@lucasvu/scope-ui 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AI_SETUP.md CHANGED
@@ -1,51 +1,271 @@
1
1
  # AI Setup
2
2
 
3
- Mục tiêu của file này để AI của project dùng `@lucasvu/scope-ui` đúng cách, không import lung tung, không hardcode màu sai chỗ không chọn nhầm component.
3
+ Muc tieu cua file nay la de AI cua project dung `@lucasvu/scope-ui` dung cach, khong import lung tung, khong hardcode mau sai cho, va giu dung base `Vite + micro frontend` khi repo duoc setup o may khac.
4
4
 
5
- Nếu project consumer đã cài package, cách nhanh nhất chạy:
5
+ Tu phien ban nay, cac phan generic truoc day thuong nam o `packages/shared/theme` da duoc ship ngay trong package nay:
6
+
7
+ - base stylesheet
8
+ - color-mode runtime
9
+ - bundled theme layers
10
+ - preset theme token generator
11
+ - layout preset va AI playbook
12
+
13
+ Surface duoc chia thanh 2 lo:
14
+
15
+ - `@lucasvu/scope-ui`: React components + full UI surface
16
+ - `@lucasvu/scope-ui/core`: theme/runtime/contracts khong phu thuoc React
17
+
18
+ Vi vay consumer project o may khac chi can cai mot package la du.
19
+
20
+ Neu project consumer da cai package, cach nhanh nhat la chay:
6
21
 
7
22
  ```bash
8
23
  npm install @lucasvu/scope-ui
9
24
  npx scope-ui-init --theme forest
10
25
  ```
11
26
 
12
- Nếu chưa biết chọn preset nào thì chạy thêm:
27
+ Neu chua biet chon preset nao thi chay them:
13
28
 
14
29
  ```bash
15
30
  npx scope-ui-init --list-themes
16
31
  ```
17
32
 
18
- Nếu chưa cài `@lucasvu/scope-ui`, các lệnh trên sẽ báo `E404` npm sẽ cố tải package tên `scope-ui-init`.
33
+ Neu chua cai `@lucasvu/scope-ui`, cac lenh tren se bao `E404` vi npm se co tai package ten `scope-ui-init`.
34
+
35
+ CLI nay se tao:
36
+
37
+ - `AGENTS.md`
38
+ - `src/styles/ui-theme.css`
39
+ - `src/layout-presets/workspace-admin-v1.ts`
40
+
41
+ `AGENTS.md` khoa flow hoi input -> doc layout preset -> dung shell -> moi toi page body. `src/layout-presets/workspace-admin-v1.ts` giu shared shell contract. `src/styles/ui-theme.css` giu token theme cua project. Neu khong truyen `--theme`, preset mac dinh la `ocean`.
42
+
43
+ ## 1. Chot dung ranh gioi trach nhiem
44
+
45
+ Voi base `Vite + micro frontend`, nen giu dung 3 lop nay:
46
+
47
+ - `@lucasvu/scope-ui`: React surface
48
+ - `@lucasvu/scope-ui/core`: design token, theme runtime, bundled theme layers, AI contract
49
+ - `apps/shell`: host app, so huu sidebar, topbar, remote mount, routing tong, va theme toan cuc.
50
+ - `apps/*-mfe`: remote app, chi so huu page business cua chinh no.
51
+
52
+ Neu repo van co `packages/shared`, hay giu no cho business util, constant, hoac remote loader noi bo. Khong nen de generic theme runtime nam ben ngoai package nua neu muc tieu la cai o may khac cung chay ngay.
53
+
54
+ Khong nen de moi MFE tu dung shell rieng, tu tao palette rieng, hoac tu viet lai `Button/Input/Card`.
55
+
56
+ ## 2. Cau truc folder khuyen nghi
57
+
58
+ ```text
59
+ .
60
+ ├─ package.json
61
+ ├─ pnpm-workspace.yaml
62
+ ├─ tsconfig.base.json
63
+ └─ apps/
64
+ ├─ shell/
65
+ │ ├─ src/app/
66
+ │ ├─ src/layouts/
67
+ │ ├─ src/routes/
68
+ │ ├─ src/remotes/
69
+ │ ├─ src/styles/
70
+ │ │ ├─ index.css
71
+ │ │ └─ ui-theme.css
72
+ │ ├─ src/main.tsx
73
+ │ └─ vite.config.ts
74
+ └─ users-mfe/
75
+ ├─ src/features/
76
+ ├─ src/pages/
77
+ ├─ src/routes/
78
+ ├─ src/services/
79
+ ├─ src/styles/
80
+ │ └─ index.css
81
+ ├─ src/bootstrap.tsx
82
+ └─ vite.config.ts
83
+ ```
19
84
 
20
- CLI này sẽ tạo `AGENTS.md`, `src/styles/ui-theme.css`, `src/layout-presets/workspace-admin-v1.ts` theo đúng convention bên dưới. `AGENTS.md` giờ khóa luôn flow hỏi input -> đọc layout preset -> dựng shell -> mới tới page body. Nếu không truyền `--theme`, preset mặc định là `ocean`.
85
+ Neu base cua ban dang dung `mfes/` thay vi `apps/`, co the giu nguyen ten folder. Dieu can giu on dinh la trach nhiem cua `shell`, `remote`, va package UI chung.
21
86
 
22
- ## 1. Import style đúng thứ tự
87
+ ## 3. Root config toi thieu
23
88
 
24
- Import package CSS trước, rồi mới import file override theme của project.
89
+ ### `pnpm-workspace.yaml`
90
+
91
+ ```yaml
92
+ packages:
93
+ - apps/*
94
+ - packages/*
95
+ ```
96
+
97
+ ### `tsconfig.base.json`
98
+
99
+ ```json
100
+ {
101
+ "compilerOptions": {
102
+ "baseUrl": "."
103
+ }
104
+ }
105
+ ```
106
+
107
+ `@lucasvu/scope-ui` nen duoc dung nhu workspace package that hoac npm package that. Neu project khong dung React, import tu `@lucasvu/scope-ui/core`.
108
+
109
+ ## 4. Import style dung thu tu
110
+
111
+ Import package CSS truoc, roi moi toi bundled theme layer cua package neu can, roi moi toi file override rieng cua app.
25
112
 
26
113
  ```ts
27
114
  import '@lucasvu/scope-ui/styles.css'
115
+ import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css'
28
116
  import './styles/ui-theme.css'
117
+ import './styles/index.css'
29
118
  ```
30
119
 
31
- `ui-theme.css` nên nơi duy nhất override màu, surface, border, shadow và gradient của thư viện.
120
+ Thu tu nay co chu dich:
32
121
 
33
- ## 2. Chọn preset theme của project
122
+ 1. `@lucasvu/scope-ui/styles.css`: nap token va component style goc.
123
+ 2. `@lucasvu/scope-ui/themes/*.css`: optional bundled shell/theme layer ship cung package.
124
+ 3. `./styles/ui-theme.css`: app shell override nhe neu can.
125
+ 4. `./styles/index.css`: reset va layout cuc bo cua shell.
34
126
 
35
- Đặt file tại `src/styles/ui-theme.css`.
127
+ Neu khong muon them bundled theme layer, co the bo qua buoc 2 va import `src/styles/ui-theme.css` ngay sau package stylesheet.
36
128
 
37
- Dùng `--list-themes` để xem preset được duyệt, rồi generate preset đã chọn:
129
+ ## 5. Color mode va packaged theme layer
38
130
 
39
- ```bash
40
- npx scope-ui-init --list-themes
41
- npx scope-ui-init --theme graphite
131
+ Package da export san color-mode runtime:
132
+
133
+ ```tsx
134
+ import {
135
+ applyDocumentClientTheme,
136
+ initializeDocumentColorMode,
137
+ } from '@lucasvu/scope-ui/core'
138
+
139
+ initializeDocumentColorMode()
140
+ applyDocumentClientTheme('neo-slate')
42
141
  ```
43
142
 
44
- File generate ra sẽ source of truth cho palette, surface, radius và shadow của project. Agent phải bám vào file này thay vì tự nghĩ màu mới.
143
+ Dung `applyDocumentClientTheme(...)` khi ban import theme layer dang attribute-scoped, vi du:
144
+
145
+ ```ts
146
+ import '@lucasvu/scope-ui/themes/theme-ui-neo-slate.css'
147
+ ```
148
+
149
+ Theme layer co 2 nhom:
150
+
151
+ - global: import la apply ngay, vi du `theme-default.css`, `theme-ui-new-main-fe.css`
152
+ - data-client-theme: can them `data-client-theme` vao `document.documentElement`, vi du `theme-ui-neo-slate.css`
153
+
154
+ Danh sach nay co san trong `uiThemeLayerAssets`.
155
+
156
+ ## 6. Step-by-step dung shell app
157
+
158
+ ### Buoc 1: Tao folder shell
159
+
160
+ ```text
161
+ apps/shell/src/
162
+ ├─ app/
163
+ ├─ layouts/
164
+ ├─ routes/
165
+ ├─ remotes/
166
+ ├─ styles/
167
+ │ ├─ index.css
168
+ │ └─ ui-theme.css
169
+ └─ main.tsx
170
+ ```
171
+
172
+ ### Buoc 2: Khoi dong theme o entry
173
+
174
+ ```tsx
175
+ import '@lucasvu/scope-ui/styles.css'
176
+ import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css'
177
+ import './styles/ui-theme.css'
178
+ import './styles/index.css'
179
+
180
+ import { initializeDocumentColorMode } from '@lucasvu/scope-ui'
181
+
182
+ initializeDocumentColorMode()
183
+ ```
184
+
185
+ Neu dung mot client theme nhu `neo-slate`, `pure-white`, `solstice-pop`, them:
186
+
187
+ ```tsx
188
+ import { applyDocumentClientTheme } from '@lucasvu/scope-ui'
189
+
190
+ applyDocumentClientTheme('neo-slate')
191
+ ```
45
192
 
46
- `AGENTS.md` sẽ thêm shell brief + screen brief dạng YAML để agent điền các giá trị như `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `pageTitle`, `filters`, `fields`, `tableColumns` trước khi bắt đầu viết JSX.
193
+ ### Buoc 3: Shell so huu app frame
47
194
 
48
- `src/layout-presets/workspace-admin-v1.ts` source of truth cho shared shell: dark sidebar, gradient topbar, intro card, optional segmented tabs, toolbar card, rồi mới tới body card/table/form.
195
+ Shell nen so huu:
196
+
197
+ - sidebar
198
+ - topbar
199
+ - route container
200
+ - remote mount point
201
+ - theme selector
202
+ - toaster/modal root neu co
203
+
204
+ Remote khong nen tu render mot shell khac neu dang chay ben trong host shell.
205
+
206
+ ### Buoc 4: Shell doc layout preset truoc khi dung page
207
+
208
+ `src/layout-presets/workspace-admin-v1.ts` la source of truth cho shared shell:
209
+
210
+ - dark sidebar
211
+ - gradient topbar
212
+ - intro card
213
+ - optional segmented tabs
214
+ - toolbar card
215
+ - body card/table/form
216
+
217
+ Khong nen bo qua preset nay roi ve mot page frame phang moi lan AI code.
218
+
219
+ ## 7. Step-by-step dung remote app
220
+
221
+ ### Folder toi thieu
222
+
223
+ ```text
224
+ apps/users-mfe/src/
225
+ ├─ features/users/
226
+ ├─ pages/
227
+ ├─ routes/
228
+ ├─ services/
229
+ ├─ styles/
230
+ │ └─ index.css
231
+ └─ bootstrap.tsx
232
+ ```
233
+
234
+ ### Rule cho remote
235
+
236
+ - Dung component tu `@lucasvu/scope-ui`.
237
+ - Khong tao them bo token/theme moi trong remote neu khong that can.
238
+ - Chi them CSS cho page hoac behavior dac thu cua remote.
239
+ - Neu remote chay standalone de local dev, van import style theo dung thu tu o tren.
240
+ - Remote so huu page business, khong so huu app shell chung.
241
+
242
+ ## 8. Theme chung nen dat o dau
243
+
244
+ Nen chia thanh 3 lop:
245
+
246
+ ### Lop 1: UI base
247
+
248
+ `@lucasvu/scope-ui/styles.css`
249
+
250
+ Lop nay dinh nghia token mac dinh va style component.
251
+
252
+ ### Lop 2: Bundled theme layer cua package
253
+
254
+ `@lucasvu/scope-ui/themes/*.css`
255
+
256
+ Vi du:
257
+
258
+ - `@lucasvu/scope-ui/themes/theme-default.css`
259
+ - `@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css`
260
+ - `@lucasvu/scope-ui/themes/theme-ui-neo-slate.css`
261
+
262
+ Day la noi package ship them shell token, typography, va visual language dung lai duoc tren may khac.
263
+
264
+ ### Lop 3: App override rat mong
265
+
266
+ `apps/shell/src/styles/ui-theme.css`
267
+
268
+ File nay chi nen override mot vai token neu shell can branding rieng:
49
269
 
50
270
  ```css
51
271
  :root {
@@ -53,37 +273,58 @@ File generate ra sẽ là source of truth cho palette, surface, radius và shado
53
273
  --tw-accent: 24 95% 52%;
54
274
  --primary-grad-from: 24 95% 52%;
55
275
  --primary-grad-to: 12 88% 56%;
56
- --surface: rgba(255, 248, 240, 0.92);
57
276
  }
58
277
 
59
278
  .dark {
60
279
  --tw-primary: 18 100% 62%;
61
280
  --tw-accent: 35 100% 58%;
62
- --surface: rgba(24, 24, 27, 0.82);
63
281
  }
64
282
  ```
65
283
 
66
- Không nên override màu trực tiếp trong từng component nếu chỉ đang đổi theme.
284
+ Khong nen doi mau truc tiep trong tung component neu chi dang doi theme.
285
+
286
+ ## 9. Chon preset theme cua project
287
+
288
+ Dat file tai `src/styles/ui-theme.css`.
289
+
290
+ Dung `--list-themes` de xem preset duoc duyet, roi generate preset da chon:
291
+
292
+ ```bash
293
+ npx scope-ui-init --list-themes
294
+ npx scope-ui-init --theme graphite
295
+ ```
296
+
297
+ File generate ra se la source of truth cho palette, surface, radius va shadow cua project. Agent phai bam vao file nay thay vi tu nghi mau moi.
298
+
299
+ Neu can them mot bundled package theme layer de co shell tone dung san, import no o app entry. Neu theme layer do la attribute-scoped, set them `data-client-theme` bang `applyDocumentClientTheme`.
67
300
 
68
- `src/layout-presets/workspace-admin-v1.ts` không cần import vào runtime. Đây layout contract cho agent/codegen đọc để giữ dark sidebar, gradient topbar, intro card, tab row, toolbar card nhất quán giữa các màn.
301
+ `AGENTS.md` se duoc generate theo format agent-definition YAML, co `activation-instructions`, `agent`, `persona`, `commands`, `dependencies`, va `brief_templates`. Agent se dien cac gia tri nhu `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `pageTitle`, `filters`, `fields`, `tableColumns` truoc khi bat dau viet JSX. Neu tool cua ban discover agent theo file rieng, co the truyen `--agents-file agents/dev.md` hoac mot path tuong tu.
69
302
 
70
- ## 3. Rule cho AI của project
303
+ `src/layout-presets/workspace-admin-v1.ts` khong can import vao runtime. Day la layout contract cho agent/codegen doc de giu dark sidebar, gradient topbar, intro card, tab row, va toolbar card nhat quan giua cac man.
71
304
 
72
- Copy phần này vào system prompt, repo instructions, `AGENTS.md`, Cursor rules, hoặc bất kỳ chỗ nào project đang dùng để ép AI theo convention:
305
+ ## 10. Rule cho AI cua project
306
+
307
+ Copy phan nay vao system prompt, repo instructions, `AGENTS.md`, Cursor rules, hoac bat ky cho nao project dang dung de ep AI theo convention:
73
308
 
74
309
  ```md
75
- Use `@lucasvu/scope-ui` as the default UI library.
310
+ Use `@lucasvu/scope-ui` for React projects and `@lucasvu/scope-ui/core` for framework-agnostic theme/runtime usage.
76
311
 
77
312
  Always:
313
+ - use `@lucasvu/scope-ui` as the shared React UI package when the app is React
314
+ - use `@lucasvu/scope-ui/core` when the app only needs theme/runtime/contracts
78
315
  - import `@lucasvu/scope-ui/styles.css` once at the app entry
79
- - import the project theme override file after the package stylesheet
316
+ - if the repo chooses a bundled theme layer, import it from `@lucasvu/scope-ui/themes/*` after the package stylesheet
317
+ - import the project theme override file after the bundled theme layer
318
+ - use `initializeDocumentColorMode` from `@lucasvu/scope-ui/core` when the app shell owns dark/light mode
319
+ - if a bundled theme layer is client-theme-scoped, set `data-client-theme` via `applyDocumentClientTheme` from `@lucasvu/scope-ui/core`
80
320
  - use root exports from `@lucasvu/scope-ui`
81
321
  - stay inside the approved preset declared by `src/styles/ui-theme.css`
82
322
  - read `src/layout-presets/workspace-admin-v1.ts` before changing the app shell or page frame
83
323
  - follow the step-by-step UI build workflow from `AGENTS.md` before writing JSX
324
+ - keep the shell in the host app and keep remotes focused on page business content
84
325
  - fill the shell + screen brief first: `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `activeSidebarItemId`, `pageTitle`, `actions`, and the page-specific schema
85
326
  - read `uiAiManifest` to choose the right component by intent
86
- - read `uiScreenBlueprint` and `uiThemeContract` before changing layout, colors, surfaces, borders, or shadows
327
+ - read `uiScreenBlueprint`, `uiThemeContract`, and `uiThemeLayerAssets` before changing layout, colors, surfaces, borders, or shadows
87
328
 
88
329
  Do not:
89
330
  - import from `MainFe` unless the task explicitly targets a legacy screen
@@ -91,6 +332,7 @@ Do not:
91
332
  - replace the shared dark-sidebar + gradient-topbar shell unless the task explicitly asks for a new shell
92
333
  - hardcode brand colors inside page components when a theme token already exists
93
334
  - create duplicate Button/Input/Select wrappers unless a project-specific behavior is required
335
+ - let each remote define a different shell or a different palette
94
336
 
95
337
  Component choice:
96
338
  - `Input` for short text
@@ -104,32 +346,53 @@ Component choice:
104
346
  - `DataTable` for tabular records
105
347
  ```
106
348
 
107
- ## 4. Runtime contract cho AI/codegen
349
+ ## 11. Runtime contract cho AI/codegen
108
350
 
109
- Trong code, AI thể đọc trực tiếp:
351
+ Trong code, AI co the doc truc tiep:
110
352
 
111
353
  ```ts
112
- import { uiAiManifest, uiScreenBlueprint, uiThemeContract, uiThemePresets, uiProjectAiRules } from '@lucasvu/scope-ui'
354
+ import {
355
+ applyDocumentClientTheme,
356
+ initializeDocumentColorMode,
357
+ uiAiManifest,
358
+ uiProjectAiRules,
359
+ uiScreenBlueprint,
360
+ uiThemeContract,
361
+ uiThemeLayerAssets,
362
+ uiThemePresets,
363
+ } from '@lucasvu/scope-ui/core'
113
364
  ```
114
365
 
115
- - `uiAiManifest`: chọn component theo intent
116
- - `uiScreenBlueprint`: brief input và khung layout chuẩn cho `list | form | detail | dashboard`, gồm cả shell fields như `layoutPreset`, `workspaceLabel`, `pageTabs`, `searchPlaceholder`
117
- - `uiThemeContract`: biết override token nào và override ở đâu
118
- - `uiThemePresets`: danh sách preset được duyệt để nhiều project dùng chung một visual language
119
- - `uiProjectAiRules`: rule ngắn gọn để inject vào agent của project
366
+ - `initializeDocumentColorMode`: dong bo dark/light mode o document root
367
+ - `applyDocumentClientTheme`: set `data-client-theme` cho bundled theme layer dang attribute-scoped
368
+ - `uiAiManifest`: chon component theo intent
369
+ - `uiScreenBlueprint`: brief input va khung layout chuan cho `list | form | detail | dashboard`, gom ca shell fields nhu `layoutPreset`, `workspaceLabel`, `pageTabs`, `searchPlaceholder`
370
+ - `uiThemeContract`: biet override token nao va override o dau
371
+ - `uiThemeLayerAssets`: danh sach bundled theme layer co san trong package, gom ca import path va activation mode
372
+ - `uiThemePresets`: danh sach preset duoc duyet de nhieu project dung chung mot visual language
373
+ - `uiProjectAiRules`: rule ngan gon de inject vao agent cua project
374
+
375
+ Neu project dung React components cua package, van import component tu root package:
376
+
377
+ ```ts
378
+ import { Button, Card, Input, Select } from '@lucasvu/scope-ui'
379
+ ```
120
380
 
121
- ## 5. Chỗ override theme
381
+ ## 12. Cho override theme
122
382
 
123
- Nếu project app shell:
383
+ Neu project co app shell:
124
384
 
125
- - import `@lucasvu/scope-ui/styles.css` app entry
126
- - import `src/styles/ui-theme.css` ngay sau đó
127
- - để agent đọc `src/layout-presets/workspace-admin-v1.ts` trước khi build page shell
128
- - toggle dark mode bằng class `.dark` trên `html` hoặc `body`, hoặc dùng `[data-ui-theme='dark']`
385
+ - import `@lucasvu/scope-ui/styles.css` o app entry
386
+ - import mot bundled package theme layer neu muon
387
+ - import `src/styles/ui-theme.css` ngay sau do
388
+ - goi `initializeDocumentColorMode()` o host app
389
+ - neu dung client theme layer, goi `applyDocumentClientTheme('<theme-id>')`
390
+ - de agent doc `src/layout-presets/workspace-admin-v1.ts` truoc khi build page shell
391
+ - toggle dark mode bang class `.dark` tren `html` hoac `body`, hoac dung `[data-ui-theme='dark']`
129
392
 
130
- Nếu project nhiều brand/theme:
393
+ Neu project co nhieu brand/theme:
131
394
 
132
- - giữ `:root` theme mặc định
133
- - tạo selector như `[data-ui-theme='brand-a']`, `[data-ui-theme='brand-b']`
134
- - vẫn nên xuất phát từ một preset duyệt sẵn rồi mới override token cần thiết
135
- - chỉ override token trong file theme, không fork component
395
+ - giu `:root` la theme mac dinh
396
+ - tao selector nhu `[data-ui-theme='brand-a']`, `[data-ui-theme='brand-b']` hoac dung `data-client-theme`
397
+ - van nen xuat phat tu mot preset duyet san roi moi override token can thiet
398
+ - chi override token trong file theme, khong fork component
package/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # @lucasvu/scope-ui
2
2
 
3
- Bộ component phong cách **shadcn** dùng chung cho các app/micro-frontend trong workspace. Tất cả đều là React component thuần, kèm sẵn theme tối và hiệu ứng kính mờ.
3
+ Bộ UI dùng chung cho các app/micro-frontend trong workspace.
4
+
5
+ - Root package `@lucasvu/scope-ui`: React components + full UI surface
6
+ - Core subpath `@lucasvu/scope-ui/core`: theme/runtime/contracts không phụ thuộc React
4
7
 
5
8
  ## Cách dùng nhanh
6
9
 
@@ -10,13 +13,40 @@ Bộ component phong cách **shadcn** dùng chung cho các app/micro-frontend tr
10
13
  npm install @lucasvu/scope-ui
11
14
  ```
12
15
 
13
- 2. Import global style một lần entry (ví dụ `main.tsx`):
16
+ 2. Nếu dùng React, import từ root package:
14
17
 
15
18
  ```ts
16
19
  import '@lucasvu/scope-ui/styles.css';
20
+ import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css';
21
+ import './styles/ui-theme.css';
22
+ ```
23
+
24
+ Nếu muốn dùng theme layer dạng client-theme, ví dụ `neo-slate`, set thêm ở app entry:
25
+
26
+ ```ts
27
+ import { applyDocumentClientTheme, initializeDocumentColorMode } from '@lucasvu/scope-ui';
28
+
29
+ initializeDocumentColorMode();
30
+ applyDocumentClientTheme('neo-slate');
17
31
  ```
18
32
 
19
- 3. Nếu muốn bootstrap rule/theme/layout cho AI trong project consumer:
33
+ 3. Nếu không dùng React, import phần generic từ `@lucasvu/scope-ui/core`:
34
+
35
+ ```ts
36
+ import '@lucasvu/scope-ui/styles.css';
37
+ import '@lucasvu/scope-ui/themes/theme-ui-neo-slate.css';
38
+
39
+ import {
40
+ applyDocumentClientTheme,
41
+ initializeDocumentColorMode,
42
+ uiThemeLayerAssets,
43
+ } from '@lucasvu/scope-ui/core';
44
+
45
+ initializeDocumentColorMode();
46
+ applyDocumentClientTheme('neo-slate');
47
+ ```
48
+
49
+ 4. Nếu muốn bootstrap rule/theme/layout cho AI trong project consumer:
20
50
 
21
51
  ```bash
22
52
  npm install @lucasvu/scope-ui
@@ -31,9 +61,9 @@ npx scope-ui-init --list-themes
31
61
 
32
62
  Lưu ý: các lệnh này chỉ chạy được sau khi project đã cài `@lucasvu/scope-ui`. Nếu chưa cài package, `npx` sẽ đi tìm một package riêng tên `scope-ui-init` trên npm và báo `E404`.
33
63
 
34
- Lệnh này sẽ tạo `AGENTS.md`, `src/styles/ui-theme.css`, và `src/layout-presets/workspace-admin-v1.ts` trong repo hiện tại theo preset đã chọn. `AGENTS.md` giờ thêm playbook step-by-step để agent hỏi đủ input, đọc layout preset, rồi dựng màn hình đúng layout/component/theme chung. Nếu không truyền `--theme`, preset mặc định là `ocean`. Dùng `--force` nếu muốn overwrite file đã tồn tại.
64
+ Lệnh này sẽ tạo `AGENTS.md`, `src/styles/ui-theme.css`, và `src/layout-presets/workspace-admin-v1.ts` trong repo hiện tại theo preset đã chọn. `AGENTS.md` giờ được generate theo format agent-definition YAML có `activation-instructions`, `agent`, `persona`, `commands`, `dependencies`, `brief_templates`, và rule lock theme/layout. Nếu muốn output thẳng vào path agent-discovery của tooling, dùng `--agents-file`, dụ `npx scope-ui-init --theme sunset --agents-file agents/dev.md`. Nếu không truyền `--theme`, preset mặc định là `ocean`. Dùng `--force` nếu muốn overwrite file đã tồn tại.
35
65
 
36
- 4. Dùng component:
66
+ 5. Dùng component:
37
67
 
38
68
  ```tsx
39
69
  import {
@@ -104,31 +134,72 @@ export function Example() {
104
134
  - `Field` phù hợp khi bạn cần bọc một control custom hoặc gom nhiều control dưới cùng một nhãn.
105
135
  - Nếu bạn đổi tên package trước khi publish, thay `@lucasvu/scope-ui` trong các ví dụ bằng package name mới.
106
136
 
137
+ ## Bundled Theme Layers
138
+
139
+ Package ship sẵn các theme asset để máy khác cài vào là dùng được ngay:
140
+
141
+ - Global apply ngay khi import: `@lucasvu/scope-ui/themes/theme-default.css`, `@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css`
142
+ - Client-theme scoped: `@lucasvu/scope-ui/themes/theme-ui-neo-slate.css`, `@lucasvu/scope-ui/themes/theme-ui-facebook-blue.css`, `@lucasvu/scope-ui/themes/theme-ui-solstice-pop.css`, ...
143
+
144
+ Bạn có thể đọc manifest ngay trong code:
145
+
146
+ ```ts
147
+ import { uiThemeLayerAssets } from '@lucasvu/scope-ui/core';
148
+ ```
149
+
150
+ Nếu một theme có `activation: 'data-client-theme'`, hãy gọi `applyDocumentClientTheme('<theme-id>')` sau khi import CSS của theme đó.
151
+
152
+ ## Core Surface
153
+
154
+ Nếu project không dùng React nhưng vẫn muốn dùng theme/runtime/contracts của package, dùng:
155
+
156
+ ```ts
157
+ import {
158
+ applyDocumentClientTheme,
159
+ initializeDocumentColorMode,
160
+ uiAiManifest,
161
+ uiProjectAiRules,
162
+ uiScreenBlueprint,
163
+ uiThemeContract,
164
+ uiThemeLayerAssets,
165
+ uiThemePresets,
166
+ } from '@lucasvu/scope-ui/core';
167
+ ```
168
+
169
+ `@lucasvu/scope-ui/core` không export React component surface.
170
+
107
171
  ## Dùng cho AI/codegen
108
172
 
109
173
  Nếu muốn AI render UI đúng và ổn định theo thư viện này, đừng chỉ đưa mỗi tên package. Hãy để agent bám vào một surface chuẩn:
110
174
 
111
175
  - Import CSS global một lần: `@lucasvu/scope-ui/styles.css`
112
- - Import file theme override của project ngay sau package CSS, ví dụ `./styles/ui-theme.css`
176
+ - Nếu project muốn dùng shell/theme layer dựng sẵn, import từ `@lucasvu/scope-ui/themes/*` ngay sau package CSS
177
+ - Import file theme override của project ngay sau bundled theme layer, ví dụ `./styles/ui-theme.css`
178
+ - Dùng `initializeDocumentColorMode()` từ `@lucasvu/scope-ui` khi shell sở hữu dark/light mode
179
+ - Nếu bundled theme layer là client-theme scoped, set `data-client-theme` bằng `applyDocumentClientTheme(...)`
113
180
  - Cài package trước khi bootstrap: `npm install @lucasvu/scope-ui`
114
181
  - Chạy `npx scope-ui-init --list-themes` để xem preset được duyệt
115
182
  - Chạy `npx scope-ui-init --theme <preset>` ở project consumer sau khi đã cài `@lucasvu/scope-ui` để tạo `AGENTS.md`, `src/styles/ui-theme.css`, và `src/layout-presets/workspace-admin-v1.ts`
183
+ - Nếu tooling của bạn đọc agent theo file riêng, dùng `--agents-file agents/dev.md` hoặc path tương đương để generate luôn agent markdown đúng chỗ
116
184
  - Khoá project vào một preset thay vì tự bịa palette mới cho từng page
117
- - Để agent đọc luôn playbook trong `AGENTS.md` `src/layout-presets/workspace-admin-v1.ts` để đi đúng thứ tự: hỏi input, khóa shell, chọn component, dựng layout, rồi mới tinh chỉnh token
185
+ - Để agent đọc luôn agent-definition trong `AGENTS.md` hoặc file bạn truyền qua `--agents-file`, cùng với `src/layout-presets/workspace-admin-v1.ts`, để đi đúng thứ tự: hỏi input, khóa shell, chọn component, dựng layout, rồi mới tinh chỉnh token
118
186
  - Buộc agent điền shell + screen brief trước khi code: `workspaceLabel`, `pageTabs`, `searchPlaceholder`, `routeUrl`, `sidebarItems`, `activeSidebarItemId`, `pageTitle`, `actions`, `filters`, `fields`, `tableColumns`
119
- - `AGENTS.md` mới sẽ có sẵn block brief dạng YAML để agent hoặc dev điền trực tiếp trước khi code
187
+ - `AGENTS.md` mới sẽ có sẵn block `commands`, `dependencies`, và `brief_templates` dạng YAML để agent hoặc dev điền trực tiếp trước khi code
120
188
  - Chỉ dùng các component canonical ở root package; tránh `MainFe` nếu không phải legacy screen
121
189
  - Cho agent đọc `uiAiManifest` để biết component nào dùng cho intent nào, props quan trọng là gì, và khi nào không nên dùng
122
190
  - Cho agent đọc `uiScreenBlueprint`, `uiThemeContract` và `uiThemePresets` để biết screen recipe, preset và token nào được phép override
123
191
 
124
192
  ```ts
125
193
  import {
194
+ applyDocumentClientTheme,
195
+ initializeDocumentColorMode,
126
196
  uiAiManifest,
127
197
  uiProjectAiRules,
128
198
  uiScreenBlueprint,
129
199
  uiThemeContract,
200
+ uiThemeLayerAssets,
130
201
  uiThemePresets,
131
- } from '@lucasvu/scope-ui';
202
+ } from '@lucasvu/scope-ui/core';
132
203
  ```
133
204
 
134
205
  `uiAiManifest` mô tả luật chọn component theo intent như: text input, textarea, fixed select, searchable select, async combobox, multi select, data table, alert, card và field wrapper.
@@ -137,13 +208,15 @@ import {
137
208
 
138
209
  `uiThemeContract` mô tả token màu, surface, border, shadow, radius, gradient và selector theme (`:root`, `.dark`, `[data-ui-theme='*']`) để AI không hardcode màu sai chỗ.
139
210
 
211
+ `uiThemeLayerAssets` mô tả các theme layer CSS được ship sẵn trong package, import path tương ứng, và theme nào cần `data-client-theme`.
212
+
140
213
  `uiThemePresets` là danh sách preset được duyệt sẵn để nhiều project có thể chọn cùng một visual language mà không cần tự dựng theme từ đầu.
141
214
 
142
215
  `AI_SETUP.md` và CLI `scope-ui-init` giúp bootstrap rule/theme/layout cho repo consumer mà không cần copy tay.
143
216
 
144
217
  ## Theme Override
145
218
 
146
- Nên để toàn bộ override theme của project vào một file riêng, ví dụ `src/styles/ui-theme.css`, rồi import file này sau `@lucasvu/scope-ui/styles.css`.
219
+ Nên để toàn bộ override theme của project vào một file riêng, ví dụ `src/styles/ui-theme.css`, rồi import file này sau `@lucasvu/scope-ui/styles.css` và sau bundled theme layer nếu có.
147
220
 
148
221
  Cách nhanh nhất là generate bộ file này từ preset:
149
222
 
@@ -155,6 +228,7 @@ npx scope-ui-init --theme ocean
155
228
 
156
229
  ```ts
157
230
  import '@lucasvu/scope-ui/styles.css';
231
+ import '@lucasvu/scope-ui/themes/theme-ui-new-main-fe.css';
158
232
  import './styles/ui-theme.css';
159
233
  ```
160
234
 
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { copyFileSync, existsSync, mkdirSync, readdirSync, rmSync } from 'node:fs'
4
+ import { dirname, join, resolve } from 'node:path'
5
+
6
+ const sourceDir = resolve(process.cwd(), '../shared/theme')
7
+ const targetDir = resolve(process.cwd(), 'dist/themes')
8
+
9
+ if (!existsSync(sourceDir)) {
10
+ console.error(`Theme asset source not found: ${sourceDir}`)
11
+ process.exit(1)
12
+ }
13
+
14
+ rmSync(targetDir, { force: true, recursive: true })
15
+ mkdirSync(targetDir, { recursive: true })
16
+
17
+ const themeFiles = readdirSync(sourceDir)
18
+ .filter((fileName) => fileName.endsWith('.css'))
19
+ .sort()
20
+
21
+ for (const fileName of themeFiles) {
22
+ const sourceFile = join(sourceDir, fileName)
23
+ const targetFile = join(targetDir, fileName)
24
+
25
+ mkdirSync(dirname(targetFile), { recursive: true })
26
+ copyFileSync(sourceFile, targetFile)
27
+ }
28
+
29
+ console.log(`Copied ${themeFiles.length} theme assets to dist/themes`)