@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.
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,
@@ -3543,50 +3832,71 @@ function holdFirstFrameUntilStreamStarts(windows, firstTick) {
3543
3832
  close: () => windows.close()
3544
3833
  };
3545
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
+ }
3546
3843
  function decodeHdrImageBuffers(args) {
3547
- 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
+ };
3548
3850
  const out = /* @__PURE__ */ new Map();
3549
3851
  for (const [imageId, srcPath] of hdrImageSrcPaths) {
3550
3852
  try {
3551
3853
  const decoded = decodePngToRgb48le(readFileSync3(srcPath));
3854
+ const releaseDecoded = reserveHdrExtractionBytes(decoded.data.length, budgetBytes);
3552
3855
  const layout = prep.hdrExtractionDims.get(imageId);
3553
- const fitInfo = prep.hdrImageFitInfo.get(imageId);
3554
- if (layout && (layout.width !== decoded.width || layout.height !== decoded.height)) {
3555
- 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);
3556
3872
  const resampled = resampleRgb48leObjectFit(
3557
3873
  decoded.data,
3558
3874
  decoded.width,
3559
3875
  decoded.height,
3560
- layout.width,
3561
- layout.height,
3562
- fit,
3876
+ target.width,
3877
+ target.height,
3878
+ normalizeObjectFit(fitInfo?.fit),
3563
3879
  fitInfo?.position
3564
3880
  );
3565
- out.set(imageId, {
3566
- data: resampled,
3567
- width: layout.width,
3568
- height: layout.height
3569
- });
3570
- } else {
3571
- out.set(imageId, {
3572
- data: Buffer.from(decoded.data),
3573
- width: decoded.width,
3574
- height: decoded.height
3575
- });
3881
+ out.set(imageId, { data: resampled, width: target.width, height: target.height });
3882
+ } finally {
3883
+ releaseDecoded();
3576
3884
  }
3577
3885
  } catch (err) {
3886
+ releaseReservation();
3578
3887
  hdrDiagnostics.imageDecodeFailures += 1;
3888
+ const message = err instanceof Error ? err.message : String(err);
3579
3889
  log.error("HDR image decode failed; aborting render", {
3580
3890
  imageId,
3581
3891
  srcPath,
3582
- error: err instanceof Error ? err.message : String(err)
3892
+ error: message
3583
3893
  });
3584
3894
  throw new Error(
3585
- `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.`
3586
3896
  );
3587
3897
  }
3588
3898
  }
3589
- return out;
3899
+ return { buffers: out, releaseReservation };
3590
3900
  }
3591
3901
 
3592
3902
  // src/services/render/stages/captureHdrFrameShared.ts
@@ -6860,14 +7170,13 @@ function resolveLocalImageSourcePath(src, options) {
6860
7170
  const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
6861
7171
  if (mapped && existsSync9(mapped)) return mapped;
6862
7172
  if (isHttpUrl(trimmed)) return null;
6863
- const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
6864
7173
  const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
6865
7174
  const candidates = [
6866
- ...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
7175
+ isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
6867
7176
  resolve5(options.downloadDir, normalizedBase)
6868
7177
  ];
6869
- const allowed = (candidate) => !escapesAssetRoot(candidate, options.assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir);
6870
- 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;
6871
7180
  }
6872
7181
  function isUsableFile(path) {
6873
7182
  try {
@@ -7729,20 +8038,13 @@ function assertSubCompositionsUsable(html, projectDir, assetRoot, visited = /* @
7729
8038
  throw new EmptyCompositionError(problems);
7730
8039
  }
7731
8040
  }
7732
- var INLINE_SCRIPT_PATTERN = /<script\b([^>]*)>([\s\S]*?)<\/script>/gi;
7733
8041
  var COMPILER_MOUNT_BLOCK_START = "/* __HF_COMPILER_MOUNT_START__ */";
7734
8042
  var COMPILER_MOUNT_BLOCK_END = "/* __HF_COMPILER_MOUNT_END__ */";
7735
8043
  function stripJsComments(source) {
7736
- return source.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
8044
+ return removeDelimitedRuns(source.replace(/\/\/.*$/gm, ""), "/*", "*/");
7737
8045
  }
7738
8046
  function stripCompilerMountBootstrap(source) {
7739
- return source.replace(
7740
- new RegExp(
7741
- `${COMPILER_MOUNT_BLOCK_START.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\s\\S]*?${COMPILER_MOUNT_BLOCK_END.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`,
7742
- "g"
7743
- ),
7744
- ""
7745
- );
8047
+ return removeDelimitedRuns(source, COMPILER_MOUNT_BLOCK_START, COMPILER_MOUNT_BLOCK_END);
7746
8048
  }
7747
8049
  function runtimeRoot(document2) {
7748
8050
  return document2.querySelector('[data-composition-id][data-root="true"]') ?? document2.querySelector("[data-composition-id]");
@@ -7767,12 +8069,9 @@ function detectRenderModeHints(html, pageMotionBlur) {
7767
8069
  message: "Detected <iframe> in the composition DOM. Nested iframe animation is routed through screenshot capture mode for compatibility."
7768
8070
  });
7769
8071
  }
7770
- let scriptMatch;
7771
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7772
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7773
- const attrs = scriptMatch[1] || "";
8072
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7774
8073
  if (/\bsrc\s*=/i.test(attrs)) continue;
7775
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8074
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7776
8075
  if (!/requestAnimationFrame\s*\(/.test(content)) continue;
7777
8076
  reasons.push({
7778
8077
  code: "requestAnimationFrame",
@@ -7824,12 +8123,9 @@ function detectAncestorBackgroundImage(html) {
7824
8123
  }
7825
8124
  var SHADER_TRANSITION_USAGE_PATTERN = /\b(?:(?:window|globalThis)\s*\.\s*)?HyperShader\s*\.\s*init\s*\(|\b__hf\s*\.\s*transitions\s*=/;
7826
8125
  function detectShaderTransitionUsage(html) {
7827
- let scriptMatch;
7828
- const scriptPattern = new RegExp(INLINE_SCRIPT_PATTERN.source, INLINE_SCRIPT_PATTERN.flags);
7829
- while ((scriptMatch = scriptPattern.exec(html)) !== null) {
7830
- const attrs = scriptMatch[1] || "";
8126
+ for (const { attrs, body } of inlineScriptBlocks(html)) {
7831
8127
  if (/\bsrc\s*=/i.test(attrs)) continue;
7832
- const content = stripJsComments(stripCompilerMountBootstrap(scriptMatch[2] || ""));
8128
+ const content = stripJsComments(stripCompilerMountBootstrap(body));
7833
8129
  if (SHADER_TRANSITION_USAGE_PATTERN.test(content)) return true;
7834
8130
  }
7835
8131
  return false;
@@ -7985,9 +8281,9 @@ async function compileHtmlFile(html, baseDir, downloadDir, log, urlByAbsentLocal
7985
8281
  if (clampList.length > 0) {
7986
8282
  compiledHtml = clampDurations(compiledHtml, clampList);
7987
8283
  }
7988
- compiledHtml = compiledHtml.replace(/(<video\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
7989
- compiledHtml = compiledHtml.replace(/(<img\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
7990
- compiledHtml = compiledHtml.replace(/(<audio\b[^>]*)\s+crossorigin(?:=["'][^"']*["'])?/gi, "$1");
8284
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "video");
8285
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "img");
8286
+ compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
7991
8287
  return { html: compiledHtml, unresolvedCompositions };
7992
8288
  }
7993
8289
  async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, probes, assetRoot) {
@@ -8421,8 +8717,9 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8421
8717
  if (isPathInside(absPath, absProjectDir)) {
8422
8718
  return null;
8423
8719
  }
8424
- if (!existsSync11(absPath)) return null;
8425
- 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);
8426
8723
  if (refusal) {
8427
8724
  if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
8428
8725
  leftOut.add(trimmed);
@@ -8472,9 +8769,6 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
8472
8769
  };
8473
8770
  }
8474
8771
  var REMOTE_MEDIA_SUBDIR = "_remote_media";
8475
- var REMOTE_MEDIA_TAG_RE = /<(?:video|audio)\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8476
- var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8477
- var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
8478
8772
  async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
8479
8773
  if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
8480
8774
  if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
@@ -8513,14 +8807,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
8513
8807
  return { html: result, remoteMediaAssets };
8514
8808
  }
8515
8809
  async function localizeRemoteMediaSources(html, downloadDir) {
8516
- const urlSet = /* @__PURE__ */ new Set();
8517
- for (const tagRe of [REMOTE_MEDIA_TAG_RE, REMOTE_SOURCE_TAG_RE]) {
8518
- const re = new RegExp(tagRe.source, tagRe.flags);
8519
- let m;
8520
- while ((m = re.exec(html)) !== null) {
8521
- if (m[1]) urlSet.add(m[1]);
8522
- }
8523
- }
8810
+ const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
8524
8811
  const localized = await downloadAndRewriteUrls(
8525
8812
  urlSet,
8526
8813
  html,
@@ -8543,12 +8830,7 @@ function dropBindingOnLocalizedMedia(html) {
8543
8830
  return changed ? document2.toString() : html;
8544
8831
  }
8545
8832
  async function localizeRemoteImageSources(html, downloadDir) {
8546
- const urlSet = /* @__PURE__ */ new Set();
8547
- const re = new RegExp(REMOTE_IMG_TAG_RE.source, REMOTE_IMG_TAG_RE.flags);
8548
- let m;
8549
- while ((m = re.exec(html)) !== null) {
8550
- if (m[1]) urlSet.add(m[1]);
8551
- }
8833
+ const urlSet = new Set(remoteSrcUrls(html, "img"));
8552
8834
  return downloadAndRewriteUrls(
8553
8835
  urlSet,
8554
8836
  html,
@@ -8812,16 +9094,13 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
8812
9094
  const file = resolve7(projectDir, path);
8813
9095
  return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
8814
9096
  };
8815
- return html.replace(
8816
- /(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
8817
- (full, prefix, src, file, suffix) => {
8818
- if (/^https?:\/\//i.test(src)) return full;
8819
- if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
8820
- gsapDist ??= renderGsapDist();
8821
- defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
8822
- return `${prefix}${gsapDist}${file}${suffix}`;
8823
- }
8824
- );
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
+ });
8825
9104
  }
8826
9105
  function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
8827
9106
  if (!isPathInside(htmlPath, projectDir)) return html;
@@ -8908,10 +9187,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
8908
9187
  options.variables ?? {},
8909
9188
  assetRoot
8910
9189
  );
8911
- const sanitizedHtml = inlinedHtml.replace(
8912
- /(<(?:video|audio)\b[^>]*?)\s+preload\s*=\s*["']none["']/gi,
8913
- "$1"
8914
- );
9190
+ const sanitizedHtml = stripPreloadNone(inlinedHtml);
8915
9191
  const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
8916
9192
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
8917
9193
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
@@ -12816,6 +13092,7 @@ async function runCaptureHdrStage(input) {
12816
13092
  let hdrEncoderClosed = false;
12817
13093
  let domSessionClosed = false;
12818
13094
  let releaseHdrExtractionReservation = null;
13095
+ let releaseHdrImageReservation = null;
12819
13096
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
12820
13097
  try {
12821
13098
  await initializeSession7(domSession);
@@ -12897,12 +13174,16 @@ async function runCaptureHdrStage(input) {
12897
13174
  });
12898
13175
  releaseHdrExtractionReservation = extracted.releaseReservation;
12899
13176
  for (const [id, source] of extracted.sources) hdrVideoFrameSources.set(id, source);
12900
- const hdrImageBuffers = decodeHdrImageBuffers({
13177
+ const decodedImages = decodeHdrImageBuffers({
12901
13178
  log,
12902
13179
  hdrImageSrcPaths,
12903
13180
  prep,
12904
- hdrDiagnostics
13181
+ hdrDiagnostics,
13182
+ width,
13183
+ height
12905
13184
  });
13185
+ releaseHdrImageReservation = decodedImages.releaseReservation;
13186
+ const hdrImageBuffers = decodedImages.buffers;
12906
13187
  assertNotAborted();
12907
13188
  try {
12908
13189
  const cleanedUpVideos = /* @__PURE__ */ new Set();
@@ -13055,6 +13336,8 @@ async function runCaptureHdrStage(input) {
13055
13336
  hdrVideoFrameSources.clear();
13056
13337
  releaseHdrExtractionReservation?.();
13057
13338
  releaseHdrExtractionReservation = null;
13339
+ releaseHdrImageReservation?.();
13340
+ releaseHdrImageReservation = null;
13058
13341
  }
13059
13342
  return {
13060
13343
  lastBrowserConsole,
@@ -14128,8 +14411,8 @@ function envInt(name, fallback) {
14128
14411
  return Number.isInteger(parsed) ? parsed : fallback;
14129
14412
  }
14130
14413
  var MAX_REPORTED_ELEMENT_TAGS = 50;
14414
+ var MAX_SCRIPT_STYLE_STRIP_PASSES = 8;
14131
14415
  var VFX_CAPTURE_RANK = { none: 0, self: 1, backdrop: 2 };
14132
- var ROOT_COMPOSITION_TAG_RE = /<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-id=["'][^"']*["'][^>]*>/i;
14133
14416
  function bucketPxDelta(delta) {
14134
14417
  if (delta === 0) return "0";
14135
14418
  if (delta <= 10) return "1-10";
@@ -14137,12 +14420,12 @@ function bucketPxDelta(delta) {
14137
14420
  return "51+";
14138
14421
  }
14139
14422
  function detectRootBodySizeMismatch(html) {
14140
- const rootTag = html.match(ROOT_COMPOSITION_TAG_RE)?.[0];
14423
+ const rootTag = firstCompositionIdTag(html);
14141
14424
  const dataWidth = rootTag && Number(rootTag.match(/\bdata-width=["'](\d+)["']/i)?.[1]);
14142
14425
  const dataHeight = rootTag && Number(rootTag.match(/\bdata-height=["'](\d+)["']/i)?.[1]);
14143
14426
  if (!dataWidth || !dataHeight) return {};
14144
- const widthFirst = html.match(HTML_BODY_CSS_WIDTH_FIRST_RE);
14145
- 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);
14146
14429
  const [cssWidth, cssHeight] = widthFirst ? [Number(widthFirst[2]), Number(widthFirst[4])] : heightFirst ? [Number(heightFirst[4]), Number(heightFirst[2])] : [void 0, void 0];
14147
14430
  if (!cssWidth || !cssHeight) return {};
14148
14431
  const delta = Math.max(Math.abs(dataWidth - cssWidth), Math.abs(dataHeight - cssHeight));
@@ -14150,17 +14433,15 @@ function detectRootBodySizeMismatch(html) {
14150
14433
  }
14151
14434
  function scanElementTags(html) {
14152
14435
  let markup = html;
14153
- for (let previous = ""; markup !== previous; ) {
14436
+ for (let previous = "", pass = 0; markup !== previous && pass < MAX_SCRIPT_STYLE_STRIP_PASSES; pass++) {
14154
14437
  previous = markup;
14155
- markup = markup.replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, "");
14438
+ markup = removeScriptAndStyleBlocks(markup);
14156
14439
  }
14157
14440
  let total = 0;
14158
14441
  const counts = /* @__PURE__ */ new Map();
14159
- for (const m of markup.matchAll(
14160
- /<\/([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
14161
- )) {
14442
+ for (const name of countedTagNames(markup)) {
14162
14443
  total++;
14163
- const tag = (m[1] ?? m[2] ?? m[3] ?? "").toLowerCase();
14444
+ const tag = name.toLowerCase();
14164
14445
  counts.set(tag, (counts.get(tag) ?? 0) + 1);
14165
14446
  }
14166
14447
  const ranked = [...counts.entries()].sort((a, b) => b[1] - a[1]);
@@ -14169,12 +14450,16 @@ function scanElementTags(html) {
14169
14450
  );
14170
14451
  const otherCount = ranked.slice(MAX_REPORTED_ELEMENT_TAGS).reduce((sum2, [, count]) => sum2 + count, 0);
14171
14452
  if (otherCount > 0) byTag.other = (byTag.other ?? 0) + otherCount;
14172
- const arollVideoCount = markup.match(/<video\b[^>]*\bdata-aroll=["']true["'][^>]*>/gi)?.length ?? 0;
14173
- 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
+ );
14174
14459
  const audioCount = counts.get("audio") ?? 0;
14175
14460
  const imageCount = counts.get("img") ?? 0;
14176
14461
  const audioGroupCount = counts.get(HF_AUDIO_GROUP_TAG) ?? 0;
14177
- const subCompositionCount = markup.match(/<[a-zA-Z][-a-zA-Z0-9]*\b[^>]*\bdata-composition-src=["'][^"']*["']/gi)?.length ?? 0;
14462
+ const subCompositionCount = countCompositionSrcMounts(markup);
14178
14463
  let colorGradingCount = 0;
14179
14464
  let hasLut = false;
14180
14465
  for (const m of markup.matchAll(
@@ -23180,6 +23465,7 @@ async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
23180
23465
  }
23181
23466
 
23182
23467
  // src/services/distributed/projectHash.ts
23468
+ import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
23183
23469
  var READ_CHUNK_BYTES = 256 * 1024;
23184
23470
 
23185
23471
  // src/services/distributed/audioSidecar.ts