@hyperframes/producer 0.9.54 → 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,
@@ -110,6 +399,8 @@ import { promisify } from "node:util";
110
399
  import { Readable } from "node:stream";
111
400
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
112
401
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
402
+ import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
403
+ import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
113
404
  import { fpsToNumber } from "@hyperframes/core";
114
405
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
115
406
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -831,6 +1122,7 @@ var HF_BRIDGE_SCRIPT = `(function() {
831
1122
  if (bridge()) __realClearInterval(iv);
832
1123
  }, 50);
833
1124
  })();`;
1125
+ var OFFER_NO_FRAMING_SITE_AN_EDITING_PORT = `<meta name="${PREVIEW_FOR_ANOTHER_SITE_META}">`;
834
1126
  var RENDER_CAPTURE_MODE_SHIM = "globalThis.__HF_RENDER_CAPTURE_MODE = true;";
835
1127
  function closeFileServerSafely(fileServer, label, log = defaultLogger) {
836
1128
  try {
@@ -918,6 +1210,7 @@ function createFileServer(options) {
918
1210
  html = injectScriptsAtHeadStart(html, preHeadScripts);
919
1211
  }
920
1212
  html = isIndex ? injectScriptsIntoHtml(html, headScripts, bodyScripts, stripEmbeddedRuntime) : html;
1213
+ html = injectTagsAtHeadStart(html, OFFER_NO_FRAMING_SITE_AN_EDITING_PORT);
921
1214
  return c.text(html, 200, { "Content-Type": contentType });
922
1215
  }
923
1216
  if (ext === ".png") {
@@ -3554,50 +3847,71 @@ function holdFirstFrameUntilStreamStarts(windows, firstTick) {
3554
3847
  close: () => windows.close()
3555
3848
  };
3556
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
+ }
3557
3858
  function decodeHdrImageBuffers(args) {
3558
- 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
+ };
3559
3865
  const out = /* @__PURE__ */ new Map();
3560
3866
  for (const [imageId, srcPath] of hdrImageSrcPaths) {
3561
3867
  try {
3562
3868
  const decoded = decodePngToRgb48le(readFileSync3(srcPath));
3869
+ const releaseDecoded = reserveHdrExtractionBytes(decoded.data.length, budgetBytes);
3563
3870
  const layout = prep.hdrExtractionDims.get(imageId);
3564
- const fitInfo = prep.hdrImageFitInfo.get(imageId);
3565
- if (layout && (layout.width !== decoded.width || layout.height !== decoded.height)) {
3566
- 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);
3567
3887
  const resampled = resampleRgb48leObjectFit(
3568
3888
  decoded.data,
3569
3889
  decoded.width,
3570
3890
  decoded.height,
3571
- layout.width,
3572
- layout.height,
3573
- fit,
3891
+ target.width,
3892
+ target.height,
3893
+ normalizeObjectFit(fitInfo?.fit),
3574
3894
  fitInfo?.position
3575
3895
  );
3576
- out.set(imageId, {
3577
- data: resampled,
3578
- width: layout.width,
3579
- height: layout.height
3580
- });
3581
- } else {
3582
- out.set(imageId, {
3583
- data: Buffer.from(decoded.data),
3584
- width: decoded.width,
3585
- height: decoded.height
3586
- });
3896
+ out.set(imageId, { data: resampled, width: target.width, height: target.height });
3897
+ } finally {
3898
+ releaseDecoded();
3587
3899
  }
3588
3900
  } catch (err) {
3901
+ releaseReservation();
3589
3902
  hdrDiagnostics.imageDecodeFailures += 1;
3903
+ const message = err instanceof Error ? err.message : String(err);
3590
3904
  log.error("HDR image decode failed; aborting render", {
3591
3905
  imageId,
3592
3906
  srcPath,
3593
- error: err instanceof Error ? err.message : String(err)
3907
+ error: message
3594
3908
  });
3595
3909
  throw new Error(
3596
- `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.`
3597
3911
  );
3598
3912
  }
3599
3913
  }
3600
- return out;
3914
+ return { buffers: out, releaseReservation };
3601
3915
  }
3602
3916
 
3603
3917
  // src/services/render/stages/captureHdrFrameShared.ts
@@ -6871,14 +7185,13 @@ function resolveLocalImageSourcePath(src, options) {
6871
7185
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
6872
7186
  if (mapped && existsSync9(mapped)) return mapped;
6873
7187
  if (isHttpUrl(trimmed)) return null;
6874
- const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
6875
7188
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
6876
7189
  const candidates = [
6877
- ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
7190
+ isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
6878
7191
  resolve5(options.downloadDir, normalizedBase)
6879
7192
  ];
6880
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
6881
- 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;
6882
7195
  }
6883
7196
  function isUsableFile(path) {
6884
7197
  try {
@@ -7740,20 +8053,13 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
7740
8053
  throw new EmptyCompositionError(problems);
7741
8054
  }
7742
8055
  }
7743
- var INLINE_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
7744
8056
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
7745
8057
  var COMPILER_MOUNT_BLOCK_END = "/* __HF_COMPILER_MOUNT_END__ */";
7746
8058
  function stripJsComments(source) {
7747
- return source.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
8059
+ return removeDelimitedRuns(source.replace(/\/\/.*$/gm, ""), "/*", "*/");
7748
8060
  }
7749
8061
  function stripCompilerMountBootstrap(source) {
7750
- return source.replace(
7751
- new RegExp(
7752
- `${COMPILER_MOUNT_BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${COMPILER_MOUNT_BLOCK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
7753
- "g"
7754
- ),
7755
- ""
7756
- );
8062
+ return removeDelimitedRuns(source, COMPILER_MOUNT_BLOCK_START, COMPILER_MOUNT_BLOCK_END);
7757
8063
  }
7758
8064
  function runtimeRoot(document2) {
7759
8065
  return document2.querySelector('[data-composition-id][data-root="true"]') ?? document2.querySelector("[data-composition-id]");
@@ -7778,12 +8084,9 @@ function detectRenderModeHints(html, pageMotionBlur) {
7778
8084
  message: "Detected <iframe> in the composition DOM. Nested iframe animation is routed through screenshot capture mode for compatibility."
7779
8085
  });
7780
8086
  }
7781
- let scriptMatch;
7782
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7783
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7784
- const attrs = scriptMatch[1] || "";
8087
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7785
8088
  if (/\bsrc\s*=/i.test(attrs)) continue;
7786
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8089
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7787
8090
  if (!/requestAnimationFrame\s*\(/.test(content)) continue;
7788
8091
  reasons.push({
7789
8092
  code: "requestAnimationFrame",
@@ -7835,12 +8138,9 @@ function detectAncestorBackgroundImage(html) {
7835
8138
  }
7836
8139
  var SHADER_TRANSITION_USAGE_PATTERN = /\b(?:(?:window|globalThis)\s*\.\s*)?HyperShader\s*\.\s*init\s*\(|\b__hf\s*\.\s*transitions\s*=/;
7837
8140
  function detectShaderTransitionUsage(html) {
7838
- let scriptMatch;
7839
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7840
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7841
- const attrs = scriptMatch[1] || "";
8141
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7842
8142
  if (/\bsrc\s*=/i.test(attrs)) continue;
7843
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8143
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7844
8144
  if (SHADER_TRANSITION_USAGE_PATTERN.test(content)) return true;
7845
8145
  }
7846
8146
  return false;
@@ -7996,9 +8296,9 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7996
8296
  if (clampList.length > 0) {
7997
8297
  compiledHtml = clampDurations(compiledHtml, clampList);
7998
8298
  }
7999
- compiledHtml = compiledHtml.replace(/(<video\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8000
- compiledHtml = compiledHtml.replace(/(<img\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8001
- compiledHtml = compiledHtml.replace(/(<audio\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8299
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "video");
8300
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "img");
8301
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
8002
8302
  return { html: compiledHtml, unresolvedCompositions };
8003
8303
  }
8004
8304
  async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
@@ -8432,8 +8732,9 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8432
8732
  if (isPathInside(absPath, absProjectDir)) {
8433
8733
  return null;
8434
8734
  }
8435
- if (!existsSync11(absPath)) return null;
8436
- 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);
8437
8738
  if (refusal) {
8438
8739
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8439
8740
  leftOut.add(trimmed);
@@ -8483,9 +8784,6 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8483
8784
  };
8484
8785
  }
8485
8786
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
8486
- var REMOTE_MEDIA_TAG_RE = /<(?:video|audio)\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8487
- var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8488
- var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8489
8787
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
8490
8788
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
8491
8789
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
@@ -8524,14 +8822,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
8524
8822
  return { html: result, remoteMediaAssets };
8525
8823
  }
8526
8824
  async function localizeRemoteMediaSources(html, downloadDir) {
8527
- const urlSet = /* @__PURE__ */ new Set();
8528
- for (const tagRe of [REMOTE_MEDIA_TAG_RE, REMOTE_SOURCE_TAG_RE]) {
8529
- const re = new RegExp(tagRe.source, tagRe.flags);
8530
- let m;
8531
- while ((m = re.exec(html)) !== null) {
8532
- if (m[1]) urlSet.add(m[1]);
8533
- }
8534
- }
8825
+ const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
8535
8826
  const localized = await downloadAndRewriteUrls(
8536
8827
  urlSet,
8537
8828
  html,
@@ -8554,12 +8845,7 @@ function dropBindingOnLocalizedMedia(html) {
8554
8845
  return changed ? document2.toString() : html;
8555
8846
  }
8556
8847
  async function localizeRemoteImageSources(html, downloadDir) {
8557
- const urlSet = /* @__PURE__ */ new Set();
8558
- const re = new RegExp(REMOTE_IMG_TAG_RE.source, REMOTE_IMG_TAG_RE.flags);
8559
- let m;
8560
- while ((m = re.exec(html)) !== null) {
8561
- if (m[1]) urlSet.add(m[1]);
8562
- }
8848
+ const urlSet = new Set(remoteSrcUrls(html, "img"));
8563
8849
  return downloadAndRewriteUrls(
8564
8850
  urlSet,
8565
8851
  html,
@@ -8820,16 +9106,13 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
8820
9106
  const file = resolve7(projectDir, path);
8821
9107
  return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
8822
9108
  };
8823
- return html.replace(
8824
- /(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
8825
- (full, prefix, src, file, suffix) => {
8826
- if (/^https?:\/\//i.test(src)) return full;
8827
- if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
8828
- gsapDist ??= renderGsapDist();
8829
- defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
8830
- return `${prefix}${gsapDist}${file}${suffix}`;
8831
- }
8832
- );
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
+ });
8833
9116
  }
8834
9117
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
8835
9118
  if (!isPathInside(htmlPath, projectDir)) return html;
@@ -8916,10 +9199,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8916
9199
  options.variables ?? {},
8917
9200
  assetRoot
8918
9201
  );
8919
- const sanitizedHtml = inlinedHtml.replace(
8920
- /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
8921
- "$1"
8922
- );
9202
+ const sanitizedHtml = stripPreloadNone(inlinedHtml);
8923
9203
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
8924
9204
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
8925
9205
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
@@ -12787,6 +13067,7 @@ async function runCaptureHdrStage(input) {
12787
13067
  let hdrEncoderClosed = false;
12788
13068
  let domSessionClosed = false;
12789
13069
  let releaseHdrExtractionReservation = null;
13070
+ let releaseHdrImageReservation = null;
12790
13071
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
12791
13072
  try {
12792
13073
  await initializeSession7(domSession);
@@ -12868,12 +13149,16 @@ async function runCaptureHdrStage(input) {
12868
13149
  });
12869
13150
  releaseHdrExtractionReservation = extracted.releaseReservation;
12870
13151
  for (const [id, source] of extracted.sources) hdrVideoFrameSources.set(id, source);
12871
- const hdrImageBuffers = decodeHdrImageBuffers({
13152
+ const decodedImages = decodeHdrImageBuffers({
12872
13153
  log,
12873
13154
  hdrImageSrcPaths,
12874
13155
  prep,
12875
- hdrDiagnostics
13156
+ hdrDiagnostics,
13157
+ width,
13158
+ height
12876
13159
  });
13160
+ releaseHdrImageReservation = decodedImages.releaseReservation;
13161
+ const hdrImageBuffers = decodedImages.buffers;
12877
13162
  assertNotAborted();
12878
13163
  try {
12879
13164
  const cleanedUpVideos = /* @__PURE__ */ new Set();
@@ -13026,6 +13311,8 @@ async function runCaptureHdrStage(input) {
13026
13311
  hdrVideoFrameSources.clear();
13027
13312
  releaseHdrExtractionReservation?.();
13028
13313
  releaseHdrExtractionReservation = null;
13314
+ releaseHdrImageReservation?.();
13315
+ releaseHdrImageReservation = null;
13029
13316
  }
13030
13317
  return {
13031
13318
  lastBrowserConsole,
@@ -14099,8 +14386,8 @@ function envInt(name, fallback) {
14099
14386
  return Number.isInteger(parsed) ? parsed : fallback;
14100
14387
  }
14101
14388
  var MAX_REPORTED_ELEMENT_TAGS = 50;
14389
+ var MAX_SCRIPT_STYLE_STRIP_PASSES = 8;
14102
14390
  var VFX_CAPTURE_RANK = { none: 0, self: 1, backdrop: 2 };
14103
- var ROOT_COMPOSITION_TAG_RE = /<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-id=["'][^"']*["'][^>]*>/i;
14104
14391
  function bucketPxDelta(delta) {
14105
14392
  if (delta === 0) return "0";
14106
14393
  if (delta <= 10) return "1-10";
@@ -14108,12 +14395,12 @@ function bucketPxDelta(delta) {
14108
14395
  return "51+";
14109
14396
  }
14110
14397
  function detectRootBodySizeMismatch(html) {
14111
- const rootTag = html.match(ROOT_COMPOSITION_TAG_RE)?.[0];
14398
+ const rootTag = firstCompositionIdTag(html);
14112
14399
  const dataWidth = rootTag && Number(rootTag.match(/\bdata-width=["'](\d+)["']/i)?.[1]);
14113
14400
  const dataHeight = rootTag && Number(rootTag.match(/\bdata-height=["'](\d+)["']/i)?.[1]);
14114
14401
  if (!dataWidth || !dataHeight) return {};
14115
- const widthFirst = html.match(HTML_BODY_CSS_WIDTH_FIRST_RE);
14116
- 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);
14117
14404
  const [cssWidth, cssHeight] = widthFirst ? [Number(widthFirst[2]), Number(widthFirst[4])] : heightFirst ? [Number(heightFirst[4]), Number(heightFirst[2])] : [void 0, void 0];
14118
14405
  if (!cssWidth || !cssHeight) return {};
14119
14406
  const delta = Math.max(Math.abs(dataWidth - cssWidth), Math.abs(dataHeight - cssHeight));
@@ -14121,17 +14408,15 @@ function detectRootBodySizeMismatch(html) {
14121
14408
  }
14122
14409
  function scanElementTags(html) {
14123
14410
  let markup = html;
14124
- for (let previous = ""; markup !== previous; ) {
14411
+ for (let previous = "", pass = 0; markup !== previous && pass < MAX_SCRIPT_STYLE_STRIP_PASSES; pass++) {
14125
14412
  previous = markup;
14126
- markup = markup.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
14413
+ markup = removeScriptAndStyleBlocks(markup);
14127
14414
  }
14128
14415
  let total = 0;
14129
14416
  const counts = /* @__PURE__ */ new Map();
14130
- for (const m of markup.matchAll(
14131
- /<\/([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
14132
- )) {
14417
+ for (const name of countedTagNames(markup)) {
14133
14418
  total++;
14134
- const tag = (m[1] ?? m[2] ?? m[3] ?? "").toLowerCase();
14419
+ const tag = name.toLowerCase();
14135
14420
  counts.set(tag, (counts.get(tag) ?? 0) + 1);
14136
14421
  }
14137
14422
  const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
@@ -14140,12 +14425,16 @@ function scanElementTags(html) {
14140
14425
  );
14141
14426
  const otherCount = ranked.slice(MAX_REPORTED_ELEMENT_TAGS).reduce((sum, [, count]) => sum + count, 0);
14142
14427
  if (otherCount > 0) byTag.other = (byTag.other ?? 0) + otherCount;
14143
- const arollVideoCount = markup.match(/<video\b[^>]*\bdata-aroll=["']true["'][^>]*>/gi)?.length ?? 0;
14144
- 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
+ );
14145
14434
  const audioCount = counts.get("audio") ?? 0;
14146
14435
  const imageCount = counts.get("img") ?? 0;
14147
14436
  const audioGroupCount = counts.get(HF_AUDIO_GROUP_TAG) ?? 0;
14148
- const subCompositionCount = markup.match(/<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-src=["'][^"']*["']/gi)?.length ?? 0;
14437
+ const subCompositionCount = countCompositionSrcMounts(markup);
14149
14438
  let colorGradingCount = 0;
14150
14439
  let hasLut = false;
14151
14440
  for (const m of markup.matchAll(