mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-09-10 22:20:14 +00:00
initial code (#2)
* feat: initial code port from hyperframes-internal Port all OSS-ready packages from the internal monorepo: - @hyperframes/core — shared types, HTML generation, GSAP utilities, runtime - @hyperframes/cli — CLI for creating, previewing, and rendering compositions - @hyperframes/engine — framework-agnostic rendering engine (BeginFrame + FFmpeg) - @hyperframes/producer — video rendering pipeline (Puppeteer + FFmpeg) - @hyperframes/ui-player — browser-based video player component - @hyperframes/studio — composition editor (React frontend + Hono backend) Includes regression test suite with Docker-based test harness. All HeyGen-internal references, deployment infrastructure, and proprietary assets have been removed. Package names migrated from @app/* to @hyperframes/*. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: scrub internal codenames and stale references from OSS port - Replace static.heygen.ai runtime URLs in test fixtures - Remove internal CDN publish script (publish-hyperframe-runtime.ts) - Replace sandbox-studio, sandbox-interceptor, __magicEditRuntime with neutral names (studio, hyperframe-runtime, __hyperframeRuntime) - Fix stale Vault API / localhost references in docs - Remove broken deprecated_studio link Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: remove remaining internal codenames and stale references - Delete stale producer README.md and PIPELINE.md (referenced nonexistent files) - Replace "Cerberus" codename with "HyperFrames" in test design reviews - Replace magic-edit postMessage identifiers with hf-preview/hf-parent - Rename debug-magic-edit-timeline.ts to debug-timeline.ts - Replace "Motion Cut" with "HyperFrames" in Timeline comments - Fix studio/CLI references to nonexistent archive package (use local data/projects/ dir, stub render proxy) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- 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
10621e7903
commit
9f8e5ba5a1
@@ -0,0 +1,83 @@
|
||||
export type RuntimeMediaClip = {
|
||||
el: HTMLVideoElement | HTMLAudioElement;
|
||||
start: number;
|
||||
mediaStart: number;
|
||||
duration: number;
|
||||
end: number;
|
||||
volume: number | null;
|
||||
};
|
||||
|
||||
export function refreshRuntimeMediaCache(params?: { resolveStartSeconds?: (element: Element) => number }): {
|
||||
timedMediaEls: Array<HTMLVideoElement | HTMLAudioElement>;
|
||||
mediaClips: RuntimeMediaClip[];
|
||||
videoClips: RuntimeMediaClip[];
|
||||
maxMediaEnd: number;
|
||||
} {
|
||||
const mediaEls = Array.from(document.querySelectorAll("video[data-start], audio[data-start]")) as Array<
|
||||
HTMLVideoElement | HTMLAudioElement
|
||||
>;
|
||||
const mediaClips: RuntimeMediaClip[] = [];
|
||||
const videoClips: RuntimeMediaClip[] = [];
|
||||
let maxMediaEnd = 0;
|
||||
for (const el of mediaEls) {
|
||||
const start = params?.resolveStartSeconds
|
||||
? params.resolveStartSeconds(el)
|
||||
: Number.parseFloat(el.dataset.start ?? "0");
|
||||
if (!Number.isFinite(start)) continue;
|
||||
const mediaStart = Number.parseFloat(el.dataset.playbackStart ?? el.dataset.mediaStart ?? "0") || 0;
|
||||
let duration = Number.parseFloat(el.dataset.duration ?? "");
|
||||
if ((!Number.isFinite(duration) || duration <= 0) && Number.isFinite(el.duration) && el.duration > 0) {
|
||||
duration = Math.max(0, el.duration - mediaStart);
|
||||
}
|
||||
const end = Number.isFinite(duration) && duration > 0 ? start + duration : Number.POSITIVE_INFINITY;
|
||||
const volumeRaw = Number.parseFloat(el.dataset.volume ?? "");
|
||||
const clip: RuntimeMediaClip = {
|
||||
el,
|
||||
start,
|
||||
mediaStart,
|
||||
duration: Number.isFinite(duration) && duration > 0 ? duration : Number.POSITIVE_INFINITY,
|
||||
end,
|
||||
volume: Number.isFinite(volumeRaw) ? volumeRaw : null,
|
||||
};
|
||||
mediaClips.push(clip);
|
||||
if (el.tagName === "VIDEO") videoClips.push(clip);
|
||||
if (Number.isFinite(end)) maxMediaEnd = Math.max(maxMediaEnd, end);
|
||||
}
|
||||
return { timedMediaEls: mediaEls, mediaClips, videoClips, maxMediaEnd };
|
||||
}
|
||||
|
||||
export function syncRuntimeMedia(params: {
|
||||
clips: RuntimeMediaClip[];
|
||||
timeSeconds: number;
|
||||
playing: boolean;
|
||||
playbackRate: number;
|
||||
}): void {
|
||||
for (const clip of params.clips) {
|
||||
const { el } = clip;
|
||||
if (!el.isConnected) continue;
|
||||
const relTime = params.timeSeconds - clip.start + clip.mediaStart;
|
||||
const isActive = params.timeSeconds >= clip.start && params.timeSeconds < clip.end && relTime >= 0;
|
||||
if (isActive) {
|
||||
if (clip.volume != null) el.volume = clip.volume;
|
||||
try {
|
||||
el.playbackRate = params.playbackRate;
|
||||
} catch {
|
||||
// ignore unsupported playbackRate
|
||||
}
|
||||
if (Math.abs((el.currentTime || 0) - relTime) > 0.3) {
|
||||
try {
|
||||
el.currentTime = relTime;
|
||||
} catch {
|
||||
// ignore browser seek restrictions
|
||||
}
|
||||
}
|
||||
if (params.playing && el.paused) {
|
||||
void el.play().catch(() => {});
|
||||
} else if (!params.playing && !el.paused) {
|
||||
el.pause();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (!el.paused) el.pause();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user