@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.
package/dist/index.js CHANGED
@@ -29,7 +29,296 @@ import {
29
29
  toFps as toFps2
30
30
  } from "@hyperframes/core";
31
31
  import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
32
- import { HTML_BODY_CSS_HEIGHT_FIRST_RE, HTML_BODY_CSS_WIDTH_FIRST_RE } from "@hyperframes/parsers";
32
+
33
+ // src/services/htmlTagScans.ts
34
+ function forwardFinder(text, pattern) {
35
+ let start = -1;
36
+ let found = null;
37
+ return (from) => {
38
+ if (start < 0 || from < start || found !== null && from > found.index) {
39
+ start = from;
40
+ pattern.lastIndex = from;
41
+ found = pattern.exec(text);
42
+ }
43
+ return found;
44
+ };
45
+ }
46
+ function indexFinder(text, pattern) {
47
+ const find = forwardFinder(text, pattern);
48
+ return (from) => find(from)?.index ?? -1;
49
+ }
50
+ var isLetter = (code) => code >= 65 && code <= 90 || code >= 97 && code <= 122;
51
+ var isDigit = (code) => code >= 48 && code <= 57;
52
+ var isNameChar = (code) => isLetter(code) || isDigit(code) || code === 45;
53
+ var isWordChar = (code) => isLetter(code) || isDigit(code) || code === 95;
54
+ function nameRunEnd(text, from) {
55
+ let end = from;
56
+ while (isNameChar(text.charCodeAt(end))) end++;
57
+ return end;
58
+ }
59
+ function tagNameEnd(text, open2) {
60
+ for (let end = nameRunEnd(text, open2 + 2); end >= open2 + 2; end--) {
61
+ if (isWordChar(text.charCodeAt(end - 1)) !== isWordChar(text.charCodeAt(end))) return end;
62
+ }
63
+ return -1;
64
+ }
65
+ function* inlineScriptBlocks(html) {
66
+ const opener = /<script\b/gi;
67
+ const closer = /<\/script>/gi;
68
+ for (let open2 = opener.exec(html); open2; open2 = opener.exec(html)) {
69
+ const attrsStart = open2.index + open2[0].length;
70
+ const gt = html.indexOf(">", attrsStart);
71
+ if (gt < 0) return;
72
+ closer.lastIndex = gt + 1;
73
+ const close = closer.exec(html);
74
+ if (!close) return;
75
+ yield { attrs: html.slice(attrsStart, gt), body: html.slice(gt + 1, close.index) };
76
+ opener.lastIndex = close.index + close[0].length;
77
+ }
78
+ }
79
+ function removeDelimitedRuns(source, start, end) {
80
+ let out = "";
81
+ let kept = 0;
82
+ for (let open2 = source.indexOf(start); open2 >= 0; open2 = source.indexOf(start, kept)) {
83
+ const close = source.indexOf(end, open2 + start.length);
84
+ if (close < 0) break;
85
+ out += source.slice(kept, open2);
86
+ kept = close + end.length;
87
+ }
88
+ return out + source.slice(kept);
89
+ }
90
+ function gsapDistFile(value) {
91
+ let dist = -1;
92
+ const distPattern = /\/dist\//gi;
93
+ for (let m = distPattern.exec(value); m; m = distPattern.exec(value)) {
94
+ if (m.index + 6 < value.length) dist = m.index;
95
+ distPattern.lastIndex = m.index + 1;
96
+ }
97
+ const gsap = dist < 0 ? null : /gsap/i.exec(value);
98
+ return gsap && gsap.index + 4 <= dist ? value.slice(dist + 6) : void 0;
99
+ }
100
+ function lastGsapMatch(html, finders, tagStart, gt) {
101
+ const { nextSrc, nextQuote, nextGt } = finders;
102
+ let match;
103
+ for (let src = nextSrc(tagStart); src && src.index < gt; src = nextSrc(src.index + 1)) {
104
+ const valueStart = src.index + 5;
105
+ const close = nextQuote(valueStart);
106
+ const end = close < 0 ? -1 : nextGt(close + 1);
107
+ if (end < 0) return { match, laterTagsFail: true };
108
+ const file = gsapDistFile(html.slice(valueStart, close));
109
+ if (file !== void 0) match = { valueStart, close, end, file };
110
+ }
111
+ return { match, laterTagsFail: false };
112
+ }
113
+ function replaceGsapDistScripts(html, replace) {
114
+ const opener = /<script\b/gi;
115
+ const finders = {
116
+ nextSrc: forwardFinder(html, /\bsrc=["']/gi),
117
+ nextQuote: indexFinder(html, /["']/g),
118
+ nextGt: indexFinder(html, />/g)
119
+ };
120
+ let out = "";
121
+ let kept = 0;
122
+ for (let open2 = opener.exec(html); open2; open2 = opener.exec(html)) {
123
+ const gt = finders.nextGt(open2.index);
124
+ if (gt < 0) break;
125
+ const { match, laterTagsFail } = lastGsapMatch(html, finders, open2.index, gt);
126
+ if (match) {
127
+ const { valueStart, close, end, file } = match;
128
+ const full = html.slice(open2.index, end + 1);
129
+ const src = html.slice(valueStart, close);
130
+ out += html.slice(kept, open2.index);
131
+ out += replace(
132
+ full,
133
+ html.slice(open2.index, valueStart),
134
+ src,
135
+ file,
136
+ html.slice(close, end + 1)
137
+ );
138
+ kept = end + 1;
139
+ }
140
+ if (laterTagsFail) break;
141
+ opener.lastIndex = match ? kept : gt;
142
+ }
143
+ return out + html.slice(kept);
144
+ }
145
+ function removeSpanPerTag(html, opener, spanIn) {
146
+ const nextGt = indexFinder(html, />/g);
147
+ let out = "";
148
+ let kept = 0;
149
+ for (let open2 = opener.exec(html); open2; open2 = opener.exec(html)) {
150
+ const attrsStart = open2.index + open2[0].length;
151
+ const gt = nextGt(attrsStart);
152
+ const span = spanIn(attrsStart, gt < 0 ? html.length : gt);
153
+ if (span) {
154
+ out += html.slice(kept, span[0]);
155
+ kept = span[1];
156
+ } else if (gt < 0) break;
157
+ opener.lastIndex = span ? kept : gt;
158
+ }
159
+ return out + html.slice(kept);
160
+ }
161
+ function stripCrossoriginAttr(html, tagName) {
162
+ const nextQuote = indexFinder(html, /["']/g);
163
+ const nextAttr = forwardFinder(html, /\scrossorigin/gi);
164
+ return removeSpanPerTag(html, new RegExp(`<${tagName}\\b`, "gi"), (attrsStart, tagEnd) => {
165
+ let last = -1;
166
+ for (let at = nextAttr(attrsStart); at && at.index < tagEnd; at = nextAttr(at.index + 12)) {
167
+ last = at.index;
168
+ }
169
+ if (last < 0) return void 0;
170
+ const nameEnd = last + 12;
171
+ const quote = html[nameEnd + 1];
172
+ const quoted = html[nameEnd] === "=" && (quote === '"' || quote === "'");
173
+ const close = quoted ? nextQuote(nameEnd + 2) : -1;
174
+ return [last, close < 0 ? nameEnd : close + 1];
175
+ });
176
+ }
177
+ function stripPreloadNone(html) {
178
+ const nextAttr = forwardFinder(html, /(?<!\s)\s+preload\s*=\s*["']none["']/gi);
179
+ return removeSpanPerTag(html, /<(?:video|audio)\b/gi, (attrsStart, tagEnd) => {
180
+ const attr = nextAttr(attrsStart);
181
+ return attr && attr.index < tagEnd ? [attr.index, attr.index + attr[0].length] : void 0;
182
+ });
183
+ }
184
+ var REMOTE_SRC_TAGS = {
185
+ media: { opener: "<(?:video|audio)\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
186
+ source: { opener: "<source\\b", attr: /\bsrc\s*=\s*["'](https?:\/\/)/gi },
187
+ img: { opener: "<img\\b", attr: /(?<![\w-])src\s*=\s*["'](https?:\/\/)/gi }
188
+ };
189
+ function remoteSrcUrls(html, tag) {
190
+ const opener = new RegExp(REMOTE_SRC_TAGS[tag].opener, "gi");
191
+ const nextAttr = forwardFinder(html, new RegExp(REMOTE_SRC_TAGS[tag].attr));
192
+ const nextGt = indexFinder(html, />/g);
193
+ const nextQuote = indexFinder(html, /["']/g);
194
+ const urls = [];
195
+ for (let open2 = opener.exec(html); open2; open2 = opener.exec(html)) {
196
+ const attrsStart = open2.index + open2[0].length;
197
+ const gt = nextGt(attrsStart);
198
+ if (gt < 0) break;
199
+ let resumeAt = gt;
200
+ for (let attr = nextAttr(attrsStart); attr && attr.index < gt; attr = nextAttr(attr.index + 1)) {
201
+ const urlRest = attr.index + attr[0].length;
202
+ const close = nextQuote(urlRest);
203
+ if (close < 0) return urls;
204
+ if (close === urlRest) continue;
205
+ const end = nextGt(close + 1);
206
+ if (end < 0) return urls;
207
+ urls.push(html.slice(urlRest - attr[1].length, close));
208
+ resumeAt = end + 1;
209
+ break;
210
+ }
211
+ opener.lastIndex = resumeAt;
212
+ }
213
+ return urls;
214
+ }
215
+ function removeScriptAndStyleBlocks(markup) {
216
+ const opener = /<(script|style)\b/gi;
217
+ const nextGt = indexFinder(markup, />/g);
218
+ const closers = {
219
+ script: forwardFinder(markup, /<\/script>/gi),
220
+ style: forwardFinder(markup, /<\/style>/gi)
221
+ };
222
+ let out = "";
223
+ let kept = 0;
224
+ for (let open2 = opener.exec(markup); open2; open2 = opener.exec(markup)) {
225
+ const gt = nextGt(open2.index + open2[0].length);
226
+ if (gt < 0) break;
227
+ const close = closers[open2[1].toLowerCase()](gt + 1);
228
+ if (!close) continue;
229
+ out += markup.slice(kept, open2.index);
230
+ kept = close.index + close[0].length;
231
+ opener.lastIndex = kept;
232
+ }
233
+ return out + markup.slice(kept);
234
+ }
235
+ var VOID_TAG = /(img|br|hr|input|source|track|area|base|col|embed|link|meta|param|wbr)\b/iy;
236
+ function countedTagAt(markup, open2, nextGt) {
237
+ const first = markup.charCodeAt(open2 + 1);
238
+ if (first === 47 && isLetter(markup.charCodeAt(open2 + 2))) {
239
+ const end = nameRunEnd(markup, open2 + 3);
240
+ return { name: markup.slice(open2 + 2, end), end };
241
+ }
242
+ if (!isLetter(first)) return void 0;
243
+ VOID_TAG.lastIndex = open2 + 1;
244
+ const known = VOID_TAG.exec(markup);
245
+ if (known) return { name: known[1], end: open2 + 1 + known[0].length };
246
+ const nameEnd = tagNameEnd(markup, open2);
247
+ const gt = nameEnd < 0 ? -1 : nextGt(open2);
248
+ if (gt < 0 || markup.charCodeAt(gt - 1) !== 47) return void 0;
249
+ return { name: markup.slice(open2 + 1, nameEnd), end: gt + 1 };
250
+ }
251
+ function* countedTagNames(markup) {
252
+ const nextGt = indexFinder(markup, />/g);
253
+ for (let open2 = markup.indexOf("<"); open2 >= 0; ) {
254
+ const tag = countedTagAt(markup, open2, nextGt);
255
+ if (tag) yield tag.name;
256
+ open2 = markup.indexOf("<", tag ? tag.end : open2 + 1);
257
+ }
258
+ }
259
+ function countTagsWithAttr(markup, tagName, attr) {
260
+ const opener = new RegExp(`<${tagName}\\b`, "gi");
261
+ const nextGt = indexFinder(markup, />/g);
262
+ const nextAttr = forwardFinder(markup, new RegExp(attr, "gi"));
263
+ let count = 0;
264
+ for (let open2 = opener.exec(markup); open2; open2 = opener.exec(markup)) {
265
+ const attrsStart = open2.index + open2[0].length;
266
+ const gt = nextGt(attrsStart);
267
+ if (gt < 0) break;
268
+ const found = nextAttr(attrsStart);
269
+ const inTag = found !== null && found.index < gt;
270
+ if (inTag) count++;
271
+ opener.lastIndex = inTag ? gt + 1 : gt;
272
+ }
273
+ return count;
274
+ }
275
+ function lastQuotedValueCloses(nextAttr, nextQuote, from, tagEnd) {
276
+ let close = -1;
277
+ let earlierClose = -1;
278
+ for (let attr = nextAttr(from); attr && attr.index < tagEnd; attr = nextAttr(attr.index + 1)) {
279
+ const quote = nextQuote(attr.index + attr[0].length);
280
+ if (quote < 0) return { close, earlierClose, unclosed: true };
281
+ earlierClose = close;
282
+ close = quote;
283
+ }
284
+ return { close, earlierClose, unclosed: false };
285
+ }
286
+ function* tagsWithQuotedAttr(html, name) {
287
+ const opener = /<[a-zA-Z]/g;
288
+ const nextGt = indexFinder(html, />/g);
289
+ const nextQuote = indexFinder(html, /["']/g);
290
+ const nextAttr = forwardFinder(html, new RegExp(`\\b${name}=["']`, "gi"));
291
+ for (let open2 = opener.exec(html); open2; open2 = opener.exec(html)) {
292
+ if (tagNameEnd(html, open2.index) < 0) continue;
293
+ const gt = nextGt(open2.index);
294
+ const tagEnd = gt < 0 ? html.length : gt;
295
+ const { close, earlierClose, unclosed } = lastQuotedValueCloses(
296
+ nextAttr,
297
+ nextQuote,
298
+ open2.index + 2,
299
+ tagEnd
300
+ );
301
+ if (close >= 0) yield { start: open2.index, close, earlierClose };
302
+ if (unclosed || close < 0 && gt < 0) return;
303
+ opener.lastIndex = close >= 0 ? close + 1 : gt;
304
+ }
305
+ }
306
+ function countCompositionSrcMounts(markup) {
307
+ let count = 0;
308
+ for (const _ of tagsWithQuotedAttr(markup, "data-composition-src")) count++;
309
+ return count;
310
+ }
311
+ function firstCompositionIdTag(html) {
312
+ for (const { start, close, earlierClose } of tagsWithQuotedAttr(html, "data-composition-id")) {
313
+ let end = html.indexOf(">", close + 1);
314
+ if (end < 0 && earlierClose >= 0) end = html.indexOf(">", earlierClose + 1);
315
+ return end < 0 ? void 0 : html.slice(start, end + 1);
316
+ }
317
+ return void 0;
318
+ }
319
+
320
+ // src/services/renderOrchestrator.ts
321
+ import { matchHtmlBodyCssHeightFirst, matchHtmlBodyCssWidthFirst } from "@hyperframes/parsers";
33
322
  import {
34
323
  extractMediaMetadata as extractMediaMetadata5,
35
324
  resolveConfig as resolveConfig2,
@@ -91,6 +380,8 @@ import { promisify } from "node:util";
91
380
  import { Readable } from "node:stream";
92
381
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
93
382
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
383
+ import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
384
+ import { PREVIEW_FOR_ANOTHER_SITE_META } from "@hyperframes/core/studio-preview-mark";
94
385
  import { fpsToNumber } from "@hyperframes/core";
95
386
  import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
96
387
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -812,6 +1103,7 @@ var HF_BRIDGE_SCRIPT = `(function() {
812
1103
  if (bridge()) __realClearInterval(iv);
813
1104
  }, 50);
814
1105
  })();`;
1106
+ var OFFER_NO_FRAMING_SITE_AN_EDITING_PORT = `<meta name="${PREVIEW_FOR_ANOTHER_SITE_META}">`;
815
1107
  var RENDER_CAPTURE_MODE_SHIM = "globalThis.__HF_RENDER_CAPTURE_MODE = true;";
816
1108
  function closeFileServerSafely(fileServer, label, log = defaultLogger) {
817
1109
  try {
@@ -899,6 +1191,7 @@ function createFileServer(options) {
899
1191
  html = injectScriptsAtHeadStart(html, preHeadScripts);
900
1192
  }
901
1193
  html = isIndex ? injectScriptsIntoHtml(html, headScripts, bodyScripts, stripEmbeddedRuntime) : html;
1194
+ html = injectTagsAtHeadStart(html, OFFER_NO_FRAMING_SITE_AN_EDITING_PORT);
902
1195
  return c.text(html, 200, { "Content-Type": contentType });
903
1196
  }
904
1197
  if (ext === ".png") {
@@ -3539,50 +3832,71 @@ function holdFirstFrameUntilStreamStarts(windows, firstTick) {
3539
3832
  close: () => windows.close()
3540
3833
  };
3541
3834
  }
3835
+ function fitHdrImageLayoutToFrame(layout, frameWidth, frameHeight) {
3836
+ const scale = Math.min(1, frameWidth / layout.width, frameHeight / layout.height);
3837
+ if (scale === 1) return layout;
3838
+ return {
3839
+ width: Math.max(1, Math.floor(layout.width * scale)),
3840
+ height: Math.max(1, Math.floor(layout.height * scale))
3841
+ };
3842
+ }
3542
3843
  function decodeHdrImageBuffers(args) {
3543
- const { log, hdrImageSrcPaths, prep, hdrDiagnostics } = args;
3844
+ const { log, hdrImageSrcPaths, prep, hdrDiagnostics, width, height } = args;
3845
+ const budgetBytes = resolveHdrExtractionBudgetBytes(process.env[HDR_EXTRACTION_MAX_BYTES_ENV]);
3846
+ const releases = [];
3847
+ const releaseReservation = () => {
3848
+ for (const release of releases.splice(0)) release();
3849
+ };
3544
3850
  const out = /* @__PURE__ */ new Map();
3545
3851
  for (const [imageId, srcPath] of hdrImageSrcPaths) {
3546
3852
  try {
3547
3853
  const decoded = decodePngToRgb48le(readFileSync3(srcPath));
3854
+ const releaseDecoded = reserveHdrExtractionBytes(decoded.data.length, budgetBytes);
3548
3855
  const layout = prep.hdrExtractionDims.get(imageId);
3549
- const fitInfo = prep.hdrImageFitInfo.get(imageId);
3550
- if (layout && (layout.width !== decoded.width || layout.height !== decoded.height)) {
3551
- const fit = normalizeObjectFit(fitInfo?.fit);
3856
+ if (!layout || layout.width === decoded.width && layout.height === decoded.height) {
3857
+ releases.push(releaseDecoded);
3858
+ out.set(imageId, decoded);
3859
+ continue;
3860
+ }
3861
+ const target = fitHdrImageLayoutToFrame(layout, width, height);
3862
+ if (target !== layout) {
3863
+ log.warn("HDR image layout box is larger than the output frame; drawing it smaller", {
3864
+ imageId,
3865
+ layout: `${layout.width}x${layout.height}`,
3866
+ drawn: `${target.width}x${target.height}`
3867
+ });
3868
+ }
3869
+ try {
3870
+ releases.push(reserveHdrExtractionBytes(target.width * target.height * 6, budgetBytes));
3871
+ const fitInfo = prep.hdrImageFitInfo.get(imageId);
3552
3872
  const resampled = resampleRgb48leObjectFit(
3553
3873
  decoded.data,
3554
3874
  decoded.width,
3555
3875
  decoded.height,
3556
- layout.width,
3557
- layout.height,
3558
- fit,
3876
+ target.width,
3877
+ target.height,
3878
+ normalizeObjectFit(fitInfo?.fit),
3559
3879
  fitInfo?.position
3560
3880
  );
3561
- out.set(imageId, {
3562
- data: resampled,
3563
- width: layout.width,
3564
- height: layout.height
3565
- });
3566
- } else {
3567
- out.set(imageId, {
3568
- data: Buffer.from(decoded.data),
3569
- width: decoded.width,
3570
- height: decoded.height
3571
- });
3881
+ out.set(imageId, { data: resampled, width: target.width, height: target.height });
3882
+ } finally {
3883
+ releaseDecoded();
3572
3884
  }
3573
3885
  } catch (err) {
3886
+ releaseReservation();
3574
3887
  hdrDiagnostics.imageDecodeFailures += 1;
3888
+ const message = err instanceof Error ? err.message : String(err);
3575
3889
  log.error("HDR image decode failed; aborting render", {
3576
3890
  imageId,
3577
3891
  srcPath,
3578
- error: err instanceof Error ? err.message : String(err)
3892
+ error: message
3579
3893
  });
3580
3894
  throw new Error(
3581
- `HDR image decode failed for image "${imageId}". Aborting render to avoid shipping missing HDR image layers.`
3895
+ `HDR image decode failed for image "${imageId}": ${message}. Aborting render to avoid shipping missing HDR image layers.`
3582
3896
  );
3583
3897
  }
3584
3898
  }
3585
- return out;
3899
+ return { buffers: out, releaseReservation };
3586
3900
  }
3587
3901
 
3588
3902
  // src/services/render/stages/captureHdrFrameShared.ts
@@ -6856,14 +7170,13 @@ function resolveLocalImageSourcePath(src, options) {
6856
7170
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
6857
7171
  if (mapped && existsSync9(mapped)) return mapped;
6858
7172
  if (isHttpUrl(trimmed)) return null;
6859
- const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
6860
7173
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
6861
7174
  const candidates = [
6862
- ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
7175
+ isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
6863
7176
  resolve5(options.downloadDir, normalizedBase)
6864
7177
  ];
6865
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
6866
- return candidates.find((candidate) => existsSync9(candidate) && allowed(candidate)) ?? null;
7178
+ const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && (!escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
7179
+ return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
6867
7180
  }
6868
7181
  function isUsableFile(path) {
6869
7182
  try {
@@ -7725,20 +8038,13 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
7725
8038
  throw new EmptyCompositionError(problems);
7726
8039
  }
7727
8040
  }
7728
- var INLINE_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
7729
8041
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
7730
8042
  var COMPILER_MOUNT_BLOCK_END = "/* __HF_COMPILER_MOUNT_END__ */";
7731
8043
  function stripJsComments(source) {
7732
- return source.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
8044
+ return removeDelimitedRuns(source.replace(/\/\/.*$/gm, ""), "/*", "*/");
7733
8045
  }
7734
8046
  function stripCompilerMountBootstrap(source) {
7735
- return source.replace(
7736
- new RegExp(
7737
- `${COMPILER_MOUNT_BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${COMPILER_MOUNT_BLOCK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
7738
- "g"
7739
- ),
7740
- ""
7741
- );
8047
+ return removeDelimitedRuns(source, COMPILER_MOUNT_BLOCK_START, COMPILER_MOUNT_BLOCK_END);
7742
8048
  }
7743
8049
  function runtimeRoot(document2) {
7744
8050
  return document2.querySelector('[data-composition-id][data-root="true"]') ?? document2.querySelector("[data-composition-id]");
@@ -7763,12 +8069,9 @@ function detectRenderModeHints(html, pageMotionBlur) {
7763
8069
  message: "Detected <iframe> in the composition DOM. Nested iframe animation is routed through screenshot capture mode for compatibility."
7764
8070
  });
7765
8071
  }
7766
- let scriptMatch;
7767
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7768
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7769
- const attrs = scriptMatch[1] || "";
8072
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7770
8073
  if (/\bsrc\s*=/i.test(attrs)) continue;
7771
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8074
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7772
8075
  if (!/requestAnimationFrame\s*\(/.test(content)) continue;
7773
8076
  reasons.push({
7774
8077
  code: "requestAnimationFrame",
@@ -7820,12 +8123,9 @@ function detectAncestorBackgroundImage(html) {
7820
8123
  }
7821
8124
  var SHADER_TRANSITION_USAGE_PATTERN = /\b(?:(?:window|globalThis)\s*\.\s*)?HyperShader\s*\.\s*init\s*\(|\b__hf\s*\.\s*transitions\s*=/;
7822
8125
  function detectShaderTransitionUsage(html) {
7823
- let scriptMatch;
7824
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7825
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7826
- const attrs = scriptMatch[1] || "";
8126
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7827
8127
  if (/\bsrc\s*=/i.test(attrs)) continue;
7828
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8128
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7829
8129
  if (SHADER_TRANSITION_USAGE_PATTERN.test(content)) return true;
7830
8130
  }
7831
8131
  return false;
@@ -7981,9 +8281,9 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7981
8281
  if (clampList.length > 0) {
7982
8282
  compiledHtml = clampDurations(compiledHtml, clampList);
7983
8283
  }
7984
- compiledHtml = compiledHtml.replace(/(<video\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
7985
- compiledHtml = compiledHtml.replace(/(<img\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
7986
- compiledHtml = compiledHtml.replace(/(<audio\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8284
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "video");
8285
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "img");
8286
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
7987
8287
  return { html: compiledHtml, unresolvedCompositions };
7988
8288
  }
7989
8289
  async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
@@ -8417,8 +8717,9 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8417
8717
  if (isPathInside(absPath, absProjectDir)) {
8418
8718
  return null;
8419
8719
  }
8420
- if (!existsSync11(absPath)) return null;
8421
- const refusal = outsideAssetRefusal(absProjectDir, absPath);
8720
+ const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
8721
+ if (!onShare && !existsSync11(absPath)) return null;
8722
+ const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath);
8422
8723
  if (refusal) {
8423
8724
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8424
8725
  leftOut.add(trimmed);
@@ -8468,9 +8769,6 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8468
8769
  };
8469
8770
  }
8470
8771
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
8471
- var REMOTE_MEDIA_TAG_RE = /<(?:video|audio)\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8472
- var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8473
- var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8474
8772
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
8475
8773
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
8476
8774
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
@@ -8509,14 +8807,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
8509
8807
  return { html: result, remoteMediaAssets };
8510
8808
  }
8511
8809
  async function localizeRemoteMediaSources(html, downloadDir) {
8512
- const urlSet = /* @__PURE__ */ new Set();
8513
- for (const tagRe of [REMOTE_MEDIA_TAG_RE, REMOTE_SOURCE_TAG_RE]) {
8514
- const re = new RegExp(tagRe.source, tagRe.flags);
8515
- let m;
8516
- while ((m = re.exec(html)) !== null) {
8517
- if (m[1]) urlSet.add(m[1]);
8518
- }
8519
- }
8810
+ const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
8520
8811
  const localized = await downloadAndRewriteUrls(
8521
8812
  urlSet,
8522
8813
  html,
@@ -8539,12 +8830,7 @@ function dropBindingOnLocalizedMedia(html) {
8539
8830
  return changed ? document2.toString() : html;
8540
8831
  }
8541
8832
  async function localizeRemoteImageSources(html, downloadDir) {
8542
- const urlSet = /* @__PURE__ */ new Set();
8543
- const re = new RegExp(REMOTE_IMG_TAG_RE.source, REMOTE_IMG_TAG_RE.flags);
8544
- let m;
8545
- while ((m = re.exec(html)) !== null) {
8546
- if (m[1]) urlSet.add(m[1]);
8547
- }
8833
+ const urlSet = new Set(remoteSrcUrls(html, "img"));
8548
8834
  return downloadAndRewriteUrls(
8549
8835
  urlSet,
8550
8836
  html,
@@ -8808,16 +9094,13 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
8808
9094
  const file = resolve7(projectDir, path);
8809
9095
  return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
8810
9096
  };
8811
- return html.replace(
8812
- /(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
8813
- (full, prefix, src, file, suffix) => {
8814
- if (/^https?:\/\//i.test(src)) return full;
8815
- if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
8816
- gsapDist ??= renderGsapDist();
8817
- defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
8818
- return `${prefix}${gsapDist}${file}${suffix}`;
8819
- }
8820
- );
9097
+ return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
9098
+ if (/^https?:\/\//i.test(src)) return full;
9099
+ if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
9100
+ gsapDist ??= renderGsapDist();
9101
+ defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
9102
+ return `${prefix}${gsapDist}${file}${suffix}`;
9103
+ });
8821
9104
  }
8822
9105
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
8823
9106
  if (!isPathInside(htmlPath, projectDir)) return html;
@@ -8904,10 +9187,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8904
9187
  options.variables ?? {},
8905
9188
  assetRoot
8906
9189
  );
8907
- const sanitizedHtml = inlinedHtml.replace(
8908
- /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
8909
- "$1"
8910
- );
9190
+ const sanitizedHtml = stripPreloadNone(inlinedHtml);
8911
9191
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
8912
9192
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
8913
9193
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
@@ -12812,6 +13092,7 @@ async function runCaptureHdrStage(input) {
12812
13092
  let hdrEncoderClosed = false;
12813
13093
  let domSessionClosed = false;
12814
13094
  let releaseHdrExtractionReservation = null;
13095
+ let releaseHdrImageReservation = null;
12815
13096
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
12816
13097
  try {
12817
13098
  await initializeSession7(domSession);
@@ -12893,12 +13174,16 @@ async function runCaptureHdrStage(input) {
12893
13174
  });
12894
13175
  releaseHdrExtractionReservation = extracted.releaseReservation;
12895
13176
  for (const [id, source] of extracted.sources) hdrVideoFrameSources.set(id, source);
12896
- const hdrImageBuffers = decodeHdrImageBuffers({
13177
+ const decodedImages = decodeHdrImageBuffers({
12897
13178
  log,
12898
13179
  hdrImageSrcPaths,
12899
13180
  prep,
12900
- hdrDiagnostics
13181
+ hdrDiagnostics,
13182
+ width,
13183
+ height
12901
13184
  });
13185
+ releaseHdrImageReservation = decodedImages.releaseReservation;
13186
+ const hdrImageBuffers = decodedImages.buffers;
12902
13187
  assertNotAborted();
12903
13188
  try {
12904
13189
  const cleanedUpVideos = /* @__PURE__ */ new Set();
@@ -13051,6 +13336,8 @@ async function runCaptureHdrStage(input) {
13051
13336
  hdrVideoFrameSources.clear();
13052
13337
  releaseHdrExtractionReservation?.();
13053
13338
  releaseHdrExtractionReservation = null;
13339
+ releaseHdrImageReservation?.();
13340
+ releaseHdrImageReservation = null;
13054
13341
  }
13055
13342
  return {
13056
13343
  lastBrowserConsole,
@@ -14124,8 +14411,8 @@ function envInt(name, fallback) {
14124
14411
  return Number.isInteger(parsed) ? parsed : fallback;
14125
14412
  }
14126
14413
  var MAX_REPORTED_ELEMENT_TAGS = 50;
14414
+ var MAX_SCRIPT_STYLE_STRIP_PASSES = 8;
14127
14415
  var VFX_CAPTURE_RANK = { none: 0, self: 1, backdrop: 2 };
14128
- var ROOT_COMPOSITION_TAG_RE = /<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-id=["'][^"']*["'][^>]*>/i;
14129
14416
  function bucketPxDelta(delta) {
14130
14417
  if (delta === 0) return "0";
14131
14418
  if (delta <= 10) return "1-10";
@@ -14133,12 +14420,12 @@ function bucketPxDelta(delta) {
14133
14420
  return "51+";
14134
14421
  }
14135
14422
  function detectRootBodySizeMismatch(html) {
14136
- const rootTag = html.match(ROOT_COMPOSITION_TAG_RE)?.[0];
14423
+ const rootTag = firstCompositionIdTag(html);
14137
14424
  const dataWidth = rootTag && Number(rootTag.match(/\bdata-width=["'](\d+)["']/i)?.[1]);
14138
14425
  const dataHeight = rootTag && Number(rootTag.match(/\bdata-height=["'](\d+)["']/i)?.[1]);
14139
14426
  if (!dataWidth || !dataHeight) return {};
14140
- const widthFirst = html.match(HTML_BODY_CSS_WIDTH_FIRST_RE);
14141
- const heightFirst = widthFirst ? void 0 : html.match(HTML_BODY_CSS_HEIGHT_FIRST_RE);
14427
+ const widthFirst = matchHtmlBodyCssWidthFirst(html);
14428
+ const heightFirst = widthFirst ? void 0 : matchHtmlBodyCssHeightFirst(html);
14142
14429
  const [cssWidth, cssHeight] = widthFirst ? [Number(widthFirst[2]), Number(widthFirst[4])] : heightFirst ? [Number(heightFirst[4]), Number(heightFirst[2])] : [void 0, void 0];
14143
14430
  if (!cssWidth || !cssHeight) return {};
14144
14431
  const delta = Math.max(Math.abs(dataWidth - cssWidth), Math.abs(dataHeight - cssHeight));
@@ -14146,17 +14433,15 @@ function detectRootBodySizeMismatch(html) {
14146
14433
  }
14147
14434
  function scanElementTags(html) {
14148
14435
  let markup = html;
14149
- for (let previous = ""; markup !== previous; ) {
14436
+ for (let previous = "", pass = 0; markup !== previous && pass < MAX_SCRIPT_STYLE_STRIP_PASSES; pass++) {
14150
14437
  previous = markup;
14151
- markup = markup.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
14438
+ markup = removeScriptAndStyleBlocks(markup);
14152
14439
  }
14153
14440
  let total = 0;
14154
14441
  const counts = /* @__PURE__ */ new Map();
14155
- for (const m of markup.matchAll(
14156
- /<\/([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
14157
- )) {
14442
+ for (const name of countedTagNames(markup)) {
14158
14443
  total++;
14159
- const tag = (m[1] ?? m[2] ?? m[3] ?? "").toLowerCase();
14444
+ const tag = name.toLowerCase();
14160
14445
  counts.set(tag, (counts.get(tag) ?? 0) + 1);
14161
14446
  }
14162
14447
  const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
@@ -14165,12 +14450,16 @@ function scanElementTags(html) {
14165
14450
  );
14166
14451
  const otherCount = ranked.slice(MAX_REPORTED_ELEMENT_TAGS).reduce((sum2, [, count]) => sum2 + count, 0);
14167
14452
  if (otherCount > 0) byTag.other = (byTag.other ?? 0) + otherCount;
14168
- const arollVideoCount = markup.match(/<video\b[^>]*\bdata-aroll=["']true["'][^>]*>/gi)?.length ?? 0;
14169
- const heygenVideoCount = markup.match(/<video\b[^>]*\bdata-media-source=["']heygen["'][^>]*>/gi)?.length ?? 0;
14453
+ const arollVideoCount = countTagsWithAttr(markup, "video", `\\bdata-aroll=["']true["']`);
14454
+ const heygenVideoCount = countTagsWithAttr(
14455
+ markup,
14456
+ "video",
14457
+ `\\bdata-media-source=["']heygen["']`
14458
+ );
14170
14459
  const audioCount = counts.get("audio") ?? 0;
14171
14460
  const imageCount = counts.get("img") ?? 0;
14172
14461
  const audioGroupCount = counts.get(HF_AUDIO_GROUP_TAG) ?? 0;
14173
- const subCompositionCount = markup.match(/<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-src=["'][^"']*["']/gi)?.length ?? 0;
14462
+ const subCompositionCount = countCompositionSrcMounts(markup);
14174
14463
  let colorGradingCount = 0;
14175
14464
  let hasLut = false;
14176
14465
  for (const m of markup.matchAll(
@@ -23176,6 +23465,7 @@ async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
23176
23465
  }
23177
23466
 
23178
23467
  // src/services/distributed/projectHash.ts
23468
+ import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
23179
23469
  var READ_CHUNK_BYTES = 256 * 1024;
23180
23470
 
23181
23471
  // src/services/distributed/audioSidecar.ts