Skip to content

Commit c87cb0c

Browse files
authored
experimental theme: a seventh round of fixes (how lists, one-mode shadows and borders, offline pictures) (#11779)
[experimental] `astryx experimental theme editor how` reads more questions through its shared readers: - **Lists:** a two-item list of variants or states before a single ask names each one for that ask: "primary and ghost buttons rounder", "hovered and pressed buttons orange", in an except list too. "except disabled buttons" keeps that state. An except covers the whole ask before it. A prohibition said before the ask ("never round the inputs; make everything rounder", "don't make cards rounder, make everything rounder") is read the same as one said after it. - **One-mode shadows:** - A one-mode shadow on a part reads the shared shadows to their layers. - It refuses with the true reason when the other mode is unknown, or when nothing of the part's own is there to remove. - **Ringed parts:** a resting shadow, or its removal, is not offered on a part that draws its hover and focus rings in its box-shadow, in either mode. - **One-mode lines:** a line the part already draws (a border, one side of it, an outline) takes its color by mode. When `set --mode` refuses such a line, it now names working steps instead of ones that repaint the other mode. - **Accent colors:** on a theme whose modes show a color in different hues, or that shows only dark mode, a lighter, darker, warmer or cooler accent moves each mode's colors from their own values. - **Swaps:** swapping two role colors also swaps their text, icon, wash and label colors in every mode. - **Corners:** comparisons read the radius each part is built with (stone's pill buttons). A button group's corners step by a px amount. - **Gradients:** gradients named by theme colors ("from the accent to the danger color") use those colors. - **Hyphens:** a part or phrase written with hyphens or underscores ("focus-ring", "table_row") reads the same as with spaces. - **Other readings:** - A text-only part's color is its text color ("the top nav heading white"). - "What color is the header" answers its fill. - "Bigger but no more than 20px" takes one step of the theme's scale, held to the bound. - "Everything serif except headings" keeps the headings' font. - "The hover tint stronger" changes the shared hover wash, not the page. - "The body text 1px bigger" steps the text size. `box-shadow none` on a card now also removes Core's elevation shadow. The selection ring stays. [experimental] `astryx experimental theme editor undo`: with no `--mode`, a setting saved for one mode only is removed, and the result names its mode; one saved for each mode gets an undo line per mode instead of a refusal that contradicts itself. [experimental] `astryx experimental theme editor` pictures (`--png`) never wait on a network: the picture's browser loads the page's own files only, so a remote stylesheet, font or image a page names (a base theme's Google Fonts import, a template's photo) fails at once instead of holding the picture until the time limit when the machine is offline or has no direct internet.
1 parent b18f5d6 commit c87cb0c

21 files changed

Lines changed: 1629 additions & 170 deletions
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[experimental] `astryx experimental theme editor how` reads more questions through its shared readers:
6+
7+
- **Lists:** a two-item list of variants or states before a single ask names each one for that ask: "primary and ghost buttons rounder", "hovered and pressed buttons orange", in an except list too. "except disabled buttons" keeps that state. An except covers the whole ask before it. A prohibition said before the ask ("never round the inputs; make everything rounder", "don't make cards rounder, make everything rounder") is read the same as one said after it.
8+
- **One-mode shadows:**
9+
- A one-mode shadow on a part reads the shared shadows to their layers.
10+
- It refuses with the true reason when the other mode is unknown, or when nothing of the part's own is there to remove.
11+
- **Ringed parts:** a resting shadow, or its removal, is not offered on a part that draws its hover and focus rings in its box-shadow, in either mode.
12+
- **One-mode lines:** a line the part already draws (a border, one side of it, an outline) takes its color by mode. When `set --mode` refuses such a line, it now names working steps instead of ones that repaint the other mode.
13+
- **Accent colors:** on a theme whose modes show a color in different hues, or that shows only dark mode, a lighter, darker, warmer or cooler accent moves each mode's colors from their own values.
14+
- **Swaps:** swapping two role colors also swaps their text, icon, wash and label colors in every mode.
15+
- **Corners:** comparisons read the radius each part is built with (stone's pill buttons). A button group's corners step by a px amount.
16+
- **Gradients:** gradients named by theme colors ("from the accent to the danger color") use those colors.
17+
- **Hyphens:** a part or phrase written with hyphens or underscores ("focus-ring", "table_row") reads the same as with spaces.
18+
- **Other readings:**
19+
- A text-only part's color is its text color ("the top nav heading white").
20+
- "What color is the header" answers its fill.
21+
- "Bigger but no more than 20px" takes one step of the theme's scale, held to the bound.
22+
- "Everything serif except headings" keeps the headings' font.
23+
- "The hover tint stronger" changes the shared hover wash, not the page.
24+
- "The body text 1px bigger" steps the text size.
25+
26+
`box-shadow none` on a card now also removes Core's elevation shadow. The selection ring stays.
27+
28+
@josephfarina
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[experimental] `astryx experimental theme editor undo`: with no `--mode`, a setting saved for one mode only is removed, and the result names its mode; one saved for each mode gets an undo line per mode instead of a refusal that contradicts itself.
6+
7+
@josephfarina
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@astryxdesign/cli': patch
3+
---
4+
5+
[experimental] `astryx experimental theme editor` pictures (`--png`) never wait on a network: the picture's browser loads the page's own files only, so a remote stylesheet, font or image a page names (a base theme's Google Fonts import, a template's photo) fails at once instead of holding the picture until the time limit when the machine is offline or has no direct internet.
6+
7+
@josephfarina

‎packages/cli/api/theme-edit/_check.mjs‎

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,39 @@ function oneModeOfTheme(data) {
24752475
: null;
24762476
}
24772477

2478+
/**
2479+
* Whether any of the parts draws a line of that kind (a border, one side's
2480+
* border, an outline) with a width, at rest or in the state named: then its
2481+
* color alone can differ by mode.
2482+
* @param {any} C the part census
2483+
* @param {string[]} parts
2484+
* @param {string} prop border, border-<side> or outline
2485+
* @param {string | undefined | null} [state]
2486+
* @returns {boolean}
2487+
*/
2488+
export function drawsLine(C, parts, prop, state) {
2489+
// (A side's line is drawn by the side's own width or the shared one.)
2490+
const keys =
2491+
prop === 'border'
2492+
? [
2493+
'border-width',
2494+
...['top', 'right', 'bottom', 'left'].map(x => `border-${x}-width`),
2495+
]
2496+
: prop.startsWith('border-')
2497+
? [`${prop}-width`, 'border-width']
2498+
: [`${prop}-width`];
2499+
return parts.some(t => {
2500+
const at = C.MAP[t]?.at ?? {};
2501+
return keys.some(k =>
2502+
Object.entries(at[k] ?? {}).some(
2503+
([sel, w]) =>
2504+
!/^\s*0(?:px)?\s*$/.test(String(w)) &&
2505+
(state ? sel.includes(state) : !/:/.test(sel)),
2506+
),
2507+
);
2508+
});
2509+
}
2510+
24782511
/**
24792512
* What a text property CSS inherits, set on a part, also reaches: the parts
24802513
* inside it that set no such property of their own, said in one line; null
@@ -5911,11 +5944,19 @@ function checkOne(ctx, slug, data, thing, value, flags, unset, reads) {
59115944
: longhandOf('color') && COLOR_PROPS.test(`${prop}-color`)
59125945
? `${prop}-color`
59135946
: null;
5947+
// A line (a border, one side's border, an outline) the part does not
5948+
// draw now would appear in the other mode too, with its current
5949+
// color: only a line the part draws takes its color by mode here.
5950+
const lined = /^(?:border(?:-(?:top|right|bottom|left))?|outline)$/.test(
5951+
prop,
5952+
);
5953+
const undrawn =
5954+
lined && !drawsLine(C, partsOf(ctx, s), prop, s.state ?? null);
59145955
// On a part whose variants each have their own color, the color per
59155956
// mode is set for one variant at a time (as that refusal says): the
59165957
// step names the default one, or the first.
59175958
let altWhen = '';
5918-
if (alt && !s.when) {
5959+
if (alt === 'background-color' && !s.when) {
59195960
const g = C.groupOfProp(alt);
59205961
const variants = [
59215962
...new Set(
@@ -5977,7 +6018,7 @@ function checkOne(ctx, slug, data, thing, value, flags, unset, reads) {
59776018
)
59786019
: null;
59796020
const runs = alt
5980-
? shapeRuns.length < shapeLines.length
6021+
? shapeRuns.length < shapeLines.length || undrawn
59816022
? null
59826023
: [
59836024
...shapeRuns,
@@ -5990,11 +6031,13 @@ function checkOne(ctx, slug, data, thing, value, flags, unset, reads) {
59906031
: null;
59916032
refuse(
59926033
E.ERR_THEME_NO_MODE,
5993-
alt
5994-
? `--mode takes a plain color; ${prop} mixes a color with ${words.length > 1 ? 'other words' : 'nothing else'}, so its color goes per mode through ${alt}${shapeLines.length ? `, and its ${prop === 'text-decoration' ? 'line and style' : 'width and style'} for both modes` : ''}.`
5995-
: colorWord && /shadow$/.test(prop)
5996-
? `--mode takes a plain color; ${prop} mixes a color with sizes, so --mode cannot hold it. Its color can still differ between light and dark: write it in the value as light-dark(<light>, <dark>).`
5997-
: `--mode works on plain colors; ${prop} is not a color, so it is set for both modes.`,
6034+
alt && undrawn
6035+
? `--mode takes a plain color; ${s.on} draws no ${prop} now, and a line's width and style are the same in both modes, so it would show in the other mode too. Write its color in the value as light-dark(<light>, <dark>), with transparent for the mode that shows none.`
6036+
: alt
6037+
? `--mode takes a plain color; ${prop} mixes a color with ${words.length > 1 ? 'other words' : 'nothing else'}, so its color goes per mode through ${alt}${shapeLines.length ? `, and its ${prop === 'text-decoration' ? 'line and style' : 'width and style'} for both modes` : ''}.`
6038+
: colorWord && /shadow$/.test(prop)
6039+
? `--mode takes a plain color; ${prop} mixes a color with sizes, so --mode cannot hold it. Its color can still differ between light and dark: write it in the value as light-dark(<light>, <dark>).`
6040+
: `--mode works on plain colors; ${prop} is not a color, so it is set for both modes.`,
59986041
{
59996042
run: runs ?? [
60006043
colorWord

‎packages/cli/api/theme-edit/_edit.mjs‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4145,18 +4145,47 @@ async function changeOnce(
41454145
},
41464146
};
41474147
}
4148-
const k = keyOf(s);
4149-
const prevIdx =
4148+
let k = keyOf(s);
4149+
let prevIdx =
41504150
rawIdx >= 0
41514151
? rawIdx
41524152
: // A setting listed twice by hand: the last entry is the one the
41534153
// build reads, so it is the one this command changes.
41544154
data.settings.map(x => keyOf(x)).lastIndexOf(k);
41554155
/** @type {string | null} */
41564156
let vibrancyGone = null;
4157-
const prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
4157+
let prev = prevIdx >= 0 ? data.settings[prevIdx] : null;
41584158
/** The other entries of a setting listed twice by hand that this command replaces or removes. @type {import('./_settings.mjs').Setting[]} */
41594159
let alsoReplaced = [];
4160+
if (sub === 'undo' && !prev && !s.mode) {
4161+
// An undo with no --mode of a setting saved for one mode only: that
4162+
// entry, named with its mode; saved for each mode, one undo each.
4163+
const modal = data.settings.filter(
4164+
x =>
4165+
x.thing === s.thing &&
4166+
x.mode &&
4167+
(x.on ?? null) === (s.on ?? null) &&
4168+
(x.when ?? null) === (s.when ?? null) &&
4169+
(x.state ?? null) === (s.state ?? null) &&
4170+
Boolean(x.only) === Boolean(s.only),
4171+
);
4172+
if (modal.length === 1) {
4173+
s.mode = modal[0].mode;
4174+
k = keyOf(s);
4175+
prevIdx = data.settings.indexOf(modal[0]);
4176+
prev = modal[0];
4177+
} else if (modal.length > 1)
4178+
refuse(
4179+
E.ERR_THEME_NOT_SET,
4180+
`${slug} sets ${describe({...s, value: '?'})
4181+
.replace(' = ?', '')
4182+
.replace(
4183+
/ \(whole theme\)$/,
4184+
'',
4185+
)} for each mode on its own (${modal.map(x => `${x.mode}: ${x.value}`).join('; ')}), so undo needs the one to remove: name its --mode.`,
4186+
{run: modal.map(x => `${P} undo ${slug} ${undoArgs(x)}`)},
4187+
);
4188+
}
41604189
if (sub === 'undo') {
41614190
if (!prev) {
41624191
// A padding set in the other form (a side for the shorthand, or the

0 commit comments

Comments
 (0)