react-native-nitro-modal 0.1.5 → 0.2.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.
Files changed (57) hide show
  1. package/README.md +17 -7
  2. package/lib/module/NitroModal.js +1 -2
  3. package/lib/module/NitroModal.js.map +1 -1
  4. package/lib/module/NitroModalView.js +4 -3
  5. package/lib/module/NitroModalView.js.map +1 -1
  6. package/lib/module/NitroModalView.native.js +3 -0
  7. package/lib/module/NitroModalView.native.js.map +1 -1
  8. package/lib/module/NitroModalView.web.js +129 -0
  9. package/lib/module/NitroModalView.web.js.map +1 -0
  10. package/lib/module/web/AnimatedValue.js +123 -0
  11. package/lib/module/web/AnimatedValue.js.map +1 -0
  12. package/lib/module/web/ModalConfig.js +26 -0
  13. package/lib/module/web/ModalConfig.js.map +1 -0
  14. package/lib/module/web/ModalController.js +279 -0
  15. package/lib/module/web/ModalController.js.map +1 -0
  16. package/lib/module/web/ModalPresenter.js +245 -0
  17. package/lib/module/web/ModalPresenter.js.map +1 -0
  18. package/lib/module/web/PopupPresenter.js +117 -0
  19. package/lib/module/web/PopupPresenter.js.map +1 -0
  20. package/lib/module/web/SheetPresenter.js +469 -0
  21. package/lib/module/web/SheetPresenter.js.map +1 -0
  22. package/lib/module/web/dom.js +125 -0
  23. package/lib/module/web/dom.js.map +1 -0
  24. package/lib/typescript/src/NitroModal.d.ts +2 -2
  25. package/lib/typescript/src/NitroModal.d.ts.map +1 -1
  26. package/lib/typescript/src/NitroModalView.d.ts +2 -1
  27. package/lib/typescript/src/NitroModalView.d.ts.map +1 -1
  28. package/lib/typescript/src/NitroModalView.native.d.ts +1 -0
  29. package/lib/typescript/src/NitroModalView.native.d.ts.map +1 -1
  30. package/lib/typescript/src/NitroModalView.web.d.ts +6 -0
  31. package/lib/typescript/src/NitroModalView.web.d.ts.map +1 -0
  32. package/lib/typescript/src/web/AnimatedValue.d.ts +48 -0
  33. package/lib/typescript/src/web/AnimatedValue.d.ts.map +1 -0
  34. package/lib/typescript/src/web/ModalConfig.d.ts +24 -0
  35. package/lib/typescript/src/web/ModalConfig.d.ts.map +1 -0
  36. package/lib/typescript/src/web/ModalController.d.ts +65 -0
  37. package/lib/typescript/src/web/ModalController.d.ts.map +1 -0
  38. package/lib/typescript/src/web/ModalPresenter.d.ts +98 -0
  39. package/lib/typescript/src/web/ModalPresenter.d.ts.map +1 -0
  40. package/lib/typescript/src/web/PopupPresenter.d.ts +20 -0
  41. package/lib/typescript/src/web/PopupPresenter.d.ts.map +1 -0
  42. package/lib/typescript/src/web/SheetPresenter.d.ts +65 -0
  43. package/lib/typescript/src/web/SheetPresenter.d.ts.map +1 -0
  44. package/lib/typescript/src/web/dom.d.ts +40 -0
  45. package/lib/typescript/src/web/dom.d.ts.map +1 -0
  46. package/package.json +3 -2
  47. package/src/NitroModal.tsx +3 -4
  48. package/src/NitroModalView.native.tsx +4 -0
  49. package/src/NitroModalView.tsx +9 -4
  50. package/src/NitroModalView.web.tsx +138 -0
  51. package/src/web/AnimatedValue.ts +189 -0
  52. package/src/web/ModalConfig.ts +57 -0
  53. package/src/web/ModalController.ts +305 -0
  54. package/src/web/ModalPresenter.ts +298 -0
  55. package/src/web/PopupPresenter.ts +129 -0
  56. package/src/web/SheetPresenter.ts +582 -0
  57. package/src/web/dom.ts +154 -0
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AnimatedValue","INSTANT","prefersReducedMotion","ModalPresenter","MARGIN","DEFAULT_CORNER_RADIUS","ENTER_SCALE","ENTER","type","response","dampingRatio","EXIT","duration","easing","t","availableRect","viewport","insets","keyboardHeight","covered","Math","max","bottom","x","left","y","top","width","right","height","popupContentArea","PopupPresenter","progress","value","render","didShow","layout","set","animateIn","animateTo","isAnimated","onEnd","notifyPresented","animateOut","configDidChange","viewportDidChange","contentSizeDidChange","stopAnimations","stop","config","popupAnimation","surface","content","grabber","elements","behavior","keyboardBehavior","available","min","contentSize","Object","assign","style","borderRadius","cornerRadius","display","area","reportContentArea","backdrop","visible","animation","opacity","String","scale","transform"],"sourceRoot":"../../../src","sources":["web/PopupPresenter.ts"],"mappings":";;AAAA;;AAEA,SAASA,aAAa,EAAEC,OAAO,QAAqB,oBAAiB;AACrE,SAASC,oBAAoB,QAAgC,UAAO;AACpE,SAASC,cAAc,QAAQ,qBAAkB;AAEjD,MAAMC,MAAM,GAAG,EAAE;AACjB,MAAMC,qBAAqB,GAAG,EAAE;AAChC,MAAMC,WAAW,GAAG,GAAG;AAEvB,MAAMC,KAAa,GAAG;EAAEC,IAAI,EAAE,QAAQ;EAAEC,QAAQ,EAAE,GAAG;EAAEC,YAAY,EAAE;AAAK,CAAC;AAC3E,MAAMC,IAAY,GAAG;EAAEH,IAAI,EAAE,QAAQ;EAAEI,QAAQ,EAAE,GAAG;EAAEC,MAAM,EAAGC,CAAC,IAAKA,CAAC,GAAGA;AAAE,CAAC;AAO5E;AACA,SAASC,aAAaA,CACpBC,QAAc,EACdC,MAAc,EACdC,cAAsB,EAChB;EACN,MAAMC,OAAO,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEH,cAAc,GAAGD,MAAM,CAACK,MAAM,CAAC;EAC3D,OAAO;IACLC,CAAC,EAAEN,MAAM,CAACO,IAAI,GAAGpB,MAAM;IACvBqB,CAAC,EAAER,MAAM,CAACS,GAAG,GAAGtB,MAAM;IACtBuB,KAAK,EAAEP,IAAI,CAACC,GAAG,CACb,CAAC,EACDL,QAAQ,CAACW,KAAK,GAAGV,MAAM,CAACO,IAAI,GAAGP,MAAM,CAACW,KAAK,GAAG,CAAC,GAAGxB,MACpD,CAAC;IACDyB,MAAM,EAAET,IAAI,CAACC,GAAG,CACd,CAAC,EACDL,QAAQ,CAACa,MAAM,GAAGZ,MAAM,CAACS,GAAG,GAAGT,MAAM,CAACK,MAAM,GAAG,CAAC,GAAGlB,MAAM,GAAGe,OAC9D;EACF,CAAC;AACH;;AAEA;AACA,OAAO,SAASW,gBAAgBA,CAACd,QAAc,EAAEC,MAAc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AS,GACT1C,aAAa,CAAC,IAAI,CAACC,QAAQ,EAAE,IAAI,CAACC,MAAM,EAAE,CAAC,CAAC;IAClDmC,OAAO,CAACU,KAAK,CAACnC,KAAK,GAAG,GAAGuC,IAAI,CAACvC,KAAK,IAAI;IACvCyB,OAAO,CAACU,KAAK,CAACjC,MAAM,GAAG,GAAGqC,IAAI,CAACrC,MAAM,IAAI;IACzC,IAAI,CAACsC,iBAAiB,CAACD,IAAI,CAACvC,KAAK,EAAEuC,IAAI,CAACrC,MAAM,CAAC;EACjD;EAEQK,MAAMA,CAACF,QAAgB,EAAE;IAC/B,IAAI,CAAC,IAAI,CAACsB,QAAQ,EAAE;IACpB,MAAM;MAAEH,OAAO;MAAEiB;IAAS,CAAC,GAAG,IAAI,CAACd,QAAQ;IAC3C,MAAMe,OAAO,GAAGjD,IAAI,CAACsC,GAAG,CAACtC,IAAI,CAACC,GAAG,CAACW,QAAQ,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;IAClD,MAAMsC,SAAS,GAAG,IAAI,CAACrB,MAAM,CAACC,cAAc;IAC5CkB,QAAQ,CAACN,KAAK,CAACS,OAAO,GAAGC,MAAM,CAACH,OAAO,CAAC;IACxClB,OAAO,CAACW,KAAK,CAACS,OAAO,GAAGD,SAAS,KAAK,MAAM,GAAG,GAAG,GAAGE,MAAM,CAACH,OAAO,CAAC;IACpE,MAAMI,KAAK,GACTH,SAAS,KAAK,OAAO,GAAGhE,WAAW,GAAG,CAAC,CAAC,GAAGA,WAAW,IAAI0B,QAAQ,GAAG,CAAC;IACxEmB,OAAO,CAACW,KAAK,CAACY,SAAS,GAAG,SAASD,KAAK,GAAG;EAC7C;AACF","ignoreList":[]}
@@ -0,0 +1,469 @@
1
+ "use strict";
2
+
3
+ /// <reference lib="dom" />
4
+
5
+ import { AnimatedValue, INSTANT } from "./AnimatedValue.js";
6
+ import { findVerticalScroller, isTextInput, prefersReducedMotion, suppressNextClick } from "./dom.js";
7
+ import { ModalPresenter } from "./ModalPresenter.js";
8
+
9
+ /** Gap kept above the sheet at its tallest. */
10
+ const TOP_GAP = 10;
11
+ /**
12
+ * Extra sheet height below the viewport so it stays attached to the bottom
13
+ * edge while rubber-banding upward.
14
+ */
15
+ const OVERSCROLL = 400;
16
+ const DEFAULT_CORNER_RADIUS = 16;
17
+ const MAX_WIDTH = 640;
18
+ /** Mouse movement before a press turns into a drag. */
19
+ const POINTER_SLOP = 6;
20
+ /** Pointer samples used for the release velocity. */
21
+ const VELOCITY_WINDOW_MS = 100;
22
+ const ENTER = {
23
+ type: 'spring',
24
+ response: 0.4,
25
+ dampingRatio: 0.9
26
+ };
27
+ const SETTLE = {
28
+ type: 'spring',
29
+ response: 0.4,
30
+ dampingRatio: 0.9
31
+ };
32
+ /** Underdamped and stopped at the bottom edge, so the exit ends on a fast frame instead of a slow tail. */
33
+ const EXIT = {
34
+ type: 'spring',
35
+ response: 0.45,
36
+ dampingRatio: 0.8
37
+ };
38
+ function sheetWidth(available) {
39
+ return Math.min(available, MAX_WIDTH);
40
+ }
41
+
42
+ /** Tallest height the content may occupy (excludes the bottom safe area). */
43
+ function maximumDetentValue(viewportHeight, insets) {
44
+ return Math.max(0, viewportHeight - insets.top - insets.bottom - TOP_GAP);
45
+ }
46
+
47
+ /** Height the content may occupy at the largest of `detents`. */
48
+ function contentHeight(detents, maximum) {
49
+ if (detents.length === 0 || detents.includes('large') || detents.includes('fitContent')) {
50
+ return maximum;
51
+ }
52
+ return detents.includes('medium') ? maximum * 0.5 : maximum * 0.25;
53
+ }
54
+
55
+ /** Best guess of the content area before the sheet is on screen. */
56
+ export function sheetContentArea(detents, viewport, insets) {
57
+ return {
58
+ width: sheetWidth(viewport.width),
59
+ height: contentHeight(detents, maximumDetentValue(viewport.height, insets))
60
+ };
61
+ }
62
+ function rubberBand(offset, dimension) {
63
+ return (1 - 1 / (offset * 0.55 / dimension + 1)) * dimension;
64
+ }
65
+ function findTouch(touches, id) {
66
+ for (let i = 0; i < touches.length; i++) {
67
+ const touch = touches.item(i);
68
+ if (touch?.identifier === id) return touch;
69
+ }
70
+ return undefined;
71
+ }
72
+
73
+ /**
74
+ * `bottomSheet` mode: an edge-attached sheet with detents, dragging,
75
+ * swipe-to-dismiss and hand-off to scrollable content, like the iOS
76
+ * implementation.
77
+ */
78
+ export class SheetPresenter extends ModalPresenter {
79
+ selectedIndex = 0;
80
+ /** The sheet sits below the viewport (before presenting / while dismissing). */
81
+ isOffscreen = true;
82
+ drag = null;
83
+ /** Vertical velocity of the swipe that requested the dismissal. */
84
+ releaseVelocity = 0;
85
+ /** The sheet's top edge in the viewport. */
86
+ top = new AnimatedValue(0, 0.5, value => this.render(value));
87
+ constructor(config, listener) {
88
+ super(config, listener);
89
+ this.selectedIndex = Math.min(Math.max(config.initialDetentIndex, 0), this.detents.length - 1);
90
+ }
91
+ snapToDetent(index) {
92
+ if (index < 0 || index >= this.detents.length) return;
93
+ this.selectedIndex = index;
94
+ this.animateToRest();
95
+ this.listener.onDetentChange(index);
96
+ }
97
+ didShow() {
98
+ const {
99
+ surface
100
+ } = this.elements;
101
+ surface.addEventListener('touchstart', this.handleTouchStart, {
102
+ passive: true
103
+ });
104
+ surface.addEventListener('touchmove', this.handleTouchMove, {
105
+ passive: false
106
+ });
107
+ surface.addEventListener('touchend', this.handleTouchEnd);
108
+ surface.addEventListener('touchcancel', this.handleTouchEnd);
109
+ surface.addEventListener('pointerdown', this.handlePointerDown);
110
+ this.layout();
111
+ this.top.set(this.viewport.height);
112
+ }
113
+ animateIn() {
114
+ this.isOffscreen = false;
115
+ this.settle(ENTER);
116
+ }
117
+ animateOut(onEnd) {
118
+ this.cancelDrag();
119
+ this.isOffscreen = true;
120
+ const velocity = this.releaseVelocity;
121
+ this.releaseVelocity = 0;
122
+ this.top.animateTo(this.viewport.height, this.motion(EXIT), {
123
+ velocity: velocity > 0 ? velocity : undefined,
124
+ stopAtTarget: true,
125
+ onEnd
126
+ });
127
+ }
128
+ configDidChange() {
129
+ this.selectedIndex = Math.min(this.selectedIndex, this.detents.length - 1);
130
+ this.layout();
131
+ this.animateToRest();
132
+ }
133
+ viewportDidChange() {
134
+ this.layout();
135
+ this.animateToRest();
136
+ }
137
+ contentSizeDidChange() {
138
+ if (this.config.detents.includes('fitContent')) {
139
+ this.animateToRest();
140
+ }
141
+ }
142
+ stopAnimations() {
143
+ this.top.stop();
144
+ }
145
+ teardown() {
146
+ super.teardown();
147
+ this.cancelDrag();
148
+ const surface = this.elements?.surface;
149
+ surface?.removeEventListener('touchstart', this.handleTouchStart);
150
+ surface?.removeEventListener('touchmove', this.handleTouchMove);
151
+ surface?.removeEventListener('touchend', this.handleTouchEnd);
152
+ surface?.removeEventListener('touchcancel', this.handleTouchEnd);
153
+ surface?.removeEventListener('pointerdown', this.handlePointerDown);
154
+ }
155
+
156
+ // Layout
157
+
158
+ get detents() {
159
+ return this.config.detents.length > 0 ? this.config.detents : ['fitContent'];
160
+ }
161
+ get maximumDetentValue() {
162
+ return maximumDetentValue(this.viewport.height, this.insets);
163
+ }
164
+ get keyboardLift() {
165
+ return this.config.keyboardBehavior === 'none' ? 0 : Math.max(0, this.keyboardHeight - this.insets.bottom);
166
+ }
167
+ height(detent) {
168
+ const maximum = this.maximumDetentValue;
169
+ switch (detent) {
170
+ case 'small':
171
+ return maximum * 0.25;
172
+ case 'medium':
173
+ return maximum * 0.5;
174
+ case 'large':
175
+ return maximum;
176
+ case 'fitContent':
177
+ return Math.min(Math.max(this.contentSize.height, 1), maximum);
178
+ }
179
+ }
180
+
181
+ /** Sheet top when resting on `detents[index]`. The bottom safe area is added below the content. */
182
+ restingTop(index) {
183
+ const {
184
+ detents
185
+ } = this;
186
+ const detent = detents[Math.min(Math.max(index, 0), detents.length - 1)] ?? 'fitContent';
187
+ const top = this.viewport.height - this.insets.bottom - this.keyboardLift - this.height(detent);
188
+ return Math.max(top, this.insets.top + TOP_GAP);
189
+ }
190
+ get detentTops() {
191
+ return this.detents.map((_, index) => this.restingTop(index));
192
+ }
193
+ layout() {
194
+ const {
195
+ surface,
196
+ content,
197
+ grabber
198
+ } = this.elements;
199
+ const width = sheetWidth(this.viewport.width);
200
+ const radius = `${this.config.cornerRadius ?? DEFAULT_CORNER_RADIUS}px`;
201
+ Object.assign(surface.style, {
202
+ left: `${(this.viewport.width - width) / 2}px`,
203
+ top: '0px',
204
+ width: `${width}px`,
205
+ height: `${this.viewport.height + OVERSCROLL}px`,
206
+ borderTopLeftRadius: radius,
207
+ borderTopRightRadius: radius,
208
+ borderBottomLeftRadius: '0px',
209
+ borderBottomRightRadius: '0px'
210
+ });
211
+ content.style.width = `${width}px`;
212
+ content.style.height = `${this.maximumDetentValue}px`;
213
+ grabber.style.display = this.config.grabberVisible ? '' : 'none';
214
+ let height = contentHeight(this.config.detents, this.maximumDetentValue);
215
+ if (this.config.keyboardBehavior === 'resize') {
216
+ height -= this.keyboardLift;
217
+ }
218
+ this.reportContentArea(width, Math.max(height, 0));
219
+ this.render(this.top.value);
220
+ }
221
+ render(top) {
222
+ if (!this.elements) return;
223
+ this.elements.surface.style.transform = `translate3d(0, ${top}px, 0)`;
224
+ this.elements.backdrop.style.opacity = String(this.backdropAlpha(top));
225
+ }
226
+
227
+ /** Fully dimmed at every detent; fades out below the lowest one. */
228
+ backdropAlpha(top) {
229
+ const bottom = this.viewport.height;
230
+ const lowest = Math.max(...this.detentTops);
231
+ if (!(bottom > lowest)) return top >= bottom ? 0 : 1;
232
+ return Math.min(Math.max((bottom - top) / (bottom - lowest), 0), 1);
233
+ }
234
+ motion(motion) {
235
+ return prefersReducedMotion() ? INSTANT : motion;
236
+ }
237
+ settle(motion, velocity) {
238
+ this.top.animateTo(this.restingTop(this.selectedIndex), this.motion(motion), {
239
+ velocity,
240
+ // Keeps the enter's completion when a re-layout takes it over.
241
+ onEnd: () => this.notifyPresented()
242
+ });
243
+ }
244
+ animateToRest() {
245
+ if (!this.elements || this.drag?.active || this.isOffscreen) return;
246
+ this.settle(SETTLE);
247
+ }
248
+
249
+ // Dragging
250
+
251
+ canDrag() {
252
+ return !this.entering && !this.isDismissing && !this.isOffscreen;
253
+ }
254
+ beginDrag(input, id, x, y, target) {
255
+ this.drag = {
256
+ input,
257
+ id,
258
+ startX: x,
259
+ startY: y,
260
+ lastY: y,
261
+ scroller: findVerticalScroller(target, this.elements.surface),
262
+ active: false,
263
+ rawTop: 0,
264
+ sheetDrove: false,
265
+ samples: []
266
+ };
267
+ }
268
+
269
+ /** Decides who handles a gesture once it moves: the sheet, or the content (scrolling, horizontal swipes). */
270
+ claim(drag, x, y, slop) {
271
+ const dx = x - drag.startX;
272
+ const dy = y - drag.startY;
273
+ if (Math.abs(dx) <= slop && Math.abs(dy) <= slop) return 'pending';
274
+ if (Math.abs(dx) > Math.abs(dy)) return 'content';
275
+ const {
276
+ scroller
277
+ } = drag;
278
+ if (!scroller) return 'sheet';
279
+ // Down: scroll back to the top before collapsing the sheet. Up: expand
280
+ // the sheet before scrolling.
281
+ if (dy > 0) return scroller.scrollTop <= 0 ? 'sheet' : 'content';
282
+ return this.top.value > Math.min(...this.detentTops) + 0.5 ? 'sheet' : 'content';
283
+ }
284
+ activate(drag) {
285
+ drag.active = true;
286
+ this.top.stop();
287
+ drag.rawTop = this.top.value;
288
+ const {
289
+ surface
290
+ } = this.elements;
291
+ // A native scroll on an ancestor makes React Native Web cancel the press
292
+ // under the pointer, so dragging from a button doesn't leave it pressed.
293
+ surface.dispatchEvent(new Event('scroll'));
294
+ if (drag.input === 'pointer') {
295
+ surface.style.setProperty('user-select', 'none');
296
+ surface.style.setProperty('-webkit-user-select', 'none');
297
+ window.getSelection()?.removeAllRanges();
298
+ }
299
+ }
300
+ moveDrag(drag, y) {
301
+ const delta = y - drag.lastY;
302
+ drag.lastY = y;
303
+ const time = performance.now();
304
+ drag.samples.push({
305
+ time,
306
+ y
307
+ });
308
+ while (drag.samples.length > 2 && time - drag.samples[0].time > VELOCITY_WINDOW_MS) {
309
+ drag.samples.shift();
310
+ }
311
+ const {
312
+ scroller
313
+ } = drag;
314
+ if (scroller) {
315
+ // The browser's own scrolling is prevented for this gesture, so the
316
+ // content is scrolled here whenever the sheet can't move.
317
+ const minTop = Math.min(...this.detentTops);
318
+ const drive = delta < 0 ? drag.rawTop > minTop + 0.5 : scroller.scrollTop <= 0;
319
+ if (drive) {
320
+ drag.rawTop = Math.max(drag.rawTop + delta, minTop);
321
+ } else {
322
+ scroller.scrollTop -= delta;
323
+ }
324
+ drag.sheetDrove = drive;
325
+ } else {
326
+ drag.rawTop += delta;
327
+ drag.sheetDrove = true;
328
+ }
329
+ this.top.set(this.constrained(drag.rawTop));
330
+ }
331
+ release(drag) {
332
+ this.stopTracking();
333
+ this.drag = null;
334
+ if (!drag.active) return;
335
+ if (drag.input === 'pointer') {
336
+ suppressNextClick();
337
+ }
338
+ const velocity = drag.sheetDrove ? this.velocity(drag) : 0;
339
+ const top = this.top.value;
340
+ const tops = this.detentTops;
341
+ const lowest = Math.max(...tops);
342
+ // Where a fling of this velocity would come to rest.
343
+ const projected = top + velocity * 0.2;
344
+ if (this.config.dismissOnSwipe && velocity >= 0 && projected > lowest + (this.viewport.height - lowest) / 2) {
345
+ this.releaseVelocity = velocity;
346
+ this.listener.onSwipeDismiss();
347
+ if (this.isDismissing) return;
348
+ this.releaseVelocity = 0;
349
+ }
350
+ const index = tops.reduce((best, candidate, i) => Math.abs(candidate - projected) < Math.abs(tops[best] - projected) ? i : best, 0);
351
+ if (index !== this.selectedIndex) {
352
+ this.selectedIndex = index;
353
+ this.listener.onDetentChange(index);
354
+ }
355
+ this.settle(SETTLE, velocity);
356
+ }
357
+
358
+ /** Abandons the gesture without settling (the exit or the content takes over). */
359
+ cancelDrag() {
360
+ this.stopTracking();
361
+ this.drag = null;
362
+ }
363
+ stopTracking() {
364
+ window.removeEventListener('pointermove', this.handlePointerMove);
365
+ window.removeEventListener('pointerup', this.handlePointerUp);
366
+ window.removeEventListener('pointercancel', this.handlePointerUp);
367
+ const surface = this.elements?.surface;
368
+ surface?.style.removeProperty('user-select');
369
+ surface?.style.removeProperty('-webkit-user-select');
370
+ }
371
+ velocity(drag) {
372
+ const now = performance.now();
373
+ const samples = drag.samples.filter(sample => now - sample.time <= VELOCITY_WINDOW_MS);
374
+ const first = samples[0];
375
+ const last = samples[samples.length - 1];
376
+ if (!first || !last || last.time <= first.time) return 0;
377
+ return (last.y - first.y) / (last.time - first.time) * 1000;
378
+ }
379
+
380
+ /** Rubber-bands above the tallest detent, and below the lowest one when swiping can't dismiss. */
381
+ constrained(top) {
382
+ const tops = this.detentTops;
383
+ const minTop = Math.min(...tops);
384
+ const maxTop = Math.max(...tops);
385
+ const dimension = Math.max(this.viewport.height, 1);
386
+ if (top < minTop) {
387
+ return minTop - rubberBand(minTop - top, dimension);
388
+ }
389
+ if (!this.config.dismissOnSwipe && top > maxTop) {
390
+ return maxTop + rubberBand(top - maxTop, dimension);
391
+ }
392
+ return top;
393
+ }
394
+
395
+ // Touch input. Touch events (rather than pointer events) let the sheet
396
+ // cancel the browser's scrolling when it claims the gesture.
397
+
398
+ handleTouchStart = event => {
399
+ if (this.drag) {
400
+ // A second finger before the sheet moved: leave it to the browser.
401
+ if (this.drag.input === 'touch' && !this.drag.active) {
402
+ this.drag = null;
403
+ }
404
+ return;
405
+ }
406
+ const touch = event.touches.length === 1 ? event.touches[0] : undefined;
407
+ if (!touch || !this.canDrag()) return;
408
+ this.beginDrag('touch', touch.identifier, touch.clientX, touch.clientY, event.target);
409
+ };
410
+ handleTouchMove = event => {
411
+ const drag = this.drag;
412
+ if (drag?.input !== 'touch') return;
413
+ const touch = findTouch(event.changedTouches, drag.id);
414
+ if (!touch) return;
415
+ if (!drag.active) {
416
+ // Once the browser has started scrolling, the gesture is its.
417
+ const owner = event.cancelable ? this.claim(drag, touch.clientX, touch.clientY, 0) : 'content';
418
+ if (owner === 'pending') return;
419
+ if (owner === 'content') {
420
+ this.drag = null;
421
+ return;
422
+ }
423
+ this.activate(drag);
424
+ }
425
+ if (event.cancelable) {
426
+ event.preventDefault();
427
+ }
428
+ this.moveDrag(drag, touch.clientY);
429
+ };
430
+ handleTouchEnd = event => {
431
+ const drag = this.drag;
432
+ if (drag?.input !== 'touch' || !findTouch(event.changedTouches, drag.id)) return;
433
+ this.release(drag);
434
+ };
435
+
436
+ // Mouse and pen input.
437
+
438
+ handlePointerDown = event => {
439
+ if (event.pointerType === 'touch' || event.button !== 0 || this.drag || !this.canDrag() ||
440
+ // Leave text selection in inputs alone.
441
+ isTextInput(event.target)) {
442
+ return;
443
+ }
444
+ this.beginDrag('pointer', event.pointerId, event.clientX, event.clientY, event.target);
445
+ window.addEventListener('pointermove', this.handlePointerMove);
446
+ window.addEventListener('pointerup', this.handlePointerUp);
447
+ window.addEventListener('pointercancel', this.handlePointerUp);
448
+ };
449
+ handlePointerMove = event => {
450
+ const drag = this.drag;
451
+ if (drag?.input !== 'pointer' || event.pointerId !== drag.id) return;
452
+ if (!drag.active) {
453
+ const owner = this.claim(drag, event.clientX, event.clientY, POINTER_SLOP);
454
+ if (owner === 'pending') return;
455
+ if (owner === 'content') {
456
+ this.cancelDrag();
457
+ return;
458
+ }
459
+ this.activate(drag);
460
+ }
461
+ this.moveDrag(drag, event.clientY);
462
+ };
463
+ handlePointerUp = event => {
464
+ const drag = this.drag;
465
+ if (drag?.input !== 'pointer' || event.pointerId !== drag.id) return;
466
+ this.release(drag);
467
+ };
468
+ }
469
+ //# sourceMappingURL=SheetPresenter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["AnimatedValue","INSTANT","findVerticalScroller","isTextInput","prefersReducedMotion","suppressNextClick","ModalPresenter","TOP_GAP","OVERSCROLL","DEFAULT_CORNER_RADIUS","MAX_WIDTH","POINTER_SLOP","VELOCITY_WINDOW_MS","ENTER","type","response","dampingRatio","SETTLE","EXIT","sheetWidth","available","Math","min","maximumDetentValue","viewportHeight","insets","max","top","bottom","contentHeight","detents","maximum","length","includes","sheetContentArea","viewport","width","height","rubberBand","offset","dimension","findTouch","touches","id","i","touch","item","identifier","undefined","SheetPresenter","selectedIndex","isOffscreen","drag","releaseVelocity","value","render","constructor","config","listener","initialDetentIndex","snapToDetent","index","animateToRest","onDetentChange","didShow","surface","elements","addEventListener","handleTouchStart","passive","handleTouchMove","handleTouchEnd","handlePointerDown","layout","set","animateIn","settle","animateOut","onEnd","cancelDrag","velocity","animateTo","motion","stopAtTarget","configDidChange","viewportDidChange","contentSizeDidChange","stopAnimations","stop","teardown","removeEventListener","keyboardLift","keyboardBehavior","keyboardHeight","detent","contentSize","restingTop","detentTops","map","_","content","grabber","radius","cornerRadius","Object","assign","style","left","borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius","display","grabberVisible","reportContentArea","transform","backdrop","opacity","String","backdropAlpha","lowest","notifyPresented","active","canDrag","entering","isDismissing","beginDrag","input","x","y","target","startX","startY","lastY","scroller","rawTop","sheetDrove","samples","claim","slop","dx","dy","abs","scrollTop","activate","dispatchEvent","Event","setProperty","window","getSelection","removeAllRanges","moveDrag","delta","time","performance","now","push","shift","minTop","drive","constrained","release","stopTracking","tops","projected","dismissOnSwipe","onSwipeDismiss","reduce","best","candidate","handlePointerMove","handlePointerUp","removeProperty","filter","sample","first","last","maxTop","event","clientX","clientY","changedTouches","owner","cancelable","preventDefault","pointerType","button","pointerId"],"sourceRoot":"../../../src","sources":["web/SheetPresenter.ts"],"mappings":";;AAAA;;AAGA,SAASA,aAAa,EAAEC,OAAO,QAAqB,oBAAiB;AACrE,SACEC,oBAAoB,EACpBC,WAAW,EACXC,oBAAoB,EACpBC,iBAAiB,QAGZ,UAAO;AAEd,SAASC,cAAc,QAAgC,qBAAkB;;AAEzE;AACA,MAAMC,OAAO,GAAG,EAAE;AAClB;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG,GAAG;AACtB,MAAMC,qBAAqB,GAAG,EAAE;AAChC,MAAMC,SAAS,GAAG,GAAG;AACrB;AACA,MAAMC,YAAY,GAAG,CAAC;AACtB;AACA,MAAMC,kBAAkB,GAAG,GAAG;AAE9B,M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OAAO,EACbzK,YACF,CAAC;MACD,IAAI2K,KAAK,KAAK,SAAS,EAAE;MACzB,IAAIA,KAAK,KAAK,SAAS,EAAE;QACvB,IAAI,CAACvG,UAAU,CAAC,CAAC;QACjB;MACF;MACA,IAAI,CAACiE,QAAQ,CAAC5F,IAAI,CAAC;IACrB;IACA,IAAI,CAACmG,QAAQ,CAACnG,IAAI,EAAE8H,KAAK,CAACE,OAAO,CAAC;EACpC,CAAC;EAEOT,eAAe,GAAIO,KAAmB,IAAK;IACjD,MAAM9H,IAAI,GAAG,IAAI,CAACA,IAAI;IACtB,IAAIA,IAAI,EAAE2E,KAAK,KAAK,SAAS,IAAImD,KAAK,CAACS,SAAS,KAAKvI,IAAI,CAACT,EAAE,EAAE;IAC9D,IAAI,CAACsH,OAAO,CAAC7G,IAAI,CAAC;EACpB,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,125 @@
1
+ "use strict";
2
+
3
+ /// <reference lib="dom" />
4
+
5
+ export const ZERO_INSETS = {
6
+ top: 0,
7
+ right: 0,
8
+ bottom: 0,
9
+ left: 0
10
+ };
11
+ export const canUseDOM = typeof window !== 'undefined' && typeof document !== 'undefined';
12
+
13
+ /** Converts a color from `processColor` (0xAARRGGBB) to CSS, scaling its alpha by `opacity`. */
14
+ export function toCSSColor(argb, opacity = 1) {
15
+ // As an unsigned 32-bit value, whatever the sign it was passed with.
16
+ const value = (argb % 2 ** 32 + 2 ** 32) % 2 ** 32;
17
+ const channel = shift => Math.floor(value / 2 ** shift) % 256;
18
+ const alpha = channel(24) / 255 * Math.min(Math.max(opacity, 0), 1);
19
+ return `rgba(${channel(16)}, ${channel(8)}, ${channel(0)}, ${Number(alpha.toFixed(3))})`;
20
+ }
21
+ let safeAreaProbe = null;
22
+
23
+ /**
24
+ * `env(safe-area-inset-*)`, read through a hidden probe element. Non-zero on
25
+ * notched devices when the page opts in with `viewport-fit=cover`.
26
+ */
27
+ export function readSafeAreaInsets() {
28
+ if (!safeAreaProbe?.isConnected) {
29
+ if (!document.body) return ZERO_INSETS;
30
+ const probe = document.createElement('div');
31
+ probe.setAttribute('aria-hidden', 'true');
32
+ probe.style.cssText = 'position:fixed;top:0;left:0;width:0;height:0;visibility:hidden;pointer-events:none;' + 'padding:env(safe-area-inset-top,0px) env(safe-area-inset-right,0px) ' + 'env(safe-area-inset-bottom,0px) env(safe-area-inset-left,0px);';
33
+ document.body.appendChild(probe);
34
+ safeAreaProbe = probe;
35
+ }
36
+ const style = getComputedStyle(safeAreaProbe);
37
+ return {
38
+ top: parseFloat(style.paddingTop) || 0,
39
+ right: parseFloat(style.paddingRight) || 0,
40
+ bottom: parseFloat(style.paddingBottom) || 0,
41
+ left: parseFloat(style.paddingLeft) || 0
42
+ };
43
+ }
44
+
45
+ /**
46
+ * Height of the on-screen keyboard over a layout viewport `layoutHeight` tall.
47
+ * Mobile browsers keep the layout viewport and shrink the visual one.
48
+ */
49
+ export function readKeyboardHeight(layoutHeight) {
50
+ const visual = window.visualViewport;
51
+ // Pinch zoom shrinks the visual viewport too.
52
+ if (!visual || Math.abs(visual.scale - 1) > 0.01) return 0;
53
+ const covered = layoutHeight - visual.offsetTop - visual.height;
54
+ return covered >= 1 ? Math.round(covered) : 0;
55
+ }
56
+
57
+ /** The size of the viewport before anything is on screen. */
58
+ export function estimateViewport() {
59
+ return {
60
+ width: document.documentElement.clientWidth || window.innerWidth,
61
+ height: window.innerHeight
62
+ };
63
+ }
64
+ function isVerticalScroller(node) {
65
+ if (!(node instanceof HTMLElement) || node.scrollHeight <= node.clientHeight) return false;
66
+ const {
67
+ overflowY
68
+ } = getComputedStyle(node);
69
+ return overflowY === 'auto' || overflowY === 'scroll';
70
+ }
71
+
72
+ /** The innermost element from `target` up to (not including) `root` that scrolls vertically. */
73
+ export function findVerticalScroller(target, root) {
74
+ let node = target instanceof Element ? target : null;
75
+ for (; node && node !== root; node = node.parentElement) {
76
+ if (isVerticalScroller(node)) return node;
77
+ }
78
+ return null;
79
+ }
80
+
81
+ /** Whether a scroller between `target` and `root` can scroll further by `deltaY`. */
82
+ export function canScrollWithin(target, root, deltaY) {
83
+ let node = target instanceof Element ? target : null;
84
+ for (; node && node !== root; node = node.parentElement) {
85
+ if (!isVerticalScroller(node)) continue;
86
+ const canScroll = deltaY < 0 ? node.scrollTop > 0 : node.scrollTop + node.clientHeight < node.scrollHeight - 1;
87
+ if (canScroll) return true;
88
+ }
89
+ return false;
90
+ }
91
+ export function isTextInput(target) {
92
+ return target instanceof Element && target.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])') != null;
93
+ }
94
+
95
+ /** Swallows the click that follows a mouse drag, so the content under the pointer isn't pressed. */
96
+ export function suppressNextClick() {
97
+ const swallow = event => {
98
+ event.stopPropagation();
99
+ event.preventDefault();
100
+ };
101
+ window.addEventListener('click', swallow, {
102
+ capture: true,
103
+ once: true
104
+ });
105
+ // A click, if any, is dispatched in the same task as the pointerup.
106
+ setTimeout(() => {
107
+ window.removeEventListener('click', swallow, {
108
+ capture: true
109
+ });
110
+ }, 0);
111
+ }
112
+ export function prefersReducedMotion() {
113
+ return typeof window.matchMedia === 'function' && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
114
+ }
115
+ let clipValue = null;
116
+
117
+ /**
118
+ * `overflow: clip` rounds the corners without making the element a scroll
119
+ * container, which focusing an input could otherwise scroll.
120
+ */
121
+ export function clipOverflow() {
122
+ clipValue ??= typeof CSS !== 'undefined' && CSS.supports('overflow', 'clip') ? 'clip' : 'hidden';
123
+ return clipValue;
124
+ }
125
+ //# sourceMappingURL=dom.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ZERO_INSETS","top","right","bottom","left","canUseDOM","window","document","toCSSColor","argb","opacity","value","channel","shift","Math","floor","alpha","min","max","Number","toFixed","safeAreaProbe","readSafeAreaInsets","isConnected","body","probe","createElement","setAttribute","style","cssText","appendChild","getComputedStyle","parseFloat","paddingTop","paddingRight","paddingBottom","paddingLeft","readKeyboardHeight","layoutHeight","visual","visualViewport","abs","scale","covered","offsetTop","height","round","estimateViewport","width","documentElement","clientWidth","innerWidth","innerHeight","isVerticalScroller","node","HTMLElement","scrollHeight","clientHeight","overflowY","findVerticalScroller","target","root","Element","parentElement","canScrollWithin","deltaY","canScroll","scrollTop","isTextInput","closest","suppressNextClick","swallow","event","stopPropagation","preventDefault","addEventListener","capture","once","setTimeout","removeEventListener","prefersReducedMotion","matchMedia","matches","clipValue","clipOverflow","CSS","supports"],"sourceRoot":"../../../src","sources":["web/dom.ts"],"mappings":";;AAAA;;AAcA,OAAO,MAAMA,WAAmB,GAAG;EAAEC,GAAG,EAAE,CAAC;EAAEC,KAAK,EAAE,CAAC;EAAEC,MAAM,EAAE,CAAC;EAAEC,IAAI,EAAE;AAAE,CAAC;AAE3E,OAAO,MAAMC,SAAS,GACpB,OAAOC,MAAM,KAAK,WAAW,IAAI,OAAOC,QAAQ,KAAK,WAAW;;AAElE;AACA,OAAO,SAASC,UAAUA,CAACC,IAAY,EAAEC,OAAO,GAAG,CAAC,EAAU;EAC5D;EACA,MAAMC,KAAK,GAAG,CAAEF,IAAI,GAAG,CAAC,IAAI,EAAE,GAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;EACpD,MAAMG,OAAO,GAAIC,KAAa,IAAKC,IAAI,CAACC,KAAK,CAACJ,KAAK,GAAG,CAAC,IAAIE,KAAK,CAAC,GAAG,GAAG;EACvE,MAAMG,KAAK,GAAIJ,OAAO,CAAC,EAAE,CAAC,GAAG,GAAG,GAAIE,IAAI,CAACG,GAAG,CAACH,IAAI,CAACI,GAAG,CAACR,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;EACrE,OAAO,QAAQE,OAAO,CAAC,EAAE,CAAC,KAAKA,OAAO,CAAC,CAAC,CAAC,KAAKA,OAAO,CAAC,CAAC,CAAC,KAAKO,MAAM,CAACH,KAAK,CAACI,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG;AAC1F;AAEA,IAAIC,aAAiC,GAAG,IAAI;;A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