@astryxdesign/cli 0.7.14 → 0.7.15-canary.g79b95eb
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/api/doctor/_adapter.d.mts +1 -0
- package/api/doctor/_adapter.mjs +8 -0
- 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/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.mjs +20 -9
- package/api/theme/build/build.d.mts +15 -1
- package/api/theme/build/build.mjs +132 -32
- package/api/theme/targets/targets.d.mts +8 -0
- package/api/theme/targets/targets.mjs +14 -1
- package/api/theme/themeBuild.doc.mjs +6 -3
- package/api/theme/themeEject.doc.mjs +3 -3
- package/api/theme/themeTargets.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +46 -3
- package/api/theme-edit/_adapter.mjs +372 -109
- package/api/theme-edit/_check.d.mts +6 -3
- package/api/theme-edit/_check.mjs +665 -87
- package/api/theme-edit/_color.mjs +4 -2
- package/api/theme-edit/_compiler.d.mts +2 -1
- package/api/theme-edit/_compiler.mjs +27 -13
- package/api/theme-edit/_context.d.mts +2 -1
- package/api/theme-edit/_context.mjs +47 -8
- package/api/theme-edit/_edit.d.mts +9 -3
- package/api/theme-edit/_edit.mjs +484 -66
- package/api/theme-edit/_how-commands.d.mts +33 -7
- package/api/theme-edit/_how-commands.mjs +57 -45
- package/api/theme-edit/_how-question.d.mts +4 -0
- package/api/theme-edit/_how-question.mjs +1004 -223
- package/api/theme-edit/_how.mjs +96 -9
- package/api/theme-edit/_palette.d.mts +38 -13
- package/api/theme-edit/_palette.mjs +620 -223
- package/api/theme-edit/_parts.mjs +63 -7
- 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 +6 -0
- package/api/theme-edit/_preview-app.mjs +1194 -207
- package/api/theme-edit/_preview.mjs +2 -2
- package/api/theme-edit/_project.d.mts +12 -1
- package/api/theme-edit/_project.mjs +37 -6
- package/api/theme-edit/_settings.d.mts +104 -33
- package/api/theme-edit/_settings.mjs +818 -118
- package/api/theme-edit/_tables.d.mts +7 -0
- package/api/theme-edit/_tables.mjs +61 -0
- package/api/theme-edit/theme-edit.type.d.mts +11 -1
- package/api/theme-edit/theme-edit.type.mjs +4 -3
- package/api/theme-edit/themeEditHow.doc.mjs +6 -0
- 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 +1 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +5 -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.generated.json +2 -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/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/theme.mjs +178 -78
- package/clients/cli/commands/experimental-theme-compile.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +1 -1
- 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/manifest.mjs +5 -2
- package/clients/cli/commands/theme.mjs +118 -22
- package/clients/cli/index.mjs +9 -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/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 +6 -0
- package/foundation/discovery/template-needs.mjs +20 -1
- 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 +2 -8
- 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 +12 -11
- 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 +716 -0
- package/foundation/fs/module-loader.mjs +7 -1
- package/foundation/fs/read-record.d.mts +31 -1
- package/foundation/fs/read-record.mjs +93 -6
- package/foundation/integrations/validate-contributions.mjs +24 -11
- package/foundation/release/cache.d.mts +11 -2
- package/foundation/release/cache.mjs +59 -10
- package/foundation/release/folder-lock.d.mts +21 -0
- package/foundation/release/folder-lock.mjs +171 -0
- package/package.json +8 -6
|
@@ -17,9 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import {createHash} from 'node:crypto';
|
|
19
19
|
import * as fs from 'node:fs';
|
|
20
|
-
import {createRequire} from 'node:module';
|
|
21
|
-
import * as os from 'node:os';
|
|
22
20
|
import * as path from 'node:path';
|
|
21
|
+
import {isAlive} from '../../foundation/release/cache.mjs';
|
|
23
22
|
import {AstryxError} from '../error.mjs';
|
|
24
23
|
import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
25
24
|
import {
|
|
@@ -50,6 +49,15 @@ import {P} from './_tables.mjs';
|
|
|
50
49
|
* @param {string | Buffer} text
|
|
51
50
|
*/
|
|
52
51
|
export function writeWhole(file, text) {
|
|
52
|
+
// A folder where a file goes (a folder named preview.html) is never
|
|
53
|
+
// written through or replaced.
|
|
54
|
+
if (fs.lstatSync(file, {throwIfNoEntry: false})?.isDirectory())
|
|
55
|
+
throw new AstryxError(
|
|
56
|
+
`${[path.dirname(path.dirname(file)), path.dirname(file), file].map(p => path.basename(p)).join('/')} is a folder, so the editor cannot write that file there. Rename or move the folder, then run the command again.`,
|
|
57
|
+
[],
|
|
58
|
+
ERROR_CODES.ERR_WRITE_FAILED,
|
|
59
|
+
);
|
|
60
|
+
sweepTemps(path.dirname(file));
|
|
53
61
|
const tmp = tempFor(file);
|
|
54
62
|
try {
|
|
55
63
|
fs.writeFileSync(tmp, text);
|
|
@@ -59,6 +67,40 @@ export function writeWhole(file, text) {
|
|
|
59
67
|
}
|
|
60
68
|
}
|
|
61
69
|
|
|
70
|
+
/** Folders swept of left temp files in this run. */
|
|
71
|
+
const swept = new Set();
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Remove the editor's own temp files a stopped command left in a folder:
|
|
75
|
+
* only names the editor makes (`.<name>.astryx-<pid>-<random>.tmp`), whose
|
|
76
|
+
* process is gone and that are more than ten minutes old. Links are never
|
|
77
|
+
* followed. Once per folder per run.
|
|
78
|
+
* @param {string} dir
|
|
79
|
+
*/
|
|
80
|
+
function sweepTemps(dir) {
|
|
81
|
+
if (swept.has(dir)) return;
|
|
82
|
+
swept.add(dir);
|
|
83
|
+
let names;
|
|
84
|
+
try {
|
|
85
|
+
names = fs.readdirSync(dir);
|
|
86
|
+
} catch {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
for (const n of names) {
|
|
90
|
+
const m = /^\..+\.astryx-(\d+)-[a-z0-9]+\.tmp$/.exec(n);
|
|
91
|
+
if (!m || Number(m[1]) === process.pid) continue;
|
|
92
|
+
const p = path.join(dir, n);
|
|
93
|
+
try {
|
|
94
|
+
const st = fs.lstatSync(p);
|
|
95
|
+
if (!st.isFile() || Date.now() - st.mtimeMs < 10 * 60_000) continue;
|
|
96
|
+
if (isAlive(Number(m[1]))) continue;
|
|
97
|
+
fs.rmSync(p, {force: true});
|
|
98
|
+
} catch {
|
|
99
|
+
// Gone already, or not ours to judge.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
62
104
|
/**
|
|
63
105
|
* A temp file beside `file` for a whole write, named so only the editor
|
|
64
106
|
* makes such names: `.<name>.astryx-<pid>-<random>.tmp`. The write that
|
|
@@ -98,6 +140,7 @@ export function tempFor(file) {
|
|
|
98
140
|
* @property {number} needs
|
|
99
141
|
* @property {boolean} pass
|
|
100
142
|
* @property {string} [note] - The whole sentence to report, when the check is not a plain stop move.
|
|
143
|
+
* @property {string[]} [dials] - The color dials whose notes report it, when its token belongs to none of them.
|
|
101
144
|
*/
|
|
102
145
|
|
|
103
146
|
/**
|
|
@@ -110,6 +153,7 @@ export function tempFor(file) {
|
|
|
110
153
|
* @property {number} vibrancy - The generator's vibrancy, 0 to 100.
|
|
111
154
|
* @property {Record<string, Partial<Record<Mode, string>>>} exact - Main tokens the theme sets exactly, the value per mode: the dial's fill gives way to them.
|
|
112
155
|
* @property {string[]} notes - What the config writer kept or replaced of a hand edit.
|
|
156
|
+
* @property {Record<string, Partial<Record<Mode, StopRef>>> | null} lift - Lifted secondary text per background token of LIFT_PARTS (the accent tint, the neutral track), per mode, from the neutral color; null without one.
|
|
113
157
|
*/
|
|
114
158
|
|
|
115
159
|
/** The color dials. Each one is a palette family of the same id. */
|
|
@@ -209,6 +253,32 @@ const NEUTRAL_TINTS =
|
|
|
209
253
|
const DARK_FILL = 70;
|
|
210
254
|
const TEXT_STOP = /** @type {[number, number]} */ ([45, 80]);
|
|
211
255
|
const ACCENT_MUTED = /** @type {[number, number]} */ ([85, 30]);
|
|
256
|
+
/**
|
|
257
|
+
* The parts whose secondary text the official neutral theme lifts, with
|
|
258
|
+
* the block it lifts it in and what the text sits on: the accent tint
|
|
259
|
+
* under selected items and tree rows, a dropzone and numbered citations;
|
|
260
|
+
* the translucent neutral track (`--color-neutral`) under segmented-control
|
|
261
|
+
* labels.
|
|
262
|
+
*/
|
|
263
|
+
export const LIFT_PARTS = /** @type {Array<[string, string, string]>} */ ([
|
|
264
|
+
['item', 'selected', '--color-accent-muted'],
|
|
265
|
+
['tree-list-item', 'selected', '--color-accent-muted'],
|
|
266
|
+
['file-input', 'mode:dropzone', '--color-accent-muted'],
|
|
267
|
+
['citation', 'variant:number', '--color-accent-muted'],
|
|
268
|
+
['segmented-control-item', 'base', '--color-neutral'],
|
|
269
|
+
]);
|
|
270
|
+
/** What each lifted background is, and the parts on it, for notes. */
|
|
271
|
+
const LIFT_GROUNDS =
|
|
272
|
+
/** @type {Record<string, {what: string, parts: string}>} */ ({
|
|
273
|
+
'--color-accent-muted': {
|
|
274
|
+
what: 'the accent tint',
|
|
275
|
+
parts: 'selected items and rows, a dropzone, numbered citations',
|
|
276
|
+
},
|
|
277
|
+
'--color-neutral': {
|
|
278
|
+
what: 'the neutral track',
|
|
279
|
+
parts: 'segmented-control labels',
|
|
280
|
+
},
|
|
281
|
+
});
|
|
212
282
|
const STATUS_MUTED = /** @type {[number, [number, string]]} */ ([
|
|
213
283
|
85,
|
|
214
284
|
[75, '3d'],
|
|
@@ -290,11 +360,11 @@ function sameColor(a, b) {
|
|
|
290
360
|
}
|
|
291
361
|
|
|
292
362
|
/**
|
|
293
|
-
* The modes a theme has.
|
|
363
|
+
* The modes a theme has: one for a one-mode theme, else light and dark.
|
|
294
364
|
* @param {{mode?: string}} data
|
|
295
365
|
* @returns {Mode[]}
|
|
296
366
|
*/
|
|
297
|
-
function
|
|
367
|
+
export function modesOf(data) {
|
|
298
368
|
return data.mode === 'light-only'
|
|
299
369
|
? ['light']
|
|
300
370
|
: data.mode === 'dark-only'
|
|
@@ -319,16 +389,47 @@ function dialFamilies(data) {
|
|
|
319
389
|
return out;
|
|
320
390
|
}
|
|
321
391
|
|
|
392
|
+
/** Notes for damaged color configs kept aside during one sync. @type {string[]} */
|
|
393
|
+
const keptDamaged = [];
|
|
394
|
+
|
|
322
395
|
/** @param {string} file */
|
|
323
396
|
function readConfig(file) {
|
|
324
397
|
if (!fs.existsSync(file)) return null;
|
|
325
398
|
try {
|
|
326
399
|
return JSON.parse(fs.readFileSync(file, 'utf8').replace(/^\uFEFF/, ''));
|
|
327
|
-
} catch
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
400
|
+
} catch {
|
|
401
|
+
// A file that does not parse holds nothing the editor can keep: it is
|
|
402
|
+
// read as no config. Only a command that writes the theme keeps its
|
|
403
|
+
// text aside (keepDamaged), so a read writes nothing.
|
|
404
|
+
damagedConfigs.add(file);
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/** Damaged configs read in this run, kept aside when a change is written. */
|
|
410
|
+
const damagedConfigs = new Set();
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Keep a damaged config's text beside it (palette.config.damaged.json,
|
|
414
|
+
* then -2, -3 …; the same text once) before the editor writes the config
|
|
415
|
+
* again, and say where.
|
|
416
|
+
* @param {string} file
|
|
417
|
+
*/
|
|
418
|
+
function keepDamaged(file) {
|
|
419
|
+
if (!damagedConfigs.has(file) || !fs.existsSync(file)) return;
|
|
420
|
+
damagedConfigs.delete(file);
|
|
421
|
+
{
|
|
422
|
+
const text = fs.readFileSync(file);
|
|
423
|
+
let n = 1;
|
|
424
|
+
const name = (/** @type {number} */ k) =>
|
|
425
|
+
`palette.config.damaged${k > 1 ? `-${k}` : ''}.json`;
|
|
426
|
+
const at = (/** @type {number} */ k) =>
|
|
427
|
+
path.join(path.dirname(file), name(k));
|
|
428
|
+
// The same damaged text is kept once.
|
|
429
|
+
while (fs.existsSync(at(n)) && !fs.readFileSync(at(n)).equals(text)) n++;
|
|
430
|
+
if (!fs.existsSync(at(n))) fs.copyFileSync(file, at(n));
|
|
431
|
+
keptDamaged.push(
|
|
432
|
+
`palette.config.json was damaged, so it was made again from the settings; its text is kept in ${name(n)}`,
|
|
332
433
|
);
|
|
333
434
|
}
|
|
334
435
|
}
|
|
@@ -525,6 +626,42 @@ function tools(candidate, data, base) {
|
|
|
525
626
|
const rgb = v == null ? null : parseColor(v);
|
|
526
627
|
return rgb && alphaOf(v) >= 1 ? hex(rgb) : null;
|
|
527
628
|
};
|
|
629
|
+
/**
|
|
630
|
+
* The exact whole-theme color a token setting gives in a mode, see-through
|
|
631
|
+
* or not, as written (a hex keeps its alpha digits); null when there is
|
|
632
|
+
* none or it is not a fixed color.
|
|
633
|
+
* @param {string} token @param {Mode} m
|
|
634
|
+
*/
|
|
635
|
+
const rawOf = (token, m) => {
|
|
636
|
+
const v = [...data.settings]
|
|
637
|
+
.reverse()
|
|
638
|
+
.find(
|
|
639
|
+
s =>
|
|
640
|
+
s.source === 'token' &&
|
|
641
|
+
s.thing === token &&
|
|
642
|
+
!s.on &&
|
|
643
|
+
!s.when &&
|
|
644
|
+
!s.state &&
|
|
645
|
+
(!s.mode || s.mode === m),
|
|
646
|
+
)?.value;
|
|
647
|
+
return v != null && parseColor(v) ? String(v).trim() : null;
|
|
648
|
+
};
|
|
649
|
+
/**
|
|
650
|
+
* Which column of a `[light, dark]` mapping a mode takes: the light one
|
|
651
|
+
* on a light page and the dark one on a dark page, by the page the theme
|
|
652
|
+
* keeps (its exact page color, else the base theme's). A base whose
|
|
653
|
+
* light page is dark, such as Gothic, gets dark-page shades in light.
|
|
654
|
+
* @param {Mode} m
|
|
655
|
+
* @returns {0 | 1}
|
|
656
|
+
*/
|
|
657
|
+
const side = m => {
|
|
658
|
+
const page =
|
|
659
|
+
rawOf('--color-background-body', m) ??
|
|
660
|
+
base?.[m]?.['--color-background-body'];
|
|
661
|
+
const rgb = page ? parseColor(page) : null;
|
|
662
|
+
if (!rgb || alphaOf(page) < 1) return m === 'light' ? 0 : 1;
|
|
663
|
+
return ratio(rgb, [255, 255, 255]) > ratio(rgb, [0, 0, 0]) ? 1 : 0;
|
|
664
|
+
};
|
|
528
665
|
/**
|
|
529
666
|
* What text and fills sit on in a mode: the theme's exact surface
|
|
530
667
|
* colors, else the neutral color's surfaces, else the base theme's; the
|
|
@@ -542,16 +679,14 @@ function tools(candidate, data, base) {
|
|
|
542
679
|
]) {
|
|
543
680
|
const own =
|
|
544
681
|
neutral && NEUTRAL_STOPS[n]
|
|
545
|
-
? ref('neutral', m, at(NEUTRAL_STOPS[n][m
|
|
682
|
+
? ref('neutral', m, at(NEUTRAL_STOPS[n][side(m)])).color
|
|
546
683
|
: null;
|
|
547
684
|
const v = exactOf(n, m) ?? own ?? base?.[m]?.[n];
|
|
548
685
|
if (v && parseColor(v) && alphaOf(v) >= 1)
|
|
549
686
|
out.push([n, hex(/** @type {number[]} */ (parseColor(v)))]);
|
|
550
687
|
}
|
|
551
688
|
if (!out.length) {
|
|
552
|
-
const s = at(
|
|
553
|
-
NEUTRAL_STOPS['--color-background-surface'][m === 'light' ? 0 : 1],
|
|
554
|
-
);
|
|
689
|
+
const s = at(NEUTRAL_STOPS['--color-background-surface'][side(m)]);
|
|
555
690
|
out.push([`${id} shade ${s}`, ref(id, m, s).color]);
|
|
556
691
|
}
|
|
557
692
|
return out;
|
|
@@ -592,82 +727,33 @@ function tools(candidate, data, base) {
|
|
|
592
727
|
/** The lowest contrast of a color on the surfaces. @param {string} color @param {Mode} m @param {string} id */
|
|
593
728
|
const page = (color, m, id) =>
|
|
594
729
|
Math.min(...surfaces(m, id).map(([, bg]) => contrast(color, bg)));
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
* package, the same official stops of a plain gray ramp from the
|
|
607
|
-
* generator. Null when neither can be read.
|
|
608
|
-
* @param {Mode} m
|
|
609
|
-
* @returns {number | null}
|
|
610
|
-
*/
|
|
611
|
-
export function officialCitation(m) {
|
|
612
|
-
if (m in citationCache)
|
|
613
|
-
return /** @type {number | null} */ (citationCache[m]);
|
|
614
|
-
const i = m === 'light' ? 0 : 1;
|
|
615
|
-
/** @type {number | null} */
|
|
616
|
-
let r = null;
|
|
617
|
-
try {
|
|
618
|
-
const dir = path.dirname(
|
|
619
|
-
path.dirname(
|
|
620
|
-
createRequire(import.meta.url).resolve('@astryxdesign/theme-neutral'),
|
|
621
|
-
),
|
|
622
|
-
);
|
|
623
|
-
const theme = fs.readFileSync(
|
|
624
|
-
path.join(dir, 'src/neutralTheme.ts'),
|
|
625
|
-
'utf8',
|
|
626
|
-
);
|
|
627
|
-
const refs = fs.readFileSync(
|
|
628
|
-
path.join(dir, 'src/neutralPaletteRefs.generated.ts'),
|
|
629
|
-
'utf8',
|
|
730
|
+
/**
|
|
731
|
+
* A color as the eye sees it on the surface in a mode: a see-through one
|
|
732
|
+
* drawn over the first surface.
|
|
733
|
+
* @param {string} color @param {Mode} m @param {string} id
|
|
734
|
+
*/
|
|
735
|
+
const solid = (color, m, id) => {
|
|
736
|
+
const rgb = /** @type {[number, number, number]} */ (parseColor(color));
|
|
737
|
+
const a = alphaOf(color);
|
|
738
|
+
if (a >= 1) return hex(rgb);
|
|
739
|
+
const under = /** @type {[number, number, number]} */ (
|
|
740
|
+
parseColor(surfaces(m, id)[0][1])
|
|
630
741
|
);
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
stop == null
|
|
647
|
-
? null
|
|
648
|
-
: new RegExp(`\\b${stop}:\\s*'(#[0-9a-f]{6})'`).exec(ramp)?.[1];
|
|
649
|
-
const text = colorOf(stopOf('--color-text-secondary'));
|
|
650
|
-
const tint = colorOf(stopOf('--color-accent-muted'));
|
|
651
|
-
if (text && tint) r = contrast(text, tint);
|
|
652
|
-
} catch {
|
|
653
|
-
r = null;
|
|
654
|
-
}
|
|
655
|
-
if (r == null)
|
|
656
|
-
try {
|
|
657
|
-
const gray = /** @type {any} */ (
|
|
658
|
-
generateTonalPalette({
|
|
659
|
-
families: [{id: 'n', seed: '#808080', kind: 'neutral'}],
|
|
660
|
-
}).palette.n
|
|
661
|
-
)[m];
|
|
662
|
-
r = contrast(
|
|
663
|
-
gray[NEUTRAL_STOPS['--color-text-secondary'][i]],
|
|
664
|
-
gray[ACCENT_MUTED[i]],
|
|
665
|
-
);
|
|
666
|
-
} catch {
|
|
667
|
-
r = null;
|
|
668
|
-
}
|
|
669
|
-
citationCache[m] = r;
|
|
670
|
-
return r;
|
|
742
|
+
return hex(compositeOver(rgb, a, under));
|
|
743
|
+
};
|
|
744
|
+
return {
|
|
745
|
+
stops,
|
|
746
|
+
at,
|
|
747
|
+
ref,
|
|
748
|
+
exactOf,
|
|
749
|
+
rawOf,
|
|
750
|
+
side,
|
|
751
|
+
solid,
|
|
752
|
+
surfaces,
|
|
753
|
+
onFor,
|
|
754
|
+
page,
|
|
755
|
+
neutral,
|
|
756
|
+
};
|
|
671
757
|
}
|
|
672
758
|
|
|
673
759
|
/** A text shade, named for a sentence. @param {StopRef} r */
|
|
@@ -739,7 +825,7 @@ function planPalette(cwd, slug, data, base) {
|
|
|
739
825
|
? {...existing}
|
|
740
826
|
: {};
|
|
741
827
|
const {settings: saved, mode: savedMode} = savedSettings(cwd, slug);
|
|
742
|
-
const modes =
|
|
828
|
+
const modes = modesOf(data);
|
|
743
829
|
|
|
744
830
|
const vibrancy = dialVibrancy(data.settings);
|
|
745
831
|
const savedVibrancy = dialVibrancy(saved);
|
|
@@ -762,7 +848,7 @@ function planPalette(cwd, slug, data, base) {
|
|
|
762
848
|
const strategy = strategyOf(modes);
|
|
763
849
|
// Only a value the editor did not write is a hand edit worth naming: the
|
|
764
850
|
// one it wrote follows the theme's mode as it was saved.
|
|
765
|
-
const wrote = savedMode ? strategyOf(
|
|
851
|
+
const wrote = savedMode ? strategyOf(modesOf({mode: savedMode})) : null;
|
|
766
852
|
if (
|
|
767
853
|
config.modeStrategy != null &&
|
|
768
854
|
config.modeStrategy !== strategy &&
|
|
@@ -852,13 +938,13 @@ function planPalette(cwd, slug, data, base) {
|
|
|
852
938
|
if (seedColored(a) && a.stop === editorStop) continue;
|
|
853
939
|
if (!modes.includes(a?.mode)) {
|
|
854
940
|
notes.push(
|
|
855
|
-
`${file}: the ${f.id} ${a?.mode} anchor at shade ${a?.stop} is dropped: the theme has no ${a?.mode} mode`,
|
|
941
|
+
`${file}: the ${f.id} ${a?.mode} anchor at shade ${shade(a?.stop)} is dropped: the theme has no ${a?.mode} mode`,
|
|
856
942
|
);
|
|
857
943
|
continue;
|
|
858
944
|
}
|
|
859
945
|
if (mine.some(x => x.mode === a.mode && x.stop === a.stop)) {
|
|
860
946
|
notes.push(
|
|
861
|
-
`${file}: your ${a.mode} anchor at shade ${a.stop} of ${f.id} is replaced by your exact ${f.id} color`,
|
|
947
|
+
`${file}: your ${a.mode} anchor at shade ${shade(a.stop)} of ${f.id} is replaced by your exact ${f.id} color`,
|
|
862
948
|
);
|
|
863
949
|
continue;
|
|
864
950
|
}
|
|
@@ -880,7 +966,13 @@ function planPalette(cwd, slug, data, base) {
|
|
|
880
966
|
};
|
|
881
967
|
if (!kind) delete out.kind;
|
|
882
968
|
if (!out.anchors.length) delete out.anchors;
|
|
883
|
-
|
|
969
|
+
// The keys always in one order, so a change and its undo write the
|
|
970
|
+
// same bytes.
|
|
971
|
+
/** @type {Record<string, unknown>} */
|
|
972
|
+
const ordered = {};
|
|
973
|
+
for (const k of FAMILY_KEYS) if (k in out) ordered[k] = out[k];
|
|
974
|
+
for (const k of Object.keys(out)) if (!(k in ordered)) ordered[k] = out[k];
|
|
975
|
+
return {family: /** @type {typeof out} */ (ordered), stop};
|
|
884
976
|
};
|
|
885
977
|
|
|
886
978
|
/** @type {PalettePlan['fills']} */
|
|
@@ -952,7 +1044,7 @@ function planPalette(cwd, slug, data, base) {
|
|
|
952
1044
|
);
|
|
953
1045
|
if (others.length < (f.anchors ?? []).length)
|
|
954
1046
|
notes.push(
|
|
955
|
-
`${file}: your dark anchor at shade ${anchor.stop} of ${id} is replaced by your exact ${id} color`,
|
|
1047
|
+
`${file}: your dark anchor at shade ${shade(anchor.stop)} of ${id} is replaced by your exact ${id} color`,
|
|
956
1048
|
);
|
|
957
1049
|
return {
|
|
958
1050
|
...f,
|
|
@@ -1012,6 +1104,24 @@ const sha256 = text => createHash('sha256').update(text).digest('hex');
|
|
|
1012
1104
|
* @returns {string[]}
|
|
1013
1105
|
*/
|
|
1014
1106
|
export function syncPalette(cwd, slug, data, base) {
|
|
1107
|
+
keptDamaged.length = 0;
|
|
1108
|
+
// The config is read first, so a damaged one is kept aside before the
|
|
1109
|
+
// sync writes it again.
|
|
1110
|
+
const config = path.join(cwd, paletteFiles(slug).config);
|
|
1111
|
+
readConfig(config);
|
|
1112
|
+
keepDamaged(config);
|
|
1113
|
+
const notes = syncPaletteFiles(cwd, slug, data, base);
|
|
1114
|
+
return [...keptDamaged.splice(0), ...notes];
|
|
1115
|
+
}
|
|
1116
|
+
|
|
1117
|
+
/**
|
|
1118
|
+
* @param {string} cwd
|
|
1119
|
+
* @param {string} slug
|
|
1120
|
+
* @param {any} data
|
|
1121
|
+
* @param {any} base
|
|
1122
|
+
* @returns {string[]}
|
|
1123
|
+
*/
|
|
1124
|
+
function syncPaletteFiles(cwd, slug, data, base) {
|
|
1015
1125
|
const f = paletteFiles(slug);
|
|
1016
1126
|
const abs = (/** @type {string} */ p) => path.join(cwd, p);
|
|
1017
1127
|
const plan = planPalette(cwd, slug, data, base);
|
|
@@ -1035,12 +1145,25 @@ export function syncPalette(cwd, slug, data, base) {
|
|
|
1035
1145
|
const mine = hash != null && (data.palette === hash || saved === hash);
|
|
1036
1146
|
delete data.palette;
|
|
1037
1147
|
if (!mine) return [];
|
|
1038
|
-
|
|
1148
|
+
// A palette file edited by hand is never deleted: it stays, and the
|
|
1149
|
+
// result names it. Its config and receipt go, so the next color change
|
|
1150
|
+
// asks whether to keep or discard it.
|
|
1151
|
+
// The selected-stops file is generated from the palette on every
|
|
1152
|
+
// change, so it always goes.
|
|
1153
|
+
const editedPalette = paletteEdited(cwd, slug);
|
|
1154
|
+
/** @type {string[]} */
|
|
1155
|
+
const notes = [];
|
|
1156
|
+
for (const p of [f.config, f.receipt, f.refs])
|
|
1039
1157
|
fs.rmSync(abs(p), {force: true});
|
|
1158
|
+
if (editedPalette)
|
|
1159
|
+
notes.push(
|
|
1160
|
+
`${f.palette} was edited by hand, so it stays: the theme no longer reads it. Move it out of tokens/ to keep it as your own, or delete it`,
|
|
1161
|
+
);
|
|
1162
|
+
else fs.rmSync(abs(f.palette), {force: true});
|
|
1040
1163
|
const tokensDir = path.dirname(abs(f.palette));
|
|
1041
1164
|
if (fs.existsSync(tokensDir) && !fs.readdirSync(tokensDir).length)
|
|
1042
1165
|
fs.rmdirSync(tokensDir);
|
|
1043
|
-
return
|
|
1166
|
+
return notes;
|
|
1044
1167
|
}
|
|
1045
1168
|
const text = `${JSON.stringify(plan.config, null, 2)}\n`;
|
|
1046
1169
|
/** @type {any} */
|
|
@@ -1059,12 +1182,23 @@ export function syncPalette(cwd, slug, data, base) {
|
|
|
1059
1182
|
// when a color change touches the config.
|
|
1060
1183
|
if (same) {
|
|
1061
1184
|
data.palette = sha256(text);
|
|
1062
|
-
|
|
1185
|
+
// The theme reads only the selected shades, which come from the
|
|
1186
|
+
// generator, so a hand edit to the palette file never shows: say so.
|
|
1187
|
+
return paletteEdited(cwd, slug)
|
|
1188
|
+
? [
|
|
1189
|
+
`${f.palette} was edited by hand, but the theme never reads it: it reads ${f.refs}, which the editor writes from the generator, so your edit does not show. The next color change asks whether to keep or discard it`,
|
|
1190
|
+
]
|
|
1191
|
+
: [];
|
|
1063
1192
|
}
|
|
1064
1193
|
if (paletteEdited(cwd, slug)) {
|
|
1065
1194
|
throw new AstryxError(
|
|
1066
|
-
`${f.palette} was edited by hand, so the editor will not write over it. To keep your edits, move the file out of tokens/ (it is then yours: import it in ${slug}.theme.ts); to discard them, delete it. Then run the command again, and the editor writes the generated shades back. Only color changes wait for this; other changes still work. Nothing was changed.`,
|
|
1067
|
-
[
|
|
1195
|
+
`${f.palette} was edited by hand, so the editor will not write over it. The theme never read the edit: it reads ${f.refs}, which the editor writes from the generator. To keep your edits, move the file out of tokens/ (it is then yours: import it in ${slug}.theme.ts); to discard them, delete it. Then run the command again, and the editor writes the generated shades back. Only color changes wait for this; other changes still work. Nothing was changed.`,
|
|
1196
|
+
[
|
|
1197
|
+
{
|
|
1198
|
+
name: `${P} show ${slug}`,
|
|
1199
|
+
reason: `do this next: after you move ${f.palette} out of tokens/ (keeps your edits) or delete it (discards them), run your command again; show lists the theme as it is now`,
|
|
1200
|
+
},
|
|
1201
|
+
],
|
|
1068
1202
|
ERROR_CODES.ERR_THEME_INVALID,
|
|
1069
1203
|
);
|
|
1070
1204
|
}
|
|
@@ -1076,41 +1210,123 @@ export function syncPalette(cwd, slug, data, base) {
|
|
|
1076
1210
|
}
|
|
1077
1211
|
|
|
1078
1212
|
/**
|
|
1079
|
-
*
|
|
1080
|
-
*
|
|
1213
|
+
* The value of the object literal that starts at the first `{` from
|
|
1214
|
+
* `from`, read as data: string and numeric keys, string values, nested
|
|
1215
|
+
* objects; quotes, commas, comments and white space as any formatter writes
|
|
1216
|
+
* them. Null when it is not such a literal.
|
|
1081
1217
|
* @param {string} text
|
|
1218
|
+
* @param {number} from
|
|
1219
|
+
* @returns {any}
|
|
1082
1220
|
*/
|
|
1083
|
-
|
|
1084
|
-
text
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1221
|
+
function objectLiteral(text, from) {
|
|
1222
|
+
const open = text.indexOf('{', from);
|
|
1223
|
+
if (open < 0) return null;
|
|
1224
|
+
/** @type {string[]} */
|
|
1225
|
+
const json = [];
|
|
1226
|
+
let depth = 0;
|
|
1227
|
+
let i = open;
|
|
1228
|
+
while (i < text.length) {
|
|
1229
|
+
const c = text[i];
|
|
1230
|
+
if (c === '/' && text[i + 1] === '/') {
|
|
1231
|
+
i = text.indexOf('\n', i);
|
|
1232
|
+
if (i < 0) return null;
|
|
1233
|
+
continue;
|
|
1234
|
+
}
|
|
1235
|
+
if (c === '/' && text[i + 1] === '*') {
|
|
1236
|
+
i = text.indexOf('*/', i + 2);
|
|
1237
|
+
if (i < 0) return null;
|
|
1238
|
+
i += 2;
|
|
1239
|
+
continue;
|
|
1240
|
+
}
|
|
1241
|
+
if (c === '"' || c === "'") {
|
|
1242
|
+
let j = i + 1;
|
|
1243
|
+
let v = '';
|
|
1244
|
+
while (j < text.length && text[j] !== c) {
|
|
1245
|
+
if (text[j] === '\\') j++;
|
|
1246
|
+
v += text[j++];
|
|
1247
|
+
}
|
|
1248
|
+
json.push(JSON.stringify(v));
|
|
1249
|
+
i = j + 1;
|
|
1250
|
+
continue;
|
|
1251
|
+
}
|
|
1252
|
+
if (/[\s]/.test(c)) {
|
|
1253
|
+
i++;
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
if (c === '{' || c === '[') depth++;
|
|
1257
|
+
if (c === '}' || c === ']') {
|
|
1258
|
+
// A trailing comma before a closing bracket.
|
|
1259
|
+
if (json.at(-1) === ',') json.pop();
|
|
1260
|
+
depth--;
|
|
1261
|
+
}
|
|
1262
|
+
if ('{}[]:,'.includes(c)) {
|
|
1263
|
+
json.push(c);
|
|
1264
|
+
i++;
|
|
1265
|
+
if (depth === 0) break;
|
|
1266
|
+
continue;
|
|
1267
|
+
}
|
|
1268
|
+
const word = /^[\w.$+-]+/.exec(text.slice(i))?.[0];
|
|
1269
|
+
if (!word) return null;
|
|
1270
|
+
json.push(JSON.stringify(word));
|
|
1271
|
+
i += word.length;
|
|
1272
|
+
}
|
|
1098
1273
|
try {
|
|
1099
|
-
|
|
1100
|
-
themePaletteGenerate('config.json', {out: 'palette.ts'}, {cwd: dir});
|
|
1101
|
-
return fs.readFileSync(path.join(dir, 'palette.ts'), 'utf8');
|
|
1274
|
+
return JSON.parse(json.join(''));
|
|
1102
1275
|
} catch {
|
|
1103
1276
|
return null;
|
|
1104
|
-
} finally {
|
|
1105
|
-
fs.rmSync(dir, {recursive: true, force: true});
|
|
1106
1277
|
}
|
|
1107
1278
|
}
|
|
1108
1279
|
|
|
1109
1280
|
/**
|
|
1110
|
-
*
|
|
1111
|
-
*
|
|
1112
|
-
* the
|
|
1113
|
-
*
|
|
1281
|
+
* The colors a palette module holds, read as data so formatting never
|
|
1282
|
+
* counts: `palette` (family, mode, stop, color) and `black`/`white`. Null
|
|
1283
|
+
* when the file does not read as one.
|
|
1284
|
+
* @param {string} text
|
|
1285
|
+
* @returns {{palette: any, black: string | null, white: string | null} | null}
|
|
1286
|
+
*/
|
|
1287
|
+
function paletteData(text) {
|
|
1288
|
+
const t = text.replace(/^\uFEFF/, '');
|
|
1289
|
+
const at = /\bconst\s+palette\s*=/.exec(t);
|
|
1290
|
+
const palette = at ? objectLiteral(t, at.index) : null;
|
|
1291
|
+
if (!palette || typeof palette !== 'object') return null;
|
|
1292
|
+
/** @param {string} name */
|
|
1293
|
+
const end = name =>
|
|
1294
|
+
new RegExp(`\\bconst\\s+${name}\\s*=\\s*["'](#[0-9a-fA-F]{6})["']`)
|
|
1295
|
+
.exec(t)?.[1]
|
|
1296
|
+
?.toLowerCase() ?? null;
|
|
1297
|
+
return {palette, black: end('black'), white: end('white')};
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
/**
|
|
1301
|
+
* Whether two palettes hold the same colors at the same stops.
|
|
1302
|
+
* @param {any} a @param {any} b
|
|
1303
|
+
*/
|
|
1304
|
+
function samePalette(a, b) {
|
|
1305
|
+
/** @param {any} p */
|
|
1306
|
+
const flat = p => {
|
|
1307
|
+
/** @type {string[]} */
|
|
1308
|
+
const out = [];
|
|
1309
|
+
for (const [fam, f] of Object.entries(p ?? {}))
|
|
1310
|
+
for (const m of /** @type {Mode[]} */ (['light', 'dark']))
|
|
1311
|
+
for (const [stop, color] of Object.entries(
|
|
1312
|
+
/** @type {any} */ (f)?.[m] ?? {},
|
|
1313
|
+
))
|
|
1314
|
+
out.push(
|
|
1315
|
+
`${fam}.${m}.${Number(stop)}=${String(color).toLowerCase()}`,
|
|
1316
|
+
);
|
|
1317
|
+
return out.sort().join('|');
|
|
1318
|
+
};
|
|
1319
|
+
return flat(a) === flat(b);
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Whether a theme's palette file was edited by hand. Its bytes match its
|
|
1324
|
+
* receipt, or its colors (read as data, so formatting, a BOM or semicolons
|
|
1325
|
+
* never count) are the ones the generator gives for the request it came
|
|
1326
|
+
* from: the receipt's, else the config the editor wrote. Without a receipt
|
|
1327
|
+
* and with a config edited by hand since, the request is unknown; then the
|
|
1328
|
+
* file counts as the editor's when it holds every shade the theme ships
|
|
1329
|
+
* (the selected-stops file) unchanged. False when there is no palette file.
|
|
1114
1330
|
* @param {string} cwd
|
|
1115
1331
|
* @param {string} slug
|
|
1116
1332
|
*/
|
|
@@ -1118,7 +1334,7 @@ export function paletteEdited(cwd, slug) {
|
|
|
1118
1334
|
const f = paletteFiles(slug);
|
|
1119
1335
|
const file = path.join(cwd, f.palette);
|
|
1120
1336
|
if (!fs.existsSync(file)) return false;
|
|
1121
|
-
const
|
|
1337
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
1122
1338
|
/** @type {any} */
|
|
1123
1339
|
let receipt;
|
|
1124
1340
|
try {
|
|
@@ -1126,17 +1342,67 @@ export function paletteEdited(cwd, slug) {
|
|
|
1126
1342
|
} catch {
|
|
1127
1343
|
receipt = null;
|
|
1128
1344
|
}
|
|
1129
|
-
if (receipt?.candidateSha256 === sha256(
|
|
1345
|
+
if (receipt?.candidateSha256 === sha256(text)) return false;
|
|
1346
|
+
const data = paletteData(text);
|
|
1347
|
+
if (!data) return true;
|
|
1130
1348
|
/** @type {any} */
|
|
1131
1349
|
let request = receipt?.request ?? null;
|
|
1350
|
+
let configMine = false;
|
|
1132
1351
|
if (!request)
|
|
1133
1352
|
try {
|
|
1134
|
-
|
|
1353
|
+
const configText = fs.readFileSync(path.join(cwd, f.config), 'utf8');
|
|
1354
|
+
const saved = JSON.parse(
|
|
1355
|
+
fs.readFileSync(
|
|
1356
|
+
path.join(cwd, 'themes', slug, `${slug}.settings.json`),
|
|
1357
|
+
'utf8',
|
|
1358
|
+
),
|
|
1359
|
+
)?.palette;
|
|
1360
|
+
configMine = saved == null || saved === sha256(configText);
|
|
1361
|
+
request = JSON.parse(configText.replace(/^\uFEFF/, ''));
|
|
1135
1362
|
} catch {
|
|
1136
1363
|
request = null;
|
|
1137
1364
|
}
|
|
1138
|
-
|
|
1139
|
-
|
|
1365
|
+
if (request && (receipt?.request || configMine))
|
|
1366
|
+
try {
|
|
1367
|
+
const candidate = generateTonalPalette(request);
|
|
1368
|
+
return !(
|
|
1369
|
+
samePalette(candidate.palette, data.palette) &&
|
|
1370
|
+
(data.black == null || data.black === candidate.black) &&
|
|
1371
|
+
(data.white == null || data.white === candidate.white)
|
|
1372
|
+
);
|
|
1373
|
+
} catch {
|
|
1374
|
+
return true;
|
|
1375
|
+
}
|
|
1376
|
+
return refsDiffer(cwd, slug, data.palette) !== false;
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Whether the selected-stops file holds a shade that differs from the
|
|
1381
|
+
* palette's: true when one differs, false when every one matches, null
|
|
1382
|
+
* when there is no such file to compare.
|
|
1383
|
+
* @param {string} cwd
|
|
1384
|
+
* @param {string} slug
|
|
1385
|
+
* @param {any} palette the palette file's colors
|
|
1386
|
+
* @returns {boolean | null}
|
|
1387
|
+
*/
|
|
1388
|
+
function refsDiffer(cwd, slug, palette) {
|
|
1389
|
+
const file = path.join(cwd, paletteFiles(slug).refs);
|
|
1390
|
+
if (!fs.existsSync(file)) return null;
|
|
1391
|
+
const refs = objectLiteral(fs.readFileSync(file, 'utf8'), 0);
|
|
1392
|
+
if (!refs || typeof refs !== 'object') return true;
|
|
1393
|
+
for (const [fam, f] of Object.entries(refs)) {
|
|
1394
|
+
if (typeof f !== 'object' || !f) continue;
|
|
1395
|
+
for (const [m, ramp] of Object.entries(/** @type {any} */ (f)))
|
|
1396
|
+
for (const [stop, color] of Object.entries(/** @type {any} */ (ramp))) {
|
|
1397
|
+
const mine = palette?.[fam]?.[m];
|
|
1398
|
+
const at = mine
|
|
1399
|
+
? Object.entries(mine).find(([k]) => Number(k) === Number(stop))?.[1]
|
|
1400
|
+
: undefined;
|
|
1401
|
+
if (String(at ?? '').toLowerCase() !== String(color).toLowerCase())
|
|
1402
|
+
return true;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
return false;
|
|
1140
1406
|
}
|
|
1141
1407
|
|
|
1142
1408
|
/**
|
|
@@ -1304,6 +1570,9 @@ function over(name, r, under) {
|
|
|
1304
1570
|
/** @param {number} r */
|
|
1305
1571
|
const round = r => Math.round(r * 100) / 100;
|
|
1306
1572
|
|
|
1573
|
+
/** A stop as text: a layout may hold 16.666666666666668. @param {number} s */
|
|
1574
|
+
const shade = s => String(round(s));
|
|
1575
|
+
|
|
1307
1576
|
/**
|
|
1308
1577
|
* The colors and token mapping of a theme's palette, or null when it sets no
|
|
1309
1578
|
* color dial. Reads the config the settings ask for and runs the generator
|
|
@@ -1322,20 +1591,8 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1322
1591
|
const {config} = plan;
|
|
1323
1592
|
const candidate = generate(config, paletteFiles(slug).config);
|
|
1324
1593
|
const t = tools(candidate, data, base);
|
|
1325
|
-
const {stops, at, ref, exactOf, surfaces} = t;
|
|
1326
|
-
const modes =
|
|
1327
|
-
/**
|
|
1328
|
-
* The secondary text color in a mode: an exact setting, else the neutral
|
|
1329
|
-
* color's, else the base theme's; null when it is not a fixed color.
|
|
1330
|
-
* @param {Mode} m
|
|
1331
|
-
*/
|
|
1332
|
-
const textSecondary = m => {
|
|
1333
|
-
const v =
|
|
1334
|
-
exactOf('--color-text-secondary', m) ??
|
|
1335
|
-
tokens['--color-text-secondary']?.[m].color ??
|
|
1336
|
-
base?.[m]?.['--color-text-secondary'];
|
|
1337
|
-
return v && parseColor(v) && alphaOf(v) >= 1 ? v : null;
|
|
1338
|
-
};
|
|
1594
|
+
const {stops, at, ref, exactOf, rawOf, side, solid, surfaces} = t;
|
|
1595
|
+
const modes = modesOf(data);
|
|
1339
1596
|
/** @type {PaletteMapping['tokens']} */
|
|
1340
1597
|
const tokens = {};
|
|
1341
1598
|
/** @type {ContrastCheck[]} */
|
|
@@ -1416,7 +1673,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1416
1673
|
put(
|
|
1417
1674
|
token,
|
|
1418
1675
|
'neutral',
|
|
1419
|
-
each(m => ref('neutral', m, at(pair[m
|
|
1676
|
+
each(m => ref('neutral', m, at(pair[side(m)]))),
|
|
1420
1677
|
);
|
|
1421
1678
|
}
|
|
1422
1679
|
for (const [token, pair] of Object.entries(NEUTRAL_TINTS))
|
|
@@ -1424,7 +1681,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1424
1681
|
token,
|
|
1425
1682
|
'neutral',
|
|
1426
1683
|
each(m => {
|
|
1427
|
-
const [s, a] = pair[m
|
|
1684
|
+
const [s, a] = pair[side(m)];
|
|
1428
1685
|
return ref('neutral', m, at(s), a);
|
|
1429
1686
|
}),
|
|
1430
1687
|
);
|
|
@@ -1440,7 +1697,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1440
1697
|
token,
|
|
1441
1698
|
'neutral',
|
|
1442
1699
|
m,
|
|
1443
|
-
at(NEUTRAL_STOPS[token][m
|
|
1700
|
+
at(NEUTRAL_STOPS[token][side(m)]),
|
|
1444
1701
|
surfaces(m, 'neutral'),
|
|
1445
1702
|
needs,
|
|
1446
1703
|
),
|
|
@@ -1484,7 +1741,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1484
1741
|
/** @type {Partial<Record<Mode, string>>} */
|
|
1485
1742
|
const exactFill = {};
|
|
1486
1743
|
for (const m of modes) {
|
|
1487
|
-
const v =
|
|
1744
|
+
const v = rawOf(names.fill, m);
|
|
1488
1745
|
if (v) exactFill[m] = v;
|
|
1489
1746
|
}
|
|
1490
1747
|
if (Object.keys(exactFill).length) exact[names.fill] = exactFill;
|
|
@@ -1520,7 +1777,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1520
1777
|
ratio: plain.ratio,
|
|
1521
1778
|
needs: TEXT,
|
|
1522
1779
|
pass: true,
|
|
1523
|
-
note: `in dark, ${names.fill} is shade ${found}, not your exact color: ${plain.why}${found === start ? '' : `; shade ${start} does not pass either, so it is the nearest shade that does`}`,
|
|
1780
|
+
note: `in dark, ${names.fill} is shade ${shade(found)}, not your exact color: ${plain.why}${found === start ? '' : `; shade ${shade(start)} does not pass either, so it is the nearest shade that does`}`,
|
|
1524
1781
|
});
|
|
1525
1782
|
}
|
|
1526
1783
|
put(names.fill, f.id, fill);
|
|
@@ -1530,10 +1787,11 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1530
1787
|
// text changes instead.
|
|
1531
1788
|
const on = each(m => {
|
|
1532
1789
|
const used = exactFill[m] ?? /** @type {StopRef} */ (fill[m]).color;
|
|
1533
|
-
|
|
1790
|
+
// A see-through exact fill is measured as it shows on the surface.
|
|
1791
|
+
const o = t.onFor(fillWord, m, solid(used, m, f.id));
|
|
1534
1792
|
const what = exactFill[m]
|
|
1535
|
-
? `your exact ${names.fill} (${used})`
|
|
1536
|
-
: `${names.fill} (shade ${fill[m]?.stop})`;
|
|
1793
|
+
? `your exact ${names.fill} (${used}${alphaOf(used) < 1 ? `, as it shows: ${solid(used, m, f.id)}` : ''})`
|
|
1794
|
+
: `${names.fill} (shade ${shade(Number(fill[m]?.stop))})`;
|
|
1537
1795
|
const moved = o.on !== o.first;
|
|
1538
1796
|
if (reports(names.on))
|
|
1539
1797
|
checks.push({
|
|
@@ -1563,7 +1821,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1563
1821
|
// the exact color, the dial's or the token's.
|
|
1564
1822
|
if (modes.includes('light') && has(names.fill)) {
|
|
1565
1823
|
const used = exactFill.light ?? /** @type {StopRef} */ (fill.light).color;
|
|
1566
|
-
const p = t.page(used, 'light', f.id);
|
|
1824
|
+
const p = t.page(solid(used, 'light', f.id), 'light', f.id);
|
|
1567
1825
|
if (p < NON_TEXT)
|
|
1568
1826
|
checks.push({
|
|
1569
1827
|
token: names.fill,
|
|
@@ -1580,66 +1838,42 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1580
1838
|
});
|
|
1581
1839
|
}
|
|
1582
1840
|
|
|
1583
|
-
// The tint: never the fill's own shade, see-through
|
|
1584
|
-
//
|
|
1585
|
-
//
|
|
1586
|
-
// and the official neutral theme's own pair (text-secondary on the
|
|
1587
|
-
// accent tint, read from the installed theme); only then it takes the
|
|
1588
|
-
// nearest shade that reads that well (darker first in dark, lighter
|
|
1589
|
-
// first in light), so it never ships below the official theme.
|
|
1841
|
+
// The tint: the official stop, never the fill's own shade, see-through
|
|
1842
|
+
// or not. Secondary text on the parts that sit on the accent tint is
|
|
1843
|
+
// lifted instead, as the official neutral theme lifts it (`lift`).
|
|
1590
1844
|
const muted = each(m => {
|
|
1591
|
-
const i = m
|
|
1845
|
+
const i = side(m);
|
|
1592
1846
|
const spec = word ? STATUS_MUTED[i] : ACCENT_MUTED[i];
|
|
1593
1847
|
const [s, alpha] = Array.isArray(spec) ? spec : [spec, undefined];
|
|
1594
|
-
|
|
1595
|
-
//
|
|
1596
|
-
const usual =
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
(a
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
const secondary = word ? null : textSecondary(m);
|
|
1605
|
-
if (!secondary) return ref(f.id, m, away[0] ?? start, alpha);
|
|
1606
|
-
const scored = away.map(x => ({
|
|
1607
|
-
stop: x,
|
|
1608
|
-
r: contrast(secondary, ref(f.id, m, x).color),
|
|
1609
|
-
}));
|
|
1610
|
-
const official = officialCitation(m);
|
|
1611
|
-
if (official == null) return ref(f.id, m, away[0] ?? start, alpha);
|
|
1612
|
-
// Readable text (4.5:1) or the official theme's own ratio, whichever
|
|
1613
|
-
// asks less: in dark the official pair reads under 4.5:1, so that is
|
|
1614
|
-
// the bar; in light it reads above, so the tint moves only for text
|
|
1615
|
-
// that does not read.
|
|
1616
|
-
const needs = Math.min(TEXT, official);
|
|
1617
|
-
const b =
|
|
1618
|
-
scored.find(x => x.r >= needs - 0.005) ??
|
|
1619
|
-
scored.reduce((x, y) => (y.r > x.r ? y : x));
|
|
1620
|
-
const pass = b.r >= needs - 0.005;
|
|
1621
|
-
if (reports(names.muted) && (b.stop !== start || !pass))
|
|
1622
|
-
checks.push({
|
|
1623
|
-
token: names.muted,
|
|
1624
|
-
mode: m,
|
|
1625
|
-
stop: b.stop,
|
|
1626
|
-
preferred: start,
|
|
1627
|
-
against: 'citation text (--color-text-secondary)',
|
|
1628
|
-
ratio: round(b.r),
|
|
1629
|
-
needs: round(needs),
|
|
1630
|
-
pass,
|
|
1631
|
-
note: pass
|
|
1632
|
-
? `${names.muted} uses shade ${b.stop} in ${m}, not ${start}, so citation text (--color-text-secondary) reads at ${round(b.r)}:1 on it${needs < TEXT ? `, as well as in the official neutral theme (${round(needs)}:1)` : ''}`
|
|
1633
|
-
: `citation text (--color-text-secondary) reads at only ${round(b.r)}:1 in ${m} on ${names.muted} even at shade ${b.stop}, the most contrasting one (needs ${round(needs)}:1): pick another ${f.id}, or set ${names.muted} exactly`,
|
|
1634
|
-
});
|
|
1635
|
-
return ref(f.id, m, b.stop, alpha);
|
|
1848
|
+
// Nearest the official stop first, both ways; on a tie (a layout
|
|
1849
|
+
// without that stop) lighter first in light, darker in dark.
|
|
1850
|
+
const usual = i === 0 ? 1 : -1;
|
|
1851
|
+
const order = [...stops].sort(
|
|
1852
|
+
(a, b) =>
|
|
1853
|
+
Math.abs(a - s) - Math.abs(b - s) ||
|
|
1854
|
+
(Math.sign(b - a) === usual ? 1 : -1),
|
|
1855
|
+
);
|
|
1856
|
+
const away = order.filter(x => x !== fill[m]?.stop);
|
|
1857
|
+
return ref(f.id, m, away[0] ?? order[0], alpha);
|
|
1636
1858
|
});
|
|
1637
1859
|
put(names.muted, f.id, muted);
|
|
1638
1860
|
/** The tint the theme really shows: an exact setting wins. @param {Mode} m */
|
|
1639
1861
|
const mutedSeen = m => {
|
|
1640
|
-
const own =
|
|
1862
|
+
const own = rawOf(names.muted, m);
|
|
1641
1863
|
return own
|
|
1642
|
-
?
|
|
1864
|
+
? surfaces(m, f.id).map(
|
|
1865
|
+
([n, bg]) =>
|
|
1866
|
+
/** @type {[string, string]} */ ([
|
|
1867
|
+
`your exact ${names.muted} over ${n}`,
|
|
1868
|
+
hex(
|
|
1869
|
+
compositeOver(
|
|
1870
|
+
/** @type {[number, number, number]} */ (parseColor(own)),
|
|
1871
|
+
alphaOf(own),
|
|
1872
|
+
/** @type {[number, number, number]} */ (parseColor(bg)),
|
|
1873
|
+
),
|
|
1874
|
+
),
|
|
1875
|
+
]),
|
|
1876
|
+
)
|
|
1643
1877
|
: over(
|
|
1644
1878
|
names.muted,
|
|
1645
1879
|
/** @type {StopRef} */ (muted[m]),
|
|
@@ -1652,7 +1886,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1652
1886
|
names.text,
|
|
1653
1887
|
f.id,
|
|
1654
1888
|
m,
|
|
1655
|
-
at(TEXT_STOP[m
|
|
1889
|
+
at(TEXT_STOP[side(m)]),
|
|
1656
1890
|
[...surfaces(m, f.id), ...mutedSeen(m)],
|
|
1657
1891
|
TEXT,
|
|
1658
1892
|
),
|
|
@@ -1665,14 +1899,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1665
1899
|
onMuted,
|
|
1666
1900
|
f.id,
|
|
1667
1901
|
each(m =>
|
|
1668
|
-
pick(
|
|
1669
|
-
onMuted,
|
|
1670
|
-
f.id,
|
|
1671
|
-
m,
|
|
1672
|
-
at(ON_MUTED[m === 'light' ? 0 : 1]),
|
|
1673
|
-
mutedSeen(m),
|
|
1674
|
-
TEXT,
|
|
1675
|
-
),
|
|
1902
|
+
pick(onMuted, f.id, m, at(ON_MUTED[side(m)]), mutedSeen(m), TEXT),
|
|
1676
1903
|
),
|
|
1677
1904
|
);
|
|
1678
1905
|
}
|
|
@@ -1680,7 +1907,7 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1680
1907
|
put(
|
|
1681
1908
|
names.border,
|
|
1682
1909
|
f.id,
|
|
1683
|
-
each(m => ref(f.id, m, at(BORDER[m
|
|
1910
|
+
each(m => ref(f.id, m, at(BORDER[side(m)]))),
|
|
1684
1911
|
);
|
|
1685
1912
|
// The focus ring follows the fill; with an exact fill it keeps
|
|
1686
1913
|
// following that (Core's ring reads --color-accent).
|
|
@@ -1702,24 +1929,189 @@ export function paletteMapping(cwd, slug, data, base, tokenDefaults) {
|
|
|
1702
1929
|
);
|
|
1703
1930
|
}
|
|
1704
1931
|
}
|
|
1932
|
+
|
|
1933
|
+
// Secondary text on the parts the official neutral theme lifts it on
|
|
1934
|
+
// (LIFT_PARTS), lifted the same way, for every accent: for each
|
|
1935
|
+
// background (the accent tint, the neutral track), the gray shade
|
|
1936
|
+
// nearest the secondary text's own that reads at 4.5:1 on it and on it
|
|
1937
|
+
// under a hover, over every surface. The grays are the neutral color's,
|
|
1938
|
+
// else a gray ramp the generator grows from the base theme's own
|
|
1939
|
+
// secondary text (written as colors, not shades of the palette). The
|
|
1940
|
+
// tint stays at its official stop. A mode where the theme sets
|
|
1941
|
+
// secondary text exactly takes that value instead, as written.
|
|
1942
|
+
/** @type {Record<string, Partial<Record<Mode, StopRef>>> | null} */
|
|
1943
|
+
let lift = null;
|
|
1944
|
+
{
|
|
1945
|
+
/** @param {Mode} m @param {string} token */
|
|
1946
|
+
const valueOf = (m, token) => {
|
|
1947
|
+
const v =
|
|
1948
|
+
rawOf(token, m) ?? tokens[token]?.[m].color ?? base?.[m]?.[token];
|
|
1949
|
+
return v && parseColor(v) ? v : null;
|
|
1950
|
+
};
|
|
1951
|
+
/** The secondary text a mode starts from. @param {Mode} m */
|
|
1952
|
+
const startText = m => {
|
|
1953
|
+
const v =
|
|
1954
|
+
tokens['--color-text-secondary']?.[m].color ??
|
|
1955
|
+
base?.[m]?.['--color-text-secondary'];
|
|
1956
|
+
return v && parseColor(v)
|
|
1957
|
+
? hex(/** @type {number[]} */ (parseColor(v)))
|
|
1958
|
+
: null;
|
|
1959
|
+
};
|
|
1960
|
+
/**
|
|
1961
|
+
* The gray ramp of a mode, and whether its shades are the palette's
|
|
1962
|
+
* neutral ones (else plain colors).
|
|
1963
|
+
* @param {Mode} m
|
|
1964
|
+
* @returns {{ramp: Record<string, string>, palette: boolean} | null}
|
|
1965
|
+
*/
|
|
1966
|
+
const grays = m => {
|
|
1967
|
+
if (neutral)
|
|
1968
|
+
return {
|
|
1969
|
+
ramp: /** @type {any} */ (candidate.palette.neutral)[m],
|
|
1970
|
+
palette: true,
|
|
1971
|
+
};
|
|
1972
|
+
const seed = startText(m);
|
|
1973
|
+
if (!seed) return null;
|
|
1974
|
+
try {
|
|
1975
|
+
const g = generateTonalPalette({
|
|
1976
|
+
modeStrategy: m === 'light' ? 'light-only' : 'dark-only',
|
|
1977
|
+
neutralProfile: 'custom',
|
|
1978
|
+
families: [{id: 'gray', seed, kind: 'neutral'}],
|
|
1979
|
+
});
|
|
1980
|
+
return {ramp: /** @type {any} */ (g.palette.gray)[m], palette: false};
|
|
1981
|
+
} catch {
|
|
1982
|
+
return null;
|
|
1983
|
+
}
|
|
1984
|
+
};
|
|
1985
|
+
/**
|
|
1986
|
+
* A color drawn over each of `under`, as the eye sees it.
|
|
1987
|
+
* @param {string} name @param {string} color @param {Array<[string, string]>} under
|
|
1988
|
+
* @returns {Array<[string, string]>}
|
|
1989
|
+
*/
|
|
1990
|
+
const drawn = (name, color, under) => {
|
|
1991
|
+
const top = /** @type {[number, number, number]} */ (parseColor(color));
|
|
1992
|
+
const a = alphaOf(color);
|
|
1993
|
+
return under.map(([n, c]) => [
|
|
1994
|
+
`${name} over ${n}`,
|
|
1995
|
+
hex(
|
|
1996
|
+
compositeOver(
|
|
1997
|
+
top,
|
|
1998
|
+
a,
|
|
1999
|
+
/** @type {[number, number, number]} */ (parseColor(c)),
|
|
2000
|
+
),
|
|
2001
|
+
),
|
|
2002
|
+
]);
|
|
2003
|
+
};
|
|
2004
|
+
/** @type {Record<string, Partial<Record<Mode, StopRef>>>} */
|
|
2005
|
+
const found = {};
|
|
2006
|
+
for (const ground of new Set(LIFT_PARTS.map(([, , g]) => g))) {
|
|
2007
|
+
const {what, parts} = LIFT_GROUNDS[ground];
|
|
2008
|
+
/** @type {Partial<Record<Mode, StopRef>>} */
|
|
2009
|
+
const byMode = {};
|
|
2010
|
+
for (const m of modes) {
|
|
2011
|
+
const own = rawOf('--color-text-secondary', m);
|
|
2012
|
+
if (own) {
|
|
2013
|
+
byMode[m] = {stop: 0, color: own, family: 'literal'};
|
|
2014
|
+
continue;
|
|
2015
|
+
}
|
|
2016
|
+
const fillColor = valueOf(m, ground);
|
|
2017
|
+
const g = grays(m);
|
|
2018
|
+
const text = startText(m);
|
|
2019
|
+
if (!fillColor || !g || !text) break;
|
|
2020
|
+
const seen = drawn(what, fillColor, surfaces(m, 'neutral'));
|
|
2021
|
+
const hover = valueOf(m, '--color-overlay-hover');
|
|
2022
|
+
const on = [
|
|
2023
|
+
...seen,
|
|
2024
|
+
...(hover && alphaOf(hover) > 0
|
|
2025
|
+
? drawn('a hover', hover, seen).map(
|
|
2026
|
+
([n, c]) =>
|
|
2027
|
+
/** @type {[string, string]} */ ([
|
|
2028
|
+
n.replace(/^a hover over (.*)$/, '$1 under a hover'),
|
|
2029
|
+
c,
|
|
2030
|
+
]),
|
|
2031
|
+
)
|
|
2032
|
+
: []),
|
|
2033
|
+
];
|
|
2034
|
+
const keys = Object.keys(g.ramp)
|
|
2035
|
+
.map(Number)
|
|
2036
|
+
.sort((a, b) => a - b);
|
|
2037
|
+
const start = keys.reduce((x, y) =>
|
|
2038
|
+
perceptualDelta(g.ramp[y], text) < perceptualDelta(g.ramp[x], text)
|
|
2039
|
+
? y
|
|
2040
|
+
: x,
|
|
2041
|
+
);
|
|
2042
|
+
const scored = keys
|
|
2043
|
+
.sort(
|
|
2044
|
+
(a, b) =>
|
|
2045
|
+
Math.abs(a - start) - Math.abs(b - start) ||
|
|
2046
|
+
(Math.sign(b - a) === TOWARD_CONTRAST[m] ? 1 : -1),
|
|
2047
|
+
)
|
|
2048
|
+
.map(stop => ({
|
|
2049
|
+
stop,
|
|
2050
|
+
r: Math.min(...on.map(([, bg]) => contrast(g.ramp[stop], bg))),
|
|
2051
|
+
}));
|
|
2052
|
+
const b =
|
|
2053
|
+
scored.find(x => x.r >= TEXT) ??
|
|
2054
|
+
scored.reduce((x, y) => (y.r > x.r ? y : x));
|
|
2055
|
+
byMode[m] = g.palette
|
|
2056
|
+
? ref('neutral', m, b.stop)
|
|
2057
|
+
: {stop: b.stop, color: g.ramp[b.stop], family: 'literal'};
|
|
2058
|
+
const moved =
|
|
2059
|
+
hex(/** @type {number[]} */ (parseColor(g.ramp[b.stop]))) !== text;
|
|
2060
|
+
if (b.r < TEXT || moved)
|
|
2061
|
+
checks.push({
|
|
2062
|
+
token: '--color-text-secondary',
|
|
2063
|
+
mode: m,
|
|
2064
|
+
stop: b.stop,
|
|
2065
|
+
preferred: start,
|
|
2066
|
+
against: `${what} over the surfaces`,
|
|
2067
|
+
ratio: round(b.r),
|
|
2068
|
+
needs: TEXT,
|
|
2069
|
+
pass: b.r >= TEXT,
|
|
2070
|
+
dials: ['accent', 'neutral'],
|
|
2071
|
+
note:
|
|
2072
|
+
b.r >= TEXT
|
|
2073
|
+
? `--color-text-secondary on ${parts} uses ${g.ramp[b.stop]} in ${m}, not ${text}, so it reads at ${round(b.r)}:1 on ${what} and under a hover, as the official theme lifts it`
|
|
2074
|
+
: `--color-text-secondary on ${parts} reads at only ${round(b.r)}:1 in ${m} on ${what} even at ${g.ramp[b.stop]}, the most contrasting gray (needs ${TEXT}:1): pick another accent or neutral, or set --color-text-secondary on those parts exactly`,
|
|
2075
|
+
});
|
|
2076
|
+
}
|
|
2077
|
+
if (modes.every(m => byMode[m])) found[ground] = byMode;
|
|
2078
|
+
}
|
|
2079
|
+
if (Object.keys(found).length) lift = found;
|
|
2080
|
+
}
|
|
2081
|
+
|
|
1705
2082
|
return {
|
|
1706
2083
|
candidate,
|
|
1707
2084
|
families: fams,
|
|
1708
2085
|
tokens,
|
|
1709
|
-
contrast: checks,
|
|
2086
|
+
contrast: checks.filter(c => c.note !== ''),
|
|
2087
|
+
lift,
|
|
1710
2088
|
vibrancy: config.vibrancy ?? VIBRANCY_DEFAULT,
|
|
1711
2089
|
exact,
|
|
1712
2090
|
notes: [
|
|
1713
2091
|
...plan.notes,
|
|
1714
2092
|
...(paletteEdited(cwd, slug)
|
|
1715
2093
|
? [
|
|
1716
|
-
`${paletteFiles(slug).palette} was edited by hand
|
|
2094
|
+
`${paletteFiles(slug).palette} was edited by hand, but the theme never reads it: it reads ${paletteFiles(slug).refs}, which the editor writes from the generator, so the edit does not show. The next color change asks whether to keep or discard it`,
|
|
1717
2095
|
]
|
|
1718
2096
|
: []),
|
|
1719
2097
|
],
|
|
1720
2098
|
};
|
|
1721
2099
|
}
|
|
1722
2100
|
|
|
2101
|
+
/**
|
|
2102
|
+
* The color dial whose generated colors a token belongs to, or null: an
|
|
2103
|
+
* exact setting of it changes what that dial's mapping picks around it.
|
|
2104
|
+
* @param {string} token
|
|
2105
|
+
* @returns {string | null}
|
|
2106
|
+
*/
|
|
2107
|
+
export function paletteDialOf(token) {
|
|
2108
|
+
if (!PALETTE_TOKENS.has(token)) return null;
|
|
2109
|
+
if (/accent|^--focus-outline-color$/.test(token)) return 'accent';
|
|
2110
|
+
for (const [dial, word] of Object.entries(STATUS_TOKEN))
|
|
2111
|
+
if (new RegExp(`-${word}(-muted)?$`).test(token)) return dial;
|
|
2112
|
+
return 'neutral';
|
|
2113
|
+
}
|
|
2114
|
+
|
|
1723
2115
|
/** Every token a color dial can point at a generated shade. */
|
|
1724
2116
|
export const PALETTE_TOKENS = new Set([
|
|
1725
2117
|
...Object.keys(NEUTRAL_STOPS),
|
|
@@ -1760,6 +2152,10 @@ export function mappingRows(dial) {
|
|
|
1760
2152
|
`${t}: light shade ${l} at opacity ${la}, dark shade ${d} at opacity ${da}`,
|
|
1761
2153
|
),
|
|
1762
2154
|
"--color-background-body: the base theme's page color, so a tinted gray never tints the page",
|
|
2155
|
+
...Object.values(LIFT_GROUNDS).map(
|
|
2156
|
+
g =>
|
|
2157
|
+
`--color-text-secondary on ${g.parts}: the shade nearest the secondary text's that reads at ${TEXT}:1 on ${g.what} and under a hover, as the official theme lifts it`,
|
|
2158
|
+
),
|
|
1763
2159
|
];
|
|
1764
2160
|
const word = dial === 'accent' ? null : STATUS_TOKEN[dial];
|
|
1765
2161
|
if (dial !== 'accent' && !word) return [];
|
|
@@ -1775,7 +2171,7 @@ export function mappingRows(dial) {
|
|
|
1775
2171
|
`${t('--color-text-$', '--color-text-accent')} and ${t('--color-icon-$', '--color-icon-accent')}: light shade ${TEXT_STOP[0]}, dark shade ${TEXT_STOP[1]} (moves to the nearest shade, darker or lighter, that reads at ${TEXT}:1 on the surfaces and the muted tint)`,
|
|
1776
2172
|
word
|
|
1777
2173
|
? `--color-${word}-muted: light shade ${STATUS_MUTED[0]}, dark shade ${STATUS_MUTED[1][0]} at opacity ${STATUS_MUTED[1][1]} over the surface, never the fill's own shade`
|
|
1778
|
-
: `--color-accent-muted: light shade ${ACCENT_MUTED[0]}, dark shade ${ACCENT_MUTED[1]}, as the official neutral theme maps it;
|
|
2174
|
+
: `--color-accent-muted: light shade ${ACCENT_MUTED[0]}, dark shade ${ACCENT_MUTED[1]}, as the official neutral theme maps it, never the fill's own shade; secondary text on the parts that sit on it (selected items and rows, a dropzone, numbered citations) is lifted instead, to the gray nearest it that reads at ${TEXT}:1 on the tint and under a hover: the neutral color's shades, else grays grown from the base theme's own secondary text`,
|
|
1779
2175
|
];
|
|
1780
2176
|
if (word)
|
|
1781
2177
|
rows.push(
|
|
@@ -1826,8 +2222,8 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
|
|
|
1826
2222
|
main[m].exact
|
|
1827
2223
|
? m === 'dark' && modes.length > 1
|
|
1828
2224
|
? 'the same exact color in dark'
|
|
1829
|
-
: `your exact color (${main[m].color}, ${dial} shade ${main[m].stop}) in ${m}`
|
|
1830
|
-
: `${dial} shade ${main[m].stop} (${main[m].color}) in ${m}`;
|
|
2225
|
+
: `your exact color (${main[m].color}, ${dial} shade ${shade(main[m].stop)}) in ${m}`
|
|
2226
|
+
: `${dial} shade ${shade(main[m].stop)} (${main[m].color}) in ${m}`;
|
|
1831
2227
|
notes.push(`${token} uses ${modes.map(part).join(' and ')}`);
|
|
1832
2228
|
}
|
|
1833
2229
|
const given = pal.families.find(x => x.dial === dial);
|
|
@@ -1836,17 +2232,18 @@ export function paletteNotes(pal, dial, slug, modes = ['light', 'dark']) {
|
|
|
1836
2232
|
`your ${dial} ${given.value} is outside the colors every screen shows (sRGB), so the nearest one, ${given.seed}, is used`,
|
|
1837
2233
|
);
|
|
1838
2234
|
for (const c of pal.contrast) {
|
|
1839
|
-
if (pal.tokens[c.token]?.family !== dial)
|
|
2235
|
+
if (pal.tokens[c.token]?.family !== dial && !c.dials?.includes(dial))
|
|
2236
|
+
continue;
|
|
1840
2237
|
// A theme with one mode never shows the other one's shades.
|
|
1841
2238
|
if (!modes.includes(c.mode)) continue;
|
|
1842
2239
|
if (c.note) notes.push(c.note);
|
|
1843
2240
|
else if (!c.pass)
|
|
1844
2241
|
notes.push(
|
|
1845
|
-
`${c.token} reads at only ${c.ratio}:1 in ${c.mode} on ${c.against} (needs ${c.needs}:1) even at shade ${c.stop}, the most contrasting one: pick a lighter or darker ${dial}, or set ${c.token} exactly`,
|
|
2242
|
+
`${c.token} reads at only ${c.ratio}:1 in ${c.mode} on ${c.against} (needs ${c.needs}:1) even at shade ${shade(c.stop)}, the most contrasting one: pick a lighter or darker ${dial}, or set ${c.token} exactly`,
|
|
1846
2243
|
);
|
|
1847
2244
|
else if (c.stop !== c.preferred)
|
|
1848
2245
|
notes.push(
|
|
1849
|
-
`${c.token} uses shade ${c.stop} in ${c.mode}, not ${c.preferred}, so it reads at ${c.ratio}:1 on ${c.against}`,
|
|
2246
|
+
`${c.token} uses shade ${shade(c.stop)} in ${c.mode}, not ${shade(c.preferred)}, so it reads at ${c.ratio}:1 on ${c.against}`,
|
|
1850
2247
|
);
|
|
1851
2248
|
}
|
|
1852
2249
|
notes.push(
|