@lostgradient/cinder 0.27.1 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +41 -0
- package/components.json +1 -1
- package/dist/_internal/code-highlighter-context.d.ts +28 -0
- package/dist/cli/index.js +12 -8
- package/dist/components/approval-card/index.js +4 -4
- package/dist/components/button/button.css +25 -0
- package/dist/components/calendar/calendar.css +14 -0
- package/dist/components/capability-gate/capability-gate.css +5 -0
- package/dist/components/checkbox/checkbox.css +19 -0
- package/dist/components/chip/chip.css +14 -0
- package/dist/components/code-block/code-block.d.svelte.ts +1 -1
- package/dist/components/code-block/code-block.examples.json +1 -1
- package/dist/components/code-block/code-block.schema.js +3 -3
- package/dist/components/code-block/code-block.svelte.d.ts +1 -1
- package/dist/components/code-block/code-block.types.d.ts +14 -12
- package/dist/components/code-block/index.js +2 -2
- package/dist/components/color-picker/color-picker.css +2 -0
- package/dist/components/combobox/combobox.css +9 -1
- package/dist/components/command-palette/command-palette.css +7 -5
- package/dist/components/file-upload/file-upload.css +2 -1
- package/dist/components/guidance-region/index.css +1 -1
- package/dist/components/image/image.examples.json +1 -1
- package/dist/components/input/input.css +20 -6
- package/dist/components/json-schema-editor/index.js +5 -5
- package/dist/components/json-schema-editor/json-view-highlighter.d.ts +14 -0
- package/dist/components/key-value-editor/index.css +1 -1
- package/dist/components/modal-region/index.css +1 -1
- package/dist/components/multi-select/multi-select.css +9 -0
- package/dist/components/pagination/pagination.css +12 -0
- package/dist/components/pin-input/pin-input.css +9 -1
- package/dist/components/radio-group/radio-group.css +16 -0
- package/dist/components/run-step-timeline/index.js +2 -2
- package/dist/components/schema-form/index.js +2 -2
- package/dist/components/schema-form/schema-form.css +9 -0
- package/dist/components/segmented-control/segmented-control.css +3 -3
- package/dist/components/selection-popover/selection-popover.css +7 -1
- package/dist/components/tag-input/tag-input.css +10 -1
- package/dist/components/terminal-frame/index.js +2 -2
- package/dist/components/terminal-frame/terminal-frame.schema.js +2 -2
- package/dist/components/terminal-frame/terminal-frame.types.d.ts +8 -0
- package/dist/components/textarea/textarea.css +1 -1
- package/dist/components/toggle/toggle.css +16 -0
- package/dist/components/tree/tree.examples.json +1 -1
- package/dist/components/virtual-list/index.js +2 -2
- package/dist/components/virtual-list/virtual-list.css +42 -9
- package/dist/highlighters/shiki/default.d.ts +13 -1
- package/dist/highlighters/shiki/default.js +2 -2
- package/dist/highlighters/shiki/index.d.ts +20 -12
- package/dist/highlighters/shiki/index.js +2 -2
- package/dist/index.browser.css +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +23 -23
- package/dist/scripts/knowledge/index.d.ts +5 -1
- package/dist/server/components/approval-card/index.js +1 -1
- package/dist/server/components/code-block/index.js +1 -1
- package/dist/server/components/color-field/index.js +2 -2
- package/dist/server/components/color-picker/index.js +2 -2
- package/dist/server/components/json-schema-editor/index.js +2 -2
- package/dist/server/components/run-step-timeline/index.js +1 -1
- package/dist/server/components/terminal-frame/index.js +1 -1
- package/dist/server/components/virtual-list/index.js +1 -1
- package/dist/server/github-dark-e7nywpbe.js +3 -0
- package/dist/server/github-light-bqtmm1zq.js +3 -0
- package/dist/server/highlighters/shiki/default.js +2 -2
- package/dist/server/highlighters/shiki/index.js +2 -2
- package/dist/server/index.js +6 -6
- package/dist/server/{index.server-4qyyw4y5.js → index.server-043cfznf.js} +1 -1
- package/dist/server/{index.server-p46tn4eb.js → index.server-09tjs48p.js} +2 -2
- package/dist/server/index.server-0hyvdf74.js +8 -0
- package/dist/server/{index.server-dxgkh9tk.js → index.server-17thvpd3.js} +1 -1
- package/dist/server/index.server-19z6hqd6.js +4 -0
- package/dist/server/index.server-31020qgk.js +3 -0
- package/dist/server/{index.server-w3nqzde5.js → index.server-45wmvjrn.js} +3 -3
- package/dist/server/{index.server-3tkgm2gn.js → index.server-6mb7w5g4.js} +2 -2
- package/dist/server/{index.server-2vxmn7x1.js → index.server-c5yajkkc.js} +4 -4
- package/dist/server/index.server-e6fknxd9.js +4 -0
- package/dist/server/index.server-fev4kwm0.js +4 -0
- package/dist/server/index.server-k4vjk75r.js +4 -0
- package/dist/server/index.server-mjbtd1gs.js +7 -0
- package/dist/server/{index.server-2bfkhzzq.js → index.server-rkp4py5n.js} +2 -2
- package/dist/server/index.server-wdz9tsq4.js +3 -0
- package/dist/server/index.server-zj9909hd.js +4 -0
- package/dist/server/json-68twtta3.js +3 -0
- package/dist/server/tokens/registry.generated.js +1 -1
- package/dist/server/tokens/runtime/index.js +92 -0
- package/dist/styles/check-token-contrast-test-values.d.ts +1 -3
- package/dist/styles/token-contrast-test-readers.d.ts +1 -1
- package/dist/tokens/registry.generated.js +2 -2
- package/dist/tokens/resolved/dark-reduced-motion.json +104 -43
- package/dist/tokens/resolved/dark.json +104 -43
- package/dist/tokens/resolved/light-reduced-motion.json +104 -43
- package/dist/tokens/resolved/light.json +104 -43
- package/dist/tokens/runtime/authoring-catalogue.d.ts +19 -0
- package/dist/tokens/runtime/authoring-catalogue.generated.d.ts +8 -0
- package/dist/tokens/runtime/authoring-palette.d.ts +25 -0
- package/dist/tokens/runtime/authoring-profiles.d.ts +48 -0
- package/dist/tokens/runtime/authoring-provenance.d.ts +31 -0
- package/dist/tokens/runtime/authoring-types.d.ts +182 -0
- package/dist/tokens/runtime/base-corpus.d.ts +29 -0
- package/dist/tokens/runtime/base-corpus.generated.d.ts +8 -0
- package/dist/tokens/runtime/context-order.d.ts +60 -0
- package/dist/tokens/runtime/context-stack.d.ts +11 -0
- package/dist/tokens/runtime/contrast/color-difference.d.ts +16 -0
- package/dist/{styles/color-contrast-utilities.d.ts → tokens/runtime/contrast/color-math.d.ts} +2 -17
- package/dist/tokens/runtime/contrast/color-mix.d.ts +3 -0
- package/dist/tokens/runtime/contrast/css-color.d.ts +29 -0
- package/dist/tokens/runtime/contrast/index.d.ts +7 -0
- package/dist/tokens/runtime/contrast/measure.d.ts +45 -0
- package/dist/tokens/runtime/contrast/pairings.d.ts +36 -0
- package/dist/tokens/runtime/contrast/thresholds.d.ts +47 -0
- package/dist/tokens/runtime/corpus-documents.d.ts +36 -0
- package/dist/tokens/runtime/corpus-validation.d.ts +10 -0
- package/dist/tokens/runtime/corpus.d.ts +35 -0
- package/dist/tokens/runtime/css-configuration.d.ts +1 -0
- package/dist/tokens/runtime/css-stylelint.d.ts +2 -0
- package/dist/tokens/runtime/css-support.d.ts +110 -0
- package/dist/tokens/runtime/evaluate.d.ts +95 -0
- package/dist/tokens/runtime/evaluated-provenance.d.ts +36 -0
- package/dist/tokens/runtime/index.d.ts +38 -0
- package/dist/tokens/runtime/index.js +95 -0
- package/dist/tokens/runtime/package-version.generated.d.ts +9 -0
- package/dist/tokens/runtime/projection.d.ts +32 -0
- package/dist/tokens/runtime/registry.d.ts +125 -0
- package/dist/tokens/runtime/resolve-extends.d.ts +30 -0
- package/dist/tokens/runtime/resolve-references.d.ts +49 -0
- package/dist/tokens/runtime/resolve-shared.d.ts +34 -0
- package/dist/tokens/runtime/resolve.d.ts +44 -0
- package/dist/tokens/runtime/resolver-order.d.ts +89 -0
- package/dist/tokens/runtime/source-digest.d.ts +20 -0
- package/dist/tokens/runtime/stylesheet-skeleton.d.ts +31 -0
- package/dist/tokens/runtime/theme-runtime.test-support.d.ts +24 -0
- package/dist/tokens/runtime/theme-sources.d.ts +46 -0
- package/dist/tokens/runtime/theme-stylesheet.d.ts +31 -0
- package/dist/tokens/runtime/types.d.ts +115 -0
- package/dist/tokens/runtime/validate-resolver.d.ts +31 -0
- package/dist/tokens/runtime/validate-schema.d.ts +22 -0
- package/dist/tokens/runtime/validate-tokens.d.ts +25 -0
- package/dist/tokens/runtime/validate-values.d.ts +33 -0
- package/dist/tokens/runtime/validate.d.ts +3 -0
- package/dist/tokens/runtime/value-color-parse.d.ts +128 -0
- package/dist/tokens/runtime/value-color.d.ts +85 -0
- package/dist/tokens/runtime/value-entry.d.ts +3 -0
- package/dist/tokens/runtime/value-formatters.d.ts +59 -0
- package/dist/tokens/sets/colors.tokens.json +65 -13
- package/dist/tokens/sets/foundation.tokens.json +23 -0
- package/dist/tokens/sets/semantic.tokens.json +136 -30
- package/dist/utilities/highlighter.d.ts +5 -5
- package/dist/utilities/retrying-loader-cache.d.ts +3 -6
- package/package.json +15 -3
- package/src/_internal/code-highlighter-context.ts +41 -0
- package/src/components/button/button.css +25 -0
- package/src/components/calendar/calendar.css +14 -0
- package/src/components/capability-gate/capability-gate.css +5 -0
- package/src/components/checkbox/checkbox.css +19 -0
- package/src/components/chip/chip.css +14 -0
- package/src/components/code-block/code-block.examples.json +1 -1
- package/src/components/code-block/code-block.schema.json +2 -2
- package/src/components/code-block/code-block.schema.ts +2 -2
- package/src/components/code-block/code-block.svelte +15 -19
- package/src/components/code-block/code-block.types.ts +14 -12
- package/src/components/color-picker/color-picker.css +2 -0
- package/src/components/combobox/combobox.css +9 -1
- package/src/components/command-palette/command-palette.css +7 -5
- package/src/components/file-upload/file-upload.css +2 -1
- package/src/components/image/image.examples.json +1 -1
- package/src/components/input/input.css +20 -6
- package/src/components/json-schema-editor/json-view-highlighter.ts +23 -0
- package/src/components/json-schema-editor/json-view.svelte +2 -0
- package/src/components/multi-select/multi-select.css +9 -0
- package/src/components/pagination/pagination.css +12 -0
- package/src/components/pin-input/pin-input.css +9 -1
- package/src/components/radio-group/radio-group.css +16 -0
- package/src/components/schema-form/schema-form.css +9 -0
- package/src/components/segmented-control/segmented-control.css +3 -3
- package/src/components/selection-popover/selection-popover.css +7 -1
- package/src/components/tag-input/tag-input.css +10 -1
- package/src/components/terminal-frame/terminal-frame.schema.json +5 -0
- package/src/components/terminal-frame/terminal-frame.schema.ts +6 -0
- package/src/components/terminal-frame/terminal-frame.svelte +6 -2
- package/src/components/terminal-frame/terminal-frame.types.ts +8 -0
- package/src/components/textarea/textarea.css +1 -1
- package/src/components/toggle/toggle.css +16 -0
- package/src/components/tree/tree.examples.json +1 -1
- package/src/components/virtual-list/virtual-list.css +42 -9
- package/src/components/virtual-list/virtual-list.svelte +54 -20
- package/src/highlighters/shiki/default.ts +13 -1
- package/src/highlighters/shiki/index.ts +20 -12
- package/src/index.ts +5 -0
- package/src/styles/foundation.css +33 -1
- package/src/styles/tokens-base.css +4 -4
- package/src/tokens/registry.generated.json +3 -3
- package/src/tokens/resolved/dark-reduced-motion.json +104 -43
- package/src/tokens/resolved/dark.json +104 -43
- package/src/tokens/resolved/light-reduced-motion.json +104 -43
- package/src/tokens/resolved/light.json +104 -43
- package/src/tokens/runtime/authoring-catalogue.generated.ts +19300 -0
- package/src/tokens/runtime/authoring-catalogue.ts +256 -0
- package/src/tokens/runtime/authoring-palette.ts +100 -0
- package/src/tokens/runtime/authoring-profiles.ts +288 -0
- package/src/tokens/runtime/authoring-provenance.ts +290 -0
- package/src/tokens/runtime/authoring-types.ts +199 -0
- package/src/tokens/runtime/base-corpus.generated.ts +10 -0
- package/src/tokens/runtime/base-corpus.ts +78 -0
- package/src/tokens/runtime/context-order.ts +182 -0
- package/src/tokens/runtime/context-stack.ts +52 -0
- package/src/tokens/runtime/contrast/color-difference.ts +114 -0
- package/src/tokens/runtime/contrast/color-math.ts +89 -0
- package/src/tokens/runtime/contrast/color-mix.ts +20 -0
- package/src/tokens/runtime/contrast/css-color.ts +312 -0
- package/src/tokens/runtime/contrast/index.ts +7 -0
- package/src/tokens/runtime/contrast/measure.ts +185 -0
- package/src/tokens/runtime/contrast/pairings.ts +324 -0
- package/src/tokens/runtime/contrast/thresholds.ts +81 -0
- package/src/tokens/runtime/corpus-documents.ts +289 -0
- package/src/tokens/runtime/corpus-validation.ts +336 -0
- package/src/tokens/runtime/corpus.ts +179 -0
- package/src/tokens/runtime/css-configuration.ts +1 -0
- package/src/tokens/runtime/css-stylelint.ts +15 -0
- package/src/tokens/runtime/css-support.ts +407 -0
- package/src/tokens/runtime/evaluate.ts +262 -0
- package/src/tokens/runtime/evaluated-provenance.ts +116 -0
- package/src/tokens/runtime/format-validator.generated.d.ts +18 -0
- package/src/tokens/runtime/format-validator.generated.js +13029 -0
- package/src/tokens/runtime/index.ts +78 -0
- package/src/tokens/runtime/package-version.generated.ts +9 -0
- package/src/tokens/runtime/projection.ts +65 -0
- package/src/tokens/runtime/registry.ts +365 -0
- package/src/tokens/runtime/resolve-extends.ts +211 -0
- package/src/tokens/runtime/resolve-references.ts +313 -0
- package/src/tokens/runtime/resolve-shared.ts +186 -0
- package/src/tokens/runtime/resolve.ts +246 -0
- package/src/tokens/runtime/resolver-order.ts +326 -0
- package/src/tokens/runtime/resolver-validator.generated.d.ts +18 -0
- package/src/tokens/runtime/resolver-validator.generated.js +15492 -0
- package/src/tokens/runtime/source-digest.ts +49 -0
- package/src/tokens/runtime/stylesheet-skeleton.ts +123 -0
- package/src/tokens/runtime/theme-sources.ts +121 -0
- package/src/tokens/runtime/theme-stylesheet.ts +177 -0
- package/src/tokens/runtime/types.ts +140 -0
- package/src/tokens/runtime/validate-resolver.ts +338 -0
- package/src/tokens/runtime/validate-schema.ts +269 -0
- package/src/tokens/runtime/validate-tokens.ts +181 -0
- package/src/tokens/runtime/validate-values.ts +396 -0
- package/src/tokens/runtime/validate.ts +57 -0
- package/src/tokens/runtime/value-color-parse.ts +309 -0
- package/src/tokens/runtime/value-color.ts +217 -0
- package/src/tokens/runtime/value-entry.ts +52 -0
- package/src/tokens/runtime/value-formatters.ts +414 -0
- package/src/tokens/sets/colors.tokens.json +65 -13
- package/src/tokens/sets/foundation.tokens.json +23 -0
- package/src/tokens/sets/semantic.tokens.json +136 -30
- package/src/utilities/highlighter.ts +5 -5
- package/src/utilities/retrying-loader-cache.ts +3 -6
- package/dist/components/code-block/code-block-default-highlighter.d.ts +0 -40
- package/dist/server/index.server-298z43yn.js +0 -4
- package/dist/server/index.server-3h11wjyh.js +0 -8
- package/dist/server/index.server-a3aerbfr.js +0 -4
- package/dist/server/index.server-kge3zp6n.js +0 -4
- package/dist/server/index.server-syf81nwz.js +0 -6
- package/dist/server/index.server-zs08f5te.js +0 -3
- package/src/components/code-block/code-block-default-highlighter.ts +0 -63
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import type { DesignToken, TokenType, ValidationIssue } from './types.ts';
|
|
2
|
+
import { TokenValidationError } from './types.ts';
|
|
3
|
+
import { unknownReservedPropertyReason } from './validate-resolver.ts';
|
|
4
|
+
import {
|
|
5
|
+
GROUP_METADATA,
|
|
6
|
+
TOKEN_METADATA,
|
|
7
|
+
TOKEN_NAME_PATTERN,
|
|
8
|
+
VENDOR_EXTENSION_PATTERN,
|
|
9
|
+
addIssue,
|
|
10
|
+
hasTokenValue,
|
|
11
|
+
isObject,
|
|
12
|
+
isReference,
|
|
13
|
+
isTokenType,
|
|
14
|
+
validateValue,
|
|
15
|
+
type JsonObject,
|
|
16
|
+
} from './validate-values.ts';
|
|
17
|
+
|
|
18
|
+
export function tokenType(
|
|
19
|
+
token: JsonObject,
|
|
20
|
+
inheritedType: TokenType | undefined,
|
|
21
|
+
path: string,
|
|
22
|
+
issues: ValidationIssue[],
|
|
23
|
+
): TokenType | undefined {
|
|
24
|
+
const declaredType = token['$type'];
|
|
25
|
+
if (declaredType !== undefined && !isTokenType(declaredType)) {
|
|
26
|
+
addIssue(issues, path, `unknown $type ${JSON.stringify(declaredType)}`);
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
const resolvedType = declaredType ?? inheritedType;
|
|
30
|
+
if (!resolvedType) addIssue(issues, path, 'token has no $type and no inherited type');
|
|
31
|
+
return resolvedType;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function validateMetadata(
|
|
35
|
+
node: JsonObject,
|
|
36
|
+
path: string,
|
|
37
|
+
issues: ValidationIssue[],
|
|
38
|
+
isDocumentRoot = false,
|
|
39
|
+
): void {
|
|
40
|
+
if (node['$schema'] !== undefined && (!isDocumentRoot || typeof node['$schema'] !== 'string'))
|
|
41
|
+
addIssue(issues, path, '$schema must be a root-level string URI');
|
|
42
|
+
if (node['$description'] !== undefined && typeof node['$description'] !== 'string')
|
|
43
|
+
addIssue(issues, path, '$description must be a string');
|
|
44
|
+
if (node['$extends'] !== undefined && !isReference(node['$extends']))
|
|
45
|
+
addIssue(issues, path, '$extends must be a token reference');
|
|
46
|
+
if (
|
|
47
|
+
node['$deprecated'] !== undefined &&
|
|
48
|
+
typeof node['$deprecated'] !== 'boolean' &&
|
|
49
|
+
typeof node['$deprecated'] !== 'string'
|
|
50
|
+
)
|
|
51
|
+
addIssue(issues, path, '$deprecated must be a boolean or string');
|
|
52
|
+
if (node['$extensions'] !== undefined) {
|
|
53
|
+
if (!isObject(node['$extensions'])) addIssue(issues, path, '$extensions must be an object');
|
|
54
|
+
else
|
|
55
|
+
for (const key of Object.keys(node['$extensions']))
|
|
56
|
+
if (!VENDOR_EXTENSION_PATTERN.test(key))
|
|
57
|
+
addIssue(issues, path, `$extensions key ${key} is not a vendor name`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validates a token-shaped node ($root's value, or an ordinary named leaf)
|
|
63
|
+
* once both callers in `validateGroup` agree it declares `$value` and/or
|
|
64
|
+
* `$ref` rather than nesting further groups.
|
|
65
|
+
*
|
|
66
|
+
* $type for a `$ref` token: unlike a `$value` token, `$ref` does not require
|
|
67
|
+
* a declared or inherited `$type` here -- the acceptance case for CIN-463
|
|
68
|
+
* (`{ copy: { $ref: "#/base" } }` at the document root, with no ancestor
|
|
69
|
+
* group typing it) has nowhere to inherit one from. `resolve.ts` fills the
|
|
70
|
+
* resolved `$type` in from the reference target when the `$ref` token
|
|
71
|
+
* declares none of its own; `validateResolvedToken` is what actually
|
|
72
|
+
* enforces "every resolved token has a $type", after that fallback has run.
|
|
73
|
+
* If a `$ref` token DOES declare its own `$type`, it is still checked here
|
|
74
|
+
* for membership in the known type set, just never used to check a value
|
|
75
|
+
* shape (there is no `$value` to check until resolution).
|
|
76
|
+
*/
|
|
77
|
+
export function validateTokenNode(
|
|
78
|
+
value: JsonObject,
|
|
79
|
+
path: string,
|
|
80
|
+
groupType: TokenType | undefined,
|
|
81
|
+
mayInheritTypeThroughExtension: boolean,
|
|
82
|
+
issues: ValidationIssue[],
|
|
83
|
+
isRoot = false,
|
|
84
|
+
): void {
|
|
85
|
+
validateMetadata(value, path, issues);
|
|
86
|
+
const hasValue = '$value' in value;
|
|
87
|
+
const hasRef = '$ref' in value;
|
|
88
|
+
if (hasValue && hasRef) addIssue(issues, path, 'a token cannot declare both $value and $ref');
|
|
89
|
+
const nonMetadataChildren = Object.keys(value).filter((key) => !key.startsWith('$'));
|
|
90
|
+
if (nonMetadataChildren.length > 0)
|
|
91
|
+
addIssue(
|
|
92
|
+
issues,
|
|
93
|
+
path,
|
|
94
|
+
isRoot
|
|
95
|
+
? '$root token cannot contain child groups'
|
|
96
|
+
: 'a token with $value or $ref cannot contain child groups',
|
|
97
|
+
);
|
|
98
|
+
for (const key of Object.keys(value))
|
|
99
|
+
if (key.startsWith('$') && !TOKEN_METADATA.has(key))
|
|
100
|
+
addIssue(issues, path, unknownReservedPropertyReason(key));
|
|
101
|
+
if (hasRef && !hasValue) {
|
|
102
|
+
if (typeof value['$ref'] !== 'string' || !value['$ref'].startsWith('#/'))
|
|
103
|
+
addIssue(issues, path, '$ref must be a JSON Pointer reference');
|
|
104
|
+
if (value['$type'] !== undefined && !isTokenType(value['$type']))
|
|
105
|
+
addIssue(issues, path, `unknown $type ${JSON.stringify(value['$type'])}`);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const type =
|
|
109
|
+
groupType === undefined && mayInheritTypeThroughExtension && value['$type'] === undefined
|
|
110
|
+
? undefined
|
|
111
|
+
: tokenType(value, groupType, path, issues);
|
|
112
|
+
if (type) validateValue(type, value['$value'], path, issues);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function validateGroup(
|
|
116
|
+
group: JsonObject,
|
|
117
|
+
path: string,
|
|
118
|
+
inheritedType: TokenType | undefined,
|
|
119
|
+
issues: ValidationIssue[],
|
|
120
|
+
isDocumentRoot = false,
|
|
121
|
+
inheritsTypeThroughExtension = false,
|
|
122
|
+
): void {
|
|
123
|
+
validateMetadata(group, path, issues, isDocumentRoot);
|
|
124
|
+
for (const key of Object.keys(group))
|
|
125
|
+
if (key.startsWith('$') && !GROUP_METADATA.has(key))
|
|
126
|
+
addIssue(issues, path, unknownReservedPropertyReason(key));
|
|
127
|
+
const groupType =
|
|
128
|
+
group['$type'] === undefined ? inheritedType : tokenType(group, inheritedType, path, issues);
|
|
129
|
+
const mayInheritTypeThroughExtension =
|
|
130
|
+
inheritsTypeThroughExtension || (groupType === undefined && group['$extends'] !== undefined);
|
|
131
|
+
for (const [name, value] of Object.entries(group)) {
|
|
132
|
+
if (name === '$root') {
|
|
133
|
+
// A `$root` token resolves at its group's own path, but reporting issues
|
|
134
|
+
// there cannot distinguish the root token from the group that holds it --
|
|
135
|
+
// and a group with a `$root` usually has siblings too. Point at the
|
|
136
|
+
// document location instead, which is unambiguous and is where the author
|
|
137
|
+
// has to edit; the token path is that minus the trailing `.$root`.
|
|
138
|
+
const rootPath = `${path}.$root`;
|
|
139
|
+
if (!isObject(value) || !hasTokenValue(value)) {
|
|
140
|
+
addIssue(issues, rootPath, '$root must be a token object');
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
validateTokenNode(value, rootPath, groupType, mayInheritTypeThroughExtension, issues, true);
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (name.startsWith('$')) continue;
|
|
147
|
+
const childPath = `${path}.${name}`;
|
|
148
|
+
if (!TOKEN_NAME_PATTERN.test(name)) {
|
|
149
|
+
addIssue(
|
|
150
|
+
issues,
|
|
151
|
+
childPath,
|
|
152
|
+
'token and group names may not start with $, or contain {, }, or .',
|
|
153
|
+
);
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (!isObject(value)) {
|
|
157
|
+
addIssue(issues, childPath, 'token or group must be an object');
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (hasTokenValue(value)) {
|
|
161
|
+
validateTokenNode(value, childPath, groupType, mayInheritTypeThroughExtension, issues);
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
validateGroup(value, childPath, groupType, issues, false, mayInheritTypeThroughExtension);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function validateTokenDocument(document: unknown, source = '$'): void {
|
|
169
|
+
const issues: ValidationIssue[] = [];
|
|
170
|
+
if (!isObject(document)) addIssue(issues, source, 'document must be an object');
|
|
171
|
+
else validateGroup(document, source, undefined, issues, true);
|
|
172
|
+
if (issues.length > 0) throw new TokenValidationError(issues);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Validates a fully resolved token so aliases cannot change its declared value shape. */
|
|
176
|
+
export function validateResolvedToken(token: DesignToken, path: string): void {
|
|
177
|
+
const issues: ValidationIssue[] = [];
|
|
178
|
+
if (!token.$type) addIssue(issues, path, 'resolved token has no $type');
|
|
179
|
+
else validateValue(token.$type, token.$value, path, issues);
|
|
180
|
+
if (issues.length > 0) throw new TokenValidationError(issues);
|
|
181
|
+
}
|
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import type { TokenType, ValidationIssue } from './types.ts';
|
|
2
|
+
import { TOKEN_TYPES } from './types.ts';
|
|
3
|
+
|
|
4
|
+
export const TOKEN_NAME_PATTERN = /^[^${}.][^{}.]*$/;
|
|
5
|
+
export const VENDOR_EXTENSION_PATTERN = /^(?:[a-z0-9-]+\.)+[a-z0-9-]+$/i;
|
|
6
|
+
export const TOKEN_TYPE_SET = new Set<string>(TOKEN_TYPES);
|
|
7
|
+
export const COLOR_SPACES = new Set([
|
|
8
|
+
'srgb',
|
|
9
|
+
'srgb-linear',
|
|
10
|
+
'display-p3',
|
|
11
|
+
'a98-rgb',
|
|
12
|
+
'prophoto-rgb',
|
|
13
|
+
'rec2020',
|
|
14
|
+
'xyz-d50',
|
|
15
|
+
'xyz-d65',
|
|
16
|
+
'hsl',
|
|
17
|
+
'hwb',
|
|
18
|
+
'lab',
|
|
19
|
+
'oklab',
|
|
20
|
+
'lch',
|
|
21
|
+
'oklch',
|
|
22
|
+
]);
|
|
23
|
+
export const HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
24
|
+
export const COLOR_MEMBERS = new Set(['colorSpace', 'components', 'alpha', 'hex']);
|
|
25
|
+
export const DIMENSION_MEMBERS = new Set(['value', 'unit']);
|
|
26
|
+
|
|
27
|
+
export type JsonObject = Record<string, unknown>;
|
|
28
|
+
export type ResolverDocumentShape = {
|
|
29
|
+
version: unknown;
|
|
30
|
+
sets: JsonObject;
|
|
31
|
+
modifiers: JsonObject;
|
|
32
|
+
resolutionOrder: unknown[];
|
|
33
|
+
};
|
|
34
|
+
export const GROUP_METADATA = new Set([
|
|
35
|
+
'$type',
|
|
36
|
+
'$description',
|
|
37
|
+
'$deprecated',
|
|
38
|
+
'$extensions',
|
|
39
|
+
'$extends',
|
|
40
|
+
'$root',
|
|
41
|
+
'$schema',
|
|
42
|
+
]);
|
|
43
|
+
export const TOKEN_METADATA = new Set([
|
|
44
|
+
'$value',
|
|
45
|
+
'$ref',
|
|
46
|
+
'$type',
|
|
47
|
+
'$description',
|
|
48
|
+
'$deprecated',
|
|
49
|
+
'$extensions',
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
export function isObject(value: unknown): value is JsonObject {
|
|
53
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isCubicBezier(value: unknown): value is [number, number, number, number] {
|
|
57
|
+
return (
|
|
58
|
+
Array.isArray(value) && value.length === 4 && value.every((entry) => typeof entry === 'number')
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function isReference(value: unknown): value is string {
|
|
63
|
+
return typeof value === 'string' && (/^\{[^{}]+\}$/.test(value) || value.startsWith('#/'));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* A node is token-shaped if it declares either the value form (`$value`) or
|
|
68
|
+
* the DTCG 2025.10 alias form (`$ref`) -- as opposed to a group, which
|
|
69
|
+
* declares neither and instead nests further named children. Checking both
|
|
70
|
+
* keys (rather than `$value` alone) is what CIN-463 fixes: previously a
|
|
71
|
+
* `$ref`-only node fell through to being validated as an (empty) group.
|
|
72
|
+
*/
|
|
73
|
+
export function hasTokenValue(value: JsonObject): boolean {
|
|
74
|
+
return '$value' in value || '$ref' in value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function addIssue(issues: ValidationIssue[], path: string, reason: string): void {
|
|
78
|
+
issues.push({ path, reason });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export function validateCompositeMembers(
|
|
82
|
+
value: JsonObject,
|
|
83
|
+
members: Readonly<Record<string, TokenType>>,
|
|
84
|
+
path: string,
|
|
85
|
+
issues: ValidationIssue[],
|
|
86
|
+
optionalMembers: ReadonlySet<string> = new Set(),
|
|
87
|
+
): void {
|
|
88
|
+
const allowedMembers = new Set([...Object.keys(members), ...optionalMembers]);
|
|
89
|
+
for (const name of Object.keys(value))
|
|
90
|
+
if (!allowedMembers.has(name)) addIssue(issues, path, `unknown composite member ${name}`);
|
|
91
|
+
for (const [name, type] of Object.entries(members)) {
|
|
92
|
+
if (!(name in value)) {
|
|
93
|
+
addIssue(issues, path, `composite value must include ${name}`);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
validateValue(type, value[name], `${path}.${name}`, issues);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function validateColor(
|
|
101
|
+
objectValue: JsonObject | undefined,
|
|
102
|
+
path: string,
|
|
103
|
+
issues: ValidationIssue[],
|
|
104
|
+
): void {
|
|
105
|
+
if (
|
|
106
|
+
!objectValue ||
|
|
107
|
+
typeof objectValue['colorSpace'] !== 'string' ||
|
|
108
|
+
!COLOR_SPACES.has(objectValue['colorSpace']) ||
|
|
109
|
+
!Array.isArray(objectValue['components']) ||
|
|
110
|
+
objectValue['components'].length !== 3 ||
|
|
111
|
+
!objectValue['components'].every(
|
|
112
|
+
(component) =>
|
|
113
|
+
typeof component === 'number' || component === 'none' || isReference(component),
|
|
114
|
+
) ||
|
|
115
|
+
(objectValue['alpha'] !== undefined &&
|
|
116
|
+
(typeof objectValue['alpha'] !== 'number' ||
|
|
117
|
+
objectValue['alpha'] < 0 ||
|
|
118
|
+
objectValue['alpha'] > 1) &&
|
|
119
|
+
objectValue['alpha'] !== 'none' &&
|
|
120
|
+
!isReference(objectValue['alpha'])) ||
|
|
121
|
+
(objectValue['hex'] !== undefined &&
|
|
122
|
+
(typeof objectValue['hex'] !== 'string' || !HEX_COLOR_PATTERN.test(objectValue['hex'])))
|
|
123
|
+
)
|
|
124
|
+
addIssue(
|
|
125
|
+
issues,
|
|
126
|
+
path,
|
|
127
|
+
'color must have a colorSpace, three numeric or none components, and valid optional alpha or hex',
|
|
128
|
+
);
|
|
129
|
+
if (objectValue)
|
|
130
|
+
for (const name of Object.keys(objectValue))
|
|
131
|
+
if (!COLOR_MEMBERS.has(name)) addIssue(issues, path, `unknown color member ${name}`);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function validateStrokeStyle(
|
|
135
|
+
value: unknown,
|
|
136
|
+
objectValue: JsonObject | undefined,
|
|
137
|
+
path: string,
|
|
138
|
+
issues: ValidationIssue[],
|
|
139
|
+
): void {
|
|
140
|
+
if (
|
|
141
|
+
typeof value === 'string' &&
|
|
142
|
+
['dotted', 'dashed', 'solid', 'double', 'groove', 'ridge', 'inset', 'outset'].includes(value)
|
|
143
|
+
)
|
|
144
|
+
return;
|
|
145
|
+
if (
|
|
146
|
+
!objectValue ||
|
|
147
|
+
!Array.isArray(objectValue['dashArray']) ||
|
|
148
|
+
objectValue['dashArray'].length === 0 ||
|
|
149
|
+
!['round', 'butt', 'square'].includes(String(objectValue['lineCap']))
|
|
150
|
+
)
|
|
151
|
+
addIssue(issues, path, 'strokeStyle must be a named style or dash array');
|
|
152
|
+
else
|
|
153
|
+
objectValue['dashArray'].forEach((entry, index) => {
|
|
154
|
+
validateValue('dimension', entry, `${path}.dashArray.${index}`, issues);
|
|
155
|
+
if (isObject(entry) && typeof entry['value'] === 'number' && entry['value'] < 0)
|
|
156
|
+
addIssue(issues, `${path}.dashArray.${index}`, 'stroke dash length must be non-negative');
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function validateShadow(
|
|
161
|
+
value: unknown,
|
|
162
|
+
objectValue: JsonObject | undefined,
|
|
163
|
+
path: string,
|
|
164
|
+
issues: ValidationIssue[],
|
|
165
|
+
): void {
|
|
166
|
+
if ((!objectValue && !Array.isArray(value)) || (Array.isArray(value) && value.length === 0))
|
|
167
|
+
addIssue(issues, path, 'shadow must be a shadow object or array');
|
|
168
|
+
else {
|
|
169
|
+
const shadows = Array.isArray(value) ? value : [objectValue];
|
|
170
|
+
for (const [index, shadow] of shadows.entries()) {
|
|
171
|
+
if (!isObject(shadow)) {
|
|
172
|
+
addIssue(issues, `${path}.${index}`, 'shadow must be an object');
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
validateCompositeMembers(
|
|
176
|
+
shadow,
|
|
177
|
+
{
|
|
178
|
+
color: 'color',
|
|
179
|
+
offsetX: 'dimension',
|
|
180
|
+
offsetY: 'dimension',
|
|
181
|
+
blur: 'dimension',
|
|
182
|
+
spread: 'dimension',
|
|
183
|
+
},
|
|
184
|
+
Array.isArray(value) ? `${path}.${index}` : path,
|
|
185
|
+
issues,
|
|
186
|
+
new Set(['inset']),
|
|
187
|
+
);
|
|
188
|
+
const blur = shadow['blur'];
|
|
189
|
+
if (isObject(blur) && typeof blur['value'] === 'number' && blur['value'] < 0)
|
|
190
|
+
addIssue(
|
|
191
|
+
issues,
|
|
192
|
+
`${Array.isArray(value) ? `${path}.${index}` : path}.blur`,
|
|
193
|
+
'shadow blur must be non-negative',
|
|
194
|
+
);
|
|
195
|
+
if (
|
|
196
|
+
shadow['inset'] !== undefined &&
|
|
197
|
+
typeof shadow['inset'] !== 'boolean' &&
|
|
198
|
+
!isReference(shadow['inset'])
|
|
199
|
+
)
|
|
200
|
+
addIssue(
|
|
201
|
+
issues,
|
|
202
|
+
`${Array.isArray(value) ? `${path}.${index}` : path}.inset`,
|
|
203
|
+
'inset must be boolean',
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function validateGradient(value: unknown, path: string, issues: ValidationIssue[]): void {
|
|
210
|
+
if (!Array.isArray(value) || value.length < 2)
|
|
211
|
+
addIssue(issues, path, 'gradient must contain at least two color-position stops');
|
|
212
|
+
else {
|
|
213
|
+
let previousPosition: number | undefined;
|
|
214
|
+
for (const [index, stop] of value.entries()) {
|
|
215
|
+
if (!isObject(stop)) {
|
|
216
|
+
addIssue(issues, `${path}.${index}`, 'gradient stop must be an object');
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
validateCompositeMembers(
|
|
220
|
+
stop,
|
|
221
|
+
{ color: 'color', position: 'number' },
|
|
222
|
+
`${path}.${index}`,
|
|
223
|
+
issues,
|
|
224
|
+
);
|
|
225
|
+
if (typeof stop['position'] === 'number' && (stop['position'] < 0 || stop['position'] > 1))
|
|
226
|
+
addIssue(issues, `${path}.${index}.position`, 'gradient position must be within [0, 1]');
|
|
227
|
+
if (
|
|
228
|
+
typeof stop['position'] === 'number' &&
|
|
229
|
+
previousPosition !== undefined &&
|
|
230
|
+
stop['position'] < previousPosition
|
|
231
|
+
)
|
|
232
|
+
addIssue(issues, `${path}.${index}.position`, 'gradient positions must be nondecreasing');
|
|
233
|
+
if (typeof stop['position'] === 'number') previousPosition = stop['position'];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function validateTypography(
|
|
239
|
+
objectValue: JsonObject | undefined,
|
|
240
|
+
path: string,
|
|
241
|
+
issues: ValidationIssue[],
|
|
242
|
+
): void {
|
|
243
|
+
if (!objectValue) addIssue(issues, path, 'typography must contain all five composite properties');
|
|
244
|
+
else {
|
|
245
|
+
validateCompositeMembers(
|
|
246
|
+
objectValue,
|
|
247
|
+
{
|
|
248
|
+
fontFamily: 'fontFamily',
|
|
249
|
+
fontSize: 'dimension',
|
|
250
|
+
fontWeight: 'fontWeight',
|
|
251
|
+
letterSpacing: 'dimension',
|
|
252
|
+
},
|
|
253
|
+
path,
|
|
254
|
+
issues,
|
|
255
|
+
new Set(['lineHeight']),
|
|
256
|
+
);
|
|
257
|
+
if (!('lineHeight' in objectValue))
|
|
258
|
+
addIssue(issues, path, 'composite value must include lineHeight');
|
|
259
|
+
else if (typeof objectValue['lineHeight'] !== 'number')
|
|
260
|
+
validateValue('dimension', objectValue['lineHeight'], `${path}.lineHeight`, issues);
|
|
261
|
+
if (
|
|
262
|
+
(typeof objectValue['lineHeight'] === 'number' && objectValue['lineHeight'] < 0) ||
|
|
263
|
+
(isObject(objectValue['lineHeight']) &&
|
|
264
|
+
typeof objectValue['lineHeight']['value'] === 'number' &&
|
|
265
|
+
objectValue['lineHeight']['value'] < 0)
|
|
266
|
+
)
|
|
267
|
+
addIssue(issues, `${path}.lineHeight`, 'typography lineHeight must be non-negative');
|
|
268
|
+
if (
|
|
269
|
+
isObject(objectValue['fontSize']) &&
|
|
270
|
+
typeof objectValue['fontSize']['value'] === 'number' &&
|
|
271
|
+
objectValue['fontSize']['value'] < 0
|
|
272
|
+
)
|
|
273
|
+
addIssue(issues, `${path}.fontSize`, 'typography fontSize must be non-negative');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function validateValue(
|
|
278
|
+
type: TokenType,
|
|
279
|
+
value: unknown,
|
|
280
|
+
path: string,
|
|
281
|
+
issues: ValidationIssue[],
|
|
282
|
+
): void {
|
|
283
|
+
if (isReference(value)) return;
|
|
284
|
+
const objectValue: JsonObject | undefined = isObject(value) ? value : undefined;
|
|
285
|
+
switch (type) {
|
|
286
|
+
case 'color':
|
|
287
|
+
validateColor(objectValue, path, issues);
|
|
288
|
+
return;
|
|
289
|
+
case 'dimension':
|
|
290
|
+
if (
|
|
291
|
+
!objectValue ||
|
|
292
|
+
typeof objectValue['value'] !== 'number' ||
|
|
293
|
+
!['px', 'rem'].includes(String(objectValue['unit']))
|
|
294
|
+
)
|
|
295
|
+
addIssue(issues, path, 'dimension must have a numeric value and px or rem unit');
|
|
296
|
+
else
|
|
297
|
+
for (const name of Object.keys(objectValue))
|
|
298
|
+
if (!DIMENSION_MEMBERS.has(name))
|
|
299
|
+
addIssue(issues, path, `unknown dimension member ${name}`);
|
|
300
|
+
return;
|
|
301
|
+
case 'duration':
|
|
302
|
+
if (
|
|
303
|
+
!objectValue ||
|
|
304
|
+
typeof objectValue['value'] !== 'number' ||
|
|
305
|
+
objectValue['value'] < 0 ||
|
|
306
|
+
!['ms', 's'].includes(String(objectValue['unit']))
|
|
307
|
+
)
|
|
308
|
+
addIssue(issues, path, 'duration must have a non-negative numeric value and ms or s unit');
|
|
309
|
+
else
|
|
310
|
+
for (const name of Object.keys(objectValue))
|
|
311
|
+
if (!DIMENSION_MEMBERS.has(name))
|
|
312
|
+
addIssue(issues, path, `unknown duration member ${name}`);
|
|
313
|
+
return;
|
|
314
|
+
case 'fontFamily':
|
|
315
|
+
if (!(
|
|
316
|
+
typeof value === 'string' ||
|
|
317
|
+
(Array.isArray(value) &&
|
|
318
|
+
value.length > 0 &&
|
|
319
|
+
value.every((entry) => typeof entry === 'string'))
|
|
320
|
+
))
|
|
321
|
+
addIssue(issues, path, 'fontFamily must be a string or string array');
|
|
322
|
+
return;
|
|
323
|
+
case 'fontWeight':
|
|
324
|
+
if (
|
|
325
|
+
!(typeof value === 'number' && value >= 1 && value <= 1000) &&
|
|
326
|
+
![
|
|
327
|
+
'thin',
|
|
328
|
+
'extra-light',
|
|
329
|
+
'light',
|
|
330
|
+
'normal',
|
|
331
|
+
'medium',
|
|
332
|
+
'semi-bold',
|
|
333
|
+
'bold',
|
|
334
|
+
'extra-bold',
|
|
335
|
+
'black',
|
|
336
|
+
'extra-black',
|
|
337
|
+
].includes(String(value))
|
|
338
|
+
)
|
|
339
|
+
addIssue(issues, path, 'fontWeight must be within [1, 1000] or a named weight');
|
|
340
|
+
return;
|
|
341
|
+
case 'number':
|
|
342
|
+
if (typeof value !== 'number') addIssue(issues, path, `${type} must be numeric`);
|
|
343
|
+
return;
|
|
344
|
+
case 'cubicBezier':
|
|
345
|
+
if (!isCubicBezier(value) || value[0] < 0 || value[0] > 1 || value[2] < 0 || value[2] > 1)
|
|
346
|
+
addIssue(issues, path, 'cubicBezier must be four numbers with x coordinates in [0, 1]');
|
|
347
|
+
return;
|
|
348
|
+
case 'strokeStyle':
|
|
349
|
+
validateStrokeStyle(value, objectValue, path, issues);
|
|
350
|
+
return;
|
|
351
|
+
case 'border':
|
|
352
|
+
if (!objectValue) addIssue(issues, path, 'border must include color, width, and style');
|
|
353
|
+
else
|
|
354
|
+
validateCompositeMembers(
|
|
355
|
+
objectValue,
|
|
356
|
+
{ color: 'color', width: 'dimension', style: 'strokeStyle' },
|
|
357
|
+
path,
|
|
358
|
+
issues,
|
|
359
|
+
);
|
|
360
|
+
if (
|
|
361
|
+
isObject(objectValue?.['width']) &&
|
|
362
|
+
typeof objectValue['width']['value'] === 'number' &&
|
|
363
|
+
objectValue['width']['value'] < 0
|
|
364
|
+
)
|
|
365
|
+
addIssue(issues, `${path}.width`, 'border width must be non-negative');
|
|
366
|
+
return;
|
|
367
|
+
case 'transition':
|
|
368
|
+
if (!objectValue)
|
|
369
|
+
addIssue(issues, path, 'transition must include duration, delay, and timingFunction');
|
|
370
|
+
else
|
|
371
|
+
validateCompositeMembers(
|
|
372
|
+
objectValue,
|
|
373
|
+
{ duration: 'duration', delay: 'duration', timingFunction: 'cubicBezier' },
|
|
374
|
+
path,
|
|
375
|
+
issues,
|
|
376
|
+
);
|
|
377
|
+
return;
|
|
378
|
+
case 'shadow':
|
|
379
|
+
validateShadow(value, objectValue, path, issues);
|
|
380
|
+
return;
|
|
381
|
+
case 'gradient':
|
|
382
|
+
validateGradient(value, path, issues);
|
|
383
|
+
return;
|
|
384
|
+
case 'typography':
|
|
385
|
+
validateTypography(objectValue, path, issues);
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function isString(value: unknown): value is string {
|
|
391
|
+
return typeof value === 'string';
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export function isTokenType(value: unknown): value is TokenType {
|
|
395
|
+
return typeof value === 'string' && TOKEN_TYPE_SET.has(value);
|
|
396
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { ResolverDocument, TokenDocument, ValidationIssue } from './types.ts';
|
|
2
|
+
import { TokenValidationError } from './types.ts';
|
|
3
|
+
import { validateResolverDocument } from './validate-resolver.ts';
|
|
4
|
+
import { validateResolverDocumentSchema, validateTokenDocumentSchema } from './validate-schema.ts';
|
|
5
|
+
import { validateTokenDocument } from './validate-tokens.ts';
|
|
6
|
+
import { addIssue, isObject } from './validate-values.ts';
|
|
7
|
+
|
|
8
|
+
export function assertValidTokenDocument(
|
|
9
|
+
document: unknown,
|
|
10
|
+
source?: string,
|
|
11
|
+
lookupDocuments: readonly unknown[] = [],
|
|
12
|
+
sourceByDocument?: ReadonlyMap<object, string>,
|
|
13
|
+
): asserts document is TokenDocument {
|
|
14
|
+
const issues: ValidationIssue[] = [];
|
|
15
|
+
if (!isObject(document)) addIssue(issues, source ?? '$', 'document must be an object');
|
|
16
|
+
if (issues.length > 0) throw new TokenValidationError(issues);
|
|
17
|
+
// First-pass gate: the official DTCG 2025.10 format JSON Schema catches shape
|
|
18
|
+
// violations structurally, before the semantic checks below run. See
|
|
19
|
+
// validate-schema.ts for why this precedes (rather than replaces) validateTokenDocument.
|
|
20
|
+
const projected = validateTokenDocumentSchema(
|
|
21
|
+
document,
|
|
22
|
+
source ?? '$',
|
|
23
|
+
lookupDocuments,
|
|
24
|
+
sourceByDocument,
|
|
25
|
+
);
|
|
26
|
+
validateTokenDocument(projected, source);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function assertValidResolverDocument(
|
|
30
|
+
document: unknown,
|
|
31
|
+
): asserts document is ResolverDocument {
|
|
32
|
+
if (!isObject(document))
|
|
33
|
+
throw new TokenValidationError([{ path: '$', reason: 'resolver must be an object' }]);
|
|
34
|
+
// First-pass gate: the official DTCG 2025.10 resolver JSON Schema catches
|
|
35
|
+
// shape violations structurally, before the semantic checks below run
|
|
36
|
+
// (see validate-schema.ts for why validateResolverDocumentSchema exists
|
|
37
|
+
// as a separate, explicitly-called step rather than being folded in here).
|
|
38
|
+
validateResolverDocumentSchema(document);
|
|
39
|
+
if (
|
|
40
|
+
document['version'] !== '2025.10' ||
|
|
41
|
+
!isObject(document['sets']) ||
|
|
42
|
+
!isObject(document['modifiers']) ||
|
|
43
|
+
!Array.isArray(document['resolutionOrder'])
|
|
44
|
+
)
|
|
45
|
+
throw new TokenValidationError([
|
|
46
|
+
{
|
|
47
|
+
path: '$',
|
|
48
|
+
reason: 'resolver must contain version, sets, modifiers, and resolutionOrder',
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
51
|
+
validateResolverDocument({
|
|
52
|
+
version: document['version'],
|
|
53
|
+
sets: document['sets'],
|
|
54
|
+
modifiers: document['modifiers'],
|
|
55
|
+
resolutionOrder: document['resolutionOrder'],
|
|
56
|
+
});
|
|
57
|
+
}
|