Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(palette): teach the canonical SVG var() form via style= (#1900)

Abraham8a36d7bbf102
diff --git a/packages/core/src/constants/preview-embed-starters.test.ts b/packages/core/src/constants/preview-embed-starters.test.ts
new file mode 100644
index 000000000..024598200
--- /dev/null
+++ b/packages/core/src/constants/preview-embed-starters.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, test } from 'bun:test';
+import { PREVIEW_EMBED_STARTERS } from './preview-embed-starters';
+
+const SVG_BLOCK_RE = /<svg\b[\s\S]*?<\/svg>/g;
+
+const PAINT_ATTRS = ['fill', 'stroke', 'color', 'stop-color', 'flood-color', 'lighting-color'];
+const PAINT_ATTR_RE = new RegExp(`\\b(${PAINT_ATTRS.join('|')})\\s*=\\s*"[^"]*var\\(`, 'i');
+
+describe('PREVIEW_EMBED_STARTERS — SVG paint-attribute hygiene (PRD-6760)', () => {
+ for (const starter of PREVIEW_EMBED_STARTERS) {
+ test(`${starter.id} — no var() in SVG paint-accepting presentation attributes`, () => {
+ const svgBlocks = starter.html.match(SVG_BLOCK_RE) ?? [];
+ for (const svg of svgBlocks) {
+ const match = svg.match(PAINT_ATTR_RE);
+ expect(
+ match,
+ match
+ ? `${starter.id}: ${match[0]} — route through style="${match[1]}: var(...)" instead`
+ : undefined,
+ ).toBeNull();
+ }
+ });
+ }
+
+ test('custom-svg starter still references the chart palette (visual smoke)', () => {
+ const customSvg = PREVIEW_EMBED_STARTERS.find((s) => s.id === 'custom-svg');
+ expect(customSvg).toBeDefined();
+ expect(customSvg?.html).toContain('var(--chart-1)');
+ expect(customSvg?.html).toContain('var(--border)');
+ expect(customSvg?.html).toContain('var(--foreground)');
+ });
+});
diff --git a/packages/core/src/constants/preview-embed-starters.ts b/packages/core/src/constants/preview-embed-starters.ts
index 4a15fa0ec..7189a6b21 100644
--- a/packages/core/src/constants/preview-embed-starters.ts
+++ b/packages/core/src/constants/preview-embed-starters.ts
@@ -47,12 +47,12 @@ const STAT_CARDS_HTML = `<div style="font-family:system-ui,sans-serif;padding:20
const CUSTOM_SVG_HTML = `<div style="font-family:system-ui,sans-serif;padding:20px;display:flex;align-items:center;gap:20px;color:var(--foreground)">
<svg width="120" height="120" viewBox="0 0 120 120" role="img" aria-label="70 percent complete">
- <circle cx="60" cy="60" r="46" fill="none" stroke="var(--border)" stroke-width="14" />
- <circle cx="60" cy="60" r="46" fill="none" stroke="var(--chart-1)" stroke-width="14"
+ <circle cx="60" cy="60" r="46" stroke-width="14" style="fill: none; stroke: var(--border)" />
+ <circle cx="60" cy="60" r="46" stroke-width="14"
stroke-linecap="round" stroke-dasharray="289" stroke-dashoffset="87"
- transform="rotate(-90 60 60)" />
+ transform="rotate(-90 60 60)" style="fill: none; stroke: var(--chart-1)" />
<text x="60" y="67" text-anchor="middle" font-size="22" font-weight="700"
- fill="var(--foreground)">70%</text>
+ style="fill: var(--foreground)">70%</text>
</svg>
<div>
<div style="font-weight:600;font-size:15px">Onboarding progress</div>
diff --git a/packages/server/src/mcp/tools/palette.ts b/packages/server/src/mcp/tools/palette.ts
index 5976d3e86..a83345853 100644
--- a/packages/server/src/mcp/tools/palette.ts
+++ b/packages/server/src/mcp/tools/palette.ts
@@ -16,7 +16,7 @@ export const DESCRIPTION = [
'Three sections:',
'- `components` — the **markdown-native forms** OK auto-promotes into themed canonical components at parse time. Write `> [!NOTE]` (not `<Callout>`), `<details>` (not `<Accordion>`), ` ```mermaid `, `$x$`. Each entry carries a copy-ready `example` + `guidance`.',
'- `embedPatterns` — copy-ready ` ```html preview ` starters (chart, stat cards, custom SVG, interactive control) already wired to the theme tokens, so an embed tracks light/dark with no hand-picked colors.',
- '- `tokens` — the CSS custom properties injected into every preview iframe; reference them as `var(--chart-1)`, `var(--foreground)`, … inside an `html preview` embed.',
+ '- `tokens` — the CSS custom properties injected into every preview iframe; reference them as `var(--chart-1)`, `var(--foreground)`, … inside an `html preview` embed. **Inside SVG, route theme tokens through `style="..."` rather than presentation attributes** — `<circle style="fill: var(--chart-1)">` works; `<circle fill="var(--chart-1)">` silently falls back to black in Safari / older Chromium because CSS `var()` is not a valid SVG `<paint>` value per the W3C spec.',
'',
'External resources load directly: the preview iframe has open network access, so an embed can load external stylesheets, `fetch` live data, or pull map tiles / remote images / web fonts over `https:`. The iframe is a sandboxed null-origin frame — an embed can reach the network but never the knowledge base, cookies, or auth.',
'',