Design tokens: carry preset defaults on upload, resolve them on download - #48
Merged
pbking merged 1 commit intoAug 30, 2026
Conversation
Pattern_Builder_Cloud_Tokens (client half of architecture §4a): - Upload: collect() scans serialized markup for every preset reference — named attributes, var:preset|… style paths, var(--wp--preset--…) custom properties, and derived has-… classes (generic support classes excluded) — and resolves each slug against this site's merged global settings (user > theme > core), fluid font sizes included. The porter bundles the result into the package automatically. - Download: the destination's definitions always win. Only missing tokens prompt — a modal lists them (swatches for colors) and asks once, for the batch, where to define them: Site styles (the theme's user Global Styles post; recommended, revertable in the editor) or the active theme's theme.json. Values are re-validated locally with the same strict grammar the service enforces before anything is written; the theme-JSON cache is busted after. - Proxy routes: POST /cloud/tokens/check (what's missing) and a tokenDestination parameter on /cloud/download; responses report tokensWritten and the UI confirms via snackbar. Verified live: a Twenty Twenty-Five pattern uploaded with 4 resolved tokens (fluid clamp() font size included), downloaded onto Twenty Twenty-Three — the modal offered exactly the two accent colors TT23 lacks (its own spacing/font-size definitions won), wrote them to the user palette, and the pattern imported. 9 new tests (112 total). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014jnurSGDDL9SPMcptRgB8U
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Contributor
Author
|
The failing Generated by Claude Code |
pbking
marked this pull request as ready for review
August 30, 2026 15:25
pbking
merged commit Aug 30, 2026
006803d
into
claude/pattern-builder-2-1-architecture-nwbvgz
1 check failed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #47 (its diff shows only token work; it retargets when #47 merges). Server half: Twenty-Bellows/patternbuilderwp.com#4.
Patterns reference theme presets by slug — a foreground color, a spacing step, a font size. This PR makes those references portable per the agreed semantics: the uploading site's values travel as defaults; the downloading site's own definitions always win; only missing tokens prompt the user for a home.
Upload — automatic
Pattern_Builder_Cloud_Tokens::collect()scans the serialized markup for every preset reference (named attributes,var:preset|…style paths,var(--wp--preset--…)custom properties, and derivedhas-…classes — generic support classes likehas-text-colorexcluded) and resolves each slug against this site's merged global settings (user customizations > theme.json > core defaults), fluid font sizes included viawp_get_typography_font_size_value(). The porter bundles the result into the package; nothing to ask.Download — destination wins; missing tokens ask once
Before a download runs, the flow checks the pattern's tokens against this site (
POST /cloud/tokens/check). Tokens the site already defines — any origin — are never touched: the pattern simply adopts the local look. Missing ones open a modal listing them (swatches for colors, values shown) with one batch choice of home:Values are re-validated locally with the same strict grammar the service enforces before anything is written (never trust the wire), the theme-JSON cache is busted, then the pattern imports as usual; the response reports
tokensWrittenand the UI confirms with a snackbar. Generated-pattern downloads go through the identical gate.Verified live (two-site loop)
A Twenty Twenty-Five pattern using
accent-2,accent-4,spacing|50, andx-largeuploaded with all four tokens resolved (including TT25's fluidclamp()font size); the service stored them and its preview renders with the source palette. Downloaded onto Twenty Twenty-Three: the modal offered exactly the two accent colors TT23 lacks — its own spacing/font-size definitions won silently — wrote them to the user palette on confirm, and the pattern imported rendering correctly.Testing
9 new PHPUnit tests (112 total, all green): every reference form extracted with support-classes excluded, resolution against injected theme data, unresolvable references dropped, missing-detection honoring existing origins, idempotent Global Styles writes that round-trip through
wp_get_global_settings(), theme.json writes + its two error paths, hostile wire values rejected, and porter export bundling. ESLint/PHPCS clean; build green.🤖 Generated with Claude Code
https://claude.ai/code/session_014jnurSGDDL9SPMcptRgB8U
Generated by Claude Code