mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-04 21:17:30 +00:00
html-in-canvas captures a few things wrongly, and a wrong blurred frame is worse than a sharp one. Add a defect list the runtime checks before it wraps a composition: a WebGL or WebGPU canvas (captured frozen), backface-hidden faces in a 3D context (drawn mirrored), an iframe (reloaded by the wrap and not recoverable), a transform or opacity below 1 on the root (ignored by the capture) and a canvas that is already a capture canvas (nesting hangs the renderer). Any hit turns blur off for the whole composition and the runtime says which one. The backface scan reads rules nested inside a style rule (CSS nesting), sheets pulled in with @import and adopted style sheets. Shadow DOM stays a documented limit. A face whose backface-visibility: hidden arrives through an animation counts too: the scan also takes the elements of running CSS or WAAPI animations that key it, and elements naming a @keyframes rule that does, as candidates. Support Chrome 157's html-in-canvas API alongside the older one: a canvas marked content="drawable" with a drawable attribute on captured children replaces layoutsubtree. Blur, the VFX runtime and Studio's browser check detect both through the new @hyperframes/core/html-in-canvas subpath. Folded review fixes: R14, R9 (the iframe defect entry). Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
30 lines
1.4 KiB
TypeScript
30 lines
1.4 KiB
TypeScript
/** Chrome <=155 marks a capture canvas with `layoutsubtree`; 157+ with `content="drawable"` and `drawable` on each captured child. */
|
|
export type HtmlInCanvasForm = "layoutsubtree" | "drawable";
|
|
|
|
export const CAPTURE_CANVAS_SELECTOR = 'canvas[layoutsubtree], canvas[content="drawable"]';
|
|
|
|
/** The form this browser's html-in-canvas takes, or null when it has no usable one. */
|
|
export function htmlInCanvasForm(win: Window = window): HtmlInCanvasForm | null {
|
|
const ctx = (win as Window & { CanvasRenderingContext2D?: { prototype: object } })
|
|
.CanvasRenderingContext2D?.prototype;
|
|
if (!ctx || !("drawElementImage" in ctx)) return null;
|
|
const canvas = win.document.createElement("canvas");
|
|
if (!("requestPaint" in canvas)) return null;
|
|
// 155 already has updateElementGeometry but still wants layoutsubtree, so this order matters.
|
|
if ("layoutSubtree" in canvas) return "layoutsubtree";
|
|
return "updateElementGeometry" in canvas ? "drawable" : null;
|
|
}
|
|
|
|
export function markCaptureCanvas(canvas: HTMLCanvasElement, form: HtmlInCanvasForm): void {
|
|
if (form === "layoutsubtree") canvas.setAttribute("layoutsubtree", "");
|
|
else canvas.setAttribute("content", "drawable");
|
|
}
|
|
|
|
export function markCaptured(el: Element, form: HtmlInCanvasForm): void {
|
|
if (form === "drawable") el.setAttribute("drawable", "");
|
|
}
|
|
|
|
export function unmarkCaptured(el: Element, form: HtmlInCanvasForm): void {
|
|
if (form === "drawable") el.removeAttribute("drawable");
|
|
}
|