@vite-hub/docs 0.4.1 → 0.5.1

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.
Files changed (75) hide show
  1. package/README.md +167 -7
  2. package/dist/{agent-copy-xPaWye_g.js → agent-copy-CY9_RkHN.js} +2 -3
  3. package/dist/{assistant-pages-BN7hNsSZ.js → assistant-pages-BbWfd69g.js} +3 -4
  4. package/dist/{assistant-shared-CWIKRtBv.d.ts → assistant-shared-BWeRcmVS.d.ts} +0 -2
  5. package/dist/{assistant-shared-WzButktj.js → assistant-shared-JcfjK-qg.js} +3 -4
  6. package/dist/assistant-worker.d.ts +1 -3
  7. package/dist/assistant-worker.js +2 -3
  8. package/dist/assistant.d.ts +1 -3
  9. package/dist/assistant.js +2 -3
  10. package/dist/{content-CPZGnn3S.js → content-C_WXjV3y.js} +60 -28
  11. package/dist/{draft-BjWmaiLn.js → draft-rOGhtXch.js} +3 -4
  12. package/dist/{error-diagnostics-B_ZOy7kF.js → error-diagnostics-Daz9oBJS.js} +65 -2
  13. package/dist/{files-UY4h1_36.js → files-BBoAGhhM.js} +1 -2
  14. package/dist/index.d.ts +7 -8
  15. package/dist/index.js +5 -6
  16. package/dist/link-checker-redirects.d.ts +0 -2
  17. package/dist/link-checker-redirects.js +2 -3
  18. package/dist/{manifest-ZdxLrcvt.js → manifest-Bti_WxDZ.js} +64 -30
  19. package/dist/{manifest-CMoxcwPm.d.ts → manifest-DJ2DyNue.d.ts} +1 -5
  20. package/dist/{page-Dx2JD3y1.d.ts → markdown-B97RuMXs.d.ts} +2 -27
  21. package/dist/{markdown-DUWnEMPp.js → markdown-BzZkYb24.js} +2 -3
  22. package/dist/navigation.d.ts +10 -6
  23. package/dist/navigation.js +23 -10
  24. package/dist/{nuxt-CAGpKl_-.d.ts → nuxt-CYAIBEHE.d.ts} +74 -8
  25. package/dist/nuxt.d.ts +3 -3
  26. package/dist/nuxt.js +1286 -89
  27. package/dist/page-B8_70-5D.d.ts +24 -0
  28. package/dist/{page-GPt09oex.js → page-DWsretqk.js} +20 -5
  29. package/dist/primitive-rail.d.ts +1 -10
  30. package/dist/primitive-rail.js +4 -10
  31. package/dist/{raw-BChwipz_.js → raw-CQukuLuj.js} +1 -2
  32. package/dist/{redirects-CmR1yu5A.js → redirects-BEFu4KLR.js} +35 -23
  33. package/dist/runnable.d.ts +33 -0
  34. package/dist/runnable.js +104 -0
  35. package/dist/runtime/app/components/DocsAsideLeftBody.vue +2 -8
  36. package/dist/runtime/app/components/DocsLearn.vue +215 -0
  37. package/dist/runtime/app/components/DocsLearnCodePre.vue +98 -0
  38. package/dist/runtime/app/components/DocsLearnFile.vue +21 -0
  39. package/dist/runtime/app/components/DocsPage.vue +11 -5
  40. package/dist/runtime/app/components/DocsPlayground.vue +117 -0
  41. package/dist/runtime/app/components/content/Example.vue +18 -49
  42. package/dist/runtime/app/components/content/PageList.vue +1 -5
  43. package/dist/runtime/app/layouts/docs.vue +36 -8
  44. package/dist/runtime/app/middleware/docs-layout.ts +2 -2
  45. package/dist/runtime/app/utils/docs-learn.ts +31 -0
  46. package/dist/runtime/app/utils/docs-playground.ts +3 -0
  47. package/dist/runtime/server/llms.d.ts +0 -2
  48. package/dist/runtime/server/llms.js +2 -3
  49. package/dist/runtime/server/markdown.d.ts +0 -7
  50. package/dist/runtime/server/markdown.js +11 -3
  51. package/dist/runtime/server/mcp.d.ts +0 -2
  52. package/dist/runtime/server/mcp.js +2 -3
  53. package/dist/runtime/server/page.d.ts +1 -3
  54. package/dist/runtime/server/page.js +4 -5
  55. package/dist/runtime/server/raw.d.ts +0 -2
  56. package/dist/runtime/server/raw.js +3 -11
  57. package/dist/runtime/server/search.d.ts +1 -3
  58. package/dist/runtime/server/search.js +4 -4
  59. package/dist/runtime/server/sitemap.d.ts +0 -2
  60. package/dist/runtime/server/sitemap.js +3 -5
  61. package/dist/runtime/server/trailing-slash.d.ts +0 -2
  62. package/dist/runtime/server/trailing-slash.js +1 -2
  63. package/dist/schema-CmSiwC4t.js +189 -0
  64. package/dist/server.d.ts +3 -4
  65. package/dist/server.js +4 -4
  66. package/dist/snapshot-worker.mjs +40 -0
  67. package/dist/steps-C3tGwhNK.d.ts +103 -0
  68. package/dist/steps-muDP1nYT.js +31 -0
  69. package/dist/{theme-BXyu4uFL.d.ts → theme-CgJRnVdT.d.ts} +0 -4
  70. package/dist/{theme-DzC8LtMH.js → theme-CxBzPBZ9.js} +2 -4
  71. package/dist/theme.d.ts +1 -1
  72. package/dist/theme.js +1 -2
  73. package/dist/{types-BhG6vGfG.d.ts → types-B6YlHil4.d.ts} +69 -8
  74. package/package.json +40 -32
  75. package/dist/schema-DwpXW0VZ.js +0 -98
@@ -1,15 +1,15 @@
1
- import { a as parseDocsDocument, r as readDocsPage } from "../../content-CPZGnn3S.js";
1
+ import { a as parseDocsDocument, r as readDocsPage } from "../../content-C_WXjV3y.js";
2
2
  import { findDocsPage } from "../../navigation.js";
3
- import { i as docsPageResponse } from "../../page-GPt09oex.js";
3
+ import { i as docsPageResponse } from "../../page-DWsretqk.js";
4
4
  import manifest from "#docs/manifest";
5
5
  import { HTTPError, defineHandler, getRouterParam } from "nitro/h3";
6
6
  import { content } from "#docs/content";
7
- //#region src/runtime/server/page.ts
7
+ // src/runtime/server/page.ts
8
8
  /** `/api/_docs/page/docs/kv.json` is the page at `/docs/kv`. The `.json` suffix lets static hosts store every page beside its folder. */
9
9
  const handler = defineHandler(async (event) => {
10
10
  const path = `/${(getRouterParam(event, "_") ?? "").replace(/\.json$/, "")}`;
11
11
  if (content && (content.preview.active() || content.preview.frame())) {
12
- const { docsDraftResponse } = await import("../../draft-BjWmaiLn.js");
12
+ const { docsDraftResponse } = await import("../../draft-rOGhtXch.js");
13
13
  const draft = await docsDraftResponse(content, manifest, path, parseDocsDocument);
14
14
  if (draft) {
15
15
  event.res.headers.set("cache-control", "private, no-store");
@@ -23,5 +23,4 @@ const handler = defineHandler(async (event) => {
23
23
  const credits = found.page.credits ? await parseDocsDocument(found.page.credits) : null;
24
24
  return docsPageResponse(manifest, found, document, credits);
25
25
  });
26
- //#endregion
27
26
  export { handler as default };
@@ -1,10 +1,8 @@
1
1
  import { EventHandler, EventHandlerRequest } from "nitro/h3";
2
- //#region src/runtime/server/raw.d.ts
3
2
  /**
4
3
  * `/raw/<page>.md`: the agent copy of a page, the one that Content serves in `llms-full.txt` and the MCP server. The
5
4
  * build prerenders the copy of every page, so static hosts serve those files first. Negotiated pages and `.md` twins
6
5
  * fetch the copy inside the server, from this route.
7
6
  */
8
7
  declare const handler: EventHandler<EventHandlerRequest, Promise<string>>;
9
- //#endregion
10
8
  export { handler as default };
@@ -1,23 +1,15 @@
1
- import { i as readDocsRawCopy } from "../../content-CPZGnn3S.js";
1
+ import { i as readDocsRawCopy } from "../../content-C_WXjV3y.js";
2
2
  import { HTTPError, defineHandler } from "nitro/h3";
3
- //#region src/runtime/server/raw.ts
3
+ // src/runtime/server/raw.ts
4
4
  /**
5
5
  * `/raw/<page>.md`: the agent copy of a page, the one that Content serves in `llms-full.txt` and the MCP server. The
6
6
  * build prerenders the copy of every page, so static hosts serve those files first. Negotiated pages and `.md` twins
7
7
  * fetch the copy inside the server, from this route.
8
8
  */
9
9
  const handler = defineHandler(async (event) => {
10
- let path;
11
- try {
12
- path = decodeURIComponent(event.url.pathname);
13
- } catch {
14
- throw HTTPError.status(404, "Page not found");
15
- }
16
- const index = path.indexOf("/raw/");
17
- const markdown = index < 0 || !path.endsWith(".md") ? null : await readDocsRawCopy(path.slice(index));
10
+ const markdown = await readDocsRawCopy(new URL(event.req.url).pathname);
18
11
  if (markdown === null) throw HTTPError.status(404, "Page not found");
19
12
  event.res.headers.set("content-type", "text/markdown; charset=utf-8");
20
13
  return markdown;
21
14
  });
22
- //#endregion
23
15
  export { handler as default };
@@ -1,6 +1,4 @@
1
- import { i as DocsSearchSection } from "../../types-BhG6vGfG.js";
1
+ import { a as DocsSearchSection } from "../../types-B6YlHil4.js";
2
2
  import { EventHandler, EventHandlerRequest } from "nitro/h3";
3
- //#region src/runtime/server/search.d.ts
4
3
  declare const handler: EventHandler<EventHandlerRequest, Promise<DocsSearchSection[]>>;
5
- //#endregion
6
4
  export { handler as default };
@@ -1,13 +1,14 @@
1
- import { r as readDocsPage } from "../../content-CPZGnn3S.js";
2
1
  import { docsIndexedPages, docsManifestPages, docsUnindexedSearchSections } from "../../navigation.js";
3
- import { a as docsSearchSections } from "../../markdown-DUWnEMPp.js";
2
+ import { a as docsSearchSections } from "../../markdown-BzZkYb24.js";
3
+ import { r as readDocsPage } from "../../content-C_WXjV3y.js";
4
4
  import manifest from "#docs/manifest";
5
5
  import { defineHandler } from "nitro/h3";
6
- //#region src/runtime/server/search.ts
6
+ // src/runtime/server/search.ts
7
7
  /** Every page split by heading, read through the Content of the page route, for the search dialog. The build prerenders it. */
8
8
  async function buildIndex() {
9
9
  const sections = [];
10
10
  for (const page of docsIndexedPages(manifest)) {
11
+ if (!page.navigation) continue;
11
12
  const document = await readDocsPage(page);
12
13
  if (!document) continue;
13
14
  const [entry, ...headings] = docsSearchSections(page.path, page.sourceTitle, document.nodes);
@@ -28,5 +29,4 @@ const handler = defineHandler(() => {
28
29
  throw error;
29
30
  });
30
31
  });
31
- //#endregion
32
32
  export { handler as default };
@@ -1,6 +1,4 @@
1
1
  import { EventHandler, EventHandlerRequest } from "nitro/h3";
2
- //#region src/runtime/server/sitemap.d.ts
3
2
  /** The indexed pages from Content and the `sitemap` paths of the options, sorted by URL, as their canonical links name them. */
4
3
  declare const handler: EventHandler<EventHandlerRequest, Promise<string>>;
5
- //#endregion
6
4
  export { handler as default };
@@ -1,8 +1,8 @@
1
- import { n as docsContent } from "../../content-CPZGnn3S.js";
2
1
  import { docsCanonicalUrl } from "../../navigation.js";
2
+ import { n as docsContent } from "../../content-C_WXjV3y.js";
3
3
  import { useRuntimeConfig } from "nitro/runtime-config";
4
4
  import { defineHandler } from "nitro/h3";
5
- //#region ../internal/dist/sitemap.js
5
+ // ../internal/dist/sitemap.js
6
6
  function escapeXml(value) {
7
7
  return value.replace(/[&<>"']/g, (character) => ({
8
8
  "&": "&amp;",
@@ -33,8 +33,7 @@ function renderSitemap(entries) {
33
33
  const urls = entries.map((entry) => ` <url>\n <loc>${escapeXml(entry.loc)}</loc>${entry.lastmod ? `\n <lastmod>${escapeXml(entry.lastmod)}</lastmod>` : ""}\n </url>`);
34
34
  return `<?xml version="1.0" encoding="UTF-8"?>\n<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n${urls.join("\n")}${urls.length ? "\n" : ""}</urlset>\n`;
35
35
  }
36
- //#endregion
37
- //#region src/runtime/server/sitemap.ts
36
+ // src/runtime/server/sitemap.ts
38
37
  /** The indexed pages from Content and the `sitemap` paths of the options, sorted by URL, as their canonical links name them. */
39
38
  const handler = defineHandler(async (event) => {
40
39
  const { site, sitemap, appBase } = useRuntimeConfig().public.docs;
@@ -48,5 +47,4 @@ const handler = defineHandler(async (event) => {
48
47
  event.res.headers.set("content-type", "application/xml; charset=utf-8");
49
48
  return renderSitemap(mergeSitemapUrls(entries, extra));
50
49
  });
51
- //#endregion
52
50
  export { handler as default };
@@ -1,10 +1,8 @@
1
1
  import { EventHandler, EventHandlerRequest } from "nitro/h3";
2
- //#region src/runtime/server/trailing-slash.d.ts
3
2
  /**
4
3
  * `/docs/kv/` moves to `/docs/kv` with a 301, the URL that the canonical link and the sitemap name. A page that also
5
4
  * answers with a slash is a duplicate, and search engines can index the copy. Static hosts that serve the prerendered
6
5
  * `docs/kv.html` first redirect the same way; this covers Node servers and Workers that render the page.
7
6
  */
8
7
  declare const handler: EventHandler<EventHandlerRequest, Response | undefined>;
9
- //#endregion
10
8
  export { handler as default };
@@ -2,7 +2,7 @@ import { docsCanonicalUrl, findDocsPage } from "../../navigation.js";
2
2
  import manifest from "#docs/manifest";
3
3
  import { useRuntimeConfig } from "nitro/runtime-config";
4
4
  import { defineHandler } from "nitro/h3";
5
- //#region src/runtime/server/trailing-slash.ts
5
+ // src/runtime/server/trailing-slash.ts
6
6
  /**
7
7
  * `/docs/kv/` moves to `/docs/kv` with a 301, the URL that the canonical link and the sitemap name. A page that also
8
8
  * answers with a slash is a duplicate, and search engines can index the copy. Static hosts that serve the prerendered
@@ -24,5 +24,4 @@ const handler = defineHandler((event) => {
24
24
  headers: { location: `${target}${search}` }
25
25
  });
26
26
  });
27
- //#endregion
28
27
  export { handler as default };
@@ -0,0 +1,189 @@
1
+ import { z } from "zod";
2
+ // src/schema.ts
3
+ /**
4
+ * How a page renders. `article` is prose with an outline, `tutorial` numbers its steps, `landing` is a wide Overview,
5
+ * and `home` is the page's own blocks at full width under the site header, without the docs sidebar, such as a
6
+ * product home page. `playground` and `learn` fill the page with a code workspace: `playground` opens the apps of
7
+ * `examples`, and `learn` runs the `::tutorial-step` blocks of a lesson on its `fixture`.
8
+ */
9
+ const docsLayouts = [
10
+ "article",
11
+ "tutorial",
12
+ "landing",
13
+ "home",
14
+ "playground",
15
+ "learn"
16
+ ];
17
+ const connectProviders = [
18
+ "anthropic",
19
+ "github",
20
+ "netlify",
21
+ "openai",
22
+ "vercel"
23
+ ];
24
+ const navigationFields = {
25
+ title: z.string().optional(),
26
+ order: z.number().optional(),
27
+ group: z.string().optional(),
28
+ kind: z.string().optional(),
29
+ panel: z.boolean().optional()
30
+ };
31
+ const seoFields = {
32
+ title: z.string().optional(),
33
+ description: z.string().optional(),
34
+ image: z.union([z.string(), z.literal(false)]).optional(),
35
+ index: z.boolean().optional()
36
+ };
37
+ const exampleFields = {
38
+ id: z.string().regex(/^[\w-]+$/, "Use letters, digits, `-`, or `_`"),
39
+ label: z.string(),
40
+ group: z.string().optional(),
41
+ description: z.string().optional(),
42
+ dir: z.string(),
43
+ open: z.string().optional(),
44
+ preview: z.string().startsWith("/").optional(),
45
+ readonly: z.array(z.string()).optional()
46
+ };
47
+ const pageFields = {
48
+ title: z.string(),
49
+ description: z.string().optional(),
50
+ tagline: z.string().optional(),
51
+ eyebrow: z.string().optional(),
52
+ credits: z.string().optional(),
53
+ keywords: z.union([z.string(), z.array(z.string())]).optional(),
54
+ icon: z.string().optional(),
55
+ layout: z.enum(docsLayouts).optional(),
56
+ tutorial: z.enum(["project", "quickstart"]).optional(),
57
+ codePanel: z.boolean().optional(),
58
+ sidebar: z.union([z.boolean(), z.literal("collapsed")]).optional(),
59
+ toc: z.boolean().optional(),
60
+ navigation: z.union([z.literal(false), z.strictObject(navigationFields)]).optional(),
61
+ seo: z.strictObject(seoFields).optional(),
62
+ examples: z.array(z.strictObject(exampleFields)).optional(),
63
+ tabs: z.array(z.strictObject({
64
+ value: z.string().regex(/^[a-z][\w-]*$/i, "Use letters, digits, `-`, or `_`, starting with a letter"),
65
+ label: z.string()
66
+ })).optional(),
67
+ render: z.string().optional(),
68
+ connect: z.array(z.enum(connectProviders)).min(1).optional(),
69
+ port: z.number().int().min(1).max(65535).optional(),
70
+ fixture: z.string().optional(),
71
+ guide: z.enum(["top", "side"]).optional(),
72
+ lesson: z.string().startsWith("/").optional(),
73
+ preview: z.string().startsWith("/").optional()
74
+ };
75
+ const layoutFields = {
76
+ examples: ["playground"],
77
+ tabs: ["playground"],
78
+ render: ["playground"],
79
+ connect: ["playground"],
80
+ port: ["playground", "learn"],
81
+ fixture: ["learn"],
82
+ guide: ["learn"],
83
+ lesson: ["learn"],
84
+ preview: ["learn"]
85
+ };
86
+ function checkLayoutFields(page, context) {
87
+ const layout = page.layout ?? "article";
88
+ for (const [field, layouts] of Object.entries(layoutFields)) {
89
+ if (page[field] === void 0 || layouts.includes(layout)) continue;
90
+ context.addIssue({
91
+ code: "custom",
92
+ path: [field],
93
+ message: `Only a page with \`layout: ${layouts.join("` or `layout: ")}\` reads \`${field}\``
94
+ });
95
+ }
96
+ if (layout === "playground") {
97
+ if (!page.examples?.length) context.addIssue({
98
+ code: "custom",
99
+ path: ["examples"],
100
+ message: "A playground page needs at least one example"
101
+ });
102
+ const ids = /* @__PURE__ */ new Set();
103
+ for (const [index, example] of (page.examples ?? []).entries()) {
104
+ if (ids.has(example.id)) context.addIssue({
105
+ code: "custom",
106
+ path: [
107
+ "examples",
108
+ index,
109
+ "id"
110
+ ],
111
+ message: `Two examples have the id \`${example.id}\``
112
+ });
113
+ ids.add(example.id);
114
+ }
115
+ if (page.render !== void 0 && page.port !== void 0) context.addIssue({
116
+ code: "custom",
117
+ path: ["port"],
118
+ message: "A `render` page runs in the browser page and has no dev server port"
119
+ });
120
+ if (page.render !== void 0 && page.connect !== void 0) context.addIssue({
121
+ code: "custom",
122
+ path: ["connect"],
123
+ message: "A `render` page runs no app, so it has no accounts to connect"
124
+ });
125
+ }
126
+ if (layout === "learn" && page.fixture === void 0) context.addIssue({
127
+ code: "custom",
128
+ path: ["fixture"],
129
+ message: "A learn page needs the `fixture` folder of its app"
130
+ });
131
+ }
132
+ /**
133
+ * Frontmatter fields of a docs page as files store them, one Standard Schema per field. `docsCollection()` passes them
134
+ * to `documents()`, so the Console editor validates the same values that the build validates, and a save writes
135
+ * dotted keys back as dotted keys.
136
+ */
137
+ const docsPageFields = {
138
+ ...pageFields,
139
+ "navigation.title": navigationFields.title,
140
+ "navigation.order": navigationFields.order,
141
+ "navigation.group": navigationFields.group,
142
+ "navigation.kind": navigationFields.kind,
143
+ "navigation.panel": navigationFields.panel,
144
+ "seo.title": seoFields.title,
145
+ "seo.description": seoFields.description,
146
+ "seo.image": seoFields.image,
147
+ "seo.index": seoFields.index
148
+ };
149
+ /**
150
+ * The build validates frontmatter with this schema after `docsFrontmatter()` expanded its dotted keys. It also checks
151
+ * that the workspace fields sit on the layouts that read them.
152
+ */
153
+ const docsPageSchema = z.strictObject(pageFields).superRefine(checkLayoutFields);
154
+ const docsSectionSchema = z.strictObject({
155
+ title: z.string().optional(),
156
+ icon: z.string().optional(),
157
+ order: z.number().optional(),
158
+ category: z.string().optional(),
159
+ group: z.string().optional(),
160
+ fold: z.boolean().optional(),
161
+ related: z.array(z.string()).optional()
162
+ });
163
+ /** YAML keys such as `navigation.order: 2` become nested objects, as Markdown frontmatter writers expect. */
164
+ function expandDottedKeys(input) {
165
+ const output = {};
166
+ for (const [key, value] of Object.entries(input)) {
167
+ const parts = key.split(".");
168
+ let target = output;
169
+ for (const part of parts.slice(0, -1)) {
170
+ const next = target[part];
171
+ target = isRecord(next) ? next : target[part] = {};
172
+ }
173
+ target[parts.at(-1)] = value;
174
+ }
175
+ return output;
176
+ }
177
+ /**
178
+ * Frontmatter with its dotted keys expanded. `navigation: false` hides the page even when dotted keys such as
179
+ * `navigation.title` also set fields.
180
+ */
181
+ function docsFrontmatter(input) {
182
+ const expanded = expandDottedKeys(input);
183
+ if (input.navigation === false) expanded.navigation = false;
184
+ return expanded;
185
+ }
186
+ function isRecord(value) {
187
+ return typeof value === "object" && value !== null && !Array.isArray(value);
188
+ }
189
+ export { docsSectionSchema as a, docsPageSchema as i, docsLayouts as n, expandDottedKeys as o, docsPageFields as r, docsFrontmatter as t };
package/dist/server.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { a as DocsParserOptions, c as docsSearchSections, i as DocsDocument, n as DocsPageResponse, o as createDocsParser, r as docsPageResponse, s as docsMarkdown, t as DocsPageLink } from "./page-Dx2JD3y1.js";
2
- import { a as createDocsContent, c as checkDocsLinks, i as DocsSourceInput, n as DocsManifestOptions, o as createDocsManifest, r as DocsSource, s as DocsLinkCheckOptions, t as DocsContentSource } from "./manifest-CMoxcwPm.js";
3
- //#region src/raw.d.ts
1
+ import { a as createDocsContent, c as checkDocsLinks, i as DocsSourceInput, n as DocsManifestOptions, o as createDocsManifest, r as DocsSource, s as DocsLinkCheckOptions, t as DocsContentSource } from "./manifest-DJ2DyNue.js";
2
+ import { a as docsSearchSections, i as docsMarkdown, n as DocsParserOptions, r as createDocsParser, t as DocsDocument } from "./markdown-B97RuMXs.js";
3
+ import { n as DocsPageResponse, r as docsPageResponse, t as DocsPageLink } from "./page-B8_70-5D.js";
4
4
  type RawMarkdownOptions = {
5
5
  /** Origin that site-relative links point to, such as `https://vitehub.dev`. Empty keeps them relative. */
6
6
  siteUrl?: string;
@@ -11,5 +11,4 @@ type RawMarkdownOptions = {
11
11
  };
12
12
  /** The page as an agent reads it: plain Markdown, links absolute, presentation blocks unwrapped, and a `# title`. */
13
13
  export declare function toRawMarkdown(source: string, options?: RawMarkdownOptions): string;
14
- //#endregion
15
14
  export { type DocsContentSource, type DocsDocument, type DocsLinkCheckOptions, type DocsManifestOptions, type DocsPageLink, type DocsPageResponse, type DocsParserOptions, type DocsSource, type DocsSourceInput, type RawMarkdownOptions, checkDocsLinks, createDocsContent, createDocsManifest, createDocsParser, docsMarkdown, docsPageResponse, docsSearchSections };
package/dist/server.js CHANGED
@@ -1,5 +1,5 @@
1
- import { i as docsPageResponse } from "./page-GPt09oex.js";
2
- import { l as checkDocsLinks, n as createDocsContent, r as createDocsManifest } from "./manifest-ZdxLrcvt.js";
3
- import { t as toRawMarkdown } from "./raw-BChwipz_.js";
4
- import { a as docsSearchSections, i as docsMarkdown, t as createDocsParser } from "./markdown-DUWnEMPp.js";
1
+ import { l as checkDocsLinks, n as createDocsContent, r as createDocsManifest } from "./manifest-Bti_WxDZ.js";
2
+ import { a as docsSearchSections, i as docsMarkdown, t as createDocsParser } from "./markdown-BzZkYb24.js";
3
+ import { t as toRawMarkdown } from "./raw-CQukuLuj.js";
4
+ import { i as docsPageResponse } from "./page-DWsretqk.js";
5
5
  export { checkDocsLinks, createDocsContent, createDocsManifest, createDocsParser, docsMarkdown, docsPageResponse, docsSearchSections, toRawMarkdown };
@@ -0,0 +1,40 @@
1
+ // Runs in its own Node process, so the snapshot (hundreds of MiB in memory) does not share the heap of the docs build.
2
+ // node snapshot-worker.mjs <app dir> <out dir> <file prefix> <lockfile>
3
+ // Prints the written file names as JSON, with the SHA-256 of the joined parts and the sizes.
4
+ import { createHash } from "node:crypto"
5
+ import { mkdir, readFile, writeFile } from "node:fs/promises"
6
+ import { dirname, resolve } from "node:path"
7
+ import { createNodeModulesSnapshot, packSnapshot } from "@vite-hub/web-container/snapshot"
8
+
9
+ const [dir, outDir, prefix, lockPath] = process.argv.slice(2)
10
+ // The lockfile pins every version, so two builds of one commit give the same bytes.
11
+ const lockfile = await readFile(lockPath, "utf8").catch((error) => {
12
+ if (error.code === "ENOENT") return undefined
13
+ throw error
14
+ })
15
+ let result
16
+ try {
17
+ result = await createNodeModulesSnapshot({ dir, lockfile })
18
+ }
19
+ catch (error) {
20
+ if (lockfile === undefined || error?.code !== "WEB_CONTAINER_SNAPSHOT_LOCKFILE_MISMATCH") throw error
21
+ // The dependencies changed since the lockfile was written. Update it, keeping the versions that still fit.
22
+ console.warn(`[docs] ${lockPath} does not match the dependencies (${error.message.split("\n")[0]}). Updating it; commit the change.`)
23
+ result = await createNodeModulesSnapshot({ dir, lockfile, frozenLockfile: false })
24
+ }
25
+ if (result.lockfile !== lockfile) {
26
+ await mkdir(dirname(lockPath), { recursive: true })
27
+ await writeFile(lockPath, result.lockfile)
28
+ console.warn(`[docs] Wrote ${lockPath}. Commit it, so the next build installs the same versions.`)
29
+ }
30
+ const parts = packSnapshot(result.snapshot)
31
+ const hash = createHash("sha256")
32
+ for (const part of parts) hash.update(part)
33
+ const sha256 = hash.digest("hex")
34
+ const files = []
35
+ for (const [index, part] of parts.entries()) {
36
+ const file = `${prefix}.${sha256.slice(0, 12)}.${index}.bin`
37
+ await writeFile(resolve(outDir, file), part)
38
+ files.push(file)
39
+ }
40
+ console.log(JSON.stringify({ files, sha256, bytes: result.snapshot.byteLength, compressed: parts.reduce((total, part) => total + part.byteLength, 0) }))
@@ -0,0 +1,103 @@
1
+ import { c as DocsConnectProvider } from "./types-B6YlHil4.js";
2
+ import { WorkspaceRenderContext, WorkspaceRenderResult } from "@vite-hub/ui/workspace";
3
+ import { Component } from "vue";
4
+ /** Text files of an app, keyed by a relative path such as `server/api/greet.post.ts`. */
5
+ type TutorialFiles = Record<string, string>;
6
+ /** Binary files of an app, such as model weights, keyed by a relative path. */
7
+ type TutorialAssets = Record<string, Uint8Array>;
8
+ interface RunnableTutorialStep {
9
+ /** The `::tutorial-step` title. */
10
+ title: string;
11
+ /** The files that this step writes, with their final contents from the fixture. */
12
+ files: TutorialFiles;
13
+ }
14
+ /** What the workspace of one tutorial mounts, built from its lesson page and its fixture. */
15
+ interface RunnableTutorialData {
16
+ slug: string;
17
+ /** The docs page that holds the lesson prose. */
18
+ page: string;
19
+ title: string;
20
+ description: string;
21
+ /** The files before step 1: the fixture without the files that the steps write, with the fixture's dependencies. */
22
+ files: TutorialFiles;
23
+ steps: RunnableTutorialStep[];
24
+ /** The parts of the `node_modules` snapshot and their SHA-256, for `fetchSnapshot()`. Without it, the workspace runs `npm install`. */
25
+ snapshot?: {
26
+ parts: string[];
27
+ sha256: string;
28
+ };
29
+ }
30
+ /** A starting app of `/playground`, read from a fixture. */
31
+ interface PlaygroundTemplate {
32
+ id: string;
33
+ label: string;
34
+ description?: string;
35
+ /** The heading of the example in the examples menu. */
36
+ group?: string;
37
+ /** The file that the editor opens first. */
38
+ open?: string;
39
+ /** The path that the preview opens when the dev server is ready. */
40
+ preview?: string;
41
+ /** The paths of `files` that the editor does not let the reader change. */
42
+ readonly?: string[];
43
+ files: TutorialFiles;
44
+ /**
45
+ * The files that are not valid UTF-8, such as model weights. The page module of a `playground` page carries them.
46
+ * `#build/playground-templates.mjs` leaves them out.
47
+ */
48
+ assets?: TutorialAssets;
49
+ /** The slug of the snapshot that this template mounts. Templates with the same dependencies share one. */
50
+ snapshotOf: string;
51
+ /** The parts of that snapshot and their SHA-256, for `fetchSnapshot()`. Without it, the workspace runs `npm install`. */
52
+ snapshot?: RunnableTutorialData["snapshot"];
53
+ }
54
+ /** An example of a `playground` page. Examples with the same `snapshotOf` mount one snapshot. A `render` page has none. */
55
+ type DocsPlaygroundExampleData = Omit<PlaygroundTemplate, "snapshotOf"> & {
56
+ snapshotOf?: string;
57
+ };
58
+ /** What the page module of a `playground` page holds, besides its loaders. */
59
+ interface DocsPlaygroundData {
60
+ layout: "playground";
61
+ examples: DocsPlaygroundExampleData[];
62
+ /** Without `render`: the port of the dev server. */
63
+ port: number;
64
+ /** Without `render`: the accounts that the reader can connect. */
65
+ connect?: DocsConnectProvider[];
66
+ }
67
+ /** What the page module of a `learn` page holds. */
68
+ interface DocsLearnData {
69
+ layout: "learn";
70
+ tutorial: RunnableTutorialData;
71
+ guide: "top" | "side";
72
+ port: number;
73
+ preview?: string;
74
+ }
75
+ /**
76
+ * The default export of the `render` module of a `layout: playground` page. It gets the text files, and the open
77
+ * example with its binary files in `example.assets`.
78
+ */
79
+ type DocsRenderFunction = (files: TutorialFiles, context: WorkspaceRenderContext) => WorkspaceRenderResult | Promise<WorkspaceRenderResult>;
80
+ /** An output tab of a `layout: playground` page, with the component that draws it. */
81
+ interface DocsWorkspaceTab {
82
+ value: string;
83
+ label: string;
84
+ component: () => Promise<{
85
+ default: Component;
86
+ }>;
87
+ }
88
+ /** The workspace of a `playground` or `learn` page, as `#build/docs/workspaces.mjs` loads it by page path. */
89
+ type DocsWorkspaceData = (DocsPlaygroundData & {
90
+ render?: () => Promise<{
91
+ default: DocsRenderFunction;
92
+ }>;
93
+ tabs?: DocsWorkspaceTab[];
94
+ }) | DocsLearnData;
95
+ /** The files at the start of step `index` (from 0), or at its end with `solution`. Each step builds on the one before. */
96
+ declare function tutorialStepFiles(tutorial: Pick<RunnableTutorialData, "files" | "steps">, index: number, state: "start" | "solution"): TutorialFiles;
97
+ /** Loads a lesson state, removing absent tutorial files while keeping unrelated reader additions. */
98
+ declare function tutorialWorkspaceFiles(tutorial: Pick<RunnableTutorialData, "files" | "steps">, current: TutorialFiles, target: TutorialFiles): TutorialFiles;
99
+ /** Whether going from `before` to `after` adds or removes a file that the dev server reads only when its process starts. */
100
+ declare function restartsDevServer(before: TutorialFiles, after: TutorialFiles): boolean;
101
+ /** The `dependencies` of a `package.json`, sorted, so two apps with the same install compare equal. Invalid JSON has its own key. */
102
+ declare function dependencyKey(packageJson: string | undefined): string;
103
+ export { DocsWorkspaceData as a, RunnableTutorialData as c, dependencyKey as d, restartsDevServer as f, DocsRenderFunction as i, RunnableTutorialStep as l, tutorialWorkspaceFiles as m, DocsPlaygroundData as n, DocsWorkspaceTab as o, tutorialStepFiles as p, DocsPlaygroundExampleData as r, PlaygroundTemplate as s, DocsLearnData as t, TutorialFiles as u };
@@ -0,0 +1,31 @@
1
+ // src/runnable/steps.ts
2
+ /** The files at the start of step `index` (from 0), or at its end with `solution`. Each step builds on the one before. */
3
+ function tutorialStepFiles(tutorial, index, state) {
4
+ const last = state === "solution" ? index : index - 1;
5
+ const files = { ...tutorial.files };
6
+ for (let step = 0; step <= last && step < tutorial.steps.length; step++) Object.assign(files, tutorial.steps[step].files);
7
+ return files;
8
+ }
9
+ /** Loads a lesson state, removing absent tutorial files while keeping unrelated reader additions. */
10
+ function tutorialWorkspaceFiles(tutorial, current, target) {
11
+ const owned = /* @__PURE__ */ new Set([...Object.keys(tutorial.files), ...tutorial.steps.flatMap((step) => Object.keys(step.files))]);
12
+ const next = { ...current };
13
+ for (const path of owned) if (!(path in target)) delete next[path];
14
+ return Object.assign(next, target);
15
+ }
16
+ const startFiles = ["index.html"];
17
+ /** Whether going from `before` to `after` adds or removes a file that the dev server reads only when its process starts. */
18
+ function restartsDevServer(before, after) {
19
+ return startFiles.some((path) => path in before !== path in after);
20
+ }
21
+ /** The `dependencies` of a `package.json`, sorted, so two apps with the same install compare equal. Invalid JSON has its own key. */
22
+ function dependencyKey(packageJson) {
23
+ try {
24
+ const dependencies = packageJson ? JSON.parse(packageJson).dependencies : void 0;
25
+ const entries = dependencies && typeof dependencies === "object" ? Object.entries(dependencies) : [];
26
+ return JSON.stringify(entries.sort(([a], [b]) => a.localeCompare(b)));
27
+ } catch {
28
+ return "invalid";
29
+ }
30
+ }
31
+ export { tutorialWorkspaceFiles as i, restartsDevServer as n, tutorialStepFiles as r, dependencyKey as t };
@@ -1,4 +1,3 @@
1
- //#region runtime/app/utils/docs-theme.d.ts
2
1
  type DocsThemeUi$1 = Record<string, unknown>;
3
2
  /** What Nuxt UI's `<UTheme>` takes: slot classes per component in `ui`, and default props per component in `props`. */
4
3
  interface DocsThemeScope {
@@ -11,8 +10,6 @@ interface DocsThemeScope {
11
10
  * the app's colors, icons, and variant classes, such as the color of a callout.
12
11
  */
13
12
  declare function docsThemeScope(theme: DocsThemeUi$1): DocsThemeScope;
14
- //#endregion
15
- //#region src/theme.d.ts
16
13
  /** Nuxt UI app config of the docs design: color aliases, icons, and slot classes per component. */
17
14
  type DocsThemeUi = Record<string, unknown>;
18
15
  /**
@@ -28,5 +25,4 @@ declare function docsAppConfigUi(design: DocsThemeUi, current: DocsThemeUi | und
28
25
  declare function docsUi(siteName: string): DocsThemeUi;
29
26
  /** The part of the theme that only adds keys, so an app with its own `app.vue` gets it in its app config. */
30
27
  declare function docsThemeAdditions(theme: DocsThemeUi): DocsThemeUi;
31
- //#endregion
32
28
  export { DocsThemeScope as a, docsUi as i, docsAppConfigUi as n, docsThemeScope as o, docsThemeAdditions as r, DocsThemeUi as t };
@@ -1,6 +1,6 @@
1
1
  import { vitehubTheme } from "@vite-hub/ui/theme";
2
2
  import { defu } from "defu";
3
- //#region runtime/app/utils/docs-theme.ts
3
+ // runtime/app/utils/docs-theme.ts
4
4
  /**
5
5
  * The theme as `<UTheme>` props, for the docs pages of an app with its own `app.vue`. The app's `app.config.ts` then
6
6
  * stays as written on the app's own pages. `<UTheme>` sets slot classes and default props only, so the docs pages keep
@@ -28,8 +28,7 @@ function docsThemeScope(theme) {
28
28
  function isRecord$1(value) {
29
29
  return typeof value === "object" && value !== null && !Array.isArray(value);
30
30
  }
31
- //#endregion
32
- //#region src/theme.ts
31
+ // src/theme.ts
33
32
  /**
34
33
  * The `ui` app config of the site. What the app writes in its Nuxt config wins over the design, and the design wins
35
34
  * over the rest, such as the green and slate defaults that Nuxt UI adds when the app lists `@nuxt/ui` before this
@@ -233,5 +232,4 @@ function docsThemeAdditions(theme) {
233
232
  function isRecord(value) {
234
233
  return typeof value === "object" && value !== null && !Array.isArray(value);
235
234
  }
236
- //#endregion
237
235
  export { docsThemeScope as i, docsThemeAdditions as n, docsUi as r, docsAppConfigUi as t };
package/dist/theme.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as DocsThemeScope, i as docsUi, n as docsAppConfigUi, o as docsThemeScope, r as docsThemeAdditions, t as DocsThemeUi } from "./theme-BXyu4uFL.js";
1
+ import { a as DocsThemeScope, i as docsUi, n as docsAppConfigUi, o as docsThemeScope, r as docsThemeAdditions, t as DocsThemeUi } from "./theme-CgJRnVdT.js";
2
2
  export { type DocsThemeScope, DocsThemeUi, docsAppConfigUi, docsThemeAdditions, docsThemeScope, docsUi };
package/dist/theme.js CHANGED
@@ -1,2 +1 @@
1
- import { i as docsThemeScope, n as docsThemeAdditions, r as docsUi, t as docsAppConfigUi } from "./theme-DzC8LtMH.js";
2
- export { docsAppConfigUi, docsThemeAdditions, docsThemeScope, docsUi };
1
+ export { t as docsAppConfigUi, n as docsThemeAdditions, i as docsThemeScope, r as docsUi } from "./theme-CxBzPBZ9.js";