Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- **Orphaned Refs Scan Scope** — `theme-orphaned-refs` skips dependency, build and agent folders (with `--exclude` for more), checks `border-radius` presets, suggests the nearest step for numeric ladders, and is now TypeScript with Jest tests (`find-orphaned-presets.ts`). ([GIT-2774](https://linear.app/lightspeedwp/issue/GIT-2774))
- **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. ([GIT-2773](https://linear.app/lightspeedwp/issue/GIT-2773))
- **Figma Tokens Layout Widths** — `figma-to-block-theme` maps the content and wide width variables to `settings.layout` in px, instead of unitless values in `settings.custom.layout`, so the theme gets the design's widths. ([GIT-2772](https://linear.app/lightspeedwp/issue/GIT-2772))
- **Figma Tokens Monospace Stack** — `figma-to-block-theme` keeps the declared system stack for a generic family such as Monospace, and falls back to `monospace` for the monospace role, instead of writing `Monospace, sans-serif`. ([GIT-2771](https://linear.app/lightspeedwp/issue/GIT-2771))
- **Figma Tokens Font Stacks** — `figma-to-block-theme` starts each font stack with the clean family name and keeps the declared fallbacks, instead of the live site's own `@font-face` name, so the stack matches the theme's `fontFace` entries. ([GIT-2770](https://linear.app/lightspeedwp/issue/GIT-2770))
- **Site Tokens Spacing Minimums** — `site-to-design-tokens` keeps mobile spacing values in order up the ladder, raising a step that would shrink below the one before and listing it for the reviewer. ([GIT-2766](https://linear.app/lightspeedwp/issue/GIT-2766))
- **Site Tokens Action Text** — `site-to-design-tokens` takes each action's text colour from the buttons that have its fill, so text and fill are a pair the site really shows. ([GIT-2765](https://linear.app/lightspeedwp/issue/GIT-2765))
- **Site Tokens Crawl Redirects** — `site-to-design-tokens` records where each page landed, warns about redirects, and leaves out pages that land on one already captured. ([GIT-2767](https://linear.app/lightspeedwp/issue/GIT-2767))
- **Site Tokens Action Colours** — `site-to-design-tokens` uses the live button colour for action backgrounds (hover one step darker) and moves defaults that fail contrast to the nearest passing step, recording each move in the report. ([#4008](https://github.com/lightspeedwp/.github/issues/4008))
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
"test:js": "jest --config .jest.config.cjs --coverage --forceExit --detectOpenHandles",
"test:figma-to-block-theme": "jest --config skills/figma-to-block-theme/scripts/jest.config.cjs",
"test:site-to-design-tokens": "jest --config skills/site-to-design-tokens/scripts/jest.config.cjs",
"test:theme-orphaned-refs": "jest --config skills/theme-orphaned-refs/scripts/jest.config.cjs",
"test:theme-orphaned-refs": "jest --config skills/theme-orphaned-refs/scripts/jest.config.cjs",
"test:site-to-figma-components": "jest --config skills/site-to-figma-components/scripts/jest.config.cjs",
"test:agent-spec-validation": "node .github/scripts/__tests__/validate-agent-specs.test.js",
"test:index-generator": "node .github/scripts/__tests__/generate-agent-index.test.js",
Expand Down
4 changes: 4 additions & 0 deletions skills/figma-to-block-theme/references/tokens-spacing.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ Use `--min-viewport` and `--max-viewport` only when the design's frames differ f
- Replace `settings.spacing.spacingSizes`, and set `defaultSpacingSizes: false`. Core's default sizes use the slugs `20` to `80`, and when they are on they override theme sizes with the same slugs, so the theme's values never reach the page. Keep `units`, `padding`, `margin` and `blockGap`.
- Compare the count with the mapper's `counts.spacing`.
- Slugs used in `styles` and patterns (`var:preset|spacing|<slug>`) must still exist. `theme-orphaned-refs` checks this.

## Layout widths

Variables whose code syntax is `--wp--custom--layout--content-size` or `--wp--custom--layout--wide-size` (the form `site-to-design-tokens` writes), or core's `--wp--style--global--content-size` and `--wide-size`, go to `settings.layout.contentSize` and `wideSize`, not to `settings.custom`. Numbers become px (`848` gives `"848px"`), and a string keeps its unit. Compare the widths with the theme's current `settings.layout` in the plan, and note `counts.layout` in the report.
5 changes: 3 additions & 2 deletions skills/figma-to-block-theme/references/tokens-typography.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ After replacing the sizes, update every reference in `styles`, `styles.blocks`,
Variables whose code syntax is `--wp--preset--font-family--<slug>` (`heading`, `body`, `monospace`, and `accent` only when the site has a third font) become `{ slug, name, fontFamily }`:

- `name` is the font name (for example "Nunito Sans"), not the slug.
- If the variable description holds a `CSS stack: <stack>` line (written by `site-to-design-tokens`) and its first family is the font named by the value, `fontFamily` is that exact stack.
- Otherwise `fontFamily` quotes names that contain spaces and adds a fallback: `sans-serif` by default, or `--font-fallback serif` for serif families. Confirm the fallback with the user.
- If the variable description holds a `CSS stack: <stack>` line (written by `site-to-design-tokens`) and its first family is the font named by the value, `fontFamily` is the font name followed by that stack's fallbacks. The first family is the live site's own `@font-face` name (for example `argesta_displayregular, serif` gives `"Argesta Display", serif`), which the theme's `fontFace` entries won't declare.
- A generic family name such as "Monospace" names no font of its own, so its declared stack is kept as it is (for example `ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace`).
- Otherwise `fontFamily` quotes names that contain spaces and adds a fallback: `monospace` for the `monospace` role, otherwise `sans-serif` by default, or `--font-fallback serif` for serif families. Confirm the fallback with the user.

### Font files

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe('FigmaVariablesMapper', () => {
);
});

it('keeps the exact CSS stack declared in a font variable description', () => {
it('keeps the fallbacks of the CSS stack declared in a font variable description', () => {
const font = (value: string, description?: string) =>
new FigmaVariablesMapper().map({
collections: [
Expand All @@ -415,13 +415,48 @@ describe('FigmaVariablesMapper', () => {
(mapped.theme.settings as Json).typography.fontFamilies[0].fontFamily;
const description = 'Headings (live). CSS stack: moret, Georgia, serif';

expect(stack(font('Moret', description))).toBe('moret, Georgia, serif');
// The live @font-face name gives way to the clean family name.
expect(stack(font('Moret', description))).toBe('Moret, Georgia, serif');
expect(
stack(font('Argesta Display', 'Body text (live). CSS stack: argesta_displayregular, serif'))
).toBe('"Argesta Display", serif');
expect(stack(font('Moret', 'CSS stack: moret'))).toBe('Moret');
// A stack for another font is ignored.
expect(stack(font('Lora', description))).toBe('Lora, sans-serif');
expect(stack(font('Moret'))).toBe('Moret, sans-serif');
expect(stack(font('Moret', 'Headings only'))).toBe('Moret, sans-serif');
});

it('keeps the system stack of a generic family such as Monospace', () => {
const family = (slug: string, value: string, description?: string) =>
(
new FigmaVariablesMapper().map({
collections: [
{
name: 'Typography',
modes: [{ id: 'm', name: 'Value' }],
variables: [
{
id: slug,
name: `Font-Families/${value}`,
type: 'STRING',
codeSyntax: { WEB: `var(--wp--preset--font-family--${slug})` },
description,
valuesByMode: { m: value },
},
],
},
],
} as never).theme.settings as Json
).typography.fontFamilies[0].fontFamily;
const system = 'ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace';

expect(family('monospace', 'Monospace', `Code (default). CSS stack: ${system}`)).toBe(system);
// 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');
});

it('writes only the font roles that exist, with no accent when there is none', () => {
const role = (slug: string, value: string) => ({
id: slug,
Expand Down Expand Up @@ -519,6 +554,56 @@ describe('FigmaVariablesMapper', () => {
);
});

it('maps content and wide width to settings.layout in px', () => {
const width = (id: string, syntax: string, value: unknown, type = 'FLOAT') => ({
id,
name: `Desktop/${id}`,
type,
codeSyntax: { WEB: `var(${syntax})` },
valuesByMode: { m: value },
});
const layout = (...variables: ReturnType<typeof width>[]) =>
new FigmaVariablesMapper().map({
collections: [{ name: 'Theme - Layout', modes: [{ id: 'm', name: 'Mode 1' }], variables }],
} as never);

// The form site-to-design-tokens writes.
const custom = layout(
width('content', '--wp--custom--layout--content-size', 848),
width('wide', '--wp--custom--layout--wide-size', 1232)
);
expect((custom.theme.settings as Json).layout).toEqual({
contentSize: '848px',
wideSize: '1232px',
});
expect((custom.theme.settings as Json).custom).toBeUndefined();
expect(custom.report.counts.layout).toBe(2);

// Core's own variable names, and string values with and without a unit.
const core = layout(
width('content', '--wp--style--global--content-size', '48rem', 'STRING'),
width('wide', '--wp--style--global--wide-size', '1200', 'STRING')
);
expect((core.theme.settings as Json).layout).toEqual({
contentSize: '48rem',
wideSize: '1200px',
});

// A layout width that isn't a length is reported, not written.
const bad = layout(width('content', '--wp--custom--layout--content-size', true, 'BOOLEAN'));
expect((bad.theme.settings as Json).layout).toBeUndefined();
expect(bad.report.warnings.join('\n')).toContain('"Desktop/content" is BOOLEAN');

// A custom value that aliases a width refers to core's variable.
const alias = layout(width('content', '--wp--custom--layout--content-size', 848), {
...width('gutter', '--wp--custom--max-text', 0),
valuesByMode: { m: { type: 'VARIABLE_ALIAS', id: 'content' } },
});
expect((alias.theme.settings as Json).custom['max-text']).toBe(
'var(--wp--style--global--content-size)'
);
});

it('gives custom lengths a unit and refuses unsafe or clashing paths', () => {
const variable = (id: string, syntax: string, value: number) => ({
id,
Expand Down
100 changes: 90 additions & 10 deletions skills/figma-to-block-theme/scripts/figma-variables-to-theme-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,38 @@ interface CustomTarget {
path: string[];
}

/** Content and wide width, which belong in `settings.layout`. */
interface LayoutTarget {
kind: 'layout';
key: 'contentSize' | 'wideSize';
}

type Target = PresetTarget | CustomTarget | LayoutTarget;

/** Keys that would reach Object.prototype if written as plain properties. */
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);

const PRESET_PATTERN =
/--wp--preset--(color|spacing|font-size|font-family|border-radius|shadow)--([a-z0-9-]+)/;
const CUSTOM_PATTERN = /--wp--custom--([a-z0-9-]+(?:--[a-z0-9-]+)*)/;
/** `site-to-design-tokens` writes the custom form; core's own variables are the style form. */
const LAYOUT_PATTERN = /--wp--(?:custom--layout|style--global)--(content|wide)-size(?![a-z0-9-])/;
/** CSS generic font families, which name no font of their own. */
const GENERIC_FAMILIES = new Set([
'serif',
'sans-serif',
'monospace',
'cursive',
'fantasy',
'system-ui',
'ui-serif',
'ui-sans-serif',
'ui-monospace',
'ui-rounded',
'math',
'emoji',
'fangsong',
]);
const MIN_MODE_PATTERN = /^(mobile|min|small|sm)$/i;
const MAX_MODE_PATTERN = /^(desktop|max|large|lg)$/i;

Expand Down Expand Up @@ -134,6 +160,8 @@ export class FigmaVariablesMapper {
private warnings: string[] = [];
/** Variation keys that come from colour modes. */
private readonly colourModes = new Set<string>();
/** `settings.layout` widths found while mapping. */
private layout: JsonObject = {};

constructor(options: MapperOptions = {}) {
this.options = options;
Expand All @@ -142,6 +170,7 @@ export class FigmaVariablesMapper {

map(data: VariablesExport): MappingResult {
this.warnings = [];
this.layout = {};
this.colourModes.clear();
this.byId.clear();
for (const collection of data.collections) {
Expand Down Expand Up @@ -200,13 +229,17 @@ export class FigmaVariablesMapper {
this.assign(settings, ['shadow', 'defaultPresets'], false);
this.assign(settings, ['shadow', 'presets'], presets.shadow);
}
if (Object.keys(this.layout).length) {
settings.layout = this.layout;
}
if (Object.keys(custom).length) {
settings.custom = custom;
}

for (const [family, entries] of Object.entries(presets)) {
counts[family] = entries.length;
}
counts.layout = Object.keys(this.layout).length;
counts.custom = this.countLeaves(custom);
counts.variations = Object.keys(variations).length;

Expand Down Expand Up @@ -245,6 +278,11 @@ export class FigmaVariablesMapper {
continue;
}

if (target.kind === 'layout') {
this.mapLayout(variable, target, baseMode.id);
continue;
}

if (target.kind === 'custom') {
this.assign(custom, target.path, this.customValue(variable, baseMode.id, target.path));
if (target.path[0] === 'color') {
Expand Down Expand Up @@ -358,7 +396,7 @@ export class FigmaVariablesMapper {
return {
slug: target.slug,
name: value,
fontFamily: this.declaredStack(variable, value) ?? this.fontStack(value),
fontFamily: this.declaredStack(variable, value) ?? this.fontStack(value, target.slug),
};
case 'border-radius':
if (typeof value !== 'number') {
Expand All @@ -378,6 +416,19 @@ export class FigmaVariablesMapper {
}
}

/** Content and wide width go to `settings.layout` as CSS lengths. */
private mapLayout(variable: ExportedVariable, target: LayoutTarget, modeId: string): void {
const value = this.resolve(variable, modeId);
if (typeof value === 'number') {
this.layout[target.key] = this.px(value);
} else if (typeof value === 'string' && value.trim()) {
// A string such as "48rem" already has its unit; a bare number gets px.
this.layout[target.key] = /^\d+(\.\d+)?$/.test(value.trim()) ? `${value.trim()}px` : value;
} else {
this.typeMismatch(variable, 'FLOAT');
}
}

private customValue(variable: ExportedVariable, modeId: string, path: string[]): unknown {
const raw = variable.valuesByMode[modeId];

Expand All @@ -390,6 +441,10 @@ export class FigmaVariablesMapper {
if (presetTarget && presetTarget.kind === 'custom') {
return `var(--wp--custom--${presetTarget.path.join('--')})`;
}
if (presetTarget && presetTarget.kind === 'layout') {
const width = presetTarget.key === 'contentSize' ? 'content' : 'wide';
return `var(--wp--style--global--${width}-size)`;
}
}

const value = this.resolve(variable, modeId);
Expand Down Expand Up @@ -461,15 +516,16 @@ export class FigmaVariablesMapper {
return presets;
}

private parseTarget(
variable: ExportedVariable,
report = true
): PresetTarget | CustomTarget | undefined {
private parseTarget(variable: ExportedVariable, report = true): Target | undefined {
const syntax = variable.codeSyntax?.WEB;
const preset = syntax?.match(PRESET_PATTERN);
if (preset) {
return { kind: 'preset', family: preset[1], slug: preset[2] };
}
const layout = syntax?.match(LAYOUT_PATTERN);
if (layout) {
return { kind: 'layout', key: layout[1] === 'content' ? 'contentSize' : 'wideSize' };
}
const customMatch = syntax?.match(CUSTOM_PATTERN);
if (customMatch) {
return { kind: 'custom', path: customMatch[1].split('--') };
Expand Down Expand Up @@ -560,20 +616,44 @@ export class FigmaVariablesMapper {
* The exact CSS stack from a `CSS stack: ...` line in the variable description, used
* only when its first family is the font the mode's value names (other modes differ).
*/
/**
* Uses the fallbacks from a "CSS stack: …" description. The declared stack starts
* with the live site's own `@font-face` name (such as `argesta_displayregular`),
* which the new theme's `fontFace` entries won't declare, so the clean family name
* replaces it.
*/
private declaredStack(variable: ExportedVariable, name: string): string | undefined {
const stack = variable.description?.match(/CSS stack:\s*(.+)$/m)?.[1].trim();
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())) {
return stack;
}
const [first, ...fallbacks] = stack.split(',').map((part) => part.trim());
const plain = (text: string) => text.toLowerCase().replace(/[^a-z0-9]/g, '');
const first = plain(stack.split(',')[0]);
const face = plain(first);
const wanted = plain(name);
return first.startsWith(wanted) || wanted.startsWith(first) ? stack : undefined;
if (!face.startsWith(wanted) && !wanted.startsWith(face)) {
return undefined;
}
return [this.quoteFamily(name), ...fallbacks.filter(Boolean)].join(', ');
}

/** 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)) {
return generic;
}
const fallback =
slug === 'monospace' ? 'monospace' : (this.options.fontFallback ?? 'sans-serif');
return `${this.quoteFamily(family)}, ${fallback}`;
}

private fontStack(family: string): string {
const quoted = /\s/.test(family) ? `"${family}"` : family;
return `${quoted}, ${this.options.fontFallback ?? 'sans-serif'}`;
private quoteFamily(family: string): string {
return /\s/.test(family) ? `"${family}"` : family;
}

private typeMismatch(variable: ExportedVariable, expected: string): undefined {
Expand Down
2 changes: 1 addition & 1 deletion skills/site-to-design-tokens/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ npx tsx ${CLAUDE_SKILL_DIR}/scripts/propose-tokens.ts site-styles.json --out pro

The proposal follows the structure in [references/target-structure.md](references/target-structure.md):

- `base`, `contrast`, and `brand`, `primary`, `cta` and `neutral` ramps from 100 to 900, each built around a live colour that keeps its exact value
- `base`, `contrast`, and `neutral`, `primary`, `brand` and `cta` ramps from 100 to 900 (in that order), each built around a live colour that keeps its exact value
- the 44 semantic roles, taken from what elements use where the site shows it, and from the TSP defaults otherwise
- type, spacing, radius, shadow, layout and breakpoint scales, with Max (1440px) and Min (390px) values

Expand Down
Loading
Loading