@hyperframes/producer 0.9.71 → 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 +140 -142
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +73 -72
- package/dist/index.js +143 -145
- package/dist/public-server.js +140 -142
- package/dist/services/htmlCompiler.d.ts +17 -4
- package/package.json +7 -7
- package/dist/services/compositionSizeLimit.d.ts +0 -28
package/dist/distributed.js
CHANGED
|
@@ -143,7 +143,7 @@ function formatExportFrameName(index, ext) {
|
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
// src/services/renderOrchestrator.ts
|
|
146
|
-
import { audioFailureDiagnostics as audioFailureDiagnostics2,
|
|
146
|
+
import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
|
|
147
147
|
import {
|
|
148
148
|
existsSync as existsSync14,
|
|
149
149
|
mkdirSync as mkdirSync6,
|
|
@@ -2459,92 +2459,7 @@ import { privateCacheRoot } from "@hyperframes/engine";
|
|
|
2459
2459
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
2460
2460
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
2461
2461
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
2462
|
-
|
|
2463
|
-
// src/services/compositionSizeLimit.ts
|
|
2464
|
-
import { statSync as statSync3 } from "node:fs";
|
|
2465
|
-
var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
2466
|
-
var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
2467
|
-
var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
2468
|
-
var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
2469
|
-
var MAX_COMPOSITION_MOUNTS = 1e4;
|
|
2470
|
-
var CompositionTooLargeError = class extends Error {
|
|
2471
|
-
constructor(message, publicMetadata) {
|
|
2472
|
-
super(message);
|
|
2473
|
-
this.publicMetadata = publicMetadata;
|
|
2474
|
-
this.name = "CompositionTooLargeError";
|
|
2475
|
-
}
|
|
2476
|
-
publicMetadata;
|
|
2477
|
-
code = COMPOSITION_TOO_LARGE;
|
|
2478
|
-
// The producer server reads these off the error for the wire envelope.
|
|
2479
|
-
owner = "user";
|
|
2480
|
-
retryable = false;
|
|
2481
|
-
};
|
|
2482
|
-
var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
2483
|
-
`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.`,
|
|
2484
|
-
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
2485
|
-
);
|
|
2486
|
-
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
2487
|
-
var REMOTE_SCRIPTS = "remote scripts";
|
|
2488
|
-
var REMOTE_STYLESHEETS = "remote stylesheets";
|
|
2489
|
-
function generatedTooLarge(file, bytes) {
|
|
2490
|
-
if (file === "composition variables") {
|
|
2491
|
-
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
2492
|
-
}
|
|
2493
|
-
if (file === "variable media sources") {
|
|
2494
|
-
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
2495
|
-
}
|
|
2496
|
-
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
2497
|
-
return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
|
|
2498
|
-
}
|
|
2499
|
-
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.`;
|
|
2500
|
-
}
|
|
2501
|
-
var CompositionExpansionBudget = class {
|
|
2502
|
-
bytes = 0;
|
|
2503
|
-
mounts = 0;
|
|
2504
|
-
generated = 0;
|
|
2505
|
-
/** `bytes` may be negative when a reserved upper bound is settled to the real size. */
|
|
2506
|
-
chargeGenerated(file, bytes) {
|
|
2507
|
-
this.generated += bytes;
|
|
2508
|
-
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
2509
|
-
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
2510
|
-
bytes: this.generated,
|
|
2511
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
2512
|
-
exceeded: "generated"
|
|
2513
|
-
});
|
|
2514
|
-
}
|
|
2515
|
-
chargeGeneratedIfItFits(bytes) {
|
|
2516
|
-
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
2517
|
-
this.generated += bytes;
|
|
2518
|
-
return true;
|
|
2519
|
-
}
|
|
2520
|
-
charge(file, bytes) {
|
|
2521
|
-
this.bytes += bytes;
|
|
2522
|
-
this.mounts += 1;
|
|
2523
|
-
if (this.bytes <= MAX_EXPANDED_COMPOSITION_BYTES && this.mounts <= MAX_COMPOSITION_MOUNTS) {
|
|
2524
|
-
return;
|
|
2525
|
-
}
|
|
2526
|
-
throw new CompositionTooLargeError(
|
|
2527
|
-
`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.`,
|
|
2528
|
-
{
|
|
2529
|
-
bytes: this.bytes,
|
|
2530
|
-
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
2531
|
-
mounts: this.mounts,
|
|
2532
|
-
exceeded: this.mounts > MAX_COMPOSITION_MOUNTS ? "mounts" : "bytes"
|
|
2533
|
-
}
|
|
2534
|
-
);
|
|
2535
|
-
}
|
|
2536
|
-
};
|
|
2537
|
-
function assertCompositionFileSize(path, file) {
|
|
2538
|
-
let bytes;
|
|
2539
|
-
try {
|
|
2540
|
-
const stats = statSync3(path);
|
|
2541
|
-
if (!stats.isFile()) return;
|
|
2542
|
-
bytes = stats.size;
|
|
2543
|
-
} catch {
|
|
2544
|
-
return;
|
|
2545
|
-
}
|
|
2546
|
-
if (bytes > MAX_COMPOSITION_HTML_BYTES) throw fileTooLarge(file, bytes);
|
|
2547
|
-
}
|
|
2462
|
+
import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
|
|
2548
2463
|
|
|
2549
2464
|
// src/services/htmlCompiler.ts
|
|
2550
2465
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
@@ -2562,7 +2477,7 @@ import {
|
|
|
2562
2477
|
stylesheetLinkMatches
|
|
2563
2478
|
} from "@hyperframes/parsers/css-url-scans";
|
|
2564
2479
|
import { createHash as createHash5 } from "node:crypto";
|
|
2565
|
-
import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
|
|
2480
|
+
import { createReadStream as createReadStream2, existsSync as existsSync7, mkdirSync as mkdirSync4, readFileSync as readFileSync5, statSync as statSync5 } from "fs";
|
|
2566
2481
|
import { join as join9, dirname as dirname7, resolve as resolve6, basename as basename3, relative as relative2, sep as sep3 } from "path";
|
|
2567
2482
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
2568
2483
|
|
|
@@ -2640,6 +2555,12 @@ import {
|
|
|
2640
2555
|
} from "@hyperframes/parsers/asset-resolution";
|
|
2641
2556
|
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
2642
2557
|
import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
|
|
2558
|
+
import {
|
|
2559
|
+
assertCompositionFileSize,
|
|
2560
|
+
CompositionExpansionBudget,
|
|
2561
|
+
REMOTE_SCRIPTS,
|
|
2562
|
+
REMOTE_STYLESHEETS
|
|
2563
|
+
} from "@hyperframes/core/compiler";
|
|
2643
2564
|
|
|
2644
2565
|
// src/services/renderMediaCollector.ts
|
|
2645
2566
|
import { parseHTML as parseHTML2 } from "linkedom";
|
|
@@ -2834,7 +2755,7 @@ import {
|
|
|
2834
2755
|
|
|
2835
2756
|
// src/services/animatedGifPrep.ts
|
|
2836
2757
|
import { createHash as createHash3 } from "node:crypto";
|
|
2837
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as
|
|
2758
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync5, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync3 } from "node:fs";
|
|
2838
2759
|
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6, resolve as resolve4 } from "node:path";
|
|
2839
2760
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
2840
2761
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
@@ -2893,7 +2814,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
2893
2814
|
}
|
|
2894
2815
|
function isUsableFile(path) {
|
|
2895
2816
|
try {
|
|
2896
|
-
const stat =
|
|
2817
|
+
const stat = statSync3(path);
|
|
2897
2818
|
return stat.isFile() && stat.size > 0;
|
|
2898
2819
|
} catch {
|
|
2899
2820
|
return false;
|
|
@@ -3158,7 +3079,7 @@ import {
|
|
|
3158
3079
|
readFileSync as readFileSync4,
|
|
3159
3080
|
readSync,
|
|
3160
3081
|
rmSync as rmSync3,
|
|
3161
|
-
statSync as
|
|
3082
|
+
statSync as statSync4,
|
|
3162
3083
|
writeFileSync as writeFileSync2
|
|
3163
3084
|
} from "node:fs";
|
|
3164
3085
|
import { dirname as dirname5, join as join7, resolve as resolve5 } from "node:path";
|
|
@@ -3402,7 +3323,7 @@ function resolveImageSource(src, options) {
|
|
|
3402
3323
|
}
|
|
3403
3324
|
function isUsableFile2(path) {
|
|
3404
3325
|
try {
|
|
3405
|
-
return
|
|
3326
|
+
return statSync4(path).size > 0;
|
|
3406
3327
|
} catch {
|
|
3407
3328
|
return false;
|
|
3408
3329
|
}
|
|
@@ -3889,16 +3810,59 @@ function detectShaderTransitionUsage(html) {
|
|
|
3889
3810
|
}
|
|
3890
3811
|
return false;
|
|
3891
3812
|
}
|
|
3892
|
-
|
|
3813
|
+
var MAX_REMOTE_ASSETS = 1e3;
|
|
3814
|
+
var ASSET_DOWNLOADS_AT_ONCE = 8;
|
|
3815
|
+
var AssetDownloads = class {
|
|
3816
|
+
constructor(signal) {
|
|
3817
|
+
this.signal = signal;
|
|
3818
|
+
}
|
|
3819
|
+
signal;
|
|
3820
|
+
reserved = /* @__PURE__ */ new Set();
|
|
3821
|
+
running = 0;
|
|
3822
|
+
queued = [];
|
|
3823
|
+
/** Throws before any of `urls` downloads when they would take the compile past the cap. */
|
|
3824
|
+
reserve(urls) {
|
|
3825
|
+
this.signal?.throwIfAborted();
|
|
3826
|
+
const fresh = new Set([...urls].filter((url) => !this.reserved.has(url)));
|
|
3827
|
+
if (this.reserved.size + fresh.size > MAX_REMOTE_ASSETS) {
|
|
3828
|
+
throw new Error(
|
|
3829
|
+
`The composition links more than ${MAX_REMOTE_ASSETS} remote media, image and font files; at most ${MAX_REMOTE_ASSETS} are downloaded at compile time`
|
|
3830
|
+
);
|
|
3831
|
+
}
|
|
3832
|
+
for (const url of fresh) this.reserved.add(url);
|
|
3833
|
+
}
|
|
3834
|
+
async download(url, destDir) {
|
|
3835
|
+
while (this.running >= ASSET_DOWNLOADS_AT_ONCE) {
|
|
3836
|
+
await new Promise((resolve10) => this.queued.push(resolve10));
|
|
3837
|
+
}
|
|
3838
|
+
if (this.signal?.aborted) {
|
|
3839
|
+
this.queued.shift()?.();
|
|
3840
|
+
this.signal.throwIfAborted();
|
|
3841
|
+
}
|
|
3842
|
+
this.running += 1;
|
|
3843
|
+
try {
|
|
3844
|
+
return await downloadToTemp(url, destDir, void 0, this.signal, void 0, {
|
|
3845
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
3846
|
+
});
|
|
3847
|
+
} finally {
|
|
3848
|
+
this.running -= 1;
|
|
3849
|
+
this.queued.shift()?.();
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
};
|
|
3853
|
+
var downloadAsset = (url, destDir, assets) => assets ? assets.download(url, destDir) : downloadToTemp(url, destDir, void 0, void 0, void 0, {
|
|
3854
|
+
onTelemetry: logRemoteDownloadTelemetry
|
|
3855
|
+
});
|
|
3856
|
+
async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
3893
3857
|
let filePath = src;
|
|
3894
3858
|
if (isHttpUrl(src)) {
|
|
3895
3859
|
const remoteDir = join9(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
3896
3860
|
if (!existsSync7(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
|
|
3861
|
+
run?.assets.reserve([src]);
|
|
3897
3862
|
try {
|
|
3898
|
-
filePath = await
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
} catch {
|
|
3863
|
+
filePath = await downloadAsset(src, remoteDir, run?.assets);
|
|
3864
|
+
} catch (err) {
|
|
3865
|
+
if (run?.assets.signal?.aborted) throw err;
|
|
3902
3866
|
return { duration: null, resolvedPath: src };
|
|
3903
3867
|
}
|
|
3904
3868
|
} else {
|
|
@@ -3940,10 +3904,10 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
3940
3904
|
}
|
|
3941
3905
|
});
|
|
3942
3906
|
const key = `${tagName}\0${filePath}`;
|
|
3943
|
-
let probed = probes
|
|
3907
|
+
let probed = run?.probes.get(key);
|
|
3944
3908
|
if (!probed) {
|
|
3945
3909
|
probed = probe();
|
|
3946
|
-
probes
|
|
3910
|
+
run?.probes.set(key, probed);
|
|
3947
3911
|
}
|
|
3948
3912
|
const outcome = await probed;
|
|
3949
3913
|
if ("error" in outcome) {
|
|
@@ -3982,7 +3946,7 @@ function markInferredVariableMediaDurations(html, unresolvedMedia) {
|
|
|
3982
3946
|
}
|
|
3983
3947
|
return changed ? document2.toString() : html;
|
|
3984
3948
|
}
|
|
3985
|
-
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath,
|
|
3949
|
+
async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlByAbsentLocalPath, run, assetRoot) {
|
|
3986
3950
|
const { html: staticCompiled, unresolved } = compileTimingAttrs(html);
|
|
3987
3951
|
const mediaUnresolved = unresolved.filter(
|
|
3988
3952
|
(el) => (el.tagName === "video" || el.tagName === "audio") && el.src
|
|
@@ -4001,7 +3965,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
4001
3965
|
el.id,
|
|
4002
3966
|
log,
|
|
4003
3967
|
urlByAbsentLocalPath,
|
|
4004
|
-
|
|
3968
|
+
run,
|
|
4005
3969
|
assetRoot
|
|
4006
3970
|
).then(({ duration }) => ({ id: el.id, duration }))
|
|
4007
3971
|
)
|
|
@@ -4026,7 +3990,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
4026
3990
|
el.id,
|
|
4027
3991
|
log,
|
|
4028
3992
|
void 0,
|
|
4029
|
-
|
|
3993
|
+
run,
|
|
4030
3994
|
assetRoot
|
|
4031
3995
|
);
|
|
4032
3996
|
return { id: el.id, tagName: el.tagName, duration: el.duration, maxDuration, src: el.src };
|
|
@@ -4049,7 +4013,7 @@ async function compileHtmlFile(html, projectDir, baseDir, downloadDir, log, urlB
|
|
|
4049
4013
|
compiledHtml = stripCrossoriginAttr(compiledHtml, "audio");
|
|
4050
4014
|
return { html: compiledHtml, unresolvedCompositions };
|
|
4051
4015
|
}
|
|
4052
|
-
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath,
|
|
4016
|
+
async function parseSubCompositions(html, projectDir, downloadDir, visited = /* @__PURE__ */ new Set(), urlByAbsentLocalPath, run, assetRoot, outsideFiles = {}, compiledSrcs = /* @__PURE__ */ new Set()) {
|
|
4053
4017
|
const subCompositions = /* @__PURE__ */ new Map();
|
|
4054
4018
|
const { document: document2 } = parseHTML5(html);
|
|
4055
4019
|
const compEls = document2.querySelectorAll("[data-composition-src]");
|
|
@@ -4084,7 +4048,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
4084
4048
|
downloadDir,
|
|
4085
4049
|
void 0,
|
|
4086
4050
|
urlByAbsentLocalPath,
|
|
4087
|
-
|
|
4051
|
+
run,
|
|
4088
4052
|
assetRoot
|
|
4089
4053
|
);
|
|
4090
4054
|
const nested = await parseSubCompositions(
|
|
@@ -4093,7 +4057,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
4093
4057
|
downloadDir,
|
|
4094
4058
|
item.nestedVisited,
|
|
4095
4059
|
urlByAbsentLocalPath,
|
|
4096
|
-
|
|
4060
|
+
run,
|
|
4097
4061
|
assetRoot,
|
|
4098
4062
|
outsideFiles,
|
|
4099
4063
|
compiledSrcs
|
|
@@ -4291,6 +4255,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
4291
4255
|
return compHtml;
|
|
4292
4256
|
},
|
|
4293
4257
|
chargeEmitted: (srcPath, bytes) => budget.chargeGenerated(srcPath, bytes),
|
|
4258
|
+
chargeElements: (srcPath, count) => budget.chargeElements(srcPath, count),
|
|
4294
4259
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
4295
4260
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
4296
4261
|
// against its own directory, project-root refs stay as authored.
|
|
@@ -4619,18 +4584,18 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
4619
4584
|
};
|
|
4620
4585
|
}
|
|
4621
4586
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
4622
|
-
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
4587
|
+
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
|
|
4588
|
+
assets?.reserve(urlSet);
|
|
4623
4589
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
4624
4590
|
if (!existsSync7(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
|
|
4625
4591
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
4626
4592
|
await Promise.all(
|
|
4627
4593
|
[...urlSet].map(async (url) => {
|
|
4628
4594
|
try {
|
|
4629
|
-
const localPath = await
|
|
4630
|
-
onTelemetry: logRemoteDownloadTelemetry
|
|
4631
|
-
});
|
|
4595
|
+
const localPath = await downloadAsset(url, remoteDir, assets);
|
|
4632
4596
|
urlToLocal.set(url, localPath);
|
|
4633
4597
|
} catch (err) {
|
|
4598
|
+
if (assets?.signal?.aborted) throw err;
|
|
4634
4599
|
const identity = safeDownloadUrlIdentity(url);
|
|
4635
4600
|
defaultLogger.warn(`[Compiler] ${warnLabel}, using original URL as fallback.`, {
|
|
4636
4601
|
urlFingerprint: identity.urlFingerprint,
|
|
@@ -4656,14 +4621,15 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
4656
4621
|
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
4657
4622
|
return { html: result, remoteMediaAssets };
|
|
4658
4623
|
}
|
|
4659
|
-
async function localizeRemoteMediaSources(html, downloadDir) {
|
|
4624
|
+
async function localizeRemoteMediaSources(html, downloadDir, assets) {
|
|
4660
4625
|
const urlSet = /* @__PURE__ */ new Set([...remoteSrcUrls(html, "media"), ...remoteSrcUrls(html, "source")]);
|
|
4661
4626
|
const localized = await downloadAndRewriteUrls(
|
|
4662
4627
|
urlSet,
|
|
4663
4628
|
html,
|
|
4664
4629
|
join9(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4665
4630
|
"Remote media download failed",
|
|
4666
|
-
"Localized remote media source(s)"
|
|
4631
|
+
"Localized remote media source(s)",
|
|
4632
|
+
assets
|
|
4667
4633
|
);
|
|
4668
4634
|
return { ...localized, html: dropBindingOnLocalizedMedia(localized.html) };
|
|
4669
4635
|
}
|
|
@@ -4679,17 +4645,18 @@ function dropBindingOnLocalizedMedia(html) {
|
|
|
4679
4645
|
}
|
|
4680
4646
|
return changed ? document2.toString() : html;
|
|
4681
4647
|
}
|
|
4682
|
-
async function localizeRemoteImageSources(html, downloadDir) {
|
|
4648
|
+
async function localizeRemoteImageSources(html, downloadDir, assets) {
|
|
4683
4649
|
const urlSet = new Set(remoteSrcUrls(html, "img"));
|
|
4684
4650
|
return downloadAndRewriteUrls(
|
|
4685
4651
|
urlSet,
|
|
4686
4652
|
html,
|
|
4687
4653
|
join9(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4688
4654
|
"Remote image download failed",
|
|
4689
|
-
"Localized remote image source(s)"
|
|
4655
|
+
"Localized remote image source(s)",
|
|
4656
|
+
assets
|
|
4690
4657
|
);
|
|
4691
4658
|
}
|
|
4692
|
-
async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
4659
|
+
async function localizeRemoteBackgroundImages(html, downloadDir, assets) {
|
|
4693
4660
|
const urlSet = /* @__PURE__ */ new Set();
|
|
4694
4661
|
for (const { parts } of remoteBackgroundUrlMatches(html)) {
|
|
4695
4662
|
if (parts[1] && !isGoogleFontsUrl(parts[1])) urlSet.add(parts[1]);
|
|
@@ -4700,6 +4667,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
4700
4667
|
join9(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4701
4668
|
"Remote background-image download failed",
|
|
4702
4669
|
"Localized remote background-image(s)",
|
|
4670
|
+
assets,
|
|
4703
4671
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
4704
4672
|
// replaceAll; this handles the unquoted url(https://..) form.
|
|
4705
4673
|
(h, url, rel) => h.replaceAll(`url(${url})`, `url(${rel})`)
|
|
@@ -4853,13 +4821,14 @@ function collectFontFaceUrls(html) {
|
|
|
4853
4821
|
}
|
|
4854
4822
|
return urlSet;
|
|
4855
4823
|
}
|
|
4856
|
-
function localizeFontFaceUrls(html, downloadDir) {
|
|
4824
|
+
function localizeFontFaceUrls(html, downloadDir, assets) {
|
|
4857
4825
|
return downloadAndRewriteUrls(
|
|
4858
4826
|
collectFontFaceUrls(html),
|
|
4859
4827
|
html,
|
|
4860
4828
|
join9(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4861
4829
|
"Remote font download failed",
|
|
4862
4830
|
"Localized remote font face(s)",
|
|
4831
|
+
assets,
|
|
4863
4832
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
4864
4833
|
);
|
|
4865
4834
|
}
|
|
@@ -4877,16 +4846,24 @@ async function readLocalFont(absPath) {
|
|
|
4877
4846
|
}
|
|
4878
4847
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
4879
4848
|
}
|
|
4880
|
-
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
4881
|
-
const absPath = localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath);
|
|
4882
|
-
if (
|
|
4883
|
-
|
|
4884
|
-
|
|
4849
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log, downloadedPath, reserve) {
|
|
4850
|
+
const absPath = downloadedPath ?? (localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath));
|
|
4851
|
+
if (downloadedPath === void 0) {
|
|
4852
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) {
|
|
4853
|
+
return void 0;
|
|
4854
|
+
}
|
|
4855
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
4856
|
+
return void 0;
|
|
4857
|
+
}
|
|
4858
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
4885
4859
|
}
|
|
4886
|
-
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
4887
4860
|
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
4888
4861
|
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
4889
4862
|
try {
|
|
4863
|
+
if (!reserve(Math.ceil(statSync5(absPath).size / 3) * 4 + 64)) {
|
|
4864
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
4865
|
+
return void 0;
|
|
4866
|
+
}
|
|
4890
4867
|
const font = await readLocalFont(absPath);
|
|
4891
4868
|
if (font.kind === "file-backed") {
|
|
4892
4869
|
dataUriByAbsolutePath.set(absPath, void 0);
|
|
@@ -4910,9 +4887,26 @@ async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsol
|
|
|
4910
4887
|
}
|
|
4911
4888
|
}
|
|
4912
4889
|
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
4913
|
-
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
4890
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger, downloadedFonts = /* @__PURE__ */ new Map()) {
|
|
4914
4891
|
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
4915
4892
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
4893
|
+
let warned = false;
|
|
4894
|
+
const keptFileBacked = (localPath) => {
|
|
4895
|
+
if (warned) return;
|
|
4896
|
+
warned = true;
|
|
4897
|
+
log.warn(
|
|
4898
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
4899
|
+
);
|
|
4900
|
+
};
|
|
4901
|
+
let reserved = 0;
|
|
4902
|
+
const reserveFor = (localPath) => (bytes) => {
|
|
4903
|
+
if (reserved + bytes > budget.generatedRoom) {
|
|
4904
|
+
keptFileBacked(localPath);
|
|
4905
|
+
return false;
|
|
4906
|
+
}
|
|
4907
|
+
reserved += bytes;
|
|
4908
|
+
return true;
|
|
4909
|
+
};
|
|
4916
4910
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
4917
4911
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
4918
4912
|
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
@@ -4920,24 +4914,26 @@ async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = de
|
|
|
4920
4914
|
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
4921
4915
|
dataUriByPath.set(
|
|
4922
4916
|
localPath,
|
|
4923
|
-
await localFontDataUri(
|
|
4917
|
+
await localFontDataUri(
|
|
4918
|
+
localPath,
|
|
4919
|
+
projectDir,
|
|
4920
|
+
assetRoot,
|
|
4921
|
+
dataUriByAbsolutePath,
|
|
4922
|
+
log,
|
|
4923
|
+
downloadedFonts.get(localPath),
|
|
4924
|
+
reserveFor(localPath)
|
|
4925
|
+
)
|
|
4924
4926
|
);
|
|
4925
4927
|
}
|
|
4926
4928
|
}
|
|
4927
4929
|
}
|
|
4928
4930
|
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
4929
|
-
let warned = false;
|
|
4930
4931
|
const embed = (source, localPath) => {
|
|
4931
4932
|
const dataUri = dataUriByPath.get(localPath);
|
|
4932
4933
|
if (!dataUri) return source;
|
|
4933
4934
|
const inlined = `url("${dataUri}")`;
|
|
4934
4935
|
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
4935
|
-
|
|
4936
|
-
warned = true;
|
|
4937
|
-
log.warn(
|
|
4938
|
-
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
4939
|
-
);
|
|
4940
|
-
}
|
|
4936
|
+
keptFileBacked(localPath);
|
|
4941
4937
|
return source;
|
|
4942
4938
|
};
|
|
4943
4939
|
return replaceMatches(
|
|
@@ -5069,7 +5065,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5069
5065
|
options.log
|
|
5070
5066
|
);
|
|
5071
5067
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
5072
|
-
const
|
|
5068
|
+
const run = { probes: /* @__PURE__ */ new Map(), assets: new AssetDownloads(options.abortSignal) };
|
|
5073
5069
|
const { html: compiledHtml, unresolvedCompositions } = await compileHtmlFile(
|
|
5074
5070
|
rawHtml,
|
|
5075
5071
|
projectDir,
|
|
@@ -5077,7 +5073,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5077
5073
|
downloadDir,
|
|
5078
5074
|
options.log,
|
|
5079
5075
|
options.urlByAbsentLocalPath,
|
|
5080
|
-
|
|
5076
|
+
run,
|
|
5081
5077
|
assetRoot
|
|
5082
5078
|
);
|
|
5083
5079
|
const { subCompositions } = await parseSubCompositions(
|
|
@@ -5086,7 +5082,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5086
5082
|
downloadDir,
|
|
5087
5083
|
void 0,
|
|
5088
5084
|
options.urlByAbsentLocalPath,
|
|
5089
|
-
|
|
5085
|
+
run,
|
|
5090
5086
|
assetRoot,
|
|
5091
5087
|
outsideFiles
|
|
5092
5088
|
);
|
|
@@ -5139,11 +5135,12 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5139
5135
|
);
|
|
5140
5136
|
const { html: htmlWithLocalMedia, remoteMediaAssets } = await localizeRemoteMediaSources(
|
|
5141
5137
|
htmlWithDeferredScripts,
|
|
5142
|
-
downloadDir
|
|
5138
|
+
downloadDir,
|
|
5139
|
+
run.assets
|
|
5143
5140
|
);
|
|
5144
|
-
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir);
|
|
5145
|
-
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir);
|
|
5146
|
-
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir);
|
|
5141
|
+
const { html: htmlWithLocalImages, remoteMediaAssets: remoteImageAssets } = await localizeRemoteImageSources(htmlWithLocalMedia, downloadDir, run.assets);
|
|
5142
|
+
const { html: htmlWithLocalBg, remoteMediaAssets: remoteBgAssets } = await localizeRemoteBackgroundImages(htmlWithLocalImages, downloadDir, run.assets);
|
|
5143
|
+
const { html: htmlWithLocalizedFonts, remoteMediaAssets: remoteFontAssets } = await localizeFontFaceUrls(htmlWithLocalBg, downloadDir, run.assets);
|
|
5147
5144
|
const {
|
|
5148
5145
|
html: htmlWithJpegs,
|
|
5149
5146
|
preparedAssets: preparedHeifAssets,
|
|
@@ -5180,7 +5177,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5180
5177
|
projectDir,
|
|
5181
5178
|
assetRoot,
|
|
5182
5179
|
budget,
|
|
5183
|
-
options.log
|
|
5180
|
+
options.log,
|
|
5181
|
+
remoteFontAssets
|
|
5184
5182
|
);
|
|
5185
5183
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
5186
5184
|
embeddedHtml,
|
|
@@ -5653,7 +5651,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
5653
5651
|
`Entry file "${relative3(projectDir, path)}" leads outside the project folder`
|
|
5654
5652
|
);
|
|
5655
5653
|
}
|
|
5656
|
-
|
|
5654
|
+
assertCompositionFileSize2(path, relative3(projectDir, path));
|
|
5657
5655
|
return readTextFile2(path);
|
|
5658
5656
|
};
|
|
5659
5657
|
const htmlPath = join10(projectDir, entryFile);
|
|
@@ -13053,7 +13051,7 @@ import {
|
|
|
13053
13051
|
probeBeginFrameLiveness as probeBeginFrameLiveness2,
|
|
13054
13052
|
readWebGlVendorInfoFromCanvas,
|
|
13055
13053
|
resolveConfig as resolveConfig5,
|
|
13056
|
-
|
|
13054
|
+
cpuBudget as cpuBudget2
|
|
13057
13055
|
} from "@hyperframes/engine";
|
|
13058
13056
|
import { readWebGlVendorInfoFromCanvas as readWebGlVendorInfoFromCanvas2 } from "@hyperframes/engine";
|
|
13059
13057
|
var LEGACY_DISTRIBUTED_VP9_CPU_USED = 2;
|
|
@@ -13583,9 +13581,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
13583
13581
|
const captureSession = session;
|
|
13584
13582
|
session = null;
|
|
13585
13583
|
verifyStarted = Date.now();
|
|
13586
|
-
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount,
|
|
13584
|
+
overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpuBudget2()) ? encodeWhileCapturing(encodeInput, framesInChunk, {
|
|
13587
13585
|
workerCount: chunkWorkerCount,
|
|
13588
|
-
cpuCount:
|
|
13586
|
+
cpuCount: cpuBudget2()
|
|
13589
13587
|
}) : null;
|
|
13590
13588
|
await observeRenderStage(
|
|
13591
13589
|
new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.1.0",
|
|
3
3
|
"buildId": "dev",
|
|
4
|
-
"sha256": "
|
|
4
|
+
"sha256": "2b9ec8bd63b637eb9a55697e43432e9dafb356f2790240c74fbf1994ff07281c",
|
|
5
5
|
"artifacts": {
|
|
6
6
|
"iife": "hyperframe.runtime.iife.js",
|
|
7
7
|
"esm": "hyperframe.runtime.mjs"
|