sweetalert2.all.js 176 KB

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