@astryx-vue/core 0.35.0 → 0.36.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-rndlABEe.js → AlertDialog-C4oB89RV.js} +5 -5
- package/dist/AppShell/index.js +1 -1
- package/dist/{AppShell-eVrOpRqn.js → AppShell-CU12SF6s.js} +2 -2
- package/dist/AvatarGroup/index.d.ts +1 -1
- package/dist/AvatarGroup/index.js +1 -1
- package/dist/{AvatarGroup-BEBUEhxF.js → AvatarGroup-DhSPWemf.js} +1 -1
- package/dist/Banner/index.d.ts +1 -1
- package/dist/Banner/index.js +1 -1
- package/dist/{Banner-CVBNGDsD.js → Banner-DeauKxQw.js} +1 -1
- package/dist/BottomSheet/index.js +2 -2
- package/dist/BottomSheet-Chr9yCIL.js +4353 -0
- package/dist/{BottomSheet-B3qXtKQj.js → BottomSheet-DCLOhzZP.js} +1 -1
- package/dist/Breadcrumbs/index.js +2 -2
- package/dist/{Breadcrumbs-B-w_yw-n.js → Breadcrumbs-BfjWIfgO.js} +1 -1
- package/dist/Button/index.d.ts +1 -1
- package/dist/Button/index.js +1 -1
- package/dist/{Button-DTdlisqJ.js → Button-V6i-PeBt.js} +2 -2
- package/dist/ButtonGroup/index.d.ts +1 -1
- package/dist/ButtonGroup/index.js +1 -1
- package/dist/{ButtonGroup-Bjzs-HAG.js → ButtonGroup-CEDeeGkY.js} +2 -2
- 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-DjySyeDR.js → Carousel-5NYWpta1.js} +1 -1
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.js +1 -1
- package/dist/{Chat-DQ6BGAvP.js → Chat-f9HzZe5y.js} +2 -2
- package/dist/CheckboxInput/index.d.ts +1 -1
- package/dist/CheckboxInput/index.js +1 -1
- package/dist/{CheckboxInput-DSW8yq92.js → CheckboxInput-ixAs3zkT.js} +4 -4
- package/dist/CheckboxList/index.d.ts +1 -1
- package/dist/CheckboxList/index.js +1 -1
- package/dist/{CheckboxListItem-B2E2O1AE.js → CheckboxListItem-DoWYdLf-.js} +4 -4
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/ClickableCard/index.js +1 -1
- package/dist/{ClickableCard-D4EGX9Dh.js → ClickableCard-DuOcbNlt.js} +1 -1
- package/dist/Code/index.js +2 -2
- package/dist/{Code-BqqB2kUM.js → Code-qHt8uZqb.js} +1 -1
- package/dist/{CodeBlock-D7ZJQV5Q.js → CodeBlock-2zigEFFD.js} +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-C5xSG7oP.js → Collapsible-Dxp-BWv-.js} +1 -1
- package/dist/CommandPalette/index.js +1 -1
- package/dist/{CommandPalette-BUNdrxrB.js → CommandPalette-PyPfsPLY.js} +2 -2
- package/dist/ComplexSelector/index.d.ts +1 -1
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-m9wi7E0j.js → ComplexSelector-B07QdP_p.js} +2 -2
- package/dist/ContextMenu/index.d.ts +1 -1
- package/dist/ContextMenu/index.js +2 -2
- package/dist/{ContextMenu-BEHfVIAq.js → ContextMenu-B6NH9NBS.js} +3 -3
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/{DateInput-CHeetz7k.js → DateInput-TrPijW9a.js} +4 -4
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/{DateRangeInput-D524C1wc.js → DateRangeInput-bKPzsoHA.js} +3 -3
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-2gTBrcbr.js → DateTimeInput-5jZPqFu2.js} +5 -5
- package/dist/Dialog/index.d.ts +1 -1
- package/dist/Dialog/index.js +3 -3
- package/dist/{Dialog-nyLGClca.js → Dialog-CDAicnpK.js} +1 -1
- package/dist/{Dialog-DS3xE1B7.js → Dialog-dm_qZ9NI.js} +1 -1
- package/dist/{DialogHeader-u_AaZpyZ.js → DialogHeader-CQfcOIfF.js} +2 -2
- package/dist/Drawer/index.d.ts +1 -1
- package/dist/Drawer/index.js +1 -1
- package/dist/{Drawer-DqUdaZFh.js → Drawer-DKSqpR2p.js} +2 -2
- package/dist/DropdownMenu/index.js +2 -2
- package/dist/{DropdownMenu-DlAON5Jf.js → DropdownMenu-C-SLsVSO.js} +6 -6
- package/dist/Field/index.js +3 -3
- package/dist/{Field-YNS4XxpR.js → Field-CZndbiqR.js} +1 -1
- package/dist/{FieldInfoTip-DFlIBJlR.js → FieldInfoTip-Ii7lSYS8.js} +1 -1
- package/dist/{FieldLabel-i0gos7hU.js → FieldLabel-ru3qavED.js} +1 -1
- package/dist/FileInput/index.js +1 -1
- package/dist/{FileInput-DYVzAtvz.js → FileInput-BtVTN7LN.js} +3 -3
- package/dist/IconButton/index.js +1 -1
- package/dist/{IconButton-DXt8DtsN.js → IconButton-4BXILpv-.js} +1 -1
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InfoTip/index.js +1 -1
- package/dist/{InfoTip--fZOD0ux.js → InfoTip-D2MzKXZH.js} +1 -1
- package/dist/{InputClearButton-LF0iVTVF.js → InputClearButton-Cm5Q3KK2.js} +1 -1
- package/dist/InputGroup/index.js +1 -1
- package/dist/{InputGroup-D4CPVzo0.js → InputGroup-CjB_XpEy.js} +1 -1
- package/dist/{Item-BKISM91o.js → Item-CKYsTbM4.js} +1 -1
- package/dist/Layout/index.js +2 -2
- package/dist/{Layout-BwSvAsLi.js → Layout-CpFgVnlQ.js} +1 -1
- package/dist/{LayoutPanel-CmzJQpnL.js → LayoutPanel-Dhm0Hubb.js} +1 -1
- package/dist/Lightbox/index.js +1 -1
- package/dist/{Lightbox-B32Yh8Uy.js → Lightbox-BSzyDGkK.js} +1 -1
- package/dist/Link/index.d.ts +1 -1
- package/dist/Link/index.js +1 -1
- package/dist/{Link-DSXyw9MW.js → Link-BnM830Xa.js} +1 -1
- package/dist/List/index.js +2 -2
- package/dist/{ListItem-D3iEhvU2.js → ListItem-B1ztelEC.js} +2 -2
- package/dist/Markdown/index.d.ts +1 -1
- package/dist/Markdown/index.js +1 -1
- package/dist/{Markdown-BY5Bju8w.js → Markdown-JjZLAFq2.js} +2 -2
- package/dist/MobileNav/index.js +1 -1
- package/dist/{MobileNavToggle-sC6GPVKQ.js → MobileNavToggle-C1_IinAo.js} +1 -1
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MoreMenu/index.js +1 -1
- package/dist/{MoreMenu-CcavOuxV.js → MoreMenu-DbYO8V7N.js} +4 -4
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/MultiSelector/index.js +1 -1
- package/dist/{MultiSelector-Diu5zHbP.js → MultiSelector-CthCkW-w.js} +4 -4
- package/dist/NavItem/index.js +1 -1
- package/dist/{NavItem-DlW8noR6.js → NavItem-DTO-BEfc.js} +1 -1
- package/dist/NavMenu/index.js +2 -2
- package/dist/{NavMenu-J2kmtb1B.js → NavMenu-g8ZVhLMG.js} +1 -1
- package/dist/{NavMenuItem-DItNRTDZ.js → NavMenuItem-DJg9jfHm.js} +2 -2
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/NumberInput/index.js +1 -1
- package/dist/{NumberInput-vhm5TQon.js → NumberInput-BM52uE72.js} +3 -3
- package/dist/Outline/index.js +1 -1
- package/dist/{Outline-CVIDd0fN.js → Outline-D4DJTfKp.js} +1 -1
- package/dist/OverflowList/index.d.ts +1 -1
- package/dist/OverflowList/index.js +1 -1
- package/dist/{OverflowList-DjWWBOkx.js → OverflowList-nW6GCEsY.js} +1 -1
- package/dist/Overlay/index.d.ts +1 -1
- package/dist/Pagination/index.js +1 -1
- package/dist/{Pagination-DKsePQjC.js → Pagination-DFZivDZZ.js} +2 -2
- package/dist/{PanGestureRecognizer-C7hNunjF.js → PanGestureRecognizer-C-gk9mOy.js} +1 -1
- package/dist/{PickerWheel-Bf7xe6g6.js → PickerWheel-sIOSfcfO.js} +5 -5
- package/dist/Popover/index.d.ts +1 -1
- package/dist/Popover/index.js +1 -1
- package/dist/{Popover-CKgepPJ6.js → Popover-IvZGq1LC.js} +3 -3
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-DopZnZDZ.js → PowerSearch-CQdyB8_N.js} +19 -19
- package/dist/{PressTracker-DL75qEq_.js → PressTracker-CPRIrG4f.js} +2 -2
- package/dist/Radio/index.d.ts +1 -1
- package/dist/Radio/index.js +1 -1
- package/dist/{RadioGroup-C-S-SnbH.js → RadioGroup-OLFNjvKt.js} +4 -4
- package/dist/RadioList/index.d.ts +1 -1
- package/dist/RadioList/index.js +1 -1
- package/dist/{RadioListItem-DzKVK4DZ.js → RadioListItem-BAEF0vc8.js} +1 -1
- package/dist/Resizable/index.js +1 -1
- package/dist/{ResizeHandle-CaZEB4Py.js → ResizeHandle-Bd4TdK7E.js} +1 -1
- package/dist/ScrollableArea/index.d.ts +1 -1
- package/dist/SegmentedControl/index.js +1 -1
- package/dist/{SegmentedControl-Bp7dpEjn.js → SegmentedControl-C0xXOVTv.js} +8 -8
- package/dist/SelectableCard/index.d.ts +1 -1
- package/dist/SelectableCard/index.js +1 -1
- package/dist/{SelectableCard-DPWaUCGZ.js → SelectableCard-B2QbpWiT.js} +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/{Selector-CJmeuWhN.js → Selector-icOfE3ja.js} +2 -2
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/SideNav/index.js +1 -1
- package/dist/{SideNav-D-AQqNPx.js → SideNav-ZZ5zCQz0.js} +4 -4
- package/dist/Slider/index.js +1 -1
- package/dist/{Slider-DU-Yl3fd.js → Slider-Bd5fxqRa.js} +7 -7
- package/dist/Stack/index.d.ts +1 -1
- package/dist/Stepper/index.js +1 -1
- package/dist/{Stepper-67SsxUne.js → Stepper-3oMdVe0c.js} +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/Switch/index.js +1 -1
- package/dist/{Switch-C6qaebkX.js → Switch-COKmqJQU.js} +8 -8
- package/dist/TabList/index.d.ts +1 -1
- package/dist/TabList/index.js +1 -1
- package/dist/{TabList-TbJ6y1gN.js → TabList-C-HBxmkc.js} +2 -2
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-DG_GVUF4.js → Table-aMqVf_iH.js} +9 -9
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/{TextArea-D6EtmxTk.js → TextArea-YJtL9Fi6.js} +4 -4
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/TextInput/index.js +1 -1
- package/dist/{TextInput-AngvgtdT.js → TextInput-CuPxOApN.js} +4 -4
- package/dist/Thumbnail/index.js +1 -1
- package/dist/{Thumbnail-DExkxw8a.js → Thumbnail-oqrKH-co.js} +2 -2
- package/dist/{TimeField-BNGg25yA.js → TimeField-DNxPI2cM.js} +40 -11
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/TimeInput/index.js +1 -1
- package/dist/{TimeInput-D8lwgHOR.js → TimeInput-PJdyNX0T.js} +2 -2
- package/dist/Timer/index.d.ts +1 -1
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/Timestamp/index.js +1 -1
- package/dist/{Timestamp-CeSb1A8c.js → Timestamp-CfzqAAX2.js} +1 -1
- package/dist/Toast/index.js +1 -1
- package/dist/{Toast-B2Fq-JYA.js → Toast-W6aKxXlF.js} +3 -3
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/ToggleButton/index.js +1 -1
- package/dist/{ToggleButton-Bn8yLHbh.js → ToggleButton-Ditxp2jT.js} +3 -3
- package/dist/Token/index.js +1 -1
- package/dist/{Token-Dpxh42Mw.js → Token-Dk6MPUkH.js} +1 -1
- package/dist/Tokenizer/index.d.ts +1 -1
- package/dist/Tokenizer/index.js +1 -1
- package/dist/{Tokenizer-B3EnI98V.js → Tokenizer-CdyoUaoZ.js} +7 -7
- package/dist/Toolbar/index.d.ts +1 -1
- package/dist/TopNav/index.d.ts +1 -1
- package/dist/TopNav/index.js +1 -1
- package/dist/{TopNav-D7mzM7pu.js → TopNav-CxAm5bN5.js} +3 -3
- package/dist/TreeList/index.js +1 -1
- package/dist/{TreeList-BmeXFFqr.js → TreeList-Dnx-uco3.js} +1 -1
- package/dist/Typeahead/index.d.ts +3 -3
- package/dist/Typeahead/index.js +1 -1
- package/dist/{Typeahead-kLp9UG-Q.js → Typeahead-Cx086Mmv.js} +3 -3
- package/dist/{accessibleName-Zr1_WoBg.js → accessibleName-CN1vKvS_.js} +1 -1
- package/dist/{boxHold-Bh1fTcXx.js → boxHold-D1G2s1tG.js} +4 -4
- package/dist/{browserClickWait-CiUtuWNK.js → browserClickWait-Cb550_M2.js} +2 -2
- package/dist/{clickGuard-Bd-jBj_G.js → clickGuard-BkegH2NW.js} +1 -1
- package/dist/composables/index.d.ts +2 -2
- package/dist/composables/index.js +7 -7
- package/dist/{composables-B6ebqwHY.js → composables-CpG7bhuQ.js} +74 -4
- package/dist/{geometry-0e0f5Mjv.js → geometry-BRW7FETc.js} +6 -195
- package/dist/{haptics-DIfaJavG.js → haptics-BEgivjBd.js} +2 -2
- package/dist/{holdEntranceInput-DWqsAYll.js → holdEntranceInput-CROBPhuO.js} +1 -1
- package/dist/{index-DXHmlFcC.d.ts → index--kbwaSXW.d.ts} +3 -3
- package/dist/{index-aHC2C89h.d.ts → index-1yvu_vpF.d.ts} +1 -1
- package/dist/{index-C9TEn6LQ.d.ts → index-B27k2e77.d.ts} +35 -35
- package/dist/{index-BB9acgK8.d.ts → index-BgT6mH3U.d.ts} +1 -1
- package/dist/{index-DoYrlaEI.d.ts → index-BufuCsTx.d.ts} +3 -3
- package/dist/{index-BDZCJ9ri.d.ts → index-BuubzuE8.d.ts} +2 -2
- package/dist/{index-mK1ICsVg.d.ts → index-C3JmGujU.d.ts} +1 -1
- package/dist/{index-CbA8rR_b.d.ts → index-CBOv5j3c.d.ts} +1 -1
- package/dist/{index-AgTJRqUY.d.ts → index-CQi9WGWE.d.ts} +2 -2
- package/dist/{index-C_iTVOHQ.d.ts → index-CilCxEvD.d.ts} +1 -1
- package/dist/{index-QC9FDUDA.d.ts → index-J83fLEyo.d.ts} +3 -3
- package/dist/{index-BA8exXNP.d.ts → index-X4S7_dmq.d.ts} +1 -1
- package/dist/{index-D8VViJw0.d.ts → index-sUMua5pp.d.ts} +47 -1
- package/dist/{index-BqAI9Sxh.d.ts → index-x7g2WHHx.d.ts} +2 -2
- package/dist/index.d.ts +16 -16
- package/dist/index.js +86 -86
- package/dist/inputAge-C-SoLwpD.js +42 -0
- package/dist/{inputHold-CvjeOOWT.js → inputHold-B53XZ8if.js} +2 -2
- package/dist/{inputHoldState-Cg1r8Ib7.js → inputHoldState-Bav14W7v.js} +1 -1
- package/dist/{inputStream-DkMWPYac.js → inputStream-DmPkJ1aU.js} +24 -1
- package/dist/{lazyBottomSheet-DlHcPsAT.js → lazyBottomSheet-DlrpPOl8.js} +1 -1
- package/dist/{resizableChannel-CaaqGvXj.js → resizableChannel-DpbFJbto.js} +1 -1
- package/dist/{scrollView-DcPpdCrj.js → scrollView-BGBtu5JP.js} +2 -42
- package/dist/selectionRanges-DB5jesLz.js +194 -0
- package/dist/{springs-DjAn_oV5.js → springs-CPk0tpwL.js} +1 -1
- package/dist/{types-DL-hRibg.d.ts → types-CTjJfVYK.d.ts} +11 -1
- package/dist/{useActionGroupTracking-DjIdPbfL.js → useActionGroupTracking-C-nLjHyn.js} +3 -2
- package/dist/{useChatStreamScroll-DEp17Yq9.js → useChatStreamScroll-DWhnCSP1.js} +1 -1
- package/dist/{useGestureRecognizer-DDd-6Km-.js → useGestureRecognizer-Di-YKr93.js} +1 -1
- package/dist/{useInputStatusIcon-m6l4qBmA.js → useInputStatusIcon-CXP2kRSe.js} +1 -1
- package/dist/{useMenuEntranceHold-C4LOzKIS.js → useMenuEntranceHold-DMHMzaRW.js} +1 -1
- package/dist/{useMenuPress-BDPqPten.js → useMenuPress-zOinmIFS.js} +3 -3
- package/dist/{usePressFeedback-D2mWzgoJ.js → usePressFeedback-CF4ISMfb.js} +3 -2
- package/dist/{useResizable-Bwv-j_9N.js → useResizable-7-uUaJ7x.js} +2 -2
- package/dist/{useTouchHitArea-DL9D10Rq.js → useTouchHitArea-CkHMLZ34.js} +1 -1
- package/package.json +1 -1
- package/styles/bottom-sheet.css +16 -0
- package/dist/BottomSheet-C6vet4pm.js +0 -1896
|
@@ -0,0 +1,4353 @@
|
|
|
1
|
+
import { c as isHTMLElement, l as isNode, n as deepActiveElement, o as isDocument, s as isElement, t as containsAlongFlatTree } from "./flatTree-BB4yPMNL.js";
|
|
2
|
+
import { t as SCROLLABLE_OVERFLOW } from "./scrollView-BGBtu5JP.js";
|
|
3
|
+
import { t as armClickGuard } from "./clickGuard-BkegH2NW.js";
|
|
4
|
+
import { a as sharedState, o as sharedWeakMap, s as sharedWeakSet } from "./sharedRealm-BYHklCVM.js";
|
|
5
|
+
import { a as subscribeInput, i as getTouches } from "./inputStream-DmPkJ1aU.js";
|
|
6
|
+
import { u as scroll } from "./gestures-yKyyMqeQ.js";
|
|
7
|
+
import { i as PRESS_SLOP_PX } from "./pressGesture-CfBgXWRM.js";
|
|
8
|
+
import { r as resetLayerScopedContext } from "./scopedProvide-C-Df7c15.js";
|
|
9
|
+
import { r as provideNestedLayerMountTarget } from "./mount-7R_s-bHB.js";
|
|
10
|
+
import { i as isTopLayer, n as useLayerDepth, o as pushLayer, t as provideLayerDepth } from "./layerDepth-DRfWATFr.js";
|
|
11
|
+
import { t as isImeKeyEvent } from "./ime-VY8-80S8.js";
|
|
12
|
+
import { t as useMediaQuery } from "./useMediaQuery-BzXGT1Aw.js";
|
|
13
|
+
import { n as defaultPrefersReducedMotion } from "./cssValues-Cr6PhYTx.js";
|
|
14
|
+
import { r as SETTLE_THRESHOLD, t as animatorFor } from "./animator-Bptiubcx.js";
|
|
15
|
+
import { t as cubicBezier } from "./bezier-Dko5MnTp.js";
|
|
16
|
+
import { n as resolveMoveTiming } from "./resolveMotion-DftkGFw6.js";
|
|
17
|
+
import { s as springs, t as KEYBOARD_SPRING } from "./springs-CPk0tpwL.js";
|
|
18
|
+
import { n as isIosWebKit, t as TOUCH_QUERY } from "./touchQueries-xy5IeZfe.js";
|
|
19
|
+
import { t as caretAt } from "./selectionRanges-DB5jesLz.js";
|
|
20
|
+
import { n as matchesMediaQuery, t as isCoarsePointer } from "./coarsePointer-BWNSUIY8.js";
|
|
21
|
+
import { t as VelocityTracker } from "./VelocityTracker-CPFBHDpy.js";
|
|
22
|
+
import { t as resolveSnapPoint } from "./resolveSnapPoint-A4dhS5jj.js";
|
|
23
|
+
import { t as useAttachment } from "./useAttachment-CGiD9rt6.js";
|
|
24
|
+
import { t as focusForLastInput } from "./focusReturn-DfZS7TCp.js";
|
|
25
|
+
import { t as useFocusTrap } from "./useFocusTrap-DcjriBe1.js";
|
|
26
|
+
import { t as rubberBand } from "./rubberBand-DDd5ElTe.js";
|
|
27
|
+
import { t as useRestoreFocus } from "./useRestoreFocus-DS7uQWok.js";
|
|
28
|
+
import { t as attachScrollKeyboardDelegation } from "./scrollKeyboardDelegation-DZ4t5PvC.js";
|
|
29
|
+
import { t as useScrollLock } from "./scrollLock-CoVg9lLU.js";
|
|
30
|
+
import { n as observeResize } from "./sharedResizeObserver-BekhnB3E.js";
|
|
31
|
+
import { n as restoreLayerFocus, r as trackLayerFocus, t as isLayerFocusStranded } from "./layerFocusReturn-CEvrMbxH.js";
|
|
32
|
+
import { t as createModalOutletHandle } from "./modalOutlet-Drr9a16b.js";
|
|
33
|
+
import { o as provideLayoutContainer } from "./context-D-Hwh-Jf.js";
|
|
34
|
+
import { t as useScrollbars } from "./useScrollbars-Ch0xqJWO.js";
|
|
35
|
+
import { n as reducedMotionFade } from "./reducedMotion-D8-U7XFT.js";
|
|
36
|
+
import { t as bottomSheetEscapeKey } from "./escape-DzSxSmez.js";
|
|
37
|
+
import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, getCurrentInstance, inject, mergeModels, mergeProps, nextTick, normalizeClass, normalizeStyle, onBeforeUnmount, onMounted, onScopeDispose, onUpdated, openBlock, provide, readonly, ref, renderSlot, shallowRef, toValue, unref, useAttrs, useModel, useTemplateRef, watch, withCtx } from "vue";
|
|
38
|
+
import "../styles/bottom-sheet.css";
|
|
39
|
+
//#region \0rolldown/runtime.js
|
|
40
|
+
var __defProp = Object.defineProperty;
|
|
41
|
+
var __exportAll = (all, no_symbols) => {
|
|
42
|
+
let target = {};
|
|
43
|
+
for (var name in all) __defProp(target, name, {
|
|
44
|
+
get: all[name],
|
|
45
|
+
enumerable: true
|
|
46
|
+
});
|
|
47
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
48
|
+
return target;
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region src/layer/inputHoldKeptInside.ts
|
|
52
|
+
/** 焦点留在退场浮层里时,还放行的键。 */
|
|
53
|
+
const KEPT_INSIDE_KEYS = /* @__PURE__ */ new Set(["Tab"]);
|
|
54
|
+
const WATCHED_ATTRIBUTES = [
|
|
55
|
+
"disabled",
|
|
56
|
+
"hidden",
|
|
57
|
+
"inert"
|
|
58
|
+
];
|
|
59
|
+
/**
|
|
60
|
+
* 退场期间挡住 `layer`,页面照常可用:浮层让所有指针穿过去,不加挡板。
|
|
61
|
+
* 焦点还在里面时,内容照样露给辅助技术,但除了 Tab 什么键、什么点击都到不了它;
|
|
62
|
+
* 焦点一离开(或者本来就不在里面),浮层自己变成 `inert` + `aria-hidden`,
|
|
63
|
+
* 直到暂挡结束。放开之后,排在放开前的焦点检查不再改动浮层。返回提前放开的函数。
|
|
64
|
+
*/
|
|
65
|
+
function holdKeptInside(layer, until) {
|
|
66
|
+
const doc = layer.ownerDocument;
|
|
67
|
+
const style = isHTMLElement(layer) ? layer.style : null;
|
|
68
|
+
const previousPointerEvents = style?.pointerEvents ?? "";
|
|
69
|
+
if (style != null) style.pointerEvents = "none";
|
|
70
|
+
const wasInert = layer.hasAttribute("inert");
|
|
71
|
+
const previousAriaHidden = layer.getAttribute("aria-hidden");
|
|
72
|
+
let isInert = false;
|
|
73
|
+
let isReleased = false;
|
|
74
|
+
const stops = [];
|
|
75
|
+
const hasFocusInside = () => {
|
|
76
|
+
const focused = deepActiveElement(doc);
|
|
77
|
+
return focused != null && containsAlongFlatTree(layer, focused);
|
|
78
|
+
};
|
|
79
|
+
const stopWatching = () => {
|
|
80
|
+
for (const stop of stops.splice(0)) stop();
|
|
81
|
+
};
|
|
82
|
+
const makeInert = () => {
|
|
83
|
+
if (isInert || isReleased) return;
|
|
84
|
+
isInert = true;
|
|
85
|
+
stopWatching();
|
|
86
|
+
layer.setAttribute("inert", "");
|
|
87
|
+
layer.setAttribute("aria-hidden", "true");
|
|
88
|
+
};
|
|
89
|
+
if (!hasFocusInside()) makeInert();
|
|
90
|
+
else {
|
|
91
|
+
const isInLayer = (event) => {
|
|
92
|
+
const target = typeof event.composedPath === "function" ? event.composedPath()[0] : event.target;
|
|
93
|
+
return isNode(target) && containsAlongFlatTree(layer, target);
|
|
94
|
+
};
|
|
95
|
+
const stopActivation = (event) => {
|
|
96
|
+
if (isInLayer(event)) {
|
|
97
|
+
event.preventDefault();
|
|
98
|
+
event.stopImmediatePropagation();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const stopKey = (event) => {
|
|
102
|
+
if (!KEPT_INSIDE_KEYS.has(event.key)) stopActivation(event);
|
|
103
|
+
};
|
|
104
|
+
const captures = [
|
|
105
|
+
["click", stopActivation],
|
|
106
|
+
["keydown", stopKey],
|
|
107
|
+
["keyup", stopKey]
|
|
108
|
+
];
|
|
109
|
+
for (const [type, listener] of captures) {
|
|
110
|
+
doc.addEventListener(type, listener, { capture: true });
|
|
111
|
+
stops.push(() => doc.removeEventListener(type, listener, { capture: true }));
|
|
112
|
+
}
|
|
113
|
+
const makeInertIfFocusLeft = () => {
|
|
114
|
+
if (!hasFocusInside()) makeInert();
|
|
115
|
+
};
|
|
116
|
+
const onFocusOut = () => queueMicrotask(makeInertIfFocusLeft);
|
|
117
|
+
layer.addEventListener("focusout", onFocusOut);
|
|
118
|
+
stops.push(() => layer.removeEventListener("focusout", onFocusOut));
|
|
119
|
+
if (typeof MutationObserver !== "undefined") {
|
|
120
|
+
const observer = new MutationObserver(makeInertIfFocusLeft);
|
|
121
|
+
observer.observe(layer, {
|
|
122
|
+
childList: true,
|
|
123
|
+
subtree: true,
|
|
124
|
+
attributeFilter: WATCHED_ATTRIBUTES
|
|
125
|
+
});
|
|
126
|
+
stops.push(() => observer.disconnect());
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
const release = () => {
|
|
130
|
+
if (isReleased) return;
|
|
131
|
+
isReleased = true;
|
|
132
|
+
stopWatching();
|
|
133
|
+
if (style != null) style.pointerEvents = previousPointerEvents;
|
|
134
|
+
if (isInert) {
|
|
135
|
+
if (!wasInert) layer.removeAttribute("inert");
|
|
136
|
+
if (previousAriaHidden == null) layer.removeAttribute("aria-hidden");
|
|
137
|
+
else layer.setAttribute("aria-hidden", previousAriaHidden);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
const end = "finished" in until ? until.finished : until;
|
|
141
|
+
Promise.resolve(end).then(release, release);
|
|
142
|
+
return release;
|
|
143
|
+
}
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/utils/layoutViewport.ts
|
|
146
|
+
/**
|
|
147
|
+
* @file layoutViewport.ts
|
|
148
|
+
* @input A window: its innerHeight and innerWidth, its visual viewport's
|
|
149
|
+
* width and scale, and its document's root box
|
|
150
|
+
* @output layoutViewportHeight, the layout viewport's height in layout px
|
|
151
|
+
* less a classic horizontal scrollbar, and __resetLayoutViewportForTest
|
|
152
|
+
* @position Internal shared measurement, not re-exported from the utils
|
|
153
|
+
* entry. The keyboard module, BottomSheet's keyboard obstruction and any
|
|
154
|
+
* layout that sizes against the layout viewport read it.
|
|
155
|
+
*/
|
|
156
|
+
/**
|
|
157
|
+
* The layout viewport's height, CSS px, in the units of element rects.
|
|
158
|
+
*
|
|
159
|
+
* `innerHeight` is the layout viewport's height in most engines. WebKit
|
|
160
|
+
* reports `innerHeight` and `innerWidth` in the pinch-zoomed visual
|
|
161
|
+
* viewport's px instead. At a 1.33 zoom of a 402 × 714 layout viewport,
|
|
162
|
+
* Safari on iOS 26.2 reports 536 and 302. Element rects and the visual
|
|
163
|
+
* viewport's height times its scale stay in layout px. So, read as is, a zoom
|
|
164
|
+
* shrinks the layout viewport by the zoom, and the function scales the height
|
|
165
|
+
* back.
|
|
166
|
+
*/
|
|
167
|
+
function layoutViewportHeight(win) {
|
|
168
|
+
const viewport = win.visualViewport;
|
|
169
|
+
const width = viewport?.width ?? 0;
|
|
170
|
+
if (viewport == null || !(width > 0)) return win.innerHeight - horizontalScrollbarHeight(win);
|
|
171
|
+
const scale = viewport.scale;
|
|
172
|
+
return (Math.abs(win.innerWidth - width) < Math.abs(win.innerWidth - width * scale) ? win.innerHeight * scale : win.innerHeight) - horizontalScrollbarHeight(win);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* The document's classic horizontal scrollbar, CSS px. It is in
|
|
176
|
+
* `innerHeight` but not in the visual viewport's height. On a desktop page
|
|
177
|
+
* wider than its window, Chromium's `innerHeight` is 800 for a 785 px visual
|
|
178
|
+
* viewport. It is the part of `innerHeight` the root's client height leaves
|
|
179
|
+
* out, up to the thickness of a scrollbar that takes room. Where scrollbars
|
|
180
|
+
* overlay the content, as on every phone, that thickness is 0. So the room a
|
|
181
|
+
* hidden toolbar adds to `innerHeight` is never taken for a scrollbar. Chrome
|
|
182
|
+
* on Android sizes the root to the viewport with its toolbar shown.
|
|
183
|
+
*/
|
|
184
|
+
function horizontalScrollbarHeight(win) {
|
|
185
|
+
const root = win.document.documentElement;
|
|
186
|
+
const gap = win.innerHeight - root.clientHeight;
|
|
187
|
+
if (!(gap > 0) || root.scrollWidth <= root.clientWidth) return 0;
|
|
188
|
+
return Math.min(gap, scrollbarThickness(win.document));
|
|
189
|
+
}
|
|
190
|
+
let thicknesses = /* @__PURE__ */ new WeakMap();
|
|
191
|
+
/** How much room a scrollbar takes from a scrolling box: 0 where overlaid. */
|
|
192
|
+
function scrollbarThickness(doc) {
|
|
193
|
+
const devicePixelRatio = doc.defaultView?.devicePixelRatio ?? 1;
|
|
194
|
+
const known = thicknesses.get(doc);
|
|
195
|
+
if (known != null && known.devicePixelRatio === devicePixelRatio) return known.thickness;
|
|
196
|
+
const thickness = measureScrollbarThickness(doc);
|
|
197
|
+
thicknesses.set(doc, {
|
|
198
|
+
devicePixelRatio,
|
|
199
|
+
thickness
|
|
200
|
+
});
|
|
201
|
+
return thickness;
|
|
202
|
+
}
|
|
203
|
+
function measureScrollbarThickness(doc) {
|
|
204
|
+
const probe = doc.createElement("div");
|
|
205
|
+
probe.style.position = "absolute";
|
|
206
|
+
probe.style.top = "-200px";
|
|
207
|
+
probe.style.width = "100px";
|
|
208
|
+
probe.style.height = "100px";
|
|
209
|
+
probe.style.overflow = "scroll";
|
|
210
|
+
probe.style.visibility = "hidden";
|
|
211
|
+
(doc.body ?? doc.documentElement).append(probe);
|
|
212
|
+
const thickness = probe.offsetHeight - probe.clientHeight;
|
|
213
|
+
probe.remove();
|
|
214
|
+
return thickness;
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/utils/scrollingAncestor.ts
|
|
218
|
+
/**
|
|
219
|
+
* @file scrollingAncestor.ts
|
|
220
|
+
* @input An element, and an optional ancestor where the walk stops.
|
|
221
|
+
* @output The element's nearest ancestor that scrolls on the block axis, and
|
|
222
|
+
* `nearestScroller`, which falls back to the document's scroller.
|
|
223
|
+
* @position Shared by the keyboard module's reveals, Outline's scroll spy
|
|
224
|
+
* and the List reorder's edge autoscroll.
|
|
225
|
+
*/
|
|
226
|
+
/**
|
|
227
|
+
* The nearest ancestor of `element` that scrolls on the block axis: its
|
|
228
|
+
* `overflow-y` lets it scroll and its content is taller than its box. The walk
|
|
229
|
+
* ends after `bound` when one is given, and at the document's root otherwise.
|
|
230
|
+
* Null when no ancestor in that range scrolls.
|
|
231
|
+
*/
|
|
232
|
+
function scrollingAncestor(element, bound) {
|
|
233
|
+
const view = element.ownerDocument.defaultView;
|
|
234
|
+
if (view == null) return null;
|
|
235
|
+
for (let node = element.parentElement; node != null; node = node.parentElement) {
|
|
236
|
+
if (SCROLLABLE_OVERFLOW.has(view.getComputedStyle(node).overflowY) && node.scrollHeight > node.clientHeight) return node;
|
|
237
|
+
if (node === bound) return null;
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* The element that scrolls `element` into view: its nearest ancestor that
|
|
243
|
+
* scrolls on the block axis, or else the document's scroller.
|
|
244
|
+
*/
|
|
245
|
+
function nearestScroller(element) {
|
|
246
|
+
const doc = element.ownerDocument;
|
|
247
|
+
const scroller = scrollingAncestor(element);
|
|
248
|
+
return scroller == null || scroller === doc.body || scroller === doc.documentElement ? doc.scrollingElement ?? doc.documentElement : scroller;
|
|
249
|
+
}
|
|
250
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
251
|
+
const HIDE_STEP_WAIT_MS = 300;
|
|
252
|
+
const HIDE_STEP_LIMIT_MS = 1e3;
|
|
253
|
+
const NON_TEXT_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
254
|
+
"button",
|
|
255
|
+
"checkbox",
|
|
256
|
+
"color",
|
|
257
|
+
"file",
|
|
258
|
+
"hidden",
|
|
259
|
+
"image",
|
|
260
|
+
"radio",
|
|
261
|
+
"range",
|
|
262
|
+
"reset",
|
|
263
|
+
"submit"
|
|
264
|
+
]);
|
|
265
|
+
/**
|
|
266
|
+
* Whether this window measures the keyboard: a top-level document with a
|
|
267
|
+
* visual viewport. Capabilities decide it, never the user agent or the
|
|
268
|
+
* pointer. The module measures a browser with its own keyboard geometry API,
|
|
269
|
+
* such as Chrome on Android with the VirtualKeyboard API, the same way.
|
|
270
|
+
* Its visual viewport shrinks for the keyboard while the layout viewport keeps
|
|
271
|
+
* its height, as everywhere else. A desktop browser's visual viewport never
|
|
272
|
+
* shrinks for a keyboard, so it reads 0. Where the app sets
|
|
273
|
+
* `interactive-widget=resizes-content`, Chrome shrinks the layout viewport
|
|
274
|
+
* with the keyboard. The height is then 0 too, and nothing rides, because the
|
|
275
|
+
* browser has made the room itself.
|
|
276
|
+
*/
|
|
277
|
+
function isKeyboardMeasurable(win) {
|
|
278
|
+
return win.visualViewport != null && win.self === win.top;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The on-screen keyboard's height over the layout viewport, CSS px. It is 0
|
|
282
|
+
* when none is shown, also while pinch-zoomed, and wherever
|
|
283
|
+
* `isKeyboardMeasurable` is false.
|
|
284
|
+
*/
|
|
285
|
+
function measureKeyboardHeight(win) {
|
|
286
|
+
const viewport = win.visualViewport;
|
|
287
|
+
if (viewport == null || !isKeyboardMeasurable(win)) return 0;
|
|
288
|
+
const height = layoutViewportHeight(win) - viewport.height * (viewport.scale ?? 1);
|
|
289
|
+
return height > 1 ? Math.round(height * 100) / 100 : 0;
|
|
290
|
+
}
|
|
291
|
+
const stores = sharedWeakMap("keyboard/keyboard-height/stores", 2);
|
|
292
|
+
function storeOf(win) {
|
|
293
|
+
let store = stores.get(win);
|
|
294
|
+
if (store == null) {
|
|
295
|
+
store = {
|
|
296
|
+
height: 0,
|
|
297
|
+
startsAtHide: null,
|
|
298
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
299
|
+
focusListeners: /* @__PURE__ */ new Set(),
|
|
300
|
+
detach: null,
|
|
301
|
+
detachFocus: null
|
|
302
|
+
};
|
|
303
|
+
stores.set(win, store);
|
|
304
|
+
}
|
|
305
|
+
return store;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Whether `win` has the VirtualKeyboard API, as Chrome on Android does. The
|
|
309
|
+
* keyboard layout guide reads Chrome's profile there (keyboardProfileOf).
|
|
310
|
+
*/
|
|
311
|
+
function hasVirtualKeyboard(win) {
|
|
312
|
+
return "virtualKeyboard" in win.navigator;
|
|
313
|
+
}
|
|
314
|
+
function isHideStep(win, shown, height) {
|
|
315
|
+
return height > 1 && height < shown - 1 && hasVirtualKeyboard(win) && matchesMediaQuery(win, REDUCED_MOTION_QUERY);
|
|
316
|
+
}
|
|
317
|
+
function attach(win, store) {
|
|
318
|
+
const viewport = win.visualViewport;
|
|
319
|
+
store.height = measureKeyboardHeight(win);
|
|
320
|
+
let stepTimer = null;
|
|
321
|
+
let stepHeight = 0;
|
|
322
|
+
let stepLimit = 0;
|
|
323
|
+
const deliver = (height, timeStamp) => {
|
|
324
|
+
if (height <= 1 && store.height > 1) store.startsAtHide = getTouches(win).starts;
|
|
325
|
+
store.height = height;
|
|
326
|
+
const report = {
|
|
327
|
+
type: "viewport",
|
|
328
|
+
height,
|
|
329
|
+
timeStamp
|
|
330
|
+
};
|
|
331
|
+
for (const listener of [...store.listeners]) listener(report);
|
|
332
|
+
};
|
|
333
|
+
const onViewport = (event) => {
|
|
334
|
+
const height = measureKeyboardHeight(win);
|
|
335
|
+
if (isHideStep(win, store.height, height)) {
|
|
336
|
+
if (stepTimer != null && Math.abs(height - stepHeight) < 1) return;
|
|
337
|
+
const now = win.performance.now();
|
|
338
|
+
if (stepTimer == null) stepLimit = now + HIDE_STEP_LIMIT_MS;
|
|
339
|
+
else clearTimeout(stepTimer);
|
|
340
|
+
stepHeight = height;
|
|
341
|
+
stepTimer = setTimeout(() => {
|
|
342
|
+
stepTimer = null;
|
|
343
|
+
deliver(measureKeyboardHeight(win), win.performance.now());
|
|
344
|
+
}, Math.min(HIDE_STEP_WAIT_MS, stepLimit - now));
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
if (stepTimer != null) {
|
|
348
|
+
clearTimeout(stepTimer);
|
|
349
|
+
stepTimer = null;
|
|
350
|
+
}
|
|
351
|
+
deliver(height, event.timeStamp);
|
|
352
|
+
};
|
|
353
|
+
viewport?.addEventListener("resize", onViewport);
|
|
354
|
+
viewport?.addEventListener("scroll", onViewport);
|
|
355
|
+
const stopResize = subscribeInput(win, "resize", (event) => {
|
|
356
|
+
if (!isNode(event.target)) onViewport(event);
|
|
357
|
+
});
|
|
358
|
+
return () => {
|
|
359
|
+
if (stepTimer != null) {
|
|
360
|
+
clearTimeout(stepTimer);
|
|
361
|
+
stepTimer = null;
|
|
362
|
+
}
|
|
363
|
+
viewport?.removeEventListener("resize", onViewport);
|
|
364
|
+
viewport?.removeEventListener("scroll", onViewport);
|
|
365
|
+
stopResize();
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
function attachFocus(win, store) {
|
|
369
|
+
const onFocus = (event) => {
|
|
370
|
+
const report = {
|
|
371
|
+
type: event.type === "focusin" ? "focusin" : "focusout",
|
|
372
|
+
height: store.height,
|
|
373
|
+
timeStamp: event.timeStamp,
|
|
374
|
+
target: event.target,
|
|
375
|
+
relatedTarget: event.relatedTarget
|
|
376
|
+
};
|
|
377
|
+
for (const listener of [...store.focusListeners]) listener(report);
|
|
378
|
+
};
|
|
379
|
+
const stopFocusIn = subscribeInput(win, "focusin", onFocus);
|
|
380
|
+
const stopFocusOut = subscribeInput(win, "focusout", onFocus);
|
|
381
|
+
return () => {
|
|
382
|
+
stopFocusIn();
|
|
383
|
+
stopFocusOut();
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Calls `listener` with every report of `win`'s keyboard until the caller
|
|
388
|
+
* runs the returned function. It reports the viewport's changes, and focus
|
|
389
|
+
* moves too when the caller sets `focus`. All subscribers of a window share
|
|
390
|
+
* one set of listeners, and its focus listeners exist only while a subscriber
|
|
391
|
+
* asks for focus moves.
|
|
392
|
+
*
|
|
393
|
+
* @example
|
|
394
|
+
* ```
|
|
395
|
+
* const stop = subscribeKeyboardHeight(window, event => {
|
|
396
|
+
* if (event.type === 'viewport') layout(event.height);
|
|
397
|
+
* });
|
|
398
|
+
* ```
|
|
399
|
+
*/
|
|
400
|
+
function subscribeKeyboardHeight(win, listener, { focus = false } = {}) {
|
|
401
|
+
const store = storeOf(win);
|
|
402
|
+
store.listeners.add(listener);
|
|
403
|
+
store.detach ??= attach(win, store);
|
|
404
|
+
if (focus) {
|
|
405
|
+
store.focusListeners.add(listener);
|
|
406
|
+
store.detachFocus ??= attachFocus(win, store);
|
|
407
|
+
}
|
|
408
|
+
return () => {
|
|
409
|
+
store.listeners.delete(listener);
|
|
410
|
+
if (focus) {
|
|
411
|
+
store.focusListeners.delete(listener);
|
|
412
|
+
if (store.focusListeners.size === 0 && store.detachFocus != null) {
|
|
413
|
+
store.detachFocus();
|
|
414
|
+
store.detachFocus = null;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (store.listeners.size === 0 && store.detach != null) {
|
|
418
|
+
store.detach();
|
|
419
|
+
store.detach = null;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Whether a finger is on `win`'s screen, from the input stream's count. A
|
|
425
|
+
* finger that was down at the keyboard's last hide counts no more until a
|
|
426
|
+
* touch starts. A touch whose target leaves the page ends at a node the
|
|
427
|
+
* window never hears.
|
|
428
|
+
*/
|
|
429
|
+
function isFingerOnScreen(win) {
|
|
430
|
+
const startsAtHide = stores.get(win)?.startsAtHide;
|
|
431
|
+
const touches = getTouches(win);
|
|
432
|
+
return touches.fingers > 0 && (startsAtHide == null || touches.starts !== startsAtHide);
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* `win`'s keyboard height. While the module listens, it is the height
|
|
436
|
+
* measured at the last report. Every reader of a keyboard change, such as
|
|
437
|
+
* each component's hook, shares that one layout read. Every change of the
|
|
438
|
+
* visual viewport or the window is a report, so a reader between two reports
|
|
439
|
+
* sees the current height. With nothing listening yet, the call measures the
|
|
440
|
+
* height now.
|
|
441
|
+
*/
|
|
442
|
+
function getKeyboardHeight(win) {
|
|
443
|
+
const store = stores.get(win);
|
|
444
|
+
return store?.detach != null ? store.height : measureKeyboardHeight(win);
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Whether focusing `element` brings up a keyboard for typing text. A control
|
|
448
|
+
* with `inputmode="none"` brings up none.
|
|
449
|
+
*/
|
|
450
|
+
function isTextEntryControl(element) {
|
|
451
|
+
if (!isHTMLElement(element) || element.getAttribute("inputmode") === "none") return false;
|
|
452
|
+
if (element.localName === "textarea") {
|
|
453
|
+
const textArea = element;
|
|
454
|
+
return !textArea.disabled && !textArea.readOnly;
|
|
455
|
+
}
|
|
456
|
+
if (element.localName === "input") {
|
|
457
|
+
const input = element;
|
|
458
|
+
return !input.disabled && !input.readOnly && !NON_TEXT_INPUT_TYPES.has((input.getAttribute("type") ?? "text").toLowerCase());
|
|
459
|
+
}
|
|
460
|
+
return element.matches("[contenteditable]:not([contenteditable=\"false\"])");
|
|
461
|
+
}
|
|
462
|
+
/** The text-entry control inside `container` that `target` is or labels. */
|
|
463
|
+
function findTextEntryControl(target, container) {
|
|
464
|
+
if (!isElement(target)) return null;
|
|
465
|
+
const direct = target.closest("input, textarea, [contenteditable]:not([contenteditable=\"false\"])");
|
|
466
|
+
if (container.contains(direct) && isTextEntryControl(direct)) return direct;
|
|
467
|
+
const label = target.closest("label");
|
|
468
|
+
const control = isHTMLElement(label) ? label.control : null;
|
|
469
|
+
return container.contains(control) && isTextEntryControl(control) ? control : null;
|
|
470
|
+
}
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/keyboard/keyboardGeometry.ts
|
|
473
|
+
const targets = sharedWeakSet("keyboard/keyboard-target/targets", 1);
|
|
474
|
+
/** Registers `element` as a keyboard target until the returned call. */
|
|
475
|
+
function registerKeyboardTarget(element) {
|
|
476
|
+
targets.add(element);
|
|
477
|
+
return () => {
|
|
478
|
+
targets.delete(element);
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
/** Whether a registered target holds `element`. */
|
|
482
|
+
function isInsideKeyboardTarget(element) {
|
|
483
|
+
for (let node = element.parentElement; node != null; node = node.parentElement) if (targets.has(node)) return true;
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
function restingBottom(element, animator) {
|
|
487
|
+
return element.getBoundingClientRect().bottom - animator.get("y");
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* How far a ride has moved `element` from where its layout puts it, as the
|
|
491
|
+
* page draws it now, CSS px. Reading the style creates no animator.
|
|
492
|
+
*/
|
|
493
|
+
function drawnOffsetOf(element) {
|
|
494
|
+
const translate = element.ownerDocument.defaultView?.getComputedStyle(element).translate ?? "";
|
|
495
|
+
return Number.parseFloat(translate.split(" ")[1] ?? "") || 0;
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* How the nearest fixed-position ancestor of `element` meets the keyboard. It
|
|
499
|
+
* is docked when its layout puts its bottom at the layout viewport's bottom
|
|
500
|
+
* edge. It can also fill the viewport, as a dialog does, or float above the
|
|
501
|
+
* bottom edge. Null with no fixed ancestor, as in page content.
|
|
502
|
+
*/
|
|
503
|
+
function fixedContainerOf(element) {
|
|
504
|
+
const view = element.ownerDocument.defaultView;
|
|
505
|
+
const node = nearestFixedAncestor(element);
|
|
506
|
+
if (view == null || node == null) return null;
|
|
507
|
+
const dock = dockOf(node, view);
|
|
508
|
+
return dock === "docked" ? { docked: node } : dock;
|
|
509
|
+
}
|
|
510
|
+
function nearestFixedAncestor(element) {
|
|
511
|
+
const view = element.ownerDocument.defaultView;
|
|
512
|
+
if (view == null) return null;
|
|
513
|
+
for (let node = element.parentElement; node != null; node = node.parentElement) if (view.getComputedStyle(node).position === "fixed") return node;
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
function transformOffsetOf(element, view) {
|
|
517
|
+
const transform = view.getComputedStyle(element).transform;
|
|
518
|
+
const matrix = /^matrix(3d)?\(([^)]*)\)$/.exec(transform);
|
|
519
|
+
if (matrix == null) return 0;
|
|
520
|
+
const values = (matrix[2] ?? "").split(",").map(Number);
|
|
521
|
+
const y = matrix[1] == null ? values[5] : values[13];
|
|
522
|
+
return y != null && Number.isFinite(y) ? y : 0;
|
|
523
|
+
}
|
|
524
|
+
function dockOf(node, view) {
|
|
525
|
+
const viewportBottom = layoutViewportHeight(view);
|
|
526
|
+
const box = node.getBoundingClientRect();
|
|
527
|
+
if (box.height >= viewportBottom - 1) return "fills-viewport";
|
|
528
|
+
const bottom = box.bottom - drawnOffsetOf(node) - transformOffsetOf(node, view);
|
|
529
|
+
return Math.abs(viewportBottom - bottom) <= 1 ? "docked" : "floating";
|
|
530
|
+
}
|
|
531
|
+
const riddenAnimators = sharedWeakMap("keyboard/keyboard-target/ridden-animators", 1);
|
|
532
|
+
function hasOwnTranslate(node, view) {
|
|
533
|
+
const translate = view.getComputedStyle(node).translate;
|
|
534
|
+
if (translate === "" || translate === "none") return false;
|
|
535
|
+
const ride = riddenAnimators.get(node);
|
|
536
|
+
return ride == null || ride.get("y") === 0;
|
|
537
|
+
}
|
|
538
|
+
const POSITION_PROPERTIES = /* @__PURE__ */ new Set([
|
|
539
|
+
"transform",
|
|
540
|
+
"translate",
|
|
541
|
+
"top",
|
|
542
|
+
"bottom",
|
|
543
|
+
"inset",
|
|
544
|
+
"inset-block",
|
|
545
|
+
"inset-block-start",
|
|
546
|
+
"inset-block-end"
|
|
547
|
+
]);
|
|
548
|
+
const KEYFRAME_FIELDS = /* @__PURE__ */ new Set([
|
|
549
|
+
"offset",
|
|
550
|
+
"computedOffset",
|
|
551
|
+
"easing",
|
|
552
|
+
"composite"
|
|
553
|
+
]);
|
|
554
|
+
function animatedProperties(animation) {
|
|
555
|
+
if ("transitionProperty" in animation) return [String(animation.transitionProperty)];
|
|
556
|
+
const effect = animation.effect;
|
|
557
|
+
if (effect == null || !("getKeyframes" in effect)) return [];
|
|
558
|
+
const names = /* @__PURE__ */ new Set();
|
|
559
|
+
for (const frame of effect.getKeyframes()) for (const key of Object.keys(frame)) if (!KEYFRAME_FIELDS.has(key)) names.add(key.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`));
|
|
560
|
+
return [...names];
|
|
561
|
+
}
|
|
562
|
+
function isMovedByApp(node) {
|
|
563
|
+
if (typeof node.getAnimations !== "function") return false;
|
|
564
|
+
const isRidden = riddenAnimators.has(node);
|
|
565
|
+
return node.getAnimations().some((animation) => {
|
|
566
|
+
if (animation.playState !== "running") return false;
|
|
567
|
+
const isTransition = "transitionProperty" in animation;
|
|
568
|
+
if (!isTransition && !("animationName" in animation)) return false;
|
|
569
|
+
const properties = animatedProperties(animation);
|
|
570
|
+
if (isRidden && isTransition && properties.every((property) => property === "translate")) return false;
|
|
571
|
+
return properties.some((property) => POSITION_PROPERTIES.has(property));
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
function isDockedContainer(node) {
|
|
575
|
+
const view = node.ownerDocument.defaultView;
|
|
576
|
+
return view != null && view.getComputedStyle(node).position === "fixed" && dockOf(node, view) === "docked";
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* How far a bottom edge at `bottom` sits under the keyboard's top, plus
|
|
580
|
+
* `offset`, CSS px; 0 when it clears it. An overlap under one CSS px is the
|
|
581
|
+
* viewport's rounding, not an obstruction.
|
|
582
|
+
*/
|
|
583
|
+
function coveredBy(bottom, height, offset, win) {
|
|
584
|
+
const covered = bottom + offset - (layoutViewportHeight(win) - height);
|
|
585
|
+
return height > 0 && covered > 1 ? covered : 0;
|
|
586
|
+
}
|
|
587
|
+
function focusedFieldIn(target) {
|
|
588
|
+
const active = target.ownerDocument.activeElement;
|
|
589
|
+
return active != null && active !== target && target.contains(active) && isTextEntryControl(active) ? active : null;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Whether `win` keeps fields above a keyboard at all: a top-level document
|
|
593
|
+
* whose visual viewport shrinks for the keyboard, under a coarse primary
|
|
594
|
+
* pointer.
|
|
595
|
+
*/
|
|
596
|
+
function followsKeyboard(win) {
|
|
597
|
+
return win != null && isKeyboardMeasurable(win) && isCoarsePointer(win);
|
|
598
|
+
}
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region src/keyboard/focusReveal.ts
|
|
601
|
+
/**
|
|
602
|
+
* @file focusReveal.ts
|
|
603
|
+
* @input A document's capture-phase `blur`, through the input stream
|
|
604
|
+
* @output refuseFocusReveal, which delivers the focus moves a surface claims
|
|
605
|
+
* with `preventScroll`, and its test-only caller count
|
|
606
|
+
* @position Keyboard module, internal to core. Every caller in a document
|
|
607
|
+
* shares one listener.
|
|
608
|
+
*/
|
|
609
|
+
const focusTakeovers = sharedWeakMap("keyboard/keyboard-height/focus-takeovers", 1);
|
|
610
|
+
/**
|
|
611
|
+
* Delivers the focus moves `claim` accepts with `preventScroll`, so the
|
|
612
|
+
* browser never reveals their destination itself. It stops when the caller
|
|
613
|
+
* runs the returned function.
|
|
614
|
+
*
|
|
615
|
+
* The browser dispatches `blur` in the capture phase ahead of its own focus
|
|
616
|
+
* step, and `blur` names the destination in `relatedTarget`. Focusing it there
|
|
617
|
+
* with preventScroll settles the change. The browser's step then finds the
|
|
618
|
+
* element already active, so it dispatches nothing further and reveals
|
|
619
|
+
* nothing.
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```
|
|
623
|
+
* const stop = refuseFocusReveal(document, {
|
|
624
|
+
* claim: target => findTextEntryControl(target, body),
|
|
625
|
+
* park: () => sheet.focus({preventScroll: true}),
|
|
626
|
+
* });
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
function refuseFocusReveal(doc, { isActive, claim, park }) {
|
|
630
|
+
const onBlur = (event) => {
|
|
631
|
+
if (isActive != null && !isActive()) return;
|
|
632
|
+
const destination = claim(event.relatedTarget);
|
|
633
|
+
if (destination != null) {
|
|
634
|
+
if (destination !== doc.activeElement) destination.focus({ preventScroll: true });
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
637
|
+
if (event.relatedTarget == null) park?.(event.target);
|
|
638
|
+
};
|
|
639
|
+
let shared = focusTakeovers.get(doc);
|
|
640
|
+
if (shared == null) {
|
|
641
|
+
const view = doc.defaultView;
|
|
642
|
+
if (view == null) return () => {};
|
|
643
|
+
const callers = /* @__PURE__ */ new Set();
|
|
644
|
+
const listener = (event) => {
|
|
645
|
+
for (const caller of [...callers]) if (callers.has(caller)) caller(event);
|
|
646
|
+
};
|
|
647
|
+
shared = {
|
|
648
|
+
stop: subscribeInput(view, "blur", (event) => {
|
|
649
|
+
if (isNode(event.target)) listener(event);
|
|
650
|
+
}),
|
|
651
|
+
callers
|
|
652
|
+
};
|
|
653
|
+
focusTakeovers.set(doc, shared);
|
|
654
|
+
}
|
|
655
|
+
shared.callers.add(onBlur);
|
|
656
|
+
return () => {
|
|
657
|
+
const current = focusTakeovers.get(doc);
|
|
658
|
+
if (current == null || !current.callers.delete(onBlur)) return;
|
|
659
|
+
if (current.callers.size === 0) {
|
|
660
|
+
current.stop();
|
|
661
|
+
focusTakeovers.delete(doc);
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
//#endregion
|
|
666
|
+
//#region src/motion/android/keyboard.ts
|
|
667
|
+
/**
|
|
668
|
+
* @file keyboard.ts
|
|
669
|
+
* @input None
|
|
670
|
+
* @output `keyboard`: how the software keyboard moves on Android, in Chrome
|
|
671
|
+
* with Gboard, as the page sees it. It holds the slides' durations and
|
|
672
|
+
* curves, and when they start against Chrome's report and a blur.
|
|
673
|
+
* @position The keyboard domain of the Android constants table, read by
|
|
674
|
+
* keyboard/keyboardModel.ts. The UIKit table holds iOS's keyboard.
|
|
675
|
+
*/
|
|
676
|
+
const keyboard = {
|
|
677
|
+
/**
|
|
678
|
+
* How long Gboard takes to slide up, in ms: from its first moved frame to
|
|
679
|
+
* its resting top.
|
|
680
|
+
*
|
|
681
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
682
|
+
* emulator); 20 shows recorded frame by frame: 250 to 282 ms, 18 of
|
|
683
|
+
* them 264 to 268 ms, Oct 25 2026
|
|
684
|
+
*/
|
|
685
|
+
showMs: 267,
|
|
686
|
+
/**
|
|
687
|
+
* The curve of Gboard's slide up, cubic-bézier control points: fast out,
|
|
688
|
+
* a long settle.
|
|
689
|
+
*
|
|
690
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
691
|
+
* emulator); the same 20 shows fit this curve over `showMs` within
|
|
692
|
+
* 2.4 px rms, Oct 25 2026
|
|
693
|
+
*/
|
|
694
|
+
showCurve: [
|
|
695
|
+
.1,
|
|
696
|
+
0,
|
|
697
|
+
0,
|
|
698
|
+
1
|
|
699
|
+
],
|
|
700
|
+
/**
|
|
701
|
+
* How long after Gboard starts to slide up Chrome's report of it fires, in
|
|
702
|
+
* ms. A show rides from the report dated back by this, joining the slide
|
|
703
|
+
* where it is.
|
|
704
|
+
*
|
|
705
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
706
|
+
* emulator); twelve shows: the first frame the page painted after the
|
|
707
|
+
* visual viewport's resize came 14 to 35 ms (median 33) after Gboard's
|
|
708
|
+
* first moved frame, less the 8 ms an event takes on average to reach
|
|
709
|
+
* the screen, Oct 25 2026
|
|
710
|
+
*/
|
|
711
|
+
showReportLagMs: 25,
|
|
712
|
+
/**
|
|
713
|
+
* How long Gboard takes to slide down out of the page, in ms.
|
|
714
|
+
*
|
|
715
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
716
|
+
* emulator); 21 hides recorded frame by frame, from Gboard's first
|
|
717
|
+
* moved frame until it leaves the screen: 148 to 153 ms in 20 of them;
|
|
718
|
+
* this length with `hideCurve` fits them within 7.7 px rms,
|
|
719
|
+
* Oct 25 2026
|
|
720
|
+
*/
|
|
721
|
+
hideMs: 167,
|
|
722
|
+
/**
|
|
723
|
+
* The curve of Gboard's slide down, cubic-bézier control points: a slow
|
|
724
|
+
* first frame, then fast.
|
|
725
|
+
*
|
|
726
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
727
|
+
* emulator); the same 21 hides, a free fit over `hideMs`, Oct 25 2026
|
|
728
|
+
*/
|
|
729
|
+
hideCurve: [
|
|
730
|
+
.3,
|
|
731
|
+
.1,
|
|
732
|
+
.2,
|
|
733
|
+
.9
|
|
734
|
+
],
|
|
735
|
+
/**
|
|
736
|
+
* How long after the focused field blurs (to nothing that brings up a
|
|
737
|
+
* keyboard) Gboard starts to slide down, in ms.
|
|
738
|
+
*
|
|
739
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
740
|
+
* emulator); five scripted blurs with a marker the page paints on the
|
|
741
|
+
* blur: Gboard's first moved frame came from a frame before the marker
|
|
742
|
+
* to 33 ms after it (median 16), Oct 25 2026
|
|
743
|
+
*/
|
|
744
|
+
hideAfterBlurMs: 16,
|
|
745
|
+
/**
|
|
746
|
+
* How long after Gboard starts to slide down Chrome's report of the hide
|
|
747
|
+
* fires, in ms, measured on blurs. A hide nothing predicts, such as Back,
|
|
748
|
+
* reuses it, though Chrome can report Back later in the slide.
|
|
749
|
+
*
|
|
750
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
751
|
+
* emulator); twelve scripted blurs: the visual viewport's resize came
|
|
752
|
+
* 42 to 52 ms after the blur (median 49), less `hideAfterBlurMs`,
|
|
753
|
+
* Oct 25 2026
|
|
754
|
+
*/
|
|
755
|
+
hideReportLagMs: 33
|
|
756
|
+
};
|
|
757
|
+
//#endregion
|
|
758
|
+
//#region src/keyboard/keyboardModel.ts
|
|
759
|
+
/**
|
|
760
|
+
* @file keyboardModel.ts
|
|
761
|
+
* @input `keyboard` from the Android table: Gboard's slides and Chrome's
|
|
762
|
+
* report timings
|
|
763
|
+
* @output createKeyboardModel, the keyboard layout guide's clock-free core,
|
|
764
|
+
* and the KeyboardTransition and KeyboardModel types
|
|
765
|
+
* @position The state of the keyboard layout guide (keyboardLayoutGuide.ts).
|
|
766
|
+
* It infers the keyboard's transition from the visual viewport's reports
|
|
767
|
+
* and focus changes, each input with its own time. It is internal to core.
|
|
768
|
+
*/
|
|
769
|
+
const EPSILON = .5;
|
|
770
|
+
/**
|
|
771
|
+
* Creates the guide's core. Tests drive it with explicit times, and the
|
|
772
|
+
* window's guide feeds it events.
|
|
773
|
+
*
|
|
774
|
+
* Chrome reports each keyboard slide through the visual viewport just after
|
|
775
|
+
* it starts. Content rides Gboard's own
|
|
776
|
+
* slides, fitted on Chromium 158 with Gboard (motion/android/keyboard.ts).
|
|
777
|
+
*
|
|
778
|
+
* - Show: from the report, dated back `androidKeyboard.showReportLagMs`, on
|
|
779
|
+
* `showCurve` over `showMs`, joining the slide where it is. The report's
|
|
780
|
+
* first painted frame trails Gboard's first moved frame by 14 to 35 ms. An
|
|
781
|
+
* `<input>` that brings an accessory bar first gives a smaller report
|
|
782
|
+
* before the keyboard's. It rides to the last keyboard's height instead, as
|
|
783
|
+
* a prediction, and the keyboard's report confirms it.
|
|
784
|
+
* - Hide: on `hideCurve` over `hideMs`. It starts
|
|
785
|
+
* `androidKeyboard.hideAfterBlurMs` after a blur that brings no keyboard,
|
|
786
|
+
* as a prediction, because Gboard starts down at the blur. When nothing
|
|
787
|
+
* predicted it, as with Back, it starts from Chrome's report, dated back
|
|
788
|
+
* `hideReportLagMs`, the lag measured on blurs.
|
|
789
|
+
* - A keyboard that changes while up, such as another keyboard, lays out at
|
|
790
|
+
* once.
|
|
791
|
+
*
|
|
792
|
+
* A prediction the viewport has not confirmed by its end gives way to what
|
|
793
|
+
* the viewport says (`verify`).
|
|
794
|
+
*/
|
|
795
|
+
function createKeyboardModel(initialInset = 0) {
|
|
796
|
+
let transition = {
|
|
797
|
+
kind: "change",
|
|
798
|
+
from: initialInset,
|
|
799
|
+
to: initialInset,
|
|
800
|
+
start: -Infinity,
|
|
801
|
+
velocity: 0,
|
|
802
|
+
animated: false,
|
|
803
|
+
predicted: false,
|
|
804
|
+
curve: null
|
|
805
|
+
};
|
|
806
|
+
let curve = null;
|
|
807
|
+
const easedCurve = (from, to, slide) => {
|
|
808
|
+
const span = slide.durationMs / 1e3;
|
|
809
|
+
const ease = cubicBezier(slide.points);
|
|
810
|
+
const value = (t) => from + (to - from) * ease(Math.min(1, Math.max(0, t / span)));
|
|
811
|
+
return {
|
|
812
|
+
value,
|
|
813
|
+
velocity: (t) => {
|
|
814
|
+
if (t >= span) return 0;
|
|
815
|
+
const a = Math.max(0, t - .001);
|
|
816
|
+
const b = Math.min(span, t + .001);
|
|
817
|
+
return (value(b) - value(a)) / (b - a);
|
|
818
|
+
}
|
|
819
|
+
};
|
|
820
|
+
};
|
|
821
|
+
const showSlide = {
|
|
822
|
+
durationMs: keyboard.showMs,
|
|
823
|
+
points: keyboard.showCurve
|
|
824
|
+
};
|
|
825
|
+
const hideSlide = {
|
|
826
|
+
durationMs: keyboard.hideMs,
|
|
827
|
+
points: keyboard.hideCurve
|
|
828
|
+
};
|
|
829
|
+
const lengthOf = () => transition.curve != null ? transition.curve.durationMs : 0;
|
|
830
|
+
let shownInset = initialInset;
|
|
831
|
+
const presentation = (time) => {
|
|
832
|
+
if (time < transition.start) return transition.from;
|
|
833
|
+
if (curve == null || time >= transition.start + lengthOf()) return transition.to;
|
|
834
|
+
return curve.value((time - transition.start) / 1e3);
|
|
835
|
+
};
|
|
836
|
+
const velocity = (time) => {
|
|
837
|
+
if (time <= transition.start) return transition.velocity;
|
|
838
|
+
if (curve == null || time >= transition.start + lengthOf()) return 0;
|
|
839
|
+
return curve.velocity((time - transition.start) / 1e3);
|
|
840
|
+
};
|
|
841
|
+
const begin = (kind, to, start, { animated = true, predicted = false } = {}) => {
|
|
842
|
+
const at = Math.max(start, transition.start);
|
|
843
|
+
const from = presentation(at);
|
|
844
|
+
const v = animated ? velocity(at) : 0;
|
|
845
|
+
const slide = animated ? to > from ? showSlide : hideSlide : null;
|
|
846
|
+
transition = {
|
|
847
|
+
kind,
|
|
848
|
+
from,
|
|
849
|
+
to,
|
|
850
|
+
start: at,
|
|
851
|
+
velocity: v,
|
|
852
|
+
animated,
|
|
853
|
+
predicted,
|
|
854
|
+
curve: slide
|
|
855
|
+
};
|
|
856
|
+
curve = slide != null && Math.abs(to - from) + Math.abs(v) > 0 ? easedCurve(from, to, slide) : null;
|
|
857
|
+
if (to > EPSILON) shownInset = to;
|
|
858
|
+
return transition;
|
|
859
|
+
};
|
|
860
|
+
const confirm = () => {
|
|
861
|
+
if (transition.predicted) transition = {
|
|
862
|
+
...transition,
|
|
863
|
+
predicted: false
|
|
864
|
+
};
|
|
865
|
+
return null;
|
|
866
|
+
};
|
|
867
|
+
return {
|
|
868
|
+
get inset() {
|
|
869
|
+
return transition.to;
|
|
870
|
+
},
|
|
871
|
+
get transition() {
|
|
872
|
+
return transition;
|
|
873
|
+
},
|
|
874
|
+
presentation,
|
|
875
|
+
velocity,
|
|
876
|
+
report(inset, time) {
|
|
877
|
+
if (inset == null) return null;
|
|
878
|
+
const target = transition.to;
|
|
879
|
+
if (Math.abs(inset - target) < EPSILON) return confirm();
|
|
880
|
+
if (inset <= EPSILON) return begin("hide", 0, time - keyboard.hideReportLagMs);
|
|
881
|
+
if (target <= EPSILON) {
|
|
882
|
+
const predicted = shownInset > inset + EPSILON;
|
|
883
|
+
return begin("show", predicted ? shownInset : inset, time - keyboard.showReportLagMs, { predicted });
|
|
884
|
+
}
|
|
885
|
+
return begin("change", inset, time, { animated: false });
|
|
886
|
+
},
|
|
887
|
+
blurred(time) {
|
|
888
|
+
if (transition.to <= EPSILON) return null;
|
|
889
|
+
return begin("hide", 0, time + keyboard.hideAfterBlurMs, { predicted: true });
|
|
890
|
+
},
|
|
891
|
+
focused(time) {
|
|
892
|
+
if (transition.kind !== "hide" || !transition.predicted) return null;
|
|
893
|
+
return begin("show", shownInset, Math.max(time, transition.start), { predicted: true });
|
|
894
|
+
},
|
|
895
|
+
verify(inset, time) {
|
|
896
|
+
if (!transition.predicted || inset == null || time < transition.start + lengthOf()) return null;
|
|
897
|
+
if (Math.abs(inset - transition.to) < EPSILON) return confirm();
|
|
898
|
+
return begin(inset > transition.to ? "show" : "hide", inset, time);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
//#endregion
|
|
903
|
+
//#region src/keyboard/keyboardLayoutGuide.ts
|
|
904
|
+
/**
|
|
905
|
+
* Whose keyboard schedule the guide reads: `chromium` where the browser has
|
|
906
|
+
* the VirtualKeyboard API, else null. Without the profile, no surface rides
|
|
907
|
+
* the guide. Chrome reports the keyboard as each slide starts. The profile is
|
|
908
|
+
* a capability, never the user agent. motion/android/keyboard.ts holds the
|
|
909
|
+
* measured timing.
|
|
910
|
+
*/
|
|
911
|
+
function keyboardProfileOf(win) {
|
|
912
|
+
return hasVirtualKeyboard(win) ? "chromium" : null;
|
|
913
|
+
}
|
|
914
|
+
const VERIFY_SLACK_MS = 150;
|
|
915
|
+
const FOCUS_HANDOFF_MS = 150;
|
|
916
|
+
const PICKER_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
917
|
+
"date",
|
|
918
|
+
"datetime-local",
|
|
919
|
+
"month",
|
|
920
|
+
"time",
|
|
921
|
+
"week"
|
|
922
|
+
]);
|
|
923
|
+
/**
|
|
924
|
+
* Whether focusing `target` brings up a software keyboard (or another input
|
|
925
|
+
* view in its place, as a select's picker does).
|
|
926
|
+
*/
|
|
927
|
+
function bringsUpKeyboard(target) {
|
|
928
|
+
const element = target instanceof Element ? target : null;
|
|
929
|
+
return isTextEntryControl(element) || element instanceof HTMLSelectElement && !element.disabled;
|
|
930
|
+
}
|
|
931
|
+
function opensPickerOverPage(target) {
|
|
932
|
+
const element = target;
|
|
933
|
+
if (element == null || element.nodeType !== 1) return false;
|
|
934
|
+
return element.tagName === "SELECT" || element.tagName === "INPUT" && PICKER_INPUT_TYPES.has(element.type);
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Whether `target` can hold a field the page cannot see: a frame, an open
|
|
938
|
+
* shadow host or a custom element. Focus on a field inside one leaves
|
|
939
|
+
* `document.activeElement` on it.
|
|
940
|
+
*/
|
|
941
|
+
function hidesField(target) {
|
|
942
|
+
return target.tagName === "IFRAME" || target.tagName === "FRAME" || target.tagName === "OBJECT" || target.tagName === "EMBED" || target.shadowRoot != null || target.tagName.includes("-");
|
|
943
|
+
}
|
|
944
|
+
const guides = sharedWeakMap("keyboard/keyboard-layout-guide/guides", 1);
|
|
945
|
+
/**
|
|
946
|
+
* The window's keyboard layout guide, created on first use.
|
|
947
|
+
*
|
|
948
|
+
* One guide serves each window. It subscribes to the keyboard module only
|
|
949
|
+
* while something subscribes to it. It owns no listener and measures nothing.
|
|
950
|
+
* It feeds the model the module's reports, the keyboard height and the focus
|
|
951
|
+
* changes that start a hide. It hands each transition to its subscribers.
|
|
952
|
+
* What it adds is timing: when a show started, a hide predicted from the
|
|
953
|
+
* blur, and the motion in between. Layout follows the keyboard height
|
|
954
|
+
* itself, and the guide's transitions only time the optional ride on top.
|
|
955
|
+
*
|
|
956
|
+
* The model reads Chrome's measured schedule: Chrome reports each slide just
|
|
957
|
+
* after it starts. A surface rides the guide only where the VirtualKeyboard
|
|
958
|
+
* API reports the keyboard. Focus can move from one field to another through
|
|
959
|
+
* something that brings no keyboard, such as a popover's container. Chrome
|
|
960
|
+
* then reports the keyboard gone for a moment and then back. So a hide
|
|
961
|
+
* reported while a field that just got focus still has it waits until the
|
|
962
|
+
* move settles.
|
|
963
|
+
*
|
|
964
|
+
* A busy page reads Chrome's reports late, after Gboard's slide. So once a
|
|
965
|
+
* hide predicted from a blur is under way, a report of the keyboard partway
|
|
966
|
+
* down, or still up, starts nothing. Only the report of the keyboard gone
|
|
967
|
+
* confirms the hide. Focus that comes back still turns it around. Focus in a
|
|
968
|
+
* frame, an open shadow host or a custom element can keep up a keyboard the
|
|
969
|
+
* guide cannot see. There the viewport decides, as before. A closed shadow
|
|
970
|
+
* root on a built-in element reads as nothing focused.
|
|
971
|
+
*
|
|
972
|
+
* @example
|
|
973
|
+
* ```
|
|
974
|
+
* const guide = getKeyboardLayoutGuide(window);
|
|
975
|
+
* const unsubscribe = guide.subscribe(t => {
|
|
976
|
+
* rideKeyboard(animator, {y: -t.to}, t);
|
|
977
|
+
* });
|
|
978
|
+
* ```
|
|
979
|
+
*/
|
|
980
|
+
function getKeyboardLayoutGuide(win) {
|
|
981
|
+
let guide = guides.get(win);
|
|
982
|
+
if (guide == null) {
|
|
983
|
+
guide = createGuide(win);
|
|
984
|
+
guides.set(win, guide);
|
|
985
|
+
}
|
|
986
|
+
return guide;
|
|
987
|
+
}
|
|
988
|
+
function createGuide(win) {
|
|
989
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
990
|
+
let profile = keyboardProfileOf(win);
|
|
991
|
+
let model = createKeyboardModel(getKeyboardHeight(win));
|
|
992
|
+
let verifyTimer = null;
|
|
993
|
+
let detach = null;
|
|
994
|
+
const keepsInputView = (target) => bringsUpKeyboard(target) && !(profile === "chromium" && opensPickerOverPage(target));
|
|
995
|
+
const awaitsHide = () => {
|
|
996
|
+
const active = win.document.activeElement;
|
|
997
|
+
return model.transition.kind === "hide" && model.transition.predicted && !keepsInputView(active) && !(active != null && hidesField(active));
|
|
998
|
+
};
|
|
999
|
+
const publish = (transition) => {
|
|
1000
|
+
if (transition == null) return;
|
|
1001
|
+
if (transition.predicted) scheduleVerify(transition);
|
|
1002
|
+
for (const listener of [...listeners]) listener(transition);
|
|
1003
|
+
};
|
|
1004
|
+
function scheduleVerify(transition) {
|
|
1005
|
+
if (verifyTimer != null) clearTimeout(verifyTimer);
|
|
1006
|
+
const due = transition.start + (transition.curve?.durationMs ?? 0) + VERIFY_SLACK_MS;
|
|
1007
|
+
verifyTimer = setTimeout(() => {
|
|
1008
|
+
verifyTimer = null;
|
|
1009
|
+
const inset = getKeyboardHeight(win);
|
|
1010
|
+
if (inset != null && inset > .5 && awaitsHide()) return;
|
|
1011
|
+
publish(model.verify(inset, win.performance.now()));
|
|
1012
|
+
}, Math.max(0, due - win.performance.now()));
|
|
1013
|
+
}
|
|
1014
|
+
const attach = () => {
|
|
1015
|
+
profile = keyboardProfileOf(win);
|
|
1016
|
+
model = createKeyboardModel(getKeyboardHeight(win));
|
|
1017
|
+
let keyboardFocusAt = -Infinity;
|
|
1018
|
+
let handoffTimer = null;
|
|
1019
|
+
const report = (height, time) => {
|
|
1020
|
+
if (handoffTimer != null) {
|
|
1021
|
+
clearTimeout(handoffTimer);
|
|
1022
|
+
handoffTimer = null;
|
|
1023
|
+
}
|
|
1024
|
+
const settled = keyboardFocusAt + FOCUS_HANDOFF_MS;
|
|
1025
|
+
if (profile === "chromium" && height < .5 && model.inset >= .5 && time < settled && keepsInputView(win.document.activeElement)) {
|
|
1026
|
+
handoffTimer = setTimeout(() => {
|
|
1027
|
+
handoffTimer = null;
|
|
1028
|
+
publish(model.report(getKeyboardHeight(win), settled));
|
|
1029
|
+
}, settled - time);
|
|
1030
|
+
return null;
|
|
1031
|
+
}
|
|
1032
|
+
if (height > .5 && awaitsHide()) return null;
|
|
1033
|
+
return model.report(height, time);
|
|
1034
|
+
};
|
|
1035
|
+
const onReport = (event) => {
|
|
1036
|
+
if (event.type === "viewport") publish(report(event.height, event.timeStamp));
|
|
1037
|
+
else if (event.type === "focusin") {
|
|
1038
|
+
if (keepsInputView(event.target)) {
|
|
1039
|
+
keyboardFocusAt = event.timeStamp;
|
|
1040
|
+
publish(model.focused(event.timeStamp));
|
|
1041
|
+
}
|
|
1042
|
+
} else if (keepsInputView(event.target) && !keepsInputView(event.relatedTarget)) publish(model.blurred(event.timeStamp));
|
|
1043
|
+
};
|
|
1044
|
+
const unsubscribe = subscribeKeyboardHeight(win, onReport, { focus: true });
|
|
1045
|
+
return () => {
|
|
1046
|
+
unsubscribe();
|
|
1047
|
+
if (handoffTimer != null) {
|
|
1048
|
+
clearTimeout(handoffTimer);
|
|
1049
|
+
handoffTimer = null;
|
|
1050
|
+
}
|
|
1051
|
+
if (verifyTimer != null) {
|
|
1052
|
+
clearTimeout(verifyTimer);
|
|
1053
|
+
verifyTimer = null;
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1057
|
+
return {
|
|
1058
|
+
get profile() {
|
|
1059
|
+
return profile;
|
|
1060
|
+
},
|
|
1061
|
+
get inset() {
|
|
1062
|
+
return model.inset;
|
|
1063
|
+
},
|
|
1064
|
+
get transition() {
|
|
1065
|
+
return model.transition;
|
|
1066
|
+
},
|
|
1067
|
+
presentation(time = win.performance.now()) {
|
|
1068
|
+
return model.presentation(time);
|
|
1069
|
+
},
|
|
1070
|
+
subscribe(listener) {
|
|
1071
|
+
listeners.add(listener);
|
|
1072
|
+
detach ??= attach();
|
|
1073
|
+
return () => {
|
|
1074
|
+
listeners.delete(listener);
|
|
1075
|
+
if (listeners.size === 0 && detach != null) {
|
|
1076
|
+
detach();
|
|
1077
|
+
detach = null;
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
}
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
//#endregion
|
|
1084
|
+
//#region src/keyboard/keyboardScrollBack.ts
|
|
1085
|
+
/**
|
|
1086
|
+
* @file keyboardScrollBack.ts
|
|
1087
|
+
* @input The keyboard module's reports, the input stream's focus and touches,
|
|
1088
|
+
* and Reduce Motion
|
|
1089
|
+
* @output The scroll back: each scroll Core makes to keep a field above the
|
|
1090
|
+
* keyboard goes back when the keyboard goes (claimKeyboardScrollBack,
|
|
1091
|
+
* noteKeyboardScroll, keyboardScrollTarget, stopKeyboardScrollBack)
|
|
1092
|
+
* @position Keyboard module, internal to core. keyboardReveal.ts records the
|
|
1093
|
+
* scrolls and keyboardTarget.ts claims the scroll back for each field.
|
|
1094
|
+
*/
|
|
1095
|
+
const addedScrolls = sharedWeakMap("keyboard/keyboard-target/scroll-back-added-scrolls", 1);
|
|
1096
|
+
const stopsOf = sharedWeakMap("keyboard/keyboard-target/scroll-back-stops", 1);
|
|
1097
|
+
const foldWaitsOf = sharedWeakMap("keyboard/keyboard-target/scroll-back-fold-waits", 1);
|
|
1098
|
+
const claimants = sharedWeakMap("keyboard/keyboard-target/scroll-back-claimants", 1);
|
|
1099
|
+
/**
|
|
1100
|
+
* Counts a field that keeps itself above `win`'s keyboard until the returned
|
|
1101
|
+
* call. Once no such field is left, nothing is put back: its page is gone.
|
|
1102
|
+
*/
|
|
1103
|
+
function claimKeyboardScrollBack(win) {
|
|
1104
|
+
claimants.set(win, (claimants.get(win) ?? 0) + 1);
|
|
1105
|
+
let isClaimed = true;
|
|
1106
|
+
return () => {
|
|
1107
|
+
if (!isClaimed) return;
|
|
1108
|
+
isClaimed = false;
|
|
1109
|
+
const left = (claimants.get(win) ?? 1) - 1;
|
|
1110
|
+
claimants.set(win, left);
|
|
1111
|
+
if (left === 0) {
|
|
1112
|
+
stopsOf.get(win)?.();
|
|
1113
|
+
foldWaitsOf.get(win)?.();
|
|
1114
|
+
}
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
function isRoot(scroller) {
|
|
1118
|
+
const doc = scroller.ownerDocument;
|
|
1119
|
+
return scroller === (doc.scrollingElement ?? doc.documentElement);
|
|
1120
|
+
}
|
|
1121
|
+
/** How far `scroller` is scrolled; for the root, the document's scroll. */
|
|
1122
|
+
function scrollTopOf(scroller, win) {
|
|
1123
|
+
return isRoot(scroller) ? win.scrollY : scroller.scrollTop;
|
|
1124
|
+
}
|
|
1125
|
+
function scrollTopTo(scroller, top, behavior, win) {
|
|
1126
|
+
if (isRoot(scroller)) win.scrollTo({
|
|
1127
|
+
top,
|
|
1128
|
+
behavior
|
|
1129
|
+
});
|
|
1130
|
+
else if (typeof scroller.scrollTo === "function") scroller.scrollTo({
|
|
1131
|
+
top,
|
|
1132
|
+
behavior
|
|
1133
|
+
});
|
|
1134
|
+
else scroller.scrollTop = top;
|
|
1135
|
+
}
|
|
1136
|
+
/**
|
|
1137
|
+
* Records that Core scrolled `scroller` from `before` to `after`, to keep a
|
|
1138
|
+
* field above the keyboard. `after` is where a smooth scroll is headed, and
|
|
1139
|
+
* where the scroller is now for any other. When the keyboard goes, the
|
|
1140
|
+
* scroller goes back to where it was before Core's first scroll. A scroller
|
|
1141
|
+
* anyone else scrolls meanwhile keeps that scroll.
|
|
1142
|
+
*/
|
|
1143
|
+
function noteKeyboardScroll(scroller, before, win, after = scrollTopOf(scroller, win)) {
|
|
1144
|
+
const now = after;
|
|
1145
|
+
const added = addedScrolls.get(win)?.get(scroller);
|
|
1146
|
+
if (added == null) {
|
|
1147
|
+
if (Math.abs(now - before) >= .5) (addedScrolls.get(win) ?? watchKeyboardGo(win)).set(scroller, {
|
|
1148
|
+
from: before,
|
|
1149
|
+
at: now,
|
|
1150
|
+
isBack: false
|
|
1151
|
+
});
|
|
1152
|
+
} else if (added.at != null && Math.abs(before - added.at) <= 1) added.at = now;
|
|
1153
|
+
else added.at = null;
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Where Core's own scroll of `scroller` is headed, while the scroller lies on
|
|
1157
|
+
* its way there, as during a smooth rise. Null for a scroller Core did not
|
|
1158
|
+
* scroll, or one moved off that way.
|
|
1159
|
+
*/
|
|
1160
|
+
function keyboardScrollTarget(scroller, win) {
|
|
1161
|
+
const added = addedScrolls.get(win)?.get(scroller);
|
|
1162
|
+
if (added?.at == null) return null;
|
|
1163
|
+
const now = scrollTopOf(scroller, win);
|
|
1164
|
+
const low = Math.min(added.from, added.at) - 1;
|
|
1165
|
+
const high = Math.max(added.from, added.at) + 1;
|
|
1166
|
+
return now >= low && now <= high ? added.at : null;
|
|
1167
|
+
}
|
|
1168
|
+
function watchKeyboardGo(win) {
|
|
1169
|
+
const scrolls = /* @__PURE__ */ new Map();
|
|
1170
|
+
const stopReports = subscribeKeyboardHeight(win, (event) => {
|
|
1171
|
+
if (event.type === "viewport" && event.height <= 1) {
|
|
1172
|
+
end();
|
|
1173
|
+
scrollBack(win, scrolls);
|
|
1174
|
+
}
|
|
1175
|
+
});
|
|
1176
|
+
let settle = null;
|
|
1177
|
+
const stopBlurs = isIosWebKit(win.document.defaultView) ? watchBlurs() : [];
|
|
1178
|
+
function watchBlurs() {
|
|
1179
|
+
return [
|
|
1180
|
+
subscribeInput(win, "touchstart", () => {}),
|
|
1181
|
+
subscribeInput(win, "touchend", () => {}),
|
|
1182
|
+
subscribeInput(win, "touchcancel", () => {}),
|
|
1183
|
+
subscribeInput(win, "focusout", () => {
|
|
1184
|
+
if (settle != null) win.clearTimeout(settle);
|
|
1185
|
+
settle = win.setTimeout(() => {
|
|
1186
|
+
settle = null;
|
|
1187
|
+
const active = win.document.activeElement;
|
|
1188
|
+
if (getTouches(win).fingers === 0 && (active == null || !bringsUpKeyboard(active) && !hidesField(active))) scrollBackAtBlur(win, scrolls);
|
|
1189
|
+
}, 0);
|
|
1190
|
+
})
|
|
1191
|
+
];
|
|
1192
|
+
}
|
|
1193
|
+
function end() {
|
|
1194
|
+
stopReports();
|
|
1195
|
+
for (const stop of stopBlurs) stop();
|
|
1196
|
+
if (settle != null) {
|
|
1197
|
+
win.clearTimeout(settle);
|
|
1198
|
+
settle = null;
|
|
1199
|
+
}
|
|
1200
|
+
addedScrolls.delete(win);
|
|
1201
|
+
stopsOf.delete(win);
|
|
1202
|
+
}
|
|
1203
|
+
addedScrolls.set(win, scrolls);
|
|
1204
|
+
stopsOf.set(win, end);
|
|
1205
|
+
return scrolls;
|
|
1206
|
+
}
|
|
1207
|
+
function scrollBackAtBlur(win, scrolls) {
|
|
1208
|
+
for (const [scroller, added] of scrolls) {
|
|
1209
|
+
if (added.at == null || reducedMotionFade(scroller) != null || Math.abs(scrollTopOf(scroller, win) - added.at) > 1) continue;
|
|
1210
|
+
added.at = added.from;
|
|
1211
|
+
added.isBack = true;
|
|
1212
|
+
scrollTopTo(scroller, added.from, "smooth", win);
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Stops a scroll back that runs from the blur, where each scroller is now. A
|
|
1217
|
+
* field that gains focus during the keyboard's slide calls it before its
|
|
1218
|
+
* reveal, so the reveal goes on from there as Core's own scroll. The instant
|
|
1219
|
+
* scroll also ends a scroll back that a touch held, which Safari would run
|
|
1220
|
+
* after the field is placed.
|
|
1221
|
+
*/
|
|
1222
|
+
function stopKeyboardScrollBack(win) {
|
|
1223
|
+
for (const [scroller, added] of addedScrolls.get(win) ?? []) {
|
|
1224
|
+
if (!added.isBack) continue;
|
|
1225
|
+
const top = scrollTopOf(scroller, win);
|
|
1226
|
+
scrollTopTo(scroller, top, "instant", win);
|
|
1227
|
+
added.at = top;
|
|
1228
|
+
added.isBack = false;
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
function scrollBack(win, scrolls) {
|
|
1232
|
+
for (const [scroller, { from, at, isBack }] of scrolls) {
|
|
1233
|
+
if (at == null || isBack || !scroller.isConnected) continue;
|
|
1234
|
+
const top = scrollTopOf(scroller, win);
|
|
1235
|
+
if (Math.abs(top - at) <= 1) scrollTopTo(scroller, from, scrollBackBehavior(scroller), win);
|
|
1236
|
+
else if (isRoot(scroller) && Math.abs(top - from) <= 1) awaitFoldedReveal(win, scroller, from, at);
|
|
1237
|
+
}
|
|
1238
|
+
scrolls.clear();
|
|
1239
|
+
}
|
|
1240
|
+
function scrollBackBehavior(scroller) {
|
|
1241
|
+
return reducedMotionFade(scroller) == null ? "smooth" : "instant";
|
|
1242
|
+
}
|
|
1243
|
+
const FOLD_WAIT_MS = 1e3;
|
|
1244
|
+
function awaitFoldedReveal(win, scroller, from, at) {
|
|
1245
|
+
const doc = win.document;
|
|
1246
|
+
const stopScroll = subscribeInput(win, "scroll", (event) => {
|
|
1247
|
+
if (event.target !== doc && event.target !== win) return;
|
|
1248
|
+
stop();
|
|
1249
|
+
if (Math.abs(scrollTopOf(scroller, win) - at) <= 1) scrollTopTo(scroller, from, scrollBackBehavior(scroller), win);
|
|
1250
|
+
});
|
|
1251
|
+
const stopTouch = subscribeInput(win, "touchstart", () => stop());
|
|
1252
|
+
const stopKeyboard = subscribeKeyboardHeight(win, (event) => {
|
|
1253
|
+
if (event.type === "viewport" && event.height > 1) stop();
|
|
1254
|
+
});
|
|
1255
|
+
const timer = win.setTimeout(stop, FOLD_WAIT_MS);
|
|
1256
|
+
foldWaitsOf.get(win)?.();
|
|
1257
|
+
foldWaitsOf.set(win, stop);
|
|
1258
|
+
function stop() {
|
|
1259
|
+
win.clearTimeout(timer);
|
|
1260
|
+
stopScroll();
|
|
1261
|
+
stopTouch();
|
|
1262
|
+
stopKeyboard();
|
|
1263
|
+
if (foldWaitsOf.get(win) === stop) foldWaitsOf.delete(win);
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
//#endregion
|
|
1267
|
+
//#region src/keyboard/revealBand.ts
|
|
1268
|
+
/**
|
|
1269
|
+
* @file revealBand.ts
|
|
1270
|
+
* @input A box's top and bottom edges and a band's, CSS px
|
|
1271
|
+
* @output distanceIntoBand, the scroll that brings the box inside the band
|
|
1272
|
+
* @position Keyboard module, internal to core. A field's reveal and the
|
|
1273
|
+
* Tall sheet's reveal share it.
|
|
1274
|
+
*/
|
|
1275
|
+
/**
|
|
1276
|
+
* How far content must scroll so a box from `top` to `bottom` sits inside the
|
|
1277
|
+
* band from `safeTop` to `safeBottom`, CSS px. A positive distance scrolls it
|
|
1278
|
+
* up and a negative one down. It is 0 when the box fits or the band is empty. A
|
|
1279
|
+
* box taller than the band keeps its bottom edge in it.
|
|
1280
|
+
*
|
|
1281
|
+
* @example
|
|
1282
|
+
* ```
|
|
1283
|
+
* const distance = distanceIntoBand(rect.top, rect.bottom, 0, keyboardTop - 17);
|
|
1284
|
+
* ```
|
|
1285
|
+
*/
|
|
1286
|
+
function distanceIntoBand(top, bottom, safeTop, safeBottom) {
|
|
1287
|
+
if (safeBottom <= safeTop) return 0;
|
|
1288
|
+
if (bottom > safeBottom) return bottom - safeBottom;
|
|
1289
|
+
if (top < safeTop) return top - safeTop;
|
|
1290
|
+
return 0;
|
|
1291
|
+
}
|
|
1292
|
+
//#endregion
|
|
1293
|
+
//#region src/keyboard/revealPan.ts
|
|
1294
|
+
/**
|
|
1295
|
+
* @file revealPan.ts
|
|
1296
|
+
* @input The visual viewport, the document's scroll and the input stream's
|
|
1297
|
+
* touches
|
|
1298
|
+
* @output watchRevealPan, which notices the browser's own reveal pan and puts
|
|
1299
|
+
* it back, and panVisualViewportTo, the one way Core pans the visual
|
|
1300
|
+
* viewport
|
|
1301
|
+
* @position Keyboard module, internal to core. Every watch in a document
|
|
1302
|
+
* shares one touch subscription.
|
|
1303
|
+
*/
|
|
1304
|
+
const touchStartWatches = sharedWeakMap("keyboard/keyboard-height/touch-start-watches", 1);
|
|
1305
|
+
function watchTouchStarts(doc, onTouchStart) {
|
|
1306
|
+
let shared = touchStartWatches.get(doc);
|
|
1307
|
+
if (shared == null) {
|
|
1308
|
+
const view = doc.defaultView;
|
|
1309
|
+
if (view == null) return () => {};
|
|
1310
|
+
const watches = /* @__PURE__ */ new Set();
|
|
1311
|
+
const stopStarts = subscribeInput(view, "touchstart", () => {
|
|
1312
|
+
for (const watch of [...watches]) watch();
|
|
1313
|
+
});
|
|
1314
|
+
const stopEnds = subscribeInput(view, "touchend", () => {});
|
|
1315
|
+
const stopCancels = subscribeInput(view, "touchcancel", () => {});
|
|
1316
|
+
shared = {
|
|
1317
|
+
stop: () => {
|
|
1318
|
+
stopStarts();
|
|
1319
|
+
stopEnds();
|
|
1320
|
+
stopCancels();
|
|
1321
|
+
},
|
|
1322
|
+
watches
|
|
1323
|
+
};
|
|
1324
|
+
touchStartWatches.set(doc, shared);
|
|
1325
|
+
}
|
|
1326
|
+
shared.watches.add(onTouchStart);
|
|
1327
|
+
return () => {
|
|
1328
|
+
const current = touchStartWatches.get(doc);
|
|
1329
|
+
if (current == null || !current.watches.delete(onTouchStart)) return;
|
|
1330
|
+
if (current.watches.size === 0) {
|
|
1331
|
+
current.stop();
|
|
1332
|
+
touchStartWatches.delete(doc);
|
|
1333
|
+
}
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
/**
|
|
1337
|
+
* Some browsers reveal a focused field themselves, after the keyboard's
|
|
1338
|
+
* report, by panning the visual viewport to it while the keyboard still
|
|
1339
|
+
* covers it. Firefox for Android pans 54 to 143 ms after the report. Chrome
|
|
1340
|
+
* on Android animates a pan of the keyboard's whole height from about 100 to
|
|
1341
|
+
* 170 ms after it. The page gets no frame until that pan ends. Such a pan
|
|
1342
|
+
* moves the visual viewport down within the
|
|
1343
|
+
* layout viewport. Since the report there is no touch, document scroll or
|
|
1344
|
+
* zoom, and a text field the caller owns has focus. In Chrome, a reveal of a
|
|
1345
|
+
* field in a fixed container also scrolls the document first. The watch reads
|
|
1346
|
+
* the behavior, never the user agent. The caller lands its field itself and
|
|
1347
|
+
* puts the pan back. Every keyboard-aware surface can use it.
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```
|
|
1351
|
+
* const watch = watchRevealPan(window, {owns: field => region.contains(field)});
|
|
1352
|
+
* // On a report that changes the height: watch.report();
|
|
1353
|
+
* // On any later report: if (watch.isRevealPan(height)) watch.putBack();
|
|
1354
|
+
* ```
|
|
1355
|
+
*/
|
|
1356
|
+
function watchRevealPan(win, { owns, onTouch, documentScrollIsReveal = false }) {
|
|
1357
|
+
const doc = win.document;
|
|
1358
|
+
let atReport = null;
|
|
1359
|
+
let touchedSinceReport = false;
|
|
1360
|
+
let isChromeReveal = null;
|
|
1361
|
+
return {
|
|
1362
|
+
report: () => {
|
|
1363
|
+
const viewport = win.visualViewport;
|
|
1364
|
+
atReport = viewport == null ? null : {
|
|
1365
|
+
x: win.scrollX,
|
|
1366
|
+
y: win.scrollY,
|
|
1367
|
+
top: viewport.offsetTop,
|
|
1368
|
+
scale: viewport.scale
|
|
1369
|
+
};
|
|
1370
|
+
touchedSinceReport = isFingerOnScreen(win);
|
|
1371
|
+
isChromeReveal = null;
|
|
1372
|
+
},
|
|
1373
|
+
isRevealPan: (height) => {
|
|
1374
|
+
const viewport = win.visualViewport;
|
|
1375
|
+
const focused = doc.activeElement;
|
|
1376
|
+
return viewport != null && atReport != null && !touchedSinceReport && height > 0 && viewport.offsetTop > atReport.top && viewport.scale === atReport.scale && focused instanceof HTMLElement && isTextEntryControl(focused) && owns(focused) && (win.scrollX === atReport.x && win.scrollY === atReport.y || documentScrollIsReveal && (isChromeReveal ??= isCentringReveal(win, viewport, focused, atReport)));
|
|
1377
|
+
},
|
|
1378
|
+
putBack: (anchor) => {
|
|
1379
|
+
isChromeReveal = null;
|
|
1380
|
+
const options = {
|
|
1381
|
+
block: "start",
|
|
1382
|
+
inline: "nearest",
|
|
1383
|
+
behavior: "instant"
|
|
1384
|
+
};
|
|
1385
|
+
if (documentScrollIsReveal && atReport != null && (win.scrollX !== atReport.x || win.scrollY !== atReport.y)) win.scrollTo({
|
|
1386
|
+
left: atReport.x,
|
|
1387
|
+
top: atReport.y,
|
|
1388
|
+
behavior: "instant"
|
|
1389
|
+
});
|
|
1390
|
+
if (anchor != null) {
|
|
1391
|
+
anchor.scrollIntoView(options);
|
|
1392
|
+
return;
|
|
1393
|
+
}
|
|
1394
|
+
panVisualViewportTo(win, atReport?.top ?? 0);
|
|
1395
|
+
},
|
|
1396
|
+
stop: watchTouchStarts(doc, () => {
|
|
1397
|
+
touchedSinceReport = true;
|
|
1398
|
+
onTouch?.();
|
|
1399
|
+
})
|
|
1400
|
+
};
|
|
1401
|
+
}
|
|
1402
|
+
const CENTRING_SLACK_PX = 2;
|
|
1403
|
+
function isCentringReveal(win, viewport, field, atReport) {
|
|
1404
|
+
const box = field.getBoundingClientRect();
|
|
1405
|
+
const centring = (box.top + box.bottom) / 2 - viewport.height / 2;
|
|
1406
|
+
const root = win.document.scrollingElement ?? win.document.documentElement;
|
|
1407
|
+
const range = root.scrollHeight - root.clientHeight;
|
|
1408
|
+
const room = layoutViewportHeight(win) - viewport.height;
|
|
1409
|
+
const scroll = Math.min(range, Math.max(0, atReport.y + centring));
|
|
1410
|
+
const pan = Math.min(room, Math.max(0, centring));
|
|
1411
|
+
return win.scrollX === atReport.x && Math.abs(win.scrollY - scroll) <= CENTRING_SLACK_PX && Math.abs(viewport.offsetTop - pan) <= CENTRING_SLACK_PX;
|
|
1412
|
+
}
|
|
1413
|
+
/**
|
|
1414
|
+
* Pans the visual viewport so its top sits `top` CSS px down the layout
|
|
1415
|
+
* viewport, without scrolling the document. A probe fixed there is scrolled
|
|
1416
|
+
* into view. In Chrome for Android this pans the visual viewport. In Firefox
|
|
1417
|
+
* for Android it pans nothing where the page has no scroll range. The pan
|
|
1418
|
+
* reaches the room the keyboard takes, which a document scroll cannot.
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```
|
|
1422
|
+
* panVisualViewportTo(window, window.visualViewport.offsetTop + 120);
|
|
1423
|
+
* ```
|
|
1424
|
+
*/
|
|
1425
|
+
function panVisualViewportTo(win, top) {
|
|
1426
|
+
const doc = win.document;
|
|
1427
|
+
const probe = doc.createElement("div");
|
|
1428
|
+
probe.style.position = "fixed";
|
|
1429
|
+
probe.style.left = "0";
|
|
1430
|
+
probe.style.top = `${top}px`;
|
|
1431
|
+
probe.style.width = "1px";
|
|
1432
|
+
probe.style.height = "1px";
|
|
1433
|
+
probe.style.visibility = "hidden";
|
|
1434
|
+
probe.style.pointerEvents = "none";
|
|
1435
|
+
(doc.body ?? doc.documentElement).append(probe);
|
|
1436
|
+
probe.scrollIntoView({
|
|
1437
|
+
block: "start",
|
|
1438
|
+
inline: "nearest",
|
|
1439
|
+
behavior: "instant"
|
|
1440
|
+
});
|
|
1441
|
+
probe.remove();
|
|
1442
|
+
}
|
|
1443
|
+
//#endregion
|
|
1444
|
+
//#region src/keyboard/tapFocus.ts
|
|
1445
|
+
/**
|
|
1446
|
+
* @file tapFocus.ts
|
|
1447
|
+
* @input A region's touch events, the shared press slop and the click guard
|
|
1448
|
+
* @output claimTapFocus, the tap route that focuses a claimed field itself,
|
|
1449
|
+
* and focusAtPoint, which focuses without Safari's reveal and puts the
|
|
1450
|
+
* caret under the finger
|
|
1451
|
+
* @position Keyboard module, internal to core. The keyboard targets deliver
|
|
1452
|
+
* taps through it.
|
|
1453
|
+
*/
|
|
1454
|
+
/**
|
|
1455
|
+
* The tap route. `deliver` focuses a one-finger tap on `region` that `claim`
|
|
1456
|
+
* accepts, such as a field without focus, instead of the browser. The
|
|
1457
|
+
* browser's own focus would reveal the field by scrolling the document. The
|
|
1458
|
+
* route prevents the tap's default at its end. The shared click guard then
|
|
1459
|
+
* takes the mouse events Safari may still send for the tap. The browser keeps a
|
|
1460
|
+
* touch that moves past the scroll slop, and a second finger. Returns a
|
|
1461
|
+
* cleanup.
|
|
1462
|
+
*
|
|
1463
|
+
* @example
|
|
1464
|
+
* ```
|
|
1465
|
+
* const stop = claimTapFocus(region, {
|
|
1466
|
+
* claim: target => editableWithoutFocus(target),
|
|
1467
|
+
* deliver: (field, x, y) => focusAtPoint(field, x, y),
|
|
1468
|
+
* });
|
|
1469
|
+
* ```
|
|
1470
|
+
*/
|
|
1471
|
+
function claimTapFocus(region, { claim, deliver }) {
|
|
1472
|
+
let start = null;
|
|
1473
|
+
const stopFollowing = () => {
|
|
1474
|
+
start = null;
|
|
1475
|
+
region.removeEventListener("touchmove", onMove);
|
|
1476
|
+
region.removeEventListener("touchend", onEnd);
|
|
1477
|
+
region.removeEventListener("touchcancel", stopFollowing);
|
|
1478
|
+
};
|
|
1479
|
+
function onMove(event) {
|
|
1480
|
+
const touch = event.touches[0];
|
|
1481
|
+
if (start == null || event.touches.length !== 1 || touch == null || Math.hypot(touch.clientX - start.x, touch.clientY - start.y) > PRESS_SLOP_PX) stopFollowing();
|
|
1482
|
+
}
|
|
1483
|
+
function onEnd(event) {
|
|
1484
|
+
const touch = event.changedTouches[0];
|
|
1485
|
+
const tap = start;
|
|
1486
|
+
stopFollowing();
|
|
1487
|
+
if (tap == null || touch == null || !event.cancelable || claim(tap.control) !== tap.control) return;
|
|
1488
|
+
event.preventDefault();
|
|
1489
|
+
deliver(tap.control, touch.clientX, touch.clientY, touch);
|
|
1490
|
+
armClickGuard(region.ownerDocument, { takesLateMouse: true });
|
|
1491
|
+
}
|
|
1492
|
+
const onStart = (event) => {
|
|
1493
|
+
if (start != null) {
|
|
1494
|
+
stopFollowing();
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
const touch = event.touches[0];
|
|
1498
|
+
const control = event.touches.length === 1 && touch != null ? claim(event.target) : null;
|
|
1499
|
+
if (control == null || touch == null) return;
|
|
1500
|
+
start = {
|
|
1501
|
+
x: touch.clientX,
|
|
1502
|
+
y: touch.clientY,
|
|
1503
|
+
control
|
|
1504
|
+
};
|
|
1505
|
+
region.addEventListener("touchmove", onMove, { passive: true });
|
|
1506
|
+
region.addEventListener("touchend", onEnd);
|
|
1507
|
+
region.addEventListener("touchcancel", stopFollowing);
|
|
1508
|
+
};
|
|
1509
|
+
region.addEventListener("touchstart", onStart, { passive: true });
|
|
1510
|
+
return () => {
|
|
1511
|
+
stopFollowing();
|
|
1512
|
+
region.removeEventListener("touchstart", onStart);
|
|
1513
|
+
};
|
|
1514
|
+
}
|
|
1515
|
+
function isTextControl(element) {
|
|
1516
|
+
return element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement;
|
|
1517
|
+
}
|
|
1518
|
+
/**
|
|
1519
|
+
* A text control's caret for a tap at (x, y). It is where the browser maps
|
|
1520
|
+
* the point inside the control. Where the browser maps none, it is after the
|
|
1521
|
+
* text, the convention for a focus without a point. A control with no text
|
|
1522
|
+
* selection stays as it is.
|
|
1523
|
+
*/
|
|
1524
|
+
function placeTextControlCaret(control, x, y) {
|
|
1525
|
+
if (control.selectionStart == null) return;
|
|
1526
|
+
const caret = caretAt(control.ownerDocument, x, y, []);
|
|
1527
|
+
const offset = caret != null && caret.node === control ? caret.offset : control.value.length;
|
|
1528
|
+
control.setSelectionRange(offset, offset);
|
|
1529
|
+
}
|
|
1530
|
+
/**
|
|
1531
|
+
* Focuses without Safari's reveal and puts the caret under the finger.
|
|
1532
|
+
* Exported for its tests.
|
|
1533
|
+
*/
|
|
1534
|
+
function focusAtPoint(editable, x, y) {
|
|
1535
|
+
editable.focus({ preventScroll: true });
|
|
1536
|
+
if (isTextControl(editable)) {
|
|
1537
|
+
placeTextControlCaret(editable, x, y);
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
const doc = editable.ownerDocument;
|
|
1541
|
+
const caret = caretAt(doc, x, y, []);
|
|
1542
|
+
if (caret != null && editable.isContentEditable && editable.contains(caret.node)) {
|
|
1543
|
+
const range = doc.createRange();
|
|
1544
|
+
range.setStart(caret.node, caret.offset);
|
|
1545
|
+
range.collapse(true);
|
|
1546
|
+
const selection = doc.getSelection();
|
|
1547
|
+
selection?.removeAllRanges();
|
|
1548
|
+
selection?.addRange(range);
|
|
1549
|
+
}
|
|
1550
|
+
}
|
|
1551
|
+
//#endregion
|
|
1552
|
+
//#region src/keyboard/keyboardReveal.ts
|
|
1553
|
+
/**
|
|
1554
|
+
* @file keyboardReveal.ts
|
|
1555
|
+
* @input The keyboard module's reports, the reveal-pan watch, the input
|
|
1556
|
+
* stream's touches and the scroll back's records
|
|
1557
|
+
* @output The reveal: a scroller brings the focused field into the band above
|
|
1558
|
+
* the keyboard (revealWithKeyboard), the pan watch (watchPans) and the tap's
|
|
1559
|
+
* delivery (deliverTap)
|
|
1560
|
+
* @position Keyboard module, internal to core. keyboardTarget.ts and
|
|
1561
|
+
* keyboardRide.ts call it.
|
|
1562
|
+
*/
|
|
1563
|
+
function scrollBy(scroller, distance, win, behavior = "instant") {
|
|
1564
|
+
const doc = scroller.ownerDocument;
|
|
1565
|
+
if (scroller === (doc.scrollingElement ?? doc.documentElement)) win.scrollBy({
|
|
1566
|
+
top: distance,
|
|
1567
|
+
behavior
|
|
1568
|
+
});
|
|
1569
|
+
else if (typeof scroller.scrollBy === "function") scroller.scrollBy({
|
|
1570
|
+
top: distance,
|
|
1571
|
+
behavior
|
|
1572
|
+
});
|
|
1573
|
+
else scroller.scrollTop += distance;
|
|
1574
|
+
}
|
|
1575
|
+
function scrollRangeOf(scroller, win) {
|
|
1576
|
+
const doc = scroller.ownerDocument;
|
|
1577
|
+
const view = scroller === (doc.scrollingElement ?? doc.documentElement) ? layoutViewportHeight(win) : scroller.clientHeight;
|
|
1578
|
+
return Math.max(0, scroller.scrollHeight - view);
|
|
1579
|
+
}
|
|
1580
|
+
function risesSmoothly(field) {
|
|
1581
|
+
return isIosWebKit(field.ownerDocument.defaultView) && reducedMotionFade(field) == null;
|
|
1582
|
+
}
|
|
1583
|
+
function bandOf(scroller, height, offset, win, shift = 0) {
|
|
1584
|
+
const doc = scroller.ownerDocument;
|
|
1585
|
+
const keyboardTop = layoutViewportHeight(win) - height;
|
|
1586
|
+
let top = 0;
|
|
1587
|
+
let bottom = height > 1 ? keyboardTop - offset : keyboardTop;
|
|
1588
|
+
if (scroller !== (doc.scrollingElement ?? doc.documentElement)) {
|
|
1589
|
+
const box = scroller.getBoundingClientRect();
|
|
1590
|
+
top = Math.max(top, box.top + shift);
|
|
1591
|
+
bottom = Math.min(bottom, box.bottom + shift);
|
|
1592
|
+
}
|
|
1593
|
+
return {
|
|
1594
|
+
top,
|
|
1595
|
+
bottom
|
|
1596
|
+
};
|
|
1597
|
+
}
|
|
1598
|
+
function revealDistance(field, scroller, height, offset, win, shift = 0) {
|
|
1599
|
+
const band = bandOf(scroller, height, offset, win, shift);
|
|
1600
|
+
const box = field.getBoundingClientRect();
|
|
1601
|
+
return distanceIntoBand(box.top + shift, box.bottom + shift, band.top, band.bottom);
|
|
1602
|
+
}
|
|
1603
|
+
function sitsInBand(field, scroller, height, offset, win, fieldShift = 0) {
|
|
1604
|
+
const band = bandOf(scroller, height, offset, win);
|
|
1605
|
+
const box = field.getBoundingClientRect();
|
|
1606
|
+
return box.top + fieldShift >= band.top - 1 && box.bottom + fieldShift <= band.bottom + 1;
|
|
1607
|
+
}
|
|
1608
|
+
function reveal(field, scroller, height, offset, win, canRise = true) {
|
|
1609
|
+
const distance = revealDistance(field, scroller, height, offset, win);
|
|
1610
|
+
if (Math.abs(distance) <= 1) return 0;
|
|
1611
|
+
const now = scrollTopOf(scroller, win);
|
|
1612
|
+
const target = Math.min(Math.max(now + distance, 0), scrollRangeOf(scroller, win));
|
|
1613
|
+
const rises = canRise && height > 1 && Math.abs(target - now - distance) <= 1 && sitsInBand(field, scroller, height, offset, win, -distance) && risesSmoothly(field);
|
|
1614
|
+
const before = keyboardScrollTarget(scroller, win) ?? now;
|
|
1615
|
+
scrollBy(scroller, distance, win, rises ? "smooth" : "instant");
|
|
1616
|
+
if (height > 1) noteKeyboardScroll(scroller, before, win, rises ? target : void 0);
|
|
1617
|
+
return rises ? target - scrollTopOf(scroller, win) : 0;
|
|
1618
|
+
}
|
|
1619
|
+
function deliverTap(control, x, y, touch) {
|
|
1620
|
+
focusAtPoint(control, x, y);
|
|
1621
|
+
const view = control.ownerDocument.defaultView;
|
|
1622
|
+
const init = {
|
|
1623
|
+
bubbles: true,
|
|
1624
|
+
cancelable: true,
|
|
1625
|
+
composed: true,
|
|
1626
|
+
detail: 1,
|
|
1627
|
+
clientX: x,
|
|
1628
|
+
clientY: y,
|
|
1629
|
+
screenX: touch.screenX,
|
|
1630
|
+
screenY: touch.screenY
|
|
1631
|
+
};
|
|
1632
|
+
const PointerClick = view?.PointerEvent;
|
|
1633
|
+
const click = typeof PointerClick === "function" ? new PointerClick("click", {
|
|
1634
|
+
...init,
|
|
1635
|
+
pointerType: "touch",
|
|
1636
|
+
isPrimary: true,
|
|
1637
|
+
pointerId: touch.identifier
|
|
1638
|
+
}) : new ((view?.MouseEvent) ?? MouseEvent)("click", init);
|
|
1639
|
+
control.dispatchEvent(click);
|
|
1640
|
+
}
|
|
1641
|
+
/**
|
|
1642
|
+
* Puts back a pan the browser makes on its own after a keyboard report. This
|
|
1643
|
+
* happens, for example, after a focus no claim saw: a script's `focus()` while
|
|
1644
|
+
* nothing has focus. The field sits in place already, so the pan only displaces
|
|
1645
|
+
* the page. A pan made at the last height goes back at the next height's
|
|
1646
|
+
* report. The caller's own pan is the new rest once reported (`expectPan`):
|
|
1647
|
+
* its report comes after the call returns.
|
|
1648
|
+
* Feed `report` each keyboard height the module reports; `owns` says whether a
|
|
1649
|
+
* focused element is one this watch keeps in place. `documentScrollIsReveal`
|
|
1650
|
+
* is watchRevealPan's option of that name.
|
|
1651
|
+
*/
|
|
1652
|
+
function watchPans(win, owns, documentScrollIsReveal = false) {
|
|
1653
|
+
const watch = watchRevealPan(win, {
|
|
1654
|
+
owns,
|
|
1655
|
+
documentScrollIsReveal
|
|
1656
|
+
});
|
|
1657
|
+
let lastHeight = getKeyboardHeight(win);
|
|
1658
|
+
let ownPanTop = null;
|
|
1659
|
+
return {
|
|
1660
|
+
report(height) {
|
|
1661
|
+
const top = win.visualViewport?.offsetTop ?? 0;
|
|
1662
|
+
if (height !== lastHeight) {
|
|
1663
|
+
if (ownPanTop == null && lastHeight > 1 && watch.isRevealPan(height)) watch.putBack();
|
|
1664
|
+
lastHeight = height;
|
|
1665
|
+
watch.report();
|
|
1666
|
+
} else if (ownPanTop != null && Math.abs(top - ownPanTop) <= 1) {
|
|
1667
|
+
ownPanTop = null;
|
|
1668
|
+
watch.report();
|
|
1669
|
+
} else if (watch.isRevealPan(height)) watch.putBack();
|
|
1670
|
+
},
|
|
1671
|
+
expectPan(top) {
|
|
1672
|
+
ownPanTop = top;
|
|
1673
|
+
},
|
|
1674
|
+
stop: () => watch.stop()
|
|
1675
|
+
};
|
|
1676
|
+
}
|
|
1677
|
+
function panIntoView(field, offset, win, pans) {
|
|
1678
|
+
const viewport = win.visualViewport;
|
|
1679
|
+
if (viewport == null) return false;
|
|
1680
|
+
const box = field.getBoundingClientRect();
|
|
1681
|
+
const need = box.bottom + offset - (viewport.offsetTop + viewport.height);
|
|
1682
|
+
if (need <= 1) return true;
|
|
1683
|
+
const room = layoutViewportHeight(win) - viewport.offsetTop - viewport.height;
|
|
1684
|
+
const pan = Math.min(need, room, box.top - viewport.offsetTop);
|
|
1685
|
+
if (pan <= 1) return false;
|
|
1686
|
+
const top = viewport.offsetTop + pan;
|
|
1687
|
+
pans.expectPan(top);
|
|
1688
|
+
panVisualViewportTo(win, top);
|
|
1689
|
+
return pan >= need - 1;
|
|
1690
|
+
}
|
|
1691
|
+
function revealWithKeyboard(region, field, scroller, offset, win, unplaced = "keep") {
|
|
1692
|
+
const doc = scroller.ownerDocument;
|
|
1693
|
+
const root = doc.scrollingElement ?? doc.documentElement;
|
|
1694
|
+
let isPlaced = true;
|
|
1695
|
+
let hasRevealed = false;
|
|
1696
|
+
let startsAtReveal = 0;
|
|
1697
|
+
const pans = watchPans(win, (focused) => focused === field() && isPlaced);
|
|
1698
|
+
const revealNow = (height) => {
|
|
1699
|
+
const focused = field();
|
|
1700
|
+
if (focused == null) return;
|
|
1701
|
+
hasRevealed = height > 1;
|
|
1702
|
+
startsAtReveal = getTouches(win).starts;
|
|
1703
|
+
const rising = reveal(focused, scroller, height, offset, win);
|
|
1704
|
+
if (unplaced === "keep") return;
|
|
1705
|
+
isPlaced = rising !== 0 || sitsInBand(focused, scroller, height, offset, win);
|
|
1706
|
+
if (isPlaced || height <= 1) return;
|
|
1707
|
+
if (unplaced === "document") {
|
|
1708
|
+
if (scroller !== root && reveal(focused, root, height, offset, win) !== 0) {
|
|
1709
|
+
isPlaced = true;
|
|
1710
|
+
return;
|
|
1711
|
+
}
|
|
1712
|
+
} else {
|
|
1713
|
+
const top = focused.getBoundingClientRect().top;
|
|
1714
|
+
const scrollY = win.scrollY;
|
|
1715
|
+
reveal(focused, root, height, offset, win, false);
|
|
1716
|
+
if (Math.abs(focused.getBoundingClientRect().top - top) <= 1) {
|
|
1717
|
+
const scrolled = win.scrollY - scrollY;
|
|
1718
|
+
if (scrolled !== 0) {
|
|
1719
|
+
const before = win.scrollY;
|
|
1720
|
+
win.scrollBy({
|
|
1721
|
+
top: -scrolled,
|
|
1722
|
+
behavior: "instant"
|
|
1723
|
+
});
|
|
1724
|
+
noteKeyboardScroll(root, before, win);
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
isPlaced = panIntoView(focused, offset, win, pans);
|
|
1729
|
+
};
|
|
1730
|
+
let lastHeight = getKeyboardHeight(win);
|
|
1731
|
+
const isLaterPressDown = () => isFingerOnScreen(win) && getTouches(win).starts !== startsAtReveal;
|
|
1732
|
+
const stopReports = subscribeKeyboardHeight(win, (event) => {
|
|
1733
|
+
if (event.type === "viewport") {
|
|
1734
|
+
if (Math.abs(event.height - lastHeight) > 1) {
|
|
1735
|
+
lastHeight = event.height;
|
|
1736
|
+
if (!hasRevealed || !isLaterPressDown()) revealNow(event.height);
|
|
1737
|
+
}
|
|
1738
|
+
pans.report(event.height);
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
1741
|
+
const onFocusIn = () => {
|
|
1742
|
+
stopKeyboardScrollBack(win);
|
|
1743
|
+
revealNow(getKeyboardHeight(win));
|
|
1744
|
+
};
|
|
1745
|
+
region.addEventListener("focusin", onFocusIn);
|
|
1746
|
+
revealNow(getKeyboardHeight(win));
|
|
1747
|
+
return () => {
|
|
1748
|
+
stopReports();
|
|
1749
|
+
pans.stop();
|
|
1750
|
+
region.removeEventListener("focusin", onFocusIn);
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
//#endregion
|
|
1754
|
+
//#region src/keyboard/rideKeyboard.ts
|
|
1755
|
+
/**
|
|
1756
|
+
* Moves `animator`'s element to `to` with the keyboard: on its curve from
|
|
1757
|
+
* `transition.start`, or at once when the keyboard jumps.
|
|
1758
|
+
*
|
|
1759
|
+
* Android's keyboard moves on Gboard's slides up and down
|
|
1760
|
+
* (motion/android/keyboard.ts). The transition publishes the slide
|
|
1761
|
+
* (`curve`), and the ride plays it. Every ride starts at the transition's
|
|
1762
|
+
* start, so content that joins a slide late lands where the keyboard is. A
|
|
1763
|
+
* transition that is not animated lands at once, such as a keyboard changing
|
|
1764
|
+
* while up. So does a slide that has ended by the call. These values are the
|
|
1765
|
+
* keyboard's own motion, with no motion role. The system moves the keyboard
|
|
1766
|
+
* on them whatever the page does, so any other curve would leave the element
|
|
1767
|
+
* out of step.
|
|
1768
|
+
*
|
|
1769
|
+
* @example
|
|
1770
|
+
* ```
|
|
1771
|
+
* guide.subscribe(t => rideKeyboard(dock.animator, {y: -lift(t.to)}, t));
|
|
1772
|
+
* ```
|
|
1773
|
+
*/
|
|
1774
|
+
function rideKeyboard(animator, to, transition, { entrance = false } = {}) {
|
|
1775
|
+
if (!transition.animated || transition.curve == null || performance.now() >= transition.start + transition.curve.durationMs) {
|
|
1776
|
+
animator.set(to);
|
|
1777
|
+
return null;
|
|
1778
|
+
}
|
|
1779
|
+
const options = entrance ? {
|
|
1780
|
+
at: transition.start,
|
|
1781
|
+
crossfadeAs: "entrance"
|
|
1782
|
+
} : { at: transition.start };
|
|
1783
|
+
const span = transition.curve.durationMs / 1e3;
|
|
1784
|
+
const ease = cubicBezier(transition.curve.points);
|
|
1785
|
+
const curves = {};
|
|
1786
|
+
for (const [property, target] of Object.entries(to)) {
|
|
1787
|
+
const from = animator.get(property, transition.start);
|
|
1788
|
+
const at = (t) => from + (target - from) * ease(Math.min(1, Math.max(0, t / span)));
|
|
1789
|
+
curves[property] = {
|
|
1790
|
+
duration: span,
|
|
1791
|
+
at,
|
|
1792
|
+
velocity: (t) => {
|
|
1793
|
+
if (t >= span) return 0;
|
|
1794
|
+
const a = Math.max(0, t - .001);
|
|
1795
|
+
const b = Math.min(span, t + .001);
|
|
1796
|
+
return (at(b) - at(a)) / (b - a);
|
|
1797
|
+
}
|
|
1798
|
+
};
|
|
1799
|
+
}
|
|
1800
|
+
return animator.play(curves, options);
|
|
1801
|
+
}
|
|
1802
|
+
//#endregion
|
|
1803
|
+
//#region src/keyboard/keyboardRide.ts
|
|
1804
|
+
function liftFor(target, animator, height, offset, win, isHostOwned) {
|
|
1805
|
+
if (!isHostOwned && (!isDockedContainer(target) || isMovedByApp(target))) return 0;
|
|
1806
|
+
const targetCovered = coveredBy(restingBottom(target, animator), height, 0, win);
|
|
1807
|
+
const field = focusedFieldIn(target);
|
|
1808
|
+
if (field != null) {
|
|
1809
|
+
if (!isHostOwned) return targetCovered;
|
|
1810
|
+
const fieldCovered = coveredBy(restingBottom(field, animator), height, offset, win);
|
|
1811
|
+
return Math.max(targetCovered, fieldCovered);
|
|
1812
|
+
}
|
|
1813
|
+
if (isTextEntryControl(target.ownerDocument.activeElement)) return 0;
|
|
1814
|
+
return animator.get("y") < 0 ? targetCovered : 0;
|
|
1815
|
+
}
|
|
1816
|
+
function exceedsRoom(container, height, win) {
|
|
1817
|
+
return height > 1 && container.getBoundingClientRect().height > layoutViewportHeight(win) - height + 1;
|
|
1818
|
+
}
|
|
1819
|
+
function focusedScrollerIn(container) {
|
|
1820
|
+
const field = focusedFieldIn(container);
|
|
1821
|
+
const scroller = field == null ? null : scrollingAncestor(field, container);
|
|
1822
|
+
return field == null || scroller == null ? null : {
|
|
1823
|
+
field,
|
|
1824
|
+
scroller
|
|
1825
|
+
};
|
|
1826
|
+
}
|
|
1827
|
+
function fieldLift(target, animator, height, offset, win) {
|
|
1828
|
+
if (!isDockedContainer(target) || isMovedByApp(target)) return 0;
|
|
1829
|
+
const overlap = coveredBy(restingBottom(target, animator), height, 0, win);
|
|
1830
|
+
const field = focusedFieldIn(target);
|
|
1831
|
+
if (field == null) return isTextEntryControl(target.ownerDocument.activeElement) ? 0 : Math.min(Math.max(0, -animator.get("y")), overlap);
|
|
1832
|
+
const need = coveredBy(restingBottom(field, animator), height, offset, win);
|
|
1833
|
+
return Math.min(need, overlap);
|
|
1834
|
+
}
|
|
1835
|
+
function clearanceAtReport(target, animator, height, win) {
|
|
1836
|
+
const field = focusedFieldIn(target);
|
|
1837
|
+
if (field == null) return null;
|
|
1838
|
+
const need = coveredBy(restingBottom(field, animator), height, 4, win);
|
|
1839
|
+
return need > 0 ? -need : null;
|
|
1840
|
+
}
|
|
1841
|
+
const currentRides = sharedWeakMap("keyboard/keyboard-target/current-rides", 1);
|
|
1842
|
+
function rideWithKeyboard(target, offset, win, isHostOwned) {
|
|
1843
|
+
currentRides.get(target)?.();
|
|
1844
|
+
const animator = animatorFor(target);
|
|
1845
|
+
riddenAnimators.set(target, animator);
|
|
1846
|
+
const guide = keyboardProfileOf(win) === "chromium" ? getKeyboardLayoutGuide(win) : null;
|
|
1847
|
+
let state = "riding";
|
|
1848
|
+
let stopReports = null;
|
|
1849
|
+
let stopGuide = null;
|
|
1850
|
+
const pans = watchPans(win, (focused) => target.contains(focused), guide != null);
|
|
1851
|
+
let frame = 0;
|
|
1852
|
+
let pendingSlide = null;
|
|
1853
|
+
let stopFocusIns = () => {};
|
|
1854
|
+
const end = () => {
|
|
1855
|
+
state = "ended";
|
|
1856
|
+
stopReports?.();
|
|
1857
|
+
stopGuide?.();
|
|
1858
|
+
stopReports = null;
|
|
1859
|
+
stopGuide = null;
|
|
1860
|
+
pans.stop();
|
|
1861
|
+
stopFocusIns();
|
|
1862
|
+
if (frame !== 0) {
|
|
1863
|
+
win.cancelAnimationFrame(frame);
|
|
1864
|
+
frame = 0;
|
|
1865
|
+
}
|
|
1866
|
+
if (currentRides.get(target) === end) currentRides.delete(target);
|
|
1867
|
+
};
|
|
1868
|
+
currentRides.set(target, end);
|
|
1869
|
+
const place = (height, transition) => {
|
|
1870
|
+
if (state === "ended") return;
|
|
1871
|
+
const isTooTall = !isHostOwned && exceedsRoom(target, height, win);
|
|
1872
|
+
const inside = isTooTall ? focusedScrollerIn(target) : null;
|
|
1873
|
+
const lift = !isTooTall ? liftFor(target, animator, height, offset, win, isHostOwned) : inside == null ? fieldLift(target, animator, height, offset, win) : 0;
|
|
1874
|
+
const y = lift > 0 ? -lift : 0;
|
|
1875
|
+
const revealBy = inside == null ? 0 : revealDistance(inside.field, inside.scroller, height, offset, win, y - animator.get("y"));
|
|
1876
|
+
if (inside != null && Math.abs(revealBy) > 1) scrollBy(inside.scroller, revealBy, win);
|
|
1877
|
+
if (y !== 0 || animator.get("y") !== 0) {
|
|
1878
|
+
if (transition == null) animator.set({ y });
|
|
1879
|
+
else {
|
|
1880
|
+
const atReport = transition.kind === "show" ? clearanceAtReport(target, animator, height, win) : null;
|
|
1881
|
+
if (atReport != null && y < atReport && atReport < animator.get("y")) animator.set({ y: atReport });
|
|
1882
|
+
rideKeyboard(animator, { y }, transition);
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
if (state === "waiting" && height <= 1) end();
|
|
1886
|
+
};
|
|
1887
|
+
const placeOnNextFrame = (slide) => {
|
|
1888
|
+
if (slide != null) pendingSlide = slide;
|
|
1889
|
+
if (frame !== 0) return;
|
|
1890
|
+
frame = win.requestAnimationFrame(() => {
|
|
1891
|
+
frame = 0;
|
|
1892
|
+
const next = pendingSlide;
|
|
1893
|
+
pendingSlide = null;
|
|
1894
|
+
place(next?.to ?? guide?.inset ?? getKeyboardHeight(win), next);
|
|
1895
|
+
});
|
|
1896
|
+
};
|
|
1897
|
+
stopReports = subscribeKeyboardHeight(win, (event) => {
|
|
1898
|
+
if (event.type === "viewport") {
|
|
1899
|
+
if (guide == null) placeOnNextFrame(null);
|
|
1900
|
+
pans.report(event.height);
|
|
1901
|
+
}
|
|
1902
|
+
});
|
|
1903
|
+
if (guide != null) stopGuide = guide.subscribe(placeOnNextFrame);
|
|
1904
|
+
stopFocusIns = subscribeInput(win, "focusin", () => placeOnNextFrame(null));
|
|
1905
|
+
placeOnNextFrame(null);
|
|
1906
|
+
return (isFinal = false) => {
|
|
1907
|
+
if (state === "ended") return;
|
|
1908
|
+
if (isFinal || getKeyboardHeight(win) <= 1) {
|
|
1909
|
+
end();
|
|
1910
|
+
if (animator.get("y") !== 0) animator.set({ y: 0 });
|
|
1911
|
+
} else state = "waiting";
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
//#endregion
|
|
1915
|
+
//#region src/keyboard/keyboardTarget.ts
|
|
1916
|
+
/**
|
|
1917
|
+
* Keeps the focused field inside `target` above the keyboard until the
|
|
1918
|
+
* returned call. `'ride'` moves `target` with the keyboard, on its slide
|
|
1919
|
+
* where the browser reports one. `'reveal'` scrolls the field into place in
|
|
1920
|
+
* `target`, a scroller. The target claims focus moves into its fields, so the
|
|
1921
|
+
* browser never pans the page to them, and it registers as a keyboard target.
|
|
1922
|
+
*
|
|
1923
|
+
* @example
|
|
1924
|
+
* ```
|
|
1925
|
+
* const stop = followKeyboard(dock, {move: 'ride', offset: FIELD_OFFSET});
|
|
1926
|
+
* ```
|
|
1927
|
+
*/
|
|
1928
|
+
function followKeyboard(target, { move, offset }) {
|
|
1929
|
+
const doc = target.ownerDocument;
|
|
1930
|
+
const win = doc.defaultView;
|
|
1931
|
+
if (!followsKeyboard(win)) return () => {};
|
|
1932
|
+
const unregister = registerKeyboardTarget(target);
|
|
1933
|
+
const stopScrollBack = claimKeyboardScrollBack(win);
|
|
1934
|
+
const stopClaim = refuseFocusReveal(doc, { claim: (destination) => destination instanceof win.HTMLElement && destination !== target && target.contains(destination) && isTextEntryControl(destination) ? destination : null });
|
|
1935
|
+
const stopTaps = claimTapFocus(target, {
|
|
1936
|
+
claim: (touched) => {
|
|
1937
|
+
const control = findTextEntryControl(touched, target);
|
|
1938
|
+
return control != null && control !== doc.activeElement ? control : null;
|
|
1939
|
+
},
|
|
1940
|
+
deliver: deliverTap
|
|
1941
|
+
});
|
|
1942
|
+
const stopMoving = move === "ride" ? rideWithKeyboard(target, offset, win, true) : revealWithKeyboard(target, () => focusedFieldIn(target), target, offset, win);
|
|
1943
|
+
return () => {
|
|
1944
|
+
stopMoving(true);
|
|
1945
|
+
stopTaps();
|
|
1946
|
+
stopClaim();
|
|
1947
|
+
stopScrollBack();
|
|
1948
|
+
unregister();
|
|
1949
|
+
};
|
|
1950
|
+
}
|
|
1951
|
+
function canBringUp(field, scroller, offset, win) {
|
|
1952
|
+
const range = scroller.scrollHeight - scroller.clientHeight - scroller.scrollTop;
|
|
1953
|
+
const box = field.getBoundingClientRect();
|
|
1954
|
+
if (range < box.top - scroller.getBoundingClientRect().top - 1) return false;
|
|
1955
|
+
const height = getKeyboardHeight(win);
|
|
1956
|
+
if (height <= 1) return true;
|
|
1957
|
+
const band = bandOf(scroller, height, offset, win);
|
|
1958
|
+
return band.bottom - band.top >= box.height - 1;
|
|
1959
|
+
}
|
|
1960
|
+
function placementOf(field, offset, win) {
|
|
1961
|
+
if (isInsideKeyboardTarget(field)) return null;
|
|
1962
|
+
const container = fixedContainerOf(field);
|
|
1963
|
+
if (container === "floating" || container === "fills-viewport") return revealWithin(field, nearestFixedAncestor(field), offset, win);
|
|
1964
|
+
if (container == null) {
|
|
1965
|
+
const scroller = nearestScroller(field);
|
|
1966
|
+
return scroller.scrollHeight > scroller.clientHeight ? {
|
|
1967
|
+
reveal: scroller,
|
|
1968
|
+
unplaced: "document"
|
|
1969
|
+
} : null;
|
|
1970
|
+
}
|
|
1971
|
+
const view = field.ownerDocument.defaultView;
|
|
1972
|
+
return view != null && hasOwnTranslate(container.docked, view) ? revealWithin(field, container.docked, offset, win) : { ride: container.docked };
|
|
1973
|
+
}
|
|
1974
|
+
function revealWithin(field, container, offset, win) {
|
|
1975
|
+
const scroller = container == null ? null : scrollingAncestor(field, container);
|
|
1976
|
+
return scroller == null || !canBringUp(field, scroller, offset, win) ? null : {
|
|
1977
|
+
reveal: scroller,
|
|
1978
|
+
unplaced: "fixed"
|
|
1979
|
+
};
|
|
1980
|
+
}
|
|
1981
|
+
/**
|
|
1982
|
+
* Keeps `field` above the on-screen keyboard until the returned call. On focus,
|
|
1983
|
+
* `placementOf` decides who moves it. A claimed focus move or tap arrives
|
|
1984
|
+
* without the browser's reveal. Where no placement fits, the browser's own
|
|
1985
|
+
* reveal stays.
|
|
1986
|
+
*
|
|
1987
|
+
* @example
|
|
1988
|
+
* ```
|
|
1989
|
+
* const stop = keepFieldAboveKeyboard(input);
|
|
1990
|
+
* ```
|
|
1991
|
+
*/
|
|
1992
|
+
function keepFieldAboveKeyboard(field, { offset = 10 } = {}) {
|
|
1993
|
+
const doc = field.ownerDocument;
|
|
1994
|
+
const win = doc.defaultView;
|
|
1995
|
+
if (!followsKeyboard(win)) return () => {};
|
|
1996
|
+
const stopScrollBack = claimKeyboardScrollBack(win);
|
|
1997
|
+
const stopClaim = refuseFocusReveal(doc, { claim: (destination) => destination === field && placementOf(field, offset, win) != null ? field : null });
|
|
1998
|
+
const stopTaps = claimTapFocus(field, {
|
|
1999
|
+
claim: () => doc.activeElement !== field && placementOf(field, offset, win) != null ? field : null,
|
|
2000
|
+
deliver: deliverTap
|
|
2001
|
+
});
|
|
2002
|
+
let stopSession = null;
|
|
2003
|
+
let stoppedSession = null;
|
|
2004
|
+
const onFocus = () => {
|
|
2005
|
+
if (stopSession != null) return;
|
|
2006
|
+
const placement = placementOf(field, offset, win);
|
|
2007
|
+
if (placement == null) return;
|
|
2008
|
+
stopKeyboardScrollBack(win);
|
|
2009
|
+
stopSession = "ride" in placement ? rideWithKeyboard(placement.ride, offset, win, false) : revealWithKeyboard(field, () => doc.activeElement === field ? field : null, placement.reveal, offset, win, placement.unplaced);
|
|
2010
|
+
};
|
|
2011
|
+
const onBlur = () => {
|
|
2012
|
+
stopSession?.();
|
|
2013
|
+
stoppedSession = stopSession ?? stoppedSession;
|
|
2014
|
+
stopSession = null;
|
|
2015
|
+
};
|
|
2016
|
+
field.addEventListener("focus", onFocus);
|
|
2017
|
+
field.addEventListener("blur", onBlur);
|
|
2018
|
+
if (doc.activeElement === field) onFocus();
|
|
2019
|
+
return () => {
|
|
2020
|
+
field.removeEventListener("focus", onFocus);
|
|
2021
|
+
field.removeEventListener("blur", onBlur);
|
|
2022
|
+
stopSession?.(true);
|
|
2023
|
+
stoppedSession?.(true);
|
|
2024
|
+
stopSession = null;
|
|
2025
|
+
stoppedSession = null;
|
|
2026
|
+
stopTaps();
|
|
2027
|
+
stopClaim();
|
|
2028
|
+
stopScrollBack();
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
//#endregion
|
|
2032
|
+
//#region src/keyboard/sheetKeyboardBody.ts
|
|
2033
|
+
/**
|
|
2034
|
+
* The custom property on the body's content box that holds the keyboard's
|
|
2035
|
+
* inset, CSS px. The sheet's stylesheet lays it out as the content box's
|
|
2036
|
+
* `::after` block size, after the content's own children.
|
|
2037
|
+
*/
|
|
2038
|
+
const KEYBOARD_INSET_PROPERTY = "--_keyboard-inset";
|
|
2039
|
+
/** The keyboard's top in the layout viewport, CSS px. */
|
|
2040
|
+
function getObstructionTop() {
|
|
2041
|
+
return layoutViewportHeight(window) - getKeyboardHeight(window);
|
|
2042
|
+
}
|
|
2043
|
+
function overlapOf(bodyBottom, obstructionTop) {
|
|
2044
|
+
const overlap = bodyBottom - obstructionTop;
|
|
2045
|
+
return overlap > 1 ? overlap : 0;
|
|
2046
|
+
}
|
|
2047
|
+
function isVisualViewportRecovered() {
|
|
2048
|
+
return getKeyboardHeight(window) <= .5;
|
|
2049
|
+
}
|
|
2050
|
+
function mayKeepKeyboard() {
|
|
2051
|
+
const target = deepActiveElement(document);
|
|
2052
|
+
return target != null && (bringsUpKeyboard(target) || hidesField(target));
|
|
2053
|
+
}
|
|
2054
|
+
/** The focused text-entry control inside `body`, if any. */
|
|
2055
|
+
function focusedControlIn(body) {
|
|
2056
|
+
const active = document.activeElement;
|
|
2057
|
+
return active instanceof HTMLElement && body.contains(active) && isTextEntryControl(active) ? active : null;
|
|
2058
|
+
}
|
|
2059
|
+
/** Creates the body's side of a sheet that reserves the keyboard's inset. */
|
|
2060
|
+
function createSheetKeyboardBody({ body, offset, isExpanded, layout, guide, ownsFocusTransitions, onInset }) {
|
|
2061
|
+
let laidOutInset = 0;
|
|
2062
|
+
let insetRange = 0;
|
|
2063
|
+
const content = () => {
|
|
2064
|
+
const first = body.firstElementChild;
|
|
2065
|
+
return first instanceof HTMLElement ? first : null;
|
|
2066
|
+
};
|
|
2067
|
+
const writeInset = (inset) => {
|
|
2068
|
+
const changes = inset !== laidOutInset;
|
|
2069
|
+
const rangeBefore = changes ? body.scrollHeight : 0;
|
|
2070
|
+
laidOutInset = inset;
|
|
2071
|
+
const box = content();
|
|
2072
|
+
const value = inset > 0 ? `${inset}px` : "";
|
|
2073
|
+
if (box != null && box.style.getPropertyValue("--_keyboard-inset") !== value) {
|
|
2074
|
+
if (inset > 0) box.style.setProperty(KEYBOARD_INSET_PROPERTY, value);
|
|
2075
|
+
else box.style.removeProperty(KEYBOARD_INSET_PROPERTY);
|
|
2076
|
+
}
|
|
2077
|
+
onInset(inset);
|
|
2078
|
+
if (changes) insetRange = inset === 0 ? 0 : Math.max(0, insetRange + body.scrollHeight - rangeBefore);
|
|
2079
|
+
};
|
|
2080
|
+
const self = {
|
|
2081
|
+
keyboardGeometry: null,
|
|
2082
|
+
smoothTarget: null,
|
|
2083
|
+
documentScrollAtKeyboard: null,
|
|
2084
|
+
keyboardObstructionTop: null,
|
|
2085
|
+
bodyScrollTopAtKeyboard: null,
|
|
2086
|
+
writeInset,
|
|
2087
|
+
clearKeyboardLayout: () => {
|
|
2088
|
+
writeInset(0);
|
|
2089
|
+
if (self.bodyScrollTopAtKeyboard != null) {
|
|
2090
|
+
self.smoothTarget = null;
|
|
2091
|
+
body.scrollTop = self.bodyScrollTopAtKeyboard;
|
|
2092
|
+
}
|
|
2093
|
+
self.keyboardGeometry = null;
|
|
2094
|
+
self.keyboardObstructionTop = null;
|
|
2095
|
+
self.bodyScrollTopAtKeyboard = null;
|
|
2096
|
+
self.documentScrollAtKeyboard = null;
|
|
2097
|
+
layout.hasLayout = false;
|
|
2098
|
+
layout.retainLayout = false;
|
|
2099
|
+
},
|
|
2100
|
+
scrollControlIntoSafeArea: (control, smoothly, ride = null) => {
|
|
2101
|
+
const measuredBodyRect = body.getBoundingClientRect();
|
|
2102
|
+
const measuredControlRect = control.getBoundingClientRect();
|
|
2103
|
+
const obstructionTop = getObstructionTop();
|
|
2104
|
+
const clearance = overlapOf(measuredBodyRect.bottom, obstructionTop) > 0 ? offset : 0;
|
|
2105
|
+
const safeTop = measuredBodyRect.top;
|
|
2106
|
+
const safeBottom = Math.min(measuredBodyRect.bottom, obstructionTop - clearance);
|
|
2107
|
+
const pending = self.smoothDistanceLeft() + self.rideOffset();
|
|
2108
|
+
const controlBottom = measuredControlRect.bottom - pending;
|
|
2109
|
+
const distance = distanceIntoBand(measuredControlRect.top - pending, controlBottom, safeTop, safeBottom);
|
|
2110
|
+
if (distance > 0) scrollBodyBy(distance, smoothly, ride, Math.max(0, obstructionTop - safeBottom - 4));
|
|
2111
|
+
else if (distance < 0) scrollBodyBy(distance, smoothly, ride);
|
|
2112
|
+
},
|
|
2113
|
+
smoothDistanceLeft: () => {
|
|
2114
|
+
if (self.smoothTarget == null) return 0;
|
|
2115
|
+
const maxScroll = Math.max(body.scrollTop, body.scrollHeight - body.clientHeight);
|
|
2116
|
+
const left = Math.min(self.smoothTarget, maxScroll) - body.scrollTop;
|
|
2117
|
+
return Math.abs(left) < 1 ? 0 : left;
|
|
2118
|
+
},
|
|
2119
|
+
applyKeyboardGeometry: (geometry) => {
|
|
2120
|
+
const obstructionTop = getObstructionTop();
|
|
2121
|
+
if (isVisualViewportRecovered()) {
|
|
2122
|
+
self.clearKeyboardLayout();
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
if (overlapOf(geometry.bodyBottom, obstructionTop) === 0) {
|
|
2126
|
+
self.clearKeyboardLayout();
|
|
2127
|
+
return;
|
|
2128
|
+
}
|
|
2129
|
+
writeInset(Math.max(0, geometry.bodyBottom - (obstructionTop - offset)));
|
|
2130
|
+
},
|
|
2131
|
+
restingScrollTop: () => {
|
|
2132
|
+
const scrollTop = body.scrollTop;
|
|
2133
|
+
const maxAtRest = Math.max(0, body.scrollHeight - insetRange - body.clientHeight);
|
|
2134
|
+
let resting = Math.min(maxAtRest, self.bodyScrollTopAtKeyboard ?? scrollTop);
|
|
2135
|
+
const active = focusedControlIn(body);
|
|
2136
|
+
if (isExpanded() && active != null) {
|
|
2137
|
+
const bodyRect = body.getBoundingClientRect();
|
|
2138
|
+
const rect = active.getBoundingClientRect();
|
|
2139
|
+
const shift = scrollTop - resting - self.rideOffset();
|
|
2140
|
+
if (rect.bottom + shift > bodyRect.bottom) resting += rect.bottom + shift - bodyRect.bottom;
|
|
2141
|
+
else if (rect.top + shift < bodyRect.top) resting += rect.top + shift - bodyRect.top;
|
|
2142
|
+
resting = Math.min(maxAtRest, Math.max(0, resting));
|
|
2143
|
+
}
|
|
2144
|
+
return resting;
|
|
2145
|
+
},
|
|
2146
|
+
contentAnimator: () => {
|
|
2147
|
+
const box = content();
|
|
2148
|
+
return guide != null && box != null ? animatorFor(box) : null;
|
|
2149
|
+
},
|
|
2150
|
+
unguidedAnimator: () => {
|
|
2151
|
+
const box = content();
|
|
2152
|
+
return ownsFocusTransitions && guide == null && box != null ? animatorFor(box) : null;
|
|
2153
|
+
},
|
|
2154
|
+
rideOffset: () => {
|
|
2155
|
+
const box = content();
|
|
2156
|
+
return box != null ? drawnOffsetOf(box) : 0;
|
|
2157
|
+
},
|
|
2158
|
+
showOnSlide: (atReport) => {
|
|
2159
|
+
const transition = guide?.transition;
|
|
2160
|
+
return transition != null && transition.kind === "show" && transition.animated && transition.curve != null && (atReport || performance.now() < transition.start + transition.curve.durationMs) ? transition : null;
|
|
2161
|
+
}
|
|
2162
|
+
};
|
|
2163
|
+
function scrollBodyBy(distance, smoothly, ride = null, within = null) {
|
|
2164
|
+
self.smoothTarget = null;
|
|
2165
|
+
const animator = ride == null ? null : self.contentAnimator();
|
|
2166
|
+
if (ride != null && animator != null) {
|
|
2167
|
+
const before = body.scrollTop;
|
|
2168
|
+
body.scrollTop = before + distance;
|
|
2169
|
+
const moved = body.scrollTop - before;
|
|
2170
|
+
if (moved !== 0) {
|
|
2171
|
+
const from = animator.get("y", ride.start) + moved;
|
|
2172
|
+
animator.set({ y: within == null ? from : Math.min(from, within) });
|
|
2173
|
+
rideKeyboard(animator, { y: 0 }, ride, { entrance: within != null });
|
|
2174
|
+
}
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2177
|
+
if (typeof body.scrollBy !== "function") {
|
|
2178
|
+
body.scrollTop += distance;
|
|
2179
|
+
return;
|
|
2180
|
+
}
|
|
2181
|
+
const reduceMotion = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
2182
|
+
const behavior = smoothly && !reduceMotion ? "smooth" : "instant";
|
|
2183
|
+
if (behavior === "smooth") self.smoothTarget = body.scrollTop + distance;
|
|
2184
|
+
body.scrollBy({
|
|
2185
|
+
top: distance,
|
|
2186
|
+
behavior
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
return self;
|
|
2190
|
+
}
|
|
2191
|
+
//#endregion
|
|
2192
|
+
//#region src/keyboard/sheetKeyboardHold.ts
|
|
2193
|
+
function rideKeyboardSpring(animator, y) {
|
|
2194
|
+
return animator.animate({ y }, { spring: KEYBOARD_SPRING });
|
|
2195
|
+
}
|
|
2196
|
+
/** Creates how a sheet's content moves while the keyboard goes. */
|
|
2197
|
+
function createSheetKeyboardHolds({ body, keyboard, layout, guide, reveal }) {
|
|
2198
|
+
let heldHide = null;
|
|
2199
|
+
const keepDrawnPlace = () => {
|
|
2200
|
+
const animator = keyboard.unguidedAnimator();
|
|
2201
|
+
if (animator == null) return () => {};
|
|
2202
|
+
const drawnBefore = animator.get("y") - body.scrollTop;
|
|
2203
|
+
return () => {
|
|
2204
|
+
const y = drawnBefore + body.scrollTop;
|
|
2205
|
+
if (Math.abs(y - animator.get("y")) < .5) return;
|
|
2206
|
+
animator.set({ y });
|
|
2207
|
+
rideKeyboardSpring(animator, 0);
|
|
2208
|
+
};
|
|
2209
|
+
};
|
|
2210
|
+
const holdThroughUnguidedHide = () => {
|
|
2211
|
+
const animator = keyboard.unguidedAnimator();
|
|
2212
|
+
if (animator == null || heldHide != null) return;
|
|
2213
|
+
const drop = body.scrollTop - keyboard.restingScrollTop();
|
|
2214
|
+
if (drop === 0) return;
|
|
2215
|
+
const hold = {
|
|
2216
|
+
release: () => {
|
|
2217
|
+
if (heldHide === hold) heldHide = null;
|
|
2218
|
+
},
|
|
2219
|
+
onReveal: () => {
|
|
2220
|
+
const active = document.activeElement;
|
|
2221
|
+
if (active instanceof HTMLElement && body.contains(active) && mayKeepKeyboard()) {
|
|
2222
|
+
hold.release();
|
|
2223
|
+
rideKeyboardSpring(animator, 0);
|
|
2224
|
+
return true;
|
|
2225
|
+
}
|
|
2226
|
+
if (isVisualViewportRecovered()) {
|
|
2227
|
+
hold.release();
|
|
2228
|
+
const y = animator.get("y");
|
|
2229
|
+
const velocity = animator.getVelocity("y");
|
|
2230
|
+
const scrollBefore = body.scrollTop;
|
|
2231
|
+
keyboard.clearKeyboardLayout();
|
|
2232
|
+
const shift = scrollBefore - body.scrollTop;
|
|
2233
|
+
if (Math.abs(y - shift) < .5) animator.set({ y: 0 });
|
|
2234
|
+
else {
|
|
2235
|
+
animator.set({ y: y - shift });
|
|
2236
|
+
animator.animate({ y: 0 }, {
|
|
2237
|
+
spring: KEYBOARD_SPRING,
|
|
2238
|
+
velocity: { y: velocity }
|
|
2239
|
+
});
|
|
2240
|
+
}
|
|
2241
|
+
}
|
|
2242
|
+
return false;
|
|
2243
|
+
}
|
|
2244
|
+
};
|
|
2245
|
+
heldHide = hold;
|
|
2246
|
+
rideKeyboardSpring(animator, drop);
|
|
2247
|
+
};
|
|
2248
|
+
const holdInsetThrough = (transition) => {
|
|
2249
|
+
heldHide?.release();
|
|
2250
|
+
const animator = keyboard.contentAnimator();
|
|
2251
|
+
const drop = body.scrollTop - keyboard.restingScrollTop();
|
|
2252
|
+
const handle = animator != null && drop !== 0 ? rideKeyboard(animator, { y: drop }, transition) : null;
|
|
2253
|
+
let timer;
|
|
2254
|
+
let landed = false;
|
|
2255
|
+
const commit = () => {
|
|
2256
|
+
reveal();
|
|
2257
|
+
animator?.set({ y: 0 });
|
|
2258
|
+
};
|
|
2259
|
+
const hold = {
|
|
2260
|
+
release: () => {
|
|
2261
|
+
clearTimeout(timer);
|
|
2262
|
+
if (heldHide === hold) heldHide = null;
|
|
2263
|
+
},
|
|
2264
|
+
onReveal: () => {
|
|
2265
|
+
if (landed && isVisualViewportRecovered()) {
|
|
2266
|
+
hold.release();
|
|
2267
|
+
commit();
|
|
2268
|
+
}
|
|
2269
|
+
return false;
|
|
2270
|
+
}
|
|
2271
|
+
};
|
|
2272
|
+
heldHide = hold;
|
|
2273
|
+
const land = () => {
|
|
2274
|
+
if (heldHide !== hold) return;
|
|
2275
|
+
landed = true;
|
|
2276
|
+
if (layout.hasLayout && !isVisualViewportRecovered()) return;
|
|
2277
|
+
hold.release();
|
|
2278
|
+
commit();
|
|
2279
|
+
};
|
|
2280
|
+
if (handle == null) {
|
|
2281
|
+
const end = transition.start + (transition.curve?.durationMs ?? 0);
|
|
2282
|
+
timer = setTimeout(land, Math.max(0, end - performance.now()));
|
|
2283
|
+
} else handle.finished.then(land);
|
|
2284
|
+
};
|
|
2285
|
+
return {
|
|
2286
|
+
blocksReveal: () => heldHide != null && heldHide.onReveal?.() !== true,
|
|
2287
|
+
keepDrawnPlace,
|
|
2288
|
+
holdThroughUnguidedHide,
|
|
2289
|
+
followGuide: () => guide?.subscribe((transition) => {
|
|
2290
|
+
if (transition.curve == null) return;
|
|
2291
|
+
if (transition.kind === "hide") {
|
|
2292
|
+
if (layout.hasLayout && transition.animated) holdInsetThrough(transition);
|
|
2293
|
+
return;
|
|
2294
|
+
}
|
|
2295
|
+
if (heldHide != null) {
|
|
2296
|
+
heldHide.release();
|
|
2297
|
+
const animator = keyboard.contentAnimator();
|
|
2298
|
+
if (animator != null) rideKeyboard(animator, { y: 0 }, transition);
|
|
2299
|
+
}
|
|
2300
|
+
}) ?? (() => {}),
|
|
2301
|
+
stop: () => {
|
|
2302
|
+
heldHide?.release();
|
|
2303
|
+
(keyboard.contentAnimator() ?? keyboard.unguidedAnimator())?.set({ y: 0 });
|
|
2304
|
+
}
|
|
2305
|
+
};
|
|
2306
|
+
}
|
|
2307
|
+
//#endregion
|
|
2308
|
+
//#region src/keyboard/sheetKeyboard.ts
|
|
2309
|
+
const reveals = sharedState("keyboard/use-mobile-keyboard/reveals-at-report", 1, () => ({ atReport: /* @__PURE__ */ new WeakSet() }));
|
|
2310
|
+
/**
|
|
2311
|
+
* Keeps a focused field in `sheet`'s `body` above the on-screen keyboard.
|
|
2312
|
+
* Returns the release.
|
|
2313
|
+
*/
|
|
2314
|
+
function attachSheetKeyboard(sheet, body, { offset, isExpanded, isOpen, isPageScrollLocked, isTouch, layout, onInset }) {
|
|
2315
|
+
const unregister = registerKeyboardTarget(sheet);
|
|
2316
|
+
const guide = isTouch && keyboardProfileOf(window) === "chromium" ? getKeyboardLayoutGuide(window) : null;
|
|
2317
|
+
const ownsFocusTransitions = isTouch && isKeyboardMeasurable(window);
|
|
2318
|
+
const keyboard = createSheetKeyboardBody({
|
|
2319
|
+
body,
|
|
2320
|
+
offset,
|
|
2321
|
+
isExpanded,
|
|
2322
|
+
layout,
|
|
2323
|
+
guide,
|
|
2324
|
+
ownsFocusTransitions,
|
|
2325
|
+
onInset
|
|
2326
|
+
});
|
|
2327
|
+
const holds = createSheetKeyboardHolds({
|
|
2328
|
+
body,
|
|
2329
|
+
keyboard,
|
|
2330
|
+
layout,
|
|
2331
|
+
guide,
|
|
2332
|
+
reveal: () => revealFocusedControl()
|
|
2333
|
+
});
|
|
2334
|
+
const claimFocusTransitions = () => refuseFocusReveal(document, {
|
|
2335
|
+
isActive: isExpanded,
|
|
2336
|
+
claim: (destination) => findTextEntryControl(destination, body),
|
|
2337
|
+
park: (origin) => {
|
|
2338
|
+
if (isOpen() && findTextEntryControl(origin, body)) sheet.focus({ preventScroll: true });
|
|
2339
|
+
}
|
|
2340
|
+
});
|
|
2341
|
+
function revealFocusedControl(atReport = false) {
|
|
2342
|
+
if (holds.blocksReveal()) return;
|
|
2343
|
+
const obstructionTop = getObstructionTop();
|
|
2344
|
+
const focusedControl = focusedControlIn(body);
|
|
2345
|
+
if (layout.hasLayout && isVisualViewportRecovered()) {
|
|
2346
|
+
const settle = holds.keepDrawnPlace();
|
|
2347
|
+
keyboard.clearKeyboardLayout();
|
|
2348
|
+
if (isExpanded() && focusedControl != null) keyboard.scrollControlIntoSafeArea(focusedControl, false);
|
|
2349
|
+
settle();
|
|
2350
|
+
return;
|
|
2351
|
+
}
|
|
2352
|
+
if (!isExpanded() || focusedControl == null) {
|
|
2353
|
+
if (layout.retainLayout && keyboard.keyboardGeometry) {
|
|
2354
|
+
const settle = holds.keepDrawnPlace();
|
|
2355
|
+
keyboard.applyKeyboardGeometry(keyboard.keyboardGeometry);
|
|
2356
|
+
settle();
|
|
2357
|
+
if (isExpanded() && layout.hasLayout && !mayKeepKeyboard()) holds.holdThroughUnguidedHide();
|
|
2358
|
+
return;
|
|
2359
|
+
}
|
|
2360
|
+
keyboard.clearKeyboardLayout();
|
|
2361
|
+
return;
|
|
2362
|
+
}
|
|
2363
|
+
if (layout.hasLayout && keyboard.keyboardObstructionTop != null && obstructionTop > keyboard.keyboardObstructionTop + .5 && keyboard.bodyScrollTopAtKeyboard != null) {
|
|
2364
|
+
keyboard.smoothTarget = null;
|
|
2365
|
+
body.scrollTop = keyboard.bodyScrollTopAtKeyboard;
|
|
2366
|
+
keyboard.keyboardObstructionTop = obstructionTop;
|
|
2367
|
+
}
|
|
2368
|
+
layout.retainLayout = false;
|
|
2369
|
+
const measuredBodyRect = body.getBoundingClientRect();
|
|
2370
|
+
const overlap = overlapOf(measuredBodyRect.bottom, obstructionTop);
|
|
2371
|
+
const clearance = overlap > 0 ? offset : 0;
|
|
2372
|
+
keyboard.keyboardGeometry = overlap > 0 ? { bodyBottom: measuredBodyRect.bottom } : null;
|
|
2373
|
+
if (overlap > 0 && !layout.hasLayout) {
|
|
2374
|
+
keyboard.keyboardObstructionTop = obstructionTop;
|
|
2375
|
+
keyboard.bodyScrollTopAtKeyboard = body.scrollTop;
|
|
2376
|
+
if (isPageScrollLocked) keyboard.documentScrollAtKeyboard = {
|
|
2377
|
+
x: window.scrollX,
|
|
2378
|
+
y: window.scrollY
|
|
2379
|
+
};
|
|
2380
|
+
}
|
|
2381
|
+
layout.hasLayout = overlap > 0;
|
|
2382
|
+
keyboard.writeInset(overlap > 0 ? Math.max(0, measuredBodyRect.bottom - (obstructionTop - clearance)) : 0);
|
|
2383
|
+
keyboard.scrollControlIntoSafeArea(focusedControl, overlap > 0 && !reveals.atReport.has(window), overlap > 0 ? keyboard.showOnSlide(atReport) : null);
|
|
2384
|
+
}
|
|
2385
|
+
const unsubscribeGuide = holds.followGuide();
|
|
2386
|
+
let animationFrame = 0;
|
|
2387
|
+
const scheduleReveal = () => {
|
|
2388
|
+
cancelAnimationFrame(animationFrame);
|
|
2389
|
+
animationFrame = requestAnimationFrame(() => revealFocusedControl());
|
|
2390
|
+
};
|
|
2391
|
+
const handleDocumentScroll = () => {
|
|
2392
|
+
const expected = keyboard.documentScrollAtKeyboard;
|
|
2393
|
+
if (expected == null || window.scrollX === expected.x && window.scrollY === expected.y) return;
|
|
2394
|
+
window.scrollTo(expected.x, expected.y);
|
|
2395
|
+
const focused = focusedControlIn(body);
|
|
2396
|
+
if (focused != null) keyboard.scrollControlIntoSafeArea(focused, false);
|
|
2397
|
+
};
|
|
2398
|
+
let stopObserving = [];
|
|
2399
|
+
const refreshObservedLayout = () => {
|
|
2400
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
2401
|
+
for (const stop of stopObserving) stop();
|
|
2402
|
+
stopObserving = [];
|
|
2403
|
+
const targets = /* @__PURE__ */ new Set([body, sheet]);
|
|
2404
|
+
for (const child of body.children) targets.add(child);
|
|
2405
|
+
const activeElement = document.activeElement;
|
|
2406
|
+
if (activeElement instanceof HTMLElement && body.contains(activeElement)) for (let element = activeElement; element && element !== body; element = element.parentElement) targets.add(element);
|
|
2407
|
+
for (const target of targets) stopObserving.push(observeResize(target, scheduleReveal));
|
|
2408
|
+
};
|
|
2409
|
+
const mutationObserver = typeof MutationObserver === "undefined" ? null : new MutationObserver((records) => {
|
|
2410
|
+
if (records.every((record) => record.type === "attributes" && record.target === body)) return;
|
|
2411
|
+
refreshObservedLayout();
|
|
2412
|
+
scheduleReveal();
|
|
2413
|
+
});
|
|
2414
|
+
const handleFocusIn = () => {
|
|
2415
|
+
refreshObservedLayout();
|
|
2416
|
+
scheduleReveal();
|
|
2417
|
+
};
|
|
2418
|
+
const handleFocusOut = () => {
|
|
2419
|
+
layout.retainLayout = layout.hasLayout;
|
|
2420
|
+
scheduleReveal();
|
|
2421
|
+
};
|
|
2422
|
+
const handleSheetTransitionEnd = (event) => {
|
|
2423
|
+
if (event.target === sheet && event.propertyName === "transform") scheduleReveal();
|
|
2424
|
+
};
|
|
2425
|
+
const stopClaiming = ownsFocusTransitions ? claimFocusTransitions() : null;
|
|
2426
|
+
let lastHeight = getKeyboardHeight(window);
|
|
2427
|
+
const revealPan = isTouch ? watchRevealPan(window, {
|
|
2428
|
+
owns: (focused) => layout.hasLayout && body.contains(focused),
|
|
2429
|
+
onTouch: () => {
|
|
2430
|
+
keyboard.smoothTarget = null;
|
|
2431
|
+
}
|
|
2432
|
+
}) : null;
|
|
2433
|
+
const unsubscribe = subscribeKeyboardHeight(window, (event) => {
|
|
2434
|
+
if (event.type !== "viewport") return;
|
|
2435
|
+
if (event.height !== lastHeight) {
|
|
2436
|
+
lastHeight = event.height;
|
|
2437
|
+
revealPan?.report();
|
|
2438
|
+
cancelAnimationFrame(animationFrame);
|
|
2439
|
+
revealFocusedControl(true);
|
|
2440
|
+
return;
|
|
2441
|
+
}
|
|
2442
|
+
if (revealPan?.isRevealPan(event.height) === true) {
|
|
2443
|
+
reveals.atReport.add(window);
|
|
2444
|
+
cancelAnimationFrame(animationFrame);
|
|
2445
|
+
const distanceLeft = keyboard.smoothDistanceLeft();
|
|
2446
|
+
if (distanceLeft === 0) revealFocusedControl();
|
|
2447
|
+
const activeElement = document.activeElement;
|
|
2448
|
+
const dialog = sheet.closest("dialog");
|
|
2449
|
+
if (dialog != null && activeElement instanceof HTMLElement && activeElement.getBoundingClientRect().bottom - keyboard.rideOffset() - distanceLeft <= getObstructionTop()) revealPan?.putBack(dialog);
|
|
2450
|
+
return;
|
|
2451
|
+
}
|
|
2452
|
+
scheduleReveal();
|
|
2453
|
+
});
|
|
2454
|
+
body.addEventListener("focusin", handleFocusIn);
|
|
2455
|
+
body.addEventListener("focusout", handleFocusOut);
|
|
2456
|
+
sheet.addEventListener("transitionend", handleSheetTransitionEnd);
|
|
2457
|
+
const stopDocumentScroll = subscribeInput(window, "scroll", (event) => {
|
|
2458
|
+
const target = event.target;
|
|
2459
|
+
if (!isNode(target) || isDocument(target)) handleDocumentScroll();
|
|
2460
|
+
});
|
|
2461
|
+
mutationObserver?.observe(body, {
|
|
2462
|
+
attributes: true,
|
|
2463
|
+
characterData: true,
|
|
2464
|
+
childList: true,
|
|
2465
|
+
subtree: true
|
|
2466
|
+
});
|
|
2467
|
+
refreshObservedLayout();
|
|
2468
|
+
scheduleReveal();
|
|
2469
|
+
return () => {
|
|
2470
|
+
unregister();
|
|
2471
|
+
cancelAnimationFrame(animationFrame);
|
|
2472
|
+
stopClaiming?.();
|
|
2473
|
+
unsubscribe();
|
|
2474
|
+
unsubscribeGuide();
|
|
2475
|
+
holds.stop();
|
|
2476
|
+
revealPan?.stop();
|
|
2477
|
+
body.removeEventListener("focusin", handleFocusIn);
|
|
2478
|
+
body.removeEventListener("focusout", handleFocusOut);
|
|
2479
|
+
sheet.removeEventListener("transitionend", handleSheetTransitionEnd);
|
|
2480
|
+
stopDocumentScroll();
|
|
2481
|
+
for (const stop of stopObserving) stop();
|
|
2482
|
+
mutationObserver?.disconnect();
|
|
2483
|
+
keyboard.writeInset(0);
|
|
2484
|
+
layout.hasLayout = false;
|
|
2485
|
+
layout.retainLayout = false;
|
|
2486
|
+
};
|
|
2487
|
+
}
|
|
2488
|
+
//#endregion
|
|
2489
|
+
//#region src/keyboard/useMobileKeyboard.ts
|
|
2490
|
+
/**
|
|
2491
|
+
* Keeps a focused field in `target`'s element above the on-screen keyboard
|
|
2492
|
+
* (see README.md). A sheet passes its panel and body, and the composable
|
|
2493
|
+
* reserves the inset at the end of the body's content. Returns the inset the
|
|
2494
|
+
* keyboard takes there, CSS px, or 0 without a keyboard, and a dismiss.
|
|
2495
|
+
*
|
|
2496
|
+
* Every option is read when it is used, so a listener always sees the
|
|
2497
|
+
* current value.
|
|
2498
|
+
*
|
|
2499
|
+
* @example
|
|
2500
|
+
* ```
|
|
2501
|
+
* const keyboard = useMobileKeyboard(panel, { move: 'ride', inset: true, body, offset: 48, isEnabled, isExpanded, isOpen, isPageScrollLocked })
|
|
2502
|
+
* ```
|
|
2503
|
+
*/
|
|
2504
|
+
function useMobileKeyboard(target, options = {}) {
|
|
2505
|
+
const move = () => options.move;
|
|
2506
|
+
const reservesInset = () => options.inset ?? false;
|
|
2507
|
+
const offset = () => toValue(options.offset) ?? 10;
|
|
2508
|
+
const isEnabled = () => toValue(options.isEnabled) ?? true;
|
|
2509
|
+
const isExpanded = () => toValue(options.isExpanded) ?? true;
|
|
2510
|
+
const isOpen = () => toValue(options.isOpen) ?? true;
|
|
2511
|
+
const isPageScrollLocked = () => toValue(options.isPageScrollLocked) ?? false;
|
|
2512
|
+
const inset = shallowRef(0);
|
|
2513
|
+
const layout = {
|
|
2514
|
+
hasLayout: false,
|
|
2515
|
+
retainLayout: false
|
|
2516
|
+
};
|
|
2517
|
+
const isTouch = useMediaQuery(TOUCH_QUERY);
|
|
2518
|
+
const dismiss = (focusTarget) => {
|
|
2519
|
+
const element = toValue(target);
|
|
2520
|
+
const activeElement = document.activeElement;
|
|
2521
|
+
if (!isEnabled() || element == null || !(activeElement instanceof HTMLElement) || activeElement === element || !element.contains(activeElement)) return;
|
|
2522
|
+
layout.retainLayout = layout.hasLayout;
|
|
2523
|
+
if (focusTarget == null) activeElement.blur();
|
|
2524
|
+
else focusTarget.focus({ preventScroll: true });
|
|
2525
|
+
};
|
|
2526
|
+
watch(() => isEnabled() && !isOpen(), (closing) => {
|
|
2527
|
+
if (closing) dismiss();
|
|
2528
|
+
}, {
|
|
2529
|
+
immediate: true,
|
|
2530
|
+
flush: "sync"
|
|
2531
|
+
});
|
|
2532
|
+
useAttachment(target, (element) => {
|
|
2533
|
+
const how = move();
|
|
2534
|
+
if (!isEnabled() || reservesInset() || !isTouch.value) return () => {};
|
|
2535
|
+
return how == null ? keepFieldAboveKeyboard(element, { offset: offset() }) : followKeyboard(element, {
|
|
2536
|
+
move: how,
|
|
2537
|
+
offset: offset()
|
|
2538
|
+
});
|
|
2539
|
+
}, () => `${isEnabled()}|${move()}|${reservesInset()}|${offset()}|${isTouch.value}`);
|
|
2540
|
+
useAttachment(target, (sheet) => {
|
|
2541
|
+
const body = toValue(options.body);
|
|
2542
|
+
if (!isEnabled() || !reservesInset() || body == null) return () => {};
|
|
2543
|
+
return attachSheetKeyboard(sheet, body, {
|
|
2544
|
+
offset: offset(),
|
|
2545
|
+
isExpanded,
|
|
2546
|
+
isOpen,
|
|
2547
|
+
isPageScrollLocked: isPageScrollLocked(),
|
|
2548
|
+
isTouch: isTouch.value,
|
|
2549
|
+
layout,
|
|
2550
|
+
onInset: (value) => {
|
|
2551
|
+
inset.value = value;
|
|
2552
|
+
}
|
|
2553
|
+
});
|
|
2554
|
+
}, () => `${isEnabled()}|${reservesInset()}|${isPageScrollLocked()}|${isTouch.value}|${offset()}|${toValue(options.body) != null}`);
|
|
2555
|
+
return {
|
|
2556
|
+
inset: readonly(inset),
|
|
2557
|
+
dismiss
|
|
2558
|
+
};
|
|
2559
|
+
}
|
|
2560
|
+
//#endregion
|
|
2561
|
+
//#region src/BottomSheet/sheetDragExit.ts
|
|
2562
|
+
/** How many more frames a drag's close looks for its scrim's fade to adopt. */
|
|
2563
|
+
const MAX_SCRIM_FADE_ADOPT_FRAMES = 3;
|
|
2564
|
+
/** Without Web Animations the animator jumps to its end, so the stylesheet's exit runs instead. */
|
|
2565
|
+
function supportsWebAnimations() {
|
|
2566
|
+
return typeof Element !== "undefined" && typeof Element.prototype.animate === "function";
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* How a drag's close plays: the close spring's move from where the finger
|
|
2570
|
+
* left the sheet, timed as the shared animator times it, and its progress
|
|
2571
|
+
* toward the point where the sheet leaves view. The surface reaches below the
|
|
2572
|
+
* screen (the reserve), so it leaves view before the spring settles, and the
|
|
2573
|
+
* scrim is clear by then.
|
|
2574
|
+
*/
|
|
2575
|
+
function dragExitFade(element, exit) {
|
|
2576
|
+
const viewportHeight = element.ownerDocument.defaultView?.innerHeight ?? 0;
|
|
2577
|
+
const shown = Math.max(0, viewportHeight - element.getBoundingClientRect().top);
|
|
2578
|
+
return resolveMoveTiming(element, springs.sheetDismissSwipe, {
|
|
2579
|
+
from: 0,
|
|
2580
|
+
to: exit.distance,
|
|
2581
|
+
velocity: exit.velocity,
|
|
2582
|
+
epsilon: SETTLE_THRESHOLD.y
|
|
2583
|
+
}, Math.min(exit.distance, shown));
|
|
2584
|
+
}
|
|
2585
|
+
/** The running fade that clears the scrim behind `panel`, if any. */
|
|
2586
|
+
function clearingScrimFade(panel) {
|
|
2587
|
+
const dialog = panel.closest("dialog");
|
|
2588
|
+
const doc = panel.ownerDocument;
|
|
2589
|
+
if (dialog == null || typeof doc.getAnimations !== "function") return void 0;
|
|
2590
|
+
const fades = doc.getAnimations().filter((animation) => {
|
|
2591
|
+
const effect = animation.effect;
|
|
2592
|
+
return effect?.target === dialog && animation.transitionProperty === "opacity" && Number(effect.getKeyframes().at(-1)?.opacity) === 0;
|
|
2593
|
+
});
|
|
2594
|
+
const onBackdrop = fades.filter((fade) => fade.effect.pseudoElement === "::backdrop");
|
|
2595
|
+
return (onBackdrop.length > 0 ? onBackdrop : fades.filter((fade) => !fade.effect.pseudoElement)).at(-1);
|
|
2596
|
+
}
|
|
2597
|
+
/**
|
|
2598
|
+
* Plays a touch drag's close on the shared animator with the dismiss swipe's
|
|
2599
|
+
* spring, from the release speed. The scrim's CSS fade takes the close's start
|
|
2600
|
+
* time, so the two end together. Returns the cleanup: a reopen during the
|
|
2601
|
+
* exit takes the sheet back from where it is.
|
|
2602
|
+
*/
|
|
2603
|
+
function playDragExit(element, exit, callbacks) {
|
|
2604
|
+
const handle = animatorFor(element).animate({ y: exit.distance }, {
|
|
2605
|
+
spring: springs.sheetDismissSwipe,
|
|
2606
|
+
velocity: { y: exit.velocity }
|
|
2607
|
+
});
|
|
2608
|
+
let isCurrent = true;
|
|
2609
|
+
let isFinished = false;
|
|
2610
|
+
let frame = null;
|
|
2611
|
+
handle.started.then((start) => {
|
|
2612
|
+
const adopt = (framesLeft) => {
|
|
2613
|
+
frame = null;
|
|
2614
|
+
if (!isCurrent) return;
|
|
2615
|
+
const fade = clearingScrimFade(element);
|
|
2616
|
+
if (fade != null) fade.startTime = start;
|
|
2617
|
+
else if (framesLeft > 0 && typeof requestAnimationFrame === "function") frame = requestAnimationFrame(() => adopt(framesLeft - 1));
|
|
2618
|
+
};
|
|
2619
|
+
adopt(MAX_SCRIM_FADE_ADOPT_FRAMES);
|
|
2620
|
+
});
|
|
2621
|
+
handle.finished.then(() => {
|
|
2622
|
+
isFinished = true;
|
|
2623
|
+
callbacks.onSettled();
|
|
2624
|
+
if (isCurrent) callbacks.complete();
|
|
2625
|
+
});
|
|
2626
|
+
return () => {
|
|
2627
|
+
isCurrent = false;
|
|
2628
|
+
if (frame != null) cancelAnimationFrame(frame);
|
|
2629
|
+
if (!isFinished) handle.retarget({ y: 0 });
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
/** A hidden sheet can stay mounted, so the exit's offset goes back to 0. */
|
|
2633
|
+
function resetDragExit(element) {
|
|
2634
|
+
animatorFor(element).set({ y: 0 });
|
|
2635
|
+
}
|
|
2636
|
+
//#endregion
|
|
2637
|
+
//#region src/BottomSheet/sheetTransition.ts
|
|
2638
|
+
const BACKSTOP_BUFFER_MS = 50;
|
|
2639
|
+
function parseTransitionTime(value) {
|
|
2640
|
+
const normalized = value.trim();
|
|
2641
|
+
if (!/^-?(?:\d+|\d*\.\d+)(?:ms|s)$/.test(normalized)) return null;
|
|
2642
|
+
const time = Number.parseFloat(normalized);
|
|
2643
|
+
return normalized.endsWith("ms") ? time : time * 1e3;
|
|
2644
|
+
}
|
|
2645
|
+
/** Longest transition duration + delay that applies to `property`, in ms. */
|
|
2646
|
+
function transitionMsFor(element, property) {
|
|
2647
|
+
const style = getComputedStyle(element);
|
|
2648
|
+
const properties = (style.transitionProperty || "").split(",").map((value) => value.trim());
|
|
2649
|
+
const durations = (style.transitionDuration || "").split(",").map(parseTransitionTime);
|
|
2650
|
+
const delays = (style.transitionDelay || "").split(",").map((value) => parseTransitionTime(value) ?? 0);
|
|
2651
|
+
return properties.reduce((longest, name, index) => {
|
|
2652
|
+
if (name !== property && name !== "all") return longest;
|
|
2653
|
+
const duration = durations[index % durations.length];
|
|
2654
|
+
if (duration == null) return longest;
|
|
2655
|
+
return Math.max(longest, duration + (delays[index % delays.length] ?? 0));
|
|
2656
|
+
}, 0);
|
|
2657
|
+
}
|
|
2658
|
+
/** Whether a CSS transition of `property` still runs on `element`. */
|
|
2659
|
+
function hasRunningTransition(element, property) {
|
|
2660
|
+
return (element.getAnimations?.() ?? []).some((animation) => animation.transitionProperty === property && (animation.playState === "running" || animation.playState === "paused"));
|
|
2661
|
+
}
|
|
2662
|
+
/**
|
|
2663
|
+
* Calls `complete` when `element` finishes transitioning `property`: on the
|
|
2664
|
+
* matching `transitionend`/`transitioncancel`, or on a timer backstop so a
|
|
2665
|
+
* missed event can never strand the caller. Without a resolved duration — the
|
|
2666
|
+
* case in a stylesheet-free test environment — it completes immediately.
|
|
2667
|
+
*/
|
|
2668
|
+
function waitForTransition(element, property, complete) {
|
|
2669
|
+
if (element == null) {
|
|
2670
|
+
complete();
|
|
2671
|
+
return () => {};
|
|
2672
|
+
}
|
|
2673
|
+
let done = false;
|
|
2674
|
+
let timer = null;
|
|
2675
|
+
let backstopMs = 0;
|
|
2676
|
+
let onTransitionEnd = () => {};
|
|
2677
|
+
const finish = () => {
|
|
2678
|
+
if (done) return;
|
|
2679
|
+
done = true;
|
|
2680
|
+
if (timer != null) clearTimeout(timer);
|
|
2681
|
+
element.removeEventListener("transitionend", onTransitionEnd);
|
|
2682
|
+
element.removeEventListener("transitioncancel", onTransitionEnd);
|
|
2683
|
+
complete();
|
|
2684
|
+
};
|
|
2685
|
+
onTransitionEnd = (event) => {
|
|
2686
|
+
if (event.target !== element || event.propertyName !== property) return;
|
|
2687
|
+
if (event.type === "transitioncancel" && hasRunningTransition(element, property)) {
|
|
2688
|
+
if (timer != null) {
|
|
2689
|
+
clearTimeout(timer);
|
|
2690
|
+
timer = setTimeout(finish, backstopMs);
|
|
2691
|
+
}
|
|
2692
|
+
return;
|
|
2693
|
+
}
|
|
2694
|
+
finish();
|
|
2695
|
+
};
|
|
2696
|
+
const duration = transitionMsFor(element, property);
|
|
2697
|
+
if (duration <= 0) {
|
|
2698
|
+
finish();
|
|
2699
|
+
return () => {};
|
|
2700
|
+
}
|
|
2701
|
+
element.addEventListener("transitionend", onTransitionEnd);
|
|
2702
|
+
element.addEventListener("transitioncancel", onTransitionEnd);
|
|
2703
|
+
backstopMs = duration + BACKSTOP_BUFFER_MS;
|
|
2704
|
+
timer = setTimeout(finish, backstopMs);
|
|
2705
|
+
return () => {
|
|
2706
|
+
if (timer != null) clearTimeout(timer);
|
|
2707
|
+
element.removeEventListener("transitionend", onTransitionEnd);
|
|
2708
|
+
element.removeEventListener("transitioncancel", onTransitionEnd);
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
/** Scrim opacity at the peek stop: dimmed, never clear, because the sheet stays modal. */
|
|
2712
|
+
const MIN_PEEK_SCRIM_OPACITY = .3;
|
|
2713
|
+
const SNAP_POINT_PATTERN = /^(\d+(?:\.\d+)?|\.\d+)(px|%)$/i;
|
|
2714
|
+
function parseSnapPoint(point, viewportPx) {
|
|
2715
|
+
if (typeof point === "number") return Number.isFinite(point) && point > 0 && point <= 1 ? point * viewportPx : null;
|
|
2716
|
+
const match = SNAP_POINT_PATTERN.exec(point.trim());
|
|
2717
|
+
if (match === null) return null;
|
|
2718
|
+
const value = Number.parseFloat(match[1]);
|
|
2719
|
+
if (!(value > 0)) return null;
|
|
2720
|
+
return match[2].toLowerCase() === "%" ? value / 100 * viewportPx : value;
|
|
2721
|
+
}
|
|
2722
|
+
/** Resolves snap points to candidate visible heights in px, dropping unusable ones. */
|
|
2723
|
+
function resolveSnapPoints(points, viewportPx) {
|
|
2724
|
+
const heights = [];
|
|
2725
|
+
for (const point of points) {
|
|
2726
|
+
const height = parseSnapPoint(point, viewportPx);
|
|
2727
|
+
if (height !== null) heights.push(height);
|
|
2728
|
+
}
|
|
2729
|
+
return heights;
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2732
|
+
* Resting offsets from fully open, ascending and de-duplicated. `0` is always
|
|
2733
|
+
* the first stop; only heights shorter than the sheet become collapsed stops;
|
|
2734
|
+
* offsets closer than `dedupPx` collapse to the taller one.
|
|
2735
|
+
*/
|
|
2736
|
+
function computeDetentOffsets(sheetHeight, detentHeights, dedupPx = 48) {
|
|
2737
|
+
const ascending = [0, ...detentHeights.filter((height) => height > 0 && height < sheetHeight).map((height) => sheetHeight - height)].sort((a, b) => a - b);
|
|
2738
|
+
const deduped = [];
|
|
2739
|
+
for (const offset of ascending) {
|
|
2740
|
+
const last = deduped[deduped.length - 1];
|
|
2741
|
+
if (last === void 0 || offset - last >= dedupPx) deduped.push(offset);
|
|
2742
|
+
}
|
|
2743
|
+
return deduped;
|
|
2744
|
+
}
|
|
2745
|
+
/** Nearest value in `offsets` to `value`; `offsets` must not be empty. */
|
|
2746
|
+
function nearestOffset(value, offsets) {
|
|
2747
|
+
return offsets.reduce((best, offset) => Math.abs(offset - value) < Math.abs(best - value) ? offset : best, offsets[0]);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* The peek stop's offset, or `null` when this sheet has no peek. A peek is the
|
|
2751
|
+
* shortest stop and a sliver: a sheet that keeps the full layout height and
|
|
2752
|
+
* slides below the viewport instead of reflowing its content into a sliver.
|
|
2753
|
+
*/
|
|
2754
|
+
function peekOffsetFor(offsets, visibleSheetHeight) {
|
|
2755
|
+
if (offsets.length < 2 || visibleSheetHeight <= 0) return null;
|
|
2756
|
+
const shortest = offsets[offsets.length - 1];
|
|
2757
|
+
return visibleSheetHeight - shortest <= .25 * visibleSheetHeight ? shortest : null;
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2760
|
+
* Scrim opacity (1 = fully opaque) for a drag or settle `offset`. It stays
|
|
2761
|
+
* opaque down to the shortest working stop and only thins past it, onto a peek
|
|
2762
|
+
* or out through the dismissal overshoot.
|
|
2763
|
+
*/
|
|
2764
|
+
function scrimOpacityForOffset(offset, offsets, dismissOffset, peekOffset) {
|
|
2765
|
+
const hasPeek = peekOffset !== null;
|
|
2766
|
+
const fadeStart = hasPeek ? offsets[offsets.length - 2] : offsets[offsets.length - 1];
|
|
2767
|
+
const fadeEnd = hasPeek ? peekOffset : dismissOffset;
|
|
2768
|
+
const floor = hasPeek ? MIN_PEEK_SCRIM_OPACITY : 0;
|
|
2769
|
+
if (offset <= fadeStart) return 1;
|
|
2770
|
+
if (offset >= fadeEnd) return floor;
|
|
2771
|
+
return 1 - (1 - floor) * ((offset - fadeStart) / (fadeEnd - fadeStart));
|
|
2772
|
+
}
|
|
2773
|
+
/**
|
|
2774
|
+
* Settle target for a released drag, restricted to the drag direction so a
|
|
2775
|
+
* committed drag never snaps back past where it started. `dir`: 1 = dragged
|
|
2776
|
+
* down, -1 = up, 0 = neither.
|
|
2777
|
+
*/
|
|
2778
|
+
function resolveSettleOffset(value, offsets, dir, baseOffset) {
|
|
2779
|
+
let candidates = offsets;
|
|
2780
|
+
if (dir > 0) {
|
|
2781
|
+
const downward = offsets.filter((offset) => offset >= baseOffset);
|
|
2782
|
+
if (downward.length > 0) candidates = downward;
|
|
2783
|
+
} else if (dir < 0) {
|
|
2784
|
+
const upward = offsets.filter((offset) => offset <= baseOffset);
|
|
2785
|
+
if (upward.length > 0) candidates = upward;
|
|
2786
|
+
}
|
|
2787
|
+
return nearestOffset(value, candidates);
|
|
2788
|
+
}
|
|
2789
|
+
/** The visible height of the sheet at a resting `offset`. */
|
|
2790
|
+
function visibleHeightForOffset(sheetHeight, offset, offscreenBlockEndInset) {
|
|
2791
|
+
return Math.max(0, sheetHeight - offscreenBlockEndInset - offset);
|
|
2792
|
+
}
|
|
2793
|
+
/** On a touch device the reserve covers a pull of the whole viewport: 40% of it. */
|
|
2794
|
+
const RESERVE_VIEWPORT_SHARE = .4;
|
|
2795
|
+
/** Below the shortest stop, a slow mouse drag past this share of its height dismisses. */
|
|
2796
|
+
const DISMISS_OVERSHOOT_RATIO = .4;
|
|
2797
|
+
/** Within this many px of a stop the live drag eases toward it. */
|
|
2798
|
+
const MAGNET_RANGE = 40;
|
|
2799
|
+
/** A mouse's or a pen's stretch past fully open: a resisted fraction, capped at MIN_RESERVE. */
|
|
2800
|
+
const OVERSCROLL_RESISTANCE = .35;
|
|
2801
|
+
/** The reserve a sheet keeps on a touch device whose layout viewport is `viewportHeight` tall. */
|
|
2802
|
+
function sheetReserve(viewportHeight) {
|
|
2803
|
+
return Math.max(48, Math.ceil(viewportHeight * RESERVE_VIEWPORT_SHARE));
|
|
2804
|
+
}
|
|
2805
|
+
/**
|
|
2806
|
+
* Whether a gesture that lands on `target` began inside another layer rendered
|
|
2807
|
+
* in this sheet's content: a `<dialog>` between the target and the body.
|
|
2808
|
+
* A sheet or Dialog opened from inside a sheet renders its dialog as a
|
|
2809
|
+
* descendant of the host's body, so its pointer and touch events bubble
|
|
2810
|
+
* through the host's listeners. That gesture is the layer's own: the host
|
|
2811
|
+
* neither arms a drag on it nor takes the pointer for it.
|
|
2812
|
+
*
|
|
2813
|
+
* A control that pans vertically on its own (a picker wheel, marked
|
|
2814
|
+
* `data-astryx-owns-pan`) keeps its gesture the same way: a downward drag on
|
|
2815
|
+
* it turns its rows and never pulls the sheet.
|
|
2816
|
+
*/
|
|
2817
|
+
function isInsideNestedLayer(target, body) {
|
|
2818
|
+
for (let element = target instanceof Element ? target : null; element != null && element !== body; element = element.parentElement) if (element.localName === "dialog" || element.hasAttribute("data-astryx-owns-pan")) return true;
|
|
2819
|
+
return false;
|
|
2820
|
+
}
|
|
2821
|
+
function magnetize(value, targets) {
|
|
2822
|
+
if (targets.length === 0) return value;
|
|
2823
|
+
let nearest = targets[0];
|
|
2824
|
+
for (const target of targets) if (Math.abs(target - value) < Math.abs(nearest - value)) nearest = target;
|
|
2825
|
+
const distance = Math.abs(value - nearest);
|
|
2826
|
+
if (distance >= MAGNET_RANGE) return value;
|
|
2827
|
+
const t = distance / MAGNET_RANGE;
|
|
2828
|
+
return value + (nearest - value) * (1 - t * t);
|
|
2829
|
+
}
|
|
2830
|
+
/**
|
|
2831
|
+
* The offset a drag shows for the raw offset `raw` under the finger. Past
|
|
2832
|
+
* fully open, a finger stretches on UIKit's rubber band over the visible
|
|
2833
|
+
* height and never past the reserve; a mouse or a pen moves a resisted
|
|
2834
|
+
* fraction capped at MIN_RESERVE. Past the shortest stop nothing pulls, so it
|
|
2835
|
+
* never fights a drag to close. Between stops, the drag eases into a stop
|
|
2836
|
+
* within MAGNET_RANGE.
|
|
2837
|
+
*/
|
|
2838
|
+
function stretchedOffset(raw, offsets, context) {
|
|
2839
|
+
if (raw < 0) return context.pointerType === "touch" ? Math.max(-context.reserve, rubberBand(raw, context.height - context.reserve, scroll.rubberBand.coefficient)) : Math.max(-48, raw * OVERSCROLL_RESISTANCE);
|
|
2840
|
+
if (raw > (offsets[offsets.length - 1] ?? 0)) return raw;
|
|
2841
|
+
return magnetize(raw, offsets);
|
|
2842
|
+
}
|
|
2843
|
+
function renderedBlockEndPadding(element) {
|
|
2844
|
+
const value = Number.parseFloat(getComputedStyle(element).paddingBlockEnd);
|
|
2845
|
+
return Number.isFinite(value) ? value : 0;
|
|
2846
|
+
}
|
|
2847
|
+
/** How much further the body could scroll on its own, ignoring the inset this hook adds. */
|
|
2848
|
+
function naturalEndGapFor(body) {
|
|
2849
|
+
if (!body) return 0;
|
|
2850
|
+
const inset = renderedBlockEndPadding(body);
|
|
2851
|
+
return Math.max(0, body.scrollHeight - body.clientHeight - inset) - body.scrollTop;
|
|
2852
|
+
}
|
|
2853
|
+
function hapticTick() {
|
|
2854
|
+
if (typeof navigator === "undefined" || typeof navigator.vibrate !== "function") return;
|
|
2855
|
+
if (typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches) return;
|
|
2856
|
+
navigator.vibrate(8);
|
|
2857
|
+
}
|
|
2858
|
+
/** Offset past which a slow mouse or pen drag dismisses instead of snapping back. */
|
|
2859
|
+
function dismissTravelFor(height, offsets, reserve) {
|
|
2860
|
+
const maxOffset = offsets[offsets.length - 1] ?? 0;
|
|
2861
|
+
return maxOffset + visibleHeightForOffset(height, maxOffset, reserve) * DISMISS_OVERSHOOT_RATIO;
|
|
2862
|
+
}
|
|
2863
|
+
//#endregion
|
|
2864
|
+
//#region src/BottomSheet/sheetScrollChain.ts
|
|
2865
|
+
/**
|
|
2866
|
+
* The boxes a touch on the sheet's body can scroll, and the edges they sit at.
|
|
2867
|
+
*
|
|
2868
|
+
* The body is where the sheet listens, but it is not always what scrolls: a
|
|
2869
|
+
* host can pin a header and footer around a scrolling middle, or lay a
|
|
2870
|
+
* scrolling grid inside the sheet. The browser scrolls the innermost box that
|
|
2871
|
+
* has room and then chains outward, so a pull belongs to the sheet only when
|
|
2872
|
+
* every box in the chain sits at the edge the pull opposes.
|
|
2873
|
+
*/
|
|
2874
|
+
/** A box a finger or a wheel can scroll along the block axis. */
|
|
2875
|
+
function isBlockScroller(element) {
|
|
2876
|
+
if (element.scrollHeight - element.clientHeight <= 1) return false;
|
|
2877
|
+
const { overflowY } = getComputedStyle(element);
|
|
2878
|
+
return overflowY === "auto" || overflowY === "scroll";
|
|
2879
|
+
}
|
|
2880
|
+
/** Every scroller between `target` and `body`, innermost first, then the body itself. */
|
|
2881
|
+
function scrollChainUnder(target, body) {
|
|
2882
|
+
const chain = [];
|
|
2883
|
+
for (let element = target instanceof Element ? target : null; element != null && element !== body; element = element.parentElement) if (element instanceof HTMLElement && isBlockScroller(element)) chain.push(element);
|
|
2884
|
+
chain.push(body);
|
|
2885
|
+
return chain;
|
|
2886
|
+
}
|
|
2887
|
+
/** Nothing in the chain can scroll up any further, so a pull down is the sheet's. */
|
|
2888
|
+
function chainAtTop(chain) {
|
|
2889
|
+
return chain.every((element) => element.scrollTop <= 0);
|
|
2890
|
+
}
|
|
2891
|
+
/** Nothing in the chain can scroll down any further, so a pull up is the sheet's. */
|
|
2892
|
+
function chainAtBottom(chain) {
|
|
2893
|
+
return chain.every((element) => element.scrollTop + element.clientHeight >= element.scrollHeight - 1);
|
|
2894
|
+
}
|
|
2895
|
+
/** Whether any box in the chain has content to scroll. */
|
|
2896
|
+
function chainScrolls(chain) {
|
|
2897
|
+
return chain.some((element) => element.scrollHeight - element.clientHeight > 1);
|
|
2898
|
+
}
|
|
2899
|
+
/**
|
|
2900
|
+
* iOS rubber-bands a scroller past its end even under `overscroll-behavior:
|
|
2901
|
+
* contain`. While the content sits at its end mid-pull, `none` holds it still,
|
|
2902
|
+
* so only the sheet moves. Returns the undo.
|
|
2903
|
+
*/
|
|
2904
|
+
function holdAtEnd(chain) {
|
|
2905
|
+
const previous = chain.map((element) => element.style.overscrollBehaviorY);
|
|
2906
|
+
for (const element of chain) element.style.overscrollBehaviorY = "none";
|
|
2907
|
+
return () => {
|
|
2908
|
+
chain.forEach((element, index) => {
|
|
2909
|
+
element.style.overscrollBehaviorY = previous[index] ?? "";
|
|
2910
|
+
});
|
|
2911
|
+
};
|
|
2912
|
+
}
|
|
2913
|
+
//#endregion
|
|
2914
|
+
//#region src/BottomSheet/sheetPointerArm.ts
|
|
2915
|
+
/**
|
|
2916
|
+
* The handle's drag for every pointer, and the body's pull down at its top for
|
|
2917
|
+
* a mouse or a pen. A finger's pull on the body belongs to the touch listeners
|
|
2918
|
+
* alone, so a touch-down never arms here.
|
|
2919
|
+
*/
|
|
2920
|
+
function createSheetPointerArm(drive) {
|
|
2921
|
+
let arm = null;
|
|
2922
|
+
function reset() {
|
|
2923
|
+
arm = null;
|
|
2924
|
+
}
|
|
2925
|
+
/** A second pointer is a pinch. The browser keeps the zoom; the sheet lets go. */
|
|
2926
|
+
function yieldToPinch(pointerId) {
|
|
2927
|
+
const active = drive.dragPointerId();
|
|
2928
|
+
if (active == null || active === pointerId) return false;
|
|
2929
|
+
drive.cancel();
|
|
2930
|
+
return true;
|
|
2931
|
+
}
|
|
2932
|
+
function onPointerMove(event) {
|
|
2933
|
+
if (drive.dragPointerId() != null) {
|
|
2934
|
+
if (drive.isTouchDrag() || yieldToPinch(event.pointerId)) return;
|
|
2935
|
+
if (event.cancelable) event.preventDefault();
|
|
2936
|
+
drive.move(event.clientY, event.timeStamp);
|
|
2937
|
+
return;
|
|
2938
|
+
}
|
|
2939
|
+
const armed = arm;
|
|
2940
|
+
if (armed == null || armed.pointerId !== event.pointerId) return;
|
|
2941
|
+
const delta = event.clientY - armed.startY;
|
|
2942
|
+
armed.tracker.add(0, event.clientY, event.timeStamp);
|
|
2943
|
+
if (delta > 8 && chainAtTop(armed.scrollers)) {
|
|
2944
|
+
arm = null;
|
|
2945
|
+
drive.begin({
|
|
2946
|
+
pointerId: armed.pointerId,
|
|
2947
|
+
pointerType: armed.pointerType,
|
|
2948
|
+
startY: armed.startY,
|
|
2949
|
+
tracker: armed.tracker
|
|
2950
|
+
}, event.clientY, event.timeStamp);
|
|
2951
|
+
if (event.cancelable) event.preventDefault();
|
|
2952
|
+
drive.move(event.clientY, event.timeStamp);
|
|
2953
|
+
} else if (delta < 0) {
|
|
2954
|
+
arm = null;
|
|
2955
|
+
drive.detach();
|
|
2956
|
+
}
|
|
2957
|
+
}
|
|
2958
|
+
function onPointerUp(event) {
|
|
2959
|
+
const active = drive.dragPointerId();
|
|
2960
|
+
if (active != null && (active !== event.pointerId || drive.isTouchDrag())) return;
|
|
2961
|
+
arm = null;
|
|
2962
|
+
if (active == null) {
|
|
2963
|
+
drive.detach();
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2966
|
+
drive.end(event.clientY, event.timeStamp);
|
|
2967
|
+
}
|
|
2968
|
+
function onPointerCancel(event) {
|
|
2969
|
+
const active = drive.dragPointerId();
|
|
2970
|
+
if (active != null && (active !== event.pointerId || drive.isTouchDrag())) return;
|
|
2971
|
+
drive.cancel();
|
|
2972
|
+
}
|
|
2973
|
+
function onHandlePointerDown(event) {
|
|
2974
|
+
if (event.button != null && event.button !== 0) return;
|
|
2975
|
+
if (yieldToPinch(event.pointerId)) return;
|
|
2976
|
+
drive.attach();
|
|
2977
|
+
const tracker = new VelocityTracker();
|
|
2978
|
+
drive.begin({
|
|
2979
|
+
pointerId: event.pointerId,
|
|
2980
|
+
pointerType: event.pointerType,
|
|
2981
|
+
startY: event.clientY,
|
|
2982
|
+
tracker
|
|
2983
|
+
}, event.clientY, event.timeStamp);
|
|
2984
|
+
if (event.cancelable) event.preventDefault();
|
|
2985
|
+
}
|
|
2986
|
+
function onBodyPointerDown(event) {
|
|
2987
|
+
if (yieldToPinch(event.pointerId)) return;
|
|
2988
|
+
arm = null;
|
|
2989
|
+
if (event.pointerType === "touch" || event.button != null && event.button !== 0) return;
|
|
2990
|
+
const body = drive.body();
|
|
2991
|
+
if (!body || isInsideNestedLayer(event.target, body)) return;
|
|
2992
|
+
const scrollers = scrollChainUnder(event.target, body);
|
|
2993
|
+
if (!chainAtTop(scrollers)) return;
|
|
2994
|
+
const tracker = new VelocityTracker();
|
|
2995
|
+
tracker.add(0, event.clientY, event.timeStamp);
|
|
2996
|
+
arm = {
|
|
2997
|
+
pointerId: event.pointerId,
|
|
2998
|
+
pointerType: event.pointerType,
|
|
2999
|
+
startY: event.clientY,
|
|
3000
|
+
scrollers,
|
|
3001
|
+
tracker
|
|
3002
|
+
};
|
|
3003
|
+
drive.attach();
|
|
3004
|
+
}
|
|
3005
|
+
return {
|
|
3006
|
+
onPointerMove,
|
|
3007
|
+
onPointerUp,
|
|
3008
|
+
onPointerCancel,
|
|
3009
|
+
onHandlePointerDown,
|
|
3010
|
+
onBodyPointerDown,
|
|
3011
|
+
reset
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
//#endregion
|
|
3015
|
+
//#region src/BottomSheet/sheetPointerSession.ts
|
|
3016
|
+
/** Window pointer listeners, the body's non-passive touch listeners, and the interruptions that cancel a drag. */
|
|
3017
|
+
function createSheetPointerSession(handlers) {
|
|
3018
|
+
let body = null;
|
|
3019
|
+
let listening = false;
|
|
3020
|
+
function attach() {
|
|
3021
|
+
if (listening || typeof window === "undefined") return;
|
|
3022
|
+
listening = true;
|
|
3023
|
+
window.addEventListener("pointermove", handlers.onPointerMove);
|
|
3024
|
+
window.addEventListener("pointerup", handlers.onPointerUp);
|
|
3025
|
+
window.addEventListener("pointercancel", handlers.onPointerCancel);
|
|
3026
|
+
}
|
|
3027
|
+
function detach() {
|
|
3028
|
+
if (!listening || typeof window === "undefined") return;
|
|
3029
|
+
listening = false;
|
|
3030
|
+
window.removeEventListener("pointermove", handlers.onPointerMove);
|
|
3031
|
+
window.removeEventListener("pointerup", handlers.onPointerUp);
|
|
3032
|
+
window.removeEventListener("pointercancel", handlers.onPointerCancel);
|
|
3033
|
+
}
|
|
3034
|
+
function unbind(element) {
|
|
3035
|
+
element.removeEventListener("touchstart", handlers.onTouchStart);
|
|
3036
|
+
element.removeEventListener("touchmove", handlers.onTouchMove);
|
|
3037
|
+
element.removeEventListener("touchend", handlers.onTouchEnd);
|
|
3038
|
+
element.removeEventListener("touchcancel", handlers.onTouchEnd);
|
|
3039
|
+
}
|
|
3040
|
+
function setBody(element) {
|
|
3041
|
+
if (body != null) unbind(body);
|
|
3042
|
+
body = element;
|
|
3043
|
+
if (element == null) return;
|
|
3044
|
+
element.addEventListener("touchstart", handlers.onTouchStart, { passive: true });
|
|
3045
|
+
element.addEventListener("touchmove", handlers.onTouchMove, { passive: false });
|
|
3046
|
+
element.addEventListener("touchend", handlers.onTouchEnd);
|
|
3047
|
+
element.addEventListener("touchcancel", handlers.onTouchEnd);
|
|
3048
|
+
}
|
|
3049
|
+
function onVisibilityChange() {
|
|
3050
|
+
if (document.visibilityState === "hidden") handlers.onInterrupt();
|
|
3051
|
+
}
|
|
3052
|
+
function destroy() {
|
|
3053
|
+
detach();
|
|
3054
|
+
setBody(null);
|
|
3055
|
+
if (typeof window === "undefined") return;
|
|
3056
|
+
window.removeEventListener("blur", handlers.onInterrupt);
|
|
3057
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
3058
|
+
}
|
|
3059
|
+
if (typeof window !== "undefined") {
|
|
3060
|
+
window.addEventListener("blur", handlers.onInterrupt);
|
|
3061
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
3062
|
+
}
|
|
3063
|
+
return {
|
|
3064
|
+
attach,
|
|
3065
|
+
detach,
|
|
3066
|
+
setBody,
|
|
3067
|
+
destroy
|
|
3068
|
+
};
|
|
3069
|
+
}
|
|
3070
|
+
//#endregion
|
|
3071
|
+
//#region src/motion/uikit/sheet.ts
|
|
3072
|
+
/**
|
|
3073
|
+
* @file sheet.ts
|
|
3074
|
+
* @input Nothing; data only
|
|
3075
|
+
* @output Exports `sheet`, the sheet's release constants. They say when
|
|
3076
|
+
* UISheetPresentationController counts a release as a flick and how near a
|
|
3077
|
+
* detent a flick counts as on it. They also give how far ahead a release is
|
|
3078
|
+
* projected, and the speed below which it is not
|
|
3079
|
+
* @position The sheet domain of the UIKit constants table (motion/uikit).
|
|
3080
|
+
* Its springs are `springs.sheetPresent`, `.sheetDismiss`, `.sheetDetent`,
|
|
3081
|
+
* `.sheetReleaseFast` and `.sheetDismissSwipe`
|
|
3082
|
+
*
|
|
3083
|
+
* Read from UIKit with a `[.medium(), .large()]` sheet in an injected host
|
|
3084
|
+
* app. Speeds are in pt/s (CSS px/s).
|
|
3085
|
+
*/
|
|
3086
|
+
const sheet = { release: {
|
|
3087
|
+
/**
|
|
3088
|
+
* Release speed (pt/s, in either direction) from which UIKit's sheet
|
|
3089
|
+
* counts a release as a flick. A sheet's flick goes at least to the next
|
|
3090
|
+
* position beyond where it is in its direction (`detentTolerance`). It
|
|
3091
|
+
* goes on past it when its projection passes it. The same speed
|
|
3092
|
+
* switches UIKit's settle from `springs.sheetDetent` (critically damped)
|
|
3093
|
+
* to `springs.sheetReleaseFast` (80 % damping). An interactive dismissal
|
|
3094
|
+
* at it takes `springs.sheetDismissSwipe`. Inside the measured bracket.
|
|
3095
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
3096
|
+
* iPhone 17 Pro, Oct 23 and Oct 24 2026. Of 134 drag releases, 55 had
|
|
3097
|
+
* their CASpringAnimation read. Every one up to 996.7 pt/s had damping
|
|
3098
|
+
* 36.515 (ζ 1), and every one from 1028.3 pt/s on had 29.212 (ζ 0.8).
|
|
3099
|
+
* So the switch lies in (996.7, 1028.3]. With a 0.1 s projection, all
|
|
3100
|
+
* 134 outcomes fit a flick threshold from 997 to 1028 pt/s.
|
|
3101
|
+
*/
|
|
3102
|
+
fastSpeed: 1008,
|
|
3103
|
+
/**
|
|
3104
|
+
* How far ahead a release is projected, as seconds of its velocity.
|
|
3105
|
+
* UIKit's sheet projects a release to `offset + velocity × this`, and the
|
|
3106
|
+
* dismissed position (fully off screen) counts as one of its positions.
|
|
3107
|
+
* A slow release settles on the position nearest this landing. A flick
|
|
3108
|
+
* goes to the first position at or past it. Inside the measured bracket.
|
|
3109
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
3110
|
+
* iPhone 17 Pro, Oct 23 to Oct 25 2026. There were 164 drag releases
|
|
3111
|
+
* of a [.medium(), .large()] sheet, from 0 to 4000 pt/s. Each gave the
|
|
3112
|
+
* offset and velocity of its last drag update and the detent it
|
|
3113
|
+
* settled on. With `fastSpeed`'s flick branch and no projection below
|
|
3114
|
+
* 250 pt/s, every release fits any value from 0.092 to 0.104 s.
|
|
3115
|
+
*/
|
|
3116
|
+
projectionSeconds: .1,
|
|
3117
|
+
/**
|
|
3118
|
+
* Release speed (pt/s) below which a release is not projected: the sheet
|
|
3119
|
+
* settles on the position nearest where it was let go. Core cancels a
|
|
3120
|
+
* release that moves back toward its start before this applies. Inside
|
|
3121
|
+
* the measured bracket.
|
|
3122
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
3123
|
+
* iPhone 17 Pro, Oct 25 2026. There were 30 releases of drags from the
|
|
3124
|
+
* medium detent. Each went past the midpoint toward large, or most of
|
|
3125
|
+
* the way to gone, then turned back. Each one let go at up to 244 pt/s
|
|
3126
|
+
* settled on the position nearest where it was let go. From 250.6 pt/s
|
|
3127
|
+
* on, the projection decided. So the switch lies in (244, 250.6].
|
|
3128
|
+
*/
|
|
3129
|
+
minProjectionSpeed: 250,
|
|
3130
|
+
/**
|
|
3131
|
+
* How close to a position (pt) a flick's offset counts as on it, so the
|
|
3132
|
+
* next position beyond is the one after it. Inside the measured bracket.
|
|
3133
|
+
* @source measured: UIKit lab (injected host app), iOS 26.2 simulator,
|
|
3134
|
+
* iPhone 17 Pro, Oct 24 2026. Two flicks released exactly on the medium
|
|
3135
|
+
* detent went on to the next position in their direction. One released
|
|
3136
|
+
* 6.7 pt above it, moving down, stopped at medium. So any value from 0
|
|
3137
|
+
* to 6.6 pt fits.
|
|
3138
|
+
*/
|
|
3139
|
+
detentTolerance: 1
|
|
3140
|
+
} };
|
|
3141
|
+
//#endregion
|
|
3142
|
+
//#region src/BottomSheet/sheetRelease.ts
|
|
3143
|
+
const PROJECTION_FACTOR = .998 / .0020000000000000018;
|
|
3144
|
+
/** A mouse or pen release shorter than this is judged where it was let go. */
|
|
3145
|
+
const PROJECTION_MIN_TRAVEL = 48;
|
|
3146
|
+
/**
|
|
3147
|
+
* A touch release takes UIKit's sheet values, with closed counted as one more
|
|
3148
|
+
* position. It is projected 0.1 s ahead, a release under 250 px/s is not
|
|
3149
|
+
* projected, and from 1008 px/s it is a flick that lands on the first position
|
|
3150
|
+
* at or past its projection. A release moving back toward where the drag
|
|
3151
|
+
* began cancels to that stop.
|
|
3152
|
+
*/
|
|
3153
|
+
function resolveTouchRelease(input) {
|
|
3154
|
+
const { offsets, height, offset, velocity } = input;
|
|
3155
|
+
const maxOffset = offsets[offsets.length - 1] ?? 0;
|
|
3156
|
+
const shortestHeight = visibleHeightForOffset(height, maxOffset, input.reserve);
|
|
3157
|
+
const { fastSpeed, minProjectionSpeed, projectionSeconds, detentTolerance } = sheet.release;
|
|
3158
|
+
const points = [...offsets, maxOffset + shortestHeight];
|
|
3159
|
+
const { index } = resolveSnapPoint({
|
|
3160
|
+
points,
|
|
3161
|
+
position: offset,
|
|
3162
|
+
velocity: velocity * 1e3,
|
|
3163
|
+
flickThreshold: input.travel > 8 ? fastSpeed : Number.POSITIVE_INFINITY,
|
|
3164
|
+
tolerance: detentTolerance,
|
|
3165
|
+
flickPastProjection: true,
|
|
3166
|
+
projection: {
|
|
3167
|
+
seconds: projectionSeconds,
|
|
3168
|
+
minSpeed: minProjectionSpeed
|
|
3169
|
+
},
|
|
3170
|
+
start: input.baseOffset
|
|
3171
|
+
});
|
|
3172
|
+
if (index === points.length - 1) return {
|
|
3173
|
+
kind: "close",
|
|
3174
|
+
exit: {
|
|
3175
|
+
distance: Math.max(0, height - offset),
|
|
3176
|
+
velocity: velocity * 1e3
|
|
3177
|
+
}
|
|
3178
|
+
};
|
|
3179
|
+
return {
|
|
3180
|
+
kind: "settle",
|
|
3181
|
+
target: points[index] ?? maxOffset
|
|
3182
|
+
};
|
|
3183
|
+
}
|
|
3184
|
+
/**
|
|
3185
|
+
* A mouse or pen release coasts on the scroll view's deceleration. One that
|
|
3186
|
+
* would coast past the dismiss line closes the sheet; any other settles on
|
|
3187
|
+
* the stop nearest where it would come to rest, in the drag's direction.
|
|
3188
|
+
*/
|
|
3189
|
+
function resolvePointerRelease(input) {
|
|
3190
|
+
const { offsets, offset } = input;
|
|
3191
|
+
const maxOffset = offsets[offsets.length - 1] ?? 0;
|
|
3192
|
+
const projected = input.travel > PROJECTION_MIN_TRAVEL ? offset + input.velocity * PROJECTION_FACTOR : offset;
|
|
3193
|
+
if (input.dir > 0 && projected > dismissTravelFor(input.height, offsets, input.reserve)) return {
|
|
3194
|
+
kind: "close",
|
|
3195
|
+
exit: null
|
|
3196
|
+
};
|
|
3197
|
+
return {
|
|
3198
|
+
kind: "settle",
|
|
3199
|
+
target: resolveSettleOffset(Math.min(Math.max(projected, 0), maxOffset), offsets, input.dir, input.baseOffset)
|
|
3200
|
+
};
|
|
3201
|
+
}
|
|
3202
|
+
/** Where a drag's release takes the sheet: a stop to settle on, or the close. */
|
|
3203
|
+
function resolveSheetRelease(input) {
|
|
3204
|
+
return input.isTouch ? resolveTouchRelease(input) : resolvePointerRelease(input);
|
|
3205
|
+
}
|
|
3206
|
+
//#endregion
|
|
3207
|
+
//#region src/BottomSheet/sheetTouchArm.ts
|
|
3208
|
+
/**
|
|
3209
|
+
* Travel past the point where a scroll ran out of content before the sheet
|
|
3210
|
+
* takes the rest of the pull: continuous with the scroll, yet a swipe that
|
|
3211
|
+
* merely comes to rest on the last pixel starts no drag on jitter.
|
|
3212
|
+
*/
|
|
3213
|
+
const CONTENT_END_HANDOFF_SLOP = 4;
|
|
3214
|
+
/** An Apple Pencil raises touch events marked `stylus`; its drag is a pen's. */
|
|
3215
|
+
function touchPointerType(touch) {
|
|
3216
|
+
return touch.touchType === "stylus" ? "pen" : "touch";
|
|
3217
|
+
}
|
|
3218
|
+
function findTouch(event, id) {
|
|
3219
|
+
return id == null ? void 0 : Array.from(event.changedTouches).find((touch) => touch.identifier === id);
|
|
3220
|
+
}
|
|
3221
|
+
/**
|
|
3222
|
+
* The body's touch path. Non-passive `touchmove` is the reliable scroll-to-drag
|
|
3223
|
+
* hand-off on touch: cancelling a move at a scroll edge stops the native
|
|
3224
|
+
* scroll and drives the sheet instead. Every touch on the body is tracked,
|
|
3225
|
+
* not only one that begins at an edge, because a swipe that starts mid-content
|
|
3226
|
+
* and scrolls to the end has to hand off too.
|
|
3227
|
+
*/
|
|
3228
|
+
function createSheetTouchArm(drive) {
|
|
3229
|
+
let arm = null;
|
|
3230
|
+
function releaseContentHold() {
|
|
3231
|
+
if (arm?.releaseContentHold != null) {
|
|
3232
|
+
arm.releaseContentHold();
|
|
3233
|
+
arm.releaseContentHold = null;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
function reset() {
|
|
3237
|
+
releaseContentHold();
|
|
3238
|
+
arm = null;
|
|
3239
|
+
}
|
|
3240
|
+
function promote(armed, touch, startY, timeStamp) {
|
|
3241
|
+
drive.begin({
|
|
3242
|
+
pointerId: armed.id,
|
|
3243
|
+
pointerType: touchPointerType(touch),
|
|
3244
|
+
startY,
|
|
3245
|
+
tracker: armed.tracker
|
|
3246
|
+
}, touch.clientY, timeStamp);
|
|
3247
|
+
drive.move(touch.clientY, timeStamp);
|
|
3248
|
+
}
|
|
3249
|
+
function onTouchStart(event) {
|
|
3250
|
+
const body = event.currentTarget;
|
|
3251
|
+
if (event.touches.length > 1) {
|
|
3252
|
+
reset();
|
|
3253
|
+
drive.yieldToPinch();
|
|
3254
|
+
return;
|
|
3255
|
+
}
|
|
3256
|
+
reset();
|
|
3257
|
+
const touch = event.changedTouches[0];
|
|
3258
|
+
if (!touch || isInsideNestedLayer(event.target, body)) return;
|
|
3259
|
+
const scrollers = scrollChainUnder(event.target, body);
|
|
3260
|
+
const bottom = chainAtBottom(scrollers) && (drive.activeOffset() > 0 || !chainScrolls(scrollers));
|
|
3261
|
+
const tracker = new VelocityTracker();
|
|
3262
|
+
tracker.add(0, touch.clientY, event.timeStamp);
|
|
3263
|
+
arm = {
|
|
3264
|
+
id: touch.identifier,
|
|
3265
|
+
startX: touch.clientX,
|
|
3266
|
+
startY: touch.clientY,
|
|
3267
|
+
scrollers,
|
|
3268
|
+
top: chainAtTop(scrollers),
|
|
3269
|
+
bottom,
|
|
3270
|
+
contentEndY: null,
|
|
3271
|
+
promotedAtContentEnd: false,
|
|
3272
|
+
releaseContentHold: null,
|
|
3273
|
+
tracker
|
|
3274
|
+
};
|
|
3275
|
+
}
|
|
3276
|
+
function moveDrag(event) {
|
|
3277
|
+
const touch = findTouch(event, drive.dragPointerId());
|
|
3278
|
+
if (!touch) return;
|
|
3279
|
+
const armed = arm;
|
|
3280
|
+
if (armed?.promotedAtContentEnd && armed.contentEndY != null) {
|
|
3281
|
+
if (touch.clientY >= armed.contentEndY) {
|
|
3282
|
+
armed.contentEndY = null;
|
|
3283
|
+
armed.promotedAtContentEnd = false;
|
|
3284
|
+
releaseContentHold();
|
|
3285
|
+
drive.cancel();
|
|
3286
|
+
return;
|
|
3287
|
+
}
|
|
3288
|
+
drive.move(touch.clientY, event.timeStamp);
|
|
3289
|
+
return;
|
|
3290
|
+
}
|
|
3291
|
+
if (event.cancelable) event.preventDefault();
|
|
3292
|
+
drive.move(touch.clientY, event.timeStamp);
|
|
3293
|
+
}
|
|
3294
|
+
function onTouchMove(event) {
|
|
3295
|
+
if (event.touches.length > 1) {
|
|
3296
|
+
reset();
|
|
3297
|
+
drive.yieldToPinch();
|
|
3298
|
+
return;
|
|
3299
|
+
}
|
|
3300
|
+
if (drive.dragPointerId() != null) {
|
|
3301
|
+
moveDrag(event);
|
|
3302
|
+
return;
|
|
3303
|
+
}
|
|
3304
|
+
const armed = arm;
|
|
3305
|
+
const touch = findTouch(event, armed?.id);
|
|
3306
|
+
if (armed == null || !touch) return;
|
|
3307
|
+
const delta = touch.clientY - armed.startY;
|
|
3308
|
+
armed.tracker.add(0, touch.clientY, event.timeStamp);
|
|
3309
|
+
const opposesTop = armed.top && delta > 0 && chainAtTop(armed.scrollers);
|
|
3310
|
+
const opposesBottom = armed.bottom && delta < 0 && chainAtBottom(armed.scrollers);
|
|
3311
|
+
const sideways = Math.abs(touch.clientX - armed.startX);
|
|
3312
|
+
const isMostlyVertical = Math.abs(delta) > sideways;
|
|
3313
|
+
if ((opposesTop || opposesBottom) && Math.abs(delta) >= 5 && isMostlyVertical && event.cancelable) event.preventDefault();
|
|
3314
|
+
if (isMostlyVertical && (opposesTop && delta > 8 || opposesBottom && delta < -8)) {
|
|
3315
|
+
if (event.cancelable) event.preventDefault();
|
|
3316
|
+
reset();
|
|
3317
|
+
promote(armed, touch, armed.startY, event.timeStamp);
|
|
3318
|
+
return;
|
|
3319
|
+
}
|
|
3320
|
+
if (Math.max(Math.abs(delta), sideways) > 8 && (armed.top || armed.bottom)) {
|
|
3321
|
+
if (!isMostlyVertical) {
|
|
3322
|
+
reset();
|
|
3323
|
+
return;
|
|
3324
|
+
}
|
|
3325
|
+
armed.top = false;
|
|
3326
|
+
armed.bottom = false;
|
|
3327
|
+
}
|
|
3328
|
+
if (armed.top && delta <= -5 && !chainAtBottom(armed.scrollers)) armed.top = false;
|
|
3329
|
+
if (armed.bottom && delta >= 5 && !chainAtTop(armed.scrollers)) armed.bottom = false;
|
|
3330
|
+
if (chainAtBottom(armed.scrollers)) {
|
|
3331
|
+
if (armed.contentEndY == null) {
|
|
3332
|
+
armed.contentEndY = touch.clientY;
|
|
3333
|
+
armed.releaseContentHold ??= holdAtEnd(armed.scrollers);
|
|
3334
|
+
} else if (armed.contentEndY - touch.clientY >= CONTENT_END_HANDOFF_SLOP) {
|
|
3335
|
+
armed.promotedAtContentEnd = true;
|
|
3336
|
+
promote(armed, touch, armed.contentEndY, event.timeStamp);
|
|
3337
|
+
}
|
|
3338
|
+
} else {
|
|
3339
|
+
armed.contentEndY = null;
|
|
3340
|
+
releaseContentHold();
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3343
|
+
function onTouchEnd(event) {
|
|
3344
|
+
reset();
|
|
3345
|
+
const pointerId = drive.dragPointerId();
|
|
3346
|
+
if (pointerId == null) return;
|
|
3347
|
+
const touch = findTouch(event, pointerId);
|
|
3348
|
+
if (touch) drive.end(touch.clientY, event.timeStamp);
|
|
3349
|
+
else if (event.touches.length === 0) drive.cancel();
|
|
3350
|
+
}
|
|
3351
|
+
return {
|
|
3352
|
+
onTouchStart,
|
|
3353
|
+
onTouchMove,
|
|
3354
|
+
onTouchEnd,
|
|
3355
|
+
reset
|
|
3356
|
+
};
|
|
3357
|
+
}
|
|
3358
|
+
//#endregion
|
|
3359
|
+
//#region src/BottomSheet/useSheetGestures.ts
|
|
3360
|
+
/** Drag, snap, and settle behavior of the sheet panel. */
|
|
3361
|
+
function useSheetGestures(options) {
|
|
3362
|
+
const { panel, body, isOpen, canDismiss, reserve, getSnapHeights, onScrimOpacity, onSnap, onDismiss, onTravelStart } = options;
|
|
3363
|
+
const isDragging = ref(false);
|
|
3364
|
+
const isReconciling = ref(false);
|
|
3365
|
+
const isOverflowing = ref(false);
|
|
3366
|
+
const dragOffset = ref(0);
|
|
3367
|
+
const settledOffset = ref(0);
|
|
3368
|
+
const settledLayoutOffset = ref(0);
|
|
3369
|
+
const scrollPreservationInset = ref(0);
|
|
3370
|
+
const scrimOpacity = ref(1);
|
|
3371
|
+
const sheetHeight = ref(0);
|
|
3372
|
+
const heldClose = ref(null);
|
|
3373
|
+
const dragExit = ref(null);
|
|
3374
|
+
const isDismissedByTouchDrag = ref(false);
|
|
3375
|
+
let dragState = null;
|
|
3376
|
+
/** The scrim of the stop a drag's close left, until the host answers the close. */
|
|
3377
|
+
let pendingDismissal = null;
|
|
3378
|
+
let reconcileToken = 0;
|
|
3379
|
+
let observer = null;
|
|
3380
|
+
let session;
|
|
3381
|
+
const activeOffset = computed(() => isDragging.value ? dragOffset.value : settledOffset.value);
|
|
3382
|
+
/** Dragging above the base stop restores the full layout height below the viewport. */
|
|
3383
|
+
const layoutOffset = computed(() => {
|
|
3384
|
+
if (heldClose.value != null) return heldClose.value.layoutOffset;
|
|
3385
|
+
if (isDragging.value) return dragOffset.value < settledOffset.value ? 0 : settledLayoutOffset.value;
|
|
3386
|
+
return settledLayoutOffset.value;
|
|
3387
|
+
});
|
|
3388
|
+
function measureNaturalHeight() {
|
|
3389
|
+
const element = panel.value;
|
|
3390
|
+
if (!element) return 0;
|
|
3391
|
+
const inlineHeight = element.style.height;
|
|
3392
|
+
if (inlineHeight === "") return element.getBoundingClientRect().height;
|
|
3393
|
+
element.style.height = "";
|
|
3394
|
+
const height = element.getBoundingClientRect().height;
|
|
3395
|
+
element.style.height = inlineHeight;
|
|
3396
|
+
return height;
|
|
3397
|
+
}
|
|
3398
|
+
function resolveDetents() {
|
|
3399
|
+
const measured = measureNaturalHeight();
|
|
3400
|
+
if (measured > 0) sheetHeight.value = measured;
|
|
3401
|
+
const height = measured > 0 ? measured : sheetHeight.value;
|
|
3402
|
+
const inset = reserve.value;
|
|
3403
|
+
const visible = visibleHeightForOffset(height, 0, inset);
|
|
3404
|
+
const offsets = computeDetentOffsets(visible, getSnapHeights());
|
|
3405
|
+
return {
|
|
3406
|
+
height,
|
|
3407
|
+
offsets,
|
|
3408
|
+
peekOffset: peekOffsetFor(offsets, visible),
|
|
3409
|
+
reserve: inset
|
|
3410
|
+
};
|
|
3411
|
+
}
|
|
3412
|
+
function scrimFor(offset, detents) {
|
|
3413
|
+
return scrimOpacityForOffset(offset, detents.offsets, dismissTravelFor(detents.height, detents.offsets, detents.reserve), detents.peekOffset);
|
|
3414
|
+
}
|
|
3415
|
+
function reportScrim(opacity) {
|
|
3416
|
+
scrimOpacity.value = opacity;
|
|
3417
|
+
onScrimOpacity(opacity);
|
|
3418
|
+
}
|
|
3419
|
+
async function reconcileLayout(targetLayoutOffset) {
|
|
3420
|
+
const token = ++reconcileToken;
|
|
3421
|
+
isReconciling.value = true;
|
|
3422
|
+
await nextTick();
|
|
3423
|
+
if (token !== reconcileToken) return;
|
|
3424
|
+
settledLayoutOffset.value = targetLayoutOffset;
|
|
3425
|
+
await nextTick();
|
|
3426
|
+
if (token !== reconcileToken) return;
|
|
3427
|
+
isReconciling.value = false;
|
|
3428
|
+
scrollPreservationInset.value = 0;
|
|
3429
|
+
}
|
|
3430
|
+
function settleAt(target, fromOffset, detents) {
|
|
3431
|
+
const targetLayoutOffset = target === detents.peekOffset ? 0 : target;
|
|
3432
|
+
settledOffset.value = target;
|
|
3433
|
+
scrollPreservationInset.value = Math.max(0, fromOffset - targetLayoutOffset - naturalEndGapFor(body.value));
|
|
3434
|
+
reportScrim(scrimFor(target, detents));
|
|
3435
|
+
onSnap(visibleHeightForOffset(detents.height, target, detents.reserve));
|
|
3436
|
+
if (target !== fromOffset) hapticTick();
|
|
3437
|
+
if (targetLayoutOffset === settledLayoutOffset.value && !isReconciling.value) return;
|
|
3438
|
+
reconcileLayout(targetLayoutOffset);
|
|
3439
|
+
}
|
|
3440
|
+
function clearDragClose() {
|
|
3441
|
+
pendingDismissal = null;
|
|
3442
|
+
heldClose.value = null;
|
|
3443
|
+
dragExit.value = null;
|
|
3444
|
+
isDismissedByTouchDrag.value = false;
|
|
3445
|
+
}
|
|
3446
|
+
/**
|
|
3447
|
+
* Asks the host to close. The sheet holds where the finger left it, so the
|
|
3448
|
+
* exit starts from there. The host answers in its next render: a host that
|
|
3449
|
+
* keeps the sheet open sends it back to its stop, the scrim with it.
|
|
3450
|
+
*/
|
|
3451
|
+
function closeSheet(exit, state) {
|
|
3452
|
+
if (!canDismiss.value) {
|
|
3453
|
+
settleAt(state.offsets[state.offsets.length - 1] ?? 0, state.baseOffset, state);
|
|
3454
|
+
return;
|
|
3455
|
+
}
|
|
3456
|
+
heldClose.value = {
|
|
3457
|
+
offset: dragOffset.value,
|
|
3458
|
+
layoutOffset: layoutOffset.value
|
|
3459
|
+
};
|
|
3460
|
+
isDismissedByTouchDrag.value = state.pointerType === "touch";
|
|
3461
|
+
dragExit.value = exit;
|
|
3462
|
+
const request = { restingScrim: scrimFor(state.baseOffset, state) };
|
|
3463
|
+
pendingDismissal = request;
|
|
3464
|
+
onDismiss();
|
|
3465
|
+
nextTick(() => {
|
|
3466
|
+
if (pendingDismissal !== request) return;
|
|
3467
|
+
pendingDismissal = null;
|
|
3468
|
+
if (!isOpen.value) return;
|
|
3469
|
+
clearDragClose();
|
|
3470
|
+
reportScrim(request.restingScrim);
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
function beginDrag(start, clientY, timeStamp) {
|
|
3474
|
+
clearDragClose();
|
|
3475
|
+
start.tracker.add(0, clientY, timeStamp);
|
|
3476
|
+
dragState = {
|
|
3477
|
+
...resolveDetents(),
|
|
3478
|
+
...start,
|
|
3479
|
+
baseOffset: settledOffset.value,
|
|
3480
|
+
hasTraveled: false
|
|
3481
|
+
};
|
|
3482
|
+
dragOffset.value = settledOffset.value;
|
|
3483
|
+
isDragging.value = true;
|
|
3484
|
+
}
|
|
3485
|
+
function moveDrag(clientY, timeStamp) {
|
|
3486
|
+
const state = dragState;
|
|
3487
|
+
if (!state) return;
|
|
3488
|
+
state.tracker.add(0, clientY, timeStamp);
|
|
3489
|
+
const shown = stretchedOffset(state.baseOffset + clientY - state.startY, state.offsets, state);
|
|
3490
|
+
dragOffset.value = shown;
|
|
3491
|
+
if (!state.hasTraveled && shown !== state.baseOffset) {
|
|
3492
|
+
state.hasTraveled = true;
|
|
3493
|
+
onTravelStart?.();
|
|
3494
|
+
}
|
|
3495
|
+
reportScrim(scrimFor(shown, state));
|
|
3496
|
+
}
|
|
3497
|
+
function endDrag(clientY, timeStamp) {
|
|
3498
|
+
const state = dragState;
|
|
3499
|
+
dragState = null;
|
|
3500
|
+
session.detach();
|
|
3501
|
+
if (!state) return;
|
|
3502
|
+
const delta = clientY - state.startY;
|
|
3503
|
+
if (state.tracker.lastSample?.y !== clientY) state.tracker.add(0, clientY, timeStamp);
|
|
3504
|
+
const release = resolveSheetRelease({
|
|
3505
|
+
offset: Math.max(0, state.baseOffset + delta),
|
|
3506
|
+
velocity: state.tracker.velocity(timeStamp).y / 1e3,
|
|
3507
|
+
height: state.height || 1,
|
|
3508
|
+
dir: Math.sign(delta),
|
|
3509
|
+
travel: Math.abs(delta),
|
|
3510
|
+
baseOffset: state.baseOffset,
|
|
3511
|
+
offsets: state.offsets,
|
|
3512
|
+
reserve: state.reserve,
|
|
3513
|
+
isTouch: state.pointerType === "touch"
|
|
3514
|
+
});
|
|
3515
|
+
if (release.kind === "close") closeSheet(release.exit, state);
|
|
3516
|
+
isDragging.value = false;
|
|
3517
|
+
if (release.kind === "settle") settleAt(release.target, state.baseOffset, state);
|
|
3518
|
+
}
|
|
3519
|
+
/** The drag in flight returns to its stop; the arms keep tracking their contacts. */
|
|
3520
|
+
function dropDrag() {
|
|
3521
|
+
const state = dragState;
|
|
3522
|
+
dragState = null;
|
|
3523
|
+
session.detach();
|
|
3524
|
+
if (!state) return;
|
|
3525
|
+
isDragging.value = false;
|
|
3526
|
+
dragOffset.value = state.baseOffset;
|
|
3527
|
+
settledOffset.value = state.baseOffset;
|
|
3528
|
+
reportScrim(scrimFor(state.baseOffset, state));
|
|
3529
|
+
}
|
|
3530
|
+
const dragPointerId = () => dragState?.pointerId ?? null;
|
|
3531
|
+
const touchArm = createSheetTouchArm({
|
|
3532
|
+
activeOffset: () => activeOffset.value,
|
|
3533
|
+
dragPointerId: () => dragState?.viaTouch ? dragState.pointerId : null,
|
|
3534
|
+
begin: (start, clientY, timeStamp) => beginDrag({
|
|
3535
|
+
...start,
|
|
3536
|
+
viaTouch: true
|
|
3537
|
+
}, clientY, timeStamp),
|
|
3538
|
+
move: moveDrag,
|
|
3539
|
+
end: endDrag,
|
|
3540
|
+
cancel: dropDrag,
|
|
3541
|
+
yieldToPinch: cancelDrag
|
|
3542
|
+
});
|
|
3543
|
+
const pointerArm = createSheetPointerArm({
|
|
3544
|
+
body: () => body.value,
|
|
3545
|
+
dragPointerId,
|
|
3546
|
+
isTouchDrag: () => dragState?.viaTouch ?? false,
|
|
3547
|
+
attach: () => session.attach(),
|
|
3548
|
+
detach: () => session.detach(),
|
|
3549
|
+
begin: (start, clientY, timeStamp) => beginDrag({
|
|
3550
|
+
...start,
|
|
3551
|
+
viaTouch: false
|
|
3552
|
+
}, clientY, timeStamp),
|
|
3553
|
+
move: moveDrag,
|
|
3554
|
+
end: endDrag,
|
|
3555
|
+
cancel: cancelDrag
|
|
3556
|
+
});
|
|
3557
|
+
/** Every arm and any drag in flight let go: the sheet returns to its stop. */
|
|
3558
|
+
function cancelDrag() {
|
|
3559
|
+
pointerArm.reset();
|
|
3560
|
+
touchArm.reset();
|
|
3561
|
+
dropDrag();
|
|
3562
|
+
}
|
|
3563
|
+
function updateOverflow() {
|
|
3564
|
+
const element = body.value;
|
|
3565
|
+
isOverflowing.value = element != null && (element.scrollHeight > element.clientHeight + 1 || element.scrollWidth > element.clientWidth + 1);
|
|
3566
|
+
}
|
|
3567
|
+
function recordSheetHeight(height) {
|
|
3568
|
+
if (isDragging.value || settledLayoutOffset.value > 0 || isReconciling.value) return;
|
|
3569
|
+
if (height > 0) sheetHeight.value = height;
|
|
3570
|
+
}
|
|
3571
|
+
session = createSheetPointerSession({
|
|
3572
|
+
onPointerMove: pointerArm.onPointerMove,
|
|
3573
|
+
onPointerUp: pointerArm.onPointerUp,
|
|
3574
|
+
onPointerCancel: pointerArm.onPointerCancel,
|
|
3575
|
+
onTouchStart: touchArm.onTouchStart,
|
|
3576
|
+
onTouchMove: touchArm.onTouchMove,
|
|
3577
|
+
onTouchEnd: touchArm.onTouchEnd,
|
|
3578
|
+
onInterrupt: () => cancelDrag()
|
|
3579
|
+
});
|
|
3580
|
+
watch(panel, (element) => {
|
|
3581
|
+
observer?.disconnect();
|
|
3582
|
+
observer = null;
|
|
3583
|
+
if (!element) return;
|
|
3584
|
+
if (typeof ResizeObserver === "undefined") {
|
|
3585
|
+
recordSheetHeight(element.getBoundingClientRect().height);
|
|
3586
|
+
return;
|
|
3587
|
+
}
|
|
3588
|
+
observer = new ResizeObserver((entries) => {
|
|
3589
|
+
const entry = entries[entries.length - 1];
|
|
3590
|
+
recordSheetHeight(entry?.borderBoxSize?.[0]?.blockSize ?? element.getBoundingClientRect().height);
|
|
3591
|
+
updateOverflow();
|
|
3592
|
+
});
|
|
3593
|
+
observer.observe(element);
|
|
3594
|
+
}, { immediate: true });
|
|
3595
|
+
watch(body, (element) => {
|
|
3596
|
+
session.setBody(element);
|
|
3597
|
+
updateOverflow();
|
|
3598
|
+
}, { immediate: true });
|
|
3599
|
+
watch(isOpen, (open) => {
|
|
3600
|
+
++reconcileToken;
|
|
3601
|
+
cancelDrag();
|
|
3602
|
+
isReconciling.value = false;
|
|
3603
|
+
scrollPreservationInset.value = 0;
|
|
3604
|
+
if (!open) {
|
|
3605
|
+
pendingDismissal = null;
|
|
3606
|
+
return;
|
|
3607
|
+
}
|
|
3608
|
+
clearDragClose();
|
|
3609
|
+
dragOffset.value = 0;
|
|
3610
|
+
settledOffset.value = 0;
|
|
3611
|
+
settledLayoutOffset.value = 0;
|
|
3612
|
+
scrimOpacity.value = 1;
|
|
3613
|
+
if (typeof ResizeObserver === "undefined") nextTick(() => recordSheetHeight(panel.value?.getBoundingClientRect().height ?? 0));
|
|
3614
|
+
});
|
|
3615
|
+
watch(canDismiss, (allowed) => {
|
|
3616
|
+
if (!allowed) cancelDrag();
|
|
3617
|
+
});
|
|
3618
|
+
onBeforeUnmount(() => {
|
|
3619
|
+
session.destroy();
|
|
3620
|
+
observer?.disconnect();
|
|
3621
|
+
observer = null;
|
|
3622
|
+
});
|
|
3623
|
+
const panelTransform = computed(() => {
|
|
3624
|
+
const translation = (heldClose.value?.offset ?? activeOffset.value) - layoutOffset.value;
|
|
3625
|
+
return translation !== 0 ? `translateY(${translation}px)` : void 0;
|
|
3626
|
+
});
|
|
3627
|
+
const panelHeight = computed(() => {
|
|
3628
|
+
if (layoutOffset.value <= 0 || sheetHeight.value <= 0) return void 0;
|
|
3629
|
+
return `${Math.max(0, sheetHeight.value - layoutOffset.value)}px`;
|
|
3630
|
+
});
|
|
3631
|
+
return {
|
|
3632
|
+
isDragging,
|
|
3633
|
+
isReconciling,
|
|
3634
|
+
isOverflowing,
|
|
3635
|
+
isAtFullHeight: computed(() => settledOffset.value === 0),
|
|
3636
|
+
panelTransform,
|
|
3637
|
+
panelHeight,
|
|
3638
|
+
scrollPreservationInset,
|
|
3639
|
+
scrimOpacity,
|
|
3640
|
+
dragExit,
|
|
3641
|
+
isDismissedByTouchDrag,
|
|
3642
|
+
onHandlePointerDown: pointerArm.onHandlePointerDown,
|
|
3643
|
+
onBodyPointerDown: pointerArm.onBodyPointerDown,
|
|
3644
|
+
updateOverflow
|
|
3645
|
+
};
|
|
3646
|
+
}
|
|
3647
|
+
//#endregion
|
|
3648
|
+
//#region src/BottomSheet/useSheetReserve.ts
|
|
3649
|
+
const BLOCK_SIZE_PROPERTIES = [
|
|
3650
|
+
"height",
|
|
3651
|
+
"min-height",
|
|
3652
|
+
"max-height",
|
|
3653
|
+
"block-size",
|
|
3654
|
+
"min-block-size",
|
|
3655
|
+
"max-block-size"
|
|
3656
|
+
];
|
|
3657
|
+
function camelCase(property) {
|
|
3658
|
+
return property.replace(/-([a-z])/g, (_match, letter) => letter.toUpperCase());
|
|
3659
|
+
}
|
|
3660
|
+
/** Whether an inline `style` binding sets any block size. */
|
|
3661
|
+
function styleSetsBlockSize(style) {
|
|
3662
|
+
if (Array.isArray(style)) return style.some(styleSetsBlockSize);
|
|
3663
|
+
if (typeof style === "string") return BLOCK_SIZE_PROPERTIES.some((property) => new RegExp(`(^|;)\\s*${property}\\s*:`, "i").test(style));
|
|
3664
|
+
if (style == null || typeof style !== "object") return false;
|
|
3665
|
+
const record = style;
|
|
3666
|
+
return BLOCK_SIZE_PROPERTIES.some((property) => record[property] != null || record[camelCase(property)] != null);
|
|
3667
|
+
}
|
|
3668
|
+
/**
|
|
3669
|
+
* Whether the caller sizes the sheet through its fallthrough attributes: an
|
|
3670
|
+
* inline block size, or any class, whose rules can size it too. Nothing
|
|
3671
|
+
* extends such a sheet by the reserve.
|
|
3672
|
+
*/
|
|
3673
|
+
function isSizedByCaller(attrs) {
|
|
3674
|
+
const className = attrs.class;
|
|
3675
|
+
return (Array.isArray(className) ? className.length > 0 : className != null && className !== "" && !(typeof className === "object" && Object.keys(className).length === 0)) || styleSetsBlockSize(attrs.style);
|
|
3676
|
+
}
|
|
3677
|
+
/**
|
|
3678
|
+
* How far the sheet's surface reaches below the screen. Only a finger
|
|
3679
|
+
* stretches the sheet past MIN_RESERVE, so a device with a touch pointer keeps
|
|
3680
|
+
* 40% of the layout viewport while the sheet is presented, enough that a pull
|
|
3681
|
+
* past the top never shows the page under it. A device without one, and a
|
|
3682
|
+
* sheet the caller sizes, keep MIN_RESERVE.
|
|
3683
|
+
*/
|
|
3684
|
+
function useSheetReserve(isPresented, isSized) {
|
|
3685
|
+
const hasTouchPointer = useMediaQuery("(any-pointer: coarse)");
|
|
3686
|
+
const viewportHeight = shallowRef(0);
|
|
3687
|
+
const tracksViewport = computed(() => isPresented.value && hasTouchPointer.value && !isSized());
|
|
3688
|
+
watch(tracksViewport, (tracks, _previous, onCleanup) => {
|
|
3689
|
+
if (!tracks || typeof window === "undefined") {
|
|
3690
|
+
viewportHeight.value = 0;
|
|
3691
|
+
return;
|
|
3692
|
+
}
|
|
3693
|
+
const read = () => {
|
|
3694
|
+
viewportHeight.value = window.innerHeight;
|
|
3695
|
+
};
|
|
3696
|
+
read();
|
|
3697
|
+
window.addEventListener("resize", read);
|
|
3698
|
+
onCleanup(() => window.removeEventListener("resize", read));
|
|
3699
|
+
}, { immediate: true });
|
|
3700
|
+
return computed(() => viewportHeight.value > 0 ? sheetReserve(viewportHeight.value) : 48);
|
|
3701
|
+
}
|
|
3702
|
+
//#endregion
|
|
3703
|
+
//#region src/BottomSheet/BottomSheetPanel.vue
|
|
3704
|
+
const _hoisted_1$1 = [
|
|
3705
|
+
"data-state",
|
|
3706
|
+
"data-height",
|
|
3707
|
+
"data-dragging",
|
|
3708
|
+
"data-reconciling",
|
|
3709
|
+
"data-exit"
|
|
3710
|
+
];
|
|
3711
|
+
const _hoisted_2$1 = [
|
|
3712
|
+
"data-keyboard",
|
|
3713
|
+
"tabindex",
|
|
3714
|
+
"role",
|
|
3715
|
+
"aria-label"
|
|
3716
|
+
];
|
|
3717
|
+
const _hoisted_3$1 = ["data-padding"];
|
|
3718
|
+
const MOBILE_KEYBOARD_BOTTOM_CLEARANCE = 48;
|
|
3719
|
+
const _sfc_main$1 = /*@__PURE__*/ defineComponent({
|
|
3720
|
+
name: "AstryxBottomSheetPanel",
|
|
3721
|
+
__name: "BottomSheetPanel",
|
|
3722
|
+
props: {
|
|
3723
|
+
state: {},
|
|
3724
|
+
label: {},
|
|
3725
|
+
height: { default: "capped" },
|
|
3726
|
+
padding: { default: void 0 },
|
|
3727
|
+
snapPoints: { default: void 0 },
|
|
3728
|
+
isSwipeDismissAllowed: {
|
|
3729
|
+
type: Boolean,
|
|
3730
|
+
default: true
|
|
3731
|
+
},
|
|
3732
|
+
isPageScrollLocked: {
|
|
3733
|
+
type: Boolean,
|
|
3734
|
+
default: false
|
|
3735
|
+
}
|
|
3736
|
+
},
|
|
3737
|
+
emits: [
|
|
3738
|
+
"dismiss",
|
|
3739
|
+
"scrimOpacity",
|
|
3740
|
+
"motionStart",
|
|
3741
|
+
"motionComplete",
|
|
3742
|
+
"snap",
|
|
3743
|
+
"scrimFade"
|
|
3744
|
+
],
|
|
3745
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
3746
|
+
const props = __props;
|
|
3747
|
+
const emit = __emit;
|
|
3748
|
+
resetLayerScopedContext();
|
|
3749
|
+
provideLayerDepth();
|
|
3750
|
+
provideLayoutContainer("bottom-sheet");
|
|
3751
|
+
const HEIGHT_BUDGETS = {
|
|
3752
|
+
hug: "92dvh",
|
|
3753
|
+
capped: "62dvh",
|
|
3754
|
+
tall: "92dvh"
|
|
3755
|
+
};
|
|
3756
|
+
const panel = useTemplateRef("panel");
|
|
3757
|
+
const body = useTemplateRef("body");
|
|
3758
|
+
const content = useTemplateRef("content");
|
|
3759
|
+
useScrollbars(body);
|
|
3760
|
+
const isInteractive = computed(() => props.state === "open");
|
|
3761
|
+
const attrs = useAttrs();
|
|
3762
|
+
const reserve = useSheetReserve(computed(() => props.state !== "hidden"), () => isSizedByCaller(attrs));
|
|
3763
|
+
const heightKind = computed(() => {
|
|
3764
|
+
const height = props.height;
|
|
3765
|
+
return height === "hug" || height === "capped" || height === "tall" ? height : "custom";
|
|
3766
|
+
});
|
|
3767
|
+
const budget = computed(() => {
|
|
3768
|
+
const height = props.height;
|
|
3769
|
+
if (typeof height === "string" && height in HEIGHT_BUDGETS) return HEIGHT_BUDGETS[height];
|
|
3770
|
+
return typeof height === "number" ? `${height}px` : height;
|
|
3771
|
+
});
|
|
3772
|
+
let dismissKeyboard = () => {};
|
|
3773
|
+
const gestures = useSheetGestures({
|
|
3774
|
+
panel,
|
|
3775
|
+
body,
|
|
3776
|
+
isOpen: isInteractive,
|
|
3777
|
+
canDismiss: computed(() => props.isSwipeDismissAllowed),
|
|
3778
|
+
reserve,
|
|
3779
|
+
getSnapHeights: () => {
|
|
3780
|
+
const points = props.snapPoints;
|
|
3781
|
+
if (!points?.length || typeof window === "undefined") return [];
|
|
3782
|
+
return resolveSnapPoints(points, window.innerHeight);
|
|
3783
|
+
},
|
|
3784
|
+
onScrimOpacity: (opacity) => emit("scrimOpacity", opacity),
|
|
3785
|
+
onSnap: (visibleHeight) => emit("snap", visibleHeight),
|
|
3786
|
+
onDismiss: () => emit("dismiss"),
|
|
3787
|
+
onTravelStart: () => dismissKeyboard(panel.value ?? void 0)
|
|
3788
|
+
});
|
|
3789
|
+
dismissKeyboard = useMobileKeyboard(panel, {
|
|
3790
|
+
move: "ride",
|
|
3791
|
+
inset: true,
|
|
3792
|
+
body,
|
|
3793
|
+
offset: MOBILE_KEYBOARD_BOTTOM_CLEARANCE,
|
|
3794
|
+
isEnabled: () => props.height === "tall" && props.state !== "hidden",
|
|
3795
|
+
isExpanded: gestures.isAtFullHeight,
|
|
3796
|
+
isOpen: isInteractive,
|
|
3797
|
+
isPageScrollLocked: () => props.isPageScrollLocked
|
|
3798
|
+
}).dismiss;
|
|
3799
|
+
const isCrossFade = computed(() => gestures.isDismissedByTouchDrag.value && defaultPrefersReducedMotion());
|
|
3800
|
+
const playedDragExit = computed(() => {
|
|
3801
|
+
const exit = gestures.dragExit.value;
|
|
3802
|
+
return exit != null && !isCrossFade.value && !defaultPrefersReducedMotion() && supportsWebAnimations() ? exit : null;
|
|
3803
|
+
});
|
|
3804
|
+
const holdsDragClose = computed(() => gestures.dragExit.value != null && (playedDragExit.value != null || isCrossFade.value));
|
|
3805
|
+
watch(playedDragExit, (exit) => {
|
|
3806
|
+
emit("scrimFade", exit != null && panel.value != null ? dragExitFade(panel.value, exit) : null);
|
|
3807
|
+
}, { flush: "sync" });
|
|
3808
|
+
const panelStyle = computed(() => {
|
|
3809
|
+
const style = {
|
|
3810
|
+
"--_sheet-budget": budget.value,
|
|
3811
|
+
"--_sheet-reserve": `${reserve.value}px`
|
|
3812
|
+
};
|
|
3813
|
+
if (isInteractive.value) {
|
|
3814
|
+
style.transform = gestures.panelTransform.value;
|
|
3815
|
+
style.height = gestures.panelHeight.value;
|
|
3816
|
+
} else if (props.state === "exiting") {
|
|
3817
|
+
style.height = gestures.panelHeight.value;
|
|
3818
|
+
if (holdsDragClose.value) style.transform = gestures.panelTransform.value ?? "translateY(0px)";
|
|
3819
|
+
}
|
|
3820
|
+
return style;
|
|
3821
|
+
});
|
|
3822
|
+
const bodyStyle = computed(() => {
|
|
3823
|
+
const inset = gestures.scrollPreservationInset.value;
|
|
3824
|
+
return inset > 0 ? { paddingBlockEnd: `${inset}px` } : void 0;
|
|
3825
|
+
});
|
|
3826
|
+
const overflowTabStop = computed(() => isInteractive.value && gestures.isOverflowing.value);
|
|
3827
|
+
let cancelMotionWait = null;
|
|
3828
|
+
/** The element a swipe's close moved on the animator, until the sheet is hidden. */
|
|
3829
|
+
let dragExitElement = null;
|
|
3830
|
+
function waitForMotion(motion) {
|
|
3831
|
+
cancelMotionWait?.();
|
|
3832
|
+
emit("motionStart", motion);
|
|
3833
|
+
const complete = () => {
|
|
3834
|
+
cancelMotionWait = null;
|
|
3835
|
+
emit("motionComplete", motion);
|
|
3836
|
+
};
|
|
3837
|
+
const element = panel.value;
|
|
3838
|
+
const exit = playedDragExit.value;
|
|
3839
|
+
if (motion === "exiting" && exit != null && element != null) {
|
|
3840
|
+
dragExitElement = element;
|
|
3841
|
+
cancelMotionWait = playDragExit(element, exit, {
|
|
3842
|
+
onSettled: () => emit("scrimFade", null),
|
|
3843
|
+
complete
|
|
3844
|
+
});
|
|
3845
|
+
return;
|
|
3846
|
+
}
|
|
3847
|
+
cancelMotionWait = waitForTransition(element, motion === "exiting" && isCrossFade.value ? "opacity" : "transform", complete);
|
|
3848
|
+
}
|
|
3849
|
+
watch(() => props.state, (state) => {
|
|
3850
|
+
if (state === "open" || state === "exiting") {
|
|
3851
|
+
waitForMotion(state === "open" ? "entering" : "exiting");
|
|
3852
|
+
return;
|
|
3853
|
+
}
|
|
3854
|
+
cancelMotionWait?.();
|
|
3855
|
+
cancelMotionWait = null;
|
|
3856
|
+
if (dragExitElement != null) {
|
|
3857
|
+
resetDragExit(dragExitElement);
|
|
3858
|
+
dragExitElement = null;
|
|
3859
|
+
}
|
|
3860
|
+
}, { flush: "post" });
|
|
3861
|
+
onMounted(() => {
|
|
3862
|
+
gestures.updateOverflow();
|
|
3863
|
+
});
|
|
3864
|
+
onUpdated(() => {
|
|
3865
|
+
gestures.updateOverflow();
|
|
3866
|
+
});
|
|
3867
|
+
watch([body, content], ([viewport, box], _previous, onCleanup) => {
|
|
3868
|
+
if (viewport == null || box == null) return;
|
|
3869
|
+
onCleanup(attachScrollKeyboardDelegation(viewport, box));
|
|
3870
|
+
});
|
|
3871
|
+
__expose({
|
|
3872
|
+
element: computed(() => panel.value ?? null),
|
|
3873
|
+
focus: (options) => panel.value?.focus(options),
|
|
3874
|
+
blur: () => panel.value?.blur()
|
|
3875
|
+
});
|
|
3876
|
+
return (_ctx, _cache) => {
|
|
3877
|
+
return openBlock(), createElementBlock("div", {
|
|
3878
|
+
ref_key: "panel",
|
|
3879
|
+
ref: panel,
|
|
3880
|
+
class: "astryx-bottom-sheet astryx-layer",
|
|
3881
|
+
"data-state": __props.state,
|
|
3882
|
+
"data-height": heightKind.value,
|
|
3883
|
+
"data-dragging": unref(gestures).isDragging.value || void 0,
|
|
3884
|
+
"data-reconciling": unref(gestures).isReconciling.value || void 0,
|
|
3885
|
+
"data-exit": __props.state === "exiting" && isCrossFade.value ? "fade" : void 0,
|
|
3886
|
+
style: normalizeStyle(panelStyle.value),
|
|
3887
|
+
tabindex: "-1"
|
|
3888
|
+
}, [createElementVNode("div", {
|
|
3889
|
+
class: "astryx-bottom-sheet__handle astryx-bottom-sheet-handle",
|
|
3890
|
+
"aria-hidden": "true",
|
|
3891
|
+
onPointerdown: _cache[0] || (_cache[0] = (...args) => unref(gestures).onHandlePointerDown && unref(gestures).onHandlePointerDown(...args))
|
|
3892
|
+
}, [..._cache[2] || (_cache[2] = [createElementVNode("div", { class: "astryx-bottom-sheet__handle-pill" }, null, -1)])], 32), createElementVNode("div", {
|
|
3893
|
+
ref_key: "body",
|
|
3894
|
+
ref: body,
|
|
3895
|
+
class: "astryx-bottom-sheet__body",
|
|
3896
|
+
"data-keyboard": __props.height === "tall" ? "tall" : void 0,
|
|
3897
|
+
tabindex: overflowTabStop.value ? 0 : void 0,
|
|
3898
|
+
role: overflowTabStop.value ? "group" : void 0,
|
|
3899
|
+
"aria-label": overflowTabStop.value ? __props.label : void 0,
|
|
3900
|
+
style: normalizeStyle(bodyStyle.value),
|
|
3901
|
+
onPointerdown: _cache[1] || (_cache[1] = (...args) => unref(gestures).onBodyPointerDown && unref(gestures).onBodyPointerDown(...args))
|
|
3902
|
+
}, [createElementVNode("div", {
|
|
3903
|
+
ref_key: "content",
|
|
3904
|
+
ref: content,
|
|
3905
|
+
class: "astryx-bottom-sheet__content",
|
|
3906
|
+
"data-padding": __props.padding
|
|
3907
|
+
}, [renderSlot(_ctx.$slots, "default")], 8, _hoisted_3$1)], 44, _hoisted_2$1)], 12, _hoisted_1$1);
|
|
3908
|
+
};
|
|
3909
|
+
}
|
|
3910
|
+
});
|
|
3911
|
+
//#endregion
|
|
3912
|
+
//#region src/BottomSheet/focusSheetPanel.ts
|
|
3913
|
+
/**
|
|
3914
|
+
* 抽屉里第一个可以接住焦点的 `data-autofocus` 元素拿到焦点。
|
|
3915
|
+
*
|
|
3916
|
+
* 抽屉里再开的抽屉或对话框,它的元素属于那一层;inert 的、看不见的、聚焦不上的都跳过。
|
|
3917
|
+
* 返回有没有找到。
|
|
3918
|
+
*/
|
|
3919
|
+
function focusFirstEligibleAutofocus(panel) {
|
|
3920
|
+
const dialog = panel.closest("dialog");
|
|
3921
|
+
for (const candidate of panel.querySelectorAll("[data-autofocus]")) {
|
|
3922
|
+
if (candidate.closest("dialog") !== dialog || candidate.closest("[inert]") != null || typeof candidate.checkVisibility === "function" && !candidate.checkVisibility()) continue;
|
|
3923
|
+
candidate.focus({ preventScroll: true });
|
|
3924
|
+
if (candidate.ownerDocument.activeElement === candidate) return true;
|
|
3925
|
+
}
|
|
3926
|
+
return false;
|
|
3927
|
+
}
|
|
3928
|
+
/**
|
|
3929
|
+
* 抽屉打开时把焦点放到该去的地方。
|
|
3930
|
+
*
|
|
3931
|
+
* 原生对话框打开时会按自己的规矩聚焦(Chromium 落在面板上,Firefox 落在第一个控件上),
|
|
3932
|
+
* 那不是使用者的选择:只要有可聚焦的 `data-autofocus` 元素,它就盖过原生的落点,所有浏览器一致。
|
|
3933
|
+
* 没有的话,焦点已经在抽屉里就不动;不在里面且这一层要接管焦点(模态的),就落在面板上。
|
|
3934
|
+
*/
|
|
3935
|
+
function focusSheetOnOpen(panel, takesPanelFocus) {
|
|
3936
|
+
if (panel == null) return;
|
|
3937
|
+
const active = panel.ownerDocument.activeElement;
|
|
3938
|
+
const isInsidePanel = active != null && panel.contains(active) && active.closest("dialog") === panel.closest("dialog");
|
|
3939
|
+
if (isInsidePanel && active.hasAttribute("data-autofocus")) return;
|
|
3940
|
+
if (focusFirstEligibleAutofocus(panel)) return;
|
|
3941
|
+
if (!isInsidePanel && takesPanelFocus) panel.focus({ preventScroll: true });
|
|
3942
|
+
}
|
|
3943
|
+
//#endregion
|
|
3944
|
+
//#region src/BottomSheet/switcher.ts
|
|
3945
|
+
const bottomSheetSwitcherKey = Symbol("astryx-bottom-sheet-switcher");
|
|
3946
|
+
//#endregion
|
|
3947
|
+
//#region src/BottomSheet/useSheetLayerDismiss.ts
|
|
3948
|
+
/**
|
|
3949
|
+
* 把底部面板登记进全页关闭栈。
|
|
3950
|
+
*
|
|
3951
|
+
* 点在外面不关:遮罩点击由对话框自己认,非模态时页面还要能点。
|
|
3952
|
+
* Escape 只打最上面一层。退出动画还在屏幕上时继续占着栈,按键不会漏到后面。
|
|
3953
|
+
*/
|
|
3954
|
+
function useSheetLayerDismiss(options) {
|
|
3955
|
+
const depth = useLayerDepth();
|
|
3956
|
+
const token = {};
|
|
3957
|
+
let stop = null;
|
|
3958
|
+
function sync() {
|
|
3959
|
+
stop?.();
|
|
3960
|
+
stop = null;
|
|
3961
|
+
if (!options.isActive.value) return;
|
|
3962
|
+
stop = pushLayer({
|
|
3963
|
+
token,
|
|
3964
|
+
depth,
|
|
3965
|
+
getContainer: options.getContainer,
|
|
3966
|
+
dismissOnPointerOutside: false,
|
|
3967
|
+
dismissOnEscape: options.escape.value,
|
|
3968
|
+
isPresent: options.isPresent,
|
|
3969
|
+
onDismiss: options.onDismiss
|
|
3970
|
+
});
|
|
3971
|
+
}
|
|
3972
|
+
watch([options.isActive, options.escape], sync, { immediate: true });
|
|
3973
|
+
onScopeDispose(() => {
|
|
3974
|
+
stop?.();
|
|
3975
|
+
stop = null;
|
|
3976
|
+
});
|
|
3977
|
+
return { isTop: () => options.isActive.value && isTopLayer(token) };
|
|
3978
|
+
}
|
|
3979
|
+
//#endregion
|
|
3980
|
+
//#region src/BottomSheet/BottomSheet.vue
|
|
3981
|
+
var BottomSheet_exports = /* @__PURE__ */ __exportAll({ default: () => _sfc_main });
|
|
3982
|
+
const _hoisted_1 = ["inert"];
|
|
3983
|
+
const _hoisted_2 = {
|
|
3984
|
+
key: 1,
|
|
3985
|
+
class: "astryx-bottom-sheet-inline"
|
|
3986
|
+
};
|
|
3987
|
+
const _hoisted_3 = {
|
|
3988
|
+
key: 0,
|
|
3989
|
+
class: "astryx-bottom-sheet__positioner astryx-bottom-sheet__positioner--inline"
|
|
3990
|
+
};
|
|
3991
|
+
const _hoisted_4 = [
|
|
3992
|
+
"data-settled",
|
|
3993
|
+
"aria-label",
|
|
3994
|
+
"aria-labelledby",
|
|
3995
|
+
"aria-modal",
|
|
3996
|
+
"role"
|
|
3997
|
+
];
|
|
3998
|
+
const _hoisted_5 = { class: "astryx-bottom-sheet__positioner" };
|
|
3999
|
+
const _hoisted_6 = {
|
|
4000
|
+
ref: "layerHost",
|
|
4001
|
+
class: "astryx-bottom-sheet__layer-host"
|
|
4002
|
+
};
|
|
4003
|
+
const _sfc_main = /*@__PURE__*/ defineComponent({
|
|
4004
|
+
name: "AstryxBottomSheet",
|
|
4005
|
+
inheritAttrs: false,
|
|
4006
|
+
__name: "BottomSheet",
|
|
4007
|
+
props: /*@__PURE__*/ mergeModels({
|
|
4008
|
+
isOpen: { type: Boolean },
|
|
4009
|
+
label: {},
|
|
4010
|
+
sheetId: {},
|
|
4011
|
+
isInline: {
|
|
4012
|
+
type: Boolean,
|
|
4013
|
+
default: false
|
|
4014
|
+
},
|
|
4015
|
+
height: { default: "capped" },
|
|
4016
|
+
snapPoints: { default: void 0 },
|
|
4017
|
+
padding: { default: void 0 },
|
|
4018
|
+
purpose: { default: "info" },
|
|
4019
|
+
hasScrim: {
|
|
4020
|
+
type: Boolean,
|
|
4021
|
+
default: true
|
|
4022
|
+
},
|
|
4023
|
+
finalFocusRef: { default: null }
|
|
4024
|
+
}, {
|
|
4025
|
+
"isOpen": {
|
|
4026
|
+
type: Boolean,
|
|
4027
|
+
default: false
|
|
4028
|
+
},
|
|
4029
|
+
"isOpenModifiers": {}
|
|
4030
|
+
}),
|
|
4031
|
+
emits: /*@__PURE__*/ mergeModels([
|
|
4032
|
+
"openChange",
|
|
4033
|
+
"update:isOpen",
|
|
4034
|
+
"motionStart",
|
|
4035
|
+
"motionComplete",
|
|
4036
|
+
"snap"
|
|
4037
|
+
], ["update:isOpen"]),
|
|
4038
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
4039
|
+
const props = __props;
|
|
4040
|
+
const emit = __emit;
|
|
4041
|
+
const isOpen = useModel(__props, "isOpen");
|
|
4042
|
+
const switcher = inject(bottomSheetSwitcherKey, null);
|
|
4043
|
+
const isEscapeAllowed = inject(bottomSheetEscapeKey, () => true);
|
|
4044
|
+
provide(bottomSheetEscapeKey, () => true);
|
|
4045
|
+
const hosted = computed(() => switcher != null && props.sheetId != null);
|
|
4046
|
+
const retained = computed(() => {
|
|
4047
|
+
if (!hosted.value || switcher == null) return false;
|
|
4048
|
+
return switcher.retainedId.value === props.sheetId && switcher.activeId.value !== props.sheetId;
|
|
4049
|
+
});
|
|
4050
|
+
const open = computed(() => {
|
|
4051
|
+
if (!hosted.value || props.sheetId == null) return isOpen.value;
|
|
4052
|
+
return switcher?.activeId.value === props.sheetId || switcher?.retainedId.value === props.sheetId;
|
|
4053
|
+
});
|
|
4054
|
+
const attrs = useAttrs();
|
|
4055
|
+
const dialog = useTemplateRef("dialog");
|
|
4056
|
+
provideNestedLayerMountTarget(useTemplateRef("layerHost"));
|
|
4057
|
+
const panel = useTemplateRef("panel");
|
|
4058
|
+
const isPresented = ref(false);
|
|
4059
|
+
const scrimOpacity = ref(1);
|
|
4060
|
+
const isModalShown = ref(false);
|
|
4061
|
+
const isSettled = ref(getCurrentInstance()?.vnode.el != null && isOpen.value && !hosted.value && !props.isInline);
|
|
4062
|
+
const panelState = computed(() => {
|
|
4063
|
+
if (retained.value) return "exiting";
|
|
4064
|
+
if (open.value) return "open";
|
|
4065
|
+
if (props.isInline || hosted.value) return "hidden";
|
|
4066
|
+
return isPresented.value ? "exiting" : "hidden";
|
|
4067
|
+
});
|
|
4068
|
+
const isDismissible = computed(() => props.purpose === "info");
|
|
4069
|
+
const isSwipeDismissAllowed = computed(() => props.purpose === "info" && !props.isInline);
|
|
4070
|
+
const scrimFade = ref(null);
|
|
4071
|
+
const isClosing = computed(() => !isOpen.value && isPresented.value);
|
|
4072
|
+
const dialogStyle = computed(() => ({
|
|
4073
|
+
"--_sheet-scrim-opacity": isClosing.value ? "0" : String(scrimOpacity.value),
|
|
4074
|
+
"--_sheet-scrim-duration": scrimFade.value == null ? void 0 : `${scrimFade.value.durationMs}ms`,
|
|
4075
|
+
"--_sheet-scrim-easing": scrimFade.value?.easing
|
|
4076
|
+
}));
|
|
4077
|
+
useFocusTrap({
|
|
4078
|
+
container: computed(() => panelElement()),
|
|
4079
|
+
isEnabled: computed(() => !hosted.value && isOpen.value && props.hasScrim)
|
|
4080
|
+
});
|
|
4081
|
+
useRestoreFocus({
|
|
4082
|
+
isEnabled: computed(() => !props.isInline && !hosted.value),
|
|
4083
|
+
shouldRestore: isOpen,
|
|
4084
|
+
preventScroll: true
|
|
4085
|
+
});
|
|
4086
|
+
/** The dialog carries the accessible name; the panel keeps every other attribute. */
|
|
4087
|
+
const dialogLabel = computed(() => {
|
|
4088
|
+
if (attrs["aria-labelledby"] != null) return void 0;
|
|
4089
|
+
return attrs["aria-label"] ?? props.label;
|
|
4090
|
+
});
|
|
4091
|
+
const labelledBy = computed(() => attrs["aria-labelledby"]);
|
|
4092
|
+
function panelAttrs() {
|
|
4093
|
+
const { "aria-label": _label, "aria-labelledby": _labelledBy, ...rest } = attrs;
|
|
4094
|
+
return rest;
|
|
4095
|
+
}
|
|
4096
|
+
const isScrollLocked = ref(false);
|
|
4097
|
+
useScrollLock(isScrollLocked);
|
|
4098
|
+
function lockScroll() {
|
|
4099
|
+
if (typeof document === "undefined") return;
|
|
4100
|
+
isScrollLocked.value = true;
|
|
4101
|
+
}
|
|
4102
|
+
function unlockScroll() {
|
|
4103
|
+
if (typeof document === "undefined") return;
|
|
4104
|
+
isScrollLocked.value = false;
|
|
4105
|
+
}
|
|
4106
|
+
function panelElement() {
|
|
4107
|
+
return panel.value?.element ?? null;
|
|
4108
|
+
}
|
|
4109
|
+
function focusPanel() {
|
|
4110
|
+
if (typeof document === "undefined") return;
|
|
4111
|
+
focusSheetOnOpen(panelElement(), props.hasScrim);
|
|
4112
|
+
}
|
|
4113
|
+
let focusRecord = null;
|
|
4114
|
+
const modalOutlet = createModalOutletHandle();
|
|
4115
|
+
function openSheet() {
|
|
4116
|
+
if (props.isInline || typeof document === "undefined") return;
|
|
4117
|
+
const dialogElement = dialog.value;
|
|
4118
|
+
if (!dialogElement) return;
|
|
4119
|
+
isPresented.value = true;
|
|
4120
|
+
if (!dialogElement.open) {
|
|
4121
|
+
focusRecord?.stop();
|
|
4122
|
+
focusRecord = trackLayerFocus({ getLayer: () => dialog.value });
|
|
4123
|
+
if (props.hasScrim) {
|
|
4124
|
+
dialogElement.showModal();
|
|
4125
|
+
isModalShown.value = true;
|
|
4126
|
+
if (!hosted.value) modalOutlet.attach(dialogElement);
|
|
4127
|
+
} else dialogElement.show();
|
|
4128
|
+
}
|
|
4129
|
+
if (props.hasScrim) lockScroll();
|
|
4130
|
+
focusPanel();
|
|
4131
|
+
}
|
|
4132
|
+
function closeSheet() {
|
|
4133
|
+
modalOutlet.detach();
|
|
4134
|
+
dialog.value?.close();
|
|
4135
|
+
unlockScroll();
|
|
4136
|
+
isPresented.value = false;
|
|
4137
|
+
isModalShown.value = false;
|
|
4138
|
+
focusRecord?.stop();
|
|
4139
|
+
focusRecord = null;
|
|
4140
|
+
const target = toValue(props.finalFocusRef);
|
|
4141
|
+
if (target?.isConnected) focusForLastInput(target, { preventScroll: true });
|
|
4142
|
+
}
|
|
4143
|
+
const layer = useSheetLayerDismiss({
|
|
4144
|
+
isActive: computed(() => !hosted.value && !props.isInline && (isOpen.value || isPresented.value)),
|
|
4145
|
+
escape: computed(() => {
|
|
4146
|
+
if (!isOpen.value || props.purpose === "required" || !isEscapeAllowed()) return "block";
|
|
4147
|
+
if (!props.hasScrim) return "ignore";
|
|
4148
|
+
return "close";
|
|
4149
|
+
}),
|
|
4150
|
+
getContainer: () => dialog.value ?? null,
|
|
4151
|
+
isPresent: () => dialog.value?.open ?? false,
|
|
4152
|
+
onDismiss: () => {
|
|
4153
|
+
if (!isOpen.value || props.purpose === "required") return;
|
|
4154
|
+
requestClose();
|
|
4155
|
+
}
|
|
4156
|
+
});
|
|
4157
|
+
function requestClose() {
|
|
4158
|
+
if (hosted.value && props.sheetId != null) {
|
|
4159
|
+
if (switcher?.activeId.value === props.sheetId) switcher.setActive(null);
|
|
4160
|
+
emit("openChange", false);
|
|
4161
|
+
return;
|
|
4162
|
+
}
|
|
4163
|
+
isOpen.value = false;
|
|
4164
|
+
emit("openChange", false);
|
|
4165
|
+
}
|
|
4166
|
+
function dismissOnEscape() {
|
|
4167
|
+
if (props.purpose === "required" || !isEscapeAllowed()) return;
|
|
4168
|
+
requestClose();
|
|
4169
|
+
}
|
|
4170
|
+
function onKeydown(event) {
|
|
4171
|
+
if (event.key !== "Escape" || !layer.isTop()) return;
|
|
4172
|
+
event.preventDefault();
|
|
4173
|
+
if (isImeKeyEvent(event)) return;
|
|
4174
|
+
dismissOnEscape();
|
|
4175
|
+
}
|
|
4176
|
+
function onCancel(event) {
|
|
4177
|
+
if (event.target !== dialog.value) return;
|
|
4178
|
+
event.preventDefault();
|
|
4179
|
+
if (!layer.isTop()) return;
|
|
4180
|
+
dismissOnEscape();
|
|
4181
|
+
}
|
|
4182
|
+
function onDialogClick(event) {
|
|
4183
|
+
if (event.target !== event.currentTarget) return;
|
|
4184
|
+
if (props.hasScrim && isDismissible.value) requestClose();
|
|
4185
|
+
}
|
|
4186
|
+
function onPanelMotionComplete(motion) {
|
|
4187
|
+
emit("motionComplete", motion);
|
|
4188
|
+
if (motion === "exiting") closeSheet();
|
|
4189
|
+
}
|
|
4190
|
+
watch(isOpen, (value) => {
|
|
4191
|
+
if (hosted.value || !value) return;
|
|
4192
|
+
openSheet();
|
|
4193
|
+
}, { flush: "post" });
|
|
4194
|
+
watch(isOpen, (value) => {
|
|
4195
|
+
if (value) {
|
|
4196
|
+
scrimOpacity.value = 1;
|
|
4197
|
+
return;
|
|
4198
|
+
}
|
|
4199
|
+
isSettled.value = false;
|
|
4200
|
+
isModalShown.value = false;
|
|
4201
|
+
});
|
|
4202
|
+
const isExiting = computed(() => !hosted.value && !props.isInline && !isOpen.value && isPresented.value);
|
|
4203
|
+
let releaseExitHold = null;
|
|
4204
|
+
watch(isExiting, (exiting) => {
|
|
4205
|
+
releaseExitHold?.();
|
|
4206
|
+
releaseExitHold = null;
|
|
4207
|
+
const element = dialog.value;
|
|
4208
|
+
if (exiting && element != null) releaseExitHold = holdKeptInside(element, new Promise(() => {}));
|
|
4209
|
+
}, { flush: "post" });
|
|
4210
|
+
onMounted(() => {
|
|
4211
|
+
if (hosted.value && props.sheetId != null) {
|
|
4212
|
+
switcher?.register(props.sheetId, {
|
|
4213
|
+
getElement: () => panelElement(),
|
|
4214
|
+
label: () => props.label,
|
|
4215
|
+
purpose: () => props.purpose
|
|
4216
|
+
});
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4219
|
+
if (isOpen.value) openSheet();
|
|
4220
|
+
});
|
|
4221
|
+
onBeforeUnmount(() => {
|
|
4222
|
+
const record = focusRecord;
|
|
4223
|
+
focusRecord = null;
|
|
4224
|
+
if (record != null) {
|
|
4225
|
+
const wasStranded = isLayerFocusStranded(record, dialog.value);
|
|
4226
|
+
queueMicrotask(() => {
|
|
4227
|
+
if (wasStranded) restoreLayerFocus(record, {
|
|
4228
|
+
layer: null,
|
|
4229
|
+
name: "BottomSheet"
|
|
4230
|
+
});
|
|
4231
|
+
record.stop();
|
|
4232
|
+
});
|
|
4233
|
+
}
|
|
4234
|
+
releaseExitHold?.();
|
|
4235
|
+
releaseExitHold = null;
|
|
4236
|
+
modalOutlet.detach();
|
|
4237
|
+
if (props.sheetId != null) switcher?.unregister(props.sheetId);
|
|
4238
|
+
unlockScroll();
|
|
4239
|
+
});
|
|
4240
|
+
__expose({
|
|
4241
|
+
element: computed(() => panelElement()),
|
|
4242
|
+
focus: (options) => panelElement()?.focus(options),
|
|
4243
|
+
blur: () => panelElement()?.blur()
|
|
4244
|
+
});
|
|
4245
|
+
return (_ctx, _cache) => {
|
|
4246
|
+
return hosted.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [open.value ? (openBlock(), createElementBlock("div", {
|
|
4247
|
+
key: 0,
|
|
4248
|
+
class: normalizeClass(["astryx-bottom-sheet__positioner", retained.value ? "astryx-bottom-sheet__positioner--retained" : "astryx-bottom-sheet__positioner--active"]),
|
|
4249
|
+
style: normalizeStyle(retained.value ? { "--_sheet-align": `${unref(switcher)?.alignmentOffset.value ?? 0}px` } : void 0),
|
|
4250
|
+
inert: retained.value || void 0
|
|
4251
|
+
}, [createVNode(_sfc_main$1, mergeProps({
|
|
4252
|
+
ref_key: "panel",
|
|
4253
|
+
ref: panel
|
|
4254
|
+
}, panelAttrs(), {
|
|
4255
|
+
state: panelState.value,
|
|
4256
|
+
label: __props.label,
|
|
4257
|
+
height: __props.height,
|
|
4258
|
+
padding: __props.padding,
|
|
4259
|
+
"snap-points": __props.snapPoints,
|
|
4260
|
+
"is-swipe-dismiss-allowed": __props.purpose === "info",
|
|
4261
|
+
"is-page-scroll-locked": __props.hasScrim,
|
|
4262
|
+
onDismiss: requestClose,
|
|
4263
|
+
onSnap: _cache[0] || (_cache[0] = ($event) => emit("snap", $event)),
|
|
4264
|
+
onMotionStart: _cache[1] || (_cache[1] = ($event) => emit("motionStart", $event)),
|
|
4265
|
+
onMotionComplete: _cache[2] || (_cache[2] = ($event) => emit("motionComplete", $event))
|
|
4266
|
+
}), {
|
|
4267
|
+
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
|
|
4268
|
+
_: 3
|
|
4269
|
+
}, 16, [
|
|
4270
|
+
"state",
|
|
4271
|
+
"label",
|
|
4272
|
+
"height",
|
|
4273
|
+
"padding",
|
|
4274
|
+
"snap-points",
|
|
4275
|
+
"is-swipe-dismiss-allowed",
|
|
4276
|
+
"is-page-scroll-locked"
|
|
4277
|
+
])], 14, _hoisted_1)) : createCommentVNode("v-if", true)], 64)) : __props.isInline ? (openBlock(), createElementBlock("div", _hoisted_2, [isOpen.value ? (openBlock(), createElementBlock("div", _hoisted_3, [createVNode(_sfc_main$1, mergeProps({
|
|
4278
|
+
ref_key: "panel",
|
|
4279
|
+
ref: panel
|
|
4280
|
+
}, panelAttrs(), {
|
|
4281
|
+
state: panelState.value,
|
|
4282
|
+
label: __props.label,
|
|
4283
|
+
height: __props.height,
|
|
4284
|
+
padding: __props.padding,
|
|
4285
|
+
"snap-points": __props.snapPoints,
|
|
4286
|
+
"is-swipe-dismiss-allowed": false,
|
|
4287
|
+
onSnap: _cache[3] || (_cache[3] = ($event) => emit("snap", $event))
|
|
4288
|
+
}), {
|
|
4289
|
+
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
|
|
4290
|
+
_: 3
|
|
4291
|
+
}, 16, [
|
|
4292
|
+
"state",
|
|
4293
|
+
"label",
|
|
4294
|
+
"height",
|
|
4295
|
+
"padding",
|
|
4296
|
+
"snap-points"
|
|
4297
|
+
])])) : createCommentVNode("v-if", true)])) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [createCommentVNode(" eslint-disable-next-line vue-a11y/no-static-element-interactions -- 点在 dialog 自身上等于点遮罩;键盘走原生 cancel 和下面的 keydown。 "), createElementVNode("dialog", {
|
|
4298
|
+
ref_key: "dialog",
|
|
4299
|
+
ref: dialog,
|
|
4300
|
+
class: normalizeClass(["astryx-bottom-sheet-dialog", {
|
|
4301
|
+
"astryx-bottom-sheet-dialog--scrim": __props.hasScrim,
|
|
4302
|
+
"astryx-bottom-sheet-dialog--closing": isClosing.value
|
|
4303
|
+
}]),
|
|
4304
|
+
"data-settled": isSettled.value || void 0,
|
|
4305
|
+
"aria-label": dialogLabel.value,
|
|
4306
|
+
"aria-labelledby": labelledBy.value,
|
|
4307
|
+
"aria-modal": __props.hasScrim && isModalShown.value ? "true" : void 0,
|
|
4308
|
+
role: __props.purpose === "required" ? "alertdialog" : void 0,
|
|
4309
|
+
style: normalizeStyle(dialogStyle.value),
|
|
4310
|
+
onCancel,
|
|
4311
|
+
onClick: onDialogClick,
|
|
4312
|
+
onKeydown
|
|
4313
|
+
}, [
|
|
4314
|
+
createElementVNode("div", _hoisted_5, [createVNode(_sfc_main$1, mergeProps({
|
|
4315
|
+
ref_key: "panel",
|
|
4316
|
+
ref: panel
|
|
4317
|
+
}, panelAttrs(), {
|
|
4318
|
+
state: panelState.value,
|
|
4319
|
+
label: __props.label,
|
|
4320
|
+
height: __props.height,
|
|
4321
|
+
padding: __props.padding,
|
|
4322
|
+
"snap-points": __props.snapPoints,
|
|
4323
|
+
"is-swipe-dismiss-allowed": isSwipeDismissAllowed.value,
|
|
4324
|
+
"is-page-scroll-locked": isScrollLocked.value,
|
|
4325
|
+
onDismiss: requestClose,
|
|
4326
|
+
onScrimOpacity: _cache[4] || (_cache[4] = ($event) => scrimOpacity.value = $event),
|
|
4327
|
+
onScrimFade: _cache[5] || (_cache[5] = ($event) => scrimFade.value = $event),
|
|
4328
|
+
onSnap: _cache[6] || (_cache[6] = ($event) => emit("snap", $event)),
|
|
4329
|
+
onMotionStart: _cache[7] || (_cache[7] = ($event) => emit("motionStart", $event)),
|
|
4330
|
+
onMotionComplete: onPanelMotionComplete
|
|
4331
|
+
}), {
|
|
4332
|
+
default: withCtx(() => [renderSlot(_ctx.$slots, "default")]),
|
|
4333
|
+
_: 3
|
|
4334
|
+
}, 16, [
|
|
4335
|
+
"state",
|
|
4336
|
+
"label",
|
|
4337
|
+
"height",
|
|
4338
|
+
"padding",
|
|
4339
|
+
"snap-points",
|
|
4340
|
+
"is-swipe-dismiss-allowed",
|
|
4341
|
+
"is-page-scroll-locked"
|
|
4342
|
+
])]),
|
|
4343
|
+
_cache[8] || (_cache[8] = createElementVNode("div", {
|
|
4344
|
+
class: "astryx-bottom-sheet__edge-tint",
|
|
4345
|
+
"aria-hidden": "true"
|
|
4346
|
+
}, null, -1)),
|
|
4347
|
+
createElementVNode("div", _hoisted_6, null, 512)
|
|
4348
|
+
], 46, _hoisted_4)], 2112));
|
|
4349
|
+
};
|
|
4350
|
+
}
|
|
4351
|
+
});
|
|
4352
|
+
//#endregion
|
|
4353
|
+
export { focusSheetOnOpen as a, bottomSheetSwitcherKey as i, _sfc_main as n, useSheetLayerDismiss as r, BottomSheet_exports as t };
|