GPQAPP

Форк
0
3391 строка · 105.6 Кб
1
/*!
2
* sweetalert2 v11.4.0
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['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
    const buttonToFocus = document.activeElement[sibling];
2545

2546
    if (buttonToFocus instanceof HTMLElement) {
2547
      buttonToFocus.focus();
2548
    }
2549
  };
2550

2551
  const handleEsc = (e, innerParams, dismissWith) => {
2552
    if (callIfFunction(innerParams.allowEscapeKey)) {
2553
      e.preventDefault();
2554
      dismissWith(DismissReason.esc);
2555
    }
2556
  };
2557

2558
  const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
2559

2560
  const isElement = elem => elem instanceof Element || isJqueryElement(elem);
2561

2562
  const argsToParams = args => {
2563
    const params = {};
2564

2565
    if (typeof args[0] === 'object' && !isElement(args[0])) {
2566
      Object.assign(params, args[0]);
2567
    } else {
2568
      ['title', 'html', 'icon'].forEach((name, index) => {
2569
        const arg = args[index];
2570

2571
        if (typeof arg === 'string' || isElement(arg)) {
2572
          params[name] = arg;
2573
        } else if (arg !== undefined) {
2574
          error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
2575
        }
2576
      });
2577
    }
2578

2579
    return params;
2580
  };
2581

2582
  function fire() {
2583
    const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
2584

2585
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2586
      args[_key] = arguments[_key];
2587
    }
2588

2589
    return new Swal(...args);
2590
  }
2591

2592
  /**
2593
   * Returns an extended version of `Swal` containing `params` as defaults.
2594
   * Useful for reusing Swal configuration.
2595
   *
2596
   * For example:
2597
   *
2598
   * Before:
2599
   * const textPromptOptions = { input: 'text', showCancelButton: true }
2600
   * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
2601
   * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
2602
   *
2603
   * After:
2604
   * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
2605
   * const {value: firstName} = await TextPrompt('What is your first name?')
2606
   * const {value: lastName} = await TextPrompt('What is your last name?')
2607
   *
2608
   * @param mixinParams
2609
   */
2610
  function mixin(mixinParams) {
2611
    class MixinSwal extends this {
2612
      _main(params, priorityMixinParams) {
2613
        return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
2614
      }
2615

2616
    }
2617

2618
    return MixinSwal;
2619
  }
2620

2621
  /**
2622
   * If `timer` parameter is set, returns number of milliseconds of timer remained.
2623
   * Otherwise, returns undefined.
2624
   */
2625

2626
  const getTimerLeft = () => {
2627
    return globalState.timeout && globalState.timeout.getTimerLeft();
2628
  };
2629
  /**
2630
   * Stop timer. Returns number of milliseconds of timer remained.
2631
   * If `timer` parameter isn't set, returns undefined.
2632
   */
2633

2634
  const stopTimer = () => {
2635
    if (globalState.timeout) {
2636
      stopTimerProgressBar();
2637
      return globalState.timeout.stop();
2638
    }
2639
  };
2640
  /**
2641
   * Resume timer. Returns number of milliseconds of timer remained.
2642
   * If `timer` parameter isn't set, returns undefined.
2643
   */
2644

2645
  const resumeTimer = () => {
2646
    if (globalState.timeout) {
2647
      const remaining = globalState.timeout.start();
2648
      animateTimerProgressBar(remaining);
2649
      return remaining;
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 toggleTimer = () => {
2658
    const timer = globalState.timeout;
2659
    return timer && (timer.running ? stopTimer() : resumeTimer());
2660
  };
2661
  /**
2662
   * Increase timer. Returns number of milliseconds of an updated timer.
2663
   * If `timer` parameter isn't set, returns undefined.
2664
   */
2665

2666
  const increaseTimer = n => {
2667
    if (globalState.timeout) {
2668
      const remaining = globalState.timeout.increase(n);
2669
      animateTimerProgressBar(remaining, true);
2670
      return remaining;
2671
    }
2672
  };
2673
  /**
2674
   * Check if timer is running. Returns true if timer is running
2675
   * or false if timer is paused or stopped.
2676
   * If `timer` parameter isn't set, returns undefined
2677
   */
2678

2679
  const isTimerRunning = () => {
2680
    return globalState.timeout && globalState.timeout.isRunning();
2681
  };
2682

2683
  let bodyClickListenerAdded = false;
2684
  const clickHandlers = {};
2685
  function bindClickHandler() {
2686
    let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
2687
    clickHandlers[attr] = this;
2688

2689
    if (!bodyClickListenerAdded) {
2690
      document.body.addEventListener('click', bodyClickListener);
2691
      bodyClickListenerAdded = true;
2692
    }
2693
  }
2694

2695
  const bodyClickListener = event => {
2696
    for (let el = event.target; el && el !== document; el = el.parentNode) {
2697
      for (const attr in clickHandlers) {
2698
        const template = el.getAttribute(attr);
2699

2700
        if (template) {
2701
          clickHandlers[attr].fire({
2702
            template
2703
          });
2704
          return;
2705
        }
2706
      }
2707
    }
2708
  };
2709

2710

2711

2712
  var staticMethods = /*#__PURE__*/Object.freeze({
2713
    isValidParameter: isValidParameter,
2714
    isUpdatableParameter: isUpdatableParameter,
2715
    isDeprecatedParameter: isDeprecatedParameter,
2716
    argsToParams: argsToParams,
2717
    isVisible: isVisible$1,
2718
    clickConfirm: clickConfirm,
2719
    clickDeny: clickDeny,
2720
    clickCancel: clickCancel,
2721
    getContainer: getContainer,
2722
    getPopup: getPopup,
2723
    getTitle: getTitle,
2724
    getHtmlContainer: getHtmlContainer,
2725
    getImage: getImage,
2726
    getIcon: getIcon,
2727
    getInputLabel: getInputLabel,
2728
    getCloseButton: getCloseButton,
2729
    getActions: getActions,
2730
    getConfirmButton: getConfirmButton,
2731
    getDenyButton: getDenyButton,
2732
    getCancelButton: getCancelButton,
2733
    getLoader: getLoader,
2734
    getFooter: getFooter,
2735
    getTimerProgressBar: getTimerProgressBar,
2736
    getFocusableElements: getFocusableElements,
2737
    getValidationMessage: getValidationMessage,
2738
    isLoading: isLoading,
2739
    fire: fire,
2740
    mixin: mixin,
2741
    showLoading: showLoading,
2742
    enableLoading: showLoading,
2743
    getTimerLeft: getTimerLeft,
2744
    stopTimer: stopTimer,
2745
    resumeTimer: resumeTimer,
2746
    toggleTimer: toggleTimer,
2747
    increaseTimer: increaseTimer,
2748
    isTimerRunning: isTimerRunning,
2749
    bindClickHandler: bindClickHandler
2750
  });
2751

2752
  /**
2753
   * Hides loader and shows back the button which was hidden by .showLoading()
2754
   */
2755

2756
  function hideLoading() {
2757
    // do nothing if popup is closed
2758
    const innerParams = privateProps.innerParams.get(this);
2759

2760
    if (!innerParams) {
2761
      return;
2762
    }
2763

2764
    const domCache = privateProps.domCache.get(this);
2765
    hide(domCache.loader);
2766

2767
    if (isToast()) {
2768
      if (innerParams.icon) {
2769
        show(getIcon());
2770
      }
2771
    } else {
2772
      showRelatedButton(domCache);
2773
    }
2774

2775
    removeClass([domCache.popup, domCache.actions], swalClasses.loading);
2776
    domCache.popup.removeAttribute('aria-busy');
2777
    domCache.popup.removeAttribute('data-loading');
2778
    domCache.confirmButton.disabled = false;
2779
    domCache.denyButton.disabled = false;
2780
    domCache.cancelButton.disabled = false;
2781
  }
2782

2783
  const showRelatedButton = domCache => {
2784
    const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
2785

2786
    if (buttonToReplace.length) {
2787
      show(buttonToReplace[0], 'inline-block');
2788
    } else if (allButtonsAreHidden()) {
2789
      hide(domCache.actions);
2790
    }
2791
  };
2792

2793
  /**
2794
   * Gets the input DOM node, this method works with input parameter.
2795
   * @returns {HTMLElement | null}
2796
   */
2797

2798
  function getInput$1(instance) {
2799
    const innerParams = privateProps.innerParams.get(instance || this);
2800
    const domCache = privateProps.domCache.get(instance || this);
2801

2802
    if (!domCache) {
2803
      return null;
2804
    }
2805

2806
    return getInput(domCache.popup, innerParams.input);
2807
  }
2808

2809
  /**
2810
   * This module contains `WeakMap`s for each effectively-"private  property" that a `Swal` has.
2811
   * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
2812
   * This is the approach that Babel will probably take to implement private methods/fields
2813
   *   https://github.com/tc39/proposal-private-methods
2814
   *   https://github.com/babel/babel/pull/7555
2815
   * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
2816
   *   then we can use that language feature.
2817
   */
2818
  var privateMethods = {
2819
    swalPromiseResolve: new WeakMap(),
2820
    swalPromiseReject: new WeakMap()
2821
  };
2822

2823
  /*
2824
   * Instance method to close sweetAlert
2825
   */
2826

2827
  function removePopupAndResetState(instance, container, returnFocus, didClose) {
2828
    if (isToast()) {
2829
      triggerDidCloseAndDispose(instance, didClose);
2830
    } else {
2831
      restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
2832
      globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
2833
        capture: globalState.keydownListenerCapture
2834
      });
2835
      globalState.keydownHandlerAdded = false;
2836
    }
2837

2838
    const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
2839
    // for some reason removing the container in Safari will scroll the document to bottom
2840

2841
    if (isSafari) {
2842
      container.setAttribute('style', 'display:none !important');
2843
      container.removeAttribute('class');
2844
      container.innerHTML = '';
2845
    } else {
2846
      container.remove();
2847
    }
2848

2849
    if (isModal()) {
2850
      undoScrollbar();
2851
      undoIOSfix();
2852
      unsetAriaHidden();
2853
    }
2854

2855
    removeBodyClasses();
2856
  }
2857

2858
  function removeBodyClasses() {
2859
    removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
2860
  }
2861

2862
  function close(resolveValue) {
2863
    resolveValue = prepareResolveValue(resolveValue);
2864
    const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
2865
    const didClose = triggerClosePopup(this);
2866

2867
    if (this.isAwaitingPromise()) {
2868
      // A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
2869
      if (!resolveValue.isDismissed) {
2870
        handleAwaitingPromise(this);
2871
        swalPromiseResolve(resolveValue);
2872
      }
2873
    } else if (didClose) {
2874
      // Resolve Swal promise
2875
      swalPromiseResolve(resolveValue);
2876
    }
2877
  }
2878
  function isAwaitingPromise() {
2879
    return !!privateProps.awaitingPromise.get(this);
2880
  }
2881

2882
  const triggerClosePopup = instance => {
2883
    const popup = getPopup();
2884

2885
    if (!popup) {
2886
      return false;
2887
    }
2888

2889
    const innerParams = privateProps.innerParams.get(instance);
2890

2891
    if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
2892
      return false;
2893
    }
2894

2895
    removeClass(popup, innerParams.showClass.popup);
2896
    addClass(popup, innerParams.hideClass.popup);
2897
    const backdrop = getContainer();
2898
    removeClass(backdrop, innerParams.showClass.backdrop);
2899
    addClass(backdrop, innerParams.hideClass.backdrop);
2900
    handlePopupAnimation(instance, popup, innerParams);
2901
    return true;
2902
  };
2903

2904
  function rejectPromise(error) {
2905
    const rejectPromise = privateMethods.swalPromiseReject.get(this);
2906
    handleAwaitingPromise(this);
2907

2908
    if (rejectPromise) {
2909
      // Reject Swal promise
2910
      rejectPromise(error);
2911
    }
2912
  }
2913

2914
  const handleAwaitingPromise = instance => {
2915
    if (instance.isAwaitingPromise()) {
2916
      privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
2917

2918
      if (!privateProps.innerParams.get(instance)) {
2919
        instance._destroy();
2920
      }
2921
    }
2922
  };
2923

2924
  const prepareResolveValue = resolveValue => {
2925
    // When user calls Swal.close()
2926
    if (typeof resolveValue === 'undefined') {
2927
      return {
2928
        isConfirmed: false,
2929
        isDenied: false,
2930
        isDismissed: true
2931
      };
2932
    }
2933

2934
    return Object.assign({
2935
      isConfirmed: false,
2936
      isDenied: false,
2937
      isDismissed: false
2938
    }, resolveValue);
2939
  };
2940

2941
  const handlePopupAnimation = (instance, popup, innerParams) => {
2942
    const container = getContainer(); // If animation is supported, animate
2943

2944
    const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
2945

2946
    if (typeof innerParams.willClose === 'function') {
2947
      innerParams.willClose(popup);
2948
    }
2949

2950
    if (animationIsSupported) {
2951
      animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
2952
    } else {
2953
      // Otherwise, remove immediately
2954
      removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
2955
    }
2956
  };
2957

2958
  const animatePopup = (instance, popup, container, returnFocus, didClose) => {
2959
    globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
2960
    popup.addEventListener(animationEndEvent, function (e) {
2961
      if (e.target === popup) {
2962
        globalState.swalCloseEventFinishedCallback();
2963
        delete globalState.swalCloseEventFinishedCallback;
2964
      }
2965
    });
2966
  };
2967

2968
  const triggerDidCloseAndDispose = (instance, didClose) => {
2969
    setTimeout(() => {
2970
      if (typeof didClose === 'function') {
2971
        didClose.bind(instance.params)();
2972
      }
2973

2974
      instance._destroy();
2975
    });
2976
  };
2977

2978
  function setButtonsDisabled(instance, buttons, disabled) {
2979
    const domCache = privateProps.domCache.get(instance);
2980
    buttons.forEach(button => {
2981
      domCache[button].disabled = disabled;
2982
    });
2983
  }
2984

2985
  function setInputDisabled(input, disabled) {
2986
    if (!input) {
2987
      return false;
2988
    }
2989

2990
    if (input.type === 'radio') {
2991
      const radiosContainer = input.parentNode.parentNode;
2992
      const radios = radiosContainer.querySelectorAll('input');
2993

2994
      for (let i = 0; i < radios.length; i++) {
2995
        radios[i].disabled = disabled;
2996
      }
2997
    } else {
2998
      input.disabled = disabled;
2999
    }
3000
  }
3001

3002
  function enableButtons() {
3003
    setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
3004
  }
3005
  function disableButtons() {
3006
    setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
3007
  }
3008
  function enableInput() {
3009
    return setInputDisabled(this.getInput(), false);
3010
  }
3011
  function disableInput() {
3012
    return setInputDisabled(this.getInput(), true);
3013
  }
3014

3015
  function showValidationMessage(error) {
3016
    const domCache = privateProps.domCache.get(this);
3017
    const params = privateProps.innerParams.get(this);
3018
    setInnerHtml(domCache.validationMessage, error);
3019
    domCache.validationMessage.className = swalClasses['validation-message'];
3020

3021
    if (params.customClass && params.customClass.validationMessage) {
3022
      addClass(domCache.validationMessage, params.customClass.validationMessage);
3023
    }
3024

3025
    show(domCache.validationMessage);
3026
    const input = this.getInput();
3027

3028
    if (input) {
3029
      input.setAttribute('aria-invalid', true);
3030
      input.setAttribute('aria-describedby', swalClasses['validation-message']);
3031
      focusInput(input);
3032
      addClass(input, swalClasses.inputerror);
3033
    }
3034
  } // Hide block with validation message
3035

3036
  function resetValidationMessage$1() {
3037
    const domCache = privateProps.domCache.get(this);
3038

3039
    if (domCache.validationMessage) {
3040
      hide(domCache.validationMessage);
3041
    }
3042

3043
    const input = this.getInput();
3044

3045
    if (input) {
3046
      input.removeAttribute('aria-invalid');
3047
      input.removeAttribute('aria-describedby');
3048
      removeClass(input, swalClasses.inputerror);
3049
    }
3050
  }
3051

3052
  function getProgressSteps$1() {
3053
    const domCache = privateProps.domCache.get(this);
3054
    return domCache.progressSteps;
3055
  }
3056

3057
  /**
3058
   * Updates popup parameters.
3059
   */
3060

3061
  function update(params) {
3062
    const popup = getPopup();
3063
    const innerParams = privateProps.innerParams.get(this);
3064

3065
    if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
3066
      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.");
3067
    }
3068

3069
    const validUpdatableParams = filterValidParams(params);
3070
    const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
3071
    render(this, updatedParams);
3072
    privateProps.innerParams.set(this, updatedParams);
3073
    Object.defineProperties(this, {
3074
      params: {
3075
        value: Object.assign({}, this.params, params),
3076
        writable: false,
3077
        enumerable: true
3078
      }
3079
    });
3080
  }
3081

3082
  const filterValidParams = params => {
3083
    const validUpdatableParams = {};
3084
    Object.keys(params).forEach(param => {
3085
      if (isUpdatableParameter(param)) {
3086
        validUpdatableParams[param] = params[param];
3087
      } else {
3088
        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"));
3089
      }
3090
    });
3091
    return validUpdatableParams;
3092
  };
3093

3094
  function _destroy() {
3095
    const domCache = privateProps.domCache.get(this);
3096
    const innerParams = privateProps.innerParams.get(this);
3097

3098
    if (!innerParams) {
3099
      disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
3100

3101
      return; // This instance has already been destroyed
3102
    } // Check if there is another Swal closing
3103

3104

3105
    if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
3106
      globalState.swalCloseEventFinishedCallback();
3107
      delete globalState.swalCloseEventFinishedCallback;
3108
    } // Check if there is a swal disposal defer timer
3109

3110

3111
    if (globalState.deferDisposalTimer) {
3112
      clearTimeout(globalState.deferDisposalTimer);
3113
      delete globalState.deferDisposalTimer;
3114
    }
3115

3116
    if (typeof innerParams.didDestroy === 'function') {
3117
      innerParams.didDestroy();
3118
    }
3119

3120
    disposeSwal(this);
3121
  }
3122

3123
  const disposeSwal = instance => {
3124
    disposeWeakMaps(instance); // Unset this.params so GC will dispose it (#1569)
3125

3126
    delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
3127

3128
    delete globalState.keydownHandler;
3129
    delete globalState.keydownTarget; // Unset currentInstance
3130

3131
    delete globalState.currentInstance;
3132
  };
3133

3134
  const disposeWeakMaps = instance => {
3135
    // If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
3136
    if (instance.isAwaitingPromise()) {
3137
      unsetWeakMaps(privateProps, instance);
3138
      privateProps.awaitingPromise.set(instance, true);
3139
    } else {
3140
      unsetWeakMaps(privateMethods, instance);
3141
      unsetWeakMaps(privateProps, instance);
3142
    }
3143
  };
3144

3145
  const unsetWeakMaps = (obj, instance) => {
3146
    for (const i in obj) {
3147
      obj[i].delete(instance);
3148
    }
3149
  };
3150

3151

3152

3153
  var instanceMethods = /*#__PURE__*/Object.freeze({
3154
    hideLoading: hideLoading,
3155
    disableLoading: hideLoading,
3156
    getInput: getInput$1,
3157
    close: close,
3158
    isAwaitingPromise: isAwaitingPromise,
3159
    rejectPromise: rejectPromise,
3160
    closePopup: close,
3161
    closeModal: close,
3162
    closeToast: close,
3163
    enableButtons: enableButtons,
3164
    disableButtons: disableButtons,
3165
    enableInput: enableInput,
3166
    disableInput: disableInput,
3167
    showValidationMessage: showValidationMessage,
3168
    resetValidationMessage: resetValidationMessage$1,
3169
    getProgressSteps: getProgressSteps$1,
3170
    update: update,
3171
    _destroy: _destroy
3172
  });
3173

3174
  let currentInstance;
3175

3176
  class SweetAlert {
3177
    constructor() {
3178
      // Prevent run in Node env
3179
      if (typeof window === 'undefined') {
3180
        return;
3181
      }
3182

3183
      currentInstance = this; // @ts-ignore
3184

3185
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
3186
        args[_key] = arguments[_key];
3187
      }
3188

3189
      const outerParams = Object.freeze(this.constructor.argsToParams(args));
3190
      Object.defineProperties(this, {
3191
        params: {
3192
          value: outerParams,
3193
          writable: false,
3194
          enumerable: true,
3195
          configurable: true
3196
        }
3197
      }); // @ts-ignore
3198

3199
      const promise = this._main(this.params);
3200

3201
      privateProps.promise.set(this, promise);
3202
    }
3203

3204
    _main(userParams) {
3205
      let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
3206
      showWarningsForParams(Object.assign({}, mixinParams, userParams));
3207

3208
      if (globalState.currentInstance) {
3209
        globalState.currentInstance._destroy();
3210

3211
        if (isModal()) {
3212
          unsetAriaHidden();
3213
        }
3214
      }
3215

3216
      globalState.currentInstance = this;
3217
      const innerParams = prepareParams(userParams, mixinParams);
3218
      setParameters(innerParams);
3219
      Object.freeze(innerParams); // clear the previous timer
3220

3221
      if (globalState.timeout) {
3222
        globalState.timeout.stop();
3223
        delete globalState.timeout;
3224
      } // clear the restore focus timeout
3225

3226

3227
      clearTimeout(globalState.restoreFocusTimeout);
3228
      const domCache = populateDomCache(this);
3229
      render(this, innerParams);
3230
      privateProps.innerParams.set(this, innerParams);
3231
      return swalPromise(this, domCache, innerParams);
3232
    } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
3233

3234

3235
    then(onFulfilled) {
3236
      const promise = privateProps.promise.get(this);
3237
      return promise.then(onFulfilled);
3238
    }
3239

3240
    finally(onFinally) {
3241
      const promise = privateProps.promise.get(this);
3242
      return promise.finally(onFinally);
3243
    }
3244

3245
  }
3246

3247
  const swalPromise = (instance, domCache, innerParams) => {
3248
    return new Promise((resolve, reject) => {
3249
      // functions to handle all closings/dismissals
3250
      const dismissWith = dismiss => {
3251
        instance.closePopup({
3252
          isDismissed: true,
3253
          dismiss
3254
        });
3255
      };
3256

3257
      privateMethods.swalPromiseResolve.set(instance, resolve);
3258
      privateMethods.swalPromiseReject.set(instance, reject);
3259

3260
      domCache.confirmButton.onclick = () => handleConfirmButtonClick(instance);
3261

3262
      domCache.denyButton.onclick = () => handleDenyButtonClick(instance);
3263

3264
      domCache.cancelButton.onclick = () => handleCancelButtonClick(instance, dismissWith);
3265

3266
      domCache.closeButton.onclick = () => dismissWith(DismissReason.close);
3267

3268
      handlePopupClick(instance, domCache, dismissWith);
3269
      addKeydownHandler(instance, globalState, innerParams, dismissWith);
3270
      handleInputOptionsAndValue(instance, innerParams);
3271
      openPopup(innerParams);
3272
      setupTimer(globalState, innerParams, dismissWith);
3273
      initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946)
3274

3275
      setTimeout(() => {
3276
        domCache.container.scrollTop = 0;
3277
      });
3278
    });
3279
  };
3280

3281
  const prepareParams = (userParams, mixinParams) => {
3282
    const templateParams = getTemplateParams(userParams);
3283
    const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
3284

3285
    params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
3286
    params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
3287
    return params;
3288
  };
3289

3290
  const populateDomCache = instance => {
3291
    const domCache = {
3292
      popup: getPopup(),
3293
      container: getContainer(),
3294
      actions: getActions(),
3295
      confirmButton: getConfirmButton(),
3296
      denyButton: getDenyButton(),
3297
      cancelButton: getCancelButton(),
3298
      loader: getLoader(),
3299
      closeButton: getCloseButton(),
3300
      validationMessage: getValidationMessage(),
3301
      progressSteps: getProgressSteps()
3302
    };
3303
    privateProps.domCache.set(instance, domCache);
3304
    return domCache;
3305
  };
3306

3307
  const setupTimer = (globalState$$1, innerParams, dismissWith) => {
3308
    const timerProgressBar = getTimerProgressBar();
3309
    hide(timerProgressBar);
3310

3311
    if (innerParams.timer) {
3312
      globalState$$1.timeout = new Timer(() => {
3313
        dismissWith('timer');
3314
        delete globalState$$1.timeout;
3315
      }, innerParams.timer);
3316

3317
      if (innerParams.timerProgressBar) {
3318
        show(timerProgressBar);
3319
        applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
3320
        setTimeout(() => {
3321
          if (globalState$$1.timeout && globalState$$1.timeout.running) {
3322
            // timer can be already stopped or unset at this point
3323
            animateTimerProgressBar(innerParams.timer);
3324
          }
3325
        });
3326
      }
3327
    }
3328
  };
3329

3330
  const initFocus = (domCache, innerParams) => {
3331
    if (innerParams.toast) {
3332
      return;
3333
    }
3334

3335
    if (!callIfFunction(innerParams.allowEnterKey)) {
3336
      return blurActiveElement();
3337
    }
3338

3339
    if (!focusButton(domCache, innerParams)) {
3340
      setFocus(innerParams, -1, 1);
3341
    }
3342
  };
3343

3344
  const focusButton = (domCache, innerParams) => {
3345
    if (innerParams.focusDeny && isVisible(domCache.denyButton)) {
3346
      domCache.denyButton.focus();
3347
      return true;
3348
    }
3349

3350
    if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
3351
      domCache.cancelButton.focus();
3352
      return true;
3353
    }
3354

3355
    if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
3356
      domCache.confirmButton.focus();
3357
      return true;
3358
    }
3359

3360
    return false;
3361
  };
3362

3363
  const blurActiveElement = () => {
3364
    if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
3365
      document.activeElement.blur();
3366
    }
3367
  }; // Assign instance methods from src/instanceMethods/*.js to prototype
3368

3369

3370
  Object.assign(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
3371

3372
  Object.assign(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
3373

3374
  Object.keys(instanceMethods).forEach(key => {
3375
    SweetAlert[key] = function () {
3376
      if (currentInstance) {
3377
        return currentInstance[key](...arguments);
3378
      }
3379
    };
3380
  });
3381
  SweetAlert.DismissReason = DismissReason;
3382
  SweetAlert.version = '11.4.0';
3383

3384
  const Swal = SweetAlert; // @ts-ignore
3385

3386
  Swal.default = Swal;
3387

3388
  return Swal;
3389

3390
}));
3391
if (typeof this !== 'undefined' && this.Sweetalert2){  this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}
3392

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.