Files
Miguel Ángel 9e87de9c5f refactor(core): simplify image-decode binder to a plain function
Addresses the simplify pass on #325:

- Replaced `createImageDecodeBinder` factory + interface + `size()`
  method with a plain `bindImageDecodes(ctx)` function. The factory
  wrapped a 20-LOC helper in a closure whose only benefit was test
  introspection — and that introspection was only ever the `size()`
  getter, which duplicates what `Set.size` on the caller-owned bound
  set already provides.
- The caller now owns the `bound` set. Production uses `WeakSet` so
  removed `<img>` elements can be garbage-collected; tests pass `Set`
  when they want `.has()` introspection. Earlier revision used `Set`
  unconditionally and claimed in a comment that this was fine because
  the bitmap cache evicts on its own — that reasoning was wrong, the
  `Set` entry keeps the whole DOM node GC-rooted.
- Listener cleanup uses an `AbortSignal` wired to the runtime's
  cleanup registry. `{ once: true }` alone only cleaned up after the
  event fired; if an `<img>` was removed before ever loading (common
  on sub-composition unmount), the listener closure leaked. The
  signal detaches the listener deterministically on runtime teardown.
- Dropped the `addEventListener` dependency injection. The only
  non-default caller was the test, and rewriting the test to assert
  against the stub's own `addEventListener` mock is simpler than
  threading an injection through the production path.
- Dropped the `tornDown` callback in favour of the signal — same
  purpose, one mechanism.
- Removed the `img.decoding !== "async"` guard. Setting a DOM string
  attribute to its existing value is a browser-level no-op; the check
  cost more than the assignment.
- Trimmed the file header and function JSDocs from ~30 lines to a
  tight 10-line block. The file header still explains the WHY; the
  inline comments explain subtle points at the call site.
- Test file slimmed from 9 verbose cases to 5 meaningful ones. The
  dropped cases were trivially asserting a single assignment
  (`decoding='async'`), collapsing duplicates ("binds multiple imgs"
  + "picks up new imgs" exercised the same path), and the
  swallowed-rejection case had no real assertion — its only
  verification was a comment claiming the `await Promise.resolve()`
  shape proved something.

No behaviour change in preview. 5/5 tests pass, typecheck clean.
2026-04-18 20:07:24 +01:00
..
2026-04-18 03:37:09 +00:00
2026-03-21 22:43:56 -07:00
2026-03-21 22:43:56 -07:00

@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