hyperframes 0.8.75 → 0.8.76

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.
@@ -66166,6 +66166,8 @@ function readExternalScriptAttributes(el) {
66166
66166
  attributes2.integrity = el.getAttribute("integrity") || "";
66167
66167
  if (el.hasAttribute("crossorigin"))
66168
66168
  attributes2.crossorigin = el.getAttribute("crossorigin") || "";
66169
+ if ((el.getAttribute("type") || "").trim().toLowerCase() === "module")
66170
+ attributes2.type = "module";
66169
66171
  return attributes2;
66170
66172
  }
66171
66173
  function ensureExternalScriptTag(doc, src, attributes2 = {}) {
@@ -66181,6 +66183,8 @@ function ensureExternalScriptTag(doc, src, attributes2 = {}) {
66181
66183
  el.setAttribute("integrity", integrity);
66182
66184
  if (attributes2.crossorigin !== void 0)
66183
66185
  el.setAttribute("crossorigin", attributes2.crossorigin);
66186
+ if (attributes2.type)
66187
+ el.setAttribute("type", attributes2.type);
66184
66188
  }
66185
66189
  if (!existing.length) {
66186
66190
  const el = elements[0];
@@ -66194,6 +66198,80 @@ var init_externalScripts = __esm({
66194
66198
  }
66195
66199
  });
66196
66200
 
66201
+ // ../core/dist/compiler/importMaps.js
66202
+ function parseImportMap(json, rebase) {
66203
+ let parsed;
66204
+ try {
66205
+ parsed = JSON.parse(json);
66206
+ } catch {
66207
+ return null;
66208
+ }
66209
+ if (!parsed || typeof parsed !== "object")
66210
+ return null;
66211
+ const { imports, scopes } = parsed;
66212
+ return {
66213
+ imports: rebaseEntries(imports, rebase),
66214
+ scopes: scopes && Object.fromEntries(Object.entries(scopes).map(([prefix, entries2]) => [
66215
+ rebase(prefix),
66216
+ rebaseEntries(entries2, rebase) ?? {}
66217
+ ]))
66218
+ };
66219
+ }
66220
+ function mergeEntries(into, from, where) {
66221
+ for (const [specifier, url] of Object.entries(from ?? {})) {
66222
+ if (!(specifier in into))
66223
+ into[specifier] = url;
66224
+ else if (into[specifier] !== url) {
66225
+ console.warn(`[HyperFrames] import map conflict for "${specifier}"${where}: keeping ${into[specifier]}, ignoring ${url}.`);
66226
+ }
66227
+ }
66228
+ }
66229
+ function mergeImportMapsIntoDocument(doc, maps) {
66230
+ if (maps.length === 0)
66231
+ return;
66232
+ let el = doc.querySelector('script[type="importmap"]');
66233
+ let page = {};
66234
+ try {
66235
+ page = el ? JSON.parse(el.textContent || "{}") : {};
66236
+ } catch {
66237
+ console.warn("[HyperFrames] the page's import map is not valid JSON; replacing it.");
66238
+ }
66239
+ const imports = { ...page.imports };
66240
+ const scopes = { ...page.scopes };
66241
+ for (const map of maps) {
66242
+ mergeEntries(imports, map.imports, "");
66243
+ for (const [prefix, entries2] of Object.entries(map.scopes ?? {})) {
66244
+ mergeEntries(scopes[prefix] ??= {}, entries2, ` in scope ${prefix}`);
66245
+ }
66246
+ }
66247
+ if (!el) {
66248
+ el = doc.createElement("script");
66249
+ el.setAttribute("type", "importmap");
66250
+ doc.head.prepend(el);
66251
+ }
66252
+ el.textContent = JSON.stringify({
66253
+ ...page,
66254
+ imports,
66255
+ ...Object.keys(scopes).length ? { scopes } : {}
66256
+ }).replace(/</g, "\\u003c");
66257
+ }
66258
+ function emitMountedModuleScripts(doc, importMaps, moduleScripts) {
66259
+ mergeImportMapsIntoDocument(doc, importMaps);
66260
+ for (const content of moduleScripts) {
66261
+ const el = doc.createElement("script");
66262
+ el.setAttribute("type", "module");
66263
+ el.textContent = content;
66264
+ doc.body.appendChild(el);
66265
+ }
66266
+ }
66267
+ var rebaseEntries;
66268
+ var init_importMaps = __esm({
66269
+ "../core/dist/compiler/importMaps.js"() {
66270
+ "use strict";
66271
+ rebaseEntries = (entries2, rebase) => entries2 && Object.fromEntries(Object.entries(entries2).map(([specifier, url]) => [specifier, rebase(url)]));
66272
+ }
66273
+ });
66274
+
66197
66275
  // ../core/dist/runtime/flattenedRoot.js
66198
66276
  function markFlattenedInnerRoot(prepared) {
66199
66277
  const authoredRootId = prepared.getAttribute("id")?.trim();
@@ -66642,6 +66720,12 @@ function scopeCssToComposition(css, compositionId, scopeSelectorOverride, author
66642
66720
  function jsonScriptLiteral(value) {
66643
66721
  return JSON.stringify(value).replace(/</g, "\\u003c");
66644
66722
  }
66723
+ function scopedModulePrelude(timelineCompositionId, compositionSrc) {
66724
+ return `const __hyperframes = (function(__hfBaseHyperframes, __hfTimelineCompId, __hfCompositionSrc) {
66725
+ return ${SCOPED_HYPERFRAMES_EXPRESSION};
66726
+ })(window.__hyperframes, ${jsonScriptLiteral(timelineCompositionId)}, ${jsonScriptLiteral(compositionSrc?.trim() || null)});
66727
+ `;
66728
+ }
66645
66729
  function wrapScopedCompositionScript(source, compositionId, errorLabel = "[HyperFrames] composition script error:", scopeSelectorOverride, timelineCompositionId = compositionId, authoredRootId, compositionSrc) {
66646
66730
  const compositionIdLiteral = jsonScriptLiteral(compositionId);
66647
66731
  const timelineCompositionIdLiteral = jsonScriptLiteral(timelineCompositionId);
@@ -66963,19 +67047,7 @@ function wrapScopedCompositionScript(source, compositionId, errorLabel = "[Hyper
66963
67047
  },
66964
67048
  });
66965
67049
  var __hfBaseHyperframes = window.__hyperframes;
66966
- var __hfScopedHyperframes = !__hfBaseHyperframes
66967
- ? __hfBaseHyperframes
66968
- : Object.assign({}, __hfBaseHyperframes, {
66969
- assetUrl: function(path) {
66970
- var page = window.document.baseURI;
66971
- return new URL(path, __hfCompositionSrc ? new URL(__hfCompositionSrc, page) : page).href;
66972
- },
66973
- getVariables: function() {
66974
- var byComp = window.__hfVariablesByComp;
66975
- var scoped = byComp && __hfTimelineCompId ? byComp[__hfTimelineCompId] : null;
66976
- return scoped ? Object.assign({}, scoped) : {};
66977
- },
66978
- });
67050
+ var __hfScopedHyperframes = ${SCOPED_HYPERFRAMES_EXPRESSION};
66979
67051
  var __hfRun = function() {
66980
67052
  try {
66981
67053
  (function(document, gsap, window, __hyperframes) {
@@ -66998,13 +67070,26 @@ function buildVariablesByCompScript(variablesByComp) {
66998
67070
  const json = jsonScriptLiteral(variablesByComp);
66999
67071
  return `window.__hfVariablesByComp = Object.assign({}, window.__hfVariablesByComp || {}, ${json});`;
67000
67072
  }
67001
- var AUTHORED_ROOT_ID_ATTR, INNER_ROOT_ATTR, GLOBAL_AT_RULES;
67073
+ var AUTHORED_ROOT_ID_ATTR, INNER_ROOT_ATTR, GLOBAL_AT_RULES, SCOPED_HYPERFRAMES_EXPRESSION;
67002
67074
  var init_compositionScoping = __esm({
67003
67075
  "../core/dist/compiler/compositionScoping.js"() {
67004
67076
  "use strict";
67005
67077
  AUTHORED_ROOT_ID_ATTR = "data-hf-authored-id";
67006
67078
  INNER_ROOT_ATTR = "data-hf-inner-root";
67007
67079
  GLOBAL_AT_RULES = /* @__PURE__ */ new Set(["keyframes", "-webkit-keyframes", "font-face"]);
67080
+ SCOPED_HYPERFRAMES_EXPRESSION = `!__hfBaseHyperframes
67081
+ ? __hfBaseHyperframes
67082
+ : Object.assign({}, __hfBaseHyperframes, {
67083
+ assetUrl: function(path) {
67084
+ var page = window.document.baseURI;
67085
+ return new URL(path, __hfCompositionSrc ? new URL(__hfCompositionSrc, page) : page).href;
67086
+ },
67087
+ getVariables: function() {
67088
+ var byComp = window.__hfVariablesByComp;
67089
+ var scoped = byComp && __hfTimelineCompId ? byComp[__hfTimelineCompId] : null;
67090
+ return scoped ? Object.assign({}, scoped) : {};
67091
+ },
67092
+ })`;
67008
67093
  }
67009
67094
  });
67010
67095
 
@@ -72433,6 +72518,13 @@ function parseGsapScriptAcornForWrite(script) {
72433
72518
  }
72434
72519
  }
72435
72520
  function parseGsapScriptAcorn(script) {
72521
+ const parsed = parseMemo.get(script) ?? parseGsapScriptAcornUncached(script);
72522
+ parseMemo.delete(script);
72523
+ parseMemo.set(script, parsed);
72524
+ if (parseMemo.size > PARSE_MEMO_ENTRIES) parseMemo.delete(parseMemo.keys().next().value);
72525
+ return structuredClone(parsed);
72526
+ }
72527
+ function parseGsapScriptAcornUncached(script) {
72436
72528
  try {
72437
72529
  const ast = parseProgram3(script);
72438
72530
  const scope = collectScopeBindings(ast);
@@ -72580,7 +72672,7 @@ function extractGsapLabels(script) {
72580
72672
  return [];
72581
72673
  }
72582
72674
  }
72583
- var PROPERTY_GROUPS2, PROP_TO_GROUP2, SKIP_KEYS, FUNCTION_TYPES, GSAP_METHODS, MAX_DEPTH, MAX_ITERS, SAFE_DEFAULT_NODES, SUPPORTED_PARAMS_CACHE, roundPercentage, GSAP_METHODS2, QUERY_METHODS, ITERATION_METHODS, SCOPE_NODE_TYPES, CONST_NODES, MATH_FNS, MATH_CONSTS, BUILTIN_VAR_KEYS, DROPPED_VAR_KEYS, EXTRAS_KEYS, PERCENTAGE_KEY_RE, GSAP_DEFAULT_DURATION;
72675
+ var PROPERTY_GROUPS2, PROP_TO_GROUP2, SKIP_KEYS, FUNCTION_TYPES, GSAP_METHODS, MAX_DEPTH, MAX_ITERS, SAFE_DEFAULT_NODES, SUPPORTED_PARAMS_CACHE, roundPercentage, GSAP_METHODS2, QUERY_METHODS, ITERATION_METHODS, SCOPE_NODE_TYPES, CONST_NODES, MATH_FNS, MATH_CONSTS, BUILTIN_VAR_KEYS, DROPPED_VAR_KEYS, EXTRAS_KEYS, PERCENTAGE_KEY_RE, GSAP_DEFAULT_DURATION, PARSE_MEMO_ENTRIES, parseMemo;
72584
72676
  var init_gsapParserAcorn = __esm({
72585
72677
  "../parsers/dist/gsapParserAcorn.js"() {
72586
72678
  "use strict";
@@ -72660,6 +72752,8 @@ var init_gsapParserAcorn = __esm({
72660
72752
  ]);
72661
72753
  PERCENTAGE_KEY_RE = /^(\d+(?:\.\d+)?)%$/;
72662
72754
  GSAP_DEFAULT_DURATION = 0.5;
72755
+ PARSE_MEMO_ENTRIES = 4;
72756
+ parseMemo = /* @__PURE__ */ new Map();
72663
72757
  }
72664
72758
  });
72665
72759
 
@@ -74211,6 +74305,81 @@ function collectDeclaredVariableIds(htmlTagRaw) {
74211
74305
  }
74212
74306
  return declared;
74213
74307
  }
74308
+ function variablesDeclarationFindings(tag, tags) {
74309
+ const raw = readJsonAttr(tag.raw, "data-composition-variables");
74310
+ if (!raw) return [];
74311
+ let parsed;
74312
+ try {
74313
+ parsed = JSON.parse(raw);
74314
+ } catch (err) {
74315
+ const reason = err instanceof Error ? err.message : "unknown";
74316
+ return [
74317
+ {
74318
+ code: "invalid_composition_variables_declaration",
74319
+ severity: "error",
74320
+ message: `data-composition-variables is not valid JSON (${reason}).`,
74321
+ fixHint: `Provide a JSON array of variable declarations: data-composition-variables='[{"id":"title","type":"string","label":"Title","default":"Hello"}]'.`,
74322
+ snippet: truncateSnippet(tag.raw)
74323
+ }
74324
+ ];
74325
+ }
74326
+ if (!Array.isArray(parsed)) {
74327
+ return [
74328
+ {
74329
+ code: "invalid_composition_variables_declaration",
74330
+ severity: "error",
74331
+ message: "data-composition-variables must be a JSON array of variable declarations.",
74332
+ fixHint: `Wrap declarations in [] and give each an id, type, label, and default: '[{"id":"title","type":"string","label":"Title","default":"Hello"}]'.`,
74333
+ snippet: truncateSnippet(tag.raw)
74334
+ }
74335
+ ];
74336
+ }
74337
+ const findings = [];
74338
+ const knownTypes = new Set(COMPOSITION_VARIABLE_TYPES2);
74339
+ const varSrcIds = /* @__PURE__ */ new Set();
74340
+ for (const other of tags) {
74341
+ const bound = readAttr(other.raw, "data-var-src");
74342
+ if (bound) varSrcIds.add(bound);
74343
+ }
74344
+ for (let i = 0; i < parsed.length; i += 1) {
74345
+ const entry = parsed[i];
74346
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
74347
+ findings.push({
74348
+ code: "invalid_composition_variables_declaration",
74349
+ severity: "error",
74350
+ message: `data-composition-variables entry [${i}] must be an object with id, type, label, and default.`,
74351
+ snippet: truncateSnippet(tag.raw)
74352
+ });
74353
+ continue;
74354
+ }
74355
+ const e = entry;
74356
+ const missing = [];
74357
+ if (typeof e.id !== "string") missing.push("id");
74358
+ if (typeof e.type !== "string" || !knownTypes.has(e.type)) missing.push("type");
74359
+ if (typeof e.label !== "string") missing.push("label");
74360
+ if (!("default" in e)) missing.push("default");
74361
+ if (missing.length > 0) {
74362
+ findings.push({
74363
+ code: "invalid_composition_variables_declaration",
74364
+ severity: "error",
74365
+ message: `data-composition-variables entry [${i}] is missing or has invalid: ${missing.join(", ")}. Type must be one of string, number, color, boolean, enum, font, image.`,
74366
+ snippet: truncateSnippet(tag.raw)
74367
+ });
74368
+ continue;
74369
+ }
74370
+ const id = String(e.id);
74371
+ if ((e.type === "image" || varSrcIds.has(id)) && typeof e.default === "string" && e.default.length > 0 && !isSafeMediaUrl(e.default)) {
74372
+ findings.push({
74373
+ code: "unloadable_media_variable_default",
74374
+ severity: "error",
74375
+ message: `Variable "${id}" defaults to a URL the runtime will refuse to load, so any element bound to it renders its authored fallback src instead and the render still exits 0.`,
74376
+ fixHint: `Media URLs must be relative, http(s), blob:, or a data:image/* URI. Copy the file into the project and reference it relatively (e.g. "assets/bg.png") rather than by absolute path.`,
74377
+ snippet: truncateSnippet(tag.raw)
74378
+ });
74379
+ }
74380
+ }
74381
+ return findings;
74382
+ }
74214
74383
  function collectAllDeclaredVariableIds(tags) {
74215
74384
  const all = /* @__PURE__ */ new Set();
74216
74385
  for (const tag of tags) {
@@ -76669,84 +76838,8 @@ var init_dist3 = __esm({
76669
76838
  // on any structural problem. Surface JSON / shape failures so authors
76670
76839
  // catch them at lint time rather than wondering why their `getVariables()`
76671
76840
  // defaults aren't applied.
76672
- // fallow-ignore-next-line complexity
76673
- ({ tags }) => {
76674
- const htmlTag = findHtmlTag(tags);
76675
- if (!htmlTag) return [];
76676
- const raw = readJsonAttr(htmlTag.raw, "data-composition-variables");
76677
- if (!raw) return [];
76678
- let parsed;
76679
- try {
76680
- parsed = JSON.parse(raw);
76681
- } catch (err) {
76682
- const reason = err instanceof Error ? err.message : "unknown";
76683
- return [
76684
- {
76685
- code: "invalid_composition_variables_declaration",
76686
- severity: "error",
76687
- message: `data-composition-variables is not valid JSON (${reason}).`,
76688
- fixHint: `Provide a JSON array of variable declarations: data-composition-variables='[{"id":"title","type":"string","label":"Title","default":"Hello"}]'.`,
76689
- snippet: truncateSnippet(htmlTag.raw)
76690
- }
76691
- ];
76692
- }
76693
- if (!Array.isArray(parsed)) {
76694
- return [
76695
- {
76696
- code: "invalid_composition_variables_declaration",
76697
- severity: "error",
76698
- message: "data-composition-variables must be a JSON array of variable declarations.",
76699
- fixHint: `Wrap declarations in [] and give each an id, type, label, and default: '[{"id":"title","type":"string","label":"Title","default":"Hello"}]'.`,
76700
- snippet: truncateSnippet(htmlTag.raw)
76701
- }
76702
- ];
76703
- }
76704
- const findings = [];
76705
- const knownTypes = new Set(COMPOSITION_VARIABLE_TYPES2);
76706
- const varSrcIds = /* @__PURE__ */ new Set();
76707
- for (const tag of tags) {
76708
- const bound = readAttr(tag.raw, "data-var-src");
76709
- if (bound) varSrcIds.add(bound);
76710
- }
76711
- for (let i = 0; i < parsed.length; i += 1) {
76712
- const entry = parsed[i];
76713
- if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
76714
- findings.push({
76715
- code: "invalid_composition_variables_declaration",
76716
- severity: "error",
76717
- message: `data-composition-variables entry [${i}] must be an object with id, type, label, and default.`,
76718
- snippet: truncateSnippet(htmlTag.raw)
76719
- });
76720
- continue;
76721
- }
76722
- const e = entry;
76723
- const missing = [];
76724
- if (typeof e.id !== "string") missing.push("id");
76725
- if (typeof e.type !== "string" || !knownTypes.has(e.type)) missing.push("type");
76726
- if (typeof e.label !== "string") missing.push("label");
76727
- if (!("default" in e)) missing.push("default");
76728
- if (missing.length > 0) {
76729
- findings.push({
76730
- code: "invalid_composition_variables_declaration",
76731
- severity: "error",
76732
- message: `data-composition-variables entry [${i}] is missing or has invalid: ${missing.join(", ")}. Type must be one of string, number, color, boolean, enum, font, image.`,
76733
- snippet: truncateSnippet(htmlTag.raw)
76734
- });
76735
- continue;
76736
- }
76737
- const id = String(e.id);
76738
- if ((e.type === "image" || varSrcIds.has(id)) && typeof e.default === "string" && e.default.length > 0 && !isSafeMediaUrl(e.default)) {
76739
- findings.push({
76740
- code: "unloadable_media_variable_default",
76741
- severity: "error",
76742
- message: `Variable "${id}" defaults to a URL the runtime will refuse to load, so any element bound to it renders its authored fallback src instead and the render still exits 0.`,
76743
- fixHint: `Media URLs must be relative, http(s), blob:, or a data:image/* URI. Copy the file into the project and reference it relatively (e.g. "assets/bg.png") rather than by absolute path.`,
76744
- snippet: truncateSnippet(htmlTag.raw)
76745
- });
76746
- }
76747
- }
76748
- return findings;
76749
- },
76841
+ // Checked on every element that declares: <html>, or the composition root.
76842
+ ({ tags }) => tags.filter((tag) => readJsonAttr(tag.raw, "data-composition-variables")).flatMap((tag) => variablesDeclarationFindings(tag, tags)),
76750
76843
  // html_dir_attribute_breaks_render — valid non-LTR dir values on
76751
76844
  // <html> renders correctly in preview/snapshot but produces a fully
76752
76845
  // blank/black video from render, with no other lint/validate/inspect
@@ -78758,6 +78851,8 @@ function inlineSubCompositions(document2, hosts, options) {
78758
78851
  const scripts = [];
78759
78852
  const externalScriptSrcs = [];
78760
78853
  const scriptItems = [];
78854
+ const importMaps = [];
78855
+ const moduleScripts = [];
78761
78856
  const externalLinks = [];
78762
78857
  const seenLinkHrefs = /* @__PURE__ */ new Set();
78763
78858
  const variablesByComp = {};
@@ -78845,7 +78940,24 @@ function inlineSubCompositions(document2, hosts, options) {
78845
78940
  }
78846
78941
  for (const scriptEl of plan2.scriptSources) {
78847
78942
  const externalSrc = resolveSubAssetPath(scriptEl.getAttribute("src"));
78848
- if (externalSrc) {
78943
+ const type = (scriptEl.getAttribute("type") || "").trim().toLowerCase();
78944
+ if (type === "importmap") {
78945
+ const map = parseImportMap(scriptEl.textContent || "", (url) => {
78946
+ const authored = url.trim();
78947
+ const rebased = resolveSubAssetPath(authored);
78948
+ if (rebased === authored)
78949
+ return rebased;
78950
+ const urlLike = /^(\/|\.\.?\/|[a-z][a-z\d+.-]*:)/i.test(rebased) ? rebased : `./${rebased}`;
78951
+ return authored.endsWith("/") && !urlLike.endsWith("/") ? `${urlLike}/` : urlLike;
78952
+ });
78953
+ if (map)
78954
+ importMaps.push(map);
78955
+ else
78956
+ console.warn(`[HyperFrames] ${src}: import map is not valid JSON, so it is skipped.`);
78957
+ } else if (type === "module" && !externalSrc) {
78958
+ const prelude = scriptCompositionId ? scopedModulePrelude(runtimeCompId || scopeCompId || scriptCompositionId, src) : "";
78959
+ moduleScripts.push(prelude + (scriptEl.textContent || ""));
78960
+ } else if (externalSrc) {
78849
78961
  if (!externalScriptSrcs.includes(externalSrc)) {
78850
78962
  externalScriptSrcs.push(externalSrc);
78851
78963
  }
@@ -78916,12 +79028,22 @@ function inlineSubCompositions(document2, hosts, options) {
78916
79028
  queue.push({ element: nestedHost.host, ancestry: nestedAncestry });
78917
79029
  }
78918
79030
  }
78919
- return { styles, scripts, externalScriptSrcs, scriptItems, externalLinks, variablesByComp };
79031
+ return {
79032
+ styles,
79033
+ scripts,
79034
+ externalScriptSrcs,
79035
+ scriptItems,
79036
+ externalLinks,
79037
+ variablesByComp,
79038
+ importMaps,
79039
+ moduleScripts
79040
+ };
78920
79041
  }
78921
79042
  var init_inlineSubCompositions = __esm({
78922
79043
  "../core/dist/compiler/inlineSubCompositions.js"() {
78923
79044
  "use strict";
78924
79045
  init_externalScripts();
79046
+ init_importMaps();
78925
79047
  init_rewriteSubCompPaths();
78926
79048
  init_getVariables();
78927
79049
  init_compositionScoping();
@@ -79113,6 +79235,7 @@ var init_htmlBundler = __esm({
79113
79235
  "use strict";
79114
79236
  init_scriptRuns();
79115
79237
  init_externalScripts();
79238
+ init_importMaps();
79116
79239
  init_flattenedRoot();
79117
79240
  init_flattenedRoot();
79118
79241
  init_getVariables();
@@ -79160,6 +79283,7 @@ var init_compiler = __esm({
79160
79283
  init_assetPaths();
79161
79284
  init_mediaRenderIds();
79162
79285
  init_externalScripts();
79286
+ init_importMaps();
79163
79287
  }
79164
79288
  });
79165
79289
 
@@ -85263,6 +85387,7 @@ __export(src_exports, {
85263
85387
  scaleProtocolTimeoutForComposition: () => scaleProtocolTimeoutForComposition,
85264
85388
  selectVerifySampleIndicesForTask: () => selectVerifySampleIndicesForTask,
85265
85389
  shouldClampToScreenshotForConcreteGpu: () => shouldClampToScreenshotForConcreteGpu,
85390
+ shouldDisableBrowserPoolForParallelWorker: () => shouldDisableBrowserPoolForParallelWorker,
85266
85391
  showVideoElements: () => showVideoElements,
85267
85392
  spawnStreamingEncoder: () => spawnStreamingEncoder,
85268
85393
  syncVideoFrameVisibility: () => syncVideoFrameVisibility,
@@ -92371,13 +92496,19 @@ function defaultSessionFactory(input) {
92371
92496
  let probeSession = input.probeSession;
92372
92497
  return {
92373
92498
  create: async () => {
92374
- const session = probeSession ? probeSession : await openSegmentedSession({ ...input, probeSession: null });
92499
+ const session = probeSession ?? await openSegmentedSession(input);
92375
92500
  if (probeSession) {
92376
92501
  openSegmentedSessionReuse(input, probeSession);
92377
92502
  probeSession = null;
92378
92503
  }
92379
- if (!session.isInitialized) await initializeSession(session);
92380
- await completeDeferredDrawElementInit(session);
92504
+ try {
92505
+ if (!session.isInitialized) await initializeSession(session);
92506
+ await completeDeferredDrawElementInit(session);
92507
+ } catch (error) {
92508
+ await closeCaptureSession(session).catch(() => {
92509
+ });
92510
+ throw error;
92511
+ }
92381
92512
  return session;
92382
92513
  }
92383
92514
  };
@@ -92388,16 +92519,19 @@ function openSegmentedSessionReuse(input, session) {
92388
92519
  async function openSegmentedSession(input) {
92389
92520
  const captureCfg = input.cfg.forceScreenshot === input.plan.forceScreenshot ? input.cfg : { ...input.cfg, forceScreenshot: input.plan.forceScreenshot };
92390
92521
  const videoInjector = input.createRenderVideoFrameInjector();
92391
- if (input.probeSession) {
92392
- prepareCaptureSessionForReuse(input.probeSession, input.framesDir, videoInjector);
92393
- return input.probeSession;
92394
- }
92522
+ const captureOptions = input.buildCaptureOptions();
92523
+ const ownBrowser = shouldDisableBrowserPoolForParallelWorker({
92524
+ parallel: (input.workerCount ?? 1) > 1,
92525
+ platform: process.platform,
92526
+ deviceScaleFactor: captureOptions.deviceScaleFactor,
92527
+ headlessShellPath: resolveHeadlessShellPath(captureCfg)
92528
+ });
92395
92529
  return createCaptureSession(
92396
92530
  input.fileServer.url,
92397
92531
  input.framesDir,
92398
- input.buildCaptureOptions(),
92532
+ captureOptions,
92399
92533
  videoInjector,
92400
- captureCfg
92534
+ ownBrowser ? { ...captureCfg, enableBrowserPool: false } : captureCfg
92401
92535
  );
92402
92536
  }
92403
92537
  async function concatSegments(concat, segmentPaths, videoOnlyPath, abortSignal, cfg) {
@@ -92410,7 +92544,7 @@ async function concatSegments(concat, segmentPaths, videoOnlyPath, abortSignal,
92410
92544
  }
92411
92545
  async function createSegmentWorker(run, id) {
92412
92546
  const { input, deps } = run;
92413
- const factory = input.sessionFactoryForWorker?.(id) ?? input.sessionFactory ?? defaultSessionFactory(input);
92547
+ const factory = input.sessionFactoryForWorker?.(id) ?? run.sessionFactory;
92414
92548
  return {
92415
92549
  id,
92416
92550
  factory,
@@ -92532,16 +92666,16 @@ async function runCaptureSegmentedStage(input) {
92532
92666
  segmentDir,
92533
92667
  skipSize: skip.size,
92534
92668
  workerCount: Math.max(1, input.workerCount ?? 1),
92535
- recycleEvery: input.browserRecycleEverySegments ?? 0
92669
+ recycleEvery: input.browserRecycleEverySegments ?? 0,
92670
+ sessionFactory: input.sessionFactory ?? defaultSessionFactory(input)
92536
92671
  };
92537
92672
  const queue = createSegmentQueue(pending);
92538
92673
  const segmentPaths = segments.map((s) => segmentOutputPath(segmentDir, s.index));
92539
92674
  if (pending.length === 0) return concatResumedRun(run, segmentPaths);
92540
92675
  let fellBackToStreaming = false;
92541
92676
  const workers = [];
92542
- for (let id = 0; id < run.workerCount; id++) workers.push(await createSegmentWorker(run, id));
92543
92677
  const consoleOf = () => workers[0]?.ctx.session.browserConsoleBuffer ?? [];
92544
- let lastBrowserConsole = consoleOf();
92678
+ let lastBrowserConsole = [];
92545
92679
  const runWorkerLoop = async (worker) => {
92546
92680
  for (; ; ) {
92547
92681
  if (fellBackToStreaming) return;
@@ -92556,6 +92690,7 @@ async function runCaptureSegmentedStage(input) {
92556
92690
  };
92557
92691
  try {
92558
92692
  assertNotAborted();
92693
+ for (let id = 0; id < run.workerCount; id++) workers.push(await createSegmentWorker(run, id));
92559
92694
  const outcomes = await Promise.allSettled(workers.map((w) => runWorkerLoop(w)));
92560
92695
  for (const worker of workers) dedupPerfs.push(getCapturePerfSummary(worker.ctx.session));
92561
92696
  const failure = outcomes.find((o) => o.status === "rejected");
@@ -96179,6 +96314,13 @@ function inlineSubCompositions2(html, subCompositions, projectDir, variableOverr
96179
96314
  }
96180
96315
  flushInline();
96181
96316
  }
96317
+ if (body) {
96318
+ emitMountedModuleScripts(
96319
+ document2,
96320
+ result.importMaps,
96321
+ result.moduleScripts
96322
+ );
96323
+ }
96182
96324
  emitRootCompositionVariableStyles(
96183
96325
  document2,
96184
96326
  result.variablesByComp,
@@ -104295,8 +104437,8 @@ async function runFontLocalize(io, localize) {
104295
104437
  }
104296
104438
 
104297
104439
  // src/version.ts
104298
- var VERSION = true ? "0.8.75" : "0.0.0-dev";
104299
- var PRODUCER_VERSION = true ? "0.8.75" : "0.0.0-dev";
104440
+ var VERSION = true ? "0.8.76" : "0.0.0-dev";
104441
+ var PRODUCER_VERSION = true ? "0.8.76" : "0.0.0-dev";
104300
104442
 
104301
104443
  // src/fontLocalizeCli.ts
104302
104444
  async function readStdin() {