@mrpelz/uikit-ish 7.8.0 → 7.10.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 (308) hide show
  1. package/dist/components/accordion/main.d.ts +12 -0
  2. package/dist/components/accordion/main.d.ts.map +1 -0
  3. package/dist/components/accordion/main.js +20 -0
  4. package/dist/components/accordion/main.js.map +1 -0
  5. package/dist/components/accordion/style.css +23 -0
  6. package/dist/components/action-sheet/main.d.ts +22 -16
  7. package/dist/components/action-sheet/main.d.ts.map +1 -1
  8. package/dist/components/action-sheet/main.js +89 -19
  9. package/dist/components/action-sheet/main.js.map +1 -1
  10. package/dist/components/action-sheet/props.d.ts +17 -5
  11. package/dist/components/action-sheet/props.d.ts.map +1 -1
  12. package/dist/components/action-sheet/style.css +24 -0
  13. package/dist/components/activity-view/main.d.ts +15 -4
  14. package/dist/components/activity-view/main.d.ts.map +1 -1
  15. package/dist/components/activity-view/main.js +27 -14
  16. package/dist/components/activity-view/main.js.map +1 -1
  17. package/dist/components/activity-view/props.d.ts +2 -10
  18. package/dist/components/activity-view/props.d.ts.map +1 -1
  19. package/dist/components/activity-view/style.css +29 -67
  20. package/dist/components/alert/main.d.ts +8 -7
  21. package/dist/components/alert/main.d.ts.map +1 -1
  22. package/dist/components/alert/main.js +32 -19
  23. package/dist/components/alert/main.js.map +1 -1
  24. package/dist/components/alert/props.d.ts +13 -2
  25. package/dist/components/alert/props.d.ts.map +1 -1
  26. package/dist/components/alert/style.css +36 -50
  27. package/dist/components/avatar/main.d.ts +5 -3
  28. package/dist/components/avatar/main.d.ts.map +1 -1
  29. package/dist/components/avatar/main.js +10 -8
  30. package/dist/components/avatar/main.js.map +1 -1
  31. package/dist/components/avatar/props.d.ts +4 -0
  32. package/dist/components/avatar/props.d.ts.map +1 -1
  33. package/dist/components/avatar/style.css +1 -7
  34. package/dist/components/badge/main.d.ts +3 -3
  35. package/dist/components/badge/main.d.ts.map +1 -1
  36. package/dist/components/badge/main.js +9 -9
  37. package/dist/components/badge/main.js.map +1 -1
  38. package/dist/components/badge/props.d.ts +4 -3
  39. package/dist/components/badge/props.d.ts.map +1 -1
  40. package/dist/components/badge/style.css +10 -4
  41. package/dist/components/button/main.d.ts.map +1 -1
  42. package/dist/components/button/main.js +15 -15
  43. package/dist/components/button/main.js.map +1 -1
  44. package/dist/components/button/props.d.ts +8 -8
  45. package/dist/components/button/props.d.ts.map +1 -1
  46. package/dist/components/button/style.css +37 -55
  47. package/dist/components/checkbox/main.d.ts.map +1 -1
  48. package/dist/components/checkbox/main.js +5 -7
  49. package/dist/components/checkbox/main.js.map +1 -1
  50. package/dist/components/checkbox/style.css +5 -8
  51. package/dist/components/collapsible/main.d.ts +9 -0
  52. package/dist/components/collapsible/main.d.ts.map +1 -0
  53. package/dist/components/collapsible/main.js +19 -0
  54. package/dist/components/collapsible/main.js.map +1 -0
  55. package/dist/components/collapsible/style.css +23 -0
  56. package/dist/components/color-picker/main.d.ts +27 -4
  57. package/dist/components/color-picker/main.d.ts.map +1 -1
  58. package/dist/components/color-picker/main.js +292 -110
  59. package/dist/components/color-picker/main.js.map +1 -1
  60. package/dist/components/color-picker/props.d.ts +64 -15
  61. package/dist/components/color-picker/props.d.ts.map +1 -1
  62. package/dist/components/color-picker/style.css +133 -65
  63. package/dist/components/contextual-menu/main.d.ts +11 -7
  64. package/dist/components/contextual-menu/main.d.ts.map +1 -1
  65. package/dist/components/contextual-menu/main.js +207 -202
  66. package/dist/components/contextual-menu/main.js.map +1 -1
  67. package/dist/components/contextual-menu/props.d.ts +21 -34
  68. package/dist/components/contextual-menu/props.d.ts.map +1 -1
  69. package/dist/components/contextual-menu/style.css +63 -34
  70. package/dist/components/date-picker/handle.d.ts +41 -0
  71. package/dist/components/date-picker/handle.d.ts.map +1 -0
  72. package/dist/components/date-picker/handle.js +47 -0
  73. package/dist/components/date-picker/handle.js.map +1 -0
  74. package/dist/components/date-picker/main.d.ts +31 -49
  75. package/dist/components/date-picker/main.d.ts.map +1 -1
  76. package/dist/components/date-picker/main.js +373 -178
  77. package/dist/components/date-picker/main.js.map +1 -1
  78. package/dist/components/date-picker/pager.d.ts +24 -0
  79. package/dist/components/date-picker/pager.d.ts.map +1 -0
  80. package/dist/components/date-picker/pager.js +307 -0
  81. package/dist/components/date-picker/pager.js.map +1 -0
  82. package/dist/components/date-picker/props.d.ts +98 -27
  83. package/dist/components/date-picker/props.d.ts.map +1 -1
  84. package/dist/components/date-picker/style.css +110 -118
  85. package/dist/components/drawer/main.d.ts +31 -0
  86. package/dist/components/drawer/main.d.ts.map +1 -0
  87. package/dist/components/drawer/main.js +119 -0
  88. package/dist/components/drawer/main.js.map +1 -0
  89. package/dist/components/drawer/props.d.ts +39 -0
  90. package/dist/components/drawer/props.d.ts.map +1 -0
  91. package/dist/components/drawer/props.js +2 -0
  92. package/dist/components/drawer/props.js.map +1 -0
  93. package/dist/components/drawer/style.css +135 -0
  94. package/dist/components/edit-menu/main.d.ts +7 -7
  95. package/dist/components/edit-menu/main.d.ts.map +1 -1
  96. package/dist/components/edit-menu/main.js +57 -40
  97. package/dist/components/edit-menu/main.js.map +1 -1
  98. package/dist/components/edit-menu/props.d.ts +14 -1
  99. package/dist/components/edit-menu/props.d.ts.map +1 -1
  100. package/dist/components/edit-menu/style.css +15 -8
  101. package/dist/components/form/main.d.ts +8 -0
  102. package/dist/components/form/main.d.ts.map +1 -1
  103. package/dist/components/form/main.js +18 -5
  104. package/dist/components/form/main.js.map +1 -1
  105. package/dist/components/form/props.d.ts +1 -2
  106. package/dist/components/form/props.d.ts.map +1 -1
  107. package/dist/components/glass/main.d.ts +1 -1
  108. package/dist/components/glass/main.js +4 -4
  109. package/dist/components/glass/main.js.map +1 -1
  110. package/dist/components/glass/props.d.ts +5 -5
  111. package/dist/components/glass/props.d.ts.map +1 -1
  112. package/dist/components/glass/style.css +176 -161
  113. package/dist/components/header/main.d.ts +5 -4
  114. package/dist/components/header/main.d.ts.map +1 -1
  115. package/dist/components/header/main.js +64 -34
  116. package/dist/components/header/main.js.map +1 -1
  117. package/dist/components/header/props.d.ts +2 -3
  118. package/dist/components/header/props.d.ts.map +1 -1
  119. package/dist/components/header/style.css +46 -65
  120. package/dist/components/index.d.ts +27 -23
  121. package/dist/components/index.d.ts.map +1 -1
  122. package/dist/components/index.js +17 -13
  123. package/dist/components/index.js.map +1 -1
  124. package/dist/components/layout/main.d.ts +2 -2
  125. package/dist/components/layout/main.d.ts.map +1 -1
  126. package/dist/components/layout/main.js +63 -167
  127. package/dist/components/layout/main.js.map +1 -1
  128. package/dist/components/layout/props.d.ts +2 -20
  129. package/dist/components/layout/props.d.ts.map +1 -1
  130. package/dist/components/layout/style.css +20 -91
  131. package/dist/components/list/main.d.ts +58 -10
  132. package/dist/components/list/main.d.ts.map +1 -1
  133. package/dist/components/list/main.js +1022 -465
  134. package/dist/components/list/main.js.map +1 -1
  135. package/dist/components/list/props.d.ts +211 -21
  136. package/dist/components/list/props.d.ts.map +1 -1
  137. package/dist/components/list/reorder.d.ts +146 -0
  138. package/dist/components/list/reorder.d.ts.map +1 -0
  139. package/dist/components/list/reorder.js +819 -0
  140. package/dist/components/list/reorder.js.map +1 -0
  141. package/dist/components/list/select.d.ts +6 -0
  142. package/dist/components/list/select.d.ts.map +1 -0
  143. package/dist/components/list/select.js +141 -0
  144. package/dist/components/list/select.js.map +1 -0
  145. package/dist/components/list/style.css +492 -507
  146. package/dist/components/list/swipe-actions-handle.d.ts +40 -0
  147. package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
  148. package/dist/components/list/swipe-actions-handle.js +51 -0
  149. package/dist/components/list/swipe-actions-handle.js.map +1 -0
  150. package/dist/components/menu/main.d.ts +102 -32
  151. package/dist/components/menu/main.d.ts.map +1 -1
  152. package/dist/components/menu/main.js +510 -99
  153. package/dist/components/menu/main.js.map +1 -1
  154. package/dist/components/menu/props.d.ts +5 -5
  155. package/dist/components/menu/props.d.ts.map +1 -1
  156. package/dist/components/menu/style.css +35 -43
  157. package/dist/components/navigation/main.d.ts +14 -2
  158. package/dist/components/navigation/main.d.ts.map +1 -1
  159. package/dist/components/navigation/main.js +437 -119
  160. package/dist/components/navigation/main.js.map +1 -1
  161. package/dist/components/navigation/props.d.ts +53 -3
  162. package/dist/components/navigation/props.d.ts.map +1 -1
  163. package/dist/components/navigation/style.css +56 -9
  164. package/dist/components/page/main.d.ts.map +1 -1
  165. package/dist/components/page/main.js +13 -8
  166. package/dist/components/page/main.js.map +1 -1
  167. package/dist/components/page/props.d.ts +8 -0
  168. package/dist/components/page/props.d.ts.map +1 -1
  169. package/dist/components/page/style.css +39 -4
  170. package/dist/components/page-control/main.d.ts +2 -2
  171. package/dist/components/page-control/main.d.ts.map +1 -1
  172. package/dist/components/page-control/main.js +66 -32
  173. package/dist/components/page-control/main.js.map +1 -1
  174. package/dist/components/page-control/props.d.ts +10 -2
  175. package/dist/components/page-control/props.d.ts.map +1 -1
  176. package/dist/components/page-control/style.css +7 -2
  177. package/dist/components/popover/main.d.ts +11 -6
  178. package/dist/components/popover/main.d.ts.map +1 -1
  179. package/dist/components/popover/main.js +63 -38
  180. package/dist/components/popover/main.js.map +1 -1
  181. package/dist/components/popover/props.d.ts +7 -6
  182. package/dist/components/popover/props.d.ts.map +1 -1
  183. package/dist/components/popover/style.css +54 -4
  184. package/dist/components/progress/main.d.ts +2 -3
  185. package/dist/components/progress/main.d.ts.map +1 -1
  186. package/dist/components/progress/main.js +148 -29
  187. package/dist/components/progress/main.js.map +1 -1
  188. package/dist/components/progress/props.d.ts +43 -9
  189. package/dist/components/progress/props.d.ts.map +1 -1
  190. package/dist/components/progress/style.css +82 -50
  191. package/dist/components/roll/main.d.ts +1 -1
  192. package/dist/components/roll/main.d.ts.map +1 -1
  193. package/dist/components/roll/main.js +90 -34
  194. package/dist/components/roll/main.js.map +1 -1
  195. package/dist/components/roll/props.d.ts +25 -8
  196. package/dist/components/roll/props.d.ts.map +1 -1
  197. package/dist/components/roll/style.css +12 -24
  198. package/dist/components/segmented/main.d.ts.map +1 -1
  199. package/dist/components/segmented/main.js +47 -30
  200. package/dist/components/segmented/main.js.map +1 -1
  201. package/dist/components/segmented/style.css +16 -23
  202. package/dist/components/sheet/main.d.ts +25 -15
  203. package/dist/components/sheet/main.d.ts.map +1 -1
  204. package/dist/components/sheet/main.js +66 -78
  205. package/dist/components/sheet/main.js.map +1 -1
  206. package/dist/components/sheet/props.d.ts +37 -3
  207. package/dist/components/sheet/props.d.ts.map +1 -1
  208. package/dist/components/sheet/style.css +183 -45
  209. package/dist/components/sidebar/main.d.ts.map +1 -1
  210. package/dist/components/sidebar/main.js +9 -13
  211. package/dist/components/sidebar/main.js.map +1 -1
  212. package/dist/components/sidebar/style.css +20 -14
  213. package/dist/components/slider/main.d.ts.map +1 -1
  214. package/dist/components/slider/main.js +23 -22
  215. package/dist/components/slider/main.js.map +1 -1
  216. package/dist/components/slider/props.d.ts +1 -2
  217. package/dist/components/slider/props.d.ts.map +1 -1
  218. package/dist/components/slider/style.css +27 -53
  219. package/dist/components/stepper/main.d.ts +4 -6
  220. package/dist/components/stepper/main.d.ts.map +1 -1
  221. package/dist/components/stepper/main.js +29 -25
  222. package/dist/components/stepper/main.js.map +1 -1
  223. package/dist/components/stepper/style.css +12 -16
  224. package/dist/components/switch/main.d.ts.map +1 -1
  225. package/dist/components/switch/main.js +40 -28
  226. package/dist/components/switch/main.js.map +1 -1
  227. package/dist/components/switch/props.d.ts +7 -5
  228. package/dist/components/switch/props.d.ts.map +1 -1
  229. package/dist/components/switch/style.css +40 -17
  230. package/dist/components/symbol/main.d.ts +2 -2
  231. package/dist/components/symbol/main.d.ts.map +1 -1
  232. package/dist/components/symbol/main.js +36 -28
  233. package/dist/components/symbol/main.js.map +1 -1
  234. package/dist/components/symbol/props.d.ts +39 -4
  235. package/dist/components/symbol/props.d.ts.map +1 -1
  236. package/dist/components/symbol/style.css +26 -5
  237. package/dist/components/tab-bar/main.d.ts +2 -2
  238. package/dist/components/tab-bar/main.d.ts.map +1 -1
  239. package/dist/components/tab-bar/main.js +133 -101
  240. package/dist/components/tab-bar/main.js.map +1 -1
  241. package/dist/components/tab-bar/props.d.ts +6 -6
  242. package/dist/components/tab-bar/props.d.ts.map +1 -1
  243. package/dist/components/tab-bar/style.css +113 -99
  244. package/dist/components/text-field/main.d.ts +3 -2
  245. package/dist/components/text-field/main.d.ts.map +1 -1
  246. package/dist/components/text-field/main.js +29 -30
  247. package/dist/components/text-field/main.js.map +1 -1
  248. package/dist/components/text-field/props.d.ts +23 -1
  249. package/dist/components/text-field/props.d.ts.map +1 -1
  250. package/dist/components/text-field/style.css +122 -82
  251. package/dist/components/toolbar/main.js +27 -27
  252. package/dist/components/toolbar/main.js.map +1 -1
  253. package/dist/components/toolbar/props.d.ts +10 -4
  254. package/dist/components/toolbar/props.d.ts.map +1 -1
  255. package/dist/components/toolbar/style.css +39 -33
  256. package/dist/components/tooltip/main.d.ts +10 -9
  257. package/dist/components/tooltip/main.d.ts.map +1 -1
  258. package/dist/components/tooltip/main.js +39 -10
  259. package/dist/components/tooltip/main.js.map +1 -1
  260. package/dist/components/tooltip/props.d.ts +2 -0
  261. package/dist/components/tooltip/props.d.ts.map +1 -1
  262. package/dist/components/tooltip/style.css +16 -16
  263. package/dist/components/typography/main.d.ts +2 -2
  264. package/dist/components/typography/main.d.ts.map +1 -1
  265. package/dist/components/typography/main.js +24 -16
  266. package/dist/components/typography/main.js.map +1 -1
  267. package/dist/components/typography/props.d.ts +11 -18
  268. package/dist/components/typography/props.d.ts.map +1 -1
  269. package/dist/components/typography/style.css +503 -623
  270. package/dist/components/utils/main.d.ts +78 -8
  271. package/dist/components/utils/main.d.ts.map +1 -1
  272. package/dist/components/utils/main.js +235 -16
  273. package/dist/components/utils/main.js.map +1 -1
  274. package/dist/components/utils/props.d.ts +27 -4
  275. package/dist/components/utils/props.d.ts.map +1 -1
  276. package/dist/components/utils/style.css +31 -18
  277. package/dist/components/viewport/edge-effect.d.ts +10 -0
  278. package/dist/components/viewport/edge-effect.d.ts.map +1 -0
  279. package/dist/components/viewport/edge-effect.js +100 -0
  280. package/dist/components/viewport/edge-effect.js.map +1 -0
  281. package/dist/components/viewport/edge.d.ts +39 -0
  282. package/dist/components/viewport/edge.d.ts.map +1 -0
  283. package/dist/components/viewport/edge.js +151 -0
  284. package/dist/components/viewport/edge.js.map +1 -0
  285. package/dist/components/viewport/input.d.ts +39 -0
  286. package/dist/components/viewport/input.d.ts.map +1 -0
  287. package/dist/components/viewport/input.js +280 -0
  288. package/dist/components/viewport/input.js.map +1 -0
  289. package/dist/components/viewport/main.d.ts +47 -9
  290. package/dist/components/viewport/main.d.ts.map +1 -1
  291. package/dist/components/viewport/main.js +745 -86
  292. package/dist/components/viewport/main.js.map +1 -1
  293. package/dist/components/viewport/padding.d.ts +78 -0
  294. package/dist/components/viewport/padding.d.ts.map +1 -0
  295. package/dist/components/viewport/padding.js +321 -0
  296. package/dist/components/viewport/padding.js.map +1 -0
  297. package/dist/components/viewport/props.d.ts +220 -11
  298. package/dist/components/viewport/props.d.ts.map +1 -1
  299. package/dist/components/viewport/style.css +377 -6
  300. package/dist/main.d.ts +0 -1
  301. package/dist/main.d.ts.map +1 -1
  302. package/dist/main.js.map +1 -1
  303. package/dist/styles.css +318 -302
  304. package/dist/styles.d.ts +2 -1
  305. package/dist/styles.d.ts.map +1 -1
  306. package/dist/styles.js +2 -1
  307. package/dist/styles.js.map +1 -1
  308. package/package.json +8 -16
@@ -1,12 +1,14 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /* eslint-disable unicorn/prefer-ternary */
3
3
  import './style.css';
4
- import { Children, forwardRef, isValidElement, useLayoutEffect, useRef, useState, } from 'react';
5
- import { cn, useForwardedRef } from '../utils/main.js';
6
- // Navigation (UIKit `UINavigationController`, after Framework7's views and
4
+ import { useRender } from '@base-ui/react/use-render';
5
+ import { Children, createContext, forwardRef, isValidElement, useContext, useLayoutEffect, useRef, useState, } from 'react';
6
+ import { cn, useForwardedRef, withStyle } from '../utils/main.js';
7
+ // Navigation (after Framework7's views and
7
8
  // `router` transitions, without its routing): a stack of pages, the app's
8
- // (no router of its own). The app renders its stack's pages as children,
9
- // each with a key; the navigation transitions between them:
9
+ // (no router of its own). The app renders its stack's pages as its
10
+ // `Stack`'s children, each with a key; the navigation transitions between
11
+ // them:
10
12
  //
11
13
  // - a page added on top (keys extended): pushed, sliding in from the
12
14
  // trailing edge over the page under it, which moves on a little and dims;
@@ -15,19 +17,30 @@ import { cn, useForwardedRef } from '../utils/main.js';
15
17
  // - anything else (e.g. another stack, a sibling's): shown at once, no
16
18
  // transition.
17
19
  //
18
- // Swiping from the top page's leading edge (touch, or a mouse) pops it
19
- // interactively: released past half the width (or flung), `onBack` is
20
- // called for the app to pop its stack (the transition is done by then);
21
- // otherwise it settles back.
20
+ // Swiping from the top page's leading edge (its `SwipeArea`: touch, or a
21
+ // mouse) pops it interactively: released past half the width (or flung),
22
+ // `onBack` is called for the app to pop its stack, its pop on from where
23
+ // the swipe left it; otherwise it settles back. A `Back` (e.g. a bar's back
24
+ // button) calls `onBack` too, the app's pop transitioning as any.
25
+ //
26
+ // Popped again while popping (e.g. a back button pressed again, or swiped
27
+ // again), each pop runs its own transition: the page on top leaves on its
28
+ // own, on from where it is, and the page it revealed starts leaving too (a
29
+ // cascade; swiped, by the swipe); pushed back mid-transition, the push
30
+ // reverses from where it is. (Not swiped while pushing.)
22
31
  //
23
32
  // Pages under the top one stay mounted (their state and scroll positions
24
- // kept), hidden. A page's `Header` blends over: its bar stays in place
25
- // while its content fades (the large title moves with the page).
33
+ // kept), hidden. A page's `Header` moves with its page, its bar too; its
34
+ // persistent items (e.g. its back button, see `Persistent`) stay put while
35
+ // the other page moving has them too. What stays regardless (e.g. a bar of
36
+ // the app's) is in the `Root`, outside its `Stack`.
26
37
  //
27
- // Deviations:
28
- // - The bar's title cross-fades in place (iOS: it moves to the back
29
- // button's place, and the back button's label to the title's).
30
- /** Pushing and popping (iOS: about 350ms, an ease-out curve). */
38
+ // Also:
39
+ // - Each page's bar moves with it, its title too; the back button stays, in a bar of
40
+ // the app's outside the stack (see above), or in each page's bar, a
41
+ // persistent item (see `Persistent`): staying put between pages having
42
+ // one, moving with a page where only it has one.
43
+ /** Pushing and popping (350ms, an ease-out curve). */
31
44
  const duration = 350;
32
45
  const easing = 'cubic-bezier(0.2, 0.9, 0.3, 1)';
33
46
  /**
@@ -39,83 +52,372 @@ const flingWindow = 100;
39
52
  const isPrefix = (shorter, longer) => shorter.length < longer.length &&
40
53
  shorter.every((key, index) => longer[index] === key);
41
54
  const sameKeys = (a, b) => a.length === b.length && a.every((key, index) => b[index] === key);
42
- /** A navigation: the app's stack of pages (keyed children, see above). */
43
- const Root = forwardRef(({ className, children, onBack, ...props }, forwardedRef) => {
55
+ /**
56
+ * Its root, for its `Back`s (going back: the app's `onBack`, if it can),
57
+ * its `SwipeArea`s (swiping back, if it can), and its `Stack`.
58
+ */
59
+ const NavigationContext = createContext({});
60
+ /**
61
+ * A navigation: its stack's state (see above), its parts in it (its
62
+ * `Stack`, a `SwipeArea`, a bar that stays).
63
+ */
64
+ const Root = forwardRef(({ className, onBack, ...props }, forwardedRef) => {
44
65
  const ref = useForwardedRef(forwardedRef);
45
- const pages = Children.toArray(children).filter((child) => isValidElement(child));
46
- const keys = pages.map((page) => String(page.key));
47
- const previousRef = useRef({ keys, pages });
66
+ // Its stack's keys (reported by its `Stack`).
67
+ const [keys, setKeys] = useState([]);
48
68
  const [transition, setTransition] = useState(null);
49
- // The page a completed swipe popped (the app pops it: no transition).
50
- const swipedRef = useRef(undefined);
69
+ // (The latest, for a swipe's pop not taken up by the app.)
70
+ const keysRef = useRef(keys);
71
+ keysRef.current = keys;
51
72
  const timerRef = useRef(undefined);
73
+ const frameRef = useRef(undefined);
52
74
  const swipeRef = useRef(undefined);
53
75
  // The progress (and its transition), on the root.
54
- const setProgress = (progress, animate) => {
76
+ const setProgress = (progress, isAnimated) => {
55
77
  const { current: root } = ref;
56
78
  if (!root)
57
79
  return;
58
- root.style.transition = animate
80
+ root.style.transition = isAnimated
59
81
  ? `--uikit-navigation-progress ${String(duration)}ms ${easing}`
60
82
  : 'none';
61
83
  root.style.setProperty('--uikit-navigation-progress', String(progress));
84
+ // (Its width as a length: moved by it, persistent items stay put, see
85
+ // `Persistent`.)
86
+ root.style.setProperty('--uikit-navigation-width', `${String(root.clientWidth)}px`);
87
+ };
88
+ // An animation's next steps (see `animate`) dropped: another taking
89
+ // over, or a swipe.
90
+ const stop = () => {
91
+ clearTimeout(timerRef.current);
92
+ if (frameRef.current !== undefined) {
93
+ cancelAnimationFrame(frameRef.current);
94
+ }
95
+ frameRef.current = undefined;
62
96
  };
63
97
  // Animates the progress, then calls `done` (once it's there).
64
98
  const animate = (from, to, done) => {
65
- clearTimeout(timerRef.current);
99
+ stop();
66
100
  setProgress(from, false);
67
101
  ref.current?.getBoundingClientRect();
68
- requestAnimationFrame(() => {
102
+ frameRef.current = requestAnimationFrame(() => {
103
+ frameRef.current = undefined;
69
104
  setProgress(to, true);
70
105
  timerRef.current = setTimeout(done, duration + 50);
71
106
  });
72
107
  };
108
+ const currentProgress = () => {
109
+ const { current: root } = ref;
110
+ if (!root)
111
+ return 0;
112
+ return (Number.parseFloat(getComputedStyle(root).getPropertyValue('--uikit-navigation-progress')) || 0);
113
+ };
73
114
  const rest = () => {
74
115
  const { current: root } = ref;
75
116
  root?.style.removeProperty('transition');
76
117
  root?.style.removeProperty('--uikit-navigation-progress');
118
+ root?.style.removeProperty('--uikit-navigation-width');
77
119
  setTransition(null);
78
120
  };
79
- // Pushed, popped, or replaced (see above).
80
- useLayoutEffect(() => {
81
- const { current: previous } = previousRef;
82
- previousRef.current = { keys, pages };
83
- if (sameKeys(previous.keys, keys))
121
+ useLayoutEffect(() => stop, []);
122
+ // At rest, or popping (the page on top leaving: swiped back further, a
123
+ // cascade, see `startSwipe`); not while pushing, nor swiping.
124
+ const canSwipe = Boolean(onBack) &&
125
+ keys.length > 1 &&
126
+ (!transition || !keys.includes(transition.top));
127
+ // A swipe's transition (see `canSwipe`): the top page over the one under
128
+ // it; while popping, the page leaving on its own (on from where it is,
129
+ // as `Departing`), the top page from where it was revealed to (`from`).
130
+ const startSwipe = (top, under) => {
131
+ const { current: root } = ref;
132
+ if (!transition?.leaving || !root)
133
+ return { top, under };
134
+ const progress = currentProgress();
135
+ const direction = getComputedStyle(root).direction === 'rtl' ? -1 : 1;
136
+ return {
137
+ departing: [
138
+ ...(transition.departing ?? []),
139
+ { key: transition.top, page: transition.leaving, progress },
140
+ ],
141
+ from: (1 - progress) * -0.3 * root.clientWidth * direction,
142
+ top,
143
+ under,
144
+ };
145
+ };
146
+ // Where it's back where it started (0; started elsewhere, `from`: where
147
+ // the top page is shown again).
148
+ const shownAt = (from) => {
149
+ const { current: root } = ref;
150
+ if (!from || !root)
151
+ return 0;
152
+ const direction = getComputedStyle(root).direction === 'rtl' ? -1 : 1;
153
+ return from / (from - root.clientWidth * direction);
154
+ };
155
+ const endSwipe = (event) => {
156
+ const { current: swipe } = swipeRef;
157
+ if (swipe?.pointerId !== event.pointerId)
84
158
  return;
85
- const oldTop = previous.keys.at(-1);
86
- const newTop = keys.at(-1);
87
- if (oldTop === undefined || newTop === undefined || oldTop === newTop) {
88
- rest();
159
+ swipeRef.current = undefined;
160
+ // Its speed as released: over the last moves (held still: none).
161
+ const now = performance.now();
162
+ const recent = swipe.moves.find(([time]) => now - time < flingWindow);
163
+ const first = recent;
164
+ const velocity = first
165
+ ? ((swipe.progress - first[1]) * swipe.width) /
166
+ Math.max(now - first[0], 1)
167
+ : 0;
168
+ const top = keys.at(-1);
169
+ const from = transition?.from;
170
+ if (event.type !== 'pointercancel' &&
171
+ (swipe.progress > 0.5 || velocity > flingVelocity)) {
172
+ // Popped: on, the app's pop taking over (see `changeKeys`, from
173
+ // where it is); not popped by the app after all, back.
174
+ animate(swipe.progress, 1, () => {
175
+ if (top === undefined || !keysRef.current.includes(top))
176
+ return;
177
+ animate(1, shownAt(from), rest);
178
+ });
179
+ onBack?.({ event, reason: 'swipe' });
89
180
  return;
90
181
  }
91
- if (isPrefix(keys, previous.keys)) {
92
- // Swiped back: popped already.
93
- if (swipedRef.current === oldTop) {
94
- swipedRef.current = undefined;
95
- rest();
96
- return;
97
- }
98
- setTransition({
182
+ animate(swipe.progress, shownAt(from), rest);
183
+ };
184
+ const back = onBack && keys.length > 1
185
+ ? (eventDetails) => onBack(eventDetails)
186
+ : undefined;
187
+ // Where a swipe back starts (see `SwipeArea`): while one can, or goes on.
188
+ const swipeHandlers = canSwipe || swipeRef.current
189
+ ? {
190
+ onLostPointerCapture: endSwipe,
191
+ onPointerCancel: endSwipe,
192
+ onPointerUp: endSwipe,
193
+ onPointerDown: (event) => {
194
+ const { current: root } = ref;
195
+ const top = keys.at(-1);
196
+ const under = keys.at(-2);
197
+ if (!root || !top || !under || event.button !== 0)
198
+ return;
199
+ event.preventDefault();
200
+ event.currentTarget.setPointerCapture(event.pointerId);
201
+ const next = startSwipe(top, under);
202
+ // (The pop it interrupts: its pages on as `next` has them.)
203
+ stop();
204
+ swipeRef.current = {
205
+ pointerId: event.pointerId,
206
+ moves: [[performance.now(), 0]],
207
+ progress: 0,
208
+ width: root.clientWidth,
209
+ x: event.clientX,
210
+ };
211
+ setProgress(0, false);
212
+ setTransition(next);
213
+ },
214
+ onPointerMove: (event) => {
215
+ const { current: swipe } = swipeRef;
216
+ const { current: root } = ref;
217
+ if (swipe?.pointerId !== event.pointerId || !root)
218
+ return;
219
+ const direction = getComputedStyle(root).direction === 'rtl' ? -1 : 1;
220
+ const moved = (event.clientX - swipe.x) * direction;
221
+ swipe.progress = Math.min(Math.max(moved / swipe.width, 0), 1);
222
+ swipe.moves = [
223
+ ...swipe.moves.slice(-8),
224
+ [performance.now(), swipe.progress],
225
+ ];
226
+ setProgress(swipe.progress, false);
227
+ },
228
+ }
229
+ : undefined;
230
+ return (_jsx(NavigationContext.Provider, { value: {
231
+ back,
232
+ stack: {
233
+ animate,
234
+ progress: currentProgress,
235
+ rest,
236
+ setKeys,
237
+ setTransition,
238
+ transition,
239
+ },
240
+ swipe: swipeHandlers,
241
+ }, children: _jsx("div", { ref: ref, "data-navigation-moving": transition ? '' : undefined, "data-navigation-part": "root", ...props, className: cn('uikit-navigation-root', className) }) }));
242
+ });
243
+ /**
244
+ * A stack's keys changed (`previous` to `keys`, its tops differing): pushed,
245
+ * popped (also mid-transition, see `Stack`), or anything else (at rest).
246
+ */
247
+ const changeKeys = (stack, previous, keys, element) => {
248
+ const oldTop = previous.keys.at(-1) ?? '';
249
+ const newTop = keys.at(-1) ?? '';
250
+ // Mid-transition (e.g. a back button pressed again): on from where it
251
+ // is, the page on top still leaving (popped further: the new top under
252
+ // it, those between gone) or coming back (pushed again).
253
+ const running = stack.transition;
254
+ if (isPrefix(keys, previous.keys)) {
255
+ if (running?.top === oldTop) {
256
+ // Its push reversed (or its swipe popped), from where it is.
257
+ stack.setTransition({
258
+ departing: running.departing,
259
+ from: running.from,
260
+ leaving: previous.pages.at(-1),
261
+ top: oldTop,
262
+ under: newTop,
263
+ });
264
+ stack.animate(stack.progress(), 1, stack.rest);
265
+ return;
266
+ }
267
+ if (running && !keys.includes(running.top)) {
268
+ // Popped further while popping: the page on top leaving on its own
269
+ // (on from where it is, see `Departing`), the one it revealed
270
+ // leaving too, from where it was revealed to, the new top under
271
+ // it (a cascade, each press its own).
272
+ const progress = stack.progress();
273
+ const width = element?.clientWidth ?? 0;
274
+ const direction = element && getComputedStyle(element).direction === 'rtl' ? -1 : 1;
275
+ const leavingPage = running.leaving ??
276
+ previous.pages.find((page) => String(page.key) === running.top);
277
+ stack.setTransition({
278
+ departing: [
279
+ ...(running.departing ?? []),
280
+ ...(leavingPage
281
+ ? [{ key: running.top, page: leavingPage, progress }]
282
+ : []),
283
+ ],
284
+ from: (1 - progress) * -0.3 * width * direction,
99
285
  leaving: previous.pages.at(-1),
100
286
  top: oldTop,
101
287
  under: newTop,
102
288
  });
103
- animate(0, 1, rest);
289
+ stack.animate(0, 1, stack.rest);
104
290
  return;
105
291
  }
106
- if (isPrefix(previous.keys, keys)) {
107
- setTransition({ top: newTop, under: oldTop });
108
- animate(1, 0, rest);
292
+ stack.setTransition({
293
+ leaving: previous.pages.at(-1),
294
+ top: oldTop,
295
+ under: newTop,
296
+ });
297
+ stack.animate(0, 1, stack.rest);
298
+ return;
299
+ }
300
+ if (isPrefix(previous.keys, keys)) {
301
+ const isBack = running?.top === newTop;
302
+ stack.setTransition({ top: newTop, under: oldTop });
303
+ stack.animate(isBack ? stack.progress() : 1, 0, stack.rest);
304
+ return;
305
+ }
306
+ stack.rest();
307
+ };
308
+ /**
309
+ * Its stack of pages (keyed children, see above), filling its root: pushed,
310
+ * popped, or replaced as the app's keys change.
311
+ */
312
+ const Stack = forwardRef(({ className, children, ...props }, forwardedRef) => {
313
+ const ref = useForwardedRef(forwardedRef);
314
+ const { stack } = useContext(NavigationContext);
315
+ const pages = Children.toArray(children).filter((child) => isValidElement(child));
316
+ const keys = pages.map((page) => String(page.key));
317
+ const previousRef = useRef({ keys, pages });
318
+ const transition = stack?.transition ?? null;
319
+ // Pushed, popped, or replaced (see above).
320
+ useLayoutEffect(() => {
321
+ stack?.setKeys(keys);
322
+ const { current: previous } = previousRef;
323
+ previousRef.current = { keys, pages };
324
+ if (!stack || sameKeys(previous.keys, keys))
325
+ return;
326
+ const oldTop = previous.keys.at(-1);
327
+ const newTop = keys.at(-1);
328
+ if (oldTop === undefined || newTop === undefined || oldTop === newTop) {
329
+ stack.rest();
109
330
  return;
110
331
  }
111
- rest();
332
+ changeKeys(stack, previous, keys, ref.current);
112
333
  // (On a change of the stack's keys only, compared above.)
113
334
  // eslint-disable-next-line react-hooks/exhaustive-deps
114
335
  }, [keys.join('\n')]);
115
- useLayoutEffect(() => () => clearTimeout(timerRef.current), []);
336
+ const departing = transition?.departing ?? [];
337
+ // Pages still leaving on their own (see above): each on from its
338
+ // progress as it was handed over, to gone (its own progress, over the
339
+ // root's).
340
+ const departedRef = useRef(new Set());
341
+ useLayoutEffect(() => {
342
+ const { current: element } = ref;
343
+ const { current: departed } = departedRef;
344
+ if (!transition)
345
+ departed.clear();
346
+ if (!element)
347
+ return;
348
+ for (const { key, progress } of departing) {
349
+ if (departed.has(key))
350
+ continue;
351
+ const frame = element.querySelector(`:scope > [data-navigation-key="${CSS.escape(key)}"]`);
352
+ if (!frame)
353
+ continue;
354
+ departed.add(key);
355
+ frame.animate([
356
+ { '--uikit-navigation-progress': String(progress) },
357
+ { '--uikit-navigation-progress': '1' },
358
+ ], { duration, easing, fill: 'forwards' });
359
+ }
360
+ });
361
+ // In a transition, the persistent items several moving pages have (by
362
+ // their ids, see `Persistent`): shared, staying put (see style.css); the
363
+ // uppermost page's shown, still pressable (e.g. its back button pressed
364
+ // again: further back, see above), its page not inert.
365
+ const [pressable, setPressable] = useState(undefined);
366
+ useLayoutEffect(() => {
367
+ const { current: element } = ref;
368
+ if (!element || !transition) {
369
+ setPressable(undefined);
370
+ return undefined;
371
+ }
372
+ // The moving pages, uppermost first: those leaving on their own (the
373
+ // earliest above), the top, the one under it.
374
+ const frames = [
375
+ ...(transition.departing ?? []).map(({ key }) => key),
376
+ transition.top,
377
+ transition.under,
378
+ ]
379
+ .map((key) => element.querySelector(`:scope > [data-navigation-key="${CSS.escape(key)}"]`))
380
+ .filter((frame) => frame !== null);
381
+ const itemsOf = (frame) => [
382
+ ...frame.querySelectorAll('[data-navigation-persistent]'),
383
+ ];
384
+ const counts = new Map();
385
+ for (const frame of frames) {
386
+ for (const id of new Set(itemsOf(frame).map((item) => item.dataset.navigationPersistent))) {
387
+ counts.set(id, (counts.get(id) ?? 0) + 1);
388
+ }
389
+ }
390
+ const shown = new Set();
391
+ const marked = [];
392
+ let uppermost;
393
+ for (const frame of frames) {
394
+ for (const item of itemsOf(frame)) {
395
+ const id = item.dataset.navigationPersistent;
396
+ if ((counts.get(id) ?? 0) < 2)
397
+ continue;
398
+ item.dataset.navigationShared = '';
399
+ if (shown.has(id)) {
400
+ item.dataset.navigationSharedHidden = '';
401
+ }
402
+ else {
403
+ shown.add(id);
404
+ uppermost ??= frame.dataset.navigationKey;
405
+ }
406
+ marked.push(item);
407
+ }
408
+ }
409
+ setPressable(uppermost);
410
+ return () => {
411
+ for (const item of marked) {
412
+ delete item.dataset.navigationShared;
413
+ delete item.dataset.navigationSharedHidden;
414
+ }
415
+ };
416
+ }, [ref, transition]);
116
417
  const roleOf = (key, index, count) => {
117
418
  if (transition) {
118
- if (key === transition.top)
419
+ const isLeaving = departing.some((entry) => entry.key === key);
420
+ if (isLeaving || key === transition.top)
119
421
  return 'top';
120
422
  if (key === transition.under)
121
423
  return 'under';
@@ -126,76 +428,92 @@ const Root = forwardRef(({ className, children, onBack, ...props }, forwardedRef
126
428
  const leaving = transition?.leaving && !keys.includes(transition.top)
127
429
  ? [transition.leaving]
128
430
  : [];
129
- const shown = [...pages, ...leaving];
130
- const canSwipe = Boolean(onBack) && keys.length > 1 && !transition;
131
- const endSwipe = (event) => {
132
- const { current: swipe } = swipeRef;
133
- if (swipe?.pointerId !== event.pointerId)
134
- return;
135
- swipeRef.current = undefined;
136
- // Its speed as released: over the last moves (held still: none).
137
- const now = performance.now();
138
- const recent = swipe.moves.find(([time]) => now - time < flingWindow);
139
- const first = recent;
140
- const velocity = first
141
- ? ((swipe.progress - first[1]) * swipe.width) /
142
- Math.max(now - first[0], 1)
143
- : 0;
144
- const top = keys.at(-1);
145
- if (event.type !== 'pointercancel' &&
146
- (swipe.progress > 0.5 || velocity > flingVelocity)) {
147
- animate(swipe.progress, 1, () => {
148
- swipedRef.current = top;
149
- onBack?.();
150
- // Not popped by the app after all: back.
151
- timerRef.current = setTimeout(() => {
152
- if (swipedRef.current !== top)
153
- return;
154
- swipedRef.current = undefined;
155
- animate(1, 0, rest);
156
- }, 1000);
157
- });
158
- return;
159
- }
160
- animate(swipe.progress, 0, rest);
161
- };
162
- return (_jsxs("div", { ref: ref, "data-navigation-moving": transition ? '' : undefined, "data-navigation-part": "root", ...props, className: cn('uikit-navigation-root', className), children: [shown.map((page, index) => {
163
- const key = String(page.key);
164
- const role = roleOf(key, index, shown.length);
165
- return (_jsx("div", { "aria-hidden": role === 'current' ? undefined : true, className: "uikit-navigation-frame", "data-navigation-part": "page", "data-navigation-role": role, inert: role !== 'current', children: page }, key));
166
- }), canSwipe || swipeRef.current ? (_jsx("div", { className: "uikit-navigation-edge", "data-navigation-part": "edge", onLostPointerCapture: endSwipe, onPointerCancel: endSwipe, onPointerUp: endSwipe, onPointerDown: (event) => {
167
- const { current: root } = ref;
168
- const top = keys.at(-1);
169
- const under = keys.at(-2);
170
- if (!root || !top || !under || event.button !== 0)
171
- return;
172
- event.preventDefault();
173
- event.currentTarget.setPointerCapture(event.pointerId);
174
- swipeRef.current = {
175
- pointerId: event.pointerId,
176
- moves: [[performance.now(), 0]],
177
- progress: 0,
178
- width: root.clientWidth,
179
- x: event.clientX,
180
- };
181
- setProgress(0, false);
182
- setTransition({ top, under });
183
- }, onPointerMove: (event) => {
184
- const { current: swipe } = swipeRef;
185
- const { current: root } = ref;
186
- if (swipe?.pointerId !== event.pointerId || !root)
187
- return;
188
- const direction = getComputedStyle(root).direction === 'rtl' ? -1 : 1;
189
- const moved = (event.clientX - swipe.x) * direction;
190
- swipe.progress = Math.min(Math.max(moved / swipe.width, 0), 1);
191
- swipe.moves = [
192
- ...swipe.moves.slice(-8),
193
- [performance.now(), swipe.progress],
194
- ];
195
- setProgress(swipe.progress, false);
196
- } })) : null] }));
431
+ const shown = [
432
+ ...pages,
433
+ ...leaving,
434
+ ...departing
435
+ .filter(({ key }) => !keys.includes(key) && key !== transition?.top)
436
+ .map(({ page }) => page),
437
+ ];
438
+ return (_jsx("div", { ref: ref, "data-navigation-part": "stack", ...props, className: cn('uikit-navigation-stack', className), children: shown.map((page, index) => {
439
+ const key = String(page.key);
440
+ const role = roleOf(key, index, shown.length);
441
+ const isInert = role !== 'current' && key !== pressable;
442
+ const departingIndex = departing.findIndex((entry) => entry.key === key);
443
+ return (_jsx("div", { "aria-hidden": isInert ? true : undefined, className: "uikit-navigation-frame", "data-navigation-departing": departingIndex === -1 ? undefined : '', "data-navigation-key": key, "data-navigation-part": "page", "data-navigation-role": role, inert: isInert, style: {
444
+ // Leaving on their own: above the top page, the earliest
445
+ // uppermost; the top page from where it was (see `from`).
446
+ zIndex: departingIndex === -1
447
+ ? undefined
448
+ : 2 + departing.length - departingIndex,
449
+ '--uikit-navigation-from': key === transition?.top && transition.from !== undefined
450
+ ? `${String(transition.from)}px`
451
+ : undefined,
452
+ }, children: page }, key));
453
+ }) }));
197
454
  });
455
+ /**
456
+ * Where a swipe back starts (touch, or a mouse): a strip at the leading
457
+ * edge (`width`, 20px), over the pages, while there's a page to go back to
458
+ * (and an `onBack`); in its `Root`. Without one, pages aren't swiped back.
459
+ * Its swipes are its own: nothing scrolls meanwhile (`touch-action`), and
460
+ * a sheet around it isn't swiped along (Base UI's swipe ignore).
461
+ */
462
+ const SwipeArea = forwardRef(({ className, style, width = 20, ...props }, ref) => {
463
+ const { swipe } = useContext(NavigationContext);
464
+ if (!swipe)
465
+ return null;
466
+ return (_jsx("div", { ref: ref, "data-base-ui-swipe-ignore": "", "data-navigation-part": "swipe-area", style: withStyle({ '--uikit-navigation-swipe-area-width': `${String(width)}px` }, style), ...props, ...swipe, className: cn('uikit-navigation-swipe-area', className) }));
467
+ });
468
+ /**
469
+ * A button taking its navigation back (its `onBack`, the app popping its
470
+ * stack), e.g. a bar's back button (`render`: a `Toolbar.Button`); on the
471
+ * root page (nothing to go back to), disabled.
472
+ */
473
+ const Back = forwardRef(({ disabled, onClick, persistentId = 'back', render, ...props }, ref) => {
474
+ const { back } = useContext(NavigationContext);
475
+ return useRender({
476
+ defaultTagName: 'button',
477
+ props: {
478
+ 'data-navigation-part': 'back',
479
+ 'data-navigation-persistent': persistentId || undefined,
480
+ disabled: disabled ?? !back,
481
+ type: 'button',
482
+ ...props,
483
+ onClick: (event) => {
484
+ onClick?.(event);
485
+ if (event.defaultPrevented)
486
+ return;
487
+ back?.({ event, reason: 'back-press' });
488
+ },
489
+ },
490
+ ref,
491
+ render,
492
+ });
493
+ });
494
+ /**
495
+ * An item of a page's bar (e.g. a toolbar button, `render`) that stays put
496
+ * through a transition while both pages moving have one of its id
497
+ * (`persistentId`), the upper page's shown; otherwise moving with its page.
498
+ * E.g. a back button (`Back` is one, by default): sliding in with the first
499
+ * page to have one, staying put on to deeper pages and back, sliding out
500
+ * with the first again.
501
+ */
502
+ const Persistent = forwardRef(({ persistentId, render, ...props }, ref) => useRender({
503
+ defaultTagName: 'div',
504
+ props: {
505
+ 'data-navigation-part': 'persistent',
506
+ 'data-navigation-persistent': persistentId,
507
+ ...props,
508
+ },
509
+ ref,
510
+ render,
511
+ }));
198
512
  export const Navigation = {
199
513
  Root,
514
+ Stack,
515
+ SwipeArea,
516
+ Back,
517
+ Persistent,
200
518
  };
201
519
  //# sourceMappingURL=main.js.map