@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,267 +0,0 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- //#region packages/playground/src/core/runtime/local/compile/types.ts
3
- var IGNORED_FILENAMES = /* @__PURE__ */ new Set(["import-map.json", "tsconfig.json"]);
4
- //#endregion
5
- //#region packages/playground/src/core/runtime/local/compile/files.ts
6
- var files_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
7
- basename: () => basename,
8
- collectBareSpecifiers: () => collectBareSpecifiers,
9
- collectReachableFilenames: () => collectReachableFilenames,
10
- createFileIndex: () => createFileIndex,
11
- dirname: () => dirname,
12
- getCommonRoot: () => getCommonRoot,
13
- getExtension: () => getExtension,
14
- isIgnoredFilename: () => isIgnoredFilename,
15
- isInsideRoot: () => isInsideRoot,
16
- isRelativeSpecifier: () => isRelativeSpecifier,
17
- joinVirtualPath: () => joinVirtualPath,
18
- listImportSpecifiers: () => listImportSpecifiers,
19
- normalizeVirtualPath: () => normalizeVirtualPath,
20
- resolveEntry: () => resolveEntry,
21
- resolveModulePath: () => resolveModulePath
22
- });
23
- /**
24
- * 统一成以 `/` 开头的 POSIX 绝对虚拟路径。
25
- * `App.vue` 与 `/App.vue` 是同一文件,和 iframe 预览使用的 files 键一致。
26
- * @param filename Playground files 的键或相对路径。
27
- * @returns 以 `/` 开头的虚拟路径。
28
- */
29
- var normalizeVirtualPath = (filename) => {
30
- const raw = String(filename || "").replace(/\\/gu, "/").trim();
31
- if (!raw) return "/";
32
- const parts = (raw.startsWith("/") ? raw : `/${raw}`).split("/");
33
- const stack = [];
34
- for (const part of parts) {
35
- if (!part || part === ".") continue;
36
- if (part === "..") {
37
- if (stack.length) stack.pop();
38
- continue;
39
- }
40
- stack.push(part);
41
- }
42
- return `/${stack.join("/")}`;
43
- };
44
- var dirname = (filename) => {
45
- const path = normalizeVirtualPath(filename);
46
- const index = path.lastIndexOf("/");
47
- if (index <= 0) return "/";
48
- return path.slice(0, index) || "/";
49
- };
50
- var basename = (filename) => {
51
- const path = normalizeVirtualPath(filename);
52
- const index = path.lastIndexOf("/");
53
- return index === -1 ? path : path.slice(index + 1);
54
- };
55
- var joinVirtualPath = (baseDir, relative) => {
56
- const rel = String(relative || "").replace(/\\/gu, "/");
57
- if (rel.startsWith("/")) return normalizeVirtualPath(rel);
58
- const base = normalizeVirtualPath(baseDir);
59
- return normalizeVirtualPath(`${base === "/" ? "" : base}/${rel}`);
60
- };
61
- var getExtension = (filename) => {
62
- const name = basename(filename);
63
- const index = name.lastIndexOf(".");
64
- if (index <= 0) return "";
65
- return name.slice(index).toLowerCase();
66
- };
67
- var isIgnoredFilename = (filename) => IGNORED_FILENAMES.has(basename(filename));
68
- var createFileIndex = (files) => {
69
- const index = /* @__PURE__ */ new Map();
70
- Object.entries(files || {}).forEach(([filename, code]) => {
71
- const normalized = normalizeVirtualPath(filename);
72
- if (isIgnoredFilename(normalized)) return;
73
- index.set(normalized, code);
74
- });
75
- return index;
76
- };
77
- var resolveEntry = (files, entry) => {
78
- const index = createFileIndex(files);
79
- if (!index.size) throw new Error("[Playground] files 为空,无法确定入口");
80
- if (entry) {
81
- const normalized = normalizeVirtualPath(entry);
82
- if (isIgnoredFilename(normalized)) throw new Error(`[Playground] entry 不能是 ${basename(normalized)}`);
83
- if (!index.has(normalized)) throw new Error(`[Playground] entry 不在 files 中: ${entry}`);
84
- return normalized;
85
- }
86
- for (const key of Object.keys(files || {})) {
87
- const normalized = normalizeVirtualPath(key);
88
- if (!isIgnoredFilename(normalized) && index.has(normalized)) return normalized;
89
- }
90
- /* istanbul ignore next -- 忽略文件已在前面排除,正常 files 不会走到这里 */
91
- throw new Error("[Playground] files 中没有可用的入口文件");
92
- };
93
- var CANDIDATE_EXTENSIONS = [
94
- ".vue",
95
- ".ts",
96
- ".js",
97
- ".tsx",
98
- ".jsx",
99
- ".json",
100
- ".css",
101
- ".scss",
102
- ".sass"
103
- ];
104
- /**
105
- * 相对 / 无扩展名解析,行为对齐 Vite:精确路径、补扩展名、`/index.*`。
106
- * @param fromFilename 发起导入的文件。
107
- * @param specifier 相对或绝对虚拟路径。
108
- * @param fileIndex 虚拟路径到 files 键的索引。
109
- * @returns 解析后的 files 键;找不到时返回 null。
110
- */
111
- var resolveModulePath = (fromFilename, specifier, fileIndex) => {
112
- if (!specifier || !(specifier === "." || specifier === ".." || specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/"))) return null;
113
- const target = joinVirtualPath(dirname(fromFilename), specifier);
114
- if (fileIndex.has(target)) return target;
115
- for (const ext of CANDIDATE_EXTENSIONS) {
116
- const withExt = `${target}${ext}`;
117
- if (fileIndex.has(withExt)) return withExt;
118
- }
119
- for (const ext of CANDIDATE_EXTENSIONS) {
120
- const asIndex = `${target}/index${ext}`;
121
- if (fileIndex.has(asIndex)) return asIndex;
122
- }
123
- return null;
124
- };
125
- var getCommonRoot = (filenames) => {
126
- const normalized = filenames.map(normalizeVirtualPath);
127
- if (!normalized.length) return "/";
128
- const split = normalized.map((path) => path.split("/").filter(Boolean));
129
- const first = split[0];
130
- let depth = first.length;
131
- for (let i = 1; i < split.length; i += 1) {
132
- let common = 0;
133
- while (common < depth && common < split[i].length && first[common] === split[i][common]) common += 1;
134
- depth = common;
135
- }
136
- if (!depth) return "/";
137
- const maybeFile = `/${first.slice(0, depth).join("/")}`;
138
- if (normalized.some((path) => path === maybeFile)) return dirname(maybeFile);
139
- return maybeFile;
140
- };
141
- var isInsideRoot = (filename, root) => {
142
- const path = normalizeVirtualPath(filename);
143
- const base = normalizeVirtualPath(root);
144
- if (base === "/") return true;
145
- return path === base || path.startsWith(`${base}/`);
146
- };
147
- /**
148
- * 静态 import / export-from / import() 的模块说明符。
149
- * @param code 源码文本。
150
- * @returns 按出现顺序收集到的说明符。
151
- */
152
- var listImportSpecifiers = (code) => {
153
- const result = [];
154
- const source = String(code || "");
155
- for (const match of source.matchAll(/(?:\bfrom\s+|import\s*\(\s*|import\s+)['"]([^'"]+)['"]/gu)) if (match[1]) result.push(match[1]);
156
- return result;
157
- };
158
- var isRelativeSpecifier = (id) => id === "." || id === ".." || id.startsWith("./") || id.startsWith("../") || id.startsWith("/");
159
- /**
160
- * 从入口出发只编译静态 import 能走到的文件。
161
- * @param files 当前 Playground 文件表。
162
- * @param entry 入口文件名。
163
- * @returns 可达文件名,入口在最前。
164
- */
165
- var collectReachableFilenames = (files, entry) => {
166
- const index = createFileIndex(files);
167
- const ordered = [];
168
- const seen = /* @__PURE__ */ new Set();
169
- const visit = (filename) => {
170
- const key = normalizeVirtualPath(filename);
171
- if (seen.has(key) || !index.has(key)) return;
172
- seen.add(key);
173
- ordered.push(key);
174
- listImportSpecifiers(index.get(key) || "").forEach((specifier) => {
175
- const resolved = resolveModulePath(key, specifier, index);
176
- if (resolved) visit(resolved);
177
- });
178
- };
179
- visit(entry);
180
- return ordered;
181
- };
182
- var collectBareSpecifiers = (files, filenames) => {
183
- const index = createFileIndex(files);
184
- const result = [];
185
- const seen = /* @__PURE__ */ new Set();
186
- filenames.forEach((filename) => {
187
- listImportSpecifiers(index.get(normalizeVirtualPath(filename)) || "").forEach((specifier) => {
188
- if (!specifier || isRelativeSpecifier(specifier) || seen.has(specifier) || /\.(?:css|scss|sass)(?:[?#]|$)/.test(specifier)) return;
189
- seen.add(specifier);
190
- result.push(specifier);
191
- });
192
- });
193
- return result;
194
- };
195
- //#endregion
196
- Object.defineProperty(exports, "collectBareSpecifiers", {
197
- enumerable: true,
198
- get: function() {
199
- return collectBareSpecifiers;
200
- }
201
- });
202
- Object.defineProperty(exports, "collectReachableFilenames", {
203
- enumerable: true,
204
- get: function() {
205
- return collectReachableFilenames;
206
- }
207
- });
208
- Object.defineProperty(exports, "createFileIndex", {
209
- enumerable: true,
210
- get: function() {
211
- return createFileIndex;
212
- }
213
- });
214
- Object.defineProperty(exports, "files_exports", {
215
- enumerable: true,
216
- get: function() {
217
- return files_exports;
218
- }
219
- });
220
- Object.defineProperty(exports, "getCommonRoot", {
221
- enumerable: true,
222
- get: function() {
223
- return getCommonRoot;
224
- }
225
- });
226
- Object.defineProperty(exports, "getExtension", {
227
- enumerable: true,
228
- get: function() {
229
- return getExtension;
230
- }
231
- });
232
- Object.defineProperty(exports, "isIgnoredFilename", {
233
- enumerable: true,
234
- get: function() {
235
- return isIgnoredFilename;
236
- }
237
- });
238
- Object.defineProperty(exports, "isInsideRoot", {
239
- enumerable: true,
240
- get: function() {
241
- return isInsideRoot;
242
- }
243
- });
244
- Object.defineProperty(exports, "isRelativeSpecifier", {
245
- enumerable: true,
246
- get: function() {
247
- return isRelativeSpecifier;
248
- }
249
- });
250
- Object.defineProperty(exports, "normalizeVirtualPath", {
251
- enumerable: true,
252
- get: function() {
253
- return normalizeVirtualPath;
254
- }
255
- });
256
- Object.defineProperty(exports, "resolveEntry", {
257
- enumerable: true,
258
- get: function() {
259
- return resolveEntry;
260
- }
261
- });
262
- Object.defineProperty(exports, "resolveModulePath", {
263
- enumerable: true,
264
- get: function() {
265
- return resolveModulePath;
266
- }
267
- });
@@ -1,167 +0,0 @@
1
- const require_rolldown_runtime = require("./rolldown-runtime-C0BPl7ul.cjs");
2
- const require_files = require("./files-BsAOZiPN.cjs");
3
- const require_modules = require("./modules-E6kK6ZJH.cjs");
4
- let vue = require("vue");
5
- vue = require_rolldown_runtime.__toESM(vue);
6
- //#region packages/playground/src/core/runtime/local/vue-guard.ts
7
- /**
8
- * 给 files 注入的 vue:同一份宿主 Vue,但 `createApp().mount` 不会卸掉页面。
9
- * 防护按本次 link 创建,多个 Playground 互不覆盖。
10
- * @param capture 本次链接收集到的根组件、局部组件和 provide。
11
- * @returns 带防护的 Vue 模块。
12
- */
13
- var createGuardedVue = (capture) => {
14
- const createApp = (rootComponent, rootProps) => {
15
- const fakeApp = {
16
- _component: rootComponent,
17
- _props: rootProps,
18
- config: {
19
- errorHandler: null,
20
- warnHandler: null,
21
- globalProperties: {}
22
- },
23
- _context: {
24
- provides: Object.create(null),
25
- components: Object.create(null),
26
- directives: Object.create(null),
27
- mixins: []
28
- },
29
- use() {
30
- return fakeApp;
31
- },
32
- mixin(mixin) {
33
- fakeApp._context.mixins.push(mixin);
34
- return fakeApp;
35
- },
36
- component(name, component) {
37
- if (component) {
38
- fakeApp._context.components[name] = component;
39
- return fakeApp;
40
- }
41
- return fakeApp._context.components[name];
42
- },
43
- directive() {
44
- return fakeApp;
45
- },
46
- provide(key, value) {
47
- fakeApp._context.provides[key] = value;
48
- return fakeApp;
49
- },
50
- mount() {
51
- capture.components = { ...fakeApp._context.components };
52
- capture.provides = { ...fakeApp._context.provides };
53
- capture.mountedComponent = (0, vue.defineComponent)({
54
- name: "PlaygroundCapturedApp",
55
- components: fakeApp._context.components,
56
- setup() {
57
- Reflect.ownKeys(fakeApp._context.provides).forEach((key) => {
58
- (0, vue.provide)(key, fakeApp._context.provides[key]);
59
- });
60
- return () => (0, vue.h)(rootComponent, rootProps || null);
61
- }
62
- });
63
- return capture.mountedComponent;
64
- },
65
- unmount() {},
66
- onUnmount() {
67
- return fakeApp;
68
- }
69
- };
70
- return fakeApp;
71
- };
72
- return new Proxy(vue, { get(target, prop, receiver) {
73
- if (prop === "createApp" || prop === "createSSRApp") return createApp;
74
- if (prop === "default") return receiver;
75
- return Reflect.get(target, prop, receiver);
76
- } });
77
- };
78
- //#endregion
79
- //#region packages/playground/src/core/runtime/local/linker.ts
80
- /**
81
- * 在当前页面链接编译结果,返回入口组件。
82
- * 未覆盖 `vue` 时换成带防护的宿主实例,避免 `mount` 卸掉页面。
83
- * @param compiled 浏览器编译结果。
84
- * @param files 当前 Playground 文件表。
85
- * @param options 可选的宿主模块表。
86
- * @returns 入口组件、样式和链接错误。
87
- */
88
- var linkPlayground = (compiled, files, options = {}) => {
89
- const errors = [...compiled.errors || []];
90
- if (!compiled.entry || errors.length) return {
91
- component: null,
92
- css: compiled.css || [],
93
- errors
94
- };
95
- const capture = {
96
- mountedComponent: null,
97
- components: {},
98
- provides: {}
99
- };
100
- const modules = { ...options.modules || {} };
101
- if (modules.vue == null || modules.vue === vue) modules.vue = createGuardedVue(capture);
102
- const fileIndex = require_files.createFileIndex(files);
103
- const root = require_files.getCommonRoot([...fileIndex.keys()]);
104
- const cache = /* @__PURE__ */ new Map();
105
- const visiting = /* @__PURE__ */ new Set();
106
- const requireFn = (fromFilename) => (id) => {
107
- if (require_files.isRelativeSpecifier(id)) {
108
- const resolved = require_files.resolveModulePath(fromFilename, id, fileIndex);
109
- if (!resolved) throw new Error(`[Playground] 无法解析相对模块 "${id}"(来自 ${fromFilename})`);
110
- /* istanbul ignore if -- 公共根已包含全部 files,正常解析不会逃出 */
111
- if (!require_files.isInsideRoot(resolved, root)) throw new Error(`[Playground] 模块逃出虚拟根: ${resolved}`);
112
- return loadModule(resolved);
113
- }
114
- const host = require_modules.resolveHostModule(id, modules);
115
- if (host) return host;
116
- throw new Error(`[Playground] 未注册的模块 "${id}"。请在 import map 中提供可加载的地址。`);
117
- };
118
- const loadModule = (filename) => {
119
- const key = require_files.normalizeVirtualPath(filename);
120
- if (cache.has(key)) return cache.get(key);
121
- if (visiting.has(key)) return cache.get(key);
122
- const mod = compiled.modules[key];
123
- if (!mod) throw new Error(`[Playground] 缺少编译模块: ${key}`);
124
- const module = { exports: {} };
125
- cache.set(key, module.exports);
126
- visiting.add(key);
127
- try {
128
- new Function("require", "module", "exports", mod.js)(requireFn(key), module, module.exports);
129
- cache.set(key, module.exports);
130
- return module.exports;
131
- } catch (error) {
132
- const message = error instanceof Error ? error.message : String(error);
133
- errors.push(`[Playground] 执行失败 ${key}: ${message}`);
134
- throw error;
135
- } finally {
136
- visiting.delete(key);
137
- }
138
- };
139
- try {
140
- const entryExports = loadModule(compiled.entry);
141
- let component = entryExports?.default ?? entryExports;
142
- if (capture.mountedComponent) component = capture.mountedComponent;
143
- /* istanbul ignore if -- 空入口在编译阶段已经报错 */
144
- if (!component) {
145
- errors.push("[Playground] 入口必须 export default 组件,或调用 createApp(App).mount()");
146
- return {
147
- component: null,
148
- css: compiled.css || [],
149
- errors
150
- };
151
- }
152
- return {
153
- component,
154
- css: compiled.css || [],
155
- errors
156
- };
157
- } catch (error) {
158
- if (!errors.length) errors.push(error instanceof Error ? error.message : String(error));
159
- return {
160
- component: null,
161
- css: compiled.css || [],
162
- errors
163
- };
164
- }
165
- };
166
- //#endregion
167
- exports.linkPlayground = linkPlayground;
@@ -1,166 +0,0 @@
1
- import { a as getCommonRoot, c as isInsideRoot, f as resolveModulePath, l as isRelativeSpecifier, r as createFileIndex, u as normalizeVirtualPath } from "./files-BqucFldk.js";
2
- import { resolveHostModule } from "./modules-BGzPcoRR.js";
3
- import * as Vue from "vue";
4
- import { defineComponent, h, provide } from "vue";
5
- //#region packages/playground/src/core/runtime/local/vue-guard.ts
6
- /**
7
- * 给 files 注入的 vue:同一份宿主 Vue,但 `createApp().mount` 不会卸掉页面。
8
- * 防护按本次 link 创建,多个 Playground 互不覆盖。
9
- * @param capture 本次链接收集到的根组件、局部组件和 provide。
10
- * @returns 带防护的 Vue 模块。
11
- */
12
- var createGuardedVue = (capture) => {
13
- const createApp = (rootComponent, rootProps) => {
14
- const fakeApp = {
15
- _component: rootComponent,
16
- _props: rootProps,
17
- config: {
18
- errorHandler: null,
19
- warnHandler: null,
20
- globalProperties: {}
21
- },
22
- _context: {
23
- provides: Object.create(null),
24
- components: Object.create(null),
25
- directives: Object.create(null),
26
- mixins: []
27
- },
28
- use() {
29
- return fakeApp;
30
- },
31
- mixin(mixin) {
32
- fakeApp._context.mixins.push(mixin);
33
- return fakeApp;
34
- },
35
- component(name, component) {
36
- if (component) {
37
- fakeApp._context.components[name] = component;
38
- return fakeApp;
39
- }
40
- return fakeApp._context.components[name];
41
- },
42
- directive() {
43
- return fakeApp;
44
- },
45
- provide(key, value) {
46
- fakeApp._context.provides[key] = value;
47
- return fakeApp;
48
- },
49
- mount() {
50
- capture.components = { ...fakeApp._context.components };
51
- capture.provides = { ...fakeApp._context.provides };
52
- capture.mountedComponent = defineComponent({
53
- name: "PlaygroundCapturedApp",
54
- components: fakeApp._context.components,
55
- setup() {
56
- Reflect.ownKeys(fakeApp._context.provides).forEach((key) => {
57
- provide(key, fakeApp._context.provides[key]);
58
- });
59
- return () => h(rootComponent, rootProps || null);
60
- }
61
- });
62
- return capture.mountedComponent;
63
- },
64
- unmount() {},
65
- onUnmount() {
66
- return fakeApp;
67
- }
68
- };
69
- return fakeApp;
70
- };
71
- return new Proxy(Vue, { get(target, prop, receiver) {
72
- if (prop === "createApp" || prop === "createSSRApp") return createApp;
73
- if (prop === "default") return receiver;
74
- return Reflect.get(target, prop, receiver);
75
- } });
76
- };
77
- //#endregion
78
- //#region packages/playground/src/core/runtime/local/linker.ts
79
- /**
80
- * 在当前页面链接编译结果,返回入口组件。
81
- * 未覆盖 `vue` 时换成带防护的宿主实例,避免 `mount` 卸掉页面。
82
- * @param compiled 浏览器编译结果。
83
- * @param files 当前 Playground 文件表。
84
- * @param options 可选的宿主模块表。
85
- * @returns 入口组件、样式和链接错误。
86
- */
87
- var linkPlayground = (compiled, files, options = {}) => {
88
- const errors = [...compiled.errors || []];
89
- if (!compiled.entry || errors.length) return {
90
- component: null,
91
- css: compiled.css || [],
92
- errors
93
- };
94
- const capture = {
95
- mountedComponent: null,
96
- components: {},
97
- provides: {}
98
- };
99
- const modules = { ...options.modules || {} };
100
- if (modules.vue == null || modules.vue === Vue) modules.vue = createGuardedVue(capture);
101
- const fileIndex = createFileIndex(files);
102
- const root = getCommonRoot([...fileIndex.keys()]);
103
- const cache = /* @__PURE__ */ new Map();
104
- const visiting = /* @__PURE__ */ new Set();
105
- const requireFn = (fromFilename) => (id) => {
106
- if (isRelativeSpecifier(id)) {
107
- const resolved = resolveModulePath(fromFilename, id, fileIndex);
108
- if (!resolved) throw new Error(`[Playground] 无法解析相对模块 "${id}"(来自 ${fromFilename})`);
109
- /* istanbul ignore if -- 公共根已包含全部 files,正常解析不会逃出 */
110
- if (!isInsideRoot(resolved, root)) throw new Error(`[Playground] 模块逃出虚拟根: ${resolved}`);
111
- return loadModule(resolved);
112
- }
113
- const host = resolveHostModule(id, modules);
114
- if (host) return host;
115
- throw new Error(`[Playground] 未注册的模块 "${id}"。请在 import map 中提供可加载的地址。`);
116
- };
117
- const loadModule = (filename) => {
118
- const key = normalizeVirtualPath(filename);
119
- if (cache.has(key)) return cache.get(key);
120
- if (visiting.has(key)) return cache.get(key);
121
- const mod = compiled.modules[key];
122
- if (!mod) throw new Error(`[Playground] 缺少编译模块: ${key}`);
123
- const module = { exports: {} };
124
- cache.set(key, module.exports);
125
- visiting.add(key);
126
- try {
127
- new Function("require", "module", "exports", mod.js)(requireFn(key), module, module.exports);
128
- cache.set(key, module.exports);
129
- return module.exports;
130
- } catch (error) {
131
- const message = error instanceof Error ? error.message : String(error);
132
- errors.push(`[Playground] 执行失败 ${key}: ${message}`);
133
- throw error;
134
- } finally {
135
- visiting.delete(key);
136
- }
137
- };
138
- try {
139
- const entryExports = loadModule(compiled.entry);
140
- let component = entryExports?.default ?? entryExports;
141
- if (capture.mountedComponent) component = capture.mountedComponent;
142
- /* istanbul ignore if -- 空入口在编译阶段已经报错 */
143
- if (!component) {
144
- errors.push("[Playground] 入口必须 export default 组件,或调用 createApp(App).mount()");
145
- return {
146
- component: null,
147
- css: compiled.css || [],
148
- errors
149
- };
150
- }
151
- return {
152
- component,
153
- css: compiled.css || [],
154
- errors
155
- };
156
- } catch (error) {
157
- if (!errors.length) errors.push(error instanceof Error ? error.message : String(error));
158
- return {
159
- component: null,
160
- css: compiled.css || [],
161
- errors
162
- };
163
- }
164
- };
165
- //#endregion
166
- export { linkPlayground };