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:
@@ -23,7 +23,7 @@ import { join, parse } from "node:path";
|
||||
import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
||||
import {
|
||||
STUDIO_PREVIEW_ERRORS,
|
||||
DEFER_MEDIA_META,
|
||||
STUDIO_PREVIEW_MARK,
|
||||
STUDIO_PREVIEW_MARK_META,
|
||||
} from "@hyperframes/core/studio-preview-mark";
|
||||
import { AFTER_FONTS_SCRIPT_TYPE } from "@hyperframes/core/compiler";
|
||||
@@ -218,7 +218,7 @@ describe("registerPreviewRoutes", () => {
|
||||
const app = new Hono();
|
||||
registerPreviewRoutes(app, createAdapter(projectDir));
|
||||
const html = await (await app.request("http://localhost/projects/demo/preview")).text();
|
||||
const mark = html.indexOf(`<meta name="${STUDIO_PREVIEW_MARK_META}">`);
|
||||
const mark = html.indexOf(`<meta name="${STUDIO_PREVIEW_MARK_META}" content="preview">`);
|
||||
expect(mark).toBeGreaterThan(-1);
|
||||
expect(mark).toBeLessThan(html.indexOf("/api/runtime.js"));
|
||||
expect(html).toContain("<script data-hf-gsap-fallback>");
|
||||
@@ -282,7 +282,7 @@ describe("registerPreviewRoutes", () => {
|
||||
expect(previewWindow[STUDIO_PREVIEW_ERRORS]).toEqual(["Uncaught Error: GSAP could not load"]);
|
||||
});
|
||||
|
||||
it("serves a later scene's image lazy, and captures every image eager with only media deferred", async () => {
|
||||
it("serves a later scene's image lazy, and captures every image eager with the capture mark", async () => {
|
||||
const projectDir = createProjectDir();
|
||||
const later =
|
||||
'<!DOCTYPE html><html><head></head><body><div data-start="5"><img src="b.png"></div></body></html>';
|
||||
@@ -295,11 +295,12 @@ describe("registerPreviewRoutes", () => {
|
||||
const preview = await (await app.request(url)).text();
|
||||
const capture = await (await app.request(`${url}?${PREVIEW_CAPTURE_PARAM}=1`)).text();
|
||||
expect(preview, path).toMatch(/<img loading="lazy" [^>]*src="b.png">/);
|
||||
expect(preview, path).toContain(STUDIO_PREVIEW_MARK_META);
|
||||
const mark = (content: string) =>
|
||||
`<meta name="${STUDIO_PREVIEW_MARK_META}" content="${content}">`;
|
||||
expect(preview, path).toContain(mark(STUDIO_PREVIEW_MARK.preview));
|
||||
expect(capture, path).not.toContain("loading=");
|
||||
expect(capture, path).not.toContain(STUDIO_PREVIEW_MARK_META);
|
||||
expect(capture, path).toContain(`<meta name="${DEFER_MEDIA_META}">`);
|
||||
expect(preview, path).not.toContain(DEFER_MEDIA_META);
|
||||
expect(capture, path).toContain(mark(STUDIO_PREVIEW_MARK.capture));
|
||||
expect(capture, path).not.toContain(mark(STUDIO_PREVIEW_MARK.preview));
|
||||
expect(capture, path).toContain("<script data-hf-gsap-fallback>");
|
||||
}
|
||||
});
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
type BundleOptions,
|
||||
} from "@hyperframes/core/compiler";
|
||||
import {
|
||||
DEFER_MEDIA_META,
|
||||
STUDIO_PREVIEW_MARK,
|
||||
STUDIO_PREVIEW_MARK_META,
|
||||
STUDIO_PREVIEW_ERRORS,
|
||||
} from "@hyperframes/core/studio-preview-mark";
|
||||
@@ -321,7 +321,7 @@ function previewVariablesFromRequest(rawVariables: string | undefined):
|
||||
return { raw: rawVariables, values: parse.values };
|
||||
}
|
||||
|
||||
/** Captures screenshot right after a seek, so they get every image eager and no preview mark; their media still
|
||||
/** Captures screenshot right after a seek, so they get every image eager and the capture mark: their media still
|
||||
* loads only near the moment shot, or a long film's still would load every clip it has. */
|
||||
export const PREVIEW_CAPTURE_PARAM = "hf-capture";
|
||||
|
||||
@@ -329,6 +329,9 @@ export const PREVIEW_CAPTURE_PARAM = "hf-capture";
|
||||
const EARLY_ERRORS_SCRIPT = `<script>(function(){var seen=window.${STUDIO_PREVIEW_ERRORS}=[];
|
||||
addEventListener("error",function(e){seen.push(e.message||String(e))});})();</script>`;
|
||||
|
||||
const previewMark = (content: string) =>
|
||||
`<meta name="${STUDIO_PREVIEW_MARK_META}" content="${content}">`;
|
||||
|
||||
function injectStudioPreviewAugmentations(
|
||||
html: string,
|
||||
adapter: StudioApiAdapter,
|
||||
@@ -337,10 +340,10 @@ function injectStudioPreviewAugmentations(
|
||||
capture: boolean,
|
||||
): string {
|
||||
const marked = capture
|
||||
? injectTagsAtHeadStart(html, `<meta name="${DEFER_MEDIA_META}">`)
|
||||
? injectTagsAtHeadStart(html, previewMark(STUDIO_PREVIEW_MARK.capture))
|
||||
: injectTagsAtHeadStart(
|
||||
lazyPreviewImages(html),
|
||||
`<meta name="${STUDIO_PREVIEW_MARK_META}">${EARLY_ERRORS_SCRIPT}`,
|
||||
`${previewMark(STUDIO_PREVIEW_MARK.preview)}${EARLY_ERRORS_SCRIPT}`,
|
||||
);
|
||||
return injectStudioMotionScript(
|
||||
injectMotionPathPluginIfNeeded(
|
||||
|
||||
Reference in New Issue
Block a user