Make var(--wsb-*) a first-class style value in the editor: - utils/tokens.ts: TokenKey, TOKEN_VARS (moved from html-export.ts, same order/content as the backend), COLOR_TOKENS palette order, tokenRef, isTokenRef, tokenKeyOf, resolveTokenValue and buildCanvasTokenCss, which defines the 16 vars + token base CSS scoped to .canvas-device-frame (never :root) with every value through cssValue(). - editor/CanvasTokenStyle.tsx: <style data-wsb-canvas-tokens> driven by useSiteDesign(), mounted in App inside SiteDesignProvider, so design edits recolour token-backed values on the canvas instantly. - panels/right/styles/TokenSwatchRow.tsx: palette-first swatch row that emits token references; .token-swatch styles appended to editor.css. - html-export.ts imports TOKEN_VARS; export output pinned byte-identical to the pre-move baseline by hash in html-export.test.ts. Refs #44 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
17 lines
772 B
TypeScript
17 lines
772 B
TypeScript
import React from 'react';
|
|
import { useSiteDesign } from '../state/SiteDesignContext';
|
|
import { buildCanvasTokenCss } from '../utils/tokens';
|
|
|
|
/**
|
|
* Defines the site's `--wsb-*` design-token variables on the editor canvas
|
|
* (scoped to `.canvas-device-frame`, never `:root`, so editor chrome is
|
|
* unaffected). Without it a component value of `var(--wsb-primary)` would
|
|
* render with no colour in the editor -- the published head defines the
|
|
* variables, the editor document otherwise does not. Re-renders on every
|
|
* design change, which is what makes token-backed values recolour instantly.
|
|
*/
|
|
export const CanvasTokenStyle: React.FC = () => {
|
|
const { design } = useSiteDesign();
|
|
return <style data-wsb-canvas-tokens="">{buildCanvasTokenCss(design)}</style>;
|
|
};
|