@takazudo/zudo-doc 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 (255) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +18 -0
  3. package/dist/body-foot-util/body-foot-util-area.d.ts +55 -0
  4. package/dist/body-foot-util/body-foot-util-area.js +71 -0
  5. package/dist/body-foot-util/edit-link.d.ts +45 -0
  6. package/dist/body-foot-util/edit-link.js +42 -0
  7. package/dist/body-foot-util/index.d.ts +3 -0
  8. package/dist/body-foot-util/index.js +11 -0
  9. package/dist/breadcrumb/breadcrumb.d.ts +57 -0
  10. package/dist/breadcrumb/breadcrumb.js +113 -0
  11. package/dist/breadcrumb/find-path.d.ts +16 -0
  12. package/dist/breadcrumb/find-path.js +13 -0
  13. package/dist/breadcrumb/index.d.ts +4 -0
  14. package/dist/breadcrumb/index.js +7 -0
  15. package/dist/breadcrumb/types.d.ts +32 -0
  16. package/dist/breadcrumb/types.js +0 -0
  17. package/dist/code-syntax/code-block-enhancer-script.d.ts +3 -0
  18. package/dist/code-syntax/code-block-enhancer-script.js +165 -0
  19. package/dist/code-syntax/code-block-enhancer.d.ts +22 -0
  20. package/dist/code-syntax/code-block-enhancer.js +13 -0
  21. package/dist/code-syntax/index.d.ts +8 -0
  22. package/dist/code-syntax/index.js +29 -0
  23. package/dist/code-syntax/mermaid-init-script.d.ts +51 -0
  24. package/dist/code-syntax/mermaid-init-script.js +225 -0
  25. package/dist/code-syntax/mermaid-init.d.ts +48 -0
  26. package/dist/code-syntax/mermaid-init.js +14 -0
  27. package/dist/code-syntax/tabs-init-script.d.ts +3 -0
  28. package/dist/code-syntax/tabs-init-script.js +106 -0
  29. package/dist/code-syntax/tabs-init.d.ts +24 -0
  30. package/dist/code-syntax/tabs-init.js +10 -0
  31. package/dist/code-syntax/tabs.d.ts +36 -0
  32. package/dist/code-syntax/tabs.js +62 -0
  33. package/dist/content/component-map.d.ts +51 -0
  34. package/dist/content/component-map.js +29 -0
  35. package/dist/content/content-blockquote.d.ts +11 -0
  36. package/dist/content/content-blockquote.js +14 -0
  37. package/dist/content/content-code.d.ts +26 -0
  38. package/dist/content/content-code.js +39 -0
  39. package/dist/content/content-link.d.ts +12 -0
  40. package/dist/content/content-link.js +43 -0
  41. package/dist/content/content-ol.d.ts +11 -0
  42. package/dist/content/content-ol.js +15 -0
  43. package/dist/content/content-paragraph.d.ts +10 -0
  44. package/dist/content/content-paragraph.js +7 -0
  45. package/dist/content/content-strong.d.ts +11 -0
  46. package/dist/content/content-strong.js +14 -0
  47. package/dist/content/content-table.d.ts +11 -0
  48. package/dist/content/content-table.js +14 -0
  49. package/dist/content/content-ul.d.ts +11 -0
  50. package/dist/content/content-ul.js +15 -0
  51. package/dist/content/heading-h2.d.ts +14 -0
  52. package/dist/content/heading-h2.js +18 -0
  53. package/dist/content/heading-h3.d.ts +14 -0
  54. package/dist/content/heading-h3.js +18 -0
  55. package/dist/content/heading-h4.d.ts +14 -0
  56. package/dist/content/heading-h4.js +18 -0
  57. package/dist/content/index.d.ts +13 -0
  58. package/dist/content/index.js +27 -0
  59. package/dist/details/details.d.ts +26 -0
  60. package/dist/details/details.js +10 -0
  61. package/dist/details/index.d.ts +2 -0
  62. package/dist/details/index.js +4 -0
  63. package/dist/doclayout/anchors.d.ts +55 -0
  64. package/dist/doclayout/anchors.js +42 -0
  65. package/dist/doclayout/doc-layout-with-defaults.d.ts +83 -0
  66. package/dist/doclayout/doc-layout-with-defaults.js +159 -0
  67. package/dist/doclayout/doc-layout.d.ts +121 -0
  68. package/dist/doclayout/doc-layout.js +89 -0
  69. package/dist/doclayout/index.d.ts +6 -0
  70. package/dist/doclayout/index.js +17 -0
  71. package/dist/footer/footer.d.ts +42 -0
  72. package/dist/footer/footer.js +79 -0
  73. package/dist/footer/index.d.ts +3 -0
  74. package/dist/footer/index.js +4 -0
  75. package/dist/footer/types.d.ts +58 -0
  76. package/dist/footer/types.js +0 -0
  77. package/dist/head/doc-head.d.ts +33 -0
  78. package/dist/head/doc-head.js +90 -0
  79. package/dist/head/index.d.ts +5 -0
  80. package/dist/head/index.js +8 -0
  81. package/dist/head/og-tags.d.ts +25 -0
  82. package/dist/head/og-tags.js +16 -0
  83. package/dist/head/twitter-card.d.ts +21 -0
  84. package/dist/head/twitter-card.js +14 -0
  85. package/dist/head/types.d.ts +83 -0
  86. package/dist/head/types.js +0 -0
  87. package/dist/header/header.d.ts +158 -0
  88. package/dist/header/header.js +367 -0
  89. package/dist/header/index.d.ts +6 -0
  90. package/dist/header/index.js +18 -0
  91. package/dist/header/nav-active.d.ts +39 -0
  92. package/dist/header/nav-active.js +24 -0
  93. package/dist/header/nav-overflow-script.d.ts +3 -0
  94. package/dist/header/nav-overflow-script.js +169 -0
  95. package/dist/header/right-items.d.ts +38 -0
  96. package/dist/header/right-items.js +30 -0
  97. package/dist/header/types.d.ts +40 -0
  98. package/dist/header/types.js +0 -0
  99. package/dist/html-preview-wrapper/dedent.d.ts +10 -0
  100. package/dist/html-preview-wrapper/dedent.js +16 -0
  101. package/dist/html-preview-wrapper/highlighted-code.d.ts +18 -0
  102. package/dist/html-preview-wrapper/highlighted-code.js +53 -0
  103. package/dist/html-preview-wrapper/html-preview-wrapper.d.ts +60 -0
  104. package/dist/html-preview-wrapper/html-preview-wrapper.js +36 -0
  105. package/dist/html-preview-wrapper/html-preview.d.ts +35 -0
  106. package/dist/html-preview-wrapper/html-preview.js +75 -0
  107. package/dist/html-preview-wrapper/index.d.ts +5 -0
  108. package/dist/html-preview-wrapper/index.js +12 -0
  109. package/dist/html-preview-wrapper/preflight.d.ts +13 -0
  110. package/dist/html-preview-wrapper/preflight.js +108 -0
  111. package/dist/html-preview-wrapper/preview-base.d.ts +29 -0
  112. package/dist/html-preview-wrapper/preview-base.js +127 -0
  113. package/dist/i18n-version/index.d.ts +5 -0
  114. package/dist/i18n-version/index.js +14 -0
  115. package/dist/i18n-version/language-switcher.d.ts +24 -0
  116. package/dist/i18n-version/language-switcher.js +25 -0
  117. package/dist/i18n-version/types.d.ts +43 -0
  118. package/dist/i18n-version/types.js +0 -0
  119. package/dist/i18n-version/version-banner.d.ts +30 -0
  120. package/dist/i18n-version/version-banner.js +21 -0
  121. package/dist/i18n-version/version-switcher.d.ts +112 -0
  122. package/dist/i18n-version/version-switcher.js +157 -0
  123. package/dist/index.d.ts +2 -0
  124. package/dist/index.js +0 -0
  125. package/dist/integrations/claude-resources/escape-for-mdx.d.ts +8 -0
  126. package/dist/integrations/claude-resources/escape-for-mdx.js +131 -0
  127. package/dist/integrations/claude-resources/generate.d.ts +13 -0
  128. package/dist/integrations/claude-resources/generate.js +404 -0
  129. package/dist/integrations/claude-resources/index.d.ts +46 -0
  130. package/dist/integrations/claude-resources/index.js +24 -0
  131. package/dist/integrations/doc-history/index.d.ts +137 -0
  132. package/dist/integrations/doc-history/index.js +138 -0
  133. package/dist/integrations/doc-history/pre-build.d.ts +58 -0
  134. package/dist/integrations/doc-history/pre-build.js +67 -0
  135. package/dist/integrations/llms-txt/dev-middleware.d.ts +40 -0
  136. package/dist/integrations/llms-txt/dev-middleware.js +76 -0
  137. package/dist/integrations/llms-txt/emit.d.ts +22 -0
  138. package/dist/integrations/llms-txt/emit.js +55 -0
  139. package/dist/integrations/llms-txt/generate.d.ts +26 -0
  140. package/dist/integrations/llms-txt/generate.js +36 -0
  141. package/dist/integrations/llms-txt/index.d.ts +7 -0
  142. package/dist/integrations/llms-txt/index.js +27 -0
  143. package/dist/integrations/llms-txt/load.d.ts +51 -0
  144. package/dist/integrations/llms-txt/load.js +83 -0
  145. package/dist/integrations/llms-txt/strip.d.ts +22 -0
  146. package/dist/integrations/llms-txt/strip.js +10 -0
  147. package/dist/integrations/llms-txt/types.d.ts +145 -0
  148. package/dist/integrations/llms-txt/types.js +0 -0
  149. package/dist/integrations/search-index/build-emitter.d.ts +30 -0
  150. package/dist/integrations/search-index/build-emitter.js +15 -0
  151. package/dist/integrations/search-index/collect.d.ts +12 -0
  152. package/dist/integrations/search-index/collect.js +48 -0
  153. package/dist/integrations/search-index/content-files.d.ts +32 -0
  154. package/dist/integrations/search-index/content-files.js +50 -0
  155. package/dist/integrations/search-index/dev-middleware.d.ts +16 -0
  156. package/dist/integrations/search-index/dev-middleware.js +30 -0
  157. package/dist/integrations/search-index/index.d.ts +5 -0
  158. package/dist/integrations/search-index/index.js +14 -0
  159. package/dist/integrations/search-index/types.d.ts +38 -0
  160. package/dist/integrations/search-index/types.js +6 -0
  161. package/dist/metainfo/doc-metainfo.d.ts +50 -0
  162. package/dist/metainfo/doc-metainfo.js +107 -0
  163. package/dist/metainfo/doc-tags.d.ts +66 -0
  164. package/dist/metainfo/doc-tags.js +53 -0
  165. package/dist/metainfo/frontmatter-preview.d.ts +95 -0
  166. package/dist/metainfo/frontmatter-preview.js +55 -0
  167. package/dist/metainfo/index.d.ts +4 -0
  168. package/dist/metainfo/index.js +28 -0
  169. package/dist/nav-indexing/category-nav.d.ts +28 -0
  170. package/dist/nav-indexing/category-nav.js +41 -0
  171. package/dist/nav-indexing/category-tree-nav.d.ts +27 -0
  172. package/dist/nav-indexing/category-tree-nav.js +49 -0
  173. package/dist/nav-indexing/doc-card-grid.d.ts +38 -0
  174. package/dist/nav-indexing/doc-card-grid.js +40 -0
  175. package/dist/nav-indexing/docs-sitemap.d.ts +25 -0
  176. package/dist/nav-indexing/docs-sitemap.js +40 -0
  177. package/dist/nav-indexing/index.d.ts +10 -0
  178. package/dist/nav-indexing/index.js +18 -0
  179. package/dist/nav-indexing/nav-card-grid.d.ts +31 -0
  180. package/dist/nav-indexing/nav-card-grid.js +43 -0
  181. package/dist/nav-indexing/site-tree-nav-demo.d.ts +39 -0
  182. package/dist/nav-indexing/site-tree-nav-demo.js +65 -0
  183. package/dist/nav-indexing/tag-nav.d.ts +38 -0
  184. package/dist/nav-indexing/tag-nav.js +96 -0
  185. package/dist/nav-indexing/types.d.ts +95 -0
  186. package/dist/nav-indexing/types.js +0 -0
  187. package/dist/nav-indexing/versions-page-content.d.ts +29 -0
  188. package/dist/nav-indexing/versions-page-content.js +76 -0
  189. package/dist/page-loading/index.d.ts +2 -0
  190. package/dist/page-loading/index.js +10 -0
  191. package/dist/page-loading/page-loading-overlay.d.ts +35 -0
  192. package/dist/page-loading/page-loading-overlay.js +50 -0
  193. package/dist/sidebar/index.d.ts +3 -0
  194. package/dist/sidebar/index.js +4 -0
  195. package/dist/sidebar/sidebar.d.ts +54 -0
  196. package/dist/sidebar/sidebar.js +35 -0
  197. package/dist/sidebar/types.d.ts +71 -0
  198. package/dist/sidebar/types.js +0 -0
  199. package/dist/sidebar-resizer/index.d.ts +14 -0
  200. package/dist/sidebar-resizer/index.js +165 -0
  201. package/dist/sidebar-resizer/sidebar-resizer-init.d.ts +20 -0
  202. package/dist/sidebar-resizer/sidebar-resizer-init.js +119 -0
  203. package/dist/sidebar-tree/build-tree.d.ts +43 -0
  204. package/dist/sidebar-tree/build-tree.js +127 -0
  205. package/dist/sidebar-tree/category-meta.d.ts +19 -0
  206. package/dist/sidebar-tree/category-meta.js +63 -0
  207. package/dist/sidebar-tree/index.d.ts +3 -0
  208. package/dist/sidebar-tree/index.js +13 -0
  209. package/dist/sidebar-tree/types.d.ts +120 -0
  210. package/dist/sidebar-tree/types.js +0 -0
  211. package/dist/tab-item/index.d.ts +2 -0
  212. package/dist/tab-item/index.js +5 -0
  213. package/dist/tab-item/tab-item.d.ts +38 -0
  214. package/dist/tab-item/tab-item.js +25 -0
  215. package/dist/theme/color-scheme-provider.d.ts +32 -0
  216. package/dist/theme/color-scheme-provider.js +43 -0
  217. package/dist/theme/color-tweak-export-modal.d.ts +20 -0
  218. package/dist/theme/color-tweak-export-modal.js +138 -0
  219. package/dist/theme/design-token-serde.d.ts +136 -0
  220. package/dist/theme/design-token-serde.js +254 -0
  221. package/dist/theme/design-token-tweak-panel.d.ts +11 -0
  222. package/dist/theme/design-token-tweak-panel.js +10 -0
  223. package/dist/theme/design-token-types.d.ts +19 -0
  224. package/dist/theme/design-token-types.js +6 -0
  225. package/dist/theme/iframe-bridge.d.ts +44 -0
  226. package/dist/theme/iframe-bridge.js +70 -0
  227. package/dist/theme/index.d.ts +9 -0
  228. package/dist/theme/index.js +42 -0
  229. package/dist/theme/theme-toggle.d.ts +17 -0
  230. package/dist/theme/theme-toggle.js +91 -0
  231. package/dist/toc/cx.d.ts +16 -0
  232. package/dist/toc/cx.js +22 -0
  233. package/dist/toc/index.d.ts +5 -0
  234. package/dist/toc/index.js +9 -0
  235. package/dist/toc/mobile-toc.d.ts +46 -0
  236. package/dist/toc/mobile-toc.js +88 -0
  237. package/dist/toc/smart-break.d.ts +27 -0
  238. package/dist/toc/smart-break.js +36 -0
  239. package/dist/toc/toc-title.d.ts +10 -0
  240. package/dist/toc/toc-title.js +14 -0
  241. package/dist/toc/toc.d.ts +60 -0
  242. package/dist/toc/toc.js +56 -0
  243. package/dist/toc/types.d.ts +23 -0
  244. package/dist/toc/types.js +0 -0
  245. package/dist/toc/use-active-heading.d.ts +30 -0
  246. package/dist/toc/use-active-heading.js +106 -0
  247. package/dist/transitions/index.d.ts +1 -0
  248. package/dist/transitions/index.js +12 -0
  249. package/dist/transitions/page-events.d.ts +41 -0
  250. package/dist/transitions/page-events.js +20 -0
  251. package/dist/url-normalizer/index.d.ts +1 -0
  252. package/dist/url-normalizer/index.js +6 -0
  253. package/dist/url-normalizer/normalize.d.ts +104 -0
  254. package/dist/url-normalizer/normalize.js +22 -0
  255. package/package.json +186 -0
@@ -0,0 +1,165 @@
1
+ import {
2
+ AFTER_NAVIGATE_EVENT,
3
+ BEFORE_NAVIGATE_EVENT
4
+ } from "../transitions/page-events.js";
5
+ const CODE_BLOCK_ENHANCER_SCRIPT = `(function () {
6
+ // Single shared ResizeObserver for all code blocks on the page.
7
+ var wrapButtons = new Map();
8
+ var resizeObserver = new ResizeObserver(function (entries) {
9
+ for (var i = 0; i < entries.length; i++) {
10
+ var btn = wrapButtons.get(entries[i].target);
11
+ if (btn) updateWrapVisibility(entries[i].target, btn);
12
+ }
13
+ });
14
+
15
+ function enhanceCodeBlocks() {
16
+ // Selector covers two shapes:
17
+ // 1. pre.syntect-... from the syntect highlighter (the class
18
+ // is anchored or merged with other classes).
19
+ // 2. bare pre inside .tab-panel (TabItem) wrappers where some
20
+ // pipelines emit class-less pre elements.
21
+ // No backticks in this comment: this whole script body lives inside
22
+ // a template literal in the host .ts module, so an inline backtick
23
+ // would close the literal and make 'panel' a free identifier.
24
+ var pres = document.querySelectorAll(
25
+ 'pre[class*="syntect-"], .tab-panel pre',
26
+ );
27
+
28
+ for (var pi = 0; pi < pres.length; pi++) {
29
+ var pre = pres[pi];
30
+ if (pre.dataset.enhanced) continue;
31
+ pre.dataset.enhanced = "true";
32
+
33
+ var codeEl = pre.querySelector("code");
34
+ if (!codeEl) continue;
35
+ var rawCode = codeEl.textContent || "";
36
+
37
+ // Wrap <pre> in a container so buttons stay fixed during horizontal scroll.
38
+ var wrapper = document.createElement("div");
39
+ wrapper.className = "code-block-wrapper";
40
+ var parent = pre.parentNode;
41
+ if (!parent) continue;
42
+ parent.insertBefore(wrapper, pre);
43
+ wrapper.appendChild(pre);
44
+
45
+ // Button group (appended to wrapper, not pre).
46
+ var group = document.createElement("div");
47
+ group.className = "code-buttons";
48
+
49
+ // Word wrap toggle (only shown when content overflows).
50
+ var wrapBtn = createWrapButton(pre);
51
+ group.appendChild(wrapBtn);
52
+
53
+ // Copy button.
54
+ var copyBtn = createCopyButton(rawCode);
55
+ group.appendChild(copyBtn);
56
+
57
+ wrapper.appendChild(group);
58
+
59
+ // Track and observe for overflow changes.
60
+ wrapButtons.set(pre, wrapBtn);
61
+ updateWrapVisibility(pre, wrapBtn);
62
+ resizeObserver.observe(pre);
63
+ }
64
+ }
65
+
66
+ function createCopyButton(code) {
67
+ var btn = document.createElement("button");
68
+ btn.type = "button";
69
+ btn.className = "code-btn code-btn-copy";
70
+ btn.setAttribute("aria-label", "Copy code");
71
+ btn.innerHTML =
72
+ '<svg class="code-icon code-icon-copy" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
73
+ '<rect x="9" y="9" width="13" height="13" rx="2" ry="2"/>' +
74
+ '<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>' +
75
+ '</svg>' +
76
+ '<svg class="code-icon code-icon-check" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
77
+ '<polyline points="20 6 9 17 4 12"/>' +
78
+ '</svg>';
79
+
80
+ var copyTimeout;
81
+ var announce = document.querySelector(".code-block-sr-announce");
82
+
83
+ btn.addEventListener("click", async function () {
84
+ var success = true;
85
+ try {
86
+ await navigator.clipboard.writeText(code);
87
+ } catch (_) {
88
+ // Fallback for older browsers.
89
+ var textarea = document.createElement("textarea");
90
+ textarea.value = code;
91
+ textarea.style.cssText = "position:fixed;opacity:0;pointer-events:none";
92
+ document.body.appendChild(textarea);
93
+ textarea.select();
94
+ success = document.execCommand("copy");
95
+ document.body.removeChild(textarea);
96
+ }
97
+ if (success) {
98
+ btn.classList.add("copied");
99
+ if (announce) announce.textContent = "Copied!";
100
+ clearTimeout(copyTimeout);
101
+ copyTimeout = setTimeout(function () {
102
+ btn.classList.remove("copied");
103
+ if (announce) announce.textContent = "";
104
+ }, 1500);
105
+ }
106
+ });
107
+
108
+ return btn;
109
+ }
110
+
111
+ function createWrapButton(pre) {
112
+ var btn = document.createElement("button");
113
+ btn.type = "button";
114
+ btn.className = "code-btn code-btn-wrap";
115
+ btn.setAttribute("aria-label", "Toggle word wrap");
116
+ btn.setAttribute("aria-pressed", "false");
117
+ btn.innerHTML =
118
+ '<svg class="code-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
119
+ '<polyline points="17 10 21 6 17 2" />' +
120
+ '<path d="M3 6h18" />' +
121
+ '<path d="M21 18H7" />' +
122
+ '<polyline points="11 22 7 18 11 14" />' +
123
+ '</svg>';
124
+
125
+ btn.addEventListener("click", function () {
126
+ var isWrapped = pre.classList.toggle("word-wrap");
127
+ btn.classList.toggle("active", isWrapped);
128
+ btn.setAttribute("aria-pressed", String(isWrapped));
129
+ });
130
+
131
+ return btn;
132
+ }
133
+
134
+ function updateWrapVisibility(pre, btn) {
135
+ // Keep visible when active (user needs to toggle back).
136
+ var isActive = btn.classList.contains("active");
137
+ btn.style.display = isActive || pre.scrollWidth > pre.clientWidth ? "" : "none";
138
+ }
139
+
140
+ // Clean up stale references before navigating away. Under zfb's
141
+ // Strategy B SPA navigation the body is replaced in place (head and
142
+ // html survive), so the OLD pre nodes the ResizeObserver was watching
143
+ // go away \u2014 unobserve them so the observer doesn't keep detached
144
+ // references, then clear the wrapButtons Map so the next
145
+ // enhanceCodeBlocks pass can repopulate it cleanly.
146
+ document.addEventListener(${JSON.stringify(BEFORE_NAVIGATE_EVENT)}, function () {
147
+ wrapButtons.forEach(function (_btn, el) {
148
+ resizeObserver.unobserve(el);
149
+ });
150
+ wrapButtons.clear();
151
+ });
152
+
153
+ // Run on initial load.
154
+ enhanceCodeBlocks();
155
+
156
+ // Re-run after every page-navigate-end signal (zfb:after-swap under
157
+ // Strategy B SPA navigation). The IIFE itself only runs on the first
158
+ // load \u2014 zfb's deselectScripts marks identical inline scripts in
159
+ // the new body as already-executed \u2014 so this listener is the path
160
+ // by which the new body's <pre> elements get enhanced.
161
+ document.addEventListener(${JSON.stringify(AFTER_NAVIGATE_EVENT)}, enhanceCodeBlocks);
162
+ })();`;
163
+ export {
164
+ CODE_BLOCK_ENHANCER_SCRIPT
165
+ };
@@ -0,0 +1,22 @@
1
+ import { JSX } from 'preact';
2
+
3
+ /** @jsxRuntime automatic */
4
+ /** @jsxImportSource preact */
5
+
6
+ /**
7
+ * Drop-in JSX replacement for `src/components/code-block-enhancer.astro`.
8
+ *
9
+ * Include **once** in the layout. Renders the screen-reader announce region
10
+ * and emits the code-block enhancer init script via `dangerouslySetInnerHTML`.
11
+ *
12
+ * The script:
13
+ * - Wraps each `<pre class="syntect-*">` in a `.code-block-wrapper` container.
14
+ * - Adds a copy-to-clipboard button and a word-wrap toggle button.
15
+ * - Observes resize events to hide the wrap button when content fits.
16
+ * - Handles before-navigate cleanup and after-navigate re-init for View
17
+ * Transitions. Event names come from `BEFORE_NAVIGATE_EVENT` /
18
+ * `AFTER_NAVIGATE_EVENT` in `../transitions/page-events.ts`.
19
+ */
20
+ declare function CodeBlockEnhancer(): JSX.Element;
21
+
22
+ export { CodeBlockEnhancer, CodeBlockEnhancer as default };
@@ -0,0 +1,13 @@
1
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
2
+ import { CODE_BLOCK_ENHANCER_SCRIPT } from "./code-block-enhancer-script.js";
3
+ function CodeBlockEnhancer() {
4
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
5
+ /* @__PURE__ */ jsx("div", { class: "code-block-sr-announce", "aria-live": "polite" }),
6
+ /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: CODE_BLOCK_ENHANCER_SCRIPT } })
7
+ ] });
8
+ }
9
+ var code_block_enhancer_default = CodeBlockEnhancer;
10
+ export {
11
+ CodeBlockEnhancer,
12
+ code_block_enhancer_default as default
13
+ };
@@ -0,0 +1,8 @@
1
+ export { CodeBlockEnhancer, CodeBlockEnhancer as CodeBlockEnhancerDefault } from './code-block-enhancer.js';
2
+ export { CODE_BLOCK_ENHANCER_SCRIPT } from './code-block-enhancer-script.js';
3
+ export { MermaidInit, MermaidInit as MermaidInitDefault, MermaidInitProps } from './mermaid-init.js';
4
+ export { MERMAID_CDN_MODULE_URL, MERMAID_INIT_SCRIPT, buildMermaidInitScript } from './mermaid-init-script.js';
5
+ export { Tabs, Tabs as TabsDefault, TabsProps } from './tabs.js';
6
+ export { TabsInit, TabsInit as TabsInitDefault } from './tabs-init.js';
7
+ export { TABS_INIT_SCRIPT } from './tabs-init-script.js';
8
+ import 'preact';
@@ -0,0 +1,29 @@
1
+ import { CodeBlockEnhancer, default as default2 } from "./code-block-enhancer.js";
2
+ import { CODE_BLOCK_ENHANCER_SCRIPT } from "./code-block-enhancer-script.js";
3
+ import {
4
+ MermaidInit,
5
+ default as default3
6
+ } from "./mermaid-init.js";
7
+ import {
8
+ MERMAID_INIT_SCRIPT,
9
+ MERMAID_CDN_MODULE_URL,
10
+ buildMermaidInitScript
11
+ } from "./mermaid-init-script.js";
12
+ import { Tabs, default as default4 } from "./tabs.js";
13
+ import { TabsInit, default as default5 } from "./tabs-init.js";
14
+ import { TABS_INIT_SCRIPT } from "./tabs-init-script.js";
15
+ export {
16
+ CODE_BLOCK_ENHANCER_SCRIPT,
17
+ CodeBlockEnhancer,
18
+ default2 as CodeBlockEnhancerDefault,
19
+ MERMAID_CDN_MODULE_URL,
20
+ MERMAID_INIT_SCRIPT,
21
+ MermaidInit,
22
+ default3 as MermaidInitDefault,
23
+ TABS_INIT_SCRIPT,
24
+ Tabs,
25
+ default4 as TabsDefault,
26
+ TabsInit,
27
+ default5 as TabsInitDefault,
28
+ buildMermaidInitScript
29
+ };
@@ -0,0 +1,51 @@
1
+ /**
2
+ * ESM CDN URL the inline init script imports `mermaid` from. esm.sh
3
+ * resolves npm package specifiers to publishable ESM modules.
4
+ *
5
+ * Pinned to a specific minor.patch (not the bare `@11` major) so the
6
+ * runtime version is byte-stable across deploys; floating on the major
7
+ * would silently pull in upstream theme-API or behaviour changes the
8
+ * SSR-time mermaid in package.json hasn't been pinned to. Bump policy:
9
+ * raise this string in the same PR that bumps `mermaid` in
10
+ * package.json so the SSR-time and runtime mermaid versions stay
11
+ * matched. Cross-major jumps need an extra parity smoke (`pnpm build`
12
+ * and a manual diagram render) since esm.sh's exports drift between
13
+ * majors.
14
+ *
15
+ * Exported (rather than baked into the template) so consumers and
16
+ * tests can override the URL — e.g. self-hosted mirrors, version-
17
+ * locked deployments — without re-templating the whole script.
18
+ */
19
+ declare const MERMAID_CDN_MODULE_URL = "https://esm.sh/mermaid@11.4.1";
20
+ /**
21
+ * Build the inline init script with a caller-supplied module URL.
22
+ *
23
+ * Why a builder (vs. just exporting `MERMAID_INIT_SCRIPT`): the
24
+ * constant interpolates `MERMAID_CDN_MODULE_URL` at module-load time,
25
+ * so reassigning the exported binding has no runtime effect — ESM
26
+ * exports are read-only and the script string is already frozen by
27
+ * the time consumers see it. Hosts that need a self-hosted /
28
+ * version-pinned / CSP-allowlisted mermaid URL call this builder
29
+ * with their URL and pass the result to `<MermaidInit script={…}/>`
30
+ * (or to their own `<script dangerouslySetInnerHTML>` site).
31
+ *
32
+ * The default-URL flow stays available via `MERMAID_INIT_SCRIPT`
33
+ * (built once below by calling this builder with
34
+ * `MERMAID_CDN_MODULE_URL`) so existing callers keep working
35
+ * unchanged.
36
+ */
37
+ declare function buildMermaidInitScript(cdnUrl: string): string;
38
+ /**
39
+ * Default-URL init script. Built once at module load by passing
40
+ * `MERMAID_CDN_MODULE_URL` to `buildMermaidInitScript`. Kept as the
41
+ * primary export for backward compatibility — `<MermaidInit/>` (no
42
+ * props) and any direct consumer that grabs this string both end up
43
+ * importing mermaid from `https://esm.sh/mermaid@11`.
44
+ *
45
+ * For a custom URL (self-hosted mirror, version-pinned package,
46
+ * CSP-allowlisted host) call `buildMermaidInitScript(yourUrl)` and
47
+ * pass the result to `<MermaidInit script={…}/>`.
48
+ */
49
+ declare const MERMAID_INIT_SCRIPT: string;
50
+
51
+ export { MERMAID_CDN_MODULE_URL, MERMAID_INIT_SCRIPT, buildMermaidInitScript };
@@ -0,0 +1,225 @@
1
+ import { AFTER_NAVIGATE_EVENT } from "../transitions/page-events.js";
2
+ const MERMAID_CDN_MODULE_URL = "https://esm.sh/mermaid@11.4.1";
3
+ function buildMermaidInitScript(cdnUrl) {
4
+ const safeUrlLiteral = JSON.stringify(cdnUrl).replace(
5
+ /<\/(script)/gi,
6
+ "<\\/$1"
7
+ );
8
+ return `(function () {
9
+ /**
10
+ * Syntactically pick the matching arg from a CSS \`light-dark(a, b)\`
11
+ * value, based on the active theme attribute on \`:root\`.
12
+ *
13
+ * zudolab/zudo-doc#1458: mermaid 11.4.1 ships khroma 2.1.0, which
14
+ * does not understand the CSS \`light-dark()\` function. CSS custom
15
+ * properties on \`:root\` are written as \`light-dark(#hex-light,
16
+ * #hex-dark)\` when colorMode is configured (see
17
+ * \`generateLightDarkCssProperties\` in
18
+ * \`src/config/color-scheme-utils.ts\`), and \`getPropertyValue\`
19
+ * returns them as the literal string. The earlier resolveColor
20
+ * temp-element trick \u2014 assigning the value to \`el.style.color\` and
21
+ * reading \`getComputedStyle\` \u2014 was unreliable in production
22
+ * (depends on browser \`light-dark()\` support and on
23
+ * \`color-scheme\` propagating to the temp element), so we parse
24
+ * the function syntactically here.
25
+ *
26
+ * Returns the picked hex on success, or \`null\` if the input is not
27
+ * a \`light-dark(...)\` value (caller falls back to resolveColor for
28
+ * \`oklch(...)\`, \`rgb(...)\`, etc.). When the theme attribute is
29
+ * missing \u2014 first paint before the color-scheme bootstrap runs, or
30
+ * a host that does not configure colorMode \u2014 returns the light arg
31
+ * as a deterministic default.
32
+ */
33
+ function parseLightDark(raw, theme) {
34
+ if (!raw) return null;
35
+ var m = raw.match(/^\\s*light-dark\\s*\\(\\s*([^,]+?)\\s*,\\s*([^)]+?)\\s*\\)\\s*$/);
36
+ if (!m) return null;
37
+ return theme === "dark" ? m[2] : m[1];
38
+ }
39
+
40
+ /**
41
+ * Resolve a CSS value to a hex color (#rrggbb).
42
+ * CSS custom properties return raw values from getComputedStyle (e.g.
43
+ * "light-dark(#fff, #000)") which mermaid cannot parse. This uses a
44
+ * temporary element so the browser resolves any CSS function to a
45
+ * concrete rgb() value, then converts it to hex.
46
+ *
47
+ * \`light-dark(...)\` is now handled syntactically in
48
+ * \`parseLightDark\` above (zudolab/zudo-doc#1458) \u2014 this function
49
+ * remains as a fallback for any other CSS function value
50
+ * (\`oklch(...)\`, \`rgb(...)\`, named colors, etc.).
51
+ */
52
+ function resolveColor(value) {
53
+ if (!value) return value;
54
+ if (/^#[0-9a-fA-F]{3}$/.test(value)) {
55
+ return "#" + value[1] + value[1] + value[2] + value[2] + value[3] + value[3];
56
+ }
57
+ if (/^#[0-9a-fA-F]{6}$/.test(value)) return value;
58
+ if (/^#[0-9a-fA-F]{8}$/.test(value)) return value.slice(0, 7);
59
+ if (/^#[0-9a-fA-F]{4}$/.test(value)) {
60
+ return "#" + value[1] + value[1] + value[2] + value[2] + value[3] + value[3];
61
+ }
62
+ var el = document.createElement("div");
63
+ el.style.display = "none";
64
+ el.style.color = value;
65
+ document.body.appendChild(el);
66
+ var resolved;
67
+ try {
68
+ resolved = getComputedStyle(el).color;
69
+ } finally {
70
+ el.remove();
71
+ }
72
+ var m = resolved.match(/(d+)/g);
73
+ if (m && m.length >= 3) {
74
+ return "#" + m.slice(0, 3).map(function (n) { return Number(n).toString(16).padStart(2, "0"); }).join("");
75
+ }
76
+ return value;
77
+ }
78
+
79
+ async function initMermaid() {
80
+ var els = document.querySelectorAll("[data-mermaid]:not([data-mermaid-rendered])");
81
+ if (els.length === 0) return;
82
+
83
+ try {
84
+ // Wave 13 (zudolab/zudo-doc#1355 Topic 4): import mermaid from a
85
+ // public ESM CDN URL because the inline <script> reaches the
86
+ // browser without a bundler \u2014 bare specifiers like "mermaid"
87
+ // cannot be resolved at runtime. See the file header for the
88
+ // full trade-off rationale.
89
+ var mod = await import(${safeUrlLiteral});
90
+ var mermaid = mod.default;
91
+ var s = getComputedStyle(document.documentElement);
92
+ // Read the active theme attribute that the color-scheme-provider
93
+ // bootstrap pins on :root (see
94
+ // packages/zudo-doc/src/theme/color-scheme-provider.tsx).
95
+ // parseLightDark uses this to pick the matching arg from
96
+ // \`light-dark(#a, #b)\` tokens before they reach mermaid /
97
+ // khroma (zudolab/zudo-doc#1458).
98
+ var theme = document.documentElement.getAttribute("data-theme");
99
+ // Read a custom property, resolve through the temporary-element
100
+ // round-trip to a hex color, and return undefined when the
101
+ // property is unset on :root. mermaid.initialize crashes (khroma
102
+ // "Unsupported color format: ''") if a theme variable is the
103
+ // empty string, but tolerates undefined as "use the default" \u2014
104
+ // so unset host tokens fall back to mermaid's own theme palette.
105
+ var v = function (name) {
106
+ var raw = s.getPropertyValue(name).trim();
107
+ if (!raw) return undefined;
108
+ // light-dark() is parsed syntactically against the active
109
+ // data-theme attribute \u2014 khroma 2.1.0 cannot parse the
110
+ // function form (zudolab/zudo-doc#1458). Other CSS function
111
+ // values (oklch(...), rgb(...), etc.) still go through the
112
+ // temp-element resolveColor path below.
113
+ var picked = parseLightDark(raw, theme);
114
+ if (picked) {
115
+ var resolvedPicked = resolveColor(picked);
116
+ return resolvedPicked || undefined;
117
+ }
118
+ var resolved = resolveColor(raw);
119
+ return resolved || undefined;
120
+ };
121
+ var bg = v("--zd-bg");
122
+ // Leave luminance as NaN when --zd-bg is not yet on :root. The
123
+ // Number.isNaN guard below maps NaN to darkMode:true, which is
124
+ // mermaid's safer default \u2014 light text on dark fills survives
125
+ // the page eventually flipping into dark mode without a
126
+ // re-render, whereas the inverse produces unreadable diagrams
127
+ // on dark backgrounds. The MutationObserver on the root style
128
+ // attribute (registered further down) will reinit with real
129
+ // luminance once ColorSchemeProvider populates the custom
130
+ // properties.
131
+ var luminance = NaN;
132
+ if (bg && bg.charAt(0) === "#" && bg.length === 7) {
133
+ var hex = bg.replace("#", "");
134
+ var r = parseInt(hex.substring(0, 2), 16) / 255;
135
+ var g = parseInt(hex.substring(2, 4), 16) / 255;
136
+ var b = parseInt(hex.substring(4, 6), 16) / 255;
137
+ luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b;
138
+ }
139
+ // Build themeVariables dynamically so undefined values don't
140
+ // reach khroma's color parser. mermaid's defaults fill in the
141
+ // gaps for any host token that is unset (e.g. when the consumer
142
+ // has not yet mounted ColorSchemeProvider on :root).
143
+ var themeVariables = {
144
+ darkMode: Number.isNaN(luminance) ? true : luminance < 0.5,
145
+ background: "transparent",
146
+ fontFamily: "inherit",
147
+ };
148
+ function setIfDefined(key, value) {
149
+ if (value !== undefined) themeVariables[key] = value;
150
+ }
151
+ var nodeBg = v("--zd-mermaid-node-bg");
152
+ var textColor = v("--zd-mermaid-text");
153
+ var lineColor = v("--zd-mermaid-line");
154
+ var noteBg = v("--zd-mermaid-note-bg");
155
+ var labelBg = v("--zd-mermaid-label-bg");
156
+ setIfDefined("primaryColor", nodeBg);
157
+ setIfDefined("primaryTextColor", textColor);
158
+ setIfDefined("primaryBorderColor", lineColor);
159
+ setIfDefined("lineColor", lineColor);
160
+ setIfDefined("secondaryColor", noteBg);
161
+ setIfDefined("tertiaryColor", noteBg);
162
+ setIfDefined("edgeLabelBackground", labelBg);
163
+ setIfDefined("labelTextColor", textColor);
164
+ setIfDefined("transitionColor", lineColor);
165
+ setIfDefined("transitionLabelColor", textColor);
166
+ setIfDefined("stateLabelColor", textColor);
167
+ setIfDefined("noteBkgColor", noteBg);
168
+ setIfDefined("noteTextColor", textColor);
169
+ setIfDefined("noteBorderColor", lineColor);
170
+ mermaid.initialize({
171
+ startOnLoad: false,
172
+ theme: "base",
173
+ themeVariables: themeVariables,
174
+ });
175
+ await mermaid.run({ nodes: Array.from(els) });
176
+ els.forEach(function (el) { el.setAttribute("data-mermaid-rendered", ""); });
177
+ } catch (e) {
178
+ console.error("[mermaid-init] Failed to render mermaid diagrams:", e);
179
+ }
180
+ }
181
+
182
+ /** Re-render all mermaid diagrams (clear rendered state so initMermaid picks them up). */
183
+ function reinitMermaid() {
184
+ document.querySelectorAll("[data-mermaid-rendered]").forEach(function (el) {
185
+ el.removeAttribute("data-mermaid-rendered");
186
+ // Remove rendered SVG so mermaid regenerates from source text.
187
+ var svg = el.querySelector("svg");
188
+ if (svg) svg.remove();
189
+ });
190
+ initMermaid();
191
+ }
192
+
193
+ // First-paint render \u2014 under zfb's Strategy B SPA navigation,
194
+ // AFTER_NAVIGATE_EVENT (zfb:after-swap) does NOT fire on the initial
195
+ // page load (only post-swap), so we have to invoke initMermaid()
196
+ // synchronously at script-evaluation time to render diagrams on the
197
+ // landing page. The listener below covers the re-render path for
198
+ // every subsequent SPA hop. zudolab/zudo-doc#1523.
199
+ initMermaid();
200
+ document.addEventListener(${JSON.stringify(AFTER_NAVIGATE_EVENT)}, function () { initMermaid(); });
201
+
202
+ // Re-render mermaid when:
203
+ // * the color-tweak panel mutates :root[style] (custom properties), or
204
+ // * the theme-toggle flips :root[data-theme] between "light" / "dark"
205
+ // (zudolab/zudo-doc#1458 \u2014 diagram colors are baked into the rendered
206
+ // SVG, so we have to clear data-mermaid-rendered and re-run with
207
+ // the new theme's hex picks from parseLightDark).
208
+ // Debounced so a synchronous flip of both attributes triggers a
209
+ // single re-render.
210
+ var tweakTimer;
211
+ new MutationObserver(function () {
212
+ clearTimeout(tweakTimer);
213
+ tweakTimer = setTimeout(reinitMermaid, 300);
214
+ }).observe(document.documentElement, {
215
+ attributes: true,
216
+ attributeFilter: ["style", "data-theme"],
217
+ });
218
+ })();`;
219
+ }
220
+ const MERMAID_INIT_SCRIPT = buildMermaidInitScript(MERMAID_CDN_MODULE_URL);
221
+ export {
222
+ MERMAID_CDN_MODULE_URL,
223
+ MERMAID_INIT_SCRIPT,
224
+ buildMermaidInitScript
225
+ };
@@ -0,0 +1,48 @@
1
+ import { JSX } from 'preact';
2
+
3
+ /** @jsxRuntime automatic */
4
+ /** @jsxImportSource preact */
5
+
6
+ /**
7
+ * Props for `<MermaidInit/>`.
8
+ *
9
+ * Either knob is optional — by default the component emits the
10
+ * pre-built `MERMAID_INIT_SCRIPT` constant (esm.sh @11 URL).
11
+ *
12
+ * `script` wins over `cdnUrl` when both are provided so a fully
13
+ * hand-rolled script can short-circuit the builder entirely.
14
+ */
15
+ interface MermaidInitProps {
16
+ /**
17
+ * Override the mermaid module URL the inline script imports at
18
+ * runtime. Use this for self-hosted mirrors, version-pinned
19
+ * packages, or CSP-allowlisted domains. The component re-builds
20
+ * the script with this URL via `buildMermaidInitScript`.
21
+ *
22
+ * Ignored when `script` is also provided.
23
+ */
24
+ cdnUrl?: string;
25
+ /**
26
+ * Replace the entire script body verbatim. Bypasses the
27
+ * `cdnUrl`-driven builder; use when the caller wants to ship a
28
+ * fully customised init routine (different theme palette wiring,
29
+ * extra mermaid plugins, etc.).
30
+ */
31
+ script?: string;
32
+ }
33
+ /**
34
+ * Drop-in JSX replacement for `src/components/mermaid-init.astro`.
35
+ *
36
+ * Include **once** in the layout. Emits the mermaid init script via
37
+ * `dangerouslySetInnerHTML`. The script lazily imports mermaid only when
38
+ * `[data-mermaid]` elements are found on the page, so pages without any
39
+ * mermaid diagrams pay zero runtime cost.
40
+ *
41
+ * The script hooks into `AFTER_NAVIGATE_EVENT` (from
42
+ * `../transitions/page-events.ts`) for View Transitions support and into
43
+ * a `MutationObserver` on `:root[style]` to re-render when the user
44
+ * changes the color scheme via the color-tweak panel.
45
+ */
46
+ declare function MermaidInit(props?: MermaidInitProps): JSX.Element;
47
+
48
+ export { MermaidInit, type MermaidInitProps, MermaidInit as default };
@@ -0,0 +1,14 @@
1
+ import { jsx } from "preact/jsx-runtime";
2
+ import {
3
+ MERMAID_INIT_SCRIPT,
4
+ buildMermaidInitScript
5
+ } from "./mermaid-init-script.js";
6
+ function MermaidInit(props = {}) {
7
+ const script = props.script ?? (props.cdnUrl ? buildMermaidInitScript(props.cdnUrl) : MERMAID_INIT_SCRIPT);
8
+ return /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: script } });
9
+ }
10
+ var mermaid_init_default = MermaidInit;
11
+ export {
12
+ MermaidInit,
13
+ mermaid_init_default as default
14
+ };
@@ -0,0 +1,3 @@
1
+ declare const TABS_INIT_SCRIPT: string;
2
+
3
+ export { TABS_INIT_SCRIPT };