@deot/docs-playground 1.1.4 → 1.1.5

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,223 +0,0 @@
1
- const require_cdn = require("./cdn-BoYKnGD3.cjs");
2
- //#region packages/playground/src/core/runtime/local/builtins.ts
3
- var loaders = {
4
- "vue": () => import("vue"),
5
- "vue-router": () => import("vue-router"),
6
- "pinia": () => import("pinia"),
7
- "@deot/helper": () => import("@deot/helper"),
8
- "@deot/helper-cache": () => import("@deot/helper-cache"),
9
- "@deot/helper-device": () => import("@deot/helper-device"),
10
- "@deot/helper-dom": () => import("@deot/helper-dom"),
11
- "@deot/helper-emitter": () => import("@deot/helper-emitter"),
12
- "@deot/helper-fp": () => import("@deot/helper-fp"),
13
- "@deot/helper-is": () => import("@deot/helper-is"),
14
- "@deot/helper-load": () => import("@deot/helper-load"),
15
- "@deot/helper-resize": () => import("@deot/helper-resize"),
16
- "@deot/helper-route": () => import("@deot/helper-route"),
17
- "@deot/helper-scheduler": () => import("@deot/helper-scheduler"),
18
- "@deot/helper-shared": () => import("@deot/helper-shared"),
19
- "@deot/helper-unicode": () => import("@deot/helper-unicode"),
20
- "@deot/helper-utils": () => import("@deot/helper-utils"),
21
- "@deot/helper-validator": () => import("@deot/helper-validator"),
22
- "@deot/helper-wheel": () => import("@deot/helper-wheel"),
23
- "@deot/http-client": () => import("@deot/http-client"),
24
- "@deot/http-core": () => import("@deot/http-core"),
25
- "@deot/http-hooks": () => import("@deot/http-hooks"),
26
- "@deot/http": () => import("@deot/http"),
27
- "@deot/vc": () => import("@deot/vc"),
28
- "@deot/vc-components": () => import("@deot/vc-components"),
29
- "@deot/vc-hooks": () => import("@deot/vc-hooks"),
30
- "@deot/vc-locale": () => import("@deot/vc-locale"),
31
- "lodash-es": () => import("lodash-es"),
32
- "echarts": () => import("echarts"),
33
- "photoswipe": () => import("photoswipe"),
34
- "jszip": () => import("jszip"),
35
- "jspdf": () => import("jspdf"),
36
- "dayjs": async () => (await import("dayjs")).default
37
- };
38
- var cache = /* @__PURE__ */ new Map();
39
- /** 直接渲染可从宿主包注入的说明符。用到时再加载,避免预览启动时执行全部副作用。 */
40
- var localBuiltinIds = new Set(Object.keys(loaders));
41
- var ensureLocalBuiltin = (id) => {
42
- const loader = loaders[id];
43
- if (!loader) return Promise.reject(/* @__PURE__ */ new Error(`[Playground] 没有本地模块 "${id}"`));
44
- let pending = cache.get(id);
45
- if (!pending) {
46
- pending = loader();
47
- cache.set(id, pending);
48
- }
49
- return pending;
50
- };
51
- //#endregion
52
- //#region packages/playground/src/core/runtime/local/modules.ts
53
- var SKIP_COPY_KEYS = /* @__PURE__ */ new Set([
54
- "prototype",
55
- "caller",
56
- "arguments"
57
- ]);
58
- var toHostModule = (ns) => {
59
- if (ns == null || typeof ns !== "object" && typeof ns !== "function") return {
60
- __esModule: true,
61
- default: ns
62
- };
63
- const source = ns;
64
- const mod = { __esModule: true };
65
- const assignKey = (key) => {
66
- if (SKIP_COPY_KEYS.has(key) || key === "__esModule") return;
67
- try {
68
- mod[key] = source[key];
69
- } catch {}
70
- };
71
- try {
72
- Object.keys(source).forEach(assignKey);
73
- } catch {}
74
- try {
75
- Object.getOwnPropertyNames(source).forEach(assignKey);
76
- } catch {}
77
- if (!("default" in mod) || mod.default === void 0) mod.default = source.default !== void 0 ? source.default : source;
78
- return mod;
79
- };
80
- var lookupHostModule = (id, modules) => {
81
- if (Object.prototype.hasOwnProperty.call(modules, id)) return toHostModule(modules[id]);
82
- return null;
83
- };
84
- var pickNestedExport = (rootMod, rest) => {
85
- if (!rest) return void 0;
86
- const parts = rest.split("/").filter(Boolean);
87
- let current = rootMod;
88
- for (const part of parts) {
89
- if (current == null || typeof current !== "object" && typeof current !== "function") return;
90
- const record = current;
91
- if (!(part in record)) return void 0;
92
- current = record[part];
93
- }
94
- return current;
95
- };
96
- /**
97
- * 先精确匹配,再从右往左剥路径,把剩余段当成导出属性。
98
- * 模块表只来自当前 Playground,不写入全局注册表。
99
- * @param id 裸模块说明符。
100
- * @param modules 当前 Playground 的模块表。
101
- * @returns 可被 `require` 使用的模块;找不到时返回 null。
102
- */
103
- var resolveHostModule = (id, modules) => {
104
- const exact = lookupHostModule(id, modules);
105
- if (exact) return exact;
106
- let cursor = id;
107
- while (true) {
108
- const slash = cursor.lastIndexOf("/");
109
- if (slash <= 0) break;
110
- const parent = cursor.slice(0, slash);
111
- const rest = id.slice(parent.length + 1);
112
- const rootMod = lookupHostModule(parent, modules);
113
- if (rootMod) {
114
- const nested = pickNestedExport(rootMod, rest);
115
- if (nested !== void 0) return toHostModule(nested);
116
- }
117
- cursor = parent;
118
- }
119
- return null;
120
- };
121
- var HOST_VUE_SPECIFIERS = /* @__PURE__ */ new Set(["vue", "vue/server-renderer"]);
122
- var messageOf = (error) => error instanceof Error ? error.message : String(error);
123
- /**
124
- * 找到 import map 里能覆盖该说明符的键。子路径没有独立 URL 时回退到父包。
125
- * @param id 裸模块说明符。
126
- * @param imports 合并后的 import map。
127
- * @returns 命中的 import map 键;没有地址时返回 null。
128
- */
129
- var resolveImportTarget = (id, imports) => {
130
- if (imports[id]) return id;
131
- let cursor = id;
132
- while (true) {
133
- const slash = cursor.lastIndexOf("/");
134
- if (slash <= 0) return null;
135
- const parent = cursor.slice(0, slash);
136
- if (imports[parent]) return parent;
137
- cursor = parent;
138
- }
139
- };
140
- var prefersLocalBuiltin = (id, imports, cdnURL) => {
141
- if (!localBuiltinIds.has(id) && !HOST_VUE_SPECIFIERS.has(id)) return false;
142
- const url = imports[id];
143
- if (!url) return true;
144
- return url === require_cdn.createBuiltinImports(cdnURL)[id];
145
- };
146
- /**
147
- * 内置依赖先注入宿主副本。import map 里与默认 CDN 不同的地址会覆盖,包括 `vue`。
148
- * @param specifiers 本次预览用到的裸模块说明符。
149
- * @param imports 合并后的 import map。
150
- * @param builtins 宿主 Vue 与 vue-router。
151
- * @param builtins.vue 当前页面的 Vue 模块。
152
- * @param builtins.vueRouter 打包进来的 vue-router,可被 import map 覆盖。
153
- * @param loader 按 URL 加载远程模块。
154
- * @param cdnURL 当前 CDN 根,用来识别默认地址。
155
- * @returns 模块表和加载错误。
156
- */
157
- var loadLocalModules = async (specifiers, imports, builtins, loader, cdnURL) => {
158
- const modules = {
159
- "vue": builtins.vue,
160
- "vue-router": builtins.vueRouter
161
- };
162
- const errors = [];
163
- const targets = /* @__PURE__ */ new Set();
164
- const localIds = /* @__PURE__ */ new Set();
165
- specifiers.forEach((specifier) => {
166
- let local = false;
167
- if (prefersLocalBuiltin(specifier, imports, cdnURL)) localIds.add(specifier);
168
- else {
169
- let cursor = specifier;
170
- while (true) {
171
- const slash = cursor.lastIndexOf("/");
172
- if (slash <= 0) break;
173
- const parent = cursor.slice(0, slash);
174
- if (prefersLocalBuiltin(parent, imports, cdnURL)) {
175
- localIds.add(parent);
176
- local = true;
177
- break;
178
- }
179
- cursor = parent;
180
- }
181
- }
182
- if (specifier === "vue-router") {
183
- if (imports["vue-router"]) targets.add("vue-router");
184
- return;
185
- }
186
- const target = resolveImportTarget(specifier, imports);
187
- if (target && prefersLocalBuiltin(target, imports, cdnURL)) localIds.add(target);
188
- else if (target) targets.add(target);
189
- else if (!local && !localIds.has(specifier)) {
190
- imports[specifier] = require_cdn.resolveNpmImport(specifier);
191
- targets.add(specifier);
192
- }
193
- });
194
- await Promise.all([...localIds].map(async (id) => {
195
- if (id === "vue" || id === "vue-router") return;
196
- if (id === "vue/server-renderer") {
197
- modules[id] = builtins.vue;
198
- return;
199
- }
200
- modules[id] = await ensureLocalBuiltin(id);
201
- }));
202
- for (const id of targets) {
203
- const url = imports[id];
204
- if (!url || prefersLocalBuiltin(id, imports, cdnURL)) continue;
205
- try {
206
- modules[id] = await loader(url);
207
- } catch (error) {
208
- errors.push(`[Playground] 无法加载模块 "${id}" (${url}): ${messageOf(error)}`);
209
- }
210
- }
211
- return {
212
- modules,
213
- errors
214
- };
215
- };
216
- //#endregion
217
- exports.ensureLocalBuiltin = ensureLocalBuiltin;
218
- exports.loadLocalModules = loadLocalModules;
219
- exports.localBuiltinIds = localBuiltinIds;
220
- exports.prefersLocalBuiltin = prefersLocalBuiltin;
221
- exports.resolveHostModule = resolveHostModule;
222
- exports.resolveImportTarget = resolveImportTarget;
223
- exports.toHostModule = toHostModule;
@@ -1,152 +0,0 @@
1
- const require_cdn = require("./cdn-BoYKnGD3.cjs");
2
- const require_files = require("./files-BsAOZiPN.cjs");
3
- const require_script = require("./script-BiCcpu3G.cjs");
4
- const require_modules = require("./modules-E6kK6ZJH.cjs");
5
- let es_module_lexer = require("es-module-lexer");
6
- let sucrase = require("sucrase");
7
- //#region packages/playground/src/core/runtime/local/remote.ts
8
- var HOST_VUE = /* @__PURE__ */ new Set(["vue", "vue/server-renderer"]);
9
- /**
10
- * 把 CDN 上的 ESM 先拉完整张依赖图,再在当前页面里执行。
11
- * 裸导入优先走 import map,缺失的 npm 依赖回退到 CDN ESM;import() 按需加载。
12
- * @param imports 合并后的 import map。
13
- * @param builtins 宿主 Vue 与 vue-router。
14
- * @param cdnURL 当前 CDN 根,用来识别默认地址。
15
- * @param importModule 浏览器原生 ESM 加载器。
16
- * @returns 按 URL 加载并执行远程模块的加载器。
17
- */
18
- var createRemoteLoader = (imports, builtins, cdnURL, importModule = (url) => import(
19
- /* @vite-ignore */
20
- url
21
- )) => {
22
- const hostModules = {
23
- "vue": builtins.vue,
24
- "vue-router": builtins.vueRouter
25
- };
26
- const pendingBuiltins = /* @__PURE__ */ new Set();
27
- const texts = /* @__PURE__ */ new Map();
28
- const evaluated = /* @__PURE__ */ new Map();
29
- const crawled = /* @__PURE__ */ new Set();
30
- const nativeModules = /* @__PURE__ */ new Map();
31
- const loadNative = (url) => {
32
- let pending = nativeModules.get(url);
33
- if (!pending) {
34
- pending = importModule(url).then((module) => {
35
- const exports = require_modules.toHostModule(module);
36
- evaluated.set(url, exports);
37
- return exports;
38
- });
39
- nativeModules.set(url, pending);
40
- }
41
- return pending;
42
- };
43
- const localBuiltinId = (id) => {
44
- if (imports[id] && !require_modules.prefersLocalBuiltin(id, imports, cdnURL)) return null;
45
- if (require_modules.prefersLocalBuiltin(id, imports, cdnURL)) return id;
46
- let cursor = id;
47
- while (true) {
48
- const slash = cursor.lastIndexOf("/");
49
- if (slash <= 0) return null;
50
- const parent = cursor.slice(0, slash);
51
- if (require_modules.prefersLocalBuiltin(parent, imports, cdnURL)) return parent;
52
- cursor = parent;
53
- }
54
- };
55
- const dependencyUrl = (from, specifier) => {
56
- if (require_files.isRelativeSpecifier(specifier) || /^https?:\/\//.test(specifier)) return new URL(specifier, from).href;
57
- if (imports[specifier] && !require_modules.prefersLocalBuiltin(specifier, imports, cdnURL)) return imports[specifier];
58
- if (HOST_VUE.has(specifier) && require_modules.prefersLocalBuiltin(specifier, imports, cdnURL)) return null;
59
- let cursor = specifier;
60
- while (cursor) {
61
- if (require_modules.localBuiltinIds.has(cursor) && require_modules.prefersLocalBuiltin(cursor, imports, cdnURL)) {
62
- pendingBuiltins.add(cursor);
63
- return null;
64
- }
65
- const slash = cursor.lastIndexOf("/");
66
- if (slash <= 0) break;
67
- cursor = cursor.slice(0, slash);
68
- }
69
- const target = imports[specifier] ? specifier : require_modules.resolveImportTarget(specifier, imports);
70
- if (!target) {
71
- imports[specifier] = require_cdn.resolveNpmImport(specifier);
72
- return imports[specifier];
73
- }
74
- return imports[target];
75
- };
76
- const crawl = async (url) => {
77
- if (/\/\+esm(?:[?#]|$)/.test(url)) {
78
- await loadNative(url);
79
- return;
80
- }
81
- if (crawled.has(url)) return;
82
- crawled.add(url);
83
- const response = await fetch(url);
84
- if (!response.ok) throw new Error(`${response.status} ${url}`);
85
- const text = await response.text();
86
- await es_module_lexer.init;
87
- const [specifiers] = (0, es_module_lexer.parse)(text);
88
- let source = text;
89
- for (const item of [...specifiers].reverse()) if (item.d >= 0) source = source.slice(0, item.ss) + "__import" + source.slice(item.ss + 6);
90
- texts.set(url, source);
91
- await Promise.all(specifiers.filter((item) => item.d === -1).map(async (item) => {
92
- const next = dependencyUrl(url, item.n);
93
- if (next) await crawl(next);
94
- }));
95
- };
96
- const requireFrom = (from) => (id) => {
97
- if (HOST_VUE.has(id) && require_modules.prefersLocalBuiltin(id, imports, cdnURL)) return require_modules.toHostModule(builtins.vue);
98
- const builtinId = localBuiltinId(id);
99
- if (builtinId) return require_modules.toHostModule(hostModules[builtinId]);
100
- if (require_files.isRelativeSpecifier(id) || /^https?:\/\//.test(id)) return evaluate(new URL(id, from).href);
101
- const target = imports[id] ? id : require_modules.resolveImportTarget(id, imports);
102
- if (!target || !imports[target]) throw new Error(`[Playground] 未注册的模块 "${id}"`);
103
- const loaded = evaluate(imports[target]);
104
- if (target === id) return loaded;
105
- if (!require_modules.resolveHostModule(id, { [target]: loaded }))
106
- /* istanbul ignore next -- 父包没有对应导出时才拒绝 */
107
- throw new Error(`[Playground] 未注册的模块 "${id}"`);
108
- return loaded;
109
- };
110
- const evaluate = (url) => {
111
- if (evaluated.has(url)) return evaluated.get(url);
112
- const text = texts.get(url);
113
- if (text == null) throw new Error(`[Playground] 远程模块尚未下载: ${url}`);
114
- const cjs = (0, sucrase.transform)(require_script.rewriteImportMeta(text, url), {
115
- transforms: ["imports"],
116
- disableESTransforms: true,
117
- production: true,
118
- filePath: url
119
- }).code;
120
- const module = { exports: {} };
121
- evaluated.set(url, module.exports);
122
- new Function("require", "module", "exports", "__import", cjs)(requireFrom(url), module, module.exports, async (id) => {
123
- const next = dependencyUrl(url, id);
124
- if (next) await load(next);
125
- else {
126
- const builtinId = localBuiltinId(id);
127
- if (builtinId && !(builtinId in hostModules)) hostModules[builtinId] = await require_modules.ensureLocalBuiltin(builtinId);
128
- }
129
- return requireFrom(url)(id);
130
- });
131
- evaluated.set(url, module.exports);
132
- return module.exports;
133
- };
134
- const loading = /* @__PURE__ */ new Map();
135
- const load = (url) => {
136
- const pending = loading.get(url);
137
- if (pending) return pending;
138
- const task = (async () => {
139
- await crawl(url);
140
- await Promise.all([...pendingBuiltins].map(async (id) => {
141
- if (id === "vue" || id === "vue-router") return;
142
- hostModules[id] = await require_modules.ensureLocalBuiltin(id);
143
- }));
144
- return evaluate(url);
145
- })();
146
- loading.set(url, task);
147
- return task;
148
- };
149
- return { load };
150
- };
151
- //#endregion
152
- exports.createRemoteLoader = createRemoteLoader;
@@ -1,152 +0,0 @@
1
- import { l as isRelativeSpecifier } from "./files-BqucFldk.js";
2
- import { a as resolveNpmImport } from "./cdn-DQoETju_.js";
3
- import { t as rewriteImportMeta } from "./script-DjUf9uWK.js";
4
- import { n as localBuiltinIds, prefersLocalBuiltin, resolveHostModule, resolveImportTarget, t as ensureLocalBuiltin, toHostModule } from "./modules-BGzPcoRR.js";
5
- import { init, parse } from "es-module-lexer";
6
- import { transform } from "sucrase";
7
- //#region packages/playground/src/core/runtime/local/remote.ts
8
- var HOST_VUE = /* @__PURE__ */ new Set(["vue", "vue/server-renderer"]);
9
- /**
10
- * 把 CDN 上的 ESM 先拉完整张依赖图,再在当前页面里执行。
11
- * 裸导入优先走 import map,缺失的 npm 依赖回退到 CDN ESM;import() 按需加载。
12
- * @param imports 合并后的 import map。
13
- * @param builtins 宿主 Vue 与 vue-router。
14
- * @param cdnURL 当前 CDN 根,用来识别默认地址。
15
- * @param importModule 浏览器原生 ESM 加载器。
16
- * @returns 按 URL 加载并执行远程模块的加载器。
17
- */
18
- var createRemoteLoader = (imports, builtins, cdnURL, importModule = (url) => import(
19
- /* @vite-ignore */
20
- url
21
- )) => {
22
- const hostModules = {
23
- "vue": builtins.vue,
24
- "vue-router": builtins.vueRouter
25
- };
26
- const pendingBuiltins = /* @__PURE__ */ new Set();
27
- const texts = /* @__PURE__ */ new Map();
28
- const evaluated = /* @__PURE__ */ new Map();
29
- const crawled = /* @__PURE__ */ new Set();
30
- const nativeModules = /* @__PURE__ */ new Map();
31
- const loadNative = (url) => {
32
- let pending = nativeModules.get(url);
33
- if (!pending) {
34
- pending = importModule(url).then((module) => {
35
- const exports = toHostModule(module);
36
- evaluated.set(url, exports);
37
- return exports;
38
- });
39
- nativeModules.set(url, pending);
40
- }
41
- return pending;
42
- };
43
- const localBuiltinId = (id) => {
44
- if (imports[id] && !prefersLocalBuiltin(id, imports, cdnURL)) return null;
45
- if (prefersLocalBuiltin(id, imports, cdnURL)) return id;
46
- let cursor = id;
47
- while (true) {
48
- const slash = cursor.lastIndexOf("/");
49
- if (slash <= 0) return null;
50
- const parent = cursor.slice(0, slash);
51
- if (prefersLocalBuiltin(parent, imports, cdnURL)) return parent;
52
- cursor = parent;
53
- }
54
- };
55
- const dependencyUrl = (from, specifier) => {
56
- if (isRelativeSpecifier(specifier) || /^https?:\/\//.test(specifier)) return new URL(specifier, from).href;
57
- if (imports[specifier] && !prefersLocalBuiltin(specifier, imports, cdnURL)) return imports[specifier];
58
- if (HOST_VUE.has(specifier) && prefersLocalBuiltin(specifier, imports, cdnURL)) return null;
59
- let cursor = specifier;
60
- while (cursor) {
61
- if (localBuiltinIds.has(cursor) && prefersLocalBuiltin(cursor, imports, cdnURL)) {
62
- pendingBuiltins.add(cursor);
63
- return null;
64
- }
65
- const slash = cursor.lastIndexOf("/");
66
- if (slash <= 0) break;
67
- cursor = cursor.slice(0, slash);
68
- }
69
- const target = imports[specifier] ? specifier : resolveImportTarget(specifier, imports);
70
- if (!target) {
71
- imports[specifier] = resolveNpmImport(specifier);
72
- return imports[specifier];
73
- }
74
- return imports[target];
75
- };
76
- const crawl = async (url) => {
77
- if (/\/\+esm(?:[?#]|$)/.test(url)) {
78
- await loadNative(url);
79
- return;
80
- }
81
- if (crawled.has(url)) return;
82
- crawled.add(url);
83
- const response = await fetch(url);
84
- if (!response.ok) throw new Error(`${response.status} ${url}`);
85
- const text = await response.text();
86
- await init;
87
- const [specifiers] = parse(text);
88
- let source = text;
89
- for (const item of [...specifiers].reverse()) if (item.d >= 0) source = source.slice(0, item.ss) + "__import" + source.slice(item.ss + 6);
90
- texts.set(url, source);
91
- await Promise.all(specifiers.filter((item) => item.d === -1).map(async (item) => {
92
- const next = dependencyUrl(url, item.n);
93
- if (next) await crawl(next);
94
- }));
95
- };
96
- const requireFrom = (from) => (id) => {
97
- if (HOST_VUE.has(id) && prefersLocalBuiltin(id, imports, cdnURL)) return toHostModule(builtins.vue);
98
- const builtinId = localBuiltinId(id);
99
- if (builtinId) return toHostModule(hostModules[builtinId]);
100
- if (isRelativeSpecifier(id) || /^https?:\/\//.test(id)) return evaluate(new URL(id, from).href);
101
- const target = imports[id] ? id : resolveImportTarget(id, imports);
102
- if (!target || !imports[target]) throw new Error(`[Playground] 未注册的模块 "${id}"`);
103
- const loaded = evaluate(imports[target]);
104
- if (target === id) return loaded;
105
- if (!resolveHostModule(id, { [target]: loaded }))
106
- /* istanbul ignore next -- 父包没有对应导出时才拒绝 */
107
- throw new Error(`[Playground] 未注册的模块 "${id}"`);
108
- return loaded;
109
- };
110
- const evaluate = (url) => {
111
- if (evaluated.has(url)) return evaluated.get(url);
112
- const text = texts.get(url);
113
- if (text == null) throw new Error(`[Playground] 远程模块尚未下载: ${url}`);
114
- const cjs = transform(rewriteImportMeta(text, url), {
115
- transforms: ["imports"],
116
- disableESTransforms: true,
117
- production: true,
118
- filePath: url
119
- }).code;
120
- const module = { exports: {} };
121
- evaluated.set(url, module.exports);
122
- new Function("require", "module", "exports", "__import", cjs)(requireFrom(url), module, module.exports, async (id) => {
123
- const next = dependencyUrl(url, id);
124
- if (next) await load(next);
125
- else {
126
- const builtinId = localBuiltinId(id);
127
- if (builtinId && !(builtinId in hostModules)) hostModules[builtinId] = await ensureLocalBuiltin(builtinId);
128
- }
129
- return requireFrom(url)(id);
130
- });
131
- evaluated.set(url, module.exports);
132
- return module.exports;
133
- };
134
- const loading = /* @__PURE__ */ new Map();
135
- const load = (url) => {
136
- const pending = loading.get(url);
137
- if (pending) return pending;
138
- const task = (async () => {
139
- await crawl(url);
140
- await Promise.all([...pendingBuiltins].map(async (id) => {
141
- if (id === "vue" || id === "vue-router") return;
142
- hostModules[id] = await ensureLocalBuiltin(id);
143
- }));
144
- return evaluate(url);
145
- })();
146
- loading.set(url, task);
147
- return task;
148
- };
149
- return { load };
150
- };
151
- //#endregion
152
- export { createRemoteLoader };
@@ -1,43 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
- return target;
16
- };
17
- var __copyProps = (to, from, except, desc) => {
18
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
19
- key = keys[i];
20
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
21
- get: ((k) => from[k]).bind(null, key),
22
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
23
- });
24
- }
25
- return to;
26
- };
27
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
28
- value: mod,
29
- enumerable: true
30
- }) : target, mod));
31
- //#endregion
32
- Object.defineProperty(exports, "__exportAll", {
33
- enumerable: true,
34
- get: function() {
35
- return __exportAll;
36
- }
37
- });
38
- Object.defineProperty(exports, "__toESM", {
39
- enumerable: true,
40
- get: function() {
41
- return __toESM;
42
- }
43
- });
@@ -1,111 +0,0 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- let sucrase = require("sucrase");
3
- let _vue_compiler_sfc_dist_compiler_sfc_esm_browser_js = require("@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js");
4
- _vue_compiler_sfc_dist_compiler_sfc_esm_browser_js = require_rolldown_runtime.__toESM(_vue_compiler_sfc_dist_compiler_sfc_esm_browser_js);
5
- //#region packages/playground/src/core/runtime/local/compile/script.ts
6
- var { babelParse, walkIdentifiers, MagicString } = _vue_compiler_sfc_dist_compiler_sfc_esm_browser_js;
7
- var rewriteJsxAttributes = (code) => {
8
- const replacements = [];
9
- for (const match of code.matchAll(/\b([\w-]+:[\w-]+)\s*=\s*\{/g)) {
10
- let depth = 1;
11
- let quote = "";
12
- const start = match.index + match[0].length;
13
- let end = start;
14
- for (; end < code.length; end += 1) {
15
- const character = code[end];
16
- if (quote) {
17
- if (character === "\\") end += 1;
18
- else if (character === quote) quote = "";
19
- } else if ("\"'`".includes(character)) quote = character;
20
- else if (character === "{") depth += 1;
21
- else if (character === "}" && --depth === 0) break;
22
- }
23
- replacements.push({
24
- start: match.index,
25
- end: end + 1,
26
- text: `{...{${JSON.stringify(match[1])}: ${code.slice(start, end)}}}`
27
- });
28
- }
29
- for (const item of replacements.reverse()) code = code.slice(0, item.start) + item.text + code.slice(item.end);
30
- return code;
31
- };
32
- var removeImportedTypeExports = (code) => {
33
- const types = /* @__PURE__ */ new Set();
34
- for (const match of code.matchAll(/\bimport\s+type\s*\{([^}]+)\}\s*from\s*['"][^'"]+['"]/g)) for (const item of match[1].split(",")) types.add(item.trim().split(/\s+as\s+/).pop());
35
- return code.replace(/\bexport\s*\{([^}]+)\}(?!\s*from)/g, (_statement, names) => `export {${names.split(",").filter((item) => !types.has(item.trim().split(/\s+as\s+/)[0])).join(",")}}`);
36
- };
37
- /**
38
- * files 里的 `import.meta.env` 没有 Vite 注入,接到开发态占位对象上。
39
- * @param code 源码文本。
40
- * @param filename 当前虚拟文件名。
41
- * @returns 替换 `import.meta` 之后的源码。
42
- */
43
- var rewriteImportMeta = (code, filename) => {
44
- if (!code.includes("process") && !code.includes("import.meta")) return code;
45
- const source = new MagicString(code);
46
- let hasMeta = false;
47
- walkIdentifiers(babelParse(code, { sourceType: "module" }), (id, parent, parents) => {
48
- if (id.name === "import" && parent?.type === "MetaProperty") {
49
- source.overwrite(parent.start, parent.end, "import_meta");
50
- hasMeta = true;
51
- }
52
- const outer = parents[parents.length - 2];
53
- if (id.name === "process" && parent?.type === "MemberExpression" && parent.object === id && !parent.computed && parent.property.type === "Identifier" && parent.property.name === "env" && outer?.type === "MemberExpression" && outer.object === parent && !outer.computed && outer.property.type === "Identifier" && outer.property.name === "NODE_ENV") source.overwrite(outer.start, outer.end, JSON.stringify("development"));
54
- }, true);
55
- if (!hasMeta) return source.toString();
56
- const meta = {
57
- url: `playground://${filename}`,
58
- env: {
59
- MODE: "development",
60
- DEV: true,
61
- PROD: false,
62
- SSR: false
63
- }
64
- };
65
- return `var import_meta = ${JSON.stringify(meta)};\n${source}`;
66
- };
67
- /**
68
- * 将 TS / ESM 转成可被 `new Function('require','module','exports', code)` 执行的 CJS。
69
- * @param code 源码文本。
70
- * @param filename 当前虚拟文件名,用来判断是否按 TypeScript 转换。
71
- * @param options 转换选项。
72
- * @param options.typescript 是否启用 TypeScript 转换。
73
- * @param options.jsx 是否转换 Vue JSX。
74
- * @param options.esm 是否保留 ESM 导入导出供 iframe 使用。
75
- * @returns 可执行的 CJS 文本。
76
- */
77
- var transformScript = (code, filename, options = {}) => {
78
- const transforms = options.esm ? [] : ["imports"];
79
- const wantTs = options.typescript === true || options.typescript !== false && (filename.endsWith(".ts") || filename.endsWith(".tsx"));
80
- if (wantTs) transforms.unshift("typescript");
81
- if (options.jsx) transforms.unshift("jsx");
82
- try {
83
- const script = wantTs ? removeImportedTypeExports(code) : code;
84
- const source = options.jsx ? `import { h as __docs_h, Fragment as __docs_Fragment } from 'vue';\n${rewriteJsxAttributes(script)}` : script;
85
- return `${rewriteImportMeta((0, sucrase.transform)(source, {
86
- transforms,
87
- disableESTransforms: true,
88
- production: true,
89
- jsxRuntime: "classic",
90
- jsxPragma: "__docs_h",
91
- jsxFragmentPragma: "__docs_Fragment",
92
- filePath: filename
93
- }).code, filename)}\n//# sourceURL=playground://${filename}`;
94
- } catch (error) {
95
- const message = error instanceof Error ? error.message : String(error);
96
- throw new Error(`[Playground] 脚本转换失败 ${filename}: ${message}`, { cause: error });
97
- }
98
- };
99
- //#endregion
100
- Object.defineProperty(exports, "rewriteImportMeta", {
101
- enumerable: true,
102
- get: function() {
103
- return rewriteImportMeta;
104
- }
105
- });
106
- Object.defineProperty(exports, "transformScript", {
107
- enumerable: true,
108
- get: function() {
109
- return transformScript;
110
- }
111
- });