@astryxdesign/cli 0.7.14-canary.g05da5aa → 0.7.14-canary.gdcc8823
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/theme-edit/_check.mjs +193 -26
- package/api/theme-edit/_context.d.mts +14 -4
- package/api/theme-edit/_context.mjs +107 -18
- package/api/theme-edit/_edit.d.mts +3 -1
- package/api/theme-edit/_edit.mjs +112 -40
- package/api/theme-edit/_how.d.mts +17 -6
- package/api/theme-edit/_how.mjs +222 -48
- package/api/theme-edit/_overview.d.mts +9 -0
- package/api/theme-edit/_overview.mjs +295 -0
- package/api/theme-edit/_palette.d.mts +14 -4
- package/api/theme-edit/_palette.mjs +117 -46
- package/api/theme-edit/_preview-app.d.mts +8 -6
- package/api/theme-edit/_preview-app.mjs +271 -45
- package/api/theme-edit/_preview.d.mts +32 -5
- package/api/theme-edit/_preview.mjs +292 -23
- package/api/theme-edit/_settings.d.mts +11 -3
- package/api/theme-edit/_settings.mjs +82 -10
- package/api/theme-edit/_tables.d.mts +5 -5
- package/api/theme-edit/_tables.mjs +31 -24
- package/api/theme-edit/theme-edit.type.d.mts +61 -48
- package/api/theme-edit/theme-edit.type.mjs +29 -25
- package/api/theme-edit/themeEditHow.doc.mjs +6 -5
- package/api/theme-edit/themeEditNew.doc.mjs +13 -3
- package/api/theme-edit/themeEditPreviewAdd.doc.mjs +1 -1
- package/api/theme-edit/themeEditSet.doc.mjs +6 -6
- package/api/theme-edit/themeEditShow.doc.mjs +4 -4
- package/api/theme-edit/themeEditUndo.doc.mjs +2 -2
- package/assets/docs/tree/icon-sets.doc.mjs +3 -3
- package/assets/icons/definitions/bookmarkAdd.doc.mjs +9 -0
- package/assets/icons/definitions/documentSearch.doc.mjs +9 -0
- package/assets/icons/definitions/keyboard.doc.mjs +9 -0
- package/assets/icons/definitions/paintBrush.doc.mjs +9 -0
- package/assets/icons/definitions/wallet.doc.mjs +9 -0
- package/assets/templates/blocks/components/ButtonGroup/ButtonGroupShowcase.doc.mjs +1 -1
- package/assets/templates/blocks/components/Lightbox/LightboxGallery.tsx +1 -1
- package/assets/templates/pages/gallery-hero/page.tsx +8 -2
- package/assets/templates/pages/settings-dialog/template.doc.mjs +3 -3
- package/assets/templates/pages/side-gallery/page.tsx +1 -1
- package/assets/templates/pages/table-filter/template.doc.mjs +2 -2
- package/assets/templates/pages/theme-showcase/page.tsx +11 -3
- package/assets/templates/pages/theme-showcase/template.doc.mjs +1 -1
- package/clients/cli/commands/experimental/theme.mjs +124 -27
- package/clients/cli/commands/experimental-theme-editor-how.doc.mjs +10 -6
- package/clients/cli/commands/experimental-theme-editor-new.doc.mjs +103 -3
- package/clients/cli/commands/experimental-theme-editor-set.doc.mjs +12 -7
- package/clients/cli/commands/experimental-theme-editor-show.doc.mjs +5 -5
- package/clients/cli/commands/experimental-theme-editor-undo.doc.mjs +3 -3
- package/clients/cli/commands/experimental-theme-editor.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme-preview-add.doc.mjs +1 -1
- package/clients/cli/commands/experimental-theme.doc.mjs +1 -2
- package/clients/cli/commands/theme.mjs +41 -6
- package/clients/cli/index.mjs +0 -1
- package/foundation/discovery/template-adapter.mjs +5 -3
- package/foundation/discovery/template-icons.d.mts +13 -0
- package/foundation/discovery/template-icons.mjs +76 -0
- package/foundation/fs/import-url.d.mts +5 -4
- package/foundation/fs/import-url.mjs +5 -4
- package/foundation/fs/module-loader.mjs +6 -3
- package/foundation/response/error-codes.d.mts +2 -1
- package/foundation/response/error-codes.doc.mjs +6 -0
- package/foundation/response/error-codes.mjs +5 -0
- package/foundation/response/response-types.doc.mjs +4 -4
- package/package.json +6 -7
- package/clients/cli/commands/experimental-theme-palette-generate.doc.mjs +0 -73
- package/clients/cli/commands/experimental-theme-palette.doc.mjs +0 -37
|
@@ -36,7 +36,13 @@ import {
|
|
|
36
36
|
} from './_tables.mjs';
|
|
37
37
|
import {isColorValue, isNumber, isSize} from './_color.mjs';
|
|
38
38
|
import {MODAL} from './_compiler.mjs';
|
|
39
|
-
import {
|
|
39
|
+
import {
|
|
40
|
+
PALETTE_DIALS,
|
|
41
|
+
PALETTE_TOKENS,
|
|
42
|
+
VIBRANCY_DEFAULT,
|
|
43
|
+
paletteToken,
|
|
44
|
+
seedOf,
|
|
45
|
+
} from './_palette.mjs';
|
|
40
46
|
import {
|
|
41
47
|
camel,
|
|
42
48
|
kebab,
|
|
@@ -145,13 +151,13 @@ export function checkSetting(
|
|
|
145
151
|
if (!fam || FAMILIES[/** @type {string} */ (s.on)])
|
|
146
152
|
refuse(
|
|
147
153
|
E.ERR_INVALID_ARGUMENT,
|
|
148
|
-
'--only is for one member of a
|
|
149
|
-
{run: [`${HOW} --list
|
|
154
|
+
'--only is for one member of a group, such as text-input (how --list groups).',
|
|
155
|
+
{run: [`${HOW} --list groups`]},
|
|
150
156
|
);
|
|
151
157
|
if (!AUTO_SPREAD.includes(/** @type {string} */ (fam)))
|
|
152
158
|
refuse(
|
|
153
159
|
E.ERR_INVALID_ARGUMENT,
|
|
154
|
-
`${s.on} is styled on its own already: only ${AUTO_SPREAD.join(' and ')} spread to their
|
|
160
|
+
`${s.on} is styled on its own already: only ${AUTO_SPREAD.join(' and ')} spread to their group, so drop --only.`,
|
|
155
161
|
{
|
|
156
162
|
run: [
|
|
157
163
|
unset
|
|
@@ -296,7 +302,7 @@ export function checkSetting(
|
|
|
296
302
|
const token = paletteToken(thing);
|
|
297
303
|
refuse(
|
|
298
304
|
E.ERR_THEME_BAD_VALUE,
|
|
299
|
-
`${thing}
|
|
305
|
+
`${thing} generates the colors of the whole theme, light and dark from one color; drop ${s.on ? '--on' : '--mode'}. For an exact color on one part or in one mode, set the token itself.`,
|
|
300
306
|
{
|
|
301
307
|
run: [
|
|
302
308
|
`${P} set ${slug} ${token} ${q(v || '#7c3aed')}${onFlag}${s.mode ? ` --mode ${s.mode}` : ''}`,
|
|
@@ -362,11 +368,43 @@ export function checkSetting(
|
|
|
362
368
|
if (!seedOf(v))
|
|
363
369
|
refuse(
|
|
364
370
|
E.ERR_THEME_BAD_VALUE,
|
|
365
|
-
`"${v}" has no fixed color, so
|
|
371
|
+
`"${v}" has no fixed color, so no shades can be generated from it.`,
|
|
366
372
|
{
|
|
367
373
|
fix: 'give a hex, a color name, or an rgb(), hsl(), hwb(), lab(), lch(), oklab() or oklch() color',
|
|
368
374
|
},
|
|
369
375
|
);
|
|
376
|
+
} else if (thing === 'vibrancy') {
|
|
377
|
+
if (s.on)
|
|
378
|
+
refuse(
|
|
379
|
+
E.ERR_THEME_BAD_VALUE,
|
|
380
|
+
'vibrancy applies to every generated color of the theme; drop --on.',
|
|
381
|
+
{run: [`${P} set ${slug} vibrancy ${q(v)}`]},
|
|
382
|
+
);
|
|
383
|
+
if (step) {
|
|
384
|
+
const cur = Number(
|
|
385
|
+
[...data.settings].reverse().find(x => x.thing === 'vibrancy')
|
|
386
|
+
?.value ?? VIBRANCY_DEFAULT,
|
|
387
|
+
);
|
|
388
|
+
s.value = String(
|
|
389
|
+
Math.max(0, Math.min(100, cur + (v === 'more' ? 10 : -10))),
|
|
390
|
+
);
|
|
391
|
+
} else if (!/^\d{1,3}$/.test(v) || Number(v) > 100)
|
|
392
|
+
refuse(
|
|
393
|
+
E.ERR_THEME_BAD_VALUE,
|
|
394
|
+
`vibrancy takes a whole number from 0 (gray) to 100 (most vivid), or more or less, not "${v}".`,
|
|
395
|
+
{run: [`${P} set ${slug} vibrancy 60`]},
|
|
396
|
+
);
|
|
397
|
+
else s.value = String(Number(v));
|
|
398
|
+
if (
|
|
399
|
+
!data.settings.some(
|
|
400
|
+
x => x.source === 'dial' && PALETTE_DIALS.includes(x.thing),
|
|
401
|
+
)
|
|
402
|
+
)
|
|
403
|
+
refuse(
|
|
404
|
+
E.ERR_THEME_NO_EFFECT,
|
|
405
|
+
'vibrancy sets how saturated the generated colors are, and this theme sets no color yet. Set one first.',
|
|
406
|
+
{run: [`${P} set ${slug} accent "#7c3aed"`]},
|
|
407
|
+
);
|
|
370
408
|
} else if (thing === 'font') {
|
|
371
409
|
if (s.on && !isRole)
|
|
372
410
|
refuse(
|
|
@@ -439,6 +477,8 @@ export function checkSetting(
|
|
|
439
477
|
`"more"/"less" work only on dials (${Object.keys(DIALS).join(', ')}). Give ${thing} a ${type} value.`,
|
|
440
478
|
);
|
|
441
479
|
checkTypedValue(type, v, thing);
|
|
480
|
+
// With no part data, what reads the token is unknown: save, unchecked.
|
|
481
|
+
if (ctx.unchecked) return s;
|
|
442
482
|
const parts = partsOf(ctx, s);
|
|
443
483
|
if (parts.length) {
|
|
444
484
|
const results = parts.map(
|
|
@@ -453,8 +493,8 @@ export function checkSetting(
|
|
|
453
493
|
const spread = Boolean(
|
|
454
494
|
FAMILIES[s.on ?? ''] || (familyOf(s.on ?? '') && parts.length > 1),
|
|
455
495
|
);
|
|
456
|
-
// A part with no record is judged by its
|
|
457
|
-
// member that has a record reads the token, as the
|
|
496
|
+
// A part with no record is judged by its group: refused when no
|
|
497
|
+
// member that has a record reads the token, as the group form is.
|
|
458
498
|
const fam = s.on ? familyOf(s.on) : null;
|
|
459
499
|
if (!recorded.length && fam && !spread) {
|
|
460
500
|
const siblings = FAMILIES[fam].filter(t => C.MAP[t]);
|
|
@@ -471,7 +511,7 @@ export function checkSetting(
|
|
|
471
511
|
);
|
|
472
512
|
refuse(
|
|
473
513
|
E.ERR_THEME_NO_EFFECT,
|
|
474
|
-
`No part of the ${fam}
|
|
514
|
+
`No part of the ${fam} group reads ${thing}, so ${s.on} cannot either. ${r.message}`,
|
|
475
515
|
{
|
|
476
516
|
run: r.run.map(x =>
|
|
477
517
|
x.replace(`--on ${famResults[0][0]}`, `--on ${s.on}`),
|
|
@@ -481,7 +521,7 @@ export function checkSetting(
|
|
|
481
521
|
);
|
|
482
522
|
}
|
|
483
523
|
if (famResults.length)
|
|
484
|
-
s.note = `${s.on} has no compiled record; checked against the ${fam}
|
|
524
|
+
s.note = `${s.on} has no compiled record; checked against the ${fam} group, where ${famResults
|
|
485
525
|
.filter(([, r]) => !r)
|
|
486
526
|
.map(([t]) => t)
|
|
487
527
|
.join(', ')} read ${thing}`;
|
|
@@ -509,7 +549,11 @@ export function checkSetting(
|
|
|
509
549
|
).message;
|
|
510
550
|
} else {
|
|
511
551
|
const r = C.checkTokenGlobal(thing, P);
|
|
512
|
-
|
|
552
|
+
// A token a dial writes is always accepted, so a dial's notes never
|
|
553
|
+
// name a token `set` refuses.
|
|
554
|
+
if (r && dialWrites(thing))
|
|
555
|
+
s.note = `no part reads ${thing} directly in this Core; a dial writes it too, so it is set as asked`;
|
|
556
|
+
else if (r)
|
|
513
557
|
refuse(E.ERR_THEME_NO_EFFECT, r.message, {run: r.run, also: r.also});
|
|
514
558
|
}
|
|
515
559
|
return s;
|
|
@@ -519,7 +563,7 @@ export function checkSetting(
|
|
|
519
563
|
if (!s.on)
|
|
520
564
|
refuse(
|
|
521
565
|
E.ERR_MISSING_ARGUMENT,
|
|
522
|
-
`${prop} is a CSS property, so it needs --on <part|
|
|
566
|
+
`${prop} is a CSS property, so it needs --on <part|group>. For the whole theme use a dial or a token.`,
|
|
523
567
|
{
|
|
524
568
|
run: [
|
|
525
569
|
`${P} set ${slug} ${prop} ${q(v || '<value>')} --on <part>`,
|
|
@@ -607,6 +651,7 @@ export function checkSetting(
|
|
|
607
651
|
* @param {import('./_settings.mjs').Setting} s
|
|
608
652
|
*/
|
|
609
653
|
function refuseInvisibleCorners(ctx, slug, s) {
|
|
654
|
+
if (ctx.unchecked) return;
|
|
610
655
|
const parts = partsOf(ctx, s);
|
|
611
656
|
if (!parts.length || parts.some(t => ctx.C.showsCorners(t))) return;
|
|
612
657
|
const kids = (ctx.C.MAP[parts[0]]?.contains ?? [])
|
|
@@ -625,6 +670,18 @@ function refuseInvisibleCorners(ctx, slug, s) {
|
|
|
625
670
|
);
|
|
626
671
|
}
|
|
627
672
|
|
|
673
|
+
/**
|
|
674
|
+
* Whether a dial writes the token: a color, a heading weight (type,
|
|
675
|
+
* headings), a radius (corners), a spacing or control size (spacing), or a
|
|
676
|
+
* font size (type, text-size).
|
|
677
|
+
* @param {string} token
|
|
678
|
+
*/
|
|
679
|
+
const dialWrites = token =>
|
|
680
|
+
PALETTE_TOKENS.has(token) ||
|
|
681
|
+
/^--(text-(heading|display)-\d-weight|radius-|spacing-|size-element-|font-size-)/.test(
|
|
682
|
+
token,
|
|
683
|
+
);
|
|
684
|
+
|
|
628
685
|
/**
|
|
629
686
|
* Answer a plain-words question with exact commands: the parts it names,
|
|
630
687
|
* the aspects it asks about, and what each part really reads for them.
|
|
@@ -637,22 +694,38 @@ export function answerHow(ctx, question) {
|
|
|
637
694
|
const TARGET = ctx.project.target;
|
|
638
695
|
const TOKENS = ctx.project.core.tokenDefaults;
|
|
639
696
|
const text = question.toLowerCase();
|
|
697
|
+
/** @type {Array<string | null>} */
|
|
698
|
+
let intents = INTENTS.filter(([, re]) => re.test(text)).map(([g]) => g);
|
|
699
|
+
// "pill" is a corner shape when the question is about corners.
|
|
700
|
+
const partText = intents.includes('corners')
|
|
701
|
+
? text.replace(/\bpills?\b/g, '')
|
|
702
|
+
: text;
|
|
640
703
|
/** @type {string[]} */
|
|
641
|
-
|
|
704
|
+
let parts = [];
|
|
642
705
|
for (const [re, ts] of PART_WORDS)
|
|
643
|
-
if (re.test(
|
|
706
|
+
if (re.test(partText))
|
|
644
707
|
for (const t of ts) if (!parts.includes(t)) parts.push(t);
|
|
645
|
-
|
|
646
|
-
|
|
708
|
+
// A variant of a part ("secondary button") answers for the part.
|
|
709
|
+
parts = parts.filter(p => !parts.some(x => x.startsWith(`${p}:`)));
|
|
710
|
+
const whiteText =
|
|
711
|
+
/\bwhite (text|labels?|writing|words)\b|\b(text|labels?|writing|words) (in |is |are )?white\b/.test(
|
|
712
|
+
text,
|
|
713
|
+
);
|
|
647
714
|
if (
|
|
648
715
|
intents.includes('text') &&
|
|
649
716
|
intents.includes('background') &&
|
|
650
|
-
!/background|fill|gradient|glossy/.test(text)
|
|
717
|
+
!/background|fill|gradient|glossy/.test(text) &&
|
|
718
|
+
!(/\bwhite\b/.test(text) && !whiteText)
|
|
651
719
|
)
|
|
652
720
|
intents = intents.filter(g => g !== 'background');
|
|
653
721
|
if (!intents.length && parts.length) intents = [null];
|
|
654
722
|
const design = Object.keys(DESIGN).filter(w => text.includes(w));
|
|
655
723
|
const tracking = /letter ?spacing|tracking|kerning/.test(text);
|
|
724
|
+
// Letter spacing is a font answer, so a spacing intent it raised goes.
|
|
725
|
+
if (tracking && intents.includes('font'))
|
|
726
|
+
intents = intents.filter(g => g !== 'spacing');
|
|
727
|
+
const weight = /\b(bold|weight|heav\w*|light(er)?|thin)\b/.test(text);
|
|
728
|
+
const px = /\b(\d+(?:\.\d+)?px)\b/.exec(text)?.[1];
|
|
656
729
|
/** @type {Array<{text: string, commands: string[]}>} */
|
|
657
730
|
const results = [];
|
|
658
731
|
/** @param {string | null} g */
|
|
@@ -666,14 +739,33 @@ export function answerHow(ctx, question) {
|
|
|
666
739
|
if (g === 'font' && tracking)
|
|
667
740
|
return /tight/.test(text) ? '-0.02em' : '0.04em';
|
|
668
741
|
if (g === 'font' && /bold|heav/.test(text)) return '700';
|
|
669
|
-
if (g === '
|
|
742
|
+
if (g === 'font' && /\b(light(er)?|thin)\b/.test(text)) return '300';
|
|
743
|
+
if (g === 'text' && whiteText) return '"#ffffff"';
|
|
744
|
+
if (g === 'text' && /\baccent (text|labels?)\b/.test(text))
|
|
745
|
+
return '"var(--color-text-accent)"';
|
|
746
|
+
if (g === 'background' && /\bwhite\b/.test(text) && !whiteText)
|
|
747
|
+
return '"#ffffff"';
|
|
670
748
|
return '<value>';
|
|
671
749
|
};
|
|
672
750
|
for (const raw of parts.slice(0, 3)) {
|
|
673
|
-
|
|
674
|
-
const
|
|
751
|
+
let [part, wp, wv] = raw.split(':');
|
|
752
|
+
const named = Boolean(wp);
|
|
675
753
|
const one = FAMILIES[part] ? FAMILIES[part][0] : part;
|
|
676
754
|
if (!TARGET.has(one)) continue;
|
|
755
|
+
// A size in the question ("small buttons") is a --when condition.
|
|
756
|
+
if (!wp) {
|
|
757
|
+
const sizes = C.variantValues(one).size ?? [];
|
|
758
|
+
const word = /\b(small|sm)\b/.test(text)
|
|
759
|
+
? ['sm', 'small']
|
|
760
|
+
: /\b(large|lg|big)\b/.test(text)
|
|
761
|
+
? ['lg', 'large']
|
|
762
|
+
: /\b(medium|md)\b/.test(text)
|
|
763
|
+
? ['md', 'medium']
|
|
764
|
+
: [];
|
|
765
|
+
const hit = word.find(w => sizes.includes(w));
|
|
766
|
+
if (hit) [wp, wv] = ['size', hit];
|
|
767
|
+
}
|
|
768
|
+
const when = wp ? ` --when ${wp}:${wv}` : '';
|
|
677
769
|
// A part with variants: a change without --when reaches every variant.
|
|
678
770
|
const variants = Object.entries(C.variantValues(one)).filter(
|
|
679
771
|
([p, vals]) =>
|
|
@@ -687,12 +779,47 @@ export function answerHow(ctx, question) {
|
|
|
687
779
|
});
|
|
688
780
|
continue;
|
|
689
781
|
}
|
|
782
|
+
if (g === 'corners' && !named) {
|
|
783
|
+
// Each clause with its own size ("small 6px, large stay pill").
|
|
784
|
+
const sizes = C.variantValues(one).size ?? [];
|
|
785
|
+
const clauses = text
|
|
786
|
+
.split(/,|;|\bbut\b|\band\b/)
|
|
787
|
+
.map(c => {
|
|
788
|
+
const size = /\b(small|sm)\b/.test(c)
|
|
789
|
+
? 'sm'
|
|
790
|
+
: /\b(large|lg|big)\b/.test(c)
|
|
791
|
+
? 'lg'
|
|
792
|
+
: /\b(medium|md)\b/.test(c)
|
|
793
|
+
? 'md'
|
|
794
|
+
: null;
|
|
795
|
+
const value =
|
|
796
|
+
/\b(\d+(?:\.\d+)?px)\b/.exec(c)?.[1] ??
|
|
797
|
+
(/pill|circ/.test(c)
|
|
798
|
+
? 'pill'
|
|
799
|
+
: /sharp|square/.test(c)
|
|
800
|
+
? 'square'
|
|
801
|
+
: null);
|
|
802
|
+
return {size, value};
|
|
803
|
+
})
|
|
804
|
+
.filter(c => c.size && sizes.includes(c.size) && c.value);
|
|
805
|
+
if (clauses.length > 1) {
|
|
806
|
+
results.push({
|
|
807
|
+
text: `corners on ${part}, by size`,
|
|
808
|
+
commands: clauses.map(c =>
|
|
809
|
+
/px$/.test(/** @type {string} */ (c.value))
|
|
810
|
+
? `${P} set <theme> border-radius ${c.value} --on ${part} --when size:${c.size}`
|
|
811
|
+
: `${P} set <theme> corners ${c.value} --on ${part} --when size:${c.size}`,
|
|
812
|
+
),
|
|
813
|
+
});
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
690
817
|
if (g === 'corners') {
|
|
691
818
|
results.push({
|
|
692
819
|
text: `corners on ${part}${when ? ` (${wp} ${wv})` : ''}`,
|
|
693
820
|
commands: [
|
|
694
821
|
`${P} set <theme> corners ${/pill|circ/.test(text) ? 'pill' : /sharp|square/.test(text) ? 'square' : 'round'} --on ${part}${when}`,
|
|
695
|
-
`${P} set <theme> border-radius 6px --on ${part}${when}`,
|
|
822
|
+
`${P} set <theme> border-radius ${px ?? '6px'} --on ${part}${when}`,
|
|
696
823
|
],
|
|
697
824
|
});
|
|
698
825
|
continue;
|
|
@@ -725,12 +852,24 @@ export function answerHow(ctx, question) {
|
|
|
725
852
|
text: `room inside ${part}`,
|
|
726
853
|
commands: [
|
|
727
854
|
`${P} set <theme> spacing ${/dense|compact|tight|cramped/.test(text) ? 'compact' : 'roomy'} --on ${part}`,
|
|
728
|
-
`${P} set <theme> padding 12px --on ${part}${when}`,
|
|
855
|
+
`${P} set <theme> padding ${px ?? '12px'} --on ${part}${when}`,
|
|
729
856
|
],
|
|
730
857
|
});
|
|
731
858
|
continue;
|
|
732
859
|
}
|
|
733
860
|
const group = g === 'spacing' ? 'font' : g;
|
|
861
|
+
if (group === 'font' && tracking && weight)
|
|
862
|
+
results.push({
|
|
863
|
+
text: `${part} weight: font-weight on the part${part === 'heading' ? ', or the headings dial for every heading' : ''}`,
|
|
864
|
+
commands: [
|
|
865
|
+
`${P} set <theme> font-weight ${/\b(light(er)?|thin)\b/.test(text) ? 300 : 700} --on ${part}${when}`,
|
|
866
|
+
...(part === 'heading'
|
|
867
|
+
? [
|
|
868
|
+
`${P} set <theme> headings ${/\b(light(er)?|thin)\b/.test(text) ? 'light' : 'bold'}`,
|
|
869
|
+
]
|
|
870
|
+
: []),
|
|
871
|
+
],
|
|
872
|
+
});
|
|
734
873
|
const reads = C.partReads(one, group);
|
|
735
874
|
const filtered = wv
|
|
736
875
|
? reads.filter(
|
|
@@ -739,7 +878,22 @@ export function answerHow(ctx, question) {
|
|
|
739
878
|
r.when.includes(''),
|
|
740
879
|
)
|
|
741
880
|
: reads;
|
|
742
|
-
|
|
881
|
+
// Weight and tracking questions name only the tokens for them.
|
|
882
|
+
const aspect =
|
|
883
|
+
group === 'font' && tracking
|
|
884
|
+
? /letter|tracking/
|
|
885
|
+
: group === 'font' && weight
|
|
886
|
+
? /weight/
|
|
887
|
+
: null;
|
|
888
|
+
const fitting = aspect
|
|
889
|
+
? (filtered.length ? filtered : reads).filter(r => aspect.test(r.token))
|
|
890
|
+
: filtered.length
|
|
891
|
+
? filtered
|
|
892
|
+
: reads;
|
|
893
|
+
// Text with no color token of its own takes the page's text color.
|
|
894
|
+
const inherited =
|
|
895
|
+
!fitting.length && group === 'text' ? '--color-text-primary' : null;
|
|
896
|
+
const list = fitting.slice(0, 4);
|
|
743
897
|
const direct =
|
|
744
898
|
group === 'font' && tracking
|
|
745
899
|
? 'letter-spacing'
|
|
@@ -752,9 +906,12 @@ export function answerHow(ctx, question) {
|
|
|
752
906
|
(group === 'text' || group === 'background' || group === 'border') &&
|
|
753
907
|
!/gradient|inset/.test(V(group));
|
|
754
908
|
results.push({
|
|
755
|
-
text: `${part} ${group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : 'no token; set the property directly'}`,
|
|
909
|
+
text: `${part} ${aspect ? (tracking ? 'letter spacing' : 'weight') : group}${when ? ` (${wp} ${wv})` : ''}: ${list.length ? `comes from ${list.map(r => r.token + C.fmtWhen(r.when) + C.statusNote(one, r.token)).join(', ')}` : inherited ? `inherits the page's text color (${inherited} for the whole theme); set the property for this part alone` : 'no token of its own; set the property directly'}`,
|
|
756
910
|
commands: [
|
|
757
911
|
`${P} set <theme> ${direct} ${V(group)} --on ${part}${when} # direct: always works`,
|
|
912
|
+
...(inherited
|
|
913
|
+
? [`${P} set <theme> ${inherited} ${V(group)} # the whole theme`]
|
|
914
|
+
: []),
|
|
758
915
|
...(tokenRoute
|
|
759
916
|
? list
|
|
760
917
|
.slice(0, 2)
|
|
@@ -816,12 +973,14 @@ export function answerHow(ctx, question) {
|
|
|
816
973
|
text: DIALS[dial].help,
|
|
817
974
|
commands: DIALS[dial].examples.map(e => `${P} ${e}`),
|
|
818
975
|
});
|
|
976
|
+
// Text and background colors come from their tokens first; the brand
|
|
977
|
+
// color after.
|
|
978
|
+
results.push(...wholeThemeTokens(ctx, g));
|
|
819
979
|
if (g === 'background' || g === 'text')
|
|
820
980
|
results.push({
|
|
821
981
|
text: DIALS.accent.help,
|
|
822
982
|
commands: DIALS.accent.examples.map(e => `${P} ${e}`),
|
|
823
983
|
});
|
|
824
|
-
results.push(...wholeThemeTokens(ctx, g));
|
|
825
984
|
}
|
|
826
985
|
}
|
|
827
986
|
if (!results.length) {
|
|
@@ -834,10 +993,18 @@ export function answerHow(ctx, question) {
|
|
|
834
993
|
}
|
|
835
994
|
}
|
|
836
995
|
void TOKENS;
|
|
996
|
+
const seen = new Set();
|
|
837
997
|
return {
|
|
838
998
|
parts,
|
|
839
999
|
aspects: /** @type {string[]} */ (intents.filter(Boolean)),
|
|
840
|
-
results: results
|
|
1000
|
+
results: results
|
|
1001
|
+
.filter(r => {
|
|
1002
|
+
const key = `${r.text}\n${r.commands.join('\n')}`;
|
|
1003
|
+
if (seen.has(key)) return false;
|
|
1004
|
+
seen.add(key);
|
|
1005
|
+
return true;
|
|
1006
|
+
})
|
|
1007
|
+
.slice(0, 10),
|
|
841
1008
|
};
|
|
842
1009
|
}
|
|
843
1010
|
|
|
@@ -7,7 +7,12 @@
|
|
|
7
7
|
* @param {string} cwd
|
|
8
8
|
*/
|
|
9
9
|
export function requireProject(cwd: string): void;
|
|
10
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* The project, its part data and the compiler. When the components cannot
|
|
12
|
+
* be rendered, the part data is empty and `unchecked` says why: changes are
|
|
13
|
+
* then saved without the checks that need it, and say so.
|
|
14
|
+
* @param {string} cwd
|
|
15
|
+
*/
|
|
11
16
|
export function context(cwd: string): Promise<{
|
|
12
17
|
project: import("./_project.mjs").ThemeProject;
|
|
13
18
|
C: {
|
|
@@ -51,6 +56,7 @@ export function context(cwd: string): Promise<{
|
|
|
51
56
|
};
|
|
52
57
|
};
|
|
53
58
|
parts: import("./_parts.mjs").PartData;
|
|
59
|
+
unchecked: string | null;
|
|
54
60
|
}>;
|
|
55
61
|
/**
|
|
56
62
|
* Pictures of HTML files, on request.
|
|
@@ -90,9 +96,13 @@ export function styledChanges(before: any, after: any): string[];
|
|
|
90
96
|
* @param {boolean} png
|
|
91
97
|
*/
|
|
92
98
|
export function previewAfter(ctx: import("./_settings.mjs").Ctx, slug: string, data: import("./_settings.mjs").ThemeData, png: boolean): Promise<{
|
|
93
|
-
preview: string;
|
|
99
|
+
preview: string | null;
|
|
94
100
|
pictures: string[];
|
|
95
101
|
pictureProblem: string | null;
|
|
102
|
+
notChecked: {
|
|
103
|
+
code: import("../../foundation/response/error-codes.mjs").ErrorCode;
|
|
104
|
+
cause: string;
|
|
105
|
+
} | null;
|
|
96
106
|
}>;
|
|
97
|
-
/** @param {string | undefined}
|
|
98
|
-
export function
|
|
107
|
+
/** @param {string | undefined} section a section of the sheet */
|
|
108
|
+
export function checkSection(section: string | undefined): void;
|
|
@@ -8,6 +8,9 @@
|
|
|
8
8
|
* @position api/theme-edit — imported only by the adapter's operation helpers
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
+
import * as fs from 'node:fs';
|
|
12
|
+
import {createRequire} from 'node:module';
|
|
13
|
+
import * as path from 'node:path';
|
|
11
14
|
import {AstryxError} from '../error.mjs';
|
|
12
15
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
13
16
|
import {CLOSEST_OPEN_FONT, OPEN_FONTS, P, SYSTEM_FONTS} from './_tables.mjs';
|
|
@@ -41,14 +44,79 @@ export function requireProject(cwd) {
|
|
|
41
44
|
);
|
|
42
45
|
}
|
|
43
46
|
|
|
44
|
-
/**
|
|
47
|
+
/**
|
|
48
|
+
* The project, its part data and the compiler. When the components cannot
|
|
49
|
+
* be rendered, the part data is empty and `unchecked` says why: changes are
|
|
50
|
+
* then saved without the checks that need it, and say so.
|
|
51
|
+
* @param {string} cwd
|
|
52
|
+
*/
|
|
45
53
|
export async function context(cwd) {
|
|
46
54
|
requireProject(cwd);
|
|
47
55
|
const project = await openProject(cwd);
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
/** @type {import('./_parts.mjs').PartData} */
|
|
57
|
+
let parts;
|
|
58
|
+
/** @type {string | null} */
|
|
59
|
+
let unchecked = null;
|
|
60
|
+
try {
|
|
61
|
+
parts = await partData(project);
|
|
62
|
+
} catch (e) {
|
|
63
|
+
if (!isRenderFailure(e)) throw e;
|
|
64
|
+
unchecked = renderCause(project, /** @type {Error} */ (e).message);
|
|
65
|
+
parts = {
|
|
66
|
+
version: 0,
|
|
67
|
+
coreKey: project.coreKey,
|
|
68
|
+
map: {},
|
|
69
|
+
pairs: [],
|
|
70
|
+
rendered: 0,
|
|
71
|
+
items: 0,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return {project, C: makeCompiler(project, parts), parts, unchecked};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** @param {unknown} e */
|
|
78
|
+
const isRenderFailure = e =>
|
|
79
|
+
e instanceof AstryxError &&
|
|
80
|
+
(e.code === E.ERR_RENDER_FAILED ||
|
|
81
|
+
e.code === E.ERR_RENDER_MISSING_DEPENDENCY);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Why the components did not render, with the likely cause: two copies of
|
|
85
|
+
* React (the app's and the one Core resolves) break every hook.
|
|
86
|
+
* @param {import('./_project.mjs').ThemeProject} project
|
|
87
|
+
* @param {string} message
|
|
88
|
+
*/
|
|
89
|
+
function renderCause(project, message) {
|
|
90
|
+
/** @param {(id: string) => string} resolve */
|
|
91
|
+
const reactOf = resolve => {
|
|
92
|
+
try {
|
|
93
|
+
return fs.realpathSync(path.dirname(resolve('react/package.json')));
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const app = reactOf(project.req.resolve);
|
|
99
|
+
let core = null;
|
|
100
|
+
try {
|
|
101
|
+
core = reactOf(
|
|
102
|
+
createRequire(project.req.resolve('@astryxdesign/core/package.json'))
|
|
103
|
+
.resolve,
|
|
104
|
+
);
|
|
105
|
+
} catch {
|
|
106
|
+
// No Core package file: nothing to compare.
|
|
107
|
+
}
|
|
108
|
+
return app && core && app !== core
|
|
109
|
+
? `${message} The likely cause: two copies of React, the app's (${app}) and the one Core resolves (${core}). Make Core resolve the app's React.`
|
|
110
|
+
: message;
|
|
50
111
|
}
|
|
51
112
|
|
|
113
|
+
/**
|
|
114
|
+
* The "saved, not checked" report of a change, or null when it was checked.
|
|
115
|
+
* @param {string | null} cause
|
|
116
|
+
*/
|
|
117
|
+
const notChecked = cause =>
|
|
118
|
+
cause ? {code: E.ERR_THEME_NOT_CHECKED, cause} : null;
|
|
119
|
+
|
|
52
120
|
/**
|
|
53
121
|
* Pictures of HTML files, on request.
|
|
54
122
|
* @param {import('./_project.mjs').ThemeProject} project
|
|
@@ -85,10 +153,17 @@ export function fontNotes(ctx, data) {
|
|
|
85
153
|
/** @type {string[]} */
|
|
86
154
|
const notes = [];
|
|
87
155
|
for (const {pkg, family, installed} of fontPackages(ctx, data)) {
|
|
156
|
+
const fallbacks =
|
|
157
|
+
Object.values(OPEN_FONTS).find(f => f.pkg === pkg)?.fallbacks ?? '';
|
|
158
|
+
const near = /monospace/.test(fallbacks)
|
|
159
|
+
? 'mono'
|
|
160
|
+
: /serif/.test(fallbacks.replace('sans-serif', ''))
|
|
161
|
+
? 'serif'
|
|
162
|
+
: 'system';
|
|
88
163
|
notes.push(
|
|
89
164
|
installed
|
|
90
165
|
? `the app loads this font with one import: import '${pkg}';`
|
|
91
|
-
: `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'
|
|
166
|
+
: `${family} is not installed, so it does not load: the previews and the app show the next font in the stack. Install it: ${installLine(ctx.project.cwd, [pkg])}. Then the preview imports it on the next set or show, and the app imports it once: import '${pkg}'; Until then, the closest font that needs no install is ${near}: ${P} set ${data.name} font ${near}`,
|
|
92
167
|
);
|
|
93
168
|
}
|
|
94
169
|
for (const s of data.settings) {
|
|
@@ -177,24 +252,38 @@ export function styledChanges(before, after) {
|
|
|
177
252
|
* @param {boolean} png
|
|
178
253
|
*/
|
|
179
254
|
export async function previewAfter(ctx, slug, data, png) {
|
|
180
|
-
|
|
255
|
+
/** @type {string | null} */
|
|
256
|
+
let preview = null;
|
|
257
|
+
let cause = ctx.unchecked ?? null;
|
|
258
|
+
try {
|
|
259
|
+
preview = await renderPreview(ctx, slug, data);
|
|
260
|
+
} catch (e) {
|
|
261
|
+
if (!isRenderFailure(e)) throw e;
|
|
262
|
+
cause ??= renderCause(ctx.project, /** @type {Error} */ (e).message);
|
|
263
|
+
}
|
|
181
264
|
const f = themeFiles(ctx.project.cwd, slug);
|
|
182
|
-
const shots =
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
265
|
+
const shots =
|
|
266
|
+
png && preview
|
|
267
|
+
? await pictures(
|
|
268
|
+
ctx.project,
|
|
269
|
+
[{html: f.preview, png: f.previewPng}],
|
|
270
|
+
modesOf(data),
|
|
271
|
+
)
|
|
272
|
+
: {files: [], problem: null};
|
|
273
|
+
return {
|
|
274
|
+
preview,
|
|
275
|
+
pictures: shots.files,
|
|
276
|
+
pictureProblem: shots.problem,
|
|
277
|
+
notChecked: notChecked(cause),
|
|
278
|
+
};
|
|
190
279
|
}
|
|
191
280
|
|
|
192
|
-
/** @param {string | undefined}
|
|
193
|
-
export function
|
|
194
|
-
if (
|
|
281
|
+
/** @param {string | undefined} section a section of the sheet */
|
|
282
|
+
export function checkSection(section) {
|
|
283
|
+
if (section != null && !SHOWCASE_GROUPS.includes(section))
|
|
195
284
|
refuse(
|
|
196
285
|
E.ERR_INVALID_ARGUMENT,
|
|
197
|
-
`--
|
|
198
|
-
{didYouMean: nearest(
|
|
286
|
+
`--section takes ${SHOWCASE_GROUPS.join(', ')}, not "${section}".`,
|
|
287
|
+
{didYouMean: nearest(section, SHOWCASE_GROUPS)},
|
|
199
288
|
);
|
|
200
289
|
}
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
* @typedef {import('./theme-edit.type.mjs').ThemeEditChangeOptions} ChangeOptions
|
|
6
6
|
*/
|
|
7
7
|
/**
|
|
8
|
-
* Start a theme in themes/<name>/, optionally on a built-in theme
|
|
8
|
+
* Start a theme in themes/<name>/, optionally on a built-in theme, with any
|
|
9
|
+
* dial settings applied in the same build. Each setting is checked as `set`
|
|
10
|
+
* checks it, before anything is written.
|
|
9
11
|
* @experimental
|
|
10
12
|
* @param {string} name
|
|
11
13
|
* @param {import('./theme-edit.type.mjs').ThemeEditNewOptions} [options]
|