mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-17 15:24:19 +00:00
refactor(studio): one preview mark with a value, preview or capture, instead of a second meta
This commit is contained in:
@@ -8,7 +8,7 @@ import {
|
||||
settleFirstFrameCompositionReadiness,
|
||||
} from "./compositionReadiness.js";
|
||||
import { createRuntimeStartTimeResolver } from "./runtime/startResolver.js";
|
||||
import { DEFER_MEDIA_META, STUDIO_PREVIEW_MARK_META } from "./studioPreviewMark.js";
|
||||
import { STUDIO_PREVIEW_MARK, STUDIO_PREVIEW_MARK_META } from "./studioPreviewMark.js";
|
||||
import { isRuntimeElementVisibleAt } from "./runtime/timeline.js";
|
||||
|
||||
function docWith(bodyHtml: string): Document {
|
||||
@@ -190,7 +190,9 @@ describe("mediaReadinessInput", () => {
|
||||
.appendChild(preview.createElement("meta"))
|
||||
.setAttribute("name", STUDIO_PREVIEW_MARK_META);
|
||||
const capture = docWith(html);
|
||||
capture.head.appendChild(capture.createElement("meta")).setAttribute("name", DEFER_MEDIA_META);
|
||||
const captureMark = capture.head.appendChild(capture.createElement("meta"));
|
||||
captureMark.setAttribute("name", STUDIO_PREVIEW_MARK_META);
|
||||
captureMark.setAttribute("content", STUDIO_PREVIEW_MARK.capture);
|
||||
const plain = docWith(html);
|
||||
const ids = (doc: Document) =>
|
||||
scanPendingCompositionAssets(doc, { scope: "all" }).pendingMedia.map((el) => el.id);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { HF_COLOR_GRADING_ATTR, serializeHfColorGrading } from "../colorGrading";
|
||||
import {
|
||||
DEFER_MEDIA_META,
|
||||
STUDIO_PREVIEW_MARK,
|
||||
STUDIO_PREVIEW_LAZY_ATTR,
|
||||
STUDIO_PREVIEW_MARK_META,
|
||||
} from "../studioPreviewMark";
|
||||
@@ -378,11 +378,11 @@ describe("runtime entry", () => {
|
||||
const loads: HTMLMediaElement[] = [];
|
||||
const spyLoad = () => {
|
||||
loads.length = 0;
|
||||
vi.spyOn(HTMLMediaElement.prototype, "load").mockImplementation(
|
||||
function (this: HTMLMediaElement) {
|
||||
loads.push(this);
|
||||
},
|
||||
);
|
||||
vi.spyOn(HTMLMediaElement.prototype, "load").mockImplementation(function (
|
||||
this: HTMLMediaElement,
|
||||
) {
|
||||
loads.push(this);
|
||||
});
|
||||
};
|
||||
const loadsOf = (...els: HTMLMediaElement[]) =>
|
||||
els.map((el) => loads.filter((loaded) => loaded === el).length);
|
||||
@@ -393,9 +393,12 @@ describe("runtime entry", () => {
|
||||
|
||||
it("loads a capture build's media only near its moment, while every image of a hidden clip stays shown", async () => {
|
||||
spyLoad();
|
||||
// What a capture build carries instead of the preview mark.
|
||||
// What a capture build carries: the mark, with the capture value.
|
||||
document.head.appendChild(
|
||||
Object.assign(document.createElement("meta"), { name: DEFER_MEDIA_META }),
|
||||
Object.assign(document.createElement("meta"), {
|
||||
name: STUDIO_PREVIEW_MARK_META,
|
||||
content: STUDIO_PREVIEW_MARK.capture,
|
||||
}),
|
||||
);
|
||||
const root = mountRoot();
|
||||
const [now, later] = videos(root, "0", "9");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
RUNTIME_STAMPED_ATTR,
|
||||
STUDIO_PREVIEW_MARK_META,
|
||||
STUDIO_PREVIEW_UPCOMING_ATTR,
|
||||
skipsImagesOfHiddenClips,
|
||||
} from "../studioPreviewMark";
|
||||
|
||||
// Hides timed non-media clips from script evaluation until the first visibility pass decides them;
|
||||
@@ -14,7 +14,6 @@ const PREVIEW_HIDE_UNTIL_FIRST_PASS = 'img[loading="lazy"] { display: none !impo
|
||||
const SKIP_ATTR = "data-hf-skip-hidden-images";
|
||||
export const SKIPPED_CLIP = `[data-start]:not(video, audio, img, [${STUDIO_PREVIEW_UPCOMING_ATTR}], [${RUNTIME_STAMPED_ATTR}])[style*="visibility: hidden"]`;
|
||||
const SKIP_HIDDEN_IMAGES = `${SKIPPED_CLIP} img { display: none !important; }`;
|
||||
const STUDIO_PREVIEW_MARK = `meta[name="${STUDIO_PREVIEW_MARK_META}"]`;
|
||||
export const CLIP_HIDDEN_ATTR = "data-hf-clip-hidden";
|
||||
const CONTENTS_ATTR = "data-hf-hidden-clip-contents";
|
||||
const HIDE_HIDDEN_CLIP_CONTENTS = `[${CLIP_HIDDEN_ATTR}][style*="visibility: hidden"] * { visibility: hidden !important; }`;
|
||||
@@ -48,7 +47,7 @@ export function hideTimedClipsUntilFirstPass(): void {
|
||||
if (typeof document === "undefined") return;
|
||||
const parent = document.head ?? document.documentElement;
|
||||
if (!parent) return;
|
||||
const preview = document.querySelector(STUDIO_PREVIEW_MARK) !== null;
|
||||
const preview = skipsImagesOfHiddenClips(document);
|
||||
if (preview && !skipsHiddenImages()) appendStyle(parent, SKIP_ATTR, SKIP_HIDDEN_IMAGES);
|
||||
if (!document.querySelector(`style[${CONTENTS_ATTR}]`))
|
||||
appendStyle(parent, CONTENTS_ATTR, HIDE_HIDDEN_CLIP_CONTENTS);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const STUDIO_PREVIEW_MARK_META = "hyperframes-studio-preview";
|
||||
/** Media deferral without the preview's image skipping: a capture's still loads only the media near its moment. */
|
||||
export const DEFER_MEDIA_META = "hyperframes-defer-media";
|
||||
/** The mark's content: Studio's own preview, or a capture build (a still shot right after a seek). */
|
||||
export const STUDIO_PREVIEW_MARK = { preview: "preview", capture: "capture" } as const;
|
||||
export const STUDIO_PREVIEW_UPCOMING_ATTR = "data-hf-upcoming";
|
||||
export const STUDIO_PREVIEW_LAZY_ATTR = "data-hf-preview-lazy";
|
||||
export const STUDIO_PREVIEW_ERRORS = "__hfPreviewErrors";
|
||||
@@ -21,8 +21,14 @@ export function applyAuthoredTiming(
|
||||
el.removeAttribute(RUNTIME_STAMPED_ATTR);
|
||||
}
|
||||
|
||||
/** Whether `doc` loads media only near the playhead: Studio's preview, or a capture build that asks for that alone. */
|
||||
const markOf = (doc: Document) =>
|
||||
doc.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`)?.getAttribute("content") ?? null;
|
||||
|
||||
/** Whether `doc` loads media only near the playhead: any marked page, the preview or a capture build. */
|
||||
export const defersMedia = (doc: Document): boolean =>
|
||||
doc.querySelector(
|
||||
`meta[name="${STUDIO_PREVIEW_MARK_META}"], meta[name="${DEFER_MEDIA_META}"]`,
|
||||
) !== null;
|
||||
doc.querySelector(`meta[name="${STUDIO_PREVIEW_MARK_META}"]`) !== null;
|
||||
|
||||
/** Whether `doc` skips hidden clips' images: the preview only (a mark without content is one); a capture keeps
|
||||
* every image eager, so a still right after a seek never shows a scene before its images. */
|
||||
export const skipsImagesOfHiddenClips = (doc: Document): boolean =>
|
||||
defersMedia(doc) && markOf(doc) !== STUDIO_PREVIEW_MARK.capture;
|
||||
|
||||
Reference in New Issue
Block a user