@ms-cloudpack/inline-scripts 0.2.50 → 0.2.52
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.
|
@@ -1 +1,35 @@
|
|
|
1
|
+
type ExtendedHTMLScriptElement = HTMLScriptElement & {
|
|
2
|
+
__captured?: boolean;
|
|
3
|
+
};
|
|
4
|
+
declare function isScriptTag(node: Node): node is ExtendedHTMLScriptElement;
|
|
5
|
+
/**
|
|
6
|
+
* Manages the deferral and controlled execution of script tags.
|
|
7
|
+
*
|
|
8
|
+
* This class captures script tags (both existing and dynamically added) to prevent
|
|
9
|
+
* their immediate execution, then reinserts them later to execute in their original
|
|
10
|
+
* document positions once async dependencies have loaded.
|
|
11
|
+
*/
|
|
12
|
+
declare class ScriptDeferralQueue {
|
|
13
|
+
/**
|
|
14
|
+
* Scripts captured for deferred execution, along with their original DOM positions.
|
|
15
|
+
*/
|
|
16
|
+
private deferredScripts;
|
|
17
|
+
private observer;
|
|
18
|
+
private captureScript;
|
|
19
|
+
/**
|
|
20
|
+
* Captures all script tags that appear after the current script in the document.
|
|
21
|
+
* Called once at initialization to defer existing scripts.
|
|
22
|
+
*/
|
|
23
|
+
captureExistingScripts(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Begins observing the document for dynamically added script tags.
|
|
26
|
+
* Any new scripts detected will be automatically captured for deferred execution.
|
|
27
|
+
*/
|
|
28
|
+
startCapturing(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Stops observing for new scripts and executes all deferred scripts in their original order.
|
|
31
|
+
* Scripts are recreated and reinserted into their original DOM positions to trigger execution.
|
|
32
|
+
*/
|
|
33
|
+
flushQueue(): void;
|
|
34
|
+
}
|
|
1
35
|
//# sourceMappingURL=bootstrap.inline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.inline.d.ts","sourceRoot":"","sources":["../src/bootstrap.inline.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"bootstrap.inline.d.ts","sourceRoot":"","sources":["../src/bootstrap.inline.ts"],"names":[],"mappings":"AAAA,KAAK,yBAAyB,GAAG,iBAAiB,GAAG;IAAE,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9E,iBAAS,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,IAAI,yBAAyB,CAElE;AAED;;;;;;GAMG;AACH,cAAM,mBAAmB;IACvB;;OAEG;IACH,OAAO,CAAC,eAAe,CAClB;IACL,OAAO,CAAC,QAAQ,CAAiC;IAEjD,OAAO,CAAC,aAAa;IAcrB;;;OAGG;IACI,sBAAsB;IAS7B;;;OAGG;IACI,cAAc;IAmBrB;;;OAGG;IACI,UAAU;CAgClB"}
|
package/lib/bootstrap.inline.js
CHANGED
|
@@ -1,12 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
function isScriptTag(node) {
|
|
3
|
+
return node.nodeType === Node.ELEMENT_NODE && node.tagName === 'SCRIPT';
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Manages the deferral and controlled execution of script tags.
|
|
7
|
+
*
|
|
8
|
+
* This class captures script tags (both existing and dynamically added) to prevent
|
|
9
|
+
* their immediate execution, then reinserts them later to execute in their original
|
|
10
|
+
* document positions once async dependencies have loaded.
|
|
11
|
+
*/
|
|
12
|
+
class ScriptDeferralQueue {
|
|
13
|
+
/**
|
|
14
|
+
* Scripts captured for deferred execution, along with their original DOM positions.
|
|
15
|
+
*/
|
|
16
|
+
deferredScripts = [];
|
|
17
|
+
observer = null;
|
|
18
|
+
captureScript(script) {
|
|
19
|
+
// Avoid capturing the same script more than once
|
|
20
|
+
if (script.__captured)
|
|
21
|
+
return;
|
|
22
|
+
script.__captured = true;
|
|
23
|
+
const parent = script.parentNode;
|
|
24
|
+
const nextSibling = script.nextSibling;
|
|
25
|
+
if (parent) {
|
|
26
|
+
parent.removeChild(script);
|
|
27
|
+
}
|
|
28
|
+
this.deferredScripts.push({ script, parent, nextSibling });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Captures all script tags that appear after the current script in the document.
|
|
32
|
+
* Called once at initialization to defer existing scripts.
|
|
33
|
+
*/
|
|
34
|
+
captureExistingScripts() {
|
|
35
|
+
const currentScript = document.currentScript;
|
|
36
|
+
if (currentScript) {
|
|
37
|
+
Array.from(document.querySelectorAll('script'))
|
|
38
|
+
.filter((script) => currentScript.compareDocumentPosition(script) & Node.DOCUMENT_POSITION_FOLLOWING)
|
|
39
|
+
.forEach((script) => this.captureScript(script));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Begins observing the document for dynamically added script tags.
|
|
44
|
+
* Any new scripts detected will be automatically captured for deferred execution.
|
|
45
|
+
*/
|
|
46
|
+
startCapturing() {
|
|
47
|
+
if (this.observer) {
|
|
48
|
+
return; // Already observing
|
|
49
|
+
}
|
|
50
|
+
this.observer = new MutationObserver((mutations) => {
|
|
51
|
+
for (const mutation of mutations) {
|
|
52
|
+
mutation.addedNodes.forEach((node) => {
|
|
53
|
+
if (isScriptTag(node)) {
|
|
54
|
+
this.captureScript(node);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
// Start observing the entire document
|
|
60
|
+
this.observer.observe(document.documentElement, { childList: true, subtree: true });
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Stops observing for new scripts and executes all deferred scripts in their original order.
|
|
64
|
+
* Scripts are recreated and reinserted into their original DOM positions to trigger execution.
|
|
65
|
+
*/
|
|
66
|
+
flushQueue() {
|
|
67
|
+
if (this.observer) {
|
|
68
|
+
this.observer.disconnect();
|
|
69
|
+
this.observer = null;
|
|
70
|
+
}
|
|
71
|
+
// Reinsert all captured script elements in their original locations
|
|
72
|
+
for (const { script, parent, nextSibling } of this.deferredScripts) {
|
|
73
|
+
// Create a new script element to trigger execution
|
|
74
|
+
const newScript = document.createElement('script');
|
|
75
|
+
// Copy all attributes (like src, type, etc.)
|
|
76
|
+
for (const attr of Array.from(script.attributes)) {
|
|
77
|
+
newScript.setAttribute(attr.name, attr.value);
|
|
78
|
+
}
|
|
79
|
+
// Copy inline script content
|
|
80
|
+
newScript.textContent = script.textContent;
|
|
81
|
+
// Check if nextSibling is still a child of parent
|
|
82
|
+
if (parent && nextSibling && nextSibling.parentNode === parent) {
|
|
83
|
+
parent.insertBefore(newScript, nextSibling);
|
|
84
|
+
}
|
|
85
|
+
else if (parent) {
|
|
86
|
+
parent.appendChild(newScript);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
// Fallback if parent is not available
|
|
90
|
+
document.body.appendChild(newScript);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
// Clear the list after reinsertion
|
|
94
|
+
this.deferredScripts = [];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
2
97
|
window.__cloudpack ??= {};
|
|
3
|
-
window.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entryScripts }) => {
|
|
98
|
+
window.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entryScripts, deferScripts }) => {
|
|
4
99
|
window.__cloudpack ??= {};
|
|
5
100
|
if (window.__cloudpack.hasBootstrapRun) {
|
|
6
101
|
console.warn('Cloudpack bootstrap has already run, skipping.');
|
|
7
102
|
return;
|
|
8
103
|
}
|
|
9
104
|
window.__cloudpack.hasBootstrapRun = true;
|
|
105
|
+
// If deferScripts is true, set up the ScriptDeferralQueue so that we can capture scripts added before and during the async loading of entry scripts
|
|
106
|
+
const scriptDeferralQueue = deferScripts ? new ScriptDeferralQueue() : undefined;
|
|
107
|
+
// If deferScripts is enabled, collect existing scripts before we start loading entry scripts
|
|
108
|
+
scriptDeferralQueue?.captureExistingScripts();
|
|
10
109
|
// Inject the import map
|
|
11
110
|
const importMapScriptTag = document.createElement('script');
|
|
12
111
|
importMapScriptTag.type = 'importmap';
|
|
@@ -26,14 +125,16 @@ window.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entry
|
|
|
26
125
|
overlayScriptTag.src = overlayScript;
|
|
27
126
|
document.head.appendChild(overlayScriptTag);
|
|
28
127
|
}
|
|
128
|
+
// If deferScripts is enabled, start observing mutations to capture dynamically added scripts
|
|
129
|
+
scriptDeferralQueue?.startCapturing();
|
|
29
130
|
// Inject the main script
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
131
|
+
void Promise.all((entryScripts ?? []).map((s) => import(s)))
|
|
132
|
+
.catch((err) => {
|
|
133
|
+
console.error('[Cloudpack] Failed to load entry scripts:', err);
|
|
134
|
+
})
|
|
135
|
+
.finally(() => {
|
|
136
|
+
// Once async work is done, stop observing further mutations and reinsert any captured scripts in their original locations
|
|
137
|
+
scriptDeferralQueue?.flushQueue();
|
|
138
|
+
});
|
|
38
139
|
};
|
|
39
140
|
//# sourceMappingURL=bootstrap.inline.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bootstrap.inline.js","sourceRoot":"","sources":["../src/bootstrap.inline.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"bootstrap.inline.js","sourceRoot":"","sources":["../src/bootstrap.inline.ts"],"names":[],"mappings":";AAEA,SAAS,WAAW,CAAC,IAAU;IAC7B,OAAO,IAAI,CAAC,QAAQ,KAAK,IAAI,CAAC,YAAY,IAAK,IAA0B,CAAC,OAAO,KAAK,QAAQ,CAAC;AACjG,CAAC;AAED;;;;;;GAMG;AACH,MAAM,mBAAmB;IACvB;;OAEG;IACK,eAAe,GACrB,EAAE,CAAC;IACG,QAAQ,GAA4B,IAAI,CAAC;IAEzC,aAAa,CAAC,MAAiC;QACrD,iDAAiD;QACjD,IAAI,MAAM,CAAC,UAAU;YAAE,OAAO;QAC9B,MAAM,CAAC,UAAU,GAAG,IAAI,CAAC;QAEzB,MAAM,MAAM,GAAG,MAAM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,QAAQ,CAAC;QACjC,gBAAgB,CAAC,GAAG,GAAG,aAAa,CAAC;QACrC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAC9C,CAAC;IAED,6FAA6F;IAC7F,mBAAmB,EAAE,cAAc,EAAE,CAAC;IAEtC,yBAAyB;IACzB,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;SACzD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,GAAG,CAAC,CAAC;IAClE,CAAC,CAAC;SACD,OAAO,CAAC,GAAG,EAAE;QACZ,0HAA0H;QAC1H,mBAAmB,EAAE,UAAU,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;AACP,CAAC,CAAC","sourcesContent":["type ExtendedHTMLScriptElement = HTMLScriptElement & { __captured?: boolean };\n\nfunction isScriptTag(node: Node): node is ExtendedHTMLScriptElement {\n return node.nodeType === Node.ELEMENT_NODE && (node as HTMLScriptElement).tagName === 'SCRIPT';\n}\n\n/**\n * Manages the deferral and controlled execution of script tags.\n *\n * This class captures script tags (both existing and dynamically added) to prevent\n * their immediate execution, then reinserts them later to execute in their original\n * document positions once async dependencies have loaded.\n */\nclass ScriptDeferralQueue {\n /**\n * Scripts captured for deferred execution, along with their original DOM positions.\n */\n private deferredScripts: { script: HTMLScriptElement; parent: ParentNode | null; nextSibling: ChildNode | null }[] =\n [];\n private observer: MutationObserver | null = null;\n\n private captureScript(script: ExtendedHTMLScriptElement) {\n // Avoid capturing the same script more than once\n if (script.__captured) return;\n script.__captured = true;\n\n const parent = script.parentNode;\n const nextSibling = script.nextSibling;\n\n if (parent) {\n parent.removeChild(script);\n }\n this.deferredScripts.push({ script, parent, nextSibling });\n }\n\n /**\n * Captures all script tags that appear after the current script in the document.\n * Called once at initialization to defer existing scripts.\n */\n public captureExistingScripts() {\n const currentScript = document.currentScript;\n if (currentScript) {\n Array.from(document.querySelectorAll('script'))\n .filter((script) => currentScript.compareDocumentPosition(script) & Node.DOCUMENT_POSITION_FOLLOWING)\n .forEach((script) => this.captureScript(script));\n }\n }\n\n /**\n * Begins observing the document for dynamically added script tags.\n * Any new scripts detected will be automatically captured for deferred execution.\n */\n public startCapturing() {\n if (this.observer) {\n return; // Already observing\n }\n\n this.observer = new MutationObserver((mutations) => {\n for (const mutation of mutations) {\n mutation.addedNodes.forEach((node) => {\n if (isScriptTag(node)) {\n this.captureScript(node);\n }\n });\n }\n });\n\n // Start observing the entire document\n this.observer.observe(document.documentElement, { childList: true, subtree: true });\n }\n\n /**\n * Stops observing for new scripts and executes all deferred scripts in their original order.\n * Scripts are recreated and reinserted into their original DOM positions to trigger execution.\n */\n public flushQueue() {\n if (this.observer) {\n this.observer.disconnect();\n this.observer = null;\n }\n\n // Reinsert all captured script elements in their original locations\n for (const { script, parent, nextSibling } of this.deferredScripts) {\n // Create a new script element to trigger execution\n const newScript = document.createElement('script');\n\n // Copy all attributes (like src, type, etc.)\n for (const attr of Array.from(script.attributes)) {\n newScript.setAttribute(attr.name, attr.value);\n }\n // Copy inline script content\n newScript.textContent = script.textContent;\n\n // Check if nextSibling is still a child of parent\n if (parent && nextSibling && nextSibling.parentNode === parent) {\n parent.insertBefore(newScript, nextSibling);\n } else if (parent) {\n parent.appendChild(newScript);\n } else {\n // Fallback if parent is not available\n document.body.appendChild(newScript);\n }\n }\n\n // Clear the list after reinsertion\n this.deferredScripts = [];\n }\n}\n\nwindow.__cloudpack ??= {};\nwindow.__cloudpack.bootstrap = ({ inlineScripts, overlayScript, importMap, entryScripts, deferScripts }) => {\n window.__cloudpack ??= {};\n if (window.__cloudpack.hasBootstrapRun) {\n console.warn('Cloudpack bootstrap has already run, skipping.');\n return;\n }\n window.__cloudpack.hasBootstrapRun = true;\n\n // If deferScripts is true, set up the ScriptDeferralQueue so that we can capture scripts added before and during the async loading of entry scripts\n const scriptDeferralQueue = deferScripts ? new ScriptDeferralQueue() : undefined;\n\n // If deferScripts is enabled, collect existing scripts before we start loading entry scripts\n scriptDeferralQueue?.captureExistingScripts();\n\n // Inject the import map\n const importMapScriptTag = document.createElement('script');\n importMapScriptTag.type = 'importmap';\n importMapScriptTag.textContent = JSON.stringify(importMap);\n document.head.appendChild(importMapScriptTag);\n\n // Inject the inline scripts\n for (const inlineScript of inlineScripts) {\n const inlineTag = document.createElement('script');\n inlineTag.type = 'module';\n inlineTag.textContent = inlineScript;\n document.head.appendChild(inlineTag);\n }\n\n // Inject the overlay script\n if (overlayScript) {\n const overlayScriptTag = document.createElement('script');\n overlayScriptTag.type = 'module';\n overlayScriptTag.src = overlayScript;\n document.head.appendChild(overlayScriptTag);\n }\n\n // If deferScripts is enabled, start observing mutations to capture dynamically added scripts\n scriptDeferralQueue?.startCapturing();\n\n // Inject the main script\n void Promise.all((entryScripts ?? []).map((s) => import(s)))\n .catch((err) => {\n console.error('[Cloudpack] Failed to load entry scripts:', err);\n })\n .finally(() => {\n // Once async work is done, stop observing further mutations and reinsert any captured scripts in their original locations\n scriptDeferralQueue?.flushQueue();\n });\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/inline-scripts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.52",
|
|
4
4
|
"description": "Provides inline scripts that must be injected into the page for Cloudpack to work properly.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@ms-cloudpack/overlay": "^0.19.
|
|
18
|
-
"@ms-cloudpack/path-utilities": "^3.1.
|
|
17
|
+
"@ms-cloudpack/overlay": "^0.19.48",
|
|
18
|
+
"@ms-cloudpack/path-utilities": "^3.1.34"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@ms-cloudpack/common-types-browser": "^0.6.
|
|
21
|
+
"@ms-cloudpack/common-types-browser": "^0.6.4",
|
|
22
22
|
"@ms-cloudpack/eslint-plugin-internal": "^0.0.1",
|
|
23
23
|
"@ms-cloudpack/scripts": "^0.0.1"
|
|
24
24
|
},
|