@hyperframes/producer 0.9.65 → 0.9.67
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 +229 -114
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +72 -71
- package/dist/index.d.ts +1 -0
- package/dist/index.js +785 -585
- package/dist/public-server.js +584 -384
- package/dist/services/compositionSizeLimit.d.ts +3 -0
- package/dist/services/htmlCompiler.d.ts +6 -8
- package/dist/services/render/cleanup.d.ts +2 -0
- package/dist/services/render/missingPath.d.ts +15 -0
- package/dist/services/render/observability.d.ts +1 -0
- package/dist/services/renderOrchestrator.d.ts +2 -0
- package/package.json +7 -7
package/dist/distributed.js
CHANGED
|
@@ -1555,6 +1555,9 @@ function normalizeErrorMessage(error) {
|
|
|
1555
1555
|
return String(error ?? "unknown error");
|
|
1556
1556
|
}
|
|
1557
1557
|
|
|
1558
|
+
// src/services/render/missingPath.ts
|
|
1559
|
+
import { errnoMissingPathOf } from "@hyperframes/core/missing-path";
|
|
1560
|
+
|
|
1558
1561
|
// src/services/render/renderEventPublisher.ts
|
|
1559
1562
|
import { cloneCaptureWarnings } from "@hyperframes/engine";
|
|
1560
1563
|
|
|
@@ -2472,6 +2475,21 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
|
2472
2475
|
`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.`,
|
|
2473
2476
|
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
2474
2477
|
);
|
|
2478
|
+
var limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
2479
|
+
var REMOTE_SCRIPTS = "remote scripts";
|
|
2480
|
+
var REMOTE_STYLESHEETS = "remote stylesheets";
|
|
2481
|
+
function generatedTooLarge(file, bytes) {
|
|
2482
|
+
if (file === "composition variables") {
|
|
2483
|
+
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
2484
|
+
}
|
|
2485
|
+
if (file === "variable media sources") {
|
|
2486
|
+
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
2487
|
+
}
|
|
2488
|
+
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
2489
|
+
return `Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. Bundle scripts and fonts with the project, or link each one once.`;
|
|
2490
|
+
}
|
|
2491
|
+
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.`;
|
|
2492
|
+
}
|
|
2475
2493
|
var CompositionExpansionBudget = class {
|
|
2476
2494
|
bytes = 0;
|
|
2477
2495
|
mounts = 0;
|
|
@@ -2480,10 +2498,16 @@ var CompositionExpansionBudget = class {
|
|
|
2480
2498
|
chargeGenerated(file, bytes) {
|
|
2481
2499
|
this.generated += bytes;
|
|
2482
2500
|
if (this.generated <= MAX_EXPANDED_COMPOSITION_BYTES) return;
|
|
2483
|
-
throw new CompositionTooLargeError(
|
|
2484
|
-
|
|
2485
|
-
|
|
2486
|
-
|
|
2501
|
+
throw new CompositionTooLargeError(generatedTooLarge(file, this.generated), {
|
|
2502
|
+
bytes: this.generated,
|
|
2503
|
+
limitBytes: MAX_EXPANDED_COMPOSITION_BYTES,
|
|
2504
|
+
exceeded: "generated"
|
|
2505
|
+
});
|
|
2506
|
+
}
|
|
2507
|
+
chargeGeneratedIfItFits(bytes) {
|
|
2508
|
+
if (this.generated + bytes > MAX_EXPANDED_COMPOSITION_BYTES) return false;
|
|
2509
|
+
this.generated += bytes;
|
|
2510
|
+
return true;
|
|
2487
2511
|
}
|
|
2488
2512
|
charge(file, bytes) {
|
|
2489
2513
|
this.bytes += bytes;
|
|
@@ -2776,6 +2800,7 @@ function placeAudio(audio, window2) {
|
|
|
2776
2800
|
import {
|
|
2777
2801
|
analyzeKeyframeIntervals,
|
|
2778
2802
|
assertMediaPayload,
|
|
2803
|
+
createConcurrencyLimit,
|
|
2779
2804
|
isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
|
|
2780
2805
|
NotMediaPayloadError as NotMediaPayloadError2,
|
|
2781
2806
|
parseMasterFxChain,
|
|
@@ -4195,7 +4220,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
4195
4220
|
}
|
|
4196
4221
|
return document2.toString();
|
|
4197
4222
|
}
|
|
4198
|
-
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles) {
|
|
4223
|
+
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles, budget) {
|
|
4199
4224
|
const { document: document2 } = parseHTML5(html);
|
|
4200
4225
|
const head = document2.querySelector("head");
|
|
4201
4226
|
const body = document2.querySelector("body");
|
|
@@ -4204,11 +4229,11 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
4204
4229
|
const emitted = emitRootCompositionVariableStyles(
|
|
4205
4230
|
document2,
|
|
4206
4231
|
{},
|
|
4207
|
-
variableOverrides
|
|
4232
|
+
variableOverrides,
|
|
4233
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
4208
4234
|
);
|
|
4209
4235
|
return { html: emitted ? document2.toString() : html, variablesByComp: {} };
|
|
4210
4236
|
}
|
|
4211
|
-
const budget = new CompositionExpansionBudget();
|
|
4212
4237
|
const readOnce = /* @__PURE__ */ new Map();
|
|
4213
4238
|
const readMountHtml = (srcPath) => {
|
|
4214
4239
|
const filePath = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
@@ -4243,6 +4268,10 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
4243
4268
|
hostIdentityMap: hostIdentityByElement,
|
|
4244
4269
|
readVariableDefaults: readDeclaredDefaults,
|
|
4245
4270
|
parseHostVariables: parseHostVariableValues,
|
|
4271
|
+
resolveFilePath: (srcPath) => {
|
|
4272
|
+
const file = resolveCompositionFile(projectDir, srcPath, assetRoot);
|
|
4273
|
+
return file && relative2(projectDir, file).split(sep3).join("/");
|
|
4274
|
+
},
|
|
4246
4275
|
resolveHtml: (srcPath) => {
|
|
4247
4276
|
const compHtml = resolveMountHtml(srcPath);
|
|
4248
4277
|
if (compHtml) budget.charge(srcPath, Buffer.byteLength(compHtml));
|
|
@@ -4333,7 +4362,8 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
4333
4362
|
emitRootCompositionVariableStyles(
|
|
4334
4363
|
document2,
|
|
4335
4364
|
result.variablesByComp,
|
|
4336
|
-
variableOverrides
|
|
4365
|
+
variableOverrides,
|
|
4366
|
+
{ chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
|
|
4337
4367
|
);
|
|
4338
4368
|
assignMediaRenderIds(document2);
|
|
4339
4369
|
return { html: document2.toString(), variablesByComp: result.variablesByComp };
|
|
@@ -4404,7 +4434,8 @@ async function downloadScript(src, mirror) {
|
|
|
4404
4434
|
}
|
|
4405
4435
|
return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
|
|
4406
4436
|
}
|
|
4407
|
-
|
|
4437
|
+
var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
|
|
4438
|
+
async function inlineExternalScripts(html, budget = new CompositionExpansionBudget()) {
|
|
4408
4439
|
const fullHtml = ensureFullDocument(html);
|
|
4409
4440
|
const wrappedFragment = fullHtml !== html;
|
|
4410
4441
|
const { document: document2 } = parseHTML5(fullHtml);
|
|
@@ -4418,20 +4449,52 @@ async function inlineExternalScripts(html) {
|
|
|
4418
4449
|
}
|
|
4419
4450
|
if (externalScripts.length === 0) return html;
|
|
4420
4451
|
const mirror = operatorGsapMirror();
|
|
4452
|
+
const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
|
|
4453
|
+
const stop = new AbortController();
|
|
4454
|
+
const fail = (error) => {
|
|
4455
|
+
stop.abort(error);
|
|
4456
|
+
throw error;
|
|
4457
|
+
};
|
|
4458
|
+
const charge = (bytes) => {
|
|
4459
|
+
try {
|
|
4460
|
+
budget.chargeGenerated(REMOTE_SCRIPTS, bytes);
|
|
4461
|
+
} catch (error) {
|
|
4462
|
+
fail(error);
|
|
4463
|
+
}
|
|
4464
|
+
};
|
|
4465
|
+
const fetches = /* @__PURE__ */ new Map();
|
|
4466
|
+
const fetchOnce = (src) => {
|
|
4467
|
+
let bytes = fetches.get(src);
|
|
4468
|
+
if (!bytes) {
|
|
4469
|
+
bytes = limit(async () => {
|
|
4470
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
4471
|
+
const downloaded = await downloadScript(src, mirror);
|
|
4472
|
+
charge(downloaded.byteLength);
|
|
4473
|
+
return downloaded;
|
|
4474
|
+
}, stop.signal);
|
|
4475
|
+
fetches.set(src, bytes);
|
|
4476
|
+
}
|
|
4477
|
+
return bytes;
|
|
4478
|
+
};
|
|
4479
|
+
const placed = /* @__PURE__ */ new Set();
|
|
4421
4480
|
const downloads = await Promise.allSettled(
|
|
4422
4481
|
externalScripts.map(async ({ el, src }) => {
|
|
4423
4482
|
const integrity = el.getAttribute("integrity") || "";
|
|
4424
|
-
|
|
4425
|
-
if (
|
|
4426
|
-
|
|
4427
|
-
}
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4483
|
+
let bytes = bundledScript(src);
|
|
4484
|
+
if (bytes && matchesScriptIntegrity(bytes, integrity)) {
|
|
4485
|
+
charge(bytes.byteLength);
|
|
4486
|
+
} else {
|
|
4487
|
+
bytes = await fetchOnce(src);
|
|
4488
|
+
if (!matchesScriptIntegrity(bytes, integrity)) {
|
|
4489
|
+
fail(new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`));
|
|
4490
|
+
}
|
|
4491
|
+
if (placed.has(src)) charge(bytes.byteLength);
|
|
4492
|
+
placed.add(src);
|
|
4431
4493
|
}
|
|
4432
4494
|
return { src, text: new TextDecoder().decode(bytes) };
|
|
4433
4495
|
})
|
|
4434
4496
|
);
|
|
4497
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
4435
4498
|
for (let i = 0; i < downloads.length; i++) {
|
|
4436
4499
|
const download = downloads[i];
|
|
4437
4500
|
const { el, src } = externalScripts[i];
|
|
@@ -4655,48 +4718,50 @@ function matchingBraces(css) {
|
|
|
4655
4718
|
}
|
|
4656
4719
|
return closes;
|
|
4657
4720
|
}
|
|
4658
|
-
|
|
4659
|
-
const
|
|
4660
|
-
|
|
4721
|
+
function remoteFontStylesheetHref(tag) {
|
|
4722
|
+
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
4723
|
+
if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
|
|
4724
|
+
return href;
|
|
4725
|
+
}
|
|
4726
|
+
async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget()) {
|
|
4727
|
+
const hrefs = /* @__PURE__ */ new Set();
|
|
4661
4728
|
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
4662
|
-
const
|
|
4663
|
-
|
|
4664
|
-
if (!hrefMatch?.[1]) continue;
|
|
4665
|
-
const href = hrefMatch[1];
|
|
4666
|
-
if (!/^https?:\/\//i.test(href)) continue;
|
|
4667
|
-
if (isGoogleFontsUrl(href)) continue;
|
|
4668
|
-
linkMatches.push({ fullMatch: tag, href });
|
|
4669
|
-
}
|
|
4670
|
-
if (linkMatches.length === 0) return html;
|
|
4671
|
-
const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
|
|
4672
|
-
const fetches = [];
|
|
4673
|
-
for (let i = 0; i < linkMatches.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
|
|
4674
|
-
const batch = linkMatches.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
|
|
4675
|
-
const results = await Promise.all(
|
|
4676
|
-
batch.map(async ({ fullMatch, href }) => {
|
|
4677
|
-
const css = await fetchExternalStylesheetCss(href);
|
|
4678
|
-
return { fullMatch, href, css };
|
|
4679
|
-
})
|
|
4680
|
-
);
|
|
4681
|
-
fetches.push(...results);
|
|
4729
|
+
const href = remoteFontStylesheetHref(parts[0]);
|
|
4730
|
+
if (href) hrefs.add(href);
|
|
4682
4731
|
}
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
const
|
|
4689
|
-
const
|
|
4732
|
+
if (hrefs.size === 0) return html;
|
|
4733
|
+
const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
|
|
4734
|
+
const inlineByHref = /* @__PURE__ */ new Map();
|
|
4735
|
+
const unique = [...hrefs];
|
|
4736
|
+
for (let i = 0; i < unique.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
|
|
4737
|
+
const batch = unique.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
|
|
4738
|
+
const sheets = await Promise.all(batch.map(fetchExternalStylesheetCss));
|
|
4739
|
+
batch.forEach((href, index) => {
|
|
4740
|
+
const css = sheets[index];
|
|
4741
|
+
const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
|
|
4742
|
+
if (fontFaceBlocks.length === 0) return;
|
|
4743
|
+
const inlineStyle = `<style>/* Inlined external font stylesheet */
|
|
4690
4744
|
${fontFaceBlocks.join("\n")}
|
|
4691
4745
|
</style>`;
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4746
|
+
budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
4747
|
+
inlineByHref.set(href, inlineStyle);
|
|
4748
|
+
const identity = safeDownloadUrlIdentity(href);
|
|
4749
|
+
defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
|
|
4750
|
+
count: fontFaceBlocks.length,
|
|
4751
|
+
urlFingerprint: identity.urlFingerprint,
|
|
4752
|
+
host: identity.host
|
|
4753
|
+
});
|
|
4697
4754
|
});
|
|
4698
4755
|
}
|
|
4699
|
-
|
|
4756
|
+
const placed = /* @__PURE__ */ new Set();
|
|
4757
|
+
return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
|
|
4758
|
+
const href = remoteFontStylesheetHref(tag);
|
|
4759
|
+
const inlineStyle = href ? inlineByHref.get(href) : void 0;
|
|
4760
|
+
if (!href || !inlineStyle) return tag;
|
|
4761
|
+
if (placed.has(href)) budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
|
|
4762
|
+
placed.add(href);
|
|
4763
|
+
return inlineStyle;
|
|
4764
|
+
});
|
|
4700
4765
|
}
|
|
4701
4766
|
function projectStylesheetFontFamilies(html, projectDir) {
|
|
4702
4767
|
const families = [];
|
|
@@ -4755,10 +4820,6 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
4755
4820
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
4756
4821
|
);
|
|
4757
4822
|
}
|
|
4758
|
-
function urlOccurrenceRe(localPath) {
|
|
4759
|
-
const escaped = localPath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4760
|
-
return new RegExp(`url\\((["']?)${escaped}\\1\\)`, "g");
|
|
4761
|
-
}
|
|
4762
4823
|
var MAX_LOCAL_FONT_DATA_URI_BYTES = 5 * 1024 * 1024;
|
|
4763
4824
|
async function readLocalFont(absPath) {
|
|
4764
4825
|
const chunks = [];
|
|
@@ -4773,59 +4834,83 @@ async function readLocalFont(absPath) {
|
|
|
4773
4834
|
}
|
|
4774
4835
|
return { kind: "inline", buffer: Buffer.concat(chunks, totalBytes) };
|
|
4775
4836
|
}
|
|
4776
|
-
async function
|
|
4777
|
-
const
|
|
4778
|
-
|
|
4779
|
-
|
|
4837
|
+
async function localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log) {
|
|
4838
|
+
const absPath = localPath.startsWith("/") ? localPath : resolve6(projectDir, localPath);
|
|
4839
|
+
if (!isPathInside(absPath, projectDir) || escapesAssetRoot(absPath, assetRoot)) return void 0;
|
|
4840
|
+
if (refusesOutsideLink(projectDir, absPath, (line) => log.warn(`[Compiler] ${line}`))) {
|
|
4841
|
+
return void 0;
|
|
4842
|
+
}
|
|
4843
|
+
if (isPrivateCompositionFile(projectDir, absPath)) return void 0;
|
|
4844
|
+
if (dataUriByAbsolutePath.has(absPath)) return dataUriByAbsolutePath.get(absPath);
|
|
4845
|
+
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
4846
|
+
try {
|
|
4847
|
+
const font = await readLocalFont(absPath);
|
|
4848
|
+
if (font.kind === "file-backed") {
|
|
4849
|
+
dataUriByAbsolutePath.set(absPath, void 0);
|
|
4850
|
+
defaultLogger.debug(
|
|
4851
|
+
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
4852
|
+
);
|
|
4853
|
+
return void 0;
|
|
4854
|
+
}
|
|
4855
|
+
const { fontToDataUri } = await import("@hyperframes/core/fonts/embed");
|
|
4856
|
+
const dataUri = await fontToDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
4857
|
+
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
4858
|
+
defaultLogger.debug(
|
|
4859
|
+
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
4860
|
+
);
|
|
4861
|
+
return dataUri;
|
|
4862
|
+
} catch (error) {
|
|
4863
|
+
defaultLogger.warn(
|
|
4864
|
+
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
4865
|
+
);
|
|
4866
|
+
return void 0;
|
|
4867
|
+
}
|
|
4868
|
+
}
|
|
4869
|
+
var replaceInner = (whole, inner, tail, next) => whole.slice(0, whole.length - tail - inner.length) + next + whole.slice(whole.length - tail);
|
|
4870
|
+
async function embedLocalFontFaces(html, projectDir, assetRoot, budget, log = defaultLogger) {
|
|
4871
|
+
const dataUriByPath = /* @__PURE__ */ new Map();
|
|
4780
4872
|
const dataUriByAbsolutePath = /* @__PURE__ */ new Map();
|
|
4781
|
-
const fileBackedAbsolutePaths = /* @__PURE__ */ new Set();
|
|
4782
4873
|
for (const { parts: style } of styleBlockMatches(html)) {
|
|
4783
4874
|
for (const { parts: face } of fontFaceBlockMatches(style[1])) {
|
|
4784
|
-
const
|
|
4785
|
-
for (const { parts } of localFontFaceUrlMatches(block)) {
|
|
4875
|
+
for (const { parts } of localFontFaceUrlMatches(face[1])) {
|
|
4786
4876
|
const localPath = parts[1];
|
|
4787
|
-
if (!localPath ||
|
|
4788
|
-
|
|
4789
|
-
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
continue;
|
|
4793
|
-
}
|
|
4794
|
-
if (isPrivateCompositionFile(projectDir, absPath)) continue;
|
|
4795
|
-
const ext = absPath.match(/\.(woff2?|ttf|otf|ttc)$/i)?.[1]?.toLowerCase() ?? "ttf";
|
|
4796
|
-
try {
|
|
4797
|
-
if (fileBackedAbsolutePaths.has(absPath)) {
|
|
4798
|
-
embeddedPaths.add(localPath);
|
|
4799
|
-
continue;
|
|
4800
|
-
}
|
|
4801
|
-
let dataUri = dataUriByAbsolutePath.get(absPath);
|
|
4802
|
-
if (!dataUri) {
|
|
4803
|
-
const font = await readLocalFont(absPath);
|
|
4804
|
-
if (font.kind === "file-backed") {
|
|
4805
|
-
fileBackedAbsolutePaths.add(absPath);
|
|
4806
|
-
defaultLogger.debug(
|
|
4807
|
-
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
4808
|
-
);
|
|
4809
|
-
embeddedPaths.add(localPath);
|
|
4810
|
-
continue;
|
|
4811
|
-
}
|
|
4812
|
-
dataUri = await toDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
4813
|
-
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
4814
|
-
defaultLogger.debug(
|
|
4815
|
-
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
4816
|
-
);
|
|
4817
|
-
}
|
|
4818
|
-
result = result.replace(urlOccurrenceRe(localPath), `url("${dataUri}")`);
|
|
4819
|
-
embeddedPaths.add(localPath);
|
|
4820
|
-
} catch (error) {
|
|
4821
|
-
defaultLogger.warn(
|
|
4822
|
-
`[Compiler] Could not embed local font ${localPath}: ${error instanceof Error ? error.message : String(error)}`
|
|
4823
|
-
);
|
|
4824
|
-
}
|
|
4877
|
+
if (!localPath || dataUriByPath.has(localPath)) continue;
|
|
4878
|
+
dataUriByPath.set(
|
|
4879
|
+
localPath,
|
|
4880
|
+
await localFontDataUri(localPath, projectDir, assetRoot, dataUriByAbsolutePath, log)
|
|
4881
|
+
);
|
|
4825
4882
|
}
|
|
4826
4883
|
}
|
|
4827
4884
|
}
|
|
4828
|
-
return
|
|
4885
|
+
if (![...dataUriByPath.values()].some(Boolean)) return html;
|
|
4886
|
+
let warned = false;
|
|
4887
|
+
const embed = (source, localPath) => {
|
|
4888
|
+
const dataUri = dataUriByPath.get(localPath);
|
|
4889
|
+
if (!dataUri) return source;
|
|
4890
|
+
const inlined = `url("${dataUri}")`;
|
|
4891
|
+
if (budget.chargeGeneratedIfItFits(inlined.length - source.length)) return inlined;
|
|
4892
|
+
if (!warned) {
|
|
4893
|
+
warned = true;
|
|
4894
|
+
log.warn(
|
|
4895
|
+
`[Compiler] Kept local font ${localPath} file-backed: the page reached its inline size limit`
|
|
4896
|
+
);
|
|
4897
|
+
}
|
|
4898
|
+
return source;
|
|
4899
|
+
};
|
|
4900
|
+
return replaceMatches(
|
|
4901
|
+
html,
|
|
4902
|
+
styleBlockMatches(html),
|
|
4903
|
+
(style, css) => replaceInner(
|
|
4904
|
+
style,
|
|
4905
|
+
css,
|
|
4906
|
+
"</style>".length,
|
|
4907
|
+
replaceMatches(
|
|
4908
|
+
css,
|
|
4909
|
+
fontFaceBlockMatches(css),
|
|
4910
|
+
(face, body) => replaceInner(face, body, 1, replaceMatches(body, localFontFaceUrlMatches(body), embed))
|
|
4911
|
+
)
|
|
4912
|
+
)
|
|
4913
|
+
);
|
|
4829
4914
|
}
|
|
4830
4915
|
function renderGsapDist() {
|
|
4831
4916
|
try {
|
|
@@ -4851,32 +4936,42 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
|
4851
4936
|
return `${prefix}${gsapDist}${file}${suffix}`;
|
|
4852
4937
|
});
|
|
4853
4938
|
}
|
|
4854
|
-
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
4939
|
+
function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath, budget) {
|
|
4855
4940
|
if (!isPathInside(htmlPath, projectDir)) return html;
|
|
4856
4941
|
const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
|
|
4857
4942
|
if (!entryPath.includes("/")) return html;
|
|
4858
4943
|
const { document: document2 } = parseHTML5(html);
|
|
4859
4944
|
const assetExists = projectAssetExists(projectDir);
|
|
4945
|
+
const charge = (bytes) => budget.chargeGenerated(entryPath, bytes);
|
|
4860
4946
|
rewriteAssetPaths(
|
|
4861
4947
|
document2.querySelectorAll("[src], [href], [srcset]"),
|
|
4862
4948
|
entryPath,
|
|
4863
4949
|
(el, attr) => el.getAttribute(attr),
|
|
4864
4950
|
(el, attr, value) => el.setAttribute(attr, value),
|
|
4865
|
-
assetExists
|
|
4951
|
+
assetExists,
|
|
4952
|
+
charge
|
|
4866
4953
|
);
|
|
4867
4954
|
rewriteInlineStyleAssetUrls(
|
|
4868
4955
|
document2.querySelectorAll("[style]"),
|
|
4869
4956
|
entryPath,
|
|
4870
4957
|
(el) => el.getAttribute("style"),
|
|
4871
4958
|
(el, value) => el.setAttribute("style", value),
|
|
4872
|
-
assetExists
|
|
4959
|
+
assetExists,
|
|
4960
|
+
charge
|
|
4873
4961
|
);
|
|
4874
4962
|
for (const style of document2.querySelectorAll("style")) {
|
|
4875
|
-
style.textContent = rewriteCssAssetUrls(
|
|
4963
|
+
style.textContent = rewriteCssAssetUrls(
|
|
4964
|
+
style.textContent || "",
|
|
4965
|
+
entryPath,
|
|
4966
|
+
assetExists,
|
|
4967
|
+
charge
|
|
4968
|
+
);
|
|
4876
4969
|
}
|
|
4877
4970
|
return document2.toString();
|
|
4878
4971
|
}
|
|
4879
|
-
|
|
4972
|
+
var MAX_VARIABLE_MEDIA_SRC_BYTES = 8 * 1024;
|
|
4973
|
+
var MEDIA_SRC_CONTROL_CHARS = /[\u0000-\u001f\u007f]/;
|
|
4974
|
+
function bindVariableMediaSources(html, variables, budget, log) {
|
|
4880
4975
|
if (!html.includes("data-var-src")) return html;
|
|
4881
4976
|
const { document: document2 } = parseHTML5(html);
|
|
4882
4977
|
const declared = {};
|
|
@@ -4887,8 +4982,17 @@ function bindVariableMediaSources(html, variables) {
|
|
|
4887
4982
|
let changed = false;
|
|
4888
4983
|
for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
|
|
4889
4984
|
if (el.closest("[data-variable-values]")) continue;
|
|
4890
|
-
const
|
|
4891
|
-
if (
|
|
4985
|
+
const bound = boundMediaSrc(el, values);
|
|
4986
|
+
if (bound === null) continue;
|
|
4987
|
+
const src = bound.trim();
|
|
4988
|
+
if (src.length > MAX_VARIABLE_MEDIA_SRC_BYTES || MEDIA_SRC_CONTROL_CHARS.test(src)) {
|
|
4989
|
+
log?.warn("[Compiler] Refused a variable media source that cannot be a URL", {
|
|
4990
|
+
length: src.length
|
|
4991
|
+
});
|
|
4992
|
+
continue;
|
|
4993
|
+
}
|
|
4994
|
+
if (el.getAttribute("src") === src) continue;
|
|
4995
|
+
budget.chargeGenerated("variable media sources", src.length);
|
|
4892
4996
|
el.setAttribute("src", src);
|
|
4893
4997
|
changed = true;
|
|
4894
4998
|
}
|
|
@@ -4908,10 +5012,18 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
4908
5012
|
throw new Error(`Entry file ${htmlPath} is not an .html file, so it is refused`);
|
|
4909
5013
|
}
|
|
4910
5014
|
assertCompositionFileSize(htmlPath, basename3(htmlPath));
|
|
4911
|
-
const
|
|
5015
|
+
const budget = new CompositionExpansionBudget();
|
|
5016
|
+
const entryHtml = rebaseDirectEntryAssetPaths(
|
|
5017
|
+
readTextFile(htmlPath),
|
|
5018
|
+
projectDir,
|
|
5019
|
+
htmlPath,
|
|
5020
|
+
budget
|
|
5021
|
+
);
|
|
4912
5022
|
const rawHtml = bindVariableMediaSources(
|
|
4913
5023
|
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
4914
|
-
options.variables ?? {}
|
|
5024
|
+
options.variables ?? {},
|
|
5025
|
+
budget,
|
|
5026
|
+
options.log
|
|
4915
5027
|
);
|
|
4916
5028
|
assertSubCompositionsUsable(rawHtml, projectDir, assetRoot, outsideFiles);
|
|
4917
5029
|
const probes = /* @__PURE__ */ new Map();
|
|
@@ -4942,7 +5054,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
4942
5054
|
projectDir,
|
|
4943
5055
|
options.variables ?? {},
|
|
4944
5056
|
assetRoot,
|
|
4945
|
-
outsideFiles
|
|
5057
|
+
outsideFiles,
|
|
5058
|
+
budget
|
|
4946
5059
|
);
|
|
4947
5060
|
const sanitizedHtml = stripPreloadNone(inlinedHtml);
|
|
4948
5061
|
const renderModeHints = detectRenderModeHints(sanitizedHtml, options.pageMotionBlur);
|
|
@@ -4950,7 +5063,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
4950
5063
|
const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
|
|
4951
5064
|
const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
|
|
4952
5065
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
4953
|
-
promoteCssImportsToLinkTags(sanitizedHtml)
|
|
5066
|
+
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
5067
|
+
budget
|
|
4954
5068
|
);
|
|
4955
5069
|
const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
|
|
4956
5070
|
injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
|
|
@@ -4962,7 +5076,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
4962
5076
|
projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
|
|
4963
5077
|
abortSignal: options.abortSignal
|
|
4964
5078
|
});
|
|
4965
|
-
const assembledHtml = await inlineExternalScripts(coalescedHtml);
|
|
5079
|
+
const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
|
|
4966
5080
|
const HF_POSITION_ATTRS = [
|
|
4967
5081
|
'data-hf-studio-path-offset="true"',
|
|
4968
5082
|
'data-hf-studio-box-size="true"',
|
|
@@ -5021,6 +5135,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5021
5135
|
htmlWithPreparedGifs,
|
|
5022
5136
|
projectDir,
|
|
5023
5137
|
assetRoot,
|
|
5138
|
+
budget,
|
|
5024
5139
|
options.log
|
|
5025
5140
|
);
|
|
5026
5141
|
const { html, externalAssets } = options.allowOutsideProjectAssets ? collectExternalAssets(
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": "0.1.0",
|
|
3
3
|
"buildId": "dev",
|
|
4
|
-
"sha256": "
|
|
4
|
+
"sha256": "86a2ef6f99a452f41a285a4644e91a0aed2ecbd865ad50d0828d958092d1cf53",
|
|
5
5
|
"artifacts": {
|
|
6
6
|
"iife": "hyperframe.runtime.iife.js",
|
|
7
7
|
"esm": "hyperframe.runtime.mjs"
|