@astryxdesign/cli 0.7.14-canary.gfdb9213 → 0.7.14
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 +197 -0
- package/api/theme/_adapter.d.mts +33 -0
- package/api/theme/_adapter.mjs +352 -16
- package/api/theme/build/build.mjs +261 -10
- package/api/theme/eject/eject.mjs +13 -1
- package/api/theme/list/list.mjs +11 -2
- package/api/theme/template/template.mjs +139 -6
- package/api/theme/theme.type.d.mts +15 -1
- package/api/theme/theme.type.mjs +9 -3
- package/api/theme/themeAdd.doc.mjs +1 -1
- package/api/theme/themeBuild.doc.mjs +10 -2
- package/api/theme/themeEject.doc.mjs +2 -2
- package/api/theme/themeListAvailable.doc.mjs +1 -1
- package/api/theme/themeRemove.doc.mjs +1 -1
- package/api/theme/themeTemplate.doc.mjs +8 -0
- package/api/theme/themeUse.doc.mjs +1 -1
- package/api/theme-edit/_adapter.d.mts +10 -2
- package/api/theme-edit/_adapter.mjs +52 -31
- package/api/theme-edit/_check.d.mts +28 -25
- package/api/theme-edit/_check.mjs +586 -548
- package/api/theme-edit/_color.d.mts +28 -2
- package/api/theme-edit/_color.mjs +306 -68
- package/api/theme-edit/_compiler.d.mts +8 -4
- package/api/theme-edit/_compiler.mjs +30 -27
- package/api/theme-edit/_context.d.mts +10 -4
- package/api/theme-edit/_context.mjs +21 -4
- package/api/theme-edit/_edit.mjs +300 -43
- package/api/theme-edit/_how-commands.d.mts +91 -0
- package/api/theme-edit/_how-commands.mjs +269 -0
- package/api/theme-edit/_how-question.d.mts +57 -0
- package/api/theme-edit/_how-question.mjs +2574 -0
- package/api/theme-edit/_how.d.mts +25 -17
- package/api/theme-edit/_how.mjs +727 -305
- package/api/theme-edit/_palette.d.mts +127 -19
- package/api/theme-edit/_palette.mjs +1313 -399
- package/api/theme-edit/_parts.mjs +36 -3
- package/api/theme-edit/_png.d.mts +18 -6
- package/api/theme-edit/_png.mjs +135 -25
- package/api/theme-edit/_preview-app.d.mts +26 -7
- package/api/theme-edit/_preview-app.mjs +1611 -280
- package/api/theme-edit/_preview.d.mts +4 -2
- package/api/theme-edit/_preview.mjs +18 -7
- package/api/theme-edit/_settings.d.mts +56 -5
- package/api/theme-edit/_settings.mjs +197 -49
- package/api/theme-edit/_tables.d.mts +0 -12
- package/api/theme-edit/_tables.mjs +24 -97
- package/api/theme-edit/theme-edit.type.d.mts +22 -5
- package/api/theme-edit/theme-edit.type.mjs +17 -6
- package/api/theme-edit/themeEditHow.doc.mjs +13 -3
- package/api/theme-edit/themeEditNew.doc.mjs +2 -1
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +16 -4
- package/api/theme-edit/themeEditPreviewApp.doc.mjs +12 -4
- package/api/theme-edit/themeEditPreviewList.doc.mjs +9 -1
- package/api/theme-edit/themeEditPreviewRemove.doc.mjs +27 -2
- package/api/theme-edit/themeEditUndo.doc.mjs +1 -1
- package/assets/docs.generated.json +1 -0
- package/assets/preview-app/gitignore +3 -0
- package/assets/templates/components.generated.json +1 -0
- package/clients/cli/bin/astryx.mjs +37 -5
- package/clients/cli/commands/experimental/theme.mjs +231 -31
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +14 -5
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +0 -1
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +3 -2
- package/clients/cli/commands/experimental-theme-preview-app.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-list.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-preview-remove.doc.mjs +2 -2
- package/clients/cli/commands/experimental-theme-targets.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +2 -2
- package/clients/cli/commands/theme-build.doc.mjs +1 -1
- package/clients/cli/commands/theme-eject.doc.mjs +3 -3
- package/clients/cli/commands/theme-remove.doc.mjs +2 -2
- package/clients/cli/commands/theme-template.doc.mjs +11 -4
- package/clients/cli/commands/theme.mjs +104 -40
- package/clients/cli/commands.generated.json +1 -0
- package/clients/cli/index.mjs +96 -4
- package/clients/cli/lib/json-shim.mjs +29 -1
- package/foundation/config/project.d.mts +16 -2
- package/foundation/config/project.mjs +40 -6
- package/foundation/config/theme-state.d.mts +9 -0
- package/foundation/config/theme-state.mjs +20 -1
- package/foundation/discovery/template-adapter.d.mts +12 -1
- package/foundation/discovery/template-adapter.mjs +24 -1
- package/foundation/discovery/template-needs.d.mts +7 -0
- package/foundation/discovery/template-needs.mjs +117 -8
- package/foundation/discovery/template-source-tree.d.mts +5 -1
- package/foundation/discovery/template-source-tree.mjs +6 -4
- package/foundation/discovery/theme-discovery.d.mts +14 -3
- package/foundation/discovery/theme-discovery.mjs +45 -12
- package/foundation/doc-compiler/import.mjs +68 -3
- package/foundation/doc-compiler/stored-docs.d.mts +27 -0
- package/foundation/doc-compiler/stored-docs.mjs +65 -0
- package/foundation/fs/fs-error.d.mts +17 -0
- package/foundation/fs/fs-error.mjs +34 -0
- package/package.json +6 -6
|
@@ -37,9 +37,9 @@ export function context(cwd: string): Promise<{
|
|
|
37
37
|
allReads: (target: string) => Set<string>;
|
|
38
38
|
anyReader: (tok: string) => string[];
|
|
39
39
|
checkTokenOn: (theme: string, target: string, token: string, value: string, P: string) => CheckFailure | null;
|
|
40
|
-
checkTokenGlobal: (token: string,
|
|
40
|
+
checkTokenGlobal: (token: string, _P: string) => CheckFailure | null;
|
|
41
41
|
variantValues: (target: string) => Record<string, string[]>;
|
|
42
|
-
contrast: (value: (pair:
|
|
42
|
+
contrast: (value: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, baseValue: (pair: TextPair, side: "fg" | "bg", mode: string) => string | null | undefined, modes: string[], { parseColor, ratio, alphaOf, compositeOver, page }: {
|
|
43
43
|
parseColor: (v: unknown) => [number, number, number] | null;
|
|
44
44
|
ratio: (a: number[], b: number[]) => number;
|
|
45
45
|
alphaOf: (v: unknown) => number;
|
|
@@ -108,5 +108,11 @@ export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, d
|
|
|
108
108
|
cause: string;
|
|
109
109
|
} | null;
|
|
110
110
|
}>;
|
|
111
|
-
/**
|
|
112
|
-
|
|
111
|
+
/**
|
|
112
|
+
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
113
|
+
* that is not a section.
|
|
114
|
+
* @param {string | undefined} section
|
|
115
|
+
* @param {string} [theme] the theme the suggestions name
|
|
116
|
+
* @returns {string | undefined}
|
|
117
|
+
*/
|
|
118
|
+
export function checkSection(section: string | undefined, theme?: string): string | undefined;
|
|
@@ -295,12 +295,29 @@ export async function previewAfter(ctx, slug, data, png) {
|
|
|
295
295
|
};
|
|
296
296
|
}
|
|
297
297
|
|
|
298
|
-
/**
|
|
299
|
-
|
|
300
|
-
|
|
298
|
+
/**
|
|
299
|
+
* The section of the sheet, in lower case, or undefined; a refusal for one
|
|
300
|
+
* that is not a section.
|
|
301
|
+
* @param {string | undefined} section
|
|
302
|
+
* @param {string} [theme] the theme the suggestions name
|
|
303
|
+
* @returns {string | undefined}
|
|
304
|
+
*/
|
|
305
|
+
export function checkSection(section, theme = 'my') {
|
|
306
|
+
if (section === '')
|
|
307
|
+
refuse(E.ERR_MISSING_ARGUMENT, '--section was given no value.', {
|
|
308
|
+
run: [`${P} show ${theme} --section ${SHOWCASE_GROUPS[0]}`],
|
|
309
|
+
});
|
|
310
|
+
const s = section?.toLowerCase();
|
|
311
|
+
if (s != null && !SHOWCASE_GROUPS.includes(s))
|
|
301
312
|
refuse(
|
|
302
313
|
E.ERR_INVALID_ARGUMENT,
|
|
303
314
|
`--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}".`,
|
|
304
|
-
{
|
|
315
|
+
{
|
|
316
|
+
didYouMean: nearest(s, SHOWCASE_GROUPS),
|
|
317
|
+
run: [
|
|
318
|
+
`${P} show ${theme} --section ${nearest(s, SHOWCASE_GROUPS)[0] ?? SHOWCASE_GROUPS[0]}`,
|
|
319
|
+
],
|
|
320
|
+
},
|
|
305
321
|
);
|
|
322
|
+
return s;
|
|
306
323
|
}
|
package/api/theme-edit/_edit.mjs
CHANGED
|
@@ -36,7 +36,9 @@ import {
|
|
|
36
36
|
partDefault,
|
|
37
37
|
partsOf,
|
|
38
38
|
q,
|
|
39
|
+
undoArgs,
|
|
39
40
|
withoutBadValues,
|
|
41
|
+
NAME_RULE,
|
|
40
42
|
readHistory,
|
|
41
43
|
refuse,
|
|
42
44
|
settingsProblem,
|
|
@@ -44,10 +46,10 @@ import {
|
|
|
44
46
|
shown,
|
|
45
47
|
slugOk,
|
|
46
48
|
themeFiles,
|
|
47
|
-
buildCurrent,
|
|
48
49
|
buildTheme,
|
|
50
|
+
staleBuild,
|
|
49
51
|
} from './_settings.mjs';
|
|
50
|
-
import {checkSetting} from './_check.mjs';
|
|
52
|
+
import {checkSetting, exampleOf, storedTokenProblem} from './_check.mjs';
|
|
51
53
|
import {MODAL} from './_compiler.mjs';
|
|
52
54
|
import {
|
|
53
55
|
PALETTE_DIALS,
|
|
@@ -99,7 +101,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
99
101
|
.slice(0, 64) || 'my-theme';
|
|
100
102
|
refuse(
|
|
101
103
|
E.ERR_INVALID_ARGUMENT,
|
|
102
|
-
`"${String(name ?? '').slice(0, 80)}" is not a theme name (
|
|
104
|
+
`"${String(name ?? '').slice(0, 80)}" is not a theme name (${NAME_RULE}).`,
|
|
103
105
|
{run: [`${P} new ${fixed}`]},
|
|
104
106
|
);
|
|
105
107
|
}
|
|
@@ -120,7 +122,7 @@ export async function themeEditNew(name, options = {}) {
|
|
|
120
122
|
}
|
|
121
123
|
if (fs.existsSync(f.settings))
|
|
122
124
|
refuse(E.ERR_FILE_EXISTS, `Theme "${name}" already exists.`, {
|
|
123
|
-
run: [`${P} show ${name}`, `${P} set ${name} base
|
|
125
|
+
run: [`${P} show ${name}`, `${P} set ${name} base neutral`],
|
|
124
126
|
});
|
|
125
127
|
if (fs.existsSync(f.dir) && fs.readdirSync(f.dir).length)
|
|
126
128
|
refuse(
|
|
@@ -140,6 +142,10 @@ export async function themeEditNew(name, options = {}) {
|
|
|
140
142
|
const ctx = await context(cwd);
|
|
141
143
|
/** @type {import('./_settings.mjs').ThemeData} */
|
|
142
144
|
const data = {name, ...(like ? {like} : {}), mode: 'both', settings: []};
|
|
145
|
+
/** @type {import('./_settings.mjs').Ctx} */ (ctx).base = await baseResolved(
|
|
146
|
+
ctx.project,
|
|
147
|
+
data.like,
|
|
148
|
+
);
|
|
143
149
|
applyNewSettings(ctx, name, data, settings);
|
|
144
150
|
const r = await commitTheme(ctx, name, data, {history: false});
|
|
145
151
|
const p = await previewAndRoute(ctx, name, data, png);
|
|
@@ -268,8 +274,7 @@ function asNewRefusal(e, slug, settings) {
|
|
|
268
274
|
*/
|
|
269
275
|
async function previewAndRoute(ctx, slug, data, png) {
|
|
270
276
|
const p = await previewAfter(ctx, slug, data, png);
|
|
271
|
-
await keepPreviewRoute(ctx, slug);
|
|
272
|
-
return p;
|
|
277
|
+
return {...p, previewStale: await keepPreviewRoute(ctx, slug)};
|
|
273
278
|
}
|
|
274
279
|
|
|
275
280
|
/**
|
|
@@ -278,12 +283,15 @@ async function previewAndRoute(ctx, slug, data, png) {
|
|
|
278
283
|
* the next `preview add` writes the route again.
|
|
279
284
|
* @param {import('./_settings.mjs').Ctx} ctx
|
|
280
285
|
* @param {string} slug
|
|
286
|
+
* @returns {Promise<string[]>} preview files changed by hand, left showing
|
|
287
|
+
* the theme as it was
|
|
281
288
|
*/
|
|
282
289
|
async function keepPreviewRoute(ctx, slug) {
|
|
283
290
|
try {
|
|
284
|
-
await refreshPreviewRoute(ctx.project.cwd, slug);
|
|
291
|
+
return (await refreshPreviewRoute(ctx.project.cwd, slug)).stale;
|
|
285
292
|
} catch {
|
|
286
293
|
// A damaged or moved preview.
|
|
294
|
+
return [];
|
|
287
295
|
}
|
|
288
296
|
}
|
|
289
297
|
|
|
@@ -300,6 +308,50 @@ export async function themeEditSet(theme, thing, value, options = {}) {
|
|
|
300
308
|
return change('set', theme, thing, value, options);
|
|
301
309
|
}
|
|
302
310
|
|
|
311
|
+
/**
|
|
312
|
+
* Refuse a theme whose saved exact tokens the type rules no longer take,
|
|
313
|
+
* naming the undo that removes the one that fails.
|
|
314
|
+
* @param {import('./_settings.mjs').Ctx} ctx
|
|
315
|
+
* @param {string} slug
|
|
316
|
+
* @param {import('./_settings.mjs').ThemeData} data
|
|
317
|
+
* @param {string} [skip]
|
|
318
|
+
*/
|
|
319
|
+
function refuseStoredTokens(ctx, slug, data, skip) {
|
|
320
|
+
const bad = storedTokenProblem(ctx, slug, data, skip);
|
|
321
|
+
if (bad)
|
|
322
|
+
refuse(
|
|
323
|
+
E.ERR_THEME_INVALID,
|
|
324
|
+
`themes/${slug}/${slug}.settings.json: ${describe(bad.setting)} holds a value the editor no longer accepts (${bad.why}).`,
|
|
325
|
+
{
|
|
326
|
+
run: [
|
|
327
|
+
`${P} undo ${slug} ${undoArgs(bad.setting)}`,
|
|
328
|
+
`${P} set ${slug} ${bad.setting.thing} ${q(exampleOf(ctx.C.typeOf(bad.setting.thing), bad.setting.thing))}`,
|
|
329
|
+
],
|
|
330
|
+
},
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* A note for type scale steps that land outside 9 to 200 pixels.
|
|
336
|
+
* @param {Record<string, string>} res resolved light tokens
|
|
337
|
+
* @returns {string[]}
|
|
338
|
+
*/
|
|
339
|
+
function extremeSteps(res) {
|
|
340
|
+
const out = Object.entries(res)
|
|
341
|
+
.filter(([k]) => /^--font-size-/.test(k))
|
|
342
|
+
.map(([k, v]) => {
|
|
343
|
+
const n = Number.parseFloat(v);
|
|
344
|
+
return /** @type {[string, number]} */ ([k, /rem$/.test(v) ? n * 16 : n]);
|
|
345
|
+
})
|
|
346
|
+
.filter(([, px]) => Number.isFinite(px) && (px < 9 || px > 200))
|
|
347
|
+
.map(([k, px]) => `${k} ${Math.round(px)}px`);
|
|
348
|
+
return out.length
|
|
349
|
+
? [
|
|
350
|
+
`some scale steps are outside reading sizes (9 to 200px): ${out.slice(0, 4).join(', ')}`,
|
|
351
|
+
]
|
|
352
|
+
: [];
|
|
353
|
+
}
|
|
354
|
+
|
|
303
355
|
/**
|
|
304
356
|
* @param {'set' | 'undo'} sub
|
|
305
357
|
* @param {string} slug
|
|
@@ -313,6 +365,7 @@ async function change(sub, slug, thing, value, options) {
|
|
|
313
365
|
requireProject(cwd);
|
|
314
366
|
const data = loadTheme(cwd, slug, thing);
|
|
315
367
|
const ctx = await context(cwd);
|
|
368
|
+
refuseStoredTokens(ctx, slug, data, thing);
|
|
316
369
|
const flags = {
|
|
317
370
|
on: options.on,
|
|
318
371
|
when: options.when,
|
|
@@ -320,8 +373,50 @@ async function change(sub, slug, thing, value, options) {
|
|
|
320
373
|
mode: options.mode,
|
|
321
374
|
only: options.only,
|
|
322
375
|
};
|
|
323
|
-
|
|
324
|
-
|
|
376
|
+
/** @type {{light: Record<string, string>, dark: Record<string, string>}} */
|
|
377
|
+
let base;
|
|
378
|
+
try {
|
|
379
|
+
base = await baseResolved(ctx.project, data.like);
|
|
380
|
+
} catch (e) {
|
|
381
|
+
// A base package that is gone: moving off it still works.
|
|
382
|
+
if (!(sub === 'set' && thing === 'base')) throw e;
|
|
383
|
+
base = await baseResolved(
|
|
384
|
+
ctx.project,
|
|
385
|
+
value === 'none' ? undefined : value,
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
/** @type {import('./_settings.mjs').Ctx} */ (ctx).base = base;
|
|
389
|
+
/** @type {import('./_settings.mjs').Setting} */
|
|
390
|
+
let s;
|
|
391
|
+
try {
|
|
392
|
+
s = checkSetting(ctx, slug, data, thing, value, flags, sub === 'undo');
|
|
393
|
+
} catch (e) {
|
|
394
|
+
// A stored setting this Core no longer knows (a renamed part or
|
|
395
|
+
// property, or a hand edit) can still be removed.
|
|
396
|
+
const stored =
|
|
397
|
+
sub === 'undo'
|
|
398
|
+
? data.settings.find(
|
|
399
|
+
x =>
|
|
400
|
+
x.thing === thing &&
|
|
401
|
+
(x.on ?? null) === (flags.on ?? null) &&
|
|
402
|
+
(x.when ?? null) === (flags.when ?? null) &&
|
|
403
|
+
(x.state ?? null) === (flags.state ?? null) &&
|
|
404
|
+
(x.mode ?? null) === (flags.mode ?? null),
|
|
405
|
+
)
|
|
406
|
+
: null;
|
|
407
|
+
if (!stored) throw e;
|
|
408
|
+
s = stored;
|
|
409
|
+
}
|
|
410
|
+
// undo <thing> <value> removes the setting only when that is its value.
|
|
411
|
+
if (sub === 'undo' && value != null && value !== '') {
|
|
412
|
+
const held = data.settings.find(x => keyOf(x) === keyOf(s));
|
|
413
|
+
if (held && held.value !== value.trim())
|
|
414
|
+
refuse(
|
|
415
|
+
E.ERR_THEME_NOT_SET,
|
|
416
|
+
`The theme sets ${describe(held)}, not ${value}.`,
|
|
417
|
+
{run: [`${P} undo ${slug} ${undoArgs(held)}`]},
|
|
418
|
+
);
|
|
419
|
+
}
|
|
325
420
|
const compiledBefore = compileTheme(ctx, data, base);
|
|
326
421
|
if (sub === 'set' && (s.thing === 'base' || s.thing === 'mode')) {
|
|
327
422
|
const before = s.thing === 'base' ? (data.like ?? 'none') : data.mode;
|
|
@@ -332,6 +427,7 @@ async function change(sub, slug, thing, value, options) {
|
|
|
332
427
|
data.mode = /** @type {'both' | 'light-only' | 'dark-only'} */ (s.value);
|
|
333
428
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
334
429
|
const p = await previewAndRoute(ctx, slug, data, png);
|
|
430
|
+
const after = await baseResolved(ctx.project, data.like).catch(() => base);
|
|
335
431
|
return {
|
|
336
432
|
type: 'themeEdit.set',
|
|
337
433
|
data: {
|
|
@@ -343,7 +439,7 @@ async function change(sub, slug, thing, value, options) {
|
|
|
343
439
|
parts: [],
|
|
344
440
|
group: null,
|
|
345
441
|
changedTokens: r.changed,
|
|
346
|
-
styled:
|
|
442
|
+
styled: styledChanges(compiledBefore, compileTheme(ctx, data, after)),
|
|
347
443
|
kept: [],
|
|
348
444
|
lifted: r.lifted,
|
|
349
445
|
notes: [
|
|
@@ -353,6 +449,24 @@ async function change(sub, slug, thing, value, options) {
|
|
|
353
449
|
...r.notes,
|
|
354
450
|
`your ${data.settings.length} settings are kept`,
|
|
355
451
|
...otherModeNotes(data),
|
|
452
|
+
// The colors are made again for the new base or mode: their
|
|
453
|
+
// shade notes follow.
|
|
454
|
+
...data.settings
|
|
455
|
+
.filter(x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing))
|
|
456
|
+
.flatMap(x =>
|
|
457
|
+
paletteNotes(
|
|
458
|
+
paletteMapping(
|
|
459
|
+
cwd,
|
|
460
|
+
slug,
|
|
461
|
+
data,
|
|
462
|
+
after,
|
|
463
|
+
ctx.project.core.tokenDefaults,
|
|
464
|
+
),
|
|
465
|
+
x.thing,
|
|
466
|
+
slug,
|
|
467
|
+
modesOf(data),
|
|
468
|
+
).slice(0, -1),
|
|
469
|
+
),
|
|
356
470
|
],
|
|
357
471
|
problems: r.problems,
|
|
358
472
|
warnings: r.warnings,
|
|
@@ -362,6 +476,8 @@ async function change(sub, slug, thing, value, options) {
|
|
|
362
476
|
}
|
|
363
477
|
const k = keyOf(s);
|
|
364
478
|
const prevIdx = data.settings.findIndex(x => keyOf(x) === k);
|
|
479
|
+
/** @type {string | null} */
|
|
480
|
+
let vibrancyGone = null;
|
|
365
481
|
const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
|
|
366
482
|
if (sub === 'undo') {
|
|
367
483
|
if (!prev) {
|
|
@@ -373,13 +489,63 @@ async function change(sub, slug, thing, value, options) {
|
|
|
373
489
|
also: near.length
|
|
374
490
|
? [`settings for ${s.thing}: ${near.join('; ')}`]
|
|
375
491
|
: [],
|
|
376
|
-
run: [
|
|
492
|
+
run: [
|
|
493
|
+
...data.settings
|
|
494
|
+
.filter(x => x.thing === s.thing)
|
|
495
|
+
.slice(0, 3)
|
|
496
|
+
.map(x => `${P} undo ${slug} ${undoArgs(x)}`),
|
|
497
|
+
`${P} show ${slug}`,
|
|
498
|
+
],
|
|
377
499
|
},
|
|
378
500
|
);
|
|
379
501
|
}
|
|
380
502
|
data.settings.splice(prevIdx, 1);
|
|
381
|
-
|
|
382
|
-
|
|
503
|
+
// Vibrancy needs a color: undoing the last one takes it along, so the
|
|
504
|
+
// theme never holds a state `set` refuses.
|
|
505
|
+
if (
|
|
506
|
+
PALETTE_DIALS.includes(s.thing) &&
|
|
507
|
+
!data.settings.some(
|
|
508
|
+
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
509
|
+
)
|
|
510
|
+
) {
|
|
511
|
+
const v = data.settings.findIndex(
|
|
512
|
+
x => x.source === 'dial' && x.thing === 'vibrancy',
|
|
513
|
+
);
|
|
514
|
+
if (v >= 0)
|
|
515
|
+
vibrancyGone = /** @type {string} */ (
|
|
516
|
+
data.settings.splice(v, 1)[0]?.value
|
|
517
|
+
);
|
|
518
|
+
}
|
|
519
|
+
} else if (prev && JSON.stringify(prev) === JSON.stringify(s)) {
|
|
520
|
+
// The same setting again: nothing moves.
|
|
521
|
+
} else {
|
|
522
|
+
// A changed setting goes last, so it wins over what came before it.
|
|
523
|
+
if (prev) data.settings.splice(prevIdx, 1);
|
|
524
|
+
data.settings.push(s);
|
|
525
|
+
}
|
|
526
|
+
// A setting for both modes replaces the ones made for one mode, which it
|
|
527
|
+
// would otherwise sit under.
|
|
528
|
+
/** @type {import('./_settings.mjs').Setting[]} */
|
|
529
|
+
const covered =
|
|
530
|
+
sub === 'set' && !s.mode && s.source !== 'dial'
|
|
531
|
+
? data.settings.filter(
|
|
532
|
+
x => x !== s && x.mode && keyOf({...x, mode: undefined}) === k,
|
|
533
|
+
)
|
|
534
|
+
: [];
|
|
535
|
+
data.settings = data.settings.filter(x => !covered.includes(x));
|
|
536
|
+
// A shorthand set after its longhands on the same part replaces them.
|
|
537
|
+
const longhands =
|
|
538
|
+
sub === 'set' && s.source === 'property'
|
|
539
|
+
? data.settings.filter(
|
|
540
|
+
x =>
|
|
541
|
+
x !== s &&
|
|
542
|
+
x.source === 'property' &&
|
|
543
|
+
x.on === s.on &&
|
|
544
|
+
x.when === s.when &&
|
|
545
|
+
x.state === s.state &&
|
|
546
|
+
x.thing.startsWith(`${s.thing}-`),
|
|
547
|
+
)
|
|
548
|
+
: [];
|
|
383
549
|
const r = await commitTheme(ctx, slug, data, {history: true});
|
|
384
550
|
const styled = styledChanges(compiledBefore, compileTheme(ctx, data, base));
|
|
385
551
|
const parts = partsOf(ctx, s);
|
|
@@ -389,6 +555,36 @@ async function change(sub, slug, thing, value, options) {
|
|
|
389
555
|
: [];
|
|
390
556
|
/** @type {string[]} */
|
|
391
557
|
const notes = [
|
|
558
|
+
...(covered.length ? [`replaces ${covered.map(describe).join(', ')}`] : []),
|
|
559
|
+
// Phones keep the base theme's reading sizes (a coarse pointer below
|
|
560
|
+
// the lg width), so a size change says where it applies.
|
|
561
|
+
...(sub === 'set' &&
|
|
562
|
+
!s.on &&
|
|
563
|
+
(['text-size', 'type'].includes(s.thing) ||
|
|
564
|
+
/^--(font-size-|text-[a-z0-9-]+-(size|leading)$)/.test(s.thing))
|
|
565
|
+
? [
|
|
566
|
+
'phones (touch screens below 1024px wide) keep the base theme reading sizes; this applies on wider or mouse screens',
|
|
567
|
+
]
|
|
568
|
+
: []),
|
|
569
|
+
// A scale step far outside reading sizes is named.
|
|
570
|
+
...(sub === 'set' && ['text-size', 'type'].includes(s.thing)
|
|
571
|
+
? extremeSteps(r.res.light)
|
|
572
|
+
: []),
|
|
573
|
+
// An accepted change that the theme already showed says so.
|
|
574
|
+
...(sub === 'set' &&
|
|
575
|
+
!r.unchanged &&
|
|
576
|
+
!r.changed.length &&
|
|
577
|
+
!styled.length &&
|
|
578
|
+
!ctx.unchecked
|
|
579
|
+
? [
|
|
580
|
+
`this changes nothing you see: the theme already shows ${describe(s)} (it is saved, and stays when the base theme changes)`,
|
|
581
|
+
]
|
|
582
|
+
: []),
|
|
583
|
+
...(longhands.length
|
|
584
|
+
? [
|
|
585
|
+
`${s.thing} comes after ${longhands.map(x => x.thing).join(', ')} on ${s.on}, so it replaces them there`,
|
|
586
|
+
]
|
|
587
|
+
: []),
|
|
392
588
|
...(r.unchanged
|
|
393
589
|
? [
|
|
394
590
|
`no change: ${describe(s)} is already set, so nothing was built and no undo step was added`,
|
|
@@ -416,6 +612,11 @@ async function change(sub, slug, thing, value, options) {
|
|
|
416
612
|
if (PALETTE_DIALS.includes(s.thing) && sub === 'undo')
|
|
417
613
|
notes.push(
|
|
418
614
|
`the ${s.thing} color is no longer generated, and the tokens it fed go back to the base theme's values`,
|
|
615
|
+
...(vibrancyGone != null
|
|
616
|
+
? [
|
|
617
|
+
`vibrancy ${vibrancyGone} is removed too: it sets how saturated the colors are, and the theme sets no color now`,
|
|
618
|
+
]
|
|
619
|
+
: []),
|
|
419
620
|
);
|
|
420
621
|
if (s.thing === 'neutral' && sub === 'set') {
|
|
421
622
|
// Only the theme's own modes; a dark theme gets no white-page offer.
|
|
@@ -464,7 +665,11 @@ async function change(sub, slug, thing, value, options) {
|
|
|
464
665
|
? {removed: prev, now: nowApplies(ctx, data, prev, base)}
|
|
465
666
|
: {}),
|
|
466
667
|
replaced: sub === 'set' ? prev : null,
|
|
467
|
-
|
|
668
|
+
// A whole-theme dial names the value it replaced, as base and mode do.
|
|
669
|
+
was:
|
|
670
|
+
sub === 'set' && prev && prev.source === 'dial' && !prev.on
|
|
671
|
+
? prev.value
|
|
672
|
+
: null,
|
|
468
673
|
notes,
|
|
469
674
|
parts,
|
|
470
675
|
group: group
|
|
@@ -522,15 +727,16 @@ function unsetColorNotes(data, base, slug) {
|
|
|
522
727
|
* @returns {Promise<import('./theme-edit.type.mjs').ThemeEditShowResponse>}
|
|
523
728
|
*/
|
|
524
729
|
export async function themeEditShow(theme, options = {}) {
|
|
525
|
-
const {cwd = process.cwd(), png = false
|
|
730
|
+
const {cwd = process.cwd(), png = false} = options;
|
|
526
731
|
requireProject(cwd);
|
|
527
|
-
checkSection(section);
|
|
732
|
+
const section = checkSection(options.section, theme);
|
|
528
733
|
const data = loadTheme(cwd, theme);
|
|
529
734
|
const ctx = await context(cwd);
|
|
735
|
+
refuseStoredTokens(ctx, theme, data);
|
|
530
736
|
const f = themeFiles(cwd, theme);
|
|
531
737
|
// A build that does not match the settings (a command stopped mid-build,
|
|
532
738
|
// a hand edit, another CLI) is made again from the settings, and said.
|
|
533
|
-
const stale =
|
|
739
|
+
const stale = staleBuild(cwd, theme, data);
|
|
534
740
|
if (stale) await buildTheme(ctx, theme, data);
|
|
535
741
|
const res = await resolvedTokens(ctx, theme);
|
|
536
742
|
const problems = await contrastProblems(ctx, data, res);
|
|
@@ -542,7 +748,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
542
748
|
ctx.project.core.tokenDefaults,
|
|
543
749
|
);
|
|
544
750
|
const preview = await renderPreview(ctx, theme, data);
|
|
545
|
-
await keepPreviewRoute(ctx, theme);
|
|
751
|
+
const previewStale = await keepPreviewRoute(ctx, theme);
|
|
546
752
|
const sheet = await renderSheet(ctx, theme, data, {group: section});
|
|
547
753
|
const modes = modesOf(data);
|
|
548
754
|
const shots = png
|
|
@@ -568,7 +774,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
568
774
|
notes: [
|
|
569
775
|
...(stale
|
|
570
776
|
? [
|
|
571
|
-
`the build did not match ${theme}.settings.json (
|
|
777
|
+
`the build did not match ${theme}.settings.json (${stale}), so it was built again from the settings`,
|
|
572
778
|
]
|
|
573
779
|
: []),
|
|
574
780
|
...fontNotes(ctx, data),
|
|
@@ -586,6 +792,7 @@ export async function themeEditShow(theme, options = {}) {
|
|
|
586
792
|
...colorsReport(pal, data),
|
|
587
793
|
problems,
|
|
588
794
|
preview,
|
|
795
|
+
previewStale,
|
|
589
796
|
sheet: sheet.file,
|
|
590
797
|
sheetComponents: sheet.components,
|
|
591
798
|
skipped: sheet.skipped,
|
|
@@ -729,20 +936,19 @@ function partValues(ctx, data, res, mode) {
|
|
|
729
936
|
*/
|
|
730
937
|
function colorsReport(pal, data) {
|
|
731
938
|
if (!pal) return {vibrancy: null, colors: [], colorNotes: []};
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
939
|
+
/** What the user set for each token exactly, in each mode. */
|
|
940
|
+
const exactBy =
|
|
941
|
+
/** @type {Record<string, {light?: string, dark?: string}>} */ ({});
|
|
942
|
+
for (const s of data.settings)
|
|
943
|
+
if (s.source === 'token' && !s.on && !s.when && !s.state)
|
|
944
|
+
for (const m of s.mode ? [s.mode] : ['light', 'dark'])
|
|
945
|
+
(exactBy[s.thing] ??= {})[/** @type {'light' | 'dark'} */ (m)] =
|
|
946
|
+
s.value;
|
|
735
947
|
/** @param {import('./_palette.mjs').StopRef} r */
|
|
736
948
|
const shade = r =>
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
for (const s of data.settings)
|
|
741
|
-
if (s.source === 'token' && !s.on)
|
|
742
|
-
exactValue[s.thing] = [
|
|
743
|
-
...(exactValue[s.thing] ? [exactValue[s.thing]] : []),
|
|
744
|
-
s.mode ? `${s.mode} ${s.value}` : s.value,
|
|
745
|
-
].join(', ');
|
|
949
|
+
r.family === 'black' || r.family === 'white'
|
|
950
|
+
? `${r.family} ${r.color}`
|
|
951
|
+
: `${r.family ? `${r.family} ` : ''}${r.stop}${r.alpha ? ` at opacity ${r.alpha}` : ''} ${r.color}${r.exact ? ' (your exact color)' : ''}`;
|
|
746
952
|
// A theme with one mode lists only that mode's shades.
|
|
747
953
|
const modes = modesOf(data);
|
|
748
954
|
/** @param {{light: import('./_palette.mjs').StopRef, dark: import('./_palette.mjs').StopRef}} v */
|
|
@@ -757,22 +963,33 @@ function colorsReport(pal, data) {
|
|
|
757
963
|
.filter(([, v]) => v.family === fam.id)
|
|
758
964
|
.map(([k, v]) => [
|
|
759
965
|
k,
|
|
760
|
-
exact
|
|
761
|
-
|
|
966
|
+
// Each mode says what it shows: the exact setting where one is
|
|
967
|
+
// made for it, else the generated shade.
|
|
968
|
+
exactBy[k]
|
|
969
|
+
? modes
|
|
970
|
+
.map(m =>
|
|
971
|
+
exactBy[k][m] != null
|
|
972
|
+
? `${m} ${exactBy[k][m]} (your exact setting wins over the generated ${shade(v[m])})`
|
|
973
|
+
: `${m} ${shade(v[m])}`,
|
|
974
|
+
)
|
|
975
|
+
.join(', ')
|
|
762
976
|
: shades(v),
|
|
763
977
|
]),
|
|
764
978
|
),
|
|
765
979
|
})),
|
|
766
|
-
colorNotes:
|
|
767
|
-
.
|
|
768
|
-
.
|
|
769
|
-
|
|
770
|
-
c.
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
?
|
|
774
|
-
:
|
|
775
|
-
|
|
980
|
+
colorNotes: [
|
|
981
|
+
...pal.notes,
|
|
982
|
+
...pal.contrast
|
|
983
|
+
.filter(c => modes.includes(c.mode))
|
|
984
|
+
.filter(c => c.note || !c.pass || c.stop !== c.preferred)
|
|
985
|
+
.map(c =>
|
|
986
|
+
c.note
|
|
987
|
+
? c.note
|
|
988
|
+
: c.pass
|
|
989
|
+
? `${c.token} ${c.mode}: shade ${c.stop}, not ${c.preferred}, so it reads at ${c.ratio}:1 on ${c.against}`
|
|
990
|
+
: `${c.token} ${c.mode}: only ${c.ratio}:1 on ${c.against} at shade ${c.stop} (needs ${c.needs}:1)`,
|
|
991
|
+
),
|
|
992
|
+
],
|
|
776
993
|
};
|
|
777
994
|
}
|
|
778
995
|
|
|
@@ -796,9 +1013,49 @@ function colorFiles(slug) {
|
|
|
796
1013
|
*/
|
|
797
1014
|
export async function themeEditUndo(theme, options = {}) {
|
|
798
1015
|
const {cwd = process.cwd(), png = false, thing} = options;
|
|
1016
|
+
// base and mode are not settings in the list: undoing one sets it back to
|
|
1017
|
+
// its default.
|
|
1018
|
+
if (thing === 'base' || thing === 'mode')
|
|
1019
|
+
return change(
|
|
1020
|
+
'set',
|
|
1021
|
+
theme,
|
|
1022
|
+
thing,
|
|
1023
|
+
thing === 'base' ? 'none' : 'both',
|
|
1024
|
+
options,
|
|
1025
|
+
);
|
|
799
1026
|
if (thing != null)
|
|
800
1027
|
return change('undo', theme, thing, options.value, options);
|
|
801
1028
|
requireProject(cwd);
|
|
1029
|
+
// A scope flag without a thing would undo some other change.
|
|
1030
|
+
const scoped = /** @type {const} */ (['on', 'when', 'state', 'mode']).find(
|
|
1031
|
+
k => options[k] != null,
|
|
1032
|
+
);
|
|
1033
|
+
if (scoped || options.only)
|
|
1034
|
+
refuse(
|
|
1035
|
+
E.ERR_MISSING_ARGUMENT,
|
|
1036
|
+
`--${scoped ?? 'only'} names where one setting applies; name the setting too, or drop it to step back one change.`,
|
|
1037
|
+
{
|
|
1038
|
+
run: [
|
|
1039
|
+
// The saved settings in that scope, as commands that remove them.
|
|
1040
|
+
...(() => {
|
|
1041
|
+
try {
|
|
1042
|
+
return loadTheme(cwd, theme)
|
|
1043
|
+
.settings.filter(x =>
|
|
1044
|
+
scoped
|
|
1045
|
+
? String(/** @type {any} */ (x)[scoped] ?? '') ===
|
|
1046
|
+
String(options[scoped])
|
|
1047
|
+
: x.only,
|
|
1048
|
+
)
|
|
1049
|
+
.slice(0, 3)
|
|
1050
|
+
.map(x => `${P} undo ${theme} ${undoArgs(x)}`);
|
|
1051
|
+
} catch {
|
|
1052
|
+
return [];
|
|
1053
|
+
}
|
|
1054
|
+
})(),
|
|
1055
|
+
`${P} undo ${theme}`,
|
|
1056
|
+
],
|
|
1057
|
+
},
|
|
1058
|
+
);
|
|
802
1059
|
// A damaged settings file is what undo recovers from: the last history
|
|
803
1060
|
// entry replaces it without the current file being read.
|
|
804
1061
|
/** @type {import('./_settings.mjs').ThemeData | null} */
|