@astryxdesign/cli 0.7.15 → 0.7.16-canary.g54dd64e

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 (123) hide show
  1. package/README.md +5 -3
  2. package/api/component/_adapter.d.mts +1 -1
  3. package/api/component/_adapter.mjs +28 -1
  4. package/api/doctor/_adapter.d.mts +17 -0
  5. package/api/doctor/_adapter.mjs +35 -0
  6. package/api/doctor/doctor.mjs +18 -4
  7. package/api/integration/pack-check.mjs +13 -7
  8. package/api/integration/validate-integration.mjs +1 -1
  9. package/api/theme/_adapter.d.mts +5 -2
  10. package/api/theme/_adapter.mjs +43 -12
  11. package/api/theme/build/build.d.mts +64 -27
  12. package/api/theme/build/build.mjs +341 -69
  13. package/api/theme/eject/eject.mjs +22 -1
  14. package/api/theme/template/template.d.mts +19 -0
  15. package/api/theme/template/template.mjs +102 -25
  16. package/api/theme/theme.type.d.mts +5 -1
  17. package/api/theme/theme.type.mjs +2 -1
  18. package/api/theme/themeBuild.doc.mjs +3 -3
  19. package/api/theme/themeEject.doc.mjs +1 -1
  20. package/api/theme/themeTemplate.doc.mjs +9 -3
  21. package/api/theme-edit/_adapter.d.mts +33 -0
  22. package/api/theme-edit/_adapter.mjs +208 -31
  23. package/api/theme-edit/_check.d.mts +38 -0
  24. package/api/theme-edit/_check.mjs +1326 -211
  25. package/api/theme-edit/_color.d.mts +2 -8
  26. package/api/theme-edit/_color.mjs +292 -219
  27. package/api/theme-edit/_compiler.d.mts +1 -0
  28. package/api/theme-edit/_compiler.mjs +20 -1
  29. package/api/theme-edit/_context.d.mts +29 -0
  30. package/api/theme-edit/_context.mjs +329 -30
  31. package/api/theme-edit/_css.d.mts +60 -1
  32. package/api/theme-edit/_css.mjs +404 -28
  33. package/api/theme-edit/_edit.d.mts +9 -0
  34. package/api/theme-edit/_edit.mjs +1025 -126
  35. package/api/theme-edit/_how-commands.d.mts +11 -26
  36. package/api/theme-edit/_how-commands.mjs +30 -2
  37. package/api/theme-edit/_how-question.d.mts +7 -0
  38. package/api/theme-edit/_how-question.mjs +1304 -176
  39. package/api/theme-edit/_how.mjs +144 -30
  40. package/api/theme-edit/_overview.mjs +2 -0
  41. package/api/theme-edit/_palette.d.mts +11 -0
  42. package/api/theme-edit/_palette.mjs +194 -65
  43. package/api/theme-edit/_parts.d.mts +16 -0
  44. package/api/theme-edit/_parts.mjs +59 -7
  45. package/api/theme-edit/_png.mjs +19 -14
  46. package/api/theme-edit/_preview-app.d.mts +3 -0
  47. package/api/theme-edit/_preview-app.mjs +843 -45
  48. package/api/theme-edit/_preview.d.mts +16 -3
  49. package/api/theme-edit/_preview.mjs +310 -29
  50. package/api/theme-edit/_project.d.mts +11 -0
  51. package/api/theme-edit/_project.mjs +46 -12
  52. package/api/theme-edit/_settings.d.mts +178 -5
  53. package/api/theme-edit/_settings.mjs +2035 -86
  54. package/api/theme-edit/_tables.d.mts +24 -0
  55. package/api/theme-edit/_tables.mjs +211 -149
  56. package/api/theme-edit/_vet.d.mts +42 -0
  57. package/api/theme-edit/_vet.mjs +144 -0
  58. package/api/theme-edit/theme-edit.type.d.mts +2 -1
  59. package/api/theme-edit/theme-edit.type.mjs +1 -1
  60. package/api/theme-edit/themeEditNew.doc.mjs +1 -1
  61. package/api/theme-edit/themeEditShow.doc.mjs +11 -3
  62. package/api/upgrade/registry/registry.mjs +6 -1
  63. package/assets/docs/tree/single-component.doc.mjs +11 -2
  64. package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
  65. package/assets/docs.generated.json +2 -2
  66. package/assets/preview-app/next.config.mjs +7 -1
  67. package/assets/preview-app/package.json +1 -0
  68. package/assets/preview-app/src/app/globals.css +1 -0
  69. package/assets/self-audit.generated.json +1 -1
  70. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
  71. package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
  72. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
  73. package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
  74. package/assets/templates/components.generated.json +1 -1
  75. package/assets/templates/pages/dashboard/page.tsx +1 -1
  76. package/authoring/doctypes/_schema.d.mts +52 -5
  77. package/authoring/doctypes/_schema.mjs +62 -7
  78. package/authoring/doctypes/base/type.ts +10 -0
  79. package/authoring/doctypes/component/component.doc.mjs +1 -1
  80. package/authoring/doctypes/function/function.doc.mjs +6 -0
  81. package/authoring/doctypes/function/type.ts +3 -0
  82. package/authoring/doctypes/legacy.mjs +5 -1
  83. package/authoring/index.d.ts +1 -0
  84. package/clients/cli/build-id.generated.json +1 -1
  85. package/clients/cli/commands/doctor.doc.mjs +2 -2
  86. package/clients/cli/commands/experimental/theme.mjs +190 -37
  87. package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
  88. package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
  89. package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
  90. package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
  91. package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
  92. package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
  93. package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
  94. package/clients/cli/commands/theme-build.doc.mjs +2 -2
  95. package/clients/cli/commands/theme-eject.doc.mjs +1 -1
  96. package/clients/cli/commands/theme-template.doc.mjs +3 -1
  97. package/clients/cli/commands/theme.mjs +168 -45
  98. package/clients/cli/formatters/index.mjs +7 -4
  99. package/clients/cli/lib/cli-error.mjs +9 -3
  100. package/clients/cli/lib/component-format.mjs +27 -9
  101. package/clients/cli/lib/json-shim.mjs +40 -2
  102. package/clients/cli/manifest.generated.json +1 -1
  103. package/clients/cli/run.mjs +49 -0
  104. package/foundation/config/project.mjs +50 -14
  105. package/foundation/discovery/theme-discovery.d.mts +5 -1
  106. package/foundation/discovery/theme-discovery.mjs +24 -3
  107. package/foundation/fs/gather-cache.d.mts +9 -2
  108. package/foundation/fs/gather-cache.mjs +79 -15
  109. package/foundation/fs/paths.d.mts +31 -0
  110. package/foundation/fs/paths.mjs +43 -10
  111. package/foundation/render/host-exit.d.mts +8 -0
  112. package/foundation/render/host-exit.mjs +11 -0
  113. package/foundation/render/page-host.mjs +56 -10
  114. package/foundation/render/page-worker.mjs +14 -0
  115. package/foundation/render/render-page.mjs +37 -2
  116. package/foundation/response/error-codes.d.mts +2 -1
  117. package/foundation/response/error-codes.d.ts +1 -0
  118. package/foundation/response/error-codes.doc.mjs +5 -0
  119. package/foundation/response/error-codes.mjs +3 -0
  120. package/foundation/response/json.d.mts +15 -0
  121. package/foundation/response/json.mjs +52 -1
  122. package/foundation/response/response-types.doc.mjs +1 -1
  123. package/package.json +7 -6
@@ -8,163 +8,173 @@
8
8
  * @position api/theme-edit — pure helpers
9
9
  */
10
10
 
11
- import {CSS_WIDE} from './_tables.mjs';
12
- import {MATH_FUNCTION, matchType} from './_css.mjs';
11
+ import {CSS_WIDE, wordTable} from './_tables.mjs';
12
+ import {
13
+ MATH_FUNCTION,
14
+ cssNumber,
15
+ keywordsOf,
16
+ matchType,
17
+ splitTop,
18
+ } from './_css.mjs';
19
+
20
+ export {splitTop};
13
21
  import {luminance, oklabToLinearRgb} from '../theme/palette/generate/color.mjs';
14
22
 
15
23
  /** @typedef {[number, number, number]} Rgb */
16
24
 
17
25
  /** The CSS named colors. */
18
- const NAMED = /** @type {Record<string, string>} */ ({
19
- aliceblue: '#f0f8ff',
20
- antiquewhite: '#faebd7',
21
- aqua: '#00ffff',
22
- aquamarine: '#7fffd4',
23
- azure: '#f0ffff',
24
- beige: '#f5f5dc',
25
- bisque: '#ffe4c4',
26
- black: '#000000',
27
- blanchedalmond: '#ffebcd',
28
- blue: '#0000ff',
29
- blueviolet: '#8a2be2',
30
- brown: '#a52a2a',
31
- burlywood: '#deb887',
32
- cadetblue: '#5f9ea0',
33
- chartreuse: '#7fff00',
34
- chocolate: '#d2691e',
35
- coral: '#ff7f50',
36
- cornflowerblue: '#6495ed',
37
- cornsilk: '#fff8dc',
38
- crimson: '#dc143c',
39
- cyan: '#00ffff',
40
- darkblue: '#00008b',
41
- darkcyan: '#008b8b',
42
- darkgoldenrod: '#b8860b',
43
- darkgray: '#a9a9a9',
44
- darkgreen: '#006400',
45
- darkgrey: '#a9a9a9',
46
- darkkhaki: '#bdb76b',
47
- darkmagenta: '#8b008b',
48
- darkolivegreen: '#556b2f',
49
- darkorange: '#ff8c00',
50
- darkorchid: '#9932cc',
51
- darkred: '#8b0000',
52
- darksalmon: '#e9967a',
53
- darkseagreen: '#8fbc8f',
54
- darkslateblue: '#483d8b',
55
- darkslategray: '#2f4f4f',
56
- darkslategrey: '#2f4f4f',
57
- darkturquoise: '#00ced1',
58
- darkviolet: '#9400d3',
59
- deeppink: '#ff1493',
60
- deepskyblue: '#00bfff',
61
- dimgray: '#696969',
62
- dimgrey: '#696969',
63
- dodgerblue: '#1e90ff',
64
- firebrick: '#b22222',
65
- floralwhite: '#fffaf0',
66
- forestgreen: '#228b22',
67
- fuchsia: '#ff00ff',
68
- gainsboro: '#dcdcdc',
69
- ghostwhite: '#f8f8ff',
70
- gold: '#ffd700',
71
- goldenrod: '#daa520',
72
- gray: '#808080',
73
- green: '#008000',
74
- greenyellow: '#adff2f',
75
- grey: '#808080',
76
- honeydew: '#f0fff0',
77
- hotpink: '#ff69b4',
78
- indianred: '#cd5c5c',
79
- indigo: '#4b0082',
80
- ivory: '#fffff0',
81
- khaki: '#f0e68c',
82
- lavender: '#e6e6fa',
83
- lavenderblush: '#fff0f5',
84
- lawngreen: '#7cfc00',
85
- lemonchiffon: '#fffacd',
86
- lightblue: '#add8e6',
87
- lightcoral: '#f08080',
88
- lightcyan: '#e0ffff',
89
- lightgoldenrodyellow: '#fafad2',
90
- lightgray: '#d3d3d3',
91
- lightgreen: '#90ee90',
92
- lightgrey: '#d3d3d3',
93
- lightpink: '#ffb6c1',
94
- lightsalmon: '#ffa07a',
95
- lightseagreen: '#20b2aa',
96
- lightskyblue: '#87cefa',
97
- lightslategray: '#778899',
98
- lightslategrey: '#778899',
99
- lightsteelblue: '#b0c4de',
100
- lightyellow: '#ffffe0',
101
- lime: '#00ff00',
102
- limegreen: '#32cd32',
103
- linen: '#faf0e6',
104
- magenta: '#ff00ff',
105
- maroon: '#800000',
106
- mediumaquamarine: '#66cdaa',
107
- mediumblue: '#0000cd',
108
- mediumorchid: '#ba55d3',
109
- mediumpurple: '#9370db',
110
- mediumseagreen: '#3cb371',
111
- mediumslateblue: '#7b68ee',
112
- mediumspringgreen: '#00fa9a',
113
- mediumturquoise: '#48d1cc',
114
- mediumvioletred: '#c71585',
115
- midnightblue: '#191970',
116
- mintcream: '#f5fffa',
117
- mistyrose: '#ffe4e1',
118
- moccasin: '#ffe4b5',
119
- navajowhite: '#ffdead',
120
- navy: '#000080',
121
- oldlace: '#fdf5e6',
122
- olive: '#808000',
123
- olivedrab: '#6b8e23',
124
- orange: '#ffa500',
125
- orangered: '#ff4500',
126
- orchid: '#da70d6',
127
- palegoldenrod: '#eee8aa',
128
- palegreen: '#98fb98',
129
- paleturquoise: '#afeeee',
130
- palevioletred: '#db7093',
131
- papayawhip: '#ffefd5',
132
- peachpuff: '#ffdab9',
133
- peru: '#cd853f',
134
- pink: '#ffc0cb',
135
- plum: '#dda0dd',
136
- powderblue: '#b0e0e6',
137
- purple: '#800080',
138
- rebeccapurple: '#663399',
139
- red: '#ff0000',
140
- rosybrown: '#bc8f8f',
141
- royalblue: '#4169e1',
142
- saddlebrown: '#8b4513',
143
- salmon: '#fa8072',
144
- sandybrown: '#f4a460',
145
- seagreen: '#2e8b57',
146
- seashell: '#fff5ee',
147
- sienna: '#a0522d',
148
- silver: '#c0c0c0',
149
- skyblue: '#87ceeb',
150
- slateblue: '#6a5acd',
151
- slategray: '#708090',
152
- slategrey: '#708090',
153
- snow: '#fffafa',
154
- springgreen: '#00ff7f',
155
- steelblue: '#4682b4',
156
- tan: '#d2b48c',
157
- teal: '#008080',
158
- thistle: '#d8bfd8',
159
- tomato: '#ff6347',
160
- turquoise: '#40e0d0',
161
- violet: '#ee82ee',
162
- wheat: '#f5deb3',
163
- white: '#ffffff',
164
- whitesmoke: '#f5f5f5',
165
- yellow: '#ffff00',
166
- yellowgreen: '#9acd32',
167
- });
26
+ const NAMED = wordTable(
27
+ /** @type {Record<string, string>} */ ({
28
+ aliceblue: '#f0f8ff',
29
+ antiquewhite: '#faebd7',
30
+ aqua: '#00ffff',
31
+ aquamarine: '#7fffd4',
32
+ azure: '#f0ffff',
33
+ beige: '#f5f5dc',
34
+ bisque: '#ffe4c4',
35
+ black: '#000000',
36
+ blanchedalmond: '#ffebcd',
37
+ blue: '#0000ff',
38
+ blueviolet: '#8a2be2',
39
+ brown: '#a52a2a',
40
+ burlywood: '#deb887',
41
+ cadetblue: '#5f9ea0',
42
+ chartreuse: '#7fff00',
43
+ chocolate: '#d2691e',
44
+ coral: '#ff7f50',
45
+ cornflowerblue: '#6495ed',
46
+ cornsilk: '#fff8dc',
47
+ crimson: '#dc143c',
48
+ cyan: '#00ffff',
49
+ darkblue: '#00008b',
50
+ darkcyan: '#008b8b',
51
+ darkgoldenrod: '#b8860b',
52
+ darkgray: '#a9a9a9',
53
+ darkgreen: '#006400',
54
+ darkgrey: '#a9a9a9',
55
+ darkkhaki: '#bdb76b',
56
+ darkmagenta: '#8b008b',
57
+ darkolivegreen: '#556b2f',
58
+ darkorange: '#ff8c00',
59
+ darkorchid: '#9932cc',
60
+ darkred: '#8b0000',
61
+ darksalmon: '#e9967a',
62
+ darkseagreen: '#8fbc8f',
63
+ darkslateblue: '#483d8b',
64
+ darkslategray: '#2f4f4f',
65
+ darkslategrey: '#2f4f4f',
66
+ darkturquoise: '#00ced1',
67
+ darkviolet: '#9400d3',
68
+ deeppink: '#ff1493',
69
+ deepskyblue: '#00bfff',
70
+ dimgray: '#696969',
71
+ dimgrey: '#696969',
72
+ dodgerblue: '#1e90ff',
73
+ firebrick: '#b22222',
74
+ floralwhite: '#fffaf0',
75
+ forestgreen: '#228b22',
76
+ fuchsia: '#ff00ff',
77
+ gainsboro: '#dcdcdc',
78
+ ghostwhite: '#f8f8ff',
79
+ gold: '#ffd700',
80
+ goldenrod: '#daa520',
81
+ gray: '#808080',
82
+ green: '#008000',
83
+ greenyellow: '#adff2f',
84
+ grey: '#808080',
85
+ honeydew: '#f0fff0',
86
+ hotpink: '#ff69b4',
87
+ indianred: '#cd5c5c',
88
+ indigo: '#4b0082',
89
+ ivory: '#fffff0',
90
+ khaki: '#f0e68c',
91
+ lavender: '#e6e6fa',
92
+ lavenderblush: '#fff0f5',
93
+ lawngreen: '#7cfc00',
94
+ lemonchiffon: '#fffacd',
95
+ lightblue: '#add8e6',
96
+ lightcoral: '#f08080',
97
+ lightcyan: '#e0ffff',
98
+ lightgoldenrodyellow: '#fafad2',
99
+ lightgray: '#d3d3d3',
100
+ lightgreen: '#90ee90',
101
+ lightgrey: '#d3d3d3',
102
+ lightpink: '#ffb6c1',
103
+ lightsalmon: '#ffa07a',
104
+ lightseagreen: '#20b2aa',
105
+ lightskyblue: '#87cefa',
106
+ lightslategray: '#778899',
107
+ lightslategrey: '#778899',
108
+ lightsteelblue: '#b0c4de',
109
+ lightyellow: '#ffffe0',
110
+ lime: '#00ff00',
111
+ limegreen: '#32cd32',
112
+ linen: '#faf0e6',
113
+ magenta: '#ff00ff',
114
+ maroon: '#800000',
115
+ mediumaquamarine: '#66cdaa',
116
+ mediumblue: '#0000cd',
117
+ mediumorchid: '#ba55d3',
118
+ mediumpurple: '#9370db',
119
+ mediumseagreen: '#3cb371',
120
+ mediumslateblue: '#7b68ee',
121
+ mediumspringgreen: '#00fa9a',
122
+ mediumturquoise: '#48d1cc',
123
+ mediumvioletred: '#c71585',
124
+ midnightblue: '#191970',
125
+ mintcream: '#f5fffa',
126
+ mistyrose: '#ffe4e1',
127
+ moccasin: '#ffe4b5',
128
+ navajowhite: '#ffdead',
129
+ navy: '#000080',
130
+ oldlace: '#fdf5e6',
131
+ olive: '#808000',
132
+ olivedrab: '#6b8e23',
133
+ orange: '#ffa500',
134
+ orangered: '#ff4500',
135
+ orchid: '#da70d6',
136
+ palegoldenrod: '#eee8aa',
137
+ palegreen: '#98fb98',
138
+ paleturquoise: '#afeeee',
139
+ palevioletred: '#db7093',
140
+ papayawhip: '#ffefd5',
141
+ peachpuff: '#ffdab9',
142
+ peru: '#cd853f',
143
+ pink: '#ffc0cb',
144
+ plum: '#dda0dd',
145
+ powderblue: '#b0e0e6',
146
+ purple: '#800080',
147
+ rebeccapurple: '#663399',
148
+ red: '#ff0000',
149
+ rosybrown: '#bc8f8f',
150
+ royalblue: '#4169e1',
151
+ saddlebrown: '#8b4513',
152
+ salmon: '#fa8072',
153
+ sandybrown: '#f4a460',
154
+ seagreen: '#2e8b57',
155
+ seashell: '#fff5ee',
156
+ sienna: '#a0522d',
157
+ silver: '#c0c0c0',
158
+ skyblue: '#87ceeb',
159
+ slateblue: '#6a5acd',
160
+ slategray: '#708090',
161
+ slategrey: '#708090',
162
+ snow: '#fffafa',
163
+ springgreen: '#00ff7f',
164
+ steelblue: '#4682b4',
165
+ tan: '#d2b48c',
166
+ teal: '#008080',
167
+ thistle: '#d8bfd8',
168
+ tomato: '#ff6347',
169
+ turquoise: '#40e0d0',
170
+ violet: '#ee82ee',
171
+ wheat: '#f5deb3',
172
+ white: '#ffffff',
173
+ whitesmoke: '#f5f5f5',
174
+ yellow: '#ffff00',
175
+ yellowgreen: '#9acd32',
176
+ }),
177
+ );
168
178
 
169
179
  /** The CSS named colors, for suggestions. */
170
180
  export const COLOR_NAMES = Object.keys(NAMED);
@@ -275,11 +285,11 @@ const d50ToD65 = ([x, y, z]) => [
275
285
  /** One number with its unit, or null. @param {string} part @param {boolean} modern */
276
286
  function num(part, modern) {
277
287
  if (modern && part.toLowerCase() === 'none') return {n: 0, unit: ''};
278
- const m =
279
- /^([+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?)(%|deg|grad|rad|turn)?$/i.exec(
280
- part,
281
- );
282
- return m ? {n: Number(m[1]), unit: (m[2] ?? '').toLowerCase()} : null;
288
+ // Read as CSS reads a number: `255.` is none.
289
+ const c = cssNumber(part);
290
+ return c && ['', '%', 'deg', 'grad', 'rad', 'turn'].includes(c.unit)
291
+ ? {n: c.value, unit: c.unit}
292
+ : null;
283
293
  }
284
294
 
285
295
  /**
@@ -489,30 +499,6 @@ function linearToOklab([r, g, b]) {
489
499
  ];
490
500
  }
491
501
 
492
- /**
493
- * A value split at `sep` outside brackets: `a(b, c), d` by `,` is
494
- * [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
495
- * @param {string} v
496
- * @param {',' | ' '} sep
497
- * @returns {string[]}
498
- */
499
- export function splitTop(v, sep) {
500
- /** @type {string[]} */
501
- const out = [];
502
- let depth = 0;
503
- let cur = '';
504
- for (const c of v) {
505
- if (c === '(') depth++;
506
- if (c === ')') depth--;
507
- if (depth === 0 && (sep === ' ' ? /\s/.test(c) : c === sep)) {
508
- if (cur.trim() || sep === ',') out.push(cur);
509
- cur = '';
510
- } else cur += c;
511
- }
512
- if (cur.trim() || sep === ',') out.push(cur);
513
- return out.filter(x => sep === ',' || x.trim());
514
- }
515
-
516
502
  /**
517
503
  * One side of a color-mix(): the color, and the share written before or
518
504
  * after it at the top level (null when none). A percentage inside the
@@ -522,22 +508,19 @@ export function splitTop(v, sep) {
522
508
  */
523
509
  export function mixSide(side) {
524
510
  const words = splitTop(side.trim(), ' ');
525
- const share = (/** @type {string | undefined} */ w) =>
526
- w != null && /^-?\d*\.?\d+%$/.test(w) ? Number.parseFloat(w) : null;
527
- // A share outside 0-100% is invalid CSS: the side then names no color,
528
- // so the mix is refused rather than extrapolated.
511
+ // Any CSS percentage: an exponent or a sign (5e1%, +50%), or math that
512
+ // gives one percentage (calc(50%)).
513
+ const share = (/** @type {string | undefined} */ w) => {
514
+ if (w == null) return null;
515
+ const plain = /^calc\(\s*(.*?)\s*\)$/i.exec(w)?.[1] ?? w;
516
+ const n = cssNumber(plain);
517
+ return n?.unit === '%' ? n.value : null;
518
+ };
529
519
  if (words.length < 2) return {color: side.trim(), pct: null};
530
- const inRange = (/** @type {number} */ p) => p >= 0 && p <= 100;
531
520
  const last = share(words.at(-1));
532
- if (last != null)
533
- return inRange(last)
534
- ? {color: words.slice(0, -1).join(' '), pct: last}
535
- : {color: '', pct: null};
521
+ if (last != null) return {color: words.slice(0, -1).join(' '), pct: last};
536
522
  const first = share(words[0]);
537
- if (first != null)
538
- return inRange(first)
539
- ? {color: words.slice(1).join(' '), pct: first}
540
- : {color: '', pct: null};
523
+ if (first != null) return {color: words.slice(1).join(' '), pct: first};
541
524
  return {color: side.trim(), pct: null};
542
525
  }
543
526
 
@@ -548,9 +531,11 @@ export function mixSide(side) {
548
531
  * color with no fixed value, a space this reader does not mix in, or
549
532
  * shares that add up to 0.
550
533
  * @param {string} inner the arguments
534
+ * @param {boolean} [approx] mix a space this reader does not mix in as
535
+ * OKLab, for a suggestion only
551
536
  * @returns {{rgb: Rgb, alpha: number} | null}
552
537
  */
553
- function mixColor(inner) {
538
+ function mixColor(inner, approx = false) {
554
539
  const args = splitTop(inner, ',').map(x => x.trim());
555
540
  if (args.length !== 3) return null;
556
541
  const sp =
@@ -558,12 +543,15 @@ function mixColor(inner) {
558
543
  args[0],
559
544
  );
560
545
  const space = sp?.[1].toLowerCase() ?? '';
561
- if (!MIX_SPACES.includes(space)) return null;
546
+ if (!MIX_SPACES.includes(space) && !approx) return null;
562
547
  const hueWay = (sp?.[2] ?? 'shorter').toLowerCase();
548
+ const mixIn = MIX_SPACES.includes(space) ? space : 'oklab';
563
549
  const sides = args.slice(1).map(a => {
564
550
  const {color, pct} = mixSide(a);
565
551
  return {read: readColor(color), pct};
566
552
  });
553
+ // A share is 0% to 100%; past that the mix is no color at all.
554
+ if (sides.some(x => x.pct != null && (x.pct < 0 || x.pct > 100))) return null;
567
555
  if (sides.some(x => !x.read)) return null;
568
556
  let [p1, p2] = sides.map(x => x.pct);
569
557
  if (p1 == null && p2 == null) [p1, p2] = [50, 50];
@@ -578,10 +566,10 @@ function mixColor(inner) {
578
566
  );
579
567
  /** @param {Rgb} rgb @returns {number[]} */
580
568
  const into = rgb => {
581
- if (space === 'srgb') return rgb.map(c => c / 255);
569
+ if (mixIn === 'srgb') return rgb.map(c => c / 255);
582
570
  const lin = rgb.map(toLinear);
583
- if (space === 'srgb-linear') return lin;
584
- if (space === 'xyz' || space === 'xyz-d65')
571
+ if (mixIn === 'srgb-linear') return lin;
572
+ if (mixIn === 'xyz' || mixIn === 'xyz-d65')
585
573
  return [
586
574
  0.41239079926595934 * lin[0] +
587
575
  0.357584339383878 * lin[1] +
@@ -594,7 +582,7 @@ function mixColor(inner) {
594
582
  0.9505321522496607 * lin[2],
595
583
  ];
596
584
  const lab = linearToOklab(lin);
597
- if (space === 'oklab') return lab;
585
+ if (mixIn === 'oklab') return lab;
598
586
  const c = Math.hypot(lab[1], lab[2]);
599
587
  return [
600
588
  lab[0],
@@ -604,12 +592,12 @@ function mixColor(inner) {
604
592
  };
605
593
  /** @param {number[]} v @returns {Rgb} */
606
594
  const back = v => {
607
- if (space === 'srgb')
595
+ if (mixIn === 'srgb')
608
596
  return /** @type {Rgb} */ (v.map(c => clamp(c, 0, 1) * 255));
609
- if (space === 'srgb-linear') return fromLinear(v);
610
- if (space === 'xyz' || space === 'xyz-d65')
597
+ if (mixIn === 'srgb-linear') return fromLinear(v);
598
+ if (mixIn === 'xyz' || mixIn === 'xyz-d65')
611
599
  return colorSpaceToRgb('xyz-d65', v);
612
- if (space === 'oklab') return oklabToRgb(v[0], v[1], v[2]);
600
+ if (mixIn === 'oklab') return oklabToRgb(v[0], v[1], v[2]);
613
601
  const h = (v[2] * Math.PI) / 180;
614
602
  return oklabToRgb(v[0], v[1] * Math.cos(h), v[1] * Math.sin(h));
615
603
  };
@@ -618,7 +606,7 @@ function mixColor(inner) {
618
606
  // Premultiplied by alpha, as CSS mixes; a missing hue takes the other's.
619
607
  const alpha = a.alpha * w1 + b.alpha * w2;
620
608
  const out = x.map((_, i) => {
621
- if (space === 'oklch' && i === 2) {
609
+ if (mixIn === 'oklch' && i === 2) {
622
610
  let h1 = Number.isNaN(x[2]) ? y[2] : x[2];
623
611
  let h2 = Number.isNaN(y[2]) ? x[2] : y[2];
624
612
  if (Number.isNaN(h1)) return 0;
@@ -636,6 +624,21 @@ function mixColor(inner) {
636
624
  return {rgb: back(out), alpha: alpha * Math.min(1, total / 100)};
637
625
  }
638
626
 
627
+ /** The channel keywords of each relative color function, in order. */
628
+ const RELATIVE_CHANNELS = wordTable(
629
+ /** @type {Record<string, string>} */ ({
630
+ rgb: 'r g b',
631
+ rgba: 'r g b',
632
+ hsl: 'h s l',
633
+ hsla: 'h s l',
634
+ hwb: 'h w b',
635
+ lab: 'l a b',
636
+ lch: 'l c h',
637
+ oklab: 'l a b',
638
+ oklch: 'l c h',
639
+ }),
640
+ );
641
+
639
642
  /**
640
643
  * A fixed CSS color read as CSS Color 4 reads it: hues wrap, saturation,
641
644
  * whiteness, blackness and lightness clamp to their range, and chroma
@@ -660,6 +663,34 @@ function readColor(s) {
660
663
  if (named) return readColor(named);
661
664
  const fn = /^([a-z-]+)\((.*)\)$/i.exec(s);
662
665
  if (fn && fn[1].toLowerCase() === 'color-mix') return mixColor(fn[2]);
666
+ if (fn) {
667
+ const name = fn[1].toLowerCase();
668
+ // The same color in both modes is that color.
669
+ if (name === 'light-dark') {
670
+ const halves = splitTop(fn[2], ',').map(x => x.trim());
671
+ const [a, b] = halves.map(x => readColor(x));
672
+ return halves.length === 2 &&
673
+ a &&
674
+ b &&
675
+ hex(a.rgb) === hex(b.rgb) &&
676
+ a.alpha === b.alpha
677
+ ? a
678
+ : null;
679
+ }
680
+ // A relative color that keeps every channel as it is (rgb(from red r g
681
+ // b)) is its origin color.
682
+ const rel =
683
+ /^from\s+(.+?)\s+([a-z]+)\s+([a-z]+)\s+([a-z]+)(?:\s*\/\s*([a-z]+))?$/i.exec(
684
+ fn[2].trim(),
685
+ );
686
+ const keep = RELATIVE_CHANNELS[name];
687
+ if (rel && keep) {
688
+ const kept =
689
+ [rel[2], rel[3], rel[4]].map(x => x.toLowerCase()).join(' ') === keep &&
690
+ (rel[5] == null || rel[5].toLowerCase() === 'alpha');
691
+ return kept ? readColor(rel[1]) : null;
692
+ }
693
+ }
663
694
  if (!fn || !FIXED.test(fn[1])) return null;
664
695
  const name = fn[1].toLowerCase();
665
696
  if (name === 'color') {
@@ -800,11 +831,51 @@ export function colorProblem(value) {
800
831
  return {kind: 'malformed', message: 'is not a valid CSS color'};
801
832
  // A mix this reader cannot work out (another space, a color with no
802
833
  // fixed value) says so, rather than calling the mix unfixed.
803
- if (fn && fn[1].toLowerCase() === 'color-mix' && !/var\(|env\(/i.test(fn[2]))
834
+ if (
835
+ fn &&
836
+ fn[1].toLowerCase() === 'color-mix' &&
837
+ !/var\(|env\(/i.test(fn[2])
838
+ ) {
839
+ // The shares, beside each color (a color's own percentages aside).
840
+ const [space, ...sides] = splitTop(fn[2], ',').map(x => x.trim());
841
+ const parts = sides.map(mixSide);
842
+ if (parts.some(x => x.pct != null && (x.pct < 0 || x.pct > 100)))
843
+ return {
844
+ kind: 'malformed',
845
+ message:
846
+ 'has a color-mix() share outside 0% to 100%, which CSS does not take',
847
+ ...(() => {
848
+ const near = mixColor(
849
+ [
850
+ space,
851
+ ...parts.map(x =>
852
+ x.pct == null
853
+ ? x.color
854
+ : `${x.color} ${Math.max(0, Math.min(100, x.pct))}%`,
855
+ ),
856
+ ].join(', '),
857
+ );
858
+ return near ? {opaque: hex(near.rgb)} : {};
859
+ })(),
860
+ };
861
+ const near = mixColor(fn[2], true);
804
862
  return {
805
863
  kind: 'unfixed',
806
- message: `is a color-mix() this editor cannot work out (it mixes in ${MIX_SPACES.join(', ')}, from colors with fixed values); give the mixed color itself`,
864
+ message: `is a color-mix() this editor does not work out (it mixes in ${MIX_SPACES.join(', ')}, from colors with fixed values)${near ? `; mixed in oklab it is about ${hex(near.rgb)}` : ''}: give the mixed color itself`,
865
+ ...(near ? {opaque: hex(near.rgb)} : {}),
807
866
  };
867
+ }
868
+ // A relative color that changes its channels is not worked out here.
869
+ const rel =
870
+ fn && /^from\s+(.+?)\s+\S+\s+\S+\s+\S+(\s*\/.*)?$/i.exec(fn[2].trim());
871
+ if (rel && !/var\(|env\(/i.test(fn?.[2] ?? '')) {
872
+ const origin = readColor(rel[1]);
873
+ return {
874
+ kind: 'unfixed',
875
+ message: `is a relative color that changes its channels, which this editor does not work out${origin ? ` (it starts from ${hex(origin.rgb)})` : ''}: give the color itself`,
876
+ ...(origin ? {opaque: hex(origin.rgb)} : {}),
877
+ };
878
+ }
808
879
  if (isColorValue(s))
809
880
  return {
810
881
  kind: 'unfixed',
@@ -876,15 +947,13 @@ export const isColorValue = v => {
876
947
  */
877
948
  export const isSize = (v, name = '') => {
878
949
  const s = String(v).trim();
879
- const length =
880
- /^-?(\d+\.?\d*|\.\d+)(e-?\d+)?(px|rem|em|ex|ch|lh|rlh|cap|ic|pt|pc|cm|mm|in|q|%|vh|vw|vmin|vmax|dvh|dvw|svh|svw|lvh|lvw|cqw|cqh|cqi|cqb)$/i;
881
950
  if (s === '0') return true;
882
- // Only a property that takes a negative length gets one: an offset, a
883
- // letter spacing, an indent.
884
- if (length.test(s))
885
- return (
886
- !s.startsWith('-') || /offset|tracking|letter-spacing|indent/.test(name)
887
- );
951
+ // One length or percentage, read as CSS reads it (+4px, 4e+1px; never
952
+ // 1.px). Only a property that takes a negative length gets one: an
953
+ // offset, a letter spacing, an indent.
954
+ const n = cssNumber(s);
955
+ if (n && n.unit && matchType('length-percentage', s) != null)
956
+ return n.value >= 0 || /offset|tracking|letter-spacing|indent/.test(name);
888
957
  if (/^var\(--[a-z0-9-]+\)$/i.test(s)) return true;
889
958
  if (/^env\([a-z-]+(,.*)?\)$/i.test(s)) return true;
890
959
  return MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null;
@@ -900,20 +969,24 @@ export const isSize = (v, name = '') => {
900
969
  export const isNumber = (v, name = '') => {
901
970
  const s = String(v).trim();
902
971
  if (/^var\(--[a-z0-9-]+\)$/i.test(s)) return true;
972
+ const n = cssNumber(s);
973
+ // A weight: a font-weight keyword, or a number from 1 to 1000.
903
974
  if (/weight/.test(name))
904
975
  return (
905
- /^(normal|bold|bolder|lighter)$/.test(s) ||
906
- (/^\d+(\.\d+)?$/.test(s) && Number(s) >= 1 && Number(s) <= 1000) ||
976
+ keywordsOf('font-weight').includes(s.toLowerCase()) ||
977
+ (n?.unit === '' && n.value >= 1 && n.value <= 1000) ||
907
978
  (MATH_FUNCTION.test(s) && matchType('number', s) != null)
908
979
  );
909
980
  if (/leading|line-height/.test(name))
910
981
  return (
911
982
  s === 'normal' ||
912
- (/^\d*\.?\d+(px|rem|em|%)?$/.test(s) && Number.parseFloat(s) >= 0) ||
983
+ (n != null &&
984
+ ['', 'px', 'rem', 'em', '%'].includes(n.unit) &&
985
+ n.value >= 0) ||
913
986
  (MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null) ||
914
987
  (MATH_FUNCTION.test(s) && matchType('number', s) != null)
915
988
  );
916
- return /^-?\d*\.?\d+$/.test(s);
989
+ return n?.unit === '';
917
990
  };
918
991
 
919
992
  /**
@@ -12,6 +12,7 @@
12
12
  export function makeCompiler(project: import("./_project.mjs").ThemeProject, parts: PartData): {
13
13
  MAP: Record<string, import("./_parts.mjs").PartRecord>;
14
14
  typeOf: (tok: string) => string;
15
+ isToken: (tok: string) => boolean;
15
16
  propsReading: (tok: string) => string[];
16
17
  feeds: (target: string, token: string) => Array<{
17
18
  part: string;