setupin 2.2.3 → 2.3.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/dist/main.js +93 -73
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -1,50 +1,6 @@
|
|
|
1
1
|
(function () {
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
function when(gist, verifyer = gist) {
|
|
5
|
-
return function(classify) {
|
|
6
|
-
const sym = Object.getOwnPropertySymbols(classify).find((sym2) => sym2.description === "default");
|
|
7
|
-
const handler = classify[verifyer] ?? (sym && classify[sym]);
|
|
8
|
-
return handler?.(gist);
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
function loaded(callback) {
|
|
12
|
-
document.addEventListener("DOMContentLoaded", callback);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function observe(SorM, callback) {
|
|
16
|
-
return when(SorM, typeof SorM)({
|
|
17
|
-
string: (selector) => new Promise((resolve, reject) => {
|
|
18
|
-
let isFound = false;
|
|
19
|
-
new MutationObserver((mutations, observer) => {
|
|
20
|
-
for (const mutation of mutations) {
|
|
21
|
-
const target = mutation.target?.querySelector(selector);
|
|
22
|
-
if (target) {
|
|
23
|
-
isFound = true;
|
|
24
|
-
observer.disconnect();
|
|
25
|
-
const result = callback?.(target);
|
|
26
|
-
result instanceof Error ? reject(result) : resolve(result);
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
loaded(() => {
|
|
31
|
-
if (isFound)
|
|
32
|
-
return;
|
|
33
|
-
observer.disconnect();
|
|
34
|
-
resolve(callback?.(void 0));
|
|
35
|
-
console.warn(`No ${selector} found`);
|
|
36
|
-
});
|
|
37
|
-
}).observe(document, {
|
|
38
|
-
childList: true,
|
|
39
|
-
subtree: true
|
|
40
|
-
});
|
|
41
|
-
}),
|
|
42
|
-
object: (map) => Object.fromEntries(
|
|
43
|
-
Object.entries(map).map(([key, fn]) => [key, observe(key, fn)])
|
|
44
|
-
)
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
|
|
48
4
|
var lib = {};
|
|
49
5
|
|
|
50
6
|
Object.defineProperty(lib, '__esModule', {
|
|
@@ -14068,9 +14024,54 @@
|
|
|
14068
14024
|
lib.parseExpression = parseExpression;
|
|
14069
14025
|
lib.tokTypes = tokTypes;
|
|
14070
14026
|
|
|
14071
|
-
function
|
|
14072
|
-
|
|
14027
|
+
function extractImport(astBody, code) {
|
|
14028
|
+
const imports = astBody.filter(({ type }) => type === "ImportDeclaration").map((node) => code.slice(node.start, node.end));
|
|
14029
|
+
return {
|
|
14030
|
+
importText: imports.join("\n"),
|
|
14031
|
+
setupText: code.replace(new RegExp(imports.join("|"), "g"), "")
|
|
14032
|
+
};
|
|
14033
|
+
}
|
|
14034
|
+
|
|
14035
|
+
function observe(selector, callback) {
|
|
14036
|
+
return new Promise((resolve, reject) => {
|
|
14037
|
+
let isFound = false;
|
|
14038
|
+
new MutationObserver((mutations, observer) => {
|
|
14039
|
+
for (const mutation of mutations) {
|
|
14040
|
+
const target = mutation.target?.querySelector(selector);
|
|
14041
|
+
if (target) {
|
|
14042
|
+
isFound = true;
|
|
14043
|
+
observer.disconnect();
|
|
14044
|
+
resolve(callback?.(target));
|
|
14045
|
+
break;
|
|
14046
|
+
}
|
|
14047
|
+
}
|
|
14048
|
+
document.addEventListener("DOMContentLoaded", () => {
|
|
14049
|
+
if (isFound)
|
|
14050
|
+
return;
|
|
14051
|
+
observer.disconnect();
|
|
14052
|
+
const result = callback?.(void 0);
|
|
14053
|
+
if (result instanceof Error) {
|
|
14054
|
+
reject(result);
|
|
14055
|
+
} else {
|
|
14056
|
+
resolve(result);
|
|
14057
|
+
console.warn(`No ${selector} found`);
|
|
14058
|
+
}
|
|
14059
|
+
});
|
|
14060
|
+
}).observe(document, {
|
|
14061
|
+
childList: true,
|
|
14062
|
+
subtree: true
|
|
14063
|
+
});
|
|
14064
|
+
});
|
|
14065
|
+
}
|
|
14066
|
+
|
|
14067
|
+
function when(gist, verifyer = gist) {
|
|
14068
|
+
return function(classify) {
|
|
14069
|
+
const sym = Object.getOwnPropertySymbols(classify).find((sym2) => sym2.description === "default");
|
|
14070
|
+
const handler = classify[verifyer] ?? (sym && classify[sym]);
|
|
14071
|
+
return handler?.(gist);
|
|
14072
|
+
};
|
|
14073
14073
|
}
|
|
14074
|
+
|
|
14074
14075
|
function getGlobalVars(astBody) {
|
|
14075
14076
|
return astBody.flatMap((node) => when(node, node.type)({
|
|
14076
14077
|
FunctionDeclaration: ({ id }) => id ? [id.name] : [],
|
|
@@ -14095,43 +14096,62 @@
|
|
|
14095
14096
|
});
|
|
14096
14097
|
}
|
|
14097
14098
|
}
|
|
14098
|
-
|
|
14099
|
-
|
|
14100
|
-
|
|
14099
|
+
|
|
14100
|
+
function ast(code) {
|
|
14101
|
+
const astBody = parse_1(code, { sourceType: "module" }).program.body;
|
|
14102
|
+
return {
|
|
14103
|
+
getGlobalVars: () => getGlobalVars(astBody),
|
|
14104
|
+
extractImport: () => extractImport(astBody, code)
|
|
14105
|
+
};
|
|
14101
14106
|
}
|
|
14102
14107
|
|
|
14103
|
-
function parseSetup(
|
|
14104
|
-
const
|
|
14105
|
-
|
|
14106
|
-
|
|
14107
|
-
|
|
14108
|
-
scriptEl.type = "module";
|
|
14109
|
-
scriptEl.textContent = importText;
|
|
14108
|
+
function parseSetup(setupEl) {
|
|
14109
|
+
const scriptContent = setupEl?.textContent ?? "";
|
|
14110
|
+
if (setupEl) {
|
|
14111
|
+
setupEl.type = "module";
|
|
14112
|
+
setupEl.textContent = "";
|
|
14110
14113
|
} else {
|
|
14111
|
-
|
|
14114
|
+
setupEl = document.createElement("script");
|
|
14115
|
+
setupEl.type = "module";
|
|
14116
|
+
document.head.appendChild(setupEl);
|
|
14112
14117
|
}
|
|
14118
|
+
const { extractImport, getGlobalVars } = ast(scriptContent);
|
|
14113
14119
|
return {
|
|
14114
|
-
|
|
14115
|
-
retNames: getGlobalVars(
|
|
14120
|
+
...extractImport(),
|
|
14121
|
+
retNames: getGlobalVars(),
|
|
14122
|
+
setupEl
|
|
14116
14123
|
};
|
|
14117
14124
|
}
|
|
14118
14125
|
|
|
14119
|
-
function parseTemplate(
|
|
14120
|
-
|
|
14121
|
-
|
|
14122
|
-
|
|
14123
|
-
|
|
14124
|
-
return
|
|
14126
|
+
function parseTemplate(templateEl) {
|
|
14127
|
+
if (!templateEl)
|
|
14128
|
+
return new Error("No template found");
|
|
14129
|
+
const templateContent = templateEl.innerHTML;
|
|
14130
|
+
templateEl.remove();
|
|
14131
|
+
return templateContent.replace(/[`"'$\\]/g, (s) => `\\${s}`);
|
|
14125
14132
|
}
|
|
14126
14133
|
|
|
14127
|
-
const oTemplate = observe("
|
|
14134
|
+
const oTemplate = observe("head>template", parseTemplate);
|
|
14128
14135
|
const oSetup = observe("script[setup]", parseSetup);
|
|
14129
|
-
|
|
14130
|
-
const
|
|
14131
|
-
const
|
|
14132
|
-
|
|
14133
|
-
|
|
14134
|
-
|
|
14135
|
-
|
|
14136
|
+
(async () => {
|
|
14137
|
+
const template = await oTemplate;
|
|
14138
|
+
const { setupEl, importText, setupText, retNames } = await oSetup;
|
|
14139
|
+
setupEl.textContent = `
|
|
14140
|
+
import * as Vue from 'https://unpkg.com/vue/dist/vue.esm-browser.prod.js'
|
|
14141
|
+
${importText}
|
|
14142
|
+
for (const k in Vue) {
|
|
14143
|
+
window[k] = Vue[k]
|
|
14144
|
+
}
|
|
14145
|
+
Vue.createApp({
|
|
14146
|
+
template: \`${template}\`,
|
|
14147
|
+
setup(){
|
|
14148
|
+
${setupText}
|
|
14149
|
+
return {
|
|
14150
|
+
${retNames}
|
|
14151
|
+
}
|
|
14152
|
+
}
|
|
14153
|
+
}).mount(document.body)
|
|
14154
|
+
`;
|
|
14155
|
+
})();
|
|
14136
14156
|
|
|
14137
14157
|
})();
|