@hyperframes/producer 0.9.59 → 0.9.63

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.
@@ -1,10 +1,26 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ // src/services/render/outputDimensions.ts
4
+ function isExpectedOutputDimensions(value) {
5
+ return typeof value === "object" && value !== null && "width" in value && "height" in value && typeof value.width === "number" && typeof value.height === "number" && Number.isSafeInteger(value.width) && Number.isSafeInteger(value.height) && value.width > 0 && value.height > 0;
6
+ }
7
+ var OutputDimensionsMismatchError = class extends Error {
8
+ code = "OUTPUT_DIMENSIONS_MISMATCH";
9
+ constructor() {
10
+ super("Compiled output dimensions do not match the requested render dimensions.");
11
+ }
12
+ };
13
+ function requireOutputDimensions(expected, width, height) {
14
+ if (expected !== void 0 && (!isExpectedOutputDimensions(expected) || expected.width !== width || expected.height !== height)) {
15
+ throw new OutputDimensionsMismatchError();
16
+ }
17
+ }
18
+
3
19
  // src/server.ts
4
20
  import {
5
21
  existsSync as existsSync25,
6
22
  mkdirSync as mkdirSync13,
7
- statSync as statSync12,
23
+ statSync as statSync13,
8
24
  mkdtempSync,
9
25
  writeFileSync as writeFileSync8,
10
26
  rmSync as rmSync13,
@@ -26,13 +42,13 @@ import {
26
42
  import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
27
43
 
28
44
  // src/services/renderOrchestrator.ts
29
- import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
45
+ import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
30
46
  import {
31
47
  existsSync as existsSync21,
32
48
  mkdirSync as mkdirSync12,
33
49
  readdirSync as readdirSync6,
34
50
  rmSync as rmSync12,
35
- statSync as statSync10,
51
+ statSync as statSync11,
36
52
  writeFileSync as writeFileSync7,
37
53
  copyFileSync as copyFileSync5,
38
54
  appendFileSync
@@ -200,6 +216,10 @@ function stripPreloadNone(html) {
200
216
  return attr && attr.index < tagEnd ? [attr.index, attr.index + attr[0].length] : void 0;
201
217
  });
202
218
  }
219
+ function hasClosedMediaTag(text) {
220
+ const open = /<(?:video|audio)\b/i.exec(text);
221
+ return open !== null && text.includes(">", open.index + open[0].length);
222
+ }
203
223
  var REMOTE_SRC_TAGS = {
204
224
  media: { opener: "<(?:video|audio)\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
205
225
  source: { opener: "<source\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
@@ -400,7 +420,10 @@ import { Readable } from "node:stream";
400
420
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
401
421
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
402
422
  import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
403
- import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
423
+ import {
424
+ PREVIEW_FOR_ANOTHER_SITE_META,
425
+ serviceWorkerScriptFetch
426
+ } from "@hyperframes/core/studio-preview-mark";
404
427
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
405
428
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
406
429
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -548,6 +571,7 @@ import { isSafePath } from "@hyperframes/core/safe-path";
548
571
  import {
549
572
  isCopiedOutsideFileType,
550
573
  isPrivateOutsideFile,
574
+ isUploadedOutsideFileType,
551
575
  leftOutWarning,
552
576
  linksOutside
553
577
  } from "@hyperframes/studio-server/outside-file";
@@ -569,15 +593,17 @@ function isPathInside(childPath, parentPath, options = {}) {
569
593
  function escapesAssetRoot(path, assetRoot) {
570
594
  return assetRoot !== void 0 && !isSafePath(assetRoot, path);
571
595
  }
572
- function outsideAssetRefusal(projectDir, path) {
596
+ function outsideAssetRefusal(projectDir, path, policy = {}) {
573
597
  if (!linksOutside(projectDir, path)) return null;
574
598
  if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
575
599
  const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
576
- return folder || isCopiedOutsideFileType(path) ? null : "file_type";
600
+ if (folder || isUploadedOutsideFileType(path)) return null;
601
+ if (!isCopiedOutsideFileType(path)) return "file_type";
602
+ return policy.includeScripts ? null : "script";
577
603
  }
578
604
  var leftOutOfRender = (file, reference, reason) => leftOutWarning(file, reference, reason, "render");
579
- function refusesOutsideLink(projectDir, path, warn) {
580
- const refusal = outsideAssetRefusal(projectDir, path);
605
+ function refusesOutsideLink(projectDir, path, warn, policy = {}) {
606
+ const refusal = outsideAssetRefusal(projectDir, path, policy);
581
607
  if (!refusal) return false;
582
608
  const file = nodeRelative(projectDir, path).split(sep).join("/");
583
609
  warn(leftOutOfRender(file, realFilePath(path), refusal));
@@ -1160,7 +1186,8 @@ function createFileServer(options) {
1160
1186
  compiledDir,
1161
1187
  port = 0,
1162
1188
  stripEmbeddedRuntime = true,
1163
- allowOutsideProjectAssets = false
1189
+ allowOutsideProjectAssets = false,
1190
+ includeOutsideScripts = false
1164
1191
  } = options;
1165
1192
  const preHeadScripts = [
1166
1193
  HF_EARLY_STUB,
@@ -1171,12 +1198,19 @@ function createFileServer(options) {
1171
1198
  const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
1172
1199
  const app = new Hono();
1173
1200
  const warnLeftOut = (line) => console.warn(`[FileServer] ${terminalText2(line)}`);
1201
+ const outsidePolicy = { includeScripts: includeOutsideScripts };
1174
1202
  let listeningPort = -1;
1175
1203
  app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
1176
1204
  await next();
1177
1205
  c.res.headers.set("X-Content-Type-Options", "nosniff");
1178
1206
  });
1179
1207
  answerOwnLoopbackHostOnly(app, () => listeningPort);
1208
+ app.use(async function refuseServiceWorkerScripts(c, next) {
1209
+ const serviceWorker = c.req.header("service-worker");
1210
+ if (!serviceWorkerScriptFetch({ serviceWorker, fetchDest: c.req.header("sec-fetch-dest") }))
1211
+ return next();
1212
+ return c.text("Forbidden", 403);
1213
+ });
1180
1214
  app.get("/*", async (c) => {
1181
1215
  let requestPath = c.req.path;
1182
1216
  if (requestPath === "/") requestPath = "/index.html";
@@ -1188,7 +1222,7 @@ function createFileServer(options) {
1188
1222
  if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
1189
1223
  if (isPrivateFileUnder(root, candidate, isStudioPrivatePath)) continue;
1190
1224
  const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
1191
- if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut)) continue;
1225
+ if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut, outsidePolicy)) continue;
1192
1226
  file = openRegularFile(candidate);
1193
1227
  if (file) break;
1194
1228
  }
@@ -2748,9 +2782,10 @@ function frameWeightedAvgMs(perfs, avgOf) {
2748
2782
  function aggregateDedup(perfs) {
2749
2783
  if (perfs.length === 0) return void 0;
2750
2784
  const armed = perfs.some((p) => p.staticDedupArmed);
2751
- const skipReasons = armed ? [] : [
2752
- ...new Set(perfs.map((p) => p.staticDedupSkipReason).filter((r) => !!r))
2753
- ].sort();
2785
+ const distinctUnarmed = (values) => {
2786
+ const distinct = armed ? [] : [...new Set(values.filter((v) => !!v))].sort();
2787
+ return distinct.length > 0 ? distinct.join("|") : void 0;
2788
+ };
2754
2789
  const verificationPerfs = perfs.filter((perf) => perf.staticDedupVerificationOutcome);
2755
2790
  const verificationOutcomes = [
2756
2791
  ...new Set(
@@ -2762,7 +2797,8 @@ function aggregateDedup(perfs) {
2762
2797
  armed,
2763
2798
  predictedFrames: perfs.reduce((sum, p) => sum + (p.staticDedupPredicted ?? 0), 0),
2764
2799
  reusedFrames: perfs.reduce((sum, p) => sum + (p.staticDedupReused ?? 0), 0),
2765
- skipReason: skipReasons.length > 0 ? skipReasons.join("|") : void 0,
2800
+ skipReason: distinctUnarmed(perfs.map((p) => p.staticDedupSkipReason)),
2801
+ ineligibleCause: distinctUnarmed(perfs.map((p) => p.staticDedupIneligibleCause)),
2766
2802
  ...verificationPerfs.length === 0 ? {} : {
2767
2803
  verifiedFrames: verificationPerfs.reduce(
2768
2804
  (sum, perf) => sum + (perf.staticDedupVerified ?? 0),
@@ -6900,6 +6936,61 @@ import { suggestMatchingPreset } from "@hyperframes/core";
6900
6936
  import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
6901
6937
  import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
6902
6938
 
6939
+ // src/services/compositionSizeLimit.ts
6940
+ import { statSync as statSync7 } from "node:fs";
6941
+ var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
6942
+ var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
6943
+ var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
6944
+ var MAX_EXPANDED_COMPOSITION_BYTES = 2 * MAX_COMPOSITION_HTML_BYTES;
6945
+ var MAX_COMPOSITION_MOUNTS = 1e4;
6946
+ var CompositionTooLargeError = class extends Error {
6947
+ constructor(message, publicMetadata) {
6948
+ super(message);
6949
+ this.publicMetadata = publicMetadata;
6950
+ this.name = "CompositionTooLargeError";
6951
+ }
6952
+ publicMetadata;
6953
+ code = COMPOSITION_TOO_LARGE;
6954
+ // The producer server reads these off the error for the wire envelope.
6955
+ owner = "user";
6956
+ retryable = false;
6957
+ };
6958
+ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
6959
+ `Composition file "${file}" is ${megabytes(bytes)}, over the ${megabytes(MAX_COMPOSITION_HTML_BYTES)} limit for one composition HTML file. Keep large data such as images, fonts and JSON in separate asset files and reference them by path instead of inlining them.`,
6960
+ { bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
6961
+ );
6962
+ var CompositionExpansionBudget = class {
6963
+ bytes = 0;
6964
+ mounts = 0;
6965
+ charge(file, bytes) {
6966
+ this.bytes += bytes;
6967
+ this.mounts += 1;
6968
+ if (this.bytes <= MAX_EXPANDED_COMPOSITION_BYTES && this.mounts <= MAX_COMPOSITION_MOUNTS) {
6969
+ return;
6970
+ }
6971
+ throw new CompositionTooLargeError(
6972
+ `Sub-composition mounts, ending at "${file}", add up to ${megabytes(this.bytes)} across ${this.mounts} mounts. One render inlines at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)} of composition HTML in at most ${MAX_COMPOSITION_MOUNTS} mounts. Mount large or repeated scenes fewer times.`,
6973
+ {
6974
+ bytes: this.bytes,
6975
+ limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
6976
+ mounts: this.mounts,
6977
+ exceeded: this.mounts > MAX_COMPOSITION_MOUNTS ? "mounts" : "bytes"
6978
+ }
6979
+ );
6980
+ }
6981
+ };
6982
+ function assertCompositionFileSize(path, file) {
6983
+ let bytes;
6984
+ try {
6985
+ const stats = statSync7(path);
6986
+ if (!stats.isFile()) return;
6987
+ bytes = stats.size;
6988
+ } catch {
6989
+ return;
6990
+ }
6991
+ if (bytes > MAX_COMPOSITION_HTML_BYTES) throw fileTooLarge(file, bytes);
6992
+ }
6993
+
6903
6994
  // src/services/htmlCompiler.ts
6904
6995
  import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
6905
6996
  import {
@@ -6986,11 +7077,13 @@ import {
6986
7077
  import {
6987
7078
  isUnresolvedAssetPlaceholder,
6988
7079
  namesAnotherNetworkRoot as namesAnotherNetworkRoot2,
7080
+ projectAssetExists,
6989
7081
  readProjectFile,
6990
7082
  readTextFile,
6991
7083
  resolveCompositionSrc
6992
7084
  } from "@hyperframes/parsers/asset-resolution";
6993
7085
  import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
7086
+ import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
6994
7087
 
6995
7088
  // src/services/renderMediaCollector.ts
6996
7089
  import { parseHTML as parseHTML2 } from "linkedom";
@@ -7184,7 +7277,7 @@ import {
7184
7277
 
7185
7278
  // src/services/animatedGifPrep.ts
7186
7279
  import { createHash as createHash4 } from "node:crypto";
7187
- import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
7280
+ import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync8 } from "node:fs";
7188
7281
  import { dirname as dirname6, isAbsolute as isAbsolute2, join as join16, resolve as resolve5 } from "node:path";
7189
7282
  import { parseHTML as parseHTML3 } from "linkedom";
7190
7283
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
@@ -7237,12 +7330,13 @@ function resolveLocalImageSourcePath(src, options) {
7237
7330
  isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
7238
7331
  resolve5(options.downloadDir, normalizedBase)
7239
7332
  ];
7240
- const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7333
+ const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
7334
+ const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7241
7335
  return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
7242
7336
  }
7243
7337
  function isUsableFile(path) {
7244
7338
  try {
7245
- const stat = statSync7(path);
7339
+ const stat = statSync8(path);
7246
7340
  return stat.isFile() && stat.size > 0;
7247
7341
  } catch {
7248
7342
  return false;
@@ -7507,7 +7601,7 @@ import {
7507
7601
  readFileSync as readFileSync7,
7508
7602
  readSync as readSync3,
7509
7603
  rmSync as rmSync10,
7510
- statSync as statSync8,
7604
+ statSync as statSync9,
7511
7605
  writeFileSync as writeFileSync4
7512
7606
  } from "node:fs";
7513
7607
  import { dirname as dirname7, join as join17, resolve as resolve6 } from "node:path";
@@ -7751,7 +7845,7 @@ function resolveImageSource(src, options) {
7751
7845
  }
7752
7846
  function isUsableFile2(path) {
7753
7847
  try {
7754
- return statSync8(path).size > 0;
7848
+ return statSync9(path).size > 0;
7755
7849
  } catch {
7756
7850
  return false;
7757
7851
  }
@@ -8030,7 +8124,7 @@ Check that each file referenced by data-composition-src contains valid HTML with
8030
8124
  };
8031
8125
  function normalizeCompositionSrcs(html, projectDir) {
8032
8126
  return html.replace(/(\bdata-composition-src=)(["'])([^"']*)\2/g, (whole, name, quote, value) => {
8033
- if (!value.includes("%") && !value.startsWith("/")) return whole;
8127
+ if (!value.includes("%") && !/^\.?[\\/]/.test(value)) return whole;
8034
8128
  const file = resolveCompositionSrc(projectDir, value);
8035
8129
  if (file === null) return whole;
8036
8130
  return `${name}${quote}${relative2(projectDir, file).split(sep3).join("/")}${quote}`;
@@ -8046,68 +8140,94 @@ function resolveCompositionFile(projectDir, src, assetRoot) {
8046
8140
  const file = resolveCompositionPath(projectDir, src, assetRoot);
8047
8141
  return file !== null && COMPOSITION_FILE.test(file) ? file : null;
8048
8142
  }
8143
+ var OUTSIDE_COMPOSITION_NEEDS_FLAG = "it is outside the project, and any scripts in it would run; move it into the project, or pass --include-outside-files to hyperframes render, to include it";
8144
+ var runsOutsideMarkupUnasked = (projectDir, filePath, assetRoot, outsideFiles) => assetRoot === void 0 && !outsideFiles.includeScripts && linksOutside2(projectDir, filePath);
8145
+ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles) {
8146
+ if (runsOutsideMarkupUnasked(projectDir, filePath, assetRoot, outsideFiles)) {
8147
+ throw new EmptyCompositionError([{ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG }]);
8148
+ }
8149
+ }
8049
8150
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8050
- function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @__PURE__ */ new Set()) {
8151
+ var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
8152
+ function compositionSrcsIn(html) {
8051
8153
  const { document: document2 } = parseHTML5(html);
8052
- const hosts = [...document2.querySelectorAll("[data-composition-src]")];
8053
- const problems = [];
8054
- for (const el of hosts) {
8055
- const srcPath = el.getAttribute("data-composition-src");
8056
- if (!srcPath) continue;
8057
- if (isUnresolvedAssetPlaceholder(srcPath)) continue;
8154
+ const templated = [];
8155
+ const templates = [...document2.querySelectorAll("template")];
8156
+ for (let template = templates.pop(); template; template = templates.pop()) {
8157
+ templated.push(...mountSrcsUnder(template.content));
8158
+ templates.push(...template.content.querySelectorAll("template"));
8159
+ }
8160
+ return { mounts: mountSrcsUnder(document2), templated };
8161
+ }
8162
+ function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8163
+ if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
8164
+ return "it is outside the project in a private location";
8165
+ }
8166
+ if (runsOutsideMarkupUnasked(projectDir, filePath, assetRoot, outsideFiles)) {
8167
+ return OUTSIDE_COMPOSITION_NEEDS_FLAG;
8168
+ }
8169
+ if (isPrivateCompositionFile(projectDir, filePath)) {
8170
+ return "it is git metadata, an env file or a private tool record";
8171
+ }
8172
+ return COMPOSITION_FILE.test(filePath) ? null : NOT_A_COMPOSITION_FILE;
8173
+ }
8174
+ function readSubCompositionFile(filePath, srcPath) {
8175
+ assertCompositionFileSize(filePath, srcPath);
8176
+ const read = readProjectFile(filePath);
8177
+ if (read.kind === "missing") return { detail: "the file does not exist" };
8178
+ if (read.kind === "folder") return { detail: "it is a folder, not an HTML file" };
8179
+ const validity = checkSubCompositionUsability(read.text, parseSubCompHtmlForValidity);
8180
+ if (!validity.ok)
8181
+ return { detail: validity.detail ?? "the file is empty or could not be parsed" };
8182
+ return { bytes: Buffer.byteLength(read.text), ...compositionSrcsIn(read.text) };
8183
+ }
8184
+ function assertSubCompositionsUsable(html, projectDir, assetRoot, outsideFiles) {
8185
+ const budget = new CompositionExpansionBudget();
8186
+ const files = /* @__PURE__ */ new Map();
8187
+ const problems = /* @__PURE__ */ new Map();
8188
+ const report = (srcPath, detail) => problems.set(`${srcPath}\0${detail}`, { srcPath, detail });
8189
+ const chain = /* @__PURE__ */ new Set();
8190
+ const paths = /* @__PURE__ */ new Map();
8191
+ const resolveMount = (srcPath) => {
8058
8192
  const filePath = resolveCompositionPath(projectDir, srcPath, assetRoot);
8059
- if (filePath === null) {
8060
- problems.push({ srcPath, detail: "it is outside the project folder" });
8061
- continue;
8062
- }
8063
- if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
8064
- problems.push({ srcPath, detail: "it is outside the project in a private location" });
8065
- continue;
8066
- }
8067
- if (isPrivateCompositionFile(projectDir, filePath)) {
8068
- problems.push({
8069
- srcPath,
8070
- detail: "it is git metadata, an env file or a private tool record"
8071
- });
8072
- continue;
8073
- }
8074
- if (!COMPOSITION_FILE.test(filePath)) {
8075
- problems.push({ srcPath, detail: NOT_A_COMPOSITION_FILE });
8076
- continue;
8077
- }
8078
- if (visited.has(filePath)) continue;
8079
- const read = readProjectFile(filePath);
8080
- if (read.kind === "missing") {
8081
- problems.push({ srcPath, detail: "the file does not exist" });
8082
- continue;
8083
- }
8084
- if (read.kind === "folder") {
8085
- problems.push({ srcPath, detail: "it is a folder, not an HTML file" });
8086
- continue;
8087
- }
8088
- const fileHtml = read.text;
8089
- const validity = checkSubCompositionUsability(fileHtml, parseSubCompHtmlForValidity);
8090
- if (!validity.ok) {
8091
- problems.push({
8092
- srcPath,
8093
- detail: validity.detail ?? "the file is empty or could not be parsed"
8094
- });
8095
- continue;
8096
- }
8097
- const nestedVisited = new Set(visited);
8098
- nestedVisited.add(filePath);
8099
- try {
8100
- assertSubCompositionsUsable(fileHtml, projectDir, assetRoot, nestedVisited);
8101
- } catch (err) {
8102
- if (err instanceof EmptyCompositionError) {
8103
- problems.push(...err.problems);
8104
- } else {
8105
- throw err;
8193
+ if (filePath === null) return { detail: "it is outside the project folder" };
8194
+ const detail = compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles);
8195
+ return detail ? { detail } : { filePath };
8196
+ };
8197
+ const walk = (srcPaths, quiet) => {
8198
+ for (const srcPath of srcPaths) {
8199
+ let resolved = paths.get(srcPath);
8200
+ if (!resolved) {
8201
+ resolved = resolveMount(srcPath);
8202
+ paths.set(srcPath, resolved);
8106
8203
  }
8204
+ if ("detail" in resolved) {
8205
+ if (!quiet) report(srcPath, resolved.detail);
8206
+ continue;
8207
+ }
8208
+ const { filePath } = resolved;
8209
+ if (chain.has(filePath)) continue;
8210
+ let file = files.get(filePath);
8211
+ if (!file) {
8212
+ file = readSubCompositionFile(filePath, srcPath);
8213
+ files.set(filePath, file);
8214
+ }
8215
+ if ("detail" in file) {
8216
+ if (!quiet) report(srcPath, file.detail);
8217
+ continue;
8218
+ }
8219
+ budget.charge(srcPath, file.bytes);
8220
+ chain.add(filePath);
8221
+ walk(file.mounts, quiet);
8222
+ walk(file.templated, true);
8223
+ chain.delete(filePath);
8107
8224
  }
8108
- }
8109
- if (problems.length > 0) {
8110
- throw new EmptyCompositionError(problems);
8225
+ };
8226
+ const entry = compositionSrcsIn(html);
8227
+ walk(entry.mounts, false);
8228
+ walk(entry.templated, true);
8229
+ if (problems.size > 0) {
8230
+ throw new EmptyCompositionError([...problems.values()]);
8111
8231
  }
8112
8232
  }
8113
8233
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
@@ -8362,7 +8482,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
8362
8482
  compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
8363
8483
  return { html: compiledHtml, unresolvedCompositions };
8364
8484
  }
8365
- async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
8485
+ async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot, outsideFiles = {}, compiledSrcs = /* @__PURE__ */ new Set()) {
8366
8486
  const subCompositions = /* @__PURE__ */ new Map();
8367
8487
  const { document: document2 } = parseHTML5(html);
8368
8488
  const compEls = document2.querySelectorAll("[data-composition-src]");
@@ -8375,6 +8495,10 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
8375
8495
  if (visited.has(filePath)) {
8376
8496
  continue;
8377
8497
  }
8498
+ if (compiledSrcs.has(srcPath)) continue;
8499
+ compiledSrcs.add(srcPath);
8500
+ assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
8501
+ assertCompositionFileSize(filePath, srcPath);
8378
8502
  const read = readProjectFile(filePath);
8379
8503
  if (read.kind !== "file") {
8380
8504
  continue;
@@ -8403,7 +8527,9 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
8403
8527
  item.nestedVisited,
8404
8528
  urlByAbsentLocalPath,
8405
8529
  probes,
8406
- assetRoot
8530
+ assetRoot,
8531
+ outsideFiles,
8532
+ compiledSrcs
8407
8533
  );
8408
8534
  return {
8409
8535
  srcPath: item.srcPath,
@@ -8539,7 +8665,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
8539
8665
  }
8540
8666
  return document2.toString();
8541
8667
  }
8542
- function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot) {
8668
+ function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles) {
8543
8669
  const { document: document2 } = parseHTML5(html);
8544
8670
  const head = document2.querySelector("head");
8545
8671
  const body = document2.querySelector("body");
@@ -8552,6 +8678,27 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8552
8678
  );
8553
8679
  return { html: emitted ? document2.toString() : html, variablesByComp: {} };
8554
8680
  }
8681
+ const budget = new CompositionExpansionBudget();
8682
+ const readOnce = /* @__PURE__ */ new Map();
8683
+ const readMountHtml = (srcPath) => {
8684
+ const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
8685
+ if (filePath) {
8686
+ assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outsideFiles);
8687
+ assertCompositionFileSize(filePath, srcPath);
8688
+ }
8689
+ const read = filePath && !isPrivateCompositionFile(projectDir, filePath) ? readProjectFile(filePath) : null;
8690
+ return read?.kind === "file" ? rewriteUnresolvableGsapToCdn(
8691
+ normalizeCompositionSrcs(read.text, projectDir),
8692
+ projectDir,
8693
+ srcPath
8694
+ ) : null;
8695
+ };
8696
+ const resolveMountHtml = (srcPath) => {
8697
+ const compiled = subCompositions.get(srcPath);
8698
+ if (compiled) return compiled;
8699
+ if (!readOnce.has(srcPath)) readOnce.set(srcPath, readMountHtml(srcPath));
8700
+ return readOnce.get(srcPath) ?? null;
8701
+ };
8555
8702
  const hostIdentityByElement = new ProducerHostIdentityMap(
8556
8703
  document2,
8557
8704
  hosts
@@ -8567,20 +8714,14 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8567
8714
  readVariableDefaults: readDeclaredDefaults,
8568
8715
  parseHostVariables: parseHostVariableValues,
8569
8716
  resolveHtml: (srcPath) => {
8570
- let compHtml = subCompositions.get(srcPath) || null;
8571
- if (!compHtml) {
8572
- const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
8573
- const read = filePath && !isPrivateCompositionFile(projectDir, filePath) ? readProjectFile(filePath) : null;
8574
- if (read?.kind === "file") {
8575
- compHtml = rewriteUnresolvableGsapToCdn(read.text, projectDir, srcPath);
8576
- }
8577
- }
8717
+ const compHtml = resolveMountHtml(srcPath);
8718
+ if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
8578
8719
  return compHtml;
8579
8720
  },
8580
8721
  parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
8581
8722
  // Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
8582
8723
  // against its own directory, project-root refs stay as authored.
8583
- assetExists: (path) => existsSync11(resolve7(projectDir, path)),
8724
+ assetExists: projectAssetExists(projectDir),
8584
8725
  // Preserve the authored root wrapper as a child of the host, matching
8585
8726
  // the preview bundler's shape (htmlBundler.ts's prepareFlattenedInnerRoot,
8586
8727
  // which the runtime compositionLoader mirrors with its own copy for the
@@ -8785,7 +8926,7 @@ ${safeText}
8785
8926
  }
8786
8927
  return wrappedFragment ? document2.body.innerHTML || "" : document2.toString();
8787
8928
  }
8788
- function collectExternalAssets(html, projectDir, log = defaultLogger, file = "index.html") {
8929
+ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "index.html", policy = {}) {
8789
8930
  const absProjectDir = resolve7(projectDir);
8790
8931
  const externalAssets = /* @__PURE__ */ new Map();
8791
8932
  const leftOut = /* @__PURE__ */ new Set();
@@ -8798,7 +8939,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8798
8939
  }
8799
8940
  const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
8800
8941
  if (!onShare && !existsSync11(absPath)) return null;
8801
- const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath);
8942
+ const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
8802
8943
  if (refusal) {
8803
8944
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8804
8945
  leftOut.add(trimmed);
@@ -9184,7 +9325,7 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
9184
9325
  const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
9185
9326
  if (!entryPath.includes("/")) return html;
9186
9327
  const { document: document2 } = parseHTML5(html);
9187
- const assetExists = (path) => existsSync11(resolve7(projectDir, path));
9328
+ const assetExists = projectAssetExists(projectDir);
9188
9329
  rewriteAssetPaths(
9189
9330
  document2.querySelectorAll("[src], [href], [srcset]"),
9190
9331
  entryPath,
@@ -9225,18 +9366,23 @@ function bindVariableMediaSources(html, variables) {
9225
9366
  var entryFileName = (projectDir, htmlPath) => isPathInside(htmlPath, projectDir) ? relative2(projectDir, htmlPath).split(sep3).join("/") : basename5(htmlPath);
9226
9367
  async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
9227
9368
  const assetRoot = options.allowOutsideProjectAssets ? void 0 : projectDir;
9369
+ const outsideFiles = { includeScripts: options.includeOutsideScripts };
9228
9370
  if (isPathInside(htmlPath, projectDir) && escapesAssetRoot(htmlPath, assetRoot)) {
9229
9371
  throw new Error(`Entry file ${htmlPath} leads outside the project folder`);
9230
9372
  }
9373
+ if (isPathInside(htmlPath, projectDir) && runsOutsideMarkupUnasked(projectDir, htmlPath, assetRoot, outsideFiles)) {
9374
+ throw new Error(`Entry file ${htmlPath} ${OUTSIDE_COMPOSITION_NEEDS_FLAG}`);
9375
+ }
9231
9376
  if (!COMPOSITION_FILE.test(htmlPath)) {
9232
9377
  throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
9233
9378
  }
9379
+ assertCompositionFileSize(htmlPath, basename5(htmlPath));
9234
9380
  const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
9235
9381
  const rawHtml = bindVariableMediaSources(
9236
9382
  normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
9237
9383
  options.variables ?? {}
9238
9384
  );
9239
- assertSubCompositionsUsable(rawHtml, projectDir, assetRoot);
9385
+ assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
9240
9386
  const probes = /* @__PURE__ */ new Map();
9241
9387
  const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
9242
9388
  rawHtml,
@@ -9255,7 +9401,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9255
9401
  void 0,
9256
9402
  options.urlByAbsentLocalPath,
9257
9403
  probes,
9258
- assetRoot
9404
+ assetRoot,
9405
+ outsideFiles
9259
9406
  );
9260
9407
  const fullHtml = ensureFullDocument(compiledHtml);
9261
9408
  const { html: inlinedHtml, variablesByComp } = inlineSubCompositions(
@@ -9263,7 +9410,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9263
9410
  subCompositions,
9264
9411
  projectDir,
9265
9412
  options.variables ?? {},
9266
- assetRoot
9413
+ assetRoot,
9414
+ outsideFiles
9267
9415
  );
9268
9416
  const sanitizedHtml = stripPreloadNone(inlinedHtml);
9269
9417
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
@@ -9317,7 +9465,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9317
9465
  cacheDir: options.animatedGifCacheDir,
9318
9466
  sourceAssets: remoteImageAssets,
9319
9467
  timeoutMs: options.ffmpegProcessTimeout,
9320
- assetRoot
9468
+ allowOutsideFiles: assetRoot === void 0
9321
9469
  });
9322
9470
  if (preparedHeifImages.length > 0) {
9323
9471
  defaultLogger.debug(`[Compiler] Converted ${preparedHeifImages.length} HEIC image(s) to JPEG`);
@@ -9333,7 +9481,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9333
9481
  cacheDir: options.animatedGifCacheDir,
9334
9482
  sourceAssets: gifSourceAssets,
9335
9483
  timeoutMs: options.ffmpegProcessTimeout,
9336
- assetRoot
9484
+ allowOutsideFiles: assetRoot === void 0
9337
9485
  });
9338
9486
  if (preparedGifs.length > 0) {
9339
9487
  defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
@@ -9348,7 +9496,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9348
9496
  embeddedHtml,
9349
9497
  projectDir,
9350
9498
  options.log,
9351
- entryFileName(projectDir, htmlPath)
9499
+ entryFileName(projectDir, htmlPath),
9500
+ { includeScripts: options.includeOutsideScripts }
9352
9501
  ) : { html: embeddedHtml, externalAssets: /* @__PURE__ */ new Map() };
9353
9502
  for (const [relPath, absPath] of remoteMediaAssets) {
9354
9503
  externalAssets.set(relPath, absPath);
@@ -9755,7 +9904,7 @@ async function resolveCompositionDurations(page, unresolved) {
9755
9904
  }
9756
9905
  return resolutions;
9757
9906
  }
9758
- async function recompileWithResolutions(compiled, resolutions, projectDir, downloadDir, assetRoot) {
9907
+ async function recompileWithResolutions(compiled, resolutions, projectDir, downloadDir, assetRoot, outsideFiles = {}) {
9759
9908
  if (resolutions.length === 0) return compiled;
9760
9909
  const html = injectDurations(compiled.html, resolutions);
9761
9910
  const { subCompositions } = await parseSubCompositions(
@@ -9765,7 +9914,8 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
9765
9914
  void 0,
9766
9915
  void 0,
9767
9916
  void 0,
9768
- assetRoot
9917
+ assetRoot,
9918
+ outsideFiles
9769
9919
  );
9770
9920
  const { videos, audios, images } = compiled;
9771
9921
  const remaining = compiled.unresolvedCompositions.filter(
@@ -9813,6 +9963,7 @@ function resolveEntryHtmlPath(input) {
9813
9963
  `Entry file "${relative3(projectDir, path)}" leads outside the project folder`
9814
9964
  );
9815
9965
  }
9966
+ assertCompositionFileSize(path, relative3(projectDir, path));
9816
9967
  return readTextFile2(path);
9817
9968
  };
9818
9969
  const htmlPath = join20(projectDir, entryFile);
@@ -9874,7 +10025,8 @@ async function runCompileStage(input) {
9874
10025
  pageMotionBlur: input.pageMotionBlur,
9875
10026
  animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
9876
10027
  ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
9877
- allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
10028
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
10029
+ includeOutsideScripts: job.config.includeOutsideScripts
9878
10030
  });
9879
10031
  assertNotAborted();
9880
10032
  const compileOnlyMs = Date.now() - compileStart;
@@ -9960,6 +10112,8 @@ async function runCompileStage(input) {
9960
10112
  });
9961
10113
  const outputWidth = Math.round(width * deviceScaleFactor);
9962
10114
  const outputHeight = Math.round(height * deviceScaleFactor);
10115
+ requireOutputDimensions(job.config.expectedOutputDimensions, outputWidth, outputHeight);
10116
+ if (job.config.expectedOutputDimensions !== void 0) job.outputDimensionsChecked = true;
9963
10117
  if (deviceScaleFactor !== 1) {
9964
10118
  log.info("Scaling composition via deviceScaleFactor", {
9965
10119
  compositionWidth: width,
@@ -10054,30 +10208,50 @@ function hasAutoStartVideos(html) {
10054
10208
  const { document: document2 } = parseHTML6(html);
10055
10209
  return document2.querySelector("video[data-hf-auto-start]") !== null;
10056
10210
  }
10057
- function scopedVariablesFor(element, variablesByComp) {
10058
- const scope = element.closest("[data-composition-id]");
10059
- const compId = scope?.getAttribute("data-composition-id")?.trim() ?? "";
10060
- return compId && Object.hasOwn(variablesByComp, compId) ? variablesByComp[compId] : void 0;
10211
+ var MAX_VARIABLE_SCOPE_STEPS = 1e6;
10212
+ function variableIdsOn(scan, element) {
10213
+ let ids = scan.ids.get(element);
10214
+ if (!ids) {
10215
+ ids = /* @__PURE__ */ new Set([
10216
+ ...Object.keys(parseHostVariableValues2(element)),
10217
+ ...Object.keys(readDeclaredDefaults2(element))
10218
+ ]);
10219
+ scan.ids.set(element, ids);
10220
+ }
10221
+ return ids;
10222
+ }
10223
+ function scopedVariablesFor(scan, element, variablesByComp) {
10224
+ for (let node = element; node; node = node.parentElement) {
10225
+ if (++scan.steps > MAX_VARIABLE_SCOPE_STEPS) return null;
10226
+ if (!node.hasAttribute("data-composition-id")) continue;
10227
+ const compId = node.getAttribute("data-composition-id")?.trim() ?? "";
10228
+ return compId && Object.hasOwn(variablesByComp, compId) ? variablesByComp[compId] : void 0;
10229
+ }
10230
+ return void 0;
10061
10231
  }
10062
- function variableHasValue(element, variableId, variables, variablesByComp) {
10232
+ function variableHasValue(scan, element, variableId, variables, variablesByComp) {
10063
10233
  if (variables && Object.hasOwn(variables, variableId)) return true;
10064
- const scoped = scopedVariablesFor(element, variablesByComp);
10234
+ const scoped = scopedVariablesFor(scan, element, variablesByComp);
10235
+ if (scoped === null) return true;
10065
10236
  if (scoped) return Object.hasOwn(scoped, variableId);
10066
10237
  for (let scope = element.parentElement; scope; scope = scope.parentElement) {
10067
- if (Object.hasOwn(parseHostVariableValues2(scope), variableId)) return true;
10068
- if (Object.hasOwn(readDeclaredDefaults2(scope), variableId)) return true;
10238
+ if (++scan.steps > MAX_VARIABLE_SCOPE_STEPS) return true;
10239
+ if (variableIdsOn(scan, scope).has(variableId)) return true;
10069
10240
  }
10070
- return Object.hasOwn(readDeclaredDefaults2(element.ownerDocument.documentElement), variableId);
10241
+ return variableIdsOn(scan, element.ownerDocument.documentElement).has(variableId);
10071
10242
  }
10072
10243
  function hasVariableBoundMedia(html, variables, variablesByComp = {}) {
10073
10244
  const { document: document2 } = parseHTML6(html);
10245
+ const scan = { ids: /* @__PURE__ */ new Map(), steps: 0 };
10074
10246
  return Array.from(
10075
10247
  document2.querySelectorAll(
10076
10248
  "img[data-var-src], audio[data-var-src], video[data-var-src], source[data-var-src]"
10077
10249
  )
10078
10250
  ).some((element) => {
10079
10251
  const variableId = element.getAttribute("data-var-src")?.trim();
10080
- return Boolean(variableId && variableHasValue(element, variableId, variables, variablesByComp));
10252
+ return Boolean(
10253
+ variableId && variableHasValue(scan, element, variableId, variables, variablesByComp)
10254
+ );
10081
10255
  });
10082
10256
  }
10083
10257
  function authoredMediaStarts(html) {
@@ -10117,29 +10291,54 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
10117
10291
  if (sourceChanged && durationInferred) return projectedEnd;
10118
10292
  return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
10119
10293
  }
10294
+ var MAX_MEDIA_SELECTOR_WORK = 1e6;
10295
+ var SIBLING_COMBINATOR = /[~+]/;
10296
+ function managedMediaElements(document2) {
10297
+ const managed = [];
10298
+ const pending = [];
10299
+ for (const element of Array.from(document2.children)) pending.push({ element, inMedia: false });
10300
+ for (let next = pending.pop(); next; next = pending.pop()) {
10301
+ const name = next.element.tagName.toLowerCase();
10302
+ const isMedia = name === "video" || name === "audio";
10303
+ if (isMedia || next.inMedia && name === "source") managed.push(next.element);
10304
+ for (const child2 of Array.from(next.element.children)) {
10305
+ pending.push({ element: child2, inMedia: next.inMedia || isMedia });
10306
+ }
10307
+ }
10308
+ return managed;
10309
+ }
10120
10310
  function hasRuntimeMediaChanges(html) {
10121
10311
  const { document: document2 } = parseHTML6(html);
10122
10312
  const scriptBodies = [...document2.querySelectorAll("script")].map(
10123
10313
  (script) => script.textContent ?? ""
10124
10314
  );
10125
10315
  const insertedMedia = scriptBodies.some(
10126
- (script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || /<(?:video|audio)\b[^>]*>/i.test(script)
10316
+ (script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
10127
10317
  );
10128
10318
  if (insertedMedia) return true;
10129
- const isManagedMedia = (element) => {
10130
- const name = element.tagName.toLowerCase();
10131
- if (name === "video" || name === "audio") return true;
10132
- return name === "source" && element.closest("video, audio") !== null;
10133
- };
10319
+ const managed = managedMediaElements(document2);
10320
+ if (managed.length === 0) return false;
10321
+ const managedIds = new Set(managed.map((element) => element.getAttribute("id")).filter(Boolean));
10322
+ const selectors = /* @__PURE__ */ new Set();
10323
+ let selectorChars = 0;
10134
10324
  for (const script of scriptBodies) {
10135
10325
  for (const mutation of extractMediaSrcMutations(script)) {
10136
- try {
10137
- const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
10138
- const idTarget = id ? document2.getElementById(id) : null;
10139
- const targets = id ? idTarget ? [idTarget] : [] : [...document2.querySelectorAll(mutation.selector)];
10140
- if (targets.some(isManagedMedia)) return true;
10141
- } catch {
10326
+ const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
10327
+ if (id) {
10328
+ if (managedIds.has(id)) return true;
10329
+ continue;
10142
10330
  }
10331
+ if (selectors.has(mutation.selector)) continue;
10332
+ if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
10333
+ selectors.add(mutation.selector);
10334
+ selectorChars += mutation.selector.length;
10335
+ if (selectorChars * managed.length > MAX_MEDIA_SELECTOR_WORK) return true;
10336
+ }
10337
+ }
10338
+ for (const selector of selectors) {
10339
+ try {
10340
+ if (managed.some((element) => element.matches(selector))) return true;
10341
+ } catch {
10143
10342
  }
10144
10343
  }
10145
10344
  return false;
@@ -10227,7 +10426,8 @@ async function runProbeStage(input) {
10227
10426
  port: 0,
10228
10427
  preHeadScripts: [VIRTUAL_TIME_SHIM],
10229
10428
  fps: job.config.fps,
10230
- allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
10429
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
10430
+ includeOutsideScripts: job.config.includeOutsideScripts
10231
10431
  });
10232
10432
  assertNotAborted();
10233
10433
  const motionBlur = job.config.motionBlur;
@@ -10383,7 +10583,8 @@ async function runProbeStage(input) {
10383
10583
  resolutions,
10384
10584
  projectDir,
10385
10585
  join21(workDir, "downloads"),
10386
- job.config.allowOutsideProjectAssets ? void 0 : projectDir
10586
+ job.config.allowOutsideProjectAssets ? void 0 : projectDir,
10587
+ { includeScripts: job.config.includeOutsideScripts }
10387
10588
  );
10388
10589
  assertNotAborted();
10389
10590
  composition.videos = compiled.videos;
@@ -13424,7 +13625,7 @@ import {
13424
13625
  readdirSync as readdirSync5,
13425
13626
  readFileSync as readFileSync9,
13426
13627
  rmSync as rmSync11,
13427
- statSync as statSync9,
13628
+ statSync as statSync10,
13428
13629
  writeFileSync as writeFileSync6
13429
13630
  } from "node:fs";
13430
13631
  import { readFile as readFile2 } from "node:fs/promises";
@@ -13553,7 +13754,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
13553
13754
  const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
13554
13755
  if (failure) return failure;
13555
13756
  }
13556
- const fileSize = existsSync20(outputPath) ? statSync9(outputPath).size : 0;
13757
+ const fileSize = existsSync20(outputPath) ? statSync10(outputPath).size : 0;
13557
13758
  return {
13558
13759
  success: true,
13559
13760
  outputPath,
@@ -13576,7 +13777,10 @@ function startEncodeProgress(job, stage, onProgress) {
13576
13777
  function resolveEngineConfig(input) {
13577
13778
  return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
13578
13779
  }
13579
- function videoEncoderOptions(input, engineCfg) {
13780
+ function overlapEncoderThreads(workerCount, cpuCount) {
13781
+ return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
13782
+ }
13783
+ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
13580
13784
  const { job, preset } = input;
13581
13785
  return {
13582
13786
  fps: job.config.fps,
@@ -13596,7 +13800,8 @@ function videoEncoderOptions(input, engineCfg) {
13596
13800
  // keyframes that survive `-f concat -c copy` at assemble time. In-process
13597
13801
  // renders leave both undefined → preserves the existing open-GOP output.
13598
13802
  lockGopForChunkConcat: input.lockGopForChunkConcat === true,
13599
- gopSize: input.gopSize
13803
+ gopSize: input.gopSize,
13804
+ softwareEncoderThreads
13600
13805
  };
13601
13806
  }
13602
13807
  function canEncodeWhileCapturing(input, workerCount, cpuCount) {
@@ -13612,8 +13817,9 @@ async function readLandedFrame(workerPath, mergedPath) {
13612
13817
  }
13613
13818
  return readFile2(mergedPath);
13614
13819
  }
13615
- function encodeWhileCapturing(input, totalFrames) {
13820
+ function encodeWhileCapturing(input, totalFrames, captureBudget) {
13616
13821
  const engineCfg = resolveEngineConfig(input);
13822
+ const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
13617
13823
  const stop = new AbortController();
13618
13824
  const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
13619
13825
  const landed = /* @__PURE__ */ new Map();
@@ -13628,7 +13834,10 @@ function encodeWhileCapturing(input, totalFrames) {
13628
13834
  let reportFed = null;
13629
13835
  const encoder = spawnStreamingEncoder4(
13630
13836
  input.videoOnlyPath,
13631
- { ...videoEncoderOptions(input, engineCfg), imageFormat: "jpeg" },
13837
+ {
13838
+ ...videoEncoderOptions(input, engineCfg, softwareEncoderThreads),
13839
+ imageFormat: "jpeg"
13840
+ },
13632
13841
  signal,
13633
13842
  engineCfg
13634
13843
  );
@@ -13681,7 +13890,7 @@ function encodeWhileCapturing(input, totalFrames) {
13681
13890
  error: String(failure ?? result?.error)
13682
13891
  }
13683
13892
  );
13684
- return runEncodeStage(input);
13893
+ return runEncodeStage({ ...input, hasAudio: false });
13685
13894
  },
13686
13895
  abort: async () => {
13687
13896
  stop.abort();
@@ -13959,7 +14168,7 @@ function sampleDirectoryBytes(dir) {
13959
14168
  for (const name of entries) {
13960
14169
  const full = join32(current, name);
13961
14170
  try {
13962
- const st = statSync10(full);
14171
+ const st = statSync11(full);
13963
14172
  if (st.isDirectory()) {
13964
14173
  stack.push(full);
13965
14174
  } else if (st.isFile()) {
@@ -14009,6 +14218,7 @@ var RenderQualityError = class extends Error {
14009
14218
  }
14010
14219
  warnings;
14011
14220
  };
14221
+ var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
14012
14222
  function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
14013
14223
  job.warnings ??= [];
14014
14224
  const existing = new Set(
@@ -14114,7 +14324,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
14114
14324
  let rangeStart = null;
14115
14325
  for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
14116
14326
  const framePath = join32(framesDir, formatCaptureFrameName(frameIndex, frameExt));
14117
- const missing = !existsSync21(framePath) || statSync10(framePath).size <= 8;
14327
+ const missing = !existsSync21(framePath) || statSync11(framePath).size <= 8;
14118
14328
  if (missing && rangeStart === null) {
14119
14329
  rangeStart = frameIndex;
14120
14330
  } else if (!missing && rangeStart !== null) {
@@ -14979,8 +15189,14 @@ async function executeRenderPipeline(input) {
14979
15189
  const onProgress = execution.onProgress;
14980
15190
  const tooSlow = new AbortController();
14981
15191
  let tooSlowError;
15192
+ const audioFailed = new AbortController();
15193
+ let audioFailure;
14982
15194
  let calibrationEvaluateTimedOut = false;
14983
- const executionSignal = job.config.maxRenderMs ? AbortSignal.any([tooSlow.signal, ...execution.signal ? [execution.signal] : []]) : execution.signal;
15195
+ const executionSignal = AbortSignal.any([
15196
+ audioFailed.signal,
15197
+ ...job.config.maxRenderMs ? [tooSlow.signal] : [],
15198
+ ...execution.signal ? [execution.signal] : []
15199
+ ]);
14984
15200
  let fileServer = null;
14985
15201
  let probeSession = null;
14986
15202
  let lastBrowserConsole = [];
@@ -15451,7 +15667,8 @@ async function executeRenderPipeline(input) {
15451
15667
  port: 0,
15452
15668
  preHeadScripts: [VIRTUAL_TIME_SHIM],
15453
15669
  fps: job.config.fps,
15454
- allowOutsideProjectAssets: job.config.allowOutsideProjectAssets
15670
+ allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
15671
+ includeOutsideScripts: job.config.includeOutsideScripts
15455
15672
  });
15456
15673
  assertNotAborted();
15457
15674
  observability.stageEnd("file_server", fileServerStart);
@@ -16242,33 +16459,41 @@ async function executeRenderPipeline(input) {
16242
16459
  }
16243
16460
  const effectiveQuality = job.config.crf ?? preset.quality;
16244
16461
  const effectiveBitrate = job.config.crf != null ? void 0 : job.config.videoBitrate;
16245
- const audioResult = await audioWait.wait(audioStage);
16246
- const { audioOutputPath, deliverySourcePath, hasAudio } = audioResult;
16247
- perfStages.audioProcessMs = audioResult.audioProcessMs;
16248
- recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16249
- if (audioResult.audioError) {
16250
- const audioFailures = audioResult.audioFailures ?? [];
16251
- const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16252
- const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16253
- applyRenderWarningPolicy(
16254
- job,
16255
- [
16256
- {
16257
- code: "audio_processing_failed",
16258
- message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16259
- details: {
16260
- mediaType: "audio",
16261
- audioFailures: audioFailureDiagnostics2(audioFailures),
16262
- failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16263
- failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16264
- failureOwner,
16265
- retryable
16462
+ const audioReady = audioStage.then((audioResult) => {
16463
+ perfStages.audioProcessMs = audioResult.audioProcessMs;
16464
+ recordLimiterAttenuation(job, audioResult.audioLoweredDb);
16465
+ if (audioResult.audioError) {
16466
+ const audioFailures = audioResult.audioFailures ?? [];
16467
+ const failureOwner = audioFailures.length === 0 ? void 0 : audioFailures.some((failure) => failure.owner === "system") ? "system" : "user";
16468
+ const retryable = audioFailures.length === 0 ? void 0 : audioFailures.every((failure) => failure.retryable);
16469
+ applyRenderWarningPolicy(
16470
+ job,
16471
+ [
16472
+ {
16473
+ code: "audio_processing_failed",
16474
+ message: `Audio mix failed; output would be video-only: ${audioResult.audioError}`,
16475
+ details: {
16476
+ mediaType: "audio",
16477
+ audioFailures: audioFailureDiagnostics2(audioFailures),
16478
+ failureReasons: [...new Set(audioFailures.map((failure) => failure.reason))],
16479
+ failureStages: [...new Set(audioFailures.map((failure) => failure.stage))],
16480
+ failureOwner,
16481
+ retryable
16482
+ }
16266
16483
  }
16267
- }
16268
- ],
16269
- log
16270
- );
16271
- }
16484
+ ],
16485
+ log
16486
+ );
16487
+ }
16488
+ return audioResult;
16489
+ });
16490
+ audioReady.catch((error) => {
16491
+ if (executionSignal.aborted) return;
16492
+ audioFailure = error;
16493
+ audioFailed.abort(error);
16494
+ });
16495
+ const mixedAudio = () => audioWait.wait(audioReady);
16496
+ if (usableCpuCount2() < MIN_CPUS_TO_CAPTURE_DURING_MIX) await mixedAudio();
16272
16497
  resetCaptureAttemptProgress(job);
16273
16498
  if (capturePlan.kind === "hdr_layered") {
16274
16499
  const layeredPlan = capturePlan;
@@ -16451,7 +16676,7 @@ async function executeRenderPipeline(input) {
16451
16676
  } catch (err) {
16452
16677
  const isVerifyError = isDrawElementVerificationError(err);
16453
16678
  const isDeStall = isDeRendererStallError(err);
16454
- if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
16679
+ if (!isVerifyError && !isDrawElementCaptureError(err) && !isDeStall || err instanceof RenderCancelledError || executionSignal.aborted === true) {
16455
16680
  throw err;
16456
16681
  }
16457
16682
  deSelfVerifyFallback = isVerifyError;
@@ -16594,7 +16819,7 @@ async function executeRenderPipeline(input) {
16594
16819
  const isSequentialStall = isSequentialCaptureStallError(err);
16595
16820
  const isParallelStall = isParallelCaptureStallError(err);
16596
16821
  const isEncoderDeath = isRetryableEncoderDeath(err);
16597
- const isCancellation = err instanceof RenderCancelledError || executionSignal?.aborted === true;
16822
+ const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
16598
16823
  if (!shouldRetryViaPinnedFallback({
16599
16824
  isVerifyError,
16600
16825
  isDeCaptureError,
@@ -16723,8 +16948,6 @@ async function executeRenderPipeline(input) {
16723
16948
  height,
16724
16949
  needsAlpha,
16725
16950
  captureImageFormat: captureOptions.format ?? "jpeg",
16726
- hasAudio,
16727
- audioOutputPath,
16728
16951
  isPngSequence,
16729
16952
  isGif,
16730
16953
  preset,
@@ -16740,7 +16963,10 @@ async function executeRenderPipeline(input) {
16740
16963
  assertNotAborted,
16741
16964
  onProgress
16742
16965
  };
16743
- const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, workerSizing.cpuCount) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
16966
+ const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, workerSizing.cpuCount) ? encodeWhileCapturing(encodeInput, totalFrames, {
16967
+ workerCount: capturePlan.workerCount,
16968
+ cpuCount: workerSizing.cpuCount
16969
+ }) : null;
16744
16970
  const captureFrameStart = Date.now();
16745
16971
  const invokeDiskCapture = (diskPlan) => observeRenderStage(
16746
16972
  observability,
@@ -16774,7 +17000,7 @@ async function executeRenderPipeline(input) {
16774
17000
  captureRes = await invokeDiskCapture(capturePlan);
16775
17001
  } catch (err) {
16776
17002
  await overlap?.abort();
16777
- if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal?.aborted === true) {
17003
+ if (!isDrawElementVerificationError(err) && !isDrawElementCaptureError(err) || err instanceof RenderCancelledError || executionSignal.aborted === true) {
16778
17004
  throw err;
16779
17005
  }
16780
17006
  deSelfVerifyFallback = isDrawElementVerificationError(err);
@@ -16833,16 +17059,17 @@ async function executeRenderPipeline(input) {
16833
17059
  perfStages.captureMs = Date.now() - stage4Start;
16834
17060
  perfStages.captureFrameMs = captureFrameMs;
16835
17061
  perfStages.captureSetupMs = Math.max(0, perfStages.captureMs - captureFrameMs);
17062
+ const { hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 } = await mixedAudio();
16836
17063
  const encodeRes = await observeRenderStage(
16837
17064
  observability,
16838
17065
  "encode",
16839
17066
  captureStageObservationData({
16840
- hasAudio,
17067
+ hasAudio: hasAudio2,
16841
17068
  isPngSequence,
16842
17069
  isGif,
16843
17070
  chunkedEncode: enableChunkedEncode
16844
17071
  }),
16845
- () => overlap ? overlap.finish() : runEncodeStage(encodeInput)
17072
+ () => overlap ? overlap.finish() : runEncodeStage({ ...encodeInput, hasAudio: hasAudio2, audioOutputPath: audioOutputPath2 })
16846
17073
  );
16847
17074
  perfStages.encodeMs = encodeRes.encodeMs;
16848
17075
  }
@@ -16862,6 +17089,7 @@ async function executeRenderPipeline(input) {
16862
17089
  if (frameLookup) frameLookup.cleanup();
16863
17090
  closeFileServerSafely(fileServer, "renderOrchestrator", log);
16864
17091
  fileServer = null;
17092
+ const { audioOutputPath, deliverySourcePath, hasAudio } = await mixedAudio();
16865
17093
  if (!isPngSequence && !isGif) {
16866
17094
  const assembleRes = await observeRenderStage(
16867
17095
  observability,
@@ -16997,8 +17225,11 @@ async function executeRenderPipeline(input) {
16997
17225
  framesRendered: job.framesRendered ?? 0,
16998
17226
  error: caught
16999
17227
  });
17000
- const error = surfaceScriptFailure(tooSlowError ?? pageNeverReady ?? caught, job);
17001
- if (!tooSlowError && (error instanceof RenderCancelledError || executionSignal?.aborted)) {
17228
+ const error = surfaceScriptFailure(
17229
+ tooSlowError ?? audioFailure ?? pageNeverReady ?? caught,
17230
+ job
17231
+ );
17232
+ if (!tooSlowError && !audioFailure && (error instanceof RenderCancelledError || executionSignal.aborted)) {
17002
17233
  job.error = error instanceof Error ? error.message : "render_cancelled";
17003
17234
  updateJobStatus(job, "cancelled", "Render cancelled", job.progress, onProgress);
17004
17235
  await eventPublisher.flush();
@@ -17040,7 +17271,7 @@ async function executeRenderPipeline(input) {
17040
17271
  `Parallel capture timed out with ${captureObservability.workerCount ?? "auto"} workers. Video-heavy compositions often need sequential capture. Retry with --workers 1`
17041
17272
  );
17042
17273
  }
17043
- const failedStage = job.currentStage || "pipeline";
17274
+ const failedStage = audioFailure === void 0 ? job.currentStage || "pipeline" : AUDIO_STAGE;
17044
17275
  const observabilitySummary = observability.summary({
17045
17276
  lastBrowserConsole,
17046
17277
  capture: withCapturedBeyondViewport(captureObservability, dedupPerfs),
@@ -17092,7 +17323,7 @@ async function executeRenderPipeline(input) {
17092
17323
  import {
17093
17324
  existsSync as existsSync22,
17094
17325
  readFileSync as readFileSync10,
17095
- statSync as statSync11,
17326
+ statSync as statSync12,
17096
17327
  openSync as openSync5,
17097
17328
  fstatSync as fstatSync3,
17098
17329
  closeSync as closeSync5,
@@ -17133,7 +17364,7 @@ function readEntryHtml(filePath) {
17133
17364
  } catch (error) {
17134
17365
  if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
17135
17366
  return null;
17136
- if (!statSync11(filePath, { throwIfNoEntry: false })?.isFile()) return null;
17367
+ if (!statSync12(filePath, { throwIfNoEntry: false })?.isFile()) return null;
17137
17368
  throw error;
17138
17369
  }
17139
17370
  try {
@@ -17149,7 +17380,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
17149
17380
  }
17150
17381
  function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
17151
17382
  const absProjectDir = resolve9(projectDir);
17152
- if (!existsSync22(absProjectDir) || !statSync11(absProjectDir).isDirectory()) {
17383
+ if (!existsSync22(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
17153
17384
  return { error: `Project directory not found: ${absProjectDir}` };
17154
17385
  }
17155
17386
  const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
@@ -17748,6 +17979,11 @@ function assertRequestOptionScalars(options) {
17748
17979
  }
17749
17980
  function assertRequestOptionObjects(options) {
17750
17981
  validateEngineConfigSnapshot2(options.engineConfig);
17982
+ if (options.expectedOutputDimensions !== void 0 && !isExpectedOutputDimensions(options.expectedOutputDimensions)) {
17983
+ throw new Error(
17984
+ "Render request expectedOutputDimensions must contain positive integer width and height"
17985
+ );
17986
+ }
17751
17987
  if (options.variables !== void 0 && !isPlainObject(options.variables)) {
17752
17988
  throw new Error("Render request variables must be a JSON object");
17753
17989
  }
@@ -17813,7 +18049,8 @@ function renderConfigFromRequest(request, runtime = {}) {
17813
18049
  ...options,
17814
18050
  producerConfig: engineConfig,
17815
18051
  logger: runtime.logger,
17816
- allowOutsideProjectAssets: runtime.allowOutsideProjectAssets === true
18052
+ allowOutsideProjectAssets: runtime.allowOutsideProjectAssets === true,
18053
+ includeOutsideScripts: runtime.includeOutsideScripts === true
17817
18054
  };
17818
18055
  }
17819
18056
 
@@ -17830,7 +18067,9 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
17830
18067
  "RENDER_TOO_SLOW",
17831
18068
  "RENDER_STAGE_STALLED",
17832
18069
  "PAGE_NEVER_READY",
17833
- "VARIABLES_INVALID"
18070
+ "VARIABLES_INVALID",
18071
+ "OUTPUT_DIMENSIONS_MISMATCH",
18072
+ "COMPOSITION_TOO_LARGE"
17834
18073
  ]);
17835
18074
  function extractSafeRenderErrorCode(error) {
17836
18075
  if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
@@ -17937,6 +18176,7 @@ function parseRenderOptions(body) {
17937
18176
  outputDynamicRange,
17938
18177
  variables,
17939
18178
  strictVariables,
18179
+ expectedOutputDimensions: isExpectedOutputDimensions(body.expectedOutputDimensions) ? body.expectedOutputDimensions : void 0,
17940
18180
  outputResolution,
17941
18181
  outputResolutionAspectAgnostic,
17942
18182
  videoFrameFormat
@@ -17976,6 +18216,7 @@ function buildRenderJobConfig(input, outputPath, log) {
17976
18216
  entryFile: input.entryFile,
17977
18217
  variables: input.variables,
17978
18218
  strictVariables: input.strictVariables,
18219
+ expectedOutputDimensions: input.expectedOutputDimensions,
17979
18220
  outputResolution: input.outputResolution,
17980
18221
  outputResolutionAspectAgnostic: input.outputResolutionAspectAgnostic,
17981
18222
  videoFrameFormat: input.videoFrameFormat,
@@ -18020,6 +18261,9 @@ function validateRenderOverrides(body) {
18020
18261
  if (body.variables !== void 0 && !isPlainObject2(body.variables)) {
18021
18262
  return 'variables must be a JSON object keyed by variable id (e.g. {"title":"Hello"})';
18022
18263
  }
18264
+ if (body.expectedOutputDimensions !== void 0 && !isExpectedOutputDimensions(body.expectedOutputDimensions)) {
18265
+ return "expectedOutputDimensions must contain positive integer width and height";
18266
+ }
18023
18267
  if (body.strictVariables !== void 0 && typeof body.strictVariables !== "boolean") {
18024
18268
  return "strictVariables must be a boolean";
18025
18269
  }
@@ -18070,7 +18314,7 @@ function prepareProjectDirectory(projectDir, options, policy) {
18070
18314
  if (!candidate) return null;
18071
18315
  const absProjectDir = policy ? resolve10(policy.projectsDir, candidate) : resolve10(candidate);
18072
18316
  const shown = policy ? candidate : absProjectDir;
18073
- if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync25(absProjectDir) || !statSync12(absProjectDir).isDirectory()) {
18317
+ if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync25(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
18074
18318
  return { error: `Project directory not found: ${shown}` };
18075
18319
  }
18076
18320
  const entry = options.entryFile || "index.html";
@@ -18173,7 +18417,7 @@ function publicPerfSummary(job) {
18173
18417
  return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
18174
18418
  }
18175
18419
  function outputFileSize(path) {
18176
- return existsSync25(path) ? statSync12(path).size : 0;
18420
+ return existsSync25(path) ? statSync13(path).size : 0;
18177
18421
  }
18178
18422
  function createBlockingProgressReporter(log, requestId) {
18179
18423
  let lastLoggedPct = -10;
@@ -18376,7 +18620,8 @@ function createRenderHandlers(options = {}) {
18376
18620
  outcome: job.outcome ?? "completed",
18377
18621
  warnings: job.warnings,
18378
18622
  perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
18379
- ...strictVariablesResult(job)
18623
+ ...strictVariablesResult(job),
18624
+ ...job.outputDimensionsChecked === void 0 ? {} : { outputDimensionsChecked: job.outputDimensionsChecked }
18380
18625
  });
18381
18626
  } catch (error) {
18382
18627
  const durationMs = Date.now() - t0;
@@ -18473,7 +18718,8 @@ function createRenderHandlers(options = {}) {
18473
18718
  warnings: job.warnings,
18474
18719
  perf: policy ? publicPerfSummary(job) : job.perfSummary ?? null,
18475
18720
  producerVersion: readProducerVersion(),
18476
- ...strictVariablesResult(job)
18721
+ ...strictVariablesResult(job),
18722
+ ...job.outputDimensionsChecked === void 0 ? {} : { outputDimensionsChecked: job.outputDimensionsChecked }
18477
18723
  })
18478
18724
  });
18479
18725
  } catch (error) {
@@ -18502,7 +18748,7 @@ function createRenderHandlers(options = {}) {
18502
18748
  store.delete(token);
18503
18749
  return c.json({ success: false, error: "Output artifact file missing" }, 404);
18504
18750
  }
18505
- const stats = statSync12(artifact.path);
18751
+ const stats = statSync13(artifact.path);
18506
18752
  return new Response(createReadStream3(artifact.path), {
18507
18753
  headers: {
18508
18754
  "content-type": "video/mp4",