@lostgradient/cinder 0.27.1 → 0.28.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.
- package/CHANGELOG.md +41 -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,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-token provenance for one ordered document stack.
|
|
3
|
+
*
|
|
4
|
+
* Given the documents one modifier context resolves, in resolution order, this
|
|
5
|
+
* reports for every token which layers supply it, which declaration wins, where
|
|
6
|
+
* its effective DTCG type is declared, and what its winning declaration reads.
|
|
7
|
+
* It reuses the evaluation machinery (`mergeAndExpandExtends`, `collectEntries`)
|
|
8
|
+
* instead of re-deriving it, so the answer is the evaluator's own: the tests
|
|
9
|
+
* assert it matches `resolveDocuments` for every token.
|
|
10
|
+
*
|
|
11
|
+
* No Node imports. The COR-491 runtime reuses this for an edited layer stack,
|
|
12
|
+
* so resetting an override is just tracing the stack without that edit.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
UNKNOWN,
|
|
17
|
+
type AuthoringLayer,
|
|
18
|
+
type ContributingLayer,
|
|
19
|
+
type EffectiveType,
|
|
20
|
+
type TokenContextProvenance,
|
|
21
|
+
type TokenInputs,
|
|
22
|
+
type TokenLocation,
|
|
23
|
+
} from './authoring-types.ts';
|
|
24
|
+
import { collectEntries, type CorpusEntry } from './corpus.ts';
|
|
25
|
+
import { tokenPathFromReference } from './resolve-shared.ts';
|
|
26
|
+
import { mergeAndExpandExtends } from './resolve.ts';
|
|
27
|
+
import type { DesignToken, TokenDocument, TokenGroup } from './types.ts';
|
|
28
|
+
|
|
29
|
+
/** One layer of a stack: its identity and its raw document. */
|
|
30
|
+
export type ProvenanceLayerInput = AuthoringLayer & { content: TokenDocument };
|
|
31
|
+
|
|
32
|
+
export type TraceOptions = {
|
|
33
|
+
/** Public custom property -> token path, used to name `cssRecipe` inputs. */
|
|
34
|
+
cssPropertyToPath?: Readonly<Record<string, string>>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type Node = Record<string, unknown>;
|
|
38
|
+
|
|
39
|
+
function isNode(value: unknown): value is Node {
|
|
40
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function isTokenNode(value: unknown): value is DesignToken {
|
|
44
|
+
return isNode(value) && ('$value' in value || '$ref' in value);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** A non-token object node is a group. */
|
|
48
|
+
function asGroup(node: Node): TokenGroup {
|
|
49
|
+
const group: TokenGroup = {};
|
|
50
|
+
for (const [key, value] of Object.entries(node))
|
|
51
|
+
Object.defineProperty(group, key, {
|
|
52
|
+
value,
|
|
53
|
+
enumerable: true,
|
|
54
|
+
configurable: true,
|
|
55
|
+
writable: true,
|
|
56
|
+
});
|
|
57
|
+
return group;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type Located = {
|
|
61
|
+
token: DesignToken | undefined;
|
|
62
|
+
groups: Array<{ path: string; group: TokenGroup }>;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** Walks a document to a token path, collecting the groups on the way (a `$root` shares its group's path). */
|
|
66
|
+
function locate(root: TokenDocument, path: string): Located {
|
|
67
|
+
const groups: Located['groups'] = [{ path: '', group: root }];
|
|
68
|
+
let current: unknown = root;
|
|
69
|
+
let prefix = '';
|
|
70
|
+
for (const segment of path === '' ? [] : path.split('.')) {
|
|
71
|
+
if (!isNode(current)) return { token: undefined, groups };
|
|
72
|
+
current = current[segment];
|
|
73
|
+
prefix = prefix ? `${prefix}.${segment}` : segment;
|
|
74
|
+
if (isNode(current) && !isTokenNode(current))
|
|
75
|
+
groups.push({ path: prefix, group: asGroup(current) });
|
|
76
|
+
}
|
|
77
|
+
if (isTokenNode(current)) return { token: current, groups };
|
|
78
|
+
if (isNode(current) && isTokenNode(current['$root'])) return { token: current['$root'], groups };
|
|
79
|
+
return { token: undefined, groups };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function cinderOf(token: DesignToken | undefined): Node | undefined {
|
|
83
|
+
const own = token?.$extensions?.['com.lostgradient.cinder'];
|
|
84
|
+
return isNode(own) ? own : undefined;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function referencedPaths(value: unknown, into: Set<string>): void {
|
|
88
|
+
if (typeof value === 'string') {
|
|
89
|
+
for (const match of value.matchAll(/\{([^{}]+)\}/g)) into.add(match[1]!);
|
|
90
|
+
if (value.startsWith('#/')) {
|
|
91
|
+
try {
|
|
92
|
+
into.add(tokenPathFromReference(value));
|
|
93
|
+
} catch {
|
|
94
|
+
// A malformed pointer is a validation error, reported by the validators.
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
} else if (Array.isArray(value)) for (const item of value) referencedPaths(item, into);
|
|
98
|
+
else if (isNode(value)) for (const item of Object.values(value)) referencedPaths(item, into);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function pointerOrReferencePath(reference: string): string | undefined {
|
|
102
|
+
try {
|
|
103
|
+
return tokenPathFromReference(reference);
|
|
104
|
+
} catch {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The merged `com.lostgradient.cinder` extension block of every token, keyed by
|
|
111
|
+
* path. `CorpusEntry` carries only the fields CSS generation reads; the
|
|
112
|
+
* catalogue also needs `nonRepresentableValue` and `scale`.
|
|
113
|
+
*/
|
|
114
|
+
export function collectCinderExtensions(root: TokenDocument): Map<string, Record<string, unknown>> {
|
|
115
|
+
const result = new Map<string, Record<string, unknown>>();
|
|
116
|
+
const walk = (group: TokenGroup, prefix: string): void => {
|
|
117
|
+
if (isTokenNode(group.$root)) result.set(prefix, cinderOf(group.$root) ?? {});
|
|
118
|
+
for (const [name, value] of Object.entries(group)) {
|
|
119
|
+
if (name.startsWith('$') || !isNode(value)) continue;
|
|
120
|
+
const path = prefix ? `${prefix}.${name}` : name;
|
|
121
|
+
if (isTokenNode(value)) result.set(path, cinderOf(value) ?? {});
|
|
122
|
+
else walk(asGroup(value), path);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
walk(root, '');
|
|
126
|
+
return result;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Traces every token of one ordered stack. */
|
|
130
|
+
export function traceProvenance(
|
|
131
|
+
stack: readonly ProvenanceLayerInput[],
|
|
132
|
+
options: TraceOptions = {},
|
|
133
|
+
): Map<string, TokenContextProvenance> {
|
|
134
|
+
const documents = stack.map((layer) => layer.content);
|
|
135
|
+
const merged = mergeAndExpandExtends(documents);
|
|
136
|
+
const finalEntries = new Map<string, CorpusEntry>();
|
|
137
|
+
collectEntries(merged, '', undefined, finalEntries);
|
|
138
|
+
|
|
139
|
+
const rawEntries = documents.map((document) => {
|
|
140
|
+
const entries = new Map<string, CorpusEntry>();
|
|
141
|
+
collectEntries(document, '', undefined, entries);
|
|
142
|
+
return entries;
|
|
143
|
+
});
|
|
144
|
+
const expanded = documents.map((document) => mergeAndExpandExtends([document], documents));
|
|
145
|
+
const expandedEntries = expanded.map((document) => {
|
|
146
|
+
const entries = new Map<string, CorpusEntry>();
|
|
147
|
+
collectEntries(document, '', undefined, entries);
|
|
148
|
+
return entries;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Whether layer `index` declares a group above `path` that carries an `$extends`. A layer's
|
|
153
|
+
* own groups shadow the lookup documents, so a layer that restates the extended group cannot
|
|
154
|
+
* expand to a member only an earlier layer declares; the merge still delivers it.
|
|
155
|
+
*/
|
|
156
|
+
function declaresExtendingAncestor(index: number, path: string): boolean {
|
|
157
|
+
const segments = path.split('.');
|
|
158
|
+
return segments.some((_, length) => {
|
|
159
|
+
const groupPath = segments.slice(0, length).join('.');
|
|
160
|
+
const group = locate(documents[index]!, groupPath).groups.find((g) => g.path === groupPath);
|
|
161
|
+
return typeof group?.group.$extends === 'string';
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** The last layer whose expansion holds `path`, else the last that extends a group above it. */
|
|
166
|
+
function supplyingLayer(path: string): number {
|
|
167
|
+
const expandedHolder = stack.findLastIndex((_, index) => expandedEntries[index]!.has(path));
|
|
168
|
+
if (expandedHolder >= 0) return expandedHolder;
|
|
169
|
+
return stack.findLastIndex((_, index) => declaresExtendingAncestor(index, path));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/** Where a member is copied from when layer `index` supplies it through the `$extends` of its ancestor `length` segments deep. */
|
|
173
|
+
function extendsHop(
|
|
174
|
+
segments: readonly string[],
|
|
175
|
+
index: number,
|
|
176
|
+
length: number,
|
|
177
|
+
): { index: number; path: string } | undefined {
|
|
178
|
+
const groupPath = segments.slice(0, length).join('.');
|
|
179
|
+
const group = locate(documents[index]!, groupPath).groups.find((g) => g.path === groupPath);
|
|
180
|
+
const extended = group?.group.$extends;
|
|
181
|
+
const target = typeof extended === 'string' ? pointerOrReferencePath(extended) : undefined;
|
|
182
|
+
if (target === undefined) return undefined;
|
|
183
|
+
const origin = [target, ...segments.slice(length)].filter(Boolean).join('.');
|
|
184
|
+
const holder = supplyingLayer(origin);
|
|
185
|
+
return holder < 0 ? undefined : { index: holder, path: origin };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The declaration that really supplies `path` in layer `index`, following `$extends` members back to their origin. */
|
|
189
|
+
function originOf(path: string, index: number, depth = 0): { index: number; path: string } {
|
|
190
|
+
if (rawEntries[index]!.has(path) || depth > 32) return { index, path };
|
|
191
|
+
const segments = path.split('.');
|
|
192
|
+
// The nearest extending ancestor that can account for the member wins.
|
|
193
|
+
const hop = segments
|
|
194
|
+
.map((_, length) => extendsHop(segments, index, length))
|
|
195
|
+
.findLast((candidate) => candidate !== undefined);
|
|
196
|
+
return hop === undefined ? { index, path } : originOf(hop.path, hop.index, depth + 1);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function typeOf(path: string, entry: CorpusEntry): EffectiveType {
|
|
200
|
+
const located = locate(merged, path);
|
|
201
|
+
let declaring: { path: string; local: boolean } | undefined;
|
|
202
|
+
if (located.token?.$type !== undefined) declaring = { path, local: true };
|
|
203
|
+
else {
|
|
204
|
+
const ancestor = located.groups.toReversed().find((g) => g.group.$type !== undefined);
|
|
205
|
+
if (ancestor) declaring = { path: ancestor.path, local: false };
|
|
206
|
+
}
|
|
207
|
+
if (!declaring || entry.type === undefined)
|
|
208
|
+
return { type: entry.type ?? UNKNOWN, origin: UNKNOWN, declaredAt: UNKNOWN };
|
|
209
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
210
|
+
const inLayer = locate(expanded[index]!, declaring.path);
|
|
211
|
+
const node = declaring.local
|
|
212
|
+
? inLayer.token
|
|
213
|
+
: inLayer.groups.find((g) => g.path === declaring.path)?.group;
|
|
214
|
+
if (node?.$type !== undefined)
|
|
215
|
+
return {
|
|
216
|
+
type: entry.type,
|
|
217
|
+
origin: declaring.local ? 'local' : 'inherited',
|
|
218
|
+
declaredAt: { document: stack[index]!.document, path: declaring.path },
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
return {
|
|
222
|
+
type: entry.type,
|
|
223
|
+
origin: declaring.local ? 'local' : 'inherited',
|
|
224
|
+
declaredAt: UNKNOWN,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function inputsOf(path: string): TokenInputs {
|
|
229
|
+
const located = locate(merged, path);
|
|
230
|
+
const aliases = new Set<string>();
|
|
231
|
+
if (located.token?.$value !== undefined) referencedPaths(located.token.$value, aliases);
|
|
232
|
+
const refs = typeof located.token?.$ref === 'string' ? [located.token.$ref] : [];
|
|
233
|
+
const extendsInputs: TokenInputs['extends'] = [];
|
|
234
|
+
for (const { path: groupPath } of located.groups) {
|
|
235
|
+
for (let index = stack.length - 1; index >= 0; index--) {
|
|
236
|
+
const rawGroup = locate(documents[index]!, groupPath).groups.find(
|
|
237
|
+
(g) => g.path === groupPath,
|
|
238
|
+
)?.group;
|
|
239
|
+
if (typeof rawGroup?.$extends !== 'string') continue;
|
|
240
|
+
const target = pointerOrReferencePath(rawGroup.$extends);
|
|
241
|
+
if (target !== undefined) extendsInputs.push({ group: groupPath, target });
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const recipe = cinderOf(located.token)?.['cssRecipe'];
|
|
246
|
+
const recipes: TokenInputs['recipes'] = [];
|
|
247
|
+
if (typeof recipe === 'string') {
|
|
248
|
+
for (const match of recipe.matchAll(/var\(\s*(--[A-Za-z0-9_-]+)/g)) {
|
|
249
|
+
const cssProperty = match[1]!;
|
|
250
|
+
if (recipes.some((r) => r.cssProperty === cssProperty)) continue;
|
|
251
|
+
recipes.push({ cssProperty, path: options.cssPropertyToPath?.[cssProperty] ?? UNKNOWN });
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return {
|
|
255
|
+
aliases: [...aliases].map((alias) => pointerOrReferencePath(`{${alias}}`) ?? alias),
|
|
256
|
+
refs: refs.map((ref) => pointerOrReferencePath(ref) ?? ref),
|
|
257
|
+
extends: extendsInputs,
|
|
258
|
+
recipes,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
const traced = new Map<string, TokenContextProvenance>();
|
|
263
|
+
for (const [path, entry] of finalEntries) {
|
|
264
|
+
const layers: ContributingLayer[] = [];
|
|
265
|
+
const expandedAnywhere = expandedEntries.some((entries) => entries.has(path));
|
|
266
|
+
const supplies = stack.map((_, index) =>
|
|
267
|
+
expandedAnywhere ? expandedEntries[index]!.has(path) : declaresExtendingAncestor(index, path),
|
|
268
|
+
);
|
|
269
|
+
stack.forEach((layer, index) => {
|
|
270
|
+
if (!supplies[index]) return;
|
|
271
|
+
layers.push({
|
|
272
|
+
document: layer.document,
|
|
273
|
+
kind: layer.kind,
|
|
274
|
+
layer: layer.layer,
|
|
275
|
+
path,
|
|
276
|
+
via: rawEntries[index]!.has(path) ? 'declared' : 'extends',
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
const lastIndex = supplyingLayer(path);
|
|
280
|
+
const origin = originOf(path, lastIndex);
|
|
281
|
+
const winner: TokenLocation = { document: stack[origin.index]!.document, path: origin.path };
|
|
282
|
+
traced.set(path, {
|
|
283
|
+
winner,
|
|
284
|
+
layers,
|
|
285
|
+
effectiveType: typeOf(path, entry),
|
|
286
|
+
inputs: inputsOf(path),
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return traced;
|
|
290
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Data model for the token authoring catalogue.
|
|
3
|
+
*
|
|
4
|
+
* This module is deliberately free of Node imports and of any import that
|
|
5
|
+
* reaches Node: the shapes below are the contract the browser-side token
|
|
6
|
+
* runtime (COR-491) consumes, so they must be movable into
|
|
7
|
+
* `src/tokens/runtime/` unchanged. Everything here is plain JSON-serializable
|
|
8
|
+
* data.
|
|
9
|
+
*
|
|
10
|
+
* The central record is {@link TokenContextProvenance}: where one token's value
|
|
11
|
+
* and type come from in one concrete modifier context. The catalogue stores it
|
|
12
|
+
* per token and per context (deduplicated into {@link ProvenanceVariant}s),
|
|
13
|
+
* and the runtime recomputes the same shape from an edited layer stack.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { TokenType } from './types.ts';
|
|
17
|
+
|
|
18
|
+
/** The literal rendered for source metadata the corpus does not declare. */
|
|
19
|
+
export const UNKNOWN = 'unknown' as const;
|
|
20
|
+
export type Unknown = typeof UNKNOWN;
|
|
21
|
+
|
|
22
|
+
/** One concrete modifier combination, e.g. `{ theme: 'dark', motion: 'reduced' }`. */
|
|
23
|
+
export type AuthoringContext = {
|
|
24
|
+
/** Deterministic id: `<theme>/<motion>`. */
|
|
25
|
+
id: string;
|
|
26
|
+
theme: string;
|
|
27
|
+
motion: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function authoringContextId(theme: string, motion: string): string {
|
|
31
|
+
return `${theme}/${motion}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Whether a layer is a resolver set or one context of a modifier. */
|
|
35
|
+
export type LayerKind = 'set' | 'modifier';
|
|
36
|
+
|
|
37
|
+
/** One ordered document in a context's resolution stack. */
|
|
38
|
+
export type AuthoringLayer = {
|
|
39
|
+
/** The document id: its repository-relative source path. */
|
|
40
|
+
document: string;
|
|
41
|
+
kind: LayerKind;
|
|
42
|
+
/** The resolver entry that contributed it, e.g. `sets.foundation` or `theme.dark`. */
|
|
43
|
+
layer: string;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/** A token path inside one document. */
|
|
47
|
+
export type TokenLocation = { document: string; path: string };
|
|
48
|
+
|
|
49
|
+
/** A layer that supplies a token, plus how it supplies it. */
|
|
50
|
+
export type ContributingLayer = TokenLocation &
|
|
51
|
+
AuthoringLayer & {
|
|
52
|
+
/** `declared` is written in the layer; `extends` arrives through a group `$extends`. */
|
|
53
|
+
via: 'declared' | 'extends';
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** The effective DTCG type and where it is declared. */
|
|
57
|
+
export type EffectiveType = {
|
|
58
|
+
type: TokenType | Unknown;
|
|
59
|
+
/** `local` is typed on the token itself; `inherited` comes from an ancestor group. */
|
|
60
|
+
origin: 'local' | 'inherited' | Unknown;
|
|
61
|
+
/** The node that declares the type: the token (local) or the group (inherited). */
|
|
62
|
+
declaredAt: TokenLocation | Unknown;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** The direct inputs of the winning declaration. */
|
|
66
|
+
export type TokenInputs = {
|
|
67
|
+
/** Token paths named by `{a.b}` references inside `$value`, in first-use order. */
|
|
68
|
+
aliases: string[];
|
|
69
|
+
/** Token paths named by a whole-token `$ref` pointer. */
|
|
70
|
+
refs: string[];
|
|
71
|
+
/** Groups the token's ancestors extend: `group` extends `target`. */
|
|
72
|
+
extends: Array<{ group: string; target: string }>;
|
|
73
|
+
/** Public custom properties a trusted `cssRecipe` reads through `var()`. */
|
|
74
|
+
recipes: Array<{ cssProperty: string; path: string }>;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/** Provenance of one token in one concrete context. The TB02 runtime reuses this shape. */
|
|
78
|
+
export type TokenContextProvenance = {
|
|
79
|
+
/** The winning declaration (the last contributing layer). */
|
|
80
|
+
winner: TokenLocation;
|
|
81
|
+
/** Every layer that supplies the token, lowest precedence first. */
|
|
82
|
+
layers: ContributingLayer[];
|
|
83
|
+
effectiveType: EffectiveType;
|
|
84
|
+
inputs: TokenInputs;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** One provenance record shared by every context in `contexts`. */
|
|
88
|
+
export type ProvenanceVariant = {
|
|
89
|
+
contexts: string[];
|
|
90
|
+
provenance: TokenContextProvenance;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/** How a token may be edited, exported as CSS, and exported as portable DTCG. */
|
|
94
|
+
export type TokenDisposition = {
|
|
95
|
+
/**
|
|
96
|
+
* `supported` edits the DTCG `$value`; `recipe` edits a trusted `cssRecipe`
|
|
97
|
+
* that governs the CSS; `css-only` has no DTCG-editable value at all.
|
|
98
|
+
*/
|
|
99
|
+
edit: 'supported' | 'recipe' | 'css-only';
|
|
100
|
+
/** Every public token is emitted into `tokens-base.css`. */
|
|
101
|
+
cssExport: 'supported';
|
|
102
|
+
/**
|
|
103
|
+
* `complete` exports the whole token; `subset` exports the DTCG value but not
|
|
104
|
+
* the CSS recipe that governs the emitted CSS; `none` exports nothing,
|
|
105
|
+
* because the token has no faithful portable value.
|
|
106
|
+
*/
|
|
107
|
+
dtcgExport: 'complete' | 'subset' | 'none';
|
|
108
|
+
cssSerialization: 'typed-value' | 'trusted-recipe' | 'mixed';
|
|
109
|
+
/** The real CSS value, present only for `css-only` tokens. Never a placeholder. */
|
|
110
|
+
cssValue?: string;
|
|
111
|
+
/** Why a token is not fully portable. */
|
|
112
|
+
reason?: string;
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
/** The numeric part a usage profile constrains. */
|
|
116
|
+
export type ProfileNumericPart = 'number' | 'dimension.value' | 'duration.value' | 'fontWeight';
|
|
117
|
+
|
|
118
|
+
/** A machine-readable numeric constraint. All bounds are inclusive unless stated. */
|
|
119
|
+
export type ProfileRange = {
|
|
120
|
+
part: ProfileNumericPart;
|
|
121
|
+
finite: true;
|
|
122
|
+
min?: number;
|
|
123
|
+
max?: number;
|
|
124
|
+
/** When true the `min` bound itself is rejected (`> min`). */
|
|
125
|
+
minExclusive?: boolean;
|
|
126
|
+
integer?: boolean;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
/** A CSS usage contract: what a token may legally be, given the properties it feeds. */
|
|
130
|
+
export type ProfileDefinition = {
|
|
131
|
+
id: string;
|
|
132
|
+
description: string;
|
|
133
|
+
/** DTCG types a token with this profile may have (a trusted `cssRecipe` may override). */
|
|
134
|
+
types: TokenType[];
|
|
135
|
+
/** The CSS properties the token is consumed by. */
|
|
136
|
+
cssUsage: string[];
|
|
137
|
+
/** Absent for non-numeric profiles. */
|
|
138
|
+
range?: ProfileRange;
|
|
139
|
+
/** Named values accepted in place of a number (font weights). */
|
|
140
|
+
keywords?: string[];
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
/** The palette families a color token may belong to. */
|
|
144
|
+
export const PALETTE_FAMILIES = [
|
|
145
|
+
'accent',
|
|
146
|
+
'neutral',
|
|
147
|
+
'success',
|
|
148
|
+
'warning',
|
|
149
|
+
'danger',
|
|
150
|
+
'info',
|
|
151
|
+
] as const;
|
|
152
|
+
export type PaletteFamily = (typeof PALETTE_FAMILIES)[number];
|
|
153
|
+
|
|
154
|
+
/** A color token's declared membership of one palette family. */
|
|
155
|
+
export type PaletteMembership = {
|
|
156
|
+
family: PaletteFamily;
|
|
157
|
+
/** The role the token plays inside the family, unique within the family. */
|
|
158
|
+
role: string;
|
|
159
|
+
/** True for the single token that holds the family's seed-matching color. */
|
|
160
|
+
anchor: boolean;
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/** One generated record per public registry entry. */
|
|
164
|
+
export type AuthoringRecord = {
|
|
165
|
+
path: string;
|
|
166
|
+
cssProperty: string;
|
|
167
|
+
/** The literal `unknown` when the corpus declares none. */
|
|
168
|
+
category: string;
|
|
169
|
+
component: string | null;
|
|
170
|
+
/** The literal `unknown` when the corpus declares none. */
|
|
171
|
+
description: string;
|
|
172
|
+
themeAware: boolean;
|
|
173
|
+
deprecated: boolean | string;
|
|
174
|
+
/** The usage profile id (see `authoring-profiles.ts`). */
|
|
175
|
+
profile: string;
|
|
176
|
+
/** The scale this token is a member of, when the corpus marks one. */
|
|
177
|
+
scale?: string;
|
|
178
|
+
/**
|
|
179
|
+
* Palette membership of a color token, from the explicit `palette` extension in source (never
|
|
180
|
+
* inferred from the token name). A color token that declares none reports `unknown`.
|
|
181
|
+
*/
|
|
182
|
+
palette?: PaletteMembership | { family: Unknown; role: Unknown; anchor: Unknown };
|
|
183
|
+
disposition: TokenDisposition;
|
|
184
|
+
variants: ProvenanceVariant[];
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/** The generated artifact. */
|
|
188
|
+
export type AuthoringCatalogue = {
|
|
189
|
+
version: 1;
|
|
190
|
+
dtcgVersion: '2025.10';
|
|
191
|
+
contexts: AuthoringContext[];
|
|
192
|
+
/** Ordered layer stack per context id. */
|
|
193
|
+
layerStacks: Record<string, AuthoringLayer[]>;
|
|
194
|
+
/** Profile definitions referenced by `AuthoringRecord.profile`. */
|
|
195
|
+
profiles: Record<string, ProfileDefinition>;
|
|
196
|
+
/** Scale name -> member token paths, in group order. */
|
|
197
|
+
scales: Record<string, string[]>;
|
|
198
|
+
records: AuthoringRecord[];
|
|
199
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE. Do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* The source digest of the bundled Cinder token base: a digest of the resolver
|
|
5
|
+
* and documents only, so nothing that changes at publish time can alter it.
|
|
6
|
+
* Regenerate: bun run --filter=@lostgradient/cinder tokens:generate
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export const BASE_SOURCE_DIGEST =
|
|
10
|
+
'sha256:35fb1c57b3c88ef6a75177972511a54deeda735c903b0bf71d63929200d37a28';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The immutable Cinder token base, as data.
|
|
3
|
+
*
|
|
4
|
+
* A theme is a set of overrides on this base, so a consumer that evaluates or
|
|
5
|
+
* saves a theme needs the base it was written against. This exports the
|
|
6
|
+
* resolver and every bundled token document keyed by relative path (the same
|
|
7
|
+
* keys the resolver's `$ref`s use), the package version, and a digest of the
|
|
8
|
+
* sources so a saved theme can detect that the base has since changed.
|
|
9
|
+
*
|
|
10
|
+
* The documents are the package's own source files, imported as JSON: one copy,
|
|
11
|
+
* no generated duplicate. The version and digest are generated by
|
|
12
|
+
* `tokens:generate` and checked by `tokens:check`; the runtime test recomputes
|
|
13
|
+
* the digest from these documents and fails if they disagree.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import resolverSource from '../cinder.resolver.json' with { type: 'json' };
|
|
17
|
+
import motionDefault from '../modes/motion-default.tokens.json' with { type: 'json' };
|
|
18
|
+
import motionForcedReduced from '../modes/motion-forced-reduced.tokens.json' with { type: 'json' };
|
|
19
|
+
import motionReduced from '../modes/motion-reduced.tokens.json' with { type: 'json' };
|
|
20
|
+
import colorsSet from '../sets/colors.tokens.json' with { type: 'json' };
|
|
21
|
+
import componentsSet from '../sets/components.tokens.json' with { type: 'json' };
|
|
22
|
+
import foundationSet from '../sets/foundation.tokens.json' with { type: 'json' };
|
|
23
|
+
import semanticSet from '../sets/semantic.tokens.json' with { type: 'json' };
|
|
24
|
+
import darkTheme from '../themes/dark.tokens.json' with { type: 'json' };
|
|
25
|
+
import lightTheme from '../themes/light.tokens.json' with { type: 'json' };
|
|
26
|
+
import { BASE_SOURCE_DIGEST } from './base-corpus.generated.ts';
|
|
27
|
+
import { VERSION } from './package-version.generated.ts';
|
|
28
|
+
import type { ResolverDocument, TokenDocument } from './types.ts';
|
|
29
|
+
import { assertValidResolverDocument } from './validate.ts';
|
|
30
|
+
|
|
31
|
+
/** The bundled Cinder base: what a theme's overrides are applied to. */
|
|
32
|
+
export type CinderBase = {
|
|
33
|
+
/**
|
|
34
|
+
* The `@lostgradient/cinder` version these sources ship in: `workspace` in the
|
|
35
|
+
* monorepo, and the published version in a mirrored package.
|
|
36
|
+
*/
|
|
37
|
+
packageVersion: string;
|
|
38
|
+
/** `sha256:<hex>` over the canonical form of `{ resolver, documents }`. */
|
|
39
|
+
sourceDigest: string;
|
|
40
|
+
resolver: ResolverDocument;
|
|
41
|
+
/** Token documents keyed by the relative path the resolver references. */
|
|
42
|
+
documents: Readonly<Record<string, TokenDocument>>;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function isTokenDocument(value: unknown): value is TokenDocument {
|
|
46
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function tokenDocument(path: string, value: unknown): TokenDocument {
|
|
50
|
+
if (!isTokenDocument(value)) throw new Error(`Bundled token document ${path} is not an object.`);
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function bundledResolver(value: unknown): ResolverDocument {
|
|
55
|
+
assertValidResolverDocument(value);
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const bundledDocuments: Array<[string, unknown]> = [
|
|
60
|
+
['modes/motion-default.tokens.json', motionDefault],
|
|
61
|
+
['modes/motion-forced-reduced.tokens.json', motionForcedReduced],
|
|
62
|
+
['modes/motion-reduced.tokens.json', motionReduced],
|
|
63
|
+
['sets/colors.tokens.json', colorsSet],
|
|
64
|
+
['sets/components.tokens.json', componentsSet],
|
|
65
|
+
['sets/foundation.tokens.json', foundationSet],
|
|
66
|
+
['sets/semantic.tokens.json', semanticSet],
|
|
67
|
+
['themes/dark.tokens.json', darkTheme],
|
|
68
|
+
['themes/light.tokens.json', lightTheme],
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
export const CINDER_BASE: CinderBase = {
|
|
72
|
+
packageVersion: VERSION,
|
|
73
|
+
sourceDigest: BASE_SOURCE_DIGEST,
|
|
74
|
+
resolver: bundledResolver(resolverSource),
|
|
75
|
+
documents: Object.fromEntries(
|
|
76
|
+
bundledDocuments.map(([path, document]) => [path, tokenDocument(path, document)]),
|
|
77
|
+
),
|
|
78
|
+
};
|