@hyperframes/producer 0.9.52 → 0.9.54

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.
@@ -198,13 +198,13 @@ import {
198
198
  referenceBackgroundResult,
199
199
  createReferenceBackgroundRecorder
200
200
  } from "@hyperframes/engine";
201
- import { join as join18, dirname as dirname10, resolve as resolve7 } from "path";
201
+ import { join as join18, dirname as dirname11, resolve as resolve7 } from "path";
202
202
  import { randomUUID } from "crypto";
203
203
 
204
204
  // src/services/fileServer.ts
205
205
  import { Hono } from "hono";
206
206
  import { serve } from "@hono/node-server";
207
- import { settleOnBrowserSafePort } from "@hyperframes/engine";
207
+ import { answerOwnLoopbackHostOnly, settleOnBrowserSafePort } from "@hyperframes/engine";
208
208
  import {
209
209
  existsSync as existsSync2,
210
210
  realpathSync,
@@ -221,7 +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
+ import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
225
225
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
226
226
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
227
227
 
@@ -329,6 +329,7 @@ var MIME_TYPES = {
329
329
  ".css": "text/css; charset=utf-8",
330
330
  ".js": "application/javascript; charset=utf-8",
331
331
  ".mjs": "application/javascript; charset=utf-8",
332
+ ".cjs": "application/javascript; charset=utf-8",
332
333
  ".json": "application/json; charset=utf-8",
333
334
  ".cube": "text/plain; charset=utf-8",
334
335
  ".png": "image/png",
@@ -868,6 +869,12 @@ function createFileServer(options) {
868
869
  const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
869
870
  const app = new Hono();
870
871
  const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
872
+ let listeningPort = -1;
873
+ app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
874
+ await next();
875
+ c.res.headers.set("X-Content-Type-Options", "nosniff");
876
+ });
877
+ answerOwnLoopbackHostOnly(app, () => listeningPort);
871
878
  app.get("/*", async (c) => {
872
879
  let requestPath = c.req.path;
873
880
  if (requestPath === "/") requestPath = "/index.html";
@@ -877,7 +884,7 @@ function createFileServer(options) {
877
884
  const candidate = join2(root, relativePath);
878
885
  const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
879
886
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
880
- if (isPrivateFileUnder(root, candidate, isVcsOrSecretPath)) continue;
887
+ if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) continue;
881
888
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
882
889
  if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
883
890
  file = openRegularFile(candidate);
@@ -963,6 +970,7 @@ function createFileServer(options) {
963
970
  const server = serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, (info) => {
964
971
  const bound = port === 0 ? settleOnBrowserSafePort(server, "127.0.0.1") : Promise.resolve(info.port);
965
972
  bound.then((boundPort) => {
973
+ listeningPort = boundPort;
966
974
  resolve10({
967
975
  url: `http://localhost:${boundPort}`,
968
976
  port: boundPort,
@@ -1055,6 +1063,9 @@ import {
1055
1063
  import {
1056
1064
  mediaIdPathSegment
1057
1065
  } from "@hyperframes/engine";
1066
+ function audioWorkDir(workDir) {
1067
+ return join3(workDir, "audio-work");
1068
+ }
1058
1069
  var BROWSER_MEDIA_EPSILON = 1e-4;
1059
1070
  function resolveBrowserMediaEnd(start, end, duration) {
1060
1071
  return Number.isFinite(duration) && duration > 0 ? start + duration : end;
@@ -2220,15 +2231,29 @@ import {
2220
2231
  // src/services/render/stages/compileStage.ts
2221
2232
  import { existsSync as existsSync8, writeFileSync as writeFileSync3 } from "node:fs";
2222
2233
  import { join as join10, relative as relative3 } from "node:path";
2234
+ import { privateCacheRoot } from "@hyperframes/engine";
2223
2235
  import { suggestMatchingPreset } from "@hyperframes/core";
2224
2236
  import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
2225
2237
  import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
2226
2238
 
2227
2239
  // src/services/htmlCompiler.ts
2228
2240
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
2241
+ import {
2242
+ cssRuleMatches,
2243
+ cssUrlMatches,
2244
+ fontFaceBlockMatches,
2245
+ hasBackgroundImageDeclaration,
2246
+ importRuleMatches,
2247
+ localFontFaceUrlMatches,
2248
+ remoteBackgroundUrlMatches,
2249
+ remoteFontFaceUrlMatches,
2250
+ replaceMatches,
2251
+ styleBlockMatches,
2252
+ stylesheetLinkMatches
2253
+ } from "@hyperframes/parsers/css-url-scans";
2229
2254
  import { createHash as createHash5 } from "node:crypto";
2230
2255
  import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
2231
- import { join as join9, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep3 } from "path";
2256
+ import { join as join9, dirname as dirname7, resolve as resolve6, basename as basename3, relative as relative2, sep as sep3 } from "path";
2232
2257
  import { parseHTML as parseHTML5 } from "linkedom";
2233
2258
 
2234
2259
  // src/services/bundledScripts.ts
@@ -2251,7 +2276,6 @@ import {
2251
2276
  extractResolvedMedia,
2252
2277
  clampDurations,
2253
2278
  shouldClampResolvedMediaDuration,
2254
- CSS_URL_RE,
2255
2279
  isNonRelativeUrl,
2256
2280
  parseStrictFiniteTimingNumber,
2257
2281
  readMediaStart,
@@ -2301,7 +2325,7 @@ import {
2301
2325
  readTextFile,
2302
2326
  resolveCompositionSrc
2303
2327
  } from "@hyperframes/parsers/asset-resolution";
2304
- import { isPrivateFileUnder as isPrivateFileUnder2, isVcsOrSecretPath as isVcsOrSecretPath2 } from "@hyperframes/core/safe-path";
2328
+ import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
2305
2329
 
2306
2330
  // src/services/renderMediaCollector.ts
2307
2331
  import { parseHTML as parseHTML2 } from "linkedom";
@@ -3133,9 +3157,11 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
3133
3157
 
3134
3158
  // src/services/assetMediaType.ts
3135
3159
  import { existsSync as existsSync6 } from "node:fs";
3136
- import { join as join8 } from "node:path";
3160
+ import { dirname as dirname6, join as join8 } from "node:path";
3137
3161
  import {
3138
3162
  fingerprintElementId,
3163
+ isHttpUrl as isHttpUrl2,
3164
+ isInsideAssetRoots,
3139
3165
  isNotMediaPayload,
3140
3166
  playlistLeavesItsFolder,
3141
3167
  NotMediaPayloadError,
@@ -3181,17 +3207,17 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
3181
3207
  }
3182
3208
  ]);
3183
3209
  }
3184
- function isRemoteOrInlineSource(src) {
3185
- return /^(?:https?:|data:|blob:|about:)/i.test(src.trim());
3210
+ function mediaAssetRoots(projectDir, compiledDir) {
3211
+ return [projectDir, compiledDir, join8(dirname6(compiledDir), "downloads")];
3186
3212
  }
3187
3213
  function dropMediaOutsideProject(input) {
3188
3214
  const { projectDir, workDir, composition, log } = input;
3189
3215
  const compiledDir = join8(workDir, "compiled");
3190
- const roots = [projectDir, compiledDir, join8(workDir, "downloads")];
3216
+ const roots = mediaAssetRoots(projectDir, compiledDir);
3191
3217
  const staysInside = ({ id, src }) => {
3192
- if (!src || isRemoteOrInlineSource(src)) return true;
3218
+ if (!src || isHttpUrl2(src)) return true;
3193
3219
  const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
3194
- if (roots.some((root) => !escapesAssetRoot(path, root))) return true;
3220
+ if (isInsideAssetRoots(path, roots)) return true;
3195
3221
  if (input.allowOutsideProjectAssets) {
3196
3222
  const refusal = outsideAssetRefusal(projectDir, path);
3197
3223
  if (refusal) log.warn(`[Render] ${leftOutOfRender(`Media "${id}"`, src, refusal)}`);
@@ -3229,7 +3255,7 @@ async function preflightCompositionAssetMediaTypes(input) {
3229
3255
  ];
3230
3256
  const byPath = /* @__PURE__ */ new Map();
3231
3257
  for (const reference of references) {
3232
- if (!reference.src || isRemoteOrInlineSource(reference.src)) continue;
3258
+ if (!reference.src || isHttpUrl2(reference.src)) continue;
3233
3259
  const resolvedPath = resolveProjectRelativeSrc3(
3234
3260
  reference.src,
3235
3261
  input.projectDir,
@@ -3329,11 +3355,17 @@ function normalizeCompositionSrcs(html, projectDir) {
3329
3355
  return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
3330
3356
  });
3331
3357
  }
3332
- function resolveCompositionFile(projectDir, src, assetRoot) {
3358
+ var COMPOSITION_FILE = /\.html?$/i;
3359
+ var NOT_A_COMPOSITION_FILE = "it is not an .html file, so it is refused";
3360
+ function resolveCompositionPath(projectDir, src, assetRoot) {
3333
3361
  const file = resolveCompositionSrc(projectDir, src);
3334
3362
  return file === null || escapesAssetRoot(file, assetRoot) ? null : file;
3335
3363
  }
3336
- var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isVcsOrSecretPath2);
3364
+ function resolveCompositionFile(projectDir, src, assetRoot) {
3365
+ const file = resolveCompositionPath(projectDir, src, assetRoot);
3366
+ return file !== null && COMPOSITION_FILE.test(file) ? file : null;
3367
+ }
3368
+ var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
3337
3369
  function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
3338
3370
  const { document: document2 } = parseHTML5(html);
3339
3371
  const hosts = [...document2.querySelectorAll("[data-composition-src]")];
@@ -3342,7 +3374,7 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
3342
3374
  const srcPath = el.getAttribute("data-composition-src");
3343
3375
  if (!srcPath) continue;
3344
3376
  if (isUnresolvedAssetPlaceholder(srcPath)) continue;
3345
- const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
3377
+ const filePath = resolveCompositionPath(projectDir, srcPath, assetRoot);
3346
3378
  if (filePath === null) {
3347
3379
  problems.push({ srcPath, detail: "it is outside the project folder" });
3348
3380
  continue;
@@ -3352,7 +3384,14 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
3352
3384
  continue;
3353
3385
  }
3354
3386
  if (isPrivateCompositionFile(projectDir, filePath)) {
3355
- problems.push({ srcPath, detail: "it is git metadata or an env file" });
3387
+ problems.push({
3388
+ srcPath,
3389
+ detail: "it is git metadata, an env file or a private tool record"
3390
+ });
3391
+ continue;
3392
+ }
3393
+ if (!COMPOSITION_FILE.test(filePath)) {
3394
+ problems.push({ srcPath, detail: NOT_A_COMPOSITION_FILE });
3356
3395
  continue;
3357
3396
  }
3358
3397
  if (visited.has(filePath)) continue;
@@ -3450,7 +3489,6 @@ var THREE_D_CONTEXT_PATTERN = /transform-style\s*:\s*preserve-3d|backface-visibi
3450
3489
  function detectThreeDTransformUsage(html) {
3451
3490
  return THREE_D_CONTEXT_PATTERN.test(html);
3452
3491
  }
3453
- var BACKGROUND_IMAGE_DECL_PATTERN = /(?:^|;|\{)\s*background(?:-image)?\s*:[^;}]*(?:\bgradient\s*\(|url\s*\()/i;
3454
3492
  function detectAncestorBackgroundImage(html) {
3455
3493
  const { document: document2 } = parseHTML5(html);
3456
3494
  const root = document2.querySelector("[data-composition-id]");
@@ -3462,13 +3500,13 @@ function detectAncestorBackgroundImage(html) {
3462
3500
  }
3463
3501
  for (const el of ancestors) {
3464
3502
  const style = el.getAttribute("style");
3465
- if (style && BACKGROUND_IMAGE_DECL_PATTERN.test(`{${style}}`)) return true;
3503
+ if (style && hasBackgroundImageDeclaration(`{${style}}`)) return true;
3466
3504
  }
3467
3505
  for (const styleEl of document2.querySelectorAll("style")) {
3468
3506
  const css = styleEl.textContent ?? "";
3469
- for (const rule of css.matchAll(/([^{}]+)\{([^}]*)\}/g)) {
3470
- const [, selectorList = "", declarations = ""] = rule;
3471
- if (!BACKGROUND_IMAGE_DECL_PATTERN.test(`{${declarations}}`)) continue;
3507
+ for (const { parts: rule } of cssRuleMatches(css)) {
3508
+ const [, selectorList, declarations] = rule;
3509
+ if (!hasBackgroundImageDeclaration(`{${declarations}}`)) continue;
3472
3510
  for (const selector of selectorList.split(",")) {
3473
3511
  const sel = selector.trim();
3474
3512
  if (!sel || sel.startsWith("@")) continue;
@@ -3678,7 +3716,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
3678
3716
  workItems.map(async (item) => {
3679
3717
  const { html: compiledSub } = await compileHtmlFile(
3680
3718
  rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
3681
- dirname6(item.filePath),
3719
+ dirname7(item.filePath),
3682
3720
  downloadDir,
3683
3721
  void 0,
3684
3722
  urlByAbsentLocalPath,
@@ -3789,7 +3827,6 @@ function coalesceHeadStylesAndBodyScripts(html) {
3789
3827
  el.textContent = dedupedStyles[i] ?? "";
3790
3828
  });
3791
3829
  const styleEls = head ? Array.from(head.querySelectorAll("style")) : [];
3792
- const importRe = /@import\s+url\([^)]*\)\s*;|@import\s+["'][^"']+["']\s*;/gi;
3793
3830
  for (const run of styleEls.length > 1 ? headStyleRuns(styleEls) : []) {
3794
3831
  const imports = [];
3795
3832
  const cssParts = [];
@@ -3797,7 +3834,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
3797
3834
  for (const el of run) {
3798
3835
  const raw = (el.textContent || "").trim();
3799
3836
  if (!raw) continue;
3800
- const nonImportCss = raw.replace(importRe, (match) => {
3837
+ const nonImportCss = replaceMatches(raw, importRuleMatches(raw), (match) => {
3801
3838
  const cleaned = match.trim();
3802
3839
  if (!seenImports.has(cleaned)) {
3803
3840
  seenImports.add(cleaned);
@@ -4107,7 +4144,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
4107
4144
  for (const styleEl of document2.querySelectorAll("style")) {
4108
4145
  const css = styleEl.textContent || "";
4109
4146
  if (!css.includes("url(")) continue;
4110
- const rewritten = css.replace(CSS_URL_RE, (full, quote, rawUrl) => {
4147
+ const rewritten = replaceMatches(css, cssUrlMatches(css), (full, quote, rawUrl) => {
4111
4148
  const result = processPath((rawUrl || "").trim());
4112
4149
  if (!result) return full;
4113
4150
  return `url(${quote || ""}${result}${quote || ""})`;
@@ -4117,7 +4154,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
4117
4154
  for (const el of document2.querySelectorAll("[style]")) {
4118
4155
  const style = el.getAttribute("style") || "";
4119
4156
  if (!style.includes("url(")) continue;
4120
- const rewritten = style.replace(CSS_URL_RE, (full, quote, rawUrl) => {
4157
+ const rewritten = replaceMatches(style, cssUrlMatches(style), (full, quote, rawUrl) => {
4121
4158
  const result = processPath((rawUrl || "").trim());
4122
4159
  if (!result) return full;
4123
4160
  return `url(${quote || ""}${result}${quote || ""})`;
@@ -4220,13 +4257,10 @@ async function localizeRemoteImageSources(html, downloadDir) {
4220
4257
  "Localized remote image source(s)"
4221
4258
  );
4222
4259
  }
4223
- var REMOTE_BG_URL_RE = /background(?:-image)?\s*:\s*[^;}"']*?url\(\s*["']?(https?:\/\/[^"')]+)["']?\s*\)/gi;
4224
4260
  async function localizeRemoteBackgroundImages(html, downloadDir) {
4225
4261
  const urlSet = /* @__PURE__ */ new Set();
4226
- const re = new RegExp(REMOTE_BG_URL_RE.source, REMOTE_BG_URL_RE.flags);
4227
- let m;
4228
- while ((m = re.exec(html)) !== null) {
4229
- if (m[1] && !isGoogleFontsUrl(m[1])) urlSet.add(m[1]);
4262
+ for (const { parts } of remoteBackgroundUrlMatches(html)) {
4263
+ if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
4230
4264
  }
4231
4265
  return downloadAndRewriteUrls(
4232
4266
  urlSet,
@@ -4239,7 +4273,6 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
4239
4273
  (h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
4240
4274
  );
4241
4275
  }
4242
- var REMOTE_FONTFACE_URL_RE = /url\(["']?(https?:\/\/[^"')]+)["']?\)/gi;
4243
4276
  function isGoogleFontsUrl(href) {
4244
4277
  try {
4245
4278
  const host = new URL(href).hostname.toLowerCase();
@@ -4267,31 +4300,33 @@ async function fetchExternalStylesheetCss(href) {
4267
4300
  }
4268
4301
  function extractFontFaceBlocks(css) {
4269
4302
  const blocks = [];
4303
+ const closes = matchingBraces(css);
4270
4304
  const atRule = /@font-face\s*/gi;
4271
- let m;
4272
- while ((m = atRule.exec(css)) !== null) {
4273
- const openIdx = css.indexOf("{", m.index + m[0].length);
4274
- if (openIdx === -1) break;
4275
- let depth = 1;
4276
- let i = openIdx + 1;
4277
- for (; i < css.length && depth > 0; i++) {
4278
- if (css[i] === "{") depth++;
4279
- else if (css[i] === "}") depth--;
4280
- }
4281
- if (depth === 0) {
4282
- blocks.push(css.slice(m.index, i));
4283
- atRule.lastIndex = i;
4284
- }
4305
+ let open2 = -1;
4306
+ for (let m = atRule.exec(css); m; m = atRule.exec(css)) {
4307
+ if (open2 < atRule.lastIndex) open2 = css.indexOf("{", atRule.lastIndex);
4308
+ if (open2 === -1) break;
4309
+ const close = closes.get(open2);
4310
+ if (close === void 0) continue;
4311
+ blocks.push(css.slice(m.index, close + 1));
4312
+ atRule.lastIndex = close + 1;
4285
4313
  }
4286
4314
  return blocks;
4287
4315
  }
4316
+ function matchingBraces(css) {
4317
+ const closes = /* @__PURE__ */ new Map();
4318
+ const unclosed = [];
4319
+ for (let i = 0; i < css.length; i++) {
4320
+ if (css[i] === "{") unclosed.push(i);
4321
+ else if (css[i] === "}" && unclosed.length > 0) closes.set(unclosed.pop(), i);
4322
+ }
4323
+ return closes;
4324
+ }
4288
4325
  async function inlineExternalFontStylesheets(html) {
4289
- const linkRe = /<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi;
4290
4326
  const hrefRe = /\bhref=["']([^"']+)["']/i;
4291
4327
  const linkMatches = [];
4292
- let linkMatch;
4293
- while ((linkMatch = linkRe.exec(html)) !== null) {
4294
- const tag = linkMatch[0];
4328
+ for (const { parts } of stylesheetLinkMatches(html)) {
4329
+ const tag = parts[0];
4295
4330
  const hrefMatch = hrefRe.exec(tag);
4296
4331
  if (!hrefMatch?.[1]) continue;
4297
4332
  const href = hrefMatch[1];
@@ -4332,16 +4367,18 @@ ${fontFaceBlocks.join("\n")}
4332
4367
  }
4333
4368
  function projectStylesheetFontFamilies(html, projectDir) {
4334
4369
  const families = [];
4335
- for (const [tag] of html.matchAll(/<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi)) {
4370
+ for (const {
4371
+ parts: [tag]
4372
+ } of stylesheetLinkMatches(html)) {
4336
4373
  const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
4337
4374
  if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
4338
4375
  const sheet = resolve6(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
4339
4376
  if (!isPathInside(sheet, projectDir) || !existsSync7(sheet)) continue;
4340
4377
  for (const face of extractFontFaceBlocks(readFileSync5(sheet, "utf8"))) {
4341
4378
  const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
4342
- const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
4379
+ const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
4343
4380
  const path = decodedUrlPath(url);
4344
- const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname6(sheet), path);
4381
+ const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname7(sheet), path);
4345
4382
  return isPathInside(file, projectDir) && existsSync7(file);
4346
4383
  });
4347
4384
  if (family && shipsFile) families.push(family);
@@ -4350,11 +4387,9 @@ function projectStylesheetFontFamilies(html, projectDir) {
4350
4387
  return families;
4351
4388
  }
4352
4389
  function collectFontFaceUrls(html) {
4353
- const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
4354
4390
  const urlSet = /* @__PURE__ */ new Set();
4355
- let styleMatch;
4356
- while ((styleMatch = styleBlockRe.exec(html)) !== null) {
4357
- const cssText = styleMatch[1] ?? "";
4391
+ for (const { parts } of styleBlockMatches(html)) {
4392
+ const cssText = parts[1];
4358
4393
  let i = 0;
4359
4394
  while (i < cssText.length) {
4360
4395
  const atIdx = cssText.indexOf("@font-face", i);
@@ -4369,10 +4404,8 @@ function collectFontFaceUrls(html) {
4369
4404
  j++;
4370
4405
  }
4371
4406
  const block = cssText.slice(braceStart + 1, j - 1);
4372
- const urlRe = new RegExp(REMOTE_FONTFACE_URL_RE.source, REMOTE_FONTFACE_URL_RE.flags);
4373
- let urlMatch;
4374
- while ((urlMatch = urlRe.exec(block)) !== null) {
4375
- if (urlMatch[1]) urlSet.add(urlMatch[1]);
4407
+ for (const { parts: parts2 } of remoteFontFaceUrlMatches(block)) {
4408
+ if (parts2[1]) urlSet.add(parts2[1]);
4376
4409
  }
4377
4410
  i = j;
4378
4411
  }
@@ -4389,7 +4422,6 @@ function localizeFontFaceUrls(html, downloadDir) {
4389
4422
  (h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
4390
4423
  );
4391
4424
  }
4392
- var LOCAL_FONTFACE_URL_RE = /url\(["']?(?!data:|file:|https?:\/\/)([^"')]+)["']?\)/gi;
4393
4425
  function urlOccurrenceRe(localPath) {
4394
4426
  const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4395
4427
  return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
@@ -4410,23 +4442,15 @@ async function readLocalFont(absPath) {
4410
4442
  }
4411
4443
  async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLogger) {
4412
4444
  const { fontToDataUri: toDataUri } = await import("@hyperframes/core/fonts/embed");
4413
- const styleBlockRe = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
4414
- const fontFaceRe = /@font-face\s*\{([^}]*)\}/gi;
4415
4445
  let result = html;
4416
4446
  const embeddedPaths = /* @__PURE__ */ new Set();
4417
4447
  const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
4418
4448
  const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
4419
- let styleMatch;
4420
- while ((styleMatch = styleBlockRe.exec(html)) !== null) {
4421
- const cssText = styleMatch[1] ?? "";
4422
- const ffRe = new RegExp(fontFaceRe.source, fontFaceRe.flags);
4423
- let ffMatch;
4424
- while ((ffMatch = ffRe.exec(cssText)) !== null) {
4425
- const block = ffMatch[1] ?? "";
4426
- const urlRe = new RegExp(LOCAL_FONTFACE_URL_RE.source, LOCAL_FONTFACE_URL_RE.flags);
4427
- let urlMatch;
4428
- while ((urlMatch = urlRe.exec(block)) !== null) {
4429
- const localPath = urlMatch[1];
4449
+ for (const { parts: style } of styleBlockMatches(html)) {
4450
+ for (const { parts: face } of fontFaceBlockMatches(style[1])) {
4451
+ const block = face[1];
4452
+ for (const { parts } of localFontFaceUrlMatches(block)) {
4453
+ const localPath = parts[1];
4430
4454
  if (!localPath || embeddedPaths.has(localPath)) continue;
4431
4455
  const absPath = localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath);
4432
4456
  if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) continue;
@@ -4545,6 +4569,9 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
4545
4569
  if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
4546
4570
  throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
4547
4571
  }
4572
+ if (!COMPOSITION_FILE.test(htmlPath)) {
4573
+ throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
4574
+ }
4548
4575
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
4549
4576
  const rawHtml = bindVariableMediaSources(
4550
4577
  normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
@@ -5100,6 +5127,14 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
5100
5127
  }
5101
5128
 
5102
5129
  // src/services/render/stages/compileStage.ts
5130
+ function animatedGifCacheDir(extractCacheDir) {
5131
+ try {
5132
+ const root = extractCacheDir && privateCacheRoot(extractCacheDir);
5133
+ return root ? join10(root, "animated-gif") : void 0;
5134
+ } catch {
5135
+ return void 0;
5136
+ }
5137
+ }
5103
5138
  function adaptAspectAgnosticResolution(requested, aspectAgnostic, width, height, log) {
5104
5139
  if (!requested || !aspectAgnostic) return requested;
5105
5140
  const flipped = suggestMatchingPreset(width, height, requested);
@@ -5179,7 +5214,7 @@ async function runCompileStage(input) {
5179
5214
  variables: input.variables,
5180
5215
  urlByAbsentLocalPath: input.urlByAbsentLocalPath,
5181
5216
  pageMotionBlur: input.pageMotionBlur,
5182
- animatedGifCacheDir: cfg.extractCacheDir ? join10(cfg.extractCacheDir, "animated-gif") : void 0,
5217
+ animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
5183
5218
  ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
5184
5219
  allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
5185
5220
  });
@@ -6057,8 +6092,13 @@ import {
6057
6092
  rebaseVideoToWindow,
6058
6093
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
6059
6094
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
6060
- isHttpUrl as isHttpUrl2,
6095
+ isHttpUrl as isHttpUrl3,
6096
+ isInsideAssetRoots as isInsideAssetRoots2,
6061
6097
  assertPublicHttpsUrl,
6098
+ downloadToTemp as downloadToTemp2,
6099
+ resolveRestrictPageNetwork,
6100
+ isUrlNotPermittedError,
6101
+ writeUrlDownloadTelemetry as writeUrlDownloadTelemetry2,
6062
6102
  resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
6063
6103
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
6064
6104
  safeVideoExtractionSourceIdentity,
@@ -6299,9 +6339,11 @@ async function runExtractVideosStage(input) {
6299
6339
  deferRangeExtraction,
6300
6340
  shownBoxes,
6301
6341
  urlByAbsentLocalPath,
6342
+ audioDownloadDir,
6302
6343
  skipFrameExtractionIds = []
6303
6344
  } = input;
6304
6345
  const stage2Start = Date.now();
6346
+ const assetRoots = job.config.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir);
6305
6347
  const extractionPolicy = resolveVideoExtractionPolicy();
6306
6348
  composition.videos = composition.videos.filter(
6307
6349
  (video) => !isVideoPastTimelineEnd(video, composition.duration)
@@ -6320,7 +6362,7 @@ async function runExtractVideosStage(input) {
6320
6362
  const probeFailures = await Promise.all(
6321
6363
  composition.videos.map(async (v) => {
6322
6364
  const videoPath = resolveProjectRelativeSrc4(v.src, projectDir, compiledDir);
6323
- if (!existsSync9(videoPath)) return null;
6365
+ if (!opensLocally(videoPath, assetRoots)) return null;
6324
6366
  try {
6325
6367
  const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata4(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata4(videoPath), {
6326
6368
  signal: abortSignal,
@@ -6358,7 +6400,7 @@ async function runExtractVideosStage(input) {
6358
6400
  const probed = await Promise.all(
6359
6401
  composition.images.map(async (img) => {
6360
6402
  const imgPath = resolveProjectRelativeSrc4(img.src, projectDir, compiledDir);
6361
- if (!existsSync9(imgPath)) return null;
6403
+ if (!opensLocally(imgPath, assetRoots)) return null;
6362
6404
  const colorSpace = await probeColorSpaceSafely(imgPath, log);
6363
6405
  if (isHdrColorSpace2(colorSpace)) {
6364
6406
  nativeHdrImageIds.add(img.id);
@@ -6371,7 +6413,16 @@ async function runExtractVideosStage(input) {
6371
6413
  imageColorSpaces.push(...probed);
6372
6414
  }
6373
6415
  if (skipFrameExtractionIds.length > 0) {
6374
- await appendVideoAudioFromProbe({ projectDir, compiledDir, composition, urlByAbsentLocalPath });
6416
+ await appendVideoAudioFromProbe({
6417
+ projectDir,
6418
+ compiledDir,
6419
+ composition,
6420
+ urlByAbsentLocalPath,
6421
+ downloadDir: audioDownloadDir,
6422
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
6423
+ signal: abortSignal,
6424
+ log
6425
+ });
6375
6426
  videoReadinessSkipIds = [...skipFrameExtractionIds];
6376
6427
  } else if (composition.videos.length > 0) {
6377
6428
  const totalVideos = composition.videos.length;
@@ -6402,6 +6453,7 @@ async function runExtractVideosStage(input) {
6402
6453
  shownBoxes,
6403
6454
  contentKeyedDirs: [join12(compiledDir, REMOTE_MEDIA_SUBDIR)],
6404
6455
  urlByAbsentLocalPath,
6456
+ assetRoots,
6405
6457
  onProgress: ({ planned = 0, done = 0 }) => {
6406
6458
  framesPlanned += planned;
6407
6459
  framesDone += done;
@@ -6478,17 +6530,41 @@ function isPublicHttpsUrl(url) {
6478
6530
  return false;
6479
6531
  }
6480
6532
  }
6533
+ function opensLocally(path, assetRoots) {
6534
+ return existsSync9(path) && (!assetRoots || isInsideAssetRoots2(path, assetRoots));
6535
+ }
6536
+ function localProbeSource(src, input) {
6537
+ const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
6538
+ const readFrom = input.urlByAbsentLocalPath?.get(path) ?? path;
6539
+ const roots = input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(input.projectDir, input.compiledDir);
6540
+ return isHttpUrl3(readFrom) || opensLocally(readFrom, roots) ? readFrom : null;
6541
+ }
6542
+ async function remoteProbeSource(video, input) {
6543
+ if (!isPublicHttpsUrl(video.src)) return null;
6544
+ if (!resolveRestrictPageNetwork()) return video.src;
6545
+ if (!video.hasAudio || video.hidden) return null;
6546
+ const downloadDir = input.downloadDir ?? join12(input.compiledDir, REMOTE_MEDIA_SUBDIR);
6547
+ try {
6548
+ return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
6549
+ onTelemetry: writeUrlDownloadTelemetry2
6550
+ });
6551
+ } catch (error) {
6552
+ if (!isUrlNotPermittedError(error)) throw error;
6553
+ input.log?.warn("Video sound skipped: its URL is outside the download address rules", {
6554
+ videoId: video.id
6555
+ });
6556
+ return null;
6557
+ }
6558
+ }
6481
6559
  async function appendVideoAudioFromProbe(input) {
6482
- const { projectDir, compiledDir, composition, urlByAbsentLocalPath } = input;
6560
+ const { composition } = input;
6483
6561
  const videos = composition.videos.filter(
6484
6562
  (video) => !isVideoPastTimelineEnd(video, composition.duration)
6485
6563
  );
6486
6564
  const probed = await Promise.all(
6487
6565
  videos.map(async (video) => {
6488
- if (isHttpUrl2(video.src) && !isPublicHttpsUrl(video.src)) return null;
6489
- const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc4(video.src, projectDir, compiledDir);
6490
- const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
6491
- if (!isHttpUrl2(readFrom) && !existsSync9(readFrom)) return null;
6566
+ const readFrom = isHttpUrl3(video.src) ? await remoteProbeSource(video, input) : localProbeSource(video.src, input);
6567
+ if (readFrom === null) return null;
6492
6568
  const metadata = await extractMediaMetadata4(readFrom);
6493
6569
  const window2 = await resolveFinalFrameExtractionWindow2(
6494
6570
  readFrom,
@@ -6510,7 +6586,7 @@ async function appendVideoAudioFromProbe(input) {
6510
6586
  // src/services/render/videoLayerPassthroughPlan.ts
6511
6587
  import {
6512
6588
  buildVideoLayerInput,
6513
- isHttpUrl as isHttpUrl3,
6589
+ isHttpUrl as isHttpUrl4,
6514
6590
  qualifyVideoLayer,
6515
6591
  resolveProjectRelativeSrc as resolveProjectRelativeSrc5
6516
6592
  } from "@hyperframes/engine";
@@ -6528,7 +6604,7 @@ import {
6528
6604
 
6529
6605
  // src/services/render/audioDeliveryLimit.ts
6530
6606
  import { existsSync as existsSync10 } from "node:fs";
6531
- import { dirname as dirname8, join as join14 } from "node:path";
6607
+ import { dirname as dirname9, join as join14 } from "node:path";
6532
6608
  import {
6533
6609
  applyAudioFxChain,
6534
6610
  describeFfmpegFailure as describeFfmpegFailure3,
@@ -6538,7 +6614,7 @@ import {
6538
6614
 
6539
6615
  // src/services/render/audioPadTrim.ts
6540
6616
  import { spawn } from "node:child_process";
6541
- import { dirname as dirname7, join as join13 } from "node:path";
6617
+ import { dirname as dirname8, join as join13 } from "node:path";
6542
6618
  import {
6543
6619
  DEFAULT_CONFIG,
6544
6620
  describeFfmpegFailure as describeFfmpegFailure2,
@@ -6832,7 +6908,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
6832
6908
  async function enforceAacTruePeak(input) {
6833
6909
  let scratchDir;
6834
6910
  try {
6835
- scratchDir = createStagingDir3(dirname7(input.audioPath), ".true-peak-");
6911
+ scratchDir = createStagingDir3(dirname8(input.audioPath), ".true-peak-");
6836
6912
  const correctedPath = join13(scratchDir, "audio.m4a");
6837
6913
  const measurements = [];
6838
6914
  let attenuationDb = 0;
@@ -7043,7 +7119,7 @@ async function limitDeliveryPeaks(input, deps = {
7043
7119
  const peak = await deps.measure(audioPath, { timeoutMs, signal });
7044
7120
  if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
7045
7121
  const alternating = ["a", "b"].map(
7046
- (k) => join14(dirname8(sourcePath), `audio-source-limited-${k}.wav`)
7122
+ (k) => join14(dirname9(sourcePath), `audio-source-limited-${k}.wav`)
7047
7123
  );
7048
7124
  let encodedFrom;
7049
7125
  let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
@@ -7191,7 +7267,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
7191
7267
  audioResult = await processCompositionAudio(
7192
7268
  audios,
7193
7269
  projectDir,
7194
- join15(workDir, "audio-work"),
7270
+ audioWorkDir(workDir),
7195
7271
  audioOutputPath,
7196
7272
  duration,
7197
7273
  abortSignal,
@@ -7201,7 +7277,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
7201
7277
  masterFxChain,
7202
7278
  urlByAbsentLocalPath,
7203
7279
  audioSidecarUrlByLocalPath,
7204
- keepEncoderInputAt: pcmSourcePath
7280
+ keepEncoderInputAt: pcmSourcePath,
7281
+ assetRoots: input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir)
7205
7282
  },
7206
7283
  compiledDir
7207
7284
  );
@@ -7664,7 +7741,7 @@ import {
7664
7741
  writeFileSync as writeFileSync4
7665
7742
  } from "node:fs";
7666
7743
  import { readFile as readFile2 } from "node:fs/promises";
7667
- import { dirname as dirname9, join as join17 } from "node:path";
7744
+ import { dirname as dirname10, join as join17 } from "node:path";
7668
7745
  import {
7669
7746
  encodeFramesChunkedConcat,
7670
7747
  encodeFramesFromDir,
@@ -7982,7 +8059,7 @@ async function runEncodeStage(input) {
7982
8059
  const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
7983
8060
  fps: job.config.fps,
7984
8061
  loop,
7985
- palettePath: join17(dirname9(videoOnlyPath), "gif-palette.png"),
8062
+ palettePath: join17(dirname10(videoOnlyPath), "gif-palette.png"),
7986
8063
  preserveAlpha: needsAlpha,
7987
8064
  signal: abortSignal,
7988
8065
  timeout: engineCfg.ffmpegEncodeTimeout
@@ -8459,7 +8536,7 @@ import {
8459
8536
 
8460
8537
  // src/services/distributed/shared.ts
8461
8538
  import { execFile as execFileCallback } from "node:child_process";
8462
- import { dirname as dirname11, join as join19 } from "node:path";
8539
+ import { dirname as dirname12, join as join19 } from "node:path";
8463
8540
  import { existsSync as existsSync15, readFileSync as readFileSync7 } from "node:fs";
8464
8541
  import { fileURLToPath as fileURLToPath3 } from "node:url";
8465
8542
  import { promisify as promisify2 } from "node:util";
@@ -8735,7 +8812,7 @@ function buildSyntheticRenderJob(input) {
8735
8812
  var cachedProducerVersion = null;
8736
8813
  function readProducerVersion() {
8737
8814
  if (cachedProducerVersion !== null) return cachedProducerVersion;
8738
- const startDir = dirname11(fileURLToPath3(import.meta.url));
8815
+ const startDir = dirname12(fileURLToPath3(import.meta.url));
8739
8816
  let current = startDir;
8740
8817
  for (let i = 0; i < 10; i++) {
8741
8818
  const candidate = join19(current, "package.json");
@@ -8749,7 +8826,7 @@ function readProducerVersion() {
8749
8826
  } catch {
8750
8827
  }
8751
8828
  }
8752
- const parent = dirname11(current);
8829
+ const parent = dirname12(current);
8753
8830
  if (parent === current) break;
8754
8831
  current = parent;
8755
8832
  }
@@ -9485,7 +9562,7 @@ import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFail
9485
9562
  import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
9486
9563
  import { open } from "node:fs/promises";
9487
9564
  import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
9488
- import { basename as basename5, dirname as dirname12, join as join24 } from "node:path";
9565
+ import { basename as basename5, dirname as dirname13, join as join24 } from "node:path";
9489
9566
  import { finished, pipeline } from "node:stream/promises";
9490
9567
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
9491
9568
  function boxAt(src, off, at, limit) {
@@ -9850,8 +9927,8 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
9850
9927
  const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
9851
9928
  const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
9852
9929
  const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
9853
- mkdirSync8(dirname12(outputPath), { recursive: true });
9854
- const workDir = createStagingDir4(dirname12(outputPath), `${basename5(outputPath)}.stitch-`);
9930
+ mkdirSync8(dirname13(outputPath), { recursive: true });
9931
+ const workDir = createStagingDir4(dirname13(outputPath), `${basename5(outputPath)}.stitch-`);
9855
9932
  const out = createWriteStream(join24(workDir, "out.mp4"));
9856
9933
  try {
9857
9934
  out.write(header);
@@ -10760,6 +10837,7 @@ function mixPlanAudio(c, compiledDir) {
10760
10837
  compiledDir,
10761
10838
  urlByAbsentLocalPath: c.urlByAbsentLocalPath,
10762
10839
  audioSidecarUrlByLocalPath: c.audioSidecarUrlByLocalPath,
10840
+ allowOutsideProjectAssets: c.job.config.allowOutsideProjectAssets,
10763
10841
  totalFrames: c.totalFrames,
10764
10842
  fps: c.job.config.fps,
10765
10843
  ffmpegProcessTimeout: c.cfg.ffmpegProcessTimeout,
@@ -11067,7 +11145,12 @@ async function buildPlanAudio(projectDir, config, workRoot, outputPath, options
11067
11145
  });
11068
11146
  try {
11069
11147
  let stageStarted = Date.now();
11070
- await appendVideoAudioFromProbe(c);
11148
+ await appendVideoAudioFromProbe({
11149
+ ...c,
11150
+ downloadDir: audioWorkDir(c.workDir),
11151
+ allowOutsideProjectAssets: c.job.config.allowOutsideProjectAssets,
11152
+ signal: c.abortSignal
11153
+ });
11071
11154
  logPlanStage(c.log, "extract", stageStarted);
11072
11155
  stageStarted = Date.now();
11073
11156
  const mixed = await mixPlanAudio(c, c.compiledDir);
@@ -11100,7 +11183,7 @@ import {
11100
11183
  writeFileSync as writeFileSync10
11101
11184
  } from "node:fs";
11102
11185
  import { tmpdir } from "node:os";
11103
- import { dirname as dirname14, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
11186
+ import { dirname as dirname15, isAbsolute as isAbsolute4, join as join30, relative as relative7, resolve as resolve9, sep as sep5 } from "node:path";
11104
11187
  import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
11105
11188
  import {
11106
11189
  createFrameLookupTable as createFrameLookupTable5,
@@ -11119,7 +11202,7 @@ import {
11119
11202
  writeFileSync as writeFileSync9
11120
11203
  } from "node:fs";
11121
11204
  import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
11122
- import { dirname as dirname13, join as join29 } from "node:path";
11205
+ import { dirname as dirname14, join as join29 } from "node:path";
11123
11206
 
11124
11207
  // src/services/distributed/planV2Errors.ts
11125
11208
  var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
@@ -11180,8 +11263,8 @@ var LocalPlanV2ArtifactPublisher = class {
11180
11263
  }
11181
11264
  this.destinationDir = destinationDir;
11182
11265
  this.#linkFile = options.linkFile ?? linkSync2;
11183
- mkdirSync11(dirname13(destinationDir), { recursive: true });
11184
- this.temporaryDir = createStagingDir5(dirname13(destinationDir), ".plan-v2-publish-");
11266
+ mkdirSync11(dirname14(destinationDir), { recursive: true });
11267
+ this.temporaryDir = createStagingDir5(dirname14(destinationDir), ".plan-v2-publish-");
11185
11268
  }
11186
11269
  async putBlob(blob) {
11187
11270
  const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
@@ -11193,8 +11276,8 @@ var LocalPlanV2ArtifactPublisher = class {
11193
11276
  }
11194
11277
  const destinationPath = planV2BlobPath(this.temporaryDir, digest);
11195
11278
  if (existsSync20(destinationPath)) return;
11196
- mkdirSync11(dirname13(destinationPath), { recursive: true });
11197
- const stagingDir = createStagingDir5(dirname13(destinationPath), ".plan-v2-blob-");
11279
+ mkdirSync11(dirname14(destinationPath), { recursive: true });
11280
+ const stagingDir = createStagingDir5(dirname14(destinationPath), ".plan-v2-blob-");
11198
11281
  const temporaryPath = join29(stagingDir, "blob");
11199
11282
  try {
11200
11283
  try {
@@ -11485,8 +11568,8 @@ function computeManifestHash(manifest) {
11485
11568
  }
11486
11569
  function writeBlob(sourcePath, destinationPath) {
11487
11570
  if (existsSync21(destinationPath)) return;
11488
- mkdirSync12(dirname14(destinationPath), { recursive: true });
11489
- const temporaryDir = createStagingDir6(dirname14(destinationPath), ".plan-v2-blob-");
11571
+ mkdirSync12(dirname15(destinationPath), { recursive: true });
11572
+ const temporaryDir = createStagingDir6(dirname15(destinationPath), ".plan-v2-blob-");
11490
11573
  const temporaryPath = join30(temporaryDir, "blob");
11491
11574
  try {
11492
11575
  copyFileSync8(sourcePath, temporaryPath);
@@ -11611,8 +11694,8 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
11611
11694
  if (publication.storedBlobs.length > 0) {
11612
11695
  throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
11613
11696
  }
11614
- mkdirSync12(dirname14(planV2Dir), { recursive: true });
11615
- const tempDir = createStagingDir6(dirname14(planV2Dir), ".plan-v2-build-");
11697
+ mkdirSync12(dirname15(planV2Dir), { recursive: true });
11698
+ const tempDir = createStagingDir6(dirname15(planV2Dir), ".plan-v2-build-");
11616
11699
  try {
11617
11700
  for (const blob of publication.blobs) {
11618
11701
  writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
@@ -11696,7 +11779,7 @@ async function planV2(projectDir, config, planV2Dir) {
11696
11779
  }
11697
11780
  const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
11698
11781
  const manifest = await planV2WithPublisher(projectDir, config, publisher, {
11699
- stagingParentDir: dirname14(planV2Dir)
11782
+ stagingParentDir: dirname15(planV2Dir)
11700
11783
  });
11701
11784
  return resultFromManifest(planV2Dir, manifest);
11702
11785
  }
@@ -11889,12 +11972,12 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
11889
11972
  artifact,
11890
11973
  sourcePath: verifyBlob(planV2Dir, artifact)
11891
11974
  }));
11892
- mkdirSync12(dirname14(destinationDir), { recursive: true });
11893
- const tempDir = createStagingDir6(dirname14(destinationDir), ".plan-v2-materialize-");
11975
+ mkdirSync12(dirname15(destinationDir), { recursive: true });
11976
+ const tempDir = createStagingDir6(dirname15(destinationDir), ".plan-v2-materialize-");
11894
11977
  try {
11895
11978
  for (const { artifact, sourcePath } of verified) {
11896
11979
  const destinationPath = join30(tempDir, ...artifact.path.split("/"));
11897
- mkdirSync12(dirname14(destinationPath), { recursive: true });
11980
+ mkdirSync12(dirname15(destinationPath), { recursive: true });
11898
11981
  copyFileSync8(sourcePath, destinationPath);
11899
11982
  }
11900
11983
  if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
@@ -11992,7 +12075,7 @@ import {
11992
12075
  statSync as statSync9,
11993
12076
  writeFileSync as writeFileSync11
11994
12077
  } from "node:fs";
11995
- import { basename as basename6, dirname as dirname15, join as join31 } from "node:path";
12078
+ import { basename as basename6, dirname as dirname16, join as join31 } from "node:path";
11996
12079
  import {
11997
12080
  appendRateCapArgs as appendRateCapArgs2,
11998
12081
  appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
@@ -12039,10 +12122,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
12039
12122
  }
12040
12123
  const format = plan.dimensions.format;
12041
12124
  const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
12042
- if (!existsSync22(dirname15(outputPath))) {
12043
- mkdirSync13(dirname15(outputPath), { recursive: true });
12125
+ if (!existsSync22(dirname16(outputPath))) {
12126
+ mkdirSync13(dirname16(outputPath), { recursive: true });
12044
12127
  }
12045
- const workDir = createStagingDir7(dirname15(outputPath), `${basename6(outputPath)}.assemble-work-`);
12128
+ const workDir = createStagingDir7(dirname16(outputPath), `${basename6(outputPath)}.assemble-work-`);
12046
12129
  const fps = { num: plan.dimensions.fpsNum, den: plan.dimensions.fpsDen };
12047
12130
  const stageMs = {};
12048
12131
  const ctx = {