@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.
Files changed (261) hide show
  1. package/CHANGELOG.md +42 -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,407 @@
1
+ import { type CorpusEntry, isPlainObject } from './corpus.ts';
2
+ import { DEFERRED_COMPONENT_ALIAS_FAMILIES } from './css-configuration.ts';
3
+ import { sanitizeComment, stylelintDisableCommentFor } from './css-stylelint.ts';
4
+ import type { ValueResolver } from './resolve.ts';
5
+ import { parseResolutionOrder } from './resolver-order.ts';
6
+ import type { ResolverDocument } from './types.ts';
7
+ import { serializeEntryValue } from './value-entry.ts';
8
+ import { isAliasReference } from './value-formatters.ts';
9
+
10
+ export function isRootDeclaredEntry(entry: CorpusEntry): boolean {
11
+ return !(
12
+ entry.component &&
13
+ DEFERRED_COMPONENT_ALIAS_FAMILIES.has(entry.component) &&
14
+ !entry.cssRecipe &&
15
+ isAliasReference(entry.value)
16
+ );
17
+ }
18
+
19
+ export function renderBaseDeclarations(
20
+ baseIndex: Map<string, CorpusEntry>,
21
+ resolveReferences: ValueResolver,
22
+ ): string {
23
+ const lines: string[] = [];
24
+ for (const entry of baseIndex.values()) {
25
+ if (!entry.cssProperty) {
26
+ throw new Error(`Base corpus token at "${entry.path}" has no cssProperty extension.`);
27
+ }
28
+ // Component aliases are defaults at their consumption sites, not root
29
+ // declarations. Deferring them lets both the public component property and
30
+ // its referenced foundation token respond to scoped ancestor overrides.
31
+ if (!isRootDeclaredEntry(entry)) continue;
32
+ if (entry.description) lines.push(`/* ${sanitizeComment(entry.description)} */`);
33
+ const value = serializeEntryValue(entry, baseIndex, resolveReferences);
34
+ const stylelintDisable = stylelintDisableCommentFor(value);
35
+ if (stylelintDisable) lines.push(stylelintDisable);
36
+ lines.push(`${entry.cssProperty}: ${value};`);
37
+ }
38
+ return lines.join('\n');
39
+ }
40
+
41
+ export function renderOverrideDeclarations(
42
+ overrides: Map<string, CorpusEntry>,
43
+ baseIndex: Map<string, CorpusEntry>,
44
+ resolveReferences: ValueResolver,
45
+ ): string {
46
+ const lines: string[] = [];
47
+ for (const [path, entry] of overrides) {
48
+ const base = baseIndex.get(path);
49
+ if (!base?.cssProperty) {
50
+ throw new Error(`Override token at "${path}" has no matching base token with a cssProperty.`);
51
+ }
52
+ const value = serializeEntryValue(entry, baseIndex, resolveReferences);
53
+ const stylelintDisable = stylelintDisableCommentFor(value);
54
+ if (stylelintDisable) lines.push(stylelintDisable);
55
+ lines.push(`${base.cssProperty}: ${value};`);
56
+ }
57
+ return lines.join('\n');
58
+ }
59
+
60
+ export function withDependentBaseAliases(
61
+ overrides: Map<string, CorpusEntry>,
62
+ baseIndex: Map<string, CorpusEntry>,
63
+ baseResolveReferences: ValueResolver,
64
+ resolveReferences: ValueResolver,
65
+ ): Map<string, CorpusEntry> {
66
+ const scoped = new Map(overrides);
67
+ for (const [path, entry] of baseIndex) {
68
+ if (scoped.has(path)) continue;
69
+ if (entry.cssRecipe || !entryContainsReference(entry)) continue;
70
+ if (
71
+ serializeEntryValue(entry, baseIndex, baseResolveReferences) !==
72
+ serializeEntryValue(entry, baseIndex, resolveReferences)
73
+ ) {
74
+ scoped.set(path, entry);
75
+ }
76
+ }
77
+ return scoped;
78
+ }
79
+
80
+ /**
81
+ * A token overridden in only ONE theme leaves the other theme's block with no
82
+ * declaration for it. Custom properties inherit as COMPUTED values, so a nested
83
+ * island of that other theme does not fall back to the `:root` `light-dark()`
84
+ * declaration -- the themed ancestor has already substituted its own arm, and
85
+ * the island inherits that substituted value.
86
+ *
87
+ * `--cinder-code-block-background` is the case this exists for: it is overridden
88
+ * only in `dark.tokens.json`, so a `[data-theme='light']` island inside a dark
89
+ * ancestor kept the dark `surface-inset` ground underneath github-light Shiki
90
+ * token colors -- the exact AA failure that token's own `$description` warns
91
+ * about. Redeclaring the foundation token it aliases (`--cinder-surface-inset`,
92
+ * which the light block DOES reset) cannot rescue it, because the alias was
93
+ * already resolved against the ancestor.
94
+ *
95
+ * So each scoped block carries a declaration for every path the OTHER block
96
+ * declares. The added entry is the BASE entry, rendered by
97
+ * {@link renderOverrideDeclarations} under this block's own resolver -- the same
98
+ * mechanism {@link withDependentBaseAliases} already uses for the aliases it
99
+ * pulls in, so a `cssRecipe` token re-emits its full `light-dark(...)` recipe
100
+ * (self-resetting under the block's own `color-scheme`) and a plain alias
101
+ * re-resolves against this theme.
102
+ *
103
+ * Applied symmetrically. Only dark currently has theme-exclusive overrides, but
104
+ * the asymmetry is a property of the corpus on any given day, not of the
105
+ * generator, and a light-only override added later must not reintroduce this.
106
+ */
107
+ export function withOppositeThemeResets(
108
+ aliases: Map<string, CorpusEntry>,
109
+ oppositeAliases: Map<string, CorpusEntry>,
110
+ baseIndex: Map<string, CorpusEntry>,
111
+ ): Map<string, CorpusEntry> {
112
+ const scoped = new Map(aliases);
113
+ for (const path of oppositeAliases.keys()) {
114
+ if (scoped.has(path)) continue;
115
+ const base = baseIndex.get(path);
116
+ if (base) scoped.set(path, base);
117
+ }
118
+ return scoped;
119
+ }
120
+
121
+ export function withThemeDependentOverrides(
122
+ overrides: Map<string, CorpusEntry>,
123
+ baseIndex: Map<string, CorpusEntry>,
124
+ systemResolveReferences: ValueResolver,
125
+ themeResolveReferences: ValueResolver,
126
+ ): Map<string, CorpusEntry> {
127
+ const scoped = withDependentBaseAliases(
128
+ new Map(),
129
+ baseIndex,
130
+ systemResolveReferences,
131
+ themeResolveReferences,
132
+ );
133
+ for (const [path, entry] of overrides) {
134
+ if (
135
+ serializeEntryValue(entry, baseIndex, systemResolveReferences) !==
136
+ serializeEntryValue(entry, baseIndex, themeResolveReferences)
137
+ ) {
138
+ scoped.set(path, entry);
139
+ }
140
+ }
141
+ return scoped;
142
+ }
143
+
144
+ function valueContainsReference(value: unknown): boolean {
145
+ if (typeof value === 'string') return /^\{[^{}]+\}$/.test(value) || value.startsWith('#/');
146
+ if (Array.isArray(value)) return value.some(valueContainsReference);
147
+ return isPlainObject(value) && Object.values(value).some(valueContainsReference);
148
+ }
149
+
150
+ export function entryContainsReference(entry: CorpusEntry): boolean {
151
+ return valueContainsReference(entry.value);
152
+ }
153
+
154
+ /**
155
+ * Two tokens mapping to one `cssProperty` with DIFFERENT values is not something
156
+ * `tokens:validate` can catch -- the mapping lives in vendor extension data, which
157
+ * the DTCG schema treats as free-form. Left undetected, both declarations are
158
+ * emitted, CSS silently keeps whichever lands last, and the resolved snapshots go
159
+ * on exposing both token paths, so `tokens:check` approves two artifacts that
160
+ * disagree about the same custom property.
161
+ *
162
+ * Sharing a `cssProperty` is only a conflict when the values differ. `$extends`
163
+ * inheritance legitimately produces two paths for one property -- the extending
164
+ * group inherits members verbatim, extension metadata included -- and those emit
165
+ * an identical declaration twice, which is redundant but harmless.
166
+ */
167
+ export function assertUniqueCssProperties(
168
+ entries: Map<string, CorpusEntry>,
169
+ baseIndex: Map<string, CorpusEntry> = entries,
170
+ resolveReferences: ValueResolver = (value) => value,
171
+ resolveReferencesFactory?: () => ValueResolver,
172
+ ): void {
173
+ const claimants = claimantsByProperty(entries);
174
+ const resolver = hasDuplicateClaimants(claimants)
175
+ ? (resolveReferencesFactory?.() ?? resolveReferences)
176
+ : resolveReferences;
177
+ const conflicts = [...claimants]
178
+ .filter(([, paths]) => paths.length > 1)
179
+ .map(
180
+ ([property, paths]) => [property, fingerprints(paths, entries, baseIndex, resolver)] as const,
181
+ )
182
+ .filter(([, values]) => values.size > 1);
183
+ if (conflicts.length === 0) return;
184
+ const detail = conflicts
185
+ .map(
186
+ ([property, values]) =>
187
+ `${property} is claimed with conflicting values by ${[...values.values()].flat().toSorted().join(', ')}`,
188
+ )
189
+ .join('; ');
190
+ throw new Error(`Conflicting cssProperty mappings in the token corpus: ${detail}`);
191
+ }
192
+
193
+ function claimantsByProperty(entries: Map<string, CorpusEntry>): Map<string, string[]> {
194
+ const grouped = new Map<string, string[]>();
195
+ for (const [path, entry] of entries) {
196
+ if (entry.cssProperty)
197
+ grouped.set(entry.cssProperty, [...(grouped.get(entry.cssProperty) ?? []), path]);
198
+ }
199
+ return grouped;
200
+ }
201
+
202
+ function hasDuplicateClaimants(grouped: Map<string, string[]>): boolean {
203
+ return [...grouped.values()].some((paths) => paths.length > 1);
204
+ }
205
+
206
+ function fingerprints(
207
+ paths: string[],
208
+ entries: Map<string, CorpusEntry>,
209
+ baseIndex: Map<string, CorpusEntry>,
210
+ resolver: ValueResolver,
211
+ ): Map<string, string[]> {
212
+ const values = new Map<string, string[]>();
213
+ for (const path of paths) {
214
+ const entry = entries.get(path)!;
215
+ const emitted = serializeEntryValue(entry, baseIndex, resolver);
216
+ const fingerprint = `${entry.type ?? ''}\u0000${emitted}`;
217
+ values.set(fingerprint, [...(values.get(fingerprint) ?? []), path]);
218
+ }
219
+ return values;
220
+ }
221
+
222
+ /**
223
+ * The same conflict {@link assertUniqueCssProperties} catches for `baseIndex`,
224
+ * applied to ONE override block (a theme or motion context) in isolation.
225
+ * `$extends` can legitimately give two base paths the same `cssProperty` with
226
+ * IDENTICAL base values (assertUniqueCssProperties already lets that through) --
227
+ * but nothing stopped a theme or motion override from then explicitly
228
+ * diverging those two paths to DIFFERENT values, because the base-only guard
229
+ * ran exactly once, against `baseIndex`, and never again against an override
230
+ * block.
231
+ *
232
+ * An override token does not always restate its own `cssProperty` extension --
233
+ * it is inherited, immutable metadata; an override document typically states
234
+ * only a new `$value` -- so grouping by `entry.cssProperty` alone would skip
235
+ * most override entries as property-less. `baseIndex` supplies whichever
236
+ * `cssProperty` (and `$type`, needed for the same type-directed fingerprint
237
+ * `assertUniqueCssProperties` already keys on) an override entry left
238
+ * unstated, so the same two-paths-one-property conflict this guards against
239
+ * at the base level is caught here too.
240
+ */
241
+ export function assertUniqueOverrideCssProperties(
242
+ overrides: Map<string, CorpusEntry>,
243
+ baseIndex: Map<string, CorpusEntry>,
244
+ scopeIndex: Map<string, CorpusEntry>,
245
+ blockName: string,
246
+ resolveReferences: ValueResolver = (value) => value,
247
+ ): void {
248
+ const resolved = effectiveOverrideEntries(overrides, baseIndex, scopeIndex);
249
+ try {
250
+ assertUniqueCssProperties(resolved, baseIndex, resolveReferences);
251
+ } catch (error) {
252
+ if (error instanceof Error)
253
+ throw new Error(`[${blockName}] ${error.message}`, { cause: error });
254
+ throw error;
255
+ }
256
+ }
257
+
258
+ function effectiveOverrideEntries(
259
+ overrides: Map<string, CorpusEntry>,
260
+ baseIndex: Map<string, CorpusEntry>,
261
+ scopeIndex: Map<string, CorpusEntry>,
262
+ ): Map<string, CorpusEntry> {
263
+ const pathsByProperty = claimantsByProperty(baseIndex);
264
+ const relevant = relevantOverridePaths(overrides, baseIndex, pathsByProperty);
265
+ const resolved = new Map<string, CorpusEntry>();
266
+ for (const path of relevant) {
267
+ const base = baseIndex.get(path);
268
+ const entry = overrides.get(path) ?? scopeIndex.get(path) ?? base;
269
+ if (entry)
270
+ resolved.set(path, {
271
+ ...entry,
272
+ cssProperty: base?.cssProperty ?? entry.cssProperty,
273
+ type: entry.type ?? base?.type,
274
+ });
275
+ }
276
+ return resolved;
277
+ }
278
+
279
+ function relevantOverridePaths(
280
+ overrides: Map<string, CorpusEntry>,
281
+ baseIndex: Map<string, CorpusEntry>,
282
+ pathsByProperty: Map<string, string[]>,
283
+ ): Set<string> {
284
+ const relevant = new Set<string>();
285
+ for (const [path, entry] of overrides) {
286
+ relevant.add(path);
287
+ const property = baseIndex.get(path)?.cssProperty ?? entry.cssProperty;
288
+ for (const sibling of property ? (pathsByProperty.get(property) ?? []) : [])
289
+ relevant.add(sibling);
290
+ }
291
+ return relevant;
292
+ }
293
+
294
+ type OverrideScope = {
295
+ name: string;
296
+ resolveReferences: ValueResolver;
297
+ };
298
+
299
+ /** A single emitted override declaration must be valid in every scope its selector reaches. */
300
+ export function assertOverrideScopeConsistency(
301
+ overrides: Map<string, CorpusEntry>,
302
+ baseIndex: Map<string, CorpusEntry>,
303
+ scopes: readonly OverrideScope[],
304
+ blockName: string,
305
+ ): void {
306
+ if (![...overrides.values()].some((entry) => entry.isRefAlias || entryContainsReference(entry)))
307
+ return;
308
+ for (const [path, entry] of overrides) {
309
+ const values = scopes.map((scope) => ({
310
+ scope: scope.name,
311
+ value: serializeEntryValue(entry, baseIndex, scope.resolveReferences),
312
+ }));
313
+ const distinct = new Set(values.map(({ value }) => value));
314
+ if (distinct.size <= 1) continue;
315
+ throw new Error(
316
+ `[${blockName}] override token "${path}" serializes differently across reachable scopes: ` +
317
+ values.map(({ scope, value }) => `${scope}=${value}`).join(', '),
318
+ );
319
+ }
320
+ }
321
+
322
+ /**
323
+ * `tokens-base.css`'s block structure is FIXED, not derived from
324
+ * `resolver.resolutionOrder`: `:root` is always assembled from every `sets`
325
+ * entry (regardless of where it sits in `resolutionOrder`), and the theme
326
+ * override blocks (`[data-theme='dark']`/`[data-theme='light']`) are always
327
+ * emitted before the motion override blocks (the `prefers-reduced-motion`
328
+ * media block and the `data-reduced-motion='on'` override) -- see
329
+ * `buildTokensBaseCss`'s `darkDeclarations`/`lightDeclarations` vs.
330
+ * `reducedMotionDeclarations`/`forcedReducedMotionDeclarations` ordering in
331
+ * the template below.
332
+ *
333
+ * DECISION (CIN-469 finding 5): rather than deriving CSS block order from
334
+ * `resolutionOrder` at generation time -- a bigger, riskier change for a PR
335
+ * whose whole point is a no-diff, tests-and-generator-only fix -- this
336
+ * generator keeps its fixed block structure and instead REJECTS a resolver
337
+ * document whose `resolutionOrder` the fixed structure cannot faithfully
338
+ * express: every `sets` entry must precede every `modifiers` entry (so
339
+ * `:root`'s "every set, unconditionally" assembly matches what
340
+ * `resolutionOrder` actually says the base layer is), and the `theme`
341
+ * modifier must precede the `motion` modifier (so theme-before-motion block
342
+ * emission matches cascade precedence, i.e. a motion override still wins over
343
+ * a theme override for a token both touch, the same way "last non-`:root`
344
+ * block wins" already works today). `cinder.resolver.json`'s current
345
+ * `resolutionOrder` -- foundation, then theme, then motion -- already
346
+ * satisfies this, so the guard is presently a no-op; it exists so a future
347
+ * resolver edit that would silently desync `resolutionOrder` from emission
348
+ * order fails loudly at generate time instead of shipping a CSS cascade that
349
+ * disagrees with the resolver's own stated precedence. If `resolutionOrder`
350
+ * ever legitimately needs a different shape, deriving block order for real
351
+ * -- not just validating it -- is the follow-up.
352
+ */
353
+ export function assertResolutionOrderMatchesCssBlockStructure(resolver: ResolverDocument): void {
354
+ const order = parseResolutionOrder(resolver);
355
+ const lastSetsIndex = order.reduce(
356
+ (last, entry, index) => (entry.kind === 'sets' ? index : last),
357
+ -1,
358
+ );
359
+ const firstModifierIndex = order.findIndex((entry) => entry.kind === 'modifiers');
360
+ if (firstModifierIndex !== -1 && lastSetsIndex > firstModifierIndex) {
361
+ throw new Error(
362
+ 'resolver\'s resolutionOrder interleaves a "sets" entry after a "modifiers" entry, but ' +
363
+ 'tokens-base.css always assembles :root from every "sets" entry unconditionally, ' +
364
+ 'regardless of position -- reorder resolutionOrder so every "sets" entry precedes every ' +
365
+ '"modifiers" entry, or teach buildTokensBaseCss to derive :root membership from position.',
366
+ );
367
+ }
368
+ const themeIndex = order.findIndex(
369
+ (entry) => entry.kind === 'modifiers' && entry.name === 'theme',
370
+ );
371
+ const motionIndex = order.findIndex(
372
+ (entry) => entry.kind === 'modifiers' && entry.name === 'motion',
373
+ );
374
+ if (themeIndex !== -1 && motionIndex !== -1 && themeIndex > motionIndex) {
375
+ throw new Error(
376
+ 'resolver\'s resolutionOrder has "motion" before "theme", but tokens-base.css always ' +
377
+ "emits the theme override blocks ([data-theme='dark']/[data-theme='light']) before the " +
378
+ 'motion override blocks (prefers-reduced-motion / data-reduced-motion) -- reorder ' +
379
+ 'resolutionOrder so "theme" precedes "motion", or teach buildTokensBaseCss to derive ' +
380
+ 'override block order from resolutionOrder.',
381
+ );
382
+ }
383
+ // `buildTokensBaseCss`'s override-block template is hardcoded to exactly two
384
+ // modifiers, "theme" and "motion" -- it never reads `resolver.modifiers` generically,
385
+ // so a third modifier's context documents would never reach ANY emitted CSS block,
386
+ // while `buildResolvedContexts`/`modifierValuesForCombo` fill every declared
387
+ // modifier (including a third one, at its own default) when composing each resolved
388
+ // snapshot's document scope. A third modifier whose default context overrides
389
+ // anything the base sets don't would then make a published resolved-context
390
+ // snapshot disagree with what the actual CSS renders, for every combination, not just
391
+ // a cross-modifier edge case -- the same class of artifact/CSS disagreement this
392
+ // whole guard exists to prevent, just triggered structurally instead of by a specific
393
+ // value collision. Reject a third modifier here rather than silently generating CSS
394
+ // that can't express it.
395
+ const unsupportedModifiers = Object.keys(resolver.modifiers).filter(
396
+ (name) => name !== 'theme' && name !== 'motion',
397
+ );
398
+ if (unsupportedModifiers.length > 0) {
399
+ throw new Error(
400
+ `resolver declares modifier(s) ${unsupportedModifiers.map((name) => `"${name}"`).join(', ')}, ` +
401
+ 'but tokens-base.css\'s override-block template only knows how to emit "theme" and ' +
402
+ '"motion" -- add support for the new modifier to buildTokensBaseCss (and to ' +
403
+ "buildResolvedContexts's published combos) before adding it to the resolver, or the " +
404
+ 'generated CSS and published resolved-context snapshots will silently disagree.',
405
+ );
406
+ }
407
+ }
@@ -0,0 +1,262 @@
1
+ /**
2
+ * The runtime's public validate / resolve / project interface.
3
+ *
4
+ * Everything here is in memory: the caller hands over a resolver and token
5
+ * documents, and receives either a result for all six contexts or
6
+ * path-addressed diagnostics. Nothing reads a file, fetches a source, or
7
+ * formats output; those stay in `scripts/`.
8
+ *
9
+ * Validation always runs first and always includes the schema stage (the
10
+ * standalone DTCG validators) before the semantic checks, so there is no way to
11
+ * reach projection or provenance with a document the schema rejects. Invalid
12
+ * types, unresolvable references, and reference cycles surface as diagnostics
13
+ * and produce no property map and no provenance. A value the CSS projection
14
+ * cannot express is a diagnostic too, never a fallback.
15
+ */
16
+
17
+ import { traceProvenance } from './authoring-provenance.ts';
18
+ import type { AuthoringContext, AuthoringLayer } from './authoring-types.ts';
19
+ import { scopeIndexFromDocuments } from './context-order.ts';
20
+ import { authoringContexts, authoringLayerStack } from './context-stack.ts';
21
+ import { validateCorpus } from './corpus-documents.ts';
22
+ import { assertResolutionOrderMatchesCssBlockStructure } from './css-support.ts';
23
+ import {
24
+ evaluateContextProvenance,
25
+ type EvaluatedProvenance,
26
+ type TokenEvaluation,
27
+ } from './evaluated-provenance.ts';
28
+ import { projectProperties, type PropertyMap } from './projection.ts';
29
+ import { TokenValidationError, type ResolverDocument, type TokenDocument } from './types.ts';
30
+ import { assertValidResolverDocument } from './validate.ts';
31
+
32
+ /** The sources of one theme: a resolver and its token documents, keyed by relative path. */
33
+ export type ThemeSources = {
34
+ /** Identifies this input. Results echo it so a stale result can be recognized and dropped. */
35
+ revision: number | string;
36
+ resolver: unknown;
37
+ documents: Readonly<Record<string, unknown>>;
38
+ };
39
+
40
+ export type ThemeDiagnostic = {
41
+ revision: number | string;
42
+ severity: 'error';
43
+ /** Where the problem is: a document path, a token path, or `$` for the whole input. */
44
+ path: string;
45
+ reason: string;
46
+ /** The context the problem appears in, when it is specific to one. */
47
+ context?: string;
48
+ };
49
+
50
+ export type ThemeValidation = {
51
+ revision: number | string;
52
+ diagnostics: ThemeDiagnostic[];
53
+ };
54
+
55
+ /**
56
+ * The outcome of evaluating a theme. A failure carries diagnostics and nothing
57
+ * else; a success carries one property map and one provenance result per
58
+ * context, and no diagnostics.
59
+ */
60
+ export type ThemeEvaluation =
61
+ | {
62
+ ok: true;
63
+ revision: number | string;
64
+ contexts: AuthoringContext[];
65
+ /** Per context id, the public custom properties and their CSS values. */
66
+ properties: Record<string, PropertyMap>;
67
+ diagnostics: ThemeDiagnostic[];
68
+ provenance: EvaluatedProvenance;
69
+ }
70
+ | { ok: false; revision: number | string; diagnostics: ThemeDiagnostic[] };
71
+
72
+ function diagnosticsFor(
73
+ revision: number | string,
74
+ error: unknown,
75
+ context?: string,
76
+ ): ThemeDiagnostic[] {
77
+ const issues =
78
+ error instanceof TokenValidationError
79
+ ? error.issues
80
+ : [{ path: '$', reason: error instanceof Error ? error.message : String(error) }];
81
+ return issues.map(({ path, reason }) => ({
82
+ revision,
83
+ severity: 'error' as const,
84
+ path,
85
+ reason,
86
+ ...(context === undefined ? {} : { context }),
87
+ }));
88
+ }
89
+
90
+ type ValidatedSources = {
91
+ resolver: ResolverDocument;
92
+ documentsByPath: Map<string, TokenDocument>;
93
+ };
94
+
95
+ function validateSources(sources: ThemeSources): ValidatedSources | ThemeDiagnostic[] {
96
+ try {
97
+ assertValidResolverDocument(sources.resolver);
98
+ // The generated stylesheet emits theme blocks before motion blocks; a resolver
99
+ // that orders them otherwise cannot be exported, so it is not a valid theme.
100
+ assertResolutionOrderMatchesCssBlockStructure(sources.resolver);
101
+ const documentsByPath = validateCorpus(
102
+ sources.resolver,
103
+ Object.entries(sources.documents).map(([path, document]) => ({ path, document })),
104
+ );
105
+ return { resolver: sources.resolver, documentsByPath };
106
+ } catch (error) {
107
+ return diagnosticsFor(sources.revision, error);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Validates a theme's sources: the resolver, every document against the DTCG
113
+ * schemas and then the semantic rules, and the resolved tokens of all six
114
+ * contexts. Returns diagnostics; an empty list means the sources are valid.
115
+ * Does not mutate its input.
116
+ */
117
+ export function validateThemeSources(sources: ThemeSources): ThemeValidation {
118
+ const validated = validateSources(sources);
119
+ return {
120
+ revision: sources.revision,
121
+ diagnostics: Array.isArray(validated) ? validated : [],
122
+ };
123
+ }
124
+
125
+ /**
126
+ * The result of `evaluateThemeProperties`: property maps for the requested contexts and no
127
+ * provenance.
128
+ */
129
+ export type ThemePropertiesEvaluation =
130
+ | {
131
+ ok: true;
132
+ revision: number | string;
133
+ contexts: AuthoringContext[];
134
+ properties: Record<string, PropertyMap>;
135
+ diagnostics: ThemeDiagnostic[];
136
+ }
137
+ | { ok: false; revision: number | string; diagnostics: ThemeDiagnostic[] };
138
+
139
+ type Selection = { contexts?: readonly string[]; provenance: boolean };
140
+
141
+ type Evaluated = {
142
+ contexts: AuthoringContext[];
143
+ properties: Record<string, PropertyMap>;
144
+ layerStacks: Record<string, AuthoringLayer[]>;
145
+ tokens: Record<string, TokenEvaluation[]>;
146
+ };
147
+
148
+ /**
149
+ * The one per-context loop behind both entry points. Validation always covers every
150
+ * context; `selection` only narrows which contexts are projected (and traced).
151
+ */
152
+ function evaluateSelected(
153
+ sources: ThemeSources,
154
+ selection: Selection,
155
+ ): Evaluated | ThemeDiagnostic[] {
156
+ const { revision } = sources;
157
+ const validated = validateSources(sources);
158
+ if (Array.isArray(validated)) return validated;
159
+
160
+ let all: Array<AuthoringContext & Record<string, string>>;
161
+ try {
162
+ all = authoringContexts(validated.resolver);
163
+ } catch (error) {
164
+ return diagnosticsFor(revision, error);
165
+ }
166
+ const wanted = selection.contexts;
167
+ const selected = wanted === undefined ? all : all.filter(({ id }) => wanted.includes(id));
168
+
169
+ const diagnostics: ThemeDiagnostic[] = [];
170
+ const properties: Record<string, PropertyMap> = {};
171
+ const layerStacks: Record<string, AuthoringLayer[]> = {};
172
+ const tokens: Record<string, TokenEvaluation[]> = {};
173
+ for (const context of selected) {
174
+ try {
175
+ const stack = authoringLayerStack(validated.resolver, validated.documentsByPath, context);
176
+ const documents = stack.map((layer) => layer.content);
177
+ const index = scopeIndexFromDocuments(documents);
178
+ const projection = projectProperties(documents, index);
179
+ if (projection.failures.length > 0) {
180
+ for (const { path, reason } of projection.failures) {
181
+ diagnostics.push({ revision, severity: 'error', path, reason, context: context.id });
182
+ }
183
+ continue;
184
+ }
185
+ properties[context.id] = projection.properties;
186
+ if (!selection.provenance) continue;
187
+ const cssPropertyToPath: Record<string, string> = {};
188
+ for (const entry of index.values()) {
189
+ if (entry.cssProperty !== undefined) cssPropertyToPath[entry.cssProperty] = entry.path;
190
+ }
191
+ layerStacks[context.id] = stack.map(({ document, kind, layer }) => ({
192
+ document,
193
+ kind,
194
+ layer,
195
+ }));
196
+ tokens[context.id] = evaluateContextProvenance(
197
+ layerStacks[context.id]!,
198
+ traceProvenance(stack, { cssPropertyToPath }),
199
+ );
200
+ } catch (error) {
201
+ diagnostics.push(...diagnosticsFor(revision, error, context.id));
202
+ }
203
+ }
204
+ if (diagnostics.length > 0) return diagnostics;
205
+ return {
206
+ contexts: selected.map(({ id, theme, motion }) => ({ id, theme, motion })),
207
+ properties,
208
+ layerStacks,
209
+ tokens,
210
+ };
211
+ }
212
+
213
+ /**
214
+ * The cheap path for an edit loop. It validates every context exactly as `evaluateTheme`
215
+ * does, so an edit that is invalid in any context is still rejected, but it projects only
216
+ * `options.contexts` (default: all six) and traces no provenance. Its property maps equal
217
+ * `evaluateTheme`'s for the contexts they share.
218
+ */
219
+ export function evaluateThemeProperties(
220
+ sources: ThemeSources,
221
+ options: { contexts?: readonly string[] } = {},
222
+ ): ThemePropertiesEvaluation {
223
+ const { revision } = sources;
224
+ const result = evaluateSelected(sources, {
225
+ provenance: false,
226
+ ...(options.contexts === undefined ? {} : { contexts: options.contexts }),
227
+ });
228
+ if (Array.isArray(result)) return { ok: false, revision, diagnostics: result };
229
+ return {
230
+ ok: true,
231
+ revision,
232
+ contexts: result.contexts,
233
+ properties: result.properties,
234
+ diagnostics: [],
235
+ };
236
+ }
237
+
238
+ /**
239
+ * Evaluates a theme across `light|dark` by `default|reduced|forced-reduced-motion`:
240
+ * validates it, computes every context from source (the two forced contexts
241
+ * included), projects each to its public CSS property map, and traces the
242
+ * evaluated provenance. Does not mutate its input, and its sources must not be mutated
243
+ * afterwards: validation results are remembered by document identity.
244
+ */
245
+ export function evaluateTheme(sources: ThemeSources): ThemeEvaluation {
246
+ const { revision } = sources;
247
+ const result = evaluateSelected(sources, { provenance: true });
248
+ if (Array.isArray(result)) return { ok: false, revision, diagnostics: result };
249
+ return {
250
+ ok: true,
251
+ revision,
252
+ contexts: result.contexts,
253
+ properties: result.properties,
254
+ diagnostics: [],
255
+ provenance: {
256
+ revision,
257
+ contexts: result.contexts,
258
+ layerStacks: result.layerStacks,
259
+ tokens: result.tokens,
260
+ },
261
+ };
262
+ }