@deot/docs-playground 1.1.4 → 1.1.6

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 CHANGED
@@ -53,7 +53,7 @@ const files = ref({
53
53
  | `id` | `string` | `''` | 标题锚点 id;未传时从 `title` 自动生成。仅挂在内联 runtime 标题上,弹窗不重复。 |
54
54
  | `expandable` | `true \| number` | `undefined` | 开启预览高度展开;未传不显示控件;`true` 展开到剩余视口;正数为目标高度(px)。 |
55
55
  | `previewScroller` | `boolean` | `false` | 在 iframe 内用 `@deot/vc` Scroller 替换原生滚动条;开启后会动态探测 `Scroller`,不存在则回退原生滚动。 |
56
- | `local` | `boolean` | `false` | 在当前文档编译并挂载,不使用 iframe。`vue` 使用宿主同一份实例;其余 import map 仍是 URL,加载后作为模块变量。 |
56
+ | `local` | `boolean` | `true` | 在当前文档编译并挂载。内置模块默认继承宿主,可通过 import map 逐个覆盖;预览使用所选 Vue 运行时挂载。 |
57
57
  | `options` | `PlaygroundOptions` | `{}` | 传给 Vue REPL store 的实例级选项;`cdnURL` 会同时作用于预览样式和默认 import map。 |
58
58
  | `previewOptions` | `SandboxProps['previewOptions']` | `undefined` | 传给当前 iframe 的 preview 选项。 |
59
59
  | `locale` | `Language` | `en-US` | 界面语言;未传入时使用上层 Locale Provider。 |
@@ -149,18 +149,18 @@ const handleMessage = async () => {
149
149
 
150
150
  同时导出 `PlaygroundFiles`、`PlaygroundView`、`PlaygroundViewport`、`PlaygroundOptions`、`PlaygroundPreviewOptions`、`EditorFilesChange` 和 `EditorFilesChangeAction` 类型。
151
151
 
152
- 站点级 Playground 模块与预览 CSS 默认由 Client 的 `$docs.modules` 与 `$docs.styles` 管理(见 [`@deot/docs-client`](../client/README.md))。独立嵌入 Playground 时,可通过 `options.builtinImportMap` 与 `options.cdnURL` 覆盖实例级配置。
152
+ 站点级 Playground 模块与预览 CSS 默认由 Client 的 `$docs.modules` 与 `$docs.styles` 管理(见 [`@deot/docs-client`](../client/README.md))。模块地址优先级由低到高为:内置默认 → `$docs.modules` → 管理页覆盖 → 实例 `options.builtinImportMap.imports`。实例只覆盖声明的模块,其余继承默认配置;也可通过 `options.cdnURL` 调整默认 CDN。
153
153
 
154
154
  ## 运行环境
155
155
 
156
- - Playground 运行时通过公共 CDN 加载 Vue 和默认 import map 中的依赖,手工预览需要网络访问。
156
+ - iframe 运行时通过公共 CDN 加载 Vue 和默认 import map 中的依赖;local 运行时加载 URL 覆盖或宿主未提供的模块时也需要网络访问。
157
157
  - 默认 CDN 为 `https://cdn.jsdelivr.net/npm`,可通过 `options.cdnURL` 换成 unpkg 等兼容 `/{package}/{file}` 路径的镜像;该地址用于预览样式和内置 import map。
158
158
  - `lodash-es` 和在线 Sass 编译器使用 jsDelivr 的 `/+esm` 入口;unpkg 等 CDN 不支持该路径。
159
- - 直接渲染时,未配置的 npm 模块(含作用域包和子路径)自动从 jsDelivr 的 `/+esm` 入口加载;组件包的传递依赖也适用,`import()` 在调用时加载。`@deot/vc` 的组件、hooks 和 locale 走远程模块加载器,Vue 保持与宿主共用。可用 `options.builtinImportMap.imports` 指定依赖的版本和 URL。
159
+ - 直接渲染时,宿主未提供且未配置的 npm 模块(含作用域包和子路径)自动从 jsDelivr 的 `/+esm` 入口加载;组件包的传递依赖也适用,`import()` 在调用时加载。可用 `options.builtinImportMap.imports` 指定依赖的版本和 URL。
160
160
  - Vue SFC 的 `<style lang="scss">` / `lang="sass"` 以及独立 `.scss` / `.sass` 文件会在浏览器里编译;`_partial.scss` 只作为 `@use` 依赖。
161
- - `options.builtinImportMap.imports` 可以覆盖默认模块 URL。Vue 运行时仍从 `play.vuejs.org` 加载。
161
+ - local 模式按模块识别显式 URL 覆盖,即使地址与内置默认相同也会加载该 URL。覆盖 `vue` 时,预览的编译产物、挂载、组件引用和注入使用这份 Vue;内置组件、hooks、locale、Pinia 和 vue-router 随之重新加载以匹配 Vue,未覆盖的普通工具模块继续复用宿主。不同预览的覆盖互不影响,显式覆盖的模块在各自预览内执行。
162
162
  - 每个 Playground 实例都使用自己的 preview 配置和 iframe 消息来源校验。
163
- - `local` 默认开启:同一份 `files` 在当前文档里编译。内置依赖默认用宿主副本;`modules` 里与默认 CDN 不同的地址会覆盖,包括 `vue` 和 `vue/server-renderer`。直接渲染不撑开预览高度,`expandable` 固定为关闭,`docs:playground.run` 不会申请临时高度;`<DocsLink>` 仍通过 `docs:navigate` 通知。`local: false` 改回 iframe Sandbox。
163
+ - `local` 默认开启:同一份 `files` 在当前文档里编译。直接渲染不撑开预览高度,`expandable` 固定为关闭,`docs:playground.run` 不会申请临时高度;`<DocsLink>` 仍通过 `docs:navigate` 通知。`local: false` 改回 iframe Sandbox。
164
164
 
165
165
  ## 仓库内 examples
166
166
 
@@ -1,7 +1,4 @@
1
- const require_scss = require("./scss-B8OFbz1k.cjs");
2
- const require_files = require("./files-BsAOZiPN.cjs");
3
- const require_script = require("./script-BiCcpu3G.cjs");
4
- const require_local_sandbox = require("./local-sandbox-0ojvBQPO.cjs");
1
+ const require_css = require("./css-DpqJBQ5c.cjs");
5
2
  let sass = require("sass");
6
3
  //#region packages/playground/src/core/runtime/local/compile/scss.ts
7
4
  /**
@@ -21,7 +18,7 @@ var toScssFiles = (files) => {
21
18
  };
22
19
  var compileLocalScss = (source, filename, files, lang) => {
23
20
  try {
24
- return require_scss.compileScssSource(source, filename.replace(/^\/+/u, ""), compiler, toScssFiles(files), lang);
21
+ return require_css.compileScssSource(source, filename.replace(/^\/+/u, ""), compiler, toScssFiles(files), lang);
25
22
  } catch (error) {
26
23
  /* istanbul ignore next -- Sass 失败时 message 总是字符串 */
27
24
  const message = error instanceof Error ? error.message : String(error);
@@ -188,7 +185,7 @@ var transformJson = (parsed, filename) => {
188
185
  return lines.join("\n");
189
186
  };
190
187
  var compileOne = async (filename, code, files) => {
191
- const ext = require_files.getExtension(filename);
188
+ const ext = require_css.getExtension(filename);
192
189
  const errors = [];
193
190
  if (ext === ".vue") {
194
191
  if (/lang\s*=\s*["']jsx["']/iu.test(code) || /lang\s*=\s*["']tsx["']/iu.test(code)) {
@@ -204,7 +201,7 @@ var compileOne = async (filename, code, files) => {
204
201
  errors.push(...result.errors);
205
202
  return {
206
203
  filename,
207
- js: require_script.transformScript(result.js, filename, { typescript: true }),
204
+ js: require_css.transformScript(result.js, filename, { typescript: true }),
208
205
  css: result.css,
209
206
  errors
210
207
  };
@@ -216,7 +213,7 @@ var compileOne = async (filename, code, files) => {
216
213
  errors
217
214
  };
218
215
  if (ext === ".scss" || ext === ".sass") try {
219
- const { css, exports: styleExports } = require_scss.extractScssExports(compileLocalScss(code, filename, files), filename);
216
+ const { css, exports: styleExports } = require_css.extractScssExports(compileLocalScss(code, filename, files), filename);
220
217
  return {
221
218
  filename,
222
219
  js: `exports.__esModule = true; exports.default = ${JSON.stringify(styleExports)};\n//# sourceURL=playground://${filename}`,
@@ -251,7 +248,7 @@ var compileOne = async (filename, code, files) => {
251
248
  if (ext === ".js" || ext === ".ts" || ext === ".jsx" || ext === ".tsx") try {
252
249
  return {
253
250
  filename,
254
- js: require_script.transformScript(code, filename, {
251
+ js: require_css.transformScript(code, filename, {
255
252
  typescript: ext === ".ts" || ext === ".tsx",
256
253
  jsx: ext === ".jsx" || ext === ".tsx"
257
254
  }),
@@ -286,7 +283,7 @@ var compilePlayground = async (files, entryOrOptions) => {
286
283
  const errors = [];
287
284
  let entry;
288
285
  try {
289
- entry = require_files.resolveEntry(files, options.entry);
286
+ entry = require_css.resolveEntry(files, options.entry);
290
287
  } catch (error) {
291
288
  return {
292
289
  entry: "",
@@ -295,8 +292,8 @@ var compilePlayground = async (files, entryOrOptions) => {
295
292
  errors: [messageOf(error)]
296
293
  };
297
294
  }
298
- const fileIndex = require_files.createFileIndex(files);
299
- const reachable = require_files.collectReachableFilenames(files, entry);
295
+ const fileIndex = require_css.createFileIndex(files);
296
+ const reachable = require_css.collectReachableFilenames(files, entry);
300
297
  const modules = {};
301
298
  const cssChunks = [];
302
299
  for (const filename of reachable) {
@@ -309,9 +306,9 @@ var compilePlayground = async (files, entryOrOptions) => {
309
306
  js: compiled.js,
310
307
  css: compiled.css
311
308
  };
312
- cssChunks.push(...require_local_sandbox.collectCss([compiled.css]));
309
+ cssChunks.push(...require_css.collectCss([compiled.css]));
313
310
  }
314
- const normalizedEntry = require_files.normalizeVirtualPath(entry);
311
+ const normalizedEntry = require_css.normalizeVirtualPath(entry);
315
312
  /* istanbul ignore if -- 可达编译总会留下入口模块 */
316
313
  if (!modules[normalizedEntry]) errors.push(`[Playground] 入口编译结果缺失: ${normalizedEntry}`);
317
314
  return {
@@ -1,7 +1,4 @@
1
- import { d as resolveEntry, n as collectReachableFilenames, o as getExtension, r as createFileIndex, u as normalizeVirtualPath } from "./files-BqucFldk.js";
2
- import { n as compileScssSource, r as extractScssExports } from "./scss-DIh6971q.js";
3
- import { n as transformScript } from "./script-DjUf9uWK.js";
4
- import { n as collectCss } from "./local-sandbox-DvcgaBOa.js";
1
+ import { a as transformScript, c as createFileIndex, h as resolveEntry, m as normalizeVirtualPath, s as collectReachableFilenames, t as collectCss, u as getExtension, v as compileScssSource, y as extractScssExports } from "./css-DleINdoA.js";
5
2
  import { compileString } from "sass";
6
3
  //#region packages/playground/src/core/runtime/local/compile/scss.ts
7
4
  /**