diff --git a/website/src/demo/export-key.ts b/website/src/demo/export-key.ts index 7e2535b9af..a10d754ad7 100644 --- a/website/src/demo/export-key.ts +++ b/website/src/demo/export-key.ts @@ -1,10 +1,13 @@ import type { RenderRequest } from '@schlessera/brain-ui-sdk/protocol'; -// Mermaid's monotonically numbered DOM IDs change with browsing order. Only -// those IDs and their references are canonicalized; content and styling remain -// part of the digest. Never substitute a vaguely similar document on a miss. +// Mermaid's monotonically numbered DOM IDs change with browsing order, and so +// do the static-export colour tokens named after them (`--bk-mermaid--…`, +// `staticMermaidSvg`). Only that render number is canonicalized; the token's +// pass and index, the content and the styling remain part of the digest. +// Never substitute a vaguely similar document on a miss. export function canonicalExport(request: RenderRequest) { - return JSON.stringify({ contentType: request.contentType, title: request.title || '', content: request.content.replace(/brain-mermaid-\d+/g, 'brain-mermaid-export') }); + const content = request.content.replace(/brain-mermaid-\d+/g, 'brain-mermaid-export').replace(/--bk-mermaid-\d+-/g, '--bk-mermaid-export-'); + return JSON.stringify({ contentType: request.contentType, title: request.title || '', content }); } export async function exportKey(request: RenderRequest) { const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonicalExport(request)));