@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,182 @@
|
|
|
1
|
+
import { collectEntries, type CorpusEntry } from './corpus.ts';
|
|
2
|
+
import { mergeAndExpandExtends } from './resolve.ts';
|
|
3
|
+
import { normalizeSourcePath, parseResolutionOrder, sourcesForEntry } from './resolver-order.ts';
|
|
4
|
+
import type { ResolverDocument, ResolverReference, TokenDocument } from './types.ts';
|
|
5
|
+
|
|
6
|
+
export type ResolvedContextCombo = {
|
|
7
|
+
name: string;
|
|
8
|
+
theme: string;
|
|
9
|
+
motion: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const RESOLVED_CONTEXT_COMBOS: readonly ResolvedContextCombo[] = [
|
|
13
|
+
{ name: 'light', theme: 'light', motion: 'default' },
|
|
14
|
+
{ name: 'dark', theme: 'dark', motion: 'default' },
|
|
15
|
+
{ name: 'light-reduced-motion', theme: 'light', motion: 'reduced' },
|
|
16
|
+
{ name: 'dark-reduced-motion', theme: 'dark', motion: 'reduced' },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The token documents one modifier-value combination contributes, in
|
|
21
|
+
* `resolver.resolutionOrder` order rather than a hardcoded [sets, theme,
|
|
22
|
+
* motion] order. Mirrors `validate-corpus.ts`'s own per-combination assembly
|
|
23
|
+
* (`parseResolutionOrder` / `sourcesForEntry`) so the resolved snapshots and
|
|
24
|
+
* the validator agree on ordering even if the resolver ever reorders or adds
|
|
25
|
+
* a set/modifier -- `mergeDocuments` keeps only the LAST occurrence of a
|
|
26
|
+
* colliding token path, so document order determines the resolved value.
|
|
27
|
+
*/
|
|
28
|
+
export function documentsForResolutionOrder(
|
|
29
|
+
resolver: ResolverDocument,
|
|
30
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
31
|
+
modifierValues: Record<string, string>,
|
|
32
|
+
): TokenDocument[] {
|
|
33
|
+
return parseResolutionOrder(resolver).flatMap((entry) =>
|
|
34
|
+
refsFor(documentsByPath, sourcesForEntry(resolver, entry, modifierValues)),
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The full modifier-value map when only SOME modifiers are named explicitly: every OTHER
|
|
40
|
+
* modifier the resolver declares is filled from its own declared `default` context. Shared by
|
|
41
|
+
* `modifierValuesForCombo` (a resolved-context snapshot, which names `theme` and `motion`
|
|
42
|
+
* together) and `modifierValuesForContext` (a single override block, which names only the one
|
|
43
|
+
* modifier it varies) so both describe "the rest of the corpus" identically. A modifier with no
|
|
44
|
+
* declared default AND not named by the caller is a genuine authoring gap -- the caller can't say
|
|
45
|
+
* what to resolve -- so this fails with a clear, named error rather than letting `sourcesForEntry`
|
|
46
|
+
* look up `contexts[undefined]` and throw an unhelpful one.
|
|
47
|
+
*/
|
|
48
|
+
function modifierValuesWithDefaults(
|
|
49
|
+
resolver: ResolverDocument,
|
|
50
|
+
named: Record<string, string>,
|
|
51
|
+
describeCaller: string,
|
|
52
|
+
): Record<string, string> {
|
|
53
|
+
const modifierValues: Record<string, string> = {};
|
|
54
|
+
for (const modifierName of Object.keys(resolver.modifiers)) {
|
|
55
|
+
const value = named[modifierName] ?? resolver.modifiers[modifierName]!.default;
|
|
56
|
+
if (value === undefined) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
`${describeCaller} does not name a value for modifier "${modifierName}", and modifier ` +
|
|
59
|
+
`"${modifierName}" has no declared default context.`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
modifierValues[modifierName] = value;
|
|
63
|
+
}
|
|
64
|
+
return modifierValues;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The full modifier-value map for one `RESOLVED_CONTEXT_COMBO`: the combo's own named
|
|
69
|
+
* modifiers (`theme`/`motion`), plus a value for every OTHER modifier the resolver declares.
|
|
70
|
+
* `RESOLVED_CONTEXT_COMBOS` is deliberately not generalized to every modifier combination --
|
|
71
|
+
* the set of published resolved contexts is a packaging decision (CIN-31), and the four named
|
|
72
|
+
* snapshots stay an explicit list.
|
|
73
|
+
*/
|
|
74
|
+
export function modifierValuesForCombo(
|
|
75
|
+
resolver: ResolverDocument,
|
|
76
|
+
combo: ResolvedContextCombo,
|
|
77
|
+
): Record<string, string> {
|
|
78
|
+
return modifierValuesWithDefaults(
|
|
79
|
+
resolver,
|
|
80
|
+
{ theme: combo.theme, motion: combo.motion },
|
|
81
|
+
`Resolved-context combo "${combo.name}"`,
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The full modifier-value map for building ONE override context in isolation -- e.g. the "dark"
|
|
87
|
+
* theme block or the "reduced" motion block in `tokens-base.css`, each of which varies a single
|
|
88
|
+
* modifier while every other modifier stays at its own declared default. This is the same
|
|
89
|
+
* default-fill `modifierValuesForCombo` applies for the resolved-context snapshots, so an
|
|
90
|
+
* override block's composed document scope and a snapshot's agree on what "the rest of the
|
|
91
|
+
* corpus" means whenever a block only varies one axis.
|
|
92
|
+
*/
|
|
93
|
+
export function modifierValuesForContext(
|
|
94
|
+
resolver: ResolverDocument,
|
|
95
|
+
modifierName: string,
|
|
96
|
+
contextName: string,
|
|
97
|
+
): Record<string, string> {
|
|
98
|
+
return modifierValuesWithDefaults(
|
|
99
|
+
resolver,
|
|
100
|
+
{ [modifierName]: contextName },
|
|
101
|
+
`Override context "${modifierName}.${contextName}"`,
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export function scopeIndexFromDocuments(
|
|
106
|
+
documents: readonly TokenDocument[],
|
|
107
|
+
): Map<string, CorpusEntry> {
|
|
108
|
+
const index = new Map<string, CorpusEntry>();
|
|
109
|
+
collectEntries(mergeAndExpandExtends([...documents]), '', undefined, index);
|
|
110
|
+
return index;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The tokens an override context (a theme or motion modifier) defines, each as
|
|
115
|
+
* that context evaluates it.
|
|
116
|
+
*
|
|
117
|
+
* Membership -- which tokens the context overrides, and in what order -- comes
|
|
118
|
+
* from the context's own documents. Each token's content comes from the same
|
|
119
|
+
* evaluation the runtime projects (`scopeIndexFromDocuments` over the whole
|
|
120
|
+
* ordered scope), so a type, `$extends` member, or other metadata the override
|
|
121
|
+
* document inherits from an earlier layer is resolved once, here, and the
|
|
122
|
+
* stylesheet generator and the browser cannot disagree about it. An override
|
|
123
|
+
* document therefore need not restate a group `$type` its base already declares.
|
|
124
|
+
*/
|
|
125
|
+
export function overrideEntries(
|
|
126
|
+
ownDocuments: readonly TokenDocument[],
|
|
127
|
+
scopeDocuments: readonly TokenDocument[],
|
|
128
|
+
): Map<string, CorpusEntry> {
|
|
129
|
+
const entries = new Map<string, CorpusEntry>();
|
|
130
|
+
collectEntries(
|
|
131
|
+
mergeAndExpandExtends([...ownDocuments], [...scopeDocuments]),
|
|
132
|
+
'',
|
|
133
|
+
undefined,
|
|
134
|
+
entries,
|
|
135
|
+
);
|
|
136
|
+
const evaluated = scopeIndexFromDocuments(scopeDocuments);
|
|
137
|
+
for (const path of entries.keys()) {
|
|
138
|
+
const entry = evaluated.get(path);
|
|
139
|
+
if (entry) entries.set(path, entry);
|
|
140
|
+
}
|
|
141
|
+
return entries;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export function documentsForSystemMotionScope(
|
|
145
|
+
resolver: ResolverDocument,
|
|
146
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
147
|
+
motion: string,
|
|
148
|
+
): TokenDocument[] {
|
|
149
|
+
const modifierValues = { motion };
|
|
150
|
+
return parseResolutionOrder(resolver)
|
|
151
|
+
.filter(
|
|
152
|
+
(entry) => entry.kind === 'sets' || (entry.kind === 'modifiers' && entry.name === 'motion'),
|
|
153
|
+
)
|
|
154
|
+
.flatMap((entry) => refsFor(documentsByPath, sourcesForEntry(resolver, entry, modifierValues)));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* `documentsByPath` is keyed by the normalized relative path `loadTokenDocuments`
|
|
159
|
+
* reports (see `load.ts`'s `Glob` scan), but a resolver `$ref` is a URI reference
|
|
160
|
+
* that may spell the same file differently (`./sets/x.tokens.json`, a percent-escaped
|
|
161
|
+
* path). `normalizeSourcePath` -- reused from `validate-corpus.ts`, which faces the
|
|
162
|
+
* identical lookup and already normalizes before comparing -- collapses both to the
|
|
163
|
+
* same key, so a schema-valid ref that validation accepts also resolves here.
|
|
164
|
+
*/
|
|
165
|
+
export function requireDocument(
|
|
166
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
167
|
+
ref: string,
|
|
168
|
+
): TokenDocument {
|
|
169
|
+
const normalizedRef = normalizeSourcePath(ref);
|
|
170
|
+
const document = documentsByPath.get(normalizedRef);
|
|
171
|
+
if (!document) {
|
|
172
|
+
throw new Error(`Resolver references "${ref}" but no loaded token document has that path.`);
|
|
173
|
+
}
|
|
174
|
+
return document;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export function refsFor(
|
|
178
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
179
|
+
refs: readonly ResolverReference[],
|
|
180
|
+
): TokenDocument[] {
|
|
181
|
+
return refs.map((ref) => requireDocument(documentsByPath, ref.$ref));
|
|
182
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The six concrete evaluation contexts of the Cinder profile (`light|dark` by
|
|
3
|
+
* `default|reduced|forced-reduced-motion`) and the ordered document stack each
|
|
4
|
+
* one resolves. Shared by the authoring catalogue and by runtime evaluation so
|
|
5
|
+
* both walk exactly the same layers.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { ProvenanceLayerInput } from './authoring-provenance.ts';
|
|
9
|
+
import { authoringContextId, type AuthoringContext } from './authoring-types.ts';
|
|
10
|
+
import { requireDocument } from './context-order.ts';
|
|
11
|
+
import {
|
|
12
|
+
combinations,
|
|
13
|
+
normalizeSourcePath,
|
|
14
|
+
parseResolutionOrder,
|
|
15
|
+
sourcesForEntry,
|
|
16
|
+
} from './resolver-order.ts';
|
|
17
|
+
import type { ResolverDocument, TokenDocument } from './types.ts';
|
|
18
|
+
|
|
19
|
+
export function authoringContexts(
|
|
20
|
+
resolver: ResolverDocument,
|
|
21
|
+
): Array<AuthoringContext & Record<string, string>> {
|
|
22
|
+
const modifiers = Object.keys(resolver.modifiers);
|
|
23
|
+
if (!modifiers.includes('theme') || !modifiers.includes('motion') || modifiers.length !== 2) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`The authoring catalogue is defined over the "theme" and "motion" modifiers; this resolver declares ${modifiers.join(', ')}.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
return combinations(resolver).map((selection) => ({
|
|
29
|
+
id: authoringContextId(selection['theme']!, selection['motion']!),
|
|
30
|
+
theme: selection['theme']!,
|
|
31
|
+
motion: selection['motion']!,
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function authoringLayerStack(
|
|
36
|
+
resolver: ResolverDocument,
|
|
37
|
+
documentsByPath: Map<string, TokenDocument>,
|
|
38
|
+
context: AuthoringContext,
|
|
39
|
+
): ProvenanceLayerInput[] {
|
|
40
|
+
const modifierValues: Record<string, string> = { theme: context.theme, motion: context.motion };
|
|
41
|
+
return parseResolutionOrder(resolver).flatMap((entry) =>
|
|
42
|
+
sourcesForEntry(resolver, entry, modifierValues).map((reference) => ({
|
|
43
|
+
document: normalizeSourcePath(reference.$ref),
|
|
44
|
+
kind: entry.kind === 'sets' ? ('set' as const) : ('modifier' as const),
|
|
45
|
+
layer:
|
|
46
|
+
entry.kind === 'sets'
|
|
47
|
+
? `sets.${entry.name}`
|
|
48
|
+
: `${entry.name}.${modifierValues[entry.name]}`,
|
|
49
|
+
content: requireDocument(documentsByPath, reference.$ref),
|
|
50
|
+
})),
|
|
51
|
+
);
|
|
52
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { clampRgb, oklchToLinearSrgb, type Lab, type OklchColor, type Rgb } from './color-math.ts';
|
|
2
|
+
|
|
3
|
+
/** CIE L*a*b* (D65) of an OKLCH color, computed on its clamped sRGB output. */
|
|
4
|
+
export function toCieLab(color: OklchColor): Lab {
|
|
5
|
+
const [r, g, b] = clampRgb(oklchToLinearSrgb(color.l, color.c, color.h));
|
|
6
|
+
const x = 0.4124564 * r + 0.3575761 * g + 0.1804375 * b;
|
|
7
|
+
const y = 0.2126729 * r + 0.7151522 * g + 0.072175 * b;
|
|
8
|
+
const z = 0.0193339 * r + 0.119192 * g + 0.9503041 * b;
|
|
9
|
+
const xn = 0.95047;
|
|
10
|
+
const yn = 1;
|
|
11
|
+
const zn = 1.08883;
|
|
12
|
+
const fx = labTransfer(x / xn);
|
|
13
|
+
const fy = labTransfer(y / yn);
|
|
14
|
+
const fz = labTransfer(z / zn);
|
|
15
|
+
return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** CIEDE2000 color difference between two CIE Lab triples. */
|
|
19
|
+
export function ciede2000(lab1: Lab, lab2: Lab): number {
|
|
20
|
+
const [bigL1, a1, b1] = lab1;
|
|
21
|
+
const [bigL2, a2, b2] = lab2;
|
|
22
|
+
const c1 = Math.hypot(a1, b1);
|
|
23
|
+
const c2 = Math.hypot(a2, b2);
|
|
24
|
+
const cBar = (c1 + c2) / 2;
|
|
25
|
+
const g = 0.5 * (1 - Math.sqrt(cBar ** 7 / (cBar ** 7 + 25 ** 7)));
|
|
26
|
+
const a1p = (1 + g) * a1;
|
|
27
|
+
const a2p = (1 + g) * a2;
|
|
28
|
+
const c1p = Math.hypot(a1p, b1);
|
|
29
|
+
const c2p = Math.hypot(a2p, b2);
|
|
30
|
+
// Reference (Sharma et al.) normalizes hue angles to [0, 360); atan2 returns (-180, 180].
|
|
31
|
+
const h1p = c1p === 0 ? 0 : ((Math.atan2(b1, a1p) * 180) / Math.PI + 360) % 360;
|
|
32
|
+
const h2p = c2p === 0 ? 0 : ((Math.atan2(b2, a2p) * 180) / Math.PI + 360) % 360;
|
|
33
|
+
const dLp = bigL2 - bigL1;
|
|
34
|
+
const dCp = c2p - c1p;
|
|
35
|
+
// Zero-chroma branch (CIEDE2000 reference): when either adjusted chroma is zero, hue is
|
|
36
|
+
// undefined — set the hue delta to 0 and skip the ±360 wrap. Without this, atan2(0, 0)
|
|
37
|
+
// is treated as a real angle and produces a nonstandard ΔE00 for grayscale pairs.
|
|
38
|
+
const chromaProduct = c1p * c2p;
|
|
39
|
+
let dhp = 0;
|
|
40
|
+
if (chromaProduct !== 0) {
|
|
41
|
+
dhp = h2p - h1p;
|
|
42
|
+
if (dhp > 180) dhp -= 360;
|
|
43
|
+
else if (dhp < -180) dhp += 360;
|
|
44
|
+
}
|
|
45
|
+
const dHp = 2 * Math.sqrt(c1p * c2p) * Math.sin((dhp * Math.PI) / 360);
|
|
46
|
+
const lBarP = (bigL1 + bigL2) / 2;
|
|
47
|
+
const cBarP = (c1p + c2p) / 2;
|
|
48
|
+
// Mean hue: again undefined at zero chroma — the reference sets it to the sum (one of the
|
|
49
|
+
// two angles is 0), with no ±360 wrap and no halving when the product is zero.
|
|
50
|
+
let hBarP: number;
|
|
51
|
+
if (chromaProduct === 0) {
|
|
52
|
+
hBarP = h1p + h2p;
|
|
53
|
+
} else if (Math.abs(h1p - h2p) <= 180) {
|
|
54
|
+
hBarP = (h1p + h2p) / 2;
|
|
55
|
+
} else {
|
|
56
|
+
hBarP = (h1p + h2p + (h1p + h2p < 360 ? 360 : -360)) / 2;
|
|
57
|
+
}
|
|
58
|
+
const t =
|
|
59
|
+
1 -
|
|
60
|
+
0.17 * Math.cos(((hBarP - 30) * Math.PI) / 180) +
|
|
61
|
+
0.24 * Math.cos((2 * hBarP * Math.PI) / 180) +
|
|
62
|
+
0.32 * Math.cos(((3 * hBarP + 6) * Math.PI) / 180) -
|
|
63
|
+
0.2 * Math.cos(((4 * hBarP - 63) * Math.PI) / 180);
|
|
64
|
+
const dTheta = 30 * Math.exp(-(((hBarP - 275) / 25) ** 2));
|
|
65
|
+
const rc = 2 * Math.sqrt(cBarP ** 7 / (cBarP ** 7 + 25 ** 7));
|
|
66
|
+
const sl = 1 + (0.015 * (lBarP - 50) ** 2) / Math.sqrt(20 + (lBarP - 50) ** 2);
|
|
67
|
+
const sc = 1 + 0.045 * cBarP;
|
|
68
|
+
const sh = 1 + 0.015 * cBarP * t;
|
|
69
|
+
const rt = -Math.sin((2 * dTheta * Math.PI) / 180) * rc;
|
|
70
|
+
return Math.sqrt(
|
|
71
|
+
(dLp / sl) ** 2 + (dCp / sc) ** 2 + (dHp / sh) ** 2 + rt * (dCp / sc) * (dHp / sh),
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Brettel-1997-style dichromacy simulation matrices applied in linear sRGB. Used only
|
|
77
|
+
* for the non-blocking CVD diagnostic, never for a hard assertion.
|
|
78
|
+
*/
|
|
79
|
+
const CVD_MATRICES = {
|
|
80
|
+
protan: [
|
|
81
|
+
[0.152286, 1.052583, -0.204868],
|
|
82
|
+
[0.114503, 0.786281, 0.099216],
|
|
83
|
+
[-0.003882, -0.048116, 1.051998],
|
|
84
|
+
],
|
|
85
|
+
deutan: [
|
|
86
|
+
[0.367322, 0.860646, -0.227968],
|
|
87
|
+
[0.280085, 0.672501, 0.047413],
|
|
88
|
+
[-0.01182, 0.04294, 0.968881],
|
|
89
|
+
],
|
|
90
|
+
tritan: [
|
|
91
|
+
[1.255528, -0.076749, -0.178779],
|
|
92
|
+
[-0.078411, 0.930809, 0.147602],
|
|
93
|
+
[0.004733, 0.691367, 0.3039],
|
|
94
|
+
],
|
|
95
|
+
} satisfies Record<string, [Rgb, Rgb, Rgb]>;
|
|
96
|
+
|
|
97
|
+
export function simulateCvd(color: OklchColor, type: keyof typeof CVD_MATRICES): Lab {
|
|
98
|
+
const [r, g, b] = clampRgb(oklchToLinearSrgb(color.l, color.c, color.h));
|
|
99
|
+
const [row0, row1, row2] = CVD_MATRICES[type];
|
|
100
|
+
const dot = (row: Rgb): number => row[0] * r + row[1] * g + row[2] * b;
|
|
101
|
+
const [sr, sg, sb] = clampRgb([dot(row0), dot(row1), dot(row2)]);
|
|
102
|
+
// Reuse the Lab path on already-linear rgb.
|
|
103
|
+
const x = 0.4124564 * sr + 0.3575761 * sg + 0.1804375 * sb;
|
|
104
|
+
const y = 0.2126729 * sr + 0.7151522 * sg + 0.072175 * sb;
|
|
105
|
+
const z = 0.0193339 * sr + 0.119192 * sg + 0.9503041 * sb;
|
|
106
|
+
const fx = labTransfer(x / 0.95047);
|
|
107
|
+
const fy = labTransfer(y / 1);
|
|
108
|
+
const fz = labTransfer(z / 1.08883);
|
|
109
|
+
return [116 * fy - 16, 500 * (fx - fy), 200 * (fy - fz)];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function labTransfer(value: number): number {
|
|
113
|
+
return value > (6 / 29) ** 3 ? Math.cbrt(value) : value / (3 * (6 / 29) ** 2) + 4 / 29;
|
|
114
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { converter } from 'culori';
|
|
2
|
+
|
|
3
|
+
export type Rgb = [number, number, number];
|
|
4
|
+
export type Lab = [number, number, number];
|
|
5
|
+
export type OklchColor = { l: number; c: number; h: number };
|
|
6
|
+
|
|
7
|
+
const toLinearSrgb = converter('lrgb');
|
|
8
|
+
|
|
9
|
+
/** OKLCH (l in 0..1, chroma, hue degrees) → linear sRGB (may be out of [0,1]). */
|
|
10
|
+
export function oklchToLinearSrgb(l: number, c: number, hDeg: number): Rgb {
|
|
11
|
+
const { r, g, b } = toLinearSrgb({ mode: 'oklch', l, c, h: hDeg });
|
|
12
|
+
return [r, g, b];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const GAMUT_EPSILON = 0.001;
|
|
16
|
+
|
|
17
|
+
/** True when every linear-sRGB channel is within [0,1] (so no chroma clamping occurs). */
|
|
18
|
+
export function isInSrgbGamut(color: OklchColor): boolean {
|
|
19
|
+
return oklchToLinearSrgb(color.l, color.c, color.h).every(
|
|
20
|
+
(channel) => channel >= -GAMUT_EPSILON && channel <= 1 + GAMUT_EPSILON,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Clamp each channel of a linear-sRGB triple into [0,1], preserving the tuple type. */
|
|
25
|
+
export function clampRgb([r, g, b]: Rgb): Rgb {
|
|
26
|
+
return [clampChannel(r), clampChannel(g), clampChannel(b)];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function clampChannel(channel: number): number {
|
|
30
|
+
return Math.min(1, Math.max(0, channel));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** The sRGB transfer function and its inverse, used to move between the two spaces below. */
|
|
34
|
+
export function encodeSrgb(channel: number): number {
|
|
35
|
+
const clamped = Math.min(1, Math.max(0, channel));
|
|
36
|
+
return clamped <= 0.0031308 ? 12.92 * clamped : 1.055 * clamped ** (1 / 2.4) - 0.055;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function decodeSrgb(channel: number): number {
|
|
40
|
+
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A translucent `foreground` painted over an opaque `background`, in and out of
|
|
45
|
+
* LINEAR sRGB.
|
|
46
|
+
*
|
|
47
|
+
* The composite itself happens on GAMMA-ENCODED channels, because that is what
|
|
48
|
+
* the browser does -- and until CIN-245 this function did it on the linear
|
|
49
|
+
* channels it is handed, which is a different color and, in the dark arm, a
|
|
50
|
+
* materially more optimistic one. Measured in Chromium (`page.screenshot` +
|
|
51
|
+
* pixel read-back, both arms, the exact tokens this file gates):
|
|
52
|
+
*
|
|
53
|
+
* white @ 35% over `#1a2430` -> rendered 105,112,120
|
|
54
|
+
* gamma composite 106,113,120 (matches)
|
|
55
|
+
* linear composite 161,162,164 (does not)
|
|
56
|
+
*
|
|
57
|
+
* Compositing black over white in linear light OVERSTATES the result's
|
|
58
|
+
* lightness and so understates contrast; compositing white over a dark surface
|
|
59
|
+
* understates it and so OVERSTATES contrast. The second direction is the
|
|
60
|
+
* dangerous one: it is exactly the dark-arm, light-ink case the border tiers
|
|
61
|
+
* now use, and the old model reported ~1.5x more contrast than ships. Every
|
|
62
|
+
* assertion here that composites reads the browser's number now.
|
|
63
|
+
*/
|
|
64
|
+
export function compositeOver(foreground: Rgb, background: Rgb, opacity: number): Rgb {
|
|
65
|
+
const compositeChannel = (channel: number, backdrop: number): number =>
|
|
66
|
+
decodeSrgb(encodeSrgb(channel) * opacity + encodeSrgb(backdrop) * (1 - opacity));
|
|
67
|
+
return [
|
|
68
|
+
compositeChannel(foreground[0], background[0]),
|
|
69
|
+
compositeChannel(foreground[1], background[1]),
|
|
70
|
+
compositeChannel(foreground[2], background[2]),
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** WCAG relative luminance of an OKLCH color (computed on its clamped sRGB output). */
|
|
75
|
+
export function wcagLuminance(color: OklchColor): number {
|
|
76
|
+
return relativeLuminance(clampRgb(oklchToLinearSrgb(color.l, color.c, color.h)));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** WCAG relative luminance of a linear-sRGB triple, unrounded. */
|
|
80
|
+
export function relativeLuminance([r, g, b]: Rgb): number {
|
|
81
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** WCAG contrast ratio between two relative luminances. */
|
|
85
|
+
export function contrastRatio(luminanceA: number, luminanceB: number): number {
|
|
86
|
+
const lighter = Math.max(luminanceA, luminanceB);
|
|
87
|
+
const darker = Math.min(luminanceA, luminanceB);
|
|
88
|
+
return (lighter + 0.05) / (darker + 0.05);
|
|
89
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { OklchColor } from './color-math.ts';
|
|
2
|
+
|
|
3
|
+
export function mixOklch(base: OklchColor, target: OklchColor, targetPercent: number): OklchColor {
|
|
4
|
+
const weight = targetPercent / 100;
|
|
5
|
+
const baseHue = base.c === 0 ? target.h : base.h;
|
|
6
|
+
const targetHue = target.c === 0 ? base.h : target.h;
|
|
7
|
+
let hueDelta = targetHue - baseHue;
|
|
8
|
+
if (hueDelta > 180) hueDelta -= 360;
|
|
9
|
+
if (hueDelta < -180) hueDelta += 360;
|
|
10
|
+
return {
|
|
11
|
+
l: base.l + (target.l - base.l) * weight,
|
|
12
|
+
c: base.c + (target.c - base.c) * weight,
|
|
13
|
+
h: baseHue + hueDelta * weight,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function deriveStatusTier(base: OklchColor, target: OklchColor): OklchColor {
|
|
18
|
+
const mixed = mixOklch(base, target, 36);
|
|
19
|
+
return { ...mixed, c: Math.min(mixed.c, 0.05) };
|
|
20
|
+
}
|