mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-03 04:38:33 +00:00
Add @chenglou/pretext dependency and fitTextFontSize() utility that uses canvas measureText to compute the largest font size that fits text within a given width. Replaces character-count heuristics with actual font-aware measurement. - New fitTextFontSize() in @hyperframes/core/text, exposed on window.__hyperframes - Generalized for all text elements (captions, titles, etc.), not just captions - Unit tests (mocked pretext) + browser integration test (real Chromium canvas) - Updated captions skill docs with usage, exit guarantee, and self-lint patterns Co-authored-by: James <james.russo@heygen.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
import { readFileSync } from "node:fs";
|
|
import { resolve } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { loadHyperframeRuntimeSource } from "../src/inline-scripts/hyperframe";
|
|
|
|
function assert(condition: unknown, message: string): void {
|
|
if (!condition) {
|
|
throw new Error(message);
|
|
}
|
|
}
|
|
|
|
const runtimeSource = loadHyperframeRuntimeSource();
|
|
|
|
const requiredSnippets = [
|
|
"window.__player",
|
|
"window.__playerReady",
|
|
"window.__renderReady",
|
|
"hf-preview",
|
|
"hf-parent",
|
|
"renderSeek",
|
|
"__hyperframes",
|
|
"fitTextFontSize",
|
|
];
|
|
|
|
for (const snippet of requiredSnippets) {
|
|
assert(runtimeSource.includes(snippet), `Runtime contract snippet missing: ${snippet}`);
|
|
}
|
|
|
|
const scriptDir = resolve(fileURLToPath(new URL(".", import.meta.url)));
|
|
const manifestPath = resolve(scriptDir, "../dist/hyperframe.manifest.json");
|
|
try {
|
|
const manifestRaw = readFileSync(manifestPath, "utf8");
|
|
const manifest = JSON.parse(manifestRaw) as { artifacts?: { iife?: string; esm?: string } };
|
|
assert(Boolean(manifest.artifacts?.iife), "Manifest is missing iife artifact");
|
|
assert(Boolean(manifest.artifacts?.esm), "Manifest is missing esm artifact");
|
|
} catch {
|
|
// Build may not have run yet; contract-only checks above still provide signal.
|
|
}
|
|
|
|
console.log(
|
|
JSON.stringify({
|
|
event: "hyperframe_runtime_contract_verified",
|
|
requiredSnippetsChecked: requiredSnippets.length,
|
|
}),
|
|
);
|