@prunellejs/ui 0.6.0 → 0.7.1

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 (46) hide show
  1. package/LICENSE +21 -0
  2. package/llms.txt +10 -8
  3. package/package.json +2 -2
  4. package/src/CommandPalette.tsx +14 -12
  5. package/src/DataTable.tsx +112 -43
  6. package/src/Dialog.tsx +4 -4
  7. package/src/Select.tsx +3 -2
  8. package/src/Tabs.tsx +2 -1
  9. package/src/Toaster.tsx +50 -86
  10. package/src/behaviors.ts +3 -7
  11. package/src/fold.ts +7 -0
  12. package/src/labels/dialog.ts +3 -0
  13. package/src/labels/fr/dialog.ts +3 -0
  14. package/src/labels/fr/palette.ts +8 -0
  15. package/src/labels/fr/select.ts +1 -0
  16. package/src/labels/fr/table.ts +13 -0
  17. package/src/labels/fr/toaster.ts +1 -0
  18. package/src/labels/palette.ts +8 -0
  19. package/src/labels/select.ts +1 -0
  20. package/src/labels/table.ts +13 -0
  21. package/src/labels/toaster.ts +1 -0
  22. package/src/plugin.ts +24 -5
  23. package/src/primitives.tsx +3 -2
  24. package/src/static.tsx +11 -6
  25. package/src/styles/bare.css +1 -0
  26. package/src/styles/base.css +6 -0
  27. package/src/styles/components/button.css +1 -1
  28. package/src/styles/components/consent.css +38 -0
  29. package/src/styles/grammars/console.css +1 -0
  30. package/src/styles/grammars/editorial.css +2 -1
  31. package/src/styles/grammars/orbit.css +7 -6
  32. package/src/styles/grammars/prunelle.css +56 -1
  33. package/src/styles/grammars/soft.css +10 -10
  34. package/src/styles/grammars/workshop.css +6 -5
  35. package/src/styles/scan.ts +10 -3
  36. package/src/styles/split.ts +48 -0
  37. package/src/styles/theme.css +1 -0
  38. package/src/styles/themed/button.css +4 -1
  39. package/src/styles/themed/command.css +1 -1
  40. package/src/styles/themed/consent.css +33 -0
  41. package/src/styles/themed/menu.css +2 -2
  42. package/src/styles/themed/select.css +2 -2
  43. package/src/styles/themed/switch.css +5 -0
  44. package/src/styles/themed/tabs.css +4 -1
  45. package/src/table-state.ts +53 -16
  46. package/src/toast.ts +50 -8
package/src/fold.ts ADDED
@@ -0,0 +1,7 @@
1
+ // Case and diacritic folding shared by the DataTable search and the CommandPalette filter, so "emile" finds "Émile".
2
+
3
+ const MARKS_RE = /\p{M}/gu
4
+
5
+ export function foldText(text: string): string {
6
+ return text.normalize('NFD').replace(MARKS_RE, '').toLowerCase()
7
+ }
@@ -0,0 +1,3 @@
1
+ export const close = 'Close'
2
+ export const dialog = 'Dialog'
3
+ export const drawer = 'Drawer'
@@ -0,0 +1,3 @@
1
+ export const close = 'Fermer'
2
+ export const dialog = 'Boîte de dialogue'
3
+ export const drawer = 'Panneau'
@@ -0,0 +1,8 @@
1
+ export const placeholder = 'Tapez une commande ou cherchez…'
2
+ export const input = 'Rechercher une commande'
3
+ export const palette = 'Palette de commandes'
4
+ export const trigger = 'Rechercher (⌘K)'
5
+ export const empty = 'Aucune commande ne correspond.'
6
+ export const noResults = 'Aucun résultat'
7
+ export const result = 'résultat'
8
+ export const results = 'résultats'
@@ -0,0 +1 @@
1
+ export const placeholder = 'Choisir…'
@@ -0,0 +1,13 @@
1
+ export const placeholder = 'Filtrer les lignes…'
2
+ export const search = 'Rechercher'
3
+ export const selectColumn = 'Sélection'
4
+ export const selectRow = 'Sélectionner la ligne'
5
+ export const selectAll = 'Sélectionner toutes les lignes'
6
+ export const ascending = 'croissant'
7
+ export const descending = 'décroissant'
8
+ export const rows = 'lignes'
9
+ export const selected = 'sélectionnées'
10
+ export const page = 'Page'
11
+ export const prev = 'Précédente'
12
+ export const next = 'Suivante'
13
+ export const empty = 'Aucune ligne ne correspond.'
@@ -0,0 +1 @@
1
+ export const dismiss = 'Fermer'
@@ -0,0 +1,8 @@
1
+ export const placeholder = 'Type a command or search...'
2
+ export const input = 'Search commands'
3
+ export const palette = 'Command palette'
4
+ export const trigger = 'Search (⌘K)'
5
+ export const empty = 'No matching commands.'
6
+ export const noResults = 'No results'
7
+ export const result = 'result'
8
+ export const results = 'results'
@@ -0,0 +1 @@
1
+ export const placeholder = 'Select…'
@@ -0,0 +1,13 @@
1
+ export const placeholder = 'Filter rows...'
2
+ export const search = 'Search'
3
+ export const selectColumn = 'Select'
4
+ export const selectRow = 'Select row'
5
+ export const selectAll = 'Select all rows'
6
+ export const ascending = 'ascending'
7
+ export const descending = 'descending'
8
+ export const rows = 'rows'
9
+ export const selected = 'selected'
10
+ export const page = 'Page'
11
+ export const prev = 'Prev'
12
+ export const next = 'Next'
13
+ export const empty = 'No matching rows.'
@@ -0,0 +1 @@
1
+ export const dismiss = 'Dismiss'
package/src/plugin.ts CHANGED
@@ -1,12 +1,13 @@
1
1
  // @prunellejs/ui PrunellePlugin — wires a pure CSS Grammar (`editorial | workshop | console | soft | orbit | prunelle | bare`)
2
2
  // and adds `prunelle ui-eject <grammar> [dest]` so apps can copy & own the entire look in ONE CSS file.
3
3
 
4
+ import type { BunPlugin } from 'bun'
4
5
  import type { BuildPluginContext, PrunellePlugin } from 'prunelle/config'
5
6
  import type { GrammarName, UiComponentPart } from './styles/split'
6
7
  import { createHash } from 'node:crypto'
7
8
  import { mkdirSync, writeFileSync } from 'node:fs'
8
- import { dirname, resolve } from 'node:path'
9
- import { definePlugin, minifyCss, serviceKey } from 'prunelle/config'
9
+ import { dirname, join, resolve } from 'node:path'
10
+ import { definePlugin, minifyCss, UI_KUI_LAYER_SERVICE } from 'prunelle/config'
10
11
  import { FALLBACK_FILE, FALLBACK_GUARD, FALLBACK_JS, withPlatformFallback } from './platform-fallback'
11
12
  import { createUiPartScanner } from './styles/scan'
12
13
  import {
@@ -29,10 +30,8 @@ export {
29
30
  }
30
31
  export type { GrammarName, UiComponentPart }
31
32
 
32
- const UI_KUI_LAYER_SERVICE = serviceKey<boolean>('prunelle.ui.kuiLayer')
33
-
34
33
  /** Returns the self-contained CSS source for a grammar (with `base.css` and component sheets inlined). */
35
- export function renderGrammarCss(grammar: GrammarName, _bareCss?: string): string {
34
+ export function renderGrammarCss(grammar: GrammarName): string {
36
35
  return renderFullGrammarCss(grammar)
37
36
  }
38
37
 
@@ -128,6 +127,25 @@ function emitGrammarStyles(ctx: BuildPluginContext, grammar: GrammarName): void
128
127
  }
129
128
  }
130
129
 
130
+ const LABELS_DIR = join(import.meta.dir, 'labels')
131
+ const LABELS_FILTER = new RegExp(`^${LABELS_DIR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[\\\\/](\\w+)\\.ts$`)
132
+ const FRENCH_RE = /^fr(?:-|$)/i
133
+
134
+ // A French app loads labels/fr/<name>.ts wherever ui imports labels/<name>.ts, so each island ships its own labels in one language.
135
+ function frenchLabels(lang: string | undefined): BunPlugin[] {
136
+ if (lang === undefined || !FRENCH_RE.test(lang))
137
+ return []
138
+ return [{
139
+ name: 'prunelle-ui-labels',
140
+ setup(build) {
141
+ build.onLoad({ filter: LABELS_FILTER }, async args => ({
142
+ contents: await Bun.file(join(LABELS_DIR, 'fr', `${LABELS_FILTER.exec(args.path)![1]}.ts`)).text(),
143
+ loader: 'ts',
144
+ }))
145
+ },
146
+ }]
147
+ }
148
+
131
149
  export function ui(options: UiPluginOptions = {}): PrunellePlugin {
132
150
  const grammar = options.grammar === undefined ? 'editorial' : options.grammar
133
151
  const emit = resolveEmitGrammars(options.emitGrammars)
@@ -135,6 +153,7 @@ export function ui(options: UiPluginOptions = {}): PrunellePlugin {
135
153
  return definePlugin({
136
154
  name: '@prunellejs/ui',
137
155
  inlineScripts: [FALLBACK_GUARD],
156
+ bunPlugins: ({ lang }) => frenchLabels(lang),
138
157
  build(ctx) {
139
158
  ctx.emitAsset(FALLBACK_FILE, FALLBACK_JS)
140
159
  if (grammar !== false) {
@@ -150,7 +150,8 @@ export interface CheckControlProps {
150
150
  id?: string | undefined
151
151
  name?: string | undefined
152
152
  value?: string | undefined
153
- label: string
153
+ /** Text or markup (a link to the privacy policy); it sits inside the wrapping `<label>`, so it names the control. */
154
+ label: PrunelleChild
154
155
  checked?: boolean | undefined
155
156
  disabled?: boolean | undefined
156
157
  class?: string | undefined
@@ -178,7 +179,7 @@ export function Switch({ id, name, value, label, checked, disabled, class: cls,
178
179
 
179
180
  export interface RadioOption {
180
181
  value: string
181
- label: string
182
+ label: PrunelleChild
182
183
  hint?: string | undefined
183
184
  disabled?: boolean | undefined
184
185
  }
package/src/static.tsx CHANGED
@@ -59,8 +59,9 @@ function restProps(props: Record<string, unknown>, skip: readonly string[]): Rec
59
59
  export function Button(props: ButtonProps) {
60
60
  const rest = restProps(props as unknown as Record<string, unknown>, ['variant', 'tone', 'size', 'href', 'type', 'disabled', 'class'])
61
61
  if (props.href !== undefined) {
62
+ // A disabled link drops its href, so it neither follows nor takes focus, as a disabled <button> does.
62
63
  return (
63
- <a data-ui="button" data-variant={props.variant ?? 'solid'} data-tone={props.tone} data-size={props.size ?? 'md'} href={props.href} class={props.class} {...rest}>
64
+ <a data-ui="button" data-variant={props.variant ?? 'solid'} data-tone={props.tone} data-size={props.size ?? 'md'} href={props.disabled ? undefined : props.href} aria-disabled={props.disabled ? 'true' : undefined} class={props.class} {...rest}>
64
65
  {props.children}
65
66
  </a>
66
67
  )
@@ -80,7 +81,8 @@ export function Notice(props: BoxProps & { tone?: Tone | undefined, role?: 'stat
80
81
  /** Zero-JS form field wrapper that auto-wires `for`, `aria-describedby`, `aria-invalid`, hints, and action errors. */
81
82
  export interface FieldProps {
82
83
  id: string
83
- label: string
84
+ /** Text or markup; it sits inside the `<label for>` that names the control. */
85
+ label: PrunelleChild
84
86
  hint?: string | undefined
85
87
  error?: string | undefined
86
88
  required?: boolean | undefined
@@ -166,7 +168,7 @@ function syncFieldAria(el: Element, id: string, err: string | undefined, hint: s
166
168
  const tokens = (el.getAttribute('aria-describedby') ?? '').split(/\s+/).filter(t => t && t !== errId && t !== hintId)
167
169
  if (err)
168
170
  tokens.push(errId)
169
- else if (hint)
171
+ if (hint)
170
172
  tokens.push(hintId)
171
173
  if (tokens.length > 0)
172
174
  el.setAttribute('aria-describedby', tokens.join(' '))
@@ -201,6 +203,9 @@ function findFieldControlInNode(node: Node): Element | null {
201
203
 
202
204
  const RAW_HTML_BRAND = Symbol.for('pru.html')
203
205
 
206
+ // The client build defines it, which drops the server-rendered HTML wiring (and its tag scanner) from islands: there a child is a DOM node.
207
+ declare const PRUNELLE_BROWSER: boolean | undefined
208
+
204
209
  function wireFieldChildren(
205
210
  children: PrunelleChild,
206
211
  wiring: FieldControlWiring,
@@ -213,7 +218,7 @@ function wireFieldChildren(
213
218
  return children
214
219
  if (Array.isArray(children))
215
220
  return children.map(child => (state.done ? child : wireFieldChildren(child, wiring, err, hint, onControl, state)))
216
- if ('__html' in children && (children as unknown as Record<symbol, unknown>)[RAW_HTML_BRAND] === true) {
221
+ if ((typeof PRUNELLE_BROWSER === 'undefined' || !PRUNELLE_BROWSER) && '__html' in children && (children as unknown as Record<symbol, unknown>)[RAW_HTML_BRAND] === true) {
217
222
  const src = (children as Html).__html
218
223
  const patched = wireFieldHtml(src, wiring)
219
224
  if (patched !== src) {
@@ -261,7 +266,7 @@ export function Field(props: FieldProps) {
261
266
  {(() => {
262
267
  const wiring: FieldControlWiring = {
263
268
  id: props.id,
264
- describedBy: lastError ? `${props.id}-error` : props.hint ? `${props.id}-hint` : undefined,
269
+ describedBy: [lastError && `${props.id}-error`, props.hint && `${props.id}-hint`].filter(Boolean).join(' ') || undefined,
265
270
  invalid: Boolean(lastError),
266
271
  required: Boolean(props.required),
267
272
  }
@@ -271,7 +276,7 @@ export function Field(props: FieldProps) {
271
276
  ownedInvalid = true
272
277
  }))
273
278
  })()}
274
- {props.hint && !props.error && <p data-part="hint" id={`${props.id}-hint`}>{props.hint}</p>}
279
+ {props.hint && <p data-part="hint" id={`${props.id}-hint`}>{props.hint}</p>}
275
280
  {props.error && <p data-part="error" id={`${props.id}-error`} role="alert">{props.error}</p>}
276
281
  </div>
277
282
  )
@@ -7,6 +7,7 @@
7
7
  @import './components/card.css';
8
8
  @import './components/badge.css';
9
9
  @import './components/notice.css';
10
+ @import './components/consent.css';
10
11
  @import './components/field.css';
11
12
  @import './components/checkbox.css';
12
13
  @import './components/switch.css';
@@ -52,4 +52,10 @@
52
52
  [hidden] {
53
53
  display: none !important;
54
54
  }
55
+
56
+ /* Windows high contrast drops backgrounds and box-shadows, so each state drawn with them is redrawn with system colors, here and in each component's themed sheet; `:root` outranks the themed and grammar rules. */
57
+ @media (forced-colors: active) {
58
+ :root [data-ui] [data-highlighted="true"] { outline: 2px solid Highlight; outline-offset: -2px; }
59
+ :root [data-ui][data-disabled="true"] { color: GrayText; }
60
+ }
55
61
  }
@@ -6,6 +6,6 @@
6
6
  min-block-size: var(--ui-touch-min, auto);
7
7
  text-decoration: none;
8
8
  cursor: pointer;
9
- &:disabled { cursor: not-allowed; }
9
+ &:disabled, &[aria-disabled="true"] { cursor: not-allowed; }
10
10
  }
11
11
  }
@@ -0,0 +1,38 @@
1
+ @layer kui {
2
+ section[data-ui="consent"] {
3
+ position: fixed;
4
+ inset-inline: 1rem;
5
+ inset-block-end: 1rem;
6
+ z-index: 50;
7
+ max-inline-size: 40rem;
8
+ max-block-size: calc(100dvh - 2rem);
9
+ margin-inline: auto;
10
+ overflow: auto;
11
+ }
12
+ /* Refuse and Accept share the banner row at one width; on a page the preferences buttons keep their own. */
13
+ section[data-ui="consent"] [data-part="actions"] > button {
14
+ flex: 1 1 10rem;
15
+ }
16
+ [data-ui="consent"] {
17
+ & [data-part="actions"] {
18
+ display: flex;
19
+ flex-wrap: wrap;
20
+ gap: 0.5rem;
21
+ }
22
+ & [data-part="choices"] {
23
+ display: grid;
24
+ margin: 0;
25
+ padding: 0;
26
+ border: 0;
27
+ }
28
+ & [data-part="choice"] {
29
+ display: flex;
30
+ align-items: center;
31
+ gap: 0.5rem;
32
+ min-block-size: 2.75rem;
33
+ }
34
+ & [data-part="details"] > summary {
35
+ padding-block: 0.75rem;
36
+ }
37
+ }
38
+ }
@@ -98,6 +98,7 @@
98
98
  --ui-tab-f: 600 0.76rem/1 var(--ui-font-body);
99
99
  --ui-tab-afg: var(--ui-accent);
100
100
  --ui-tab-abg: var(--ui-surface);
101
+ --ui-tab-aind: inset 0 2px 0 var(--ui-accent);
101
102
  --ui-tab-ppad: 0.85rem 0 0;
102
103
  & [data-part="trigger"] { border-bottom: 0; &[data-state="active"] { border-color: var(--ui-line); margin-bottom: -1px; } }
103
104
  }
@@ -17,7 +17,7 @@
17
17
  --ui-success: light-dark(#2f6f44, #6ec488);
18
18
  --ui-warning: light-dark(#875900, #e3b341);
19
19
  --ui-danger: light-dark(#b42318, #f97066);
20
- --ui-font-body: 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
21
  --ui-font-display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
22
22
  --ui-radius: 0px;
23
23
  --ui-density: 1.1;
@@ -91,6 +91,7 @@
91
91
  --ui-tab-pad: 0.65rem 0;
92
92
  --ui-tab-f: 500 0.92rem/1 var(--ui-font-body);
93
93
  --ui-tab-ppad: 1.25rem 0 0;
94
+ --ui-tab-aind: none;
94
95
  & [data-part="trigger"] { border-bottom: 2px solid transparent; margin-bottom: -1px; &[data-state="active"] { border-bottom-color: var(--ui-ink); } }
95
96
  }
96
97
 
@@ -23,8 +23,8 @@
23
23
  --ui-success: light-dark(#1f6f4a, #7fd8a6);
24
24
  --ui-warning: light-dark(#8a4f06, #e6c07b);
25
25
  --ui-danger: light-dark(#a81f15, #ff6b6b);
26
- --ui-font-display: 'Chakra Petch', 'Space Grotesk', system-ui, sans-serif;
27
- --ui-font-body: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
26
+ --ui-font-display: 'Chakra Petch', 'Space Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
27
+ --ui-font-body: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans', 'Helvetica Neue', Arial, sans-serif;
28
28
  --ui-font-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', Menlo, Consolas, monospace;
29
29
  --ui-radius: 4px;
30
30
  --ui-radius-inner: 3px;
@@ -118,10 +118,10 @@
118
118
  --ui-btn-sm-pad: 0.36rem 0.65rem;
119
119
  --ui-btn-lg-fs: 0.92rem;
120
120
  --ui-btn-lg-pad: 0.68rem 1.2rem;
121
- &:hover:not(:disabled) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
122
- &[data-variant="ghost"] { color: var(--ui-subtext); &:hover:not(:disabled) { background: var(--ui-surface); color: var(--ui-ink); border-color: var(--ui-line); } }
123
- &[data-tone="accent"] { font-weight: 600; &:hover:not(:disabled) { filter: brightness(1.06); } }
124
- &[data-tone="danger"] { background: color-mix(in srgb, var(--ui-danger) 12%, var(--ui-surface)); border-color: color-mix(in srgb, var(--ui-danger) 55%, transparent); color: var(--ui-danger); &:hover:not(:disabled) { background: var(--ui-danger); border-color: var(--ui-danger); color: var(--ui-on-accent); } }
121
+ &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface-strong); border-color: color-mix(in srgb, var(--ui-accent) 55%, var(--ui-line-strong)); }
122
+ &[data-variant="ghost"] { color: var(--ui-subtext); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-surface); color: var(--ui-ink); border-color: var(--ui-line); } }
123
+ &[data-tone="accent"] { font-weight: 600; &:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); } }
124
+ &[data-tone="danger"] { background: color-mix(in srgb, var(--ui-danger) 12%, var(--ui-surface)); border-color: color-mix(in srgb, var(--ui-danger) 55%, transparent); color: var(--ui-danger); &:hover:not(:disabled, [aria-disabled="true"]) { background: var(--ui-danger); border-color: var(--ui-danger); color: var(--ui-on-accent); } }
125
125
  }
126
126
 
127
127
  [data-ui="card"] {
@@ -186,6 +186,7 @@
186
186
  --ui-tab-pad: 0.42rem 0.85rem;
187
187
  --ui-tab-f: 500 0.78rem/1.2 var(--ui-font-mono);
188
188
  --ui-tab-abg: var(--ui-surface);
189
+ --ui-tab-aind: inset 0 2px 0 var(--ui-accent);
189
190
  --ui-tab-ppad: 0.95rem;
190
191
  & [data-part="trigger"] { border-bottom: 0; border-radius: var(--ui-radius) var(--ui-radius) 0 0; &[data-state="active"] { border-color: var(--ui-line); margin-bottom: -1px; } }
191
192
  & [data-part="panel"] { border: 1px solid var(--ui-line); border-top: 0; border-radius: 0 0 var(--ui-radius) var(--ui-radius); background: var(--ui-surface); }
@@ -145,7 +145,7 @@
145
145
  --ui-tab-pad: 8px 0;
146
146
  --ui-tab-f: 400 0.8125rem/1.3 var(--ui-font-body);
147
147
  --ui-tab-ppad: 14px 0 0;
148
- & [data-part="trigger"] { margin-block-end: -1px; &[data-state="active"] { box-shadow: inset 0 -2px 0 var(--ui-accent); } }
148
+ & [data-part="trigger"] { margin-block-end: -1px; }
149
149
  }
150
150
 
151
151
  dialog[data-ui="dialog"],
@@ -220,6 +220,17 @@
220
220
  }
221
221
  }
222
222
  }
223
+ /* @part: checkbox */
224
+ @media (forced-colors: active) {
225
+ :root [data-ui="checkbox"] input[type="checkbox"] {
226
+ border: 1.5px solid ButtonText;
227
+ background: Canvas;
228
+ &:checked { border-color: Highlight; background: Highlight; }
229
+ &:checked::after { border-color: HighlightText; }
230
+ &:disabled { border-color: GrayText; }
231
+ &:disabled:checked { border-color: GrayText; background: GrayText; }
232
+ }
233
+ }
223
234
 
224
235
  /* The eye. A shut eye is its lower lid, a curve painted as the control's background; opening it fades the lid, grows the almond (::before) to full height and shows the pupil (::after), an upright oval. */
225
236
  [data-ui="radio-group"] input[type="radio"],
@@ -281,6 +292,20 @@
281
292
  &:disabled { cursor: not-allowed; }
282
293
  }
283
294
  }
295
+ /* @part: radio-group */
296
+ @media (forced-colors: active) {
297
+ :root [data-ui="radio-group"] input[type="radio"] {
298
+ border: 1.5px solid ButtonText;
299
+ border-radius: 50%;
300
+ background: Canvas;
301
+ &::before { display: none; }
302
+ &::after { inline-size: 50%; block-size: 50%; background: HighlightText; }
303
+ &:checked { border-color: Highlight; background: Highlight; }
304
+ &:checked::after { opacity: 1; transform: none; }
305
+ &:disabled { border-color: GrayText; }
306
+ &:disabled:checked { border-color: GrayText; background: GrayText; }
307
+ }
308
+ }
284
309
 
285
310
  /* Switch: the input is the visible track (and carries base.css's focus-visible ring), the track part its sliding eye knob. */
286
311
  [data-ui="switch"] {
@@ -332,6 +357,36 @@
332
357
  inset-inline-start: 18px;
333
358
  &::after { inset-inline-start: auto; transform: scaleY(var(--ui-lid)); }
334
359
  }
360
+ /* @part: switch */
361
+ @media (forced-colors: active) {
362
+ :root [data-ui="switch"] input[type="checkbox"] {
363
+ border: 1.5px solid ButtonText;
364
+ background: Canvas;
365
+ &:checked { border-color: Highlight; background: Highlight; }
366
+ &:disabled { border-color: GrayText; }
367
+ &:disabled:checked { border-color: GrayText; background: GrayText; }
368
+ }
369
+ :root [data-ui="switch"] [data-part="track"] {
370
+ border: 1.5px solid ButtonText;
371
+ background: Canvas;
372
+ &::before { display: none; }
373
+ &::after { inline-size: 6px; block-size: 6px; border-radius: 50%; opacity: 1; transform: none; background: ButtonText; }
374
+ }
375
+ :root [data-ui="switch"] input:checked + [data-part="track"] {
376
+ border-color: HighlightText;
377
+ background: Highlight;
378
+ &::after { background: HighlightText; }
379
+ }
380
+ :root [data-ui="switch"] input:disabled + [data-part="track"] {
381
+ border-color: GrayText;
382
+ &::after { background: GrayText; }
383
+ }
384
+ :root [data-ui="switch"] input:disabled:checked + [data-part="track"] {
385
+ border-color: Canvas;
386
+ background: GrayText;
387
+ &::after { background: Canvas; }
388
+ }
389
+ }
335
390
 
336
391
  /* Progress: the native bar stays for assistive tech and the eye shows it. */
337
392
  [data-ui="progress"] {
@@ -17,7 +17,7 @@
17
17
  --ui-success: light-dark(#116630, #4ade80);
18
18
  --ui-warning: light-dark(#8f420a, #fbbf24);
19
19
  --ui-danger: light-dark(#b91c1c, #f87171);
20
- --ui-font-body: 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
21
  --ui-radius: 12px;
22
22
  --ui-pill: 999px;
23
23
  --ui-motion: 180ms;
@@ -29,9 +29,9 @@
29
29
  --ui-btn-r: var(--ui-pill);
30
30
  --ui-btn-bd: 0;
31
31
  --ui-btn-bg: var(--ui-surface-2);
32
- &:hover:not(:disabled) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
33
- &:active:not(:disabled) { transform: scale(0.98); }
34
- &[data-tone="accent"]:hover:not(:disabled), &[data-tone="danger"]:hover:not(:disabled) { filter: brightness(1.06); }
32
+ &:hover:not(:disabled, [aria-disabled="true"]) { background: color-mix(in srgb, var(--ui-ink) 12%, var(--ui-surface-2)); }
33
+ &:active:not(:disabled, [aria-disabled="true"]) { transform: scale(0.98); }
34
+ &[data-tone="accent"]:hover:not(:disabled, [aria-disabled="true"]), &[data-tone="danger"]:hover:not(:disabled, [aria-disabled="true"]) { filter: brightness(1.06); }
35
35
  &[data-variant="outline"] { box-shadow: inset 0 0 0 1.5px var(--ui-line-strong); }
36
36
  }
37
37
 
@@ -81,8 +81,9 @@
81
81
  --ui-tab-pad: 0.45rem 1rem;
82
82
  --ui-tab-f: 600 0.86rem/1 var(--ui-font-body);
83
83
  --ui-tab-abg: var(--ui-surface);
84
+ --ui-tab-aind: inset 0 0 0 1.5px var(--ui-line-strong), 0 1px 4px rgb(0 0 0 / 0.08);
84
85
  & [data-part="list"] { padding: 0.25rem; border-radius: var(--ui-pill); background: var(--ui-surface-2); }
85
- & [data-part="trigger"] { border-radius: var(--ui-pill); &[data-state="active"] { box-shadow: 0 1px 4px rgb(0 0 0 / 0.08); } }
86
+ & [data-part="trigger"] { border-radius: var(--ui-pill); }
86
87
  }
87
88
 
88
89
  dialog[data-ui="dialog"],
@@ -106,10 +107,9 @@
106
107
 
107
108
  [data-ui="select"] {
108
109
  --ui-sel-bg: var(--ui-surface-2);
109
- --ui-sel-bd: 0;
110
+ --ui-sel-bd: 1.5px solid var(--ui-line-strong);
110
111
  --ui-sel-r: 10px;
111
112
  --ui-sel-pad: 0.55rem 0.9rem;
112
- & [data-part="option"][data-selected="true"] { font-weight: 600; }
113
113
  }
114
114
 
115
115
  [data-ui="toast"] {
@@ -119,7 +119,7 @@
119
119
  }
120
120
 
121
121
  [data-ui="switch"] {
122
- --ui-sw-bd: 0;
122
+ --ui-sw-bd: 1.5px solid var(--ui-line-strong);
123
123
  --ui-sw-r: var(--ui-pill);
124
124
  --ui-sw-bg: var(--ui-surface-2);
125
125
  --ui-sw-th: var(--ui-surface);
@@ -134,7 +134,7 @@
134
134
  }
135
135
 
136
136
  dialog[data-ui="command"] {
137
- --ui-cmd-ibb: 0;
137
+ --ui-cmd-ibb: 1.5px solid var(--ui-line-strong);
138
138
  --ui-cmd-ibg: var(--ui-surface-2);
139
139
  --ui-cmd-ipad: 0.9rem 1.1rem;
140
140
  --ui-cmd-hbg: var(--ui-surface-2);
@@ -144,7 +144,7 @@
144
144
 
145
145
  [data-ui="datatable"] {
146
146
  --ui-table-gap: 0.85rem;
147
- --ui-srch-bd: 0;
147
+ --ui-srch-bd: 1.5px solid var(--ui-line-strong);
148
148
  --ui-srch-r: var(--ui-pill);
149
149
  --ui-srch-bg: var(--ui-surface-2);
150
150
  --ui-srch-pad: 0.5rem 0.95rem;
@@ -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);
@@ -33,10 +33,10 @@
33
33
  letter-spacing: 0.04em;
34
34
  text-transform: uppercase;
35
35
  box-shadow: var(--ui-press-shadow);
36
- &:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ui-line); }
37
- &:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ui-line); }
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
38
  &[data-tone="accent"], &[data-tone="danger"], &[data-variant="outline"] { border-color: var(--ui-line); }
39
- &[data-variant="ghost"]:hover:not(:disabled) { border-color: var(--ui-line); transform: none; box-shadow: none; }
39
+ &[data-variant="ghost"]:hover:not(:disabled, [aria-disabled="true"]) { border-color: var(--ui-line); transform: none; box-shadow: none; }
40
40
  }
41
41
 
42
42
  [data-ui="card"] {
@@ -100,6 +100,7 @@
100
100
  --ui-tab-fg: var(--ui-ink);
101
101
  --ui-tab-abg: var(--ui-accent);
102
102
  --ui-tab-afg: var(--ui-on-accent);
103
+ --ui-tab-aind: none;
103
104
  & [data-part="list"] { border: var(--ui-border-w) solid var(--ui-line); background: var(--ui-paper); }
104
105
  & [data-part="trigger"] { border-right: var(--ui-border-w) solid var(--ui-line); text-transform: uppercase; &:last-child { border-right: 0; } }
105
106
  }
@@ -24,6 +24,12 @@ const DATA_UI_ALIASES: Readonly<Record<string, readonly UiComponentPart[]>> = {
24
24
  'command-root': ['command', 'button'],
25
25
  }
26
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
+
27
33
  function isUiImportSource(specifier: string): boolean {
28
34
  if (specifier === '@prunellejs/ui')
29
35
  return true
@@ -64,9 +70,10 @@ function scanSingleFile(file: string): FileUiScan {
64
70
  for (const match of code.matchAll(IMPORT_STMT_RE)) {
65
71
  const clause = match[1]!
66
72
  const source = match[2]!
67
- if (!isUiImportSource(source))
73
+ const fromPrunelle = source === 'prunelle'
74
+ if (!fromPrunelle && !isUiImportSource(source))
68
75
  continue
69
- if (NAMESPACE_RE.test(clause)) {
76
+ if (!fromPrunelle && NAMESPACE_RE.test(clause)) {
70
77
  all = true
71
78
  break
72
79
  }
@@ -77,7 +84,7 @@ function scanSingleFile(file: string): FileUiScan {
77
84
  if (spec === '' || spec.startsWith('type '))
78
85
  continue
79
86
  const imported = spec.split(/\s+as\s+/)[0]!.trim()
80
- const mapped = UI_EXPORT_TO_PARTS[imported]
87
+ const mapped = (fromPrunelle ? PRUNELLE_EXPORT_TO_PARTS : UI_EXPORT_TO_PARTS)[imported]
81
88
  if (mapped !== undefined) {
82
89
  for (const p of mapped)
83
90
  parts.add(p)
@@ -15,6 +15,7 @@ export const UI_COMPONENT_PARTS = [
15
15
  'card',
16
16
  'badge',
17
17
  'notice',
18
+ 'consent',
18
19
  'field',
19
20
  'checkbox',
20
21
  'switch',
@@ -95,6 +96,50 @@ const DATA_UI_RE = /\[data-ui="([^"]+)"\]/g
95
96
  const DATA_LAYOUT_RE = /\[data-layout(?:="[^"]*")?\]/
96
97
  const PART_TAG_RE = /\/\*\s*@part:\s*([^*]+?)\s*\*\//
97
98
  const LEADING_COMMENT_RE = /^\s*(\/\*[\s\S]*?\*\/)/
99
+ const ROOT_BLOCK_RE = /^\s*:root\s*\{([^{}]*)\}\s*$/
100
+
101
+ const LIGHT_DARK = 'light-dark('
102
+
103
+ /** `value` with each `light-dark(light, dark)` replaced by the argument of one scheme. */
104
+ function pickScheme(value: string, dark: boolean): string {
105
+ let out = ''
106
+ let from = 0
107
+ for (let at = value.indexOf(LIGHT_DARK); at !== -1; at = value.indexOf(LIGHT_DARK, from)) {
108
+ let depth = 0
109
+ let comma = -1
110
+ let end = at + LIGHT_DARK.length
111
+ for (; end < value.length; end++) {
112
+ const ch = value[end]
113
+ if (ch === '(')
114
+ depth++
115
+ else if (ch === ')' && depth-- === 0)
116
+ break
117
+ else if (ch === ',' && depth === 0 && comma === -1)
118
+ comma = end
119
+ }
120
+ if (comma === -1 || end === value.length)
121
+ return value
122
+ const arg = dark ? value.slice(comma + 1, end) : value.slice(at + LIGHT_DARK.length, comma)
123
+ out += value.slice(from, at) + pickScheme(arg.trim(), dark)
124
+ from = end + 1
125
+ }
126
+ return out + value.slice(from)
127
+ }
128
+
129
+ // A browser without `light-dark()` (Safari before 17.5, the last on iPhone 8 and X being 16.7) drops every token using it, so the page loses its palette: it gets the `:root` tokens again, resolved by `prefers-color-scheme`.
130
+ function colorSchemeFallback(baseBlocks: readonly string[]): string {
131
+ const decls: string[] = []
132
+ for (const block of baseBlocks) {
133
+ for (const decl of block.match(ROOT_BLOCK_RE)?.[1]?.split(';') ?? []) {
134
+ if (decl.includes(LIGHT_DARK))
135
+ decls.push(decl.trim())
136
+ }
137
+ }
138
+ if (decls.length === 0)
139
+ return ''
140
+ const root = (dark: boolean): string => `:root { ${decls.map(d => pickScheme(d, dark)).join('; ')}; }`
141
+ return `@supports not (color: light-dark(#000, #fff)) {\n ${root(false)}\n @media (prefers-color-scheme: dark) { ${root(true)} }\n}`
142
+ }
98
143
 
99
144
  function resolveDataUiPart(name: string): UiComponentPart | undefined {
100
145
  if (name === 'table')
@@ -284,6 +329,9 @@ function parseGrammar(grammar: GrammarName): ParsedGrammar {
284
329
  }
285
330
  }
286
331
 
332
+ const fallback = colorSchemeFallback(baseBlocks)
333
+ if (fallback)
334
+ baseBlocks.push(fallback)
287
335
  const parsed: ParsedGrammar = { header, topRules, baseBlocks, partBlocks }
288
336
  cachedGrammars.set(grammar, parsed)
289
337
  return parsed