MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / createWaapiAdapter

Function createWaapiAdapter

packages/core/src/runtime/adapters/waapi.ts:4–230  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2import { swallow } from "../diagnostics";
3
4export function createWaapiAdapter(): RuntimeDeterministicAdapter {
5 let didDiscover = false;
6 let lastSeekTimeMs = 0;
7 let animateHookInstalled = false;
8 let hookedPrototype:
9 | (Element & {
10 animate?: Element["animate"];
11 __hfOriginalAnimate?: Element["animate"];
12 })
13 | undefined;
14 let originalAnimate: Element["animate"] | undefined;
15 let installedAnimate: Element["animate"] | undefined;
16 const animations = new Set<Animation>();
17 let baselines = new WeakMap<
18 Animation,
19 {
20 compositionTimeMs: number;
21 animationTimeMs: number;
22 }
23 >();
24
25 const snapshotAnimations = () => {
26 if (!document.getAnimations) return [];
27 try {
28 return document.getAnimations();
29 } catch {
30 return [];
31 }
32 };
33
34 const readAnimationTimeMs = (animation: Animation) => {
35 const raw = Number(animation.currentTime);
36 return Number.isFinite(raw) && raw > 0 ? raw : 0;
37 };
38
39 const normalizeInitialAnimationTimeMs = (animationTimeMs: number, compositionTimeMs: number) => {
40 if (compositionTimeMs <= 0) {
41 return animationTimeMs;
42 }
43
44 if (animationTimeMs >= compositionTimeMs) {
45 return Math.max(0, animationTimeMs - compositionTimeMs);
46 }
47
48 return animationTimeMs;
49 };
50
51 const ensureBaseline = (animation: Animation, compositionTimeMs: number) => {
52 const existing = baselines.get(animation);
53 if (existing) {
54 return existing;
55 }
56
57 const baseline = {
58 compositionTimeMs,
59 animationTimeMs: didDiscover
60 ? normalizeInitialAnimationTimeMs(readAnimationTimeMs(animation), compositionTimeMs)
61 : readAnimationTimeMs(animation),

Callers 3

waapi.test.tsFile · 0.90

Calls 8

swallowFunction · 0.90
installAnimateHookFunction · 0.85
trackAnimationsFunction · 0.85
snapshotAnimationsFunction · 0.85
ensureBaselineFunction · 0.85
inferAnimationEndSecondsFunction · 0.70
pauseMethod · 0.65
clearMethod · 0.45

Tested by 1