@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/index.js
CHANGED
|
@@ -7099,92 +7099,7 @@ import { privateCacheRoot } from "@hyperframes/engine";
|
|
|
7099
7099
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
7100
7100
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
7101
7101
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
7102
|
-
|
|
7103
|
-
// src/services/compositionSizeLimit.ts
|
|
7104
|
-
import { statSync as statSync6 } from "node:fs";
|
|
7105
|
-
var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
7106
|
-
var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
7107
|
-
var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
7108
|
-
var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
7109
|
-
var MAX_COMPOSITION_MOUNTS = 1e4;
|
|
7110
|
-
var CompositionTooLargeError = class extends Error {
|
|
7111
|
-
constructor(message, publicMetadata) {
|
|
7112
|
-
super(message);
|
|
7113
|
-
this.publicMetadata = publicMetadata;
|
|
7114
|
-
this.name = "CompositionTooLargeError";
|
|
7115
|
-
}
|
|
7116
|
-
publicMetadata;
|
|
7117
|
-
code = COMPOSITION_TOO_LARGE;
|
|
7118
|
-
// The producer server reads these off the error for the wire envelope.
|
|
7119
|
-
owner = "user";
|
|
7120
|
-
retryable = false;
|
|
7121
|
-
};
|
|
7122
|
-
var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
7123
|
-
`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.`,
|
|
7124
|
-
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
7125
|
-
);
|
|
7126
|
-
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
7127
|
-
var REMOTE_SCRIPTS = "remote scripts";
|
|
7128
|
-
var REMOTE_STYLESHEETS = "remote stylesheets";
|
|
7129
|
-
function generatedTooLarge(file, bytes) {
|
|
7130
|
-
if (file === "composition variables") {
|
|
7131
|
-
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
7132
|
-
}
|
|
7133
|
-
if (file === "variable media sources") {
|
|
7134
|
-
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
7135
|
-
}
|
|
7136
|
-
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
7137
|
-
return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
|
|
7138
|
-
}
|
|
7139
|
-
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.`;
|
|
7140
|
-
}
|
|
7141
|
-
var CompositionExpansionBudget = class {
|
|
7142
|
-
bytes = 0;
|
|
7143
|
-
mounts = 0;
|
|
7144
|
-
generated = 0;
|
|
7145
|
-
/** `bytes` may be negative when a reserved upper bound is settled to the real size. */
|
|
7146
|
-
chargeGenerated(file, bytes) {
|
|
7147
|
-
this.generated += bytes;
|
|
7148
|
-
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
7149
|
-
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
7150
|
-
bytes: this.generated,
|
|
7151
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
7152
|
-
exceeded: "generated"
|
|
7153
|
-
});
|
|
7154
|
-
}
|
|
7155
|
-
chargeGeneratedIfItFits(bytes) {
|
|
7156
|
-
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
7157
|
-
this.generated += bytes;
|
|
7158
|
-
return true;
|
|
7159
|
-
}
|
|
7160
|
-
charge(file, bytes) {
|
|
7161
|
-
this.bytes += bytes;
|
|
7162
|
-
this.mounts += 1;
|
|
7163
|
-
if (this.bytes <= MAX_EXPANDED_COMPOSITION_BYTES && this.mounts <= MAX_COMPOSITION_MOUNTS) {
|
|
7164
|
-
return;
|
|
7165
|
-
}
|
|
7166
|
-
throw new CompositionTooLargeError(
|
|
7167
|
-
`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.`,
|
|
7168
|
-
{
|
|
7169
|
-
bytes: this.bytes,
|
|
7170
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
7171
|
-
mounts: this.mounts,
|
|
7172
|
-
exceeded: this.mounts > MAX_COMPOSITION_MOUNTS ? "mounts" : "bytes"
|
|
7173
|
-
}
|
|
7174
|
-
);
|
|
7175
|
-
}
|
|
7176
|
-
};
|
|
7177
|
-
function assertCompositionFileSize(path, file) {
|
|
7178
|
-
let bytes;
|
|
7179
|
-
try {
|
|
7180
|
-
const stats = statSync6(path);
|
|
7181
|
-
if (!stats.isFile()) return;
|
|
7182
|
-
bytes = stats.size;
|
|
7183
|
-
} catch {
|
|
7184
|
-
return;
|
|
7185
|
-
}
|
|
7186
|
-
if (bytes > MAX_COMPOSITION_HTML_BYTES) throw fileTooLarge(file, bytes);
|
|
7187
|
-
}
|
|
7102
|
+
import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
|
|
7188
7103
|
|
|
7189
7104
|
// src/services/htmlCompiler.ts
|
|
7190
7105
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
@@ -7202,7 +7117,7 @@ import {
|
|
|
7202
7117
|
stylesheetLinkMatches
|
|
7203
7118
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7204
7119
|
import { createHash as createHash6 } from "node:crypto";
|
|
7205
|
-
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
7120
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8, statSync as statSync8 } from "fs";
|
|
7206
7121
|
import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7207
7122
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7208
7123
|
|
|
@@ -7280,6 +7195,12 @@ import {
|
|
|
7280
7195
|
} from "@hyperframes/parsers/asset-resolution";
|
|
7281
7196
|
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
7282
7197
|
import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
|
|
7198
|
+
import {
|
|
7199
|
+
assertCompositionFileSize,
|
|
7200
|
+
CompositionExpansionBudget,
|
|
7201
|
+
REMOTE_SCRIPTS,
|
|
7202
|
+
REMOTE_STYLESHEETS
|
|
7203
|
+
} from "@hyperframes/core/compiler";
|
|
7283
7204
|
|
|
7284
7205
|
// src/services/renderMediaCollector.ts
|
|
7285
7206
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -7474,7 +7395,7 @@ import {
|
|
|
7474
7395
|
|
|
7475
7396
|
// src/services/animatedGifPrep.ts
|
|
7476
7397
|
import { createHash as createHash4 } from "node:crypto";
|
|
7477
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as
|
|
7398
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
7478
7399
|
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7479
7400
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7480
7401
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
@@ -7533,7 +7454,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7533
7454
|
}
|
|
7534
7455
|
function isUsableFile(path) {
|
|
7535
7456
|
try {
|
|
7536
|
-
const stat =
|
|
7457
|
+
const stat = statSync6(path);
|
|
7537
7458
|
return stat.isFile() && stat.size > 0;
|
|
7538
7459
|
} catch {
|
|
7539
7460
|
return false;
|
|
@@ -7798,7 +7719,7 @@ import {
|
|
|
7798
7719
|
readFileSync as readFileSync7,
|
|
7799
7720
|
readSync as readSync3,
|
|
7800
7721
|
rmSync as rmSync10,
|
|
7801
|
-
statSync as
|
|
7722
|
+
statSync as statSync7,
|
|
7802
7723
|
writeFileSync as writeFileSync3
|
|
7803
7724
|
} from "node:fs";
|
|
7804
7725
|
import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
|
|
@@ -8042,7 +7963,7 @@ function resolveImageSource(src, options) {
|
|
|
8042
7963
|
}
|
|
8043
7964
|
function isUsableFile2(path) {
|
|
8044
7965
|
try {
|
|
8045
|
-
return
|
|
7966
|
+
return statSync7(path).size > 0;
|
|
8046
7967
|
} catch {
|
|
8047
7968
|
return false;
|
|
8048
7969
|
}
|
|
@@ -8529,16 +8450,59 @@ function detectShaderTransitionUsage(html) {
|
|
|
8529
8450
|
}
|
|
8530
8451
|
return false;
|
|
8531
8452
|
}
|
|
8532
|
-
|
|
8453
|
+
var MAX_REMOTE_ASSETS = 1e3;
|
|
8454
|
+
var ASSET_DOWNLOADS_AT_ONCE = 8;
|
|
8455
|
+
var AssetDownloads = class {
|
|
8456
|
+
constructor(signal) {
|
|
8457
|
+
this.signal = signal;
|
|
8458
|
+
}
|
|
8459
|
+
signal;
|
|
8460
|
+
reserved = /* @__PURE__ */ new Set();
|
|
8461
|
+
running = 0;
|
|
8462
|
+
queued = [];
|
|
8463
|
+
/** Throws before any of `urls` downloads when they would take the compile past the cap. */
|
|
8464
|
+
reserve(urls) {
|
|
8465
|
+
this.signal?.throwIfAborted();
|
|
8466
|
+
const fresh = new Set([...urls].filter((url) => !this.reserved.has(url)));
|
|
8467
|
+
if (this.reserved.size + fresh.size > MAX_REMOTE_ASSETS) {
|
|
8468
|
+
throw new Error(
|
|
8469
|
+
`The composition links more than ${MAX_REMOTE_ASSETS} remote media, image and font files; at most ${MAX_REMOTE_ASSETS} are downloaded at compile time`
|
|
8470
|
+
);
|
|
8471
|
+
}
|
|
8472
|
+
for (const url of fresh) this.reserved.add(url);
|
|
8473
|
+
}
|
|
8474
|
+
async download(url, destDir) {
|
|
8475
|
+
while (this.running >= ASSET_DOWNLOADS_AT_ONCE) {
|
|
8476
|
+
await new Promise((resolve14) => this.queued.push(resolve14));
|
|
8477
|
+
}
|
|
8478
|
+
if (this.signal?.aborted) {
|
|
8479
|
+
this.queued.shift()?.();
|
|
8480
|
+
this.signal.throwIfAborted();
|
|
8481
|
+
}
|
|
8482
|
+
this.running += 1;
|
|
8483
|
+
try {
|
|
8484
|
+
return await downloadToTemp(url, destDir, void 0, this.signal, void 0, {
|
|
8485
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
8486
|
+
});
|
|
8487
|
+
} finally {
|
|
8488
|
+
this.running -= 1;
|
|
8489
|
+
this.queued.shift()?.();
|
|
8490
|
+
}
|
|
8491
|
+
}
|
|
8492
|
+
};
|
|
8493
|
+
var downloadAsset = (url, destDir, assets) => assets ? assets.download(url, destDir) : downloadToTemp(url, destDir, void 0, void 0, void 0, {
|
|
8494
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
8495
|
+
});
|
|
8496
|
+
async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
8533
8497
|
let filePath = src;
|
|
8534
8498
|
if (isHttpUrl(src)) {
|
|
8535
8499
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8536
8500
|
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8501
|
+
run?.assets.reserve([src]);
|
|
8537
8502
|
try {
|
|
8538
|
-
filePath = await
|
|
8539
|
-
|
|
8540
|
-
|
|
8541
|
-
} catch {
|
|
8503
|
+
filePath = await downloadAsset(src, remoteDir, run?.assets);
|
|
8504
|
+
} catch (err) {
|
|
8505
|
+
if (run?.assets.signal?.aborted) throw err;
|
|
8542
8506
|
return { duration: null, resolvedPath: src };
|
|
8543
8507
|
}
|
|
8544
8508
|
} else {
|
|
@@ -8580,10 +8544,10 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8580
8544
|
}
|
|
8581
8545
|
});
|
|
8582
8546
|
const key = `${tagName}\0${filePath}`;
|
|
8583
|
-
let probed = probes
|
|
8547
|
+
let probed = run?.probes.get(key);
|
|
8584
8548
|
if (!probed) {
|
|
8585
8549
|
probed = probe();
|
|
8586
|
-
probes
|
|
8550
|
+
run?.probes.set(key, probed);
|
|
8587
8551
|
}
|
|
8588
8552
|
const outcome = await probed;
|
|
8589
8553
|
if ("error" in outcome) {
|
|
@@ -8622,7 +8586,7 @@ function markInferredVariableMediaDurations(html, unresolvedMedia) {
|
|
|
8622
8586
|
}
|
|
8623
8587
|
return changed ? document2.toString() : html;
|
|
8624
8588
|
}
|
|
8625
|
-
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath,
|
|
8589
|
+
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
8626
8590
|
const { html: staticCompiled, unresolved } = compileTimingAttrs(html);
|
|
8627
8591
|
const mediaUnresolved = unresolved.filter(
|
|
8628
8592
|
(el) => (el.tagName === "video" || el.tagName === "audio") && el.src
|
|
@@ -8641,7 +8605,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8641
8605
|
el.id,
|
|
8642
8606
|
log,
|
|
8643
8607
|
urlByAbsentLocalPath,
|
|
8644
|
-
|
|
8608
|
+
run,
|
|
8645
8609
|
assetRoot
|
|
8646
8610
|
).then(({ duration }) => ({ id: el.id, duration }))
|
|
8647
8611
|
)
|
|
@@ -8666,7 +8630,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8666
8630
|
el.id,
|
|
8667
8631
|
log,
|
|
8668
8632
|
void 0,
|
|
8669
|
-
|
|
8633
|
+
run,
|
|
8670
8634
|
assetRoot
|
|
8671
8635
|
);
|
|
8672
8636
|
return { id: el.id, tagName: el.tagName, duration: el.duration, maxDuration, src: el.src };
|
|
@@ -8689,7 +8653,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
8689
8653
|
compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
|
|
8690
8654
|
return { html: compiledHtml, unresolvedCompositions };
|
|
8691
8655
|
}
|
|
8692
|
-
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath,
|
|
8656
|
+
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, run, assetRoot, outsideFiles = {}, compiledSrcs = /* @__PURE__ */ new Set()) {
|
|
8693
8657
|
const subCompositions = /* @__PURE__ */ new Map();
|
|
8694
8658
|
const { document: document2 } = parseHTML5(html);
|
|
8695
8659
|
const compEls = document2.querySelectorAll("[data-composition-src]");
|
|
@@ -8724,7 +8688,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8724
8688
|
downloadDir,
|
|
8725
8689
|
void 0,
|
|
8726
8690
|
urlByAbsentLocalPath,
|
|
8727
|
-
|
|
8691
|
+
run,
|
|
8728
8692
|
assetRoot
|
|
8729
8693
|
);
|
|
8730
8694
|
const nested = await parseSubCompositions(
|
|
@@ -8733,7 +8697,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8733
8697
|
downloadDir,
|
|
8734
8698
|
item.nestedVisited,
|
|
8735
8699
|
urlByAbsentLocalPath,
|
|
8736
|
-
|
|
8700
|
+
run,
|
|
8737
8701
|
assetRoot,
|
|
8738
8702
|
outsideFiles,
|
|
8739
8703
|
compiledSrcs
|
|
@@ -8931,6 +8895,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
8931
8895
|
return compHtml;
|
|
8932
8896
|
},
|
|
8933
8897
|
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
8898
|
+
chargeElements: (srcPath, count) => budget.chargeElements(srcPath, count),
|
|
8934
8899
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
8935
8900
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
8936
8901
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -9259,18 +9224,18 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9259
9224
|
};
|
|
9260
9225
|
}
|
|
9261
9226
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
9262
|
-
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
9227
|
+
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
|
|
9228
|
+
assets?.reserve(urlSet);
|
|
9263
9229
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9264
9230
|
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
9265
9231
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9266
9232
|
await Promise.all(
|
|
9267
9233
|
[...urlSet].map(async (url) => {
|
|
9268
9234
|
try {
|
|
9269
|
-
const localPath = await
|
|
9270
|
-
onTelemetry: logRemoteDownloadTelemetry
|
|
9271
|
-
});
|
|
9235
|
+
const localPath = await downloadAsset(url, remoteDir, assets);
|
|
9272
9236
|
urlToLocal.set(url, localPath);
|
|
9273
9237
|
} catch (err) {
|
|
9238
|
+
if (assets?.signal?.aborted) throw err;
|
|
9274
9239
|
const identity = safeDownloadUrlIdentity(url);
|
|
9275
9240
|
defaultLogger.warn(`[Compiler] ${warnLabel}, using original URL as fallback.`, {
|
|
9276
9241
|
urlFingerprint: identity.urlFingerprint,
|
|
@@ -9296,14 +9261,15 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
9296
9261
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
9297
9262
|
return { html: result, remoteMediaAssets };
|
|
9298
9263
|
}
|
|
9299
|
-
async function localizeRemoteMediaSources(html, downloadDir) {
|
|
9264
|
+
async function localizeRemoteMediaSources(html, downloadDir, assets) {
|
|
9300
9265
|
const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
|
|
9301
9266
|
const localized = await downloadAndRewriteUrls(
|
|
9302
9267
|
urlSet,
|
|
9303
9268
|
html,
|
|
9304
9269
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9305
9270
|
"Remote media download failed",
|
|
9306
|
-
"Localized remote media source(s)"
|
|
9271
|
+
"Localized remote media source(s)",
|
|
9272
|
+
assets
|
|
9307
9273
|
);
|
|
9308
9274
|
return { ...localized, html: dropBindingOnLocalizedMedia(localized.html) };
|
|
9309
9275
|
}
|
|
@@ -9319,17 +9285,18 @@ function dropBindingOnLocalizedMedia(html) {
|
|
|
9319
9285
|
}
|
|
9320
9286
|
return changed ? document2.toString() : html;
|
|
9321
9287
|
}
|
|
9322
|
-
async function localizeRemoteImageSources(html, downloadDir) {
|
|
9288
|
+
async function localizeRemoteImageSources(html, downloadDir, assets) {
|
|
9323
9289
|
const urlSet = new Set(remoteSrcUrls(html, "img"));
|
|
9324
9290
|
return downloadAndRewriteUrls(
|
|
9325
9291
|
urlSet,
|
|
9326
9292
|
html,
|
|
9327
9293
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9328
9294
|
"Remote image download failed",
|
|
9329
|
-
"Localized remote image source(s)"
|
|
9295
|
+
"Localized remote image source(s)",
|
|
9296
|
+
assets
|
|
9330
9297
|
);
|
|
9331
9298
|
}
|
|
9332
|
-
async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
9299
|
+
async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
9333
9300
|
const urlSet = /* @__PURE__ */ new Set();
|
|
9334
9301
|
for (const { parts } of remoteBackgroundUrlMatches(html)) {
|
|
9335
9302
|
if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
|
|
@@ -9340,6 +9307,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
9340
9307
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9341
9308
|
"Remote background-image download failed",
|
|
9342
9309
|
"Localized remote background-image(s)",
|
|
9310
|
+
assets,
|
|
9343
9311
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
9344
9312
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
9345
9313
|
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
@@ -9496,13 +9464,14 @@ function collectFontFaceUrls(html) {
|
|
|
9496
9464
|
async function localizeRemoteFontFaces(html, downloadDir) {
|
|
9497
9465
|
return localizeFontFaceUrls(await inlineExternalFontStylesheets(html), downloadDir);
|
|
9498
9466
|
}
|
|
9499
|
-
function localizeFontFaceUrls(html, downloadDir) {
|
|
9467
|
+
function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
9500
9468
|
return downloadAndRewriteUrls(
|
|
9501
9469
|
collectFontFaceUrls(html),
|
|
9502
9470
|
html,
|
|
9503
9471
|
join21(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
9504
9472
|
"Remote font download failed",
|
|
9505
9473
|
"Localized remote font face(s)",
|
|
9474
|
+
assets,
|
|
9506
9475
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
9507
9476
|
);
|
|
9508
9477
|
}
|
|
@@ -9520,16 +9489,24 @@ async function readLocalFont(absPath) {
|
|
|
9520
9489
|
}
|
|
9521
9490
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
9522
9491
|
}
|
|
9523
|
-
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
9524
|
-
const absPath = localPath.startsWith("/") ? localPath : resolve8(projectDir, localPath);
|
|
9525
|
-
if (
|
|
9526
|
-
|
|
9527
|
-
|
|
9492
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log, downloadedPath, reserve) {
|
|
9493
|
+
const absPath = downloadedPath ?? (localPath.startsWith("/") ? localPath : resolve8(projectDir, localPath));
|
|
9494
|
+
if (downloadedPath === void 0) {
|
|
9495
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) {
|
|
9496
|
+
return void 0;
|
|
9497
|
+
}
|
|
9498
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
9499
|
+
return void 0;
|
|
9500
|
+
}
|
|
9501
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9528
9502
|
}
|
|
9529
|
-
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
9530
9503
|
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
9531
9504
|
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
9532
9505
|
try {
|
|
9506
|
+
if (!reserve(Math.ceil(statSync8(absPath).size / 3) * 4 + 64)) {
|
|
9507
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
9508
|
+
return void 0;
|
|
9509
|
+
}
|
|
9533
9510
|
const font = await readLocalFont(absPath);
|
|
9534
9511
|
if (font.kind === "file-backed") {
|
|
9535
9512
|
dataUriByAbsolutePath.set(absPath, void 0);
|
|
@@ -9553,9 +9530,26 @@ async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsol
|
|
|
9553
9530
|
}
|
|
9554
9531
|
}
|
|
9555
9532
|
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
9556
|
-
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
9533
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger, downloadedFonts = /* @__PURE__ */ new Map()) {
|
|
9557
9534
|
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
9558
9535
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
9536
|
+
let warned = false;
|
|
9537
|
+
const keptFileBacked = (localPath) => {
|
|
9538
|
+
if (warned) return;
|
|
9539
|
+
warned = true;
|
|
9540
|
+
log.warn(
|
|
9541
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9542
|
+
);
|
|
9543
|
+
};
|
|
9544
|
+
let reserved = 0;
|
|
9545
|
+
const reserveFor = (localPath) => (bytes) => {
|
|
9546
|
+
if (reserved + bytes > budget.generatedRoom) {
|
|
9547
|
+
keptFileBacked(localPath);
|
|
9548
|
+
return false;
|
|
9549
|
+
}
|
|
9550
|
+
reserved += bytes;
|
|
9551
|
+
return true;
|
|
9552
|
+
};
|
|
9559
9553
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
9560
9554
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
9561
9555
|
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
@@ -9563,24 +9557,26 @@ async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = de
|
|
|
9563
9557
|
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
9564
9558
|
dataUriByPath.set(
|
|
9565
9559
|
localPath,
|
|
9566
|
-
await localFontDataUri(
|
|
9560
|
+
await localFontDataUri(
|
|
9561
|
+
localPath,
|
|
9562
|
+
projectDir,
|
|
9563
|
+
assetRoot,
|
|
9564
|
+
dataUriByAbsolutePath,
|
|
9565
|
+
log,
|
|
9566
|
+
downloadedFonts.get(localPath),
|
|
9567
|
+
reserveFor(localPath)
|
|
9568
|
+
)
|
|
9567
9569
|
);
|
|
9568
9570
|
}
|
|
9569
9571
|
}
|
|
9570
9572
|
}
|
|
9571
9573
|
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
9572
|
-
let warned = false;
|
|
9573
9574
|
const embed = (source, localPath) => {
|
|
9574
9575
|
const dataUri = dataUriByPath.get(localPath);
|
|
9575
9576
|
if (!dataUri) return source;
|
|
9576
9577
|
const inlined = `url("${dataUri}")`;
|
|
9577
9578
|
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
9578
|
-
|
|
9579
|
-
warned = true;
|
|
9580
|
-
log.warn(
|
|
9581
|
-
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
9582
|
-
);
|
|
9583
|
-
}
|
|
9579
|
+
keptFileBacked(localPath);
|
|
9584
9580
|
return source;
|
|
9585
9581
|
};
|
|
9586
9582
|
return replaceMatches(
|
|
@@ -9712,7 +9708,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9712
9708
|
options.log
|
|
9713
9709
|
);
|
|
9714
9710
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
9715
|
-
const
|
|
9711
|
+
const run = { probes: /* @__PURE__ */ new Map(), assets: new AssetDownloads(options.abortSignal) };
|
|
9716
9712
|
const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
|
|
9717
9713
|
rawHtml,
|
|
9718
9714
|
projectDir,
|
|
@@ -9720,7 +9716,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9720
9716
|
downloadDir,
|
|
9721
9717
|
options.log,
|
|
9722
9718
|
options.urlByAbsentLocalPath,
|
|
9723
|
-
|
|
9719
|
+
run,
|
|
9724
9720
|
assetRoot
|
|
9725
9721
|
);
|
|
9726
9722
|
const { subCompositions } = await parseSubCompositions(
|
|
@@ -9729,7 +9725,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9729
9725
|
downloadDir,
|
|
9730
9726
|
void 0,
|
|
9731
9727
|
options.urlByAbsentLocalPath,
|
|
9732
|
-
|
|
9728
|
+
run,
|
|
9733
9729
|
assetRoot,
|
|
9734
9730
|
outsideFiles
|
|
9735
9731
|
);
|
|
@@ -9782,11 +9778,12 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9782
9778
|
);
|
|
9783
9779
|
const { html: htmlWithLocalMedia, remoteMediaAssets } = await localizeRemoteMediaSources(
|
|
9784
9780
|
htmlWithDeferredScripts,
|
|
9785
|
-
downloadDir
|
|
9781
|
+
downloadDir,
|
|
9782
|
+
run.assets
|
|
9786
9783
|
);
|
|
9787
|
-
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir);
|
|
9788
|
-
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir);
|
|
9789
|
-
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir);
|
|
9784
|
+
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir, run.assets);
|
|
9785
|
+
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir, run.assets);
|
|
9786
|
+
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir, run.assets);
|
|
9790
9787
|
const {
|
|
9791
9788
|
html: htmlWithJpegs,
|
|
9792
9789
|
preparedAssets: preparedHeifAssets,
|
|
@@ -9823,7 +9820,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9823
9820
|
projectDir,
|
|
9824
9821
|
assetRoot,
|
|
9825
9822
|
budget,
|
|
9826
|
-
options.log
|
|
9823
|
+
options.log,
|
|
9824
|
+
remoteFontAssets
|
|
9827
9825
|
);
|
|
9828
9826
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
9829
9827
|
embeddedHtml,
|
|
@@ -10296,7 +10294,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10296
10294
|
`Entry file "${relative4(projectDir, path)}" leads outside the project folder`
|
|
10297
10295
|
);
|
|
10298
10296
|
}
|
|
10299
|
-
|
|
10297
|
+
assertCompositionFileSize2(path, relative4(projectDir, path));
|
|
10300
10298
|
return readTextFile2(path);
|
|
10301
10299
|
};
|
|
10302
10300
|
const htmlPath = join22(projectDir, entryFile);
|