mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-04 07:19:52 +00:00
* refactor: split useTimelinePlayer.ts and hyperframes-player.ts into focused modules (<500 LOC each) * fix(ci): scope 500 LOC check to packages/studio, add allowlist for grandfathered files * feat(cli): Linux ARM64 support — auto-install Chromium on DGX Spark / GB10 / Jetson Chrome Headless Shell has no Linux ARM64 binary. On arm64 Linux: - Detects the platform automatically - Tries to auto-install system Chromium via apt-get (works on Ubuntu/Debian ARM) - Falls back to clear manual instructions with exact commands - 'hyperframes browser ensure' guides through the setup interactively - After setup, all render commands work without any flags * fix(ci): disable Windows Defender real-time monitoring to prevent EPERM builds Path exclusions are insufficient — Defender re-scans new files created during bun install before the exclusion takes effect. Disable real-time monitoring for the entire job duration instead (standard CI practice). * refactor(studio): split all files >500 LOC + extract useToast, delete allowlist All 11 large files split into focused modules under 500 LOC. App.tsx extracted toast logic into useToast hook (493 LOC now). .filesize-allowlist deleted — no longer needed. * fix: remove unused imports from split files, extract useToast from App.tsx App.tsx: 504 → 493 lines (toast logic extracted to useToast hook) timelineDOM.ts: remove unused imports from re-export pattern MotionPanel.tsx: remove unused clampStudioCustomEasePoints import studioMotionOps.ts: remove unused StudioGsapMotionDirection import * fix(ci): use Set-MpPreference to fully disable Windows Defender (both jobs) * fix(producer): use node --experimental-strip-types instead of tsx for build:fonts Eliminates the tsx binary dependency that Windows Defender locks during bun install, causing EPERM errors. Node 22.6+ strips TypeScript types natively with no external binary. * chore: remove .filesize-allowlist — App.tsx is now 493 lines (<500) * fix(ci): disable Windows Defender before checkout to prevent all EPERM races * fix(producer): skip build:fonts if fontData.generated.ts already exists The generated file is tracked in git, so CI doesn't need to regenerate it. This avoids @fontsource/inter node_modules access on Windows which triggers EPERM from Defender scanning during bun install.
133 lines
4.4 KiB
TypeScript
133 lines
4.4 KiB
TypeScript
/**
|
|
* Shader transition option types, constants, and pure helper functions for
|
|
* injecting shader capture scale and loading mode parameters into composition
|
|
* URLs and srcdoc HTML.
|
|
*/
|
|
|
|
export const SHADER_CAPTURE_SCALE_ATTR = "shader-capture-scale";
|
|
export const SHADER_LOADING_ATTR = "shader-loading";
|
|
export const SHADER_CAPTURE_SCALE_PARAM = "__hf_shader_capture_scale";
|
|
export const SHADER_LOADING_PARAM = "__hf_shader_loading";
|
|
|
|
export const SHADER_LOADING_PHRASES = [
|
|
"Preparing scene transitions",
|
|
"Sampling outgoing scene motion",
|
|
"Sampling incoming scene motion",
|
|
"Caching transition frames",
|
|
"Finalizing transition preview",
|
|
];
|
|
|
|
export type ShaderLoadingMode = "composition" | "player" | "none";
|
|
|
|
export interface ShaderTransitionState {
|
|
ready?: boolean;
|
|
progress?: number;
|
|
total?: number;
|
|
currentTransition?: number;
|
|
transitionTotal?: number;
|
|
transitionFrame?: number;
|
|
transitionFrames?: number;
|
|
phase?: "cached" | "capturing" | "finalizing";
|
|
loading?: boolean;
|
|
}
|
|
|
|
export function normalizeShaderCaptureScale(value: string | null): string | null {
|
|
if (value === null) return null;
|
|
const parsed = Number(value);
|
|
if (!Number.isFinite(parsed) || parsed <= 0) return null;
|
|
return String(Math.min(1, Math.max(0.25, parsed)));
|
|
}
|
|
|
|
export function normalizeShaderLoadingMode(value: string | null): ShaderLoadingMode {
|
|
if (value === null || value.trim() === "") return "composition";
|
|
const normalized = value.trim().toLowerCase();
|
|
if (
|
|
normalized === "none" ||
|
|
normalized === "false" ||
|
|
normalized === "0" ||
|
|
normalized === "off"
|
|
) {
|
|
return "none";
|
|
}
|
|
if (
|
|
normalized === "player" ||
|
|
normalized === "true" ||
|
|
normalized === "1" ||
|
|
normalized === "on"
|
|
) {
|
|
return "player";
|
|
}
|
|
return "composition";
|
|
}
|
|
|
|
function setQueryParam(params: URLSearchParams, key: string, value: string | null): void {
|
|
if (value === null) params.delete(key);
|
|
else params.set(key, value);
|
|
}
|
|
|
|
export function withShaderQueryParams(
|
|
src: string,
|
|
scale: string | null,
|
|
loadingMode: ShaderLoadingMode,
|
|
): string {
|
|
const hashIndex = src.indexOf("#");
|
|
const beforeHash = hashIndex >= 0 ? src.slice(0, hashIndex) : src;
|
|
const hash = hashIndex >= 0 ? src.slice(hashIndex) : "";
|
|
const queryIndex = beforeHash.indexOf("?");
|
|
const path = queryIndex >= 0 ? beforeHash.slice(0, queryIndex) : beforeHash;
|
|
const query = queryIndex >= 0 ? beforeHash.slice(queryIndex + 1) : "";
|
|
const params = new URLSearchParams(query);
|
|
setQueryParam(params, SHADER_CAPTURE_SCALE_PARAM, scale);
|
|
setQueryParam(params, SHADER_LOADING_PARAM, loadingMode === "composition" ? null : loadingMode);
|
|
const nextQuery = params.toString();
|
|
return `${path}${nextQuery ? `?${nextQuery}` : ""}${hash}`;
|
|
}
|
|
|
|
export function injectShaderOptionsIntoSrcdoc(
|
|
html: string,
|
|
scale: string | null,
|
|
loadingMode: ShaderLoadingMode,
|
|
): string {
|
|
if (scale === null && loadingMode === "composition") return html;
|
|
const lines: string[] = [];
|
|
if (scale !== null) lines.push(`window.__HF_SHADER_CAPTURE_SCALE=${JSON.stringify(scale)};`);
|
|
if (loadingMode !== "composition") {
|
|
lines.push(`window.__HF_SHADER_LOADING=${JSON.stringify(loadingMode)};`);
|
|
}
|
|
const script = `<script data-hyperframes-player-shader-options>${lines.join("")}</script>`;
|
|
if (/<head\b[^>]*>/i.test(html))
|
|
return html.replace(/<head\b[^>]*>/i, (match) => `${match}${script}`);
|
|
if (/<html\b[^>]*>/i.test(html))
|
|
return html.replace(/<html\b[^>]*>/i, (match) => `${match}${script}`);
|
|
return `${script}${html}`;
|
|
}
|
|
|
|
/**
|
|
* Convenience wrappers that read shader attributes directly from an element,
|
|
* avoiding boilerplate in the web component class body.
|
|
*/
|
|
|
|
export function getShaderModeFromElement(el: Element): ShaderLoadingMode {
|
|
return normalizeShaderLoadingMode(el.getAttribute(SHADER_LOADING_ATTR));
|
|
}
|
|
|
|
export function getShaderCaptureScaleFromElement(el: Element): number {
|
|
return Number(normalizeShaderCaptureScale(el.getAttribute(SHADER_CAPTURE_SCALE_ATTR)) ?? "1");
|
|
}
|
|
|
|
export function prepareSrcForElement(el: Element, src: string): string {
|
|
return withShaderQueryParams(
|
|
src,
|
|
normalizeShaderCaptureScale(el.getAttribute(SHADER_CAPTURE_SCALE_ATTR)),
|
|
getShaderModeFromElement(el),
|
|
);
|
|
}
|
|
|
|
export function prepareSrcdocForElement(el: Element, srcdoc: string): string {
|
|
return injectShaderOptionsIntoSrcdoc(
|
|
srcdoc,
|
|
normalizeShaderCaptureScale(el.getAttribute(SHADER_CAPTURE_SCALE_ATTR)),
|
|
getShaderModeFromElement(el),
|
|
);
|
|
}
|