@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.
- package/llms.txt +4 -4
- package/package.json +3 -3
- package/src/CommandPalette.tsx +27 -29
- package/src/DataTable.tsx +64 -68
- package/src/Dialog.tsx +7 -7
- package/src/Menu.tsx +3 -5
- package/src/Select.tsx +33 -17
- package/src/Tabs.tsx +8 -9
- package/src/Toaster.tsx +4 -3
- package/src/labels/dialog.ts +7 -3
- package/src/labels/en/dialog.ts +11 -0
- package/src/labels/en/palette.ts +21 -0
- package/src/labels/en/select.ts +7 -0
- package/src/labels/en/table.ts +31 -0
- package/src/labels/en/toaster.ts +7 -0
- package/src/labels/fr/dialog.ts +7 -3
- package/src/labels/fr/palette.ts +12 -8
- package/src/labels/fr/select.ts +5 -1
- package/src/labels/fr/table.ts +17 -13
- package/src/labels/fr/toaster.ts +5 -1
- package/src/labels/palette.ts +7 -8
- package/src/labels/select.ts +7 -1
- package/src/labels/table.ts +7 -13
- package/src/labels/toaster.ts +7 -1
- package/src/locale.ts +15 -0
- package/src/platform-fallback.ts +7 -5
- package/src/plugin.ts +29 -10
- package/src/primitives.tsx +40 -41
- package/src/static.tsx +85 -20
- package/src/styles/bare.css +1 -1
- package/src/styles/base.css +3 -3
- package/src/styles/components/accordion.css +1 -1
- package/src/styles/components/badge.css +1 -1
- package/src/styles/components/button.css +1 -1
- package/src/styles/components/card.css +1 -1
- package/src/styles/components/checkbox.css +1 -1
- package/src/styles/components/command.css +1 -1
- package/src/styles/components/consent.css +1 -1
- package/src/styles/components/datatable.css +1 -1
- package/src/styles/components/dialog.css +1 -1
- package/src/styles/components/drawer.css +1 -1
- package/src/styles/components/field.css +1 -1
- package/src/styles/components/layout.css +1 -8
- package/src/styles/components/menu.css +1 -1
- package/src/styles/components/notice.css +1 -1
- package/src/styles/components/popover.css +1 -1
- package/src/styles/components/progress.css +1 -1
- package/src/styles/components/radio-group.css +1 -1
- package/src/styles/components/select.css +1 -1
- package/src/styles/components/switch.css +1 -1
- package/src/styles/components/tabs.css +1 -1
- package/src/styles/components/toast.css +1 -1
- package/src/styles/grammars/console.css +1 -1
- package/src/styles/grammars/editorial.css +1 -1
- package/src/styles/grammars/orbit.css +1 -1
- package/src/styles/grammars/prunelle.css +1 -1
- package/src/styles/grammars/soft.css +1 -1
- package/src/styles/grammars/workshop.css +1 -1
- package/src/styles/scan.ts +24 -4
- package/src/styles/split.ts +10 -10
- package/src/styles/theme.css +1 -1
- package/src/styles/themed/accordion.css +1 -1
- package/src/styles/themed/badge.css +1 -1
- package/src/styles/themed/button.css +1 -1
- package/src/styles/themed/card.css +1 -1
- package/src/styles/themed/checkbox.css +1 -1
- package/src/styles/themed/command.css +1 -1
- package/src/styles/themed/consent.css +1 -1
- package/src/styles/themed/datatable.css +1 -1
- package/src/styles/themed/dialog.css +1 -1
- package/src/styles/themed/drawer.css +1 -1
- package/src/styles/themed/field.css +1 -1
- package/src/styles/themed/menu.css +1 -1
- package/src/styles/themed/notice.css +1 -1
- package/src/styles/themed/popover.css +1 -1
- package/src/styles/themed/radio-group.css +1 -1
- package/src/styles/themed/select.css +1 -1
- package/src/styles/themed/switch.css +1 -1
- package/src/styles/themed/tabs.css +1 -1
- package/src/styles/themed/toast.css +1 -1
- 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
|
-
|
|
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
|
|
136
|
-
|
|
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
|
-
|
|
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 (
|
|
144
|
-
|
|
164
|
+
else if (id.value.startsWith('pru-'))
|
|
165
|
+
replace(id, `id="${escAttr(wiring.id)}"`)
|
|
145
166
|
|
|
146
167
|
if (wiring.describedBy) {
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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 &&
|
|
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) &&
|
|
177
|
+
if (NATIVE_CTRL_RE.test(target.tag) && find('required') === undefined)
|
|
156
178
|
attrs += ' required'
|
|
157
|
-
if (
|
|
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('
|
|
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
|
-
|
|
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
|
-
|
|
382
|
+
style={layoutStyle({ '--ui-gap': isSpaceToken(props.gap) ? undefined : props.gap }, props.style)}
|
|
318
383
|
class={props.class}
|
|
319
384
|
{...rest}
|
|
320
385
|
>
|
package/src/styles/bare.css
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* @prunellejs/ui bare floor: behavior, layout primitives, accessibility & top-layer positioning only.
|
|
2
|
-
* Everything sits inside @layer
|
|
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';
|
package/src/styles/base.css
CHANGED
|
@@ -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
|
|
2
|
+
* Everything sits inside @layer pru-ui so Tailwind utilities and user CSS always win without !important. */
|
|
3
3
|
|
|
4
|
-
@layer
|
|
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
|
-
.
|
|
11
|
+
.pru-sr-only {
|
|
12
12
|
position: absolute;
|
|
13
13
|
width: 1px;
|
|
14
14
|
height: 1px;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
@layer
|
|
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
|
|
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
|
}
|
package/src/styles/scan.ts
CHANGED
|
@@ -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 (
|
|
84
|
-
|
|
85
|
-
|
|
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')
|
package/src/styles/split.ts
CHANGED
|
@@ -245,11 +245,11 @@ function scanTopBlocks(css: string): RawBlock[] {
|
|
|
245
245
|
return blocks
|
|
246
246
|
}
|
|
247
247
|
|
|
248
|
-
function
|
|
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+
|
|
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 =
|
|
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 =
|
|
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) ?
|
|
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+
|
|
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
|
|
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
|
|
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
|
|
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
|
|
427
|
+
out.push(`@layer pru-ui {\n${layerChunks.filter(Boolean).join('\n\n')}\n}`)
|
|
428
428
|
return `${out.join('\n\n')}\n`
|
|
429
429
|
}
|
package/src/styles/theme.css
CHANGED