@hyperframes/producer 0.9.64 → 0.9.65

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.
@@ -2475,6 +2475,16 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
2475
2475
  var CompositionExpansionBudget = class {
2476
2476
  bytes = 0;
2477
2477
  mounts = 0;
2478
+ generated = 0;
2479
+ /** `bytes` may be negative when a reserved upper bound is settled to the real size. */
2480
+ chargeGenerated(file, bytes) {
2481
+ this.generated += bytes;
2482
+ if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
2483
+ throw new CompositionTooLargeError(
2484
+ `Scripts and styles generated for sub-composition mounts, ending at "${file}", add up to ${megabytes(this.generated)}. One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)} for its mounts. Merge small inline scripts and style rules, keep data-composition-id values short, or mount scenes fewer times.`,
2485
+ { bytes: this.generated, limitBytes: MAX_EXPANDED_COMPOSITION_BYTES, exceeded: "generated" }
2486
+ );
2487
+ }
2478
2488
  charge(file, bytes) {
2479
2489
  this.bytes += bytes;
2480
2490
  this.mounts += 1;
@@ -4238,6 +4248,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
4238
4248
  if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
4239
4249
  return compHtml;
4240
4250
  },
4251
+ chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
4241
4252
  parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
4242
4253
  // Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
4243
4254
  // against its own directory, project-root refs stay as authored.
@@ -5812,21 +5823,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
5812
5823
  return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
5813
5824
  }
5814
5825
  var MAX_MEDIA_SELECTOR_WORK = 1e6;
5815
- var SIBLING_COMBINATOR = /[~+]/;
5816
- function managedMediaElements(document2) {
5826
+ var ATTRIBUTE_SELECTOR = /\[\s*[\w-]+\s*(?:[~|^$*]?=\s*(?:"[^"\\]*"|'[^'\\]*'|[\w-]+)\s*(?:[is]\s*)?)?\]/g;
5827
+ var COMPOUND_SELECTORS = /^[\w\s#.*>,@-]+$/;
5828
+ function cheapSelectorShape(selector) {
5829
+ const shape = selector.replace(ATTRIBUTE_SELECTOR, "@").trim();
5830
+ if (!COMPOUND_SELECTORS.test(shape)) return null;
5831
+ const collapsed = shape.replace(/\s+/g, " ").replace(/ ?([>,]) ?/g, "$1");
5832
+ const parts = collapsed.split(",");
5833
+ return parts.every((part) => part !== "" && part.split(" ").length <= 2) ? collapsed : null;
5834
+ }
5835
+ var attributeChars = (element) => Array.from(element.attributes).reduce((sum2, a) => sum2 + a.name.length + a.value.length + 1, 0);
5836
+ function managedMediaElements(document2, measure) {
5817
5837
  const managed = [];
5818
- const pending = [];
5819
- for (const element of Array.from(document2.children)) pending.push({ element, inMedia: false });
5838
+ const pending = Array.from(document2.children, (element) => ({
5839
+ element,
5840
+ inMedia: false,
5841
+ depth: 0,
5842
+ above: 0
5843
+ }));
5820
5844
  for (let next = pending.pop(); next; next = pending.pop()) {
5821
- const name = next.element.tagName.toLowerCase();
5845
+ const { element, depth } = next;
5846
+ const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
5847
+ const name = element.tagName.toLowerCase();
5822
5848
  const isMedia = name === "video" || name === "audio";
5823
- if (isMedia || next.inMedia && name === "source") managed.push(next.element);
5824
- for (const child3 of Array.from(next.element.children)) {
5825
- pending.push({ element: child3, inMedia: next.inMedia || isMedia });
5849
+ if (isMedia || next.inMedia && name === "source") {
5850
+ managed.push({ element, depth, chainAttributeChars });
5851
+ }
5852
+ for (const child3 of Array.from(element.children)) {
5853
+ const inMedia = next.inMedia || isMedia;
5854
+ pending.push({ element: child3, inMedia, depth: depth + 1, above: chainAttributeChars });
5826
5855
  }
5827
5856
  }
5828
5857
  return managed;
5829
5858
  }
5859
+ function selectorCheckCost(selector, measured) {
5860
+ const shape = cheapSelectorShape(selector);
5861
+ if (shape === null) return Infinity;
5862
+ const tests = (shape.match(/[.#@]/g)?.length ?? 0) + shape.split(/[ >,]/).length;
5863
+ let cost = 0;
5864
+ for (const media of measured) {
5865
+ cost += selector.length * (media.depth + 1) + tests * media.chainAttributeChars;
5866
+ if (cost > MAX_MEDIA_SELECTOR_WORK) return cost;
5867
+ }
5868
+ return cost;
5869
+ }
5830
5870
  function hasRuntimeMediaChanges(html) {
5831
5871
  const { document: document2 } = parseHTML6(html);
5832
5872
  const scriptBodies = [...document2.querySelectorAll("script")].map(
@@ -5836,11 +5876,12 @@ function hasRuntimeMediaChanges(html) {
5836
5876
  (script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
5837
5877
  );
5838
5878
  if (insertedMedia) return true;
5839
- const managed = managedMediaElements(document2);
5879
+ const managed = managedMediaElements(document2, false);
5840
5880
  if (managed.length === 0) return false;
5841
- const managedIds = new Set(managed.map((element) => element.getAttribute("id")).filter(Boolean));
5881
+ const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
5842
5882
  const selectors = /* @__PURE__ */ new Set();
5843
- let selectorChars = 0;
5883
+ let work = 0;
5884
+ let measured;
5844
5885
  for (const script of scriptBodies) {
5845
5886
  for (const mutation of extractMediaSrcMutations(script)) {
5846
5887
  const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
@@ -5849,15 +5890,15 @@ function hasRuntimeMediaChanges(html) {
5849
5890
  continue;
5850
5891
  }
5851
5892
  if (selectors.has(mutation.selector)) continue;
5852
- if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
5853
5893
  selectors.add(mutation.selector);
5854
- selectorChars += mutation.selector.length;
5855
- if (selectorChars * managed.length > MAX_MEDIA_SELECTOR_WORK) return true;
5894
+ measured ??= managedMediaElements(document2, true);
5895
+ work += selectorCheckCost(mutation.selector, measured);
5896
+ if (work > MAX_MEDIA_SELECTOR_WORK) return true;
5856
5897
  }
5857
5898
  }
5858
5899
  for (const selector of selectors) {
5859
5900
  try {
5860
- if (managed.some((element) => element.matches(selector))) return true;
5901
+ if (managed.some((media) => media.element.matches(selector))) return true;
5861
5902
  } catch {
5862
5903
  }
5863
5904
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "9908c266bf0c428907be35f907a443dd2d6d3fe4c2706f935269903361f95c30",
4
+ "sha256": "26bc2c53086737e056afd7751aeee6ff6f019d5c4a9e820a7d055c46b5737c73",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"