@hyperframes/producer 0.9.81 → 0.9.83

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -324,7 +324,7 @@ function firstCompositionIdTag(html) {
324
324
  // src/services/renderOrchestrator.ts
325
325
  import { matchHtmlBodyCssHeightFirst, matchHtmlBodyCssWidthFirst } from "@hyperframes/parsers";
326
326
  import {
327
- extractMediaMetadata as extractMediaMetadata5,
327
+ extractMediaMetadata as extractMediaMetadata6,
328
328
  resolveConfig as resolveConfig2,
329
329
  closeCaptureSession as closeCaptureSession8,
330
330
  createCaptureSession as createCaptureSession8,
@@ -347,7 +347,7 @@ import {
347
347
  scaleProtocolTimeoutForComposition,
348
348
  classifyCaptureFailure as classifyCaptureFailure3,
349
349
  cloneCaptureWarning,
350
- isMemoryExhaustionError,
350
+ isMemoryExhaustionError as isMemoryExhaustionError2,
351
351
  isTransientBrowserError as isTransientBrowserError2,
352
352
  isDrawElementVerificationError,
353
353
  isDrawElementCaptureError,
@@ -2098,9 +2098,9 @@ var OWNER_FILE = "owner.json";
2098
2098
  var TRANSACTION_BACKUP = "backup";
2099
2099
  var RENDER_JOB_DIR = /^[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$/;
2100
2100
  function pidScope() {
2101
- const attempt = (read) => {
2101
+ const attempt = (read2) => {
2102
2102
  try {
2103
- return read();
2103
+ return read2();
2104
2104
  } catch {
2105
2105
  return void 0;
2106
2106
  }
@@ -7124,13 +7124,21 @@ import { parseHTML as parseHTML5 } from "linkedom";
7124
7124
  // src/services/bundledScripts.ts
7125
7125
  import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
7126
7126
  import { join as join17 } from "node:path";
7127
- import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
7127
+ import { GSAP_CDN_VERSION } from "@hyperframes/core/gsap-cdn";
7128
7128
  var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
7129
+ var DEFAULT_CDN_GSAP_3 = /^https:\/\/cdn\.jsdelivr\.net\/npm\/gsap@(3\.\d+\.\d+)\/dist\/([A-Za-z]+\.min\.js)$/;
7130
+ var read = (file) => existsSync8(file) ? readFileSync5(file) : null;
7129
7131
  function bundledScript(url) {
7130
7132
  const dir = process.env[GSAP_VENDOR_DIR_ENV];
7131
- if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
7132
- const file = join17(dir, "gsap.min.js");
7133
- return existsSync8(file) ? readFileSync5(file) : null;
7133
+ const [, version, file] = DEFAULT_CDN_GSAP_3.exec(url) ?? [];
7134
+ if (!dir || !version || !file) return null;
7135
+ const at = version === GSAP_CDN_VERSION ? dir : join17(dir, "..", "..", `gsap@${version}`, "dist");
7136
+ return read(join17(at, file));
7137
+ }
7138
+ function bundledGsapStandIn(url) {
7139
+ const dir = process.env[GSAP_VENDOR_DIR_ENV];
7140
+ const [, , file] = DEFAULT_CDN_GSAP_3.exec(url) ?? [];
7141
+ return dir && file ? read(join17(dir, file)) : null;
7134
7142
  }
7135
7143
 
7136
7144
  // src/services/htmlCompiler.ts
@@ -7156,7 +7164,7 @@ import { MAX_AUDIO_GAIN } from "@hyperframes/core/audio-gain";
7156
7164
  import { CAPTURE_CANVAS_SELECTOR } from "@hyperframes/core/html-in-canvas";
7157
7165
  import { readPlaybackRate } from "@hyperframes/parsers/media-duration";
7158
7166
  import { resolveRateSpec } from "@hyperframes/core/speed-ramp";
7159
- import { gsapCdnDist as gsapCdnDist2, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
7167
+ import { gsapCdnDist, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
7160
7168
  import {
7161
7169
  assignBundledRuntimeCompositionIds,
7162
7170
  assignMediaRenderIds,
@@ -8302,13 +8310,13 @@ function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8302
8310
  }
8303
8311
  function readSubCompositionFile(filePath, srcPath) {
8304
8312
  assertCompositionFileSize(filePath, srcPath);
8305
- const read = readProjectFile(filePath);
8306
- if (read.kind === "missing") return { detail: "the file does not exist" };
8307
- if (read.kind === "folder") return { detail: "it is a folder, not an HTML file" };
8308
- const validity = checkSubCompositionUsability(read.text, parseSubCompHtmlForValidity);
8313
+ const read2 = readProjectFile(filePath);
8314
+ if (read2.kind === "missing") return { detail: "the file does not exist" };
8315
+ if (read2.kind === "folder") return { detail: "it is a folder, not an HTML file" };
8316
+ const validity = checkSubCompositionUsability(read2.text, parseSubCompHtmlForValidity);
8309
8317
  if (!validity.ok)
8310
8318
  return { detail: validity.detail ?? "the file is empty or could not be parsed" };
8311
- return { bytes: Buffer.byteLength(read.text), ...compositionSrcsIn(read.text) };
8319
+ return { bytes: Buffer.byteLength(read2.text), ...compositionSrcsIn(read2.text) };
8312
8320
  }
8313
8321
  function assertSubCompositionsUsable(html, projectDir, assetRoot, outsideFiles) {
8314
8322
  const budget = new CompositionExpansionBudget();
@@ -8409,6 +8417,96 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
8409
8417
  function detectThreeDTransformUsage(html) {
8410
8418
  return THREE_D_CONTEXT_PATTERN.test(html);
8411
8419
  }
8420
+ var CSS_ESCAPE = /\\(?:[0-9a-fA-F]{1,6}[ \t\n\r\f]?|[^])?/y;
8421
+ function ancestorSelectorSteps(list) {
8422
+ const selectors = [];
8423
+ let steps = [];
8424
+ let combinators = [];
8425
+ let compound = "";
8426
+ let open2 = false;
8427
+ let combinator = null;
8428
+ const skipGroup = (at, close) => {
8429
+ let depth = 0;
8430
+ for (let i = at; i < list.length; i++) {
8431
+ const ch = list[i];
8432
+ if (ch === "\\") i++;
8433
+ else if (ch === '"' || ch === "'") {
8434
+ const end = list.indexOf(ch, i + 1);
8435
+ if (end < 0) return -1;
8436
+ i = end;
8437
+ } else if (ch === list[at]) depth++;
8438
+ else if (ch === close && --depth === 0) return i;
8439
+ }
8440
+ return -1;
8441
+ };
8442
+ const flush = () => {
8443
+ if (!open2) return;
8444
+ if ((combinator === "+" || combinator === "~") && steps.length > 0) {
8445
+ steps.pop();
8446
+ combinator = combinators.pop() ?? null;
8447
+ }
8448
+ steps.push({ compound: compound || "*", child: combinator === ">" });
8449
+ combinators.push(combinator);
8450
+ compound = "";
8451
+ open2 = false;
8452
+ combinator = null;
8453
+ };
8454
+ for (let i = 0; i <= list.length; i++) {
8455
+ const ch = list[i];
8456
+ if (ch === void 0 || ch === ",") {
8457
+ flush();
8458
+ if (steps.length) selectors.push(steps);
8459
+ steps = [];
8460
+ combinators = [];
8461
+ combinator = null;
8462
+ } else if (ch === "\\") {
8463
+ CSS_ESCAPE.lastIndex = i;
8464
+ const escape = CSS_ESCAPE.exec(list)[0];
8465
+ compound += escape;
8466
+ i += escape.length - 1;
8467
+ open2 = true;
8468
+ } else if (ch === "[") {
8469
+ const end = skipGroup(i, "]");
8470
+ if (end < 0) return null;
8471
+ compound += list.slice(i, end + 1);
8472
+ open2 = true;
8473
+ i = end;
8474
+ } else if (ch === ":") {
8475
+ while (/[:\w-]/.test(list[i + 1] ?? "")) i++;
8476
+ if (list[i + 1] === "(") i = skipGroup(i + 1, ")");
8477
+ if (i < 0) return null;
8478
+ open2 = true;
8479
+ } else if (/\s/.test(ch)) {
8480
+ flush();
8481
+ if (steps.length) combinator ??= " ";
8482
+ } else if (ch === ">" || ch === "+" || ch === "~") {
8483
+ flush();
8484
+ combinator = ch;
8485
+ } else if (ch === "(" || ch === ")" || ch === "]") {
8486
+ return null;
8487
+ } else {
8488
+ compound += ch;
8489
+ open2 = true;
8490
+ }
8491
+ }
8492
+ return selectors;
8493
+ }
8494
+ function matchesAnAncestor(steps, ancestors) {
8495
+ let reach = ancestors.map((el) => el.matches(steps[0].compound));
8496
+ for (const step of steps.slice(1)) {
8497
+ let above = false;
8498
+ const next = ancestors.map(() => false);
8499
+ for (let j = ancestors.length - 1; j >= 0; j--) {
8500
+ const placed = step.child ? reach[j + 1] === true : above;
8501
+ next[j] = placed && ancestors[j].matches(step.compound);
8502
+ above ||= reach[j];
8503
+ }
8504
+ reach = next;
8505
+ }
8506
+ return reach.includes(true);
8507
+ }
8508
+ var MAX_ROOT_ANCESTORS = 256;
8509
+ var MAX_ANCESTOR_SELECTOR_CHECKS = 1e5;
8412
8510
  function detectAncestorBackgroundImage(html) {
8413
8511
  const { document: document2 } = parseHTML5(html);
8414
8512
  const root = document2.querySelector("[data-composition-id]");
@@ -8418,6 +8516,8 @@ function detectAncestorBackgroundImage(html) {
8418
8516
  if (document2.documentElement && !ancestors.includes(document2.documentElement)) {
8419
8517
  ancestors.push(document2.documentElement);
8420
8518
  }
8519
+ if (ancestors.length > MAX_ROOT_ANCESTORS) return true;
8520
+ let selectorChecks = 0;
8421
8521
  for (const el of ancestors) {
8422
8522
  const style = el.getAttribute("style");
8423
8523
  if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
@@ -8427,14 +8527,14 @@ function detectAncestorBackgroundImage(html) {
8427
8527
  for (const { parts: rule } of cssRuleMatches(css)) {
8428
8528
  const [, selectorList, declarations] = rule;
8429
8529
  if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
8430
- for (const selector of selectorList.split(",")) {
8431
- const sel = selector.trim();
8432
- if (!sel || sel.startsWith("@")) continue;
8433
- if (/^(?:html|:root)$/i.test(sel)) return true;
8530
+ if (selectorList.trim().startsWith("@")) continue;
8531
+ const selectors = ancestorSelectorSteps(selectorList);
8532
+ if (!selectors) return true;
8533
+ for (const steps of selectors) {
8534
+ selectorChecks += steps.length * ancestors.length;
8535
+ if (selectorChecks > MAX_ANCESTOR_SELECTOR_CHECKS) return true;
8434
8536
  try {
8435
- for (const matched of document2.querySelectorAll(sel)) {
8436
- if (ancestors.includes(matched)) return true;
8437
- }
8537
+ if (matchesAnAncestor(steps, ancestors)) return true;
8438
8538
  } catch {
8439
8539
  }
8440
8540
  }
@@ -8683,11 +8783,11 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
8683
8783
  compiledSrcs.add(srcPath);
8684
8784
  assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
8685
8785
  assertCompositionFileSize(filePath, srcPath);
8686
- const read = readProjectFile(filePath);
8687
- if (read.kind !== "file") {
8786
+ const read2 = readProjectFile(filePath);
8787
+ if (read2.kind !== "file") {
8688
8788
  continue;
8689
8789
  }
8690
- const rawSubHtml = normalizeCompositionSrcs(read.text, projectDir);
8790
+ const rawSubHtml = normalizeCompositionSrcs(read2.text, projectDir);
8691
8791
  const nestedVisited = new Set(visited);
8692
8792
  nestedVisited.add(filePath);
8693
8793
  workItems.push({ srcPath, filePath, rawSubHtml, nestedVisited });
@@ -8889,9 +8989,9 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8889
8989
  assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
8890
8990
  assertCompositionFileSize(filePath, srcPath);
8891
8991
  }
8892
- const read = filePath && !isPrivateCompositionFile(projectDir, filePath) ? readProjectFile(filePath) : null;
8893
- return read?.kind === "file" ? rewriteUnresolvableGsapToCdn(
8894
- normalizeCompositionSrcs(read.text, projectDir),
8992
+ const read2 = filePath && !isPrivateCompositionFile(projectDir, filePath) ? readProjectFile(filePath) : null;
8993
+ return read2?.kind === "file" ? rewriteUnresolvableGsapToCdn(
8994
+ normalizeCompositionSrcs(read2.text, projectDir),
8895
8995
  projectDir,
8896
8996
  srcPath
8897
8997
  ) : null;
@@ -9118,6 +9218,9 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
9118
9218
  });
9119
9219
  const remote = new Set(externalScripts.filter((_, i) => !local[i]).map(({ src }) => src));
9120
9220
  assertRemoteFetchCount("scripts", remote.size);
9221
+ const pinned = new Set(
9222
+ externalScripts.filter(({ el }) => el.getAttribute("integrity")).map(({ src }) => src)
9223
+ );
9121
9224
  const mirror = operatorGsapMirror();
9122
9225
  const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
9123
9226
  const stop = new AbortController();
@@ -9140,7 +9243,16 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
9140
9243
  if (!bytes) {
9141
9244
  bytes = limit(async () => {
9142
9245
  fetchSignal.throwIfAborted();
9143
- const downloaded = await downloadScript(src, mirror, fetchSignal);
9246
+ const downloaded = await downloadScript(src, mirror, fetchSignal).catch(
9247
+ (error) => {
9248
+ const standIn = pinned.has(src) || fetchSignal.aborted ? null : bundledGsapStandIn(src);
9249
+ if (!standIn) throw error;
9250
+ defaultLogger.warn(
9251
+ `[Compiler] Could not download ${src} (${error}); using the host's own GSAP instead.`
9252
+ );
9253
+ return standIn;
9254
+ }
9255
+ );
9144
9256
  charge(downloaded.byteLength);
9145
9257
  return downloaded;
9146
9258
  }, fetchSignal);
@@ -9627,7 +9739,7 @@ async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = de
9627
9739
  }
9628
9740
  function renderGsapDist() {
9629
9741
  try {
9630
- return gsapCdnDist2(void 0, normalizeGsapBaseUrl(process.env.HYPERFRAMES_GSAP_BASE_URL));
9742
+ return gsapCdnDist(void 0, normalizeGsapBaseUrl(process.env.HYPERFRAMES_GSAP_BASE_URL));
9631
9743
  } catch (cause) {
9632
9744
  throw new Error(
9633
9745
  "Invalid HYPERFRAMES_GSAP_BASE_URL: use an absolute HTTPS npm mirror root (plain HTTP only for localhost) without credentials, query, or fragment",
@@ -10515,11 +10627,14 @@ import {
10515
10627
  compositionRequiresWebGpu,
10516
10628
  createCaptureSession as createCaptureSession4,
10517
10629
  deriveBeginFrameProbeTimeTicks,
10630
+ extractMediaMetadata as extractMediaMetadata4,
10518
10631
  getCompositionDuration,
10519
10632
  getCompositionLengthSource,
10520
10633
  initializeSession as initializeSession4,
10634
+ isMemoryExhaustionError,
10521
10635
  isTransientBrowserError,
10522
10636
  probeBeginFrameLiveness,
10637
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
10523
10638
  videoAudioId
10524
10639
  } from "@hyperframes/engine";
10525
10640
  import {
@@ -10624,6 +10739,33 @@ function hasVariableBoundMedia(html, variables, variablesByComp = {}) {
10624
10739
  );
10625
10740
  });
10626
10741
  }
10742
+ async function probeVideoHold(videos, html, projectDir, compiledDir) {
10743
+ const { document: document2 } = parseHTML6(html);
10744
+ const bound = /* @__PURE__ */ new Set();
10745
+ for (const video of document2.querySelectorAll("video")) {
10746
+ if (!video.matches("[data-var-src]") && !video.querySelector("source[data-var-src]")) continue;
10747
+ const id = video.getAttribute(MEDIA_RENDER_ID_ATTR2) || video.getAttribute("id");
10748
+ if (id) bound.add(id);
10749
+ }
10750
+ const hints = await Promise.all(
10751
+ videos.map(async ({ id, src }) => {
10752
+ if (bound.has(id) || /^https?:\/\//i.test(src)) return null;
10753
+ try {
10754
+ const path = resolveProjectRelativeSrc4(src, projectDir, compiledDir);
10755
+ const { width, height } = await extractMediaMetadata4(path);
10756
+ return width > 0 && height > 0 ? { id, width, height } : null;
10757
+ } catch {
10758
+ return null;
10759
+ }
10760
+ })
10761
+ );
10762
+ const held = hints.filter((hint) => hint !== null);
10763
+ return { skipReadinessVideoIds: held.map((hint) => hint.id), videoMetadataHints: held };
10764
+ }
10765
+ function probeHoldFitsCapture(probeHeld, captureHeld) {
10766
+ const held = new Set(captureHeld);
10767
+ return (probeHeld ?? []).every((id) => held.has(id));
10768
+ }
10627
10769
  function authoredMediaStarts(html) {
10628
10770
  const { document: document2 } = parseHTML6(html);
10629
10771
  const starts = /* @__PURE__ */ new Map();
@@ -10760,6 +10902,16 @@ function reportedLengthSource(source) {
10760
10902
  const srcHash = createHash7("sha256").update(name).digest("hex").slice(0, 12);
10761
10903
  return { from: "media", tag: source.tag, trimmed: source.trimmed, srcHash };
10762
10904
  }
10905
+ var STOPPED = "Preparing the render stopped while ";
10906
+ async function probeStep(step, call) {
10907
+ try {
10908
+ return await call();
10909
+ } catch (error) {
10910
+ if (error instanceof Error && !error.message.startsWith(STOPPED) && !isMemoryExhaustionError(error))
10911
+ error.message = `${STOPPED}${step}: ${error.message}`;
10912
+ throw error;
10913
+ }
10914
+ }
10763
10915
  async function runProbeStage(input) {
10764
10916
  const {
10765
10917
  projectDir,
@@ -10832,6 +10984,12 @@ async function runProbeStage(input) {
10832
10984
  assertNotAborted();
10833
10985
  const motionBlur = job.config.motionBlur;
10834
10986
  const captureOpts = {
10987
+ ...await probeVideoHold(
10988
+ composition.videos,
10989
+ compiled.html,
10990
+ projectDir,
10991
+ join23(workDir, "compiled")
10992
+ ),
10835
10993
  recordReferenceBackground: input.recordReferenceBackground,
10836
10994
  width,
10837
10995
  height,
@@ -10870,7 +11028,8 @@ async function runProbeStage(input) {
10870
11028
  log.info(`Still waiting for browser initialization... (${elapsed}s elapsed)`);
10871
11029
  }, 3e4);
10872
11030
  try {
10873
- await initializeSession4(probeSession);
11031
+ const opening = probeSession;
11032
+ await probeStep("opening the film in the browser", () => initializeSession4(opening));
10874
11033
  } finally {
10875
11034
  clearInterval(heartbeat);
10876
11035
  }
@@ -10949,7 +11108,8 @@ async function runProbeStage(input) {
10949
11108
  null,
10950
11109
  { ...probeCfg, forceScreenshot: true }
10951
11110
  );
10952
- await initializeSession4(probeSession);
11111
+ const reopening = probeSession;
11112
+ await probeStep("opening the film in the browser", () => initializeSession4(reopening));
10953
11113
  assertNotAborted();
10954
11114
  lastBrowserConsole = probeSession.browserConsoleBuffer;
10955
11115
  }
@@ -10957,8 +11117,13 @@ async function runProbeStage(input) {
10957
11117
  const session = probeSession;
10958
11118
  if (composition.duration <= 0) {
10959
11119
  log.info("Discovering composition duration...");
10960
- const discoveredDuration = await getCompositionDuration(session);
10961
- lengthSource = reportedLengthSource(await getCompositionLengthSource(session));
11120
+ const discoveredDuration = await probeStep(
11121
+ "reading the film's length",
11122
+ () => getCompositionDuration(session)
11123
+ );
11124
+ lengthSource = reportedLengthSource(
11125
+ await probeStep("reading the film's length", () => getCompositionLengthSource(session))
11126
+ );
10962
11127
  assertNotAborted();
10963
11128
  log.info("Probed composition duration from browser", {
10964
11129
  discoveredDuration,
@@ -10972,9 +11137,9 @@ async function runProbeStage(input) {
10972
11137
  });
10973
11138
  }
10974
11139
  if (compiled.unresolvedCompositions.length > 0) {
10975
- const resolutions = await resolveCompositionDurations(
10976
- session.page,
10977
- compiled.unresolvedCompositions
11140
+ const resolutions = await probeStep(
11141
+ "reading each scene's length",
11142
+ () => resolveCompositionDurations(session.page, compiled.unresolvedCompositions)
10978
11143
  );
10979
11144
  assertNotAborted();
10980
11145
  if (resolutions.length > 0) {
@@ -10994,7 +11159,10 @@ async function runProbeStage(input) {
10994
11159
  }
10995
11160
  }
10996
11161
  log.info("Discovering media assets from browser DOM...");
10997
- const browserMedia = await discoverMediaFromBrowser(session.page);
11162
+ const browserMedia = await probeStep(
11163
+ "listing the film's videos, audio and images",
11164
+ () => discoverMediaFromBrowser(session.page)
11165
+ );
10998
11166
  assertNotAborted();
10999
11167
  if (browserMedia.length > 0) {
11000
11168
  const existingVideoIds = new Set(composition.videos.map((v) => v.id));
@@ -11132,11 +11300,14 @@ async function runProbeStage(input) {
11132
11300
  log.info("Discovering audio volume automation...", {
11133
11301
  audioCount: composition.audios.length
11134
11302
  });
11135
- const automation = await discoverAudioVolumeAutomationFromTimeline(
11136
- session.page,
11137
- composition.audios.map((audio) => audio.id),
11138
- composition.duration,
11139
- fpsToNumber6(job.config.fps)
11303
+ const automation = await probeStep(
11304
+ "reading the audio's volume changes",
11305
+ () => discoverAudioVolumeAutomationFromTimeline(
11306
+ session.page,
11307
+ composition.audios.map((audio) => audio.id),
11308
+ composition.duration,
11309
+ fpsToNumber6(job.config.fps)
11310
+ )
11140
11311
  );
11141
11312
  assertNotAborted();
11142
11313
  if (automation.length > 0) {
@@ -11155,9 +11326,9 @@ async function runProbeStage(input) {
11155
11326
  log.info("Discovering video visibility windows...", {
11156
11327
  videoCount: composition.videos.length
11157
11328
  });
11158
- const visibilityWindows = await discoverVideoVisibilityFromTimeline(
11159
- session.page,
11160
- composition.duration
11329
+ const visibilityWindows = await probeStep(
11330
+ "finding when each video is on screen",
11331
+ () => discoverVideoVisibilityFromTimeline(session.page, composition.duration)
11161
11332
  );
11162
11333
  assertNotAborted();
11163
11334
  for (const win of visibilityWindows) {
@@ -11356,7 +11527,7 @@ import {
11356
11527
  createFrameLookupTable as createFrameLookupTable3,
11357
11528
  detectTransfer,
11358
11529
  extractAllVideoFrames,
11359
- extractMediaMetadata as extractMediaMetadata4,
11530
+ extractMediaMetadata as extractMediaMetadata5,
11360
11531
  gradingKeepsSdr as gradingKeepsSdr2,
11361
11532
  isVideoPastTimelineEnd,
11362
11533
  isHdrColorSpace as isHdrColorSpace2,
@@ -11370,7 +11541,7 @@ import {
11370
11541
  resolveRestrictPageNetwork,
11371
11542
  isUrlNotPermittedError,
11372
11543
  writeUrlDownloadTelemetry as writeUrlDownloadTelemetry2,
11373
- resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
11544
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc5,
11374
11545
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
11375
11546
  safeVideoExtractionSourceIdentity,
11376
11547
  videoAudioId as videoAudioId2
@@ -11586,7 +11757,7 @@ function applyVideoExtractionFailurePolicy(result, policy, log) {
11586
11757
  }
11587
11758
  async function probeColorSpaceSafely(path, log) {
11588
11759
  try {
11589
- const meta = await extractMediaMetadata4(path);
11760
+ const meta = await extractMediaMetadata5(path);
11590
11761
  return meta.colorSpace;
11591
11762
  } catch (error) {
11592
11763
  log?.warn("HDR color-space probe failed; treating source as SDR", {
@@ -11632,14 +11803,14 @@ async function runExtractVideosStage(input) {
11632
11803
  log?.info("Probing video color spaces...", { videoCount: composition.videos.length });
11633
11804
  const probeFailures = await Promise.all(
11634
11805
  composition.videos.map(async (v) => {
11635
- const videoPath = resolveProjectRelativeSrc4(v.src, projectDir, compiledDir);
11806
+ const videoPath = resolveProjectRelativeSrc5(v.src, projectDir, compiledDir);
11636
11807
  if (!opensLocally(videoPath, assetRoots)) return null;
11637
11808
  try {
11638
11809
  const attempted = extractionPolicy.maxTransientRetries === 0 ? {
11639
- result: await extractMediaMetadata4(videoPath, { signal: abortSignal }),
11810
+ result: await extractMediaMetadata5(videoPath, { signal: abortSignal }),
11640
11811
  retries: 0
11641
11812
  } : await runVideoExtractionWithRetry2(
11642
- () => extractMediaMetadata4(videoPath, { signal: abortSignal }),
11813
+ () => extractMediaMetadata5(videoPath, { signal: abortSignal }),
11643
11814
  {
11644
11815
  signal: abortSignal,
11645
11816
  maxTransientRetries: extractionPolicy.maxTransientRetries,
@@ -11676,7 +11847,7 @@ async function runExtractVideosStage(input) {
11676
11847
  if (probesHdr && composition.images.length > 0) {
11677
11848
  const probed = await Promise.all(
11678
11849
  composition.images.map(async (img) => {
11679
- const imgPath = resolveProjectRelativeSrc4(img.src, projectDir, compiledDir);
11850
+ const imgPath = resolveProjectRelativeSrc5(img.src, projectDir, compiledDir);
11680
11851
  if (!opensLocally(imgPath, assetRoots)) return null;
11681
11852
  const colorSpace = await probeColorSpaceSafely(imgPath, log);
11682
11853
  if (isHdrColorSpace2(colorSpace)) {
@@ -11811,7 +11982,7 @@ function opensLocally(path, assetRoots) {
11811
11982
  return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
11812
11983
  }
11813
11984
  function localProbeSource(src, input) {
11814
- const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
11985
+ const path = resolveProjectRelativeSrc5(src, input.projectDir, input.compiledDir);
11815
11986
  const readFrom = input.urlByAbsentLocalPath?.get(path) ?? path;
11816
11987
  const roots = input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(input.projectDir, input.compiledDir);
11817
11988
  return isHttpUrl3(readFrom) || opensLocally(readFrom, roots) ? readFrom : null;
@@ -11842,7 +12013,7 @@ async function appendVideoAudioFromProbe(input) {
11842
12013
  videos.map(async (video) => {
11843
12014
  const readFrom = isHttpUrl3(video.src) ? await remoteProbeSource(video, input) : localProbeSource(video.src, input);
11844
12015
  if (readFrom === null) return null;
11845
- const metadata = await extractMediaMetadata4(readFrom, { signal: input.signal });
12016
+ const metadata = await extractMediaMetadata5(readFrom, { signal: input.signal });
11846
12017
  const window2 = await resolveFinalFrameExtractionWindow2(
11847
12018
  readFrom,
11848
12019
  video,
@@ -11866,7 +12037,7 @@ import {
11866
12037
  buildVideoLayerInput,
11867
12038
  isHttpUrl as isHttpUrl4,
11868
12039
  qualifyVideoLayer,
11869
- resolveProjectRelativeSrc as resolveProjectRelativeSrc5
12040
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc6
11870
12041
  } from "@hyperframes/engine";
11871
12042
  var SAMPLES = 9;
11872
12043
  function inspectVideoLayout(id, w, h, time) {
@@ -11928,7 +12099,7 @@ async function planVideoLayerPassthrough(input) {
11928
12099
  if (!q.qualifies) return { reason: q.reason };
11929
12100
  const { video } = q;
11930
12101
  if (isHttpUrl4(video.src)) return { reason: "remote_source" };
11931
- const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
12102
+ const path = resolveProjectRelativeSrc6(video.src, input.projectDir, input.compiledDir);
11932
12103
  if (!existsSync14(path)) return { reason: "source_missing" };
11933
12104
  const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
11934
12105
  if ("reason" in layout) return layout;
@@ -14891,7 +15062,7 @@ function isRecoverableParallelCaptureError(error) {
14891
15062
  return kind === "transient_browser" || kind === "protocol_timeout";
14892
15063
  }
14893
15064
  function describeMemoryExhaustion(error, ctx) {
14894
- if (!isMemoryExhaustionError(error)) return null;
15065
+ if (!isMemoryExhaustionError2(error)) return null;
14895
15066
  const raw = normalizeErrorMessage(error);
14896
15067
  const dims = ctx.width && ctx.height ? ` (${ctx.width}\xD7${ctx.height}${ctx.totalFrames ? `, ${ctx.totalFrames} frames` : ""})` : "";
14897
15068
  return `Render ran out of memory${dims}: ${raw}
@@ -16037,6 +16208,11 @@ async function executeRenderPipeline(input) {
16037
16208
  failureToEnforce
16038
16209
  } = extractResult;
16039
16210
  perfStages.videoExtractMs = extractResult.videoExtractMs;
16211
+ if (probeSession && !probeHoldFitsCapture(probeSession.options.skipReadinessVideoIds, videoReadinessSkipIds)) {
16212
+ const held = probeSession;
16213
+ probeSession = null;
16214
+ await closeCaptureSession8(held);
16215
+ }
16040
16216
  const coverageReports = extractionResult ? computeVideoFrameCoverage(composition.videos, extractionResult.extracted, job.config.fps) : [];
16041
16217
  const coverageThreshold = resolveVideoCoverageThreshold();
16042
16218
  const authoredTimedClipCount = countAuthoredTimedClips(compiled.html);
@@ -17058,7 +17234,7 @@ async function executeRenderPipeline(input) {
17058
17234
  totalFrames,
17059
17235
  segmentFrames,
17060
17236
  key: manifestKey,
17061
- probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
17237
+ probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata6)
17062
17238
  });
17063
17239
  segmentManifest.completed = existing.completed.filter(
17064
17240
  (entry) => completedSegments.has(entry.index)
@@ -17294,7 +17470,7 @@ async function executeRenderPipeline(input) {
17294
17470
  isBeginFrameCapture: !capturePlan.forceScreenshot && !cfg.useDrawElement && parallelCaptureMode === "beginframe"
17295
17471
  }))
17296
17472
  throw err;
17297
- const isMemoryExhaustion = !isVerifyError && isMemoryExhaustionError(err);
17473
+ const isMemoryExhaustion = !isVerifyError && isMemoryExhaustionError2(err);
17298
17474
  deSelfVerifyFallback = isVerifyError;
17299
17475
  if (isVerifyError) {
17300
17476
  const t = deVerifyFallbackTelemetry(err);
@@ -17821,14 +17997,14 @@ function child2(buf, parent, type) {
17821
17997
  return found;
17822
17998
  }
17823
17999
  var SCAN_BYTES = 64 * 1024;
17824
- async function readMp4Layout(read) {
18000
+ async function readMp4Layout(read2) {
17825
18001
  const found = /* @__PURE__ */ new Map();
17826
18002
  let payload;
17827
18003
  let buf = Buffer.alloc(0);
17828
18004
  let bufAt = 0;
17829
18005
  const load = async (start, end) => {
17830
18006
  if (start >= bufAt && end <= bufAt + buf.length) return;
17831
- buf = await read(start, Math.max(end, start + SCAN_BYTES));
18007
+ buf = await read2(start, Math.max(end, start + SCAN_BYTES));
17832
18008
  bufAt = start;
17833
18009
  };
17834
18010
  for (let at = 0; !(found.has("ftyp") && found.has("moov") && payload); ) {