@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,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 declare const VERSION = "0.27.1";
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import type { CorpusEntry } from './corpus.ts';
|
|
16
|
+
import type { TokenDocument } from './types.ts';
|
|
17
|
+
/** Public custom property -> CSS value, with keys in code-unit order. */
|
|
18
|
+
export type PropertyMap = Readonly<Record<string, string>>;
|
|
19
|
+
export type ProjectionFailure = {
|
|
20
|
+
path: string;
|
|
21
|
+
reason: string;
|
|
22
|
+
};
|
|
23
|
+
/** Whether a token belongs to the public `--cinder-*` surface. */
|
|
24
|
+
export declare function isPublicEntry(entry: CorpusEntry): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Projects a context to its public property map. Private `--_cinder-*` runtime
|
|
27
|
+
* variables and tokens with no `cssProperty` never appear in the output.
|
|
28
|
+
*/
|
|
29
|
+
export declare function projectProperties(documents: readonly TokenDocument[], index?: Map<string, CorpusEntry>): {
|
|
30
|
+
properties: PropertyMap;
|
|
31
|
+
failures: ProjectionFailure[];
|
|
32
|
+
};
|
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
import { type CorpusEntry } from './corpus.ts';
|
|
25
|
+
import type { ResolverDocument, TokenDocument } from './types.ts';
|
|
26
|
+
export type TokenRegistryEntry = {
|
|
27
|
+
/** Dotted corpus path, e.g. `space.4` or `button.radius.xs`. */
|
|
28
|
+
path: string;
|
|
29
|
+
/** The `--cinder-*` (or `--_cinder-*`) custom property this token emits. */
|
|
30
|
+
cssProperty: string;
|
|
31
|
+
/** The `com.lostgradient.cinder` extension's `category`, when present. */
|
|
32
|
+
category: string | undefined;
|
|
33
|
+
/** The `com.lostgradient.cinder` extension's `component`, when present -- only component-scoped tokens carry one. */
|
|
34
|
+
component: string | undefined;
|
|
35
|
+
/** The `com.lostgradient.cinder` extension's `public` flag. */
|
|
36
|
+
public: boolean;
|
|
37
|
+
/** Whether the `light` or `dark` theme document overrides this token. */
|
|
38
|
+
themeAware: boolean;
|
|
39
|
+
/** The DTCG `$deprecated` field verbatim: `false` when absent, otherwise `true` or the deprecation message string. */
|
|
40
|
+
deprecated: boolean | string;
|
|
41
|
+
/** The token's `$description`, when present. */
|
|
42
|
+
description: string | undefined;
|
|
43
|
+
};
|
|
44
|
+
export type TokenRegistry = {
|
|
45
|
+
/** Every base token, in corpus traversal order. */
|
|
46
|
+
entries: readonly TokenRegistryEntry[];
|
|
47
|
+
/** Token path -> CSS custom property. */
|
|
48
|
+
pathToCssProperty: Readonly<Record<string, string>>;
|
|
49
|
+
/**
|
|
50
|
+
* CSS custom property -> a single CANONICAL token path (deterministic --
|
|
51
|
+
* the first path to claim the property in corpus traversal order, never
|
|
52
|
+
* "whichever happened to be assigned last"). The reverse of
|
|
53
|
+
* {@link TokenRegistry.pathToCssProperty}, but not always its exact
|
|
54
|
+
* inverse: `$extends` inheritance can legitimately produce two token paths
|
|
55
|
+
* for one `cssProperty` (the extending group inherits the member, and its
|
|
56
|
+
* `cssProperty`, verbatim -- `assertUniqueCssProperties` in `generate.ts`
|
|
57
|
+
* permits this specific case because both paths emit an identical
|
|
58
|
+
* declaration). When that happens, this map still returns exactly one
|
|
59
|
+
* path so the common "what token backs this CSS property" lookup stays
|
|
60
|
+
* simple; see {@link TokenRegistry.cssPropertyToPaths} for the full list.
|
|
61
|
+
*/
|
|
62
|
+
cssPropertyToPath: Readonly<Record<string, string>>;
|
|
63
|
+
/**
|
|
64
|
+
* CSS custom property -> every token path that claims it, in corpus
|
|
65
|
+
* traversal order (length 1 in the overwhelming common case; length > 1
|
|
66
|
+
* only for the `$extends`-inherited-verbatim case described above).
|
|
67
|
+
* `cssPropertyToPaths[property][0]` always equals
|
|
68
|
+
* `cssPropertyToPath[property]`.
|
|
69
|
+
*/
|
|
70
|
+
cssPropertyToPaths: Readonly<Record<string, readonly string[]>>;
|
|
71
|
+
/** Category name -> the token paths in that category, in corpus traversal order. */
|
|
72
|
+
byCategory: Readonly<Record<string, readonly string[]>>;
|
|
73
|
+
/** Component name -> the token paths scoped to that component, in corpus traversal order. */
|
|
74
|
+
byComponent: Readonly<Record<string, readonly string[]>>;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The base `sets` document list the resolver orders -- the exact same
|
|
78
|
+
* assembly `buildTokensBaseCss` uses for its own `baseDocuments`, factored
|
|
79
|
+
* out here so a caller that needs a value resolver over the base scope (the
|
|
80
|
+
* docs generator, serializing a token's `:root` value for its "Default"
|
|
81
|
+
* column) builds it from this same list instead of re-deriving it.
|
|
82
|
+
*/
|
|
83
|
+
export declare function buildBaseDocuments(resolver: ResolverDocument, documentsByPath: Map<string, TokenDocument>): TokenDocument[];
|
|
84
|
+
/**
|
|
85
|
+
* The base-token index (every token declared by the `sets` the resolver
|
|
86
|
+
* orders, `$extends` already expanded) -- the exact same construction
|
|
87
|
+
* `buildTokensBaseCss` performs for `baseIndex`, factored out here so the
|
|
88
|
+
* registry and `tokens-base.css` generation can never structurally diverge.
|
|
89
|
+
*
|
|
90
|
+
* Also enforces the same `assertUniqueCssProperties` invariant
|
|
91
|
+
* `buildTokensBaseCss` enforces before it ever emits CSS. This module is a
|
|
92
|
+
* shared entry point -- `generate-artifacts.ts` (the `tokens:generate` CLI,
|
|
93
|
+
* which already runs `buildTokensBaseCss` first) is only one caller; a test,
|
|
94
|
+
* or a future CIN-31/32/34 consumer, can call `buildBaseIndex` directly
|
|
95
|
+
* without going through `tokens:generate` at all, and would otherwise accept
|
|
96
|
+
* a conflicting `cssProperty` mapping that CSS generation would have
|
|
97
|
+
* rejected -- producing an ambiguous `cssPropertyToPath` (see
|
|
98
|
+
* {@link buildTokenRegistryFromIndexes}) on a last-write-wins basis with no
|
|
99
|
+
* error.
|
|
100
|
+
*/
|
|
101
|
+
export declare function buildBaseIndex(resolver: ResolverDocument, documentsByPath: Map<string, TokenDocument>): Map<string, CorpusEntry>;
|
|
102
|
+
/**
|
|
103
|
+
* The set of base-token paths that the `light` OR `dark` theme document
|
|
104
|
+
* overrides -- "theme-aware" per the registry contract. Built the same way
|
|
105
|
+
* `buildTokensBaseCss` builds `lightOverrides`/`darkOverrides` (own theme
|
|
106
|
+
* documents, `$extends` resolved against the theme's full composed scope so
|
|
107
|
+
* a theme override reaching a foundation group via `$extends` still counts),
|
|
108
|
+
* but only the PATHS are needed here, not the override values themselves.
|
|
109
|
+
*/
|
|
110
|
+
export declare function themeAwarePaths(resolver: ResolverDocument, documentsByPath: Map<string, TokenDocument>): Set<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Builds the typed {@link TokenRegistry} from already-collected corpus
|
|
113
|
+
* indexes. Kept pure and synchronous (no file I/O) so CIN-31's generator, and
|
|
114
|
+
* any test, can construct fixtures directly rather than loading the real
|
|
115
|
+
* corpus from disk. {@link buildTokenRegistry} is the disk-reading wrapper.
|
|
116
|
+
*/
|
|
117
|
+
export declare function buildTokenRegistryFromIndexes(baseIndex: ReadonlyMap<string, CorpusEntry>, themeAware: ReadonlySet<string>): TokenRegistry;
|
|
118
|
+
/**
|
|
119
|
+
* Serializes a {@link TokenRegistry} to its committed JSON form. Pure
|
|
120
|
+
* string-building, deliberately separate from writing the file to disk (that
|
|
121
|
+
* thin layer lives in `generate-artifacts.ts`, alongside the other
|
|
122
|
+
* `tokens:generate` outputs) so CIN-31's generator, or a test, can call this
|
|
123
|
+
* without touching the filesystem.
|
|
124
|
+
*/
|
|
125
|
+
export declare function serializeTokenRegistry(registry: TokenRegistry): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ExtensionOrigins } from './resolve-shared.ts';
|
|
2
|
+
import type { TokenGroup } from './types.ts';
|
|
3
|
+
export declare function inheritMissingGroupMembers(target: TokenGroup, source: TokenGroup, extensionOrigins?: ExtensionOrigins): void;
|
|
4
|
+
/**
|
|
5
|
+
* The `$deprecated` a group at `groupPath` carries EFFECTIVELY, once ordinary
|
|
6
|
+
* (non-`$extends`) ancestor nesting is taken into account -- the nearest of
|
|
7
|
+
* the group itself, its parent, its grandparent, and so on that declares
|
|
8
|
+
* `$deprecated` directly. `groups` is keyed by the RAW merged tree
|
|
9
|
+
* (`collectGroups`, run before any `$extends` expansion), so this reads each
|
|
10
|
+
* candidate's own declared value only; it does not itself resolve a further
|
|
11
|
+
* `$extends` chain on an ancestor (a deeper edge case -- an ancestor that is
|
|
12
|
+
* itself only deprecated via its OWN `$extends` -- outside what this helper
|
|
13
|
+
* addresses).
|
|
14
|
+
*
|
|
15
|
+
* `resolveExtends` needs this rather than a plain `extended.$deprecated`
|
|
16
|
+
* property read: `generate.ts`'s `collectEntries` propagates `$deprecated`
|
|
17
|
+
* down through ordinary group nesting at CSS/registry generation time, well
|
|
18
|
+
* after `$extends` has already run here, so a group that inherits
|
|
19
|
+
* `$deprecated` only from an ANCESTOR (never declaring it directly itself)
|
|
20
|
+
* still reads `undefined` at this point unless this helper walks up for it.
|
|
21
|
+
* Without it, `derived: { $extends: '{outer.base}' }` under a deprecated
|
|
22
|
+
* `outer` (with `outer.base` itself never declaring `$deprecated`) copied no
|
|
23
|
+
* deprecation onto `derived` at all, even though every token under
|
|
24
|
+
* `outer.base` is itself effectively deprecated by the time generation walks
|
|
25
|
+
* it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function effectiveGroupDeprecated(groupPath: string, groups: Map<string, TokenGroup>): TokenGroup['$deprecated'];
|
|
28
|
+
export declare function effectiveGroupType(groupPath: string, groups: Map<string, TokenGroup>): TokenGroup['$type'];
|
|
29
|
+
export declare function groupMetadataBase(group: TokenGroup, groupPath: string, groups: Map<string, TokenGroup>): TokenGroup;
|
|
30
|
+
export declare function resolveExtends(groupPath: string, groups: Map<string, TokenGroup>, visiting: Set<string>, complete: Set<string>, lookupGroups?: Map<string, TokenGroup>, extensionOrigins?: ExtensionOrigins): TokenGroup;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type RawRefs, type ResolvedTokens } from './resolve-shared.ts';
|
|
2
|
+
import type { DesignToken, TokenGroup } from './types.ts';
|
|
3
|
+
export declare function resolveReference(reference: string, tokens: ResolvedTokens, rawRefs: RawRefs, rootTokenPaths: Set<string>, resolving: Set<string>, groups: Map<string, TokenGroup>, completed: Set<string>): unknown;
|
|
4
|
+
export declare function resolveValue(value: unknown, tokens: ResolvedTokens, rawRefs: RawRefs, rootTokenPaths: Set<string>, resolving: Set<string>, groups: Map<string, TokenGroup>, completed: Set<string>): unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a `$ref` token -- a whole-token DTCG 2025.10 alias, distinct from
|
|
7
|
+
* a `{a.b.c}`/`#/a/b/c` reference embedded IN a `$value`. Reuses
|
|
8
|
+
* `resolveReference` (the same machinery an ordinary alias `$value` goes
|
|
9
|
+
* through) rather than a separate path walk, so chained aliases and
|
|
10
|
+
* property-level pointers (`#/base/$value/blur`) work identically for both
|
|
11
|
+
* forms, and so `resolving` cycle detection is shared: a `$ref` chain that
|
|
12
|
+
* loops back on itself trips the same "circular token alias" guard
|
|
13
|
+
* `resolveToken` already applies before this runs.
|
|
14
|
+
*
|
|
15
|
+
* `$type` precedence for a `$ref` token: its own declared `$type` (validated
|
|
16
|
+
* only for known-type membership in `validate.ts`, never required) wins;
|
|
17
|
+
* failing that, the type already inherited from its enclosing group -- set
|
|
18
|
+
* by `withResolvedType` before `resolveToken` is ever called -- wins;
|
|
19
|
+
* failing THAT, the whole-token alias target's resolved `$type` is copied in
|
|
20
|
+
* here. A property-level `$ref` has no whole-token target to borrow a type
|
|
21
|
+
* from, so `$type` is left however it was (possibly still undefined), and
|
|
22
|
+
* `validateResolvedToken` is what reports a genuinely untyped resolved
|
|
23
|
+
* token, the same way it already does for an untyped ordinary token.
|
|
24
|
+
*
|
|
25
|
+
* The `$ref` key is deleted once resolved: a fully resolved `DesignToken` is
|
|
26
|
+
* expected to carry `$value` alone (mirroring the `$value`/`$ref` mutual
|
|
27
|
+
* exclusivity `validate.ts` enforces on the raw document), and downstream
|
|
28
|
+
* consumers of `resolveDocuments`'s output should never have to check for a
|
|
29
|
+
* leftover alias pointer next to the value it named.
|
|
30
|
+
*/
|
|
31
|
+
/**
|
|
32
|
+
* The `tokens` index key a whole-token reference ultimately names, for type
|
|
33
|
+
* inference below -- distinct from `tokenPathFromReference`'s plain dotted
|
|
34
|
+
* join, which treats trailing `$value`/`$root` segments as ordinary path
|
|
35
|
+
* levels. A group's root token is indexed under the GROUP's own path
|
|
36
|
+
* (`collectTokens` sets it at `prefix`, not `prefix.$root`), so
|
|
37
|
+
* `#/group/$root` and `#/$root` need their `$root` segment stripped before
|
|
38
|
+
* the `tokens.get` lookup, or it misses -- the same redirect
|
|
39
|
+
* `resolveReference`'s loop applies to `targetsRootToken` above, factored out
|
|
40
|
+
* here since type inference needs only the final indexed path, not a
|
|
41
|
+
* resolved value. A trailing `$value` segment (`#/base/$value`,
|
|
42
|
+
* `#/group/$root/$value`, `#/$root/$value`) names the token's WHOLE value,
|
|
43
|
+
* not a nested property, and must be stripped FIRST -- otherwise
|
|
44
|
+
* `#/group/$root/$value` dot-joins to `group.$root.$value`, which ends in
|
|
45
|
+
* neither `$root` nor a bare `$root`, and the redirect below never fires.
|
|
46
|
+
*/
|
|
47
|
+
export declare function refTargetIndexPath(reference: string): string;
|
|
48
|
+
export declare function resolveRefToken(path: string, token: DesignToken, tokens: ResolvedTokens, rawRefs: RawRefs, rootTokenPaths: Set<string>, resolving: Set<string>, groups: Map<string, TokenGroup>, completed: Set<string>): void;
|
|
49
|
+
export declare function resolveToken(path: string, tokens: ResolvedTokens, rawRefs: RawRefs, rootTokenPaths: Set<string>, resolving: Set<string>, groups: Map<string, TokenGroup>, completed: Set<string>): DesignToken;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { DesignToken, TokenGroup } from './types.ts';
|
|
2
|
+
export type JsonObject = Record<string, unknown>;
|
|
3
|
+
export type ResolvedTokens = Map<string, DesignToken>;
|
|
4
|
+
export type ExtensionOrigin = {
|
|
5
|
+
source: string;
|
|
6
|
+
path: string;
|
|
7
|
+
};
|
|
8
|
+
export type ExtensionOrigins = WeakMap<object, ExtensionOrigin>;
|
|
9
|
+
/**
|
|
10
|
+
* Every token's ORIGINAL `$ref` string, captured once in `buildTokenIndex`
|
|
11
|
+
* before any resolution runs. `resolveRefToken` deletes `$ref` from a
|
|
12
|
+
* token's live entry in `ResolvedTokens` once resolved (so a resolved token
|
|
13
|
+
* never carries a leftover alias pointer) -- a pointer that targets another
|
|
14
|
+
* alias token's OWN `$ref` property (`#/alias/$ref`) would otherwise always
|
|
15
|
+
* find it already gone, regardless of processing order, since
|
|
16
|
+
* `resolveDocuments`'s top-level loop may resolve `alias` before anything
|
|
17
|
+
* ever asks to read its `$ref`. This snapshot is immune to that mutation.
|
|
18
|
+
*/
|
|
19
|
+
export type RawRefs = Map<string, string>;
|
|
20
|
+
export declare function isObject(value: unknown): value is JsonObject;
|
|
21
|
+
export declare function isToken(value: unknown): value is DesignToken;
|
|
22
|
+
export declare function isTokenGroup(value: unknown): value is TokenGroup;
|
|
23
|
+
export declare function clone<T>(value: T, extensionOrigins?: ExtensionOrigins): T;
|
|
24
|
+
export declare function copyExtensionOrigins(value: unknown, copy: unknown, origins: ExtensionOrigins): void;
|
|
25
|
+
export declare function normalizeObjectPrototypes(value: unknown): void;
|
|
26
|
+
export declare function withResolvedType(token: DesignToken, inheritedType?: DesignToken['$type']): DesignToken;
|
|
27
|
+
export declare function issue(path: string, reason: string): never;
|
|
28
|
+
export declare function tokenPathFromReference(reference: string): string;
|
|
29
|
+
export declare function pointerSegments(reference: string): string[];
|
|
30
|
+
export declare function getByPath(value: unknown, segments: string[]): unknown;
|
|
31
|
+
export declare function collectGroups(group: TokenGroup, prefix: string, groups: Map<string, TokenGroup>): void;
|
|
32
|
+
export declare function collectExtensionOrigins(group: TokenGroup, prefix: string, source: string | undefined, origins: ExtensionOrigins): void;
|
|
33
|
+
export declare function extensionIssue(groupPath: string, reason: string, group: TokenGroup, extensionOrigins?: ExtensionOrigins): never;
|
|
34
|
+
export declare function collectTokens(group: TokenGroup, prefix: string, tokens: ResolvedTokens, rootTokenPaths: Set<string>, inheritedType?: DesignToken['$type']): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type ExtensionOrigins } from './resolve-shared.ts';
|
|
2
|
+
import type { DesignToken, TokenDocument } from './types.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Merges documents and applies `$extends` group inheritance (missing members copied in,
|
|
5
|
+
* `$type` propagated) across the merged tree, WITHOUT resolving any alias reference --
|
|
6
|
+
* factored out of `buildTokenIndex` so a caller that must keep raw, unresolved `$value`s (a
|
|
7
|
+
* `{a.b.c}` string means "emit `var(--other-property)`", not "inline a literal") can still get
|
|
8
|
+
* `$extends` applied before walking the tree, the same way `resolveDocuments` and
|
|
9
|
+
* `createValueResolver` do.
|
|
10
|
+
*
|
|
11
|
+
* `lookupDocuments` (defaults to `documents` itself) is where `$extends` TARGETS are looked up --
|
|
12
|
+
* distinct from `documents`, which is both what gets merged/mutated and what gets returned. A
|
|
13
|
+
* caller that must return only ITS OWN documents' tree (an override context, whose returned shape
|
|
14
|
+
* determines which tokens that context is considered to "define") but whose `$extends` may
|
|
15
|
+
* reference a group that lives only in a broader document set (e.g. a foundation group the
|
|
16
|
+
* override document never itself contains) passes that broader set as `lookupDocuments`. Own
|
|
17
|
+
* groups are collected AFTER (and so take precedence over) the lookup groups, so `resolveExtends`
|
|
18
|
+
* still mutates and returns the caller's own tree -- a target found only in `lookupDocuments`
|
|
19
|
+
* contributes members by being copied in, never by becoming part of the returned tree itself.
|
|
20
|
+
*/
|
|
21
|
+
export declare function mergeAndExpandExtends(documents: TokenDocument[], lookupDocuments?: TokenDocument[], sourceByDocument?: ReadonlyMap<object, string>): TokenDocument;
|
|
22
|
+
/** Resolves group inheritance, whole-token aliases, and property-level aliases. */
|
|
23
|
+
export declare function resolveDocuments(documents: TokenDocument[]): Record<string, DesignToken>;
|
|
24
|
+
export type ValueResolver = (value: unknown) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Builds a resolver, against the given documents, for arbitrary raw value trees -- not just
|
|
27
|
+
* whole tokens. `resolveDocuments` only exposes references already resolved at the top level of
|
|
28
|
+
* each token's `$value`; a reference nested inside a composite member (a shadow layer's
|
|
29
|
+
* `inset`, one component of a color, ...) needs the same reference machinery applied to an
|
|
30
|
+
* arbitrary sub-value, including property-path splitting (`{a.b.c}` / `#/a/b/c` may name a
|
|
31
|
+
* whole token OR a property within one) and cycle detection. Reuses `resolveValue` --
|
|
32
|
+
* `resolveDocuments` calls the exact same function on each token's `$value` -- rather than a
|
|
33
|
+
* second resolver.
|
|
34
|
+
*/
|
|
35
|
+
export declare function createValueResolver(documents: TokenDocument[]): ValueResolver;
|
|
36
|
+
/**
|
|
37
|
+
* Merges ordered documents. A later document's token wins on VALUE and on
|
|
38
|
+
* generation metadata, but no longer replaces the earlier token wholesale:
|
|
39
|
+
* `mergeToken` keeps identity and documentation from the token being overridden
|
|
40
|
+
* when the override does not restate them. "Last occurrence wins" therefore
|
|
41
|
+
* still describes `$value`, and no longer describes the whole token.
|
|
42
|
+
*/
|
|
43
|
+
export declare function mergeDocuments(documents: TokenDocument[], extensionOrigins?: ExtensionOrigins): TokenDocument;
|
|
44
|
+
export declare function resolveDocument(document: TokenDocument): Record<string, DesignToken>;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { type ResolverDocument, type ResolverReference } from './types.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Normalizes a source `$ref` into the repository-relative form `loadTokenDocuments`
|
|
4
|
+
* reports. The resolver schema types these as URI references, so `./sets/x.tokens.json`
|
|
5
|
+
* and `sets/x.tokens.json` name the same file; comparing the raw strings against
|
|
6
|
+
* globbed paths would report a file that exists as missing. Percent-escapes are
|
|
7
|
+
* decoded for the same reason, and a malformed escape is left as-is so the failure
|
|
8
|
+
* surfaces as a clear "source does not exist" rather than a decoding crash --
|
|
9
|
+
* ajv's `uri-reference` format catches genuinely malformed references upstream.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizeSourcePath(reference: string): string;
|
|
12
|
+
export declare function normalizedDocumentsByPath<T>(documentsByPath: Map<string, T>): Map<string, T>;
|
|
13
|
+
/**
|
|
14
|
+
* Whether a source `$ref` names a resolver-internal pointer (`#/sets/<name>`)
|
|
15
|
+
* rather than an on-disk document, decoding percent-escapes FIRST -- the same
|
|
16
|
+
* order `resolutionOrderTarget` in `validate.ts` already applies (RFC 6901 §6:
|
|
17
|
+
* percent-decode the whole fragment before structural parsing). A raw,
|
|
18
|
+
* undecoded `startsWith('#/')` check disagrees with that: a valid
|
|
19
|
+
* percent-encoded pointer such as `#%2Fsets%2Fbase` decodes to `#/sets/base`
|
|
20
|
+
* and is correctly recognized as internal by `resolutionOrderTarget`, but the
|
|
21
|
+
* SAME string does not literally start with `#/`, so an undecoded check here
|
|
22
|
+
* misclassified it as a filesystem reference and reported a nonexistent file
|
|
23
|
+
* named `#%2Fsets%2Fbase` instead of expanding the set.
|
|
24
|
+
*/
|
|
25
|
+
export declare function isInternalReference(reference: string): boolean;
|
|
26
|
+
export declare function internalSetNames(sources: ResolverReference[]): string[];
|
|
27
|
+
export declare function reachableSetNames(resolver: ResolverDocument, rootName: string): Set<string>;
|
|
28
|
+
/** Rejects a later modifier re-expanding a base set after another modifier already overrode it. */
|
|
29
|
+
export declare function expandSetSources(resolver: ResolverDocument, setName: string, visiting?: Set<string>, referencePath?: string): ResolverReference[];
|
|
30
|
+
/**
|
|
31
|
+
* Expands one modifier context's `sources` the same way {@link expandSetSources}
|
|
32
|
+
* expands a set's -- a context entry may reference a set (`#/sets/<name>`),
|
|
33
|
+
* expanded recursively via `expandSetSources`, but per the resolver schema's
|
|
34
|
+
* `referenceObjectForModifiers` prohibition, a modifier context may not
|
|
35
|
+
* reference another modifier.
|
|
36
|
+
*/
|
|
37
|
+
export declare function expandContextSources(resolver: ResolverDocument, modifierName: string, contextName: string): ResolverReference[];
|
|
38
|
+
/**
|
|
39
|
+
* Indexes expanded context sources by modifier name, then context name.
|
|
40
|
+
*
|
|
41
|
+
* Nesting two maps -- rather than concatenating both names into one string
|
|
42
|
+
* key -- keeps this collision-free: resolver modifier and context names are
|
|
43
|
+
* otherwise unrestricted, so e.g. modifier "a" context "b:c" and modifier
|
|
44
|
+
* "a:b" context "c" could concatenate to the same key under ANY fixed
|
|
45
|
+
* delimiter and silently overwrite each other, resolving the wrong document
|
|
46
|
+
* list for one of them. Two-level indexing has no such joint-key space to
|
|
47
|
+
* collide in.
|
|
48
|
+
*/
|
|
49
|
+
export declare function buildContextSourcesIndex(expandedContexts: ReadonlyArray<{
|
|
50
|
+
modifierName: string;
|
|
51
|
+
contextName: string;
|
|
52
|
+
sources: ResolverReference[];
|
|
53
|
+
}>): Map<string, Map<string, ResolverReference[]>>;
|
|
54
|
+
export declare function validateExpandedSources(expandedSets: ReadonlyArray<{
|
|
55
|
+
setName: string;
|
|
56
|
+
sources: ResolverReference[];
|
|
57
|
+
}>, expandedContexts: ReadonlyArray<{
|
|
58
|
+
modifierName: string;
|
|
59
|
+
contextName: string;
|
|
60
|
+
sources: ResolverReference[];
|
|
61
|
+
}>, documentsByPath: Map<string, unknown>): void;
|
|
62
|
+
/**
|
|
63
|
+
* Returns the concrete ordered document scopes in which each source participates.
|
|
64
|
+
* `$extends` targets are resolved against these scopes only; unrelated sets and
|
|
65
|
+
* modifier contexts must not contribute projection metadata to one another.
|
|
66
|
+
*/
|
|
67
|
+
export type ResolutionOrderEntry = {
|
|
68
|
+
kind: 'sets' | 'modifiers';
|
|
69
|
+
name: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Parses every resolutionOrder `$ref` into its target kind and name, reusing
|
|
73
|
+
* validation's own parser so the two paths cannot drift. That matters for
|
|
74
|
+
* RFC 6901 tilde-escapes: a set named `a/b` is referenced as `#/sets/a~1b`,
|
|
75
|
+
* and decoding it here is what keeps the later `resolver.sets[name]` lookup
|
|
76
|
+
* in `sourcesForEntry` finding the entry that validation already accepted.
|
|
77
|
+
*/
|
|
78
|
+
export declare function parseResolutionOrder(resolver: ResolverDocument): ResolutionOrderEntry[];
|
|
79
|
+
/**
|
|
80
|
+
* The token sources a resolutionOrder entry contributes for one
|
|
81
|
+
* modifier-value combination, with any resolver-internal `#/sets/<name>`
|
|
82
|
+
* reference already expanded to the plain document `$ref`s it stands for --
|
|
83
|
+
* every caller (this validator, `generate.ts`, `registry.ts`) resolves the
|
|
84
|
+
* result straight into `documentsByPath` lookups with no expansion of its
|
|
85
|
+
* own.
|
|
86
|
+
*/
|
|
87
|
+
export declare function sourcesForEntry(resolver: ResolverDocument, entry: ResolutionOrderEntry, modifierValues: Record<string, string>): ResolverReference[];
|
|
88
|
+
/** Every combination of one context value per modifier, cartesian product across all modifiers. */
|
|
89
|
+
export declare function combinations(resolver: ResolverDocument): Array<Record<string, string>>;
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
/** `JSON.stringify` with object keys sorted, so equal values serialize identically. */
|
|
11
|
+
export declare function canonicalJson(value: unknown): string;
|
|
12
|
+
/** The lowercase hexadecimal SHA-256 of a string's UTF-8 bytes. */
|
|
13
|
+
export declare function sha256Hex(text: string): Promise<string>;
|
|
14
|
+
/** What identifies a token source: its resolver and its documents keyed by relative path. */
|
|
15
|
+
export type DigestableSource = {
|
|
16
|
+
resolver: unknown;
|
|
17
|
+
documents: Readonly<Record<string, unknown>>;
|
|
18
|
+
};
|
|
19
|
+
/** `sha256:<hex>` over the canonical form of `{ resolver, documents }`. */
|
|
20
|
+
export declare function computeSourceDigest(source: DigestableSource): Promise<string>;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
export type StylesheetDeclarations = {
|
|
11
|
+
/** The `:root` declarations every context starts from. */
|
|
12
|
+
root: string;
|
|
13
|
+
/** Declarations for `[data-theme='dark']` / `[data-theme='light']`, root or descendant. */
|
|
14
|
+
dark: string;
|
|
15
|
+
light: string;
|
|
16
|
+
/** `prefers-reduced-motion: reduce`, with no theme named. */
|
|
17
|
+
reducedMotion: string;
|
|
18
|
+
darkReducedMotion: string;
|
|
19
|
+
lightReducedMotion: string;
|
|
20
|
+
/** `[data-reduced-motion='on']`, with no theme named. */
|
|
21
|
+
forcedReducedMotion: string;
|
|
22
|
+
darkForcedReducedMotion: string;
|
|
23
|
+
lightForcedReducedMotion: string;
|
|
24
|
+
/**
|
|
25
|
+
* Declarations for a root with no `data-theme` under `prefers-color-scheme: dark`. The
|
|
26
|
+
* generator leaves this empty (its `:root` uses `light-dark()`); a complete theme needs it.
|
|
27
|
+
*/
|
|
28
|
+
systemDark?: string;
|
|
29
|
+
};
|
|
30
|
+
/** Everything after the file header: `:root` through the forced-motion blocks. */
|
|
31
|
+
export declare function renderStylesheetSkeleton(d: StylesheetDeclarations): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test support for the runtime parity suite: evaluates what a generated
|
|
3
|
+
* stylesheet declares for one context, so runtime property maps can be compared
|
|
4
|
+
* with the CLI's CSS output.
|
|
5
|
+
*
|
|
6
|
+
* It models the document the stylesheet targets: `<html>` carrying
|
|
7
|
+
* `data-theme`, and `data-reduced-motion="on"` for the forced context. The
|
|
8
|
+
* `reduced` context is the operating-system preference, so
|
|
9
|
+
* `@media (prefers-reduced-motion: reduce)` applies and the attribute is absent.
|
|
10
|
+
* `prefers-color-scheme` blocks guard on `:not([data-theme])`, so they never
|
|
11
|
+
* apply to an explicit theme. Only the selector forms the generator emits are
|
|
12
|
+
* understood; any other selector fails the test rather than being guessed at.
|
|
13
|
+
*/
|
|
14
|
+
export type CascadeContext = {
|
|
15
|
+
theme: string;
|
|
16
|
+
motion: string;
|
|
17
|
+
};
|
|
18
|
+
/** Each custom property's winning declaration for `<html>` in `context`. */
|
|
19
|
+
export declare function cascadeCustomProperties(css: string, context: CascadeContext): Map<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Normalizes values the way the generator's formatter does, so an unformatted
|
|
22
|
+
* runtime value compares equal to its committed, Prettier-formatted counterpart.
|
|
23
|
+
*/
|
|
24
|
+
export declare function normalizeCssValues(properties: ReadonlyMap<string, string>): Promise<Map<string, string>>;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
import type { ThemeSources } from './evaluate.ts';
|
|
12
|
+
import type { TokenDocument } from './types.ts';
|
|
13
|
+
/** Where each override scope's document lives in the resolver. */
|
|
14
|
+
export declare const OVERRIDE_DOCUMENTS: {
|
|
15
|
+
readonly shared: "overrides/shared.tokens.json";
|
|
16
|
+
readonly light: "overrides/light.tokens.json";
|
|
17
|
+
readonly dark: "overrides/dark.tokens.json";
|
|
18
|
+
readonly reduced: "overrides/reduced.tokens.json";
|
|
19
|
+
readonly forcedReduced: "overrides/forced-reduced-motion.tokens.json";
|
|
20
|
+
};
|
|
21
|
+
export type OverrideScopeName = keyof typeof OVERRIDE_DOCUMENTS;
|
|
22
|
+
/** The part of an envelope the runtime needs; the playground's envelope type satisfies it. */
|
|
23
|
+
export type ThemeSourceEnvelope = {
|
|
24
|
+
base: {
|
|
25
|
+
resolver: unknown;
|
|
26
|
+
documents: Readonly<Record<string, unknown>>;
|
|
27
|
+
};
|
|
28
|
+
overrides: Readonly<Record<OverrideScopeName, unknown>>;
|
|
29
|
+
};
|
|
30
|
+
/** The envelope as runtime sources: the embedded base with the override documents inserted. */
|
|
31
|
+
export declare function buildThemeSources(envelope: ThemeSourceEnvelope, revision: number): ThemeSources;
|
|
32
|
+
/**
|
|
33
|
+
* Lay CSS-only edits (public token path, then concrete context, then value) over a projected
|
|
34
|
+
* context. They win over everything. A path outside the public registry is ignored, and
|
|
35
|
+
* `accept` lets the caller apply a stricter value check than the stylesheet's own.
|
|
36
|
+
*/
|
|
37
|
+
export declare function applyCssOnlyOverrides(properties: Readonly<Record<string, string>>, cssOverrides: Readonly<Record<string, Readonly<Record<string, string | undefined>>>>, context: string, accept?: (value: string) => boolean): Record<string, string>;
|
|
38
|
+
/**
|
|
39
|
+
* The token document one concrete context resolves to: its ordered documents merged the way
|
|
40
|
+
* evaluation merges them, with aliases, `$extends`, descriptions and extensions still in
|
|
41
|
+
* place. Nothing is flattened or evaluated. The sources must already have passed validation.
|
|
42
|
+
*/
|
|
43
|
+
export declare function mergedContextDocument(sources: ThemeSources, context: {
|
|
44
|
+
theme: string;
|
|
45
|
+
motion: string;
|
|
46
|
+
}): TokenDocument;
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
export type StylesheetContext = 'light/default' | 'light/reduced' | 'light/forced-reduced-motion' | 'dark/default' | 'dark/reduced' | 'dark/forced-reduced-motion';
|
|
17
|
+
export type ContextProperties = Readonly<Record<StylesheetContext, Readonly<Record<string, string>>>>;
|
|
18
|
+
export declare const THEME_LAYER = "cinder-theme";
|
|
19
|
+
export declare class StylesheetError extends Error {
|
|
20
|
+
constructor(message: string);
|
|
21
|
+
}
|
|
22
|
+
export type ThemeStylesheetOptions = {
|
|
23
|
+
/** One line naming the theme and the exact Cinder base it was checked against. */
|
|
24
|
+
identity?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The stylesheet for six evaluated contexts. Every public property of `light/default` is
|
|
28
|
+
* declared on `:root`; the dark theme block, the system-dark root and each motion block
|
|
29
|
+
* restate only what differs, with the generator's precedence.
|
|
30
|
+
*/
|
|
31
|
+
export declare function renderThemeStylesheet(maps: ContextProperties, options?: ThemeStylesheetOptions): string;
|