@hyperframes/producer 0.9.63 → 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.
package/dist/index.js CHANGED
@@ -6947,6 +6947,16 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
6947
6947
  var CompositionExpansionBudget = class {
6948
6948
  bytes = 0;
6949
6949
  mounts = 0;
6950
+ generated = 0;
6951
+ /** `bytes` may be negative when a reserved upper bound is settled to the real size. */
6952
+ chargeGenerated(file, bytes) {
6953
+ this.generated += bytes;
6954
+ if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
6955
+ throw new CompositionTooLargeError(
6956
+ `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.`,
6957
+ { bytes: this.generated, limitBytes: MAX_EXPANDED_COMPOSITION_BYTES, exceeded: "generated" }
6958
+ );
6959
+ }
6950
6960
  charge(file, bytes) {
6951
6961
  this.bytes += bytes;
6952
6962
  this.mounts += 1;
@@ -8133,16 +8143,23 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
8133
8143
  }
8134
8144
  }
8135
8145
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8136
- var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
8137
8146
  function compositionSrcsIn(html) {
8138
8147
  const { document: document2 } = parseHTML5(html);
8148
+ const mounts = [];
8139
8149
  const templated = [];
8140
- const templates = [...document2.querySelectorAll("template")];
8141
- for (let template = templates.pop(); template; template = templates.pop()) {
8142
- templated.push(...mountSrcsUnder(template.content));
8143
- templates.push(...template.content.querySelectorAll("template"));
8150
+ const stack = [...document2.children].reverse().map((el) => [el, false]);
8151
+ for (let next = stack.pop(); next; next = stack.pop()) {
8152
+ const [el, inTemplate] = next;
8153
+ const srcPath = el.getAttribute("data-composition-src");
8154
+ if (srcPath && !isUnresolvedAssetPlaceholder(srcPath)) {
8155
+ (inTemplate ? templated : mounts).push(srcPath);
8156
+ }
8157
+ const childrenInTemplate = inTemplate || el.localName === "template";
8158
+ const children = [...el.children];
8159
+ for (let i = children.length - 1; i >= 0; i -= 1)
8160
+ stack.push([children[i], childrenInTemplate]);
8144
8161
  }
8145
- return { mounts: mountSrcsUnder(document2), templated };
8162
+ return { mounts, templated };
8146
8163
  }
8147
8164
  function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8148
8165
  if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
@@ -8703,6 +8720,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8703
8720
  if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
8704
8721
  return compHtml;
8705
8722
  },
8723
+ chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
8706
8724
  parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
8707
8725
  // Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
8708
8726
  // against its own directory, project-root refs stay as authored.
@@ -10280,21 +10298,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
10280
10298
  return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
10281
10299
  }
10282
10300
  var MAX_MEDIA_SELECTOR_WORK = 1e6;
10283
- var SIBLING_COMBINATOR = /[~+]/;
10284
- function managedMediaElements(document2) {
10301
+ var ATTRIBUTE_SELECTOR = /\[\s*[\w-]+\s*(?:[~|^$*]?=\s*(?:"[^"\\]*"|'[^'\\]*'|[\w-]+)\s*(?:[is]\s*)?)?\]/g;
10302
+ var COMPOUND_SELECTORS = /^[\w\s#.*>,@-]+$/;
10303
+ function cheapSelectorShape(selector) {
10304
+ const shape = selector.replace(ATTRIBUTE_SELECTOR, "@").trim();
10305
+ if (!COMPOUND_SELECTORS.test(shape)) return null;
10306
+ const collapsed = shape.replace(/\s+/g, " ").replace(/ ?([>,]) ?/g, "$1");
10307
+ const parts = collapsed.split(",");
10308
+ return parts.every((part) => part !== "" && part.split(" ").length <= 2) ? collapsed : null;
10309
+ }
10310
+ var attributeChars = (element) => Array.from(element.attributes).reduce((sum2, a) => sum2 + a.name.length + a.value.length + 1, 0);
10311
+ function managedMediaElements(document2, measure) {
10285
10312
  const managed = [];
10286
- const pending = [];
10287
- for (const element of Array.from(document2.children)) pending.push({ element, inMedia: false });
10313
+ const pending = Array.from(document2.children, (element) => ({
10314
+ element,
10315
+ inMedia: false,
10316
+ depth: 0,
10317
+ above: 0
10318
+ }));
10288
10319
  for (let next = pending.pop(); next; next = pending.pop()) {
10289
- const name = next.element.tagName.toLowerCase();
10320
+ const { element, depth } = next;
10321
+ const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
10322
+ const name = element.tagName.toLowerCase();
10290
10323
  const isMedia = name === "video" || name === "audio";
10291
- if (isMedia || next.inMedia && name === "source") managed.push(next.element);
10292
- for (const child3 of Array.from(next.element.children)) {
10293
- pending.push({ element: child3, inMedia: next.inMedia || isMedia });
10324
+ if (isMedia || next.inMedia && name === "source") {
10325
+ managed.push({ element, depth, chainAttributeChars });
10326
+ }
10327
+ for (const child3 of Array.from(element.children)) {
10328
+ const inMedia = next.inMedia || isMedia;
10329
+ pending.push({ element: child3, inMedia, depth: depth + 1, above: chainAttributeChars });
10294
10330
  }
10295
10331
  }
10296
10332
  return managed;
10297
10333
  }
10334
+ function selectorCheckCost(selector, measured) {
10335
+ const shape = cheapSelectorShape(selector);
10336
+ if (shape === null) return Infinity;
10337
+ const tests = (shape.match(/[.#@]/g)?.length ?? 0) + shape.split(/[ >,]/).length;
10338
+ let cost = 0;
10339
+ for (const media of measured) {
10340
+ cost += selector.length * (media.depth + 1) + tests * media.chainAttributeChars;
10341
+ if (cost > MAX_MEDIA_SELECTOR_WORK) return cost;
10342
+ }
10343
+ return cost;
10344
+ }
10298
10345
  function hasRuntimeMediaChanges(html) {
10299
10346
  const { document: document2 } = parseHTML6(html);
10300
10347
  const scriptBodies = [...document2.querySelectorAll("script")].map(
@@ -10304,11 +10351,12 @@ function hasRuntimeMediaChanges(html) {
10304
10351
  (script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
10305
10352
  );
10306
10353
  if (insertedMedia) return true;
10307
- const managed = managedMediaElements(document2);
10354
+ const managed = managedMediaElements(document2, false);
10308
10355
  if (managed.length === 0) return false;
10309
- const managedIds = new Set(managed.map((element) => element.getAttribute("id")).filter(Boolean));
10356
+ const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
10310
10357
  const selectors = /* @__PURE__ */ new Set();
10311
- let selectorChars = 0;
10358
+ let work = 0;
10359
+ let measured;
10312
10360
  for (const script of scriptBodies) {
10313
10361
  for (const mutation of extractMediaSrcMutations(script)) {
10314
10362
  const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
@@ -10317,15 +10365,15 @@ function hasRuntimeMediaChanges(html) {
10317
10365
  continue;
10318
10366
  }
10319
10367
  if (selectors.has(mutation.selector)) continue;
10320
- if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
10321
10368
  selectors.add(mutation.selector);
10322
- selectorChars += mutation.selector.length;
10323
- if (selectorChars * managed.length > MAX_MEDIA_SELECTOR_WORK) return true;
10369
+ measured ??= managedMediaElements(document2, true);
10370
+ work += selectorCheckCost(mutation.selector, measured);
10371
+ if (work > MAX_MEDIA_SELECTOR_WORK) return true;
10324
10372
  }
10325
10373
  }
10326
10374
  for (const selector of selectors) {
10327
10375
  try {
10328
- if (managed.some((element) => element.matches(selector))) return true;
10376
+ if (managed.some((media) => media.element.matches(selector))) return true;
10329
10377
  } catch {
10330
10378
  }
10331
10379
  }
@@ -6962,6 +6962,16 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
6962
6962
  var CompositionExpansionBudget = class {
6963
6963
  bytes = 0;
6964
6964
  mounts = 0;
6965
+ generated = 0;
6966
+ /** `bytes` may be negative when a reserved upper bound is settled to the real size. */
6967
+ chargeGenerated(file, bytes) {
6968
+ this.generated += bytes;
6969
+ if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
6970
+ throw new CompositionTooLargeError(
6971
+ `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.`,
6972
+ { bytes: this.generated, limitBytes: MAX_EXPANDED_COMPOSITION_BYTES, exceeded: "generated" }
6973
+ );
6974
+ }
6965
6975
  charge(file, bytes) {
6966
6976
  this.bytes += bytes;
6967
6977
  this.mounts += 1;
@@ -8148,16 +8158,23 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
8148
8158
  }
8149
8159
  }
8150
8160
  var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
8151
- var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
8152
8161
  function compositionSrcsIn(html) {
8153
8162
  const { document: document2 } = parseHTML5(html);
8163
+ const mounts = [];
8154
8164
  const templated = [];
8155
- const templates = [...document2.querySelectorAll("template")];
8156
- for (let template = templates.pop(); template; template = templates.pop()) {
8157
- templated.push(...mountSrcsUnder(template.content));
8158
- templates.push(...template.content.querySelectorAll("template"));
8165
+ const stack = [...document2.children].reverse().map((el) => [el, false]);
8166
+ for (let next = stack.pop(); next; next = stack.pop()) {
8167
+ const [el, inTemplate] = next;
8168
+ const srcPath = el.getAttribute("data-composition-src");
8169
+ if (srcPath && !isUnresolvedAssetPlaceholder(srcPath)) {
8170
+ (inTemplate ? templated : mounts).push(srcPath);
8171
+ }
8172
+ const childrenInTemplate = inTemplate || el.localName === "template";
8173
+ const children = [...el.children];
8174
+ for (let i = children.length - 1; i >= 0; i -= 1)
8175
+ stack.push([children[i], childrenInTemplate]);
8159
8176
  }
8160
- return { mounts: mountSrcsUnder(document2), templated };
8177
+ return { mounts, templated };
8161
8178
  }
8162
8179
  function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
8163
8180
  if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
@@ -8718,6 +8735,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
8718
8735
  if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
8719
8736
  return compHtml;
8720
8737
  },
8738
+ chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
8721
8739
  parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
8722
8740
  // Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
8723
8741
  // against its own directory, project-root refs stay as authored.
@@ -10292,21 +10310,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
10292
10310
  return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
10293
10311
  }
10294
10312
  var MAX_MEDIA_SELECTOR_WORK = 1e6;
10295
- var SIBLING_COMBINATOR = /[~+]/;
10296
- function managedMediaElements(document2) {
10313
+ var ATTRIBUTE_SELECTOR = /\[\s*[\w-]+\s*(?:[~|^$*]?=\s*(?:"[^"\\]*"|'[^'\\]*'|[\w-]+)\s*(?:[is]\s*)?)?\]/g;
10314
+ var COMPOUND_SELECTORS = /^[\w\s#.*>,@-]+$/;
10315
+ function cheapSelectorShape(selector) {
10316
+ const shape = selector.replace(ATTRIBUTE_SELECTOR, "@").trim();
10317
+ if (!COMPOUND_SELECTORS.test(shape)) return null;
10318
+ const collapsed = shape.replace(/\s+/g, " ").replace(/ ?([>,]) ?/g, "$1");
10319
+ const parts = collapsed.split(",");
10320
+ return parts.every((part) => part !== "" && part.split(" ").length <= 2) ? collapsed : null;
10321
+ }
10322
+ var attributeChars = (element) => Array.from(element.attributes).reduce((sum, a) => sum + a.name.length + a.value.length + 1, 0);
10323
+ function managedMediaElements(document2, measure) {
10297
10324
  const managed = [];
10298
- const pending = [];
10299
- for (const element of Array.from(document2.children)) pending.push({ element, inMedia: false });
10325
+ const pending = Array.from(document2.children, (element) => ({
10326
+ element,
10327
+ inMedia: false,
10328
+ depth: 0,
10329
+ above: 0
10330
+ }));
10300
10331
  for (let next = pending.pop(); next; next = pending.pop()) {
10301
- const name = next.element.tagName.toLowerCase();
10332
+ const { element, depth } = next;
10333
+ const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
10334
+ const name = element.tagName.toLowerCase();
10302
10335
  const isMedia = name === "video" || name === "audio";
10303
- if (isMedia || next.inMedia && name === "source") managed.push(next.element);
10304
- for (const child2 of Array.from(next.element.children)) {
10305
- pending.push({ element: child2, inMedia: next.inMedia || isMedia });
10336
+ if (isMedia || next.inMedia && name === "source") {
10337
+ managed.push({ element, depth, chainAttributeChars });
10338
+ }
10339
+ for (const child2 of Array.from(element.children)) {
10340
+ const inMedia = next.inMedia || isMedia;
10341
+ pending.push({ element: child2, inMedia, depth: depth + 1, above: chainAttributeChars });
10306
10342
  }
10307
10343
  }
10308
10344
  return managed;
10309
10345
  }
10346
+ function selectorCheckCost(selector, measured) {
10347
+ const shape = cheapSelectorShape(selector);
10348
+ if (shape === null) return Infinity;
10349
+ const tests = (shape.match(/[.#@]/g)?.length ?? 0) + shape.split(/[ >,]/).length;
10350
+ let cost = 0;
10351
+ for (const media of measured) {
10352
+ cost += selector.length * (media.depth + 1) + tests * media.chainAttributeChars;
10353
+ if (cost > MAX_MEDIA_SELECTOR_WORK) return cost;
10354
+ }
10355
+ return cost;
10356
+ }
10310
10357
  function hasRuntimeMediaChanges(html) {
10311
10358
  const { document: document2 } = parseHTML6(html);
10312
10359
  const scriptBodies = [...document2.querySelectorAll("script")].map(
@@ -10316,11 +10363,12 @@ function hasRuntimeMediaChanges(html) {
10316
10363
  (script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
10317
10364
  );
10318
10365
  if (insertedMedia) return true;
10319
- const managed = managedMediaElements(document2);
10366
+ const managed = managedMediaElements(document2, false);
10320
10367
  if (managed.length === 0) return false;
10321
- const managedIds = new Set(managed.map((element) => element.getAttribute("id")).filter(Boolean));
10368
+ const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
10322
10369
  const selectors = /* @__PURE__ */ new Set();
10323
- let selectorChars = 0;
10370
+ let work = 0;
10371
+ let measured;
10324
10372
  for (const script of scriptBodies) {
10325
10373
  for (const mutation of extractMediaSrcMutations(script)) {
10326
10374
  const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
@@ -10329,15 +10377,15 @@ function hasRuntimeMediaChanges(html) {
10329
10377
  continue;
10330
10378
  }
10331
10379
  if (selectors.has(mutation.selector)) continue;
10332
- if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
10333
10380
  selectors.add(mutation.selector);
10334
- selectorChars += mutation.selector.length;
10335
- if (selectorChars * managed.length > MAX_MEDIA_SELECTOR_WORK) return true;
10381
+ measured ??= managedMediaElements(document2, true);
10382
+ work += selectorCheckCost(mutation.selector, measured);
10383
+ if (work > MAX_MEDIA_SELECTOR_WORK) return true;
10336
10384
  }
10337
10385
  }
10338
10386
  for (const selector of selectors) {
10339
10387
  try {
10340
- if (managed.some((element) => element.matches(selector))) return true;
10388
+ if (managed.some((media) => media.element.matches(selector))) return true;
10341
10389
  } catch {
10342
10390
  }
10343
10391
  }
@@ -9,10 +9,13 @@ export declare const MAX_COMPOSITION_HTML_BYTES: number;
9
9
  * above, but a few small files that mount each other many times assemble a page far larger.
10
10
  */
11
11
  export declare const MAX_EXPANDED_COMPOSITION_BYTES: number;
12
- /** Adds up every mount a render inlines and throws once the total passes either limit. */
12
+ /** Adds up every mount a render inlines, and what it generates for them, and throws past a limit. */
13
13
  export declare class CompositionExpansionBudget {
14
14
  private bytes;
15
15
  private mounts;
16
+ private generated;
17
+ /** `bytes` may be negative when a reserved upper bound is settled to the real size. */
18
+ chargeGenerated(file: string, bytes: number): void;
16
19
  charge(file: string, bytes: number): void;
17
20
  }
18
21
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.63",
3
+ "version": "0.9.65",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,11 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/engine": "0.9.63",
39
- "@hyperframes/core": "0.9.63",
40
- "@hyperframes/lint": "0.9.63",
41
- "@hyperframes/studio-server": "0.9.63",
42
- "@hyperframes/parsers": "0.9.63"
38
+ "@hyperframes/core": "0.9.65",
39
+ "@hyperframes/lint": "0.9.65",
40
+ "@hyperframes/studio-server": "0.9.65",
41
+ "@hyperframes/engine": "0.9.65",
42
+ "@hyperframes/parsers": "0.9.65"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@types/node": "^25.0.10",
@@ -48,7 +48,7 @@
48
48
  "tsx": "^4.21.0",
49
49
  "typescript": "^5.7.2",
50
50
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.63"
51
+ "@hyperframes/aws-lambda": "0.9.65"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=22"