@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,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@lostgradient/cinder/tokens/runtime`: the pure token kernel shared by the
|
|
3
|
+
* generator scripts and the browser.
|
|
4
|
+
*
|
|
5
|
+
* It is a narrow, in-memory interface -- validate, evaluate (resolve and
|
|
6
|
+
* project), trace provenance -- plus the bundled Cinder base and the authoring
|
|
7
|
+
* catalogue as data. It reads no files, fetches nothing, and formats nothing.
|
|
8
|
+
* See `README.md` for the contract.
|
|
9
|
+
*
|
|
10
|
+
* There is deliberately no export for validating a document against the schema
|
|
11
|
+
* alone: every path to a result runs the schema stage and then the semantic
|
|
12
|
+
* rules together.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export { AUTHORING_CATALOGUE } from './authoring-catalogue.generated.ts';
|
|
16
|
+
export { buildAuthoringCatalogue } from './authoring-catalogue.ts';
|
|
17
|
+
export { PROFILES, profileRangeViolation, selectProfile } from './authoring-profiles.ts';
|
|
18
|
+
export type { ProfileSubject } from './authoring-profiles.ts';
|
|
19
|
+
export { traceProvenance } from './authoring-provenance.ts';
|
|
20
|
+
export type { ProvenanceLayerInput, TraceOptions } from './authoring-provenance.ts';
|
|
21
|
+
export { PALETTE_FAMILIES, UNKNOWN, authoringContextId } from './authoring-types.ts';
|
|
22
|
+
export type {
|
|
23
|
+
AuthoringCatalogue,
|
|
24
|
+
AuthoringContext,
|
|
25
|
+
AuthoringLayer,
|
|
26
|
+
AuthoringRecord,
|
|
27
|
+
ContributingLayer,
|
|
28
|
+
EffectiveType,
|
|
29
|
+
LayerKind,
|
|
30
|
+
PaletteFamily,
|
|
31
|
+
PaletteMembership,
|
|
32
|
+
ProfileDefinition,
|
|
33
|
+
ProfileRange,
|
|
34
|
+
ProvenanceVariant,
|
|
35
|
+
TokenContextProvenance,
|
|
36
|
+
TokenDisposition,
|
|
37
|
+
TokenInputs,
|
|
38
|
+
TokenLocation,
|
|
39
|
+
} from './authoring-types.ts';
|
|
40
|
+
export { CINDER_BASE } from './base-corpus.ts';
|
|
41
|
+
export type { CinderBase } from './base-corpus.ts';
|
|
42
|
+
export { authoringContexts, authoringLayerStack } from './context-stack.ts';
|
|
43
|
+
export * from './contrast/index.ts';
|
|
44
|
+
export { evaluateTheme, evaluateThemeProperties, validateThemeSources } from './evaluate.ts';
|
|
45
|
+
export type {
|
|
46
|
+
ThemeDiagnostic,
|
|
47
|
+
ThemeEvaluation,
|
|
48
|
+
ThemePropertiesEvaluation,
|
|
49
|
+
ThemeSources,
|
|
50
|
+
ThemeValidation,
|
|
51
|
+
} from './evaluate.ts';
|
|
52
|
+
export { evaluateContextProvenance } from './evaluated-provenance.ts';
|
|
53
|
+
export type { EvaluatedProvenance, TokenEvaluation } from './evaluated-provenance.ts';
|
|
54
|
+
export type { PropertyMap } from './projection.ts';
|
|
55
|
+
export { canonicalJson, computeSourceDigest, sha256Hex } from './source-digest.ts';
|
|
56
|
+
export type { DigestableSource } from './source-digest.ts';
|
|
57
|
+
export {
|
|
58
|
+
OVERRIDE_DOCUMENTS,
|
|
59
|
+
applyCssOnlyOverrides,
|
|
60
|
+
buildThemeSources,
|
|
61
|
+
mergedContextDocument,
|
|
62
|
+
} from './theme-sources.ts';
|
|
63
|
+
export type { OverrideScopeName, ThemeSourceEnvelope } from './theme-sources.ts';
|
|
64
|
+
export { StylesheetError, THEME_LAYER, renderThemeStylesheet } from './theme-stylesheet.ts';
|
|
65
|
+
export type {
|
|
66
|
+
ContextProperties,
|
|
67
|
+
StylesheetContext,
|
|
68
|
+
ThemeStylesheetOptions,
|
|
69
|
+
} from './theme-stylesheet.ts';
|
|
70
|
+
export { TOKEN_TYPES, TokenValidationError } from './types.ts';
|
|
71
|
+
export type {
|
|
72
|
+
DesignToken,
|
|
73
|
+
ResolverDocument,
|
|
74
|
+
TokenDocument,
|
|
75
|
+
TokenGroup,
|
|
76
|
+
TokenType,
|
|
77
|
+
ValidationIssue,
|
|
78
|
+
} from './types.ts';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GENERATED FILE. Do not edit by hand.
|
|
3
|
+
*
|
|
4
|
+
* The version of `@lostgradient/cinder` these token sources ship in. The workspace
|
|
5
|
+
* carries no version, so this is the sentinel `workspace`; the mirror substitutes
|
|
6
|
+
* the published version when it composes the package.
|
|
7
|
+
* Regenerate: bun run --filter=@lostgradient/cinder tokens:generate
|
|
8
|
+
*/
|
|
9
|
+
export const VERSION = '0.27.1';
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Typed and trusted-recipe CSS projection for one evaluation context.
|
|
3
|
+
*
|
|
4
|
+
* Given the ordered documents of a context, this reports the value every public
|
|
5
|
+
* `--cinder-*` custom property has there, written in the same syntax the
|
|
6
|
+
* generated stylesheet uses (a whole-token alias stays `var(--cinder-...)`, a
|
|
7
|
+
* trusted `cssRecipe` is emitted verbatim, a typed value is serialized). It is
|
|
8
|
+
* the generator's own serializer (`serializeEntryValue`) applied to the
|
|
9
|
+
* context's merged tokens, so the browser and `tokens-base.css` cannot disagree
|
|
10
|
+
* about what a token means.
|
|
11
|
+
*
|
|
12
|
+
* A value that cannot be projected is reported, never skipped or replaced with
|
|
13
|
+
* a fallback: the caller gets a path-addressed failure and no property map.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { scopeIndexFromDocuments } from './context-order.ts';
|
|
17
|
+
import type { CorpusEntry } from './corpus.ts';
|
|
18
|
+
import { createValueResolver } from './resolve.ts';
|
|
19
|
+
import type { TokenDocument } from './types.ts';
|
|
20
|
+
import { serializeEntryValue } from './value-entry.ts';
|
|
21
|
+
|
|
22
|
+
/** Public custom property -> CSS value, with keys in code-unit order. */
|
|
23
|
+
export type PropertyMap = Readonly<Record<string, string>>;
|
|
24
|
+
|
|
25
|
+
export type ProjectionFailure = { path: string; reason: string };
|
|
26
|
+
|
|
27
|
+
/** Whether a token belongs to the public `--cinder-*` surface. */
|
|
28
|
+
export function isPublicEntry(entry: CorpusEntry): boolean {
|
|
29
|
+
return (
|
|
30
|
+
entry.public === true &&
|
|
31
|
+
typeof entry.cssProperty === 'string' &&
|
|
32
|
+
entry.cssProperty.startsWith('--cinder-')
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function compareCodeUnits(left: string, right: string): number {
|
|
37
|
+
if (left < right) return -1;
|
|
38
|
+
return left > right ? 1 : 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Projects a context to its public property map. Private `--_cinder-*` runtime
|
|
43
|
+
* variables and tokens with no `cssProperty` never appear in the output.
|
|
44
|
+
*/
|
|
45
|
+
export function projectProperties(
|
|
46
|
+
documents: readonly TokenDocument[],
|
|
47
|
+
index: Map<string, CorpusEntry> = scopeIndexFromDocuments(documents),
|
|
48
|
+
): { properties: PropertyMap; failures: ProjectionFailure[] } {
|
|
49
|
+
const resolveReferences = createValueResolver([...documents]);
|
|
50
|
+
const projected: Array<[string, string]> = [];
|
|
51
|
+
const failures: ProjectionFailure[] = [];
|
|
52
|
+
for (const entry of index.values()) {
|
|
53
|
+
if (!isPublicEntry(entry) || entry.cssProperty === undefined) continue;
|
|
54
|
+
try {
|
|
55
|
+
projected.push([entry.cssProperty, serializeEntryValue(entry, index, resolveReferences)]);
|
|
56
|
+
} catch (error) {
|
|
57
|
+
failures.push({
|
|
58
|
+
path: entry.path,
|
|
59
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
projected.sort(([left], [right]) => compareCodeUnits(left, right));
|
|
64
|
+
return { properties: Object.fromEntries(projected), failures };
|
|
65
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a typed, machine-readable registry of the DTCG token corpus.
|
|
3
|
+
*
|
|
4
|
+
* This is the SHARED extraction module CIN-32 and CIN-34 are blocked on, and
|
|
5
|
+
* the module CIN-31 imports to build `src/tokens/registry.generated.ts` (a
|
|
6
|
+
* package-exported registry for consumers). `generate-artifacts.ts` -- the
|
|
7
|
+
* `tokens:generate` CLI entry point, which depends on both this module and
|
|
8
|
+
* `generate.ts` (see that file's module doc for why the dependency can only
|
|
9
|
+
* run in that direction) -- writes this module's output to
|
|
10
|
+
* `src/tokens/registry.generated.json` as one more `tokens:generate`
|
|
11
|
+
* artifact, via {@link serializeTokenRegistry}. The extraction itself lives
|
|
12
|
+
* here, independent of any file-writing concern, so a caller (CIN-31's
|
|
13
|
+
* generator, a test, `generate-artifacts.ts`'s own JSON writer) gets the
|
|
14
|
+
* typed structure directly instead of having to re-parse generated JSON or
|
|
15
|
+
* re-walk the corpus.
|
|
16
|
+
*
|
|
17
|
+
* Reuses generate.ts's corpus-walking machinery (`collectEntries`,
|
|
18
|
+
* `CorpusEntry`, `loadCorpus`) and resolve.ts's `mergeAndExpandExtends`
|
|
19
|
+
* rather than re-deriving corpus structure -- the base-token index this
|
|
20
|
+
* module builds is assembled the same way `buildTokensBaseCss` assembles
|
|
21
|
+
* `baseIndex`, so the registry and `tokens-base.css` can never structurally
|
|
22
|
+
* disagree about which base tokens exist.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import {
|
|
26
|
+
documentsForResolutionOrder,
|
|
27
|
+
modifierValuesForContext,
|
|
28
|
+
overrideEntries,
|
|
29
|
+
requireDocument,
|
|
30
|
+
} from './context-order.ts';
|
|
31
|
+
import { collectEntries, type CorpusEntry } from './corpus.ts';
|
|
32
|
+
import { assertUniqueCssProperties, withDependentBaseAliases } from './css-support.ts';
|
|
33
|
+
import { createValueResolver, mergeAndExpandExtends } from './resolve.ts';
|
|
34
|
+
import { expandContextSources, parseResolutionOrder, sourcesForEntry } from './resolver-order.ts';
|
|
35
|
+
import type { ResolverDocument, TokenDocument } from './types.ts';
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The theme contexts `buildTokensBaseCss` emits a selector for. The registry's
|
|
39
|
+
* `themeAware` facet means "light or dark overrides this token", so it must
|
|
40
|
+
* track what the CSS actually emits rather than every context the resolver
|
|
41
|
+
* happens to declare -- otherwise a future third context would mark tokens
|
|
42
|
+
* theme-aware that no generated selector overrides.
|
|
43
|
+
*/
|
|
44
|
+
const EMITTED_THEME_CONTEXTS = new Set(['light', 'dark']);
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The two custom-property namespaces the package owns. They are disjoint --
|
|
48
|
+
* `--_cinder-` diverges from `--cinder-` at the third character -- so neither
|
|
49
|
+
* prefix is the complement of the other and a name can satisfy neither.
|
|
50
|
+
*/
|
|
51
|
+
const PUBLIC_TOKEN_PREFIX = '--cinder-';
|
|
52
|
+
const PRIVATE_TOKEN_PREFIX = '--_cinder-';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The full grammar a `cssProperty` must satisfy, not just its prefix.
|
|
56
|
+
*
|
|
57
|
+
* CSS itself permits uppercase and underscores in a custom-property name, and
|
|
58
|
+
* the generators would happily emit one -- but `tokens-doc-drift.test.ts`
|
|
59
|
+
* parses generated rows with a `[a-z0-9-]+` suffix, so a token named
|
|
60
|
+
* `--cinder-fontAxis` would generate CSS and a documentation row and then be
|
|
61
|
+
* reported by the required drift gate as MISSING, pointing at documentation
|
|
62
|
+
* rather than at the name. Rather than widen the parser to accept names the
|
|
63
|
+
* design system does not actually use, the contract is enforced here, at the
|
|
64
|
+
* boundary that owns it, where the error can name the offending token.
|
|
65
|
+
*
|
|
66
|
+
* Keep this in step with that test's row pattern: the two are one contract.
|
|
67
|
+
*/
|
|
68
|
+
const CSS_PROPERTY_PATTERN = /^--_?cinder-[a-z0-9-]+$/;
|
|
69
|
+
|
|
70
|
+
export type TokenRegistryEntry = {
|
|
71
|
+
/** Dotted corpus path, e.g. `space.4` or `button.radius.xs`. */
|
|
72
|
+
path: string;
|
|
73
|
+
/** The `--cinder-*` (or `--_cinder-*`) custom property this token emits. */
|
|
74
|
+
cssProperty: string;
|
|
75
|
+
/** The `com.lostgradient.cinder` extension's `category`, when present. */
|
|
76
|
+
category: string | undefined;
|
|
77
|
+
/** The `com.lostgradient.cinder` extension's `component`, when present -- only component-scoped tokens carry one. */
|
|
78
|
+
component: string | undefined;
|
|
79
|
+
/** The `com.lostgradient.cinder` extension's `public` flag. */
|
|
80
|
+
public: boolean;
|
|
81
|
+
/** Whether the `light` or `dark` theme document overrides this token. */
|
|
82
|
+
themeAware: boolean;
|
|
83
|
+
/** The DTCG `$deprecated` field verbatim: `false` when absent, otherwise `true` or the deprecation message string. */
|
|
84
|
+
deprecated: boolean | string;
|
|
85
|
+
/** The token's `$description`, when present. */
|
|
86
|
+
description: string | undefined;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type TokenRegistry = {
|
|
90
|
+
/** Every base token, in corpus traversal order. */
|
|
91
|
+
entries: readonly TokenRegistryEntry[];
|
|
92
|
+
/** Token path -> CSS custom property. */
|
|
93
|
+
pathToCssProperty: Readonly<Record<string, string>>;
|
|
94
|
+
/**
|
|
95
|
+
* CSS custom property -> a single CANONICAL token path (deterministic --
|
|
96
|
+
* the first path to claim the property in corpus traversal order, never
|
|
97
|
+
* "whichever happened to be assigned last"). The reverse of
|
|
98
|
+
* {@link TokenRegistry.pathToCssProperty}, but not always its exact
|
|
99
|
+
* inverse: `$extends` inheritance can legitimately produce two token paths
|
|
100
|
+
* for one `cssProperty` (the extending group inherits the member, and its
|
|
101
|
+
* `cssProperty`, verbatim -- `assertUniqueCssProperties` in `generate.ts`
|
|
102
|
+
* permits this specific case because both paths emit an identical
|
|
103
|
+
* declaration). When that happens, this map still returns exactly one
|
|
104
|
+
* path so the common "what token backs this CSS property" lookup stays
|
|
105
|
+
* simple; see {@link TokenRegistry.cssPropertyToPaths} for the full list.
|
|
106
|
+
*/
|
|
107
|
+
cssPropertyToPath: Readonly<Record<string, string>>;
|
|
108
|
+
/**
|
|
109
|
+
* CSS custom property -> every token path that claims it, in corpus
|
|
110
|
+
* traversal order (length 1 in the overwhelming common case; length > 1
|
|
111
|
+
* only for the `$extends`-inherited-verbatim case described above).
|
|
112
|
+
* `cssPropertyToPaths[property][0]` always equals
|
|
113
|
+
* `cssPropertyToPath[property]`.
|
|
114
|
+
*/
|
|
115
|
+
cssPropertyToPaths: Readonly<Record<string, readonly string[]>>;
|
|
116
|
+
/** Category name -> the token paths in that category, in corpus traversal order. */
|
|
117
|
+
byCategory: Readonly<Record<string, readonly string[]>>;
|
|
118
|
+
/** Component name -> the token paths scoped to that component, in corpus traversal order. */
|
|
119
|
+
byComponent: Readonly<Record<string, readonly string[]>>;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
function refsFor(
|
|
123
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
124
|
+
refs: ReadonlyArray<{ $ref: string }>,
|
|
125
|
+
): TokenDocument[] {
|
|
126
|
+
return refs.map((ref) => requireDocument(documentsByPath, ref.$ref));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The base `sets` document list the resolver orders -- the exact same
|
|
131
|
+
* assembly `buildTokensBaseCss` uses for its own `baseDocuments`, factored
|
|
132
|
+
* out here so a caller that needs a value resolver over the base scope (the
|
|
133
|
+
* docs generator, serializing a token's `:root` value for its "Default"
|
|
134
|
+
* column) builds it from this same list instead of re-deriving it.
|
|
135
|
+
*/
|
|
136
|
+
export function buildBaseDocuments(
|
|
137
|
+
resolver: ResolverDocument,
|
|
138
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
139
|
+
): TokenDocument[] {
|
|
140
|
+
return parseResolutionOrder(resolver)
|
|
141
|
+
.filter((entry) => entry.kind === 'sets')
|
|
142
|
+
.flatMap((entry) => refsFor(documentsByPath, sourcesForEntry(resolver, entry, {})));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* The base-token index (every token declared by the `sets` the resolver
|
|
147
|
+
* orders, `$extends` already expanded) -- the exact same construction
|
|
148
|
+
* `buildTokensBaseCss` performs for `baseIndex`, factored out here so the
|
|
149
|
+
* registry and `tokens-base.css` generation can never structurally diverge.
|
|
150
|
+
*
|
|
151
|
+
* Also enforces the same `assertUniqueCssProperties` invariant
|
|
152
|
+
* `buildTokensBaseCss` enforces before it ever emits CSS. This module is a
|
|
153
|
+
* shared entry point -- `generate-artifacts.ts` (the `tokens:generate` CLI,
|
|
154
|
+
* which already runs `buildTokensBaseCss` first) is only one caller; a test,
|
|
155
|
+
* or a future CIN-31/32/34 consumer, can call `buildBaseIndex` directly
|
|
156
|
+
* without going through `tokens:generate` at all, and would otherwise accept
|
|
157
|
+
* a conflicting `cssProperty` mapping that CSS generation would have
|
|
158
|
+
* rejected -- producing an ambiguous `cssPropertyToPath` (see
|
|
159
|
+
* {@link buildTokenRegistryFromIndexes}) on a last-write-wins basis with no
|
|
160
|
+
* error.
|
|
161
|
+
*/
|
|
162
|
+
export function buildBaseIndex(
|
|
163
|
+
resolver: ResolverDocument,
|
|
164
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
165
|
+
): Map<string, CorpusEntry> {
|
|
166
|
+
const baseDocuments = buildBaseDocuments(resolver, documentsByPath);
|
|
167
|
+
const mergedBase = mergeAndExpandExtends(baseDocuments);
|
|
168
|
+
const baseIndex = new Map<string, CorpusEntry>();
|
|
169
|
+
collectEntries(mergedBase, '', undefined, baseIndex);
|
|
170
|
+
assertUniqueCssProperties(baseIndex, baseIndex, undefined, () =>
|
|
171
|
+
createValueResolver(baseDocuments),
|
|
172
|
+
);
|
|
173
|
+
return baseIndex;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* The set of base-token paths that the `light` OR `dark` theme document
|
|
178
|
+
* overrides -- "theme-aware" per the registry contract. Built the same way
|
|
179
|
+
* `buildTokensBaseCss` builds `lightOverrides`/`darkOverrides` (own theme
|
|
180
|
+
* documents, `$extends` resolved against the theme's full composed scope so
|
|
181
|
+
* a theme override reaching a foundation group via `$extends` still counts),
|
|
182
|
+
* but only the PATHS are needed here, not the override values themselves.
|
|
183
|
+
*/
|
|
184
|
+
export function themeAwarePaths(
|
|
185
|
+
resolver: ResolverDocument,
|
|
186
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
187
|
+
): Set<string> {
|
|
188
|
+
const themeModifier = resolver.modifiers['theme'];
|
|
189
|
+
if (!themeModifier) return new Set();
|
|
190
|
+
|
|
191
|
+
const aware = new Set<string>();
|
|
192
|
+
const baseDocuments = buildBaseDocuments(resolver, documentsByPath);
|
|
193
|
+
const baseIndex = buildBaseIndex(resolver, documentsByPath);
|
|
194
|
+
// Only the contexts buildTokensBaseCss actually emits a selector for. The
|
|
195
|
+
// registry contract defines themeAware as "light or dark overrides this", so
|
|
196
|
+
// counting a future third context (say `high-contrast`) would advertise
|
|
197
|
+
// tokens as theme-aware that no generated theme selector overrides.
|
|
198
|
+
for (const themeName of Object.keys(themeModifier.contexts).filter((name) =>
|
|
199
|
+
EMITTED_THEME_CONTEXTS.has(name),
|
|
200
|
+
)) {
|
|
201
|
+
// `expandContextSources`, not a raw `themeModifier.contexts[themeName]`
|
|
202
|
+
// read -- the same resolver-internal `#/sets/<name>` expansion
|
|
203
|
+
// `buildTokensBaseCss` in `generate.ts` needs for the identical reason:
|
|
204
|
+
// an unexpanded internal reference reaches `refsFor`'s `requireDocument`,
|
|
205
|
+
// which looks for a literal on-disk document by that name and throws.
|
|
206
|
+
const ownDocuments = refsFor(
|
|
207
|
+
documentsByPath,
|
|
208
|
+
expandContextSources(resolver, 'theme', themeName),
|
|
209
|
+
);
|
|
210
|
+
const scopeDocuments = documentsForResolutionOrder(
|
|
211
|
+
resolver,
|
|
212
|
+
documentsByPath,
|
|
213
|
+
modifierValuesForContext(resolver, 'theme', themeName),
|
|
214
|
+
);
|
|
215
|
+
const overrides = overrideEntries(ownDocuments, scopeDocuments);
|
|
216
|
+
for (const path of withDependentBaseAliases(
|
|
217
|
+
overrides,
|
|
218
|
+
baseIndex,
|
|
219
|
+
createValueResolver(baseDocuments),
|
|
220
|
+
createValueResolver(scopeDocuments),
|
|
221
|
+
).keys())
|
|
222
|
+
aware.add(path);
|
|
223
|
+
}
|
|
224
|
+
return aware;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Builds the typed {@link TokenRegistry} from already-collected corpus
|
|
229
|
+
* indexes. Kept pure and synchronous (no file I/O) so CIN-31's generator, and
|
|
230
|
+
* any test, can construct fixtures directly rather than loading the real
|
|
231
|
+
* corpus from disk. {@link buildTokenRegistry} is the disk-reading wrapper.
|
|
232
|
+
*/
|
|
233
|
+
export function buildTokenRegistryFromIndexes(
|
|
234
|
+
baseIndex: ReadonlyMap<string, CorpusEntry>,
|
|
235
|
+
themeAware: ReadonlySet<string>,
|
|
236
|
+
): TokenRegistry {
|
|
237
|
+
const entries: TokenRegistryEntry[] = [];
|
|
238
|
+
// Every string-keyed index below is built with `Object.create(null)` rather
|
|
239
|
+
// than an object literal. A token path or a free-form `category`/`component`
|
|
240
|
+
// extension value can legitimately be `__proto__` (`resolve.test.ts` asserts
|
|
241
|
+
// this is a supported token path), and assigning into an ordinary object
|
|
242
|
+
// under that key hits the inherited prototype setter instead of creating an
|
|
243
|
+
// own property: the entry silently vanishes from `JSON.stringify` output,
|
|
244
|
+
// a lookup returns `Object.prototype` instead of `undefined`, and a later
|
|
245
|
+
// `(byCategory[entry.category] ??= []).push(...)` throws because
|
|
246
|
+
// `Object.prototype` has no `.push`. `Object.create(null)` sidesteps all of
|
|
247
|
+
// that -- every key becomes a real own property, `__proto__` included.
|
|
248
|
+
const pathToCssProperty: Record<string, string> = Object.create(null);
|
|
249
|
+
const cssPropertyToPath: Record<string, string> = Object.create(null);
|
|
250
|
+
const cssPropertyToPaths: Record<string, string[]> = Object.create(null);
|
|
251
|
+
const byCategory: Record<string, string[]> = Object.create(null);
|
|
252
|
+
const byComponent: Record<string, string[]> = Object.create(null);
|
|
253
|
+
|
|
254
|
+
for (const entry of baseIndex.values()) {
|
|
255
|
+
if (!entry.cssProperty) {
|
|
256
|
+
throw new Error(`Base corpus token at "${entry.path}" has no cssProperty extension.`);
|
|
257
|
+
}
|
|
258
|
+
if (entry.public === undefined) {
|
|
259
|
+
throw new Error(`Base corpus token at "${entry.path}" has no public extension.`);
|
|
260
|
+
}
|
|
261
|
+
// Nothing in corpus validation relates these two free-form extension fields,
|
|
262
|
+
// so without this a token could advertise an internal implementation detail
|
|
263
|
+
// as part of the public surface to every registry consumer.
|
|
264
|
+
if (entry.category !== undefined && entry.category.trim() === '') {
|
|
265
|
+
throw new Error(`Base corpus token at "${entry.path}" has a blank category extension.`);
|
|
266
|
+
}
|
|
267
|
+
if (entry.component !== undefined && entry.component.trim() === '') {
|
|
268
|
+
throw new Error(`Base corpus token at "${entry.path}" has a blank component extension.`);
|
|
269
|
+
}
|
|
270
|
+
// `cssRecipe` is free-form, so the schema accepts `""`. An empty recipe
|
|
271
|
+
// still WINS over the typed `$value` during serialization, so the token
|
|
272
|
+
// emits a custom property with no value and a documentation row whose
|
|
273
|
+
// Default cell is an empty code span -- which `extractDocTokens` cannot
|
|
274
|
+
// match (its value group is `(.+?)`), so the required drift test reports
|
|
275
|
+
// the token missing. Same shape as the cssProperty grammar guard: reject
|
|
276
|
+
// what the generators accept but the drift parser cannot read back.
|
|
277
|
+
if (entry.cssRecipe !== undefined && entry.cssRecipe.trim() === '') {
|
|
278
|
+
throw new Error(
|
|
279
|
+
`Base corpus token at "${entry.path}" has a blank cssRecipe extension. ` +
|
|
280
|
+
'Omit the field to fall back to the typed $value, rather than setting it empty.',
|
|
281
|
+
);
|
|
282
|
+
}
|
|
283
|
+
// Both branches check positively for the prefix the flag requires. Deriving
|
|
284
|
+
// either from the absence of the other admits a third namespace: a
|
|
285
|
+
// `--vendor-foo` token marked public does not start with `--_cinder-`, so a
|
|
286
|
+
// negative public check accepts it and the registry then advertises a name
|
|
287
|
+
// that is not part of the package's `--cinder-` contract at all. The prefix
|
|
288
|
+
// and the flag are one contract, not two, and neither prefix is the
|
|
289
|
+
// complement of the other.
|
|
290
|
+
const requiredPrefix = entry.public ? PUBLIC_TOKEN_PREFIX : PRIVATE_TOKEN_PREFIX;
|
|
291
|
+
if (!entry.cssProperty.startsWith(requiredPrefix)) {
|
|
292
|
+
throw new Error(
|
|
293
|
+
`Base corpus token at "${entry.path}" is marked ` +
|
|
294
|
+
`${entry.public ? 'public' : 'private'} but its cssProperty ` +
|
|
295
|
+
`"${entry.cssProperty}" does not use the ${requiredPrefix} prefix.`,
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
if (!CSS_PROPERTY_PATTERN.test(entry.cssProperty)) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Base corpus token at "${entry.path}" has cssProperty ` +
|
|
301
|
+
`"${entry.cssProperty}", which is outside the kebab-case grammar ` +
|
|
302
|
+
`${String(CSS_PROPERTY_PATTERN)} that the generated documentation is ` +
|
|
303
|
+
`parsed with. Rename the token to lowercase letters, digits, and hyphens.`,
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
const registryEntry: TokenRegistryEntry = {
|
|
308
|
+
path: entry.path,
|
|
309
|
+
cssProperty: entry.cssProperty,
|
|
310
|
+
category: entry.category,
|
|
311
|
+
component: entry.component,
|
|
312
|
+
public: entry.public,
|
|
313
|
+
themeAware: themeAware.has(entry.path),
|
|
314
|
+
deprecated: entry.deprecated ?? false,
|
|
315
|
+
description: entry.description,
|
|
316
|
+
};
|
|
317
|
+
entries.push(registryEntry);
|
|
318
|
+
|
|
319
|
+
pathToCssProperty[entry.path] = entry.cssProperty;
|
|
320
|
+
|
|
321
|
+
// A cssProperty may legitimately be claimed by more than one path only
|
|
322
|
+
// when `$extends` inheritance produces two paths for one identical
|
|
323
|
+
// declaration (see generate.ts's `assertUniqueCssProperties`, which
|
|
324
|
+
// `buildBaseIndex` above already runs before any registry is built from
|
|
325
|
+
// its output -- conflicting, non-identical claims never reach this loop).
|
|
326
|
+
// `cssPropertyToPath` keeps the FIRST path to claim a property
|
|
327
|
+
// (deterministic corpus-traversal order) as the canonical answer, rather
|
|
328
|
+
// than last-write-wins, so the common "one token per property" lookup is
|
|
329
|
+
// stable; `cssPropertyToPaths` records every claimant for a caller that
|
|
330
|
+
// needs the full set.
|
|
331
|
+
if (!(entry.cssProperty in cssPropertyToPath)) {
|
|
332
|
+
cssPropertyToPath[entry.cssProperty] = entry.path;
|
|
333
|
+
}
|
|
334
|
+
(cssPropertyToPaths[entry.cssProperty] ??= []).push(entry.path);
|
|
335
|
+
|
|
336
|
+
// Test for presence, not truthiness. `toEntry` preserves a blank
|
|
337
|
+
// `category`/`component` (the DTCG schema does not validate vendor-extension
|
|
338
|
+
// contents), so a truthiness check would keep the empty string on the entry
|
|
339
|
+
// while omitting the token from the index -- leaving the registry internally
|
|
340
|
+
// inconsistent, with indexed consumers silently missing it. Blank grouping
|
|
341
|
+
// names are rejected outright instead.
|
|
342
|
+
if (entry.category !== undefined) (byCategory[entry.category] ??= []).push(entry.path);
|
|
343
|
+
if (entry.component !== undefined) (byComponent[entry.component] ??= []).push(entry.path);
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return {
|
|
347
|
+
entries,
|
|
348
|
+
pathToCssProperty,
|
|
349
|
+
cssPropertyToPath,
|
|
350
|
+
cssPropertyToPaths,
|
|
351
|
+
byCategory,
|
|
352
|
+
byComponent,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* Serializes a {@link TokenRegistry} to its committed JSON form. Pure
|
|
358
|
+
* string-building, deliberately separate from writing the file to disk (that
|
|
359
|
+
* thin layer lives in `generate-artifacts.ts`, alongside the other
|
|
360
|
+
* `tokens:generate` outputs) so CIN-31's generator, or a test, can call this
|
|
361
|
+
* without touching the filesystem.
|
|
362
|
+
*/
|
|
363
|
+
export function serializeTokenRegistry(registry: TokenRegistry): string {
|
|
364
|
+
return JSON.stringify(registry);
|
|
365
|
+
}
|