mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-19 19:36:04 +00:00
fix(shader-transitions): address review — NaN guard, canvas sync, shared defaults
- Validate data-width/data-height: fall back to defaults if NaN or <= 0 - Sync existing #gl-canvas dimensions on reuse (if init called twice) - Import DEFAULT_WIDTH/DEFAULT_HEIGHT in capture.ts instead of hardcoding 1920/1080 in parameter defaults Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
c81ef50e2f
commit
a8f0752bf6
@@ -1,4 +1,5 @@
|
||||
import html2canvas from "html2canvas";
|
||||
import { DEFAULT_WIDTH, DEFAULT_HEIGHT } from "./webgl.js";
|
||||
|
||||
let patched = false;
|
||||
|
||||
@@ -29,8 +30,8 @@ export function initCapture(): void {
|
||||
export function captureScene(
|
||||
sceneEl: HTMLElement,
|
||||
bgColor: string,
|
||||
width: number = 1920,
|
||||
height: number = 1080,
|
||||
width: number = DEFAULT_WIDTH,
|
||||
height: number = DEFAULT_HEIGHT,
|
||||
): Promise<HTMLCanvasElement> {
|
||||
return html2canvas(sceneEl, {
|
||||
width,
|
||||
@@ -89,8 +90,8 @@ export function captureScene(
|
||||
export function captureIncomingScene(
|
||||
toScene: HTMLElement,
|
||||
bgColor: string,
|
||||
width: number = 1920,
|
||||
height: number = 1080,
|
||||
width: number = DEFAULT_WIDTH,
|
||||
height: number = DEFAULT_HEIGHT,
|
||||
): Promise<HTMLCanvasElement> {
|
||||
return new Promise<HTMLCanvasElement>((resolve, reject) => {
|
||||
const origZ = toScene.style.zIndex;
|
||||
|
||||
@@ -160,8 +160,10 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
|
||||
const root = document.querySelector<HTMLElement>("[data-composition-id]");
|
||||
const compId = config.compositionId || root?.getAttribute("data-composition-id") || "main";
|
||||
const compWidth = Number(root?.getAttribute("data-width") || DEFAULT_WIDTH);
|
||||
const compHeight = Number(root?.getAttribute("data-height") || DEFAULT_HEIGHT);
|
||||
const rawW = Number(root?.getAttribute("data-width"));
|
||||
const rawH = Number(root?.getAttribute("data-height"));
|
||||
const compWidth = Number.isFinite(rawW) && rawW > 0 ? rawW : DEFAULT_WIDTH;
|
||||
const compHeight = Number.isFinite(rawH) && rawH > 0 ? rawH : DEFAULT_HEIGHT;
|
||||
|
||||
// The Hyperframes engine injects a virtual-time shim (window.__HF_VIRTUAL_TIME__)
|
||||
// during render mode and composites every transition itself from the
|
||||
@@ -190,11 +192,13 @@ export function init(config: HyperShaderConfig): GsapTimeline {
|
||||
if (!glCanvas) {
|
||||
glCanvas = document.createElement("canvas");
|
||||
glCanvas.id = "gl-canvas";
|
||||
glCanvas.width = compWidth;
|
||||
glCanvas.height = compHeight;
|
||||
glCanvas.style.cssText = `position:absolute;top:0;left:0;width:${compWidth}px;height:${compHeight}px;z-index:100;pointer-events:none;display:none;`;
|
||||
glCanvas.style.cssText = `position:absolute;top:0;left:0;z-index:100;pointer-events:none;display:none;`;
|
||||
(root || document.body).appendChild(glCanvas);
|
||||
}
|
||||
glCanvas.width = compWidth;
|
||||
glCanvas.height = compHeight;
|
||||
glCanvas.style.width = `${compWidth}px`;
|
||||
glCanvas.style.height = `${compHeight}px`;
|
||||
|
||||
const gl = createContext(glCanvas, compWidth, compHeight);
|
||||
if (!gl) {
|
||||
|
||||
Reference in New Issue
Block a user