text stringlengths 0 1.47k |
|---|
.viz-stat > :first-child { font-size: 12px; color: var(--muted-foreground); } |
.viz-stat-value { font-size: 1.4em; font-weight: 500; line-height: 1.2; } |
.viz-badge { |
display: inline-block; |
padding: 1px 8px; |
border-radius: 999px; |
background: color-mix(in oklab, var(--primary) 14%, transparent); |
color: var(--primary); |
font-size: 12px; |
} |
.form-label { display: block; font-size: 12px; color: var(--muted-foreground); margin-bottom: 4px; } |
.form-control, .form-select { |
width: 100%; |
padding: 5px 10px; |
border: 1px solid var(--border); |
border-radius: var(--radius); |
background: transparent; |
color: var(--foreground); |
font: inherit; |
} |
.form-check { display: flex; align-items: center; gap: 6px; } |
.form-check input { accent-color: var(--primary); } |
input[type='range'] { accent-color: var(--primary); } |
table { border-collapse: collapse; width: 100%; } |
th, td { text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--border); } |
th { font-weight: 500; color: var(--muted-foreground); font-size: 12px; } |
.table-responsive { overflow-x: auto; } |
`; |
const RESOURCE_SOURCES = [ |
"blob:", |
"data:", |
...[ |
"https://cdnjs.cloudflare.com", |
"https://cdn.jsdelivr.net", |
"https://esm.sh", |
"https://fonts.bunny.net", |
"https://fonts.googleapis.com", |
"https://fonts.gstatic.com", |
"https://unpkg.com" |
] |
].join(" "); |
/** The frame document's Content-Security-Policy. */ |
const FRAME_CSP = [ |
"default-src 'none'", |
`script-src 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' ${RESOURCE_SOURCES}`, |
`style-src 'unsafe-inline' ${RESOURCE_SOURCES}`, |
`img-src ${RESOURCE_SOURCES}`, |
`font-src ${RESOURCE_SOURCES}`, |
`media-src ${RESOURCE_SOURCES}`, |
"worker-src blob:", |
"connect-src blob: data:", |
"frame-src 'none'", |
"object-src 'none'", |
"base-uri 'none'", |
"form-action 'none'" |
].join("; "); |
/** Wire type of the frame→card height report message. */ |
const HEIGHT_MESSAGE_TYPE = "dsh-visualize:height"; |
/** Wire type of the card→frame streaming fragment update message. */ |
const STREAM_MESSAGE_TYPE = "dsh-visualize:stream"; |
/** |
* Assemble the complete srcdoc document for one visualization frame. |
* @param options - fragment, title, bridged palette, and report token. |
* @returns the HTML document string for the iframe's `srcDoc`. |
*/ |
function buildFrameDoc(options) { |
const rootVars = Object.entries(options.themeVars).map(([name, value]) => [name, sanitizeCssValue(value)]).filter(([, value]) => value.length > 0).map(([name, value]) => `--dsh-viz-${name}: ${value};`).join(" "); |
return `<!doctype html> |
<html lang="en"> |
<head> |
<meta charset="utf-8"> |
<meta name="viewport" content="width=device-width, initial-scale=1"> |
<meta name="referrer" content="no-referrer"> |
<meta http-equiv="Content-Security-Policy" content="${FRAME_CSP}"> |
<title>${escapeHtml(options.title)}</title> |
<style>${FRAME_CSS} |
:root { ${rootVars} color-scheme: ${options.colorScheme}; } |
body { padding: 4px 2px; }</style> |
</head> |
<body> |
${options.fragment} |
<script>${heightReporter(options.reportToken)}<\/script> |
</body> |
</html> |
`; |
} |
/** |
* The frame-side height reporter: posts the document's scroll height to the |
* parent on load and on every resize, so the card can size the iframe to its |
* content (a sandboxed frame's document is unreachable from the parent). |
* @param reportToken - correlation token echoed in each message. |
* @returns the inline script body. |
*/ |
function heightReporter(reportToken) { |
const token = JSON.stringify(reportToken); |
return ` |
(function () { |
var post = function () { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.