@hyperframes/producer 0.9.64 → 0.9.66
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 +190 -79
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +72 -71
- package/dist/index.js +190 -79
- package/dist/public-server.js +190 -79
- package/dist/services/compositionSizeLimit.d.ts +5 -1
- package/dist/services/htmlCompiler.d.ts +1 -6
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -6959,9 +6959,35 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
|
6959
6959
|
`Composition file "${file}" is ${megabytes(bytes)}, over the ${megabytes(MAX_COMPOSITION_HTML_BYTES)} limit for one composition HTML file. Keep large data such as images, fonts and JSON in separate asset files and reference them by path instead of inlining them.`,
|
|
6960
6960
|
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
6961
6961
|
);
|
|
6962
|
+
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
6963
|
+
function generatedTooLarge(file, bytes) {
|
|
6964
|
+
if (file === "composition variables") {
|
|
6965
|
+
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
6966
|
+
}
|
|
6967
|
+
if (file === "variable media sources") {
|
|
6968
|
+
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
6969
|
+
}
|
|
6970
|
+
return `Scripts, styles and rebased asset paths generated for compositions, ending at "${file}", add up to ${megabytes(bytes)}. 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.`;
|
|
6971
|
+
}
|
|
6962
6972
|
var CompositionExpansionBudget = class {
|
|
6963
6973
|
bytes = 0;
|
|
6964
6974
|
mounts = 0;
|
|
6975
|
+
generated = 0;
|
|
6976
|
+
/** `bytes` may be negative when a reserved upper bound is settled to the real size. */
|
|
6977
|
+
chargeGenerated(file, bytes) {
|
|
6978
|
+
this.generated += bytes;
|
|
6979
|
+
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
6980
|
+
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
6981
|
+
bytes: this.generated,
|
|
6982
|
+
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
6983
|
+
exceeded: "generated"
|
|
6984
|
+
});
|
|
6985
|
+
}
|
|
6986
|
+
chargeGeneratedIfItFits(bytes) {
|
|
6987
|
+
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
6988
|
+
this.generated += bytes;
|
|
6989
|
+
return true;
|
|
6990
|
+
}
|
|
6965
6991
|
charge(file, bytes) {
|
|
6966
6992
|
this.bytes += bytes;
|
|
6967
6993
|
this.mounts += 1;
|
|
@@ -8672,7 +8698,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
8672
8698
|
}
|
|
8673
8699
|
return document2.toString();
|
|
8674
8700
|
}
|
|
8675
|
-
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles) {
|
|
8701
|
+
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles, budget) {
|
|
8676
8702
|
const { document: document2 } = parseHTML5(html);
|
|
8677
8703
|
const head = document2.querySelector("head");
|
|
8678
8704
|
const body = document2.querySelector("body");
|
|
@@ -8681,11 +8707,11 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8681
8707
|
const emitted = emitRootCompositionVariableStyles(
|
|
8682
8708
|
document2,
|
|
8683
8709
|
{},
|
|
8684
|
-
variableOverrides
|
|
8710
|
+
variableOverrides,
|
|
8711
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
8685
8712
|
);
|
|
8686
8713
|
return { html: emitted ? document2.toString() : html, variablesByComp: {} };
|
|
8687
8714
|
}
|
|
8688
|
-
const budget = new CompositionExpansionBudget();
|
|
8689
8715
|
const readOnce = /* @__PURE__ */ new Map();
|
|
8690
8716
|
const readMountHtml = (srcPath) => {
|
|
8691
8717
|
const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
@@ -8720,11 +8746,16 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8720
8746
|
hostIdentityMap: hostIdentityByElement,
|
|
8721
8747
|
readVariableDefaults: readDeclaredDefaults,
|
|
8722
8748
|
parseHostVariables: parseHostVariableValues,
|
|
8749
|
+
resolveFilePath: (srcPath) => {
|
|
8750
|
+
const file = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
8751
|
+
return file && relative2(projectDir, file).split(sep3).join("/");
|
|
8752
|
+
},
|
|
8723
8753
|
resolveHtml: (srcPath) => {
|
|
8724
8754
|
const compHtml = resolveMountHtml(srcPath);
|
|
8725
8755
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
8726
8756
|
return compHtml;
|
|
8727
8757
|
},
|
|
8758
|
+
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
8728
8759
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
8729
8760
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
8730
8761
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -8809,7 +8840,8 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8809
8840
|
emitRootCompositionVariableStyles(
|
|
8810
8841
|
document2,
|
|
8811
8842
|
result.variablesByComp,
|
|
8812
|
-
variableOverrides
|
|
8843
|
+
variableOverrides,
|
|
8844
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
8813
8845
|
);
|
|
8814
8846
|
assignMediaRenderIds(document2);
|
|
8815
8847
|
return { html: document2.toString(), variablesByComp: result.variablesByComp };
|
|
@@ -9231,10 +9263,6 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
9231
9263
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9232
9264
|
);
|
|
9233
9265
|
}
|
|
9234
|
-
function urlOccurrenceRe(localPath) {
|
|
9235
|
-
const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
9236
|
-
return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
|
|
9237
|
-
}
|
|
9238
9266
|
var MAX_LOCAL_FONT_DATA_URI_BYTES = 5 * 1024 * 1024;
|
|
9239
9267
|
async function readLocalFont(absPath) {
|
|
9240
9268
|
const chunks = [];
|
|
@@ -9249,59 +9277,83 @@ async function readLocalFont(absPath) {
|
|
|
9249
9277
|
}
|
|
9250
9278
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
9251
9279
|
}
|
|
9252
|
-
async function
|
|
9253
|
-
const
|
|
9254
|
-
|
|
9255
|
-
|
|
9280
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
9281
|
+
const absPath = localPath.startsWith("/") ? localPath : resolve7(projectDir, localPath);
|
|
9282
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) return void 0;
|
|
9283
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
9284
|
+
return void 0;
|
|
9285
|
+
}
|
|
9286
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9287
|
+
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
9288
|
+
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9289
|
+
try {
|
|
9290
|
+
const font = await readLocalFont(absPath);
|
|
9291
|
+
if (font.kind === "file-backed") {
|
|
9292
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
9293
|
+
defaultLogger.debug(
|
|
9294
|
+
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
9295
|
+
);
|
|
9296
|
+
return void 0;
|
|
9297
|
+
}
|
|
9298
|
+
const { fontToDataUri } = await import("@hyperframes/core/fonts/embed");
|
|
9299
|
+
const dataUri = await fontToDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
9300
|
+
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
9301
|
+
defaultLogger.debug(
|
|
9302
|
+
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
9303
|
+
);
|
|
9304
|
+
return dataUri;
|
|
9305
|
+
} catch (error) {
|
|
9306
|
+
defaultLogger.warn(
|
|
9307
|
+
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
9308
|
+
);
|
|
9309
|
+
return void 0;
|
|
9310
|
+
}
|
|
9311
|
+
}
|
|
9312
|
+
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
9313
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
9314
|
+
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
9256
9315
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
9257
|
-
const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
|
|
9258
9316
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
9259
9317
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
9260
|
-
const
|
|
9261
|
-
for (const { parts } of localFontFaceUrlMatches(block)) {
|
|
9318
|
+
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
9262
9319
|
const localPath = parts[1];
|
|
9263
|
-
if (!localPath ||
|
|
9264
|
-
|
|
9265
|
-
|
|
9266
|
-
|
|
9267
|
-
|
|
9268
|
-
continue;
|
|
9269
|
-
}
|
|
9270
|
-
if (isPrivateCompositionFile(projectDir, absPath)) continue;
|
|
9271
|
-
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9272
|
-
try {
|
|
9273
|
-
if (fileBackedAbsolutePaths.has(absPath)) {
|
|
9274
|
-
embeddedPaths.add(localPath);
|
|
9275
|
-
continue;
|
|
9276
|
-
}
|
|
9277
|
-
let dataUri = dataUriByAbsolutePath.get(absPath);
|
|
9278
|
-
if (!dataUri) {
|
|
9279
|
-
const font = await readLocalFont(absPath);
|
|
9280
|
-
if (font.kind === "file-backed") {
|
|
9281
|
-
fileBackedAbsolutePaths.add(absPath);
|
|
9282
|
-
defaultLogger.debug(
|
|
9283
|
-
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
9284
|
-
);
|
|
9285
|
-
embeddedPaths.add(localPath);
|
|
9286
|
-
continue;
|
|
9287
|
-
}
|
|
9288
|
-
dataUri = await toDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
9289
|
-
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
9290
|
-
defaultLogger.debug(
|
|
9291
|
-
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
9292
|
-
);
|
|
9293
|
-
}
|
|
9294
|
-
result = result.replace(urlOccurrenceRe(localPath), `url("${dataUri}")`);
|
|
9295
|
-
embeddedPaths.add(localPath);
|
|
9296
|
-
} catch (error) {
|
|
9297
|
-
defaultLogger.warn(
|
|
9298
|
-
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
9299
|
-
);
|
|
9300
|
-
}
|
|
9320
|
+
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
9321
|
+
dataUriByPath.set(
|
|
9322
|
+
localPath,
|
|
9323
|
+
await localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log)
|
|
9324
|
+
);
|
|
9301
9325
|
}
|
|
9302
9326
|
}
|
|
9303
9327
|
}
|
|
9304
|
-
return
|
|
9328
|
+
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
9329
|
+
let warned = false;
|
|
9330
|
+
const embed = (source, localPath) => {
|
|
9331
|
+
const dataUri = dataUriByPath.get(localPath);
|
|
9332
|
+
if (!dataUri) return source;
|
|
9333
|
+
const inlined = `url("${dataUri}")`;
|
|
9334
|
+
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
9335
|
+
if (!warned) {
|
|
9336
|
+
warned = true;
|
|
9337
|
+
log.warn(
|
|
9338
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9339
|
+
);
|
|
9340
|
+
}
|
|
9341
|
+
return source;
|
|
9342
|
+
};
|
|
9343
|
+
return replaceMatches(
|
|
9344
|
+
html,
|
|
9345
|
+
styleBlockMatches(html),
|
|
9346
|
+
(style, css) => replaceInner(
|
|
9347
|
+
style,
|
|
9348
|
+
css,
|
|
9349
|
+
"</style>".length,
|
|
9350
|
+
replaceMatches(
|
|
9351
|
+
css,
|
|
9352
|
+
fontFaceBlockMatches(css),
|
|
9353
|
+
(face, body) => replaceInner(face, body, 1, replaceMatches(body, localFontFaceUrlMatches(body), embed))
|
|
9354
|
+
)
|
|
9355
|
+
)
|
|
9356
|
+
);
|
|
9305
9357
|
}
|
|
9306
9358
|
function renderGsapDist() {
|
|
9307
9359
|
try {
|
|
@@ -9327,32 +9379,42 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
|
9327
9379
|
return `${prefix}${gsapDist}${file}${suffix}`;
|
|
9328
9380
|
});
|
|
9329
9381
|
}
|
|
9330
|
-
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
9382
|
+
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath, budget) {
|
|
9331
9383
|
if (!isPathInside(htmlPath, projectDir)) return html;
|
|
9332
9384
|
const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
|
|
9333
9385
|
if (!entryPath.includes("/")) return html;
|
|
9334
9386
|
const { document: document2 } = parseHTML5(html);
|
|
9335
9387
|
const assetExists = projectAssetExists(projectDir);
|
|
9388
|
+
const charge = (bytes) => budget.chargeGenerated(entryPath, bytes);
|
|
9336
9389
|
rewriteAssetPaths(
|
|
9337
9390
|
document2.querySelectorAll("[src], [href], [srcset]"),
|
|
9338
9391
|
entryPath,
|
|
9339
9392
|
(el, attr) => el.getAttribute(attr),
|
|
9340
9393
|
(el, attr, value) => el.setAttribute(attr, value),
|
|
9341
|
-
assetExists
|
|
9394
|
+
assetExists,
|
|
9395
|
+
charge
|
|
9342
9396
|
);
|
|
9343
9397
|
rewriteInlineStyleAssetUrls(
|
|
9344
9398
|
document2.querySelectorAll("[style]"),
|
|
9345
9399
|
entryPath,
|
|
9346
9400
|
(el) => el.getAttribute("style"),
|
|
9347
9401
|
(el, value) => el.setAttribute("style", value),
|
|
9348
|
-
assetExists
|
|
9402
|
+
assetExists,
|
|
9403
|
+
charge
|
|
9349
9404
|
);
|
|
9350
9405
|
for (const style of document2.querySelectorAll("style")) {
|
|
9351
|
-
style.textContent = rewriteCssAssetUrls(
|
|
9406
|
+
style.textContent = rewriteCssAssetUrls(
|
|
9407
|
+
style.textContent || "",
|
|
9408
|
+
entryPath,
|
|
9409
|
+
assetExists,
|
|
9410
|
+
charge
|
|
9411
|
+
);
|
|
9352
9412
|
}
|
|
9353
9413
|
return document2.toString();
|
|
9354
9414
|
}
|
|
9355
|
-
|
|
9415
|
+
var MAX_VARIABLE_MEDIA_SRC_BYTES = 8 * 1024;
|
|
9416
|
+
var MEDIA_SRC_CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
9417
|
+
function bindVariableMediaSources(html, variables, budget, log) {
|
|
9356
9418
|
if (!html.includes("data-var-src")) return html;
|
|
9357
9419
|
const { document: document2 } = parseHTML5(html);
|
|
9358
9420
|
const declared = {};
|
|
@@ -9363,8 +9425,17 @@ function bindVariableMediaSources(html, variables) {
|
|
|
9363
9425
|
let changed = false;
|
|
9364
9426
|
for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
|
|
9365
9427
|
if (el.closest("[data-variable-values]")) continue;
|
|
9366
|
-
const
|
|
9367
|
-
if (
|
|
9428
|
+
const bound = boundMediaSrc(el, values);
|
|
9429
|
+
if (bound === null) continue;
|
|
9430
|
+
const src = bound.trim();
|
|
9431
|
+
if (src.length > MAX_VARIABLE_MEDIA_SRC_BYTES || MEDIA_SRC_CONTROL_CHARS.test(src)) {
|
|
9432
|
+
log?.warn("[Compiler] Refused a variable media source that cannot be a URL", {
|
|
9433
|
+
length: src.length
|
|
9434
|
+
});
|
|
9435
|
+
continue;
|
|
9436
|
+
}
|
|
9437
|
+
if (el.getAttribute("src") === src) continue;
|
|
9438
|
+
budget.chargeGenerated("variable media sources", src.length);
|
|
9368
9439
|
el.setAttribute("src", src);
|
|
9369
9440
|
changed = true;
|
|
9370
9441
|
}
|
|
@@ -9384,10 +9455,18 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9384
9455
|
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
|
|
9385
9456
|
}
|
|
9386
9457
|
assertCompositionFileSize(htmlPath, basename5(htmlPath));
|
|
9387
|
-
const
|
|
9458
|
+
const budget = new CompositionExpansionBudget();
|
|
9459
|
+
const entryHtml = rebaseDirectEntryAssetPaths(
|
|
9460
|
+
readTextFile(htmlPath),
|
|
9461
|
+
projectDir,
|
|
9462
|
+
htmlPath,
|
|
9463
|
+
budget
|
|
9464
|
+
);
|
|
9388
9465
|
const rawHtml = bindVariableMediaSources(
|
|
9389
9466
|
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
9390
|
-
options.variables ?? {}
|
|
9467
|
+
options.variables ?? {},
|
|
9468
|
+
budget,
|
|
9469
|
+
options.log
|
|
9391
9470
|
);
|
|
9392
9471
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
9393
9472
|
const probes = /* @__PURE__ */ new Map();
|
|
@@ -9418,7 +9497,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9418
9497
|
projectDir,
|
|
9419
9498
|
options.variables ?? {},
|
|
9420
9499
|
assetRoot,
|
|
9421
|
-
outsideFiles
|
|
9500
|
+
outsideFiles,
|
|
9501
|
+
budget
|
|
9422
9502
|
);
|
|
9423
9503
|
const sanitizedHtml = stripPreloadNone(inlinedHtml);
|
|
9424
9504
|
const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
|
|
@@ -9497,6 +9577,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9497
9577
|
htmlWithPreparedGifs,
|
|
9498
9578
|
projectDir,
|
|
9499
9579
|
assetRoot,
|
|
9580
|
+
budget,
|
|
9500
9581
|
options.log
|
|
9501
9582
|
);
|
|
9502
9583
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
@@ -10299,21 +10380,50 @@ function reconcileBrowserMediaEnd(existingEnd, projectedEnd, sourceChanged, dura
|
|
|
10299
10380
|
return existingEnd <= 0 ? projectedEnd : Math.min(existingEnd, projectedEnd);
|
|
10300
10381
|
}
|
|
10301
10382
|
var MAX_MEDIA_SELECTOR_WORK = 1e6;
|
|
10302
|
-
var
|
|
10303
|
-
|
|
10383
|
+
var ATTRIBUTE_SELECTOR = /\[\s*[\w-]+\s*(?:[~|^$*]?=\s*(?:"[^"\\]*"|'[^'\\]*'|[\w-]+)\s*(?:[is]\s*)?)?\]/g;
|
|
10384
|
+
var COMPOUND_SELECTORS = /^[\w\s#.*>,@-]+$/;
|
|
10385
|
+
function cheapSelectorShape(selector) {
|
|
10386
|
+
const shape = selector.replace(ATTRIBUTE_SELECTOR, "@").trim();
|
|
10387
|
+
if (!COMPOUND_SELECTORS.test(shape)) return null;
|
|
10388
|
+
const collapsed = shape.replace(/\s+/g, " ").replace(/ ?([>,]) ?/g, "$1");
|
|
10389
|
+
const parts = collapsed.split(",");
|
|
10390
|
+
return parts.every((part) => part !== "" && part.split(" ").length <= 2) ? collapsed : null;
|
|
10391
|
+
}
|
|
10392
|
+
var attributeChars = (element) => Array.from(element.attributes).reduce((sum, a) => sum + a.name.length + a.value.length + 1, 0);
|
|
10393
|
+
function managedMediaElements(document2, measure) {
|
|
10304
10394
|
const managed = [];
|
|
10305
|
-
const pending =
|
|
10306
|
-
|
|
10395
|
+
const pending = Array.from(document2.children, (element) => ({
|
|
10396
|
+
element,
|
|
10397
|
+
inMedia: false,
|
|
10398
|
+
depth: 0,
|
|
10399
|
+
above: 0
|
|
10400
|
+
}));
|
|
10307
10401
|
for (let next = pending.pop(); next; next = pending.pop()) {
|
|
10308
|
-
const
|
|
10402
|
+
const { element, depth } = next;
|
|
10403
|
+
const chainAttributeChars = measure ? next.above + attributeChars(element) : 0;
|
|
10404
|
+
const name = element.tagName.toLowerCase();
|
|
10309
10405
|
const isMedia = name === "video" || name === "audio";
|
|
10310
|
-
if (isMedia || next.inMedia && name === "source")
|
|
10311
|
-
|
|
10312
|
-
|
|
10406
|
+
if (isMedia || next.inMedia && name === "source") {
|
|
10407
|
+
managed.push({ element, depth, chainAttributeChars });
|
|
10408
|
+
}
|
|
10409
|
+
for (const child2 of Array.from(element.children)) {
|
|
10410
|
+
const inMedia = next.inMedia || isMedia;
|
|
10411
|
+
pending.push({ element: child2, inMedia, depth: depth + 1, above: chainAttributeChars });
|
|
10313
10412
|
}
|
|
10314
10413
|
}
|
|
10315
10414
|
return managed;
|
|
10316
10415
|
}
|
|
10416
|
+
function selectorCheckCost(selector, measured) {
|
|
10417
|
+
const shape = cheapSelectorShape(selector);
|
|
10418
|
+
if (shape === null) return Infinity;
|
|
10419
|
+
const tests = (shape.match(/[.#@]/g)?.length ?? 0) + shape.split(/[ >,]/).length;
|
|
10420
|
+
let cost = 0;
|
|
10421
|
+
for (const media of measured) {
|
|
10422
|
+
cost += selector.length * (media.depth + 1) + tests * media.chainAttributeChars;
|
|
10423
|
+
if (cost > MAX_MEDIA_SELECTOR_WORK) return cost;
|
|
10424
|
+
}
|
|
10425
|
+
return cost;
|
|
10426
|
+
}
|
|
10317
10427
|
function hasRuntimeMediaChanges(html) {
|
|
10318
10428
|
const { document: document2 } = parseHTML6(html);
|
|
10319
10429
|
const scriptBodies = [...document2.querySelectorAll("script")].map(
|
|
@@ -10323,11 +10433,12 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10323
10433
|
(script) => /\bcreateElement\s*\(\s*["'`](?:video|audio)["'`]\s*\)/i.test(script) || /\bnew\s+(?:Audio|Video)\s*\(/i.test(script) || hasClosedMediaTag(script)
|
|
10324
10434
|
);
|
|
10325
10435
|
if (insertedMedia) return true;
|
|
10326
|
-
const managed = managedMediaElements(document2);
|
|
10436
|
+
const managed = managedMediaElements(document2, false);
|
|
10327
10437
|
if (managed.length === 0) return false;
|
|
10328
|
-
const managedIds = new Set(managed.map((
|
|
10438
|
+
const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
|
|
10329
10439
|
const selectors = /* @__PURE__ */ new Set();
|
|
10330
|
-
let
|
|
10440
|
+
let work = 0;
|
|
10441
|
+
let measured;
|
|
10331
10442
|
for (const script of scriptBodies) {
|
|
10332
10443
|
for (const mutation of extractMediaSrcMutations(script)) {
|
|
10333
10444
|
const id = /^#[A-Za-z_][\w-]*$/.test(mutation.selector) ? mutation.selector.slice(1) : null;
|
|
@@ -10336,15 +10447,15 @@ function hasRuntimeMediaChanges(html) {
|
|
|
10336
10447
|
continue;
|
|
10337
10448
|
}
|
|
10338
10449
|
if (selectors.has(mutation.selector)) continue;
|
|
10339
|
-
if (SIBLING_COMBINATOR.test(mutation.selector)) return true;
|
|
10340
10450
|
selectors.add(mutation.selector);
|
|
10341
|
-
|
|
10342
|
-
|
|
10451
|
+
measured ??= managedMediaElements(document2, true);
|
|
10452
|
+
work += selectorCheckCost(mutation.selector, measured);
|
|
10453
|
+
if (work > MAX_MEDIA_SELECTOR_WORK) return true;
|
|
10343
10454
|
}
|
|
10344
10455
|
}
|
|
10345
10456
|
for (const selector of selectors) {
|
|
10346
10457
|
try {
|
|
10347
|
-
if (managed.some((
|
|
10458
|
+
if (managed.some((media) => media.element.matches(selector))) return true;
|
|
10348
10459
|
} catch {
|
|
10349
10460
|
}
|
|
10350
10461
|
}
|
|
@@ -9,10 +9,14 @@ 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;
|
|
19
|
+
chargeGeneratedIfItFits(bytes: number): boolean;
|
|
16
20
|
charge(file: string, bytes: number): void;
|
|
17
21
|
}
|
|
18
22
|
/**
|
|
@@ -153,12 +153,6 @@ export declare function localizeRemoteFontFaces(html: string, downloadDir: strin
|
|
|
153
153
|
html: string;
|
|
154
154
|
remoteMediaAssets: Map<string, string>;
|
|
155
155
|
}>;
|
|
156
|
-
/**
|
|
157
|
-
* Match one `url(<path>)` occurrence, with or without quotes, for a literal
|
|
158
|
-
* path. Exported for tests: the suffix-collision it prevents is invisible in
|
|
159
|
-
* ordinary projects and easy to reintroduce.
|
|
160
|
-
*/
|
|
161
|
-
export declare function urlOccurrenceRe(localPath: string): RegExp;
|
|
162
156
|
/**
|
|
163
157
|
* Optional behavior toggles for {@link compileForRender}. All fields are
|
|
164
158
|
* additive; omitting `options` preserves the in-process renderer's defaults.
|
|
@@ -205,6 +199,7 @@ export interface CompileForRenderOptions {
|
|
|
205
199
|
allowOutsideProjectAssets?: boolean;
|
|
206
200
|
includeOutsideScripts?: boolean;
|
|
207
201
|
}
|
|
202
|
+
export declare const MAX_VARIABLE_MEDIA_SRC_BYTES: number;
|
|
208
203
|
/**
|
|
209
204
|
* Compile an HTML composition project into a single self-contained HTML string
|
|
210
205
|
* with all media metadata resolved.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/producer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.66",
|
|
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/
|
|
40
|
-
"@hyperframes/
|
|
41
|
-
"@hyperframes/
|
|
42
|
-
"@hyperframes/
|
|
38
|
+
"@hyperframes/parsers": "0.9.66",
|
|
39
|
+
"@hyperframes/engine": "0.9.66",
|
|
40
|
+
"@hyperframes/studio-server": "0.9.66",
|
|
41
|
+
"@hyperframes/lint": "0.9.66",
|
|
42
|
+
"@hyperframes/core": "0.9.66"
|
|
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.66"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|