@lostgradient/cinder 0.27.1 → 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.
Files changed (261) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/components.json +1 -1
  3. package/dist/_internal/code-highlighter-context.d.ts +28 -0
  4. package/dist/cli/index.js +12 -8
  5. package/dist/components/approval-card/index.js +4 -4
  6. package/dist/components/button/button.css +25 -0
  7. package/dist/components/calendar/calendar.css +14 -0
  8. package/dist/components/capability-gate/capability-gate.css +5 -0
  9. package/dist/components/checkbox/checkbox.css +19 -0
  10. package/dist/components/chip/chip.css +14 -0
  11. package/dist/components/code-block/code-block.d.svelte.ts +1 -1
  12. package/dist/components/code-block/code-block.examples.json +1 -1
  13. package/dist/components/code-block/code-block.schema.js +3 -3
  14. package/dist/components/code-block/code-block.svelte.d.ts +1 -1
  15. package/dist/components/code-block/code-block.types.d.ts +14 -12
  16. package/dist/components/code-block/index.js +2 -2
  17. package/dist/components/color-picker/color-picker.css +2 -0
  18. package/dist/components/combobox/combobox.css +9 -1
  19. package/dist/components/command-palette/command-palette.css +7 -5
  20. package/dist/components/file-upload/file-upload.css +2 -1
  21. package/dist/components/guidance-region/index.css +1 -1
  22. package/dist/components/image/image.examples.json +1 -1
  23. package/dist/components/input/input.css +20 -6
  24. package/dist/components/json-schema-editor/index.js +5 -5
  25. package/dist/components/json-schema-editor/json-view-highlighter.d.ts +14 -0
  26. package/dist/components/key-value-editor/index.css +1 -1
  27. package/dist/components/modal-region/index.css +1 -1
  28. package/dist/components/multi-select/multi-select.css +9 -0
  29. package/dist/components/pagination/pagination.css +12 -0
  30. package/dist/components/pin-input/pin-input.css +9 -1
  31. package/dist/components/radio-group/radio-group.css +16 -0
  32. package/dist/components/run-step-timeline/index.js +2 -2
  33. package/dist/components/schema-form/index.js +2 -2
  34. package/dist/components/schema-form/schema-form.css +9 -0
  35. package/dist/components/segmented-control/segmented-control.css +3 -3
  36. package/dist/components/selection-popover/selection-popover.css +7 -1
  37. package/dist/components/tag-input/tag-input.css +10 -1
  38. package/dist/components/terminal-frame/index.js +2 -2
  39. package/dist/components/terminal-frame/terminal-frame.schema.js +2 -2
  40. package/dist/components/terminal-frame/terminal-frame.types.d.ts +8 -0
  41. package/dist/components/textarea/textarea.css +1 -1
  42. package/dist/components/toggle/toggle.css +16 -0
  43. package/dist/components/tree/tree.examples.json +1 -1
  44. package/dist/components/virtual-list/index.js +2 -2
  45. package/dist/components/virtual-list/virtual-list.css +42 -9
  46. package/dist/highlighters/shiki/default.d.ts +13 -1
  47. package/dist/highlighters/shiki/default.js +2 -2
  48. package/dist/highlighters/shiki/index.d.ts +20 -12
  49. package/dist/highlighters/shiki/index.js +2 -2
  50. package/dist/index.browser.css +1 -1
  51. package/dist/index.d.ts +2 -0
  52. package/dist/index.js +23 -23
  53. package/dist/scripts/knowledge/index.d.ts +5 -1
  54. package/dist/server/components/approval-card/index.js +1 -1
  55. package/dist/server/components/code-block/index.js +1 -1
  56. package/dist/server/components/color-field/index.js +2 -2
  57. package/dist/server/components/color-picker/index.js +2 -2
  58. package/dist/server/components/json-schema-editor/index.js +2 -2
  59. package/dist/server/components/run-step-timeline/index.js +1 -1
  60. package/dist/server/components/terminal-frame/index.js +1 -1
  61. package/dist/server/components/virtual-list/index.js +1 -1
  62. package/dist/server/github-dark-e7nywpbe.js +3 -0
  63. package/dist/server/github-light-bqtmm1zq.js +3 -0
  64. package/dist/server/highlighters/shiki/default.js +2 -2
  65. package/dist/server/highlighters/shiki/index.js +2 -2
  66. package/dist/server/index.js +6 -6
  67. package/dist/server/{index.server-4qyyw4y5.js → index.server-043cfznf.js} +1 -1
  68. package/dist/server/{index.server-p46tn4eb.js → index.server-09tjs48p.js} +2 -2
  69. package/dist/server/index.server-0hyvdf74.js +8 -0
  70. package/dist/server/{index.server-dxgkh9tk.js → index.server-17thvpd3.js} +1 -1
  71. package/dist/server/index.server-19z6hqd6.js +4 -0
  72. package/dist/server/index.server-31020qgk.js +3 -0
  73. package/dist/server/{index.server-w3nqzde5.js → index.server-45wmvjrn.js} +3 -3
  74. package/dist/server/{index.server-3tkgm2gn.js → index.server-6mb7w5g4.js} +2 -2
  75. package/dist/server/{index.server-2vxmn7x1.js → index.server-c5yajkkc.js} +4 -4
  76. package/dist/server/index.server-e6fknxd9.js +4 -0
  77. package/dist/server/index.server-fev4kwm0.js +4 -0
  78. package/dist/server/index.server-k4vjk75r.js +4 -0
  79. package/dist/server/index.server-mjbtd1gs.js +7 -0
  80. package/dist/server/{index.server-2bfkhzzq.js → index.server-rkp4py5n.js} +2 -2
  81. package/dist/server/index.server-wdz9tsq4.js +3 -0
  82. package/dist/server/index.server-zj9909hd.js +4 -0
  83. package/dist/server/json-68twtta3.js +3 -0
  84. package/dist/server/tokens/registry.generated.js +1 -1
  85. package/dist/server/tokens/runtime/index.js +92 -0
  86. package/dist/styles/check-token-contrast-test-values.d.ts +1 -3
  87. package/dist/styles/token-contrast-test-readers.d.ts +1 -1
  88. package/dist/tokens/registry.generated.js +2 -2
  89. package/dist/tokens/resolved/dark-reduced-motion.json +104 -43
  90. package/dist/tokens/resolved/dark.json +104 -43
  91. package/dist/tokens/resolved/light-reduced-motion.json +104 -43
  92. package/dist/tokens/resolved/light.json +104 -43
  93. package/dist/tokens/runtime/authoring-catalogue.d.ts +19 -0
  94. package/dist/tokens/runtime/authoring-catalogue.generated.d.ts +8 -0
  95. package/dist/tokens/runtime/authoring-palette.d.ts +25 -0
  96. package/dist/tokens/runtime/authoring-profiles.d.ts +48 -0
  97. package/dist/tokens/runtime/authoring-provenance.d.ts +31 -0
  98. package/dist/tokens/runtime/authoring-types.d.ts +182 -0
  99. package/dist/tokens/runtime/base-corpus.d.ts +29 -0
  100. package/dist/tokens/runtime/base-corpus.generated.d.ts +8 -0
  101. package/dist/tokens/runtime/context-order.d.ts +60 -0
  102. package/dist/tokens/runtime/context-stack.d.ts +11 -0
  103. package/dist/tokens/runtime/contrast/color-difference.d.ts +16 -0
  104. package/dist/{styles/color-contrast-utilities.d.ts → tokens/runtime/contrast/color-math.d.ts} +2 -17
  105. package/dist/tokens/runtime/contrast/color-mix.d.ts +3 -0
  106. package/dist/tokens/runtime/contrast/css-color.d.ts +29 -0
  107. package/dist/tokens/runtime/contrast/index.d.ts +7 -0
  108. package/dist/tokens/runtime/contrast/measure.d.ts +45 -0
  109. package/dist/tokens/runtime/contrast/pairings.d.ts +36 -0
  110. package/dist/tokens/runtime/contrast/thresholds.d.ts +47 -0
  111. package/dist/tokens/runtime/corpus-documents.d.ts +36 -0
  112. package/dist/tokens/runtime/corpus-validation.d.ts +10 -0
  113. package/dist/tokens/runtime/corpus.d.ts +35 -0
  114. package/dist/tokens/runtime/css-configuration.d.ts +1 -0
  115. package/dist/tokens/runtime/css-stylelint.d.ts +2 -0
  116. package/dist/tokens/runtime/css-support.d.ts +110 -0
  117. package/dist/tokens/runtime/evaluate.d.ts +95 -0
  118. package/dist/tokens/runtime/evaluated-provenance.d.ts +36 -0
  119. package/dist/tokens/runtime/index.d.ts +38 -0
  120. package/dist/tokens/runtime/index.js +95 -0
  121. package/dist/tokens/runtime/package-version.generated.d.ts +9 -0
  122. package/dist/tokens/runtime/projection.d.ts +32 -0
  123. package/dist/tokens/runtime/registry.d.ts +125 -0
  124. package/dist/tokens/runtime/resolve-extends.d.ts +30 -0
  125. package/dist/tokens/runtime/resolve-references.d.ts +49 -0
  126. package/dist/tokens/runtime/resolve-shared.d.ts +34 -0
  127. package/dist/tokens/runtime/resolve.d.ts +44 -0
  128. package/dist/tokens/runtime/resolver-order.d.ts +89 -0
  129. package/dist/tokens/runtime/source-digest.d.ts +20 -0
  130. package/dist/tokens/runtime/stylesheet-skeleton.d.ts +31 -0
  131. package/dist/tokens/runtime/theme-runtime.test-support.d.ts +24 -0
  132. package/dist/tokens/runtime/theme-sources.d.ts +46 -0
  133. package/dist/tokens/runtime/theme-stylesheet.d.ts +31 -0
  134. package/dist/tokens/runtime/types.d.ts +115 -0
  135. package/dist/tokens/runtime/validate-resolver.d.ts +31 -0
  136. package/dist/tokens/runtime/validate-schema.d.ts +22 -0
  137. package/dist/tokens/runtime/validate-tokens.d.ts +25 -0
  138. package/dist/tokens/runtime/validate-values.d.ts +33 -0
  139. package/dist/tokens/runtime/validate.d.ts +3 -0
  140. package/dist/tokens/runtime/value-color-parse.d.ts +128 -0
  141. package/dist/tokens/runtime/value-color.d.ts +85 -0
  142. package/dist/tokens/runtime/value-entry.d.ts +3 -0
  143. package/dist/tokens/runtime/value-formatters.d.ts +59 -0
  144. package/dist/tokens/sets/colors.tokens.json +65 -13
  145. package/dist/tokens/sets/foundation.tokens.json +23 -0
  146. package/dist/tokens/sets/semantic.tokens.json +136 -30
  147. package/dist/utilities/highlighter.d.ts +5 -5
  148. package/dist/utilities/retrying-loader-cache.d.ts +3 -6
  149. package/package.json +15 -3
  150. package/src/_internal/code-highlighter-context.ts +41 -0
  151. package/src/components/button/button.css +25 -0
  152. package/src/components/calendar/calendar.css +14 -0
  153. package/src/components/capability-gate/capability-gate.css +5 -0
  154. package/src/components/checkbox/checkbox.css +19 -0
  155. package/src/components/chip/chip.css +14 -0
  156. package/src/components/code-block/code-block.examples.json +1 -1
  157. package/src/components/code-block/code-block.schema.json +2 -2
  158. package/src/components/code-block/code-block.schema.ts +2 -2
  159. package/src/components/code-block/code-block.svelte +15 -19
  160. package/src/components/code-block/code-block.types.ts +14 -12
  161. package/src/components/color-picker/color-picker.css +2 -0
  162. package/src/components/combobox/combobox.css +9 -1
  163. package/src/components/command-palette/command-palette.css +7 -5
  164. package/src/components/file-upload/file-upload.css +2 -1
  165. package/src/components/image/image.examples.json +1 -1
  166. package/src/components/input/input.css +20 -6
  167. package/src/components/json-schema-editor/json-view-highlighter.ts +23 -0
  168. package/src/components/json-schema-editor/json-view.svelte +2 -0
  169. package/src/components/multi-select/multi-select.css +9 -0
  170. package/src/components/pagination/pagination.css +12 -0
  171. package/src/components/pin-input/pin-input.css +9 -1
  172. package/src/components/radio-group/radio-group.css +16 -0
  173. package/src/components/schema-form/schema-form.css +9 -0
  174. package/src/components/segmented-control/segmented-control.css +3 -3
  175. package/src/components/selection-popover/selection-popover.css +7 -1
  176. package/src/components/tag-input/tag-input.css +10 -1
  177. package/src/components/terminal-frame/terminal-frame.schema.json +5 -0
  178. package/src/components/terminal-frame/terminal-frame.schema.ts +6 -0
  179. package/src/components/terminal-frame/terminal-frame.svelte +6 -2
  180. package/src/components/terminal-frame/terminal-frame.types.ts +8 -0
  181. package/src/components/textarea/textarea.css +1 -1
  182. package/src/components/toggle/toggle.css +16 -0
  183. package/src/components/tree/tree.examples.json +1 -1
  184. package/src/components/virtual-list/virtual-list.css +42 -9
  185. package/src/components/virtual-list/virtual-list.svelte +54 -20
  186. package/src/highlighters/shiki/default.ts +13 -1
  187. package/src/highlighters/shiki/index.ts +20 -12
  188. package/src/index.ts +5 -0
  189. package/src/styles/foundation.css +33 -1
  190. package/src/styles/tokens-base.css +4 -4
  191. package/src/tokens/registry.generated.json +3 -3
  192. package/src/tokens/resolved/dark-reduced-motion.json +104 -43
  193. package/src/tokens/resolved/dark.json +104 -43
  194. package/src/tokens/resolved/light-reduced-motion.json +104 -43
  195. package/src/tokens/resolved/light.json +104 -43
  196. package/src/tokens/runtime/authoring-catalogue.generated.ts +19300 -0
  197. package/src/tokens/runtime/authoring-catalogue.ts +256 -0
  198. package/src/tokens/runtime/authoring-palette.ts +100 -0
  199. package/src/tokens/runtime/authoring-profiles.ts +288 -0
  200. package/src/tokens/runtime/authoring-provenance.ts +290 -0
  201. package/src/tokens/runtime/authoring-types.ts +199 -0
  202. package/src/tokens/runtime/base-corpus.generated.ts +10 -0
  203. package/src/tokens/runtime/base-corpus.ts +78 -0
  204. package/src/tokens/runtime/context-order.ts +182 -0
  205. package/src/tokens/runtime/context-stack.ts +52 -0
  206. package/src/tokens/runtime/contrast/color-difference.ts +114 -0
  207. package/src/tokens/runtime/contrast/color-math.ts +89 -0
  208. package/src/tokens/runtime/contrast/color-mix.ts +20 -0
  209. package/src/tokens/runtime/contrast/css-color.ts +312 -0
  210. package/src/tokens/runtime/contrast/index.ts +7 -0
  211. package/src/tokens/runtime/contrast/measure.ts +185 -0
  212. package/src/tokens/runtime/contrast/pairings.ts +324 -0
  213. package/src/tokens/runtime/contrast/thresholds.ts +81 -0
  214. package/src/tokens/runtime/corpus-documents.ts +289 -0
  215. package/src/tokens/runtime/corpus-validation.ts +336 -0
  216. package/src/tokens/runtime/corpus.ts +179 -0
  217. package/src/tokens/runtime/css-configuration.ts +1 -0
  218. package/src/tokens/runtime/css-stylelint.ts +15 -0
  219. package/src/tokens/runtime/css-support.ts +407 -0
  220. package/src/tokens/runtime/evaluate.ts +262 -0
  221. package/src/tokens/runtime/evaluated-provenance.ts +116 -0
  222. package/src/tokens/runtime/format-validator.generated.d.ts +18 -0
  223. package/src/tokens/runtime/format-validator.generated.js +13029 -0
  224. package/src/tokens/runtime/index.ts +78 -0
  225. package/src/tokens/runtime/package-version.generated.ts +9 -0
  226. package/src/tokens/runtime/projection.ts +65 -0
  227. package/src/tokens/runtime/registry.ts +365 -0
  228. package/src/tokens/runtime/resolve-extends.ts +211 -0
  229. package/src/tokens/runtime/resolve-references.ts +313 -0
  230. package/src/tokens/runtime/resolve-shared.ts +186 -0
  231. package/src/tokens/runtime/resolve.ts +246 -0
  232. package/src/tokens/runtime/resolver-order.ts +326 -0
  233. package/src/tokens/runtime/resolver-validator.generated.d.ts +18 -0
  234. package/src/tokens/runtime/resolver-validator.generated.js +15492 -0
  235. package/src/tokens/runtime/source-digest.ts +49 -0
  236. package/src/tokens/runtime/stylesheet-skeleton.ts +123 -0
  237. package/src/tokens/runtime/theme-sources.ts +121 -0
  238. package/src/tokens/runtime/theme-stylesheet.ts +177 -0
  239. package/src/tokens/runtime/types.ts +140 -0
  240. package/src/tokens/runtime/validate-resolver.ts +338 -0
  241. package/src/tokens/runtime/validate-schema.ts +269 -0
  242. package/src/tokens/runtime/validate-tokens.ts +181 -0
  243. package/src/tokens/runtime/validate-values.ts +396 -0
  244. package/src/tokens/runtime/validate.ts +57 -0
  245. package/src/tokens/runtime/value-color-parse.ts +309 -0
  246. package/src/tokens/runtime/value-color.ts +217 -0
  247. package/src/tokens/runtime/value-entry.ts +52 -0
  248. package/src/tokens/runtime/value-formatters.ts +414 -0
  249. package/src/tokens/sets/colors.tokens.json +65 -13
  250. package/src/tokens/sets/foundation.tokens.json +23 -0
  251. package/src/tokens/sets/semantic.tokens.json +136 -30
  252. package/src/utilities/highlighter.ts +5 -5
  253. package/src/utilities/retrying-loader-cache.ts +3 -6
  254. package/dist/components/code-block/code-block-default-highlighter.d.ts +0 -40
  255. package/dist/server/index.server-298z43yn.js +0 -4
  256. package/dist/server/index.server-3h11wjyh.js +0 -8
  257. package/dist/server/index.server-a3aerbfr.js +0 -4
  258. package/dist/server/index.server-kge3zp6n.js +0 -4
  259. package/dist/server/index.server-syf81nwz.js +0 -6
  260. package/dist/server/index.server-zs08f5te.js +0 -3
  261. package/src/components/code-block/code-block-default-highlighter.ts +0 -63
@@ -0,0 +1,326 @@
1
+ import { TokenValidationError, type ResolverDocument, type ResolverReference } from './types.ts';
2
+ import { resolutionOrderTarget } from './validate-resolver.ts';
3
+
4
+ /**
5
+ * `path.posix.normalize` without the Node dependency: collapses `.`, empty, and
6
+ * `..` segments, and keeps a leading `/` or unresolvable leading `..` segments.
7
+ */
8
+ function normalizePosixPath(path: string): string {
9
+ if (path === '') return '.';
10
+ const absolute = path.startsWith('/');
11
+ const trailing = path.endsWith('/');
12
+ const segments: string[] = [];
13
+ for (const segment of path.split('/')) {
14
+ if (segment === '' || segment === '.') continue;
15
+ if (segment === '..') {
16
+ if (segments.length > 0 && segments.at(-1) !== '..') segments.pop();
17
+ else if (!absolute) segments.push('..');
18
+ } else segments.push(segment);
19
+ }
20
+ let normalized = segments.join('/');
21
+ if (normalized === '' && !absolute) normalized = '.';
22
+ if (normalized !== '' && trailing) normalized += '/';
23
+ return absolute ? `/${normalized}` : normalized;
24
+ }
25
+
26
+ /**
27
+ * Normalizes a source `$ref` into the repository-relative form `loadTokenDocuments`
28
+ * reports. The resolver schema types these as URI references, so `./sets/x.tokens.json`
29
+ * and `sets/x.tokens.json` name the same file; comparing the raw strings against
30
+ * globbed paths would report a file that exists as missing. Percent-escapes are
31
+ * decoded for the same reason, and a malformed escape is left as-is so the failure
32
+ * surfaces as a clear "source does not exist" rather than a decoding crash --
33
+ * ajv's `uri-reference` format catches genuinely malformed references upstream.
34
+ */
35
+ export function normalizeSourcePath(reference: string): string {
36
+ let decoded = reference;
37
+ try {
38
+ decoded = decodeURIComponent(reference);
39
+ } catch {
40
+ // Leave the reference undecoded; the existence check reports it.
41
+ }
42
+ return normalizePosixPath(decoded).replace(/^\.\//, '');
43
+ }
44
+
45
+ export function normalizedDocumentsByPath<T>(documentsByPath: Map<string, T>): Map<string, T> {
46
+ const normalized = new Map<string, T>();
47
+ for (const [path, document] of documentsByPath) {
48
+ const normalizedPath = normalizeSourcePath(path);
49
+ if (normalized.has(normalizedPath))
50
+ throw new TokenValidationError([
51
+ {
52
+ path: '$',
53
+ reason: `duplicate loaded token document path after normalization: ${normalizedPath}`,
54
+ },
55
+ ]);
56
+ normalized.set(normalizedPath, document);
57
+ }
58
+ return normalized;
59
+ }
60
+
61
+ /**
62
+ * Whether a source `$ref` names a resolver-internal pointer (`#/sets/<name>`)
63
+ * rather than an on-disk document, decoding percent-escapes FIRST -- the same
64
+ * order `resolutionOrderTarget` in `validate.ts` already applies (RFC 6901 §6:
65
+ * percent-decode the whole fragment before structural parsing). A raw,
66
+ * undecoded `startsWith('#/')` check disagrees with that: a valid
67
+ * percent-encoded pointer such as `#%2Fsets%2Fbase` decodes to `#/sets/base`
68
+ * and is correctly recognized as internal by `resolutionOrderTarget`, but the
69
+ * SAME string does not literally start with `#/`, so an undecoded check here
70
+ * misclassified it as a filesystem reference and reported a nonexistent file
71
+ * named `#%2Fsets%2Fbase` instead of expanding the set.
72
+ */
73
+ export function isInternalReference(reference: string): boolean {
74
+ if (!reference.startsWith('#')) return false;
75
+ let decoded = reference;
76
+ try {
77
+ decoded = decodeURIComponent(reference);
78
+ } catch {
79
+ // Leave undecoded; a malformed escape simply fails the check below, the
80
+ // same way `resolutionOrderTarget` returns `undefined` for one.
81
+ }
82
+ return decoded.startsWith('#/');
83
+ }
84
+
85
+ export function internalSetNames(sources: ResolverReference[]): string[] {
86
+ return sources.flatMap((source) => {
87
+ if (!isInternalReference(source.$ref)) return [];
88
+ const target = resolutionOrderTarget(source.$ref);
89
+ return target?.kind === 'sets' ? [target.name] : [];
90
+ });
91
+ }
92
+
93
+ export function reachableSetNames(resolver: ResolverDocument, rootName: string): Set<string> {
94
+ const reachable = new Set<string>();
95
+ const visit = (setName: string): void => {
96
+ if (reachable.has(setName)) return;
97
+ reachable.add(setName);
98
+ const set = Object.hasOwn(resolver.sets, setName) ? resolver.sets[setName] : undefined;
99
+ if (!set) return;
100
+ for (const childName of internalSetNames(set.sources)) visit(childName);
101
+ };
102
+ visit(rootName);
103
+ return reachable;
104
+ }
105
+
106
+ /** Rejects a later modifier re-expanding a base set after another modifier already overrode it. */
107
+
108
+ export function expandSetSources(
109
+ resolver: ResolverDocument,
110
+ setName: string,
111
+ visiting: Set<string> = new Set(),
112
+ // The reference SITE reporting a missing/cyclic `setName` -- defaults to
113
+ // `$.sets.<setName>` for a top-level call (where `setName` genuinely is the
114
+ // site: `resolver.sets` is being looked up directly, not reached via
115
+ // another set's `sources`), but a recursive call passes the path of the
116
+ // `sources` array that named `setName`, so a missing/cyclic TARGET set is
117
+ // reported at the place that referenced it rather than at
118
+ // `$.sets.<missing>`, which does not exist in the document.
119
+ referencePath: string = `$.sets.${setName}`,
120
+ ): ResolverReference[] {
121
+ if (visiting.has(setName))
122
+ throw new TokenValidationError([
123
+ {
124
+ path: referencePath,
125
+ reason: `cyclic set reference: ${[...visiting, setName].join(' -> ')}`,
126
+ },
127
+ ]);
128
+ // `Object.hasOwn` first: resolver set names are unrestricted, and `sets` is
129
+ // a normal-prototype object, so an unknown name that happens to collide
130
+ // with an inherited `Object.prototype` property (`constructor`,
131
+ // `toString`, ...) would otherwise return that inherited value instead of
132
+ // `undefined`, skipping the intended "unknown set" error and throwing a
133
+ // raw, confusing `TypeError` from `set.sources.flatMap` below instead.
134
+ const set = Object.hasOwn(resolver.sets, setName) ? resolver.sets[setName] : undefined;
135
+ if (!set)
136
+ throw new TokenValidationError([
137
+ {
138
+ path: referencePath,
139
+ reason: `resolver-internal reference names an unknown set: ${setName}`,
140
+ },
141
+ ]);
142
+ visiting.add(setName);
143
+ const expanded = set.sources.flatMap((source) => {
144
+ if (!isInternalReference(source.$ref)) return [source];
145
+ const target = resolutionOrderTarget(source.$ref);
146
+ if (!target)
147
+ throw new TokenValidationError([
148
+ {
149
+ path: `$.sets.${setName}.sources`,
150
+ reason: `malformed resolver-internal reference: ${source.$ref}`,
151
+ },
152
+ ]);
153
+ if (target.kind === 'modifiers')
154
+ throw new TokenValidationError([
155
+ {
156
+ path: `$.sets.${setName}.sources`,
157
+ reason: `a set may not reference a modifier: ${source.$ref}`,
158
+ },
159
+ ]);
160
+ return expandSetSources(resolver, target.name, visiting, `$.sets.${setName}.sources`);
161
+ });
162
+ visiting.delete(setName);
163
+ return expanded;
164
+ }
165
+
166
+ /**
167
+ * Expands one modifier context's `sources` the same way {@link expandSetSources}
168
+ * expands a set's -- a context entry may reference a set (`#/sets/<name>`),
169
+ * expanded recursively via `expandSetSources`, but per the resolver schema's
170
+ * `referenceObjectForModifiers` prohibition, a modifier context may not
171
+ * reference another modifier.
172
+ */
173
+ export function expandContextSources(
174
+ resolver: ResolverDocument,
175
+ modifierName: string,
176
+ contextName: string,
177
+ ): ResolverReference[] {
178
+ // Same `Object.hasOwn` guard as `expandSetSources` above, for the same
179
+ // reason: an unknown modifier/context name colliding with an inherited
180
+ // `Object.prototype` property must not silently resolve to that inherited
181
+ // value.
182
+ const modifier = Object.hasOwn(resolver.modifiers, modifierName)
183
+ ? resolver.modifiers[modifierName]
184
+ : undefined;
185
+ const sources =
186
+ modifier && Object.hasOwn(modifier.contexts, contextName)
187
+ ? modifier.contexts[contextName]
188
+ : undefined;
189
+ if (!modifier || !sources)
190
+ throw new TokenValidationError([
191
+ {
192
+ path: `$.modifiers.${modifierName}`,
193
+ reason: `resolver-internal reference names an unknown modifier context: ${contextName}`,
194
+ },
195
+ ]);
196
+ return sources.flatMap((source) => {
197
+ if (!isInternalReference(source.$ref)) return [source];
198
+ const target = resolutionOrderTarget(source.$ref);
199
+ const contextPath = `$.modifiers.${modifierName}.contexts.${contextName}`;
200
+ if (!target)
201
+ throw new TokenValidationError([
202
+ { path: contextPath, reason: `malformed resolver-internal reference: ${source.$ref}` },
203
+ ]);
204
+ if (target.kind === 'modifiers')
205
+ throw new TokenValidationError([
206
+ {
207
+ path: contextPath,
208
+ reason: `a modifier context may not reference another modifier: ${source.$ref}`,
209
+ },
210
+ ]);
211
+ return expandSetSources(resolver, target.name, new Set(), contextPath);
212
+ });
213
+ }
214
+
215
+ /**
216
+ * Indexes expanded context sources by modifier name, then context name.
217
+ *
218
+ * Nesting two maps -- rather than concatenating both names into one string
219
+ * key -- keeps this collision-free: resolver modifier and context names are
220
+ * otherwise unrestricted, so e.g. modifier "a" context "b:c" and modifier
221
+ * "a:b" context "c" could concatenate to the same key under ANY fixed
222
+ * delimiter and silently overwrite each other, resolving the wrong document
223
+ * list for one of them. Two-level indexing has no such joint-key space to
224
+ * collide in.
225
+ */
226
+ export function buildContextSourcesIndex(
227
+ expandedContexts: ReadonlyArray<{
228
+ modifierName: string;
229
+ contextName: string;
230
+ sources: ResolverReference[];
231
+ }>,
232
+ ): Map<string, Map<string, ResolverReference[]>> {
233
+ const index = new Map<string, Map<string, ResolverReference[]>>();
234
+ for (const { modifierName, contextName, sources } of expandedContexts) {
235
+ const byContext = index.get(modifierName) ?? new Map();
236
+ byContext.set(contextName, sources);
237
+ index.set(modifierName, byContext);
238
+ }
239
+ return index;
240
+ }
241
+
242
+ export function validateExpandedSources(
243
+ expandedSets: ReadonlyArray<{ setName: string; sources: ResolverReference[] }>,
244
+ expandedContexts: ReadonlyArray<{
245
+ modifierName: string;
246
+ contextName: string;
247
+ sources: ResolverReference[];
248
+ }>,
249
+ documentsByPath: Map<string, unknown>,
250
+ ): void {
251
+ const knownPaths = new Set([...documentsByPath.keys()].map(normalizeSourcePath));
252
+ const missingSources = [
253
+ ...expandedSets.flatMap(({ setName, sources }) =>
254
+ sources
255
+ .filter((source) => !knownPaths.has(normalizeSourcePath(source.$ref)))
256
+ .map((source) => ({
257
+ path: `$.sets.${setName}.sources`,
258
+ reason: `source does not exist: ${source.$ref}`,
259
+ })),
260
+ ),
261
+ ...expandedContexts.flatMap(({ modifierName, contextName, sources }) =>
262
+ sources
263
+ .filter((source) => !knownPaths.has(normalizeSourcePath(source.$ref)))
264
+ .map((source) => ({
265
+ path: `$.modifiers.${modifierName}.contexts.${contextName}`,
266
+ reason: `source does not exist: ${source.$ref}`,
267
+ })),
268
+ ),
269
+ ];
270
+ if (missingSources.length > 0) throw new TokenValidationError(missingSources);
271
+ }
272
+
273
+ /**
274
+ * Returns the concrete ordered document scopes in which each source participates.
275
+ * `$extends` targets are resolved against these scopes only; unrelated sets and
276
+ * modifier contexts must not contribute projection metadata to one another.
277
+ */
278
+
279
+ export type ResolutionOrderEntry = { kind: 'sets' | 'modifiers'; name: string };
280
+
281
+ /**
282
+ * Parses every resolutionOrder `$ref` into its target kind and name, reusing
283
+ * validation's own parser so the two paths cannot drift. That matters for
284
+ * RFC 6901 tilde-escapes: a set named `a/b` is referenced as `#/sets/a~1b`,
285
+ * and decoding it here is what keeps the later `resolver.sets[name]` lookup
286
+ * in `sourcesForEntry` finding the entry that validation already accepted.
287
+ */
288
+ export function parseResolutionOrder(resolver: ResolverDocument): ResolutionOrderEntry[] {
289
+ return resolver.resolutionOrder.map((entry) => {
290
+ const target = resolutionOrderTarget(entry.$ref);
291
+ if (!target)
292
+ throw new Error(`resolutionOrder entry is not a well-formed pointer: ${entry.$ref}`);
293
+ return target;
294
+ });
295
+ }
296
+
297
+ /**
298
+ * The token sources a resolutionOrder entry contributes for one
299
+ * modifier-value combination, with any resolver-internal `#/sets/<name>`
300
+ * reference already expanded to the plain document `$ref`s it stands for --
301
+ * every caller (this validator, `generate.ts`, `registry.ts`) resolves the
302
+ * result straight into `documentsByPath` lookups with no expansion of its
303
+ * own.
304
+ */
305
+ export function sourcesForEntry(
306
+ resolver: ResolverDocument,
307
+ entry: ResolutionOrderEntry,
308
+ modifierValues: Record<string, string>,
309
+ ): ResolverReference[] {
310
+ if (entry.kind === 'sets') return expandSetSources(resolver, entry.name);
311
+ return expandContextSources(resolver, entry.name, modifierValues[entry.name]!);
312
+ }
313
+
314
+ /** Every combination of one context value per modifier, cartesian product across all modifiers. */
315
+ export function combinations(resolver: ResolverDocument): Array<Record<string, string>> {
316
+ return Object.entries(resolver.modifiers).reduce<Array<Record<string, string>>>(
317
+ (current, [name, modifier]) =>
318
+ current.flatMap((selection) =>
319
+ Object.keys(modifier.contexts).map((contextName) => ({
320
+ ...selection,
321
+ [name]: contextName,
322
+ })),
323
+ ),
324
+ [{}],
325
+ );
326
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * GENERATED FILE. Do not edit by hand.
3
+ *
4
+ * Types for the standalone resolver validator generated from
5
+ * scripts/tokens/schemas/dtcg-resolver-2025-10.json.
6
+ * Regenerate: bun run --filter=@lostgradient/cinder tokens:generate
7
+ */
8
+
9
+ import type { ErrorObject } from 'ajv';
10
+
11
+ /** A compiled DTCG schema validator. `errors` is set by the most recent failing call. */
12
+ export type StandaloneValidator = ((data: unknown) => boolean) & {
13
+ errors?: ErrorObject[] | null;
14
+ };
15
+
16
+ export const validate: StandaloneValidator;
17
+ declare const validator: StandaloneValidator;
18
+ export default validator;