@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.
- package/dist/distributed.js +56 -15
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +56 -15
- package/dist/public-server.js +56 -15
- package/dist/services/compositionSizeLimit.d.ts +4 -1
- package/package.json +7 -7
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;
|
|
@@ -8710,6 +8720,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8710
8720
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
8711
8721
|
return compHtml;
|
|
8712
8722
|
},
|
|
8723
|
+
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
8713
8724
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
8714
8725
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
8715
8726
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -10287,21 +10298,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
|
|
|
10287
10298
|
return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
|
|
10288
10299
|
}
|
|
10289
10300
|
var MAX_MEDIA_SELECTOR_WORK = 1e6;
|
|
10290
|
-
var
|
|
10291
|
-
|
|
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) {
|
|
10292
10312
|
const managed = [];
|
|
10293
|
-
const pending =
|
|
10294
|
-
|
|
10313
|
+
const pending = Array.from(document2.children, (element) => ({
|
|
10314
|
+
element,
|
|
10315
|
+
inMedia: false,
|
|
10316
|
+
depth: 0,
|
|
10317
|
+
above: 0
|
|
10318
|
+
}));
|
|
10295
10319
|
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
10296
|
-
const
|
|
10320
|
+
const { element, depth } = next;
|
|
10321
|
+
const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
|
|
10322
|
+
const name = element.tagName.toLowerCase();
|
|
10297
10323
|
const isMedia = name === "video" || name === "audio";
|
|
10298
|
-
if (isMedia || next.inMedia && name === "source")
|
|
10299
|
-
|
|
10300
|
-
|
|
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 });
|
|
10301
10330
|
}
|
|
10302
10331
|
}
|
|
10303
10332
|
return managed;
|
|
10304
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
|
+
}
|
|
10305
10345
|
function hasRuntimeMediaChanges(html) {
|
|
10306
10346
|
const { document: document2 } = parseHTML6(html);
|
|
10307
10347
|
const scriptBodies = [...document2.querySelectorAll("script")].map(
|
|
@@ -10311,11 +10351,12 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10311
10351
|
(script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
|
|
10312
10352
|
);
|
|
10313
10353
|
if (insertedMedia) return true;
|
|
10314
|
-
const managed = managedMediaElements(document2);
|
|
10354
|
+
const managed = managedMediaElements(document2, false);
|
|
10315
10355
|
if (managed.length === 0) return false;
|
|
10316
|
-
const managedIds = new Set(managed.map((
|
|
10356
|
+
const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
|
|
10317
10357
|
const selectors = /* @__PURE__ */ new Set();
|
|
10318
|
-
let
|
|
10358
|
+
let work = 0;
|
|
10359
|
+
let measured;
|
|
10319
10360
|
for (const script of scriptBodies) {
|
|
10320
10361
|
for (const mutation of extractMediaSrcMutations(script)) {
|
|
10321
10362
|
const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
|
|
@@ -10324,15 +10365,15 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10324
10365
|
continue;
|
|
10325
10366
|
}
|
|
10326
10367
|
if (selectors.has(mutation.selector)) continue;
|
|
10327
|
-
if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
|
|
10328
10368
|
selectors.add(mutation.selector);
|
|
10329
|
-
|
|
10330
|
-
|
|
10369
|
+
measured ??= managedMediaElements(document2, true);
|
|
10370
|
+
work += selectorCheckCost(mutation.selector, measured);
|
|
10371
|
+
if (work > MAX_MEDIA_SELECTOR_WORK) return true;
|
|
10331
10372
|
}
|
|
10332
10373
|
}
|
|
10333
10374
|
for (const selector of selectors) {
|
|
10334
10375
|
try {
|
|
10335
|
-
if (managed.some((
|
|
10376
|
+
if (managed.some((media) => media.element.matches(selector))) return true;
|
|
10336
10377
|
} catch {
|
|
10337
10378
|
}
|
|
10338
10379
|
}
|
package/dist/public-server.js
CHANGED
|
@@ -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;
|
|
@@ -8725,6 +8735,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8725
8735
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
8726
8736
|
return compHtml;
|
|
8727
8737
|
},
|
|
8738
|
+
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
8728
8739
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
8729
8740
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
8730
8741
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -10299,21 +10310,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
|
|
|
10299
10310
|
return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
|
|
10300
10311
|
}
|
|
10301
10312
|
var MAX_MEDIA_SELECTOR_WORK = 1e6;
|
|
10302
|
-
var
|
|
10303
|
-
|
|
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) {
|
|
10304
10324
|
const managed = [];
|
|
10305
|
-
const pending =
|
|
10306
|
-
|
|
10325
|
+
const pending = Array.from(document2.children, (element) => ({
|
|
10326
|
+
element,
|
|
10327
|
+
inMedia: false,
|
|
10328
|
+
depth: 0,
|
|
10329
|
+
above: 0
|
|
10330
|
+
}));
|
|
10307
10331
|
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
10308
|
-
const
|
|
10332
|
+
const { element, depth } = next;
|
|
10333
|
+
const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
|
|
10334
|
+
const name = element.tagName.toLowerCase();
|
|
10309
10335
|
const isMedia = name === "video" || name === "audio";
|
|
10310
|
-
if (isMedia || next.inMedia && name === "source")
|
|
10311
|
-
|
|
10312
|
-
|
|
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 });
|
|
10313
10342
|
}
|
|
10314
10343
|
}
|
|
10315
10344
|
return managed;
|
|
10316
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
|
+
}
|
|
10317
10357
|
function hasRuntimeMediaChanges(html) {
|
|
10318
10358
|
const { document: document2 } = parseHTML6(html);
|
|
10319
10359
|
const scriptBodies = [...document2.querySelectorAll("script")].map(
|
|
@@ -10323,11 +10363,12 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10323
10363
|
(script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
|
|
10324
10364
|
);
|
|
10325
10365
|
if (insertedMedia) return true;
|
|
10326
|
-
const managed = managedMediaElements(document2);
|
|
10366
|
+
const managed = managedMediaElements(document2, false);
|
|
10327
10367
|
if (managed.length === 0) return false;
|
|
10328
|
-
const managedIds = new Set(managed.map((
|
|
10368
|
+
const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
|
|
10329
10369
|
const selectors = /* @__PURE__ */ new Set();
|
|
10330
|
-
let
|
|
10370
|
+
let work = 0;
|
|
10371
|
+
let measured;
|
|
10331
10372
|
for (const script of scriptBodies) {
|
|
10332
10373
|
for (const mutation of extractMediaSrcMutations(script)) {
|
|
10333
10374
|
const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
|
|
@@ -10336,15 +10377,15 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10336
10377
|
continue;
|
|
10337
10378
|
}
|
|
10338
10379
|
if (selectors.has(mutation.selector)) continue;
|
|
10339
|
-
if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
|
|
10340
10380
|
selectors.add(mutation.selector);
|
|
10341
|
-
|
|
10342
|
-
|
|
10381
|
+
measured ??= managedMediaElements(document2, true);
|
|
10382
|
+
work += selectorCheckCost(mutation.selector, measured);
|
|
10383
|
+
if (work > MAX_MEDIA_SELECTOR_WORK) return true;
|
|
10343
10384
|
}
|
|
10344
10385
|
}
|
|
10345
10386
|
for (const selector of selectors) {
|
|
10346
10387
|
try {
|
|
10347
|
-
if (managed.some((
|
|
10388
|
+
if (managed.some((media) => media.element.matches(selector))) return true;
|
|
10348
10389
|
} catch {
|
|
10349
10390
|
}
|
|
10350
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
|
|
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.
|
|
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/
|
|
39
|
-
"@hyperframes/lint": "0.9.
|
|
40
|
-
"@hyperframes/
|
|
41
|
-
"@hyperframes/
|
|
42
|
-
"@hyperframes/
|
|
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.
|
|
51
|
+
"@hyperframes/aws-lambda": "0.9.65"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|