Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ 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))
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.
Original file line number Diff line number Diff line change
Expand Up @@ -554,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
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ 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',
Expand Down Expand Up @@ -150,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 @@ -158,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 @@ -216,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 @@ -261,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 @@ -394,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 @@ -406,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 @@ -477,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
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The proposal and the Figma script follow the TSP design system file (The Safari

| Collection | Modes | Holds | Code syntax |
| ------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Theme - Colour | Value | Primitives: `Theme/base`, `Theme/contrast`, `brand/100` … `900`, `primary/…`, `cta/…`, `neutral/…`, `system/<kind>/<foreground or background>`, `custom/overlay`, `shadow/<alpha>` | `--wp--preset--color--<slug>`; overlay and shadows `--wp--custom--color--…` |
| Theme - Colour | Value | Primitives: `Theme/base`, `Theme/contrast`, `neutral/100` … `900`, `primary/…`, `brand/…`, `cta/…` (in that order), `system/<kind>/<foreground or background>`, `custom/overlay`, `shadow/<alpha>` | `--wp--preset--color--<slug>`; overlay and shadows `--wp--custom--color--…` |
| Theme - Semantic | Value | Aliases of the primitives, by role | `--wp--custom--color--<role>--<name>` |
| Theme - Typography | Max, Min | `Sizes/<Name>`, `Font-Families/Primary` (heading), `Secondary` (body), `Tertiary` (accent, only with a third family) and `Monospace`, `Line-Heights/<Name>`, `Weights/<role>` | `--wp--preset--font-size--<slug>` (`100` … `900`), `--wp--preset--font-family--heading`, `body`, `accent` and `monospace`, `--wp--custom--line-height--<slug>`, `--wp--custom--font-weight--<role>` |
| Theme - Spacing | Max, Min | `Padding/None`, `Padding/XXS`, `Padding/XS` … `Padding/Colossal` | `--wp--preset--spacing--<slug>` (`5` … `100`) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('TokenPlanBuilder', () => {
expect(collection('Theme - Semantic').variables).toHaveLength(44);
});

it('creates the ramps in the LightSpeed palette order', () => {
const families = collection('Theme - Colour')
.variables.map((v) => v.name.split('/')[0])
.filter((family, i, all) => all.indexOf(family) === i);
expect(families.slice(0, 5)).toEqual(['Theme', 'neutral', 'primary', 'brand', 'cta']);
});

it('names and code syntax match the TSP file and the mapper', () => {
const colour = collection('Theme - Colour').variables;
expect(colour.find((v) => v.key === 'brand-600')).toMatchObject({
Expand Down
3 changes: 2 additions & 1 deletion skills/site-to-design-tokens/scripts/write-token-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export class TokenPlanBuilder {
values: { Value: rgba(p.colour.primitives.contrast) },
},
];
for (const family of ['brand', 'primary', 'cta', 'neutral'] as Family[]) {
// The LightSpeed palette order: neutral, primary, brand, cta.
for (const family of ['neutral', 'primary', 'brand', 'cta'] as Family[]) {
for (const step of RAMP_STEPS) {
const slug = `${family}-${step}`;
colour.push({
Expand Down
11 changes: 7 additions & 4 deletions skills/theme-orphaned-refs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect

## Workflow (sequential)

1. Load theme.json and build the preset registry for `color`, `font-family`, `font-size`, `spacing`, `shadow`, `gradient`, `duotone`.
2. Scan the theme in path order (root → subfolders) for:
1. Load theme.json and build the preset registry for `color`, `font-family`, `font-size`, `spacing`, `shadow`, `border-radius`, `gradient`, `duotone`.
2. Scan the theme's own files in path order (root → subfolders), skipping `node_modules`, `vendor`, `build`, `dist`, `coverage`, `.git`, `.agents`, `.claude` and `.github`, for:
- `var:preset|<type>|<slug>`
- `--wp--preset--<type>--<slug>`
3. For each reference whose slug is not defined in theme.json, replace it with the closest match.
Expand All @@ -24,6 +24,7 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect

- **Exact match**: keep as-is.
- **Numeric slugs** (e.g., `accent-4`): choose the nearest numeric slug with the same prefix from theme.json.
- **Bare numeric ladders** (font sizes `100`–`900`, radius `0`–`700`, spacing `5`–`100`): choose the nearest step. Check what the old value was for: a pill button radius belongs on `Round`, even when another step is nearer by size.
- **Accent/CTA/Brand 1–9**: map to `*-100`, `*-200`, etc. when present.
- **Font sizes by name**:
- `small` → `300`, `medium` → `400`, `large` → `500`, `x-large` → `600`, `xx-large` → `700` (fallback to nearest numeric).
Expand All @@ -36,9 +37,11 @@ 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 <theme-root> --report <path outside the theme>
```
python scripts/find_orphaned_presets.py --root <theme-root>
```

Add `--exclude <folder>` (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.

Expand Down
Loading
Loading