UNPKG

12.5 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5const index = require('./index-a0a08b2a.js');
6const ionicGlobal = require('./ionic-global-06f21c1a.js');
7const overlays = require('./overlays-59863ad4.js');
8const index$1 = require('./index-e1bb33c3.js');
9const theme = require('./theme-30b7a575.js');
10const animation = require('./animation-13cbbb20.js');
11require('./hardware-back-button-148ce546.js');
12require('./helpers-d381ec4d.js');
13
14/**
15 * iOS Loading Enter Animation
16 */
17const iosEnterAnimation = (baseEl) => {
18 const baseAnimation = animation.createAnimation();
19 const backdropAnimation = animation.createAnimation();
20 const wrapperAnimation = animation.createAnimation();
21 backdropAnimation
22 .addElement(baseEl.querySelector('ion-backdrop'))
23 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
24 .beforeStyles({
25 'pointer-events': 'none'
26 })
27 .afterClearStyles(['pointer-events']);
28 wrapperAnimation
29 .addElement(baseEl.querySelector('.loading-wrapper'))
30 .keyframes([
31 { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
32 { offset: 1, opacity: 1, transform: 'scale(1)' }
33 ]);
34 return baseAnimation
35 .addElement(baseEl)
36 .easing('ease-in-out')
37 .duration(200)
38 .addAnimation([backdropAnimation, wrapperAnimation]);
39};
40
41/**
42 * iOS Loading Leave Animation
43 */
44const iosLeaveAnimation = (baseEl) => {
45 const baseAnimation = animation.createAnimation();
46 const backdropAnimation = animation.createAnimation();
47 const wrapperAnimation = animation.createAnimation();
48 backdropAnimation
49 .addElement(baseEl.querySelector('ion-backdrop'))
50 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
51 wrapperAnimation
52 .addElement(baseEl.querySelector('.loading-wrapper'))
53 .keyframes([
54 { offset: 0, opacity: 0.99, transform: 'scale(1)' },
55 { offset: 1, opacity: 0, transform: 'scale(0.9)' }
56 ]);
57 return baseAnimation
58 .addElement(baseEl)
59 .easing('ease-in-out')
60 .duration(200)
61 .addAnimation([backdropAnimation, wrapperAnimation]);
62};
63
64/**
65 * Md Loading Enter Animation
66 */
67const mdEnterAnimation = (baseEl) => {
68 const baseAnimation = animation.createAnimation();
69 const backdropAnimation = animation.createAnimation();
70 const wrapperAnimation = animation.createAnimation();
71 backdropAnimation
72 .addElement(baseEl.querySelector('ion-backdrop'))
73 .fromTo('opacity', 0.01, 'var(--backdrop-opacity)')
74 .beforeStyles({
75 'pointer-events': 'none'
76 })
77 .afterClearStyles(['pointer-events']);
78 wrapperAnimation
79 .addElement(baseEl.querySelector('.loading-wrapper'))
80 .keyframes([
81 { offset: 0, opacity: 0.01, transform: 'scale(1.1)' },
82 { offset: 1, opacity: 1, transform: 'scale(1)' }
83 ]);
84 return baseAnimation
85 .addElement(baseEl)
86 .easing('ease-in-out')
87 .duration(200)
88 .addAnimation([backdropAnimation, wrapperAnimation]);
89};
90
91/**
92 * Md Loading Leave Animation
93 */
94const mdLeaveAnimation = (baseEl) => {
95 const baseAnimation = animation.createAnimation();
96 const backdropAnimation = animation.createAnimation();
97 const wrapperAnimation = animation.createAnimation();
98 backdropAnimation
99 .addElement(baseEl.querySelector('ion-backdrop'))
100 .fromTo('opacity', 'var(--backdrop-opacity)', 0);
101 wrapperAnimation
102 .addElement(baseEl.querySelector('.loading-wrapper'))
103 .keyframes([
104 { offset: 0, opacity: 0.99, transform: 'scale(1)' },
105 { offset: 1, opacity: 0, transform: 'scale(0.9)' }
106 ]);
107 return baseAnimation
108 .addElement(baseEl)
109 .easing('ease-in-out')
110 .duration(200)
111 .addAnimation([backdropAnimation, wrapperAnimation]);
112};
113
114const 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}.spinner-lines.sc-ion-loading-ios,.spinner-lines-small.sc-ion-loading-ios,.spinner-bubbles.sc-ion-loading-ios,.spinner-circles.sc-ion-loading-ios,.spinner-crescent.sc-ion-loading-ios,.spinner-dots.sc-ion-loading-ios{color:var(--spinner-color)}.sc-ion-loading-ios-h{--background:var(--ion-overlay-background-color, var(--ion-color-step-100, #f9f9f9));--max-width:270px;--max-height:90%;--spinner-color:var(--ion-color-step-600, #666666);--backdrop-opacity:var(--ion-backdrop-opacity, 0.3);color:var(--ion-text-color, #000);font-size:14px}.loading-wrapper.sc-ion-loading-ios{border-radius:8px;padding-left:34px;padding-right:34px;padding-top:24px;padding-bottom:24px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.loading-wrapper.sc-ion-loading-ios{padding-left:unset;padding-right:unset;-webkit-padding-start:34px;padding-inline-start:34px;-webkit-padding-end:34px;padding-inline-end:34px}}@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{margin-left:16px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.loading-spinner.sc-ion-loading-ios+.loading-content.sc-ion-loading-ios{margin-left:unset;-webkit-margin-start:16px;margin-inline-start:16px}}";
115
116const 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}.spinner-lines.sc-ion-loading-md,.spinner-lines-small.sc-ion-loading-md,.spinner-bubbles.sc-ion-loading-md,.spinner-circles.sc-ion-loading-md,.spinner-crescent.sc-ion-loading-md,.spinner-dots.sc-ion-loading-md{color:var(--spinner-color)}.sc-ion-loading-md-h{--background:var(--ion-color-step-50, #f2f2f2);--max-width:280px;--max-height:90%;--spinner-color:var(--ion-color-primary, #3880ff);--backdrop-opacity:var(--ion-backdrop-opacity, 0.32);color:var(--ion-color-step-850, #262626);font-size:14px}.loading-wrapper.sc-ion-loading-md{border-radius:2px;padding-left:24px;padding-right: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)}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.loading-wrapper.sc-ion-loading-md{padding-left:unset;padding-right:unset;-webkit-padding-start:24px;padding-inline-start:24px;-webkit-padding-end:24px;padding-inline-end:24px}}.loading-spinner.sc-ion-loading-md+.loading-content.sc-ion-loading-md{margin-left:16px}@supports ((-webkit-margin-start: 0) or (margin-inline-start: 0)) or (-webkit-margin-start: 0){.loading-spinner.sc-ion-loading-md+.loading-content.sc-ion-loading-md{margin-left:unset;-webkit-margin-start:16px;margin-inline-start:16px}}";
117
118const Loading = class {
119 constructor(hostRef) {
120 index.registerInstance(this, hostRef);
121 this.didPresent = index.createEvent(this, "ionLoadingDidPresent", 7);
122 this.willPresent = index.createEvent(this, "ionLoadingWillPresent", 7);
123 this.willDismiss = index.createEvent(this, "ionLoadingWillDismiss", 7);
124 this.didDismiss = index.createEvent(this, "ionLoadingDidDismiss", 7);
125 this.presented = false;
126 /**
127 * If `true`, the keyboard will be automatically dismissed when the overlay is presented.
128 */
129 this.keyboardClose = true;
130 /**
131 * Number of milliseconds to wait before dismissing the loading indicator.
132 */
133 this.duration = 0;
134 /**
135 * If `true`, the loading indicator will be dismissed when the backdrop is clicked.
136 */
137 this.backdropDismiss = false;
138 /**
139 * If `true`, a backdrop will be displayed behind the loading indicator.
140 */
141 this.showBackdrop = true;
142 /**
143 * If `true`, the loading indicator will be translucent.
144 * Only applies when the mode is `"ios"` and the device supports
145 * [`backdrop-filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter#Browser_compatibility).
146 */
147 this.translucent = false;
148 /**
149 * If `true`, the loading indicator will animate.
150 */
151 this.animated = true;
152 this.onBackdropTap = () => {
153 this.dismiss(undefined, overlays.BACKDROP);
154 };
155 }
156 connectedCallback() {
157 overlays.prepareOverlay(this.el);
158 }
159 componentWillLoad() {
160 if (this.spinner === undefined) {
161 const mode = ionicGlobal.getIonMode(this);
162 this.spinner = ionicGlobal.config.get('loadingSpinner', ionicGlobal.config.get('spinner', mode === 'ios' ? 'lines' : 'crescent'));
163 }
164 }
165 /**
166 * Present the loading overlay after it has been created.
167 */
168 async present() {
169 await overlays.present(this, 'loadingEnter', iosEnterAnimation, mdEnterAnimation, undefined);
170 if (this.duration > 0) {
171 this.durationTimeout = setTimeout(() => this.dismiss(), this.duration + 10);
172 }
173 }
174 /**
175 * Dismiss the loading overlay after it has been presented.
176 *
177 * @param data Any data to emit in the dismiss events.
178 * @param role The role of the element that is dismissing the loading.
179 * This can be useful in a button handler for determining which button was
180 * clicked to dismiss the loading.
181 * Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
182 */
183 dismiss(data, role) {
184 if (this.durationTimeout) {
185 clearTimeout(this.durationTimeout);
186 }
187 return overlays.dismiss(this, data, role, 'loadingLeave', iosLeaveAnimation, mdLeaveAnimation);
188 }
189 /**
190 * Returns a promise that resolves when the loading did dismiss.
191 */
192 onDidDismiss() {
193 return overlays.eventMethod(this.el, 'ionLoadingDidDismiss');
194 }
195 /**
196 * Returns a promise that resolves when the loading will dismiss.
197 */
198 onWillDismiss() {
199 return overlays.eventMethod(this.el, 'ionLoadingWillDismiss');
200 }
201 render() {
202 const { message, spinner } = this;
203 const mode = ionicGlobal.getIonMode(this);
204 return (index.h(index.Host, { onIonBackdropTap: this.onBackdropTap, tabindex: "-1", style: {
205 zIndex: `${40000 + this.overlayIndex}`
206 }, class: Object.assign(Object.assign({}, theme.getClassMap(this.cssClass)), { [mode]: true, 'loading-translucent': this.translucent }) }, index.h("ion-backdrop", { visible: this.showBackdrop, tappable: this.backdropDismiss }), index.h("div", { tabindex: "0" }), index.h("div", { class: "loading-wrapper ion-overlay-wrapper", role: "dialog" }, spinner && (index.h("div", { class: "loading-spinner" }, index.h("ion-spinner", { name: spinner, "aria-hidden": "true" }))), message && index.h("div", { class: "loading-content", innerHTML: index$1.sanitizeDOMString(message) })), index.h("div", { tabindex: "0" })));
207 }
208 get el() { return index.getElement(this); }
209};
210Loading.style = {
211 ios: loadingIosCss,
212 md: loadingMdCss
213};
214
215exports.ion_loading = Loading;