@hyperframes/producer 0.9.40 → 0.9.42

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.
@@ -14,7 +14,7 @@ import {
14
14
  rmSync as rmSync7,
15
15
  writeFileSync as writeFileSync8
16
16
  } from "node:fs";
17
- import { extname as extname4, isAbsolute as isAbsolute3, join as join27, relative as relative6, sep as sep3 } from "node:path";
17
+ import { extname as extname4, isAbsolute as isAbsolute3, join as join27, relative as relative6, sep as sep4 } from "node:path";
18
18
  import {
19
19
  fpsToNumber as fpsToNumber9,
20
20
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
@@ -71,6 +71,73 @@ var defaultLogger = createConsoleLogger(
71
71
  process.env.HF_DEBUG_RENDER === "1" ? "debug" : "info"
72
72
  );
73
73
 
74
+ // src/utils/paths.ts
75
+ import {
76
+ basename,
77
+ join,
78
+ sep,
79
+ resolve as nodeResolve,
80
+ relative as nodeRelative,
81
+ isAbsolute as nodeIsAbsolute
82
+ } from "node:path";
83
+ import { statSync } from "node:fs";
84
+ import { fileURLToPath } from "node:url";
85
+ import { isSafePath } from "@hyperframes/core/safe-path";
86
+ import {
87
+ isCopiedOutsideFileType,
88
+ isPrivateOutsideFile,
89
+ leftOutWarning,
90
+ linksOutside
91
+ } from "@hyperframes/studio-server/outside-file";
92
+ import { realFilePath } from "@hyperframes/studio-server/safe-path";
93
+ var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
94
+ // resolves to a bogus renders dir.
95
+ nodeResolve(fileURLToPath(import.meta.url), "../../..", "renders");
96
+ var LEADING_PARENT_SEGMENT_RE = /^\.\.(?:[\\/]|$)/;
97
+ function isPathInside(childPath, parentPath, options = {}) {
98
+ const resolvePath = options.pathModule?.resolve ?? nodeResolve;
99
+ const relativePath = options.pathModule?.relative ?? nodeRelative;
100
+ const isPathAbsolute = options.pathModule?.isAbsolute ?? nodeIsAbsolute;
101
+ const absChild = resolvePath(childPath);
102
+ const absParent = resolvePath(parentPath);
103
+ if (absChild === absParent) return true;
104
+ const rel = relativePath(absParent, absChild);
105
+ return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
106
+ }
107
+ function escapesAssetRoot(path, assetRoot) {
108
+ return assetRoot !== void 0 && !isSafePath(assetRoot, path);
109
+ }
110
+ function outsideAssetRefusal(projectDir, path) {
111
+ if (!linksOutside(projectDir, path)) return null;
112
+ if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
113
+ const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
114
+ return folder || isCopiedOutsideFileType(path) ? null : "file_type";
115
+ }
116
+ var leftOutOfRender = (file, reference, reason) => leftOutWarning(file, reference, reason, "render");
117
+ function refusesOutsideLink(projectDir, path, warn) {
118
+ const refusal = outsideAssetRefusal(projectDir, path);
119
+ if (!refusal) return false;
120
+ const file = nodeRelative(projectDir, path).split(sep).join("/");
121
+ warn(leftOutOfRender(file, realFilePath(path), refusal));
122
+ return true;
123
+ }
124
+ function toExternalAssetKey(absPath) {
125
+ if (absPath.startsWith("hf-ext/")) return absPath;
126
+ let normalised = absPath.replace(/\\/g, "/");
127
+ normalised = normalised.replace(/^\/\/\?\/UNC\//i, "//");
128
+ normalised = normalised.replace(/^\/\/\?\//, "");
129
+ normalised = normalised.replace(/^\/\/([^/]+)\//, "unc/$1/");
130
+ normalised = normalised.replace(/^\/+/, "");
131
+ normalised = normalised.replace(/^([A-Za-z]):\/?/, "$1/");
132
+ return "hf-ext/" + normalised;
133
+ }
134
+ function formatCaptureFrameName(index, ext) {
135
+ return `frame_${String(index).padStart(6, "0")}.${ext}`;
136
+ }
137
+ function formatExportFrameName(index, ext) {
138
+ return `frame_${String(index + 1).padStart(6, "0")}.${ext}`;
139
+ }
140
+
74
141
  // src/services/renderOrchestrator.ts
75
142
  import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
76
143
  import {
@@ -78,7 +145,7 @@ import {
78
145
  mkdirSync as mkdirSync6,
79
146
  readdirSync as readdirSync3,
80
147
  rmSync as rmSync5,
81
- statSync as statSync5,
148
+ statSync as statSync6,
82
149
  writeFileSync as writeFileSync5,
83
150
  copyFileSync as copyFileSync5,
84
151
  appendFileSync
@@ -141,7 +208,7 @@ import { settleOnBrowserSafePort } from "@hyperframes/engine";
141
208
  import {
142
209
  existsSync as existsSync2,
143
210
  realpathSync,
144
- statSync,
211
+ statSync as statSync2,
145
212
  createReadStream,
146
213
  openSync,
147
214
  fstatSync,
@@ -151,7 +218,7 @@ import {
151
218
  } from "node:fs";
152
219
  import { promisify } from "node:util";
153
220
  import { Readable } from "node:stream";
154
- import { join, extname, resolve as resolve2, sep } from "node:path";
221
+ import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
155
222
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
156
223
  import { fpsToNumber } from "@hyperframes/core";
157
224
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -161,8 +228,8 @@ import { openRangeEnd } from "@hyperframes/studio-server/media-range";
161
228
  import { createHash } from "node:crypto";
162
229
  import { existsSync, readFileSync } from "node:fs";
163
230
  import { dirname, resolve } from "node:path";
164
- import { fileURLToPath } from "node:url";
165
- var PRODUCER_DIR = dirname(fileURLToPath(import.meta.url));
231
+ import { fileURLToPath as fileURLToPath2 } from "node:url";
232
+ var PRODUCER_DIR = dirname(fileURLToPath2(import.meta.url));
166
233
  var SIBLING_MANIFEST_PATH = resolve(PRODUCER_DIR, "hyperframe.manifest.json");
167
234
  var MODULE_RELATIVE_MANIFEST_PATH = resolve(
168
235
  PRODUCER_DIR,
@@ -233,10 +300,10 @@ function getHfEarlyStub() {
233
300
 
234
301
  // src/services/fileServer.ts
235
302
  var readFileAsync = promisify(readFile);
236
- function isPathInside(child3, parent, options = {}) {
303
+ function isPathInside2(child3, parent, options = {}) {
237
304
  const { resolveSymlinks = false, pathModule } = options;
238
305
  const resolveFn = pathModule?.resolve ?? resolve2;
239
- const separator = pathModule?.sep ?? sep;
306
+ const separator = pathModule?.sep ?? sep2;
240
307
  const resolvedChild = resolveFn(child3);
241
308
  const resolvedParent = resolveFn(parent);
242
309
  const normalizedChild = resolveSymlinks && existsSync2(resolvedChild) ? realpathSync.native(resolvedChild) : resolvedChild;
@@ -759,7 +826,7 @@ function openRegularFile(filePath) {
759
826
  } catch (error) {
760
827
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
761
828
  return null;
762
- if (!statSync(filePath, { throwIfNoEntry: false })?.isFile()) return null;
829
+ if (!statSync2(filePath, { throwIfNoEntry: false })?.isFile()) return null;
763
830
  throw error;
764
831
  }
765
832
  let accepted = false;
@@ -788,6 +855,7 @@ function createFileServer(options) {
788
855
  const headScripts = options.headScripts ?? [getVerifiedHyperframeRuntimeSource()];
789
856
  const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
790
857
  const app = new Hono();
858
+ const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
791
859
  app.get("/*", async (c) => {
792
860
  let requestPath = c.req.path;
793
861
  if (requestPath === "/") requestPath = "/index.html";
@@ -800,9 +868,12 @@ function createFileServer(options) {
800
868
  }).join("/");
801
869
  let file = null;
802
870
  for (const root of compiledDir ? [compiledDir, projectDir] : [projectDir]) {
803
- const candidate = join(root, relativePath);
871
+ const candidate = join2(root, relativePath);
804
872
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
805
- if (isPathInside(candidate, root, { resolveSymlinks })) file = openRegularFile(candidate);
873
+ if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
874
+ const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
875
+ if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
876
+ file = openRegularFile(candidate);
806
877
  if (file) break;
807
878
  }
808
879
  if (!file) {
@@ -977,52 +1048,6 @@ import {
977
1048
  import {
978
1049
  mediaIdPathSegment
979
1050
  } from "@hyperframes/engine";
980
-
981
- // src/utils/paths.ts
982
- import {
983
- basename,
984
- join as join2,
985
- resolve as nodeResolve,
986
- relative as nodeRelative,
987
- isAbsolute as nodeIsAbsolute
988
- } from "node:path";
989
- import { fileURLToPath as fileURLToPath2 } from "node:url";
990
- import { isSafePath } from "@hyperframes/core/safe-path";
991
- var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
992
- // resolves to a bogus renders dir.
993
- nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
994
- var LEADING_PARENT_SEGMENT_RE = /^\.\.(?:[\\/]|$)/;
995
- function isPathInside2(childPath, parentPath, options = {}) {
996
- const resolvePath = options.pathModule?.resolve ?? nodeResolve;
997
- const relativePath = options.pathModule?.relative ?? nodeRelative;
998
- const isPathAbsolute = options.pathModule?.isAbsolute ?? nodeIsAbsolute;
999
- const absChild = resolvePath(childPath);
1000
- const absParent = resolvePath(parentPath);
1001
- if (absChild === absParent) return true;
1002
- const rel = relativePath(absParent, absChild);
1003
- return rel !== "" && !LEADING_PARENT_SEGMENT_RE.test(rel) && !isPathAbsolute(rel);
1004
- }
1005
- function escapesAssetRoot(path, assetRoot) {
1006
- return assetRoot !== void 0 && !isSafePath(assetRoot, path);
1007
- }
1008
- function toExternalAssetKey(absPath) {
1009
- if (absPath.startsWith("hf-ext/")) return absPath;
1010
- let normalised = absPath.replace(/\\/g, "/");
1011
- normalised = normalised.replace(/^\/\/\?\/UNC\//i, "//");
1012
- normalised = normalised.replace(/^\/\/\?\//, "");
1013
- normalised = normalised.replace(/^\/\/([^/]+)\//, "unc/$1/");
1014
- normalised = normalised.replace(/^\/+/, "");
1015
- normalised = normalised.replace(/^([A-Za-z]):\/?/, "$1/");
1016
- return "hf-ext/" + normalised;
1017
- }
1018
- function formatCaptureFrameName(index, ext) {
1019
- return `frame_${String(index).padStart(6, "0")}.${ext}`;
1020
- }
1021
- function formatExportFrameName(index, ext) {
1022
- return `frame_${String(index + 1).padStart(6, "0")}.${ext}`;
1023
- }
1024
-
1025
- // src/services/render/shared.ts
1026
1051
  var BROWSER_MEDIA_EPSILON = 1e-4;
1027
1052
  function resolveBrowserMediaEnd(start, end, duration) {
1028
1053
  return Number.isFinite(duration) && duration > 0 ? start + duration : end;
@@ -1049,7 +1074,7 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1049
1074
  writeFileSync(join3(compileDir, "index.html"), compiled.html, "utf-8");
1050
1075
  for (const [srcPath, html] of compiled.subCompositions) {
1051
1076
  const outPath = join3(compileDir, srcPath);
1052
- if (!isPathInside2(outPath, compileDir)) {
1077
+ if (!isPathInside(outPath, compileDir)) {
1053
1078
  console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
1054
1079
  continue;
1055
1080
  }
@@ -1058,7 +1083,7 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1058
1083
  }
1059
1084
  for (const [relativePath, absolutePath] of compiled.externalAssets) {
1060
1085
  const outPath = resolve3(join3(compileDir, relativePath));
1061
- if (!isPathInside2(outPath, compileDir)) {
1086
+ if (!isPathInside(outPath, compileDir)) {
1062
1087
  console.warn(`[Render] Skipping external asset with unsafe path: ${relativePath}`);
1063
1088
  continue;
1064
1089
  }
@@ -1269,7 +1294,7 @@ function materializeExtractedFramesForCompiledDir(extracted, compiledDir, option
1269
1294
  const compiledFrameRoot = pathModule.join(resolvedCompiledDir, "__hyperframes_video_frames");
1270
1295
  for (const ext of extracted) {
1271
1296
  const resolvedOut = pathModule.resolve(ext.outputDir);
1272
- if (isPathInside2(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
1297
+ if (isPathInside(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
1273
1298
  const linkPath = pathModule.join(compiledFrameRoot, mediaIdPathSegment(ext.videoId));
1274
1299
  if (!fileSystem.existsSync(linkPath)) {
1275
1300
  fileSystem.mkdirSync(pathModule.dirname(linkPath), { recursive: true });
@@ -2196,7 +2221,7 @@ import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolu
2196
2221
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
2197
2222
  import { createHash as createHash5 } from "node:crypto";
2198
2223
  import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
2199
- import { join as join9, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep2 } from "path";
2224
+ import { join as join9, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep3 } from "path";
2200
2225
  import { parseHTML as parseHTML5 } from "linkedom";
2201
2226
 
2202
2227
  // src/services/bundledScripts.ts
@@ -2231,6 +2256,7 @@ import {
2231
2256
  rewriteInlineStyleAssetUrls
2232
2257
  } from "@hyperframes/core";
2233
2258
  import { MAX_AUDIO_GAIN } from "@hyperframes/core/audio-gain";
2259
+ import { CAPTURE_CANVAS_SELECTOR } from "@hyperframes/core/html-in-canvas";
2234
2260
  import { readPlaybackRate } from "@hyperframes/parsers/media-duration";
2235
2261
  import { resolveRateSpec } from "@hyperframes/core/speed-ramp";
2236
2262
  import { gsapCdnDist as gsapCdnDist2, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
@@ -2460,7 +2486,7 @@ import {
2460
2486
 
2461
2487
  // src/services/animatedGifPrep.ts
2462
2488
  import { createHash as createHash3 } from "node:crypto";
2463
- import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
2489
+ import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync3 } from "node:fs";
2464
2490
  import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6, resolve as resolve4 } from "node:path";
2465
2491
  import { parseHTML as parseHTML3 } from "linkedom";
2466
2492
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
@@ -2508,12 +2534,12 @@ function resolveLocalImageSourcePath(src, options) {
2508
2534
  ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve4(options.projectDir, projectRelative)],
2509
2535
  resolve4(options.downloadDir, normalizedBase)
2510
2536
  ];
2511
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) || !escapesAssetRoot(candidate, options.downloadDir);
2537
+ const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
2512
2538
  return candidates.find((candidate) => existsSync5(candidate) && allowed(candidate)) ?? null;
2513
2539
  }
2514
2540
  function isUsableFile(path) {
2515
2541
  try {
2516
- const stat = statSync2(path);
2542
+ const stat = statSync3(path);
2517
2543
  return stat.isFile() && stat.size > 0;
2518
2544
  } catch {
2519
2545
  return false;
@@ -2777,7 +2803,7 @@ import {
2777
2803
  readFileSync as readFileSync4,
2778
2804
  readSync,
2779
2805
  rmSync as rmSync3,
2780
- statSync as statSync3,
2806
+ statSync as statSync4,
2781
2807
  writeFileSync as writeFileSync2
2782
2808
  } from "node:fs";
2783
2809
  import { dirname as dirname5, join as join7, resolve as resolve5 } from "node:path";
@@ -3020,7 +3046,7 @@ function resolveImageSource(src, options) {
3020
3046
  }
3021
3047
  function isUsableFile2(path) {
3022
3048
  try {
3023
- return statSync3(path).size > 0;
3049
+ return statSync4(path).size > 0;
3024
3050
  } catch {
3025
3051
  return false;
3026
3052
  }
@@ -3154,6 +3180,11 @@ function dropMediaOutsideProject(input) {
3154
3180
  if (!src || isRemoteOrInlineSource(src)) return true;
3155
3181
  const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
3156
3182
  if (roots.some((root) => !escapesAssetRoot(path, root))) return true;
3183
+ if (input.allowOutsideProjectAssets) {
3184
+ const refusal = outsideAssetRefusal(projectDir, path);
3185
+ if (refusal) log.warn(`[Render] ${leftOutOfRender(`Media "${id}"`, src, refusal)}`);
3186
+ return refusal === null;
3187
+ }
3157
3188
  log.warn(`[Render] Media "${id}" source is missing: it is outside the project folder`, { src });
3158
3189
  return false;
3159
3190
  };
@@ -3280,7 +3311,7 @@ function normalizeCompositionSrcs(html, projectDir) {
3280
3311
  if (!value.includes("%") && !value.startsWith("/")) return whole;
3281
3312
  const file = resolveCompositionSrc(projectDir, value);
3282
3313
  if (file === null) return whole;
3283
- return `${name}${quote}${relative2(projectDir, file).split(sep2).join("/")}${quote}`;
3314
+ return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
3284
3315
  });
3285
3316
  }
3286
3317
  function resolveCompositionFile(projectDir, src, assetRoot) {
@@ -3301,6 +3332,10 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
3301
3332
  problems.push({ srcPath, detail: "it is outside the project folder" });
3302
3333
  continue;
3303
3334
  }
3335
+ if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
3336
+ problems.push({ srcPath, detail: "it is outside the project in a private location" });
3337
+ continue;
3338
+ }
3304
3339
  if (isPrivateCompositionFile(projectDir, filePath)) {
3305
3340
  problems.push({ srcPath, detail: "it is git metadata or an env file" });
3306
3341
  continue;
@@ -3361,7 +3396,7 @@ function runtimeRoot(document2) {
3361
3396
  function detectRenderModeHints(html, pageMotionBlur) {
3362
3397
  const reasons = [];
3363
3398
  const { document: document2 } = parseHTML5(html);
3364
- if (document2.querySelector("canvas[layoutsubtree]")) {
3399
+ if (document2.querySelector(CAPTURE_CANVAS_SELECTOR)) {
3365
3400
  reasons.push({
3366
3401
  code: "htmlInCanvas",
3367
3402
  message: "Detected html-in-canvas API (layoutsubtree canvas). Chrome does not support concurrent drawElementImage across multiple workers; render is pinned to a single worker."
@@ -3369,7 +3404,7 @@ function detectRenderModeHints(html, pageMotionBlur) {
3369
3404
  } else if (pageMotionBlur !== "off" && runtimeRoot(document2)?.getAttribute("data-motion-blur") === "on") {
3370
3405
  reasons.push({
3371
3406
  code: "captureMotionBlur",
3372
- message: 'Detected capture motion blur (data-motion-blur="on"), which draws each frame with html-in-canvas; routed through screenshot capture mode.'
3407
+ message: 'Detected motion blur (data-motion-blur="on"), drawn per frame with an SVG filter or, on the capture tier, html-in-canvas; routed through screenshot capture mode.'
3373
3408
  });
3374
3409
  }
3375
3410
  if (document2.querySelector("iframe")) {
@@ -4006,17 +4041,24 @@ ${safeText}
4006
4041
  }
4007
4042
  return wrappedFragment ? document2.body.innerHTML || "" : document2.toString();
4008
4043
  }
4009
- function collectExternalAssets(html, projectDir) {
4044
+ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "index.html") {
4010
4045
  const absProjectDir = resolve6(projectDir);
4011
4046
  const externalAssets = /* @__PURE__ */ new Map();
4047
+ const leftOut2 = /* @__PURE__ */ new Set();
4012
4048
  function processPath(rawPath) {
4013
4049
  const trimmed = rawPath.trim();
4014
4050
  if (isNonRelativeUrl(trimmed)) return null;
4015
4051
  const absPath = resolve6(absProjectDir, trimmed);
4016
- if (isPathInside2(absPath, absProjectDir)) {
4052
+ if (isPathInside(absPath, absProjectDir)) {
4017
4053
  return null;
4018
4054
  }
4019
4055
  if (!existsSync7(absPath)) return null;
4056
+ const refusal = outsideAssetRefusal(absProjectDir, absPath);
4057
+ if (refusal) {
4058
+ if (!leftOut2.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
4059
+ leftOut2.add(trimmed);
4060
+ return null;
4061
+ }
4020
4062
  const safeKey = toExternalAssetKey(absPath);
4021
4063
  externalAssets.set(safeKey, absPath);
4022
4064
  return safeKey;
@@ -4110,13 +4152,26 @@ async function localizeRemoteMediaSources(html, downloadDir) {
4110
4152
  if (m[1]) urlSet.add(m[1]);
4111
4153
  }
4112
4154
  }
4113
- return downloadAndRewriteUrls(
4155
+ const localized = await downloadAndRewriteUrls(
4114
4156
  urlSet,
4115
4157
  html,
4116
4158
  join9(downloadDir, REMOTE_MEDIA_SUBDIR),
4117
4159
  "Remote media download failed",
4118
4160
  "Localized remote media source(s)"
4119
4161
  );
4162
+ return { ...localized, html: dropBindingOnLocalizedMedia(localized.html) };
4163
+ }
4164
+ function dropBindingOnLocalizedMedia(html) {
4165
+ if (!html.includes("data-var-src")) return html;
4166
+ const { document: document2 } = parseHTML5(html);
4167
+ let changed = false;
4168
+ for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
4169
+ if (el.closest("[data-variable-values]")) continue;
4170
+ if (!el.getAttribute("src")?.startsWith(`${REMOTE_MEDIA_SUBDIR}/`)) continue;
4171
+ el.removeAttribute("data-var-src");
4172
+ changed = true;
4173
+ }
4174
+ return changed ? document2.toString() : html;
4120
4175
  }
4121
4176
  async function localizeRemoteImageSources(html, downloadDir) {
4122
4177
  const urlSet = /* @__PURE__ */ new Set();
@@ -4249,13 +4304,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
4249
4304
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
4250
4305
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
4251
4306
  const sheet = resolve6(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
4252
- if (!isPathInside2(sheet, projectDir) || !existsSync7(sheet)) continue;
4307
+ if (!isPathInside(sheet, projectDir) || !existsSync7(sheet)) continue;
4253
4308
  for (const face of extractFontFaceBlocks(readFileSync5(sheet, "utf8"))) {
4254
4309
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
4255
4310
  const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
4256
4311
  const path = decodedUrlPath(url);
4257
4312
  const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname6(sheet), path);
4258
- return isPathInside2(file, projectDir) && existsSync7(file);
4313
+ return isPathInside(file, projectDir) && existsSync7(file);
4259
4314
  });
4260
4315
  if (family && shipsFile) families.push(family);
4261
4316
  }
@@ -4321,7 +4376,7 @@ async function readLocalFont(absPath) {
4321
4376
  }
4322
4377
  return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
4323
4378
  }
4324
- async function embedLocalFontFaces(html, projectDir, assetRoot) {
4379
+ async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLogger) {
4325
4380
  const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
4326
4381
  const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
4327
4382
  const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
@@ -4342,7 +4397,11 @@ async function embedLocalFontFaces(html, projectDir, assetRoot) {
4342
4397
  const localPath = urlMatch[1];
4343
4398
  if (!localPath || embeddedPaths.has(localPath)) continue;
4344
4399
  const absPath = localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath);
4345
- if (!isPathInside2(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
4400
+ if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
4401
+ if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
4402
+ embeddedPaths.add(localPath);
4403
+ continue;
4404
+ }
4346
4405
  const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
4347
4406
  try {
4348
4407
  if (fileBackedAbsolutePaths.has(absPath)) {
@@ -4406,7 +4465,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
4406
4465
  );
4407
4466
  }
4408
4467
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
4409
- if (!isPathInside2(htmlPath, projectDir)) return html;
4468
+ if (!isPathInside(htmlPath, projectDir)) return html;
4410
4469
  const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
4411
4470
  if (!entryPath.includes("/")) return html;
4412
4471
  const { document: document2 } = parseHTML5(html);
@@ -4448,9 +4507,10 @@ function bindVariableMediaSources(html, variables) {
4448
4507
  }
4449
4508
  return changed ? document2.toString() : html;
4450
4509
  }
4510
+ var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ? relative2(projectDir, htmlPath).split(sep3).join("/") : basename3(htmlPath);
4451
4511
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
4452
4512
  const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
4453
- if (isPathInside2(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
4513
+ if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
4454
4514
  throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
4455
4515
  }
4456
4516
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
@@ -4562,8 +4622,18 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4562
4622
  if (preparedGifs.length > 0) {
4563
4623
  defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
4564
4624
  }
4565
- const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir, assetRoot);
4566
- const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(embeddedHtml, projectDir) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
4625
+ const embeddedHtml = await embedLocalFontFaces(
4626
+ htmlWithPreparedGifs,
4627
+ projectDir,
4628
+ assetRoot,
4629
+ options.log
4630
+ );
4631
+ const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
4632
+ embeddedHtml,
4633
+ projectDir,
4634
+ options.log,
4635
+ entryFileName(projectDir, htmlPath)
4636
+ ) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
4567
4637
  for (const [relPath, absPath] of remoteMediaAssets) {
4568
4638
  externalAssets.set(relPath, absPath);
4569
4639
  }
@@ -5134,9 +5204,13 @@ async function runCompileStage(input) {
5134
5204
  width: compiled.width,
5135
5205
  height: compiled.height
5136
5206
  };
5137
- if (!job.config.allowOutsideProjectAssets) {
5138
- dropMediaOutsideProject({ projectDir, workDir, composition, log });
5139
- }
5207
+ dropMediaOutsideProject({
5208
+ projectDir,
5209
+ workDir,
5210
+ composition,
5211
+ log,
5212
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
5213
+ });
5140
5214
  await preflightCompositionAssetMediaTypes({
5141
5215
  projectDir,
5142
5216
  compiledDir: join10(workDir, "compiled"),
@@ -5761,9 +5835,13 @@ async function runProbeStage(input) {
5761
5835
  }
5762
5836
  }
5763
5837
  }
5764
- if (!job.config.allowOutsideProjectAssets) {
5765
- dropMediaOutsideProject({ projectDir, workDir, composition, log });
5766
- }
5838
+ dropMediaOutsideProject({
5839
+ projectDir,
5840
+ workDir,
5841
+ composition,
5842
+ log,
5843
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
5844
+ });
5767
5845
  await preflightCompositionAssetMediaTypes({
5768
5846
  projectDir,
5769
5847
  compiledDir: join11(workDir, "compiled"),
@@ -7540,7 +7618,7 @@ import {
7540
7618
  readdirSync as readdirSync2,
7541
7619
  readFileSync as readFileSync6,
7542
7620
  rmSync as rmSync4,
7543
- statSync as statSync4,
7621
+ statSync as statSync5,
7544
7622
  writeFileSync as writeFileSync4
7545
7623
  } from "node:fs";
7546
7624
  import { readFile as readFile2 } from "node:fs/promises";
@@ -7669,7 +7747,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
7669
7747
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
7670
7748
  if (failure) return failure;
7671
7749
  }
7672
- const fileSize = existsSync13(outputPath) ? statSync4(outputPath).size : 0;
7750
+ const fileSize = existsSync13(outputPath) ? statSync5(outputPath).size : 0;
7673
7751
  return {
7674
7752
  success: true,
7675
7753
  outputPath,
@@ -7923,7 +8001,7 @@ function sampleDirectoryBytes(dir) {
7923
8001
  for (const name of entries) {
7924
8002
  const full = join18(current, name);
7925
8003
  try {
7926
- const st = statSync5(full);
8004
+ const st = statSync6(full);
7927
8005
  if (st.isDirectory()) {
7928
8006
  stack.push(full);
7929
8007
  } else if (st.isFile()) {
@@ -8004,7 +8082,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
8004
8082
  let rangeStart = null;
8005
8083
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
8006
8084
  const framePath = join18(framesDir, formatCaptureFrameName(frameIndex, frameExt));
8007
- const missing = !existsSync14(framePath) || statSync5(framePath).size <= 8;
8085
+ const missing = !existsSync14(framePath) || statSync6(framePath).size <= 8;
8008
8086
  if (missing && rangeStart === null) {
8009
8087
  rangeStart = frameIndex;
8010
8088
  } else if (!missing && rangeStart !== null) {
@@ -10402,7 +10480,7 @@ function pathInside(root, path) {
10402
10480
  function stableSourcePath(roots, srcPath) {
10403
10481
  for (const [root, prefix] of roots) {
10404
10482
  const rel = pathInside(root, srcPath);
10405
- if (rel !== null) return [prefix, ...rel.split(sep3)].filter(Boolean).join("/");
10483
+ if (rel !== null) return [prefix, ...rel.split(sep4)].filter(Boolean).join("/");
10406
10484
  }
10407
10485
  return srcPath;
10408
10486
  }
@@ -10417,7 +10495,7 @@ function createVideoSourceShipper(input) {
10417
10495
  for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
10418
10496
  const rel = pathInside(root, srcPath);
10419
10497
  if (rel !== null && (existsSync19(join27(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
10420
- result = ["compiled", ...rel.split(sep3)].join("/");
10498
+ result = ["compiled", ...rel.split(sep4)].join("/");
10421
10499
  break;
10422
10500
  }
10423
10501
  }
@@ -10492,8 +10570,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
10492
10570
  filter: (src) => {
10493
10571
  const rel = relative6(projectDir, src);
10494
10572
  if (rel === "" || rel.startsWith("..")) return true;
10495
- if (!job.config.allowOutsideProjectAssets && !isSafePath2(projectDir, src)) return false;
10496
- const firstSegment = rel.split(sep3, 1)[0];
10573
+ if (job.config.allowOutsideProjectAssets) {
10574
+ if (refusesOutsideLink(projectDir, src, (line) => log.warn(`[Plan] ${line}`))) return false;
10575
+ } else if (!isSafePath2(projectDir, src)) return false;
10576
+ const firstSegment = rel.split(sep4, 1)[0];
10497
10577
  return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
10498
10578
  }
10499
10579
  });
@@ -10974,11 +11054,11 @@ import {
10974
11054
  readFileSync as readFileSync10,
10975
11055
  readdirSync as readdirSync7,
10976
11056
  rmSync as rmSync9,
10977
- statSync as statSync7,
11057
+ statSync as statSync8,
10978
11058
  writeFileSync as writeFileSync10
10979
11059
  } from "node:fs";
10980
11060
  import { tmpdir } from "node:os";
10981
- import { dirname as dirname14, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep4 } from "node:path";
11061
+ import { dirname as dirname14, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
10982
11062
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
10983
11063
  import {
10984
11064
  createFrameLookupTable as createFrameLookupTable5,
@@ -10993,7 +11073,7 @@ import {
10993
11073
  linkSync as linkSync2,
10994
11074
  mkdirSync as mkdirSync11,
10995
11075
  rmSync as rmSync8,
10996
- statSync as statSync6,
11076
+ statSync as statSync7,
10997
11077
  writeFileSync as writeFileSync9
10998
11078
  } from "node:fs";
10999
11079
  import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
@@ -11068,7 +11148,7 @@ var LocalPlanV2ArtifactPublisher = class {
11068
11148
  }
11069
11149
  async putBlob(blob) {
11070
11150
  const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
11071
- const sourceSize = statSync6(blob.sourcePath).size;
11151
+ const sourceSize = statSync7(blob.sourcePath).size;
11072
11152
  if (sourceSize !== blob.sizeBytes) {
11073
11153
  throw new PlanV2IntegrityError(
11074
11154
  `published blob size changed for ${digest}: expected ${blob.sizeBytes}, got ${sourceSize}`
@@ -11150,7 +11230,7 @@ function listFiles(root) {
11150
11230
  walk(absolutePath);
11151
11231
  } else if (entry.isFile()) {
11152
11232
  files.push({
11153
- path: relative7(rootResolved, absolutePath).split(sep4).join("/"),
11233
+ path: relative7(rootResolved, absolutePath).split(sep5).join("/"),
11154
11234
  absolutePath
11155
11235
  });
11156
11236
  } else {
@@ -11190,7 +11270,7 @@ function isExtractionCacheCompleteSentinelPath(path) {
11190
11270
  function resolveExtractedVideoOutputDir(planDir, videoId) {
11191
11271
  const videoRoot = resolve9(planDir, "video-frames");
11192
11272
  const outputDir = resolve9(videoRoot, mediaIdPathSegment4(videoId));
11193
- if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep4}`)) {
11273
+ if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep5}`)) {
11194
11274
  throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
11195
11275
  }
11196
11276
  return outputDir;
@@ -11350,7 +11430,7 @@ function collectChunkVideoDependencies(input) {
11350
11430
  for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
11351
11431
  const globalTime = frame * input.fpsDen / input.fpsNum;
11352
11432
  for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
11353
- const path = input.deferredSources.get(videoId) ?? relative7(resolve9(input.executionPlanDir), payload.framePath).split(sep4).join("/");
11433
+ const path = input.deferredSources.get(videoId) ?? relative7(resolve9(input.executionPlanDir), payload.framePath).split(sep5).join("/");
11354
11434
  assertSafeRelativePath(path);
11355
11435
  const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
11356
11436
  indexes.add(chunk.index);
@@ -11382,7 +11462,7 @@ function publishBlobFor(absolutePath, digests) {
11382
11462
  return {
11383
11463
  sourcePath: absolutePath,
11384
11464
  sha256: planFileSha256(absolutePath, digests),
11385
- sizeBytes: statSync7(absolutePath).size
11465
+ sizeBytes: statSync8(absolutePath).size
11386
11466
  };
11387
11467
  }
11388
11468
  async function putBlobs(publisher, blobs) {
@@ -11750,7 +11830,7 @@ function verifyBlob(planV2Dir, artifact) {
11750
11830
  if (!existsSync21(sourcePath)) {
11751
11831
  throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
11752
11832
  }
11753
- const stats = statSync7(sourcePath);
11833
+ const stats = statSync8(sourcePath);
11754
11834
  if (!stats.isFile() || stats.size !== artifact.sizeBytes) {
11755
11835
  throw new PlanV2IntegrityError(`artifact size mismatch for ${artifact.path}`);
11756
11836
  }
@@ -11843,7 +11923,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
11843
11923
  for (const artifact of required) {
11844
11924
  if (Object.hasOwn(remoteSources, artifact.path)) continue;
11845
11925
  const path = join30(planDir, ...artifact.path.split("/"));
11846
- if (!existsSync21(path) || statSync7(path).size !== artifact.sizeBytes) {
11926
+ if (!existsSync21(path) || statSync8(path).size !== artifact.sizeBytes) {
11847
11927
  throw new PlanV2IntegrityError(
11848
11928
  `materialized artifact missing or truncated: ${artifact.path}`
11849
11929
  );
@@ -11872,7 +11952,7 @@ import {
11872
11952
  readFileSync as readFileSync11,
11873
11953
  readdirSync as readdirSync8,
11874
11954
  rmSync as rmSync10,
11875
- statSync as statSync8,
11955
+ statSync as statSync9,
11876
11956
  writeFileSync as writeFileSync11
11877
11957
  } from "node:fs";
11878
11958
  import { basename as basename6, dirname as dirname15, join as join31 } from "node:path";
@@ -11917,7 +11997,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11917
11997
  outputPath,
11918
11998
  durationMs: Date.now() - start,
11919
11999
  framesEncoded: plan.totalFrames,
11920
- fileSize: statSync8(outputPath).size
12000
+ fileSize: statSync9(outputPath).size
11921
12001
  };
11922
12002
  }
11923
12003
  const format = plan.dimensions.format;
@@ -11964,7 +12044,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
11964
12044
  });
11965
12045
  }
11966
12046
  }
11967
- const fileSize = existsSync22(outputPath) ? statSync8(outputPath).size : 0;
12047
+ const fileSize = existsSync22(outputPath) ? statSync9(outputPath).size : 0;
11968
12048
  return {
11969
12049
  ...referenceBackgroundResult6(plan[REFERENCE_BACKGROUND_FIELD4]),
11970
12050
  outputPath,
@@ -12162,7 +12242,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12162
12242
  mkdirSync13(outputPath, { recursive: true });
12163
12243
  let globalIdx = 0;
12164
12244
  for (const chunkDir of chunkPaths) {
12165
- if (!statSync8(chunkDir).isDirectory()) {
12245
+ if (!statSync9(chunkDir).isDirectory()) {
12166
12246
  throw new Error(
12167
12247
  `[assemble] png-sequence chunk must be a directory: ${chunkDir} (got a file)`
12168
12248
  );
@@ -12189,7 +12269,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12189
12269
  let fileSize = 0;
12190
12270
  for (const name of readdirSync8(outputPath)) {
12191
12271
  try {
12192
- fileSize += statSync8(join31(outputPath, name)).size;
12272
+ fileSize += statSync9(join31(outputPath, name)).size;
12193
12273
  } catch {
12194
12274
  }
12195
12275
  }
@@ -13241,7 +13321,7 @@ function validateIntDimension(field, value) {
13241
13321
  }
13242
13322
 
13243
13323
  // src/services/distributed/projectHash.ts
13244
- import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync9 } from "node:fs";
13324
+ import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync10 } from "node:fs";
13245
13325
  import { createHash as createHash9 } from "node:crypto";
13246
13326
  import { join as join34 } from "node:path";
13247
13327
  var SITE_ID_SCHEME = "site-v2\0";
@@ -13258,7 +13338,7 @@ function listSiteFiles(projectDir) {
13258
13338
  const relPath = rel === "" ? name : `${rel}/${name}`;
13259
13339
  let stat;
13260
13340
  try {
13261
- stat = statSync9(full);
13341
+ stat = statSync10(full);
13262
13342
  } catch (err) {
13263
13343
  throw new Error(`[listSiteFiles] cannot read ${relPath} (dangling symlink?)`, {
13264
13344
  cause: err