@takazudo/zudo-doc 0.2.0 → 0.2.2

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 (35) hide show
  1. package/README.md +53 -2
  2. package/dist/doclayout/doc-layout.js +25 -19
  3. package/dist/header/nav-active.d.ts +0 -11
  4. package/dist/header/nav-active.js +7 -2
  5. package/dist/html-preview-wrapper/html-preview-wrapper.d.ts +13 -0
  6. package/dist/html-preview-wrapper/html-preview-wrapper.js +12 -1
  7. package/dist/html-preview-wrapper/html-preview.d.ts +43 -2
  8. package/dist/html-preview-wrapper/html-preview.js +8 -2
  9. package/dist/integrations/claude-resources/generate.js +50 -54
  10. package/dist/integrations/doc-history/pre-build.d.ts +13 -5
  11. package/dist/integrations/doc-history/pre-build.js +11 -28
  12. package/dist/integrations/llms-txt/dev-middleware.d.ts +1 -0
  13. package/dist/integrations/llms-txt/emit.d.ts +1 -0
  14. package/dist/integrations/llms-txt/generate.d.ts +1 -0
  15. package/dist/integrations/llms-txt/index.d.ts +3 -2
  16. package/dist/integrations/llms-txt/load.d.ts +7 -35
  17. package/dist/integrations/llms-txt/load.js +21 -54
  18. package/dist/integrations/llms-txt/strip.d.ts +11 -9
  19. package/dist/integrations/llms-txt/strip.js +1 -3
  20. package/dist/integrations/llms-txt/types.d.ts +7 -20
  21. package/dist/integrations/search-index/collect.js +3 -2
  22. package/dist/md-utils/index.d.ts +76 -0
  23. package/dist/{integrations/search-index/content-files.js → md-utils/index.js} +12 -5
  24. package/dist/safelist.css +1 -1
  25. package/dist/sidebar-tree/category-meta.js +6 -1
  26. package/dist/theme/iframe-bridge.js +5 -3
  27. package/dist/theme/index.d.ts +2 -0
  28. package/dist/theme/theme-toggle.d.ts +7 -6
  29. package/dist/theme/theme-toggle.js +5 -81
  30. package/dist/theme-toggle/color-scheme-sync.d.ts +38 -0
  31. package/dist/theme-toggle/color-scheme-sync.js +22 -0
  32. package/dist/theme-toggle/index.d.ts +12 -0
  33. package/dist/theme-toggle/index.js +83 -0
  34. package/package.json +15 -6
  35. package/dist/integrations/search-index/content-files.d.ts +0 -42
@@ -0,0 +1,22 @@
1
+ const COLOR_SCHEME_CHANGED_EVENT = "color-scheme-changed";
2
+ const STORAGE_KEY = "zudo-doc-theme";
3
+ function readColorSchemeFromDom(defaultMode) {
4
+ const actual = document.documentElement.getAttribute("data-theme");
5
+ return actual === "light" || actual === "dark" ? actual : defaultMode;
6
+ }
7
+ function applyColorScheme(next) {
8
+ document.documentElement.setAttribute("data-theme", next);
9
+ document.documentElement.style.colorScheme = next;
10
+ localStorage.setItem(STORAGE_KEY, next);
11
+ window.dispatchEvent(new CustomEvent(COLOR_SCHEME_CHANGED_EVENT));
12
+ }
13
+ function subscribeColorSchemeChanged(listener) {
14
+ window.addEventListener(COLOR_SCHEME_CHANGED_EVENT, listener);
15
+ return () => window.removeEventListener(COLOR_SCHEME_CHANGED_EVENT, listener);
16
+ }
17
+ export {
18
+ COLOR_SCHEME_CHANGED_EVENT,
19
+ applyColorScheme,
20
+ readColorSchemeFromDom,
21
+ subscribeColorSchemeChanged
22
+ };
@@ -0,0 +1,12 @@
1
+ import * as preact from 'preact';
2
+ import { ColorSchemeMode } from './color-scheme-sync.js';
3
+
4
+ interface ThemeToggleProps {
5
+ defaultMode?: ColorSchemeMode;
6
+ }
7
+ declare function ThemeToggle({ defaultMode, }: ThemeToggleProps): preact.JSX.Element;
8
+ declare namespace ThemeToggle {
9
+ var displayName: string;
10
+ }
11
+
12
+ export { ThemeToggle, type ThemeToggleProps };
@@ -0,0 +1,83 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "preact/jsx-runtime";
3
+ import { useState, useEffect } from "preact/hooks";
4
+ import {
5
+ applyColorScheme,
6
+ readColorSchemeFromDom,
7
+ subscribeColorSchemeChanged
8
+ } from "./color-scheme-sync.js";
9
+ function SunIcon() {
10
+ return /* @__PURE__ */ jsxs(
11
+ "svg",
12
+ {
13
+ "aria-hidden": "true",
14
+ xmlns: "http://www.w3.org/2000/svg",
15
+ width: "20",
16
+ height: "20",
17
+ viewBox: "0 0 24 24",
18
+ fill: "none",
19
+ stroke: "currentColor",
20
+ strokeWidth: "2",
21
+ strokeLinecap: "round",
22
+ strokeLinejoin: "round",
23
+ children: [
24
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "5" }),
25
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "1", x2: "12", y2: "3" }),
26
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "21", x2: "12", y2: "23" }),
27
+ /* @__PURE__ */ jsx("line", { x1: "4.22", y1: "4.22", x2: "5.64", y2: "5.64" }),
28
+ /* @__PURE__ */ jsx("line", { x1: "18.36", y1: "18.36", x2: "19.78", y2: "19.78" }),
29
+ /* @__PURE__ */ jsx("line", { x1: "1", y1: "12", x2: "3", y2: "12" }),
30
+ /* @__PURE__ */ jsx("line", { x1: "21", y1: "12", x2: "23", y2: "12" }),
31
+ /* @__PURE__ */ jsx("line", { x1: "4.22", y1: "19.78", x2: "5.64", y2: "18.36" }),
32
+ /* @__PURE__ */ jsx("line", { x1: "18.36", y1: "5.64", x2: "19.78", y2: "4.22" })
33
+ ]
34
+ }
35
+ );
36
+ }
37
+ function MoonIcon() {
38
+ return /* @__PURE__ */ jsx(
39
+ "svg",
40
+ {
41
+ "aria-hidden": "true",
42
+ xmlns: "http://www.w3.org/2000/svg",
43
+ width: "20",
44
+ height: "20",
45
+ viewBox: "0 0 24 24",
46
+ fill: "none",
47
+ stroke: "currentColor",
48
+ strokeWidth: "2",
49
+ strokeLinecap: "round",
50
+ strokeLinejoin: "round",
51
+ children: /* @__PURE__ */ jsx("path", { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" })
52
+ }
53
+ );
54
+ }
55
+ function ThemeToggle({
56
+ defaultMode = "dark"
57
+ }) {
58
+ const [mode, setMode] = useState(defaultMode);
59
+ useEffect(() => {
60
+ const sync = () => setMode(readColorSchemeFromDom(defaultMode));
61
+ sync();
62
+ return subscribeColorSchemeChanged(sync);
63
+ }, []);
64
+ function toggle() {
65
+ const next = mode === "dark" ? "light" : "dark";
66
+ setMode(next);
67
+ applyColorScheme(next);
68
+ }
69
+ const nextMode = mode === "dark" ? "light" : "dark";
70
+ return /* @__PURE__ */ jsx(
71
+ "button",
72
+ {
73
+ onClick: toggle,
74
+ "aria-label": `Switch to ${nextMode} mode`,
75
+ className: "text-muted hover:text-fg transition-colors p-hsp-sm focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-2",
76
+ children: mode === "dark" ? /* @__PURE__ */ jsx(SunIcon, {}) : /* @__PURE__ */ jsx(MoonIcon, {})
77
+ }
78
+ );
79
+ }
80
+ ThemeToggle.displayName = "ThemeToggle";
81
+ export {
82
+ ThemeToggle
83
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takazudo/zudo-doc",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "description": "zudo-doc framework primitives layer that sits on top of zfb's engine — sidebar, theme, TOC, breadcrumb, layouts, head injection, View Transitions, SSR-skip wrappers (per ADR-003).",
6
6
  "license": "MIT",
@@ -43,6 +43,10 @@
43
43
  "types": "./dist/theme/color-scheme-provider.d.ts",
44
44
  "default": "./dist/theme/color-scheme-provider.js"
45
45
  },
46
+ "./theme-toggle": {
47
+ "types": "./dist/theme-toggle/index.d.ts",
48
+ "default": "./dist/theme-toggle/index.js"
49
+ },
46
50
  "./toc": {
47
51
  "types": "./dist/toc/index.d.ts",
48
52
  "default": "./dist/toc/index.js"
@@ -160,10 +164,11 @@
160
164
  ],
161
165
  "peerDependencies": {
162
166
  "preact": "^10.29.1",
163
- "@takazudo/zfb": "^0.1.0-next.35",
164
- "@takazudo/zfb-runtime": "^0.1.0-next.35",
167
+ "@takazudo/zfb": "^0.1.0-next.38",
168
+ "@takazudo/zfb-runtime": "^0.1.0-next.38",
165
169
  "@takazudo/zdtp": "^0.2.0-next.2",
166
- "@takazudo/zudo-doc-history-server": "^0.2.0"
170
+ "shiki": "^4.0.2",
171
+ "@takazudo/zudo-doc-history-server": "^0.2.2"
167
172
  },
168
173
  "peerDependenciesMeta": {
169
174
  "@takazudo/zudo-doc-history-server": {
@@ -171,6 +176,9 @@
171
176
  },
172
177
  "@takazudo/zdtp": {
173
178
  "optional": true
179
+ },
180
+ "shiki": {
181
+ "optional": true
174
182
  }
175
183
  },
176
184
  "dependencies": {
@@ -181,11 +189,12 @@
181
189
  "cross-env": "^7.0.3",
182
190
  "preact": "^10.29.1",
183
191
  "preact-render-to-string": "^6.6.6",
192
+ "shiki": "^4.0.2",
184
193
  "tsup": "^8.0.0",
185
194
  "typescript": "^5.0.0",
186
195
  "vitest": "^4.1.0",
187
- "@takazudo/zfb": "0.1.0-next.35",
188
- "@takazudo/zfb-runtime": "0.1.0-next.35"
196
+ "@takazudo/zfb": "0.1.0-next.38",
197
+ "@takazudo/zfb-runtime": "0.1.0-next.38"
189
198
  },
190
199
  "scripts": {
191
200
  "build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 tsup",
@@ -1,42 +0,0 @@
1
- /**
2
- * Strip markdown formatting to plain text. Conservative-by-design — the
3
- * regex pipeline is identical to today's Astro integration so search
4
- * excerpts stay byte-equal across the cutover. Do not add new rules
5
- * without also updating the byte-equality fixtures (topic-plugin-audit).
6
- */
7
- declare function stripMarkdown(md: string): string;
8
- /** Walk a directory recursively and collect all `.md`/`.mdx` files. */
9
- declare function collectMdFiles(dir: string): Array<{
10
- filePath: string;
11
- slug: string;
12
- }>;
13
- /** Compute the site-relative URL for a slug + locale, honouring `base`. */
14
- declare function slugToUrl(slug: string, locale: string | null, base: string): string;
15
- /** Frontmatter fields the integration cares about. Extra keys pass through. */
16
- interface DocFrontmatter {
17
- title?: string;
18
- description?: string;
19
- draft?: boolean;
20
- unlisted?: boolean;
21
- search_exclude?: boolean;
22
- /**
23
- * A `category_no_page` index.mdx carries category metadata only and builds
24
- * no route — so its slug must NOT enter the search index (the result link
25
- * would 404). Mirrors the route/sitemap exclusion in the host project.
26
- */
27
- category_no_page?: boolean;
28
- [key: string]: unknown;
29
- }
30
- /** Parse a markdown file. Returns null when the file cannot be read. */
31
- declare function parseMarkdownFile(filePath: string): {
32
- data: DocFrontmatter;
33
- content: string;
34
- } | null;
35
- /**
36
- * A page is excluded from indexing when explicitly opted out, drafted,
37
- * unlisted, or a `category_no_page` metadata-only category index (no built
38
- * route to link to).
39
- */
40
- declare function isExcluded(data: DocFrontmatter): boolean;
41
-
42
- export { type DocFrontmatter, collectMdFiles, isExcluded, parseMarkdownFile, slugToUrl, stripMarkdown };