@mrpelz/uikit-ish 7.8.0 → 7.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/accordion/main.d.ts +12 -0
- package/dist/components/accordion/main.d.ts.map +1 -0
- package/dist/components/accordion/main.js +20 -0
- package/dist/components/accordion/main.js.map +1 -0
- package/dist/components/accordion/style.css +23 -0
- package/dist/components/action-sheet/main.d.ts +22 -16
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +89 -19
- package/dist/components/action-sheet/main.js.map +1 -1
- package/dist/components/action-sheet/props.d.ts +17 -5
- package/dist/components/action-sheet/props.d.ts.map +1 -1
- package/dist/components/action-sheet/style.css +24 -0
- package/dist/components/activity-view/main.d.ts +15 -4
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +27 -14
- package/dist/components/activity-view/main.js.map +1 -1
- package/dist/components/activity-view/props.d.ts +2 -10
- package/dist/components/activity-view/props.d.ts.map +1 -1
- package/dist/components/activity-view/style.css +29 -67
- package/dist/components/alert/main.d.ts +8 -7
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +32 -19
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +13 -2
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +36 -50
- package/dist/components/avatar/main.d.ts +5 -3
- package/dist/components/avatar/main.d.ts.map +1 -1
- package/dist/components/avatar/main.js +10 -8
- package/dist/components/avatar/main.js.map +1 -1
- package/dist/components/avatar/props.d.ts +4 -0
- package/dist/components/avatar/props.d.ts.map +1 -1
- package/dist/components/avatar/style.css +1 -7
- package/dist/components/badge/main.d.ts +3 -3
- package/dist/components/badge/main.d.ts.map +1 -1
- package/dist/components/badge/main.js +9 -9
- package/dist/components/badge/main.js.map +1 -1
- package/dist/components/badge/props.d.ts +4 -3
- package/dist/components/badge/props.d.ts.map +1 -1
- package/dist/components/badge/style.css +10 -4
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +15 -15
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/props.d.ts +8 -8
- package/dist/components/button/props.d.ts.map +1 -1
- package/dist/components/button/style.css +37 -55
- package/dist/components/checkbox/main.d.ts.map +1 -1
- package/dist/components/checkbox/main.js +5 -7
- package/dist/components/checkbox/main.js.map +1 -1
- package/dist/components/checkbox/style.css +5 -8
- package/dist/components/collapsible/main.d.ts +9 -0
- package/dist/components/collapsible/main.d.ts.map +1 -0
- package/dist/components/collapsible/main.js +19 -0
- package/dist/components/collapsible/main.js.map +1 -0
- package/dist/components/collapsible/style.css +23 -0
- package/dist/components/color-picker/main.d.ts +27 -4
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +292 -110
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +64 -15
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +133 -65
- package/dist/components/contextual-menu/main.d.ts +11 -7
- package/dist/components/contextual-menu/main.d.ts.map +1 -1
- package/dist/components/contextual-menu/main.js +207 -202
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +21 -34
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +63 -34
- package/dist/components/date-picker/handle.d.ts +41 -0
- package/dist/components/date-picker/handle.d.ts.map +1 -0
- package/dist/components/date-picker/handle.js +47 -0
- package/dist/components/date-picker/handle.js.map +1 -0
- package/dist/components/date-picker/main.d.ts +31 -49
- package/dist/components/date-picker/main.d.ts.map +1 -1
- package/dist/components/date-picker/main.js +373 -178
- package/dist/components/date-picker/main.js.map +1 -1
- package/dist/components/date-picker/pager.d.ts +24 -0
- package/dist/components/date-picker/pager.d.ts.map +1 -0
- package/dist/components/date-picker/pager.js +307 -0
- package/dist/components/date-picker/pager.js.map +1 -0
- package/dist/components/date-picker/props.d.ts +98 -27
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +110 -118
- package/dist/components/drawer/main.d.ts +31 -0
- package/dist/components/drawer/main.d.ts.map +1 -0
- package/dist/components/drawer/main.js +119 -0
- package/dist/components/drawer/main.js.map +1 -0
- package/dist/components/drawer/props.d.ts +39 -0
- package/dist/components/drawer/props.d.ts.map +1 -0
- package/dist/components/drawer/props.js +2 -0
- package/dist/components/drawer/props.js.map +1 -0
- package/dist/components/drawer/style.css +135 -0
- package/dist/components/edit-menu/main.d.ts +7 -7
- package/dist/components/edit-menu/main.d.ts.map +1 -1
- package/dist/components/edit-menu/main.js +57 -40
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +14 -1
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +15 -8
- package/dist/components/form/main.d.ts +8 -0
- package/dist/components/form/main.d.ts.map +1 -1
- package/dist/components/form/main.js +18 -5
- package/dist/components/form/main.js.map +1 -1
- package/dist/components/form/props.d.ts +1 -2
- package/dist/components/form/props.d.ts.map +1 -1
- package/dist/components/glass/main.d.ts +1 -1
- package/dist/components/glass/main.js +4 -4
- package/dist/components/glass/main.js.map +1 -1
- package/dist/components/glass/props.d.ts +5 -5
- package/dist/components/glass/props.d.ts.map +1 -1
- package/dist/components/glass/style.css +176 -161
- package/dist/components/header/main.d.ts +5 -4
- package/dist/components/header/main.d.ts.map +1 -1
- package/dist/components/header/main.js +64 -34
- package/dist/components/header/main.js.map +1 -1
- package/dist/components/header/props.d.ts +2 -3
- package/dist/components/header/props.d.ts.map +1 -1
- package/dist/components/header/style.css +46 -65
- package/dist/components/index.d.ts +27 -23
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +17 -13
- package/dist/components/index.js.map +1 -1
- package/dist/components/layout/main.d.ts +2 -2
- package/dist/components/layout/main.d.ts.map +1 -1
- package/dist/components/layout/main.js +63 -167
- package/dist/components/layout/main.js.map +1 -1
- package/dist/components/layout/props.d.ts +2 -20
- package/dist/components/layout/props.d.ts.map +1 -1
- package/dist/components/layout/style.css +20 -91
- package/dist/components/list/main.d.ts +58 -10
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +1022 -465
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +211 -21
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/reorder.d.ts +146 -0
- package/dist/components/list/reorder.d.ts.map +1 -0
- package/dist/components/list/reorder.js +819 -0
- package/dist/components/list/reorder.js.map +1 -0
- package/dist/components/list/select.d.ts +6 -0
- package/dist/components/list/select.d.ts.map +1 -0
- package/dist/components/list/select.js +141 -0
- package/dist/components/list/select.js.map +1 -0
- package/dist/components/list/style.css +492 -507
- package/dist/components/list/swipe-actions-handle.d.ts +40 -0
- package/dist/components/list/swipe-actions-handle.d.ts.map +1 -0
- package/dist/components/list/swipe-actions-handle.js +51 -0
- package/dist/components/list/swipe-actions-handle.js.map +1 -0
- package/dist/components/menu/main.d.ts +102 -32
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +510 -99
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +5 -5
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +35 -43
- package/dist/components/navigation/main.d.ts +14 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +437 -119
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +53 -3
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +56 -9
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +13 -8
- package/dist/components/page/main.js.map +1 -1
- package/dist/components/page/props.d.ts +8 -0
- package/dist/components/page/props.d.ts.map +1 -1
- package/dist/components/page/style.css +39 -4
- package/dist/components/page-control/main.d.ts +2 -2
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +66 -32
- package/dist/components/page-control/main.js.map +1 -1
- package/dist/components/page-control/props.d.ts +10 -2
- package/dist/components/page-control/props.d.ts.map +1 -1
- package/dist/components/page-control/style.css +7 -2
- package/dist/components/popover/main.d.ts +11 -6
- package/dist/components/popover/main.d.ts.map +1 -1
- package/dist/components/popover/main.js +63 -38
- package/dist/components/popover/main.js.map +1 -1
- package/dist/components/popover/props.d.ts +7 -6
- package/dist/components/popover/props.d.ts.map +1 -1
- package/dist/components/popover/style.css +54 -4
- package/dist/components/progress/main.d.ts +2 -3
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +148 -29
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +43 -9
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +82 -50
- package/dist/components/roll/main.d.ts +1 -1
- package/dist/components/roll/main.d.ts.map +1 -1
- package/dist/components/roll/main.js +90 -34
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +25 -8
- package/dist/components/roll/props.d.ts.map +1 -1
- package/dist/components/roll/style.css +12 -24
- package/dist/components/segmented/main.d.ts.map +1 -1
- package/dist/components/segmented/main.js +47 -30
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/style.css +16 -23
- package/dist/components/sheet/main.d.ts +25 -15
- package/dist/components/sheet/main.d.ts.map +1 -1
- package/dist/components/sheet/main.js +66 -78
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +37 -3
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +183 -45
- package/dist/components/sidebar/main.d.ts.map +1 -1
- package/dist/components/sidebar/main.js +9 -13
- package/dist/components/sidebar/main.js.map +1 -1
- package/dist/components/sidebar/style.css +20 -14
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +23 -22
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/props.d.ts +1 -2
- package/dist/components/slider/props.d.ts.map +1 -1
- package/dist/components/slider/style.css +27 -53
- package/dist/components/stepper/main.d.ts +4 -6
- package/dist/components/stepper/main.d.ts.map +1 -1
- package/dist/components/stepper/main.js +29 -25
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +12 -16
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +40 -28
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +7 -5
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +40 -17
- package/dist/components/symbol/main.d.ts +2 -2
- package/dist/components/symbol/main.d.ts.map +1 -1
- package/dist/components/symbol/main.js +36 -28
- package/dist/components/symbol/main.js.map +1 -1
- package/dist/components/symbol/props.d.ts +39 -4
- package/dist/components/symbol/props.d.ts.map +1 -1
- package/dist/components/symbol/style.css +26 -5
- package/dist/components/tab-bar/main.d.ts +2 -2
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +133 -101
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +6 -6
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +113 -99
- package/dist/components/text-field/main.d.ts +3 -2
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +29 -30
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +23 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +122 -82
- package/dist/components/toolbar/main.js +27 -27
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/props.d.ts +10 -4
- package/dist/components/toolbar/props.d.ts.map +1 -1
- package/dist/components/toolbar/style.css +39 -33
- package/dist/components/tooltip/main.d.ts +10 -9
- package/dist/components/tooltip/main.d.ts.map +1 -1
- package/dist/components/tooltip/main.js +39 -10
- package/dist/components/tooltip/main.js.map +1 -1
- package/dist/components/tooltip/props.d.ts +2 -0
- package/dist/components/tooltip/props.d.ts.map +1 -1
- package/dist/components/tooltip/style.css +16 -16
- package/dist/components/typography/main.d.ts +2 -2
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +24 -16
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +11 -18
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +503 -623
- package/dist/components/utils/main.d.ts +78 -8
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +235 -16
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +27 -4
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +31 -18
- package/dist/components/viewport/edge-effect.d.ts +10 -0
- package/dist/components/viewport/edge-effect.d.ts.map +1 -0
- package/dist/components/viewport/edge-effect.js +100 -0
- package/dist/components/viewport/edge-effect.js.map +1 -0
- package/dist/components/viewport/edge.d.ts +39 -0
- package/dist/components/viewport/edge.d.ts.map +1 -0
- package/dist/components/viewport/edge.js +151 -0
- package/dist/components/viewport/edge.js.map +1 -0
- package/dist/components/viewport/input.d.ts +39 -0
- package/dist/components/viewport/input.d.ts.map +1 -0
- package/dist/components/viewport/input.js +280 -0
- package/dist/components/viewport/input.js.map +1 -0
- package/dist/components/viewport/main.d.ts +47 -9
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +745 -86
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +78 -0
- package/dist/components/viewport/padding.d.ts.map +1 -0
- package/dist/components/viewport/padding.js +321 -0
- package/dist/components/viewport/padding.js.map +1 -0
- package/dist/components/viewport/props.d.ts +220 -11
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +377 -6
- package/dist/main.d.ts +0 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js.map +1 -1
- package/dist/styles.css +318 -302
- package/dist/styles.d.ts +2 -1
- package/dist/styles.d.ts.map +1 -1
- package/dist/styles.js +2 -1
- package/dist/styles.js.map +1 -1
- package/package.json +8 -16
|
@@ -1,37 +1,61 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import './style.css';
|
|
3
|
-
import { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// down.
|
|
16
|
-
// - Anchors (`Anchor`; `Top`, `Bottom`): floating above the content at an
|
|
17
|
-
// edge of the visual viewport: top (e.g. a toolbar), bottom (e.g. a tab
|
|
18
|
-
// bar, or a message field pushed up by the keyboard), leading or trailing
|
|
19
|
-
// (e.g. a compact sidebar swiping in).
|
|
20
|
-
// - The content layer (`Content`): the viewport's scroll container,
|
|
21
|
-
// resized by the keyboard (or overlaid).
|
|
22
|
-
// - Anchors and content keep the safe area insets clear (as padding): all,
|
|
23
|
-
// by dimension (block, inline), or none.
|
|
3
|
+
import { createContext, forwardRef, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, } from 'react';
|
|
4
|
+
import { WheelGestures } from 'wheel-gestures';
|
|
5
|
+
import { cn, useForwardedRef, usePortalContainer, withStyle, } from '../utils/main.js';
|
|
6
|
+
import { registerScroller, scrollerUnder, subscribeScrollers, useScrollerRegistration, } from './edge.js';
|
|
7
|
+
import { EdgeEffects } from './edge-effect.js';
|
|
8
|
+
import { createAnchorHandle, Padding, useAnchorRegistration, useAnchorSize, useOverscrollRoom, } from './padding.js';
|
|
9
|
+
export { preventFocusShift, preventInputZoom, preventTextActions, useFocusShiftPrevention, useInputZoomPrevention, useTextActionsPrevention, } from './input.js';
|
|
10
|
+
export { useScrollerRegistration, useViewportEdgeElement } from './edge.js';
|
|
11
|
+
export { EdgeEffects } from './edge-effect.js';
|
|
12
|
+
export { useAnchorSize, useCreateViewportAnchorHandle, ViewportAnchorHandle, ViewportScopeContext, } from './padding.js';
|
|
13
|
+
/** Nothing to tell (no provider tracking, see `createScrollStore`). */
|
|
14
|
+
const noRefresh = () => undefined;
|
|
24
15
|
/** The latest scroll, and its listeners. */
|
|
25
16
|
const createScrollStore = () => {
|
|
26
17
|
let latest = {
|
|
27
18
|
atBottom: false,
|
|
28
19
|
atTop: true,
|
|
29
|
-
|
|
20
|
+
isHeld: false,
|
|
21
|
+
overscroll: 0,
|
|
30
22
|
position: 0,
|
|
31
23
|
};
|
|
32
24
|
const listeners = new Set();
|
|
25
|
+
// Bouncing by itself (seen past an end, see `Provider`).
|
|
26
|
+
let isNative = false;
|
|
27
|
+
// Otherwise moved along as it's pulled (not the document's, see
|
|
28
|
+
// `Provider`), while an overscroll area holds it (see `Overscroll`):
|
|
29
|
+
// without one, nothing's moved (the browser's own scrolling untouched).
|
|
30
|
+
let isMoved = false;
|
|
31
|
+
let holds = 0;
|
|
32
|
+
// The provider's, told as holds come and go (see `Provider`).
|
|
33
|
+
let refresh = noRefresh;
|
|
33
34
|
return {
|
|
34
35
|
current: () => latest,
|
|
36
|
+
hold: () => {
|
|
37
|
+
holds += 1;
|
|
38
|
+
refresh();
|
|
39
|
+
let isHeld = true;
|
|
40
|
+
return () => {
|
|
41
|
+
if (!isHeld)
|
|
42
|
+
return;
|
|
43
|
+
isHeld = false;
|
|
44
|
+
holds -= 1;
|
|
45
|
+
refresh();
|
|
46
|
+
};
|
|
47
|
+
},
|
|
48
|
+
isMoved: () => isMoved && !isNative && holds > 0,
|
|
49
|
+
isNative: () => isNative,
|
|
50
|
+
setMoved: (value) => {
|
|
51
|
+
isMoved = value;
|
|
52
|
+
},
|
|
53
|
+
setRefresh: (listener) => {
|
|
54
|
+
refresh = listener;
|
|
55
|
+
},
|
|
56
|
+
setNative: () => {
|
|
57
|
+
isNative = true;
|
|
58
|
+
},
|
|
35
59
|
emit: (event) => {
|
|
36
60
|
latest = event;
|
|
37
61
|
for (const listener of listeners)
|
|
@@ -46,152 +70,787 @@ const createScrollStore = () => {
|
|
|
46
70
|
};
|
|
47
71
|
};
|
|
48
72
|
const ViewportContext = createContext(undefined);
|
|
49
|
-
|
|
73
|
+
/**
|
|
74
|
+
* The direction scrolled in, of the scrolls given it (from `start`): it
|
|
75
|
+
* changes once scrolled `threshold` px the other way from where it last
|
|
76
|
+
* turned.
|
|
77
|
+
*/
|
|
78
|
+
const trackDirection = (threshold, start) => {
|
|
79
|
+
let turn = start;
|
|
80
|
+
let direction;
|
|
81
|
+
return (scroll) => {
|
|
82
|
+
const { position } = scroll;
|
|
83
|
+
const isOn = direction === 'down' ? position > turn : position < turn;
|
|
84
|
+
if (direction !== undefined && isOn) {
|
|
85
|
+
turn = position;
|
|
86
|
+
}
|
|
87
|
+
else if (Math.abs(position - turn) >= threshold) {
|
|
88
|
+
direction = position > turn ? 'down' : 'up';
|
|
89
|
+
turn = position;
|
|
90
|
+
}
|
|
91
|
+
return { ...scroll, direction };
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
// A wheel pulling (see `Provider`): held until quiet for this long (its
|
|
95
|
+
// gesture's own end, adapting to its events' pace, comes as soon as a
|
|
96
|
+
// finger pauses).
|
|
97
|
+
const wheelQuiet = 150;
|
|
98
|
+
// A fling's start, told apart as inertia after a few deltas (see
|
|
99
|
+
// `Provider`): its first delta at least this much of the largest (uneven,
|
|
100
|
+
// e.g. interpolated, its largest isn't always its first).
|
|
101
|
+
const flingStart = 0.75;
|
|
102
|
+
/**
|
|
103
|
+
* Rubber-banding: how far content moves pulled `distance` px past
|
|
104
|
+
* an end, in a scroll container `size` px high (never as far as that).
|
|
105
|
+
*/
|
|
106
|
+
const rubberBand = (distance, size) => size > 0 ? (1 - 1 / ((distance * 0.55) / size + 1)) * size : 0;
|
|
107
|
+
/**
|
|
108
|
+
* A wheel's rubber-banding (a trackpad's, a wheel's): stiffer, reaching half
|
|
109
|
+
* as far (wheel deltas aren't a finger's distance on the screen, and
|
|
110
|
+
* inertia is told apart only after a few of them, see `Provider`).
|
|
111
|
+
*/
|
|
112
|
+
const wheelRubberBand = (distance, size) => size > 0 ? (1 - 1 / ((distance * 0.4) / (size / 2) + 1)) * (size / 2) : 0;
|
|
113
|
+
// Released, the pull bounces back this long (ms; see `Provider`).
|
|
114
|
+
const bounceDuration = 350;
|
|
115
|
+
const clamp = (value, max) => Math.round(Math.min(Math.max(value, 0), max));
|
|
116
|
+
/**
|
|
117
|
+
* The visual viewport: the window's; or, with a `screen` (the app's, when
|
|
118
|
+
* it isn't the window: e.g. a device's frame in a page), within it: what
|
|
119
|
+
* the keyboard covers of its bottom, how far its top is scrolled out of
|
|
120
|
+
* view while the keyboard shows (as the window's offset), what remains.
|
|
121
|
+
*/
|
|
122
|
+
const readVisual = (screen) => {
|
|
50
123
|
if (typeof window === 'undefined') {
|
|
51
|
-
return {
|
|
124
|
+
return {
|
|
125
|
+
height: 0,
|
|
126
|
+
isHidden: false,
|
|
127
|
+
keyboardInset: 0,
|
|
128
|
+
left: 0,
|
|
129
|
+
top: 0,
|
|
130
|
+
width: 0,
|
|
131
|
+
};
|
|
52
132
|
}
|
|
53
133
|
const { visualViewport: viewport } = window;
|
|
134
|
+
const isHidden = document.visibilityState === 'hidden';
|
|
54
135
|
const height = viewport?.height ?? window.innerHeight;
|
|
55
136
|
const top = viewport?.offsetTop ?? 0;
|
|
137
|
+
const keyboardInset = Math.max(0, Math.round(window.innerHeight - height - top));
|
|
138
|
+
if (!screen) {
|
|
139
|
+
return {
|
|
140
|
+
height,
|
|
141
|
+
isHidden,
|
|
142
|
+
keyboardInset,
|
|
143
|
+
left: viewport?.offsetLeft ?? 0,
|
|
144
|
+
top,
|
|
145
|
+
width: viewport?.width ?? window.innerWidth,
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
// Within the screen (its box in the layout viewport): without the
|
|
149
|
+
// keyboard, all of it (its own scrolling out of view is the page's).
|
|
150
|
+
const rect = screen.getBoundingClientRect();
|
|
151
|
+
const screenKeyboard = keyboardInset > 0 ? clamp(rect.bottom - (top + height), rect.height) : 0;
|
|
152
|
+
const screenTop = keyboardInset > 0 ? clamp(top - rect.top, rect.height) : 0;
|
|
56
153
|
return {
|
|
57
|
-
height,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
154
|
+
height: Math.max(0, Math.round(rect.height) - screenTop - screenKeyboard),
|
|
155
|
+
isHidden,
|
|
156
|
+
keyboardInset: screenKeyboard,
|
|
157
|
+
left: 0,
|
|
158
|
+
top: screenTop,
|
|
159
|
+
width: Math.round(rect.width),
|
|
62
160
|
};
|
|
63
161
|
};
|
|
162
|
+
/** An element, or a ref's (a portal container's, if it's one). */
|
|
163
|
+
const elementOf = (value) => {
|
|
164
|
+
const element = value && 'current' in value ? value.current : value;
|
|
165
|
+
return element instanceof HTMLElement ? element : null;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* The root's markers (see style.css): the window an app's (its layers in
|
|
169
|
+
* it, or a provider tracking it), and an iOS Home Screen app's.
|
|
170
|
+
*/
|
|
171
|
+
const windowAttribute = 'data-uikit-viewport-window';
|
|
172
|
+
const standaloneAttribute = 'data-uikit-viewport-standalone';
|
|
173
|
+
/** Holds of the window's markers (see `useWindowHold`). */
|
|
174
|
+
let windowHolds = 0;
|
|
175
|
+
/**
|
|
176
|
+
* The window held as an app's while mounted, unless in a screen (its
|
|
177
|
+
* portal container, e.g. a device's frame): the root marked (its
|
|
178
|
+
* background beneath the layers, see style.css); in an iOS Home Screen app
|
|
179
|
+
* (`navigator.standalone`; its display mode `browser` without a web app
|
|
180
|
+
* manifest), its document as tall as the screen (WebKit's layout viewport
|
|
181
|
+
* short otherwise). Unmarked with the last hold.
|
|
182
|
+
*/
|
|
183
|
+
const useWindowHold = (screen) => {
|
|
184
|
+
useLayoutEffect(() => {
|
|
185
|
+
if (elementOf(screen))
|
|
186
|
+
return undefined;
|
|
187
|
+
const root = document.documentElement;
|
|
188
|
+
if (windowHolds === 0) {
|
|
189
|
+
root.setAttribute(windowAttribute, '');
|
|
190
|
+
if (navigator.standalone === true) {
|
|
191
|
+
root.setAttribute(standaloneAttribute, '');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
windowHolds += 1;
|
|
195
|
+
return () => {
|
|
196
|
+
windowHolds -= 1;
|
|
197
|
+
if (windowHolds > 0)
|
|
198
|
+
return;
|
|
199
|
+
root.removeAttribute(windowAttribute);
|
|
200
|
+
root.removeAttribute(standaloneAttribute);
|
|
201
|
+
};
|
|
202
|
+
}, [screen]);
|
|
203
|
+
};
|
|
64
204
|
/** Provides the visual viewport and scroll tracking (see above). */
|
|
65
|
-
const Provider = ({ children,
|
|
66
|
-
|
|
205
|
+
const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
206
|
+
// Its screen: its own, or the provided portal container's (e.g. a
|
|
207
|
+
// device's frame), or none (the window's).
|
|
208
|
+
const screen = usePortalContainer(ownScreen);
|
|
209
|
+
const [visual, setVisual] = useState(() => readVisual());
|
|
67
210
|
const [scroll] = useState(createScrollStore);
|
|
68
|
-
//
|
|
211
|
+
// Tracked without a `scroller`: the page filling its screen (see
|
|
212
|
+
// edge.ts), or the document's.
|
|
213
|
+
const [filling, setFilling] = useState(undefined);
|
|
214
|
+
useLayoutEffect(() => {
|
|
215
|
+
if (scroller)
|
|
216
|
+
return undefined;
|
|
217
|
+
const element = elementOf(screen);
|
|
218
|
+
const resolve = () => {
|
|
219
|
+
const rect = element
|
|
220
|
+
? element.getBoundingClientRect()
|
|
221
|
+
: new DOMRect(0, 0, innerWidth, innerHeight);
|
|
222
|
+
setFilling(scrollerUnder(rect, element));
|
|
223
|
+
};
|
|
224
|
+
resolve();
|
|
225
|
+
const unsubscribe = subscribeScrollers(resolve);
|
|
226
|
+
// The document's, in the window: a scroller too (an app's own anchors'
|
|
227
|
+
// without pages).
|
|
228
|
+
const unregister = element || !document.scrollingElement
|
|
229
|
+
? undefined
|
|
230
|
+
: registerScroller(document.scrollingElement);
|
|
231
|
+
return () => {
|
|
232
|
+
unsubscribe();
|
|
233
|
+
unregister?.();
|
|
234
|
+
};
|
|
235
|
+
}, [screen, scroller]);
|
|
236
|
+
// Tracking the window: it's an app's.
|
|
237
|
+
useWindowHold(screen);
|
|
238
|
+
// The visual viewport (once per frame), as custom properties, too: on
|
|
239
|
+
// the root element, or its screen.
|
|
69
240
|
useLayoutEffect(() => {
|
|
70
|
-
const
|
|
241
|
+
const element = elementOf(screen);
|
|
242
|
+
const root = element ?? document.documentElement;
|
|
71
243
|
let frame = 0;
|
|
244
|
+
const apply = () => {
|
|
245
|
+
const next = readVisual(element);
|
|
246
|
+
for (const [name, value] of [
|
|
247
|
+
['height', next.height],
|
|
248
|
+
['width', next.width],
|
|
249
|
+
['top', next.top],
|
|
250
|
+
['left', next.left],
|
|
251
|
+
['keyboard-inset', next.keyboardInset],
|
|
252
|
+
]) {
|
|
253
|
+
root.style.setProperty(`--uikit-viewport-${name}`, `${value}px`);
|
|
254
|
+
}
|
|
255
|
+
setVisual((current) => Object.keys(next).every((key) => current[key] === next[key])
|
|
256
|
+
? current
|
|
257
|
+
: next);
|
|
258
|
+
};
|
|
72
259
|
const update = () => {
|
|
73
260
|
cancelAnimationFrame(frame);
|
|
74
|
-
frame = requestAnimationFrame(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
261
|
+
frame = requestAnimationFrame(apply);
|
|
262
|
+
};
|
|
263
|
+
// Hidden or shown (see `isHidden`): told at once (no frames while
|
|
264
|
+
// hidden), the rest kept as it was (e.g. the keyboard's push: its field
|
|
265
|
+
// focused again as it's shown, see `preventFocusShift`); shown, read
|
|
266
|
+
// anew once the keyboard has settled (not back after all: none).
|
|
267
|
+
let recheck;
|
|
268
|
+
const onVisibility = () => {
|
|
269
|
+
clearTimeout(recheck);
|
|
270
|
+
const isHidden = document.visibilityState === 'hidden';
|
|
271
|
+
setVisual((current) => current.isHidden === isHidden ? current : { ...current, isHidden });
|
|
272
|
+
if (isHidden) {
|
|
273
|
+
cancelAnimationFrame(frame);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
recheck = setTimeout(update, 500);
|
|
89
277
|
};
|
|
90
278
|
update();
|
|
279
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
91
280
|
const { visualViewport: viewport } = window;
|
|
92
281
|
viewport?.addEventListener('resize', update);
|
|
93
282
|
viewport?.addEventListener('scroll', update);
|
|
94
283
|
window.addEventListener('resize', update);
|
|
284
|
+
// A screen moves with its page (any scroller's).
|
|
285
|
+
if (element) {
|
|
286
|
+
addEventListener('scroll', update, { capture: true, passive: true });
|
|
287
|
+
}
|
|
95
288
|
return () => {
|
|
96
289
|
cancelAnimationFrame(frame);
|
|
290
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
291
|
+
clearTimeout(recheck);
|
|
97
292
|
viewport?.removeEventListener('resize', update);
|
|
98
293
|
viewport?.removeEventListener('scroll', update);
|
|
99
294
|
window.removeEventListener('resize', update);
|
|
295
|
+
if (!element)
|
|
296
|
+
return;
|
|
297
|
+
removeEventListener('scroll', update, { capture: true });
|
|
298
|
+
for (const name of ['height', 'width', 'top', 'left', 'keyboard-inset']) {
|
|
299
|
+
element.style.removeProperty(`--uikit-viewport-${name}`);
|
|
300
|
+
}
|
|
100
301
|
};
|
|
101
|
-
}, []);
|
|
102
|
-
// Scroll tracking: the
|
|
103
|
-
//
|
|
302
|
+
}, [screen]);
|
|
303
|
+
// Scroll tracking: the position (within the scroll range), and how far
|
|
304
|
+
// it's overscrolled: Safari's own bounce (the position past an end), or,
|
|
305
|
+
// where browsers keep it in range, touches and wheels pulling at an end
|
|
306
|
+
// (rubber-banded, as Safari's), moving it along while an overscroll area
|
|
307
|
+
// holds it (its `--uikit-viewport-bounce`, see style.css; not the
|
|
308
|
+
// document's; without one, the browser's own scrolling untouched).
|
|
104
309
|
useEffect(() => {
|
|
105
|
-
const element = scroller?.current ?? document.scrollingElement;
|
|
310
|
+
const element = scroller?.current ?? filling ?? document.scrollingElement;
|
|
106
311
|
if (!element)
|
|
107
312
|
return undefined;
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
313
|
+
const isDocument = element === document.scrollingElement;
|
|
314
|
+
const target = isDocument ? window : element;
|
|
315
|
+
scroll.setMoved(!isDocument);
|
|
316
|
+
// Pulled past an end (px, signed as `overscroll`), from where a touch
|
|
317
|
+
// started pulling (`origin`).
|
|
318
|
+
let pull = 0;
|
|
319
|
+
let origin;
|
|
320
|
+
let isTouching = false;
|
|
321
|
+
// A wheel gesture pulling (fingers on a trackpad, a wheel turning; not
|
|
322
|
+
// its inertia), until it ends (see `onGesture`).
|
|
323
|
+
let isWheeling = false;
|
|
324
|
+
let quiet;
|
|
325
|
+
// Pulled by a wheel (see `wheelRubberBand`), not a touch.
|
|
326
|
+
let isWheelPull = false;
|
|
327
|
+
// The held gesture's deltas, and the pull before each (see `onGesture`).
|
|
328
|
+
let history = [];
|
|
329
|
+
const range = () => Math.max(0, element.scrollHeight - element.clientHeight);
|
|
330
|
+
// A pull's bounce back (see `release`), and how far it's moved along.
|
|
331
|
+
let bounce = 0;
|
|
332
|
+
let shifted = 0;
|
|
333
|
+
const emit = () => {
|
|
334
|
+
const end = range();
|
|
335
|
+
const raw = element.scrollTop;
|
|
336
|
+
const position = Math.min(Math.max(raw, 0), end);
|
|
337
|
+
if (raw !== position)
|
|
338
|
+
scroll.setNative();
|
|
339
|
+
// Moved away from the end it's pulled past (e.g. scrolled to the top
|
|
340
|
+
// as the content changes): none left.
|
|
341
|
+
if ((pull < 0 && position > 0) || (pull > 0 && position < end - 1)) {
|
|
342
|
+
cancelAnimationFrame(bounce);
|
|
343
|
+
pull = 0;
|
|
344
|
+
origin = undefined;
|
|
116
345
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
346
|
+
const overscroll = scroll.isNative()
|
|
347
|
+
? raw - position
|
|
348
|
+
: Math.sign(pull) *
|
|
349
|
+
(isWheelPull ? wheelRubberBand : rubberBand)(Math.abs(pull), element.clientHeight);
|
|
350
|
+
const by = scroll.isMoved() ? -overscroll : 0;
|
|
351
|
+
if (by !== shifted && element instanceof HTMLElement) {
|
|
352
|
+
shifted = by;
|
|
353
|
+
const { style } = element;
|
|
354
|
+
if (by === 0) {
|
|
355
|
+
style.removeProperty('--uikit-viewport-bounce');
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
style.setProperty('--uikit-viewport-bounce', `${String(by)}px`);
|
|
359
|
+
}
|
|
120
360
|
}
|
|
121
|
-
|
|
361
|
+
scroll.emit({
|
|
122
362
|
atBottom: position >= end - 1,
|
|
123
363
|
atTop: position <= 0,
|
|
124
|
-
|
|
364
|
+
isHeld: isTouching || isWheeling,
|
|
365
|
+
overscroll,
|
|
125
366
|
position,
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
// Released: bouncing back (easing out, as Safari's), unless caught
|
|
370
|
+
// again (a touch, a wheel: on from where it is).
|
|
371
|
+
const release = () => {
|
|
372
|
+
origin = undefined;
|
|
373
|
+
const from = pull;
|
|
374
|
+
let start;
|
|
375
|
+
const step = (now) => {
|
|
376
|
+
start ??= now;
|
|
377
|
+
const progress = Math.min((now - start) / bounceDuration, 1);
|
|
378
|
+
pull = progress < 1 ? from * (1 - progress) ** 3 : 0;
|
|
379
|
+
emit();
|
|
380
|
+
if (progress < 1)
|
|
381
|
+
bounce = requestAnimationFrame(step);
|
|
126
382
|
};
|
|
127
|
-
|
|
383
|
+
cancelAnimationFrame(bounce);
|
|
384
|
+
bounce = requestAnimationFrame(step);
|
|
128
385
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
386
|
+
const onTouchStart = () => {
|
|
387
|
+
cancelAnimationFrame(bounce);
|
|
388
|
+
isTouching = true;
|
|
389
|
+
isWheelPull = false;
|
|
390
|
+
origin = undefined;
|
|
391
|
+
};
|
|
392
|
+
// Pulling down at the start (or up at the end), from where it started
|
|
393
|
+
// to; back the other way, scrolling again.
|
|
394
|
+
const onTouchMove = (event) => {
|
|
395
|
+
const touch = event.touches[0];
|
|
396
|
+
if (!touch)
|
|
397
|
+
return;
|
|
398
|
+
const y = touch.clientY;
|
|
399
|
+
const raw = element.scrollTop;
|
|
400
|
+
const isAtEdge = raw <= 0 || raw >= range();
|
|
401
|
+
// (Caught bouncing back: on from its pull.)
|
|
402
|
+
origin ??= isAtEdge ? y + pull : undefined;
|
|
403
|
+
const moved = origin === undefined ? 0 : y - origin;
|
|
404
|
+
if ((raw <= 0 && moved > 0) || (raw >= range() && moved < 0)) {
|
|
405
|
+
pull = -moved;
|
|
406
|
+
}
|
|
407
|
+
else {
|
|
408
|
+
pull = 0;
|
|
409
|
+
origin = isAtEdge ? y : undefined;
|
|
410
|
+
}
|
|
411
|
+
emit();
|
|
412
|
+
};
|
|
413
|
+
const onTouchEnd = (event) => {
|
|
414
|
+
if (event.touches.length > 0)
|
|
415
|
+
return;
|
|
416
|
+
isTouching = false;
|
|
417
|
+
release();
|
|
418
|
+
};
|
|
419
|
+
// Wheel gestures (`wheel-gestures`: where they start and end, and when
|
|
420
|
+
// they're inertia, the fingers lifted, e.g. Chrome's interpolated
|
|
421
|
+
// fling): pulling on past an end (or back) while held; inertia never
|
|
422
|
+
// pulls (as no finger does), releasing at once; quiet, released (see
|
|
423
|
+
// `wheelQuiet`).
|
|
424
|
+
// Inertia is told apart only after a few of its deltas: those pulled
|
|
425
|
+
// too, so once it is, the pull goes back to where it was before the
|
|
426
|
+
// fling started (the fingers lifting: see `flingStart`), told while
|
|
427
|
+
// still held (e.g. no longer armed), then released. (Where browsers
|
|
428
|
+
// tell inertia, `WheelEvent.momentum`, e.g. Chrome, from its first.)
|
|
429
|
+
// eslint-disable-next-line new-cap -- the library's factory
|
|
430
|
+
const gestures = WheelGestures({
|
|
431
|
+
preventWheelAction: false,
|
|
432
|
+
reverseSign: false,
|
|
433
|
+
});
|
|
434
|
+
const onGesture = ({ axisDelta, event, isEnding, isMomentum, }) => {
|
|
435
|
+
if (isEnding)
|
|
436
|
+
return;
|
|
437
|
+
if (isMomentum) {
|
|
438
|
+
if (!isWheeling)
|
|
439
|
+
return;
|
|
440
|
+
clearTimeout(quiet);
|
|
441
|
+
// Told apart late (no `momentum`): back to before the fling.
|
|
442
|
+
if (typeof event.momentum !== 'boolean') {
|
|
443
|
+
const largest = Math.max(...history.map(({ delta }) => Math.abs(delta)));
|
|
444
|
+
const start = history.find(({ delta }) => Math.abs(delta) >= largest * flingStart);
|
|
445
|
+
pull = start?.pull ?? pull;
|
|
446
|
+
emit();
|
|
447
|
+
}
|
|
448
|
+
isWheeling = false;
|
|
449
|
+
history = [];
|
|
450
|
+
release();
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
cancelAnimationFrame(bounce);
|
|
454
|
+
if (!isWheeling)
|
|
455
|
+
history = [];
|
|
456
|
+
isWheeling = true;
|
|
457
|
+
clearTimeout(quiet);
|
|
458
|
+
quiet = setTimeout(() => {
|
|
459
|
+
isWheeling = false;
|
|
460
|
+
history = [];
|
|
461
|
+
release();
|
|
462
|
+
}, wheelQuiet);
|
|
463
|
+
isWheelPull = true;
|
|
464
|
+
const [, delta] = axisDelta;
|
|
465
|
+
history.push({ delta, pull });
|
|
466
|
+
const raw = element.scrollTop;
|
|
467
|
+
const isPast = (raw <= 0 && delta < 0) || (raw >= range() && delta > 0);
|
|
468
|
+
if (isPast || pull !== 0) {
|
|
469
|
+
const next = pull + delta;
|
|
470
|
+
pull = pull !== 0 && Math.sign(next) !== Math.sign(pull) ? 0 : next;
|
|
471
|
+
}
|
|
472
|
+
emit();
|
|
473
|
+
};
|
|
474
|
+
const off = gestures.on('wheel', onGesture);
|
|
475
|
+
const onWheel = (event) => gestures.feedWheel(event);
|
|
476
|
+
const listeners = [
|
|
477
|
+
['scroll', emit],
|
|
478
|
+
['touchstart', onTouchStart],
|
|
479
|
+
['touchmove', onTouchMove],
|
|
480
|
+
['touchend', onTouchEnd],
|
|
481
|
+
['touchcancel', onTouchEnd],
|
|
482
|
+
['wheel', onWheel],
|
|
483
|
+
];
|
|
484
|
+
for (const [type, listener] of listeners) {
|
|
485
|
+
target.addEventListener(type, listener, { passive: true });
|
|
486
|
+
}
|
|
487
|
+
// Its state at once (e.g. another page tracked, scrolled already),
|
|
488
|
+
// and again as overscroll areas come and go (moving it, or not).
|
|
489
|
+
emit();
|
|
490
|
+
scroll.setRefresh(emit);
|
|
491
|
+
return () => {
|
|
492
|
+
scroll.setRefresh(noRefresh);
|
|
493
|
+
off();
|
|
494
|
+
gestures.disconnect();
|
|
495
|
+
clearTimeout(quiet);
|
|
496
|
+
cancelAnimationFrame(bounce);
|
|
497
|
+
for (const [type, listener] of listeners) {
|
|
498
|
+
target.removeEventListener(type, listener);
|
|
499
|
+
}
|
|
500
|
+
if (element instanceof HTMLElement) {
|
|
501
|
+
element.style.removeProperty('--uikit-viewport-bounce');
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
}, [filling, scroll, scroller]);
|
|
132
505
|
const value = useMemo(() => ({ scroll, visual }), [scroll, visual]);
|
|
133
506
|
return (_jsx(ViewportContext.Provider, { value: value, children: children }));
|
|
134
507
|
};
|
|
508
|
+
// A regular width: the window's, from 768px.
|
|
509
|
+
const regularQuery = '(width >= 768px)';
|
|
510
|
+
const subscribeRegular = (onChange) => {
|
|
511
|
+
const query = matchMedia(regularQuery);
|
|
512
|
+
query.addEventListener('change', onChange);
|
|
513
|
+
return () => query.removeEventListener('change', onChange);
|
|
514
|
+
};
|
|
515
|
+
/**
|
|
516
|
+
* The window's horizontal size class (no `Provider` needed): e.g. a sheet
|
|
517
|
+
* on `compact` (a phone), a popover on `regular` (a tablet); `compact` before
|
|
518
|
+
* hydration (server rendering).
|
|
519
|
+
*/
|
|
520
|
+
export const useSizeClass = () => useSyncExternalStore(subscribeRegular, () => (matchMedia(regularQuery).matches ? 'regular' : 'compact'), () => 'compact');
|
|
135
521
|
/** The visual viewport and the keyboard's height (needs a `Provider`). */
|
|
136
522
|
export const useVisualViewport = () => {
|
|
137
523
|
const context = useContext(ViewportContext);
|
|
138
524
|
return context?.visual ?? readVisual();
|
|
139
525
|
};
|
|
140
526
|
/**
|
|
141
|
-
* Calls `listener` on every scroll of the tracked scroll container
|
|
142
|
-
* `Provider`);
|
|
527
|
+
* Calls `listener` on every scroll of the tracked scroll container, and as
|
|
528
|
+
* it's overscrolled (needs a `Provider`); the direction past its own
|
|
529
|
+
* `threshold`. It can change without resubscribing.
|
|
143
530
|
*/
|
|
144
|
-
export const useViewportScroll = (listener) => {
|
|
531
|
+
export const useViewportScroll = (listener, { threshold = 8 } = {}) => {
|
|
145
532
|
const context = useContext(ViewportContext);
|
|
146
533
|
const latest = useRef(listener);
|
|
147
534
|
useLayoutEffect(() => {
|
|
148
535
|
latest.current = listener;
|
|
149
536
|
});
|
|
150
|
-
useEffect(() =>
|
|
537
|
+
useEffect(() => {
|
|
538
|
+
if (!context)
|
|
539
|
+
return undefined;
|
|
540
|
+
const track = trackDirection(threshold, context.scroll.current().position);
|
|
541
|
+
return context.scroll.subscribe((scroll) => latest.current(track(scroll)));
|
|
542
|
+
}, [context, threshold]);
|
|
151
543
|
};
|
|
152
544
|
/**
|
|
153
|
-
* The direction the tracked scroll container is scrolled in
|
|
154
|
-
* it's at its top or bottom (re-rendering when
|
|
545
|
+
* The direction the tracked scroll container is scrolled in (past
|
|
546
|
+
* `threshold`), and whether it's at its top or bottom (re-rendering when
|
|
547
|
+
* these change).
|
|
155
548
|
*/
|
|
156
|
-
export const useScrollDirection = () => {
|
|
549
|
+
export const useScrollDirection = (options) => {
|
|
157
550
|
const context = useContext(ViewportContext);
|
|
158
551
|
const [state, setState] = useState(() => {
|
|
159
|
-
const { atBottom, atTop
|
|
552
|
+
const { atBottom, atTop } = context?.scroll.current() ?? {
|
|
160
553
|
atBottom: false,
|
|
161
554
|
atTop: true,
|
|
162
|
-
direction: undefined,
|
|
163
555
|
};
|
|
164
|
-
return { atBottom, atTop, direction };
|
|
556
|
+
return { atBottom, atTop, direction: undefined };
|
|
165
557
|
});
|
|
166
558
|
useViewportScroll(({ atBottom, atTop, direction }) => setState((current) => current.atBottom === atBottom &&
|
|
167
559
|
current.atTop === atTop &&
|
|
168
560
|
current.direction === direction
|
|
169
561
|
? current
|
|
170
|
-
: { atBottom, atTop, direction }));
|
|
562
|
+
: { atBottom, atTop, direction }), options);
|
|
171
563
|
return state;
|
|
172
564
|
};
|
|
565
|
+
/**
|
|
566
|
+
* Whether the element (`ref`'s, as first mounted) is in the visible area:
|
|
567
|
+
* the viewport, or `scroller`'s box (an `IntersectionObserver`; `false`
|
|
568
|
+
* until it reports, and on the server).
|
|
569
|
+
*/
|
|
570
|
+
export const useElementVisibility = (ref, { rootMargin = '0px', scroller, threshold = 0, } = {}) => {
|
|
571
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
572
|
+
useEffect(() => {
|
|
573
|
+
const element = ref.current;
|
|
574
|
+
if (!element)
|
|
575
|
+
return undefined;
|
|
576
|
+
const observer = new IntersectionObserver((entries) => {
|
|
577
|
+
const entry = entries.at(-1);
|
|
578
|
+
if (!entry)
|
|
579
|
+
return;
|
|
580
|
+
setIsVisible(entry.isIntersecting && entry.intersectionRatio >= threshold);
|
|
581
|
+
}, { root: scroller?.current ?? null, rootMargin, threshold });
|
|
582
|
+
observer.observe(element);
|
|
583
|
+
return () => observer.disconnect();
|
|
584
|
+
}, [ref, rootMargin, scroller, threshold]);
|
|
585
|
+
return isVisible;
|
|
586
|
+
};
|
|
587
|
+
/** The visible area's edges (client coordinates): the scroller's box, inside its borders and scroll bars, or the layout viewport's. */
|
|
588
|
+
const readArea = (scroller) => {
|
|
589
|
+
if (!scroller) {
|
|
590
|
+
const { clientHeight, clientWidth } = document.documentElement;
|
|
591
|
+
return { bottom: clientHeight, left: 0, right: clientWidth, top: 0 };
|
|
592
|
+
}
|
|
593
|
+
const box = scroller.getBoundingClientRect();
|
|
594
|
+
const left = box.left + scroller.clientLeft;
|
|
595
|
+
const top = box.top + scroller.clientTop;
|
|
596
|
+
return {
|
|
597
|
+
bottom: top + scroller.clientHeight,
|
|
598
|
+
left,
|
|
599
|
+
right: left + scroller.clientWidth,
|
|
600
|
+
top,
|
|
601
|
+
};
|
|
602
|
+
};
|
|
603
|
+
const share = (part, whole) => (whole > 0 ? part / whole : 0);
|
|
604
|
+
const readGeometry = (element, scroller) => {
|
|
605
|
+
const box = element.getBoundingClientRect();
|
|
606
|
+
const area = readArea(scroller);
|
|
607
|
+
const visibleWidth = Math.max(0, Math.min(box.right, area.right) - Math.max(box.left, area.left));
|
|
608
|
+
const visibleHeight = Math.max(0, Math.min(box.bottom, area.bottom) - Math.max(box.top, area.top));
|
|
609
|
+
return {
|
|
610
|
+
bottom: area.bottom - box.bottom,
|
|
611
|
+
height: box.height,
|
|
612
|
+
left: box.left - area.left,
|
|
613
|
+
right: area.right - box.right,
|
|
614
|
+
top: box.top - area.top,
|
|
615
|
+
visibleHeight,
|
|
616
|
+
visibleHeightRatio: share(visibleHeight, box.height),
|
|
617
|
+
visibleRatio: share(visibleWidth * visibleHeight, box.width * box.height),
|
|
618
|
+
visibleWidth,
|
|
619
|
+
visibleWidthRatio: share(visibleWidth, box.width),
|
|
620
|
+
width: box.width,
|
|
621
|
+
};
|
|
622
|
+
};
|
|
623
|
+
/**
|
|
624
|
+
* Calls `listener` with where the element (`ref`'s, as first mounted) is in
|
|
625
|
+
* the visible area (the viewport, or `scroller`'s box): its edges'
|
|
626
|
+
* distances to the area's, how much of it shows. Measured once per frame
|
|
627
|
+
* while anything scrolls or resizes, and only while it's visible (once
|
|
628
|
+
* more as it leaves), and once as it mounts; the listener can change
|
|
629
|
+
* without resubscribing (as `useViewportScroll`'s), and nothing re-renders
|
|
630
|
+
* unless it does (e.g. setting state).
|
|
631
|
+
*/
|
|
632
|
+
export const useElementGeometry = (ref, listener, { scroller } = {}) => {
|
|
633
|
+
const isVisible = useElementVisibility(ref, { scroller });
|
|
634
|
+
const latest = useRef(listener);
|
|
635
|
+
useLayoutEffect(() => {
|
|
636
|
+
latest.current = listener;
|
|
637
|
+
});
|
|
638
|
+
useEffect(() => {
|
|
639
|
+
const element = ref.current;
|
|
640
|
+
if (!element)
|
|
641
|
+
return undefined;
|
|
642
|
+
const update = () => latest.current(readGeometry(element, scroller?.current ?? null));
|
|
643
|
+
// (Visible or not: where it is now, e.g. having just left.)
|
|
644
|
+
update();
|
|
645
|
+
if (!isVisible)
|
|
646
|
+
return undefined;
|
|
647
|
+
let frame = 0;
|
|
648
|
+
const schedule = () => {
|
|
649
|
+
if (frame)
|
|
650
|
+
return;
|
|
651
|
+
frame = requestAnimationFrame(() => {
|
|
652
|
+
frame = 0;
|
|
653
|
+
update();
|
|
654
|
+
});
|
|
655
|
+
};
|
|
656
|
+
// (Scrolls of any container moving it: they don't bubble, so captured.)
|
|
657
|
+
addEventListener('scroll', schedule, { capture: true, passive: true });
|
|
658
|
+
addEventListener('resize', schedule, { passive: true });
|
|
659
|
+
const resizes = new ResizeObserver(schedule);
|
|
660
|
+
resizes.observe(element);
|
|
661
|
+
if (scroller?.current)
|
|
662
|
+
resizes.observe(scroller.current);
|
|
663
|
+
return () => {
|
|
664
|
+
cancelAnimationFrame(frame);
|
|
665
|
+
removeEventListener('scroll', schedule, { capture: true });
|
|
666
|
+
removeEventListener('resize', schedule);
|
|
667
|
+
resizes.disconnect();
|
|
668
|
+
};
|
|
669
|
+
}, [ref, scroller, isVisible]);
|
|
670
|
+
};
|
|
173
671
|
/**
|
|
174
672
|
* Floats above the content (and its scroll container) at an edge of the
|
|
175
673
|
* visual viewport (see the custom properties above): a bar at the top or
|
|
176
674
|
* bottom, a (compact) sidebar at the leading or trailing edge; its safe
|
|
177
675
|
* area insets kept clear (as padding).
|
|
178
676
|
*/
|
|
179
|
-
const Anchor = forwardRef(({ className, edge, keyboard = 'push', safeArea = 'all', ...props },
|
|
677
|
+
const Anchor = forwardRef(({ className, edge, edgeEffect = 'soft', edgeTint, handle, keyboard = 'push', safeArea = 'all', style, ...props }, forwardedRef) => {
|
|
678
|
+
const ref = useForwardedRef(forwardedRef);
|
|
679
|
+
// Its size, for the paddings making room for it (see `Padding`); its
|
|
680
|
+
// edge effect, for the scrollers drawing it (see `EdgeEffects`).
|
|
681
|
+
useAnchorRegistration(ref, edge, handle, {
|
|
682
|
+
effect: edgeEffect,
|
|
683
|
+
keyboard,
|
|
684
|
+
tint: edgeTint,
|
|
685
|
+
});
|
|
686
|
+
useWindowHold(usePortalContainer(undefined));
|
|
687
|
+
return (_jsx("div", { ref: ref, "data-edge": edge, "data-keyboard": keyboard, "data-safe-area": safeArea, style: style, ...props, className: cn('uikit-viewport-anchor', className), "data-viewport-part": "anchor" }));
|
|
688
|
+
});
|
|
689
|
+
// A content layer's `alwaysBounce`, as its attribute: on, off (none), or
|
|
690
|
+
// unset (`auto`, see style.css).
|
|
691
|
+
const bounceAttribute = (alwaysBounce) => {
|
|
692
|
+
if (alwaysBounce === undefined)
|
|
693
|
+
return 'auto';
|
|
694
|
+
return alwaysBounce ? '' : undefined;
|
|
695
|
+
};
|
|
180
696
|
/**
|
|
181
|
-
* The content layer: filling the viewport, scrolling its content (
|
|
182
|
-
*
|
|
183
|
-
* kept clear
|
|
697
|
+
* The content layer: filling the viewport, scrolling its content (a
|
|
698
|
+
* scroller, tracked by its `Provider` unless a page within it fills the
|
|
699
|
+
* screen, see edge.ts), below the anchors; its safe area insets kept clear
|
|
700
|
+
* (as padding), or not, by what it holds (`auto`, see style.css).
|
|
184
701
|
*/
|
|
185
|
-
const Content = forwardRef(({ className, keyboard = 'resize', safeArea = '
|
|
702
|
+
const Content = forwardRef(({ alwaysBounce, children, className, keyboard = 'resize', safeArea = 'auto', ...props }, forwardedRef) => {
|
|
703
|
+
const ref = useForwardedRef(forwardedRef);
|
|
704
|
+
useWindowHold(usePortalContainer(undefined));
|
|
705
|
+
useScrollerRegistration(ref);
|
|
706
|
+
return (_jsxs("div", { ref: ref, "data-always-bounce": bounceAttribute(alwaysBounce), "data-keyboard": keyboard, "data-safe-area": safeArea, ...props, className: cn('uikit-viewport-content', className), "data-viewport-part": "content", "data-viewport-scroller": "", children: [children, _jsx(EdgeEffects, { scroller: ref })] }));
|
|
707
|
+
});
|
|
708
|
+
/**
|
|
709
|
+
* What shows past an end of the tracked scroll container as it's pulled
|
|
710
|
+
* there (needs a `Provider`): e.g. a refresh indicator. A layer beneath the
|
|
711
|
+
* content layer (rendered before it), from its edge's bars (`anchor`), the
|
|
712
|
+
* content's end moving it along as it bounces (Safari's own bounce; other
|
|
713
|
+
* browsers', the scroll container moved along as it's pulled, while an
|
|
714
|
+
* overscroll area is shown: it holds that); where the
|
|
715
|
+
* content stays (the document's, there), sliding in over it. Its pull, as
|
|
716
|
+
* custom properties: `--uikit-viewport-overscroll` (px), and
|
|
717
|
+
* `--uikit-viewport-overscroll-progress` (0 to 1, of its own size; open, 1).
|
|
718
|
+
* Open, it's kept shown at rest, the padding at its edge making room for it
|
|
719
|
+
* (see `useOverscrollRoom`).
|
|
720
|
+
*/
|
|
721
|
+
const Overscroll = forwardRef(({ anchor, className, edge = 'block-start', open = false, safeArea = 'all', style, ...props }, forwardedRef) => {
|
|
722
|
+
const context = useContext(ViewportContext);
|
|
723
|
+
const ref = useForwardedRef(forwardedRef);
|
|
724
|
+
const layer = useRef(null);
|
|
725
|
+
const inset = useAnchorSize(edge, anchor);
|
|
726
|
+
const [size, setSize] = useState(0);
|
|
727
|
+
const isOpen = useRef(open);
|
|
728
|
+
const pull = useRef(0);
|
|
729
|
+
useOverscrollRoom(edge, open ? size : 0);
|
|
730
|
+
useWindowHold(usePortalContainer(undefined));
|
|
731
|
+
// The content moved along as it's pulled, while it's shown (see
|
|
732
|
+
// `Provider`).
|
|
733
|
+
useLayoutEffect(() => context?.scroll.hold(), [context]);
|
|
734
|
+
// Its pull, and how far along (of its size; open, all the way).
|
|
735
|
+
const update = useCallback(() => {
|
|
736
|
+
const { current: element } = layer;
|
|
737
|
+
if (!element)
|
|
738
|
+
return;
|
|
739
|
+
const height = ref.current?.offsetHeight ?? 0;
|
|
740
|
+
const progress = height > 0 ? Math.min(pull.current / height, 1) : 0;
|
|
741
|
+
element.style.setProperty('--uikit-viewport-overscroll', `${String(pull.current)}px`);
|
|
742
|
+
element.style.setProperty('--uikit-viewport-overscroll-progress', String(isOpen.current ? 1 : progress));
|
|
743
|
+
// Where the content stays (a document's, not bouncing): over it.
|
|
744
|
+
const scroll = context?.scroll;
|
|
745
|
+
element.toggleAttribute('data-overlay', !(scroll?.isNative() ?? false) && !(scroll?.isMoved() ?? false));
|
|
746
|
+
}, [context, ref]);
|
|
747
|
+
useLayoutEffect(() => {
|
|
748
|
+
isOpen.current = open;
|
|
749
|
+
update();
|
|
750
|
+
}, [open, update]);
|
|
751
|
+
useViewportScroll(({ overscroll }) => {
|
|
752
|
+
pull.current = Math.max(0, edge === 'block-start' ? -overscroll : overscroll);
|
|
753
|
+
update();
|
|
754
|
+
});
|
|
755
|
+
// Its size (the room made for it, open).
|
|
756
|
+
useLayoutEffect(() => {
|
|
757
|
+
const { current: element } = ref;
|
|
758
|
+
if (!element)
|
|
759
|
+
return undefined;
|
|
760
|
+
const observer = new ResizeObserver(([record]) => {
|
|
761
|
+
setSize(Math.round(record?.borderBoxSize[0]?.blockSize ?? 0));
|
|
762
|
+
});
|
|
763
|
+
observer.observe(element);
|
|
764
|
+
return () => observer.disconnect();
|
|
765
|
+
}, [ref]);
|
|
766
|
+
return (_jsx("div", { ref: layer, className: "uikit-viewport-overscroll", "data-edge": edge, "data-safe-area": safeArea, "data-viewport-part": "overscroll", style: { '--uikit-viewport-overscroll-inset': `${String(inset)}px` }, children: _jsx("div", { ref: ref, "data-open": open ? '' : undefined, style: withStyle({
|
|
767
|
+
'--uikit-viewport-overscroll-room': `${String(open ? size : 0)}px`,
|
|
768
|
+
}, style), ...props, className: cn('uikit-viewport-overscroll-area', className), "data-viewport-part": "overscroll-area" }) }));
|
|
769
|
+
});
|
|
186
770
|
/** A bar at the block start (the top; an `Anchor`). */
|
|
187
771
|
const BlockStart = forwardRef((props, ref) => (_jsx(Anchor, { ref: ref, edge: "block-start", ...props })));
|
|
188
772
|
/** A bar at the block end (the bottom), above the keyboard (an `Anchor`). */
|
|
189
773
|
const BlockEnd = forwardRef((props, ref) => (_jsx(Anchor, { ref: ref, edge: "block-end", ...props })));
|
|
774
|
+
/**
|
|
775
|
+
* What's typed into, kept above the keyboard (e.g. a field's row, with its
|
|
776
|
+
* slider): while focus is within it and the keyboard covers it, lifted
|
|
777
|
+
* (its own box moved up, its place kept) until its end is `gap` above the
|
|
778
|
+
* keyboard; back as focus leaves, or the keyboard hides. Needs a
|
|
779
|
+
* `Provider` (the keyboard's height); without one, it stays.
|
|
780
|
+
*/
|
|
781
|
+
const KeyboardAccessory = forwardRef(({ className, gap = 8, ...props }, forwardedRef) => {
|
|
782
|
+
const ref = useForwardedRef(forwardedRef);
|
|
783
|
+
const { keyboardInset } = useVisualViewport();
|
|
784
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
785
|
+
// (Its lift now: its box measured without it.)
|
|
786
|
+
const liftRef = useRef(0);
|
|
787
|
+
// Lifted by what the keyboard covers of it (the visual viewport's bottom,
|
|
788
|
+
// the window's: where the keyboard's top is, whatever the screen).
|
|
789
|
+
const update = useCallback(() => {
|
|
790
|
+
const { current: element } = ref;
|
|
791
|
+
if (!element)
|
|
792
|
+
return;
|
|
793
|
+
const { visualViewport: viewport } = window;
|
|
794
|
+
let lift = 0;
|
|
795
|
+
if (isFocused && keyboardInset > 0 && viewport) {
|
|
796
|
+
const bottom = element.getBoundingClientRect().bottom + liftRef.current;
|
|
797
|
+
const keyboardTop = viewport.offsetTop + viewport.height;
|
|
798
|
+
lift = Math.max(0, Math.round(bottom + gap - keyboardTop));
|
|
799
|
+
}
|
|
800
|
+
liftRef.current = lift;
|
|
801
|
+
element.style.setProperty('--uikit-viewport-keyboard-lift', `${String(lift)}px`);
|
|
802
|
+
element.toggleAttribute('data-lifted', lift > 0);
|
|
803
|
+
}, [gap, isFocused, keyboardInset, ref]);
|
|
804
|
+
useLayoutEffect(update, [update]);
|
|
805
|
+
// Focus within it (`focusin`, `focusout`: they bubble, unlike a `focus`
|
|
806
|
+
// listener's events, e.g. Preact's `onFocus`).
|
|
807
|
+
useEffect(() => {
|
|
808
|
+
const { current: element } = ref;
|
|
809
|
+
if (!element)
|
|
810
|
+
return undefined;
|
|
811
|
+
const onFocusIn = () => setIsFocused(true);
|
|
812
|
+
const onFocusOut = ({ relatedTarget }) => {
|
|
813
|
+
// (Focus moving within it: still.)
|
|
814
|
+
if (relatedTarget instanceof Node && element.contains(relatedTarget)) {
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
setIsFocused(false);
|
|
818
|
+
};
|
|
819
|
+
// (Focused already: e.g. a sheet's initial focus, before this.)
|
|
820
|
+
setIsFocused(element.contains(document.activeElement));
|
|
821
|
+
element.addEventListener('focusin', onFocusIn);
|
|
822
|
+
element.addEventListener('focusout', onFocusOut);
|
|
823
|
+
return () => {
|
|
824
|
+
element.removeEventListener('focusin', onFocusIn);
|
|
825
|
+
element.removeEventListener('focusout', onFocusOut);
|
|
826
|
+
};
|
|
827
|
+
}, [ref]);
|
|
828
|
+
// Moved meanwhile (scrolled, the visual viewport too): anew.
|
|
829
|
+
useEffect(() => {
|
|
830
|
+
if (!isFocused)
|
|
831
|
+
return undefined;
|
|
832
|
+
const { visualViewport: viewport } = window;
|
|
833
|
+
const options = { capture: true, passive: true };
|
|
834
|
+
addEventListener('scroll', update, options);
|
|
835
|
+
viewport?.addEventListener('resize', update);
|
|
836
|
+
viewport?.addEventListener('scroll', update);
|
|
837
|
+
return () => {
|
|
838
|
+
removeEventListener('scroll', update, options);
|
|
839
|
+
viewport?.removeEventListener('resize', update);
|
|
840
|
+
viewport?.removeEventListener('scroll', update);
|
|
841
|
+
};
|
|
842
|
+
}, [isFocused, update]);
|
|
843
|
+
return (_jsx("div", { ref: ref, ...props, className: cn('uikit-viewport-keyboard-accessory', className), "data-viewport-part": "keyboard-accessory" }));
|
|
844
|
+
});
|
|
190
845
|
export const Viewport = {
|
|
191
846
|
Provider,
|
|
192
847
|
Anchor,
|
|
193
848
|
Content,
|
|
194
849
|
BlockStart,
|
|
195
850
|
BlockEnd,
|
|
851
|
+
Overscroll,
|
|
852
|
+
Padding,
|
|
853
|
+
KeyboardAccessory,
|
|
854
|
+
createAnchorHandle,
|
|
196
855
|
};
|
|
197
856
|
//# sourceMappingURL=main.js.map
|