@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.
- package/README.md +5 -3
- package/api/component/_adapter.d.mts +1 -1
- package/api/component/_adapter.mjs +28 -1
- package/api/doctor/_adapter.d.mts +17 -0
- package/api/doctor/_adapter.mjs +35 -0
- package/api/doctor/doctor.mjs +18 -4
- package/api/integration/pack-check.mjs +13 -7
- package/api/integration/validate-integration.mjs +1 -1
- package/api/theme/_adapter.d.mts +5 -2
- package/api/theme/_adapter.mjs +43 -12
- package/api/theme/build/build.d.mts +64 -27
- package/api/theme/build/build.mjs +341 -69
- package/api/theme/eject/eject.mjs +22 -1
- package/api/theme/template/template.d.mts +19 -0
- package/api/theme/template/template.mjs +102 -25
- package/api/theme/theme.type.d.mts +5 -1
- package/api/theme/theme.type.mjs +2 -1
- package/api/theme/themeBuild.doc.mjs +3 -3
- package/api/theme/themeEject.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +9 -3
- package/api/theme-edit/_adapter.d.mts +33 -0
- package/api/theme-edit/_adapter.mjs +208 -31
- package/api/theme-edit/_check.d.mts +38 -0
- package/api/theme-edit/_check.mjs +1326 -211
- package/api/theme-edit/_color.d.mts +2 -8
- package/api/theme-edit/_color.mjs +292 -219
- package/api/theme-edit/_compiler.d.mts +1 -0
- package/api/theme-edit/_compiler.mjs +20 -1
- package/api/theme-edit/_context.d.mts +29 -0
- package/api/theme-edit/_context.mjs +329 -30
- package/api/theme-edit/_css.d.mts +60 -1
- package/api/theme-edit/_css.mjs +404 -28
- package/api/theme-edit/_edit.d.mts +9 -0
- package/api/theme-edit/_edit.mjs +1025 -126
- package/api/theme-edit/_how-commands.d.mts +11 -26
- package/api/theme-edit/_how-commands.mjs +30 -2
- package/api/theme-edit/_how-question.d.mts +7 -0
- package/api/theme-edit/_how-question.mjs +1304 -176
- package/api/theme-edit/_how.mjs +144 -30
- package/api/theme-edit/_overview.mjs +2 -0
- package/api/theme-edit/_palette.d.mts +11 -0
- package/api/theme-edit/_palette.mjs +194 -65
- package/api/theme-edit/_parts.d.mts +16 -0
- package/api/theme-edit/_parts.mjs +59 -7
- package/api/theme-edit/_png.mjs +19 -14
- package/api/theme-edit/_preview-app.d.mts +3 -0
- package/api/theme-edit/_preview-app.mjs +843 -45
- package/api/theme-edit/_preview.d.mts +16 -3
- package/api/theme-edit/_preview.mjs +310 -29
- package/api/theme-edit/_project.d.mts +11 -0
- package/api/theme-edit/_project.mjs +46 -12
- package/api/theme-edit/_settings.d.mts +178 -5
- package/api/theme-edit/_settings.mjs +2035 -86
- package/api/theme-edit/_tables.d.mts +24 -0
- package/api/theme-edit/_tables.mjs +211 -149
- package/api/theme-edit/_vet.d.mts +42 -0
- package/api/theme-edit/_vet.mjs +144 -0
- package/api/theme-edit/theme-edit.type.d.mts +2 -1
- package/api/theme-edit/theme-edit.type.mjs +1 -1
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditShow.doc.mjs +11 -3
- package/api/upgrade/registry/registry.mjs +6 -1
- package/assets/docs/tree/single-component.doc.mjs +11 -2
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -2
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/preview-app/package.json +1 -0
- package/assets/preview-app/src/app/globals.css +1 -0
- package/assets/self-audit.generated.json +1 -1
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/ColumnsVirtualizationHookUsage.tsx +53 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Table/InfiniteScrollHookUsage.tsx +33 -0
- package/assets/templates/components.generated.json +1 -1
- package/assets/templates/pages/dashboard/page.tsx +1 -1
- package/authoring/doctypes/_schema.d.mts +52 -5
- package/authoring/doctypes/_schema.mjs +62 -7
- package/authoring/doctypes/base/type.ts +10 -0
- package/authoring/doctypes/component/component.doc.mjs +1 -1
- package/authoring/doctypes/function/function.doc.mjs +6 -0
- package/authoring/doctypes/function/type.ts +3 -0
- package/authoring/doctypes/legacy.mjs +5 -1
- package/authoring/index.d.ts +1 -0
- package/clients/cli/build-id.generated.json +1 -1
- package/clients/cli/commands/doctor.doc.mjs +2 -2
- package/clients/cli/commands/experimental/theme.mjs +190 -37
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-eject.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +3 -1
- package/clients/cli/commands/theme.mjs +168 -45
- package/clients/cli/formatters/index.mjs +7 -4
- package/clients/cli/lib/cli-error.mjs +9 -3
- package/clients/cli/lib/component-format.mjs +27 -9
- package/clients/cli/lib/json-shim.mjs +40 -2
- package/clients/cli/manifest.generated.json +1 -1
- package/clients/cli/run.mjs +49 -0
- package/foundation/config/project.mjs +50 -14
- package/foundation/discovery/theme-discovery.d.mts +5 -1
- package/foundation/discovery/theme-discovery.mjs +24 -3
- package/foundation/fs/gather-cache.d.mts +9 -2
- package/foundation/fs/gather-cache.mjs +79 -15
- package/foundation/fs/paths.d.mts +31 -0
- package/foundation/fs/paths.mjs +43 -10
- package/foundation/render/host-exit.d.mts +8 -0
- package/foundation/render/host-exit.mjs +11 -0
- package/foundation/render/page-host.mjs +56 -10
- package/foundation/render/page-worker.mjs +14 -0
- package/foundation/render/render-page.mjs +37 -2
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.d.ts +1 -0
- package/foundation/response/error-codes.doc.mjs +5 -0
- package/foundation/response/error-codes.mjs +3 -0
- package/foundation/response/json.d.mts +15 -0
- package/foundation/response/json.mjs +52 -1
- package/foundation/response/response-types.doc.mjs +1 -1
- 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 {
|
|
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 =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
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 (
|
|
569
|
+
if (mixIn === 'srgb') return rgb.map(c => c / 255);
|
|
582
570
|
const lin = rgb.map(toLinear);
|
|
583
|
-
if (
|
|
584
|
-
if (
|
|
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 (
|
|
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 (
|
|
595
|
+
if (mixIn === 'srgb')
|
|
608
596
|
return /** @type {Rgb} */ (v.map(c => clamp(c, 0, 1) * 255));
|
|
609
|
-
if (
|
|
610
|
-
if (
|
|
597
|
+
if (mixIn === 'srgb-linear') return fromLinear(v);
|
|
598
|
+
if (mixIn === 'xyz' || mixIn === 'xyz-d65')
|
|
611
599
|
return colorSpaceToRgb('xyz-d65', v);
|
|
612
|
-
if (
|
|
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 (
|
|
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 (
|
|
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
|
|
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
|
-
//
|
|
883
|
-
//
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
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
|
-
|
|
906
|
-
(
|
|
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
|
-
(
|
|
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
|
|
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;
|