ion-loading.cjs.entry.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /*!
  2. * (C) Ionic http://ionicframework.com - MIT License
  3. */
  4. 'use strict';
  5. Object.defineProperty(exports, '__esModule', { value: true });
  6. const index = require('./index-2e236a04.js');
  7. const config = require('./config-f6225ae7.js');
  8. const helpers = require('./helpers-8a48fdea.js');
  9. const lockController = require('./lock-controller-6585a42a.js');
  10. const overlays = require('./overlays-4c291a05.js');
  11. const theme = require('./theme-d1c573d2.js');
  12. const index$1 = require('./index-cc858e97.js');
  13. const ionicGlobal = require('./ionic-global-6dea5a96.js');
  14. const animation = require('./animation-ab2d3449.js');
  15. require('./index-c8d52405.js');
  16. require('./hardware-back-button-3d2b1004.js');
  17. require('./framework-delegate-862d9d00.js');
  18. require('./gesture-controller-9436f482.js');
  19. /**
  20. * iOS Loading Enter Animation
  21. */
  22. const iosEnterAnimation = (baseEl) => {
  23. const baseAnimation = animation.createAnimation();
  24. const backdropAnimation = animation.createAnimation();
  25. const wrapperAnimation = animation.createAnimation();
  26. backdropAnimation
  27. .addElement(baseEl.querySelector('ion-backdrop'))
  28. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  29. .beforeStyles({
  30. 'pointer-events': 'none',
  31. })
  32. .afterClearStyles(['pointer-events']);
  33. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  34. { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
  35. { offset: 1, opacity: 1, transform: 'scale(1)' },
  36. ]);
  37. return baseAnimation
  38. .addElement(baseEl)
  39. .easing('ease-in-out')
  40. .duration(200)
  41. .addAnimation([backdropAnimation, wrapperAnimation]);
  42. };
  43. /**
  44. * iOS Loading Leave Animation
  45. */
  46. const iosLeaveAnimation = (baseEl) => {
  47. const baseAnimation = animation.createAnimation();
  48. const backdropAnimation = animation.createAnimation();
  49. const wrapperAnimation = animation.createAnimation();
  50. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  51. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  52. { offset: 0, opacity: 0.99, transform: 'scale(1)' },
  53. { offset: 1, opacity: 0, transform: 'scale(0.9)' },
  54. ]);
  55. return baseAnimation
  56. .addElement(baseEl)
  57. .easing('ease-in-out')
  58. .duration(200)
  59. .addAnimation([backdropAnimation, wrapperAnimation]);
  60. };
  61. /**
  62. * Md Loading Enter Animation
  63. */
  64. const mdEnterAnimation = (baseEl) => {
  65. const baseAnimation = animation.createAnimation();
  66. const backdropAnimation = animation.createAnimation();
  67. const wrapperAnimation = animation.createAnimation();
  68. backdropAnimation
  69. .addElement(baseEl.querySelector('ion-backdrop'))
  70. .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
  71. .beforeStyles({
  72. 'pointer-events': 'none',
  73. })
  74. .afterClearStyles(['pointer-events']);
  75. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  76. { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
  77. { offset: 1, opacity: 1, transform: 'scale(1)' },
  78. ]);
  79. return baseAnimation
  80. .addElement(baseEl)
  81. .easing('ease-in-out')
  82. .duration(200)
  83. .addAnimation([backdropAnimation, wrapperAnimation]);
  84. };
  85. /**
  86. * Md Loading Leave Animation
  87. */
  88. const mdLeaveAnimation = (baseEl) => {
  89. const baseAnimation = animation.createAnimation();
  90. const backdropAnimation = animation.createAnimation();
  91. const wrapperAnimation = animation.createAnimation();
  92. backdropAnimation.addElement(baseEl.querySelector('ion-backdrop')).fromTo('opacity', 'var(--backdrop-opacity)', 0);
  93. wrapperAnimation.addElement(baseEl.querySelector('.loading-wrapper')).keyframes([
  94. { offset: 0, opacity: 0.99, transform: 'scale(1)' },
  95. { offset: 1, opacity: 0, transform: 'scale(0.9)' },
  96. ]);
  97. return baseAnimation
  98. .addElement(baseEl)
  99. .easing('ease-in-out')
  100. .duration(200)
  101. .addAnimation([backdropAnimation, wrapperAnimation]);
  102. };
  103. const loadingIosCss = ".sc-ion-loading-ios-h{--min-width:auto;--width:auto;--min-height:auto;--height:auto;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:fixed;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;outline:none;font-family:var(--ion-font-family, inherit);contain:strict;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-loading-ios-h{display:none}.loading-wrapper.sc-ion-loading-ios{display:-ms-flexbox;display:flex;-ms-flex-align:inherit;align-items:inherit;-ms-flex-pack:inherit;justify-content:inherit;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);background:var(--background);opacity:0;z-index:10}ion-spinner.sc-ion-loading-ios{color:var(--spinner-color)}.sc-ion-loading-ios-h{--background:var(--ion-overlay-background-color, var(--ion-color-step-100, var(--ion-background-color-step-100, #f9f9f9)));--max-width:270px;--max-height:90%;--spinner-color:var(--ion-color-step-600, var(--ion-text-color-step-400, #666666));--backdrop-opacity:var(--ion-backdrop-opacity, 0.3);color:var(--ion-text-color, #000);font-size:0.875rem}.loading-wrapper.sc-ion-loading-ios{border-radius:8px;-webkit-padding-start:34px;padding-inline-start:34px;-webkit-padding-end:34px;padding-inline-end:34px;padding-top:24px;padding-bottom:24px}@supports ((-webkit-backdrop-filter: blur(0)) or (backdrop-filter: blur(0))){.loading-translucent.sc-ion-loading-ios-h .loading-wrapper.sc-ion-loading-ios{background-color:rgba(var(--ion-background-color-rgb, 255, 255, 255), 0.8);-webkit-backdrop-filter:saturate(180%) blur(20px);backdrop-filter:saturate(180%) blur(20px)}}.loading-content.sc-ion-loading-ios{font-weight:bold}.loading-spinner.sc-ion-loading-ios+.loading-content.sc-ion-loading-ios{-webkit-margin-start:16px;margin-inline-start:16px}";
  104. const IonLoadingIosStyle0 = loadingIosCss;
  105. const loadingMdCss = ".sc-ion-loading-md-h{--min-width:auto;--width:auto;--min-height:auto;--height:auto;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased;left:0;right:0;top:0;bottom:0;display:-ms-flexbox;display:flex;position:fixed;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;outline:none;font-family:var(--ion-font-family, inherit);contain:strict;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;z-index:1001}.overlay-hidden.sc-ion-loading-md-h{display:none}.loading-wrapper.sc-ion-loading-md{display:-ms-flexbox;display:flex;-ms-flex-align:inherit;align-items:inherit;-ms-flex-pack:inherit;justify-content:inherit;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);background:var(--background);opacity:0;z-index:10}ion-spinner.sc-ion-loading-md{color:var(--spinner-color)}.sc-ion-loading-md-h{--background:var(--ion-color-step-50, var(--ion-background-color-step-50, #f2f2f2));--max-width:280px;--max-height:90%;--spinner-color:var(--ion-color-primary, #0054e9);--backdrop-opacity:var(--ion-backdrop-opacity, 0.32);color:var(--ion-color-step-850, var(--ion-text-color-step-150, #262626));font-size:0.875rem}.loading-wrapper.sc-ion-loading-md{border-radius:2px;-webkit-padding-start:24px;padding-inline-start:24px;-webkit-padding-end:24px;padding-inline-end:24px;padding-top:24px;padding-bottom:24px;-webkit-box-shadow:0 16px 20px rgba(0, 0, 0, 0.4);box-shadow:0 16px 20px rgba(0, 0, 0, 0.4)}.loading-spinner.sc-ion-loading-md+.loading-content.sc-ion-loading-md{-webkit-margin-start:16px;margin-inline-start:16px}";
  106. const IonLoadingMdStyle0 = loadingMdCss;
  107. const Loading = class {
  108. constructor(hostRef) {
  109. index.registerInstance(this, hostRef);
  110. this.didPresent = index.createEvent(this, "ionLoadingDidPresent", 7);
  111. this.willPresent = index.createEvent(this, "ionLoadingWillPresent", 7);
  112. this.willDismiss = index.createEvent(this, "ionLoadingWillDismiss", 7);
  113. this.didDismiss = index.createEvent(this, "ionLoadingDidDismiss", 7);
  114. this.didPresentShorthand = index.createEvent(this, "didPresent", 7);
  115. this.willPresentShorthand = index.createEvent(this, "willPresent", 7);
  116. this.willDismissShorthand = index.createEvent(this, "willDismiss", 7);
  117. this.didDismissShorthand = index.createEvent(this, "didDismiss", 7);
  118. this.delegateController = overlays.createDelegateController(this);
  119. this.lockController = lockController.createLockController();
  120. this.triggerController = overlays.createTriggerController();
  121. this.customHTMLEnabled = index$1.config.get('innerHTMLTemplatesEnabled', config.ENABLE_HTML_CONTENT_DEFAULT);
  122. this.presented = false;
  123. this.onBackdropTap = () => {
  124. this.dismiss(undefined, overlays.BACKDROP);
  125. };
  126. this.overlayIndex = undefined;
  127. this.delegate = undefined;
  128. this.hasController = false;
  129. this.keyboardClose = true;
  130. this.enterAnimation = undefined;
  131. this.leaveAnimation = undefined;
  132. this.message = undefined;
  133. this.cssClass = undefined;
  134. this.duration = 0;
  135. this.backdropDismiss = false;
  136. this.showBackdrop = true;
  137. this.spinner = undefined;
  138. this.translucent = false;
  139. this.animated = true;
  140. this.htmlAttributes = undefined;
  141. this.isOpen = false;
  142. this.trigger = undefined;
  143. }
  144. onIsOpenChange(newValue, oldValue) {
  145. if (newValue === true && oldValue === false) {
  146. this.present();
  147. }
  148. else if (newValue === false && oldValue === true) {
  149. this.dismiss();
  150. }
  151. }
  152. triggerChanged() {
  153. const { trigger, el, triggerController } = this;
  154. if (trigger) {
  155. triggerController.addClickListener(el, trigger);
  156. }
  157. }
  158. connectedCallback() {
  159. overlays.prepareOverlay(this.el);
  160. this.triggerChanged();
  161. }
  162. componentWillLoad() {
  163. var _a;
  164. if (this.spinner === undefined) {
  165. const mode = ionicGlobal.getIonMode(this);
  166. this.spinner = index$1.config.get('loadingSpinner', index$1.config.get('spinner', mode === 'ios' ? 'lines' : 'crescent'));
  167. }
  168. if (!((_a = this.htmlAttributes) === null || _a === void 0 ? void 0 : _a.id)) {
  169. overlays.setOverlayId(this.el);
  170. }
  171. }
  172. componentDidLoad() {
  173. /**
  174. * If loading indicator was rendered with isOpen="true"
  175. * then we should open loading indicator immediately.
  176. */
  177. if (this.isOpen === true) {
  178. helpers.raf(() => this.present());
  179. }
  180. /**
  181. * When binding values in frameworks such as Angular
  182. * it is possible for the value to be set after the Web Component
  183. * initializes but before the value watcher is set up in Stencil.
  184. * As a result, the watcher callback may not be fired.
  185. * We work around this by manually calling the watcher
  186. * callback when the component has loaded and the watcher
  187. * is configured.
  188. */
  189. this.triggerChanged();
  190. }
  191. disconnectedCallback() {
  192. this.triggerController.removeClickListener();
  193. }
  194. /**
  195. * Present the loading overlay after it has been created.
  196. */
  197. async present() {
  198. const unlock = await this.lockController.lock();
  199. await this.delegateController.attachViewToDom();
  200. await overlays.present(this, 'loadingEnter', iosEnterAnimation, mdEnterAnimation);
  201. if (this.duration > 0) {
  202. this.durationTimeout = setTimeout(() => this.dismiss(), this.duration + 10);
  203. }
  204. unlock();
  205. }
  206. /**
  207. * Dismiss the loading overlay after it has been presented.
  208. *
  209. * @param data Any data to emit in the dismiss events.
  210. * @param role The role of the element that is dismissing the loading.
  211. * This can be useful in a button handler for determining which button was
  212. * clicked to dismiss the loading.
  213. * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
  214. *
  215. * This is a no-op if the overlay has not been presented yet. If you want
  216. * to remove an overlay from the DOM that was never presented, use the
  217. * [remove](https://developer.mozilla.org/en-US/docs/Web/API/Element/remove) method.
  218. */
  219. async dismiss(data, role) {
  220. const unlock = await this.lockController.lock();
  221. if (this.durationTimeout) {
  222. clearTimeout(this.durationTimeout);
  223. }
  224. const dismissed = await overlays.dismiss(this, data, role, 'loadingLeave', iosLeaveAnimation, mdLeaveAnimation);
  225. if (dismissed) {
  226. this.delegateController.removeViewFromDom();
  227. }
  228. unlock();
  229. return dismissed;
  230. }
  231. /**
  232. * Returns a promise that resolves when the loading did dismiss.
  233. */
  234. onDidDismiss() {
  235. return overlays.eventMethod(this.el, 'ionLoadingDidDismiss');
  236. }
  237. /**
  238. * Returns a promise that resolves when the loading will dismiss.
  239. */
  240. onWillDismiss() {
  241. return overlays.eventMethod(this.el, 'ionLoadingWillDismiss');
  242. }
  243. renderLoadingMessage(msgId) {
  244. const { customHTMLEnabled, message } = this;
  245. if (customHTMLEnabled) {
  246. return index.h("div", { class: "loading-content", id: msgId, innerHTML: config.sanitizeDOMString(message) });
  247. }
  248. return (index.h("div", { class: "loading-content", id: msgId }, message));
  249. }
  250. render() {
  251. const { message, spinner, htmlAttributes, overlayIndex } = this;
  252. const mode = ionicGlobal.getIonMode(this);
  253. const msgId = `loading-${overlayIndex}-msg`;
  254. /**
  255. * If the message is defined, use that as the label.
  256. * Otherwise, don't set aria-labelledby.
  257. */
  258. const ariaLabelledBy = message !== undefined ? msgId : null;
  259. return (index.h(index.Host, Object.assign({ key: 'd6066c8b56b1fe4b597a243a7dab191ef0d21286', role: "dialog", "aria-modal": "true", "aria-labelledby": ariaLabelledBy, tabindex: "-1" }, htmlAttributes, { style: {
  260. zIndex: `${40000 + this.overlayIndex}`,
  261. }, onIonBackdropTap: this.onBackdropTap, class: Object.assign(Object.assign({}, theme.getClassMap(this.cssClass)), { [mode]: true, 'overlay-hidden': true, 'loading-translucent': this.translucent }) }), index.h("ion-backdrop", { key: '2431eda00a2a3f510f5dfc39b7c7d47c056dfa3d', visible: this.showBackdrop, tappable: this.backdropDismiss }), index.h("div", { key: 'cf210aaf5e754e4eccdb49cf7ead4647b3f9b2d1', tabindex: "0", "aria-hidden": "true" }), index.h("div", { key: 'fa9375143d391656d70e181d25b952c77c2fc6ec', class: "loading-wrapper ion-overlay-wrapper" }, spinner && (index.h("div", { key: '8e4a4ed994f7f62df86b03696ac95162df41f52d', class: "loading-spinner" }, index.h("ion-spinner", { key: 'e5b323c272d365853ba92bd211e390b4fd4751d2', name: spinner, "aria-hidden": "true" }))), message !== undefined && this.renderLoadingMessage(msgId)), index.h("div", { key: 'cae35ec8c34800477bff3ebcec8010e632158233', tabindex: "0", "aria-hidden": "true" })));
  262. }
  263. get el() { return index.getElement(this); }
  264. static get watchers() { return {
  265. "isOpen": ["onIsOpenChange"],
  266. "trigger": ["triggerChanged"]
  267. }; }
  268. };
  269. Loading.style = {
  270. ios: IonLoadingIosStyle0,
  271. md: IonLoadingMdStyle0
  272. };
  273. exports.ion_loading = Loading;