@capgo/capacitor-sheets 8.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +437 -0
- package/dist/angular/index.d.mts +114 -0
- package/dist/angular/index.d.ts +114 -0
- package/dist/angular/index.js +1890 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/angular/index.mjs +1863 -0
- package/dist/angular/index.mjs.map +1 -0
- package/dist/chunk-LAUTMWR7.mjs +261 -0
- package/dist/chunk-LAUTMWR7.mjs.map +1 -0
- package/dist/chunk-YBLI7KN6.mjs +1629 -0
- package/dist/chunk-YBLI7KN6.mjs.map +1 -0
- package/dist/components-4JACDCD4.mjs +48 -0
- package/dist/components-4JACDCD4.mjs.map +1 -0
- package/dist/index.d.mts +513 -0
- package/dist/index.d.ts +513 -0
- package/dist/index.js +2069 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +70 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +240 -0
- package/dist/react/index.d.ts +240 -0
- package/dist/react/index.js +1900 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +1871 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/solid/index.d.mts +114 -0
- package/dist/solid/index.d.ts +114 -0
- package/dist/solid/index.js +1890 -0
- package/dist/solid/index.js.map +1 -0
- package/dist/solid/index.mjs +1863 -0
- package/dist/solid/index.mjs.map +1 -0
- package/dist/styles-ZKNWSPZR.mjs +9 -0
- package/dist/styles-ZKNWSPZR.mjs.map +1 -0
- package/dist/svelte/index.d.mts +121 -0
- package/dist/svelte/index.d.ts +121 -0
- package/dist/svelte/index.js +1904 -0
- package/dist/svelte/index.js.map +1 -0
- package/dist/svelte/index.mjs +1876 -0
- package/dist/svelte/index.mjs.map +1 -0
- package/dist/vue/index.d.mts +114 -0
- package/dist/vue/index.d.ts +114 -0
- package/dist/vue/index.js +1890 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/index.mjs +1863 -0
- package/dist/vue/index.mjs.map +1 -0
- package/docs/demos/bottom-sheet.webp +0 -0
- package/docs/demos/card.webp +0 -0
- package/docs/demos/detached-sheet.webp +0 -0
- package/docs/demos/lightbox.webp +0 -0
- package/docs/demos/long-sheet.webp +0 -0
- package/docs/demos/page-from-bottom.webp +0 -0
- package/docs/demos/page.webp +0 -0
- package/docs/demos/parallax-page.webp +0 -0
- package/docs/demos/persistent-sheet-with-detent.webp +0 -0
- package/docs/demos/sheet-with-depth.webp +0 -0
- package/docs/demos/sheet-with-detent.webp +0 -0
- package/docs/demos/sheet-with-keyboard.webp +0 -0
- package/docs/demos/sheet-with-stacking.webp +0 -0
- package/docs/demos/sidebar.webp +0 -0
- package/docs/demos/toast.webp +0 -0
- package/docs/demos/top-sheet.webp +0 -0
- package/package.json +162 -0
|
@@ -0,0 +1,1890 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/solid/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
setupSheet: () => setupSheet
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/core/utils.ts
|
|
28
|
+
var focusableSelector = [
|
|
29
|
+
"a[href]",
|
|
30
|
+
"area[href]",
|
|
31
|
+
"button:not([disabled])",
|
|
32
|
+
'input:not([disabled]):not([type="hidden"])',
|
|
33
|
+
"select:not([disabled])",
|
|
34
|
+
"textarea:not([disabled])",
|
|
35
|
+
"iframe",
|
|
36
|
+
"object",
|
|
37
|
+
"embed",
|
|
38
|
+
"[contenteditable]",
|
|
39
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
40
|
+
"cap-sheet-handle",
|
|
41
|
+
"cap-sheet-trigger"
|
|
42
|
+
].join(",");
|
|
43
|
+
function clamp(value, min, max) {
|
|
44
|
+
return Math.min(Math.max(value, min), max);
|
|
45
|
+
}
|
|
46
|
+
function parseBoolean(value, defaultValue) {
|
|
47
|
+
if (value === null) return defaultValue;
|
|
48
|
+
if (value === "" || value === "true") return true;
|
|
49
|
+
if (value === "false") return false;
|
|
50
|
+
return defaultValue;
|
|
51
|
+
}
|
|
52
|
+
function parseList(value) {
|
|
53
|
+
return value ? value.split(/[,\s]+/).map((item) => item.trim()).filter(Boolean) : [];
|
|
54
|
+
}
|
|
55
|
+
function parseTracks(value, fallback) {
|
|
56
|
+
const tracks = parseList(value).filter(
|
|
57
|
+
(item) => ["top", "bottom", "left", "right"].includes(item)
|
|
58
|
+
);
|
|
59
|
+
return tracks.length > 0 ? tracks : [fallback];
|
|
60
|
+
}
|
|
61
|
+
function parsePlacement(value) {
|
|
62
|
+
return ["top", "bottom", "left", "right", "center"].includes(value || "") ? value : "bottom";
|
|
63
|
+
}
|
|
64
|
+
function trackForPlacement(placement, tracks) {
|
|
65
|
+
if (placement !== "center" && tracks.includes(placement)) return placement;
|
|
66
|
+
return tracks[0] || (placement === "center" ? "bottom" : placement);
|
|
67
|
+
}
|
|
68
|
+
function isVerticalTrack(track) {
|
|
69
|
+
return track === "top" || track === "bottom";
|
|
70
|
+
}
|
|
71
|
+
function trackSign(track) {
|
|
72
|
+
return track === "bottom" || track === "right" ? 1 : -1;
|
|
73
|
+
}
|
|
74
|
+
function getEmPx(element) {
|
|
75
|
+
if (!element?.ownerDocument.defaultView) return 16;
|
|
76
|
+
const fontSize = element.ownerDocument.defaultView.getComputedStyle(element).fontSize;
|
|
77
|
+
const parsed = Number.parseFloat(fontSize);
|
|
78
|
+
return Number.isFinite(parsed) && parsed > 0 ? parsed : 16;
|
|
79
|
+
}
|
|
80
|
+
function toEm(element, value) {
|
|
81
|
+
return value / getEmPx(element);
|
|
82
|
+
}
|
|
83
|
+
function measureCssLength(length, context, axis) {
|
|
84
|
+
const doc = context.ownerDocument;
|
|
85
|
+
const probe = doc.createElement("div");
|
|
86
|
+
probe.style.position = "absolute";
|
|
87
|
+
probe.style.visibility = "hidden";
|
|
88
|
+
probe.style.pointerEvents = "none";
|
|
89
|
+
probe.style.inset = "0";
|
|
90
|
+
if (axis === "x") {
|
|
91
|
+
probe.style.width = length;
|
|
92
|
+
probe.style.height = "0";
|
|
93
|
+
} else {
|
|
94
|
+
probe.style.height = length;
|
|
95
|
+
probe.style.width = "0";
|
|
96
|
+
}
|
|
97
|
+
context.appendChild(probe);
|
|
98
|
+
const rect = probe.getBoundingClientRect();
|
|
99
|
+
probe.remove();
|
|
100
|
+
return axis === "x" ? rect.width : rect.height;
|
|
101
|
+
}
|
|
102
|
+
function getFocusable(container) {
|
|
103
|
+
return Array.from(container.querySelectorAll(focusableSelector)).filter((element) => {
|
|
104
|
+
if (element.hasAttribute("disabled")) return false;
|
|
105
|
+
if (element.getAttribute("aria-hidden") === "true") return false;
|
|
106
|
+
const rects = element.getClientRects();
|
|
107
|
+
return rects.length > 0;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function dispatch(target, type, detail) {
|
|
111
|
+
target.dispatchEvent(new CustomEvent(type, { bubbles: true, composed: true, detail }));
|
|
112
|
+
}
|
|
113
|
+
function defineElement(name, constructor) {
|
|
114
|
+
if (typeof customElements === "undefined") return;
|
|
115
|
+
if (!customElements.get(name)) {
|
|
116
|
+
customElements.define(name, constructor);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function shouldSkipMotion(settingsSkip) {
|
|
120
|
+
if (settingsSkip === true) return true;
|
|
121
|
+
if (settingsSkip === "auto" && typeof matchMedia !== "undefined") {
|
|
122
|
+
return matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
function createId(prefix) {
|
|
127
|
+
return `${prefix}-${Math.random().toString(36).slice(2, 10)}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/core/styles.ts
|
|
131
|
+
var STYLE_ID = "capgo-capacitor-sheets-styles";
|
|
132
|
+
var CSS = `
|
|
133
|
+
:root {
|
|
134
|
+
--cap-sheet-100-lvh-dvh-pct: max(100%, 100vh);
|
|
135
|
+
--cap-sheet-backdrop-color: rgb(0 0 0);
|
|
136
|
+
--cap-sheet-backdrop-opacity: 0.44;
|
|
137
|
+
--cap-sheet-radius: 1.5em;
|
|
138
|
+
--cap-sheet-handle-color: rgb(115 115 115);
|
|
139
|
+
--cap-sheet-surface: Canvas;
|
|
140
|
+
--cap-sheet-shadow: 0 0.5em 2.5em rgb(0 0 0 / 0.18);
|
|
141
|
+
--cap-sheet-z-index: 1000;
|
|
142
|
+
--cap-sheet-safe-area-top: max(env(safe-area-inset-top, 0em), var(--safe-area-inset-top, 0em));
|
|
143
|
+
--cap-sheet-safe-area-bottom: max(env(safe-area-inset-bottom, 0em), var(--safe-area-inset-bottom, 0em));
|
|
144
|
+
--cap-sheet-safe-area-left: max(env(safe-area-inset-left, 0em), var(--safe-area-inset-left, 0em));
|
|
145
|
+
--cap-sheet-safe-area-right: max(env(safe-area-inset-right, 0em), var(--safe-area-inset-right, 0em));
|
|
146
|
+
--cap-sheet-applied-safe-area-top: var(--cap-sheet-safe-area-top);
|
|
147
|
+
--cap-sheet-applied-safe-area-bottom: var(--cap-sheet-safe-area-bottom);
|
|
148
|
+
--cap-sheet-applied-safe-area-left: var(--cap-sheet-safe-area-left);
|
|
149
|
+
--cap-sheet-applied-safe-area-right: var(--cap-sheet-safe-area-right);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@supports (height: 1dvh) {
|
|
153
|
+
:root {
|
|
154
|
+
--cap-sheet-100-lvh-dvh-pct: max(100dvh, 100lvh);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
cap-sheet,
|
|
159
|
+
cap-sheet-portal,
|
|
160
|
+
cap-sheet-special-wrapper,
|
|
161
|
+
cap-sheet-special-wrapper-content,
|
|
162
|
+
cap-sheet-stack {
|
|
163
|
+
display: contents;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
cap-sheet-view {
|
|
167
|
+
position: fixed;
|
|
168
|
+
inset: 0;
|
|
169
|
+
display: grid;
|
|
170
|
+
width: 100%;
|
|
171
|
+
height: var(--cap-sheet-100-lvh-dvh-pct);
|
|
172
|
+
z-index: var(--cap-sheet-z-index);
|
|
173
|
+
pointer-events: none;
|
|
174
|
+
touch-action: none;
|
|
175
|
+
overscroll-behavior: none;
|
|
176
|
+
contain: layout style;
|
|
177
|
+
box-sizing: border-box;
|
|
178
|
+
padding-block-start: var(--cap-sheet-applied-safe-area-top, 0em);
|
|
179
|
+
padding-block-end: calc(var(--cap-sheet-applied-safe-area-bottom, 0em) + var(--cap-sheet-keyboard-offset, 0em));
|
|
180
|
+
padding-inline-start: var(--cap-sheet-applied-safe-area-left, 0em);
|
|
181
|
+
padding-inline-end: var(--cap-sheet-applied-safe-area-right, 0em);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
cap-sheet-view[hidden] {
|
|
185
|
+
display: none !important;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
cap-sheet-view[content-placement="top"] {
|
|
189
|
+
align-items: start;
|
|
190
|
+
justify-items: center;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
cap-sheet-view[content-placement="bottom"],
|
|
194
|
+
cap-sheet-view:not([content-placement]) {
|
|
195
|
+
align-items: end;
|
|
196
|
+
justify-items: center;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
cap-sheet-view[content-placement="left"] {
|
|
200
|
+
align-items: center;
|
|
201
|
+
justify-items: start;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
cap-sheet-view[content-placement="right"] {
|
|
205
|
+
align-items: center;
|
|
206
|
+
justify-items: end;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
cap-sheet-view[content-placement="center"] {
|
|
210
|
+
align-items: center;
|
|
211
|
+
justify-items: center;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
cap-sheet-backdrop {
|
|
215
|
+
position: absolute;
|
|
216
|
+
inset: 0;
|
|
217
|
+
display: block;
|
|
218
|
+
background: var(--cap-sheet-backdrop-color);
|
|
219
|
+
opacity: 0;
|
|
220
|
+
pointer-events: none;
|
|
221
|
+
touch-action: none;
|
|
222
|
+
will-change: opacity;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
cap-sheet-content {
|
|
226
|
+
box-sizing: border-box;
|
|
227
|
+
position: relative;
|
|
228
|
+
display: block;
|
|
229
|
+
width: min(100%, 34em);
|
|
230
|
+
max-height: 100%;
|
|
231
|
+
color: CanvasText;
|
|
232
|
+
background: var(--cap-sheet-surface);
|
|
233
|
+
border-radius: var(--cap-sheet-radius) var(--cap-sheet-radius) 0 0;
|
|
234
|
+
box-shadow: var(--cap-sheet-shadow);
|
|
235
|
+
overflow: auto;
|
|
236
|
+
overscroll-behavior: contain;
|
|
237
|
+
pointer-events: auto;
|
|
238
|
+
touch-action: pan-x pan-y;
|
|
239
|
+
will-change: transform, opacity;
|
|
240
|
+
-webkit-overflow-scrolling: touch;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
cap-sheet-view[content-placement="top"] cap-sheet-content {
|
|
244
|
+
border-radius: 0 0 var(--cap-sheet-radius) var(--cap-sheet-radius);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
cap-sheet-view[content-placement="left"] cap-sheet-content {
|
|
248
|
+
width: min(88%, 28em);
|
|
249
|
+
height: 100%;
|
|
250
|
+
max-height: 100%;
|
|
251
|
+
border-radius: 0 var(--cap-sheet-radius) var(--cap-sheet-radius) 0;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
cap-sheet-view[content-placement="right"] cap-sheet-content {
|
|
255
|
+
width: min(88%, 28em);
|
|
256
|
+
height: 100%;
|
|
257
|
+
max-height: 100%;
|
|
258
|
+
border-radius: var(--cap-sheet-radius) 0 0 var(--cap-sheet-radius);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
cap-sheet-view[content-placement="center"] cap-sheet-content {
|
|
262
|
+
width: min(90%, 30em);
|
|
263
|
+
max-height: min(90%, 42em);
|
|
264
|
+
border-radius: var(--cap-sheet-radius);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
cap-sheet-bleeding-background {
|
|
268
|
+
position: absolute;
|
|
269
|
+
inset: 0;
|
|
270
|
+
z-index: -1;
|
|
271
|
+
display: block;
|
|
272
|
+
background: var(--cap-sheet-surface);
|
|
273
|
+
border-radius: inherit;
|
|
274
|
+
pointer-events: none;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
cap-sheet-view[content-placement="bottom"] cap-sheet-bleeding-background,
|
|
278
|
+
cap-sheet-view:not([content-placement]) cap-sheet-bleeding-background {
|
|
279
|
+
inset-block-end: -8em;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
cap-sheet-view[content-placement="top"] cap-sheet-bleeding-background {
|
|
283
|
+
inset-block-start: -8em;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
cap-sheet-view[content-placement="left"] cap-sheet-bleeding-background {
|
|
287
|
+
inset-inline-start: -8em;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
cap-sheet-view[content-placement="right"] cap-sheet-bleeding-background {
|
|
291
|
+
inset-inline-end: -8em;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
cap-sheet-handle {
|
|
295
|
+
box-sizing: border-box;
|
|
296
|
+
display: grid;
|
|
297
|
+
place-items: center;
|
|
298
|
+
width: 100%;
|
|
299
|
+
height: 2.25em;
|
|
300
|
+
cursor: grab;
|
|
301
|
+
touch-action: none;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
cap-sheet-handle::before {
|
|
305
|
+
content: "";
|
|
306
|
+
display: block;
|
|
307
|
+
width: 2.75em;
|
|
308
|
+
height: 0.3125em;
|
|
309
|
+
border-radius: 999em;
|
|
310
|
+
background: var(--cap-sheet-handle-color);
|
|
311
|
+
opacity: 0.65;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
cap-sheet-handle:active {
|
|
315
|
+
cursor: grabbing;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
cap-sheet-title,
|
|
319
|
+
cap-sheet-description {
|
|
320
|
+
display: block;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
cap-sheet-outlet {
|
|
324
|
+
display: block;
|
|
325
|
+
transform-origin: center;
|
|
326
|
+
will-change: transform, opacity, filter;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
cap-scroll {
|
|
330
|
+
display: block;
|
|
331
|
+
overflow: auto;
|
|
332
|
+
overscroll-behavior: contain;
|
|
333
|
+
-webkit-overflow-scrolling: touch;
|
|
334
|
+
scroll-behavior: smooth;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
cap-scroll[axis="x"] {
|
|
338
|
+
overflow-x: auto;
|
|
339
|
+
overflow-y: hidden;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
cap-scroll[axis="y"],
|
|
343
|
+
cap-scroll:not([axis]) {
|
|
344
|
+
overflow-x: hidden;
|
|
345
|
+
overflow-y: auto;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
cap-scroll-content {
|
|
349
|
+
display: block;
|
|
350
|
+
min-width: 100%;
|
|
351
|
+
min-height: 100%;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
cap-fixed {
|
|
355
|
+
position: fixed;
|
|
356
|
+
inset-inline: 0;
|
|
357
|
+
z-index: calc(var(--cap-sheet-z-index) + 1);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
cap-island,
|
|
361
|
+
cap-external-overlay {
|
|
362
|
+
display: contents;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
cap-visually-hidden,
|
|
366
|
+
cap-auto-focus-target[hidden-target] {
|
|
367
|
+
position: absolute;
|
|
368
|
+
width: 0.0625em;
|
|
369
|
+
height: 0.0625em;
|
|
370
|
+
margin: -0.0625em;
|
|
371
|
+
overflow: hidden;
|
|
372
|
+
clip: rect(0 0 0 0);
|
|
373
|
+
white-space: nowrap;
|
|
374
|
+
border: 0;
|
|
375
|
+
padding: 0;
|
|
376
|
+
}
|
|
377
|
+
`;
|
|
378
|
+
function injectCapSheetStyles(root = document) {
|
|
379
|
+
if (root.getElementById(STYLE_ID)) return;
|
|
380
|
+
const style = root.createElement("style");
|
|
381
|
+
style.id = STYLE_ID;
|
|
382
|
+
style.textContent = CSS;
|
|
383
|
+
root.head.appendChild(style);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// src/components/cap-scroll.ts
|
|
387
|
+
var CapScroll = class extends HTMLElement {
|
|
388
|
+
scrollTarget = this;
|
|
389
|
+
connectedCallback() {
|
|
390
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
391
|
+
this.scrollTarget = this;
|
|
392
|
+
this.addEventListener("scroll", this.handleScroll, { passive: true });
|
|
393
|
+
}
|
|
394
|
+
disconnectedCallback() {
|
|
395
|
+
this.removeEventListener("scroll", this.handleScroll);
|
|
396
|
+
}
|
|
397
|
+
/** Return scroll progress from `0` to `1`. */
|
|
398
|
+
getProgress() {
|
|
399
|
+
return this.getAvailableDistance() === 0 ? 0 : clamp(this.getDistance() / this.getAvailableDistance(), 0, 1);
|
|
400
|
+
}
|
|
401
|
+
/** Return traveled distance in CSS pixels. */
|
|
402
|
+
getDistance() {
|
|
403
|
+
return this.axis === "x" ? this.scrollTarget.scrollLeft : this.scrollTarget.scrollTop;
|
|
404
|
+
}
|
|
405
|
+
/** Return available travel distance in CSS pixels. */
|
|
406
|
+
getAvailableDistance() {
|
|
407
|
+
return this.axis === "x" ? Math.max(0, this.scrollTarget.scrollWidth - this.scrollTarget.clientWidth) : Math.max(0, this.scrollTarget.scrollHeight - this.scrollTarget.clientHeight);
|
|
408
|
+
}
|
|
409
|
+
scrollTo(optionsOrX, y) {
|
|
410
|
+
if (typeof optionsOrX === "number") {
|
|
411
|
+
super.scrollTo(optionsOrX, y ?? 0);
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
if (!optionsOrX || "top" in optionsOrX || "left" in optionsOrX) {
|
|
415
|
+
super.scrollTo(optionsOrX);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const travelOptions = optionsOrX;
|
|
419
|
+
const distance = this.resolveDistance(travelOptions.progress, travelOptions.distance);
|
|
420
|
+
this.scrollTarget.scrollTo({
|
|
421
|
+
left: this.axis === "x" ? distance : void 0,
|
|
422
|
+
top: this.axis === "y" ? distance : void 0,
|
|
423
|
+
behavior: travelOptions.behavior
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
scrollBy(optionsOrX, y) {
|
|
427
|
+
if (typeof optionsOrX === "number") {
|
|
428
|
+
super.scrollBy(optionsOrX, y ?? 0);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
if (!optionsOrX || "top" in optionsOrX || "left" in optionsOrX) {
|
|
432
|
+
super.scrollBy(optionsOrX);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const travelOptions = optionsOrX;
|
|
436
|
+
const distance = this.resolveDistance(travelOptions.progress, travelOptions.distance);
|
|
437
|
+
this.scrollTarget.scrollBy({
|
|
438
|
+
left: this.axis === "x" ? distance : void 0,
|
|
439
|
+
top: this.axis === "y" ? distance : void 0,
|
|
440
|
+
behavior: travelOptions.behavior
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
get axis() {
|
|
444
|
+
return this.getAttribute("axis") === "x" ? "x" : "y";
|
|
445
|
+
}
|
|
446
|
+
resolveDistance(progress, distance) {
|
|
447
|
+
if (distance !== void 0) return distance;
|
|
448
|
+
return clamp(progress ?? 0, 0, 1) * this.getAvailableDistance();
|
|
449
|
+
}
|
|
450
|
+
handleScroll = () => {
|
|
451
|
+
dispatch(this, "cap-scroll", {
|
|
452
|
+
progress: this.getProgress(),
|
|
453
|
+
distance: this.getDistance(),
|
|
454
|
+
availableDistance: this.getAvailableDistance()
|
|
455
|
+
});
|
|
456
|
+
};
|
|
457
|
+
};
|
|
458
|
+
var CapScrollContent = class extends HTMLElement {
|
|
459
|
+
connectedCallback() {
|
|
460
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
// src/core/theme-color.ts
|
|
465
|
+
var baseThemeColor = null;
|
|
466
|
+
var activeDimmerCount = 0;
|
|
467
|
+
function getThemeMeta(documentRef) {
|
|
468
|
+
return documentRef.querySelector('meta[name="theme-color"]');
|
|
469
|
+
}
|
|
470
|
+
function parseHexColor(color) {
|
|
471
|
+
const normalized = color.trim().replace("#", "");
|
|
472
|
+
if (![3, 6].includes(normalized.length)) return null;
|
|
473
|
+
const expanded = normalized.length === 3 ? normalized.split("").map((char) => `${char}${char}`).join("") : normalized;
|
|
474
|
+
const value = Number.parseInt(expanded, 16);
|
|
475
|
+
if (!Number.isFinite(value)) return null;
|
|
476
|
+
return [value >> 16 & 255, value >> 8 & 255, value & 255];
|
|
477
|
+
}
|
|
478
|
+
function parseRgbColor(color) {
|
|
479
|
+
const match = color.match(/rgba?\(([^)]+)\)/i);
|
|
480
|
+
if (!match) return null;
|
|
481
|
+
const values = match[1].split(/[\s,/]+/).map((item) => Number.parseFloat(item)).filter((item) => Number.isFinite(item));
|
|
482
|
+
if (values.length < 3) return null;
|
|
483
|
+
return [values[0], values[1], values[2]];
|
|
484
|
+
}
|
|
485
|
+
function toHex(channel) {
|
|
486
|
+
return Math.round(channel).toString(16).padStart(2, "0");
|
|
487
|
+
}
|
|
488
|
+
function blend(base, overlay, alpha) {
|
|
489
|
+
const baseRgb = parseHexColor(base) || parseRgbColor(base);
|
|
490
|
+
const overlayRgb = parseHexColor(overlay) || parseRgbColor(overlay);
|
|
491
|
+
if (!baseRgb || !overlayRgb) return null;
|
|
492
|
+
const [r, g, b] = baseRgb.map((channel, index) => channel * (1 - alpha) + overlayRgb[index] * alpha);
|
|
493
|
+
return `#${toHex(r)}${toHex(g)}${toHex(b)}`;
|
|
494
|
+
}
|
|
495
|
+
function setThemeColorDimming(documentRef, alpha, overlayColor = "rgb(0 0 0)") {
|
|
496
|
+
const meta = getThemeMeta(documentRef);
|
|
497
|
+
if (!meta) return;
|
|
498
|
+
if (baseThemeColor === null) {
|
|
499
|
+
baseThemeColor = meta.content;
|
|
500
|
+
}
|
|
501
|
+
const next = blend(baseThemeColor, overlayColor, alpha);
|
|
502
|
+
if (next) {
|
|
503
|
+
meta.content = next;
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function retainThemeColorDimmer() {
|
|
507
|
+
activeDimmerCount += 1;
|
|
508
|
+
}
|
|
509
|
+
function releaseThemeColorDimmer(documentRef) {
|
|
510
|
+
activeDimmerCount = Math.max(0, activeDimmerCount - 1);
|
|
511
|
+
if (activeDimmerCount === 0 && baseThemeColor !== null) {
|
|
512
|
+
const meta = getThemeMeta(documentRef);
|
|
513
|
+
if (meta) {
|
|
514
|
+
meta.content = baseThemeColor;
|
|
515
|
+
}
|
|
516
|
+
baseThemeColor = null;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/core/sheet-controller.ts
|
|
521
|
+
var defaultOptions = {
|
|
522
|
+
contentPlacement: "bottom",
|
|
523
|
+
sheetRole: "dialog",
|
|
524
|
+
safeArea: "auto",
|
|
525
|
+
swipe: true,
|
|
526
|
+
swipeDismissal: true,
|
|
527
|
+
swipeOvershoot: true,
|
|
528
|
+
swipeTrap: true,
|
|
529
|
+
inertOutside: true,
|
|
530
|
+
nativeEdgeSwipePrevention: true,
|
|
531
|
+
nativeFocusScrollPrevention: true,
|
|
532
|
+
closeOnOutsideClick: true,
|
|
533
|
+
closeOnEscape: true,
|
|
534
|
+
focusTrap: true,
|
|
535
|
+
restoreFocus: true,
|
|
536
|
+
themeColorDimming: "auto"
|
|
537
|
+
};
|
|
538
|
+
var defaultAnimation = {
|
|
539
|
+
duration: 420,
|
|
540
|
+
easing: "cubic-bezier(0.22, 1, 0.36, 1)",
|
|
541
|
+
skip: "auto",
|
|
542
|
+
contentMove: true
|
|
543
|
+
};
|
|
544
|
+
var stackRegistry = /* @__PURE__ */ new Map();
|
|
545
|
+
function parseNumber(value) {
|
|
546
|
+
if (value === null) return void 0;
|
|
547
|
+
const parsed = Number.parseInt(value, 10);
|
|
548
|
+
return Number.isFinite(parsed) ? parsed : void 0;
|
|
549
|
+
}
|
|
550
|
+
function normalizeDetents(value) {
|
|
551
|
+
if (Array.isArray(value)) return value.filter(Boolean);
|
|
552
|
+
return parseList(value || null);
|
|
553
|
+
}
|
|
554
|
+
var safeAreaEdges = ["top", "bottom", "left", "right"];
|
|
555
|
+
function parseSafeArea(value) {
|
|
556
|
+
if (value === null) return void 0;
|
|
557
|
+
const normalized = value.trim().toLowerCase();
|
|
558
|
+
if (!normalized || normalized === "true" || normalized === "auto" || normalized === "all") return "auto";
|
|
559
|
+
if (normalized === "false" || normalized === "none" || normalized === "off") return "none";
|
|
560
|
+
const edges = parseList(normalized).filter(
|
|
561
|
+
(edge) => safeAreaEdges.includes(edge)
|
|
562
|
+
);
|
|
563
|
+
return edges.length > 0 ? edges : "auto";
|
|
564
|
+
}
|
|
565
|
+
function resolveSafeAreaEdges(value) {
|
|
566
|
+
if (value === false || value === "none") return [];
|
|
567
|
+
if (Array.isArray(value)) return value.filter((edge) => safeAreaEdges.includes(edge));
|
|
568
|
+
return safeAreaEdges;
|
|
569
|
+
}
|
|
570
|
+
function readOptionsFromElement(root) {
|
|
571
|
+
const placement = parsePlacement(root.getAttribute("content-placement"));
|
|
572
|
+
const defaultActiveDetent = parseNumber(root.getAttribute("default-active-detent"));
|
|
573
|
+
const activeDetent = parseNumber(root.getAttribute("active-detent"));
|
|
574
|
+
return {
|
|
575
|
+
componentId: root.getAttribute("component-id") || root.id || void 0,
|
|
576
|
+
stack: root.getAttribute("stack") || void 0,
|
|
577
|
+
defaultPresented: parseBoolean(root.getAttribute("default-presented"), false),
|
|
578
|
+
presented: root.hasAttribute("presented") ? parseBoolean(root.getAttribute("presented"), true) : void 0,
|
|
579
|
+
defaultActiveDetent,
|
|
580
|
+
activeDetent,
|
|
581
|
+
detents: normalizeDetents(root.getAttribute("detents") || void 0),
|
|
582
|
+
sheetRole: root.getAttribute("sheet-role") || defaultOptions.sheetRole,
|
|
583
|
+
contentPlacement: placement,
|
|
584
|
+
safeArea: parseSafeArea(root.getAttribute("safe-area")),
|
|
585
|
+
tracks: parseTracks(root.getAttribute("tracks"), placement === "center" ? "bottom" : placement),
|
|
586
|
+
swipe: parseBoolean(root.getAttribute("swipe"), defaultOptions.swipe),
|
|
587
|
+
swipeDismissal: parseBoolean(root.getAttribute("swipe-dismissal"), defaultOptions.swipeDismissal),
|
|
588
|
+
swipeOvershoot: parseBoolean(root.getAttribute("swipe-overshoot"), defaultOptions.swipeOvershoot),
|
|
589
|
+
swipeTrap: parseBoolean(root.getAttribute("swipe-trap"), defaultOptions.swipeTrap),
|
|
590
|
+
inertOutside: parseBoolean(root.getAttribute("inert-outside"), defaultOptions.inertOutside),
|
|
591
|
+
nativeEdgeSwipePrevention: parseBoolean(
|
|
592
|
+
root.getAttribute("native-edge-swipe-prevention"),
|
|
593
|
+
defaultOptions.nativeEdgeSwipePrevention
|
|
594
|
+
),
|
|
595
|
+
nativeFocusScrollPrevention: parseBoolean(
|
|
596
|
+
root.getAttribute("native-focus-scroll-prevention"),
|
|
597
|
+
defaultOptions.nativeFocusScrollPrevention
|
|
598
|
+
),
|
|
599
|
+
closeOnOutsideClick: parseBoolean(root.getAttribute("close-on-outside-click"), defaultOptions.closeOnOutsideClick),
|
|
600
|
+
closeOnEscape: parseBoolean(root.getAttribute("close-on-escape"), defaultOptions.closeOnEscape),
|
|
601
|
+
focusTrap: parseBoolean(root.getAttribute("focus-trap"), defaultOptions.focusTrap),
|
|
602
|
+
restoreFocus: parseBoolean(root.getAttribute("restore-focus"), defaultOptions.restoreFocus),
|
|
603
|
+
themeColorDimming: root.getAttribute("theme-color-dimming") === "false" ? false : root.getAttribute("theme-color-dimming") === "auto" ? "auto" : defaultOptions.themeColorDimming
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function resolveAnimation(settings) {
|
|
607
|
+
const preset = settings?.preset || "smooth";
|
|
608
|
+
const presetDefaults = {
|
|
609
|
+
gentle: { duration: 520, easing: "cubic-bezier(0.16, 1, 0.3, 1)" },
|
|
610
|
+
smooth: { duration: defaultAnimation.duration, easing: defaultAnimation.easing },
|
|
611
|
+
snappy: { duration: 260, easing: "cubic-bezier(0.2, 0, 0, 1)" }
|
|
612
|
+
};
|
|
613
|
+
return {
|
|
614
|
+
...defaultAnimation,
|
|
615
|
+
...presetDefaults[preset],
|
|
616
|
+
duration: settings?.duration ?? presetDefaults[preset]?.duration ?? defaultAnimation.duration,
|
|
617
|
+
easing: settings?.easing ?? presetDefaults[preset]?.easing ?? defaultAnimation.easing,
|
|
618
|
+
skip: settings?.skip ?? defaultAnimation.skip,
|
|
619
|
+
contentMove: settings?.contentMove ?? defaultAnimation.contentMove
|
|
620
|
+
};
|
|
621
|
+
}
|
|
622
|
+
function attributeBoolean(value) {
|
|
623
|
+
return value ? "true" : "false";
|
|
624
|
+
}
|
|
625
|
+
var SheetController = class {
|
|
626
|
+
root;
|
|
627
|
+
id;
|
|
628
|
+
parts = {
|
|
629
|
+
outlets: /* @__PURE__ */ new Set(),
|
|
630
|
+
islands: /* @__PURE__ */ new Set(),
|
|
631
|
+
externalOverlays: /* @__PURE__ */ new Set()
|
|
632
|
+
};
|
|
633
|
+
options;
|
|
634
|
+
presented = false;
|
|
635
|
+
activeDetent = 0;
|
|
636
|
+
status = "idle";
|
|
637
|
+
detentOffsetsPx = [0, 0];
|
|
638
|
+
hiddenOffsetPx = 0;
|
|
639
|
+
currentOffsetPx = 0;
|
|
640
|
+
activeTrack = "bottom";
|
|
641
|
+
pointerTravel = null;
|
|
642
|
+
connected = false;
|
|
643
|
+
lockedScroll = false;
|
|
644
|
+
previousBodyOverflow = "";
|
|
645
|
+
previousBodyTouchAction = "";
|
|
646
|
+
inertedElements = /* @__PURE__ */ new Map();
|
|
647
|
+
previousFocus = null;
|
|
648
|
+
hasThemeDimmer = false;
|
|
649
|
+
stackId = null;
|
|
650
|
+
documentListenersAttached = false;
|
|
651
|
+
viewListenersElement = null;
|
|
652
|
+
visualViewportListenersAttached = false;
|
|
653
|
+
handleVisualViewportResize = () => {
|
|
654
|
+
const view = this.parts.view;
|
|
655
|
+
const visualViewport = this.root.ownerDocument.defaultView?.visualViewport;
|
|
656
|
+
if (!view) return;
|
|
657
|
+
if (!visualViewport || this.options.nativeFocusScrollPrevention === false) {
|
|
658
|
+
view.style.setProperty("--cap-sheet-keyboard-offset", "0em");
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
const layoutHeight = this.root.ownerDocument.documentElement.clientHeight;
|
|
662
|
+
const keyboardOffset = Math.max(0, layoutHeight - visualViewport.height - visualViewport.offsetTop);
|
|
663
|
+
view.style.setProperty("--cap-sheet-keyboard-offset", `${toEm(view, keyboardOffset)}em`);
|
|
664
|
+
};
|
|
665
|
+
handleDocumentKeyDown = (event) => {
|
|
666
|
+
if (!this.presented) return;
|
|
667
|
+
if (event.key === "Escape" && this.options.closeOnEscape !== false) {
|
|
668
|
+
event.preventDefault();
|
|
669
|
+
void this.dismiss({ source: "escape" });
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (event.key === "Tab" && this.options.focusTrap !== false) {
|
|
673
|
+
this.trapFocus(event);
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
handleViewClick = (event) => {
|
|
677
|
+
if (!this.presented || this.options.closeOnOutsideClick === false) return;
|
|
678
|
+
if (event.target === this.parts.view || event.target === this.parts.backdrop) {
|
|
679
|
+
void this.dismiss({ source: "outside" });
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
handlePointerDown = (event) => {
|
|
683
|
+
if (!this.presented || this.options.swipe === false || this.options.contentPlacement === "center") return;
|
|
684
|
+
if (!(event.target instanceof Element)) return;
|
|
685
|
+
if (!this.parts.content?.contains(event.target) && event.target !== this.parts.backdrop) return;
|
|
686
|
+
if (this.options.nativeEdgeSwipePrevention !== false && this.isNativeEdgePointer(event)) {
|
|
687
|
+
event.preventDefault();
|
|
688
|
+
}
|
|
689
|
+
this.remeasure();
|
|
690
|
+
this.pointerTravel = {
|
|
691
|
+
id: event.pointerId,
|
|
692
|
+
startOffsetPx: this.currentOffsetPx,
|
|
693
|
+
startX: event.clientX,
|
|
694
|
+
startY: event.clientY,
|
|
695
|
+
lastX: event.clientX,
|
|
696
|
+
lastY: event.clientY,
|
|
697
|
+
lastTime: performance.now(),
|
|
698
|
+
velocity: 0,
|
|
699
|
+
dragging: false
|
|
700
|
+
};
|
|
701
|
+
};
|
|
702
|
+
handlePointerMove = (event) => {
|
|
703
|
+
const travel = this.pointerTravel;
|
|
704
|
+
if (travel?.id !== event.pointerId) return;
|
|
705
|
+
const axis = isVerticalTrack(this.activeTrack) ? "y" : "x";
|
|
706
|
+
const current = axis === "y" ? event.clientY : event.clientX;
|
|
707
|
+
const start = axis === "y" ? travel.startY : travel.startX;
|
|
708
|
+
const delta = current - start;
|
|
709
|
+
const crossDelta = axis === "y" ? event.clientX - travel.startX : event.clientY - travel.startY;
|
|
710
|
+
if (!travel.dragging) {
|
|
711
|
+
if (Math.abs(delta) < 6 || Math.abs(crossDelta) > Math.abs(delta) * 1.25) return;
|
|
712
|
+
travel.dragging = true;
|
|
713
|
+
event.currentTarget?.setPointerCapture?.(event.pointerId);
|
|
714
|
+
this.setStatus("dragging");
|
|
715
|
+
dispatch(this.root, "cap-sheet-drag-start", this.getTravelEvent());
|
|
716
|
+
}
|
|
717
|
+
if (this.options.swipeTrap !== false) {
|
|
718
|
+
event.preventDefault();
|
|
719
|
+
}
|
|
720
|
+
const now = performance.now();
|
|
721
|
+
const previous = axis === "y" ? travel.lastY : travel.lastX;
|
|
722
|
+
const elapsed = Math.max(now - travel.lastTime, 1);
|
|
723
|
+
travel.velocity = (current - previous) / elapsed * 1e3;
|
|
724
|
+
travel.lastX = event.clientX;
|
|
725
|
+
travel.lastY = event.clientY;
|
|
726
|
+
travel.lastTime = now;
|
|
727
|
+
const nextOffset = this.limitOffset(travel.startOffsetPx + delta);
|
|
728
|
+
this.applyOffset(nextOffset, "dragging");
|
|
729
|
+
};
|
|
730
|
+
handlePointerUp = (event) => {
|
|
731
|
+
const travel = this.pointerTravel;
|
|
732
|
+
if (travel?.id !== event.pointerId) return;
|
|
733
|
+
const currentTarget = event.currentTarget;
|
|
734
|
+
if (currentTarget?.hasPointerCapture?.(event.pointerId)) {
|
|
735
|
+
currentTarget.releasePointerCapture(event.pointerId);
|
|
736
|
+
}
|
|
737
|
+
this.pointerTravel = null;
|
|
738
|
+
if (!travel.dragging) return;
|
|
739
|
+
const nearest = this.nearestDetentForOffset(this.currentOffsetPx, travel.velocity);
|
|
740
|
+
dispatch(this.root, "cap-sheet-drag-end", this.getTravelEvent());
|
|
741
|
+
if (nearest === 0 && this.options.swipeDismissal !== false) {
|
|
742
|
+
void this.dismiss({ source: "gesture" });
|
|
743
|
+
return;
|
|
744
|
+
}
|
|
745
|
+
void this.stepTo(nearest, { source: "gesture" });
|
|
746
|
+
};
|
|
747
|
+
handleWheel = (event) => {
|
|
748
|
+
if (!this.presented || this.options.swipe === false || this.options.contentPlacement === "center") return;
|
|
749
|
+
if (!(event.target instanceof Element)) return;
|
|
750
|
+
if (!this.parts.content?.contains(event.target) && event.target !== this.parts.backdrop) return;
|
|
751
|
+
const delta = isVerticalTrack(this.activeTrack) ? event.deltaY : event.deltaX;
|
|
752
|
+
if (Math.abs(delta) < 1) return;
|
|
753
|
+
const nextOffset = this.limitOffset(this.currentOffsetPx + delta);
|
|
754
|
+
if (Math.abs(nextOffset - this.currentOffsetPx) < 0.5) return;
|
|
755
|
+
event.preventDefault();
|
|
756
|
+
this.applyOffset(nextOffset, "dragging");
|
|
757
|
+
window.clearTimeout(this.root.__capWheelSettle);
|
|
758
|
+
this.root.__capWheelSettle = window.setTimeout(() => {
|
|
759
|
+
const nearest = this.nearestDetentForOffset(this.currentOffsetPx, delta * 10);
|
|
760
|
+
if (nearest === 0 && this.options.swipeDismissal !== false) {
|
|
761
|
+
void this.dismiss({ source: "gesture" });
|
|
762
|
+
} else {
|
|
763
|
+
void this.stepTo(nearest, { source: "gesture" });
|
|
764
|
+
}
|
|
765
|
+
}, 120);
|
|
766
|
+
};
|
|
767
|
+
constructor(root) {
|
|
768
|
+
this.root = root;
|
|
769
|
+
this.options = readOptionsFromElement(root);
|
|
770
|
+
this.id = this.options.componentId || root.id || createId("cap-sheet");
|
|
771
|
+
if (!root.id) root.id = this.id;
|
|
772
|
+
}
|
|
773
|
+
/** Connect the controller to the DOM and initialize current state. */
|
|
774
|
+
connect() {
|
|
775
|
+
if (this.connected) return;
|
|
776
|
+
this.connected = true;
|
|
777
|
+
this.configure(readOptionsFromElement(this.root));
|
|
778
|
+
const nextPresented = this.options.presented ?? this.options.defaultPresented ?? false;
|
|
779
|
+
this.activeDetent = this.resolveInitialDetent();
|
|
780
|
+
this.presented = nextPresented;
|
|
781
|
+
this.setStatus("idle");
|
|
782
|
+
this.remeasure();
|
|
783
|
+
this.applyOffset(
|
|
784
|
+
nextPresented ? this.detentOffsetsPx[this.activeDetent] || 0 : this.detentOffsetsPx[0] || 0,
|
|
785
|
+
"idle"
|
|
786
|
+
);
|
|
787
|
+
this.updateDomState(false);
|
|
788
|
+
this.addGlobalListeners();
|
|
789
|
+
this.registerStack();
|
|
790
|
+
}
|
|
791
|
+
/** Disconnect listeners and restore outside DOM state. */
|
|
792
|
+
disconnect() {
|
|
793
|
+
this.connected = false;
|
|
794
|
+
this.removeGlobalListeners();
|
|
795
|
+
this.unlockPage();
|
|
796
|
+
this.clearInert();
|
|
797
|
+
this.releaseThemeDimmer();
|
|
798
|
+
this.unregisterStack();
|
|
799
|
+
}
|
|
800
|
+
/** Update options from attributes or setup helpers. */
|
|
801
|
+
configure(options) {
|
|
802
|
+
this.options = {
|
|
803
|
+
...defaultOptions,
|
|
804
|
+
...this.options,
|
|
805
|
+
...options,
|
|
806
|
+
detents: normalizeDetents(options.detents ?? this.options.detents)
|
|
807
|
+
};
|
|
808
|
+
const placement = this.options.contentPlacement || defaultOptions.contentPlacement;
|
|
809
|
+
const tracks = Array.isArray(this.options.tracks) ? this.options.tracks : this.options.tracks ? [this.options.tracks] : [placement === "center" ? "bottom" : placement];
|
|
810
|
+
this.activeTrack = trackForPlacement(placement, tracks);
|
|
811
|
+
this.parts.view?.setAttribute("content-placement", placement);
|
|
812
|
+
this.parts.view?.setAttribute("role", this.options.sheetRole || "dialog");
|
|
813
|
+
this.applySafeArea();
|
|
814
|
+
this.handleVisualViewportResize();
|
|
815
|
+
if (this.parts.content) {
|
|
816
|
+
this.parts.content.setAttribute("aria-modal", attributeBoolean(this.options.inertOutside !== false));
|
|
817
|
+
}
|
|
818
|
+
this.linkAccessibleNames();
|
|
819
|
+
this.registerStack();
|
|
820
|
+
}
|
|
821
|
+
/** Register a view, backdrop, content, or semantic part. */
|
|
822
|
+
registerPart(part, element) {
|
|
823
|
+
this.parts[part] = element;
|
|
824
|
+
this.configure(this.options);
|
|
825
|
+
if (this.connected && part === "view") {
|
|
826
|
+
this.addViewListeners();
|
|
827
|
+
this.addVisualViewportListeners();
|
|
828
|
+
this.handleVisualViewportResize();
|
|
829
|
+
}
|
|
830
|
+
this.remeasure();
|
|
831
|
+
this.applyOffset(
|
|
832
|
+
this.presented ? this.detentOffsetsPx[this.activeDetent] || 0 : this.detentOffsetsPx[0] || this.hiddenOffsetPx,
|
|
833
|
+
this.status
|
|
834
|
+
);
|
|
835
|
+
this.updateDomState(this.presented);
|
|
836
|
+
}
|
|
837
|
+
/** Unregister a view, backdrop, content, or semantic part. */
|
|
838
|
+
unregisterPart(part, element) {
|
|
839
|
+
if (this.parts[part] === element) {
|
|
840
|
+
if (part === "view") this.removeViewListeners();
|
|
841
|
+
this.parts[part] = void 0;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
/** Register an outlet animated by sheet progress. */
|
|
845
|
+
registerOutlet(element) {
|
|
846
|
+
this.parts.outlets.add(element);
|
|
847
|
+
this.updateOutletProgress();
|
|
848
|
+
}
|
|
849
|
+
/** Unregister an outlet. */
|
|
850
|
+
unregisterOutlet(element) {
|
|
851
|
+
this.parts.outlets.delete(element);
|
|
852
|
+
}
|
|
853
|
+
/** Register an outside island that remains interactive with inert outside enabled. */
|
|
854
|
+
registerIsland(element) {
|
|
855
|
+
this.parts.islands.add(element);
|
|
856
|
+
if (this.presented) this.applyInert();
|
|
857
|
+
}
|
|
858
|
+
/** Unregister an outside island. */
|
|
859
|
+
unregisterIsland(element) {
|
|
860
|
+
this.parts.islands.delete(element);
|
|
861
|
+
if (this.presented) this.applyInert();
|
|
862
|
+
}
|
|
863
|
+
/** Present the sheet. */
|
|
864
|
+
async present(options = {}) {
|
|
865
|
+
this.remeasure();
|
|
866
|
+
if (this.presented) {
|
|
867
|
+
await this.stepTo(options.detent ?? this.activeDetent, options);
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
this.previousFocus = this.root.ownerDocument.activeElement;
|
|
871
|
+
this.presented = true;
|
|
872
|
+
this.activeDetent = clamp(options.detent ?? this.resolveInitialDetent(), 1, this.detentOffsetsPx.length - 1);
|
|
873
|
+
this.updateDomState(true);
|
|
874
|
+
this.lockPage();
|
|
875
|
+
this.applyInert();
|
|
876
|
+
this.retainThemeDimmer();
|
|
877
|
+
this.setStatus("entering");
|
|
878
|
+
dispatch(this.root, "cap-sheet-present", this.getTravelEvent());
|
|
879
|
+
await this.animateTo(this.detentOffsetsPx[this.activeDetent] || 0, {
|
|
880
|
+
...this.options.enteringAnimationSettings || {},
|
|
881
|
+
...options.animation || {}
|
|
882
|
+
});
|
|
883
|
+
this.setStatus("idle");
|
|
884
|
+
this.focusInitialElement();
|
|
885
|
+
this.emitPresentedChange(true, options.source || "programmatic");
|
|
886
|
+
this.emitActiveDetentChange(this.activeDetent, 0);
|
|
887
|
+
this.updateStack();
|
|
888
|
+
}
|
|
889
|
+
/** Dismiss the sheet. */
|
|
890
|
+
async dismiss(options = {}) {
|
|
891
|
+
if (!this.presented) return;
|
|
892
|
+
this.remeasure();
|
|
893
|
+
const previous = this.activeDetent;
|
|
894
|
+
this.presented = false;
|
|
895
|
+
this.activeDetent = 0;
|
|
896
|
+
this.setStatus("exiting");
|
|
897
|
+
dispatch(this.root, "cap-sheet-dismiss", this.getTravelEvent());
|
|
898
|
+
await this.animateTo(this.detentOffsetsPx[0] || this.hiddenOffsetPx, {
|
|
899
|
+
...this.options.exitingAnimationSettings || {},
|
|
900
|
+
...options.animation || {}
|
|
901
|
+
});
|
|
902
|
+
this.setStatus("idle");
|
|
903
|
+
this.updateDomState(false);
|
|
904
|
+
this.unlockPage();
|
|
905
|
+
this.clearInert();
|
|
906
|
+
this.releaseThemeDimmer();
|
|
907
|
+
this.restoreFocus();
|
|
908
|
+
this.emitPresentedChange(false, options.source || "programmatic");
|
|
909
|
+
this.emitActiveDetentChange(0, previous);
|
|
910
|
+
this.updateStack();
|
|
911
|
+
}
|
|
912
|
+
/** Toggle presentation state. */
|
|
913
|
+
async toggle(options = {}) {
|
|
914
|
+
if (this.presented) {
|
|
915
|
+
await this.dismiss(options);
|
|
916
|
+
} else {
|
|
917
|
+
await this.present(options);
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
/** Step to a specific detent index. */
|
|
921
|
+
async stepTo(detent, options = {}) {
|
|
922
|
+
this.remeasure();
|
|
923
|
+
const target = clamp(detent, this.options.swipeDismissal === false ? 1 : 0, this.detentOffsetsPx.length - 1);
|
|
924
|
+
if (target === 0) {
|
|
925
|
+
await this.dismiss(options);
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if (!this.presented) {
|
|
929
|
+
await this.present({ ...options, detent: target });
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
const previous = this.activeDetent;
|
|
933
|
+
this.activeDetent = target;
|
|
934
|
+
this.setStatus("settling");
|
|
935
|
+
await this.animateTo(this.detentOffsetsPx[target] || 0, {
|
|
936
|
+
...this.options.steppingAnimationSettings || {},
|
|
937
|
+
...options.animation || {}
|
|
938
|
+
});
|
|
939
|
+
this.setStatus("idle");
|
|
940
|
+
if (previous !== target) {
|
|
941
|
+
this.emitActiveDetentChange(target, previous);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
/** Step up or down one detent. */
|
|
945
|
+
async step(direction = "up", options = {}) {
|
|
946
|
+
const delta = direction === "up" ? 1 : -1;
|
|
947
|
+
await this.stepTo(this.activeDetent + delta, options);
|
|
948
|
+
}
|
|
949
|
+
/** Recalculate content size and detent offsets. */
|
|
950
|
+
remeasure() {
|
|
951
|
+
const content = this.parts.content;
|
|
952
|
+
if (!content) return;
|
|
953
|
+
const placement = this.options.contentPlacement || "bottom";
|
|
954
|
+
if (placement === "center") {
|
|
955
|
+
this.hiddenOffsetPx = 0;
|
|
956
|
+
this.detentOffsetsPx = [0, 0];
|
|
957
|
+
return;
|
|
958
|
+
}
|
|
959
|
+
const view = this.parts.view;
|
|
960
|
+
const shouldMeasureHiddenView = Boolean(view?.hidden);
|
|
961
|
+
const previousVisibility = view?.style.visibility || "";
|
|
962
|
+
const previousPointerEvents = view?.style.pointerEvents || "";
|
|
963
|
+
if (view && shouldMeasureHiddenView) {
|
|
964
|
+
view.hidden = false;
|
|
965
|
+
view.style.visibility = "hidden";
|
|
966
|
+
view.style.pointerEvents = "none";
|
|
967
|
+
}
|
|
968
|
+
try {
|
|
969
|
+
const track = this.activeTrack;
|
|
970
|
+
const sign = trackSign(track);
|
|
971
|
+
const axis = isVerticalTrack(track) ? "y" : "x";
|
|
972
|
+
const rect = content.getBoundingClientRect();
|
|
973
|
+
const size = axis === "y" ? rect.height : rect.width;
|
|
974
|
+
this.hiddenOffsetPx = Math.max(size, 1) * sign;
|
|
975
|
+
const detents = normalizeDetents(this.options.detents);
|
|
976
|
+
const offsets = [this.hiddenOffsetPx];
|
|
977
|
+
for (const detent of detents) {
|
|
978
|
+
const visible = measureCssLength(detent, content, axis);
|
|
979
|
+
const offset = Math.max(Math.abs(this.hiddenOffsetPx) - visible, 0) * sign;
|
|
980
|
+
offsets.push(offset);
|
|
981
|
+
}
|
|
982
|
+
offsets.push(0);
|
|
983
|
+
this.detentOffsetsPx = offsets;
|
|
984
|
+
this.activeDetent = clamp(this.activeDetent, this.options.swipeDismissal === false ? 1 : 0, offsets.length - 1);
|
|
985
|
+
dispatch(this.root, "cap-sheet-travel-range-change", {
|
|
986
|
+
offsets: offsets.map((offset) => toEm(content, offset)),
|
|
987
|
+
count: offsets.length
|
|
988
|
+
});
|
|
989
|
+
} finally {
|
|
990
|
+
if (view && shouldMeasureHiddenView) {
|
|
991
|
+
view.hidden = true;
|
|
992
|
+
view.style.visibility = previousVisibility;
|
|
993
|
+
view.style.pointerEvents = previousPointerEvents;
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
/** Read current normalized travel details. */
|
|
998
|
+
getTravelEvent() {
|
|
999
|
+
const progress = this.getProgressForOffset(this.currentOffsetPx);
|
|
1000
|
+
return {
|
|
1001
|
+
progress,
|
|
1002
|
+
activeDetent: this.activeDetent,
|
|
1003
|
+
offset: toEm(this.parts.content || this.root, this.currentOffsetPx),
|
|
1004
|
+
status: this.status
|
|
1005
|
+
};
|
|
1006
|
+
}
|
|
1007
|
+
resolveInitialDetent() {
|
|
1008
|
+
const detents = normalizeDetents(this.options.detents);
|
|
1009
|
+
const last = detents.length + 1;
|
|
1010
|
+
const configured = this.options.activeDetent ?? this.options.defaultActiveDetent;
|
|
1011
|
+
if (configured !== void 0) return clamp(configured, 1, last);
|
|
1012
|
+
return detents.length > 0 ? 1 : last;
|
|
1013
|
+
}
|
|
1014
|
+
applyOffset(offsetPx, status) {
|
|
1015
|
+
this.currentOffsetPx = offsetPx;
|
|
1016
|
+
this.setStatus(status);
|
|
1017
|
+
const content = this.parts.content;
|
|
1018
|
+
const backdrop = this.parts.backdrop;
|
|
1019
|
+
const view = this.parts.view;
|
|
1020
|
+
const placement = this.options.contentPlacement || "bottom";
|
|
1021
|
+
const progress = this.getProgressForOffset(offsetPx);
|
|
1022
|
+
if (content) {
|
|
1023
|
+
if (placement === "center") {
|
|
1024
|
+
const scale = 0.96 + progress * 0.04;
|
|
1025
|
+
content.style.transform = `translate3d(0, 0, 0) scale(${scale})`;
|
|
1026
|
+
content.style.opacity = String(progress);
|
|
1027
|
+
} else {
|
|
1028
|
+
const offsetEm = toEm(content, offsetPx);
|
|
1029
|
+
const x = isVerticalTrack(this.activeTrack) ? "0" : `${offsetEm}em`;
|
|
1030
|
+
const y = isVerticalTrack(this.activeTrack) ? `${offsetEm}em` : "0";
|
|
1031
|
+
content.style.transform = `translate3d(${x}, ${y}, 0)`;
|
|
1032
|
+
content.style.opacity = "1";
|
|
1033
|
+
}
|
|
1034
|
+
}
|
|
1035
|
+
if (backdrop) {
|
|
1036
|
+
backdrop.style.opacity = String(
|
|
1037
|
+
progress * Number.parseFloat(getComputedStyle(backdrop).getPropertyValue("--cap-sheet-backdrop-opacity") || "0.44")
|
|
1038
|
+
);
|
|
1039
|
+
backdrop.style.pointerEvents = progress > 0.01 && !this.hasInteractiveOutside() ? "auto" : "none";
|
|
1040
|
+
}
|
|
1041
|
+
if (view) {
|
|
1042
|
+
view.style.pointerEvents = progress > 0.01 && !this.hasInteractiveOutside() ? "auto" : "none";
|
|
1043
|
+
view.dataset.presented = this.presented ? "true" : "false";
|
|
1044
|
+
view.dataset.status = status;
|
|
1045
|
+
view.dataset.outsideInteractive = this.hasInteractiveOutside() ? "true" : "false";
|
|
1046
|
+
}
|
|
1047
|
+
this.applyOutletAnimations(progress);
|
|
1048
|
+
this.updateThemeDimming(progress);
|
|
1049
|
+
dispatch(this.root, "cap-sheet-travel", this.getTravelEvent());
|
|
1050
|
+
}
|
|
1051
|
+
async animateTo(targetOffsetPx, settings) {
|
|
1052
|
+
const content = this.parts.content;
|
|
1053
|
+
const backdrop = this.parts.backdrop;
|
|
1054
|
+
const resolved = resolveAnimation(settings);
|
|
1055
|
+
if (!content || shouldSkipMotion(resolved.skip)) {
|
|
1056
|
+
this.applyOffset(targetOffsetPx, "idle");
|
|
1057
|
+
return;
|
|
1058
|
+
}
|
|
1059
|
+
const startOffset = this.currentOffsetPx;
|
|
1060
|
+
const fromProgress = this.getProgressForOffset(startOffset);
|
|
1061
|
+
const toProgress = this.getProgressForOffset(targetOffsetPx);
|
|
1062
|
+
const duration = Math.max(0, resolved.duration);
|
|
1063
|
+
const axis = isVerticalTrack(this.activeTrack) ? "y" : "x";
|
|
1064
|
+
const fromEm = toEm(content, startOffset);
|
|
1065
|
+
const targetEm = toEm(content, targetOffsetPx);
|
|
1066
|
+
const fromTransform = this.options.contentPlacement === "center" ? `translate3d(0, 0, 0) scale(${0.96 + fromProgress * 0.04})` : axis === "y" ? `translate3d(0, ${fromEm}em, 0)` : `translate3d(${fromEm}em, 0, 0)`;
|
|
1067
|
+
const toTransform = this.options.contentPlacement === "center" ? `translate3d(0, 0, 0) scale(${0.96 + toProgress * 0.04})` : axis === "y" ? `translate3d(0, ${targetEm}em, 0)` : `translate3d(${targetEm}em, 0, 0)`;
|
|
1068
|
+
const contentAnimation = resolved.contentMove ? content.animate(
|
|
1069
|
+
[
|
|
1070
|
+
{ transform: fromTransform, opacity: this.options.contentPlacement === "center" ? fromProgress : 1 },
|
|
1071
|
+
{ transform: toTransform, opacity: this.options.contentPlacement === "center" ? toProgress : 1 }
|
|
1072
|
+
],
|
|
1073
|
+
{ duration, easing: resolved.easing, fill: "both" }
|
|
1074
|
+
) : null;
|
|
1075
|
+
const backdropOpacity = backdrop ? Number.parseFloat(getComputedStyle(backdrop).getPropertyValue("--cap-sheet-backdrop-opacity") || "0.44") : 0;
|
|
1076
|
+
const backdropAnimation = backdrop?.animate(
|
|
1077
|
+
[{ opacity: fromProgress * backdropOpacity }, { opacity: toProgress * backdropOpacity }],
|
|
1078
|
+
{ duration, easing: resolved.easing, fill: "both" }
|
|
1079
|
+
);
|
|
1080
|
+
const started = performance.now();
|
|
1081
|
+
let frame;
|
|
1082
|
+
const tick = () => {
|
|
1083
|
+
const progress = duration === 0 ? 1 : clamp((performance.now() - started) / duration, 0, 1);
|
|
1084
|
+
const offset = startOffset + (targetOffsetPx - startOffset) * progress;
|
|
1085
|
+
this.currentOffsetPx = offset;
|
|
1086
|
+
this.applyOutletAnimations(this.getProgressForOffset(offset));
|
|
1087
|
+
this.updateThemeDimming(this.getProgressForOffset(offset));
|
|
1088
|
+
dispatch(this.root, "cap-sheet-travel", this.getTravelEvent());
|
|
1089
|
+
if (progress < 1) frame = requestAnimationFrame(tick);
|
|
1090
|
+
};
|
|
1091
|
+
frame = requestAnimationFrame(tick);
|
|
1092
|
+
await Promise.allSettled([
|
|
1093
|
+
contentAnimation?.finished,
|
|
1094
|
+
backdropAnimation ? backdropAnimation.finished : Promise.resolve()
|
|
1095
|
+
]);
|
|
1096
|
+
cancelAnimationFrame(frame);
|
|
1097
|
+
contentAnimation?.cancel();
|
|
1098
|
+
backdropAnimation?.cancel();
|
|
1099
|
+
this.applyOffset(targetOffsetPx, "idle");
|
|
1100
|
+
}
|
|
1101
|
+
getProgressForOffset(offsetPx) {
|
|
1102
|
+
if (this.options.contentPlacement === "center") {
|
|
1103
|
+
return this.presented ? 1 : 0;
|
|
1104
|
+
}
|
|
1105
|
+
const hidden = Math.abs(this.hiddenOffsetPx) || 1;
|
|
1106
|
+
return clamp(1 - Math.abs(offsetPx) / hidden, 0, 1);
|
|
1107
|
+
}
|
|
1108
|
+
limitOffset(offsetPx) {
|
|
1109
|
+
const sign = trackSign(this.activeTrack);
|
|
1110
|
+
const maxAbs = Math.abs(this.hiddenOffsetPx);
|
|
1111
|
+
const min = sign < 0 ? -maxAbs : 0;
|
|
1112
|
+
const max = sign < 0 ? 0 : maxAbs;
|
|
1113
|
+
if (this.options.swipeOvershoot === false) return clamp(offsetPx, min, max);
|
|
1114
|
+
if (offsetPx < min) return min + (offsetPx - min) * 0.18;
|
|
1115
|
+
if (offsetPx > max) return max + (offsetPx - max) * 0.18;
|
|
1116
|
+
return offsetPx;
|
|
1117
|
+
}
|
|
1118
|
+
nearestDetentForOffset(offsetPx, velocity) {
|
|
1119
|
+
const sign = trackSign(this.activeTrack);
|
|
1120
|
+
const fling = Math.abs(velocity) > 700 ? Math.sign(velocity) * sign : 0;
|
|
1121
|
+
if (fling > 0) return Math.max(0, this.activeDetent - 1);
|
|
1122
|
+
if (fling < 0) return Math.min(this.detentOffsetsPx.length - 1, this.activeDetent + 1);
|
|
1123
|
+
let nearest = 0;
|
|
1124
|
+
let nearestDistance = Number.POSITIVE_INFINITY;
|
|
1125
|
+
this.detentOffsetsPx.forEach((offset, index) => {
|
|
1126
|
+
if (index === 0 && this.options.swipeDismissal === false) return;
|
|
1127
|
+
const distance = Math.abs(offset - offsetPx);
|
|
1128
|
+
if (distance < nearestDistance) {
|
|
1129
|
+
nearest = index;
|
|
1130
|
+
nearestDistance = distance;
|
|
1131
|
+
}
|
|
1132
|
+
});
|
|
1133
|
+
return nearest;
|
|
1134
|
+
}
|
|
1135
|
+
hasInteractiveOutside() {
|
|
1136
|
+
return this.options.inertOutside === false && this.options.closeOnOutsideClick === false;
|
|
1137
|
+
}
|
|
1138
|
+
isNativeEdgePointer(event) {
|
|
1139
|
+
const view = this.parts.view;
|
|
1140
|
+
if (!view) return false;
|
|
1141
|
+
const rect = view.getBoundingClientRect();
|
|
1142
|
+
const edgeSize = Math.max(20, rect.width * 0.04);
|
|
1143
|
+
return event.clientX - rect.left <= edgeSize || rect.right - event.clientX <= edgeSize || event.clientY - rect.top <= edgeSize || rect.bottom - event.clientY <= edgeSize;
|
|
1144
|
+
}
|
|
1145
|
+
applySafeArea() {
|
|
1146
|
+
const view = this.parts.view;
|
|
1147
|
+
if (!view) return;
|
|
1148
|
+
const edges = new Set(resolveSafeAreaEdges(this.options.safeArea));
|
|
1149
|
+
view.dataset.safeArea = edges.size > 0 ? Array.from(edges).join(" ") : "none";
|
|
1150
|
+
for (const edge of safeAreaEdges) {
|
|
1151
|
+
view.style.setProperty(
|
|
1152
|
+
`--cap-sheet-applied-safe-area-${edge}`,
|
|
1153
|
+
edges.has(edge) ? `var(--cap-sheet-safe-area-${edge})` : "0em"
|
|
1154
|
+
);
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
addGlobalListeners() {
|
|
1158
|
+
const doc = this.root.ownerDocument;
|
|
1159
|
+
if (!this.documentListenersAttached) {
|
|
1160
|
+
doc.addEventListener("keydown", this.handleDocumentKeyDown);
|
|
1161
|
+
this.documentListenersAttached = true;
|
|
1162
|
+
}
|
|
1163
|
+
this.addViewListeners();
|
|
1164
|
+
this.addVisualViewportListeners();
|
|
1165
|
+
}
|
|
1166
|
+
removeGlobalListeners() {
|
|
1167
|
+
const doc = this.root.ownerDocument;
|
|
1168
|
+
if (this.documentListenersAttached) {
|
|
1169
|
+
doc.removeEventListener("keydown", this.handleDocumentKeyDown);
|
|
1170
|
+
this.documentListenersAttached = false;
|
|
1171
|
+
}
|
|
1172
|
+
this.removeViewListeners();
|
|
1173
|
+
this.removeVisualViewportListeners();
|
|
1174
|
+
}
|
|
1175
|
+
addViewListeners() {
|
|
1176
|
+
const view = this.parts.view;
|
|
1177
|
+
if (!view || this.viewListenersElement === view) return;
|
|
1178
|
+
this.removeViewListeners();
|
|
1179
|
+
view.addEventListener("click", this.handleViewClick);
|
|
1180
|
+
view.addEventListener("pointerdown", this.handlePointerDown);
|
|
1181
|
+
view.addEventListener("pointermove", this.handlePointerMove, { passive: false });
|
|
1182
|
+
view.addEventListener("pointerup", this.handlePointerUp);
|
|
1183
|
+
view.addEventListener("pointercancel", this.handlePointerUp);
|
|
1184
|
+
view.addEventListener("wheel", this.handleWheel, { passive: false });
|
|
1185
|
+
this.viewListenersElement = view;
|
|
1186
|
+
}
|
|
1187
|
+
removeViewListeners() {
|
|
1188
|
+
const view = this.viewListenersElement;
|
|
1189
|
+
if (!view) return;
|
|
1190
|
+
view.removeEventListener("click", this.handleViewClick);
|
|
1191
|
+
view.removeEventListener("pointerdown", this.handlePointerDown);
|
|
1192
|
+
view.removeEventListener("pointermove", this.handlePointerMove);
|
|
1193
|
+
view.removeEventListener("pointerup", this.handlePointerUp);
|
|
1194
|
+
view.removeEventListener("pointercancel", this.handlePointerUp);
|
|
1195
|
+
view.removeEventListener("wheel", this.handleWheel);
|
|
1196
|
+
this.viewListenersElement = null;
|
|
1197
|
+
}
|
|
1198
|
+
addVisualViewportListeners() {
|
|
1199
|
+
const visualViewport = this.root.ownerDocument.defaultView?.visualViewport;
|
|
1200
|
+
if (!visualViewport || this.visualViewportListenersAttached) return;
|
|
1201
|
+
visualViewport.addEventListener("resize", this.handleVisualViewportResize);
|
|
1202
|
+
visualViewport.addEventListener("scroll", this.handleVisualViewportResize);
|
|
1203
|
+
this.visualViewportListenersAttached = true;
|
|
1204
|
+
this.handleVisualViewportResize();
|
|
1205
|
+
}
|
|
1206
|
+
removeVisualViewportListeners() {
|
|
1207
|
+
const visualViewport = this.root.ownerDocument.defaultView?.visualViewport;
|
|
1208
|
+
if (!visualViewport || !this.visualViewportListenersAttached) return;
|
|
1209
|
+
visualViewport.removeEventListener("resize", this.handleVisualViewportResize);
|
|
1210
|
+
visualViewport.removeEventListener("scroll", this.handleVisualViewportResize);
|
|
1211
|
+
this.visualViewportListenersAttached = false;
|
|
1212
|
+
}
|
|
1213
|
+
updateDomState(presented) {
|
|
1214
|
+
const view = this.parts.view;
|
|
1215
|
+
const content = this.parts.content;
|
|
1216
|
+
if (view) {
|
|
1217
|
+
view.hidden = !presented && Math.abs(this.currentOffsetPx) === Math.abs(this.detentOffsetsPx[0] || 0);
|
|
1218
|
+
view.dataset.presented = presented ? "true" : "false";
|
|
1219
|
+
view.dataset.status = this.status;
|
|
1220
|
+
view.style.setProperty("--cap-sheet-z-index", String(this.getStackZIndex()));
|
|
1221
|
+
}
|
|
1222
|
+
if (content) {
|
|
1223
|
+
content.setAttribute("aria-hidden", attributeBoolean(!presented));
|
|
1224
|
+
content.setAttribute("tabindex", content.getAttribute("tabindex") || "-1");
|
|
1225
|
+
}
|
|
1226
|
+
this.root.toggleAttribute("presented", presented);
|
|
1227
|
+
}
|
|
1228
|
+
linkAccessibleNames() {
|
|
1229
|
+
if (!this.parts.content) return;
|
|
1230
|
+
if (this.parts.title) {
|
|
1231
|
+
if (!this.parts.title.id) this.parts.title.id = createId("cap-sheet-title");
|
|
1232
|
+
this.parts.content.setAttribute("aria-labelledby", this.parts.title.id);
|
|
1233
|
+
}
|
|
1234
|
+
if (this.parts.description) {
|
|
1235
|
+
if (!this.parts.description.id) this.parts.description.id = createId("cap-sheet-description");
|
|
1236
|
+
this.parts.content.setAttribute("aria-describedby", this.parts.description.id);
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
focusInitialElement() {
|
|
1240
|
+
const content = this.parts.content;
|
|
1241
|
+
if (!content) return;
|
|
1242
|
+
const target = this.parts.autoFocusTarget || content.querySelector("cap-auto-focus-target, [autofocus]");
|
|
1243
|
+
const focusable = target || getFocusable(content)[0] || content;
|
|
1244
|
+
requestAnimationFrame(() => focusable.focus({ preventScroll: this.options.nativeFocusScrollPrevention !== false }));
|
|
1245
|
+
}
|
|
1246
|
+
restoreFocus() {
|
|
1247
|
+
if (this.options.restoreFocus === false) return;
|
|
1248
|
+
if (this.previousFocus instanceof HTMLElement && this.previousFocus.isConnected) {
|
|
1249
|
+
this.previousFocus.focus({ preventScroll: true });
|
|
1250
|
+
}
|
|
1251
|
+
this.previousFocus = null;
|
|
1252
|
+
}
|
|
1253
|
+
trapFocus(event) {
|
|
1254
|
+
const content = this.parts.content;
|
|
1255
|
+
if (!content) return;
|
|
1256
|
+
const focusable = getFocusable(content);
|
|
1257
|
+
if (focusable.length === 0) {
|
|
1258
|
+
event.preventDefault();
|
|
1259
|
+
content.focus({ preventScroll: true });
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const first = focusable[0];
|
|
1263
|
+
const last = focusable[focusable.length - 1];
|
|
1264
|
+
const active = this.root.ownerDocument.activeElement;
|
|
1265
|
+
if (event.shiftKey && active === first) {
|
|
1266
|
+
event.preventDefault();
|
|
1267
|
+
last.focus({ preventScroll: true });
|
|
1268
|
+
} else if (!event.shiftKey && active === last) {
|
|
1269
|
+
event.preventDefault();
|
|
1270
|
+
first.focus({ preventScroll: true });
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
lockPage() {
|
|
1274
|
+
if (this.lockedScroll) return;
|
|
1275
|
+
const body = this.root.ownerDocument.body;
|
|
1276
|
+
this.previousBodyOverflow = body.style.overflow;
|
|
1277
|
+
this.previousBodyTouchAction = body.style.touchAction;
|
|
1278
|
+
body.dataset.capSheetScrollLocked = "true";
|
|
1279
|
+
body.style.overflow = "hidden";
|
|
1280
|
+
body.style.touchAction = "none";
|
|
1281
|
+
this.lockedScroll = true;
|
|
1282
|
+
}
|
|
1283
|
+
unlockPage() {
|
|
1284
|
+
if (!this.lockedScroll) return;
|
|
1285
|
+
const body = this.root.ownerDocument.body;
|
|
1286
|
+
delete body.dataset.capSheetScrollLocked;
|
|
1287
|
+
body.style.overflow = this.previousBodyOverflow;
|
|
1288
|
+
body.style.touchAction = this.previousBodyTouchAction;
|
|
1289
|
+
this.previousBodyOverflow = "";
|
|
1290
|
+
this.previousBodyTouchAction = "";
|
|
1291
|
+
this.lockedScroll = false;
|
|
1292
|
+
}
|
|
1293
|
+
applyInert() {
|
|
1294
|
+
if (this.options.inertOutside === false || !this.parts.view) return;
|
|
1295
|
+
const body = this.root.ownerDocument.body;
|
|
1296
|
+
const allowed = /* @__PURE__ */ new Set([this.parts.view, ...this.parts.islands, ...this.parts.externalOverlays]);
|
|
1297
|
+
this.clearInert();
|
|
1298
|
+
for (const child of Array.from(body.children)) {
|
|
1299
|
+
if (!(child instanceof HTMLElement)) continue;
|
|
1300
|
+
const isAllowed = Array.from(allowed).some((element) => child === element || child.contains(element));
|
|
1301
|
+
if (isAllowed) continue;
|
|
1302
|
+
this.inertedElements.set(child, child.getAttribute("aria-hidden"));
|
|
1303
|
+
child.inert = true;
|
|
1304
|
+
child.setAttribute("aria-hidden", "true");
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
clearInert() {
|
|
1308
|
+
for (const [element, ariaHidden] of this.inertedElements) {
|
|
1309
|
+
element.inert = false;
|
|
1310
|
+
if (ariaHidden === null) {
|
|
1311
|
+
element.removeAttribute("aria-hidden");
|
|
1312
|
+
} else {
|
|
1313
|
+
element.setAttribute("aria-hidden", ariaHidden);
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
this.inertedElements.clear();
|
|
1317
|
+
}
|
|
1318
|
+
retainThemeDimmer() {
|
|
1319
|
+
if (this.hasThemeDimmer || this.options.themeColorDimming !== "auto") return;
|
|
1320
|
+
this.hasThemeDimmer = true;
|
|
1321
|
+
retainThemeColorDimmer();
|
|
1322
|
+
}
|
|
1323
|
+
releaseThemeDimmer() {
|
|
1324
|
+
if (!this.hasThemeDimmer) return;
|
|
1325
|
+
this.hasThemeDimmer = false;
|
|
1326
|
+
releaseThemeColorDimmer(this.root.ownerDocument);
|
|
1327
|
+
}
|
|
1328
|
+
updateThemeDimming(progress) {
|
|
1329
|
+
if (!this.hasThemeDimmer || this.options.themeColorDimming !== "auto") return;
|
|
1330
|
+
const color = this.parts.backdrop ? getComputedStyle(this.parts.backdrop).getPropertyValue("--cap-sheet-backdrop-color") || "rgb(0 0 0)" : "rgb(0 0 0)";
|
|
1331
|
+
setThemeColorDimming(this.root.ownerDocument, clamp(progress * 0.44, 0, 0.7), color);
|
|
1332
|
+
}
|
|
1333
|
+
applyOutletAnimations(progress) {
|
|
1334
|
+
this.updateOutletProgress();
|
|
1335
|
+
for (const outlet of this.parts.outlets) {
|
|
1336
|
+
const animation = outlet.travelAnimation;
|
|
1337
|
+
if (!animation) continue;
|
|
1338
|
+
for (const [property, value] of Object.entries(animation)) {
|
|
1339
|
+
if (value === null || value === void 0) continue;
|
|
1340
|
+
if (Array.isArray(value)) {
|
|
1341
|
+
outlet.style.setProperty(property, tween(value[0], value[1], progress));
|
|
1342
|
+
} else if (typeof value === "function") {
|
|
1343
|
+
const next = value({ progress, tween: (start, end) => tween(start, end, progress) });
|
|
1344
|
+
if (next !== null && next !== void 0) outlet.style.setProperty(property, String(next));
|
|
1345
|
+
} else {
|
|
1346
|
+
outlet.style.setProperty(property, String(value));
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
updateOutletProgress() {
|
|
1352
|
+
const travel = this.getTravelEvent();
|
|
1353
|
+
for (const outlet of this.parts.outlets) {
|
|
1354
|
+
outlet.style.setProperty("--cap-sheet-progress", String(travel.progress));
|
|
1355
|
+
outlet.style.setProperty("--cap-sheet-offset", `${travel.offset}em`);
|
|
1356
|
+
outlet.dataset.sheetStatus = travel.status;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
emitPresentedChange(presented, source) {
|
|
1360
|
+
const detail = { presented, source };
|
|
1361
|
+
dispatch(this.root, "cap-sheet-presented-change", detail);
|
|
1362
|
+
}
|
|
1363
|
+
emitActiveDetentChange(activeDetent, previousActiveDetent) {
|
|
1364
|
+
const detail = { activeDetent, previousActiveDetent };
|
|
1365
|
+
dispatch(this.root, "cap-sheet-active-detent-change", detail);
|
|
1366
|
+
}
|
|
1367
|
+
registerStack() {
|
|
1368
|
+
const nextStack = this.options.stack || this.root.closest("cap-sheet-stack")?.id || null;
|
|
1369
|
+
if (this.stackId === nextStack) return;
|
|
1370
|
+
this.unregisterStack();
|
|
1371
|
+
this.stackId = nextStack;
|
|
1372
|
+
if (!nextStack) return;
|
|
1373
|
+
const stack = stackRegistry.get(nextStack) || /* @__PURE__ */ new Set();
|
|
1374
|
+
stack.add(this);
|
|
1375
|
+
stackRegistry.set(nextStack, stack);
|
|
1376
|
+
this.updateStack();
|
|
1377
|
+
}
|
|
1378
|
+
unregisterStack() {
|
|
1379
|
+
if (!this.stackId) return;
|
|
1380
|
+
const stack = stackRegistry.get(this.stackId);
|
|
1381
|
+
stack?.delete(this);
|
|
1382
|
+
if (stack?.size === 0) stackRegistry.delete(this.stackId);
|
|
1383
|
+
this.stackId = null;
|
|
1384
|
+
}
|
|
1385
|
+
getStackZIndex() {
|
|
1386
|
+
if (!this.stackId) return 1e3;
|
|
1387
|
+
const stack = Array.from(stackRegistry.get(this.stackId) || []);
|
|
1388
|
+
const index = stack.indexOf(this);
|
|
1389
|
+
return 1e3 + Math.max(index, 0) * 2;
|
|
1390
|
+
}
|
|
1391
|
+
updateStack() {
|
|
1392
|
+
if (!this.stackId) return;
|
|
1393
|
+
const stack = Array.from(stackRegistry.get(this.stackId) || []);
|
|
1394
|
+
const presented = stack.filter((controller) => controller.presented);
|
|
1395
|
+
stack.forEach((controller, index) => {
|
|
1396
|
+
controller.parts.view?.style.setProperty("--cap-sheet-z-index", String(1e3 + index * 2));
|
|
1397
|
+
const depth = presented.length - presented.indexOf(controller) - 1;
|
|
1398
|
+
const stackDepth = Math.max(depth, 0);
|
|
1399
|
+
controller.parts.content?.style.setProperty("--cap-sheet-stack-depth", String(stackDepth));
|
|
1400
|
+
controller.applyStackingAnimations(stackDepth);
|
|
1401
|
+
});
|
|
1402
|
+
}
|
|
1403
|
+
applyStackingAnimations(depth) {
|
|
1404
|
+
const progress = clamp(depth, 0, 4) / 4;
|
|
1405
|
+
for (const outlet of this.parts.outlets) {
|
|
1406
|
+
const animation = outlet.stackingAnimation;
|
|
1407
|
+
if (!animation) continue;
|
|
1408
|
+
for (const [property, value] of Object.entries(animation)) {
|
|
1409
|
+
if (value === null || value === void 0) continue;
|
|
1410
|
+
if (Array.isArray(value)) {
|
|
1411
|
+
outlet.style.setProperty(property, tween(value[0], value[1], progress));
|
|
1412
|
+
} else if (typeof value === "function") {
|
|
1413
|
+
const next = value({ progress, tween: (start, end) => tween(start, end, progress) });
|
|
1414
|
+
if (next !== null && next !== void 0) outlet.style.setProperty(property, String(next));
|
|
1415
|
+
} else {
|
|
1416
|
+
outlet.style.setProperty(property, String(value));
|
|
1417
|
+
}
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
setStatus(status) {
|
|
1422
|
+
if (this.status === status) return;
|
|
1423
|
+
const previousStatus = this.status;
|
|
1424
|
+
this.status = status;
|
|
1425
|
+
dispatch(this.root, "cap-sheet-travel-status-change", { previousStatus, status });
|
|
1426
|
+
}
|
|
1427
|
+
};
|
|
1428
|
+
function tween(start, end, progress) {
|
|
1429
|
+
const startString = String(start);
|
|
1430
|
+
const endString = String(end);
|
|
1431
|
+
const startValue = Number.parseFloat(startString);
|
|
1432
|
+
const endValue = Number.parseFloat(endString);
|
|
1433
|
+
if (!Number.isFinite(startValue) || !Number.isFinite(endValue)) return progress < 1 ? startString : endString;
|
|
1434
|
+
const unit = endString.replace(String(endValue), "") || startString.replace(String(startValue), "");
|
|
1435
|
+
const next = startValue + (endValue - startValue) * progress;
|
|
1436
|
+
return `${next}${unit}`;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// src/components/cap-sheet.ts
|
|
1440
|
+
var observed = [
|
|
1441
|
+
"active-detent",
|
|
1442
|
+
"close-on-escape",
|
|
1443
|
+
"close-on-outside-click",
|
|
1444
|
+
"content-placement",
|
|
1445
|
+
"default-active-detent",
|
|
1446
|
+
"default-presented",
|
|
1447
|
+
"detents",
|
|
1448
|
+
"focus-trap",
|
|
1449
|
+
"inert-outside",
|
|
1450
|
+
"native-edge-swipe-prevention",
|
|
1451
|
+
"native-focus-scroll-prevention",
|
|
1452
|
+
"presented",
|
|
1453
|
+
"restore-focus",
|
|
1454
|
+
"safe-area",
|
|
1455
|
+
"sheet-role",
|
|
1456
|
+
"stack",
|
|
1457
|
+
"swipe",
|
|
1458
|
+
"swipe-dismissal",
|
|
1459
|
+
"swipe-overshoot",
|
|
1460
|
+
"swipe-trap",
|
|
1461
|
+
"theme-color-dimming",
|
|
1462
|
+
"tracks"
|
|
1463
|
+
];
|
|
1464
|
+
var CapSheet = class extends HTMLElement {
|
|
1465
|
+
controller = new SheetController(this);
|
|
1466
|
+
syncingAttribute = false;
|
|
1467
|
+
static get observedAttributes() {
|
|
1468
|
+
return observed;
|
|
1469
|
+
}
|
|
1470
|
+
connectedCallback() {
|
|
1471
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1472
|
+
this.style.display ||= "contents";
|
|
1473
|
+
this.controller.connect();
|
|
1474
|
+
}
|
|
1475
|
+
disconnectedCallback() {
|
|
1476
|
+
this.controller.disconnect();
|
|
1477
|
+
}
|
|
1478
|
+
attributeChangedCallback() {
|
|
1479
|
+
if (this.syncingAttribute) return;
|
|
1480
|
+
this.controller.configure({});
|
|
1481
|
+
if (this.isConnected) {
|
|
1482
|
+
if (this.hasAttribute("presented") && !this.controller.presented) {
|
|
1483
|
+
void this.present({ source: "programmatic" });
|
|
1484
|
+
} else if (!this.hasAttribute("presented") && this.controller.presented) {
|
|
1485
|
+
void this.dismiss({ source: "programmatic" });
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
/** True when the sheet is currently presented. */
|
|
1490
|
+
get presented() {
|
|
1491
|
+
return this.controller.presented;
|
|
1492
|
+
}
|
|
1493
|
+
set presented(value) {
|
|
1494
|
+
if (value) {
|
|
1495
|
+
void this.present();
|
|
1496
|
+
} else {
|
|
1497
|
+
void this.dismiss();
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
/** Current active detent index. */
|
|
1501
|
+
get activeDetent() {
|
|
1502
|
+
return this.controller.activeDetent;
|
|
1503
|
+
}
|
|
1504
|
+
set activeDetent(value) {
|
|
1505
|
+
void this.stepTo(value);
|
|
1506
|
+
}
|
|
1507
|
+
/** Configure the sheet imperatively without depending on a framework adapter. */
|
|
1508
|
+
configure(options) {
|
|
1509
|
+
this.controller.configure(options);
|
|
1510
|
+
}
|
|
1511
|
+
/** Present the sheet. */
|
|
1512
|
+
async present(options = {}) {
|
|
1513
|
+
await this.controller.present(options);
|
|
1514
|
+
this.syncAttribute("presented", true);
|
|
1515
|
+
}
|
|
1516
|
+
/** Dismiss the sheet. */
|
|
1517
|
+
async dismiss(options = {}) {
|
|
1518
|
+
await this.controller.dismiss(options);
|
|
1519
|
+
this.syncAttribute("presented", false);
|
|
1520
|
+
}
|
|
1521
|
+
/** Toggle presentation state. */
|
|
1522
|
+
async toggle(options = {}) {
|
|
1523
|
+
if (this.presented) {
|
|
1524
|
+
await this.dismiss(options);
|
|
1525
|
+
} else {
|
|
1526
|
+
await this.present(options);
|
|
1527
|
+
}
|
|
1528
|
+
}
|
|
1529
|
+
/** Step to a specific detent index. */
|
|
1530
|
+
async stepTo(detent, options = {}) {
|
|
1531
|
+
await this.controller.stepTo(detent, options);
|
|
1532
|
+
if (this.controller.presented) this.syncAttribute("presented", true);
|
|
1533
|
+
}
|
|
1534
|
+
/** Step one detent up or down. */
|
|
1535
|
+
async step(direction = "up", options = {}) {
|
|
1536
|
+
await this.controller.step(direction, options);
|
|
1537
|
+
}
|
|
1538
|
+
syncAttribute(name, enabled) {
|
|
1539
|
+
this.syncingAttribute = true;
|
|
1540
|
+
this.toggleAttribute(name, enabled);
|
|
1541
|
+
this.syncingAttribute = false;
|
|
1542
|
+
}
|
|
1543
|
+
};
|
|
1544
|
+
function getSheetFromElement(element) {
|
|
1545
|
+
const explicitTarget = element.getAttribute("for");
|
|
1546
|
+
if (explicitTarget) {
|
|
1547
|
+
const found = element.ownerDocument.getElementById(explicitTarget);
|
|
1548
|
+
return isCapSheetElement(found) ? found : null;
|
|
1549
|
+
}
|
|
1550
|
+
const nearest = element.closest("cap-sheet");
|
|
1551
|
+
return isCapSheetElement(nearest) ? nearest : null;
|
|
1552
|
+
}
|
|
1553
|
+
function isCapSheetElement(element) {
|
|
1554
|
+
if (element?.localName !== "cap-sheet") return false;
|
|
1555
|
+
const candidate = element;
|
|
1556
|
+
return typeof candidate.present === "function" && typeof candidate.dismiss === "function";
|
|
1557
|
+
}
|
|
1558
|
+
function applySheetOptions(element, options) {
|
|
1559
|
+
if (options.contentPlacement) element.setAttribute("content-placement", options.contentPlacement);
|
|
1560
|
+
if (options.detents !== void 0) {
|
|
1561
|
+
element.setAttribute("detents", Array.isArray(options.detents) ? options.detents.join(" ") : options.detents);
|
|
1562
|
+
}
|
|
1563
|
+
if (options.activeDetent !== void 0) element.setAttribute("active-detent", String(options.activeDetent));
|
|
1564
|
+
if (options.defaultActiveDetent !== void 0) {
|
|
1565
|
+
element.setAttribute("default-active-detent", String(options.defaultActiveDetent));
|
|
1566
|
+
}
|
|
1567
|
+
if (options.defaultPresented !== void 0)
|
|
1568
|
+
element.setAttribute("default-presented", String(options.defaultPresented));
|
|
1569
|
+
if (options.presented !== void 0) element.toggleAttribute("presented", options.presented);
|
|
1570
|
+
if (options.sheetRole) element.setAttribute("sheet-role", options.sheetRole);
|
|
1571
|
+
if (options.safeArea !== void 0) {
|
|
1572
|
+
element.setAttribute(
|
|
1573
|
+
"safe-area",
|
|
1574
|
+
Array.isArray(options.safeArea) ? options.safeArea.join(" ") : String(options.safeArea)
|
|
1575
|
+
);
|
|
1576
|
+
}
|
|
1577
|
+
if (options.stack) element.setAttribute("stack", options.stack);
|
|
1578
|
+
if (options.tracks)
|
|
1579
|
+
element.setAttribute("tracks", Array.isArray(options.tracks) ? options.tracks.join(" ") : options.tracks);
|
|
1580
|
+
for (const [key, attr] of [
|
|
1581
|
+
["swipe", "swipe"],
|
|
1582
|
+
["swipeDismissal", "swipe-dismissal"],
|
|
1583
|
+
["swipeOvershoot", "swipe-overshoot"],
|
|
1584
|
+
["swipeTrap", "swipe-trap"],
|
|
1585
|
+
["inertOutside", "inert-outside"],
|
|
1586
|
+
["nativeEdgeSwipePrevention", "native-edge-swipe-prevention"],
|
|
1587
|
+
["nativeFocusScrollPrevention", "native-focus-scroll-prevention"],
|
|
1588
|
+
["closeOnOutsideClick", "close-on-outside-click"],
|
|
1589
|
+
["closeOnEscape", "close-on-escape"],
|
|
1590
|
+
["focusTrap", "focus-trap"],
|
|
1591
|
+
["restoreFocus", "restore-focus"]
|
|
1592
|
+
]) {
|
|
1593
|
+
const value = options[key];
|
|
1594
|
+
if (typeof value === "boolean") element.setAttribute(attr, String(value));
|
|
1595
|
+
}
|
|
1596
|
+
if (options.themeColorDimming !== void 0) {
|
|
1597
|
+
element.setAttribute("theme-color-dimming", options.themeColorDimming === false ? "false" : "auto");
|
|
1598
|
+
}
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
// src/components/sheet-actions.ts
|
|
1602
|
+
function normalizeAction(value, fallback) {
|
|
1603
|
+
return ["present", "dismiss", "toggle", "step"].includes(value || "") ? value : fallback;
|
|
1604
|
+
}
|
|
1605
|
+
async function runAction(element, fallback) {
|
|
1606
|
+
const sheet = getSheetFromElement(element);
|
|
1607
|
+
if (!sheet) return;
|
|
1608
|
+
const action = normalizeAction(element.getAttribute("action"), fallback);
|
|
1609
|
+
if (action === "present") {
|
|
1610
|
+
await sheet.present({ source: "trigger" });
|
|
1611
|
+
} else if (action === "dismiss") {
|
|
1612
|
+
await sheet.dismiss({ source: "trigger" });
|
|
1613
|
+
} else if (action === "step") {
|
|
1614
|
+
const detent = Number.parseInt(element.getAttribute("detent") || "", 10);
|
|
1615
|
+
if (Number.isFinite(detent)) {
|
|
1616
|
+
await sheet.stepTo(detent, { source: "trigger" });
|
|
1617
|
+
} else {
|
|
1618
|
+
await sheet.step(element.getAttribute("direction") || "up", { source: "trigger" });
|
|
1619
|
+
}
|
|
1620
|
+
} else {
|
|
1621
|
+
await sheet.toggle({ source: "trigger" });
|
|
1622
|
+
}
|
|
1623
|
+
}
|
|
1624
|
+
var CapSheetTrigger = class extends HTMLElement {
|
|
1625
|
+
connectedCallback() {
|
|
1626
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1627
|
+
this.role ||= "button";
|
|
1628
|
+
if (!this.hasAttribute("tabindex")) this.tabIndex = 0;
|
|
1629
|
+
this.addEventListener("click", this.handleClick);
|
|
1630
|
+
this.addEventListener("keydown", this.handleKeyDown);
|
|
1631
|
+
}
|
|
1632
|
+
disconnectedCallback() {
|
|
1633
|
+
this.removeEventListener("click", this.handleClick);
|
|
1634
|
+
this.removeEventListener("keydown", this.handleKeyDown);
|
|
1635
|
+
}
|
|
1636
|
+
handleClick = () => {
|
|
1637
|
+
void runAction(this, "toggle");
|
|
1638
|
+
};
|
|
1639
|
+
handleKeyDown = (event) => {
|
|
1640
|
+
if (event.key !== "Enter" && event.key !== " ") return;
|
|
1641
|
+
event.preventDefault();
|
|
1642
|
+
void runAction(this, "toggle");
|
|
1643
|
+
};
|
|
1644
|
+
};
|
|
1645
|
+
var CapSheetHandle = class extends HTMLElement {
|
|
1646
|
+
connectedCallback() {
|
|
1647
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1648
|
+
this.role ||= "button";
|
|
1649
|
+
if (!this.hasAttribute("tabindex")) this.tabIndex = 0;
|
|
1650
|
+
this.setAttribute("aria-label", this.getAttribute("aria-label") || "Move sheet");
|
|
1651
|
+
this.addEventListener("click", this.handleClick);
|
|
1652
|
+
this.addEventListener("keydown", this.handleKeyDown);
|
|
1653
|
+
}
|
|
1654
|
+
disconnectedCallback() {
|
|
1655
|
+
this.removeEventListener("click", this.handleClick);
|
|
1656
|
+
this.removeEventListener("keydown", this.handleKeyDown);
|
|
1657
|
+
}
|
|
1658
|
+
handleClick = () => {
|
|
1659
|
+
void runAction(this, "step");
|
|
1660
|
+
};
|
|
1661
|
+
handleKeyDown = (event) => {
|
|
1662
|
+
if (event.key === "ArrowUp") {
|
|
1663
|
+
event.preventDefault();
|
|
1664
|
+
this.setAttribute("direction", "up");
|
|
1665
|
+
void runAction(this, "step");
|
|
1666
|
+
}
|
|
1667
|
+
if (event.key === "ArrowDown") {
|
|
1668
|
+
event.preventDefault();
|
|
1669
|
+
this.setAttribute("direction", "down");
|
|
1670
|
+
void runAction(this, "step");
|
|
1671
|
+
}
|
|
1672
|
+
};
|
|
1673
|
+
};
|
|
1674
|
+
|
|
1675
|
+
// src/components/sheet-context.ts
|
|
1676
|
+
var CapSheetStack = class extends HTMLElement {
|
|
1677
|
+
connectedCallback() {
|
|
1678
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1679
|
+
this.style.display ||= "contents";
|
|
1680
|
+
if (!this.id) this.id = `cap-sheet-stack-${Math.random().toString(36).slice(2, 10)}`;
|
|
1681
|
+
}
|
|
1682
|
+
};
|
|
1683
|
+
var CapSheetOutlet = class extends HTMLElement {
|
|
1684
|
+
travelAnimation;
|
|
1685
|
+
stackingAnimation;
|
|
1686
|
+
connectedCallback() {
|
|
1687
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1688
|
+
getSheetFromElement(this)?.controller.registerOutlet(this);
|
|
1689
|
+
}
|
|
1690
|
+
disconnectedCallback() {
|
|
1691
|
+
getSheetFromElement(this)?.controller.unregisterOutlet(this);
|
|
1692
|
+
}
|
|
1693
|
+
};
|
|
1694
|
+
var CapSheetSpecialWrapper = class extends HTMLElement {
|
|
1695
|
+
connectedCallback() {
|
|
1696
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1697
|
+
this.style.display ||= "contents";
|
|
1698
|
+
}
|
|
1699
|
+
};
|
|
1700
|
+
var CapSheetSpecialWrapperContent = class extends HTMLElement {
|
|
1701
|
+
connectedCallback() {
|
|
1702
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1703
|
+
this.style.display ||= "contents";
|
|
1704
|
+
}
|
|
1705
|
+
};
|
|
1706
|
+
var CapIsland = class extends HTMLElement {
|
|
1707
|
+
connectedCallback() {
|
|
1708
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1709
|
+
getSheetFromElement(this)?.controller.registerIsland(this);
|
|
1710
|
+
}
|
|
1711
|
+
disconnectedCallback() {
|
|
1712
|
+
getSheetFromElement(this)?.controller.unregisterIsland(this);
|
|
1713
|
+
}
|
|
1714
|
+
};
|
|
1715
|
+
var CapExternalOverlay = class extends HTMLElement {
|
|
1716
|
+
registered = null;
|
|
1717
|
+
connectedCallback() {
|
|
1718
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1719
|
+
this.register();
|
|
1720
|
+
}
|
|
1721
|
+
disconnectedCallback() {
|
|
1722
|
+
this.unregister();
|
|
1723
|
+
}
|
|
1724
|
+
register() {
|
|
1725
|
+
const sheet = getSheetFromElement(this);
|
|
1726
|
+
if (!sheet) return;
|
|
1727
|
+
const selector = this.getAttribute("content-getter");
|
|
1728
|
+
const content = selector ? this.ownerDocument.querySelector(selector) : this;
|
|
1729
|
+
if (!content) return;
|
|
1730
|
+
this.registered = content;
|
|
1731
|
+
sheet.controller.registerIsland(content);
|
|
1732
|
+
}
|
|
1733
|
+
unregister() {
|
|
1734
|
+
const sheet = getSheetFromElement(this);
|
|
1735
|
+
if (sheet && this.registered) {
|
|
1736
|
+
sheet.controller.unregisterIsland(this.registered);
|
|
1737
|
+
}
|
|
1738
|
+
this.registered = null;
|
|
1739
|
+
}
|
|
1740
|
+
};
|
|
1741
|
+
var CapFixed = class extends HTMLElement {
|
|
1742
|
+
connectedCallback() {
|
|
1743
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1744
|
+
}
|
|
1745
|
+
};
|
|
1746
|
+
var CapVisuallyHidden = class extends HTMLElement {
|
|
1747
|
+
connectedCallback() {
|
|
1748
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
|
|
1752
|
+
// src/components/sheet-parts.ts
|
|
1753
|
+
var SheetPartElement = class extends HTMLElement {
|
|
1754
|
+
connectedCallback() {
|
|
1755
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1756
|
+
const sheet = getSheetFromElement(this);
|
|
1757
|
+
sheet?.controller.registerPart(this.partName, this);
|
|
1758
|
+
}
|
|
1759
|
+
disconnectedCallback() {
|
|
1760
|
+
const sheet = getSheetFromElement(this);
|
|
1761
|
+
sheet?.controller.unregisterPart(this.partName, this);
|
|
1762
|
+
}
|
|
1763
|
+
};
|
|
1764
|
+
var CapSheetView = class extends SheetPartElement {
|
|
1765
|
+
partName = "view";
|
|
1766
|
+
connectedCallback() {
|
|
1767
|
+
super.connectedCallback();
|
|
1768
|
+
const sheet = getSheetFromElement(this);
|
|
1769
|
+
const placement = this.getAttribute("content-placement") || sheet?.controller.options.contentPlacement || "bottom";
|
|
1770
|
+
this.setAttribute("content-placement", placement);
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
var CapSheetBackdrop = class extends SheetPartElement {
|
|
1774
|
+
partName = "backdrop";
|
|
1775
|
+
};
|
|
1776
|
+
var CapSheetContent = class extends SheetPartElement {
|
|
1777
|
+
partName = "content";
|
|
1778
|
+
connectedCallback() {
|
|
1779
|
+
super.connectedCallback();
|
|
1780
|
+
if (!this.hasAttribute("tabindex")) this.tabIndex = -1;
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
var CapSheetBleedingBackground = class extends HTMLElement {
|
|
1784
|
+
connectedCallback() {
|
|
1785
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
var CapSheetTitle = class extends SheetPartElement {
|
|
1789
|
+
partName = "title";
|
|
1790
|
+
connectedCallback() {
|
|
1791
|
+
if (!this.id) this.id = createId("cap-sheet-title");
|
|
1792
|
+
super.connectedCallback();
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
var CapSheetDescription = class extends SheetPartElement {
|
|
1796
|
+
partName = "description";
|
|
1797
|
+
connectedCallback() {
|
|
1798
|
+
if (!this.id) this.id = createId("cap-sheet-description");
|
|
1799
|
+
super.connectedCallback();
|
|
1800
|
+
}
|
|
1801
|
+
};
|
|
1802
|
+
var CapAutoFocusTarget = class extends SheetPartElement {
|
|
1803
|
+
partName = "autoFocusTarget";
|
|
1804
|
+
connectedCallback() {
|
|
1805
|
+
if (!this.hasAttribute("tabindex")) this.tabIndex = -1;
|
|
1806
|
+
super.connectedCallback();
|
|
1807
|
+
}
|
|
1808
|
+
};
|
|
1809
|
+
|
|
1810
|
+
// src/components/sheet-portal.ts
|
|
1811
|
+
var CapSheetPortal = class extends HTMLElement {
|
|
1812
|
+
host = null;
|
|
1813
|
+
connectedCallback() {
|
|
1814
|
+
injectCapSheetStyles(this.ownerDocument);
|
|
1815
|
+
this.style.display ||= "contents";
|
|
1816
|
+
if (this.hasAttribute("disabled")) return;
|
|
1817
|
+
const sheet = this.closest("cap-sheet");
|
|
1818
|
+
if (!sheet) return;
|
|
1819
|
+
if (!sheet.id) sheet.id = createId("cap-sheet");
|
|
1820
|
+
this.host = this.ownerDocument.createElement("div");
|
|
1821
|
+
this.host.dataset.capSheetPortal = sheet.id;
|
|
1822
|
+
this.host.style.display = "contents";
|
|
1823
|
+
for (const child of Array.from(this.children)) {
|
|
1824
|
+
if (child instanceof HTMLElement && !child.hasAttribute("for")) {
|
|
1825
|
+
child.setAttribute("for", sheet.id);
|
|
1826
|
+
for (const descendant of Array.from(
|
|
1827
|
+
child.querySelectorAll(
|
|
1828
|
+
"cap-sheet-view, cap-sheet-backdrop, cap-sheet-content, cap-sheet-title, cap-sheet-description, cap-sheet-trigger, cap-sheet-handle, cap-auto-focus-target"
|
|
1829
|
+
)
|
|
1830
|
+
)) {
|
|
1831
|
+
if (!descendant.hasAttribute("for")) descendant.setAttribute("for", sheet.id);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
this.host.appendChild(child);
|
|
1835
|
+
}
|
|
1836
|
+
this.ownerDocument.body.appendChild(this.host);
|
|
1837
|
+
}
|
|
1838
|
+
disconnectedCallback() {
|
|
1839
|
+
if (!this.host) return;
|
|
1840
|
+
for (const child of Array.from(this.host.children)) {
|
|
1841
|
+
this.appendChild(child);
|
|
1842
|
+
}
|
|
1843
|
+
this.host.remove();
|
|
1844
|
+
this.host = null;
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
|
|
1848
|
+
// src/components/index.ts
|
|
1849
|
+
defineElement("cap-sheet", CapSheet);
|
|
1850
|
+
defineElement("cap-sheet-trigger", CapSheetTrigger);
|
|
1851
|
+
defineElement("cap-sheet-portal", CapSheetPortal);
|
|
1852
|
+
defineElement("cap-sheet-view", CapSheetView);
|
|
1853
|
+
defineElement("cap-sheet-backdrop", CapSheetBackdrop);
|
|
1854
|
+
defineElement("cap-sheet-content", CapSheetContent);
|
|
1855
|
+
defineElement("cap-sheet-bleeding-background", CapSheetBleedingBackground);
|
|
1856
|
+
defineElement("cap-sheet-handle", CapSheetHandle);
|
|
1857
|
+
defineElement("cap-sheet-title", CapSheetTitle);
|
|
1858
|
+
defineElement("cap-sheet-description", CapSheetDescription);
|
|
1859
|
+
defineElement("cap-sheet-special-wrapper", CapSheetSpecialWrapper);
|
|
1860
|
+
defineElement("cap-sheet-special-wrapper-content", CapSheetSpecialWrapperContent);
|
|
1861
|
+
defineElement("cap-sheet-stack", CapSheetStack);
|
|
1862
|
+
defineElement("cap-sheet-outlet", CapSheetOutlet);
|
|
1863
|
+
defineElement("cap-scroll", CapScroll);
|
|
1864
|
+
defineElement("cap-scroll-content", CapScrollContent);
|
|
1865
|
+
defineElement("cap-fixed", CapFixed);
|
|
1866
|
+
defineElement("cap-island", CapIsland);
|
|
1867
|
+
defineElement("cap-external-overlay", CapExternalOverlay);
|
|
1868
|
+
defineElement("cap-visually-hidden", CapVisuallyHidden);
|
|
1869
|
+
defineElement("cap-auto-focus-target", CapAutoFocusTarget);
|
|
1870
|
+
|
|
1871
|
+
// src/solid/index.ts
|
|
1872
|
+
function setupSheet(element, options = {}) {
|
|
1873
|
+
applySheetOptions(element, options);
|
|
1874
|
+
const presented = (event) => options.onPresentedChange?.(event.detail);
|
|
1875
|
+
const detent = (event) => options.onActiveDetentChange?.(event.detail);
|
|
1876
|
+
const travel = (event) => options.onTravel?.(event.detail);
|
|
1877
|
+
element.addEventListener("cap-sheet-presented-change", presented);
|
|
1878
|
+
element.addEventListener("cap-sheet-active-detent-change", detent);
|
|
1879
|
+
element.addEventListener("cap-sheet-travel", travel);
|
|
1880
|
+
return () => {
|
|
1881
|
+
element.removeEventListener("cap-sheet-presented-change", presented);
|
|
1882
|
+
element.removeEventListener("cap-sheet-active-detent-change", detent);
|
|
1883
|
+
element.removeEventListener("cap-sheet-travel", travel);
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1887
|
+
0 && (module.exports = {
|
|
1888
|
+
setupSheet
|
|
1889
|
+
});
|
|
1890
|
+
//# sourceMappingURL=index.js.map
|