@burojs/ui-shadcn 0.3.0 → 0.5.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.
- package/README.md +26 -7
- package/dist/bulk-summary-CwSd6Yjb.cjs +108 -0
- package/dist/bulk-summary-CwSd6Yjb.cjs.map +1 -0
- package/dist/bulk-summary-GxMDP4bw.js +108 -0
- package/dist/bulk-summary-GxMDP4bw.js.map +1 -0
- package/dist/button-BxnnE28H.cjs +55 -0
- package/dist/button-BxnnE28H.cjs.map +1 -0
- package/dist/button-MWVeZaqj.js +44 -0
- package/dist/button-MWVeZaqj.js.map +1 -0
- package/dist/candidates-gate-CX2PBu6l.js +63 -0
- package/dist/candidates-gate-CX2PBu6l.js.map +1 -0
- package/dist/candidates-gate-DiFI52r7.cjs +70 -0
- package/dist/candidates-gate-DiFI52r7.cjs.map +1 -0
- package/dist/candidates-relation-picker-CBsVcnPR.js +82 -0
- package/dist/candidates-relation-picker-CBsVcnPR.js.map +1 -0
- package/dist/candidates-relation-picker-Dd_GVLlu.cjs +84 -0
- package/dist/candidates-relation-picker-Dd_GVLlu.cjs.map +1 -0
- package/dist/check-confirm-dialog-BRByTFpg.cjs +1534 -0
- package/dist/check-confirm-dialog-BRByTFpg.cjs.map +1 -0
- package/dist/check-confirm-dialog-CkaVTPT9.js +1232 -0
- package/dist/check-confirm-dialog-CkaVTPT9.js.map +1 -0
- package/dist/dialog-B_rt9S1c.js +63 -0
- package/dist/dialog-B_rt9S1c.js.map +1 -0
- package/dist/dialog-DRNUq9EA.cjs +112 -0
- package/dist/dialog-DRNUq9EA.cjs.map +1 -0
- package/dist/filter-builder-B3mZFL-K.cjs +1761 -0
- package/dist/filter-builder-B3mZFL-K.cjs.map +1 -0
- package/dist/filter-builder-DOnaXNfP.js +1605 -0
- package/dist/filter-builder-DOnaXNfP.js.map +1 -0
- package/dist/flow-runtime-B6zOHYqI.cjs +255 -0
- package/dist/flow-runtime-B6zOHYqI.cjs.map +1 -0
- package/dist/flow-runtime-D8h99FSg.js +252 -0
- package/dist/flow-runtime-D8h99FSg.js.map +1 -0
- package/dist/flow-screen-CX05b3G9.cjs +705 -0
- package/dist/flow-screen-CX05b3G9.cjs.map +1 -0
- package/dist/flow-screen-CmbARSqg.js +701 -0
- package/dist/flow-screen-CmbARSqg.js.map +1 -0
- package/dist/index.cjs +6453 -17494
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3754 -3621
- package/dist/index.d.ts +3754 -3621
- package/dist/index.js +6217 -17219
- package/dist/index.js.map +1 -1
- package/dist/inline-flow-host-B7U1OJUe.cjs +112 -0
- package/dist/inline-flow-host-B7U1OJUe.cjs.map +1 -0
- package/dist/inline-flow-host-C3H2UpSA.js +112 -0
- package/dist/inline-flow-host-C3H2UpSA.js.map +1 -0
- package/dist/input-BI0czGyI.cjs +23 -0
- package/dist/input-BI0czGyI.cjs.map +1 -0
- package/dist/input-CUPStzZO.js +17 -0
- package/dist/input-CUPStzZO.js.map +1 -0
- package/dist/label-66W1qbke.js +29 -0
- package/dist/label-66W1qbke.js.map +1 -0
- package/dist/label-w6JYf2cF.cjs +36 -0
- package/dist/label-w6JYf2cF.cjs.map +1 -0
- package/dist/layout/theme-storage-key.cjs +5 -10
- package/dist/layout/theme-storage-key.cjs.map +1 -1
- package/dist/layout/theme-storage-key.d.cts +2 -23
- package/dist/layout/theme-storage-key.d.ts +2 -23
- package/dist/layout/theme-storage-key.js +5 -2
- package/dist/layout/theme-storage-key.js.map +1 -1
- package/dist/lazy-relation-picker-dialog-2oxnA6IR.js +14 -0
- package/dist/lazy-relation-picker-dialog-2oxnA6IR.js.map +1 -0
- package/dist/lazy-relation-picker-dialog-BfAGKzUG.cjs +19 -0
- package/dist/lazy-relation-picker-dialog-BfAGKzUG.cjs.map +1 -0
- package/dist/markdown/index.cjs +424 -511
- package/dist/markdown/index.cjs.map +1 -1
- package/dist/markdown/index.d.cts +1072 -34
- package/dist/markdown/index.d.ts +1072 -34
- package/dist/markdown/index.js +411 -459
- package/dist/markdown/index.js.map +1 -1
- package/dist/page-flow-route-CQ7HsbBm.cjs +277 -0
- package/dist/page-flow-route-CQ7HsbBm.cjs.map +1 -0
- package/dist/page-flow-route-CyXSvXSE.js +277 -0
- package/dist/page-flow-route-CyXSvXSE.js.map +1 -0
- package/dist/peek-filter-CnqHwTMU.cjs +51 -0
- package/dist/peek-filter-CnqHwTMU.cjs.map +1 -0
- package/dist/peek-filter-ErLfO153.js +28 -0
- package/dist/peek-filter-ErLfO153.js.map +1 -0
- package/dist/place-node--GdsP688.js +7315 -0
- package/dist/place-node--GdsP688.js.map +1 -0
- package/dist/place-node-SIp4XYQH.cjs +7833 -0
- package/dist/place-node-SIp4XYQH.cjs.map +1 -0
- package/dist/related-list-cards-B6x9HQQp.js +42 -0
- package/dist/related-list-cards-B6x9HQQp.js.map +1 -0
- package/dist/related-list-cards-nxuODlIA.cjs +42 -0
- package/dist/related-list-cards-nxuODlIA.cjs.map +1 -0
- package/dist/related-list-timeline-BYJKEbmA.cjs +142 -0
- package/dist/related-list-timeline-BYJKEbmA.cjs.map +1 -0
- package/dist/related-list-timeline-DEdfd-rr.js +142 -0
- package/dist/related-list-timeline-DEdfd-rr.js.map +1 -0
- package/dist/related-rows-B4levHcR.js +186 -0
- package/dist/related-rows-B4levHcR.js.map +1 -0
- package/dist/related-rows-zh5f_4QR.cjs +209 -0
- package/dist/related-rows-zh5f_4QR.cjs.map +1 -0
- package/dist/relation-create-BOaUe12G.cjs +362 -0
- package/dist/relation-create-BOaUe12G.cjs.map +1 -0
- package/dist/relation-create-Bg-eEJLs.js +337 -0
- package/dist/relation-create-Bg-eEJLs.js.map +1 -0
- package/dist/relation-many-picker-B-NCEUgX.cjs +465 -0
- package/dist/relation-many-picker-B-NCEUgX.cjs.map +1 -0
- package/dist/relation-many-picker-gdAOD-qK.js +464 -0
- package/dist/relation-many-picker-gdAOD-qK.js.map +1 -0
- package/dist/relation-picker-BAY77ivO.js +462 -0
- package/dist/relation-picker-BAY77ivO.js.map +1 -0
- package/dist/relation-picker-Da_uhFvA.cjs +479 -0
- package/dist/relation-picker-Da_uhFvA.cjs.map +1 -0
- package/dist/relation-picker-dialog-M0pQaWlp.cjs +300 -0
- package/dist/relation-picker-dialog-M0pQaWlp.cjs.map +1 -0
- package/dist/relation-picker-dialog-hA9rYrZB.js +299 -0
- package/dist/relation-picker-dialog-hA9rYrZB.js.map +1 -0
- package/dist/resource-page-router-OSQyRA5b.cjs +1779 -0
- package/dist/resource-page-router-OSQyRA5b.cjs.map +1 -0
- package/dist/resource-page-router-T4vS5gbJ.js +1582 -0
- package/dist/resource-page-router-T4vS5gbJ.js.map +1 -0
- package/dist/rich-text-DFerywgz.js +457 -0
- package/dist/rich-text-DFerywgz.js.map +1 -0
- package/dist/rich-text-vTyVjDoa.cjs +460 -0
- package/dist/rich-text-vTyVjDoa.cjs.map +1 -0
- package/dist/search-access-B7G5oR8n.cjs +812 -0
- package/dist/search-access-B7G5oR8n.cjs.map +1 -0
- package/dist/search-access-CURsWn-U.js +669 -0
- package/dist/search-access-CURsWn-U.js.map +1 -0
- package/dist/shell-BPlk8hEa.js +205 -0
- package/dist/shell-BPlk8hEa.js.map +1 -0
- package/dist/shell-DxhlsPwm.cjs +271 -0
- package/dist/shell-DxhlsPwm.cjs.map +1 -0
- package/dist/skeleton-U2noefj5.js +13 -0
- package/dist/skeleton-U2noefj5.js.map +1 -0
- package/dist/skeleton-_1gP7wan.cjs +18 -0
- package/dist/skeleton-_1gP7wan.cjs.map +1 -0
- package/dist/styles.css +255 -17
- package/dist/theme/theme-css.cjs +95 -96
- package/dist/theme/theme-css.cjs.map +1 -1
- package/dist/theme/theme-css.d.cts +10 -8
- package/dist/theme/theme-css.d.ts +10 -8
- package/dist/theme/theme-css.js +94 -94
- package/dist/theme/theme-css.js.map +1 -1
- package/dist/theme/theme-storage.cjs +34 -39
- package/dist/theme/theme-storage.cjs.map +1 -1
- package/dist/theme/theme-storage.d.cts +3 -1
- package/dist/theme/theme-storage.d.ts +3 -1
- package/dist/theme/theme-storage.js +33 -37
- package/dist/theme/theme-storage.js.map +1 -1
- package/dist/theme-storage-key-pYlp4aDS.d.cts +31 -0
- package/dist/theme-storage-key-pYlp4aDS.d.ts +31 -0
- package/dist/toaster-C7CiYA4Z.cjs +248 -0
- package/dist/toaster-C7CiYA4Z.cjs.map +1 -0
- package/dist/toaster-CfCRLgR-.js +164 -0
- package/dist/toaster-CfCRLgR-.js.map +1 -0
- package/dist/use-dialog-filter-state-BBCC0OEK.cjs +92 -0
- package/dist/use-dialog-filter-state-BBCC0OEK.cjs.map +1 -0
- package/dist/use-dialog-filter-state-BDcgS5Oz.js +87 -0
- package/dist/use-dialog-filter-state-BDcgS5Oz.js.map +1 -0
- package/dist/use-theme-DFlpXils.cjs +257 -0
- package/dist/use-theme-DFlpXils.cjs.map +1 -0
- package/dist/use-theme-dnE3Od3I.js +175 -0
- package/dist/use-theme-dnE3Od3I.js.map +1 -0
- package/package.json +18 -17
- package/dist/chunk-ABUQPOOE.js +0 -11
- package/dist/chunk-ABUQPOOE.js.map +0 -1
- package/dist/chunk-DBGGWBFG.cjs +0 -199
- package/dist/chunk-DBGGWBFG.cjs.map +0 -1
- package/dist/chunk-FMX4GLCQ.js +0 -6
- package/dist/chunk-FMX4GLCQ.js.map +0 -1
- package/dist/chunk-UC57Z243.js +0 -143
- package/dist/chunk-UC57Z243.js.map +0 -1
- package/dist/chunk-UPGPO75B.js +0 -164
- package/dist/chunk-UPGPO75B.js.map +0 -1
- package/dist/chunk-VXJAXJ3U.cjs +0 -8
- package/dist/chunk-VXJAXJ3U.cjs.map +0 -1
- package/dist/chunk-W7AEYE7A.cjs +0 -13
- package/dist/chunk-W7AEYE7A.cjs.map +0 -1
- package/dist/chunk-YF5IW525.cjs +0 -155
- package/dist/chunk-YF5IW525.cjs.map +0 -1
- package/dist/rich-text-6V7WZ3WV.cjs +0 -518
- package/dist/rich-text-6V7WZ3WV.cjs.map +0 -1
- package/dist/rich-text-N2FZEJJV.js +0 -491
- package/dist/rich-text-N2FZEJJV.js.map +0 -1
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { n as narrowSearchDecl, t as namesHiddenField } from "./search-access-CURsWn-U.js";
|
|
2
|
+
import { EMPTY_FILTER_GROUP, composeListFilter } from "@burojs/core";
|
|
3
|
+
import { useApp, useFilterFields, useListAccess } from "@burojs/react";
|
|
4
|
+
import { useCallback, useMemo, useState } from "react";
|
|
5
|
+
//#region src/fields/use-dialog-filter-state.ts
|
|
6
|
+
function useDialogFilterState(resource, options) {
|
|
7
|
+
const def = useApp().registry.get(resource);
|
|
8
|
+
const { available, fixed } = useFilterFields(resource, {
|
|
9
|
+
fixedFilters: options.fixedFilters,
|
|
10
|
+
enabled: options.enabled
|
|
11
|
+
});
|
|
12
|
+
const [group, setGroupState] = useState(EMPTY_FILTER_GROUP);
|
|
13
|
+
const [search, setSearchState] = useState("");
|
|
14
|
+
const [page, setPage] = useState(1);
|
|
15
|
+
const setGroup = useCallback((next) => {
|
|
16
|
+
setGroupState(next);
|
|
17
|
+
setPage(1);
|
|
18
|
+
}, []);
|
|
19
|
+
const setSearch = useCallback((next) => {
|
|
20
|
+
setSearchState(next);
|
|
21
|
+
setPage(1);
|
|
22
|
+
}, []);
|
|
23
|
+
const reset = useCallback(() => {
|
|
24
|
+
setGroupState(EMPTY_FILTER_GROUP);
|
|
25
|
+
setSearchState("");
|
|
26
|
+
setPage(1);
|
|
27
|
+
}, []);
|
|
28
|
+
const { searchField } = options;
|
|
29
|
+
const access = useListAccess(resource);
|
|
30
|
+
const accessReady = access.status === "ready";
|
|
31
|
+
const searchDecl = useMemo(() => {
|
|
32
|
+
const declared = def?.views?.list?.search;
|
|
33
|
+
return narrowSearchDecl(declared !== void 0 ? declared : searchField === void 0 ? void 0 : { fields: [searchField] }, (field) => access.fieldVisible(field));
|
|
34
|
+
}, [
|
|
35
|
+
def,
|
|
36
|
+
searchField,
|
|
37
|
+
access
|
|
38
|
+
]);
|
|
39
|
+
const searchContext = useMemo(() => ({
|
|
40
|
+
resource,
|
|
41
|
+
def
|
|
42
|
+
}), [resource, def]);
|
|
43
|
+
const filter = useMemo(() => composeListFilter({
|
|
44
|
+
fixed,
|
|
45
|
+
group,
|
|
46
|
+
search,
|
|
47
|
+
searchDecl,
|
|
48
|
+
searchContext
|
|
49
|
+
}), [
|
|
50
|
+
fixed,
|
|
51
|
+
group,
|
|
52
|
+
search,
|
|
53
|
+
searchDecl,
|
|
54
|
+
searchContext
|
|
55
|
+
]);
|
|
56
|
+
const blocked = !accessReady || namesHiddenField(filter, (field) => access.fieldVisible(field));
|
|
57
|
+
return useMemo(() => ({
|
|
58
|
+
searchEnabled: searchDecl !== void 0,
|
|
59
|
+
blocked,
|
|
60
|
+
group,
|
|
61
|
+
setGroup,
|
|
62
|
+
search,
|
|
63
|
+
setSearch,
|
|
64
|
+
page,
|
|
65
|
+
setPage,
|
|
66
|
+
available,
|
|
67
|
+
fixed,
|
|
68
|
+
filter,
|
|
69
|
+
reset
|
|
70
|
+
}), [
|
|
71
|
+
group,
|
|
72
|
+
setGroup,
|
|
73
|
+
search,
|
|
74
|
+
setSearch,
|
|
75
|
+
page,
|
|
76
|
+
available,
|
|
77
|
+
fixed,
|
|
78
|
+
filter,
|
|
79
|
+
reset,
|
|
80
|
+
searchDecl,
|
|
81
|
+
blocked
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
export { useDialogFilterState as t };
|
|
86
|
+
|
|
87
|
+
//# sourceMappingURL=use-dialog-filter-state-BDcgS5Oz.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-dialog-filter-state-BDcgS5Oz.js","names":[],"sources":["../src/fields/use-dialog-filter-state.ts"],"sourcesContent":["import {\n EMPTY_FILTER_GROUP,\n composeListFilter,\n type ErasedResourceHandle,\n type FilterExpression,\n type FilterGroup,\n type FixedFilterInput,\n type ResolvedFixedFilter,\n type SearchDecl,\n} from '@burojs/core';\nimport { useApp, useFilterFields, useListAccess, type FilterFieldSpec } from '@burojs/react';\nimport { namesHiddenField, narrowSearchDecl } from './search-access.js';\nimport { useCallback, useMemo, useState } from 'react';\n\n/** The portable erased AST — the only shape this module deals in. */\ntype ErasedExpression = FilterExpression<ErasedResourceHandle>;\n\n/** Options for {@link useDialogFilterState}. */\nexport interface UseDialogFilterStateOptions {\n /** Call-site narrowing (e.g. scope the target list to a product group). */\n readonly fixedFilters?: readonly FixedFilterInput[];\n /**\n * Fallback search field, used ONLY when the target resource declares no\n * `views.list.search`. Wrapped into a single-field `SearchFieldsDecl`\n * (`{ fields: [searchField] }`, implicit `contains` — same degenerate form\n * `searchToFilter` already gives a bare field-name string) so the override\n * goes through the exact same `composeListFilter` → `searchToFilter` path\n * as a real declaration, rather than a second hand-built predicate at the\n * call site. The target's own declaration always wins when present — this\n * is a fallback, not an override of a declared search.\n */\n readonly searchField?: string;\n /**\n * Gates the field-derivation walk (`useFilterFields`'s `categorizeField`\n * pass over every field of the resource). Defaults to `true`. A caller\n * whose UI isn't visible yet (e.g. `RelationPickerDialog` before it's\n * opened) should pass `false` to skip that work on every mount /\n * `fixedFilters`-identity change; the derivation recomputes in full the\n * next render where this flips back to `true`.\n */\n readonly enabled?: boolean;\n}\n\n/** Return shape of {@link useDialogFilterState}. */\nexport interface DialogFilterState {\n readonly group: FilterGroup;\n readonly setGroup: (next: FilterGroup) => void;\n readonly search: string;\n readonly setSearch: (next: string) => void;\n readonly page: number;\n readonly setPage: (page: number) => void;\n readonly available: readonly FilterFieldSpec[];\n readonly fixed: readonly ResolvedFixedFilter[];\n /** The single expression to hand the data provider. */\n readonly filter: ErasedExpression | undefined;\n /** Whether the target has a search for this user (no field left means no search box). */\n readonly searchEnabled: boolean;\n /** The read must not be sent: undecided access, or a filter naming a field the user may not view. */\n readonly blocked: boolean;\n readonly reset: () => void;\n}\n\n/**\n * Local (non-URL) filter state for the relation-picker's advanced-search\n * dialog.\n *\n * `useResourceList` cannot serve this: it unconditionally calls\n * `useResourceUrlState`, which throws without a `RouterAdapterProvider` and,\n * when one IS present, writes to `?<resource>.*`. A picker dialog mounted\n * inside a form for resource A, searching TARGET resource B, would then\n * write B's list state into the URL — clobbering a real B list page open on\n * another tab of the same app, and reading back whatever that page last\n * wrote on open. So this hook keeps `group`/`search`/`page` in plain\n * `useState` and reuses the SAME composition core's list controller uses\n * (`composeListFilter`) so the two never drift on what a filter means.\n *\n * No `pinned` slot: pinned controls are a list-PAGE affordance (permanent\n * screen real estate for a couple of always-visible facets); a modal has no\n * spare real estate to spend on them.\n */\nexport function useDialogFilterState(\n resource: string,\n options: UseDialogFilterStateOptions,\n): DialogFilterState {\n const app = useApp();\n const def = app.registry.get(resource);\n const { available, fixed } = useFilterFields(resource, {\n fixedFilters: options.fixedFilters,\n enabled: options.enabled,\n });\n\n const [group, setGroupState] = useState<FilterGroup>(EMPTY_FILTER_GROUP);\n const [search, setSearchState] = useState('');\n const [page, setPage] = useState(1);\n\n // Any change to WHAT is filtered invalidates the current page — the same\n // rule `useResourceList`'s URL-state controller applies to its own\n // group/search setters.\n const setGroup = useCallback((next: FilterGroup) => {\n setGroupState(next);\n setPage(1);\n }, []);\n\n const setSearch = useCallback((next: string) => {\n setSearchState(next);\n setPage(1);\n }, []);\n\n const reset = useCallback(() => {\n setGroupState(EMPTY_FILTER_GROUP);\n setSearchState('');\n setPage(1);\n }, []);\n\n // The target's own declaration always wins; `options.searchField` only\n // fills in when the target declares no search at all. Memoized so an\n // omitted declaration doesn't hand `composeListFilter`'s `filter` memo a\n // fresh `{ fields: [...] }` literal (and therefore a spurious recompute)\n // on every render — see `UseDialogFilterStateOptions.searchField`'s doc.\n const { searchField } = options;\n const access = useListAccess(resource);\n const accessReady = access.status === 'ready';\n const searchDecl = useMemo<SearchDecl | undefined>(() => {\n const declared = def?.views?.list?.search;\n const base =\n declared !== undefined\n ? declared\n : searchField === undefined\n ? undefined\n : { fields: [searchField] };\n return narrowSearchDecl(base, (field) => access.fieldVisible(field));\n }, [def, searchField, access]);\n const searchContext = useMemo(() => ({ resource, def }), [resource, def]);\n\n const filter = useMemo<ErasedExpression | undefined>(\n () => composeListFilter({ fixed, group, search, searchDecl, searchContext }),\n [fixed, group, search, searchDecl, searchContext],\n );\n\n // A read whose composed filter names a field the user may not view is forbidden (an author\n // predicate, or a function search's output); an undecided access sends nothing yet.\n const blocked = !accessReady || namesHiddenField(filter, (field) => access.fieldVisible(field));\n\n return useMemo<DialogFilterState>(\n () => ({\n searchEnabled: searchDecl !== undefined,\n blocked,\n group,\n setGroup,\n search,\n setSearch,\n page,\n setPage,\n available,\n fixed,\n filter,\n reset,\n }),\n [\n group,\n setGroup,\n search,\n setSearch,\n page,\n available,\n fixed,\n filter,\n reset,\n searchDecl,\n blocked,\n ],\n );\n}\n"],"mappings":";;;;;AAgFA,SAAgB,qBACd,UACA,SACmB;CAEnB,MAAM,MADM,OACE,CAAC,CAAC,SAAS,IAAI,QAAQ;CACrC,MAAM,EAAE,WAAW,UAAU,gBAAgB,UAAU;EACrD,cAAc,QAAQ;EACtB,SAAS,QAAQ;CACnB,CAAC;CAED,MAAM,CAAC,OAAO,iBAAiB,SAAsB,kBAAkB;CACvE,MAAM,CAAC,QAAQ,kBAAkB,SAAS,EAAE;CAC5C,MAAM,CAAC,MAAM,WAAW,SAAS,CAAC;CAKlC,MAAM,WAAW,aAAa,SAAsB;EAClD,cAAc,IAAI;EAClB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,YAAY,aAAa,SAAiB;EAC9C,eAAe,IAAI;EACnB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAEL,MAAM,QAAQ,kBAAkB;EAC9B,cAAc,kBAAkB;EAChC,eAAe,EAAE;EACjB,QAAQ,CAAC;CACX,GAAG,CAAC,CAAC;CAOL,MAAM,EAAE,gBAAgB;CACxB,MAAM,SAAS,cAAc,QAAQ;CACrC,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,aAAa,cAAsC;EACvD,MAAM,WAAW,KAAK,OAAO,MAAM;EAOnC,OAAO,iBALL,aAAa,KAAA,IACT,WACA,gBAAgB,KAAA,IACd,KAAA,IACA,EAAE,QAAQ,CAAC,WAAW,EAAE,IACD,UAAU,OAAO,aAAa,KAAK,CAAC;CACrE,GAAG;EAAC;EAAK;EAAa;CAAM,CAAC;CAC7B,MAAM,gBAAgB,eAAe;EAAE;EAAU;CAAI,IAAI,CAAC,UAAU,GAAG,CAAC;CAExE,MAAM,SAAS,cACP,kBAAkB;EAAE;EAAO;EAAO;EAAQ;EAAY;CAAc,CAAC,GAC3E;EAAC;EAAO;EAAO;EAAQ;EAAY;CAAa,CAClD;CAIA,MAAM,UAAU,CAAC,eAAe,iBAAiB,SAAS,UAAU,OAAO,aAAa,KAAK,CAAC;CAE9F,OAAO,eACE;EACL,eAAe,eAAe,KAAA;EAC9B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,IACA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CACF;AACF"}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
const require_layout_theme_storage_key = require("./layout/theme-storage-key.cjs");
|
|
24
|
+
let react = require("react");
|
|
25
|
+
let clsx = require("clsx");
|
|
26
|
+
let tailwind_merge = require("tailwind-merge");
|
|
27
|
+
let github_slugger = require("github-slugger");
|
|
28
|
+
github_slugger = __toESM(github_slugger, 1);
|
|
29
|
+
//#region src/lib/cn.ts
|
|
30
|
+
function cn(...inputs) {
|
|
31
|
+
return (0, tailwind_merge.twMerge)((0, clsx.clsx)(inputs));
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/markdown/anchors.ts
|
|
35
|
+
const DOC_ID_PREFIX = "user-content-";
|
|
36
|
+
function docSlug(text) {
|
|
37
|
+
return new github_slugger.default().slug(text);
|
|
38
|
+
}
|
|
39
|
+
function readDocHash() {
|
|
40
|
+
if (typeof window === "undefined") return "";
|
|
41
|
+
const raw = window.location.hash.replace(/^#/, "");
|
|
42
|
+
if (raw === "") return "";
|
|
43
|
+
try {
|
|
44
|
+
return decodeURIComponent(raw);
|
|
45
|
+
} catch {
|
|
46
|
+
return raw;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function findDocAnchor(hash, root = document) {
|
|
50
|
+
let id = hash.replace(/^#/, "");
|
|
51
|
+
if (id === "") return null;
|
|
52
|
+
try {
|
|
53
|
+
id = decodeURIComponent(id);
|
|
54
|
+
} catch {}
|
|
55
|
+
const doc = root.ownerDocument ?? root;
|
|
56
|
+
const pick = (candidate) => {
|
|
57
|
+
const el = doc.getElementById(candidate);
|
|
58
|
+
if (!el) return null;
|
|
59
|
+
return root === doc || root.contains(el) ? el : null;
|
|
60
|
+
};
|
|
61
|
+
return pick("user-content-" + id) ?? pick(id);
|
|
62
|
+
}
|
|
63
|
+
function placeInScroller(target) {
|
|
64
|
+
let container = target.parentElement;
|
|
65
|
+
while (container) {
|
|
66
|
+
const style = getComputedStyle(container);
|
|
67
|
+
if (/(auto|scroll)/.test(style.overflowY) && container.scrollHeight > container.clientHeight + 1) break;
|
|
68
|
+
container = container.parentElement;
|
|
69
|
+
}
|
|
70
|
+
if (!container) {
|
|
71
|
+
target.scrollIntoView({
|
|
72
|
+
block: "start",
|
|
73
|
+
behavior: "auto"
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;
|
|
78
|
+
const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;
|
|
79
|
+
container.scrollTop += delta;
|
|
80
|
+
}
|
|
81
|
+
function scrollToDocAnchor(hash, root = document.body, settleMs = 1500) {
|
|
82
|
+
let stopped = false;
|
|
83
|
+
const go = () => {
|
|
84
|
+
if (stopped) return;
|
|
85
|
+
const target = findDocAnchor(hash, root);
|
|
86
|
+
if (target) placeInScroller(target);
|
|
87
|
+
};
|
|
88
|
+
const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));
|
|
89
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => requestAnimationFrame(go));
|
|
90
|
+
observer?.observe(root);
|
|
91
|
+
const timer = setTimeout(() => {
|
|
92
|
+
stopped = true;
|
|
93
|
+
observer?.disconnect();
|
|
94
|
+
}, settleMs);
|
|
95
|
+
return () => {
|
|
96
|
+
stopped = true;
|
|
97
|
+
cancelAnimationFrame(raf1);
|
|
98
|
+
observer?.disconnect();
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function docShareUrl(slug, href = window.location.href) {
|
|
103
|
+
const url = new URL(href);
|
|
104
|
+
const safe = /[#?%\s]/.test(slug) ? encodeURIComponent(slug) : slug;
|
|
105
|
+
return `${url.origin}${url.pathname}${url.search}#${safe}`;
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/layout/use-theme.ts
|
|
109
|
+
const THEME_CHOICES = [
|
|
110
|
+
"light",
|
|
111
|
+
"dark",
|
|
112
|
+
"system"
|
|
113
|
+
];
|
|
114
|
+
function systemPrefersDark() {
|
|
115
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
116
|
+
}
|
|
117
|
+
function readChoice() {
|
|
118
|
+
if (typeof window === "undefined") return "system";
|
|
119
|
+
try {
|
|
120
|
+
const saved = window.localStorage.getItem(require_layout_theme_storage_key.THEME_STORAGE_KEY);
|
|
121
|
+
if (saved === "light" || saved === "dark") return saved;
|
|
122
|
+
} catch {}
|
|
123
|
+
return "system";
|
|
124
|
+
}
|
|
125
|
+
function resolveTheme(choice) {
|
|
126
|
+
if (choice === "light" || choice === "dark") return choice;
|
|
127
|
+
return systemPrefersDark() ? "dark" : "light";
|
|
128
|
+
}
|
|
129
|
+
function applyDomClass(resolved) {
|
|
130
|
+
if (typeof document === "undefined") return;
|
|
131
|
+
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
132
|
+
}
|
|
133
|
+
function persistChoice(choice) {
|
|
134
|
+
if (typeof window === "undefined") return;
|
|
135
|
+
try {
|
|
136
|
+
if (choice === "system") window.localStorage.removeItem(require_layout_theme_storage_key.THEME_STORAGE_KEY);
|
|
137
|
+
else window.localStorage.setItem(require_layout_theme_storage_key.THEME_STORAGE_KEY, choice);
|
|
138
|
+
} catch {}
|
|
139
|
+
}
|
|
140
|
+
function useTheme() {
|
|
141
|
+
const [state, setState] = (0, react.useState)({
|
|
142
|
+
choice: "system",
|
|
143
|
+
resolved: "light"
|
|
144
|
+
});
|
|
145
|
+
(0, react.useEffect)(() => {
|
|
146
|
+
const choice = readChoice();
|
|
147
|
+
setState({
|
|
148
|
+
choice,
|
|
149
|
+
resolved: resolveTheme(choice)
|
|
150
|
+
});
|
|
151
|
+
const root = document.documentElement;
|
|
152
|
+
const observer = new MutationObserver(() => {
|
|
153
|
+
const resolved = root.classList.contains("dark") ? "dark" : "light";
|
|
154
|
+
setState((prev) => prev.resolved === resolved ? prev : {
|
|
155
|
+
...prev,
|
|
156
|
+
resolved
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
observer.observe(root, {
|
|
160
|
+
attributes: true,
|
|
161
|
+
attributeFilter: ["class"]
|
|
162
|
+
});
|
|
163
|
+
const mql = typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
164
|
+
const onSystemChange = (event) => {
|
|
165
|
+
const choice = readChoice();
|
|
166
|
+
if (choice !== "system") return;
|
|
167
|
+
const resolved = event.matches ? "dark" : "light";
|
|
168
|
+
applyDomClass(resolved);
|
|
169
|
+
setState((prev) => prev.choice === choice && prev.resolved === resolved ? prev : {
|
|
170
|
+
choice,
|
|
171
|
+
resolved
|
|
172
|
+
});
|
|
173
|
+
};
|
|
174
|
+
mql?.addEventListener("change", onSystemChange);
|
|
175
|
+
return () => {
|
|
176
|
+
observer.disconnect();
|
|
177
|
+
mql?.removeEventListener("change", onSystemChange);
|
|
178
|
+
};
|
|
179
|
+
}, []);
|
|
180
|
+
const setTheme = (0, react.useCallback)((next) => {
|
|
181
|
+
const resolved = resolveTheme(next);
|
|
182
|
+
applyDomClass(resolved);
|
|
183
|
+
persistChoice(next);
|
|
184
|
+
setState({
|
|
185
|
+
choice: next,
|
|
186
|
+
resolved
|
|
187
|
+
});
|
|
188
|
+
}, []);
|
|
189
|
+
return {
|
|
190
|
+
choice: state.choice,
|
|
191
|
+
resolved: state.resolved,
|
|
192
|
+
setTheme
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
Object.defineProperty(exports, "DOC_ID_PREFIX", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
get: function() {
|
|
199
|
+
return DOC_ID_PREFIX;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(exports, "THEME_CHOICES", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
get: function() {
|
|
205
|
+
return THEME_CHOICES;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(exports, "__toESM", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function() {
|
|
211
|
+
return __toESM;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(exports, "cn", {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
get: function() {
|
|
217
|
+
return cn;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
Object.defineProperty(exports, "docShareUrl", {
|
|
221
|
+
enumerable: true,
|
|
222
|
+
get: function() {
|
|
223
|
+
return docShareUrl;
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
Object.defineProperty(exports, "docSlug", {
|
|
227
|
+
enumerable: true,
|
|
228
|
+
get: function() {
|
|
229
|
+
return docSlug;
|
|
230
|
+
}
|
|
231
|
+
});
|
|
232
|
+
Object.defineProperty(exports, "findDocAnchor", {
|
|
233
|
+
enumerable: true,
|
|
234
|
+
get: function() {
|
|
235
|
+
return findDocAnchor;
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
Object.defineProperty(exports, "readDocHash", {
|
|
239
|
+
enumerable: true,
|
|
240
|
+
get: function() {
|
|
241
|
+
return readDocHash;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
Object.defineProperty(exports, "scrollToDocAnchor", {
|
|
245
|
+
enumerable: true,
|
|
246
|
+
get: function() {
|
|
247
|
+
return scrollToDocAnchor;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
Object.defineProperty(exports, "useTheme", {
|
|
251
|
+
enumerable: true,
|
|
252
|
+
get: function() {
|
|
253
|
+
return useTheme;
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
|
|
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 `#почему…` — 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/** 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;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,EAAE,IAAI,KAAK;CAClD;CACA,OAAO,KAAA,kBAAqB,EAAE,KAAK,KAAK,EAAE;AAC5C;AAiBA,SAAS,gBAAgB,QAAuB;CAC9C,IAAI,YAAY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AO,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"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { THEME_STORAGE_KEY } from "./layout/theme-storage-key.js";
|
|
2
|
+
import { useCallback, useEffect, useState } from "react";
|
|
3
|
+
import { clsx } from "clsx";
|
|
4
|
+
import { twMerge } from "tailwind-merge";
|
|
5
|
+
import GithubSlugger from "github-slugger";
|
|
6
|
+
//#region src/lib/cn.ts
|
|
7
|
+
function cn(...inputs) {
|
|
8
|
+
return twMerge(clsx(inputs));
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
//#region src/markdown/anchors.ts
|
|
12
|
+
const DOC_ID_PREFIX = "user-content-";
|
|
13
|
+
function docSlug(text) {
|
|
14
|
+
return new GithubSlugger().slug(text);
|
|
15
|
+
}
|
|
16
|
+
function readDocHash() {
|
|
17
|
+
if (typeof window === "undefined") return "";
|
|
18
|
+
const raw = window.location.hash.replace(/^#/, "");
|
|
19
|
+
if (raw === "") return "";
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(raw);
|
|
22
|
+
} catch {
|
|
23
|
+
return raw;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function findDocAnchor(hash, root = document) {
|
|
27
|
+
let id = hash.replace(/^#/, "");
|
|
28
|
+
if (id === "") return null;
|
|
29
|
+
try {
|
|
30
|
+
id = decodeURIComponent(id);
|
|
31
|
+
} catch {}
|
|
32
|
+
const doc = root.ownerDocument ?? root;
|
|
33
|
+
const pick = (candidate) => {
|
|
34
|
+
const el = doc.getElementById(candidate);
|
|
35
|
+
if (!el) return null;
|
|
36
|
+
return root === doc || root.contains(el) ? el : null;
|
|
37
|
+
};
|
|
38
|
+
return pick("user-content-" + id) ?? pick(id);
|
|
39
|
+
}
|
|
40
|
+
function placeInScroller(target) {
|
|
41
|
+
let container = target.parentElement;
|
|
42
|
+
while (container) {
|
|
43
|
+
const style = getComputedStyle(container);
|
|
44
|
+
if (/(auto|scroll)/.test(style.overflowY) && container.scrollHeight > container.clientHeight + 1) break;
|
|
45
|
+
container = container.parentElement;
|
|
46
|
+
}
|
|
47
|
+
if (!container) {
|
|
48
|
+
target.scrollIntoView({
|
|
49
|
+
block: "start",
|
|
50
|
+
behavior: "auto"
|
|
51
|
+
});
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const margin = Number.parseFloat(getComputedStyle(target).scrollMarginTop) || 0;
|
|
55
|
+
const delta = target.getBoundingClientRect().top - container.getBoundingClientRect().top - margin;
|
|
56
|
+
container.scrollTop += delta;
|
|
57
|
+
}
|
|
58
|
+
function scrollToDocAnchor(hash, root = document.body, settleMs = 1500) {
|
|
59
|
+
let stopped = false;
|
|
60
|
+
const go = () => {
|
|
61
|
+
if (stopped) return;
|
|
62
|
+
const target = findDocAnchor(hash, root);
|
|
63
|
+
if (target) placeInScroller(target);
|
|
64
|
+
};
|
|
65
|
+
const raf1 = requestAnimationFrame(() => requestAnimationFrame(go));
|
|
66
|
+
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(() => requestAnimationFrame(go));
|
|
67
|
+
observer?.observe(root);
|
|
68
|
+
const timer = setTimeout(() => {
|
|
69
|
+
stopped = true;
|
|
70
|
+
observer?.disconnect();
|
|
71
|
+
}, settleMs);
|
|
72
|
+
return () => {
|
|
73
|
+
stopped = true;
|
|
74
|
+
cancelAnimationFrame(raf1);
|
|
75
|
+
observer?.disconnect();
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function docShareUrl(slug, href = window.location.href) {
|
|
80
|
+
const url = new URL(href);
|
|
81
|
+
const safe = /[#?%\s]/.test(slug) ? encodeURIComponent(slug) : slug;
|
|
82
|
+
return `${url.origin}${url.pathname}${url.search}#${safe}`;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/layout/use-theme.ts
|
|
86
|
+
const THEME_CHOICES = [
|
|
87
|
+
"light",
|
|
88
|
+
"dark",
|
|
89
|
+
"system"
|
|
90
|
+
];
|
|
91
|
+
function systemPrefersDark() {
|
|
92
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
93
|
+
}
|
|
94
|
+
function readChoice() {
|
|
95
|
+
if (typeof window === "undefined") return "system";
|
|
96
|
+
try {
|
|
97
|
+
const saved = window.localStorage.getItem(THEME_STORAGE_KEY);
|
|
98
|
+
if (saved === "light" || saved === "dark") return saved;
|
|
99
|
+
} catch {}
|
|
100
|
+
return "system";
|
|
101
|
+
}
|
|
102
|
+
function resolveTheme(choice) {
|
|
103
|
+
if (choice === "light" || choice === "dark") return choice;
|
|
104
|
+
return systemPrefersDark() ? "dark" : "light";
|
|
105
|
+
}
|
|
106
|
+
function applyDomClass(resolved) {
|
|
107
|
+
if (typeof document === "undefined") return;
|
|
108
|
+
document.documentElement.classList.toggle("dark", resolved === "dark");
|
|
109
|
+
}
|
|
110
|
+
function persistChoice(choice) {
|
|
111
|
+
if (typeof window === "undefined") return;
|
|
112
|
+
try {
|
|
113
|
+
if (choice === "system") window.localStorage.removeItem(THEME_STORAGE_KEY);
|
|
114
|
+
else window.localStorage.setItem(THEME_STORAGE_KEY, choice);
|
|
115
|
+
} catch {}
|
|
116
|
+
}
|
|
117
|
+
function useTheme() {
|
|
118
|
+
const [state, setState] = useState({
|
|
119
|
+
choice: "system",
|
|
120
|
+
resolved: "light"
|
|
121
|
+
});
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
const choice = readChoice();
|
|
124
|
+
setState({
|
|
125
|
+
choice,
|
|
126
|
+
resolved: resolveTheme(choice)
|
|
127
|
+
});
|
|
128
|
+
const root = document.documentElement;
|
|
129
|
+
const observer = new MutationObserver(() => {
|
|
130
|
+
const resolved = root.classList.contains("dark") ? "dark" : "light";
|
|
131
|
+
setState((prev) => prev.resolved === resolved ? prev : {
|
|
132
|
+
...prev,
|
|
133
|
+
resolved
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
observer.observe(root, {
|
|
137
|
+
attributes: true,
|
|
138
|
+
attributeFilter: ["class"]
|
|
139
|
+
});
|
|
140
|
+
const mql = typeof window.matchMedia === "function" ? window.matchMedia("(prefers-color-scheme: dark)") : void 0;
|
|
141
|
+
const onSystemChange = (event) => {
|
|
142
|
+
const choice = readChoice();
|
|
143
|
+
if (choice !== "system") return;
|
|
144
|
+
const resolved = event.matches ? "dark" : "light";
|
|
145
|
+
applyDomClass(resolved);
|
|
146
|
+
setState((prev) => prev.choice === choice && prev.resolved === resolved ? prev : {
|
|
147
|
+
choice,
|
|
148
|
+
resolved
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
mql?.addEventListener("change", onSystemChange);
|
|
152
|
+
return () => {
|
|
153
|
+
observer.disconnect();
|
|
154
|
+
mql?.removeEventListener("change", onSystemChange);
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
157
|
+
const setTheme = useCallback((next) => {
|
|
158
|
+
const resolved = resolveTheme(next);
|
|
159
|
+
applyDomClass(resolved);
|
|
160
|
+
persistChoice(next);
|
|
161
|
+
setState({
|
|
162
|
+
choice: next,
|
|
163
|
+
resolved
|
|
164
|
+
});
|
|
165
|
+
}, []);
|
|
166
|
+
return {
|
|
167
|
+
choice: state.choice,
|
|
168
|
+
resolved: state.resolved,
|
|
169
|
+
setTheme
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
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 };
|
|
174
|
+
|
|
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 `#почему…` — 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/** 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;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,IAA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