mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-12 20:47:30 +00:00
* feat(catalog): add the seven 3D-motion pieces as installable registry blocks Each piece ships as a registry block with a CDN poster and preview, a live catalog detail page and its source. Scripts travel inside the catalog payload (shared vendor libraries fetched once, item scripts inline, the one HDR as a data URI) because the docs host only serves fonts, images and JSON. NO_ESSAY_COMMENTS_OK: the long comment blocks are in vendored libraries and the ported frost source under registry/blocks, not hand-written here. HF_MAX_NONLFS_KB=6000: four hosted texture PNGs under docs/public/catalog/items are runtime assets the docs host must serve as files. fallow skipped locally: it audits against origin/main and this branch is stacked on an older main. * chore(catalog): regenerate gallery data and nav after rebasing onto main * fix(catalog): read the install manifest through the bounded project reader * fix(catalog): a script the inliner missed fails the payload instead of shipping a dead URL * refactor(catalog): the leftover-script check reuses the reference finder * fix(catalog): frost and glass textures load from the CDN and the iteration presets are gone * chore(catalog): regenerate the frost and glass payloads and nav * fix(catalog): frost and glass textures are hosted through the registry url field, not hardcoded * chore(catalog): regenerate the frost and glass payloads against the hosted texture URLs * fix(catalog): the hosted-reference rewrite refuses a bare name it cannot safely replace * ci(catalog): verify changed catalog payloads in headless Chrome and check the docs catalog * feat(catalog): every item page follows the shared layout with a Tune panel and tabs * fix(catalog): let the texture-mask item host its masks so its tile plays live * chore(catalog): regenerate item pages, gallery data and the texture-mask payload * chore(catalog): regenerate item pages after merging main * fix(catalog): declared-only variables get the Tune panel, Code and Docs tabs capped * feat(catalog): give the blend-difference caption a demo scene so its tile plays live * chore(catalog): live payload for the blend-difference caption * perf(catalog): heavy 3d pieces compile and draw before ready, not on the first visible frame * feat(catalog): the avatar promo card hosts its videos, audio and fonts on the CDN * feat(catalog): the avatar promo card tile plays live from its CDN-hosted media * chore(catalog): the avatar promo card plays live, no allowlist left * chore(catalog): shorten two comment blocks * chore(catalog): trim first-party comment blocks to the comment-check limits * chore(catalog): shorten two frost source comments * fix(catalog): the Docs tab renders as prose again, and the detail page honours reduced motion Frame-mode pages carry no prose wrapper, and the detail component sat inside not-prose, so the Docs slot's headings, paragraphs, links and lists had no styling at all. The slots now carry their own prose classes and the chrome around them keeps not-prose. The recorded clip also gets the reduced-motion guard the docs-snippet check requires, and the generator reads stability from the source metadata type so the scripts typecheck passes. * fix(catalog): docs-tab paragraphs render as blocks Mintlify emits paragraphs as inline spans, so two paragraphs in the Docs slot ran together. * fix(ci): drop the duplicate docs_catalog job output git's line-based auto-merge silently duplicated the outputs key when main and this branch each added it on non-adjacent lines during the rebase; oxfmt's yaml parser rejects the repeated map key. * fix(catalog): close four CodeQL alerts in the frost source * chore(catalog): allowlist the avatar-promo-card CDN asset deletions, format sync-docs-catalog check-no-main-deletions.mjs was rejecting 11 local mp4/font files this branch already deleted in favor of CDN hosting; scripts/sync-docs-catalog.mjs had one line over the 100-col print width from an earlier edit in this branch. * fix(catalog): detail tabs use docs prose spacing, Install first; previews skip no-WebGPU runners * fix(catalog): the docs tab scrolls with the page instead of a capped inner box * refactor(catalog): split the payload asset and verify scripts into single-purpose helpers * refactor(catalog): split the preview generator into single-purpose helpers * ci(catalog): fail when the committed catalog differs from generator output The docs host serves the committed catalog and nothing regenerates it, so a stale copy shipped silently. The catalog payloads job now generates into a temp dir and compares it with the committed tree. * chore(catalog): regenerate docs/public/catalog with the refactored scripts One full regeneration from an empty output tree with the current scripts. The tree grows from 58.4 MB to 65.1 MB. Two hosted assets are about 2 MB each (an avatar png and a wav); the same bytes are already committed under assets/, so HF_MAX_NONLFS_KB is raised for this commit only. * fix(catalog): run the catalog script tests under the runner they are written for The rebase put three node:test files in the vitest half of test:scripts, where they report "No test suite found". They now sit in the node --test list. * fix(catalog): a WebGPU item without an adapter shows its recorded clip and says why * ci(catalog): the drift check runs from a committed fetch mirror with no network Generation now serves every font and CDN script fetch from scripts/catalog-fetch-mirror and fails when a fetch is not in it, even if the caller swallowed the error. CATALOG_FETCH_MIRROR=record refreshes the mirror from the live network. The docs_catalog filter also watches packages/core, packages/producer and the mirror, and the 13 re-hashed font files are listed in ALLOWED_DELETIONS. * chore(catalog): clean up the temp font cache and sort the mirror index without a locale * fix(catalog): hide Tune when the clip stands in, time out the adapter request, share one check * fix(catalog): the adapter probe survives a sync throw and a hang; test the clip guard * fix(catalog): keep the adapter probe inside the component, Mintlify evaluates only exports * fix(catalog): run the detail and page generator tests in CI; no Tune flash while probing WebGPU * docs(catalog): credit vendored libraries and make each SKILL.md list what the block installs CREDITS.md names every vendored dependency with its upstream and licence, and flags the two leaf textures whose origin is still to be confirmed. Each SKILL.md Files table now comes from the block manifest and its install and render paths point at compositions/<name>/. A test checks that every path a SKILL.md names is a manifest file that exists. * fix(catalog): a declared WebGPU item passes verify by its manifest tag, not by console wording verify-catalog-payloads forgave a missing adapter only by matching the markup and the message, which library-reported errors and widgets never satisfy. The webgpu tag in the item manifest is now the owner: a tagged item ignores its page and console errors, an untagged one gets no forgiveness, and a marker payload with no html is listed instead of crashing the run. * docs(catalog): correct the credits per block and guard the mount and render paths CREDITS.md states the three.js version and vendored-or-CDN status per block, adds d3-delaunay, Clipper on the CDN and the Google Fonts loads, and lists every texture with no known origin. The SKILL.md test now also checks the mount and render paths against the manifest composition. * test(catalog): read each block manifest once in the SKILL.md file test The two checks shared a copied manifest read, which fallow flagged as a clone with a high score. * fix(catalog): commit the hosted item files a gitignore rule kept out, and check git not the disk The compositions/ and *-ad/ ignore rules matched folder names under docs/public/catalog/items, so 33 hosted fonts, textures and marks were generated but never committed and would 404 on the docs host. The rules now have a negation for that tree and the files are added. The drift check read the checkout, where git-ignored files still exist, so it passed locally and failed only in CI. It now unpacks HEAD with git archive and compares that. * fix(catalog): a tile keeps its poster until the composition has painted * fix(catalog): a tagged WebGPU item forgives only the adapter-absent error, and test the wiring The manifest webgpu tag now decides whether an item may lack an adapter, and the error wording decides which lines are that absence. Any other page or console error on the item, and every failed request, still fails. The per-item decision is one exported function the tests drive, marker payloads are parsed by a tested helper, and the SKILL.md variable counts are checked against their tables (cuboid-carousel said forty-nine for forty). * fix(catalog): the pinned group's posters load eagerly at high priority * fix(catalog): type the tile reveal test so the scripts typecheck passes * fix(catalog): stop the adapter signature matching an unrelated failed adapter request failed to request .*adapter also matched errors about other adapters. It now matches only a request for the WebGPU adapter, so a tagged item cannot hide an unrelated failure behind it. * test(catalog): a tagged item still fails on an error about some other adapter * feat(catalog): the install command sits above the preview, as on the live catalog * fix(catalog): find the install slot through Mintlify's child wrapper * fix(docs): catalog copy buttons keep their size when the label swaps to Copied * refactor(docs): name the shown copy label once in the catalog copy button * fix(docs): primary catalog button keeps a readable label on hover and after copy * fix(docs): inset the catalog tab strip and tab content to match the boxed panels
364 lines
13 KiB
TypeScript
364 lines
13 KiB
TypeScript
/**
|
|
* The `?hfv=` round trip, end to end.
|
|
*
|
|
* A declared variable default leaves the explorer as a query parameter, passes
|
|
* through the preview wrapper, gets a src rewrite from the player, and is read
|
|
* back by the bootstrap the generator appends to the composition. Four hops,
|
|
* and a value has to survive all four byte-identical.
|
|
*
|
|
* It did not: the player re-serialized the whole query with `URLSearchParams`
|
|
* (form encoding, space -> `+`) while the bootstrap read it with
|
|
* `decodeURIComponent` (percent decoding, which leaves `+` alone), so
|
|
* "Ship it today" reached the page as "Ship+it+today" and an SVG `d` attribute
|
|
* full of spaces stopped parsing altogether.
|
|
*
|
|
* These tests run the actual emitted scripts and the actual player helper, so
|
|
* reintroducing either half of that mismatch fails them.
|
|
*/
|
|
import assert from "node:assert/strict";
|
|
import { readFileSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { describe, it } from "node:test";
|
|
import { fileURLToPath } from "node:url";
|
|
import { runInNewContext } from "node:vm";
|
|
import { prepareSrcForElement } from "../packages/player/src/shader-options.ts";
|
|
import {
|
|
mdxStringAttribute,
|
|
stageProps,
|
|
variableBootstrap,
|
|
variablePreviewWrapper,
|
|
} from "./generate-catalog-pages.ts";
|
|
|
|
const here = join(fileURLToPath(import.meta.url), "..");
|
|
|
|
/** The player as the catalog uses it: no shader attributes at all, so its only
|
|
* effect on a src is whatever it does to the query it was handed. */
|
|
const plainPlayer = { getAttribute: () => null } as unknown as Element;
|
|
|
|
const OWN_FILE = "svg-stroke-trace.html";
|
|
const WRAPPER_BASE = `../../components/svg-stroke-trace/${OWN_FILE}`;
|
|
|
|
/**
|
|
* Every character class this bug reaches. Spaces are the reported symptom; the
|
|
* rest are here so a fix that special-cases spaces cannot pass.
|
|
*/
|
|
const DECLARED: Record<string, string> = {
|
|
spaces: "Ship it today",
|
|
plus: "C++ and 1+1 and +1 555 010 0199",
|
|
ampersand: "a&b=c&d",
|
|
reserved: "50% off #1 ready? yes/no",
|
|
nonAscii: "café — naïve 東京 🎬",
|
|
quotes: 'he said "hi" and it\'s fine',
|
|
svgPath:
|
|
"M 92 328 C 178 142 292 138 366 276 C 430 396 500 414 558 262 C 622 94 724 112 786 274 C 836 406 894 376 930 194",
|
|
};
|
|
|
|
function scriptBody(html: string): string {
|
|
const match = /<script>([\s\S]*)<\/script>/.exec(html);
|
|
assert.ok(match, "expected exactly one inline <script>");
|
|
return match[1] ?? "";
|
|
}
|
|
|
|
function queryOf(url: string): string {
|
|
const index = url.indexOf("?");
|
|
return index >= 0 ? url.slice(index) : "";
|
|
}
|
|
|
|
/**
|
|
* Hop 1: the explorer's first load. Mirrors the one expression in
|
|
* docs/snippets/catalog-detail.jsx that builds it, which the last test in
|
|
* this file pins so the two cannot drift apart silently.
|
|
*/
|
|
function explorerQuery(values: Record<string, string>): string {
|
|
return `?hfv=${encodeURIComponent(JSON.stringify(values))}`;
|
|
}
|
|
|
|
/** Hop 2: the wrapper page, run for real. Returns the src it hands the player,
|
|
* either from its own URL or from an explorer message. */
|
|
function runWrapper(search: string, message?: Record<string, string>): string {
|
|
let src = "";
|
|
let onMessage: ((event: { origin: string; data: unknown }) => void) | null = null;
|
|
const player = {
|
|
ready: false,
|
|
currentTime: 0,
|
|
setAttribute: (name: string, value: string) => {
|
|
if (name === "src") src = value;
|
|
},
|
|
addEventListener: () => {},
|
|
seek: () => {},
|
|
play: () => {},
|
|
};
|
|
runInNewContext(scriptBody(variablePreviewWrapper(WRAPPER_BASE).join("\n")), {
|
|
URLSearchParams,
|
|
document: { getElementById: () => player },
|
|
location: { origin: "https://docs.test", search },
|
|
setInterval: () => 0,
|
|
clearInterval: () => {},
|
|
addEventListener: (
|
|
type: string,
|
|
handler: (event: { origin: string; data: unknown }) => void,
|
|
) => {
|
|
if (type === "message") onMessage = handler;
|
|
},
|
|
});
|
|
if (message) {
|
|
assert.ok(onMessage, "wrapper never registered a message listener");
|
|
(onMessage as (event: unknown) => void)({
|
|
origin: "https://docs.test",
|
|
data: { hfVariables: message },
|
|
});
|
|
}
|
|
return src;
|
|
}
|
|
|
|
/** Hop 4: the bootstrap the generator appends to the composition, run for real.
|
|
* Returns what a composition would actually read. */
|
|
function runBootstrap(search: string): {
|
|
fromWindow: unknown;
|
|
fromAttribute: unknown;
|
|
} {
|
|
const host = {
|
|
attributes: new Map<string, string>([["data-composition-src", `./${OWN_FILE}`]]),
|
|
getAttribute(name: string) {
|
|
return this.attributes.get(name) ?? null;
|
|
},
|
|
setAttribute(name: string, value: string) {
|
|
this.attributes.set(name, value);
|
|
},
|
|
};
|
|
const win: Record<string, unknown> = {};
|
|
runInNewContext(scriptBody(variableBootstrap(OWN_FILE)), {
|
|
URLSearchParams,
|
|
document: { querySelectorAll: () => [host] },
|
|
location: { search },
|
|
window: win,
|
|
});
|
|
const raw = host.getAttribute("data-variable-values");
|
|
// Re-parsed in this realm: the object the script built carries the vm realm's
|
|
// Object.prototype, which deepEqual counts as a difference all by itself.
|
|
const parsed = win.__hfVariables;
|
|
return {
|
|
fromWindow: parsed === undefined ? undefined : JSON.parse(JSON.stringify(parsed)),
|
|
fromAttribute: raw === null ? null : JSON.parse(raw),
|
|
};
|
|
}
|
|
|
|
/** A player build that form-encodes the whole query, which is what every
|
|
* already-published @hyperframes/player on the CDN does. The reader has to
|
|
* survive it, because the docs load the player from a CDN and cannot wait for
|
|
* a release. */
|
|
function formEncodingPlayer(src: string): string {
|
|
const index = src.indexOf("?");
|
|
if (index < 0) return src;
|
|
return `${src.slice(0, index)}?${new URLSearchParams(src.slice(index + 1)).toString()}`;
|
|
}
|
|
|
|
describe("hfv round trip", () => {
|
|
const assertDeclaredSurvives = (demoSrc: string): void => {
|
|
const read = runBootstrap(queryOf(demoSrc));
|
|
assert.deepEqual(read.fromWindow, DECLARED);
|
|
assert.deepEqual(read.fromAttribute, DECLARED);
|
|
};
|
|
|
|
it("carries every declared value through all four hops unchanged", () => {
|
|
assertDeclaredSurvives(prepareSrcForElement(plainPlayer, runWrapper(explorerQuery(DECLARED))));
|
|
});
|
|
|
|
it("survives a player build that form-encodes the query", () => {
|
|
assertDeclaredSurvives(formEncodingPlayer(runWrapper(explorerQuery(DECLARED))));
|
|
});
|
|
|
|
it("carries an edited value in from the explorer's message", () => {
|
|
const edited = { ...DECLARED, spaces: "Make it happen" };
|
|
const demoSrc = prepareSrcForElement(plainPlayer, runWrapper("", edited));
|
|
assert.deepEqual(runBootstrap(queryOf(demoSrc)).fromWindow, edited);
|
|
});
|
|
|
|
for (const [name, value] of Object.entries(DECLARED)) {
|
|
it(`keeps ${name} byte-identical`, () => {
|
|
const one = { [name]: value };
|
|
const demoSrc = prepareSrcForElement(plainPlayer, runWrapper(explorerQuery(one)));
|
|
const read = runBootstrap(queryOf(demoSrc));
|
|
assert.deepEqual(read.fromWindow, one);
|
|
});
|
|
}
|
|
|
|
it("leaves the composition alone when no values are passed", () => {
|
|
assert.equal(runWrapper(""), WRAPPER_BASE);
|
|
assert.deepEqual(runBootstrap(""), { fromWindow: undefined, fromAttribute: null });
|
|
});
|
|
});
|
|
|
|
describe("player src rewriting", () => {
|
|
it("hands the composition its query back byte-identical", () => {
|
|
const src = "demo.html?hfv=%7B%22a%22%3A%22one%20two%22%7D&keep=a%20b%2Bc#frag";
|
|
assert.equal(prepareSrcForElement(plainPlayer, src), src);
|
|
});
|
|
});
|
|
|
|
describe("explorer producer", () => {
|
|
it("still posts the values in the message the wrapper listens for", () => {
|
|
const source = readFileSync(
|
|
join(here, "..", "docs", "snippets", "catalog-detail.jsx"),
|
|
"utf-8",
|
|
);
|
|
assert.match(source, /postMessage\(\{ hfVariables: values \}/);
|
|
});
|
|
});
|
|
|
|
describe("mdxStringAttribute", () => {
|
|
it("emits a plain double-quoted string, not an expression", () => {
|
|
assert.equal(
|
|
mdxStringAttribute("title", "beat-freeze-cut.html"),
|
|
'title="beat-freeze-cut.html"',
|
|
);
|
|
});
|
|
|
|
it("escapes the characters that would end the string or open an expression", () => {
|
|
assert.equal(
|
|
mdxStringAttribute("title", 'say "hi" & <b>{x}</b>'),
|
|
'title="say "hi" & <b>{x}</b>"',
|
|
);
|
|
});
|
|
|
|
it("leaves backticks alone inside the quoted value", () => {
|
|
assert.equal(mdxStringAttribute("title", "`code`"), 'title="`code`"');
|
|
});
|
|
|
|
it("passes backslashes through unchanged, since JSX strings do not treat them as escapes", () => {
|
|
assert.equal(mdxStringAttribute("title", "a\\b"), 'title="a\\b"');
|
|
});
|
|
});
|
|
|
|
describe("WebGPU stage fallback props", () => {
|
|
const page = (name: string) =>
|
|
readFileSync(join(here, "..", "docs", "catalog", "blocks", `${name}.mdx`), "utf-8");
|
|
|
|
it("gives a live WebGPU item its recorded clip, poster and the webgpu flag", () => {
|
|
const mdx = page("frost-sequence-camera-orbit");
|
|
assert.match(mdx, /^ {2}previewSrc=/m);
|
|
assert.match(mdx, /^ {2}video=".*frost-sequence-camera-orbit\.mp4"/m);
|
|
assert.match(mdx, /^ {2}poster=/m);
|
|
assert.match(mdx, /^ {2}webgpu$/m);
|
|
});
|
|
|
|
it("leaves a live item that does not need WebGPU without a recorded fallback", () => {
|
|
const mdx = page("ai-chat-reveal");
|
|
assert.match(mdx, /^ {2}previewSrc=/m);
|
|
assert.doesNotMatch(mdx, /^ {2}(video=|webgpu$)/m);
|
|
});
|
|
});
|
|
|
|
describe("WebGPU adapter probe", () => {
|
|
const source = readFileSync(join(here, "..", "docs", "snippets", "catalog-detail.jsx"), "utf-8");
|
|
const fn = source.slice(
|
|
source.indexOf("const hasWebgpuAdapter"),
|
|
source.indexOf("// END hasWebgpuAdapter"),
|
|
);
|
|
const probe = runInNewContext(`${fn} hasWebgpuAdapter`, { setTimeout, Promise }) as (
|
|
gpu: unknown,
|
|
ms: number,
|
|
) => Promise<boolean>;
|
|
|
|
it("says yes only for a real adapter", async () => {
|
|
assert.equal(await probe({ requestAdapter: async () => ({}) }, 50), true);
|
|
});
|
|
|
|
it("falls back for no gpu, a null adapter, a rejection, a sync throw and a hang", async () => {
|
|
const throws = () => {
|
|
throw new Error("blocked");
|
|
};
|
|
const cases = [
|
|
undefined,
|
|
{ requestAdapter: async () => null },
|
|
{ requestAdapter: () => Promise.reject(new Error("no")) },
|
|
{ requestAdapter: throws },
|
|
{ requestAdapter: () => new Promise(() => {}) },
|
|
];
|
|
for (const gpu of cases) assert.equal(await probe(gpu, 30), false);
|
|
});
|
|
});
|
|
|
|
describe("snippet scope", () => {
|
|
it("has no top-level helper outside its exports, because Mintlify only evaluates exports", () => {
|
|
const source = readFileSync(
|
|
join(here, "..", "docs", "snippets", "catalog-detail.jsx"),
|
|
"utf-8",
|
|
);
|
|
assert.deepEqual(source.match(/^(?:function|const|let|var|class) .*/gm), null);
|
|
});
|
|
});
|
|
|
|
describe("stageProps recorded-clip guard", () => {
|
|
const frost = JSON.parse(
|
|
readFileSync(
|
|
join(here, "..", "registry", "blocks", "frost-sequence-camera-orbit", "registry-item.json"),
|
|
"utf-8",
|
|
),
|
|
);
|
|
|
|
it("offers the recorded fallback only when the manifest has a clip", () => {
|
|
assert.ok(stageProps("block", frost).includes(" webgpu"));
|
|
assert.deepEqual(stageProps("block", { ...frost, preview: undefined }), []);
|
|
});
|
|
});
|
|
|
|
describe("tile reveal", () => {
|
|
const source = readFileSync(join(here, "..", "docs", "snippets", "catalog-gallery.jsx"), "utf-8");
|
|
const fn = source.slice(
|
|
source.indexOf("const revealWhenPainted"),
|
|
source.indexOf("// END revealWhenPainted"),
|
|
);
|
|
const frames: Array<() => void> = [];
|
|
const revealWhenPainted = runInNewContext(`${fn} revealWhenPainted`, {
|
|
requestAnimationFrame: (cb: () => void) => frames.push(cb),
|
|
}) as (player: unknown, reveal: () => void) => void;
|
|
const player = (assetsReady: boolean) => {
|
|
const target = new EventTarget();
|
|
return Object.assign(target, { assetsReady });
|
|
};
|
|
|
|
it("keeps the poster until assetsready plus one frame, not at runtime ready", () => {
|
|
frames.length = 0;
|
|
const p = player(false);
|
|
let revealed = 0;
|
|
revealWhenPainted(p, () => revealed++);
|
|
p.dispatchEvent(new Event("ready"));
|
|
assert.equal(revealed + frames.length, 0);
|
|
p.dispatchEvent(new Event("assetsready"));
|
|
assert.equal(revealed, 0);
|
|
frames.forEach((f) => f());
|
|
assert.equal(revealed, 1);
|
|
});
|
|
|
|
it("reveals after one frame when the assets were already settled", () => {
|
|
frames.length = 0;
|
|
let revealed = 0;
|
|
revealWhenPainted(player(true), () => revealed++);
|
|
frames.forEach((f) => f());
|
|
assert.equal(revealed, 1);
|
|
});
|
|
|
|
it("wires the reveal into the ready handler and not a bare data-ready flip", () => {
|
|
const handler = source.slice(
|
|
source.indexOf("addEventListener('ready'"),
|
|
source.indexOf("player.setAttribute('srcdoc'"),
|
|
);
|
|
assert.match(handler, /revealWhenPainted\(/);
|
|
assert.doesNotMatch(handler.split("revealWhenPainted")[0] ?? "", /dataset\.ready = 'true'/);
|
|
});
|
|
});
|
|
|
|
describe("tile poster priority", () => {
|
|
const source = readFileSync(join(here, "..", "docs", "snippets", "catalog-gallery.jsx"), "utf-8");
|
|
|
|
it("fetches the pinned group's posters eagerly at high priority and every other poster lazily", () => {
|
|
assert.match(
|
|
source,
|
|
/loading: eager \? "eager" : "lazy", fetchPriority: eager \? "high" : undefined/,
|
|
);
|
|
assert.match(source, /card\(item, group\.pinned === true\)/);
|
|
assert.doesNotMatch(source, /\.map\(card\)/);
|
|
});
|
|
});
|