@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,414 @@
1
+ import { isPlainObject } from './corpus.ts';
2
+ import type { ValueResolver } from './resolve.ts';
3
+ import type { TokenType } from './types.ts';
4
+
5
+ export type DimensionOrDuration = { value: number; unit: string };
6
+ type ColorComponent = number | 'none';
7
+ /** `isColorValue` admits exactly three channels, so the formatters below can destructure them without a check. */
8
+ export type ColorValue = {
9
+ colorSpace: string;
10
+ components: [ColorComponent, ColorComponent, ColorComponent];
11
+ alpha?: number | 'none';
12
+ hex?: string;
13
+ };
14
+ export type ShadowLayer = {
15
+ color: ColorValue;
16
+ offsetX: DimensionOrDuration;
17
+ offsetY: DimensionOrDuration;
18
+ blur: DimensionOrDuration;
19
+ spread: DimensionOrDuration;
20
+ inset?: boolean;
21
+ };
22
+
23
+ /** Matches both DTCG alias syntaxes: curly-brace (`{a.b.c}`) and JSON Pointer (`#/a/b/c`), the same two forms `validate.ts`'s `isReference` accepts and `resolve.ts` resolves. */
24
+ export function isAliasReference(value: unknown): value is string {
25
+ return typeof value === 'string' && (/^\{[^{}]+\}$/.test(value) || value.startsWith('#/'));
26
+ }
27
+
28
+ // Runtime type guards narrow `unknown` `$value` payloads to their expected
29
+ // shape, matching validate.ts's own idiom -- ajv and validate-corpus.ts
30
+ // already checked the full corpus upstream, so these are a defensive second
31
+ // check plus the mechanism TypeScript needs to narrow safely, without a bare
32
+ // `as` type assertion on data that starts life as `unknown`.
33
+
34
+ function isDimensionOrDuration(value: unknown): value is DimensionOrDuration {
35
+ return (
36
+ isPlainObject(value) && typeof value['value'] === 'number' && typeof value['unit'] === 'string'
37
+ );
38
+ }
39
+
40
+ function isNumberValue(value: unknown): value is number {
41
+ return typeof value === 'number';
42
+ }
43
+
44
+ function isCubicBezierValue(value: unknown): value is readonly [number, number, number, number] {
45
+ return (
46
+ Array.isArray(value) && value.length === 4 && value.every((entry) => typeof entry === 'number')
47
+ );
48
+ }
49
+
50
+ function isFontFamilyValue(value: unknown): value is string[] | string {
51
+ return (
52
+ typeof value === 'string' ||
53
+ (Array.isArray(value) && value.every((entry) => typeof entry === 'string'))
54
+ );
55
+ }
56
+
57
+ function isColorComponent(value: unknown): value is number | 'none' {
58
+ return typeof value === 'number' || value === 'none';
59
+ }
60
+
61
+ function isColorValue(value: unknown): value is ColorValue {
62
+ if (!isPlainObject(value)) return false;
63
+ if (typeof value['colorSpace'] !== 'string') return false;
64
+ const components = value['components'];
65
+ if (!Array.isArray(components) || components.length !== 3 || !components.every(isColorComponent))
66
+ return false;
67
+ if (value['alpha'] !== undefined && !isColorComponent(value['alpha'])) return false;
68
+ if (value['hex'] !== undefined && typeof value['hex'] !== 'string') return false;
69
+ return true;
70
+ }
71
+
72
+ function isShadowLayerArray(value: unknown): value is readonly ShadowLayer[] {
73
+ return (
74
+ Array.isArray(value) &&
75
+ value.every(
76
+ (layer) =>
77
+ isPlainObject(layer) &&
78
+ isColorValue(layer['color']) &&
79
+ isDimensionOrDuration(layer['offsetX']) &&
80
+ isDimensionOrDuration(layer['offsetY']) &&
81
+ isDimensionOrDuration(layer['blur']) &&
82
+ isDimensionOrDuration(layer['spread']) &&
83
+ (layer['inset'] === undefined || typeof layer['inset'] === 'boolean'),
84
+ )
85
+ );
86
+ }
87
+
88
+ /** `validate.ts` accepts a shadow `$value` as either a single layer object or an array of layers (DTCG allows both); normalize the single-object form to a one-element array before shape-checking so the generator accepts everything the validator does. */
89
+ function normalizeShadowValue(value: unknown): unknown {
90
+ return isPlainObject(value) ? [value] : value;
91
+ }
92
+
93
+ /**
94
+ * DTCG named font weights per the format module's fontWeight value schema
95
+ * ("Represents a font weight as per the OpenType wght tag specification"),
96
+ * mapped to the OpenType usWeightClass numbers the names stand for. CSS
97
+ * `font-weight` has no keyword for most of these (only `normal`/`bold` are
98
+ * CSS keywords, and they don't cover the other eight) but accepts any number
99
+ * in [1, 1000], so every name -- including `normal`/`bold` -- is translated
100
+ * to its number uniformly rather than passing a subset through as keywords.
101
+ */
102
+ const DTCG_NAMED_FONT_WEIGHTS: Readonly<Record<string, number>> = {
103
+ thin: 100,
104
+ 'extra-light': 200,
105
+ light: 300,
106
+ normal: 400,
107
+ medium: 500,
108
+ 'semi-bold': 600,
109
+ bold: 700,
110
+ 'extra-bold': 800,
111
+ black: 900,
112
+ 'extra-black': 950,
113
+ };
114
+
115
+ function isFontWeightValue(value: unknown): value is number | string {
116
+ return isNumberValue(value) || (typeof value === 'string' && value in DTCG_NAMED_FONT_WEIGHTS);
117
+ }
118
+
119
+ function formatFontWeight(value: number | string): string {
120
+ return formatNumber(typeof value === 'number' ? value : DTCG_NAMED_FONT_WEIGHTS[value]!);
121
+ }
122
+
123
+ /** Precision-safe number-to-string: plain `String()` round-trips every literal in this corpus (verified), EXCEPT results of real arithmetic (the oklch lightness-to-percentage conversion), which route through {@link roundForDisplay} first. */
124
+ function formatNumber(value: number): string {
125
+ if (Object.is(value, -0)) return '0';
126
+ return String(value);
127
+ }
128
+
129
+ /** Clears floating-point noise from a computed value (e.g. `0.994 * 100 === 99.39999999999999`) without touching values that were never computed. */
130
+ function roundForDisplay(value: number): number {
131
+ return Number(value.toFixed(10));
132
+ }
133
+
134
+ function formatComponent(component: number | 'none'): string {
135
+ return component === 'none' ? 'none' : formatNumber(component);
136
+ }
137
+
138
+ function formatOklchLightness(component: number | 'none'): string {
139
+ if (component === 'none') return 'none';
140
+ return `${formatNumber(roundForDisplay(component * 100))}%`;
141
+ }
142
+
143
+ /** Collapses a 6-digit hex literal to 3-digit shorthand when every channel pair is a doubled digit (`#ffffff` -> `#fff`), matching the shorthand already authored in tokens-base.css for the two checkerboard tokens. */
144
+ function collapseHex(hex: string): string {
145
+ const normalized = hex.toLowerCase();
146
+ const match = /^#([0-9a-f]{6})$/.exec(normalized);
147
+ if (!match) return normalized;
148
+ const digits = match[1]!;
149
+ const [r1, r2, g1, g2, b1, b2] = digits;
150
+ if (r1 === r2 && g1 === g2 && b1 === b2) return `#${r1}${g1}${b1}`;
151
+ return normalized;
152
+ }
153
+
154
+ function formatColor(value: ColorValue): string {
155
+ // A fully-transparent color is the `transparent` keyword regardless of its
156
+ // base channels -- matches `--cinder-border-inverse`'s light-arm literal.
157
+ if (typeof value.alpha === 'number' && value.alpha === 0) return 'transparent';
158
+
159
+ // `hex` is optional metadata on `srgb` values; the `components` are the
160
+ // source of truth EXCEPT here, where the current file's own literal is a
161
+ // hex value (the two checkerboard tokens) -- so hex presence signals
162
+ // "serialize as hex", not "here is a redundant fallback to ignore". A
163
+ // 6-digit hex has no alpha channel, so it may only stand in for the color
164
+ // when the value is fully opaque (no alpha, or alpha === 1); otherwise the
165
+ // hex would silently discard the alpha, so fall through to the
166
+ // component-based `color()` form below, which carries it explicitly.
167
+ const isOpaque = value.alpha === undefined || value.alpha === 1;
168
+ if (value.colorSpace === 'srgb' && typeof value.hex === 'string' && isOpaque) {
169
+ return collapseHex(value.hex);
170
+ }
171
+
172
+ if (value.colorSpace === 'oklch') return formatOklch(value);
173
+ if (value.colorSpace === 'srgb') return formatSrgb(value);
174
+
175
+ const other = formatOtherColorSpace(value);
176
+ if (other !== undefined) return other;
177
+
178
+ throw new Error(
179
+ `No direct CSS serialization implemented for color colorSpace "${value.colorSpace}". ` +
180
+ 'Add it to formatOtherColorSpace before authoring a color in that space.',
181
+ );
182
+ }
183
+
184
+ /** DTCG color spaces CSS Color 4 writes as `color(<space> a b c)`. */
185
+ const PREDEFINED_COLOR_SPACES = new Set([
186
+ 'srgb-linear',
187
+ 'display-p3',
188
+ 'a98-rgb',
189
+ 'prophoto-rgb',
190
+ 'rec2020',
191
+ 'xyz-d50',
192
+ 'xyz-d65',
193
+ ]);
194
+
195
+ /**
196
+ * The colors authored in a space other than oklch or srgb, written in the space they are
197
+ * authored in: a source in Display P3 stays `color(display-p3 …)` and is never converted or
198
+ * clamped on its way to CSS. Percent-based channels follow the DTCG ranges (hsl and hwb
199
+ * saturation, lightness, whiteness and blackness are 0–100; lab and lch lightness are 0–100;
200
+ * oklab lightness is 0–1).
201
+ */
202
+ function formatOtherColorSpace(value: ColorValue): string | undefined {
203
+ const [first, second, third] = value.components;
204
+ const alpha = value.alpha === undefined ? '' : ` / ${formatComponent(value.alpha)}`;
205
+ const [a, b, c] = [formatComponent(first), formatComponent(second), formatComponent(third)];
206
+ const percent = (component: number | 'none'): string =>
207
+ component === 'none' ? 'none' : `${formatNumber(component)}%`;
208
+ if (PREDEFINED_COLOR_SPACES.has(value.colorSpace)) {
209
+ return `color(${value.colorSpace} ${a} ${b} ${c}${alpha})`;
210
+ }
211
+ switch (value.colorSpace) {
212
+ case 'lab':
213
+ return `lab(${percent(first)} ${b} ${c}${alpha})`;
214
+ case 'lch':
215
+ return `lch(${percent(first)} ${b} ${c}${alpha})`;
216
+ case 'oklab':
217
+ return `oklab(${formatOklchLightness(first)} ${b} ${c}${alpha})`;
218
+ case 'hsl':
219
+ return `hsl(${a} ${percent(second)} ${percent(third)}${alpha})`;
220
+ case 'hwb':
221
+ return `hwb(${a} ${percent(second)} ${percent(third)}${alpha})`;
222
+ default:
223
+ return undefined;
224
+ }
225
+ }
226
+
227
+ function formatOklch(value: ColorValue): string {
228
+ const [lightness, chroma, hue] = value.components;
229
+ const alpha = value.alpha === undefined ? '' : ` / ${formatComponent(value.alpha)}`;
230
+ return `oklch(${formatOklchLightness(lightness)} ${formatComponent(chroma)} ${formatComponent(hue)}${alpha})`;
231
+ }
232
+
233
+ function formatSrgb(value: ColorValue): string {
234
+ const [red, green, blue] = value.components;
235
+ const alpha = value.alpha === undefined ? '' : ` / ${formatComponent(value.alpha)}`;
236
+ return `color(srgb ${formatComponent(red)} ${formatComponent(green)} ${formatComponent(blue)}${alpha})`;
237
+ }
238
+
239
+ /**
240
+ * `<length>` values (dimensions) may drop their unit only when the value is
241
+ * exactly zero -- that's why `--cinder-space-0` and every shadow's
242
+ * zero-valued `offsetX` are authored as bare `0`, not `0px`/`0rem`.
243
+ */
244
+ function formatDimension(value: DimensionOrDuration): string {
245
+ if (value.value === 0) return '0';
246
+ return `${formatNumber(value.value)}${value.unit}`;
247
+ }
248
+
249
+ /**
250
+ * `<time>` values (durations) always require a unit in CSS, even at zero --
251
+ * `transition-duration: 0` is invalid. `--cinder-duration-instant` and every
252
+ * reduced-motion override stay `0ms`, never bare `0`.
253
+ */
254
+ function formatDuration(value: DimensionOrDuration): string {
255
+ return `${formatNumber(value.value)}${value.unit}`;
256
+ }
257
+
258
+ function formatCubicBezier(value: readonly number[]): string {
259
+ return `cubic-bezier(${value.map(formatNumber).join(', ')})`;
260
+ }
261
+
262
+ /** CSS Fonts Module generic-family keywords, which must stay bare (unquoted) even though they'd otherwise look like ordinary custom-idents -- quoting one of these turns it into a font named e.g. "sans-serif" instead of the generic fallback. */
263
+ const GENERIC_FONT_FAMILY_KEYWORDS = new Set([
264
+ 'serif',
265
+ 'sans-serif',
266
+ 'cursive',
267
+ 'fantasy',
268
+ 'monospace',
269
+ 'system-ui',
270
+ 'ui-serif',
271
+ 'ui-sans-serif',
272
+ 'ui-monospace',
273
+ 'ui-rounded',
274
+ 'math',
275
+ ]);
276
+
277
+ /** A conservative single-token CSS `<custom-ident>`: letters/digits/`-`/`_`, not digit-led. Every non-generic name in the corpus today (`-apple-system`, `SFMono-Regular`, `BlinkMacSystemFont`, `Roboto`, `Menlo`, `Consolas`) matches this and stays bare; anything that doesn't -- a space (`Segoe UI`), a comma (`ACME, Inc`), an apostrophe, a leading digit -- is not a valid bare identifier and must be quoted as a CSS string instead, per the `family-name = <custom-ident>+ | <string>` grammar. */
278
+ const SAFE_UNQUOTED_FONT_FAMILY_NAME = /^-?[A-Za-z_][A-Za-z0-9_-]*$/;
279
+
280
+ /**
281
+ * CSS-wide keywords (CSS Values and Units § 3.2), checked case-insensitively. Each one is
282
+ * syntactically a valid bare `<custom-ident>` -- `inherit` matches
283
+ * {@link SAFE_UNQUOTED_FONT_FAMILY_NAME} just as cleanly as `Roboto` does -- but emitted bare in
284
+ * a `font-family` declaration it triggers cascade behavior (`inherit`, `initial`, `unset`,
285
+ * `revert`, `revert-layer`) instead of naming a font with that literal name, silently changing
286
+ * what the declaration means. Quoting forces the string interpretation.
287
+ */
288
+ const CSS_WIDE_KEYWORDS = new Set(['inherit', 'initial', 'revert', 'revert-layer', 'unset']);
289
+
290
+ function escapeFontFamilyString(name: string): string {
291
+ return name.replaceAll('\\', '\\\\').replaceAll("'", "\\'");
292
+ }
293
+
294
+ function formatFontFamilyName(name: string): string {
295
+ if (GENERIC_FONT_FAMILY_KEYWORDS.has(name)) return name;
296
+ if (CSS_WIDE_KEYWORDS.has(name.toLowerCase())) return `'${escapeFontFamilyString(name)}'`;
297
+ if (SAFE_UNQUOTED_FONT_FAMILY_NAME.test(name)) return name;
298
+ return `'${escapeFontFamilyString(name)}'`;
299
+ }
300
+
301
+ function formatFontFamily(value: string[] | string): string {
302
+ const names = Array.isArray(value) ? value : [value];
303
+ return names.map(formatFontFamilyName).join(', ');
304
+ }
305
+
306
+ function formatShadow(layers: readonly ShadowLayer[]): string {
307
+ return layers
308
+ .map((layer) => {
309
+ const parts = [
310
+ layer.inset ? 'inset' : undefined,
311
+ formatDimension(layer.offsetX),
312
+ formatDimension(layer.offsetY),
313
+ formatDimension(layer.blur),
314
+ // Spread is omitted (3-value shadow form) when it is exactly zero,
315
+ // matching the authored style throughout tokens-base.css.
316
+ layer.spread.value !== 0 ? formatDimension(layer.spread) : undefined,
317
+ formatColor(layer.color),
318
+ ];
319
+ return parts.filter((part): part is string => part !== undefined).join(' ');
320
+ })
321
+ .join(', ');
322
+ }
323
+
324
+ /**
325
+ * `validate.ts` permits a reference (`{a.b.c}` or `#/a/b/c`) at any composite leaf position --
326
+ * a shadow layer's `color`, a color's individual `components`/`alpha`, a border's `width`, and
327
+ * so on -- alongside the whole-value alias `serializeEntryValue` already handles before this
328
+ * function is ever called. `resolveReferences` (identity by default, so existing callers that
329
+ * pass literal, already-resolved values are unaffected) resolves every such reference, at any
330
+ * depth, to its literal value before shape-checking and formatting proceed.
331
+ */
332
+ export function serializeTypedValue(
333
+ type: TokenType,
334
+ value: unknown,
335
+ path: string,
336
+ resolveReferences: ValueResolver = (raw) => raw,
337
+ ): string {
338
+ const resolvedValue = resolveReferences(value);
339
+ const serializer = typedSerializers[type];
340
+ if (serializer === undefined) {
341
+ throw new Error(
342
+ `No direct CSS serialization implemented for token type "${type}" at "${path}". ` +
343
+ 'Add a cssRecipe extension in the corpus, or extend serializeTypedValue.',
344
+ );
345
+ }
346
+ return serializer(resolvedValue, path);
347
+ }
348
+
349
+ type TypedSerializer = (value: unknown, path: string) => string;
350
+
351
+ function invalid(path: string, type: string, expected: string): never {
352
+ throw new Error(
353
+ `Token at "${path}" has $type "${type}" but its $value is not a valid ${expected}.`,
354
+ );
355
+ }
356
+
357
+ const typedSerializers: Record<string, TypedSerializer> = {
358
+ dimension: (value, path) =>
359
+ isDimensionOrDuration(value)
360
+ ? formatDimension(value)
361
+ : invalid(path, 'dimension', '{value, unit} dimension'),
362
+ duration: (value, path) =>
363
+ isDimensionOrDuration(value)
364
+ ? formatDuration(value)
365
+ : invalid(path, 'duration', '{value, unit} duration'),
366
+ number: (value, path) =>
367
+ isNumberValue(value) ? formatNumber(value) : invalid(path, 'number', 'number'),
368
+ fontWeight: (value, path) =>
369
+ isFontWeightValue(value)
370
+ ? formatFontWeight(value)
371
+ : invalid(path, 'fontWeight', 'number in [1, 1000] or named DTCG font weight'),
372
+ cubicBezier: (value, path) =>
373
+ isCubicBezierValue(value)
374
+ ? formatCubicBezier(value)
375
+ : invalid(path, 'cubicBezier', 'four-number cubic-bezier'),
376
+ fontFamily: (value, path) =>
377
+ isFontFamilyValue(value)
378
+ ? formatFontFamily(value)
379
+ : invalid(path, 'fontFamily', 'string | string[] font family'),
380
+ color: (value, path) =>
381
+ isColorValue(value) ? formatColor(value) : invalid(path, 'color', 'color'),
382
+ shadow: (value, path) => {
383
+ const normalized = normalizeShadowValue(value);
384
+ return isShadowLayerArray(normalized)
385
+ ? formatShadow(normalized)
386
+ : invalid(path, 'shadow', 'shadow layer object or array');
387
+ },
388
+ };
389
+
390
+ /**
391
+ * The `baseIndex` key a whole-token JSON Pointer alias names, beyond
392
+ * `tokenPathFromReference`'s plain dot-join.
393
+ *
394
+ * A property-FORM pointer whose last segment is literally `$value` (e.g.
395
+ * `#/dimension/hairline/$value`) names the referenced token's WHOLE value --
396
+ * resolve.ts's own `resolveReference` special-cases a trailing `$value`
397
+ * segment the same way (see resolve.test.ts's "resolves a property-level
398
+ * JSON Pointer reference" case, which targets a whole dimension token via
399
+ * `#/dimension/hairline/$value`). `tokenPathFromReference` has no such
400
+ * special case -- it just dot-joins every segment -- so without stripping it
401
+ * here, the exact-match `baseIndex` lookup misses the token entirely even
402
+ * though `tokens:validate` accepts the identical reference. Gated on `#/`
403
+ * (pointer syntax): a curly alias `{a.b.$value}` is a literal dotted path
404
+ * through the corpus, not resolve.ts's pointer special case, so stripping it
405
+ * there would just as wrongly make the generator and the validator disagree
406
+ * the other way.
407
+ *
408
+ * A `$root` segment is a REDIRECT to the group's own root token, which
409
+ * `collectEntries` indexes at the group's own path (`prefix`), not
410
+ * `prefix.$root` -- the same redirect resolve.ts's `refTargetIndexPath`
411
+ * applies for type inference. `#/group/$root` and `#/group/$root/$value`
412
+ * both name the root token's whole identity and must strip to `group`;
413
+ * `#/$root`/`#/$root/$value` strip to the document root's own path (`''`).
414
+ */
@@ -18,7 +18,11 @@
18
18
  "cssProperty": "--cinder-status-success-background",
19
19
  "public": true,
20
20
  "category": "color",
21
- "cssRecipe": "light-dark(oklch(94.5% 0.045 145), oklch(28% 0.07 145))"
21
+ "cssRecipe": "light-dark(oklch(94.5% 0.045 145), oklch(28% 0.07 145))",
22
+ "palette": {
23
+ "family": "success",
24
+ "role": "background"
25
+ }
22
26
  }
23
27
  }
24
28
  },
@@ -34,7 +38,11 @@
34
38
  "cssProperty": "--cinder-status-success-text",
35
39
  "public": true,
36
40
  "category": "color",
37
- "cssRecipe": "light-dark(oklch(40% 0.127 145), oklch(88% 0.11 145))"
41
+ "cssRecipe": "light-dark(oklch(40% 0.127 145), oklch(88% 0.11 145))",
42
+ "palette": {
43
+ "family": "success",
44
+ "role": "text"
45
+ }
38
46
  }
39
47
  }
40
48
  },
@@ -50,7 +58,11 @@
50
58
  "cssProperty": "--cinder-status-success-border",
51
59
  "public": true,
52
60
  "category": "color",
53
- "cssRecipe": "light-dark(oklch(80% 0.05 145), oklch(45% 0.09 145))"
61
+ "cssRecipe": "light-dark(oklch(80% 0.05 145), oklch(45% 0.09 145))",
62
+ "palette": {
63
+ "family": "success",
64
+ "role": "border"
65
+ }
54
66
  }
55
67
  }
56
68
  },
@@ -100,7 +112,11 @@
100
112
  "cssProperty": "--cinder-status-warning-background",
101
113
  "public": true,
102
114
  "category": "color",
103
- "cssRecipe": "light-dark(oklch(94.5% 0.042 75), oklch(28% 0.06 75))"
115
+ "cssRecipe": "light-dark(oklch(94.5% 0.042 75), oklch(28% 0.06 75))",
116
+ "palette": {
117
+ "family": "warning",
118
+ "role": "background"
119
+ }
104
120
  }
105
121
  }
106
122
  },
@@ -116,7 +132,11 @@
116
132
  "cssProperty": "--cinder-status-warning-text",
117
133
  "public": true,
118
134
  "category": "color",
119
- "cssRecipe": "light-dark(oklch(40% 0.085 75), oklch(90% 0.08 75))"
135
+ "cssRecipe": "light-dark(oklch(40% 0.085 75), oklch(90% 0.08 75))",
136
+ "palette": {
137
+ "family": "warning",
138
+ "role": "text"
139
+ }
120
140
  }
121
141
  }
122
142
  },
@@ -132,7 +152,11 @@
132
152
  "cssProperty": "--cinder-status-warning-border",
133
153
  "public": true,
134
154
  "category": "color",
135
- "cssRecipe": "light-dark(oklch(80% 0.06 75), oklch(50% 0.1 75))"
155
+ "cssRecipe": "light-dark(oklch(80% 0.06 75), oklch(50% 0.1 75))",
156
+ "palette": {
157
+ "family": "warning",
158
+ "role": "border"
159
+ }
136
160
  }
137
161
  }
138
162
  },
@@ -182,7 +206,11 @@
182
206
  "cssProperty": "--cinder-status-neutral-background",
183
207
  "public": true,
184
208
  "category": "color",
185
- "cssRecipe": "light-dark(oklch(94.5% 0.004 255), oklch(28% 0.04 245))"
209
+ "cssRecipe": "light-dark(oklch(94.5% 0.004 255), oklch(28% 0.04 245))",
210
+ "palette": {
211
+ "family": "neutral",
212
+ "role": "status-neutral-background"
213
+ }
186
214
  }
187
215
  }
188
216
  },
@@ -226,7 +254,11 @@
226
254
  "cssProperty": "--cinder-status-danger-background",
227
255
  "public": true,
228
256
  "category": "color",
229
- "cssRecipe": "light-dark(oklch(94.5% 0.026 25), oklch(28% 0.09 25))"
257
+ "cssRecipe": "light-dark(oklch(94.5% 0.026 25), oklch(28% 0.09 25))",
258
+ "palette": {
259
+ "family": "danger",
260
+ "role": "background"
261
+ }
230
262
  }
231
263
  }
232
264
  },
@@ -242,7 +274,11 @@
242
274
  "cssProperty": "--cinder-status-danger-text",
243
275
  "public": true,
244
276
  "category": "color",
245
- "cssRecipe": "light-dark(oklch(42% 0.16 25), oklch(90% 0.05 25))"
277
+ "cssRecipe": "light-dark(oklch(42% 0.16 25), oklch(90% 0.05 25))",
278
+ "palette": {
279
+ "family": "danger",
280
+ "role": "text"
281
+ }
246
282
  }
247
283
  }
248
284
  },
@@ -258,7 +294,11 @@
258
294
  "cssProperty": "--cinder-status-danger-border",
259
295
  "public": true,
260
296
  "category": "color",
261
- "cssRecipe": "light-dark(oklch(80% 0.06 25), oklch(50% 0.11 25))"
297
+ "cssRecipe": "light-dark(oklch(80% 0.06 25), oklch(50% 0.11 25))",
298
+ "palette": {
299
+ "family": "danger",
300
+ "role": "border"
301
+ }
262
302
  }
263
303
  }
264
304
  },
@@ -308,7 +348,11 @@
308
348
  "cssProperty": "--cinder-status-info-background",
309
349
  "public": true,
310
350
  "category": "color",
311
- "cssRecipe": "light-dark(oklch(94.5% 0.03 230), oklch(28% 0.057 230))"
351
+ "cssRecipe": "light-dark(oklch(94.5% 0.03 230), oklch(28% 0.057 230))",
352
+ "palette": {
353
+ "family": "info",
354
+ "role": "background"
355
+ }
312
356
  }
313
357
  }
314
358
  },
@@ -324,7 +368,11 @@
324
368
  "cssProperty": "--cinder-status-info-text",
325
369
  "public": true,
326
370
  "category": "color",
327
- "cssRecipe": "light-dark(oklch(40% 0.079 230), oklch(88% 0.071 230))"
371
+ "cssRecipe": "light-dark(oklch(40% 0.079 230), oklch(88% 0.071 230))",
372
+ "palette": {
373
+ "family": "info",
374
+ "role": "text"
375
+ }
328
376
  }
329
377
  }
330
378
  },
@@ -340,7 +388,11 @@
340
388
  "cssProperty": "--cinder-status-info-border",
341
389
  "public": true,
342
390
  "category": "color",
343
- "cssRecipe": "light-dark(oklch(80% 0.05 230), oklch(45% 0.08 230))"
391
+ "cssRecipe": "light-dark(oklch(80% 0.05 230), oklch(45% 0.08 230))",
392
+ "palette": {
393
+ "family": "info",
394
+ "role": "border"
395
+ }
344
396
  }
345
397
  }
346
398
  },