sweetalert2 11.3.9 → 11.4.2

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.
@@ -0,0 +1,3403 @@
1
+ /*!
2
+ * sweetalert2 v11.4.2
3
+ * Released under the MIT License.
4
+ */
5
+ (function (global, factory) {
6
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
7
+ typeof define === 'function' && define.amd ? define(factory) :
8
+ (global = global || self, global.Sweetalert2 = factory());
9
+ }(this, function () { 'use strict';
10
+
11
+ const consolePrefix = 'SweetAlert2:';
12
+ /**
13
+ * Filter the unique values into a new array
14
+ * @param arr
15
+ */
16
+
17
+ const uniqueArray = arr => {
18
+ const result = [];
19
+
20
+ for (let i = 0; i < arr.length; i++) {
21
+ if (result.indexOf(arr[i]) === -1) {
22
+ result.push(arr[i]);
23
+ }
24
+ }
25
+
26
+ return result;
27
+ };
28
+ /**
29
+ * Capitalize the first letter of a string
30
+ * @param {string} str
31
+ * @returns {string}
32
+ */
33
+
34
+ const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);
35
+ /**
36
+ * @param {NodeList | HTMLCollection | NamedNodeMap} nodeList
37
+ * @returns {array}
38
+ */
39
+
40
+ const toArray = nodeList => Array.prototype.slice.call(nodeList);
41
+ /**
42
+ * Standardize console warnings
43
+ * @param {string | array} message
44
+ */
45
+
46
+ const warn = message => {
47
+ console.warn("".concat(consolePrefix, " ").concat(typeof message === 'object' ? message.join(' ') : message));
48
+ };
49
+ /**
50
+ * Standardize console errors
51
+ * @param {string} message
52
+ */
53
+
54
+ const error = message => {
55
+ console.error("".concat(consolePrefix, " ").concat(message));
56
+ };
57
+ /**
58
+ * Private global state for `warnOnce`
59
+ * @type {Array}
60
+ * @private
61
+ */
62
+
63
+ const previousWarnOnceMessages = [];
64
+ /**
65
+ * Show a console warning, but only if it hasn't already been shown
66
+ * @param {string} message
67
+ */
68
+
69
+ const warnOnce = message => {
70
+ if (!previousWarnOnceMessages.includes(message)) {
71
+ previousWarnOnceMessages.push(message);
72
+ warn(message);
73
+ }
74
+ };
75
+ /**
76
+ * Show a one-time console warning about deprecated params/methods
77
+ */
78
+
79
+ const warnAboutDeprecation = (deprecatedParam, useInstead) => {
80
+ warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
81
+ };
82
+ /**
83
+ * If `arg` is a function, call it (with no arguments or context) and return the result.
84
+ * Otherwise, just pass the value through
85
+ * @param arg
86
+ */
87
+
88
+ const callIfFunction = arg => typeof arg === 'function' ? arg() : arg;
89
+ const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function';
90
+ const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
91
+ const isPromise = arg => arg && Promise.resolve(arg) === arg;
92
+
93
+ const defaultParams = {
94
+ title: '',
95
+ titleText: '',
96
+ text: '',
97
+ html: '',
98
+ footer: '',
99
+ icon: undefined,
100
+ iconColor: undefined,
101
+ iconHtml: undefined,
102
+ template: undefined,
103
+ toast: false,
104
+ showClass: {
105
+ popup: 'swal2-show',
106
+ backdrop: 'swal2-backdrop-show',
107
+ icon: 'swal2-icon-show'
108
+ },
109
+ hideClass: {
110
+ popup: 'swal2-hide',
111
+ backdrop: 'swal2-backdrop-hide',
112
+ icon: 'swal2-icon-hide'
113
+ },
114
+ customClass: {},
115
+ target: 'body',
116
+ color: undefined,
117
+ backdrop: true,
118
+ heightAuto: true,
119
+ allowOutsideClick: true,
120
+ allowEscapeKey: true,
121
+ allowEnterKey: true,
122
+ stopKeydownPropagation: true,
123
+ keydownListenerCapture: false,
124
+ showConfirmButton: true,
125
+ showDenyButton: false,
126
+ showCancelButton: false,
127
+ preConfirm: undefined,
128
+ preDeny: undefined,
129
+ confirmButtonText: 'OK',
130
+ confirmButtonAriaLabel: '',
131
+ confirmButtonColor: undefined,
132
+ denyButtonText: 'No',
133
+ denyButtonAriaLabel: '',
134
+ denyButtonColor: undefined,
135
+ cancelButtonText: 'Cancel',
136
+ cancelButtonAriaLabel: '',
137
+ cancelButtonColor: undefined,
138
+ buttonsStyling: true,
139
+ reverseButtons: false,
140
+ focusConfirm: true,
141
+ focusDeny: false,
142
+ focusCancel: false,
143
+ returnFocus: true,
144
+ showCloseButton: false,
145
+ closeButtonHtml: '&times;',
146
+ closeButtonAriaLabel: 'Close this dialog',
147
+ loaderHtml: '',
148
+ showLoaderOnConfirm: false,
149
+ showLoaderOnDeny: false,
150
+ imageUrl: undefined,
151
+ imageWidth: undefined,
152
+ imageHeight: undefined,
153
+ imageAlt: '',
154
+ timer: undefined,
155
+ timerProgressBar: false,
156
+ width: undefined,
157
+ padding: undefined,
158
+ background: undefined,
159
+ input: undefined,
160
+ inputPlaceholder: '',
161
+ inputLabel: '',
162
+ inputValue: '',
163
+ inputOptions: {},
164
+ inputAutoTrim: true,
165
+ inputAttributes: {},
166
+ inputValidator: undefined,
167
+ returnInputValueOnDeny: false,
168
+ validationMessage: undefined,
169
+ grow: false,
170
+ position: 'center',
171
+ progressSteps: [],
172
+ currentProgressStep: undefined,
173
+ progressStepsDistance: undefined,
174
+ willOpen: undefined,
175
+ didOpen: undefined,
176
+ didRender: undefined,
177
+ willClose: undefined,
178
+ didClose: undefined,
179
+ didDestroy: undefined,
180
+ scrollbarPadding: true
181
+ };
182
+ const updatableParams = ['allowEscapeKey', 'allowOutsideClick', 'background', 'buttonsStyling', 'cancelButtonAriaLabel', 'cancelButtonColor', 'cancelButtonText', 'closeButtonAriaLabel', 'closeButtonHtml', 'color', 'confirmButtonAriaLabel', 'confirmButtonColor', 'confirmButtonText', 'currentProgressStep', 'customClass', 'denyButtonAriaLabel', 'denyButtonColor', 'denyButtonText', 'didClose', 'didDestroy', 'footer', 'hideClass', 'html', 'icon', 'iconColor', 'iconHtml', 'imageAlt', 'imageHeight', 'imageUrl', 'imageWidth', 'preConfirm', 'preDeny', 'progressSteps', 'returnFocus', 'reverseButtons', 'showCancelButton', 'showCloseButton', 'showConfirmButton', 'showDenyButton', 'text', 'title', 'titleText', 'willClose'];
183
+ const deprecatedParams = {};
184
+ const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
185
+ /**
186
+ * Is valid parameter
187
+ * @param {string} paramName
188
+ */
189
+
190
+ const isValidParameter = paramName => {
191
+ return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
192
+ };
193
+ /**
194
+ * Is valid parameter for Swal.update() method
195
+ * @param {string} paramName
196
+ */
197
+
198
+ const isUpdatableParameter = paramName => {
199
+ return updatableParams.indexOf(paramName) !== -1;
200
+ };
201
+ /**
202
+ * Is deprecated parameter
203
+ * @param {string} paramName
204
+ */
205
+
206
+ const isDeprecatedParameter = paramName => {
207
+ return deprecatedParams[paramName];
208
+ };
209
+
210
+ const checkIfParamIsValid = param => {
211
+ if (!isValidParameter(param)) {
212
+ warn("Unknown parameter \"".concat(param, "\""));
213
+ }
214
+ };
215
+
216
+ const checkIfToastParamIsValid = param => {
217
+ if (toastIncompatibleParams.includes(param)) {
218
+ warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
219
+ }
220
+ };
221
+
222
+ const checkIfParamIsDeprecated = param => {
223
+ if (isDeprecatedParameter(param)) {
224
+ warnAboutDeprecation(param, isDeprecatedParameter(param));
225
+ }
226
+ };
227
+ /**
228
+ * Show relevant warnings for given params
229
+ *
230
+ * @param params
231
+ */
232
+
233
+
234
+ const showWarningsForParams = params => {
235
+ if (!params.backdrop && params.allowOutsideClick) {
236
+ warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
237
+ }
238
+
239
+ for (const param in params) {
240
+ checkIfParamIsValid(param);
241
+
242
+ if (params.toast) {
243
+ checkIfToastParamIsValid(param);
244
+ }
245
+
246
+ checkIfParamIsDeprecated(param);
247
+ }
248
+ };
249
+
250
+ const swalPrefix = 'swal2-';
251
+ const prefix = items => {
252
+ const result = {};
253
+
254
+ for (const i in items) {
255
+ result[items[i]] = swalPrefix + items[i];
256
+ }
257
+
258
+ return result;
259
+ };
260
+ const swalClasses = prefix(['container', 'shown', 'height-auto', 'iosfix', 'popup', 'modal', 'no-backdrop', 'no-transition', 'toast', 'toast-shown', 'show', 'hide', 'close', 'title', 'html-container', 'actions', 'confirm', 'deny', 'cancel', 'default-outline', 'footer', 'icon', 'icon-content', 'image', 'input', 'file', 'range', 'select', 'radio', 'checkbox', 'label', 'textarea', 'inputerror', 'input-label', 'validation-message', 'progress-steps', 'active-progress-step', 'progress-step', 'progress-step-line', 'loader', 'loading', 'styled', 'top', 'top-start', 'top-end', 'top-left', 'top-right', 'center', 'center-start', 'center-end', 'center-left', 'center-right', 'bottom', 'bottom-start', 'bottom-end', 'bottom-left', 'bottom-right', 'grow-row', 'grow-column', 'grow-fullscreen', 'rtl', 'timer-progress-bar', 'timer-progress-bar-container', 'scrollbar-measure', 'icon-success', 'icon-warning', 'icon-info', 'icon-question', 'icon-error']);
261
+ const iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
262
+
263
+ /**
264
+ * Gets the popup container which contains the backdrop and the popup itself.
265
+ *
266
+ * @returns {HTMLElement | null}
267
+ */
268
+
269
+ const getContainer = () => document.body.querySelector(".".concat(swalClasses.container));
270
+ const elementBySelector = selectorString => {
271
+ const container = getContainer();
272
+ return container ? container.querySelector(selectorString) : null;
273
+ };
274
+
275
+ const elementByClass = className => {
276
+ return elementBySelector(".".concat(className));
277
+ };
278
+
279
+ const getPopup = () => elementByClass(swalClasses.popup);
280
+ const getIcon = () => elementByClass(swalClasses.icon);
281
+ const getTitle = () => elementByClass(swalClasses.title);
282
+ const getHtmlContainer = () => elementByClass(swalClasses['html-container']);
283
+ const getImage = () => elementByClass(swalClasses.image);
284
+ const getProgressSteps = () => elementByClass(swalClasses['progress-steps']);
285
+ const getValidationMessage = () => elementByClass(swalClasses['validation-message']);
286
+ const getConfirmButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm));
287
+ const getDenyButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.deny));
288
+ const getInputLabel = () => elementByClass(swalClasses['input-label']);
289
+ const getLoader = () => elementBySelector(".".concat(swalClasses.loader));
290
+ const getCancelButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel));
291
+ const getActions = () => elementByClass(swalClasses.actions);
292
+ const getFooter = () => elementByClass(swalClasses.footer);
293
+ const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']);
294
+ const getCloseButton = () => elementByClass(swalClasses.close); // https://github.com/jkup/focusable/blob/master/index.js
295
+
296
+ const focusable = "\n a[href],\n area[href],\n input:not([disabled]),\n select:not([disabled]),\n textarea:not([disabled]),\n button:not([disabled]),\n iframe,\n object,\n embed,\n [tabindex=\"0\"],\n [contenteditable],\n audio[controls],\n video[controls],\n summary\n";
297
+ const getFocusableElements = () => {
298
+ const focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex
299
+ .sort((a, b) => {
300
+ const tabindexA = parseInt(a.getAttribute('tabindex'));
301
+ const tabindexB = parseInt(b.getAttribute('tabindex'));
302
+
303
+ if (tabindexA > tabindexB) {
304
+ return 1;
305
+ } else if (tabindexA < tabindexB) {
306
+ return -1;
307
+ }
308
+
309
+ return 0;
310
+ });
311
+ const otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(el => el.getAttribute('tabindex') !== '-1');
312
+ return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el));
313
+ };
314
+ const isModal = () => {
315
+ return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
316
+ };
317
+ const isToast = () => {
318
+ return getPopup() && hasClass(getPopup(), swalClasses.toast);
319
+ };
320
+ const isLoading = () => {
321
+ return getPopup().hasAttribute('data-loading');
322
+ };
323
+
324
+ const states = {
325
+ previousBodyPadding: null
326
+ };
327
+ /**
328
+ * Securely set innerHTML of an element
329
+ * https://github.com/sweetalert2/sweetalert2/issues/1926
330
+ *
331
+ * @param {HTMLElement} elem
332
+ * @param {string} html
333
+ */
334
+
335
+ const setInnerHtml = (elem, html) => {
336
+ elem.textContent = '';
337
+
338
+ if (html) {
339
+ const parser = new DOMParser();
340
+ const parsed = parser.parseFromString(html, "text/html");
341
+ toArray(parsed.querySelector('head').childNodes).forEach(child => {
342
+ elem.appendChild(child);
343
+ });
344
+ toArray(parsed.querySelector('body').childNodes).forEach(child => {
345
+ elem.appendChild(child);
346
+ });
347
+ }
348
+ };
349
+ /**
350
+ * @param {HTMLElement} elem
351
+ * @param {string} className
352
+ * @returns {boolean}
353
+ */
354
+
355
+ const hasClass = (elem, className) => {
356
+ if (!className) {
357
+ return false;
358
+ }
359
+
360
+ const classList = className.split(/\s+/);
361
+
362
+ for (let i = 0; i < classList.length; i++) {
363
+ if (!elem.classList.contains(classList[i])) {
364
+ return false;
365
+ }
366
+ }
367
+
368
+ return true;
369
+ };
370
+
371
+ const removeCustomClasses = (elem, params) => {
372
+ toArray(elem.classList).forEach(className => {
373
+ if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass).includes(className)) {
374
+ elem.classList.remove(className);
375
+ }
376
+ });
377
+ };
378
+
379
+ const applyCustomClass = (elem, params, className) => {
380
+ removeCustomClasses(elem, params);
381
+
382
+ if (params.customClass && params.customClass[className]) {
383
+ if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
384
+ return warn("Invalid type of customClass.".concat(className, "! Expected string or iterable object, got \"").concat(typeof params.customClass[className], "\""));
385
+ }
386
+
387
+ addClass(elem, params.customClass[className]);
388
+ }
389
+ };
390
+ /**
391
+ * @param {HTMLElement} popup
392
+ * @param {string} inputType
393
+ * @returns {HTMLInputElement | null}
394
+ */
395
+
396
+ const getInput = (popup, inputType) => {
397
+ if (!inputType) {
398
+ return null;
399
+ }
400
+
401
+ switch (inputType) {
402
+ case 'select':
403
+ case 'textarea':
404
+ case 'file':
405
+ return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses[inputType]));
406
+
407
+ case 'checkbox':
408
+ return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.checkbox, " input"));
409
+
410
+ case 'radio':
411
+ return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:checked")) || popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:first-child"));
412
+
413
+ case 'range':
414
+ return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.range, " input"));
415
+
416
+ default:
417
+ return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.input));
418
+ }
419
+ };
420
+ /**
421
+ * @param {HTMLInputElement} input
422
+ */
423
+
424
+ const focusInput = input => {
425
+ input.focus(); // place cursor at end of text in text input
426
+
427
+ if (input.type !== 'file') {
428
+ // http://stackoverflow.com/a/2345915
429
+ const val = input.value;
430
+ input.value = '';
431
+ input.value = val;
432
+ }
433
+ };
434
+ /**
435
+ * @param {HTMLElement | HTMLElement[] | null} target
436
+ * @param {string | string[]} classList
437
+ * @param {boolean} condition
438
+ */
439
+
440
+ const toggleClass = (target, classList, condition) => {
441
+ if (!target || !classList) {
442
+ return;
443
+ }
444
+
445
+ if (typeof classList === 'string') {
446
+ classList = classList.split(/\s+/).filter(Boolean);
447
+ }
448
+
449
+ classList.forEach(className => {
450
+ if (Array.isArray(target)) {
451
+ target.forEach(elem => {
452
+ condition ? elem.classList.add(className) : elem.classList.remove(className);
453
+ });
454
+ } else {
455
+ condition ? target.classList.add(className) : target.classList.remove(className);
456
+ }
457
+ });
458
+ };
459
+ /**
460
+ * @param {HTMLElement | HTMLElement[] | null} target
461
+ * @param {string | string[]} classList
462
+ */
463
+
464
+ const addClass = (target, classList) => {
465
+ toggleClass(target, classList, true);
466
+ };
467
+ /**
468
+ * @param {HTMLElement | HTMLElement[] | null} target
469
+ * @param {string | string[]} classList
470
+ */
471
+
472
+ const removeClass = (target, classList) => {
473
+ toggleClass(target, classList, false);
474
+ };
475
+ /**
476
+ * Get direct child of an element by class name
477
+ *
478
+ * @param {HTMLElement} elem
479
+ * @param {string} className
480
+ * @returns {HTMLElement | null}
481
+ */
482
+
483
+ const getDirectChildByClass = (elem, className) => {
484
+ const childNodes = toArray(elem.childNodes);
485
+
486
+ for (let i = 0; i < childNodes.length; i++) {
487
+ if (hasClass(childNodes[i], className)) {
488
+ return childNodes[i];
489
+ }
490
+ }
491
+ };
492
+ /**
493
+ * @param {HTMLElement} elem
494
+ * @param {string} property
495
+ * @param {*} value
496
+ */
497
+
498
+ const applyNumericalStyle = (elem, property, value) => {
499
+ if (value === "".concat(parseInt(value))) {
500
+ value = parseInt(value);
501
+ }
502
+
503
+ if (value || parseInt(value) === 0) {
504
+ elem.style[property] = typeof value === 'number' ? "".concat(value, "px") : value;
505
+ } else {
506
+ elem.style.removeProperty(property);
507
+ }
508
+ };
509
+ /**
510
+ * @param {HTMLElement} elem
511
+ * @param {string} display
512
+ */
513
+
514
+ const show = function (elem) {
515
+ let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
516
+ elem.style.display = display;
517
+ };
518
+ /**
519
+ * @param {HTMLElement} elem
520
+ */
521
+
522
+ const hide = elem => {
523
+ elem.style.display = 'none';
524
+ };
525
+ const setStyle = (parent, selector, property, value) => {
526
+ const el = parent.querySelector(selector);
527
+
528
+ if (el) {
529
+ el.style[property] = value;
530
+ }
531
+ };
532
+ const toggle = (elem, condition, display) => {
533
+ condition ? show(elem, display) : hide(elem);
534
+ }; // borrowed from jquery $(elem).is(':visible') implementation
535
+
536
+ const isVisible = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
537
+ const allButtonsAreHidden = () => !isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton());
538
+ const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight); // borrowed from https://stackoverflow.com/a/46352119
539
+
540
+ const hasCssAnimation = elem => {
541
+ const style = window.getComputedStyle(elem);
542
+ const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
543
+ const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
544
+ return animDuration > 0 || transDuration > 0;
545
+ };
546
+ const animateTimerProgressBar = function (timer) {
547
+ let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
548
+ const timerProgressBar = getTimerProgressBar();
549
+
550
+ if (isVisible(timerProgressBar)) {
551
+ if (reset) {
552
+ timerProgressBar.style.transition = 'none';
553
+ timerProgressBar.style.width = '100%';
554
+ }
555
+
556
+ setTimeout(() => {
557
+ timerProgressBar.style.transition = "width ".concat(timer / 1000, "s linear");
558
+ timerProgressBar.style.width = '0%';
559
+ }, 10);
560
+ }
561
+ };
562
+ const stopTimerProgressBar = () => {
563
+ const timerProgressBar = getTimerProgressBar();
564
+ const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
565
+ timerProgressBar.style.removeProperty('transition');
566
+ timerProgressBar.style.width = '100%';
567
+ const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
568
+ const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
569
+ timerProgressBar.style.removeProperty('transition');
570
+ timerProgressBar.style.width = "".concat(timerProgressBarPercent, "%");
571
+ };
572
+
573
+ /**
574
+ * Detect Node env
575
+ *
576
+ * @returns {boolean}
577
+ */
578
+ const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined';
579
+
580
+ const RESTORE_FOCUS_TIMEOUT = 100;
581
+
582
+ const globalState = {};
583
+
584
+ const focusPreviousActiveElement = () => {
585
+ if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
586
+ globalState.previousActiveElement.focus();
587
+ globalState.previousActiveElement = null;
588
+ } else if (document.body) {
589
+ document.body.focus();
590
+ }
591
+ }; // Restore previous active (focused) element
592
+
593
+
594
+ const restoreActiveElement = returnFocus => {
595
+ return new Promise(resolve => {
596
+ if (!returnFocus) {
597
+ return resolve();
598
+ }
599
+
600
+ const x = window.scrollX;
601
+ const y = window.scrollY;
602
+ globalState.restoreFocusTimeout = setTimeout(() => {
603
+ focusPreviousActiveElement();
604
+ resolve();
605
+ }, RESTORE_FOCUS_TIMEOUT); // issues/900
606
+
607
+ window.scrollTo(x, y);
608
+ });
609
+ };
610
+
611
+ const sweetHTML = "\n <div aria-labelledby=\"".concat(swalClasses.title, "\" aria-describedby=\"").concat(swalClasses['html-container'], "\" class=\"").concat(swalClasses.popup, "\" tabindex=\"-1\">\n <button type=\"button\" class=\"").concat(swalClasses.close, "\"></button>\n <ul class=\"").concat(swalClasses['progress-steps'], "\"></ul>\n <div class=\"").concat(swalClasses.icon, "\"></div>\n <img class=\"").concat(swalClasses.image, "\" />\n <h2 class=\"").concat(swalClasses.title, "\" id=\"").concat(swalClasses.title, "\"></h2>\n <div class=\"").concat(swalClasses['html-container'], "\" id=\"").concat(swalClasses['html-container'], "\"></div>\n <input class=\"").concat(swalClasses.input, "\" />\n <input type=\"file\" class=\"").concat(swalClasses.file, "\" />\n <div class=\"").concat(swalClasses.range, "\">\n <input type=\"range\" />\n <output></output>\n </div>\n <select class=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label for=\"").concat(swalClasses.checkbox, "\" class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\"></textarea>\n <div class=\"").concat(swalClasses['validation-message'], "\" id=\"").concat(swalClasses['validation-message'], "\"></div>\n <div class=\"").concat(swalClasses.actions, "\">\n <div class=\"").concat(swalClasses.loader, "\"></div>\n <button type=\"button\" class=\"").concat(swalClasses.confirm, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.deny, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.cancel, "\"></button>\n </div>\n <div class=\"").concat(swalClasses.footer, "\"></div>\n <div class=\"").concat(swalClasses['timer-progress-bar-container'], "\">\n <div class=\"").concat(swalClasses['timer-progress-bar'], "\"></div>\n </div>\n </div>\n").replace(/(^|\n)\s*/g, '');
612
+
613
+ const resetOldContainer = () => {
614
+ const oldContainer = getContainer();
615
+
616
+ if (!oldContainer) {
617
+ return false;
618
+ }
619
+
620
+ oldContainer.remove();
621
+ removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
622
+ return true;
623
+ };
624
+
625
+ const resetValidationMessage = () => {
626
+ globalState.currentInstance.resetValidationMessage();
627
+ };
628
+
629
+ const addInputChangeListeners = () => {
630
+ const popup = getPopup();
631
+ const input = getDirectChildByClass(popup, swalClasses.input);
632
+ const file = getDirectChildByClass(popup, swalClasses.file);
633
+ const range = popup.querySelector(".".concat(swalClasses.range, " input"));
634
+ const rangeOutput = popup.querySelector(".".concat(swalClasses.range, " output"));
635
+ const select = getDirectChildByClass(popup, swalClasses.select);
636
+ const checkbox = popup.querySelector(".".concat(swalClasses.checkbox, " input"));
637
+ const textarea = getDirectChildByClass(popup, swalClasses.textarea);
638
+ input.oninput = resetValidationMessage;
639
+ file.onchange = resetValidationMessage;
640
+ select.onchange = resetValidationMessage;
641
+ checkbox.onchange = resetValidationMessage;
642
+ textarea.oninput = resetValidationMessage;
643
+
644
+ range.oninput = () => {
645
+ resetValidationMessage();
646
+ rangeOutput.value = range.value;
647
+ };
648
+
649
+ range.onchange = () => {
650
+ resetValidationMessage();
651
+ range.nextSibling.value = range.value;
652
+ };
653
+ };
654
+
655
+ const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target;
656
+
657
+ const setupAccessibility = params => {
658
+ const popup = getPopup();
659
+ popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
660
+ popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
661
+
662
+ if (!params.toast) {
663
+ popup.setAttribute('aria-modal', 'true');
664
+ }
665
+ };
666
+
667
+ const setupRTL = targetElement => {
668
+ if (window.getComputedStyle(targetElement).direction === 'rtl') {
669
+ addClass(getContainer(), swalClasses.rtl);
670
+ }
671
+ };
672
+ /*
673
+ * Add modal + backdrop to DOM
674
+ */
675
+
676
+
677
+ const init = params => {
678
+ // Clean up the old popup container if it exists
679
+ const oldContainerExisted = resetOldContainer();
680
+ /* istanbul ignore if */
681
+
682
+ if (isNodeEnv()) {
683
+ error('SweetAlert2 requires document to initialize');
684
+ return;
685
+ }
686
+
687
+ const container = document.createElement('div');
688
+ container.className = swalClasses.container;
689
+
690
+ if (oldContainerExisted) {
691
+ addClass(container, swalClasses['no-transition']);
692
+ }
693
+
694
+ setInnerHtml(container, sweetHTML);
695
+ const targetElement = getTarget(params.target);
696
+ targetElement.appendChild(container);
697
+ setupAccessibility(params);
698
+ setupRTL(targetElement);
699
+ addInputChangeListeners();
700
+ };
701
+
702
+ /**
703
+ * @param {HTMLElement | object | string} param
704
+ * @param {HTMLElement} target
705
+ */
706
+
707
+ const parseHtmlToContainer = (param, target) => {
708
+ // DOM element
709
+ if (param instanceof HTMLElement) {
710
+ target.appendChild(param);
711
+ } // Object
712
+ else if (typeof param === 'object') {
713
+ handleObject(param, target);
714
+ } // Plain string
715
+ else if (param) {
716
+ setInnerHtml(target, param);
717
+ }
718
+ };
719
+ /**
720
+ * @param {object} param
721
+ * @param {HTMLElement} target
722
+ */
723
+
724
+ const handleObject = (param, target) => {
725
+ // JQuery element(s)
726
+ if (param.jquery) {
727
+ handleJqueryElem(target, param);
728
+ } // For other objects use their string representation
729
+ else {
730
+ setInnerHtml(target, param.toString());
731
+ }
732
+ };
733
+
734
+ const handleJqueryElem = (target, elem) => {
735
+ target.textContent = '';
736
+
737
+ if (0 in elem) {
738
+ for (let i = 0; (i in elem); i++) {
739
+ target.appendChild(elem[i].cloneNode(true));
740
+ }
741
+ } else {
742
+ target.appendChild(elem.cloneNode(true));
743
+ }
744
+ };
745
+
746
+ const animationEndEvent = (() => {
747
+ // Prevent run in Node env
748
+
749
+ /* istanbul ignore if */
750
+ if (isNodeEnv()) {
751
+ return false;
752
+ }
753
+
754
+ const testEl = document.createElement('div');
755
+ const transEndEventNames = {
756
+ WebkitAnimation: 'webkitAnimationEnd',
757
+ // Chrome, Safari and Opera
758
+ animation: 'animationend' // Standard syntax
759
+
760
+ };
761
+
762
+ for (const i in transEndEventNames) {
763
+ if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') {
764
+ return transEndEventNames[i];
765
+ }
766
+ }
767
+
768
+ return false;
769
+ })();
770
+
771
+ // https://github.com/twbs/bootstrap/blob/master/js/src/modal.js
772
+
773
+ const measureScrollbar = () => {
774
+ const scrollDiv = document.createElement('div');
775
+ scrollDiv.className = swalClasses['scrollbar-measure'];
776
+ document.body.appendChild(scrollDiv);
777
+ const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
778
+ document.body.removeChild(scrollDiv);
779
+ return scrollbarWidth;
780
+ };
781
+
782
+ const renderActions = (instance, params) => {
783
+ const actions = getActions();
784
+ const loader = getLoader(); // Actions (buttons) wrapper
785
+
786
+ if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
787
+ hide(actions);
788
+ } else {
789
+ show(actions);
790
+ } // Custom class
791
+
792
+
793
+ applyCustomClass(actions, params, 'actions'); // Render all the buttons
794
+
795
+ renderButtons(actions, loader, params); // Loader
796
+
797
+ setInnerHtml(loader, params.loaderHtml);
798
+ applyCustomClass(loader, params, 'loader');
799
+ };
800
+
801
+ function renderButtons(actions, loader, params) {
802
+ const confirmButton = getConfirmButton();
803
+ const denyButton = getDenyButton();
804
+ const cancelButton = getCancelButton(); // Render buttons
805
+
806
+ renderButton(confirmButton, 'confirm', params);
807
+ renderButton(denyButton, 'deny', params);
808
+ renderButton(cancelButton, 'cancel', params);
809
+ handleButtonsStyling(confirmButton, denyButton, cancelButton, params);
810
+
811
+ if (params.reverseButtons) {
812
+ if (params.toast) {
813
+ actions.insertBefore(cancelButton, confirmButton);
814
+ actions.insertBefore(denyButton, confirmButton);
815
+ } else {
816
+ actions.insertBefore(cancelButton, loader);
817
+ actions.insertBefore(denyButton, loader);
818
+ actions.insertBefore(confirmButton, loader);
819
+ }
820
+ }
821
+ }
822
+
823
+ function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
824
+ if (!params.buttonsStyling) {
825
+ return removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
826
+ }
827
+
828
+ addClass([confirmButton, denyButton, cancelButton], swalClasses.styled); // Buttons background colors
829
+
830
+ if (params.confirmButtonColor) {
831
+ confirmButton.style.backgroundColor = params.confirmButtonColor;
832
+ addClass(confirmButton, swalClasses['default-outline']);
833
+ }
834
+
835
+ if (params.denyButtonColor) {
836
+ denyButton.style.backgroundColor = params.denyButtonColor;
837
+ addClass(denyButton, swalClasses['default-outline']);
838
+ }
839
+
840
+ if (params.cancelButtonColor) {
841
+ cancelButton.style.backgroundColor = params.cancelButtonColor;
842
+ addClass(cancelButton, swalClasses['default-outline']);
843
+ }
844
+ }
845
+
846
+ function renderButton(button, buttonType, params) {
847
+ toggle(button, params["show".concat(capitalizeFirstLetter(buttonType), "Button")], 'inline-block');
848
+ setInnerHtml(button, params["".concat(buttonType, "ButtonText")]); // Set caption text
849
+
850
+ button.setAttribute('aria-label', params["".concat(buttonType, "ButtonAriaLabel")]); // ARIA label
851
+ // Add buttons custom classes
852
+
853
+ button.className = swalClasses[buttonType];
854
+ applyCustomClass(button, params, "".concat(buttonType, "Button"));
855
+ addClass(button, params["".concat(buttonType, "ButtonClass")]);
856
+ }
857
+
858
+ function handleBackdropParam(container, backdrop) {
859
+ if (typeof backdrop === 'string') {
860
+ container.style.background = backdrop;
861
+ } else if (!backdrop) {
862
+ addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
863
+ }
864
+ }
865
+
866
+ function handlePositionParam(container, position) {
867
+ if (position in swalClasses) {
868
+ addClass(container, swalClasses[position]);
869
+ } else {
870
+ warn('The "position" parameter is not valid, defaulting to "center"');
871
+ addClass(container, swalClasses.center);
872
+ }
873
+ }
874
+
875
+ function handleGrowParam(container, grow) {
876
+ if (grow && typeof grow === 'string') {
877
+ const growClass = "grow-".concat(grow);
878
+
879
+ if (growClass in swalClasses) {
880
+ addClass(container, swalClasses[growClass]);
881
+ }
882
+ }
883
+ }
884
+
885
+ const renderContainer = (instance, params) => {
886
+ const container = getContainer();
887
+
888
+ if (!container) {
889
+ return;
890
+ }
891
+
892
+ handleBackdropParam(container, params.backdrop);
893
+ handlePositionParam(container, params.position);
894
+ handleGrowParam(container, params.grow); // Custom class
895
+
896
+ applyCustomClass(container, params, 'container');
897
+ };
898
+
899
+ /**
900
+ * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
901
+ * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
902
+ * This is the approach that Babel will probably take to implement private methods/fields
903
+ * https://github.com/tc39/proposal-private-methods
904
+ * https://github.com/babel/babel/pull/7555
905
+ * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
906
+ * then we can use that language feature.
907
+ */
908
+ var privateProps = {
909
+ awaitingPromise: new WeakMap(),
910
+ promise: new WeakMap(),
911
+ innerParams: new WeakMap(),
912
+ domCache: new WeakMap()
913
+ };
914
+
915
+ const inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
916
+ const renderInput = (instance, params) => {
917
+ const popup = getPopup();
918
+ const innerParams = privateProps.innerParams.get(instance);
919
+ const rerender = !innerParams || params.input !== innerParams.input;
920
+ inputTypes.forEach(inputType => {
921
+ const inputClass = swalClasses[inputType];
922
+ const inputContainer = getDirectChildByClass(popup, inputClass); // set attributes
923
+
924
+ setAttributes(inputType, params.inputAttributes); // set class
925
+
926
+ inputContainer.className = inputClass;
927
+
928
+ if (rerender) {
929
+ hide(inputContainer);
930
+ }
931
+ });
932
+
933
+ if (params.input) {
934
+ if (rerender) {
935
+ showInput(params);
936
+ } // set custom class
937
+
938
+
939
+ setCustomClass(params);
940
+ }
941
+ };
942
+
943
+ const showInput = params => {
944
+ if (!renderInputType[params.input]) {
945
+ return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
946
+ }
947
+
948
+ const inputContainer = getInputContainer(params.input);
949
+ const input = renderInputType[params.input](inputContainer, params);
950
+ show(input); // input autofocus
951
+
952
+ setTimeout(() => {
953
+ focusInput(input);
954
+ });
955
+ };
956
+
957
+ const removeAttributes = input => {
958
+ for (let i = 0; i < input.attributes.length; i++) {
959
+ const attrName = input.attributes[i].name;
960
+
961
+ if (!['type', 'value', 'style'].includes(attrName)) {
962
+ input.removeAttribute(attrName);
963
+ }
964
+ }
965
+ };
966
+
967
+ const setAttributes = (inputType, inputAttributes) => {
968
+ const input = getInput(getPopup(), inputType);
969
+
970
+ if (!input) {
971
+ return;
972
+ }
973
+
974
+ removeAttributes(input);
975
+
976
+ for (const attr in inputAttributes) {
977
+ input.setAttribute(attr, inputAttributes[attr]);
978
+ }
979
+ };
980
+
981
+ const setCustomClass = params => {
982
+ const inputContainer = getInputContainer(params.input);
983
+
984
+ if (params.customClass) {
985
+ addClass(inputContainer, params.customClass.input);
986
+ }
987
+ };
988
+
989
+ const setInputPlaceholder = (input, params) => {
990
+ if (!input.placeholder || params.inputPlaceholder) {
991
+ input.placeholder = params.inputPlaceholder;
992
+ }
993
+ };
994
+
995
+ const setInputLabel = (input, prependTo, params) => {
996
+ if (params.inputLabel) {
997
+ input.id = swalClasses.input;
998
+ const label = document.createElement('label');
999
+ const labelClass = swalClasses['input-label'];
1000
+ label.setAttribute('for', input.id);
1001
+ label.className = labelClass;
1002
+ addClass(label, params.customClass.inputLabel);
1003
+ label.innerText = params.inputLabel;
1004
+ prependTo.insertAdjacentElement('beforebegin', label);
1005
+ }
1006
+ };
1007
+
1008
+ const getInputContainer = inputType => {
1009
+ const inputClass = swalClasses[inputType] ? swalClasses[inputType] : swalClasses.input;
1010
+ return getDirectChildByClass(getPopup(), inputClass);
1011
+ };
1012
+
1013
+ const renderInputType = {};
1014
+
1015
+ renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = (input, params) => {
1016
+ if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
1017
+ input.value = params.inputValue;
1018
+ } else if (!isPromise(params.inputValue)) {
1019
+ warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(typeof params.inputValue, "\""));
1020
+ }
1021
+
1022
+ setInputLabel(input, input, params);
1023
+ setInputPlaceholder(input, params);
1024
+ input.type = params.input;
1025
+ return input;
1026
+ };
1027
+
1028
+ renderInputType.file = (input, params) => {
1029
+ setInputLabel(input, input, params);
1030
+ setInputPlaceholder(input, params);
1031
+ return input;
1032
+ };
1033
+
1034
+ renderInputType.range = (range, params) => {
1035
+ const rangeInput = range.querySelector('input');
1036
+ const rangeOutput = range.querySelector('output');
1037
+ rangeInput.value = params.inputValue;
1038
+ rangeInput.type = params.input;
1039
+ rangeOutput.value = params.inputValue;
1040
+ setInputLabel(rangeInput, range, params);
1041
+ return range;
1042
+ };
1043
+
1044
+ renderInputType.select = (select, params) => {
1045
+ select.textContent = '';
1046
+
1047
+ if (params.inputPlaceholder) {
1048
+ const placeholder = document.createElement('option');
1049
+ setInnerHtml(placeholder, params.inputPlaceholder);
1050
+ placeholder.value = '';
1051
+ placeholder.disabled = true;
1052
+ placeholder.selected = true;
1053
+ select.appendChild(placeholder);
1054
+ }
1055
+
1056
+ setInputLabel(select, select, params);
1057
+ return select;
1058
+ };
1059
+
1060
+ renderInputType.radio = radio => {
1061
+ radio.textContent = '';
1062
+ return radio;
1063
+ };
1064
+
1065
+ renderInputType.checkbox = (checkboxContainer, params) => {
1066
+ /** @type {HTMLInputElement} */
1067
+ const checkbox = getInput(getPopup(), 'checkbox');
1068
+ checkbox.value = '1';
1069
+ checkbox.id = swalClasses.checkbox;
1070
+ checkbox.checked = Boolean(params.inputValue);
1071
+ const label = checkboxContainer.querySelector('span');
1072
+ setInnerHtml(label, params.inputPlaceholder);
1073
+ return checkboxContainer;
1074
+ };
1075
+
1076
+ renderInputType.textarea = (textarea, params) => {
1077
+ textarea.value = params.inputValue;
1078
+ setInputPlaceholder(textarea, params);
1079
+ setInputLabel(textarea, textarea, params);
1080
+
1081
+ const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight); // https://github.com/sweetalert2/sweetalert2/issues/2291
1082
+
1083
+
1084
+ setTimeout(() => {
1085
+ // https://github.com/sweetalert2/sweetalert2/issues/1699
1086
+ if ('MutationObserver' in window) {
1087
+ const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
1088
+
1089
+ const textareaResizeHandler = () => {
1090
+ const textareaWidth = textarea.offsetWidth + getMargin(textarea);
1091
+
1092
+ if (textareaWidth > initialPopupWidth) {
1093
+ getPopup().style.width = "".concat(textareaWidth, "px");
1094
+ } else {
1095
+ getPopup().style.width = null;
1096
+ }
1097
+ };
1098
+
1099
+ new MutationObserver(textareaResizeHandler).observe(textarea, {
1100
+ attributes: true,
1101
+ attributeFilter: ['style']
1102
+ });
1103
+ }
1104
+ });
1105
+ return textarea;
1106
+ };
1107
+
1108
+ const renderContent = (instance, params) => {
1109
+ const htmlContainer = getHtmlContainer();
1110
+ applyCustomClass(htmlContainer, params, 'htmlContainer'); // Content as HTML
1111
+
1112
+ if (params.html) {
1113
+ parseHtmlToContainer(params.html, htmlContainer);
1114
+ show(htmlContainer, 'block');
1115
+ } // Content as plain text
1116
+ else if (params.text) {
1117
+ htmlContainer.textContent = params.text;
1118
+ show(htmlContainer, 'block');
1119
+ } // No content
1120
+ else {
1121
+ hide(htmlContainer);
1122
+ }
1123
+
1124
+ renderInput(instance, params);
1125
+ };
1126
+
1127
+ const renderFooter = (instance, params) => {
1128
+ const footer = getFooter();
1129
+ toggle(footer, params.footer);
1130
+
1131
+ if (params.footer) {
1132
+ parseHtmlToContainer(params.footer, footer);
1133
+ } // Custom class
1134
+
1135
+
1136
+ applyCustomClass(footer, params, 'footer');
1137
+ };
1138
+
1139
+ const renderCloseButton = (instance, params) => {
1140
+ const closeButton = getCloseButton();
1141
+ setInnerHtml(closeButton, params.closeButtonHtml); // Custom class
1142
+
1143
+ applyCustomClass(closeButton, params, 'closeButton');
1144
+ toggle(closeButton, params.showCloseButton);
1145
+ closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
1146
+ };
1147
+
1148
+ const renderIcon = (instance, params) => {
1149
+ const innerParams = privateProps.innerParams.get(instance);
1150
+ const icon = getIcon(); // if the given icon already rendered, apply the styling without re-rendering the icon
1151
+
1152
+ if (innerParams && params.icon === innerParams.icon) {
1153
+ // Custom or default content
1154
+ setContent(icon, params);
1155
+ applyStyles(icon, params);
1156
+ return;
1157
+ }
1158
+
1159
+ if (!params.icon && !params.iconHtml) {
1160
+ return hide(icon);
1161
+ }
1162
+
1163
+ if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
1164
+ error("Unknown icon! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.icon, "\""));
1165
+ return hide(icon);
1166
+ }
1167
+
1168
+ show(icon); // Custom or default content
1169
+
1170
+ setContent(icon, params);
1171
+ applyStyles(icon, params); // Animate icon
1172
+
1173
+ addClass(icon, params.showClass.icon);
1174
+ };
1175
+
1176
+ const applyStyles = (icon, params) => {
1177
+ for (const iconType in iconTypes) {
1178
+ if (params.icon !== iconType) {
1179
+ removeClass(icon, iconTypes[iconType]);
1180
+ }
1181
+ }
1182
+
1183
+ addClass(icon, iconTypes[params.icon]); // Icon color
1184
+
1185
+ setColor(icon, params); // Success icon background color
1186
+
1187
+ adjustSuccessIconBackgroundColor(); // Custom class
1188
+
1189
+ applyCustomClass(icon, params, 'icon');
1190
+ }; // Adjust success icon background color to match the popup background color
1191
+
1192
+
1193
+ const adjustSuccessIconBackgroundColor = () => {
1194
+ const popup = getPopup();
1195
+ const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
1196
+ const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
1197
+
1198
+ for (let i = 0; i < successIconParts.length; i++) {
1199
+ successIconParts[i].style.backgroundColor = popupBackgroundColor;
1200
+ }
1201
+ };
1202
+
1203
+ const successIconHtml = "\n <div class=\"swal2-success-circular-line-left\"></div>\n <span class=\"swal2-success-line-tip\"></span> <span class=\"swal2-success-line-long\"></span>\n <div class=\"swal2-success-ring\"></div> <div class=\"swal2-success-fix\"></div>\n <div class=\"swal2-success-circular-line-right\"></div>\n";
1204
+ const errorIconHtml = "\n <span class=\"swal2-x-mark\">\n <span class=\"swal2-x-mark-line-left\"></span>\n <span class=\"swal2-x-mark-line-right\"></span>\n </span>\n";
1205
+
1206
+ const setContent = (icon, params) => {
1207
+ icon.textContent = '';
1208
+
1209
+ if (params.iconHtml) {
1210
+ setInnerHtml(icon, iconContent(params.iconHtml));
1211
+ } else if (params.icon === 'success') {
1212
+ setInnerHtml(icon, successIconHtml);
1213
+ } else if (params.icon === 'error') {
1214
+ setInnerHtml(icon, errorIconHtml);
1215
+ } else {
1216
+ const defaultIconHtml = {
1217
+ question: '?',
1218
+ warning: '!',
1219
+ info: 'i'
1220
+ };
1221
+ setInnerHtml(icon, iconContent(defaultIconHtml[params.icon]));
1222
+ }
1223
+ };
1224
+
1225
+ const setColor = (icon, params) => {
1226
+ if (!params.iconColor) {
1227
+ return;
1228
+ }
1229
+
1230
+ icon.style.color = params.iconColor;
1231
+ icon.style.borderColor = params.iconColor;
1232
+
1233
+ for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) {
1234
+ setStyle(icon, sel, 'backgroundColor', params.iconColor);
1235
+ }
1236
+
1237
+ setStyle(icon, '.swal2-success-ring', 'borderColor', params.iconColor);
1238
+ };
1239
+
1240
+ const iconContent = content => "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>");
1241
+
1242
+ const renderImage = (instance, params) => {
1243
+ const image = getImage();
1244
+
1245
+ if (!params.imageUrl) {
1246
+ return hide(image);
1247
+ }
1248
+
1249
+ show(image, ''); // Src, alt
1250
+
1251
+ image.setAttribute('src', params.imageUrl);
1252
+ image.setAttribute('alt', params.imageAlt); // Width, height
1253
+
1254
+ applyNumericalStyle(image, 'width', params.imageWidth);
1255
+ applyNumericalStyle(image, 'height', params.imageHeight); // Class
1256
+
1257
+ image.className = swalClasses.image;
1258
+ applyCustomClass(image, params, 'image');
1259
+ };
1260
+
1261
+ const createStepElement = step => {
1262
+ const stepEl = document.createElement('li');
1263
+ addClass(stepEl, swalClasses['progress-step']);
1264
+ setInnerHtml(stepEl, step);
1265
+ return stepEl;
1266
+ };
1267
+
1268
+ const createLineElement = params => {
1269
+ const lineEl = document.createElement('li');
1270
+ addClass(lineEl, swalClasses['progress-step-line']);
1271
+
1272
+ if (params.progressStepsDistance) {
1273
+ lineEl.style.width = params.progressStepsDistance;
1274
+ }
1275
+
1276
+ return lineEl;
1277
+ };
1278
+
1279
+ const renderProgressSteps = (instance, params) => {
1280
+ const progressStepsContainer = getProgressSteps();
1281
+
1282
+ if (!params.progressSteps || params.progressSteps.length === 0) {
1283
+ return hide(progressStepsContainer);
1284
+ }
1285
+
1286
+ show(progressStepsContainer);
1287
+ progressStepsContainer.textContent = '';
1288
+
1289
+ if (params.currentProgressStep >= params.progressSteps.length) {
1290
+ warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
1291
+ }
1292
+
1293
+ params.progressSteps.forEach((step, index) => {
1294
+ const stepEl = createStepElement(step);
1295
+ progressStepsContainer.appendChild(stepEl);
1296
+
1297
+ if (index === params.currentProgressStep) {
1298
+ addClass(stepEl, swalClasses['active-progress-step']);
1299
+ }
1300
+
1301
+ if (index !== params.progressSteps.length - 1) {
1302
+ const lineEl = createLineElement(params);
1303
+ progressStepsContainer.appendChild(lineEl);
1304
+ }
1305
+ });
1306
+ };
1307
+
1308
+ const renderTitle = (instance, params) => {
1309
+ const title = getTitle();
1310
+ toggle(title, params.title || params.titleText, 'block');
1311
+
1312
+ if (params.title) {
1313
+ parseHtmlToContainer(params.title, title);
1314
+ }
1315
+
1316
+ if (params.titleText) {
1317
+ title.innerText = params.titleText;
1318
+ } // Custom class
1319
+
1320
+
1321
+ applyCustomClass(title, params, 'title');
1322
+ };
1323
+
1324
+ const renderPopup = (instance, params) => {
1325
+ const container = getContainer();
1326
+ const popup = getPopup(); // Width
1327
+ // https://github.com/sweetalert2/sweetalert2/issues/2170
1328
+
1329
+ if (params.toast) {
1330
+ applyNumericalStyle(container, 'width', params.width);
1331
+ popup.style.width = '100%';
1332
+ popup.insertBefore(getLoader(), getIcon());
1333
+ } else {
1334
+ applyNumericalStyle(popup, 'width', params.width);
1335
+ } // Padding
1336
+
1337
+
1338
+ applyNumericalStyle(popup, 'padding', params.padding); // Color
1339
+
1340
+ if (params.color) {
1341
+ popup.style.color = params.color;
1342
+ } // Background
1343
+
1344
+
1345
+ if (params.background) {
1346
+ popup.style.background = params.background;
1347
+ }
1348
+
1349
+ hide(getValidationMessage()); // Classes
1350
+
1351
+ addClasses(popup, params);
1352
+ };
1353
+
1354
+ const addClasses = (popup, params) => {
1355
+ // Default Class + showClass when updating Swal.update({})
1356
+ popup.className = "".concat(swalClasses.popup, " ").concat(isVisible(popup) ? params.showClass.popup : '');
1357
+
1358
+ if (params.toast) {
1359
+ addClass([document.documentElement, document.body], swalClasses['toast-shown']);
1360
+ addClass(popup, swalClasses.toast);
1361
+ } else {
1362
+ addClass(popup, swalClasses.modal);
1363
+ } // Custom class
1364
+
1365
+
1366
+ applyCustomClass(popup, params, 'popup');
1367
+
1368
+ if (typeof params.customClass === 'string') {
1369
+ addClass(popup, params.customClass);
1370
+ } // Icon class (#1842)
1371
+
1372
+
1373
+ if (params.icon) {
1374
+ addClass(popup, swalClasses["icon-".concat(params.icon)]);
1375
+ }
1376
+ };
1377
+
1378
+ const render = (instance, params) => {
1379
+ renderPopup(instance, params);
1380
+ renderContainer(instance, params);
1381
+ renderProgressSteps(instance, params);
1382
+ renderIcon(instance, params);
1383
+ renderImage(instance, params);
1384
+ renderTitle(instance, params);
1385
+ renderCloseButton(instance, params);
1386
+ renderContent(instance, params);
1387
+ renderActions(instance, params);
1388
+ renderFooter(instance, params);
1389
+
1390
+ if (typeof params.didRender === 'function') {
1391
+ params.didRender(getPopup());
1392
+ }
1393
+ };
1394
+
1395
+ const DismissReason = Object.freeze({
1396
+ cancel: 'cancel',
1397
+ backdrop: 'backdrop',
1398
+ close: 'close',
1399
+ esc: 'esc',
1400
+ timer: 'timer'
1401
+ });
1402
+
1403
+ // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
1404
+ // elements not within the active modal dialog will not be surfaced if a user opens a screen
1405
+ // reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
1406
+
1407
+ const setAriaHidden = () => {
1408
+ const bodyChildren = toArray(document.body.children);
1409
+ bodyChildren.forEach(el => {
1410
+ if (el === getContainer() || el.contains(getContainer())) {
1411
+ return;
1412
+ }
1413
+
1414
+ if (el.hasAttribute('aria-hidden')) {
1415
+ el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
1416
+ }
1417
+
1418
+ el.setAttribute('aria-hidden', 'true');
1419
+ });
1420
+ };
1421
+ const unsetAriaHidden = () => {
1422
+ const bodyChildren = toArray(document.body.children);
1423
+ bodyChildren.forEach(el => {
1424
+ if (el.hasAttribute('data-previous-aria-hidden')) {
1425
+ el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'));
1426
+ el.removeAttribute('data-previous-aria-hidden');
1427
+ } else {
1428
+ el.removeAttribute('aria-hidden');
1429
+ }
1430
+ });
1431
+ };
1432
+
1433
+ const swalStringParams = ['swal-title', 'swal-html', 'swal-footer'];
1434
+ const getTemplateParams = params => {
1435
+ const template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template;
1436
+
1437
+ if (!template) {
1438
+ return {};
1439
+ }
1440
+ /** @type {DocumentFragment} */
1441
+
1442
+
1443
+ const templateContent = template.content;
1444
+ showWarningsForElements(templateContent);
1445
+ const result = Object.assign(getSwalParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
1446
+ return result;
1447
+ };
1448
+ /**
1449
+ * @param {DocumentFragment} templateContent
1450
+ */
1451
+
1452
+ const getSwalParams = templateContent => {
1453
+ const result = {};
1454
+ toArray(templateContent.querySelectorAll('swal-param')).forEach(param => {
1455
+ showWarningsForAttributes(param, ['name', 'value']);
1456
+ const paramName = param.getAttribute('name');
1457
+ const value = param.getAttribute('value');
1458
+
1459
+ if (typeof defaultParams[paramName] === 'boolean' && value === 'false') {
1460
+ result[paramName] = false;
1461
+ }
1462
+
1463
+ if (typeof defaultParams[paramName] === 'object') {
1464
+ result[paramName] = JSON.parse(value);
1465
+ }
1466
+ });
1467
+ return result;
1468
+ };
1469
+ /**
1470
+ * @param {DocumentFragment} templateContent
1471
+ */
1472
+
1473
+
1474
+ const getSwalButtons = templateContent => {
1475
+ const result = {};
1476
+ toArray(templateContent.querySelectorAll('swal-button')).forEach(button => {
1477
+ showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
1478
+ const type = button.getAttribute('type');
1479
+ result["".concat(type, "ButtonText")] = button.innerHTML;
1480
+ result["show".concat(capitalizeFirstLetter(type), "Button")] = true;
1481
+
1482
+ if (button.hasAttribute('color')) {
1483
+ result["".concat(type, "ButtonColor")] = button.getAttribute('color');
1484
+ }
1485
+
1486
+ if (button.hasAttribute('aria-label')) {
1487
+ result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label');
1488
+ }
1489
+ });
1490
+ return result;
1491
+ };
1492
+ /**
1493
+ * @param {DocumentFragment} templateContent
1494
+ */
1495
+
1496
+
1497
+ const getSwalImage = templateContent => {
1498
+ const result = {};
1499
+ /** @type {HTMLElement} */
1500
+
1501
+ const image = templateContent.querySelector('swal-image');
1502
+
1503
+ if (image) {
1504
+ showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']);
1505
+
1506
+ if (image.hasAttribute('src')) {
1507
+ result.imageUrl = image.getAttribute('src');
1508
+ }
1509
+
1510
+ if (image.hasAttribute('width')) {
1511
+ result.imageWidth = image.getAttribute('width');
1512
+ }
1513
+
1514
+ if (image.hasAttribute('height')) {
1515
+ result.imageHeight = image.getAttribute('height');
1516
+ }
1517
+
1518
+ if (image.hasAttribute('alt')) {
1519
+ result.imageAlt = image.getAttribute('alt');
1520
+ }
1521
+ }
1522
+
1523
+ return result;
1524
+ };
1525
+ /**
1526
+ * @param {DocumentFragment} templateContent
1527
+ */
1528
+
1529
+
1530
+ const getSwalIcon = templateContent => {
1531
+ const result = {};
1532
+ /** @type {HTMLElement} */
1533
+
1534
+ const icon = templateContent.querySelector('swal-icon');
1535
+
1536
+ if (icon) {
1537
+ showWarningsForAttributes(icon, ['type', 'color']);
1538
+
1539
+ if (icon.hasAttribute('type')) {
1540
+ result.icon = icon.getAttribute('type');
1541
+ }
1542
+
1543
+ if (icon.hasAttribute('color')) {
1544
+ result.iconColor = icon.getAttribute('color');
1545
+ }
1546
+
1547
+ result.iconHtml = icon.innerHTML;
1548
+ }
1549
+
1550
+ return result;
1551
+ };
1552
+ /**
1553
+ * @param {DocumentFragment} templateContent
1554
+ */
1555
+
1556
+
1557
+ const getSwalInput = templateContent => {
1558
+ const result = {};
1559
+ /** @type {HTMLElement} */
1560
+
1561
+ const input = templateContent.querySelector('swal-input');
1562
+
1563
+ if (input) {
1564
+ showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']);
1565
+ result.input = input.getAttribute('type') || 'text';
1566
+
1567
+ if (input.hasAttribute('label')) {
1568
+ result.inputLabel = input.getAttribute('label');
1569
+ }
1570
+
1571
+ if (input.hasAttribute('placeholder')) {
1572
+ result.inputPlaceholder = input.getAttribute('placeholder');
1573
+ }
1574
+
1575
+ if (input.hasAttribute('value')) {
1576
+ result.inputValue = input.getAttribute('value');
1577
+ }
1578
+ }
1579
+
1580
+ const inputOptions = templateContent.querySelectorAll('swal-input-option');
1581
+
1582
+ if (inputOptions.length) {
1583
+ result.inputOptions = {};
1584
+ toArray(inputOptions).forEach(option => {
1585
+ showWarningsForAttributes(option, ['value']);
1586
+ const optionValue = option.getAttribute('value');
1587
+ const optionName = option.innerHTML;
1588
+ result.inputOptions[optionValue] = optionName;
1589
+ });
1590
+ }
1591
+
1592
+ return result;
1593
+ };
1594
+ /**
1595
+ * @param {DocumentFragment} templateContent
1596
+ * @param {string[]} paramNames
1597
+ */
1598
+
1599
+
1600
+ const getSwalStringParams = (templateContent, paramNames) => {
1601
+ const result = {};
1602
+
1603
+ for (const i in paramNames) {
1604
+ const paramName = paramNames[i];
1605
+ /** @type {HTMLElement} */
1606
+
1607
+ const tag = templateContent.querySelector(paramName);
1608
+
1609
+ if (tag) {
1610
+ showWarningsForAttributes(tag, []);
1611
+ result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
1612
+ }
1613
+ }
1614
+
1615
+ return result;
1616
+ };
1617
+ /**
1618
+ * @param {DocumentFragment} templateContent
1619
+ */
1620
+
1621
+
1622
+ const showWarningsForElements = templateContent => {
1623
+ const allowedElements = swalStringParams.concat(['swal-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']);
1624
+ toArray(templateContent.children).forEach(el => {
1625
+ const tagName = el.tagName.toLowerCase();
1626
+
1627
+ if (allowedElements.indexOf(tagName) === -1) {
1628
+ warn("Unrecognized element <".concat(tagName, ">"));
1629
+ }
1630
+ });
1631
+ };
1632
+ /**
1633
+ * @param {HTMLElement} el
1634
+ * @param {string[]} allowedAttributes
1635
+ */
1636
+
1637
+
1638
+ const showWarningsForAttributes = (el, allowedAttributes) => {
1639
+ toArray(el.attributes).forEach(attribute => {
1640
+ if (allowedAttributes.indexOf(attribute.name) === -1) {
1641
+ warn(["Unrecognized attribute \"".concat(attribute.name, "\" on <").concat(el.tagName.toLowerCase(), ">."), "".concat(allowedAttributes.length ? "Allowed attributes are: ".concat(allowedAttributes.join(', ')) : 'To set the value, use HTML within the element.')]);
1642
+ }
1643
+ });
1644
+ };
1645
+
1646
+ var defaultInputValidators = {
1647
+ email: (string, validationMessage) => {
1648
+ return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid email address');
1649
+ },
1650
+ url: (string, validationMessage) => {
1651
+ // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013
1652
+ return /^https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-z]{2,63}\b([-a-zA-Z0-9@:%_+.~#?&/=]*)$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || 'Invalid URL');
1653
+ }
1654
+ };
1655
+
1656
+ function setDefaultInputValidators(params) {
1657
+ // Use default `inputValidator` for supported input types if not provided
1658
+ if (!params.inputValidator) {
1659
+ Object.keys(defaultInputValidators).forEach(key => {
1660
+ if (params.input === key) {
1661
+ params.inputValidator = defaultInputValidators[key];
1662
+ }
1663
+ });
1664
+ }
1665
+ }
1666
+
1667
+ function validateCustomTargetElement(params) {
1668
+ // Determine if the custom target element is valid
1669
+ if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
1670
+ warn('Target parameter is not valid, defaulting to "body"');
1671
+ params.target = 'body';
1672
+ }
1673
+ }
1674
+ /**
1675
+ * Set type, text and actions on popup
1676
+ *
1677
+ * @param params
1678
+ */
1679
+
1680
+
1681
+ function setParameters(params) {
1682
+ setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm
1683
+
1684
+ if (params.showLoaderOnConfirm && !params.preConfirm) {
1685
+ warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request');
1686
+ }
1687
+
1688
+ validateCustomTargetElement(params); // Replace newlines with <br> in title
1689
+
1690
+ if (typeof params.title === 'string') {
1691
+ params.title = params.title.split('\n').join('<br />');
1692
+ }
1693
+
1694
+ init(params);
1695
+ }
1696
+
1697
+ class Timer {
1698
+ constructor(callback, delay) {
1699
+ this.callback = callback;
1700
+ this.remaining = delay;
1701
+ this.running = false;
1702
+ this.start();
1703
+ }
1704
+
1705
+ start() {
1706
+ if (!this.running) {
1707
+ this.running = true;
1708
+ this.started = new Date();
1709
+ this.id = setTimeout(this.callback, this.remaining);
1710
+ }
1711
+
1712
+ return this.remaining;
1713
+ }
1714
+
1715
+ stop() {
1716
+ if (this.running) {
1717
+ this.running = false;
1718
+ clearTimeout(this.id);
1719
+ this.remaining -= new Date().getTime() - this.started.getTime();
1720
+ }
1721
+
1722
+ return this.remaining;
1723
+ }
1724
+
1725
+ increase(n) {
1726
+ const running = this.running;
1727
+
1728
+ if (running) {
1729
+ this.stop();
1730
+ }
1731
+
1732
+ this.remaining += n;
1733
+
1734
+ if (running) {
1735
+ this.start();
1736
+ }
1737
+
1738
+ return this.remaining;
1739
+ }
1740
+
1741
+ getTimerLeft() {
1742
+ if (this.running) {
1743
+ this.stop();
1744
+ this.start();
1745
+ }
1746
+
1747
+ return this.remaining;
1748
+ }
1749
+
1750
+ isRunning() {
1751
+ return this.running;
1752
+ }
1753
+
1754
+ }
1755
+
1756
+ const fixScrollbar = () => {
1757
+ // for queues, do not do this more than once
1758
+ if (states.previousBodyPadding !== null) {
1759
+ return;
1760
+ } // if the body has overflow
1761
+
1762
+
1763
+ if (document.body.scrollHeight > window.innerHeight) {
1764
+ // add padding so the content doesn't shift after removal of scrollbar
1765
+ states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
1766
+ document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px");
1767
+ }
1768
+ };
1769
+ const undoScrollbar = () => {
1770
+ if (states.previousBodyPadding !== null) {
1771
+ document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px");
1772
+ states.previousBodyPadding = null;
1773
+ }
1774
+ };
1775
+
1776
+ /* istanbul ignore file */
1777
+
1778
+ const iOSfix = () => {
1779
+ const iOS = // @ts-ignore
1780
+ /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
1781
+
1782
+ if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
1783
+ const offset = document.body.scrollTop;
1784
+ document.body.style.top = "".concat(offset * -1, "px");
1785
+ addClass(document.body, swalClasses.iosfix);
1786
+ lockBodyScroll();
1787
+ addBottomPaddingForTallPopups();
1788
+ }
1789
+ };
1790
+ /**
1791
+ * https://github.com/sweetalert2/sweetalert2/issues/1948
1792
+ */
1793
+
1794
+ const addBottomPaddingForTallPopups = () => {
1795
+ const ua = navigator.userAgent;
1796
+ const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
1797
+ const webkit = !!ua.match(/WebKit/i);
1798
+ const iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
1799
+
1800
+ if (iOSSafari) {
1801
+ const bottomPanelHeight = 44;
1802
+
1803
+ if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
1804
+ getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
1805
+ }
1806
+ }
1807
+ };
1808
+ /**
1809
+ * https://github.com/sweetalert2/sweetalert2/issues/1246
1810
+ */
1811
+
1812
+
1813
+ const lockBodyScroll = () => {
1814
+ const container = getContainer();
1815
+ let preventTouchMove;
1816
+
1817
+ container.ontouchstart = e => {
1818
+ preventTouchMove = shouldPreventTouchMove(e);
1819
+ };
1820
+
1821
+ container.ontouchmove = e => {
1822
+ if (preventTouchMove) {
1823
+ e.preventDefault();
1824
+ e.stopPropagation();
1825
+ }
1826
+ };
1827
+ };
1828
+
1829
+ const shouldPreventTouchMove = event => {
1830
+ const target = event.target;
1831
+ const container = getContainer();
1832
+
1833
+ if (isStylus(event) || isZoom(event)) {
1834
+ return false;
1835
+ }
1836
+
1837
+ if (target === container) {
1838
+ return true;
1839
+ }
1840
+
1841
+ if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603
1842
+ target.tagName !== 'TEXTAREA' && // #2266
1843
+ !(isScrollable(getHtmlContainer()) && // #1944
1844
+ getHtmlContainer().contains(target))) {
1845
+ return true;
1846
+ }
1847
+
1848
+ return false;
1849
+ };
1850
+ /**
1851
+ * https://github.com/sweetalert2/sweetalert2/issues/1786
1852
+ *
1853
+ * @param {*} event
1854
+ * @returns {boolean}
1855
+ */
1856
+
1857
+
1858
+ const isStylus = event => {
1859
+ return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
1860
+ };
1861
+ /**
1862
+ * https://github.com/sweetalert2/sweetalert2/issues/1891
1863
+ *
1864
+ * @param {TouchEvent} event
1865
+ * @returns {boolean}
1866
+ */
1867
+
1868
+
1869
+ const isZoom = event => {
1870
+ return event.touches && event.touches.length > 1;
1871
+ };
1872
+
1873
+ const undoIOSfix = () => {
1874
+ if (hasClass(document.body, swalClasses.iosfix)) {
1875
+ const offset = parseInt(document.body.style.top, 10);
1876
+ removeClass(document.body, swalClasses.iosfix);
1877
+ document.body.style.top = '';
1878
+ document.body.scrollTop = offset * -1;
1879
+ }
1880
+ };
1881
+
1882
+ const SHOW_CLASS_TIMEOUT = 10;
1883
+ /**
1884
+ * Open popup, add necessary classes and styles, fix scrollbar
1885
+ *
1886
+ * @param params
1887
+ */
1888
+
1889
+ const openPopup = params => {
1890
+ const container = getContainer();
1891
+ const popup = getPopup();
1892
+
1893
+ if (typeof params.willOpen === 'function') {
1894
+ params.willOpen(popup);
1895
+ }
1896
+
1897
+ const bodyStyles = window.getComputedStyle(document.body);
1898
+ const initialBodyOverflow = bodyStyles.overflowY;
1899
+ addClasses$1(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto'
1900
+
1901
+ setTimeout(() => {
1902
+ setScrollingVisibility(container, popup);
1903
+ }, SHOW_CLASS_TIMEOUT);
1904
+
1905
+ if (isModal()) {
1906
+ fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
1907
+ setAriaHidden();
1908
+ }
1909
+
1910
+ if (!isToast() && !globalState.previousActiveElement) {
1911
+ globalState.previousActiveElement = document.activeElement;
1912
+ }
1913
+
1914
+ if (typeof params.didOpen === 'function') {
1915
+ setTimeout(() => params.didOpen(popup));
1916
+ }
1917
+
1918
+ removeClass(container, swalClasses['no-transition']);
1919
+ };
1920
+
1921
+ const swalOpenAnimationFinished = event => {
1922
+ const popup = getPopup();
1923
+
1924
+ if (event.target !== popup) {
1925
+ return;
1926
+ }
1927
+
1928
+ const container = getContainer();
1929
+ popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
1930
+ container.style.overflowY = 'auto';
1931
+ };
1932
+
1933
+ const setScrollingVisibility = (container, popup) => {
1934
+ if (animationEndEvent && hasCssAnimation(popup)) {
1935
+ container.style.overflowY = 'hidden';
1936
+ popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
1937
+ } else {
1938
+ container.style.overflowY = 'auto';
1939
+ }
1940
+ };
1941
+
1942
+ const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
1943
+ iOSfix();
1944
+
1945
+ if (scrollbarPadding && initialBodyOverflow !== 'hidden') {
1946
+ fixScrollbar();
1947
+ } // sweetalert2/issues/1247
1948
+
1949
+
1950
+ setTimeout(() => {
1951
+ container.scrollTop = 0;
1952
+ });
1953
+ };
1954
+
1955
+ const addClasses$1 = (container, popup, params) => {
1956
+ addClass(container, params.showClass.backdrop); // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
1957
+
1958
+ popup.style.setProperty('opacity', '0', 'important');
1959
+ show(popup, 'grid');
1960
+ setTimeout(() => {
1961
+ // Animate popup right after showing it
1962
+ addClass(popup, params.showClass.popup); // and remove the opacity workaround
1963
+
1964
+ popup.style.removeProperty('opacity');
1965
+ }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062
1966
+
1967
+ addClass([document.documentElement, document.body], swalClasses.shown);
1968
+
1969
+ if (params.heightAuto && params.backdrop && !params.toast) {
1970
+ addClass([document.documentElement, document.body], swalClasses['height-auto']);
1971
+ }
1972
+ };
1973
+
1974
+ /**
1975
+ * Shows loader (spinner), this is useful with AJAX requests.
1976
+ * By default the loader be shown instead of the "Confirm" button.
1977
+ */
1978
+
1979
+ const showLoading = buttonToReplace => {
1980
+ let popup = getPopup();
1981
+
1982
+ if (!popup) {
1983
+ new Swal(); // eslint-disable-line no-new
1984
+ }
1985
+
1986
+ popup = getPopup();
1987
+ const loader = getLoader();
1988
+
1989
+ if (isToast()) {
1990
+ hide(getIcon());
1991
+ } else {
1992
+ replaceButton(popup, buttonToReplace);
1993
+ }
1994
+
1995
+ show(loader);
1996
+ popup.setAttribute('data-loading', true);
1997
+ popup.setAttribute('aria-busy', true);
1998
+ popup.focus();
1999
+ };
2000
+
2001
+ const replaceButton = (popup, buttonToReplace) => {
2002
+ const actions = getActions();
2003
+ const loader = getLoader();
2004
+
2005
+ if (!buttonToReplace && isVisible(getConfirmButton())) {
2006
+ buttonToReplace = getConfirmButton();
2007
+ }
2008
+
2009
+ show(actions);
2010
+
2011
+ if (buttonToReplace) {
2012
+ hide(buttonToReplace);
2013
+ loader.setAttribute('data-button-to-replace', buttonToReplace.className);
2014
+ }
2015
+
2016
+ loader.parentNode.insertBefore(loader, buttonToReplace);
2017
+ addClass([popup, actions], swalClasses.loading);
2018
+ };
2019
+
2020
+ const handleInputOptionsAndValue = (instance, params) => {
2021
+ if (params.input === 'select' || params.input === 'radio') {
2022
+ handleInputOptions(instance, params);
2023
+ } else if (['text', 'email', 'number', 'tel', 'textarea'].includes(params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
2024
+ showLoading(getConfirmButton());
2025
+ handleInputValue(instance, params);
2026
+ }
2027
+ };
2028
+ const getInputValue = (instance, innerParams) => {
2029
+ const input = instance.getInput();
2030
+
2031
+ if (!input) {
2032
+ return null;
2033
+ }
2034
+
2035
+ switch (innerParams.input) {
2036
+ case 'checkbox':
2037
+ return getCheckboxValue(input);
2038
+
2039
+ case 'radio':
2040
+ return getRadioValue(input);
2041
+
2042
+ case 'file':
2043
+ return getFileValue(input);
2044
+
2045
+ default:
2046
+ return innerParams.inputAutoTrim ? input.value.trim() : input.value;
2047
+ }
2048
+ };
2049
+
2050
+ const getCheckboxValue = input => input.checked ? 1 : 0;
2051
+
2052
+ const getRadioValue = input => input.checked ? input.value : null;
2053
+
2054
+ const getFileValue = input => input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
2055
+
2056
+ const handleInputOptions = (instance, params) => {
2057
+ const popup = getPopup();
2058
+
2059
+ const processInputOptions = inputOptions => populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
2060
+
2061
+ if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
2062
+ showLoading(getConfirmButton());
2063
+ asPromise(params.inputOptions).then(inputOptions => {
2064
+ instance.hideLoading();
2065
+ processInputOptions(inputOptions);
2066
+ });
2067
+ } else if (typeof params.inputOptions === 'object') {
2068
+ processInputOptions(params.inputOptions);
2069
+ } else {
2070
+ error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(typeof params.inputOptions));
2071
+ }
2072
+ };
2073
+
2074
+ const handleInputValue = (instance, params) => {
2075
+ const input = instance.getInput();
2076
+ hide(input);
2077
+ asPromise(params.inputValue).then(inputValue => {
2078
+ input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : "".concat(inputValue);
2079
+ show(input);
2080
+ input.focus();
2081
+ instance.hideLoading();
2082
+ }).catch(err => {
2083
+ error("Error in inputValue promise: ".concat(err));
2084
+ input.value = '';
2085
+ show(input);
2086
+ input.focus();
2087
+ instance.hideLoading();
2088
+ });
2089
+ };
2090
+
2091
+ const populateInputOptions = {
2092
+ select: (popup, inputOptions, params) => {
2093
+ const select = getDirectChildByClass(popup, swalClasses.select);
2094
+
2095
+ const renderOption = (parent, optionLabel, optionValue) => {
2096
+ const option = document.createElement('option');
2097
+ option.value = optionValue;
2098
+ setInnerHtml(option, optionLabel);
2099
+ option.selected = isSelected(optionValue, params.inputValue);
2100
+ parent.appendChild(option);
2101
+ };
2102
+
2103
+ inputOptions.forEach(inputOption => {
2104
+ const optionValue = inputOption[0];
2105
+ const optionLabel = inputOption[1]; // <optgroup> spec:
2106
+ // https://www.w3.org/TR/html401/interact/forms.html#h-17.6
2107
+ // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
2108
+ // check whether this is a <optgroup>
2109
+
2110
+ if (Array.isArray(optionLabel)) {
2111
+ // if it is an array, then it is an <optgroup>
2112
+ const optgroup = document.createElement('optgroup');
2113
+ optgroup.label = optionValue;
2114
+ optgroup.disabled = false; // not configurable for now
2115
+
2116
+ select.appendChild(optgroup);
2117
+ optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
2118
+ } else {
2119
+ // case of <option>
2120
+ renderOption(select, optionLabel, optionValue);
2121
+ }
2122
+ });
2123
+ select.focus();
2124
+ },
2125
+ radio: (popup, inputOptions, params) => {
2126
+ const radio = getDirectChildByClass(popup, swalClasses.radio);
2127
+ inputOptions.forEach(inputOption => {
2128
+ const radioValue = inputOption[0];
2129
+ const radioLabel = inputOption[1];
2130
+ const radioInput = document.createElement('input');
2131
+ const radioLabelElement = document.createElement('label');
2132
+ radioInput.type = 'radio';
2133
+ radioInput.name = swalClasses.radio;
2134
+ radioInput.value = radioValue;
2135
+
2136
+ if (isSelected(radioValue, params.inputValue)) {
2137
+ radioInput.checked = true;
2138
+ }
2139
+
2140
+ const label = document.createElement('span');
2141
+ setInnerHtml(label, radioLabel);
2142
+ label.className = swalClasses.label;
2143
+ radioLabelElement.appendChild(radioInput);
2144
+ radioLabelElement.appendChild(label);
2145
+ radio.appendChild(radioLabelElement);
2146
+ });
2147
+ const radios = radio.querySelectorAll('input');
2148
+
2149
+ if (radios.length) {
2150
+ radios[0].focus();
2151
+ }
2152
+ }
2153
+ };
2154
+ /**
2155
+ * Converts `inputOptions` into an array of `[value, label]`s
2156
+ * @param inputOptions
2157
+ */
2158
+
2159
+ const formatInputOptions = inputOptions => {
2160
+ const result = [];
2161
+
2162
+ if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
2163
+ inputOptions.forEach((value, key) => {
2164
+ let valueFormatted = value;
2165
+
2166
+ if (typeof valueFormatted === 'object') {
2167
+ // case of <optgroup>
2168
+ valueFormatted = formatInputOptions(valueFormatted);
2169
+ }
2170
+
2171
+ result.push([key, valueFormatted]);
2172
+ });
2173
+ } else {
2174
+ Object.keys(inputOptions).forEach(key => {
2175
+ let valueFormatted = inputOptions[key];
2176
+
2177
+ if (typeof valueFormatted === 'object') {
2178
+ // case of <optgroup>
2179
+ valueFormatted = formatInputOptions(valueFormatted);
2180
+ }
2181
+
2182
+ result.push([key, valueFormatted]);
2183
+ });
2184
+ }
2185
+
2186
+ return result;
2187
+ };
2188
+
2189
+ const isSelected = (optionValue, inputValue) => {
2190
+ return inputValue && inputValue.toString() === optionValue.toString();
2191
+ };
2192
+
2193
+ const handleConfirmButtonClick = instance => {
2194
+ const innerParams = privateProps.innerParams.get(instance);
2195
+ instance.disableButtons();
2196
+
2197
+ if (innerParams.input) {
2198
+ handleConfirmOrDenyWithInput(instance, 'confirm');
2199
+ } else {
2200
+ confirm(instance, true);
2201
+ }
2202
+ };
2203
+ const handleDenyButtonClick = instance => {
2204
+ const innerParams = privateProps.innerParams.get(instance);
2205
+ instance.disableButtons();
2206
+
2207
+ if (innerParams.returnInputValueOnDeny) {
2208
+ handleConfirmOrDenyWithInput(instance, 'deny');
2209
+ } else {
2210
+ deny(instance, false);
2211
+ }
2212
+ };
2213
+ const handleCancelButtonClick = (instance, dismissWith) => {
2214
+ instance.disableButtons();
2215
+ dismissWith(DismissReason.cancel);
2216
+ };
2217
+
2218
+ const handleConfirmOrDenyWithInput = (instance, type
2219
+ /* 'confirm' | 'deny' */
2220
+ ) => {
2221
+ const innerParams = privateProps.innerParams.get(instance);
2222
+
2223
+ if (!innerParams.input) {
2224
+ return error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type)));
2225
+ }
2226
+
2227
+ const inputValue = getInputValue(instance, innerParams);
2228
+
2229
+ if (innerParams.inputValidator) {
2230
+ handleInputValidator(instance, inputValue, type);
2231
+ } else if (!instance.getInput().checkValidity()) {
2232
+ instance.enableButtons();
2233
+ instance.showValidationMessage(innerParams.validationMessage);
2234
+ } else if (type === 'deny') {
2235
+ deny(instance, inputValue);
2236
+ } else {
2237
+ confirm(instance, inputValue);
2238
+ }
2239
+ };
2240
+
2241
+ const handleInputValidator = (instance, inputValue, type
2242
+ /* 'confirm' | 'deny' */
2243
+ ) => {
2244
+ const innerParams = privateProps.innerParams.get(instance);
2245
+ instance.disableInput();
2246
+ const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
2247
+ validationPromise.then(validationMessage => {
2248
+ instance.enableButtons();
2249
+ instance.enableInput();
2250
+
2251
+ if (validationMessage) {
2252
+ instance.showValidationMessage(validationMessage);
2253
+ } else if (type === 'deny') {
2254
+ deny(instance, inputValue);
2255
+ } else {
2256
+ confirm(instance, inputValue);
2257
+ }
2258
+ });
2259
+ };
2260
+
2261
+ const deny = (instance, value) => {
2262
+ const innerParams = privateProps.innerParams.get(instance || undefined);
2263
+
2264
+ if (innerParams.showLoaderOnDeny) {
2265
+ showLoading(getDenyButton());
2266
+ }
2267
+
2268
+ if (innerParams.preDeny) {
2269
+ privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preDeny's promise is received
2270
+
2271
+ const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
2272
+ preDenyPromise.then(preDenyValue => {
2273
+ if (preDenyValue === false) {
2274
+ instance.hideLoading();
2275
+ } else {
2276
+ instance.closePopup({
2277
+ isDenied: true,
2278
+ value: typeof preDenyValue === 'undefined' ? value : preDenyValue
2279
+ });
2280
+ }
2281
+ }).catch(error$$1 => rejectWith(instance || undefined, error$$1));
2282
+ } else {
2283
+ instance.closePopup({
2284
+ isDenied: true,
2285
+ value
2286
+ });
2287
+ }
2288
+ };
2289
+
2290
+ const succeedWith = (instance, value) => {
2291
+ instance.closePopup({
2292
+ isConfirmed: true,
2293
+ value
2294
+ });
2295
+ };
2296
+
2297
+ const rejectWith = (instance, error$$1) => {
2298
+ instance.rejectPromise(error$$1);
2299
+ };
2300
+
2301
+ const confirm = (instance, value) => {
2302
+ const innerParams = privateProps.innerParams.get(instance || undefined);
2303
+
2304
+ if (innerParams.showLoaderOnConfirm) {
2305
+ showLoading();
2306
+ }
2307
+
2308
+ if (innerParams.preConfirm) {
2309
+ instance.resetValidationMessage();
2310
+ privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preConfirm's promise is received
2311
+
2312
+ const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
2313
+ preConfirmPromise.then(preConfirmValue => {
2314
+ if (isVisible(getValidationMessage()) || preConfirmValue === false) {
2315
+ instance.hideLoading();
2316
+ } else {
2317
+ succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
2318
+ }
2319
+ }).catch(error$$1 => rejectWith(instance || undefined, error$$1));
2320
+ } else {
2321
+ succeedWith(instance, value);
2322
+ }
2323
+ };
2324
+
2325
+ const handlePopupClick = (instance, domCache, dismissWith) => {
2326
+ const innerParams = privateProps.innerParams.get(instance);
2327
+
2328
+ if (innerParams.toast) {
2329
+ handleToastClick(instance, domCache, dismissWith);
2330
+ } else {
2331
+ // Ignore click events that had mousedown on the popup but mouseup on the container
2332
+ // This can happen when the user drags a slider
2333
+ handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
2334
+
2335
+ handleContainerMousedown(domCache);
2336
+ handleModalClick(instance, domCache, dismissWith);
2337
+ }
2338
+ };
2339
+
2340
+ const handleToastClick = (instance, domCache, dismissWith) => {
2341
+ // Closing toast by internal click
2342
+ domCache.popup.onclick = () => {
2343
+ const innerParams = privateProps.innerParams.get(instance);
2344
+
2345
+ if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
2346
+ return;
2347
+ }
2348
+
2349
+ dismissWith(DismissReason.close);
2350
+ };
2351
+ };
2352
+ /**
2353
+ * @param {*} innerParams
2354
+ * @returns {boolean}
2355
+ */
2356
+
2357
+
2358
+ const isAnyButtonShown = innerParams => {
2359
+ return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
2360
+ };
2361
+
2362
+ let ignoreOutsideClick = false;
2363
+
2364
+ const handleModalMousedown = domCache => {
2365
+ domCache.popup.onmousedown = () => {
2366
+ domCache.container.onmouseup = function (e) {
2367
+ domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
2368
+ // have any other direct children aside of the popup
2369
+
2370
+ if (e.target === domCache.container) {
2371
+ ignoreOutsideClick = true;
2372
+ }
2373
+ };
2374
+ };
2375
+ };
2376
+
2377
+ const handleContainerMousedown = domCache => {
2378
+ domCache.container.onmousedown = () => {
2379
+ domCache.popup.onmouseup = function (e) {
2380
+ domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
2381
+
2382
+ if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
2383
+ ignoreOutsideClick = true;
2384
+ }
2385
+ };
2386
+ };
2387
+ };
2388
+
2389
+ const handleModalClick = (instance, domCache, dismissWith) => {
2390
+ domCache.container.onclick = e => {
2391
+ const innerParams = privateProps.innerParams.get(instance);
2392
+
2393
+ if (ignoreOutsideClick) {
2394
+ ignoreOutsideClick = false;
2395
+ return;
2396
+ }
2397
+
2398
+ if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
2399
+ dismissWith(DismissReason.backdrop);
2400
+ }
2401
+ };
2402
+ };
2403
+
2404
+ /*
2405
+ * Global function to determine if SweetAlert2 popup is shown
2406
+ */
2407
+
2408
+ const isVisible$1 = () => {
2409
+ return isVisible(getPopup());
2410
+ };
2411
+ /*
2412
+ * Global function to click 'Confirm' button
2413
+ */
2414
+
2415
+ const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
2416
+ /*
2417
+ * Global function to click 'Deny' button
2418
+ */
2419
+
2420
+ const clickDeny = () => getDenyButton() && getDenyButton().click();
2421
+ /*
2422
+ * Global function to click 'Cancel' button
2423
+ */
2424
+
2425
+ const clickCancel = () => getCancelButton() && getCancelButton().click();
2426
+
2427
+ const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
2428
+ if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
2429
+ globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
2430
+ capture: globalState.keydownListenerCapture
2431
+ });
2432
+ globalState.keydownHandlerAdded = false;
2433
+ }
2434
+
2435
+ if (!innerParams.toast) {
2436
+ globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
2437
+
2438
+ globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
2439
+ globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
2440
+ globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
2441
+ capture: globalState.keydownListenerCapture
2442
+ });
2443
+ globalState.keydownHandlerAdded = true;
2444
+ }
2445
+ }; // Focus handling
2446
+
2447
+ const setFocus = (innerParams, index, increment) => {
2448
+ const focusableElements = getFocusableElements(); // search for visible elements and select the next possible match
2449
+
2450
+ if (focusableElements.length) {
2451
+ index = index + increment; // rollover to first item
2452
+
2453
+ if (index === focusableElements.length) {
2454
+ index = 0; // go to last item
2455
+ } else if (index === -1) {
2456
+ index = focusableElements.length - 1;
2457
+ }
2458
+
2459
+ return focusableElements[index].focus();
2460
+ } // no visible focusable elements, focus the popup
2461
+
2462
+
2463
+ getPopup().focus();
2464
+ };
2465
+ const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
2466
+ const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
2467
+
2468
+ const keydownHandler = (instance, e, dismissWith) => {
2469
+ const innerParams = privateProps.innerParams.get(instance);
2470
+
2471
+ if (!innerParams) {
2472
+ return; // This instance has already been destroyed
2473
+ }
2474
+
2475
+ if (innerParams.stopKeydownPropagation) {
2476
+ e.stopPropagation();
2477
+ } // ENTER
2478
+
2479
+
2480
+ if (e.key === 'Enter') {
2481
+ handleEnter(instance, e, innerParams);
2482
+ } // TAB
2483
+ else if (e.key === 'Tab') {
2484
+ handleTab(e, innerParams);
2485
+ } // ARROWS - switch focus between buttons
2486
+ else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
2487
+ handleArrows(e.key);
2488
+ } // ESC
2489
+ else if (e.key === 'Escape') {
2490
+ handleEsc(e, innerParams, dismissWith);
2491
+ }
2492
+ };
2493
+
2494
+ const handleEnter = (instance, e, innerParams) => {
2495
+ // #2386 #720 #721
2496
+ if (!callIfFunction(innerParams.allowEnterKey) || e.isComposing) {
2497
+ return;
2498
+ }
2499
+
2500
+ if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) {
2501
+ if (['textarea', 'file'].includes(innerParams.input)) {
2502
+ return; // do not submit
2503
+ }
2504
+
2505
+ clickConfirm();
2506
+ e.preventDefault();
2507
+ }
2508
+ };
2509
+
2510
+ const handleTab = (e, innerParams) => {
2511
+ const targetElement = e.target;
2512
+ const focusableElements = getFocusableElements();
2513
+ let btnIndex = -1;
2514
+
2515
+ for (let i = 0; i < focusableElements.length; i++) {
2516
+ if (targetElement === focusableElements[i]) {
2517
+ btnIndex = i;
2518
+ break;
2519
+ }
2520
+ } // Cycle to the next button
2521
+
2522
+
2523
+ if (!e.shiftKey) {
2524
+ setFocus(innerParams, btnIndex, 1);
2525
+ } // Cycle to the prev button
2526
+ else {
2527
+ setFocus(innerParams, btnIndex, -1);
2528
+ }
2529
+
2530
+ e.stopPropagation();
2531
+ e.preventDefault();
2532
+ };
2533
+
2534
+ const handleArrows = key => {
2535
+ const confirmButton = getConfirmButton();
2536
+ const denyButton = getDenyButton();
2537
+ const cancelButton = getCancelButton();
2538
+
2539
+ if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
2540
+ return;
2541
+ }
2542
+
2543
+ const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
2544
+ let buttonToFocus = document.activeElement;
2545
+
2546
+ for (let i = 0; i < getActions().children.length; i++) {
2547
+ buttonToFocus = buttonToFocus[sibling];
2548
+
2549
+ if (!buttonToFocus) {
2550
+ return;
2551
+ }
2552
+
2553
+ if (isVisible(buttonToFocus) && buttonToFocus instanceof HTMLButtonElement) {
2554
+ break;
2555
+ }
2556
+ }
2557
+
2558
+ if (buttonToFocus instanceof HTMLButtonElement) {
2559
+ buttonToFocus.focus();
2560
+ }
2561
+ };
2562
+
2563
+ const handleEsc = (e, innerParams, dismissWith) => {
2564
+ if (callIfFunction(innerParams.allowEscapeKey)) {
2565
+ e.preventDefault();
2566
+ dismissWith(DismissReason.esc);
2567
+ }
2568
+ };
2569
+
2570
+ const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
2571
+
2572
+ const isElement = elem => elem instanceof Element || isJqueryElement(elem);
2573
+
2574
+ const argsToParams = args => {
2575
+ const params = {};
2576
+
2577
+ if (typeof args[0] === 'object' && !isElement(args[0])) {
2578
+ Object.assign(params, args[0]);
2579
+ } else {
2580
+ ['title', 'html', 'icon'].forEach((name, index) => {
2581
+ const arg = args[index];
2582
+
2583
+ if (typeof arg === 'string' || isElement(arg)) {
2584
+ params[name] = arg;
2585
+ } else if (arg !== undefined) {
2586
+ error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
2587
+ }
2588
+ });
2589
+ }
2590
+
2591
+ return params;
2592
+ };
2593
+
2594
+ function fire() {
2595
+ const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
2596
+
2597
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2598
+ args[_key] = arguments[_key];
2599
+ }
2600
+
2601
+ return new Swal(...args);
2602
+ }
2603
+
2604
+ /**
2605
+ * Returns an extended version of `Swal` containing `params` as defaults.
2606
+ * Useful for reusing Swal configuration.
2607
+ *
2608
+ * For example:
2609
+ *
2610
+ * Before:
2611
+ * const textPromptOptions = { input: 'text', showCancelButton: true }
2612
+ * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
2613
+ * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
2614
+ *
2615
+ * After:
2616
+ * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
2617
+ * const {value: firstName} = await TextPrompt('What is your first name?')
2618
+ * const {value: lastName} = await TextPrompt('What is your last name?')
2619
+ *
2620
+ * @param mixinParams
2621
+ */
2622
+ function mixin(mixinParams) {
2623
+ class MixinSwal extends this {
2624
+ _main(params, priorityMixinParams) {
2625
+ return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
2626
+ }
2627
+
2628
+ }
2629
+
2630
+ return MixinSwal;
2631
+ }
2632
+
2633
+ /**
2634
+ * If `timer` parameter is set, returns number of milliseconds of timer remained.
2635
+ * Otherwise, returns undefined.
2636
+ */
2637
+
2638
+ const getTimerLeft = () => {
2639
+ return globalState.timeout && globalState.timeout.getTimerLeft();
2640
+ };
2641
+ /**
2642
+ * Stop timer. Returns number of milliseconds of timer remained.
2643
+ * If `timer` parameter isn't set, returns undefined.
2644
+ */
2645
+
2646
+ const stopTimer = () => {
2647
+ if (globalState.timeout) {
2648
+ stopTimerProgressBar();
2649
+ return globalState.timeout.stop();
2650
+ }
2651
+ };
2652
+ /**
2653
+ * Resume timer. Returns number of milliseconds of timer remained.
2654
+ * If `timer` parameter isn't set, returns undefined.
2655
+ */
2656
+
2657
+ const resumeTimer = () => {
2658
+ if (globalState.timeout) {
2659
+ const remaining = globalState.timeout.start();
2660
+ animateTimerProgressBar(remaining);
2661
+ return remaining;
2662
+ }
2663
+ };
2664
+ /**
2665
+ * Resume timer. Returns number of milliseconds of timer remained.
2666
+ * If `timer` parameter isn't set, returns undefined.
2667
+ */
2668
+
2669
+ const toggleTimer = () => {
2670
+ const timer = globalState.timeout;
2671
+ return timer && (timer.running ? stopTimer() : resumeTimer());
2672
+ };
2673
+ /**
2674
+ * Increase timer. Returns number of milliseconds of an updated timer.
2675
+ * If `timer` parameter isn't set, returns undefined.
2676
+ */
2677
+
2678
+ const increaseTimer = n => {
2679
+ if (globalState.timeout) {
2680
+ const remaining = globalState.timeout.increase(n);
2681
+ animateTimerProgressBar(remaining, true);
2682
+ return remaining;
2683
+ }
2684
+ };
2685
+ /**
2686
+ * Check if timer is running. Returns true if timer is running
2687
+ * or false if timer is paused or stopped.
2688
+ * If `timer` parameter isn't set, returns undefined
2689
+ */
2690
+
2691
+ const isTimerRunning = () => {
2692
+ return globalState.timeout && globalState.timeout.isRunning();
2693
+ };
2694
+
2695
+ let bodyClickListenerAdded = false;
2696
+ const clickHandlers = {};
2697
+ function bindClickHandler() {
2698
+ let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
2699
+ clickHandlers[attr] = this;
2700
+
2701
+ if (!bodyClickListenerAdded) {
2702
+ document.body.addEventListener('click', bodyClickListener);
2703
+ bodyClickListenerAdded = true;
2704
+ }
2705
+ }
2706
+
2707
+ const bodyClickListener = event => {
2708
+ for (let el = event.target; el && el !== document; el = el.parentNode) {
2709
+ for (const attr in clickHandlers) {
2710
+ const template = el.getAttribute(attr);
2711
+
2712
+ if (template) {
2713
+ clickHandlers[attr].fire({
2714
+ template
2715
+ });
2716
+ return;
2717
+ }
2718
+ }
2719
+ }
2720
+ };
2721
+
2722
+
2723
+
2724
+ var staticMethods = /*#__PURE__*/Object.freeze({
2725
+ isValidParameter: isValidParameter,
2726
+ isUpdatableParameter: isUpdatableParameter,
2727
+ isDeprecatedParameter: isDeprecatedParameter,
2728
+ argsToParams: argsToParams,
2729
+ isVisible: isVisible$1,
2730
+ clickConfirm: clickConfirm,
2731
+ clickDeny: clickDeny,
2732
+ clickCancel: clickCancel,
2733
+ getContainer: getContainer,
2734
+ getPopup: getPopup,
2735
+ getTitle: getTitle,
2736
+ getHtmlContainer: getHtmlContainer,
2737
+ getImage: getImage,
2738
+ getIcon: getIcon,
2739
+ getInputLabel: getInputLabel,
2740
+ getCloseButton: getCloseButton,
2741
+ getActions: getActions,
2742
+ getConfirmButton: getConfirmButton,
2743
+ getDenyButton: getDenyButton,
2744
+ getCancelButton: getCancelButton,
2745
+ getLoader: getLoader,
2746
+ getFooter: getFooter,
2747
+ getTimerProgressBar: getTimerProgressBar,
2748
+ getFocusableElements: getFocusableElements,
2749
+ getValidationMessage: getValidationMessage,
2750
+ isLoading: isLoading,
2751
+ fire: fire,
2752
+ mixin: mixin,
2753
+ showLoading: showLoading,
2754
+ enableLoading: showLoading,
2755
+ getTimerLeft: getTimerLeft,
2756
+ stopTimer: stopTimer,
2757
+ resumeTimer: resumeTimer,
2758
+ toggleTimer: toggleTimer,
2759
+ increaseTimer: increaseTimer,
2760
+ isTimerRunning: isTimerRunning,
2761
+ bindClickHandler: bindClickHandler
2762
+ });
2763
+
2764
+ /**
2765
+ * Hides loader and shows back the button which was hidden by .showLoading()
2766
+ */
2767
+
2768
+ function hideLoading() {
2769
+ // do nothing if popup is closed
2770
+ const innerParams = privateProps.innerParams.get(this);
2771
+
2772
+ if (!innerParams) {
2773
+ return;
2774
+ }
2775
+
2776
+ const domCache = privateProps.domCache.get(this);
2777
+ hide(domCache.loader);
2778
+
2779
+ if (isToast()) {
2780
+ if (innerParams.icon) {
2781
+ show(getIcon());
2782
+ }
2783
+ } else {
2784
+ showRelatedButton(domCache);
2785
+ }
2786
+
2787
+ removeClass([domCache.popup, domCache.actions], swalClasses.loading);
2788
+ domCache.popup.removeAttribute('aria-busy');
2789
+ domCache.popup.removeAttribute('data-loading');
2790
+ domCache.confirmButton.disabled = false;
2791
+ domCache.denyButton.disabled = false;
2792
+ domCache.cancelButton.disabled = false;
2793
+ }
2794
+
2795
+ const showRelatedButton = domCache => {
2796
+ const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
2797
+
2798
+ if (buttonToReplace.length) {
2799
+ show(buttonToReplace[0], 'inline-block');
2800
+ } else if (allButtonsAreHidden()) {
2801
+ hide(domCache.actions);
2802
+ }
2803
+ };
2804
+
2805
+ /**
2806
+ * Gets the input DOM node, this method works with input parameter.
2807
+ * @returns {HTMLElement | null}
2808
+ */
2809
+
2810
+ function getInput$1(instance) {
2811
+ const innerParams = privateProps.innerParams.get(instance || this);
2812
+ const domCache = privateProps.domCache.get(instance || this);
2813
+
2814
+ if (!domCache) {
2815
+ return null;
2816
+ }
2817
+
2818
+ return getInput(domCache.popup, innerParams.input);
2819
+ }
2820
+
2821
+ /**
2822
+ * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
2823
+ * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
2824
+ * This is the approach that Babel will probably take to implement private methods/fields
2825
+ * https://github.com/tc39/proposal-private-methods
2826
+ * https://github.com/babel/babel/pull/7555
2827
+ * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
2828
+ * then we can use that language feature.
2829
+ */
2830
+ var privateMethods = {
2831
+ swalPromiseResolve: new WeakMap(),
2832
+ swalPromiseReject: new WeakMap()
2833
+ };
2834
+
2835
+ /*
2836
+ * Instance method to close sweetAlert
2837
+ */
2838
+
2839
+ function removePopupAndResetState(instance, container, returnFocus, didClose) {
2840
+ if (isToast()) {
2841
+ triggerDidCloseAndDispose(instance, didClose);
2842
+ } else {
2843
+ restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
2844
+ globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
2845
+ capture: globalState.keydownListenerCapture
2846
+ });
2847
+ globalState.keydownHandlerAdded = false;
2848
+ }
2849
+
2850
+ const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
2851
+ // for some reason removing the container in Safari will scroll the document to bottom
2852
+
2853
+ if (isSafari) {
2854
+ container.setAttribute('style', 'display:none !important');
2855
+ container.removeAttribute('class');
2856
+ container.innerHTML = '';
2857
+ } else {
2858
+ container.remove();
2859
+ }
2860
+
2861
+ if (isModal()) {
2862
+ undoScrollbar();
2863
+ undoIOSfix();
2864
+ unsetAriaHidden();
2865
+ }
2866
+
2867
+ removeBodyClasses();
2868
+ }
2869
+
2870
+ function removeBodyClasses() {
2871
+ removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
2872
+ }
2873
+
2874
+ function close(resolveValue) {
2875
+ resolveValue = prepareResolveValue(resolveValue);
2876
+ const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
2877
+ const didClose = triggerClosePopup(this);
2878
+
2879
+ if (this.isAwaitingPromise()) {
2880
+ // A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
2881
+ if (!resolveValue.isDismissed) {
2882
+ handleAwaitingPromise(this);
2883
+ swalPromiseResolve(resolveValue);
2884
+ }
2885
+ } else if (didClose) {
2886
+ // Resolve Swal promise
2887
+ swalPromiseResolve(resolveValue);
2888
+ }
2889
+ }
2890
+ function isAwaitingPromise() {
2891
+ return !!privateProps.awaitingPromise.get(this);
2892
+ }
2893
+
2894
+ const triggerClosePopup = instance => {
2895
+ const popup = getPopup();
2896
+
2897
+ if (!popup) {
2898
+ return false;
2899
+ }
2900
+
2901
+ const innerParams = privateProps.innerParams.get(instance);
2902
+
2903
+ if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
2904
+ return false;
2905
+ }
2906
+
2907
+ removeClass(popup, innerParams.showClass.popup);
2908
+ addClass(popup, innerParams.hideClass.popup);
2909
+ const backdrop = getContainer();
2910
+ removeClass(backdrop, innerParams.showClass.backdrop);
2911
+ addClass(backdrop, innerParams.hideClass.backdrop);
2912
+ handlePopupAnimation(instance, popup, innerParams);
2913
+ return true;
2914
+ };
2915
+
2916
+ function rejectPromise(error) {
2917
+ const rejectPromise = privateMethods.swalPromiseReject.get(this);
2918
+ handleAwaitingPromise(this);
2919
+
2920
+ if (rejectPromise) {
2921
+ // Reject Swal promise
2922
+ rejectPromise(error);
2923
+ }
2924
+ }
2925
+
2926
+ const handleAwaitingPromise = instance => {
2927
+ if (instance.isAwaitingPromise()) {
2928
+ privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
2929
+
2930
+ if (!privateProps.innerParams.get(instance)) {
2931
+ instance._destroy();
2932
+ }
2933
+ }
2934
+ };
2935
+
2936
+ const prepareResolveValue = resolveValue => {
2937
+ // When user calls Swal.close()
2938
+ if (typeof resolveValue === 'undefined') {
2939
+ return {
2940
+ isConfirmed: false,
2941
+ isDenied: false,
2942
+ isDismissed: true
2943
+ };
2944
+ }
2945
+
2946
+ return Object.assign({
2947
+ isConfirmed: false,
2948
+ isDenied: false,
2949
+ isDismissed: false
2950
+ }, resolveValue);
2951
+ };
2952
+
2953
+ const handlePopupAnimation = (instance, popup, innerParams) => {
2954
+ const container = getContainer(); // If animation is supported, animate
2955
+
2956
+ const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
2957
+
2958
+ if (typeof innerParams.willClose === 'function') {
2959
+ innerParams.willClose(popup);
2960
+ }
2961
+
2962
+ if (animationIsSupported) {
2963
+ animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
2964
+ } else {
2965
+ // Otherwise, remove immediately
2966
+ removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
2967
+ }
2968
+ };
2969
+
2970
+ const animatePopup = (instance, popup, container, returnFocus, didClose) => {
2971
+ globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
2972
+ popup.addEventListener(animationEndEvent, function (e) {
2973
+ if (e.target === popup) {
2974
+ globalState.swalCloseEventFinishedCallback();
2975
+ delete globalState.swalCloseEventFinishedCallback;
2976
+ }
2977
+ });
2978
+ };
2979
+
2980
+ const triggerDidCloseAndDispose = (instance, didClose) => {
2981
+ setTimeout(() => {
2982
+ if (typeof didClose === 'function') {
2983
+ didClose.bind(instance.params)();
2984
+ }
2985
+
2986
+ instance._destroy();
2987
+ });
2988
+ };
2989
+
2990
+ function setButtonsDisabled(instance, buttons, disabled) {
2991
+ const domCache = privateProps.domCache.get(instance);
2992
+ buttons.forEach(button => {
2993
+ domCache[button].disabled = disabled;
2994
+ });
2995
+ }
2996
+
2997
+ function setInputDisabled(input, disabled) {
2998
+ if (!input) {
2999
+ return false;
3000
+ }
3001
+
3002
+ if (input.type === 'radio') {
3003
+ const radiosContainer = input.parentNode.parentNode;
3004
+ const radios = radiosContainer.querySelectorAll('input');
3005
+
3006
+ for (let i = 0; i < radios.length; i++) {
3007
+ radios[i].disabled = disabled;
3008
+ }
3009
+ } else {
3010
+ input.disabled = disabled;
3011
+ }
3012
+ }
3013
+
3014
+ function enableButtons() {
3015
+ setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
3016
+ }
3017
+ function disableButtons() {
3018
+ setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
3019
+ }
3020
+ function enableInput() {
3021
+ return setInputDisabled(this.getInput(), false);
3022
+ }
3023
+ function disableInput() {
3024
+ return setInputDisabled(this.getInput(), true);
3025
+ }
3026
+
3027
+ function showValidationMessage(error) {
3028
+ const domCache = privateProps.domCache.get(this);
3029
+ const params = privateProps.innerParams.get(this);
3030
+ setInnerHtml(domCache.validationMessage, error);
3031
+ domCache.validationMessage.className = swalClasses['validation-message'];
3032
+
3033
+ if (params.customClass && params.customClass.validationMessage) {
3034
+ addClass(domCache.validationMessage, params.customClass.validationMessage);
3035
+ }
3036
+
3037
+ show(domCache.validationMessage);
3038
+ const input = this.getInput();
3039
+
3040
+ if (input) {
3041
+ input.setAttribute('aria-invalid', true);
3042
+ input.setAttribute('aria-describedby', swalClasses['validation-message']);
3043
+ focusInput(input);
3044
+ addClass(input, swalClasses.inputerror);
3045
+ }
3046
+ } // Hide block with validation message
3047
+
3048
+ function resetValidationMessage$1() {
3049
+ const domCache = privateProps.domCache.get(this);
3050
+
3051
+ if (domCache.validationMessage) {
3052
+ hide(domCache.validationMessage);
3053
+ }
3054
+
3055
+ const input = this.getInput();
3056
+
3057
+ if (input) {
3058
+ input.removeAttribute('aria-invalid');
3059
+ input.removeAttribute('aria-describedby');
3060
+ removeClass(input, swalClasses.inputerror);
3061
+ }
3062
+ }
3063
+
3064
+ function getProgressSteps$1() {
3065
+ const domCache = privateProps.domCache.get(this);
3066
+ return domCache.progressSteps;
3067
+ }
3068
+
3069
+ /**
3070
+ * Updates popup parameters.
3071
+ */
3072
+
3073
+ function update(params) {
3074
+ const popup = getPopup();
3075
+ const innerParams = privateProps.innerParams.get(this);
3076
+
3077
+ if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
3078
+ return warn("You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.");
3079
+ }
3080
+
3081
+ const validUpdatableParams = filterValidParams(params);
3082
+ const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
3083
+ render(this, updatedParams);
3084
+ privateProps.innerParams.set(this, updatedParams);
3085
+ Object.defineProperties(this, {
3086
+ params: {
3087
+ value: Object.assign({}, this.params, params),
3088
+ writable: false,
3089
+ enumerable: true
3090
+ }
3091
+ });
3092
+ }
3093
+
3094
+ const filterValidParams = params => {
3095
+ const validUpdatableParams = {};
3096
+ Object.keys(params).forEach(param => {
3097
+ if (isUpdatableParameter(param)) {
3098
+ validUpdatableParams[param] = params[param];
3099
+ } else {
3100
+ warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md"));
3101
+ }
3102
+ });
3103
+ return validUpdatableParams;
3104
+ };
3105
+
3106
+ function _destroy() {
3107
+ const domCache = privateProps.domCache.get(this);
3108
+ const innerParams = privateProps.innerParams.get(this);
3109
+
3110
+ if (!innerParams) {
3111
+ disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
3112
+
3113
+ return; // This instance has already been destroyed
3114
+ } // Check if there is another Swal closing
3115
+
3116
+
3117
+ if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
3118
+ globalState.swalCloseEventFinishedCallback();
3119
+ delete globalState.swalCloseEventFinishedCallback;
3120
+ } // Check if there is a swal disposal defer timer
3121
+
3122
+
3123
+ if (globalState.deferDisposalTimer) {
3124
+ clearTimeout(globalState.deferDisposalTimer);
3125
+ delete globalState.deferDisposalTimer;
3126
+ }
3127
+
3128
+ if (typeof innerParams.didDestroy === 'function') {
3129
+ innerParams.didDestroy();
3130
+ }
3131
+
3132
+ disposeSwal(this);
3133
+ }
3134
+
3135
+ const disposeSwal = instance => {
3136
+ disposeWeakMaps(instance); // Unset this.params so GC will dispose it (#1569)
3137
+
3138
+ delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
3139
+
3140
+ delete globalState.keydownHandler;
3141
+ delete globalState.keydownTarget; // Unset currentInstance
3142
+
3143
+ delete globalState.currentInstance;
3144
+ };
3145
+
3146
+ const disposeWeakMaps = instance => {
3147
+ // If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
3148
+ if (instance.isAwaitingPromise()) {
3149
+ unsetWeakMaps(privateProps, instance);
3150
+ privateProps.awaitingPromise.set(instance, true);
3151
+ } else {
3152
+ unsetWeakMaps(privateMethods, instance);
3153
+ unsetWeakMaps(privateProps, instance);
3154
+ }
3155
+ };
3156
+
3157
+ const unsetWeakMaps = (obj, instance) => {
3158
+ for (const i in obj) {
3159
+ obj[i].delete(instance);
3160
+ }
3161
+ };
3162
+
3163
+
3164
+
3165
+ var instanceMethods = /*#__PURE__*/Object.freeze({
3166
+ hideLoading: hideLoading,
3167
+ disableLoading: hideLoading,
3168
+ getInput: getInput$1,
3169
+ close: close,
3170
+ isAwaitingPromise: isAwaitingPromise,
3171
+ rejectPromise: rejectPromise,
3172
+ closePopup: close,
3173
+ closeModal: close,
3174
+ closeToast: close,
3175
+ enableButtons: enableButtons,
3176
+ disableButtons: disableButtons,
3177
+ enableInput: enableInput,
3178
+ disableInput: disableInput,
3179
+ showValidationMessage: showValidationMessage,
3180
+ resetValidationMessage: resetValidationMessage$1,
3181
+ getProgressSteps: getProgressSteps$1,
3182
+ update: update,
3183
+ _destroy: _destroy
3184
+ });
3185
+
3186
+ let currentInstance;
3187
+
3188
+ class SweetAlert {
3189
+ constructor() {
3190
+ // Prevent run in Node env
3191
+ if (typeof window === 'undefined') {
3192
+ return;
3193
+ }
3194
+
3195
+ currentInstance = this; // @ts-ignore
3196
+
3197
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3198
+ args[_key] = arguments[_key];
3199
+ }
3200
+
3201
+ const outerParams = Object.freeze(this.constructor.argsToParams(args));
3202
+ Object.defineProperties(this, {
3203
+ params: {
3204
+ value: outerParams,
3205
+ writable: false,
3206
+ enumerable: true,
3207
+ configurable: true
3208
+ }
3209
+ }); // @ts-ignore
3210
+
3211
+ const promise = this._main(this.params);
3212
+
3213
+ privateProps.promise.set(this, promise);
3214
+ }
3215
+
3216
+ _main(userParams) {
3217
+ let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3218
+ showWarningsForParams(Object.assign({}, mixinParams, userParams));
3219
+
3220
+ if (globalState.currentInstance) {
3221
+ globalState.currentInstance._destroy();
3222
+
3223
+ if (isModal()) {
3224
+ unsetAriaHidden();
3225
+ }
3226
+ }
3227
+
3228
+ globalState.currentInstance = this;
3229
+ const innerParams = prepareParams(userParams, mixinParams);
3230
+ setParameters(innerParams);
3231
+ Object.freeze(innerParams); // clear the previous timer
3232
+
3233
+ if (globalState.timeout) {
3234
+ globalState.timeout.stop();
3235
+ delete globalState.timeout;
3236
+ } // clear the restore focus timeout
3237
+
3238
+
3239
+ clearTimeout(globalState.restoreFocusTimeout);
3240
+ const domCache = populateDomCache(this);
3241
+ render(this, innerParams);
3242
+ privateProps.innerParams.set(this, innerParams);
3243
+ return swalPromise(this, domCache, innerParams);
3244
+ } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
3245
+
3246
+
3247
+ then(onFulfilled) {
3248
+ const promise = privateProps.promise.get(this);
3249
+ return promise.then(onFulfilled);
3250
+ }
3251
+
3252
+ finally(onFinally) {
3253
+ const promise = privateProps.promise.get(this);
3254
+ return promise.finally(onFinally);
3255
+ }
3256
+
3257
+ }
3258
+
3259
+ const swalPromise = (instance, domCache, innerParams) => {
3260
+ return new Promise((resolve, reject) => {
3261
+ // functions to handle all closings/dismissals
3262
+ const dismissWith = dismiss => {
3263
+ instance.closePopup({
3264
+ isDismissed: true,
3265
+ dismiss
3266
+ });
3267
+ };
3268
+
3269
+ privateMethods.swalPromiseResolve.set(instance, resolve);
3270
+ privateMethods.swalPromiseReject.set(instance, reject);
3271
+
3272
+ domCache.confirmButton.onclick = () => handleConfirmButtonClick(instance);
3273
+
3274
+ domCache.denyButton.onclick = () => handleDenyButtonClick(instance);
3275
+
3276
+ domCache.cancelButton.onclick = () => handleCancelButtonClick(instance, dismissWith);
3277
+
3278
+ domCache.closeButton.onclick = () => dismissWith(DismissReason.close);
3279
+
3280
+ handlePopupClick(instance, domCache, dismissWith);
3281
+ addKeydownHandler(instance, globalState, innerParams, dismissWith);
3282
+ handleInputOptionsAndValue(instance, innerParams);
3283
+ openPopup(innerParams);
3284
+ setupTimer(globalState, innerParams, dismissWith);
3285
+ initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946)
3286
+
3287
+ setTimeout(() => {
3288
+ domCache.container.scrollTop = 0;
3289
+ });
3290
+ });
3291
+ };
3292
+
3293
+ const prepareParams = (userParams, mixinParams) => {
3294
+ const templateParams = getTemplateParams(userParams);
3295
+ const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
3296
+
3297
+ params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
3298
+ params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
3299
+ return params;
3300
+ };
3301
+
3302
+ const populateDomCache = instance => {
3303
+ const domCache = {
3304
+ popup: getPopup(),
3305
+ container: getContainer(),
3306
+ actions: getActions(),
3307
+ confirmButton: getConfirmButton(),
3308
+ denyButton: getDenyButton(),
3309
+ cancelButton: getCancelButton(),
3310
+ loader: getLoader(),
3311
+ closeButton: getCloseButton(),
3312
+ validationMessage: getValidationMessage(),
3313
+ progressSteps: getProgressSteps()
3314
+ };
3315
+ privateProps.domCache.set(instance, domCache);
3316
+ return domCache;
3317
+ };
3318
+
3319
+ const setupTimer = (globalState$$1, innerParams, dismissWith) => {
3320
+ const timerProgressBar = getTimerProgressBar();
3321
+ hide(timerProgressBar);
3322
+
3323
+ if (innerParams.timer) {
3324
+ globalState$$1.timeout = new Timer(() => {
3325
+ dismissWith('timer');
3326
+ delete globalState$$1.timeout;
3327
+ }, innerParams.timer);
3328
+
3329
+ if (innerParams.timerProgressBar) {
3330
+ show(timerProgressBar);
3331
+ applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
3332
+ setTimeout(() => {
3333
+ if (globalState$$1.timeout && globalState$$1.timeout.running) {
3334
+ // timer can be already stopped or unset at this point
3335
+ animateTimerProgressBar(innerParams.timer);
3336
+ }
3337
+ });
3338
+ }
3339
+ }
3340
+ };
3341
+
3342
+ const initFocus = (domCache, innerParams) => {
3343
+ if (innerParams.toast) {
3344
+ return;
3345
+ }
3346
+
3347
+ if (!callIfFunction(innerParams.allowEnterKey)) {
3348
+ return blurActiveElement();
3349
+ }
3350
+
3351
+ if (!focusButton(domCache, innerParams)) {
3352
+ setFocus(innerParams, -1, 1);
3353
+ }
3354
+ };
3355
+
3356
+ const focusButton = (domCache, innerParams) => {
3357
+ if (innerParams.focusDeny && isVisible(domCache.denyButton)) {
3358
+ domCache.denyButton.focus();
3359
+ return true;
3360
+ }
3361
+
3362
+ if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
3363
+ domCache.cancelButton.focus();
3364
+ return true;
3365
+ }
3366
+
3367
+ if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
3368
+ domCache.confirmButton.focus();
3369
+ return true;
3370
+ }
3371
+
3372
+ return false;
3373
+ };
3374
+
3375
+ const blurActiveElement = () => {
3376
+ if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
3377
+ document.activeElement.blur();
3378
+ }
3379
+ }; // Assign instance methods from src/instanceMethods/*.js to prototype
3380
+
3381
+
3382
+ Object.assign(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
3383
+
3384
+ Object.assign(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
3385
+
3386
+ Object.keys(instanceMethods).forEach(key => {
3387
+ SweetAlert[key] = function () {
3388
+ if (currentInstance) {
3389
+ return currentInstance[key](...arguments);
3390
+ }
3391
+ };
3392
+ });
3393
+ SweetAlert.DismissReason = DismissReason;
3394
+ SweetAlert.version = '11.4.2';
3395
+
3396
+ const Swal = SweetAlert; // @ts-ignore
3397
+
3398
+ Swal.default = Swal;
3399
+
3400
+ return Swal;
3401
+
3402
+ }));
3403
+ if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}