@wrksz/docs 0.0.0-stage → 0.1.0

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 (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +157 -2
  3. package/dist/agents.d.ts +30 -0
  4. package/dist/agents.js +70 -0
  5. package/dist/components/agent-logos.js +90 -0
  6. package/dist/components/agent-prompt.d.ts +29 -0
  7. package/dist/components/agent-prompt.js +100 -0
  8. package/dist/components/badge.d.ts +16 -0
  9. package/dist/components/badge.js +26 -0
  10. package/dist/components/brand.js +30 -0
  11. package/dist/components/callout.d.ts +24 -0
  12. package/dist/components/callout.js +58 -0
  13. package/dist/components/cards.d.ts +26 -0
  14. package/dist/components/cards.js +48 -0
  15. package/dist/components/code-body.js +18 -0
  16. package/dist/components/code-group.d.ts +20 -0
  17. package/dist/components/code-group.js +41 -0
  18. package/dist/components/code-tabs.d.ts +30 -0
  19. package/dist/components/code-tabs.js +49 -0
  20. package/dist/components/content-tabs.d.ts +14 -0
  21. package/dist/components/content-tabs.js +27 -0
  22. package/dist/components/copy-code.js +41 -0
  23. package/dist/components/deferred-analytics.js +5 -0
  24. package/dist/components/details.d.ts +20 -0
  25. package/dist/components/details.js +29 -0
  26. package/dist/components/heading-link.js +23 -0
  27. package/dist/components/heading.d.ts +5 -0
  28. package/dist/components/heading.js +22 -0
  29. package/dist/components/icons.js +362 -0
  30. package/dist/components/image.d.ts +27 -0
  31. package/dist/components/image.js +204 -0
  32. package/dist/components/inline-text.js +14 -0
  33. package/dist/components/install.d.ts +22 -0
  34. package/dist/components/install.js +62 -0
  35. package/dist/components/mdx-tabs.d.ts +22 -0
  36. package/dist/components/mdx-tabs.js +30 -0
  37. package/dist/components/practice.d.ts +41 -0
  38. package/dist/components/practice.js +99 -0
  39. package/dist/components/props.d.ts +37 -0
  40. package/dist/components/props.js +70 -0
  41. package/dist/components/status.js +35 -0
  42. package/dist/components/steps.d.ts +18 -0
  43. package/dist/components/steps.js +23 -0
  44. package/dist/components/theme-switch.js +31 -0
  45. package/dist/components/ui/kbd.js +410 -0
  46. package/dist/components/ui/scroll-area.js +169 -0
  47. package/dist/components/ui/table.d.ts +33 -0
  48. package/dist/components/ui/table.js +103 -0
  49. package/dist/components/ui/tabs.js +69 -0
  50. package/dist/components/ui/toast.js +629 -0
  51. package/dist/components/ui/tooltip.js +31 -0
  52. package/dist/components/wrksz-mark.js +12 -0
  53. package/dist/docs/index.d.ts +8 -0
  54. package/dist/docs/index.js +8 -0
  55. package/dist/docs/layout.d.ts +6 -0
  56. package/dist/docs/layout.js +10 -0
  57. package/dist/docs/page-actions.d.ts +36 -0
  58. package/dist/docs/page-actions.js +136 -0
  59. package/dist/docs/page-footer.d.ts +14 -0
  60. package/dist/docs/page-footer.js +68 -0
  61. package/dist/docs/page-header.d.ts +13 -0
  62. package/dist/docs/page-header.js +57 -0
  63. package/dist/docs/page.d.ts +16 -0
  64. package/dist/docs/page.js +38 -0
  65. package/dist/docs/reading.js +64 -0
  66. package/dist/docs/shell.js +101 -0
  67. package/dist/docs/sidebar.js +161 -0
  68. package/dist/docs/toc-bar.d.ts +12 -0
  69. package/dist/docs/toc-bar.js +132 -0
  70. package/dist/docs/toc.d.ts +11 -0
  71. package/dist/docs/toc.js +127 -0
  72. package/dist/fonts/Inter-Italic.woff2 +0 -0
  73. package/dist/fonts/Inter-LICENSE.txt +92 -0
  74. package/dist/fonts/Inter.woff2 +0 -0
  75. package/dist/fonts/IoskeleyMono-Bold.woff2 +0 -0
  76. package/dist/fonts/IoskeleyMono-Italic.woff2 +0 -0
  77. package/dist/fonts/IoskeleyMono-LICENSE.txt +92 -0
  78. package/dist/fonts/IoskeleyMono-Regular.woff2 +0 -0
  79. package/dist/fonts.d.ts +1 -0
  80. package/dist/fonts.js +38 -0
  81. package/dist/home/features.d.ts +39 -0
  82. package/dist/home/features.js +75 -0
  83. package/dist/home/footer.d.ts +4 -0
  84. package/dist/home/footer.js +79 -0
  85. package/dist/home/hero-content.js +102 -0
  86. package/dist/home/hero-install.js +128 -0
  87. package/dist/home/hero-stage.d.ts +4 -0
  88. package/dist/home/hero-stage.js +9 -0
  89. package/dist/home/hero.d.ts +6 -0
  90. package/dist/home/hero.js +16 -0
  91. package/dist/home/home-header.d.ts +1 -0
  92. package/dist/home/home-header.js +173 -0
  93. package/dist/home/index.d.ts +7 -0
  94. package/dist/home/index.js +7 -0
  95. package/dist/home/layout.d.ts +6 -0
  96. package/dist/home/layout.js +15 -0
  97. package/dist/home/reveal.js +31 -0
  98. package/dist/index.d.ts +4 -0
  99. package/dist/index.js +4 -0
  100. package/dist/lib/clipboard.js +55 -0
  101. package/dist/lib/cn.js +1 -0
  102. package/dist/lib/format.js +9 -0
  103. package/dist/lib/package-manager-script.js +12 -0
  104. package/dist/lib/package-manager.js +54 -0
  105. package/dist/lib/theme-config.js +10 -0
  106. package/dist/llms.d.ts +34 -0
  107. package/dist/llms.js +111 -0
  108. package/dist/next.d.ts +18 -0
  109. package/dist/next.js +45 -0
  110. package/dist/node_modules/.pnpm/@types_mdast@4.0.4/node_modules/@types/mdast/index.d.ts +930 -0
  111. package/dist/node_modules/.pnpm/@types_mdx@2.0.14/node_modules/@types/mdx/types.d.ts +81 -0
  112. package/dist/node_modules/.pnpm/@types_unist@3.0.3/node_modules/@types/unist/index.d.ts +80 -0
  113. package/dist/registry.d.ts +61 -0
  114. package/dist/registry.js +113 -0
  115. package/dist/root.d.ts +9 -0
  116. package/dist/root.js +34 -0
  117. package/dist/search.d.ts +5 -0
  118. package/dist/search.js +43 -0
  119. package/dist/seo/index.d.ts +6 -0
  120. package/dist/seo/index.js +6 -0
  121. package/dist/seo/json-ld.d.ts +17 -0
  122. package/dist/seo/json-ld.js +88 -0
  123. package/dist/seo/metadata.d.ts +21 -0
  124. package/dist/seo/metadata.js +75 -0
  125. package/dist/seo/robots.d.ts +14 -0
  126. package/dist/seo/robots.js +18 -0
  127. package/dist/seo/sitemap.d.ts +16 -0
  128. package/dist/seo/sitemap.js +26 -0
  129. package/dist/seo/url.d.ts +6 -0
  130. package/dist/seo/url.js +11 -0
  131. package/dist/server.js +63 -0
  132. package/dist/site-context.js +17 -0
  133. package/dist/site.d.ts +41 -0
  134. package/dist/site.js +13 -0
  135. package/dist/source/compile.d.ts +6 -0
  136. package/dist/source/compile.js +32 -0
  137. package/dist/source/errors.d.ts +4 -0
  138. package/dist/source/errors.js +10 -0
  139. package/dist/source/frontmatter.d.ts +13 -0
  140. package/dist/source/frontmatter.js +102 -0
  141. package/dist/source/highlight.js +102 -0
  142. package/dist/source/index.d.ts +36 -0
  143. package/dist/source/index.js +102 -0
  144. package/dist/source/markdown.d.ts +48 -0
  145. package/dist/source/markdown.js +393 -0
  146. package/dist/source/prompt.js +33 -0
  147. package/dist/source/scan.d.ts +8 -0
  148. package/dist/source/scan.js +64 -0
  149. package/dist/source/toc.d.ts +5 -0
  150. package/dist/source/toc.js +28 -0
  151. package/dist/source/tree.d.ts +29 -0
  152. package/dist/source/tree.js +91 -0
  153. package/dist/styles.css +879 -0
  154. package/dist/typography.d.ts +101 -0
  155. package/dist/typography.js +232 -0
  156. package/package.json +84 -4
@@ -0,0 +1,16 @@
1
+ import { MetadataRoute } from "next";
2
+ import { Site } from "../site.js";
3
+ import { Source } from "../source/index.js";
4
+ /** Options for `createSitemap`. */
5
+ export type SitemapOptions = {
6
+ /** Include the root `/` home page entry. Defaults to `true`. */
7
+ includeHome?: boolean;
8
+ /** Additional sitemap entries appended after documentation pages. */
9
+ extra?: MetadataRoute.Sitemap;
10
+ };
11
+ /**
12
+ * Generates a Next.js `MetadataRoute.Sitemap` from `site` and `source`.
13
+ * Automatically excludes `hidden` and `draft` pages and attaches `lastModified`
14
+ * timestamps when available.
15
+ */
16
+ export declare function createSitemap(site: Site, source: Source, options?: SitemapOptions): MetadataRoute.Sitemap;
@@ -0,0 +1,26 @@
1
+ import { absoluteUrl } from "./url.js";
2
+ // src/seo/sitemap.ts
3
+ /**
4
+ * Generates a Next.js `MetadataRoute.Sitemap` from `site` and `source`.
5
+ * Automatically excludes `hidden` and `draft` pages and attaches `lastModified`
6
+ * timestamps when available.
7
+ */
8
+ function createSitemap(site, source, options) {
9
+ const entries = [];
10
+ if (options?.includeHome !== false) entries.push({
11
+ url: absoluteUrl(site, "/"),
12
+ priority: 1
13
+ });
14
+ for (const page of source.pages()) {
15
+ if (page.data.hidden || page.data.draft) continue;
16
+ const modified = source.updated(page);
17
+ entries.push({
18
+ url: absoluteUrl(site, page.url),
19
+ ...modified ? { lastModified: modified } : {},
20
+ priority: page.slugs.length === 0 ? .9 : .7
21
+ });
22
+ }
23
+ if (options?.extra?.length) entries.push(...options.extra);
24
+ return entries;
25
+ }
26
+ export { createSitemap };
@@ -0,0 +1,6 @@
1
+ import { Site } from "../site.js";
2
+ /**
3
+ * Joins a site's base URL with a relative path, normalizing leading and
4
+ * trailing slashes so canonical URLs, sitemaps, and JSON-LD stay consistent.
5
+ */
6
+ export declare function absoluteUrl(site: Pick<Site, "url">, path?: string): string;
@@ -0,0 +1,11 @@
1
+ // src/seo/url.ts
2
+ /**
3
+ * Joins a site's base URL with a relative path, normalizing leading and
4
+ * trailing slashes so canonical URLs, sitemaps, and JSON-LD stay consistent.
5
+ */
6
+ function absoluteUrl(site, path = "/") {
7
+ const base = site.url.replace(/\/+$/, "");
8
+ if (!path || path === "/") return base;
9
+ return `${base}${path.startsWith("/") ? path : `/${path}`}`;
10
+ }
11
+ export { absoluteUrl };
package/dist/server.js ADDED
@@ -0,0 +1,63 @@
1
+ import { unstable_cache } from "next/cache";
2
+ import { downloadsUrl, latestUrl, pick } from "./registry.js";
3
+ import { githubUrl } from "./site.js";
4
+ // src/server.ts
5
+ function githubHeaders() {
6
+ const token = process.env.GITHUB_TOKEN;
7
+ return {
8
+ Accept: "application/vnd.github+json",
9
+ ...token ? { Authorization: `Bearer ${token}` } : {}
10
+ };
11
+ }
12
+ async function json(url, init) {
13
+ try {
14
+ const res = await fetch(url, init);
15
+ return res.ok ? await res.json() : null;
16
+ } catch {
17
+ return null;
18
+ }
19
+ }
20
+ function getGitHubStars(site) {
21
+ return unstable_cache(async () => {
22
+ return (await json(githubUrl(site).replace("https://github.com", "https://api.github.com/repos"), { headers: githubHeaders() }))?.stargazers_count ?? null;
23
+ }, [
24
+ "github-stars",
25
+ site.repo.owner,
26
+ site.repo.name
27
+ ], { revalidate: 3600 })();
28
+ }
29
+ async function weeklyDownloads(pkg) {
30
+ const source = pkg.registry.downloads;
31
+ const url = downloadsUrl(pkg);
32
+ if (!source || !url) return null;
33
+ const value = pick(await json(url), source.path);
34
+ return typeof value === "number" ? value : null;
35
+ }
36
+ function getWeeklyDownloads(site) {
37
+ return unstable_cache(() => weeklyDownloads(site.package), [
38
+ "weekly-downloads",
39
+ site.package.registry.id,
40
+ site.package.name
41
+ ], { revalidate: 3600 })();
42
+ }
43
+ async function latestVersion(pkg) {
44
+ const url = latestUrl(pkg);
45
+ if (!pkg.registry.latest || !url) return null;
46
+ const value = pick(await json(url), pkg.registry.latest.path);
47
+ return typeof value === "string" && value ? value : null;
48
+ }
49
+ /**
50
+ * The version to show next to the site's name: `site.version` when it is set, nothing when
51
+ * it is `false`, otherwise the latest release from the registry, cached for an hour. A
52
+ * package that is not published yet shows none.
53
+ */
54
+ function getVersion(site) {
55
+ if (site.version === false) return Promise.resolve(null);
56
+ if (typeof site.version === "string") return Promise.resolve(site.version);
57
+ return unstable_cache(() => latestVersion(site.package), [
58
+ "latest-version",
59
+ site.package.registry.id,
60
+ site.package.name
61
+ ], { revalidate: 3600 })();
62
+ }
63
+ export { getGitHubStars, getVersion, getWeeklyDownloads };
@@ -0,0 +1,17 @@
1
+ "use client";
2
+ import { createContext, use } from "react";
3
+ import { jsx } from "react/jsx-runtime";
4
+ // src/site-context.tsx
5
+ const SiteContext = createContext(null);
6
+ function SiteProvider({ site, children }) {
7
+ return /* @__PURE__ */ jsx(SiteContext, {
8
+ value: site,
9
+ children
10
+ });
11
+ }
12
+ function useSite() {
13
+ const site = use(SiteContext);
14
+ if (!site) throw new Error("useSite needs <DocsRoot site={...}> above it.");
15
+ return site;
16
+ }
17
+ export { SiteProvider, useSite };
package/dist/site.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import { Agent } from "./agents.js";
2
+ import { Package } from "./registry.js";
3
+ export type SiteLink = {
4
+ label: string;
5
+ href: string;
6
+ };
7
+ export type Site = {
8
+ name: string;
9
+ package: Package;
10
+ description: string;
11
+ url: string;
12
+ repo: {
13
+ owner: string;
14
+ name: string;
15
+ branch?: string;
16
+ docsDir?: string;
17
+ };
18
+ footer?: {
19
+ label: string;
20
+ links: SiteLink[];
21
+ }[];
22
+ nav?: SiteLink[];
23
+ /**
24
+ * Agents `<AgentPrompt>` offers, by id (`claude-code`, `codex`, `cursor`, `claude`,
25
+ * `chatgpt`, `grok`) or as `defineAgent` objects. Defaults to Claude Code, Codex, Cursor.
26
+ */
27
+ agents?: (string | Agent)[];
28
+ /**
29
+ * Where a page's Open menu sends it, after "View as Markdown": agents by id or
30
+ * `defineAgent`. Defaults to ChatGPT, Claude, Grok and Cursor.
31
+ */
32
+ openIn?: (string | Agent)[];
33
+ /**
34
+ * Version shown next to the name. Left out, it is the latest release from the package's
35
+ * registry; a string pins it; `false` hides it.
36
+ */
37
+ version?: string | false;
38
+ };
39
+ export declare function defineSite(site: Site): Site;
40
+ export declare function githubUrl(site: Site): string;
41
+ export declare function editUrl(site: Site, path: string): string;
package/dist/site.js ADDED
@@ -0,0 +1,13 @@
1
+ // src/site.ts
2
+ function defineSite(site) {
3
+ return site;
4
+ }
5
+ function githubUrl(site) {
6
+ return `https://github.com/${site.repo.owner}/${site.repo.name}`;
7
+ }
8
+ function editUrl(site, path) {
9
+ const branch = site.repo.branch ?? "main";
10
+ const dir = site.repo.docsDir ?? "apps/docs/content/docs";
11
+ return `${githubUrl(site)}/blob/${branch}/${dir}/${path}`;
12
+ }
13
+ export { defineSite, editUrl, githubUrl };
@@ -0,0 +1,6 @@
1
+ import { MDXContent } from "../node_modules/.pnpm/@types_mdx@2.0.14/node_modules/@types/mdx/types.js";
2
+ import { TocEntry } from "./toc.js";
3
+ export type Compiled = {
4
+ Body: MDXContent;
5
+ toc: TocEntry[];
6
+ };
@@ -0,0 +1,32 @@
1
+ import { compile, run } from "@mdx-js/mdx";
2
+ import * as runtime from "react/jsx-runtime";
3
+ import remarkGfm from "remark-gfm";
4
+ import { rehypeHighlight } from "./highlight.js";
5
+ import { remarkAgentPrompt } from "./prompt.js";
6
+ import { ContentError } from "./errors.js";
7
+ import { rehypeToc } from "./toc.js";
8
+ // src/source/compile.ts
9
+ async function compileMdx(file, body, format) {
10
+ const toc = [];
11
+ let code;
12
+ try {
13
+ code = String(await compile(body, {
14
+ format,
15
+ outputFormat: "function-body",
16
+ development: false,
17
+ remarkPlugins: [remarkGfm, remarkAgentPrompt],
18
+ rehypePlugins: [[rehypeToc, { toc }], rehypeHighlight]
19
+ }));
20
+ } catch (error) {
21
+ const place = error.line ? ` (line ${error.line})` : "";
22
+ throw new ContentError(file, `MDX does not compile${place}. ${error.message}`);
23
+ }
24
+ return {
25
+ Body: (await run(code, {
26
+ ...runtime,
27
+ baseUrl: import.meta.url
28
+ })).default,
29
+ toc
30
+ };
31
+ }
32
+ export { compileMdx };
@@ -0,0 +1,4 @@
1
+ export declare class ContentError extends Error {
2
+ readonly file: string;
3
+ constructor(file: string, message: string);
4
+ }
@@ -0,0 +1,10 @@
1
+ // src/source/errors.ts
2
+ var ContentError = class extends Error {
3
+ file;
4
+ constructor(file, message) {
5
+ super(`${file}: ${message}`);
6
+ this.name = "ContentError";
7
+ this.file = file;
8
+ }
9
+ };
10
+ export { ContentError };
@@ -0,0 +1,13 @@
1
+ export type PageStatus = "new" | "beta" | "deprecated";
2
+ export type Frontmatter = {
3
+ title: string;
4
+ description?: string;
5
+ navTitle?: string;
6
+ external?: string;
7
+ status?: PageStatus;
8
+ hidden?: boolean;
9
+ draft?: boolean;
10
+ toc?: boolean;
11
+ keywords?: string[];
12
+ updated?: Date;
13
+ };
@@ -0,0 +1,102 @@
1
+ import { parse } from "yaml";
2
+ import { ContentError } from "./errors.js";
3
+ // src/source/frontmatter.ts
4
+ const FIELDS = {
5
+ title: {
6
+ type: "string",
7
+ required: true
8
+ },
9
+ description: { type: "string" },
10
+ navTitle: { type: "string" },
11
+ external: { type: "url" },
12
+ status: { type: "status" },
13
+ hidden: { type: "boolean" },
14
+ draft: { type: "boolean" },
15
+ toc: { type: "boolean" },
16
+ keywords: { type: "strings" },
17
+ updated: { type: "date" }
18
+ };
19
+ const STATUSES = [
20
+ "new",
21
+ "beta",
22
+ "deprecated"
23
+ ];
24
+ function distance(a, b) {
25
+ const row = Array.from({ length: b.length + 1 }, (_, i) => i);
26
+ for (let i = 1; i <= a.length; i++) {
27
+ let previous = row[0] ?? 0;
28
+ row[0] = i;
29
+ for (let j = 1; j <= b.length; j++) {
30
+ const current = row[j] ?? 0;
31
+ row[j] = Math.min(current + 1, (row[j - 1] ?? 0) + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
32
+ previous = current;
33
+ }
34
+ }
35
+ return row[b.length] ?? 0;
36
+ }
37
+ function suggest(key) {
38
+ const best = Object.keys(FIELDS).map((name) => ({
39
+ name,
40
+ score: distance(key.toLowerCase(), name.toLowerCase())
41
+ })).toSorted((a, b) => a.score - b.score)[0];
42
+ return best && best.score <= 2 ? ` Did you mean "${best.name}"?` : "";
43
+ }
44
+ function check(file, key, field, value) {
45
+ const fail = (expected) => new ContentError(file, `"${key}" should be ${expected}, got ${JSON.stringify(value)}.`);
46
+ switch (field.type) {
47
+ case "string":
48
+ if (typeof value !== "string" || value.trim() === "") throw fail("a non-empty string");
49
+ return value.trim();
50
+ case "boolean":
51
+ if (typeof value !== "boolean") throw fail("true or false");
52
+ return value;
53
+ case "strings":
54
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) throw fail("a list of strings");
55
+ return value;
56
+ case "date": {
57
+ const date = value instanceof Date ? value : new Date(String(value));
58
+ if (Number.isNaN(date.getTime())) throw fail("a date like 2026-11-27");
59
+ return date;
60
+ }
61
+ case "status":
62
+ if (!STATUSES.includes(value)) throw fail(`one of ${STATUSES.map((s) => `"${s}"`).join(", ")}`);
63
+ return value;
64
+ case "url":
65
+ if (typeof value !== "string" || !/^https?:\/\//.test(value)) throw fail("an absolute http(s) URL");
66
+ return value;
67
+ }
68
+ }
69
+ function splitFrontmatter(source) {
70
+ const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(source);
71
+ if (!match) return {
72
+ data: "",
73
+ body: source
74
+ };
75
+ return {
76
+ data: match[1] ?? "",
77
+ body: source.slice(match[0].length)
78
+ };
79
+ }
80
+ function parseFrontmatter(file, source) {
81
+ const { data, body } = splitFrontmatter(source);
82
+ let raw;
83
+ try {
84
+ raw = data ? parse(data) : {};
85
+ } catch (error) {
86
+ throw new ContentError(file, `frontmatter is not valid YAML. ${error.message}`);
87
+ }
88
+ if (raw === null || typeof raw !== "object" || Array.isArray(raw)) throw new ContentError(file, "frontmatter should be a set of key: value pairs.");
89
+ const result = {};
90
+ for (const [key, value] of Object.entries(raw)) {
91
+ const field = FIELDS[key];
92
+ if (!field) throw new ContentError(file, `"${key}" is not a frontmatter field.${suggest(key)}`);
93
+ if (value === null || value === void 0) continue;
94
+ result[key] = check(file, key, field, value);
95
+ }
96
+ for (const [key, field] of Object.entries(FIELDS)) if (field.required && result[key] === void 0) throw new ContentError(file, `"${key}" is required.`);
97
+ return {
98
+ data: result,
99
+ body
100
+ };
101
+ }
102
+ export { parseFrontmatter, splitFrontmatter };
@@ -0,0 +1,102 @@
1
+ import { codeToTokens, isSupportedLanguage, pierreDark, pierreLight } from "@pierre/highlights";
2
+ import { toString } from "hast-util-to-string";
3
+ import { visit } from "unist-util-visit";
4
+ // src/source/highlight.ts
5
+ /** `// [!code ++]`, `# [!code --]`, `{/* [!code highlight] *\/}` and the like, at the end of a line. */
6
+ const NOTATION = /\s*(?:\/\/|#|--|\/\*|\{\/\*|<!--)\s*\[!code\s+(\+\+|--|highlight|hl)\]\s*(?:\*\/\}|\*\/|-->)?\s*$/;
7
+ const MARKS = {
8
+ "++": "add",
9
+ "--": "remove",
10
+ highlight: "highlighted",
11
+ hl: "highlighted"
12
+ };
13
+ /** `{1,3-5}` in the fence: line numbers to highlight, counted from 1. */
14
+ function metaLines(meta) {
15
+ const lines = /* @__PURE__ */ new Set();
16
+ const range = /\{([\d\s,-]+)\}/.exec(meta)?.[1];
17
+ if (!range) return lines;
18
+ for (const part of range.split(",")) {
19
+ const [from, to = from] = part.trim().split("-").map(Number);
20
+ if (from === void 0 || to === void 0 || Number.isNaN(from) || Number.isNaN(to)) continue;
21
+ for (let line = from; line <= to; line++) lines.add(line);
22
+ }
23
+ return lines;
24
+ }
25
+ function metaTitle(meta) {
26
+ const match = /(?:^|\s)title=(?:"([^"]*)"|'([^']*)')/.exec(meta);
27
+ return match?.[1] ?? match?.[2];
28
+ }
29
+ function language(code) {
30
+ const classes = code.properties.className;
31
+ return (Array.isArray(classes) ? classes.map(String).find((name) => name.startsWith("language-")) : void 0)?.slice(9) ?? "text";
32
+ }
33
+ function tokenize(source, lang) {
34
+ const { tokens } = codeToTokens(source, {
35
+ lang: isSupportedLanguage(lang) ? lang : "text",
36
+ themes: {
37
+ light: pierreLight,
38
+ dark: pierreDark
39
+ },
40
+ defaultColor: false,
41
+ cssVariablePrefix: "--hl-"
42
+ });
43
+ return tokens.map((line) => line.map((token) => ({
44
+ type: "element",
45
+ tagName: "span",
46
+ properties: token.htmlStyle ? { style: Object.entries(token.htmlStyle).map(([name, value]) => `${name}:${value}`).join(";") } : {},
47
+ children: [{
48
+ type: "text",
49
+ value: token.content
50
+ }]
51
+ })));
52
+ }
53
+ /**
54
+ * Highlights fenced code with Pierre's highlighter, in both themes at once: each token
55
+ * carries `--hl-light` and `--hl-dark`, and CSS picks one. Reads `title="…"` and `{1,3}`
56
+ * from the fence and `[!code ++]`, `[!code --]` and `[!code highlight]` comments from
57
+ * the lines, which it removes from the code.
58
+ */
59
+ function rehypeHighlight() {
60
+ return (tree) => {
61
+ visit(tree, "element", (pre) => {
62
+ const code = pre.tagName === "pre" ? pre.children[0] : void 0;
63
+ if (code?.type !== "element" || code.tagName !== "code") return;
64
+ const meta = String(code.data?.meta ?? "");
65
+ const lang = language(code);
66
+ const marks = [];
67
+ const source = toString(code).replace(/\n$/, "").split("\n").map((line, index) => {
68
+ const match = NOTATION.exec(line);
69
+ if (!match?.[1]) return line;
70
+ marks[index] = MARKS[match[1]];
71
+ return line.slice(0, match.index);
72
+ }).join("\n");
73
+ const highlighted = metaLines(meta);
74
+ const lines = [];
75
+ tokenize(source, lang).forEach((tokens, index) => {
76
+ const mark = marks[index] ?? (highlighted.has(index + 1) ? "highlighted" : void 0);
77
+ if (index > 0) lines.push({
78
+ type: "text",
79
+ value: "\n"
80
+ });
81
+ lines.push({
82
+ type: "element",
83
+ tagName: "span",
84
+ properties: { className: mark === "highlighted" ? ["line", "highlighted"] : mark ? [
85
+ "line",
86
+ "diff",
87
+ mark
88
+ ] : ["line"] },
89
+ children: tokens
90
+ });
91
+ });
92
+ const title = metaTitle(meta);
93
+ pre.properties = {
94
+ ...title ? { dataTitle: title } : {},
95
+ dataLanguage: lang
96
+ };
97
+ code.properties = {};
98
+ code.children = lines;
99
+ });
100
+ };
101
+ }
102
+ export { rehypeHighlight };
@@ -0,0 +1,36 @@
1
+ import { Compiled } from "./compile.js";
2
+ import { JsxElement, LowerContext, Lowering, MarkdownOptions, builtInLowerings, mdxToMarkdown } from "./markdown.js";
3
+ import { ContentPage } from "./scan.js";
4
+ import { Crumb, TreeFolder, TreeLink, TreeNode, TreePage, TreeSection } from "./tree.js";
5
+ import { ContentError } from "./errors.js";
6
+ import { Frontmatter, PageStatus } from "./frontmatter.js";
7
+ import { TocEntry } from "./toc.js";
8
+ export type SourceOptions = {
9
+ dir: string;
10
+ baseUrl?: string;
11
+ drafts?: boolean;
12
+ };
13
+ export type Source = ReturnType<typeof createSource>;
14
+ export declare function createSource({ dir, baseUrl, drafts }: SourceOptions): {
15
+ /** Path the docs are served under, e.g. `/docs`. */
16
+ baseUrl: string;
17
+ pages(): ContentPage[];
18
+ page(slugs?: string[]): ContentPage | undefined;
19
+ tree(): TreeNode[];
20
+ breadcrumbs(page: ContentPage): Crumb[];
21
+ neighbours(page: ContentPage): {
22
+ previous?: TreePage;
23
+ next?: TreePage;
24
+ };
25
+ params(): {
26
+ slug: string[];
27
+ }[];
28
+ /**
29
+ * The page as plain Markdown for agents and `.md` exports, with its title and
30
+ * description on top. See `mdxToMarkdown` for what happens to components and code.
31
+ */
32
+ markdown(page: ContentPage, options?: MarkdownOptions): string;
33
+ render(page: ContentPage): Promise<Compiled>;
34
+ updated(page: ContentPage): Date | undefined;
35
+ };
36
+ export { ContentError, type ContentPage, type Crumb, type Frontmatter, type JsxElement, type LowerContext, type Lowering, type MarkdownOptions, type PageStatus, type TocEntry, type TreeFolder, type TreeLink, type TreeNode, type TreePage, type TreeSection, builtInLowerings, mdxToMarkdown };
@@ -0,0 +1,102 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { join, resolve } from "node:path";
3
+ import { cache } from "react";
4
+ import { compileMdx } from "./compile.js";
5
+ import { builtInLowerings, mdxToMarkdown } from "./markdown.js";
6
+ import { scanContent } from "./scan.js";
7
+ import { buildTree, findTrail, flattenTree } from "./tree.js";
8
+ import { ContentError } from "./errors.js";
9
+ // src/source/index.ts
10
+ function allPages(folder) {
11
+ return [...folder.pages, ...folder.folders.flatMap(allPages)];
12
+ }
13
+ function createSource({ dir, baseUrl = "/docs", drafts = process.env.NODE_ENV !== "production" }) {
14
+ const root = resolve(dir);
15
+ const fresh = process.env.NODE_ENV === "development";
16
+ let snapshot;
17
+ function load() {
18
+ if (snapshot && !fresh) return snapshot;
19
+ const content = scanContent(root, baseUrl, drafts);
20
+ const tree = buildTree(content);
21
+ snapshot = {
22
+ pages: allPages(content),
23
+ tree,
24
+ order: flattenTree(tree)
25
+ };
26
+ return snapshot;
27
+ }
28
+ const render = cache((path, body) => compileMdx(path, body, path.endsWith(".md") ? "md" : "mdx"));
29
+ const updated = cache((path) => {
30
+ try {
31
+ const out = execFileSync("git", [
32
+ "log",
33
+ "-1",
34
+ "--format=%cI",
35
+ "--",
36
+ join(root, path)
37
+ ], {
38
+ cwd: root,
39
+ encoding: "utf8",
40
+ stdio: [
41
+ "ignore",
42
+ "pipe",
43
+ "ignore"
44
+ ]
45
+ }).trim();
46
+ return out ? new Date(out) : void 0;
47
+ } catch {
48
+ return;
49
+ }
50
+ });
51
+ return {
52
+ /** Path the docs are served under, e.g. `/docs`. */
53
+ baseUrl,
54
+ pages() {
55
+ return load().pages.filter((page) => !page.data.external);
56
+ },
57
+ page(slugs = []) {
58
+ const key = slugs.map(decodeURIComponent).join("/");
59
+ return this.pages().find((page) => page.slugs.join("/") === key);
60
+ },
61
+ tree() {
62
+ return load().tree;
63
+ },
64
+ breadcrumbs(page) {
65
+ return findTrail(load().tree, page.url) ?? [];
66
+ },
67
+ neighbours(page) {
68
+ const order = load().order;
69
+ const index = order.findIndex((item) => item.url === page.url);
70
+ if (index < 0) return {};
71
+ const previous = order[index - 1];
72
+ const next = order[index + 1];
73
+ return {
74
+ ...previous ? { previous } : {},
75
+ ...next ? { next } : {}
76
+ };
77
+ },
78
+ params() {
79
+ return this.pages().map((page) => ({ slug: page.slugs }));
80
+ },
81
+ /**
82
+ * The page as plain Markdown for agents and `.md` exports, with its title and
83
+ * description on top. See `mdxToMarkdown` for what happens to components and code.
84
+ */
85
+ markdown(page, options = {}) {
86
+ return mdxToMarkdown(page.body, {
87
+ baseUrl,
88
+ pageUrl: page.url,
89
+ ...options,
90
+ title: page.data.title,
91
+ ...page.data.description ? { description: page.data.description } : {}
92
+ });
93
+ },
94
+ render(page) {
95
+ return render(page.path, page.body);
96
+ },
97
+ updated(page) {
98
+ return page.data.updated ?? updated(page.path);
99
+ }
100
+ };
101
+ }
102
+ export { ContentError, builtInLowerings, createSource, mdxToMarkdown };
@@ -0,0 +1,48 @@
1
+ import { PhrasingContent, RootContent } from "../node_modules/.pnpm/@types_mdast@4.0.4/node_modules/@types/mdast/index.js";
2
+ import { MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx-jsx";
3
+ import { Registry } from "../registry.js";
4
+ export type JsxElement = MdxJsxFlowElement | MdxJsxTextElement;
5
+ /** What a lowering gets besides the element: its attributes, its children and helpers. */
6
+ export type LowerContext = {
7
+ /** An attribute as written: a string, `true` for a bare one, `undefined` when missing. */
8
+ attr: (name: string) => string | true | undefined;
9
+ /** The element's children, already lowered. */
10
+ children: RootContent[];
11
+ /** Inline Markdown in a plain string, e.g. an attribute with `code` in backticks. */
12
+ inline: (text: string) => PhrasingContent[];
13
+ /** Flattens lowered children into phrasing content, e.g. for a table cell. */
14
+ phrasing: (nodes: RootContent[]) => PhrasingContent[];
15
+ /** Turns a link on the site into an absolute URL to its Markdown version. */
16
+ href: (href: string) => string;
17
+ options: MarkdownOptions;
18
+ };
19
+ /**
20
+ * Turns one MDX component into plain Markdown nodes. Return `undefined` to keep the
21
+ * element's children as they are, or an empty array to drop it.
22
+ */
23
+ export type Lowering = (element: JsxElement, context: LowerContext) => RootContent[] | undefined;
24
+ export type MarkdownOptions = {
25
+ /** Site origin, e.g. `https://docs.wrksz.dev`; makes links and images absolute. */
26
+ origin?: string;
27
+ /** Path the docs live under, e.g. `/docs`; links below it point to `.md` pages. */
28
+ baseUrl?: string;
29
+ /** Registry `<Install>` uses when it names none. */
30
+ registry?: Registry;
31
+ /** Registries `<Install registry="…">` can name. */
32
+ registries?: Record<string, Registry>;
33
+ /** Path of the page being exported, e.g. `/docs/guides`; fills `{page}` in prompts. */
34
+ pageUrl?: string;
35
+ /** Lowerings for the site's own components; they replace built-ins of the same name. */
36
+ components?: Record<string, Lowering>;
37
+ };
38
+ /** How each built-in component reads as plain Markdown. */
39
+ export declare const builtInLowerings: Record<string, Lowering>;
40
+ /**
41
+ * Turns the MDX body of a page into plain Markdown for agents and `.md` exports: components
42
+ * become the Markdown they stand for, imports and expressions go, highlighter notation is
43
+ * stripped from code, and links on the site point at Markdown pages.
44
+ */
45
+ export declare function mdxToMarkdown(body: string, { title, description, ...options }?: MarkdownOptions & {
46
+ title?: string;
47
+ description?: string;
48
+ }): string;