@hyperframes/producer 0.9.66 → 0.9.68

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.
@@ -1555,6 +1555,9 @@ function normalizeErrorMessage(error) {
1555
1555
  return String(error ?? "unknown error");
1556
1556
  }
1557
1557
 
1558
+ // src/services/render/missingPath.ts
1559
+ import { errnoMissingPathOf } from "@hyperframes/core/missing-path";
1560
+
1558
1561
  // src/services/render/renderEventPublisher.ts
1559
1562
  import { cloneCaptureWarnings } from "@hyperframes/engine";
1560
1563
 
@@ -1749,6 +1752,10 @@ import { createStagingDir as createStagingDir2 } from "@hyperframes/core/atomic-
1749
1752
  var BYTES_PER_MIB = 1024 * 1024;
1750
1753
  var DEFAULT_HDR_WINDOW_BYTES = 512 * BYTES_PER_MIB;
1751
1754
 
1755
+ // src/services/render/segmentManifest.ts
1756
+ import { previewToken } from "@hyperframes/core/preview-proof";
1757
+ import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
1758
+
1752
1759
  // src/services/render/stages/captureStreamingStage.ts
1753
1760
  import {
1754
1761
  DrawElementVerificationError,
@@ -2045,9 +2052,6 @@ import {
2045
2052
  createVideoFrameInjector
2046
2053
  } from "@hyperframes/engine";
2047
2054
 
2048
- // src/services/render/segmentManifest.ts
2049
- import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
2050
-
2051
2055
  // src/services/render/hdrMode.ts
2052
2056
  import {
2053
2057
  analyzeCompositionHdr,
@@ -2473,6 +2477,8 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
2473
2477
  { bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
2474
2478
  );
2475
2479
  var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
2480
+ var REMOTE_SCRIPTS = "remote scripts";
2481
+ var REMOTE_STYLESHEETS = "remote stylesheets";
2476
2482
  function generatedTooLarge(file, bytes) {
2477
2483
  if (file === "composition variables") {
2478
2484
  return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
@@ -2480,6 +2486,9 @@ function generatedTooLarge(file, bytes) {
2480
2486
  if (file === "variable media sources") {
2481
2487
  return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
2482
2488
  }
2489
+ if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
2490
+ return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
2491
+ }
2483
2492
  return `Scripts, styles and rebased asset paths generated for compositions, ending at "${file}", add up to ${megabytes(bytes)}. One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)} for its mounts. Merge small inline scripts and style rules, keep data-composition-id values short, or mount scenes fewer times.`;
2484
2493
  }
2485
2494
  var CompositionExpansionBudget = class {
@@ -2792,6 +2801,7 @@ function placeAudio(audio, window2) {
2792
2801
  import {
2793
2802
  analyzeKeyframeIntervals,
2794
2803
  assertMediaPayload,
2804
+ createConcurrencyLimit,
2795
2805
  isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
2796
2806
  NotMediaPayloadError as NotMediaPayloadError2,
2797
2807
  parseMasterFxChain,
@@ -4425,7 +4435,8 @@ async function downloadScript(src, mirror) {
4425
4435
  }
4426
4436
  return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
4427
4437
  }
4428
- async function inlineExternalScripts(html) {
4438
+ var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
4439
+ async function inlineExternalScripts(html, budget = new CompositionExpansionBudget()) {
4429
4440
  const fullHtml = ensureFullDocument(html);
4430
4441
  const wrappedFragment = fullHtml !== html;
4431
4442
  const { document: document2 } = parseHTML5(fullHtml);
@@ -4439,20 +4450,52 @@ async function inlineExternalScripts(html) {
4439
4450
  }
4440
4451
  if (externalScripts.length === 0) return html;
4441
4452
  const mirror = operatorGsapMirror();
4453
+ const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
4454
+ const stop = new AbortController();
4455
+ const fail = (error) => {
4456
+ stop.abort(error);
4457
+ throw error;
4458
+ };
4459
+ const charge = (bytes) => {
4460
+ try {
4461
+ budget.chargeGenerated(REMOTE_SCRIPTS, bytes);
4462
+ } catch (error) {
4463
+ fail(error);
4464
+ }
4465
+ };
4466
+ const fetches = /* @__PURE__ */ new Map();
4467
+ const fetchOnce = (src) => {
4468
+ let bytes = fetches.get(src);
4469
+ if (!bytes) {
4470
+ bytes = limit(async () => {
4471
+ if (stop.signal.aborted) throw stop.signal.reason;
4472
+ const downloaded = await downloadScript(src, mirror);
4473
+ charge(downloaded.byteLength);
4474
+ return downloaded;
4475
+ }, stop.signal);
4476
+ fetches.set(src, bytes);
4477
+ }
4478
+ return bytes;
4479
+ };
4480
+ const placed = /* @__PURE__ */ new Set();
4442
4481
  const downloads = await Promise.allSettled(
4443
4482
  externalScripts.map(async ({ el, src }) => {
4444
4483
  const integrity = el.getAttribute("integrity") || "";
4445
- const bundled = bundledScript(src);
4446
- if (bundled && matchesScriptIntegrity(bundled, integrity)) {
4447
- return { src, text: new TextDecoder().decode(bundled) };
4448
- }
4449
- const bytes = await downloadScript(src, mirror);
4450
- if (!matchesScriptIntegrity(bytes, integrity)) {
4451
- throw new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`);
4484
+ let bytes = bundledScript(src);
4485
+ if (bytes && matchesScriptIntegrity(bytes, integrity)) {
4486
+ charge(bytes.byteLength);
4487
+ } else {
4488
+ bytes = await fetchOnce(src);
4489
+ if (!matchesScriptIntegrity(bytes, integrity)) {
4490
+ fail(new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`));
4491
+ }
4492
+ if (placed.has(src)) charge(bytes.byteLength);
4493
+ placed.add(src);
4452
4494
  }
4453
4495
  return { src, text: new TextDecoder().decode(bytes) };
4454
4496
  })
4455
4497
  );
4498
+ if (stop.signal.aborted) throw stop.signal.reason;
4456
4499
  for (let i = 0; i < downloads.length; i++) {
4457
4500
  const download = downloads[i];
4458
4501
  const { el, src } = externalScripts[i];
@@ -4676,48 +4719,50 @@ function matchingBraces(css) {
4676
4719
  }
4677
4720
  return closes;
4678
4721
  }
4679
- async function inlineExternalFontStylesheets(html) {
4680
- const hrefRe = /\bhref=["']([^"']+)["']/i;
4681
- const linkMatches = [];
4722
+ function remoteFontStylesheetHref(tag) {
4723
+ const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
4724
+ if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
4725
+ return href;
4726
+ }
4727
+ async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget()) {
4728
+ const hrefs = /* @__PURE__ */ new Set();
4682
4729
  for (const { parts } of stylesheetLinkMatches(html)) {
4683
- const tag = parts[0];
4684
- const hrefMatch = hrefRe.exec(tag);
4685
- if (!hrefMatch?.[1]) continue;
4686
- const href = hrefMatch[1];
4687
- if (!/^https?:\/\//i.test(href)) continue;
4688
- if (isGoogleFontsUrl(href)) continue;
4689
- linkMatches.push({ fullMatch: tag, href });
4690
- }
4691
- if (linkMatches.length === 0) return html;
4692
- const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
4693
- const fetches = [];
4694
- for (let i = 0; i < linkMatches.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
4695
- const batch = linkMatches.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
4696
- const results = await Promise.all(
4697
- batch.map(async ({ fullMatch, href }) => {
4698
- const css = await fetchExternalStylesheetCss(href);
4699
- return { fullMatch, href, css };
4700
- })
4701
- );
4702
- fetches.push(...results);
4730
+ const href = remoteFontStylesheetHref(parts[0]);
4731
+ if (href) hrefs.add(href);
4703
4732
  }
4704
- let result = html;
4705
- for (const { fullMatch, href, css } of fetches) {
4706
- if (css === null) continue;
4707
- const fontFaceBlocks = extractFontFaceBlocks(css);
4708
- if (fontFaceBlocks.length === 0) continue;
4709
- const identity = safeDownloadUrlIdentity(href);
4710
- const inlineStyle = `<style>/* Inlined external font stylesheet */
4733
+ if (hrefs.size === 0) return html;
4734
+ const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
4735
+ const inlineByHref = /* @__PURE__ */ new Map();
4736
+ const unique = [...hrefs];
4737
+ for (let i = 0; i < unique.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
4738
+ const batch = unique.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
4739
+ const sheets = await Promise.all(batch.map(fetchExternalStylesheetCss));
4740
+ batch.forEach((href, index) => {
4741
+ const css = sheets[index];
4742
+ const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
4743
+ if (fontFaceBlocks.length === 0) return;
4744
+ const inlineStyle = `<style>/* Inlined external font stylesheet */
4711
4745
  ${fontFaceBlocks.join("\n")}
4712
4746
  </style>`;
4713
- result = result.replace(fullMatch, inlineStyle);
4714
- defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
4715
- count: fontFaceBlocks.length,
4716
- urlFingerprint: identity.urlFingerprint,
4717
- host: identity.host
4747
+ budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
4748
+ inlineByHref.set(href, inlineStyle);
4749
+ const identity = safeDownloadUrlIdentity(href);
4750
+ defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
4751
+ count: fontFaceBlocks.length,
4752
+ urlFingerprint: identity.urlFingerprint,
4753
+ host: identity.host
4754
+ });
4718
4755
  });
4719
4756
  }
4720
- return result;
4757
+ const placed = /* @__PURE__ */ new Set();
4758
+ return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
4759
+ const href = remoteFontStylesheetHref(tag);
4760
+ const inlineStyle = href ? inlineByHref.get(href) : void 0;
4761
+ if (!href || !inlineStyle) return tag;
4762
+ if (placed.has(href)) budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
4763
+ placed.add(href);
4764
+ return inlineStyle;
4765
+ });
4721
4766
  }
4722
4767
  function projectStylesheetFontFamilies(html, projectDir) {
4723
4768
  const families = [];
@@ -5019,7 +5064,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
5019
5064
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
5020
5065
  const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
5021
5066
  const fontSheetHtml = await inlineExternalFontStylesheets(
5022
- promoteCssImportsToLinkTags(sanitizedHtml)
5067
+ promoteCssImportsToLinkTags(sanitizedHtml),
5068
+ budget
5023
5069
  );
5024
5070
  const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
5025
5071
  injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
@@ -5031,7 +5077,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
5031
5077
  projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
5032
5078
  abortSignal: options.abortSignal
5033
5079
  });
5034
- const assembledHtml = await inlineExternalScripts(coalescedHtml);
5080
+ const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
5035
5081
  const HF_POSITION_ATTRS = [
5036
5082
  'data-hf-studio-path-offset="true"',
5037
5083
  'data-hf-studio-box-size="true"',
@@ -12616,6 +12662,7 @@ import { basename as basename6, dirname as dirname16, join as join31 } from "nod
12616
12662
  import {
12617
12663
  appendRateCapArgs as appendRateCapArgs2,
12618
12664
  appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
12665
+ concatListInputArgs,
12619
12666
  describeFfmpegFailure as describeFfmpegFailure5,
12620
12667
  getEncoderPreset as getEncoderPreset5,
12621
12668
  MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME4,
@@ -12834,7 +12881,7 @@ function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
12834
12881
  const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
12835
12882
  writeFileSync11(listPath, `${body}
12836
12883
  `, "utf-8");
12837
- return ["-r", fpsArg, "-f", "concat", "-safe", "0", "-i", listPath];
12884
+ return ["-r", fpsArg, ...concatListInputArgs(listPath)];
12838
12885
  }
12839
12886
  async function probeJoinedFrameInfo(videoPaths, fps, signal) {
12840
12887
  const infos = await Promise.all(
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "2a9e26f5b780e1f414573d4a7d513e409ef718f508650c18f6e32a52069b68a1",
4
+ "sha256": "151e6b9b3c8baac125278612a28f910b6194f7c0563b8d26d72be54c1dead643",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"