snowy-designer
Version:
基于Epic-Designer-Pro版本的设计器,可视化开发页面表单
79 lines (78 loc) • 2.54 kB
JavaScript
import { useVueImportMap as M, useStore as g } from "@vue/repl";
import { ref as l } from "vue";
import { useEsModule as v } from "./es-module-shims.js";
import { compileModulesForPreview as _ } from "./moduleCompiler.js";
const { importMap: h, vueVersion: y } = M({
runtimeDev: `${location.origin}/node_modules/.vite/deps/vue.js?v=8f14ebc7`,
serverRenderer: `${location.origin}/src/vue-server-renderer-dev-proxy`
});
async function C(o) {
return new Promise((e) => {
const t = g(
{
builtinImportMap: h,
outputMode: l("js"),
showOutput: l(!0),
vueVersion: y
},
o
);
t.init();
const { importShim: m, setImportMap: s } = v(), c = l(), r = t.getImportMap();
s(r), I(r), c.value = void 0;
const { mainFile: n } = t;
setTimeout(async () => {
const p = _(t), u = w(p), i = new Blob([u], { type: "text/javascript" }), a = URL.createObjectURL(i), d = await m(a);
Object.values(d.default).forEach(
(f) => j(f.__css__)
), e(d.default[n]);
});
});
}
function I(o) {
const e = document.createElement("script");
e.type = "importmap-shim", e.innerHTML = JSON.stringify(o), document.body.append(e);
}
function w(o) {
const t = `const __modules__ = {}; ${o.map((c) => `(() => { ${c} })();`).join(`
`)} export default __modules__;`, m = t.match(/import\s+(?:\S.*?)??from\s+['"].*?['"];?\s*/g) || [], s = t.replaceAll(
/import\s+(?:\S.*?)??from\s+['"].*?['"];?\s*/g,
""
);
return console.log(m, "-imports"), b(m.join(`
`)) + s;
}
function b(o) {
const e = /import\s+(?:\*\s+as\s+(\w+)|(\{[^}]*\}))\s+from\s+['"](.*?)['"];?/g, t = /* @__PURE__ */ new Map(), m = /* @__PURE__ */ new Map();
let s;
for (; (s = e.exec(o)) !== null; ) {
const r = s[1], n = s[2], p = s[3];
if (r)
m.set(p, r);
else if (n) {
const u = n.trim().replaceAll(/[{}]/g, "").split(",").map((i) => i.trim());
t.has(p) || t.set(p, /* @__PURE__ */ new Set()), u.forEach((i) => {
var a;
return (a = t.get(p)) == null ? void 0 : a.add(i);
});
}
}
return [
...[...m.entries()].map(
([r, n]) => `import * as ${n} from '${r}';`
),
...[...t.entries()].map(
([r, n]) => `import { ${[...n].join(", ")} } from '${r}';`
)
].join(`
`);
}
function j(o) {
if (typeof o == "string" && o.length > 0) {
const e = document.createElement("style");
e.type = "text/css", e.append(document.createTextNode(o)), document.head.append(e);
}
}
export {
C as parseComponent
};