vendor: 4,501 bytes, lines 1-159
1/*! 2* sweetalert2 v11.9.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 = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Sweetalert2 = factory()); 9})(this, (function () { 'use strict'; 10 11 function _classPrivateFieldGet(receiver, privateMap) { 12 var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); 13 return _classApplyDescriptorGet(receiver, descriptor); 14 } 15 function _classPrivateFieldSet(receiver, privateMap, value) { 16 var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); 17 _classApplyDescriptorSet(receiver, descriptor, value); 18 return value; 19 } 20 function _classExtractFieldDescriptor(receiver, privateMap, action) { 21 if (!privateMap.has(receiver)) { 22 throw new TypeError("attempted to " + action + " private field on non-instance"); 23 } 24 return privateMap.get(receiver); 25 } 26 function _classApplyDescriptorGet(receiver, descriptor) { 27 if (descriptor.get) { 28 return descriptor.get.call(receiver); 29 } 30 return descriptor.value; 31 } 32 function _classApplyDescriptorSet(receiver, descriptor, value) { 33 if (descriptor.set) { 34 descriptor.set.call(receiver, value); 35 } else { 36 if (!descriptor.writable) { 37 throw new TypeError("attempted to set read only private field"); 38 } 39 descriptor.value = value; 40 } 41 } 42 function _checkPrivateRedeclaration(obj, privateCollection) { 43 if (privateCollection.has(obj)) { 44 throw new TypeError("Cannot initialize the same private elements twice on an object"); 45 } 46 } 47 function _classPrivateFieldInitSpec(obj, privateMap, value) { 48 _checkPrivateRedeclaration(obj, privateMap); 49 privateMap.set(obj, value); 50 } 51 52 const RESTORE_FOCUS_TIMEOUT = 100; 53 54 /** @type {GlobalState} */ 55 const globalState = {}; 56 const focusPreviousActiveElement = () => { 57 if (globalState.previousActiveElement instanceof HTMLElement) { 58 globalState.previousActiveElement.focus(); 59 globalState.previousActiveElement = null; 60 } else if (document.body) { 61 document.body.focus(); 62 } 63 }; 64 65 /** 66 * Restore previous active (focused) element 67 * 68 * @param {boolean} returnFocus 69 * @returns {Promise<void>} 70 */ 71 const restoreActiveElement = returnFocus => { 72 return new Promise(resolve => { 73 if (!returnFocus) { 74 return resolve(); 75 } 76 const x = window.scrollX; 77 const y = window.scrollY; 78 globalState.restoreFocusTimeout = setTimeout(() => { 79 focusPreviousActiveElement(); 80 resolve(); 81 }, RESTORE_FOCUS_TIMEOUT); // issues/900 82 83 window.scrollTo(x, y); 84 }); 85 }; 86 87 const swalPrefix = 'swal2-'; 88 89 /** 90 * @typedef 91 * { | 'container' 92 * | 'shown' 93 * | 'height-auto' 94 * | 'iosfix' 95 * | 'popup' 96 * | 'modal' 97 * | 'no-backdrop' 98 * | 'no-transition' 99 * | 'toast' 100 * | 'toast-shown' 101 * | 'show' 102 * | 'hide' 103 * | 'close' 104 * | 'title' 105 * | 'html-container' 106 * | 'actions' 107 * | 'confirm' 108 * | 'deny' 109 * | 'cancel' 110 * | 'default-outline' 111 * | 'footer' 112 * | 'icon' 113 * | 'icon-content' 114 * | 'image' 115 * | 'input' 116 * | 'file' 117 * | 'range' 118 * | 'select' 119 * | 'radio' 120 * | 'checkbox' 121 * | 'label' 122 * | 'textarea' 123 * | 'inputerror' 124 * | 'input-label' 125 * | 'validation-message' 126 * | 'progress-steps' 127 * | 'active-progress-step' 128 * | 'progress-step' 129 * | 'progress-step-line' 130 * | 'loader' 131 * | 'loading' 132 * | 'styled' 133 * | 'top' 134 * | 'top-start' 135 * | 'top-end' 136 * | 'top-left' 137 * | 'top-right' 138 * | 'center' 139 * | 'center-start' 140 * | 'center-end' 141 * | 'center-left' 142 * | 'center-right' 143 * | 'bottom' 144 * | 'bottom-start' 145 * | 'bottom-end' 146 * | 'bottom-left' 147 * | 'bottom-right' 148 * | 'grow-row' 149 * | 'grow-column' 150 * | 'grow-fullscreen' 151 * | 'rtl' 152 * | 'timer-progress-bar' 153 * | 'timer-progress-bar-container' 154 * | 'scrollbar-measure' 155 * | 'icon-success' 156 * | 'icon-warning' 157 * | 'icon-info' 158 * | 'icon-question' 159 * | 'icon-error'
160 * } SwalClass 161 * @typedef {Record<SwalClass, string>} SwalClasses 162 */ 163 164 /** 165 * @typedef {'success' | 'warning' | 'info' | 'question' | 'error'} SwalIcon 166 * @typedef {Record<SwalIcon, string>} SwalIcons 167 */ 168 169 /** @type {SwalClass[]} */ 170 const classNames = ['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']; 171 const swalClasses = classNames.reduce((acc, className) => { 172 acc[className] = swalPrefix + className; 173 return acc; 174 }, /** @type {SwalClasses} */{}); 175 176 /** @type {SwalIcon[]} */ 177 const icons = ['success', 'warning', 'info', 'question', 'error']; 178 const iconTypes = icons.reduce((acc, icon) => { 179 acc[icon] = swalPrefix + icon; 180 return acc; 181 }, /** @type {SwalIcons} */{}); 182 183 const consolePrefix = 'SweetAlert2:'; 184 185 /** 186 * Capitalize the first letter of a string 187 * 188 * @param {string} str 189 * @returns {string} 190 */ 191 const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1); 192 193 /** 194 * Standardize console warnings 195 * 196 * @param {string | string[]} message 197 */ 198 const warn = message => { 199 console.warn("".concat(consolePrefix, " ").concat(typeof message === 'object' ? message.join(' ') : message)); 200 }; 201 202 /** 203 * Standardize console errors 204 * 205 * @param {string} message 206 */ 207 const error = message => { 208 console.error("".concat(consolePrefix, " ").concat(message)); 209 }; 210 211 /** 212 * Private global state for `warnOnce` 213 * 214 * @type {string[]} 215 * @private 216 */ 217 const previousWarnOnceMessages = []; 218 219 /** 220 * Show a console warning, but only if it hasn't already been shown 221 * 222 * @param {string} message 223 */ 224 const warnOnce = message => { 225 if (!previousWarnOnceMessages.includes(message)) { 226 previousWarnOnceMessages.push(message); 227 warn(message); 228 } 229 }; 230 231 /** 232 * Show a one-time console warning about deprecated params/methods 233 * 234 * @param {string} deprecatedParam 235 * @param {string} useInstead 236 */ 237 const warnAboutDeprecation = (deprecatedParam, useInstead) => { 238 warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead.")); 239 }; 240 241 /** 242 * If `arg` is a function, call it (with no arguments or context) and return the result. 243 * Otherwise, just pass the value through 244 * 245 * @param {Function | any} arg 246 * @returns {any} 247 */ 248 const callIfFunction = arg => typeof arg === 'function' ? arg() : arg; 249 250 /** 251 * @param {any} arg 252 * @returns {boolean} 253 */ 254 const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function'; 255 256 /** 257 * @param {any} arg 258 * @returns {Promise<any>} 259 */ 260 const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg); 261 262 /** 263 * @param {any} arg 264 * @returns {boolean} 265 */ 266 const isPromise = arg => arg && Promise.resolve(arg) === arg; 267 268 /** 269 * Gets the popup container which contains the backdrop and the popup itself. 270 * 271 * @returns {HTMLElement | null} 272 */ 273 const getContainer = () => document.body.querySelector(".".concat(swalClasses.container)); 274 275 /** 276 * @param {string}
vendor: 5,343 bytes, lines 276-449
276 selectorString 277 * @returns {HTMLElement | null} 278 */ 279 const elementBySelector = selectorString => { 280 const container = getContainer(); 281 return container ? container.querySelector(selectorString) : null; 282 }; 283 284 /** 285 * @param {string} className 286 * @returns {HTMLElement | null} 287 */ 288 const elementByClass = className => { 289 return elementBySelector(".".concat(className)); 290 }; 291 292 /** 293 * @returns {HTMLElement | null} 294 */ 295 const getPopup = () => elementByClass(swalClasses.popup); 296 297 /** 298 * @returns {HTMLElement | null} 299 */ 300 const getIcon = () => elementByClass(swalClasses.icon); 301 302 /** 303 * @returns {HTMLElement | null} 304 */ 305 const getIconContent = () => elementByClass(swalClasses['icon-content']); 306 307 /** 308 * @returns {HTMLElement | null} 309 */ 310 const getTitle = () => elementByClass(swalClasses.title); 311 312 /** 313 * @returns {HTMLElement | null} 314 */ 315 const getHtmlContainer = () => elementByClass(swalClasses['html-container']); 316 317 /** 318 * @returns {HTMLElement | null} 319 */ 320 const getImage = () => elementByClass(swalClasses.image); 321 322 /** 323 * @returns {HTMLElement | null} 324 */ 325 const getProgressSteps = () => elementByClass(swalClasses['progress-steps']); 326 327 /** 328 * @returns {HTMLElement | null} 329 */ 330 const getValidationMessage = () => elementByClass(swalClasses['validation-message']); 331 332 /** 333 * @returns {HTMLButtonElement | null} 334 */ 335 const getConfirmButton = () => /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm)); 336 337 /** 338 * @returns {HTMLButtonElement | null} 339 */ 340 const getCancelButton = () => /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel)); 341 342 /** 343 * @returns {HTMLButtonElement | null} 344 */ 345 const getDenyButton = () => /** @type {HTMLButtonElement} */elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.deny)); 346 347 /** 348 * @returns {HTMLElement | null} 349 */ 350 const getInputLabel = () => elementByClass(swalClasses['input-label']); 351 352 /** 353 * @returns {HTMLElement | null} 354 */ 355 const getLoader = () => elementBySelector(".".concat(swalClasses.loader)); 356 357 /** 358 * @returns {HTMLElement | null} 359 */ 360 const getActions = () => elementByClass(swalClasses.actions); 361 362 /** 363 * @returns {HTMLElement | null} 364 */ 365 const getFooter = () => elementByClass(swalClasses.footer); 366 367 /** 368 * @returns {HTMLElement | null} 369 */ 370 const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']); 371 372 /** 373 * @returns {HTMLElement | null} 374 */ 375 const getCloseButton = () => elementByClass(swalClasses.close); 376 377 // https://github.com/jkup/focusable/blob/master/index.js 378 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"; 379 /** 380 * @returns {HTMLElement[]} 381 */ 382 const getFocusableElements = () => { 383 const popup = getPopup(); 384 if (!popup) { 385 return []; 386 } 387 /** @type {NodeListOf<HTMLElement>} */ 388 const focusableElementsWithTabindex = popup.querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])'); 389 const focusableElementsWithTabindexSorted = Array.from(focusableElementsWithTabindex) 390 // sort according to tabindex 391 .sort((a, b) => { 392 const tabindexA = parseInt(a.getAttribute('tabindex') || '0'); 393 const tabindexB = parseInt(b.getAttribute('tabindex') || '0'); 394 if (tabindexA > tabindexB) { 395 return 1; 396 } else if (tabindexA < tabindexB) { 397 return -1; 398 } 399 return 0; 400 }); 401 402 /** @type {NodeListOf<HTMLElement>} */ 403 const otherFocusableElements = popup.querySelectorAll(focusable); 404 const otherFocusableElementsFiltered = Array.from(otherFocusableElements).filter(el => el.getAttribute('tabindex') !== '-1'); 405 return [...new Set(focusableElementsWithTabindexSorted.concat(otherFocusableElementsFiltered))].filter(el => isVisible$1(el)); 406 }; 407 408 /** 409 * @returns {boolean} 410 */ 411 const isModal = () => { 412 return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']); 413 }; 414 415 /** 416 * @returns {boolean} 417 */ 418 const isToast = () => { 419 const popup = getPopup(); 420 if (!popup) { 421 return false; 422 } 423 return hasClass(popup, swalClasses.toast); 424 }; 425 426 /** 427 * @returns {boolean} 428 */ 429 const isLoading = () => { 430 const popup = getPopup(); 431 if (!popup) { 432 return false; 433 } 434 return popup.hasAttribute('data-loading'); 435 }; 436 437 /** 438 * Securely set innerHTML of an element 439 * https://github.com/sweetalert2/sweetalert2/issues/1926 440 * 441 * @param {HTMLElement} elem 442 * @param {string} html 443 */ 444 const setInnerHtml = (elem, html) => { 445 elem.textContent = ''; 446 if (html) { 447 const parser = new DOMParser(); 448 const parsed = parser.parseFromString(html, "text/html"); 449 const head = parsed.querySelector('head');
450 head && Array.from(head.childNodes).forEach(child => { 451 elem.appendChild(child); 452 }); 453 const body = parsed.querySelector('body'); 454 body && Array.from(body.childNodes).forEach(child => { 455 if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) { 456 elem.appendChild(child.cloneNode(true)); // https://github.com/sweetalert2/sweetalert2/issues/2507 457 } else { 458 elem.appendChild(child); 459 } 460 }); 461 } 462 }; 463 464 /** 465 * @param {HTMLElement} elem 466 * @param {string} className 467 * @returns {boolean} 468 */ 469 const hasClass = (elem, className) => { 470 if (!className) { 471 return false; 472 } 473 const classList = className.split(/\s+/); 474 for (let i = 0; i < classList.length; i++) { 475 if (!elem.classList.contains(classList[i])) { 476 return false; 477 } 478 } 479 return true; 480 }; 481 482 /** 483 * @param {HTMLElement} elem 484 * @param {SweetAlertOptions} params 485 */ 486 const removeCustomClasses = (elem, params) => { 487 Array.from(elem.classList).forEach(className => { 488 if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass || {}).includes(className)) { 489 elem.classList.remove(className); 490 } 491 }); 492 }; 493 494 /** 495 * @param {HTMLElement} elem 496 * @param {SweetAlertOptions} params 497 * @param {string} className 498 */ 499 const applyCustomClass = (elem, params, className) => { 500 removeCustomClasses(elem, params); 501 if (params.customClass && params.customClass[className]) { 502 if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) { 503 warn("Invalid type of customClass.".concat(className, "! Expected string or iterable object, got \"").concat(typeof params.customClass[className], "\"")); 504 return; 505 } 506 addClass(elem, params.customClass[className]); 507 } 508 }; 509 510 /** 511 * @param {HTMLElement} popup 512 * @param {import('./renderers/renderInput').InputClass | SweetAlertInput} inputClass 513 * @returns {HTMLInputElement | null} 514 */ 515 const getInput$1 = (popup, inputClass) => { 516 if (!inputClass) { 517 return null; 518 } 519 switch (inputClass) { 520 case 'select': 521 case 'textarea': 522 case 'file': 523 return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses[inputClass])); 524 case 'checkbox': 525 return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.checkbox, " input")); 526 case 'radio': 527 return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:checked")) || popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:first-child")); 528 case 'range': 529 return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.range, " input")); 530 default: 531 return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.input)); 532 } 533 }; 534 535 /** 536 * @param {HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement} input 537 */ 538 const focusInput = input => { 539 input.focus(); 540 541 // place cursor at end of text in text input 542 if (input.type !== 'file') { 543 // http://stackoverflow.com/a/2345915 544 const val = input.value; 545 input.value = ''; 546 input.value = val; 547 } 548 }; 549 550 /** 551 * @param {HTMLElement | HTMLElement[] | null} target 552 * @param {string | string[] | readonly string[] | undefined} classList 553 * @param {boolean} condition 554 */ 555 const toggleClass = (target, classList, condition) => { 556 if (!target || !classList) { 557 return; 558 } 559 if (typeof classList === 'string') { 560 classList = classList.split(/\s+/).filter(Boolean); 561 } 562 classList.forEach(className => { 563 if (Array.isArray(target)) { 564 target.forEach(elem => { 565 condition ? elem.classList.add(className) : elem.classList.remove(className); 566 }); 567 } else { 568 condition ? target.classList.add(className) : target.classList.remove(className); 569 } 570 });
571 }; 572 573 /** 574 * @param {HTMLElement | HTMLElement[] | null} target 575 * @param {string | string[] | readonly string[] | undefined} classList 576 */ 577 const addClass = (target, classList) => { 578 toggleClass(target, classList, true); 579 }; 580 581 /** 582 * @param {HTMLElement | HTMLElement[] | null} target 583 * @param {string | string[] | readonly string[] | undefined} classList 584 */ 585 const removeClass = (target, classList) => { 586 toggleClass(target, classList, false); 587 }; 588 589 /** 590 * Get direct child of an element by class name 591 * 592 * @param {HTMLElement} elem 593 * @param {string} className 594 * @returns {HTMLElement | undefined} 595 */ 596 const getDirectChildByClass = (elem, className) => { 597 const children = Array.from(elem.children); 598 for (let i = 0; i < children.length; i++) { 599 const child = children[i]; 600 if (child instanceof HTMLElement && hasClass(child, className)) { 601 return child; 602 } 603 } 604 }; 605 606 /** 607 * @param {HTMLElement} elem 608 * @param {string} property 609 * @param {*} value 610 */ 611 const applyNumericalStyle = (elem, property, value) => { 612 if (value === "".concat(parseInt(value))) { 613 value = parseInt(value); 614 } 615 if (value || parseInt(value) === 0) { 616 elem.style[property] = typeof value === 'number' ? "".concat(value, "px") : value; 617 } else { 618 elem.style.removeProperty(property); 619 } 620 }; 621 622 /** 623 * @param {HTMLElement | null} elem 624 * @param {string} display 625 */ 626 const show = function (elem) { 627 let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex'; 628 elem && (elem.style.display = display); 629 }; 630 631 /** 632 * @param {HTMLElement | null} elem 633 */ 634 const hide = elem => { 635 elem && (elem.style.display = 'none'); 636 }; 637 638 /** 639 * @param {HTMLElement | null} elem 640 * @param {string} display 641 */ 642 const showWhenInnerHtmlPresent = function (elem) { 643 let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'block'; 644 if (!elem) { 645 return; 646 } 647 new MutationObserver(() => { 648 toggle(elem, elem.innerHTML, display); 649 }).observe(elem, { 650 childList: true, 651 subtree: true 652 }); 653 }; 654 655 /** 656 * @param {HTMLElement} parent 657 * @param {string} selector 658 * @param {string} property 659 * @param {string} value 660 */ 661 const setStyle = (parent, selector, property, value) => { 662 /** @type {HTMLElement} */ 663 const el = parent.querySelector(selector); 664 if (el) { 665 el.style[property] = value; 666 } 667 }; 668 669 /** 670 * @param {HTMLElement} elem 671 * @param {any} condition 672 * @param {string} display 673 */ 674 const toggle = function (elem, condition) { 675 let display = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'flex'; 676 condition ? show(elem, display) : hide(elem); 677 }; 678 679 /** 680 * borrowed from jquery $(elem).is(':visible') implementation 681 * 682 * @param {HTMLElement | null} elem 683 * @returns {boolean} 684 */ 685 const isVisible$1 = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length)); 686 687 /** 688 * @returns {boolean} 689 */ 690 const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton()); 691 692 /** 693 * @param {HTMLElement} elem 694 * @returns {boolean} 695 */ 696 const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight); 697 698 /** 699 * borrowed from https://stackoverflow.com/a/46352119 700 * 701 * @param {HTMLElement} elem 702 * @returns {boolean} 703 */ 704 const hasCssAnimation = elem => { 705 const style = window.getComputedStyle(elem); 706 const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0'); 707 const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0'); 708 return animDuration > 0 || transDuration > 0; 709 }; 710 711 /** 712 * @param {number} timer 713 * @param {boolean} reset 714 */ 715 const animateTimerProgressBar = function (timer) { 716 let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; 717 const timerProgressBar = getTimerProgressBar(); 718 if (!timerProgressBar) { 719 return; 720 } 721 if (isVisible$1(timerProgressBar)) { 722 if (reset) {
vendor: 5,724 bytes, lines 723-823
723 timerProgressBar.style.transition = 'none'; 724 timerProgressBar.style.width = '100%'; 725 } 726 setTimeout(() => { 727 timerProgressBar.style.transition = "width ".concat(timer / 1000, "s linear"); 728 timerProgressBar.style.width = '0%'; 729 }, 10); 730 } 731 }; 732 const stopTimerProgressBar = () => { 733 const timerProgressBar = getTimerProgressBar(); 734 if (!timerProgressBar) { 735 return; 736 } 737 const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width); 738 timerProgressBar.style.removeProperty('transition'); 739 timerProgressBar.style.width = '100%'; 740 const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width); 741 const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100; 742 timerProgressBar.style.width = "".concat(timerProgressBarPercent, "%"); 743 }; 744 745 /** 746 * Detect Node env 747 * 748 * @returns {boolean} 749 */ 750 const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined'; 751 752 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, "\" id=\"").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, "\" id=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" id=\"").concat(swalClasses.checkbox, "\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\" id=\"").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, ''); 753 754 /** 755 * @returns {boolean} 756 */ 757 const resetOldContainer = () => { 758 const oldContainer = getContainer(); 759 if (!oldContainer) { 760 return false; 761 } 762 oldContainer.remove(); 763 removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]); 764 return true; 765 }; 766 const resetValidationMessage$1 = () => { 767 globalState.currentInstance.resetValidationMessage(); 768 }; 769 const addInputChangeListeners = () => { 770 const popup = getPopup(); 771 const input = getDirectChildByClass(popup, swalClasses.input); 772 const file = getDirectChildByClass(popup, swalClasses.file); 773 /** @type {HTMLInputElement} */ 774 const range = popup.querySelector(".".concat(swalClasses.range, " input")); 775 /** @type {HTMLOutputElement} */ 776 const rangeOutput = popup.querySelector(".".concat(swalClasses.range, " output")); 777 const select = getDirectChildByClass(popup, swalClasses.select); 778 /** @type {HTMLInputElement} */ 779 const checkbox = popup.querySelector(".".concat(swalClasses.checkbox, " input")); 780 const textarea = getDirectChildByClass(popup, swalClasses.textarea); 781 input.oninput = resetValidationMessage$1; 782 file.onchange = resetValidationMessage$1; 783 select.onchange = resetValidationMessage$1; 784 checkbox.onchange = resetValidationMessage$1; 785 textarea.oninput = resetValidationMessage$1; 786 range.oninput = () => { 787 resetValidationMessage$1(); 788 rangeOutput.value = range.value; 789 }; 790 range.onchange = () => { 791 resetValidationMessage$1(); 792 rangeOutput.value = range.value; 793 }; 794 }; 795 796 /** 797 * @param {string | HTMLElement} target 798 * @returns {HTMLElement} 799 */ 800 const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target; 801 802 /** 803 * @param {SweetAlertOptions} params 804 */ 805 const setupAccessibility = params => { 806 const popup = getPopup(); 807 popup.setAttribute('role', params.toast ? 'alert' : 'dialog'); 808 popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive'); 809 if (!params.toast) { 810 popup.setAttribute('aria-modal', 'true'); 811 } 812 }; 813 814 /** 815 * @param {HTMLElement} targetElement 816 */ 817 const setupRTL = targetElement => { 818 if (window.getComputedStyle(targetElement).direction === 'rtl') { 819 addClass(getContainer(), swalClasses.rtl); 820 } 821 }; 822 823 /**
824 * Add modal + backdrop + no-war message for Russians to DOM 825 * 826 * @param {SweetAlertOptions} params 827 */ 828 const init = params => { 829 // Clean up the old popup container if it exists 830 const oldContainerExisted = resetOldContainer(); 831 if (isNodeEnv()) { 832 error('SweetAlert2 requires document to initialize'); 833 return; 834 } 835 const container = document.createElement('div'); 836 container.className = swalClasses.container; 837 if (oldContainerExisted) { 838 addClass(container, swalClasses['no-transition']); 839 } 840 setInnerHtml(container, sweetHTML); 841 const targetElement = getTarget(params.target); 842 targetElement.appendChild(container); 843 setupAccessibility(params); 844 setupRTL(targetElement); 845 addInputChangeListeners(); 846 }; 847 848 /** 849 * @param {HTMLElement | object | string} param 850 * @param {HTMLElement} target 851 */ 852 const parseHtmlToContainer = (param, target) => { 853 // DOM element 854 if (param instanceof HTMLElement) { 855 target.appendChild(param); 856 } 857 858 // Object 859 else if (typeof param === 'object') { 860 handleObject(param, target); 861 } 862 863 // Plain string 864 else if (param) { 865 setInnerHtml(target, param); 866 } 867 }; 868 869 /** 870 * @param {any} param 871 * @param {HTMLElement} target 872 */ 873 const handleObject = (param, target) => { 874 // JQuery element(s) 875 if (param.jquery) { 876 handleJqueryElem(target, param); 877 } 878 879 // For other objects use their string representation 880 else { 881 setInnerHtml(target, param.toString()); 882 } 883 }; 884 885 /** 886 * @param {HTMLElement} target 887 * @param {any} elem 888 */ 889 const handleJqueryElem = (target, elem) => { 890 target.textContent = ''; 891 if (0 in elem) { 892 for (let i = 0; (i in elem); i++) { 893 target.appendChild(elem[i].cloneNode(true)); 894 } 895 } else { 896 target.appendChild(elem.cloneNode(true)); 897 } 898 }; 899 900 /** 901 * @returns {'webkitAnimationEnd' | 'animationend' | false} 902 */ 903 const animationEndEvent = (() => { 904 // Prevent run in Node env 905 if (isNodeEnv()) { 906 return false; 907 } 908 const testEl = document.createElement('div'); 909 910 // Chrome, Safari and Opera 911 if (typeof testEl.style.webkitAnimation !== 'undefined') { 912 return 'webkitAnimationEnd'; 913 } 914 915 // Standard syntax 916 if (typeof testEl.style.animation !== 'undefined') { 917 return 'animationend'; 918 } 919 return false; 920 })();
vendor: 19,619 bytes, lines 921-1528
921 922 /** 923 * @param {SweetAlert} instance 924 * @param {SweetAlertOptions} params 925 */ 926 const renderActions = (instance, params) => { 927 const actions = getActions(); 928 const loader = getLoader(); 929 if (!actions || !loader) { 930 return; 931 } 932 933 // Actions (buttons) wrapper 934 if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) { 935 hide(actions); 936 } else { 937 show(actions); 938 } 939 940 // Custom class 941 applyCustomClass(actions, params, 'actions'); 942 943 // Render all the buttons 944 renderButtons(actions, loader, params); 945 946 // Loader 947 setInnerHtml(loader, params.loaderHtml || ''); 948 applyCustomClass(loader, params, 'loader'); 949 }; 950 951 /** 952 * @param {HTMLElement} actions 953 * @param {HTMLElement} loader 954 * @param {SweetAlertOptions} params 955 */ 956 function renderButtons(actions, loader, params) { 957 const confirmButton = getConfirmButton(); 958 const denyButton = getDenyButton(); 959 const cancelButton = getCancelButton(); 960 if (!confirmButton || !denyButton || !cancelButton) { 961 return; 962 } 963 964 // Render buttons 965 renderButton(confirmButton, 'confirm', params); 966 renderButton(denyButton, 'deny', params); 967 renderButton(cancelButton, 'cancel', params); 968 handleButtonsStyling(confirmButton, denyButton, cancelButton, params); 969 if (params.reverseButtons) { 970 if (params.toast) { 971 actions.insertBefore(cancelButton, confirmButton); 972 actions.insertBefore(denyButton, confirmButton); 973 } else { 974 actions.insertBefore(cancelButton, loader); 975 actions.insertBefore(denyButton, loader); 976 actions.insertBefore(confirmButton, loader); 977 } 978 } 979 } 980 981 /** 982 * @param {HTMLElement} confirmButton 983 * @param {HTMLElement} denyButton 984 * @param {HTMLElement} cancelButton 985 * @param {SweetAlertOptions} params 986 */ 987 function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) { 988 if (!params.buttonsStyling) { 989 removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled); 990 return; 991 } 992 addClass([confirmButton, denyButton, cancelButton], swalClasses.styled); 993 994 // Buttons background colors 995 if (params.confirmButtonColor) { 996 confirmButton.style.backgroundColor = params.confirmButtonColor; 997 addClass(confirmButton, swalClasses['default-outline']); 998 } 999 if (params.denyButtonColor) { 1000 denyButton.style.backgroundColor = params.denyButtonColor; 1001 addClass(denyButton, swalClasses['default-outline']); 1002 } 1003 if (params.cancelButtonColor) { 1004 cancelButton.style.backgroundColor = params.cancelButtonColor; 1005 addClass(cancelButton, swalClasses['default-outline']); 1006 } 1007 } 1008 1009 /** 1010 * @param {HTMLElement} button 1011 * @param {'confirm' | 'deny' | 'cancel'} buttonType 1012 * @param {SweetAlertOptions} params 1013 */ 1014 function renderButton(button, buttonType, params) { 1015 const buttonName = /** @type {'Confirm' | 'Deny' | 'Cancel'} */capitalizeFirstLetter(buttonType); 1016 toggle(button, params["show".concat(buttonName, "Button")], 'inline-block'); 1017 setInnerHtml(button, params["".concat(buttonType, "ButtonText")] || ''); // Set caption text 1018 button.setAttribute('aria-label', params["".concat(buttonType, "ButtonAriaLabel")] || ''); // ARIA label 1019 1020 // Add buttons custom classes 1021 button.className = swalClasses[buttonType]; 1022 applyCustomClass(button, params, "".concat(buttonType, "Button")); 1023 } 1024 1025 /** 1026 * @param {SweetAlert} instance 1027 * @param {SweetAlertOptions} params 1028 */ 1029 const renderCloseButton = (instance, params) => { 1030 const closeButton = getCloseButton(); 1031 if (!closeButton) { 1032 return; 1033 } 1034 setInnerHtml(closeButton, params.closeButtonHtml || ''); 1035 1036 // Custom class 1037 applyCustomClass(closeButton, params, 'closeButton'); 1038 toggle(closeButton, params.showCloseButton); 1039 closeButton.setAttribute('aria-label', params.closeButtonAriaLabel || ''); 1040 }; 1041 1042 /** 1043 * @param {SweetAlert} instance 1044 * @param {SweetAlertOptions} params 1045 */ 1046 const renderContainer = (instance, params) => { 1047 const container = getContainer(); 1048 if (!container) { 1049 return; 1050 } 1051 handleBackdropParam(container, params.backdrop); 1052 handlePositionParam(container, params.position); 1053 handleGrowParam(container, params.grow); 1054 1055 // Custom class 1056 applyCustomClass(container, params, 'container'); 1057 }; 1058 1059 /** 1060 * @param {HTMLElement} container 1061 * @param {SweetAlertOptions['backdrop']} backdrop 1062 */ 1063 function handleBackdropParam(container, backdrop) { 1064 if (typeof backdrop === 'string') { 1065 container.style.background = backdrop; 1066 } else if (!backdrop) { 1067 addClass([document.documentElement, document.body], swalClasses['no-backdrop']); 1068 } 1069 } 1070 1071 /** 1072 * @param {HTMLElement} container 1073 * @param {SweetAlertOptions['position']} position 1074 */ 1075 function handlePositionParam(container, position) { 1076 if (!position) { 1077 return; 1078 } 1079 if (position in swalClasses) { 1080 addClass(container, swalClasses[position]); 1081 } else { 1082 warn('The "position" parameter is not valid, defaulting to "center"'); 1083 addClass(container, swalClasses.center); 1084 } 1085 } 1086 1087 /** 1088 * @param {HTMLElement} container 1089 * @param {SweetAlertOptions['grow']} grow 1090 */ 1091 function handleGrowParam(container, grow) { 1092 if (!grow) { 1093 return; 1094 } 1095 addClass(container, swalClasses["grow-".concat(grow)]); 1096 } 1097 1098 /** 1099 * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has. 1100 * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` 1101 * This is the approach that Babel will probably take to implement private methods/fields 1102 * https://github.com/tc39/proposal-private-methods 1103 * https://github.com/babel/babel/pull/7555 1104 * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* 1105 * then we can use that language feature. 1106 */ 1107 1108 var privateProps = { 1109 innerParams: new WeakMap(), 1110 domCache: new WeakMap() 1111 }; 1112 1113 /// <reference path="../../../../sweetalert2.d.ts"/> 1114 1115 1116 /** @type {InputClass[]} */ 1117 const inputClasses = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea']; 1118 1119 /** 1120 * @param {SweetAlert} instance 1121 * @param {SweetAlertOptions} params 1122 */ 1123 const renderInput = (instance, params) => { 1124 const popup = getPopup(); 1125 if (!popup) { 1126 return; 1127 } 1128 const innerParams = privateProps.innerParams.get(instance); 1129 const rerender = !innerParams || params.input !== innerParams.input; 1130 inputClasses.forEach(inputClass => { 1131 const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]); 1132 if (!inputContainer) { 1133 return; 1134 } 1135 1136 // set attributes 1137 setAttributes(inputClass, params.inputAttributes); 1138 1139 // set class 1140 inputContainer.className = swalClasses[inputClass]; 1141 if (rerender) { 1142 hide(inputContainer); 1143 } 1144 }); 1145 if (params.input) { 1146 if (rerender) { 1147 showInput(params); 1148 } 1149 // set custom class 1150 setCustomClass(params); 1151 } 1152 }; 1153 1154 /** 1155 * @param {SweetAlertOptions} params 1156 */ 1157 const showInput = params => { 1158 if (!params.input) { 1159 return; 1160 } 1161 if (!renderInputType[params.input]) { 1162 error("Unexpected type of input! Expected ".concat(Object.keys(renderInputType).join(' | '), ", got \"").concat(params.input, "\"")); 1163 return; 1164 } 1165 const inputContainer = getInputContainer(params.input); 1166 const input = renderInputType[params.input](inputContainer, params); 1167 show(inputContainer); 1168 1169 // input autofocus 1170 if (params.inputAutoFocus) { 1171 setTimeout(() => { 1172 focusInput(input); 1173 }); 1174 } 1175 }; 1176 1177 /** 1178 * @param {HTMLInputElement} input 1179 */ 1180 const removeAttributes = input => { 1181 for (let i = 0; i < input.attributes.length; i++) { 1182 const attrName = input.attributes[i].name; 1183 if (!['id', 'type', 'value', 'style'].includes(attrName)) { 1184 input.removeAttribute(attrName); 1185 } 1186 } 1187 }; 1188 1189 /** 1190 * @param {InputClass} inputClass 1191 * @param {SweetAlertOptions['inputAttributes']} inputAttributes 1192 */ 1193 const setAttributes = (inputClass, inputAttributes) => { 1194 const input = getInput$1(getPopup(), inputClass); 1195 if (!input) { 1196 return; 1197 } 1198 removeAttributes(input); 1199 for (const attr in inputAttributes) { 1200 input.setAttribute(attr, inputAttributes[attr]); 1201 } 1202 }; 1203 1204 /** 1205 * @param {SweetAlertOptions} params 1206 */ 1207 const setCustomClass = params => { 1208 const inputContainer = getInputContainer(params.input); 1209 if (typeof params.customClass === 'object') { 1210 addClass(inputContainer, params.customClass.input); 1211 } 1212 }; 1213 1214 /** 1215 * @param {HTMLInputElement | HTMLTextAreaElement} input 1216 * @param {SweetAlertOptions} params 1217 */ 1218 const setInputPlaceholder = (input, params) => { 1219 if (!input.placeholder || params.inputPlaceholder) { 1220 input.placeholder = params.inputPlaceholder; 1221 } 1222 }; 1223 1224 /** 1225 * @param {Input} input 1226 * @param {Input} prependTo 1227 * @param {SweetAlertOptions} params 1228 */ 1229 const setInputLabel = (input, prependTo, params) => { 1230 if (params.inputLabel) { 1231 const label = document.createElement('label'); 1232 const labelClass = swalClasses['input-label']; 1233 label.setAttribute('for', input.id); 1234 label.className = labelClass; 1235 if (typeof params.customClass === 'object') { 1236 addClass(label, params.customClass.inputLabel); 1237 } 1238 label.innerText = params.inputLabel; 1239 prependTo.insertAdjacentElement('beforebegin', label); 1240 } 1241 }; 1242 1243 /** 1244 * @param {SweetAlertOptions['input']} inputType 1245 * @returns {HTMLElement} 1246 */ 1247 const getInputContainer = inputType => { 1248 return getDirectChildByClass(getPopup(), swalClasses[inputType] || swalClasses.input); 1249 }; 1250 1251 /** 1252 * @param {HTMLInputElement | HTMLOutputElement | HTMLTextAreaElement} input 1253 * @param {SweetAlertOptions['inputValue']} inputValue 1254 */ 1255 const checkAndSetInputValue = (input, inputValue) => { 1256 if (['string', 'number'].includes(typeof inputValue)) { 1257 input.value = "".concat(inputValue); 1258 } else if (!isPromise(inputValue)) { 1259 warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(typeof inputValue, "\"")); 1260 } 1261 }; 1262 1263 /** @type {Record<SweetAlertInput, (input: Input | HTMLElement, params: SweetAlertOptions) => Input>} */ 1264 const renderInputType = {}; 1265 1266 /** 1267 * @param {HTMLInputElement} input 1268 * @param {SweetAlertOptions} params 1269 * @returns {HTMLInputElement} 1270 */ 1271 renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = renderInputType.search = renderInputType.date = renderInputType['datetime-local'] = renderInputType.time = renderInputType.week = renderInputType.month = (input, params) => { 1272 checkAndSetInputValue(input, params.inputValue); 1273 setInputLabel(input, input, params); 1274 setInputPlaceholder(input, params); 1275 input.type = params.input; 1276 return input; 1277 }; 1278 1279 /** 1280 * @param {HTMLInputElement} input 1281 * @param {SweetAlertOptions} params 1282 * @returns {HTMLInputElement} 1283 */ 1284 renderInputType.file = (input, params) => { 1285 setInputLabel(input, input, params); 1286 setInputPlaceholder(input, params); 1287 return input; 1288 }; 1289 1290 /** 1291 * @param {HTMLInputElement} range 1292 * @param {SweetAlertOptions} params 1293 * @returns {HTMLInputElement} 1294 */ 1295 renderInputType.range = (range, params) => { 1296 const rangeInput = range.querySelector('input'); 1297 const rangeOutput = range.querySelector('output'); 1298 checkAndSetInputValue(rangeInput, params.inputValue); 1299 rangeInput.type = params.input; 1300 checkAndSetInputValue(rangeOutput, params.inputValue); 1301 setInputLabel(rangeInput, range, params); 1302 return range; 1303 }; 1304 1305 /** 1306 * @param {HTMLSelectElement} select 1307 * @param {SweetAlertOptions} params 1308 * @returns {HTMLSelectElement} 1309 */ 1310 renderInputType.select = (select, params) => { 1311 select.textContent = ''; 1312 if (params.inputPlaceholder) { 1313 const placeholder = document.createElement('option'); 1314 setInnerHtml(placeholder, params.inputPlaceholder); 1315 placeholder.value = ''; 1316 placeholder.disabled = true; 1317 placeholder.selected = true; 1318 select.appendChild(placeholder); 1319 } 1320 setInputLabel(select, select, params); 1321 return select; 1322 }; 1323 1324 /** 1325 * @param {HTMLInputElement} radio 1326 * @returns {HTMLInputElement} 1327 */ 1328 renderInputType.radio = radio => { 1329 radio.textContent = ''; 1330 return radio; 1331 }; 1332 1333 /** 1334 * @param {HTMLLabelElement} checkboxContainer 1335 * @param {SweetAlertOptions} params 1336 * @returns {HTMLInputElement} 1337 */ 1338 renderInputType.checkbox = (checkboxContainer, params) => { 1339 const checkbox = getInput$1(getPopup(), 'checkbox'); 1340 checkbox.value = '1'; 1341 checkbox.checked = Boolean(params.inputValue); 1342 const label = checkboxContainer.querySelector('span'); 1343 setInnerHtml(label, params.inputPlaceholder); 1344 return checkbox; 1345 }; 1346 1347 /** 1348 * @param {HTMLTextAreaElement} textarea 1349 * @param {SweetAlertOptions} params 1350 * @returns {HTMLTextAreaElement} 1351 */ 1352 renderInputType.textarea = (textarea, params) => { 1353 checkAndSetInputValue(textarea, params.inputValue); 1354 setInputPlaceholder(textarea, params); 1355 setInputLabel(textarea, textarea, params); 1356 1357 /** 1358 * @param {HTMLElement} el 1359 * @returns {number} 1360 */ 1361 const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight); 1362 1363 // https://github.com/sweetalert2/sweetalert2/issues/2291 1364 setTimeout(() => { 1365 // https://github.com/sweetalert2/sweetalert2/issues/1699 1366 if ('MutationObserver' in window) { 1367 const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width); 1368 const textareaResizeHandler = () => { 1369 // check if texarea is still in document (i.e. popup wasn't closed in the meantime) 1370 if (!document.body.contains(textarea)) { 1371 return; 1372 } 1373 const textareaWidth = textarea.offsetWidth + getMargin(textarea); 1374 if (textareaWidth > initialPopupWidth) { 1375 getPopup().style.width = "".concat(textareaWidth, "px"); 1376 } else { 1377 applyNumericalStyle(getPopup(), 'width', params.width); 1378 } 1379 }; 1380 new MutationObserver(textareaResizeHandler).observe(textarea, { 1381 attributes: true, 1382 attributeFilter: ['style'] 1383 }); 1384 } 1385 }); 1386 return textarea; 1387 }; 1388 1389 /** 1390 * @param {SweetAlert} instance 1391 * @param {SweetAlertOptions} params 1392 */ 1393 const renderContent = (instance, params) => { 1394 const htmlContainer = getHtmlContainer(); 1395 if (!htmlContainer) { 1396 return; 1397 } 1398 showWhenInnerHtmlPresent(htmlContainer); 1399 applyCustomClass(htmlContainer, params, 'htmlContainer'); 1400 1401 // Content as HTML 1402 if (params.html) { 1403 parseHtmlToContainer(params.html, htmlContainer); 1404 show(htmlContainer, 'block'); 1405 } 1406 1407 // Content as plain text 1408 else if (params.text) { 1409 htmlContainer.textContent = params.text; 1410 show(htmlContainer, 'block'); 1411 } 1412 1413 // No content 1414 else { 1415 hide(htmlContainer); 1416 } 1417 renderInput(instance, params); 1418 }; 1419 1420 /** 1421 * @param {SweetAlert} instance 1422 * @param {SweetAlertOptions} params 1423 */ 1424 const renderFooter = (instance, params) => { 1425 const footer = getFooter(); 1426 if (!footer) { 1427 return; 1428 } 1429 showWhenInnerHtmlPresent(footer); 1430 toggle(footer, params.footer, 'block'); 1431 if (params.footer) { 1432 parseHtmlToContainer(params.footer, footer); 1433 } 1434 1435 // Custom class 1436 applyCustomClass(footer, params, 'footer'); 1437 }; 1438 1439 /** 1440 * @param {SweetAlert} instance 1441 * @param {SweetAlertOptions} params 1442 */ 1443 const renderIcon = (instance, params) => { 1444 const innerParams = privateProps.innerParams.get(instance); 1445 const icon = getIcon(); 1446 if (!icon) { 1447 return; 1448 } 1449 1450 // if the given icon already rendered, apply the styling without re-rendering the icon 1451 if (innerParams && params.icon === innerParams.icon) { 1452 // Custom or default content 1453 setContent(icon, params); 1454 applyStyles(icon, params); 1455 return; 1456 } 1457 if (!params.icon && !params.iconHtml) { 1458 hide(icon); 1459 return; 1460 } 1461 if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) { 1462 error("Unknown icon! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.icon, "\"")); 1463 hide(icon); 1464 return; 1465 } 1466 show(icon); 1467 1468 // Custom or default content 1469 setContent(icon, params); 1470 applyStyles(icon, params); 1471 1472 // Animate icon 1473 addClass(icon, params.showClass && params.showClass.icon); 1474 }; 1475 1476 /** 1477 * @param {HTMLElement} icon 1478 * @param {SweetAlertOptions} params 1479 */ 1480 const applyStyles = (icon, params) => { 1481 for (const [iconType, iconClassName] of Object.entries(iconTypes)) { 1482 if (params.icon !== iconType) { 1483 removeClass(icon, iconClassName); 1484 } 1485 } 1486 addClass(icon, params.icon && iconTypes[params.icon]); 1487 1488 // Icon color 1489 setColor(icon, params); 1490 1491 // Success icon background color 1492 adjustSuccessIconBackgroundColor(); 1493 1494 // Custom class 1495 applyCustomClass(icon, params, 'icon'); 1496 }; 1497 1498 // Adjust success icon background color to match the popup background color 1499 const adjustSuccessIconBackgroundColor = () => { 1500 const popup = getPopup(); 1501 if (!popup) { 1502 return; 1503 } 1504 const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color'); 1505 /** @type {NodeListOf<HTMLElement>} */ 1506 const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix'); 1507 for (let i = 0; i < successIconParts.length; i++) { 1508 successIconParts[i].style.backgroundColor = popupBackgroundColor; 1509 } 1510 }; 1511 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"; 1512 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"; 1513 1514 /** 1515 * @param {HTMLElement} icon 1516 * @param {SweetAlertOptions} params 1517 */ 1518 const setContent = (icon, params) => { 1519 if (!params.icon && !params.iconHtml) { 1520 return; 1521 } 1522 let oldContent = icon.innerHTML; 1523 let newContent = ''; 1524 if (params.iconHtml) { 1525 newContent = iconContent(params.iconHtml); 1526 } else if (params.icon === 'success') { 1527 newContent = successIconHtml; 1528 oldContent = oldContent.replace(/ style=".*?"/g, '');
vendor: 4,977 bytes, lines 1528-1693
1528 // undo adjustSuccessIconBackgroundColor() 1529 } else if (params.icon === 'error') { 1530 newContent = errorIconHtml; 1531 } else if (params.icon) { 1532 const defaultIconHtml = { 1533 question: '?', 1534 warning: '!', 1535 info: 'i' 1536 }; 1537 newContent = iconContent(defaultIconHtml[params.icon]); 1538 } 1539 if (oldContent.trim() !== newContent.trim()) { 1540 setInnerHtml(icon, newContent); 1541 } 1542 }; 1543 1544 /** 1545 * @param {HTMLElement} icon 1546 * @param {SweetAlertOptions} params 1547 */ 1548 const setColor = (icon, params) => { 1549 if (!params.iconColor) { 1550 return; 1551 } 1552 icon.style.color = params.iconColor; 1553 icon.style.borderColor = params.iconColor; 1554 for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) { 1555 setStyle(icon, sel, 'backgroundColor', params.iconColor); 1556 } 1557 setStyle(icon, '.swal2-success-ring', 'borderColor', params.iconColor); 1558 }; 1559 1560 /** 1561 * @param {string} content 1562 * @returns {string} 1563 */ 1564 const iconContent = content => "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>"); 1565 1566 /** 1567 * @param {SweetAlert} instance 1568 * @param {SweetAlertOptions} params 1569 */ 1570 const renderImage = (instance, params) => { 1571 const image = getImage(); 1572 if (!image) { 1573 return; 1574 } 1575 if (!params.imageUrl) { 1576 hide(image); 1577 return; 1578 } 1579 show(image, ''); 1580 1581 // Src, alt 1582 image.setAttribute('src', params.imageUrl); 1583 image.setAttribute('alt', params.imageAlt || ''); 1584 1585 // Width, height 1586 applyNumericalStyle(image, 'width', params.imageWidth); 1587 applyNumericalStyle(image, 'height', params.imageHeight); 1588 1589 // Class 1590 image.className = swalClasses.image; 1591 applyCustomClass(image, params, 'image'); 1592 }; 1593 1594 /** 1595 * @param {SweetAlert} instance 1596 * @param {SweetAlertOptions} params 1597 */ 1598 const renderPopup = (instance, params) => { 1599 const container = getContainer(); 1600 const popup = getPopup(); 1601 if (!container || !popup) { 1602 return; 1603 } 1604 1605 // Width 1606 // https://github.com/sweetalert2/sweetalert2/issues/2170 1607 if (params.toast) { 1608 applyNumericalStyle(container, 'width', params.width); 1609 popup.style.width = '100%'; 1610 const loader = getLoader(); 1611 loader && popup.insertBefore(loader, getIcon()); 1612 } else { 1613 applyNumericalStyle(popup, 'width', params.width); 1614 } 1615 1616 // Padding 1617 applyNumericalStyle(popup, 'padding', params.padding); 1618 1619 // Color 1620 if (params.color) { 1621 popup.style.color = params.color; 1622 } 1623 1624 // Background 1625 if (params.background) { 1626 popup.style.background = params.background; 1627 } 1628 hide(getValidationMessage()); 1629 1630 // Classes 1631 addClasses$1(popup, params); 1632 }; 1633 1634 /** 1635 * @param {HTMLElement} popup 1636 * @param {SweetAlertOptions} params 1637 */ 1638 const addClasses$1 = (popup, params) => { 1639 const showClass = params.showClass || {}; 1640 // Default Class + showClass when updating Swal.update({}) 1641 popup.className = "".concat(swalClasses.popup, " ").concat(isVisible$1(popup) ? showClass.popup : ''); 1642 if (params.toast) { 1643 addClass([document.documentElement, document.body], swalClasses['toast-shown']); 1644 addClass(popup, swalClasses.toast); 1645 } else { 1646 addClass(popup, swalClasses.modal); 1647 } 1648 1649 // Custom class 1650 applyCustomClass(popup, params, 'popup'); 1651 if (typeof params.customClass === 'string') { 1652 addClass(popup, params.customClass); 1653 } 1654 1655 // Icon class (#1842) 1656 if (params.icon) { 1657 addClass(popup, swalClasses["icon-".concat(params.icon)]); 1658 } 1659 }; 1660 1661 /** 1662 * @param {SweetAlert} instance 1663 * @param {SweetAlertOptions} params 1664 */ 1665 const renderProgressSteps = (instance, params) => { 1666 const progressStepsContainer = getProgressSteps(); 1667 if (!progressStepsContainer) { 1668 return; 1669 } 1670 const { 1671 progressSteps, 1672 currentProgressStep 1673 } = params; 1674 if (!progressSteps || progressSteps.length === 0 || currentProgressStep === undefined) { 1675 hide(progressStepsContainer); 1676 return; 1677 } 1678 show(progressStepsContainer); 1679 progressStepsContainer.textContent = ''; 1680 if (currentProgressStep >= progressSteps.length) { 1681 warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)'); 1682 } 1683 progressSteps.forEach((step, index) => { 1684 const stepEl = createStepElement(step); 1685 progressStepsContainer.appendChild(stepEl); 1686 if (index === currentProgressStep) { 1687 addClass(stepEl, swalClasses['active-progress-step']); 1688 } 1689 if (index !== progressSteps.length - 1) { 1690 const lineEl = createLineElement(params); 1691 progressStepsContainer.appendChild(lineEl); 1692 } 1693 });
vendor: 13,867 bytes, lines 1694-2144
1694 }; 1695 1696 /** 1697 * @param {string} step 1698 * @returns {HTMLLIElement} 1699 */ 1700 const createStepElement = step => { 1701 const stepEl = document.createElement('li'); 1702 addClass(stepEl, swalClasses['progress-step']); 1703 setInnerHtml(stepEl, step); 1704 return stepEl; 1705 }; 1706 1707 /** 1708 * @param {SweetAlertOptions} params 1709 * @returns {HTMLLIElement} 1710 */ 1711 const createLineElement = params => { 1712 const lineEl = document.createElement('li'); 1713 addClass(lineEl, swalClasses['progress-step-line']); 1714 if (params.progressStepsDistance) { 1715 applyNumericalStyle(lineEl, 'width', params.progressStepsDistance); 1716 } 1717 return lineEl; 1718 }; 1719 1720 /** 1721 * @param {SweetAlert} instance 1722 * @param {SweetAlertOptions} params 1723 */ 1724 const renderTitle = (instance, params) => { 1725 const title = getTitle(); 1726 if (!title) { 1727 return; 1728 } 1729 showWhenInnerHtmlPresent(title); 1730 toggle(title, params.title || params.titleText, 'block'); 1731 if (params.title) { 1732 parseHtmlToContainer(params.title, title); 1733 } 1734 if (params.titleText) { 1735 title.innerText = params.titleText; 1736 } 1737 1738 // Custom class 1739 applyCustomClass(title, params, 'title'); 1740 }; 1741 1742 /** 1743 * @param {SweetAlert} instance 1744 * @param {SweetAlertOptions} params 1745 */ 1746 const render = (instance, params) => { 1747 renderPopup(instance, params); 1748 renderContainer(instance, params); 1749 renderProgressSteps(instance, params); 1750 renderIcon(instance, params); 1751 renderImage(instance, params); 1752 renderTitle(instance, params); 1753 renderCloseButton(instance, params); 1754 renderContent(instance, params); 1755 renderActions(instance, params); 1756 renderFooter(instance, params); 1757 const popup = getPopup(); 1758 if (typeof params.didRender === 'function' && popup) { 1759 params.didRender(popup); 1760 } 1761 }; 1762 1763 /* 1764 * Global function to determine if SweetAlert2 popup is shown 1765 */ 1766 const isVisible = () => { 1767 return isVisible$1(getPopup()); 1768 }; 1769 1770 /* 1771 * Global function to click 'Confirm' button 1772 */ 1773 const clickConfirm = () => { 1774 var _dom$getConfirmButton; 1775 return (_dom$getConfirmButton = getConfirmButton()) === null || _dom$getConfirmButton === void 0 ? void 0 : _dom$getConfirmButton.click(); 1776 }; 1777 1778 /* 1779 * Global function to click 'Deny' button 1780 */ 1781 const clickDeny = () => { 1782 var _dom$getDenyButton; 1783 return (_dom$getDenyButton = getDenyButton()) === null || _dom$getDenyButton === void 0 ? void 0 : _dom$getDenyButton.click(); 1784 }; 1785 1786 /* 1787 * Global function to click 'Cancel' button 1788 */ 1789 const clickCancel = () => { 1790 var _dom$getCancelButton; 1791 return (_dom$getCancelButton = getCancelButton()) === null || _dom$getCancelButton === void 0 ? void 0 : _dom$getCancelButton.click(); 1792 }; 1793 1794 /** @typedef {'cancel' | 'backdrop' | 'close' | 'esc' | 'timer'} DismissReason */ 1795 1796 /** @type {Record<DismissReason, DismissReason>} */ 1797 const DismissReason = Object.freeze({ 1798 cancel: 'cancel', 1799 backdrop: 'backdrop', 1800 close: 'close', 1801 esc: 'esc', 1802 timer: 'timer' 1803 }); 1804 1805 /** 1806 * @param {GlobalState} globalState 1807 */ 1808 const removeKeydownHandler = globalState => { 1809 if (globalState.keydownTarget && globalState.keydownHandlerAdded) { 1810 globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, { 1811 capture: globalState.keydownListenerCapture 1812 }); 1813 globalState.keydownHandlerAdded = false; 1814 } 1815 }; 1816 1817 /** 1818 * @param {GlobalState} globalState 1819 * @param {SweetAlertOptions} innerParams 1820 * @param {*} dismissWith 1821 */ 1822 const addKeydownHandler = (globalState, innerParams, dismissWith) => { 1823 removeKeydownHandler(globalState); 1824 if (!innerParams.toast) { 1825 globalState.keydownHandler = e => keydownHandler(innerParams, e, dismissWith); 1826 globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup(); 1827 globalState.keydownListenerCapture = innerParams.keydownListenerCapture; 1828 globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, { 1829 capture: globalState.keydownListenerCapture 1830 }); 1831 globalState.keydownHandlerAdded = true; 1832 } 1833 }; 1834 1835 /** 1836 * @param {number} index 1837 * @param {number} increment 1838 */ 1839 const setFocus = (index, increment) => { 1840 var _dom$getPopup; 1841 const focusableElements = getFocusableElements(); 1842 // search for visible elements and select the next possible match 1843 if (focusableElements.length) { 1844 index = index + increment; 1845 1846 // rollover to first item 1847 if (index === focusableElements.length) { 1848 index = 0; 1849 1850 // go to last item 1851 } else if (index === -1) { 1852 index = focusableElements.length - 1; 1853 } 1854 focusableElements[index].focus(); 1855 return; 1856 } 1857 // no visible focusable elements, focus the popup 1858 (_dom$getPopup = getPopup()) === null || _dom$getPopup === void 0 || _dom$getPopup.focus(); 1859 }; 1860 const arrowKeysNextButton = ['ArrowRight', 'ArrowDown']; 1861 const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp']; 1862 1863 /** 1864 * @param {SweetAlertOptions} innerParams 1865 * @param {KeyboardEvent} event 1866 * @param {Function} dismissWith 1867 */ 1868 const keydownHandler = (innerParams, event, dismissWith) => { 1869 if (!innerParams) { 1870 return; // This instance has already been destroyed 1871 } 1872 1873 // Ignore keydown during IME composition 1874 // https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition 1875 // https://github.com/sweetalert2/sweetalert2/issues/720 1876 // https://github.com/sweetalert2/sweetalert2/issues/2406 1877 if (event.isComposing || event.keyCode === 229) { 1878 return; 1879 } 1880 if (innerParams.stopKeydownPropagation) { 1881 event.stopPropagation(); 1882 } 1883 1884 // ENTER 1885 if (event.key === 'Enter') { 1886 handleEnter(event, innerParams); 1887 } 1888 1889 // TAB 1890 else if (event.key === 'Tab') { 1891 handleTab(event); 1892 } 1893 1894 // ARROWS - switch focus between buttons 1895 else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(event.key)) { 1896 handleArrows(event.key); 1897 } 1898 1899 // ESC 1900 else if (event.key === 'Escape') { 1901 handleEsc(event, innerParams, dismissWith); 1902 } 1903 }; 1904 1905 /** 1906 * @param {KeyboardEvent} event 1907 * @param {SweetAlertOptions} innerParams 1908 */ 1909 const handleEnter = (event, innerParams) => { 1910 // https://github.com/sweetalert2/sweetalert2/issues/2386 1911 if (!callIfFunction(innerParams.allowEnterKey)) { 1912 return; 1913 } 1914 const input = getInput$1(getPopup(), innerParams.input); 1915 if (event.target && input && event.target instanceof HTMLElement && event.target.outerHTML === input.outerHTML) { 1916 if (['textarea', 'file'].includes(innerParams.input)) { 1917 return; // do not submit 1918 } 1919 1920 clickConfirm(); 1921 event.preventDefault(); 1922 } 1923 }; 1924 1925 /** 1926 * @param {KeyboardEvent} event 1927 */ 1928 const handleTab = event => { 1929 const targetElement = event.target; 1930 const focusableElements = getFocusableElements(); 1931 let btnIndex = -1; 1932 for (let i = 0; i < focusableElements.length; i++) { 1933 if (targetElement === focusableElements[i]) { 1934 btnIndex = i; 1935 break; 1936 } 1937 } 1938 1939 // Cycle to the next button 1940 if (!event.shiftKey) { 1941 setFocus(btnIndex, 1); 1942 } 1943 1944 // Cycle to the prev button 1945 else { 1946 setFocus(btnIndex, -1); 1947 } 1948 event.stopPropagation(); 1949 event.preventDefault(); 1950 }; 1951 1952 /** 1953 * @param {string} key 1954 */ 1955 const handleArrows = key => { 1956 const actions = getActions(); 1957 const confirmButton = getConfirmButton(); 1958 const denyButton = getDenyButton(); 1959 const cancelButton = getCancelButton(); 1960 if (!actions || !confirmButton || !denyButton || !cancelButton) { 1961 return; 1962 } 1963 /** @type HTMLElement[] */ 1964 const buttons = [confirmButton, denyButton, cancelButton]; 1965 if (document.activeElement instanceof HTMLElement && !buttons.includes(document.activeElement)) { 1966 return; 1967 } 1968 const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling'; 1969 let buttonToFocus = document.activeElement; 1970 if (!buttonToFocus) { 1971 return; 1972 } 1973 for (let i = 0; i < actions.children.length; i++) { 1974 buttonToFocus = buttonToFocus[sibling]; 1975 if (!buttonToFocus) { 1976 return; 1977 } 1978 if (buttonToFocus instanceof HTMLButtonElement && isVisible$1(buttonToFocus)) { 1979 break; 1980 } 1981 } 1982 if (buttonToFocus instanceof HTMLButtonElement) { 1983 buttonToFocus.focus(); 1984 } 1985 }; 1986 1987 /** 1988 * @param {KeyboardEvent} event 1989 * @param {SweetAlertOptions} innerParams 1990 * @param {Function} dismissWith 1991 */ 1992 const handleEsc = (event, innerParams, dismissWith) => { 1993 if (callIfFunction(innerParams.allowEscapeKey)) { 1994 event.preventDefault(); 1995 dismissWith(DismissReason.esc); 1996 } 1997 }; 1998 1999 /** 2000 * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has. 2001 * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')` 2002 * This is the approach that Babel will probably take to implement private methods/fields 2003 * https://github.com/tc39/proposal-private-methods 2004 * https://github.com/babel/babel/pull/7555 2005 * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module* 2006 * then we can use that language feature. 2007 */ 2008 2009 var privateMethods = { 2010 swalPromiseResolve: new WeakMap(), 2011 swalPromiseReject: new WeakMap() 2012 }; 2013 2014 // From https://developer.paciellogroup.com/blog/2018/06/the-current-state-of-modal-dialog-accessibility/ 2015 // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that 2016 // elements not within the active modal dialog will not be surfaced if a user opens a screen 2017 // reader’s list of elements (headings, form controls, landmarks, etc.) in the document. 2018 2019 const setAriaHidden = () => { 2020 const bodyChildren = Array.from(document.body.children); 2021 bodyChildren.forEach(el => { 2022 if (el === getContainer() || el.contains(getContainer())) { 2023 return; 2024 } 2025 if (el.hasAttribute('aria-hidden')) { 2026 el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden') || ''); 2027 } 2028 el.setAttribute('aria-hidden', 'true'); 2029 }); 2030 }; 2031 const unsetAriaHidden = () => { 2032 const bodyChildren = Array.from(document.body.children); 2033 bodyChildren.forEach(el => { 2034 if (el.hasAttribute('data-previous-aria-hidden')) { 2035 el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden') || ''); 2036 el.removeAttribute('data-previous-aria-hidden'); 2037 } else { 2038 el.removeAttribute('aria-hidden'); 2039 } 2040 }); 2041 }; 2042 2043 // @ts-ignore 2044 const isSafariOrIOS = typeof window !== 'undefined' && !!window.GestureEvent; // true for Safari desktop + all iOS browsers https://stackoverflow.com/a/70585394 2045 2046 /** 2047 * Fix iOS scrolling 2048 * http://stackoverflow.com/q/39626302 2049 */ 2050 const iOSfix = () => { 2051 if (isSafariOrIOS && !hasClass(document.body, swalClasses.iosfix)) { 2052 const offset = document.body.scrollTop; 2053 document.body.style.top = "".concat(offset * -1, "px"); 2054 addClass(document.body, swalClasses.iosfix); 2055 lockBodyScroll(); 2056 } 2057 }; 2058 2059 /** 2060 * https://github.com/sweetalert2/sweetalert2/issues/1246 2061 */ 2062 const lockBodyScroll = () => { 2063 const container = getContainer(); 2064 if (!container) { 2065 return; 2066 } 2067 /** @type {boolean} */ 2068 let preventTouchMove; 2069 /** 2070 * @param {TouchEvent} event 2071 */ 2072 container.ontouchstart = event => { 2073 preventTouchMove = shouldPreventTouchMove(event); 2074 }; 2075 /** 2076 * @param {TouchEvent} event 2077 */ 2078 container.ontouchmove = event => { 2079 if (preventTouchMove) { 2080 event.preventDefault(); 2081 event.stopPropagation(); 2082 } 2083 }; 2084 }; 2085 2086 /** 2087 * @param {TouchEvent} event 2088 * @returns {boolean} 2089 */ 2090 const shouldPreventTouchMove = event => { 2091 const target = event.target; 2092 const container = getContainer(); 2093 const htmlContainer = getHtmlContainer(); 2094 if (!container || !htmlContainer) { 2095 return false; 2096 } 2097 if (isStylus(event) || isZoom(event)) { 2098 return false; 2099 } 2100 if (target === container) { 2101 return true; 2102 } 2103 if (!isScrollable(container) && target instanceof HTMLElement && target.tagName !== 'INPUT' && 2104 // #1603 2105 target.tagName !== 'TEXTAREA' && 2106 // #2266 2107 !(isScrollable(htmlContainer) && 2108 // #1944 2109 htmlContainer.contains(target))) { 2110 return true; 2111 } 2112 return false; 2113 }; 2114 2115 /** 2116 * https://github.com/sweetalert2/sweetalert2/issues/1786 2117 * 2118 * @param {*} event 2119 * @returns {boolean} 2120 */ 2121 const isStylus = event => { 2122 return event.touches && event.touches.length && event.touches[0].touchType === 'stylus'; 2123 }; 2124 2125 /** 2126 * https://github.com/sweetalert2/sweetalert2/issues/1891 2127 * 2128 * @param {TouchEvent} event 2129 * @returns {boolean} 2130 */ 2131 const isZoom = event => { 2132 return event.touches && event.touches.length > 1; 2133 }; 2134 const undoIOSfix = () => { 2135 if (hasClass(document.body, swalClasses.iosfix)) { 2136 const offset = parseInt(document.body.style.top, 10); 2137 removeClass(document.body, swalClasses.iosfix); 2138 document.body.style.top = ''; 2139 document.body.scrollTop = offset * -1; 2140 } 2141 }; 2142 2143 /** 2144 * Measure scrollbar width for padding body during modal show/hide
vendor: 12,046 bytes, lines 2145-2520
2145 * https://github.com/twbs/bootstrap/blob/master/js/src/modal.js 2146 * 2147 * @returns {number} 2148 */ 2149 const measureScrollbar = () => { 2150 const scrollDiv = document.createElement('div'); 2151 scrollDiv.className = swalClasses['scrollbar-measure']; 2152 document.body.appendChild(scrollDiv); 2153 const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth; 2154 document.body.removeChild(scrollDiv); 2155 return scrollbarWidth; 2156 }; 2157 2158 /** 2159 * Remember state in cases where opening and handling a modal will fiddle with it. 2160 * @type {number | null} 2161 */ 2162 let previousBodyPadding = null; 2163 2164 /** 2165 * @param {string} initialBodyOverflow 2166 */ 2167 const replaceScrollbarWithPadding = initialBodyOverflow => { 2168 // for queues, do not do this more than once 2169 if (previousBodyPadding !== null) { 2170 return; 2171 } 2172 // if the body has overflow 2173 if (document.body.scrollHeight > window.innerHeight || initialBodyOverflow === 'scroll' // https://github.com/sweetalert2/sweetalert2/issues/2663 2174 ) { 2175 // add padding so the content doesn't shift after removal of scrollbar 2176 previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right')); 2177 document.body.style.paddingRight = "".concat(previousBodyPadding + measureScrollbar(), "px"); 2178 } 2179 }; 2180 const undoReplaceScrollbarWithPadding = () => { 2181 if (previousBodyPadding !== null) { 2182 document.body.style.paddingRight = "".concat(previousBodyPadding, "px"); 2183 previousBodyPadding = null; 2184 } 2185 }; 2186 2187 /** 2188 * @param {SweetAlert} instance 2189 * @param {HTMLElement} container 2190 * @param {boolean} returnFocus 2191 * @param {Function} didClose 2192 */ 2193 function removePopupAndResetState(instance, container, returnFocus, didClose) { 2194 if (isToast()) { 2195 triggerDidCloseAndDispose(instance, didClose); 2196 } else { 2197 restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose)); 2198 removeKeydownHandler(globalState); 2199 } 2200 2201 // workaround for https://github.com/sweetalert2/sweetalert2/issues/2088 2202 // for some reason removing the container in Safari will scroll the document to bottom 2203 if (isSafariOrIOS) { 2204 container.setAttribute('style', 'display:none !important'); 2205 container.removeAttribute('class'); 2206 container.innerHTML = ''; 2207 } else { 2208 container.remove(); 2209 } 2210 if (isModal()) { 2211 undoReplaceScrollbarWithPadding(); 2212 undoIOSfix(); 2213 unsetAriaHidden(); 2214 } 2215 removeBodyClasses(); 2216 } 2217 2218 /** 2219 * Remove SweetAlert2 classes from body 2220 */ 2221 function removeBodyClasses() { 2222 removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]); 2223 } 2224 2225 /** 2226 * Instance method to close sweetAlert 2227 * 2228 * @param {any} resolveValue 2229 */ 2230 function close(resolveValue) { 2231 resolveValue = prepareResolveValue(resolveValue); 2232 const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this); 2233 const didClose = triggerClosePopup(this); 2234 if (this.isAwaitingPromise) { 2235 // A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335 2236 if (!resolveValue.isDismissed) { 2237 handleAwaitingPromise(this); 2238 swalPromiseResolve(resolveValue); 2239 } 2240 } else if (didClose) { 2241 // Resolve Swal promise 2242 swalPromiseResolve(resolveValue); 2243 } 2244 } 2245 const triggerClosePopup = instance => { 2246 const popup = getPopup(); 2247 if (!popup) { 2248 return false; 2249 } 2250 const innerParams = privateProps.innerParams.get(instance); 2251 if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) { 2252 return false; 2253 } 2254 removeClass(popup, innerParams.showClass.popup); 2255 addClass(popup, innerParams.hideClass.popup); 2256 const backdrop = getContainer(); 2257 removeClass(backdrop, innerParams.showClass.backdrop); 2258 addClass(backdrop, innerParams.hideClass.backdrop); 2259 handlePopupAnimation(instance, popup, innerParams); 2260 return true; 2261 }; 2262 2263 /** 2264 * @param {any} error 2265 */ 2266 function rejectPromise(error) { 2267 const rejectPromise = privateMethods.swalPromiseReject.get(this); 2268 handleAwaitingPromise(this); 2269 if (rejectPromise) { 2270 // Reject Swal promise 2271 rejectPromise(error); 2272 } 2273 } 2274 2275 /** 2276 * @param {SweetAlert} instance 2277 */ 2278 const handleAwaitingPromise = instance => { 2279 if (instance.isAwaitingPromise) { 2280 delete instance.isAwaitingPromise; 2281 // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335 2282 if (!privateProps.innerParams.get(instance)) { 2283 instance._destroy(); 2284 } 2285 } 2286 }; 2287 2288 /** 2289 * @param {any} resolveValue 2290 * @returns {SweetAlertResult} 2291 */ 2292 const prepareResolveValue = resolveValue => { 2293 // When user calls Swal.close() 2294 if (typeof resolveValue === 'undefined') { 2295 return { 2296 isConfirmed: false, 2297 isDenied: false, 2298 isDismissed: true 2299 }; 2300 } 2301 return Object.assign({ 2302 isConfirmed: false, 2303 isDenied: false, 2304 isDismissed: false 2305 }, resolveValue); 2306 }; 2307 2308 /** 2309 * @param {SweetAlert} instance 2310 * @param {HTMLElement} popup 2311 * @param {SweetAlertOptions} innerParams 2312 */ 2313 const handlePopupAnimation = (instance, popup, innerParams) => { 2314 const container = getContainer(); 2315 // If animation is supported, animate 2316 const animationIsSupported = animationEndEvent && hasCssAnimation(popup); 2317 if (typeof innerParams.willClose === 'function') { 2318 innerParams.willClose(popup); 2319 } 2320 if (animationIsSupported) { 2321 animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose); 2322 } else { 2323 // Otherwise, remove immediately 2324 removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose); 2325 } 2326 }; 2327 2328 /** 2329 * @param {SweetAlert} instance 2330 * @param {HTMLElement} popup 2331 * @param {HTMLElement} container 2332 * @param {boolean} returnFocus 2333 * @param {Function} didClose 2334 */ 2335 const animatePopup = (instance, popup, container, returnFocus, didClose) => { 2336 if (!animationEndEvent) { 2337 return; 2338 } 2339 globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose); 2340 popup.addEventListener(animationEndEvent, function (e) { 2341 if (e.target === popup) { 2342 globalState.swalCloseEventFinishedCallback(); 2343 delete globalState.swalCloseEventFinishedCallback; 2344 } 2345 }); 2346 }; 2347 2348 /** 2349 * @param {SweetAlert} instance 2350 * @param {Function} didClose 2351 */ 2352 const triggerDidCloseAndDispose = (instance, didClose) => { 2353 setTimeout(() => { 2354 if (typeof didClose === 'function') { 2355 didClose.bind(instance.params)(); 2356 } 2357 // instance might have been destroyed already 2358 if (instance._destroy) { 2359 instance._destroy(); 2360 } 2361 }); 2362 }; 2363 2364 /** 2365 * Shows loader (spinner), this is useful with AJAX requests. 2366 * By default the loader be shown instead of the "Confirm" button. 2367 * 2368 * @param {HTMLButtonElement | null} [buttonToReplace] 2369 */ 2370 const showLoading = buttonToReplace => { 2371 let popup = getPopup(); 2372 if (!popup) { 2373 new Swal(); // eslint-disable-line no-new 2374 } 2375 2376 popup = getPopup(); 2377 if (!popup) { 2378 return; 2379 } 2380 const loader = getLoader(); 2381 if (isToast()) { 2382 hide(getIcon()); 2383 } else { 2384 replaceButton(popup, buttonToReplace); 2385 } 2386 show(loader); 2387 popup.setAttribute('data-loading', 'true'); 2388 popup.setAttribute('aria-busy', 'true'); 2389 popup.focus(); 2390 }; 2391 2392 /** 2393 * @param {HTMLElement} popup 2394 * @param {HTMLButtonElement | null} [buttonToReplace] 2395 */ 2396 const replaceButton = (popup, buttonToReplace) => { 2397 const actions = getActions(); 2398 const loader = getLoader(); 2399 if (!actions || !loader) { 2400 return; 2401 } 2402 if (!buttonToReplace && isVisible$1(getConfirmButton())) { 2403 buttonToReplace = getConfirmButton(); 2404 } 2405 show(actions); 2406 if (buttonToReplace) { 2407 hide(buttonToReplace); 2408 loader.setAttribute('data-button-to-replace', buttonToReplace.className); 2409 actions.insertBefore(loader, buttonToReplace); 2410 } 2411 addClass([popup, actions], swalClasses.loading); 2412 }; 2413 2414 /** 2415 * @param {SweetAlert} instance 2416 * @param {SweetAlertOptions} params 2417 */ 2418 const handleInputOptionsAndValue = (instance, params) => { 2419 if (params.input === 'select' || params.input === 'radio') { 2420 handleInputOptions(instance, params); 2421 } else if (['text', 'email', 'number', 'tel', 'textarea'].some(i => i === params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) { 2422 showLoading(getConfirmButton()); 2423 handleInputValue(instance, params); 2424 } 2425 }; 2426 2427 /** 2428 * @param {SweetAlert} instance 2429 * @param {SweetAlertOptions} innerParams 2430 * @returns {SweetAlertInputValue} 2431 */ 2432 const getInputValue = (instance, innerParams) => { 2433 const input = instance.getInput(); 2434 if (!input) { 2435 return null; 2436 } 2437 switch (innerParams.input) { 2438 case 'checkbox': 2439 return getCheckboxValue(input); 2440 case 'radio': 2441 return getRadioValue(input); 2442 case 'file': 2443 return getFileValue(input); 2444 default: 2445 return innerParams.inputAutoTrim ? input.value.trim() : input.value; 2446 } 2447 }; 2448 2449 /** 2450 * @param {HTMLInputElement} input 2451 * @returns {number} 2452 */ 2453 const getCheckboxValue = input => input.checked ? 1 : 0; 2454 2455 /** 2456 * @param {HTMLInputElement} input 2457 * @returns {string | null} 2458 */ 2459 const getRadioValue = input => input.checked ? input.value : null; 2460 2461 /** 2462 * @param {HTMLInputElement} input 2463 * @returns {FileList | File | null} 2464 */ 2465 const getFileValue = input => input.files && input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null; 2466 2467 /** 2468 * @param {SweetAlert} instance 2469 * @param {SweetAlertOptions} params 2470 */ 2471 const handleInputOptions = (instance, params) => { 2472 const popup = getPopup(); 2473 if (!popup) { 2474 return; 2475 } 2476 /** 2477 * @param {Record<string, any>} inputOptions 2478 */ 2479 const processInputOptions = inputOptions => { 2480 if (params.input === 'select') { 2481 populateSelectOptions(popup, formatInputOptions(inputOptions), params); 2482 } else if (params.input === 'radio') { 2483 populateRadioOptions(popup, formatInputOptions(inputOptions), params); 2484 } 2485 }; 2486 if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) { 2487 showLoading(getConfirmButton()); 2488 asPromise(params.inputOptions).then(inputOptions => { 2489 instance.hideLoading(); 2490 processInputOptions(inputOptions); 2491 }); 2492 } else if (typeof params.inputOptions === 'object') { 2493 processInputOptions(params.inputOptions); 2494 } else { 2495 error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(typeof params.inputOptions)); 2496 } 2497 }; 2498 2499 /** 2500 * @param {SweetAlert} instance 2501 * @param {SweetAlertOptions} params 2502 */ 2503 const handleInputValue = (instance, params) => { 2504 const input = instance.getInput(); 2505 if (!input) { 2506 return; 2507 } 2508 hide(input); 2509 asPromise(params.inputValue).then(inputValue => { 2510 input.value = params.input === 'number' ? "".concat(parseFloat(inputValue) || 0) : "".concat(inputValue); 2511 show(input); 2512 input.focus(); 2513 instance.hideLoading(); 2514 }).catch(err => { 2515 error("Error in inputValue promise: ".concat(err)); 2516 input.value = ''; 2517 show(input); 2518 input.focus(); 2519 instance.hideLoading(); 2520 });
vendor: 52,856 bytes, lines 2521-4155
2521 }; 2522 2523 /** 2524 * @param {HTMLElement} popup 2525 * @param {InputOptionFlattened[]} inputOptions 2526 * @param {SweetAlertOptions} params 2527 */ 2528 function populateSelectOptions(popup, inputOptions, params) { 2529 const select = getDirectChildByClass(popup, swalClasses.select); 2530 if (!select) { 2531 return; 2532 } 2533 /** 2534 * @param {HTMLElement} parent 2535 * @param {string} optionLabel 2536 * @param {string} optionValue 2537 */ 2538 const renderOption = (parent, optionLabel, optionValue) => { 2539 const option = document.createElement('option'); 2540 option.value = optionValue; 2541 setInnerHtml(option, optionLabel); 2542 option.selected = isSelected(optionValue, params.inputValue); 2543 parent.appendChild(option); 2544 }; 2545 inputOptions.forEach(inputOption => { 2546 const optionValue = inputOption[0]; 2547 const optionLabel = inputOption[1]; 2548 // <optgroup> spec: 2549 // https://www.w3.org/TR/html401/interact/forms.html#h-17.6 2550 // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..." 2551 // check whether this is a <optgroup> 2552 if (Array.isArray(optionLabel)) { 2553 // if it is an array, then it is an <optgroup> 2554 const optgroup = document.createElement('optgroup'); 2555 optgroup.label = optionValue; 2556 optgroup.disabled = false; // not configurable for now 2557 select.appendChild(optgroup); 2558 optionLabel.forEach(o => renderOption(optgroup, o[1], o[0])); 2559 } else { 2560 // case of <option> 2561 renderOption(select, optionLabel, optionValue); 2562 } 2563 }); 2564 select.focus(); 2565 } 2566 2567 /** 2568 * @param {HTMLElement} popup 2569 * @param {InputOptionFlattened[]} inputOptions 2570 * @param {SweetAlertOptions} params 2571 */ 2572 function populateRadioOptions(popup, inputOptions, params) { 2573 const radio = getDirectChildByClass(popup, swalClasses.radio); 2574 if (!radio) { 2575 return; 2576 } 2577 inputOptions.forEach(inputOption => { 2578 const radioValue = inputOption[0]; 2579 const radioLabel = inputOption[1]; 2580 const radioInput = document.createElement('input'); 2581 const radioLabelElement = document.createElement('label'); 2582 radioInput.type = 'radio'; 2583 radioInput.name = swalClasses.radio; 2584 radioInput.value = radioValue; 2585 if (isSelected(radioValue, params.inputValue)) { 2586 radioInput.checked = true; 2587 } 2588 const label = document.createElement('span'); 2589 setInnerHtml(label, radioLabel); 2590 label.className = swalClasses.label; 2591 radioLabelElement.appendChild(radioInput); 2592 radioLabelElement.appendChild(label); 2593 radio.appendChild(radioLabelElement); 2594 }); 2595 const radios = radio.querySelectorAll('input'); 2596 if (radios.length) { 2597 radios[0].focus(); 2598 } 2599 } 2600 2601 /** 2602 * Converts `inputOptions` into an array of `[value, label]`s 2603 * 2604 * @param {Record<string, any>} inputOptions 2605 * @typedef {string[]} InputOptionFlattened 2606 * @returns {InputOptionFlattened[]} 2607 */ 2608 const formatInputOptions = inputOptions => { 2609 /** @type {InputOptionFlattened[]} */ 2610 const result = []; 2611 if (inputOptions instanceof Map) { 2612 inputOptions.forEach((value, key) => { 2613 let valueFormatted = value; 2614 if (typeof valueFormatted === 'object') { 2615 // case of <optgroup> 2616 valueFormatted = formatInputOptions(valueFormatted); 2617 } 2618 result.push([key, valueFormatted]); 2619 }); 2620 } else { 2621 Object.keys(inputOptions).forEach(key => { 2622 let valueFormatted = inputOptions[key]; 2623 if (typeof valueFormatted === 'object') { 2624 // case of <optgroup> 2625 valueFormatted = formatInputOptions(valueFormatted); 2626 } 2627 result.push([key, valueFormatted]); 2628 }); 2629 } 2630 return result; 2631 }; 2632 2633 /** 2634 * @param {string} optionValue 2635 * @param {SweetAlertInputValue} inputValue 2636 * @returns {boolean} 2637 */ 2638 const isSelected = (optionValue, inputValue) => { 2639 return !!inputValue && inputValue.toString() === optionValue.toString(); 2640 }; 2641 2642 /** 2643 * @param {SweetAlert} instance 2644 */ 2645 const handleConfirmButtonClick = instance => { 2646 const innerParams = privateProps.innerParams.get(instance); 2647 instance.disableButtons(); 2648 if (innerParams.input) { 2649 handleConfirmOrDenyWithInput(instance, 'confirm'); 2650 } else { 2651 confirm(instance, true); 2652 } 2653 }; 2654 2655 /** 2656 * @param {SweetAlert} instance 2657 */ 2658 const handleDenyButtonClick = instance => { 2659 const innerParams = privateProps.innerParams.get(instance); 2660 instance.disableButtons(); 2661 if (innerParams.returnInputValueOnDeny) { 2662 handleConfirmOrDenyWithInput(instance, 'deny'); 2663 } else { 2664 deny(instance, false); 2665 } 2666 }; 2667 2668 /** 2669 * @param {SweetAlert} instance 2670 * @param {Function} dismissWith 2671 */ 2672 const handleCancelButtonClick = (instance, dismissWith) => { 2673 instance.disableButtons(); 2674 dismissWith(DismissReason.cancel); 2675 }; 2676 2677 /** 2678 * @param {SweetAlert} instance 2679 * @param {'confirm' | 'deny'} type 2680 */ 2681 const handleConfirmOrDenyWithInput = (instance, type) => { 2682 const innerParams = privateProps.innerParams.get(instance); 2683 if (!innerParams.input) { 2684 error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type))); 2685 return; 2686 } 2687 const input = instance.getInput(); 2688 const inputValue = getInputValue(instance, innerParams); 2689 if (innerParams.inputValidator) { 2690 handleInputValidator(instance, inputValue, type); 2691 } else if (input && !input.checkValidity()) { 2692 instance.enableButtons(); 2693 instance.showValidationMessage(innerParams.validationMessage); 2694 } else if (type === 'deny') { 2695 deny(instance, inputValue); 2696 } else { 2697 confirm(instance, inputValue); 2698 } 2699 }; 2700 2701 /** 2702 * @param {SweetAlert} instance 2703 * @param {SweetAlertInputValue} inputValue 2704 * @param {'confirm' | 'deny'} type 2705 */ 2706 const handleInputValidator = (instance, inputValue, type) => { 2707 const innerParams = privateProps.innerParams.get(instance); 2708 instance.disableInput(); 2709 const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage))); 2710 validationPromise.then(validationMessage => { 2711 instance.enableButtons(); 2712 instance.enableInput(); 2713 if (validationMessage) { 2714 instance.showValidationMessage(validationMessage); 2715 } else if (type === 'deny') { 2716 deny(instance, inputValue); 2717 } else { 2718 confirm(instance, inputValue); 2719 } 2720 }); 2721 }; 2722 2723 /** 2724 * @param {SweetAlert} instance 2725 * @param {any} value 2726 */ 2727 const deny = (instance, value) => { 2728 const innerParams = privateProps.innerParams.get(instance || undefined); 2729 if (innerParams.showLoaderOnDeny) { 2730 showLoading(getDenyButton()); 2731 } 2732 if (innerParams.preDeny) { 2733 instance.isAwaitingPromise = 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 2734 const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage))); 2735 preDenyPromise.then(preDenyValue => { 2736 if (preDenyValue === false) { 2737 instance.hideLoading(); 2738 handleAwaitingPromise(instance); 2739 } else { 2740 instance.close({ 2741 isDenied: true, 2742 value: typeof preDenyValue === 'undefined' ? value : preDenyValue 2743 }); 2744 } 2745 }).catch(error => rejectWith(instance || undefined, error)); 2746 } else { 2747 instance.close({ 2748 isDenied: true, 2749 value 2750 }); 2751 } 2752 }; 2753 2754 /** 2755 * @param {SweetAlert} instance 2756 * @param {any} value 2757 */ 2758 const succeedWith = (instance, value) => { 2759 instance.close({ 2760 isConfirmed: true, 2761 value 2762 }); 2763 }; 2764 2765 /** 2766 * 2767 * @param {SweetAlert} instance 2768 * @param {string} error 2769 */ 2770 const rejectWith = (instance, error) => { 2771 instance.rejectPromise(error); 2772 }; 2773 2774 /** 2775 * 2776 * @param {SweetAlert} instance 2777 * @param {any} value 2778 */ 2779 const confirm = (instance, value) => { 2780 const innerParams = privateProps.innerParams.get(instance || undefined); 2781 if (innerParams.showLoaderOnConfirm) { 2782 showLoading(); 2783 } 2784 if (innerParams.preConfirm) { 2785 instance.resetValidationMessage(); 2786 instance.isAwaitingPromise = 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 2787 const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage))); 2788 preConfirmPromise.then(preConfirmValue => { 2789 if (isVisible$1(getValidationMessage()) || preConfirmValue === false) { 2790 instance.hideLoading(); 2791 handleAwaitingPromise(instance); 2792 } else { 2793 succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue); 2794 } 2795 }).catch(error => rejectWith(instance || undefined, error)); 2796 } else { 2797 succeedWith(instance, value); 2798 } 2799 }; 2800 2801 /** 2802 * Hides loader and shows back the button which was hidden by .showLoading() 2803 */ 2804 function hideLoading() { 2805 // do nothing if popup is closed 2806 const innerParams = privateProps.innerParams.get(this); 2807 if (!innerParams) { 2808 return; 2809 } 2810 const domCache = privateProps.domCache.get(this); 2811 hide(domCache.loader); 2812 if (isToast()) { 2813 if (innerParams.icon) { 2814 show(getIcon()); 2815 } 2816 } else { 2817 showRelatedButton(domCache); 2818 } 2819 removeClass([domCache.popup, domCache.actions], swalClasses.loading); 2820 domCache.popup.removeAttribute('aria-busy'); 2821 domCache.popup.removeAttribute('data-loading'); 2822 domCache.confirmButton.disabled = false; 2823 domCache.denyButton.disabled = false; 2824 domCache.cancelButton.disabled = false; 2825 } 2826 const showRelatedButton = domCache => { 2827 const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace')); 2828 if (buttonToReplace.length) { 2829 show(buttonToReplace[0], 'inline-block'); 2830 } else if (allButtonsAreHidden()) { 2831 hide(domCache.actions); 2832 } 2833 }; 2834 2835 /** 2836 * Gets the input DOM node, this method works with input parameter. 2837 * 2838 * @returns {HTMLInputElement | null} 2839 */ 2840 function getInput() { 2841 const innerParams = privateProps.innerParams.get(this); 2842 const domCache = privateProps.domCache.get(this); 2843 if (!domCache) { 2844 return null; 2845 } 2846 return getInput$1(domCache.popup, innerParams.input); 2847 } 2848 2849 /** 2850 * @param {SweetAlert} instance 2851 * @param {string[]} buttons 2852 * @param {boolean} disabled 2853 */ 2854 function setButtonsDisabled(instance, buttons, disabled) { 2855 const domCache = privateProps.domCache.get(instance); 2856 buttons.forEach(button => { 2857 domCache[button].disabled = disabled; 2858 }); 2859 } 2860 2861 /** 2862 * @param {HTMLInputElement | null} input 2863 * @param {boolean} disabled 2864 */ 2865 function setInputDisabled(input, disabled) { 2866 const popup = getPopup(); 2867 if (!popup || !input) { 2868 return; 2869 } 2870 if (input.type === 'radio') { 2871 /** @type {NodeListOf<HTMLInputElement>} */ 2872 const radios = popup.querySelectorAll("[name=\"".concat(swalClasses.radio, "\"]")); 2873 for (let i = 0; i < radios.length; i++) { 2874 radios[i].disabled = disabled; 2875 } 2876 } else { 2877 input.disabled = disabled; 2878 } 2879 } 2880 2881 /** 2882 * Enable all the buttons 2883 * @this {SweetAlert} 2884 */ 2885 function enableButtons() { 2886 setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false); 2887 } 2888 2889 /** 2890 * Disable all the buttons 2891 * @this {SweetAlert} 2892 */ 2893 function disableButtons() { 2894 setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true); 2895 } 2896 2897 /** 2898 * Enable the input field 2899 * @this {SweetAlert} 2900 */ 2901 function enableInput() { 2902 setInputDisabled(this.getInput(), false); 2903 } 2904 2905 /** 2906 * Disable the input field 2907 * @this {SweetAlert} 2908 */ 2909 function disableInput() { 2910 setInputDisabled(this.getInput(), true); 2911 } 2912 2913 /** 2914 * Show block with validation message 2915 * 2916 * @param {string} error 2917 * @this {SweetAlert} 2918 */ 2919 function showValidationMessage(error) { 2920 const domCache = privateProps.domCache.get(this); 2921 const params = privateProps.innerParams.get(this); 2922 setInnerHtml(domCache.validationMessage, error); 2923 domCache.validationMessage.className = swalClasses['validation-message']; 2924 if (params.customClass && params.customClass.validationMessage) { 2925 addClass(domCache.validationMessage, params.customClass.validationMessage); 2926 } 2927 show(domCache.validationMessage); 2928 const input = this.getInput(); 2929 if (input) { 2930 input.setAttribute('aria-invalid', 'true'); 2931 input.setAttribute('aria-describedby', swalClasses['validation-message']); 2932 focusInput(input); 2933 addClass(input, swalClasses.inputerror); 2934 } 2935 } 2936 2937 /** 2938 * Hide block with validation message 2939 * 2940 * @this {SweetAlert} 2941 */ 2942 function resetValidationMessage() { 2943 const domCache = privateProps.domCache.get(this); 2944 if (domCache.validationMessage) { 2945 hide(domCache.validationMessage); 2946 } 2947 const input = this.getInput(); 2948 if (input) { 2949 input.removeAttribute('aria-invalid'); 2950 input.removeAttribute('aria-describedby'); 2951 removeClass(input, swalClasses.inputerror); 2952 } 2953 } 2954 2955 const defaultParams = { 2956 title: '', 2957 titleText: '', 2958 text: '', 2959 html: '', 2960 footer: '', 2961 icon: undefined, 2962 iconColor: undefined, 2963 iconHtml: undefined, 2964 template: undefined, 2965 toast: false, 2966 showClass: { 2967 popup: 'swal2-show', 2968 backdrop: 'swal2-backdrop-show', 2969 icon: 'swal2-icon-show' 2970 }, 2971 hideClass: { 2972 popup: 'swal2-hide', 2973 backdrop: 'swal2-backdrop-hide', 2974 icon: 'swal2-icon-hide' 2975 }, 2976 customClass: {}, 2977 target: 'body', 2978 color: undefined, 2979 backdrop: true, 2980 heightAuto: true, 2981 allowOutsideClick: true, 2982 allowEscapeKey: true, 2983 allowEnterKey: true, 2984 stopKeydownPropagation: true, 2985 keydownListenerCapture: false, 2986 showConfirmButton: true, 2987 showDenyButton: false, 2988 showCancelButton: false, 2989 preConfirm: undefined, 2990 preDeny: undefined, 2991 confirmButtonText: 'OK', 2992 confirmButtonAriaLabel: '', 2993 confirmButtonColor: undefined, 2994 denyButtonText: 'No', 2995 denyButtonAriaLabel: '', 2996 denyButtonColor: undefined, 2997 cancelButtonText: 'Cancel', 2998 cancelButtonAriaLabel: '', 2999 cancelButtonColor: undefined, 3000 buttonsStyling: true, 3001 reverseButtons: false, 3002 focusConfirm: true, 3003 focusDeny: false, 3004 focusCancel: false, 3005 returnFocus: true, 3006 showCloseButton: false, 3007 closeButtonHtml: '×', 3008 closeButtonAriaLabel: 'Close this dialog', 3009 loaderHtml: '', 3010 showLoaderOnConfirm: false, 3011 showLoaderOnDeny: false, 3012 imageUrl: undefined, 3013 imageWidth: undefined, 3014 imageHeight: undefined, 3015 imageAlt: '', 3016 timer: undefined, 3017 timerProgressBar: false, 3018 width: undefined, 3019 padding: undefined, 3020 background: undefined, 3021 input: undefined, 3022 inputPlaceholder: '', 3023 inputLabel: '', 3024 inputValue: '', 3025 inputOptions: {}, 3026 inputAutoFocus: true, 3027 inputAutoTrim: true, 3028 inputAttributes: {}, 3029 inputValidator: undefined, 3030 returnInputValueOnDeny: false, 3031 validationMessage: undefined, 3032 grow: false, 3033 position: 'center', 3034 progressSteps: [], 3035 currentProgressStep: undefined, 3036 progressStepsDistance: undefined, 3037 willOpen: undefined, 3038 didOpen: undefined, 3039 didRender: undefined, 3040 willClose: undefined, 3041 didClose: undefined, 3042 didDestroy: undefined, 3043 scrollbarPadding: true 3044 }; 3045 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']; 3046 3047 /** @type {Record<string, string>} */ 3048 const deprecatedParams = {}; 3049 const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture']; 3050 3051 /** 3052 * Is valid parameter 3053 * 3054 * @param {string} paramName 3055 * @returns {boolean} 3056 */ 3057 const isValidParameter = paramName => { 3058 return Object.prototype.hasOwnProperty.call(defaultParams, paramName); 3059 }; 3060 3061 /** 3062 * Is valid parameter for Swal.update() method 3063 * 3064 * @param {string} paramName 3065 * @returns {boolean} 3066 */ 3067 const isUpdatableParameter = paramName => { 3068 return updatableParams.indexOf(paramName) !== -1; 3069 }; 3070 3071 /** 3072 * Is deprecated parameter 3073 * 3074 * @param {string} paramName 3075 * @returns {string | undefined} 3076 */ 3077 const isDeprecatedParameter = paramName => { 3078 return deprecatedParams[paramName]; 3079 }; 3080 3081 /** 3082 * @param {string} param 3083 */ 3084 const checkIfParamIsValid = param => { 3085 if (!isValidParameter(param)) { 3086 warn("Unknown parameter \"".concat(param, "\"")); 3087 } 3088 }; 3089 3090 /** 3091 * @param {string} param 3092 */ 3093 const checkIfToastParamIsValid = param => { 3094 if (toastIncompatibleParams.includes(param)) { 3095 warn("The parameter \"".concat(param, "\" is incompatible with toasts")); 3096 } 3097 }; 3098 3099 /** 3100 * @param {string} param 3101 */ 3102 const checkIfParamIsDeprecated = param => { 3103 const isDeprecated = isDeprecatedParameter(param); 3104 if (isDeprecated) { 3105 warnAboutDeprecation(param, isDeprecated); 3106 } 3107 }; 3108 3109 /** 3110 * Show relevant warnings for given params 3111 * 3112 * @param {SweetAlertOptions} params 3113 */ 3114 const showWarningsForParams = params => { 3115 if (params.backdrop === false && params.allowOutsideClick) { 3116 warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`'); 3117 } 3118 for (const param in params) { 3119 checkIfParamIsValid(param); 3120 if (params.toast) { 3121 checkIfToastParamIsValid(param); 3122 } 3123 checkIfParamIsDeprecated(param); 3124 } 3125 }; 3126 3127 /** 3128 * Updates popup parameters. 3129 * 3130 * @param {SweetAlertOptions} params 3131 */ 3132 function update(params) { 3133 const popup = getPopup(); 3134 const innerParams = privateProps.innerParams.get(this); 3135 if (!popup || hasClass(popup, innerParams.hideClass.popup)) { 3136 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."); 3137 return; 3138 } 3139 const validUpdatableParams = filterValidParams(params); 3140 const updatedParams = Object.assign({}, innerParams, validUpdatableParams); 3141 render(this, updatedParams); 3142 privateProps.innerParams.set(this, updatedParams); 3143 Object.defineProperties(this, { 3144 params: { 3145 value: Object.assign({}, this.params, params), 3146 writable: false, 3147 enumerable: true 3148 } 3149 }); 3150 } 3151 3152 /** 3153 * @param {SweetAlertOptions} params 3154 * @returns {SweetAlertOptions} 3155 */ 3156 const filterValidParams = params => { 3157 const validUpdatableParams = {}; 3158 Object.keys(params).forEach(param => { 3159 if (isUpdatableParameter(param)) { 3160 validUpdatableParams[param] = params[param]; 3161 } else { 3162 warn("Invalid parameter to update: ".concat(param)); 3163 } 3164 }); 3165 return validUpdatableParams; 3166 }; 3167 3168 /** 3169 * Dispose the current SweetAlert2 instance 3170 */ 3171 function _destroy() { 3172 const domCache = privateProps.domCache.get(this); 3173 const innerParams = privateProps.innerParams.get(this); 3174 if (!innerParams) { 3175 disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335 3176 return; // This instance has already been destroyed 3177 } 3178 3179 // Check if there is another Swal closing 3180 if (domCache.popup && globalState.swalCloseEventFinishedCallback) { 3181 globalState.swalCloseEventFinishedCallback(); 3182 delete globalState.swalCloseEventFinishedCallback; 3183 } 3184 if (typeof innerParams.didDestroy === 'function') { 3185 innerParams.didDestroy(); 3186 } 3187 disposeSwal(this); 3188 } 3189 3190 /** 3191 * @param {SweetAlert} instance 3192 */ 3193 const disposeSwal = instance => { 3194 disposeWeakMaps(instance); 3195 // Unset this.params so GC will dispose it (#1569) 3196 delete instance.params; 3197 // Unset globalState props so GC will dispose globalState (#1569) 3198 delete globalState.keydownHandler; 3199 delete globalState.keydownTarget; 3200 // Unset currentInstance 3201 delete globalState.currentInstance; 3202 }; 3203 3204 /** 3205 * @param {SweetAlert} instance 3206 */ 3207 const disposeWeakMaps = instance => { 3208 // If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335 3209 if (instance.isAwaitingPromise) { 3210 unsetWeakMaps(privateProps, instance); 3211 instance.isAwaitingPromise = true; 3212 } else { 3213 unsetWeakMaps(privateMethods, instance); 3214 unsetWeakMaps(privateProps, instance); 3215 delete instance.isAwaitingPromise; 3216 // Unset instance methods 3217 delete instance.disableButtons; 3218 delete instance.enableButtons; 3219 delete instance.getInput; 3220 delete instance.disableInput; 3221 delete instance.enableInput; 3222 delete instance.hideLoading; 3223 delete instance.disableLoading; 3224 delete instance.showValidationMessage; 3225 delete instance.resetValidationMessage; 3226 delete instance.close; 3227 delete instance.closePopup; 3228 delete instance.closeModal; 3229 delete instance.closeToast; 3230 delete instance.rejectPromise; 3231 delete instance.update; 3232 delete instance._destroy; 3233 } 3234 }; 3235 3236 /** 3237 * @param {object} obj 3238 * @param {SweetAlert} instance 3239 */ 3240 const unsetWeakMaps = (obj, instance) => { 3241 for (const i in obj) { 3242 obj[i].delete(instance); 3243 } 3244 }; 3245 3246 var instanceMethods = /*#__PURE__*/Object.freeze({ 3247 __proto__: null, 3248 _destroy: _destroy, 3249 close: close, 3250 closeModal: close, 3251 closePopup: close, 3252 closeToast: close, 3253 disableButtons: disableButtons, 3254 disableInput: disableInput, 3255 disableLoading: hideLoading, 3256 enableButtons: enableButtons, 3257 enableInput: enableInput, 3258 getInput: getInput, 3259 handleAwaitingPromise: handleAwaitingPromise, 3260 hideLoading: hideLoading, 3261 rejectPromise: rejectPromise, 3262 resetValidationMessage: resetValidationMessage, 3263 showValidationMessage: showValidationMessage, 3264 update: update 3265 }); 3266 3267 /** 3268 * @param {SweetAlertOptions} innerParams 3269 * @param {DomCache} domCache 3270 * @param {Function} dismissWith 3271 */ 3272 const handlePopupClick = (innerParams, domCache, dismissWith) => { 3273 if (innerParams.toast) { 3274 handleToastClick(innerParams, domCache, dismissWith); 3275 } else { 3276 // Ignore click events that had mousedown on the popup but mouseup on the container 3277 // This can happen when the user drags a slider 3278 handleModalMousedown(domCache); 3279 3280 // Ignore click events that had mousedown on the container but mouseup on the popup 3281 handleContainerMousedown(domCache); 3282 handleModalClick(innerParams, domCache, dismissWith); 3283 } 3284 }; 3285 3286 /** 3287 * @param {SweetAlertOptions} innerParams 3288 * @param {DomCache} domCache 3289 * @param {Function} dismissWith 3290 */ 3291 const handleToastClick = (innerParams, domCache, dismissWith) => { 3292 // Closing toast by internal click 3293 domCache.popup.onclick = () => { 3294 if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) { 3295 return; 3296 } 3297 dismissWith(DismissReason.close); 3298 }; 3299 }; 3300 3301 /** 3302 * @param {SweetAlertOptions} innerParams 3303 * @returns {boolean} 3304 */ 3305 const isAnyButtonShown = innerParams => { 3306 return !!(innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton); 3307 }; 3308 let ignoreOutsideClick = false; 3309 3310 /** 3311 * @param {DomCache} domCache 3312 */ 3313 const handleModalMousedown = domCache => { 3314 domCache.popup.onmousedown = () => { 3315 domCache.container.onmouseup = function (e) { 3316 domCache.container.onmouseup = () => {}; 3317 // We only check if the mouseup target is the container because usually it doesn't 3318 // have any other direct children aside of the popup 3319 if (e.target === domCache.container) { 3320 ignoreOutsideClick = true; 3321 } 3322 }; 3323 }; 3324 }; 3325 3326 /** 3327 * @param {DomCache} domCache 3328 */ 3329 const handleContainerMousedown = domCache => { 3330 domCache.container.onmousedown = () => { 3331 domCache.popup.onmouseup = function (e) { 3332 domCache.popup.onmouseup = () => {}; 3333 // We also need to check if the mouseup target is a child of the popup 3334 if (e.target === domCache.popup || e.target instanceof HTMLElement && domCache.popup.contains(e.target)) { 3335 ignoreOutsideClick = true; 3336 } 3337 }; 3338 }; 3339 }; 3340 3341 /** 3342 * @param {SweetAlertOptions} innerParams 3343 * @param {DomCache} domCache 3344 * @param {Function} dismissWith 3345 */ 3346 const handleModalClick = (innerParams, domCache, dismissWith) => { 3347 domCache.container.onclick = e => { 3348 if (ignoreOutsideClick) { 3349 ignoreOutsideClick = false; 3350 return; 3351 } 3352 if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) { 3353 dismissWith(DismissReason.backdrop); 3354 } 3355 }; 3356 }; 3357 3358 const isJqueryElement = elem => typeof elem === 'object' && elem.jquery; 3359 const isElement = elem => elem instanceof Element || isJqueryElement(elem); 3360 const argsToParams = args => { 3361 const params = {}; 3362 if (typeof args[0] === 'object' && !isElement(args[0])) { 3363 Object.assign(params, args[0]); 3364 } else { 3365 ['title', 'html', 'icon'].forEach((name, index) => { 3366 const arg = args[index]; 3367 if (typeof arg === 'string' || isElement(arg)) { 3368 params[name] = arg; 3369 } else if (arg !== undefined) { 3370 error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg)); 3371 } 3372 }); 3373 } 3374 return params; 3375 }; 3376 3377 /** 3378 * Main method to create a new SweetAlert2 popup 3379 * 3380 * @param {...SweetAlertOptions} args 3381 * @returns {Promise<SweetAlertResult>} 3382 */ 3383 function fire() { 3384 const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias 3385 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 3386 args[_key] = arguments[_key]; 3387 } 3388 return new Swal(...args); 3389 } 3390 3391 /** 3392 * Returns an extended version of `Swal` containing `params` as defaults. 3393 * Useful for reusing Swal configuration. 3394 * 3395 * For example: 3396 * 3397 * Before: 3398 * const textPromptOptions = { input: 'text', showCancelButton: true } 3399 * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' }) 3400 * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' }) 3401 * 3402 * After: 3403 * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true }) 3404 * const {value: firstName} = await TextPrompt('What is your first name?') 3405 * const {value: lastName} = await TextPrompt('What is your last name?') 3406 * 3407 * @param {SweetAlertOptions} mixinParams 3408 * @returns {SweetAlert} 3409 */ 3410 function mixin(mixinParams) { 3411 class MixinSwal extends this { 3412 _main(params, priorityMixinParams) { 3413 return super._main(params, Object.assign({}, mixinParams, priorityMixinParams)); 3414 } 3415 } 3416 // @ts-ignore 3417 return MixinSwal; 3418 } 3419 3420 /** 3421 * If `timer` parameter is set, returns number of milliseconds of timer remained. 3422 * Otherwise, returns undefined. 3423 * 3424 * @returns {number | undefined} 3425 */ 3426 const getTimerLeft = () => { 3427 return globalState.timeout && globalState.timeout.getTimerLeft(); 3428 }; 3429 3430 /** 3431 * Stop timer. Returns number of milliseconds of timer remained. 3432 * If `timer` parameter isn't set, returns undefined. 3433 * 3434 * @returns {number | undefined} 3435 */ 3436 const stopTimer = () => { 3437 if (globalState.timeout) { 3438 stopTimerProgressBar(); 3439 return globalState.timeout.stop(); 3440 } 3441 }; 3442 3443 /** 3444 * Resume timer. Returns number of milliseconds of timer remained. 3445 * If `timer` parameter isn't set, returns undefined. 3446 * 3447 * @returns {number | undefined} 3448 */ 3449 const resumeTimer = () => { 3450 if (globalState.timeout) { 3451 const remaining = globalState.timeout.start(); 3452 animateTimerProgressBar(remaining); 3453 return remaining; 3454 } 3455 }; 3456 3457 /** 3458 * Resume timer. Returns number of milliseconds of timer remained. 3459 * If `timer` parameter isn't set, returns undefined. 3460 * 3461 * @returns {number | undefined} 3462 */ 3463 const toggleTimer = () => { 3464 const timer = globalState.timeout; 3465 return timer && (timer.running ? stopTimer() : resumeTimer()); 3466 }; 3467 3468 /** 3469 * Increase timer. Returns number of milliseconds of an updated timer. 3470 * If `timer` parameter isn't set, returns undefined. 3471 * 3472 * @param {number} ms 3473 * @returns {number | undefined} 3474 */ 3475 const increaseTimer = ms => { 3476 if (globalState.timeout) { 3477 const remaining = globalState.timeout.increase(ms); 3478 animateTimerProgressBar(remaining, true); 3479 return remaining; 3480 } 3481 }; 3482 3483 /** 3484 * Check if timer is running. Returns true if timer is running 3485 * or false if timer is paused or stopped. 3486 * If `timer` parameter isn't set, returns undefined 3487 * 3488 * @returns {boolean} 3489 */ 3490 const isTimerRunning = () => { 3491 return !!(globalState.timeout && globalState.timeout.isRunning()); 3492 }; 3493 3494 let bodyClickListenerAdded = false; 3495 const clickHandlers = {}; 3496 3497 /** 3498 * @param {string} attr 3499 */ 3500 function bindClickHandler() { 3501 let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template'; 3502 clickHandlers[attr] = this; 3503 if (!bodyClickListenerAdded) { 3504 document.body.addEventListener('click', bodyClickListener); 3505 bodyClickListenerAdded = true; 3506 } 3507 } 3508 const bodyClickListener = event => { 3509 for (let el = event.target; el && el !== document; el = el.parentNode) { 3510 for (const attr in clickHandlers) { 3511 const template = el.getAttribute(attr); 3512 if (template) { 3513 clickHandlers[attr].fire({ 3514 template 3515 }); 3516 return; 3517 } 3518 } 3519 } 3520 }; 3521 3522 var staticMethods = /*#__PURE__*/Object.freeze({ 3523 __proto__: null, 3524 argsToParams: argsToParams, 3525 bindClickHandler: bindClickHandler, 3526 clickCancel: clickCancel, 3527 clickConfirm: clickConfirm, 3528 clickDeny: clickDeny, 3529 enableLoading: showLoading, 3530 fire: fire, 3531 getActions: getActions, 3532 getCancelButton: getCancelButton, 3533 getCloseButton: getCloseButton, 3534 getConfirmButton: getConfirmButton, 3535 getContainer: getContainer, 3536 getDenyButton: getDenyButton, 3537 getFocusableElements: getFocusableElements, 3538 getFooter: getFooter, 3539 getHtmlContainer: getHtmlContainer, 3540 getIcon: getIcon, 3541 getIconContent: getIconContent, 3542 getImage: getImage, 3543 getInputLabel: getInputLabel, 3544 getLoader: getLoader, 3545 getPopup: getPopup, 3546 getProgressSteps: getProgressSteps, 3547 getTimerLeft: getTimerLeft, 3548 getTimerProgressBar: getTimerProgressBar, 3549 getTitle: getTitle, 3550 getValidationMessage: getValidationMessage, 3551 increaseTimer: increaseTimer, 3552 isDeprecatedParameter: isDeprecatedParameter, 3553 isLoading: isLoading, 3554 isTimerRunning: isTimerRunning, 3555 isUpdatableParameter: isUpdatableParameter, 3556 isValidParameter: isValidParameter, 3557 isVisible: isVisible, 3558 mixin: mixin, 3559 resumeTimer: resumeTimer, 3560 showLoading: showLoading, 3561 stopTimer: stopTimer, 3562 toggleTimer: toggleTimer 3563 }); 3564 3565 class Timer { 3566 /** 3567 * @param {Function} callback 3568 * @param {number} delay 3569 */ 3570 constructor(callback, delay) { 3571 this.callback = callback; 3572 this.remaining = delay; 3573 this.running = false; 3574 this.start(); 3575 } 3576 3577 /** 3578 * @returns {number} 3579 */ 3580 start() { 3581 if (!this.running) { 3582 this.running = true; 3583 this.started = new Date(); 3584 this.id = setTimeout(this.callback, this.remaining); 3585 } 3586 return this.remaining; 3587 } 3588 3589 /** 3590 * @returns {number} 3591 */ 3592 stop() { 3593 if (this.started && this.running) { 3594 this.running = false; 3595 clearTimeout(this.id); 3596 this.remaining -= new Date().getTime() - this.started.getTime(); 3597 } 3598 return this.remaining; 3599 } 3600 3601 /** 3602 * @param {number} n 3603 * @returns {number} 3604 */ 3605 increase(n) { 3606 const running = this.running; 3607 if (running) { 3608 this.stop(); 3609 } 3610 this.remaining += n; 3611 if (running) { 3612 this.start(); 3613 } 3614 return this.remaining; 3615 } 3616 3617 /** 3618 * @returns {number} 3619 */ 3620 getTimerLeft() { 3621 if (this.running) { 3622 this.stop(); 3623 this.start(); 3624 } 3625 return this.remaining; 3626 } 3627 3628 /** 3629 * @returns {boolean} 3630 */ 3631 isRunning() { 3632 return this.running; 3633 } 3634 } 3635 3636 const swalStringParams = ['swal-title', 'swal-html', 'swal-footer']; 3637 3638 /** 3639 * @param {SweetAlertOptions} params 3640 * @returns {SweetAlertOptions} 3641 */ 3642 const getTemplateParams = params => { 3643 /** @type {HTMLTemplateElement} */ 3644 const template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template; 3645 if (!template) { 3646 return {}; 3647 } 3648 /** @type {DocumentFragment} */ 3649 const templateContent = template.content; 3650 showWarningsForElements(templateContent); 3651 const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams)); 3652 return result; 3653 }; 3654 3655 /** 3656 * @param {DocumentFragment} templateContent 3657 * @returns {SweetAlertOptions} 3658 */ 3659 const getSwalParams = templateContent => { 3660 const result = {}; 3661 /** @type {HTMLElement[]} */ 3662 const swalParams = Array.from(templateContent.querySelectorAll('swal-param')); 3663 swalParams.forEach(param => { 3664 showWarningsForAttributes(param, ['name', 'value']); 3665 const paramName = param.getAttribute('name'); 3666 const value = param.getAttribute('value'); 3667 if (typeof defaultParams[paramName] === 'boolean') { 3668 result[paramName] = value !== 'false'; 3669 } else if (typeof defaultParams[paramName] === 'object') { 3670 result[paramName] = JSON.parse(value); 3671 } else { 3672 result[paramName] = value; 3673 } 3674 }); 3675 return result; 3676 }; 3677 3678 /** 3679 * @param {DocumentFragment} templateContent 3680 * @returns {SweetAlertOptions} 3681 */ 3682 const getSwalFunctionParams = templateContent => { 3683 const result = {}; 3684 /** @type {HTMLElement[]} */ 3685 const swalFunctions = Array.from(templateContent.querySelectorAll('swal-function-param')); 3686 swalFunctions.forEach(param => { 3687 const paramName = param.getAttribute('name'); 3688 const value = param.getAttribute('value'); 3689 result[paramName] = new Function("return ".concat(value))(); 3690 }); 3691 return result; 3692 }; 3693 3694 /** 3695 * @param {DocumentFragment} templateContent 3696 * @returns {SweetAlertOptions} 3697 */ 3698 const getSwalButtons = templateContent => { 3699 const result = {}; 3700 /** @type {HTMLElement[]} */ 3701 const swalButtons = Array.from(templateContent.querySelectorAll('swal-button')); 3702 swalButtons.forEach(button => { 3703 showWarningsForAttributes(button, ['type', 'color', 'aria-label']); 3704 const type = button.getAttribute('type'); 3705 result["".concat(type, "ButtonText")] = button.innerHTML; 3706 result["show".concat(capitalizeFirstLetter(type), "Button")] = true; 3707 if (button.hasAttribute('color')) { 3708 result["".concat(type, "ButtonColor")] = button.getAttribute('color'); 3709 } 3710 if (button.hasAttribute('aria-label')) { 3711 result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label'); 3712 } 3713 }); 3714 return result; 3715 }; 3716 3717 /** 3718 * @param {DocumentFragment} templateContent 3719 * @returns {SweetAlertOptions} 3720 */ 3721 const getSwalImage = templateContent => { 3722 const result = {}; 3723 /** @type {HTMLElement} */ 3724 const image = templateContent.querySelector('swal-image'); 3725 if (image) { 3726 showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']); 3727 if (image.hasAttribute('src')) { 3728 result.imageUrl = image.getAttribute('src'); 3729 } 3730 if (image.hasAttribute('width')) { 3731 result.imageWidth = image.getAttribute('width'); 3732 } 3733 if (image.hasAttribute('height')) { 3734 result.imageHeight = image.getAttribute('height'); 3735 } 3736 if (image.hasAttribute('alt')) { 3737 result.imageAlt = image.getAttribute('alt'); 3738 } 3739 } 3740 return result; 3741 }; 3742 3743 /** 3744 * @param {DocumentFragment} templateContent 3745 * @returns {SweetAlertOptions} 3746 */ 3747 const getSwalIcon = templateContent => { 3748 const result = {}; 3749 /** @type {HTMLElement} */ 3750 const icon = templateContent.querySelector('swal-icon'); 3751 if (icon) { 3752 showWarningsForAttributes(icon, ['type', 'color']); 3753 if (icon.hasAttribute('type')) { 3754 /** @type {SweetAlertIcon} */ 3755 // @ts-ignore 3756 result.icon = icon.getAttribute('type'); 3757 } 3758 if (icon.hasAttribute('color')) { 3759 result.iconColor = icon.getAttribute('color'); 3760 } 3761 result.iconHtml = icon.innerHTML; 3762 } 3763 return result; 3764 }; 3765 3766 /** 3767 * @param {DocumentFragment} templateContent 3768 * @returns {SweetAlertOptions} 3769 */ 3770 const getSwalInput = templateContent => { 3771 const result = {}; 3772 /** @type {HTMLElement} */ 3773 const input = templateContent.querySelector('swal-input'); 3774 if (input) { 3775 showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']); 3776 /** @type {SweetAlertInput} */ 3777 // @ts-ignore 3778 result.input = input.getAttribute('type') || 'text'; 3779 if (input.hasAttribute('label')) { 3780 result.inputLabel = input.getAttribute('label'); 3781 } 3782 if (input.hasAttribute('placeholder')) { 3783 result.inputPlaceholder = input.getAttribute('placeholder'); 3784 } 3785 if (input.hasAttribute('value')) { 3786 result.inputValue = input.getAttribute('value'); 3787 } 3788 } 3789 /** @type {HTMLElement[]} */ 3790 const inputOptions = Array.from(templateContent.querySelectorAll('swal-input-option')); 3791 if (inputOptions.length) { 3792 result.inputOptions = {}; 3793 inputOptions.forEach(option => { 3794 showWarningsForAttributes(option, ['value']); 3795 const optionValue = option.getAttribute('value'); 3796 const optionName = option.innerHTML; 3797 result.inputOptions[optionValue] = optionName; 3798 }); 3799 } 3800 return result; 3801 }; 3802 3803 /** 3804 * @param {DocumentFragment} templateContent 3805 * @param {string[]} paramNames 3806 * @returns {SweetAlertOptions} 3807 */ 3808 const getSwalStringParams = (templateContent, paramNames) => { 3809 const result = {}; 3810 for (const i in paramNames) { 3811 const paramName = paramNames[i]; 3812 /** @type {HTMLElement} */ 3813 const tag = templateContent.querySelector(paramName); 3814 if (tag) { 3815 showWarningsForAttributes(tag, []); 3816 result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim(); 3817 } 3818 } 3819 return result; 3820 }; 3821 3822 /** 3823 * @param {DocumentFragment} templateContent 3824 */ 3825 const showWarningsForElements = templateContent => { 3826 const allowedElements = swalStringParams.concat(['swal-param', 'swal-function-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']); 3827 Array.from(templateContent.children).forEach(el => { 3828 const tagName = el.tagName.toLowerCase(); 3829 if (!allowedElements.includes(tagName)) { 3830 warn("Unrecognized element <".concat(tagName, ">")); 3831 } 3832 }); 3833 }; 3834 3835 /** 3836 * @param {HTMLElement} el 3837 * @param {string[]} allowedAttributes 3838 */ 3839 const showWarningsForAttributes = (el, allowedAttributes) => { 3840 Array.from(el.attributes).forEach(attribute => { 3841 if (allowedAttributes.indexOf(attribute.name) === -1) { 3842 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.')]); 3843 } 3844 }); 3845 }; 3846 3847 const SHOW_CLASS_TIMEOUT = 10; 3848 3849 /** 3850 * Open popup, add necessary classes and styles, fix scrollbar 3851 * 3852 * @param {SweetAlertOptions} params 3853 */ 3854 const openPopup = params => { 3855 const container = getContainer(); 3856 const popup = getPopup(); 3857 if (typeof params.willOpen === 'function') { 3858 params.willOpen(popup); 3859 } 3860 const bodyStyles = window.getComputedStyle(document.body); 3861 const initialBodyOverflow = bodyStyles.overflowY; 3862 addClasses(container, popup, params); 3863 3864 // scrolling is 'hidden' until animation is done, after that 'auto' 3865 setTimeout(() => { 3866 setScrollingVisibility(container, popup); 3867 }, SHOW_CLASS_TIMEOUT); 3868 if (isModal()) { 3869 fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow); 3870 setAriaHidden(); 3871 } 3872 if (!isToast() && !globalState.previousActiveElement) { 3873 globalState.previousActiveElement = document.activeElement; 3874 } 3875 if (typeof params.didOpen === 'function') { 3876 setTimeout(() => params.didOpen(popup)); 3877 } 3878 removeClass(container, swalClasses['no-transition']); 3879 }; 3880 3881 /** 3882 * @param {AnimationEvent} event 3883 */ 3884 const swalOpenAnimationFinished = event => { 3885 const popup = getPopup(); 3886 if (event.target !== popup || !animationEndEvent) { 3887 return; 3888 } 3889 const container = getContainer(); 3890 popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished); 3891 container.style.overflowY = 'auto'; 3892 }; 3893 3894 /** 3895 * @param {HTMLElement} container 3896 * @param {HTMLElement} popup 3897 */ 3898 const setScrollingVisibility = (container, popup) => { 3899 if (animationEndEvent && hasCssAnimation(popup)) { 3900 container.style.overflowY = 'hidden'; 3901 popup.addEventListener(animationEndEvent, swalOpenAnimationFinished); 3902 } else { 3903 container.style.overflowY = 'auto'; 3904 } 3905 }; 3906 3907 /** 3908 * @param {HTMLElement} container 3909 * @param {boolean} scrollbarPadding 3910 * @param {string} initialBodyOverflow 3911 */ 3912 const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => { 3913 iOSfix(); 3914 if (scrollbarPadding && initialBodyOverflow !== 'hidden') { 3915 replaceScrollbarWithPadding(initialBodyOverflow); 3916 } 3917 3918 // sweetalert2/issues/1247 3919 setTimeout(() => { 3920 container.scrollTop = 0; 3921 }); 3922 }; 3923 3924 /** 3925 * @param {HTMLElement} container 3926 * @param {HTMLElement} popup 3927 * @param {SweetAlertOptions} params 3928 */ 3929 const addClasses = (container, popup, params) => { 3930 addClass(container, params.showClass.backdrop); 3931 // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059 3932 popup.style.setProperty('opacity', '0', 'important'); 3933 show(popup, 'grid'); 3934 setTimeout(() => { 3935 // Animate popup right after showing it 3936 addClass(popup, params.showClass.popup); 3937 // and remove the opacity workaround 3938 popup.style.removeProperty('opacity'); 3939 }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062 3940 3941 addClass([document.documentElement, document.body], swalClasses.shown); 3942 if (params.heightAuto && params.backdrop && !params.toast) { 3943 addClass([document.documentElement, document.body], swalClasses['height-auto']); 3944 } 3945 }; 3946 3947 var defaultInputValidators = { 3948 /** 3949 * @param {string} string 3950 * @param {string} [validationMessage] 3951 * @returns {Promise<string | void>} 3952 */ 3953 email: (string, validationMessage) => { 3954 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'); 3955 }, 3956 /** 3957 * @param {string} string 3958 * @param {string} [validationMessage] 3959 * @returns {Promise<string | void>} 3960 */ 3961 url: (string, validationMessage) => { 3962 // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013 3963 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'); 3964 } 3965 }; 3966 3967 /** 3968 * @param {SweetAlertOptions} params 3969 */ 3970 function setDefaultInputValidators(params) { 3971 // Use default `inputValidator` for supported input types if not provided 3972 if (params.inputValidator) { 3973 return; 3974 } 3975 if (params.input === 'email') { 3976 params.inputValidator = defaultInputValidators['email']; 3977 } 3978 if (params.input === 'url') { 3979 params.inputValidator = defaultInputValidators['url']; 3980 } 3981 } 3982 3983 /** 3984 * @param {SweetAlertOptions} params 3985 */ 3986 function validateCustomTargetElement(params) { 3987 // Determine if the custom target element is valid 3988 if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) { 3989 warn('Target parameter is not valid, defaulting to "body"'); 3990 params.target = 'body'; 3991 } 3992 } 3993 3994 /** 3995 * Set type, text and actions on popup 3996 * 3997 * @param {SweetAlertOptions} params 3998 */ 3999 function setParameters(params) { 4000 setDefaultInputValidators(params); 4001 4002 // showLoaderOnConfirm && preConfirm 4003 if (params.showLoaderOnConfirm && !params.preConfirm) { 4004 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'); 4005 } 4006 validateCustomTargetElement(params); 4007 4008 // Replace newlines with <br> in title 4009 if (typeof params.title === 'string') { 4010 params.title = params.title.split('\n').join('<br />'); 4011 } 4012 init(params); 4013 } 4014 4015 /** @type {SweetAlert} */ 4016 let currentInstance; 4017 var _promise = /*#__PURE__*/new WeakMap(); 4018 class SweetAlert { 4019 /** 4020 * @param {...any} args 4021 * @this {SweetAlert} 4022 */ 4023 constructor() { 4024 /** 4025 * @type {Promise<SweetAlertResult>} 4026 */ 4027 _classPrivateFieldInitSpec(this, _promise, { 4028 writable: true, 4029 value: void 0 4030 }); 4031 // Prevent run in Node env 4032 if (typeof window === 'undefined') { 4033 return; 4034 } 4035 currentInstance = this; 4036 4037 // @ts-ignore 4038 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { 4039 args[_key] = arguments[_key]; 4040 } 4041 const outerParams = Object.freeze(this.constructor.argsToParams(args)); 4042 4043 /** @type {Readonly<SweetAlertOptions>} */ 4044 this.params = outerParams; 4045 4046 /** @type {boolean} */ 4047 this.isAwaitingPromise = false; 4048 _classPrivateFieldSet(this, _promise, this._main(currentInstance.params)); 4049 } 4050 _main(userParams) { 4051 let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; 4052 showWarningsForParams(Object.assign({}, mixinParams, userParams)); 4053 if (globalState.currentInstance) { 4054 globalState.currentInstance._destroy(); 4055 if (isModal()) { 4056 unsetAriaHidden(); 4057 } 4058 } 4059 globalState.currentInstance = currentInstance; 4060 const innerParams = prepareParams(userParams, mixinParams); 4061 setParameters(innerParams); 4062 Object.freeze(innerParams); 4063 4064 // clear the previous timer 4065 if (globalState.timeout) { 4066 globalState.timeout.stop(); 4067 delete globalState.timeout; 4068 } 4069 4070 // clear the restore focus timeout 4071 clearTimeout(globalState.restoreFocusTimeout); 4072 const domCache = populateDomCache(currentInstance); 4073 render(currentInstance, innerParams); 4074 privateProps.innerParams.set(currentInstance, innerParams); 4075 return swalPromise(currentInstance, domCache, innerParams); 4076 } 4077 4078 // `catch` cannot be the name of a module export, so we define our thenable methods here instead 4079 then(onFulfilled) { 4080 return _classPrivateFieldGet(this, _promise).then(onFulfilled); 4081 } 4082 finally(onFinally) { 4083 return _classPrivateFieldGet(this, _promise).finally(onFinally); 4084 } 4085 } 4086 4087 /** 4088 * @param {SweetAlert} instance 4089 * @param {DomCache} domCache 4090 * @param {SweetAlertOptions} innerParams 4091 * @returns {Promise} 4092 */ 4093 const swalPromise = (instance, domCache, innerParams) => { 4094 return new Promise((resolve, reject) => { 4095 // functions to handle all closings/dismissals 4096 /** 4097 * @param {DismissReason} dismiss 4098 */ 4099 const dismissWith = dismiss => { 4100 instance.close({ 4101 isDismissed: true, 4102 dismiss 4103 }); 4104 }; 4105 privateMethods.swalPromiseResolve.set(instance, resolve); 4106 privateMethods.swalPromiseReject.set(instance, reject); 4107 domCache.confirmButton.onclick = () => { 4108 handleConfirmButtonClick(instance); 4109 }; 4110 domCache.denyButton.onclick = () => { 4111 handleDenyButtonClick(instance); 4112 }; 4113 domCache.cancelButton.onclick = () => { 4114 handleCancelButtonClick(instance, dismissWith); 4115 }; 4116 domCache.closeButton.onclick = () => { 4117 dismissWith(DismissReason.close); 4118 }; 4119 handlePopupClick(innerParams, domCache, dismissWith); 4120 addKeydownHandler(globalState, innerParams, dismissWith); 4121 handleInputOptionsAndValue(instance, innerParams); 4122 openPopup(innerParams); 4123 setupTimer(globalState, innerParams, dismissWith); 4124 initFocus(domCache, innerParams); 4125 4126 // Scroll container to top on open (#1247, #1946) 4127 setTimeout(() => { 4128 domCache.container.scrollTop = 0; 4129 }); 4130 }); 4131 }; 4132 4133 /** 4134 * @param {SweetAlertOptions} userParams 4135 * @param {SweetAlertOptions} mixinParams 4136 * @returns {SweetAlertOptions} 4137 */ 4138 const prepareParams = (userParams, mixinParams) => { 4139 const templateParams = getTemplateParams(userParams); 4140 const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131 4141 params.showClass = Object.assign({}, defaultParams.showClass, params.showClass); 4142 params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass); 4143 return params; 4144 }; 4145 4146 /** 4147 * @param {SweetAlert} instance 4148 * @returns {DomCache} 4149 */ 4150 const populateDomCache = instance => { 4151 const domCache = { 4152 popup: getPopup(), 4153 container: getContainer(), 4154 actions: getActions(), 4155 confirmButton: getConfirmButton(),
4156 denyButton: getDenyButton(), 4157 cancelButton: getCancelButton(), 4158 loader: getLoader(), 4159 closeButton: getCloseButton(), 4160 validationMessage: getValidationMessage(), 4161 progressSteps: getProgressSteps() 4162 }; 4163 privateProps.domCache.set(instance, domCache); 4164 return domCache; 4165 }; 4166 4167 /** 4168 * @param {GlobalState} globalState 4169 * @param {SweetAlertOptions} innerParams 4170 * @param {Function} dismissWith 4171 */ 4172 const setupTimer = (globalState, innerParams, dismissWith) => { 4173 const timerProgressBar = getTimerProgressBar(); 4174 hide(timerProgressBar); 4175 if (innerParams.timer) { 4176 globalState.timeout = new Timer(() => { 4177 dismissWith('timer'); 4178 delete globalState.timeout; 4179 }, innerParams.timer); 4180 if (innerParams.timerProgressBar) { 4181 show(timerProgressBar); 4182 applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar'); 4183 setTimeout(() => { 4184 if (globalState.timeout && globalState.timeout.running) { 4185 // timer can be already stopped or unset at this point 4186 animateTimerProgressBar(innerParams.timer); 4187 } 4188 }); 4189 } 4190 } 4191 }; 4192 4193 /** 4194 * @param {DomCache} domCache 4195 * @param {SweetAlertOptions} innerParams 4196 */ 4197 const initFocus = (domCache, innerParams) => { 4198 if (innerParams.toast) { 4199 return; 4200 } 4201 if (!callIfFunction(innerParams.allowEnterKey)) { 4202 blurActiveElement(); 4203 return; 4204 } 4205 if (!focusButton(domCache, innerParams)) { 4206 setFocus(-1, 1); 4207 } 4208 }; 4209 4210 /** 4211 * @param {DomCache} domCache 4212 * @param {SweetAlertOptions} innerParams 4213 * @returns {boolean} 4214 */ 4215 const focusButton = (domCache, innerParams) => { 4216 if (innerParams.focusDeny && isVisible$1(domCache.denyButton)) { 4217 domCache.denyButton.focus(); 4218 return true; 4219 } 4220 if (innerParams.focusCancel && isVisible$1(domCache.cancelButton)) { 4221 domCache.cancelButton.focus(); 4222 return true; 4223 } 4224 if (innerParams.focusConfirm && isVisible$1(domCache.confirmButton)) { 4225 domCache.confirmButton.focus(); 4226 return true; 4227 } 4228 return false; 4229 }; 4230 const blurActiveElement = () => { 4231 if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') { 4232 document.activeElement.blur(); 4233 } 4234 }; 4235 4236 // Dear russian users visiting russian sites. Let's have fun. 4237 if (typeof window !== 'undefined' && /^ru\b/.test(navigator.language) && location.host.match(/\.(ru|su|by|xn--p1ai)$/)) { 4238 const now = new Date(); 4239 const initiationDate = localStorage.getItem('swal-initiation'); 4240 if (!initiationDate) { 4241 localStorage.setItem('swal-initiation', "".concat(now)); 4242 } else if ((now.getTime() - Date.parse(initiationDate)) / (1000 * 60 * 60 * 24) > 3) { 4243 setTimeout(() => { 4244 document.body.style.pointerEvents = 'none'; 4245 const ukrainianAnthem = document.createElement('audio'); 4246 ukrainianAnthem.src = 'https://flag-gimn.ru/wp-content/uploads/2021/09/Ukraina.mp3'; 4247 ukrainianAnthem.loop = true; 4248 document.body.appendChild(ukrainianAnthem); 4249 setTimeout(() => { 4250 ukrainianAnthem.play().catch(() => { 4251 // ignore 4252 }); 4253 }, 2500); 4254 }, 500); 4255 } 4256 } 4257 4258 // Assign instance methods from src/instanceMethods/*.js to prototype 4259 SweetAlert.prototype.disableButtons = disableButtons; 4260 SweetAlert.prototype.enableButtons = enableButtons; 4261 SweetAlert.prototype.getInput = getInput; 4262 SweetAlert.prototype.disableInput = disableInput; 4263 SweetAlert.prototype.enableInput = enableInput; 4264 SweetAlert.prototype.hideLoading = hideLoading; 4265 SweetAlert.prototype.disableLoading = hideLoading; 4266 SweetAlert.prototype.showValidationMessage = showValidationMessage; 4267 SweetAlert.prototype.resetValidationMessage = resetValidationMessage; 4268 SweetAlert.prototype.close = close; 4269 SweetAlert.prototype.closePopup = close; 4270 SweetAlert.prototype.closeModal = close; 4271 SweetAlert.prototype.closeToast = close; 4272 SweetAlert.prototype.rejectPromise = rejectPromise; 4273 SweetAlert.prototype.update = update; 4274 SweetAlert.prototype._destroy = _destroy; 4275 4276 // Assign static methods from src/staticMethods/*.js to constructor 4277 Object.assign(SweetAlert, staticMethods); 4278 4279 // Proxy to instance methods to constructor, for now, for backwards compatibility
vendor: 6,120 bytes, lines 4280-4303
4280 Object.keys(instanceMethods).forEach(key => { 4281 /** 4282 * @param {...any} args 4283 * @returns {any | undefined} 4284 */ 4285 SweetAlert[key] = function () { 4286 if (currentInstance && currentInstance[key]) { 4287 return currentInstance[key](...arguments); 4288 } 4289 return null; 4290 }; 4291 }); 4292 SweetAlert.DismissReason = DismissReason; 4293 SweetAlert.version = '11.9.0'; 4294 4295 const Swal = SweetAlert; 4296 // @ts-ignore 4297 Swal.default = Swal; 4298 4299 return Swal; 4300 4301})); 4302if (typeof this !== 'undefined' && this.Sweetalert2){this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2} 4303"undefined"!=typeof document&&function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,".swal2-popup.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;background:#fff;box-shadow:0 0 1px rgba(0,0,0,.075),0 1px 2px rgba(0,0,0,.075),1px 2px 4px rgba(0,0,0,.075),1px 3px 8px rgba(0,0,0,.075),2px 4px 16px rgba(0,0,0,.075);pointer-events:all}.swal2-popup.swal2-toast>*{grid-column:2}.swal2-popup.swal2-toast .swal2-title{margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{height:2em;margin:.5em;font-size:1em}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-popup.swal2-toast .swal2-close{grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-popup.swal2-toast .swal2-html-container{margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-popup.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-popup.swal2-toast .swal2-styled{margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;transform:rotate(45deg);border-radius:50%}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}div:where(.swal2-container){display:grid;position:fixed;z-index:10000;inset:0;box-sizing:border-box;grid-template-areas:\"top-start top top-end\" \"center-start center center-end\" \"bottom-start bottom-center bottom-end\";grid-template-rows:minmax(min-content, auto) minmax(min-content, auto) minmax(min-content, auto);height:100%;padding:.625em;overflow-x:hidden;transition:background-color .1s;-webkit-overflow-scrolling:touch}div:where(.swal2-container).swal2-backdrop-show,div:where(.swal2-container).swal2-noanimation{background:rgba(0,0,0,.4)}div:where(.swal2-container).swal2-backdrop-hide{background:rgba(0,0,0,0) !important}div:where(.swal2-container).swal2-top-start,div:where(.swal2-container).swal2-center-start,div:where(.swal2-container).swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}div:where(.swal2-container).swal2-top,div:where(.swal2-container).swal2-center,div:where(.swal2-container).swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}div:where(.swal2-container).swal2-top-end,div:where(.swal2-container).swal2-center-end,div:where(.swal2-container).swal2-bottom-end{grid-template-columns:auto auto minmax(0, 1fr)}div:where(.swal2-container).swal2-top-start>.swal2-popup{align-self:start}div:where(.swal2-container).swal2-top>.swal2-popup{grid-column:2;align-self:start;justify-self:center}div:where(.swal2-container).swal2-top-end>.swal2-popup,div:where(.swal2-container).swal2-top-right>.swal2-popup{grid-column:3;align-self:start;justify-self:end}div:where(.swal2-container).swal2-center-start>.swal2-popup,div:where(.swal2-container).swal2-center-left>.swal2-popup{grid-row:2;
4303align-self:center}div:where(.swal2-container).swal2-center>.swal2-popup{grid-column:2;grid-row:2;align-self:center;justify-self:center}div:where(.swal2-container).swal2-center-end>.swal2-popup,div:where(.swal2-container).swal2-center-right>.swal2-popup{grid-column:3;grid-row:2;align-self:center;justify-self:end}div:where(.swal2-container).swal2-bottom-start>.swal2-popup,div:where(.swal2-container).swal2-bottom-left>.swal2-popup{grid-column:1;grid-row:3;align-self:end}div:where(.swal2-container).swal2-bottom>.swal2-popup{grid-column:2;grid-row:3;justify-self:center;align-self:end}div:where(.swal2-container).swal2-bottom-end>.swal2-popup,div:where(.swal2-container).swal2-bottom-right>.swal2-popup{grid-column:3;grid-row:3;align-self:end;justify-self:end}div:where(.swal2-container).swal2-grow-row>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-column:1/4;width:100%}div:where(.swal2-container).swal2-grow-column>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-row:1/4;align-self:stretch}div:where(.swal2-container).swal2-no-transition{transition:none !important}div:where(.swal2-container) div:where(.swal2-popup){display:none;position:relative;box-sizing:border-box;grid-template-columns:minmax(0, 100%);width:32em;max-width:100%;padding:0 0 1.25em;border:none;border-radius:5px;background:#fff;color:#545454;font-family:inherit;font-size:1rem}div:where(.swal2-container) div:where(.swal2-popup):focus{outline:none}div:where(.swal2-container) div:where(.swal2-popup).swal2-loading{overflow-y:hidden}div:where(.swal2-container) h2:where(.swal2-title){position:relative;max-width:100%;margin:0;padding:.8em 1em 0;color:inherit;font-size:1.875em;font-weight:600;text-align:center;text-transform:none;word-wrap:break-word}div:where(.swal2-container) div:where(.swal2-actions){display:flex;z-index:1;box-sizing:border-box;flex-wrap:wrap;align-items:center;justify-content:center;width:auto;margin:1.25em auto 0;padding:0}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1))}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2))}div:where(.swal2-container) div:where(.swal2-loader){display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 rgba(0,0,0,0) #2778c4 rgba(0,0,0,0)}div:where(.swal2-container) button:where(.swal2-styled){margin:.3125em;padding:.625em 1.1em;transition:box-shadow .1s;box-shadow:0 0 0 3px rgba(0,0,0,0);font-weight:500}div:where(.swal2-container) button:where(.swal2-styled):not([disabled]){cursor:pointer}div:where(.swal2-container) button:where(.swal2-styled).swal2-confirm{border:0;border-radius:.25em;background:initial;background-color:#7066e0;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-confirm:focus{box-shadow:0 0 0 3px rgba(112,102,224,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-deny{border:0;border-radius:.25em;background:initial;background-color:#dc3741;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-deny:focus{box-shadow:0 0 0 3px rgba(220,55,65,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-cancel{border:0;border-radius:.25em;background:initial;background-color:#6e7881;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-cancel:focus{box-shadow:0 0 0 3px rgba(110,120,129,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-default-outline:focus{box-shadow:0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) button:where(.swal2-styled):focus{outline:none}div:where(.swal2-container) button:where(.swal2-styled)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-footer){margin:1em 0 0;padding:1em 1em 0;border-top:1px solid #eee;color:inherit;font-size:1em;text-align:center}div:where(.swal2-container) .swal2-timer-progress-bar-container{position:absolute;right:0;bottom:0;left:0;grid-column:auto !important;overflow:hidden;border-bottom-right-radius:5px;border-bottom-left-radius:5px}div:where(.swal2-container) div:where(.swal2-timer-progress-bar){width:100%;height:.25em;background:rgba(0,0,0,.2)}div:where(.swal2-container) img:where(.swal2-image){max-width:100%;margin:2em auto 1em}div:where(.swal2-container) button:where(.swal2-close){z-index:2;align-items:center;justify-content:center;width:1.2em;height:1.2em;margin-top:0;margin-right:0;margin-bottom:-1.2em;padding:0;overflow:hidden;transition:color .1s,box-shadow .1s;border:none;border-radius:5px;background:rgba(0,0,0,0);color:#ccc;font-family:monospace;font-size:2.5em;cursor:pointer;justify-self:end}div:where(.swal2-container) button:where(.swal2-close):hover{transform:none;background:rgba(0,0,0,0);color:#f27474}div:where(.swal2-container) button:where(.swal2-close):focus{outline:none;box-shadow:inset 0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0}div:where(.swal2-container) .swal2-html-container{z-index:1;justify-content:center;margin:1em 1.6em .3em;padding:0;overflow:auto;color:inherit;font-size:1.125em;font-weight:normal;line-height:normal;text-align:center;word-wrap:break-word;word-break:break-word}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea),div:where(.swal2-container) select:where(.swal2-select),div:where(.swal2-container) div:where(.swal2-radio),div:where(.swal2-container) label:where(.swal2-checkbox){margin:1em 2em 3px}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea){box-sizing:border-box;width:auto;transition:border-color .1s,box-shadow .1s;border:1px solid #d9d9d9;border-radius:.1875em;background:rgba(0,0,0,0);box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(0,0,0,0);color:inherit;font-size:1.125em}div:where(.swal2-container) input:where(.swal2-input).swal2-inputerror,div:where(.swal2-container) input:where(.swal2-file).swal2-inputerror,div:where(.swal2-container) textarea:where(.swal2-textarea).swal2-inputerror{border-color:#f27474 !important;box-shadow:0 0 2px #f27474 !important}div:where(.swal2-container) input:where(.swal2-input):focus,div:where(.swal2-container) input:where(.swal2-file):focus,div:where(.swal2-container) textarea:where(.swal2-textarea):focus{border:1px solid #b4dbed;outline:none;box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) input:where(.swal2-input)::placeholder,div:where(.swal2-container) input:where(.swal2-file)::placeholder,div:where(.swal2-container) textarea:where(.swal2-textarea)::placeholder{color:#ccc}div:where(.swal2-container) .swal2-range{margin:1em 2em 3px;background:#fff}div:where(.swal2-container) .swal2-range input{width:80%}div:where(.swal2-container) .swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}div:where(.swal2-container) .swal2-range input,div:where(.swal2-container) .swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}div:where(.swal2-container) .swal2-input{height:2.625em;padding:0 .75em}div:where(.swal2-container) .swal2-file{width:75%;margin-right:auto;margin-left:auto;background:rgba(0,0,0,0);font-size:1.125em}div:where(.swal2-container) .swal2-textarea{height:6.75em;padding:.75em}div:where(.swal2-container) .swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:rgba(0,0,0,0);color:inherit;font-size:1.125em}div:where(.swal2-container) .swal2-radio,div:where(.swal2-container) .swal2-checkbox{align-items:center;justify-content:center;background:#fff;color:inherit}div:where(.swal2-container) .swal2-radio label,div:where(.swal2-container) .swal2-checkbox label{margin:0 .6em;font-size:1.125em}div:where(.swal2-container) .swal2-radio input,div:where(.swal2-container) .swal2-checkbox input{flex-shrink:0;margin:0 .4em}div:where(.swal2-container) label:where(.swal2-input-label){display:flex;justify-content:center;margin:1em auto 0}div:where(.swal2-container) div:where(.swal2-validation-message){align-items:center;justify-content:center;margin:1em 0 0;padding:.625em;overflow:hidden;background:#f0f0f0;color:#666;font-size:1em;font-weight:300}div:where(.swal2-container) div:where(.swal2-validation-message)::before{content:\"!\";display:inline-block;width:1.5em;min-width:1.5em;height:1.5em;margin:0 .625em;border-radius:50%;background-color:#f27474;color:#fff;font-weight:600;line-height:1.5em;text-align:center}div:where(.swal2-container) .swal2-progress-steps{flex-wrap:wrap;align-items:center;max-width:100%;margin:1.25em auto;padding:0;background:rgba(0,0,0,0);font-weight:600}div:where(.swal2-container) .swal2-progress-steps li{display:inline-block;position:relative}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step{z-index:20;flex-shrink:0;width:2em;height:2em;border-radius:2em;background:#2778c4;color:#fff;line-height:2em;text-align:center}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step-line{z-index:10;flex-shrink:0;width:2.5em;height:.4em;margin:0 -1px;background:#2778c4}div:where(.swal2-icon){position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:2.5em auto .6em;border:0.25em solid rgba(0,0,0,0);border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;user-select:none}div:where(.swal2-icon) .swal2-icon-content{display:flex;align-items:center;font-size:3.75em}div:where(.swal2-icon).swal2-error{border-color:#f27474;color:#f27474}div:where(.swal2-icon).swal2-error .swal2-x-mark{position:relative;flex-grow:1}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line]{display:block;position:absolute;top:2.3125em;width:2.9375em;height:.3125em;border-radius:.125em;background-color:#f27474}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}div:where(.swal2-icon).swal2-warning{border-color:#facea8;color:#f8bb86}div:where(.swal2-icon).swal2-warning.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-warning.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .5s}div:where(.swal2-icon).swal2-info{border-color:#9de0f6;color:#3fc3ee}div:where(.swal2-icon).swal2-info.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-info.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .8s}div:where(.swal2-icon).swal2-question{border-color:#c9dae1;color:#87adbd}div:where(.swal2-icon).swal2-question.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-question.swal2-icon-show .swal2-icon-content{animation:swal2-animate-question-mark .8s}div:where(.swal2-icon).swal2-success{border-color:#a5dc86;color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;transform:rotate(45deg);border-radius:50%}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.4375em;left:-2.0635em;transform:rotate(-45deg);transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.6875em;left:1.875em;transform:rotate(-45deg);transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}div:where(.swal2-icon).swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-0.25em;
4303left:-0.25em;box-sizing:content-box;width:100%;height:100%;border:.25em solid rgba(165,220,134,.3);border-radius:50%}div:where(.swal2-icon).swal2-success .swal2-success-fix{position:absolute;z-index:1;top:.5em;left:1.625em;width:.4375em;height:5.625em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line]{display:block;position:absolute;z-index:2;height:.3125em;border-radius:.125em;background-color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=tip]{top:2.875em;left:.8125em;width:1.5625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-success [class^=swal2-success-line][class$=long]{top:2.375em;right:.5em;width:2.9375em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}[class^=swal2]{-webkit-tap-highlight-color:rgba(0,0,0,0)}.swal2-show{animation:swal2-show .3s}.swal2-hide{animation:swal2-hide .15s forwards}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}.swal2-rtl .swal2-close{margin-right:initial;margin-left:0}.swal2-rtl .swal2-timer-progress-bar{right:0;left:auto}@keyframes swal2-toast-show{0%{transform:translateY(-0.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(0.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0deg)}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}
4303}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-0.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}@keyframes swal2-show{0%{transform:scale(0.7)}45%{transform:scale(1.05)}80%{transform:scale(0.95)}100%{transform:scale(1)}}@keyframes swal2-hide{0%{transform:scale(1);opacity:1}100%{transform:scale(0.5);opacity:0}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-0.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(0.4);opacity:0}
430350%{margin-top:1.625em;transform:scale(0.4);opacity:0}80%{margin-top:-0.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0deg);opacity:1}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}@keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@keyframes swal2-animate-i-mark{0%{transform:rotateZ(45deg);opacity:0}25%{transform:rotateZ(-25deg);opacity:.4}50%{transform:rotateZ(15deg);opacity:.8}75%{transform:rotateZ(-5deg);opacity:1}100%{transform:rotateX(0);opacity:1}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto !important}body.swal2-no-backdrop .swal2-container{background-color:rgba(0,0,0,0) !important;pointer-events:none}body.swal2-no-backdrop .swal2-container .swal2-popup{pointer-events:all}body.swal2-no-backdrop .swal2-container .swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll !important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static !important}}body.swal2-toast-shown .swal2-container{box-sizing:border-box;width:360px;max-width:100%;background-color:rgba(0,0,0,0);pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{inset:0 auto auto 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{inset:0 0 auto auto}body.swal2-toast-shown .swal2-container.swal2-top-start,body.swal2-toast-shown .swal2-container.swal2-top-left{inset:0 auto auto 0}body.swal2-toast-shown .swal2-container.swal2-center-start,body.swal2-toast-shown .swal2-container.swal2-center-left{inset:50% auto auto 0;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{inset:50% auto auto 50%;transform:translate(-50%, -50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{inset:50% 0 auto auto;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-start,body.swal2-toast-shown .swal2-container.swal2-bottom-left{inset:auto auto 0 0}body.swal2-toast-shown .swal2-container.swal2-bottom{inset:auto auto 0 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{inset:auto 0 0 auto}");
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.