@mrpelz/uikit-ish 7.8.0 → 7.9.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 -15
- package/dist/components/action-sheet/main.d.ts.map +1 -1
- package/dist/components/action-sheet/main.js +86 -16
- 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 +15 -0
- package/dist/components/activity-view/main.d.ts +14 -3
- package/dist/components/activity-view/main.d.ts.map +1 -1
- package/dist/components/activity-view/main.js +19 -4
- 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 +8 -46
- package/dist/components/alert/main.d.ts +6 -4
- package/dist/components/alert/main.d.ts.map +1 -1
- package/dist/components/alert/main.js +20 -4
- package/dist/components/alert/main.js.map +1 -1
- package/dist/components/alert/props.d.ts +12 -1
- package/dist/components/alert/props.d.ts.map +1 -1
- package/dist/components/alert/style.css +13 -27
- 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 +3 -0
- 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 +0 -6
- package/dist/components/badge/main.d.ts +2 -2
- package/dist/components/badge/main.d.ts.map +1 -1
- package/dist/components/badge/main.js +5 -5
- 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 +3 -2
- package/dist/components/button/main.d.ts.map +1 -1
- package/dist/components/button/main.js +6 -6
- package/dist/components/button/main.js.map +1 -1
- package/dist/components/button/style.css +11 -27
- package/dist/components/checkbox/style.css +2 -5
- 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 +1 -1
- package/dist/components/color-picker/main.d.ts.map +1 -1
- package/dist/components/color-picker/main.js +40 -33
- package/dist/components/color-picker/main.js.map +1 -1
- package/dist/components/color-picker/props.d.ts +21 -7
- package/dist/components/color-picker/props.d.ts.map +1 -1
- package/dist/components/color-picker/style.css +9 -27
- 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 +99 -47
- package/dist/components/contextual-menu/main.js.map +1 -1
- package/dist/components/contextual-menu/props.d.ts +17 -7
- package/dist/components/contextual-menu/props.d.ts.map +1 -1
- package/dist/components/contextual-menu/style.css +11 -8
- 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 +300 -139
- 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 +93 -22
- package/dist/components/date-picker/props.d.ts.map +1 -1
- package/dist/components/date-picker/style.css +59 -71
- 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 +74 -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 +31 -23
- package/dist/components/edit-menu/main.js.map +1 -1
- package/dist/components/edit-menu/props.d.ts +13 -0
- package/dist/components/edit-menu/props.d.ts.map +1 -1
- package/dist/components/edit-menu/style.css +5 -7
- 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 +15 -2
- 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/style.css +19 -4
- 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 +56 -27
- 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 +62 -42
- package/dist/components/index.d.ts +26 -22
- 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 +59 -163
- 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 +18 -89
- package/dist/components/list/main.d.ts +49 -9
- package/dist/components/list/main.d.ts.map +1 -1
- package/dist/components/list/main.js +769 -208
- package/dist/components/list/main.js.map +1 -1
- package/dist/components/list/props.d.ts +165 -8
- package/dist/components/list/props.d.ts.map +1 -1
- package/dist/components/list/style.css +308 -371
- 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 +31 -8
- package/dist/components/menu/main.d.ts.map +1 -1
- package/dist/components/menu/main.js +175 -39
- package/dist/components/menu/main.js.map +1 -1
- package/dist/components/menu/props.d.ts +2 -1
- package/dist/components/menu/props.d.ts.map +1 -1
- package/dist/components/menu/style.css +10 -32
- package/dist/components/navigation/main.d.ts +11 -2
- package/dist/components/navigation/main.d.ts.map +1 -1
- package/dist/components/navigation/main.js +186 -98
- package/dist/components/navigation/main.js.map +1 -1
- package/dist/components/navigation/props.d.ts +20 -3
- package/dist/components/navigation/props.d.ts.map +1 -1
- package/dist/components/navigation/style.css +24 -7
- package/dist/components/page/main.d.ts.map +1 -1
- package/dist/components/page/main.js +2 -2
- 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 -1
- package/dist/components/page-control/main.d.ts +1 -1
- package/dist/components/page-control/main.d.ts.map +1 -1
- package/dist/components/page-control/main.js +59 -25
- 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 +5 -0
- 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 +53 -31
- 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 +45 -4
- package/dist/components/progress/main.d.ts +1 -1
- package/dist/components/progress/main.d.ts.map +1 -1
- package/dist/components/progress/main.js +108 -15
- package/dist/components/progress/main.js.map +1 -1
- package/dist/components/progress/props.d.ts +25 -5
- package/dist/components/progress/props.d.ts.map +1 -1
- package/dist/components/progress/style.css +67 -35
- 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 +81 -25
- package/dist/components/roll/main.js.map +1 -1
- package/dist/components/roll/props.d.ts +24 -7
- package/dist/components/roll/props.d.ts.map +1 -1
- package/dist/components/roll/style.css +1 -13
- package/dist/components/segmented/main.js +3 -3
- package/dist/components/segmented/main.js.map +1 -1
- package/dist/components/segmented/style.css +2 -14
- 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 +57 -73
- package/dist/components/sheet/main.js.map +1 -1
- package/dist/components/sheet/props.d.ts +36 -2
- package/dist/components/sheet/props.d.ts.map +1 -1
- package/dist/components/sheet/style.css +176 -44
- package/dist/components/sidebar/style.css +13 -7
- package/dist/components/slider/main.d.ts.map +1 -1
- package/dist/components/slider/main.js +6 -5
- package/dist/components/slider/main.js.map +1 -1
- package/dist/components/slider/style.css +2 -28
- 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 +17 -11
- package/dist/components/stepper/main.js.map +1 -1
- package/dist/components/stepper/style.css +4 -8
- package/dist/components/switch/main.d.ts.map +1 -1
- package/dist/components/switch/main.js +16 -11
- package/dist/components/switch/main.js.map +1 -1
- package/dist/components/switch/props.d.ts +2 -2
- package/dist/components/switch/props.d.ts.map +1 -1
- package/dist/components/switch/style.css +28 -1
- 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 +34 -27
- 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 +25 -4
- package/dist/components/tab-bar/main.d.ts.map +1 -1
- package/dist/components/tab-bar/main.js +59 -46
- package/dist/components/tab-bar/main.js.map +1 -1
- package/dist/components/tab-bar/props.d.ts +3 -3
- package/dist/components/tab-bar/props.d.ts.map +1 -1
- package/dist/components/tab-bar/style.css +24 -46
- package/dist/components/text-field/main.d.ts.map +1 -1
- package/dist/components/text-field/main.js +9 -8
- package/dist/components/text-field/main.js.map +1 -1
- package/dist/components/text-field/props.d.ts +8 -1
- package/dist/components/text-field/props.d.ts.map +1 -1
- package/dist/components/text-field/style.css +21 -55
- package/dist/components/toolbar/main.d.ts.map +1 -1
- package/dist/components/toolbar/main.js +11 -9
- package/dist/components/toolbar/main.js.map +1 -1
- package/dist/components/toolbar/style.css +28 -22
- 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 +35 -6
- 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 +11 -11
- package/dist/components/typography/main.d.ts.map +1 -1
- package/dist/components/typography/main.js +16 -6
- package/dist/components/typography/main.js.map +1 -1
- package/dist/components/typography/props.d.ts +2 -9
- package/dist/components/typography/props.d.ts.map +1 -1
- package/dist/components/typography/style.css +0 -120
- package/dist/components/utils/main.d.ts +34 -5
- package/dist/components/utils/main.d.ts.map +1 -1
- package/dist/components/utils/main.js +81 -12
- package/dist/components/utils/main.js.map +1 -1
- package/dist/components/utils/props.d.ts +4 -2
- package/dist/components/utils/props.d.ts.map +1 -1
- package/dist/components/utils/style.css +29 -16
- package/dist/components/viewport/input.d.ts +23 -0
- package/dist/components/viewport/input.d.ts.map +1 -0
- package/dist/components/viewport/input.js +95 -0
- package/dist/components/viewport/input.js.map +1 -0
- package/dist/components/viewport/main.d.ts +42 -9
- package/dist/components/viewport/main.d.ts.map +1 -1
- package/dist/components/viewport/main.js +488 -66
- package/dist/components/viewport/main.js.map +1 -1
- package/dist/components/viewport/padding.d.ts +50 -0
- package/dist/components/viewport/padding.d.ts.map +1 -0
- package/dist/components/viewport/padding.js +226 -0
- package/dist/components/viewport/padding.js.map +1 -0
- package/dist/components/viewport/props.d.ts +155 -7
- package/dist/components/viewport/props.d.ts.map +1 -1
- package/dist/components/viewport/style.css +172 -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 +35 -2
- 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 +6 -13
|
@@ -1,37 +1,35 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import './style.css';
|
|
3
|
-
import { createContext, forwardRef, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
-
import { cn } from '../utils/main.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// and the keyboard's height (what it covers of the layout viewport), as
|
|
9
|
-
// custom properties on the root element (`--uikit-viewport-height`,
|
|
10
|
-
// `-width`, `-top`, `-left`, `-keyboard-inset`) and a hook.
|
|
11
|
-
// - Scroll tracking (`Provider`, `useViewportScroll`, `useScrollDirection`):
|
|
12
|
-
// the direction a scroll container (the document's, by default) is
|
|
13
|
-
// scrolled in (past a threshold, so jitter doesn't flip it), and whether
|
|
14
|
-
// it's at its top or bottom; e.g. to collapse a tab bar while scrolling
|
|
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 { cn, useForwardedRef, usePortalContainer, withStyle, } from '../utils/main.js';
|
|
5
|
+
import { createAnchorHandle, Padding, useAnchorRegistration, useAnchorSize, useOverscrollRoom, } from './padding.js';
|
|
6
|
+
export { preventFocusShift, preventInputZoom, useFocusShiftPrevention, useInputZoomPrevention, } from './input.js';
|
|
7
|
+
export { useAnchorSize, useCreateViewportAnchorHandle, ViewportAnchorHandle, ViewportScopeContext, } from './padding.js';
|
|
24
8
|
/** The latest scroll, and its listeners. */
|
|
25
9
|
const createScrollStore = () => {
|
|
26
10
|
let latest = {
|
|
27
11
|
atBottom: false,
|
|
28
12
|
atTop: true,
|
|
29
|
-
|
|
13
|
+
isHeld: false,
|
|
14
|
+
overscroll: 0,
|
|
30
15
|
position: 0,
|
|
31
16
|
};
|
|
32
17
|
const listeners = new Set();
|
|
18
|
+
// Bouncing by itself (seen past an end, see `Provider`).
|
|
19
|
+
let isNative = false;
|
|
20
|
+
// Otherwise moved along as it's pulled (not the document's, see
|
|
21
|
+
// `Provider`).
|
|
22
|
+
let isMoved = false;
|
|
33
23
|
return {
|
|
34
24
|
current: () => latest,
|
|
25
|
+
isMoved: () => isMoved && !isNative,
|
|
26
|
+
isNative: () => isNative,
|
|
27
|
+
setMoved: (value) => {
|
|
28
|
+
isMoved = value;
|
|
29
|
+
},
|
|
30
|
+
setNative: () => {
|
|
31
|
+
isNative = true;
|
|
32
|
+
},
|
|
35
33
|
emit: (event) => {
|
|
36
34
|
latest = event;
|
|
37
35
|
for (const listener of listeners)
|
|
@@ -46,33 +44,102 @@ const createScrollStore = () => {
|
|
|
46
44
|
};
|
|
47
45
|
};
|
|
48
46
|
const ViewportContext = createContext(undefined);
|
|
49
|
-
|
|
47
|
+
/**
|
|
48
|
+
* The direction scrolled in, of the scrolls given it (from `start`): it
|
|
49
|
+
* changes once scrolled `threshold` px the other way from where it last
|
|
50
|
+
* turned.
|
|
51
|
+
*/
|
|
52
|
+
const trackDirection = (threshold, start) => {
|
|
53
|
+
let turn = start;
|
|
54
|
+
let direction;
|
|
55
|
+
return (scroll) => {
|
|
56
|
+
const { position } = scroll;
|
|
57
|
+
const isOn = direction === 'down' ? position > turn : position < turn;
|
|
58
|
+
if (direction !== undefined && isOn) {
|
|
59
|
+
turn = position;
|
|
60
|
+
}
|
|
61
|
+
else if (Math.abs(position - turn) >= threshold) {
|
|
62
|
+
direction = position > turn ? 'down' : 'up';
|
|
63
|
+
turn = position;
|
|
64
|
+
}
|
|
65
|
+
return { ...scroll, direction };
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Rubber-banding (UIKit's): how far content moves pulled `distance` px past
|
|
70
|
+
* an end, in a scroll container `size` px high (never as far as that).
|
|
71
|
+
*/
|
|
72
|
+
const rubberBand = (distance, size) => size > 0 ? (1 - 1 / ((distance * 0.55) / size + 1)) * size : 0;
|
|
73
|
+
// A wheel overscrolling (see `Provider`): held until quiet for this long.
|
|
74
|
+
const wheelQuiet = 150;
|
|
75
|
+
// A wheel coasting (fingers lifted, the browser's inertia: e.g. Chrome's
|
|
76
|
+
// fling): this many deltas in a row shrinking, each within this long (ms)
|
|
77
|
+
// of the last.
|
|
78
|
+
const wheelDecays = 4;
|
|
79
|
+
const wheelInterval = 50;
|
|
80
|
+
// Released, the pull bounces back this long (ms; see `Provider`).
|
|
81
|
+
const bounceDuration = 350;
|
|
82
|
+
// A wheel's delta, in pixels (by its `deltaMode`: pixels, lines, pages).
|
|
83
|
+
const wheelPixels = (event, page) => event.deltaY * ([1, 16, page][event.deltaMode] ?? 1);
|
|
84
|
+
const clamp = (value, max) => Math.round(Math.min(Math.max(value, 0), max));
|
|
85
|
+
/**
|
|
86
|
+
* The visual viewport: the window's; or, with a `screen` (the app's, when
|
|
87
|
+
* it isn't the window: e.g. a device's frame in a page), within it: what
|
|
88
|
+
* the keyboard covers of its bottom, how far its top is scrolled out of
|
|
89
|
+
* view while the keyboard shows (as the window's offset), what remains.
|
|
90
|
+
*/
|
|
91
|
+
const readVisual = (screen) => {
|
|
50
92
|
if (typeof window === 'undefined') {
|
|
51
93
|
return { height: 0, keyboardInset: 0, left: 0, top: 0, width: 0 };
|
|
52
94
|
}
|
|
53
95
|
const { visualViewport: viewport } = window;
|
|
54
96
|
const height = viewport?.height ?? window.innerHeight;
|
|
55
97
|
const top = viewport?.offsetTop ?? 0;
|
|
98
|
+
const keyboardInset = Math.max(0, Math.round(window.innerHeight - height - top));
|
|
99
|
+
if (!screen) {
|
|
100
|
+
return {
|
|
101
|
+
height,
|
|
102
|
+
keyboardInset,
|
|
103
|
+
left: viewport?.offsetLeft ?? 0,
|
|
104
|
+
top,
|
|
105
|
+
width: viewport?.width ?? window.innerWidth,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
// Within the screen (its box in the layout viewport): without the
|
|
109
|
+
// keyboard, all of it (its own scrolling out of view is the page's).
|
|
110
|
+
const rect = screen.getBoundingClientRect();
|
|
111
|
+
const screenKeyboard = keyboardInset > 0 ? clamp(rect.bottom - (top + height), rect.height) : 0;
|
|
112
|
+
const screenTop = keyboardInset > 0 ? clamp(top - rect.top, rect.height) : 0;
|
|
56
113
|
return {
|
|
57
|
-
height,
|
|
58
|
-
keyboardInset:
|
|
59
|
-
left:
|
|
60
|
-
top,
|
|
61
|
-
width:
|
|
114
|
+
height: Math.max(0, Math.round(rect.height) - screenTop - screenKeyboard),
|
|
115
|
+
keyboardInset: screenKeyboard,
|
|
116
|
+
left: 0,
|
|
117
|
+
top: screenTop,
|
|
118
|
+
width: Math.round(rect.width),
|
|
62
119
|
};
|
|
63
120
|
};
|
|
121
|
+
/** An element, or a ref's (a portal container's, if it's one). */
|
|
122
|
+
const elementOf = (value) => {
|
|
123
|
+
const element = value && 'current' in value ? value.current : value;
|
|
124
|
+
return element instanceof HTMLElement ? element : null;
|
|
125
|
+
};
|
|
64
126
|
/** Provides the visual viewport and scroll tracking (see above). */
|
|
65
|
-
const Provider = ({ children,
|
|
66
|
-
|
|
127
|
+
const Provider = ({ children, screen: ownScreen, scroller, }) => {
|
|
128
|
+
// Its screen: its own, or the provided portal container's (e.g. a
|
|
129
|
+
// device's frame), or none (the window's).
|
|
130
|
+
const screen = usePortalContainer(ownScreen);
|
|
131
|
+
const [visual, setVisual] = useState(() => readVisual());
|
|
67
132
|
const [scroll] = useState(createScrollStore);
|
|
68
|
-
// The visual viewport (once per frame), as custom properties, too
|
|
133
|
+
// The visual viewport (once per frame), as custom properties, too: on
|
|
134
|
+
// the root element, or its screen.
|
|
69
135
|
useLayoutEffect(() => {
|
|
70
|
-
const
|
|
136
|
+
const element = elementOf(screen);
|
|
137
|
+
const root = element ?? document.documentElement;
|
|
71
138
|
let frame = 0;
|
|
72
139
|
const update = () => {
|
|
73
140
|
cancelAnimationFrame(frame);
|
|
74
141
|
frame = requestAnimationFrame(() => {
|
|
75
|
-
const next = readVisual();
|
|
142
|
+
const next = readVisual(element);
|
|
76
143
|
for (const [name, value] of [
|
|
77
144
|
['height', next.height],
|
|
78
145
|
['width', next.width],
|
|
@@ -92,97 +159,449 @@ const Provider = ({ children, scroller, threshold = 8, }) => {
|
|
|
92
159
|
viewport?.addEventListener('resize', update);
|
|
93
160
|
viewport?.addEventListener('scroll', update);
|
|
94
161
|
window.addEventListener('resize', update);
|
|
162
|
+
// A screen moves with its page (any scroller's).
|
|
163
|
+
if (element) {
|
|
164
|
+
addEventListener('scroll', update, { capture: true, passive: true });
|
|
165
|
+
}
|
|
95
166
|
return () => {
|
|
96
167
|
cancelAnimationFrame(frame);
|
|
97
168
|
viewport?.removeEventListener('resize', update);
|
|
98
169
|
viewport?.removeEventListener('scroll', update);
|
|
99
170
|
window.removeEventListener('resize', update);
|
|
171
|
+
if (!element)
|
|
172
|
+
return;
|
|
173
|
+
removeEventListener('scroll', update, { capture: true });
|
|
174
|
+
for (const name of ['height', 'width', 'top', 'left', 'keyboard-inset']) {
|
|
175
|
+
element.style.removeProperty(`--uikit-viewport-${name}`);
|
|
176
|
+
}
|
|
100
177
|
};
|
|
101
|
-
}, []);
|
|
102
|
-
// Scroll tracking: the
|
|
103
|
-
//
|
|
178
|
+
}, [screen]);
|
|
179
|
+
// Scroll tracking: the position (within the scroll range), and how far
|
|
180
|
+
// it's overscrolled: Safari's own bounce (the position past an end), or,
|
|
181
|
+
// where browsers keep it in range, touches and wheels pulling at an end
|
|
182
|
+
// (rubber-banded, as Safari's), moving it along (its
|
|
183
|
+
// `--uikit-viewport-bounce`, see style.css; not the document's).
|
|
104
184
|
useEffect(() => {
|
|
105
185
|
const element = scroller?.current ?? document.scrollingElement;
|
|
106
186
|
if (!element)
|
|
107
187
|
return undefined;
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
188
|
+
const isDocument = element === document.scrollingElement;
|
|
189
|
+
const target = isDocument ? window : element;
|
|
190
|
+
scroll.setMoved(!isDocument);
|
|
191
|
+
// Pulled past an end (px, signed as `overscroll`), from where a touch
|
|
192
|
+
// started pulling (`origin`).
|
|
193
|
+
let pull = 0;
|
|
194
|
+
let origin;
|
|
195
|
+
let isTouching = false;
|
|
196
|
+
let wheel;
|
|
197
|
+
const range = () => Math.max(0, element.scrollHeight - element.clientHeight);
|
|
198
|
+
// A pull's bounce back (see `release`), and how far it's moved along.
|
|
199
|
+
let bounce = 0;
|
|
200
|
+
let shifted = 0;
|
|
201
|
+
const emit = () => {
|
|
202
|
+
const end = range();
|
|
203
|
+
const raw = element.scrollTop;
|
|
204
|
+
const position = Math.min(Math.max(raw, 0), end);
|
|
205
|
+
if (raw !== position)
|
|
206
|
+
scroll.setNative();
|
|
207
|
+
// Moved away from the end it's pulled past (e.g. scrolled to the top
|
|
208
|
+
// as the content changes): none left.
|
|
209
|
+
if ((pull < 0 && position > 0) || (pull > 0 && position < end - 1)) {
|
|
210
|
+
cancelAnimationFrame(bounce);
|
|
211
|
+
pull = 0;
|
|
212
|
+
origin = undefined;
|
|
116
213
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
214
|
+
const overscroll = scroll.isNative()
|
|
215
|
+
? raw - position
|
|
216
|
+
: Math.sign(pull) * rubberBand(Math.abs(pull), element.clientHeight);
|
|
217
|
+
const by = scroll.isMoved() ? -overscroll : 0;
|
|
218
|
+
if (by !== shifted && element instanceof HTMLElement) {
|
|
219
|
+
shifted = by;
|
|
220
|
+
const { style } = element;
|
|
221
|
+
if (by === 0) {
|
|
222
|
+
style.removeProperty('--uikit-viewport-bounce');
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
style.setProperty('--uikit-viewport-bounce', `${String(by)}px`);
|
|
226
|
+
}
|
|
120
227
|
}
|
|
121
|
-
|
|
228
|
+
scroll.emit({
|
|
122
229
|
atBottom: position >= end - 1,
|
|
123
230
|
atTop: position <= 0,
|
|
124
|
-
|
|
231
|
+
isHeld: isTouching || wheel !== undefined,
|
|
232
|
+
overscroll,
|
|
125
233
|
position,
|
|
234
|
+
});
|
|
235
|
+
};
|
|
236
|
+
// Released: bouncing back (easing out, as Safari's), unless caught
|
|
237
|
+
// again (a touch, a wheel: on from where it is).
|
|
238
|
+
const release = () => {
|
|
239
|
+
origin = undefined;
|
|
240
|
+
const from = pull;
|
|
241
|
+
let start;
|
|
242
|
+
const step = (now) => {
|
|
243
|
+
start ??= now;
|
|
244
|
+
const progress = Math.min((now - start) / bounceDuration, 1);
|
|
245
|
+
pull = progress < 1 ? from * (1 - progress) ** 3 : 0;
|
|
246
|
+
emit();
|
|
247
|
+
if (progress < 1)
|
|
248
|
+
bounce = requestAnimationFrame(step);
|
|
126
249
|
};
|
|
127
|
-
|
|
250
|
+
cancelAnimationFrame(bounce);
|
|
251
|
+
bounce = requestAnimationFrame(step);
|
|
128
252
|
};
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
253
|
+
const onTouchStart = () => {
|
|
254
|
+
cancelAnimationFrame(bounce);
|
|
255
|
+
isTouching = true;
|
|
256
|
+
origin = undefined;
|
|
257
|
+
};
|
|
258
|
+
// Pulling down at the start (or up at the end), from where it started
|
|
259
|
+
// to; back the other way, scrolling again.
|
|
260
|
+
const onTouchMove = (event) => {
|
|
261
|
+
const touch = event.touches[0];
|
|
262
|
+
if (!touch)
|
|
263
|
+
return;
|
|
264
|
+
const y = touch.clientY;
|
|
265
|
+
const raw = element.scrollTop;
|
|
266
|
+
const isAtEdge = raw <= 0 || raw >= range();
|
|
267
|
+
// (Caught bouncing back: on from its pull.)
|
|
268
|
+
origin ??= isAtEdge ? y + pull : undefined;
|
|
269
|
+
const moved = origin === undefined ? 0 : y - origin;
|
|
270
|
+
if ((raw <= 0 && moved > 0) || (raw >= range() && moved < 0)) {
|
|
271
|
+
pull = -moved;
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
pull = 0;
|
|
275
|
+
origin = isAtEdge ? y : undefined;
|
|
276
|
+
}
|
|
277
|
+
emit();
|
|
278
|
+
};
|
|
279
|
+
const onTouchEnd = (event) => {
|
|
280
|
+
if (event.touches.length > 0)
|
|
281
|
+
return;
|
|
282
|
+
isTouching = false;
|
|
283
|
+
release();
|
|
284
|
+
};
|
|
285
|
+
// A wheel's last delta and when, and how many shrank in a row; coasting
|
|
286
|
+
// (see `wheelDecays`) until it turns or goes quiet (not as a delta grows:
|
|
287
|
+
// an interpolated inertia's, e.g. Chrome's, uneven, would pull again,
|
|
288
|
+
// e.g. turning a second page).
|
|
289
|
+
let last = { delta: 0, time: 0 };
|
|
290
|
+
let decays = 0;
|
|
291
|
+
let isCoasting = false;
|
|
292
|
+
// Coasting: released at once (inertia doesn't pull on, as no finger
|
|
293
|
+
// does), none of it pulling again.
|
|
294
|
+
const coast = (event, delta) => {
|
|
295
|
+
const isTurned = Math.sign(delta) !== Math.sign(last.delta);
|
|
296
|
+
const isQuiet = event.timeStamp - last.time > wheelQuiet;
|
|
297
|
+
const isShrinking = Math.abs(delta) < Math.abs(last.delta);
|
|
298
|
+
decays =
|
|
299
|
+
isShrinking && event.timeStamp - last.time < wheelInterval
|
|
300
|
+
? decays + 1
|
|
301
|
+
: 0;
|
|
302
|
+
if (isTurned || isQuiet)
|
|
303
|
+
isCoasting = false;
|
|
304
|
+
if (decays >= wheelDecays)
|
|
305
|
+
isCoasting = true;
|
|
306
|
+
last = { delta, time: event.timeStamp };
|
|
307
|
+
if (!isCoasting)
|
|
308
|
+
return false;
|
|
309
|
+
if (wheel !== undefined) {
|
|
310
|
+
clearTimeout(wheel);
|
|
311
|
+
wheel = undefined;
|
|
312
|
+
release();
|
|
313
|
+
}
|
|
314
|
+
return true;
|
|
315
|
+
};
|
|
316
|
+
// Wheeled on past an end (or back), until quiet.
|
|
317
|
+
const onWheel = (event) => {
|
|
318
|
+
const delta = wheelPixels(event, element.clientHeight);
|
|
319
|
+
if (coast(event, delta))
|
|
320
|
+
return;
|
|
321
|
+
cancelAnimationFrame(bounce);
|
|
322
|
+
const raw = element.scrollTop;
|
|
323
|
+
const isPast = (raw <= 0 && delta < 0) || (raw >= range() && delta > 0);
|
|
324
|
+
if (isPast || pull !== 0) {
|
|
325
|
+
const next = pull + delta;
|
|
326
|
+
pull = pull !== 0 && Math.sign(next) !== Math.sign(pull) ? 0 : next;
|
|
327
|
+
}
|
|
328
|
+
clearTimeout(wheel);
|
|
329
|
+
wheel = setTimeout(() => {
|
|
330
|
+
wheel = undefined;
|
|
331
|
+
release();
|
|
332
|
+
}, wheelQuiet);
|
|
333
|
+
emit();
|
|
334
|
+
};
|
|
335
|
+
const listeners = [
|
|
336
|
+
['scroll', emit],
|
|
337
|
+
['touchstart', onTouchStart],
|
|
338
|
+
['touchmove', onTouchMove],
|
|
339
|
+
['touchend', onTouchEnd],
|
|
340
|
+
['touchcancel', onTouchEnd],
|
|
341
|
+
['wheel', onWheel],
|
|
342
|
+
];
|
|
343
|
+
for (const [type, listener] of listeners) {
|
|
344
|
+
target.addEventListener(type, listener, { passive: true });
|
|
345
|
+
}
|
|
346
|
+
return () => {
|
|
347
|
+
clearTimeout(wheel);
|
|
348
|
+
cancelAnimationFrame(bounce);
|
|
349
|
+
for (const [type, listener] of listeners) {
|
|
350
|
+
target.removeEventListener(type, listener);
|
|
351
|
+
}
|
|
352
|
+
if (element instanceof HTMLElement) {
|
|
353
|
+
element.style.removeProperty('--uikit-viewport-bounce');
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
}, [scroll, scroller]);
|
|
132
357
|
const value = useMemo(() => ({ scroll, visual }), [scroll, visual]);
|
|
133
358
|
return (_jsx(ViewportContext.Provider, { value: value, children: children }));
|
|
134
359
|
};
|
|
360
|
+
// A regular width: the window's, from 768px.
|
|
361
|
+
const regularQuery = '(width >= 768px)';
|
|
362
|
+
const subscribeRegular = (onChange) => {
|
|
363
|
+
const query = matchMedia(regularQuery);
|
|
364
|
+
query.addEventListener('change', onChange);
|
|
365
|
+
return () => query.removeEventListener('change', onChange);
|
|
366
|
+
};
|
|
367
|
+
/**
|
|
368
|
+
* The window's horizontal size class (no `Provider` needed): e.g. a sheet
|
|
369
|
+
* on `compact` (a phone), a popover on `regular` (an iPad); `compact` before
|
|
370
|
+
* hydration (server rendering).
|
|
371
|
+
*/
|
|
372
|
+
export const useSizeClass = () => useSyncExternalStore(subscribeRegular, () => (matchMedia(regularQuery).matches ? 'regular' : 'compact'), () => 'compact');
|
|
135
373
|
/** The visual viewport and the keyboard's height (needs a `Provider`). */
|
|
136
374
|
export const useVisualViewport = () => {
|
|
137
375
|
const context = useContext(ViewportContext);
|
|
138
376
|
return context?.visual ?? readVisual();
|
|
139
377
|
};
|
|
140
378
|
/**
|
|
141
|
-
* Calls `listener` on every scroll of the tracked scroll container
|
|
142
|
-
* `Provider`);
|
|
379
|
+
* Calls `listener` on every scroll of the tracked scroll container, and as
|
|
380
|
+
* it's overscrolled (needs a `Provider`); the direction past its own
|
|
381
|
+
* `threshold`. It can change without resubscribing.
|
|
143
382
|
*/
|
|
144
|
-
export const useViewportScroll = (listener) => {
|
|
383
|
+
export const useViewportScroll = (listener, { threshold = 8 } = {}) => {
|
|
145
384
|
const context = useContext(ViewportContext);
|
|
146
385
|
const latest = useRef(listener);
|
|
147
386
|
useLayoutEffect(() => {
|
|
148
387
|
latest.current = listener;
|
|
149
388
|
});
|
|
150
|
-
useEffect(() =>
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
if (!context)
|
|
391
|
+
return undefined;
|
|
392
|
+
const track = trackDirection(threshold, context.scroll.current().position);
|
|
393
|
+
return context.scroll.subscribe((scroll) => latest.current(track(scroll)));
|
|
394
|
+
}, [context, threshold]);
|
|
151
395
|
};
|
|
152
396
|
/**
|
|
153
|
-
* The direction the tracked scroll container is scrolled in
|
|
154
|
-
* it's at its top or bottom (re-rendering when
|
|
397
|
+
* The direction the tracked scroll container is scrolled in (past
|
|
398
|
+
* `threshold`), and whether it's at its top or bottom (re-rendering when
|
|
399
|
+
* these change).
|
|
155
400
|
*/
|
|
156
|
-
export const useScrollDirection = () => {
|
|
401
|
+
export const useScrollDirection = (options) => {
|
|
157
402
|
const context = useContext(ViewportContext);
|
|
158
403
|
const [state, setState] = useState(() => {
|
|
159
|
-
const { atBottom, atTop
|
|
404
|
+
const { atBottom, atTop } = context?.scroll.current() ?? {
|
|
160
405
|
atBottom: false,
|
|
161
406
|
atTop: true,
|
|
162
|
-
direction: undefined,
|
|
163
407
|
};
|
|
164
|
-
return { atBottom, atTop, direction };
|
|
408
|
+
return { atBottom, atTop, direction: undefined };
|
|
165
409
|
});
|
|
166
410
|
useViewportScroll(({ atBottom, atTop, direction }) => setState((current) => current.atBottom === atBottom &&
|
|
167
411
|
current.atTop === atTop &&
|
|
168
412
|
current.direction === direction
|
|
169
413
|
? current
|
|
170
|
-
: { atBottom, atTop, direction }));
|
|
414
|
+
: { atBottom, atTop, direction }), options);
|
|
171
415
|
return state;
|
|
172
416
|
};
|
|
417
|
+
/**
|
|
418
|
+
* Whether the element (`ref`'s, as first mounted) is in the visible area:
|
|
419
|
+
* the viewport, or `scroller`'s box (an `IntersectionObserver`; `false`
|
|
420
|
+
* until it reports, and on the server).
|
|
421
|
+
*/
|
|
422
|
+
export const useElementVisibility = (ref, { rootMargin = '0px', scroller, threshold = 0, } = {}) => {
|
|
423
|
+
const [isVisible, setIsVisible] = useState(false);
|
|
424
|
+
useEffect(() => {
|
|
425
|
+
const element = ref.current;
|
|
426
|
+
if (!element)
|
|
427
|
+
return undefined;
|
|
428
|
+
const observer = new IntersectionObserver((entries) => {
|
|
429
|
+
const entry = entries.at(-1);
|
|
430
|
+
if (!entry)
|
|
431
|
+
return;
|
|
432
|
+
setIsVisible(entry.isIntersecting && entry.intersectionRatio >= threshold);
|
|
433
|
+
}, { root: scroller?.current ?? null, rootMargin, threshold });
|
|
434
|
+
observer.observe(element);
|
|
435
|
+
return () => observer.disconnect();
|
|
436
|
+
}, [ref, rootMargin, scroller, threshold]);
|
|
437
|
+
return isVisible;
|
|
438
|
+
};
|
|
439
|
+
/** The visible area's edges (client coordinates): the scroller's box, inside its borders and scroll bars, or the layout viewport's. */
|
|
440
|
+
const readArea = (scroller) => {
|
|
441
|
+
if (!scroller) {
|
|
442
|
+
const { clientHeight, clientWidth } = document.documentElement;
|
|
443
|
+
return { bottom: clientHeight, left: 0, right: clientWidth, top: 0 };
|
|
444
|
+
}
|
|
445
|
+
const box = scroller.getBoundingClientRect();
|
|
446
|
+
const left = box.left + scroller.clientLeft;
|
|
447
|
+
const top = box.top + scroller.clientTop;
|
|
448
|
+
return {
|
|
449
|
+
bottom: top + scroller.clientHeight,
|
|
450
|
+
left,
|
|
451
|
+
right: left + scroller.clientWidth,
|
|
452
|
+
top,
|
|
453
|
+
};
|
|
454
|
+
};
|
|
455
|
+
const share = (part, whole) => (whole > 0 ? part / whole : 0);
|
|
456
|
+
const readGeometry = (element, scroller) => {
|
|
457
|
+
const box = element.getBoundingClientRect();
|
|
458
|
+
const area = readArea(scroller);
|
|
459
|
+
const visibleWidth = Math.max(0, Math.min(box.right, area.right) - Math.max(box.left, area.left));
|
|
460
|
+
const visibleHeight = Math.max(0, Math.min(box.bottom, area.bottom) - Math.max(box.top, area.top));
|
|
461
|
+
return {
|
|
462
|
+
bottom: area.bottom - box.bottom,
|
|
463
|
+
height: box.height,
|
|
464
|
+
left: box.left - area.left,
|
|
465
|
+
right: area.right - box.right,
|
|
466
|
+
top: box.top - area.top,
|
|
467
|
+
visibleHeight,
|
|
468
|
+
visibleHeightRatio: share(visibleHeight, box.height),
|
|
469
|
+
visibleRatio: share(visibleWidth * visibleHeight, box.width * box.height),
|
|
470
|
+
visibleWidth,
|
|
471
|
+
visibleWidthRatio: share(visibleWidth, box.width),
|
|
472
|
+
width: box.width,
|
|
473
|
+
};
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Calls `listener` with where the element (`ref`'s, as first mounted) is in
|
|
477
|
+
* the visible area (the viewport, or `scroller`'s box): its edges'
|
|
478
|
+
* distances to the area's, how much of it shows. Measured once per frame
|
|
479
|
+
* while anything scrolls or resizes, and only while it's visible (once
|
|
480
|
+
* more as it leaves), and once as it mounts; the listener can change
|
|
481
|
+
* without resubscribing (as `useViewportScroll`'s), and nothing re-renders
|
|
482
|
+
* unless it does (e.g. setting state).
|
|
483
|
+
*/
|
|
484
|
+
export const useElementGeometry = (ref, listener, { scroller } = {}) => {
|
|
485
|
+
const isVisible = useElementVisibility(ref, { scroller });
|
|
486
|
+
const latest = useRef(listener);
|
|
487
|
+
useLayoutEffect(() => {
|
|
488
|
+
latest.current = listener;
|
|
489
|
+
});
|
|
490
|
+
useEffect(() => {
|
|
491
|
+
const element = ref.current;
|
|
492
|
+
if (!element)
|
|
493
|
+
return undefined;
|
|
494
|
+
const update = () => latest.current(readGeometry(element, scroller?.current ?? null));
|
|
495
|
+
// (Visible or not: where it is now, e.g. having just left.)
|
|
496
|
+
update();
|
|
497
|
+
if (!isVisible)
|
|
498
|
+
return undefined;
|
|
499
|
+
let frame = 0;
|
|
500
|
+
const schedule = () => {
|
|
501
|
+
if (frame)
|
|
502
|
+
return;
|
|
503
|
+
frame = requestAnimationFrame(() => {
|
|
504
|
+
frame = 0;
|
|
505
|
+
update();
|
|
506
|
+
});
|
|
507
|
+
};
|
|
508
|
+
// (Scrolls of any container moving it: they don't bubble, so captured.)
|
|
509
|
+
addEventListener('scroll', schedule, { capture: true, passive: true });
|
|
510
|
+
addEventListener('resize', schedule, { passive: true });
|
|
511
|
+
const resizes = new ResizeObserver(schedule);
|
|
512
|
+
resizes.observe(element);
|
|
513
|
+
if (scroller?.current)
|
|
514
|
+
resizes.observe(scroller.current);
|
|
515
|
+
return () => {
|
|
516
|
+
cancelAnimationFrame(frame);
|
|
517
|
+
removeEventListener('scroll', schedule, { capture: true });
|
|
518
|
+
removeEventListener('resize', schedule);
|
|
519
|
+
resizes.disconnect();
|
|
520
|
+
};
|
|
521
|
+
}, [ref, scroller, isVisible]);
|
|
522
|
+
};
|
|
173
523
|
/**
|
|
174
524
|
* Floats above the content (and its scroll container) at an edge of the
|
|
175
525
|
* visual viewport (see the custom properties above): a bar at the top or
|
|
176
526
|
* bottom, a (compact) sidebar at the leading or trailing edge; its safe
|
|
177
527
|
* area insets kept clear (as padding).
|
|
178
528
|
*/
|
|
179
|
-
const Anchor = forwardRef(({ className, edge, keyboard = 'push', safeArea = 'all', ...props },
|
|
529
|
+
const Anchor = forwardRef(({ className, edge, handle, keyboard = 'push', safeArea = 'all', ...props }, forwardedRef) => {
|
|
530
|
+
const ref = useForwardedRef(forwardedRef);
|
|
531
|
+
// Its size, for the paddings making room for it (see `Padding`).
|
|
532
|
+
useAnchorRegistration(ref, edge, handle);
|
|
533
|
+
return (_jsx("div", { ref: ref, "data-edge": edge, "data-keyboard": keyboard, "data-safe-area": safeArea, ...props, className: cn('uikit-viewport-anchor', className), "data-viewport-part": "anchor" }));
|
|
534
|
+
});
|
|
535
|
+
// A content layer's `alwaysBounce`, as its attribute: on, off (none), or
|
|
536
|
+
// unset (`auto`, see style.css).
|
|
537
|
+
const bounceAttribute = (alwaysBounce) => {
|
|
538
|
+
if (alwaysBounce === undefined)
|
|
539
|
+
return 'auto';
|
|
540
|
+
return alwaysBounce ? '' : undefined;
|
|
541
|
+
};
|
|
180
542
|
/**
|
|
181
543
|
* The content layer: filling the viewport, scrolling its content (track it
|
|
182
544
|
* with `Provider`'s `scroller`), below the anchors; its safe area insets
|
|
183
545
|
* kept clear (as padding).
|
|
184
546
|
*/
|
|
185
|
-
const Content = forwardRef(({ className, keyboard = 'resize', safeArea = 'all', ...props }, ref) => (_jsx("div", { ref: ref, "data-keyboard": keyboard, "data-safe-area": safeArea, ...props, className: cn('uikit-viewport-content', className), "data-viewport-part": "content" })));
|
|
547
|
+
const Content = forwardRef(({ alwaysBounce, className, keyboard = 'resize', safeArea = 'all', ...props }, ref) => (_jsx("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" })));
|
|
548
|
+
/**
|
|
549
|
+
* What shows past an end of the tracked scroll container as it's pulled
|
|
550
|
+
* there (needs a `Provider`): e.g. a refresh indicator. A layer beneath the
|
|
551
|
+
* content layer (rendered before it), from its edge's bars (`anchor`), the
|
|
552
|
+
* content's end moving it along as it bounces (Safari's own bounce; other
|
|
553
|
+
* browsers', the scroll container moved along as it's pulled); where the
|
|
554
|
+
* content stays (the document's, there), sliding in over it. Its pull, as
|
|
555
|
+
* custom properties: `--uikit-viewport-overscroll` (px), and
|
|
556
|
+
* `--uikit-viewport-overscroll-progress` (0 to 1, of its own size; open, 1).
|
|
557
|
+
* Open, it's kept shown at rest, the padding at its edge making room for it
|
|
558
|
+
* (see `useOverscrollRoom`).
|
|
559
|
+
*/
|
|
560
|
+
const Overscroll = forwardRef(({ anchor, className, edge = 'block-start', open = false, style, ...props }, forwardedRef) => {
|
|
561
|
+
const context = useContext(ViewportContext);
|
|
562
|
+
const ref = useForwardedRef(forwardedRef);
|
|
563
|
+
const layer = useRef(null);
|
|
564
|
+
const inset = useAnchorSize(edge, anchor);
|
|
565
|
+
const [size, setSize] = useState(0);
|
|
566
|
+
const isOpen = useRef(open);
|
|
567
|
+
const pull = useRef(0);
|
|
568
|
+
useOverscrollRoom(edge, open ? size : 0);
|
|
569
|
+
// Its pull, and how far along (of its size; open, all the way).
|
|
570
|
+
const update = useCallback(() => {
|
|
571
|
+
const { current: element } = layer;
|
|
572
|
+
if (!element)
|
|
573
|
+
return;
|
|
574
|
+
const height = ref.current?.offsetHeight ?? 0;
|
|
575
|
+
const progress = height > 0 ? Math.min(pull.current / height, 1) : 0;
|
|
576
|
+
element.style.setProperty('--uikit-viewport-overscroll', `${String(pull.current)}px`);
|
|
577
|
+
element.style.setProperty('--uikit-viewport-overscroll-progress', String(isOpen.current ? 1 : progress));
|
|
578
|
+
// Where the content stays (a document's, not bouncing): over it.
|
|
579
|
+
const scroll = context?.scroll;
|
|
580
|
+
element.toggleAttribute('data-overlay', !(scroll?.isNative() ?? false) && !(scroll?.isMoved() ?? false));
|
|
581
|
+
}, [context, ref]);
|
|
582
|
+
useLayoutEffect(() => {
|
|
583
|
+
isOpen.current = open;
|
|
584
|
+
update();
|
|
585
|
+
}, [open, update]);
|
|
586
|
+
useViewportScroll(({ overscroll }) => {
|
|
587
|
+
pull.current = Math.max(0, edge === 'block-start' ? -overscroll : overscroll);
|
|
588
|
+
update();
|
|
589
|
+
});
|
|
590
|
+
// Its size (the room made for it, open).
|
|
591
|
+
useLayoutEffect(() => {
|
|
592
|
+
const { current: element } = ref;
|
|
593
|
+
if (!element)
|
|
594
|
+
return undefined;
|
|
595
|
+
const observer = new ResizeObserver(([record]) => {
|
|
596
|
+
setSize(Math.round(record?.borderBoxSize[0]?.blockSize ?? 0));
|
|
597
|
+
});
|
|
598
|
+
observer.observe(element);
|
|
599
|
+
return () => observer.disconnect();
|
|
600
|
+
}, [ref]);
|
|
601
|
+
return (_jsx("div", { ref: layer, className: "uikit-viewport-overscroll", "data-edge": edge, "data-viewport-part": "overscroll", style: { '--uikit-viewport-overscroll-inset': `${String(inset)}px` }, children: _jsx("div", { ref: ref, "data-open": open ? '' : undefined, style: withStyle({
|
|
602
|
+
'--uikit-viewport-overscroll-room': `${String(open ? size : 0)}px`,
|
|
603
|
+
}, style), ...props, className: cn('uikit-viewport-overscroll-area', className), "data-viewport-part": "overscroll-area" }) }));
|
|
604
|
+
});
|
|
186
605
|
/** A bar at the block start (the top; an `Anchor`). */
|
|
187
606
|
const BlockStart = forwardRef((props, ref) => (_jsx(Anchor, { ref: ref, edge: "block-start", ...props })));
|
|
188
607
|
/** A bar at the block end (the bottom), above the keyboard (an `Anchor`). */
|
|
@@ -193,5 +612,8 @@ export const Viewport = {
|
|
|
193
612
|
Content,
|
|
194
613
|
BlockStart,
|
|
195
614
|
BlockEnd,
|
|
615
|
+
Overscroll,
|
|
616
|
+
Padding,
|
|
617
|
+
createAnchorHandle,
|
|
196
618
|
};
|
|
197
619
|
//# sourceMappingURL=main.js.map
|