mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
* fix(docs): check catalog link values by type and isolate the preview A catalog page restores its variable values from the query string, so a shared link decides what the preview composition is given. Values from a link are now kept only when they fit the variable they name: a finite number, a boolean, one of an enum's options, a colour, an image address, or text with no angle brackets. Anything else opens at its default. The preview player now runs the composition with an opaque origin (sandbox-origin="opaque"), so a composition cannot reach the docs page. The bootstrap already drives the player only through its API and postMessage, and every docs asset is served with CORS, so playback, seek-on-remount and edits behave as before. chatgpt-exchange sets its editable text with textContent instead of building innerHTML from it. A new check, check:registry-innerhtml, fails any registry file that reads variables and adds markup writes; the files that do so today are listed with their current counts and may only go down. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(docs): keep a link's text out of copied commands until the reader sets it (#7785) A catalog page restores tuned values from its link, and the install command, the render command and the agent request carried those values as if the reader had typed them. The commands quote only for bash and zsh, and the agent request is pasted as the reader's own words. The page now tracks which variables the reader set on it. A value that only came with the link goes into a command when it is a number, a boolean, or short text of letters, digits, spaces and plain punctuation, and into the agent request only when it is a number, a boolean or one of the item's own options. A page opened with values from its link says so and offers "Reset to defaults", and the install command wraps instead of scrolling so the whole line is visible. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
4.6 KiB
JavaScript
103 lines
4.6 KiB
JavaScript
import { spawnSync } from "node:child_process";
|
|
import { readFileSync } from "node:fs";
|
|
import { join, resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
/**
|
|
* Registry files that read composition variables and still write markup with `innerHTML` and friends, with how
|
|
* many such writes each has today. A variable's value comes from whoever configures the item, including a docs
|
|
* link someone shares, so a value written as markup can add elements and run script. New files that read
|
|
* variables must set text with `textContent` or build nodes instead, and the files below may only lose writes.
|
|
* Lower a count, or delete the entry, when a file is converted.
|
|
*
|
|
* chatgpt-exchange's remaining writes are its own icons and layout; its variable text already goes through
|
|
* `textContent`.
|
|
*/
|
|
export const MARKUP_WRITE_BASELINE = new Map([
|
|
["registry/blocks/ai-chat-reveal/ai-chat-reveal.html", 2],
|
|
["registry/blocks/chatgpt-exchange/chatgpt-exchange.html", 4],
|
|
["registry/blocks/claude-exchange/claude-exchange.html", 6],
|
|
["registry/blocks/exploded-stack/exploded-stack.html", 1],
|
|
["registry/blocks/message-thread-reveal/message-thread-reveal.html", 1],
|
|
["registry/blocks/share-sheet-carousel/share-sheet-carousel.html", 1],
|
|
["registry/blocks/slack-notification-ad/slack-notification-ad.html", 1],
|
|
["registry/blocks/wireframe-portal-title/wireframe-portal-title.html", 1],
|
|
["registry/components/beat-timeline/beat-timeline.html", 1],
|
|
["registry/components/chat-message/chat-message.html", 2],
|
|
["registry/components/chat-thread/chat-thread.html", 4],
|
|
["registry/components/chat-thread/demo.html", 4],
|
|
["registry/components/cursor-context-menu/cursor-context-menu.html", 2],
|
|
["registry/components/cursor-marquee-select/cursor-marquee-select.html", 1],
|
|
["registry/components/multiplayer-cursors/multiplayer-cursors.html", 1],
|
|
["registry/components/notes-typing/demo.html", 1],
|
|
["registry/components/notes-typing/notes-typing.html", 1],
|
|
["registry/components/pan-stations/pan-stations.html", 2],
|
|
["registry/components/perspective-marquee/demo.html", 1],
|
|
["registry/components/perspective-marquee/perspective-marquee.html", 1],
|
|
["registry/components/screen-flow-carousel/screen-flow-carousel.html", 1],
|
|
["registry/components/scroll-feed/scroll-feed.html", 3],
|
|
["registry/components/social-proof-card/demo.html", 2],
|
|
["registry/components/social-proof-card/social-proof-card.html", 2],
|
|
["registry/components/sticky-mock-swap/sticky-mock-swap.html", 1],
|
|
]);
|
|
|
|
const READS_VARIABLES = /\bgetVariables\b|\b__hfVariables\b/;
|
|
const MARKUP_WRITE =
|
|
/\.(?:inner|outer)HTML\s*\+?=(?!=)|\binsertAdjacentHTML\s*\(|\bdocument\.write(?:ln)?\s*\(/g;
|
|
const SOURCE_FILE = /\.(?:html|js|mjs)$/;
|
|
|
|
/** How many markup writes `source` makes, or 0 when it reads no variables. */
|
|
export function markupWrites(source) {
|
|
if (!READS_VARIABLES.test(source)) return 0;
|
|
return source.match(MARKUP_WRITE)?.length ?? 0;
|
|
}
|
|
|
|
/** Files whose markup writes exceed their baseline (0 for a file not listed), sorted by path. */
|
|
export function findMarkupWriteGrowth(counts, baseline = MARKUP_WRITE_BASELINE) {
|
|
return [...counts]
|
|
.filter(([path, count]) => count > (baseline.get(path) ?? 0))
|
|
.map(([path, count]) => ({ path, count, allowed: baseline.get(path) ?? 0 }))
|
|
.sort((a, b) => a.path.localeCompare(b.path));
|
|
}
|
|
|
|
export function registrySourceFiles(cwd = process.cwd()) {
|
|
const result = spawnSync("git", ["ls-files", "-z", "registry"], { cwd, encoding: "utf8" });
|
|
if (result.error) throw result.error;
|
|
if (result.status !== 0) {
|
|
throw new Error(result.stderr.trim() || `git ls-files exited with status ${result.status}`);
|
|
}
|
|
return result.stdout
|
|
.split("\0")
|
|
.filter((path) => SOURCE_FILE.test(path) && !path.includes(".test."));
|
|
}
|
|
|
|
export function checkRegistryMarkupWrites(cwd = process.cwd()) {
|
|
const counts = new Map(
|
|
registrySourceFiles(cwd).map((path) => [
|
|
path,
|
|
markupWrites(readFileSync(join(cwd, path), "utf8")),
|
|
]),
|
|
);
|
|
return findMarkupWriteGrowth(counts);
|
|
}
|
|
|
|
function main() {
|
|
const grown = checkRegistryMarkupWrites();
|
|
if (grown.length === 0) {
|
|
console.log("Registry markup-write check passed.");
|
|
return;
|
|
}
|
|
console.error(
|
|
"Registry files that read variables write more markup than scripts/check-registry-innerhtml.mjs allows:",
|
|
);
|
|
for (const { path, count, allowed } of grown)
|
|
console.error(`- ${path}: ${count} (allowed ${allowed})`);
|
|
console.error(
|
|
"Set variable text with textContent, or build elements with createElement, instead of innerHTML.",
|
|
);
|
|
process.exitCode = 1;
|
|
}
|
|
|
|
const entryPath = process.argv[1] ? resolve(process.argv[1]) : null;
|
|
if (entryPath === fileURLToPath(import.meta.url)) main();
|