diff --git a/CHANGELOG.md b/CHANGELOG.md index 21d50715b3..e94193e66a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- **Theme Token Review Follow-ups** — Sans Serif stays `sans-serif` in `figma-to-block-theme`, `site-to-design-tokens` pairs button text by colour and lists moved spacing, and `theme-orphaned-refs` wants an absolute report path. (#4044) - **Site Tokens Numeric Slugs** — `site-to-design-tokens` exports the scaffold's numeric slugs for font sizes, radius and shadows, and radius uses bare size names. ([#4004](https://github.com/lightspeedwp/.github/issues/4004)) - **Orphaned Refs Scan Scope** — `theme-orphaned-refs` skips `node_modules`, build and agent folders, checks radius presets, suggests numeric steps, and is now TypeScript with tests. ([#4037](https://github.com/lightspeedwp/.github/pull/4037)) - **Site Tokens Palette Order** — `site-to-design-tokens` exports the colour ramps in the LightSpeed order (neutral, primary, brand, cta), so the theme palette follows the convention. ([#4035](https://github.com/lightspeedwp/.github/pull/4035)) diff --git a/skills/figma-to-block-theme/scripts/__tests__/figma-variables-to-theme-json.test.ts b/skills/figma-to-block-theme/scripts/__tests__/figma-variables-to-theme-json.test.ts index f14a2edddf..f086346ac1 100644 --- a/skills/figma-to-block-theme/scripts/__tests__/figma-variables-to-theme-json.test.ts +++ b/skills/figma-to-block-theme/scripts/__tests__/figma-variables-to-theme-json.test.ts @@ -455,6 +455,11 @@ describe('FigmaVariablesMapper', () => { // With no declared stack, a generic name is the stack, and a named mono font falls back to monospace. expect(family('monospace', 'Monospace')).toBe('monospace'); expect(family('monospace', 'Fira Code')).toBe('"Fira Code", monospace'); + // The site-tokens default body font is "Sans Serif" with the stack `sans-serif`. + expect(family('body', 'Sans Serif', 'Body (default). CSS stack: sans-serif')).toBe( + 'sans-serif' + ); + expect(family('body', 'Sans Serif')).toBe('sans-serif'); }); it('writes only the font roles that exist, with no accent when there is none', () => { diff --git a/skills/figma-to-block-theme/scripts/figma-variables-to-theme-json.ts b/skills/figma-to-block-theme/scripts/figma-variables-to-theme-json.ts index a0021ffda0..6390b58c02 100644 --- a/skills/figma-to-block-theme/scripts/figma-variables-to-theme-json.ts +++ b/skills/figma-to-block-theme/scripts/figma-variables-to-theme-json.ts @@ -627,8 +627,9 @@ export class FigmaVariablesMapper { if (!stack) { return undefined; } - // A generic name such as "Monospace" has no font of its own: the declared system stack is the font. - if (GENERIC_FAMILIES.has(name.trim().toLowerCase())) { + // A generic name such as "Monospace" or "Sans Serif" has no font of its own: the + // declared system stack is the font. + if (this.genericFamily(name)) { return stack; } const [first, ...fallbacks] = stack.split(',').map((part) => part.trim()); @@ -643,8 +644,8 @@ export class FigmaVariablesMapper { /** A stack with no declaration: the family, then the generic family for its role. */ private fontStack(family: string, slug: string): string { - const generic = family.trim().toLowerCase(); - if (GENERIC_FAMILIES.has(generic)) { + const generic = this.genericFamily(family); + if (generic) { return generic; } const fallback = @@ -652,6 +653,15 @@ export class FigmaVariablesMapper { return `${this.quoteFamily(family)}, ${fallback}`; } + /** The CSS generic keyword a display name stands for ("Sans Serif" is `sans-serif`). */ + private genericFamily(name: string): string | undefined { + const wanted = name + .trim() + .toLowerCase() + .replace(/[\s_]+/g, '-'); + return GENERIC_FAMILIES.has(wanted) ? wanted : undefined; + } + private quoteFamily(family: string): string { return /\s/.test(family) ? `"${family}"` : family; } diff --git a/skills/site-to-design-tokens/references/proposal-review.md b/skills/site-to-design-tokens/references/proposal-review.md index dcee8f28ae..42ba148845 100644 --- a/skills/site-to-design-tokens/references/proposal-review.md +++ b/skills/site-to-design-tokens/references/proposal-review.md @@ -12,7 +12,7 @@ Each item needs an answer before approval: - **Confirm each family's anchor.** Each line gives the live colour, its step, and where the site uses it. To change one, re-run `propose-tokens.ts` with `--assign brand=#hex` (or `primary`, `cta`). - **Generated placeholders.** When the site has no colour for a family, a placeholder is generated. Ask the reviewer for the real colour. -- **Merged sizes.** The type scale has 8 steps. Extra sizes are merged into their nearest neighbour, and smaller sizes share `Tiny`. Check that nothing important was merged. +- **Merged sizes.** The type scale has up to 9 steps (`100` to `900`). Extra sizes are merged into their nearest neighbour, and smaller sizes share `Tiny`. Check that nothing important was merged. - **Kept defaults.** A semantic role whose live colour was unreadable on the page keeps its TSP default. ## Colour primitives diff --git a/skills/site-to-design-tokens/scripts/__tests__/propose-tokens.test.ts b/skills/site-to-design-tokens/scripts/__tests__/propose-tokens.test.ts index d29cf3393e..c9a2979878 100644 --- a/skills/site-to-design-tokens/scripts/__tests__/propose-tokens.test.ts +++ b/skills/site-to-design-tokens/scripts/__tests__/propose-tokens.test.ts @@ -237,7 +237,9 @@ describe('TokenProposer on a sparse site', () => { ['Gigantic', '90', 140], ['Colossal', '100', 200], ]); - expect(proposer['decisions'].join(' ')).toContain('moved down to free lower steps'); + expect(proposer['decisions'].join(' ')).toContain( + 'so none is dropped: 140px to `90`, 200px to `100`.' + ); }); it('fills the whole 5 to 100 ladder with 11 distinct values and drops none', () => { @@ -573,6 +575,20 @@ describe('TokenProposer action text', () => { expect(sem['action/cta/text'].evidence).toMatch(/^#ffffff on #a31700 buttons/); }); + it('pairs text with a fill that has the same value as contrast', () => { + // The fill resolves to `contrast` by name, but the action background is `primary-900`. + const primitives = { base: '#ffffff', contrast: '#111111', 'primary-900': '#111111' }; + const sem = new TokenProposer().proposeSemantic( + [{ hex: '#111111', weight: 5, uses: { 'button-background': 5 } }], + primitives, + [{ family: 'primary', hex: '#111111', step: 900, source: 'observed', evidence: '' } as never], + new Map([['#111111', new Map([['#ffffff', 5]])]]) + ); + expect(sem['action/primary/background'].token).toBe('primary-900'); + expect(sem['action/primary/text']).toMatchObject({ token: 'base', source: 'observed' }); + expect(sem['action/primary/text'].evidence).toMatch(/^#ffffff on #111111 buttons/); + }); + it('pairs only opaque button text with opaque button fills', () => { const pairs = new TokenProposer().buttonTextByFill([ { key: 'a', role: 'button', color: 'rgb(255, 255, 255)', background: 'rgb(0, 0, 0)' }, diff --git a/skills/site-to-design-tokens/scripts/propose-tokens.ts b/skills/site-to-design-tokens/scripts/propose-tokens.ts index a659010978..3e8a7ff0d9 100644 --- a/skills/site-to-design-tokens/scripts/propose-tokens.ts +++ b/skills/site-to-design-tokens/scripts/propose-tokens.ts @@ -735,8 +735,11 @@ export class TokenProposer { } const texts = new Map(); const fills: string[] = []; + // Compare colours, not token names: a fill that also matches `contrast` resolves + // to that name, while the action background can be a family step of the same value. + const fillValue = primitives[fill.token]; for (const [fillHex, onFill] of buttonText) { - if (this.nearestPrimitive(fillHex, primitives) !== fill.token) { + if (primitives[this.nearestPrimitive(fillHex, primitives)] !== fillValue) { continue; } fills.push(fillHex); @@ -1159,17 +1162,17 @@ export class TokenProposer { ); indexes.push(Math.max(nearest, indexes.length ? indexes[indexes.length - 1] + 1 : 0)); } - let shifted = false; + const moved: string[] = []; for (let i = indexes.length - 1; i >= 0; i--) { const ceiling = i === indexes.length - 1 ? last : indexes[i + 1] - 1; if (indexes[i] > ceiling) { indexes[i] = ceiling; - shifted = true; + moved.unshift(`${kept[i].max}px to \`${SPACING_STEPS[ceiling].slug}\``); } } - if (shifted) { + if (moved.length) { this.decisions.push( - 'Some spacing values moved down to free lower steps so the whole 5 to 100 ladder is used and none is dropped.' + `Some spacing values moved down to a free lower step so none is dropped: ${moved.join(', ')}.` ); } const steps: ScaleEntry[] = kept.map((c, i) => ({ diff --git a/skills/theme-orphaned-refs/SKILL.md b/skills/theme-orphaned-refs/SKILL.md index 800ecbb617..de73b1ff5a 100644 --- a/skills/theme-orphaned-refs/SKILL.md +++ b/skills/theme-orphaned-refs/SKILL.md @@ -38,9 +38,17 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect Use the bundled script to find orphaned references and suggested replacements: ```bash -npx tsx ${CLAUDE_SKILL_DIR}/scripts/find-orphaned-presets.ts --root --report +npx tsx ${CLAUDE_SKILL_DIR}/scripts/find-orphaned-presets.ts --root --report /absolute/path/outside-the-theme.txt ``` +From the root of a `.github` checkout, where `CLAUDE_SKILL_DIR` is not set: + +```bash +npx tsx skills/theme-orphaned-refs/scripts/find-orphaned-presets.ts --root --report /absolute/path/outside-the-theme.txt +``` + +Give `--report` an absolute path. A relative path is resolved against the theme root, not the current folder, so the report would land inside the theme. + Add `--exclude ` (repeatable) to skip another folder. Run `npm ci` in the `.github` checkout first. Tests: `npm run test:theme-orphaned-refs` from the repository root. Then apply replacements with minimal, localized edits.