@ionic/core 7.5.4-dev.11699632730.1e6d9b70 → 7.5.4-dev.11699895923.130c21aa

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 (94) hide show
  1. package/components/ion-modal.js +2 -2
  2. package/components/ion-toast.js +417 -67
  3. package/components/overlays.js +2 -1
  4. package/css/ionic.bundle.css +1 -1
  5. package/css/ionic.bundle.css.map +1 -1
  6. package/css/utils.bundle.css +0 -133
  7. package/css/utils.bundle.css.map +1 -1
  8. package/dist/cjs/index.cjs.js +1 -1
  9. package/dist/cjs/ion-action-sheet.cjs.entry.js +1 -1
  10. package/dist/cjs/ion-alert.cjs.entry.js +1 -1
  11. package/dist/cjs/ion-datetime_3.cjs.entry.js +1 -1
  12. package/dist/cjs/ion-loading.cjs.entry.js +1 -1
  13. package/dist/cjs/ion-menu_3.cjs.entry.js +1 -1
  14. package/dist/cjs/ion-modal.cjs.entry.js +2 -2
  15. package/dist/cjs/ion-popover.cjs.entry.js +1 -1
  16. package/dist/cjs/ion-select_3.cjs.entry.js +1 -1
  17. package/dist/cjs/ion-toast.cjs.entry.js +430 -83
  18. package/dist/cjs/ionic.cjs.js +1 -1
  19. package/dist/cjs/loader.cjs.js +1 -1
  20. package/dist/cjs/{overlays-d80a2cf2.js → overlays-ba1a1e21.js} +2 -0
  21. package/dist/collection/components/modal/gestures/swipe-to-close.js +2 -1
  22. package/dist/collection/components/toast/animations/ios.enter.js +2 -1
  23. package/dist/collection/components/toast/animations/md.enter.js +2 -1
  24. package/dist/collection/components/toast/animations/utils.js +11 -0
  25. package/dist/collection/components/toast/gestures/swipe-to-dismiss.js +267 -0
  26. package/dist/collection/components/toast/test/swipe-gesture/toast.e2e.js +84 -0
  27. package/dist/collection/components/toast/toast.js +104 -1
  28. package/dist/collection/utils/overlays.js +1 -0
  29. package/dist/docs.json +37 -1
  30. package/dist/esm/index.js +1 -1
  31. package/dist/esm/ion-action-sheet.entry.js +1 -1
  32. package/dist/esm/ion-alert.entry.js +1 -1
  33. package/dist/esm/ion-datetime_3.entry.js +1 -1
  34. package/dist/esm/ion-loading.entry.js +1 -1
  35. package/dist/esm/ion-menu_3.entry.js +1 -1
  36. package/dist/esm/ion-modal.entry.js +2 -2
  37. package/dist/esm/ion-popover.entry.js +1 -1
  38. package/dist/esm/ion-select_3.entry.js +1 -1
  39. package/dist/esm/ion-toast.entry.js +413 -66
  40. package/dist/esm/ionic.js +1 -1
  41. package/dist/esm/loader.js +1 -1
  42. package/dist/esm/{overlays-a31c8878.js → overlays-d79b34b4.js} +2 -1
  43. package/dist/esm-es5/index.js +1 -1
  44. package/dist/esm-es5/ion-action-sheet.entry.js +1 -1
  45. package/dist/esm-es5/ion-alert.entry.js +1 -1
  46. package/dist/esm-es5/ion-datetime_3.entry.js +1 -1
  47. package/dist/esm-es5/ion-loading.entry.js +1 -1
  48. package/dist/esm-es5/ion-menu_3.entry.js +1 -1
  49. package/dist/esm-es5/ion-modal.entry.js +1 -1
  50. package/dist/esm-es5/ion-popover.entry.js +1 -1
  51. package/dist/esm-es5/ion-select_3.entry.js +1 -1
  52. package/dist/esm-es5/ion-toast.entry.js +1 -1
  53. package/dist/esm-es5/ionic.js +1 -1
  54. package/dist/esm-es5/loader.js +1 -1
  55. package/dist/esm-es5/{overlays-a31c8878.js → overlays-d79b34b4.js} +1 -1
  56. package/dist/html.html-data.json +9 -0
  57. package/dist/ionic/index.esm.js +1 -1
  58. package/dist/ionic/ionic.esm.js +1 -1
  59. package/dist/ionic/{p-c32a6c04.entry.js → p-020dd47f.entry.js} +1 -1
  60. package/dist/ionic/p-02663394.system.js +1 -1
  61. package/dist/ionic/{p-b86c6c05.entry.js → p-138a4a93.entry.js} +1 -1
  62. package/dist/ionic/{p-4c75cb48.system.js → p-1511dc35.system.js} +1 -1
  63. package/dist/ionic/{p-3a769110.system.entry.js → p-1fc6b5a5.system.entry.js} +1 -1
  64. package/dist/ionic/{p-90020ef0.system.entry.js → p-2151a4a4.system.entry.js} +1 -1
  65. package/dist/ionic/{p-539c09e8.system.entry.js → p-2ae9a434.system.entry.js} +1 -1
  66. package/dist/ionic/{p-1e59dd04.system.entry.js → p-3dedd258.system.entry.js} +1 -1
  67. package/dist/ionic/{p-98c70e3c.system.js → p-53f75103.system.js} +1 -1
  68. package/dist/ionic/{p-75338011.entry.js → p-664cc492.entry.js} +1 -1
  69. package/dist/ionic/p-6c89025e.system.entry.js +4 -0
  70. package/dist/ionic/{p-8140a084.entry.js → p-78a8e1e8.entry.js} +1 -1
  71. package/dist/ionic/{p-d54a8393.system.entry.js → p-81bdfa1c.system.entry.js} +1 -1
  72. package/dist/ionic/p-8414ed31.entry.js +4 -0
  73. package/dist/ionic/{p-307963db.js → p-938c4956.js} +1 -1
  74. package/dist/ionic/{p-c09fa14d.entry.js → p-a9424586.entry.js} +1 -1
  75. package/dist/ionic/{p-59107f99.system.entry.js → p-ab1908ba.system.entry.js} +1 -1
  76. package/dist/ionic/{p-e91c7eb4.system.entry.js → p-cb6c380e.system.entry.js} +1 -1
  77. package/dist/ionic/{p-a4e4dba1.entry.js → p-e119ac8b.entry.js} +1 -1
  78. package/dist/ionic/p-e3b7a2d0.system.entry.js +4 -0
  79. package/dist/ionic/{p-53b1930e.entry.js → p-e525dbea.entry.js} +1 -1
  80. package/dist/ionic/p-f2d4e3c8.entry.js +4 -0
  81. package/dist/types/components/toast/animations/utils.d.ts +9 -0
  82. package/dist/types/components/toast/gestures/swipe-to-dismiss.d.ts +9 -0
  83. package/dist/types/components/toast/toast-interface.d.ts +1 -0
  84. package/dist/types/components/toast/toast.d.ts +28 -1
  85. package/dist/types/components.d.ts +10 -2
  86. package/dist/types/utils/overlays.d.ts +1 -0
  87. package/hydrate/index.js +413 -66
  88. package/package.json +1 -1
  89. package/css/themes/dark.css +0 -135
  90. package/css/themes/dark.css.map +0 -1
  91. package/dist/ionic/p-139bd79d.system.entry.js +0 -4
  92. package/dist/ionic/p-7d68e4ea.entry.js +0 -4
  93. package/dist/ionic/p-999a7271.entry.js +0 -4
  94. package/dist/ionic/p-e66f7d10.system.entry.js +0 -4
@@ -5,18 +5,107 @@
5
5
 
6
6
  Object.defineProperty(exports, '__esModule', { value: true });
7
7
 
8
- const index$2 = require('./index-73186843.js');
8
+ const index$3 = require('./index-73186843.js');
9
9
  const config = require('./config-d5882735.js');
10
10
  const helpers = require('./helpers-ea4ccbcb.js');
11
11
  const lockController = require('./lock-controller-4ae2eb59.js');
12
12
  const index$1 = require('./index-cc7dfb7c.js');
13
- const overlays = require('./overlays-d80a2cf2.js');
13
+ const overlays = require('./overlays-ba1a1e21.js');
14
14
  const theme = require('./theme-fbc56b3b.js');
15
15
  const ionicGlobal = require('./ionic-global-4538d91c.js');
16
16
  const animation = require('./animation-d101aa7a.js');
17
17
  const index = require('./index-c8d52405.js');
18
+ const index$2 = require('./index-0ee995e4.js');
18
19
  require('./framework-delegate-c0873a6f.js');
19
20
  require('./hardware-back-button-b67c8e75.js');
21
+ require('./gesture-controller-b46721be.js');
22
+
23
+ /**
24
+ * Calculate the CSS top and bottom position of the toast, to be used
25
+ * as starting points for the animation keyframes.
26
+ *
27
+ * The default animations for both MD and iOS
28
+ * use translateY, which calculates from the
29
+ * top edge of the screen. This behavior impacts
30
+ * how we compute the offset when a toast has
31
+ * position='bottom' since we need to calculate from
32
+ * the bottom edge of the screen instead.
33
+ *
34
+ * @param position The value of the toast's position prop.
35
+ * @param positionAnchor The element the toast should be anchored to,
36
+ * if applicable.
37
+ * @param mode The toast component's mode (md, ios, etc).
38
+ * @param toast A reference to the toast element itself.
39
+ */
40
+ function getAnimationPosition(position, positionAnchor, mode, toast) {
41
+ /**
42
+ * Start with a predefined offset from the edge the toast will be
43
+ * positioned relative to, whether on the screen or anchor element.
44
+ */
45
+ let offset;
46
+ if (mode === 'md') {
47
+ offset = position === 'top' ? 8 : -8;
48
+ }
49
+ else {
50
+ offset = position === 'top' ? 10 : -10;
51
+ }
52
+ /**
53
+ * If positionAnchor is defined, add in the distance from the target
54
+ * screen edge to the target anchor edge. For position="top", the
55
+ * bottom anchor edge is targeted. For position="bottom", the top
56
+ * anchor edge is targeted.
57
+ */
58
+ if (positionAnchor && index.win) {
59
+ warnIfAnchorIsHidden(positionAnchor, toast);
60
+ const box = positionAnchor.getBoundingClientRect();
61
+ if (position === 'top') {
62
+ offset += box.bottom;
63
+ }
64
+ else if (position === 'bottom') {
65
+ /**
66
+ * Just box.top is the distance from the top edge of the screen
67
+ * to the top edge of the anchor. We want to calculate from the
68
+ * bottom edge of the screen instead.
69
+ */
70
+ offset -= index.win.innerHeight - box.top;
71
+ }
72
+ /**
73
+ * We don't include safe area here because that should already be
74
+ * accounted for when checking the position of the anchor.
75
+ */
76
+ return {
77
+ top: `${offset}px`,
78
+ bottom: `${offset}px`,
79
+ };
80
+ }
81
+ else {
82
+ return {
83
+ top: `calc(${offset}px + var(--ion-safe-area-top, 0px))`,
84
+ bottom: `calc(${offset}px - var(--ion-safe-area-bottom, 0px))`,
85
+ };
86
+ }
87
+ }
88
+ /**
89
+ * If the anchor element is hidden, getBoundingClientRect()
90
+ * will return all 0s for it, which can cause unexpected
91
+ * results in the position calculation when animating.
92
+ */
93
+ function warnIfAnchorIsHidden(positionAnchor, toast) {
94
+ if (positionAnchor.offsetParent === null) {
95
+ index$1.printIonWarning('The positionAnchor element for ion-toast was found in the DOM, but appears to be hidden. This may lead to unexpected positioning of the toast.', toast);
96
+ }
97
+ }
98
+ /**
99
+ * Returns the top offset required to place
100
+ * the toast in the middle of the screen.
101
+ * Only needed when position="toast".
102
+ * @param toastHeight - The height of the ion-toast element
103
+ * @param wrapperHeight - The height of the .toast-wrapper element
104
+ * inside the toast's shadow root.
105
+ */
106
+ const getOffsetForMiddlePosition = (toastHeight, wrapperHeight) => {
107
+ return Math.floor(toastHeight / 2 - wrapperHeight / 2);
108
+ };
20
109
 
21
110
  /**
22
111
  * iOS Toast Enter Animation
@@ -33,7 +122,7 @@ const iosEnterAnimation = (baseEl, opts) => {
33
122
  wrapperAnimation.fromTo('transform', 'translateY(-100%)', `translateY(${top})`);
34
123
  break;
35
124
  case 'middle':
36
- const topPosition = Math.floor(baseEl.clientHeight / 2 - wrapperEl.clientHeight / 2);
125
+ const topPosition = getOffsetForMiddlePosition(baseEl.clientHeight, wrapperEl.clientHeight);
37
126
  wrapperEl.style.top = `${topPosition}px`;
38
127
  wrapperAnimation.fromTo('opacity', 0.01, 1);
39
128
  break;
@@ -84,7 +173,7 @@ const mdEnterAnimation = (baseEl, opts) => {
84
173
  wrapperAnimation.fromTo('opacity', 0.01, 1);
85
174
  break;
86
175
  case 'middle':
87
- const topPosition = Math.floor(baseEl.clientHeight / 2 - wrapperEl.clientHeight / 2);
176
+ const topPosition = getOffsetForMiddlePosition(baseEl.clientHeight, wrapperEl.clientHeight);
88
177
  wrapperEl.style.top = `${topPosition}px`;
89
178
  wrapperAnimation.fromTo('opacity', 0.01, 1);
90
179
  break;
@@ -109,80 +198,261 @@ const mdLeaveAnimation = (baseEl) => {
109
198
  };
110
199
 
111
200
  /**
112
- * Calculate the CSS top and bottom position of the toast, to be used
113
- * as starting points for the animation keyframes.
114
- *
115
- * The default animations for both MD and iOS
116
- * use translateY, which calculates from the
117
- * top edge of the screen. This behavior impacts
118
- * how we compute the offset when a toast has
119
- * position='bottom' since we need to calculate from
120
- * the bottom edge of the screen instead.
121
- *
122
- * @param position The value of the toast's position prop.
123
- * @param positionAnchor The element the toast should be anchored to,
124
- * if applicable.
125
- * @param mode The toast component's mode (md, ios, etc).
126
- * @param toast A reference to the toast element itself.
201
+ * Create a gesture that allows the Toast
202
+ * to be swiped to dismiss.
203
+ * @param el - The Toast element
204
+ * @param toastPosition - The last computed position of the Toast. This is computed in the "present" method.
205
+ * @param onDismiss - A callback to fire when the Toast was swiped to dismiss.
127
206
  */
128
- function getAnimationPosition(position, positionAnchor, mode, toast) {
207
+ const createSwipeToDismissGesture = (el, toastPosition, onDismiss) => {
129
208
  /**
130
- * Start with a predefined offset from the edge the toast will be
131
- * positioned relative to, whether on the screen or anchor element.
209
+ * Users should swipe on the visible toast wrapper
210
+ * rather than on ion-toast which covers the entire screen.
211
+ * When testing the class instance the inner wrapper will not
212
+ * be defined. As a result, we use a placeholder element in those environments.
132
213
  */
133
- let offset;
134
- if (mode === 'md') {
135
- offset = position === 'top' ? 8 : -8;
136
- }
137
- else {
138
- offset = position === 'top' ? 10 : -10;
139
- }
214
+ const wrapperEl = helpers.getElementRoot(el).querySelector('.toast-wrapper');
215
+ const hostElHeight = el.clientHeight;
216
+ const wrapperElBox = wrapperEl.getBoundingClientRect();
140
217
  /**
141
- * If positionAnchor is defined, add in the distance from the target
142
- * screen edge to the target anchor edge. For position="top", the
143
- * bottom anchor edge is targeted. For position="bottom", the top
144
- * anchor edge is targeted.
218
+ * The maximum amount that
219
+ * the toast can be swiped. This should
220
+ * account for the wrapper element's height
221
+ * too so the toast can be swiped offscreen
222
+ * completely.
145
223
  */
146
- if (positionAnchor && index.win) {
147
- warnIfAnchorIsHidden(positionAnchor, toast);
148
- const box = positionAnchor.getBoundingClientRect();
149
- if (position === 'top') {
150
- offset += box.bottom;
224
+ let MAX_SWIPE_DISTANCE = 0;
225
+ /**
226
+ * The step value at which a toast
227
+ * is eligible for dismissing via gesture.
228
+ */
229
+ const DISMISS_THRESHOLD = 0.5;
230
+ /**
231
+ * The middle position Toast starts 50% of the way
232
+ * through the animation, so we need to use this
233
+ * as the starting point for our step values.
234
+ */
235
+ const STEP_OFFSET = el.position === 'middle' ? 0.5 : 0;
236
+ /**
237
+ * When the Toast is at the top users will be
238
+ * swiping up. As a result, the delta values will be
239
+ * negative numbers which will result in negative steps
240
+ * and thresholds. As a result, we need to make those numbers
241
+ * positive.
242
+ */
243
+ const INVERSION_FACTOR = el.position === 'top' ? -1 : 1;
244
+ /**
245
+ * The top offset that places the
246
+ * toast in the middle of the screen.
247
+ * Only needed when position="middle".
248
+ */
249
+ const topPosition = getOffsetForMiddlePosition(hostElHeight, wrapperElBox.height);
250
+ const SWIPE_UP_DOWN_KEYFRAMES = [
251
+ { offset: 0, transform: `translateY(-${topPosition + wrapperElBox.height}px)` },
252
+ { offset: 0.5, transform: `translateY(0px)` },
253
+ { offset: 1, transform: `translateY(${topPosition + wrapperElBox.height}px)` },
254
+ ];
255
+ const swipeAnimation = animation.createAnimation('toast-swipe-to-dismiss-animation')
256
+ .addElement(wrapperEl)
257
+ /**
258
+ * The specific value here does not actually
259
+ * matter. We just need this to be a positive
260
+ * value so the animation does not jump
261
+ * to the end when the user beings to drag.
262
+ */
263
+ .duration(100);
264
+ switch (el.position) {
265
+ case 'middle':
266
+ MAX_SWIPE_DISTANCE = hostElHeight + wrapperElBox.height;
267
+ swipeAnimation.keyframes(SWIPE_UP_DOWN_KEYFRAMES);
268
+ /**
269
+ * Toast can be swiped up or down but
270
+ * should start in the middle of the screen.
271
+ */
272
+ swipeAnimation.progressStart(true, 0.5);
273
+ break;
274
+ case 'top':
275
+ /**
276
+ * The bottom edge of the wrapper
277
+ * includes the distance between the top
278
+ * of the screen and the top of the wrapper
279
+ * as well as the wrapper height so the wrapper
280
+ * can be dragged fully offscreen.
281
+ */
282
+ MAX_SWIPE_DISTANCE = wrapperElBox.bottom;
283
+ swipeAnimation.keyframes([
284
+ { offset: 0, transform: `translateY(${toastPosition.top})` },
285
+ { offset: 1, transform: 'translateY(-100%)' },
286
+ ]);
287
+ swipeAnimation.progressStart(true, 0);
288
+ break;
289
+ case 'bottom':
290
+ default:
291
+ /**
292
+ * This computes the distance between the
293
+ * top of the wrapper and the bottom of the
294
+ * screen including the height of the wrapper
295
+ * element so it can be dragged fully offscreen.
296
+ */
297
+ MAX_SWIPE_DISTANCE = hostElHeight - wrapperElBox.top;
298
+ swipeAnimation.keyframes([
299
+ { offset: 0, transform: `translateY(${toastPosition.bottom})` },
300
+ { offset: 1, transform: 'translateY(100%)' },
301
+ ]);
302
+ swipeAnimation.progressStart(true, 0);
303
+ break;
304
+ }
305
+ const computeStep = (delta) => {
306
+ return (delta * INVERSION_FACTOR) / MAX_SWIPE_DISTANCE;
307
+ };
308
+ const onMove = (detail) => {
309
+ const step = STEP_OFFSET + computeStep(detail.deltaY);
310
+ swipeAnimation.progressStep(step);
311
+ };
312
+ const onEnd = (detail) => {
313
+ const velocity = detail.velocityY;
314
+ const threshold = ((detail.deltaY + velocity * 1000) / MAX_SWIPE_DISTANCE) * INVERSION_FACTOR;
315
+ /**
316
+ * Disable the gesture for the remainder of the animation.
317
+ * It will be re-enabled if the toast animates back to
318
+ * its initial presented position.
319
+ */
320
+ gesture.enable(false);
321
+ let shouldDismiss = true;
322
+ let playTo = 1;
323
+ let step = 0;
324
+ let remainingDistance = 0;
325
+ if (el.position === 'middle') {
326
+ /**
327
+ * A middle positioned Toast appears
328
+ * in the middle of the screen (at animation offset 0.5).
329
+ * As a result, the threshold will be calculated relative
330
+ * to this starting position. In other words at animation offset 0.5
331
+ * the threshold will be 0. We want the middle Toast to be eligible
332
+ * for dismiss when the user has swiped either half way up or down the
333
+ * screen. As a result, we divide DISMISS_THRESHOLD in half. We also
334
+ * consider when the threshold is a negative in the event the
335
+ * user drags up (since the deltaY will also be negative).
336
+ */
337
+ shouldDismiss = threshold >= DISMISS_THRESHOLD / 2 || threshold <= -DISMISS_THRESHOLD / 2;
338
+ /**
339
+ * Since we are replacing the keyframes
340
+ * below the animation always starts from
341
+ * the beginning of the new keyframes.
342
+ * Similarly, we are always playing to
343
+ * the end of the new keyframes.
344
+ */
345
+ playTo = 1;
346
+ step = 0;
347
+ /**
348
+ * The Toast should animate from wherever its
349
+ * current position is to the desired end state.
350
+ *
351
+ * To begin, we get the current position of the
352
+ * Toast for its starting state.
353
+ */
354
+ const wrapperElBox = wrapperEl.getBoundingClientRect();
355
+ const startOffset = wrapperElBox.top - topPosition;
356
+ const startPosition = `${startOffset}px`;
357
+ /**
358
+ * If the deltaY is negative then the user is swiping
359
+ * up, so the Toast should animate to the top of the screen.
360
+ * If the deltaY is positive then the user is swiping
361
+ * down, so the Toast should animate to the bottom of the screen.
362
+ * We also account for when the deltaY is 0, but realistically
363
+ * that should never happen because it means the user did not drag
364
+ * the toast.
365
+ */
366
+ const offsetFactor = detail.deltaY <= 0 ? -1 : 1;
367
+ const endOffset = (topPosition + wrapperElBox.height) * offsetFactor;
368
+ /**
369
+ * If the Toast should dismiss
370
+ * then we need to figure out which edge of
371
+ * the screen it should animate towards.
372
+ * By default, the Toast will come
373
+ * back to its default state in the
374
+ * middle of the screen.
375
+ */
376
+ const endPosition = shouldDismiss ? `${endOffset}px` : '0px';
377
+ const KEYFRAMES = [
378
+ { offset: 0, transform: `translateY(${startPosition})` },
379
+ { offset: 1, transform: `translateY(${endPosition})` },
380
+ ];
381
+ swipeAnimation.keyframes(KEYFRAMES);
382
+ /**
383
+ * Compute the remaining amount of pixels the
384
+ * toast needs to move to be fully dismissed.
385
+ */
386
+ remainingDistance = endOffset - startOffset;
151
387
  }
152
- else if (position === 'bottom') {
388
+ else {
389
+ shouldDismiss = threshold >= DISMISS_THRESHOLD;
390
+ playTo = shouldDismiss ? 1 : 0;
391
+ step = computeStep(detail.deltaY);
153
392
  /**
154
- * Just box.top is the distance from the top edge of the screen
155
- * to the top edge of the anchor. We want to calculate from the
156
- * bottom edge of the screen instead.
393
+ * Compute the remaining amount of pixels the
394
+ * toast needs to move to be fully dismissed.
157
395
  */
158
- offset -= index.win.innerHeight - box.top;
396
+ const remainingStepAmount = shouldDismiss ? 1 - step : step;
397
+ remainingDistance = remainingStepAmount * MAX_SWIPE_DISTANCE;
159
398
  }
160
399
  /**
161
- * We don't include safe area here because that should already be
162
- * accounted for when checking the position of the anchor.
400
+ * The animation speed should depend on how quickly
401
+ * the user flicks the toast across the screen. However,
402
+ * it should be no slower than 200ms.
403
+ * We use Math.abs on the remainingDistance because that value
404
+ * can be negative when swiping up on a middle position toast.
163
405
  */
164
- return {
165
- top: `${offset}px`,
166
- bottom: `${offset}px`,
167
- };
168
- }
169
- else {
170
- return {
171
- top: `calc(${offset}px + var(--ion-safe-area-top, 0px))`,
172
- bottom: `calc(${offset}px - var(--ion-safe-area-bottom, 0px))`,
173
- };
174
- }
175
- }
176
- /**
177
- * If the anchor element is hidden, getBoundingClientRect()
178
- * will return all 0s for it, which can cause unexpected
179
- * results in the position calculation when animating.
180
- */
181
- function warnIfAnchorIsHidden(positionAnchor, toast) {
182
- if (positionAnchor.offsetParent === null) {
183
- index$1.printIonWarning('The positionAnchor element for ion-toast was found in the DOM, but appears to be hidden. This may lead to unexpected positioning of the toast.', toast);
184
- }
185
- }
406
+ const duration = Math.min(Math.abs(remainingDistance) / Math.abs(velocity), 200);
407
+ swipeAnimation
408
+ .onFinish(() => {
409
+ if (shouldDismiss) {
410
+ onDismiss();
411
+ swipeAnimation.destroy();
412
+ }
413
+ else {
414
+ if (el.position === 'middle') {
415
+ /**
416
+ * If the toast snapped back to
417
+ * the middle of the screen we need
418
+ * to reset the keyframes
419
+ * so the toast can be swiped
420
+ * up or down again.
421
+ */
422
+ swipeAnimation.keyframes(SWIPE_UP_DOWN_KEYFRAMES).progressStart(true, 0.5);
423
+ }
424
+ else {
425
+ swipeAnimation.progressStart(true, 0);
426
+ }
427
+ /**
428
+ * If the toast did not dismiss then
429
+ * the user should be able to swipe again.
430
+ */
431
+ gesture.enable(true);
432
+ }
433
+ /**
434
+ * This must be a one time callback
435
+ * otherwise a new callback will
436
+ * be added every time onEnd runs.
437
+ */
438
+ }, { oneTimeCallback: true })
439
+ .progressEnd(playTo, step, duration);
440
+ };
441
+ const gesture = index$2.createGesture({
442
+ el: wrapperEl,
443
+ gestureName: 'toast-swipe-to-dismiss',
444
+ gesturePriority: overlays.OVERLAY_GESTURE_PRIORITY,
445
+ /**
446
+ * Toast only supports vertical swipes.
447
+ * This needs to be updated if we later
448
+ * support horizontal swipes.
449
+ */
450
+ direction: 'y',
451
+ onMove,
452
+ onEnd,
453
+ });
454
+ return gesture;
455
+ };
186
456
 
187
457
  const toastIosCss = ":host{--border-width:0;--border-style:none;--border-color:initial;--box-shadow:none;--min-width:auto;--width:auto;--min-height:auto;--height:auto;--max-height:auto;--white-space:normal;top:0;display:block;position:absolute;width:100%;height:100%;outline:none;color:var(--color);font-family:var(--ion-font-family, inherit);contain:strict;z-index:1001;pointer-events:none}@supports (inset-inline-start: 0){:host{inset-inline-start:0}}@supports not (inset-inline-start: 0){:host{left:0}:host-context([dir=rtl]){left:unset;right:unset;right:0}@supports selector(:dir(rtl)){:host(:dir(rtl)){left:unset;right:unset;right:0}}}:host(.overlay-hidden){display:none}:host(.ion-color){--button-color:inherit;color:var(--ion-color-contrast)}:host(.ion-color) .toast-button-cancel{color:inherit}:host(.ion-color) .toast-wrapper{background:var(--ion-color-base)}.toast-wrapper{border-radius:var(--border-radius);width:var(--width);min-width:var(--min-width);max-width:var(--max-width);height:var(--height);min-height:var(--min-height);max-height:var(--max-height);border-width:var(--border-width);border-style:var(--border-style);border-color:var(--border-color);background:var(--background);-webkit-box-shadow:var(--box-shadow);box-shadow:var(--box-shadow)}@supports (inset-inline-start: 0){.toast-wrapper{inset-inline-start:var(--start);inset-inline-end:var(--end)}}@supports not (inset-inline-start: 0){.toast-wrapper{left:var(--start);right:var(--end)}:host-context([dir=rtl]) .toast-wrapper{left:unset;right:unset;left:var(--end);right:var(--start)}[dir=rtl] .toast-wrapper{left:unset;right:unset;left:var(--end);right:var(--start)}@supports selector(:dir(rtl)){.toast-wrapper:dir(rtl){left:unset;right:unset;left:var(--end);right:var(--start)}}}.toast-wrapper.toast-top{-webkit-transform:translate3d(0, -100%, 0);transform:translate3d(0, -100%, 0);top:0}.toast-wrapper.toast-bottom{-webkit-transform:translate3d(0, 100%, 0);transform:translate3d(0, 100%, 0);bottom:0}.toast-container{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;pointer-events:auto;height:inherit;min-height:inherit;max-height:inherit;contain:content}.toast-layout-stacked .toast-container{-ms-flex-wrap:wrap;flex-wrap:wrap}.toast-layout-baseline .toast-content{display:-ms-flexbox;display:flex;-ms-flex:1;flex:1;-ms-flex-direction:column;flex-direction:column;-ms-flex-pack:center;justify-content:center}.toast-icon{-webkit-margin-start:16px;margin-inline-start:16px}.toast-content{min-width:0}.toast-message{-ms-flex:1;flex:1;white-space:var(--white-space)}.toast-button-group{display:-ms-flexbox;display:flex}.toast-layout-stacked .toast-button-group{-ms-flex-pack:end;justify-content:end;width:100%}.toast-button{border:0;outline:none;color:var(--button-color);z-index:0}.toast-icon,.toast-button-icon{font-size:1.4em}.toast-button-inner{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}@media (any-hover: hover){.toast-button:hover{cursor:pointer}}:host{--background:var(--ion-color-step-50, #f2f2f2);--border-radius:14px;--button-color:var(--ion-color-primary, #3880ff);--color:var(--ion-color-step-850, #262626);--max-width:700px;--max-height:478px;--start:10px;--end:10px;font-size:clamp(14px, 0.875rem, 43.4px)}.toast-wrapper{-webkit-margin-start:auto;margin-inline-start:auto;-webkit-margin-end:auto;margin-inline-end:auto;margin-top:auto;margin-bottom:auto;display:block;position:absolute;z-index:10}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){:host(.toast-translucent) .toast-wrapper{background:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px)}:host(.ion-color.toast-translucent) .toast-wrapper{background:rgba(var(--ion-color-base-rgb), 0.8)}}.toast-wrapper.toast-middle{opacity:0.01}.toast-content{-webkit-padding-start:15px;padding-inline-start:15px;-webkit-padding-end:15px;padding-inline-end:15px;padding-top:15px;padding-bottom:15px}.toast-header{margin-bottom:2px;font-weight:500}.toast-button{-webkit-padding-start:15px;padding-inline-start:15px;-webkit-padding-end:15px;padding-inline-end:15px;padding-top:10px;padding-bottom:10px;min-height:44px;-webkit-transition:background-color, opacity 100ms linear;transition:background-color, opacity 100ms linear;border:0;background-color:transparent;font-family:var(--ion-font-family);font-size:clamp(17px, 1.0625rem, 21.998px);font-weight:500;overflow:hidden}.toast-button.ion-activated{opacity:0.4}@media (any-hover: hover){.toast-button:hover{opacity:0.6}}";
188
458
 
@@ -190,15 +460,15 @@ const toastMdCss = ":host{--border-width:0;--border-style:none;--border-color:in
190
460
 
191
461
  const Toast = class {
192
462
  constructor(hostRef) {
193
- index$2.registerInstance(this, hostRef);
194
- this.didPresent = index$2.createEvent(this, "ionToastDidPresent", 7);
195
- this.willPresent = index$2.createEvent(this, "ionToastWillPresent", 7);
196
- this.willDismiss = index$2.createEvent(this, "ionToastWillDismiss", 7);
197
- this.didDismiss = index$2.createEvent(this, "ionToastDidDismiss", 7);
198
- this.didPresentShorthand = index$2.createEvent(this, "didPresent", 7);
199
- this.willPresentShorthand = index$2.createEvent(this, "willPresent", 7);
200
- this.willDismissShorthand = index$2.createEvent(this, "willDismiss", 7);
201
- this.didDismissShorthand = index$2.createEvent(this, "didDismiss", 7);
463
+ index$3.registerInstance(this, hostRef);
464
+ this.didPresent = index$3.createEvent(this, "ionToastDidPresent", 7);
465
+ this.willPresent = index$3.createEvent(this, "ionToastWillPresent", 7);
466
+ this.willDismiss = index$3.createEvent(this, "ionToastWillDismiss", 7);
467
+ this.didDismiss = index$3.createEvent(this, "ionToastDidDismiss", 7);
468
+ this.didPresentShorthand = index$3.createEvent(this, "didPresent", 7);
469
+ this.willPresentShorthand = index$3.createEvent(this, "willPresent", 7);
470
+ this.willDismissShorthand = index$3.createEvent(this, "willDismiss", 7);
471
+ this.didDismissShorthand = index$3.createEvent(this, "didDismiss", 7);
202
472
  this.delegateController = overlays.createDelegateController(this);
203
473
  this.lockController = lockController.createLockController();
204
474
  this.triggerController = overlays.createTriggerController();
@@ -211,6 +481,41 @@ const Toast = class {
211
481
  this.callButtonHandler(cancelButton);
212
482
  }
213
483
  };
484
+ /**
485
+ * Create a new swipe gesture so Toast
486
+ * can be swiped to dismiss.
487
+ */
488
+ this.createSwipeGesture = (toastPosition) => {
489
+ const gesture = (this.gesture = createSwipeToDismissGesture(this.el, toastPosition, () => {
490
+ /**
491
+ * If the gesture completed then
492
+ * we should dismiss the toast.
493
+ */
494
+ this.dismiss(undefined, overlays.GESTURE);
495
+ }));
496
+ gesture.enable(true);
497
+ };
498
+ /**
499
+ * Destroy an existing swipe gesture
500
+ * so Toast can no longer be swiped to dismiss.
501
+ */
502
+ this.destroySwipeGesture = () => {
503
+ const { gesture } = this;
504
+ if (gesture === undefined) {
505
+ return;
506
+ }
507
+ gesture.destroy();
508
+ this.gesture = undefined;
509
+ };
510
+ /**
511
+ * Returns `true` if swipeGesture
512
+ * is configured to a value that enables the swipe behavior.
513
+ * Returns `false` otherwise.
514
+ */
515
+ this.prefersSwipeGesture = () => {
516
+ const { swipeGesture } = this;
517
+ return swipeGesture === 'vertical';
518
+ };
214
519
  this.revealContentToScreenReader = false;
215
520
  this.overlayIndex = undefined;
216
521
  this.delegate = undefined;
@@ -231,9 +536,37 @@ const Toast = class {
231
536
  this.animated = true;
232
537
  this.icon = undefined;
233
538
  this.htmlAttributes = undefined;
539
+ this.swipeGesture = undefined;
234
540
  this.isOpen = false;
235
541
  this.trigger = undefined;
236
542
  }
543
+ swipeGestureChanged() {
544
+ /**
545
+ * If the Toast is presented, then we need to destroy
546
+ * any actives gestures before a new gesture is potentially
547
+ * created below.
548
+ *
549
+ * If the Toast is dismissed, then no gesture should be available
550
+ * since the Toast is not visible. This case should never
551
+ * happen since the "dismiss" method handles destroying
552
+ * any active swipe gestures, but we keep this code
553
+ * around to handle the first case.
554
+ */
555
+ this.destroySwipeGesture();
556
+ /**
557
+ * A new swipe gesture should only be created
558
+ * if the Toast is presented. If the Toast is not
559
+ * yet presented then the "present" method will
560
+ * handle calling the swipe gesture setup function.
561
+ */
562
+ if (this.presented && this.prefersSwipeGesture()) {
563
+ /**
564
+ * If the Toast is presented then
565
+ * lastPresentedPosition is defined.
566
+ */
567
+ this.createSwipeGesture(this.lastPresentedPosition);
568
+ }
569
+ }
237
570
  onIsOpenChange(newValue, oldValue) {
238
571
  if (newValue === true && oldValue === false) {
239
572
  this.present();
@@ -295,6 +628,14 @@ const Toast = class {
295
628
  if (this.duration > 0) {
296
629
  this.durationTimeout = setTimeout(() => this.dismiss(undefined, 'timeout'), this.duration);
297
630
  }
631
+ /**
632
+ * If the Toast has a swipe gesture then we can
633
+ * create the gesture so users can swipe the
634
+ * presented Toast.
635
+ */
636
+ if (this.prefersSwipeGesture()) {
637
+ this.createSwipeGesture(animationPosition);
638
+ }
298
639
  unlock();
299
640
  }
300
641
  /**
@@ -329,6 +670,11 @@ const Toast = class {
329
670
  this.revealContentToScreenReader = false;
330
671
  }
331
672
  this.lastPresentedPosition = undefined;
673
+ /**
674
+ * If the Toast has a swipe gesture then we can
675
+ * safely destroy it now that it is dismissed.
676
+ */
677
+ this.destroySwipeGesture();
332
678
  unlock();
333
679
  return dismissed;
334
680
  }
@@ -427,7 +773,7 @@ const Toast = class {
427
773
  'toast-button-group': true,
428
774
  [`toast-button-group-${side}`]: true,
429
775
  };
430
- return (index$2.h("div", { class: buttonGroupsClasses }, buttons.map((b) => (index$2.h("button", Object.assign({}, b.htmlAttributes, { type: "button", class: buttonClass(b), tabIndex: 0, onClick: () => this.buttonClick(b), part: buttonPart(b) }), index$2.h("div", { class: "toast-button-inner" }, b.icon && (index$2.h("ion-icon", { "aria-hidden": "true", icon: b.icon, slot: b.text === undefined ? 'icon-only' : undefined, class: "toast-button-icon" })), b.text), mode === 'md' && (index$2.h("ion-ripple-effect", { type: b.icon !== undefined && b.text === undefined ? 'unbounded' : 'bounded' })))))));
776
+ return (index$3.h("div", { class: buttonGroupsClasses }, buttons.map((b) => (index$3.h("button", Object.assign({}, b.htmlAttributes, { type: "button", class: buttonClass(b), tabIndex: 0, onClick: () => this.buttonClick(b), part: buttonPart(b) }), index$3.h("div", { class: "toast-button-inner" }, b.icon && (index$3.h("ion-icon", { "aria-hidden": "true", icon: b.icon, slot: b.text === undefined ? 'icon-only' : undefined, class: "toast-button-icon" })), b.text), mode === 'md' && (index$3.h("ion-ripple-effect", { type: b.icon !== undefined && b.text === undefined ? 'unbounded' : 'bounded' })))))));
431
777
  }
432
778
  /**
433
779
  * Render the `message` property.
@@ -437,9 +783,9 @@ const Toast = class {
437
783
  renderToastMessage(key, ariaHidden = null) {
438
784
  const { customHTMLEnabled, message } = this;
439
785
  if (customHTMLEnabled) {
440
- return (index$2.h("div", { key: key, "aria-hidden": ariaHidden, class: "toast-message", part: "message", innerHTML: config.sanitizeDOMString(message) }));
786
+ return (index$3.h("div", { key: key, "aria-hidden": ariaHidden, class: "toast-message", part: "message", innerHTML: config.sanitizeDOMString(message) }));
441
787
  }
442
- return (index$2.h("div", { key: key, "aria-hidden": ariaHidden, class: "toast-message", part: "message" }, message));
788
+ return (index$3.h("div", { key: key, "aria-hidden": ariaHidden, class: "toast-message", part: "message" }, message));
443
789
  }
444
790
  /**
445
791
  * Render the `header` property.
@@ -447,7 +793,7 @@ const Toast = class {
447
793
  * @param ariaHidden - If "true" then content will be hidden from screen readers.
448
794
  */
449
795
  renderHeader(key, ariaHidden = null) {
450
- return (index$2.h("div", { key: key, class: "toast-header", "aria-hidden": ariaHidden, part: "header" }, this.header));
796
+ return (index$3.h("div", { key: key, class: "toast-header", "aria-hidden": ariaHidden, part: "header" }, this.header));
451
797
  }
452
798
  render() {
453
799
  const { layout, el, revealContentToScreenReader, header, message } = this;
@@ -467,12 +813,13 @@ const Toast = class {
467
813
  if (layout === 'stacked' && startButtons.length > 0 && endButtons.length > 0) {
468
814
  index$1.printIonWarning('This toast is using start and end buttons with the stacked toast layout. We recommend following the best practice of using either start or end buttons with the stacked toast layout.', el);
469
815
  }
470
- return (index$2.h(index$2.Host, Object.assign({ tabindex: "-1" }, this.htmlAttributes, { style: {
816
+ return (index$3.h(index$3.Host, Object.assign({ tabindex: "-1" }, this.htmlAttributes, { style: {
471
817
  zIndex: `${60000 + this.overlayIndex}`,
472
- }, class: theme.createColorClasses(this.color, Object.assign(Object.assign({ [mode]: true }, theme.getClassMap(this.cssClass)), { 'overlay-hidden': true, 'toast-translucent': this.translucent })), onIonToastWillDismiss: this.dispatchCancelHandler }), index$2.h("div", { class: wrapperClass }, index$2.h("div", { class: "toast-container", part: "container" }, this.renderButtons(startButtons, 'start'), this.icon !== undefined && (index$2.h("ion-icon", { class: "toast-icon", part: "icon", icon: this.icon, lazy: false, "aria-hidden": "true" })), index$2.h("div", { class: "toast-content", role: "status", "aria-atomic": "true", "aria-live": "polite" }, !revealContentToScreenReader && header !== undefined && this.renderHeader('oldHeader', 'true'), !revealContentToScreenReader && message !== undefined && this.renderToastMessage('oldMessage', 'true'), revealContentToScreenReader && header !== undefined && this.renderHeader('header'), revealContentToScreenReader && message !== undefined && this.renderToastMessage('header')), this.renderButtons(endButtons, 'end')))));
818
+ }, class: theme.createColorClasses(this.color, Object.assign(Object.assign({ [mode]: true }, theme.getClassMap(this.cssClass)), { 'overlay-hidden': true, 'toast-translucent': this.translucent })), onIonToastWillDismiss: this.dispatchCancelHandler }), index$3.h("div", { class: wrapperClass }, index$3.h("div", { class: "toast-container", part: "container" }, this.renderButtons(startButtons, 'start'), this.icon !== undefined && (index$3.h("ion-icon", { class: "toast-icon", part: "icon", icon: this.icon, lazy: false, "aria-hidden": "true" })), index$3.h("div", { class: "toast-content", role: "status", "aria-atomic": "true", "aria-live": "polite" }, !revealContentToScreenReader && header !== undefined && this.renderHeader('oldHeader', 'true'), !revealContentToScreenReader && message !== undefined && this.renderToastMessage('oldMessage', 'true'), revealContentToScreenReader && header !== undefined && this.renderHeader('header'), revealContentToScreenReader && message !== undefined && this.renderToastMessage('header')), this.renderButtons(endButtons, 'end')))));
473
819
  }
474
- get el() { return index$2.getElement(this); }
820
+ get el() { return index$3.getElement(this); }
475
821
  static get watchers() { return {
822
+ "swipeGesture": ["swipeGestureChanged"],
476
823
  "isOpen": ["onIsOpenChange"],
477
824
  "trigger": ["triggerChanged"]
478
825
  }; }