@hyperframes/producer 0.9.55 → 0.9.56

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,
@@ -3558,50 +3847,71 @@ function holdFirstFrameUntilStreamStarts(windows, firstTick) {
3558
3847
  close: () => windows.close()
3559
3848
  };
3560
3849
  }
3850
+ function fitHdrImageLayoutToFrame(layout, frameWidth, frameHeight) {
3851
+ const scale = Math.min(1, frameWidth / layout.width, frameHeight / layout.height);
3852
+ if (scale === 1) return layout;
3853
+ return {
3854
+ width: Math.max(1, Math.floor(layout.width * scale)),
3855
+ height: Math.max(1, Math.floor(layout.height * scale))
3856
+ };
3857
+ }
3561
3858
  function decodeHdrImageBuffers(args) {
3562
- const { log, hdrImageSrcPaths, prep, hdrDiagnostics } = args;
3859
+ const { log, hdrImageSrcPaths, prep, hdrDiagnostics, width, height } = args;
3860
+ const budgetBytes = resolveHdrExtractionBudgetBytes(process.env[HDR_EXTRACTION_MAX_BYTES_ENV]);
3861
+ const releases = [];
3862
+ const releaseReservation = () => {
3863
+ for (const release of releases.splice(0)) release();
3864
+ };
3563
3865
  const out = /* @__PURE__ */ new Map();
3564
3866
  for (const [imageId, srcPath] of hdrImageSrcPaths) {
3565
3867
  try {
3566
3868
  const decoded = decodePngToRgb48le(readFileSync3(srcPath));
3869
+ const releaseDecoded = reserveHdrExtractionBytes(decoded.data.length, budgetBytes);
3567
3870
  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);
3871
+ if (!layout || layout.width === decoded.width && layout.height === decoded.height) {
3872
+ releases.push(releaseDecoded);
3873
+ out.set(imageId, decoded);
3874
+ continue;
3875
+ }
3876
+ const target = fitHdrImageLayoutToFrame(layout, width, height);
3877
+ if (target !== layout) {
3878
+ log.warn("HDR image layout box is larger than the output frame; drawing it smaller", {
3879
+ imageId,
3880
+ layout: `${layout.width}x${layout.height}`,
3881
+ drawn: `${target.width}x${target.height}`
3882
+ });
3883
+ }
3884
+ try {
3885
+ releases.push(reserveHdrExtractionBytes(target.width * target.height * 6, budgetBytes));
3886
+ const fitInfo = prep.hdrImageFitInfo.get(imageId);
3571
3887
  const resampled = resampleRgb48leObjectFit(
3572
3888
  decoded.data,
3573
3889
  decoded.width,
3574
3890
  decoded.height,
3575
- layout.width,
3576
- layout.height,
3577
- fit,
3891
+ target.width,
3892
+ target.height,
3893
+ normalizeObjectFit(fitInfo?.fit),
3578
3894
  fitInfo?.position
3579
3895
  );
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
- });
3896
+ out.set(imageId, { data: resampled, width: target.width, height: target.height });
3897
+ } finally {
3898
+ releaseDecoded();
3591
3899
  }
3592
3900
  } catch (err) {
3901
+ releaseReservation();
3593
3902
  hdrDiagnostics.imageDecodeFailures += 1;
3903
+ const message = err instanceof Error ? err.message : String(err);
3594
3904
  log.error("HDR image decode failed; aborting render", {
3595
3905
  imageId,
3596
3906
  srcPath,
3597
- error: err instanceof Error ? err.message : String(err)
3907
+ error: message
3598
3908
  });
3599
3909
  throw new Error(
3600
- `HDR image decode failed for image "${imageId}". Aborting render to avoid shipping missing HDR image layers.`
3910
+ `HDR image decode failed for image "${imageId}": ${message}. Aborting render to avoid shipping missing HDR image layers.`
3601
3911
  );
3602
3912
  }
3603
3913
  }
3604
- return out;
3914
+ return { buffers: out, releaseReservation };
3605
3915
  }
3606
3916
 
3607
3917
  // src/services/render/stages/captureHdrFrameShared.ts
@@ -6875,14 +7185,13 @@ function resolveLocalImageSourcePath(src, options) {
6875
7185
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
6876
7186
  if (mapped && existsSync9(mapped)) return mapped;
6877
7187
  if (isHttpUrl(trimmed)) return null;
6878
- const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
6879
7188
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
6880
7189
  const candidates = [
6881
- ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
7190
+ isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
6882
7191
  resolve5(options.downloadDir, normalizedBase)
6883
7192
  ];
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;
7193
+ const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && (!escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7194
+ return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
6886
7195
  }
6887
7196
  function isUsableFile(path) {
6888
7197
  try {
@@ -7744,20 +8053,13 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
7744
8053
  throw new EmptyCompositionError(problems);
7745
8054
  }
7746
8055
  }
7747
- var INLINE_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
7748
8056
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
7749
8057
  var COMPILER_MOUNT_BLOCK_END = "/* __HF_COMPILER_MOUNT_END__ */";
7750
8058
  function stripJsComments(source) {
7751
- return source.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
8059
+ return removeDelimitedRuns(source.replace(/\/\/.*$/gm, ""), "/*", "*/");
7752
8060
  }
7753
8061
  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
- );
8062
+ return removeDelimitedRuns(source, COMPILER_MOUNT_BLOCK_START, COMPILER_MOUNT_BLOCK_END);
7761
8063
  }
7762
8064
  function runtimeRoot(document2) {
7763
8065
  return document2.querySelector('[data-composition-id][data-root="true"]') ?? document2.querySelector("[data-composition-id]");
@@ -7782,12 +8084,9 @@ function detectRenderModeHints(html, pageMotionBlur) {
7782
8084
  message: "Detected <iframe> in the composition DOM. Nested iframe animation is routed through screenshot capture mode for compatibility."
7783
8085
  });
7784
8086
  }
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] || "";
8087
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7789
8088
  if (/\bsrc\s*=/i.test(attrs)) continue;
7790
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8089
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7791
8090
  if (!/requestAnimationFrame\s*\(/.test(content)) continue;
7792
8091
  reasons.push({
7793
8092
  code: "requestAnimationFrame",
@@ -7839,12 +8138,9 @@ function detectAncestorBackgroundImage(html) {
7839
8138
  }
7840
8139
  var SHADER_TRANSITION_USAGE_PATTERN = /\b(?:(?:window|globalThis)\s*\.\s*)?HyperShader\s*\.\s*init\s*\(|\b__hf\s*\.\s*transitions\s*=/;
7841
8140
  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] || "";
8141
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7846
8142
  if (/\bsrc\s*=/i.test(attrs)) continue;
7847
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8143
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7848
8144
  if (SHADER_TRANSITION_USAGE_PATTERN.test(content)) return true;
7849
8145
  }
7850
8146
  return false;
@@ -8000,9 +8296,9 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
8000
8296
  if (clampList.length > 0) {
8001
8297
  compiledHtml = clampDurations(compiledHtml, clampList);
8002
8298
  }
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");
8299
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "video");
8300
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "img");
8301
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
8006
8302
  return { html: compiledHtml, unresolvedCompositions };
8007
8303
  }
8008
8304
  async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
@@ -8436,8 +8732,9 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8436
8732
  if (isPathInside(absPath, absProjectDir)) {
8437
8733
  return null;
8438
8734
  }
8439
- if (!existsSync11(absPath)) return null;
8440
- const refusal = outsideAssetRefusal(absProjectDir, absPath);
8735
+ const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
8736
+ if (!onShare && !existsSync11(absPath)) return null;
8737
+ const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath);
8441
8738
  if (refusal) {
8442
8739
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8443
8740
  leftOut.add(trimmed);
@@ -8487,9 +8784,6 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8487
8784
  };
8488
8785
  }
8489
8786
  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
8787
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
8494
8788
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
8495
8789
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
@@ -8528,14 +8822,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
8528
8822
  return { html: result, remoteMediaAssets };
8529
8823
  }
8530
8824
  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
- }
8825
+ const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
8539
8826
  const localized = await downloadAndRewriteUrls(
8540
8827
  urlSet,
8541
8828
  html,
@@ -8558,12 +8845,7 @@ function dropBindingOnLocalizedMedia(html) {
8558
8845
  return changed ? document2.toString() : html;
8559
8846
  }
8560
8847
  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
- }
8848
+ const urlSet = new Set(remoteSrcUrls(html, "img"));
8567
8849
  return downloadAndRewriteUrls(
8568
8850
  urlSet,
8569
8851
  html,
@@ -8824,16 +9106,13 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
8824
9106
  const file = resolve7(projectDir, path);
8825
9107
  return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
8826
9108
  };
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
- );
9109
+ return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
9110
+ if (/^https?:\/\//i.test(src)) return full;
9111
+ if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
9112
+ gsapDist ??= renderGsapDist();
9113
+ defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
9114
+ return `${prefix}${gsapDist}${file}${suffix}`;
9115
+ });
8837
9116
  }
8838
9117
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
8839
9118
  if (!isPathInside(htmlPath, projectDir)) return html;
@@ -8920,10 +9199,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8920
9199
  options.variables ?? {},
8921
9200
  assetRoot
8922
9201
  );
8923
- const sanitizedHtml = inlinedHtml.replace(
8924
- /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
8925
- "$1"
8926
- );
9202
+ const sanitizedHtml = stripPreloadNone(inlinedHtml);
8927
9203
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
8928
9204
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
8929
9205
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
@@ -12791,6 +13067,7 @@ async function runCaptureHdrStage(input) {
12791
13067
  let hdrEncoderClosed = false;
12792
13068
  let domSessionClosed = false;
12793
13069
  let releaseHdrExtractionReservation = null;
13070
+ let releaseHdrImageReservation = null;
12794
13071
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
12795
13072
  try {
12796
13073
  await initializeSession7(domSession);
@@ -12872,12 +13149,16 @@ async function runCaptureHdrStage(input) {
12872
13149
  });
12873
13150
  releaseHdrExtractionReservation = extracted.releaseReservation;
12874
13151
  for (const [id, source] of extracted.sources) hdrVideoFrameSources.set(id, source);
12875
- const hdrImageBuffers = decodeHdrImageBuffers({
13152
+ const decodedImages = decodeHdrImageBuffers({
12876
13153
  log,
12877
13154
  hdrImageSrcPaths,
12878
13155
  prep,
12879
- hdrDiagnostics
13156
+ hdrDiagnostics,
13157
+ width,
13158
+ height
12880
13159
  });
13160
+ releaseHdrImageReservation = decodedImages.releaseReservation;
13161
+ const hdrImageBuffers = decodedImages.buffers;
12881
13162
  assertNotAborted();
12882
13163
  try {
12883
13164
  const cleanedUpVideos = /* @__PURE__ */ new Set();
@@ -13030,6 +13311,8 @@ async function runCaptureHdrStage(input) {
13030
13311
  hdrVideoFrameSources.clear();
13031
13312
  releaseHdrExtractionReservation?.();
13032
13313
  releaseHdrExtractionReservation = null;
13314
+ releaseHdrImageReservation?.();
13315
+ releaseHdrImageReservation = null;
13033
13316
  }
13034
13317
  return {
13035
13318
  lastBrowserConsole,
@@ -14103,8 +14386,8 @@ function envInt(name, fallback) {
14103
14386
  return Number.isInteger(parsed) ? parsed : fallback;
14104
14387
  }
14105
14388
  var MAX_REPORTED_ELEMENT_TAGS = 50;
14389
+ var MAX_SCRIPT_STYLE_STRIP_PASSES = 8;
14106
14390
  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
14391
  function bucketPxDelta(delta) {
14109
14392
  if (delta === 0) return "0";
14110
14393
  if (delta <= 10) return "1-10";
@@ -14112,12 +14395,12 @@ function bucketPxDelta(delta) {
14112
14395
  return "51+";
14113
14396
  }
14114
14397
  function detectRootBodySizeMismatch(html) {
14115
- const rootTag = html.match(ROOT_COMPOSITION_TAG_RE)?.[0];
14398
+ const rootTag = firstCompositionIdTag(html);
14116
14399
  const dataWidth = rootTag && Number(rootTag.match(/\bdata-width=["'](\d+)["']/i)?.[1]);
14117
14400
  const dataHeight = rootTag && Number(rootTag.match(/\bdata-height=["'](\d+)["']/i)?.[1]);
14118
14401
  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);
14402
+ const widthFirst = matchHtmlBodyCssWidthFirst(html);
14403
+ const heightFirst = widthFirst ? void 0 : matchHtmlBodyCssHeightFirst(html);
14121
14404
  const [cssWidth, cssHeight] = widthFirst ? [Number(widthFirst[2]), Number(widthFirst[4])] : heightFirst ? [Number(heightFirst[4]), Number(heightFirst[2])] : [void 0, void 0];
14122
14405
  if (!cssWidth || !cssHeight) return {};
14123
14406
  const delta = Math.max(Math.abs(dataWidth - cssWidth), Math.abs(dataHeight - cssHeight));
@@ -14125,17 +14408,15 @@ function detectRootBodySizeMismatch(html) {
14125
14408
  }
14126
14409
  function scanElementTags(html) {
14127
14410
  let markup = html;
14128
- for (let previous = ""; markup !== previous; ) {
14411
+ for (let previous = "", pass = 0; markup !== previous && pass < MAX_SCRIPT_STYLE_STRIP_PASSES; pass++) {
14129
14412
  previous = markup;
14130
- markup = markup.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
14413
+ markup = removeScriptAndStyleBlocks(markup);
14131
14414
  }
14132
14415
  let total = 0;
14133
14416
  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
- )) {
14417
+ for (const name of countedTagNames(markup)) {
14137
14418
  total++;
14138
- const tag = (m[1] ?? m[2] ?? m[3] ?? "").toLowerCase();
14419
+ const tag = name.toLowerCase();
14139
14420
  counts.set(tag, (counts.get(tag) ?? 0) + 1);
14140
14421
  }
14141
14422
  const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
@@ -14144,12 +14425,16 @@ function scanElementTags(html) {
14144
14425
  );
14145
14426
  const otherCount = ranked.slice(MAX_REPORTED_ELEMENT_TAGS).reduce((sum, [, count]) => sum + count, 0);
14146
14427
  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;
14428
+ const arollVideoCount = countTagsWithAttr(markup, "video", `\\bdata-aroll=["']true["']`);
14429
+ const heygenVideoCount = countTagsWithAttr(
14430
+ markup,
14431
+ "video",
14432
+ `\\bdata-media-source=["']heygen["']`
14433
+ );
14149
14434
  const audioCount = counts.get("audio") ?? 0;
14150
14435
  const imageCount = counts.get("img") ?? 0;
14151
14436
  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;
14437
+ const subCompositionCount = countCompositionSrcMounts(markup);
14153
14438
  let colorGradingCount = 0;
14154
14439
  let hasLut = false;
14155
14440
  for (const m of markup.matchAll(