@astryx-vue/core 0.30.0 → 0.30.1

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 (239) hide show
  1. package/dist/AlertDialog/index.js +1 -1
  2. package/dist/{AlertDialog-D_lrpZz_.js → AlertDialog-B_p1yL3k.js} +7 -7
  3. package/dist/AppShell/index.js +1 -1
  4. package/dist/{AppShell-CxUmt6hX.js → AppShell-D3KZSLvb.js} +5 -5
  5. package/dist/AvatarGroup/index.d.ts +1 -1
  6. package/dist/AvatarGroup/index.js +1 -1
  7. package/dist/{AvatarGroup-DT5RbxDa.js → AvatarGroup-Dd-yDDNz.js} +2 -2
  8. package/dist/Banner/index.d.ts +1 -1
  9. package/dist/Banner/index.js +1 -1
  10. package/dist/{Banner-Ctg1puM6.js → Banner-DKmvoMxD.js} +1 -1
  11. package/dist/BottomSheet/index.d.ts +1 -1
  12. package/dist/BottomSheet/index.js +2 -2
  13. package/dist/{BottomSheet-CmNOXlZO.js → BottomSheet-Btf8Yn8k.js} +845 -276
  14. package/dist/{BottomSheet-_K41Oliv.js → BottomSheet-CQGtoh2x.js} +1 -1
  15. package/dist/Breadcrumbs/index.js +2 -2
  16. package/dist/{Breadcrumbs-CdGqhFKU.js → Breadcrumbs-D6825HQI.js} +1 -1
  17. package/dist/Button/index.js +1 -1
  18. package/dist/{Button-CvHeZGf1.js → Button-DdPty46q.js} +2 -2
  19. package/dist/ButtonGroup/index.d.ts +1 -1
  20. package/dist/ButtonGroup/index.js +1 -1
  21. package/dist/{ButtonGroup-CUN_rC57.js → ButtonGroup-oI99JAyN.js} +3 -3
  22. package/dist/Calendar/index.d.ts +1 -1
  23. package/dist/Carousel/index.d.ts +1 -1
  24. package/dist/Carousel/index.js +1 -1
  25. package/dist/{Carousel-CbdHb8MD.js → Carousel-BNr79JpP.js} +1 -1
  26. package/dist/Chat/index.d.ts +1 -1
  27. package/dist/Chat/index.js +1 -1
  28. package/dist/{Chat-B7ccEmTR.js → Chat-BadS0fEx.js} +2 -2
  29. package/dist/CheckboxInput/index.d.ts +1 -1
  30. package/dist/CheckboxInput/index.js +1 -1
  31. package/dist/{CheckboxInput-5r6VWqId.js → CheckboxInput-CzP8gP3v.js} +3 -3
  32. package/dist/CheckboxList/index.d.ts +1 -1
  33. package/dist/CheckboxList/index.js +1 -1
  34. package/dist/{CheckboxListItem-CKeQzQ0W.js → CheckboxListItem-CxBjpX3d.js} +4 -4
  35. package/dist/ClickableCard/index.d.ts +1 -1
  36. package/dist/ClickableCard/index.js +1 -1
  37. package/dist/{ClickableCard-ChmOwgYq.js → ClickableCard-B86P2aiM.js} +1 -1
  38. package/dist/Code/index.js +1 -1
  39. package/dist/{CodeBlock-4i1vvmOc.js → CodeBlock-Cgm4uOhG.js} +1 -1
  40. package/dist/Collapsible/index.js +1 -1
  41. package/dist/{Collapsible-B2vrr_YP.js → Collapsible-CfTN722D.js} +3 -3
  42. package/dist/CommandPalette/index.d.ts +1 -1
  43. package/dist/CommandPalette/index.js +1 -1
  44. package/dist/{CommandPalette-BMwvTjff.js → CommandPalette-BgVwGtdA.js} +2 -2
  45. package/dist/ComplexSelector/index.js +1 -1
  46. package/dist/{ComplexSelector-B4iFyilD.js → ComplexSelector-DqWJVx7H.js} +2 -2
  47. package/dist/ContextMenu/index.d.ts +1 -1
  48. package/dist/ContextMenu/index.js +2 -2
  49. package/dist/{ContextMenu-DquYeIEF.js → ContextMenu-C9dJGu3M.js} +3 -3
  50. package/dist/DateInput/index.d.ts +1 -1
  51. package/dist/DateInput/index.js +1 -1
  52. package/dist/{DateInput-MNNyi4XK.js → DateInput-CGKaozkw.js} +3 -3
  53. package/dist/DateRangeInput/index.d.ts +1 -1
  54. package/dist/DateRangeInput/index.js +1 -1
  55. package/dist/{DateRangeInput-DOHntScL.js → DateRangeInput-BVHXgzXz.js} +3 -3
  56. package/dist/DateTimeInput/index.d.ts +1 -1
  57. package/dist/DateTimeInput/index.js +1 -1
  58. package/dist/{DateTimeInput-BaghFHW6.js → DateTimeInput-DRm3lekJ.js} +5 -5
  59. package/dist/Dialog/index.js +3 -3
  60. package/dist/{Dialog-Ctha_b_L.js → Dialog-BN-NycQr.js} +1 -1
  61. package/dist/{Dialog-CGf64DqF.js → Dialog-Dt0gNuMT.js} +1 -1
  62. package/dist/{DialogHeader-BxTV37GT.js → DialogHeader-CSH2_5v-.js} +2 -2
  63. package/dist/Drawer/index.d.ts +1 -1
  64. package/dist/Drawer/index.js +1 -1
  65. package/dist/{Drawer-DAnc2ut9.js → Drawer-PeMgE4iA.js} +2 -2
  66. package/dist/DropdownMenu/index.js +3 -3
  67. package/dist/{DropdownMenu-BPi0pm0w.js → DropdownMenu-C9bvYZPt.js} +5 -5
  68. package/dist/{DropdownMenu-DuSVFQoS.js → DropdownMenu-_lQQyQCn.js} +6 -6
  69. package/dist/Field/index.js +3 -3
  70. package/dist/{Field-d5R_kRMv.js → Field-D-fRqyso.js} +1 -1
  71. package/dist/{FieldInfoTip-BhKtjq3g.js → FieldInfoTip-Bstp5Lvd.js} +1 -1
  72. package/dist/{FieldLabel-BHNpYFx7.js → FieldLabel-lV_qLaGp.js} +1 -1
  73. package/dist/FileInput/index.js +1 -1
  74. package/dist/{FileInput-BCg4HROm.js → FileInput-CTNnDIkm.js} +3 -3
  75. package/dist/IconButton/index.js +1 -1
  76. package/dist/{IconButton-BZgU_THt.js → IconButton-DPezhVBA.js} +1 -1
  77. package/dist/InfoTip/index.d.ts +1 -1
  78. package/dist/InfoTip/index.js +1 -1
  79. package/dist/{InfoTip-E2-OzKti.js → InfoTip-B4BFfLtT.js} +1 -1
  80. package/dist/{InputClearButton-B62_uexC.js → InputClearButton-CxU3iv-5.js} +1 -1
  81. package/dist/InputGroup/index.js +1 -1
  82. package/dist/{InputGroup-DKBqRYFf.js → InputGroup-CraWGK6Y.js} +1 -1
  83. package/dist/{Item-C8UAQwFQ.js → Item-C9u_kQUO.js} +15 -14
  84. package/dist/Lightbox/index.js +1 -1
  85. package/dist/{Lightbox-Bou1gTfv.js → Lightbox-BNUG9CQ1.js} +1 -1
  86. package/dist/Link/index.d.ts +1 -1
  87. package/dist/Link/index.js +1 -1
  88. package/dist/{Link-CaJ5lmKk.js → Link-Bwgpn-di.js} +1 -1
  89. package/dist/List/index.js +2 -2
  90. package/dist/{ListItem-BlrEngDO.js → ListItem-_lOmngHp.js} +2 -2
  91. package/dist/Markdown/index.js +1 -1
  92. package/dist/{Markdown-BE6vdvPG.js → Markdown-BlEi5UGN.js} +2 -2
  93. package/dist/MobileNav/index.js +1 -1
  94. package/dist/{MobileNavToggle-D5yGMHU4.js → MobileNavToggle-wVa9dzH1.js} +1 -1
  95. package/dist/MoreMenu/index.d.ts +1 -1
  96. package/dist/MoreMenu/index.js +1 -1
  97. package/dist/{MoreMenu-CNzTagqr.js → MoreMenu-MmvMRWv5.js} +3 -3
  98. package/dist/MultiSelector/index.d.ts +1 -1
  99. package/dist/MultiSelector/index.js +1 -1
  100. package/dist/{MultiSelector-MGEiRi1W.js → MultiSelector-DXrKQLmq.js} +4 -4
  101. package/dist/NavItem/index.js +1 -1
  102. package/dist/{NavItem-kj9FbbFS.js → NavItem-D4xHjSTo.js} +1 -1
  103. package/dist/NavMenu/index.js +2 -2
  104. package/dist/{NavMenu-ZN5cqCxO.js → NavMenu-NCg3VjAQ.js} +2 -2
  105. package/dist/{NavMenuItem-xm3e0V8q.js → NavMenuItem-Bla6fYVl.js} +3 -3
  106. package/dist/NumberInput/index.d.ts +1 -1
  107. package/dist/NumberInput/index.js +1 -1
  108. package/dist/{NumberInput-D4ECOHh_.js → NumberInput-DicgvFte.js} +3 -3
  109. package/dist/Outline/index.js +1 -1
  110. package/dist/{Outline-DI9MZnuQ.js → Outline-DlO_97b4.js} +3 -3
  111. package/dist/OverflowList/index.d.ts +1 -1
  112. package/dist/OverflowList/index.js +1 -1
  113. package/dist/{OverflowList-m1tf_fR1.js → OverflowList-BYYz3ePw.js} +1 -1
  114. package/dist/Overlay/index.d.ts +1 -1
  115. package/dist/Pagination/index.js +1 -1
  116. package/dist/{Pagination-BdjxuxM3.js → Pagination-DM_W9Ue-.js} +3 -3
  117. package/dist/Popover/index.js +1 -1
  118. package/dist/{Popover-DEj8xWN-.js → Popover-CxReY-4u.js} +5 -5
  119. package/dist/PowerSearch/index.d.ts +1 -1
  120. package/dist/PowerSearch/index.js +1 -1
  121. package/dist/{PowerSearch-BJDFietK.js → PowerSearch-BwUWZG3p.js} +19 -19
  122. package/dist/Radio/index.d.ts +1 -1
  123. package/dist/Radio/index.js +1 -1
  124. package/dist/{RadioGroup-B3UoJrOA.js → RadioGroup-CsJYGjyx.js} +3 -3
  125. package/dist/RadioList/index.d.ts +1 -1
  126. package/dist/RadioList/index.js +1 -1
  127. package/dist/{RadioListItem-CD7kUGlN.js → RadioListItem-Yc3K82YE.js} +1 -1
  128. package/dist/ScrollableArea/index.d.ts +1 -1
  129. package/dist/SegmentedControl/index.js +1 -1
  130. package/dist/{SegmentedControl-DGd6JlaD.js → SegmentedControl-C-F5dkcG.js} +2 -2
  131. package/dist/SelectableCard/index.d.ts +1 -1
  132. package/dist/SelectableCard/index.js +1 -1
  133. package/dist/{SelectableCard-GRWYx3iD.js → SelectableCard-CwfpgsS8.js} +1 -1
  134. package/dist/Selector/index.d.ts +1 -1
  135. package/dist/Selector/index.js +1 -1
  136. package/dist/{Selector-BD0u-5Fy.js → Selector-bH99g1vj.js} +2 -2
  137. package/dist/SideNav/index.d.ts +1 -1
  138. package/dist/SideNav/index.js +2 -2
  139. package/dist/{SideNav-DoqCLRiX.js → SideNav-C1ZxusAB.js} +6 -6
  140. package/dist/Slider/index.js +1 -1
  141. package/dist/{Slider-DHR7HZ7N.js → Slider-Bq_7Nskr.js} +2 -2
  142. package/dist/Stepper/index.d.ts +1 -1
  143. package/dist/Stepper/index.js +1 -1
  144. package/dist/{Stepper-CCuggsov.js → Stepper-CWluGqBs.js} +1 -1
  145. package/dist/Switch/index.d.ts +1 -1
  146. package/dist/Switch/index.js +1 -1
  147. package/dist/{Switch-CnFC7jGw.js → Switch-DTPvMAxd.js} +2 -2
  148. package/dist/TabList/index.js +1 -1
  149. package/dist/{TabList-fMlX8m6n.js → TabList-C4i7UZkp.js} +3 -3
  150. package/dist/Table/index.d.ts +1 -1
  151. package/dist/Table/index.js +1 -1
  152. package/dist/{Table-DoKmVdhZ.js → Table-ClHIgsKO.js} +13 -13
  153. package/dist/TextArea/index.d.ts +1 -1
  154. package/dist/TextArea/index.js +1 -1
  155. package/dist/{TextArea-y9mmYAIy.js → TextArea-J2_wct0p.js} +4 -4
  156. package/dist/TextInput/index.d.ts +1 -1
  157. package/dist/TextInput/index.js +1 -1
  158. package/dist/{TextInput-BLGEh7vE.js → TextInput-Da1TYd57.js} +4 -4
  159. package/dist/Thumbnail/index.js +1 -1
  160. package/dist/{Thumbnail-Dm8krgGF.js → Thumbnail-1LsaJ4_m.js} +2 -2
  161. package/dist/{TimeField-DS30hnty.js → TimeField-i5ESA500.js} +2 -2
  162. package/dist/TimeInput/index.d.ts +1 -1
  163. package/dist/TimeInput/index.js +1 -1
  164. package/dist/{TimeInput-DcY4b3dg.js → TimeInput-frnKZo1M.js} +2 -2
  165. package/dist/Timestamp/index.d.ts +1 -1
  166. package/dist/Timestamp/index.js +1 -1
  167. package/dist/{Timestamp-BhBuBHu8.js → Timestamp-SseS_qtf.js} +1 -1
  168. package/dist/Toast/index.js +1 -1
  169. package/dist/{Toast-CnLk7LzS.js → Toast-tAq4S96S.js} +149 -20
  170. package/dist/ToggleButton/index.d.ts +1 -1
  171. package/dist/ToggleButton/index.js +1 -1
  172. package/dist/{ToggleButton-B9IJcpdJ.js → ToggleButton-B6hBzeVl.js} +3 -3
  173. package/dist/Token/index.d.ts +1 -1
  174. package/dist/Token/index.js +1 -1
  175. package/dist/{Token-C7Dt5ygK.js → Token-DTGUCgpn.js} +1 -1
  176. package/dist/Tokenizer/index.d.ts +1 -1
  177. package/dist/Tokenizer/index.js +1 -1
  178. package/dist/{Tokenizer-D7ZCTbnf.js → Tokenizer-iFZAuIwu.js} +7 -7
  179. package/dist/Toolbar/index.d.ts +1 -1
  180. package/dist/Toolbar/index.js +1 -1
  181. package/dist/{Toolbar-DSWH8ll4.js → Toolbar-BHkPxDxA.js} +1 -1
  182. package/dist/TopNav/index.d.ts +1 -1
  183. package/dist/TopNav/index.js +1 -1
  184. package/dist/{TopNav-CK_F6Ud5.js → TopNav-CcIayfsW.js} +4 -4
  185. package/dist/TreeList/index.js +1 -1
  186. package/dist/{TreeList-Dh0uAj2B.js → TreeList-Da_OKrv_.js} +4 -4
  187. package/dist/Typeahead/index.js +1 -1
  188. package/dist/{Typeahead-Cs-46obm.js → Typeahead-BD6xXNKh.js} +3 -3
  189. package/dist/VelocityTracker-DgjmootV.js +165 -0
  190. package/dist/{animator-BGq5a6vT.js → animator-CEHDYTfQ.js} +29 -173
  191. package/dist/{batch-BhaAWUIt.js → batch-D2a2MsSW.js} +4 -19
  192. package/dist/bezier-Dko5MnTp.js +37 -0
  193. package/dist/{clickGuard-FrlnECMp.js → clickGuard-C3VmOLhI.js} +2 -1
  194. package/dist/composables/index.js +7 -7
  195. package/dist/composables-Bs0O_SRd.js +2548 -0
  196. package/dist/{context-jtpQfR6F.js → context-NKb_prrS.js} +2 -2
  197. package/dist/{edge-CJIswPTX.js → edge-tj-cLZYh.js} +1 -1
  198. package/dist/{edgeRide-Drk4V-MC.js → edgeRide-DcUqLXE2.js} +4 -4
  199. package/dist/{handle-BazRxHwq.js → handle-CwxCHapJ.js} +1 -1
  200. package/dist/{holdEntranceInput-DMCOeRqu.js → holdEntranceInput-DgimbgGm.js} +1 -1
  201. package/dist/{index-BVeTS-R5.d.ts → index-3qz8Qztx.d.ts} +4 -4
  202. package/dist/{index-Q1oG9yIT.d.ts → index-B-3EGjfQ.d.ts} +2 -2
  203. package/dist/{index-C1e8LNx2.d.ts → index-BjqoHLMq.d.ts} +1 -1
  204. package/dist/{index-DQ3akoRZ.d.ts → index-Bu4R0WZA.d.ts} +3 -3
  205. package/dist/{index-BDZCJ9ri.d.ts → index-BuubzuE8.d.ts} +2 -2
  206. package/dist/{index-BL9fE6gs.d.ts → index-Cw4CUe06.d.ts} +5 -5
  207. package/dist/{index-CUuUoX3h.d.ts → index-JE1HrzdJ.d.ts} +3 -3
  208. package/dist/{index-hUa5oQ5O.d.ts → index-m3DOxOw6.d.ts} +42 -42
  209. package/dist/index.d.ts +9 -9
  210. package/dist/index.js +85 -85
  211. package/dist/{inputHold-BmChuR9x.js → inputHold-DW2LYHb5.js} +4 -4
  212. package/dist/{inputHoldState-pblUT4oh.js → inputHoldState-xntIqr5W.js} +2 -1
  213. package/dist/{inputStream-LZdK8luP.js → inputStream-bPd9eB2b.js} +2 -49
  214. package/dist/isRtlElement-NHuH48AA.js +23 -0
  215. package/dist/{landing-CBaXCGEg.js → landing-Bi7X7w_7.js} +3 -3
  216. package/dist/{lazyBottomSheet-Cmd-WMEE.js → lazyBottomSheet-BVZ1yH8g.js} +1 -1
  217. package/dist/{timing-CSHWQbTJ.js → linearEasing-ScK9LqAY.js} +30 -1
  218. package/dist/{bezier-Df-yGuNZ.js → presentation-Cy_yf56y.js} +2 -39
  219. package/dist/{pressFeedback-DVR5V1b6.js → pressFeedback-9dqGYjxv.js} +2 -2
  220. package/dist/{resolveMotion-CurhYTVC.js → resolveMotion-1cwESYvK.js} +202 -1
  221. package/dist/resolveSnapPoint-DdZyBkT4.js +717 -0
  222. package/dist/{flatTree-BB4yPMNL.js → sharedRealm-H1OrlP0V.js} +49 -1
  223. package/dist/{themeTiming-BFDOPRjK.js → themeTiming-NUkH9HsU.js} +1 -1
  224. package/dist/{touchHold-CFJlSClt.js → touchHold-DXtx7npm.js} +1 -1
  225. package/dist/{useActionGroupTracking-C6BzQzvp.js → useActionGroupTracking-CLFF7FI2.js} +2 -2
  226. package/dist/{useAnimatedLayout-DC2l3WrE.js → useAnimatedLayout-DWWc31RR.js} +1 -1
  227. package/dist/{composables-BTRbNgmR.js → useAttachment-BuNyeUXy.js} +44 -3464
  228. package/dist/{useChatStreamScroll-Cv51kRT0.js → useChatStreamScroll-CuMzkXgD.js} +1 -1
  229. package/dist/{useInputStatusIcon-BngSzjVd.js → useInputStatusIcon-BqV6YzTV.js} +1 -1
  230. package/dist/{useListFocus-CkHfsZp0.js → useListFocus-Ccd_HU9T.js} +2 -23
  231. package/dist/{useMenuDrillIn-BQx6lQMz.js → useMenuDrillIn-Cj6MM77J.js} +1 -1
  232. package/dist/{useMenuEntranceHold-buV5S9yk.js → useMenuEntranceHold-HznOwIry.js} +1 -1
  233. package/dist/{useMenuHover-CfQtWMg-.js → useMenuHover-DoBatZeD.js} +1 -1
  234. package/dist/{useMenuPress-DU6pAIHy.js → useMenuPress-DcwVUsQO.js} +3 -3
  235. package/dist/{usePressFeedback-BhNcuxQv.js → usePressFeedback-DHdmAsMp.js} +1 -1
  236. package/dist/{useTouchHitArea-CNZyA18Y.js → useTouchHitArea-SY1ITxSJ.js} +2 -2
  237. package/package.json +1 -1
  238. package/styles/bottom-sheet.css +28 -8
  239. package/dist/{index-D8lv2BiD.d.ts → index-BqhgeAT4.d.ts} +1 -1
@@ -0,0 +1,2548 @@
1
+ import { O as solveSpring, k as toSpring, t as resolveMotion, u as motionNow } from "./resolveMotion-1cwESYvK.js";
2
+ import { f as registerScrollTable, p as scroll, s as UIKIT_LONG_PRESS, u as UIKIT_TAP, v as registerMotionTable } from "./pressGesture-BzIBmKF2.js";
3
+ import { o as pushLayer } from "./layerDepth-D3Rh8T5C.js";
4
+ import { t as useMediaQuery } from "./useMediaQuery-BzXGT1Aw.js";
5
+ import { n as createMotionEngine, r as SETTLE_THRESHOLD } from "./animator-CEHDYTfQ.js";
6
+ import { t as devWarn } from "./useDevWarning-B2fsk2B-.js";
7
+ import { n as registerSpringsTable, r as springs, t as resolveSnapPoint } from "./resolveSnapPoint-DdZyBkT4.js";
8
+ import { a as lockSelection, c as MANIPULATION, i as getGestureHost, l as isActive, n as PanGestureRecognizer, o as locksSelectionFor, r as travel, s as GestureRecognizer, t as useAttachment } from "./useAttachment-BuNyeUXy.js";
9
+ import { o as useComponentMessages } from "./context-B8IEFCDR.js";
10
+ import { t as _sfc_main$1 } from "./Kbd-CbD993ig.js";
11
+ import { t as keyboardHintMessages } from "./keyboard-hint-KWx0-7kD.js";
12
+ import { n as observeResize } from "./sharedResizeObserver-BekhnB3E.js";
13
+ import { r as makeSnapPaging, s as snapPages } from "./snapPagingValue-B5hfph1H.js";
14
+ import { t as useTouchTriggerInternal } from "./useTouchTriggerInternal-Bl602PtA.js";
15
+ import { Fragment, computed, createBlock, createElementBlock, createElementVNode, defineComponent, getCurrentInstance, getCurrentScope, h, normalizeStyle, onBeforeUnmount, onMounted, onScopeDispose, openBlock, ref, renderList, toDisplayString, toValue, unref, vShow, watch, withDirectives } from "vue";
16
+ import "../styles/indicator-focus-ring.css";
17
+ import "../styles/keyboard-hint.css";
18
+ //#region src/motion/decay.ts
19
+ /**
20
+ * @file decay.ts
21
+ * @input A release value, velocity and a UIScrollView deceleration rate
22
+ * @output Exports `solveDecay`, the closed-form momentum coast of a scroll
23
+ * view after the finger lifts (value, velocity, rest point, settle time,
24
+ * time to reach a value), and `decayRestDistance`
25
+ * @position Pure math under the motion animator; no DOM, no React
26
+ *
27
+ * UIScrollView's deceleration rate is a per-millisecond velocity factor: the
28
+ * speed is multiplied by the rate every millisecond (0.998 normal, 0.99 fast;
29
+ * see uikit/scroll.ts). As a continuous decay that is
30
+ * v(t) = v₀·e^(−λt), x(t) = x₀ + v₀·(1 − e^(−λt)) ÷ λ, λ = −1000·ln(rate) /s
31
+ * and the coast ends at x₀ + v₀ ÷ λ. WWDC18 "Designing Fluid Interfaces"
32
+ * projects the same rest point with the geometric series v₀·rate ÷ (1 − rate)
33
+ * per millisecond (projection.ts), 0.1 % shorter at the normal rate (499.0
34
+ * against 499.5 ms of the release speed); the continuous form is the one
35
+ * that also gives the position and velocity at every instant, which the
36
+ * animator needs to grab a coasting surface mid-flight.
37
+ *
38
+ * Units: time in seconds, velocity in units per second.
39
+ */
40
+ function decayConstant(rate) {
41
+ if (!(rate > 0 && rate < 1)) throw new RangeError(`decay: rate must be in (0, 1), got ${rate}`);
42
+ return -1e3 * Math.log(rate);
43
+ }
44
+ /**
45
+ * The momentum coast UIScrollView performs after the finger lifts.
46
+ *
47
+ * @example
48
+ * ```
49
+ * const coast = solveDecay({from: 0, velocity: 2000});
50
+ * coast.rest; // ≈ 999 px
51
+ * coast.value(0.2); // px after 200 ms
52
+ * ```
53
+ */
54
+ function solveDecay({ from, velocity: initialVelocity, rate = scroll.decelerationRate.normal }) {
55
+ const lambda = decayConstant(rate);
56
+ const rest = from + initialVelocity / lambda;
57
+ const speed0 = Math.abs(initialVelocity);
58
+ return {
59
+ from,
60
+ initialVelocity,
61
+ rate,
62
+ rest,
63
+ value: (t) => from + initialVelocity * -Math.expm1(-lambda * t) / lambda,
64
+ velocity: (t) => initialVelocity * Math.exp(-lambda * t),
65
+ settleTime: (threshold) => {
66
+ const remaining = speed0 / lambda;
67
+ if (!(threshold > 0)) return Infinity;
68
+ return remaining <= threshold ? 0 : Math.log(remaining / threshold) / lambda;
69
+ },
70
+ timeToSpeed: (speed) => speed0 <= speed ? 0 : speed > 0 ? Math.log(speed0 / speed) / lambda : Infinity,
71
+ timeToReach: (target) => {
72
+ if (initialVelocity === 0) return target === from ? 0 : null;
73
+ const fraction = lambda * (target - from) / initialVelocity;
74
+ if (fraction < 0 || fraction >= 1) return null;
75
+ return -Math.log1p(-fraction) / lambda;
76
+ }
77
+ };
78
+ }
79
+ //#endregion
80
+ //#region src/motion/coast.ts
81
+ /** A curve that holds `end` from `duration` on. */
82
+ function settling(duration, end, at, velocity) {
83
+ return {
84
+ duration,
85
+ at: (t) => t >= duration ? end : at(t),
86
+ velocity: (t) => t >= duration ? 0 : velocity(t)
87
+ };
88
+ }
89
+ /**
90
+ * The momentum curves of a release with `velocity` (px per second on each
91
+ * translate axis), for `animator.decay`, which moves only `x` and `y`:
92
+ * momentum continues a finger's throw (design:reduced-motion DR2).
93
+ *
94
+ * @example
95
+ * ```
96
+ * animator.decay(
97
+ * coast(animator, {x: velocityX}, {bounds: {x: {min: -maxScroll, max: 0}}}),
98
+ * );
99
+ * ```
100
+ */
101
+ function coast(animator, velocity, options = {}) {
102
+ const velocities = {};
103
+ for (const key of ["x", "y"]) {
104
+ const value = velocity[key];
105
+ if (value != null && Number.isFinite(value)) velocities[key] = value;
106
+ }
107
+ const rate = options.rate ?? scroll.decelerationRate.normal;
108
+ registerScrollTable();
109
+ const bounce = toSpring(resolveMotion(animator.element, options.bounce ?? scroll.bounce));
110
+ const curves = {};
111
+ for (const [key, v0] of Object.entries(velocities)) {
112
+ const from = animator.get(key, options.at);
113
+ const bounds = options.bounds?.[key];
114
+ const threshold = SETTLE_THRESHOLD[key];
115
+ if (bounds != null && (from < bounds.min || from > bounds.max)) {
116
+ const edge = from < bounds.min ? bounds.min : bounds.max;
117
+ const back = solveSpring(bounce, {
118
+ from,
119
+ to: edge,
120
+ velocity: v0
121
+ });
122
+ curves[key] = {
123
+ ...settling(back.settleTime(threshold), edge, (t) => back.value(t), (t) => back.velocity(t)),
124
+ isTransition: true
125
+ };
126
+ continue;
127
+ }
128
+ const glide = solveDecay({
129
+ from,
130
+ velocity: v0,
131
+ rate
132
+ });
133
+ const edge = bounds == null ? null : glide.rest < bounds.min ? bounds.min : glide.rest > bounds.max ? bounds.max : null;
134
+ const hit = edge == null ? null : glide.timeToReach(edge);
135
+ if (edge != null && hit != null) {
136
+ const spring = solveSpring(bounce, {
137
+ from: edge,
138
+ to: edge,
139
+ velocity: glide.velocity(hit)
140
+ });
141
+ curves[key] = settling(hit + spring.settleTime(threshold), edge, (t) => t < hit ? glide.value(t) : spring.value(t - hit), (t) => t < hit ? glide.velocity(t) : spring.velocity(t - hit));
142
+ } else if (v0 === 0) curves[key] = settling(0, from, () => from, () => 0);
143
+ else curves[key] = settling(glide.settleTime(threshold * 2), edge ?? glide.rest, (t) => glide.value(t), (t) => glide.velocity(t));
144
+ }
145
+ return curves;
146
+ }
147
+ //#endregion
148
+ //#region src/composables/internal/attachableAnimator.ts
149
+ const CHANNELS = [
150
+ "x",
151
+ "y",
152
+ "scale",
153
+ "rotate",
154
+ "opacity"
155
+ ];
156
+ /** The values of the channels the public API names, and nothing else. */
157
+ function motionValues(values) {
158
+ const out = {};
159
+ if (values == null) return out;
160
+ for (const channel of CHANNELS) {
161
+ const value = values[channel];
162
+ if (typeof value === "number" && Number.isFinite(value)) out[channel] = value;
163
+ }
164
+ return out;
165
+ }
166
+ /**
167
+ * A coast from `from` at `velocity` on the momentum decay a scroll view
168
+ * uses, ending at rest. The theme does not change this decay. An opacity
169
+ * coast stops at 0 or 1.
170
+ */
171
+ function momentum(from, velocity, threshold, isUnit) {
172
+ const glide = solveDecay({
173
+ from,
174
+ velocity
175
+ });
176
+ const edge = !isUnit ? null : glide.rest < 0 ? 0 : glide.rest > 1 ? 1 : null;
177
+ const duration = (edge == null ? null : glide.timeToReach(edge)) ?? glide.settleTime(threshold);
178
+ const end = edge ?? glide.rest;
179
+ return {
180
+ duration,
181
+ at: (t) => t >= duration ? end : glide.value(t),
182
+ velocity: (t) => t >= duration ? 0 : glide.velocity(t)
183
+ };
184
+ }
185
+ function snapshot(read) {
186
+ return {
187
+ x: read("x"),
188
+ y: read("y"),
189
+ scale: read("scale"),
190
+ rotate: read("rotate"),
191
+ opacity: read("opacity")
192
+ };
193
+ }
194
+ /**
195
+ * Resolves once every motion of one call has finished, or as soon as any of
196
+ * them is interrupted (`finished` resolves `false`). A later call that takes
197
+ * over one channel ends the whole call where it stopped, as one `animate`
198
+ * does. The other channels move on.
199
+ */
200
+ async function settledOrTakenOver(moving) {
201
+ if (moving.length === 0) return;
202
+ await new Promise((resolve) => {
203
+ let left = moving.length;
204
+ for (const finished of moving) finished.then((completed) => {
205
+ left -= 1;
206
+ if (!completed || left === 0) resolve();
207
+ });
208
+ });
209
+ }
210
+ /** A new or remounted element starts from these values. */
211
+ const REST = {
212
+ x: 0,
213
+ y: 0,
214
+ scale: 1,
215
+ rotate: 0,
216
+ opacity: 1
217
+ };
218
+ /**
219
+ * An animator whose element is attached later, through `attach`. It is the
220
+ * one construction `createAnimator` and `useAnimator` share, so the
221
+ * composable has no behavior of its own. Not exported from the package.
222
+ */
223
+ function createAttachableAnimator() {
224
+ const motion = createMotionEngine(null);
225
+ let element = null;
226
+ let destroyed = false;
227
+ const inactive = () => destroyed || element == null;
228
+ return {
229
+ animator: {
230
+ async animate(target, options) {
231
+ const to = motionValues(target);
232
+ if (inactive() || Object.keys(to).length === 0) return;
233
+ registerSpringsTable();
234
+ const velocity = motionValues(options?.velocity);
235
+ await motion.animate(to, {
236
+ spring: springs.stateChange,
237
+ ...Object.keys(velocity).length > 0 ? { velocity } : {}
238
+ }).finished;
239
+ },
240
+ async decay(velocity) {
241
+ if (inactive()) return;
242
+ const given = motionValues(velocity);
243
+ const translate = coast(motion, {
244
+ x: given.x,
245
+ y: given.y
246
+ });
247
+ const others = {};
248
+ for (const channel of [
249
+ "scale",
250
+ "rotate",
251
+ "opacity"
252
+ ]) {
253
+ const v0 = given[channel];
254
+ if (v0 != null) {
255
+ const property = channel === "scale" ? "scaleX" : channel;
256
+ others[channel] = momentum(motion.get(property), v0, SETTLE_THRESHOLD[property], channel === "opacity");
257
+ }
258
+ }
259
+ const moving = [];
260
+ if (Object.keys(translate).length > 0) moving.push(motion.decay(translate).finished);
261
+ if (Object.keys(others).length > 0) moving.push(motion.play(others).finished);
262
+ await settledOrTakenOver(moving);
263
+ },
264
+ set(values) {
265
+ if (!inactive()) motion.set(motionValues(values));
266
+ },
267
+ get() {
268
+ return snapshot((channel) => motion.get(channel));
269
+ },
270
+ getVelocity() {
271
+ return snapshot((channel) => motion.getVelocity(channel));
272
+ },
273
+ stop() {
274
+ if (!inactive()) motion.stop();
275
+ },
276
+ destroy() {
277
+ if (!destroyed) {
278
+ destroyed = true;
279
+ motion.stop();
280
+ motion.dispose();
281
+ }
282
+ }
283
+ },
284
+ attach: (next) => {
285
+ if (destroyed || next === element) return;
286
+ if (element != null) {
287
+ motion.attach(null);
288
+ motion.stop();
289
+ motion.set(motionValues(REST));
290
+ }
291
+ element = next;
292
+ motion.attach(next);
293
+ }
294
+ };
295
+ }
296
+ //#endregion
297
+ //#region src/composables/createAnimator.ts
298
+ /**
299
+ * 用组件库自己的动效驱动 `element`。`animate` 用状态切换弹簧把通道带到目标值,
300
+ * `decay` 从松手速度开始惯性滑行,`set` 直接跳到某个值,`get` 和
301
+ * `getVelocity` 读当前值和速度,`stop` 原地停下,`destroy` 放开元素。
302
+ * 系统开启「减弱动态效果」时,每次调用都会改走替代方案:触屏上位移变成短淡入淡出,
303
+ * 鼠标环境下直接落到终点。
304
+ *
305
+ * 一个元素只配一个 animator,两个会互相覆盖。在组件里优先用 `useAnimator`。
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * const animator = createAnimator(card)
310
+ * await animator.animate({ x: 0, rotate: 0 }, { velocity: { x: -900 } })
311
+ * void animator.decay({ x: 2400 })
312
+ * animator.destroy()
313
+ * ```
314
+ */
315
+ function createAnimator(element) {
316
+ const { animator, attach } = createAttachableAnimator();
317
+ attach(element);
318
+ return animator;
319
+ }
320
+ //#endregion
321
+ //#region src/gestures/createPanGesture.ts
322
+ const ZERO = {
323
+ x: 0,
324
+ y: 0
325
+ };
326
+ /** Report drags on `element` as values, with the recognizer's options. */
327
+ function createPan(element, options) {
328
+ const { axis, onPan } = options;
329
+ const recognizer = new PanGestureRecognizer({
330
+ name: "pan",
331
+ ...options.recognizer,
332
+ direction: axis === "x" ? "horizontal" : axis === "y" ? "vertical" : "any"
333
+ });
334
+ const along = (point) => axis === "x" ? {
335
+ x: point.x,
336
+ y: 0
337
+ } : axis === "y" ? {
338
+ x: 0,
339
+ y: point.y
340
+ } : {
341
+ x: point.x,
342
+ y: point.y
343
+ };
344
+ let input = "touch";
345
+ recognizer.addListener(() => {
346
+ const state = recognizer.state;
347
+ if (state !== "began" && state !== "changed" && state !== "ended" && state !== "cancelled") return;
348
+ if (state === "began") {
349
+ const touch = recognizer.trackedTouches[0];
350
+ input = touch == null ? "touch" : touch.scrollType != null ? "scroll" : touch.pointerType;
351
+ }
352
+ onPan({
353
+ state,
354
+ translation: along(recognizer.translation()),
355
+ totalTranslation: along(recognizer.totalTranslation()),
356
+ velocity: state === "cancelled" ? { ...ZERO } : along(recognizer.velocity()),
357
+ input
358
+ });
359
+ });
360
+ let detach = getGestureHost(element.ownerDocument).attach(element, recognizer);
361
+ return { destroy() {
362
+ const current = detach;
363
+ detach = null;
364
+ current?.();
365
+ } };
366
+ }
367
+ /**
368
+ * Report drags on `element` as values. The drag claims its touch at UIKit's
369
+ * 10 pt, as `UIPanGestureRecognizer` does, so a tap stays a tap. The pan sets
370
+ * the element's `touch-action` for the axis.
371
+ * @example
372
+ * ```ts
373
+ * const pan = createPanGesture(card, {
374
+ * axis: 'x',
375
+ * onPan: ({ state, translation }) => {
376
+ * card.style.translate = state === 'changed' ? `${translation.x}px` : ''
377
+ * },
378
+ * })
379
+ * // Later:
380
+ * pan.destroy()
381
+ * ```
382
+ */
383
+ function createPanGesture(element, options) {
384
+ const { axis, onPan } = options;
385
+ return createPan(element, {
386
+ axis,
387
+ onPan: ({ state, translation, velocity }) => {
388
+ onPan({
389
+ state,
390
+ translation,
391
+ velocity
392
+ });
393
+ }
394
+ });
395
+ }
396
+ //#endregion
397
+ //#region src/dragToSnapPoints/compositorSettle.ts
398
+ /** Keyframes per second: twice a 60 Hz display's frame rate. */
399
+ const SAMPLE_HZ = 120;
400
+ /** The longest a settle plays (ms). */
401
+ const MAX_MS = 3e3;
402
+ /** The keyframe times (ms): a fixed grid, plus each time the curve crosses a bend. */
403
+ function keyframeTimes(valueAt, durationMs, bends) {
404
+ const steps = Math.ceil(durationMs / 1e3 * SAMPLE_HZ);
405
+ const grid = [];
406
+ for (let step = 0; step <= steps; step += 1) grid.push(Math.min(durationMs, step / SAMPLE_HZ * 1e3));
407
+ const times = [...grid];
408
+ for (const bend of bends) for (let index = 0; index < grid.length - 1; index += 1) {
409
+ let low = grid[index];
410
+ let high = grid[index + 1];
411
+ if ((valueAt(low) - bend) * (valueAt(high) - bend) >= 0) continue;
412
+ for (let iteration = 0; iteration < 24; iteration += 1) {
413
+ const middle = (low + high) / 2;
414
+ if ((valueAt(low) - bend) * (valueAt(middle) - bend) <= 0) high = middle;
415
+ else low = middle;
416
+ }
417
+ times.push((low + high) / 2);
418
+ }
419
+ return times.sort((a, b) => a - b);
420
+ }
421
+ /**
422
+ * Plays `curve` on `parts` from now. `onPass` runs on the first frame the
423
+ * value is past its offset in its direction, and `onFinish` on the first
424
+ * frame after the curve ends. A part with no Web Animations (a test DOM)
425
+ * shows the end pose at once, and the callbacks keep the curve's times.
426
+ */
427
+ function playCompositorSettle({ curve, parts, requestFrame, onPass, onFinish }) {
428
+ const durationMs = Math.min(MAX_MS, Math.max(0, curve.settleTime(SETTLE_THRESHOLD.x) * 1e3));
429
+ const started = motionNow();
430
+ let stopped = false;
431
+ let passed = onPass == null;
432
+ const valueAt = (ms) => curve.value(ms / 1e3);
433
+ const times = keyframeTimes(valueAt, durationMs, new Set(parts.flatMap((part) => part.bends ?? [])));
434
+ const values = times.map((ms, index) => index === times.length - 1 ? curve.to : valueAt(ms));
435
+ const offsets = times.map((ms) => durationMs === 0 ? 1 : ms / durationMs);
436
+ const animations = durationMs === 0 ? [] : parts.filter((part) => typeof part.element.animate === "function").map((part) => {
437
+ const end = part.offset(curve.to);
438
+ const animation = part.element.animate(values.map((value, index) => ({
439
+ offset: offsets[index],
440
+ translate: `${part.offset(value) - end}px 0px`
441
+ })), {
442
+ duration: durationMs,
443
+ easing: "linear",
444
+ fill: "backwards"
445
+ });
446
+ animation.startTime = started;
447
+ return animation;
448
+ });
449
+ const elapsedSeconds = () => Math.min(durationMs, Math.max(0, motionNow() - started)) / 1e3;
450
+ const presented = () => curve.value(elapsedSeconds());
451
+ const cancelAll = () => {
452
+ for (const animation of animations) animation.cancel();
453
+ };
454
+ const stop = () => {
455
+ const value = presented();
456
+ stopped = true;
457
+ cancelAll();
458
+ return value;
459
+ };
460
+ const frame = () => {
461
+ if (stopped) return;
462
+ const seconds = elapsedSeconds();
463
+ if (!passed && onPass != null) {
464
+ if ((curve.value(seconds) - onPass.offset) * onPass.direction >= 0) {
465
+ passed = true;
466
+ onPass.call();
467
+ if (stopped) return;
468
+ }
469
+ }
470
+ if (seconds * 1e3 >= durationMs) {
471
+ stopped = true;
472
+ cancelAll();
473
+ onFinish();
474
+ return;
475
+ }
476
+ requestFrame(frame);
477
+ };
478
+ requestFrame(frame);
479
+ return {
480
+ presented,
481
+ velocity: () => curve.velocity(elapsedSeconds()),
482
+ stop
483
+ };
484
+ }
485
+ //#endregion
486
+ //#region src/dragToSnapPoints/createSnapDrag.ts
487
+ /** The document timeline's clock, which the animator runs on. */
488
+ const now = () => performance.now();
489
+ /** Runs `callback` in the next animation frame (a timer without one). */
490
+ function requestFrame(callback) {
491
+ if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => callback());
492
+ else setTimeout(callback, 16);
493
+ }
494
+ /**
495
+ * Where `element` is drawn now, read from the inline value an animator left
496
+ * on it. A drag destroyed and created again leaves it where it stopped. An
497
+ * axis it does not set reads 0.
498
+ */
499
+ function drawnAt(element, customProperty) {
500
+ if (customProperty != null) {
501
+ const value = Number.parseFloat(element.style.getPropertyValue(customProperty));
502
+ return {
503
+ x: Number.isFinite(value) ? value : 0,
504
+ y: 0
505
+ };
506
+ }
507
+ const [x = 0, y = 0] = element.style.getPropertyValue("translate").trim().split(/\s+/).map((part) => Number.parseFloat(part)).map((value) => Number.isFinite(value) ? value : 0);
508
+ return {
509
+ x,
510
+ y
511
+ };
512
+ }
513
+ /** Drops a point that is not a finite number, with a dev warning. */
514
+ function sortedSnapPoints(snapPoints) {
515
+ const usable = snapPoints.filter((point) => Number.isFinite(point));
516
+ if (usable.length < snapPoints.length) devWarn("createDragToSnapPoints", "snapPoints must be numbers; the others are ignored.");
517
+ return usable.sort((a, b) => a - b);
518
+ }
519
+ /** Lets a drag move `element` along `axis` and settles it on its snap points. */
520
+ function createSnapDrag(element, options) {
521
+ const { axis, onSettle, model } = options;
522
+ if (options.customProperty != null && axis !== "x") devWarn("createSnapDrag", "customProperty draws the x axis only, so this y drag draws nothing.");
523
+ const flickThreshold = options.flickThreshold ?? 1008;
524
+ let points = sortedSnapPoints(options.snapPoints);
525
+ const drawn = drawnAt(element, options.customProperty?.name);
526
+ const animator = createMotionEngine(element, {
527
+ initial: drawn,
528
+ ...options.customProperty != null ? { customProperty: options.customProperty } : {}
529
+ });
530
+ let targetIndex = points.length === 0 ? 0 : resolveSnapPoint({
531
+ points,
532
+ position: drawn[axis],
533
+ velocity: 0,
534
+ flickThreshold
535
+ }).index;
536
+ let turn = 0;
537
+ let drag = null;
538
+ let destroyed = false;
539
+ let inFlight = null;
540
+ let compositor = null;
541
+ let finishCompositor = null;
542
+ const position = () => compositor?.presented() ?? animator.get(axis);
543
+ /** Stops a compositor settle where it is on screen, and draws it there. */
544
+ const holdCompositor = () => {
545
+ if (compositor == null) return;
546
+ const value = compositor.stop();
547
+ compositor = null;
548
+ finishCompositor = null;
549
+ animator.set({ [axis]: value }, { promote: false });
550
+ };
551
+ const settle = (target, settleOptions) => {
552
+ registerSpringsTable();
553
+ targetIndex = target;
554
+ const mine = ++turn;
555
+ const flight = {
556
+ turn: mine,
557
+ options: settleOptions,
558
+ passed: false
559
+ };
560
+ inFlight = flight;
561
+ const { velocity } = settleOptions;
562
+ const spring = settleOptions.spring ?? springs.settle;
563
+ const touchRelease = settleOptions.touchRelease === true;
564
+ const { compositorParts } = options;
565
+ if (compositorParts != null && animator.reducedMotion({ touchRelease }) === "off") {
566
+ const startVelocity = velocity != null && velocity !== 0 ? velocity : compositor?.velocity() ?? animator.getVelocity(axis);
567
+ const from = position();
568
+ holdCompositor();
569
+ const to = points[target];
570
+ const curve = solveSpring(toSpring(resolveMotion(element, spring)), {
571
+ from,
572
+ to,
573
+ velocity: startVelocity
574
+ });
575
+ const { onPass } = settleOptions;
576
+ const play = () => {
577
+ if (destroyed || mine !== turn) return;
578
+ animator.stop();
579
+ animator.set({ [axis]: to }, { promote: false });
580
+ const finish = () => {
581
+ compositor = null;
582
+ finishCompositor = null;
583
+ if (inFlight === flight) inFlight = null;
584
+ if (mine === turn && !destroyed) onSettle(targetIndex);
585
+ };
586
+ compositor = playCompositorSettle({
587
+ curve,
588
+ parts: compositorParts(),
589
+ requestFrame,
590
+ ...onPass != null ? { onPass: {
591
+ ...onPass,
592
+ call: () => {
593
+ flight.passed = true;
594
+ onPass.call();
595
+ }
596
+ } } : {},
597
+ onFinish: finish
598
+ });
599
+ finishCompositor = finish;
600
+ };
601
+ if (settleOptions.start === "next-frame") requestFrame(play);
602
+ else play();
603
+ return null;
604
+ }
605
+ holdCompositor();
606
+ const handle = animator.animate({ [axis]: points[target] }, {
607
+ spring,
608
+ ...velocity != null && velocity !== 0 ? { velocity: { [axis]: velocity } } : {}
609
+ }, {
610
+ touchRelease,
611
+ ...settleOptions.start != null ? { start: settleOptions.start } : {}
612
+ });
613
+ let finished = false;
614
+ handle.finished.then((arrived) => {
615
+ finished = true;
616
+ if (inFlight === flight) inFlight = null;
617
+ if (arrived && mine === turn && !destroyed) onSettle(targetIndex);
618
+ });
619
+ const { onPass } = settleOptions;
620
+ if (onPass != null && typeof requestAnimationFrame === "function") {
621
+ const { direction } = onPass;
622
+ const check = (time) => {
623
+ if (destroyed || mine !== turn) return;
624
+ if ((animator.get(axis, time) - onPass.offset) * direction >= 0) {
625
+ flight.passed = true;
626
+ onPass.call();
627
+ return;
628
+ }
629
+ if (!finished) requestAnimationFrame(check);
630
+ };
631
+ requestAnimationFrame(check);
632
+ }
633
+ return handle;
634
+ };
635
+ /** Lands a model's landing (null: the element stays as it is). */
636
+ const land = (landing, touchRelease) => {
637
+ if (landing != null) settle(landing.index, {
638
+ velocity: landing.velocity,
639
+ spring: landing.spring,
640
+ touchRelease
641
+ });
642
+ };
643
+ const pan = createPan(element, {
644
+ axis,
645
+ recognizer: options.pan,
646
+ onPan: ({ state, translation, totalTranslation, velocity, input }) => {
647
+ if (destroyed || points.length === 0) return;
648
+ const moved = {
649
+ translation: translation[axis],
650
+ total: totalTranslation[axis],
651
+ input
652
+ };
653
+ if (state === "began") {
654
+ drag = {
655
+ start: position(),
656
+ startIndex: targetIndex,
657
+ input,
658
+ caught: false
659
+ };
660
+ if (model?.begin?.({
661
+ start: drag.start,
662
+ ...moved
663
+ }) === false) {
664
+ drag = null;
665
+ return;
666
+ }
667
+ }
668
+ if (drag == null) return;
669
+ const reading = {
670
+ start: drag.start,
671
+ ...moved,
672
+ input: drag.input
673
+ };
674
+ if (state === "began" || state === "changed") {
675
+ const target = model?.move != null ? model.move(reading) : { offset: drag.start + moved.translation };
676
+ if (target == null) return;
677
+ if (!drag.caught) {
678
+ drag.caught = true;
679
+ turn += 1;
680
+ holdCompositor();
681
+ }
682
+ if (target.spring == null) animator.set({ [axis]: target.offset });
683
+ else {
684
+ registerSpringsTable();
685
+ animator.animate({ [axis]: target.offset }, { spring: target.spring }, { at: now() });
686
+ }
687
+ return;
688
+ }
689
+ const { startIndex, start } = drag;
690
+ drag = null;
691
+ const touchRelease = reading.input === "touch";
692
+ if (state === "cancelled") {
693
+ if (model?.cancel != null) land(model.cancel(reading), touchRelease);
694
+ else settle(startIndex, {
695
+ velocity: 0,
696
+ touchRelease
697
+ });
698
+ return;
699
+ }
700
+ const release = velocity[axis];
701
+ if (model?.release != null) {
702
+ land(model.release({
703
+ ...reading,
704
+ velocity: release
705
+ }), touchRelease);
706
+ return;
707
+ }
708
+ const { index: target } = resolveSnapPoint({
709
+ points,
710
+ position: position(),
711
+ velocity: release,
712
+ flickThreshold,
713
+ start
714
+ });
715
+ settle(target, {
716
+ velocity: release,
717
+ touchRelease
718
+ });
719
+ }
720
+ });
721
+ return {
722
+ settleTo(target, settleOptions = {}) {
723
+ if (destroyed) return null;
724
+ if (!Number.isInteger(target) || target < 0 || target >= points.length) {
725
+ devWarn("createDragToSnapPoints", `settleTo(${target}) is outside the ${points.length} snap points, so it does nothing.`);
726
+ return null;
727
+ }
728
+ drag = null;
729
+ return settle(target, {
730
+ velocity: 0,
731
+ ...settleOptions
732
+ });
733
+ },
734
+ setSnapPoints(snapPoints) {
735
+ if (destroyed) return;
736
+ const flight = (drag == null || !drag.caught) && inFlight?.turn === turn ? inFlight : null;
737
+ const heading = flight == null ? null : points[targetIndex];
738
+ const startPoint = drag == null ? null : points[drag.startIndex];
739
+ points = sortedSnapPoints(snapPoints);
740
+ if (points.length === 0) {
741
+ turn += 1;
742
+ drag = null;
743
+ holdCompositor();
744
+ animator.stop();
745
+ targetIndex = 0;
746
+ return;
747
+ }
748
+ const nearest = (at) => resolveSnapPoint({
749
+ points,
750
+ position: at,
751
+ velocity: 0,
752
+ flickThreshold
753
+ }).index;
754
+ if (flight != null && heading != null) {
755
+ const { onPass, ...rest } = flight.options;
756
+ settle(nearest(heading), {
757
+ ...rest,
758
+ ...flight.passed ? {} : { onPass },
759
+ velocity: 0
760
+ });
761
+ if (drag != null) drag.startIndex = nearest(startPoint ?? drag.start);
762
+ return;
763
+ }
764
+ targetIndex = nearest(startPoint ?? position());
765
+ if (drag != null) drag.startIndex = targetIndex;
766
+ },
767
+ snapPoints() {
768
+ return points;
769
+ },
770
+ animator,
771
+ position,
772
+ finishSettle() {
773
+ const finish = finishCompositor;
774
+ if (compositor == null || finish == null) return;
775
+ compositor.stop();
776
+ finish();
777
+ },
778
+ destroy() {
779
+ if (destroyed) return;
780
+ destroyed = true;
781
+ pan.destroy();
782
+ holdCompositor();
783
+ animator.stop();
784
+ animator.dispose();
785
+ }
786
+ };
787
+ }
788
+ //#endregion
789
+ //#region src/dragToSnapPoints/createDragToSnapPoints.ts
790
+ /**
791
+ * @file createDragToSnapPoints.ts
792
+ * @input An element and its snap points
793
+ * @output The public snap-point drag: `createDragToSnapPoints`, its options
794
+ * and handle. Also re-exports createSnapDrag and its types (the drag under
795
+ * it, with the options only Core passes), which no package entry exports.
796
+ * @position Public entry point, re-exported from the package through
797
+ * composables/createDragToSnapPoints.ts, and wrapped by
798
+ * `useDragToSnapPoints`. Importing it does no DOM work.
799
+ *
800
+ * SYNC: When modified, update:
801
+ * - createDragToSnapPoints.test.ts
802
+ * - ../composables/useDragToSnapPoints.ts
803
+ * - the use-drag-to-snap-points docs
804
+ */
805
+ /**
806
+ * Lets a drag move `element` along `axis` and settles it on `snapPoints` at
807
+ * the release, then calls `onSettle(index)`.
808
+ *
809
+ * The release settles on the nearest snap point. A release faster than
810
+ * `flickThreshold` carries to the next one in its direction. A release that
811
+ * moves back toward the drag's start returns to the snap point it started
812
+ * from. The settle springs from the release velocity. Under Reduce Motion,
813
+ * the release cross-fades after a touch drag or on a coarse primary pointer,
814
+ * and lands at once elsewhere. `settleTo(index)` settles without a drag, for
815
+ * the keyboard.
816
+ *
817
+ * @example
818
+ * ```ts
819
+ * const snap = createDragToSnapPoints(drawer, {
820
+ * axis: 'y',
821
+ * snapPoints: [0, 240, 480],
822
+ * onSettle: index => console.log('settled on', index),
823
+ * })
824
+ * button.addEventListener('click', () => snap.settleTo(0))
825
+ * // Later:
826
+ * snap.destroy()
827
+ * ```
828
+ */
829
+ function createDragToSnapPoints(element, options) {
830
+ const { axis, flickThreshold, onSettle } = options;
831
+ if (!options.snapPoints.some((point) => Number.isFinite(point))) {
832
+ devWarn("createDragToSnapPoints", "snapPoints is empty, so the drag does nothing.");
833
+ return {
834
+ settleTo() {},
835
+ destroy() {}
836
+ };
837
+ }
838
+ const snap = createSnapDrag(element, {
839
+ axis,
840
+ snapPoints: options.snapPoints,
841
+ ...flickThreshold != null ? { flickThreshold } : {},
842
+ onSettle
843
+ });
844
+ return {
845
+ settleTo(index) {
846
+ snap.settleTo(index);
847
+ },
848
+ destroy() {
849
+ snap.destroy();
850
+ }
851
+ };
852
+ }
853
+ //#endregion
854
+ //#region src/composables/useAnimator.ts
855
+ /**
856
+ * 用组件库自己的动效驱动 `target` 指向的元素。`target` 可以是模板 ref、
857
+ * getter 或元素本身。在事件处理和侦听器里调用返回值的 `animate`、`decay`、
858
+ * `set`、`get`、`getVelocity`、`stop`。
859
+ *
860
+ * 返回值只创建一次,动画不触发组件重新渲染。animator 跟着 `target`
861
+ * 当前指向的元素走,换成新元素时新元素从静止状态开始。作用域销毁时停下
862
+ * 正在跑的动画并放开元素。没有元素时每个调用都不做事,`animate` 和
863
+ * `decay` 立刻 resolve。服务端渲染时不碰 DOM。
864
+ *
865
+ * @example
866
+ * ```ts
867
+ * const card = useTemplateRef<HTMLElement>('card')
868
+ * const animator = useAnimator(card)
869
+ * function pop(): void {
870
+ * void animator.animate({ scale: 1.2 })
871
+ * }
872
+ * ```
873
+ */
874
+ function useAnimator(target) {
875
+ const { animator, attach } = createAttachableAnimator();
876
+ const { destroy: _destroy, ...handle } = animator;
877
+ watch(() => toValue(target) ?? null, (element) => attach(element), {
878
+ immediate: true,
879
+ flush: "sync"
880
+ });
881
+ if (getCurrentScope()) onScopeDispose(() => attach(null));
882
+ return handle;
883
+ }
884
+ //#endregion
885
+ //#region src/composables/useContainerReveal.ts
886
+ function useContainerReveal(options = {}) {
887
+ function containerProps(reveal = {}) {
888
+ if (toValue(options.isEnabled) === false) return {};
889
+ return {
890
+ class: {
891
+ "astryx-reveal": true,
892
+ "astryx-reveal--inactive": reveal.forceState === "inactive",
893
+ "astryx-reveal--active": reveal.forceState === "active"
894
+ },
895
+ style: reveal.hoverDelay ? { "--_hover-delay": `${reveal.hoverDelay}ms` } : void 0
896
+ };
897
+ }
898
+ function contentProps(reveal = {}) {
899
+ if (toValue(options.isEnabled) === false) return {};
900
+ const inverted = reveal.isRevealInverted === true;
901
+ const preserved = reveal.isLayoutPreserved === true;
902
+ return { class: {
903
+ "astryx-reveal__content": !inverted,
904
+ "astryx-reveal__content--preserve": !inverted && preserved,
905
+ "astryx-reveal__conceal": inverted,
906
+ "astryx-reveal__conceal--preserve": inverted && preserved,
907
+ "astryx-reveal__shown": reveal.forceVisibility === "shown",
908
+ "astryx-reveal__hidden": reveal.forceVisibility === "hidden" && !preserved,
909
+ "astryx-reveal__hidden--preserve": reveal.forceVisibility === "hidden" && preserved
910
+ } };
911
+ }
912
+ return {
913
+ containerProps,
914
+ contentProps
915
+ };
916
+ }
917
+ //#endregion
918
+ //#region src/composables/useControllableState.ts
919
+ /**
920
+ * 受控或自己管的 v-model。
921
+ *
922
+ * Astryx 没有同名 hook。各组件原来各自判断「外面传了值就听外面的,没传就自己记」,
923
+ * 这里收成一个函数,方便以后的 v-model 共用。
924
+ */
925
+ function useControllableState(options) {
926
+ const { modelValue, onChange } = options;
927
+ const controlled = modelValue.value !== void 0;
928
+ const local = ref(toValue(options.defaultValue));
929
+ const isControlled = computed(() => controlled);
930
+ const value = computed(() => controlled ? modelValue.value : local.value);
931
+ function setValue(next) {
932
+ if (Object.is(value.value, next)) return;
933
+ if (controlled) modelValue.value = next;
934
+ else local.value = next;
935
+ onChange?.(next);
936
+ }
937
+ return {
938
+ isControlled,
939
+ setValue,
940
+ value
941
+ };
942
+ }
943
+ //#endregion
944
+ //#region src/composables/useDragToSnapPoints.ts
945
+ /**
946
+ * 让 `target` 指向的元素能沿 `axis` 拖动,松手后停到 `snapPoints` 里的一个点上。
947
+ * `target` 可以是模板 ref、getter 或元素本身。
948
+ *
949
+ * 拖动跟着 `target` 当前指向的元素走,元素换掉就挂到新元素上,作用域销毁时拆掉。
950
+ * `options` 是响应式对象时,`axis`、`snapPoints`、`flickThreshold` 变了就重建拖动,
951
+ * 元素停在原处(正在进行的回弹也一样);内容相同的新数组不会重建。`onSettle`
952
+ * 每次停稳时才从 `options` 里读,换一个新函数不会重建。服务端渲染时不碰 DOM。
953
+ *
954
+ * @example
955
+ * ```ts
956
+ * const drawer = useTemplateRef<HTMLElement>('drawer')
957
+ * const index = ref(0)
958
+ * const { settleTo } = useDragToSnapPoints(drawer, {
959
+ * axis: 'y',
960
+ * snapPoints: [0, 240, 480],
961
+ * onSettle: (next) => { index.value = next },
962
+ * })
963
+ * ```
964
+ */
965
+ function useDragToSnapPoints(target, options) {
966
+ let current = null;
967
+ const points = () => JSON.stringify(options.snapPoints);
968
+ useAttachment(target, (element) => {
969
+ const snap = createDragToSnapPoints(element, {
970
+ axis: options.axis,
971
+ snapPoints: JSON.parse(points()),
972
+ flickThreshold: options.flickThreshold,
973
+ onSettle: (index) => options.onSettle(index)
974
+ });
975
+ current = snap;
976
+ return () => {
977
+ snap.destroy();
978
+ if (current === snap) current = null;
979
+ };
980
+ }, () => `${options.axis} ${points()} ${options.flickThreshold ?? ""}`);
981
+ return { settleTo: (index) => current?.settleTo(index) };
982
+ }
983
+ //#endregion
984
+ //#region src/composables/internal/entryAnimation.ts
985
+ /**
986
+ * 预设对应的共享动画类。时长、缓动和「减少动态效果」的处理都在 `styles/motion.css` 里。
987
+ * 类名里的 above 指元素从下方升上去,below 指从上方落下来。
988
+ */
989
+ const ENTRY_ANIMATION_CLASSES = {
990
+ slideDown: "astryx-motion-slide-in-below",
991
+ slideUp: "astryx-motion-slide-in-above",
992
+ fadeIn: "astryx-motion-fade-in",
993
+ scaleIn: "astryx-motion-scale-in"
994
+ };
995
+ let hasPaintedPage = false;
996
+ let isTrackingPaint = false;
997
+ function trackFirstPaint() {
998
+ if (isTrackingPaint || typeof window === "undefined" || typeof requestAnimationFrame !== "function") return;
999
+ isTrackingPaint = true;
1000
+ requestAnimationFrame(() => {
1001
+ requestAnimationFrame(() => {
1002
+ hasPaintedPage = true;
1003
+ });
1004
+ });
1005
+ }
1006
+ /** 首屏是否已经画过。服务端没有 window,永远返回 false。 */
1007
+ function isAfterFirstPaint() {
1008
+ trackFirstPaint();
1009
+ return hasPaintedPage;
1010
+ }
1011
+ /**
1012
+ * 对应原版 Astryx 的 `hooks/useEntryAnimation`。
1013
+ *
1014
+ * 元素挂载时播一次入场动画,但只对首屏画完之后才插进来的元素生效:
1015
+ * 首屏就渲染出来的元素不播放,免得整页一起动。
1016
+ *
1017
+ * 用法是把返回的 `entryClass` 绑到 `class` 上。动画时长和缓动取自主题的
1018
+ * motion token,「减少动态效果」打开时动画会直接落到结束状态。
1019
+ */
1020
+ function useEntryAnimation(options = {}) {
1021
+ const preset = options.preset ?? "slideDown";
1022
+ if (isHydrating()) return { entryClass: null };
1023
+ return { entryClass: isAfterFirstPaint() ? ENTRY_ANIMATION_CLASSES[preset] : null };
1024
+ }
1025
+ /**
1026
+ * 当前组件是否在接管服务端渲染的 DOM。Vue 接管时先把已有的 DOM 节点交给组件的 vnode,
1027
+ * 再运行 setup;普通挂载时这里还是 null。不在组件里调用时返回 false。
1028
+ */
1029
+ function isHydrating() {
1030
+ return getCurrentInstance()?.vnode.el != null;
1031
+ }
1032
+ trackFirstPaint();
1033
+ //#endregion
1034
+ //#region src/composables/useGridFocus.ts
1035
+ /** 网格里一格可以接受的元素:按钮,或者显式可聚焦的元素。 */
1036
+ const DEFAULT_CELL_SELECTOR = "button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
1037
+ /**
1038
+ * 对应原版 Astryx 的 `hooks/useGridFocus`。
1039
+ *
1040
+ * 按 WAI-ARIA 的 grid 模式管二维网格的键盘导航:方向键一格一格走,
1041
+ * Home/End 走到行首行尾,Ctrl+Home/Ctrl+End 走到整张网格的开头和结尾,
1042
+ * Page Up/Down 交给调用方(日历里就是翻月)。走到边界时可以把事件交出去,
1043
+ * 让别的网格接住焦点,例如翻到上个月继续用方向键。
1044
+ *
1045
+ * 它靠读 DOM 里格子的顺序算行列,所以格子要不要能聚焦、要不要聚焦格子里的某个按钮,
1046
+ * 都是通过 `isCellFocusable` 和 `getFocusTarget` 两个回调交给调用方决定。
1047
+ */
1048
+ function useGridFocus(options) {
1049
+ const gridRef = ref(null);
1050
+ const cellSelector = options.cellSelector ?? DEFAULT_CELL_SELECTOR;
1051
+ function isRoving() {
1052
+ return toValue(options.hasRovingTabIndex ?? false);
1053
+ }
1054
+ function getCells() {
1055
+ const grid = gridRef.value;
1056
+ if (grid == null) return [];
1057
+ return [...grid.querySelectorAll(cellSelector)];
1058
+ }
1059
+ /** 能接焦点的格子,按 DOM 顺序。 */
1060
+ function getFocusableCells() {
1061
+ return getCells().filter((cell) => options.isCellFocusable?.(cell) ?? true);
1062
+ }
1063
+ function resolveTarget(cell) {
1064
+ return options.getFocusTarget?.(cell) ?? cell;
1065
+ }
1066
+ function indexOfTarget(target) {
1067
+ if (target == null) return -1;
1068
+ return getCells().findIndex((cell) => cell === target || cell.contains(target));
1069
+ }
1070
+ function activeIndex() {
1071
+ const grid = gridRef.value;
1072
+ if (grid == null) return -1;
1073
+ const focused = grid.ownerDocument.activeElement;
1074
+ if (focused == null || !grid.contains(focused)) return -1;
1075
+ return indexOfTarget(focused);
1076
+ }
1077
+ /** 让当前格子成为唯一的 Tab 落脚点,其余格子退出 Tab 顺序。 */
1078
+ function syncRovingTabIndex(index) {
1079
+ if (!isRoving()) return;
1080
+ getCells().forEach((cell, cellIndex) => {
1081
+ const target = resolveTarget(cell);
1082
+ if (target != null) target.tabIndex = cellIndex === index ? 0 : -1;
1083
+ });
1084
+ }
1085
+ function focusTargetOf(cell) {
1086
+ if (cell == null) return false;
1087
+ if (!(options.isCellFocusable?.(cell) ?? true)) return false;
1088
+ const target = resolveTarget(cell);
1089
+ if (target == null) return false;
1090
+ target.focus({ preventScroll: true });
1091
+ syncRovingTabIndex(getCells().indexOf(cell));
1092
+ return true;
1093
+ }
1094
+ function columns() {
1095
+ return Math.max(1, toValue(options.columns));
1096
+ }
1097
+ function columnOf(index) {
1098
+ return index < 0 ? 0 : index % columns();
1099
+ }
1100
+ /** 走到边界外面时,把当前列和步长交给调用方,让另一张网格接住焦点。 */
1101
+ function navigateOut(current, offset, isAfter) {
1102
+ if (current < 0) return;
1103
+ const column = columnOf(current);
1104
+ if (isAfter) options.onNavigateAfter?.(column, offset);
1105
+ else options.onNavigateBefore?.(column, offset);
1106
+ }
1107
+ function moveTo(index, offset) {
1108
+ const cells = getCells();
1109
+ const target = cells[index];
1110
+ if (target == null) {
1111
+ navigateOut(activeIndex(), offset, index >= cells.length);
1112
+ return;
1113
+ }
1114
+ if (!(options.isCellFocusable?.(target) ?? true)) return;
1115
+ focusTargetOf(target);
1116
+ }
1117
+ function handleKeyDown(event) {
1118
+ if (event.defaultPrevented) return;
1119
+ if (gridRef.value == null) return;
1120
+ const index = activeIndex();
1121
+ if (index < 0) return;
1122
+ const cols = columns();
1123
+ const last = getCells().length - 1;
1124
+ const rowStart = index - columnOf(index);
1125
+ switch (event.key) {
1126
+ case "ArrowRight":
1127
+ event.preventDefault();
1128
+ moveTo(index + 1, 1);
1129
+ break;
1130
+ case "ArrowLeft":
1131
+ event.preventDefault();
1132
+ moveTo(index - 1, 1);
1133
+ break;
1134
+ case "ArrowDown":
1135
+ event.preventDefault();
1136
+ moveTo(index + cols, cols);
1137
+ break;
1138
+ case "ArrowUp":
1139
+ event.preventDefault();
1140
+ moveTo(index - cols, cols);
1141
+ break;
1142
+ case "Home":
1143
+ event.preventDefault();
1144
+ moveTo(event.ctrlKey || event.metaKey ? 0 : rowStart, 1);
1145
+ break;
1146
+ case "End":
1147
+ event.preventDefault();
1148
+ moveTo(event.ctrlKey || event.metaKey ? last : rowStart + cols - 1, 1);
1149
+ break;
1150
+ case "PageUp":
1151
+ if (options.onPageUp == null) break;
1152
+ event.preventDefault();
1153
+ options.onPageUp();
1154
+ break;
1155
+ case "PageDown":
1156
+ if (options.onPageDown == null) break;
1157
+ event.preventDefault();
1158
+ options.onPageDown();
1159
+ }
1160
+ }
1161
+ function handleFocus(event) {
1162
+ if (!isRoving()) return;
1163
+ const target = event.target;
1164
+ if (!(target instanceof Element)) return;
1165
+ const index = indexOfTarget(target);
1166
+ if (index < 0) return;
1167
+ syncRovingTabIndex(index);
1168
+ }
1169
+ function focusCell(index) {
1170
+ const cells = getCells();
1171
+ if (cells.length === 0) return;
1172
+ focusTargetOf(cells[Math.min(Math.max(index, 0), cells.length - 1)]);
1173
+ }
1174
+ function focusFirst() {
1175
+ focusTargetOf(getFocusableCells()[0]);
1176
+ }
1177
+ function focusLast() {
1178
+ const cells = getFocusableCells();
1179
+ focusTargetOf(cells[cells.length - 1]);
1180
+ }
1181
+ /** 首次渲染后补上 Tab 落脚点;已经有一个 `tabindex="0"` 的格子就尊重它。 */
1182
+ function seedRovingTabIndex() {
1183
+ if (!isRoving()) return;
1184
+ const cells = getCells();
1185
+ const seeded = cells.findIndex((cell) => {
1186
+ const target = resolveTarget(cell);
1187
+ return target != null && target.tabIndex === 0 && (options.isCellFocusable?.(cell) ?? true);
1188
+ });
1189
+ if (seeded >= 0) {
1190
+ syncRovingTabIndex(seeded);
1191
+ return;
1192
+ }
1193
+ const first = cells.findIndex((cell) => options.isCellFocusable?.(cell) ?? true);
1194
+ if (first >= 0) syncRovingTabIndex(first);
1195
+ }
1196
+ onMounted(seedRovingTabIndex);
1197
+ watch(gridRef, seedRovingTabIndex);
1198
+ watch([() => toValue(options.columns), () => toValue(options.hasRovingTabIndex ?? false)], seedRovingTabIndex);
1199
+ onScopeDispose(() => {
1200
+ gridRef.value = null;
1201
+ });
1202
+ return {
1203
+ gridRef,
1204
+ handleKeyDown,
1205
+ handleFocus,
1206
+ focusCell,
1207
+ focusFirst,
1208
+ focusLast
1209
+ };
1210
+ }
1211
+ //#endregion
1212
+ //#region src/composables/useGridRovingFocus.ts
1213
+ /**
1214
+ * 网格式导航(roving tabindex):用方向键在二维网格中移动焦点。
1215
+ * 供 Calendar、Pagination(如果需要)等组件复用。
1216
+ */
1217
+ function useGridRovingFocus(options) {
1218
+ const { rows, columns, activeIndex, isEnabled = ref(true), isDisabled, onChange } = options;
1219
+ const row = ref(0);
1220
+ const column = ref(0);
1221
+ watch(activeIndex, (index) => {
1222
+ const cols = columns.value;
1223
+ if (cols > 0) {
1224
+ row.value = Math.floor(index / cols);
1225
+ column.value = index % cols;
1226
+ }
1227
+ }, { immediate: true });
1228
+ function indexFromRowCol(r, c) {
1229
+ return r * columns.value + c;
1230
+ }
1231
+ function moveTo(targetRow, targetCol) {
1232
+ if (!isEnabled.value) return;
1233
+ const r = Math.max(0, Math.min(targetRow, rows.value - 1));
1234
+ const c = Math.max(0, Math.min(targetCol, columns.value - 1));
1235
+ if (isDisabled?.(r, c)) return;
1236
+ const index = indexFromRowCol(r, c);
1237
+ onChange(index);
1238
+ }
1239
+ function moveUp() {
1240
+ moveTo(row.value - 1, column.value);
1241
+ }
1242
+ function moveDown() {
1243
+ moveTo(row.value + 1, column.value);
1244
+ }
1245
+ function moveLeft() {
1246
+ moveTo(row.value, column.value - 1);
1247
+ }
1248
+ function moveRight() {
1249
+ moveTo(row.value, column.value + 1);
1250
+ }
1251
+ function moveToFirstInRow() {
1252
+ moveTo(row.value, 0);
1253
+ }
1254
+ function moveToLastInRow() {
1255
+ moveTo(row.value, columns.value - 1);
1256
+ }
1257
+ function moveToFirstInColumn() {
1258
+ moveTo(0, column.value);
1259
+ }
1260
+ function moveToLastInColumn() {
1261
+ moveTo(rows.value - 1, column.value);
1262
+ }
1263
+ function onKeyDown(event) {
1264
+ if (!isEnabled.value) return;
1265
+ switch (event.key) {
1266
+ case "ArrowUp":
1267
+ event.preventDefault();
1268
+ moveUp();
1269
+ break;
1270
+ case "ArrowDown":
1271
+ event.preventDefault();
1272
+ moveDown();
1273
+ break;
1274
+ case "ArrowLeft":
1275
+ event.preventDefault();
1276
+ moveLeft();
1277
+ break;
1278
+ case "ArrowRight":
1279
+ event.preventDefault();
1280
+ moveRight();
1281
+ break;
1282
+ case "Home":
1283
+ event.preventDefault();
1284
+ if (event.ctrlKey) moveTo(0, 0);
1285
+ else moveToFirstInRow();
1286
+ break;
1287
+ case "End":
1288
+ event.preventDefault();
1289
+ if (event.ctrlKey) moveTo(rows.value - 1, columns.value - 1);
1290
+ else moveToLastInRow();
1291
+ break;
1292
+ case "PageUp":
1293
+ event.preventDefault();
1294
+ moveToFirstInColumn();
1295
+ break;
1296
+ case "PageDown":
1297
+ event.preventDefault();
1298
+ moveToLastInColumn();
1299
+ }
1300
+ }
1301
+ return {
1302
+ row,
1303
+ column,
1304
+ onKeyDown,
1305
+ moveTo
1306
+ };
1307
+ }
1308
+ //#endregion
1309
+ //#region src/composables/useImageMode.ts
1310
+ /**
1311
+ * APCA 感知亮度。先把 sRGB 按 2.4 线性化,再用接近 BT.709 的系数合成,
1312
+ * 最后做 0.56 次方,让 0.5 接近视觉上的中灰。饱和色比简单的伽马亮度更准。
1313
+ */
1314
+ function perceptualLightness(r, g, b) {
1315
+ const linear = (channel) => (channel / 255) ** 2.4;
1316
+ return (.2126729 * linear(r) + .7151522 * linear(g) + .072175 * linear(b)) ** .56;
1317
+ }
1318
+ /** 一组采样像素的平均亮度,再和阈值比出深浅。 */
1319
+ function imageModeFromPixels(pixels, threshold = .5) {
1320
+ let red = 0;
1321
+ let green = 0;
1322
+ let blue = 0;
1323
+ let count = 0;
1324
+ for (let index = 0; index < pixels.length; index += 4) {
1325
+ red += pixels[index] ?? 0;
1326
+ green += pixels[index + 1] ?? 0;
1327
+ blue += pixels[index + 2] ?? 0;
1328
+ count += 1;
1329
+ }
1330
+ const safeCount = count || 1;
1331
+ return perceptualLightness(red / safeCount, green / safeCount, blue / safeCount) > threshold ? "light" : "dark";
1332
+ }
1333
+ /**
1334
+ * 按图片亮度判断该用深色还是浅色前景。采样走 OffscreenCanvas,不往页面上画。
1335
+ * 跨域或网络失败时返回 `fallback`。
1336
+ */
1337
+ function useImageMode(src, options = {}) {
1338
+ const mode = ref(toValue(options).fallback ?? null);
1339
+ let request = 0;
1340
+ async function detect(url) {
1341
+ const current = ++request;
1342
+ const settings = toValue(options);
1343
+ const threshold = settings.threshold ?? .5;
1344
+ const fallback = settings.fallback ?? null;
1345
+ mode.value = fallback;
1346
+ try {
1347
+ const response = await fetch(url);
1348
+ if (!response.ok) throw new Error(`image ${response.status}`);
1349
+ const bitmap = await createImageBitmap(await response.blob());
1350
+ if (current !== request) return;
1351
+ const region = settings.region;
1352
+ const sx = region ? Math.round(region.x * bitmap.width) : 0;
1353
+ const sy = region ? Math.round(region.y * bitmap.height) : 0;
1354
+ const sw = region ? Math.max(1, Math.round(region.width * bitmap.width)) : bitmap.width;
1355
+ const sh = region ? Math.max(1, Math.round(region.height * bitmap.height)) : bitmap.height;
1356
+ const sample = 10;
1357
+ const context = new OffscreenCanvas(sample, sample).getContext("2d");
1358
+ if (!context) return;
1359
+ context.drawImage(bitmap, sx, sy, sw, sh, 0, 0, sample, sample);
1360
+ const pixels = context.getImageData(0, 0, sample, sample).data;
1361
+ if (current !== request) return;
1362
+ mode.value = imageModeFromPixels(pixels, threshold);
1363
+ } catch {
1364
+ if (current === request) mode.value = fallback;
1365
+ }
1366
+ }
1367
+ const sampleKey = computed(() => {
1368
+ const { region, threshold } = toValue(options);
1369
+ return [
1370
+ toValue(src),
1371
+ region?.x,
1372
+ region?.y,
1373
+ region?.width,
1374
+ region?.height,
1375
+ threshold
1376
+ ].join("|");
1377
+ });
1378
+ watch(sampleKey, () => {
1379
+ const url = toValue(src);
1380
+ if (!url) {
1381
+ request += 1;
1382
+ mode.value = toValue(options).fallback ?? null;
1383
+ return;
1384
+ }
1385
+ detect(url);
1386
+ }, { immediate: true });
1387
+ onScopeDispose(() => {
1388
+ request += 1;
1389
+ });
1390
+ return mode;
1391
+ }
1392
+ //#endregion
1393
+ //#region src/composables/useIndicatorFocusRing.ts
1394
+ /** 读不到 `:focus-visible` 时宁可按可见处理,不能把焦点环弄丢(WCAG 2.4.7)。 */
1395
+ function isFocusVisible(target) {
1396
+ try {
1397
+ return target.matches(":focus-visible");
1398
+ } catch {
1399
+ return true;
1400
+ }
1401
+ }
1402
+ /**
1403
+ * 对应原版 Astryx 的 `hooks/useIndicatorFocusRing`。
1404
+ *
1405
+ * 给「真输入框藏起来、画面上的图形代替它」的控件画标准焦点环:复选框、
1406
+ * 单选框都把真正的 input 设成透明,焦点环只能画在旁边那个图形上。
1407
+ *
1408
+ * 环画在指示器自己的元素上,只有这个元素自己的圆角能决定环的形状;
1409
+ * 而且只在 `:focus-visible` 时画,鼠标点一下不会亮。统一放在这里管,
1410
+ * 主题换掉指示器也照样有可见焦点,不会因为漏了一个属性就整块没法用键盘。
1411
+ */
1412
+ function useIndicatorFocusRing(options) {
1413
+ function indicator() {
1414
+ const child = options.containerRef.value?.firstElementChild;
1415
+ return child instanceof HTMLElement ? child : null;
1416
+ }
1417
+ /** 标记属性 `data-astryx-focus-ring` 的画法是 `styles/indicator-focus-ring.css`。 */
1418
+ function clear() {
1419
+ const element = indicator();
1420
+ if (element != null) delete element.dataset.astryxFocusRing;
1421
+ }
1422
+ function onFocus(event) {
1423
+ if (toValue(options.isDisabled ?? false)) {
1424
+ clear();
1425
+ return;
1426
+ }
1427
+ const target = event.target;
1428
+ if (!(target instanceof Element) || !isFocusVisible(target)) {
1429
+ clear();
1430
+ return;
1431
+ }
1432
+ const element = indicator();
1433
+ if (element != null) element.dataset.astryxFocusRing = "";
1434
+ }
1435
+ function onBlur() {
1436
+ clear();
1437
+ }
1438
+ return { focusProps: {
1439
+ onFocus,
1440
+ onBlur
1441
+ } };
1442
+ }
1443
+ //#endregion
1444
+ //#region src/composables/KeyboardHint.vue
1445
+ const _hoisted_1 = { class: "astryx-keyboard-hint__keys" };
1446
+ const _hoisted_2 = { class: "astryx-keyboard-hint__label" };
1447
+ const _sfc_main = /*@__PURE__*/ defineComponent({
1448
+ __name: "KeyboardHint",
1449
+ props: {
1450
+ visible: { type: Boolean },
1451
+ anchor: {},
1452
+ orientation: {}
1453
+ },
1454
+ setup(__props) {
1455
+ const props = __props;
1456
+ const messages = useComponentMessages({ keyboardHint: keyboardHintMessages });
1457
+ const hint = ref(null);
1458
+ const position = ref({
1459
+ top: 0,
1460
+ left: 0
1461
+ });
1462
+ const keys = computed(() => {
1463
+ if (props.orientation === "vertical") return ["up", "down"];
1464
+ if (props.orientation === "both") return [
1465
+ "left",
1466
+ "right",
1467
+ "up",
1468
+ "down"
1469
+ ];
1470
+ return ["left", "right"];
1471
+ });
1472
+ const style = computed(() => ({
1473
+ top: `${position.value.top}px`,
1474
+ left: `${position.value.left}px`
1475
+ }));
1476
+ function place() {
1477
+ const anchor = props.anchor;
1478
+ const element = hint.value;
1479
+ if (!anchor || !element) return;
1480
+ const rect = anchor.getBoundingClientRect();
1481
+ const hintRect = element.getBoundingClientRect();
1482
+ const top = Math.max(8, rect.top - hintRect.height - 8);
1483
+ const left = Math.min(window.innerWidth - hintRect.width - 8, Math.max(8, rect.left + rect.width / 2 - hintRect.width / 2));
1484
+ position.value = {
1485
+ top,
1486
+ left
1487
+ };
1488
+ }
1489
+ watch(() => [props.visible, props.anchor], () => {
1490
+ if (!props.visible) return;
1491
+ requestAnimationFrame(() => place());
1492
+ });
1493
+ function onScroll() {
1494
+ if (props.visible) place();
1495
+ }
1496
+ onMounted(() => {
1497
+ window.addEventListener("scroll", onScroll, true);
1498
+ window.addEventListener("resize", onScroll);
1499
+ });
1500
+ onBeforeUnmount(() => {
1501
+ window.removeEventListener("scroll", onScroll, true);
1502
+ window.removeEventListener("resize", onScroll);
1503
+ });
1504
+ return (_ctx, _cache) => {
1505
+ return withDirectives((openBlock(), createElementBlock("div", {
1506
+ ref_key: "hint",
1507
+ ref: hint,
1508
+ class: "astryx-keyboard-hint",
1509
+ "aria-hidden": "true",
1510
+ style: normalizeStyle(style.value)
1511
+ }, [createElementVNode("span", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(keys.value, (key) => {
1512
+ return openBlock(), createBlock(_sfc_main$1, {
1513
+ key,
1514
+ keys: key
1515
+ }, null, 8, ["keys"]);
1516
+ }), 128))]), createElementVNode("span", _hoisted_2, toDisplayString(unref(messages).keyboardHint.navigate), 1)], 4)), [[vShow, __props.visible]]);
1517
+ };
1518
+ }
1519
+ });
1520
+ //#endregion
1521
+ //#region src/composables/useKeyboardHint.ts
1522
+ const ARROW_KEYS = /* @__PURE__ */ new Set([
1523
+ "ArrowLeft",
1524
+ "ArrowRight",
1525
+ "ArrowUp",
1526
+ "ArrowDown"
1527
+ ]);
1528
+ /**
1529
+ * 一组方向键控件第一次被键盘点进来时,在当前项旁边短暂提示「用方向键移动」。
1530
+ * 提示显示期间登记在共用的关闭栈里,Escape 只关它,焦点不动。
1531
+ * 按过方向键、Escape、焦点离开(或设了时限且超时)之后不再出现。
1532
+ */
1533
+ function useKeyboardHint(options = {}) {
1534
+ const visible = ref(false);
1535
+ const anchor = ref(null);
1536
+ const orientation = computed(() => options.orientation ?? "horizontal");
1537
+ let dismissed = false;
1538
+ let timer;
1539
+ function hide() {
1540
+ visible.value = false;
1541
+ if (timer != null) {
1542
+ clearTimeout(timer);
1543
+ timer = void 0;
1544
+ }
1545
+ }
1546
+ function show(target) {
1547
+ if (dismissed || options.isEnabled === false) return;
1548
+ anchor.value = target;
1549
+ visible.value = true;
1550
+ if (timer != null) clearTimeout(timer);
1551
+ timer = void 0;
1552
+ if (options.dismissAfterMs != null) timer = setTimeout(() => {
1553
+ dismissed = true;
1554
+ hide();
1555
+ }, options.dismissAfterMs);
1556
+ }
1557
+ const token = {};
1558
+ let unregister = null;
1559
+ function release() {
1560
+ unregister?.();
1561
+ unregister = null;
1562
+ }
1563
+ watch(visible, (shown) => {
1564
+ release();
1565
+ if (!shown) return;
1566
+ unregister = pushLayer({
1567
+ token,
1568
+ getTrigger: () => anchor.value,
1569
+ dismissOnPointerOutside: false,
1570
+ dismissOnEscape: "close",
1571
+ onDismiss() {
1572
+ dismissed = true;
1573
+ hide();
1574
+ }
1575
+ });
1576
+ }, { flush: "post" });
1577
+ function onFocus(event) {
1578
+ if (dismissed || options.isEnabled === false) return;
1579
+ const target = event.target;
1580
+ const current = event.currentTarget;
1581
+ if (!(target instanceof HTMLElement) || !(current instanceof HTMLElement)) return;
1582
+ if (event.relatedTarget instanceof Node && current.contains(event.relatedTarget)) {
1583
+ if (visible.value) anchor.value = target;
1584
+ return;
1585
+ }
1586
+ if (!target.matches(":focus-visible")) return;
1587
+ show(target);
1588
+ }
1589
+ function onBlur(event) {
1590
+ const current = event.currentTarget;
1591
+ if (!(current instanceof HTMLElement)) return;
1592
+ if (event.relatedTarget instanceof Node && current.contains(event.relatedTarget)) return;
1593
+ dismissed = true;
1594
+ hide();
1595
+ }
1596
+ function onKeyDown(event) {
1597
+ if (!ARROW_KEYS.has(event.key)) return;
1598
+ dismissed = true;
1599
+ hide();
1600
+ }
1601
+ onBeforeUnmount(() => {
1602
+ release();
1603
+ if (timer != null) clearTimeout(timer);
1604
+ });
1605
+ return {
1606
+ visible,
1607
+ anchor,
1608
+ orientation,
1609
+ onFocus,
1610
+ onBlur,
1611
+ onKeyDown,
1612
+ Hint: defineComponent({
1613
+ name: "AstryxKeyboardHint",
1614
+ setup() {
1615
+ return () => h(_sfc_main, {
1616
+ visible: visible.value,
1617
+ anchor: anchor.value,
1618
+ orientation: toValue(orientation)
1619
+ });
1620
+ }
1621
+ })
1622
+ };
1623
+ }
1624
+ //#endregion
1625
+ //#region src/composables/usePanGesture.ts
1626
+ /**
1627
+ * 把 `target` 指向的元素上的拖动报成数值。`target` 可以是模板 ref、getter
1628
+ * 或元素本身。
1629
+ *
1630
+ * 元素上始终只有一个拖动手势:换了元素、或 `options` 是响应式对象且 `axis`
1631
+ * 变了,就重建;作用域销毁时拆掉。`onPan` 每次报告时才从 `options` 里读,
1632
+ * 换一个新函数不会重建手势。拖动过程中不触发组件重新渲染。正在进行的拖动遇到
1633
+ * 重建或卸载时直接结束,不再调 `onPan`。服务端渲染时不碰 DOM。
1634
+ *
1635
+ * @example
1636
+ * ```ts
1637
+ * const card = useTemplateRef<HTMLElement>('card')
1638
+ * usePanGesture(card, {
1639
+ * axis: 'x',
1640
+ * onPan: ({ state, translation }) => {
1641
+ * card.value!.style.translate = state === 'changed' ? `${translation.x}px` : ''
1642
+ * },
1643
+ * })
1644
+ * ```
1645
+ */
1646
+ function usePanGesture(target, options) {
1647
+ useAttachment(target, (element) => {
1648
+ let isForwarding = true;
1649
+ const gesture = createPanGesture(element, {
1650
+ axis: options.axis,
1651
+ onPan: (event) => {
1652
+ if (isForwarding) options.onPan(event);
1653
+ }
1654
+ });
1655
+ return () => {
1656
+ isForwarding = false;
1657
+ gesture.destroy();
1658
+ };
1659
+ }, () => options.axis);
1660
+ }
1661
+ //#endregion
1662
+ //#region src/motion/uikit/paging.ts
1663
+ /**
1664
+ * @file paging.ts
1665
+ * @input Nothing; data only
1666
+ * @output Exports `paging`, the measured constants of a paging UIScrollView,
1667
+ * and `registerPagingTable`, which registers them with the motion registry
1668
+ * @position The paging domain of the UIKit constants table (motion/uikit). Only
1669
+ * core reads it, so the `uikit` namespace does not re-export it
1670
+ */
1671
+ const paging = {
1672
+ /**
1673
+ * After the lift, one model moves the content: the settle onto the chosen
1674
+ * page and the return from an overscroll. Each display frame runs floor(frame
1675
+ * interval in ms) steps of 1 ms:
1676
+ *
1677
+ * v = (v + (target − x) · springPull) · friction; x += v (v: pt per step)
1678
+ *
1679
+ * A 60 Hz frame runs 16 steps, not 16.67. With these values, the model
1680
+ * replays eight captured releases to 0.20 pt RMS. It replays five overscroll
1681
+ * returns to 0.16–0.33 pt RMS (402 pt pages, iOS 26.2, 3× screen). Without
1682
+ * the floor, the error is 1.0 pt RMS, with a systematic shape.
1683
+ */
1684
+ integrator: {
1685
+ /**
1686
+ * Velocity added per 1 ms step, per point of distance to the target page
1687
+ * (pt per step²).
1688
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026.
1689
+ * `_pagingSpringPull` reads the same on a 402 pt paging UIScrollView and
1690
+ * on UIPageViewController's scroll view. It replays 8 captured settles to
1691
+ * 0.20 pt RMS.
1692
+ */
1693
+ springPull: 284858e-9,
1694
+ /**
1695
+ * Velocity kept per step after the pull (`_pagingFriction`, equal to
1696
+ * `_defaultPagingFriction`).
1697
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. Both read
1698
+ * the same on the two scroll views of `springPull`, and they replay with
1699
+ * it.
1700
+ */
1701
+ friction: .970815,
1702
+ /**
1703
+ * Integration steps per second: floor(16.67 ms) = 16 steps per 60 Hz frame,
1704
+ * and floor(8.33 ms) = 8 per 120 Hz frame, so 960.
1705
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. In a 60 fps
1706
+ * log of 8 releases at rest, floored stepping fits to 0.20 pt RMS.
1707
+ * Unfloored stepping fits to 1.0 pt RMS.
1708
+ */
1709
+ stepsPerSecond: 960,
1710
+ /**
1711
+ * A settle ends exactly on the page once the remaining distance is below
1712
+ * this many points and the step velocity is below `restSpeed`.
1713
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. The
1714
+ * captured settles jump the last 0.33 pt onto the page about 0.35 s after
1715
+ * a release at rest.
1716
+ */
1717
+ restDistance: .5,
1718
+ /**
1719
+ * Step velocity (pt per step) below which a settle may end.
1720
+ * @source GUESS — the captured settles end at about 0.04 pt per step;
1721
+ * the threshold is not observable more finely at 60 fps
1722
+ * @measure M-PG12
1723
+ */
1724
+ restSpeed: .05
1725
+ },
1726
+ release: {
1727
+ /**
1728
+ * Released slower than `advanceSpeed`, the scroll view settles on the page
1729
+ * nearest the content position: past half a page, the next one. The pager
1730
+ * keeps the start page instead for a release that moves back toward it.
1731
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. In releases
1732
+ * at rest from page 1, content at 48.5 % of the page stays, and 57.5 %
1733
+ * goes to the next page. On a second 402 pt pager, 45 % stays and 55 %
1734
+ * advances.
1735
+ */
1736
+ commitFraction: .5,
1737
+ /**
1738
+ * Released at least this fast (pt/s), the scroll view pages in the
1739
+ * direction of the velocity, from any content position. A flick from 6 % of
1740
+ * the page advances. The speed is UIPanGestureRecognizer's velocity at the
1741
+ * last movement, and it never decays. The scroll view's
1742
+ * `_horizontalVelocity` equals it at every sample. A drag held still for
1743
+ * 397 ms before the lift still pages at the speed it had.
1744
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. Steady
1745
+ * releases at 10, 25 and 40 % of a 402 pt page: 292.7, 295.3 and 298.6
1746
+ * pt/s stay; 310.7, 316.4 and 329.9 advance. The result is the same at
1747
+ * every position: a threshold, not a projection.
1748
+ */
1749
+ advanceSpeed: 300,
1750
+ /**
1751
+ * A settle velocity slower than this (pt/s) is zeroed, so the settle starts
1752
+ * at rest. It is paging's own tuning on the one release velocity that every
1753
+ * gesture reads.
1754
+ * @source GUESS — the middle of the measured (200, 249] bracket. In the
1755
+ * UIKit lab (iOS 26.2 simulator, Oct 23 2026),
1756
+ * `scrollViewWillEndDragging` reads 0 for steady releases at 175 and 200
1757
+ * pt/s. It reads 0.249 pt/ms for a release at 249 pt/s.
1758
+ * @measure M-PG13
1759
+ */
1760
+ velocityFloor: 225,
1761
+ /**
1762
+ * Pages a release may travel from the page the drag started on, at any
1763
+ * speed and drag distance.
1764
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A drag of
1765
+ * 1.5 pages from page 1 lands on page 2 at release speeds of 0, 600 and
1766
+ * 3000 pt/s.
1767
+ */
1768
+ maxPagesFromStart: 1
1769
+ },
1770
+ /**
1771
+ * A finger that lands on a pager settling after a swipe does not stop it at
1772
+ * once. The settle runs on for about this long, then the content holds under
1773
+ * the finger. Lifted without a move, the content settles again on the
1774
+ * nearest page.
1775
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. After
1776
+ * touch-downs 60 and 160 ms into a settle, the content moved on for 82.6
1777
+ * and 87.5 ms (5 frames), then held.
1778
+ */
1779
+ catchStopMs: 85,
1780
+ /**
1781
+ * In a sheet, a horizontal pager's pan begins only for a drag within atan(1 ÷
1782
+ * this) of horizontal (26.6° for 2). A steeper drag goes to the sheet.
1783
+ * Between 26.6° and 45°, neither moves.
1784
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A scroll
1785
+ * view's directional lock holds the major axis up to 25° and frees it from
1786
+ * 30°. An inline calendar pager in a sheet pages at 20° from horizontal. At
1787
+ * 35° and 45°, it moves neither itself nor the sheet, and it leaves 55° to
1788
+ * the sheet.
1789
+ */
1790
+ panAxisRatio: 2,
1791
+ /**
1792
+ * Inside a vertical scroll view, exactly one of the pager and the scroll view
1793
+ * takes a drag, decided once by its dominant axis. The pager takes it when
1794
+ * |dx| ≥ this × |dy|, 45° and the tie included. The scroll view takes any
1795
+ * other drag.
1796
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 24 2026. A 402 × 300
1797
+ * paging view sits in a full-screen vertical scroll view, with 150 pt drags
1798
+ * at 0–90°. The pager takes 0–45°, and the page takes 50–90°. At 35°, the
1799
+ * outer view stays at 0 through 86 pt of vertical travel. The choice
1800
+ * happens at 10–15 pt of travel.
1801
+ */
1802
+ nestedPanAxisRatio: 1,
1803
+ animatedScroll: {
1804
+ /**
1805
+ * `setContentOffset(_:animated:)` duration in milliseconds. It is the same
1806
+ * for one page and for five, as for a page control's tap.
1807
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026.
1808
+ * `_contentOffsetAnimationDuration` reads 0.3, and five animated moves of
1809
+ * 1 to 5 pages each last 0.30 s.
1810
+ */
1811
+ durationMs: 300,
1812
+ /**
1813
+ * Its curve is a sinusoidal ease-in-out: x = from + (to − from) · (1 − cos
1814
+ * πu) ÷ 2, for u = t ÷ duration. This cubic bézier matches it to 0.02 % of
1815
+ * the distance (0.09 pt over a 402 pt page).
1816
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. The five
1817
+ * moves fit the sinusoid to 0.14–0.51 pt RMS, and a 2010 pt move fits to
1818
+ * 0.20 pt. The curve easeInEaseOut (0.42, 0, 0.58, 1) misses by 7.7 pt.
1819
+ */
1820
+ curve: [
1821
+ .364212,
1822
+ 0,
1823
+ .635788,
1824
+ 1
1825
+ ]
1826
+ },
1827
+ /**
1828
+ * Past the first or last page, the content follows the finger through the
1829
+ * scroll view's rubber band (scroll.rubberBand.coefficient), with d = the
1830
+ * page width. It returns on the integrator above.
1831
+ * @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A pan of 90
1832
+ * pt past page 0 shows 42.7–45 pt, and 290 pt shows 114.3 pt. The formula
1833
+ * gives 44.1 and 114.2, with c 0.55 and d 402. The return replays on the
1834
+ * integrator to 0.16–0.33 pt RMS.
1835
+ */
1836
+ rubberBandDimension: "pageWidth"
1837
+ };
1838
+ /**
1839
+ * Registers this table with the motion registry (motion/roles.ts). The pager
1840
+ * then reads `setContentOffset(_:animated:)`'s duration and curve through
1841
+ * `resolveMotion`, as it reads every touch motion. The table lists no role,
1842
+ * because no motion role names any of its values, so each plays as measured.
1843
+ * A page that plays no paging motion ships no paging registry. The module
1844
+ * registers its own table at import (one idempotent in-memory write, no DOM).
1845
+ */
1846
+ function registerPagingTable() {
1847
+ registerMotionTable("paging", paging, { exclude: ["catchStopMs"] });
1848
+ }
1849
+ registerPagingTable();
1850
+ //#endregion
1851
+ //#region src/gestures/LongPressGestureRecognizer.ts
1852
+ var LongPressGestureRecognizer = class extends GestureRecognizer {
1853
+ get kind() {
1854
+ return "longPress";
1855
+ }
1856
+ /** Internal. The host's brand: a long press keeps the callout and selection off (recognizerInternals). */
1857
+ get family() {
1858
+ return "longPress";
1859
+ }
1860
+ minimumPressDuration;
1861
+ allowableMovement;
1862
+ numberOfTapsRequired;
1863
+ numberOfTouchesRequired;
1864
+ tapsDone = 0;
1865
+ /** The taps phase's current tap: when it landed and its most fingers. */
1866
+ tapStartedAt = null;
1867
+ tapMostTouches = 0;
1868
+ isPressTimerArmed = false;
1869
+ /** When the gesture began, on the event clock. */
1870
+ beganAt = null;
1871
+ constructor(options = {}) {
1872
+ super({
1873
+ ...options,
1874
+ selectionLock: options.selectionLock !== void 0 ? options.selectionLock : (options.minimumPressDuration ?? UIKIT_LONG_PRESS.minimumPressDuration.value) > 0 ? lockSelection : null
1875
+ });
1876
+ this.minimumPressDuration = options.minimumPressDuration ?? UIKIT_LONG_PRESS.minimumPressDuration.value;
1877
+ this.allowableMovement = options.allowableMovement ?? UIKIT_LONG_PRESS.allowableMovement.value;
1878
+ this.numberOfTapsRequired = options.numberOfTapsRequired ?? 0;
1879
+ this.numberOfTouchesRequired = options.numberOfTouchesRequired ?? 1;
1880
+ }
1881
+ isInvolved() {
1882
+ return super.isInvolved() || this.tapsDone > 0;
1883
+ }
1884
+ get nativeTouchBehavior() {
1885
+ return MANIPULATION;
1886
+ }
1887
+ acceptsTouch(touch) {
1888
+ if (isActive(this.state)) return false;
1889
+ return super.acceptsTouch(touch);
1890
+ }
1891
+ touchesBegan(_touches, event) {
1892
+ if (this.numberOfTouches > this.numberOfTouchesRequired) {
1893
+ this.setState("failed");
1894
+ return;
1895
+ }
1896
+ if (this.tapsDone > 0) this.clearTimer();
1897
+ if (this.tapsDone < this.numberOfTapsRequired) {
1898
+ this.tapStartedAt ??= event.time;
1899
+ this.tapMostTouches = Math.max(this.tapMostTouches, this.numberOfTouches);
1900
+ }
1901
+ if (this.numberOfTouches === this.numberOfTouchesRequired && this.tapsDone >= this.numberOfTapsRequired) {
1902
+ if (this.minimumPressDuration <= 0) {
1903
+ this.beganAt = event.time;
1904
+ this.setState("began");
1905
+ return;
1906
+ }
1907
+ this.isPressTimerArmed = true;
1908
+ this.setTimer(event.time + this.minimumPressDuration, () => {
1909
+ this.isPressTimerArmed = false;
1910
+ if (this.state === "possible" && this.numberOfTouches === this.numberOfTouchesRequired) {
1911
+ this.beganAt = this.now();
1912
+ this.setState("began");
1913
+ }
1914
+ });
1915
+ }
1916
+ }
1917
+ touchesMoved(touches) {
1918
+ if (this.state === "possible") {
1919
+ if (touches.some((touch) => travel(touch) > this.allowableMovement)) this.setState("failed");
1920
+ return;
1921
+ }
1922
+ if (isActive(this.state)) this.setState("changed");
1923
+ }
1924
+ touchesEnded(touches, event) {
1925
+ if (isActive(this.state)) {
1926
+ this.setState("ended");
1927
+ return;
1928
+ }
1929
+ if (this.isPressTimerArmed || this.tapsDone >= this.numberOfTapsRequired) {
1930
+ this.setState("failed");
1931
+ return;
1932
+ }
1933
+ if (this.numberOfTouches - touches.length > 0) return;
1934
+ const heldFor = event.time - (this.tapStartedAt ?? event.time);
1935
+ const fingers = this.tapMostTouches;
1936
+ this.tapStartedAt = null;
1937
+ this.tapMostTouches = 0;
1938
+ if (heldFor > UIKIT_TAP.maximumTapDuration.value || fingers !== this.numberOfTouchesRequired) {
1939
+ this.setState("failed");
1940
+ return;
1941
+ }
1942
+ this.tapsDone += 1;
1943
+ this.setTimer(event.time + UIKIT_TAP.maximumIntervalBetweenTaps.value, () => {
1944
+ this.setState("failed");
1945
+ });
1946
+ }
1947
+ reset() {
1948
+ this.tapsDone = 0;
1949
+ this.tapStartedAt = null;
1950
+ this.tapMostTouches = 0;
1951
+ this.isPressTimerArmed = false;
1952
+ this.beganAt = null;
1953
+ }
1954
+ };
1955
+ //#endregion
1956
+ //#region src/composables/internal/snapPagingCatcher.ts
1957
+ /**
1958
+ * 翻页途中「接住」这一行的识别器:一个零时长、不认领触摸的长按。它从不认领
1959
+ * 触摸,所以从正在翻页的这一行上开始的竖向滑动或双指捏合仍然归页面,和 UIKit
1960
+ * 里分页视图停住后把竖向拖动交给外层滚动视图一样。它只记下按下来的是哪种指针,
1961
+ * 并提供一个按事件时钟走的接住计时器和「不让内容收到这次触摸」两件事。
1962
+ */
1963
+ var SettleCatcher = class extends LongPressGestureRecognizer {
1964
+ /** 按下来接住这一行的指针种类。 */
1965
+ pointerType = null;
1966
+ get claimsTouches() {
1967
+ return false;
1968
+ }
1969
+ /**
1970
+ * 触摸后 `ms` 毫秒(按事件时钟)调用 `callback`,触摸先结束就不调。仲裁会在
1971
+ * 任何更晚的输入之前跑它,所以页面忙、按下和抬起一起到时,它仍然先跑。
1972
+ * 零时长、不认点按次数的长按不占用自己唯一的仲裁计时器,正好拿来用。
1973
+ */
1974
+ armCatch(ms, callback) {
1975
+ this.setTimer((this.beganAt ?? this.now()) + ms, callback);
1976
+ }
1977
+ /** 取消 `armCatch` 设下、还没跑的接住。 */
1978
+ disarmCatch() {
1979
+ this.clearTimer();
1980
+ }
1981
+ /** 把这次触摸从下面的内容那里拿走:不按下、不点击。UIKit 里停住滚动视图的那次触摸也到不了内容。 */
1982
+ takeFromContent() {
1983
+ this.cancelTouchesInView();
1984
+ }
1985
+ touchesBegan(touches, event) {
1986
+ if (this.state === "possible" && touches.length > 0) this.pointerType = touches[0].pointerType;
1987
+ super.touchesBegan(touches, event);
1988
+ }
1989
+ };
1990
+ //#endregion
1991
+ //#region src/composables/internal/snapPagingMotion.ts
1992
+ const browserClock = {
1993
+ now: () => performance.now(),
1994
+ frame: (callback) => requestAnimationFrame(() => callback()),
1995
+ cancel: (handle) => cancelAnimationFrame(handle)
1996
+ };
1997
+ /** 下标列表里离 `to` 最近的那一个。 */
1998
+ function nearestIndex(stops, to) {
1999
+ let best = 0;
2000
+ for (let i = 1; i < stops.length; i++) if (Math.abs(stops[i] - to) < Math.abs(stops[best] - to)) best = i;
2001
+ return best;
2002
+ }
2003
+ /**
2004
+ * 从第 `anchor` 个停点算起的「一屏一页」:每一页落在离上一页一屏远最近的停点上,
2005
+ * 并且至少往前走一个停点。
2006
+ */
2007
+ function viewPages(stops, anchor, width) {
2008
+ const pages = [stops[anchor]];
2009
+ for (let i = anchor; i < stops.length - 1;) {
2010
+ i = Math.max(nearestIndex(stops, stops[i] + width), i + 1);
2011
+ pages.push(stops[i]);
2012
+ }
2013
+ for (let i = anchor; i > 0;) {
2014
+ i = Math.min(nearestIndex(stops, stops[i] - width), i - 1);
2015
+ pages.unshift(stops[i]);
2016
+ }
2017
+ return pages;
2018
+ }
2019
+ /** 松手后按这个时长(秒)把速度投出去,再找离投点最近的一页。 */
2020
+ const PROJECTION_SECONDS = .1;
2021
+ /**
2022
+ * 松手时停在哪一页:轻扫至少翻到运动方向上的下一页,慢慢松手就停在投点最近的一页。
2023
+ * 不论多快,离起手那一页(`anchor`)最多一页。返回页的下标。
2024
+ */
2025
+ function pickPage(pages, at, velocity, anchor) {
2026
+ let index = nearestIndex(pages, at + velocity * PROJECTION_SECONDS);
2027
+ if (velocity >= 300) {
2028
+ const ahead = pages.findIndex((page) => page > at + .5);
2029
+ if (ahead !== -1) index = Math.max(index, ahead);
2030
+ } else if (velocity <= -300) {
2031
+ let behind = -1;
2032
+ for (let i = pages.length - 1; i >= 0; i--) if (pages[i] < at - .5) {
2033
+ behind = i;
2034
+ break;
2035
+ }
2036
+ if (behind !== -1) index = Math.min(index, behind);
2037
+ }
2038
+ return Math.min(Math.max(index, anchor - 1, 0), anchor + 1, pages.length - 1);
2039
+ }
2040
+ /** 弹簧的固有角频率:大约 0.4 秒走完一页,接近 UIKit 翻页的手感。 */
2041
+ const SPRING_OMEGA = 2 * Math.PI / .4;
2042
+ /** 轻扫很快时弹簧可以收得更紧,但不超过这个角频率。 */
2043
+ const MAX_OMEGA = 60;
2044
+ const REST_DISTANCE = .5;
2045
+ const REST_VELOCITY = 20;
2046
+ /**
2047
+ * 用临界阻尼弹簧把位置从 `from` 带到 `to`,带着初速度 `velocity`(像素每秒)。
2048
+ * 每一帧调用 `onFrame`,停稳后最后一次给出 `to` 并调用 `onRest`。
2049
+ */
2050
+ function springTo(clock, from, to, velocity, onFrame, onRest) {
2051
+ const start = clock.now();
2052
+ const offset0 = from - to;
2053
+ const toward = offset0 === 0 ? 0 : -velocity * Math.sign(offset0);
2054
+ const omega = Math.max(SPRING_OMEGA, Math.min(MAX_OMEGA, toward / Math.max(Math.abs(offset0), 1e-6)));
2055
+ let handle = 0;
2056
+ let stopped = false;
2057
+ function state(time) {
2058
+ const t = Math.max(0, time - start) / 1e3;
2059
+ const decay = Math.exp(-omega * t);
2060
+ const b = velocity + omega * offset0;
2061
+ return {
2062
+ offset: (offset0 + b * t) * decay,
2063
+ velocity: (b - omega * (offset0 + b * t)) * decay
2064
+ };
2065
+ }
2066
+ function tick() {
2067
+ if (stopped) return;
2068
+ const now = state(clock.now());
2069
+ if (Math.abs(now.offset) < REST_DISTANCE && Math.abs(now.velocity) < REST_VELOCITY) {
2070
+ stopped = true;
2071
+ onFrame(to);
2072
+ onRest();
2073
+ return;
2074
+ }
2075
+ onFrame(to + now.offset);
2076
+ handle = clock.frame(tick);
2077
+ }
2078
+ handle = clock.frame(tick);
2079
+ return {
2080
+ target: to,
2081
+ velocity: () => stopped ? 0 : state(clock.now()).velocity,
2082
+ stop() {
2083
+ stopped = true;
2084
+ clock.cancel(handle);
2085
+ }
2086
+ };
2087
+ }
2088
+ //#endregion
2089
+ //#region src/composables/internal/snapPagingSkip.ts
2090
+ /**
2091
+ * 原生吸附要跳过末端那一页吞掉的项(见 `snapPages`),这样滚轮、方向键和
2092
+ * 普通滚动也停在和轻扫同样的页上。被跳过的项交还时恢复自己原来的行内值。
2093
+ * 停点随尺寸和子项变化,最多一帧算一次;分页按住这一行时,等交还时再写。
2094
+ */
2095
+ function followSkippedStops(element, track) {
2096
+ const skipped = /* @__PURE__ */ new Map();
2097
+ let frame = null;
2098
+ let isDue = false;
2099
+ function restore(item, own) {
2100
+ if (own.value === "") item.style.removeProperty("scroll-snap-align");
2101
+ else item.style.setProperty("scroll-snap-align", own.value, own.priority);
2102
+ }
2103
+ function skip(items) {
2104
+ for (const [item, own] of skipped) if (!items.includes(item)) {
2105
+ skipped.delete(item);
2106
+ restore(item, own);
2107
+ }
2108
+ for (const item of items) if (item instanceof HTMLElement && !skipped.has(item)) {
2109
+ skipped.set(item, {
2110
+ value: item.style.getPropertyValue("scroll-snap-align"),
2111
+ priority: item.style.getPropertyPriority("scroll-snap-align")
2112
+ });
2113
+ item.style.setProperty("scroll-snap-align", "none");
2114
+ }
2115
+ }
2116
+ function apply() {
2117
+ isDue = false;
2118
+ skip(track.pages().skipped);
2119
+ }
2120
+ function schedule() {
2121
+ if (track.isHeld()) {
2122
+ isDue = true;
2123
+ return;
2124
+ }
2125
+ if (frame != null || typeof requestAnimationFrame !== "function") return;
2126
+ frame = requestAnimationFrame(() => {
2127
+ frame = null;
2128
+ if (track.isHeld()) isDue = true;
2129
+ else apply();
2130
+ });
2131
+ }
2132
+ const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
2133
+ function observeItems() {
2134
+ if (resize == null) return;
2135
+ resize.disconnect();
2136
+ resize.observe(element);
2137
+ for (const item of Array.from(element.children)) resize.observe(item);
2138
+ }
2139
+ const mutations = typeof MutationObserver === "undefined" ? null : new MutationObserver(() => {
2140
+ observeItems();
2141
+ schedule();
2142
+ });
2143
+ mutations?.observe(element, { childList: true });
2144
+ observeItems();
2145
+ schedule();
2146
+ return {
2147
+ takeDue: () => isDue ? apply : void 0,
2148
+ stop() {
2149
+ mutations?.disconnect();
2150
+ resize?.disconnect();
2151
+ if (frame != null) cancelAnimationFrame(frame);
2152
+ frame = null;
2153
+ skip([]);
2154
+ }
2155
+ };
2156
+ }
2157
+ //#endregion
2158
+ //#region src/composables/internal/snapPagingTrack.ts
2159
+ function createSnapTrack(element, onHeld) {
2160
+ let held = false;
2161
+ let heldAt = 0;
2162
+ let heldTravel = 0;
2163
+ let sign = 1;
2164
+ let ownSnapType = "";
2165
+ let ownSnapPriority = "";
2166
+ const isRtl = () => getComputedStyle(element).direction === "rtl";
2167
+ const nativeTravel = () => Math.max(0, element.scrollWidth - element.clientWidth);
2168
+ const position = () => held ? heldAt : Math.abs(element.scrollLeft);
2169
+ const travel = () => held ? heldTravel : nativeTravel();
2170
+ function write(at) {
2171
+ element.scrollTo({
2172
+ left: sign * at,
2173
+ behavior: "instant"
2174
+ });
2175
+ }
2176
+ function report() {
2177
+ onHeld?.({
2178
+ offset: heldAt,
2179
+ travel: heldTravel
2180
+ });
2181
+ }
2182
+ return {
2183
+ isHeld: () => held,
2184
+ position,
2185
+ travel,
2186
+ pages: () => snapPages(element, position(), travel()),
2187
+ viewWidth() {
2188
+ const style = getComputedStyle(element);
2189
+ const padding = (Number.parseFloat(style.scrollPaddingLeft) || 0) + (Number.parseFloat(style.scrollPaddingRight) || 0);
2190
+ return Math.max(1, element.clientWidth - padding);
2191
+ },
2192
+ takeOver() {
2193
+ if (held) return;
2194
+ sign = isRtl() ? -1 : 1;
2195
+ heldAt = Math.abs(element.scrollLeft);
2196
+ heldTravel = nativeTravel();
2197
+ ownSnapType = element.style.getPropertyValue("scroll-snap-type");
2198
+ ownSnapPriority = element.style.getPropertyPriority("scroll-snap-type");
2199
+ element.style.setProperty("scroll-snap-type", "none");
2200
+ held = true;
2201
+ report();
2202
+ },
2203
+ place(at) {
2204
+ if (!held) return;
2205
+ heldAt = Math.min(Math.max(at, 0), heldTravel);
2206
+ write(heldAt);
2207
+ report();
2208
+ },
2209
+ remeasure() {
2210
+ if (!held) return;
2211
+ const next = nativeTravel();
2212
+ if (next === heldTravel) return;
2213
+ heldTravel = next;
2214
+ if (heldAt > heldTravel) {
2215
+ heldAt = heldTravel;
2216
+ write(heldAt);
2217
+ }
2218
+ report();
2219
+ },
2220
+ handBack(beforeSnap) {
2221
+ if (!held) return;
2222
+ held = false;
2223
+ beforeSnap?.();
2224
+ if (ownSnapType === "") element.style.removeProperty("scroll-snap-type");
2225
+ else element.style.setProperty("scroll-snap-type", ownSnapType, ownSnapPriority);
2226
+ write(heldAt);
2227
+ if (onHeld != null) {
2228
+ onHeld({
2229
+ offset: heldAt,
2230
+ travel: heldTravel
2231
+ });
2232
+ onHeld(null);
2233
+ }
2234
+ }
2235
+ };
2236
+ }
2237
+ //#endregion
2238
+ //#region src/composables/internal/snapPagingAttach.ts
2239
+ function prefersReducedMotion() {
2240
+ return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
2241
+ }
2242
+ /**
2243
+ * 把吸附分页挂到滚动行上。拖动走手势引擎:一个横向的拖动识别器接手指、触控笔和
2244
+ * 触控板横扫,过了 UIKit 的 10pt 起拖距离才接管这一行,松手速度由识别器的
2245
+ * VelocityTracker 给出;鼠标拖动和鼠标滚轮留给原生滚动。另有一个不认领触摸的
2246
+ * 「接住」识别器:翻页途中按上去就停住这一行。
2247
+ *
2248
+ * - 松手后的翻页:按下后这一行再走 `paging.catchStopMs` 才停住,和 UIKit 实测一致;
2249
+ * 手指或触控笔的这次触摸到不了下面的内容,鼠标保留它的点击。
2250
+ * - 按钮、方向键、`scrollTo` 这类程序发起的翻页:手指一碰就停住。鼠标仍然等那一段。
2251
+ * - 停住后不拖、直接抬起:停到最近的一页。停住之前就抬起:翻页照常走完。
2252
+ */
2253
+ function attachPaging(element, options, onHeld, clock = browserClock) {
2254
+ const track = createSnapTrack(element, onHeld);
2255
+ const skip = followSkippedStops(element, track);
2256
+ let pages = [0];
2257
+ let anchor = 0;
2258
+ let sign = 1;
2259
+ let motion = null;
2260
+ let isReleaseSettle = false;
2261
+ let drag = null;
2262
+ let isCaught = false;
2263
+ let isCatchArmed = false;
2264
+ let releaseSelection = null;
2265
+ let isAttached = true;
2266
+ function hold() {
2267
+ motion?.stop();
2268
+ motion = null;
2269
+ track.takeOver();
2270
+ sign = getComputedStyle(element).direction === "rtl" ? -1 : 1;
2271
+ const at = track.position();
2272
+ const { stops } = track.pages();
2273
+ pages = (options().pages ?? "view") === "item" ? stops : viewPages(stops, nearestIndex(stops, at), track.viewWidth());
2274
+ anchor = nearestIndex(pages, at);
2275
+ }
2276
+ function finish() {
2277
+ if (drag != null || isCaught) return;
2278
+ track.handBack(skip.takeDue());
2279
+ }
2280
+ function settleTo(target, velocity, fromRelease) {
2281
+ motion?.stop();
2282
+ motion = null;
2283
+ isReleaseSettle = fromRelease;
2284
+ if (prefersReducedMotion()) {
2285
+ track.place(target);
2286
+ finish();
2287
+ return;
2288
+ }
2289
+ motion = springTo(clock, track.position(), target, velocity, (at) => track.place(at), () => {
2290
+ motion = null;
2291
+ finish();
2292
+ });
2293
+ }
2294
+ function release(velocity) {
2295
+ const at = track.position();
2296
+ settleTo(pages[pickPage(pages, at, velocity, anchor)] ?? at, velocity, true);
2297
+ }
2298
+ const host = getGestureHost(element.ownerDocument);
2299
+ const pan = new PanGestureRecognizer({
2300
+ name: "snapPaging",
2301
+ direction: "horizontal",
2302
+ allowedPointerTypes: ["touch", "pen"],
2303
+ allowedScrollTypes: ["continuous"],
2304
+ shouldBegin: () => track.isHeld() || track.travel() > 1
2305
+ });
2306
+ const catcher = new SettleCatcher({
2307
+ name: "snapPagingCatch",
2308
+ minimumPressDuration: 0,
2309
+ allowableMovement: Number.POSITIVE_INFINITY,
2310
+ selectionLock: null,
2311
+ shouldBegin: () => motion != null && drag == null
2312
+ });
2313
+ catcher.recognizeSimultaneouslyWith(pan);
2314
+ function holdSelection(on) {
2315
+ if (on && releaseSelection == null && locksSelectionFor(catcher.pointerType ?? "touch")) releaseSelection = lockSelection([element], null);
2316
+ else if (!on && releaseSelection != null) {
2317
+ releaseSelection();
2318
+ releaseSelection = null;
2319
+ }
2320
+ }
2321
+ function clearCatchTimer() {
2322
+ if (isCatchArmed) {
2323
+ isCatchArmed = false;
2324
+ catcher.disarmCatch();
2325
+ }
2326
+ }
2327
+ function catchSettle() {
2328
+ if (motion == null || drag != null) return;
2329
+ hold();
2330
+ isCaught = true;
2331
+ }
2332
+ pan.addListener(() => {
2333
+ if (!isAttached) return;
2334
+ const state = pan.state;
2335
+ if (state === "began") {
2336
+ clearCatchTimer();
2337
+ hold();
2338
+ drag = {
2339
+ from: track.position(),
2340
+ isScroll: pan.trackedTouches[0]?.scrollType != null
2341
+ };
2342
+ }
2343
+ if (drag == null) return;
2344
+ if (state === "began" || state === "changed") {
2345
+ let at = drag.from - sign * pan.translation().x;
2346
+ if (drag.isScroll) {
2347
+ const low = pages[anchor - 1] ?? pages[0] ?? 0;
2348
+ const high = pages[anchor + 1] ?? pages[pages.length - 1] ?? 0;
2349
+ at = Math.min(Math.max(at, low), high);
2350
+ }
2351
+ host.ownScroll(element);
2352
+ track.place(at);
2353
+ return;
2354
+ }
2355
+ if (state === "ended" || state === "cancelled") {
2356
+ drag = null;
2357
+ isCaught = false;
2358
+ release(state === "ended" ? -sign * pan.velocity().x : 0);
2359
+ }
2360
+ });
2361
+ catcher.addListener(() => {
2362
+ if (!isAttached) return;
2363
+ const state = catcher.state;
2364
+ if (state === "began") {
2365
+ holdSelection(true);
2366
+ const isMouse = catcher.pointerType === "mouse";
2367
+ if (isReleaseSettle && !isMouse) catcher.takeFromContent();
2368
+ clearCatchTimer();
2369
+ isCaught = false;
2370
+ if (!isReleaseSettle && !isMouse) {
2371
+ catchSettle();
2372
+ return;
2373
+ }
2374
+ isCatchArmed = true;
2375
+ catcher.armCatch(paging.catchStopMs, () => {
2376
+ if (!isCatchArmed) return;
2377
+ isCatchArmed = false;
2378
+ catchSettle();
2379
+ });
2380
+ return;
2381
+ }
2382
+ if (state === "ended" || state === "cancelled") {
2383
+ holdSelection(false);
2384
+ if (isCatchArmed) {
2385
+ clearCatchTimer();
2386
+ return;
2387
+ }
2388
+ const wasCaught = isCaught;
2389
+ isCaught = false;
2390
+ if (wasCaught && drag == null && motion == null) release(0);
2391
+ }
2392
+ });
2393
+ const detachPan = host.attach(element, pan);
2394
+ const detachCatch = host.attach(element, catcher);
2395
+ const remeasure = () => track.remeasure();
2396
+ const unobserveSizes = [element, ...Array.from(element.children)].map((node) => observeResize(node, remeasure));
2397
+ function move(target) {
2398
+ if (drag != null && !drag.isScroll) return;
2399
+ drag = null;
2400
+ const velocity = motion?.velocity() ?? 0;
2401
+ hold();
2402
+ const end = track.travel();
2403
+ settleTo(Math.min(Math.max(target(track.position(), end), 0), end), velocity, false);
2404
+ }
2405
+ return {
2406
+ detach() {
2407
+ isAttached = false;
2408
+ clearCatchTimer();
2409
+ holdSelection(false);
2410
+ detachCatch();
2411
+ detachPan();
2412
+ for (const unobserve of unobserveSizes) unobserve();
2413
+ motion?.stop();
2414
+ motion = null;
2415
+ drag = null;
2416
+ isCaught = false;
2417
+ track.handBack();
2418
+ skip.stop();
2419
+ },
2420
+ move,
2421
+ moveHeld(target) {
2422
+ if (!track.isHeld()) return false;
2423
+ move(target);
2424
+ return true;
2425
+ }
2426
+ };
2427
+ }
2428
+ //#endregion
2429
+ //#region src/composables/useSnapPaging.ts
2430
+ /**
2431
+ * 给 Carousel 的吸附停点加上 iOS 式翻页:`<Carousel :has-snap="paging">`,
2432
+ * 其中 `const paging = useSnapPaging()`。手指或触控板横扫时,一次轻扫翻一屏,
2433
+ * 传 `{ pages: 'item' }` 时翻一项,停在某一项的起始边。鼠标滚轮和鼠标拖动保持原生滚动。
2434
+ *
2435
+ * `options` 可以是 ref 或 getter,新的 `pages` 从下一次轻扫开始生效。
2436
+ * Carousel 一直用它第一次挂上的那个值。
2437
+ */
2438
+ function useSnapPaging(options = {}) {
2439
+ return makeSnapPaging((element, onHeld) => attachPaging(element, () => toValue(options), onHeld));
2440
+ }
2441
+ //#endregion
2442
+ //#region src/composables/useStreamingText.ts
2443
+ const CHARS_PER_TICK = {
2444
+ natural: 10,
2445
+ fast: 4,
2446
+ instant: Number.POSITIVE_INFINITY
2447
+ };
2448
+ const FALLBACK_DURATION_MS = 95;
2449
+ function parseCssDuration(value) {
2450
+ const milliseconds = /^([\d.]+)ms$/.exec(value.trim());
2451
+ if (milliseconds?.[1] != null) return Number(milliseconds[1]);
2452
+ const seconds = /^([\d.]+)s$/.exec(value.trim());
2453
+ if (seconds?.[1] != null) return Number(seconds[1]) * 1e3;
2454
+ return null;
2455
+ }
2456
+ function motionDuration() {
2457
+ if (typeof document === "undefined") return FALLBACK_DURATION_MS;
2458
+ return parseCssDuration(getComputedStyle(document.documentElement).getPropertyValue("--astryx-duration-fast-min")) ?? FALLBACK_DURATION_MS;
2459
+ }
2460
+ function tickInterval(speed) {
2461
+ if (speed === "instant") return 0;
2462
+ const duration = motionDuration();
2463
+ const tick = speed === "fast" ? duration / 20 : duration / 10;
2464
+ return Math.max(4, Math.round(tick));
2465
+ }
2466
+ const graphemeSegmenter = typeof Intl.Segmenter === "function" ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
2467
+ function isLowSurrogate(codeUnit) {
2468
+ return codeUnit >= 56320 && codeUnit <= 57343;
2469
+ }
2470
+ /**
2471
+ * Move `offset` back to the start of the grapheme it lands inside, so a slice
2472
+ * never cuts a surrogate pair, a flag, or a ZWJ sequence in half.
2473
+ */
2474
+ function snapToGraphemeBoundary(text, offset) {
2475
+ if (offset <= 0 || offset >= text.length) return offset;
2476
+ if (graphemeSegmenter != null) return graphemeSegmenter.segment(text).containing(offset)?.index ?? offset;
2477
+ return isLowSurrogate(text.charCodeAt(offset)) ? offset - 1 : offset;
2478
+ }
2479
+ /**
2480
+ * Smooth a burst of streamed text into a steady reveal.
2481
+ * While `isStreaming` is false, or the user prefers reduced motion, the full
2482
+ * source is returned. The reveal steps by UTF-16 units and then snaps back to
2483
+ * a grapheme boundary.
2484
+ */
2485
+ function useStreamingText(targetText, isStreaming = false, options) {
2486
+ const displayedLen = ref(0);
2487
+ const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
2488
+ const target = computed(() => toValue(targetText));
2489
+ const streaming = computed(() => toValue(isStreaming));
2490
+ const speed = computed(() => toValue(options)?.speed ?? "natural");
2491
+ const instant = computed(() => !streaming.value || speed.value === "instant" || prefersReducedMotion.value);
2492
+ watch(target, (next, previous) => {
2493
+ const revealed = (previous ?? "").slice(0, displayedLen.value);
2494
+ if (next.length === 0 || revealed.length > 0 && !next.startsWith(revealed)) displayedLen.value = 0;
2495
+ });
2496
+ watch(streaming, (next) => {
2497
+ if (!next) displayedLen.value = target.value.length;
2498
+ });
2499
+ watch(instant, (isInstant, _, onCleanup) => {
2500
+ if (isInstant) return;
2501
+ let frame = 0;
2502
+ let lastTick = 0;
2503
+ const tick = (now) => {
2504
+ const interval = tickInterval(speed.value);
2505
+ if (now - lastTick >= interval) {
2506
+ lastTick = now;
2507
+ const goal = target.value.length;
2508
+ if (displayedLen.value < goal) {
2509
+ const step = CHARS_PER_TICK[speed.value];
2510
+ displayedLen.value = Math.min(displayedLen.value + step, goal);
2511
+ }
2512
+ }
2513
+ frame = requestAnimationFrame(tick);
2514
+ };
2515
+ frame = requestAnimationFrame(tick);
2516
+ onCleanup(() => cancelAnimationFrame(frame));
2517
+ }, { immediate: true });
2518
+ return computed(() => {
2519
+ const text = target.value;
2520
+ if (instant.value) return text;
2521
+ return text.slice(0, snapToGraphemeBoundary(text, displayedLen.value));
2522
+ });
2523
+ }
2524
+ //#endregion
2525
+ //#region src/composables/useTouchTrigger.ts
2526
+ /**
2527
+ * 悬停类浮层(Tooltip、HoverCard)共用的触屏行为。
2528
+ *
2529
+ * 触屏上表达不了「悬停」:点一下会合成 `mouseenter`,不处理的悬停浮层要么
2530
+ * 每次点都弹出来、又没有东西能关掉它,要么把用户点控件的这一下吃掉。
2531
+ *
2532
+ * 一次触屏按压要等它成了轻点才算数。手指落在触发器上可能是开始滚动、缩放或长按,
2533
+ * 只有浏览器在手指挪动或抬起后才知道是哪个,它的 click 就是结论。所以从触发器上开始的
2534
+ * 滚动不会打开提示,停着不动的手指也不会。点开的浮层在外面轻点抬起时关,
2535
+ * 或在外面开始的滚动被浏览器接走时关,和 iOS 关闭弹出框的时机一样。
2536
+ */
2537
+ function useTouchTrigger(options) {
2538
+ const touch = useTouchTriggerInternal(options);
2539
+ return {
2540
+ isTouchPointer: touch.isTouchPointer,
2541
+ isTouchInteraction: touch.isTouchInteraction,
2542
+ handlePointerEnter: touch.handlePointerEnter,
2543
+ handlePointerDown: touch.handlePointerDown,
2544
+ clearTapOpen: touch.clearTapOpen
2545
+ };
2546
+ }
2547
+ //#endregion
2548
+ export { useAnimator as _, usePanGesture as a, createAnimator as b, imageModeFromPixels as c, useGridRovingFocus as d, useGridFocus as f, useContainerReveal as g, useControllableState as h, useSnapPaging as i, perceptualLightness as l, useDragToSnapPoints as m, snapToGraphemeBoundary as n, useKeyboardHint as o, useEntryAnimation as p, useStreamingText as r, useIndicatorFocusRing as s, useTouchTrigger as t, useImageMode as u, createDragToSnapPoints as v, createPanGesture as y };