text
stringlengths
0
1.47k
next.innerHTML = data.fragment;
sync(root, next);
});
})();
`;
}
/**
* Keep one bridged palette value inert inside a style block: resolved
* computed-style colors never contain declaration or block delimiters, so any
* occurrence marks a malformed value, dropped rather than repaired.
* @param value - the raw computed-style value.
* @returns the trimmed value, or empty when it must be dropped.
*/
function sanitizeCssValue(value) {
const trimmed = value.trim();
return /[;{}<>]/u.test(trimmed) ? "" : trimmed;
}
/**
* Minimal HTML text escape for the frame `<title>`.
* @param text - raw text.
* @returns the escaped text.
*/
function escapeHtml(text) {
return text.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
}
//#endregion
//#region src/client/theme.ts
/**
* Host-theme resolution shared by the settled card and the streaming preview:
* reads the DSH `--dsw-alias-*` design tokens (whale-blue brand accent
* included) off `document.body` and derives the host color scheme. The body is
* the read point because DSH mounts the token definitions there (dark override
* under `body[data-ds-dark-theme]`), and custom properties only cascade
* DOWNWARD — a `:root`-mounted theme still reaches the body by inheritance,
* the reverse read never works. Missing tokens resolve to empty strings the
* shell drops, so the frame stylesheet's `light-dark()` fallbacks apply
* outside DSH.
*/
/** Host design token → frame variable bridge (values resolved per render). */
const TOKEN_BRIDGE = [
["foreground", "--dsw-alias-label-primary"],
["card", "--dsw-alias-bg-layer-1"],
["muted-foreground", "--dsw-alias-label-caption"],
["border", "--dsw-alias-border-l2"],
["primary", "--dsw-alias-brand-primary-new-colorprimary-new-color"],
["primary-foreground", "--dsw-alias-label-primary-inverted"]
];
/**
* Resolve the bridged palette and the host color scheme from computed style.
* @returns the palette map and scheme for {@link buildFrameDoc}.
*/
function resolveTheme() {
const computed = getComputedStyle(document.body);
const themeVars = {};
for (const [frameName, hostToken] of TOKEN_BRIDGE) themeVars[frameName] = computed.getPropertyValue(hostToken);
const scheme = computed.colorScheme;
return {
themeVars,
colorScheme: scheme.includes("dark") && !scheme.includes("light") ? "dark" : scheme.includes("light") && !scheme.includes("dark") ? "light" : document.body.hasAttribute("data-ds-dark-theme") ? "dark" : matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"
};
}
//#endregion
//#region src/client/VisualizeCard.tsx
/**
* The `visualize` toolview: renders the persisted fragment from the call's
* durable meta inside `<iframe sandbox="allow-scripts">` with the frame's own
* CSP. Replay-stable by construction — everything drawn derives from the
* logged call slice, never from the fragment file.
*
* Theme bridge: the card resolves the host's `--dsw-alias-*` design tokens
* (whale-blue brand accent included) at render time and injects them into the
* frame document as `--dsh-viz-*` variables; a mutation of the root element's
* attributes or an OS appearance flip re-resolves them, so the frame follows
* live theme switches. The frame body stays transparent to blend with the
* conversation surface.
*
* Height: a sandboxed frame's document is unreachable from the parent, so the
* frame posts its scroll height (tagged with this call's id) and the card
* sizes the iframe, capped per mode with internal scrolling past the cap.
*/
/** Iframe height bounds; content beyond the cap scrolls inside the frame. */
const MIN_HEIGHT = 48;
const HEIGHT_CAP = {
inline: 800,
wide: 1200
};
const headerStyle = {
display: "flex",
alignItems: "baseline",
gap: 8,
fontSize: 12,
opacity: .65,
margin: "2px 0 6px",
overflow: "hidden",
whiteSpace: "nowrap"
};
const frameStyle$1 = {
display: "block",
width: "100%",
border: 0,