@deot/docs-playground 1.1.3 → 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.
- package/README.md +1 -0
- package/dist/{compile-DSMuM8zl.cjs → compile-29EUKPOy.cjs} +29 -40
- package/dist/{compile-Bw7v7QE-.js → compile-CM_OyqYN.js} +21 -32
- package/dist/css-DleINdoA.js +580 -0
- package/dist/css-DpqJBQ5c.cjs +786 -0
- package/dist/index.cjs +1925 -101
- package/dist/index.js +1879 -47
- package/dist/index.style.css +1 -1
- package/package.json +21 -20
- package/dist/cdn-Czve5_9b.cjs +0 -94
- package/dist/cdn-DEvdGJu2.js +0 -53
- package/dist/files-C5UMzYxA.js +0 -178
- package/dist/files-D5LNOtjp.cjs +0 -192
- package/dist/linker-B--sjERT.cjs +0 -167
- package/dist/linker-JHdz37DK.js +0 -166
- package/dist/local-sandbox-B8IJ5jWb.js +0 -431
- package/dist/local-sandbox-DnkKrBhf.cjs +0 -428
- package/dist/modules-CInmL-8h.cjs +0 -217
- package/dist/modules-DlLJF_vd.js +0 -211
- package/dist/remote-CKMzn1J3.cjs +0 -106
- package/dist/remote-DfXAsO9n.js +0 -106
- package/dist/rolldown-runtime-C0BPl7ul.cjs +0 -43
- package/dist/script-5Xzzx7u5.cjs +0 -57
- package/dist/script-xKUjE8pf.js +0 -46
- package/dist/scss-Co2it4vB.js +0 -215
- package/dist/scss-DaIqB_qT.cjs +0 -233
- package/dist/store-BF7z-oaO.cjs +0 -964
- package/dist/store-D8vwi-HV.js +0 -767
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
|
|
2
|
-
const require_store = require("./store-BF7z-oaO.cjs");
|
|
3
|
-
let vue = require("vue");
|
|
4
|
-
vue = require_rolldown_runtime.__toESM(vue);
|
|
5
|
-
let _deot_vc = require("@deot/vc");
|
|
6
|
-
let vue_router = require("vue-router");
|
|
7
|
-
vue_router = require_rolldown_runtime.__toESM(vue_router);
|
|
8
|
-
//#region packages/playground/src/core/runtime/local/compile/css.ts
|
|
9
|
-
var collectCss = (chunks) => {
|
|
10
|
-
const result = [];
|
|
11
|
-
chunks.forEach((chunk) => {
|
|
12
|
-
const css = String(chunk || "").trim();
|
|
13
|
-
if (css) result.push(css);
|
|
14
|
-
});
|
|
15
|
-
return result;
|
|
16
|
-
};
|
|
17
|
-
var injectStyle = (id, cssList) => {
|
|
18
|
-
/* istanbul ignore if -- 仅浏览器注入样式 */
|
|
19
|
-
if (typeof document === "undefined") return null;
|
|
20
|
-
document.querySelector(`style[data-playground-id="${id}"]`)?.remove();
|
|
21
|
-
const css = cssList.filter(Boolean).join("\n");
|
|
22
|
-
if (!css) return null;
|
|
23
|
-
const style = document.createElement("style");
|
|
24
|
-
style.setAttribute("data-playground-id", id);
|
|
25
|
-
style.textContent = css;
|
|
26
|
-
document.head.appendChild(style);
|
|
27
|
-
return style;
|
|
28
|
-
};
|
|
29
|
-
var removeStyle = (id) => {
|
|
30
|
-
/* istanbul ignore if -- 仅浏览器注入样式 */
|
|
31
|
-
if (typeof document === "undefined") return;
|
|
32
|
-
document.querySelector(`style[data-playground-id="${id}"]`)?.remove();
|
|
33
|
-
};
|
|
34
|
-
//#endregion
|
|
35
|
-
//#region packages/playground/src/core/runtime/local/playground.ts
|
|
36
|
-
/**
|
|
37
|
-
* 直接渲染与页面同文档,弹层不需要临时撑高。
|
|
38
|
-
* `run` 仍返回可调用函数,但不会申请高度,也不会改动预览尺寸。
|
|
39
|
-
* @param vue 宿主 Vue,只用其中的 `isRef`。
|
|
40
|
-
* @returns 注入给预览的 `docs:playground`。
|
|
41
|
-
*/
|
|
42
|
-
var createLocalPlayground = (vue) => {
|
|
43
|
-
const run = (_height, optionsOrHandler, lastHandler) => {
|
|
44
|
-
const visible = (typeof optionsOrHandler === "function" || optionsOrHandler == null ? {} : optionsOrHandler).visible;
|
|
45
|
-
const handler = typeof optionsOrHandler === "function" ? optionsOrHandler : typeof lastHandler === "function" ? lastHandler : vue.isRef(visible) ? () => {
|
|
46
|
-
visible.value = true;
|
|
47
|
-
} : void 0;
|
|
48
|
-
return (...args) => {
|
|
49
|
-
if (typeof handler !== "function") return void 0;
|
|
50
|
-
return handler(...args);
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
return {
|
|
54
|
-
enable: () => Promise.resolve(true),
|
|
55
|
-
disable() {},
|
|
56
|
-
dispose() {},
|
|
57
|
-
run
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
//#endregion
|
|
61
|
-
//#region packages/playground/src/core/runtime/local/port.ts
|
|
62
|
-
/** 只在桥接 iframe 内部转发,保证父页面收到的 source 是该 iframe。 */
|
|
63
|
-
var LOCAL_BRIDGE_CHANNEL = "docs:local-out";
|
|
64
|
-
var BRIDGE_INSTALLER = `
|
|
65
|
-
if (!window.__docsLocalBridge) {
|
|
66
|
-
window.__docsLocalBridge = true;
|
|
67
|
-
window.addEventListener('message', function (event) {
|
|
68
|
-
var data = event.data;
|
|
69
|
-
if (!data || data.channel !== ${JSON.stringify(LOCAL_BRIDGE_CHANNEL)}) return;
|
|
70
|
-
window.parent.postMessage(data.payload, '*');
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
`;
|
|
74
|
-
var LOCAL_BRIDGE_SRCDOC = `<!doctype html><html><head></head><body><script>${BRIDGE_INSTALLER}<\/script></body></html>`;
|
|
75
|
-
/**
|
|
76
|
-
* 在同源空白 iframe 里安装转发脚本。调用发生在 iframe realm,父页面看到的 source 才是它。
|
|
77
|
-
* @param iframe 用作消息身份的空白 iframe。
|
|
78
|
-
* @returns 脚本是否已经装上。
|
|
79
|
-
*/
|
|
80
|
-
var installLocalBridge = (iframe) => {
|
|
81
|
-
const win = iframe.contentWindow;
|
|
82
|
-
if (!win || win.__docsLocalBridge) return Boolean(win?.__docsLocalBridge);
|
|
83
|
-
win.eval(BRIDGE_INSTALLER);
|
|
84
|
-
return Boolean(win.__docsLocalBridge);
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* 满足 PlaygroundService 现有 Window 调用的预览窗口。
|
|
88
|
-
* 出站消息经 iframe 转发,入站回复再交回服务,协议仍是 docs:height / docs:navigate。
|
|
89
|
-
*/
|
|
90
|
-
var LocalPreviewPort = class {
|
|
91
|
-
iframe;
|
|
92
|
-
parent;
|
|
93
|
-
listeners = /* @__PURE__ */ new Map();
|
|
94
|
-
constructor(iframe) {
|
|
95
|
-
this.iframe = iframe;
|
|
96
|
-
this.parent = { postMessage: (data) => {
|
|
97
|
-
this.iframe.contentWindow?.postMessage({
|
|
98
|
-
channel: LOCAL_BRIDGE_CHANNEL,
|
|
99
|
-
payload: data
|
|
100
|
-
}, "*");
|
|
101
|
-
} };
|
|
102
|
-
}
|
|
103
|
-
get contentWindow() {
|
|
104
|
-
return this.iframe.contentWindow;
|
|
105
|
-
}
|
|
106
|
-
get innerHeight() {
|
|
107
|
-
const fromWindow = this.iframe.contentWindow?.innerHeight ?? 0;
|
|
108
|
-
if (fromWindow > 0) return fromWindow;
|
|
109
|
-
return this.iframe.clientHeight || this.iframe.parentElement?.clientHeight || 0;
|
|
110
|
-
}
|
|
111
|
-
addEventListener(type, listener) {
|
|
112
|
-
const win = this.iframe.contentWindow;
|
|
113
|
-
if (!win) return;
|
|
114
|
-
if (type !== "message") {
|
|
115
|
-
win.addEventListener(type, listener);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const wrapped = (event) => {
|
|
119
|
-
const message = event;
|
|
120
|
-
const data = message.data;
|
|
121
|
-
if (data && data.channel === "docs:local-out") return;
|
|
122
|
-
listener({
|
|
123
|
-
data: message.data,
|
|
124
|
-
source: this.parent
|
|
125
|
-
});
|
|
126
|
-
};
|
|
127
|
-
this.listeners.set(listener, wrapped);
|
|
128
|
-
win.addEventListener("message", wrapped);
|
|
129
|
-
}
|
|
130
|
-
removeEventListener(type, listener) {
|
|
131
|
-
const win = this.iframe.contentWindow;
|
|
132
|
-
if (!win) return;
|
|
133
|
-
const wrapped = this.listeners.get(listener);
|
|
134
|
-
if (wrapped) {
|
|
135
|
-
this.listeners.delete(listener);
|
|
136
|
-
win.removeEventListener(type, wrapped);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
win.removeEventListener(type, listener);
|
|
140
|
-
}
|
|
141
|
-
requestAnimationFrame(callback) {
|
|
142
|
-
return window.requestAnimationFrame(callback);
|
|
143
|
-
}
|
|
144
|
-
cancelAnimationFrame(handle) {
|
|
145
|
-
window.cancelAnimationFrame(handle);
|
|
146
|
-
}
|
|
147
|
-
setTimeout(handler, timeout, ...args) {
|
|
148
|
-
return window.setTimeout(handler, timeout, ...args);
|
|
149
|
-
}
|
|
150
|
-
clearTimeout(handle) {
|
|
151
|
-
window.clearTimeout(handle);
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region packages/playground/src/core/runtime/local/format-error.ts
|
|
156
|
-
/**
|
|
157
|
-
* 空 reject(例如弹层取消)不要渲染成红条。
|
|
158
|
-
* @param error 运行时抛出的值。
|
|
159
|
-
* @returns 可展示的错误文本;空取消返回空字符串。
|
|
160
|
-
*/
|
|
161
|
-
var formatPlaygroundRuntimeError = (error) => {
|
|
162
|
-
if (error == null) return "";
|
|
163
|
-
const raw = typeof error === "object" && "message" in error ? error.message : error;
|
|
164
|
-
if (raw == null || raw === "") return "";
|
|
165
|
-
const text = String(raw);
|
|
166
|
-
if (text === "undefined" || text === "null") return "";
|
|
167
|
-
return text;
|
|
168
|
-
};
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region packages/playground/src/core/runtime/local/local-sandbox.vue?vue&type=script&setup=true&lang.ts
|
|
171
|
-
var _hoisted_1 = ["srcdoc"];
|
|
172
|
-
var local_sandbox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ (0, vue.defineComponent)({
|
|
173
|
-
__name: "local-sandbox",
|
|
174
|
-
props: {
|
|
175
|
-
files: {},
|
|
176
|
-
entry: {},
|
|
177
|
-
options: {},
|
|
178
|
-
previewScroller: {
|
|
179
|
-
type: Boolean,
|
|
180
|
-
default: false
|
|
181
|
-
},
|
|
182
|
-
clearConsole: {
|
|
183
|
-
type: Boolean,
|
|
184
|
-
default: false
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
emits: ["error"],
|
|
188
|
-
setup(__props, { expose: __expose, emit: __emit }) {
|
|
189
|
-
const props = __props;
|
|
190
|
-
const emit = __emit;
|
|
191
|
-
const bridgeSrcdoc = LOCAL_BRIDGE_SRCDOC;
|
|
192
|
-
const containerEl = (0, vue.ref)(null);
|
|
193
|
-
const bridgeEl = (0, vue.ref)(null);
|
|
194
|
-
const mountEl = (0, vue.ref)(null);
|
|
195
|
-
const compileError = (0, vue.ref)("");
|
|
196
|
-
const runtimeError = (0, vue.ref)("");
|
|
197
|
-
const messageSource = (0, vue.shallowRef)(null);
|
|
198
|
-
let port = null;
|
|
199
|
-
let previewApp = null;
|
|
200
|
-
let version = 0;
|
|
201
|
-
let pendingMount = null;
|
|
202
|
-
const styleId = `docs-local-${Math.random().toString(36).slice(2, 10)}`;
|
|
203
|
-
const publishError = () => {
|
|
204
|
-
emit("error", {
|
|
205
|
-
compile: compileError.value,
|
|
206
|
-
runtime: runtimeError.value
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
(0, vue.watch)([compileError, runtimeError], publishError);
|
|
210
|
-
const createDocsLink = (preview) => (0, vue.defineComponent)({
|
|
211
|
-
name: "DocsLink",
|
|
212
|
-
props: { to: {
|
|
213
|
-
type: String,
|
|
214
|
-
default: ""
|
|
215
|
-
} },
|
|
216
|
-
setup(linkProps, { slots }) {
|
|
217
|
-
return () => (0, vue.h)("a", {
|
|
218
|
-
href: linkProps.to,
|
|
219
|
-
style: {
|
|
220
|
-
color: "inherit",
|
|
221
|
-
textDecoration: "none"
|
|
222
|
-
},
|
|
223
|
-
onClick(event) {
|
|
224
|
-
event.preventDefault();
|
|
225
|
-
preview.parent.postMessage({
|
|
226
|
-
action: "docs:navigate",
|
|
227
|
-
to: linkProps.to
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}, slots.default?.());
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
const destroyPreview = () => {
|
|
234
|
-
previewApp?.unmount();
|
|
235
|
-
previewApp = null;
|
|
236
|
-
removeStyle(styleId);
|
|
237
|
-
};
|
|
238
|
-
const mountPreview = (component, preview, css) => {
|
|
239
|
-
if (!mountEl.value) return;
|
|
240
|
-
destroyPreview();
|
|
241
|
-
injectStyle(styleId, css);
|
|
242
|
-
if (props.clearConsole) console.clear();
|
|
243
|
-
const useScroller = props.previewScroller === true;
|
|
244
|
-
const app = vue.createApp({
|
|
245
|
-
name: "LocalSandboxRoot",
|
|
246
|
-
setup() {
|
|
247
|
-
const service = createLocalPlayground(vue);
|
|
248
|
-
(0, vue.provide)("docs:playground", service);
|
|
249
|
-
(0, vue.onErrorCaptured)((error) => {
|
|
250
|
-
const message = formatPlaygroundRuntimeError(error);
|
|
251
|
-
if (message) runtimeError.value = message;
|
|
252
|
-
return false;
|
|
253
|
-
});
|
|
254
|
-
(0, vue.onBeforeUnmount)(() => service.dispose());
|
|
255
|
-
return () => {
|
|
256
|
-
const content = (0, vue.h)(component);
|
|
257
|
-
if (!useScroller) return content;
|
|
258
|
-
return (0, vue.h)(_deot_vc.Scroller, {
|
|
259
|
-
height: "100%",
|
|
260
|
-
native: false,
|
|
261
|
-
autoResize: true,
|
|
262
|
-
showBar: true,
|
|
263
|
-
contentClass: require_store.PREVIEW_SCROLL_CONTENT_CLASS
|
|
264
|
-
}, { default: () => content });
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
});
|
|
268
|
-
app.component("DocsLink", createDocsLink(preview));
|
|
269
|
-
app.config.errorHandler = (error) => {
|
|
270
|
-
const message = formatPlaygroundRuntimeError(error);
|
|
271
|
-
if (message) runtimeError.value = message;
|
|
272
|
-
};
|
|
273
|
-
app.mount(mountEl.value);
|
|
274
|
-
previewApp = app;
|
|
275
|
-
};
|
|
276
|
-
const ensurePort = () => {
|
|
277
|
-
const iframe = bridgeEl.value;
|
|
278
|
-
if (!iframe?.contentWindow) return null;
|
|
279
|
-
try {
|
|
280
|
-
if (!installLocalBridge(iframe)) return null;
|
|
281
|
-
} catch {
|
|
282
|
-
return null;
|
|
283
|
-
}
|
|
284
|
-
port ??= new LocalPreviewPort(iframe);
|
|
285
|
-
messageSource.value = iframe.contentWindow;
|
|
286
|
-
return port;
|
|
287
|
-
};
|
|
288
|
-
const tryMount = async () => {
|
|
289
|
-
const job = pendingMount;
|
|
290
|
-
/* istanbul ignore if -- 桥接 iframe 尚未就绪或编译已被取代 */
|
|
291
|
-
if (!job || job.version !== version) return;
|
|
292
|
-
const preview = ensurePort();
|
|
293
|
-
/* istanbul ignore if -- 挂载点在编译完成时已经存在 */
|
|
294
|
-
if (!preview || !mountEl.value) return;
|
|
295
|
-
await (0, vue.nextTick)();
|
|
296
|
-
/* istanbul ignore if -- 桥接 iframe 尚未就绪或编译已被取代 */
|
|
297
|
-
if (pendingMount !== job || !mountEl.value) return;
|
|
298
|
-
pendingMount = null;
|
|
299
|
-
mountPreview(job.component, preview, job.css);
|
|
300
|
-
};
|
|
301
|
-
const run = async () => {
|
|
302
|
-
const current = ++version;
|
|
303
|
-
pendingMount = null;
|
|
304
|
-
compileError.value = "";
|
|
305
|
-
runtimeError.value = "";
|
|
306
|
-
publishError();
|
|
307
|
-
destroyPreview();
|
|
308
|
-
try {
|
|
309
|
-
const [{ compilePlayground }, { linkPlayground }, modulesApi, fileApi] = await Promise.all([
|
|
310
|
-
Promise.resolve().then(() => require("./compile-DSMuM8zl.cjs")),
|
|
311
|
-
Promise.resolve().then(() => require("./linker-B--sjERT.cjs")),
|
|
312
|
-
Promise.resolve().then(() => require("./modules-CInmL-8h.cjs")),
|
|
313
|
-
Promise.resolve().then(() => require("./files-D5LNOtjp.cjs"))
|
|
314
|
-
]);
|
|
315
|
-
/* istanbul ignore if -- 并发编译时只保留最后一次 */
|
|
316
|
-
if (current !== version) return;
|
|
317
|
-
const compiled = await compilePlayground(props.files, { entry: props.entry });
|
|
318
|
-
/* istanbul ignore if -- 并发编译时只保留最后一次 */
|
|
319
|
-
if (current !== version) return;
|
|
320
|
-
if (compiled.errors.length || !compiled.entry) {
|
|
321
|
-
compileError.value = compiled.errors.join("\n") || "[Playground] 未能确定入口";
|
|
322
|
-
publishError();
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const imports = require_store.createRuntimeImports(props.options.cdnURL, props.options.builtinImportMap);
|
|
326
|
-
const specifiers = fileApi.collectBareSpecifiers(props.files, fileApi.collectReachableFilenames(props.files, compiled.entry));
|
|
327
|
-
const { createRemoteLoader } = await Promise.resolve().then(() => require("./remote-CKMzn1J3.cjs"));
|
|
328
|
-
const remote = createRemoteLoader(imports, {
|
|
329
|
-
vue,
|
|
330
|
-
vueRouter: vue_router
|
|
331
|
-
}, props.options.cdnURL);
|
|
332
|
-
const loaded = await modulesApi.loadLocalModules(specifiers, imports, {
|
|
333
|
-
vue,
|
|
334
|
-
vueRouter: vue_router
|
|
335
|
-
}, (url) => remote.load(url), props.options.cdnURL);
|
|
336
|
-
/* istanbul ignore if -- 并发编译时只保留最后一次 */
|
|
337
|
-
if (current !== version) return;
|
|
338
|
-
if (loaded.errors.length) {
|
|
339
|
-
compileError.value = loaded.errors.join("\n");
|
|
340
|
-
publishError();
|
|
341
|
-
return;
|
|
342
|
-
}
|
|
343
|
-
const linked = linkPlayground(compiled, props.files, { modules: loaded.modules });
|
|
344
|
-
/* istanbul ignore if -- 并发编译时只保留最后一次 */
|
|
345
|
-
if (current !== version) return;
|
|
346
|
-
if (linked.errors.length || !linked.component) {
|
|
347
|
-
compileError.value = (linked.errors.length ? linked.errors : ["[Playground] 未能解析入口组件"]).join("\n");
|
|
348
|
-
publishError();
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
pendingMount = {
|
|
352
|
-
component: linked.component,
|
|
353
|
-
css: linked.css,
|
|
354
|
-
version: current
|
|
355
|
-
};
|
|
356
|
-
await tryMount();
|
|
357
|
-
} catch (error) {
|
|
358
|
-
/* istanbul ignore next -- 编译器自身异常才进入,普通错误走结果里的 errors */
|
|
359
|
-
if (current !== version) return;
|
|
360
|
-
/* istanbul ignore next -- 同上,只兜底编译器抛错 */
|
|
361
|
-
compileError.value = error instanceof Error ? error.message : String(error);
|
|
362
|
-
/* istanbul ignore next -- 同上,只兜底编译器抛错 */
|
|
363
|
-
publishError();
|
|
364
|
-
}
|
|
365
|
-
};
|
|
366
|
-
const handleBridgeLoad = () => {
|
|
367
|
-
tryMount();
|
|
368
|
-
};
|
|
369
|
-
(0, vue.onMounted)(() => {
|
|
370
|
-
run();
|
|
371
|
-
});
|
|
372
|
-
(0, vue.watch)(() => [
|
|
373
|
-
props.files,
|
|
374
|
-
props.entry,
|
|
375
|
-
props.options,
|
|
376
|
-
props.previewScroller
|
|
377
|
-
], () => {
|
|
378
|
-
if (!containerEl.value) return;
|
|
379
|
-
run();
|
|
380
|
-
}, { deep: true });
|
|
381
|
-
(0, vue.onBeforeUnmount)(() => {
|
|
382
|
-
version += 1;
|
|
383
|
-
pendingMount = null;
|
|
384
|
-
destroyPreview();
|
|
385
|
-
});
|
|
386
|
-
__expose({
|
|
387
|
-
container: containerEl,
|
|
388
|
-
messageSource,
|
|
389
|
-
local: true,
|
|
390
|
-
refresh: () => {
|
|
391
|
-
run();
|
|
392
|
-
}
|
|
393
|
-
});
|
|
394
|
-
return (_ctx, _cache) => {
|
|
395
|
-
return (0, vue.openBlock)(), (0, vue.createElementBlock)("div", {
|
|
396
|
-
ref_key: "containerEl",
|
|
397
|
-
ref: containerEl,
|
|
398
|
-
class: "docs-playground-local"
|
|
399
|
-
}, [(0, vue.createElementVNode)("iframe", {
|
|
400
|
-
ref_key: "bridgeEl",
|
|
401
|
-
ref: bridgeEl,
|
|
402
|
-
class: "docs-playground-local__bridge",
|
|
403
|
-
tabindex: "-1",
|
|
404
|
-
"aria-hidden": "true",
|
|
405
|
-
title: "",
|
|
406
|
-
srcdoc: (0, vue.unref)(bridgeSrcdoc),
|
|
407
|
-
onLoad: handleBridgeLoad
|
|
408
|
-
}, null, 40, _hoisted_1), (0, vue.createElementVNode)("div", {
|
|
409
|
-
ref_key: "mountEl",
|
|
410
|
-
ref: mountEl,
|
|
411
|
-
class: "docs-playground-local__mount"
|
|
412
|
-
}, null, 512)], 512);
|
|
413
|
-
};
|
|
414
|
-
}
|
|
415
|
-
});
|
|
416
|
-
//#endregion
|
|
417
|
-
//#region packages/playground/src/core/runtime/local/local-sandbox.vue
|
|
418
|
-
var local_sandbox_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ default: () => local_sandbox_default });
|
|
419
|
-
var local_sandbox_default = local_sandbox_vue_vue_type_script_setup_true_lang_default;
|
|
420
|
-
//#endregion
|
|
421
|
-
exports.collectCss = collectCss;
|
|
422
|
-
exports.default = local_sandbox_default;
|
|
423
|
-
Object.defineProperty(exports, "local_sandbox_exports", {
|
|
424
|
-
enumerable: true,
|
|
425
|
-
get: function() {
|
|
426
|
-
return local_sandbox_exports;
|
|
427
|
-
}
|
|
428
|
-
});
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
const require_cdn = require("./cdn-Czve5_9b.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
|
-
if (prefersLocalBuiltin(specifier, imports, cdnURL)) localIds.add(specifier);
|
|
167
|
-
else {
|
|
168
|
-
let cursor = specifier;
|
|
169
|
-
while (true) {
|
|
170
|
-
const slash = cursor.lastIndexOf("/");
|
|
171
|
-
if (slash <= 0) break;
|
|
172
|
-
const parent = cursor.slice(0, slash);
|
|
173
|
-
if (prefersLocalBuiltin(parent, imports, cdnURL)) {
|
|
174
|
-
localIds.add(parent);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
177
|
-
cursor = parent;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
if (specifier === "vue-router") {
|
|
181
|
-
if (imports["vue-router"]) targets.add("vue-router");
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
const target = resolveImportTarget(specifier, imports);
|
|
185
|
-
if (target && prefersLocalBuiltin(target, imports, cdnURL)) localIds.add(target);
|
|
186
|
-
else if (target) targets.add(target);
|
|
187
|
-
});
|
|
188
|
-
await Promise.all([...localIds].map(async (id) => {
|
|
189
|
-
if (id === "vue" || id === "vue-router") return;
|
|
190
|
-
if (id === "vue/server-renderer") {
|
|
191
|
-
modules[id] = builtins.vue;
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
modules[id] = await ensureLocalBuiltin(id);
|
|
195
|
-
}));
|
|
196
|
-
for (const id of targets) {
|
|
197
|
-
const url = imports[id];
|
|
198
|
-
if (!url || prefersLocalBuiltin(id, imports, cdnURL)) continue;
|
|
199
|
-
try {
|
|
200
|
-
modules[id] = await loader(url);
|
|
201
|
-
} catch (error) {
|
|
202
|
-
errors.push(`[Playground] 无法加载模块 "${id}" (${url}): ${messageOf(error)}`);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
return {
|
|
206
|
-
modules,
|
|
207
|
-
errors
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
//#endregion
|
|
211
|
-
exports.ensureLocalBuiltin = ensureLocalBuiltin;
|
|
212
|
-
exports.loadLocalModules = loadLocalModules;
|
|
213
|
-
exports.localBuiltinIds = localBuiltinIds;
|
|
214
|
-
exports.prefersLocalBuiltin = prefersLocalBuiltin;
|
|
215
|
-
exports.resolveHostModule = resolveHostModule;
|
|
216
|
-
exports.resolveImportTarget = resolveImportTarget;
|
|
217
|
-
exports.toHostModule = toHostModule;
|