@prunellejs/ui 0.1.1 → 0.7.0

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.
Files changed (79) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +19 -11
  3. package/package.json +2 -2
  4. package/src/CommandPalette.tsx +130 -75
  5. package/src/DataTable.tsx +131 -58
  6. package/src/Dialog.tsx +30 -14
  7. package/src/Menu.tsx +10 -8
  8. package/src/Select.tsx +19 -8
  9. package/src/Tabs.tsx +2 -1
  10. package/src/Toaster.tsx +79 -5
  11. package/src/behaviors.ts +104 -6
  12. package/src/fold.ts +7 -0
  13. package/src/index.ts +1 -1
  14. package/src/labels/dialog.ts +3 -0
  15. package/src/labels/fr/dialog.ts +3 -0
  16. package/src/labels/fr/palette.ts +8 -0
  17. package/src/labels/fr/select.ts +1 -0
  18. package/src/labels/fr/table.ts +13 -0
  19. package/src/labels/fr/toaster.ts +1 -0
  20. package/src/labels/palette.ts +8 -0
  21. package/src/labels/select.ts +1 -0
  22. package/src/labels/table.ts +13 -0
  23. package/src/labels/toaster.ts +1 -0
  24. package/src/plugin.ts +114 -31
  25. package/src/primitives.tsx +3 -2
  26. package/src/static.tsx +11 -6
  27. package/src/styles/bare.css +22 -312
  28. package/src/styles/base.css +61 -0
  29. package/src/styles/components/accordion.css +10 -0
  30. package/src/styles/components/badge.css +6 -0
  31. package/src/styles/components/button.css +11 -0
  32. package/src/styles/components/card.css +5 -0
  33. package/src/styles/components/checkbox.css +11 -0
  34. package/src/styles/components/command.css +25 -0
  35. package/src/styles/components/consent.css +38 -0
  36. package/src/styles/components/datatable.css +9 -0
  37. package/src/styles/components/dialog.css +16 -0
  38. package/src/styles/components/drawer.css +29 -0
  39. package/src/styles/components/field.css +8 -0
  40. package/src/styles/components/layout.css +69 -0
  41. package/src/styles/components/menu.css +21 -0
  42. package/src/styles/components/notice.css +5 -0
  43. package/src/styles/components/popover.css +8 -0
  44. package/src/styles/components/progress.css +14 -0
  45. package/src/styles/components/radio-group.css +11 -0
  46. package/src/styles/components/select.css +25 -0
  47. package/src/styles/components/switch.css +42 -0
  48. package/src/styles/components/tabs.css +4 -0
  49. package/src/styles/components/toast.css +28 -0
  50. package/src/styles/grammars/console.css +114 -256
  51. package/src/styles/grammars/editorial.css +101 -271
  52. package/src/styles/grammars/orbit.css +121 -390
  53. package/src/styles/grammars/prunelle.css +157 -360
  54. package/src/styles/grammars/soft.css +106 -240
  55. package/src/styles/grammars/workshop.css +110 -251
  56. package/src/styles/scan.ts +144 -0
  57. package/src/styles/split.ts +429 -0
  58. package/src/styles/theme.css +22 -0
  59. package/src/styles/themed/accordion.css +20 -0
  60. package/src/styles/themed/badge.css +20 -0
  61. package/src/styles/themed/button.css +24 -0
  62. package/src/styles/themed/card.css +23 -0
  63. package/src/styles/themed/checkbox.css +4 -0
  64. package/src/styles/themed/command.css +33 -0
  65. package/src/styles/themed/consent.css +33 -0
  66. package/src/styles/themed/datatable.css +28 -0
  67. package/src/styles/themed/dialog.css +13 -0
  68. package/src/styles/themed/drawer.css +13 -0
  69. package/src/styles/themed/field.css +22 -0
  70. package/src/styles/themed/menu.css +21 -0
  71. package/src/styles/themed/notice.css +17 -0
  72. package/src/styles/themed/popover.css +11 -0
  73. package/src/styles/themed/radio-group.css +12 -0
  74. package/src/styles/themed/select.css +32 -0
  75. package/src/styles/themed/switch.css +23 -0
  76. package/src/styles/themed/tabs.css +20 -0
  77. package/src/styles/themed/toast.css +18 -0
  78. package/src/table-state.ts +53 -16
  79. package/src/toast.ts +50 -8
@@ -1,7 +1,7 @@
1
1
  /* Grammar: Workshop — tactile 2px ink frames, hard unblurred offset shadows, physical press travel.
2
2
  * Inspired by print & craft studios (like jb-peinture). Eject via `prunelle ui-eject workshop`. */
3
3
 
4
- @import '../bare.css';
4
+ @import '../theme.css';
5
5
 
6
6
  @layer kui {
7
7
  :root {
@@ -17,8 +17,8 @@
17
17
  --ui-success: light-dark(#31692d, #7ac074);
18
18
  --ui-warning: light-dark(#855700, #eab354);
19
19
  --ui-danger: light-dark(#b0322a, #f0756b);
20
- --ui-font-body: ui-sans-serif, system-ui, -apple-system, sans-serif;
21
- --ui-font-display: ui-sans-serif, system-ui, -apple-system, sans-serif;
20
+ --ui-font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
21
+ --ui-font-display: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
22
22
  --ui-radius: 2px;
23
23
  --ui-border-w: 2px;
24
24
  --ui-shadow: 5px 5px 0 var(--ui-shadow-color);
@@ -27,287 +27,146 @@
27
27
  }
28
28
 
29
29
  [data-ui="button"] {
30
- display: inline-flex;
31
- align-items: center;
32
- justify-content: center;
33
- gap: 0.5rem;
34
- font: 700 0.88rem/1 var(--ui-font-body);
30
+ --ui-btn-f: 700 0.88rem/1 var(--ui-font-body);
31
+ --ui-btn-pad: 0.7rem 1.25rem;
32
+ --ui-btn-bd: var(--ui-border-w) solid var(--ui-line);
35
33
  letter-spacing: 0.04em;
36
34
  text-transform: uppercase;
37
- padding: 0.7rem 1.25rem;
38
- border-radius: var(--ui-radius);
39
- border: var(--ui-border-w) solid var(--ui-line);
40
- background: var(--ui-surface);
41
- color: var(--ui-ink);
42
35
  box-shadow: var(--ui-press-shadow);
43
- text-decoration: none;
44
- cursor: pointer;
45
- transition: transform var(--ui-motion), box-shadow var(--ui-motion), background var(--ui-motion);
46
-
47
- &:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ui-line); }
48
- &:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ui-line); }
49
- &:disabled { opacity: 0.5; cursor: not-allowed; }
50
- &[data-tone="accent"] { background: var(--ui-accent); border-color: var(--ui-line); color: var(--ui-on-accent); }
51
- &[data-tone="danger"] { background: var(--ui-danger); border-color: var(--ui-line); color: var(--ui-on-accent); }
52
- &[data-variant="outline"] { background: transparent; }
53
- &[data-variant="ghost"] { border-color: transparent; background: transparent; box-shadow: none; }
54
- &[data-variant="ghost"]:hover:not(:disabled) { border-color: var(--ui-line); transform: none; box-shadow: none; }
55
- &[data-size="sm"] { font-size: 0.78rem; padding: 0.45rem 0.85rem; }
56
- &[data-size="lg"] { font-size: 0.98rem; padding: 0.9rem 1.6rem; }
36
+ &:hover:not(:disabled, [aria-disabled="true"]) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ui-line); }
37
+ &:active:not(:disabled, [aria-disabled="true"]) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ui-line); }
38
+ &[data-tone="accent"], &[data-tone="danger"], &[data-variant="outline"] { border-color: var(--ui-line); }
39
+ &[data-variant="ghost"]:hover:not(:disabled, [aria-disabled="true"]) { border-color: var(--ui-line); transform: none; box-shadow: none; }
57
40
  }
58
41
 
59
- /* Card: crisp framed print with hard unblurred drop shadow */
60
42
  [data-ui="card"] {
61
- border: var(--ui-border-w) solid var(--ui-line);
62
- border-radius: var(--ui-radius);
63
- background: var(--ui-surface);
64
- color: var(--ui-ink);
43
+ --ui-card-bd: var(--ui-border-w) solid var(--ui-line);
44
+ --ui-card-pad: 1.25rem;
45
+ --ui-card-hf: 800 1.1rem/1.3 var(--ui-font-display);
46
+ --ui-card-hpb: 0.75rem;
47
+ --ui-card-hmb: 0.75rem;
48
+ --ui-card-hbd: var(--ui-border-w) solid var(--ui-line);
49
+ --ui-card-fpt: 0.75rem;
50
+ --ui-card-fbd: var(--ui-border-w) solid var(--ui-line);
65
51
  box-shadow: var(--ui-shadow);
66
- padding: 1.25rem;
67
-
68
- & [data-part="header"] {
69
- font-family: var(--ui-font-display);
70
- font-weight: 800;
71
- font-size: 1.1rem;
72
- padding-block-end: 0.75rem;
73
- margin-block-end: 0.75rem;
74
- border-bottom: var(--ui-border-w) solid var(--ui-line);
75
- }
76
- & [data-part="footer"] {
77
- margin-block-start: 1rem;
78
- padding-block-start: 0.75rem;
79
- border-top: var(--ui-border-w) solid var(--ui-line);
80
- }
81
52
  }
82
53
 
83
54
  [data-ui="badge"] {
84
- display: inline-flex;
85
- align-items: center;
86
- font: 700 0.74rem/1 var(--ui-font-body);
55
+ --ui-badge-f: 700 0.74rem/1 var(--ui-font-body);
56
+ --ui-badge-pad: 0.3rem 0.65rem;
57
+ --ui-badge-bd: var(--ui-border-w) solid var(--ui-line);
58
+ --ui-badge-bg: var(--ui-surface);
59
+ --ui-badge-fg: var(--ui-ink);
60
+ --ui-badge-tbg: 100%;
61
+ --ui-badge-tfg: var(--ui-on-accent);
62
+ --ui-badge-tbd: 0%;
63
+ --ui-badge-tbd0: var(--ui-line);
87
64
  letter-spacing: 0.08em;
88
65
  text-transform: uppercase;
89
- padding: 0.3rem 0.65rem;
90
- border: var(--ui-border-w) solid var(--ui-line);
91
- border-radius: var(--ui-radius);
92
- background: var(--ui-surface);
93
- color: var(--ui-ink);
94
-
95
- &[data-tone="accent"] { background: var(--ui-accent); color: var(--ui-on-accent); }
96
- &[data-tone="success"] { background: var(--ui-success); color: var(--ui-on-accent); }
97
- &[data-tone="warning"] { background: var(--ui-warning); color: var(--ui-on-accent); }
98
- &[data-tone="danger"] { background: var(--ui-danger); color: var(--ui-on-accent); }
99
66
  }
100
67
 
101
68
  [data-ui="notice"] {
102
- border: var(--ui-border-w) solid var(--ui-line);
103
- border-radius: var(--ui-radius);
104
- background: var(--ui-surface);
69
+ --ui-notice-bw: var(--ui-border-w);
70
+ --ui-notice-pad: 0.9rem 1.1rem;
105
71
  box-shadow: 4px 4px 0 var(--ui-shadow-color);
106
- padding: 0.9rem 1.1rem;
107
- &[data-tone="accent"] { border-color: var(--ui-accent); }
108
- &[data-tone="success"] { border-color: var(--ui-success); }
109
- &[data-tone="warning"] { border-color: var(--ui-warning); }
110
- &[data-tone="danger"] { border-color: var(--ui-danger); }
72
+ &[data-tone] { border-color: var(--ui-tone); }
111
73
  }
112
74
 
113
75
  [data-ui="field"] {
114
- display: flex;
115
- flex-direction: column;
116
- gap: 0.4rem;
117
- & [data-part="label"] { font: 700 0.82rem/1.2 var(--ui-font-body); text-transform: uppercase; letter-spacing: 0.06em; }
118
- & input, & textarea, & select {
119
- font: 500 0.95rem/1.4 var(--ui-font-body);
120
- color: var(--ui-ink);
121
- background: var(--ui-surface);
122
- border: var(--ui-border-w) solid var(--ui-line);
123
- border-radius: var(--ui-radius);
124
- padding: 0.6rem 0.85rem;
125
- }
126
- & [aria-invalid="true"] { border-color: var(--ui-danger); }
127
- & [data-part="hint"] { font-size: 0.82rem; color: var(--ui-muted); }
128
- & [data-part="error"] { font-size: 0.82rem; font-weight: 600; color: var(--ui-danger); }
129
- }
130
-
131
- [data-ui="accordion"] details {
132
- border: var(--ui-border-w) solid var(--ui-line);
133
- background: var(--ui-surface);
134
- & + details { margin-block-start: calc(-1 * var(--ui-border-w)); }
135
- }
136
- [data-ui="accordion"] summary[data-part="trigger"] {
137
- list-style: none;
138
- cursor: pointer;
139
- padding: 0.85rem 1rem;
140
- font-weight: 700;
141
- display: flex;
142
- justify-content: space-between;
143
- &::after { content: '▸'; }
144
- }
145
- [data-ui="accordion"] details[open] summary[data-part="trigger"]::after { content: '▾'; }
146
- [data-ui="accordion"] [data-part="content"] { padding: 0 1rem 1rem; color: var(--ui-muted); }
147
-
148
- [data-ui="tabs"] [data-part="list"] {
149
- display: inline-flex;
150
- border: var(--ui-border-w) solid var(--ui-line);
151
- background: var(--ui-paper);
152
- }
153
- [data-ui="tabs"] [data-part="trigger"] {
154
- background: transparent;
155
- border: 0;
156
- border-right: var(--ui-border-w) solid var(--ui-line);
157
- padding: 0.55rem 1rem;
158
- font: 700 0.82rem/1 var(--ui-font-body);
159
- text-transform: uppercase;
160
- color: var(--ui-ink);
161
- cursor: pointer;
162
- &:last-child { border-right: 0; }
163
- &[data-state="active"] { background: var(--ui-accent); color: var(--ui-on-accent); }
164
- }
165
- [data-ui="tabs"] [data-part="panel"] { padding-block-start: 1rem; }
166
-
167
- dialog[data-ui="dialog"] {
168
- border: var(--ui-border-w) solid var(--ui-line);
169
- border-radius: var(--ui-radius);
170
- background: var(--ui-surface);
171
- color: var(--ui-ink);
172
- box-shadow: 8px 8px 0 var(--ui-line);
173
- padding: 0;
174
- & > [data-part="panel"] { padding: 1.5rem; }
175
- & [data-part="title"] { margin: 0 0 0.5rem; font-weight: 800; font-size: 1.25rem; }
176
- }
177
-
178
- [data-ui="popover"][popover],
179
- [data-ui="menu"] [data-part="content"],
180
- [data-ui="select"] [data-part="listbox"] {
181
- background: var(--ui-surface);
182
- color: var(--ui-ink);
183
- border: var(--ui-border-w) solid var(--ui-line);
184
- box-shadow: var(--ui-shadow);
185
- padding: 0.35rem;
186
- min-inline-size: 12rem;
76
+ --ui-fld-lf: 700 0.82rem/1.2 var(--ui-font-body);
77
+ --ui-in-f: 500 0.95rem/1.4 var(--ui-font-body);
78
+ --ui-in-bd: var(--ui-border-w) solid var(--ui-line);
79
+ --ui-in-pad: 0.6rem 0.85rem;
80
+ & [data-part="label"] { text-transform: uppercase; letter-spacing: 0.06em; }
81
+ & [data-part="error"] { font-weight: 600; }
82
+ }
83
+
84
+ [data-ui="accordion"] {
85
+ --ui-acc-bd: var(--ui-border-w) solid var(--ui-line);
86
+ --ui-acc-bg: var(--ui-surface);
87
+ --ui-acc-gap: calc(-1 * var(--ui-border-w));
88
+ --ui-acc-tpad: 0.85rem 1rem;
89
+ --ui-acc-tf: 700 1rem/1.3 var(--ui-font-body);
90
+ --ui-acc-m: '▸';
91
+ --ui-acc-mo: '▾';
92
+ --ui-acc-cpad: 0 1rem 1rem;
93
+ }
94
+
95
+ [data-ui="tabs"] {
96
+ --ui-tab-disp: inline-flex;
97
+ --ui-tab-gap: 0;
98
+ --ui-tab-pad: 0.55rem 1rem;
99
+ --ui-tab-f: 700 0.82rem/1 var(--ui-font-body);
100
+ --ui-tab-fg: var(--ui-ink);
101
+ --ui-tab-abg: var(--ui-accent);
102
+ --ui-tab-afg: var(--ui-on-accent);
103
+ --ui-tab-aind: none;
104
+ & [data-part="list"] { border: var(--ui-border-w) solid var(--ui-line); background: var(--ui-paper); }
105
+ & [data-part="trigger"] { border-right: var(--ui-border-w) solid var(--ui-line); text-transform: uppercase; &:last-child { border-right: 0; } }
106
+ }
107
+
108
+ dialog[data-ui="dialog"],
109
+ dialog[data-ui="drawer"],
110
+ dialog[data-ui="command"] {
111
+ --ui-dlg-bd: var(--ui-border-w) solid var(--ui-line);
112
+ --ui-dlg-sh: 8px 8px 0 var(--ui-line);
113
+ --ui-dlg-tf: 800 1.25rem/1.25 var(--ui-font-display);
187
114
  }
188
115
 
189
- [data-ui="menu"] [data-part="item"],
190
- [data-ui="select"] [data-part="option"] {
191
- display: flex;
192
- align-items: center;
193
- justify-content: space-between;
194
- width: 100%;
195
- text-align: left;
196
- background: transparent;
197
- border: 0;
198
- padding: 0.5rem 0.7rem;
199
- font: 600 0.88rem/1.3 var(--ui-font-body);
200
- color: var(--ui-ink);
201
- cursor: pointer;
202
- &:hover, &[data-highlighted="true"] { background: var(--ui-paper); }
203
- &[data-selected="true"] { background: var(--ui-accent); color: var(--ui-on-accent); }
116
+ [data-ui="popover"],
117
+ [data-ui="menu"],
118
+ [data-ui="select"] {
119
+ --ui-pop-bd: var(--ui-border-w) solid var(--ui-line);
120
+ --ui-pop-sh: var(--ui-shadow);
121
+ --ui-it-f: 600 0.88rem/1.3 var(--ui-font-body);
122
+ --ui-it-hbg: var(--ui-paper);
204
123
  }
205
124
 
206
- [data-ui="select"] [data-part="trigger"] {
207
- display: inline-flex;
208
- align-items: center;
209
- justify-content: space-between;
210
- gap: 1rem;
211
- min-inline-size: 12rem;
212
- background: var(--ui-surface);
213
- color: var(--ui-ink);
214
- border: var(--ui-border-w) solid var(--ui-line);
215
- box-shadow: var(--ui-press-shadow);
216
- padding: 0.55rem 0.85rem;
217
- font: 600 0.9rem/1.3 var(--ui-font-body);
218
- cursor: pointer;
125
+ [data-ui="select"] {
126
+ --ui-sel-bd: var(--ui-border-w) solid var(--ui-line);
127
+ --ui-sel-pad: 0.55rem 0.85rem;
128
+ --ui-sel-f: 600 0.9rem/1.3 var(--ui-font-body);
129
+ & [data-part="trigger"] { box-shadow: var(--ui-press-shadow); }
130
+ & [data-part="option"][data-selected="true"] { background: var(--ui-accent); color: var(--ui-on-accent); }
219
131
  }
220
132
 
221
133
  [data-ui="toast"] {
222
- background: var(--ui-surface);
223
- color: var(--ui-ink);
224
- border: var(--ui-border-w) solid var(--ui-line);
225
- box-shadow: var(--ui-shadow);
226
- padding: 0.8rem 1rem;
227
- display: flex;
228
- align-items: start;
229
- justify-content: space-between;
230
- gap: 0.75rem;
231
- &[data-tone="accent"] { border-color: var(--ui-accent); }
232
- &[data-tone="success"] { border-color: var(--ui-success); }
233
- &[data-tone="warning"] { border-color: var(--ui-warning); }
234
- &[data-tone="danger"] { border-color: var(--ui-danger); }
134
+ --ui-tst-bw: var(--ui-border-w);
135
+ --ui-tst-sh: var(--ui-shadow);
136
+ --ui-tst-pad: 0.8rem 1rem;
137
+ &[data-tone] { border-color: var(--ui-tone); }
235
138
  }
236
139
 
237
- [data-ui="checkbox"] input,
238
- [data-ui="radio-group"] input { accent-color: var(--ui-accent); }
239
- [data-ui="switch"] [data-part="track"] {
240
- border: var(--ui-border-w) solid var(--ui-line);
241
- background: var(--ui-surface);
242
- &::after { background: var(--ui-line); }
243
- }
244
- [data-ui="switch"] input:checked + [data-part="track"] {
245
- background: var(--ui-accent);
246
- &::after { background: var(--ui-on-accent); }
140
+ [data-ui="switch"] {
141
+ --ui-sw-bd: var(--ui-border-w) solid var(--ui-line);
142
+ --ui-sw-bg: var(--ui-surface);
143
+ --ui-sw-th: var(--ui-line);
144
+ --ui-sw-onbd: var(--ui-line);
247
145
  }
248
- [data-ui="radio-group"] [data-part="legend"] {
249
- font-weight: 800;
250
- font-size: 0.82rem;
251
- text-transform: uppercase;
252
- margin-block-end: 0.45rem;
253
- }
254
- [data-ui="radio-group"] [data-part="hint"] { font-size: 0.8rem; color: var(--ui-muted); }
255
146
 
256
- dialog[data-ui="drawer"],
257
- dialog[data-ui="command"] {
258
- border: var(--ui-border-w) solid var(--ui-line);
259
- background: var(--ui-surface);
260
- color: var(--ui-ink);
261
- box-shadow: 8px 8px 0 var(--ui-line);
262
- padding: 0;
263
- }
264
- dialog[data-ui="drawer"] > [data-part="panel"] {
265
- padding: 1.5rem;
147
+ [data-ui="radio-group"] {
148
+ --ui-rg-lf: 800 0.82rem/1.2 var(--ui-font-body);
149
+ --ui-rg-lc: uppercase;
150
+ --ui-rg-lfg: var(--ui-ink);
266
151
  }
152
+
267
153
  dialog[data-ui="command"] {
268
- padding: 0;
269
- & [data-part="input"] {
270
- width: 100%;
271
- border: 0;
272
- border-bottom: var(--ui-border-w) solid var(--ui-line);
273
- background: var(--ui-paper);
274
- color: var(--ui-ink);
275
- padding: 0.85rem 1rem;
276
- font: 600 0.95rem/1.3 var(--ui-font-body);
277
- }
278
- & [data-part="list"] { padding: 0.4rem; }
279
- & [data-part="item"] {
280
- display: flex;
281
- justify-content: space-between;
282
- align-items: center;
283
- width: 100%;
284
- border: 0;
285
- background: transparent;
286
- color: var(--ui-ink);
287
- padding: 0.55rem 0.7rem;
288
- font: 600 0.9rem/1.3 var(--ui-font-body);
289
- cursor: pointer;
290
- &[data-highlighted="true"] { background: var(--ui-accent); color: var(--ui-on-accent); }
291
- }
292
- & [data-part="kbd"] { font-size: 0.74rem; border: var(--ui-border-w) solid currentColor; padding: 0.05rem 0.35rem; font-weight: 700; }
293
- & [data-part="empty"] { padding: 1rem; margin: 0; color: var(--ui-muted); }
154
+ --ui-cmd-ibb: var(--ui-border-w) solid var(--ui-line);
155
+ --ui-cmd-ibg: var(--ui-paper);
156
+ --ui-cmd-if: 600 0.95rem/1.3 var(--ui-font-body);
157
+ --ui-cmd-mf: 600 0.9rem/1.3 var(--ui-font-body);
158
+ --ui-cmd-hbg: var(--ui-accent);
159
+ --ui-cmd-hfg: var(--ui-on-accent);
160
+ & [data-part="kbd"] { color: currentColor; border: var(--ui-border-w) solid currentColor; font-weight: 700; }
294
161
  }
162
+
295
163
  [data-ui="datatable"] {
296
- display: flex;
297
- flex-direction: column;
298
- gap: 0.75rem;
299
- & [data-part="search"] {
300
- border: var(--ui-border-w) solid var(--ui-line);
301
- background: var(--ui-surface);
302
- color: var(--ui-ink);
303
- padding: 0.45rem 0.7rem;
304
- font: 600 0.88rem/1.3 var(--ui-font-body);
305
- }
306
- & [data-part="meta"] { font-size: 0.8rem; font-weight: 700; color: var(--ui-muted); }
307
- & table { border: var(--ui-border-w) solid var(--ui-line); background: var(--ui-surface); box-shadow: var(--ui-shadow); }
308
- & th { background: var(--ui-paper); border-bottom: var(--ui-border-w) solid var(--ui-line); padding: 0.55rem 0.7rem; font-size: 0.8rem; text-transform: uppercase; font-weight: 800; }
309
- & td { border-bottom: 1px solid var(--ui-line); padding: 0.6rem 0.7rem; }
310
- & tr[data-selected="true"] { background: color-mix(in srgb, var(--ui-accent) 16%, var(--ui-surface)); }
311
- & [data-part="sort"] { background: transparent; border: 0; padding: 0; font: inherit; text-transform: inherit; color: inherit; cursor: pointer; }
164
+ --ui-srch-bd: var(--ui-border-w) solid var(--ui-line);
165
+ --ui-tbl-bd: var(--ui-border-w) solid var(--ui-line);
166
+ --ui-tbl-bg: var(--ui-surface);
167
+ --ui-th-bb: var(--ui-border-w) solid var(--ui-line);
168
+ --ui-tbl-sel: color-mix(in srgb, var(--ui-accent) 16%, var(--ui-surface));
169
+ & table { box-shadow: var(--ui-shadow); }
170
+ & th { background: var(--ui-paper); text-transform: uppercase; font-weight: 800; }
312
171
  }
313
172
  }
@@ -0,0 +1,144 @@
1
+ // Static scanner detecting which `@prunellejs/ui` component parts a set of source files renders.
2
+ // Checks both named imports from `@prunellejs/ui` and literal `data-ui="..."` / `data-layout="..."` attributes.
3
+
4
+ import type { UiComponentPart } from './split'
5
+ import { existsSync, readFileSync } from 'node:fs'
6
+ import { resolve } from 'node:path'
7
+ import { UI_COMPONENT_PARTS, UI_EXPORT_TO_PARTS } from './split'
8
+
9
+ const PART_SET = new Set<string>(UI_COMPONENT_PARTS)
10
+ const UI_SRC_DIR = resolve(import.meta.dir, '..')
11
+
12
+ const IMPORT_STMT_RE = /import\s+(?!type\b)([\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g
13
+ const NAMED_LIST_RE = /\{([\s\S]*?)\}/
14
+ const NAMESPACE_RE = /\*\s+as\s+[A-Za-z_$]/
15
+ const DATA_UI_ATTR_RE = /\bdata-ui\s*=\s*(?:["']([^"']+)["']|\{([^}]*)\})/g
16
+ const DATA_LAYOUT_ATTR_RE = /\bdata-layout\s*=/
17
+ const STATIC_QUOTED_RE = /^\s*["']([^"']+)["']\s*$/
18
+
19
+ const DATA_UI_ALIASES: Readonly<Record<string, readonly UiComponentPart[]>> = {
20
+ 'table': ['datatable'],
21
+ 'toaster': ['toast'],
22
+ 'dialog-root': ['dialog', 'button', 'layout'],
23
+ 'drawer-root': ['drawer', 'button', 'layout'],
24
+ 'command-root': ['command', 'button'],
25
+ }
26
+
27
+ // prunelle's own components that render `data-ui` markup styled here.
28
+ const PRUNELLE_EXPORT_TO_PARTS: Readonly<Record<string, readonly UiComponentPart[]>> = {
29
+ ConsentBanner: ['consent', 'button'],
30
+ ConsentPreferences: ['consent', 'button'],
31
+ }
32
+
33
+ function isUiImportSource(specifier: string): boolean {
34
+ if (specifier === '@prunellejs/ui')
35
+ return true
36
+ // Tests and monorepo apps may import the workspace package entry directly.
37
+ return specifier.endsWith('/packages/ui/src/index.ts') || specifier.endsWith('/packages/ui/src/index')
38
+ }
39
+
40
+ function isInsideUiPackage(file: string): boolean {
41
+ const norm = file.replace(/\\/g, '/')
42
+ return norm.startsWith(`${UI_SRC_DIR.replace(/\\/g, '/')}/`)
43
+ || norm.includes('/node_modules/@prunellejs/ui/')
44
+ }
45
+
46
+ function addPartForAttr(value: string, out: Set<UiComponentPart>): void {
47
+ const aliased = DATA_UI_ALIASES[value]
48
+ if (aliased !== undefined) {
49
+ for (const p of aliased)
50
+ out.add(p)
51
+ return
52
+ }
53
+ if (PART_SET.has(value))
54
+ out.add(value as UiComponentPart)
55
+ }
56
+
57
+ export interface FileUiScan {
58
+ parts: readonly UiComponentPart[]
59
+ all: boolean
60
+ }
61
+
62
+ function scanSingleFile(file: string): FileUiScan {
63
+ if (isInsideUiPackage(file) || !existsSync(file))
64
+ return { parts: [], all: false }
65
+
66
+ const code = readFileSync(file, 'utf8')
67
+ const parts = new Set<UiComponentPart>()
68
+ let all = false
69
+
70
+ for (const match of code.matchAll(IMPORT_STMT_RE)) {
71
+ const clause = match[1]!
72
+ const source = match[2]!
73
+ const fromPrunelle = source === 'prunelle'
74
+ if (!fromPrunelle && !isUiImportSource(source))
75
+ continue
76
+ if (!fromPrunelle && NAMESPACE_RE.test(clause)) {
77
+ all = true
78
+ break
79
+ }
80
+ const named = NAMED_LIST_RE.exec(clause)
81
+ if (named !== null) {
82
+ for (const rawSpec of named[1]!.split(',')) {
83
+ const spec = rawSpec.trim()
84
+ if (spec === '' || spec.startsWith('type '))
85
+ continue
86
+ const imported = spec.split(/\s+as\s+/)[0]!.trim()
87
+ const mapped = (fromPrunelle ? PRUNELLE_EXPORT_TO_PARTS : UI_EXPORT_TO_PARTS)[imported]
88
+ if (mapped !== undefined) {
89
+ for (const p of mapped)
90
+ parts.add(p)
91
+ }
92
+ }
93
+ }
94
+ }
95
+
96
+ if (!all) {
97
+ if (DATA_LAYOUT_ATTR_RE.test(code))
98
+ parts.add('layout')
99
+ for (const match of code.matchAll(DATA_UI_ATTR_RE)) {
100
+ const literal = match[1]
101
+ if (literal !== undefined) {
102
+ addPartForAttr(literal, parts)
103
+ continue
104
+ }
105
+ const expr = match[2] ?? ''
106
+ const staticMatch = STATIC_QUOTED_RE.exec(expr)
107
+ if (staticMatch !== null) {
108
+ addPartForAttr(staticMatch[1]!, parts)
109
+ }
110
+ else {
111
+ all = true
112
+ break
113
+ }
114
+ }
115
+ }
116
+
117
+ return all
118
+ ? { parts: UI_COMPONENT_PARTS, all: true }
119
+ : { parts: [...parts], all: false }
120
+ }
121
+
122
+ /** Creates a per-build cached scanner resolving the set of `@prunellejs/ui` component parts used by a list of source files. */
123
+ export function createUiPartScanner(): (files: readonly string[]) => Set<UiComponentPart> {
124
+ const cache = new Map<string, FileUiScan>()
125
+ const scan = (file: string): FileUiScan => {
126
+ let entry = cache.get(file)
127
+ if (entry === undefined) {
128
+ entry = scanSingleFile(file)
129
+ cache.set(file, entry)
130
+ }
131
+ return entry
132
+ }
133
+ return (files: readonly string[]): Set<UiComponentPart> => {
134
+ const out = new Set<UiComponentPart>()
135
+ for (const file of files) {
136
+ const res = scan(file)
137
+ if (res.all)
138
+ return new Set(UI_COMPONENT_PARTS)
139
+ for (const p of res.parts)
140
+ out.add(p)
141
+ }
142
+ return out
143
+ }
144
+ }