@hyperframes/core 0.9.84 → 0.9.86
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 +4 -11
- package/dist/compiler/compositionSizeLimit.js +12 -11
- package/dist/compiler/externalScripts.d.ts +1 -1
- package/dist/compiler/externalScripts.js +4 -2
- package/dist/compiler/htmlBundler.js +144 -56
- package/dist/generated/runtime-inline.js +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/runtime/adapters/gsap.d.ts +39 -0
- package/dist/runtime/adapters/gsap.js +469 -0
- package/dist/runtime/adapters/gsapAuthoredOrder.d.ts +5 -0
- package/dist/runtime/adapters/gsapAuthoredOrder.js +27 -0
- package/dist/runtime/editing/editElement.d.ts +4 -2
- package/dist/runtime/editing/editElement.js +26 -27
- package/dist/runtime/editing/patchTween.js +11 -0
- 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/editingDraft.js +7 -3
- package/dist/runtime/editingElement.d.ts +1 -0
- package/dist/runtime/editingGestureStart.d.ts +7 -0
- package/dist/runtime/editingGestureStart.js +9 -0
- package/dist/runtime/editingHandles.js +2 -0
- package/dist/runtime/editingPort.d.ts +13 -4
- package/dist/runtime/editingPort.js +5 -1
- package/package.json +4 -4
|
@@ -1,19 +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";
|
|
8
|
+
export declare const LOCAL_SCRIPTS = "local scripts";
|
|
9
|
+
export declare const LOCAL_STYLESHEETS = "local stylesheets";
|
|
17
10
|
export declare const ENTRY_PAGE = "the entry page";
|
|
18
11
|
/** Adds up every mount a render inlines, and what it generates for them, and throws past a limit. */
|
|
19
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;
|
|
@@ -39,6 +30,8 @@ const fileTooLarge = (file, bytes) => new CompositionTooLargeError(`Composition
|
|
|
39
30
|
const limitText = `One render generates at most ${megabytes(MAX_EXPANDED_COMPOSITION_BYTES)}`;
|
|
40
31
|
export const REMOTE_SCRIPTS = "remote scripts";
|
|
41
32
|
export const REMOTE_STYLESHEETS = "remote stylesheets";
|
|
33
|
+
export const LOCAL_SCRIPTS = "local scripts";
|
|
34
|
+
export const LOCAL_STYLESHEETS = "local stylesheets";
|
|
42
35
|
export const ENTRY_PAGE = "the entry page";
|
|
43
36
|
function generatedTooLarge(file, bytes) {
|
|
44
37
|
if (file === "composition variables") {
|
|
@@ -49,6 +42,14 @@ function generatedTooLarge(file, bytes) {
|
|
|
49
42
|
return (`Variable-bound media sources add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
50
43
|
"Use shorter URLs or bind fewer elements.");
|
|
51
44
|
}
|
|
45
|
+
if (file === LOCAL_SCRIPTS) {
|
|
46
|
+
return (`Local scripts copied into their tags add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
47
|
+
"Name each script file in one tag.");
|
|
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
|
+
}
|
|
52
53
|
if (file === REMOTE_SCRIPTS || file === REMOTE_STYLESHEETS) {
|
|
53
54
|
return (`Inlined ${file} add up to ${megabytes(bytes)}. ${limitText}. ` +
|
|
54
55
|
"Bundle scripts and fonts with the project, or link each one once.");
|
|
@@ -5,4 +5,4 @@ export interface ExternalScriptAttributes {
|
|
|
5
5
|
}
|
|
6
6
|
export declare function readExternalScriptAttributes(el: Element): ExternalScriptAttributes;
|
|
7
7
|
/** Deduplicate scripts without discarding a nested composition's integrity requirement. */
|
|
8
|
-
export declare function ensureExternalScriptTag(doc: Document, src: string, attributes?: ExternalScriptAttributes):
|
|
8
|
+
export declare function ensureExternalScriptTag(doc: Document, src: string, attributes?: ExternalScriptAttributes, tagsWithSrc?: Element[]): Element[];
|
|
@@ -9,8 +9,9 @@ export function readExternalScriptAttributes(el) {
|
|
|
9
9
|
return attributes;
|
|
10
10
|
}
|
|
11
11
|
/** Deduplicate scripts without discarding a nested composition's integrity requirement. */
|
|
12
|
-
export function ensureExternalScriptTag(doc, src, attributes = {}) {
|
|
13
|
-
const existing =
|
|
12
|
+
export function ensureExternalScriptTag(doc, src, attributes = {}, tagsWithSrc) {
|
|
13
|
+
const existing = tagsWithSrc ??
|
|
14
|
+
[...doc.querySelectorAll("script[src]")].filter((el) => el.getAttribute("src")?.trim() === src);
|
|
14
15
|
const requirements = new Set([attributes.integrity, ...existing.map((el) => el.getAttribute("integrity"))]
|
|
15
16
|
.map((value) => value
|
|
16
17
|
?.trim()
|
|
@@ -34,4 +35,5 @@ export function ensureExternalScriptTag(doc, src, attributes = {}) {
|
|
|
34
35
|
el.setAttribute("src", src);
|
|
35
36
|
doc.body.appendChild(el);
|
|
36
37
|
}
|
|
38
|
+
return elements;
|
|
37
39
|
}
|
|
@@ -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 } 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";
|
|
@@ -89,6 +89,14 @@ function safeReadFile(filePath) {
|
|
|
89
89
|
return null;
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
+
function readScriptOnce(filePath) {
|
|
93
|
+
const scripts = bundleReads.getStore()?.scripts;
|
|
94
|
+
if (!scripts)
|
|
95
|
+
return safeReadFile(filePath);
|
|
96
|
+
if (!scripts.has(filePath))
|
|
97
|
+
scripts.set(filePath, safeReadFile(filePath));
|
|
98
|
+
return scripts.get(filePath) ?? null;
|
|
99
|
+
}
|
|
92
100
|
const CSS_PLACEHOLDER_RE = /\/\*__hf_(?:c|import_)\d+__\*\//g;
|
|
93
101
|
export function restoreCssPlaceholders(css, texts) {
|
|
94
102
|
return css.replace(CSS_PLACEHOLDER_RE, (placeholder) => texts.get(placeholder) ?? placeholder);
|
|
@@ -192,7 +200,9 @@ function rebaseEntryAuthoredAssetPaths(document, sourceDir, projectDir) {
|
|
|
192
200
|
el.setAttribute(HF_COLOR_GRADING_ATTR, rebaseColorGradingLutPath(value, sourceDir, projectDir));
|
|
193
201
|
}
|
|
194
202
|
}
|
|
195
|
-
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));
|
|
196
206
|
const { stripped: strippedCss, comments: placeholders } = withCommentsStripped(css);
|
|
197
207
|
const withPlaceholders = replaceMatches(strippedCss, cssImportMatches(strippedCss), (full, _q1, urlPath, _q2, barePath, mediaQuery) => {
|
|
198
208
|
const importPath = urlPath ?? barePath;
|
|
@@ -209,7 +219,7 @@ function inlineCssFile(css, cssFileDir, projectDir, activeImports) {
|
|
|
209
219
|
if (content == null)
|
|
210
220
|
return full;
|
|
211
221
|
activeImports.add(resolved);
|
|
212
|
-
const inlined = inlineCssFile(content, dirname(resolved), projectDir, activeImports);
|
|
222
|
+
const inlined = inlineCssFile(content, dirname(resolved), projectDir, activeImports, budget);
|
|
213
223
|
activeImports.delete(resolved);
|
|
214
224
|
const trimmedMedia = (mediaQuery || "").trim();
|
|
215
225
|
const block = trimmedMedia ? `@media ${trimmedMedia} {\n${inlined}\n}\n` : inlined + "\n";
|
|
@@ -772,36 +782,89 @@ async function stripJsCommentsParserSafe(source, provenance) {
|
|
|
772
782
|
async function inlineScriptSource(js, provenance) {
|
|
773
783
|
return escapeInlineScriptSource(await stripJsCommentsParserSafe(js, provenance));
|
|
774
784
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
el.getAttribute("
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
785
|
+
/** The page's script tags by `src`, collected at first use; a pin carried to a new spelling adds its tag. */
|
|
786
|
+
function scriptTagsBySrc(doc) {
|
|
787
|
+
let index;
|
|
788
|
+
return () => {
|
|
789
|
+
if (index)
|
|
790
|
+
return index;
|
|
791
|
+
index = new Map();
|
|
792
|
+
for (const el of doc.querySelectorAll("script[src]")) {
|
|
793
|
+
const src = el.getAttribute("src")?.trim() ?? "";
|
|
794
|
+
const tags = index.get(src);
|
|
795
|
+
if (tags)
|
|
796
|
+
tags.push(el);
|
|
797
|
+
else
|
|
798
|
+
index.set(src, [el]);
|
|
799
|
+
}
|
|
800
|
+
return index;
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
/** Whether a local script stays external because a tag pins its file; the page's pins are indexed once. */
|
|
804
|
+
function localScriptPins(doc, resolvePath, tagsBySrc) {
|
|
805
|
+
let pins;
|
|
806
|
+
const carried = new Set();
|
|
807
|
+
return (src) => {
|
|
808
|
+
if (!pins) {
|
|
809
|
+
pins = new Map();
|
|
810
|
+
for (const el of doc.querySelectorAll("script[src][integrity]")) {
|
|
811
|
+
const candidate = el.getAttribute("src") || "";
|
|
812
|
+
if (!isRelativeUrl(candidate) || !el.getAttribute("integrity")?.trim())
|
|
813
|
+
continue;
|
|
814
|
+
const path = resolvePath(candidate);
|
|
815
|
+
if (!path)
|
|
816
|
+
continue;
|
|
817
|
+
const attributes = readExternalScriptAttributes(el);
|
|
818
|
+
const key = JSON.stringify(attributes);
|
|
819
|
+
const byAttributes = pins.get(path) ?? new Map();
|
|
820
|
+
byAttributes.delete(key);
|
|
821
|
+
pins.set(path, byAttributes.set(key, attributes));
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
const path = resolvePath(src);
|
|
825
|
+
const pinned = path ? pins.get(path) : undefined;
|
|
826
|
+
if (!pinned)
|
|
827
|
+
return false;
|
|
828
|
+
if (!carried.has(src)) {
|
|
829
|
+
carried.add(src);
|
|
830
|
+
const index = tagsBySrc();
|
|
831
|
+
for (const attributes of pinned.values())
|
|
832
|
+
index.set(src, ensureExternalScriptTag(doc, src, attributes, index.get(src) ?? []));
|
|
833
|
+
}
|
|
834
|
+
return true;
|
|
835
|
+
};
|
|
788
836
|
}
|
|
789
|
-
|
|
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
|
+
}
|
|
851
|
+
function hoistExternalScript(src, projectDir, doc, seen, chunks, attributes) {
|
|
790
852
|
if (attributes.integrity?.trim()) {
|
|
791
853
|
ensureExternalScriptTag(doc, src, attributes);
|
|
792
|
-
|
|
854
|
+
seen.srcs.add(src);
|
|
793
855
|
return;
|
|
794
856
|
}
|
|
795
|
-
if (
|
|
857
|
+
if (seen.srcs.has(src))
|
|
796
858
|
return;
|
|
797
|
-
|
|
859
|
+
seen.srcs.add(src);
|
|
798
860
|
if (!isNonRelativeUrl(src) && !isAbsolute(src) && attributes.type !== "module") {
|
|
799
861
|
const jsPath = resolveWithinProject(projectDir, decodedUrlPath(src));
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
862
|
+
if (jsPath && seen.paths.has(jsPath))
|
|
863
|
+
return;
|
|
864
|
+
const js = jsPath ? readScriptOnce(jsPath) : null;
|
|
865
|
+
if (jsPath && js != null) {
|
|
866
|
+
seen.paths.add(jsPath);
|
|
867
|
+
chunks.push(seen.inlineFile(src, js));
|
|
805
868
|
return;
|
|
806
869
|
}
|
|
807
870
|
}
|
|
@@ -823,7 +886,7 @@ function hoistCompositionScripts(container, opts) {
|
|
|
823
886
|
opts.moduleScripts.push(prelude + (scriptEl.textContent || ""));
|
|
824
887
|
}
|
|
825
888
|
else if (externalSrc) {
|
|
826
|
-
hoistExternalScript(externalSrc, opts.projectDir, opts.document, opts.
|
|
889
|
+
hoistExternalScript(externalSrc, opts.projectDir, opts.document, opts.seenCompScripts, opts.compScriptChunks, readExternalScriptAttributes(scriptEl));
|
|
827
890
|
}
|
|
828
891
|
else {
|
|
829
892
|
opts.compScriptChunks.push(opts.compId
|
|
@@ -846,6 +909,7 @@ export function bundleToSingleHtml(projectDir, options) {
|
|
|
846
909
|
projectDir,
|
|
847
910
|
privateFiles: options?.privateFiles ?? "studio",
|
|
848
911
|
noteRead,
|
|
912
|
+
scripts: new Map(),
|
|
849
913
|
};
|
|
850
914
|
return bundleReads.run(scope, () => bundleProject(projectDir, options));
|
|
851
915
|
}
|
|
@@ -912,6 +976,7 @@ async function bundleProject(projectDir, options) {
|
|
|
912
976
|
if (resolve(sourceDir) !== resolve(projectDir)) {
|
|
913
977
|
rebaseEntryAuthoredAssetPaths(document, sourceDir, projectDir);
|
|
914
978
|
}
|
|
979
|
+
const budget = new CompositionExpansionBudget();
|
|
915
980
|
for (const el of [...document.querySelectorAll('link[rel="stylesheet"]')]) {
|
|
916
981
|
const href = el.getAttribute("href");
|
|
917
982
|
if (!href || !isRelativeUrl(href) || cssStyleMergeKey(el) === undefined)
|
|
@@ -930,29 +995,29 @@ async function bundleProject(projectDir, options) {
|
|
|
930
995
|
if (value !== null)
|
|
931
996
|
style.setAttribute(name, value);
|
|
932
997
|
}
|
|
933
|
-
style.textContent = inlineCssFile(css, dirname(cssPath), projectDir, new Set([cssPath]));
|
|
998
|
+
style.textContent = inlineCssFile(css, dirname(cssPath), projectDir, new Set([cssPath]), budget);
|
|
934
999
|
el.replaceWith(style);
|
|
935
1000
|
}
|
|
936
1001
|
// Read before sub-compositions add theirs: only the root's own scripts can reach into scenes.
|
|
937
1002
|
const rootScripts = options?.sceneParts
|
|
938
1003
|
? [
|
|
939
|
-
...
|
|
940
|
-
|
|
941
|
-
...
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1004
|
+
...new Set([
|
|
1005
|
+
...document.querySelectorAll(`script:not([${RUNTIME_BOOTSTRAP_ATTR}])`),
|
|
1006
|
+
...[...document.querySelectorAll("template")].flatMap((t) => [
|
|
1007
|
+
...(templateContent(t)?.querySelectorAll("script") ?? []),
|
|
1008
|
+
]),
|
|
1009
|
+
].map((el) => {
|
|
1010
|
+
const src = el.getAttribute("src");
|
|
1011
|
+
const path = src && isRelativeUrl(src) ? resolveEntryUrl(src) : null;
|
|
1012
|
+
return src ? (path && readScriptOnce(path)) || "" : el.textContent || "";
|
|
1013
|
+
})),
|
|
1014
|
+
].map((text) => (isLibraryCopy(text) ? "" : text))
|
|
949
1015
|
: [];
|
|
950
1016
|
// Inline sub-compositions (via shared function)
|
|
951
1017
|
const trackedCompositionHosts = getBundledTrackedCompositionHosts(document);
|
|
952
1018
|
const hostIdentityByElement = assignBundledRuntimeCompositionIds(trackedCompositionHosts);
|
|
953
1019
|
const subCompositionHosts = trackedCompositionHosts.filter((host) => host.hasAttribute("data-composition-src"));
|
|
954
1020
|
const sceneSources = new Map();
|
|
955
|
-
const budget = new CompositionExpansionBudget();
|
|
956
1021
|
const subCompResult = inlineSubCompositions(document, subCompositionHosts, {
|
|
957
1022
|
resolveHtml: (srcPath) => {
|
|
958
1023
|
if (!isRelativeUrl(srcPath))
|
|
@@ -993,7 +1058,7 @@ async function bundleProject(projectDir, options) {
|
|
|
993
1058
|
tagScenes: options?.sceneParts === true,
|
|
994
1059
|
readProjectScript: (path) => {
|
|
995
1060
|
const resolved = isRelativeUrl(path) ? resolveEntryUrl(path) : null;
|
|
996
|
-
return resolved ?
|
|
1061
|
+
return resolved ? readScriptOnce(resolved) : null;
|
|
997
1062
|
},
|
|
998
1063
|
readVariableDefaults: readDeclaredDefaults,
|
|
999
1064
|
parseHostVariables: parseHostVariableValues,
|
|
@@ -1013,11 +1078,21 @@ async function bundleProject(projectDir, options) {
|
|
|
1013
1078
|
const compVariablesByComp = {
|
|
1014
1079
|
...subCompResult.variablesByComp,
|
|
1015
1080
|
};
|
|
1016
|
-
const
|
|
1017
|
-
const
|
|
1081
|
+
const pageScriptTags = scriptTagsBySrc(document);
|
|
1082
|
+
const keepsEntryPinned = localScriptPins(document, resolveEntryUrl, pageScriptTags);
|
|
1083
|
+
const keepsCompPinned = localScriptPins(document, (value) => resolveWithinProject(projectDir, decodedUrlPath(value)), pageScriptTags);
|
|
1084
|
+
const seenCompScripts = {
|
|
1085
|
+
srcs: new Set(),
|
|
1086
|
+
paths: new Set(),
|
|
1087
|
+
inlineFile: (src, js) => inlinedScriptFile(js, () => keepsCompPinned(src), budget),
|
|
1088
|
+
};
|
|
1089
|
+
const scriptFile = (src) => (isRelativeUrl(src) && resolveEntryUrl(src)) || src;
|
|
1090
|
+
const scenesByFile = new Map();
|
|
1018
1091
|
for (const item of subCompResult.scriptItems)
|
|
1019
|
-
if (item.kind !== "inline")
|
|
1020
|
-
|
|
1092
|
+
if (item.kind !== "inline") {
|
|
1093
|
+
const file = scriptFile(item.src);
|
|
1094
|
+
scenesByFile.set(file, (scenesByFile.get(file) ?? new Set()).add(item.scene));
|
|
1095
|
+
}
|
|
1021
1096
|
for (const scriptItem of subCompResult.scriptItems) {
|
|
1022
1097
|
if (scriptItem.kind === "inline") {
|
|
1023
1098
|
pushRun(scriptRuns, scriptItem.scene, scriptItem.content);
|
|
@@ -1026,20 +1101,22 @@ async function bundleProject(projectDir, options) {
|
|
|
1026
1101
|
const extSrc = scriptItem.src;
|
|
1027
1102
|
if (scriptItem.integrity?.trim()) {
|
|
1028
1103
|
ensureExternalScriptTag(document, extSrc, scriptItem);
|
|
1029
|
-
|
|
1104
|
+
seenCompScripts.srcs.add(extSrc);
|
|
1030
1105
|
continue;
|
|
1031
1106
|
}
|
|
1032
|
-
if (
|
|
1107
|
+
if (seenCompScripts.srcs.has(extSrc))
|
|
1033
1108
|
continue;
|
|
1034
|
-
|
|
1109
|
+
seenCompScripts.srcs.add(extSrc);
|
|
1035
1110
|
// Run once for the film when scenes share it: a scene mounts without the one that loaded it first.
|
|
1036
|
-
const scene = (
|
|
1111
|
+
const scene = (scenesByFile.get(scriptFile(extSrc))?.size ?? 0) > 1 ? undefined : scriptItem.scene;
|
|
1037
1112
|
if (isRelativeUrl(extSrc) && scriptItem.type !== "module") {
|
|
1038
1113
|
const jsPath = resolveEntryUrl(extSrc);
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1114
|
+
if (jsPath && seenCompScripts.paths.has(jsPath))
|
|
1115
|
+
continue;
|
|
1116
|
+
const js = jsPath ? readScriptOnce(jsPath) : null;
|
|
1117
|
+
if (jsPath && js != null) {
|
|
1118
|
+
seenCompScripts.paths.add(jsPath);
|
|
1119
|
+
pushRun(scriptRuns, scene, inlinedScriptFile(js, () => keepsEntryPinned(extSrc), budget));
|
|
1043
1120
|
continue;
|
|
1044
1121
|
}
|
|
1045
1122
|
}
|
|
@@ -1108,7 +1185,7 @@ async function bundleProject(projectDir, options) {
|
|
|
1108
1185
|
runtimeScope,
|
|
1109
1186
|
runtimeCompId,
|
|
1110
1187
|
authoredRootId: authoredRootId ?? undefined,
|
|
1111
|
-
|
|
1188
|
+
seenCompScripts,
|
|
1112
1189
|
compScriptChunks,
|
|
1113
1190
|
importMaps: subCompResult.importMaps,
|
|
1114
1191
|
moduleScripts: subCompResult.moduleScripts,
|
|
@@ -1143,7 +1220,7 @@ async function bundleProject(projectDir, options) {
|
|
|
1143
1220
|
runtimeScope,
|
|
1144
1221
|
runtimeCompId,
|
|
1145
1222
|
authoredRootId: undefined,
|
|
1146
|
-
|
|
1223
|
+
seenCompScripts,
|
|
1147
1224
|
compScriptChunks,
|
|
1148
1225
|
importMaps: subCompResult.importMaps,
|
|
1149
1226
|
moduleScripts: subCompResult.moduleScripts,
|
|
@@ -1156,11 +1233,14 @@ async function bundleProject(projectDir, options) {
|
|
|
1156
1233
|
// Remove the template element from the document
|
|
1157
1234
|
templateEl.remove();
|
|
1158
1235
|
}
|
|
1236
|
+
// A file named by several regular (or nomodule) tags runs once, as a composition's scripts do: a copy per tag grew
|
|
1237
|
+
// the page past memory. Data blocks each keep their text; every copy is charged to the page's budget.
|
|
1238
|
+
const inlinedRootRuns = new Set();
|
|
1159
1239
|
for (const el of [...document.querySelectorAll("script[src]")]) {
|
|
1160
1240
|
const src = el.getAttribute("src");
|
|
1161
1241
|
if (!src || !isRelativeUrl(src))
|
|
1162
1242
|
continue;
|
|
1163
|
-
if (
|
|
1243
|
+
if (keepsEntryPinned(src))
|
|
1164
1244
|
continue;
|
|
1165
1245
|
// Module scripts can contain static imports whose resolution is relative
|
|
1166
1246
|
// to the script URL. Folding their source into a classic inline script
|
|
@@ -1168,9 +1248,17 @@ async function bundleProject(projectDir, options) {
|
|
|
1168
1248
|
if ((el.getAttribute("type") || "").trim().toLowerCase() === "module")
|
|
1169
1249
|
continue;
|
|
1170
1250
|
const jsPath = resolveEntryUrl(src);
|
|
1171
|
-
const
|
|
1172
|
-
if (
|
|
1251
|
+
const run = isJavaScriptType(el) ? `${el.hasAttribute("nomodule")} ${jsPath}` : null;
|
|
1252
|
+
if (jsPath && run !== null && inlinedRootRuns.has(run)) {
|
|
1253
|
+
el.remove();
|
|
1254
|
+
continue;
|
|
1255
|
+
}
|
|
1256
|
+
const js = jsPath ? readScriptOnce(jsPath) : null;
|
|
1257
|
+
if (!jsPath || js == null)
|
|
1173
1258
|
continue;
|
|
1259
|
+
budget.chargeGenerated(LOCAL_SCRIPTS, Buffer.byteLength(js));
|
|
1260
|
+
if (run !== null)
|
|
1261
|
+
inlinedRootRuns.add(run);
|
|
1174
1262
|
el.setAttribute(INLINED_FILE_ATTR, src);
|
|
1175
1263
|
el.removeAttribute("src");
|
|
1176
1264
|
el.textContent = js;
|