@hyperframes/core 0.9.85 → 0.9.87
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/compiler/compositionSizeLimit.d.ts +3 -11
- package/dist/compiler/compositionSizeLimit.js +7 -11
- package/dist/compiler/htmlBundler.js +25 -8
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/runtime/editing/editElement.d.ts +4 -2
- package/dist/runtime/editing/editElement.js +26 -27
- package/dist/runtime/editing/textEdit.d.ts +4 -1
- package/dist/runtime/editing/textEdit.js +46 -26
- package/dist/runtime/editing/textMarkup.d.ts +4 -0
- package/dist/runtime/editing/textMarkup.js +22 -0
- package/dist/runtime/editingElement.d.ts +1 -0
- package/dist/runtime/editingGestureStart.d.ts +7 -0
- package/dist/runtime/editingGestureStart.js +11 -0
- package/dist/runtime/editingHandles.js +2 -0
- package/dist/runtime/editingPort.d.ts +13 -4
- package/dist/runtime/editingPort.js +5 -1
- package/dist/runtime/types.d.ts +7 -0
- package/package.json +4 -4
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* runs on the render server's main thread, and their cost grows with the page's size, so one huge
|
|
4
|
-
* page would hold up every other render in the same process.
|
|
5
|
-
*/
|
|
6
|
-
export declare const MAX_COMPOSITION_HTML_BYTES: number;
|
|
7
|
-
/**
|
|
8
|
-
* What one render may inline across every sub-composition mount. Each file is checked on its own
|
|
9
|
-
* above, but a few small files that mount each other many times assemble a page far larger.
|
|
10
|
-
*/
|
|
11
|
-
export declare const MAX_EXPANDED_COMPOSITION_BYTES: number;
|
|
1
|
+
import { MAX_COMPOSITION_HTML_BYTES, MAX_EXPANDED_COMPOSITION_BYTES } from "@hyperframes/lint";
|
|
2
|
+
export { MAX_COMPOSITION_HTML_BYTES, MAX_EXPANDED_COMPOSITION_BYTES };
|
|
12
3
|
/** About 4x the largest composition in 7 days of production renders (24,800 elements). */
|
|
13
4
|
export declare const MAX_EXPANDED_ELEMENTS = 100000;
|
|
14
5
|
export declare function isCompositionTooLargeError(error: unknown): error is Error;
|
|
15
6
|
export declare const REMOTE_SCRIPTS = "remote scripts";
|
|
16
7
|
export declare const REMOTE_STYLESHEETS = "remote stylesheets";
|
|
17
8
|
export declare const LOCAL_SCRIPTS = "local scripts";
|
|
9
|
+
export declare const LOCAL_STYLESHEETS = "local stylesheets";
|
|
18
10
|
export declare const ENTRY_PAGE = "the entry page";
|
|
19
11
|
/** Adds up every mount a render inlines, and what it generates for them, and throws past a limit. */
|
|
20
12
|
export declare class CompositionExpansionBudget {
|
|
@@ -1,19 +1,10 @@
|
|
|
1
1
|
import { statSync } from "node:fs";
|
|
2
|
+
import { MAX_COMPOSITION_HTML_BYTES, MAX_EXPANDED_COMPOSITION_BYTES } from "@hyperframes/lint";
|
|
2
3
|
import { terminalText } from "../terminalText.js";
|
|
3
|
-
|
|
4
|
-
* The largest entry or sub-composition HTML file a render compiles. Compiling and probing a page
|
|
5
|
-
* runs on the render server's main thread, and their cost grows with the page's size, so one huge
|
|
6
|
-
* page would hold up every other render in the same process.
|
|
7
|
-
*/
|
|
8
|
-
export const MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
4
|
+
export { MAX_COMPOSITION_HTML_BYTES, MAX_EXPANDED_COMPOSITION_BYTES };
|
|
9
5
|
const COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
10
6
|
const megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
11
7
|
const quotedForTerminalAndLogs = (file) => `"${terminalText(file)}"`;
|
|
12
|
-
/**
|
|
13
|
-
* What one render may inline across every sub-composition mount. Each file is checked on its own
|
|
14
|
-
* above, but a few small files that mount each other many times assemble a page far larger.
|
|
15
|
-
*/
|
|
16
|
-
export const MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
17
8
|
const MAX_COMPOSITION_MOUNTS = 10_000;
|
|
18
9
|
/** About 4x the largest composition in 7 days of production renders (24,800 elements). */
|
|
19
10
|
export const MAX_EXPANDED_ELEMENTS = 100_000;
|
|
@@ -40,6 +31,7 @@ const limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSI
|
|
|
40
31
|
export const REMOTE_SCRIPTS = "remote scripts";
|
|
41
32
|
export const REMOTE_STYLESHEETS = "remote stylesheets";
|
|
42
33
|
export const LOCAL_SCRIPTS = "local scripts";
|
|
34
|
+
export const LOCAL_STYLESHEETS = "local stylesheets";
|
|
43
35
|
export const ENTRY_PAGE = "the entry page";
|
|
44
36
|
function generatedTooLarge(file, bytes) {
|
|
45
37
|
if (file === "composition variables") {
|
|
@@ -54,6 +46,10 @@ function generatedTooLarge(file, bytes) {
|
|
|
54
46
|
return (`Local scripts copied into their tags add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
55
47
|
"Name each script file in one tag.");
|
|
56
48
|
}
|
|
49
|
+
if (file === LOCAL_STYLESHEETS) {
|
|
50
|
+
return (`Local stylesheets copied into the page add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
51
|
+
"Link each stylesheet once and import each file once.");
|
|
52
|
+
}
|
|
57
53
|
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
58
54
|
return (`Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
59
55
|
"Bundle scripts and fonts with the project, or link each one once.");
|
|
@@ -26,7 +26,7 @@ import { emitVariablesByCompScript, dedupeFontFaceRules, hoistFontFaceRules, sco
|
|
|
26
26
|
import { validateHyperframeHtmlContract } from "./staticGuard.js";
|
|
27
27
|
import { getHyperframeRuntimeScript } from "../generated/runtime-inline.js";
|
|
28
28
|
import { readDeclaredDefaults } from "../runtime/getVariables.js";
|
|
29
|
-
import { assertCompositionFileSize, CompositionExpansionBudget, LOCAL_SCRIPTS, } from "./compositionSizeLimit.js";
|
|
29
|
+
import { assertCompositionFileSize, CompositionExpansionBudget, LOCAL_SCRIPTS, LOCAL_STYLESHEETS, } from "./compositionSizeLimit.js";
|
|
30
30
|
import { ensureExternalLinkTag, inlineSubCompositions, isLibraryCopy, refuseSwapsReachedByRootScripts, } from "./inlineSubCompositions.js";
|
|
31
31
|
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath, isVcsOrSecretPath, resolveWithinProject, } from "../safePath.js";
|
|
32
32
|
import { ensureHfIds } from "@hyperframes/parsers/hf-ids";
|
|
@@ -200,7 +200,9 @@ function rebaseEntryAuthoredAssetPaths(document, sourceDir, projectDir) {
|
|
|
200
200
|
el.setAttribute(HF_COLOR_GRADING_ATTR, rebaseColorGradingLutPath(value, sourceDir, projectDir));
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
|
-
function inlineCssFile(css, cssFileDir, projectDir, activeImports) {
|
|
203
|
+
function inlineCssFile(css, cssFileDir, projectDir, activeImports, budget) {
|
|
204
|
+
// Charged per copy, before its imports are read: a file imported twice at every level doubles per level.
|
|
205
|
+
budget.chargeGenerated(LOCAL_STYLESHEETS, Buffer.byteLength(css));
|
|
204
206
|
const { stripped: strippedCss, comments: placeholders } = withCommentsStripped(css);
|
|
205
207
|
const withPlaceholders = replaceMatches(strippedCss, cssImportMatches(strippedCss), (full, _q1, urlPath, _q2, barePath, mediaQuery) => {
|
|
206
208
|
const importPath = urlPath ?? barePath;
|
|
@@ -217,7 +219,7 @@ function inlineCssFile(css, cssFileDir, projectDir, activeImports) {
|
|
|
217
219
|
if (content == null)
|
|
218
220
|
return full;
|
|
219
221
|
activeImports.add(resolved);
|
|
220
|
-
const inlined = inlineCssFile(content, dirname(resolved), projectDir, activeImports);
|
|
222
|
+
const inlined = inlineCssFile(content, dirname(resolved), projectDir, activeImports, budget);
|
|
221
223
|
activeImports.delete(resolved);
|
|
222
224
|
const trimmedMedia = (mediaQuery || "").trim();
|
|
223
225
|
const block = trimmedMedia ? `@media ${trimmedMedia} {\n${inlined}\n}\n` : inlined + "\n";
|
|
@@ -832,6 +834,20 @@ function localScriptPins(doc, resolvePath, tagsBySrc) {
|
|
|
832
834
|
return true;
|
|
833
835
|
};
|
|
834
836
|
}
|
|
837
|
+
/**
|
|
838
|
+
* A local script file copied in for a composition. Charged when read, so many names for one file stop at
|
|
839
|
+
* the budget; given back if a pin keeps the file external.
|
|
840
|
+
*/
|
|
841
|
+
function inlinedScriptFile(js, keepsPinned, budget) {
|
|
842
|
+
const bytes = Buffer.byteLength(js);
|
|
843
|
+
budget.chargeGenerated(LOCAL_SCRIPTS, bytes);
|
|
844
|
+
return () => {
|
|
845
|
+
if (!keepsPinned())
|
|
846
|
+
return js;
|
|
847
|
+
budget.chargeGenerated(LOCAL_SCRIPTS, -bytes);
|
|
848
|
+
return "";
|
|
849
|
+
};
|
|
850
|
+
}
|
|
835
851
|
function hoistExternalScript(src, projectDir, doc, seen, chunks, attributes) {
|
|
836
852
|
if (attributes.integrity?.trim()) {
|
|
837
853
|
ensureExternalScriptTag(doc, src, attributes);
|
|
@@ -848,7 +864,7 @@ function hoistExternalScript(src, projectDir, doc, seen, chunks, attributes) {
|
|
|
848
864
|
const js = jsPath ? readScriptOnce(jsPath) : null;
|
|
849
865
|
if (jsPath && js != null) {
|
|
850
866
|
seen.paths.add(jsPath);
|
|
851
|
-
chunks.push(
|
|
867
|
+
chunks.push(seen.inlineFile(src, js));
|
|
852
868
|
return;
|
|
853
869
|
}
|
|
854
870
|
}
|
|
@@ -960,6 +976,7 @@ async function bundleProject(projectDir, options) {
|
|
|
960
976
|
if (resolve(sourceDir) !== resolve(projectDir)) {
|
|
961
977
|
rebaseEntryAuthoredAssetPaths(document, sourceDir, projectDir);
|
|
962
978
|
}
|
|
979
|
+
const budget = new CompositionExpansionBudget();
|
|
963
980
|
for (const el of [...document.querySelectorAll('link[rel="stylesheet"]')]) {
|
|
964
981
|
const href = el.getAttribute("href");
|
|
965
982
|
if (!href || !isRelativeUrl(href) || cssStyleMergeKey(el) === undefined)
|
|
@@ -978,7 +995,7 @@ async function bundleProject(projectDir, options) {
|
|
|
978
995
|
if (value !== null)
|
|
979
996
|
style.setAttribute(name, value);
|
|
980
997
|
}
|
|
981
|
-
style.textContent = inlineCssFile(css, dirname(cssPath), projectDir, new Set([cssPath]));
|
|
998
|
+
style.textContent = inlineCssFile(css, dirname(cssPath), projectDir, new Set([cssPath]), budget);
|
|
982
999
|
el.replaceWith(style);
|
|
983
1000
|
}
|
|
984
1001
|
// Read before sub-compositions add theirs: only the root's own scripts can reach into scenes.
|
|
@@ -1001,7 +1018,6 @@ async function bundleProject(projectDir, options) {
|
|
|
1001
1018
|
const hostIdentityByElement = assignBundledRuntimeCompositionIds(trackedCompositionHosts);
|
|
1002
1019
|
const subCompositionHosts = trackedCompositionHosts.filter((host) => host.hasAttribute("data-composition-src"));
|
|
1003
1020
|
const sceneSources = new Map();
|
|
1004
|
-
const budget = new CompositionExpansionBudget();
|
|
1005
1021
|
const subCompResult = inlineSubCompositions(document, subCompositionHosts, {
|
|
1006
1022
|
resolveHtml: (srcPath) => {
|
|
1007
1023
|
if (!isRelativeUrl(srcPath))
|
|
@@ -1064,10 +1080,11 @@ async function bundleProject(projectDir, options) {
|
|
|
1064
1080
|
};
|
|
1065
1081
|
const pageScriptTags = scriptTagsBySrc(document);
|
|
1066
1082
|
const keepsEntryPinned = localScriptPins(document, resolveEntryUrl, pageScriptTags);
|
|
1083
|
+
const keepsCompPinned = localScriptPins(document, (value) => resolveWithinProject(projectDir, decodedUrlPath(value)), pageScriptTags);
|
|
1067
1084
|
const seenCompScripts = {
|
|
1068
1085
|
srcs: new Set(),
|
|
1069
1086
|
paths: new Set(),
|
|
1070
|
-
|
|
1087
|
+
inlineFile: (src, js) => inlinedScriptFile(js, () => keepsCompPinned(src), budget),
|
|
1071
1088
|
};
|
|
1072
1089
|
const scriptFile = (src) => (isRelativeUrl(src) && resolveEntryUrl(src)) || src;
|
|
1073
1090
|
const scenesByFile = new Map();
|
|
@@ -1099,7 +1116,7 @@ async function bundleProject(projectDir, options) {
|
|
|
1099
1116
|
const js = jsPath ? readScriptOnce(jsPath) : null;
|
|
1100
1117
|
if (jsPath && js != null) {
|
|
1101
1118
|
seenCompScripts.paths.add(jsPath);
|
|
1102
|
-
pushRun(scriptRuns, scene, () =>
|
|
1119
|
+
pushRun(scriptRuns, scene, inlinedScriptFile(js, () => keepsEntryPinned(extSrc), budget));
|
|
1103
1120
|
continue;
|
|
1104
1121
|
}
|
|
1105
1122
|
}
|