glasslikeui 1.6.0 → 1.7.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/LICENSE +373 -674
- package/README.md +68 -4
- package/dist/actions/dragSnap.d.ts +16 -39
- package/dist/actions/dragSnap.js +6 -224
- package/dist/actions/dragSnapMath.d.ts +68 -0
- package/dist/actions/dragSnapMath.js +165 -0
- package/dist/actions/dragSurface.d.ts +26 -0
- package/dist/actions/dragSurface.js +187 -0
- package/dist/actions/focusTrap.d.ts +22 -0
- package/dist/actions/focusTrap.js +83 -0
- package/dist/actions/index.d.ts +3 -0
- package/dist/actions/index.js +3 -0
- package/dist/actions/inertSiblings.d.ts +10 -0
- package/dist/actions/inertSiblings.js +35 -0
- package/dist/actions/reducedMotion.d.ts +25 -0
- package/dist/actions/reducedMotion.js +26 -0
- package/dist/actions/sheetBodyDrag.d.ts +14 -0
- package/dist/actions/sheetBodyDrag.js +26 -0
- package/dist/actions/sheetExit.d.ts +36 -0
- package/dist/actions/sheetExit.js +65 -0
- package/dist/actions/swipeActions.d.ts +14 -5
- package/dist/actions/swipeActions.js +89 -16
- package/dist/components/glass/Glass.svelte +41 -6
- package/dist/components/glass/Sheet.svelte +227 -60
- package/dist/components/glass/Sheet.svelte.d.ts +7 -1
- package/dist/components/interactive/Button.svelte +4 -2
- package/dist/components/list/ListRow.svelte +33 -10
- package/dist/constants/shapes.d.ts +7 -0
- package/dist/constants/shapes.js +16 -0
- package/dist/styles/glasslikeui.css +31 -0
- package/dist/styles/lens.css +41 -0
- package/package.json +2 -2
|
@@ -3,7 +3,12 @@
|
|
|
3
3
|
* `.swipeActions(edge:allowsFullSwipe:)`.
|
|
4
4
|
*
|
|
5
5
|
* The node is translated by the `--swipe-x` custom property and tagged with
|
|
6
|
-
* `data-swipe-state`; the action strip itself is the caller's markup.
|
|
6
|
+
* `data-swipe-state`; the action strip itself is the caller's markup. When
|
|
7
|
+
* `stateElement` is given (an ancestor both the content and the strip can see),
|
|
8
|
+
* the same properties are mirrored onto it, together with `--swipe-reveal`, the
|
|
9
|
+
* unsigned distance the content has travelled. A strip with
|
|
10
|
+
* `min-width: var(--swipe-reveal)` then grows to fill exactly the revealed
|
|
11
|
+
* space, so no gap opens when the row is dragged past the action width.
|
|
7
12
|
*
|
|
8
13
|
* Usage:
|
|
9
14
|
* <div use:swipeActions={{
|
|
@@ -26,7 +31,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
26
31
|
};
|
|
27
32
|
// The velocity helpers are axis-agnostic -- `y` is simply "position along the
|
|
28
33
|
// drag axis", so the x-axis gesture reuses them rather than cloning them.
|
|
29
|
-
import { computeVelocity, pushSample } from './
|
|
34
|
+
import { computeVelocity, pushSample } from './dragSnapMath';
|
|
30
35
|
/** Fraction of the row that must be crossed to arm a full swipe. */
|
|
31
36
|
export var DEFAULT_FULL_SWIPE_THRESHOLD = 0.5;
|
|
32
37
|
/** How much of an overshoot past the limit is tracked. */
|
|
@@ -40,10 +45,7 @@ export function edgeSign(edge) {
|
|
|
40
45
|
// Unknown edges fall back to trailing, matching SwiftUI's default.
|
|
41
46
|
return edge === 'leading' ? 1 : -1;
|
|
42
47
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Constrain a raw pointer delta to the row's travel: one-to-one up to the
|
|
45
|
-
* limit, damped beyond it, and zero against the configured edge.
|
|
46
|
-
*/
|
|
48
|
+
/** Constrain a raw pointer delta to the row's travel: one-to-one to the limit, damped beyond it, never past the row width, and zero against the configured edge. */
|
|
47
49
|
export function clampSwipeOffset(rawDx, geo) {
|
|
48
50
|
if (!Number.isFinite(rawDx))
|
|
49
51
|
return 0;
|
|
@@ -60,7 +62,14 @@ export function clampSwipeOffset(rawDx, geo) {
|
|
|
60
62
|
? Math.max(geo.actionsWidth, geo.rowWidth)
|
|
61
63
|
: geo.actionsWidth;
|
|
62
64
|
var travel = magnitude <= limit ? magnitude : limit + (magnitude - limit) * DEFAULT_SWIPE_RUBBER_BAND;
|
|
63
|
-
|
|
65
|
+
// The content cannot leave the row, however far the pointer goes. An
|
|
66
|
+
// unmeasured row (0) puts no cap on it.
|
|
67
|
+
var capped = geo.rowWidth > 0 ? Math.min(travel, geo.rowWidth) : travel;
|
|
68
|
+
return capped * sign;
|
|
69
|
+
}
|
|
70
|
+
/** The unsigned distance a given offset has slid the content, in px. */
|
|
71
|
+
export function revealedWidth(offset) {
|
|
72
|
+
return Number.isFinite(offset) ? Math.abs(offset) : 0;
|
|
64
73
|
}
|
|
65
74
|
/** Where the row settles once the pointer is released. */
|
|
66
75
|
export function resolveSwipeState(offset, velocity, geo) {
|
|
@@ -93,8 +102,25 @@ export function offsetForState(state, geo) {
|
|
|
93
102
|
return geo.rowWidth * sign;
|
|
94
103
|
return 0;
|
|
95
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The strip's own width. Its `min-width` (which tracks the revealed distance)
|
|
107
|
+
* is lifted for the read, otherwise a strip stretched by an earlier drag would
|
|
108
|
+
* report its stretched width and raise its own limit.
|
|
109
|
+
*/
|
|
96
110
|
function measureWidth(el) {
|
|
97
|
-
|
|
111
|
+
if (!el)
|
|
112
|
+
return 0;
|
|
113
|
+
var previous = el.style.minWidth;
|
|
114
|
+
el.style.minWidth = '0px';
|
|
115
|
+
var width = el.getBoundingClientRect().width;
|
|
116
|
+
el.style.minWidth = previous;
|
|
117
|
+
return width;
|
|
118
|
+
}
|
|
119
|
+
function clearState(el) {
|
|
120
|
+
el.style.removeProperty('--swipe-x');
|
|
121
|
+
el.style.removeProperty('--swipe-reveal');
|
|
122
|
+
el.removeAttribute('data-swipe-state');
|
|
123
|
+
el.removeAttribute('data-swipe-dragging');
|
|
98
124
|
}
|
|
99
125
|
export function swipeActions(node, initialOptions) {
|
|
100
126
|
var options = __assign({}, initialOptions);
|
|
@@ -105,21 +131,57 @@ export function swipeActions(node, initialOptions) {
|
|
|
105
131
|
var claimed = false;
|
|
106
132
|
var abandoned = false;
|
|
107
133
|
var samples = [];
|
|
134
|
+
// The strip's natural width, read once per gesture. Re-reading it on every
|
|
135
|
+
// move would let a strip that grows with the drag raise its own limit.
|
|
136
|
+
var naturalWidth = null;
|
|
137
|
+
function actionsWidth() {
|
|
138
|
+
if (options.actionsWidth !== undefined)
|
|
139
|
+
return options.actionsWidth;
|
|
140
|
+
if (naturalWidth === null) {
|
|
141
|
+
var measured = measureWidth(options.actionsElement);
|
|
142
|
+
// 0 means "not laid out yet": do not remember it.
|
|
143
|
+
if (measured > 0)
|
|
144
|
+
naturalWidth = measured;
|
|
145
|
+
return measured;
|
|
146
|
+
}
|
|
147
|
+
return naturalWidth;
|
|
148
|
+
}
|
|
108
149
|
function geometry() {
|
|
109
|
-
var _a, _b, _c
|
|
150
|
+
var _a, _b, _c;
|
|
110
151
|
return {
|
|
111
152
|
edge: (_a = options.edge) !== null && _a !== void 0 ? _a : 'trailing',
|
|
112
|
-
actionsWidth:
|
|
113
|
-
rowWidth: (
|
|
114
|
-
allowsFullSwipe: (
|
|
153
|
+
actionsWidth: actionsWidth(),
|
|
154
|
+
rowWidth: (_b = options.rowWidth) !== null && _b !== void 0 ? _b : node.getBoundingClientRect().width,
|
|
155
|
+
allowsFullSwipe: (_c = options.allowsFullSwipe) !== null && _c !== void 0 ? _c : false
|
|
115
156
|
};
|
|
116
157
|
}
|
|
158
|
+
/** Every element the gesture reports to: the node, plus the optional ancestor. */
|
|
159
|
+
function targets() {
|
|
160
|
+
return options.stateElement ? [node, options.stateElement] : [node];
|
|
161
|
+
}
|
|
117
162
|
function applyOffset(offset) {
|
|
118
|
-
|
|
163
|
+
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
164
|
+
var el = _a[_i];
|
|
165
|
+
el.style.setProperty('--swipe-x', "".concat(offset, "px"));
|
|
166
|
+
el.style.setProperty('--swipe-reveal', "".concat(revealedWidth(offset), "px"));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function setDragging(on) {
|
|
170
|
+
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
171
|
+
var el = _a[_i];
|
|
172
|
+
if (on)
|
|
173
|
+
el.setAttribute('data-swipe-dragging', 'true');
|
|
174
|
+
else
|
|
175
|
+
el.removeAttribute('data-swipe-dragging');
|
|
176
|
+
}
|
|
119
177
|
}
|
|
120
178
|
function settle(next) {
|
|
121
179
|
state = next;
|
|
122
|
-
|
|
180
|
+
setDragging(false);
|
|
181
|
+
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
182
|
+
var el = _a[_i];
|
|
183
|
+
el.setAttribute('data-swipe-state', next);
|
|
184
|
+
}
|
|
123
185
|
applyOffset(offsetForState(next, geometry()));
|
|
124
186
|
}
|
|
125
187
|
function onPointerDown(event) {
|
|
@@ -132,6 +194,9 @@ export function swipeActions(node, initialOptions) {
|
|
|
132
194
|
startY = event.clientY;
|
|
133
195
|
claimed = false;
|
|
134
196
|
abandoned = false;
|
|
197
|
+
// Measure the strip once, now, before the drag can stretch it.
|
|
198
|
+
naturalWidth = null;
|
|
199
|
+
actionsWidth();
|
|
135
200
|
samples = [{ y: event.clientX, t: performance.now() }];
|
|
136
201
|
}
|
|
137
202
|
function onPointerMove(event) {
|
|
@@ -148,6 +213,7 @@ export function swipeActions(node, initialOptions) {
|
|
|
148
213
|
if (Math.abs(dx) < SWIPE_SLOP)
|
|
149
214
|
return;
|
|
150
215
|
claimed = true;
|
|
216
|
+
setDragging(true);
|
|
151
217
|
}
|
|
152
218
|
var resting = offsetForState(state, geometry());
|
|
153
219
|
applyOffset(clampSwipeOffset(resting + dx, geometry()));
|
|
@@ -186,7 +252,12 @@ export function swipeActions(node, initialOptions) {
|
|
|
186
252
|
settle('closed');
|
|
187
253
|
return {
|
|
188
254
|
update: function (newOptions) {
|
|
255
|
+
var previous = options.stateElement;
|
|
189
256
|
options = __assign({}, newOptions);
|
|
257
|
+
naturalWidth = null;
|
|
258
|
+
// A swapped-out ancestor must not keep stale state.
|
|
259
|
+
if (previous && previous !== options.stateElement)
|
|
260
|
+
clearState(previous);
|
|
190
261
|
settle(state);
|
|
191
262
|
},
|
|
192
263
|
destroy: function () {
|
|
@@ -194,8 +265,10 @@ export function swipeActions(node, initialOptions) {
|
|
|
194
265
|
node.removeEventListener('pointermove', onPointerMove);
|
|
195
266
|
node.removeEventListener('pointerup', onPointerUp);
|
|
196
267
|
node.removeEventListener('pointercancel', onPointerCancel);
|
|
197
|
-
|
|
198
|
-
|
|
268
|
+
for (var _i = 0, _a = targets(); _i < _a.length; _i++) {
|
|
269
|
+
var el = _a[_i];
|
|
270
|
+
clearState(el);
|
|
271
|
+
}
|
|
199
272
|
}
|
|
200
273
|
};
|
|
201
274
|
}
|
|
@@ -151,17 +151,52 @@
|
|
|
151
151
|
mix-blend-mode: overlay;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
.glass-content {
|
|
155
|
+
position: relative;
|
|
156
|
+
z-index: 2;
|
|
157
|
+
height: 100%;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/* Control shapes centre their content on both axes. The surface does the
|
|
161
|
+
centring rather than a percentage height on .glass-content: WebKit
|
|
162
|
+
resolves that percentage against the aspect-ratio box without removing
|
|
163
|
+
the padding, so the content overflowed and a circle label sat one
|
|
164
|
+
padding-width below centre. :where keeps callers able to override. */
|
|
165
|
+
:where(.glass-surface[data-glass-shape='capsule']),
|
|
166
|
+
:where(.glass-surface[data-glass-shape='circle']) {
|
|
156
167
|
display: flex;
|
|
157
168
|
align-items: center;
|
|
158
169
|
justify-content: center;
|
|
159
170
|
}
|
|
160
171
|
|
|
161
|
-
.glass-content
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
172
|
+
:where(.glass-surface[data-glass-shape='capsule']) > .glass-content,
|
|
173
|
+
:where(.glass-surface[data-glass-shape='circle']) > .glass-content {
|
|
174
|
+
height: auto;
|
|
175
|
+
min-width: 0;
|
|
176
|
+
max-width: 100%;
|
|
177
|
+
text-align: center;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
:where(.glass-surface[data-glass-shape='circle']) > .glass-content {
|
|
181
|
+
display: flex;
|
|
182
|
+
align-items: center;
|
|
183
|
+
justify-content: center;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/* A rect surface holding one text-level child (see GLASS_LONE_LABEL_ELEMENTS)
|
|
187
|
+
centres it the same way. The :has() guard keeps panels, cards and stacks,
|
|
188
|
+
whose child is a div or several children, laid out exactly as before. */
|
|
189
|
+
:where(.glass-surface:has(> .glass-content > :global(:where(span, label, strong, b, em, small, svg, img):only-child))) {
|
|
190
|
+
display: flex;
|
|
191
|
+
align-items: center;
|
|
192
|
+
justify-content: center;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
:where(.glass-surface:has(> .glass-content > :global(:where(span, label, strong, b, em, small, svg, img):only-child))) > .glass-content {
|
|
196
|
+
height: auto;
|
|
197
|
+
min-width: 0;
|
|
198
|
+
max-width: 100%;
|
|
199
|
+
text-align: center;
|
|
165
200
|
}
|
|
166
201
|
|
|
167
202
|
.glass-surface.has-shadow {
|
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Snippet } from 'svelte';
|
|
3
3
|
import { fromAction } from 'svelte/attachments';
|
|
4
|
-
import {
|
|
4
|
+
import { getIconPath } from '../../icons';
|
|
5
|
+
import { dragSurface } from '../../actions/dragSurface';
|
|
5
6
|
import {
|
|
6
|
-
dragSnap,
|
|
7
7
|
detentFractions,
|
|
8
|
+
isDragStartAllowed,
|
|
9
|
+
sheetYForFraction,
|
|
10
|
+
detentAt,
|
|
8
11
|
type SheetDetentName
|
|
9
|
-
} from '../../actions/
|
|
12
|
+
} from '../../actions/dragSnapMath';
|
|
13
|
+
import { startSheetExit, type SheetExit } from '../../actions/sheetExit';
|
|
14
|
+
import { inertSiblings } from '../../actions/inertSiblings';
|
|
15
|
+
import { trapTab } from '../../actions/focusTrap';
|
|
10
16
|
|
|
11
|
-
|
|
17
|
+
/** The parts of the sheet a drag starts from on the press: the handle and the header. */
|
|
18
|
+
const DRAG_REGIONS = '.sheet-handle-container, .sheet-header';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The body, where a press only arms a drag that starts once it pulls down
|
|
22
|
+
* with the content at the top, so taps and scrolling there keep working.
|
|
23
|
+
*/
|
|
24
|
+
const BODY_DRAG_REGION = '.sheet-content';
|
|
12
25
|
|
|
13
26
|
interface Props {
|
|
14
27
|
isOpen?: boolean;
|
|
@@ -20,6 +33,12 @@
|
|
|
20
33
|
initialDetent?: SheetDetentName;
|
|
21
34
|
showHandle?: boolean;
|
|
22
35
|
draggable?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Turns off drag to dismiss, mirroring SwiftUI's interactiveDismissDisabled.
|
|
38
|
+
* Dragging below the smallest detent then rubber-bands and snaps back. The
|
|
39
|
+
* close button, Escape and the backdrop still close the sheet.
|
|
40
|
+
*/
|
|
41
|
+
interactiveDismissDisabled?: boolean;
|
|
23
42
|
class?: string;
|
|
24
43
|
}
|
|
25
44
|
|
|
@@ -33,29 +52,77 @@
|
|
|
33
52
|
initialDetent = 'medium',
|
|
34
53
|
showHandle = true,
|
|
35
54
|
draggable = true,
|
|
55
|
+
interactiveDismissDisabled = false,
|
|
36
56
|
class: className = ''
|
|
37
57
|
}: Props = $props();
|
|
38
58
|
|
|
59
|
+
const uid = $props.id();
|
|
60
|
+
const titleId = `${uid}-title`;
|
|
61
|
+
|
|
39
62
|
const fractions = $derived(detentFractions(detents));
|
|
40
63
|
const initialIndex = $derived(Math.max(0, detents.indexOf(initialDetent)));
|
|
41
64
|
|
|
42
65
|
let currentIndex = $derived(initialIndex);
|
|
43
66
|
let sheetEl = $state<HTMLElement | undefined>();
|
|
44
67
|
|
|
68
|
+
// The sheet stays in the DOM after isOpen turns false, for as long as its exit
|
|
69
|
+
// animation runs. `mounted` is set once it has been shown and cleared when the
|
|
70
|
+
// exit completes.
|
|
71
|
+
let mounted = $state(false);
|
|
72
|
+
let exit: SheetExit | null = null;
|
|
73
|
+
let opener: Element | null = null;
|
|
74
|
+
let releaseInert: (() => void) | null = null;
|
|
75
|
+
|
|
76
|
+
const present = $derived(isOpen || mounted);
|
|
77
|
+
const sheetState = $derived(isOpen ? 'open' : 'closing');
|
|
78
|
+
|
|
79
|
+
/** Slide the sheet away, then unmount. Safe to call more than once. */
|
|
80
|
+
function beginExit() {
|
|
81
|
+
if (exit) return;
|
|
82
|
+
if (!sheetEl) {
|
|
83
|
+
finishExit();
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
let done = false;
|
|
87
|
+
const handle = startSheetExit({
|
|
88
|
+
element: sheetEl,
|
|
89
|
+
restoreY: sheetYForFraction(detentAt(fractions, currentIndex)),
|
|
90
|
+
onDone: () => {
|
|
91
|
+
done = true;
|
|
92
|
+
finishExit();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
// Under reduced motion onDone has already run, so there is nothing to track.
|
|
96
|
+
if (!done) exit = handle;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function finishExit() {
|
|
100
|
+
exit = null;
|
|
101
|
+
mounted = false;
|
|
102
|
+
// The opener sits behind the sheet, so it cannot take focus until the page
|
|
103
|
+
// is no longer inert.
|
|
104
|
+
releaseInert?.();
|
|
105
|
+
if (opener instanceof HTMLElement && opener.isConnected) opener.focus({ preventScroll: true });
|
|
106
|
+
opener = null;
|
|
107
|
+
}
|
|
108
|
+
|
|
45
109
|
function close() {
|
|
110
|
+
// A closed or already closing sheet ignores repeat requests, so onClose
|
|
111
|
+
// fires exactly once per close.
|
|
112
|
+
if (!isOpen || exit) return;
|
|
113
|
+
beginExit();
|
|
46
114
|
isOpen = false;
|
|
47
115
|
onClose?.();
|
|
48
|
-
if (isBrowser) {
|
|
49
|
-
document.body.style.overflow = '';
|
|
50
|
-
}
|
|
51
116
|
}
|
|
52
117
|
|
|
53
118
|
function handleKeydown(e: KeyboardEvent) {
|
|
54
119
|
// The window listener is always attached, so a closed sheet would
|
|
55
|
-
// otherwise fire onClose
|
|
120
|
+
// otherwise fire onClose on every Escape.
|
|
56
121
|
if (!isOpen) return;
|
|
57
122
|
if (e.key === 'Escape') {
|
|
58
123
|
close();
|
|
124
|
+
} else if (e.key === 'Tab' && sheetEl) {
|
|
125
|
+
trapTab(e, sheetEl);
|
|
59
126
|
}
|
|
60
127
|
}
|
|
61
128
|
|
|
@@ -71,22 +138,84 @@
|
|
|
71
138
|
if (name) onDetentChange?.(name);
|
|
72
139
|
}
|
|
73
140
|
|
|
141
|
+
function canStartDrag(event: PointerEvent): boolean {
|
|
142
|
+
if (exit || !sheetEl) return false;
|
|
143
|
+
return isDragStartAllowed(event.target as Element | null, sheetEl, DRAG_REGIONS);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function canStartBodyDrag(event: PointerEvent): boolean {
|
|
147
|
+
if (exit || !sheetEl) return false;
|
|
148
|
+
return isDragStartAllowed(event.target as Element | null, sheetEl, BODY_DRAG_REGION);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Whether the content is scrolled to the top, mirrored to data-scroll-at-top.
|
|
153
|
+
* The browser reads touch-action when a touch begins, so this has to be right
|
|
154
|
+
* before the next pointerdown, not worked out during it.
|
|
155
|
+
*/
|
|
156
|
+
let contentAtTop = $state(true);
|
|
157
|
+
|
|
158
|
+
function trackScrollTop(node: HTMLElement) {
|
|
159
|
+
// Content is mounted afresh on every open, so start from its real offset.
|
|
160
|
+
const sync = () => (contentAtTop = node.scrollTop <= 0);
|
|
161
|
+
sync();
|
|
162
|
+
node.addEventListener('scroll', sync, { passive: true });
|
|
163
|
+
return () => node.removeEventListener('scroll', sync);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Follows isOpen: shows the sheet, cancels a pending exit when it is reopened
|
|
167
|
+
// mid-animation, and starts the exit when the parent clears isOpen itself.
|
|
74
168
|
$effect(() => {
|
|
75
169
|
if (isOpen) {
|
|
170
|
+
if (exit) {
|
|
171
|
+
exit.cancel();
|
|
172
|
+
exit = null;
|
|
173
|
+
}
|
|
174
|
+
mounted = true;
|
|
175
|
+
} else if (sheetEl && mounted) {
|
|
176
|
+
beginExit();
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// Move focus into the dialog when it appears and give it back on close.
|
|
181
|
+
$effect(() => {
|
|
182
|
+
if (!sheetEl) return;
|
|
183
|
+
opener = document.activeElement;
|
|
184
|
+
// Leave focus alone if something inside (an autofocus field) already has it.
|
|
185
|
+
if (!sheetEl.contains(opener)) sheetEl.focus({ preventScroll: true });
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
// The page behind a modal dialog is inert for as long as the sheet is on screen.
|
|
189
|
+
// Declared after the focus effect so the opener is recorded before it goes inert.
|
|
190
|
+
$effect(() => {
|
|
191
|
+
if (!sheetEl) return;
|
|
192
|
+
const release = inertSiblings(sheetEl);
|
|
193
|
+
releaseInert = release;
|
|
194
|
+
return () => {
|
|
195
|
+
release();
|
|
196
|
+
if (releaseInert === release) releaseInert = null;
|
|
197
|
+
};
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
$effect(() => {
|
|
201
|
+
if (present) {
|
|
76
202
|
document.body.style.overflow = 'hidden';
|
|
77
203
|
}
|
|
78
204
|
return () => {
|
|
79
205
|
document.body.style.overflow = '';
|
|
80
206
|
};
|
|
81
207
|
});
|
|
208
|
+
|
|
209
|
+
$effect(() => () => exit?.cancel());
|
|
82
210
|
</script>
|
|
83
211
|
|
|
84
212
|
<svelte:window onkeydown={handleKeydown} />
|
|
85
213
|
|
|
86
|
-
{#if
|
|
214
|
+
{#if present}
|
|
87
215
|
<div
|
|
88
216
|
class="sheet-backdrop"
|
|
89
217
|
class:open={isOpen}
|
|
218
|
+
data-sheet-state={sheetState}
|
|
90
219
|
onclick={handleBackdropClick}
|
|
91
220
|
onkeydown={(e) => e.key === 'Escape' && close()}
|
|
92
221
|
role="presentation"
|
|
@@ -95,50 +224,53 @@
|
|
|
95
224
|
bind:this={sheetEl}
|
|
96
225
|
class="sheet-container {className}"
|
|
97
226
|
class:open={isOpen}
|
|
227
|
+
data-sheet-state={sheetState}
|
|
228
|
+
role="dialog"
|
|
229
|
+
aria-modal="true"
|
|
230
|
+
aria-labelledby={title ? titleId : undefined}
|
|
231
|
+
aria-label={title ? undefined : 'Sheet'}
|
|
232
|
+
tabindex="-1"
|
|
233
|
+
{@attach fromAction(dragSurface, () => ({
|
|
234
|
+
detents: fractions,
|
|
235
|
+
initial: currentIndex,
|
|
236
|
+
disabled: !draggable || (fractions.length < 2 && interactiveDismissDisabled),
|
|
237
|
+
canStart: canStartDrag,
|
|
238
|
+
canStartAfterSlop: canStartBodyDrag,
|
|
239
|
+
onSnap: handleSnap,
|
|
240
|
+
...(interactiveDismissDisabled ? {} : { onDismiss: close })
|
|
241
|
+
}))}
|
|
98
242
|
>
|
|
99
243
|
{#if showHandle}
|
|
100
|
-
<div
|
|
101
|
-
class="sheet-handle-container"
|
|
102
|
-
{@attach fromAction(dragSnap, () => ({
|
|
103
|
-
target: sheetEl,
|
|
104
|
-
detents: fractions,
|
|
105
|
-
initial: currentIndex,
|
|
106
|
-
disabled: !draggable || fractions.length < 2,
|
|
107
|
-
onSnap: handleSnap
|
|
108
|
-
}))}
|
|
109
|
-
>
|
|
244
|
+
<div class="sheet-handle-container">
|
|
110
245
|
<div class="sheet-handle"></div>
|
|
111
246
|
</div>
|
|
112
247
|
{/if}
|
|
113
248
|
|
|
114
249
|
{#if title}
|
|
115
250
|
<header class="sheet-header">
|
|
116
|
-
<
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
<Spacer />
|
|
136
|
-
<div class="sheet-spacer"></div>
|
|
137
|
-
</HStack>
|
|
251
|
+
<div class="sheet-spacer"></div>
|
|
252
|
+
<h2 class="sheet-title" id={titleId}>{title}</h2>
|
|
253
|
+
<button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
|
|
254
|
+
<svg
|
|
255
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
256
|
+
width="16"
|
|
257
|
+
height="16"
|
|
258
|
+
viewBox="0 0 24 24"
|
|
259
|
+
fill="none"
|
|
260
|
+
stroke="currentColor"
|
|
261
|
+
stroke-width="2.5"
|
|
262
|
+
stroke-linecap="round"
|
|
263
|
+
stroke-linejoin="round"
|
|
264
|
+
aria-hidden="true"
|
|
265
|
+
focusable="false"
|
|
266
|
+
>
|
|
267
|
+
{@html getIconPath('xmark')}
|
|
268
|
+
</svg>
|
|
269
|
+
</button>
|
|
138
270
|
</header>
|
|
139
271
|
{/if}
|
|
140
272
|
|
|
141
|
-
<div class="sheet-content">
|
|
273
|
+
<div class="sheet-content" data-scroll-at-top={contentAtTop} {@attach trackScrollTop}>
|
|
142
274
|
{@render children()}
|
|
143
275
|
</div>
|
|
144
276
|
</div>
|
|
@@ -150,12 +282,16 @@
|
|
|
150
282
|
position: fixed;
|
|
151
283
|
inset: 0;
|
|
152
284
|
background: rgba(0, 0, 0, 0.4);
|
|
153
|
-
backdrop-filter: blur(4px);
|
|
154
|
-
-webkit-backdrop-filter: blur(4px);
|
|
285
|
+
backdrop-filter: blur(var(--glass-backdrop-blur, 4px));
|
|
286
|
+
-webkit-backdrop-filter: blur(var(--glass-backdrop-blur, 4px));
|
|
155
287
|
z-index: 1000;
|
|
156
288
|
opacity: 0;
|
|
157
289
|
visibility: hidden;
|
|
158
|
-
|
|
290
|
+
/* The fade runs in step with the sheet's slide, and stops with it under
|
|
291
|
+
reduced motion. */
|
|
292
|
+
transition:
|
|
293
|
+
opacity var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1)),
|
|
294
|
+
visibility var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1));
|
|
159
295
|
}
|
|
160
296
|
|
|
161
297
|
.sheet-backdrop.open {
|
|
@@ -163,6 +299,12 @@
|
|
|
163
299
|
visibility: visible;
|
|
164
300
|
}
|
|
165
301
|
|
|
302
|
+
/* An exiting sheet ignores the pointer: no second close, no new drag. */
|
|
303
|
+
.sheet-backdrop[data-sheet-state='closing'],
|
|
304
|
+
.sheet-container[data-sheet-state='closing'] {
|
|
305
|
+
pointer-events: none;
|
|
306
|
+
}
|
|
307
|
+
|
|
166
308
|
.sheet-container {
|
|
167
309
|
--sheet-y: 100vh;
|
|
168
310
|
position: fixed;
|
|
@@ -179,13 +321,14 @@
|
|
|
179
321
|
display: flex;
|
|
180
322
|
flex-direction: column;
|
|
181
323
|
transform: translateY(var(--sheet-y));
|
|
182
|
-
transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
|
|
324
|
+
transition: transform var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1));
|
|
183
325
|
z-index: 1001;
|
|
184
326
|
border-top: 1px solid var(--glass-border);
|
|
185
327
|
box-shadow:
|
|
186
328
|
0 -8px 32px -8px var(--glass-shadow),
|
|
187
329
|
inset 0 1px 0 0 var(--glass-highlight);
|
|
188
330
|
touch-action: none;
|
|
331
|
+
outline: none;
|
|
189
332
|
}
|
|
190
333
|
|
|
191
334
|
.sheet-handle-container {
|
|
@@ -205,35 +348,45 @@
|
|
|
205
348
|
border-radius: 3px;
|
|
206
349
|
}
|
|
207
350
|
|
|
351
|
+
/* Title centred between an empty cell and the trailing close button, so the
|
|
352
|
+
title stays centred whatever its length. The header is also a drag region. */
|
|
208
353
|
.sheet-header {
|
|
209
354
|
padding: 0 var(--spacing-md);
|
|
210
355
|
height: 56px;
|
|
211
356
|
border-bottom: 1px solid var(--glass-divider);
|
|
212
|
-
display:
|
|
357
|
+
display: grid;
|
|
358
|
+
grid-template-columns: 36px minmax(0, 1fr) 36px;
|
|
213
359
|
align-items: center;
|
|
360
|
+
gap: var(--spacing-sm);
|
|
214
361
|
}
|
|
215
362
|
|
|
216
363
|
.sheet-close-btn {
|
|
217
|
-
display: flex;
|
|
364
|
+
display: inline-flex;
|
|
218
365
|
align-items: center;
|
|
219
|
-
|
|
220
|
-
|
|
366
|
+
justify-content: center;
|
|
367
|
+
width: 32px;
|
|
368
|
+
height: 32px;
|
|
369
|
+
padding: 0;
|
|
221
370
|
border: none;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
371
|
+
border-radius: 50%;
|
|
372
|
+
/* currentColor, so the glyph and its tint follow the text colour even when
|
|
373
|
+
the page defines no --color-text token. */
|
|
374
|
+
background: color-mix(in srgb, currentColor 10%, transparent);
|
|
375
|
+
color: var(--color-text-secondary, currentColor);
|
|
225
376
|
cursor: pointer;
|
|
226
|
-
|
|
227
|
-
transition: opacity var(--transition-fast);
|
|
228
|
-
font-family: var(--font-system);
|
|
377
|
+
transition: background var(--transition-fast), opacity var(--transition-fast);
|
|
229
378
|
}
|
|
230
379
|
|
|
231
380
|
.sheet-close-btn:hover {
|
|
232
|
-
|
|
381
|
+
background: color-mix(in srgb, currentColor 16%, transparent);
|
|
233
382
|
}
|
|
234
383
|
|
|
235
|
-
.sheet-close-btn
|
|
236
|
-
|
|
384
|
+
.sheet-close-btn:focus-visible {
|
|
385
|
+
/* Two tones, so the ring holds 3:1 on a dark or a light sheet. The inner
|
|
386
|
+
ring is the shadow hugging the button, the outer one the outline. */
|
|
387
|
+
outline: 2px solid var(--sheet-focus-ring-outer, #3b8eea);
|
|
388
|
+
outline-offset: 2px;
|
|
389
|
+
box-shadow: 0 0 0 2px var(--sheet-focus-ring-inner, #ffffff);
|
|
237
390
|
}
|
|
238
391
|
|
|
239
392
|
.sheet-title {
|
|
@@ -242,10 +395,11 @@
|
|
|
242
395
|
color: var(--color-text);
|
|
243
396
|
text-align: center;
|
|
244
397
|
font-family: var(--font-system);
|
|
398
|
+
margin: 0;
|
|
245
399
|
}
|
|
246
400
|
|
|
247
401
|
.sheet-spacer {
|
|
248
|
-
width:
|
|
402
|
+
width: 36px;
|
|
249
403
|
}
|
|
250
404
|
|
|
251
405
|
.sheet-content {
|
|
@@ -254,6 +408,19 @@
|
|
|
254
408
|
overflow-x: hidden;
|
|
255
409
|
-webkit-overflow-scrolling: touch;
|
|
256
410
|
font-family: var(--font-system);
|
|
411
|
+
/* Scrolled down, the content keeps every native pan; a pull down scrolls it
|
|
412
|
+
back up. */
|
|
413
|
+
touch-action: pan-x pan-y;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/* At the top, the browser keeps only the pan that scrolls the content down
|
|
417
|
+
(a finger moving up), so a finger moving down reaches the drag handlers
|
|
418
|
+
instead of becoming a pan and a pointercancel. Engines without directional
|
|
419
|
+
pans keep pan-x pan-y: the body scrolls, and touch drags use the handle. */
|
|
420
|
+
@supports (touch-action: pan-down) {
|
|
421
|
+
.sheet-content[data-scroll-at-top='true'] {
|
|
422
|
+
touch-action: pan-x pan-down;
|
|
423
|
+
}
|
|
257
424
|
}
|
|
258
425
|
|
|
259
426
|
@media (min-width: 769px) {
|