@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
@@ -99,6 +99,7 @@ export declare const isCancel: (role: string | undefined) => boolean;
99
99
  export declare const safeCall: (handler: any, arg?: any) => any;
100
100
  export declare const BACKDROP = "backdrop";
101
101
  export declare const GESTURE = "gesture";
102
+ export declare const OVERLAY_GESTURE_PRIORITY = 39;
102
103
  /**
103
104
  * Creates a delegate controller.
104
105
  *
package/hydrate/index.js CHANGED
@@ -8728,6 +8728,7 @@ const safeCall = (handler, arg) => {
8728
8728
  };
8729
8729
  const BACKDROP = 'backdrop';
8730
8730
  const GESTURE = 'gesture';
8731
+ const OVERLAY_GESTURE_PRIORITY = 39;
8731
8732
  /**
8732
8733
  * Creates a delegate controller.
8733
8734
  *
@@ -22299,7 +22300,7 @@ const createSwipeToCloseGesture = (el, animation, statusBarStyle, onDismiss) =>
22299
22300
  const gesture = createGesture({
22300
22301
  el,
22301
22302
  gestureName: 'modalSwipeToClose',
22302
- gesturePriority: 39,
22303
+ gesturePriority: OVERLAY_GESTURE_PRIORITY,
22303
22304
  direction: 'y',
22304
22305
  threshold: 10,
22305
22306
  canStart,
@@ -33963,6 +33964,93 @@ class Thumbnail {
33963
33964
  }; }
33964
33965
  }
33965
33966
 
33967
+ /**
33968
+ * Calculate the CSS top and bottom position of the toast, to be used
33969
+ * as starting points for the animation keyframes.
33970
+ *
33971
+ * The default animations for both MD and iOS
33972
+ * use translateY, which calculates from the
33973
+ * top edge of the screen. This behavior impacts
33974
+ * how we compute the offset when a toast has
33975
+ * position='bottom' since we need to calculate from
33976
+ * the bottom edge of the screen instead.
33977
+ *
33978
+ * @param position The value of the toast's position prop.
33979
+ * @param positionAnchor The element the toast should be anchored to,
33980
+ * if applicable.
33981
+ * @param mode The toast component's mode (md, ios, etc).
33982
+ * @param toast A reference to the toast element itself.
33983
+ */
33984
+ function getAnimationPosition(position, positionAnchor, mode, toast) {
33985
+ /**
33986
+ * Start with a predefined offset from the edge the toast will be
33987
+ * positioned relative to, whether on the screen or anchor element.
33988
+ */
33989
+ let offset;
33990
+ if (mode === 'md') {
33991
+ offset = position === 'top' ? 8 : -8;
33992
+ }
33993
+ else {
33994
+ offset = position === 'top' ? 10 : -10;
33995
+ }
33996
+ /**
33997
+ * If positionAnchor is defined, add in the distance from the target
33998
+ * screen edge to the target anchor edge. For position="top", the
33999
+ * bottom anchor edge is targeted. For position="bottom", the top
34000
+ * anchor edge is targeted.
34001
+ */
34002
+ if (positionAnchor && win$1) {
34003
+ warnIfAnchorIsHidden(positionAnchor, toast);
34004
+ const box = positionAnchor.getBoundingClientRect();
34005
+ if (position === 'top') {
34006
+ offset += box.bottom;
34007
+ }
34008
+ else if (position === 'bottom') {
34009
+ /**
34010
+ * Just box.top is the distance from the top edge of the screen
34011
+ * to the top edge of the anchor. We want to calculate from the
34012
+ * bottom edge of the screen instead.
34013
+ */
34014
+ offset -= win$1.innerHeight - box.top;
34015
+ }
34016
+ /**
34017
+ * We don't include safe area here because that should already be
34018
+ * accounted for when checking the position of the anchor.
34019
+ */
34020
+ return {
34021
+ top: `${offset}px`,
34022
+ bottom: `${offset}px`,
34023
+ };
34024
+ }
34025
+ else {
34026
+ return {
34027
+ top: `calc(${offset}px + var(--ion-safe-area-top, 0px))`,
34028
+ bottom: `calc(${offset}px - var(--ion-safe-area-bottom, 0px))`,
34029
+ };
34030
+ }
34031
+ }
34032
+ /**
34033
+ * If the anchor element is hidden, getBoundingClientRect()
34034
+ * will return all 0s for it, which can cause unexpected
34035
+ * results in the position calculation when animating.
34036
+ */
34037
+ function warnIfAnchorIsHidden(positionAnchor, toast) {
34038
+ if (positionAnchor.offsetParent === null) {
34039
+ 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);
34040
+ }
34041
+ }
34042
+ /**
34043
+ * Returns the top offset required to place
34044
+ * the toast in the middle of the screen.
34045
+ * Only needed when position="toast".
34046
+ * @param toastHeight - The height of the ion-toast element
34047
+ * @param wrapperHeight - The height of the .toast-wrapper element
34048
+ * inside the toast's shadow root.
34049
+ */
34050
+ const getOffsetForMiddlePosition = (toastHeight, wrapperHeight) => {
34051
+ return Math.floor(toastHeight / 2 - wrapperHeight / 2);
34052
+ };
34053
+
33966
34054
  /**
33967
34055
  * iOS Toast Enter Animation
33968
34056
  */
@@ -33978,7 +34066,7 @@ const iosEnterAnimation = (baseEl, opts) => {
33978
34066
  wrapperAnimation.fromTo('transform', 'translateY(-100%)', `translateY(${top})`);
33979
34067
  break;
33980
34068
  case 'middle':
33981
- const topPosition = Math.floor(baseEl.clientHeight / 2 - wrapperEl.clientHeight / 2);
34069
+ const topPosition = getOffsetForMiddlePosition(baseEl.clientHeight, wrapperEl.clientHeight);
33982
34070
  wrapperEl.style.top = `${topPosition}px`;
33983
34071
  wrapperAnimation.fromTo('opacity', 0.01, 1);
33984
34072
  break;
@@ -34029,7 +34117,7 @@ const mdEnterAnimation = (baseEl, opts) => {
34029
34117
  wrapperAnimation.fromTo('opacity', 0.01, 1);
34030
34118
  break;
34031
34119
  case 'middle':
34032
- const topPosition = Math.floor(baseEl.clientHeight / 2 - wrapperEl.clientHeight / 2);
34120
+ const topPosition = getOffsetForMiddlePosition(baseEl.clientHeight, wrapperEl.clientHeight);
34033
34121
  wrapperEl.style.top = `${topPosition}px`;
34034
34122
  wrapperAnimation.fromTo('opacity', 0.01, 1);
34035
34123
  break;
@@ -34054,80 +34142,261 @@ const mdLeaveAnimation = (baseEl) => {
34054
34142
  };
34055
34143
 
34056
34144
  /**
34057
- * Calculate the CSS top and bottom position of the toast, to be used
34058
- * as starting points for the animation keyframes.
34059
- *
34060
- * The default animations for both MD and iOS
34061
- * use translateY, which calculates from the
34062
- * top edge of the screen. This behavior impacts
34063
- * how we compute the offset when a toast has
34064
- * position='bottom' since we need to calculate from
34065
- * the bottom edge of the screen instead.
34066
- *
34067
- * @param position The value of the toast's position prop.
34068
- * @param positionAnchor The element the toast should be anchored to,
34069
- * if applicable.
34070
- * @param mode The toast component's mode (md, ios, etc).
34071
- * @param toast A reference to the toast element itself.
34145
+ * Create a gesture that allows the Toast
34146
+ * to be swiped to dismiss.
34147
+ * @param el - The Toast element
34148
+ * @param toastPosition - The last computed position of the Toast. This is computed in the "present" method.
34149
+ * @param onDismiss - A callback to fire when the Toast was swiped to dismiss.
34072
34150
  */
34073
- function getAnimationPosition(position, positionAnchor, mode, toast) {
34151
+ const createSwipeToDismissGesture = (el, toastPosition, onDismiss) => {
34074
34152
  /**
34075
- * Start with a predefined offset from the edge the toast will be
34076
- * positioned relative to, whether on the screen or anchor element.
34153
+ * Users should swipe on the visible toast wrapper
34154
+ * rather than on ion-toast which covers the entire screen.
34155
+ * When testing the class instance the inner wrapper will not
34156
+ * be defined. As a result, we use a placeholder element in those environments.
34077
34157
  */
34078
- let offset;
34079
- if (mode === 'md') {
34080
- offset = position === 'top' ? 8 : -8;
34081
- }
34082
- else {
34083
- offset = position === 'top' ? 10 : -10;
34084
- }
34158
+ const wrapperEl = getElementRoot(el).querySelector('.toast-wrapper');
34159
+ const hostElHeight = el.clientHeight;
34160
+ const wrapperElBox = wrapperEl.getBoundingClientRect();
34085
34161
  /**
34086
- * If positionAnchor is defined, add in the distance from the target
34087
- * screen edge to the target anchor edge. For position="top", the
34088
- * bottom anchor edge is targeted. For position="bottom", the top
34089
- * anchor edge is targeted.
34162
+ * The maximum amount that
34163
+ * the toast can be swiped. This should
34164
+ * account for the wrapper element's height
34165
+ * too so the toast can be swiped offscreen
34166
+ * completely.
34090
34167
  */
34091
- if (positionAnchor && win$1) {
34092
- warnIfAnchorIsHidden(positionAnchor, toast);
34093
- const box = positionAnchor.getBoundingClientRect();
34094
- if (position === 'top') {
34095
- offset += box.bottom;
34168
+ let MAX_SWIPE_DISTANCE = 0;
34169
+ /**
34170
+ * The step value at which a toast
34171
+ * is eligible for dismissing via gesture.
34172
+ */
34173
+ const DISMISS_THRESHOLD = 0.5;
34174
+ /**
34175
+ * The middle position Toast starts 50% of the way
34176
+ * through the animation, so we need to use this
34177
+ * as the starting point for our step values.
34178
+ */
34179
+ const STEP_OFFSET = el.position === 'middle' ? 0.5 : 0;
34180
+ /**
34181
+ * When the Toast is at the top users will be
34182
+ * swiping up. As a result, the delta values will be
34183
+ * negative numbers which will result in negative steps
34184
+ * and thresholds. As a result, we need to make those numbers
34185
+ * positive.
34186
+ */
34187
+ const INVERSION_FACTOR = el.position === 'top' ? -1 : 1;
34188
+ /**
34189
+ * The top offset that places the
34190
+ * toast in the middle of the screen.
34191
+ * Only needed when position="middle".
34192
+ */
34193
+ const topPosition = getOffsetForMiddlePosition(hostElHeight, wrapperElBox.height);
34194
+ const SWIPE_UP_DOWN_KEYFRAMES = [
34195
+ { offset: 0, transform: `translateY(-${topPosition + wrapperElBox.height}px)` },
34196
+ { offset: 0.5, transform: `translateY(0px)` },
34197
+ { offset: 1, transform: `translateY(${topPosition + wrapperElBox.height}px)` },
34198
+ ];
34199
+ const swipeAnimation = createAnimation('toast-swipe-to-dismiss-animation')
34200
+ .addElement(wrapperEl)
34201
+ /**
34202
+ * The specific value here does not actually
34203
+ * matter. We just need this to be a positive
34204
+ * value so the animation does not jump
34205
+ * to the end when the user beings to drag.
34206
+ */
34207
+ .duration(100);
34208
+ switch (el.position) {
34209
+ case 'middle':
34210
+ MAX_SWIPE_DISTANCE = hostElHeight + wrapperElBox.height;
34211
+ swipeAnimation.keyframes(SWIPE_UP_DOWN_KEYFRAMES);
34212
+ /**
34213
+ * Toast can be swiped up or down but
34214
+ * should start in the middle of the screen.
34215
+ */
34216
+ swipeAnimation.progressStart(true, 0.5);
34217
+ break;
34218
+ case 'top':
34219
+ /**
34220
+ * The bottom edge of the wrapper
34221
+ * includes the distance between the top
34222
+ * of the screen and the top of the wrapper
34223
+ * as well as the wrapper height so the wrapper
34224
+ * can be dragged fully offscreen.
34225
+ */
34226
+ MAX_SWIPE_DISTANCE = wrapperElBox.bottom;
34227
+ swipeAnimation.keyframes([
34228
+ { offset: 0, transform: `translateY(${toastPosition.top})` },
34229
+ { offset: 1, transform: 'translateY(-100%)' },
34230
+ ]);
34231
+ swipeAnimation.progressStart(true, 0);
34232
+ break;
34233
+ case 'bottom':
34234
+ default:
34235
+ /**
34236
+ * This computes the distance between the
34237
+ * top of the wrapper and the bottom of the
34238
+ * screen including the height of the wrapper
34239
+ * element so it can be dragged fully offscreen.
34240
+ */
34241
+ MAX_SWIPE_DISTANCE = hostElHeight - wrapperElBox.top;
34242
+ swipeAnimation.keyframes([
34243
+ { offset: 0, transform: `translateY(${toastPosition.bottom})` },
34244
+ { offset: 1, transform: 'translateY(100%)' },
34245
+ ]);
34246
+ swipeAnimation.progressStart(true, 0);
34247
+ break;
34248
+ }
34249
+ const computeStep = (delta) => {
34250
+ return (delta * INVERSION_FACTOR) / MAX_SWIPE_DISTANCE;
34251
+ };
34252
+ const onMove = (detail) => {
34253
+ const step = STEP_OFFSET + computeStep(detail.deltaY);
34254
+ swipeAnimation.progressStep(step);
34255
+ };
34256
+ const onEnd = (detail) => {
34257
+ const velocity = detail.velocityY;
34258
+ const threshold = ((detail.deltaY + velocity * 1000) / MAX_SWIPE_DISTANCE) * INVERSION_FACTOR;
34259
+ /**
34260
+ * Disable the gesture for the remainder of the animation.
34261
+ * It will be re-enabled if the toast animates back to
34262
+ * its initial presented position.
34263
+ */
34264
+ gesture.enable(false);
34265
+ let shouldDismiss = true;
34266
+ let playTo = 1;
34267
+ let step = 0;
34268
+ let remainingDistance = 0;
34269
+ if (el.position === 'middle') {
34270
+ /**
34271
+ * A middle positioned Toast appears
34272
+ * in the middle of the screen (at animation offset 0.5).
34273
+ * As a result, the threshold will be calculated relative
34274
+ * to this starting position. In other words at animation offset 0.5
34275
+ * the threshold will be 0. We want the middle Toast to be eligible
34276
+ * for dismiss when the user has swiped either half way up or down the
34277
+ * screen. As a result, we divide DISMISS_THRESHOLD in half. We also
34278
+ * consider when the threshold is a negative in the event the
34279
+ * user drags up (since the deltaY will also be negative).
34280
+ */
34281
+ shouldDismiss = threshold >= DISMISS_THRESHOLD / 2 || threshold <= -DISMISS_THRESHOLD / 2;
34282
+ /**
34283
+ * Since we are replacing the keyframes
34284
+ * below the animation always starts from
34285
+ * the beginning of the new keyframes.
34286
+ * Similarly, we are always playing to
34287
+ * the end of the new keyframes.
34288
+ */
34289
+ playTo = 1;
34290
+ step = 0;
34291
+ /**
34292
+ * The Toast should animate from wherever its
34293
+ * current position is to the desired end state.
34294
+ *
34295
+ * To begin, we get the current position of the
34296
+ * Toast for its starting state.
34297
+ */
34298
+ const wrapperElBox = wrapperEl.getBoundingClientRect();
34299
+ const startOffset = wrapperElBox.top - topPosition;
34300
+ const startPosition = `${startOffset}px`;
34301
+ /**
34302
+ * If the deltaY is negative then the user is swiping
34303
+ * up, so the Toast should animate to the top of the screen.
34304
+ * If the deltaY is positive then the user is swiping
34305
+ * down, so the Toast should animate to the bottom of the screen.
34306
+ * We also account for when the deltaY is 0, but realistically
34307
+ * that should never happen because it means the user did not drag
34308
+ * the toast.
34309
+ */
34310
+ const offsetFactor = detail.deltaY <= 0 ? -1 : 1;
34311
+ const endOffset = (topPosition + wrapperElBox.height) * offsetFactor;
34312
+ /**
34313
+ * If the Toast should dismiss
34314
+ * then we need to figure out which edge of
34315
+ * the screen it should animate towards.
34316
+ * By default, the Toast will come
34317
+ * back to its default state in the
34318
+ * middle of the screen.
34319
+ */
34320
+ const endPosition = shouldDismiss ? `${endOffset}px` : '0px';
34321
+ const KEYFRAMES = [
34322
+ { offset: 0, transform: `translateY(${startPosition})` },
34323
+ { offset: 1, transform: `translateY(${endPosition})` },
34324
+ ];
34325
+ swipeAnimation.keyframes(KEYFRAMES);
34326
+ /**
34327
+ * Compute the remaining amount of pixels the
34328
+ * toast needs to move to be fully dismissed.
34329
+ */
34330
+ remainingDistance = endOffset - startOffset;
34096
34331
  }
34097
- else if (position === 'bottom') {
34332
+ else {
34333
+ shouldDismiss = threshold >= DISMISS_THRESHOLD;
34334
+ playTo = shouldDismiss ? 1 : 0;
34335
+ step = computeStep(detail.deltaY);
34098
34336
  /**
34099
- * Just box.top is the distance from the top edge of the screen
34100
- * to the top edge of the anchor. We want to calculate from the
34101
- * bottom edge of the screen instead.
34337
+ * Compute the remaining amount of pixels the
34338
+ * toast needs to move to be fully dismissed.
34102
34339
  */
34103
- offset -= win$1.innerHeight - box.top;
34340
+ const remainingStepAmount = shouldDismiss ? 1 - step : step;
34341
+ remainingDistance = remainingStepAmount * MAX_SWIPE_DISTANCE;
34104
34342
  }
34105
34343
  /**
34106
- * We don't include safe area here because that should already be
34107
- * accounted for when checking the position of the anchor.
34344
+ * The animation speed should depend on how quickly
34345
+ * the user flicks the toast across the screen. However,
34346
+ * it should be no slower than 200ms.
34347
+ * We use Math.abs on the remainingDistance because that value
34348
+ * can be negative when swiping up on a middle position toast.
34108
34349
  */
34109
- return {
34110
- top: `${offset}px`,
34111
- bottom: `${offset}px`,
34112
- };
34113
- }
34114
- else {
34115
- return {
34116
- top: `calc(${offset}px + var(--ion-safe-area-top, 0px))`,
34117
- bottom: `calc(${offset}px - var(--ion-safe-area-bottom, 0px))`,
34118
- };
34119
- }
34120
- }
34121
- /**
34122
- * If the anchor element is hidden, getBoundingClientRect()
34123
- * will return all 0s for it, which can cause unexpected
34124
- * results in the position calculation when animating.
34125
- */
34126
- function warnIfAnchorIsHidden(positionAnchor, toast) {
34127
- if (positionAnchor.offsetParent === null) {
34128
- 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);
34129
- }
34130
- }
34350
+ const duration = Math.min(Math.abs(remainingDistance) / Math.abs(velocity), 200);
34351
+ swipeAnimation
34352
+ .onFinish(() => {
34353
+ if (shouldDismiss) {
34354
+ onDismiss();
34355
+ swipeAnimation.destroy();
34356
+ }
34357
+ else {
34358
+ if (el.position === 'middle') {
34359
+ /**
34360
+ * If the toast snapped back to
34361
+ * the middle of the screen we need
34362
+ * to reset the keyframes
34363
+ * so the toast can be swiped
34364
+ * up or down again.
34365
+ */
34366
+ swipeAnimation.keyframes(SWIPE_UP_DOWN_KEYFRAMES).progressStart(true, 0.5);
34367
+ }
34368
+ else {
34369
+ swipeAnimation.progressStart(true, 0);
34370
+ }
34371
+ /**
34372
+ * If the toast did not dismiss then
34373
+ * the user should be able to swipe again.
34374
+ */
34375
+ gesture.enable(true);
34376
+ }
34377
+ /**
34378
+ * This must be a one time callback
34379
+ * otherwise a new callback will
34380
+ * be added every time onEnd runs.
34381
+ */
34382
+ }, { oneTimeCallback: true })
34383
+ .progressEnd(playTo, step, duration);
34384
+ };
34385
+ const gesture = createGesture({
34386
+ el: wrapperEl,
34387
+ gestureName: 'toast-swipe-to-dismiss',
34388
+ gesturePriority: OVERLAY_GESTURE_PRIORITY,
34389
+ /**
34390
+ * Toast only supports vertical swipes.
34391
+ * This needs to be updated if we later
34392
+ * support horizontal swipes.
34393
+ */
34394
+ direction: 'y',
34395
+ onMove,
34396
+ onEnd,
34397
+ });
34398
+ return gesture;
34399
+ };
34131
34400
 
34132
34401
  const toastIosCss = "/*!@:host*/.sc-ion-toast-ios-h{--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*/.sc-ion-toast-ios-h{inset-inline-start:0}}@supports not (inset-inline-start: 0){/*!@:host*/.sc-ion-toast-ios-h{left:0}/*!@:host-context([dir=rtl])*/[dir=rtl].sc-ion-toast-ios-h,[dir=rtl] .sc-ion-toast-ios-h{left:unset;right:unset;right:0}/*!@@supports selector(:dir(rtl))*/@supports .sc-ion-toast-ios selector(.sc-ion-toast-ios:dir(rtl)){.sc-ion-toast-ios-h:dir(rtl){left:unset;right:unset;right:0}}}/*!@:host(.overlay-hidden)*/.overlay-hidden.sc-ion-toast-ios-h{display:none}/*!@:host(.ion-color)*/.ion-color.sc-ion-toast-ios-h{--button-color:inherit;color:var(--ion-color-contrast)}/*!@:host(.ion-color) .toast-button-cancel*/.ion-color.sc-ion-toast-ios-h .toast-button-cancel.sc-ion-toast-ios{color:inherit}/*!@:host(.ion-color) .toast-wrapper*/.ion-color.sc-ion-toast-ios-h .toast-wrapper.sc-ion-toast-ios{background:var(--ion-color-base)}/*!@.toast-wrapper*/.toast-wrapper.sc-ion-toast-ios{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*/.toast-wrapper.sc-ion-toast-ios{inset-inline-start:var(--start);inset-inline-end:var(--end)}}@supports not (inset-inline-start: 0){/*!@.toast-wrapper*/.toast-wrapper.sc-ion-toast-ios{left:var(--start);right:var(--end)}/*!@:host-context([dir=rtl]) .toast-wrapper*/[dir=rtl].sc-ion-toast-ios-h .toast-wrapper.sc-ion-toast-ios,[dir=rtl] .sc-ion-toast-ios-h .toast-wrapper.sc-ion-toast-ios{left:unset;right:unset;left:var(--end);right:var(--start)}/*!@[dir=rtl] .toast-wrapper*/[dir=rtl].sc-ion-toast-ios .toast-wrapper.sc-ion-toast-ios{left:unset;right:unset;left:var(--end);right:var(--start)}/*!@@supports selector(:dir(rtl))*/@supports .sc-ion-toast-ios selector(.sc-ion-toast-ios:dir(rtl)){.toast-wrapper:dir(rtl){left:unset;right:unset;left:var(--end);right:var(--start)}}}/*!@.toast-wrapper.toast-top*/.toast-wrapper.toast-top.sc-ion-toast-ios{-webkit-transform:translate3d(0, -100%, 0);transform:translate3d(0, -100%, 0);top:0}/*!@.toast-wrapper.toast-bottom*/.toast-wrapper.toast-bottom.sc-ion-toast-ios{-webkit-transform:translate3d(0, 100%, 0);transform:translate3d(0, 100%, 0);bottom:0}/*!@.toast-container*/.toast-container.sc-ion-toast-ios{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*/.toast-layout-stacked.sc-ion-toast-ios .toast-container.sc-ion-toast-ios{-ms-flex-wrap:wrap;flex-wrap:wrap}/*!@.toast-layout-baseline .toast-content*/.toast-layout-baseline.sc-ion-toast-ios .toast-content.sc-ion-toast-ios{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*/.toast-icon.sc-ion-toast-ios{-webkit-margin-start:16px;margin-inline-start:16px}/*!@.toast-content*/.toast-content.sc-ion-toast-ios{min-width:0}/*!@.toast-message*/.toast-message.sc-ion-toast-ios{-ms-flex:1;flex:1;white-space:var(--white-space)}/*!@.toast-button-group*/.toast-button-group.sc-ion-toast-ios{display:-ms-flexbox;display:flex}/*!@.toast-layout-stacked .toast-button-group*/.toast-layout-stacked.sc-ion-toast-ios .toast-button-group.sc-ion-toast-ios{-ms-flex-pack:end;justify-content:end;width:100%}/*!@.toast-button*/.toast-button.sc-ion-toast-ios{border:0;outline:none;color:var(--button-color);z-index:0}/*!@.toast-icon,\n.toast-button-icon*/.toast-icon.sc-ion-toast-ios,.toast-button-icon.sc-ion-toast-ios{font-size:1.4em}/*!@.toast-button-inner*/.toast-button-inner.sc-ion-toast-ios{display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center}@media (any-hover: hover){/*!@.toast-button:hover*/.toast-button.sc-ion-toast-ios:hover{cursor:pointer}}/*!@:host*/.sc-ion-toast-ios-h{--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*/.toast-wrapper.sc-ion-toast-ios{-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*/.toast-translucent.sc-ion-toast-ios-h .toast-wrapper.sc-ion-toast-ios{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*/.ion-color.toast-translucent.sc-ion-toast-ios-h .toast-wrapper.sc-ion-toast-ios{background:rgba(var(--ion-color-base-rgb), 0.8)}}/*!@.toast-wrapper.toast-middle*/.toast-wrapper.toast-middle.sc-ion-toast-ios{opacity:0.01}/*!@.toast-content*/.toast-content.sc-ion-toast-ios{-webkit-padding-start:15px;padding-inline-start:15px;-webkit-padding-end:15px;padding-inline-end:15px;padding-top:15px;padding-bottom:15px}/*!@.toast-header*/.toast-header.sc-ion-toast-ios{margin-bottom:2px;font-weight:500}/*!@.toast-button*/.toast-button.sc-ion-toast-ios{-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*/.toast-button.ion-activated.sc-ion-toast-ios{opacity:0.4}@media (any-hover: hover){/*!@.toast-button:hover*/.toast-button.sc-ion-toast-ios:hover{opacity:0.6}}";
34133
34402
 
@@ -34167,6 +34436,41 @@ class Toast {
34167
34436
  this.callButtonHandler(cancelButton);
34168
34437
  }
34169
34438
  };
34439
+ /**
34440
+ * Create a new swipe gesture so Toast
34441
+ * can be swiped to dismiss.
34442
+ */
34443
+ this.createSwipeGesture = (toastPosition) => {
34444
+ const gesture = (this.gesture = createSwipeToDismissGesture(this.el, toastPosition, () => {
34445
+ /**
34446
+ * If the gesture completed then
34447
+ * we should dismiss the toast.
34448
+ */
34449
+ this.dismiss(undefined, GESTURE);
34450
+ }));
34451
+ gesture.enable(true);
34452
+ };
34453
+ /**
34454
+ * Destroy an existing swipe gesture
34455
+ * so Toast can no longer be swiped to dismiss.
34456
+ */
34457
+ this.destroySwipeGesture = () => {
34458
+ const { gesture } = this;
34459
+ if (gesture === undefined) {
34460
+ return;
34461
+ }
34462
+ gesture.destroy();
34463
+ this.gesture = undefined;
34464
+ };
34465
+ /**
34466
+ * Returns `true` if swipeGesture
34467
+ * is configured to a value that enables the swipe behavior.
34468
+ * Returns `false` otherwise.
34469
+ */
34470
+ this.prefersSwipeGesture = () => {
34471
+ const { swipeGesture } = this;
34472
+ return swipeGesture === 'vertical';
34473
+ };
34170
34474
  this.revealContentToScreenReader = false;
34171
34475
  this.overlayIndex = undefined;
34172
34476
  this.delegate = undefined;
@@ -34187,9 +34491,37 @@ class Toast {
34187
34491
  this.animated = true;
34188
34492
  this.icon = undefined;
34189
34493
  this.htmlAttributes = undefined;
34494
+ this.swipeGesture = undefined;
34190
34495
  this.isOpen = false;
34191
34496
  this.trigger = undefined;
34192
34497
  }
34498
+ swipeGestureChanged() {
34499
+ /**
34500
+ * If the Toast is presented, then we need to destroy
34501
+ * any actives gestures before a new gesture is potentially
34502
+ * created below.
34503
+ *
34504
+ * If the Toast is dismissed, then no gesture should be available
34505
+ * since the Toast is not visible. This case should never
34506
+ * happen since the "dismiss" method handles destroying
34507
+ * any active swipe gestures, but we keep this code
34508
+ * around to handle the first case.
34509
+ */
34510
+ this.destroySwipeGesture();
34511
+ /**
34512
+ * A new swipe gesture should only be created
34513
+ * if the Toast is presented. If the Toast is not
34514
+ * yet presented then the "present" method will
34515
+ * handle calling the swipe gesture setup function.
34516
+ */
34517
+ if (this.presented && this.prefersSwipeGesture()) {
34518
+ /**
34519
+ * If the Toast is presented then
34520
+ * lastPresentedPosition is defined.
34521
+ */
34522
+ this.createSwipeGesture(this.lastPresentedPosition);
34523
+ }
34524
+ }
34193
34525
  onIsOpenChange(newValue, oldValue) {
34194
34526
  if (newValue === true && oldValue === false) {
34195
34527
  this.present();
@@ -34251,6 +34583,14 @@ class Toast {
34251
34583
  if (this.duration > 0) {
34252
34584
  this.durationTimeout = setTimeout(() => this.dismiss(undefined, 'timeout'), this.duration);
34253
34585
  }
34586
+ /**
34587
+ * If the Toast has a swipe gesture then we can
34588
+ * create the gesture so users can swipe the
34589
+ * presented Toast.
34590
+ */
34591
+ if (this.prefersSwipeGesture()) {
34592
+ this.createSwipeGesture(animationPosition);
34593
+ }
34254
34594
  unlock();
34255
34595
  }
34256
34596
  /**
@@ -34285,6 +34625,11 @@ class Toast {
34285
34625
  this.revealContentToScreenReader = false;
34286
34626
  }
34287
34627
  this.lastPresentedPosition = undefined;
34628
+ /**
34629
+ * If the Toast has a swipe gesture then we can
34630
+ * safely destroy it now that it is dismissed.
34631
+ */
34632
+ this.destroySwipeGesture();
34288
34633
  unlock();
34289
34634
  return dismissed;
34290
34635
  }
@@ -34429,6 +34774,7 @@ class Toast {
34429
34774
  }
34430
34775
  get el() { return getElement(this); }
34431
34776
  static get watchers() { return {
34777
+ "swipeGesture": ["swipeGestureChanged"],
34432
34778
  "isOpen": ["onIsOpenChange"],
34433
34779
  "trigger": ["triggerChanged"]
34434
34780
  }; }
@@ -34459,6 +34805,7 @@ class Toast {
34459
34805
  "animated": [4],
34460
34806
  "icon": [1],
34461
34807
  "htmlAttributes": [16],
34808
+ "swipeGesture": [1, "swipe-gesture"],
34462
34809
  "isOpen": [4, "is-open"],
34463
34810
  "trigger": [1],
34464
34811
  "revealContentToScreenReader": [32],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ionic/core",
3
- "version": "7.5.4-dev.11699632730.1e6d9b70",
3
+ "version": "7.5.4-dev.11699895923.130c21aa",
4
4
  "description": "Base components for Ionic",
5
5
  "keywords": [
6
6
  "ionic",