@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.
- package/dist/AlertDialog/index.js +1 -1
- package/dist/{AlertDialog-D_lrpZz_.js → AlertDialog-B_p1yL3k.js} +7 -7
- package/dist/AppShell/index.js +1 -1
- package/dist/{AppShell-CxUmt6hX.js → AppShell-D3KZSLvb.js} +5 -5
- package/dist/AvatarGroup/index.d.ts +1 -1
- package/dist/AvatarGroup/index.js +1 -1
- package/dist/{AvatarGroup-DT5RbxDa.js → AvatarGroup-Dd-yDDNz.js} +2 -2
- package/dist/Banner/index.d.ts +1 -1
- package/dist/Banner/index.js +1 -1
- package/dist/{Banner-Ctg1puM6.js → Banner-DKmvoMxD.js} +1 -1
- package/dist/BottomSheet/index.d.ts +1 -1
- package/dist/BottomSheet/index.js +2 -2
- package/dist/{BottomSheet-CmNOXlZO.js → BottomSheet-Btf8Yn8k.js} +845 -276
- package/dist/{BottomSheet-_K41Oliv.js → BottomSheet-CQGtoh2x.js} +1 -1
- package/dist/Breadcrumbs/index.js +2 -2
- package/dist/{Breadcrumbs-CdGqhFKU.js → Breadcrumbs-D6825HQI.js} +1 -1
- package/dist/Button/index.js +1 -1
- package/dist/{Button-CvHeZGf1.js → Button-DdPty46q.js} +2 -2
- package/dist/ButtonGroup/index.d.ts +1 -1
- package/dist/ButtonGroup/index.js +1 -1
- package/dist/{ButtonGroup-CUN_rC57.js → ButtonGroup-oI99JAyN.js} +3 -3
- package/dist/Calendar/index.d.ts +1 -1
- package/dist/Carousel/index.d.ts +1 -1
- package/dist/Carousel/index.js +1 -1
- package/dist/{Carousel-CbdHb8MD.js → Carousel-BNr79JpP.js} +1 -1
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.js +1 -1
- package/dist/{Chat-B7ccEmTR.js → Chat-BadS0fEx.js} +2 -2
- package/dist/CheckboxInput/index.d.ts +1 -1
- package/dist/CheckboxInput/index.js +1 -1
- package/dist/{CheckboxInput-5r6VWqId.js → CheckboxInput-CzP8gP3v.js} +3 -3
- package/dist/CheckboxList/index.d.ts +1 -1
- package/dist/CheckboxList/index.js +1 -1
- package/dist/{CheckboxListItem-CKeQzQ0W.js → CheckboxListItem-CxBjpX3d.js} +4 -4
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/ClickableCard/index.js +1 -1
- package/dist/{ClickableCard-ChmOwgYq.js → ClickableCard-B86P2aiM.js} +1 -1
- package/dist/Code/index.js +1 -1
- package/dist/{CodeBlock-4i1vvmOc.js → CodeBlock-Cgm4uOhG.js} +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-B2vrr_YP.js → Collapsible-CfTN722D.js} +3 -3
- package/dist/CommandPalette/index.d.ts +1 -1
- package/dist/CommandPalette/index.js +1 -1
- package/dist/{CommandPalette-BMwvTjff.js → CommandPalette-BgVwGtdA.js} +2 -2
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-B4iFyilD.js → ComplexSelector-DqWJVx7H.js} +2 -2
- package/dist/ContextMenu/index.d.ts +1 -1
- package/dist/ContextMenu/index.js +2 -2
- package/dist/{ContextMenu-DquYeIEF.js → ContextMenu-C9dJGu3M.js} +3 -3
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/{DateInput-MNNyi4XK.js → DateInput-CGKaozkw.js} +3 -3
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/{DateRangeInput-DOHntScL.js → DateRangeInput-BVHXgzXz.js} +3 -3
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-BaghFHW6.js → DateTimeInput-DRm3lekJ.js} +5 -5
- package/dist/Dialog/index.js +3 -3
- package/dist/{Dialog-Ctha_b_L.js → Dialog-BN-NycQr.js} +1 -1
- package/dist/{Dialog-CGf64DqF.js → Dialog-Dt0gNuMT.js} +1 -1
- package/dist/{DialogHeader-BxTV37GT.js → DialogHeader-CSH2_5v-.js} +2 -2
- package/dist/Drawer/index.d.ts +1 -1
- package/dist/Drawer/index.js +1 -1
- package/dist/{Drawer-DAnc2ut9.js → Drawer-PeMgE4iA.js} +2 -2
- package/dist/DropdownMenu/index.js +3 -3
- package/dist/{DropdownMenu-BPi0pm0w.js → DropdownMenu-C9bvYZPt.js} +5 -5
- package/dist/{DropdownMenu-DuSVFQoS.js → DropdownMenu-_lQQyQCn.js} +6 -6
- package/dist/Field/index.js +3 -3
- package/dist/{Field-d5R_kRMv.js → Field-D-fRqyso.js} +1 -1
- package/dist/{FieldInfoTip-BhKtjq3g.js → FieldInfoTip-Bstp5Lvd.js} +1 -1
- package/dist/{FieldLabel-BHNpYFx7.js → FieldLabel-lV_qLaGp.js} +1 -1
- package/dist/FileInput/index.js +1 -1
- package/dist/{FileInput-BCg4HROm.js → FileInput-CTNnDIkm.js} +3 -3
- package/dist/IconButton/index.js +1 -1
- package/dist/{IconButton-BZgU_THt.js → IconButton-DPezhVBA.js} +1 -1
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InfoTip/index.js +1 -1
- package/dist/{InfoTip-E2-OzKti.js → InfoTip-B4BFfLtT.js} +1 -1
- package/dist/{InputClearButton-B62_uexC.js → InputClearButton-CxU3iv-5.js} +1 -1
- package/dist/InputGroup/index.js +1 -1
- package/dist/{InputGroup-DKBqRYFf.js → InputGroup-CraWGK6Y.js} +1 -1
- package/dist/{Item-C8UAQwFQ.js → Item-C9u_kQUO.js} +15 -14
- package/dist/Lightbox/index.js +1 -1
- package/dist/{Lightbox-Bou1gTfv.js → Lightbox-BNUG9CQ1.js} +1 -1
- package/dist/Link/index.d.ts +1 -1
- package/dist/Link/index.js +1 -1
- package/dist/{Link-CaJ5lmKk.js → Link-Bwgpn-di.js} +1 -1
- package/dist/List/index.js +2 -2
- package/dist/{ListItem-BlrEngDO.js → ListItem-_lOmngHp.js} +2 -2
- package/dist/Markdown/index.js +1 -1
- package/dist/{Markdown-BE6vdvPG.js → Markdown-BlEi5UGN.js} +2 -2
- package/dist/MobileNav/index.js +1 -1
- package/dist/{MobileNavToggle-D5yGMHU4.js → MobileNavToggle-wVa9dzH1.js} +1 -1
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MoreMenu/index.js +1 -1
- package/dist/{MoreMenu-CNzTagqr.js → MoreMenu-MmvMRWv5.js} +3 -3
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/MultiSelector/index.js +1 -1
- package/dist/{MultiSelector-MGEiRi1W.js → MultiSelector-DXrKQLmq.js} +4 -4
- package/dist/NavItem/index.js +1 -1
- package/dist/{NavItem-kj9FbbFS.js → NavItem-D4xHjSTo.js} +1 -1
- package/dist/NavMenu/index.js +2 -2
- package/dist/{NavMenu-ZN5cqCxO.js → NavMenu-NCg3VjAQ.js} +2 -2
- package/dist/{NavMenuItem-xm3e0V8q.js → NavMenuItem-Bla6fYVl.js} +3 -3
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/NumberInput/index.js +1 -1
- package/dist/{NumberInput-D4ECOHh_.js → NumberInput-DicgvFte.js} +3 -3
- package/dist/Outline/index.js +1 -1
- package/dist/{Outline-DI9MZnuQ.js → Outline-DlO_97b4.js} +3 -3
- package/dist/OverflowList/index.d.ts +1 -1
- package/dist/OverflowList/index.js +1 -1
- package/dist/{OverflowList-m1tf_fR1.js → OverflowList-BYYz3ePw.js} +1 -1
- package/dist/Overlay/index.d.ts +1 -1
- package/dist/Pagination/index.js +1 -1
- package/dist/{Pagination-BdjxuxM3.js → Pagination-DM_W9Ue-.js} +3 -3
- package/dist/Popover/index.js +1 -1
- package/dist/{Popover-DEj8xWN-.js → Popover-CxReY-4u.js} +5 -5
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-BJDFietK.js → PowerSearch-BwUWZG3p.js} +19 -19
- package/dist/Radio/index.d.ts +1 -1
- package/dist/Radio/index.js +1 -1
- package/dist/{RadioGroup-B3UoJrOA.js → RadioGroup-CsJYGjyx.js} +3 -3
- package/dist/RadioList/index.d.ts +1 -1
- package/dist/RadioList/index.js +1 -1
- package/dist/{RadioListItem-CD7kUGlN.js → RadioListItem-Yc3K82YE.js} +1 -1
- package/dist/ScrollableArea/index.d.ts +1 -1
- package/dist/SegmentedControl/index.js +1 -1
- package/dist/{SegmentedControl-DGd6JlaD.js → SegmentedControl-C-F5dkcG.js} +2 -2
- package/dist/SelectableCard/index.d.ts +1 -1
- package/dist/SelectableCard/index.js +1 -1
- package/dist/{SelectableCard-GRWYx3iD.js → SelectableCard-CwfpgsS8.js} +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/{Selector-BD0u-5Fy.js → Selector-bH99g1vj.js} +2 -2
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/SideNav/index.js +2 -2
- package/dist/{SideNav-DoqCLRiX.js → SideNav-C1ZxusAB.js} +6 -6
- package/dist/Slider/index.js +1 -1
- package/dist/{Slider-DHR7HZ7N.js → Slider-Bq_7Nskr.js} +2 -2
- package/dist/Stepper/index.d.ts +1 -1
- package/dist/Stepper/index.js +1 -1
- package/dist/{Stepper-CCuggsov.js → Stepper-CWluGqBs.js} +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/Switch/index.js +1 -1
- package/dist/{Switch-CnFC7jGw.js → Switch-DTPvMAxd.js} +2 -2
- package/dist/TabList/index.js +1 -1
- package/dist/{TabList-fMlX8m6n.js → TabList-C4i7UZkp.js} +3 -3
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-DoKmVdhZ.js → Table-ClHIgsKO.js} +13 -13
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/{TextArea-y9mmYAIy.js → TextArea-J2_wct0p.js} +4 -4
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/TextInput/index.js +1 -1
- package/dist/{TextInput-BLGEh7vE.js → TextInput-Da1TYd57.js} +4 -4
- package/dist/Thumbnail/index.js +1 -1
- package/dist/{Thumbnail-Dm8krgGF.js → Thumbnail-1LsaJ4_m.js} +2 -2
- package/dist/{TimeField-DS30hnty.js → TimeField-i5ESA500.js} +2 -2
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/TimeInput/index.js +1 -1
- package/dist/{TimeInput-DcY4b3dg.js → TimeInput-frnKZo1M.js} +2 -2
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/Timestamp/index.js +1 -1
- package/dist/{Timestamp-BhBuBHu8.js → Timestamp-SseS_qtf.js} +1 -1
- package/dist/Toast/index.js +1 -1
- package/dist/{Toast-CnLk7LzS.js → Toast-tAq4S96S.js} +149 -20
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/ToggleButton/index.js +1 -1
- package/dist/{ToggleButton-B9IJcpdJ.js → ToggleButton-B6hBzeVl.js} +3 -3
- package/dist/Token/index.d.ts +1 -1
- package/dist/Token/index.js +1 -1
- package/dist/{Token-C7Dt5ygK.js → Token-DTGUCgpn.js} +1 -1
- package/dist/Tokenizer/index.d.ts +1 -1
- package/dist/Tokenizer/index.js +1 -1
- package/dist/{Tokenizer-D7ZCTbnf.js → Tokenizer-iFZAuIwu.js} +7 -7
- package/dist/Toolbar/index.d.ts +1 -1
- package/dist/Toolbar/index.js +1 -1
- package/dist/{Toolbar-DSWH8ll4.js → Toolbar-BHkPxDxA.js} +1 -1
- package/dist/TopNav/index.d.ts +1 -1
- package/dist/TopNav/index.js +1 -1
- package/dist/{TopNav-CK_F6Ud5.js → TopNav-CcIayfsW.js} +4 -4
- package/dist/TreeList/index.js +1 -1
- package/dist/{TreeList-Dh0uAj2B.js → TreeList-Da_OKrv_.js} +4 -4
- package/dist/Typeahead/index.js +1 -1
- package/dist/{Typeahead-Cs-46obm.js → Typeahead-BD6xXNKh.js} +3 -3
- package/dist/VelocityTracker-DgjmootV.js +165 -0
- package/dist/{animator-BGq5a6vT.js → animator-CEHDYTfQ.js} +29 -173
- package/dist/{batch-BhaAWUIt.js → batch-D2a2MsSW.js} +4 -19
- package/dist/bezier-Dko5MnTp.js +37 -0
- package/dist/{clickGuard-FrlnECMp.js → clickGuard-C3VmOLhI.js} +2 -1
- package/dist/composables/index.js +7 -7
- package/dist/composables-Bs0O_SRd.js +2548 -0
- package/dist/{context-jtpQfR6F.js → context-NKb_prrS.js} +2 -2
- package/dist/{edge-CJIswPTX.js → edge-tj-cLZYh.js} +1 -1
- package/dist/{edgeRide-Drk4V-MC.js → edgeRide-DcUqLXE2.js} +4 -4
- package/dist/{handle-BazRxHwq.js → handle-CwxCHapJ.js} +1 -1
- package/dist/{holdEntranceInput-DMCOeRqu.js → holdEntranceInput-DgimbgGm.js} +1 -1
- package/dist/{index-BVeTS-R5.d.ts → index-3qz8Qztx.d.ts} +4 -4
- package/dist/{index-Q1oG9yIT.d.ts → index-B-3EGjfQ.d.ts} +2 -2
- package/dist/{index-C1e8LNx2.d.ts → index-BjqoHLMq.d.ts} +1 -1
- package/dist/{index-DQ3akoRZ.d.ts → index-Bu4R0WZA.d.ts} +3 -3
- package/dist/{index-BDZCJ9ri.d.ts → index-BuubzuE8.d.ts} +2 -2
- package/dist/{index-BL9fE6gs.d.ts → index-Cw4CUe06.d.ts} +5 -5
- package/dist/{index-CUuUoX3h.d.ts → index-JE1HrzdJ.d.ts} +3 -3
- package/dist/{index-hUa5oQ5O.d.ts → index-m3DOxOw6.d.ts} +42 -42
- package/dist/index.d.ts +9 -9
- package/dist/index.js +85 -85
- package/dist/{inputHold-BmChuR9x.js → inputHold-DW2LYHb5.js} +4 -4
- package/dist/{inputHoldState-pblUT4oh.js → inputHoldState-xntIqr5W.js} +2 -1
- package/dist/{inputStream-LZdK8luP.js → inputStream-bPd9eB2b.js} +2 -49
- package/dist/isRtlElement-NHuH48AA.js +23 -0
- package/dist/{landing-CBaXCGEg.js → landing-Bi7X7w_7.js} +3 -3
- package/dist/{lazyBottomSheet-Cmd-WMEE.js → lazyBottomSheet-BVZ1yH8g.js} +1 -1
- package/dist/{timing-CSHWQbTJ.js → linearEasing-ScK9LqAY.js} +30 -1
- package/dist/{bezier-Df-yGuNZ.js → presentation-Cy_yf56y.js} +2 -39
- package/dist/{pressFeedback-DVR5V1b6.js → pressFeedback-9dqGYjxv.js} +2 -2
- package/dist/{resolveMotion-CurhYTVC.js → resolveMotion-1cwESYvK.js} +202 -1
- package/dist/resolveSnapPoint-DdZyBkT4.js +717 -0
- package/dist/{flatTree-BB4yPMNL.js → sharedRealm-H1OrlP0V.js} +49 -1
- package/dist/{themeTiming-BFDOPRjK.js → themeTiming-NUkH9HsU.js} +1 -1
- package/dist/{touchHold-CFJlSClt.js → touchHold-DXtx7npm.js} +1 -1
- package/dist/{useActionGroupTracking-C6BzQzvp.js → useActionGroupTracking-CLFF7FI2.js} +2 -2
- package/dist/{useAnimatedLayout-DC2l3WrE.js → useAnimatedLayout-DWWc31RR.js} +1 -1
- package/dist/{composables-BTRbNgmR.js → useAttachment-BuNyeUXy.js} +44 -3464
- package/dist/{useChatStreamScroll-Cv51kRT0.js → useChatStreamScroll-CuMzkXgD.js} +1 -1
- package/dist/{useInputStatusIcon-BngSzjVd.js → useInputStatusIcon-BqV6YzTV.js} +1 -1
- package/dist/{useListFocus-CkHfsZp0.js → useListFocus-Ccd_HU9T.js} +2 -23
- package/dist/{useMenuDrillIn-BQx6lQMz.js → useMenuDrillIn-Cj6MM77J.js} +1 -1
- package/dist/{useMenuEntranceHold-buV5S9yk.js → useMenuEntranceHold-HznOwIry.js} +1 -1
- package/dist/{useMenuHover-CfQtWMg-.js → useMenuHover-DoBatZeD.js} +1 -1
- package/dist/{useMenuPress-DU6pAIHy.js → useMenuPress-DcwVUsQO.js} +3 -3
- package/dist/{usePressFeedback-BhNcuxQv.js → usePressFeedback-DHdmAsMp.js} +1 -1
- package/dist/{useTouchHitArea-CNZyA18Y.js → useTouchHitArea-SY1ITxSJ.js} +2 -2
- package/package.json +1 -1
- package/styles/bottom-sheet.css +28 -8
- package/dist/{index-D8lv2BiD.d.ts → index-BqhgeAT4.d.ts} +1 -1
|
@@ -1,868 +1,18 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { d as parseTouchAction, f as rootOverflow, l as SCROLLABLE_OVERFLOW, p as clockOf, u as isInsideScrollView } from "./pressFeedback-
|
|
3
|
-
import { i as withoutClickGuard, n as disarmClickGuard, t as armClickGuard } from "./clickGuard-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { o as pushLayer } from "./layerDepth-D3Rh8T5C.js";
|
|
8
|
-
import { t as useMediaQuery } from "./useMediaQuery-BzXGT1Aw.js";
|
|
9
|
-
import { l as motionNow, t as resolveMotion } from "./resolveMotion-CurhYTVC.js";
|
|
10
|
-
import { a as presentedOffsetOf, c as watchPresentedElements, i as presentedElements, s as resolvePresented } from "./bezier-Df-yGuNZ.js";
|
|
11
|
-
import { t as devWarn } from "./useDevWarning-B2fsk2B-.js";
|
|
1
|
+
import { a as sharedWeakMap, c as deepActiveElement, d as shadowRootsOutward, h as isNode, l as parentAcrossShadow, m as isHTMLElement, n as sharedKey, p as isElement, s as containsAlongFlatTree, t as realmValue, u as shadowHostOf } from "./sharedRealm-H1OrlP0V.js";
|
|
2
|
+
import { d as parseTouchAction, f as rootOverflow, l as SCROLLABLE_OVERFLOW, p as clockOf, u as isInsideScrollView } from "./pressFeedback-9dqGYjxv.js";
|
|
3
|
+
import { i as withoutClickGuard, n as disarmClickGuard, t as armClickGuard } from "./clickGuard-C3VmOLhI.js";
|
|
4
|
+
import { i as subscribeInput } from "./inputStream-bPd9eB2b.js";
|
|
5
|
+
import { c as UIKIT_PAN, l as UIKIT_PRESS, s as UIKIT_LONG_PRESS, u as UIKIT_TAP } from "./pressGesture-BzIBmKF2.js";
|
|
6
|
+
import { i as presentedOffsetOf, o as resolvePresented, r as presentedElements, s as watchPresentedElements } from "./presentation-Cy_yf56y.js";
|
|
12
7
|
import { t as isApplePlatform } from "./isApplePlatform-B1ju6F5B.js";
|
|
13
8
|
import { a as isIosWebKit, r as watchCoarsePointer, t as isCoarsePointer } from "./coarsePointer-BfMx3H23.js";
|
|
14
|
-
import {
|
|
15
|
-
import { t as holdsTouch } from "./touchHold-
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import { t as keyboardHintMessages } from "./keyboard-hint-KWx0-7kD.js";
|
|
19
|
-
import { n as observeResize } from "./sharedResizeObserver-BekhnB3E.js";
|
|
20
|
-
import { r as makeSnapPaging, s as snapPages } from "./snapPagingValue-B5hfph1H.js";
|
|
21
|
-
import { t as useTouchTriggerInternal } from "./useTouchTriggerInternal-Bl602PtA.js";
|
|
22
|
-
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";
|
|
23
|
-
import "../styles/indicator-focus-ring.css";
|
|
24
|
-
import "../styles/keyboard-hint.css";
|
|
25
|
-
//#region src/motion/decay.ts
|
|
26
|
-
/**
|
|
27
|
-
* @file decay.ts
|
|
28
|
-
* @input A release value, velocity and a UIScrollView deceleration rate
|
|
29
|
-
* @output Exports `solveDecay`, the closed-form momentum coast of a scroll
|
|
30
|
-
* view after the finger lifts (value, velocity, rest point, settle time,
|
|
31
|
-
* time to reach a value), and `decayRestDistance`
|
|
32
|
-
* @position Pure math under the motion animator; no DOM, no React
|
|
33
|
-
*
|
|
34
|
-
* UIScrollView's deceleration rate is a per-millisecond velocity factor: the
|
|
35
|
-
* speed is multiplied by the rate every millisecond (0.998 normal, 0.99 fast;
|
|
36
|
-
* see uikit/scroll.ts). As a continuous decay that is
|
|
37
|
-
* v(t) = v₀·e^(−λt), x(t) = x₀ + v₀·(1 − e^(−λt)) ÷ λ, λ = −1000·ln(rate) /s
|
|
38
|
-
* and the coast ends at x₀ + v₀ ÷ λ. WWDC18 "Designing Fluid Interfaces"
|
|
39
|
-
* projects the same rest point with the geometric series v₀·rate ÷ (1 − rate)
|
|
40
|
-
* per millisecond (projection.ts), 0.1 % shorter at the normal rate (499.0
|
|
41
|
-
* against 499.5 ms of the release speed); the continuous form is the one
|
|
42
|
-
* that also gives the position and velocity at every instant, which the
|
|
43
|
-
* animator needs to grab a coasting surface mid-flight.
|
|
44
|
-
*
|
|
45
|
-
* Units: time in seconds, velocity in units per second.
|
|
46
|
-
*/
|
|
47
|
-
function decayConstant(rate) {
|
|
48
|
-
if (!(rate > 0 && rate < 1)) throw new RangeError(`decay: rate must be in (0, 1), got ${rate}`);
|
|
49
|
-
return -1e3 * Math.log(rate);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* The momentum coast UIScrollView performs after the finger lifts.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* ```
|
|
56
|
-
* const coast = solveDecay({from: 0, velocity: 2000});
|
|
57
|
-
* coast.rest; // ≈ 999 px
|
|
58
|
-
* coast.value(0.2); // px after 200 ms
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
function solveDecay({ from, velocity: initialVelocity, rate = scroll.decelerationRate.normal }) {
|
|
62
|
-
const lambda = decayConstant(rate);
|
|
63
|
-
const rest = from + initialVelocity / lambda;
|
|
64
|
-
const speed0 = Math.abs(initialVelocity);
|
|
65
|
-
return {
|
|
66
|
-
from,
|
|
67
|
-
initialVelocity,
|
|
68
|
-
rate,
|
|
69
|
-
rest,
|
|
70
|
-
value: (t) => from + initialVelocity * -Math.expm1(-lambda * t) / lambda,
|
|
71
|
-
velocity: (t) => initialVelocity * Math.exp(-lambda * t),
|
|
72
|
-
settleTime: (threshold) => {
|
|
73
|
-
const remaining = speed0 / lambda;
|
|
74
|
-
if (!(threshold > 0)) return Infinity;
|
|
75
|
-
return remaining <= threshold ? 0 : Math.log(remaining / threshold) / lambda;
|
|
76
|
-
},
|
|
77
|
-
timeToSpeed: (speed) => speed0 <= speed ? 0 : speed > 0 ? Math.log(speed0 / speed) / lambda : Infinity,
|
|
78
|
-
timeToReach: (target) => {
|
|
79
|
-
if (initialVelocity === 0) return target === from ? 0 : null;
|
|
80
|
-
const fraction = lambda * (target - from) / initialVelocity;
|
|
81
|
-
if (fraction < 0 || fraction >= 1) return null;
|
|
82
|
-
return -Math.log1p(-fraction) / lambda;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
//#endregion
|
|
87
|
-
//#region src/motion/coast.ts
|
|
88
|
-
/** A curve that holds `end` from `duration` on. */
|
|
89
|
-
function settling(duration, end, at, velocity) {
|
|
90
|
-
return {
|
|
91
|
-
duration,
|
|
92
|
-
at: (t) => t >= duration ? end : at(t),
|
|
93
|
-
velocity: (t) => t >= duration ? 0 : velocity(t)
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* The momentum curves of a release with `velocity` (px per second on each
|
|
98
|
-
* translate axis), for `animator.decay`, which moves only `x` and `y`:
|
|
99
|
-
* momentum continues a finger's throw (design:reduced-motion DR2).
|
|
100
|
-
*
|
|
101
|
-
* @example
|
|
102
|
-
* ```
|
|
103
|
-
* animator.decay(
|
|
104
|
-
* coast(animator, {x: velocityX}, {bounds: {x: {min: -maxScroll, max: 0}}}),
|
|
105
|
-
* );
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
function coast(animator, velocity, options = {}) {
|
|
109
|
-
const velocities = {};
|
|
110
|
-
for (const key of ["x", "y"]) {
|
|
111
|
-
const value = velocity[key];
|
|
112
|
-
if (value != null && Number.isFinite(value)) velocities[key] = value;
|
|
113
|
-
}
|
|
114
|
-
const rate = options.rate ?? scroll.decelerationRate.normal;
|
|
115
|
-
registerScrollTable();
|
|
116
|
-
const bounce = toSpring(resolveMotion(animator.element, options.bounce ?? scroll.bounce));
|
|
117
|
-
const curves = {};
|
|
118
|
-
for (const [key, v0] of Object.entries(velocities)) {
|
|
119
|
-
const from = animator.get(key, options.at);
|
|
120
|
-
const bounds = options.bounds?.[key];
|
|
121
|
-
const threshold = SETTLE_THRESHOLD[key];
|
|
122
|
-
if (bounds != null && (from < bounds.min || from > bounds.max)) {
|
|
123
|
-
const edge = from < bounds.min ? bounds.min : bounds.max;
|
|
124
|
-
const back = solveSpring(bounce, {
|
|
125
|
-
from,
|
|
126
|
-
to: edge,
|
|
127
|
-
velocity: v0
|
|
128
|
-
});
|
|
129
|
-
curves[key] = {
|
|
130
|
-
...settling(back.settleTime(threshold), edge, (t) => back.value(t), (t) => back.velocity(t)),
|
|
131
|
-
isTransition: true
|
|
132
|
-
};
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
const glide = solveDecay({
|
|
136
|
-
from,
|
|
137
|
-
velocity: v0,
|
|
138
|
-
rate
|
|
139
|
-
});
|
|
140
|
-
const edge = bounds == null ? null : glide.rest < bounds.min ? bounds.min : glide.rest > bounds.max ? bounds.max : null;
|
|
141
|
-
const hit = edge == null ? null : glide.timeToReach(edge);
|
|
142
|
-
if (edge != null && hit != null) {
|
|
143
|
-
const spring = solveSpring(bounce, {
|
|
144
|
-
from: edge,
|
|
145
|
-
to: edge,
|
|
146
|
-
velocity: glide.velocity(hit)
|
|
147
|
-
});
|
|
148
|
-
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));
|
|
149
|
-
} else if (v0 === 0) curves[key] = settling(0, from, () => from, () => 0);
|
|
150
|
-
else curves[key] = settling(glide.settleTime(threshold * 2), edge ?? glide.rest, (t) => glide.value(t), (t) => glide.velocity(t));
|
|
151
|
-
}
|
|
152
|
-
return curves;
|
|
153
|
-
}
|
|
154
|
-
//#endregion
|
|
155
|
-
//#region src/motion/springRole.ts
|
|
156
|
-
/**
|
|
157
|
-
* Registers the row as the role `springs.<name>` and returns it. A page that
|
|
158
|
-
* plays no spring ships no springs registry. Each spring role registers
|
|
159
|
-
* itself when the module that plays it loads (one idempotent in-memory write,
|
|
160
|
-
* no DOM). Write each call with the pure annotation, so a bundle that does
|
|
161
|
-
* not use the row drops the call.
|
|
162
|
-
*/
|
|
163
|
-
function springRole(name, spring) {
|
|
164
|
-
return registerSpringRole(`springs.${name}`, spring);
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/motion/uikit/menuSprings.ts
|
|
168
|
-
/**
|
|
169
|
-
* @file menuSprings.ts
|
|
170
|
-
* @input Nothing; data only
|
|
171
|
-
* @output The springs of UIKit's alerts, action sheets, menus and context
|
|
172
|
-
* menus, each in the vocabulary of its source
|
|
173
|
-
* @position Part of the springs domain of the UIKit constants table:
|
|
174
|
-
* springs.ts re-exports every row and lists them in `springs`
|
|
175
|
-
*/
|
|
176
|
-
/**
|
|
177
|
-
* Alert (UIAlertController .alert) appearing: fades in and scales from
|
|
178
|
-
* 1.2 to 1, the dimming fading in alongside. UIKit asks
|
|
179
|
-
* `UIView.animate(withDuration: 0.404, usingSpringWithDamping: 600,
|
|
180
|
-
* initialSpringVelocity: 0)`; the damping clamps to critical, and the
|
|
181
|
-
* spring settles at 0.404 s.
|
|
182
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
183
|
-
* iPhone 17 Pro, UIView.animate hooked and CASpringAnimation dumped
|
|
184
|
-
* (mass 1, stiffness 522.350, damping 45.710, duration 0.404),
|
|
185
|
-
* Oct 23 2026
|
|
186
|
-
*/
|
|
187
|
-
const ALERT_PRESENT_SPRING = {
|
|
188
|
-
mass: 1,
|
|
189
|
-
stiffness: 522.35,
|
|
190
|
-
damping: 45.71
|
|
191
|
-
};
|
|
192
|
-
/**
|
|
193
|
-
* Alert dismissing: the same spring, opacity only.
|
|
194
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
195
|
-
* iPhone 17 Pro, CASpringAnimation dump, Oct 23 2026
|
|
196
|
-
*/
|
|
197
|
-
const ALERT_DISMISS_SPRING = {
|
|
198
|
-
mass: 1,
|
|
199
|
-
stiffness: 522.35,
|
|
200
|
-
damping: 45.71
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Action sheet (UIAlertController .actionSheet) appearing: identical to
|
|
204
|
-
* the alert.
|
|
205
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
206
|
-
* iPhone 17 Pro, CASpringAnimation dump, Oct 23 2026
|
|
207
|
-
*/
|
|
208
|
-
const ACTION_SHEET_PRESENT_SPRING = {
|
|
209
|
-
mass: 1,
|
|
210
|
-
stiffness: 522.35,
|
|
211
|
-
damping: 45.71
|
|
212
|
-
};
|
|
213
|
-
/**
|
|
214
|
-
* Action sheet dismissing: identical to the alert.
|
|
215
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
216
|
-
* iPhone 17 Pro, CASpringAnimation dump, Oct 23 2026
|
|
217
|
-
*/
|
|
218
|
-
const ACTION_SHEET_DISMISS_SPRING = {
|
|
219
|
-
mass: 1,
|
|
220
|
-
stiffness: 522.35,
|
|
221
|
-
damping: 45.71
|
|
222
|
-
};
|
|
223
|
-
/**
|
|
224
|
-
* UIMenu (from a button) opening; UIKit drives it per frame and lets it
|
|
225
|
-
* track a finger still on the screen.
|
|
226
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
227
|
-
* iPhone 17 Pro, `_animateUsingSpringWithDampingRatio:response:tracking:`
|
|
228
|
-
* hooked (0.8, 0.32, tracking), Oct 23 2026
|
|
229
|
-
*/
|
|
230
|
-
const MENU_OPEN_SPRING = /* @__PURE__ */ springRole("menuOpen", {
|
|
231
|
-
response: .32,
|
|
232
|
-
dampingRatio: .8
|
|
233
|
-
});
|
|
234
|
-
/**
|
|
235
|
-
* UIMenu closing (a tap outside).
|
|
236
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
237
|
-
* iPhone 17 Pro, the same hook (0.85, 0.35, not tracking), Oct 23 2026
|
|
238
|
-
*/
|
|
239
|
-
const MENU_CLOSE_SPRING = /* @__PURE__ */ springRole("menuClose", {
|
|
240
|
-
response: .35,
|
|
241
|
-
dampingRatio: .85
|
|
242
|
-
});
|
|
243
|
-
/**
|
|
244
|
-
* A sub-menu opening in place (its row tapped on a phone): a card laid over
|
|
245
|
-
* the parent's rows from the tapped row grows down to fit the sub-menu, the
|
|
246
|
-
* menu's box with it, and the parent's rows recede, on this spring
|
|
247
|
-
* (spec:AST-094 FR34).
|
|
248
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
249
|
-
* iPhone 17 Pro, a pull-down button at y 150 whose menu opens downward
|
|
250
|
-
* (Alpha, Beta, Sort By ▸ (Name, Date, Size), Delete), every menu label,
|
|
251
|
-
* image and view read per 60 Hz tick, Oct 24 2026 (t from the tap-down;
|
|
252
|
-
* the lift at 60 ms): the menu's box kept its top and grew 188 → 190.9
|
|
253
|
-
* (106 ms), 198.1 (123), 218.1 (156), 238.5 (189), 255.6 (223), 268.2
|
|
254
|
-
* (256), 276.7 (289), 282.1 (324), 285.2 (359), 286.8 (389), 287.6 (424),
|
|
255
|
-
* settling at 287.2; the parent rows' opacity followed it (1 → 0.5 by 389
|
|
256
|
-
* ms). UIKit's own spring for it, logged as the
|
|
257
|
-
* `UIViewSpringAnimationBehavior` it starts a few ms after the lift on
|
|
258
|
-
* every sub-menu row (four captures): damping ratio 0.85, response 0.4 s.
|
|
259
|
-
* It fits the box's eleven frames to 0.12 pt rms of the 99 pt travel
|
|
260
|
-
* (start 89.5 ms), as a free single-spring fit does (0.86, 0.395)
|
|
261
|
-
*/
|
|
262
|
-
const SUB_MENU_OPEN_SPRING = /* @__PURE__ */ springRole("subMenuOpen", {
|
|
263
|
-
response: .4,
|
|
264
|
-
dampingRatio: .85
|
|
265
|
-
});
|
|
266
|
-
/**
|
|
267
|
-
* Back out of a sub-menu (its header tapped): the card shrinks back up into
|
|
268
|
-
* the row, the menu's box with it, and the parent's rows come back, on this
|
|
269
|
-
* spring (spec:AST-094 FR34).
|
|
270
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
271
|
-
* iPhone 17 Pro, the same menu and readings, Oct 24 2026 (t from the
|
|
272
|
-
* tap-down; the lift at 60 ms): the box 287.2 → 284.3 (128 ms), 268.7
|
|
273
|
-
* (160), 249.9 (195), 233 (228), 219.6 (260), 209.6 (296), 202.5 (329),
|
|
274
|
-
* 197.6 (361), 194.3 (395), 192.1 (428), 189.7 (494), 188 (628); the
|
|
275
|
-
* parent rows' opacity 0.5 → 0.59 (160), 0.69 (195), 0.77 (228), 0.84
|
|
276
|
-
* (260), 0.89 (296), 0.93 (329), 0.95 (361), 0.97 (395), 0.99 (461), 1
|
|
277
|
-
* (527). UIKit's own spring for it, logged as the
|
|
278
|
-
* `UIViewSpringAnimationBehavior` it starts on every header back (three
|
|
279
|
-
* captures): damping ratio 1, response 0.4 s. It fits the box's twelve
|
|
280
|
-
* frames to 0.28 pt rms of the 99 pt travel (start 111 ms), the opacity to
|
|
281
|
-
* 0.0055 rms
|
|
282
|
-
*/
|
|
283
|
-
const SUB_MENU_BACK_SPRING = /* @__PURE__ */ springRole("subMenuBack", {
|
|
284
|
-
response: .4,
|
|
285
|
-
dampingRatio: 1
|
|
286
|
-
});
|
|
287
|
-
/**
|
|
288
|
-
* Context menu (UIContextMenuInteraction): the preview lifting once the
|
|
289
|
-
* long press commits.
|
|
290
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
291
|
-
* iPhone 17 Pro, the same hook (0.8, 0.32, tracking), Oct 23 2026
|
|
292
|
-
*/
|
|
293
|
-
const CONTEXT_MENU_LIFT_SPRING = /* @__PURE__ */ springRole("contextMenuLift", {
|
|
294
|
-
response: .32,
|
|
295
|
-
dampingRatio: .8
|
|
296
|
-
});
|
|
297
|
-
/**
|
|
298
|
-
* Context menu dismissing (a tap outside).
|
|
299
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
300
|
-
* iPhone 17 Pro, the same hook (0.85, 0.35, not tracking), Oct 23 2026
|
|
301
|
-
*/
|
|
302
|
-
const CONTEXT_MENU_DISMISS_SPRING = /* @__PURE__ */ springRole("contextMenuDismiss", {
|
|
303
|
-
response: .35,
|
|
304
|
-
dampingRatio: .85
|
|
305
|
-
});
|
|
306
|
-
/**
|
|
307
|
-
* Context menu: the menu's entrance beside the lifted preview and the preview
|
|
308
|
-
* shadow's rise and fade (the preview's growth and the backdrop's fade take
|
|
309
|
-
* the lift spring above).
|
|
310
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
311
|
-
* iPhone 17 Pro, per-frame morph and platter layers, Oct 23 2026: the menu
|
|
312
|
-
* content's opacity, blur and scale, the morph container's centre and the
|
|
313
|
-
* preview shadow's opacity each fit (0.30, 0.80), rms ≤ 0.001; the issued
|
|
314
|
-
* UIViewSpringAnimationBehaviorSettings are (0.8, 0.3)
|
|
315
|
-
*/
|
|
316
|
-
const CONTEXT_MENU_MORPH_SPRING = /* @__PURE__ */ springRole("contextMenuMorph", {
|
|
317
|
-
response: .3,
|
|
318
|
-
dampingRatio: .8
|
|
319
|
-
});
|
|
320
|
-
/**
|
|
321
|
-
* What UIKit plays for a menu with Reduce Motion on: critically damped,
|
|
322
|
-
* slower, no overshoot. A reference reading of UIKit only, never played:
|
|
323
|
-
* under reduced motion no core transition springs (`design:reduced-motion`
|
|
324
|
-
* DR1); a touch presentation cross-fades instead (DR2), and nothing opts
|
|
325
|
-
* out (DR4, `spec:AST-094` FR8).
|
|
326
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
327
|
-
* iPhone 17 Pro, `_animateUsingSpringWithDampingRatio:response:tracking:`
|
|
328
|
-
* hooked with Reduce Motion on (1.0, 0.4), Oct 23 2026
|
|
329
|
-
*/
|
|
330
|
-
const MENU_REDUCED_MOTION_SPRING = {
|
|
331
|
-
response: .4,
|
|
332
|
-
dampingRatio: 1
|
|
333
|
-
};
|
|
334
|
-
//#endregion
|
|
335
|
-
//#region src/motion/uikit/springs.ts
|
|
336
|
-
/**
|
|
337
|
-
* @file springs.ts
|
|
338
|
-
* @input Nothing; data only
|
|
339
|
-
* @output One export per UIKit / SwiftUI interaction spring the touch
|
|
340
|
-
* presentations use (`SHEET_PRESENT_SPRING`, `SETTLE_SPRING`, …), each in
|
|
341
|
-
* the vocabulary of its source (SpringDescription: duration/bounce,
|
|
342
|
-
* response/dampingRatio or mass/stiffness/damping; a reader normalizes them
|
|
343
|
-
* to one form), and `springs`, the table of all of them by row name
|
|
344
|
-
* @position The springs domain of the UIKit constants table (motion/uikit)
|
|
345
|
-
*
|
|
346
|
-
* Every leaf carries one or more `@source` (apple-docs | wwdc | webkit |
|
|
347
|
-
* measured | GUESS); webkit and GUESS values also carry the `@measure` task
|
|
348
|
-
* that will confirm or replace them (MEASUREMENTS.md lists them all).
|
|
349
|
-
* uikit.test.ts enforces both.
|
|
350
|
-
*
|
|
351
|
-
* Most springs are measured on iOS 26.2 or documented by Apple; one is still
|
|
352
|
-
* a GUESS (`banner`). `switchThumbMove` is the switch's measured travel,
|
|
353
|
-
* which uikit/switch.ts reads. A guess starts from the nearest sourced
|
|
354
|
-
* spring and names it. A component built on the table gets the measured
|
|
355
|
-
* value the moment it lands, without changing.
|
|
356
|
-
*
|
|
357
|
-
* Press highlight in/out are fades, not springs: see timing.ts.
|
|
358
|
-
*/
|
|
359
|
-
/**
|
|
360
|
-
* SwiftUI `.smooth`: no bounce. Also SwiftUI's `Spring()` and
|
|
361
|
-
* `.spring(duration:bounce:)` defaults.
|
|
362
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/spring/smooth(duration:extrabounce:)
|
|
363
|
-
*/
|
|
364
|
-
const SETTLE_SPRING = /* @__PURE__ */ springRole("settle", {
|
|
365
|
-
duration: .5,
|
|
366
|
-
bounce: 0
|
|
367
|
-
});
|
|
368
|
-
/**
|
|
369
|
-
* SwiftUI `.snappy`: "small amount of bounce", base bounce 0.15.
|
|
370
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/spring/snappy(duration:extrabounce:)
|
|
371
|
-
*/
|
|
372
|
-
const QUICK_CHANGE_SPRING = /* @__PURE__ */ springRole("quickChange", {
|
|
373
|
-
duration: .5,
|
|
374
|
-
bounce: .15
|
|
375
|
-
});
|
|
376
|
-
/**
|
|
377
|
-
* SwiftUI `.bouncy`: base bounce 0.3.
|
|
378
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/spring/bouncy(duration:extrabounce:)
|
|
379
|
-
*/
|
|
380
|
-
const EMPHASIS_SPRING = /* @__PURE__ */ springRole("emphasis", {
|
|
381
|
-
duration: .5,
|
|
382
|
-
bounce: .3
|
|
383
|
-
});
|
|
384
|
-
/**
|
|
385
|
-
* SwiftUI `interactiveSpring()` defaults: for a value that tracks a finger.
|
|
386
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/animation/interactivespring(response:dampingfraction:blendduration:)
|
|
387
|
-
*/
|
|
388
|
-
const FINGER_TRACKING_SPRING = /* @__PURE__ */ springRole("fingerTracking", {
|
|
389
|
-
response: .15,
|
|
390
|
-
dampingRatio: .86
|
|
391
|
-
});
|
|
392
|
-
/**
|
|
393
|
-
* SwiftUI `Animation.default` since iOS 17 (what `withAnimation` uses).
|
|
394
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/animation/default
|
|
395
|
-
*/
|
|
396
|
-
const STATE_CHANGE_SPRING = /* @__PURE__ */ springRole("stateChange", {
|
|
397
|
-
response: .55,
|
|
398
|
-
dampingRatio: 1
|
|
399
|
-
});
|
|
400
|
-
/**
|
|
401
|
-
* SwiftUI `.spring(response:dampingFraction:blendDuration:)` defaults.
|
|
402
|
-
* @source apple-docs https://developer.apple.com/documentation/swiftui/animation/spring(response:dampingfraction:blendduration:)
|
|
403
|
-
*/
|
|
404
|
-
const DIRECT_CHANGE_SPRING = /* @__PURE__ */ springRole("directChange", {
|
|
405
|
-
response: .5,
|
|
406
|
-
dampingRatio: .825
|
|
407
|
-
});
|
|
408
|
-
/**
|
|
409
|
-
* UIKit `UIView.animate(springDuration:bounce:…)` defaults (iOS 17).
|
|
410
|
-
* @source apple-docs https://developer.apple.com/documentation/uikit/uiview/animate(springduration:bounce:initialspringvelocity:delay:options:animations:completion:)
|
|
411
|
-
*/
|
|
412
|
-
const TIMED_CHANGE_SPRING = /* @__PURE__ */ springRole("timedChange", {
|
|
413
|
-
duration: .5,
|
|
414
|
-
bounce: 0
|
|
415
|
-
});
|
|
416
|
-
/**
|
|
417
|
-
* UIKit's default spring, `UISpringTimingParameters()`: Apple documents
|
|
418
|
-
* its damping ratio as 4.56, which is exactly 500 ÷ (2·√(3·1000)).
|
|
419
|
-
* Overdamped on paper; Core Animation treats overdamping as critical
|
|
420
|
-
* unless told otherwise, so in effect it is a critically
|
|
421
|
-
* damped spring with ω₀ = 18.26 rad/s (response 0.344 s) that settles in
|
|
422
|
-
* 0.506 s. The keyboard does not use it (see `keyboard`).
|
|
423
|
-
* @source apple-docs https://developer.apple.com/documentation/uikit/uispringtimingparameters/init() (damping ratio 4.56)
|
|
424
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
425
|
-
* iPhone 17 Pro, CAAnimation read, Oct 23 2026: UISpringTimingParameters()
|
|
426
|
-
* is mass 3, stiffness 1000, damping 500; UIKit runs it for 0.505824 s
|
|
427
|
-
* (clamped to critical) whatever duration the animator was given, and
|
|
428
|
-
* `UIView.animate` with curve 7 outside the keyboard is this spring with
|
|
429
|
-
* its duration forced to 0.5 s
|
|
430
|
-
*/
|
|
431
|
-
const VIEW_CHANGE_SPRING = /* @__PURE__ */ springRole("viewChange", {
|
|
432
|
-
mass: 3,
|
|
433
|
-
stiffness: 1e3,
|
|
434
|
-
damping: 500
|
|
435
|
-
});
|
|
436
|
-
/**
|
|
437
|
-
* Push (programmatic or a row tap): the incoming card slides in from the
|
|
438
|
-
* trailing edge, the outgoing card shifts by `navigation.parallax`. The
|
|
439
|
-
* spring does not start from rest: it starts at
|
|
440
|
-
* `navigation.pushVelocity` × the travel per second.
|
|
441
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
442
|
-
* iPhone 17 Pro, time-free fit of the (value, velocity) pairs UIKit
|
|
443
|
-
* writes to the cards' CAPresentationModifiers every frame (rms 5e-4 of
|
|
444
|
-
* the travel), Oct 23 2026
|
|
445
|
-
*/
|
|
446
|
-
const NAVIGATION_PUSH_SPRING = {
|
|
447
|
-
response: .3,
|
|
448
|
-
dampingRatio: 1
|
|
449
|
-
};
|
|
450
|
-
/**
|
|
451
|
-
* Pop (back button or programmatic): identical to the push.
|
|
452
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
453
|
-
* iPhone 17 Pro, CAPresentationModifier fit as for the push, Oct 23 2026
|
|
454
|
-
*/
|
|
455
|
-
const NAVIGATION_POP_SPRING = {
|
|
456
|
-
response: .3,
|
|
457
|
-
dampingRatio: 1
|
|
458
|
-
};
|
|
459
|
-
/**
|
|
460
|
-
* Interactive pop finishing or cancelling after the finger lifts, starting
|
|
461
|
-
* from the finger's velocity; which one is `navigation.interactivePop*`.
|
|
462
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
463
|
-
* iPhone 17 Pro, CAPresentationModifier fit over released swipes,
|
|
464
|
-
* Oct 23 2026
|
|
465
|
-
*/
|
|
466
|
-
const NAVIGATION_INTERACTIVE_POP_FINISH_SPRING = {
|
|
467
|
-
response: .3,
|
|
468
|
-
dampingRatio: .85
|
|
469
|
-
};
|
|
470
|
-
/**
|
|
471
|
-
* Navigation bar elements (Liquid Glass) moving during a push or pop.
|
|
472
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
473
|
-
* iPhone 17 Pro, UIView.animate(springDuration: 0.6, bounce: 0,
|
|
474
|
-
* .beginFromCurrentState) calls hooked during transitions, Oct 23 2026
|
|
475
|
-
*/
|
|
476
|
-
const NAVIGATION_BAR_ELEMENTS_SPRING = {
|
|
477
|
-
duration: .6,
|
|
478
|
-
bounce: 0
|
|
479
|
-
};
|
|
480
|
-
/**
|
|
481
|
-
* Sheet presented programmatically: UIKit's default spring
|
|
482
|
-
* (`UIViewPropertyAnimator(duration: 0.4, timingParameters:
|
|
483
|
-
* UISpringTimingParameters())`), which renders critically damped at
|
|
484
|
-
* response 0.344 s; the same at the medium and large detents.
|
|
485
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
486
|
-
* iPhone 17 Pro, CAAnimation dump (mass 3, stiffness 1000, damping 500,
|
|
487
|
-
* duration 0.5, allowsOverdamping off), Oct 23 2026
|
|
488
|
-
*/
|
|
489
|
-
const SHEET_PRESENT_SPRING = {
|
|
490
|
-
mass: 3,
|
|
491
|
-
stiffness: 1e3,
|
|
492
|
-
damping: 500
|
|
493
|
-
};
|
|
494
|
-
/**
|
|
495
|
-
* Sheet dismissed programmatically (Cancel / Done / a scrim tap).
|
|
496
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
497
|
-
* iPhone 17 Pro, CAAnimation dump, the same spring as the presentation,
|
|
498
|
-
* Oct 23 2026
|
|
499
|
-
*/
|
|
500
|
-
const SHEET_DISMISS_SPRING = {
|
|
501
|
-
mass: 3,
|
|
502
|
-
stiffness: 1e3,
|
|
503
|
-
damping: 500
|
|
504
|
-
};
|
|
505
|
-
/**
|
|
506
|
-
* Detent change (`animateChanges`) and the settle after a slow release
|
|
507
|
-
* (below the sheet's fast-release speed, which the sheet's own table
|
|
508
|
-
* records): critically damped at the same pace as the presentation.
|
|
509
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
510
|
-
* iPhone 17 Pro, `_UISpringParameters(dampingRatio: 1, response:
|
|
511
|
-
* 0.3441442326)` hooked, CASpringAnimation mass 1, stiffness 333.333,
|
|
512
|
-
* damping 36.515, Oct 23 2026
|
|
513
|
-
*/
|
|
514
|
-
const SHEET_DETENT_SPRING = {
|
|
515
|
-
response: .3441442326,
|
|
516
|
-
dampingRatio: 1
|
|
517
|
-
};
|
|
518
|
-
/**
|
|
519
|
-
* The settle after a fast release (from the sheet's fast-release speed
|
|
520
|
-
* on), toward a detent or out of the screen: same pace, 80 % damping;
|
|
521
|
-
* UIKit hands it the finger's velocity.
|
|
522
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
523
|
-
* iPhone 17 Pro, CASpringAnimation dump over 36 releases (mass 1,
|
|
524
|
-
* stiffness 333.333, damping 29.212), Oct 23 2026
|
|
525
|
-
*/
|
|
526
|
-
const SHEET_RELEASE_FAST_SPRING = {
|
|
527
|
-
response: .3441442326,
|
|
528
|
-
dampingRatio: .8
|
|
529
|
-
};
|
|
530
|
-
/**
|
|
531
|
-
* Sheet dismissed by a swipe: the fast-release spring.
|
|
532
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
533
|
-
* iPhone 17 Pro, CASpringAnimation dump (300 pt swipe in 0.15 s:
|
|
534
|
-
* stiffness 333.333, damping 29.212), Oct 23 2026
|
|
535
|
-
*/
|
|
536
|
-
const SHEET_DISMISS_SWIPE_SPRING = /* @__PURE__ */ springRole("sheetDismissSwipe", {
|
|
537
|
-
response: .3441442326,
|
|
538
|
-
dampingRatio: .8
|
|
539
|
-
});
|
|
540
|
-
/**
|
|
541
|
-
* UISwitch thumb travelling between off and on, measured: the switch table's
|
|
542
|
-
* `travel` reads this row, so the value has one home.
|
|
543
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
544
|
-
* iPhone 17 Pro, the lens's position behavior read on a tap (damping 1,
|
|
545
|
-
* response 0.3); the lens center after a 50 ms tap and after a 1 s hold
|
|
546
|
-
* fits one spring at 0.31 / 1 (rms 0.11 pt), Oct 23 2026
|
|
547
|
-
*/
|
|
548
|
-
const SWITCH_THUMB_MOVE_SPRING = {
|
|
549
|
-
response: .3,
|
|
550
|
-
dampingRatio: 1
|
|
551
|
-
};
|
|
552
|
-
/**
|
|
553
|
-
* Keyboard frame animation, show and hide alike: critically damped,
|
|
554
|
-
* response 0.2667 s. The notification reports curve 7 and 0.3833 s
|
|
555
|
-
* (`timing.keyboardNotificationMs`); Core Animation cuts the spring there.
|
|
556
|
-
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
557
|
-
* iPhone 17 Pro, CAAnimation read on the keyboard host and a
|
|
558
|
-
* keyboardLayoutGuide-pinned view, Oct 23 2026
|
|
559
|
-
*/
|
|
560
|
-
const KEYBOARD_SPRING = {
|
|
561
|
-
mass: 1,
|
|
562
|
-
stiffness: 555.0265,
|
|
563
|
-
damping: 47.118
|
|
564
|
-
};
|
|
565
|
-
/**
|
|
566
|
-
* Banner / toast sliding in from the top edge (system notification
|
|
567
|
-
* banner as the reference).
|
|
568
|
-
* @source GUESS — UIKit's default spring
|
|
569
|
-
* @measure M-T1
|
|
570
|
-
*/
|
|
571
|
-
const BANNER_SPRING = {
|
|
572
|
-
mass: 3,
|
|
573
|
-
stiffness: 1e3,
|
|
574
|
-
damping: 500
|
|
575
|
-
};
|
|
576
|
-
/**
|
|
577
|
-
* UISlider's release: after a finger lifts, the thumb settles on this spring
|
|
578
|
-
* toward 0.4 of the release's momentum projection. It is critically damped,
|
|
579
|
-
* so it never overshoots a target ahead of it.
|
|
580
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
|
|
581
|
-
* `UIViewSpringAnimationBehavior` at the lift reads response 0.4 and
|
|
582
|
-
* damping ratio 1. Four releases fit it per frame (the UIKit slider
|
|
583
|
-
* table). Oct 23 2026
|
|
584
|
-
*/
|
|
585
|
-
const SLIDER_RELEASE_SPRING = /* @__PURE__ */ springRole("sliderRelease", {
|
|
586
|
-
response: .4,
|
|
587
|
-
dampingRatio: 1
|
|
588
|
-
});
|
|
589
|
-
/**
|
|
590
|
-
* UISlider's lift: a finger's touch-down scales the thumb up on this spring.
|
|
591
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
|
|
592
|
-
* thumb's scale per frame after touch-down (the UIKit slider table).
|
|
593
|
-
* Oct 23 2026
|
|
594
|
-
*/
|
|
595
|
-
const SLIDER_LIFT_SPRING = /* @__PURE__ */ springRole("sliderLift", {
|
|
596
|
-
response: .215,
|
|
597
|
-
dampingRatio: .6
|
|
598
|
-
});
|
|
599
|
-
/**
|
|
600
|
-
* UISlider's drop: the lift's end scales the thumb back down on this spring.
|
|
601
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, iPhone 17 Pro. The
|
|
602
|
-
* thumb's scale per frame after the lift (the UIKit slider table).
|
|
603
|
-
* Oct 23 2026
|
|
604
|
-
*/
|
|
605
|
-
const SLIDER_DROP_SPRING = /* @__PURE__ */ springRole("sliderDrop", {
|
|
606
|
-
response: .5,
|
|
607
|
-
dampingRatio: .7
|
|
608
|
-
});
|
|
609
|
-
/**
|
|
610
|
-
* Every spring above, by row name: the table the existing readers use. A
|
|
611
|
-
* component imports only the rows it plays (`architecture:component-style-authoring`
|
|
612
|
-
* INV6), each the same object as its row here.
|
|
613
|
-
*/
|
|
614
|
-
const springs = {
|
|
615
|
-
settle: SETTLE_SPRING,
|
|
616
|
-
quickChange: QUICK_CHANGE_SPRING,
|
|
617
|
-
emphasis: EMPHASIS_SPRING,
|
|
618
|
-
fingerTracking: FINGER_TRACKING_SPRING,
|
|
619
|
-
stateChange: STATE_CHANGE_SPRING,
|
|
620
|
-
directChange: DIRECT_CHANGE_SPRING,
|
|
621
|
-
timedChange: TIMED_CHANGE_SPRING,
|
|
622
|
-
viewChange: VIEW_CHANGE_SPRING,
|
|
623
|
-
navigationPush: NAVIGATION_PUSH_SPRING,
|
|
624
|
-
navigationPop: NAVIGATION_POP_SPRING,
|
|
625
|
-
navigationInteractivePopFinish: NAVIGATION_INTERACTIVE_POP_FINISH_SPRING,
|
|
626
|
-
navigationBarElements: NAVIGATION_BAR_ELEMENTS_SPRING,
|
|
627
|
-
sheetPresent: SHEET_PRESENT_SPRING,
|
|
628
|
-
sheetDismiss: SHEET_DISMISS_SPRING,
|
|
629
|
-
sheetDetent: SHEET_DETENT_SPRING,
|
|
630
|
-
sheetReleaseFast: SHEET_RELEASE_FAST_SPRING,
|
|
631
|
-
sheetDismissSwipe: SHEET_DISMISS_SWIPE_SPRING,
|
|
632
|
-
alertPresent: ALERT_PRESENT_SPRING,
|
|
633
|
-
alertDismiss: ALERT_DISMISS_SPRING,
|
|
634
|
-
actionSheetPresent: ACTION_SHEET_PRESENT_SPRING,
|
|
635
|
-
actionSheetDismiss: ACTION_SHEET_DISMISS_SPRING,
|
|
636
|
-
menuOpen: MENU_OPEN_SPRING,
|
|
637
|
-
menuClose: MENU_CLOSE_SPRING,
|
|
638
|
-
subMenuOpen: SUB_MENU_OPEN_SPRING,
|
|
639
|
-
subMenuBack: SUB_MENU_BACK_SPRING,
|
|
640
|
-
contextMenuLift: CONTEXT_MENU_LIFT_SPRING,
|
|
641
|
-
contextMenuDismiss: CONTEXT_MENU_DISMISS_SPRING,
|
|
642
|
-
contextMenuMorph: CONTEXT_MENU_MORPH_SPRING,
|
|
643
|
-
menuReducedMotion: MENU_REDUCED_MOTION_SPRING,
|
|
644
|
-
switchThumbMove: SWITCH_THUMB_MOVE_SPRING,
|
|
645
|
-
keyboard: KEYBOARD_SPRING,
|
|
646
|
-
banner: BANNER_SPRING,
|
|
647
|
-
sliderRelease: SLIDER_RELEASE_SPRING,
|
|
648
|
-
sliderLift: SLIDER_LIFT_SPRING,
|
|
649
|
-
sliderDrop: SLIDER_DROP_SPRING
|
|
650
|
-
};
|
|
651
|
-
/**
|
|
652
|
-
* The only springs that are motion roles. The touch presentations' record
|
|
653
|
-
* names some, and a component's own record names others, such as Slider's
|
|
654
|
-
* three. The generated motion role table lists each with its record.
|
|
655
|
-
* The registry takes these rows alone, so registering ships no other spring.
|
|
656
|
-
*/
|
|
657
|
-
const SPRING_ROLES = {
|
|
658
|
-
fingerTracking: FINGER_TRACKING_SPRING,
|
|
659
|
-
emphasis: EMPHASIS_SPRING,
|
|
660
|
-
settle: SETTLE_SPRING,
|
|
661
|
-
quickChange: QUICK_CHANGE_SPRING,
|
|
662
|
-
viewChange: VIEW_CHANGE_SPRING,
|
|
663
|
-
timedChange: TIMED_CHANGE_SPRING,
|
|
664
|
-
stateChange: STATE_CHANGE_SPRING,
|
|
665
|
-
directChange: DIRECT_CHANGE_SPRING,
|
|
666
|
-
menuOpen: MENU_OPEN_SPRING,
|
|
667
|
-
menuClose: MENU_CLOSE_SPRING,
|
|
668
|
-
subMenuOpen: SUB_MENU_OPEN_SPRING,
|
|
669
|
-
subMenuBack: SUB_MENU_BACK_SPRING,
|
|
670
|
-
sheetDismissSwipe: SHEET_DISMISS_SWIPE_SPRING,
|
|
671
|
-
contextMenuLift: CONTEXT_MENU_LIFT_SPRING,
|
|
672
|
-
contextMenuDismiss: CONTEXT_MENU_DISMISS_SPRING,
|
|
673
|
-
contextMenuMorph: CONTEXT_MENU_MORPH_SPRING,
|
|
674
|
-
sliderRelease: SLIDER_RELEASE_SPRING,
|
|
675
|
-
sliderLift: SLIDER_LIFT_SPRING,
|
|
676
|
-
sliderDrop: SLIDER_DROP_SPRING
|
|
677
|
-
};
|
|
678
|
-
/**
|
|
679
|
-
* Registers the role springs (`SPRING_ROLES`) as internal motion roles
|
|
680
|
-
* (motion/roles.ts), by their row names (`springs.settle`). Every other
|
|
681
|
-
* spring, UIKit's menu spring under Reduce Motion and the keyboard's
|
|
682
|
-
* included, is not a role. Each role row registers itself when it loads, so
|
|
683
|
-
* a call registers nothing new. A call still puts all 19 role rows in the
|
|
684
|
-
* caller's bundle.
|
|
685
|
-
*/
|
|
686
|
-
function registerSpringsTable() {
|
|
687
|
-
registerMotionTable("springs", SPRING_ROLES, { roles: Object.keys(SPRING_ROLES) });
|
|
688
|
-
}
|
|
689
|
-
//#endregion
|
|
690
|
-
//#region src/composables/internal/attachableAnimator.ts
|
|
691
|
-
const CHANNELS = [
|
|
692
|
-
"x",
|
|
693
|
-
"y",
|
|
694
|
-
"scale",
|
|
695
|
-
"rotate",
|
|
696
|
-
"opacity"
|
|
697
|
-
];
|
|
698
|
-
/** The values of the channels the public API names, and nothing else. */
|
|
699
|
-
function motionValues(values) {
|
|
700
|
-
const out = {};
|
|
701
|
-
if (values == null) return out;
|
|
702
|
-
for (const channel of CHANNELS) {
|
|
703
|
-
const value = values[channel];
|
|
704
|
-
if (typeof value === "number" && Number.isFinite(value)) out[channel] = value;
|
|
705
|
-
}
|
|
706
|
-
return out;
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
* A coast from `from` at `velocity` on the momentum decay a scroll view
|
|
710
|
-
* uses, ending at rest. The theme does not change this decay. An opacity
|
|
711
|
-
* coast stops at 0 or 1.
|
|
712
|
-
*/
|
|
713
|
-
function momentum(from, velocity, threshold, isUnit) {
|
|
714
|
-
const glide = solveDecay({
|
|
715
|
-
from,
|
|
716
|
-
velocity
|
|
717
|
-
});
|
|
718
|
-
const edge = !isUnit ? null : glide.rest < 0 ? 0 : glide.rest > 1 ? 1 : null;
|
|
719
|
-
const duration = (edge == null ? null : glide.timeToReach(edge)) ?? glide.settleTime(threshold);
|
|
720
|
-
const end = edge ?? glide.rest;
|
|
721
|
-
return {
|
|
722
|
-
duration,
|
|
723
|
-
at: (t) => t >= duration ? end : glide.value(t),
|
|
724
|
-
velocity: (t) => t >= duration ? 0 : glide.velocity(t)
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
function snapshot(read) {
|
|
728
|
-
return {
|
|
729
|
-
x: read("x"),
|
|
730
|
-
y: read("y"),
|
|
731
|
-
scale: read("scale"),
|
|
732
|
-
rotate: read("rotate"),
|
|
733
|
-
opacity: read("opacity")
|
|
734
|
-
};
|
|
735
|
-
}
|
|
736
|
-
/**
|
|
737
|
-
* Resolves once every motion of one call has finished, or as soon as any of
|
|
738
|
-
* them is interrupted (`finished` resolves `false`). A later call that takes
|
|
739
|
-
* over one channel ends the whole call where it stopped, as one `animate`
|
|
740
|
-
* does. The other channels move on.
|
|
741
|
-
*/
|
|
742
|
-
async function settledOrTakenOver(moving) {
|
|
743
|
-
if (moving.length === 0) return;
|
|
744
|
-
await new Promise((resolve) => {
|
|
745
|
-
let left = moving.length;
|
|
746
|
-
for (const finished of moving) finished.then((completed) => {
|
|
747
|
-
left -= 1;
|
|
748
|
-
if (!completed || left === 0) resolve();
|
|
749
|
-
});
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
/** A new or remounted element starts from these values. */
|
|
753
|
-
const REST = {
|
|
754
|
-
x: 0,
|
|
755
|
-
y: 0,
|
|
756
|
-
scale: 1,
|
|
757
|
-
rotate: 0,
|
|
758
|
-
opacity: 1
|
|
759
|
-
};
|
|
760
|
-
/**
|
|
761
|
-
* An animator whose element is attached later, through `attach`. It is the
|
|
762
|
-
* one construction `createAnimator` and `useAnimator` share, so the
|
|
763
|
-
* composable has no behavior of its own. Not exported from the package.
|
|
764
|
-
*/
|
|
765
|
-
function createAttachableAnimator() {
|
|
766
|
-
const motion = createMotionEngine(null);
|
|
767
|
-
let element = null;
|
|
768
|
-
let destroyed = false;
|
|
769
|
-
const inactive = () => destroyed || element == null;
|
|
770
|
-
return {
|
|
771
|
-
animator: {
|
|
772
|
-
async animate(target, options) {
|
|
773
|
-
const to = motionValues(target);
|
|
774
|
-
if (inactive() || Object.keys(to).length === 0) return;
|
|
775
|
-
registerSpringsTable();
|
|
776
|
-
const velocity = motionValues(options?.velocity);
|
|
777
|
-
await motion.animate(to, {
|
|
778
|
-
spring: springs.stateChange,
|
|
779
|
-
...Object.keys(velocity).length > 0 ? { velocity } : {}
|
|
780
|
-
}).finished;
|
|
781
|
-
},
|
|
782
|
-
async decay(velocity) {
|
|
783
|
-
if (inactive()) return;
|
|
784
|
-
const given = motionValues(velocity);
|
|
785
|
-
const translate = coast(motion, {
|
|
786
|
-
x: given.x,
|
|
787
|
-
y: given.y
|
|
788
|
-
});
|
|
789
|
-
const others = {};
|
|
790
|
-
for (const channel of [
|
|
791
|
-
"scale",
|
|
792
|
-
"rotate",
|
|
793
|
-
"opacity"
|
|
794
|
-
]) {
|
|
795
|
-
const v0 = given[channel];
|
|
796
|
-
if (v0 != null) {
|
|
797
|
-
const property = channel === "scale" ? "scaleX" : channel;
|
|
798
|
-
others[channel] = momentum(motion.get(property), v0, SETTLE_THRESHOLD[property], channel === "opacity");
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
const moving = [];
|
|
802
|
-
if (Object.keys(translate).length > 0) moving.push(motion.decay(translate).finished);
|
|
803
|
-
if (Object.keys(others).length > 0) moving.push(motion.play(others).finished);
|
|
804
|
-
await settledOrTakenOver(moving);
|
|
805
|
-
},
|
|
806
|
-
set(values) {
|
|
807
|
-
if (!inactive()) motion.set(motionValues(values));
|
|
808
|
-
},
|
|
809
|
-
get() {
|
|
810
|
-
return snapshot((channel) => motion.get(channel));
|
|
811
|
-
},
|
|
812
|
-
getVelocity() {
|
|
813
|
-
return snapshot((channel) => motion.getVelocity(channel));
|
|
814
|
-
},
|
|
815
|
-
stop() {
|
|
816
|
-
if (!inactive()) motion.stop();
|
|
817
|
-
},
|
|
818
|
-
destroy() {
|
|
819
|
-
if (!destroyed) {
|
|
820
|
-
destroyed = true;
|
|
821
|
-
motion.stop();
|
|
822
|
-
motion.dispose();
|
|
823
|
-
}
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
attach: (next) => {
|
|
827
|
-
if (destroyed || next === element) return;
|
|
828
|
-
if (element != null) {
|
|
829
|
-
motion.attach(null);
|
|
830
|
-
motion.stop();
|
|
831
|
-
motion.set(motionValues(REST));
|
|
832
|
-
}
|
|
833
|
-
element = next;
|
|
834
|
-
motion.attach(next);
|
|
835
|
-
}
|
|
836
|
-
};
|
|
837
|
-
}
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region src/composables/createAnimator.ts
|
|
840
|
-
/**
|
|
841
|
-
* 用组件库自己的动效驱动 `element`。`animate` 用状态切换弹簧把通道带到目标值,
|
|
842
|
-
* `decay` 从松手速度开始惯性滑行,`set` 直接跳到某个值,`get` 和
|
|
843
|
-
* `getVelocity` 读当前值和速度,`stop` 原地停下,`destroy` 放开元素。
|
|
844
|
-
* 系统开启「减弱动态效果」时,每次调用都会改走替代方案:触屏上位移变成短淡入淡出,
|
|
845
|
-
* 鼠标环境下直接落到终点。
|
|
846
|
-
*
|
|
847
|
-
* 一个元素只配一个 animator,两个会互相覆盖。在组件里优先用 `useAnimator`。
|
|
848
|
-
*
|
|
849
|
-
* @example
|
|
850
|
-
* ```ts
|
|
851
|
-
* const animator = createAnimator(card)
|
|
852
|
-
* await animator.animate({ x: 0, rotate: 0 }, { velocity: { x: -900 } })
|
|
853
|
-
* void animator.decay({ x: 2400 })
|
|
854
|
-
* animator.destroy()
|
|
855
|
-
* ```
|
|
856
|
-
*/
|
|
857
|
-
function createAnimator(element) {
|
|
858
|
-
const { animator, attach } = createAttachableAnimator();
|
|
859
|
-
attach(element);
|
|
860
|
-
return animator;
|
|
861
|
-
}
|
|
862
|
-
//#endregion
|
|
9
|
+
import { t as isRtlElement } from "./isRtlElement-NHuH48AA.js";
|
|
10
|
+
import { t as holdsTouch } from "./touchHold-DXtx7npm.js";
|
|
11
|
+
import { t as VelocityTracker } from "./VelocityTracker-DgjmootV.js";
|
|
12
|
+
import { getCurrentScope, onScopeDispose, toValue, watch } from "vue";
|
|
863
13
|
//#region src/gestures/arenaTypes.ts
|
|
864
14
|
/** The browser's clock: `performance.now()`, the base of `event.timeStamp`. */
|
|
865
|
-
const browserClock
|
|
15
|
+
const browserClock = {
|
|
866
16
|
now: () => typeof performance === "undefined" ? Date.now() : performance.now(),
|
|
867
17
|
setTimeout: (callback, ms) => setTimeout(callback, ms),
|
|
868
18
|
clearTimeout: (handle) => clearTimeout(handle)
|
|
@@ -921,7 +71,7 @@ var ArenaScheduler = class {
|
|
|
921
71
|
owesResolution = false;
|
|
922
72
|
constructor(options = {}) {
|
|
923
73
|
this.options = options;
|
|
924
|
-
this.clock = options.clock ?? browserClock
|
|
74
|
+
this.clock = options.clock ?? browserClock;
|
|
925
75
|
this.environment = options.environment ?? DEFAULT_ENVIRONMENT;
|
|
926
76
|
}
|
|
927
77
|
/** The current time on the event clock. */
|
|
@@ -2115,10 +1265,10 @@ function eventTime(event, timing) {
|
|
|
2115
1265
|
*/
|
|
2116
1266
|
function documentClock(doc) {
|
|
2117
1267
|
const view = doc.defaultView;
|
|
2118
|
-
if (view == null || view === globalThis) return browserClock
|
|
1268
|
+
if (view == null || view === globalThis) return browserClock;
|
|
2119
1269
|
return {
|
|
2120
|
-
...browserClock
|
|
2121
|
-
now: () => clockOf(doc)?.now() ?? browserClock
|
|
1270
|
+
...browserClock,
|
|
1271
|
+
now: () => clockOf(doc)?.now() ?? browserClock.now()
|
|
2122
1272
|
};
|
|
2123
1273
|
}
|
|
2124
1274
|
/** A touch list as an array; a synthetic event may carry none. */
|
|
@@ -5706,171 +4856,8 @@ function travel(touch) {
|
|
|
5706
4856
|
return Math.hypot(touch.x - touch.startX, touch.y - touch.startY);
|
|
5707
4857
|
}
|
|
5708
4858
|
//#endregion
|
|
5709
|
-
//#region src/gestures/VelocityTracker.ts
|
|
5710
|
-
const ZERO$2 = {
|
|
5711
|
-
x: 0,
|
|
5712
|
-
y: 0
|
|
5713
|
-
};
|
|
5714
|
-
const PAN_CURRENT_WEIGHT = UIKIT_VELOCITY.currentWeight.value;
|
|
5715
|
-
const SCROLL_CURRENT_WEIGHT = UIKIT_VELOCITY.scrollReleaseWeight.value;
|
|
5716
|
-
function blend(weight, current, previous) {
|
|
5717
|
-
return {
|
|
5718
|
-
x: weight * current.x + (1 - weight) * previous.x,
|
|
5719
|
-
y: weight * current.y + (1 - weight) * previous.y
|
|
5720
|
-
};
|
|
5721
|
-
}
|
|
5722
|
-
var VelocityTracker = class {
|
|
5723
|
-
stillness;
|
|
5724
|
-
/** The newest sample added, moved or not. */
|
|
5725
|
-
newest = null;
|
|
5726
|
-
/**
|
|
5727
|
-
* The newest moved samples, oldest first (the touch-down counts as the
|
|
5728
|
-
* first); the filter reads the last three.
|
|
5729
|
-
*/
|
|
5730
|
-
moved = [];
|
|
5731
|
-
/** Moved samples since the touch-down. */
|
|
5732
|
-
moves = 0;
|
|
5733
|
-
/** The newest pan value, and the one before it. */
|
|
5734
|
-
pan = ZERO$2;
|
|
5735
|
-
previousPan = ZERO$2;
|
|
5736
|
-
constructor(options = {}) {
|
|
5737
|
-
this.stillness = options.stillness ?? UIKIT_VELOCITY.stillness.value;
|
|
5738
|
-
}
|
|
5739
|
-
/** Forget every sample (a new gesture). */
|
|
5740
|
-
reset() {
|
|
5741
|
-
this.newest = null;
|
|
5742
|
-
this.moved = [];
|
|
5743
|
-
this.moves = 0;
|
|
5744
|
-
this.pan = ZERO$2;
|
|
5745
|
-
this.previousPan = ZERO$2;
|
|
5746
|
-
}
|
|
5747
|
-
/**
|
|
5748
|
-
* Record a position. Timestamps must not go backwards (an older sample is
|
|
5749
|
-
* ignored), and a moved sample at the newest moved sample's timestamp
|
|
5750
|
-
* replaces it. A sample at the newest position is not motion: it changes
|
|
5751
|
-
* no velocity, unless `isMotion` says the contact moved anyway (a pinch's
|
|
5752
|
-
* value holding while both fingers move, which reads as zero velocity for
|
|
5753
|
-
* that interval).
|
|
5754
|
-
*/
|
|
5755
|
-
add(x, y, time, { isMotion = false } = {}) {
|
|
5756
|
-
if (this.newest != null && time < this.newest.time) return;
|
|
5757
|
-
this.newest = {
|
|
5758
|
-
x,
|
|
5759
|
-
y,
|
|
5760
|
-
time
|
|
5761
|
-
};
|
|
5762
|
-
const last = this.moved[this.moved.length - 1];
|
|
5763
|
-
if (last != null && x === last.x && y === last.y && !isMotion) return;
|
|
5764
|
-
if (last != null && time === last.time) this.moved[this.moved.length - 1] = {
|
|
5765
|
-
x,
|
|
5766
|
-
y,
|
|
5767
|
-
time
|
|
5768
|
-
};
|
|
5769
|
-
else {
|
|
5770
|
-
this.moved.push({
|
|
5771
|
-
x,
|
|
5772
|
-
y,
|
|
5773
|
-
time
|
|
5774
|
-
});
|
|
5775
|
-
if (this.moved.length > 3) this.moved.shift();
|
|
5776
|
-
if (last != null) {
|
|
5777
|
-
this.moves += 1;
|
|
5778
|
-
this.previousPan = this.pan;
|
|
5779
|
-
}
|
|
5780
|
-
}
|
|
5781
|
-
this.pan = panVelocity(this.moved);
|
|
5782
|
-
}
|
|
5783
|
-
/**
|
|
5784
|
-
* Re-base the samples by an offset (a recognizer whose value was set
|
|
5785
|
-
* mid-gesture): every interval, the moved-sample count and the velocity
|
|
5786
|
-
* carry on unchanged.
|
|
5787
|
-
*/
|
|
5788
|
-
offsetBy(dx, dy) {
|
|
5789
|
-
const shift = (sample) => ({
|
|
5790
|
-
...sample,
|
|
5791
|
-
x: sample.x + dx,
|
|
5792
|
-
y: sample.y + dy
|
|
5793
|
-
});
|
|
5794
|
-
this.newest = this.newest == null ? null : shift(this.newest);
|
|
5795
|
-
this.moved = this.moved.map(shift);
|
|
5796
|
-
}
|
|
5797
|
-
/**
|
|
5798
|
-
* Re-base the samples by a factor (a pinch whose scale was set
|
|
5799
|
-
* mid-gesture): positions and velocities scale with it, and the
|
|
5800
|
-
* moved-sample count carries on.
|
|
5801
|
-
*/
|
|
5802
|
-
scaleBy(factor) {
|
|
5803
|
-
const scale = (sample) => ({
|
|
5804
|
-
...sample,
|
|
5805
|
-
x: sample.x * factor,
|
|
5806
|
-
y: sample.y * factor
|
|
5807
|
-
});
|
|
5808
|
-
this.newest = this.newest == null ? null : scale(this.newest);
|
|
5809
|
-
this.moved = this.moved.map(scale);
|
|
5810
|
-
this.pan = {
|
|
5811
|
-
x: this.pan.x * factor,
|
|
5812
|
-
y: this.pan.y * factor
|
|
5813
|
-
};
|
|
5814
|
-
this.previousPan = {
|
|
5815
|
-
x: this.previousPan.x * factor,
|
|
5816
|
-
y: this.previousPan.y * factor
|
|
5817
|
-
};
|
|
5818
|
-
}
|
|
5819
|
-
/** Record every sample in order. */
|
|
5820
|
-
addSamples(samples) {
|
|
5821
|
-
for (const sample of samples) this.add(sample.x, sample.y, sample.time);
|
|
5822
|
-
}
|
|
5823
|
-
/** The newest sample, if any. */
|
|
5824
|
-
get lastSample() {
|
|
5825
|
-
return this.newest;
|
|
5826
|
-
}
|
|
5827
|
-
/**
|
|
5828
|
-
* The pan's velocity in px/s. Pass the release's event time to read the
|
|
5829
|
-
* release velocity of a dragged surface: 0 after a rest longer than the
|
|
5830
|
-
* stillness interval, or with fewer than two moved samples (AST-100 FR2).
|
|
5831
|
-
*/
|
|
5832
|
-
velocity(releaseTime) {
|
|
5833
|
-
if (releaseTime != null && !this.releases(releaseTime)) return ZERO$2;
|
|
5834
|
-
return this.pan;
|
|
5835
|
-
}
|
|
5836
|
-
/**
|
|
5837
|
-
* A scrolling surface's release velocity in px/s (paging, a wheel): 0.25
|
|
5838
|
-
* times the newest pan value plus 0.75 times the previous one, with the
|
|
5839
|
-
* same stillness and two-moved-sample rules (AST-100 FR2).
|
|
5840
|
-
*/
|
|
5841
|
-
scrollVelocity(releaseTime) {
|
|
5842
|
-
if (!this.releases(releaseTime)) return ZERO$2;
|
|
5843
|
-
return blend(SCROLL_CURRENT_WEIGHT, this.pan, this.previousPan);
|
|
5844
|
-
}
|
|
5845
|
-
releases(releaseTime) {
|
|
5846
|
-
const last = this.moved[this.moved.length - 1];
|
|
5847
|
-
return this.moves >= 2 && last != null && releaseTime - last.time <= this.stillness;
|
|
5848
|
-
}
|
|
5849
|
-
};
|
|
5850
|
-
/**
|
|
5851
|
-
* UIPanGestureRecognizer's filter over the newest moved samples: 0.2 x the
|
|
5852
|
-
* newest interval's velocity + 0.8 x the previous one's; one interval so far
|
|
5853
|
-
* is reported whole, as UIKit does.
|
|
5854
|
-
*/
|
|
5855
|
-
function panVelocity(moved) {
|
|
5856
|
-
const n = moved.length;
|
|
5857
|
-
if (n < 2) return ZERO$2;
|
|
5858
|
-
const current = pairVelocity(moved[n - 2], moved[n - 1]);
|
|
5859
|
-
if (n === 2) return current;
|
|
5860
|
-
return blend(PAN_CURRENT_WEIGHT, current, pairVelocity(moved[n - 3], moved[n - 2]));
|
|
5861
|
-
}
|
|
5862
|
-
/** Instantaneous velocity (px/s) between two samples, zero across no time. */
|
|
5863
|
-
function pairVelocity(start, end) {
|
|
5864
|
-
const dt = end.time - start.time;
|
|
5865
|
-
if (dt <= 0) return ZERO$2;
|
|
5866
|
-
return {
|
|
5867
|
-
x: (end.x - start.x) / dt * 1e3,
|
|
5868
|
-
y: (end.y - start.y) / dt * 1e3
|
|
5869
|
-
};
|
|
5870
|
-
}
|
|
5871
|
-
//#endregion
|
|
5872
4859
|
//#region src/gestures/PanGestureRecognizer.ts
|
|
5873
|
-
const ZERO
|
|
4860
|
+
const ZERO = {
|
|
5874
4861
|
x: 0,
|
|
5875
4862
|
y: 0
|
|
5876
4863
|
};
|
|
@@ -5911,7 +4898,7 @@ var PanGestureRecognizer = class extends GestureRecognizer {
|
|
|
5911
4898
|
/** The axis a `lockAxis` pan locked to when it began. */
|
|
5912
4899
|
lockedAxis = null;
|
|
5913
4900
|
/** The movement the begin threshold took (excluded from `translation()`). */
|
|
5914
|
-
travelAtBegan = ZERO
|
|
4901
|
+
travelAtBegan = ZERO;
|
|
5915
4902
|
tracker;
|
|
5916
4903
|
/**
|
|
5917
4904
|
* Read once per press. A finger that lands later keeps the press's
|
|
@@ -5921,12 +4908,12 @@ var PanGestureRecognizer = class extends GestureRecognizer {
|
|
|
5921
4908
|
/** The lift's event time once the pan ended: its release (AST-100 FR2). */
|
|
5922
4909
|
releaseTime = void 0;
|
|
5923
4910
|
/** The centroid where the gesture started, in client px. */
|
|
5924
|
-
origin = ZERO
|
|
4911
|
+
origin = ZERO;
|
|
5925
4912
|
/** Re-basing that keeps the translation continuous across finger changes. */
|
|
5926
|
-
adjust = ZERO
|
|
4913
|
+
adjust = ZERO;
|
|
5927
4914
|
/** Translation since touch-down, before `setTranslation` offsets. */
|
|
5928
|
-
raw = ZERO
|
|
5929
|
-
offset = ZERO
|
|
4915
|
+
raw = ZERO;
|
|
4916
|
+
offset = ZERO;
|
|
5930
4917
|
/** How a `firstMoveDecides` pan read the touch's first move, once it moved. */
|
|
5931
4918
|
firstMove = null;
|
|
5932
4919
|
constructor(options = {}) {
|
|
@@ -6016,9 +5003,9 @@ var PanGestureRecognizer = class extends GestureRecognizer {
|
|
|
6016
5003
|
const first = touches[0];
|
|
6017
5004
|
if (this.hysteresisFor != null && first != null) this.hysteresis = this.hysteresisFor(first);
|
|
6018
5005
|
this.origin = centroid(this.touches.values());
|
|
6019
|
-
this.adjust = ZERO
|
|
6020
|
-
this.raw = ZERO
|
|
6021
|
-
this.offset = ZERO
|
|
5006
|
+
this.adjust = ZERO;
|
|
5007
|
+
this.raw = ZERO;
|
|
5008
|
+
this.offset = ZERO;
|
|
6022
5009
|
this.tracker.reset();
|
|
6023
5010
|
this.tracker.add(this.origin.x, this.origin.y, event.time);
|
|
6024
5011
|
} else this.rebase(new Set(touches.map((touch) => touch.id)), "added");
|
|
@@ -6056,11 +5043,11 @@ var PanGestureRecognizer = class extends GestureRecognizer {
|
|
|
6056
5043
|
}
|
|
6057
5044
|
reset() {
|
|
6058
5045
|
this.lockedAxis = null;
|
|
6059
|
-
this.travelAtBegan = ZERO
|
|
6060
|
-
this.origin = ZERO
|
|
6061
|
-
this.adjust = ZERO
|
|
6062
|
-
this.raw = ZERO
|
|
6063
|
-
this.offset = ZERO
|
|
5046
|
+
this.travelAtBegan = ZERO;
|
|
5047
|
+
this.origin = ZERO;
|
|
5048
|
+
this.adjust = ZERO;
|
|
5049
|
+
this.raw = ZERO;
|
|
5050
|
+
this.offset = ZERO;
|
|
6064
5051
|
this.releaseTime = void 0;
|
|
6065
5052
|
this.firstMove = null;
|
|
6066
5053
|
this.tracker.reset();
|
|
@@ -6187,824 +5174,21 @@ var PanGestureRecognizer = class extends GestureRecognizer {
|
|
|
6187
5174
|
}
|
|
6188
5175
|
};
|
|
6189
5176
|
//#endregion
|
|
6190
|
-
//#region src/gestures/
|
|
6191
|
-
|
|
6192
|
-
|
|
6193
|
-
|
|
6194
|
-
|
|
6195
|
-
|
|
6196
|
-
|
|
6197
|
-
|
|
6198
|
-
const recognizer = new PanGestureRecognizer({
|
|
6199
|
-
name: "pan",
|
|
6200
|
-
...options.recognizer,
|
|
6201
|
-
direction: axis === "x" ? "horizontal" : axis === "y" ? "vertical" : "any"
|
|
6202
|
-
});
|
|
6203
|
-
const along = (point) => axis === "x" ? {
|
|
6204
|
-
x: point.x,
|
|
6205
|
-
y: 0
|
|
6206
|
-
} : axis === "y" ? {
|
|
6207
|
-
x: 0,
|
|
6208
|
-
y: point.y
|
|
6209
|
-
} : {
|
|
6210
|
-
x: point.x,
|
|
6211
|
-
y: point.y
|
|
5177
|
+
//#region src/gestures/useAttachment.ts
|
|
5178
|
+
function useAttachment(target, attach, key = () => null) {
|
|
5179
|
+
if (typeof document === "undefined") return;
|
|
5180
|
+
let release = null;
|
|
5181
|
+
const releaseNow = () => {
|
|
5182
|
+
const current = release;
|
|
5183
|
+
release = null;
|
|
5184
|
+
current?.();
|
|
6212
5185
|
};
|
|
6213
|
-
|
|
6214
|
-
|
|
6215
|
-
|
|
6216
|
-
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
input = touch == null ? "touch" : touch.scrollType != null ? "scroll" : touch.pointerType;
|
|
6220
|
-
}
|
|
6221
|
-
onPan({
|
|
6222
|
-
state,
|
|
6223
|
-
translation: along(recognizer.translation()),
|
|
6224
|
-
totalTranslation: along(recognizer.totalTranslation()),
|
|
6225
|
-
velocity: state === "cancelled" ? { ...ZERO } : along(recognizer.velocity()),
|
|
6226
|
-
input
|
|
6227
|
-
});
|
|
6228
|
-
});
|
|
6229
|
-
let detach = getGestureHost(element.ownerDocument).attach(element, recognizer);
|
|
6230
|
-
return { destroy() {
|
|
6231
|
-
const current = detach;
|
|
6232
|
-
detach = null;
|
|
6233
|
-
current?.();
|
|
6234
|
-
} };
|
|
6235
|
-
}
|
|
6236
|
-
/**
|
|
6237
|
-
* Report drags on `element` as values. The drag claims its touch at UIKit's
|
|
6238
|
-
* 10 pt, as `UIPanGestureRecognizer` does, so a tap stays a tap. The pan sets
|
|
6239
|
-
* the element's `touch-action` for the axis.
|
|
6240
|
-
* @example
|
|
6241
|
-
* ```ts
|
|
6242
|
-
* const pan = createPanGesture(card, {
|
|
6243
|
-
* axis: 'x',
|
|
6244
|
-
* onPan: ({ state, translation }) => {
|
|
6245
|
-
* card.style.translate = state === 'changed' ? `${translation.x}px` : ''
|
|
6246
|
-
* },
|
|
6247
|
-
* })
|
|
6248
|
-
* // Later:
|
|
6249
|
-
* pan.destroy()
|
|
6250
|
-
* ```
|
|
6251
|
-
*/
|
|
6252
|
-
function createPanGesture(element, options) {
|
|
6253
|
-
const { axis, onPan } = options;
|
|
6254
|
-
return createPan(element, {
|
|
6255
|
-
axis,
|
|
6256
|
-
onPan: ({ state, translation, velocity }) => {
|
|
6257
|
-
onPan({
|
|
6258
|
-
state,
|
|
6259
|
-
translation,
|
|
6260
|
-
velocity
|
|
6261
|
-
});
|
|
6262
|
-
}
|
|
6263
|
-
});
|
|
6264
|
-
}
|
|
6265
|
-
//#endregion
|
|
6266
|
-
//#region src/motion/projection.ts
|
|
6267
|
-
/**
|
|
6268
|
-
* @file projection.ts
|
|
6269
|
-
* @input A release position and velocity, candidate rest points
|
|
6270
|
-
* @output Exports `projectDistance` / `project` (WWDC18's momentum
|
|
6271
|
-
* projection) and `selectSnapPoint` (the release target UIKit-style)
|
|
6272
|
-
* @position Pure math; no DOM, no React
|
|
6273
|
-
*
|
|
6274
|
-
* WWDC18 "Designing Fluid Interfaces" (session 803): a thrown object goes to
|
|
6275
|
-
* the endpoint nearest to where it WOULD coast if it were scrolled, not the
|
|
6276
|
-
* endpoint nearest to where the finger let go. The talk's projection
|
|
6277
|
-
* function, verbatim in units/s:
|
|
6278
|
-
*
|
|
6279
|
-
* func project(initialVelocity: CGFloat, decelerationRate: CGFloat) -> CGFloat {
|
|
6280
|
-
* return (initialVelocity / 1000.0) * decelerationRate / (1.0 - decelerationRate)
|
|
6281
|
-
* }
|
|
6282
|
-
*
|
|
6283
|
-
* used with `UIScrollView.DecelerationRate.normal`. A slow release projects
|
|
6284
|
-
* onto itself, so it places; a flick continues past the finger.
|
|
6285
|
-
*/
|
|
6286
|
-
/** Distance a surface released at `velocity` units/s coasts (WWDC18). */
|
|
6287
|
-
function projectDistance(velocity, rate = scroll.decelerationRate.normal) {
|
|
6288
|
-
if (!(rate > 0 && rate < 1)) throw new RangeError(`projection: rate must be in (0, 1), got ${rate}`);
|
|
6289
|
-
return velocity / 1e3 * rate / (1 - rate);
|
|
6290
|
-
}
|
|
6291
|
-
/** Where a surface released at `position` with `velocity` would come to rest. */
|
|
6292
|
-
function project(position, velocity, rate = scroll.decelerationRate.normal) {
|
|
6293
|
-
return position + projectDistance(velocity, rate);
|
|
6294
|
-
}
|
|
6295
|
-
/**
|
|
6296
|
-
* The rest point a release goes to: the one nearest the projected rest
|
|
6297
|
-
* position. This is the math primitive (projection + nearest); the release
|
|
6298
|
-
* policy on top of it (a flick advances at least one detent, a release moving
|
|
6299
|
-
* back toward its start cancels) is `resolveSnapPoint` (resolveSnapPoint.ts), so a
|
|
6300
|
-
* component's release rule calls that rather than adding its own. `fromIndex` + `maxSteps` limit how many points away from the
|
|
6301
|
-
* starting one a single release may travel (by index order; pass points
|
|
6302
|
-
* sorted along the axis). Ties go to the point in the direction of travel.
|
|
6303
|
-
*
|
|
6304
|
-
* @example
|
|
6305
|
-
* ```
|
|
6306
|
-
* // A sheet with detents at 0, 300 and 600 px, released at 320 px moving
|
|
6307
|
-
* // 900 px/s toward 600: projected ≈ 769 → 600.
|
|
6308
|
-
* selectSnapPoint([0, 300, 600], {position: 320, velocity: 900});
|
|
6309
|
-
* ```
|
|
6310
|
-
*/
|
|
6311
|
-
function selectSnapPoint(points, { position, velocity, rate = scroll.decelerationRate.normal, fromIndex, maxSteps }) {
|
|
6312
|
-
if (points.length === 0) throw new RangeError("projection: selectSnapPoint needs at least one point");
|
|
6313
|
-
const projected = project(position, velocity, rate);
|
|
6314
|
-
let lo = 0;
|
|
6315
|
-
let hi = points.length - 1;
|
|
6316
|
-
if (fromIndex != null && maxSteps != null) {
|
|
6317
|
-
const from = Math.min(Math.max(fromIndex, 0), points.length - 1);
|
|
6318
|
-
lo = Math.max(lo, from - maxSteps);
|
|
6319
|
-
hi = Math.min(hi, from + maxSteps);
|
|
6320
|
-
}
|
|
6321
|
-
let best = lo;
|
|
6322
|
-
let bestDistance = Infinity;
|
|
6323
|
-
for (let i = lo; i <= hi; i++) {
|
|
6324
|
-
const distance = Math.abs(points[i] - projected);
|
|
6325
|
-
const isTie = Math.abs(distance - bestDistance) < 1e-9;
|
|
6326
|
-
const isAhead = Math.sign(points[i] - points[best]) === Math.sign(velocity);
|
|
6327
|
-
if (distance < bestDistance - 1e-9 || isTie && isAhead) {
|
|
6328
|
-
best = i;
|
|
6329
|
-
bestDistance = distance;
|
|
6330
|
-
}
|
|
6331
|
-
}
|
|
6332
|
-
return {
|
|
6333
|
-
index: best,
|
|
6334
|
-
value: points[best],
|
|
6335
|
-
projected
|
|
6336
|
-
};
|
|
6337
|
-
}
|
|
6338
|
-
//#endregion
|
|
6339
|
-
//#region src/motion/resolveSnapPoint.ts
|
|
6340
|
-
/**
|
|
6341
|
-
* @file resolveSnapPoint.ts
|
|
6342
|
-
* @input A release (position and velocity on one axis), the points it can
|
|
6343
|
-
* land on, and the release policy's thresholds
|
|
6344
|
-
* @output Exports resolveSnapPoint: the index of the snap point a release lands on,
|
|
6345
|
-
* and the projected rest position it was judged from
|
|
6346
|
-
* @position The release policy of the motion foundation, on
|
|
6347
|
-
* `selectSnapPoint` (projection.ts), which stays the math primitive
|
|
6348
|
-
* (projection + nearest). Pure: no DOM, no React. Internal to core: not
|
|
6349
|
-
* exported from the package or any barrel (resolveSnapPoint.test.ts locks
|
|
6350
|
-
* that). A component's release rule calls it with its own points and
|
|
6351
|
-
* thresholds; this is the one "where does a release land" helper, so a
|
|
6352
|
-
* second one should not be added beside it.
|
|
6353
|
-
*
|
|
6354
|
-
* - A slow release lands on the snap point nearest where it would come to rest:
|
|
6355
|
-
* its position, or, with `projection`, its position plus the distance it
|
|
6356
|
-
* would coast at its velocity (projection.ts). Below
|
|
6357
|
-
* `projection.minSpeed` nothing is projected, so it lands on the snap point
|
|
6358
|
-
* nearest where it was let go. A tie goes the way a projected release
|
|
6359
|
-
* moves, and otherwise to the earlier snap point (`selectSnapPoint`).
|
|
6360
|
-
* - A flick (`flickThreshold` or faster) lands at least on the next snap point
|
|
6361
|
-
* beyond its position in the direction it moves, or on the nearest
|
|
6362
|
-
* snap point to its projection if that is farther. A snap point within
|
|
6363
|
-
* `tolerance` of the position counts as reached, so the flick goes on to
|
|
6364
|
-
* the one after it. With `flickPastProjection`, a flick lands on the first
|
|
6365
|
-
* snap point at or past its projection instead. A projection that passes a
|
|
6366
|
-
* snap point carries the flick on.
|
|
6367
|
-
* - With `start` (where the drag began), a release moving back toward it
|
|
6368
|
-
* cancels to the snap point nearest `start`, whatever its travel so far or its
|
|
6369
|
-
* speed.
|
|
6370
|
-
* - With `fromIndex` and `maxSteps`, a release lands at most `maxSteps`
|
|
6371
|
-
* points away from the one at `fromIndex` (a pager's one page per
|
|
6372
|
-
* release).
|
|
6373
|
-
*
|
|
6374
|
-
* Snap points are ascending positions on the axis; velocities are in the same
|
|
6375
|
-
* units per second, positive toward larger positions.
|
|
6376
|
-
*/
|
|
6377
|
-
/** The deceleration rate whose projection reaches `seconds` of the velocity. */
|
|
6378
|
-
function rateForProjection(seconds) {
|
|
6379
|
-
const ms = seconds * 1e3;
|
|
6380
|
-
return ms / (1 + ms);
|
|
6381
|
-
}
|
|
6382
|
-
/** The index of the snap point nearest `position` (the first on a tie). */
|
|
6383
|
-
function nearestIndex$1(points, position) {
|
|
6384
|
-
let best = 0;
|
|
6385
|
-
for (let i = 1; i < points.length; i += 1) if (Math.abs(points[i] - position) < Math.abs(points[best] - position)) best = i;
|
|
6386
|
-
return best;
|
|
6387
|
-
}
|
|
6388
|
-
/**
|
|
6389
|
-
* The snap point a release lands on.
|
|
6390
|
-
*
|
|
6391
|
-
* @example
|
|
6392
|
-
* ```
|
|
6393
|
-
* // Snap points at 0, 300 and 640 px. Released at 300 px moving toward 640 at
|
|
6394
|
-
* // 1200 px/s, a flick: on to 640, although its projection (420 px) is
|
|
6395
|
-
* // nearer 300.
|
|
6396
|
-
* resolveSnapPoint({
|
|
6397
|
-
* points: [0, 300, 640],
|
|
6398
|
-
* position: 300,
|
|
6399
|
-
* velocity: 1200,
|
|
6400
|
-
* flickThreshold: 1008,
|
|
6401
|
-
* tolerance: 1,
|
|
6402
|
-
* projection: {seconds: 0.1, minSpeed: 250},
|
|
6403
|
-
* start: 0,
|
|
6404
|
-
* }); // {index: 2, projected: 420}
|
|
6405
|
-
* ```
|
|
6406
|
-
*/
|
|
6407
|
-
function resolveSnapPoint({ points, position, velocity, flickThreshold, tolerance = 0, flickPastProjection = false, projection, start, fromIndex, maxSteps }) {
|
|
6408
|
-
if (points.length === 0) throw new RangeError("resolveSnapPoint needs at least one snap point");
|
|
6409
|
-
const choice = selectSnapPoint(points, {
|
|
6410
|
-
position,
|
|
6411
|
-
velocity: projection == null || Math.abs(velocity) < (projection.minSpeed ?? 0) ? 0 : velocity,
|
|
6412
|
-
rate: projection == null ? void 0 : rateForProjection(projection.seconds),
|
|
6413
|
-
fromIndex,
|
|
6414
|
-
maxSteps
|
|
6415
|
-
});
|
|
6416
|
-
let index = choice.index;
|
|
6417
|
-
if (Math.abs(velocity) >= flickThreshold) {
|
|
6418
|
-
let next = -1;
|
|
6419
|
-
if (velocity > 0) next = points.findIndex((d) => d > position + tolerance);
|
|
6420
|
-
else for (let i = points.length - 1; i >= 0 && next === -1; i -= 1) if (points[i] < position - tolerance) next = i;
|
|
6421
|
-
if (next !== -1 && (velocity > 0 ? next > index : next < index)) index = next;
|
|
6422
|
-
if (flickPastProjection) {
|
|
6423
|
-
const projected = choice.projected;
|
|
6424
|
-
let past = velocity > 0 ? points.length - 1 : 0;
|
|
6425
|
-
if (velocity > 0) {
|
|
6426
|
-
const at = points.findIndex((d) => d >= projected - tolerance);
|
|
6427
|
-
past = at === -1 ? past : at;
|
|
6428
|
-
} else for (let i = points.length - 1; i >= 0; i -= 1) if (points[i] <= projected + tolerance) {
|
|
6429
|
-
past = i;
|
|
6430
|
-
break;
|
|
6431
|
-
}
|
|
6432
|
-
if (velocity > 0 ? past > index : past < index) index = past;
|
|
6433
|
-
}
|
|
6434
|
-
}
|
|
6435
|
-
if (start != null && velocity !== 0 && Math.sign(velocity) === Math.sign(start - position)) index = nearestIndex$1(points, start);
|
|
6436
|
-
if (fromIndex != null && maxSteps != null) {
|
|
6437
|
-
const from = Math.min(Math.max(fromIndex, 0), points.length - 1);
|
|
6438
|
-
index = Math.min(Math.max(index, from - maxSteps), from + maxSteps);
|
|
6439
|
-
}
|
|
6440
|
-
return {
|
|
6441
|
-
index,
|
|
6442
|
-
projected: choice.projected
|
|
6443
|
-
};
|
|
6444
|
-
}
|
|
6445
|
-
//#endregion
|
|
6446
|
-
//#region src/dragToSnapPoints/compositorSettle.ts
|
|
6447
|
-
/** Keyframes per second: twice a 60 Hz display's frame rate. */
|
|
6448
|
-
const SAMPLE_HZ = 120;
|
|
6449
|
-
/** The longest a settle plays (ms). */
|
|
6450
|
-
const MAX_MS = 3e3;
|
|
6451
|
-
/** The keyframe times (ms): a fixed grid, plus each time the curve crosses a bend. */
|
|
6452
|
-
function keyframeTimes(valueAt, durationMs, bends) {
|
|
6453
|
-
const steps = Math.ceil(durationMs / 1e3 * SAMPLE_HZ);
|
|
6454
|
-
const grid = [];
|
|
6455
|
-
for (let step = 0; step <= steps; step += 1) grid.push(Math.min(durationMs, step / SAMPLE_HZ * 1e3));
|
|
6456
|
-
const times = [...grid];
|
|
6457
|
-
for (const bend of bends) for (let index = 0; index < grid.length - 1; index += 1) {
|
|
6458
|
-
let low = grid[index];
|
|
6459
|
-
let high = grid[index + 1];
|
|
6460
|
-
if ((valueAt(low) - bend) * (valueAt(high) - bend) >= 0) continue;
|
|
6461
|
-
for (let iteration = 0; iteration < 24; iteration += 1) {
|
|
6462
|
-
const middle = (low + high) / 2;
|
|
6463
|
-
if ((valueAt(low) - bend) * (valueAt(middle) - bend) <= 0) high = middle;
|
|
6464
|
-
else low = middle;
|
|
6465
|
-
}
|
|
6466
|
-
times.push((low + high) / 2);
|
|
6467
|
-
}
|
|
6468
|
-
return times.sort((a, b) => a - b);
|
|
6469
|
-
}
|
|
6470
|
-
/**
|
|
6471
|
-
* Plays `curve` on `parts` from now. `onPass` runs on the first frame the
|
|
6472
|
-
* value is past its offset in its direction, and `onFinish` on the first
|
|
6473
|
-
* frame after the curve ends. A part with no Web Animations (a test DOM)
|
|
6474
|
-
* shows the end pose at once, and the callbacks keep the curve's times.
|
|
6475
|
-
*/
|
|
6476
|
-
function playCompositorSettle({ curve, parts, requestFrame, onPass, onFinish }) {
|
|
6477
|
-
const durationMs = Math.min(MAX_MS, Math.max(0, curve.settleTime(SETTLE_THRESHOLD.x) * 1e3));
|
|
6478
|
-
const started = motionNow();
|
|
6479
|
-
let stopped = false;
|
|
6480
|
-
let passed = onPass == null;
|
|
6481
|
-
const valueAt = (ms) => curve.value(ms / 1e3);
|
|
6482
|
-
const times = keyframeTimes(valueAt, durationMs, new Set(parts.flatMap((part) => part.bends ?? [])));
|
|
6483
|
-
const values = times.map((ms, index) => index === times.length - 1 ? curve.to : valueAt(ms));
|
|
6484
|
-
const offsets = times.map((ms) => durationMs === 0 ? 1 : ms / durationMs);
|
|
6485
|
-
const animations = durationMs === 0 ? [] : parts.filter((part) => typeof part.element.animate === "function").map((part) => {
|
|
6486
|
-
const end = part.offset(curve.to);
|
|
6487
|
-
const animation = part.element.animate(values.map((value, index) => ({
|
|
6488
|
-
offset: offsets[index],
|
|
6489
|
-
translate: `${part.offset(value) - end}px 0px`
|
|
6490
|
-
})), {
|
|
6491
|
-
duration: durationMs,
|
|
6492
|
-
easing: "linear",
|
|
6493
|
-
fill: "backwards"
|
|
6494
|
-
});
|
|
6495
|
-
animation.startTime = started;
|
|
6496
|
-
return animation;
|
|
6497
|
-
});
|
|
6498
|
-
const elapsedSeconds = () => Math.min(durationMs, Math.max(0, motionNow() - started)) / 1e3;
|
|
6499
|
-
const presented = () => curve.value(elapsedSeconds());
|
|
6500
|
-
const cancelAll = () => {
|
|
6501
|
-
for (const animation of animations) animation.cancel();
|
|
6502
|
-
};
|
|
6503
|
-
const stop = () => {
|
|
6504
|
-
const value = presented();
|
|
6505
|
-
stopped = true;
|
|
6506
|
-
cancelAll();
|
|
6507
|
-
return value;
|
|
6508
|
-
};
|
|
6509
|
-
const frame = () => {
|
|
6510
|
-
if (stopped) return;
|
|
6511
|
-
const seconds = elapsedSeconds();
|
|
6512
|
-
if (!passed && onPass != null) {
|
|
6513
|
-
if ((curve.value(seconds) - onPass.offset) * onPass.direction >= 0) {
|
|
6514
|
-
passed = true;
|
|
6515
|
-
onPass.call();
|
|
6516
|
-
if (stopped) return;
|
|
6517
|
-
}
|
|
6518
|
-
}
|
|
6519
|
-
if (seconds * 1e3 >= durationMs) {
|
|
6520
|
-
stopped = true;
|
|
6521
|
-
cancelAll();
|
|
6522
|
-
onFinish();
|
|
6523
|
-
return;
|
|
6524
|
-
}
|
|
6525
|
-
requestFrame(frame);
|
|
6526
|
-
};
|
|
6527
|
-
requestFrame(frame);
|
|
6528
|
-
return {
|
|
6529
|
-
presented,
|
|
6530
|
-
velocity: () => curve.velocity(elapsedSeconds()),
|
|
6531
|
-
stop
|
|
6532
|
-
};
|
|
6533
|
-
}
|
|
6534
|
-
//#endregion
|
|
6535
|
-
//#region src/dragToSnapPoints/createSnapDrag.ts
|
|
6536
|
-
/** The document timeline's clock, which the animator runs on. */
|
|
6537
|
-
const now = () => performance.now();
|
|
6538
|
-
/** Runs `callback` in the next animation frame (a timer without one). */
|
|
6539
|
-
function requestFrame(callback) {
|
|
6540
|
-
if (typeof requestAnimationFrame === "function") requestAnimationFrame(() => callback());
|
|
6541
|
-
else setTimeout(callback, 16);
|
|
6542
|
-
}
|
|
6543
|
-
/**
|
|
6544
|
-
* Where `element` is drawn now, read from the inline value an animator left
|
|
6545
|
-
* on it. A drag destroyed and created again leaves it where it stopped. An
|
|
6546
|
-
* axis it does not set reads 0.
|
|
6547
|
-
*/
|
|
6548
|
-
function drawnAt(element, customProperty) {
|
|
6549
|
-
if (customProperty != null) {
|
|
6550
|
-
const value = Number.parseFloat(element.style.getPropertyValue(customProperty));
|
|
6551
|
-
return {
|
|
6552
|
-
x: Number.isFinite(value) ? value : 0,
|
|
6553
|
-
y: 0
|
|
6554
|
-
};
|
|
6555
|
-
}
|
|
6556
|
-
const [x = 0, y = 0] = element.style.getPropertyValue("translate").trim().split(/\s+/).map((part) => Number.parseFloat(part)).map((value) => Number.isFinite(value) ? value : 0);
|
|
6557
|
-
return {
|
|
6558
|
-
x,
|
|
6559
|
-
y
|
|
6560
|
-
};
|
|
6561
|
-
}
|
|
6562
|
-
/** Drops a point that is not a finite number, with a dev warning. */
|
|
6563
|
-
function sortedSnapPoints(snapPoints) {
|
|
6564
|
-
const usable = snapPoints.filter((point) => Number.isFinite(point));
|
|
6565
|
-
if (usable.length < snapPoints.length) devWarn("createDragToSnapPoints", "snapPoints must be numbers; the others are ignored.");
|
|
6566
|
-
return usable.sort((a, b) => a - b);
|
|
6567
|
-
}
|
|
6568
|
-
/** Lets a drag move `element` along `axis` and settles it on its snap points. */
|
|
6569
|
-
function createSnapDrag(element, options) {
|
|
6570
|
-
const { axis, onSettle, model } = options;
|
|
6571
|
-
if (options.customProperty != null && axis !== "x") devWarn("createSnapDrag", "customProperty draws the x axis only, so this y drag draws nothing.");
|
|
6572
|
-
const flickThreshold = options.flickThreshold ?? 1008;
|
|
6573
|
-
let points = sortedSnapPoints(options.snapPoints);
|
|
6574
|
-
const drawn = drawnAt(element, options.customProperty?.name);
|
|
6575
|
-
const animator = createMotionEngine(element, {
|
|
6576
|
-
initial: drawn,
|
|
6577
|
-
...options.customProperty != null ? { customProperty: options.customProperty } : {}
|
|
6578
|
-
});
|
|
6579
|
-
let targetIndex = points.length === 0 ? 0 : resolveSnapPoint({
|
|
6580
|
-
points,
|
|
6581
|
-
position: drawn[axis],
|
|
6582
|
-
velocity: 0,
|
|
6583
|
-
flickThreshold
|
|
6584
|
-
}).index;
|
|
6585
|
-
let turn = 0;
|
|
6586
|
-
let drag = null;
|
|
6587
|
-
let destroyed = false;
|
|
6588
|
-
let inFlight = null;
|
|
6589
|
-
let compositor = null;
|
|
6590
|
-
let finishCompositor = null;
|
|
6591
|
-
const position = () => compositor?.presented() ?? animator.get(axis);
|
|
6592
|
-
/** Stops a compositor settle where it is on screen, and draws it there. */
|
|
6593
|
-
const holdCompositor = () => {
|
|
6594
|
-
if (compositor == null) return;
|
|
6595
|
-
const value = compositor.stop();
|
|
6596
|
-
compositor = null;
|
|
6597
|
-
finishCompositor = null;
|
|
6598
|
-
animator.set({ [axis]: value }, { promote: false });
|
|
6599
|
-
};
|
|
6600
|
-
const settle = (target, settleOptions) => {
|
|
6601
|
-
registerSpringsTable();
|
|
6602
|
-
targetIndex = target;
|
|
6603
|
-
const mine = ++turn;
|
|
6604
|
-
const flight = {
|
|
6605
|
-
turn: mine,
|
|
6606
|
-
options: settleOptions,
|
|
6607
|
-
passed: false
|
|
6608
|
-
};
|
|
6609
|
-
inFlight = flight;
|
|
6610
|
-
const { velocity } = settleOptions;
|
|
6611
|
-
const spring = settleOptions.spring ?? springs.settle;
|
|
6612
|
-
const touchRelease = settleOptions.touchRelease === true;
|
|
6613
|
-
const { compositorParts } = options;
|
|
6614
|
-
if (compositorParts != null && animator.reducedMotion({ touchRelease }) === "off") {
|
|
6615
|
-
const startVelocity = velocity != null && velocity !== 0 ? velocity : compositor?.velocity() ?? animator.getVelocity(axis);
|
|
6616
|
-
const from = position();
|
|
6617
|
-
holdCompositor();
|
|
6618
|
-
const to = points[target];
|
|
6619
|
-
const curve = solveSpring(toSpring(resolveMotion(element, spring)), {
|
|
6620
|
-
from,
|
|
6621
|
-
to,
|
|
6622
|
-
velocity: startVelocity
|
|
6623
|
-
});
|
|
6624
|
-
const { onPass } = settleOptions;
|
|
6625
|
-
const play = () => {
|
|
6626
|
-
if (destroyed || mine !== turn) return;
|
|
6627
|
-
animator.stop();
|
|
6628
|
-
animator.set({ [axis]: to }, { promote: false });
|
|
6629
|
-
const finish = () => {
|
|
6630
|
-
compositor = null;
|
|
6631
|
-
finishCompositor = null;
|
|
6632
|
-
if (inFlight === flight) inFlight = null;
|
|
6633
|
-
if (mine === turn && !destroyed) onSettle(targetIndex);
|
|
6634
|
-
};
|
|
6635
|
-
compositor = playCompositorSettle({
|
|
6636
|
-
curve,
|
|
6637
|
-
parts: compositorParts(),
|
|
6638
|
-
requestFrame,
|
|
6639
|
-
...onPass != null ? { onPass: {
|
|
6640
|
-
...onPass,
|
|
6641
|
-
call: () => {
|
|
6642
|
-
flight.passed = true;
|
|
6643
|
-
onPass.call();
|
|
6644
|
-
}
|
|
6645
|
-
} } : {},
|
|
6646
|
-
onFinish: finish
|
|
6647
|
-
});
|
|
6648
|
-
finishCompositor = finish;
|
|
6649
|
-
};
|
|
6650
|
-
if (settleOptions.start === "next-frame") requestFrame(play);
|
|
6651
|
-
else play();
|
|
6652
|
-
return null;
|
|
6653
|
-
}
|
|
6654
|
-
holdCompositor();
|
|
6655
|
-
const handle = animator.animate({ [axis]: points[target] }, {
|
|
6656
|
-
spring,
|
|
6657
|
-
...velocity != null && velocity !== 0 ? { velocity: { [axis]: velocity } } : {}
|
|
6658
|
-
}, {
|
|
6659
|
-
touchRelease,
|
|
6660
|
-
...settleOptions.start != null ? { start: settleOptions.start } : {}
|
|
6661
|
-
});
|
|
6662
|
-
let finished = false;
|
|
6663
|
-
handle.finished.then((arrived) => {
|
|
6664
|
-
finished = true;
|
|
6665
|
-
if (inFlight === flight) inFlight = null;
|
|
6666
|
-
if (arrived && mine === turn && !destroyed) onSettle(targetIndex);
|
|
6667
|
-
});
|
|
6668
|
-
const { onPass } = settleOptions;
|
|
6669
|
-
if (onPass != null && typeof requestAnimationFrame === "function") {
|
|
6670
|
-
const { direction } = onPass;
|
|
6671
|
-
const check = (time) => {
|
|
6672
|
-
if (destroyed || mine !== turn) return;
|
|
6673
|
-
if ((animator.get(axis, time) - onPass.offset) * direction >= 0) {
|
|
6674
|
-
flight.passed = true;
|
|
6675
|
-
onPass.call();
|
|
6676
|
-
return;
|
|
6677
|
-
}
|
|
6678
|
-
if (!finished) requestAnimationFrame(check);
|
|
6679
|
-
};
|
|
6680
|
-
requestAnimationFrame(check);
|
|
6681
|
-
}
|
|
6682
|
-
return handle;
|
|
6683
|
-
};
|
|
6684
|
-
/** Lands a model's landing (null: the element stays as it is). */
|
|
6685
|
-
const land = (landing, touchRelease) => {
|
|
6686
|
-
if (landing != null) settle(landing.index, {
|
|
6687
|
-
velocity: landing.velocity,
|
|
6688
|
-
spring: landing.spring,
|
|
6689
|
-
touchRelease
|
|
6690
|
-
});
|
|
6691
|
-
};
|
|
6692
|
-
const pan = createPan(element, {
|
|
6693
|
-
axis,
|
|
6694
|
-
recognizer: options.pan,
|
|
6695
|
-
onPan: ({ state, translation, totalTranslation, velocity, input }) => {
|
|
6696
|
-
if (destroyed || points.length === 0) return;
|
|
6697
|
-
const moved = {
|
|
6698
|
-
translation: translation[axis],
|
|
6699
|
-
total: totalTranslation[axis],
|
|
6700
|
-
input
|
|
6701
|
-
};
|
|
6702
|
-
if (state === "began") {
|
|
6703
|
-
drag = {
|
|
6704
|
-
start: position(),
|
|
6705
|
-
startIndex: targetIndex,
|
|
6706
|
-
input,
|
|
6707
|
-
caught: false
|
|
6708
|
-
};
|
|
6709
|
-
if (model?.begin?.({
|
|
6710
|
-
start: drag.start,
|
|
6711
|
-
...moved
|
|
6712
|
-
}) === false) {
|
|
6713
|
-
drag = null;
|
|
6714
|
-
return;
|
|
6715
|
-
}
|
|
6716
|
-
}
|
|
6717
|
-
if (drag == null) return;
|
|
6718
|
-
const reading = {
|
|
6719
|
-
start: drag.start,
|
|
6720
|
-
...moved,
|
|
6721
|
-
input: drag.input
|
|
6722
|
-
};
|
|
6723
|
-
if (state === "began" || state === "changed") {
|
|
6724
|
-
const target = model?.move != null ? model.move(reading) : { offset: drag.start + moved.translation };
|
|
6725
|
-
if (target == null) return;
|
|
6726
|
-
if (!drag.caught) {
|
|
6727
|
-
drag.caught = true;
|
|
6728
|
-
turn += 1;
|
|
6729
|
-
holdCompositor();
|
|
6730
|
-
}
|
|
6731
|
-
if (target.spring == null) animator.set({ [axis]: target.offset });
|
|
6732
|
-
else {
|
|
6733
|
-
registerSpringsTable();
|
|
6734
|
-
animator.animate({ [axis]: target.offset }, { spring: target.spring }, { at: now() });
|
|
6735
|
-
}
|
|
6736
|
-
return;
|
|
6737
|
-
}
|
|
6738
|
-
const { startIndex, start } = drag;
|
|
6739
|
-
drag = null;
|
|
6740
|
-
const touchRelease = reading.input === "touch";
|
|
6741
|
-
if (state === "cancelled") {
|
|
6742
|
-
if (model?.cancel != null) land(model.cancel(reading), touchRelease);
|
|
6743
|
-
else settle(startIndex, {
|
|
6744
|
-
velocity: 0,
|
|
6745
|
-
touchRelease
|
|
6746
|
-
});
|
|
6747
|
-
return;
|
|
6748
|
-
}
|
|
6749
|
-
const release = velocity[axis];
|
|
6750
|
-
if (model?.release != null) {
|
|
6751
|
-
land(model.release({
|
|
6752
|
-
...reading,
|
|
6753
|
-
velocity: release
|
|
6754
|
-
}), touchRelease);
|
|
6755
|
-
return;
|
|
6756
|
-
}
|
|
6757
|
-
const { index: target } = resolveSnapPoint({
|
|
6758
|
-
points,
|
|
6759
|
-
position: position(),
|
|
6760
|
-
velocity: release,
|
|
6761
|
-
flickThreshold,
|
|
6762
|
-
start
|
|
6763
|
-
});
|
|
6764
|
-
settle(target, {
|
|
6765
|
-
velocity: release,
|
|
6766
|
-
touchRelease
|
|
6767
|
-
});
|
|
6768
|
-
}
|
|
6769
|
-
});
|
|
6770
|
-
return {
|
|
6771
|
-
settleTo(target, settleOptions = {}) {
|
|
6772
|
-
if (destroyed) return null;
|
|
6773
|
-
if (!Number.isInteger(target) || target < 0 || target >= points.length) {
|
|
6774
|
-
devWarn("createDragToSnapPoints", `settleTo(${target}) is outside the ${points.length} snap points, so it does nothing.`);
|
|
6775
|
-
return null;
|
|
6776
|
-
}
|
|
6777
|
-
drag = null;
|
|
6778
|
-
return settle(target, {
|
|
6779
|
-
velocity: 0,
|
|
6780
|
-
...settleOptions
|
|
6781
|
-
});
|
|
6782
|
-
},
|
|
6783
|
-
setSnapPoints(snapPoints) {
|
|
6784
|
-
if (destroyed) return;
|
|
6785
|
-
const flight = (drag == null || !drag.caught) && inFlight?.turn === turn ? inFlight : null;
|
|
6786
|
-
const heading = flight == null ? null : points[targetIndex];
|
|
6787
|
-
const startPoint = drag == null ? null : points[drag.startIndex];
|
|
6788
|
-
points = sortedSnapPoints(snapPoints);
|
|
6789
|
-
if (points.length === 0) {
|
|
6790
|
-
turn += 1;
|
|
6791
|
-
drag = null;
|
|
6792
|
-
holdCompositor();
|
|
6793
|
-
animator.stop();
|
|
6794
|
-
targetIndex = 0;
|
|
6795
|
-
return;
|
|
6796
|
-
}
|
|
6797
|
-
const nearest = (at) => resolveSnapPoint({
|
|
6798
|
-
points,
|
|
6799
|
-
position: at,
|
|
6800
|
-
velocity: 0,
|
|
6801
|
-
flickThreshold
|
|
6802
|
-
}).index;
|
|
6803
|
-
if (flight != null && heading != null) {
|
|
6804
|
-
const { onPass, ...rest } = flight.options;
|
|
6805
|
-
settle(nearest(heading), {
|
|
6806
|
-
...rest,
|
|
6807
|
-
...flight.passed ? {} : { onPass },
|
|
6808
|
-
velocity: 0
|
|
6809
|
-
});
|
|
6810
|
-
if (drag != null) drag.startIndex = nearest(startPoint ?? drag.start);
|
|
6811
|
-
return;
|
|
6812
|
-
}
|
|
6813
|
-
targetIndex = nearest(startPoint ?? position());
|
|
6814
|
-
if (drag != null) drag.startIndex = targetIndex;
|
|
6815
|
-
},
|
|
6816
|
-
snapPoints() {
|
|
6817
|
-
return points;
|
|
6818
|
-
},
|
|
6819
|
-
animator,
|
|
6820
|
-
position,
|
|
6821
|
-
finishSettle() {
|
|
6822
|
-
const finish = finishCompositor;
|
|
6823
|
-
if (compositor == null || finish == null) return;
|
|
6824
|
-
compositor.stop();
|
|
6825
|
-
finish();
|
|
6826
|
-
},
|
|
6827
|
-
destroy() {
|
|
6828
|
-
if (destroyed) return;
|
|
6829
|
-
destroyed = true;
|
|
6830
|
-
pan.destroy();
|
|
6831
|
-
holdCompositor();
|
|
6832
|
-
animator.stop();
|
|
6833
|
-
animator.dispose();
|
|
6834
|
-
}
|
|
6835
|
-
};
|
|
6836
|
-
}
|
|
6837
|
-
//#endregion
|
|
6838
|
-
//#region src/dragToSnapPoints/createDragToSnapPoints.ts
|
|
6839
|
-
/**
|
|
6840
|
-
* @file createDragToSnapPoints.ts
|
|
6841
|
-
* @input An element and its snap points
|
|
6842
|
-
* @output The public snap-point drag: `createDragToSnapPoints`, its options
|
|
6843
|
-
* and handle. Also re-exports createSnapDrag and its types (the drag under
|
|
6844
|
-
* it, with the options only Core passes), which no package entry exports.
|
|
6845
|
-
* @position Public entry point, re-exported from the package through
|
|
6846
|
-
* composables/createDragToSnapPoints.ts, and wrapped by
|
|
6847
|
-
* `useDragToSnapPoints`. Importing it does no DOM work.
|
|
6848
|
-
*
|
|
6849
|
-
* SYNC: When modified, update:
|
|
6850
|
-
* - createDragToSnapPoints.test.ts
|
|
6851
|
-
* - ../composables/useDragToSnapPoints.ts
|
|
6852
|
-
* - the use-drag-to-snap-points docs
|
|
6853
|
-
*/
|
|
6854
|
-
/**
|
|
6855
|
-
* Lets a drag move `element` along `axis` and settles it on `snapPoints` at
|
|
6856
|
-
* the release, then calls `onSettle(index)`.
|
|
6857
|
-
*
|
|
6858
|
-
* The release settles on the nearest snap point. A release faster than
|
|
6859
|
-
* `flickThreshold` carries to the next one in its direction. A release that
|
|
6860
|
-
* moves back toward the drag's start returns to the snap point it started
|
|
6861
|
-
* from. The settle springs from the release velocity. Under Reduce Motion,
|
|
6862
|
-
* the release cross-fades after a touch drag or on a coarse primary pointer,
|
|
6863
|
-
* and lands at once elsewhere. `settleTo(index)` settles without a drag, for
|
|
6864
|
-
* the keyboard.
|
|
6865
|
-
*
|
|
6866
|
-
* @example
|
|
6867
|
-
* ```ts
|
|
6868
|
-
* const snap = createDragToSnapPoints(drawer, {
|
|
6869
|
-
* axis: 'y',
|
|
6870
|
-
* snapPoints: [0, 240, 480],
|
|
6871
|
-
* onSettle: index => console.log('settled on', index),
|
|
6872
|
-
* })
|
|
6873
|
-
* button.addEventListener('click', () => snap.settleTo(0))
|
|
6874
|
-
* // Later:
|
|
6875
|
-
* snap.destroy()
|
|
6876
|
-
* ```
|
|
6877
|
-
*/
|
|
6878
|
-
function createDragToSnapPoints(element, options) {
|
|
6879
|
-
const { axis, flickThreshold, onSettle } = options;
|
|
6880
|
-
if (!options.snapPoints.some((point) => Number.isFinite(point))) {
|
|
6881
|
-
devWarn("createDragToSnapPoints", "snapPoints is empty, so the drag does nothing.");
|
|
6882
|
-
return {
|
|
6883
|
-
settleTo() {},
|
|
6884
|
-
destroy() {}
|
|
6885
|
-
};
|
|
6886
|
-
}
|
|
6887
|
-
const snap = createSnapDrag(element, {
|
|
6888
|
-
axis,
|
|
6889
|
-
snapPoints: options.snapPoints,
|
|
6890
|
-
...flickThreshold != null ? { flickThreshold } : {},
|
|
6891
|
-
onSettle
|
|
6892
|
-
});
|
|
6893
|
-
return {
|
|
6894
|
-
settleTo(index) {
|
|
6895
|
-
snap.settleTo(index);
|
|
6896
|
-
},
|
|
6897
|
-
destroy() {
|
|
6898
|
-
snap.destroy();
|
|
6899
|
-
}
|
|
6900
|
-
};
|
|
6901
|
-
}
|
|
6902
|
-
//#endregion
|
|
6903
|
-
//#region src/composables/useAnimator.ts
|
|
6904
|
-
/**
|
|
6905
|
-
* 用组件库自己的动效驱动 `target` 指向的元素。`target` 可以是模板 ref、
|
|
6906
|
-
* getter 或元素本身。在事件处理和侦听器里调用返回值的 `animate`、`decay`、
|
|
6907
|
-
* `set`、`get`、`getVelocity`、`stop`。
|
|
6908
|
-
*
|
|
6909
|
-
* 返回值只创建一次,动画不触发组件重新渲染。animator 跟着 `target`
|
|
6910
|
-
* 当前指向的元素走,换成新元素时新元素从静止状态开始。作用域销毁时停下
|
|
6911
|
-
* 正在跑的动画并放开元素。没有元素时每个调用都不做事,`animate` 和
|
|
6912
|
-
* `decay` 立刻 resolve。服务端渲染时不碰 DOM。
|
|
6913
|
-
*
|
|
6914
|
-
* @example
|
|
6915
|
-
* ```ts
|
|
6916
|
-
* const card = useTemplateRef<HTMLElement>('card')
|
|
6917
|
-
* const animator = useAnimator(card)
|
|
6918
|
-
* function pop(): void {
|
|
6919
|
-
* void animator.animate({ scale: 1.2 })
|
|
6920
|
-
* }
|
|
6921
|
-
* ```
|
|
6922
|
-
*/
|
|
6923
|
-
function useAnimator(target) {
|
|
6924
|
-
const { animator, attach } = createAttachableAnimator();
|
|
6925
|
-
const { destroy: _destroy, ...handle } = animator;
|
|
6926
|
-
watch(() => toValue(target) ?? null, (element) => attach(element), {
|
|
6927
|
-
immediate: true,
|
|
6928
|
-
flush: "sync"
|
|
6929
|
-
});
|
|
6930
|
-
if (getCurrentScope()) onScopeDispose(() => attach(null));
|
|
6931
|
-
return handle;
|
|
6932
|
-
}
|
|
6933
|
-
//#endregion
|
|
6934
|
-
//#region src/composables/useContainerReveal.ts
|
|
6935
|
-
function useContainerReveal(options = {}) {
|
|
6936
|
-
function containerProps(reveal = {}) {
|
|
6937
|
-
if (toValue(options.isEnabled) === false) return {};
|
|
6938
|
-
return {
|
|
6939
|
-
class: {
|
|
6940
|
-
"astryx-reveal": true,
|
|
6941
|
-
"astryx-reveal--inactive": reveal.forceState === "inactive",
|
|
6942
|
-
"astryx-reveal--active": reveal.forceState === "active"
|
|
6943
|
-
},
|
|
6944
|
-
style: reveal.hoverDelay ? { "--_hover-delay": `${reveal.hoverDelay}ms` } : void 0
|
|
6945
|
-
};
|
|
6946
|
-
}
|
|
6947
|
-
function contentProps(reveal = {}) {
|
|
6948
|
-
if (toValue(options.isEnabled) === false) return {};
|
|
6949
|
-
const inverted = reveal.isRevealInverted === true;
|
|
6950
|
-
const preserved = reveal.isLayoutPreserved === true;
|
|
6951
|
-
return { class: {
|
|
6952
|
-
"astryx-reveal__content": !inverted,
|
|
6953
|
-
"astryx-reveal__content--preserve": !inverted && preserved,
|
|
6954
|
-
"astryx-reveal__conceal": inverted,
|
|
6955
|
-
"astryx-reveal__conceal--preserve": inverted && preserved,
|
|
6956
|
-
"astryx-reveal__shown": reveal.forceVisibility === "shown",
|
|
6957
|
-
"astryx-reveal__hidden": reveal.forceVisibility === "hidden" && !preserved,
|
|
6958
|
-
"astryx-reveal__hidden--preserve": reveal.forceVisibility === "hidden" && preserved
|
|
6959
|
-
} };
|
|
6960
|
-
}
|
|
6961
|
-
return {
|
|
6962
|
-
containerProps,
|
|
6963
|
-
contentProps
|
|
6964
|
-
};
|
|
6965
|
-
}
|
|
6966
|
-
//#endregion
|
|
6967
|
-
//#region src/composables/useControllableState.ts
|
|
6968
|
-
/**
|
|
6969
|
-
* 受控或自己管的 v-model。
|
|
6970
|
-
*
|
|
6971
|
-
* Astryx 没有同名 hook。各组件原来各自判断「外面传了值就听外面的,没传就自己记」,
|
|
6972
|
-
* 这里收成一个函数,方便以后的 v-model 共用。
|
|
6973
|
-
*/
|
|
6974
|
-
function useControllableState(options) {
|
|
6975
|
-
const { modelValue, onChange } = options;
|
|
6976
|
-
const controlled = modelValue.value !== void 0;
|
|
6977
|
-
const local = ref(toValue(options.defaultValue));
|
|
6978
|
-
const isControlled = computed(() => controlled);
|
|
6979
|
-
const value = computed(() => controlled ? modelValue.value : local.value);
|
|
6980
|
-
function setValue(next) {
|
|
6981
|
-
if (Object.is(value.value, next)) return;
|
|
6982
|
-
if (controlled) modelValue.value = next;
|
|
6983
|
-
else local.value = next;
|
|
6984
|
-
onChange?.(next);
|
|
6985
|
-
}
|
|
6986
|
-
return {
|
|
6987
|
-
isControlled,
|
|
6988
|
-
setValue,
|
|
6989
|
-
value
|
|
6990
|
-
};
|
|
6991
|
-
}
|
|
6992
|
-
//#endregion
|
|
6993
|
-
//#region src/gestures/useAttachment.ts
|
|
6994
|
-
function useAttachment(target, attach, key = () => null) {
|
|
6995
|
-
if (typeof document === "undefined") return;
|
|
6996
|
-
let release = null;
|
|
6997
|
-
const releaseNow = () => {
|
|
6998
|
-
const current = release;
|
|
6999
|
-
release = null;
|
|
7000
|
-
current?.();
|
|
7001
|
-
};
|
|
7002
|
-
const stop = watch([() => toValue(target), key], ([node]) => {
|
|
7003
|
-
releaseNow();
|
|
7004
|
-
if (node != null) release = attach(node);
|
|
7005
|
-
}, {
|
|
7006
|
-
immediate: true,
|
|
7007
|
-
flush: "sync"
|
|
5186
|
+
const stop = watch([() => toValue(target), key], ([node]) => {
|
|
5187
|
+
releaseNow();
|
|
5188
|
+
if (node != null) release = attach(node);
|
|
5189
|
+
}, {
|
|
5190
|
+
immediate: true,
|
|
5191
|
+
flush: "sync"
|
|
7008
5192
|
});
|
|
7009
5193
|
if (getCurrentScope()) onScopeDispose(() => {
|
|
7010
5194
|
stop();
|
|
@@ -7012,1608 +5196,4 @@ function useAttachment(target, attach, key = () => null) {
|
|
|
7012
5196
|
});
|
|
7013
5197
|
}
|
|
7014
5198
|
//#endregion
|
|
7015
|
-
|
|
7016
|
-
/**
|
|
7017
|
-
* 让 `target` 指向的元素能沿 `axis` 拖动,松手后停到 `snapPoints` 里的一个点上。
|
|
7018
|
-
* `target` 可以是模板 ref、getter 或元素本身。
|
|
7019
|
-
*
|
|
7020
|
-
* 拖动跟着 `target` 当前指向的元素走,元素换掉就挂到新元素上,作用域销毁时拆掉。
|
|
7021
|
-
* `options` 是响应式对象时,`axis`、`snapPoints`、`flickThreshold` 变了就重建拖动,
|
|
7022
|
-
* 元素停在原处(正在进行的回弹也一样);内容相同的新数组不会重建。`onSettle`
|
|
7023
|
-
* 每次停稳时才从 `options` 里读,换一个新函数不会重建。服务端渲染时不碰 DOM。
|
|
7024
|
-
*
|
|
7025
|
-
* @example
|
|
7026
|
-
* ```ts
|
|
7027
|
-
* const drawer = useTemplateRef<HTMLElement>('drawer')
|
|
7028
|
-
* const index = ref(0)
|
|
7029
|
-
* const { settleTo } = useDragToSnapPoints(drawer, {
|
|
7030
|
-
* axis: 'y',
|
|
7031
|
-
* snapPoints: [0, 240, 480],
|
|
7032
|
-
* onSettle: (next) => { index.value = next },
|
|
7033
|
-
* })
|
|
7034
|
-
* ```
|
|
7035
|
-
*/
|
|
7036
|
-
function useDragToSnapPoints(target, options) {
|
|
7037
|
-
let current = null;
|
|
7038
|
-
const points = () => JSON.stringify(options.snapPoints);
|
|
7039
|
-
useAttachment(target, (element) => {
|
|
7040
|
-
const snap = createDragToSnapPoints(element, {
|
|
7041
|
-
axis: options.axis,
|
|
7042
|
-
snapPoints: JSON.parse(points()),
|
|
7043
|
-
flickThreshold: options.flickThreshold,
|
|
7044
|
-
onSettle: (index) => options.onSettle(index)
|
|
7045
|
-
});
|
|
7046
|
-
current = snap;
|
|
7047
|
-
return () => {
|
|
7048
|
-
snap.destroy();
|
|
7049
|
-
if (current === snap) current = null;
|
|
7050
|
-
};
|
|
7051
|
-
}, () => `${options.axis} ${points()} ${options.flickThreshold ?? ""}`);
|
|
7052
|
-
return { settleTo: (index) => current?.settleTo(index) };
|
|
7053
|
-
}
|
|
7054
|
-
//#endregion
|
|
7055
|
-
//#region src/composables/internal/entryAnimation.ts
|
|
7056
|
-
/**
|
|
7057
|
-
* 预设对应的共享动画类。时长、缓动和「减少动态效果」的处理都在 `styles/motion.css` 里。
|
|
7058
|
-
* 类名里的 above 指元素从下方升上去,below 指从上方落下来。
|
|
7059
|
-
*/
|
|
7060
|
-
const ENTRY_ANIMATION_CLASSES = {
|
|
7061
|
-
slideDown: "astryx-motion-slide-in-below",
|
|
7062
|
-
slideUp: "astryx-motion-slide-in-above",
|
|
7063
|
-
fadeIn: "astryx-motion-fade-in",
|
|
7064
|
-
scaleIn: "astryx-motion-scale-in"
|
|
7065
|
-
};
|
|
7066
|
-
let hasPaintedPage = false;
|
|
7067
|
-
let isTrackingPaint = false;
|
|
7068
|
-
function trackFirstPaint() {
|
|
7069
|
-
if (isTrackingPaint || typeof window === "undefined" || typeof requestAnimationFrame !== "function") return;
|
|
7070
|
-
isTrackingPaint = true;
|
|
7071
|
-
requestAnimationFrame(() => {
|
|
7072
|
-
requestAnimationFrame(() => {
|
|
7073
|
-
hasPaintedPage = true;
|
|
7074
|
-
});
|
|
7075
|
-
});
|
|
7076
|
-
}
|
|
7077
|
-
/** 首屏是否已经画过。服务端没有 window,永远返回 false。 */
|
|
7078
|
-
function isAfterFirstPaint() {
|
|
7079
|
-
trackFirstPaint();
|
|
7080
|
-
return hasPaintedPage;
|
|
7081
|
-
}
|
|
7082
|
-
/**
|
|
7083
|
-
* 对应原版 Astryx 的 `hooks/useEntryAnimation`。
|
|
7084
|
-
*
|
|
7085
|
-
* 元素挂载时播一次入场动画,但只对首屏画完之后才插进来的元素生效:
|
|
7086
|
-
* 首屏就渲染出来的元素不播放,免得整页一起动。
|
|
7087
|
-
*
|
|
7088
|
-
* 用法是把返回的 `entryClass` 绑到 `class` 上。动画时长和缓动取自主题的
|
|
7089
|
-
* motion token,「减少动态效果」打开时动画会直接落到结束状态。
|
|
7090
|
-
*/
|
|
7091
|
-
function useEntryAnimation(options = {}) {
|
|
7092
|
-
const preset = options.preset ?? "slideDown";
|
|
7093
|
-
if (isHydrating()) return { entryClass: null };
|
|
7094
|
-
return { entryClass: isAfterFirstPaint() ? ENTRY_ANIMATION_CLASSES[preset] : null };
|
|
7095
|
-
}
|
|
7096
|
-
/**
|
|
7097
|
-
* 当前组件是否在接管服务端渲染的 DOM。Vue 接管时先把已有的 DOM 节点交给组件的 vnode,
|
|
7098
|
-
* 再运行 setup;普通挂载时这里还是 null。不在组件里调用时返回 false。
|
|
7099
|
-
*/
|
|
7100
|
-
function isHydrating() {
|
|
7101
|
-
return getCurrentInstance()?.vnode.el != null;
|
|
7102
|
-
}
|
|
7103
|
-
trackFirstPaint();
|
|
7104
|
-
//#endregion
|
|
7105
|
-
//#region src/composables/useGridFocus.ts
|
|
7106
|
-
/** 网格里一格可以接受的元素:按钮,或者显式可聚焦的元素。 */
|
|
7107
|
-
const DEFAULT_CELL_SELECTOR = "button:not([disabled]), [tabindex]:not([tabindex=\"-1\"])";
|
|
7108
|
-
/**
|
|
7109
|
-
* 对应原版 Astryx 的 `hooks/useGridFocus`。
|
|
7110
|
-
*
|
|
7111
|
-
* 按 WAI-ARIA 的 grid 模式管二维网格的键盘导航:方向键一格一格走,
|
|
7112
|
-
* Home/End 走到行首行尾,Ctrl+Home/Ctrl+End 走到整张网格的开头和结尾,
|
|
7113
|
-
* Page Up/Down 交给调用方(日历里就是翻月)。走到边界时可以把事件交出去,
|
|
7114
|
-
* 让别的网格接住焦点,例如翻到上个月继续用方向键。
|
|
7115
|
-
*
|
|
7116
|
-
* 它靠读 DOM 里格子的顺序算行列,所以格子要不要能聚焦、要不要聚焦格子里的某个按钮,
|
|
7117
|
-
* 都是通过 `isCellFocusable` 和 `getFocusTarget` 两个回调交给调用方决定。
|
|
7118
|
-
*/
|
|
7119
|
-
function useGridFocus(options) {
|
|
7120
|
-
const gridRef = ref(null);
|
|
7121
|
-
const cellSelector = options.cellSelector ?? DEFAULT_CELL_SELECTOR;
|
|
7122
|
-
function isRoving() {
|
|
7123
|
-
return toValue(options.hasRovingTabIndex ?? false);
|
|
7124
|
-
}
|
|
7125
|
-
function getCells() {
|
|
7126
|
-
const grid = gridRef.value;
|
|
7127
|
-
if (grid == null) return [];
|
|
7128
|
-
return [...grid.querySelectorAll(cellSelector)];
|
|
7129
|
-
}
|
|
7130
|
-
/** 能接焦点的格子,按 DOM 顺序。 */
|
|
7131
|
-
function getFocusableCells() {
|
|
7132
|
-
return getCells().filter((cell) => options.isCellFocusable?.(cell) ?? true);
|
|
7133
|
-
}
|
|
7134
|
-
function resolveTarget(cell) {
|
|
7135
|
-
return options.getFocusTarget?.(cell) ?? cell;
|
|
7136
|
-
}
|
|
7137
|
-
function indexOfTarget(target) {
|
|
7138
|
-
if (target == null) return -1;
|
|
7139
|
-
return getCells().findIndex((cell) => cell === target || cell.contains(target));
|
|
7140
|
-
}
|
|
7141
|
-
function activeIndex() {
|
|
7142
|
-
const grid = gridRef.value;
|
|
7143
|
-
if (grid == null) return -1;
|
|
7144
|
-
const focused = grid.ownerDocument.activeElement;
|
|
7145
|
-
if (focused == null || !grid.contains(focused)) return -1;
|
|
7146
|
-
return indexOfTarget(focused);
|
|
7147
|
-
}
|
|
7148
|
-
/** 让当前格子成为唯一的 Tab 落脚点,其余格子退出 Tab 顺序。 */
|
|
7149
|
-
function syncRovingTabIndex(index) {
|
|
7150
|
-
if (!isRoving()) return;
|
|
7151
|
-
getCells().forEach((cell, cellIndex) => {
|
|
7152
|
-
const target = resolveTarget(cell);
|
|
7153
|
-
if (target != null) target.tabIndex = cellIndex === index ? 0 : -1;
|
|
7154
|
-
});
|
|
7155
|
-
}
|
|
7156
|
-
function focusTargetOf(cell) {
|
|
7157
|
-
if (cell == null) return false;
|
|
7158
|
-
if (!(options.isCellFocusable?.(cell) ?? true)) return false;
|
|
7159
|
-
const target = resolveTarget(cell);
|
|
7160
|
-
if (target == null) return false;
|
|
7161
|
-
target.focus({ preventScroll: true });
|
|
7162
|
-
syncRovingTabIndex(getCells().indexOf(cell));
|
|
7163
|
-
return true;
|
|
7164
|
-
}
|
|
7165
|
-
function columns() {
|
|
7166
|
-
return Math.max(1, toValue(options.columns));
|
|
7167
|
-
}
|
|
7168
|
-
function columnOf(index) {
|
|
7169
|
-
return index < 0 ? 0 : index % columns();
|
|
7170
|
-
}
|
|
7171
|
-
/** 走到边界外面时,把当前列和步长交给调用方,让另一张网格接住焦点。 */
|
|
7172
|
-
function navigateOut(current, offset, isAfter) {
|
|
7173
|
-
if (current < 0) return;
|
|
7174
|
-
const column = columnOf(current);
|
|
7175
|
-
if (isAfter) options.onNavigateAfter?.(column, offset);
|
|
7176
|
-
else options.onNavigateBefore?.(column, offset);
|
|
7177
|
-
}
|
|
7178
|
-
function moveTo(index, offset) {
|
|
7179
|
-
const cells = getCells();
|
|
7180
|
-
const target = cells[index];
|
|
7181
|
-
if (target == null) {
|
|
7182
|
-
navigateOut(activeIndex(), offset, index >= cells.length);
|
|
7183
|
-
return;
|
|
7184
|
-
}
|
|
7185
|
-
if (!(options.isCellFocusable?.(target) ?? true)) return;
|
|
7186
|
-
focusTargetOf(target);
|
|
7187
|
-
}
|
|
7188
|
-
function handleKeyDown(event) {
|
|
7189
|
-
if (event.defaultPrevented) return;
|
|
7190
|
-
if (gridRef.value == null) return;
|
|
7191
|
-
const index = activeIndex();
|
|
7192
|
-
if (index < 0) return;
|
|
7193
|
-
const cols = columns();
|
|
7194
|
-
const last = getCells().length - 1;
|
|
7195
|
-
const rowStart = index - columnOf(index);
|
|
7196
|
-
switch (event.key) {
|
|
7197
|
-
case "ArrowRight":
|
|
7198
|
-
event.preventDefault();
|
|
7199
|
-
moveTo(index + 1, 1);
|
|
7200
|
-
break;
|
|
7201
|
-
case "ArrowLeft":
|
|
7202
|
-
event.preventDefault();
|
|
7203
|
-
moveTo(index - 1, 1);
|
|
7204
|
-
break;
|
|
7205
|
-
case "ArrowDown":
|
|
7206
|
-
event.preventDefault();
|
|
7207
|
-
moveTo(index + cols, cols);
|
|
7208
|
-
break;
|
|
7209
|
-
case "ArrowUp":
|
|
7210
|
-
event.preventDefault();
|
|
7211
|
-
moveTo(index - cols, cols);
|
|
7212
|
-
break;
|
|
7213
|
-
case "Home":
|
|
7214
|
-
event.preventDefault();
|
|
7215
|
-
moveTo(event.ctrlKey || event.metaKey ? 0 : rowStart, 1);
|
|
7216
|
-
break;
|
|
7217
|
-
case "End":
|
|
7218
|
-
event.preventDefault();
|
|
7219
|
-
moveTo(event.ctrlKey || event.metaKey ? last : rowStart + cols - 1, 1);
|
|
7220
|
-
break;
|
|
7221
|
-
case "PageUp":
|
|
7222
|
-
if (options.onPageUp == null) break;
|
|
7223
|
-
event.preventDefault();
|
|
7224
|
-
options.onPageUp();
|
|
7225
|
-
break;
|
|
7226
|
-
case "PageDown":
|
|
7227
|
-
if (options.onPageDown == null) break;
|
|
7228
|
-
event.preventDefault();
|
|
7229
|
-
options.onPageDown();
|
|
7230
|
-
}
|
|
7231
|
-
}
|
|
7232
|
-
function handleFocus(event) {
|
|
7233
|
-
if (!isRoving()) return;
|
|
7234
|
-
const target = event.target;
|
|
7235
|
-
if (!(target instanceof Element)) return;
|
|
7236
|
-
const index = indexOfTarget(target);
|
|
7237
|
-
if (index < 0) return;
|
|
7238
|
-
syncRovingTabIndex(index);
|
|
7239
|
-
}
|
|
7240
|
-
function focusCell(index) {
|
|
7241
|
-
const cells = getCells();
|
|
7242
|
-
if (cells.length === 0) return;
|
|
7243
|
-
focusTargetOf(cells[Math.min(Math.max(index, 0), cells.length - 1)]);
|
|
7244
|
-
}
|
|
7245
|
-
function focusFirst() {
|
|
7246
|
-
focusTargetOf(getFocusableCells()[0]);
|
|
7247
|
-
}
|
|
7248
|
-
function focusLast() {
|
|
7249
|
-
const cells = getFocusableCells();
|
|
7250
|
-
focusTargetOf(cells[cells.length - 1]);
|
|
7251
|
-
}
|
|
7252
|
-
/** 首次渲染后补上 Tab 落脚点;已经有一个 `tabindex="0"` 的格子就尊重它。 */
|
|
7253
|
-
function seedRovingTabIndex() {
|
|
7254
|
-
if (!isRoving()) return;
|
|
7255
|
-
const cells = getCells();
|
|
7256
|
-
const seeded = cells.findIndex((cell) => {
|
|
7257
|
-
const target = resolveTarget(cell);
|
|
7258
|
-
return target != null && target.tabIndex === 0 && (options.isCellFocusable?.(cell) ?? true);
|
|
7259
|
-
});
|
|
7260
|
-
if (seeded >= 0) {
|
|
7261
|
-
syncRovingTabIndex(seeded);
|
|
7262
|
-
return;
|
|
7263
|
-
}
|
|
7264
|
-
const first = cells.findIndex((cell) => options.isCellFocusable?.(cell) ?? true);
|
|
7265
|
-
if (first >= 0) syncRovingTabIndex(first);
|
|
7266
|
-
}
|
|
7267
|
-
onMounted(seedRovingTabIndex);
|
|
7268
|
-
watch(gridRef, seedRovingTabIndex);
|
|
7269
|
-
watch([() => toValue(options.columns), () => toValue(options.hasRovingTabIndex ?? false)], seedRovingTabIndex);
|
|
7270
|
-
onScopeDispose(() => {
|
|
7271
|
-
gridRef.value = null;
|
|
7272
|
-
});
|
|
7273
|
-
return {
|
|
7274
|
-
gridRef,
|
|
7275
|
-
handleKeyDown,
|
|
7276
|
-
handleFocus,
|
|
7277
|
-
focusCell,
|
|
7278
|
-
focusFirst,
|
|
7279
|
-
focusLast
|
|
7280
|
-
};
|
|
7281
|
-
}
|
|
7282
|
-
//#endregion
|
|
7283
|
-
//#region src/composables/useGridRovingFocus.ts
|
|
7284
|
-
/**
|
|
7285
|
-
* 网格式导航(roving tabindex):用方向键在二维网格中移动焦点。
|
|
7286
|
-
* 供 Calendar、Pagination(如果需要)等组件复用。
|
|
7287
|
-
*/
|
|
7288
|
-
function useGridRovingFocus(options) {
|
|
7289
|
-
const { rows, columns, activeIndex, isEnabled = ref(true), isDisabled, onChange } = options;
|
|
7290
|
-
const row = ref(0);
|
|
7291
|
-
const column = ref(0);
|
|
7292
|
-
watch(activeIndex, (index) => {
|
|
7293
|
-
const cols = columns.value;
|
|
7294
|
-
if (cols > 0) {
|
|
7295
|
-
row.value = Math.floor(index / cols);
|
|
7296
|
-
column.value = index % cols;
|
|
7297
|
-
}
|
|
7298
|
-
}, { immediate: true });
|
|
7299
|
-
function indexFromRowCol(r, c) {
|
|
7300
|
-
return r * columns.value + c;
|
|
7301
|
-
}
|
|
7302
|
-
function moveTo(targetRow, targetCol) {
|
|
7303
|
-
if (!isEnabled.value) return;
|
|
7304
|
-
const r = Math.max(0, Math.min(targetRow, rows.value - 1));
|
|
7305
|
-
const c = Math.max(0, Math.min(targetCol, columns.value - 1));
|
|
7306
|
-
if (isDisabled?.(r, c)) return;
|
|
7307
|
-
const index = indexFromRowCol(r, c);
|
|
7308
|
-
onChange(index);
|
|
7309
|
-
}
|
|
7310
|
-
function moveUp() {
|
|
7311
|
-
moveTo(row.value - 1, column.value);
|
|
7312
|
-
}
|
|
7313
|
-
function moveDown() {
|
|
7314
|
-
moveTo(row.value + 1, column.value);
|
|
7315
|
-
}
|
|
7316
|
-
function moveLeft() {
|
|
7317
|
-
moveTo(row.value, column.value - 1);
|
|
7318
|
-
}
|
|
7319
|
-
function moveRight() {
|
|
7320
|
-
moveTo(row.value, column.value + 1);
|
|
7321
|
-
}
|
|
7322
|
-
function moveToFirstInRow() {
|
|
7323
|
-
moveTo(row.value, 0);
|
|
7324
|
-
}
|
|
7325
|
-
function moveToLastInRow() {
|
|
7326
|
-
moveTo(row.value, columns.value - 1);
|
|
7327
|
-
}
|
|
7328
|
-
function moveToFirstInColumn() {
|
|
7329
|
-
moveTo(0, column.value);
|
|
7330
|
-
}
|
|
7331
|
-
function moveToLastInColumn() {
|
|
7332
|
-
moveTo(rows.value - 1, column.value);
|
|
7333
|
-
}
|
|
7334
|
-
function onKeyDown(event) {
|
|
7335
|
-
if (!isEnabled.value) return;
|
|
7336
|
-
switch (event.key) {
|
|
7337
|
-
case "ArrowUp":
|
|
7338
|
-
event.preventDefault();
|
|
7339
|
-
moveUp();
|
|
7340
|
-
break;
|
|
7341
|
-
case "ArrowDown":
|
|
7342
|
-
event.preventDefault();
|
|
7343
|
-
moveDown();
|
|
7344
|
-
break;
|
|
7345
|
-
case "ArrowLeft":
|
|
7346
|
-
event.preventDefault();
|
|
7347
|
-
moveLeft();
|
|
7348
|
-
break;
|
|
7349
|
-
case "ArrowRight":
|
|
7350
|
-
event.preventDefault();
|
|
7351
|
-
moveRight();
|
|
7352
|
-
break;
|
|
7353
|
-
case "Home":
|
|
7354
|
-
event.preventDefault();
|
|
7355
|
-
if (event.ctrlKey) moveTo(0, 0);
|
|
7356
|
-
else moveToFirstInRow();
|
|
7357
|
-
break;
|
|
7358
|
-
case "End":
|
|
7359
|
-
event.preventDefault();
|
|
7360
|
-
if (event.ctrlKey) moveTo(rows.value - 1, columns.value - 1);
|
|
7361
|
-
else moveToLastInRow();
|
|
7362
|
-
break;
|
|
7363
|
-
case "PageUp":
|
|
7364
|
-
event.preventDefault();
|
|
7365
|
-
moveToFirstInColumn();
|
|
7366
|
-
break;
|
|
7367
|
-
case "PageDown":
|
|
7368
|
-
event.preventDefault();
|
|
7369
|
-
moveToLastInColumn();
|
|
7370
|
-
}
|
|
7371
|
-
}
|
|
7372
|
-
return {
|
|
7373
|
-
row,
|
|
7374
|
-
column,
|
|
7375
|
-
onKeyDown,
|
|
7376
|
-
moveTo
|
|
7377
|
-
};
|
|
7378
|
-
}
|
|
7379
|
-
//#endregion
|
|
7380
|
-
//#region src/composables/useImageMode.ts
|
|
7381
|
-
/**
|
|
7382
|
-
* APCA 感知亮度。先把 sRGB 按 2.4 线性化,再用接近 BT.709 的系数合成,
|
|
7383
|
-
* 最后做 0.56 次方,让 0.5 接近视觉上的中灰。饱和色比简单的伽马亮度更准。
|
|
7384
|
-
*/
|
|
7385
|
-
function perceptualLightness(r, g, b) {
|
|
7386
|
-
const linear = (channel) => (channel / 255) ** 2.4;
|
|
7387
|
-
return (.2126729 * linear(r) + .7151522 * linear(g) + .072175 * linear(b)) ** .56;
|
|
7388
|
-
}
|
|
7389
|
-
/** 一组采样像素的平均亮度,再和阈值比出深浅。 */
|
|
7390
|
-
function imageModeFromPixels(pixels, threshold = .5) {
|
|
7391
|
-
let red = 0;
|
|
7392
|
-
let green = 0;
|
|
7393
|
-
let blue = 0;
|
|
7394
|
-
let count = 0;
|
|
7395
|
-
for (let index = 0; index < pixels.length; index += 4) {
|
|
7396
|
-
red += pixels[index] ?? 0;
|
|
7397
|
-
green += pixels[index + 1] ?? 0;
|
|
7398
|
-
blue += pixels[index + 2] ?? 0;
|
|
7399
|
-
count += 1;
|
|
7400
|
-
}
|
|
7401
|
-
const safeCount = count || 1;
|
|
7402
|
-
return perceptualLightness(red / safeCount, green / safeCount, blue / safeCount) > threshold ? "light" : "dark";
|
|
7403
|
-
}
|
|
7404
|
-
/**
|
|
7405
|
-
* 按图片亮度判断该用深色还是浅色前景。采样走 OffscreenCanvas,不往页面上画。
|
|
7406
|
-
* 跨域或网络失败时返回 `fallback`。
|
|
7407
|
-
*/
|
|
7408
|
-
function useImageMode(src, options = {}) {
|
|
7409
|
-
const mode = ref(toValue(options).fallback ?? null);
|
|
7410
|
-
let request = 0;
|
|
7411
|
-
async function detect(url) {
|
|
7412
|
-
const current = ++request;
|
|
7413
|
-
const settings = toValue(options);
|
|
7414
|
-
const threshold = settings.threshold ?? .5;
|
|
7415
|
-
const fallback = settings.fallback ?? null;
|
|
7416
|
-
mode.value = fallback;
|
|
7417
|
-
try {
|
|
7418
|
-
const response = await fetch(url);
|
|
7419
|
-
if (!response.ok) throw new Error(`image ${response.status}`);
|
|
7420
|
-
const bitmap = await createImageBitmap(await response.blob());
|
|
7421
|
-
if (current !== request) return;
|
|
7422
|
-
const region = settings.region;
|
|
7423
|
-
const sx = region ? Math.round(region.x * bitmap.width) : 0;
|
|
7424
|
-
const sy = region ? Math.round(region.y * bitmap.height) : 0;
|
|
7425
|
-
const sw = region ? Math.max(1, Math.round(region.width * bitmap.width)) : bitmap.width;
|
|
7426
|
-
const sh = region ? Math.max(1, Math.round(region.height * bitmap.height)) : bitmap.height;
|
|
7427
|
-
const sample = 10;
|
|
7428
|
-
const context = new OffscreenCanvas(sample, sample).getContext("2d");
|
|
7429
|
-
if (!context) return;
|
|
7430
|
-
context.drawImage(bitmap, sx, sy, sw, sh, 0, 0, sample, sample);
|
|
7431
|
-
const pixels = context.getImageData(0, 0, sample, sample).data;
|
|
7432
|
-
if (current !== request) return;
|
|
7433
|
-
mode.value = imageModeFromPixels(pixels, threshold);
|
|
7434
|
-
} catch {
|
|
7435
|
-
if (current === request) mode.value = fallback;
|
|
7436
|
-
}
|
|
7437
|
-
}
|
|
7438
|
-
const sampleKey = computed(() => {
|
|
7439
|
-
const { region, threshold } = toValue(options);
|
|
7440
|
-
return [
|
|
7441
|
-
toValue(src),
|
|
7442
|
-
region?.x,
|
|
7443
|
-
region?.y,
|
|
7444
|
-
region?.width,
|
|
7445
|
-
region?.height,
|
|
7446
|
-
threshold
|
|
7447
|
-
].join("|");
|
|
7448
|
-
});
|
|
7449
|
-
watch(sampleKey, () => {
|
|
7450
|
-
const url = toValue(src);
|
|
7451
|
-
if (!url) {
|
|
7452
|
-
request += 1;
|
|
7453
|
-
mode.value = toValue(options).fallback ?? null;
|
|
7454
|
-
return;
|
|
7455
|
-
}
|
|
7456
|
-
detect(url);
|
|
7457
|
-
}, { immediate: true });
|
|
7458
|
-
onScopeDispose(() => {
|
|
7459
|
-
request += 1;
|
|
7460
|
-
});
|
|
7461
|
-
return mode;
|
|
7462
|
-
}
|
|
7463
|
-
//#endregion
|
|
7464
|
-
//#region src/composables/useIndicatorFocusRing.ts
|
|
7465
|
-
/** 读不到 `:focus-visible` 时宁可按可见处理,不能把焦点环弄丢(WCAG 2.4.7)。 */
|
|
7466
|
-
function isFocusVisible(target) {
|
|
7467
|
-
try {
|
|
7468
|
-
return target.matches(":focus-visible");
|
|
7469
|
-
} catch {
|
|
7470
|
-
return true;
|
|
7471
|
-
}
|
|
7472
|
-
}
|
|
7473
|
-
/**
|
|
7474
|
-
* 对应原版 Astryx 的 `hooks/useIndicatorFocusRing`。
|
|
7475
|
-
*
|
|
7476
|
-
* 给「真输入框藏起来、画面上的图形代替它」的控件画标准焦点环:复选框、
|
|
7477
|
-
* 单选框都把真正的 input 设成透明,焦点环只能画在旁边那个图形上。
|
|
7478
|
-
*
|
|
7479
|
-
* 环画在指示器自己的元素上,只有这个元素自己的圆角能决定环的形状;
|
|
7480
|
-
* 而且只在 `:focus-visible` 时画,鼠标点一下不会亮。统一放在这里管,
|
|
7481
|
-
* 主题换掉指示器也照样有可见焦点,不会因为漏了一个属性就整块没法用键盘。
|
|
7482
|
-
*/
|
|
7483
|
-
function useIndicatorFocusRing(options) {
|
|
7484
|
-
function indicator() {
|
|
7485
|
-
const child = options.containerRef.value?.firstElementChild;
|
|
7486
|
-
return child instanceof HTMLElement ? child : null;
|
|
7487
|
-
}
|
|
7488
|
-
/** 标记属性 `data-astryx-focus-ring` 的画法是 `styles/indicator-focus-ring.css`。 */
|
|
7489
|
-
function clear() {
|
|
7490
|
-
const element = indicator();
|
|
7491
|
-
if (element != null) delete element.dataset.astryxFocusRing;
|
|
7492
|
-
}
|
|
7493
|
-
function onFocus(event) {
|
|
7494
|
-
if (toValue(options.isDisabled ?? false)) {
|
|
7495
|
-
clear();
|
|
7496
|
-
return;
|
|
7497
|
-
}
|
|
7498
|
-
const target = event.target;
|
|
7499
|
-
if (!(target instanceof Element) || !isFocusVisible(target)) {
|
|
7500
|
-
clear();
|
|
7501
|
-
return;
|
|
7502
|
-
}
|
|
7503
|
-
const element = indicator();
|
|
7504
|
-
if (element != null) element.dataset.astryxFocusRing = "";
|
|
7505
|
-
}
|
|
7506
|
-
function onBlur() {
|
|
7507
|
-
clear();
|
|
7508
|
-
}
|
|
7509
|
-
return { focusProps: {
|
|
7510
|
-
onFocus,
|
|
7511
|
-
onBlur
|
|
7512
|
-
} };
|
|
7513
|
-
}
|
|
7514
|
-
//#endregion
|
|
7515
|
-
//#region src/composables/KeyboardHint.vue
|
|
7516
|
-
const _hoisted_1 = { class: "astryx-keyboard-hint__keys" };
|
|
7517
|
-
const _hoisted_2 = { class: "astryx-keyboard-hint__label" };
|
|
7518
|
-
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
7519
|
-
__name: "KeyboardHint",
|
|
7520
|
-
props: {
|
|
7521
|
-
visible: { type: Boolean },
|
|
7522
|
-
anchor: {},
|
|
7523
|
-
orientation: {}
|
|
7524
|
-
},
|
|
7525
|
-
setup(__props) {
|
|
7526
|
-
const props = __props;
|
|
7527
|
-
const messages = useComponentMessages({ keyboardHint: keyboardHintMessages });
|
|
7528
|
-
const hint = ref(null);
|
|
7529
|
-
const position = ref({
|
|
7530
|
-
top: 0,
|
|
7531
|
-
left: 0
|
|
7532
|
-
});
|
|
7533
|
-
const keys = computed(() => {
|
|
7534
|
-
if (props.orientation === "vertical") return ["up", "down"];
|
|
7535
|
-
if (props.orientation === "both") return [
|
|
7536
|
-
"left",
|
|
7537
|
-
"right",
|
|
7538
|
-
"up",
|
|
7539
|
-
"down"
|
|
7540
|
-
];
|
|
7541
|
-
return ["left", "right"];
|
|
7542
|
-
});
|
|
7543
|
-
const style = computed(() => ({
|
|
7544
|
-
top: `${position.value.top}px`,
|
|
7545
|
-
left: `${position.value.left}px`
|
|
7546
|
-
}));
|
|
7547
|
-
function place() {
|
|
7548
|
-
const anchor = props.anchor;
|
|
7549
|
-
const element = hint.value;
|
|
7550
|
-
if (!anchor || !element) return;
|
|
7551
|
-
const rect = anchor.getBoundingClientRect();
|
|
7552
|
-
const hintRect = element.getBoundingClientRect();
|
|
7553
|
-
const top = Math.max(8, rect.top - hintRect.height - 8);
|
|
7554
|
-
const left = Math.min(window.innerWidth - hintRect.width - 8, Math.max(8, rect.left + rect.width / 2 - hintRect.width / 2));
|
|
7555
|
-
position.value = {
|
|
7556
|
-
top,
|
|
7557
|
-
left
|
|
7558
|
-
};
|
|
7559
|
-
}
|
|
7560
|
-
watch(() => [props.visible, props.anchor], () => {
|
|
7561
|
-
if (!props.visible) return;
|
|
7562
|
-
requestAnimationFrame(() => place());
|
|
7563
|
-
});
|
|
7564
|
-
function onScroll() {
|
|
7565
|
-
if (props.visible) place();
|
|
7566
|
-
}
|
|
7567
|
-
onMounted(() => {
|
|
7568
|
-
window.addEventListener("scroll", onScroll, true);
|
|
7569
|
-
window.addEventListener("resize", onScroll);
|
|
7570
|
-
});
|
|
7571
|
-
onBeforeUnmount(() => {
|
|
7572
|
-
window.removeEventListener("scroll", onScroll, true);
|
|
7573
|
-
window.removeEventListener("resize", onScroll);
|
|
7574
|
-
});
|
|
7575
|
-
return (_ctx, _cache) => {
|
|
7576
|
-
return withDirectives((openBlock(), createElementBlock("div", {
|
|
7577
|
-
ref_key: "hint",
|
|
7578
|
-
ref: hint,
|
|
7579
|
-
class: "astryx-keyboard-hint",
|
|
7580
|
-
"aria-hidden": "true",
|
|
7581
|
-
style: normalizeStyle(style.value)
|
|
7582
|
-
}, [createElementVNode("span", _hoisted_1, [(openBlock(true), createElementBlock(Fragment, null, renderList(keys.value, (key) => {
|
|
7583
|
-
return openBlock(), createBlock(_sfc_main$1, {
|
|
7584
|
-
key,
|
|
7585
|
-
keys: key
|
|
7586
|
-
}, null, 8, ["keys"]);
|
|
7587
|
-
}), 128))]), createElementVNode("span", _hoisted_2, toDisplayString(unref(messages).keyboardHint.navigate), 1)], 4)), [[vShow, __props.visible]]);
|
|
7588
|
-
};
|
|
7589
|
-
}
|
|
7590
|
-
});
|
|
7591
|
-
//#endregion
|
|
7592
|
-
//#region src/composables/useKeyboardHint.ts
|
|
7593
|
-
const ARROW_KEYS = /* @__PURE__ */ new Set([
|
|
7594
|
-
"ArrowLeft",
|
|
7595
|
-
"ArrowRight",
|
|
7596
|
-
"ArrowUp",
|
|
7597
|
-
"ArrowDown"
|
|
7598
|
-
]);
|
|
7599
|
-
/**
|
|
7600
|
-
* 一组方向键控件第一次被键盘点进来时,在当前项旁边短暂提示「用方向键移动」。
|
|
7601
|
-
* 提示显示期间登记在共用的关闭栈里,Escape 只关它,焦点不动。
|
|
7602
|
-
* 按过方向键、Escape、焦点离开(或设了时限且超时)之后不再出现。
|
|
7603
|
-
*/
|
|
7604
|
-
function useKeyboardHint(options = {}) {
|
|
7605
|
-
const visible = ref(false);
|
|
7606
|
-
const anchor = ref(null);
|
|
7607
|
-
const orientation = computed(() => options.orientation ?? "horizontal");
|
|
7608
|
-
let dismissed = false;
|
|
7609
|
-
let timer;
|
|
7610
|
-
function hide() {
|
|
7611
|
-
visible.value = false;
|
|
7612
|
-
if (timer != null) {
|
|
7613
|
-
clearTimeout(timer);
|
|
7614
|
-
timer = void 0;
|
|
7615
|
-
}
|
|
7616
|
-
}
|
|
7617
|
-
function show(target) {
|
|
7618
|
-
if (dismissed || options.isEnabled === false) return;
|
|
7619
|
-
anchor.value = target;
|
|
7620
|
-
visible.value = true;
|
|
7621
|
-
if (timer != null) clearTimeout(timer);
|
|
7622
|
-
timer = void 0;
|
|
7623
|
-
if (options.dismissAfterMs != null) timer = setTimeout(() => {
|
|
7624
|
-
dismissed = true;
|
|
7625
|
-
hide();
|
|
7626
|
-
}, options.dismissAfterMs);
|
|
7627
|
-
}
|
|
7628
|
-
const token = {};
|
|
7629
|
-
let unregister = null;
|
|
7630
|
-
function release() {
|
|
7631
|
-
unregister?.();
|
|
7632
|
-
unregister = null;
|
|
7633
|
-
}
|
|
7634
|
-
watch(visible, (shown) => {
|
|
7635
|
-
release();
|
|
7636
|
-
if (!shown) return;
|
|
7637
|
-
unregister = pushLayer({
|
|
7638
|
-
token,
|
|
7639
|
-
getTrigger: () => anchor.value,
|
|
7640
|
-
dismissOnPointerOutside: false,
|
|
7641
|
-
dismissOnEscape: "close",
|
|
7642
|
-
onDismiss() {
|
|
7643
|
-
dismissed = true;
|
|
7644
|
-
hide();
|
|
7645
|
-
}
|
|
7646
|
-
});
|
|
7647
|
-
}, { flush: "post" });
|
|
7648
|
-
function onFocus(event) {
|
|
7649
|
-
if (dismissed || options.isEnabled === false) return;
|
|
7650
|
-
const target = event.target;
|
|
7651
|
-
const current = event.currentTarget;
|
|
7652
|
-
if (!(target instanceof HTMLElement) || !(current instanceof HTMLElement)) return;
|
|
7653
|
-
if (event.relatedTarget instanceof Node && current.contains(event.relatedTarget)) {
|
|
7654
|
-
if (visible.value) anchor.value = target;
|
|
7655
|
-
return;
|
|
7656
|
-
}
|
|
7657
|
-
if (!target.matches(":focus-visible")) return;
|
|
7658
|
-
show(target);
|
|
7659
|
-
}
|
|
7660
|
-
function onBlur(event) {
|
|
7661
|
-
const current = event.currentTarget;
|
|
7662
|
-
if (!(current instanceof HTMLElement)) return;
|
|
7663
|
-
if (event.relatedTarget instanceof Node && current.contains(event.relatedTarget)) return;
|
|
7664
|
-
dismissed = true;
|
|
7665
|
-
hide();
|
|
7666
|
-
}
|
|
7667
|
-
function onKeyDown(event) {
|
|
7668
|
-
if (!ARROW_KEYS.has(event.key)) return;
|
|
7669
|
-
dismissed = true;
|
|
7670
|
-
hide();
|
|
7671
|
-
}
|
|
7672
|
-
onBeforeUnmount(() => {
|
|
7673
|
-
release();
|
|
7674
|
-
if (timer != null) clearTimeout(timer);
|
|
7675
|
-
});
|
|
7676
|
-
return {
|
|
7677
|
-
visible,
|
|
7678
|
-
anchor,
|
|
7679
|
-
orientation,
|
|
7680
|
-
onFocus,
|
|
7681
|
-
onBlur,
|
|
7682
|
-
onKeyDown,
|
|
7683
|
-
Hint: defineComponent({
|
|
7684
|
-
name: "AstryxKeyboardHint",
|
|
7685
|
-
setup() {
|
|
7686
|
-
return () => h(_sfc_main, {
|
|
7687
|
-
visible: visible.value,
|
|
7688
|
-
anchor: anchor.value,
|
|
7689
|
-
orientation: toValue(orientation)
|
|
7690
|
-
});
|
|
7691
|
-
}
|
|
7692
|
-
})
|
|
7693
|
-
};
|
|
7694
|
-
}
|
|
7695
|
-
//#endregion
|
|
7696
|
-
//#region src/composables/usePanGesture.ts
|
|
7697
|
-
/**
|
|
7698
|
-
* 把 `target` 指向的元素上的拖动报成数值。`target` 可以是模板 ref、getter
|
|
7699
|
-
* 或元素本身。
|
|
7700
|
-
*
|
|
7701
|
-
* 元素上始终只有一个拖动手势:换了元素、或 `options` 是响应式对象且 `axis`
|
|
7702
|
-
* 变了,就重建;作用域销毁时拆掉。`onPan` 每次报告时才从 `options` 里读,
|
|
7703
|
-
* 换一个新函数不会重建手势。拖动过程中不触发组件重新渲染。正在进行的拖动遇到
|
|
7704
|
-
* 重建或卸载时直接结束,不再调 `onPan`。服务端渲染时不碰 DOM。
|
|
7705
|
-
*
|
|
7706
|
-
* @example
|
|
7707
|
-
* ```ts
|
|
7708
|
-
* const card = useTemplateRef<HTMLElement>('card')
|
|
7709
|
-
* usePanGesture(card, {
|
|
7710
|
-
* axis: 'x',
|
|
7711
|
-
* onPan: ({ state, translation }) => {
|
|
7712
|
-
* card.value!.style.translate = state === 'changed' ? `${translation.x}px` : ''
|
|
7713
|
-
* },
|
|
7714
|
-
* })
|
|
7715
|
-
* ```
|
|
7716
|
-
*/
|
|
7717
|
-
function usePanGesture(target, options) {
|
|
7718
|
-
useAttachment(target, (element) => {
|
|
7719
|
-
let isForwarding = true;
|
|
7720
|
-
const gesture = createPanGesture(element, {
|
|
7721
|
-
axis: options.axis,
|
|
7722
|
-
onPan: (event) => {
|
|
7723
|
-
if (isForwarding) options.onPan(event);
|
|
7724
|
-
}
|
|
7725
|
-
});
|
|
7726
|
-
return () => {
|
|
7727
|
-
isForwarding = false;
|
|
7728
|
-
gesture.destroy();
|
|
7729
|
-
};
|
|
7730
|
-
}, () => options.axis);
|
|
7731
|
-
}
|
|
7732
|
-
//#endregion
|
|
7733
|
-
//#region src/motion/uikit/paging.ts
|
|
7734
|
-
/**
|
|
7735
|
-
* @file paging.ts
|
|
7736
|
-
* @input Nothing; data only
|
|
7737
|
-
* @output Exports `paging`, the measured constants of a paging UIScrollView,
|
|
7738
|
-
* and `registerPagingTable`, which registers them with the motion registry
|
|
7739
|
-
* @position The paging domain of the UIKit constants table (motion/uikit). Only
|
|
7740
|
-
* core reads it, so the `uikit` namespace does not re-export it
|
|
7741
|
-
*/
|
|
7742
|
-
const paging = {
|
|
7743
|
-
/**
|
|
7744
|
-
* After the lift, one model moves the content: the settle onto the chosen
|
|
7745
|
-
* page and the return from an overscroll. Each display frame runs floor(frame
|
|
7746
|
-
* interval in ms) steps of 1 ms:
|
|
7747
|
-
*
|
|
7748
|
-
* v = (v + (target − x) · springPull) · friction; x += v (v: pt per step)
|
|
7749
|
-
*
|
|
7750
|
-
* A 60 Hz frame runs 16 steps, not 16.67. With these values, the model
|
|
7751
|
-
* replays eight captured releases to 0.20 pt RMS. It replays five overscroll
|
|
7752
|
-
* returns to 0.16–0.33 pt RMS (402 pt pages, iOS 26.2, 3× screen). Without
|
|
7753
|
-
* the floor, the error is 1.0 pt RMS, with a systematic shape.
|
|
7754
|
-
*/
|
|
7755
|
-
integrator: {
|
|
7756
|
-
/**
|
|
7757
|
-
* Velocity added per 1 ms step, per point of distance to the target page
|
|
7758
|
-
* (pt per step²).
|
|
7759
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026.
|
|
7760
|
-
* `_pagingSpringPull` reads the same on a 402 pt paging UIScrollView and
|
|
7761
|
-
* on UIPageViewController's scroll view. It replays 8 captured settles to
|
|
7762
|
-
* 0.20 pt RMS.
|
|
7763
|
-
*/
|
|
7764
|
-
springPull: 284858e-9,
|
|
7765
|
-
/**
|
|
7766
|
-
* Velocity kept per step after the pull (`_pagingFriction`, equal to
|
|
7767
|
-
* `_defaultPagingFriction`).
|
|
7768
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. Both read
|
|
7769
|
-
* the same on the two scroll views of `springPull`, and they replay with
|
|
7770
|
-
* it.
|
|
7771
|
-
*/
|
|
7772
|
-
friction: .970815,
|
|
7773
|
-
/**
|
|
7774
|
-
* Integration steps per second: floor(16.67 ms) = 16 steps per 60 Hz frame,
|
|
7775
|
-
* and floor(8.33 ms) = 8 per 120 Hz frame, so 960.
|
|
7776
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. In a 60 fps
|
|
7777
|
-
* log of 8 releases at rest, floored stepping fits to 0.20 pt RMS.
|
|
7778
|
-
* Unfloored stepping fits to 1.0 pt RMS.
|
|
7779
|
-
*/
|
|
7780
|
-
stepsPerSecond: 960,
|
|
7781
|
-
/**
|
|
7782
|
-
* A settle ends exactly on the page once the remaining distance is below
|
|
7783
|
-
* this many points and the step velocity is below `restSpeed`.
|
|
7784
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. The
|
|
7785
|
-
* captured settles jump the last 0.33 pt onto the page about 0.35 s after
|
|
7786
|
-
* a release at rest.
|
|
7787
|
-
*/
|
|
7788
|
-
restDistance: .5,
|
|
7789
|
-
/**
|
|
7790
|
-
* Step velocity (pt per step) below which a settle may end.
|
|
7791
|
-
* @source GUESS — the captured settles end at about 0.04 pt per step;
|
|
7792
|
-
* the threshold is not observable more finely at 60 fps
|
|
7793
|
-
* @measure M-PG12
|
|
7794
|
-
*/
|
|
7795
|
-
restSpeed: .05
|
|
7796
|
-
},
|
|
7797
|
-
release: {
|
|
7798
|
-
/**
|
|
7799
|
-
* Released slower than `advanceSpeed`, the scroll view settles on the page
|
|
7800
|
-
* nearest the content position: past half a page, the next one. The pager
|
|
7801
|
-
* keeps the start page instead for a release that moves back toward it.
|
|
7802
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. In releases
|
|
7803
|
-
* at rest from page 1, content at 48.5 % of the page stays, and 57.5 %
|
|
7804
|
-
* goes to the next page. On a second 402 pt pager, 45 % stays and 55 %
|
|
7805
|
-
* advances.
|
|
7806
|
-
*/
|
|
7807
|
-
commitFraction: .5,
|
|
7808
|
-
/**
|
|
7809
|
-
* Released at least this fast (pt/s), the scroll view pages in the
|
|
7810
|
-
* direction of the velocity, from any content position. A flick from 6 % of
|
|
7811
|
-
* the page advances. The speed is UIPanGestureRecognizer's velocity at the
|
|
7812
|
-
* last movement, and it never decays. The scroll view's
|
|
7813
|
-
* `_horizontalVelocity` equals it at every sample. A drag held still for
|
|
7814
|
-
* 397 ms before the lift still pages at the speed it had.
|
|
7815
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. Steady
|
|
7816
|
-
* releases at 10, 25 and 40 % of a 402 pt page: 292.7, 295.3 and 298.6
|
|
7817
|
-
* pt/s stay; 310.7, 316.4 and 329.9 advance. The result is the same at
|
|
7818
|
-
* every position: a threshold, not a projection.
|
|
7819
|
-
*/
|
|
7820
|
-
advanceSpeed: 300,
|
|
7821
|
-
/**
|
|
7822
|
-
* A settle velocity slower than this (pt/s) is zeroed, so the settle starts
|
|
7823
|
-
* at rest. It is paging's own tuning on the one release velocity that every
|
|
7824
|
-
* gesture reads.
|
|
7825
|
-
* @source GUESS — the middle of the measured (200, 249] bracket. In the
|
|
7826
|
-
* UIKit lab (iOS 26.2 simulator, Oct 23 2026),
|
|
7827
|
-
* `scrollViewWillEndDragging` reads 0 for steady releases at 175 and 200
|
|
7828
|
-
* pt/s. It reads 0.249 pt/ms for a release at 249 pt/s.
|
|
7829
|
-
* @measure M-PG13
|
|
7830
|
-
*/
|
|
7831
|
-
velocityFloor: 225,
|
|
7832
|
-
/**
|
|
7833
|
-
* Pages a release may travel from the page the drag started on, at any
|
|
7834
|
-
* speed and drag distance.
|
|
7835
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A drag of
|
|
7836
|
-
* 1.5 pages from page 1 lands on page 2 at release speeds of 0, 600 and
|
|
7837
|
-
* 3000 pt/s.
|
|
7838
|
-
*/
|
|
7839
|
-
maxPagesFromStart: 1
|
|
7840
|
-
},
|
|
7841
|
-
/**
|
|
7842
|
-
* A finger that lands on a pager settling after a swipe does not stop it at
|
|
7843
|
-
* once. The settle runs on for about this long, then the content holds under
|
|
7844
|
-
* the finger. Lifted without a move, the content settles again on the
|
|
7845
|
-
* nearest page.
|
|
7846
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. After
|
|
7847
|
-
* touch-downs 60 and 160 ms into a settle, the content moved on for 82.6
|
|
7848
|
-
* and 87.5 ms (5 frames), then held.
|
|
7849
|
-
*/
|
|
7850
|
-
catchStopMs: 85,
|
|
7851
|
-
/**
|
|
7852
|
-
* In a sheet, a horizontal pager's pan begins only for a drag within atan(1 ÷
|
|
7853
|
-
* this) of horizontal (26.6° for 2). A steeper drag goes to the sheet.
|
|
7854
|
-
* Between 26.6° and 45°, neither moves.
|
|
7855
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A scroll
|
|
7856
|
-
* view's directional lock holds the major axis up to 25° and frees it from
|
|
7857
|
-
* 30°. An inline calendar pager in a sheet pages at 20° from horizontal. At
|
|
7858
|
-
* 35° and 45°, it moves neither itself nor the sheet, and it leaves 55° to
|
|
7859
|
-
* the sheet.
|
|
7860
|
-
*/
|
|
7861
|
-
panAxisRatio: 2,
|
|
7862
|
-
/**
|
|
7863
|
-
* Inside a vertical scroll view, exactly one of the pager and the scroll view
|
|
7864
|
-
* takes a drag, decided once by its dominant axis. The pager takes it when
|
|
7865
|
-
* |dx| ≥ this × |dy|, 45° and the tie included. The scroll view takes any
|
|
7866
|
-
* other drag.
|
|
7867
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 24 2026. A 402 × 300
|
|
7868
|
-
* paging view sits in a full-screen vertical scroll view, with 150 pt drags
|
|
7869
|
-
* at 0–90°. The pager takes 0–45°, and the page takes 50–90°. At 35°, the
|
|
7870
|
-
* outer view stays at 0 through 86 pt of vertical travel. The choice
|
|
7871
|
-
* happens at 10–15 pt of travel.
|
|
7872
|
-
*/
|
|
7873
|
-
nestedPanAxisRatio: 1,
|
|
7874
|
-
animatedScroll: {
|
|
7875
|
-
/**
|
|
7876
|
-
* `setContentOffset(_:animated:)` duration in milliseconds. It is the same
|
|
7877
|
-
* for one page and for five, as for a page control's tap.
|
|
7878
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026.
|
|
7879
|
-
* `_contentOffsetAnimationDuration` reads 0.3, and five animated moves of
|
|
7880
|
-
* 1 to 5 pages each last 0.30 s.
|
|
7881
|
-
*/
|
|
7882
|
-
durationMs: 300,
|
|
7883
|
-
/**
|
|
7884
|
-
* Its curve is a sinusoidal ease-in-out: x = from + (to − from) · (1 − cos
|
|
7885
|
-
* πu) ÷ 2, for u = t ÷ duration. This cubic bézier matches it to 0.02 % of
|
|
7886
|
-
* the distance (0.09 pt over a 402 pt page).
|
|
7887
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. The five
|
|
7888
|
-
* moves fit the sinusoid to 0.14–0.51 pt RMS, and a 2010 pt move fits to
|
|
7889
|
-
* 0.20 pt. The curve easeInEaseOut (0.42, 0, 0.58, 1) misses by 7.7 pt.
|
|
7890
|
-
*/
|
|
7891
|
-
curve: [
|
|
7892
|
-
.364212,
|
|
7893
|
-
0,
|
|
7894
|
-
.635788,
|
|
7895
|
-
1
|
|
7896
|
-
]
|
|
7897
|
-
},
|
|
7898
|
-
/**
|
|
7899
|
-
* Past the first or last page, the content follows the finger through the
|
|
7900
|
-
* scroll view's rubber band (scroll.rubberBand.coefficient), with d = the
|
|
7901
|
-
* page width. It returns on the integrator above.
|
|
7902
|
-
* @source measured: UIKit lab, iOS 26.2 simulator, Oct 23 2026. A pan of 90
|
|
7903
|
-
* pt past page 0 shows 42.7–45 pt, and 290 pt shows 114.3 pt. The formula
|
|
7904
|
-
* gives 44.1 and 114.2, with c 0.55 and d 402. The return replays on the
|
|
7905
|
-
* integrator to 0.16–0.33 pt RMS.
|
|
7906
|
-
*/
|
|
7907
|
-
rubberBandDimension: "pageWidth"
|
|
7908
|
-
};
|
|
7909
|
-
/**
|
|
7910
|
-
* Registers this table with the motion registry (motion/roles.ts). The pager
|
|
7911
|
-
* then reads `setContentOffset(_:animated:)`'s duration and curve through
|
|
7912
|
-
* `resolveMotion`, as it reads every touch motion. The table lists no role,
|
|
7913
|
-
* because no motion role names any of its values, so each plays as measured.
|
|
7914
|
-
* A page that plays no paging motion ships no paging registry. The module
|
|
7915
|
-
* registers its own table at import (one idempotent in-memory write, no DOM).
|
|
7916
|
-
*/
|
|
7917
|
-
function registerPagingTable() {
|
|
7918
|
-
registerMotionTable("paging", paging, { exclude: ["catchStopMs"] });
|
|
7919
|
-
}
|
|
7920
|
-
registerPagingTable();
|
|
7921
|
-
//#endregion
|
|
7922
|
-
//#region src/gestures/LongPressGestureRecognizer.ts
|
|
7923
|
-
var LongPressGestureRecognizer = class extends GestureRecognizer {
|
|
7924
|
-
get kind() {
|
|
7925
|
-
return "longPress";
|
|
7926
|
-
}
|
|
7927
|
-
/** Internal. The host's brand: a long press keeps the callout and selection off (recognizerInternals). */
|
|
7928
|
-
get family() {
|
|
7929
|
-
return "longPress";
|
|
7930
|
-
}
|
|
7931
|
-
minimumPressDuration;
|
|
7932
|
-
allowableMovement;
|
|
7933
|
-
numberOfTapsRequired;
|
|
7934
|
-
numberOfTouchesRequired;
|
|
7935
|
-
tapsDone = 0;
|
|
7936
|
-
/** The taps phase's current tap: when it landed and its most fingers. */
|
|
7937
|
-
tapStartedAt = null;
|
|
7938
|
-
tapMostTouches = 0;
|
|
7939
|
-
isPressTimerArmed = false;
|
|
7940
|
-
/** When the gesture began, on the event clock. */
|
|
7941
|
-
beganAt = null;
|
|
7942
|
-
constructor(options = {}) {
|
|
7943
|
-
super({
|
|
7944
|
-
...options,
|
|
7945
|
-
selectionLock: options.selectionLock !== void 0 ? options.selectionLock : (options.minimumPressDuration ?? UIKIT_LONG_PRESS.minimumPressDuration.value) > 0 ? lockSelection : null
|
|
7946
|
-
});
|
|
7947
|
-
this.minimumPressDuration = options.minimumPressDuration ?? UIKIT_LONG_PRESS.minimumPressDuration.value;
|
|
7948
|
-
this.allowableMovement = options.allowableMovement ?? UIKIT_LONG_PRESS.allowableMovement.value;
|
|
7949
|
-
this.numberOfTapsRequired = options.numberOfTapsRequired ?? 0;
|
|
7950
|
-
this.numberOfTouchesRequired = options.numberOfTouchesRequired ?? 1;
|
|
7951
|
-
}
|
|
7952
|
-
isInvolved() {
|
|
7953
|
-
return super.isInvolved() || this.tapsDone > 0;
|
|
7954
|
-
}
|
|
7955
|
-
get nativeTouchBehavior() {
|
|
7956
|
-
return MANIPULATION;
|
|
7957
|
-
}
|
|
7958
|
-
acceptsTouch(touch) {
|
|
7959
|
-
if (isActive(this.state)) return false;
|
|
7960
|
-
return super.acceptsTouch(touch);
|
|
7961
|
-
}
|
|
7962
|
-
touchesBegan(_touches, event) {
|
|
7963
|
-
if (this.numberOfTouches > this.numberOfTouchesRequired) {
|
|
7964
|
-
this.setState("failed");
|
|
7965
|
-
return;
|
|
7966
|
-
}
|
|
7967
|
-
if (this.tapsDone > 0) this.clearTimer();
|
|
7968
|
-
if (this.tapsDone < this.numberOfTapsRequired) {
|
|
7969
|
-
this.tapStartedAt ??= event.time;
|
|
7970
|
-
this.tapMostTouches = Math.max(this.tapMostTouches, this.numberOfTouches);
|
|
7971
|
-
}
|
|
7972
|
-
if (this.numberOfTouches === this.numberOfTouchesRequired && this.tapsDone >= this.numberOfTapsRequired) {
|
|
7973
|
-
if (this.minimumPressDuration <= 0) {
|
|
7974
|
-
this.beganAt = event.time;
|
|
7975
|
-
this.setState("began");
|
|
7976
|
-
return;
|
|
7977
|
-
}
|
|
7978
|
-
this.isPressTimerArmed = true;
|
|
7979
|
-
this.setTimer(event.time + this.minimumPressDuration, () => {
|
|
7980
|
-
this.isPressTimerArmed = false;
|
|
7981
|
-
if (this.state === "possible" && this.numberOfTouches === this.numberOfTouchesRequired) {
|
|
7982
|
-
this.beganAt = this.now();
|
|
7983
|
-
this.setState("began");
|
|
7984
|
-
}
|
|
7985
|
-
});
|
|
7986
|
-
}
|
|
7987
|
-
}
|
|
7988
|
-
touchesMoved(touches) {
|
|
7989
|
-
if (this.state === "possible") {
|
|
7990
|
-
if (touches.some((touch) => travel(touch) > this.allowableMovement)) this.setState("failed");
|
|
7991
|
-
return;
|
|
7992
|
-
}
|
|
7993
|
-
if (isActive(this.state)) this.setState("changed");
|
|
7994
|
-
}
|
|
7995
|
-
touchesEnded(touches, event) {
|
|
7996
|
-
if (isActive(this.state)) {
|
|
7997
|
-
this.setState("ended");
|
|
7998
|
-
return;
|
|
7999
|
-
}
|
|
8000
|
-
if (this.isPressTimerArmed || this.tapsDone >= this.numberOfTapsRequired) {
|
|
8001
|
-
this.setState("failed");
|
|
8002
|
-
return;
|
|
8003
|
-
}
|
|
8004
|
-
if (this.numberOfTouches - touches.length > 0) return;
|
|
8005
|
-
const heldFor = event.time - (this.tapStartedAt ?? event.time);
|
|
8006
|
-
const fingers = this.tapMostTouches;
|
|
8007
|
-
this.tapStartedAt = null;
|
|
8008
|
-
this.tapMostTouches = 0;
|
|
8009
|
-
if (heldFor > UIKIT_TAP.maximumTapDuration.value || fingers !== this.numberOfTouchesRequired) {
|
|
8010
|
-
this.setState("failed");
|
|
8011
|
-
return;
|
|
8012
|
-
}
|
|
8013
|
-
this.tapsDone += 1;
|
|
8014
|
-
this.setTimer(event.time + UIKIT_TAP.maximumIntervalBetweenTaps.value, () => {
|
|
8015
|
-
this.setState("failed");
|
|
8016
|
-
});
|
|
8017
|
-
}
|
|
8018
|
-
reset() {
|
|
8019
|
-
this.tapsDone = 0;
|
|
8020
|
-
this.tapStartedAt = null;
|
|
8021
|
-
this.tapMostTouches = 0;
|
|
8022
|
-
this.isPressTimerArmed = false;
|
|
8023
|
-
this.beganAt = null;
|
|
8024
|
-
}
|
|
8025
|
-
};
|
|
8026
|
-
//#endregion
|
|
8027
|
-
//#region src/composables/internal/snapPagingCatcher.ts
|
|
8028
|
-
/**
|
|
8029
|
-
* 翻页途中「接住」这一行的识别器:一个零时长、不认领触摸的长按。它从不认领
|
|
8030
|
-
* 触摸,所以从正在翻页的这一行上开始的竖向滑动或双指捏合仍然归页面,和 UIKit
|
|
8031
|
-
* 里分页视图停住后把竖向拖动交给外层滚动视图一样。它只记下按下来的是哪种指针,
|
|
8032
|
-
* 并提供一个按事件时钟走的接住计时器和「不让内容收到这次触摸」两件事。
|
|
8033
|
-
*/
|
|
8034
|
-
var SettleCatcher = class extends LongPressGestureRecognizer {
|
|
8035
|
-
/** 按下来接住这一行的指针种类。 */
|
|
8036
|
-
pointerType = null;
|
|
8037
|
-
get claimsTouches() {
|
|
8038
|
-
return false;
|
|
8039
|
-
}
|
|
8040
|
-
/**
|
|
8041
|
-
* 触摸后 `ms` 毫秒(按事件时钟)调用 `callback`,触摸先结束就不调。仲裁会在
|
|
8042
|
-
* 任何更晚的输入之前跑它,所以页面忙、按下和抬起一起到时,它仍然先跑。
|
|
8043
|
-
* 零时长、不认点按次数的长按不占用自己唯一的仲裁计时器,正好拿来用。
|
|
8044
|
-
*/
|
|
8045
|
-
armCatch(ms, callback) {
|
|
8046
|
-
this.setTimer((this.beganAt ?? this.now()) + ms, callback);
|
|
8047
|
-
}
|
|
8048
|
-
/** 取消 `armCatch` 设下、还没跑的接住。 */
|
|
8049
|
-
disarmCatch() {
|
|
8050
|
-
this.clearTimer();
|
|
8051
|
-
}
|
|
8052
|
-
/** 把这次触摸从下面的内容那里拿走:不按下、不点击。UIKit 里停住滚动视图的那次触摸也到不了内容。 */
|
|
8053
|
-
takeFromContent() {
|
|
8054
|
-
this.cancelTouchesInView();
|
|
8055
|
-
}
|
|
8056
|
-
touchesBegan(touches, event) {
|
|
8057
|
-
if (this.state === "possible" && touches.length > 0) this.pointerType = touches[0].pointerType;
|
|
8058
|
-
super.touchesBegan(touches, event);
|
|
8059
|
-
}
|
|
8060
|
-
};
|
|
8061
|
-
//#endregion
|
|
8062
|
-
//#region src/composables/internal/snapPagingMotion.ts
|
|
8063
|
-
const browserClock = {
|
|
8064
|
-
now: () => performance.now(),
|
|
8065
|
-
frame: (callback) => requestAnimationFrame(() => callback()),
|
|
8066
|
-
cancel: (handle) => cancelAnimationFrame(handle)
|
|
8067
|
-
};
|
|
8068
|
-
/** 下标列表里离 `to` 最近的那一个。 */
|
|
8069
|
-
function nearestIndex(stops, to) {
|
|
8070
|
-
let best = 0;
|
|
8071
|
-
for (let i = 1; i < stops.length; i++) if (Math.abs(stops[i] - to) < Math.abs(stops[best] - to)) best = i;
|
|
8072
|
-
return best;
|
|
8073
|
-
}
|
|
8074
|
-
/**
|
|
8075
|
-
* 从第 `anchor` 个停点算起的「一屏一页」:每一页落在离上一页一屏远最近的停点上,
|
|
8076
|
-
* 并且至少往前走一个停点。
|
|
8077
|
-
*/
|
|
8078
|
-
function viewPages(stops, anchor, width) {
|
|
8079
|
-
const pages = [stops[anchor]];
|
|
8080
|
-
for (let i = anchor; i < stops.length - 1;) {
|
|
8081
|
-
i = Math.max(nearestIndex(stops, stops[i] + width), i + 1);
|
|
8082
|
-
pages.push(stops[i]);
|
|
8083
|
-
}
|
|
8084
|
-
for (let i = anchor; i > 0;) {
|
|
8085
|
-
i = Math.min(nearestIndex(stops, stops[i] - width), i - 1);
|
|
8086
|
-
pages.unshift(stops[i]);
|
|
8087
|
-
}
|
|
8088
|
-
return pages;
|
|
8089
|
-
}
|
|
8090
|
-
/** 松手后按这个时长(秒)把速度投出去,再找离投点最近的一页。 */
|
|
8091
|
-
const PROJECTION_SECONDS = .1;
|
|
8092
|
-
/**
|
|
8093
|
-
* 松手时停在哪一页:轻扫至少翻到运动方向上的下一页,慢慢松手就停在投点最近的一页。
|
|
8094
|
-
* 不论多快,离起手那一页(`anchor`)最多一页。返回页的下标。
|
|
8095
|
-
*/
|
|
8096
|
-
function pickPage(pages, at, velocity, anchor) {
|
|
8097
|
-
let index = nearestIndex(pages, at + velocity * PROJECTION_SECONDS);
|
|
8098
|
-
if (velocity >= 300) {
|
|
8099
|
-
const ahead = pages.findIndex((page) => page > at + .5);
|
|
8100
|
-
if (ahead !== -1) index = Math.max(index, ahead);
|
|
8101
|
-
} else if (velocity <= -300) {
|
|
8102
|
-
let behind = -1;
|
|
8103
|
-
for (let i = pages.length - 1; i >= 0; i--) if (pages[i] < at - .5) {
|
|
8104
|
-
behind = i;
|
|
8105
|
-
break;
|
|
8106
|
-
}
|
|
8107
|
-
if (behind !== -1) index = Math.min(index, behind);
|
|
8108
|
-
}
|
|
8109
|
-
return Math.min(Math.max(index, anchor - 1, 0), anchor + 1, pages.length - 1);
|
|
8110
|
-
}
|
|
8111
|
-
/** 弹簧的固有角频率:大约 0.4 秒走完一页,接近 UIKit 翻页的手感。 */
|
|
8112
|
-
const SPRING_OMEGA = 2 * Math.PI / .4;
|
|
8113
|
-
/** 轻扫很快时弹簧可以收得更紧,但不超过这个角频率。 */
|
|
8114
|
-
const MAX_OMEGA = 60;
|
|
8115
|
-
const REST_DISTANCE = .5;
|
|
8116
|
-
const REST_VELOCITY = 20;
|
|
8117
|
-
/**
|
|
8118
|
-
* 用临界阻尼弹簧把位置从 `from` 带到 `to`,带着初速度 `velocity`(像素每秒)。
|
|
8119
|
-
* 每一帧调用 `onFrame`,停稳后最后一次给出 `to` 并调用 `onRest`。
|
|
8120
|
-
*/
|
|
8121
|
-
function springTo(clock, from, to, velocity, onFrame, onRest) {
|
|
8122
|
-
const start = clock.now();
|
|
8123
|
-
const offset0 = from - to;
|
|
8124
|
-
const toward = offset0 === 0 ? 0 : -velocity * Math.sign(offset0);
|
|
8125
|
-
const omega = Math.max(SPRING_OMEGA, Math.min(MAX_OMEGA, toward / Math.max(Math.abs(offset0), 1e-6)));
|
|
8126
|
-
let handle = 0;
|
|
8127
|
-
let stopped = false;
|
|
8128
|
-
function state(time) {
|
|
8129
|
-
const t = Math.max(0, time - start) / 1e3;
|
|
8130
|
-
const decay = Math.exp(-omega * t);
|
|
8131
|
-
const b = velocity + omega * offset0;
|
|
8132
|
-
return {
|
|
8133
|
-
offset: (offset0 + b * t) * decay,
|
|
8134
|
-
velocity: (b - omega * (offset0 + b * t)) * decay
|
|
8135
|
-
};
|
|
8136
|
-
}
|
|
8137
|
-
function tick() {
|
|
8138
|
-
if (stopped) return;
|
|
8139
|
-
const now = state(clock.now());
|
|
8140
|
-
if (Math.abs(now.offset) < REST_DISTANCE && Math.abs(now.velocity) < REST_VELOCITY) {
|
|
8141
|
-
stopped = true;
|
|
8142
|
-
onFrame(to);
|
|
8143
|
-
onRest();
|
|
8144
|
-
return;
|
|
8145
|
-
}
|
|
8146
|
-
onFrame(to + now.offset);
|
|
8147
|
-
handle = clock.frame(tick);
|
|
8148
|
-
}
|
|
8149
|
-
handle = clock.frame(tick);
|
|
8150
|
-
return {
|
|
8151
|
-
target: to,
|
|
8152
|
-
velocity: () => stopped ? 0 : state(clock.now()).velocity,
|
|
8153
|
-
stop() {
|
|
8154
|
-
stopped = true;
|
|
8155
|
-
clock.cancel(handle);
|
|
8156
|
-
}
|
|
8157
|
-
};
|
|
8158
|
-
}
|
|
8159
|
-
//#endregion
|
|
8160
|
-
//#region src/composables/internal/snapPagingSkip.ts
|
|
8161
|
-
/**
|
|
8162
|
-
* 原生吸附要跳过末端那一页吞掉的项(见 `snapPages`),这样滚轮、方向键和
|
|
8163
|
-
* 普通滚动也停在和轻扫同样的页上。被跳过的项交还时恢复自己原来的行内值。
|
|
8164
|
-
* 停点随尺寸和子项变化,最多一帧算一次;分页按住这一行时,等交还时再写。
|
|
8165
|
-
*/
|
|
8166
|
-
function followSkippedStops(element, track) {
|
|
8167
|
-
const skipped = /* @__PURE__ */ new Map();
|
|
8168
|
-
let frame = null;
|
|
8169
|
-
let isDue = false;
|
|
8170
|
-
function restore(item, own) {
|
|
8171
|
-
if (own.value === "") item.style.removeProperty("scroll-snap-align");
|
|
8172
|
-
else item.style.setProperty("scroll-snap-align", own.value, own.priority);
|
|
8173
|
-
}
|
|
8174
|
-
function skip(items) {
|
|
8175
|
-
for (const [item, own] of skipped) if (!items.includes(item)) {
|
|
8176
|
-
skipped.delete(item);
|
|
8177
|
-
restore(item, own);
|
|
8178
|
-
}
|
|
8179
|
-
for (const item of items) if (item instanceof HTMLElement && !skipped.has(item)) {
|
|
8180
|
-
skipped.set(item, {
|
|
8181
|
-
value: item.style.getPropertyValue("scroll-snap-align"),
|
|
8182
|
-
priority: item.style.getPropertyPriority("scroll-snap-align")
|
|
8183
|
-
});
|
|
8184
|
-
item.style.setProperty("scroll-snap-align", "none");
|
|
8185
|
-
}
|
|
8186
|
-
}
|
|
8187
|
-
function apply() {
|
|
8188
|
-
isDue = false;
|
|
8189
|
-
skip(track.pages().skipped);
|
|
8190
|
-
}
|
|
8191
|
-
function schedule() {
|
|
8192
|
-
if (track.isHeld()) {
|
|
8193
|
-
isDue = true;
|
|
8194
|
-
return;
|
|
8195
|
-
}
|
|
8196
|
-
if (frame != null || typeof requestAnimationFrame !== "function") return;
|
|
8197
|
-
frame = requestAnimationFrame(() => {
|
|
8198
|
-
frame = null;
|
|
8199
|
-
if (track.isHeld()) isDue = true;
|
|
8200
|
-
else apply();
|
|
8201
|
-
});
|
|
8202
|
-
}
|
|
8203
|
-
const resize = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(schedule);
|
|
8204
|
-
function observeItems() {
|
|
8205
|
-
if (resize == null) return;
|
|
8206
|
-
resize.disconnect();
|
|
8207
|
-
resize.observe(element);
|
|
8208
|
-
for (const item of Array.from(element.children)) resize.observe(item);
|
|
8209
|
-
}
|
|
8210
|
-
const mutations = typeof MutationObserver === "undefined" ? null : new MutationObserver(() => {
|
|
8211
|
-
observeItems();
|
|
8212
|
-
schedule();
|
|
8213
|
-
});
|
|
8214
|
-
mutations?.observe(element, { childList: true });
|
|
8215
|
-
observeItems();
|
|
8216
|
-
schedule();
|
|
8217
|
-
return {
|
|
8218
|
-
takeDue: () => isDue ? apply : void 0,
|
|
8219
|
-
stop() {
|
|
8220
|
-
mutations?.disconnect();
|
|
8221
|
-
resize?.disconnect();
|
|
8222
|
-
if (frame != null) cancelAnimationFrame(frame);
|
|
8223
|
-
frame = null;
|
|
8224
|
-
skip([]);
|
|
8225
|
-
}
|
|
8226
|
-
};
|
|
8227
|
-
}
|
|
8228
|
-
//#endregion
|
|
8229
|
-
//#region src/composables/internal/snapPagingTrack.ts
|
|
8230
|
-
function createSnapTrack(element, onHeld) {
|
|
8231
|
-
let held = false;
|
|
8232
|
-
let heldAt = 0;
|
|
8233
|
-
let heldTravel = 0;
|
|
8234
|
-
let sign = 1;
|
|
8235
|
-
let ownSnapType = "";
|
|
8236
|
-
let ownSnapPriority = "";
|
|
8237
|
-
const isRtl = () => getComputedStyle(element).direction === "rtl";
|
|
8238
|
-
const nativeTravel = () => Math.max(0, element.scrollWidth - element.clientWidth);
|
|
8239
|
-
const position = () => held ? heldAt : Math.abs(element.scrollLeft);
|
|
8240
|
-
const travel = () => held ? heldTravel : nativeTravel();
|
|
8241
|
-
function write(at) {
|
|
8242
|
-
element.scrollTo({
|
|
8243
|
-
left: sign * at,
|
|
8244
|
-
behavior: "instant"
|
|
8245
|
-
});
|
|
8246
|
-
}
|
|
8247
|
-
function report() {
|
|
8248
|
-
onHeld?.({
|
|
8249
|
-
offset: heldAt,
|
|
8250
|
-
travel: heldTravel
|
|
8251
|
-
});
|
|
8252
|
-
}
|
|
8253
|
-
return {
|
|
8254
|
-
isHeld: () => held,
|
|
8255
|
-
position,
|
|
8256
|
-
travel,
|
|
8257
|
-
pages: () => snapPages(element, position(), travel()),
|
|
8258
|
-
viewWidth() {
|
|
8259
|
-
const style = getComputedStyle(element);
|
|
8260
|
-
const padding = (Number.parseFloat(style.scrollPaddingLeft) || 0) + (Number.parseFloat(style.scrollPaddingRight) || 0);
|
|
8261
|
-
return Math.max(1, element.clientWidth - padding);
|
|
8262
|
-
},
|
|
8263
|
-
takeOver() {
|
|
8264
|
-
if (held) return;
|
|
8265
|
-
sign = isRtl() ? -1 : 1;
|
|
8266
|
-
heldAt = Math.abs(element.scrollLeft);
|
|
8267
|
-
heldTravel = nativeTravel();
|
|
8268
|
-
ownSnapType = element.style.getPropertyValue("scroll-snap-type");
|
|
8269
|
-
ownSnapPriority = element.style.getPropertyPriority("scroll-snap-type");
|
|
8270
|
-
element.style.setProperty("scroll-snap-type", "none");
|
|
8271
|
-
held = true;
|
|
8272
|
-
report();
|
|
8273
|
-
},
|
|
8274
|
-
place(at) {
|
|
8275
|
-
if (!held) return;
|
|
8276
|
-
heldAt = Math.min(Math.max(at, 0), heldTravel);
|
|
8277
|
-
write(heldAt);
|
|
8278
|
-
report();
|
|
8279
|
-
},
|
|
8280
|
-
remeasure() {
|
|
8281
|
-
if (!held) return;
|
|
8282
|
-
const next = nativeTravel();
|
|
8283
|
-
if (next === heldTravel) return;
|
|
8284
|
-
heldTravel = next;
|
|
8285
|
-
if (heldAt > heldTravel) {
|
|
8286
|
-
heldAt = heldTravel;
|
|
8287
|
-
write(heldAt);
|
|
8288
|
-
}
|
|
8289
|
-
report();
|
|
8290
|
-
},
|
|
8291
|
-
handBack(beforeSnap) {
|
|
8292
|
-
if (!held) return;
|
|
8293
|
-
held = false;
|
|
8294
|
-
beforeSnap?.();
|
|
8295
|
-
if (ownSnapType === "") element.style.removeProperty("scroll-snap-type");
|
|
8296
|
-
else element.style.setProperty("scroll-snap-type", ownSnapType, ownSnapPriority);
|
|
8297
|
-
write(heldAt);
|
|
8298
|
-
if (onHeld != null) {
|
|
8299
|
-
onHeld({
|
|
8300
|
-
offset: heldAt,
|
|
8301
|
-
travel: heldTravel
|
|
8302
|
-
});
|
|
8303
|
-
onHeld(null);
|
|
8304
|
-
}
|
|
8305
|
-
}
|
|
8306
|
-
};
|
|
8307
|
-
}
|
|
8308
|
-
//#endregion
|
|
8309
|
-
//#region src/composables/internal/snapPagingAttach.ts
|
|
8310
|
-
function prefersReducedMotion() {
|
|
8311
|
-
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
8312
|
-
}
|
|
8313
|
-
/**
|
|
8314
|
-
* 把吸附分页挂到滚动行上。拖动走手势引擎:一个横向的拖动识别器接手指、触控笔和
|
|
8315
|
-
* 触控板横扫,过了 UIKit 的 10pt 起拖距离才接管这一行,松手速度由识别器的
|
|
8316
|
-
* VelocityTracker 给出;鼠标拖动和鼠标滚轮留给原生滚动。另有一个不认领触摸的
|
|
8317
|
-
* 「接住」识别器:翻页途中按上去就停住这一行。
|
|
8318
|
-
*
|
|
8319
|
-
* - 松手后的翻页:按下后这一行再走 `paging.catchStopMs` 才停住,和 UIKit 实测一致;
|
|
8320
|
-
* 手指或触控笔的这次触摸到不了下面的内容,鼠标保留它的点击。
|
|
8321
|
-
* - 按钮、方向键、`scrollTo` 这类程序发起的翻页:手指一碰就停住。鼠标仍然等那一段。
|
|
8322
|
-
* - 停住后不拖、直接抬起:停到最近的一页。停住之前就抬起:翻页照常走完。
|
|
8323
|
-
*/
|
|
8324
|
-
function attachPaging(element, options, onHeld, clock = browserClock) {
|
|
8325
|
-
const track = createSnapTrack(element, onHeld);
|
|
8326
|
-
const skip = followSkippedStops(element, track);
|
|
8327
|
-
let pages = [0];
|
|
8328
|
-
let anchor = 0;
|
|
8329
|
-
let sign = 1;
|
|
8330
|
-
let motion = null;
|
|
8331
|
-
let isReleaseSettle = false;
|
|
8332
|
-
let drag = null;
|
|
8333
|
-
let isCaught = false;
|
|
8334
|
-
let isCatchArmed = false;
|
|
8335
|
-
let releaseSelection = null;
|
|
8336
|
-
let isAttached = true;
|
|
8337
|
-
function hold() {
|
|
8338
|
-
motion?.stop();
|
|
8339
|
-
motion = null;
|
|
8340
|
-
track.takeOver();
|
|
8341
|
-
sign = getComputedStyle(element).direction === "rtl" ? -1 : 1;
|
|
8342
|
-
const at = track.position();
|
|
8343
|
-
const { stops } = track.pages();
|
|
8344
|
-
pages = (options().pages ?? "view") === "item" ? stops : viewPages(stops, nearestIndex(stops, at), track.viewWidth());
|
|
8345
|
-
anchor = nearestIndex(pages, at);
|
|
8346
|
-
}
|
|
8347
|
-
function finish() {
|
|
8348
|
-
if (drag != null || isCaught) return;
|
|
8349
|
-
track.handBack(skip.takeDue());
|
|
8350
|
-
}
|
|
8351
|
-
function settleTo(target, velocity, fromRelease) {
|
|
8352
|
-
motion?.stop();
|
|
8353
|
-
motion = null;
|
|
8354
|
-
isReleaseSettle = fromRelease;
|
|
8355
|
-
if (prefersReducedMotion()) {
|
|
8356
|
-
track.place(target);
|
|
8357
|
-
finish();
|
|
8358
|
-
return;
|
|
8359
|
-
}
|
|
8360
|
-
motion = springTo(clock, track.position(), target, velocity, (at) => track.place(at), () => {
|
|
8361
|
-
motion = null;
|
|
8362
|
-
finish();
|
|
8363
|
-
});
|
|
8364
|
-
}
|
|
8365
|
-
function release(velocity) {
|
|
8366
|
-
const at = track.position();
|
|
8367
|
-
settleTo(pages[pickPage(pages, at, velocity, anchor)] ?? at, velocity, true);
|
|
8368
|
-
}
|
|
8369
|
-
const host = getGestureHost(element.ownerDocument);
|
|
8370
|
-
const pan = new PanGestureRecognizer({
|
|
8371
|
-
name: "snapPaging",
|
|
8372
|
-
direction: "horizontal",
|
|
8373
|
-
allowedPointerTypes: ["touch", "pen"],
|
|
8374
|
-
allowedScrollTypes: ["continuous"],
|
|
8375
|
-
shouldBegin: () => track.isHeld() || track.travel() > 1
|
|
8376
|
-
});
|
|
8377
|
-
const catcher = new SettleCatcher({
|
|
8378
|
-
name: "snapPagingCatch",
|
|
8379
|
-
minimumPressDuration: 0,
|
|
8380
|
-
allowableMovement: Number.POSITIVE_INFINITY,
|
|
8381
|
-
selectionLock: null,
|
|
8382
|
-
shouldBegin: () => motion != null && drag == null
|
|
8383
|
-
});
|
|
8384
|
-
catcher.recognizeSimultaneouslyWith(pan);
|
|
8385
|
-
function holdSelection(on) {
|
|
8386
|
-
if (on && releaseSelection == null && locksSelectionFor(catcher.pointerType ?? "touch")) releaseSelection = lockSelection([element], null);
|
|
8387
|
-
else if (!on && releaseSelection != null) {
|
|
8388
|
-
releaseSelection();
|
|
8389
|
-
releaseSelection = null;
|
|
8390
|
-
}
|
|
8391
|
-
}
|
|
8392
|
-
function clearCatchTimer() {
|
|
8393
|
-
if (isCatchArmed) {
|
|
8394
|
-
isCatchArmed = false;
|
|
8395
|
-
catcher.disarmCatch();
|
|
8396
|
-
}
|
|
8397
|
-
}
|
|
8398
|
-
function catchSettle() {
|
|
8399
|
-
if (motion == null || drag != null) return;
|
|
8400
|
-
hold();
|
|
8401
|
-
isCaught = true;
|
|
8402
|
-
}
|
|
8403
|
-
pan.addListener(() => {
|
|
8404
|
-
if (!isAttached) return;
|
|
8405
|
-
const state = pan.state;
|
|
8406
|
-
if (state === "began") {
|
|
8407
|
-
clearCatchTimer();
|
|
8408
|
-
hold();
|
|
8409
|
-
drag = {
|
|
8410
|
-
from: track.position(),
|
|
8411
|
-
isScroll: pan.trackedTouches[0]?.scrollType != null
|
|
8412
|
-
};
|
|
8413
|
-
}
|
|
8414
|
-
if (drag == null) return;
|
|
8415
|
-
if (state === "began" || state === "changed") {
|
|
8416
|
-
let at = drag.from - sign * pan.translation().x;
|
|
8417
|
-
if (drag.isScroll) {
|
|
8418
|
-
const low = pages[anchor - 1] ?? pages[0] ?? 0;
|
|
8419
|
-
const high = pages[anchor + 1] ?? pages[pages.length - 1] ?? 0;
|
|
8420
|
-
at = Math.min(Math.max(at, low), high);
|
|
8421
|
-
}
|
|
8422
|
-
host.ownScroll(element);
|
|
8423
|
-
track.place(at);
|
|
8424
|
-
return;
|
|
8425
|
-
}
|
|
8426
|
-
if (state === "ended" || state === "cancelled") {
|
|
8427
|
-
drag = null;
|
|
8428
|
-
isCaught = false;
|
|
8429
|
-
release(state === "ended" ? -sign * pan.velocity().x : 0);
|
|
8430
|
-
}
|
|
8431
|
-
});
|
|
8432
|
-
catcher.addListener(() => {
|
|
8433
|
-
if (!isAttached) return;
|
|
8434
|
-
const state = catcher.state;
|
|
8435
|
-
if (state === "began") {
|
|
8436
|
-
holdSelection(true);
|
|
8437
|
-
const isMouse = catcher.pointerType === "mouse";
|
|
8438
|
-
if (isReleaseSettle && !isMouse) catcher.takeFromContent();
|
|
8439
|
-
clearCatchTimer();
|
|
8440
|
-
isCaught = false;
|
|
8441
|
-
if (!isReleaseSettle && !isMouse) {
|
|
8442
|
-
catchSettle();
|
|
8443
|
-
return;
|
|
8444
|
-
}
|
|
8445
|
-
isCatchArmed = true;
|
|
8446
|
-
catcher.armCatch(paging.catchStopMs, () => {
|
|
8447
|
-
if (!isCatchArmed) return;
|
|
8448
|
-
isCatchArmed = false;
|
|
8449
|
-
catchSettle();
|
|
8450
|
-
});
|
|
8451
|
-
return;
|
|
8452
|
-
}
|
|
8453
|
-
if (state === "ended" || state === "cancelled") {
|
|
8454
|
-
holdSelection(false);
|
|
8455
|
-
if (isCatchArmed) {
|
|
8456
|
-
clearCatchTimer();
|
|
8457
|
-
return;
|
|
8458
|
-
}
|
|
8459
|
-
const wasCaught = isCaught;
|
|
8460
|
-
isCaught = false;
|
|
8461
|
-
if (wasCaught && drag == null && motion == null) release(0);
|
|
8462
|
-
}
|
|
8463
|
-
});
|
|
8464
|
-
const detachPan = host.attach(element, pan);
|
|
8465
|
-
const detachCatch = host.attach(element, catcher);
|
|
8466
|
-
const remeasure = () => track.remeasure();
|
|
8467
|
-
const unobserveSizes = [element, ...Array.from(element.children)].map((node) => observeResize(node, remeasure));
|
|
8468
|
-
function move(target) {
|
|
8469
|
-
if (drag != null && !drag.isScroll) return;
|
|
8470
|
-
drag = null;
|
|
8471
|
-
const velocity = motion?.velocity() ?? 0;
|
|
8472
|
-
hold();
|
|
8473
|
-
const end = track.travel();
|
|
8474
|
-
settleTo(Math.min(Math.max(target(track.position(), end), 0), end), velocity, false);
|
|
8475
|
-
}
|
|
8476
|
-
return {
|
|
8477
|
-
detach() {
|
|
8478
|
-
isAttached = false;
|
|
8479
|
-
clearCatchTimer();
|
|
8480
|
-
holdSelection(false);
|
|
8481
|
-
detachCatch();
|
|
8482
|
-
detachPan();
|
|
8483
|
-
for (const unobserve of unobserveSizes) unobserve();
|
|
8484
|
-
motion?.stop();
|
|
8485
|
-
motion = null;
|
|
8486
|
-
drag = null;
|
|
8487
|
-
isCaught = false;
|
|
8488
|
-
track.handBack();
|
|
8489
|
-
skip.stop();
|
|
8490
|
-
},
|
|
8491
|
-
move,
|
|
8492
|
-
moveHeld(target) {
|
|
8493
|
-
if (!track.isHeld()) return false;
|
|
8494
|
-
move(target);
|
|
8495
|
-
return true;
|
|
8496
|
-
}
|
|
8497
|
-
};
|
|
8498
|
-
}
|
|
8499
|
-
//#endregion
|
|
8500
|
-
//#region src/composables/useSnapPaging.ts
|
|
8501
|
-
/**
|
|
8502
|
-
* 给 Carousel 的吸附停点加上 iOS 式翻页:`<Carousel :has-snap="paging">`,
|
|
8503
|
-
* 其中 `const paging = useSnapPaging()`。手指或触控板横扫时,一次轻扫翻一屏,
|
|
8504
|
-
* 传 `{ pages: 'item' }` 时翻一项,停在某一项的起始边。鼠标滚轮和鼠标拖动保持原生滚动。
|
|
8505
|
-
*
|
|
8506
|
-
* `options` 可以是 ref 或 getter,新的 `pages` 从下一次轻扫开始生效。
|
|
8507
|
-
* Carousel 一直用它第一次挂上的那个值。
|
|
8508
|
-
*/
|
|
8509
|
-
function useSnapPaging(options = {}) {
|
|
8510
|
-
return makeSnapPaging((element, onHeld) => attachPaging(element, () => toValue(options), onHeld));
|
|
8511
|
-
}
|
|
8512
|
-
//#endregion
|
|
8513
|
-
//#region src/composables/useStreamingText.ts
|
|
8514
|
-
const CHARS_PER_TICK = {
|
|
8515
|
-
natural: 10,
|
|
8516
|
-
fast: 4,
|
|
8517
|
-
instant: Number.POSITIVE_INFINITY
|
|
8518
|
-
};
|
|
8519
|
-
const FALLBACK_DURATION_MS = 95;
|
|
8520
|
-
function parseCssDuration(value) {
|
|
8521
|
-
const milliseconds = /^([\d.]+)ms$/.exec(value.trim());
|
|
8522
|
-
if (milliseconds?.[1] != null) return Number(milliseconds[1]);
|
|
8523
|
-
const seconds = /^([\d.]+)s$/.exec(value.trim());
|
|
8524
|
-
if (seconds?.[1] != null) return Number(seconds[1]) * 1e3;
|
|
8525
|
-
return null;
|
|
8526
|
-
}
|
|
8527
|
-
function motionDuration() {
|
|
8528
|
-
if (typeof document === "undefined") return FALLBACK_DURATION_MS;
|
|
8529
|
-
return parseCssDuration(getComputedStyle(document.documentElement).getPropertyValue("--astryx-duration-fast-min")) ?? FALLBACK_DURATION_MS;
|
|
8530
|
-
}
|
|
8531
|
-
function tickInterval(speed) {
|
|
8532
|
-
if (speed === "instant") return 0;
|
|
8533
|
-
const duration = motionDuration();
|
|
8534
|
-
const tick = speed === "fast" ? duration / 20 : duration / 10;
|
|
8535
|
-
return Math.max(4, Math.round(tick));
|
|
8536
|
-
}
|
|
8537
|
-
const graphemeSegmenter = typeof Intl.Segmenter === "function" ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null;
|
|
8538
|
-
function isLowSurrogate(codeUnit) {
|
|
8539
|
-
return codeUnit >= 56320 && codeUnit <= 57343;
|
|
8540
|
-
}
|
|
8541
|
-
/**
|
|
8542
|
-
* Move `offset` back to the start of the grapheme it lands inside, so a slice
|
|
8543
|
-
* never cuts a surrogate pair, a flag, or a ZWJ sequence in half.
|
|
8544
|
-
*/
|
|
8545
|
-
function snapToGraphemeBoundary(text, offset) {
|
|
8546
|
-
if (offset <= 0 || offset >= text.length) return offset;
|
|
8547
|
-
if (graphemeSegmenter != null) return graphemeSegmenter.segment(text).containing(offset)?.index ?? offset;
|
|
8548
|
-
return isLowSurrogate(text.charCodeAt(offset)) ? offset - 1 : offset;
|
|
8549
|
-
}
|
|
8550
|
-
/**
|
|
8551
|
-
* Smooth a burst of streamed text into a steady reveal.
|
|
8552
|
-
* While `isStreaming` is false, or the user prefers reduced motion, the full
|
|
8553
|
-
* source is returned. The reveal steps by UTF-16 units and then snaps back to
|
|
8554
|
-
* a grapheme boundary.
|
|
8555
|
-
*/
|
|
8556
|
-
function useStreamingText(targetText, isStreaming = false, options) {
|
|
8557
|
-
const displayedLen = ref(0);
|
|
8558
|
-
const prefersReducedMotion = useMediaQuery("(prefers-reduced-motion: reduce)");
|
|
8559
|
-
const target = computed(() => toValue(targetText));
|
|
8560
|
-
const streaming = computed(() => toValue(isStreaming));
|
|
8561
|
-
const speed = computed(() => toValue(options)?.speed ?? "natural");
|
|
8562
|
-
const instant = computed(() => !streaming.value || speed.value === "instant" || prefersReducedMotion.value);
|
|
8563
|
-
watch(target, (next, previous) => {
|
|
8564
|
-
const revealed = (previous ?? "").slice(0, displayedLen.value);
|
|
8565
|
-
if (next.length === 0 || revealed.length > 0 && !next.startsWith(revealed)) displayedLen.value = 0;
|
|
8566
|
-
});
|
|
8567
|
-
watch(streaming, (next) => {
|
|
8568
|
-
if (!next) displayedLen.value = target.value.length;
|
|
8569
|
-
});
|
|
8570
|
-
watch(instant, (isInstant, _, onCleanup) => {
|
|
8571
|
-
if (isInstant) return;
|
|
8572
|
-
let frame = 0;
|
|
8573
|
-
let lastTick = 0;
|
|
8574
|
-
const tick = (now) => {
|
|
8575
|
-
const interval = tickInterval(speed.value);
|
|
8576
|
-
if (now - lastTick >= interval) {
|
|
8577
|
-
lastTick = now;
|
|
8578
|
-
const goal = target.value.length;
|
|
8579
|
-
if (displayedLen.value < goal) {
|
|
8580
|
-
const step = CHARS_PER_TICK[speed.value];
|
|
8581
|
-
displayedLen.value = Math.min(displayedLen.value + step, goal);
|
|
8582
|
-
}
|
|
8583
|
-
}
|
|
8584
|
-
frame = requestAnimationFrame(tick);
|
|
8585
|
-
};
|
|
8586
|
-
frame = requestAnimationFrame(tick);
|
|
8587
|
-
onCleanup(() => cancelAnimationFrame(frame));
|
|
8588
|
-
}, { immediate: true });
|
|
8589
|
-
return computed(() => {
|
|
8590
|
-
const text = target.value;
|
|
8591
|
-
if (instant.value) return text;
|
|
8592
|
-
return text.slice(0, snapToGraphemeBoundary(text, displayedLen.value));
|
|
8593
|
-
});
|
|
8594
|
-
}
|
|
8595
|
-
//#endregion
|
|
8596
|
-
//#region src/composables/useTouchTrigger.ts
|
|
8597
|
-
/**
|
|
8598
|
-
* 悬停类浮层(Tooltip、HoverCard)共用的触屏行为。
|
|
8599
|
-
*
|
|
8600
|
-
* 触屏上表达不了「悬停」:点一下会合成 `mouseenter`,不处理的悬停浮层要么
|
|
8601
|
-
* 每次点都弹出来、又没有东西能关掉它,要么把用户点控件的这一下吃掉。
|
|
8602
|
-
*
|
|
8603
|
-
* 一次触屏按压要等它成了轻点才算数。手指落在触发器上可能是开始滚动、缩放或长按,
|
|
8604
|
-
* 只有浏览器在手指挪动或抬起后才知道是哪个,它的 click 就是结论。所以从触发器上开始的
|
|
8605
|
-
* 滚动不会打开提示,停着不动的手指也不会。点开的浮层在外面轻点抬起时关,
|
|
8606
|
-
* 或在外面开始的滚动被浏览器接走时关,和 iOS 关闭弹出框的时机一样。
|
|
8607
|
-
*/
|
|
8608
|
-
function useTouchTrigger(options) {
|
|
8609
|
-
const touch = useTouchTriggerInternal(options);
|
|
8610
|
-
return {
|
|
8611
|
-
isTouchPointer: touch.isTouchPointer,
|
|
8612
|
-
isTouchInteraction: touch.isTouchInteraction,
|
|
8613
|
-
handlePointerEnter: touch.handlePointerEnter,
|
|
8614
|
-
handlePointerDown: touch.handlePointerDown,
|
|
8615
|
-
clearTapOpen: touch.clearTapOpen
|
|
8616
|
-
};
|
|
8617
|
-
}
|
|
8618
|
-
//#endregion
|
|
8619
|
-
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 };
|
|
5199
|
+
export { lockSelection as a, MANIPULATION as c, getGestureHost as i, isActive as l, PanGestureRecognizer as n, locksSelectionFor as o, travel as r, GestureRecognizer as s, useAttachment as t, internals as u };
|