Files
hyperframes/packages/core/src/runtime/entry.ts
T
Miguel Ángel f312fca7e2 feat(producer): fail a render whose variables the page does not declare (#7548)
* feat(producer): fail a render whose variables the page does not declare

* chore(producer): keep the comment share and the dead-code audit clean for the variables check
2026-11-11 08:46:13 +00:00

107 lines
3.9 KiB
TypeScript

import { refreshSvgSelectorAliases } from "../compiler/svgSelectorAliases";
import { recordStartupError } from "./diagnostics";
import {
initSandboxRuntimeModular,
installAuthoredMediaCapture,
installFlatGsapTransforms,
} from "./init";
import { installAuthoredOpacityCapture } from "./colorGrading";
import { deferMediaUntilDue } from "./preloadMedia";
import { hideTimedClipsUntilFirstPass, keepInlineHideRulesForOlderShaders } from "./timedClipHide";
import { fitTextFontSize } from "../text/fitTextFontSize";
import { pretext } from "../text/pretext";
import { assetUrl } from "./assetUrl";
import { getDeclaredVariableSources, getVariables } from "./getVariables";
import { clearRuntimeData, registerRuntimeDataHandler, setRuntimeData } from "./runtimeData";
import { runScriptsAfterFonts } from "./afterFonts";
import { AFTER_FONTS_SCRIPTS } from "../compiler/scriptRuns";
import { hasFrameSources, registerFrameSource } from "./frameSources";
import { createFilmBridge } from "./filmBridge";
import { trackAcceleratedCanvases } from "./captureMotionBlur";
import { parkFarScenesAtBoot } from "./sceneWindow";
import { installPausedVideoCallbacks } from "./pausedVideoCallbacks";
type HyperframeWindow = Window & {
__hyperframeRuntimeBootstrapped?: boolean;
__hyperframes?: {
assetUrl: typeof assetUrl;
fitTextFontSize: typeof fitTextFontSize;
getVariables: typeof getVariables;
getDeclaredVariableSources: typeof getDeclaredVariableSources;
pretext: typeof pretext;
registerRuntimeDataHandler: typeof registerRuntimeDataHandler;
setRuntimeData: typeof setRuntimeData;
clearRuntimeData: typeof clearRuntimeData;
registerFrameSource: typeof registerFrameSource;
createFilmBridge: typeof createFilmBridge;
};
};
// Inline composition scripts can run before DOMContentLoaded.
// Ensure timeline registry exists at script evaluation time.
(window as HyperframeWindow).__timelines = (window as HyperframeWindow).__timelines || {};
// Stamp color-graded elements with their authored inline opacity BEFORE the
// composition's animation scripts (and the grading hide) mutate it — must run
// at script evaluation time, while the document is still parsing.
installAuthoredOpacityCapture();
installAuthoredMediaCapture();
installPausedVideoCallbacks();
installFlatGsapTransforms();
trackAcceleratedCanvases();
window.__hfHasFrameSources = hasFrameSources;
hideTimedClipsUntilFirstPass();
deferMediaUntilDue();
// 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 = {
assetUrl,
fitTextFontSize,
getVariables,
getDeclaredVariableSources,
pretext,
registerRuntimeDataHandler,
setRuntimeData,
clearRuntimeData,
registerFrameSource,
createFilmBridge,
};
function bootstrapHyperframeRuntime(): void {
const win = window as HyperframeWindow;
if (win.__hyperframeRuntimeBootstrapped) {
return;
}
win.__hyperframeRuntimeBootstrapped = true;
keepInlineHideRulesForOlderShaders();
initSandboxRuntimeModular();
}
// Compiled composition scripts wait for web fonts, so what they measure matches every run.
function startAfterCompositionScripts(): void {
try {
parkFarScenesAtBoot();
refreshSvgSelectorAliases();
const deferred = Array.from(document.querySelectorAll(AFTER_FONTS_SCRIPTS));
if (deferred.length === 0) bootstrapHyperframeRuntime();
else {
void runScriptsAfterFonts(deferred, bootstrapHyperframeRuntime).catch((err: unknown) => {
recordStartupError(err);
reportError(err);
});
}
} catch (err) {
recordStartupError(err);
throw err;
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", startAfterCompositionScripts, { once: true });
} else {
startAfterCompositionScripts();
}