@astryx-vue/core 0.36.1 → 0.36.2
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-C4oB89RV.js → AlertDialog-Dz8T0KIa.js} +1 -1
- package/dist/AppShell/index.js +1 -1
- package/dist/{AppShell-CU12SF6s.js → AppShell-ClZ2Y8cu.js} +2 -2
- package/dist/AvatarGroup/index.d.ts +1 -1
- package/dist/Banner/index.d.ts +1 -1
- package/dist/BottomSheet/index.d.ts +1 -1
- package/dist/BottomSheet/index.js +2 -2
- package/dist/{BottomSheet-DCLOhzZP.js → BottomSheet-CRHPDrmS.js} +3 -3
- package/dist/BottomSheet-CYsGu9GP.js +1926 -0
- package/dist/Breadcrumbs/index.js +2 -2
- package/dist/{Breadcrumbs-BfjWIfgO.js → Breadcrumbs-nO9YHygD.js} +1 -1
- package/dist/Button/index.d.ts +1 -1
- package/dist/ButtonGroup/index.d.ts +1 -1
- package/dist/Calendar/index.d.ts +1 -1
- package/dist/Card/index.d.ts +1 -1
- package/dist/Carousel/index.d.ts +1 -1
- package/dist/Chat/index.d.ts +1 -1
- package/dist/Chat/index.js +1 -1
- package/dist/{Chat-f9HzZe5y.js → Chat-BRtDKajd.js} +230 -12
- package/dist/CheckboxInput/index.d.ts +1 -1
- package/dist/CheckboxList/index.d.ts +1 -1
- package/dist/ClickableCard/index.d.ts +1 -1
- package/dist/Collapsible/index.d.ts +1 -1
- package/dist/Collapsible/index.js +1 -1
- package/dist/{Collapsible-Dxp-BWv-.js → Collapsible-DfVihLCR.js} +1 -1
- package/dist/CommandPalette/index.d.ts +1 -1
- package/dist/CommandPalette/index.js +1 -1
- package/dist/{CommandPalette-PyPfsPLY.js → CommandPalette-D07roA0D.js} +1 -1
- package/dist/ComplexSelector/index.js +1 -1
- package/dist/{ComplexSelector-B07QdP_p.js → ComplexSelector-7OdAby6v.js} +1 -1
- package/dist/ContextMenu/index.d.ts +1 -1
- package/dist/ContextMenu/index.js +2 -2
- package/dist/{ContextMenu-B6NH9NBS.js → ContextMenu-BIJyyObZ.js} +4 -4
- package/dist/DateInput/index.d.ts +1 -1
- package/dist/DateInput/index.js +1 -1
- package/dist/{DateInput-TrPijW9a.js → DateInput-BNKoPL3j.js} +2 -2
- package/dist/DateRangeInput/index.d.ts +1 -1
- package/dist/DateRangeInput/index.js +1 -1
- package/dist/{DateRangeInput-bKPzsoHA.js → DateRangeInput-CGDlPnUb.js} +1 -1
- package/dist/DateTimeInput/index.d.ts +1 -1
- package/dist/DateTimeInput/index.js +1 -1
- package/dist/{DateTimeInput-5jZPqFu2.js → DateTimeInput-CRWUAh75.js} +3 -3
- package/dist/Dialog/index.d.ts +1 -1
- package/dist/Dialog/index.js +3 -3
- package/dist/{Dialog-dm_qZ9NI.js → Dialog-BxijA4zr.js} +2 -2
- package/dist/{Dialog-CDAicnpK.js → Dialog-CXa-tu02.js} +1 -1
- package/dist/{DialogHeader-CQfcOIfF.js → DialogHeader-D7f97ksG.js} +1 -1
- package/dist/Divider/index.d.ts +1 -1
- package/dist/Drawer/index.d.ts +1 -1
- package/dist/Drawer/index.js +1 -1
- package/dist/{Drawer-DKSqpR2p.js → Drawer-C3t7NKiF.js} +2 -2
- package/dist/DropdownMenu/index.js +2 -2
- package/dist/{DropdownMenu-C-SLsVSO.js → DropdownMenu-Bklf6ekH.js} +4 -4
- package/dist/FileInput/index.d.ts +1 -1
- package/dist/HoverCard/index.d.ts +1 -1
- package/dist/InfoTip/index.d.ts +1 -1
- package/dist/InputGroup/index.d.ts +1 -1
- package/dist/Layout/index.js +2 -2
- package/dist/{Layout-CpFgVnlQ.js → Layout-BDS2ZN6C.js} +1 -1
- package/dist/{LayoutPanel-Dhm0Hubb.js → LayoutPanel-D56PBM4I.js} +1 -1
- package/dist/Lightbox/index.js +1 -1
- package/dist/{Lightbox-BSzyDGkK.js → Lightbox-CnTXrgq6.js} +2 -2
- package/dist/Link/index.d.ts +1 -1
- package/dist/List/index.d.ts +1 -1
- package/dist/Markdown/index.d.ts +1 -1
- package/dist/MobileNav/index.js +1 -1
- package/dist/{MobileNavToggle-C1_IinAo.js → MobileNavToggle-CjlgmcSf.js} +2 -2
- package/dist/MoreMenu/index.d.ts +1 -1
- package/dist/MoreMenu/index.js +1 -1
- package/dist/{MoreMenu-DbYO8V7N.js → MoreMenu-CGTbwTyw.js} +1 -1
- package/dist/MultiSelector/index.d.ts +1 -1
- package/dist/MultiSelector/index.js +1 -1
- package/dist/{MultiSelector-CthCkW-w.js → MultiSelector-BjFYfRqV.js} +1 -1
- package/dist/NavMenu/index.js +2 -2
- package/dist/{NavMenu-g8ZVhLMG.js → NavMenu-BflnhBtX.js} +1 -1
- package/dist/{NavMenuItem-DJg9jfHm.js → NavMenuItem-CrFrczWe.js} +1 -1
- package/dist/NumberInput/index.d.ts +1 -1
- package/dist/NumberInput/index.js +1 -1
- package/dist/{NumberInput-BM52uE72.js → NumberInput-vWUcgJU8.js} +2 -0
- package/dist/OverflowList/index.d.ts +1 -1
- package/dist/OverflowList/index.js +1 -1
- package/dist/{OverflowList-nW6GCEsY.js → OverflowList-D9Ua6e3-.js} +1 -1
- package/dist/Pagination/index.d.ts +1 -1
- package/dist/Pagination/index.js +1 -1
- package/dist/{Pagination-DFZivDZZ.js → Pagination-DGcl38z9.js} +3 -3
- package/dist/Popover/index.d.ts +1 -1
- package/dist/Popover/index.js +1 -1
- package/dist/{Popover-IvZGq1LC.js → Popover-DlCqmkYD.js} +3 -3
- package/dist/PowerSearch/index.d.ts +1 -1
- package/dist/PowerSearch/index.js +1 -1
- package/dist/{PowerSearch-CQdyB8_N.js → PowerSearch-BKhXYPRO.js} +10 -10
- package/dist/ProgressBar/index.d.ts +1 -1
- package/dist/Radio/index.d.ts +1 -1
- package/dist/RadioList/index.d.ts +1 -1
- package/dist/Resizable/index.d.ts +1 -1
- package/dist/ScrollableArea/index.d.ts +1 -1
- package/dist/SegmentedControl/index.d.ts +1 -1
- package/dist/SelectableCard/index.d.ts +1 -1
- package/dist/Selector/index.d.ts +1 -1
- package/dist/Selector/index.js +1 -1
- package/dist/{Selector-icOfE3ja.js → Selector-CHq3XHwH.js} +1 -1
- package/dist/SideNav/index.d.ts +1 -1
- package/dist/SideNav/index.js +1 -1
- package/dist/{SideNav-ZZ5zCQz0.js → SideNav-D8jQrwtL.js} +1 -1
- package/dist/Stepper/index.d.ts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/TabList/index.d.ts +1 -1
- package/dist/TabList/index.js +1 -1
- package/dist/{TabList-C-HBxmkc.js → TabList-DjRutwar.js} +1 -1
- package/dist/Table/index.d.ts +1 -1
- package/dist/Table/index.js +1 -1
- package/dist/{Table-aMqVf_iH.js → Table-waEj3x_o.js} +8 -8
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/TextArea/index.js +1 -1
- package/dist/{TextArea-YJtL9Fi6.js → TextArea-BtBC4IoD.js} +2 -0
- package/dist/TextInput/index.d.ts +1 -1
- package/dist/TextInput/index.js +1 -1
- package/dist/{TextInput-CuPxOApN.js → TextInput-cotkU2bC.js} +2 -0
- package/dist/{TimeField-DNxPI2cM.js → TimeField-BXQCZIwP.js} +1 -1
- package/dist/TimeInput/index.d.ts +1 -1
- package/dist/TimeInput/index.js +1 -1
- package/dist/{TimeInput-PJdyNX0T.js → TimeInput-C_ZssG1D.js} +1 -1
- package/dist/Timer/index.d.ts +1 -1
- package/dist/Timestamp/index.d.ts +1 -1
- package/dist/ToggleButton/index.d.ts +1 -1
- package/dist/Tokenizer/index.d.ts +1 -1
- package/dist/Tokenizer/index.js +1 -1
- package/dist/{Tokenizer-CdyoUaoZ.js → Tokenizer-hmGkGVG7.js} +3 -3
- package/dist/Toolbar/index.d.ts +1 -1
- package/dist/Tooltip/index.d.ts +1 -1
- package/dist/TopNav/index.d.ts +1 -1
- package/dist/TopNav/index.js +1 -1
- package/dist/{TopNav-CxAm5bN5.js → TopNav-D7jH9iwk.js} +2 -2
- package/dist/TreeList/index.d.ts +1 -1
- package/dist/Typeahead/index.d.ts +1 -1
- package/dist/{accessibleName-CN1vKvS_.js → accessibleName-CHrrgpAy.js} +1 -1
- package/dist/composables/index.js +4 -4
- package/dist/{focusLeaving-DMkbxFkF.js → focusLeaving-BbZ69DYV.js} +1 -1
- package/dist/{focusReturn-DfZS7TCp.js → focusReturn-BeSRm0xD.js} +34 -3
- package/dist/{index-X4S7_dmq.d.ts → index-BA8exXNP.d.ts} +1 -1
- package/dist/{index-x7g2WHHx.d.ts → index-BGUuyAMO.d.ts} +10 -10
- package/dist/{index-CBOv5j3c.d.ts → index-BQ3cm7mP.d.ts} +2 -2
- package/dist/{index-BufuCsTx.d.ts → index-BRr4ANpr.d.ts} +8 -8
- package/dist/{index-DHUCHxn2.d.ts → index-BWWirRm3.d.ts} +1 -1
- package/dist/{index--kbwaSXW.d.ts → index-BWzEt0gT.d.ts} +2 -2
- package/dist/{index-CTjkJP4x.d.ts → index-Bgk1Rj2A.d.ts} +1 -1
- package/dist/{index-CZ29Xu_E.d.ts → index-Bwh8O-v8.d.ts} +1 -1
- package/dist/{index-B27k2e77.d.ts → index-C0smuLQ8.d.ts} +80 -80
- package/dist/{index-BjqoHLMq.d.ts → index-C1e8LNx2.d.ts} +1 -1
- package/dist/{index-CilCxEvD.d.ts → index-C6Iv6sgd.d.ts} +3 -3
- package/dist/{index-1yvu_vpF.d.ts → index-CAJMHw-g.d.ts} +4 -4
- package/dist/{index-ZXrvTM3A.d.ts → index-CArP_6wv.d.ts} +1 -1
- package/dist/{index-DofC9Rll.d.ts → index-CJdOt5Cc.d.ts} +2 -2
- package/dist/{index-C4S65SAW.d.ts → index-CKnr0JlT.d.ts} +1 -1
- package/dist/{index-C3JmGujU.d.ts → index-Cm36VS1A.d.ts} +3 -3
- package/dist/{index-C8wfe0Mr.d.ts → index-D05JGsT3.d.ts} +1 -1
- package/dist/{index-rr6Rns7h.d.ts → index-D2B3ysZr.d.ts} +2 -2
- package/dist/{index-J83fLEyo.d.ts → index-DA3DMFds.d.ts} +4 -4
- package/dist/{index-tdOyqA_U.d.ts → index-DlH0BI35.d.ts} +2 -2
- package/dist/{index-JE1HrzdJ.d.ts → index-DsWEyz1N.d.ts} +1 -1
- package/dist/{index-DYabo8TI.d.ts → index-SWw-WMTO.d.ts} +2 -2
- package/dist/{index-CdvmnNMH.d.ts → index-Xc3q9f84.d.ts} +2 -2
- package/dist/{index-C93nwgTW.d.ts → index-gmY3A_Iw.d.ts} +1 -1
- package/dist/{index-BenG-F5d.d.ts → index-maTGrWjF.d.ts} +1 -1
- package/dist/{index-yQc-te9a.d.ts → index-ql9ApSTF.d.ts} +2 -2
- package/dist/index.d.ts +26 -26
- package/dist/index.js +45 -45
- package/dist/{layerFocusReturn-CEvrMbxH.js → layerFocusReturn-uixUCSc8.js} +1 -1
- package/dist/{lazyBottomSheet-DlrpPOl8.js → lazyBottomSheet-zUe1mYmM.js} +1 -1
- package/dist/rideKeyboard-BCzVooOd.js +1635 -0
- package/dist/{useChatStreamScroll-DWhnCSP1.js → useChatStreamScroll-3mJvbNtI.js} +30 -4
- package/dist/{useFocusTrap-DcjriBe1.js → useFocusTrap-Bj9GskLh.js} +1 -1
- package/dist/{useMenuPress-zOinmIFS.js → useMenuPress-kjmot8Bn.js} +1 -1
- package/dist/useMobileKeyboard-BDPV51xl.js +806 -0
- package/dist/{useRestoreFocus-DS7uQWok.js → useRestoreFocus-m3rsqE4d.js} +1 -1
- package/package.json +1 -1
- package/styles/chat.css +6 -0
- package/dist/BottomSheet-Chr9yCIL.js +0 -4353
|
@@ -0,0 +1,1635 @@
|
|
|
1
|
+
import { c as isHTMLElement, l as isNode, s as isElement } from "./flatTree-BB4yPMNL.js";
|
|
2
|
+
import { t as armClickGuard } from "./clickGuard-BkegH2NW.js";
|
|
3
|
+
import { o as sharedWeakMap, s as sharedWeakSet } from "./sharedRealm-BYHklCVM.js";
|
|
4
|
+
import { a as subscribeInput, i as getTouches } from "./inputStream-DmPkJ1aU.js";
|
|
5
|
+
import { i as PRESS_SLOP_PX } from "./pressGesture-CfBgXWRM.js";
|
|
6
|
+
import { t as cubicBezier } from "./bezier-Dko5MnTp.js";
|
|
7
|
+
import { n as isIosWebKit } from "./touchQueries-xy5IeZfe.js";
|
|
8
|
+
import { t as caretAt } from "./selectionRanges-DB5jesLz.js";
|
|
9
|
+
import { n as matchesMediaQuery, t as isCoarsePointer } from "./coarsePointer-BWNSUIY8.js";
|
|
10
|
+
import { n as reducedMotionFade } from "./reducedMotion-D8-U7XFT.js";
|
|
11
|
+
//#region src/utils/layoutViewport.ts
|
|
12
|
+
/**
|
|
13
|
+
* @file layoutViewport.ts
|
|
14
|
+
* @input A window: its innerHeight and innerWidth, its visual viewport's
|
|
15
|
+
* width and scale, and its document's root box
|
|
16
|
+
* @output layoutViewportHeight, the layout viewport's height in layout px
|
|
17
|
+
* less a classic horizontal scrollbar, and __resetLayoutViewportForTest
|
|
18
|
+
* @position Internal shared measurement, not re-exported from the utils
|
|
19
|
+
* entry. The keyboard module, BottomSheet's keyboard obstruction and any
|
|
20
|
+
* layout that sizes against the layout viewport read it.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* The layout viewport's height, CSS px, in the units of element rects.
|
|
24
|
+
*
|
|
25
|
+
* `innerHeight` is the layout viewport's height in most engines. WebKit
|
|
26
|
+
* reports `innerHeight` and `innerWidth` in the pinch-zoomed visual
|
|
27
|
+
* viewport's px instead. At a 1.33 zoom of a 402 × 714 layout viewport,
|
|
28
|
+
* Safari on iOS 26.2 reports 536 and 302. Element rects and the visual
|
|
29
|
+
* viewport's height times its scale stay in layout px. So, read as is, a zoom
|
|
30
|
+
* shrinks the layout viewport by the zoom, and the function scales the height
|
|
31
|
+
* back.
|
|
32
|
+
*/
|
|
33
|
+
function layoutViewportHeight(win) {
|
|
34
|
+
const viewport = win.visualViewport;
|
|
35
|
+
const width = viewport?.width ?? 0;
|
|
36
|
+
if (viewport == null || !(width > 0)) return win.innerHeight - horizontalScrollbarHeight(win);
|
|
37
|
+
const scale = viewport.scale;
|
|
38
|
+
return (Math.abs(win.innerWidth - width) < Math.abs(win.innerWidth - width * scale) ? win.innerHeight * scale : win.innerHeight) - horizontalScrollbarHeight(win);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The document's classic horizontal scrollbar, CSS px. It is in
|
|
42
|
+
* `innerHeight` but not in the visual viewport's height. On a desktop page
|
|
43
|
+
* wider than its window, Chromium's `innerHeight` is 800 for a 785 px visual
|
|
44
|
+
* viewport. It is the part of `innerHeight` the root's client height leaves
|
|
45
|
+
* out, up to the thickness of a scrollbar that takes room. Where scrollbars
|
|
46
|
+
* overlay the content, as on every phone, that thickness is 0. So the room a
|
|
47
|
+
* hidden toolbar adds to `innerHeight` is never taken for a scrollbar. Chrome
|
|
48
|
+
* on Android sizes the root to the viewport with its toolbar shown.
|
|
49
|
+
*/
|
|
50
|
+
function horizontalScrollbarHeight(win) {
|
|
51
|
+
const root = win.document.documentElement;
|
|
52
|
+
const gap = win.innerHeight - root.clientHeight;
|
|
53
|
+
if (!(gap > 0) || root.scrollWidth <= root.clientWidth) return 0;
|
|
54
|
+
return Math.min(gap, scrollbarThickness(win.document));
|
|
55
|
+
}
|
|
56
|
+
let thicknesses = /* @__PURE__ */ new WeakMap();
|
|
57
|
+
/** How much room a scrollbar takes from a scrolling box: 0 where overlaid. */
|
|
58
|
+
function scrollbarThickness(doc) {
|
|
59
|
+
const devicePixelRatio = doc.defaultView?.devicePixelRatio ?? 1;
|
|
60
|
+
const known = thicknesses.get(doc);
|
|
61
|
+
if (known != null && known.devicePixelRatio === devicePixelRatio) return known.thickness;
|
|
62
|
+
const thickness = measureScrollbarThickness(doc);
|
|
63
|
+
thicknesses.set(doc, {
|
|
64
|
+
devicePixelRatio,
|
|
65
|
+
thickness
|
|
66
|
+
});
|
|
67
|
+
return thickness;
|
|
68
|
+
}
|
|
69
|
+
function measureScrollbarThickness(doc) {
|
|
70
|
+
const probe = doc.createElement("div");
|
|
71
|
+
probe.style.position = "absolute";
|
|
72
|
+
probe.style.top = "-200px";
|
|
73
|
+
probe.style.width = "100px";
|
|
74
|
+
probe.style.height = "100px";
|
|
75
|
+
probe.style.overflow = "scroll";
|
|
76
|
+
probe.style.visibility = "hidden";
|
|
77
|
+
(doc.body ?? doc.documentElement).append(probe);
|
|
78
|
+
const thickness = probe.offsetHeight - probe.clientHeight;
|
|
79
|
+
probe.remove();
|
|
80
|
+
return thickness;
|
|
81
|
+
}
|
|
82
|
+
const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
83
|
+
const HIDE_STEP_WAIT_MS = 300;
|
|
84
|
+
const HIDE_STEP_LIMIT_MS = 1e3;
|
|
85
|
+
const NON_TEXT_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
86
|
+
"button",
|
|
87
|
+
"checkbox",
|
|
88
|
+
"color",
|
|
89
|
+
"file",
|
|
90
|
+
"hidden",
|
|
91
|
+
"image",
|
|
92
|
+
"radio",
|
|
93
|
+
"range",
|
|
94
|
+
"reset",
|
|
95
|
+
"submit"
|
|
96
|
+
]);
|
|
97
|
+
/**
|
|
98
|
+
* Whether this window measures the keyboard: a top-level document with a
|
|
99
|
+
* visual viewport. Capabilities decide it, never the user agent or the
|
|
100
|
+
* pointer. The module measures a browser with its own keyboard geometry API,
|
|
101
|
+
* such as Chrome on Android with the VirtualKeyboard API, the same way.
|
|
102
|
+
* Its visual viewport shrinks for the keyboard while the layout viewport keeps
|
|
103
|
+
* its height, as everywhere else. A desktop browser's visual viewport never
|
|
104
|
+
* shrinks for a keyboard, so it reads 0. Where the app sets
|
|
105
|
+
* `interactive-widget=resizes-content`, Chrome shrinks the layout viewport
|
|
106
|
+
* with the keyboard. The height is then 0 too, and nothing rides, because the
|
|
107
|
+
* browser has made the room itself.
|
|
108
|
+
*/
|
|
109
|
+
function isKeyboardMeasurable(win) {
|
|
110
|
+
return win.visualViewport != null && win.self === win.top;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* The on-screen keyboard's height over the layout viewport, CSS px. It is 0
|
|
114
|
+
* when none is shown, also while pinch-zoomed, and wherever
|
|
115
|
+
* `isKeyboardMeasurable` is false.
|
|
116
|
+
*/
|
|
117
|
+
function measureKeyboardHeight(win) {
|
|
118
|
+
const viewport = win.visualViewport;
|
|
119
|
+
if (viewport == null || !isKeyboardMeasurable(win)) return 0;
|
|
120
|
+
const height = layoutViewportHeight(win) - viewport.height * (viewport.scale ?? 1);
|
|
121
|
+
return height > 1 ? Math.round(height * 100) / 100 : 0;
|
|
122
|
+
}
|
|
123
|
+
const stores = sharedWeakMap("keyboard/keyboard-height/stores", 2);
|
|
124
|
+
function storeOf(win) {
|
|
125
|
+
let store = stores.get(win);
|
|
126
|
+
if (store == null) {
|
|
127
|
+
store = {
|
|
128
|
+
height: 0,
|
|
129
|
+
startsAtHide: null,
|
|
130
|
+
listeners: /* @__PURE__ */ new Set(),
|
|
131
|
+
focusListeners: /* @__PURE__ */ new Set(),
|
|
132
|
+
detach: null,
|
|
133
|
+
detachFocus: null
|
|
134
|
+
};
|
|
135
|
+
stores.set(win, store);
|
|
136
|
+
}
|
|
137
|
+
return store;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Whether `win` has the VirtualKeyboard API, as Chrome on Android does. The
|
|
141
|
+
* keyboard layout guide reads Chrome's profile there (keyboardProfileOf).
|
|
142
|
+
*/
|
|
143
|
+
function hasVirtualKeyboard(win) {
|
|
144
|
+
return "virtualKeyboard" in win.navigator;
|
|
145
|
+
}
|
|
146
|
+
function isHideStep(win, shown, height) {
|
|
147
|
+
return height > 1 && height < shown - 1 && hasVirtualKeyboard(win) && matchesMediaQuery(win, REDUCED_MOTION_QUERY);
|
|
148
|
+
}
|
|
149
|
+
function attach(win, store) {
|
|
150
|
+
const viewport = win.visualViewport;
|
|
151
|
+
store.height = measureKeyboardHeight(win);
|
|
152
|
+
let stepTimer = null;
|
|
153
|
+
let stepHeight = 0;
|
|
154
|
+
let stepLimit = 0;
|
|
155
|
+
const deliver = (height, timeStamp) => {
|
|
156
|
+
if (height <= 1 && store.height > 1) store.startsAtHide = getTouches(win).starts;
|
|
157
|
+
store.height = height;
|
|
158
|
+
const report = {
|
|
159
|
+
type: "viewport",
|
|
160
|
+
height,
|
|
161
|
+
timeStamp
|
|
162
|
+
};
|
|
163
|
+
for (const listener of [...store.listeners]) listener(report);
|
|
164
|
+
};
|
|
165
|
+
const onViewport = (event) => {
|
|
166
|
+
const height = measureKeyboardHeight(win);
|
|
167
|
+
if (isHideStep(win, store.height, height)) {
|
|
168
|
+
if (stepTimer != null && Math.abs(height - stepHeight) < 1) return;
|
|
169
|
+
const now = win.performance.now();
|
|
170
|
+
if (stepTimer == null) stepLimit = now + HIDE_STEP_LIMIT_MS;
|
|
171
|
+
else clearTimeout(stepTimer);
|
|
172
|
+
stepHeight = height;
|
|
173
|
+
stepTimer = setTimeout(() => {
|
|
174
|
+
stepTimer = null;
|
|
175
|
+
deliver(measureKeyboardHeight(win), win.performance.now());
|
|
176
|
+
}, Math.min(HIDE_STEP_WAIT_MS, stepLimit - now));
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (stepTimer != null) {
|
|
180
|
+
clearTimeout(stepTimer);
|
|
181
|
+
stepTimer = null;
|
|
182
|
+
}
|
|
183
|
+
deliver(height, event.timeStamp);
|
|
184
|
+
};
|
|
185
|
+
viewport?.addEventListener("resize", onViewport);
|
|
186
|
+
viewport?.addEventListener("scroll", onViewport);
|
|
187
|
+
const stopResize = subscribeInput(win, "resize", (event) => {
|
|
188
|
+
if (!isNode(event.target)) onViewport(event);
|
|
189
|
+
});
|
|
190
|
+
return () => {
|
|
191
|
+
if (stepTimer != null) {
|
|
192
|
+
clearTimeout(stepTimer);
|
|
193
|
+
stepTimer = null;
|
|
194
|
+
}
|
|
195
|
+
viewport?.removeEventListener("resize", onViewport);
|
|
196
|
+
viewport?.removeEventListener("scroll", onViewport);
|
|
197
|
+
stopResize();
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function attachFocus(win, store) {
|
|
201
|
+
const onFocus = (event) => {
|
|
202
|
+
const report = {
|
|
203
|
+
type: event.type === "focusin" ? "focusin" : "focusout",
|
|
204
|
+
height: store.height,
|
|
205
|
+
timeStamp: event.timeStamp,
|
|
206
|
+
target: event.target,
|
|
207
|
+
relatedTarget: event.relatedTarget
|
|
208
|
+
};
|
|
209
|
+
for (const listener of [...store.focusListeners]) listener(report);
|
|
210
|
+
};
|
|
211
|
+
const stopFocusIn = subscribeInput(win, "focusin", onFocus);
|
|
212
|
+
const stopFocusOut = subscribeInput(win, "focusout", onFocus);
|
|
213
|
+
return () => {
|
|
214
|
+
stopFocusIn();
|
|
215
|
+
stopFocusOut();
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Calls `listener` with every report of `win`'s keyboard until the caller
|
|
220
|
+
* runs the returned function. It reports the viewport's changes, and focus
|
|
221
|
+
* moves too when the caller sets `focus`. All subscribers of a window share
|
|
222
|
+
* one set of listeners, and its focus listeners exist only while a subscriber
|
|
223
|
+
* asks for focus moves.
|
|
224
|
+
*
|
|
225
|
+
* @example
|
|
226
|
+
* ```
|
|
227
|
+
* const stop = subscribeKeyboardHeight(window, event => {
|
|
228
|
+
* if (event.type === 'viewport') layout(event.height);
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
function subscribeKeyboardHeight(win, listener, { focus = false } = {}) {
|
|
233
|
+
const store = storeOf(win);
|
|
234
|
+
store.listeners.add(listener);
|
|
235
|
+
store.detach ??= attach(win, store);
|
|
236
|
+
if (focus) {
|
|
237
|
+
store.focusListeners.add(listener);
|
|
238
|
+
store.detachFocus ??= attachFocus(win, store);
|
|
239
|
+
}
|
|
240
|
+
return () => {
|
|
241
|
+
store.listeners.delete(listener);
|
|
242
|
+
if (focus) {
|
|
243
|
+
store.focusListeners.delete(listener);
|
|
244
|
+
if (store.focusListeners.size === 0 && store.detachFocus != null) {
|
|
245
|
+
store.detachFocus();
|
|
246
|
+
store.detachFocus = null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (store.listeners.size === 0 && store.detach != null) {
|
|
250
|
+
store.detach();
|
|
251
|
+
store.detach = null;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Whether a finger is on `win`'s screen, from the input stream's count. A
|
|
257
|
+
* finger that was down at the keyboard's last hide counts no more until a
|
|
258
|
+
* touch starts. A touch whose target leaves the page ends at a node the
|
|
259
|
+
* window never hears.
|
|
260
|
+
*/
|
|
261
|
+
function isFingerOnScreen(win) {
|
|
262
|
+
const startsAtHide = stores.get(win)?.startsAtHide;
|
|
263
|
+
const touches = getTouches(win);
|
|
264
|
+
return touches.fingers > 0 && (startsAtHide == null || touches.starts !== startsAtHide);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* `win`'s keyboard height. While the module listens, it is the height
|
|
268
|
+
* measured at the last report. Every reader of a keyboard change, such as
|
|
269
|
+
* each component's hook, shares that one layout read. Every change of the
|
|
270
|
+
* visual viewport or the window is a report, so a reader between two reports
|
|
271
|
+
* sees the current height. With nothing listening yet, the call measures the
|
|
272
|
+
* height now.
|
|
273
|
+
*/
|
|
274
|
+
function getKeyboardHeight(win) {
|
|
275
|
+
const store = stores.get(win);
|
|
276
|
+
return store?.detach != null ? store.height : measureKeyboardHeight(win);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Whether focusing `element` brings up a keyboard for typing text. A control
|
|
280
|
+
* with `inputmode="none"` brings up none.
|
|
281
|
+
*/
|
|
282
|
+
function isTextEntryControl(element) {
|
|
283
|
+
if (!isHTMLElement(element) || element.getAttribute("inputmode") === "none") return false;
|
|
284
|
+
if (element.localName === "textarea") {
|
|
285
|
+
const textArea = element;
|
|
286
|
+
return !textArea.disabled && !textArea.readOnly;
|
|
287
|
+
}
|
|
288
|
+
if (element.localName === "input") {
|
|
289
|
+
const input = element;
|
|
290
|
+
return !input.disabled && !input.readOnly && !NON_TEXT_INPUT_TYPES.has((input.getAttribute("type") ?? "text").toLowerCase());
|
|
291
|
+
}
|
|
292
|
+
return element.matches("[contenteditable]:not([contenteditable=\"false\"])");
|
|
293
|
+
}
|
|
294
|
+
/** The text-entry control inside `container` that `target` is or labels. */
|
|
295
|
+
function findTextEntryControl(target, container) {
|
|
296
|
+
if (!isElement(target)) return null;
|
|
297
|
+
const direct = target.closest("input, textarea, [contenteditable]:not([contenteditable=\"false\"])");
|
|
298
|
+
if (container.contains(direct) && isTextEntryControl(direct)) return direct;
|
|
299
|
+
const label = target.closest("label");
|
|
300
|
+
const control = isHTMLElement(label) ? label.control : null;
|
|
301
|
+
return container.contains(control) && isTextEntryControl(control) ? control : null;
|
|
302
|
+
}
|
|
303
|
+
//#endregion
|
|
304
|
+
//#region src/keyboard/keyboardGeometry.ts
|
|
305
|
+
const targets = sharedWeakSet("keyboard/keyboard-target/targets", 1);
|
|
306
|
+
/** Registers `element` as a keyboard target until the returned call. */
|
|
307
|
+
function registerKeyboardTarget(element) {
|
|
308
|
+
targets.add(element);
|
|
309
|
+
return () => {
|
|
310
|
+
targets.delete(element);
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
/** Whether a registered target holds `element`. */
|
|
314
|
+
function isInsideKeyboardTarget(element) {
|
|
315
|
+
for (let node = element.parentElement; node != null; node = node.parentElement) if (targets.has(node)) return true;
|
|
316
|
+
return false;
|
|
317
|
+
}
|
|
318
|
+
function restingBottom(element, animator) {
|
|
319
|
+
return element.getBoundingClientRect().bottom - animator.get("y");
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* How far a ride has moved `element` from where its layout puts it, as the
|
|
323
|
+
* page draws it now, CSS px. Reading the style creates no animator.
|
|
324
|
+
*/
|
|
325
|
+
function drawnOffsetOf(element) {
|
|
326
|
+
const translate = element.ownerDocument.defaultView?.getComputedStyle(element).translate ?? "";
|
|
327
|
+
return Number.parseFloat(translate.split(" ")[1] ?? "") || 0;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* How the nearest fixed-position ancestor of `element` meets the keyboard. It
|
|
331
|
+
* is docked when its layout puts its bottom at the layout viewport's bottom
|
|
332
|
+
* edge. It can also fill the viewport, as a dialog does, or float above the
|
|
333
|
+
* bottom edge. Null with no fixed ancestor, as in page content.
|
|
334
|
+
*/
|
|
335
|
+
function fixedContainerOf(element) {
|
|
336
|
+
const view = element.ownerDocument.defaultView;
|
|
337
|
+
const node = nearestFixedAncestor(element);
|
|
338
|
+
if (view == null || node == null) return null;
|
|
339
|
+
const dock = dockOf(node, view);
|
|
340
|
+
return dock === "docked" ? { docked: node } : dock;
|
|
341
|
+
}
|
|
342
|
+
function nearestFixedAncestor(element) {
|
|
343
|
+
const view = element.ownerDocument.defaultView;
|
|
344
|
+
if (view == null) return null;
|
|
345
|
+
for (let node = element.parentElement; node != null; node = node.parentElement) if (view.getComputedStyle(node).position === "fixed") return node;
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
function transformOffsetOf(element, view) {
|
|
349
|
+
const transform = view.getComputedStyle(element).transform;
|
|
350
|
+
const matrix = /^matrix(3d)?\(([^)]*)\)$/.exec(transform);
|
|
351
|
+
if (matrix == null) return 0;
|
|
352
|
+
const values = (matrix[2] ?? "").split(",").map(Number);
|
|
353
|
+
const y = matrix[1] == null ? values[5] : values[13];
|
|
354
|
+
return y != null && Number.isFinite(y) ? y : 0;
|
|
355
|
+
}
|
|
356
|
+
function dockOf(node, view) {
|
|
357
|
+
const viewportBottom = layoutViewportHeight(view);
|
|
358
|
+
const box = node.getBoundingClientRect();
|
|
359
|
+
if (box.height >= viewportBottom - 1) return "fills-viewport";
|
|
360
|
+
const bottom = box.bottom - drawnOffsetOf(node) - transformOffsetOf(node, view);
|
|
361
|
+
return Math.abs(viewportBottom - bottom) <= 1 ? "docked" : "floating";
|
|
362
|
+
}
|
|
363
|
+
const riddenAnimators = sharedWeakMap("keyboard/keyboard-target/ridden-animators", 1);
|
|
364
|
+
function hasOwnTranslate(node, view) {
|
|
365
|
+
const translate = view.getComputedStyle(node).translate;
|
|
366
|
+
if (translate === "" || translate === "none") return false;
|
|
367
|
+
const ride = riddenAnimators.get(node);
|
|
368
|
+
return ride == null || ride.get("y") === 0;
|
|
369
|
+
}
|
|
370
|
+
const POSITION_PROPERTIES = /* @__PURE__ */ new Set([
|
|
371
|
+
"transform",
|
|
372
|
+
"translate",
|
|
373
|
+
"top",
|
|
374
|
+
"bottom",
|
|
375
|
+
"inset",
|
|
376
|
+
"inset-block",
|
|
377
|
+
"inset-block-start",
|
|
378
|
+
"inset-block-end"
|
|
379
|
+
]);
|
|
380
|
+
const KEYFRAME_FIELDS = /* @__PURE__ */ new Set([
|
|
381
|
+
"offset",
|
|
382
|
+
"computedOffset",
|
|
383
|
+
"easing",
|
|
384
|
+
"composite"
|
|
385
|
+
]);
|
|
386
|
+
function animatedProperties(animation) {
|
|
387
|
+
if ("transitionProperty" in animation) return [String(animation.transitionProperty)];
|
|
388
|
+
const effect = animation.effect;
|
|
389
|
+
if (effect == null || !("getKeyframes" in effect)) return [];
|
|
390
|
+
const names = /* @__PURE__ */ new Set();
|
|
391
|
+
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()}`));
|
|
392
|
+
return [...names];
|
|
393
|
+
}
|
|
394
|
+
function isMovedByApp(node) {
|
|
395
|
+
if (typeof node.getAnimations !== "function") return false;
|
|
396
|
+
const isRidden = riddenAnimators.has(node);
|
|
397
|
+
return node.getAnimations().some((animation) => {
|
|
398
|
+
if (animation.playState !== "running") return false;
|
|
399
|
+
const isTransition = "transitionProperty" in animation;
|
|
400
|
+
if (!isTransition && !("animationName" in animation)) return false;
|
|
401
|
+
const properties = animatedProperties(animation);
|
|
402
|
+
if (isRidden && isTransition && properties.every((property) => property === "translate")) return false;
|
|
403
|
+
return properties.some((property) => POSITION_PROPERTIES.has(property));
|
|
404
|
+
});
|
|
405
|
+
}
|
|
406
|
+
function isDockedContainer(node) {
|
|
407
|
+
const view = node.ownerDocument.defaultView;
|
|
408
|
+
return view != null && view.getComputedStyle(node).position === "fixed" && dockOf(node, view) === "docked";
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* How far a bottom edge at `bottom` sits under the keyboard's top, plus
|
|
412
|
+
* `offset`, CSS px; 0 when it clears it. An overlap under one CSS px is the
|
|
413
|
+
* viewport's rounding, not an obstruction.
|
|
414
|
+
*/
|
|
415
|
+
function coveredBy(bottom, height, offset, win) {
|
|
416
|
+
const covered = bottom + offset - (layoutViewportHeight(win) - height);
|
|
417
|
+
return height > 0 && covered > 1 ? covered : 0;
|
|
418
|
+
}
|
|
419
|
+
function focusedFieldIn(target) {
|
|
420
|
+
const active = target.ownerDocument.activeElement;
|
|
421
|
+
return active != null && active !== target && target.contains(active) && isTextEntryControl(active) ? active : null;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Whether `win` keeps fields above a keyboard at all: a top-level document
|
|
425
|
+
* whose visual viewport shrinks for the keyboard, under a coarse primary
|
|
426
|
+
* pointer.
|
|
427
|
+
*/
|
|
428
|
+
function followsKeyboard(win) {
|
|
429
|
+
return win != null && isKeyboardMeasurable(win) && isCoarsePointer(win);
|
|
430
|
+
}
|
|
431
|
+
//#endregion
|
|
432
|
+
//#region src/keyboard/focusReveal.ts
|
|
433
|
+
/**
|
|
434
|
+
* @file focusReveal.ts
|
|
435
|
+
* @input A document's capture-phase `blur`, through the input stream
|
|
436
|
+
* @output refuseFocusReveal, which delivers the focus moves a surface claims
|
|
437
|
+
* with `preventScroll`, and its test-only caller count
|
|
438
|
+
* @position Keyboard module, internal to core. Every caller in a document
|
|
439
|
+
* shares one listener.
|
|
440
|
+
*/
|
|
441
|
+
const focusTakeovers = sharedWeakMap("keyboard/keyboard-height/focus-takeovers", 1);
|
|
442
|
+
/**
|
|
443
|
+
* Delivers the focus moves `claim` accepts with `preventScroll`, so the
|
|
444
|
+
* browser never reveals their destination itself. It stops when the caller
|
|
445
|
+
* runs the returned function.
|
|
446
|
+
*
|
|
447
|
+
* The browser dispatches `blur` in the capture phase ahead of its own focus
|
|
448
|
+
* step, and `blur` names the destination in `relatedTarget`. Focusing it there
|
|
449
|
+
* with preventScroll settles the change. The browser's step then finds the
|
|
450
|
+
* element already active, so it dispatches nothing further and reveals
|
|
451
|
+
* nothing.
|
|
452
|
+
*
|
|
453
|
+
* @example
|
|
454
|
+
* ```
|
|
455
|
+
* const stop = refuseFocusReveal(document, {
|
|
456
|
+
* claim: target => findTextEntryControl(target, body),
|
|
457
|
+
* park: () => sheet.focus({preventScroll: true}),
|
|
458
|
+
* });
|
|
459
|
+
* ```
|
|
460
|
+
*/
|
|
461
|
+
function refuseFocusReveal(doc, { isActive, claim, park }) {
|
|
462
|
+
const onBlur = (event) => {
|
|
463
|
+
if (isActive != null && !isActive()) return;
|
|
464
|
+
const destination = claim(event.relatedTarget);
|
|
465
|
+
if (destination != null) {
|
|
466
|
+
if (destination !== doc.activeElement) destination.focus({ preventScroll: true });
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
if (event.relatedTarget == null) park?.(event.target);
|
|
470
|
+
};
|
|
471
|
+
let shared = focusTakeovers.get(doc);
|
|
472
|
+
if (shared == null) {
|
|
473
|
+
const view = doc.defaultView;
|
|
474
|
+
if (view == null) return () => {};
|
|
475
|
+
const callers = /* @__PURE__ */ new Set();
|
|
476
|
+
const listener = (event) => {
|
|
477
|
+
for (const caller of [...callers]) if (callers.has(caller)) caller(event);
|
|
478
|
+
};
|
|
479
|
+
shared = {
|
|
480
|
+
stop: subscribeInput(view, "blur", (event) => {
|
|
481
|
+
if (isNode(event.target)) listener(event);
|
|
482
|
+
}),
|
|
483
|
+
callers
|
|
484
|
+
};
|
|
485
|
+
focusTakeovers.set(doc, shared);
|
|
486
|
+
}
|
|
487
|
+
shared.callers.add(onBlur);
|
|
488
|
+
return () => {
|
|
489
|
+
const current = focusTakeovers.get(doc);
|
|
490
|
+
if (current == null || !current.callers.delete(onBlur)) return;
|
|
491
|
+
if (current.callers.size === 0) {
|
|
492
|
+
current.stop();
|
|
493
|
+
focusTakeovers.delete(doc);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
}
|
|
497
|
+
//#endregion
|
|
498
|
+
//#region src/motion/android/keyboard.ts
|
|
499
|
+
/**
|
|
500
|
+
* @file keyboard.ts
|
|
501
|
+
* @input None
|
|
502
|
+
* @output `keyboard`: how the software keyboard moves on Android, in Chrome
|
|
503
|
+
* with Gboard, as the page sees it. It holds the slides' durations and
|
|
504
|
+
* curves, and when they start against Chrome's report and a blur.
|
|
505
|
+
* @position The keyboard domain of the Android constants table, read by
|
|
506
|
+
* keyboard/keyboardModel.ts. The UIKit table holds iOS's keyboard.
|
|
507
|
+
*/
|
|
508
|
+
const keyboard = {
|
|
509
|
+
/**
|
|
510
|
+
* How long Gboard takes to slide up, in ms: from its first moved frame to
|
|
511
|
+
* its resting top.
|
|
512
|
+
*
|
|
513
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
514
|
+
* emulator); 20 shows recorded frame by frame: 250 to 282 ms, 18 of
|
|
515
|
+
* them 264 to 268 ms, Oct 25 2026
|
|
516
|
+
*/
|
|
517
|
+
showMs: 267,
|
|
518
|
+
/**
|
|
519
|
+
* The curve of Gboard's slide up, cubic-bézier control points: fast out,
|
|
520
|
+
* a long settle.
|
|
521
|
+
*
|
|
522
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
523
|
+
* emulator); the same 20 shows fit this curve over `showMs` within
|
|
524
|
+
* 2.4 px rms, Oct 25 2026
|
|
525
|
+
*/
|
|
526
|
+
showCurve: [
|
|
527
|
+
.1,
|
|
528
|
+
0,
|
|
529
|
+
0,
|
|
530
|
+
1
|
|
531
|
+
],
|
|
532
|
+
/**
|
|
533
|
+
* How long after Gboard starts to slide up Chrome's report of it fires, in
|
|
534
|
+
* ms. A show rides from the report dated back by this, joining the slide
|
|
535
|
+
* where it is.
|
|
536
|
+
*
|
|
537
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
538
|
+
* emulator); twelve shows: the first frame the page painted after the
|
|
539
|
+
* visual viewport's resize came 14 to 35 ms (median 33) after Gboard's
|
|
540
|
+
* first moved frame, less the 8 ms an event takes on average to reach
|
|
541
|
+
* the screen, Oct 25 2026
|
|
542
|
+
*/
|
|
543
|
+
showReportLagMs: 25,
|
|
544
|
+
/**
|
|
545
|
+
* How long Gboard takes to slide down out of the page, in ms.
|
|
546
|
+
*
|
|
547
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
548
|
+
* emulator); 21 hides recorded frame by frame, from Gboard's first
|
|
549
|
+
* moved frame until it leaves the screen: 148 to 153 ms in 20 of them;
|
|
550
|
+
* this length with `hideCurve` fits them within 7.7 px rms,
|
|
551
|
+
* Oct 25 2026
|
|
552
|
+
*/
|
|
553
|
+
hideMs: 167,
|
|
554
|
+
/**
|
|
555
|
+
* The curve of Gboard's slide down, cubic-bézier control points: a slow
|
|
556
|
+
* first frame, then fast.
|
|
557
|
+
*
|
|
558
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
559
|
+
* emulator); the same 21 hides, a free fit over `hideMs`, Oct 25 2026
|
|
560
|
+
*/
|
|
561
|
+
hideCurve: [
|
|
562
|
+
.3,
|
|
563
|
+
.1,
|
|
564
|
+
.2,
|
|
565
|
+
.9
|
|
566
|
+
],
|
|
567
|
+
/**
|
|
568
|
+
* How long after the focused field blurs (to nothing that brings up a
|
|
569
|
+
* keyboard) Gboard starts to slide down, in ms.
|
|
570
|
+
*
|
|
571
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
572
|
+
* emulator); five scripted blurs with a marker the page paints on the
|
|
573
|
+
* blur: Gboard's first moved frame came from a frame before the marker
|
|
574
|
+
* to 33 ms after it (median 16), Oct 25 2026
|
|
575
|
+
*/
|
|
576
|
+
hideAfterBlurMs: 16,
|
|
577
|
+
/**
|
|
578
|
+
* How long after Gboard starts to slide down Chrome's report of the hide
|
|
579
|
+
* fires, in ms, measured on blurs. A hide nothing predicts, such as Back,
|
|
580
|
+
* reuses it, though Chrome can report Back later in the slide.
|
|
581
|
+
*
|
|
582
|
+
* @source measured: Chromium 158 with Gboard on Android 15 (API 35
|
|
583
|
+
* emulator); twelve scripted blurs: the visual viewport's resize came
|
|
584
|
+
* 42 to 52 ms after the blur (median 49), less `hideAfterBlurMs`,
|
|
585
|
+
* Oct 25 2026
|
|
586
|
+
*/
|
|
587
|
+
hideReportLagMs: 33
|
|
588
|
+
};
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region src/keyboard/keyboardModel.ts
|
|
591
|
+
/**
|
|
592
|
+
* @file keyboardModel.ts
|
|
593
|
+
* @input `keyboard` from the Android table: Gboard's slides and Chrome's
|
|
594
|
+
* report timings
|
|
595
|
+
* @output createKeyboardModel, the keyboard layout guide's clock-free core,
|
|
596
|
+
* and the KeyboardTransition and KeyboardModel types
|
|
597
|
+
* @position The state of the keyboard layout guide (keyboardLayoutGuide.ts).
|
|
598
|
+
* It infers the keyboard's transition from the visual viewport's reports
|
|
599
|
+
* and focus changes, each input with its own time. It is internal to core.
|
|
600
|
+
*/
|
|
601
|
+
const EPSILON = .5;
|
|
602
|
+
/**
|
|
603
|
+
* Creates the guide's core. Tests drive it with explicit times, and the
|
|
604
|
+
* window's guide feeds it events.
|
|
605
|
+
*
|
|
606
|
+
* Chrome reports each keyboard slide through the visual viewport just after
|
|
607
|
+
* it starts. Content rides Gboard's own
|
|
608
|
+
* slides, fitted on Chromium 158 with Gboard (motion/android/keyboard.ts).
|
|
609
|
+
*
|
|
610
|
+
* - Show: from the report, dated back `androidKeyboard.showReportLagMs`, on
|
|
611
|
+
* `showCurve` over `showMs`, joining the slide where it is. The report's
|
|
612
|
+
* first painted frame trails Gboard's first moved frame by 14 to 35 ms. An
|
|
613
|
+
* `<input>` that brings an accessory bar first gives a smaller report
|
|
614
|
+
* before the keyboard's. It rides to the last keyboard's height instead, as
|
|
615
|
+
* a prediction, and the keyboard's report confirms it.
|
|
616
|
+
* - Hide: on `hideCurve` over `hideMs`. It starts
|
|
617
|
+
* `androidKeyboard.hideAfterBlurMs` after a blur that brings no keyboard,
|
|
618
|
+
* as a prediction, because Gboard starts down at the blur. When nothing
|
|
619
|
+
* predicted it, as with Back, it starts from Chrome's report, dated back
|
|
620
|
+
* `hideReportLagMs`, the lag measured on blurs.
|
|
621
|
+
* - A keyboard that changes while up, such as another keyboard, lays out at
|
|
622
|
+
* once.
|
|
623
|
+
*
|
|
624
|
+
* A prediction the viewport has not confirmed by its end gives way to what
|
|
625
|
+
* the viewport says (`verify`).
|
|
626
|
+
*/
|
|
627
|
+
function createKeyboardModel(initialInset = 0) {
|
|
628
|
+
let transition = {
|
|
629
|
+
kind: "change",
|
|
630
|
+
from: initialInset,
|
|
631
|
+
to: initialInset,
|
|
632
|
+
start: -Infinity,
|
|
633
|
+
velocity: 0,
|
|
634
|
+
animated: false,
|
|
635
|
+
predicted: false,
|
|
636
|
+
curve: null
|
|
637
|
+
};
|
|
638
|
+
let curve = null;
|
|
639
|
+
const easedCurve = (from, to, slide) => {
|
|
640
|
+
const span = slide.durationMs / 1e3;
|
|
641
|
+
const ease = cubicBezier(slide.points);
|
|
642
|
+
const value = (t) => from + (to - from) * ease(Math.min(1, Math.max(0, t / span)));
|
|
643
|
+
return {
|
|
644
|
+
value,
|
|
645
|
+
velocity: (t) => {
|
|
646
|
+
if (t >= span) return 0;
|
|
647
|
+
const a = Math.max(0, t - .001);
|
|
648
|
+
const b = Math.min(span, t + .001);
|
|
649
|
+
return (value(b) - value(a)) / (b - a);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
const showSlide = {
|
|
654
|
+
durationMs: keyboard.showMs,
|
|
655
|
+
points: keyboard.showCurve
|
|
656
|
+
};
|
|
657
|
+
const hideSlide = {
|
|
658
|
+
durationMs: keyboard.hideMs,
|
|
659
|
+
points: keyboard.hideCurve
|
|
660
|
+
};
|
|
661
|
+
const lengthOf = () => transition.curve != null ? transition.curve.durationMs : 0;
|
|
662
|
+
let shownInset = initialInset;
|
|
663
|
+
const presentation = (time) => {
|
|
664
|
+
if (time < transition.start) return transition.from;
|
|
665
|
+
if (curve == null || time >= transition.start + lengthOf()) return transition.to;
|
|
666
|
+
return curve.value((time - transition.start) / 1e3);
|
|
667
|
+
};
|
|
668
|
+
const velocity = (time) => {
|
|
669
|
+
if (time <= transition.start) return transition.velocity;
|
|
670
|
+
if (curve == null || time >= transition.start + lengthOf()) return 0;
|
|
671
|
+
return curve.velocity((time - transition.start) / 1e3);
|
|
672
|
+
};
|
|
673
|
+
const begin = (kind, to, start, { animated = true, predicted = false } = {}) => {
|
|
674
|
+
const at = Math.max(start, transition.start);
|
|
675
|
+
const from = presentation(at);
|
|
676
|
+
const v = animated ? velocity(at) : 0;
|
|
677
|
+
const slide = animated ? to > from ? showSlide : hideSlide : null;
|
|
678
|
+
transition = {
|
|
679
|
+
kind,
|
|
680
|
+
from,
|
|
681
|
+
to,
|
|
682
|
+
start: at,
|
|
683
|
+
velocity: v,
|
|
684
|
+
animated,
|
|
685
|
+
predicted,
|
|
686
|
+
curve: slide
|
|
687
|
+
};
|
|
688
|
+
curve = slide != null && Math.abs(to - from) + Math.abs(v) > 0 ? easedCurve(from, to, slide) : null;
|
|
689
|
+
if (to > EPSILON) shownInset = to;
|
|
690
|
+
return transition;
|
|
691
|
+
};
|
|
692
|
+
const confirm = () => {
|
|
693
|
+
if (transition.predicted) transition = {
|
|
694
|
+
...transition,
|
|
695
|
+
predicted: false
|
|
696
|
+
};
|
|
697
|
+
return null;
|
|
698
|
+
};
|
|
699
|
+
return {
|
|
700
|
+
get inset() {
|
|
701
|
+
return transition.to;
|
|
702
|
+
},
|
|
703
|
+
get transition() {
|
|
704
|
+
return transition;
|
|
705
|
+
},
|
|
706
|
+
presentation,
|
|
707
|
+
velocity,
|
|
708
|
+
report(inset, time) {
|
|
709
|
+
if (inset == null) return null;
|
|
710
|
+
const target = transition.to;
|
|
711
|
+
if (Math.abs(inset - target) < EPSILON) return confirm();
|
|
712
|
+
if (inset <= EPSILON) return begin("hide", 0, time - keyboard.hideReportLagMs);
|
|
713
|
+
if (target <= EPSILON) {
|
|
714
|
+
const predicted = shownInset > inset + EPSILON;
|
|
715
|
+
return begin("show", predicted ? shownInset : inset, time - keyboard.showReportLagMs, { predicted });
|
|
716
|
+
}
|
|
717
|
+
return begin("change", inset, time, { animated: false });
|
|
718
|
+
},
|
|
719
|
+
blurred(time) {
|
|
720
|
+
if (transition.to <= EPSILON) return null;
|
|
721
|
+
return begin("hide", 0, time + keyboard.hideAfterBlurMs, { predicted: true });
|
|
722
|
+
},
|
|
723
|
+
focused(time) {
|
|
724
|
+
if (transition.kind !== "hide" || !transition.predicted) return null;
|
|
725
|
+
return begin("show", shownInset, Math.max(time, transition.start), { predicted: true });
|
|
726
|
+
},
|
|
727
|
+
verify(inset, time) {
|
|
728
|
+
if (!transition.predicted || inset == null || time < transition.start + lengthOf()) return null;
|
|
729
|
+
if (Math.abs(inset - transition.to) < EPSILON) return confirm();
|
|
730
|
+
return begin(inset > transition.to ? "show" : "hide", inset, time);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
//#endregion
|
|
735
|
+
//#region src/keyboard/keyboardLayoutGuide.ts
|
|
736
|
+
/**
|
|
737
|
+
* Whose keyboard schedule the guide reads: `chromium` where the browser has
|
|
738
|
+
* the VirtualKeyboard API, else null. Without the profile, no surface rides
|
|
739
|
+
* the guide. Chrome reports the keyboard as each slide starts. The profile is
|
|
740
|
+
* a capability, never the user agent. motion/android/keyboard.ts holds the
|
|
741
|
+
* measured timing.
|
|
742
|
+
*/
|
|
743
|
+
function keyboardProfileOf(win) {
|
|
744
|
+
return hasVirtualKeyboard(win) ? "chromium" : null;
|
|
745
|
+
}
|
|
746
|
+
const VERIFY_SLACK_MS = 150;
|
|
747
|
+
const FOCUS_HANDOFF_MS = 150;
|
|
748
|
+
const PICKER_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
749
|
+
"date",
|
|
750
|
+
"datetime-local",
|
|
751
|
+
"month",
|
|
752
|
+
"time",
|
|
753
|
+
"week"
|
|
754
|
+
]);
|
|
755
|
+
/**
|
|
756
|
+
* Whether focusing `target` brings up a software keyboard (or another input
|
|
757
|
+
* view in its place, as a select's picker does).
|
|
758
|
+
*/
|
|
759
|
+
function bringsUpKeyboard(target) {
|
|
760
|
+
const element = target instanceof Element ? target : null;
|
|
761
|
+
return isTextEntryControl(element) || element instanceof HTMLSelectElement && !element.disabled;
|
|
762
|
+
}
|
|
763
|
+
function opensPickerOverPage(target) {
|
|
764
|
+
const element = target;
|
|
765
|
+
if (element == null || element.nodeType !== 1) return false;
|
|
766
|
+
return element.tagName === "SELECT" || element.tagName === "INPUT" && PICKER_INPUT_TYPES.has(element.type);
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* Whether `target` can hold a field the page cannot see: a frame, an open
|
|
770
|
+
* shadow host or a custom element. Focus on a field inside one leaves
|
|
771
|
+
* `document.activeElement` on it.
|
|
772
|
+
*/
|
|
773
|
+
function hidesField(target) {
|
|
774
|
+
return target.tagName === "IFRAME" || target.tagName === "FRAME" || target.tagName === "OBJECT" || target.tagName === "EMBED" || target.shadowRoot != null || target.tagName.includes("-");
|
|
775
|
+
}
|
|
776
|
+
const guides = sharedWeakMap("keyboard/keyboard-layout-guide/guides", 1);
|
|
777
|
+
/**
|
|
778
|
+
* The window's keyboard layout guide, created on first use.
|
|
779
|
+
*
|
|
780
|
+
* One guide serves each window. It subscribes to the keyboard module only
|
|
781
|
+
* while something subscribes to it. It owns no listener and measures nothing.
|
|
782
|
+
* It feeds the model the module's reports, the keyboard height and the focus
|
|
783
|
+
* changes that start a hide. It hands each transition to its subscribers.
|
|
784
|
+
* What it adds is timing: when a show started, a hide predicted from the
|
|
785
|
+
* blur, and the motion in between. Layout follows the keyboard height
|
|
786
|
+
* itself, and the guide's transitions only time the optional ride on top.
|
|
787
|
+
*
|
|
788
|
+
* The model reads Chrome's measured schedule: Chrome reports each slide just
|
|
789
|
+
* after it starts. A surface rides the guide only where the VirtualKeyboard
|
|
790
|
+
* API reports the keyboard. Focus can move from one field to another through
|
|
791
|
+
* something that brings no keyboard, such as a popover's container. Chrome
|
|
792
|
+
* then reports the keyboard gone for a moment and then back. So a hide
|
|
793
|
+
* reported while a field that just got focus still has it waits until the
|
|
794
|
+
* move settles.
|
|
795
|
+
*
|
|
796
|
+
* A busy page reads Chrome's reports late, after Gboard's slide. So once a
|
|
797
|
+
* hide predicted from a blur is under way, a report of the keyboard partway
|
|
798
|
+
* down, or still up, starts nothing. Only the report of the keyboard gone
|
|
799
|
+
* confirms the hide. Focus that comes back still turns it around. Focus in a
|
|
800
|
+
* frame, an open shadow host or a custom element can keep up a keyboard the
|
|
801
|
+
* guide cannot see. There the viewport decides, as before. A closed shadow
|
|
802
|
+
* root on a built-in element reads as nothing focused.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* ```
|
|
806
|
+
* const guide = getKeyboardLayoutGuide(window);
|
|
807
|
+
* const unsubscribe = guide.subscribe(t => {
|
|
808
|
+
* rideKeyboard(animator, {y: -t.to}, t);
|
|
809
|
+
* });
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
function getKeyboardLayoutGuide(win) {
|
|
813
|
+
let guide = guides.get(win);
|
|
814
|
+
if (guide == null) {
|
|
815
|
+
guide = createGuide(win);
|
|
816
|
+
guides.set(win, guide);
|
|
817
|
+
}
|
|
818
|
+
return guide;
|
|
819
|
+
}
|
|
820
|
+
function createGuide(win) {
|
|
821
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
822
|
+
let profile = keyboardProfileOf(win);
|
|
823
|
+
let model = createKeyboardModel(getKeyboardHeight(win));
|
|
824
|
+
let verifyTimer = null;
|
|
825
|
+
let detach = null;
|
|
826
|
+
const keepsInputView = (target) => bringsUpKeyboard(target) && !(profile === "chromium" && opensPickerOverPage(target));
|
|
827
|
+
const awaitsHide = () => {
|
|
828
|
+
const active = win.document.activeElement;
|
|
829
|
+
return model.transition.kind === "hide" && model.transition.predicted && !keepsInputView(active) && !(active != null && hidesField(active));
|
|
830
|
+
};
|
|
831
|
+
const publish = (transition) => {
|
|
832
|
+
if (transition == null) return;
|
|
833
|
+
if (transition.predicted) scheduleVerify(transition);
|
|
834
|
+
for (const listener of [...listeners]) listener(transition);
|
|
835
|
+
};
|
|
836
|
+
function scheduleVerify(transition) {
|
|
837
|
+
if (verifyTimer != null) clearTimeout(verifyTimer);
|
|
838
|
+
const due = transition.start + (transition.curve?.durationMs ?? 0) + VERIFY_SLACK_MS;
|
|
839
|
+
verifyTimer = setTimeout(() => {
|
|
840
|
+
verifyTimer = null;
|
|
841
|
+
const inset = getKeyboardHeight(win);
|
|
842
|
+
if (inset != null && inset > .5 && awaitsHide()) return;
|
|
843
|
+
publish(model.verify(inset, win.performance.now()));
|
|
844
|
+
}, Math.max(0, due - win.performance.now()));
|
|
845
|
+
}
|
|
846
|
+
const attach = () => {
|
|
847
|
+
profile = keyboardProfileOf(win);
|
|
848
|
+
model = createKeyboardModel(getKeyboardHeight(win));
|
|
849
|
+
let keyboardFocusAt = -Infinity;
|
|
850
|
+
let handoffTimer = null;
|
|
851
|
+
const report = (height, time) => {
|
|
852
|
+
if (handoffTimer != null) {
|
|
853
|
+
clearTimeout(handoffTimer);
|
|
854
|
+
handoffTimer = null;
|
|
855
|
+
}
|
|
856
|
+
const settled = keyboardFocusAt + FOCUS_HANDOFF_MS;
|
|
857
|
+
if (profile === "chromium" && height < .5 && model.inset >= .5 && time < settled && keepsInputView(win.document.activeElement)) {
|
|
858
|
+
handoffTimer = setTimeout(() => {
|
|
859
|
+
handoffTimer = null;
|
|
860
|
+
publish(model.report(getKeyboardHeight(win), settled));
|
|
861
|
+
}, settled - time);
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
if (height > .5 && awaitsHide()) return null;
|
|
865
|
+
return model.report(height, time);
|
|
866
|
+
};
|
|
867
|
+
const onReport = (event) => {
|
|
868
|
+
if (event.type === "viewport") publish(report(event.height, event.timeStamp));
|
|
869
|
+
else if (event.type === "focusin") {
|
|
870
|
+
if (keepsInputView(event.target)) {
|
|
871
|
+
keyboardFocusAt = event.timeStamp;
|
|
872
|
+
publish(model.focused(event.timeStamp));
|
|
873
|
+
}
|
|
874
|
+
} else if (keepsInputView(event.target) && !keepsInputView(event.relatedTarget)) publish(model.blurred(event.timeStamp));
|
|
875
|
+
};
|
|
876
|
+
const unsubscribe = subscribeKeyboardHeight(win, onReport, { focus: true });
|
|
877
|
+
return () => {
|
|
878
|
+
unsubscribe();
|
|
879
|
+
if (handoffTimer != null) {
|
|
880
|
+
clearTimeout(handoffTimer);
|
|
881
|
+
handoffTimer = null;
|
|
882
|
+
}
|
|
883
|
+
if (verifyTimer != null) {
|
|
884
|
+
clearTimeout(verifyTimer);
|
|
885
|
+
verifyTimer = null;
|
|
886
|
+
}
|
|
887
|
+
};
|
|
888
|
+
};
|
|
889
|
+
return {
|
|
890
|
+
get profile() {
|
|
891
|
+
return profile;
|
|
892
|
+
},
|
|
893
|
+
get inset() {
|
|
894
|
+
return model.inset;
|
|
895
|
+
},
|
|
896
|
+
get transition() {
|
|
897
|
+
return model.transition;
|
|
898
|
+
},
|
|
899
|
+
presentation(time = win.performance.now()) {
|
|
900
|
+
return model.presentation(time);
|
|
901
|
+
},
|
|
902
|
+
subscribe(listener) {
|
|
903
|
+
listeners.add(listener);
|
|
904
|
+
detach ??= attach();
|
|
905
|
+
return () => {
|
|
906
|
+
listeners.delete(listener);
|
|
907
|
+
if (listeners.size === 0 && detach != null) {
|
|
908
|
+
detach();
|
|
909
|
+
detach = null;
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
};
|
|
914
|
+
}
|
|
915
|
+
//#endregion
|
|
916
|
+
//#region src/keyboard/keyboardScrollBack.ts
|
|
917
|
+
/**
|
|
918
|
+
* @file keyboardScrollBack.ts
|
|
919
|
+
* @input The keyboard module's reports, the input stream's focus and touches,
|
|
920
|
+
* and Reduce Motion
|
|
921
|
+
* @output The scroll back: each scroll Core makes to keep a field above the
|
|
922
|
+
* keyboard goes back when the keyboard goes (claimKeyboardScrollBack,
|
|
923
|
+
* noteKeyboardScroll, keyboardScrollTarget, stopKeyboardScrollBack)
|
|
924
|
+
* @position Keyboard module, internal to core. keyboardReveal.ts records the
|
|
925
|
+
* scrolls and keyboardTarget.ts claims the scroll back for each field.
|
|
926
|
+
*/
|
|
927
|
+
const addedScrolls = sharedWeakMap("keyboard/keyboard-target/scroll-back-added-scrolls", 1);
|
|
928
|
+
const stopsOf = sharedWeakMap("keyboard/keyboard-target/scroll-back-stops", 1);
|
|
929
|
+
const foldWaitsOf = sharedWeakMap("keyboard/keyboard-target/scroll-back-fold-waits", 1);
|
|
930
|
+
const claimants = sharedWeakMap("keyboard/keyboard-target/scroll-back-claimants", 1);
|
|
931
|
+
/**
|
|
932
|
+
* Counts a field that keeps itself above `win`'s keyboard until the returned
|
|
933
|
+
* call. Once no such field is left, nothing is put back: its page is gone.
|
|
934
|
+
*/
|
|
935
|
+
function claimKeyboardScrollBack(win) {
|
|
936
|
+
claimants.set(win, (claimants.get(win) ?? 0) + 1);
|
|
937
|
+
let isClaimed = true;
|
|
938
|
+
return () => {
|
|
939
|
+
if (!isClaimed) return;
|
|
940
|
+
isClaimed = false;
|
|
941
|
+
const left = (claimants.get(win) ?? 1) - 1;
|
|
942
|
+
claimants.set(win, left);
|
|
943
|
+
if (left === 0) {
|
|
944
|
+
stopsOf.get(win)?.();
|
|
945
|
+
foldWaitsOf.get(win)?.();
|
|
946
|
+
}
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
function isRoot(scroller) {
|
|
950
|
+
const doc = scroller.ownerDocument;
|
|
951
|
+
return scroller === (doc.scrollingElement ?? doc.documentElement);
|
|
952
|
+
}
|
|
953
|
+
/** How far `scroller` is scrolled; for the root, the document's scroll. */
|
|
954
|
+
function scrollTopOf(scroller, win) {
|
|
955
|
+
return isRoot(scroller) ? win.scrollY : scroller.scrollTop;
|
|
956
|
+
}
|
|
957
|
+
function scrollTopTo(scroller, top, behavior, win) {
|
|
958
|
+
if (isRoot(scroller)) win.scrollTo({
|
|
959
|
+
top,
|
|
960
|
+
behavior
|
|
961
|
+
});
|
|
962
|
+
else if (typeof scroller.scrollTo === "function") scroller.scrollTo({
|
|
963
|
+
top,
|
|
964
|
+
behavior
|
|
965
|
+
});
|
|
966
|
+
else scroller.scrollTop = top;
|
|
967
|
+
}
|
|
968
|
+
/**
|
|
969
|
+
* Records that Core scrolled `scroller` from `before` to `after`, to keep a
|
|
970
|
+
* field above the keyboard. `after` is where a smooth scroll is headed, and
|
|
971
|
+
* where the scroller is now for any other. When the keyboard goes, the
|
|
972
|
+
* scroller goes back to where it was before Core's first scroll. A scroller
|
|
973
|
+
* anyone else scrolls meanwhile keeps that scroll.
|
|
974
|
+
*/
|
|
975
|
+
function noteKeyboardScroll(scroller, before, win, after = scrollTopOf(scroller, win)) {
|
|
976
|
+
const now = after;
|
|
977
|
+
const added = addedScrolls.get(win)?.get(scroller);
|
|
978
|
+
if (added == null) {
|
|
979
|
+
if (Math.abs(now - before) >= .5) (addedScrolls.get(win) ?? watchKeyboardGo(win)).set(scroller, {
|
|
980
|
+
from: before,
|
|
981
|
+
at: now,
|
|
982
|
+
isBack: false
|
|
983
|
+
});
|
|
984
|
+
} else if (added.at != null && Math.abs(before - added.at) <= 1) added.at = now;
|
|
985
|
+
else added.at = null;
|
|
986
|
+
}
|
|
987
|
+
/**
|
|
988
|
+
* Where Core's own scroll of `scroller` is headed, while the scroller lies on
|
|
989
|
+
* its way there, as during a smooth rise. Null for a scroller Core did not
|
|
990
|
+
* scroll, or one moved off that way.
|
|
991
|
+
*/
|
|
992
|
+
function keyboardScrollTarget(scroller, win) {
|
|
993
|
+
const added = addedScrolls.get(win)?.get(scroller);
|
|
994
|
+
if (added?.at == null) return null;
|
|
995
|
+
const now = scrollTopOf(scroller, win);
|
|
996
|
+
const low = Math.min(added.from, added.at) - 1;
|
|
997
|
+
const high = Math.max(added.from, added.at) + 1;
|
|
998
|
+
return now >= low && now <= high ? added.at : null;
|
|
999
|
+
}
|
|
1000
|
+
function watchKeyboardGo(win) {
|
|
1001
|
+
const scrolls = /* @__PURE__ */ new Map();
|
|
1002
|
+
const stopReports = subscribeKeyboardHeight(win, (event) => {
|
|
1003
|
+
if (event.type === "viewport" && event.height <= 1) {
|
|
1004
|
+
end();
|
|
1005
|
+
scrollBack(win, scrolls);
|
|
1006
|
+
}
|
|
1007
|
+
});
|
|
1008
|
+
let settle = null;
|
|
1009
|
+
const stopBlurs = isIosWebKit(win.document.defaultView) ? watchBlurs() : [];
|
|
1010
|
+
function watchBlurs() {
|
|
1011
|
+
return [
|
|
1012
|
+
subscribeInput(win, "touchstart", () => {}),
|
|
1013
|
+
subscribeInput(win, "touchend", () => {}),
|
|
1014
|
+
subscribeInput(win, "touchcancel", () => {}),
|
|
1015
|
+
subscribeInput(win, "focusout", () => {
|
|
1016
|
+
if (settle != null) win.clearTimeout(settle);
|
|
1017
|
+
settle = win.setTimeout(() => {
|
|
1018
|
+
settle = null;
|
|
1019
|
+
const active = win.document.activeElement;
|
|
1020
|
+
if (getTouches(win).fingers === 0 && (active == null || !bringsUpKeyboard(active) && !hidesField(active))) scrollBackAtBlur(win, scrolls);
|
|
1021
|
+
}, 0);
|
|
1022
|
+
})
|
|
1023
|
+
];
|
|
1024
|
+
}
|
|
1025
|
+
function end() {
|
|
1026
|
+
stopReports();
|
|
1027
|
+
for (const stop of stopBlurs) stop();
|
|
1028
|
+
if (settle != null) {
|
|
1029
|
+
win.clearTimeout(settle);
|
|
1030
|
+
settle = null;
|
|
1031
|
+
}
|
|
1032
|
+
addedScrolls.delete(win);
|
|
1033
|
+
stopsOf.delete(win);
|
|
1034
|
+
}
|
|
1035
|
+
addedScrolls.set(win, scrolls);
|
|
1036
|
+
stopsOf.set(win, end);
|
|
1037
|
+
return scrolls;
|
|
1038
|
+
}
|
|
1039
|
+
function scrollBackAtBlur(win, scrolls) {
|
|
1040
|
+
for (const [scroller, added] of scrolls) {
|
|
1041
|
+
if (added.at == null || reducedMotionFade(scroller) != null || Math.abs(scrollTopOf(scroller, win) - added.at) > 1) continue;
|
|
1042
|
+
added.at = added.from;
|
|
1043
|
+
added.isBack = true;
|
|
1044
|
+
scrollTopTo(scroller, added.from, "smooth", win);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
/**
|
|
1048
|
+
* Stops a scroll back that runs from the blur, where each scroller is now. A
|
|
1049
|
+
* field that gains focus during the keyboard's slide calls it before its
|
|
1050
|
+
* reveal, so the reveal goes on from there as Core's own scroll. The instant
|
|
1051
|
+
* scroll also ends a scroll back that a touch held, which Safari would run
|
|
1052
|
+
* after the field is placed.
|
|
1053
|
+
*/
|
|
1054
|
+
function stopKeyboardScrollBack(win) {
|
|
1055
|
+
for (const [scroller, added] of addedScrolls.get(win) ?? []) {
|
|
1056
|
+
if (!added.isBack) continue;
|
|
1057
|
+
const top = scrollTopOf(scroller, win);
|
|
1058
|
+
scrollTopTo(scroller, top, "instant", win);
|
|
1059
|
+
added.at = top;
|
|
1060
|
+
added.isBack = false;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
function scrollBack(win, scrolls) {
|
|
1064
|
+
for (const [scroller, { from, at, isBack }] of scrolls) {
|
|
1065
|
+
if (at == null || isBack || !scroller.isConnected) continue;
|
|
1066
|
+
const top = scrollTopOf(scroller, win);
|
|
1067
|
+
if (Math.abs(top - at) <= 1) scrollTopTo(scroller, from, scrollBackBehavior(scroller), win);
|
|
1068
|
+
else if (isRoot(scroller) && Math.abs(top - from) <= 1) awaitFoldedReveal(win, scroller, from, at);
|
|
1069
|
+
}
|
|
1070
|
+
scrolls.clear();
|
|
1071
|
+
}
|
|
1072
|
+
function scrollBackBehavior(scroller) {
|
|
1073
|
+
return reducedMotionFade(scroller) == null ? "smooth" : "instant";
|
|
1074
|
+
}
|
|
1075
|
+
const FOLD_WAIT_MS = 1e3;
|
|
1076
|
+
function awaitFoldedReveal(win, scroller, from, at) {
|
|
1077
|
+
const doc = win.document;
|
|
1078
|
+
const stopScroll = subscribeInput(win, "scroll", (event) => {
|
|
1079
|
+
if (event.target !== doc && event.target !== win) return;
|
|
1080
|
+
stop();
|
|
1081
|
+
if (Math.abs(scrollTopOf(scroller, win) - at) <= 1) scrollTopTo(scroller, from, scrollBackBehavior(scroller), win);
|
|
1082
|
+
});
|
|
1083
|
+
const stopTouch = subscribeInput(win, "touchstart", () => stop());
|
|
1084
|
+
const stopKeyboard = subscribeKeyboardHeight(win, (event) => {
|
|
1085
|
+
if (event.type === "viewport" && event.height > 1) stop();
|
|
1086
|
+
});
|
|
1087
|
+
const timer = win.setTimeout(stop, FOLD_WAIT_MS);
|
|
1088
|
+
foldWaitsOf.get(win)?.();
|
|
1089
|
+
foldWaitsOf.set(win, stop);
|
|
1090
|
+
function stop() {
|
|
1091
|
+
win.clearTimeout(timer);
|
|
1092
|
+
stopScroll();
|
|
1093
|
+
stopTouch();
|
|
1094
|
+
stopKeyboard();
|
|
1095
|
+
if (foldWaitsOf.get(win) === stop) foldWaitsOf.delete(win);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
//#endregion
|
|
1099
|
+
//#region src/keyboard/revealBand.ts
|
|
1100
|
+
/**
|
|
1101
|
+
* @file revealBand.ts
|
|
1102
|
+
* @input A box's top and bottom edges and a band's, CSS px
|
|
1103
|
+
* @output distanceIntoBand, the scroll that brings the box inside the band
|
|
1104
|
+
* @position Keyboard module, internal to core. A field's reveal and the
|
|
1105
|
+
* Tall sheet's reveal share it.
|
|
1106
|
+
*/
|
|
1107
|
+
/**
|
|
1108
|
+
* How far content must scroll so a box from `top` to `bottom` sits inside the
|
|
1109
|
+
* band from `safeTop` to `safeBottom`, CSS px. A positive distance scrolls it
|
|
1110
|
+
* up and a negative one down. It is 0 when the box fits or the band is empty. A
|
|
1111
|
+
* box taller than the band keeps its bottom edge in it.
|
|
1112
|
+
*
|
|
1113
|
+
* @example
|
|
1114
|
+
* ```
|
|
1115
|
+
* const distance = distanceIntoBand(rect.top, rect.bottom, 0, keyboardTop - 17);
|
|
1116
|
+
* ```
|
|
1117
|
+
*/
|
|
1118
|
+
function distanceIntoBand(top, bottom, safeTop, safeBottom) {
|
|
1119
|
+
if (safeBottom <= safeTop) return 0;
|
|
1120
|
+
if (bottom > safeBottom) return bottom - safeBottom;
|
|
1121
|
+
if (top < safeTop) return top - safeTop;
|
|
1122
|
+
return 0;
|
|
1123
|
+
}
|
|
1124
|
+
//#endregion
|
|
1125
|
+
//#region src/keyboard/revealPan.ts
|
|
1126
|
+
/**
|
|
1127
|
+
* @file revealPan.ts
|
|
1128
|
+
* @input The visual viewport, the document's scroll and the input stream's
|
|
1129
|
+
* touches
|
|
1130
|
+
* @output watchRevealPan, which notices the browser's own reveal pan and puts
|
|
1131
|
+
* it back, and panVisualViewportTo, the one way Core pans the visual
|
|
1132
|
+
* viewport
|
|
1133
|
+
* @position Keyboard module, internal to core. Every watch in a document
|
|
1134
|
+
* shares one touch subscription.
|
|
1135
|
+
*/
|
|
1136
|
+
const touchStartWatches = sharedWeakMap("keyboard/keyboard-height/touch-start-watches", 1);
|
|
1137
|
+
function watchTouchStarts(doc, onTouchStart) {
|
|
1138
|
+
let shared = touchStartWatches.get(doc);
|
|
1139
|
+
if (shared == null) {
|
|
1140
|
+
const view = doc.defaultView;
|
|
1141
|
+
if (view == null) return () => {};
|
|
1142
|
+
const watches = /* @__PURE__ */ new Set();
|
|
1143
|
+
const stopStarts = subscribeInput(view, "touchstart", () => {
|
|
1144
|
+
for (const watch of [...watches]) watch();
|
|
1145
|
+
});
|
|
1146
|
+
const stopEnds = subscribeInput(view, "touchend", () => {});
|
|
1147
|
+
const stopCancels = subscribeInput(view, "touchcancel", () => {});
|
|
1148
|
+
shared = {
|
|
1149
|
+
stop: () => {
|
|
1150
|
+
stopStarts();
|
|
1151
|
+
stopEnds();
|
|
1152
|
+
stopCancels();
|
|
1153
|
+
},
|
|
1154
|
+
watches
|
|
1155
|
+
};
|
|
1156
|
+
touchStartWatches.set(doc, shared);
|
|
1157
|
+
}
|
|
1158
|
+
shared.watches.add(onTouchStart);
|
|
1159
|
+
return () => {
|
|
1160
|
+
const current = touchStartWatches.get(doc);
|
|
1161
|
+
if (current == null || !current.watches.delete(onTouchStart)) return;
|
|
1162
|
+
if (current.watches.size === 0) {
|
|
1163
|
+
current.stop();
|
|
1164
|
+
touchStartWatches.delete(doc);
|
|
1165
|
+
}
|
|
1166
|
+
};
|
|
1167
|
+
}
|
|
1168
|
+
/**
|
|
1169
|
+
* Some browsers reveal a focused field themselves, after the keyboard's
|
|
1170
|
+
* report, by panning the visual viewport to it while the keyboard still
|
|
1171
|
+
* covers it. Firefox for Android pans 54 to 143 ms after the report. Chrome
|
|
1172
|
+
* on Android animates a pan of the keyboard's whole height from about 100 to
|
|
1173
|
+
* 170 ms after it. The page gets no frame until that pan ends. Such a pan
|
|
1174
|
+
* moves the visual viewport down within the
|
|
1175
|
+
* layout viewport. Since the report there is no touch, document scroll or
|
|
1176
|
+
* zoom, and a text field the caller owns has focus. In Chrome, a reveal of a
|
|
1177
|
+
* field in a fixed container also scrolls the document first. The watch reads
|
|
1178
|
+
* the behavior, never the user agent. The caller lands its field itself and
|
|
1179
|
+
* puts the pan back. Every keyboard-aware surface can use it.
|
|
1180
|
+
*
|
|
1181
|
+
* @example
|
|
1182
|
+
* ```
|
|
1183
|
+
* const watch = watchRevealPan(window, {owns: field => region.contains(field)});
|
|
1184
|
+
* // On a report that changes the height: watch.report();
|
|
1185
|
+
* // On any later report: if (watch.isRevealPan(height)) watch.putBack();
|
|
1186
|
+
* ```
|
|
1187
|
+
*/
|
|
1188
|
+
function watchRevealPan(win, { owns, onTouch, documentScrollIsReveal = false }) {
|
|
1189
|
+
const doc = win.document;
|
|
1190
|
+
let atReport = null;
|
|
1191
|
+
let touchedSinceReport = false;
|
|
1192
|
+
let isChromeReveal = null;
|
|
1193
|
+
return {
|
|
1194
|
+
report: () => {
|
|
1195
|
+
const viewport = win.visualViewport;
|
|
1196
|
+
atReport = viewport == null ? null : {
|
|
1197
|
+
x: win.scrollX,
|
|
1198
|
+
y: win.scrollY,
|
|
1199
|
+
top: viewport.offsetTop,
|
|
1200
|
+
scale: viewport.scale
|
|
1201
|
+
};
|
|
1202
|
+
touchedSinceReport = isFingerOnScreen(win);
|
|
1203
|
+
isChromeReveal = null;
|
|
1204
|
+
},
|
|
1205
|
+
isRevealPan: (height) => {
|
|
1206
|
+
const viewport = win.visualViewport;
|
|
1207
|
+
const focused = doc.activeElement;
|
|
1208
|
+
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)));
|
|
1209
|
+
},
|
|
1210
|
+
putBack: (anchor) => {
|
|
1211
|
+
isChromeReveal = null;
|
|
1212
|
+
const options = {
|
|
1213
|
+
block: "start",
|
|
1214
|
+
inline: "nearest",
|
|
1215
|
+
behavior: "instant"
|
|
1216
|
+
};
|
|
1217
|
+
if (documentScrollIsReveal && atReport != null && (win.scrollX !== atReport.x || win.scrollY !== atReport.y)) win.scrollTo({
|
|
1218
|
+
left: atReport.x,
|
|
1219
|
+
top: atReport.y,
|
|
1220
|
+
behavior: "instant"
|
|
1221
|
+
});
|
|
1222
|
+
if (anchor != null) {
|
|
1223
|
+
anchor.scrollIntoView(options);
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
panVisualViewportTo(win, atReport?.top ?? 0);
|
|
1227
|
+
},
|
|
1228
|
+
stop: watchTouchStarts(doc, () => {
|
|
1229
|
+
touchedSinceReport = true;
|
|
1230
|
+
onTouch?.();
|
|
1231
|
+
})
|
|
1232
|
+
};
|
|
1233
|
+
}
|
|
1234
|
+
const CENTRING_SLACK_PX = 2;
|
|
1235
|
+
function isCentringReveal(win, viewport, field, atReport) {
|
|
1236
|
+
const box = field.getBoundingClientRect();
|
|
1237
|
+
const centring = (box.top + box.bottom) / 2 - viewport.height / 2;
|
|
1238
|
+
const root = win.document.scrollingElement ?? win.document.documentElement;
|
|
1239
|
+
const range = root.scrollHeight - root.clientHeight;
|
|
1240
|
+
const room = layoutViewportHeight(win) - viewport.height;
|
|
1241
|
+
const scroll = Math.min(range, Math.max(0, atReport.y + centring));
|
|
1242
|
+
const pan = Math.min(room, Math.max(0, centring));
|
|
1243
|
+
return win.scrollX === atReport.x && Math.abs(win.scrollY - scroll) <= CENTRING_SLACK_PX && Math.abs(viewport.offsetTop - pan) <= CENTRING_SLACK_PX;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Pans the visual viewport so its top sits `top` CSS px down the layout
|
|
1247
|
+
* viewport, without scrolling the document. A probe fixed there is scrolled
|
|
1248
|
+
* into view. In Chrome for Android this pans the visual viewport. In Firefox
|
|
1249
|
+
* for Android it pans nothing where the page has no scroll range. The pan
|
|
1250
|
+
* reaches the room the keyboard takes, which a document scroll cannot.
|
|
1251
|
+
*
|
|
1252
|
+
* @example
|
|
1253
|
+
* ```
|
|
1254
|
+
* panVisualViewportTo(window, window.visualViewport.offsetTop + 120);
|
|
1255
|
+
* ```
|
|
1256
|
+
*/
|
|
1257
|
+
function panVisualViewportTo(win, top) {
|
|
1258
|
+
const doc = win.document;
|
|
1259
|
+
const probe = doc.createElement("div");
|
|
1260
|
+
probe.style.position = "fixed";
|
|
1261
|
+
probe.style.left = "0";
|
|
1262
|
+
probe.style.top = `${top}px`;
|
|
1263
|
+
probe.style.width = "1px";
|
|
1264
|
+
probe.style.height = "1px";
|
|
1265
|
+
probe.style.visibility = "hidden";
|
|
1266
|
+
probe.style.pointerEvents = "none";
|
|
1267
|
+
(doc.body ?? doc.documentElement).append(probe);
|
|
1268
|
+
probe.scrollIntoView({
|
|
1269
|
+
block: "start",
|
|
1270
|
+
inline: "nearest",
|
|
1271
|
+
behavior: "instant"
|
|
1272
|
+
});
|
|
1273
|
+
probe.remove();
|
|
1274
|
+
}
|
|
1275
|
+
//#endregion
|
|
1276
|
+
//#region src/keyboard/tapFocus.ts
|
|
1277
|
+
/**
|
|
1278
|
+
* @file tapFocus.ts
|
|
1279
|
+
* @input A region's touch events, the shared press slop and the click guard
|
|
1280
|
+
* @output claimTapFocus, the tap route that focuses a claimed field itself,
|
|
1281
|
+
* and focusAtPoint, which focuses without Safari's reveal and puts the
|
|
1282
|
+
* caret under the finger
|
|
1283
|
+
* @position Keyboard module, internal to core. The keyboard targets deliver
|
|
1284
|
+
* taps through it.
|
|
1285
|
+
*/
|
|
1286
|
+
/**
|
|
1287
|
+
* The tap route. `deliver` focuses a one-finger tap on `region` that `claim`
|
|
1288
|
+
* accepts, such as a field without focus, instead of the browser. The
|
|
1289
|
+
* browser's own focus would reveal the field by scrolling the document. The
|
|
1290
|
+
* route prevents the tap's default at its end. The shared click guard then
|
|
1291
|
+
* takes the mouse events Safari may still send for the tap. The browser keeps a
|
|
1292
|
+
* touch that moves past the scroll slop, and a second finger. Returns a
|
|
1293
|
+
* cleanup.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```
|
|
1297
|
+
* const stop = claimTapFocus(region, {
|
|
1298
|
+
* claim: target => editableWithoutFocus(target),
|
|
1299
|
+
* deliver: (field, x, y) => focusAtPoint(field, x, y),
|
|
1300
|
+
* });
|
|
1301
|
+
* ```
|
|
1302
|
+
*/
|
|
1303
|
+
function claimTapFocus(region, { claim, deliver }) {
|
|
1304
|
+
let start = null;
|
|
1305
|
+
const stopFollowing = () => {
|
|
1306
|
+
start = null;
|
|
1307
|
+
region.removeEventListener("touchmove", onMove);
|
|
1308
|
+
region.removeEventListener("touchend", onEnd);
|
|
1309
|
+
region.removeEventListener("touchcancel", stopFollowing);
|
|
1310
|
+
};
|
|
1311
|
+
function onMove(event) {
|
|
1312
|
+
const touch = event.touches[0];
|
|
1313
|
+
if (start == null || event.touches.length !== 1 || touch == null || Math.hypot(touch.clientX - start.x, touch.clientY - start.y) > PRESS_SLOP_PX) stopFollowing();
|
|
1314
|
+
}
|
|
1315
|
+
function onEnd(event) {
|
|
1316
|
+
const touch = event.changedTouches[0];
|
|
1317
|
+
const tap = start;
|
|
1318
|
+
stopFollowing();
|
|
1319
|
+
if (tap == null || touch == null || !event.cancelable || claim(tap.control) !== tap.control) return;
|
|
1320
|
+
event.preventDefault();
|
|
1321
|
+
deliver(tap.control, touch.clientX, touch.clientY, touch);
|
|
1322
|
+
armClickGuard(region.ownerDocument, { takesLateMouse: true });
|
|
1323
|
+
}
|
|
1324
|
+
const onStart = (event) => {
|
|
1325
|
+
if (start != null) {
|
|
1326
|
+
stopFollowing();
|
|
1327
|
+
return;
|
|
1328
|
+
}
|
|
1329
|
+
const touch = event.touches[0];
|
|
1330
|
+
const control = event.touches.length === 1 && touch != null ? claim(event.target) : null;
|
|
1331
|
+
if (control == null || touch == null) return;
|
|
1332
|
+
start = {
|
|
1333
|
+
x: touch.clientX,
|
|
1334
|
+
y: touch.clientY,
|
|
1335
|
+
control
|
|
1336
|
+
};
|
|
1337
|
+
region.addEventListener("touchmove", onMove, { passive: true });
|
|
1338
|
+
region.addEventListener("touchend", onEnd);
|
|
1339
|
+
region.addEventListener("touchcancel", stopFollowing);
|
|
1340
|
+
};
|
|
1341
|
+
region.addEventListener("touchstart", onStart, { passive: true });
|
|
1342
|
+
return () => {
|
|
1343
|
+
stopFollowing();
|
|
1344
|
+
region.removeEventListener("touchstart", onStart);
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
function isTextControl(element) {
|
|
1348
|
+
return element instanceof HTMLTextAreaElement || element instanceof HTMLInputElement;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* A text control's caret for a tap at (x, y). It is where the browser maps
|
|
1352
|
+
* the point inside the control. Where the browser maps none, it is after the
|
|
1353
|
+
* text, the convention for a focus without a point. A control with no text
|
|
1354
|
+
* selection stays as it is.
|
|
1355
|
+
*/
|
|
1356
|
+
function placeTextControlCaret(control, x, y) {
|
|
1357
|
+
if (control.selectionStart == null) return;
|
|
1358
|
+
const caret = caretAt(control.ownerDocument, x, y, []);
|
|
1359
|
+
const offset = caret != null && caret.node === control ? caret.offset : control.value.length;
|
|
1360
|
+
control.setSelectionRange(offset, offset);
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Focuses without Safari's reveal and puts the caret under the finger.
|
|
1364
|
+
* Exported for its tests.
|
|
1365
|
+
*/
|
|
1366
|
+
function focusAtPoint(editable, x, y) {
|
|
1367
|
+
editable.focus({ preventScroll: true });
|
|
1368
|
+
if (isTextControl(editable)) {
|
|
1369
|
+
placeTextControlCaret(editable, x, y);
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
const doc = editable.ownerDocument;
|
|
1373
|
+
const caret = caretAt(doc, x, y, []);
|
|
1374
|
+
if (caret != null && editable.isContentEditable && editable.contains(caret.node)) {
|
|
1375
|
+
const range = doc.createRange();
|
|
1376
|
+
range.setStart(caret.node, caret.offset);
|
|
1377
|
+
range.collapse(true);
|
|
1378
|
+
const selection = doc.getSelection();
|
|
1379
|
+
selection?.removeAllRanges();
|
|
1380
|
+
selection?.addRange(range);
|
|
1381
|
+
}
|
|
1382
|
+
}
|
|
1383
|
+
//#endregion
|
|
1384
|
+
//#region src/keyboard/keyboardReveal.ts
|
|
1385
|
+
/**
|
|
1386
|
+
* @file keyboardReveal.ts
|
|
1387
|
+
* @input The keyboard module's reports, the reveal-pan watch, the input
|
|
1388
|
+
* stream's touches and the scroll back's records
|
|
1389
|
+
* @output The reveal: a scroller brings the focused field into the band above
|
|
1390
|
+
* the keyboard (revealWithKeyboard), the pan watch (watchPans) and the tap's
|
|
1391
|
+
* delivery (deliverTap)
|
|
1392
|
+
* @position Keyboard module, internal to core. keyboardTarget.ts and
|
|
1393
|
+
* keyboardRide.ts call it.
|
|
1394
|
+
*/
|
|
1395
|
+
function scrollBy(scroller, distance, win, behavior = "instant") {
|
|
1396
|
+
const doc = scroller.ownerDocument;
|
|
1397
|
+
if (scroller === (doc.scrollingElement ?? doc.documentElement)) win.scrollBy({
|
|
1398
|
+
top: distance,
|
|
1399
|
+
behavior
|
|
1400
|
+
});
|
|
1401
|
+
else if (typeof scroller.scrollBy === "function") scroller.scrollBy({
|
|
1402
|
+
top: distance,
|
|
1403
|
+
behavior
|
|
1404
|
+
});
|
|
1405
|
+
else scroller.scrollTop += distance;
|
|
1406
|
+
}
|
|
1407
|
+
function scrollRangeOf(scroller, win) {
|
|
1408
|
+
const doc = scroller.ownerDocument;
|
|
1409
|
+
const view = scroller === (doc.scrollingElement ?? doc.documentElement) ? layoutViewportHeight(win) : scroller.clientHeight;
|
|
1410
|
+
return Math.max(0, scroller.scrollHeight - view);
|
|
1411
|
+
}
|
|
1412
|
+
function risesSmoothly(field) {
|
|
1413
|
+
return isIosWebKit(field.ownerDocument.defaultView) && reducedMotionFade(field) == null;
|
|
1414
|
+
}
|
|
1415
|
+
function bandOf(scroller, height, offset, win, shift = 0) {
|
|
1416
|
+
const doc = scroller.ownerDocument;
|
|
1417
|
+
const keyboardTop = layoutViewportHeight(win) - height;
|
|
1418
|
+
let top = 0;
|
|
1419
|
+
let bottom = height > 1 ? keyboardTop - offset : keyboardTop;
|
|
1420
|
+
if (scroller !== (doc.scrollingElement ?? doc.documentElement)) {
|
|
1421
|
+
const box = scroller.getBoundingClientRect();
|
|
1422
|
+
top = Math.max(top, box.top + shift);
|
|
1423
|
+
bottom = Math.min(bottom, box.bottom + shift);
|
|
1424
|
+
}
|
|
1425
|
+
return {
|
|
1426
|
+
top,
|
|
1427
|
+
bottom
|
|
1428
|
+
};
|
|
1429
|
+
}
|
|
1430
|
+
function revealDistance(field, scroller, height, offset, win, shift = 0) {
|
|
1431
|
+
const band = bandOf(scroller, height, offset, win, shift);
|
|
1432
|
+
const box = field.getBoundingClientRect();
|
|
1433
|
+
return distanceIntoBand(box.top + shift, box.bottom + shift, band.top, band.bottom);
|
|
1434
|
+
}
|
|
1435
|
+
function sitsInBand(field, scroller, height, offset, win, fieldShift = 0) {
|
|
1436
|
+
const band = bandOf(scroller, height, offset, win);
|
|
1437
|
+
const box = field.getBoundingClientRect();
|
|
1438
|
+
return box.top + fieldShift >= band.top - 1 && box.bottom + fieldShift <= band.bottom + 1;
|
|
1439
|
+
}
|
|
1440
|
+
function reveal(field, scroller, height, offset, win, canRise = true) {
|
|
1441
|
+
const distance = revealDistance(field, scroller, height, offset, win);
|
|
1442
|
+
if (Math.abs(distance) <= 1) return 0;
|
|
1443
|
+
const now = scrollTopOf(scroller, win);
|
|
1444
|
+
const target = Math.min(Math.max(now + distance, 0), scrollRangeOf(scroller, win));
|
|
1445
|
+
const rises = canRise && height > 1 && Math.abs(target - now - distance) <= 1 && sitsInBand(field, scroller, height, offset, win, -distance) && risesSmoothly(field);
|
|
1446
|
+
const before = keyboardScrollTarget(scroller, win) ?? now;
|
|
1447
|
+
scrollBy(scroller, distance, win, rises ? "smooth" : "instant");
|
|
1448
|
+
if (height > 1) noteKeyboardScroll(scroller, before, win, rises ? target : void 0);
|
|
1449
|
+
return rises ? target - scrollTopOf(scroller, win) : 0;
|
|
1450
|
+
}
|
|
1451
|
+
function deliverTap(control, x, y, touch) {
|
|
1452
|
+
focusAtPoint(control, x, y);
|
|
1453
|
+
const view = control.ownerDocument.defaultView;
|
|
1454
|
+
const init = {
|
|
1455
|
+
bubbles: true,
|
|
1456
|
+
cancelable: true,
|
|
1457
|
+
composed: true,
|
|
1458
|
+
detail: 1,
|
|
1459
|
+
clientX: x,
|
|
1460
|
+
clientY: y,
|
|
1461
|
+
screenX: touch.screenX,
|
|
1462
|
+
screenY: touch.screenY
|
|
1463
|
+
};
|
|
1464
|
+
const PointerClick = view?.PointerEvent;
|
|
1465
|
+
const click = typeof PointerClick === "function" ? new PointerClick("click", {
|
|
1466
|
+
...init,
|
|
1467
|
+
pointerType: "touch",
|
|
1468
|
+
isPrimary: true,
|
|
1469
|
+
pointerId: touch.identifier
|
|
1470
|
+
}) : new ((view?.MouseEvent) ?? MouseEvent)("click", init);
|
|
1471
|
+
control.dispatchEvent(click);
|
|
1472
|
+
}
|
|
1473
|
+
/**
|
|
1474
|
+
* Puts back a pan the browser makes on its own after a keyboard report. This
|
|
1475
|
+
* happens, for example, after a focus no claim saw: a script's `focus()` while
|
|
1476
|
+
* nothing has focus. The field sits in place already, so the pan only displaces
|
|
1477
|
+
* the page. A pan made at the last height goes back at the next height's
|
|
1478
|
+
* report. The caller's own pan is the new rest once reported (`expectPan`):
|
|
1479
|
+
* its report comes after the call returns.
|
|
1480
|
+
* Feed `report` each keyboard height the module reports; `owns` says whether a
|
|
1481
|
+
* focused element is one this watch keeps in place. `documentScrollIsReveal`
|
|
1482
|
+
* is watchRevealPan's option of that name.
|
|
1483
|
+
*/
|
|
1484
|
+
function watchPans(win, owns, documentScrollIsReveal = false) {
|
|
1485
|
+
const watch = watchRevealPan(win, {
|
|
1486
|
+
owns,
|
|
1487
|
+
documentScrollIsReveal
|
|
1488
|
+
});
|
|
1489
|
+
let lastHeight = getKeyboardHeight(win);
|
|
1490
|
+
let ownPanTop = null;
|
|
1491
|
+
return {
|
|
1492
|
+
report(height) {
|
|
1493
|
+
const top = win.visualViewport?.offsetTop ?? 0;
|
|
1494
|
+
if (height !== lastHeight) {
|
|
1495
|
+
if (ownPanTop == null && lastHeight > 1 && watch.isRevealPan(height)) watch.putBack();
|
|
1496
|
+
lastHeight = height;
|
|
1497
|
+
watch.report();
|
|
1498
|
+
} else if (ownPanTop != null && Math.abs(top - ownPanTop) <= 1) {
|
|
1499
|
+
ownPanTop = null;
|
|
1500
|
+
watch.report();
|
|
1501
|
+
} else if (watch.isRevealPan(height)) watch.putBack();
|
|
1502
|
+
},
|
|
1503
|
+
expectPan(top) {
|
|
1504
|
+
ownPanTop = top;
|
|
1505
|
+
},
|
|
1506
|
+
stop: () => watch.stop()
|
|
1507
|
+
};
|
|
1508
|
+
}
|
|
1509
|
+
function panIntoView(field, offset, win, pans) {
|
|
1510
|
+
const viewport = win.visualViewport;
|
|
1511
|
+
if (viewport == null) return false;
|
|
1512
|
+
const box = field.getBoundingClientRect();
|
|
1513
|
+
const need = box.bottom + offset - (viewport.offsetTop + viewport.height);
|
|
1514
|
+
if (need <= 1) return true;
|
|
1515
|
+
const room = layoutViewportHeight(win) - viewport.offsetTop - viewport.height;
|
|
1516
|
+
const pan = Math.min(need, room, box.top - viewport.offsetTop);
|
|
1517
|
+
if (pan <= 1) return false;
|
|
1518
|
+
const top = viewport.offsetTop + pan;
|
|
1519
|
+
pans.expectPan(top);
|
|
1520
|
+
panVisualViewportTo(win, top);
|
|
1521
|
+
return pan >= need - 1;
|
|
1522
|
+
}
|
|
1523
|
+
function revealWithKeyboard(region, field, scroller, offset, win, unplaced = "keep") {
|
|
1524
|
+
const doc = scroller.ownerDocument;
|
|
1525
|
+
const root = doc.scrollingElement ?? doc.documentElement;
|
|
1526
|
+
let isPlaced = true;
|
|
1527
|
+
let hasRevealed = false;
|
|
1528
|
+
let startsAtReveal = 0;
|
|
1529
|
+
const pans = watchPans(win, (focused) => focused === field() && isPlaced);
|
|
1530
|
+
const revealNow = (height) => {
|
|
1531
|
+
const focused = field();
|
|
1532
|
+
if (focused == null) return;
|
|
1533
|
+
hasRevealed = height > 1;
|
|
1534
|
+
startsAtReveal = getTouches(win).starts;
|
|
1535
|
+
const rising = reveal(focused, scroller, height, offset, win);
|
|
1536
|
+
if (unplaced === "keep") return;
|
|
1537
|
+
isPlaced = rising !== 0 || sitsInBand(focused, scroller, height, offset, win);
|
|
1538
|
+
if (isPlaced || height <= 1) return;
|
|
1539
|
+
if (unplaced === "document") {
|
|
1540
|
+
if (scroller !== root && reveal(focused, root, height, offset, win) !== 0) {
|
|
1541
|
+
isPlaced = true;
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
} else {
|
|
1545
|
+
const top = focused.getBoundingClientRect().top;
|
|
1546
|
+
const scrollY = win.scrollY;
|
|
1547
|
+
reveal(focused, root, height, offset, win, false);
|
|
1548
|
+
if (Math.abs(focused.getBoundingClientRect().top - top) <= 1) {
|
|
1549
|
+
const scrolled = win.scrollY - scrollY;
|
|
1550
|
+
if (scrolled !== 0) {
|
|
1551
|
+
const before = win.scrollY;
|
|
1552
|
+
win.scrollBy({
|
|
1553
|
+
top: -scrolled,
|
|
1554
|
+
behavior: "instant"
|
|
1555
|
+
});
|
|
1556
|
+
noteKeyboardScroll(root, before, win);
|
|
1557
|
+
}
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
isPlaced = panIntoView(focused, offset, win, pans);
|
|
1561
|
+
};
|
|
1562
|
+
let lastHeight = getKeyboardHeight(win);
|
|
1563
|
+
const isLaterPressDown = () => isFingerOnScreen(win) && getTouches(win).starts !== startsAtReveal;
|
|
1564
|
+
const stopReports = subscribeKeyboardHeight(win, (event) => {
|
|
1565
|
+
if (event.type === "viewport") {
|
|
1566
|
+
if (Math.abs(event.height - lastHeight) > 1) {
|
|
1567
|
+
lastHeight = event.height;
|
|
1568
|
+
if (!hasRevealed || !isLaterPressDown()) revealNow(event.height);
|
|
1569
|
+
}
|
|
1570
|
+
pans.report(event.height);
|
|
1571
|
+
}
|
|
1572
|
+
});
|
|
1573
|
+
const onFocusIn = () => {
|
|
1574
|
+
stopKeyboardScrollBack(win);
|
|
1575
|
+
revealNow(getKeyboardHeight(win));
|
|
1576
|
+
};
|
|
1577
|
+
region.addEventListener("focusin", onFocusIn);
|
|
1578
|
+
revealNow(getKeyboardHeight(win));
|
|
1579
|
+
return () => {
|
|
1580
|
+
stopReports();
|
|
1581
|
+
pans.stop();
|
|
1582
|
+
region.removeEventListener("focusin", onFocusIn);
|
|
1583
|
+
};
|
|
1584
|
+
}
|
|
1585
|
+
//#endregion
|
|
1586
|
+
//#region src/keyboard/rideKeyboard.ts
|
|
1587
|
+
/**
|
|
1588
|
+
* Moves `animator`'s element to `to` with the keyboard: on its curve from
|
|
1589
|
+
* `transition.start`, or at once when the keyboard jumps.
|
|
1590
|
+
*
|
|
1591
|
+
* Android's keyboard moves on Gboard's slides up and down
|
|
1592
|
+
* (motion/android/keyboard.ts). The transition publishes the slide
|
|
1593
|
+
* (`curve`), and the ride plays it. Every ride starts at the transition's
|
|
1594
|
+
* start, so content that joins a slide late lands where the keyboard is. A
|
|
1595
|
+
* transition that is not animated lands at once, such as a keyboard changing
|
|
1596
|
+
* while up. So does a slide that has ended by the call. These values are the
|
|
1597
|
+
* keyboard's own motion, with no motion role. The system moves the keyboard
|
|
1598
|
+
* on them whatever the page does, so any other curve would leave the element
|
|
1599
|
+
* out of step.
|
|
1600
|
+
*
|
|
1601
|
+
* @example
|
|
1602
|
+
* ```
|
|
1603
|
+
* guide.subscribe(t => rideKeyboard(dock.animator, {y: -lift(t.to)}, t));
|
|
1604
|
+
* ```
|
|
1605
|
+
*/
|
|
1606
|
+
function rideKeyboard(animator, to, transition, { entrance = false } = {}) {
|
|
1607
|
+
if (!transition.animated || transition.curve == null || performance.now() >= transition.start + transition.curve.durationMs) {
|
|
1608
|
+
animator.set(to);
|
|
1609
|
+
return null;
|
|
1610
|
+
}
|
|
1611
|
+
const options = entrance ? {
|
|
1612
|
+
at: transition.start,
|
|
1613
|
+
crossfadeAs: "entrance"
|
|
1614
|
+
} : { at: transition.start };
|
|
1615
|
+
const span = transition.curve.durationMs / 1e3;
|
|
1616
|
+
const ease = cubicBezier(transition.curve.points);
|
|
1617
|
+
const curves = {};
|
|
1618
|
+
for (const [property, target] of Object.entries(to)) {
|
|
1619
|
+
const from = animator.get(property, transition.start);
|
|
1620
|
+
const at = (t) => from + (target - from) * ease(Math.min(1, Math.max(0, t / span)));
|
|
1621
|
+
curves[property] = {
|
|
1622
|
+
duration: span,
|
|
1623
|
+
at,
|
|
1624
|
+
velocity: (t) => {
|
|
1625
|
+
if (t >= span) return 0;
|
|
1626
|
+
const a = Math.max(0, t - .001);
|
|
1627
|
+
const b = Math.min(span, t + .001);
|
|
1628
|
+
return (at(b) - at(a)) / (b - a);
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
return animator.play(curves, options);
|
|
1633
|
+
}
|
|
1634
|
+
//#endregion
|
|
1635
|
+
export { riddenAnimators as A, hasOwnTranslate as C, nearestFixedAncestor as D, isMovedByApp as E, subscribeKeyboardHeight as F, layoutViewportHeight as I, getKeyboardHeight as M, isKeyboardMeasurable as N, registerKeyboardTarget as O, isTextEntryControl as P, followsKeyboard as S, isInsideKeyboardTarget as T, refuseFocusReveal as _, revealWithKeyboard as a, fixedContainerOf as b, claimTapFocus as c, claimKeyboardScrollBack as d, stopKeyboardScrollBack as f, keyboardProfileOf as g, hidesField as h, revealDistance as i, findTextEntryControl as j, restingBottom as k, watchRevealPan as l, getKeyboardLayoutGuide as m, bandOf as n, scrollBy as o, bringsUpKeyboard as p, deliverTap as r, watchPans as s, rideKeyboard as t, distanceIntoBand as u, coveredBy as v, isDockedContainer as w, focusedFieldIn as x, drawnOffsetOf as y };
|