@lostgradient/cinder 0.27.0 → 0.28.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/CHANGELOG.md +42 -0
- package/components.json +1 -1
- package/dist/_internal/code-highlighter-context.d.ts +28 -0
- package/dist/cli/index.js +12 -8
- package/dist/components/approval-card/index.js +4 -4
- package/dist/components/button/button.css +25 -0
- package/dist/components/calendar/calendar.css +14 -0
- package/dist/components/capability-gate/capability-gate.css +5 -0
- package/dist/components/checkbox/checkbox.css +19 -0
- package/dist/components/chip/chip.css +14 -0
- package/dist/components/code-block/code-block.d.svelte.ts +1 -1
- package/dist/components/code-block/code-block.examples.json +1 -1
- package/dist/components/code-block/code-block.schema.js +3 -3
- package/dist/components/code-block/code-block.svelte.d.ts +1 -1
- package/dist/components/code-block/code-block.types.d.ts +14 -12
- package/dist/components/code-block/index.js +2 -2
- package/dist/components/color-picker/color-picker.css +2 -0
- package/dist/components/combobox/combobox.css +9 -1
- package/dist/components/command-palette/command-palette.css +7 -5
- package/dist/components/file-upload/file-upload.css +2 -1
- package/dist/components/guidance-region/index.css +1 -1
- package/dist/components/image/image.examples.json +1 -1
- package/dist/components/input/input.css +20 -6
- package/dist/components/json-schema-editor/index.js +5 -5
- package/dist/components/json-schema-editor/json-view-highlighter.d.ts +14 -0
- package/dist/components/key-value-editor/index.css +1 -1
- package/dist/components/modal-region/index.css +1 -1
- package/dist/components/multi-select/multi-select.css +9 -0
- package/dist/components/pagination/pagination.css +12 -0
- package/dist/components/pin-input/pin-input.css +9 -1
- package/dist/components/radio-group/radio-group.css +16 -0
- package/dist/components/run-step-timeline/index.js +2 -2
- package/dist/components/schema-form/index.js +2 -2
- package/dist/components/schema-form/schema-form.css +9 -0
- package/dist/components/segmented-control/segmented-control.css +3 -3
- package/dist/components/selection-popover/selection-popover.css +7 -1
- package/dist/components/tag-input/tag-input.css +10 -1
- package/dist/components/terminal-frame/index.js +2 -2
- package/dist/components/terminal-frame/terminal-frame.schema.js +2 -2
- package/dist/components/terminal-frame/terminal-frame.types.d.ts +8 -0
- package/dist/components/textarea/textarea.css +1 -1
- package/dist/components/toggle/toggle.css +16 -0
- package/dist/components/tree/tree.examples.json +1 -1
- package/dist/components/virtual-list/index.js +2 -2
- package/dist/components/virtual-list/virtual-list.css +42 -9
- package/dist/highlighters/shiki/default.d.ts +13 -1
- package/dist/highlighters/shiki/default.js +2 -2
- package/dist/highlighters/shiki/index.d.ts +20 -12
- package/dist/highlighters/shiki/index.js +2 -2
- package/dist/index.browser.css +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -23
- package/dist/scripts/knowledge/index.d.ts +5 -1
- package/dist/server/components/approval-card/index.js +1 -1
- package/dist/server/components/code-block/index.js +1 -1
- package/dist/server/components/color-field/index.js +2 -2
- package/dist/server/components/color-picker/index.js +2 -2
- package/dist/server/components/json-schema-editor/index.js +2 -2
- package/dist/server/components/run-step-timeline/index.js +1 -1
- package/dist/server/components/terminal-frame/index.js +1 -1
- package/dist/server/components/virtual-list/index.js +1 -1
- package/dist/server/github-dark-e7nywpbe.js +3 -0
- package/dist/server/github-light-bqtmm1zq.js +3 -0
- package/dist/server/highlighters/shiki/default.js +2 -2
- package/dist/server/highlighters/shiki/index.js +2 -2
- package/dist/server/index.js +6 -6
- package/dist/server/{index.server-4qyyw4y5.js → index.server-043cfznf.js} +1 -1
- package/dist/server/{index.server-p46tn4eb.js → index.server-09tjs48p.js} +2 -2
- package/dist/server/index.server-0hyvdf74.js +8 -0
- package/dist/server/{index.server-dxgkh9tk.js → index.server-17thvpd3.js} +1 -1
- package/dist/server/index.server-19z6hqd6.js +4 -0
- package/dist/server/index.server-31020qgk.js +3 -0
- package/dist/server/{index.server-w3nqzde5.js → index.server-45wmvjrn.js} +3 -3
- package/dist/server/{index.server-3tkgm2gn.js → index.server-6mb7w5g4.js} +2 -2
- package/dist/server/{index.server-2vxmn7x1.js → index.server-c5yajkkc.js} +4 -4
- package/dist/server/index.server-e6fknxd9.js +4 -0
- package/dist/server/index.server-fev4kwm0.js +4 -0
- package/dist/server/index.server-k4vjk75r.js +4 -0
- package/dist/server/index.server-mjbtd1gs.js +7 -0
- package/dist/server/{index.server-2bfkhzzq.js → index.server-rkp4py5n.js} +2 -2
- package/dist/server/index.server-wdz9tsq4.js +3 -0
- package/dist/server/index.server-zj9909hd.js +4 -0
- package/dist/server/json-68twtta3.js +3 -0
- package/dist/server/tokens/registry.generated.js +1 -1
- package/dist/server/tokens/runtime/index.js +92 -0
- package/dist/styles/check-token-contrast-test-values.d.ts +1 -3
- package/dist/styles/token-contrast-test-readers.d.ts +1 -1
- package/dist/tokens/registry.generated.js +2 -2
- package/dist/tokens/resolved/dark-reduced-motion.json +104 -43
- package/dist/tokens/resolved/dark.json +104 -43
- package/dist/tokens/resolved/light-reduced-motion.json +104 -43
- package/dist/tokens/resolved/light.json +104 -43
- package/dist/tokens/runtime/authoring-catalogue.d.ts +19 -0
- package/dist/tokens/runtime/authoring-catalogue.generated.d.ts +8 -0
- package/dist/tokens/runtime/authoring-palette.d.ts +25 -0
- package/dist/tokens/runtime/authoring-profiles.d.ts +48 -0
- package/dist/tokens/runtime/authoring-provenance.d.ts +31 -0
- package/dist/tokens/runtime/authoring-types.d.ts +182 -0
- package/dist/tokens/runtime/base-corpus.d.ts +29 -0
- package/dist/tokens/runtime/base-corpus.generated.d.ts +8 -0
- package/dist/tokens/runtime/context-order.d.ts +60 -0
- package/dist/tokens/runtime/context-stack.d.ts +11 -0
- package/dist/tokens/runtime/contrast/color-difference.d.ts +16 -0
- package/dist/{styles/color-contrast-utilities.d.ts → tokens/runtime/contrast/color-math.d.ts} +2 -17
- package/dist/tokens/runtime/contrast/color-mix.d.ts +3 -0
- package/dist/tokens/runtime/contrast/css-color.d.ts +29 -0
- package/dist/tokens/runtime/contrast/index.d.ts +7 -0
- package/dist/tokens/runtime/contrast/measure.d.ts +45 -0
- package/dist/tokens/runtime/contrast/pairings.d.ts +36 -0
- package/dist/tokens/runtime/contrast/thresholds.d.ts +47 -0
- package/dist/tokens/runtime/corpus-documents.d.ts +36 -0
- package/dist/tokens/runtime/corpus-validation.d.ts +10 -0
- package/dist/tokens/runtime/corpus.d.ts +35 -0
- package/dist/tokens/runtime/css-configuration.d.ts +1 -0
- package/dist/tokens/runtime/css-stylelint.d.ts +2 -0
- package/dist/tokens/runtime/css-support.d.ts +110 -0
- package/dist/tokens/runtime/evaluate.d.ts +95 -0
- package/dist/tokens/runtime/evaluated-provenance.d.ts +36 -0
- package/dist/tokens/runtime/index.d.ts +38 -0
- package/dist/tokens/runtime/index.js +95 -0
- package/dist/tokens/runtime/package-version.generated.d.ts +9 -0
- package/dist/tokens/runtime/projection.d.ts +32 -0
- package/dist/tokens/runtime/registry.d.ts +125 -0
- package/dist/tokens/runtime/resolve-extends.d.ts +30 -0
- package/dist/tokens/runtime/resolve-references.d.ts +49 -0
- package/dist/tokens/runtime/resolve-shared.d.ts +34 -0
- package/dist/tokens/runtime/resolve.d.ts +44 -0
- package/dist/tokens/runtime/resolver-order.d.ts +89 -0
- package/dist/tokens/runtime/source-digest.d.ts +20 -0
- package/dist/tokens/runtime/stylesheet-skeleton.d.ts +31 -0
- package/dist/tokens/runtime/theme-runtime.test-support.d.ts +24 -0
- package/dist/tokens/runtime/theme-sources.d.ts +46 -0
- package/dist/tokens/runtime/theme-stylesheet.d.ts +31 -0
- package/dist/tokens/runtime/types.d.ts +115 -0
- package/dist/tokens/runtime/validate-resolver.d.ts +31 -0
- package/dist/tokens/runtime/validate-schema.d.ts +22 -0
- package/dist/tokens/runtime/validate-tokens.d.ts +25 -0
- package/dist/tokens/runtime/validate-values.d.ts +33 -0
- package/dist/tokens/runtime/validate.d.ts +3 -0
- package/dist/tokens/runtime/value-color-parse.d.ts +128 -0
- package/dist/tokens/runtime/value-color.d.ts +85 -0
- package/dist/tokens/runtime/value-entry.d.ts +3 -0
- package/dist/tokens/runtime/value-formatters.d.ts +59 -0
- package/dist/tokens/sets/colors.tokens.json +65 -13
- package/dist/tokens/sets/foundation.tokens.json +23 -0
- package/dist/tokens/sets/semantic.tokens.json +136 -30
- package/dist/utilities/highlighter.d.ts +5 -5
- package/dist/utilities/retrying-loader-cache.d.ts +3 -6
- package/package.json +15 -3
- package/src/_internal/code-highlighter-context.ts +41 -0
- package/src/components/button/button.css +25 -0
- package/src/components/calendar/calendar.css +14 -0
- package/src/components/capability-gate/capability-gate.css +5 -0
- package/src/components/checkbox/checkbox.css +19 -0
- package/src/components/chip/chip.css +14 -0
- package/src/components/code-block/code-block.examples.json +1 -1
- package/src/components/code-block/code-block.schema.json +2 -2
- package/src/components/code-block/code-block.schema.ts +2 -2
- package/src/components/code-block/code-block.svelte +15 -19
- package/src/components/code-block/code-block.types.ts +14 -12
- package/src/components/color-picker/color-picker.css +2 -0
- package/src/components/combobox/combobox.css +9 -1
- package/src/components/command-palette/command-palette.css +7 -5
- package/src/components/file-upload/file-upload.css +2 -1
- package/src/components/image/image.examples.json +1 -1
- package/src/components/input/input.css +20 -6
- package/src/components/json-schema-editor/json-view-highlighter.ts +23 -0
- package/src/components/json-schema-editor/json-view.svelte +2 -0
- package/src/components/multi-select/multi-select.css +9 -0
- package/src/components/pagination/pagination.css +12 -0
- package/src/components/pin-input/pin-input.css +9 -1
- package/src/components/radio-group/radio-group.css +16 -0
- package/src/components/schema-form/schema-form.css +9 -0
- package/src/components/segmented-control/segmented-control.css +3 -3
- package/src/components/selection-popover/selection-popover.css +7 -1
- package/src/components/tag-input/tag-input.css +10 -1
- package/src/components/terminal-frame/terminal-frame.schema.json +5 -0
- package/src/components/terminal-frame/terminal-frame.schema.ts +6 -0
- package/src/components/terminal-frame/terminal-frame.svelte +6 -2
- package/src/components/terminal-frame/terminal-frame.types.ts +8 -0
- package/src/components/textarea/textarea.css +1 -1
- package/src/components/toggle/toggle.css +16 -0
- package/src/components/tree/tree.examples.json +1 -1
- package/src/components/virtual-list/virtual-list.css +42 -9
- package/src/components/virtual-list/virtual-list.svelte +54 -20
- package/src/highlighters/shiki/default.ts +13 -1
- package/src/highlighters/shiki/index.ts +20 -12
- package/src/index.ts +5 -0
- package/src/styles/foundation.css +33 -1
- package/src/styles/tokens-base.css +4 -4
- package/src/tokens/registry.generated.json +3 -3
- package/src/tokens/resolved/dark-reduced-motion.json +104 -43
- package/src/tokens/resolved/dark.json +104 -43
- package/src/tokens/resolved/light-reduced-motion.json +104 -43
- package/src/tokens/resolved/light.json +104 -43
- package/src/tokens/runtime/authoring-catalogue.generated.ts +19300 -0
- package/src/tokens/runtime/authoring-catalogue.ts +256 -0
- package/src/tokens/runtime/authoring-palette.ts +100 -0
- package/src/tokens/runtime/authoring-profiles.ts +288 -0
- package/src/tokens/runtime/authoring-provenance.ts +290 -0
- package/src/tokens/runtime/authoring-types.ts +199 -0
- package/src/tokens/runtime/base-corpus.generated.ts +10 -0
- package/src/tokens/runtime/base-corpus.ts +78 -0
- package/src/tokens/runtime/context-order.ts +182 -0
- package/src/tokens/runtime/context-stack.ts +52 -0
- package/src/tokens/runtime/contrast/color-difference.ts +114 -0
- package/src/tokens/runtime/contrast/color-math.ts +89 -0
- package/src/tokens/runtime/contrast/color-mix.ts +20 -0
- package/src/tokens/runtime/contrast/css-color.ts +312 -0
- package/src/tokens/runtime/contrast/index.ts +7 -0
- package/src/tokens/runtime/contrast/measure.ts +185 -0
- package/src/tokens/runtime/contrast/pairings.ts +324 -0
- package/src/tokens/runtime/contrast/thresholds.ts +81 -0
- package/src/tokens/runtime/corpus-documents.ts +289 -0
- package/src/tokens/runtime/corpus-validation.ts +336 -0
- package/src/tokens/runtime/corpus.ts +179 -0
- package/src/tokens/runtime/css-configuration.ts +1 -0
- package/src/tokens/runtime/css-stylelint.ts +15 -0
- package/src/tokens/runtime/css-support.ts +407 -0
- package/src/tokens/runtime/evaluate.ts +262 -0
- package/src/tokens/runtime/evaluated-provenance.ts +116 -0
- package/src/tokens/runtime/format-validator.generated.d.ts +18 -0
- package/src/tokens/runtime/format-validator.generated.js +13029 -0
- package/src/tokens/runtime/index.ts +78 -0
- package/src/tokens/runtime/package-version.generated.ts +9 -0
- package/src/tokens/runtime/projection.ts +65 -0
- package/src/tokens/runtime/registry.ts +365 -0
- package/src/tokens/runtime/resolve-extends.ts +211 -0
- package/src/tokens/runtime/resolve-references.ts +313 -0
- package/src/tokens/runtime/resolve-shared.ts +186 -0
- package/src/tokens/runtime/resolve.ts +246 -0
- package/src/tokens/runtime/resolver-order.ts +326 -0
- package/src/tokens/runtime/resolver-validator.generated.d.ts +18 -0
- package/src/tokens/runtime/resolver-validator.generated.js +15492 -0
- package/src/tokens/runtime/source-digest.ts +49 -0
- package/src/tokens/runtime/stylesheet-skeleton.ts +123 -0
- package/src/tokens/runtime/theme-sources.ts +121 -0
- package/src/tokens/runtime/theme-stylesheet.ts +177 -0
- package/src/tokens/runtime/types.ts +140 -0
- package/src/tokens/runtime/validate-resolver.ts +338 -0
- package/src/tokens/runtime/validate-schema.ts +269 -0
- package/src/tokens/runtime/validate-tokens.ts +181 -0
- package/src/tokens/runtime/validate-values.ts +396 -0
- package/src/tokens/runtime/validate.ts +57 -0
- package/src/tokens/runtime/value-color-parse.ts +309 -0
- package/src/tokens/runtime/value-color.ts +217 -0
- package/src/tokens/runtime/value-entry.ts +52 -0
- package/src/tokens/runtime/value-formatters.ts +414 -0
- package/src/tokens/sets/colors.tokens.json +65 -13
- package/src/tokens/sets/foundation.tokens.json +23 -0
- package/src/tokens/sets/semantic.tokens.json +136 -30
- package/src/utilities/highlighter.ts +5 -5
- package/src/utilities/retrying-loader-cache.ts +3 -6
- package/dist/components/code-block/code-block-default-highlighter.d.ts +0 -40
- package/dist/server/index.server-298z43yn.js +0 -4
- package/dist/server/index.server-3h11wjyh.js +0 -8
- package/dist/server/index.server-a3aerbfr.js +0 -4
- package/dist/server/index.server-kge3zp6n.js +0 -4
- package/dist/server/index.server-syf81nwz.js +0 -6
- package/dist/server/index.server-zs08f5te.js +0 -3
- package/src/components/code-block/code-block-default-highlighter.ts +0 -63
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical JSON and the digest that identifies a token source.
|
|
3
|
+
*
|
|
4
|
+
* The digest hashes a canonical form (object keys in code-unit order, no
|
|
5
|
+
* insignificant whitespace), so equal sources hash equally wherever they were
|
|
6
|
+
* authored or whatever order their keys arrived in. SHA-256 comes from Web
|
|
7
|
+
* Crypto, which every browser, Bun, and Node provide; no Node module is
|
|
8
|
+
* involved.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** `JSON.stringify` with object keys sorted, so equal values serialize identically. */
|
|
12
|
+
export function canonicalJson(value: unknown): string {
|
|
13
|
+
return JSON.stringify(sortKeys(value));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function sortKeys(value: unknown): unknown {
|
|
17
|
+
if (Array.isArray(value)) return value.map(sortKeys);
|
|
18
|
+
if (typeof value !== 'object' || value === null) return value;
|
|
19
|
+
const sorted: Record<string, unknown> = {};
|
|
20
|
+
for (const [key, child] of Object.entries(value).toSorted(([left], [right]) =>
|
|
21
|
+
left < right ? -1 : left > right ? 1 : 0,
|
|
22
|
+
)) {
|
|
23
|
+
Object.defineProperty(sorted, key, {
|
|
24
|
+
value: sortKeys(child),
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return sorted;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The lowercase hexadecimal SHA-256 of a string's UTF-8 bytes. */
|
|
34
|
+
export async function sha256Hex(text: string): Promise<string> {
|
|
35
|
+
const digest = await globalThis.crypto.subtle.digest('SHA-256', new TextEncoder().encode(text));
|
|
36
|
+
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** What identifies a token source: its resolver and its documents keyed by relative path. */
|
|
40
|
+
export type DigestableSource = {
|
|
41
|
+
resolver: unknown;
|
|
42
|
+
documents: Readonly<Record<string, unknown>>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** `sha256:<hex>` over the canonical form of `{ resolver, documents }`. */
|
|
46
|
+
export async function computeSourceDigest(source: DigestableSource): Promise<string> {
|
|
47
|
+
const text = canonicalJson({ resolver: source.resolver, documents: source.documents });
|
|
48
|
+
return `sha256:${await sha256Hex(text)}`;
|
|
49
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The selector and media skeleton of a Cinder token stylesheet.
|
|
3
|
+
*
|
|
4
|
+
* The generator (`tokens-base.css`) and the theme builder's deployment CSS both fill this
|
|
5
|
+
* one template, so the root/descendant `[data-theme]`, `prefers-reduced-motion` and
|
|
6
|
+
* `[data-reduced-motion]` precedence contract is written down exactly once. Each field is
|
|
7
|
+
* a block of ready-made declarations (without braces); an empty block is not emitted
|
|
8
|
+
* where the contract allows omitting it.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export type StylesheetDeclarations = {
|
|
12
|
+
/** The `:root` declarations every context starts from. */
|
|
13
|
+
root: string;
|
|
14
|
+
/** Declarations for `[data-theme='dark']` / `[data-theme='light']`, root or descendant. */
|
|
15
|
+
dark: string;
|
|
16
|
+
light: string;
|
|
17
|
+
/** `prefers-reduced-motion: reduce`, with no theme named. */
|
|
18
|
+
reducedMotion: string;
|
|
19
|
+
darkReducedMotion: string;
|
|
20
|
+
lightReducedMotion: string;
|
|
21
|
+
/** `[data-reduced-motion='on']`, with no theme named. */
|
|
22
|
+
forcedReducedMotion: string;
|
|
23
|
+
darkForcedReducedMotion: string;
|
|
24
|
+
lightForcedReducedMotion: string;
|
|
25
|
+
/**
|
|
26
|
+
* Declarations for a root with no `data-theme` under `prefers-color-scheme: dark`. The
|
|
27
|
+
* generator leaves this empty (its `:root` uses `light-dark()`); a complete theme needs it.
|
|
28
|
+
*/
|
|
29
|
+
systemDark?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const NOT_FORCED_OFF =
|
|
33
|
+
":not([data-cinder-reduced-motion='false']):not([data-reduced-motion='off']):not([data-reduced-motion='on'])";
|
|
34
|
+
|
|
35
|
+
function themeBlock(theme: 'dark' | 'light', declarations: string): string {
|
|
36
|
+
return declarations
|
|
37
|
+
? `:root${NOT_FORCED_OFF} [data-theme='${theme}'],
|
|
38
|
+
:root[data-theme='${theme}']${NOT_FORCED_OFF} {
|
|
39
|
+
${declarations}
|
|
40
|
+
}`
|
|
41
|
+
: '';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function reducedSystemBlock(scheme: 'dark' | 'light', declarations: string): string {
|
|
45
|
+
return declarations
|
|
46
|
+
? `@media (prefers-color-scheme: ${scheme}) {
|
|
47
|
+
:root:not([data-theme])${NOT_FORCED_OFF} {
|
|
48
|
+
${declarations}
|
|
49
|
+
}
|
|
50
|
+
}`
|
|
51
|
+
: '';
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function forcedThemeBlock(theme: 'dark' | 'light', declarations: string): string {
|
|
55
|
+
return declarations
|
|
56
|
+
? `:root[data-reduced-motion='on'] [data-theme='${theme}'],
|
|
57
|
+
:root[data-reduced-motion='on'][data-theme='${theme}'] {
|
|
58
|
+
${declarations}
|
|
59
|
+
}`
|
|
60
|
+
: '';
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Everything after the file header: `:root` through the forced-motion blocks. */
|
|
64
|
+
export function renderStylesheetSkeleton(d: StylesheetDeclarations): string {
|
|
65
|
+
const systemDark = d.systemDark
|
|
66
|
+
? `@media (prefers-color-scheme: dark) {
|
|
67
|
+
:root:not([data-theme]) {
|
|
68
|
+
${d.systemDark}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
`
|
|
73
|
+
: '';
|
|
74
|
+
return `:root {
|
|
75
|
+
/* Structural: not a design token. */
|
|
76
|
+
color-scheme: light dark;
|
|
77
|
+
|
|
78
|
+
${d.root}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
:root[data-theme='dark'] {
|
|
82
|
+
/* Structural: not a design token. */
|
|
83
|
+
color-scheme: dark;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
:root[data-theme='light'] {
|
|
87
|
+
/* Structural: not a design token. */
|
|
88
|
+
color-scheme: light;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[data-theme='dark'] {
|
|
92
|
+
/* Structural: not a design token. */
|
|
93
|
+
color-scheme: dark;
|
|
94
|
+
|
|
95
|
+
${d.dark}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
[data-theme='light'] {
|
|
99
|
+
/* Structural: not a design token. */
|
|
100
|
+
color-scheme: light;
|
|
101
|
+
|
|
102
|
+
${d.light}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
${systemDark}@media (prefers-reduced-motion: reduce) {
|
|
106
|
+
:root${NOT_FORCED_OFF} {
|
|
107
|
+
${d.reducedMotion}
|
|
108
|
+
}
|
|
109
|
+
${themeBlock('dark', d.darkReducedMotion)}
|
|
110
|
+
${themeBlock('light', d.lightReducedMotion)}
|
|
111
|
+
${reducedSystemBlock('dark', d.darkReducedMotion)}
|
|
112
|
+
${reducedSystemBlock('light', d.lightReducedMotion)}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
:root[data-reduced-motion='on'] {
|
|
116
|
+
${d.forcedReducedMotion}
|
|
117
|
+
}
|
|
118
|
+
${forcedThemeBlock('dark', d.darkForcedReducedMotion)}
|
|
119
|
+
${forcedThemeBlock('light', d.lightForcedReducedMotion)}
|
|
120
|
+
${d.darkForcedReducedMotion ? `@media (prefers-color-scheme: dark) {\n :root[data-reduced-motion='on']:not([data-theme]) {\n${d.darkForcedReducedMotion}\n }\n}` : ''}
|
|
121
|
+
${d.lightForcedReducedMotion ? `@media (prefers-color-scheme: light) {\n :root[data-reduced-motion='on']:not([data-theme]) {\n${d.lightForcedReducedMotion}\n }\n}` : ''}
|
|
122
|
+
`;
|
|
123
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A saved theme as runtime sources.
|
|
3
|
+
*
|
|
4
|
+
* A Cinder Theme v1 envelope embeds an immutable Cinder base (resolver and documents) and
|
|
5
|
+
* five override trees. The overrides are DTCG documents appended to the resolver's own
|
|
6
|
+
* source lists, so layering is the resolver's and is never reimplemented: shared overrides
|
|
7
|
+
* join the first set, `light`/`dark` join the theme contexts, and `reduced`/`forcedReduced`
|
|
8
|
+
* join the motion contexts. The theme builder and a consumer that loads a saved envelope
|
|
9
|
+
* compose sources through this one function.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { AUTHORING_CATALOGUE } from './authoring-catalogue.generated.ts';
|
|
13
|
+
import { authoringLayerStack } from './context-stack.ts';
|
|
14
|
+
import type { ThemeSources } from './evaluate.ts';
|
|
15
|
+
import { mergeDocuments } from './resolve.ts';
|
|
16
|
+
import type { ResolverDocument, TokenDocument } from './types.ts';
|
|
17
|
+
|
|
18
|
+
/** Where each override scope's document lives in the resolver. */
|
|
19
|
+
export const OVERRIDE_DOCUMENTS = {
|
|
20
|
+
shared: 'overrides/shared.tokens.json',
|
|
21
|
+
light: 'overrides/light.tokens.json',
|
|
22
|
+
dark: 'overrides/dark.tokens.json',
|
|
23
|
+
reduced: 'overrides/reduced.tokens.json',
|
|
24
|
+
forcedReduced: 'overrides/forced-reduced-motion.tokens.json',
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
export type OverrideScopeName = keyof typeof OVERRIDE_DOCUMENTS;
|
|
28
|
+
|
|
29
|
+
/** The part of an envelope the runtime needs; the playground's envelope type satisfies it. */
|
|
30
|
+
export type ThemeSourceEnvelope = {
|
|
31
|
+
base: { resolver: unknown; documents: Readonly<Record<string, unknown>> };
|
|
32
|
+
overrides: Readonly<Record<OverrideScopeName, unknown>>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
type SourceList = Array<{ $ref: string }>;
|
|
36
|
+
type ResolverShape = {
|
|
37
|
+
sets: Record<string, { sources: SourceList }>;
|
|
38
|
+
modifiers: Record<string, { contexts: Record<string, SourceList> }>;
|
|
39
|
+
resolutionOrder: Array<{ $ref: string }>;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
function append(list: SourceList | undefined, path: string): void {
|
|
43
|
+
list?.push({ $ref: path });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The first set in resolution order: the base set the shared overrides follow. */
|
|
47
|
+
function firstSetName(resolver: ResolverShape): string | undefined {
|
|
48
|
+
const entry = resolver.resolutionOrder.find((reference) => reference.$ref.startsWith('#/sets/'));
|
|
49
|
+
return entry?.$ref.slice('#/sets/'.length);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The envelope as runtime sources: the embedded base with the override documents inserted. */
|
|
53
|
+
export function buildThemeSources(envelope: ThemeSourceEnvelope, revision: number): ThemeSources {
|
|
54
|
+
// The sources are validated by the caller before they are evaluated; this only appends refs.
|
|
55
|
+
// eslint-disable-next-line no-unsafe-type-assertion
|
|
56
|
+
const resolver = structuredClone(envelope.base.resolver) as ResolverShape;
|
|
57
|
+
append(resolver.sets[firstSetName(resolver) ?? '']?.sources, OVERRIDE_DOCUMENTS.shared);
|
|
58
|
+
const theme = resolver.modifiers['theme']?.contexts;
|
|
59
|
+
append(theme?.['light'], OVERRIDE_DOCUMENTS.light);
|
|
60
|
+
append(theme?.['dark'], OVERRIDE_DOCUMENTS.dark);
|
|
61
|
+
const motion = resolver.modifiers['motion']?.contexts;
|
|
62
|
+
append(motion?.['reduced'], OVERRIDE_DOCUMENTS.reduced);
|
|
63
|
+
append(motion?.['forced-reduced-motion'], OVERRIDE_DOCUMENTS.forcedReduced);
|
|
64
|
+
return {
|
|
65
|
+
revision,
|
|
66
|
+
resolver,
|
|
67
|
+
documents: {
|
|
68
|
+
...envelope.base.documents,
|
|
69
|
+
[OVERRIDE_DOCUMENTS.shared]: envelope.overrides.shared,
|
|
70
|
+
[OVERRIDE_DOCUMENTS.light]: envelope.overrides.light,
|
|
71
|
+
[OVERRIDE_DOCUMENTS.dark]: envelope.overrides.dark,
|
|
72
|
+
[OVERRIDE_DOCUMENTS.reduced]: envelope.overrides.reduced,
|
|
73
|
+
[OVERRIDE_DOCUMENTS.forcedReduced]: envelope.overrides.forcedReduced,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const cssPropertyByPath = new Map(
|
|
79
|
+
AUTHORING_CATALOGUE.records.map((record) => [record.path, record.cssProperty] as const),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Lay CSS-only edits (public token path, then concrete context, then value) over a projected
|
|
84
|
+
* context. They win over everything. A path outside the public registry is ignored, and
|
|
85
|
+
* `accept` lets the caller apply a stricter value check than the stylesheet's own.
|
|
86
|
+
*/
|
|
87
|
+
export function applyCssOnlyOverrides(
|
|
88
|
+
properties: Readonly<Record<string, string>>,
|
|
89
|
+
cssOverrides: Readonly<Record<string, Readonly<Record<string, string | undefined>>>>,
|
|
90
|
+
context: string,
|
|
91
|
+
accept: (value: string) => boolean = () => true,
|
|
92
|
+
): Record<string, string> {
|
|
93
|
+
const merged: Record<string, string> = { ...properties };
|
|
94
|
+
for (const [path, byContext] of Object.entries(cssOverrides)) {
|
|
95
|
+
const value = byContext[context];
|
|
96
|
+
const property = cssPropertyByPath.get(path);
|
|
97
|
+
if (value !== undefined && property !== undefined && accept(value)) merged[property] = value;
|
|
98
|
+
}
|
|
99
|
+
return merged;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The token document one concrete context resolves to: its ordered documents merged the way
|
|
104
|
+
* evaluation merges them, with aliases, `$extends`, descriptions and extensions still in
|
|
105
|
+
* place. Nothing is flattened or evaluated. The sources must already have passed validation.
|
|
106
|
+
*/
|
|
107
|
+
export function mergedContextDocument(
|
|
108
|
+
sources: ThemeSources,
|
|
109
|
+
context: { theme: string; motion: string },
|
|
110
|
+
): TokenDocument {
|
|
111
|
+
// The sources must already have passed validation, which checks every document.
|
|
112
|
+
// eslint-disable-next-line no-unsafe-type-assertion
|
|
113
|
+
const documents = new Map(Object.entries(sources.documents) as Array<[string, TokenDocument]>);
|
|
114
|
+
// eslint-disable-next-line no-unsafe-type-assertion
|
|
115
|
+
const layers = authoringLayerStack(sources.resolver as ResolverDocument, documents, {
|
|
116
|
+
id: `${context.theme}/${context.motion}`,
|
|
117
|
+
theme: context.theme,
|
|
118
|
+
motion: context.motion,
|
|
119
|
+
});
|
|
120
|
+
return mergeDocuments(layers.map((layer) => layer.content));
|
|
121
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployment CSS for a theme: a complete standalone stylesheet built from the six evaluated
|
|
3
|
+
* property maps, written into the `cinder-theme` cascade layer.
|
|
4
|
+
*
|
|
5
|
+
* The maps are exactly what the theme builder's preview applies for each concrete context,
|
|
6
|
+
* so the stylesheet reproduces the preview by construction. The selector and media
|
|
7
|
+
* structure is the generator's own (`renderStylesheetSkeleton`): root and descendant
|
|
8
|
+
* `[data-theme]` blocks, `prefers-reduced-motion` and `[data-reduced-motion='on']` blocks
|
|
9
|
+
* with the same precedence. This module only decides which declarations go in which block.
|
|
10
|
+
* It emits no reset, preflight or component selector.
|
|
11
|
+
*
|
|
12
|
+
* Nothing is trusted: a property name outside `--cinder-*` or a value that could close a
|
|
13
|
+
* declaration, open a rule, add a comment or fetch a resource throws instead of being
|
|
14
|
+
* written into a stylesheet.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { renderStylesheetSkeleton } from './stylesheet-skeleton.ts';
|
|
18
|
+
|
|
19
|
+
export type StylesheetContext =
|
|
20
|
+
| 'light/default'
|
|
21
|
+
| 'light/reduced'
|
|
22
|
+
| 'light/forced-reduced-motion'
|
|
23
|
+
| 'dark/default'
|
|
24
|
+
| 'dark/reduced'
|
|
25
|
+
| 'dark/forced-reduced-motion';
|
|
26
|
+
|
|
27
|
+
export type ContextProperties = Readonly<
|
|
28
|
+
Record<StylesheetContext, Readonly<Record<string, string>>>
|
|
29
|
+
>;
|
|
30
|
+
|
|
31
|
+
export const THEME_LAYER = 'cinder-theme';
|
|
32
|
+
const LAYER_ORDER = `cinder.tokens, cinder.foundation, cinder.components, cinder.utilities, ${THEME_LAYER}`;
|
|
33
|
+
|
|
34
|
+
const PROPERTY_NAME = /^--cinder-[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
35
|
+
const UNSAFE_VALUE = /[;{}\\<>@!]|\/\*|\*\/|url\(|image\(|image-set\(|src\(|expression\(/i;
|
|
36
|
+
|
|
37
|
+
function hasControlCharacter(value: string): boolean {
|
|
38
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
39
|
+
if (value.charCodeAt(index) < 32) return true;
|
|
40
|
+
}
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export class StylesheetError extends Error {
|
|
45
|
+
constructor(message: string) {
|
|
46
|
+
super(message);
|
|
47
|
+
this.name = 'StylesheetError';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function declaration(name: string, value: string): string {
|
|
52
|
+
if (!PROPERTY_NAME.test(name)) throw new StylesheetError(`"${name}" is not a Cinder property.`);
|
|
53
|
+
if (value.trim() === '' || UNSAFE_VALUE.test(value) || hasControlCharacter(value)) {
|
|
54
|
+
throw new StylesheetError(`The value of ${name} is not a plain CSS value.`);
|
|
55
|
+
}
|
|
56
|
+
return ` ${name}: ${value};`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function lines(names: Iterable<string>, values: Readonly<Record<string, string>>): string {
|
|
60
|
+
return [...names]
|
|
61
|
+
.sort()
|
|
62
|
+
.filter((name) => values[name] !== undefined)
|
|
63
|
+
.map((name) => declaration(name, values[name] ?? ''))
|
|
64
|
+
.join('\n');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function differing(
|
|
68
|
+
left: Readonly<Record<string, string>>,
|
|
69
|
+
right: Readonly<Record<string, string>>,
|
|
70
|
+
): Set<string> {
|
|
71
|
+
const names = new Set([...Object.keys(left), ...Object.keys(right)]);
|
|
72
|
+
return new Set([...names].filter((name) => left[name] !== right[name]));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const REFERENCE = /var\(\s*(--[\w-]+)/g;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Custom properties substitute `var()` where they are declared, so a nested scope inherits
|
|
79
|
+
* the substituted value of an alias declared above it. Whenever a property changes in a
|
|
80
|
+
* block, every property whose value reads it, directly or through other properties, must be
|
|
81
|
+
* declared in that block too (the generator's "dependent aliases"). `sources` are every map
|
|
82
|
+
* whose text may refer to a changed property.
|
|
83
|
+
*/
|
|
84
|
+
function withDependents(
|
|
85
|
+
seed: ReadonlySet<string>,
|
|
86
|
+
sources: ReadonlyArray<Readonly<Record<string, string>>>,
|
|
87
|
+
): Set<string> {
|
|
88
|
+
const references = new Map<string, Set<string>>();
|
|
89
|
+
for (const source of sources) {
|
|
90
|
+
for (const [name, value] of Object.entries(source)) {
|
|
91
|
+
const found = references.get(name) ?? new Set<string>();
|
|
92
|
+
for (const match of value.matchAll(REFERENCE)) found.add(match[1] ?? '');
|
|
93
|
+
references.set(name, found);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const result = new Set(seed);
|
|
97
|
+
let grew = true;
|
|
98
|
+
while (grew) {
|
|
99
|
+
grew = false;
|
|
100
|
+
for (const [name, found] of references) {
|
|
101
|
+
if (!result.has(name) && [...found].some((reference) => result.has(reference))) {
|
|
102
|
+
result.add(name);
|
|
103
|
+
grew = true;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function comment(text: string): string {
|
|
111
|
+
return text.replace(/\*\//g, '* /').replace(/[\r\n]+/g, ' ');
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type ThemeStylesheetOptions = {
|
|
115
|
+
/** One line naming the theme and the exact Cinder base it was checked against. */
|
|
116
|
+
identity?: string;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
type MotionName = 'reduced' | 'forced-reduced-motion';
|
|
120
|
+
|
|
121
|
+
/** The declarations a motion block restates for one theme. */
|
|
122
|
+
function motionDeclarations(
|
|
123
|
+
maps: ContextProperties,
|
|
124
|
+
theme: 'light' | 'dark',
|
|
125
|
+
motion: MotionName,
|
|
126
|
+
): string {
|
|
127
|
+
const system = differing(maps[`light/${motion}`], maps['light/default']);
|
|
128
|
+
const own = differing(maps[`${theme}/${motion}`], maps[`${theme}/default`]);
|
|
129
|
+
const names = withDependents(new Set([...system, ...own]), [
|
|
130
|
+
maps[`${theme}/${motion}`],
|
|
131
|
+
maps[`${theme}/default`],
|
|
132
|
+
maps[`light/${motion}`],
|
|
133
|
+
]);
|
|
134
|
+
return lines(names, maps[`${theme}/${motion}`]);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* The stylesheet for six evaluated contexts. Every public property of `light/default` is
|
|
139
|
+
* declared on `:root`; the dark theme block, the system-dark root and each motion block
|
|
140
|
+
* restate only what differs, with the generator's precedence.
|
|
141
|
+
*/
|
|
142
|
+
export function renderThemeStylesheet(
|
|
143
|
+
maps: ContextProperties,
|
|
144
|
+
options: ThemeStylesheetOptions = {},
|
|
145
|
+
): string {
|
|
146
|
+
const light = maps['light/default'];
|
|
147
|
+
const dark = maps['dark/default'];
|
|
148
|
+
const themeDiff = withDependents(differing(light, dark), [light, dark]);
|
|
149
|
+
const css = renderStylesheetSkeleton({
|
|
150
|
+
root: lines(Object.keys(light), light),
|
|
151
|
+
dark: lines(themeDiff, dark),
|
|
152
|
+
light: lines(themeDiff, light),
|
|
153
|
+
systemDark: lines(themeDiff, dark),
|
|
154
|
+
reducedMotion: motionDeclarations(maps, 'light', 'reduced'),
|
|
155
|
+
darkReducedMotion: motionDeclarations(maps, 'dark', 'reduced'),
|
|
156
|
+
lightReducedMotion: motionDeclarations(maps, 'light', 'reduced'),
|
|
157
|
+
forcedReducedMotion: motionDeclarations(maps, 'light', 'forced-reduced-motion'),
|
|
158
|
+
darkForcedReducedMotion: motionDeclarations(maps, 'dark', 'forced-reduced-motion'),
|
|
159
|
+
lightForcedReducedMotion: motionDeclarations(maps, 'light', 'forced-reduced-motion'),
|
|
160
|
+
});
|
|
161
|
+
const identity = options.identity === undefined ? '' : ` * ${comment(options.identity)}\n`;
|
|
162
|
+
return `/*
|
|
163
|
+
* Cinder theme stylesheet. Complete and standalone: no reset, no preflight, no component rules.
|
|
164
|
+
${identity} *
|
|
165
|
+
* Load it after Cinder's own styles. The layer order below puts ${THEME_LAYER} after every Cinder
|
|
166
|
+
* layer, so the theme wins whichever stylesheet is parsed first.
|
|
167
|
+
* Set data-theme="light" or "dark" on the root (or any descendant, including a portal
|
|
168
|
+
* container); data-reduced-motion="on" forces reduced motion.
|
|
169
|
+
* Fonts: font-family stacks are exported as written. Whether a font is installed, and its
|
|
170
|
+
* glyph metrics, depend on the environment that renders the page.
|
|
171
|
+
*/
|
|
172
|
+
@layer ${LAYER_ORDER};
|
|
173
|
+
|
|
174
|
+
@layer ${THEME_LAYER} {
|
|
175
|
+
${css}}
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/** DTCG 2025.10 token names may not contain path or reference delimiters. */
|
|
2
|
+
export type TokenName = string;
|
|
3
|
+
|
|
4
|
+
export type ColorValue = {
|
|
5
|
+
colorSpace: string;
|
|
6
|
+
components: Array<number | 'none'>;
|
|
7
|
+
alpha?: number | 'none';
|
|
8
|
+
hex?: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type DimensionValue = { value: number; unit: 'px' | 'rem' };
|
|
12
|
+
export type DurationValue = { value: number; unit: 'ms' | 's' };
|
|
13
|
+
export type StrokeStyleValue =
|
|
14
|
+
string | { dashArray: DimensionValue[]; lineCap: 'round' | 'butt' | 'square' };
|
|
15
|
+
export type BorderValue = {
|
|
16
|
+
color: ColorValue | string;
|
|
17
|
+
width: DimensionValue | string;
|
|
18
|
+
style: StrokeStyleValue | string;
|
|
19
|
+
};
|
|
20
|
+
export type TransitionValue = {
|
|
21
|
+
duration: DurationValue | string;
|
|
22
|
+
delay: DurationValue | string;
|
|
23
|
+
timingFunction: [number, number, number, number] | string;
|
|
24
|
+
};
|
|
25
|
+
export type ShadowValue = {
|
|
26
|
+
color: ColorValue | string;
|
|
27
|
+
offsetX: DimensionValue | string;
|
|
28
|
+
offsetY: DimensionValue | string;
|
|
29
|
+
blur: DimensionValue | string;
|
|
30
|
+
spread: DimensionValue | string;
|
|
31
|
+
inset?: boolean;
|
|
32
|
+
};
|
|
33
|
+
export type GradientStop = { color: ColorValue | string; position: number | string };
|
|
34
|
+
export type TypographyValue = {
|
|
35
|
+
fontFamily: string[] | string;
|
|
36
|
+
fontSize: DimensionValue | string;
|
|
37
|
+
fontWeight: number | string;
|
|
38
|
+
letterSpacing: DimensionValue | string;
|
|
39
|
+
lineHeight: number | DimensionValue | string;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type TokenValue =
|
|
43
|
+
| ColorValue
|
|
44
|
+
| DimensionValue
|
|
45
|
+
| DurationValue
|
|
46
|
+
| StrokeStyleValue
|
|
47
|
+
| BorderValue
|
|
48
|
+
| TransitionValue
|
|
49
|
+
| ShadowValue
|
|
50
|
+
| GradientStop[]
|
|
51
|
+
| TypographyValue
|
|
52
|
+
| string
|
|
53
|
+
| string[]
|
|
54
|
+
| number
|
|
55
|
+
| [number, number, number, number];
|
|
56
|
+
|
|
57
|
+
export const TOKEN_TYPES = [
|
|
58
|
+
'color',
|
|
59
|
+
'dimension',
|
|
60
|
+
'fontFamily',
|
|
61
|
+
'fontWeight',
|
|
62
|
+
'duration',
|
|
63
|
+
'cubicBezier',
|
|
64
|
+
'number',
|
|
65
|
+
'strokeStyle',
|
|
66
|
+
'border',
|
|
67
|
+
'transition',
|
|
68
|
+
'shadow',
|
|
69
|
+
'gradient',
|
|
70
|
+
'typography',
|
|
71
|
+
] as const;
|
|
72
|
+
|
|
73
|
+
export type TokenType = (typeof TOKEN_TYPES)[number];
|
|
74
|
+
|
|
75
|
+
export type TokenExtensions = Record<string, unknown>;
|
|
76
|
+
|
|
77
|
+
export type DesignToken = {
|
|
78
|
+
/**
|
|
79
|
+
* Parsed JSON remains unknown until it is validated for the token's $type.
|
|
80
|
+
* Optional because a DTCG 2025.10 `$ref` token declares `$ref` instead of
|
|
81
|
+
* `$value` -- the two are mutually exclusive (see CIN-463) -- and gains a
|
|
82
|
+
* `$value` only once `resolve.ts` resolves the alias.
|
|
83
|
+
*/
|
|
84
|
+
$value?: unknown;
|
|
85
|
+
/**
|
|
86
|
+
* DTCG 2025.10 whole-token alias: a JSON Pointer to another token, in
|
|
87
|
+
* place of `$value`. `resolve.ts` deletes this once the token is resolved,
|
|
88
|
+
* so a fully resolved `DesignToken` never carries both `$ref` and `$value`.
|
|
89
|
+
*/
|
|
90
|
+
$ref?: string;
|
|
91
|
+
$type?: TokenType;
|
|
92
|
+
$description?: string;
|
|
93
|
+
$deprecated?: boolean | string;
|
|
94
|
+
$extensions?: TokenExtensions;
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export type TokenGroup = {
|
|
98
|
+
$type?: TokenType;
|
|
99
|
+
$description?: string;
|
|
100
|
+
$deprecated?: boolean | string;
|
|
101
|
+
$extensions?: TokenExtensions;
|
|
102
|
+
$root?: DesignToken;
|
|
103
|
+
$extends?: string;
|
|
104
|
+
[name: TokenName]: DesignToken | TokenGroup | string | boolean | TokenExtensions | undefined;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export type TokenDocument = TokenGroup & {
|
|
108
|
+
$schema?: string;
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* DTCG 2025.10 resolver reference object. Cinder only authors $ref entries
|
|
113
|
+
* (relative file paths for sources, #/sets/<name> or #/modifiers/<name> for
|
|
114
|
+
* resolutionOrder) -- the spec also allows inline set/modifier/token
|
|
115
|
+
* documents in these positions, which Cinder does not use.
|
|
116
|
+
*/
|
|
117
|
+
export type ResolverReference = { $ref: string };
|
|
118
|
+
export type ResolverSet = { sources: ResolverReference[] };
|
|
119
|
+
export type ResolverModifier = {
|
|
120
|
+
contexts: Record<string, ResolverReference[]>;
|
|
121
|
+
default?: string;
|
|
122
|
+
};
|
|
123
|
+
export type ResolverDocument = {
|
|
124
|
+
version: '2025.10';
|
|
125
|
+
sets: Record<string, ResolverSet>;
|
|
126
|
+
modifiers: Record<string, ResolverModifier>;
|
|
127
|
+
resolutionOrder: ResolverReference[];
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export type ValidationIssue = { path: string; reason: string };
|
|
131
|
+
|
|
132
|
+
export class TokenValidationError extends Error {
|
|
133
|
+
constructor(
|
|
134
|
+
readonly issues: ValidationIssue[],
|
|
135
|
+
readonly sourceOwned = false,
|
|
136
|
+
) {
|
|
137
|
+
super(issues.map((issue) => `${issue.path}: ${issue.reason}`).join('\n'));
|
|
138
|
+
this.name = 'TokenValidationError';
|
|
139
|
+
}
|
|
140
|
+
}
|