@qiankunjs/shared 0.0.1-alpha.0
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/LICENSE +21 -0
- package/dist/cjs/assets-transpilers/index.d.ts +2 -0
- package/dist/cjs/assets-transpilers/index.js +34 -0
- package/dist/cjs/assets-transpilers/index.js.map +1 -0
- package/dist/cjs/assets-transpilers/link.d.ts +1 -0
- package/dist/cjs/assets-transpilers/link.js +20 -0
- package/dist/cjs/assets-transpilers/link.js.map +1 -0
- package/dist/cjs/assets-transpilers/script.d.ts +10 -0
- package/dist/cjs/assets-transpilers/script.js +50 -0
- package/dist/cjs/assets-transpilers/script.js.map +1 -0
- package/dist/cjs/assets-transpilers/utils.d.ts +2 -0
- package/dist/cjs/assets-transpilers/utils.js +58 -0
- package/dist/cjs/assets-transpilers/utils.js.map +1 -0
- package/dist/cjs/index.d.ts +6 -0
- package/dist/cjs/index.js +28 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/utils.d.ts +11 -0
- package/dist/cjs/utils.js +33 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/assets-transpilers/index.d.ts +2 -0
- package/dist/esm/assets-transpilers/index.js +26 -0
- package/dist/esm/assets-transpilers/index.js.map +1 -0
- package/dist/esm/assets-transpilers/link.d.ts +1 -0
- package/dist/esm/assets-transpilers/link.js +13 -0
- package/dist/esm/assets-transpilers/link.js.map +1 -0
- package/dist/esm/assets-transpilers/script.d.ts +10 -0
- package/dist/esm/assets-transpilers/script.js +44 -0
- package/dist/esm/assets-transpilers/script.js.map +1 -0
- package/dist/esm/assets-transpilers/utils.d.ts +2 -0
- package/dist/esm/assets-transpilers/utils.js +51 -0
- package/dist/esm/assets-transpilers/utils.js.map +1 -0
- package/dist/esm/index.d.ts +6 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/utils.d.ts +11 -0
- package/dist/esm/utils.js +25 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +32 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Kuitos
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.transpileAssets = transpileAssets;
|
|
8
|
+
var _link = _interopRequireDefault(require("./link"));
|
|
9
|
+
var _script = _interopRequireDefault(require("./script"));
|
|
10
|
+
/**
|
|
11
|
+
* @author Kuitos
|
|
12
|
+
* @since 2023-03-14
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
function transpileAssets(node, baseURI, opts) {
|
|
16
|
+
var _ref = node,
|
|
17
|
+
tagName = _ref.tagName;
|
|
18
|
+
switch (tagName) {
|
|
19
|
+
case 'SCRIPT':
|
|
20
|
+
{
|
|
21
|
+
(0, _script.default)(node, baseURI, opts);
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
case 'LINK':
|
|
25
|
+
{
|
|
26
|
+
(0, _link.default)(node, baseURI);
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
default:
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
return node;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transpileAssets","node","baseURI","opts","tagName","transpileScript","transpileLink"],"sources":["../../../src/assets-transpilers/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-14\n */\nimport transpileLink from './link';\nimport type { TransformerOpts } from './script';\nimport transpileScript from './script';\n\nexport function transpileAssets<T extends Node>(node: T, baseURI: string, opts: TransformerOpts): T {\n const { tagName } = node as any as HTMLElement;\n\n switch (tagName) {\n case 'SCRIPT': {\n transpileScript(node as any as HTMLScriptElement, baseURI, opts);\n break;\n }\n\n case 'LINK': {\n transpileLink(node as any as HTMLLinkElement, baseURI);\n break;\n }\n\n default:\n break;\n }\n\n return node;\n}\n"],"mappings":";;;;;;;AAIA;AAEA;AANA;AACA;AACA;AACA;;AAKO,SAASA,eAAe,CAAiBC,IAAO,EAAEC,OAAe,EAAEC,IAAqB,EAAK;EAClG,WAAoBF,IAAI;IAAhBG,OAAO,QAAPA,OAAO;EAEf,QAAQA,OAAO;IACb,KAAK,QAAQ;MAAE;QACb,IAAAC,eAAe,EAACJ,IAAI,EAA8BC,OAAO,EAAEC,IAAI,CAAC;QAChE;MACF;IAEA,KAAK,MAAM;MAAE;QACX,IAAAG,aAAa,EAACL,IAAI,EAA4BC,OAAO,CAAC;QACtD;MACF;IAEA;MACE;EAAM;EAGV,OAAOD,IAAI;AACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function transpileLink(link: HTMLLinkElement, baseURI: string): HTMLLinkElement;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transpileLink;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
/**
|
|
9
|
+
* @author Kuitos
|
|
10
|
+
* @since 2023-04-26
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
function transpileLink(link, baseURI) {
|
|
14
|
+
var hrefAttribute = link.getAttribute('href');
|
|
15
|
+
if (hrefAttribute) {
|
|
16
|
+
link.href = (0, _utils.getEntireUrl)(hrefAttribute, baseURI);
|
|
17
|
+
}
|
|
18
|
+
return link;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transpileLink","link","baseURI","hrefAttribute","getAttribute","href","getEntireUrl"],"sources":["../../../src/assets-transpilers/link.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\nimport { getEntireUrl } from '../utils';\n\nexport default function transpileLink(link: HTMLLinkElement, baseURI: string): HTMLLinkElement {\n const hrefAttribute = link.getAttribute('href');\n if (hrefAttribute) {\n link.href = getEntireUrl(hrefAttribute, baseURI);\n }\n return link;\n}\n"],"mappings":";;;;;;AAIA;AAJA;AACA;AACA;AACA;;AAGe,SAASA,aAAa,CAACC,IAAqB,EAAEC,OAAe,EAAmB;EAC7F,IAAMC,aAAa,GAAGF,IAAI,CAACG,YAAY,CAAC,MAAM,CAAC;EAC/C,IAAID,aAAa,EAAE;IACjBF,IAAI,CAACI,IAAI,GAAG,IAAAC,mBAAY,EAACH,aAAa,EAAED,OAAO,CAAC;EAClD;EACA,OAAOD,IAAI;AACb"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-03-16
|
|
4
|
+
*/
|
|
5
|
+
import type { Sandbox } from '@qiankunjs/sandbox';
|
|
6
|
+
export declare type TransformerOpts = {
|
|
7
|
+
fetch: typeof window.fetch;
|
|
8
|
+
sandbox?: Sandbox;
|
|
9
|
+
};
|
|
10
|
+
export default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: TransformerOpts): void;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = transpileScript;
|
|
7
|
+
var _utils = require("../utils");
|
|
8
|
+
/**
|
|
9
|
+
* @author Kuitos
|
|
10
|
+
* @since 2023-03-16
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
var isValidJavaScriptType = function isValidJavaScriptType(type) {
|
|
14
|
+
var handleTypes = ['text/javascript', 'module', 'application/javascript', 'text/ecmascript', 'application/ecmascript'];
|
|
15
|
+
return !type || handleTypes.indexOf(type) !== -1;
|
|
16
|
+
};
|
|
17
|
+
function transpileScript(script, baseURI, opts) {
|
|
18
|
+
// Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI
|
|
19
|
+
// Such as <script src="./foo.js"></script> will be resolved to http://localhost:8000/foo.js while read script.src
|
|
20
|
+
var srcAttribute = script.getAttribute('src');
|
|
21
|
+
var sandbox = opts.sandbox;
|
|
22
|
+
if (sandbox) {
|
|
23
|
+
if (srcAttribute) {
|
|
24
|
+
script.removeAttribute('src');
|
|
25
|
+
var scriptSrc = (0, _utils.getEntireUrl)(srcAttribute, baseURI);
|
|
26
|
+
script.dataset.src = scriptSrc;
|
|
27
|
+
var _fetch = opts.fetch;
|
|
28
|
+
_fetch(scriptSrc).then(function (res) {
|
|
29
|
+
return res.text();
|
|
30
|
+
}).then(function (code) {
|
|
31
|
+
var codeFactory = sandbox.makeEvaluateFactory(code, scriptSrc);
|
|
32
|
+
script.src = URL.createObjectURL(new Blob([codeFactory], {
|
|
33
|
+
type: 'application/javascript'
|
|
34
|
+
}));
|
|
35
|
+
});
|
|
36
|
+
} else if (isValidJavaScriptType(script.type)) {
|
|
37
|
+
var code = script.textContent;
|
|
38
|
+
if (code) {
|
|
39
|
+
script.textContent = sandbox.makeEvaluateFactory(code, baseURI);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
if (srcAttribute) {
|
|
44
|
+
script.src = (0, _utils.getEntireUrl)(srcAttribute, baseURI);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// TODO find entry exports
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isValidJavaScriptType","type","handleTypes","indexOf","transpileScript","script","baseURI","opts","srcAttribute","getAttribute","sandbox","removeAttribute","scriptSrc","getEntireUrl","dataset","src","fetch","then","res","text","code","codeFactory","makeEvaluateFactory","URL","createObjectURL","Blob","textContent"],"sources":["../../../src/assets-transpilers/script.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-16\n */\n\nimport type { Sandbox } from '@qiankunjs/sandbox';\nimport { getEntireUrl } from '../utils';\n\nexport type TransformerOpts = {\n fetch: typeof window.fetch;\n sandbox?: Sandbox;\n};\n\nconst isValidJavaScriptType = (type?: string): boolean => {\n const handleTypes = [\n 'text/javascript',\n 'module',\n 'application/javascript',\n 'text/ecmascript',\n 'application/ecmascript',\n ];\n return !type || handleTypes.indexOf(type) !== -1;\n};\n\nexport default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: TransformerOpts): void {\n // Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI\n // Such as <script src=\"./foo.js\"></script> will be resolved to http://localhost:8000/foo.js while read script.src\n const srcAttribute = script.getAttribute('src');\n const { sandbox } = opts;\n\n if (sandbox) {\n if (srcAttribute) {\n script.removeAttribute('src');\n\n const scriptSrc = getEntireUrl(srcAttribute, baseURI);\n script.dataset.src = scriptSrc;\n\n const { fetch } = opts;\n fetch(scriptSrc)\n .then((res) => res.text())\n .then((code) => {\n const codeFactory = sandbox.makeEvaluateFactory(code, scriptSrc);\n script.src = URL.createObjectURL(new Blob([codeFactory], { type: 'application/javascript' }));\n });\n } else if (isValidJavaScriptType(script.type)) {\n const code = script.textContent;\n if (code) {\n script.textContent = sandbox.makeEvaluateFactory(code, baseURI);\n }\n }\n } else {\n if (srcAttribute) {\n script.src = getEntireUrl(srcAttribute, baseURI);\n }\n }\n\n // TODO find entry exports\n}\n"],"mappings":";;;;;;AAMA;AANA;AACA;AACA;AACA;;AAUA,IAAMA,qBAAqB,GAAG,SAAxBA,qBAAqB,CAAIC,IAAa,EAAc;EACxD,IAAMC,WAAW,GAAG,CAClB,iBAAiB,EACjB,QAAQ,EACR,wBAAwB,EACxB,iBAAiB,EACjB,wBAAwB,CACzB;EACD,OAAO,CAACD,IAAI,IAAIC,WAAW,CAACC,OAAO,CAACF,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAEc,SAASG,eAAe,CAACC,MAAyB,EAAEC,OAAe,EAAEC,IAAqB,EAAQ;EAC/G;EACA;EACA,IAAMC,YAAY,GAAGH,MAAM,CAACI,YAAY,CAAC,KAAK,CAAC;EAC/C,IAAQC,OAAO,GAAKH,IAAI,CAAhBG,OAAO;EAEf,IAAIA,OAAO,EAAE;IACX,IAAIF,YAAY,EAAE;MAChBH,MAAM,CAACM,eAAe,CAAC,KAAK,CAAC;MAE7B,IAAMC,SAAS,GAAG,IAAAC,mBAAY,EAACL,YAAY,EAAEF,OAAO,CAAC;MACrDD,MAAM,CAACS,OAAO,CAACC,GAAG,GAAGH,SAAS;MAE9B,IAAQI,MAAK,GAAKT,IAAI,CAAdS,KAAK;MACbA,MAAK,CAACJ,SAAS,CAAC,CACbK,IAAI,CAAC,UAACC,GAAG;QAAA,OAAKA,GAAG,CAACC,IAAI,EAAE;MAAA,EAAC,CACzBF,IAAI,CAAC,UAACG,IAAI,EAAK;QACd,IAAMC,WAAW,GAAGX,OAAO,CAACY,mBAAmB,CAACF,IAAI,EAAER,SAAS,CAAC;QAChEP,MAAM,CAACU,GAAG,GAAGQ,GAAG,CAACC,eAAe,CAAC,IAAIC,IAAI,CAAC,CAACJ,WAAW,CAAC,EAAE;UAAEpB,IAAI,EAAE;QAAyB,CAAC,CAAC,CAAC;MAC/F,CAAC,CAAC;IACN,CAAC,MAAM,IAAID,qBAAqB,CAACK,MAAM,CAACJ,IAAI,CAAC,EAAE;MAC7C,IAAMmB,IAAI,GAAGf,MAAM,CAACqB,WAAW;MAC/B,IAAIN,IAAI,EAAE;QACRf,MAAM,CAACqB,WAAW,GAAGhB,OAAO,CAACY,mBAAmB,CAACF,IAAI,EAAEd,OAAO,CAAC;MACjE;IACF;EACF,CAAC,MAAM;IACL,IAAIE,YAAY,EAAE;MAChBH,MAAM,CAACU,GAAG,GAAG,IAAAF,mBAAY,EAACL,YAAY,EAAEF,OAAO,CAAC;IAClD;EACF;;EAEA;AACF"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getGlobalProp = getGlobalProp;
|
|
7
|
+
exports.noteGlobalProps = noteGlobalProps;
|
|
8
|
+
var isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1;
|
|
9
|
+
function shouldSkipProperty(global, p) {
|
|
10
|
+
if (!global.hasOwnProperty(p) || !isNaN(p) && p < global.length) return true;
|
|
11
|
+
if (isIE11) {
|
|
12
|
+
// https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围
|
|
13
|
+
try {
|
|
14
|
+
return global[p] && typeof window !== 'undefined' && global[p].parent === window;
|
|
15
|
+
} catch (err) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
} else {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// safari unpredictably lists some new globals first or second in object order
|
|
24
|
+
var firstGlobalProp, secondGlobalProp, lastGlobalProp;
|
|
25
|
+
function getGlobalProp(global) {
|
|
26
|
+
var cnt = 0;
|
|
27
|
+
var lastProp;
|
|
28
|
+
var hasIframe = false;
|
|
29
|
+
for (var p in global) {
|
|
30
|
+
if (shouldSkipProperty(global, p)) continue;
|
|
31
|
+
|
|
32
|
+
// 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断
|
|
33
|
+
for (var i = 0; i < window.frames.length && !hasIframe; i++) {
|
|
34
|
+
var frame = window.frames[i];
|
|
35
|
+
if (frame === global[p]) {
|
|
36
|
+
hasIframe = true;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (!hasIframe && (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp)) return p;
|
|
41
|
+
cnt++;
|
|
42
|
+
lastProp = p;
|
|
43
|
+
}
|
|
44
|
+
if (lastProp !== lastGlobalProp) return lastProp;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
function noteGlobalProps(global) {
|
|
48
|
+
// alternatively Object.keys(global).pop()
|
|
49
|
+
// but this may be faster (pending benchmarks)
|
|
50
|
+
firstGlobalProp = secondGlobalProp = undefined;
|
|
51
|
+
for (var p in global) {
|
|
52
|
+
if (shouldSkipProperty(global, p)) continue;
|
|
53
|
+
if (!firstGlobalProp) firstGlobalProp = p;else if (!secondGlobalProp) secondGlobalProp = p;
|
|
54
|
+
lastGlobalProp = p;
|
|
55
|
+
}
|
|
56
|
+
return lastGlobalProp;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isIE11","navigator","userAgent","indexOf","shouldSkipProperty","global","p","hasOwnProperty","isNaN","length","window","parent","err","firstGlobalProp","secondGlobalProp","lastGlobalProp","getGlobalProp","cnt","lastProp","hasIframe","i","frames","frame","noteGlobalProps","undefined"],"sources":["../../../src/assets-transpilers/utils.ts"],"sourcesContent":["const isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1;\n\nfunction shouldSkipProperty(global: WindowProxy, p: PropertyKey) {\n if (!global.hasOwnProperty(p) || (!isNaN(p as any) && <any>p < global.length)) return true;\n\n if (isIE11) {\n // https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围\n try {\n return global[p as any] && typeof window !== 'undefined' && global[p as any].parent === window;\n } catch (err) {\n return true;\n }\n } else {\n return false;\n }\n}\n\n// safari unpredictably lists some new globals first or second in object order\nlet firstGlobalProp: string | undefined, secondGlobalProp: string | undefined, lastGlobalProp: string | undefined;\n\nexport function getGlobalProp(global: WindowProxy) {\n let cnt = 0;\n let lastProp;\n let hasIframe = false;\n\n for (const p in global) {\n if (shouldSkipProperty(global, p)) continue;\n\n // 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断\n for (let i = 0; i < window.frames.length && !hasIframe; i++) {\n const frame = window.frames[i];\n if (frame === global[p as any]) {\n hasIframe = true;\n break;\n }\n }\n\n if (!hasIframe && ((cnt === 0 && p !== firstGlobalProp) || (cnt === 1 && p !== secondGlobalProp))) return p;\n cnt++;\n lastProp = p;\n }\n\n if (lastProp !== lastGlobalProp) return lastProp;\n\n return;\n}\n\nexport function noteGlobalProps(global: WindowProxy) {\n // alternatively Object.keys(global).pop()\n // but this may be faster (pending benchmarks)\n firstGlobalProp = secondGlobalProp = undefined;\n\n for (const p in global) {\n if (shouldSkipProperty(global, p)) continue;\n if (!firstGlobalProp) firstGlobalProp = p;\n else if (!secondGlobalProp) secondGlobalProp = p;\n lastGlobalProp = p;\n }\n\n return lastGlobalProp;\n}\n"],"mappings":";;;;;;;AAAA,IAAMA,MAAM,GAAG,OAAOC,SAAS,KAAK,WAAW,IAAIA,SAAS,CAACC,SAAS,CAACC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAEhG,SAASC,kBAAkB,CAACC,MAAmB,EAAEC,CAAc,EAAE;EAC/D,IAAI,CAACD,MAAM,CAACE,cAAc,CAACD,CAAC,CAAC,IAAK,CAACE,KAAK,CAACF,CAAC,CAAQ,IAASA,CAAC,GAAGD,MAAM,CAACI,MAAO,EAAE,OAAO,IAAI;EAE1F,IAAIT,MAAM,EAAE;IACV;IACA,IAAI;MACF,OAAOK,MAAM,CAACC,CAAC,CAAQ,IAAI,OAAOI,MAAM,KAAK,WAAW,IAAIL,MAAM,CAACC,CAAC,CAAQ,CAACK,MAAM,KAAKD,MAAM;IAChG,CAAC,CAAC,OAAOE,GAAG,EAAE;MACZ,OAAO,IAAI;IACb;EACF,CAAC,MAAM;IACL,OAAO,KAAK;EACd;AACF;;AAEA;AACA,IAAIC,eAAmC,EAAEC,gBAAoC,EAAEC,cAAkC;AAE1G,SAASC,aAAa,CAACX,MAAmB,EAAE;EACjD,IAAIY,GAAG,GAAG,CAAC;EACX,IAAIC,QAAQ;EACZ,IAAIC,SAAS,GAAG,KAAK;EAErB,KAAK,IAAMb,CAAC,IAAID,MAAM,EAAE;IACtB,IAAID,kBAAkB,CAACC,MAAM,EAAEC,CAAC,CAAC,EAAE;;IAEnC;IACA,KAAK,IAAIc,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGV,MAAM,CAACW,MAAM,CAACZ,MAAM,IAAI,CAACU,SAAS,EAAEC,CAAC,EAAE,EAAE;MAC3D,IAAME,KAAK,GAAGZ,MAAM,CAACW,MAAM,CAACD,CAAC,CAAC;MAC9B,IAAIE,KAAK,KAAKjB,MAAM,CAACC,CAAC,CAAQ,EAAE;QAC9Ba,SAAS,GAAG,IAAI;QAChB;MACF;IACF;IAEA,IAAI,CAACA,SAAS,KAAMF,GAAG,KAAK,CAAC,IAAIX,CAAC,KAAKO,eAAe,IAAMI,GAAG,KAAK,CAAC,IAAIX,CAAC,KAAKQ,gBAAiB,CAAC,EAAE,OAAOR,CAAC;IAC3GW,GAAG,EAAE;IACLC,QAAQ,GAAGZ,CAAC;EACd;EAEA,IAAIY,QAAQ,KAAKH,cAAc,EAAE,OAAOG,QAAQ;EAEhD;AACF;AAEO,SAASK,eAAe,CAAClB,MAAmB,EAAE;EACnD;EACA;EACAQ,eAAe,GAAGC,gBAAgB,GAAGU,SAAS;EAE9C,KAAK,IAAMlB,CAAC,IAAID,MAAM,EAAE;IACtB,IAAID,kBAAkB,CAACC,MAAM,EAAEC,CAAC,CAAC,EAAE;IACnC,IAAI,CAACO,eAAe,EAAEA,eAAe,GAAGP,CAAC,CAAC,KACrC,IAAI,CAACQ,gBAAgB,EAAEA,gBAAgB,GAAGR,CAAC;IAChDS,cAAc,GAAGT,CAAC;EACpB;EAEA,OAAOS,cAAc;AACvB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _assetsTranspilers = require("./assets-transpilers");
|
|
7
|
+
Object.keys(_assetsTranspilers).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _assetsTranspilers[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function get() {
|
|
13
|
+
return _assetsTranspilers[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _utils = require("./utils");
|
|
18
|
+
Object.keys(_utils).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _utils[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return _utils[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-05-06\n */\nexport * from './assets-transpilers';\nexport * from './utils';\n"],"mappings":";;;;;AAIA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-04-26
|
|
4
|
+
*/
|
|
5
|
+
export declare class Deferred<T> {
|
|
6
|
+
promise: Promise<T>;
|
|
7
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
8
|
+
reject: (reason?: any) => void;
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare function getEntireUrl(uri: string, baseURI: string): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Deferred = void 0;
|
|
8
|
+
exports.getEntireUrl = getEntireUrl;
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
12
|
+
/**
|
|
13
|
+
* @author Kuitos
|
|
14
|
+
* @since 2023-04-26
|
|
15
|
+
*/
|
|
16
|
+
var Deferred = /*#__PURE__*/(0, _createClass2.default)(function Deferred() {
|
|
17
|
+
var _this = this;
|
|
18
|
+
(0, _classCallCheck2.default)(this, Deferred);
|
|
19
|
+
(0, _defineProperty2.default)(this, "promise", void 0);
|
|
20
|
+
(0, _defineProperty2.default)(this, "resolve", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "reject", void 0);
|
|
22
|
+
this.promise = new Promise(function (resolve, reject) {
|
|
23
|
+
_this.resolve = resolve;
|
|
24
|
+
_this.reject = reject;
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
exports.Deferred = Deferred;
|
|
28
|
+
function getEntireUrl(uri, baseURI) {
|
|
29
|
+
var publicPath = new URL(baseURI, window.location.href);
|
|
30
|
+
var entireUrl = new URL(uri, publicPath.toString());
|
|
31
|
+
return entireUrl.toString();
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Deferred","promise","Promise","resolve","reject","getEntireUrl","uri","baseURI","publicPath","URL","window","location","href","entireUrl","toString"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\n\nexport class Deferred<T> {\n promise: Promise<T>;\n\n resolve!: (value: T | PromiseLike<T>) => void;\n\n reject!: (reason?: any) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n}\n\nexport function getEntireUrl(uri: string, baseURI: string): string {\n const publicPath = new URL(baseURI, window.location.href);\n const entireUrl = new URL(uri, publicPath.toString());\n return entireUrl.toString();\n}\n"],"mappings":";;;;;;;;;;;AAAA;AACA;AACA;AACA;AAHA,IAKaA,QAAQ,2CAOnB,oBAAc;EAAA;EAAA;EAAA;EAAA;EAAA;EACZ,IAAI,CAACC,OAAO,GAAG,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC9C,KAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,KAAI,CAACC,MAAM,GAAGA,MAAM;EACtB,CAAC,CAAC;AACJ,CAAC;AAAA;AAGI,SAASC,YAAY,CAACC,GAAW,EAAEC,OAAe,EAAU;EACjE,IAAMC,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,EAAEG,MAAM,CAACC,QAAQ,CAACC,IAAI,CAAC;EACzD,IAAMC,SAAS,GAAG,IAAIJ,GAAG,CAACH,GAAG,EAAEE,UAAU,CAACM,QAAQ,EAAE,CAAC;EACrD,OAAOD,SAAS,CAACC,QAAQ,EAAE;AAC7B"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-03-14
|
|
4
|
+
*/
|
|
5
|
+
import transpileLink from "./link";
|
|
6
|
+
import transpileScript from "./script";
|
|
7
|
+
export function transpileAssets(node, baseURI, opts) {
|
|
8
|
+
var _ref = node,
|
|
9
|
+
tagName = _ref.tagName;
|
|
10
|
+
switch (tagName) {
|
|
11
|
+
case 'SCRIPT':
|
|
12
|
+
{
|
|
13
|
+
transpileScript(node, baseURI, opts);
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
case 'LINK':
|
|
17
|
+
{
|
|
18
|
+
transpileLink(node, baseURI);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
default:
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["transpileLink","transpileScript","transpileAssets","node","baseURI","opts","tagName"],"sources":["../../../src/assets-transpilers/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-14\n */\nimport transpileLink from './link';\nimport type { TransformerOpts } from './script';\nimport transpileScript from './script';\n\nexport function transpileAssets<T extends Node>(node: T, baseURI: string, opts: TransformerOpts): T {\n const { tagName } = node as any as HTMLElement;\n\n switch (tagName) {\n case 'SCRIPT': {\n transpileScript(node as any as HTMLScriptElement, baseURI, opts);\n break;\n }\n\n case 'LINK': {\n transpileLink(node as any as HTMLLinkElement, baseURI);\n break;\n }\n\n default:\n break;\n }\n\n return node;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,OAAOA,aAAa;AAEpB,OAAOC,eAAe;AAEtB,OAAO,SAASC,eAAe,CAAiBC,IAAO,EAAEC,OAAe,EAAEC,IAAqB,EAAK;EAClG,WAAoBF,IAAI;IAAhBG,OAAO,QAAPA,OAAO;EAEf,QAAQA,OAAO;IACb,KAAK,QAAQ;MAAE;QACbL,eAAe,CAACE,IAAI,EAA8BC,OAAO,EAAEC,IAAI,CAAC;QAChE;MACF;IAEA,KAAK,MAAM;MAAE;QACXL,aAAa,CAACG,IAAI,EAA4BC,OAAO,CAAC;QACtD;MACF;IAEA;MACE;EAAM;EAGV,OAAOD,IAAI;AACb"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function transpileLink(link: HTMLLinkElement, baseURI: string): HTMLLinkElement;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-04-26
|
|
4
|
+
*/
|
|
5
|
+
import { getEntireUrl } from "../utils";
|
|
6
|
+
export default function transpileLink(link, baseURI) {
|
|
7
|
+
var hrefAttribute = link.getAttribute('href');
|
|
8
|
+
if (hrefAttribute) {
|
|
9
|
+
link.href = getEntireUrl(hrefAttribute, baseURI);
|
|
10
|
+
}
|
|
11
|
+
return link;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getEntireUrl","transpileLink","link","baseURI","hrefAttribute","getAttribute","href"],"sources":["../../../src/assets-transpilers/link.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\nimport { getEntireUrl } from '../utils';\n\nexport default function transpileLink(link: HTMLLinkElement, baseURI: string): HTMLLinkElement {\n const hrefAttribute = link.getAttribute('href');\n if (hrefAttribute) {\n link.href = getEntireUrl(hrefAttribute, baseURI);\n }\n return link;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA,SAASA,YAAY;AAErB,eAAe,SAASC,aAAa,CAACC,IAAqB,EAAEC,OAAe,EAAmB;EAC7F,IAAMC,aAAa,GAAGF,IAAI,CAACG,YAAY,CAAC,MAAM,CAAC;EAC/C,IAAID,aAAa,EAAE;IACjBF,IAAI,CAACI,IAAI,GAAGN,YAAY,CAACI,aAAa,EAAED,OAAO,CAAC;EAClD;EACA,OAAOD,IAAI;AACb"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-03-16
|
|
4
|
+
*/
|
|
5
|
+
import type { Sandbox } from '@qiankunjs/sandbox';
|
|
6
|
+
export declare type TransformerOpts = {
|
|
7
|
+
fetch: typeof window.fetch;
|
|
8
|
+
sandbox?: Sandbox;
|
|
9
|
+
};
|
|
10
|
+
export default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: TransformerOpts): void;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-03-16
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { getEntireUrl } from "../utils";
|
|
7
|
+
var isValidJavaScriptType = function isValidJavaScriptType(type) {
|
|
8
|
+
var handleTypes = ['text/javascript', 'module', 'application/javascript', 'text/ecmascript', 'application/ecmascript'];
|
|
9
|
+
return !type || handleTypes.indexOf(type) !== -1;
|
|
10
|
+
};
|
|
11
|
+
export default function transpileScript(script, baseURI, opts) {
|
|
12
|
+
// Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI
|
|
13
|
+
// Such as <script src="./foo.js"></script> will be resolved to http://localhost:8000/foo.js while read script.src
|
|
14
|
+
var srcAttribute = script.getAttribute('src');
|
|
15
|
+
var sandbox = opts.sandbox;
|
|
16
|
+
if (sandbox) {
|
|
17
|
+
if (srcAttribute) {
|
|
18
|
+
script.removeAttribute('src');
|
|
19
|
+
var scriptSrc = getEntireUrl(srcAttribute, baseURI);
|
|
20
|
+
script.dataset.src = scriptSrc;
|
|
21
|
+
var _fetch = opts.fetch;
|
|
22
|
+
_fetch(scriptSrc).then(function (res) {
|
|
23
|
+
return res.text();
|
|
24
|
+
}).then(function (code) {
|
|
25
|
+
var codeFactory = sandbox.makeEvaluateFactory(code, scriptSrc);
|
|
26
|
+
script.src = URL.createObjectURL(new Blob([codeFactory], {
|
|
27
|
+
type: 'application/javascript'
|
|
28
|
+
}));
|
|
29
|
+
});
|
|
30
|
+
} else if (isValidJavaScriptType(script.type)) {
|
|
31
|
+
var code = script.textContent;
|
|
32
|
+
if (code) {
|
|
33
|
+
script.textContent = sandbox.makeEvaluateFactory(code, baseURI);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
if (srcAttribute) {
|
|
38
|
+
script.src = getEntireUrl(srcAttribute, baseURI);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// TODO find entry exports
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["getEntireUrl","isValidJavaScriptType","type","handleTypes","indexOf","transpileScript","script","baseURI","opts","srcAttribute","getAttribute","sandbox","removeAttribute","scriptSrc","dataset","src","fetch","then","res","text","code","codeFactory","makeEvaluateFactory","URL","createObjectURL","Blob","textContent"],"sources":["../../../src/assets-transpilers/script.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-03-16\n */\n\nimport type { Sandbox } from '@qiankunjs/sandbox';\nimport { getEntireUrl } from '../utils';\n\nexport type TransformerOpts = {\n fetch: typeof window.fetch;\n sandbox?: Sandbox;\n};\n\nconst isValidJavaScriptType = (type?: string): boolean => {\n const handleTypes = [\n 'text/javascript',\n 'module',\n 'application/javascript',\n 'text/ecmascript',\n 'application/ecmascript',\n ];\n return !type || handleTypes.indexOf(type) !== -1;\n};\n\nexport default function transpileScript(script: HTMLScriptElement, baseURI: string, opts: TransformerOpts): void {\n // Can't use script.src directly, because it will be resolved to absolute path by browser with Node.baseURI\n // Such as <script src=\"./foo.js\"></script> will be resolved to http://localhost:8000/foo.js while read script.src\n const srcAttribute = script.getAttribute('src');\n const { sandbox } = opts;\n\n if (sandbox) {\n if (srcAttribute) {\n script.removeAttribute('src');\n\n const scriptSrc = getEntireUrl(srcAttribute, baseURI);\n script.dataset.src = scriptSrc;\n\n const { fetch } = opts;\n fetch(scriptSrc)\n .then((res) => res.text())\n .then((code) => {\n const codeFactory = sandbox.makeEvaluateFactory(code, scriptSrc);\n script.src = URL.createObjectURL(new Blob([codeFactory], { type: 'application/javascript' }));\n });\n } else if (isValidJavaScriptType(script.type)) {\n const code = script.textContent;\n if (code) {\n script.textContent = sandbox.makeEvaluateFactory(code, baseURI);\n }\n }\n } else {\n if (srcAttribute) {\n script.src = getEntireUrl(srcAttribute, baseURI);\n }\n }\n\n // TODO find entry exports\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;;AAGA,SAASA,YAAY;AAOrB,IAAMC,qBAAqB,GAAG,SAAxBA,qBAAqB,CAAIC,IAAa,EAAc;EACxD,IAAMC,WAAW,GAAG,CAClB,iBAAiB,EACjB,QAAQ,EACR,wBAAwB,EACxB,iBAAiB,EACjB,wBAAwB,CACzB;EACD,OAAO,CAACD,IAAI,IAAIC,WAAW,CAACC,OAAO,CAACF,IAAI,CAAC,KAAK,CAAC,CAAC;AAClD,CAAC;AAED,eAAe,SAASG,eAAe,CAACC,MAAyB,EAAEC,OAAe,EAAEC,IAAqB,EAAQ;EAC/G;EACA;EACA,IAAMC,YAAY,GAAGH,MAAM,CAACI,YAAY,CAAC,KAAK,CAAC;EAC/C,IAAQC,OAAO,GAAKH,IAAI,CAAhBG,OAAO;EAEf,IAAIA,OAAO,EAAE;IACX,IAAIF,YAAY,EAAE;MAChBH,MAAM,CAACM,eAAe,CAAC,KAAK,CAAC;MAE7B,IAAMC,SAAS,GAAGb,YAAY,CAACS,YAAY,EAAEF,OAAO,CAAC;MACrDD,MAAM,CAACQ,OAAO,CAACC,GAAG,GAAGF,SAAS;MAE9B,IAAQG,MAAK,GAAKR,IAAI,CAAdQ,KAAK;MACbA,MAAK,CAACH,SAAS,CAAC,CACbI,IAAI,CAAC,UAACC,GAAG;QAAA,OAAKA,GAAG,CAACC,IAAI,EAAE;MAAA,EAAC,CACzBF,IAAI,CAAC,UAACG,IAAI,EAAK;QACd,IAAMC,WAAW,GAAGV,OAAO,CAACW,mBAAmB,CAACF,IAAI,EAAEP,SAAS,CAAC;QAChEP,MAAM,CAACS,GAAG,GAAGQ,GAAG,CAACC,eAAe,CAAC,IAAIC,IAAI,CAAC,CAACJ,WAAW,CAAC,EAAE;UAAEnB,IAAI,EAAE;QAAyB,CAAC,CAAC,CAAC;MAC/F,CAAC,CAAC;IACN,CAAC,MAAM,IAAID,qBAAqB,CAACK,MAAM,CAACJ,IAAI,CAAC,EAAE;MAC7C,IAAMkB,IAAI,GAAGd,MAAM,CAACoB,WAAW;MAC/B,IAAIN,IAAI,EAAE;QACRd,MAAM,CAACoB,WAAW,GAAGf,OAAO,CAACW,mBAAmB,CAACF,IAAI,EAAEb,OAAO,CAAC;MACjE;IACF;EACF,CAAC,MAAM;IACL,IAAIE,YAAY,EAAE;MAChBH,MAAM,CAACS,GAAG,GAAGf,YAAY,CAACS,YAAY,EAAEF,OAAO,CAAC;IAClD;EACF;;EAEA;AACF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1;
|
|
2
|
+
function shouldSkipProperty(global, p) {
|
|
3
|
+
if (!global.hasOwnProperty(p) || !isNaN(p) && p < global.length) return true;
|
|
4
|
+
if (isIE11) {
|
|
5
|
+
// https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围
|
|
6
|
+
try {
|
|
7
|
+
return global[p] && typeof window !== 'undefined' && global[p].parent === window;
|
|
8
|
+
} catch (err) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
} else {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// safari unpredictably lists some new globals first or second in object order
|
|
17
|
+
var firstGlobalProp, secondGlobalProp, lastGlobalProp;
|
|
18
|
+
export function getGlobalProp(global) {
|
|
19
|
+
var cnt = 0;
|
|
20
|
+
var lastProp;
|
|
21
|
+
var hasIframe = false;
|
|
22
|
+
for (var p in global) {
|
|
23
|
+
if (shouldSkipProperty(global, p)) continue;
|
|
24
|
+
|
|
25
|
+
// 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断
|
|
26
|
+
for (var i = 0; i < window.frames.length && !hasIframe; i++) {
|
|
27
|
+
var frame = window.frames[i];
|
|
28
|
+
if (frame === global[p]) {
|
|
29
|
+
hasIframe = true;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (!hasIframe && (cnt === 0 && p !== firstGlobalProp || cnt === 1 && p !== secondGlobalProp)) return p;
|
|
34
|
+
cnt++;
|
|
35
|
+
lastProp = p;
|
|
36
|
+
}
|
|
37
|
+
if (lastProp !== lastGlobalProp) return lastProp;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
export function noteGlobalProps(global) {
|
|
41
|
+
// alternatively Object.keys(global).pop()
|
|
42
|
+
// but this may be faster (pending benchmarks)
|
|
43
|
+
firstGlobalProp = secondGlobalProp = undefined;
|
|
44
|
+
for (var p in global) {
|
|
45
|
+
if (shouldSkipProperty(global, p)) continue;
|
|
46
|
+
if (!firstGlobalProp) firstGlobalProp = p;else if (!secondGlobalProp) secondGlobalProp = p;
|
|
47
|
+
lastGlobalProp = p;
|
|
48
|
+
}
|
|
49
|
+
return lastGlobalProp;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["isIE11","navigator","userAgent","indexOf","shouldSkipProperty","global","p","hasOwnProperty","isNaN","length","window","parent","err","firstGlobalProp","secondGlobalProp","lastGlobalProp","getGlobalProp","cnt","lastProp","hasIframe","i","frames","frame","noteGlobalProps","undefined"],"sources":["../../../src/assets-transpilers/utils.ts"],"sourcesContent":["const isIE11 = typeof navigator !== 'undefined' && navigator.userAgent.indexOf('Trident') !== -1;\n\nfunction shouldSkipProperty(global: WindowProxy, p: PropertyKey) {\n if (!global.hasOwnProperty(p) || (!isNaN(p as any) && <any>p < global.length)) return true;\n\n if (isIE11) {\n // https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围\n try {\n return global[p as any] && typeof window !== 'undefined' && global[p as any].parent === window;\n } catch (err) {\n return true;\n }\n } else {\n return false;\n }\n}\n\n// safari unpredictably lists some new globals first or second in object order\nlet firstGlobalProp: string | undefined, secondGlobalProp: string | undefined, lastGlobalProp: string | undefined;\n\nexport function getGlobalProp(global: WindowProxy) {\n let cnt = 0;\n let lastProp;\n let hasIframe = false;\n\n for (const p in global) {\n if (shouldSkipProperty(global, p)) continue;\n\n // 遍历 iframe,检查 window 上的属性值是否是 iframe,是则跳过后面的 first 和 second 判断\n for (let i = 0; i < window.frames.length && !hasIframe; i++) {\n const frame = window.frames[i];\n if (frame === global[p as any]) {\n hasIframe = true;\n break;\n }\n }\n\n if (!hasIframe && ((cnt === 0 && p !== firstGlobalProp) || (cnt === 1 && p !== secondGlobalProp))) return p;\n cnt++;\n lastProp = p;\n }\n\n if (lastProp !== lastGlobalProp) return lastProp;\n\n return;\n}\n\nexport function noteGlobalProps(global: WindowProxy) {\n // alternatively Object.keys(global).pop()\n // but this may be faster (pending benchmarks)\n firstGlobalProp = secondGlobalProp = undefined;\n\n for (const p in global) {\n if (shouldSkipProperty(global, p)) continue;\n if (!firstGlobalProp) firstGlobalProp = p;\n else if (!secondGlobalProp) secondGlobalProp = p;\n lastGlobalProp = p;\n }\n\n return lastGlobalProp;\n}\n"],"mappings":"AAAA,IAAMA,MAAM,GAAG,OAAOC,SAAS,KAAK,WAAW,IAAIA,SAAS,CAACC,SAAS,CAACC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAEhG,SAASC,kBAAkB,CAACC,MAAmB,EAAEC,CAAc,EAAE;EAC/D,IAAI,CAACD,MAAM,CAACE,cAAc,CAACD,CAAC,CAAC,IAAK,CAACE,KAAK,CAACF,CAAC,CAAQ,IAASA,CAAC,GAAGD,MAAM,CAACI,MAAO,EAAE,OAAO,IAAI;EAE1F,IAAIT,MAAM,EAAE;IACV;IACA,IAAI;MACF,OAAOK,MAAM,CAACC,CAAC,CAAQ,IAAI,OAAOI,MAAM,KAAK,WAAW,IAAIL,MAAM,CAACC,CAAC,CAAQ,CAACK,MAAM,KAAKD,MAAM;IAChG,CAAC,CAAC,OAAOE,GAAG,EAAE;MACZ,OAAO,IAAI;IACb;EACF,CAAC,MAAM;IACL,OAAO,KAAK;EACd;AACF;;AAEA;AACA,IAAIC,eAAmC,EAAEC,gBAAoC,EAAEC,cAAkC;AAEjH,OAAO,SAASC,aAAa,CAACX,MAAmB,EAAE;EACjD,IAAIY,GAAG,GAAG,CAAC;EACX,IAAIC,QAAQ;EACZ,IAAIC,SAAS,GAAG,KAAK;EAErB,KAAK,IAAMb,CAAC,IAAID,MAAM,EAAE;IACtB,IAAID,kBAAkB,CAACC,MAAM,EAAEC,CAAC,CAAC,EAAE;;IAEnC;IACA,KAAK,IAAIc,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGV,MAAM,CAACW,MAAM,CAACZ,MAAM,IAAI,CAACU,SAAS,EAAEC,CAAC,EAAE,EAAE;MAC3D,IAAME,KAAK,GAAGZ,MAAM,CAACW,MAAM,CAACD,CAAC,CAAC;MAC9B,IAAIE,KAAK,KAAKjB,MAAM,CAACC,CAAC,CAAQ,EAAE;QAC9Ba,SAAS,GAAG,IAAI;QAChB;MACF;IACF;IAEA,IAAI,CAACA,SAAS,KAAMF,GAAG,KAAK,CAAC,IAAIX,CAAC,KAAKO,eAAe,IAAMI,GAAG,KAAK,CAAC,IAAIX,CAAC,KAAKQ,gBAAiB,CAAC,EAAE,OAAOR,CAAC;IAC3GW,GAAG,EAAE;IACLC,QAAQ,GAAGZ,CAAC;EACd;EAEA,IAAIY,QAAQ,KAAKH,cAAc,EAAE,OAAOG,QAAQ;EAEhD;AACF;AAEA,OAAO,SAASK,eAAe,CAAClB,MAAmB,EAAE;EACnD;EACA;EACAQ,eAAe,GAAGC,gBAAgB,GAAGU,SAAS;EAE9C,KAAK,IAAMlB,CAAC,IAAID,MAAM,EAAE;IACtB,IAAID,kBAAkB,CAACC,MAAM,EAAEC,CAAC,CAAC,EAAE;IACnC,IAAI,CAACO,eAAe,EAAEA,eAAe,GAAGP,CAAC,CAAC,KACrC,IAAI,CAACQ,gBAAgB,EAAEA,gBAAgB,GAAGR,CAAC;IAChDS,cAAc,GAAGT,CAAC;EACpB;EAEA,OAAOS,cAAc;AACvB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-05-06\n */\nexport * from './assets-transpilers';\nexport * from './utils';\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author Kuitos
|
|
3
|
+
* @since 2023-04-26
|
|
4
|
+
*/
|
|
5
|
+
export declare class Deferred<T> {
|
|
6
|
+
promise: Promise<T>;
|
|
7
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
8
|
+
reject: (reason?: any) => void;
|
|
9
|
+
constructor();
|
|
10
|
+
}
|
|
11
|
+
export declare function getEntireUrl(uri: string, baseURI: string): string;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
/**
|
|
5
|
+
* @author Kuitos
|
|
6
|
+
* @since 2023-04-26
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export var Deferred = /*#__PURE__*/_createClass(function Deferred() {
|
|
10
|
+
var _this = this;
|
|
11
|
+
_classCallCheck(this, Deferred);
|
|
12
|
+
_defineProperty(this, "promise", void 0);
|
|
13
|
+
_defineProperty(this, "resolve", void 0);
|
|
14
|
+
_defineProperty(this, "reject", void 0);
|
|
15
|
+
this.promise = new Promise(function (resolve, reject) {
|
|
16
|
+
_this.resolve = resolve;
|
|
17
|
+
_this.reject = reject;
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
export function getEntireUrl(uri, baseURI) {
|
|
21
|
+
var publicPath = new URL(baseURI, window.location.href);
|
|
22
|
+
var entireUrl = new URL(uri, publicPath.toString());
|
|
23
|
+
return entireUrl.toString();
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["Deferred","promise","Promise","resolve","reject","getEntireUrl","uri","baseURI","publicPath","URL","window","location","href","entireUrl","toString"],"sources":["../../src/utils.ts"],"sourcesContent":["/**\n * @author Kuitos\n * @since 2023-04-26\n */\n\nexport class Deferred<T> {\n promise: Promise<T>;\n\n resolve!: (value: T | PromiseLike<T>) => void;\n\n reject!: (reason?: any) => void;\n\n constructor() {\n this.promise = new Promise((resolve, reject) => {\n this.resolve = resolve;\n this.reject = reject;\n });\n }\n}\n\nexport function getEntireUrl(uri: string, baseURI: string): string {\n const publicPath = new URL(baseURI, window.location.href);\n const entireUrl = new URL(uri, publicPath.toString());\n return entireUrl.toString();\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;;AAEA,WAAaA,QAAQ,6BAOnB,oBAAc;EAAA;EAAA;EAAA;EAAA;EAAA;EACZ,IAAI,CAACC,OAAO,GAAG,IAAIC,OAAO,CAAC,UAACC,OAAO,EAAEC,MAAM,EAAK;IAC9C,KAAI,CAACD,OAAO,GAAGA,OAAO;IACtB,KAAI,CAACC,MAAM,GAAGA,MAAM;EACtB,CAAC,CAAC;AACJ,CAAC;AAGH,OAAO,SAASC,YAAY,CAACC,GAAW,EAAEC,OAAe,EAAU;EACjE,IAAMC,UAAU,GAAG,IAAIC,GAAG,CAACF,OAAO,EAAEG,MAAM,CAACC,QAAQ,CAACC,IAAI,CAAC;EACzD,IAAMC,SAAS,GAAG,IAAIJ,GAAG,CAACH,GAAG,EAAEE,UAAU,CAACM,QAAQ,EAAE,CAAC;EACrD,OAAOD,SAAS,CAACC,QAAQ,EAAE;AAC7B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@qiankunjs/shared",
|
|
3
|
+
"version": "0.0.1-alpha.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.js",
|
|
7
|
+
"types": "./dist/esm/index.d.ts",
|
|
8
|
+
"author": "Kuitos",
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@babel/runtime": "^7.10.5",
|
|
12
|
+
"lodash": "^4.17.11",
|
|
13
|
+
"@qiankunjs/sandbox": "^0.0.1-alpha.0"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/lodash": "^4.14.129",
|
|
17
|
+
"babel-plugin-import": "^1.12.1",
|
|
18
|
+
"father": "^4.1.0",
|
|
19
|
+
"import-html-entry": "^1.12.0",
|
|
20
|
+
"single-spa": "6.0.0-beta.3",
|
|
21
|
+
"tachometer": "^0.5.10",
|
|
22
|
+
"typescript": "^4.1.2"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "father build",
|
|
29
|
+
"test": "cross-env NODE_ENV=test jest",
|
|
30
|
+
"bench": "npm run build && tachometer ./benchmarks/parser/tern/import-html-entry.html ./benchmarks/parser/tern/parser.html --timeout=1"
|
|
31
|
+
}
|
|
32
|
+
}
|