@hyperframes/producer 0.9.66 → 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 +91 -46
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +61 -61
- package/dist/index.d.ts +1 -0
- package/dist/index.js +649 -519
- package/dist/public-server.js +448 -318
- package/dist/services/compositionSizeLimit.d.ts +2 -0
- package/dist/services/htmlCompiler.d.ts +5 -2
- 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
|
|
|
@@ -2473,6 +2476,8 @@ var fileTooLarge = (file, bytes) => new CompositionTooLargeError(
|
|
|
2473
2476
|
{ bytes, limitBytes: MAX_COMPOSITION_HTML_BYTES }
|
|
2474
2477
|
);
|
|
2475
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";
|
|
2476
2481
|
function generatedTooLarge(file, bytes) {
|
|
2477
2482
|
if (file === "composition variables") {
|
|
2478
2483
|
return `Composition variable styles add up to ${megabytes(bytes)}. ${limitText}. Shorten the variable values or declare them on fewer elements.`;
|
|
@@ -2480,6 +2485,9 @@ function generatedTooLarge(file, bytes) {
|
|
|
2480
2485
|
if (file === "variable media sources") {
|
|
2481
2486
|
return `Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. Use shorter URLs or bind fewer elements.`;
|
|
2482
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
|
+
}
|
|
2483
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.`;
|
|
2484
2492
|
}
|
|
2485
2493
|
var CompositionExpansionBudget = class {
|
|
@@ -2792,6 +2800,7 @@ function placeAudio(audio, window2) {
|
|
|
2792
2800
|
import {
|
|
2793
2801
|
analyzeKeyframeIntervals,
|
|
2794
2802
|
assertMediaPayload,
|
|
2803
|
+
createConcurrencyLimit,
|
|
2795
2804
|
isPrivateUnderAssetRoots as isPrivateUnderAssetRoots3,
|
|
2796
2805
|
NotMediaPayloadError as NotMediaPayloadError2,
|
|
2797
2806
|
parseMasterFxChain,
|
|
@@ -4425,7 +4434,8 @@ async function downloadScript(src, mirror) {
|
|
|
4425
4434
|
}
|
|
4426
4435
|
return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
|
|
4427
4436
|
}
|
|
4428
|
-
|
|
4437
|
+
var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
|
|
4438
|
+
async function inlineExternalScripts(html, budget = new CompositionExpansionBudget()) {
|
|
4429
4439
|
const fullHtml = ensureFullDocument(html);
|
|
4430
4440
|
const wrappedFragment = fullHtml !== html;
|
|
4431
4441
|
const { document: document2 } = parseHTML5(fullHtml);
|
|
@@ -4439,20 +4449,52 @@ async function inlineExternalScripts(html) {
|
|
|
4439
4449
|
}
|
|
4440
4450
|
if (externalScripts.length === 0) return html;
|
|
4441
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();
|
|
4442
4480
|
const downloads = await Promise.allSettled(
|
|
4443
4481
|
externalScripts.map(async ({ el, src }) => {
|
|
4444
4482
|
const integrity = el.getAttribute("integrity") || "";
|
|
4445
|
-
|
|
4446
|
-
if (
|
|
4447
|
-
|
|
4448
|
-
}
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
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);
|
|
4452
4493
|
}
|
|
4453
4494
|
return { src, text: new TextDecoder().decode(bytes) };
|
|
4454
4495
|
})
|
|
4455
4496
|
);
|
|
4497
|
+
if (stop.signal.aborted) throw stop.signal.reason;
|
|
4456
4498
|
for (let i = 0; i < downloads.length; i++) {
|
|
4457
4499
|
const download = downloads[i];
|
|
4458
4500
|
const { el, src } = externalScripts[i];
|
|
@@ -4676,48 +4718,50 @@ function matchingBraces(css) {
|
|
|
4676
4718
|
}
|
|
4677
4719
|
return closes;
|
|
4678
4720
|
}
|
|
4679
|
-
|
|
4680
|
-
const
|
|
4681
|
-
|
|
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();
|
|
4682
4728
|
for (const { parts } of stylesheetLinkMatches(html)) {
|
|
4683
|
-
const
|
|
4684
|
-
|
|
4685
|
-
if (!hrefMatch?.[1]) continue;
|
|
4686
|
-
const href = hrefMatch[1];
|
|
4687
|
-
if (!/^https?:\/\//i.test(href)) continue;
|
|
4688
|
-
if (isGoogleFontsUrl(href)) continue;
|
|
4689
|
-
linkMatches.push({ fullMatch: tag, href });
|
|
4690
|
-
}
|
|
4691
|
-
if (linkMatches.length === 0) return html;
|
|
4692
|
-
const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
|
|
4693
|
-
const fetches = [];
|
|
4694
|
-
for (let i = 0; i < linkMatches.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
|
|
4695
|
-
const batch = linkMatches.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
|
|
4696
|
-
const results = await Promise.all(
|
|
4697
|
-
batch.map(async ({ fullMatch, href }) => {
|
|
4698
|
-
const css = await fetchExternalStylesheetCss(href);
|
|
4699
|
-
return { fullMatch, href, css };
|
|
4700
|
-
})
|
|
4701
|
-
);
|
|
4702
|
-
fetches.push(...results);
|
|
4729
|
+
const href = remoteFontStylesheetHref(parts[0]);
|
|
4730
|
+
if (href) hrefs.add(href);
|
|
4703
4731
|
}
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
const
|
|
4710
|
-
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 */
|
|
4711
4744
|
${fontFaceBlocks.join("\n")}
|
|
4712
4745
|
</style>`;
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
|
|
4717
|
-
|
|
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
|
+
});
|
|
4718
4754
|
});
|
|
4719
4755
|
}
|
|
4720
|
-
|
|
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
|
+
});
|
|
4721
4765
|
}
|
|
4722
4766
|
function projectStylesheetFontFamilies(html, projectDir) {
|
|
4723
4767
|
const families = [];
|
|
@@ -5019,7 +5063,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5019
5063
|
const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
|
|
5020
5064
|
const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
|
|
5021
5065
|
const fontSheetHtml = await inlineExternalFontStylesheets(
|
|
5022
|
-
promoteCssImportsToLinkTags(sanitizedHtml)
|
|
5066
|
+
promoteCssImportsToLinkTags(sanitizedHtml),
|
|
5067
|
+
budget
|
|
5023
5068
|
);
|
|
5024
5069
|
const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
|
|
5025
5070
|
injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
|
|
@@ -5031,7 +5076,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
5031
5076
|
projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
|
|
5032
5077
|
abortSignal: options.abortSignal
|
|
5033
5078
|
});
|
|
5034
|
-
const assembledHtml = await inlineExternalScripts(coalescedHtml);
|
|
5079
|
+
const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
|
|
5035
5080
|
const HF_POSITION_ATTRS = [
|
|
5036
5081
|
'data-hf-studio-path-offset="true"',
|
|
5037
5082
|
'data-hf-studio-box-size="true"',
|
|
@@ -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"
|