mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-05 17:30:50 +00:00
Adds the parametrized-render primitive from hf#592 by reusing the existing
data-composition-variables schema as the source of declared defaults.
- Runtime helper window.__hyperframes.getVariables() (also exported from
@hyperframes/core) reads data-composition-variables defaults from the
document root and merges window.__hfVariables (CLI override) on top.
Returns Partial<T> for typed access; supports a generic for editor
ergonomics. Same code path runs in dev preview and at render time.
- CLI render --variables '<json>' / --variables-file <path> populates the
override. Mutually exclusive; fail-fast on conflicting flags, missing
file, unparseable JSON, or non-object payloads. parseVariablesArg is
exported as a pure function so validation paths stay unit-testable.
- Engine injects window.__hfVariables via evaluateOnNewDocument before
any page script runs, so the helper sees the merged values on its
first call. Empty payloads are skipped to avoid pointless init scripts.
- Producer threads variables through RenderConfig and into the engine's
CaptureOptions; Docker mode forwards --variables to the in-container
CLI invocation via dockerRunArgs.
Composition authors declare variables once on the root <html> element:
<html data-composition-variables='[
{"id":"title","type":"string","label":"Title","default":"Hello"}
]'>
and read them in any composition script:
const { title } = window.__hyperframes.getVariables();
A render with `--variables '{"title":"Q4 Report"}'` overrides the default
without modifying the composition source. Missing keys fall through to
the declared defaults, so dev preview and CLI renders without --variables
behave identically.
This is PR 1 of a 4-PR stack. Sub-comp per-instance scoping (carrying
host data-variable-values through the inlined sub-comp's getVariables()
call) lands in PR 2; schema validation and lint in PR 3; skill / scaffold
distribution in PR 4.
Tests: 9 new unit tests for getVariables() (jsdom), 11 new CLI tests
covering parseVariablesArg validation paths and Docker passthrough,
2 new dockerRunArgs assertions for the --variables flag. All existing
tests green (core 611, cli 208, engine 519).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
39 lines
1.3 KiB
TypeScript
39 lines
1.3 KiB
TypeScript
import { initSandboxRuntimeModular } from "./init";
|
|
import { fitTextFontSize } from "../text/fitTextFontSize";
|
|
import { getVariables } from "./getVariables";
|
|
|
|
type HyperframeWindow = Window & {
|
|
__hyperframeRuntimeBootstrapped?: boolean;
|
|
__hyperframes?: {
|
|
fitTextFontSize: typeof fitTextFontSize;
|
|
getVariables: typeof getVariables;
|
|
};
|
|
};
|
|
|
|
// Inline composition scripts can run before DOMContentLoaded.
|
|
// Ensure timeline registry exists at script evaluation time.
|
|
(window as HyperframeWindow).__timelines = (window as HyperframeWindow).__timelines || {};
|
|
|
|
// Expose runtime helpers immediately so composition scripts can use them
|
|
// before DOMContentLoaded (font sizing runs during script evaluation, and
|
|
// getVariables is read by composition setup before the timeline is built).
|
|
(window as HyperframeWindow).__hyperframes = {
|
|
fitTextFontSize,
|
|
getVariables,
|
|
};
|
|
|
|
function bootstrapHyperframeRuntime(): void {
|
|
const win = window as HyperframeWindow;
|
|
if (win.__hyperframeRuntimeBootstrapped) {
|
|
return;
|
|
}
|
|
win.__hyperframeRuntimeBootstrapped = true;
|
|
initSandboxRuntimeModular();
|
|
}
|
|
|
|
if (document.readyState === "loading") {
|
|
document.addEventListener("DOMContentLoaded", bootstrapHyperframeRuntime, { once: true });
|
|
} else {
|
|
bootstrapHyperframeRuntime();
|
|
}
|