@burojs/ui-shadcn 0.4.0 → 0.6.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 (131) hide show
  1. package/README.md +22 -5
  2. package/dist/bulk-summary-CwSd6Yjb.cjs +108 -0
  3. package/dist/bulk-summary-CwSd6Yjb.cjs.map +1 -0
  4. package/dist/bulk-summary-GxMDP4bw.js +108 -0
  5. package/dist/bulk-summary-GxMDP4bw.js.map +1 -0
  6. package/dist/button-BxnnE28H.cjs +55 -0
  7. package/dist/button-BxnnE28H.cjs.map +1 -0
  8. package/dist/button-MWVeZaqj.js +44 -0
  9. package/dist/button-MWVeZaqj.js.map +1 -0
  10. package/dist/candidates-gate-Bb70LPAy.js +135 -0
  11. package/dist/candidates-gate-Bb70LPAy.js.map +1 -0
  12. package/dist/candidates-gate-D33jXLHO.cjs +153 -0
  13. package/dist/candidates-gate-D33jXLHO.cjs.map +1 -0
  14. package/dist/candidates-relation-picker-B116Bmqi.js +31 -0
  15. package/dist/candidates-relation-picker-B116Bmqi.js.map +1 -0
  16. package/dist/candidates-relation-picker-Cy0rTxvI.cjs +31 -0
  17. package/dist/candidates-relation-picker-Cy0rTxvI.cjs.map +1 -0
  18. package/dist/check-confirm-dialog--gPFnEeg.cjs +1547 -0
  19. package/dist/check-confirm-dialog--gPFnEeg.cjs.map +1 -0
  20. package/dist/check-confirm-dialog-bRT8lt0d.js +1245 -0
  21. package/dist/check-confirm-dialog-bRT8lt0d.js.map +1 -0
  22. package/dist/dialog-B_rt9S1c.js +63 -0
  23. package/dist/dialog-B_rt9S1c.js.map +1 -0
  24. package/dist/dialog-DRNUq9EA.cjs +112 -0
  25. package/dist/dialog-DRNUq9EA.cjs.map +1 -0
  26. package/dist/filter-builder-Bhn-dhZV.js +1621 -0
  27. package/dist/filter-builder-Bhn-dhZV.js.map +1 -0
  28. package/dist/filter-builder-nXqtM_h4.cjs +1789 -0
  29. package/dist/filter-builder-nXqtM_h4.cjs.map +1 -0
  30. package/dist/flow-runtime-D3avVH0I.cjs +255 -0
  31. package/dist/flow-runtime-D3avVH0I.cjs.map +1 -0
  32. package/dist/flow-runtime-s6lkRPKF.js +252 -0
  33. package/dist/flow-runtime-s6lkRPKF.js.map +1 -0
  34. package/dist/flow-screen-CCvgDI9G.js +704 -0
  35. package/dist/flow-screen-CCvgDI9G.js.map +1 -0
  36. package/dist/flow-screen-Ci_Sik4Y.cjs +708 -0
  37. package/dist/flow-screen-Ci_Sik4Y.cjs.map +1 -0
  38. package/dist/index.cjs +3420 -11986
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +1843 -2015
  41. package/dist/index.d.ts +1849 -2021
  42. package/dist/index.js +3090 -11675
  43. package/dist/index.js.map +1 -1
  44. package/dist/inline-flow-host-B6FI0ctQ.js +112 -0
  45. package/dist/inline-flow-host-B6FI0ctQ.js.map +1 -0
  46. package/dist/inline-flow-host-DV1et3c6.cjs +112 -0
  47. package/dist/inline-flow-host-DV1et3c6.cjs.map +1 -0
  48. package/dist/input-BI0czGyI.cjs +23 -0
  49. package/dist/input-BI0czGyI.cjs.map +1 -0
  50. package/dist/input-CUPStzZO.js +17 -0
  51. package/dist/input-CUPStzZO.js.map +1 -0
  52. package/dist/label-66W1qbke.js +29 -0
  53. package/dist/label-66W1qbke.js.map +1 -0
  54. package/dist/label-w6JYf2cF.cjs +36 -0
  55. package/dist/label-w6JYf2cF.cjs.map +1 -0
  56. package/dist/markdown/index.cjs +1 -1
  57. package/dist/markdown/index.d.cts +2 -3
  58. package/dist/markdown/index.d.ts +2 -3
  59. package/dist/markdown/index.js +1 -1
  60. package/dist/page-flow-route-hdnULWqd.cjs +277 -0
  61. package/dist/page-flow-route-hdnULWqd.cjs.map +1 -0
  62. package/dist/page-flow-route-i3ZfJ1sd.js +277 -0
  63. package/dist/page-flow-route-i3ZfJ1sd.js.map +1 -0
  64. package/dist/place-node-C5SmIAYU.cjs +8139 -0
  65. package/dist/place-node-C5SmIAYU.cjs.map +1 -0
  66. package/dist/place-node-NraNYKPx.js +7597 -0
  67. package/dist/place-node-NraNYKPx.js.map +1 -0
  68. package/dist/related-list-cards-BWZ9GfOG.js +42 -0
  69. package/dist/related-list-cards-BWZ9GfOG.js.map +1 -0
  70. package/dist/related-list-cards-CFq3meUn.cjs +42 -0
  71. package/dist/related-list-cards-CFq3meUn.cjs.map +1 -0
  72. package/dist/related-list-timeline-CCzl71aA.cjs +142 -0
  73. package/dist/related-list-timeline-CCzl71aA.cjs.map +1 -0
  74. package/dist/related-list-timeline-yrPsjA3F.js +142 -0
  75. package/dist/related-list-timeline-yrPsjA3F.js.map +1 -0
  76. package/dist/related-rows-ea43qhhy.cjs +208 -0
  77. package/dist/related-rows-ea43qhhy.cjs.map +1 -0
  78. package/dist/related-rows-o0_t-Yce.js +185 -0
  79. package/dist/related-rows-o0_t-Yce.js.map +1 -0
  80. package/dist/relation-create-IA40t1hi.cjs +364 -0
  81. package/dist/relation-create-IA40t1hi.cjs.map +1 -0
  82. package/dist/relation-create-h6F9B4C4.js +339 -0
  83. package/dist/relation-create-h6F9B4C4.js.map +1 -0
  84. package/dist/relation-many-picker-C8zFEjwd.cjs +467 -0
  85. package/dist/relation-many-picker-C8zFEjwd.cjs.map +1 -0
  86. package/dist/relation-many-picker-bvkjkv-k.js +466 -0
  87. package/dist/relation-many-picker-bvkjkv-k.js.map +1 -0
  88. package/dist/relation-picker-Z0ZJJ5uS.js +493 -0
  89. package/dist/relation-picker-Z0ZJJ5uS.js.map +1 -0
  90. package/dist/relation-picker-dialog-0IzkjmiA.cjs +304 -0
  91. package/dist/relation-picker-dialog-0IzkjmiA.cjs.map +1 -0
  92. package/dist/relation-picker-dialog-B6nIiJBf.js +303 -0
  93. package/dist/relation-picker-dialog-B6nIiJBf.js.map +1 -0
  94. package/dist/relation-picker-gag0qSR5.cjs +516 -0
  95. package/dist/relation-picker-gag0qSR5.cjs.map +1 -0
  96. package/dist/resource-page-router-3RUf9d1j.js +1588 -0
  97. package/dist/resource-page-router-3RUf9d1j.js.map +1 -0
  98. package/dist/resource-page-router-PXfMW9nh.cjs +1785 -0
  99. package/dist/resource-page-router-PXfMW9nh.cjs.map +1 -0
  100. package/dist/{rich-text-IDFvyvRE.js → rich-text-DFerywgz.js} +7 -4
  101. package/dist/{rich-text-IDFvyvRE.js.map → rich-text-DFerywgz.js.map} +1 -1
  102. package/dist/{rich-text-lndbYqzR.cjs → rich-text-vTyVjDoa.cjs} +25 -22
  103. package/dist/{rich-text-lndbYqzR.cjs.map → rich-text-vTyVjDoa.cjs.map} +1 -1
  104. package/dist/search-access-CPPmfuvy.js +654 -0
  105. package/dist/search-access-CPPmfuvy.js.map +1 -0
  106. package/dist/search-access-Dugvttlg.cjs +791 -0
  107. package/dist/search-access-Dugvttlg.cjs.map +1 -0
  108. package/dist/shell-BPlk8hEa.js +205 -0
  109. package/dist/shell-BPlk8hEa.js.map +1 -0
  110. package/dist/shell-DxhlsPwm.cjs +271 -0
  111. package/dist/shell-DxhlsPwm.cjs.map +1 -0
  112. package/dist/skeleton-U2noefj5.js +13 -0
  113. package/dist/skeleton-U2noefj5.js.map +1 -0
  114. package/dist/skeleton-_1gP7wan.cjs +18 -0
  115. package/dist/skeleton-_1gP7wan.cjs.map +1 -0
  116. package/dist/styles.css +241 -9
  117. package/dist/toaster-C02XbB9r.js +135 -0
  118. package/dist/toaster-C02XbB9r.js.map +1 -0
  119. package/dist/toaster-Cr51X7bz.cjs +195 -0
  120. package/dist/toaster-Cr51X7bz.cjs.map +1 -0
  121. package/dist/use-dialog-filter-state-C--oMAZG.js +87 -0
  122. package/dist/use-dialog-filter-state-C--oMAZG.js.map +1 -0
  123. package/dist/use-dialog-filter-state-Dhe8PcB5.cjs +92 -0
  124. package/dist/use-dialog-filter-state-Dhe8PcB5.cjs.map +1 -0
  125. package/dist/{use-theme-BwPWinB2.cjs → use-theme-DFlpXils.cjs} +12 -1
  126. package/dist/use-theme-DFlpXils.cjs.map +1 -0
  127. package/dist/{use-theme-IHmtrhEt.js → use-theme-dnE3Od3I.js} +7 -2
  128. package/dist/use-theme-dnE3Od3I.js.map +1 -0
  129. package/package.json +16 -14
  130. package/dist/use-theme-BwPWinB2.cjs.map +0 -1
  131. package/dist/use-theme-IHmtrhEt.js.map +0 -1
@@ -106,6 +106,11 @@ function docShareUrl(slug, href = window.location.href) {
106
106
  }
107
107
  //#endregion
108
108
  //#region src/layout/use-theme.ts
109
+ const THEME_CHOICES = [
110
+ "light",
111
+ "dark",
112
+ "system"
113
+ ];
109
114
  function systemPrefersDark() {
110
115
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
111
116
  }
@@ -194,6 +199,12 @@ Object.defineProperty(exports, "DOC_ID_PREFIX", {
194
199
  return DOC_ID_PREFIX;
195
200
  }
196
201
  });
202
+ Object.defineProperty(exports, "THEME_CHOICES", {
203
+ enumerable: true,
204
+ get: function() {
205
+ return THEME_CHOICES;
206
+ }
207
+ });
197
208
  Object.defineProperty(exports, "__toESM", {
198
209
  enumerable: true,
199
210
  get: function() {
@@ -243,4 +254,4 @@ Object.defineProperty(exports, "useTheme", {
243
254
  }
244
255
  });
245
256
 
246
- //# sourceMappingURL=use-theme-BwPWinB2.cjs.map
257
+ //# sourceMappingURL=use-theme-DFlpXils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-theme-DFlpXils.cjs","names":["twMerge","GithubSlugger","THEME_STORAGE_KEY","useState","useCallback"],"sources":["../src/lib/cn.ts","../src/markdown/anchors.ts","../src/layout/use-theme.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","import GithubSlugger from 'github-slugger';\n\n/**\n * Anchor identity for documentation, in ONE place.\n *\n * Three things have to agree on what `#kak-ustroen-gtin` means: `rehype-slug`,\n * which stamps ids onto headings; the FAQ accordion, which is built from\n * headings but never goes through rehype; and whatever scrolls to a hash. When\n * they disagree the link simply does nothing — no error, no console warning,\n * the page just sits there — so the algorithm lives here and everyone imports it.\n *\n * `github-slugger` is not an extra dependency: `rehype-slug` uses it internally,\n * which is exactly why it is the right choice — matching its output by\n * reimplementing it would be a slow-motion bug in a language with case rules,\n * combining marks and a Cyrillic alphabet.\n */\n\n/** Prefix `rehype-sanitize` renames every id to. See `defaultSchema.clobberPrefix`. */\nexport const DOC_ID_PREFIX = 'user-content-';\n\n/**\n * Slug for a heading's text — the value that appears in a shareable `#hash`.\n *\n * A fresh slugger per call ON PURPOSE. `GithubSlugger` is stateful: it\n * remembers what it has emitted and disambiguates repeats as `foo-1`, `foo-2`.\n * That is right when walking one document top to bottom, and wrong here, where\n * the same heading must produce the same hash every time it is asked about.\n */\nexport function docSlug(text: string): string {\n return new GithubSlugger().slug(text);\n}\n\n/**\n * The current fragment, DECODED, without its `#`.\n *\n * `window.location.hash` hands back a percent-encoded string —\n * `#%D0%BF%D0%BE%D1%87%D0%B5%D0%BC%D1%83…` for a non-ASCII slug — so every\n * comparison against a slug fails, silently, for every non-ASCII alphabet. It works perfectly in ASCII-only slugs, which is\n * the worst possible way for it to be wrong.\n */\nexport function readDocHash(): string {\n if (typeof window === 'undefined') return '';\n const raw = window.location.hash.replace(/^#/, '');\n if (raw === '') return '';\n try {\n return decodeURIComponent(raw);\n } catch {\n // A malformed escape sequence is not worth throwing over.\n return raw;\n }\n}\n\n/**\n * Find the element a hash points at.\n *\n * Tries the prefixed id first, because a heading inside sanitized Markdown is\n * the common case, then the bare one for anchors we render ourselves (the FAQ\n * accordion, which is built from React and never passes through the sanitizer).\n */\nexport function findDocAnchor(hash: string, root: Document | Element = document): Element | null {\n let id = hash.replace(/^#/, '');\n if (id === '') return null;\n try {\n id = decodeURIComponent(id);\n } catch {\n /* keep the raw form */\n }\n\n /*\n `getElementById`, NOT `querySelector('#'+id)`.\n\n A fragment is user input — it arrives from the address bar — and `#a.b:c`\n is a perfectly ordinary thing to paste and an invalid CSS selector, so\n `querySelector` throws a `SyntaxError` on it. `CSS.escape` would fix that\n where it exists, and it does not exist in jsdom, so the crash would have\n been invisible to the unit suite and live only in production. Looking an id\n up by id involves no selector parsing at all.\n */\n const doc = root.ownerDocument ?? (root as Document);\n const pick = (candidate: string): Element | null => {\n const el = doc.getElementById(candidate);\n if (!el) return null;\n // Scoped lookups must not reach outside their root — the handbook searches\n // within the open article so a stale heading elsewhere cannot win.\n return root === doc || root.contains(el) ? el : null;\n };\n return pick(DOC_ID_PREFIX + id) ?? pick(id);\n}\n\n/**\n * Bring an element to the top of ITS OWN scroll container, and nothing else.\n *\n * `scrollIntoView` cannot be used here. It scrolls EVERY scrollable ancestor,\n * the document included — and the document does scroll in this shell, because\n * `SidebarInset` is `min-h-svh` and the app's own sidebar can exceed a short\n * viewport. Clicking an anchor therefore dragged the whole page up: the app\n * header and the handbook's own search box went off the top of the screen, and\n * the layout read as broken. Caught in a screenshot, not by any assertion.\n *\n * Walking to the nearest scrollable ancestor and moving only that keeps the\n * effect where the reader expects it — inside the column they are reading.\n * `scroll-margin-top` is honoured by hand, since we are no longer going through\n * the API that would apply it.\n */\nfunction placeInScroller(target: Element): void {\n let container = target.parentElement;\n while (container) {\n const style = getComputedStyle(container);\n if (\n /(auto|scroll)/.test(style.overflowY) &&\n container.scrollHeight > container.clientHeight + 1\n ) {\n break;\n }\n container = container.parentElement;\n }\n if (!container) {\n // Nothing between here and the document scrolls; the browser's own\n // behaviour is then exactly right.\n target.scrollIntoView({ block: 'start', behavior: 'auto' });\n return;\n }\n const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;\n const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;\n container.scrollTop += delta;\n}\n\n/**\n * Scroll to an anchor and KEEP it in view while the article settles.\n *\n * One `scrollIntoView` is not enough here. An article's height is not final\n * when its markup lands: a mermaid diagram renders asynchronously and a lazily\n * loaded image has no height until it arrives, and either one appearing ABOVE\n * the target pushes it back down — the reader watches the page scroll to the\n * right place and then drift away from it. Measured: the target ended 731px\n * down a 709px pane, i.e. just off the bottom.\n *\n * So the scroll is repeated whenever the container resizes, for a short window\n * and no longer. The window is a deliberate ceiling rather than a guess at how\n * long rendering takes: after it, the reader owns the scroll position, and\n * yanking it back because a late image loaded would be worse than being a few\n * pixels off.\n */\nexport function scrollToDocAnchor(\n hash: string,\n root: Element = document.body,\n settleMs = 1500,\n): () => void {\n let stopped = false;\n const go = () => {\n if (stopped) return;\n const target = findDocAnchor(hash, root);\n if (target) placeInScroller(target);\n };\n // Two frames: markdown → hast → DOM, then layout.\n const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));\n\n const observer =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => requestAnimationFrame(go));\n observer?.observe(root);\n const timer = setTimeout(() => {\n stopped = true;\n observer?.disconnect();\n }, settleMs);\n\n return () => {\n stopped = true;\n cancelAnimationFrame(raf1);\n observer?.disconnect();\n clearTimeout(timer);\n };\n}\n\n/**\n * A shareable url for an anchor on the current page — READABLE.\n *\n * `new URL(…).toString()` percent-encodes the fragment, so a Russian heading\n * becomes forty characters of `%D0%BF%D0%BE…`. That is correct and unusable:\n * the entire point of this link is being pasted into a message where a person\n * reads it, and a wall of escapes tells them nothing about where it goes.\n * Browsers accept a literal fragment and encode it themselves on navigation.\n *\n * The slug is still escaped if it contains anything that would change how the\n * url PARSES — `#`, `?`, whitespace, or a stray `%`. `github-slugger` does not\n * emit those, but this is the one place where being wrong produces a link that\n * silently points somewhere else.\n */\nexport function docShareUrl(slug: string, href: string = window.location.href): string {\n const url = new URL(href);\n const safe = /[#?%\\s]/.test(slug) ? encodeURIComponent(slug) : slug;\n return `${url.origin}${url.pathname}${url.search}#${safe}`;\n}\n","'use client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { THEME_STORAGE_KEY } from './theme-storage-key.js';\n\n/**\n * Re-exported here so most consumers only need one import path. A pre-paint\n * bootstrap is the one exception — `examples/next/app/layout.tsx` imports the\n * constant from the separate, hook-free `@burojs/ui-shadcn/theme-storage-key`\n * subpath instead; see `./theme-storage-key.js` for why a Server Component\n * cannot import it from here.\n */\nexport { THEME_STORAGE_KEY };\n\n/** What the user picked. `'system'` means \"no explicit choice\" — nothing is\n * persisted for it; its absence from storage IS the `system` state. */\nexport type ThemeChoice = 'light' | 'dark' | 'system';\n\n/** Every theme choice, in the order a control offers them. */\nexport const THEME_CHOICES: readonly ThemeChoice[] = ['light', 'dark', 'system'];\n\n/** What is actually painted. Never `'system'` — every reader (Toaster,\n * CodeMirror, Mermaid) only ever needs to know light or dark. */\nexport type ResolvedTheme = 'light' | 'dark';\n\nexport interface UseThemeResult {\n /** The persisted preference, including `'system'`. Only the theme\n * submenu (the one place with a three-way control) needs this. */\n choice: ThemeChoice;\n /** The resolved light/dark value, kept in sync with the `dark` class on\n * `<html>`. This is what every read-only consumer wants. */\n resolved: ResolvedTheme;\n /** Set a new choice: applies the `dark` class immediately and persists\n * (or, for `'system'`, clears) the preference. */\n setTheme: (next: ThemeChoice) => void;\n}\n\nfunction systemPrefersDark(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n );\n}\n\nfunction readChoice(): ThemeChoice {\n if (typeof window === 'undefined') return 'system';\n try {\n const saved = window.localStorage.getItem(THEME_STORAGE_KEY);\n if (saved === 'light' || saved === 'dark') return saved;\n } catch {\n // localStorage may be disabled — fall through to system\n }\n return 'system';\n}\n\nfunction resolveTheme(choice: ThemeChoice): ResolvedTheme {\n if (choice === 'light' || choice === 'dark') return choice;\n return systemPrefersDark() ? 'dark' : 'light';\n}\n\nfunction applyDomClass(resolved: ResolvedTheme): void {\n if (typeof document === 'undefined') return;\n document.documentElement.classList.toggle('dark', resolved === 'dark');\n}\n\nfunction persistChoice(choice: ThemeChoice): void {\n if (typeof window === 'undefined') return;\n try {\n if (choice === 'system') window.localStorage.removeItem(THEME_STORAGE_KEY);\n else window.localStorage.setItem(THEME_STORAGE_KEY, choice);\n } catch {\n // localStorage may be disabled — the class flip already applied.\n }\n}\n\ninterface ThemeState {\n choice: ThemeChoice;\n resolved: ResolvedTheme;\n}\n\n/**\n * Single source of truth for light/dark/system, replacing seven places that\n * each used to know about the theme independently (a bootstrap script, a\n * command-palette action, a submenu, an unused kit component, and three\n * MutationObserver-based readers).\n *\n * Read-only consumers (Toaster, CodeMirror, Mermaid) only need `resolved`\n * and don't call the public `setTheme` — they stay in sync via the\n * `<html class=\"dark\">` MutationObserver below, which fires regardless of\n * WHICH writer flipped it. That is deliberate: it's the same mechanism these\n * three already used individually before this hook existed, now shared\n * instead of duplicated, and it means a future writer doesn't need to know\n * about every reader. Every mounted instance — including these \"read-only\"\n * ones — still runs its OWN `onSystemChange` listener below and applies the\n * class itself on an OS change; see that listener for why re-reading storage\n * there (rather than trusting this instance's local `choice`) is required\n * for that to be safe with several instances mounted at once.\n *\n * `choice` (the three-way value, including `'system'`) is NOT synchronized\n * the same way — the `dark` class alone can't tell \"explicitly dark\" apart\n * from \"system, and the system happens to be dark\". The only consumer that\n * needs `choice` is the theme submenu, and Radix unmounts a closed dropdown's\n * content, so it re-reads storage fresh every time it opens; no live\n * cross-component sync of `choice` is needed in practice.\n *\n * NOT used by the bootstrap `<script>` in `app/layout.tsx` — see the comment\n * there for why a hook cannot do that job.\n */\nexport function useTheme(): UseThemeResult {\n // Safe default for the very first client render, corrected synchronously\n // by the effect below on mount — mirrors the pattern the three readers\n // used before migrating here (start light/false, fix it post-mount) so no\n // component newly grows a hydration-mismatch warning.\n const [state, setState] = useState<ThemeState>({ choice: 'system', resolved: 'light' });\n\n useEffect(() => {\n const choice = readChoice();\n setState({ choice, resolved: resolveTheme(choice) });\n\n const root = document.documentElement;\n const observer = new MutationObserver(() => {\n const resolved: ResolvedTheme = root.classList.contains('dark') ? 'dark' : 'light';\n setState((prev) => (prev.resolved === resolved ? prev : { ...prev, resolved }));\n });\n observer.observe(root, { attributes: true, attributeFilter: ['class'] });\n\n const mql =\n typeof window.matchMedia === 'function'\n ? window.matchMedia('(prefers-color-scheme: dark)')\n : undefined;\n const onSystemChange = (event: { matches: boolean }) => {\n // Re-read the stored choice instead of trusting this instance's own\n // `prev.choice`: `choice` is captured once at mount and never\n // resynchronised, but several `useTheme()` instances mount at once\n // (Toaster, CodeMirror, Mermaid, the admin layout, the theme submenu\n // while open). If a later explicit pick only updates the instance that\n // made it, every OTHER instance still believes `system` applies and\n // would repaint the whole app back to the OS value on the next\n // preference flip — silently overriding storage, which is why this\n // must not trust local state. Storage is already the single source of\n // truth (`setTheme('system')` clears the key), so a fresh read here is\n // correct in both directions: an explicit pick is respected, and\n // `system` is honoured even once the one instance that set it has\n // unmounted. Every other live instance's listener fires on the same OS\n // change and independently reaches the same conclusion, so several\n // instances may call `applyDomClass` with the same value for one\n // event — redundant, but harmless, and not worth coordinating.\n const choice = readChoice();\n if (choice !== 'system') return;\n const resolved: ResolvedTheme = event.matches ? 'dark' : 'light';\n applyDomClass(resolved);\n setState((prev) =>\n prev.choice === choice && prev.resolved === resolved ? prev : { choice, resolved },\n );\n };\n mql?.addEventListener('change', onSystemChange);\n\n return () => {\n observer.disconnect();\n mql?.removeEventListener('change', onSystemChange);\n };\n }, []);\n\n const setTheme = useCallback((next: ThemeChoice) => {\n const resolved = resolveTheme(next);\n applyDomClass(resolved);\n persistChoice(next);\n setState({ choice: next, resolved });\n }, []);\n\n return { choice: state.choice, resolved: state.resolved, setTheme };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,GAAG,GAAG,QAA8B;CAClD,QAAA,GAAOA,eAAAA,QAAAA,EAAAA,GAAQ,KAAA,KAAA,CAAK,MAAM,CAAC;AAC7B;;;ACaA,MAAa,gBAAgB;AAU7B,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,IAAIC,eAAAA,QAAc,CAAC,CAAC,KAAK,IAAI;AACtC;AAUA,SAAgB,cAAsB;CAC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,CAAC;CAEL,OAAO;EAAE,QAAQ,MAAM;EAAQ,UAAU,MAAM;EAAU;CAAS;AACpE"}
@@ -83,6 +83,11 @@ function docShareUrl(slug, href = window.location.href) {
83
83
  }
84
84
  //#endregion
85
85
  //#region src/layout/use-theme.ts
86
+ const THEME_CHOICES = [
87
+ "light",
88
+ "dark",
89
+ "system"
90
+ ];
86
91
  function systemPrefersDark() {
87
92
  return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
88
93
  }
@@ -165,6 +170,6 @@ function useTheme() {
165
170
  };
166
171
  }
167
172
  //#endregion
168
- export { findDocAnchor as a, cn as c, docSlug as i, DOC_ID_PREFIX as n, readDocHash as o, docShareUrl as r, scrollToDocAnchor as s, useTheme as t };
173
+ export { docSlug as a, scrollToDocAnchor as c, docShareUrl as i, cn as l, useTheme as n, findDocAnchor as o, DOC_ID_PREFIX as r, readDocHash as s, THEME_CHOICES as t };
169
174
 
170
- //# sourceMappingURL=use-theme-IHmtrhEt.js.map
175
+ //# sourceMappingURL=use-theme-dnE3Od3I.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-theme-dnE3Od3I.js","names":[],"sources":["../src/lib/cn.ts","../src/markdown/anchors.ts","../src/layout/use-theme.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","import GithubSlugger from 'github-slugger';\n\n/**\n * Anchor identity for documentation, in ONE place.\n *\n * Three things have to agree on what `#kak-ustroen-gtin` means: `rehype-slug`,\n * which stamps ids onto headings; the FAQ accordion, which is built from\n * headings but never goes through rehype; and whatever scrolls to a hash. When\n * they disagree the link simply does nothing — no error, no console warning,\n * the page just sits there — so the algorithm lives here and everyone imports it.\n *\n * `github-slugger` is not an extra dependency: `rehype-slug` uses it internally,\n * which is exactly why it is the right choice — matching its output by\n * reimplementing it would be a slow-motion bug in a language with case rules,\n * combining marks and a Cyrillic alphabet.\n */\n\n/** Prefix `rehype-sanitize` renames every id to. See `defaultSchema.clobberPrefix`. */\nexport const DOC_ID_PREFIX = 'user-content-';\n\n/**\n * Slug for a heading's text — the value that appears in a shareable `#hash`.\n *\n * A fresh slugger per call ON PURPOSE. `GithubSlugger` is stateful: it\n * remembers what it has emitted and disambiguates repeats as `foo-1`, `foo-2`.\n * That is right when walking one document top to bottom, and wrong here, where\n * the same heading must produce the same hash every time it is asked about.\n */\nexport function docSlug(text: string): string {\n return new GithubSlugger().slug(text);\n}\n\n/**\n * The current fragment, DECODED, without its `#`.\n *\n * `window.location.hash` hands back a percent-encoded string —\n * `#%D0%BF%D0%BE%D1%87%D0%B5%D0%BC%D1%83…` for a non-ASCII slug — so every\n * comparison against a slug fails, silently, for every non-ASCII alphabet. It works perfectly in ASCII-only slugs, which is\n * the worst possible way for it to be wrong.\n */\nexport function readDocHash(): string {\n if (typeof window === 'undefined') return '';\n const raw = window.location.hash.replace(/^#/, '');\n if (raw === '') return '';\n try {\n return decodeURIComponent(raw);\n } catch {\n // A malformed escape sequence is not worth throwing over.\n return raw;\n }\n}\n\n/**\n * Find the element a hash points at.\n *\n * Tries the prefixed id first, because a heading inside sanitized Markdown is\n * the common case, then the bare one for anchors we render ourselves (the FAQ\n * accordion, which is built from React and never passes through the sanitizer).\n */\nexport function findDocAnchor(hash: string, root: Document | Element = document): Element | null {\n let id = hash.replace(/^#/, '');\n if (id === '') return null;\n try {\n id = decodeURIComponent(id);\n } catch {\n /* keep the raw form */\n }\n\n /*\n `getElementById`, NOT `querySelector('#'+id)`.\n\n A fragment is user input — it arrives from the address bar — and `#a.b:c`\n is a perfectly ordinary thing to paste and an invalid CSS selector, so\n `querySelector` throws a `SyntaxError` on it. `CSS.escape` would fix that\n where it exists, and it does not exist in jsdom, so the crash would have\n been invisible to the unit suite and live only in production. Looking an id\n up by id involves no selector parsing at all.\n */\n const doc = root.ownerDocument ?? (root as Document);\n const pick = (candidate: string): Element | null => {\n const el = doc.getElementById(candidate);\n if (!el) return null;\n // Scoped lookups must not reach outside their root — the handbook searches\n // within the open article so a stale heading elsewhere cannot win.\n return root === doc || root.contains(el) ? el : null;\n };\n return pick(DOC_ID_PREFIX + id) ?? pick(id);\n}\n\n/**\n * Bring an element to the top of ITS OWN scroll container, and nothing else.\n *\n * `scrollIntoView` cannot be used here. It scrolls EVERY scrollable ancestor,\n * the document included — and the document does scroll in this shell, because\n * `SidebarInset` is `min-h-svh` and the app's own sidebar can exceed a short\n * viewport. Clicking an anchor therefore dragged the whole page up: the app\n * header and the handbook's own search box went off the top of the screen, and\n * the layout read as broken. Caught in a screenshot, not by any assertion.\n *\n * Walking to the nearest scrollable ancestor and moving only that keeps the\n * effect where the reader expects it — inside the column they are reading.\n * `scroll-margin-top` is honoured by hand, since we are no longer going through\n * the API that would apply it.\n */\nfunction placeInScroller(target: Element): void {\n let container = target.parentElement;\n while (container) {\n const style = getComputedStyle(container);\n if (\n /(auto|scroll)/.test(style.overflowY) &&\n container.scrollHeight > container.clientHeight + 1\n ) {\n break;\n }\n container = container.parentElement;\n }\n if (!container) {\n // Nothing between here and the document scrolls; the browser's own\n // behaviour is then exactly right.\n target.scrollIntoView({ block: 'start', behavior: 'auto' });\n return;\n }\n const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;\n const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;\n container.scrollTop += delta;\n}\n\n/**\n * Scroll to an anchor and KEEP it in view while the article settles.\n *\n * One `scrollIntoView` is not enough here. An article's height is not final\n * when its markup lands: a mermaid diagram renders asynchronously and a lazily\n * loaded image has no height until it arrives, and either one appearing ABOVE\n * the target pushes it back down — the reader watches the page scroll to the\n * right place and then drift away from it. Measured: the target ended 731px\n * down a 709px pane, i.e. just off the bottom.\n *\n * So the scroll is repeated whenever the container resizes, for a short window\n * and no longer. The window is a deliberate ceiling rather than a guess at how\n * long rendering takes: after it, the reader owns the scroll position, and\n * yanking it back because a late image loaded would be worse than being a few\n * pixels off.\n */\nexport function scrollToDocAnchor(\n hash: string,\n root: Element = document.body,\n settleMs = 1500,\n): () => void {\n let stopped = false;\n const go = () => {\n if (stopped) return;\n const target = findDocAnchor(hash, root);\n if (target) placeInScroller(target);\n };\n // Two frames: markdown → hast → DOM, then layout.\n const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));\n\n const observer =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => requestAnimationFrame(go));\n observer?.observe(root);\n const timer = setTimeout(() => {\n stopped = true;\n observer?.disconnect();\n }, settleMs);\n\n return () => {\n stopped = true;\n cancelAnimationFrame(raf1);\n observer?.disconnect();\n clearTimeout(timer);\n };\n}\n\n/**\n * A shareable url for an anchor on the current page — READABLE.\n *\n * `new URL(…).toString()` percent-encodes the fragment, so a Russian heading\n * becomes forty characters of `%D0%BF%D0%BE…`. That is correct and unusable:\n * the entire point of this link is being pasted into a message where a person\n * reads it, and a wall of escapes tells them nothing about where it goes.\n * Browsers accept a literal fragment and encode it themselves on navigation.\n *\n * The slug is still escaped if it contains anything that would change how the\n * url PARSES — `#`, `?`, whitespace, or a stray `%`. `github-slugger` does not\n * emit those, but this is the one place where being wrong produces a link that\n * silently points somewhere else.\n */\nexport function docShareUrl(slug: string, href: string = window.location.href): string {\n const url = new URL(href);\n const safe = /[#?%\\s]/.test(slug) ? encodeURIComponent(slug) : slug;\n return `${url.origin}${url.pathname}${url.search}#${safe}`;\n}\n","'use client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { THEME_STORAGE_KEY } from './theme-storage-key.js';\n\n/**\n * Re-exported here so most consumers only need one import path. A pre-paint\n * bootstrap is the one exception — `examples/next/app/layout.tsx` imports the\n * constant from the separate, hook-free `@burojs/ui-shadcn/theme-storage-key`\n * subpath instead; see `./theme-storage-key.js` for why a Server Component\n * cannot import it from here.\n */\nexport { THEME_STORAGE_KEY };\n\n/** What the user picked. `'system'` means \"no explicit choice\" — nothing is\n * persisted for it; its absence from storage IS the `system` state. */\nexport type ThemeChoice = 'light' | 'dark' | 'system';\n\n/** Every theme choice, in the order a control offers them. */\nexport const THEME_CHOICES: readonly ThemeChoice[] = ['light', 'dark', 'system'];\n\n/** What is actually painted. Never `'system'` — every reader (Toaster,\n * CodeMirror, Mermaid) only ever needs to know light or dark. */\nexport type ResolvedTheme = 'light' | 'dark';\n\nexport interface UseThemeResult {\n /** The persisted preference, including `'system'`. Only the theme\n * submenu (the one place with a three-way control) needs this. */\n choice: ThemeChoice;\n /** The resolved light/dark value, kept in sync with the `dark` class on\n * `<html>`. This is what every read-only consumer wants. */\n resolved: ResolvedTheme;\n /** Set a new choice: applies the `dark` class immediately and persists\n * (or, for `'system'`, clears) the preference. */\n setTheme: (next: ThemeChoice) => void;\n}\n\nfunction systemPrefersDark(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n );\n}\n\nfunction readChoice(): ThemeChoice {\n if (typeof window === 'undefined') return 'system';\n try {\n const saved = window.localStorage.getItem(THEME_STORAGE_KEY);\n if (saved === 'light' || saved === 'dark') return saved;\n } catch {\n // localStorage may be disabled — fall through to system\n }\n return 'system';\n}\n\nfunction resolveTheme(choice: ThemeChoice): ResolvedTheme {\n if (choice === 'light' || choice === 'dark') return choice;\n return systemPrefersDark() ? 'dark' : 'light';\n}\n\nfunction applyDomClass(resolved: ResolvedTheme): void {\n if (typeof document === 'undefined') return;\n document.documentElement.classList.toggle('dark', resolved === 'dark');\n}\n\nfunction persistChoice(choice: ThemeChoice): void {\n if (typeof window === 'undefined') return;\n try {\n if (choice === 'system') window.localStorage.removeItem(THEME_STORAGE_KEY);\n else window.localStorage.setItem(THEME_STORAGE_KEY, choice);\n } catch {\n // localStorage may be disabled — the class flip already applied.\n }\n}\n\ninterface ThemeState {\n choice: ThemeChoice;\n resolved: ResolvedTheme;\n}\n\n/**\n * Single source of truth for light/dark/system, replacing seven places that\n * each used to know about the theme independently (a bootstrap script, a\n * command-palette action, a submenu, an unused kit component, and three\n * MutationObserver-based readers).\n *\n * Read-only consumers (Toaster, CodeMirror, Mermaid) only need `resolved`\n * and don't call the public `setTheme` — they stay in sync via the\n * `<html class=\"dark\">` MutationObserver below, which fires regardless of\n * WHICH writer flipped it. That is deliberate: it's the same mechanism these\n * three already used individually before this hook existed, now shared\n * instead of duplicated, and it means a future writer doesn't need to know\n * about every reader. Every mounted instance — including these \"read-only\"\n * ones — still runs its OWN `onSystemChange` listener below and applies the\n * class itself on an OS change; see that listener for why re-reading storage\n * there (rather than trusting this instance's local `choice`) is required\n * for that to be safe with several instances mounted at once.\n *\n * `choice` (the three-way value, including `'system'`) is NOT synchronized\n * the same way — the `dark` class alone can't tell \"explicitly dark\" apart\n * from \"system, and the system happens to be dark\". The only consumer that\n * needs `choice` is the theme submenu, and Radix unmounts a closed dropdown's\n * content, so it re-reads storage fresh every time it opens; no live\n * cross-component sync of `choice` is needed in practice.\n *\n * NOT used by the bootstrap `<script>` in `app/layout.tsx` — see the comment\n * there for why a hook cannot do that job.\n */\nexport function useTheme(): UseThemeResult {\n // Safe default for the very first client render, corrected synchronously\n // by the effect below on mount — mirrors the pattern the three readers\n // used before migrating here (start light/false, fix it post-mount) so no\n // component newly grows a hydration-mismatch warning.\n const [state, setState] = useState<ThemeState>({ choice: 'system', resolved: 'light' });\n\n useEffect(() => {\n const choice = readChoice();\n setState({ choice, resolved: resolveTheme(choice) });\n\n const root = document.documentElement;\n const observer = new MutationObserver(() => {\n const resolved: ResolvedTheme = root.classList.contains('dark') ? 'dark' : 'light';\n setState((prev) => (prev.resolved === resolved ? prev : { ...prev, resolved }));\n });\n observer.observe(root, { attributes: true, attributeFilter: ['class'] });\n\n const mql =\n typeof window.matchMedia === 'function'\n ? window.matchMedia('(prefers-color-scheme: dark)')\n : undefined;\n const onSystemChange = (event: { matches: boolean }) => {\n // Re-read the stored choice instead of trusting this instance's own\n // `prev.choice`: `choice` is captured once at mount and never\n // resynchronised, but several `useTheme()` instances mount at once\n // (Toaster, CodeMirror, Mermaid, the admin layout, the theme submenu\n // while open). If a later explicit pick only updates the instance that\n // made it, every OTHER instance still believes `system` applies and\n // would repaint the whole app back to the OS value on the next\n // preference flip — silently overriding storage, which is why this\n // must not trust local state. Storage is already the single source of\n // truth (`setTheme('system')` clears the key), so a fresh read here is\n // correct in both directions: an explicit pick is respected, and\n // `system` is honoured even once the one instance that set it has\n // unmounted. Every other live instance's listener fires on the same OS\n // change and independently reaches the same conclusion, so several\n // instances may call `applyDomClass` with the same value for one\n // event — redundant, but harmless, and not worth coordinating.\n const choice = readChoice();\n if (choice !== 'system') return;\n const resolved: ResolvedTheme = event.matches ? 'dark' : 'light';\n applyDomClass(resolved);\n setState((prev) =>\n prev.choice === choice && prev.resolved === resolved ? prev : { choice, resolved },\n );\n };\n mql?.addEventListener('change', onSystemChange);\n\n return () => {\n observer.disconnect();\n mql?.removeEventListener('change', onSystemChange);\n };\n }, []);\n\n const setTheme = useCallback((next: ThemeChoice) => {\n const resolved = resolveTheme(next);\n applyDomClass(resolved);\n persistChoice(next);\n setState({ choice: next, resolved });\n }, []);\n\n return { choice: state.choice, resolved: state.resolved, setTheme };\n}\n"],"mappings":";;;;;;AAGA,SAAgB,GAAG,GAAG,QAA8B;CAClD,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ACaA,MAAa,gBAAgB;AAU7B,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,IAAI,cAAc,CAAC,CAAC,KAAK,IAAI;AACtC;AAUA,SAAgB,cAAsB;CACpC,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,MAAM,MAAM,OAAO,SAAS,KAAK,QAAQ,MAAM,EAAE;CACjD,IAAI,QAAQ,IAAI,OAAO;CACvB,IAAI;EACF,OAAO,mBAAmB,GAAG;CAC/B,QAAQ;EAEN,OAAO;CACT;AACF;AASA,SAAgB,cAAc,MAAc,OAA2B,UAA0B;CAC/F,IAAI,KAAK,KAAK,Q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aAAa,MAAM;EAAE,CAAC;EAEnD,MAAM,OAAO,SAAS;EACtB,MAAM,WAAW,IAAI,uBAAuB;GAC1C,MAAM,WAA0B,KAAK,UAAU,SAAS,MAAM,IAAI,SAAS;GAC3E,UAAU,SAAU,KAAK,aAAa,WAAW,OAAO;IAAE,GAAG;IAAM;GAAS,CAAE;EAChF,CAAC;EACD,SAAS,QAAQ,MAAM;GAAE,YAAY;GAAM,iBAAiB,CAAC,OAAO;EAAE,CAAC;EAEvE,MAAM,MACJ,OAAO,OAAO,eAAe,aACzB,OAAO,WAAW,8BAA8B,IAChD,KAAA;EACN,MAAM,kBAAkB,UAAgC;GAiBtD,MAAM,SAAS,WAAW;GAC1B,IAAI,WAAW,UAAU;GACzB,MAAM,WAA0B,MAAM,UAAU,SAAS;GACzD,cAAc,QAAQ;GACtB,UAAU,SACR,KAAK,WAAW,UAAU,KAAK,aAAa,WAAW,OAAO;IAAE;IAAQ;GAAS,CACnF;EACF;EACA,KAAK,iBAAiB,UAAU,cAAc;EAE9C,aAAa;GACX,SAAS,WAAW;GACpB,KAAK,oBAAoB,UAAU,cAAc;EACnD;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,WAAW,aAAa,SAAsB;EAClD,MAAM,WAAW,aAAa,IAAI;EAClC,cAAc,QAAQ;EACtB,cAAc,IAAI;EAClB,SAAS;GAAE,QAAQ;GAAM;EAAS,CAAC;CACrC,GAAG,CAAC,CAAC;CAEL,OAAO;EAAE,QAAQ,MAAM;EAAQ,UAAU,MAAM;EAAU;CAAS;AACpE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@burojs/ui-shadcn",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "license": "MIT",
5
5
  "description": "Buro: default shadcn+Tailwind UI kit with required testid attributes",
6
6
  "type": "module",
@@ -84,19 +84,19 @@
84
84
  "dependencies": {
85
85
  "@hookform/resolvers": "^3.9.0",
86
86
  "@radix-ui/react-accordion": "^1.2.20",
87
- "@radix-ui/react-alert-dialog": "^1.1.15",
87
+ "@radix-ui/react-alert-dialog": "1.1.15",
88
88
  "@radix-ui/react-avatar": "^1.1.0",
89
89
  "@radix-ui/react-checkbox": "^1.1.0",
90
90
  "@radix-ui/react-collapsible": "^1.1.0",
91
- "@radix-ui/react-dialog": "^1.1.0",
92
- "@radix-ui/react-dropdown-menu": "^2.1.0",
91
+ "@radix-ui/react-dialog": "1.1.15",
92
+ "@radix-ui/react-dropdown-menu": "2.1.16",
93
93
  "@radix-ui/react-label": "^2.1.0",
94
- "@radix-ui/react-popover": "^1.1.0",
95
- "@radix-ui/react-select": "^2.1.0",
94
+ "@radix-ui/react-popover": "1.1.15",
95
+ "@radix-ui/react-select": "2.2.6",
96
96
  "@radix-ui/react-separator": "^1.1.0",
97
97
  "@radix-ui/react-slot": "^1.1.0",
98
98
  "@radix-ui/react-tabs": "^1.1.0",
99
- "@radix-ui/react-tooltip": "^1.1.0",
99
+ "@radix-ui/react-tooltip": "1.2.8",
100
100
  "@tabler/icons-react": "^3.46.0",
101
101
  "@tailwindcss/typography": "^0.5",
102
102
  "@tanstack/react-table": "^8.20.0",
@@ -120,11 +120,11 @@
120
120
  "tw-animate-css": "^1.4.0",
121
121
  "unist-util-visit": "^5",
122
122
  "zod": "^3.24.0",
123
- "@burojs/core": "0.4.0",
124
- "@burojs/field-types": "0.4.0",
125
- "@burojs/file-storage": "0.4.0",
126
- "@burojs/i18n-core": "0.4.0",
127
- "@burojs/react": "0.4.0"
123
+ "@burojs/core": "0.6.0",
124
+ "@burojs/field-types": "0.6.0",
125
+ "@burojs/file-storage": "0.6.0",
126
+ "@burojs/i18n-core": "0.6.0",
127
+ "@burojs/react": "0.6.0"
128
128
  },
129
129
  "peerDependencies": {
130
130
  "react": "^19.0.0",
@@ -139,6 +139,7 @@
139
139
  "@testing-library/user-event": "^14.5.0",
140
140
  "@types/react": "^19.0.0",
141
141
  "@types/react-dom": "^19.0.0",
142
+ "axe-core": "4.13.0",
142
143
  "expect-type": "^1.1.0",
143
144
  "jsdom": "^26.0.0",
144
145
  "khroma": "^2.1.0",
@@ -146,8 +147,9 @@
146
147
  "react-dom": "^19.0.0",
147
148
  "typescript": "^5.5.0",
148
149
  "vitest": "^4.0.0",
149
- "@burojs/context": "0.4.0",
150
- "@burojs/export": "0.4.0",
150
+ "@burojs/context": "0.6.0",
151
+ "@burojs/export": "0.6.0",
152
+ "@burojs/testing": "0.6.0",
151
153
  "@burojs/tooling-eslint": "0.0.0",
152
154
  "@burojs/tooling-globals": "0.0.0",
153
155
  "@burojs/tooling-tsconfig": "0.0.0"
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-theme-BwPWinB2.cjs","names":["twMerge","GithubSlugger","THEME_STORAGE_KEY","useState","useCallback"],"sources":["../src/lib/cn.ts","../src/markdown/anchors.ts","../src/layout/use-theme.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","import GithubSlugger from 'github-slugger';\n\n/**\n * Anchor identity for documentation, in ONE place.\n *\n * Three things have to agree on what `#kak-ustroen-gtin` means: `rehype-slug`,\n * which stamps ids onto headings; the FAQ accordion, which is built from\n * headings but never goes through rehype; and whatever scrolls to a hash. When\n * they disagree the link simply does nothing — no error, no console warning,\n * the page just sits there — so the algorithm lives here and everyone imports it.\n *\n * `github-slugger` is not an extra dependency: `rehype-slug` uses it internally,\n * which is exactly why it is the right choice — matching its output by\n * reimplementing it would be a slow-motion bug in a language with case rules,\n * combining marks and a Cyrillic alphabet.\n */\n\n/** Prefix `rehype-sanitize` renames every id to. See `defaultSchema.clobberPrefix`. */\nexport const DOC_ID_PREFIX = 'user-content-';\n\n/**\n * Slug for a heading's text — the value that appears in a shareable `#hash`.\n *\n * A fresh slugger per call ON PURPOSE. `GithubSlugger` is stateful: it\n * remembers what it has emitted and disambiguates repeats as `foo-1`, `foo-2`.\n * That is right when walking one document top to bottom, and wrong here, where\n * the same heading must produce the same hash every time it is asked about.\n */\nexport function docSlug(text: string): string {\n return new GithubSlugger().slug(text);\n}\n\n/**\n * The current fragment, DECODED, without its `#`.\n *\n * `window.location.hash` hands back a percent-encoded string —\n * `#%D0%BF%D0%BE%D1%87%D0%B5%D0%BC%D1%83…` for `#почему…` — so every\n * comparison against a slug fails, silently, for exactly the alphabet this\n * project writes its documentation in. It works perfectly in English, which is\n * the worst possible way for it to be wrong.\n */\nexport function readDocHash(): string {\n if (typeof window === 'undefined') return '';\n const raw = window.location.hash.replace(/^#/, '');\n if (raw === '') return '';\n try {\n return decodeURIComponent(raw);\n } catch {\n // A malformed escape sequence is not worth throwing over.\n return raw;\n }\n}\n\n/**\n * Find the element a hash points at.\n *\n * Tries the prefixed id first, because a heading inside sanitized Markdown is\n * the common case, then the bare one for anchors we render ourselves (the FAQ\n * accordion, which is built from React and never passes through the sanitizer).\n */\nexport function findDocAnchor(hash: string, root: Document | Element = document): Element | null {\n let id = hash.replace(/^#/, '');\n if (id === '') return null;\n try {\n id = decodeURIComponent(id);\n } catch {\n /* keep the raw form */\n }\n\n /*\n `getElementById`, NOT `querySelector('#'+id)`.\n\n A fragment is user input — it arrives from the address bar — and `#a.b:c`\n is a perfectly ordinary thing to paste and an invalid CSS selector, so\n `querySelector` throws a `SyntaxError` on it. `CSS.escape` would fix that\n where it exists, and it does not exist in jsdom, so the crash would have\n been invisible to the unit suite and live only in production. Looking an id\n up by id involves no selector parsing at all.\n */\n const doc = root.ownerDocument ?? (root as Document);\n const pick = (candidate: string): Element | null => {\n const el = doc.getElementById(candidate);\n if (!el) return null;\n // Scoped lookups must not reach outside their root — the handbook searches\n // within the open article so a stale heading elsewhere cannot win.\n return root === doc || root.contains(el) ? el : null;\n };\n return pick(DOC_ID_PREFIX + id) ?? pick(id);\n}\n\n/**\n * Bring an element to the top of ITS OWN scroll container, and nothing else.\n *\n * `scrollIntoView` cannot be used here. It scrolls EVERY scrollable ancestor,\n * the document included — and the document does scroll in this shell, because\n * `SidebarInset` is `min-h-svh` and the app's own sidebar can exceed a short\n * viewport. Clicking an anchor therefore dragged the whole page up: the app\n * header and the handbook's own search box went off the top of the screen, and\n * the layout read as broken. Caught in a screenshot, not by any assertion.\n *\n * Walking to the nearest scrollable ancestor and moving only that keeps the\n * effect where the reader expects it — inside the column they are reading.\n * `scroll-margin-top` is honoured by hand, since we are no longer going through\n * the API that would apply it.\n */\nfunction placeInScroller(target: Element): void {\n let container = target.parentElement;\n while (container) {\n const style = getComputedStyle(container);\n if (\n /(auto|scroll)/.test(style.overflowY) &&\n container.scrollHeight > container.clientHeight + 1\n ) {\n break;\n }\n container = container.parentElement;\n }\n if (!container) {\n // Nothing between here and the document scrolls; the browser's own\n // behaviour is then exactly right.\n target.scrollIntoView({ block: 'start', behavior: 'auto' });\n return;\n }\n const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;\n const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;\n container.scrollTop += delta;\n}\n\n/**\n * Scroll to an anchor and KEEP it in view while the article settles.\n *\n * One `scrollIntoView` is not enough here. An article's height is not final\n * when its markup lands: a mermaid diagram renders asynchronously and a lazily\n * loaded image has no height until it arrives, and either one appearing ABOVE\n * the target pushes it back down — the reader watches the page scroll to the\n * right place and then drift away from it. Measured: the target ended 731px\n * down a 709px pane, i.e. just off the bottom.\n *\n * So the scroll is repeated whenever the container resizes, for a short window\n * and no longer. The window is a deliberate ceiling rather than a guess at how\n * long rendering takes: after it, the reader owns the scroll position, and\n * yanking it back because a late image loaded would be worse than being a few\n * pixels off.\n */\nexport function scrollToDocAnchor(\n hash: string,\n root: Element = document.body,\n settleMs = 1500,\n): () => void {\n let stopped = false;\n const go = () => {\n if (stopped) return;\n const target = findDocAnchor(hash, root);\n if (target) placeInScroller(target);\n };\n // Two frames: markdown → hast → DOM, then layout.\n const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));\n\n const observer =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => requestAnimationFrame(go));\n observer?.observe(root);\n const timer = setTimeout(() => {\n stopped = true;\n observer?.disconnect();\n }, settleMs);\n\n return () => {\n stopped = true;\n cancelAnimationFrame(raf1);\n observer?.disconnect();\n clearTimeout(timer);\n };\n}\n\n/**\n * A shareable url for an anchor on the current page — READABLE.\n *\n * `new URL(…).toString()` percent-encodes the fragment, so a Russian heading\n * becomes forty characters of `%D0%BF%D0%BE…`. That is correct and unusable:\n * the entire point of this link is being pasted into a message where a person\n * reads it, and a wall of escapes tells them nothing about where it goes.\n * Browsers accept a literal fragment and encode it themselves on navigation.\n *\n * The slug is still escaped if it contains anything that would change how the\n * url PARSES — `#`, `?`, whitespace, or a stray `%`. `github-slugger` does not\n * emit those, but this is the one place where being wrong produces a link that\n * silently points somewhere else.\n */\nexport function docShareUrl(slug: string, href: string = window.location.href): string {\n const url = new URL(href);\n const safe = /[#?%\\s]/.test(slug) ? encodeURIComponent(slug) : slug;\n return `${url.origin}${url.pathname}${url.search}#${safe}`;\n}\n","'use client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { THEME_STORAGE_KEY } from './theme-storage-key.js';\n\n/**\n * Re-exported here so most consumers only need one import path. A pre-paint\n * bootstrap is the one exception — `examples/next/app/layout.tsx` imports the\n * constant from the separate, hook-free `@burojs/ui-shadcn/theme-storage-key`\n * subpath instead; see `./theme-storage-key.js` for why a Server Component\n * cannot import it from here.\n */\nexport { THEME_STORAGE_KEY };\n\n/** What the user picked. `'system'` means \"no explicit choice\" — nothing is\n * persisted for it; its absence from storage IS the `system` state. */\nexport type ThemeChoice = 'light' | 'dark' | 'system';\n\n/** What is actually painted. Never `'system'` — every reader (Toaster,\n * CodeMirror, Mermaid) only ever needs to know light or dark. */\nexport type ResolvedTheme = 'light' | 'dark';\n\nexport interface UseThemeResult {\n /** The persisted preference, including `'system'`. Only the theme\n * submenu (the one place with a three-way control) needs this. */\n choice: ThemeChoice;\n /** The resolved light/dark value, kept in sync with the `dark` class on\n * `<html>`. This is what every read-only consumer wants. */\n resolved: ResolvedTheme;\n /** Set a new choice: applies the `dark` class immediately and persists\n * (or, for `'system'`, clears) the preference. */\n setTheme: (next: ThemeChoice) => void;\n}\n\nfunction systemPrefersDark(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n );\n}\n\nfunction readChoice(): ThemeChoice {\n if (typeof window === 'undefined') return 'system';\n try {\n const saved = window.localStorage.getItem(THEME_STORAGE_KEY);\n if (saved === 'light' || saved === 'dark') return saved;\n } catch {\n // localStorage may be disabled — fall through to system\n }\n return 'system';\n}\n\nfunction resolveTheme(choice: ThemeChoice): ResolvedTheme {\n if (choice === 'light' || choice === 'dark') return choice;\n return systemPrefersDark() ? 'dark' : 'light';\n}\n\nfunction applyDomClass(resolved: ResolvedTheme): void {\n if (typeof document === 'undefined') return;\n document.documentElement.classList.toggle('dark', resolved === 'dark');\n}\n\nfunction persistChoice(choice: ThemeChoice): void {\n if (typeof window === 'undefined') return;\n try {\n if (choice === 'system') window.localStorage.removeItem(THEME_STORAGE_KEY);\n else window.localStorage.setItem(THEME_STORAGE_KEY, choice);\n } catch {\n // localStorage may be disabled — the class flip already applied.\n }\n}\n\ninterface ThemeState {\n choice: ThemeChoice;\n resolved: ResolvedTheme;\n}\n\n/**\n * Single source of truth for light/dark/system, replacing seven places that\n * each used to know about the theme independently (a bootstrap script, a\n * command-palette action, a submenu, an unused kit component, and three\n * MutationObserver-based readers).\n *\n * Read-only consumers (Toaster, CodeMirror, Mermaid) only need `resolved`\n * and don't call the public `setTheme` — they stay in sync via the\n * `<html class=\"dark\">` MutationObserver below, which fires regardless of\n * WHICH writer flipped it. That is deliberate: it's the same mechanism these\n * three already used individually before this hook existed, now shared\n * instead of duplicated, and it means a future writer doesn't need to know\n * about every reader. Every mounted instance — including these \"read-only\"\n * ones — still runs its OWN `onSystemChange` listener below and applies the\n * class itself on an OS change; see that listener for why re-reading storage\n * there (rather than trusting this instance's local `choice`) is required\n * for that to be safe with several instances mounted at once.\n *\n * `choice` (the three-way value, including `'system'`) is NOT synchronized\n * the same way — the `dark` class alone can't tell \"explicitly dark\" apart\n * from \"system, and the system happens to be dark\". The only consumer that\n * needs `choice` is the theme submenu, and Radix unmounts a closed dropdown's\n * content, so it re-reads storage fresh every time it opens; no live\n * cross-component sync of `choice` is needed in practice.\n *\n * NOT used by the bootstrap `<script>` in `app/layout.tsx` — see the comment\n * there for why a hook cannot do that job.\n */\nexport function useTheme(): UseThemeResult {\n // Safe default for the very first client render, corrected synchronously\n // by the effect below on mount — mirrors the pattern the three readers\n // used before migrating here (start light/false, fix it post-mount) so no\n // component newly grows a hydration-mismatch warning.\n const [state, setState] = useState<ThemeState>({ choice: 'system', resolved: 'light' });\n\n useEffect(() => {\n const choice = readChoice();\n setState({ choice, resolved: resolveTheme(choice) });\n\n const root = document.documentElement;\n const observer = new MutationObserver(() => {\n const resolved: ResolvedTheme = root.classList.contains('dark') ? 'dark' : 'light';\n setState((prev) => (prev.resolved === resolved ? prev : { ...prev, resolved }));\n });\n observer.observe(root, { attributes: true, attributeFilter: ['class'] });\n\n const mql =\n typeof window.matchMedia === 'function'\n ? window.matchMedia('(prefers-color-scheme: dark)')\n : undefined;\n const onSystemChange = (event: { matches: boolean }) => {\n // Re-read the stored choice instead of trusting this instance's own\n // `prev.choice`: `choice` is captured once at mount and never\n // resynchronised, but several `useTheme()` instances mount at once\n // (Toaster, CodeMirror, Mermaid, the admin layout, the theme submenu\n // while open). If a later explicit pick only updates the instance that\n // made it, every OTHER instance still believes `system` applies and\n // would repaint the whole app back to the OS value on the next\n // preference flip — silently overriding storage, which is why this\n // must not trust local state. Storage is already the single source of\n // truth (`setTheme('system')` clears the key), so a fresh read here is\n // correct in both directions: an explicit pick is respected, and\n // `system` is honoured even once the one instance that set it has\n // unmounted. Every other live instance's listener fires on the same OS\n // change and independently reaches the same conclusion, so several\n // instances may call `applyDomClass` with the same value for one\n // event — redundant, but harmless, and not worth coordinating.\n const choice = readChoice();\n if (choice !== 'system') return;\n const resolved: ResolvedTheme = event.matches ? 'dark' : 'light';\n applyDomClass(resolved);\n setState((prev) =>\n prev.choice === choice && prev.resolved === resolved ? prev : { choice, resolved },\n );\n };\n mql?.addEventListener('change', onSystemChange);\n\n return () => {\n observer.disconnect();\n mql?.removeEventListener('change', onSystemChange);\n };\n }, []);\n\n const setTheme = useCallback((next: ThemeChoice) => {\n const resolved = resolveTheme(next);\n applyDomClass(resolved);\n persistChoice(next);\n setState({ choice: next, resolved });\n }, []);\n\n return { choice: state.choice, resolved: state.resolved, setTheme };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,SAAgB,GAAG,GAAG,QAA8B;CAClD,QAAA,GAAOA,eAAAA,QAAAA,EAAAA,GAAQ,KAAA,KAAA,CAAK,MAAM,CAAC;AAC7B;;;ACaA,MAAa,gBAAgB;AAU7B,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,IAAIC,eAAAA,QAAc,CAAC,CAAC,KAAK,IAAI;AACtC;AAWA,SAAgB,cAAsB;CACpC,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,MAAM,MAAM,OAAO,SAAS,KAAK,QAAQ,MAAM,EAAE;CACjD,IAAI,QAAQ,IAAI,OAAO;CACvB,IAAI;EACF,OAAO,mBAAmB,GAAG;CAC/B,QAAQ;EAEN,OAAO;CACT;AACF;AASA,SAAgB,cAAc,MAAc,OAA2B,UAA0B;CAC/F,IAAI,KAAK,KAAK,QAAQ,MAAM,EAAE;CAC9B,IAAI,OAAO,IAAI,OAAO;CACtB,IAAI;EACF,KAAK,mBAAmB,EAAE;CAC5B,QAAQ,CAER;CAYA,MAAM,MAAM,KAAK,iBAAkB;CACnC,MAAM,QAAQ,cAAsC;EAClD,MAAM,KAAK,IAAI,eAAe,SAAS;EACvC,IAAI,CAAC,IAAI,OAAO;EAGhB,OAAO,SAAS,OAAO,KAAK,SAAS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M;GAAE,YAAY;GAAM,iBAAiB,CAAC,OAAO;EAAE,CAAC;EAEvE,MAAM,MACJ,OAAO,OAAO,eAAe,aACzB,OAAO,WAAW,8BAA8B,IAChD,KAAA;EACN,MAAM,kBAAkB,UAAgC;GAiBtD,MAAM,SAAS,WAAW;GAC1B,IAAI,WAAW,UAAU;GACzB,MAAM,WAA0B,MAAM,UAAU,SAAS;GACzD,cAAc,QAAQ;GACtB,UAAU,SACR,KAAK,WAAW,UAAU,KAAK,aAAa,WAAW,OAAO;IAAE;IAAQ;GAAS,CACnF;EACF;EACA,KAAK,iBAAiB,UAAU,cAAc;EAE9C,aAAa;GACX,SAAS,WAAW;GACpB,KAAK,oBAAoB,UAAU,cAAc;EACnD;CACF,GAAG,CAAC,CAAC;CAEL,MAAM,YAAA,GAAWC,MAAAA,YAAAA,EAAa,SAAsB;EAClD,MAAM,WAAW,aAAa,IAAI;EAClC,cAAc,QAAQ;EACtB,cAAc,IAAI;EAClB,SAAS;GAAE,QAAQ;GAAM;EAAS,CAAC;CACrC,GAAG,CAAC,CAAC;CAEL,OAAO;EAAE,QAAQ,MAAM;EAAQ,UAAU,MAAM;EAAU;CAAS;AACpE"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-theme-IHmtrhEt.js","names":[],"sources":["../src/lib/cn.ts","../src/markdown/anchors.ts","../src/layout/use-theme.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]): string {\n return twMerge(clsx(inputs));\n}\n","import GithubSlugger from 'github-slugger';\n\n/**\n * Anchor identity for documentation, in ONE place.\n *\n * Three things have to agree on what `#kak-ustroen-gtin` means: `rehype-slug`,\n * which stamps ids onto headings; the FAQ accordion, which is built from\n * headings but never goes through rehype; and whatever scrolls to a hash. When\n * they disagree the link simply does nothing — no error, no console warning,\n * the page just sits there — so the algorithm lives here and everyone imports it.\n *\n * `github-slugger` is not an extra dependency: `rehype-slug` uses it internally,\n * which is exactly why it is the right choice — matching its output by\n * reimplementing it would be a slow-motion bug in a language with case rules,\n * combining marks and a Cyrillic alphabet.\n */\n\n/** Prefix `rehype-sanitize` renames every id to. See `defaultSchema.clobberPrefix`. */\nexport const DOC_ID_PREFIX = 'user-content-';\n\n/**\n * Slug for a heading's text — the value that appears in a shareable `#hash`.\n *\n * A fresh slugger per call ON PURPOSE. `GithubSlugger` is stateful: it\n * remembers what it has emitted and disambiguates repeats as `foo-1`, `foo-2`.\n * That is right when walking one document top to bottom, and wrong here, where\n * the same heading must produce the same hash every time it is asked about.\n */\nexport function docSlug(text: string): string {\n return new GithubSlugger().slug(text);\n}\n\n/**\n * The current fragment, DECODED, without its `#`.\n *\n * `window.location.hash` hands back a percent-encoded string —\n * `#%D0%BF%D0%BE%D1%87%D0%B5%D0%BC%D1%83…` for `#почему…` — so every\n * comparison against a slug fails, silently, for exactly the alphabet this\n * project writes its documentation in. It works perfectly in English, which is\n * the worst possible way for it to be wrong.\n */\nexport function readDocHash(): string {\n if (typeof window === 'undefined') return '';\n const raw = window.location.hash.replace(/^#/, '');\n if (raw === '') return '';\n try {\n return decodeURIComponent(raw);\n } catch {\n // A malformed escape sequence is not worth throwing over.\n return raw;\n }\n}\n\n/**\n * Find the element a hash points at.\n *\n * Tries the prefixed id first, because a heading inside sanitized Markdown is\n * the common case, then the bare one for anchors we render ourselves (the FAQ\n * accordion, which is built from React and never passes through the sanitizer).\n */\nexport function findDocAnchor(hash: string, root: Document | Element = document): Element | null {\n let id = hash.replace(/^#/, '');\n if (id === '') return null;\n try {\n id = decodeURIComponent(id);\n } catch {\n /* keep the raw form */\n }\n\n /*\n `getElementById`, NOT `querySelector('#'+id)`.\n\n A fragment is user input — it arrives from the address bar — and `#a.b:c`\n is a perfectly ordinary thing to paste and an invalid CSS selector, so\n `querySelector` throws a `SyntaxError` on it. `CSS.escape` would fix that\n where it exists, and it does not exist in jsdom, so the crash would have\n been invisible to the unit suite and live only in production. Looking an id\n up by id involves no selector parsing at all.\n */\n const doc = root.ownerDocument ?? (root as Document);\n const pick = (candidate: string): Element | null => {\n const el = doc.getElementById(candidate);\n if (!el) return null;\n // Scoped lookups must not reach outside their root — the handbook searches\n // within the open article so a stale heading elsewhere cannot win.\n return root === doc || root.contains(el) ? el : null;\n };\n return pick(DOC_ID_PREFIX + id) ?? pick(id);\n}\n\n/**\n * Bring an element to the top of ITS OWN scroll container, and nothing else.\n *\n * `scrollIntoView` cannot be used here. It scrolls EVERY scrollable ancestor,\n * the document included — and the document does scroll in this shell, because\n * `SidebarInset` is `min-h-svh` and the app's own sidebar can exceed a short\n * viewport. Clicking an anchor therefore dragged the whole page up: the app\n * header and the handbook's own search box went off the top of the screen, and\n * the layout read as broken. Caught in a screenshot, not by any assertion.\n *\n * Walking to the nearest scrollable ancestor and moving only that keeps the\n * effect where the reader expects it — inside the column they are reading.\n * `scroll-margin-top` is honoured by hand, since we are no longer going through\n * the API that would apply it.\n */\nfunction placeInScroller(target: Element): void {\n let container = target.parentElement;\n while (container) {\n const style = getComputedStyle(container);\n if (\n /(auto|scroll)/.test(style.overflowY) &&\n container.scrollHeight > container.clientHeight + 1\n ) {\n break;\n }\n container = container.parentElement;\n }\n if (!container) {\n // Nothing between here and the document scrolls; the browser's own\n // behaviour is then exactly right.\n target.scrollIntoView({ block: 'start', behavior: 'auto' });\n return;\n }\n const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;\n const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;\n container.scrollTop += delta;\n}\n\n/**\n * Scroll to an anchor and KEEP it in view while the article settles.\n *\n * One `scrollIntoView` is not enough here. An article's height is not final\n * when its markup lands: a mermaid diagram renders asynchronously and a lazily\n * loaded image has no height until it arrives, and either one appearing ABOVE\n * the target pushes it back down — the reader watches the page scroll to the\n * right place and then drift away from it. Measured: the target ended 731px\n * down a 709px pane, i.e. just off the bottom.\n *\n * So the scroll is repeated whenever the container resizes, for a short window\n * and no longer. The window is a deliberate ceiling rather than a guess at how\n * long rendering takes: after it, the reader owns the scroll position, and\n * yanking it back because a late image loaded would be worse than being a few\n * pixels off.\n */\nexport function scrollToDocAnchor(\n hash: string,\n root: Element = document.body,\n settleMs = 1500,\n): () => void {\n let stopped = false;\n const go = () => {\n if (stopped) return;\n const target = findDocAnchor(hash, root);\n if (target) placeInScroller(target);\n };\n // Two frames: markdown → hast → DOM, then layout.\n const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));\n\n const observer =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => requestAnimationFrame(go));\n observer?.observe(root);\n const timer = setTimeout(() => {\n stopped = true;\n observer?.disconnect();\n }, settleMs);\n\n return () => {\n stopped = true;\n cancelAnimationFrame(raf1);\n observer?.disconnect();\n clearTimeout(timer);\n };\n}\n\n/**\n * A shareable url for an anchor on the current page — READABLE.\n *\n * `new URL(…).toString()` percent-encodes the fragment, so a Russian heading\n * becomes forty characters of `%D0%BF%D0%BE…`. That is correct and unusable:\n * the entire point of this link is being pasted into a message where a person\n * reads it, and a wall of escapes tells them nothing about where it goes.\n * Browsers accept a literal fragment and encode it themselves on navigation.\n *\n * The slug is still escaped if it contains anything that would change how the\n * url PARSES — `#`, `?`, whitespace, or a stray `%`. `github-slugger` does not\n * emit those, but this is the one place where being wrong produces a link that\n * silently points somewhere else.\n */\nexport function docShareUrl(slug: string, href: string = window.location.href): string {\n const url = new URL(href);\n const safe = /[#?%\\s]/.test(slug) ? encodeURIComponent(slug) : slug;\n return `${url.origin}${url.pathname}${url.search}#${safe}`;\n}\n","'use client';\nimport { useCallback, useEffect, useState } from 'react';\nimport { THEME_STORAGE_KEY } from './theme-storage-key.js';\n\n/**\n * Re-exported here so most consumers only need one import path. A pre-paint\n * bootstrap is the one exception — `examples/next/app/layout.tsx` imports the\n * constant from the separate, hook-free `@burojs/ui-shadcn/theme-storage-key`\n * subpath instead; see `./theme-storage-key.js` for why a Server Component\n * cannot import it from here.\n */\nexport { THEME_STORAGE_KEY };\n\n/** What the user picked. `'system'` means \"no explicit choice\" — nothing is\n * persisted for it; its absence from storage IS the `system` state. */\nexport type ThemeChoice = 'light' | 'dark' | 'system';\n\n/** What is actually painted. Never `'system'` — every reader (Toaster,\n * CodeMirror, Mermaid) only ever needs to know light or dark. */\nexport type ResolvedTheme = 'light' | 'dark';\n\nexport interface UseThemeResult {\n /** The persisted preference, including `'system'`. Only the theme\n * submenu (the one place with a three-way control) needs this. */\n choice: ThemeChoice;\n /** The resolved light/dark value, kept in sync with the `dark` class on\n * `<html>`. This is what every read-only consumer wants. */\n resolved: ResolvedTheme;\n /** Set a new choice: applies the `dark` class immediately and persists\n * (or, for `'system'`, clears) the preference. */\n setTheme: (next: ThemeChoice) => void;\n}\n\nfunction systemPrefersDark(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof window.matchMedia === 'function' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches\n );\n}\n\nfunction readChoice(): ThemeChoice {\n if (typeof window === 'undefined') return 'system';\n try {\n const saved = window.localStorage.getItem(THEME_STORAGE_KEY);\n if (saved === 'light' || saved === 'dark') return saved;\n } catch {\n // localStorage may be disabled — fall through to system\n }\n return 'system';\n}\n\nfunction resolveTheme(choice: ThemeChoice): ResolvedTheme {\n if (choice === 'light' || choice === 'dark') return choice;\n return systemPrefersDark() ? 'dark' : 'light';\n}\n\nfunction applyDomClass(resolved: ResolvedTheme): void {\n if (typeof document === 'undefined') return;\n document.documentElement.classList.toggle('dark', resolved === 'dark');\n}\n\nfunction persistChoice(choice: ThemeChoice): void {\n if (typeof window === 'undefined') return;\n try {\n if (choice === 'system') window.localStorage.removeItem(THEME_STORAGE_KEY);\n else window.localStorage.setItem(THEME_STORAGE_KEY, choice);\n } catch {\n // localStorage may be disabled — the class flip already applied.\n }\n}\n\ninterface ThemeState {\n choice: ThemeChoice;\n resolved: ResolvedTheme;\n}\n\n/**\n * Single source of truth for light/dark/system, replacing seven places that\n * each used to know about the theme independently (a bootstrap script, a\n * command-palette action, a submenu, an unused kit component, and three\n * MutationObserver-based readers).\n *\n * Read-only consumers (Toaster, CodeMirror, Mermaid) only need `resolved`\n * and don't call the public `setTheme` — they stay in sync via the\n * `<html class=\"dark\">` MutationObserver below, which fires regardless of\n * WHICH writer flipped it. That is deliberate: it's the same mechanism these\n * three already used individually before this hook existed, now shared\n * instead of duplicated, and it means a future writer doesn't need to know\n * about every reader. Every mounted instance — including these \"read-only\"\n * ones — still runs its OWN `onSystemChange` listener below and applies the\n * class itself on an OS change; see that listener for why re-reading storage\n * there (rather than trusting this instance's local `choice`) is required\n * for that to be safe with several instances mounted at once.\n *\n * `choice` (the three-way value, including `'system'`) is NOT synchronized\n * the same way — the `dark` class alone can't tell \"explicitly dark\" apart\n * from \"system, and the system happens to be dark\". The only consumer that\n * needs `choice` is the theme submenu, and Radix unmounts a closed dropdown's\n * content, so it re-reads storage fresh every time it opens; no live\n * cross-component sync of `choice` is needed in practice.\n *\n * NOT used by the bootstrap `<script>` in `app/layout.tsx` — see the comment\n * there for why a hook cannot do that job.\n */\nexport function useTheme(): UseThemeResult {\n // Safe default for the very first client render, corrected synchronously\n // by the effect below on mount — mirrors the pattern the three readers\n // used before migrating here (start light/false, fix it post-mount) so no\n // component newly grows a hydration-mismatch warning.\n const [state, setState] = useState<ThemeState>({ choice: 'system', resolved: 'light' });\n\n useEffect(() => {\n const choice = readChoice();\n setState({ choice, resolved: resolveTheme(choice) });\n\n const root = document.documentElement;\n const observer = new MutationObserver(() => {\n const resolved: ResolvedTheme = root.classList.contains('dark') ? 'dark' : 'light';\n setState((prev) => (prev.resolved === resolved ? prev : { ...prev, resolved }));\n });\n observer.observe(root, { attributes: true, attributeFilter: ['class'] });\n\n const mql =\n typeof window.matchMedia === 'function'\n ? window.matchMedia('(prefers-color-scheme: dark)')\n : undefined;\n const onSystemChange = (event: { matches: boolean }) => {\n // Re-read the stored choice instead of trusting this instance's own\n // `prev.choice`: `choice` is captured once at mount and never\n // resynchronised, but several `useTheme()` instances mount at once\n // (Toaster, CodeMirror, Mermaid, the admin layout, the theme submenu\n // while open). If a later explicit pick only updates the instance that\n // made it, every OTHER instance still believes `system` applies and\n // would repaint the whole app back to the OS value on the next\n // preference flip — silently overriding storage, which is why this\n // must not trust local state. Storage is already the single source of\n // truth (`setTheme('system')` clears the key), so a fresh read here is\n // correct in both directions: an explicit pick is respected, and\n // `system` is honoured even once the one instance that set it has\n // unmounted. Every other live instance's listener fires on the same OS\n // change and independently reaches the same conclusion, so several\n // instances may call `applyDomClass` with the same value for one\n // event — redundant, but harmless, and not worth coordinating.\n const choice = readChoice();\n if (choice !== 'system') return;\n const resolved: ResolvedTheme = event.matches ? 'dark' : 'light';\n applyDomClass(resolved);\n setState((prev) =>\n prev.choice === choice && prev.resolved === resolved ? prev : { choice, resolved },\n );\n };\n mql?.addEventListener('change', onSystemChange);\n\n return () => {\n observer.disconnect();\n mql?.removeEventListener('change', onSystemChange);\n };\n }, []);\n\n const setTheme = useCallback((next: ThemeChoice) => {\n const resolved = resolveTheme(next);\n applyDomClass(resolved);\n persistChoice(next);\n setState({ choice: next, resolved });\n }, []);\n\n return { choice: state.choice, resolved: state.resolved, setTheme };\n}\n"],"mappings":";;;;;;AAGA,SAAgB,GAAG,GAAG,QAA8B;CAClD,OAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;;;ACaA,MAAa,gBAAgB;AAU7B,SAAgB,QAAQ,MAAsB;CAC5C,OAAO,IAAI,cAAc,CAAC,CAAC,KAAK,IAAI;AACtC;AAWA,SAAgB,cAAsB;CACpC,IAAI,OAAO,WAAW,aAAa,OAAO;CAC1C,MAAM,MAAM,OAAO,SAAS,KAAK,QAAQ,MAAM,EAAE;CACjD,IAAI,QAAQ,IAAI,OAAO;CACvB,IAAI;EACF,OAAO,mBAAmB,GAAG;CAC/B,QAAQ;EAEN,OAAO;CACT;AACF;AASA,SAAgB,cAAc,MAAc,OAA2B,UAA0B;CAC/F,IAAI,KAAK,KAAK,QAAQ,MAAM,EAAE;CAC9B,IAAI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