@hyperframes/producer 0.9.48 → 0.9.50

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.
@@ -221,6 +221,7 @@ import { Readable } from "node:stream";
221
221
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
222
222
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
223
223
  import { fpsToNumber } from "@hyperframes/core";
224
+ import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
224
225
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
225
226
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
226
227
 
@@ -876,6 +877,7 @@ function createFileServer(options) {
876
877
  const candidate = join2(root, relativePath);
877
878
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
878
879
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
880
+ if (isPrivateFileUnder(root, candidate, isVcsOrSecretPath)) continue;
879
881
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
880
882
  if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
881
883
  file = openRegularFile(candidate);
@@ -2299,7 +2301,7 @@ import {
2299
2301
  readTextFile,
2300
2302
  resolveCompositionSrc
2301
2303
  } from "@hyperframes/parsers/asset-resolution";
2302
- import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
2304
+ import { isPrivateFileUnder as isPrivateFileUnder2, isVcsOrSecretPath as isVcsOrSecretPath2 } from "@hyperframes/core/safe-path";
2303
2305
 
2304
2306
  // src/services/renderMediaCollector.ts
2305
2307
  import { parseHTML as parseHTML2 } from "linkedom";
@@ -2477,6 +2479,7 @@ import {
2477
2479
  // src/utils/urlDownloader.ts
2478
2480
  import {
2479
2481
  downloadToTemp,
2482
+ fetchPublicHttpsBytes,
2480
2483
  fetchPublicHttpsText,
2481
2484
  isHttpUrl,
2482
2485
  safeDownloadUrlIdentity,
@@ -3134,14 +3137,18 @@ import { join as join8 } from "node:path";
3134
3137
  import {
3135
3138
  fingerprintElementId,
3136
3139
  isNotMediaPayload,
3140
+ playlistLeavesItsFolder,
3137
3141
  NotMediaPayloadError,
3138
3142
  probeMediaProfile,
3139
3143
  resolveProjectRelativeSrc as resolveProjectRelativeSrc3
3140
3144
  } from "@hyperframes/engine";
3141
3145
  var ASSET_MEDIA_TYPE_MISMATCH = "ASSET_MEDIA_TYPE_MISMATCH";
3142
3146
  var AssetMediaTypeMismatchError = class extends Error {
3147
+ // fallow-ignore-next-line unused-class-member
3143
3148
  code = ASSET_MEDIA_TYPE_MISMATCH;
3149
+ // fallow-ignore-next-line unused-class-member
3144
3150
  owner = "user";
3151
+ // fallow-ignore-next-line unused-class-member
3145
3152
  retryable = false;
3146
3153
  mismatches;
3147
3154
  constructor(mismatches) {
@@ -3197,6 +3204,11 @@ function dropMediaOutsideProject(input) {
3197
3204
  composition.audios = composition.audios.filter(staysInside);
3198
3205
  composition.images = composition.images.filter(staysInside);
3199
3206
  }
3207
+ async function notMediaReferences(path, references) {
3208
+ const videos = references.filter((ref) => ref.expected === "video");
3209
+ if (videos.length > 0 && await isNotMediaPayload(path)) return videos;
3210
+ return await playlistLeavesItsFolder(path) ? references : [];
3211
+ }
3200
3212
  async function preflightCompositionAssetMediaTypes(input) {
3201
3213
  const references = [
3202
3214
  ...input.composition.videos.map((asset) => ({
@@ -3232,11 +3244,9 @@ async function preflightCompositionAssetMediaTypes(input) {
3232
3244
  await Promise.all(
3233
3245
  entries.map(
3234
3246
  ([resolvedPath, pathReferences]) => withMediaProbeSlot(async () => {
3235
- const sniffableReferences = pathReferences.filter((ref) => ref.expected === "video");
3236
- if (sniffableReferences.length > 0 && await isNotMediaPayload(resolvedPath)) {
3237
- notMediaFingerprints.push(
3238
- ...sniffableReferences.map((ref) => fingerprintElementId(ref.id))
3239
- );
3247
+ const refused = await notMediaReferences(resolvedPath, pathReferences);
3248
+ if (refused.length > 0) {
3249
+ notMediaFingerprints.push(...refused.map((ref) => fingerprintElementId(ref.id)));
3240
3250
  return;
3241
3251
  }
3242
3252
  let profile;
@@ -3323,7 +3333,7 @@ function resolveCompositionFile(projectDir, src, assetRoot) {
3323
3333
  const file = resolveCompositionSrc(projectDir, src);
3324
3334
  return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
3325
3335
  }
3326
- var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder(projectDir, filePath, isVcsOrSecretPath);
3336
+ var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isVcsOrSecretPath2);
3327
3337
  function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
3328
3338
  const { document: document2 } = parseHTML5(html);
3329
3339
  const hosts = [...document2.querySelectorAll("[data-composition-src]")];
@@ -3990,6 +4000,26 @@ function matchesScriptIntegrity(bytes, metadata) {
3990
4000
  (hash) => hash[1]?.toLowerCase() === strongest && actual.equals(Buffer.from(hash[2], "base64"))
3991
4001
  );
3992
4002
  }
4003
+ var MAX_SCRIPT_BYTES = 16 * 1024 * 1024;
4004
+ function operatorGsapMirror() {
4005
+ const raw = process.env.HYPERFRAMES_GSAP_BASE_URL?.trim();
4006
+ if (!raw || raw.startsWith("/")) return void 0;
4007
+ try {
4008
+ return `${normalizeGsapBaseUrl(raw)}/`;
4009
+ } catch {
4010
+ return void 0;
4011
+ }
4012
+ }
4013
+ async function downloadScript(src, mirror) {
4014
+ if (mirror && new URL(src).href.startsWith(mirror)) {
4015
+ const response = await fetch(src, { redirect: "error", signal: AbortSignal.timeout(15e3) });
4016
+ if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
4017
+ const bytes = new Uint8Array(await response.arrayBuffer());
4018
+ if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
4019
+ return bytes;
4020
+ }
4021
+ return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
4022
+ }
3993
4023
  async function inlineExternalScripts(html) {
3994
4024
  const fullHtml = ensureFullDocument(html);
3995
4025
  const wrappedFragment = fullHtml !== html;
@@ -4003,6 +4033,7 @@ async function inlineExternalScripts(html) {
4003
4033
  }
4004
4034
  }
4005
4035
  if (externalScripts.length === 0) return html;
4036
+ const mirror = operatorGsapMirror();
4006
4037
  const downloads = await Promise.allSettled(
4007
4038
  externalScripts.map(async ({ el, src }) => {
4008
4039
  const integrity = el.getAttribute("integrity") || "";
@@ -4010,11 +4041,7 @@ async function inlineExternalScripts(html) {
4010
4041
  if (bundled && matchesScriptIntegrity(bundled, integrity)) {
4011
4042
  return { src, text: new TextDecoder().decode(bundled) };
4012
4043
  }
4013
- const response = await fetch(src, {
4014
- signal: AbortSignal.timeout(15e3)
4015
- });
4016
- if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
4017
- const bytes = new Uint8Array(await response.arrayBuffer());
4044
+ const bytes = await downloadScript(src, mirror);
4018
4045
  if (!matchesScriptIntegrity(bytes, integrity)) {
4019
4046
  throw new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`);
4020
4047
  }
@@ -6031,6 +6058,7 @@ import {
6031
6058
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
6032
6059
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
6033
6060
  isHttpUrl as isHttpUrl2,
6061
+ assertPublicHttpsUrl,
6034
6062
  resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
6035
6063
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
6036
6064
  safeVideoExtractionSourceIdentity,
@@ -6442,6 +6470,14 @@ function appendAutoDetectedVideoAudio(composition, extracted) {
6442
6470
  existingAudioSrcs.add(video.src);
6443
6471
  }
6444
6472
  }
6473
+ function isPublicHttpsUrl(url) {
6474
+ try {
6475
+ assertPublicHttpsUrl(url);
6476
+ return true;
6477
+ } catch {
6478
+ return false;
6479
+ }
6480
+ }
6445
6481
  async function appendVideoAudioFromProbe(input) {
6446
6482
  const { projectDir, compiledDir, composition, urlByAbsentLocalPath } = input;
6447
6483
  const videos = composition.videos.filter(
@@ -6449,6 +6485,7 @@ async function appendVideoAudioFromProbe(input) {
6449
6485
  );
6450
6486
  const probed = await Promise.all(
6451
6487
  videos.map(async (video) => {
6488
+ if (isHttpUrl2(video.src) && !isPublicHttpsUrl(video.src)) return null;
6452
6489
  const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc4(video.src, projectDir, compiledDir);
6453
6490
  const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
6454
6491
  if (!isHttpUrl2(readFrom) && !existsSync9(readFrom)) return null;
package/dist/index.js CHANGED
@@ -92,6 +92,7 @@ import { Readable } from "node:stream";
92
92
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
93
93
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
94
94
  import { fpsToNumber } from "@hyperframes/core";
95
+ import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
95
96
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
96
97
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
97
98
 
@@ -866,6 +867,7 @@ function createFileServer(options) {
866
867
  const candidate = join2(root, relativePath);
867
868
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
868
869
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
870
+ if (isPrivateFileUnder(root, candidate, isVcsOrSecretPath)) continue;
869
871
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
870
872
  if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
871
873
  file = openRegularFile(candidate);
@@ -5642,20 +5644,25 @@ async function oversizedVideos(videos, projectDir, compiledDir, canvas) {
5642
5644
  );
5643
5645
  return videos.filter((_, index) => sized[index]);
5644
5646
  }
5645
- function shownBoxTimes(videos, fps) {
5647
+ function shownBoxTimes(videos, fps, duration) {
5646
5648
  const frame = fps.den / fps.num;
5647
5649
  const times = /* @__PURE__ */ new Set();
5648
- for (const { start, end } of videos) {
5650
+ for (const { start, end: authoredEnd } of videos) {
5651
+ const end = Math.min(authoredEnd, duration);
5652
+ if (!Number.isFinite(start) || !Number.isFinite(end) || start > end) continue;
5649
5653
  const last = Math.max(start, end - frame);
5650
- for (let t = start; t < last; t += SHOWN_BOX_STRIDE_S) times.add(t);
5654
+ for (let step = 0; start + step * SHOWN_BOX_STRIDE_S < last; step += 1) {
5655
+ times.add(start + step * SHOWN_BOX_STRIDE_S);
5656
+ }
5651
5657
  times.add(last);
5652
5658
  }
5653
5659
  return [...times].sort((a, b) => a - b);
5654
5660
  }
5655
- async function measureLocalShownBoxes(page, videos, fps, log) {
5656
- const times = shownBoxTimes(videos, fps);
5661
+ async function measureLocalShownBoxes(page, videos, fps, duration, log) {
5662
+ let times = [];
5657
5663
  const startedAt = Date.now();
5658
5664
  try {
5665
+ times = shownBoxTimes(videos, fps, duration);
5659
5666
  const ranges = await measureVideoShownBoxRanges(
5660
5667
  page,
5661
5668
  videos.map((video) => video.id),
@@ -6589,7 +6596,7 @@ import {
6589
6596
  readTextFile,
6590
6597
  resolveCompositionSrc
6591
6598
  } from "@hyperframes/parsers/asset-resolution";
6592
- import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
6599
+ import { isPrivateFileUnder as isPrivateFileUnder2, isVcsOrSecretPath as isVcsOrSecretPath2 } from "@hyperframes/core/safe-path";
6593
6600
 
6594
6601
  // src/services/renderMediaCollector.ts
6595
6602
  import { parseHTML as parseHTML2 } from "linkedom";
@@ -6767,6 +6774,7 @@ import {
6767
6774
  // src/utils/urlDownloader.ts
6768
6775
  import {
6769
6776
  downloadToTemp,
6777
+ fetchPublicHttpsBytes,
6770
6778
  fetchPublicHttpsText,
6771
6779
  isHttpUrl,
6772
6780
  safeDownloadUrlIdentity,
@@ -7424,14 +7432,18 @@ import { join as join18 } from "node:path";
7424
7432
  import {
7425
7433
  fingerprintElementId,
7426
7434
  isNotMediaPayload,
7435
+ playlistLeavesItsFolder,
7427
7436
  NotMediaPayloadError,
7428
7437
  probeMediaProfile,
7429
7438
  resolveProjectRelativeSrc as resolveProjectRelativeSrc3
7430
7439
  } from "@hyperframes/engine";
7431
7440
  var ASSET_MEDIA_TYPE_MISMATCH = "ASSET_MEDIA_TYPE_MISMATCH";
7432
7441
  var AssetMediaTypeMismatchError = class extends Error {
7442
+ // fallow-ignore-next-line unused-class-member
7433
7443
  code = ASSET_MEDIA_TYPE_MISMATCH;
7444
+ // fallow-ignore-next-line unused-class-member
7434
7445
  owner = "user";
7446
+ // fallow-ignore-next-line unused-class-member
7435
7447
  retryable = false;
7436
7448
  mismatches;
7437
7449
  constructor(mismatches) {
@@ -7487,6 +7499,11 @@ function dropMediaOutsideProject(input) {
7487
7499
  composition.audios = composition.audios.filter(staysInside);
7488
7500
  composition.images = composition.images.filter(staysInside);
7489
7501
  }
7502
+ async function notMediaReferences(path, references) {
7503
+ const videos = references.filter((ref) => ref.expected === "video");
7504
+ if (videos.length > 0 && await isNotMediaPayload(path)) return videos;
7505
+ return await playlistLeavesItsFolder(path) ? references : [];
7506
+ }
7490
7507
  async function preflightCompositionAssetMediaTypes(input) {
7491
7508
  const references = [
7492
7509
  ...input.composition.videos.map((asset) => ({
@@ -7522,11 +7539,9 @@ async function preflightCompositionAssetMediaTypes(input) {
7522
7539
  await Promise.all(
7523
7540
  entries.map(
7524
7541
  ([resolvedPath, pathReferences]) => withMediaProbeSlot(async () => {
7525
- const sniffableReferences = pathReferences.filter((ref) => ref.expected === "video");
7526
- if (sniffableReferences.length > 0 && await isNotMediaPayload(resolvedPath)) {
7527
- notMediaFingerprints.push(
7528
- ...sniffableReferences.map((ref) => fingerprintElementId(ref.id))
7529
- );
7542
+ const refused = await notMediaReferences(resolvedPath, pathReferences);
7543
+ if (refused.length > 0) {
7544
+ notMediaFingerprints.push(...refused.map((ref) => fingerprintElementId(ref.id)));
7530
7545
  return;
7531
7546
  }
7532
7547
  let profile;
@@ -7613,7 +7628,7 @@ function resolveCompositionFile(projectDir, src, assetRoot) {
7613
7628
  const file = resolveCompositionSrc(projectDir, src);
7614
7629
  return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
7615
7630
  }
7616
- var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder(projectDir, filePath, isVcsOrSecretPath);
7631
+ var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isVcsOrSecretPath2);
7617
7632
  function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
7618
7633
  const { document: document2 } = parseHTML5(html);
7619
7634
  const hosts = [...document2.querySelectorAll("[data-composition-src]")];
@@ -8280,6 +8295,26 @@ function matchesScriptIntegrity(bytes, metadata) {
8280
8295
  (hash) => hash[1]?.toLowerCase() === strongest && actual.equals(Buffer.from(hash[2], "base64"))
8281
8296
  );
8282
8297
  }
8298
+ var MAX_SCRIPT_BYTES = 16 * 1024 * 1024;
8299
+ function operatorGsapMirror() {
8300
+ const raw = process.env.HYPERFRAMES_GSAP_BASE_URL?.trim();
8301
+ if (!raw || raw.startsWith("/")) return void 0;
8302
+ try {
8303
+ return `${normalizeGsapBaseUrl(raw)}/`;
8304
+ } catch {
8305
+ return void 0;
8306
+ }
8307
+ }
8308
+ async function downloadScript(src, mirror) {
8309
+ if (mirror && new URL(src).href.startsWith(mirror)) {
8310
+ const response = await fetch(src, { redirect: "error", signal: AbortSignal.timeout(15e3) });
8311
+ if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
8312
+ const bytes = new Uint8Array(await response.arrayBuffer());
8313
+ if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
8314
+ return bytes;
8315
+ }
8316
+ return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
8317
+ }
8283
8318
  async function inlineExternalScripts(html) {
8284
8319
  const fullHtml = ensureFullDocument(html);
8285
8320
  const wrappedFragment = fullHtml !== html;
@@ -8293,6 +8328,7 @@ async function inlineExternalScripts(html) {
8293
8328
  }
8294
8329
  }
8295
8330
  if (externalScripts.length === 0) return html;
8331
+ const mirror = operatorGsapMirror();
8296
8332
  const downloads = await Promise.allSettled(
8297
8333
  externalScripts.map(async ({ el, src }) => {
8298
8334
  const integrity = el.getAttribute("integrity") || "";
@@ -8300,11 +8336,7 @@ async function inlineExternalScripts(html) {
8300
8336
  if (bundled && matchesScriptIntegrity(bundled, integrity)) {
8301
8337
  return { src, text: new TextDecoder().decode(bundled) };
8302
8338
  }
8303
- const response = await fetch(src, {
8304
- signal: AbortSignal.timeout(15e3)
8305
- });
8306
- if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
8307
- const bytes = new Uint8Array(await response.arrayBuffer());
8339
+ const bytes = await downloadScript(src, mirror);
8308
8340
  if (!matchesScriptIntegrity(bytes, integrity)) {
8309
8341
  throw new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`);
8310
8342
  }
@@ -10324,6 +10356,7 @@ import {
10324
10356
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
10325
10357
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
10326
10358
  isHttpUrl as isHttpUrl2,
10359
+ assertPublicHttpsUrl,
10327
10360
  resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
10328
10361
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
10329
10362
  safeVideoExtractionSourceIdentity,
@@ -10735,6 +10768,14 @@ function appendAutoDetectedVideoAudio(composition, extracted) {
10735
10768
  existingAudioSrcs.add(video.src);
10736
10769
  }
10737
10770
  }
10771
+ function isPublicHttpsUrl(url) {
10772
+ try {
10773
+ assertPublicHttpsUrl(url);
10774
+ return true;
10775
+ } catch {
10776
+ return false;
10777
+ }
10778
+ }
10738
10779
  async function appendVideoAudioFromProbe(input) {
10739
10780
  const { projectDir, compiledDir, composition, urlByAbsentLocalPath } = input;
10740
10781
  const videos = composition.videos.filter(
@@ -10742,6 +10783,7 @@ async function appendVideoAudioFromProbe(input) {
10742
10783
  );
10743
10784
  const probed = await Promise.all(
10744
10785
  videos.map(async (video) => {
10786
+ if (isHttpUrl2(video.src) && !isPublicHttpsUrl(video.src)) return null;
10745
10787
  const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc4(video.src, projectDir, compiledDir);
10746
10788
  const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
10747
10789
  if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
@@ -14743,7 +14785,6 @@ async function executeRenderPipeline(input) {
14743
14785
  compositionHash = computeCompositionObservabilityHash(compiled.html);
14744
14786
  fileServer = probeResult.fileServer;
14745
14787
  probeSession = probeResult.probeSession;
14746
- const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(probeSession.page, largerThanCanvas, job.config.fps, log) : void 0;
14747
14788
  job.strictVariablesChecked = probeResult.strictVariablesChecked;
14748
14789
  lastBrowserConsole = probeResult.lastBrowserConsole;
14749
14790
  let resolvedCaptureBeyondViewport = probeSession?.options.captureBeyondViewport;
@@ -14759,6 +14800,13 @@ async function executeRenderPipeline(input) {
14759
14800
  totalFrames,
14760
14801
  fps: fpsToNumber8(job.config.fps)
14761
14802
  });
14803
+ const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(
14804
+ probeSession.page,
14805
+ largerThanCanvas,
14806
+ job.config.fps,
14807
+ probeResult.duration,
14808
+ log
14809
+ ) : void 0;
14762
14810
  perfStages.browserProbeMs = probeResult.browserProbeMs;
14763
14811
  perfStages.compileMs = Date.now() - stage1Start;
14764
14812
  if (probeResult.beginFrameStalled && !captureForceScreenshot) {
@@ -109,6 +109,7 @@ import { Readable } from "node:stream";
109
109
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
110
110
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
111
111
  import { fpsToNumber } from "@hyperframes/core";
112
+ import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
112
113
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
113
114
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
114
115
 
@@ -883,6 +884,7 @@ function createFileServer(options) {
883
884
  const candidate = join2(root, relativePath);
884
885
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
885
886
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
887
+ if (isPrivateFileUnder(root, candidate, isVcsOrSecretPath)) continue;
886
888
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
887
889
  if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
888
890
  file = openRegularFile(candidate);
@@ -5655,20 +5657,25 @@ async function oversizedVideos(videos, projectDir, compiledDir, canvas) {
5655
5657
  );
5656
5658
  return videos.filter((_, index) => sized[index]);
5657
5659
  }
5658
- function shownBoxTimes(videos, fps) {
5660
+ function shownBoxTimes(videos, fps, duration) {
5659
5661
  const frame = fps.den / fps.num;
5660
5662
  const times = /* @__PURE__ */ new Set();
5661
- for (const { start, end } of videos) {
5663
+ for (const { start, end: authoredEnd } of videos) {
5664
+ const end = Math.min(authoredEnd, duration);
5665
+ if (!Number.isFinite(start) || !Number.isFinite(end) || start > end) continue;
5662
5666
  const last = Math.max(start, end - frame);
5663
- for (let t = start; t < last; t += SHOWN_BOX_STRIDE_S) times.add(t);
5667
+ for (let step = 0; start + step * SHOWN_BOX_STRIDE_S < last; step += 1) {
5668
+ times.add(start + step * SHOWN_BOX_STRIDE_S);
5669
+ }
5664
5670
  times.add(last);
5665
5671
  }
5666
5672
  return [...times].sort((a, b) => a - b);
5667
5673
  }
5668
- async function measureLocalShownBoxes(page, videos, fps, log) {
5669
- const times = shownBoxTimes(videos, fps);
5674
+ async function measureLocalShownBoxes(page, videos, fps, duration, log) {
5675
+ let times = [];
5670
5676
  const startedAt = Date.now();
5671
5677
  try {
5678
+ times = shownBoxTimes(videos, fps, duration);
5672
5679
  const ranges = await measureVideoShownBoxRanges(
5673
5680
  page,
5674
5681
  videos.map((video) => video.id),
@@ -6602,7 +6609,7 @@ import {
6602
6609
  readTextFile,
6603
6610
  resolveCompositionSrc
6604
6611
  } from "@hyperframes/parsers/asset-resolution";
6605
- import { isPrivateFileUnder, isVcsOrSecretPath } from "@hyperframes/core/safe-path";
6612
+ import { isPrivateFileUnder as isPrivateFileUnder2, isVcsOrSecretPath as isVcsOrSecretPath2 } from "@hyperframes/core/safe-path";
6606
6613
 
6607
6614
  // src/services/renderMediaCollector.ts
6608
6615
  import { parseHTML as parseHTML2 } from "linkedom";
@@ -6780,6 +6787,7 @@ import {
6780
6787
  // src/utils/urlDownloader.ts
6781
6788
  import {
6782
6789
  downloadToTemp,
6790
+ fetchPublicHttpsBytes,
6783
6791
  fetchPublicHttpsText,
6784
6792
  isHttpUrl,
6785
6793
  safeDownloadUrlIdentity,
@@ -7437,14 +7445,18 @@ import { join as join18 } from "node:path";
7437
7445
  import {
7438
7446
  fingerprintElementId,
7439
7447
  isNotMediaPayload,
7448
+ playlistLeavesItsFolder,
7440
7449
  NotMediaPayloadError,
7441
7450
  probeMediaProfile,
7442
7451
  resolveProjectRelativeSrc as resolveProjectRelativeSrc3
7443
7452
  } from "@hyperframes/engine";
7444
7453
  var ASSET_MEDIA_TYPE_MISMATCH = "ASSET_MEDIA_TYPE_MISMATCH";
7445
7454
  var AssetMediaTypeMismatchError = class extends Error {
7455
+ // fallow-ignore-next-line unused-class-member
7446
7456
  code = ASSET_MEDIA_TYPE_MISMATCH;
7457
+ // fallow-ignore-next-line unused-class-member
7447
7458
  owner = "user";
7459
+ // fallow-ignore-next-line unused-class-member
7448
7460
  retryable = false;
7449
7461
  mismatches;
7450
7462
  constructor(mismatches) {
@@ -7500,6 +7512,11 @@ function dropMediaOutsideProject(input) {
7500
7512
  composition.audios = composition.audios.filter(staysInside);
7501
7513
  composition.images = composition.images.filter(staysInside);
7502
7514
  }
7515
+ async function notMediaReferences(path, references) {
7516
+ const videos = references.filter((ref) => ref.expected === "video");
7517
+ if (videos.length > 0 && await isNotMediaPayload(path)) return videos;
7518
+ return await playlistLeavesItsFolder(path) ? references : [];
7519
+ }
7503
7520
  async function preflightCompositionAssetMediaTypes(input) {
7504
7521
  const references = [
7505
7522
  ...input.composition.videos.map((asset) => ({
@@ -7535,11 +7552,9 @@ async function preflightCompositionAssetMediaTypes(input) {
7535
7552
  await Promise.all(
7536
7553
  entries.map(
7537
7554
  ([resolvedPath, pathReferences]) => withMediaProbeSlot(async () => {
7538
- const sniffableReferences = pathReferences.filter((ref) => ref.expected === "video");
7539
- if (sniffableReferences.length > 0 && await isNotMediaPayload(resolvedPath)) {
7540
- notMediaFingerprints.push(
7541
- ...sniffableReferences.map((ref) => fingerprintElementId(ref.id))
7542
- );
7555
+ const refused = await notMediaReferences(resolvedPath, pathReferences);
7556
+ if (refused.length > 0) {
7557
+ notMediaFingerprints.push(...refused.map((ref) => fingerprintElementId(ref.id)));
7543
7558
  return;
7544
7559
  }
7545
7560
  let profile;
@@ -7626,7 +7641,7 @@ function resolveCompositionFile(projectDir, src, assetRoot) {
7626
7641
  const file = resolveCompositionSrc(projectDir, src);
7627
7642
  return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
7628
7643
  }
7629
- var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder(projectDir, filePath, isVcsOrSecretPath);
7644
+ var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isVcsOrSecretPath2);
7630
7645
  function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
7631
7646
  const { document: document2 } = parseHTML5(html);
7632
7647
  const hosts = [...document2.querySelectorAll("[data-composition-src]")];
@@ -8293,6 +8308,26 @@ function matchesScriptIntegrity(bytes, metadata) {
8293
8308
  (hash) => hash[1]?.toLowerCase() === strongest && actual.equals(Buffer.from(hash[2], "base64"))
8294
8309
  );
8295
8310
  }
8311
+ var MAX_SCRIPT_BYTES = 16 * 1024 * 1024;
8312
+ function operatorGsapMirror() {
8313
+ const raw = process.env.HYPERFRAMES_GSAP_BASE_URL?.trim();
8314
+ if (!raw || raw.startsWith("/")) return void 0;
8315
+ try {
8316
+ return `${normalizeGsapBaseUrl(raw)}/`;
8317
+ } catch {
8318
+ return void 0;
8319
+ }
8320
+ }
8321
+ async function downloadScript(src, mirror) {
8322
+ if (mirror && new URL(src).href.startsWith(mirror)) {
8323
+ const response = await fetch(src, { redirect: "error", signal: AbortSignal.timeout(15e3) });
8324
+ if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
8325
+ const bytes = new Uint8Array(await response.arrayBuffer());
8326
+ if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
8327
+ return bytes;
8328
+ }
8329
+ return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
8330
+ }
8296
8331
  async function inlineExternalScripts(html) {
8297
8332
  const fullHtml = ensureFullDocument(html);
8298
8333
  const wrappedFragment = fullHtml !== html;
@@ -8306,6 +8341,7 @@ async function inlineExternalScripts(html) {
8306
8341
  }
8307
8342
  }
8308
8343
  if (externalScripts.length === 0) return html;
8344
+ const mirror = operatorGsapMirror();
8309
8345
  const downloads = await Promise.allSettled(
8310
8346
  externalScripts.map(async ({ el, src }) => {
8311
8347
  const integrity = el.getAttribute("integrity") || "";
@@ -8313,11 +8349,7 @@ async function inlineExternalScripts(html) {
8313
8349
  if (bundled && matchesScriptIntegrity(bundled, integrity)) {
8314
8350
  return { src, text: new TextDecoder().decode(bundled) };
8315
8351
  }
8316
- const response = await fetch(src, {
8317
- signal: AbortSignal.timeout(15e3)
8318
- });
8319
- if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
8320
- const bytes = new Uint8Array(await response.arrayBuffer());
8352
+ const bytes = await downloadScript(src, mirror);
8321
8353
  if (!matchesScriptIntegrity(bytes, integrity)) {
8322
8354
  throw new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`);
8323
8355
  }
@@ -10302,6 +10334,7 @@ import {
10302
10334
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
10303
10335
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
10304
10336
  isHttpUrl as isHttpUrl2,
10337
+ assertPublicHttpsUrl,
10305
10338
  resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
10306
10339
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
10307
10340
  safeVideoExtractionSourceIdentity,
@@ -10708,6 +10741,14 @@ function appendAutoDetectedVideoAudio(composition, extracted) {
10708
10741
  existingAudioSrcs.add(video.src);
10709
10742
  }
10710
10743
  }
10744
+ function isPublicHttpsUrl(url) {
10745
+ try {
10746
+ assertPublicHttpsUrl(url);
10747
+ return true;
10748
+ } catch {
10749
+ return false;
10750
+ }
10751
+ }
10711
10752
  async function appendVideoAudioFromProbe(input) {
10712
10753
  const { projectDir, compiledDir, composition, urlByAbsentLocalPath } = input;
10713
10754
  const videos = composition.videos.filter(
@@ -10715,6 +10756,7 @@ async function appendVideoAudioFromProbe(input) {
10715
10756
  );
10716
10757
  const probed = await Promise.all(
10717
10758
  videos.map(async (video) => {
10759
+ if (isHttpUrl2(video.src) && !isPublicHttpsUrl(video.src)) return null;
10718
10760
  const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc4(video.src, projectDir, compiledDir);
10719
10761
  const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
10720
10762
  if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
@@ -14716,7 +14758,6 @@ async function executeRenderPipeline(input) {
14716
14758
  compositionHash = computeCompositionObservabilityHash(compiled.html);
14717
14759
  fileServer = probeResult.fileServer;
14718
14760
  probeSession = probeResult.probeSession;
14719
- const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(probeSession.page, largerThanCanvas, job.config.fps, log) : void 0;
14720
14761
  job.strictVariablesChecked = probeResult.strictVariablesChecked;
14721
14762
  lastBrowserConsole = probeResult.lastBrowserConsole;
14722
14763
  let resolvedCaptureBeyondViewport = probeSession?.options.captureBeyondViewport;
@@ -14732,6 +14773,13 @@ async function executeRenderPipeline(input) {
14732
14773
  totalFrames,
14733
14774
  fps: fpsToNumber8(job.config.fps)
14734
14775
  });
14776
+ const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(
14777
+ probeSession.page,
14778
+ largerThanCanvas,
14779
+ job.config.fps,
14780
+ probeResult.duration,
14781
+ log
14782
+ ) : void 0;
14735
14783
  perfStages.browserProbeMs = probeResult.browserProbeMs;
14736
14784
  perfStages.compileMs = Date.now() - stage1Start;
14737
14785
  if (probeResult.beginFrameStalled && !captureForceScreenshot) {
@@ -6,11 +6,11 @@ export declare function oversizedVideos(videos: readonly VideoElement[], project
6
6
  width: number;
7
7
  height: number;
8
8
  }): Promise<VideoElement[]>;
9
- /** Each video's first and last frame and every stride between, in composition seconds, ascending. */
9
+ /** Each video's first and last frame before `duration` and every stride between, in seconds, ascending. */
10
10
  export declare function shownBoxTimes(videos: readonly VideoElement[], fps: {
11
11
  num: number;
12
12
  den: number;
13
- }): number[];
13
+ }, duration: number): number[];
14
14
  /**
15
15
  * The box to extract each video at: the largest it is drawn at, plus headroom when it moves. Undefined when
16
16
  * the measure fails, and every video then keeps its full size.
@@ -18,4 +18,4 @@ export declare function shownBoxTimes(videos: readonly VideoElement[], fps: {
18
18
  export declare function measureLocalShownBoxes(page: Page, videos: readonly VideoElement[], fps: {
19
19
  num: number;
20
20
  den: number;
21
- }, log: ProducerLogger): Promise<Map<string, ShownBox> | undefined>;
21
+ }, duration: number, log: ProducerLogger): Promise<Map<string, ShownBox> | undefined>;
@@ -2,4 +2,4 @@
2
2
  * Re-exported from @hyperframes/engine.
3
3
  * @see engine/src/utils/urlDownloader.ts for implementation.
4
4
  */
5
- export { downloadToTemp, fetchPublicHttpsText, isHttpUrl, safeDownloadUrlIdentity, writeUrlDownloadTelemetry, type UrlDownloadTelemetry, } from "@hyperframes/engine";
5
+ export { downloadToTemp, fetchPublicHttpsBytes, fetchPublicHttpsText, isHttpUrl, safeDownloadUrlIdentity, writeUrlDownloadTelemetry, type UrlDownloadTelemetry, } from "@hyperframes/engine";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.48",
3
+ "version": "0.9.50",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/core": "0.9.48",
39
- "@hyperframes/parsers": "0.9.48",
40
- "@hyperframes/lint": "0.9.48",
41
- "@hyperframes/engine": "0.9.48",
42
- "@hyperframes/studio-server": "0.9.48"
38
+ "@hyperframes/parsers": "0.9.50",
39
+ "@hyperframes/studio-server": "0.9.50",
40
+ "@hyperframes/lint": "0.9.50",
41
+ "@hyperframes/core": "0.9.50",
42
+ "@hyperframes/engine": "0.9.50"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.48"
51
+ "@hyperframes/aws-lambda": "0.9.50"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"