@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/distributed.js +69 -21
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +69 -21
- package/dist/public-server.js +69 -21
- package/dist/services/compositionSizeLimit.d.ts +4 -1
- package/package.json +7 -7
package/dist/distributed.js
CHANGED
|
@@ -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;
|
|
@@ -3661,16 +3671,23 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
|
|
|
3661
3671
|
}
|
|
3662
3672
|
}
|
|
3663
3673
|
var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder2(projectDir, filePath, isStudioPrivatePath2);
|
|
3664
|
-
var mountSrcsUnder = (root) => [...root.querySelectorAll("[data-composition-src]")].map((el) => el.getAttribute("data-composition-src")).filter((srcPath) => !!srcPath && !isUnresolvedAssetPlaceholder(srcPath));
|
|
3665
3674
|
function compositionSrcsIn(html) {
|
|
3666
3675
|
const { document: document2 } = parseHTML5(html);
|
|
3676
|
+
const mounts = [];
|
|
3667
3677
|
const templated = [];
|
|
3668
|
-
const
|
|
3669
|
-
for (let
|
|
3670
|
-
|
|
3671
|
-
|
|
3678
|
+
const stack = [...document2.children].reverse().map((el) => [el, false]);
|
|
3679
|
+
for (let next = stack.pop(); next; next = stack.pop()) {
|
|
3680
|
+
const [el, inTemplate] = next;
|
|
3681
|
+
const srcPath = el.getAttribute("data-composition-src");
|
|
3682
|
+
if (srcPath && !isUnresolvedAssetPlaceholder(srcPath)) {
|
|
3683
|
+
(inTemplate ? templated : mounts).push(srcPath);
|
|
3684
|
+
}
|
|
3685
|
+
const childrenInTemplate = inTemplate || el.localName === "template";
|
|
3686
|
+
const children = [...el.children];
|
|
3687
|
+
for (let i = children.length - 1; i >= 0; i -= 1)
|
|
3688
|
+
stack.push([children[i], childrenInTemplate]);
|
|
3672
3689
|
}
|
|
3673
|
-
return { mounts
|
|
3690
|
+
return { mounts, templated };
|
|
3674
3691
|
}
|
|
3675
3692
|
function compositionPathProblem(projectDir, filePath, assetRoot, outsideFiles) {
|
|
3676
3693
|
if (outsideAssetRefusal(projectDir, filePath) === "blocklisted") {
|
|
@@ -4231,6 +4248,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
4231
4248
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
4232
4249
|
return compHtml;
|
|
4233
4250
|
},
|
|
4251
|
+
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
4234
4252
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
4235
4253
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
4236
4254
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -5805,21 +5823,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
|
|
|
5805
5823
|
return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
|
|
5806
5824
|
}
|
|
5807
5825
|
var MAX_MEDIA_SELECTOR_WORK = 1e6;
|
|
5808
|
-
var
|
|
5809
|
-
|
|
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) {
|
|
5810
5837
|
const managed = [];
|
|
5811
|
-
const pending =
|
|
5812
|
-
|
|
5838
|
+
const pending = Array.from(document2.children, (element) => ({
|
|
5839
|
+
element,
|
|
5840
|
+
inMedia: false,
|
|
5841
|
+
depth: 0,
|
|
5842
|
+
above: 0
|
|
5843
|
+
}));
|
|
5813
5844
|
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
5814
|
-
const
|
|
5845
|
+
const { element, depth } = next;
|
|
5846
|
+
const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
|
|
5847
|
+
const name = element.tagName.toLowerCase();
|
|
5815
5848
|
const isMedia = name === "video" || name === "audio";
|
|
5816
|
-
if (isMedia || next.inMedia && name === "source")
|
|
5817
|
-
|
|
5818
|
-
|
|
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 });
|
|
5819
5855
|
}
|
|
5820
5856
|
}
|
|
5821
5857
|
return managed;
|
|
5822
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
|
+
}
|
|
5823
5870
|
function hasRuntimeMediaChanges(html) {
|
|
5824
5871
|
const { document: document2 } = parseHTML6(html);
|
|
5825
5872
|
const scriptBodies = [...document2.querySelectorAll("script")].map(
|
|
@@ -5829,11 +5876,12 @@ function hasRuntimeMediaChanges(html) {
|
|
|
5829
5876
|
(script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
|
|
5830
5877
|
);
|
|
5831
5878
|
if (insertedMedia) return true;
|
|
5832
|
-
const managed = managedMediaElements(document2);
|
|
5879
|
+
const managed = managedMediaElements(document2, false);
|
|
5833
5880
|
if (managed.length === 0) return false;
|
|
5834
|
-
const managedIds = new Set(managed.map((
|
|
5881
|
+
const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
|
|
5835
5882
|
const selectors = /* @__PURE__ */ new Set();
|
|
5836
|
-
let
|
|
5883
|
+
let work = 0;
|
|
5884
|
+
let measured;
|
|
5837
5885
|
for (const script of scriptBodies) {
|
|
5838
5886
|
for (const mutation of extractMediaSrcMutations(script)) {
|
|
5839
5887
|
const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
|
|
@@ -5842,15 +5890,15 @@ function hasRuntimeMediaChanges(html) {
|
|
|
5842
5890
|
continue;
|
|
5843
5891
|
}
|
|
5844
5892
|
if (selectors.has(mutation.selector)) continue;
|
|
5845
|
-
if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
|
|
5846
5893
|
selectors.add(mutation.selector);
|
|
5847
|
-
|
|
5848
|
-
|
|
5894
|
+
measured ??= managedMediaElements(document2, true);
|
|
5895
|
+
work += selectorCheckCost(mutation.selector, measured);
|
|
5896
|
+
if (work > MAX_MEDIA_SELECTOR_WORK) return true;
|
|
5849
5897
|
}
|
|
5850
5898
|
}
|
|
5851
5899
|
for (const selector of selectors) {
|
|
5852
5900
|
try {
|
|
5853
|
-
if (managed.some((
|
|
5901
|
+
if (managed.some((media) => media.element.matches(selector))) return true;
|
|
5854
5902
|
} catch {
|
|
5855
5903
|
}
|
|
5856
5904
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.1.0",
|
|
3
3
|
"buildId": "dev",
|
|
4
|
-
"sha256": "
|
|
4
|
+
"sha256": "26bc2c53086737e056afd7751aeee6ff6f019d5c4a9e820a7d055c46b5737c73",
|
|
5
5
|
"artifacts": {
|
|
6
6
|
"iife": "hyperframe.runtime.iife.js",
|
|
7
7
|
"esm": "hyperframe.runtime.mjs"
|