@hyperframes/producer 0.9.72 → 0.9.73
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 +136 -138
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +70 -69
- package/dist/index.js +136 -138
- package/dist/public-server.js +136 -138
- package/dist/services/htmlCompiler.d.ts +17 -4
- package/package.json +7 -7
- package/dist/services/compositionSizeLimit.d.ts +0 -28
package/dist/public-server.js
CHANGED
|
@@ -7114,92 +7114,7 @@ import { privateCacheRoot } from "@hyperframes/engine";
|
|
|
7114
7114
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
7115
7115
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
7116
7116
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
7117
|
-
|
|
7118
|
-
// src/services/compositionSizeLimit.ts
|
|
7119
|
-
import { statSync as statSync6 } from "node:fs";
|
|
7120
|
-
var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
7121
|
-
var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
7122
|
-
var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
7123
|
-
var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
7124
|
-
var MAX_COMPOSITION_MOUNTS = 1e4;
|
|
7125
|
-
var CompositionTooLargeError = class extends Error {
|
|
7126
|
-
constructor(message, publicMetadata) {
|
|
7127
|
-
super(message);
|
|
7128
|
-
this.publicMetadata = publicMetadata;
|
|
7129
|
-
this.name = "CompositionTooLargeError";
|
|
7130
|
-
}
|
|
7131
|
-
publicMetadata;
|
|
7132
|
-
code = COMPOSITION_TOO_LARGE;
|
|
7133
|
-
// The producer server reads these off the error for the wire envelope.
|
|
7134
|
-
owner = "user";
|
|
7135
|
-
retryable = false;
|
|
7136
|
-
};
|
|
7137
|
-
var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
7138
|
-
`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.`,
|
|
7139
|
-
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
7140
|
-
);
|
|
7141
|
-
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
7142
|
-
var REMOTE_SCRIPTS = "remote scripts";
|
|
7143
|
-
var REMOTE_STYLESHEETS = "remote stylesheets";
|
|
7144
|
-
function generatedTooLarge(file, bytes) {
|
|
7145
|
-
if (file === "composition variables") {
|
|
7146
|
-
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
7147
|
-
}
|
|
7148
|
-
if (file === "variable media sources") {
|
|
7149
|
-
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
7150
|
-
}
|
|
7151
|
-
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
7152
|
-
return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
|
|
7153
|
-
}
|
|
7154
|
-
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.`;
|
|
7155
|
-
}
|
|
7156
|
-
var CompositionExpansionBudget = class {
|
|
7157
|
-
bytes = 0;
|
|
7158
|
-
mounts = 0;
|
|
7159
|
-
generated = 0;
|
|
7160
|
-
/** `bytes` may be negative when a reserved upper bound is settled to the real size. */
|
|
7161
|
-
chargeGenerated(file, bytes) {
|
|
7162
|
-
this.generated += bytes;
|
|
7163
|
-
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
7164
|
-
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
7165
|
-
bytes: this.generated,
|
|
7166
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
7167
|
-
exceeded: "generated"
|
|
7168
|
-
});
|
|
7169
|
-
}
|
|
7170
|
-
chargeGeneratedIfItFits(bytes) {
|
|
7171
|
-
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
7172
|
-
this.generated += bytes;
|
|
7173
|
-
return true;
|
|
7174
|
-
}
|
|
7175
|
-
charge(file, bytes) {
|
|
7176
|
-
this.bytes += bytes;
|
|
7177
|
-
this.mounts += 1;
|
|
7178
|
-
if (this.bytes <= MAX_EXPANDED_COMPOSITION_BYTES && this.mounts <= MAX_COMPOSITION_MOUNTS) {
|
|
7179
|
-
return;
|
|
7180
|
-
}
|
|
7181
|
-
throw new CompositionTooLargeError(
|
|
7182
|
-
`Sub-composition mounts, ending at "${file}", add up to ${megabytes(this.bytes)} across ${this.mounts} mounts. One render inlines at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)} of composition HTML in at most ${MAX_COMPOSITION_MOUNTS} mounts. Mount large or repeated scenes fewer times.`,
|
|
7183
|
-
{
|
|
7184
|
-
bytes: this.bytes,
|
|
7185
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
7186
|
-
mounts: this.mounts,
|
|
7187
|
-
exceeded: this.mounts > MAX_COMPOSITION_MOUNTS ? "mounts" : "bytes"
|
|
7188
|
-
}
|
|
7189
|
-
);
|
|
7190
|
-
}
|
|
7191
|
-
};
|
|
7192
|
-
function assertCompositionFileSize(path, file) {
|
|
7193
|
-
let bytes;
|
|
7194
|
-
try {
|
|
7195
|
-
const stats = statSync6(path);
|
|
7196
|
-
if (!stats.isFile()) return;
|
|
7197
|
-
bytes = stats.size;
|
|
7198
|
-
} catch {
|
|
7199
|
-
return;
|
|
7200
|
-
}
|
|
7201
|
-
if (bytes > MAX_COMPOSITION_HTML_BYTES) throw fileTooLarge(file, bytes);
|
|
7202
|
-
}
|
|
7117
|
+
import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
|
|
7203
7118
|
|
|
7204
7119
|
// src/services/htmlCompiler.ts
|
|
7205
7120
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
@@ -7217,7 +7132,7 @@ import {
|
|
|
7217
7132
|
stylesheetLinkMatches
|
|
7218
7133
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7219
7134
|
import { createHash as createHash6 } from "node:crypto";
|
|
7220
|
-
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
7135
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8, statSync as statSync8 } from "fs";
|
|
7221
7136
|
import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7222
7137
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7223
7138
|
|
|
@@ -7295,6 +7210,12 @@ import {
|
|
|
7295
7210
|
} from "@hyperframes/parsers/asset-resolution";
|
|
7296
7211
|
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
7297
7212
|
import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
|
|
7213
|
+
import {
|
|
7214
|
+
assertCompositionFileSize,
|
|
7215
|
+
CompositionExpansionBudget,
|
|
7216
|
+
REMOTE_SCRIPTS,
|
|
7217
|
+
REMOTE_STYLESHEETS
|
|
7218
|
+
} from "@hyperframes/core/compiler";
|
|
7298
7219
|
|
|
7299
7220
|
// src/services/renderMediaCollector.ts
|
|
7300
7221
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -7489,7 +7410,7 @@ import {
|
|
|
7489
7410
|
|
|
7490
7411
|
// src/services/animatedGifPrep.ts
|
|
7491
7412
|
import { createHash as createHash4 } from "node:crypto";
|
|
7492
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as
|
|
7413
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
7493
7414
|
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7494
7415
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7495
7416
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
@@ -7548,7 +7469,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7548
7469
|
}
|
|
7549
7470
|
function isUsableFile(path) {
|
|
7550
7471
|
try {
|
|
7551
|
-
const stat =
|
|
7472
|
+
const stat = statSync6(path);
|
|
7552
7473
|
return stat.isFile() && stat.size > 0;
|
|
7553
7474
|
} catch {
|
|
7554
7475
|
return false;
|
|
@@ -7813,7 +7734,7 @@ import {
|
|
|
7813
7734
|
readFileSync as readFileSync7,
|
|
7814
7735
|
readSync as readSync3,
|
|
7815
7736
|
rmSync as rmSync10,
|
|
7816
|
-
statSync as
|
|
7737
|
+
statSync as statSync7,
|
|
7817
7738
|
writeFileSync as writeFileSync3
|
|
7818
7739
|
} from "node:fs";
|
|
7819
7740
|
import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
|
|
@@ -8057,7 +7978,7 @@ function resolveImageSource(src, options) {
|
|
|
8057
7978
|
}
|
|
8058
7979
|
function isUsableFile2(path) {
|
|
8059
7980
|
try {
|
|
8060
|
-
return
|
|
7981
|
+
return statSync7(path).size > 0;
|
|
8061
7982
|
} catch {
|
|
8062
7983
|
return false;
|
|
8063
7984
|
}
|
|
@@ -8544,16 +8465,59 @@ function detectShaderTransitionUsage(html) {
|
|
|
8544
8465
|
}
|
|
8545
8466
|
return false;
|
|
8546
8467
|
}
|
|
8547
|
-
|
|
8468
|
+
var MAX_REMOTE_ASSETS = 1e3;
|
|
8469
|
+
var ASSET_DOWNLOADS_AT_ONCE = 8;
|
|
8470
|
+
var AssetDownloads = class {
|
|
8471
|
+
constructor(signal) {
|
|
8472
|
+
this.signal = signal;
|
|
8473
|
+
}
|
|
8474
|
+
signal;
|
|
8475
|
+
reserved = /* @__PURE__ */ new Set();
|
|
8476
|
+
running = 0;
|
|
8477
|
+
queued = [];
|
|
8478
|
+
/** Throws before any of `urls` downloads when they would take the compile past the cap. */
|
|
8479
|
+
reserve(urls) {
|
|
8480
|
+
this.signal?.throwIfAborted();
|
|
8481
|
+
const fresh = new Set([...urls].filter((url) => !this.reserved.has(url)));
|
|
8482
|
+
if (this.reserved.size + fresh.size > MAX_REMOTE_ASSETS) {
|
|
8483
|
+
throw new Error(
|
|
8484
|
+
`The composition links more than ${MAX_REMOTE_ASSETS} remote media, image and font files; at most ${MAX_REMOTE_ASSETS} are downloaded at compile time`
|
|
8485
|
+
);
|
|
8486
|
+
}
|
|
8487
|
+
for (const url of fresh) this.reserved.add(url);
|
|
8488
|
+
}
|
|
8489
|
+
async download(url, destDir) {
|
|
8490
|
+
while (this.running >= ASSET_DOWNLOADS_AT_ONCE) {
|
|
8491
|
+
await new Promise((resolve12) => this.queued.push(resolve12));
|
|
8492
|
+
}
|
|
8493
|
+
if (this.signal?.aborted) {
|
|
8494
|
+
this.queued.shift()?.();
|
|
8495
|
+
this.signal.throwIfAborted();
|
|
8496
|
+
}
|
|
8497
|
+
this.running += 1;
|
|
8498
|
+
try {
|
|
8499
|
+
return await downloadToTemp(url, destDir, void 0, this.signal, void 0, {
|
|
8500
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
8501
|
+
});
|
|
8502
|
+
} finally {
|
|
8503
|
+
this.running -= 1;
|
|
8504
|
+
this.queued.shift()?.();
|
|
8505
|
+
}
|
|
8506
|
+
}
|
|
8507
|
+
};
|
|
8508
|
+
var downloadAsset = (url, destDir, assets) => assets ? assets.download(url, destDir) : downloadToTemp(url, destDir, void 0, void 0, void 0, {
|
|
8509
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
8510
|
+
});
|
|
8511
|
+
async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
8548
8512
|
let filePath = src;
|
|
8549
8513
|
if (isHttpUrl(src)) {
|
|
8550
8514
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8551
8515
|
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8516
|
+
run?.assets.reserve([src]);
|
|
8552
8517
|
try {
|
|
8553
|
-
filePath = await
|
|
8554
|
-
|
|
8555
|
-
|
|
8556
|
-
} catch {
|
|
8518
|
+
filePath = await downloadAsset(src, remoteDir, run?.assets);
|
|
8519
|
+
} catch (err) {
|
|
8520
|
+
if (run?.assets.signal?.aborted) throw err;
|
|
8557
8521
|
return { duration: null, resolvedPath: src };
|
|
8558
8522
|
}
|
|
8559
8523
|
} else {
|
|
@@ -8595,10 +8559,10 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8595
8559
|
}
|
|
8596
8560
|
});
|
|
8597
8561
|
const key = `${tagName}\0${filePath}`;
|
|
8598
|
-
let probed = probes
|
|
8562
|
+
let probed = run?.probes.get(key);
|
|
8599
8563
|
if (!probed) {
|
|
8600
8564
|
probed = probe();
|
|
8601
|
-
probes
|
|
8565
|
+
run?.probes.set(key, probed);
|
|
8602
8566
|
}
|
|
8603
8567
|
const outcome = await probed;
|
|
8604
8568
|
if ("error" in outcome) {
|
|
@@ -8637,7 +8601,7 @@ function markInferredVariableMediaDurations(html, unresolvedMedia) {
|
|
|
8637
8601
|
}
|
|
8638
8602
|
return changed ? document2.toString() : html;
|
|
8639
8603
|
}
|
|
8640
|
-
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath,
|
|
8604
|
+
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
8641
8605
|
const { html: staticCompiled, unresolved } = compileTimingAttrs(html);
|
|
8642
8606
|
const mediaUnresolved = unresolved.filter(
|
|
8643
8607
|
(el) => (el.tagName === "video" || el.tagName === "audio") && el.src
|
|
@@ -8656,7 +8620,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8656
8620
|
el.id,
|
|
8657
8621
|
log,
|
|
8658
8622
|
urlByAbsentLocalPath,
|
|
8659
|
-
|
|
8623
|
+
run,
|
|
8660
8624
|
assetRoot
|
|
8661
8625
|
).then(({ duration }) => ({ id: el.id, duration }))
|
|
8662
8626
|
)
|
|
@@ -8681,7 +8645,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8681
8645
|
el.id,
|
|
8682
8646
|
log,
|
|
8683
8647
|
void 0,
|
|
8684
|
-
|
|
8648
|
+
run,
|
|
8685
8649
|
assetRoot
|
|
8686
8650
|
);
|
|
8687
8651
|
return { id: el.id, tagName: el.tagName, duration: el.duration, maxDuration, src: el.src };
|
|
@@ -8704,7 +8668,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8704
8668
|
compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
|
|
8705
8669
|
return { html: compiledHtml, unresolvedCompositions };
|
|
8706
8670
|
}
|
|
8707
|
-
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath,
|
|
8671
|
+
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, run, assetRoot, outsideFiles = {}, compiledSrcs = /* @__PURE__ */ new Set()) {
|
|
8708
8672
|
const subCompositions = /* @__PURE__ */ new Map();
|
|
8709
8673
|
const { document: document2 } = parseHTML5(html);
|
|
8710
8674
|
const compEls = document2.querySelectorAll("[data-composition-src]");
|
|
@@ -8739,7 +8703,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8739
8703
|
downloadDir,
|
|
8740
8704
|
void 0,
|
|
8741
8705
|
urlByAbsentLocalPath,
|
|
8742
|
-
|
|
8706
|
+
run,
|
|
8743
8707
|
assetRoot
|
|
8744
8708
|
);
|
|
8745
8709
|
const nested = await parseSubCompositions(
|
|
@@ -8748,7 +8712,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8748
8712
|
downloadDir,
|
|
8749
8713
|
item.nestedVisited,
|
|
8750
8714
|
urlByAbsentLocalPath,
|
|
8751
|
-
|
|
8715
|
+
run,
|
|
8752
8716
|
assetRoot,
|
|
8753
8717
|
outsideFiles,
|
|
8754
8718
|
compiledSrcs
|
|
@@ -8946,6 +8910,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8946
8910
|
return compHtml;
|
|
8947
8911
|
},
|
|
8948
8912
|
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
8913
|
+
chargeElements: (srcPath, count) => budget.chargeElements(srcPath, count),
|
|
8949
8914
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
8950
8915
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
8951
8916
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -9274,18 +9239,18 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9274
9239
|
};
|
|
9275
9240
|
}
|
|
9276
9241
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
9277
|
-
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
9242
|
+
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
|
|
9243
|
+
assets?.reserve(urlSet);
|
|
9278
9244
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9279
9245
|
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
9280
9246
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9281
9247
|
await Promise.all(
|
|
9282
9248
|
[...urlSet].map(async (url) => {
|
|
9283
9249
|
try {
|
|
9284
|
-
const localPath = await
|
|
9285
|
-
onTelemetry: logRemoteDownloadTelemetry
|
|
9286
|
-
});
|
|
9250
|
+
const localPath = await downloadAsset(url, remoteDir, assets);
|
|
9287
9251
|
urlToLocal.set(url, localPath);
|
|
9288
9252
|
} catch (err) {
|
|
9253
|
+
if (assets?.signal?.aborted) throw err;
|
|
9289
9254
|
const identity = safeDownloadUrlIdentity(url);
|
|
9290
9255
|
defaultLogger.warn(`[Compiler] ${warnLabel}, using original URL as fallback.`, {
|
|
9291
9256
|
urlFingerprint: identity.urlFingerprint,
|
|
@@ -9311,14 +9276,15 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9311
9276
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
9312
9277
|
return { html: result, remoteMediaAssets };
|
|
9313
9278
|
}
|
|
9314
|
-
async function localizeRemoteMediaSources(html, downloadDir) {
|
|
9279
|
+
async function localizeRemoteMediaSources(html, downloadDir, assets) {
|
|
9315
9280
|
const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
|
|
9316
9281
|
const localized = await downloadAndRewriteUrls(
|
|
9317
9282
|
urlSet,
|
|
9318
9283
|
html,
|
|
9319
9284
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9320
9285
|
"Remote media download failed",
|
|
9321
|
-
"Localized remote media source(s)"
|
|
9286
|
+
"Localized remote media source(s)",
|
|
9287
|
+
assets
|
|
9322
9288
|
);
|
|
9323
9289
|
return { ...localized, html: dropBindingOnLocalizedMedia(localized.html) };
|
|
9324
9290
|
}
|
|
@@ -9334,17 +9300,18 @@ function dropBindingOnLocalizedMedia(html) {
|
|
|
9334
9300
|
}
|
|
9335
9301
|
return changed ? document2.toString() : html;
|
|
9336
9302
|
}
|
|
9337
|
-
async function localizeRemoteImageSources(html, downloadDir) {
|
|
9303
|
+
async function localizeRemoteImageSources(html, downloadDir, assets) {
|
|
9338
9304
|
const urlSet = new Set(remoteSrcUrls(html, "img"));
|
|
9339
9305
|
return downloadAndRewriteUrls(
|
|
9340
9306
|
urlSet,
|
|
9341
9307
|
html,
|
|
9342
9308
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9343
9309
|
"Remote image download failed",
|
|
9344
|
-
"Localized remote image source(s)"
|
|
9310
|
+
"Localized remote image source(s)",
|
|
9311
|
+
assets
|
|
9345
9312
|
);
|
|
9346
9313
|
}
|
|
9347
|
-
async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
9314
|
+
async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
9348
9315
|
const urlSet = /* @__PURE__ */ new Set();
|
|
9349
9316
|
for (const { parts } of remoteBackgroundUrlMatches(html)) {
|
|
9350
9317
|
if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
|
|
@@ -9355,6 +9322,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
9355
9322
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9356
9323
|
"Remote background-image download failed",
|
|
9357
9324
|
"Localized remote background-image(s)",
|
|
9325
|
+
assets,
|
|
9358
9326
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
9359
9327
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
9360
9328
|
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
@@ -9508,13 +9476,14 @@ function collectFontFaceUrls(html) {
|
|
|
9508
9476
|
}
|
|
9509
9477
|
return urlSet;
|
|
9510
9478
|
}
|
|
9511
|
-
function localizeFontFaceUrls(html, downloadDir) {
|
|
9479
|
+
function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
9512
9480
|
return downloadAndRewriteUrls(
|
|
9513
9481
|
collectFontFaceUrls(html),
|
|
9514
9482
|
html,
|
|
9515
9483
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9516
9484
|
"Remote font download failed",
|
|
9517
9485
|
"Localized remote font face(s)",
|
|
9486
|
+
assets,
|
|
9518
9487
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9519
9488
|
);
|
|
9520
9489
|
}
|
|
@@ -9532,16 +9501,24 @@ async function readLocalFont(absPath) {
|
|
|
9532
9501
|
}
|
|
9533
9502
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
9534
9503
|
}
|
|
9535
|
-
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
9536
|
-
const absPath = localPath.startsWith("/") ? localPath : resolve8(projectDir, localPath);
|
|
9537
|
-
if (
|
|
9538
|
-
|
|
9539
|
-
|
|
9504
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log, downloadedPath, reserve) {
|
|
9505
|
+
const absPath = downloadedPath ?? (localPath.startsWith("/") ? localPath : resolve8(projectDir, localPath));
|
|
9506
|
+
if (downloadedPath === void 0) {
|
|
9507
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) {
|
|
9508
|
+
return void 0;
|
|
9509
|
+
}
|
|
9510
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
9511
|
+
return void 0;
|
|
9512
|
+
}
|
|
9513
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9540
9514
|
}
|
|
9541
|
-
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9542
9515
|
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
9543
9516
|
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9544
9517
|
try {
|
|
9518
|
+
if (!reserve(Math.ceil(statSync8(absPath).size / 3) * 4 + 64)) {
|
|
9519
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
9520
|
+
return void 0;
|
|
9521
|
+
}
|
|
9545
9522
|
const font = await readLocalFont(absPath);
|
|
9546
9523
|
if (font.kind === "file-backed") {
|
|
9547
9524
|
dataUriByAbsolutePath.set(absPath, void 0);
|
|
@@ -9565,9 +9542,26 @@ async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsol
|
|
|
9565
9542
|
}
|
|
9566
9543
|
}
|
|
9567
9544
|
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
9568
|
-
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
9545
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger, downloadedFonts = /* @__PURE__ */ new Map()) {
|
|
9569
9546
|
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
9570
9547
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
9548
|
+
let warned = false;
|
|
9549
|
+
const keptFileBacked = (localPath) => {
|
|
9550
|
+
if (warned) return;
|
|
9551
|
+
warned = true;
|
|
9552
|
+
log.warn(
|
|
9553
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9554
|
+
);
|
|
9555
|
+
};
|
|
9556
|
+
let reserved = 0;
|
|
9557
|
+
const reserveFor = (localPath) => (bytes) => {
|
|
9558
|
+
if (reserved + bytes > budget.generatedRoom) {
|
|
9559
|
+
keptFileBacked(localPath);
|
|
9560
|
+
return false;
|
|
9561
|
+
}
|
|
9562
|
+
reserved += bytes;
|
|
9563
|
+
return true;
|
|
9564
|
+
};
|
|
9571
9565
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
9572
9566
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
9573
9567
|
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
@@ -9575,24 +9569,26 @@ async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = de
|
|
|
9575
9569
|
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
9576
9570
|
dataUriByPath.set(
|
|
9577
9571
|
localPath,
|
|
9578
|
-
await localFontDataUri(
|
|
9572
|
+
await localFontDataUri(
|
|
9573
|
+
localPath,
|
|
9574
|
+
projectDir,
|
|
9575
|
+
assetRoot,
|
|
9576
|
+
dataUriByAbsolutePath,
|
|
9577
|
+
log,
|
|
9578
|
+
downloadedFonts.get(localPath),
|
|
9579
|
+
reserveFor(localPath)
|
|
9580
|
+
)
|
|
9579
9581
|
);
|
|
9580
9582
|
}
|
|
9581
9583
|
}
|
|
9582
9584
|
}
|
|
9583
9585
|
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
9584
|
-
let warned = false;
|
|
9585
9586
|
const embed = (source, localPath) => {
|
|
9586
9587
|
const dataUri = dataUriByPath.get(localPath);
|
|
9587
9588
|
if (!dataUri) return source;
|
|
9588
9589
|
const inlined = `url("${dataUri}")`;
|
|
9589
9590
|
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
9590
|
-
|
|
9591
|
-
warned = true;
|
|
9592
|
-
log.warn(
|
|
9593
|
-
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9594
|
-
);
|
|
9595
|
-
}
|
|
9591
|
+
keptFileBacked(localPath);
|
|
9596
9592
|
return source;
|
|
9597
9593
|
};
|
|
9598
9594
|
return replaceMatches(
|
|
@@ -9724,7 +9720,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9724
9720
|
options.log
|
|
9725
9721
|
);
|
|
9726
9722
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
9727
|
-
const
|
|
9723
|
+
const run = { probes: /* @__PURE__ */ new Map(), assets: new AssetDownloads(options.abortSignal) };
|
|
9728
9724
|
const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
|
|
9729
9725
|
rawHtml,
|
|
9730
9726
|
projectDir,
|
|
@@ -9732,7 +9728,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9732
9728
|
downloadDir,
|
|
9733
9729
|
options.log,
|
|
9734
9730
|
options.urlByAbsentLocalPath,
|
|
9735
|
-
|
|
9731
|
+
run,
|
|
9736
9732
|
assetRoot
|
|
9737
9733
|
);
|
|
9738
9734
|
const { subCompositions } = await parseSubCompositions(
|
|
@@ -9741,7 +9737,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9741
9737
|
downloadDir,
|
|
9742
9738
|
void 0,
|
|
9743
9739
|
options.urlByAbsentLocalPath,
|
|
9744
|
-
|
|
9740
|
+
run,
|
|
9745
9741
|
assetRoot,
|
|
9746
9742
|
outsideFiles
|
|
9747
9743
|
);
|
|
@@ -9794,11 +9790,12 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9794
9790
|
);
|
|
9795
9791
|
const { html: htmlWithLocalMedia, remoteMediaAssets } = await localizeRemoteMediaSources(
|
|
9796
9792
|
htmlWithDeferredScripts,
|
|
9797
|
-
downloadDir
|
|
9793
|
+
downloadDir,
|
|
9794
|
+
run.assets
|
|
9798
9795
|
);
|
|
9799
|
-
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir);
|
|
9800
|
-
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir);
|
|
9801
|
-
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir);
|
|
9796
|
+
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir, run.assets);
|
|
9797
|
+
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir, run.assets);
|
|
9798
|
+
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir, run.assets);
|
|
9802
9799
|
const {
|
|
9803
9800
|
html: htmlWithJpegs,
|
|
9804
9801
|
preparedAssets: preparedHeifAssets,
|
|
@@ -9835,7 +9832,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9835
9832
|
projectDir,
|
|
9836
9833
|
assetRoot,
|
|
9837
9834
|
budget,
|
|
9838
|
-
options.log
|
|
9835
|
+
options.log,
|
|
9836
|
+
remoteFontAssets
|
|
9839
9837
|
);
|
|
9840
9838
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
9841
9839
|
embeddedHtml,
|
|
@@ -10308,7 +10306,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10308
10306
|
`Entry file "${relative4(projectDir, path)}" leads outside the project folder`
|
|
10309
10307
|
);
|
|
10310
10308
|
}
|
|
10311
|
-
|
|
10309
|
+
assertCompositionFileSize2(path, relative4(projectDir, path));
|
|
10312
10310
|
return readTextFile2(path);
|
|
10313
10311
|
};
|
|
10314
10312
|
const htmlPath = join22(projectDir, entryFile);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RateSpec, type ResolvedDuration, type UnresolvedElement } from "@hyperframes/core";
|
|
2
|
-
import { CompositionExpansionBudget } from "
|
|
2
|
+
import { CompositionExpansionBudget } from "@hyperframes/core/compiler";
|
|
3
3
|
import { type OutsideFilePolicy } from "../utils/paths.js";
|
|
4
4
|
import { type VideoElement, type ImageElement, type AudioElement, type AudioVolumeKeyframe } from "@hyperframes/engine";
|
|
5
5
|
import type { Page } from "puppeteer-core";
|
|
@@ -55,6 +55,19 @@ export declare function detectThreeDTransformUsage(html: string): boolean;
|
|
|
55
55
|
*/
|
|
56
56
|
export declare function detectAncestorBackgroundImage(html: string): boolean;
|
|
57
57
|
export declare function detectShaderTransitionUsage(html: string): boolean;
|
|
58
|
+
/** At most this many distinct remote media, image and font files download for one compile. */
|
|
59
|
+
export declare const MAX_REMOTE_ASSETS = 1000;
|
|
60
|
+
/** One compile's media, image and font downloads: its cancel, a cap on distinct files, a few at a time. */
|
|
61
|
+
declare class AssetDownloads {
|
|
62
|
+
readonly signal?: AbortSignal | undefined;
|
|
63
|
+
private readonly reserved;
|
|
64
|
+
private running;
|
|
65
|
+
private readonly queued;
|
|
66
|
+
constructor(signal?: AbortSignal | undefined);
|
|
67
|
+
/** Throws before any of `urls` downloads when they would take the compile past the cap. */
|
|
68
|
+
reserve(urls: Iterable<string>): void;
|
|
69
|
+
download(url: string, destDir: string): Promise<string>;
|
|
70
|
+
}
|
|
58
71
|
/**
|
|
59
72
|
* Distinct remote addresses one compile downloads, per kind: scripts, and non-Google stylesheets (counted before
|
|
60
73
|
* their contents are read, so a stylesheet with no font rules counts too).
|
|
@@ -104,7 +117,7 @@ export declare const REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
|
104
117
|
* the race entirely and keeps the render hermetic.
|
|
105
118
|
*/
|
|
106
119
|
/** @internal exported for unit testing only */
|
|
107
|
-
export declare function localizeRemoteMediaSources(html: string, downloadDir: string): Promise<{
|
|
120
|
+
export declare function localizeRemoteMediaSources(html: string, downloadDir: string, assets?: AssetDownloads): Promise<{
|
|
108
121
|
html: string;
|
|
109
122
|
remoteMediaAssets: Map<string, string>;
|
|
110
123
|
}>;
|
|
@@ -132,7 +145,7 @@ export declare function localizeRemoteMediaSources(html: string, downloadDir: st
|
|
|
132
145
|
* `hyperframes publish`'s archive-time localize step.
|
|
133
146
|
*/
|
|
134
147
|
/** @internal exported for unit testing only */
|
|
135
|
-
export declare function localizeRemoteImageSources(html: string, downloadDir: string): Promise<{
|
|
148
|
+
export declare function localizeRemoteImageSources(html: string, downloadDir: string, assets?: AssetDownloads): Promise<{
|
|
136
149
|
html: string;
|
|
137
150
|
remoteMediaAssets: Map<string, string>;
|
|
138
151
|
}>;
|
|
@@ -149,7 +162,7 @@ export declare function localizeRemoteImageSources(html: string, downloadDir: st
|
|
|
149
162
|
*
|
|
150
163
|
* @internal exported for unit testing only
|
|
151
164
|
*/
|
|
152
|
-
export declare function localizeRemoteBackgroundImages(html: string, downloadDir: string): Promise<{
|
|
165
|
+
export declare function localizeRemoteBackgroundImages(html: string, downloadDir: string, assets?: AssetDownloads): Promise<{
|
|
153
166
|
html: string;
|
|
154
167
|
remoteMediaAssets: Map<string, string>;
|
|
155
168
|
}>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/producer",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.73",
|
|
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/core": "0.9.
|
|
39
|
-
"@hyperframes/lint": "0.9.
|
|
40
|
-
"@hyperframes/
|
|
41
|
-
"@hyperframes/parsers": "0.9.
|
|
42
|
-
"@hyperframes/
|
|
38
|
+
"@hyperframes/core": "0.9.73",
|
|
39
|
+
"@hyperframes/lint": "0.9.73",
|
|
40
|
+
"@hyperframes/engine": "0.9.73",
|
|
41
|
+
"@hyperframes/parsers": "0.9.73",
|
|
42
|
+
"@hyperframes/studio-server": "0.9.73"
|
|
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.73"
|
|
52
52
|
},
|
|
53
53
|
"engines": {
|
|
54
54
|
"node": ">=22"
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The largest entry or sub-composition HTML file a render compiles. Compiling and probing a page
|
|
3
|
-
* runs on the render server's main thread, and their cost grows with the page's size, so one huge
|
|
4
|
-
* page would hold up every other render in the same process.
|
|
5
|
-
*/
|
|
6
|
-
export declare const MAX_COMPOSITION_HTML_BYTES: number;
|
|
7
|
-
/**
|
|
8
|
-
* What one render may inline across every sub-composition mount. Each file is checked on its own
|
|
9
|
-
* above, but a few small files that mount each other many times assemble a page far larger.
|
|
10
|
-
*/
|
|
11
|
-
export declare const MAX_EXPANDED_COMPOSITION_BYTES: number;
|
|
12
|
-
export declare const REMOTE_SCRIPTS = "remote scripts";
|
|
13
|
-
export declare const REMOTE_STYLESHEETS = "remote stylesheets";
|
|
14
|
-
/** Adds up every mount a render inlines, and what it generates for them, and throws past a limit. */
|
|
15
|
-
export declare class CompositionExpansionBudget {
|
|
16
|
-
private bytes;
|
|
17
|
-
private mounts;
|
|
18
|
-
private generated;
|
|
19
|
-
/** `bytes` may be negative when a reserved upper bound is settled to the real size. */
|
|
20
|
-
chargeGenerated(file: string, bytes: number): void;
|
|
21
|
-
chargeGeneratedIfItFits(bytes: number): boolean;
|
|
22
|
-
charge(file: string, bytes: number): void;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Throws {@link CompositionTooLargeError} when `path` is a file over the limit, before anything
|
|
26
|
-
* reads it. A missing path or a folder passes, so the caller's own read reports it as before.
|
|
27
|
-
*/
|
|
28
|
-
export declare function assertCompositionFileSize(path: string, file: string): void;
|