@prunellejs/ui 0.8.0 → 0.10.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 (81) hide show
  1. package/llms.txt +4 -4
  2. package/package.json +3 -3
  3. package/src/CommandPalette.tsx +27 -29
  4. package/src/DataTable.tsx +64 -68
  5. package/src/Dialog.tsx +7 -7
  6. package/src/Menu.tsx +3 -5
  7. package/src/Select.tsx +33 -17
  8. package/src/Tabs.tsx +8 -9
  9. package/src/Toaster.tsx +4 -3
  10. package/src/labels/dialog.ts +7 -3
  11. package/src/labels/en/dialog.ts +11 -0
  12. package/src/labels/en/palette.ts +21 -0
  13. package/src/labels/en/select.ts +7 -0
  14. package/src/labels/en/table.ts +31 -0
  15. package/src/labels/en/toaster.ts +7 -0
  16. package/src/labels/fr/dialog.ts +7 -3
  17. package/src/labels/fr/palette.ts +12 -8
  18. package/src/labels/fr/select.ts +5 -1
  19. package/src/labels/fr/table.ts +17 -13
  20. package/src/labels/fr/toaster.ts +5 -1
  21. package/src/labels/palette.ts +7 -8
  22. package/src/labels/select.ts +7 -1
  23. package/src/labels/table.ts +7 -13
  24. package/src/labels/toaster.ts +7 -1
  25. package/src/locale.ts +15 -0
  26. package/src/platform-fallback.ts +7 -5
  27. package/src/plugin.ts +29 -10
  28. package/src/primitives.tsx +40 -41
  29. package/src/static.tsx +85 -20
  30. package/src/styles/bare.css +1 -1
  31. package/src/styles/base.css +3 -3
  32. package/src/styles/components/accordion.css +1 -1
  33. package/src/styles/components/badge.css +1 -1
  34. package/src/styles/components/button.css +1 -1
  35. package/src/styles/components/card.css +1 -1
  36. package/src/styles/components/checkbox.css +1 -1
  37. package/src/styles/components/command.css +1 -1
  38. package/src/styles/components/consent.css +1 -1
  39. package/src/styles/components/datatable.css +1 -1
  40. package/src/styles/components/dialog.css +1 -1
  41. package/src/styles/components/drawer.css +1 -1
  42. package/src/styles/components/field.css +1 -1
  43. package/src/styles/components/layout.css +1 -8
  44. package/src/styles/components/menu.css +1 -1
  45. package/src/styles/components/notice.css +1 -1
  46. package/src/styles/components/popover.css +1 -1
  47. package/src/styles/components/progress.css +1 -1
  48. package/src/styles/components/radio-group.css +1 -1
  49. package/src/styles/components/select.css +1 -1
  50. package/src/styles/components/switch.css +1 -1
  51. package/src/styles/components/tabs.css +1 -1
  52. package/src/styles/components/toast.css +1 -1
  53. package/src/styles/grammars/console.css +1 -1
  54. package/src/styles/grammars/editorial.css +1 -1
  55. package/src/styles/grammars/orbit.css +1 -1
  56. package/src/styles/grammars/prunelle.css +1 -1
  57. package/src/styles/grammars/soft.css +1 -1
  58. package/src/styles/grammars/workshop.css +1 -1
  59. package/src/styles/scan.ts +24 -4
  60. package/src/styles/split.ts +10 -10
  61. package/src/styles/theme.css +1 -1
  62. package/src/styles/themed/accordion.css +1 -1
  63. package/src/styles/themed/badge.css +1 -1
  64. package/src/styles/themed/button.css +1 -1
  65. package/src/styles/themed/card.css +1 -1
  66. package/src/styles/themed/checkbox.css +1 -1
  67. package/src/styles/themed/command.css +1 -1
  68. package/src/styles/themed/consent.css +1 -1
  69. package/src/styles/themed/datatable.css +1 -1
  70. package/src/styles/themed/dialog.css +1 -1
  71. package/src/styles/themed/drawer.css +1 -1
  72. package/src/styles/themed/field.css +1 -1
  73. package/src/styles/themed/menu.css +1 -1
  74. package/src/styles/themed/notice.css +1 -1
  75. package/src/styles/themed/popover.css +1 -1
  76. package/src/styles/themed/radio-group.css +1 -1
  77. package/src/styles/themed/select.css +1 -1
  78. package/src/styles/themed/switch.css +1 -1
  79. package/src/styles/themed/tabs.css +1 -1
  80. package/src/styles/themed/toast.css +1 -1
  81. package/src/table-state.ts +11 -5
package/src/static.tsx CHANGED
@@ -47,11 +47,14 @@ export interface ButtonProps {
47
47
  [attr: string]: unknown
48
48
  }
49
49
 
50
- function restProps(props: Record<string, unknown>, skip: readonly string[]): Record<string, unknown> {
50
+ export function restProps(props: Record<string, unknown>, skip: readonly string[]): Record<string, unknown> {
51
51
  const out: Record<string, unknown> = {}
52
52
  for (const k of Object.keys(props)) {
53
- if (k !== 'children' && !skip.includes(k))
54
- out[k] = props[k]
53
+ if (k !== 'children' && !skip.includes(k)) {
54
+ const desc = Object.getOwnPropertyDescriptor(props, k)
55
+ if (desc !== undefined)
56
+ Object.defineProperty(out, k, desc)
57
+ }
55
58
  }
56
59
  return out
57
60
  }
@@ -129,32 +132,51 @@ function scanOpeningTags(html: string): ScannedTag[] {
129
132
  }
130
133
 
131
134
  const NATIVE_CTRL_RE = /^(?:input|textarea|select)$/i
135
+ const ATTR_RE = /([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g
136
+ const CTRL_ROLES = new Set(['combobox', 'textbox', 'listbox', 'spinbutton'])
137
+
138
+ interface ScannedAttr {
139
+ name: string
140
+ value: string
141
+ start: number
142
+ end: number
143
+ }
144
+
145
+ /** The attributes of an opening tag by name, so `data-id` or a value holding `id=` is never taken for `id`. */
146
+ function readAttrs(raw: string): ScannedAttr[] {
147
+ return [...raw.matchAll(ATTR_RE)].map(m => ({ name: m[1]!.toLowerCase(), value: m[2] ?? m[3] ?? m[4] ?? '', start: m.index, end: m.index + m[0].length }))
148
+ }
132
149
 
133
150
  function wireFieldHtml(html: string, wiring: FieldControlWiring): string {
134
151
  const tags = scanOpeningTags(html)
135
- const target = tags.find(t => NATIVE_CTRL_RE.test(t.tag) && !(/\btype\s*=\s*(?:"hidden"|'hidden'|hidden\b)/i.test(t.rawAttrs) && /^input$/i.test(t.tag)))
136
- ?? tags.find(t => /\brole\s*=\s*["'](?:combobox|textbox|listbox|spinbutton)["']/i.test(t.rawAttrs))
152
+ const valueOf = (t: ScannedTag, name: string): string | undefined => readAttrs(t.rawAttrs).find(a => a.name === name)?.value.toLowerCase()
153
+ const target = tags.find(t => NATIVE_CTRL_RE.test(t.tag) && !(/^input$/i.test(t.tag) && valueOf(t, 'type') === 'hidden'))
154
+ ?? tags.find(t => CTRL_ROLES.has(valueOf(t, 'role') ?? ''))
137
155
  if (target === undefined)
138
156
  return html
139
157
 
140
158
  let attrs = target.rawAttrs
141
- if (!/\bid\s*=/i.test(attrs))
159
+ const find = (name: string) => readAttrs(attrs).find(a => a.name === name)
160
+ const replace = (a: ScannedAttr, text: string) => { attrs = `${attrs.slice(0, a.start)}${text}${attrs.slice(a.end)}` }
161
+ const id = find('id')
162
+ if (id === undefined)
142
163
  attrs += ` id="${escAttr(wiring.id)}"`
143
- else if (/\bid\s*=\s*"kui-[^"]*"/i.test(attrs))
144
- attrs = attrs.replace(/\bid\s*=\s*"kui-[^"]*"/i, `id="${escAttr(wiring.id)}"`)
164
+ else if (id.value.startsWith('pru-'))
165
+ replace(id, `id="${escAttr(wiring.id)}"`)
145
166
 
146
167
  if (wiring.describedBy) {
147
- const descRe = /(\baria-describedby\s*=\s*")([^"]*)(")/i
148
- attrs = descRe.test(attrs)
149
- ? attrs.replace(descRe, (_, p1: string, cur: string, p3: string) => `${p1}${escAttr(mergeTokenAttr(cur, wiring.describedBy!))}${p3}`)
150
- : `${attrs} aria-describedby="${escAttr(wiring.describedBy)}"`
168
+ const described = find('aria-describedby')
169
+ if (described === undefined)
170
+ attrs += ` aria-describedby="${escAttr(wiring.describedBy)}"`
171
+ else
172
+ replace(described, `aria-describedby="${escAttr(mergeTokenAttr(described.value, wiring.describedBy))}"`)
151
173
  }
152
- if (wiring.invalid && !/\baria-invalid\s*=/i.test(attrs))
174
+ if (wiring.invalid && find('aria-invalid') === undefined)
153
175
  attrs += ' aria-invalid="true"'
154
176
  if (wiring.required) {
155
- if (NATIVE_CTRL_RE.test(target.tag) && !/\brequired(?:\s|=|$)/i.test(attrs))
177
+ if (NATIVE_CTRL_RE.test(target.tag) && find('required') === undefined)
156
178
  attrs += ' required'
157
- if (!/\baria-required\s*=/i.test(attrs))
179
+ if (find('aria-required') === undefined)
158
180
  attrs += ' aria-required="true"'
159
181
  }
160
182
  return `${html.slice(0, target.start)}<${target.tag}${attrs}${target.selfClose}>${html.slice(target.end)}`
@@ -182,7 +204,7 @@ function syncFieldAria(el: Element, id: string, err: string | undefined, hint: s
182
204
 
183
205
  function wireFieldElement(el: Element, wiring: FieldControlWiring, err: string | undefined, hint: string | undefined): void {
184
206
  const curId = el.getAttribute('id')
185
- if (!curId || curId.startsWith('kui-'))
207
+ if (!curId || curId.startsWith('pru-'))
186
208
  el.setAttribute('id', wiring.id)
187
209
  syncFieldAria(el, wiring.id, err, hint, false)
188
210
  if (wiring.required) {
@@ -290,16 +312,59 @@ export type SpaceValue = SpaceToken | (string & {})
290
312
  export type TrackValue = TrackSize | (string & {})
291
313
 
292
314
  const SPACE_TOKENS = new Set<string>(['none', '2xs', 'xs', 'sm', 'md', 'lg', 'xl', '2xl'])
315
+ const UNSAFE_CSS_VALUE_RE = /[;{}\r\n\f\\"'`<>]|\/\*|\*\/|(?:^|[^\w-])(?:url|expression|image-set)\s*\(/i
293
316
 
294
317
  const isSpaceToken = (v: string | undefined): boolean => v !== undefined && SPACE_TOKENS.has(v)
295
318
 
319
+ /** Validates a custom CSS length/track value so inline custom properties reject `;`, `url(`, `expression(`, or unbalanced parens. */
320
+ export function safeCssLength(value: string | undefined): string | undefined {
321
+ if (value === undefined)
322
+ return undefined
323
+ const trimmed = value.trim()
324
+ if (trimmed === '' || UNSAFE_CSS_VALUE_RE.test(trimmed))
325
+ return undefined
326
+ let depth = 0
327
+ for (let i = 0; i < trimmed.length; i++) {
328
+ if (trimmed[i] === '(')
329
+ depth++
330
+ else if (trimmed[i] === ')' && --depth < 0)
331
+ return undefined
332
+ }
333
+ return depth === 0 ? trimmed : undefined
334
+ }
335
+
336
+ type StyleProp = string | Record<string, string | number | undefined> | undefined
337
+
338
+ /** Merges validated layout CSS custom properties (`--ui-gap`, `--ui-min`, `--ui-side`) with a caller's `style` prop. */
339
+ export function layoutStyle(
340
+ vars: Record<string, string | undefined>,
341
+ userStyle: unknown,
342
+ ): StyleProp {
343
+ const entries: Array<[string, string]> = []
344
+ for (const [k, raw] of Object.entries(vars)) {
345
+ const safe = safeCssLength(raw)
346
+ if (safe !== undefined)
347
+ entries.push([k, safe])
348
+ }
349
+ if (entries.length === 0)
350
+ return userStyle as StyleProp
351
+ if (typeof userStyle === 'string') {
352
+ const prefix = entries.map(([k, v]) => `${k}:${v}`).join(';')
353
+ const trimmed = userStyle.trim()
354
+ return trimmed === '' ? `${prefix};` : `${prefix};${trimmed}`
355
+ }
356
+ if (userStyle !== null && typeof userStyle === 'object')
357
+ return { ...Object.fromEntries(entries), ...(userStyle as Record<string, string | number | undefined>) }
358
+ return `${entries.map(([k, v]) => `${k}:${v}`).join(';')};`
359
+ }
360
+
296
361
  export function Stack(props: BoxProps & { gap?: SpaceValue | undefined }) {
297
- const rest = restProps(props, ['gap', 'class'])
362
+ const rest = restProps(props, ['gap', 'class', 'style'])
298
363
  return (
299
364
  <div
300
365
  data-layout="stack"
301
366
  data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
302
- data-gap-value={props.gap && !isSpaceToken(props.gap) ? props.gap : undefined}
367
+ style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
303
368
  class={props.class}
304
369
  {...rest}
305
370
  >
@@ -309,12 +374,12 @@ export function Stack(props: BoxProps & { gap?: SpaceValue | undefined }) {
309
374
  }
310
375
 
311
376
  export function Cluster(props: BoxProps & { gap?: SpaceValue | undefined }) {
312
- const rest = restProps(props, ['gap', 'class'])
377
+ const rest = restProps(props, ['gap', 'class', 'style'])
313
378
  return (
314
379
  <div
315
380
  data-layout="cluster"
316
381
  data-gap={isSpaceToken(props.gap) ? props.gap : undefined}
317
- data-gap-value={props.gap && !isSpaceToken(props.gap) ? props.gap : undefined}
382
+ style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
318
383
  class={props.class}
319
384
  {...rest}
320
385
  >
@@ -1,5 +1,5 @@
1
1
  /* @prunellejs/ui bare floor: behavior, layout primitives, accessibility & top-layer positioning only.
2
- * Everything sits inside @layer kui so Tailwind utilities and user CSS always win without !important. */
2
+ * Everything sits inside @layer pru-ui so Tailwind utilities and user CSS always win without !important. */
3
3
 
4
4
  @import './base.css';
5
5
  @import './components/layout.css';
@@ -1,14 +1,14 @@
1
1
  /* @prunellejs/ui base floor: box-sizing, screen-reader utility, single focus indicator, reduced motion & [hidden].
2
- * Everything sits inside @layer kui so Tailwind utilities and user CSS always win without !important. */
2
+ * Everything sits inside @layer pru-ui so Tailwind utilities and user CSS always win without !important. */
3
3
 
4
- @layer kui {
4
+ @layer pru-ui {
5
5
  [data-ui] *,
6
6
  [data-ui] *::before,
7
7
  [data-ui] *::after {
8
8
  box-sizing: border-box;
9
9
  }
10
10
 
11
- .kui-sr-only {
11
+ .pru-sr-only {
12
12
  position: absolute;
13
13
  width: 1px;
14
14
  height: 1px;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="accordion"] summary[data-part="trigger"] {
3
3
  list-style: none;
4
4
  cursor: pointer;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="badge"] {
3
3
  display: inline-flex;
4
4
  align-items: center;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="button"] {
3
3
  display: inline-flex;
4
4
  align-items: center;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="card"] {
3
3
  display: block;
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="checkbox"] {
3
3
  display: inline-flex;
4
4
  align-items: center;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  html:has(dialog[data-ui]:modal) { overflow: hidden; }
3
3
  /* The palette ends 1rem above the viewport's bottom; the input stays put and only the results scroll. */
4
4
  dialog[data-ui="command"] {
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  section[data-ui="consent"] {
3
3
  position: fixed;
4
4
  inset-inline: 1rem;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="datatable"] { display: flex; flex-direction: column; gap: var(--ui-table-gap, 0.75rem); }
3
3
  [data-ui="datatable"] [data-part="scroll"] { overflow-x: auto; }
4
4
  [data-ui="datatable"] [data-part="search"] { min-block-size: var(--ui-touch-min, auto); font-size: var(--ui-input-floor, inherit); }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  /* The page behind a modal does not scroll */
3
3
  html:has(dialog[data-ui]:modal) {
4
4
  overflow: hidden;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  html:has(dialog[data-ui]:modal) {
3
3
  overflow: hidden;
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="field"] {
3
3
  display: flex;
4
4
  flex-direction: column;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  /* Every Layout primitives (0 KB JS) */
3
3
  [data-layout="stack"] {
4
4
  display: flex;
@@ -59,11 +59,4 @@
59
59
  [data-layout="sidebar"][data-side="md"] { --ui-side: 16rem; }
60
60
  [data-layout="sidebar"][data-side="lg"] { --ui-side: 20rem; }
61
61
  [data-layout="sidebar"][data-side="xl"] { --ui-side: 24rem; }
62
-
63
- /* Progressive CSS Values 5 attr() support for custom CSS lengths without inline style attributes */
64
- @supports (gap: attr(data-gap-value type(<length-percentage>))) {
65
- [data-layout][data-gap-value] { --ui-gap: attr(data-gap-value type(<length-percentage>)); }
66
- [data-layout="grid"][data-min-value] { --ui-min: attr(data-min-value type(<length-percentage>)); }
67
- [data-layout="sidebar"][data-side-value] { --ui-side: attr(data-side-value type(<length-percentage>)); }
68
- }
69
62
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="menu"] {
3
3
  display: inline-block;
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="notice"] {
3
3
  display: block;
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="popover"][popover] {
3
3
  inset: auto;
4
4
  margin: 0;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  /* Progress: the native bar; a grammar may draw the eye instead */
3
3
  [data-ui="progress"] {
4
4
  display: inline-flex;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="radio-group"] { border: 0; padding: 0; margin: 0; }
3
3
  [data-ui="radio-group"] [data-part="options"] { display: flex; flex-direction: column; gap: 0.45rem; }
4
4
  [data-ui="radio-group"] [data-part="option"] {
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="select"] { display: inline-block; }
3
3
  [data-ui="select"] [data-part="trigger"] {
4
4
  display: inline-flex;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="switch"] {
3
3
  display: inline-flex;
4
4
  align-items: center;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="tabs"] [data-part="list"] { display: var(--ui-tab-disp, flex); }
3
3
  [data-ui="tabs"] [data-part="trigger"] { cursor: pointer; min-block-size: var(--ui-touch-min, auto); }
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="toaster"] {
3
3
  position: fixed;
4
4
  inset-block-end: 1rem;
@@ -3,7 +3,7 @@
3
3
 
4
4
  @import '../theme.css';
5
5
 
6
- @layer kui {
6
+ @layer pru-ui {
7
7
  :root {
8
8
  color-scheme: dark light;
9
9
  --ui-paper: light-dark(#f4f5f7, #0b0d10);
@@ -3,7 +3,7 @@
3
3
 
4
4
  @import '../theme.css';
5
5
 
6
- @layer kui {
6
+ @layer pru-ui {
7
7
  :root {
8
8
  color-scheme: light dark;
9
9
  --ui-paper: light-dark(#faf8f4, #141311);
@@ -5,7 +5,7 @@
5
5
 
6
6
  @import '../theme.css';
7
7
 
8
- @layer kui {
8
+ @layer pru-ui {
9
9
  :root {
10
10
  color-scheme: dark light;
11
11
  --ui-paper: light-dark(#eef1f6, #090c13);
@@ -10,7 +10,7 @@
10
10
  /* @part: radio-group, switch */
11
11
  @property --ui-lid-ink { syntax: '<color>'; inherits: true; initial-value: transparent; }
12
12
 
13
- @layer kui {
13
+ @layer pru-ui {
14
14
  :root {
15
15
  color-scheme: light dark;
16
16
  --ui-paper: light-dark(#f8f4ee, #130e16);
@@ -3,7 +3,7 @@
3
3
 
4
4
  @import '../theme.css';
5
5
 
6
- @layer kui {
6
+ @layer pru-ui {
7
7
  :root {
8
8
  color-scheme: light dark;
9
9
  --ui-paper: light-dark(#f8f9fb, #101216);
@@ -3,7 +3,7 @@
3
3
 
4
4
  @import '../theme.css';
5
5
 
6
- @layer kui {
6
+ @layer pru-ui {
7
7
  :root {
8
8
  color-scheme: light dark;
9
9
  --ui-paper: light-dark(#f1eadc, #181512);
@@ -1,5 +1,5 @@
1
1
  // Static scanner detecting which `@prunellejs/ui` component parts a set of source files renders.
2
- // Checks imports and re-exports from `@prunellejs/ui` plus literal `data-ui="..."` / `data-layout="..."` attributes.
2
+ // Checks imports, dynamic imports, requires and re-exports from `@prunellejs/ui` plus literal `data-ui="..."` / `data-layout="..."` attributes.
3
3
 
4
4
  import type { UiComponentPart } from './split'
5
5
  import { existsSync, readFileSync } from 'node:fs'
@@ -19,6 +19,7 @@ const IMPORT_EXPORT_RE = new RegExp(
19
19
  const NAMED_LIST_RE = /\{([\s\S]*?)\}/
20
20
  const NAMESPACE_RE = /^\s*\*(?:\s+as\s+[A-Za-z_$][\w$]*)?\s*$|,\s*\*\s+as\s+[A-Za-z_$][\w$]*/
21
21
  const COMMENT_RE = /\/\/[^\n]*|\/\*[\s\S]*?\*\//g
22
+ const MODULE_CALL_RE = /\b(?:import|require)\s*\(\s*['"]([^'"]+)['"]\s*\)/g
22
23
  const DATA_UI_ATTR_RE = /\bdata-ui\s*=\s*(?:["']([^"']+)["']|\{([^}]*)\})/g
23
24
  const DATA_LAYOUT_ATTR_RE = /\bdata-layout\s*=/
24
25
  const STATIC_QUOTED_RE = /^\s*["']([^"']+)["']\s*$/
@@ -35,6 +36,14 @@ const DATA_UI_ALIASES: Readonly<Record<string, readonly UiComponentPart[]>> = {
35
36
  const PRUNELLE_EXPORT_TO_PARTS: Readonly<Record<string, readonly UiComponentPart[]>> = {
36
37
  ConsentBanner: ['consent', 'button'],
37
38
  ConsentPreferences: ['consent', 'button'],
39
+ CookieTable: ['datatable'],
40
+ }
41
+
42
+ function addPrunelleParts(out: Set<UiComponentPart>): void {
43
+ for (const parts of Object.values(PRUNELLE_EXPORT_TO_PARTS)) {
44
+ for (const p of parts)
45
+ out.add(p)
46
+ }
38
47
  }
39
48
 
40
49
  function isUiImportSource(specifier: string): boolean {
@@ -80,9 +89,12 @@ function scanSingleFile(file: string): FileUiScan {
80
89
  const fromPrunelle = source === 'prunelle'
81
90
  if (!fromPrunelle && !isUiImportSource(source))
82
91
  continue
83
- if (!fromPrunelle && NAMESPACE_RE.test(clause)) {
84
- all = true
85
- break
92
+ if (NAMESPACE_RE.test(clause)) {
93
+ if (!fromPrunelle) {
94
+ all = true
95
+ break
96
+ }
97
+ addPrunelleParts(parts)
86
98
  }
87
99
  const named = NAMED_LIST_RE.exec(clause)
88
100
  if (named !== null) {
@@ -100,6 +112,14 @@ function scanSingleFile(file: string): FileUiScan {
100
112
  }
101
113
  }
102
114
 
115
+ // A dynamic import or a require hands over the whole module, so every part of it counts.
116
+ for (const match of code.matchAll(MODULE_CALL_RE)) {
117
+ if (isUiImportSource(match[1]!))
118
+ all = true
119
+ else if (match[1] === 'prunelle')
120
+ addPrunelleParts(parts)
121
+ }
122
+
103
123
  if (!all) {
104
124
  if (DATA_LAYOUT_ATTR_RE.test(code))
105
125
  parts.add('layout')
@@ -245,11 +245,11 @@ function scanTopBlocks(css: string): RawBlock[] {
245
245
  return blocks
246
246
  }
247
247
 
248
- function unwrapLayerKui(css: string): string {
248
+ function unwrapLayerPruUi(css: string): string {
249
249
  const blocks = scanTopBlocks(css)
250
250
  const inner: string[] = []
251
251
  for (const b of blocks) {
252
- if (/^@layer\s+kui\b/.test(b.prelude)) {
252
+ if (/^@layer\s+pru-ui\b/.test(b.prelude)) {
253
253
  const open = b.full.indexOf('{')
254
254
  const close = b.full.lastIndexOf('}')
255
255
  if (open !== -1 && close > open)
@@ -269,14 +269,14 @@ const cachedGrammars = new Map<GrammarName, ParsedGrammar>()
269
269
 
270
270
  function readBaseBody(): string {
271
271
  if (cachedBaseBody === undefined)
272
- cachedBaseBody = unwrapLayerKui(readFileSync(join(STYLES_DIR, 'base.css'), 'utf8'))
272
+ cachedBaseBody = unwrapLayerPruUi(readFileSync(join(STYLES_DIR, 'base.css'), 'utf8'))
273
273
  return cachedBaseBody
274
274
  }
275
275
 
276
276
  function readComponentBody(part: UiComponentPart): string {
277
277
  let body = cachedComponentBodies.get(part)
278
278
  if (body === undefined) {
279
- body = unwrapLayerKui(readFileSync(join(STYLES_DIR, 'components', `${part}.css`), 'utf8'))
279
+ body = unwrapLayerPruUi(readFileSync(join(STYLES_DIR, 'components', `${part}.css`), 'utf8'))
280
280
  cachedComponentBodies.set(part, body)
281
281
  }
282
282
  return body
@@ -286,7 +286,7 @@ function readThemedBody(part: UiComponentPart): string | null {
286
286
  let body = cachedThemedBodies.get(part)
287
287
  if (body === undefined) {
288
288
  const file = join(STYLES_DIR, 'themed', `${part}.css`)
289
- body = existsSync(file) ? unwrapLayerKui(readFileSync(file, 'utf8')) : null
289
+ body = existsSync(file) ? unwrapLayerPruUi(readFileSync(file, 'utf8')) : null
290
290
  cachedThemedBodies.set(part, body)
291
291
  }
292
292
  return body
@@ -310,7 +310,7 @@ function parseGrammar(grammar: GrammarName): ParsedGrammar {
310
310
  const partBlocks: TaggedBlock[] = []
311
311
 
312
312
  for (const top of scanTopBlocks(raw)) {
313
- if (/^@layer\s+kui\b/.test(top.prelude)) {
313
+ if (/^@layer\s+pru-ui\b/.test(top.prelude)) {
314
314
  const open = top.full.indexOf('{')
315
315
  const close = top.full.lastIndexOf('}')
316
316
  if (open === -1 || close <= open)
@@ -358,11 +358,11 @@ export function renderGrammarBaseCss(grammar: GrammarName): string {
358
358
  out.push(rule.css)
359
359
  }
360
360
  const layerBody = [readBaseBody(), ...parsed.baseBlocks].filter(Boolean).join('\n\n')
361
- out.push(`@layer kui {\n${layerBody}\n}`)
361
+ out.push(`@layer pru-ui {\n${layerBody}\n}`)
362
362
  return `${out.join('\n\n')}\n`
363
363
  }
364
364
 
365
- /** Returns ONLY the component CSS (structural + tokenized + grammar overrides) for `parts`, in deterministic cascade order inside `@layer kui`. */
365
+ /** Returns ONLY the component CSS (structural + tokenized + grammar overrides) for `parts`, in deterministic cascade order inside `@layer pru-ui`. */
366
366
  export function renderGrammarPartsCss(grammar: GrammarName, parts: Iterable<UiComponentPart>): string {
367
367
  const wanted = new Set<UiComponentPart>()
368
368
  for (const p of parts) {
@@ -397,7 +397,7 @@ export function renderGrammarPartsCss(grammar: GrammarName, parts: Iterable<UiCo
397
397
  }
398
398
  }
399
399
 
400
- out.push(`@layer kui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
400
+ out.push(`@layer pru-ui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
401
401
  return `${out.join('\n\n')}\n`
402
402
  }
403
403
 
@@ -424,6 +424,6 @@ export function renderGrammarCss(grammar: GrammarName): string {
424
424
  layerChunks.push(blk.css)
425
425
  }
426
426
 
427
- out.push(`@layer kui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
427
+ out.push(`@layer pru-ui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
428
428
  return `${out.join('\n\n')}\n`
429
429
  }
@@ -1,4 +1,4 @@
1
- /* @prunellejs/ui tokenized component layer: shared by all 6 themed grammars inside @layer kui. */
1
+ /* @prunellejs/ui tokenized component layer: shared by all 6 themed grammars inside @layer pru-ui. */
2
2
 
3
3
  @import './bare.css';
4
4
  @import './themed/button.css';
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="accordion"] details {
3
3
  border: var(--ui-acc-bd, none);
4
4
  border-bottom: var(--ui-acc-bb, var(--ui-acc-bd, none));
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="badge"] {
3
3
  font: var(--ui-badge-f, 600 0.74rem/1 var(--ui-font-body));
4
4
  padding: var(--ui-badge-pad, 0.25rem 0.55rem);
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="button"] {
3
3
  gap: var(--ui-btn-gap, 0.5rem);
4
4
  min-block-size: max(var(--ui-touch-min, 0px), var(--ui-btn-h, 0px));
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="card"] {
3
3
  border: var(--ui-card-bd, 1px solid var(--ui-line));
4
4
  border-radius: var(--ui-radius);
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="checkbox"] { font-size: var(--ui-chk-fs, inherit); }
3
3
  [data-ui="checkbox"] input { accent-color: var(--ui-chk-acc, var(--ui-accent-fill, var(--ui-accent))); }
4
4
  }
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  dialog[data-ui="command"] {
3
3
  border: var(--ui-dlg-bd, 1px solid var(--ui-line-strong));
4
4
  border-radius: var(--ui-dlg-r, var(--ui-radius));
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="consent"] {
3
3
  color: var(--ui-ink);
4
4
  font-family: var(--ui-font-body);
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="datatable"] {
3
3
  font-size: var(--ui-tbl-fs, inherit);
4
4
  & [data-part="search"] {
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  dialog[data-ui="dialog"] {
3
3
  border: var(--ui-dlg-bd, 1px solid var(--ui-line-strong));
4
4
  border-radius: var(--ui-dlg-r, var(--ui-radius));
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  dialog[data-ui="drawer"] {
3
3
  border: var(--ui-dlg-bd, 1px solid var(--ui-line-strong));
4
4
  border-radius: 0;
@@ -1,4 +1,4 @@
1
- @layer kui {
1
+ @layer pru-ui {
2
2
  [data-ui="field"] {
3
3
  gap: var(--ui-fld-gap, 0.35rem);
4
4