@mikebrucker/brucks 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +274 -2
  3. package/dist/blucks/components/homeCard.d.ts +27 -0
  4. package/dist/blucks/components/homeCard.js +53 -0
  5. package/dist/blucks/components/homeCard.js.map +1 -0
  6. package/dist/blucks/components/scrollToTopFab.d.ts +16 -0
  7. package/dist/blucks/components/scrollToTopFab.js +187 -0
  8. package/dist/blucks/components/scrollToTopFab.js.map +1 -0
  9. package/dist/blucks/components/settingsPickerModal.d.ts +11 -0
  10. package/dist/blucks/components/settingsPickerModal.js +49 -0
  11. package/dist/blucks/components/settingsPickerModal.js.map +1 -0
  12. package/dist/blucks/components/settingsRow.d.ts +12 -0
  13. package/dist/blucks/components/settingsRow.js +34 -0
  14. package/dist/blucks/components/settingsRow.js.map +1 -0
  15. package/dist/blucks/components/settingsSection.d.ts +8 -0
  16. package/dist/blucks/components/settingsSection.js +19 -0
  17. package/dist/blucks/components/settingsSection.js.map +1 -0
  18. package/dist/blucks/components/settingsSwatchButton.d.ts +10 -0
  19. package/dist/blucks/components/settingsSwatchButton.js +38 -0
  20. package/dist/blucks/components/settingsSwatchButton.js.map +1 -0
  21. package/dist/blucks/hooks/useDisclosure.d.ts +5 -0
  22. package/dist/blucks/hooks/useDisclosure.js +34 -0
  23. package/dist/blucks/hooks/useDisclosure.js.map +1 -0
  24. package/dist/blucks/hooks/useScrollAncestor.d.ts +3 -0
  25. package/dist/blucks/hooks/useScrollAncestor.js +40 -0
  26. package/dist/blucks/hooks/useScrollAncestor.js.map +1 -0
  27. package/dist/blucks/index.d.ts +12 -0
  28. package/dist/blucks/index.js +13 -0
  29. package/dist/blucks/layout/appLayout.d.ts +16 -0
  30. package/dist/blucks/layout/appLayout.js +93 -0
  31. package/dist/blucks/layout/appLayout.js.map +1 -0
  32. package/dist/blucks/layout/footer.d.ts +7 -0
  33. package/dist/blucks/layout/footer.js +18 -0
  34. package/dist/blucks/layout/footer.js.map +1 -0
  35. package/dist/blucks/layout/header.d.ts +22 -0
  36. package/dist/blucks/layout/header.js +121 -0
  37. package/dist/blucks/layout/header.js.map +1 -0
  38. package/dist/blucks/lib/utils.d.ts +6 -0
  39. package/dist/blucks/lib/utils.js +12 -0
  40. package/dist/blucks/lib/utils.js.map +1 -0
  41. package/dist/style/index.d.ts +4 -0
  42. package/dist/style/index.js +5 -0
  43. package/dist/style/settings.d.ts +105 -0
  44. package/dist/style/settings.js +156 -0
  45. package/dist/style/settings.js.map +1 -0
  46. package/dist/style/styles.d.ts +6 -0
  47. package/dist/style/styles.js +10 -0
  48. package/dist/style/styles.js.map +1 -0
  49. package/dist/style/theme.css +1449 -0
  50. package/dist/style/types.d.ts +6 -0
  51. package/dist/style/types.js +9 -0
  52. package/dist/style/types.js.map +1 -0
  53. package/dist/style/utils.d.ts +2 -0
  54. package/dist/style/utils.js +28 -0
  55. package/dist/style/utils.js.map +1 -0
  56. package/dist/ui/components/accordion.d.ts +81 -0
  57. package/dist/ui/components/accordion.js +449 -0
  58. package/dist/ui/components/accordion.js.map +1 -0
  59. package/dist/ui/components/alertDialog.d.ts +17 -0
  60. package/dist/ui/components/alertDialog.js +134 -0
  61. package/dist/ui/components/alertDialog.js.map +1 -0
  62. package/dist/ui/components/button.d.ts +10 -0
  63. package/dist/ui/components/button.js +51 -0
  64. package/dist/ui/components/button.js.map +1 -0
  65. package/dist/ui/components/checkbox.d.ts +3 -0
  66. package/dist/ui/components/checkbox.js +56 -0
  67. package/dist/ui/components/checkbox.js.map +1 -0
  68. package/dist/ui/components/chip.d.ts +13 -0
  69. package/dist/ui/components/chip.js +26 -0
  70. package/dist/ui/components/chip.js.map +1 -0
  71. package/dist/ui/components/collapsible.d.ts +22 -0
  72. package/dist/ui/components/collapsible.js +197 -0
  73. package/dist/ui/components/collapsible.js.map +1 -0
  74. package/dist/ui/components/drawer.d.ts +13 -0
  75. package/dist/ui/components/drawer.js +81 -0
  76. package/dist/ui/components/drawer.js.map +1 -0
  77. package/dist/ui/components/fab.d.ts +12 -0
  78. package/dist/ui/components/fab.js +51 -0
  79. package/dist/ui/components/fab.js.map +1 -0
  80. package/dist/ui/components/form.d.ts +7 -0
  81. package/dist/ui/components/form.js +107 -0
  82. package/dist/ui/components/form.js.map +1 -0
  83. package/dist/ui/components/icon.d.ts +9 -0
  84. package/dist/ui/components/icon.js +28 -0
  85. package/dist/ui/components/icon.js.map +1 -0
  86. package/dist/ui/components/input.d.ts +12 -0
  87. package/dist/ui/components/input.js +44 -0
  88. package/dist/ui/components/input.js.map +1 -0
  89. package/dist/ui/components/loader.d.ts +15 -0
  90. package/dist/ui/components/loader.js +27 -0
  91. package/dist/ui/components/loader.js.map +1 -0
  92. package/dist/ui/components/modal.d.ts +19 -0
  93. package/dist/ui/components/modal.js +144 -0
  94. package/dist/ui/components/modal.js.map +1 -0
  95. package/dist/ui/components/note.d.ts +6 -0
  96. package/dist/ui/components/note.js +12 -0
  97. package/dist/ui/components/note.js.map +1 -0
  98. package/dist/ui/components/popover.d.ts +15 -0
  99. package/dist/ui/components/popover.js +110 -0
  100. package/dist/ui/components/popover.js.map +1 -0
  101. package/dist/ui/components/progress.d.ts +11 -0
  102. package/dist/ui/components/progress.js +87 -0
  103. package/dist/ui/components/progress.js.map +1 -0
  104. package/dist/ui/components/radioGroup.d.ts +4 -0
  105. package/dist/ui/components/radioGroup.js +82 -0
  106. package/dist/ui/components/radioGroup.js.map +1 -0
  107. package/dist/ui/components/scrollArea.d.ts +29 -0
  108. package/dist/ui/components/scrollArea.js +185 -0
  109. package/dist/ui/components/scrollArea.js.map +1 -0
  110. package/dist/ui/components/select.d.ts +23 -0
  111. package/dist/ui/components/select.js +198 -0
  112. package/dist/ui/components/select.js.map +1 -0
  113. package/dist/ui/components/separator.d.ts +4 -0
  114. package/dist/ui/components/separator.js +48 -0
  115. package/dist/ui/components/separator.js.map +1 -0
  116. package/dist/ui/components/slider.d.ts +26 -0
  117. package/dist/ui/components/slider.js +228 -0
  118. package/dist/ui/components/slider.js.map +1 -0
  119. package/dist/ui/components/sortableList.d.ts +13 -0
  120. package/dist/ui/components/sortableList.js +116 -0
  121. package/dist/ui/components/sortableList.js.map +1 -0
  122. package/dist/ui/components/sortableListRow.d.ts +8 -0
  123. package/dist/ui/components/sortableListRow.js +79 -0
  124. package/dist/ui/components/sortableListRow.js.map +1 -0
  125. package/dist/ui/components/switch.d.ts +3 -0
  126. package/dist/ui/components/switch.js +47 -0
  127. package/dist/ui/components/switch.js.map +1 -0
  128. package/dist/ui/components/tabs.d.ts +7 -0
  129. package/dist/ui/components/tabs.js +106 -0
  130. package/dist/ui/components/tabs.js.map +1 -0
  131. package/dist/ui/components/textarea.d.ts +8 -0
  132. package/dist/ui/components/textarea.js +40 -0
  133. package/dist/ui/components/textarea.js.map +1 -0
  134. package/dist/ui/components/toast.d.ts +13 -0
  135. package/dist/ui/components/toast.js +136 -0
  136. package/dist/ui/components/toast.js.map +1 -0
  137. package/dist/ui/components/toggle-group.d.ts +11 -0
  138. package/dist/ui/components/toggle-group.js +158 -0
  139. package/dist/ui/components/toggle-group.js.map +1 -0
  140. package/dist/ui/components/toggle.d.ts +12 -0
  141. package/dist/ui/components/toggle.js +48 -0
  142. package/dist/ui/components/toggle.js.map +1 -0
  143. package/dist/ui/components/tooltip.d.ts +8 -0
  144. package/dist/ui/components/tooltip.js +59 -0
  145. package/dist/ui/components/tooltip.js.map +1 -0
  146. package/dist/ui/hooks/useCloseOnBack.d.ts +7 -0
  147. package/dist/ui/hooks/useCloseOnBack.js +46 -0
  148. package/dist/ui/hooks/useCloseOnBack.js.map +1 -0
  149. package/dist/ui/hooks/useReturnFocus.d.ts +9 -0
  150. package/dist/ui/hooks/useReturnFocus.js +30 -0
  151. package/dist/ui/hooks/useReturnFocus.js.map +1 -0
  152. package/dist/ui/index.d.ts +33 -0
  153. package/dist/ui/index.js +34 -0
  154. package/dist/ui/lib/defaultLabels.d.ts +31 -0
  155. package/dist/ui/lib/defaultLabels.js +16 -0
  156. package/dist/ui/lib/defaultLabels.js.map +1 -0
  157. package/dist/ui/lib/labels.d.ts +10 -0
  158. package/dist/ui/lib/labels.js +37 -0
  159. package/dist/ui/lib/labels.js.map +1 -0
  160. package/package.json +79 -4
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mike Brucker
4
+ Copyright (c) 2023 shadcn (the components based on shadcn/ui)
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,275 @@
1
- # Temporary Holding Version
1
+ # brucks
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The UI components shared by bruck and grammatik, as a local React package, plus
4
+ the app code both had copies of: the style settings, the settings page kit, the
5
+ home card, the scroll-to-top button and the page layout.
6
+
7
+ It has three entry points, one per folder in `src/`:
8
+
9
+ | Import | Holds | Builds on |
10
+ | --- | --- | --- |
11
+ | `@mikebrucker/brucks/style` (+ `@mikebrucker/brucks/style/theme.css`) | the Tailwind theme, `cn`, `Side`, the class recipes, the style settings | nothing |
12
+ | `@mikebrucker/brucks/ui` (+ `@mikebrucker/brucks/ui/<file>`) | the components, `BrucksProvider`, the back stack | style |
13
+ | `@mikebrucker/brucks/blucks` | `AppLayout`, `Header`, `Footer`, the settings kit, `HomeCard`, `ScrollToTopFab`, `useDisclosure`, `useScrollAncestor`, `isKeyOf` | ui, style |
14
+
15
+ There is no plain `brucks` import, so everything has exactly one import path.
16
+ `npm run lint` keeps the layers apart: style imports neither ui nor blucks, and ui
17
+ never imports blucks.
18
+
19
+ `src/ui/components` is the merge of `src/components/ui` from both apps. Each file
20
+ was taken from whichever side changed it since grammatik forked from bruck, and
21
+ merged where both did. The build ships ES modules with their `"use client"`
22
+ directives intact, type declarations, and the Tailwind theme as source. The
23
+ `"use client"` modules go through the React Compiler. The others stay plain, so
24
+ Server Components can render them.
25
+
26
+ ## Scripts
27
+
28
+ | Script | What it does |
29
+ | --- | --- |
30
+ | `npm start` | The playground: every component with live props, at http://localhost:5173 |
31
+ | `npm run build` | `dist/{ui,style,blucks}`: one ES module per source file, `.d.ts` files, `style/theme.css` |
32
+ | `npm run typecheck` | `tsc --noEmit`, for brucks and for the playground |
33
+ | `npm test` | The playground's browser tests (Playwright, Chromium), against their own server on port 5199 |
34
+ | `npm run lint` | `biome check` |
35
+ | `npm run format` | `biome format --write` |
36
+
37
+ `prepare` runs the build, so installing brucks into an app builds it first.
38
+
39
+ `npm test` runs in Chromium and Firefox, which Playwright needs once per machine (or per
40
+ sandbox: VSCodium's Flatpak terminal has its own cache):
41
+ `npx playwright install --only-shell chromium firefox`.
42
+
43
+ ## Playground
44
+
45
+ `playground/` is a Vite app on brucks's own source (through `brucks/ui`, `brucks/style`
46
+ and `brucks/blucks`, so edits show up live). It is not part of the package. It uses the apps' i18n setup and
47
+ bruck's settings page, built on brucks's settings kit and style settings, so
48
+ components look the way they do in bruck and grammatik.
49
+
50
+ - `/en`, `/de`: a link to every demo. Each demo has its own page, e.g.
51
+ `/en/slider`, with links to the demos before and after it. A path without a
52
+ locale gets the browser's, so `/slider` works too. The pages are React Router
53
+ routes, so switching pages doesn't reload the app.
54
+ The menu lists the demos and filters them by name or by brucks export.
55
+ - `/en/settings`: theme, high contrast, accent, menu side, corners, zoom, language.
56
+ - Each demo has Reset, and a crash stays inside its card. `?crash` on a demo
57
+ page (`/en/button?crash`) shows the fallback on purpose.
58
+ - Each demo shows its code, which follows the props set in its controls and
59
+ leaves out the ones at the component's default. `DemoCard` requires it; demos
60
+ build it with `jsxCode.ts` from the values their preview renders with.
61
+ - Class fields start empty. Classes a demo needs itself show read-only above
62
+ the field, as `built-in className` and so on, and the field adds to them: the
63
+ prop gets `cn(builtIn, typed)`. Demos pass them to `DemoClassName` as
64
+ `builtIn`, never as the field's starting value.
65
+ - Backspace (outside text fields) stands in for the Android back button: it
66
+ calls `closeTopmost()`.
67
+ - `playground/src/components/modules/playground/registry.ts` maps every brucks
68
+ export to the card that shows it. A new export without a card fails
69
+ `npm run typecheck`.
70
+ - `playground/e2e/` holds the browser tests. Every test also fails on any console
71
+ error or warning.
72
+
73
+ ## Using it in an app
74
+
75
+ ### Install
76
+
77
+ ```sh
78
+ npm install @mikebrucker/brucks
79
+ ```
80
+
81
+ ### Styles
82
+
83
+ The theme is a Tailwind partial. Import it into the app's Tailwind entry, after
84
+ Tailwind and tw-animate-css:
85
+
86
+ ```css
87
+ @import "tailwindcss" theme(static);
88
+ @import "tw-animate-css";
89
+ @import "@mikebrucker/brucks/style/theme.css";
90
+ ```
91
+
92
+ `theme(static)` is recommended. The accent ramps alias Tailwind's own palettes,
93
+ and static mode makes sure every palette var exists, including ones the app only
94
+ builds at runtime. The theme registers all of `dist/` (ui, blucks and style) as a
95
+ Tailwind source itself, so the classes brucks uses are generated without any
96
+ `@source` line in the app.
97
+
98
+ The theme provides:
99
+
100
+ - the color, radius and accent tokens (`html.dark` / `html.light`,
101
+ `html.high-contrast`, `html[data-accent]`)
102
+ - the `dark` and `hc` variants
103
+ - the stacking layers (see below)
104
+ - the drawer, collapsible and flap keyframes (`animate-flap`)
105
+ - the `safe-area-y` utility and the loader
106
+ - a base rule giving every element `border-border` and `outline-ring`
107
+ - a reduced-motion rule: with reduced motion on, every animation and transition
108
+ finishes at once
109
+
110
+ Fonts and the `html`/`body` rules stay in the app. The titles of Popover and
111
+ Header take the app's display font through `titleClassName`, Footer's text
112
+ through `className`.
113
+
114
+ ### Stacking
115
+
116
+ The components sit on named layers, which the theme defines as `--z-index-*`
117
+ tokens. The app can use them as `z-*` classes too, and put its own layers in
118
+ between:
119
+
120
+ | Class | Value | Used by |
121
+ | --- | --- | --- |
122
+ | `z-sticky` | 10 | Accordion's sticky headers, the sticky Footer |
123
+ | `z-header` | 20 | the sticky Header, above sticky content scrolling under it |
124
+ | `z-fab` | 50 | Fab |
125
+ | `z-dialog` | 60 | Modal, Drawer, AlertDialog |
126
+ | `z-skip-link` | 100 | AppLayout's skip link, once focused |
127
+ | `z-loader` | 1000 | the full-screen Loader |
128
+ | `z-popover-backdrop` | 9998 | Popover's backdrop |
129
+ | `z-popover` | 9999 | Popover, Select, Tooltip, Toast |
130
+
131
+ `cn()` knows the names, so a `z-*` class passed to a component replaces its
132
+ layer.
133
+
134
+ ### Components
135
+
136
+ ```tsx
137
+ import { Button, Modal } from "@mikebrucker/brucks/ui";
138
+ import { Button } from "@mikebrucker/brucks/ui/button";
139
+ ```
140
+
141
+ Every component also has its own entry, named like the app file it came from
142
+ (`@mikebrucker/brucks/ui/alertDialog`, `@mikebrucker/brucks/ui/toggle-group`, ...), so `@/components/ui/x` maps
143
+ to `@mikebrucker/brucks/ui/x`. `cn` comes from `@mikebrucker/brucks/style`.
144
+
145
+ ### Labels
146
+
147
+ The components ship no translations. Their screen reader labels default to
148
+ English and are replaced through `BrucksProvider` from `@mikebrucker/brucks/ui`, usually inside
149
+ the app's i18n provider. The one provider also names `@mikebrucker/brucks/blucks`'s
150
+ `ScrollToTopFab` (`scrollToTop`) and `AppLayout`'s skip link (`skipToContent`),
151
+ and `menu` names `Drawer`:
152
+
153
+ ```tsx
154
+ <BrucksProvider
155
+ labels={{
156
+ close: t(($) => $.ariaLabels.close),
157
+ dialog: t(($) => $.ariaLabels.dialog),
158
+ menu: t(($) => $.ariaLabels.menu),
159
+ dragToReorder: t(($) => $.ariaLabels.drag_to_reorder),
160
+ reorderAnnouncement: (values) => t(($) => $.ariaLabels.reorder_announcement, values),
161
+ notification: t(($) => $.ariaLabels.notification),
162
+ notifications: t(($) => $.ariaLabels.notifications), // keep "{hotkey}" in the text
163
+ dragInstructions: t(($) => $.ariaLabels.drag_instructions),
164
+ scrollToTop: t(($) => $.ariaLabels.scroll_to_top),
165
+ skipToContent: t(($) => $.ariaLabels.skip_to_content),
166
+ }}
167
+ >
168
+ {children}
169
+ </BrucksProvider>
170
+ ```
171
+
172
+ `Loader` renders in Server Components, which can't read the provider, so it
173
+ takes its screen reader text as a `label` prop instead. `Drawer` and `Modal`
174
+ take a `title` for their screen reader name, in place of the "menu" and
175
+ "dialog" labels.
176
+
177
+ ### Android back button
178
+
179
+ `Modal`, `Drawer`, `AlertDialog`, `Popover` and `Select` register themselves with
180
+ `useCloseOnBack` while open. An app's back button handler calls `closeTopmost()` from `@mikebrucker/brucks/ui` to
181
+ close the one on top. It has to be brucks's own export, since the open overlays
182
+ are tracked in that module.
183
+
184
+ ### Style settings (`@mikebrucker/brucks/style`)
185
+
186
+ `Themes`, `Accents`, `RoundedCorners`, `RoundedTargets` and `Zooms` (with their
187
+ types and the `accents`/`roundedCorners` lists) are the options the theme
188
+ understands. Each writer puts a choice where theme.css reads it and stores it
189
+ under its own localStorage key:
190
+
191
+ | Writer | Writes |
192
+ | --- | --- |
193
+ | `applyTheme(theme)` | `dark` or `light` on `<html>` (`system` follows the OS); returns which |
194
+ | `applyAccent(accent)` | `data-accent` |
195
+ | `applyRounded(target, corner)` | `--rounded-primary` / `--rounded-secondary` |
196
+ | `applyZoom(zoom)` | `--zoom`, clamped to `Zooms`; returns the value it applied |
197
+ | `applyHighContrast(on)` | `high-contrast` |
198
+ | `applyMenuSide(side)` | only the stored value |
199
+
200
+ `readStoredStyle()` returns the stored choices, each one validated, with
201
+ `defaultStyle` for anything missing or invalid (high contrast falls back to the
202
+ OS preference). `darkSchemeQuery` is the media query to follow while the theme
203
+ is `system`. The store holding the choices stays in the app; the playground's
204
+ `stores/useStyleStore.ts` and `components/providers/styleInit.tsx` show the
205
+ wiring.
206
+
207
+ `@mikebrucker/brucks/style` also has `cn`, `Side`/`Sides` and the class recipes: `chip`,
208
+ `keyboardButton`, `toggleOn` (a pressed ToggleGroupItem in the accent) and
209
+ `navSelected` (the current page's nav link).
210
+
211
+ ### Blocks (`@mikebrucker/brucks/blucks`)
212
+
213
+ The blocks of an app, optional: ui and style never need them. Together with the
214
+ style settings they make a full settings page.
215
+
216
+ - `AppLayout` frames every page: a skip link, the `header`, `main` as the one
217
+ scroller, with the page in a centered column, an optional `sidebar` beside it
218
+ on `sidebarSide`, and the `footer` below (a `sticky` Footer, like the Header).
219
+ `contentClassName` styles the column, e.g. its side padding. `main` and the
220
+ sidebar reach under the header's and footer's rounded corners, so the page
221
+ scrolls on behind them: give them a `sticky` Header and Footer, which sit on a
222
+ layer above that content. The sidebar pads itself with `--inset-top` and
223
+ `--inset-bottom`, that overlap (`0px` without a header or footer). The skip link
224
+ reads the `skipToContent` label. The app's menu and other overlays render
225
+ beside it.
226
+ - `Header` is the bar on top. Its `title` (the site's name or the page's, which
227
+ ends in an ellipsis when too long) can hold the app's link home, and `heading`
228
+ makes it the page's `h1`. `leading` goes before it (a back link), `children`
229
+ after it (a nav), then an icon button for `onAction` with `actionIcon`, named
230
+ by `actionLabel` or the `menu` label.
231
+ - `Footer` is the bar at the bottom, holding a line of text.
232
+
233
+ ```tsx
234
+ const menu = useDisclosure();
235
+
236
+ <>
237
+ <AppLayout
238
+ header={
239
+ <Header
240
+ sticky
241
+ title={<Link href={`/${language}`}>{websiteTitle}</Link>}
242
+ titleClassName="font-metal-mania"
243
+ onAction={menu.open}
244
+ actionIcon={Menu01Icon}
245
+ />
246
+ }
247
+ footer={<Footer className="font-metal-mania">{websiteTitle}</Footer>}
248
+ >
249
+ {children}
250
+ </AppLayout>
251
+ <Menu open={menu.isOpen} onClose={menu.close} />
252
+ </>
253
+ ```
254
+
255
+ - `SettingsSection`, `SettingsRow`, `SettingsSwatchButton` and
256
+ `SettingsPickerModal` (its `title` names the dialog) build a settings page.
257
+ - `HomeCard` links to a section of the app. With `asChild` its child is the
258
+ link and the card's content goes inside it:
259
+
260
+ ```tsx
261
+ <HomeCard asChild title={…} icon={…}>
262
+ <Link href={`/${language}/games`} />
263
+ </HomeCard>
264
+ ```
265
+
266
+ Without `asChild` it is a button that runs `onClick`.
267
+ - `ScrollToTopFab` scrolls its nearest scrolling ancestor to the top. It fades in
268
+ after `screensBeforeVisible` screen heights; `position="inline"` keeps it in
269
+ the flow, always shown. Its name is the `scrollToTop` label. Pressed from the
270
+ keyboard, it moves focus to the scroller (when focusable, like a skip link's
271
+ `main`), so the next Tab starts at the top.
272
+ - `useDisclosure()` gives `{ isOpen, open, close }`. `useScrollAncestor(ref)`
273
+ finds the nearest scrolling ancestor.
274
+ - `isKeyOf(options, value)` narrows a Radix `onValueChange` string to an option
275
+ map's keys.
@@ -0,0 +1,27 @@
1
+ import type { IconSvgElement } from "@hugeicons/react";
2
+ import { type VariantProps } from "class-variance-authority";
3
+ import type { ReactNode } from "react";
4
+ declare const homeCardVariants: (props?: ({
5
+ size?: "hero" | "default" | "compact" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ type HomeCardProps = VariantProps<typeof homeCardVariants> & {
8
+ /**
9
+ * The card becomes its only child, the app's link (`<Link href="…" />`), with
10
+ * the card's content put inside it. Without it the card is a button, and
11
+ * `onClick` is what it does.
12
+ */
13
+ asChild?: boolean;
14
+ children?: ReactNode;
15
+ onClick?: () => void;
16
+ title: string;
17
+ titleClassName?: string;
18
+ description?: string;
19
+ icon: IconSvgElement;
20
+ iconClassName?: string;
21
+ /** Sits in the bottom right corner, level with the media. */
22
+ badge?: ReactNode;
23
+ media?: ReactNode;
24
+ className?: string;
25
+ };
26
+ declare function HomeCard({ asChild, children, onClick, title, titleClassName, description, icon, iconClassName, badge, media, size, className, }: HomeCardProps): import("react").JSX.Element;
27
+ export { HomeCard, type HomeCardProps };
@@ -0,0 +1,53 @@
1
+ import { cn } from "../../style/utils.js";
2
+ import { Slot } from "radix-ui";
3
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
4
+ import { cva } from "class-variance-authority";
5
+ import { HugeiconsIcon } from "@hugeicons/react";
6
+ // src/blucks/components/homeCard.tsx
7
+ var homeCardVariants = cva("bg-card text-card-foreground border border-border border-l-4 border-l-theme-500 rounded-primary flex flex-col gap-2 p-3 sm:p-4 h-full outline-none transition-all duration-300 hover:bg-muted active:bg-muted active:translate-y-px focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 active:shadow-[0_2px_3px_-1px_rgb(0_0_0/0.25),0_1px_2px_-1px_rgb(0_0_0/0.15)] dark:active:shadow-[0_2px_3px_-1px_rgb(0_0_0/0.35),0_1px_2px_-1px_rgb(0_0_0/0.22)]", {
8
+ variants: { size: {
9
+ hero: "hover:-translate-y-1 shadow-[0_10px_16px_-3px_rgb(0_0_0/0.30),0_5px_8px_-4px_rgb(0_0_0/0.20)] dark:shadow-[0_10px_16px_-3px_rgb(0_0_0/0.45),0_5px_8px_-4px_rgb(0_0_0/0.30)] hover:shadow-[0_16px_24px_-4px_rgb(0_0_0/0.35),0_8px_12px_-5px_rgb(0_0_0/0.25)] dark:hover:shadow-[0_16px_24px_-4px_rgb(0_0_0/0.5),0_8px_12px_-5px_rgb(0_0_0/0.35)]",
10
+ default: "hover:-translate-y-0.5 shadow-[0_5px_6px_-1px_rgb(0_0_0/0.25),0_3px_4px_-2px_rgb(0_0_0/0.15)] dark:shadow-[0_5px_6px_-1px_rgb(0_0_0/0.35),0_3px_4px_-2px_rgb(0_0_0/0.22)] hover:shadow-[0_9px_14px_-2px_rgb(0_0_0/0.30),0_5px_8px_-3px_rgb(0_0_0/0.20)] dark:hover:shadow-[0_9px_14px_-2px_rgb(0_0_0/0.45),0_5px_8px_-3px_rgb(0_0_0/0.30)]",
11
+ compact: "hover:-translate-y-0.5 shadow-[0_3px_4px_-1px_rgb(0_0_0/0.2),0_2px_3px_-2px_rgb(0_0_0/0.12)] dark:shadow-[0_3px_4px_-1px_rgb(0_0_0/0.3),0_2px_3px_-2px_rgb(0_0_0/0.18)] hover:shadow-[0_6px_10px_-2px_rgb(0_0_0/0.25),0_3px_5px_-3px_rgb(0_0_0/0.15)] dark:hover:shadow-[0_6px_10px_-2px_rgb(0_0_0/0.38),0_3px_5px_-3px_rgb(0_0_0/0.24)]"
12
+ } },
13
+ defaultVariants: { size: "default" }
14
+ });
15
+ function HomeCard({ asChild = false, children, onClick, title, titleClassName, description, icon, iconClassName, badge, media, size = "default", className }) {
16
+ const content = /* @__PURE__ */ jsxs(Fragment, { children: [
17
+ /* @__PURE__ */ jsxs("div", {
18
+ className: "flex items-center gap-2.5",
19
+ children: [/* @__PURE__ */ jsx(HugeiconsIcon, {
20
+ icon,
21
+ "aria-hidden": true,
22
+ className: cn("size-6 shrink-0 text-theme-600", iconClassName)
23
+ }), /* @__PURE__ */ jsx("h2", {
24
+ className: cn("text-lg font-bold leading-tight", titleClassName),
25
+ children: title
26
+ })]
27
+ }),
28
+ description ? /* @__PURE__ */ jsx("p", {
29
+ className: "text-sm text-muted-foreground whitespace-pre-wrap",
30
+ children: description
31
+ }) : null,
32
+ badge ? /* @__PURE__ */ jsxs("div", {
33
+ className: "flex items-end gap-2 mt-auto",
34
+ children: [media, /* @__PURE__ */ jsx("div", {
35
+ className: "ml-auto shrink-0",
36
+ children: badge
37
+ })]
38
+ }) : media
39
+ ] });
40
+ if (asChild) return /* @__PURE__ */ jsxs(Slot.Root, {
41
+ className: cn(homeCardVariants({ size }), className),
42
+ children: [/* @__PURE__ */ jsx(Slot.Slottable, { children }), content]
43
+ });
44
+ return /* @__PURE__ */ jsx("button", {
45
+ type: "button",
46
+ onClick,
47
+ className: cn(homeCardVariants({ size }), "w-full text-left cursor-pointer", className),
48
+ children: content
49
+ });
50
+ }
51
+ export { HomeCard };
52
+
53
+ //# sourceMappingURL=homeCard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"homeCard.js","names":["_Fragment"],"sources":["../../../src/blucks/components/homeCard.tsx"],"sourcesContent":["import type { IconSvgElement } from \"@hugeicons/react\";\nimport { HugeiconsIcon } from \"@hugeicons/react\";\nimport { cva, type VariantProps } from \"class-variance-authority\";\nimport { Slot } from \"radix-ui\";\nimport type { ReactNode } from \"react\";\nimport { cn } from \"~/style/utils\";\n\nconst homeCardVariants = cva(\n \"bg-card text-card-foreground border border-border border-l-4 border-l-theme-500 rounded-primary flex flex-col gap-2 p-3 sm:p-4 h-full outline-none transition-all duration-300 hover:bg-muted active:bg-muted active:translate-y-px focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 active:shadow-[0_2px_3px_-1px_rgb(0_0_0/0.25),0_1px_2px_-1px_rgb(0_0_0/0.15)] dark:active:shadow-[0_2px_3px_-1px_rgb(0_0_0/0.35),0_1px_2px_-1px_rgb(0_0_0/0.22)]\",\n {\n variants: {\n size: {\n hero: \"hover:-translate-y-1 shadow-[0_10px_16px_-3px_rgb(0_0_0/0.30),0_5px_8px_-4px_rgb(0_0_0/0.20)] dark:shadow-[0_10px_16px_-3px_rgb(0_0_0/0.45),0_5px_8px_-4px_rgb(0_0_0/0.30)] hover:shadow-[0_16px_24px_-4px_rgb(0_0_0/0.35),0_8px_12px_-5px_rgb(0_0_0/0.25)] dark:hover:shadow-[0_16px_24px_-4px_rgb(0_0_0/0.5),0_8px_12px_-5px_rgb(0_0_0/0.35)]\",\n default:\n \"hover:-translate-y-0.5 shadow-[0_5px_6px_-1px_rgb(0_0_0/0.25),0_3px_4px_-2px_rgb(0_0_0/0.15)] dark:shadow-[0_5px_6px_-1px_rgb(0_0_0/0.35),0_3px_4px_-2px_rgb(0_0_0/0.22)] hover:shadow-[0_9px_14px_-2px_rgb(0_0_0/0.30),0_5px_8px_-3px_rgb(0_0_0/0.20)] dark:hover:shadow-[0_9px_14px_-2px_rgb(0_0_0/0.45),0_5px_8px_-3px_rgb(0_0_0/0.30)]\",\n compact:\n \"hover:-translate-y-0.5 shadow-[0_3px_4px_-1px_rgb(0_0_0/0.2),0_2px_3px_-2px_rgb(0_0_0/0.12)] dark:shadow-[0_3px_4px_-1px_rgb(0_0_0/0.3),0_2px_3px_-2px_rgb(0_0_0/0.18)] hover:shadow-[0_6px_10px_-2px_rgb(0_0_0/0.25),0_3px_5px_-3px_rgb(0_0_0/0.15)] dark:hover:shadow-[0_6px_10px_-2px_rgb(0_0_0/0.38),0_3px_5px_-3px_rgb(0_0_0/0.24)]\",\n },\n },\n defaultVariants: {\n size: \"default\",\n },\n },\n);\n\ntype HomeCardProps = VariantProps<typeof homeCardVariants> & {\n /**\n * The card becomes its only child, the app's link (`<Link href=\"…\" />`), with\n * the card's content put inside it. Without it the card is a button, and\n * `onClick` is what it does.\n */\n asChild?: boolean;\n children?: ReactNode;\n onClick?: () => void;\n title: string;\n titleClassName?: string;\n description?: string;\n icon: IconSvgElement;\n iconClassName?: string;\n /** Sits in the bottom right corner, level with the media. */\n badge?: ReactNode;\n media?: ReactNode;\n className?: string;\n};\n\nfunction HomeCard({\n asChild = false,\n children,\n onClick,\n title,\n titleClassName,\n description,\n icon,\n iconClassName,\n badge,\n media,\n size = \"default\",\n className,\n}: HomeCardProps) {\n const content = (\n <>\n <div className=\"flex items-center gap-2.5\">\n <HugeiconsIcon\n icon={icon}\n aria-hidden\n className={cn(\"size-6 shrink-0 text-theme-600\", iconClassName)}\n />\n <h2 className={cn(\"text-lg font-bold leading-tight\", titleClassName)}>{title}</h2>\n </div>\n {description ? (\n <p className=\"text-sm text-muted-foreground whitespace-pre-wrap\">{description}</p>\n ) : null}\n {badge ? (\n <div className=\"flex items-end gap-2 mt-auto\">\n {media}\n <div className=\"ml-auto shrink-0\">{badge}</div>\n </div>\n ) : (\n media\n )}\n </>\n );\n\n if (asChild) {\n return (\n <Slot.Root className={cn(homeCardVariants({ size }), className)}>\n <Slot.Slottable>{children}</Slot.Slottable>\n {content}\n </Slot.Root>\n );\n }\n\n return (\n <button\n type=\"button\"\n onClick={onClick}\n className={cn(homeCardVariants({ size }), \"w-full text-left cursor-pointer\", className)}\n >\n {content}\n </button>\n );\n}\n\nexport { HomeCard, type HomeCardProps };\n"],"mappings":";;;;;;AAOA,IAAM,mBAAmB,IACvB,sdACA;CACE,UAAU,EACR,MAAM;EACJ,MAAM;EACN,SACE;EACF,SACE;CACJ,EACF;CACA,iBAAiB,EACf,MAAM,UACR;AACF,CACF;AAsBA,SAAS,SAAS,EAChB,UAAU,OACV,UACA,SACA,OACA,gBACA,aACA,MACA,eACA,OACA,OACA,OAAO,WACP,aACgB;CAChB,MAAM,UACJ,qBAAAA,UAAA,EAAA,UAAA;EACE,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACE,oBAAC,eAAD;IACQ;IACN,eAAA;IACA,WAAW,GAAG,kCAAkC,aAAa;GAC9D,CAAA,GACD,oBAAC,MAAD;IAAI,WAAW,GAAG,mCAAmC,cAAc;IAAI,UAAA;GAAU,CAAA,CAC9E;;EACJ,cACC,oBAAC,KAAD;GAAG,WAAU;GAAqD,UAAA;EAAe,CAAA,IAC/E;EACH,QACC,qBAAC,OAAD;GAAK,WAAU;GAAf,UAAA,CACG,OACD,oBAAC,OAAD;IAAK,WAAU;IAAoB,UAAA;GAAW,CAAA,CAC3C;EAEL,CAAA,IAAA;CAEF,EAAA,CAAA;CAGJ,IAAI,SACF,OACE,qBAAC,KAAK,MAAN;EAAW,WAAW,GAAG,iBAAiB,EAAE,KAAK,CAAC,GAAG,SAAS;EAA9D,UAAA,CACE,oBAAC,KAAK,WAAN,EAAiB,SAAyB,CAAA,GACzC,OACQ;;CAIf,OACE,oBAAC,UAAD;EACE,MAAK;EACI;EACT,WAAW,GAAG,iBAAiB,EAAE,KAAK,CAAC,GAAG,mCAAmC,SAAS;EAErF,UAAA;CACK,CAAA;AAEZ"}
@@ -0,0 +1,16 @@
1
+ import { type ComponentProps } from "react";
2
+ import { AppIcon } from "../../ui/components/icon";
3
+ type ScrollToTopFabProps = {
4
+ /** How many screen heights must be scrolled before the button appears. */
5
+ screensBeforeVisible?: number;
6
+ /** `inline` drops the fixed positioning and keeps the button in normal flow. */
7
+ position?: "bottom-right" | "bottom-left" | "inline";
8
+ className?: string;
9
+ /** Draws the icon in the theme accent. */
10
+ theme?: boolean;
11
+ icon?: ComponentProps<typeof AppIcon>["icon"];
12
+ /** Rocks the icon with the flap animation. */
13
+ animate?: boolean;
14
+ };
15
+ declare function ScrollToTopFab({ screensBeforeVisible, position, className, theme, icon, animate, }: ScrollToTopFabProps): import("react").JSX.Element;
16
+ export { ScrollToTopFab };
@@ -0,0 +1,187 @@
1
+ "use client";
2
+ import { cn } from "../../style/utils.js";
3
+ import { AppIcon } from "../../ui/components/icon.js";
4
+ import { useBrucksLabels } from "../../ui/lib/labels.js";
5
+ import { Fab } from "../../ui/components/fab.js";
6
+ import { useScrollAncestor } from "../hooks/useScrollAncestor.js";
7
+ import { c } from "react/compiler-runtime";
8
+ import { useEffect, useRef, useState } from "react";
9
+ import { jsx } from "react/jsx-runtime";
10
+ import { FlyingHumanIcon } from "@hugeicons/core-free-icons";
11
+ // src/blucks/components/scrollToTopFab.tsx
12
+ /** Frames the scroller may sit still before the climb counts as stalled. */
13
+ var STALLED_FRAMES = 3;
14
+ /** Reader input that means the scroller is theirs again. */
15
+ var HANDOVER_EVENTS = [
16
+ "wheel",
17
+ "touchstart",
18
+ "pointerdown",
19
+ "keydown"
20
+ ];
21
+ function ScrollToTopFab(t0) {
22
+ const $ = c(25);
23
+ const { screensBeforeVisible: t1, position: t2, className, theme: t3, icon: t4, animate: t5 } = t0;
24
+ const screensBeforeVisible = t1 === void 0 ? 2.5 : t1;
25
+ const position = t2 === void 0 ? "bottom-right" : t2;
26
+ const theme = t3 === void 0 ? false : t3;
27
+ const icon = t4 === void 0 ? FlyingHumanIcon : t4;
28
+ const animate = t5 === void 0 ? true : t5;
29
+ const labels = useBrucksLabels();
30
+ const fadesOnScroll = position !== "inline";
31
+ const fabRef = useRef(null);
32
+ const scrollAncestor = useScrollAncestor(fabRef);
33
+ const [visible, setVisible] = useState(false);
34
+ let t6;
35
+ let t7;
36
+ if ($[0] !== fadesOnScroll || $[1] !== screensBeforeVisible || $[2] !== scrollAncestor) {
37
+ t6 = () => {
38
+ if (!scrollAncestor || !fadesOnScroll) return;
39
+ const onScroll = () => {
40
+ setVisible(scrollAncestor.scrollTop > scrollAncestor.clientHeight * screensBeforeVisible);
41
+ };
42
+ const scrollTarget = scrollAncestor === document.documentElement ? document : scrollAncestor;
43
+ onScroll();
44
+ scrollTarget.addEventListener("scroll", onScroll, { passive: true });
45
+ return () => scrollTarget.removeEventListener("scroll", onScroll);
46
+ };
47
+ t7 = [
48
+ scrollAncestor,
49
+ screensBeforeVisible,
50
+ fadesOnScroll
51
+ ];
52
+ $[0] = fadesOnScroll;
53
+ $[1] = screensBeforeVisible;
54
+ $[2] = scrollAncestor;
55
+ $[3] = t6;
56
+ $[4] = t7;
57
+ } else {
58
+ t6 = $[3];
59
+ t7 = $[4];
60
+ }
61
+ useEffect(t6, t7);
62
+ const endClimb = useRef(null);
63
+ let t8;
64
+ let t9;
65
+ if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
66
+ t8 = () => () => endClimb.current?.();
67
+ t9 = [];
68
+ $[5] = t8;
69
+ $[6] = t9;
70
+ } else {
71
+ t8 = $[5];
72
+ t9 = $[6];
73
+ }
74
+ useEffect(t8, t9);
75
+ let t10;
76
+ if ($[7] !== scrollAncestor) {
77
+ t10 = () => {
78
+ if (!scrollAncestor) return;
79
+ endClimb.current?.();
80
+ const fab = fabRef.current;
81
+ if (fab && document.activeElement === fab) {
82
+ scrollAncestor.focus({ preventScroll: true });
83
+ if (document.activeElement === fab) fab.blur();
84
+ }
85
+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
86
+ scrollAncestor.scrollTo({
87
+ top: 0,
88
+ behavior: "auto"
89
+ });
90
+ return;
91
+ }
92
+ const runway = scrollAncestor.clientHeight;
93
+ if (scrollAncestor.scrollTop > runway) scrollAncestor.scrollTo({
94
+ top: runway,
95
+ behavior: "auto"
96
+ });
97
+ scrollAncestor.scrollTo({
98
+ top: 0,
99
+ behavior: "smooth"
100
+ });
101
+ let frame = requestAnimationFrame(tick);
102
+ let previousTop = scrollAncestor.scrollTop;
103
+ let stalledFrames = 0;
104
+ function tick() {
105
+ if (!scrollAncestor) return;
106
+ const { scrollTop } = scrollAncestor;
107
+ if (scrollTop === 0) {
108
+ endClimb.current?.();
109
+ return;
110
+ }
111
+ stalledFrames = scrollTop === previousTop ? stalledFrames + 1 : 0;
112
+ previousTop = scrollTop;
113
+ if (stalledFrames >= STALLED_FRAMES) {
114
+ stalledFrames = 0;
115
+ scrollAncestor.scrollTo({
116
+ top: 0,
117
+ behavior: "smooth"
118
+ });
119
+ }
120
+ frame = requestAnimationFrame(tick);
121
+ }
122
+ const stop = () => endClimb.current?.();
123
+ for (const event of HANDOVER_EVENTS) scrollAncestor.addEventListener(event, stop, { passive: true });
124
+ endClimb.current = () => {
125
+ cancelAnimationFrame(frame);
126
+ for (const event_0 of HANDOVER_EVENTS) scrollAncestor.removeEventListener(event_0, stop);
127
+ endClimb.current = null;
128
+ };
129
+ };
130
+ $[7] = scrollAncestor;
131
+ $[8] = t10;
132
+ } else t10 = $[8];
133
+ const scrollToTop = t10;
134
+ const t11 = fadesOnScroll ? visible : true;
135
+ const t12 = theme ? "text-theme-600" : null;
136
+ let t13;
137
+ if ($[9] !== className || $[10] !== t12) {
138
+ t13 = cn(className, t12);
139
+ $[9] = className;
140
+ $[10] = t12;
141
+ $[11] = t13;
142
+ } else t13 = $[11];
143
+ const t14 = labels.scrollToTop;
144
+ const t15 = animate && "animate-flap";
145
+ const t16 = icon === FlyingHumanIcon && "-rotate-25";
146
+ let t17;
147
+ if ($[12] !== t15 || $[13] !== t16) {
148
+ t17 = cn(t15, t16);
149
+ $[12] = t15;
150
+ $[13] = t16;
151
+ $[14] = t17;
152
+ } else t17 = $[14];
153
+ let t18;
154
+ if ($[15] !== icon || $[16] !== t17) {
155
+ t18 = /* @__PURE__ */ jsx(AppIcon, {
156
+ icon,
157
+ className: t17
158
+ });
159
+ $[15] = icon;
160
+ $[16] = t17;
161
+ $[17] = t18;
162
+ } else t18 = $[17];
163
+ let t19;
164
+ if ($[18] !== labels.scrollToTop || $[19] !== position || $[20] !== scrollToTop || $[21] !== t11 || $[22] !== t13 || $[23] !== t18) {
165
+ t19 = /* @__PURE__ */ jsx(Fab, {
166
+ ref: fabRef,
167
+ type: "button",
168
+ position,
169
+ visible: t11,
170
+ className: t13,
171
+ "aria-label": t14,
172
+ onClick: scrollToTop,
173
+ children: t18
174
+ });
175
+ $[18] = labels.scrollToTop;
176
+ $[19] = position;
177
+ $[20] = scrollToTop;
178
+ $[21] = t11;
179
+ $[22] = t13;
180
+ $[23] = t18;
181
+ $[24] = t19;
182
+ } else t19 = $[24];
183
+ return t19;
184
+ }
185
+ export { ScrollToTopFab };
186
+
187
+ //# sourceMappingURL=scrollToTopFab.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrollToTopFab.js","names":["c","_c","FlyingHumanIcon","ComponentProps","useEffect","useRef","useState","useScrollAncestor","cn","Fab","AppIcon","useBrucksLabels","STALLED_FRAMES","HANDOVER_EVENTS","const","ScrollToTopFabProps","screensBeforeVisible","position","className","theme","icon","animate","ScrollToTopFab","t0","$","t1","t2","t3","t4","t5","undefined","labels","fadesOnScroll","fabRef","scrollAncestor","visible","setVisible","t6","t7","onScroll","scrollTop","clientHeight","scrollTarget","document","documentElement","addEventListener","passive","removeEventListener","endClimb","t8","t9","Symbol","for","current","t10","fab","activeElement","focus","preventScroll","blur","window","matchMedia","matches","scrollTo","top","behavior","runway","frame","requestAnimationFrame","tick","previousTop","stalledFrames","stop","event","cancelAnimationFrame","event_0","scrollToTop","t11","t12","t13","t14","t15","t16","t17","t18","t19","_c"],"sources":["../../../src/blucks/components/scrollToTopFab.tsx"],"sourcesContent":["\"use client\";\n\nimport { FlyingHumanIcon } from \"@hugeicons/core-free-icons\";\nimport { type ComponentProps, useEffect, useRef, useState } from \"react\";\nimport { useScrollAncestor } from \"~/blucks/hooks/useScrollAncestor\";\nimport { cn } from \"~/style/utils\";\nimport { Fab } from \"~/ui/components/fab\";\nimport { AppIcon } from \"~/ui/components/icon\";\nimport { useBrucksLabels } from \"~/ui/lib/labels\";\n\n/** Frames the scroller may sit still before the climb counts as stalled. */\nconst STALLED_FRAMES = 3;\n\n/** Reader input that means the scroller is theirs again. */\nconst HANDOVER_EVENTS = [\"wheel\", \"touchstart\", \"pointerdown\", \"keydown\"] as const;\n\ntype ScrollToTopFabProps = {\n /** How many screen heights must be scrolled before the button appears. */\n screensBeforeVisible?: number;\n /** `inline` drops the fixed positioning and keeps the button in normal flow. */\n position?: \"bottom-right\" | \"bottom-left\" | \"inline\";\n className?: string;\n /** Draws the icon in the theme accent. */\n theme?: boolean;\n icon?: ComponentProps<typeof AppIcon>[\"icon\"];\n /** Rocks the icon with the flap animation. */\n animate?: boolean;\n};\n\nfunction ScrollToTopFab({\n screensBeforeVisible = 2.5,\n position = \"bottom-right\",\n className,\n theme = false,\n icon = FlyingHumanIcon,\n animate = true,\n}: ScrollToTopFabProps) {\n const labels = useBrucksLabels();\n\n // An in-flow button would leave a hole while hidden, so it never fades out.\n const fadesOnScroll = position !== \"inline\";\n\n const fabRef = useRef<HTMLButtonElement>(null);\n const scrollAncestor = useScrollAncestor(fabRef);\n const [visible, setVisible] = useState(false);\n\n useEffect(() => {\n if (!scrollAncestor || !fadesOnScroll) return;\n\n const onScroll = () => {\n setVisible(scrollAncestor.scrollTop > scrollAncestor.clientHeight * screensBeforeVisible);\n };\n\n // The page's own scrolling fires its scroll events at the document, not at <html>.\n const scrollTarget: EventTarget =\n scrollAncestor === document.documentElement ? document : scrollAncestor;\n\n onScroll();\n scrollTarget.addEventListener(\"scroll\", onScroll, { passive: true });\n\n return () => scrollTarget.removeEventListener(\"scroll\", onScroll);\n }, [scrollAncestor, screensBeforeVisible, fadesOnScroll]);\n\n /** Tears down an in-flight climb: the frame loop and its handover listeners. */\n const endClimb = useRef<(() => void) | null>(null);\n useEffect(() => () => endClimb.current?.(), []);\n\n const scrollToTop = () => {\n if (!scrollAncestor) return;\n endClimb.current?.();\n\n // Focus goes up with the reader, instead of staying on a button left at the bottom (and hidden there).\n const fab = fabRef.current;\n if (fab && document.activeElement === fab) {\n scrollAncestor.focus({ preventScroll: true });\n if (document.activeElement === fab) fab.blur();\n }\n\n if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n scrollAncestor.scrollTo({ top: 0, behavior: \"auto\" });\n return;\n }\n\n /*\n * The browser paces a smooth scroll by its distance, and a virtualized list\n * puts hundreds of thousands of pixels between the bottom and the top, so\n * animating the whole trip crawls. Cut to within a screen of the top - none\n * of what is skipped is on screen long enough to read - and animate only\n * that last leg.\n */\n const runway = scrollAncestor.clientHeight;\n if (scrollAncestor.scrollTop > runway) {\n scrollAncestor.scrollTo({ top: runway, behavior: \"auto\" });\n }\n\n scrollAncestor.scrollTo({ top: 0, behavior: \"smooth\" });\n\n /*\n * A virtualized list remeasures rows as they scroll into view and re-anchors\n * the scroll offset to keep them from jumping, which cancels the native\n * animation partway up. Re-aim whenever the climb stalls short of the top,\n * and hand the scroller back the moment the reader touches it.\n */\n let frame = requestAnimationFrame(tick);\n let previousTop = scrollAncestor.scrollTop;\n let stalledFrames = 0;\n\n function tick() {\n if (!scrollAncestor) return;\n const { scrollTop } = scrollAncestor;\n\n if (scrollTop === 0) {\n endClimb.current?.();\n return;\n }\n\n stalledFrames = scrollTop === previousTop ? stalledFrames + 1 : 0;\n previousTop = scrollTop;\n\n if (stalledFrames >= STALLED_FRAMES) {\n stalledFrames = 0;\n scrollAncestor.scrollTo({ top: 0, behavior: \"smooth\" });\n }\n\n frame = requestAnimationFrame(tick);\n }\n\n const stop = () => endClimb.current?.();\n for (const event of HANDOVER_EVENTS) {\n scrollAncestor.addEventListener(event, stop, { passive: true });\n }\n\n endClimb.current = () => {\n cancelAnimationFrame(frame);\n for (const event of HANDOVER_EVENTS) {\n scrollAncestor.removeEventListener(event, stop);\n }\n endClimb.current = null;\n };\n };\n\n return (\n <Fab\n ref={fabRef}\n type=\"button\"\n position={position}\n visible={fadesOnScroll ? visible : true}\n className={cn(className, theme ? \"text-theme-600\" : null)}\n aria-label={labels.scrollToTop}\n onClick={scrollToTop}\n >\n <AppIcon\n icon={icon}\n className={cn(animate && \"animate-flap\", icon === FlyingHumanIcon && \"-rotate-25\")}\n />\n </Fab>\n );\n}\n\nexport { ScrollToTopFab };\n"],"mappings":";;;;;;;;;;;;AAWA,IAAMY,iBAAiB;;AAGvB,IAAMC,kBAAkB;CAAC;CAAS;CAAc;CAAe;AAAS;AAexE,SAAAS,eAAAC,IAAA;CAAA,MAAAC,IAAAvB,EAAA,EAAA;CAAwB,MAAA,EAAAe,sBAAAS,IAAAR,UAAAS,IAAAR,WAAAC,OAAAQ,IAAAP,MAAAQ,IAAAP,SAAAQ,OAAAN;CACtB,MAAAP,uBAAAS,OAAAK,KAAAA,IAAA,MAAAL;CACA,MAAAR,WAAAS,OAAAI,KAAAA,IAAA,iBAAAJ;CAEA,MAAAP,QAAAQ,OAAAG,KAAAA,IAAA,QAAAH;CACA,MAAAP,OAAAQ,OAAAE,KAAAA,IAAA5B,kBAAA0B;CACA,MAAAP,UAAAQ,OAAAC,KAAAA,IAAA,OAAAD;CA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CAAA;EAaE5D,EAAA,MAAAO,OAAA6C;EAAApD,EAAA,MAAAP;EAAAO,EAAA,MAAAoD;EAAApD,EAAA,MAAAqD;EAAArD,EAAA,MAAAuD;EAAAvD,EAAA,MAAA4D;EAAA5D,EAAA,MAAA6D;CAAA,OAAAA,MAAA7D,EAAA;CAAA,OAbN6D;AAaM"}
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from "react";
2
+ interface SettingsPickerModalProps {
3
+ open: boolean;
4
+ /** Names the dialog; without it brucks falls back to the generic "Dialog". */
5
+ title: string;
6
+ onClose: () => void;
7
+ gridClassName: string;
8
+ children: ReactNode;
9
+ }
10
+ declare function SettingsPickerModal({ open, title, onClose, gridClassName, children, }: SettingsPickerModalProps): import("react").JSX.Element;
11
+ export { SettingsPickerModal };