@hyperframes/producer 0.9.55 → 0.9.58

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.
@@ -48,7 +48,296 @@ import {
48
48
  toFps as toFps2
49
49
  } from "@hyperframes/core";
50
50
  import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
51
- import { HTML_BODY_CSS_HEIGHT_FIRST_RE, HTML_BODY_CSS_WIDTH_FIRST_RE } from "@hyperframes/parsers";
51
+
52
+ // src/services/htmlTagScans.ts
53
+ function forwardFinder(text, pattern) {
54
+ let start = -1;
55
+ let found = null;
56
+ return (from) => {
57
+ if (start < 0 || from < start || found !== null && from > found.index) {
58
+ start = from;
59
+ pattern.lastIndex = from;
60
+ found = pattern.exec(text);
61
+ }
62
+ return found;
63
+ };
64
+ }
65
+ function indexFinder(text, pattern) {
66
+ const find = forwardFinder(text, pattern);
67
+ return (from) => find(from)?.index ?? -1;
68
+ }
69
+ var isLetter = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122;
70
+ var isDigit = (code) => code >= 48 && code <= 57;
71
+ var isNameChar = (code) => isLetter(code) || isDigit(code) || code === 45;
72
+ var isWordChar = (code) => isLetter(code) || isDigit(code) || code === 95;
73
+ function nameRunEnd(text, from) {
74
+ let end = from;
75
+ while (isNameChar(text.charCodeAt(end))) end++;
76
+ return end;
77
+ }
78
+ function tagNameEnd(text, open) {
79
+ for (let end = nameRunEnd(text, open + 2); end >= open + 2; end--) {
80
+ if (isWordChar(text.charCodeAt(end - 1)) !== isWordChar(text.charCodeAt(end))) return end;
81
+ }
82
+ return -1;
83
+ }
84
+ function* inlineScriptBlocks(html) {
85
+ const opener = /<script\b/gi;
86
+ const closer = /<\/script>/gi;
87
+ for (let open = opener.exec(html); open; open = opener.exec(html)) {
88
+ const attrsStart = open.index + open[0].length;
89
+ const gt = html.indexOf(">", attrsStart);
90
+ if (gt < 0) return;
91
+ closer.lastIndex = gt + 1;
92
+ const close = closer.exec(html);
93
+ if (!close) return;
94
+ yield { attrs: html.slice(attrsStart, gt), body: html.slice(gt + 1, close.index) };
95
+ opener.lastIndex = close.index + close[0].length;
96
+ }
97
+ }
98
+ function removeDelimitedRuns(source, start, end) {
99
+ let out = "";
100
+ let kept = 0;
101
+ for (let open = source.indexOf(start); open >= 0; open = source.indexOf(start, kept)) {
102
+ const close = source.indexOf(end, open + start.length);
103
+ if (close < 0) break;
104
+ out += source.slice(kept, open);
105
+ kept = close + end.length;
106
+ }
107
+ return out + source.slice(kept);
108
+ }
109
+ function gsapDistFile(value) {
110
+ let dist = -1;
111
+ const distPattern = /\/dist\//gi;
112
+ for (let m = distPattern.exec(value); m; m = distPattern.exec(value)) {
113
+ if (m.index + 6 < value.length) dist = m.index;
114
+ distPattern.lastIndex = m.index + 1;
115
+ }
116
+ const gsap = dist < 0 ? null : /gsap/i.exec(value);
117
+ return gsap && gsap.index + 4 <= dist ? value.slice(dist + 6) : void 0;
118
+ }
119
+ function lastGsapMatch(html, finders, tagStart, gt) {
120
+ const { nextSrc, nextQuote, nextGt } = finders;
121
+ let match;
122
+ for (let src = nextSrc(tagStart); src && src.index < gt; src = nextSrc(src.index + 1)) {
123
+ const valueStart = src.index + 5;
124
+ const close = nextQuote(valueStart);
125
+ const end = close < 0 ? -1 : nextGt(close + 1);
126
+ if (end < 0) return { match, laterTagsFail: true };
127
+ const file = gsapDistFile(html.slice(valueStart, close));
128
+ if (file !== void 0) match = { valueStart, close, end, file };
129
+ }
130
+ return { match, laterTagsFail: false };
131
+ }
132
+ function replaceGsapDistScripts(html, replace) {
133
+ const opener = /<script\b/gi;
134
+ const finders = {
135
+ nextSrc: forwardFinder(html, /\bsrc=["']/gi),
136
+ nextQuote: indexFinder(html, /["']/g),
137
+ nextGt: indexFinder(html, />/g)
138
+ };
139
+ let out = "";
140
+ let kept = 0;
141
+ for (let open = opener.exec(html); open; open = opener.exec(html)) {
142
+ const gt = finders.nextGt(open.index);
143
+ if (gt < 0) break;
144
+ const { match, laterTagsFail } = lastGsapMatch(html, finders, open.index, gt);
145
+ if (match) {
146
+ const { valueStart, close, end, file } = match;
147
+ const full = html.slice(open.index, end + 1);
148
+ const src = html.slice(valueStart, close);
149
+ out += html.slice(kept, open.index);
150
+ out += replace(
151
+ full,
152
+ html.slice(open.index, valueStart),
153
+ src,
154
+ file,
155
+ html.slice(close, end + 1)
156
+ );
157
+ kept = end + 1;
158
+ }
159
+ if (laterTagsFail) break;
160
+ opener.lastIndex = match ? kept : gt;
161
+ }
162
+ return out + html.slice(kept);
163
+ }
164
+ function removeSpanPerTag(html, opener, spanIn) {
165
+ const nextGt = indexFinder(html, />/g);
166
+ let out = "";
167
+ let kept = 0;
168
+ for (let open = opener.exec(html); open; open = opener.exec(html)) {
169
+ const attrsStart = open.index + open[0].length;
170
+ const gt = nextGt(attrsStart);
171
+ const span = spanIn(attrsStart, gt < 0 ? html.length : gt);
172
+ if (span) {
173
+ out += html.slice(kept, span[0]);
174
+ kept = span[1];
175
+ } else if (gt < 0) break;
176
+ opener.lastIndex = span ? kept : gt;
177
+ }
178
+ return out + html.slice(kept);
179
+ }
180
+ function stripCrossoriginAttr(html, tagName) {
181
+ const nextQuote = indexFinder(html, /["']/g);
182
+ const nextAttr = forwardFinder(html, /\scrossorigin/gi);
183
+ return removeSpanPerTag(html, new RegExp(`<${tagName}\\b`, "gi"), (attrsStart, tagEnd) => {
184
+ let last = -1;
185
+ for (let at = nextAttr(attrsStart); at && at.index < tagEnd; at = nextAttr(at.index + 12)) {
186
+ last = at.index;
187
+ }
188
+ if (last < 0) return void 0;
189
+ const nameEnd = last + 12;
190
+ const quote = html[nameEnd + 1];
191
+ const quoted = html[nameEnd] === "=" && (quote === '"' || quote === "'");
192
+ const close = quoted ? nextQuote(nameEnd + 2) : -1;
193
+ return [last, close < 0 ? nameEnd : close + 1];
194
+ });
195
+ }
196
+ function stripPreloadNone(html) {
197
+ const nextAttr = forwardFinder(html, /(?<!\s)\s+preload\s*=\s*["']none["']/gi);
198
+ return removeSpanPerTag(html, /<(?:video|audio)\b/gi, (attrsStart, tagEnd) => {
199
+ const attr = nextAttr(attrsStart);
200
+ return attr && attr.index < tagEnd ? [attr.index, attr.index + attr[0].length] : void 0;
201
+ });
202
+ }
203
+ var REMOTE_SRC_TAGS = {
204
+ media: { opener: "<(?:video|audio)\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
205
+ source: { opener: "<source\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
206
+ img: { opener: "<img\\b", attr: /(?<![\w-])src\s*=\s*["'](https?:\/\/)/gi }
207
+ };
208
+ function remoteSrcUrls(html, tag) {
209
+ const opener = new RegExp(REMOTE_SRC_TAGS[tag].opener, "gi");
210
+ const nextAttr = forwardFinder(html, new RegExp(REMOTE_SRC_TAGS[tag].attr));
211
+ const nextGt = indexFinder(html, />/g);
212
+ const nextQuote = indexFinder(html, /["']/g);
213
+ const urls = [];
214
+ for (let open = opener.exec(html); open; open = opener.exec(html)) {
215
+ const attrsStart = open.index + open[0].length;
216
+ const gt = nextGt(attrsStart);
217
+ if (gt < 0) break;
218
+ let resumeAt = gt;
219
+ for (let attr = nextAttr(attrsStart); attr && attr.index < gt; attr = nextAttr(attr.index + 1)) {
220
+ const urlRest = attr.index + attr[0].length;
221
+ const close = nextQuote(urlRest);
222
+ if (close < 0) return urls;
223
+ if (close === urlRest) continue;
224
+ const end = nextGt(close + 1);
225
+ if (end < 0) return urls;
226
+ urls.push(html.slice(urlRest - attr[1].length, close));
227
+ resumeAt = end + 1;
228
+ break;
229
+ }
230
+ opener.lastIndex = resumeAt;
231
+ }
232
+ return urls;
233
+ }
234
+ function removeScriptAndStyleBlocks(markup) {
235
+ const opener = /<(script|style)\b/gi;
236
+ const nextGt = indexFinder(markup, />/g);
237
+ const closers = {
238
+ script: forwardFinder(markup, /<\/script>/gi),
239
+ style: forwardFinder(markup, /<\/style>/gi)
240
+ };
241
+ let out = "";
242
+ let kept = 0;
243
+ for (let open = opener.exec(markup); open; open = opener.exec(markup)) {
244
+ const gt = nextGt(open.index + open[0].length);
245
+ if (gt < 0) break;
246
+ const close = closers[open[1].toLowerCase()](gt + 1);
247
+ if (!close) continue;
248
+ out += markup.slice(kept, open.index);
249
+ kept = close.index + close[0].length;
250
+ opener.lastIndex = kept;
251
+ }
252
+ return out + markup.slice(kept);
253
+ }
254
+ var VOID_TAG = /(img|br|hr|input|source|track|area|base|col|embed|link|meta|param|wbr)\b/iy;
255
+ function countedTagAt(markup, open, nextGt) {
256
+ const first = markup.charCodeAt(open + 1);
257
+ if (first === 47 && isLetter(markup.charCodeAt(open + 2))) {
258
+ const end = nameRunEnd(markup, open + 3);
259
+ return { name: markup.slice(open + 2, end), end };
260
+ }
261
+ if (!isLetter(first)) return void 0;
262
+ VOID_TAG.lastIndex = open + 1;
263
+ const known = VOID_TAG.exec(markup);
264
+ if (known) return { name: known[1], end: open + 1 + known[0].length };
265
+ const nameEnd = tagNameEnd(markup, open);
266
+ const gt = nameEnd < 0 ? -1 : nextGt(open);
267
+ if (gt < 0 || markup.charCodeAt(gt - 1) !== 47) return void 0;
268
+ return { name: markup.slice(open + 1, nameEnd), end: gt + 1 };
269
+ }
270
+ function* countedTagNames(markup) {
271
+ const nextGt = indexFinder(markup, />/g);
272
+ for (let open = markup.indexOf("<"); open >= 0; ) {
273
+ const tag = countedTagAt(markup, open, nextGt);
274
+ if (tag) yield tag.name;
275
+ open = markup.indexOf("<", tag ? tag.end : open + 1);
276
+ }
277
+ }
278
+ function countTagsWithAttr(markup, tagName, attr) {
279
+ const opener = new RegExp(`<${tagName}\\b`, "gi");
280
+ const nextGt = indexFinder(markup, />/g);
281
+ const nextAttr = forwardFinder(markup, new RegExp(attr, "gi"));
282
+ let count = 0;
283
+ for (let open = opener.exec(markup); open; open = opener.exec(markup)) {
284
+ const attrsStart = open.index + open[0].length;
285
+ const gt = nextGt(attrsStart);
286
+ if (gt < 0) break;
287
+ const found = nextAttr(attrsStart);
288
+ const inTag = found !== null && found.index < gt;
289
+ if (inTag) count++;
290
+ opener.lastIndex = inTag ? gt + 1 : gt;
291
+ }
292
+ return count;
293
+ }
294
+ function lastQuotedValueCloses(nextAttr, nextQuote, from, tagEnd) {
295
+ let close = -1;
296
+ let earlierClose = -1;
297
+ for (let attr = nextAttr(from); attr && attr.index < tagEnd; attr = nextAttr(attr.index + 1)) {
298
+ const quote = nextQuote(attr.index + attr[0].length);
299
+ if (quote < 0) return { close, earlierClose, unclosed: true };
300
+ earlierClose = close;
301
+ close = quote;
302
+ }
303
+ return { close, earlierClose, unclosed: false };
304
+ }
305
+ function* tagsWithQuotedAttr(html, name) {
306
+ const opener = /<[a-zA-Z]/g;
307
+ const nextGt = indexFinder(html, />/g);
308
+ const nextQuote = indexFinder(html, /["']/g);
309
+ const nextAttr = forwardFinder(html, new RegExp(`\\b${name}=["']`, "gi"));
310
+ for (let open = opener.exec(html); open; open = opener.exec(html)) {
311
+ if (tagNameEnd(html, open.index) < 0) continue;
312
+ const gt = nextGt(open.index);
313
+ const tagEnd = gt < 0 ? html.length : gt;
314
+ const { close, earlierClose, unclosed } = lastQuotedValueCloses(
315
+ nextAttr,
316
+ nextQuote,
317
+ open.index + 2,
318
+ tagEnd
319
+ );
320
+ if (close >= 0) yield { start: open.index, close, earlierClose };
321
+ if (unclosed || close < 0 && gt < 0) return;
322
+ opener.lastIndex = close >= 0 ? close + 1 : gt;
323
+ }
324
+ }
325
+ function countCompositionSrcMounts(markup) {
326
+ let count = 0;
327
+ for (const _ of tagsWithQuotedAttr(markup, "data-composition-src")) count++;
328
+ return count;
329
+ }
330
+ function firstCompositionIdTag(html) {
331
+ for (const { start, close, earlierClose } of tagsWithQuotedAttr(html, "data-composition-id")) {
332
+ let end = html.indexOf(">", close + 1);
333
+ if (end < 0 && earlierClose >= 0) end = html.indexOf(">", earlierClose + 1);
334
+ return end < 0 ? void 0 : html.slice(start, end + 1);
335
+ }
336
+ return void 0;
337
+ }
338
+
339
+ // src/services/renderOrchestrator.ts
340
+ import { matchHtmlBodyCssHeightFirst, matchHtmlBodyCssWidthFirst } from "@hyperframes/parsers";
52
341
  import {
53
342
  extractMediaMetadata as extractMediaMetadata5,
54
343
  resolveConfig as resolveConfig2,
@@ -112,7 +401,7 @@ import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:p
112
401
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
113
402
  import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
114
403
  import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
115
- import { fpsToNumber } from "@hyperframes/core";
404
+ import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
116
405
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
117
406
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
118
407
  import { openRangeEnd } from "@hyperframes/studio-server/media-range";
@@ -203,6 +492,7 @@ function getHfEarlyStub() {
203
492
  }
204
493
 
205
494
  // src/logger.ts
495
+ import { terminalText } from "@hyperframes/core";
206
496
  var LOG_LEVEL_PRIORITY = {
207
497
  error: 0,
208
498
  warn: 1,
@@ -212,26 +502,26 @@ var LOG_LEVEL_PRIORITY = {
212
502
  function createConsoleLogger(level = "info") {
213
503
  const threshold = LOG_LEVEL_PRIORITY[level];
214
504
  const shouldLog = (msgLevel) => LOG_LEVEL_PRIORITY[msgLevel] <= threshold;
215
- const formatMeta = (meta) => meta ? ` ${JSON.stringify(meta)}` : "";
505
+ const formatMeta = (meta) => meta ? ` ${terminalText(JSON.stringify(meta))}` : "";
216
506
  return {
217
507
  error(message, meta) {
218
508
  if (shouldLog("error")) {
219
- console.error(`[ERROR] ${message}${formatMeta(meta)}`);
509
+ console.error(`[ERROR] ${terminalText(message)}${formatMeta(meta)}`);
220
510
  }
221
511
  },
222
512
  warn(message, meta) {
223
513
  if (shouldLog("warn")) {
224
- console.warn(`[WARN] ${message}${formatMeta(meta)}`);
514
+ console.warn(`[WARN] ${terminalText(message)}${formatMeta(meta)}`);
225
515
  }
226
516
  },
227
517
  info(message, meta) {
228
518
  if (shouldLog("info")) {
229
- console.error(`[INFO] ${message}${formatMeta(meta)}`);
519
+ console.error(`[INFO] ${terminalText(message)}${formatMeta(meta)}`);
230
520
  }
231
521
  },
232
522
  debug(message, meta) {
233
523
  if (shouldLog("debug")) {
234
- console.error(`[DEBUG] ${message}${formatMeta(meta)}`);
524
+ console.error(`[DEBUG] ${terminalText(message)}${formatMeta(meta)}`);
235
525
  }
236
526
  },
237
527
  isLevelEnabled(msgLevel) {
@@ -880,7 +1170,7 @@ function createFileServer(options) {
880
1170
  const headScripts = options.headScripts ?? [getVerifiedHyperframeRuntimeSource()];
881
1171
  const bodyScripts = options.bodyScripts ?? [buildRenderModeScript(options.fps), HF_BRIDGE_SCRIPT];
882
1172
  const app = new Hono();
883
- const warnLeftOut = (line) => console.warn(`[FileServer] ${line}`);
1173
+ const warnLeftOut = (line) => console.warn(`[FileServer] ${terminalText2(line)}`);
884
1174
  let listeningPort = -1;
885
1175
  app.use(async function loadEachFileOnlyAsItsNamedType(c, next) {
886
1176
  await next();
@@ -904,7 +1194,7 @@ function createFileServer(options) {
904
1194
  }
905
1195
  if (!file) {
906
1196
  if (!/favicon\.ico$/i.test(requestPath)) {
907
- console.warn(`[FileServer] 404 Not Found: ${requestPath}`);
1197
+ console.warn(`[FileServer] 404 Not Found: ${terminalText2(requestPath)}`);
908
1198
  }
909
1199
  return c.text("Not found", 404);
910
1200
  }
@@ -1142,7 +1432,8 @@ import {
1142
1432
  import { basename as basename2, dirname as dirname2, isAbsolute, join as join3, relative, resolve as resolve3 } from "node:path";
1143
1433
  import {
1144
1434
  CANVAS_DIMENSIONS,
1145
- checkOutputResolutionCompatibility
1435
+ checkOutputResolutionCompatibility,
1436
+ terminalText as terminalText3
1146
1437
  } from "@hyperframes/core";
1147
1438
  import {
1148
1439
  mediaIdPathSegment
@@ -1187,7 +1478,7 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1187
1478
  for (const [srcPath, html] of compiled.subCompositions) {
1188
1479
  const outPath = join3(compileDir, srcPath);
1189
1480
  if (!isPathInside(outPath, compileDir)) {
1190
- console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
1481
+ console.warn(`[Render] Skipping sub-composition with unsafe path: ${terminalText3(srcPath)}`);
1191
1482
  continue;
1192
1483
  }
1193
1484
  mkdirSync(dirname2(outPath), { recursive: true });
@@ -1196,7 +1487,9 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
1196
1487
  for (const [relativePath, absolutePath] of compiled.externalAssets) {
1197
1488
  const outPath = resolve3(join3(compileDir, relativePath));
1198
1489
  if (!isPathInside(outPath, compileDir)) {
1199
- console.warn(`[Render] Skipping external asset with unsafe path: ${relativePath}`);
1490
+ console.warn(
1491
+ `[Render] Skipping external asset with unsafe path: ${terminalText3(relativePath)}`
1492
+ );
1200
1493
  continue;
1201
1494
  }
1202
1495
  mkdirSync(dirname2(outPath), { recursive: true });
@@ -3095,6 +3388,7 @@ import {
3095
3388
  resolveProjectRelativeSrc,
3096
3389
  resolveVideoExtractionWindow,
3097
3390
  runFfmpeg,
3391
+ urlInputArgs,
3098
3392
  videoStartOnMediaTimeline
3099
3393
  } from "@hyperframes/engine";
3100
3394
  import { fpsToFfmpegArg, fpsToNumber as fpsToNumber3 } from "@hyperframes/core";
@@ -3387,7 +3681,15 @@ function hdrWindowFrames(frameSize, windowBytes) {
3387
3681
  return Math.max(8, Math.floor(windowBytes / frameSize));
3388
3682
  }
3389
3683
  async function probeFirstTick(srcPath, mediaStart, fps, runFfmpegImpl, abortSignal) {
3390
- const args = ["-ss", String(mediaStart), "-i", srcPath, "-frames:v", "1"];
3684
+ const args = [
3685
+ ...urlInputArgs(srcPath),
3686
+ "-ss",
3687
+ String(mediaStart),
3688
+ "-i",
3689
+ srcPath,
3690
+ "-frames:v",
3691
+ "1"
3692
+ ];
3391
3693
  const result = await runFfmpegImpl([...args, ...["-vf", "showinfo", "-f", "null", "-"]], {
3392
3694
  signal: abortSignal
3393
3695
  });
@@ -3461,6 +3763,7 @@ async function extractHdrVideoFrames(args) {
3461
3763
  // Decode before seeking for the one-frame path. Input-side seeking can
3462
3764
  // return zero frames for valid unindexed/negative-base transports.
3463
3765
  [
3766
+ ...urlInputArgs(srcPath),
3464
3767
  "-i",
3465
3768
  srcPath,
3466
3769
  "-ss",
@@ -3545,6 +3848,7 @@ function hdrWindowFfmpegArgs(a) {
3545
3848
  const filters = [`fps=${a.fpsArg}:start_time=${(a.firstTick / a.fps).toFixed(6)}`, a.scale];
3546
3849
  if (trim > 0) filters.push(`trim=start_frame=${trim}`);
3547
3850
  return [
3851
+ ...urlInputArgs(a.srcPath),
3548
3852
  ...["-ss", (a.ffmpegSeek + seekFrame / a.fps).toFixed(6), "-i", a.srcPath],
3549
3853
  ...["-vf", filters.join(","), "-frames:v", String(a.frames), "-fps_mode", "passthrough"]
3550
3854
  ];
@@ -3558,50 +3862,71 @@ function holdFirstFrameUntilStreamStarts(windows, firstTick) {
3558
3862
  close: () => windows.close()
3559
3863
  };
3560
3864
  }
3865
+ function fitHdrImageLayoutToFrame(layout, frameWidth, frameHeight) {
3866
+ const scale = Math.min(1, frameWidth / layout.width, frameHeight / layout.height);
3867
+ if (scale === 1) return layout;
3868
+ return {
3869
+ width: Math.max(1, Math.floor(layout.width * scale)),
3870
+ height: Math.max(1, Math.floor(layout.height * scale))
3871
+ };
3872
+ }
3561
3873
  function decodeHdrImageBuffers(args) {
3562
- const { log, hdrImageSrcPaths, prep, hdrDiagnostics } = args;
3874
+ const { log, hdrImageSrcPaths, prep, hdrDiagnostics, width, height } = args;
3875
+ const budgetBytes = resolveHdrExtractionBudgetBytes(process.env[HDR_EXTRACTION_MAX_BYTES_ENV]);
3876
+ const releases = [];
3877
+ const releaseReservation = () => {
3878
+ for (const release of releases.splice(0)) release();
3879
+ };
3563
3880
  const out = /* @__PURE__ */ new Map();
3564
3881
  for (const [imageId, srcPath] of hdrImageSrcPaths) {
3565
3882
  try {
3566
3883
  const decoded = decodePngToRgb48le(readFileSync3(srcPath));
3884
+ const releaseDecoded = reserveHdrExtractionBytes(decoded.data.length, budgetBytes);
3567
3885
  const layout = prep.hdrExtractionDims.get(imageId);
3568
- const fitInfo = prep.hdrImageFitInfo.get(imageId);
3569
- if (layout && (layout.width !== decoded.width || layout.height !== decoded.height)) {
3570
- const fit = normalizeObjectFit(fitInfo?.fit);
3886
+ if (!layout || layout.width === decoded.width && layout.height === decoded.height) {
3887
+ releases.push(releaseDecoded);
3888
+ out.set(imageId, decoded);
3889
+ continue;
3890
+ }
3891
+ const target = fitHdrImageLayoutToFrame(layout, width, height);
3892
+ if (target !== layout) {
3893
+ log.warn("HDR image layout box is larger than the output frame; drawing it smaller", {
3894
+ imageId,
3895
+ layout: `${layout.width}x${layout.height}`,
3896
+ drawn: `${target.width}x${target.height}`
3897
+ });
3898
+ }
3899
+ try {
3900
+ releases.push(reserveHdrExtractionBytes(target.width * target.height * 6, budgetBytes));
3901
+ const fitInfo = prep.hdrImageFitInfo.get(imageId);
3571
3902
  const resampled = resampleRgb48leObjectFit(
3572
3903
  decoded.data,
3573
3904
  decoded.width,
3574
3905
  decoded.height,
3575
- layout.width,
3576
- layout.height,
3577
- fit,
3906
+ target.width,
3907
+ target.height,
3908
+ normalizeObjectFit(fitInfo?.fit),
3578
3909
  fitInfo?.position
3579
3910
  );
3580
- out.set(imageId, {
3581
- data: resampled,
3582
- width: layout.width,
3583
- height: layout.height
3584
- });
3585
- } else {
3586
- out.set(imageId, {
3587
- data: Buffer.from(decoded.data),
3588
- width: decoded.width,
3589
- height: decoded.height
3590
- });
3911
+ out.set(imageId, { data: resampled, width: target.width, height: target.height });
3912
+ } finally {
3913
+ releaseDecoded();
3591
3914
  }
3592
3915
  } catch (err) {
3916
+ releaseReservation();
3593
3917
  hdrDiagnostics.imageDecodeFailures += 1;
3918
+ const message = err instanceof Error ? err.message : String(err);
3594
3919
  log.error("HDR image decode failed; aborting render", {
3595
3920
  imageId,
3596
3921
  srcPath,
3597
- error: err instanceof Error ? err.message : String(err)
3922
+ error: message
3598
3923
  });
3599
3924
  throw new Error(
3600
- `HDR image decode failed for image "${imageId}". Aborting render to avoid shipping missing HDR image layers.`
3925
+ `HDR image decode failed for image "${imageId}": ${message}. Aborting render to avoid shipping missing HDR image layers.`
3601
3926
  );
3602
3927
  }
3603
3928
  }
3604
- return out;
3929
+ return { buffers: out, releaseReservation };
3605
3930
  }
3606
3931
 
3607
3932
  // src/services/render/stages/captureHdrFrameShared.ts
@@ -6599,7 +6924,8 @@ import {
6599
6924
  rewriteAssetPath,
6600
6925
  rewriteAssetPaths,
6601
6926
  rewriteCssAssetUrls,
6602
- rewriteInlineStyleAssetUrls
6927
+ rewriteInlineStyleAssetUrls,
6928
+ terminalText as terminalText4
6603
6929
  } from "@hyperframes/core";
6604
6930
  import { MAX_AUDIO_GAIN } from "@hyperframes/core/audio-gain";
6605
6931
  import { CAPTURE_CANVAS_SELECTOR } from "@hyperframes/core/html-in-canvas";
@@ -6810,6 +7136,7 @@ function placeAudio(audio, window2) {
6810
7136
  import {
6811
7137
  analyzeKeyframeIntervals,
6812
7138
  assertMediaPayload,
7139
+ isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
6813
7140
  NotMediaPayloadError as NotMediaPayloadError2,
6814
7141
  parseMasterFxChain,
6815
7142
  probeMediaProfile as probeMediaProfile2
@@ -6837,7 +7164,13 @@ import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as
6837
7164
  import { dirname as dirname6, isAbsolute as isAbsolute2, join as join16, resolve as resolve5 } from "node:path";
6838
7165
  import { parseHTML as parseHTML3 } from "linkedom";
6839
7166
  import { parseAnimatedGifMetadata } from "@hyperframes/core";
6840
- import { DEFAULT_VP9_CPU_USED, runFfmpeg as runFfmpeg2, renameWithRetry as renameWithRetry3 } from "@hyperframes/engine";
7167
+ import {
7168
+ DEFAULT_VP9_CPU_USED,
7169
+ isPrivateUnderAssetRoots,
7170
+ runFfmpeg as runFfmpeg2,
7171
+ renameWithRetry as renameWithRetry3,
7172
+ urlInputArgs as urlInputArgs2
7173
+ } from "@hyperframes/engine";
6841
7174
  import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
6842
7175
  var PREPARED_GIF_SUBDIR = "_animated_gif";
6843
7176
  var CACHE_SCHEMA = "hfgif-v1";
@@ -6875,14 +7208,13 @@ function resolveLocalImageSourcePath(src, options) {
6875
7208
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
6876
7209
  if (mapped && existsSync9(mapped)) return mapped;
6877
7210
  if (isHttpUrl(trimmed)) return null;
6878
- const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
6879
7211
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
6880
7212
  const candidates = [
6881
- ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
7213
+ isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
6882
7214
  resolve5(options.downloadDir, normalizedBase)
6883
7215
  ];
6884
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
6885
- return candidates.find((candidate) => existsSync9(candidate) && allowed(candidate)) ?? null;
7216
+ 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));
7217
+ return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
6886
7218
  }
6887
7219
  function isUsableFile(path) {
6888
7220
  try {
@@ -6950,6 +7282,7 @@ function buildAnimatedGifTranscodeArgs(input) {
6950
7282
  args.push(
6951
7283
  "-ignore_loop",
6952
7284
  "1",
7285
+ ...urlInputArgs2(input.inputPath),
6953
7286
  "-i",
6954
7287
  input.inputPath,
6955
7288
  "-an",
@@ -7155,7 +7488,7 @@ import {
7155
7488
  } from "node:fs";
7156
7489
  import { dirname as dirname7, join as join17, resolve as resolve6 } from "node:path";
7157
7490
  import { parseHTML as parseHTML4 } from "linkedom";
7158
- import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe } from "@hyperframes/engine";
7491
+ import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
7159
7492
 
7160
7493
  // src/services/heifRotation.ts
7161
7494
  function* boxes(buf, start, end) {
@@ -7354,6 +7687,7 @@ async function convertHeifToJpeg(request) {
7354
7687
  "-hide_banner",
7355
7688
  "-loglevel",
7356
7689
  "error",
7690
+ ...urlInputArgs3(request.inputPath),
7357
7691
  "-i",
7358
7692
  request.inputPath,
7359
7693
  ...mapArgs,
@@ -7477,7 +7811,9 @@ import {
7477
7811
  fingerprintElementId,
7478
7812
  isHttpUrl as isHttpUrl2,
7479
7813
  isInsideAssetRoots,
7814
+ isNotImagePayload,
7480
7815
  isNotMediaPayload,
7816
+ isPrivateUnderAssetRoots as isPrivateUnderAssetRoots2,
7481
7817
  playlistLeavesItsFolder,
7482
7818
  NotMediaPayloadError,
7483
7819
  probeMediaProfile,
@@ -7532,6 +7868,10 @@ function dropMediaOutsideProject(input) {
7532
7868
  const staysInside = ({ id, src }) => {
7533
7869
  if (!src || isHttpUrl2(src)) return true;
7534
7870
  const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
7871
+ if (isPrivateUnderAssetRoots2(path, roots)) {
7872
+ log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
7873
+ return false;
7874
+ }
7535
7875
  if (isInsideAssetRoots(path, roots)) return true;
7536
7876
  if (input.allowOutsideProjectAssets) {
7537
7877
  const refusal = outsideAssetRefusal(projectDir, path);
@@ -7548,6 +7888,8 @@ function dropMediaOutsideProject(input) {
7548
7888
  async function notMediaReferences(path, references) {
7549
7889
  const videos = references.filter((ref) => ref.expected === "video");
7550
7890
  if (videos.length > 0 && await isNotMediaPayload(path)) return videos;
7891
+ const images = references.filter((ref) => ref.expected === "image");
7892
+ if (images.length > 0 && await isNotImagePayload(path)) return images;
7551
7893
  return await playlistLeavesItsFolder(path) ? references : [];
7552
7894
  }
7553
7895
  async function preflightCompositionAssetMediaTypes(input) {
@@ -7744,20 +8086,13 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
7744
8086
  throw new EmptyCompositionError(problems);
7745
8087
  }
7746
8088
  }
7747
- var INLINE_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
7748
8089
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
7749
8090
  var COMPILER_MOUNT_BLOCK_END = "/* __HF_COMPILER_MOUNT_END__ */";
7750
8091
  function stripJsComments(source) {
7751
- return source.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
8092
+ return removeDelimitedRuns(source.replace(/\/\/.*$/gm, ""), "/*", "*/");
7752
8093
  }
7753
8094
  function stripCompilerMountBootstrap(source) {
7754
- return source.replace(
7755
- new RegExp(
7756
- `${COMPILER_MOUNT_BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${COMPILER_MOUNT_BLOCK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
7757
- "g"
7758
- ),
7759
- ""
7760
- );
8095
+ return removeDelimitedRuns(source, COMPILER_MOUNT_BLOCK_START, COMPILER_MOUNT_BLOCK_END);
7761
8096
  }
7762
8097
  function runtimeRoot(document2) {
7763
8098
  return document2.querySelector('[data-composition-id][data-root="true"]') ?? document2.querySelector("[data-composition-id]");
@@ -7782,12 +8117,9 @@ function detectRenderModeHints(html, pageMotionBlur) {
7782
8117
  message: "Detected <iframe> in the composition DOM. Nested iframe animation is routed through screenshot capture mode for compatibility."
7783
8118
  });
7784
8119
  }
7785
- let scriptMatch;
7786
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7787
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7788
- const attrs = scriptMatch[1] || "";
8120
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7789
8121
  if (/\bsrc\s*=/i.test(attrs)) continue;
7790
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8122
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7791
8123
  if (!/requestAnimationFrame\s*\(/.test(content)) continue;
7792
8124
  reasons.push({
7793
8125
  code: "requestAnimationFrame",
@@ -7839,17 +8171,14 @@ function detectAncestorBackgroundImage(html) {
7839
8171
  }
7840
8172
  var SHADER_TRANSITION_USAGE_PATTERN = /\b(?:(?:window|globalThis)\s*\.\s*)?HyperShader\s*\.\s*init\s*\(|\b__hf\s*\.\s*transitions\s*=/;
7841
8173
  function detectShaderTransitionUsage(html) {
7842
- let scriptMatch;
7843
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7844
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7845
- const attrs = scriptMatch[1] || "";
8174
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7846
8175
  if (/\bsrc\s*=/i.test(attrs)) continue;
7847
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8176
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7848
8177
  if (SHADER_TRANSITION_USAGE_PATTERN.test(content)) return true;
7849
8178
  }
7850
8179
  return false;
7851
8180
  }
7852
- async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes, assetRoot) {
8181
+ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes, assetRoot) {
7853
8182
  let filePath = src;
7854
8183
  if (isHttpUrl(src)) {
7855
8184
  const remoteDir = join19(downloadDir, REMOTE_MEDIA_SUBDIR);
@@ -7864,7 +8193,9 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
7864
8193
  } else {
7865
8194
  filePath = decodedUrlPath(src);
7866
8195
  if (!filePath.startsWith("/")) filePath = join19(baseDir, filePath);
7867
- if (escapesAssetRoot(filePath, assetRoot)) return { duration: null, resolvedPath: filePath };
8196
+ if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir])) {
8197
+ return { duration: null, resolvedPath: filePath };
8198
+ }
7868
8199
  filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
7869
8200
  if (!isHttpUrl(filePath) && namesAnotherNetworkRoot2(baseDir, filePath)) {
7870
8201
  return { duration: null, resolvedPath: filePath };
@@ -7940,7 +8271,7 @@ function markInferredVariableMediaDurations(html, unresolvedMedia) {
7940
8271
  }
7941
8272
  return changed ? document2.toString() : html;
7942
8273
  }
7943
- async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocalPath, probes, assetRoot) {
8274
+ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath, probes, assetRoot) {
7944
8275
  const { html: staticCompiled, unresolved } = compileTimingAttrs(html);
7945
8276
  const mediaUnresolved = unresolved.filter(
7946
8277
  (el) => (el.tagName === "video" || el.tagName === "audio") && el.src
@@ -7952,6 +8283,7 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7952
8283
  el.src,
7953
8284
  el.mediaStart,
7954
8285
  el.playbackRate,
8286
+ projectDir,
7955
8287
  baseDir,
7956
8288
  downloadDir,
7957
8289
  el.tagName,
@@ -7976,6 +8308,7 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7976
8308
  el.src,
7977
8309
  el.mediaStart,
7978
8310
  el.playbackRate,
8311
+ projectDir,
7979
8312
  baseDir,
7980
8313
  downloadDir,
7981
8314
  el.tagName,
@@ -8000,9 +8333,9 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
8000
8333
  if (clampList.length > 0) {
8001
8334
  compiledHtml = clampDurations(compiledHtml, clampList);
8002
8335
  }
8003
- compiledHtml = compiledHtml.replace(/(<video\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8004
- compiledHtml = compiledHtml.replace(/(<img\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8005
- compiledHtml = compiledHtml.replace(/(<audio\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8336
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "video");
8337
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "img");
8338
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
8006
8339
  return { html: compiledHtml, unresolvedCompositions };
8007
8340
  }
8008
8341
  async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
@@ -8031,6 +8364,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
8031
8364
  workItems.map(async (item) => {
8032
8365
  const { html: compiledSub } = await compileHtmlFile(
8033
8366
  rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
8367
+ projectDir,
8034
8368
  dirname9(item.filePath),
8035
8369
  downloadDir,
8036
8370
  void 0,
@@ -8233,7 +8567,9 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8233
8567
  flattenInnerRoot: prepareFlattenedInnerRoot,
8234
8568
  onMissingComposition: (srcPath, reason) => {
8235
8569
  console.warn(
8236
- `[Compiler] Skipping sub-composition "${srcPath}": ${reason ?? "the file is missing or empty"}.`
8570
+ terminalText4(
8571
+ `[Compiler] Skipping sub-composition "${srcPath}": ${reason ?? "the file is missing or empty"}.`
8572
+ )
8237
8573
  );
8238
8574
  }
8239
8575
  }
@@ -8436,8 +8772,9 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8436
8772
  if (isPathInside(absPath, absProjectDir)) {
8437
8773
  return null;
8438
8774
  }
8439
- if (!existsSync11(absPath)) return null;
8440
- const refusal = outsideAssetRefusal(absProjectDir, absPath);
8775
+ const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
8776
+ if (!onShare && !existsSync11(absPath)) return null;
8777
+ const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath);
8441
8778
  if (refusal) {
8442
8779
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8443
8780
  leftOut.add(trimmed);
@@ -8487,9 +8824,6 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8487
8824
  };
8488
8825
  }
8489
8826
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
8490
- var REMOTE_MEDIA_TAG_RE = /<(?:video|audio)\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8491
- var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8492
- var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8493
8827
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
8494
8828
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
8495
8829
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
@@ -8528,14 +8862,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
8528
8862
  return { html: result, remoteMediaAssets };
8529
8863
  }
8530
8864
  async function localizeRemoteMediaSources(html, downloadDir) {
8531
- const urlSet = /* @__PURE__ */ new Set();
8532
- for (const tagRe of [REMOTE_MEDIA_TAG_RE, REMOTE_SOURCE_TAG_RE]) {
8533
- const re = new RegExp(tagRe.source, tagRe.flags);
8534
- let m;
8535
- while ((m = re.exec(html)) !== null) {
8536
- if (m[1]) urlSet.add(m[1]);
8537
- }
8538
- }
8865
+ const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
8539
8866
  const localized = await downloadAndRewriteUrls(
8540
8867
  urlSet,
8541
8868
  html,
@@ -8558,12 +8885,7 @@ function dropBindingOnLocalizedMedia(html) {
8558
8885
  return changed ? document2.toString() : html;
8559
8886
  }
8560
8887
  async function localizeRemoteImageSources(html, downloadDir) {
8561
- const urlSet = /* @__PURE__ */ new Set();
8562
- const re = new RegExp(REMOTE_IMG_TAG_RE.source, REMOTE_IMG_TAG_RE.flags);
8563
- let m;
8564
- while ((m = re.exec(html)) !== null) {
8565
- if (m[1]) urlSet.add(m[1]);
8566
- }
8888
+ const urlSet = new Set(remoteSrcUrls(html, "img"));
8567
8889
  return downloadAndRewriteUrls(
8568
8890
  urlSet,
8569
8891
  html,
@@ -8773,6 +9095,7 @@ async function embedLocalFontFaces(html, projectDir, assetRoot, log = defaultLog
8773
9095
  embeddedPaths.add(localPath);
8774
9096
  continue;
8775
9097
  }
9098
+ if (isPrivateCompositionFile(projectDir, absPath)) continue;
8776
9099
  const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
8777
9100
  try {
8778
9101
  if (fileBackedAbsolutePaths.has(absPath)) {
@@ -8824,16 +9147,13 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
8824
9147
  const file = resolve7(projectDir, path);
8825
9148
  return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
8826
9149
  };
8827
- return html.replace(
8828
- /(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
8829
- (full, prefix, src, file, suffix) => {
8830
- if (/^https?:\/\//i.test(src)) return full;
8831
- if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
8832
- gsapDist ??= renderGsapDist();
8833
- defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
8834
- return `${prefix}${gsapDist}${file}${suffix}`;
8835
- }
8836
- );
9150
+ return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
9151
+ if (/^https?:\/\//i.test(src)) return full;
9152
+ if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
9153
+ gsapDist ??= renderGsapDist();
9154
+ defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
9155
+ return `${prefix}${gsapDist}${file}${suffix}`;
9156
+ });
8837
9157
  }
8838
9158
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
8839
9159
  if (!isPathInside(htmlPath, projectDir)) return html;
@@ -8897,6 +9217,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8897
9217
  const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
8898
9218
  rawHtml,
8899
9219
  projectDir,
9220
+ projectDir,
8900
9221
  downloadDir,
8901
9222
  options.log,
8902
9223
  options.urlByAbsentLocalPath,
@@ -8920,10 +9241,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8920
9241
  options.variables ?? {},
8921
9242
  assetRoot
8922
9243
  );
8923
- const sanitizedHtml = inlinedHtml.replace(
8924
- /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
8925
- "$1"
8926
- );
9244
+ const sanitizedHtml = stripPreloadNone(inlinedHtml);
8927
9245
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
8928
9246
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
8929
9247
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
@@ -9032,7 +9350,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
9032
9350
  for (const video of videos) {
9033
9351
  if (isHttpUrl(video.src)) continue;
9034
9352
  const videoPath = resolve7(projectDir, video.src);
9035
- if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot))
9353
+ if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
9036
9354
  continue;
9037
9355
  advised.add(videoPath);
9038
9356
  const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
@@ -9662,7 +9980,8 @@ import {
9662
9980
  readMediaStart as readMediaStart2,
9663
9981
  shiftRateLane as shiftRateLane2,
9664
9982
  sourceTimeAt as sourceTimeAt3,
9665
- timeAtSourceTime
9983
+ timeAtSourceTime,
9984
+ terminalText as terminalText5
9666
9985
  } from "@hyperframes/core";
9667
9986
  import { parseHostVariableValues as parseHostVariableValues2, readDeclaredDefaults as readDeclaredDefaults2 } from "@hyperframes/core/compiler";
9668
9987
  import { extractMediaSrcMutations } from "@hyperframes/parsers";
@@ -10295,7 +10614,7 @@ async function runProbeStage(input) {
10295
10614
  failures: failedRequests.slice(0, 10)
10296
10615
  });
10297
10616
  for (const line of failedRequests.slice(0, 5)) {
10298
- console.warn(`[Render] Asset load failure: ${line}`);
10617
+ console.warn(`[Render] Asset load failure: ${terminalText5(line)}`);
10299
10618
  }
10300
10619
  }
10301
10620
  }
@@ -10376,7 +10695,7 @@ import {
10376
10695
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
10377
10696
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
10378
10697
  isHttpUrl as isHttpUrl3,
10379
- isInsideAssetRoots as isInsideAssetRoots2,
10698
+ assetRootsRefusal,
10380
10699
  assertPublicHttpsUrl,
10381
10700
  downloadToTemp as downloadToTemp2,
10382
10701
  resolveRestrictPageNetwork,
@@ -10809,7 +11128,7 @@ function isPublicHttpsUrl(url) {
10809
11128
  }
10810
11129
  }
10811
11130
  function opensLocally(path, assetRoots) {
10812
- return existsSync13(path) && (!assetRoots || isInsideAssetRoots2(path, assetRoots));
11131
+ return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
10813
11132
  }
10814
11133
  function localProbeSource(src, input) {
10815
11134
  const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
@@ -12791,6 +13110,7 @@ async function runCaptureHdrStage(input) {
12791
13110
  let hdrEncoderClosed = false;
12792
13111
  let domSessionClosed = false;
12793
13112
  let releaseHdrExtractionReservation = null;
13113
+ let releaseHdrImageReservation = null;
12794
13114
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
12795
13115
  try {
12796
13116
  await initializeSession7(domSession);
@@ -12872,12 +13192,16 @@ async function runCaptureHdrStage(input) {
12872
13192
  });
12873
13193
  releaseHdrExtractionReservation = extracted.releaseReservation;
12874
13194
  for (const [id, source] of extracted.sources) hdrVideoFrameSources.set(id, source);
12875
- const hdrImageBuffers = decodeHdrImageBuffers({
13195
+ const decodedImages = decodeHdrImageBuffers({
12876
13196
  log,
12877
13197
  hdrImageSrcPaths,
12878
13198
  prep,
12879
- hdrDiagnostics
13199
+ hdrDiagnostics,
13200
+ width,
13201
+ height
12880
13202
  });
13203
+ releaseHdrImageReservation = decodedImages.releaseReservation;
13204
+ const hdrImageBuffers = decodedImages.buffers;
12881
13205
  assertNotAborted();
12882
13206
  try {
12883
13207
  const cleanedUpVideos = /* @__PURE__ */ new Set();
@@ -13030,6 +13354,8 @@ async function runCaptureHdrStage(input) {
13030
13354
  hdrVideoFrameSources.clear();
13031
13355
  releaseHdrExtractionReservation?.();
13032
13356
  releaseHdrExtractionReservation = null;
13357
+ releaseHdrImageReservation?.();
13358
+ releaseHdrImageReservation = null;
13033
13359
  }
13034
13360
  return {
13035
13361
  lastBrowserConsole,
@@ -14103,8 +14429,8 @@ function envInt(name, fallback) {
14103
14429
  return Number.isInteger(parsed) ? parsed : fallback;
14104
14430
  }
14105
14431
  var MAX_REPORTED_ELEMENT_TAGS = 50;
14432
+ var MAX_SCRIPT_STYLE_STRIP_PASSES = 8;
14106
14433
  var VFX_CAPTURE_RANK = { none: 0, self: 1, backdrop: 2 };
14107
- var ROOT_COMPOSITION_TAG_RE = /<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-id=["'][^"']*["'][^>]*>/i;
14108
14434
  function bucketPxDelta(delta) {
14109
14435
  if (delta === 0) return "0";
14110
14436
  if (delta <= 10) return "1-10";
@@ -14112,12 +14438,12 @@ function bucketPxDelta(delta) {
14112
14438
  return "51+";
14113
14439
  }
14114
14440
  function detectRootBodySizeMismatch(html) {
14115
- const rootTag = html.match(ROOT_COMPOSITION_TAG_RE)?.[0];
14441
+ const rootTag = firstCompositionIdTag(html);
14116
14442
  const dataWidth = rootTag && Number(rootTag.match(/\bdata-width=["'](\d+)["']/i)?.[1]);
14117
14443
  const dataHeight = rootTag && Number(rootTag.match(/\bdata-height=["'](\d+)["']/i)?.[1]);
14118
14444
  if (!dataWidth || !dataHeight) return {};
14119
- const widthFirst = html.match(HTML_BODY_CSS_WIDTH_FIRST_RE);
14120
- const heightFirst = widthFirst ? void 0 : html.match(HTML_BODY_CSS_HEIGHT_FIRST_RE);
14445
+ const widthFirst = matchHtmlBodyCssWidthFirst(html);
14446
+ const heightFirst = widthFirst ? void 0 : matchHtmlBodyCssHeightFirst(html);
14121
14447
  const [cssWidth, cssHeight] = widthFirst ? [Number(widthFirst[2]), Number(widthFirst[4])] : heightFirst ? [Number(heightFirst[4]), Number(heightFirst[2])] : [void 0, void 0];
14122
14448
  if (!cssWidth || !cssHeight) return {};
14123
14449
  const delta = Math.max(Math.abs(dataWidth - cssWidth), Math.abs(dataHeight - cssHeight));
@@ -14125,17 +14451,15 @@ function detectRootBodySizeMismatch(html) {
14125
14451
  }
14126
14452
  function scanElementTags(html) {
14127
14453
  let markup = html;
14128
- for (let previous = ""; markup !== previous; ) {
14454
+ for (let previous = "", pass = 0; markup !== previous && pass < MAX_SCRIPT_STYLE_STRIP_PASSES; pass++) {
14129
14455
  previous = markup;
14130
- markup = markup.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
14456
+ markup = removeScriptAndStyleBlocks(markup);
14131
14457
  }
14132
14458
  let total = 0;
14133
14459
  const counts = /* @__PURE__ */ new Map();
14134
- for (const m of markup.matchAll(
14135
- /<\/([a-zA-Z][-a-zA-Z0-9]*)|<(img|br|hr|input|source|track|area|base|col|embed|link|meta|param|wbr)\b|<([a-zA-Z][-a-zA-Z0-9]*)\b[^>]*\/>/gi
14136
- )) {
14460
+ for (const name of countedTagNames(markup)) {
14137
14461
  total++;
14138
- const tag = (m[1] ?? m[2] ?? m[3] ?? "").toLowerCase();
14462
+ const tag = name.toLowerCase();
14139
14463
  counts.set(tag, (counts.get(tag) ?? 0) + 1);
14140
14464
  }
14141
14465
  const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
@@ -14144,12 +14468,16 @@ function scanElementTags(html) {
14144
14468
  );
14145
14469
  const otherCount = ranked.slice(MAX_REPORTED_ELEMENT_TAGS).reduce((sum, [, count]) => sum + count, 0);
14146
14470
  if (otherCount > 0) byTag.other = (byTag.other ?? 0) + otherCount;
14147
- const arollVideoCount = markup.match(/<video\b[^>]*\bdata-aroll=["']true["'][^>]*>/gi)?.length ?? 0;
14148
- const heygenVideoCount = markup.match(/<video\b[^>]*\bdata-media-source=["']heygen["'][^>]*>/gi)?.length ?? 0;
14471
+ const arollVideoCount = countTagsWithAttr(markup, "video", `\\bdata-aroll=["']true["']`);
14472
+ const heygenVideoCount = countTagsWithAttr(
14473
+ markup,
14474
+ "video",
14475
+ `\\bdata-media-source=["']heygen["']`
14476
+ );
14149
14477
  const audioCount = counts.get("audio") ?? 0;
14150
14478
  const imageCount = counts.get("img") ?? 0;
14151
14479
  const audioGroupCount = counts.get(HF_AUDIO_GROUP_TAG) ?? 0;
14152
- const subCompositionCount = markup.match(/<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-src=["'][^"']*["']/gi)?.length ?? 0;
14480
+ const subCompositionCount = countCompositionSrcMounts(markup);
14153
14481
  let colorGradingCount = 0;
14154
14482
  let hasLut = false;
14155
14483
  for (const m of markup.matchAll(