mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-14 18:01:20 +08:00
b2755057d5
Real-AI-test log entry #11 from the heygen-showcase build: "My own regression: 2 lint errors after I edited beat-3 — root_missing_composition_id + root_missing_dimensions. I'd written a literal <video> token inside a CSS comment, which trips the linter's root-tag regex." Verified on a synthetic repro of the exact beat shape: <template> <style> /* The card uses <video> as the surface for the generated clip. */ .b3-root { ... } </style> <div data-composition-id="beat-3" data-width="1920" data-height="1080" ...> ... </div> </template> Before the fix, findRootTag scans the template's body for the first non-style/script tag. extractOpenTags's TAG_PATTERN regex (/<([a-z][\w:-]*)(\s[^<>]*?)?>/gi) matches `<video>` literally even when it sits inside CSS comment text inside a <style> block — the extractor never sees structure, only the byte stream. So it returns `<video>` as the first non-meta tag, the linter treats that as the composition root, and emits two cascading false errors: root_missing_composition_id (a CSS-comment <video> has no attrs) root_missing_dimensions (same) The fix masks comment / <style> / <script> RANGES out of bodyContent before tag extraction: - HTML comments: <!-- ... --> - <style> blocks: <style>...</style> (their content carries CSS comments that may contain literal tag tokens) - <script> blocks: <script>...</script> (same reasoning — template literals, string content, comments may carry tokens) Mask uses same-length space substitution so the returned tag's `.index` offset still points at the real position in the original source — no downstream rule that reads the source by offset is disturbed. Test coverage: - CSS-comment <video> inside <style>: root now correctly resolves to the real <div> (was: <video>). - HTML-comment <video> outside <style>: root resolves correctly. - Genuinely-broken root (no comments, missing attrs) still picks the broken <div> as root, so root_missing_* errors still fire correctly for real violations. - Well-formed beat (the user's heygen-showcase fix shape): root detected with all required attrs intact. All 18 existing core lint rule tests pass with the fix (`bun test src/lint/rules/core.test.ts` → 18 pass, 0 fail). Eliminates one of the four "biggest time sinks" the agent's factual log called out (the two self-inflicted beat-3 regressions caught only at verification — the <video>-in-comment case is now structurally prevented at the linter level instead of relying on the agent to remember landmine #6 from beat-builder-guide). The existing landmine #6 ("Don't include literal HTML opening tags inside HTML comments — linter regex false-positives") stays in the beat-builder doc as a backstop, but the structural fix here makes it defensive-in-depth rather than load-bearing.
@hyperframes/core
Types, parsers, generators, compiler, linter, runtime, and frame adapters for the Hyperframes video framework.
Install
npm install @hyperframes/core
Most users don't need to install core directly — the CLI, producer, and studio packages depend on it internally.
What's inside
| Module | Description |
|---|---|
| Types | TimelineElement, CompositionSpec, Asset, canvas dimensions, defaults |
| Parsers | parseHtml — extract timeline elements from HTML; parseGsapScript — parse GSAP animations |
| Generators | generateHyperframesHtml — produce valid Hyperframes HTML from a composition spec |
| Compiler | compileTimingAttrs — resolve data-start / data-duration into absolute times |
| Linter | lintHyperframeHtml — validate Hyperframes HTML (missing attributes, overlapping tracks, etc.) |
| Runtime | IIFE script injected into the browser — manages seek, media playback, and the window.__hf protocol |
| Frame Adapters | Pluggable animation drivers (GSAP, Lottie, CSS, or custom) |
Frame Adapters
A frame adapter tells the engine how to seek your animation to a specific frame:
import { createGSAPFrameAdapter } from "@hyperframes/core";
const adapter = createGSAPFrameAdapter({
getTimeline: () => gsap.timeline(),
compositionId: "my-video",
});
Implement FrameAdapter for custom animation runtimes:
import type { FrameAdapter } from "@hyperframes/core";
const myAdapter: FrameAdapter = {
id: "my-adapter",
getDurationFrames: () => 300,
seekFrame: (frame) => {
/* seek your animation */
},
};
Parsing and generating HTML
import { parseHtml, generateHyperframesHtml } from "@hyperframes/core";
const { elements, metadata } = parseHtml(htmlString);
const html = generateHyperframesHtml(spec);
Linting
import { lintHyperframeHtml } from "@hyperframes/core/lint";
const result = lintHyperframeHtml(htmlString);
// result.findings: { severity, message, elementId }[]
Documentation
Full documentation: hyperframes.heygen.com/packages/core
Related packages
@hyperframes/engine— rendering engine that drives the browser@hyperframes/producer— full render pipeline (capture + encode)hyperframes— CLI