sweetalert2.all.js 130 KB

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