@astryxdesign/cli 0.7.14 → 0.7.15-canary.g06b7e61
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/CHANGELOG.md +3 -3
- package/README.md +63 -63
- package/api/build/_adapter.d.mts +4 -0
- package/api/build/_adapter.mjs +28 -2
- package/api/build/blocks/blocks.d.mts +10 -1
- package/api/build/blocks/blocks.mjs +84 -7
- package/api/build/build.mjs +6 -1
- package/api/build/tree.d.mts +4 -0
- package/api/build/tree.mjs +9 -2
- package/api/doctor/_adapter.d.mts +3 -1
- package/api/doctor/_adapter.mjs +14 -1
- package/api/doctor/_authoring-audit.d.mts +42 -0
- package/api/doctor/_authoring-audit.mjs +106 -0
- package/api/doctor/doctor.d.mts +7 -0
- package/api/doctor/doctor.mjs +24 -39
- package/api/doctor/theme-checks.mjs +56 -21
- package/api/integration/add-helpers.mjs +5 -0
- package/api/integration/add-theme.mjs +15 -110
- package/api/integration/validate-integration.mjs +17 -3
- package/api/integration/validateIntegration.doc.mjs +1 -1
- package/api/search/_adapter.mjs +124 -3
- package/api/search/_candidate-score.mjs +63 -9
- package/api/search/_entries.d.mts +10 -0
- package/api/search/_entries.mjs +68 -1
- package/api/search/_gather-templates.d.mts +11 -0
- package/api/search/_gather-templates.mjs +22 -2
- package/api/search/_words.mjs +26 -6
- package/api/swizzle/copy/copy.mjs +1 -1
- package/api/theme/_adapter.d.mts +37 -5
- package/api/theme/_adapter.mjs +381 -57
- package/api/theme/_fork.d.mts +90 -0
- package/api/theme/_fork.mjs +246 -0
- package/api/theme/build/build.d.mts +40 -2
- package/api/theme/build/build.mjs +477 -66
- package/api/theme/eject/eject.mjs +36 -15
- package/api/theme/list/list.mjs +3 -6
- package/api/theme/palette/generate/generator.d.mts +13 -0
- package/api/theme/palette/generate/generator.mjs +32 -2
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +24 -4
- package/api/theme/template/template.mjs +48 -2
- package/api/theme/theme.type.d.mts +8 -0
- package/api/theme/theme.type.mjs +5 -1
- package/api/theme/themeBuild.doc.mjs +7 -4
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeRemove.doc.mjs +5 -2
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +2 -2
- package/api/theme/themeUse.doc.mjs +8 -2
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +496 -112
- package/api/theme-edit/_catalog.d.mts +1 -6
- package/api/theme-edit/_catalog.mjs +5 -268
- package/api/theme-edit/_check.d.mts +9 -4
- package/api/theme-edit/_check.mjs +1232 -229
- package/api/theme-edit/_color.d.mts +19 -0
- package/api/theme-edit/_color.mjs +280 -34
- package/api/theme-edit/_compiler.d.mts +3 -1
- package/api/theme-edit/_compiler.mjs +52 -13
- package/api/theme-edit/_context.d.mts +4 -1
- package/api/theme-edit/_context.mjs +126 -13
- package/api/theme-edit/_css.d.mts +84 -0
- package/api/theme-edit/_css.mjs +700 -0
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +806 -103
- package/api/theme-edit/_how-commands.d.mts +38 -7
- package/api/theme-edit/_how-commands.mjs +64 -45
- package/api/theme-edit/_how-question.d.mts +33 -0
- package/api/theme-edit/_how-question.mjs +2553 -381
- package/api/theme-edit/_how.mjs +402 -31
- package/api/theme-edit/_overview.mjs +2 -7
- package/api/theme-edit/_palette.d.mts +60 -13
- package/api/theme-edit/_palette.mjs +826 -295
- package/api/theme-edit/_parts.d.mts +42 -10
- package/api/theme-edit/_parts.mjs +280 -69
- package/api/theme-edit/_png.d.mts +4 -4
- package/api/theme-edit/_png.mjs +4 -2
- package/api/theme-edit/_preview-app.d.mts +14 -0
- package/api/theme-edit/_preview-app.mjs +1675 -235
- package/api/theme-edit/_preview.d.mts +7 -16
- package/api/theme-edit/_preview.mjs +79 -86
- package/api/theme-edit/_project.d.mts +32 -2
- package/api/theme-edit/_project.mjs +80 -19
- package/api/theme-edit/_settings.d.mts +199 -52
- package/api/theme-edit/_settings.mjs +1422 -217
- package/api/theme-edit/_tables.d.mts +19 -6
- package/api/theme-edit/_tables.mjs +150 -92
- package/api/theme-edit/theme-edit.type.d.mts +20 -1
- package/api/theme-edit/theme-edit.type.mjs +6 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- package/api/theme-edit/themeEditNew.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +1 -1
- package/api/theme-edit/themeEditPreviewList.doc.mjs +2 -2
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -1
- package/api/theme-edit/themeEditSet.doc.mjs +1 -1
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/api/upgrade/_adapter.d.mts +1 -0
- package/assets/codemods/run-codemod.mjs +61 -0
- package/assets/codemods/runner.mjs +5 -4
- package/assets/codemods/transforms/v0.0.14/rename-status-variants.mjs +3 -0
- package/assets/codemods/transforms/v0.1.8/rename-avatar-size-scale.mjs +5 -1
- package/assets/codemods/transforms/v0.6.4/migrate-native-picker-to-presentation.mjs +3 -0
- package/assets/codemods/transforms/v0.7.0/migrate-deprecated-theme-surface.mjs +4 -0
- package/assets/codemods/transforms/v0.7.0/rename-empty-search-results-text.mjs +17 -12
- package/assets/codemods/transforms/v0.7.2/migrate-list-edge-compensation-to-edge.mjs +3 -0
- package/assets/codemods/transforms/v0.7.5/migrate-codeblock-tokenizer-to-language.mjs +3 -0
- package/assets/codemods/transforms/v0.7.8/promote-tokenizer-presentation.mjs +3 -0
- package/assets/docs/tree/calendars.doc.mjs +1 -3
- package/assets/docs/tree/checks.doc.mjs +22 -1
- package/assets/docs/tree/publishing.doc.mjs +1 -0
- package/assets/docs/tree/tokens-and-setup.doc.mjs +39 -3
- package/assets/docs.generated.json +2 -1
- package/assets/preview-app/next.config.mjs +7 -1
- package/assets/self-audit.generated.json +1 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Theme/useThemeNameHookUsage.tsx +31 -0
- package/assets/templates/components.generated.json +1 -1
- package/authoring/integration/integration.doc.mjs +8 -0
- package/authoring/integration/schema.d.mts +8 -0
- package/authoring/integration/schema.mjs +1 -0
- package/authoring/integration/type.ts +9 -0
- package/clients/cli/bin/astryx.mjs +19 -15
- package/clients/cli/build-id.generated.json +1 -0
- package/clients/cli/commands/ensure-core-built.mjs +12 -5
- package/clients/cli/commands/experimental/index.mjs +10 -10
- package/clients/cli/commands/experimental/theme.mjs +200 -81
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +1 -2
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-remove.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-template.doc.mjs +4 -3
- package/clients/cli/commands/integration.mjs +8 -0
- package/clients/cli/commands/manifest.mjs +5 -2
- package/clients/cli/commands/theme-build.doc.mjs +2 -2
- package/clients/cli/commands/theme-list.doc.mjs +1 -1
- package/clients/cli/commands/theme-template.doc.mjs +1 -1
- package/clients/cli/commands/theme.mjs +439 -66
- package/clients/cli/index.mjs +27 -6
- package/clients/cli/lib/cli-error.mjs +118 -3
- package/clients/cli/lib/manifest.mjs +37 -0
- package/clients/cli/lib/resolve-theme.mjs +2 -1
- package/clients/cli/manifest.generated.json +1 -0
- package/foundation/config/project.mjs +34 -8
- package/foundation/config/theme-state.d.mts +16 -0
- package/foundation/config/theme-state.mjs +84 -13
- package/foundation/discovery/module-exports.mjs +16 -2
- package/foundation/discovery/stored-self-audit.d.mts +31 -0
- package/foundation/discovery/stored-self-audit.mjs +119 -0
- package/foundation/discovery/template-adapter.d.mts +48 -2
- package/foundation/discovery/template-adapter.mjs +51 -19
- package/foundation/discovery/template-needs.d.mts +19 -0
- package/foundation/discovery/template-needs.mjs +50 -16
- package/foundation/discovery/template-source-tree.d.mts +7 -0
- package/foundation/discovery/template-source-tree.mjs +15 -0
- package/foundation/discovery/theme-discovery.d.mts +2 -1
- package/foundation/discovery/theme-discovery.mjs +16 -10
- package/foundation/discovery/theme-imports.d.mts +16 -0
- package/foundation/discovery/theme-imports.mjs +30 -2
- package/foundation/discovery/theme-module-extensions.d.mts +18 -0
- package/foundation/discovery/theme-module-extensions.mjs +30 -0
- package/foundation/doc-compiler/import.mjs +22 -15
- package/foundation/doc-compiler/stored-docs.d.mts +18 -12
- package/foundation/doc-compiler/stored-docs.mjs +52 -19
- package/foundation/env/private-dir.d.mts +17 -0
- package/foundation/env/private-dir.mjs +42 -0
- package/foundation/fs/gather-cache.d.mts +108 -0
- package/foundation/fs/gather-cache.mjs +783 -0
- package/foundation/fs/jiti-cache.d.mts +21 -0
- package/foundation/fs/jiti-cache.mjs +66 -0
- package/foundation/fs/module-loader.mjs +14 -3
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +100 -7
- package/foundation/integrations/autolink.d.mts +1 -24
- package/foundation/integrations/autolink.mjs +7 -60
- package/foundation/integrations/declared-dependencies.d.mts +27 -0
- package/foundation/integrations/declared-dependencies.mjs +73 -0
- package/foundation/integrations/integrations.d.mts +8 -0
- package/foundation/integrations/integrations.mjs +4 -0
- package/foundation/integrations/may-have-integrations.d.mts +8 -0
- package/foundation/integrations/may-have-integrations.mjs +47 -0
- package/foundation/integrations/validate-contributions.d.mts +62 -1
- package/foundation/integrations/validate-contributions.mjs +476 -40
- package/foundation/release/cache.d.mts +32 -4
- package/foundation/release/cache.mjs +105 -16
- package/foundation/release/folder-lock.d.mts +28 -0
- package/foundation/release/folder-lock.mjs +205 -0
- package/foundation/release/lock-lease.d.mts +2 -1
- package/foundation/release/lock-lease.mjs +7 -2
- package/foundation/response/error-codes.doc.mjs +1 -1
- package/foundation/response/response-types.doc.mjs +5 -5
- package/package.json +8 -6
- package/api/theme-edit/_css-properties.d.mts +0 -10
- package/api/theme-edit/_css-properties.mjs +0 -556
|
@@ -16,6 +16,25 @@ export function alphaOf(value: unknown): number;
|
|
|
16
16
|
* @returns {Rgb}
|
|
17
17
|
*/
|
|
18
18
|
export function compositeOver(over: Rgb, alpha: number, under: Rgb): Rgb;
|
|
19
|
+
/**
|
|
20
|
+
* A value split at `sep` outside brackets: `a(b, c), d` by `,` is
|
|
21
|
+
* [`a(b, c)`, ` d`]. A space separator also splits runs of spaces.
|
|
22
|
+
* @param {string} v
|
|
23
|
+
* @param {',' | ' '} sep
|
|
24
|
+
* @returns {string[]}
|
|
25
|
+
*/
|
|
26
|
+
export function splitTop(v: string, sep: "," | " "): string[];
|
|
27
|
+
/**
|
|
28
|
+
* One side of a color-mix(): the color, and the share written before or
|
|
29
|
+
* after it at the top level (null when none). A percentage inside the
|
|
30
|
+
* color (`hsl(0 100% 50%) 30%`) is the color's own.
|
|
31
|
+
* @param {string} side
|
|
32
|
+
* @returns {{color: string, pct: number | null}}
|
|
33
|
+
*/
|
|
34
|
+
export function mixSide(side: string): {
|
|
35
|
+
color: string;
|
|
36
|
+
pct: number | null;
|
|
37
|
+
};
|
|
19
38
|
/**
|
|
20
39
|
* The RGB of a fixed CSS color: a hex, a named color, or rgb(), hsl(),
|
|
21
40
|
* hwb(), lab(), lch(), oklab(), oklch() or color() in srgb, srgb-linear or
|
|
@@ -8,6 +8,8 @@
|
|
|
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
13
|
import {luminance, oklabToLinearRgb} from '../theme/palette/generate/color.mjs';
|
|
12
14
|
|
|
13
15
|
/** @typedef {[number, number, number]} Rgb */
|
|
@@ -168,14 +170,7 @@ const NAMED = /** @type {Record<string, string>} */ ({
|
|
|
168
170
|
export const COLOR_NAMES = Object.keys(NAMED);
|
|
169
171
|
|
|
170
172
|
/** Color keywords that are valid colors but have no fixed value. */
|
|
171
|
-
const KEYWORDS = [
|
|
172
|
-
'transparent',
|
|
173
|
-
'currentcolor',
|
|
174
|
-
'inherit',
|
|
175
|
-
'initial',
|
|
176
|
-
'unset',
|
|
177
|
-
'revert',
|
|
178
|
-
];
|
|
173
|
+
const KEYWORDS = ['transparent', 'currentcolor', ...CSS_WIDE];
|
|
179
174
|
|
|
180
175
|
/** CSS system colors: valid, but they follow the user's device. */
|
|
181
176
|
const SYSTEM = [
|
|
@@ -208,7 +203,72 @@ const FUNCTIONS =
|
|
|
208
203
|
const FIXED = /^(rgba?|hsla?|hwb|lab|lch|oklab|oklch|color)$/i;
|
|
209
204
|
|
|
210
205
|
/** The `color()` spaces this reader converts to sRGB. */
|
|
211
|
-
const COLOR_SPACES = [
|
|
206
|
+
const COLOR_SPACES = [
|
|
207
|
+
'srgb',
|
|
208
|
+
'srgb-linear',
|
|
209
|
+
'display-p3',
|
|
210
|
+
'a98-rgb',
|
|
211
|
+
'prophoto-rgb',
|
|
212
|
+
'rec2020',
|
|
213
|
+
'xyz',
|
|
214
|
+
'xyz-d50',
|
|
215
|
+
'xyz-d65',
|
|
216
|
+
];
|
|
217
|
+
|
|
218
|
+
/** Each RGB space's transfer to linear light, and its matrix to XYZ D65 (D50 for ProPhoto). */
|
|
219
|
+
const RGB_SPACES =
|
|
220
|
+
/** @type {Record<string, {lin: (v: number) => number, m: number[][], d50?: boolean}>} */ ({
|
|
221
|
+
'display-p3': {
|
|
222
|
+
lin: v =>
|
|
223
|
+
Math.abs(v) <= 0.04045
|
|
224
|
+
? v / 12.92
|
|
225
|
+
: Math.sign(v) * ((Math.abs(v) + 0.055) / 1.055) ** 2.4,
|
|
226
|
+
m: [
|
|
227
|
+
[0.4865709486482162, 0.26566769316909306, 0.1982172852343625],
|
|
228
|
+
[0.2289745640697488, 0.6917385218365064, 0.079286914093745],
|
|
229
|
+
[0, 0.04511338185890264, 1.043944368900976],
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
'a98-rgb': {
|
|
233
|
+
lin: v => Math.sign(v) * Math.abs(v) ** (563 / 256),
|
|
234
|
+
m: [
|
|
235
|
+
[0.5766690429101305, 0.1855582379065463, 0.1882286462349947],
|
|
236
|
+
[0.29734497525053605, 0.6273635662554661, 0.0752914584939979],
|
|
237
|
+
[0.02703136138641234, 0.07068885253582723, 0.9913375368376388],
|
|
238
|
+
],
|
|
239
|
+
},
|
|
240
|
+
rec2020: {
|
|
241
|
+
lin: v => {
|
|
242
|
+
const a = 1.09929682680944;
|
|
243
|
+
const b = 0.018053968510807;
|
|
244
|
+
return Math.abs(v) < b * 4.5
|
|
245
|
+
? v / 4.5
|
|
246
|
+
: Math.sign(v) * ((Math.abs(v) + a - 1) / a) ** (1 / 0.45);
|
|
247
|
+
},
|
|
248
|
+
m: [
|
|
249
|
+
[0.6369580483012914, 0.14461690358620832, 0.1688809751641721],
|
|
250
|
+
[0.2627002120112671, 0.6779980715188708, 0.05930171646986196],
|
|
251
|
+
[0, 0.028072693049087428, 1.060985057710791],
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
'prophoto-rgb': {
|
|
255
|
+
lin: v =>
|
|
256
|
+
Math.abs(v) <= 16 / 512 ? v / 16 : Math.sign(v) * Math.abs(v) ** 1.8,
|
|
257
|
+
m: [
|
|
258
|
+
[0.7977604896723027, 0.13518583717574031, 0.0313493495815248],
|
|
259
|
+
[0.2880711282292934, 0.7118432178101014, 0.00008565396060525902],
|
|
260
|
+
[0, 0, 0.8251046025104601],
|
|
261
|
+
],
|
|
262
|
+
d50: true,
|
|
263
|
+
},
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
/** XYZ D50 to XYZ D65 (Bradford). @param {number[]} c */
|
|
267
|
+
const d50ToD65 = ([x, y, z]) => [
|
|
268
|
+
0.955473421488075 * x - 0.02309845494876471 * y + 0.06325924320057072 * z,
|
|
269
|
+
-0.0283697093338637 * x + 1.0099953980813041 * y + 0.021041441191917323 * z,
|
|
270
|
+
0.012314014864481998 * x - 0.020507649298898964 * y + 1.330365926242124 * z,
|
|
271
|
+
];
|
|
212
272
|
|
|
213
273
|
/** @typedef {{n: number, unit: string}} Num */
|
|
214
274
|
|
|
@@ -338,8 +398,8 @@ function oklabToRgb(l, a, b) {
|
|
|
338
398
|
}
|
|
339
399
|
|
|
340
400
|
/**
|
|
341
|
-
* A `color()` value in sRGB: srgb as it is,
|
|
342
|
-
* through linear light, clipped to the sRGB gamut.
|
|
401
|
+
* A `color()` value in sRGB: srgb as it is, the other RGB spaces and
|
|
402
|
+
* XYZ through linear light and XYZ D65, clipped to the sRGB gamut.
|
|
343
403
|
* @param {string} space @param {number[]} c 0..1
|
|
344
404
|
* @returns {Rgb}
|
|
345
405
|
*/
|
|
@@ -347,20 +407,17 @@ function colorSpaceToRgb(space, c) {
|
|
|
347
407
|
if (space === 'srgb')
|
|
348
408
|
return /** @type {Rgb} */ (c.map(v => clamp(v, 0, 1) * 255));
|
|
349
409
|
if (space === 'srgb-linear') return fromLinear(c);
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
0.6917385218365064 * lin[1] +
|
|
362
|
-
0.079286914093745 * lin[2];
|
|
363
|
-
const z = 0.04511338185890264 * lin[1] + 1.043944368900976 * lin[2];
|
|
410
|
+
/** @type {number[]} */
|
|
411
|
+
let xyz;
|
|
412
|
+
if (space === 'xyz' || space === 'xyz-d65') xyz = c;
|
|
413
|
+
else if (space === 'xyz-d50') xyz = d50ToD65(c);
|
|
414
|
+
else {
|
|
415
|
+
const rgb = RGB_SPACES[space];
|
|
416
|
+
const lin = c.map(rgb.lin);
|
|
417
|
+
const t = rgb.m.map(r => r[0] * lin[0] + r[1] * lin[1] + r[2] * lin[2]);
|
|
418
|
+
xyz = rgb.d50 ? d50ToD65(t) : t;
|
|
419
|
+
}
|
|
420
|
+
const [x, y, z] = xyz;
|
|
364
421
|
return fromLinear([
|
|
365
422
|
3.2409699419045226 * x - 1.537383177570094 * y - 0.4986107602930034 * z,
|
|
366
423
|
-0.9692436362808796 * x + 1.8759675015077202 * y + 0.04155505740717559 * z,
|
|
@@ -411,6 +468,174 @@ export function compositeOver(over, alpha, under) {
|
|
|
411
468
|
);
|
|
412
469
|
}
|
|
413
470
|
|
|
471
|
+
/** The color-mix() spaces this reader mixes in. */
|
|
472
|
+
const MIX_SPACES = ['srgb', 'srgb-linear', 'xyz', 'xyz-d65', 'oklab', 'oklch'];
|
|
473
|
+
|
|
474
|
+
/** An sRGB channel (0..255) in linear light. @param {number} c */
|
|
475
|
+
const toLinear = c => {
|
|
476
|
+
const v = c / 255;
|
|
477
|
+
return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
/** Linear sRGB to OKLab. @param {number[]} lin @returns {number[]} */
|
|
481
|
+
function linearToOklab([r, g, b]) {
|
|
482
|
+
const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
|
|
483
|
+
const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
|
|
484
|
+
const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
|
|
485
|
+
return [
|
|
486
|
+
0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
|
|
487
|
+
1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
|
|
488
|
+
0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
|
|
489
|
+
];
|
|
490
|
+
}
|
|
491
|
+
|
|
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
|
+
/**
|
|
517
|
+
* One side of a color-mix(): the color, and the share written before or
|
|
518
|
+
* after it at the top level (null when none). A percentage inside the
|
|
519
|
+
* color (`hsl(0 100% 50%) 30%`) is the color's own.
|
|
520
|
+
* @param {string} side
|
|
521
|
+
* @returns {{color: string, pct: number | null}}
|
|
522
|
+
*/
|
|
523
|
+
export function mixSide(side) {
|
|
524
|
+
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.
|
|
529
|
+
if (words.length < 2) return {color: side.trim(), pct: null};
|
|
530
|
+
const inRange = (/** @type {number} */ p) => p >= 0 && p <= 100;
|
|
531
|
+
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};
|
|
536
|
+
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};
|
|
541
|
+
return {color: side.trim(), pct: null};
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* The fixed color a color-mix() of two fixed colors gives, as CSS Color 5
|
|
546
|
+
* mixes them (shares that do not add up to 100% are scaled, and a total
|
|
547
|
+
* under 100% makes the result see-through), or null when it is not one: a
|
|
548
|
+
* color with no fixed value, a space this reader does not mix in, or
|
|
549
|
+
* shares that add up to 0.
|
|
550
|
+
* @param {string} inner the arguments
|
|
551
|
+
* @returns {{rgb: Rgb, alpha: number} | null}
|
|
552
|
+
*/
|
|
553
|
+
function mixColor(inner) {
|
|
554
|
+
const args = splitTop(inner, ',').map(x => x.trim());
|
|
555
|
+
if (args.length !== 3) return null;
|
|
556
|
+
const sp =
|
|
557
|
+
/^in\s+([a-z0-9-]+)(?:\s+(shorter|longer|increasing|decreasing)\s+hue)?$/i.exec(
|
|
558
|
+
args[0],
|
|
559
|
+
);
|
|
560
|
+
const space = sp?.[1].toLowerCase() ?? '';
|
|
561
|
+
if (!MIX_SPACES.includes(space)) return null;
|
|
562
|
+
const hueWay = (sp?.[2] ?? 'shorter').toLowerCase();
|
|
563
|
+
const sides = args.slice(1).map(a => {
|
|
564
|
+
const {color, pct} = mixSide(a);
|
|
565
|
+
return {read: readColor(color), pct};
|
|
566
|
+
});
|
|
567
|
+
if (sides.some(x => !x.read)) return null;
|
|
568
|
+
let [p1, p2] = sides.map(x => x.pct);
|
|
569
|
+
if (p1 == null && p2 == null) [p1, p2] = [50, 50];
|
|
570
|
+
else if (p1 == null) p1 = 100 - /** @type {number} */ (p2);
|
|
571
|
+
else if (p2 == null) p2 = 100 - p1;
|
|
572
|
+
const total = /** @type {number} */ (p1) + /** @type {number} */ (p2);
|
|
573
|
+
if (!(total > 0)) return null;
|
|
574
|
+
const w2 = /** @type {number} */ (p2) / total;
|
|
575
|
+
const w1 = 1 - w2;
|
|
576
|
+
const [a, b] = sides.map(
|
|
577
|
+
x => /** @type {{rgb: Rgb, alpha: number}} */ (x.read),
|
|
578
|
+
);
|
|
579
|
+
/** @param {Rgb} rgb @returns {number[]} */
|
|
580
|
+
const into = rgb => {
|
|
581
|
+
if (space === 'srgb') return rgb.map(c => c / 255);
|
|
582
|
+
const lin = rgb.map(toLinear);
|
|
583
|
+
if (space === 'srgb-linear') return lin;
|
|
584
|
+
if (space === 'xyz' || space === 'xyz-d65')
|
|
585
|
+
return [
|
|
586
|
+
0.41239079926595934 * lin[0] +
|
|
587
|
+
0.357584339383878 * lin[1] +
|
|
588
|
+
0.1804807884018343 * lin[2],
|
|
589
|
+
0.21263900587151027 * lin[0] +
|
|
590
|
+
0.715168678767756 * lin[1] +
|
|
591
|
+
0.07219231536073371 * lin[2],
|
|
592
|
+
0.01933081871559182 * lin[0] +
|
|
593
|
+
0.11919477979462598 * lin[1] +
|
|
594
|
+
0.9505321522496607 * lin[2],
|
|
595
|
+
];
|
|
596
|
+
const lab = linearToOklab(lin);
|
|
597
|
+
if (space === 'oklab') return lab;
|
|
598
|
+
const c = Math.hypot(lab[1], lab[2]);
|
|
599
|
+
return [
|
|
600
|
+
lab[0],
|
|
601
|
+
c,
|
|
602
|
+
c < 1e-6 ? NaN : (Math.atan2(lab[2], lab[1]) * 180) / Math.PI,
|
|
603
|
+
];
|
|
604
|
+
};
|
|
605
|
+
/** @param {number[]} v @returns {Rgb} */
|
|
606
|
+
const back = v => {
|
|
607
|
+
if (space === 'srgb')
|
|
608
|
+
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')
|
|
611
|
+
return colorSpaceToRgb('xyz-d65', v);
|
|
612
|
+
if (space === 'oklab') return oklabToRgb(v[0], v[1], v[2]);
|
|
613
|
+
const h = (v[2] * Math.PI) / 180;
|
|
614
|
+
return oklabToRgb(v[0], v[1] * Math.cos(h), v[1] * Math.sin(h));
|
|
615
|
+
};
|
|
616
|
+
const x = into(a.rgb);
|
|
617
|
+
const y = into(b.rgb);
|
|
618
|
+
// Premultiplied by alpha, as CSS mixes; a missing hue takes the other's.
|
|
619
|
+
const alpha = a.alpha * w1 + b.alpha * w2;
|
|
620
|
+
const out = x.map((_, i) => {
|
|
621
|
+
if (space === 'oklch' && i === 2) {
|
|
622
|
+
let h1 = Number.isNaN(x[2]) ? y[2] : x[2];
|
|
623
|
+
let h2 = Number.isNaN(y[2]) ? x[2] : y[2];
|
|
624
|
+
if (Number.isNaN(h1)) return 0;
|
|
625
|
+
const d = h2 - h1;
|
|
626
|
+
if (hueWay === 'shorter' && Math.abs(d) > 180) h2 += d > 0 ? -360 : 360;
|
|
627
|
+
if (hueWay === 'longer' && Math.abs(d) < 180 && d !== 0)
|
|
628
|
+
h2 += d > 0 ? -360 : 360;
|
|
629
|
+
if (hueWay === 'increasing' && h2 < h1) h2 += 360;
|
|
630
|
+
if (hueWay === 'decreasing' && h2 > h1) h2 -= 360;
|
|
631
|
+
return h1 * w1 + h2 * w2;
|
|
632
|
+
}
|
|
633
|
+
const mixed = x[i] * a.alpha * w1 + y[i] * b.alpha * w2;
|
|
634
|
+
return alpha > 0 ? mixed / alpha : 0;
|
|
635
|
+
});
|
|
636
|
+
return {rgb: back(out), alpha: alpha * Math.min(1, total / 100)};
|
|
637
|
+
}
|
|
638
|
+
|
|
414
639
|
/**
|
|
415
640
|
* A fixed CSS color read as CSS Color 4 reads it: hues wrap, saturation,
|
|
416
641
|
* whiteness, blackness and lightness clamp to their range, and chroma
|
|
@@ -434,6 +659,7 @@ function readColor(s) {
|
|
|
434
659
|
const named = NAMED[s.toLowerCase()];
|
|
435
660
|
if (named) return readColor(named);
|
|
436
661
|
const fn = /^([a-z-]+)\((.*)\)$/i.exec(s);
|
|
662
|
+
if (fn && fn[1].toLowerCase() === 'color-mix') return mixColor(fn[2]);
|
|
437
663
|
if (!fn || !FIXED.test(fn[1])) return null;
|
|
438
664
|
const name = fn[1].toLowerCase();
|
|
439
665
|
if (name === 'color') {
|
|
@@ -572,6 +798,13 @@ export function colorProblem(value) {
|
|
|
572
798
|
}
|
|
573
799
|
if (fn && FIXED.test(fn[1]) && !/var\(|calc\(|env\(|\bfrom\b/i.test(fn[2]))
|
|
574
800
|
return {kind: 'malformed', message: 'is not a valid CSS color'};
|
|
801
|
+
// A mix this reader cannot work out (another space, a color with no
|
|
802
|
+
// fixed value) says so, rather than calling the mix unfixed.
|
|
803
|
+
if (fn && fn[1].toLowerCase() === 'color-mix' && !/var\(|env\(/i.test(fn[2]))
|
|
804
|
+
return {
|
|
805
|
+
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`,
|
|
807
|
+
};
|
|
575
808
|
if (isColorValue(s))
|
|
576
809
|
return {
|
|
577
810
|
kind: 'unfixed',
|
|
@@ -607,6 +840,7 @@ export function ratio(a, b) {
|
|
|
607
840
|
* numbers must be well formed; one with `var()`, `calc()`, `env()` or a
|
|
608
841
|
* relative color is taken as written.
|
|
609
842
|
* @param {unknown} v
|
|
843
|
+
* @returns {boolean}
|
|
610
844
|
*/
|
|
611
845
|
export const isColorValue = v => {
|
|
612
846
|
const s = String(v).trim();
|
|
@@ -624,6 +858,9 @@ export const isColorValue = v => {
|
|
|
624
858
|
/^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(s) ||
|
|
625
859
|
FUNCTIONS.test(s) ||
|
|
626
860
|
/^var\(--[a-z0-9-]+\)$/i.test(s) ||
|
|
861
|
+
// A variable with a color to fall back to.
|
|
862
|
+
(/^var\(--[a-z0-9-]+\s*,\s*(.+)\)$/i.test(s) &&
|
|
863
|
+
isColorValue(/^var\(--[a-z0-9-]+\s*,\s*(.+)\)$/i.exec(s)?.[1] ?? '')) ||
|
|
627
864
|
Object.hasOwn(NAMED, s.toLowerCase()) ||
|
|
628
865
|
KEYWORDS.includes(s.toLowerCase()) ||
|
|
629
866
|
SYSTEM.includes(s.toLowerCase())
|
|
@@ -650,13 +887,13 @@ export const isSize = (v, name = '') => {
|
|
|
650
887
|
);
|
|
651
888
|
if (/^var\(--[a-z0-9-]+\)$/i.test(s)) return true;
|
|
652
889
|
if (/^env\([a-z-]+(,.*)?\)$/i.test(s)) return true;
|
|
653
|
-
return
|
|
890
|
+
return MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null;
|
|
654
891
|
};
|
|
655
892
|
|
|
656
893
|
/**
|
|
657
894
|
* Whether a value reads as a CSS number for the token: a weight is 1 to
|
|
658
|
-
* 1000 or a weight keyword; a line height is a
|
|
659
|
-
* percentage, or `normal`.
|
|
895
|
+
* 1000 or a weight keyword; a line height is a number, length or
|
|
896
|
+
* percentage of 0 or more, or `normal`.
|
|
660
897
|
* @param {unknown} v
|
|
661
898
|
* @param {string} [name]
|
|
662
899
|
*/
|
|
@@ -666,13 +903,15 @@ export const isNumber = (v, name = '') => {
|
|
|
666
903
|
if (/weight/.test(name))
|
|
667
904
|
return (
|
|
668
905
|
/^(normal|bold|bolder|lighter)$/.test(s) ||
|
|
669
|
-
(/^\d+(\.\d+)?$/.test(s) && Number(s) >= 1 && Number(s) <= 1000)
|
|
906
|
+
(/^\d+(\.\d+)?$/.test(s) && Number(s) >= 1 && Number(s) <= 1000) ||
|
|
907
|
+
(MATH_FUNCTION.test(s) && matchType('number', s) != null)
|
|
670
908
|
);
|
|
671
909
|
if (/leading|line-height/.test(name))
|
|
672
910
|
return (
|
|
673
911
|
s === 'normal' ||
|
|
674
|
-
(/^\d*\.?\d+(px|rem|em|%)?$/.test(s) && Number.parseFloat(s)
|
|
675
|
-
|
|
912
|
+
(/^\d*\.?\d+(px|rem|em|%)?$/.test(s) && Number.parseFloat(s) >= 0) ||
|
|
913
|
+
(MATH_FUNCTION.test(s) && matchType('length-percentage', s) != null) ||
|
|
914
|
+
(MATH_FUNCTION.test(s) && matchType('number', s) != null)
|
|
676
915
|
);
|
|
677
916
|
return /^-?\d*\.?\d+$/.test(s);
|
|
678
917
|
};
|
|
@@ -687,13 +926,20 @@ export const isNumber = (v, name = '') => {
|
|
|
687
926
|
export function isSafeValue(v) {
|
|
688
927
|
// A shell comment ("# direct"), as a command run without a shell passes
|
|
689
928
|
// it, is a comment too.
|
|
690
|
-
//
|
|
691
|
-
|
|
929
|
+
// `</` (a closing tag), control characters, comments and !important are
|
|
930
|
+
// refused anywhere; < and > only outside a quoted string.
|
|
931
|
+
// A tab is white space, as CSS reads it.
|
|
932
|
+
if (
|
|
933
|
+
// eslint-disable-next-line no-control-regex
|
|
934
|
+
/<\/|[\u0000-\u0008\u000a-\u001f\u007f]|\/\*|!important|(^|\s)#(\s|$)/i.test(
|
|
935
|
+
v,
|
|
936
|
+
)
|
|
937
|
+
)
|
|
692
938
|
return false;
|
|
693
939
|
const outside = v
|
|
694
940
|
.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'/g, '""')
|
|
695
941
|
.replace(/url\(data:[^\s"'()\\]*\)/gi, 'url()');
|
|
696
|
-
if (/[;{}
|
|
942
|
+
if (/[;{}\\<>]/.test(outside)) return false;
|
|
697
943
|
let depth = 0;
|
|
698
944
|
for (const c of outside.replace(/""/g, '')) {
|
|
699
945
|
if (c === '"' || c === "'") return false;
|
|
@@ -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
|
+
propsReading: (tok: string) => string[];
|
|
15
16
|
feeds: (target: string, token: string) => Array<{
|
|
16
17
|
part: string;
|
|
17
18
|
prop: string;
|
|
@@ -39,7 +40,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
|
|
|
39
40
|
alphaOf: (v: unknown) => number;
|
|
40
41
|
compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
|
|
41
42
|
page: (mode: string) => string | null | undefined;
|
|
42
|
-
}) => {
|
|
43
|
+
}, extra?: TextPair[]) => {
|
|
43
44
|
problems: {
|
|
44
45
|
part: string;
|
|
45
46
|
mode: string;
|
|
@@ -55,6 +56,7 @@ export function makeCompiler(project: import("./_project.mjs").ThemeProject, par
|
|
|
55
56
|
};
|
|
56
57
|
/** Only these token types may differ between light and dark. */
|
|
57
58
|
export const MODAL: Set<string>;
|
|
59
|
+
export function isColorToken(name: string): boolean;
|
|
58
60
|
export type Read = {
|
|
59
61
|
token: string;
|
|
60
62
|
props: string[];
|
|
@@ -10,10 +10,20 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import {DIRECT, GROUPS, HOW} from './_tables.mjs';
|
|
13
|
+
import {quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
13
14
|
|
|
14
15
|
/** Only these token types may differ between light and dark. */
|
|
15
16
|
export const MODAL = new Set(['color', 'shadow']);
|
|
16
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Whether a token is a color by its name, as Core's color groups and the
|
|
20
|
+
* token table type it: `--color-*`, `--syntax-*` and `--focus-outline-color`.
|
|
21
|
+
* Settings are checked by it where no installed Core is read.
|
|
22
|
+
* @param {string} name
|
|
23
|
+
*/
|
|
24
|
+
export const isColorToken = name =>
|
|
25
|
+
/^--color-|^--syntax-|^--focus-outline-color$/.test(name);
|
|
26
|
+
|
|
17
27
|
/** Tokens a component may read only in some states: never refused globally. */
|
|
18
28
|
/**
|
|
19
29
|
* Tokens no catalog part is recorded reading, though Core reads them: code
|
|
@@ -60,11 +70,10 @@ export function makeCompiler(project, parts) {
|
|
|
60
70
|
put(groupVars(core.easeVars), 'easing');
|
|
61
71
|
for (const k of Object.keys(core.tokenDefaults ?? {})) {
|
|
62
72
|
if (TYPE[k]) continue;
|
|
63
|
-
if (
|
|
73
|
+
if (isColorToken(k)) TYPE[k] = 'color';
|
|
64
74
|
else if (/^--font-family/.test(k)) TYPE[k] = 'font';
|
|
65
75
|
else if (/^--font-weight|^--text-.*-weight$/.test(k)) TYPE[k] = 'number';
|
|
66
76
|
else if (/^--shadow/.test(k)) TYPE[k] = 'shadow';
|
|
67
|
-
else if (/^--focus-outline-color/.test(k)) TYPE[k] = 'color';
|
|
68
77
|
else if (
|
|
69
78
|
/^--(radius|spacing|size|text-.*-size|border-width|focus-outline-(width|offset))/.test(
|
|
70
79
|
k,
|
|
@@ -230,9 +239,6 @@ export function makeCompiler(project, parts) {
|
|
|
230
239
|
.slice(0, 4)
|
|
231
240
|
.join(', ');
|
|
232
241
|
|
|
233
|
-
/** @param {string} v */
|
|
234
|
-
const quote = v => (/[\s"#(]/.test(v) ? `"${v.replace(/"/g, '\\"')}"` : v);
|
|
235
|
-
|
|
236
242
|
/**
|
|
237
243
|
* Whether a token set on a part can take effect there: the part, or a part
|
|
238
244
|
* inside it, must read it. A part with no record is checked through the
|
|
@@ -271,7 +277,7 @@ export function makeCompiler(project, parts) {
|
|
|
271
277
|
return null;
|
|
272
278
|
}
|
|
273
279
|
const reads = g ? partReads(target, g) : [];
|
|
274
|
-
const v =
|
|
280
|
+
const v = quoteCommandArgument(value);
|
|
275
281
|
/** @type {string[]} */
|
|
276
282
|
const run = [];
|
|
277
283
|
if (reads.length)
|
|
@@ -346,7 +352,7 @@ export function makeCompiler(project, parts) {
|
|
|
346
352
|
: [];
|
|
347
353
|
return {
|
|
348
354
|
message: `No component reads ${token}, so setting it changes nothing.${near.length ? ` Tokens components do read for ${g}: ${near.join(', ')}.` : ''}`,
|
|
349
|
-
run: [`${HOW} ${
|
|
355
|
+
run: [`${HOW} ${quoteCommandArgument(token)}`],
|
|
350
356
|
also: [],
|
|
351
357
|
};
|
|
352
358
|
}
|
|
@@ -383,12 +389,14 @@ export function makeCompiler(project, parts) {
|
|
|
383
389
|
* @param {{parseColor: (v: unknown) => [number, number, number] | null, ratio: (a: number[], b: number[]) => number, alphaOf: (v: unknown) => number, compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number], page: (mode: string) => string | null | undefined}} helpers
|
|
384
390
|
* `page` is the page color in a mode: a see-through background is drawn
|
|
385
391
|
* over it, and see-through text over that background, before measuring.
|
|
392
|
+
* @param {TextPair[]} [extra] more pairs to measure (a part's variants)
|
|
386
393
|
*/
|
|
387
394
|
function contrast(
|
|
388
395
|
value,
|
|
389
396
|
baseValue,
|
|
390
397
|
modes,
|
|
391
398
|
{parseColor, ratio, alphaOf, compositeOver, page},
|
|
399
|
+
extra = [],
|
|
392
400
|
) {
|
|
393
401
|
/**
|
|
394
402
|
* The opaque colors the eye sees for a pair, or null with no fixed color.
|
|
@@ -401,9 +409,7 @@ export function makeCompiler(project, parts) {
|
|
|
401
409
|
const bgAlpha = alphaOf(bg);
|
|
402
410
|
const back = parseColor(bg);
|
|
403
411
|
const under =
|
|
404
|
-
bgAlpha === 0
|
|
405
|
-
? ground
|
|
406
|
-
: back && compositeOver(back, bgAlpha, ground);
|
|
412
|
+
bgAlpha === 0 ? ground : back && compositeOver(back, bgAlpha, ground);
|
|
407
413
|
const top = parseColor(fg);
|
|
408
414
|
if (!under || !top) return null;
|
|
409
415
|
return [compositeOver(top, alphaOf(fg), under), under];
|
|
@@ -413,7 +419,7 @@ export function makeCompiler(project, parts) {
|
|
|
413
419
|
const seen = new Set();
|
|
414
420
|
/** @type {Set<string>} */
|
|
415
421
|
const unchecked = new Set();
|
|
416
|
-
for (const p of parts.pairs) {
|
|
422
|
+
for (const p of [...parts.pairs, ...extra]) {
|
|
417
423
|
if (
|
|
418
424
|
p.fg.target !== p.bg.target &&
|
|
419
425
|
p.bg.target &&
|
|
@@ -451,9 +457,17 @@ export function makeCompiler(project, parts) {
|
|
|
451
457
|
mode: m,
|
|
452
458
|
ratio: Number(r.toFixed(2)),
|
|
453
459
|
sample: p.sample,
|
|
454
|
-
|
|
460
|
+
// A side the theme changed is named by the value it set, not the
|
|
461
|
+
// token the part reads without it.
|
|
462
|
+
fg:
|
|
463
|
+
fg !== baseValue(p, 'fg', m)
|
|
464
|
+
? String(fg)
|
|
465
|
+
: (p.fg.tokens[0] ?? String(fg)),
|
|
455
466
|
bgPart: p.bg.target,
|
|
456
|
-
bg:
|
|
467
|
+
bg:
|
|
468
|
+
bg !== baseValue(p, 'bg', m)
|
|
469
|
+
? String(bg)
|
|
470
|
+
: (p.bg.tokens[0] ?? String(bg)),
|
|
457
471
|
});
|
|
458
472
|
}
|
|
459
473
|
}
|
|
@@ -498,9 +512,34 @@ export function makeCompiler(project, parts) {
|
|
|
498
512
|
return false;
|
|
499
513
|
}
|
|
500
514
|
|
|
515
|
+
/** @type {Map<string, string[]>} */
|
|
516
|
+
const propsCache = new Map();
|
|
517
|
+
/**
|
|
518
|
+
* The CSS properties anything in the catalog reads a token in.
|
|
519
|
+
* @param {string} tok
|
|
520
|
+
*/
|
|
521
|
+
const propsReading = tok => {
|
|
522
|
+
let r = propsCache.get(tok);
|
|
523
|
+
if (!r) {
|
|
524
|
+
/** @type {Set<string>} */
|
|
525
|
+
const out = new Set();
|
|
526
|
+
for (const t of Object.values(MAP)) {
|
|
527
|
+
for (const [prop, v] of Object.entries(t.own ?? {}))
|
|
528
|
+
if (tok in v.tokens) out.add(prop);
|
|
529
|
+
for (const [k, v] of Object.entries(t.inside ?? {}))
|
|
530
|
+
if (k === tok)
|
|
531
|
+
for (const p of /** @type {string[]} */ (v)) out.add(p);
|
|
532
|
+
}
|
|
533
|
+
r = [...out];
|
|
534
|
+
propsCache.set(tok, r);
|
|
535
|
+
}
|
|
536
|
+
return r;
|
|
537
|
+
};
|
|
538
|
+
|
|
501
539
|
return {
|
|
502
540
|
MAP,
|
|
503
541
|
typeOf,
|
|
542
|
+
propsReading,
|
|
504
543
|
feeds,
|
|
505
544
|
fmtFeeds,
|
|
506
545
|
showsCorners,
|
|
@@ -18,6 +18,7 @@ export function context(cwd: string): Promise<{
|
|
|
18
18
|
C: {
|
|
19
19
|
MAP: Record<string, import("./_parts.mjs").PartRecord>;
|
|
20
20
|
typeOf: (tok: string) => string;
|
|
21
|
+
propsReading: (tok: string) => string[];
|
|
21
22
|
feeds: (target: string, token: string) => Array<{
|
|
22
23
|
part: string;
|
|
23
24
|
prop: string;
|
|
@@ -45,7 +46,7 @@ export function context(cwd: string): Promise<{
|
|
|
45
46
|
alphaOf: (v: unknown) => number;
|
|
46
47
|
compositeOver: (over: [number, number, number], alpha: number, under: [number, number, number]) => [number, number, number];
|
|
47
48
|
page: (mode: string) => string | null | undefined;
|
|
48
|
-
}) => {
|
|
49
|
+
}, extra?: TextPair[]) => {
|
|
49
50
|
problems: {
|
|
50
51
|
part: string;
|
|
51
52
|
mode: string;
|
|
@@ -61,6 +62,7 @@ export function context(cwd: string): Promise<{
|
|
|
61
62
|
};
|
|
62
63
|
parts: import("./_parts.mjs").PartData;
|
|
63
64
|
unchecked: string | null;
|
|
65
|
+
uncheckedCode: string | null;
|
|
64
66
|
}>;
|
|
65
67
|
/**
|
|
66
68
|
* Pictures of HTML files, on request.
|
|
@@ -100,6 +102,7 @@ export function styledChanges(before: any, after: any): string[];
|
|
|
100
102
|
* @param {boolean} png
|
|
101
103
|
*/
|
|
102
104
|
export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, png: boolean): Promise<{
|
|
105
|
+
sheetStale?: string | undefined;
|
|
103
106
|
preview: string | null;
|
|
104
107
|
pictures: string[];
|
|
105
108
|
pictureProblem: string | null;
|