ChatGPT 阅读模式

🍞 显示一个用于阅读的模态框

当前为 2023-10-29 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name chatgpt-read-mode
  3. // @description 🍞 show a modal for Read
  4. // @author mefengl
  5. // @version 0.0.4
  6. // @namespace https://github.com/mefengl
  7. // @require https://cdn.jsdelivr.net/npm/@mozilla/readability@0.4.3/Readability.min.js
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=openai.com
  9. // @license MIT
  10. // @match *://*/*
  11. // @grant GM_registerMenuCommand
  12.  
  13. // @name:en ChatGPT Read Mode
  14. // @description:en 🍞 Show a modal for Read
  15. // @name:zh-CN ChatGPT 阅读模式
  16. // @description:zh-CN 🍞 显示一个用于阅读的模态框
  17. // @name:es Modo de lectura de ChatGPT
  18. // @description:es 🍞 Mostrar un modal para Leer
  19. // @name:hi ChatGPT पढ़ने का मोड
  20. // @description:hi 🍞 पढ़ने के लिए एक मोडल दिखाएं
  21. // @name:ar وضع القراءة لـ ChatGPT
  22. // @description:ar 🍞 عرض نموذج للقراءة
  23. // @name:pt Modo de leitura do ChatGPT
  24. // @description:pt 🍞 Mostre um modal para Leitura
  25. // @name:ru Режим чтения ChatGPT
  26. // @description:ru 🍞 Показать модальное окно для чтения
  27. // @name:ja ChatGPTの読み取りモード
  28. // @description:ja 🍞 閲覧用のモーダルを表示する
  29. // @name:de ChatGPT-Lesemodus
  30. // @description:de 🍞 Zeigen Sie ein Modal für Lesen an
  31. // @name:fr Mode de lecture ChatGPT
  32. // @description:fr 🍞 Afficher une fenêtre modale pour la lecture
  33. // ==/UserScript==
  34. "use strict";
  35. (() => {
  36. var __create = Object.create;
  37. var __defProp = Object.defineProperty;
  38. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  39. var __getOwnPropNames = Object.getOwnPropertyNames;
  40. var __getProtoOf = Object.getPrototypeOf;
  41. var __hasOwnProp = Object.prototype.hasOwnProperty;
  42. var __commonJS = (cb, mod) => function __require() {
  43. return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
  44. };
  45. var __copyProps = (to, from, except, desc) => {
  46. if (from && typeof from === "object" || typeof from === "function") {
  47. for (let key of __getOwnPropNames(from))
  48. if (!__hasOwnProp.call(to, key) && key !== except)
  49. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  50. }
  51. return to;
  52. };
  53. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  54. // If the importer is in node compatibility mode or this is not an ESM
  55. // file that has been converted to a CommonJS file using a Babel-
  56. // compatible transform (i.e. "__esModule" has not been set), then set
  57. // "default" to the CommonJS "module.exports" for node compatibility.
  58. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  59. mod
  60. ));
  61. var __async = (__this, __arguments, generator) => {
  62. return new Promise((resolve, reject) => {
  63. var fulfilled = (value) => {
  64. try {
  65. step(generator.next(value));
  66. } catch (e) {
  67. reject(e);
  68. }
  69. };
  70. var rejected = (value) => {
  71. try {
  72. step(generator.throw(value));
  73. } catch (e) {
  74. reject(e);
  75. }
  76. };
  77. var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
  78. step((generator = generator.apply(__this, __arguments)).next());
  79. });
  80. };
  81.  
  82. // ../../packages/chatkit/dist/chatgpt/index.js
  83. var require_chatgpt = __commonJS({
  84. "../../packages/chatkit/dist/chatgpt/index.js"(exports, module) {
  85. "use strict";
  86. var __defProp2 = Object.defineProperty;
  87. var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
  88. var __getOwnPropNames2 = Object.getOwnPropertyNames;
  89. var __hasOwnProp2 = Object.prototype.hasOwnProperty;
  90. var __export = (target, all) => {
  91. for (var name in all)
  92. __defProp2(target, name, { get: all[name], enumerable: true });
  93. };
  94. var __copyProps2 = (to, from, except, desc) => {
  95. if (from && typeof from === "object" || typeof from === "function") {
  96. for (let key of __getOwnPropNames2(from))
  97. if (!__hasOwnProp2.call(to, key) && key !== except)
  98. __defProp2(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc2(from, key)) || desc.enumerable });
  99. }
  100. return to;
  101. };
  102. var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
  103. var chatgpt_exports = {};
  104. __export(chatgpt_exports, {
  105. clickFollowUpButton: () => clickFollowUpButton,
  106. getButton: () => getButton,
  107. getContinueGeneratingButton: () => getContinueGeneratingButton,
  108. getConversation: () => getConversation,
  109. getCopyLinkButton: () => getCopyLinkButton,
  110. getFollowUpButtons: () => getFollowUpButtons,
  111. getHistoryBlockTitle: () => getHistoryBlockTitle,
  112. getHistoryBlocks: () => getHistoryBlocks,
  113. getHistoryBlocksWithTitle: () => getHistoryBlocksWithTitle,
  114. getInitialButtons: () => getInitialButtons,
  115. getLastResponse: () => getLastResponse,
  116. getLastResponseElement: () => getLastResponseElement,
  117. getModelSelectButton: () => getModelSelectButton,
  118. getNav: () => getNav,
  119. getNewModelSelectButtons: () => getNewModelSelectButtons,
  120. getRegenerateButton: () => getRegenerateButton,
  121. getResponseElementHTMLs: () => getResponseElementHTMLs2,
  122. getShareChatButton: () => getShareChatButton,
  123. getStopGeneratingButton: () => getStopGeneratingButton,
  124. getSubmitButton: () => getSubmitButton,
  125. getTextarea: () => getTextarea,
  126. getTextareaValue: () => getTextareaValue,
  127. hasNewModelSelectButtons: () => hasNewModelSelectButtons,
  128. isConversationStarted: () => isConversationStarted,
  129. isGenerating: () => isGenerating,
  130. isHorizontalConversation: () => isHorizontalConversation,
  131. onSend: () => onSend,
  132. regenerate: () => regenerate,
  133. send: () => send,
  134. setHorizontalConversation: () => setHorizontalConversation,
  135. setPromptListener: () => setPromptListener,
  136. setPureConversation: () => setPureConversation,
  137. setTextarea: () => setTextarea,
  138. waitForIdle: () => waitForIdle
  139. });
  140. module.exports = __toCommonJS(chatgpt_exports);
  141. function getNav() {
  142. return document.querySelector("nav");
  143. }
  144. function getHistoryBlocks() {
  145. const nav = getNav();
  146. if (!nav)
  147. return [];
  148. const result = Array.from(nav.querySelectorAll("ol")).map((ol) => ol.parentElement);
  149. return result;
  150. }
  151. function getHistoryBlockTitle(historyBlock) {
  152. var _a;
  153. return ((_a = historyBlock.querySelector("h3")) == null ? void 0 : _a.textContent) || "";
  154. }
  155. function getHistoryBlocksWithTitle() {
  156. const historyBlocks = getHistoryBlocks();
  157. const result = historyBlocks.map((historyBlock) => ({
  158. block: historyBlock,
  159. title: getHistoryBlockTitle(historyBlock)
  160. }));
  161. return result;
  162. }
  163. function getTextarea() {
  164. const form = document.querySelector("form");
  165. if (!form)
  166. return;
  167. const textareas = form.querySelectorAll("textarea");
  168. const result = textareas[0];
  169. return result;
  170. }
  171. function getSubmitButton() {
  172. const textarea = getTextarea();
  173. if (!textarea)
  174. return;
  175. return textarea.nextElementSibling;
  176. }
  177. function getInitialButtons() {
  178. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => button.querySelectorAll(".truncate").length === 2);
  179. }
  180. function getFollowUpButtons() {
  181. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  182. var _a;
  183. return (_a = button.textContent) == null ? void 0 : _a.trim().match(/[.!?]$/);
  184. });
  185. }
  186. function clickFollowUpButton(index) {
  187. const followUpButtons = getFollowUpButtons();
  188. if (followUpButtons.length === 0)
  189. return;
  190. if (index === void 0 || index < 0 || index >= followUpButtons.length) {
  191. index = Math.floor(Math.random() * followUpButtons.length);
  192. }
  193. followUpButtons[index].click();
  194. }
  195. function getButton(text) {
  196. return Array.from(document.querySelectorAll('button[as="button"]')).find((button) => {
  197. var _a;
  198. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes(text);
  199. });
  200. }
  201. function getRegenerateButton() {
  202. return getButton("regenerate");
  203. }
  204. function getContinueGeneratingButton() {
  205. return getButton("continue");
  206. }
  207. function getStopGeneratingButton() {
  208. return getButton("stop");
  209. }
  210. function getResponseElementHTMLs2() {
  211. return Array.from(document.querySelectorAll(".markdown")).map((m) => m.innerHTML);
  212. }
  213. function getLastResponseElement() {
  214. const responseElements = document.querySelectorAll(".group.w-full");
  215. return responseElements[responseElements.length - 1];
  216. }
  217. function getLastResponse() {
  218. const lastResponseElement = getLastResponseElement();
  219. if (!lastResponseElement)
  220. return;
  221. const lastResponse = lastResponseElement.textContent;
  222. return lastResponse;
  223. }
  224. function getTextareaValue() {
  225. var _a;
  226. return ((_a = getTextarea()) == null ? void 0 : _a.value) || "";
  227. }
  228. function setTextarea(message) {
  229. const textarea = getTextarea();
  230. if (!textarea)
  231. return;
  232. textarea.value = message;
  233. textarea.dispatchEvent(new Event("input", { bubbles: true }));
  234. }
  235. function send(message) {
  236. return __async(this, null, function* () {
  237. setTextarea(message);
  238. const textarea = getTextarea();
  239. if (!textarea)
  240. return;
  241. while (textarea.value === message) {
  242. textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
  243. yield new Promise((resolve) => setTimeout(resolve, 100));
  244. }
  245. });
  246. }
  247. function regenerate() {
  248. const regenerateButton = getRegenerateButton();
  249. if (!regenerateButton)
  250. return;
  251. regenerateButton.click();
  252. }
  253. function onSend(callback) {
  254. const textarea = getTextarea();
  255. if (!textarea)
  256. return;
  257. textarea.addEventListener("keydown", function(event) {
  258. if (event.key === "Enter" && !event.shiftKey) {
  259. callback();
  260. }
  261. });
  262. const sendButton = getSubmitButton();
  263. if (!sendButton)
  264. return;
  265. sendButton.addEventListener("mousedown", callback);
  266. }
  267. function isGenerating() {
  268. var _a, _b;
  269. return ((_b = (_a = getSubmitButton()) == null ? void 0 : _a.firstElementChild) == null ? void 0 : _b.childElementCount) === 3;
  270. }
  271. function waitForIdle() {
  272. return new Promise((resolve) => {
  273. const interval = setInterval(() => {
  274. if (!isGenerating()) {
  275. clearInterval(interval);
  276. resolve();
  277. }
  278. }, 1e3);
  279. });
  280. }
  281. function setPromptListener(key = "prompt_texts") {
  282. let last_trigger_time = +/* @__PURE__ */ new Date();
  283. if (location.href.includes("chat.openai")) {
  284. GM_addValueChangeListener(key, (name, old_value, new_value) => __async(this, null, function* () {
  285. if (+/* @__PURE__ */ new Date() - last_trigger_time < 500) {
  286. return;
  287. }
  288. last_trigger_time = +/* @__PURE__ */ new Date();
  289. setTimeout(() => __async(this, null, function* () {
  290. var _a, _b;
  291. const prompt_texts = new_value;
  292. const isLong = prompt_texts.length > 60;
  293. if (prompt_texts.length > 0) {
  294. let firstTime = true;
  295. while (true) {
  296. const waitTime = isLong && !document.hasFocus() ? 20 * 1e3 : 2e3;
  297. if (!firstTime) {
  298. yield new Promise((resolve) => setTimeout(resolve, waitTime));
  299. }
  300. if (!firstTime && isGenerating()) {
  301. continue;
  302. } else if (getContinueGeneratingButton()) {
  303. (_a = getContinueGeneratingButton()) == null ? void 0 : _a.click();
  304. continue;
  305. } else if (getRegenerateButton() && !getTextarea()) {
  306. yield new Promise((resolve) => setTimeout(resolve, 10 * 1e3));
  307. (_b = getRegenerateButton()) == null ? void 0 : _b.click();
  308. continue;
  309. }
  310. firstTime = false;
  311. if (prompt_texts.length === 0) {
  312. break;
  313. }
  314. yield send(prompt_texts.shift() || "");
  315. }
  316. }
  317. }), 0);
  318. GM_setValue(key, []);
  319. }));
  320. }
  321. }
  322. function getConversation() {
  323. var _a, _b;
  324. return (_b = (_a = document.querySelector('div[class^="react-scroll-to-bottom"]')) == null ? void 0 : _a.firstChild) == null ? void 0 : _b.firstChild;
  325. }
  326. function getModelSelectButton() {
  327. const conversation = getConversation();
  328. if (!conversation)
  329. return;
  330. return Array.from(conversation.querySelectorAll("button")).find((button) => {
  331. var _a;
  332. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("model");
  333. });
  334. }
  335. function getNewModelSelectButtons() {
  336. return Array.from(document.querySelectorAll("[class^='group/button']"));
  337. }
  338. function hasNewModelSelectButtons() {
  339. return getNewModelSelectButtons().length > 0;
  340. }
  341. function isConversationStarted() {
  342. return !getModelSelectButton();
  343. }
  344. function setPureConversation() {
  345. const conversation = getConversation();
  346. if (!conversation)
  347. return;
  348. const firstChild = conversation.firstChild;
  349. if (!firstChild)
  350. return;
  351. const newDiv = document.createElement("div");
  352. conversation.insertBefore(newDiv, firstChild.nextSibling);
  353. }
  354. function isHorizontalConversation() {
  355. const conversation = getConversation();
  356. if (!conversation)
  357. return true;
  358. if (!isConversationStarted())
  359. return true;
  360. return conversation.classList.contains("grid");
  361. }
  362. function setHorizontalConversation() {
  363. if (isHorizontalConversation())
  364. return;
  365. setPureConversation();
  366. const conversation = getConversation();
  367. if (!conversation)
  368. return;
  369. conversation.classList.remove("flex", "flex-col", "items-center");
  370. conversation.classList.add("grid", "grid-cols-2", "place-items-center");
  371. }
  372. function getShareChatButton() {
  373. return document.querySelector('button[aria-label="Share chat"]');
  374. }
  375. function getCopyLinkButton() {
  376. return Array.from(document.querySelectorAll('button[as="button"]')).filter((button) => {
  377. var _a;
  378. return (_a = button.textContent) == null ? void 0 : _a.trim().toLowerCase().includes("copy link");
  379. })[0];
  380. }
  381. }
  382. });
  383.  
  384. // ../../packages/chatkit/chatgpt.js
  385. var require_chatgpt2 = __commonJS({
  386. "../../packages/chatkit/chatgpt.js"(exports, module) {
  387. module.exports = require_chatgpt();
  388. }
  389. });
  390.  
  391. // ../../node_modules/.pnpm/sweetalert2@11.7.18_patch_hash=f6fyhrnxzcw7s2jwg2q3jn75v4/node_modules/sweetalert2/dist/sweetalert2.all.js
  392. var require_sweetalert2_all = __commonJS({
  393. "../../node_modules/.pnpm/sweetalert2@11.7.18_patch_hash=f6fyhrnxzcw7s2jwg2q3jn75v4/node_modules/sweetalert2/dist/sweetalert2.all.js"(exports, module) {
  394. (function(global, factory) {
  395. typeof exports === "object" && typeof module !== "undefined" ? module.exports = factory() : typeof define === "function" && define.amd ? define(factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, global.Sweetalert2 = factory());
  396. })(exports, function() {
  397. "use strict";
  398. const RESTORE_FOCUS_TIMEOUT = 100;
  399. const globalState = {};
  400. const focusPreviousActiveElement = () => {
  401. if (globalState.previousActiveElement instanceof HTMLElement) {
  402. globalState.previousActiveElement.focus();
  403. globalState.previousActiveElement = null;
  404. } else if (document.body) {
  405. document.body.focus();
  406. }
  407. };
  408. const restoreActiveElement = (returnFocus) => {
  409. return new Promise((resolve) => {
  410. if (!returnFocus) {
  411. return resolve();
  412. }
  413. const x = window.scrollX;
  414. const y = window.scrollY;
  415. globalState.restoreFocusTimeout = setTimeout(() => {
  416. focusPreviousActiveElement();
  417. resolve();
  418. }, RESTORE_FOCUS_TIMEOUT);
  419. window.scrollTo(x, y);
  420. });
  421. };
  422. var privateProps = {
  423. promise: /* @__PURE__ */ new WeakMap(),
  424. innerParams: /* @__PURE__ */ new WeakMap(),
  425. domCache: /* @__PURE__ */ new WeakMap()
  426. };
  427. const swalPrefix = "swal2-";
  428. const classNames = ["container", "shown", "height-auto", "iosfix", "popup", "modal", "no-backdrop", "no-transition", "toast", "toast-shown", "show", "hide", "close", "title", "html-container", "actions", "confirm", "deny", "cancel", "default-outline", "footer", "icon", "icon-content", "image", "input", "file", "range", "select", "radio", "checkbox", "label", "textarea", "inputerror", "input-label", "validation-message", "progress-steps", "active-progress-step", "progress-step", "progress-step-line", "loader", "loading", "styled", "top", "top-start", "top-end", "top-left", "top-right", "center", "center-start", "center-end", "center-left", "center-right", "bottom", "bottom-start", "bottom-end", "bottom-left", "bottom-right", "grow-row", "grow-column", "grow-fullscreen", "rtl", "timer-progress-bar", "timer-progress-bar-container", "scrollbar-measure", "icon-success", "icon-warning", "icon-info", "icon-question", "icon-error"];
  429. const swalClasses = classNames.reduce(
  430. (acc, className) => {
  431. acc[className] = swalPrefix + className;
  432. return acc;
  433. },
  434. /** @type {SwalClasses} */
  435. {}
  436. );
  437. const icons = ["success", "warning", "info", "question", "error"];
  438. const iconTypes = icons.reduce(
  439. (acc, icon) => {
  440. acc[icon] = swalPrefix + icon;
  441. return acc;
  442. },
  443. /** @type {SwalIcons} */
  444. {}
  445. );
  446. const consolePrefix = "SweetAlert2:";
  447. const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
  448. const warn = (message) => {
  449. console.warn(`${consolePrefix} ${typeof message === "object" ? message.join(" ") : message}`);
  450. };
  451. const error = (message) => {
  452. console.error(`${consolePrefix} ${message}`);
  453. };
  454. const previousWarnOnceMessages = [];
  455. const warnOnce = (message) => {
  456. if (!previousWarnOnceMessages.includes(message)) {
  457. previousWarnOnceMessages.push(message);
  458. warn(message);
  459. }
  460. };
  461. const warnAboutDeprecation = (deprecatedParam, useInstead) => {
  462. warnOnce(`"${deprecatedParam}" is deprecated and will be removed in the next major release. Please use "${useInstead}" instead.`);
  463. };
  464. const callIfFunction = (arg) => typeof arg === "function" ? arg() : arg;
  465. const hasToPromiseFn = (arg) => arg && typeof arg.toPromise === "function";
  466. const asPromise = (arg) => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
  467. const isPromise = (arg) => arg && Promise.resolve(arg) === arg;
  468. const getContainer = () => document.body.querySelector(`.${swalClasses.container}`);
  469. const elementBySelector = (selectorString) => {
  470. const container = getContainer();
  471. return container ? container.querySelector(selectorString) : null;
  472. };
  473. const elementByClass = (className) => {
  474. return elementBySelector(`.${className}`);
  475. };
  476. const getPopup = () => elementByClass(swalClasses.popup);
  477. const getIcon = () => elementByClass(swalClasses.icon);
  478. const getIconContent = () => elementByClass(swalClasses["icon-content"]);
  479. const getTitle = () => elementByClass(swalClasses.title);
  480. const getHtmlContainer = () => elementByClass(swalClasses["html-container"]);
  481. const getImage = () => elementByClass(swalClasses.image);
  482. const getProgressSteps = () => elementByClass(swalClasses["progress-steps"]);
  483. const getValidationMessage = () => elementByClass(swalClasses["validation-message"]);
  484. const getConfirmButton = () => (
  485. /** @type {HTMLButtonElement} */
  486. elementBySelector(`.${swalClasses.actions} .${swalClasses.confirm}`)
  487. );
  488. const getCancelButton = () => (
  489. /** @type {HTMLButtonElement} */
  490. elementBySelector(`.${swalClasses.actions} .${swalClasses.cancel}`)
  491. );
  492. const getDenyButton = () => (
  493. /** @type {HTMLButtonElement} */
  494. elementBySelector(`.${swalClasses.actions} .${swalClasses.deny}`)
  495. );
  496. const getInputLabel = () => elementByClass(swalClasses["input-label"]);
  497. const getLoader = () => elementBySelector(`.${swalClasses.loader}`);
  498. const getActions = () => elementByClass(swalClasses.actions);
  499. const getFooter = () => elementByClass(swalClasses.footer);
  500. const getTimerProgressBar = () => elementByClass(swalClasses["timer-progress-bar"]);
  501. const getCloseButton = () => elementByClass(swalClasses.close);
  502. const focusable = `
  503. a[href],
  504. area[href],
  505. input:not([disabled]),
  506. select:not([disabled]),
  507. textarea:not([disabled]),
  508. button:not([disabled]),
  509. iframe,
  510. object,
  511. embed,
  512. [tabindex="0"],
  513. [contenteditable],
  514. audio[controls],
  515. video[controls],
  516. summary
  517. `;
  518. const getFocusableElements = () => {
  519. const popup = getPopup();
  520. if (!popup) {
  521. return [];
  522. }
  523. const focusableElementsWithTabindex = popup.querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])');
  524. const focusableElementsWithTabindexSorted = Array.from(focusableElementsWithTabindex).sort((a, b) => {
  525. const tabindexA = parseInt(a.getAttribute("tabindex") || "0");
  526. const tabindexB = parseInt(b.getAttribute("tabindex") || "0");
  527. if (tabindexA > tabindexB) {
  528. return 1;
  529. } else if (tabindexA < tabindexB) {
  530. return -1;
  531. }
  532. return 0;
  533. });
  534. const otherFocusableElements = popup.querySelectorAll(focusable);
  535. const otherFocusableElementsFiltered = Array.from(otherFocusableElements).filter((el) => el.getAttribute("tabindex") !== "-1");
  536. return [...new Set(focusableElementsWithTabindexSorted.concat(otherFocusableElementsFiltered))].filter((el) => isVisible$1(el));
  537. };
  538. const isModal = () => {
  539. return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses["toast-shown"]) && !hasClass(document.body, swalClasses["no-backdrop"]);
  540. };
  541. const isToast = () => {
  542. const popup = getPopup();
  543. if (!popup) {
  544. return false;
  545. }
  546. return hasClass(popup, swalClasses.toast);
  547. };
  548. const isLoading = () => {
  549. const popup = getPopup();
  550. if (!popup) {
  551. return false;
  552. }
  553. return popup.hasAttribute("data-loading");
  554. };
  555. const setInnerHtml = (elem, html) => {
  556. elem.textContent = "";
  557. if (html) {
  558. const parser = new DOMParser();
  559. const parsed = parser.parseFromString(html, `text/html`);
  560. Array.from(parsed.querySelector("head").childNodes).forEach((child) => {
  561. elem.appendChild(child);
  562. });
  563. Array.from(parsed.querySelector("body").childNodes).forEach((child) => {
  564. if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) {
  565. elem.appendChild(child.cloneNode(true));
  566. } else {
  567. elem.appendChild(child);
  568. }
  569. });
  570. }
  571. };
  572. const hasClass = (elem, className) => {
  573. if (!className) {
  574. return false;
  575. }
  576. const classList = className.split(/\s+/);
  577. for (let i = 0; i < classList.length; i++) {
  578. if (!elem.classList.contains(classList[i])) {
  579. return false;
  580. }
  581. }
  582. return true;
  583. };
  584. const removeCustomClasses = (elem, params) => {
  585. Array.from(elem.classList).forEach((className) => {
  586. if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass).includes(className)) {
  587. elem.classList.remove(className);
  588. }
  589. });
  590. };
  591. const applyCustomClass = (elem, params, className) => {
  592. removeCustomClasses(elem, params);
  593. if (params.customClass && params.customClass[className]) {
  594. if (typeof params.customClass[className] !== "string" && !params.customClass[className].forEach) {
  595. warn(`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof params.customClass[className]}"`);
  596. return;
  597. }
  598. addClass(elem, params.customClass[className]);
  599. }
  600. };
  601. const getInput$1 = (popup, inputClass) => {
  602. if (!inputClass) {
  603. return null;
  604. }
  605. switch (inputClass) {
  606. case "select":
  607. case "textarea":
  608. case "file":
  609. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses[inputClass]}`);
  610. case "checkbox":
  611. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`);
  612. case "radio":
  613. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) || popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`);
  614. case "range":
  615. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`);
  616. default:
  617. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.input}`);
  618. }
  619. };
  620. const focusInput = (input) => {
  621. input.focus();
  622. if (input.type !== "file") {
  623. const val = input.value;
  624. input.value = "";
  625. input.value = val;
  626. }
  627. };
  628. const toggleClass = (target, classList, condition) => {
  629. if (!target || !classList) {
  630. return;
  631. }
  632. if (typeof classList === "string") {
  633. classList = classList.split(/\s+/).filter(Boolean);
  634. }
  635. classList.forEach((className) => {
  636. if (Array.isArray(target)) {
  637. target.forEach((elem) => {
  638. condition ? elem.classList.add(className) : elem.classList.remove(className);
  639. });
  640. } else {
  641. condition ? target.classList.add(className) : target.classList.remove(className);
  642. }
  643. });
  644. };
  645. const addClass = (target, classList) => {
  646. toggleClass(target, classList, true);
  647. };
  648. const removeClass = (target, classList) => {
  649. toggleClass(target, classList, false);
  650. };
  651. const getDirectChildByClass = (elem, className) => {
  652. const children = Array.from(elem.children);
  653. for (let i = 0; i < children.length; i++) {
  654. const child = children[i];
  655. if (child instanceof HTMLElement && hasClass(child, className)) {
  656. return child;
  657. }
  658. }
  659. };
  660. const applyNumericalStyle = (elem, property, value) => {
  661. if (value === `${parseInt(value)}`) {
  662. value = parseInt(value);
  663. }
  664. if (value || parseInt(value) === 0) {
  665. elem.style[property] = typeof value === "number" ? `${value}px` : value;
  666. } else {
  667. elem.style.removeProperty(property);
  668. }
  669. };
  670. const show = function(elem) {
  671. let display = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "flex";
  672. elem && (elem.style.display = display);
  673. };
  674. const hide = (elem) => {
  675. elem && (elem.style.display = "none");
  676. };
  677. const setStyle = (parent, selector, property, value) => {
  678. const el = parent.querySelector(selector);
  679. if (el) {
  680. el.style[property] = value;
  681. }
  682. };
  683. const toggle = function(elem, condition) {
  684. let display = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "flex";
  685. condition ? show(elem, display) : hide(elem);
  686. };
  687. const isVisible$1 = (elem) => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
  688. const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton());
  689. const isScrollable = (elem) => !!(elem.scrollHeight > elem.clientHeight);
  690. const hasCssAnimation = (elem) => {
  691. const style = window.getComputedStyle(elem);
  692. const animDuration = parseFloat(style.getPropertyValue("animation-duration") || "0");
  693. const transDuration = parseFloat(style.getPropertyValue("transition-duration") || "0");
  694. return animDuration > 0 || transDuration > 0;
  695. };
  696. const animateTimerProgressBar = function(timer) {
  697. let reset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  698. const timerProgressBar = getTimerProgressBar();
  699. if (isVisible$1(timerProgressBar)) {
  700. if (reset) {
  701. timerProgressBar.style.transition = "none";
  702. timerProgressBar.style.width = "100%";
  703. }
  704. setTimeout(() => {
  705. timerProgressBar.style.transition = `width ${timer / 1e3}s linear`;
  706. timerProgressBar.style.width = "0%";
  707. }, 10);
  708. }
  709. };
  710. const stopTimerProgressBar = () => {
  711. const timerProgressBar = getTimerProgressBar();
  712. const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  713. timerProgressBar.style.removeProperty("transition");
  714. timerProgressBar.style.width = "100%";
  715. const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  716. const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
  717. timerProgressBar.style.width = `${timerProgressBarPercent}%`;
  718. };
  719. const isNodeEnv = () => typeof window === "undefined" || typeof document === "undefined";
  720. const sweetHTML = `
  721. <div aria-labelledby="${swalClasses.title}" aria-describedby="${swalClasses["html-container"]}" class="${swalClasses.popup}" tabindex="-1">
  722. <button type="button" class="${swalClasses.close}"></button>
  723. <ul class="${swalClasses["progress-steps"]}"></ul>
  724. <div class="${swalClasses.icon}"></div>
  725. <img class="${swalClasses.image}" />
  726. <h2 class="${swalClasses.title}" id="${swalClasses.title}"></h2>
  727. <div class="${swalClasses["html-container"]}" id="${swalClasses["html-container"]}"></div>
  728. <input class="${swalClasses.input}" id="${swalClasses.input}" />
  729. <input type="file" class="${swalClasses.file}" />
  730. <div class="${swalClasses.range}">
  731. <input type="range" />
  732. <output></output>
  733. </div>
  734. <select class="${swalClasses.select}" id="${swalClasses.select}"></select>
  735. <div class="${swalClasses.radio}"></div>
  736. <label class="${swalClasses.checkbox}">
  737. <input type="checkbox" id="${swalClasses.checkbox}" />
  738. <span class="${swalClasses.label}"></span>
  739. </label>
  740. <textarea class="${swalClasses.textarea}" id="${swalClasses.textarea}"></textarea>
  741. <div class="${swalClasses["validation-message"]}" id="${swalClasses["validation-message"]}"></div>
  742. <div class="${swalClasses.actions}">
  743. <div class="${swalClasses.loader}"></div>
  744. <button type="button" class="${swalClasses.confirm}"></button>
  745. <button type="button" class="${swalClasses.deny}"></button>
  746. <button type="button" class="${swalClasses.cancel}"></button>
  747. </div>
  748. <div class="${swalClasses.footer}"></div>
  749. <div class="${swalClasses["timer-progress-bar-container"]}">
  750. <div class="${swalClasses["timer-progress-bar"]}"></div>
  751. </div>
  752. </div>
  753. `.replace(/(^|\n)\s*/g, "");
  754. const resetOldContainer = () => {
  755. const oldContainer = getContainer();
  756. if (!oldContainer) {
  757. return false;
  758. }
  759. oldContainer.remove();
  760. removeClass([document.documentElement, document.body], [swalClasses["no-backdrop"], swalClasses["toast-shown"], swalClasses["has-column"]]);
  761. return true;
  762. };
  763. const resetValidationMessage$1 = () => {
  764. globalState.currentInstance.resetValidationMessage();
  765. };
  766. const addInputChangeListeners = () => {
  767. const popup = getPopup();
  768. const input = getDirectChildByClass(popup, swalClasses.input);
  769. const file = getDirectChildByClass(popup, swalClasses.file);
  770. const range = popup.querySelector(`.${swalClasses.range} input`);
  771. const rangeOutput = popup.querySelector(`.${swalClasses.range} output`);
  772. const select = getDirectChildByClass(popup, swalClasses.select);
  773. const checkbox = popup.querySelector(`.${swalClasses.checkbox} input`);
  774. const textarea = getDirectChildByClass(popup, swalClasses.textarea);
  775. input.oninput = resetValidationMessage$1;
  776. file.onchange = resetValidationMessage$1;
  777. select.onchange = resetValidationMessage$1;
  778. checkbox.onchange = resetValidationMessage$1;
  779. textarea.oninput = resetValidationMessage$1;
  780. range.oninput = () => {
  781. resetValidationMessage$1();
  782. rangeOutput.value = range.value;
  783. };
  784. range.onchange = () => {
  785. resetValidationMessage$1();
  786. rangeOutput.value = range.value;
  787. };
  788. };
  789. const getTarget = (target) => typeof target === "string" ? document.querySelector(target) : target;
  790. const setupAccessibility = (params) => {
  791. const popup = getPopup();
  792. popup.setAttribute("role", params.toast ? "alert" : "dialog");
  793. popup.setAttribute("aria-live", params.toast ? "polite" : "assertive");
  794. if (!params.toast) {
  795. popup.setAttribute("aria-modal", "true");
  796. }
  797. };
  798. const setupRTL = (targetElement) => {
  799. if (window.getComputedStyle(targetElement).direction === "rtl") {
  800. addClass(getContainer(), swalClasses.rtl);
  801. }
  802. };
  803. const init = (params) => {
  804. const oldContainerExisted = resetOldContainer();
  805. if (isNodeEnv()) {
  806. error("SweetAlert2 requires document to initialize");
  807. return;
  808. }
  809. const container = document.createElement("div");
  810. container.className = swalClasses.container;
  811. if (oldContainerExisted) {
  812. addClass(container, swalClasses["no-transition"]);
  813. }
  814. setInnerHtml(container, sweetHTML);
  815. const targetElement = getTarget(params.target);
  816. targetElement.appendChild(container);
  817. setupAccessibility(params);
  818. setupRTL(targetElement);
  819. addInputChangeListeners();
  820. };
  821. const parseHtmlToContainer = (param, target) => {
  822. if (param instanceof HTMLElement) {
  823. target.appendChild(param);
  824. } else if (typeof param === "object") {
  825. handleObject(param, target);
  826. } else if (param) {
  827. setInnerHtml(target, param);
  828. }
  829. };
  830. const handleObject = (param, target) => {
  831. if (param.jquery) {
  832. handleJqueryElem(target, param);
  833. } else {
  834. setInnerHtml(target, param.toString());
  835. }
  836. };
  837. const handleJqueryElem = (target, elem) => {
  838. target.textContent = "";
  839. if (0 in elem) {
  840. for (let i = 0; i in elem; i++) {
  841. target.appendChild(elem[i].cloneNode(true));
  842. }
  843. } else {
  844. target.appendChild(elem.cloneNode(true));
  845. }
  846. };
  847. const animationEndEvent = (() => {
  848. if (isNodeEnv()) {
  849. return false;
  850. }
  851. const testEl = document.createElement("div");
  852. const transEndEventNames = {
  853. WebkitAnimation: "webkitAnimationEnd",
  854. // Chrome, Safari and Opera
  855. animation: "animationend"
  856. // Standard syntax
  857. };
  858. for (const i in transEndEventNames) {
  859. if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== "undefined") {
  860. return transEndEventNames[i];
  861. }
  862. }
  863. return false;
  864. })();
  865. const renderActions = (instance, params) => {
  866. const actions = getActions();
  867. const loader = getLoader();
  868. if (!actions || !loader) {
  869. return;
  870. }
  871. if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
  872. hide(actions);
  873. } else {
  874. show(actions);
  875. }
  876. applyCustomClass(actions, params, "actions");
  877. renderButtons(actions, loader, params);
  878. setInnerHtml(loader, params.loaderHtml || "");
  879. applyCustomClass(loader, params, "loader");
  880. };
  881. function renderButtons(actions, loader, params) {
  882. const confirmButton = getConfirmButton();
  883. const denyButton = getDenyButton();
  884. const cancelButton = getCancelButton();
  885. if (!confirmButton || !denyButton || !cancelButton) {
  886. return;
  887. }
  888. renderButton(confirmButton, "confirm", params);
  889. renderButton(denyButton, "deny", params);
  890. renderButton(cancelButton, "cancel", params);
  891. handleButtonsStyling(confirmButton, denyButton, cancelButton, params);
  892. if (params.reverseButtons) {
  893. if (params.toast) {
  894. actions.insertBefore(cancelButton, confirmButton);
  895. actions.insertBefore(denyButton, confirmButton);
  896. } else {
  897. actions.insertBefore(cancelButton, loader);
  898. actions.insertBefore(denyButton, loader);
  899. actions.insertBefore(confirmButton, loader);
  900. }
  901. }
  902. }
  903. function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
  904. if (!params.buttonsStyling) {
  905. removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
  906. return;
  907. }
  908. addClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
  909. if (params.confirmButtonColor) {
  910. confirmButton.style.backgroundColor = params.confirmButtonColor;
  911. addClass(confirmButton, swalClasses["default-outline"]);
  912. }
  913. if (params.denyButtonColor) {
  914. denyButton.style.backgroundColor = params.denyButtonColor;
  915. addClass(denyButton, swalClasses["default-outline"]);
  916. }
  917. if (params.cancelButtonColor) {
  918. cancelButton.style.backgroundColor = params.cancelButtonColor;
  919. addClass(cancelButton, swalClasses["default-outline"]);
  920. }
  921. }
  922. function renderButton(button, buttonType, params) {
  923. const buttonName = (
  924. /** @type {'Confirm' | 'Deny' | 'Cancel'} */
  925. capitalizeFirstLetter(buttonType)
  926. );
  927. toggle(button, params[`show${buttonName}Button`], "inline-block");
  928. setInnerHtml(button, params[`${buttonType}ButtonText`] || "");
  929. button.setAttribute("aria-label", params[`${buttonType}ButtonAriaLabel`] || "");
  930. button.className = swalClasses[buttonType];
  931. applyCustomClass(button, params, `${buttonType}Button`);
  932. }
  933. const renderCloseButton = (instance, params) => {
  934. const closeButton = getCloseButton();
  935. if (!closeButton) {
  936. return;
  937. }
  938. setInnerHtml(closeButton, params.closeButtonHtml || "");
  939. applyCustomClass(closeButton, params, "closeButton");
  940. toggle(closeButton, params.showCloseButton);
  941. closeButton.setAttribute("aria-label", params.closeButtonAriaLabel || "");
  942. };
  943. const renderContainer = (instance, params) => {
  944. const container = getContainer();
  945. if (!container) {
  946. return;
  947. }
  948. handleBackdropParam(container, params.backdrop);
  949. handlePositionParam(container, params.position);
  950. handleGrowParam(container, params.grow);
  951. applyCustomClass(container, params, "container");
  952. };
  953. function handleBackdropParam(container, backdrop) {
  954. if (typeof backdrop === "string") {
  955. container.style.background = backdrop;
  956. } else if (!backdrop) {
  957. addClass([document.documentElement, document.body], swalClasses["no-backdrop"]);
  958. }
  959. }
  960. function handlePositionParam(container, position) {
  961. if (!position) {
  962. return;
  963. }
  964. if (position in swalClasses) {
  965. addClass(container, swalClasses[position]);
  966. } else {
  967. warn('The "position" parameter is not valid, defaulting to "center"');
  968. addClass(container, swalClasses.center);
  969. }
  970. }
  971. function handleGrowParam(container, grow) {
  972. if (!grow) {
  973. return;
  974. }
  975. addClass(container, swalClasses[`grow-${grow}`]);
  976. }
  977. const inputClasses = ["input", "file", "range", "select", "radio", "checkbox", "textarea"];
  978. const renderInput = (instance, params) => {
  979. const popup = getPopup();
  980. const innerParams = privateProps.innerParams.get(instance);
  981. const rerender = !innerParams || params.input !== innerParams.input;
  982. inputClasses.forEach((inputClass) => {
  983. const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
  984. setAttributes(inputClass, params.inputAttributes);
  985. inputContainer.className = swalClasses[inputClass];
  986. if (rerender) {
  987. hide(inputContainer);
  988. }
  989. });
  990. if (params.input) {
  991. if (rerender) {
  992. showInput(params);
  993. }
  994. setCustomClass(params);
  995. }
  996. };
  997. const showInput = (params) => {
  998. if (!renderInputType[params.input]) {
  999. error(`Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`);
  1000. return;
  1001. }
  1002. const inputContainer = getInputContainer(params.input);
  1003. const input = renderInputType[params.input](inputContainer, params);
  1004. show(inputContainer);
  1005. if (params.inputAutoFocus) {
  1006. setTimeout(() => {
  1007. focusInput(input);
  1008. });
  1009. }
  1010. };
  1011. const removeAttributes = (input) => {
  1012. for (let i = 0; i < input.attributes.length; i++) {
  1013. const attrName = input.attributes[i].name;
  1014. if (!["id", "type", "value", "style"].includes(attrName)) {
  1015. input.removeAttribute(attrName);
  1016. }
  1017. }
  1018. };
  1019. const setAttributes = (inputClass, inputAttributes) => {
  1020. const input = getInput$1(getPopup(), inputClass);
  1021. if (!input) {
  1022. return;
  1023. }
  1024. removeAttributes(input);
  1025. for (const attr in inputAttributes) {
  1026. input.setAttribute(attr, inputAttributes[attr]);
  1027. }
  1028. };
  1029. const setCustomClass = (params) => {
  1030. const inputContainer = getInputContainer(params.input);
  1031. if (typeof params.customClass === "object") {
  1032. addClass(inputContainer, params.customClass.input);
  1033. }
  1034. };
  1035. const setInputPlaceholder = (input, params) => {
  1036. if (!input.placeholder || params.inputPlaceholder) {
  1037. input.placeholder = params.inputPlaceholder;
  1038. }
  1039. };
  1040. const setInputLabel = (input, prependTo, params) => {
  1041. if (params.inputLabel) {
  1042. const label = document.createElement("label");
  1043. const labelClass = swalClasses["input-label"];
  1044. label.setAttribute("for", input.id);
  1045. label.className = labelClass;
  1046. if (typeof params.customClass === "object") {
  1047. addClass(label, params.customClass.inputLabel);
  1048. }
  1049. label.innerText = params.inputLabel;
  1050. prependTo.insertAdjacentElement("beforebegin", label);
  1051. }
  1052. };
  1053. const getInputContainer = (inputType) => {
  1054. return getDirectChildByClass(getPopup(), swalClasses[inputType] || swalClasses.input);
  1055. };
  1056. const checkAndSetInputValue = (input, inputValue) => {
  1057. if (["string", "number"].includes(typeof inputValue)) {
  1058. input.value = `${inputValue}`;
  1059. } else if (!isPromise(inputValue)) {
  1060. warn(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof inputValue}"`);
  1061. }
  1062. };
  1063. const renderInputType = {};
  1064. renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = (input, params) => {
  1065. checkAndSetInputValue(input, params.inputValue);
  1066. setInputLabel(input, input, params);
  1067. setInputPlaceholder(input, params);
  1068. input.type = params.input;
  1069. return input;
  1070. };
  1071. renderInputType.file = (input, params) => {
  1072. setInputLabel(input, input, params);
  1073. setInputPlaceholder(input, params);
  1074. return input;
  1075. };
  1076. renderInputType.range = (range, params) => {
  1077. const rangeInput = range.querySelector("input");
  1078. const rangeOutput = range.querySelector("output");
  1079. checkAndSetInputValue(rangeInput, params.inputValue);
  1080. rangeInput.type = params.input;
  1081. checkAndSetInputValue(rangeOutput, params.inputValue);
  1082. setInputLabel(rangeInput, range, params);
  1083. return range;
  1084. };
  1085. renderInputType.select = (select, params) => {
  1086. select.textContent = "";
  1087. if (params.inputPlaceholder) {
  1088. const placeholder = document.createElement("option");
  1089. setInnerHtml(placeholder, params.inputPlaceholder);
  1090. placeholder.value = "";
  1091. placeholder.disabled = true;
  1092. placeholder.selected = true;
  1093. select.appendChild(placeholder);
  1094. }
  1095. setInputLabel(select, select, params);
  1096. return select;
  1097. };
  1098. renderInputType.radio = (radio) => {
  1099. radio.textContent = "";
  1100. return radio;
  1101. };
  1102. renderInputType.checkbox = (checkboxContainer, params) => {
  1103. const checkbox = getInput$1(getPopup(), "checkbox");
  1104. checkbox.value = "1";
  1105. checkbox.checked = Boolean(params.inputValue);
  1106. const label = checkboxContainer.querySelector("span");
  1107. setInnerHtml(label, params.inputPlaceholder);
  1108. return checkbox;
  1109. };
  1110. renderInputType.textarea = (textarea, params) => {
  1111. checkAndSetInputValue(textarea, params.inputValue);
  1112. setInputPlaceholder(textarea, params);
  1113. setInputLabel(textarea, textarea, params);
  1114. const getMargin = (el) => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight);
  1115. setTimeout(() => {
  1116. if ("MutationObserver" in window) {
  1117. const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
  1118. const textareaResizeHandler = () => {
  1119. if (!document.body.contains(textarea)) {
  1120. return;
  1121. }
  1122. const textareaWidth = textarea.offsetWidth + getMargin(textarea);
  1123. if (textareaWidth > initialPopupWidth) {
  1124. getPopup().style.width = `${textareaWidth}px`;
  1125. } else {
  1126. applyNumericalStyle(getPopup(), "width", params.width);
  1127. }
  1128. };
  1129. new MutationObserver(textareaResizeHandler).observe(textarea, {
  1130. attributes: true,
  1131. attributeFilter: ["style"]
  1132. });
  1133. }
  1134. });
  1135. return textarea;
  1136. };
  1137. const renderContent = (instance, params) => {
  1138. const htmlContainer = getHtmlContainer();
  1139. if (!htmlContainer) {
  1140. return;
  1141. }
  1142. applyCustomClass(htmlContainer, params, "htmlContainer");
  1143. if (params.html) {
  1144. parseHtmlToContainer(params.html, htmlContainer);
  1145. show(htmlContainer, "block");
  1146. } else if (params.text) {
  1147. htmlContainer.textContent = params.text;
  1148. show(htmlContainer, "block");
  1149. } else {
  1150. hide(htmlContainer);
  1151. }
  1152. renderInput(instance, params);
  1153. };
  1154. const renderFooter = (instance, params) => {
  1155. const footer = getFooter();
  1156. if (!footer) {
  1157. return;
  1158. }
  1159. toggle(footer, params.footer);
  1160. if (params.footer) {
  1161. parseHtmlToContainer(params.footer, footer);
  1162. }
  1163. applyCustomClass(footer, params, "footer");
  1164. };
  1165. const renderIcon = (instance, params) => {
  1166. const innerParams = privateProps.innerParams.get(instance);
  1167. const icon = getIcon();
  1168. if (!icon) {
  1169. return;
  1170. }
  1171. if (innerParams && params.icon === innerParams.icon) {
  1172. setContent(icon, params);
  1173. applyStyles(icon, params);
  1174. return;
  1175. }
  1176. if (!params.icon && !params.iconHtml) {
  1177. hide(icon);
  1178. return;
  1179. }
  1180. if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
  1181. error(`Unknown icon! Expected "success", "error", "warning", "info" or "question", got "${params.icon}"`);
  1182. hide(icon);
  1183. return;
  1184. }
  1185. show(icon);
  1186. setContent(icon, params);
  1187. applyStyles(icon, params);
  1188. addClass(icon, params.showClass && params.showClass.icon);
  1189. };
  1190. const applyStyles = (icon, params) => {
  1191. for (const [iconType, iconClassName] of Object.entries(iconTypes)) {
  1192. if (params.icon !== iconType) {
  1193. removeClass(icon, iconClassName);
  1194. }
  1195. }
  1196. addClass(icon, params.icon && iconTypes[params.icon]);
  1197. setColor(icon, params);
  1198. adjustSuccessIconBackgroundColor();
  1199. applyCustomClass(icon, params, "icon");
  1200. };
  1201. const adjustSuccessIconBackgroundColor = () => {
  1202. const popup = getPopup();
  1203. if (!popup) {
  1204. return;
  1205. }
  1206. const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue("background-color");
  1207. const successIconParts = popup.querySelectorAll("[class^=swal2-success-circular-line], .swal2-success-fix");
  1208. for (let i = 0; i < successIconParts.length; i++) {
  1209. successIconParts[i].style.backgroundColor = popupBackgroundColor;
  1210. }
  1211. };
  1212. const successIconHtml = `
  1213. <div class="swal2-success-circular-line-left"></div>
  1214. <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
  1215. <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
  1216. <div class="swal2-success-circular-line-right"></div>
  1217. `;
  1218. const errorIconHtml = `
  1219. <span class="swal2-x-mark">
  1220. <span class="swal2-x-mark-line-left"></span>
  1221. <span class="swal2-x-mark-line-right"></span>
  1222. </span>
  1223. `;
  1224. const setContent = (icon, params) => {
  1225. if (!params.icon) {
  1226. return;
  1227. }
  1228. let oldContent = icon.innerHTML;
  1229. let newContent;
  1230. if (params.iconHtml) {
  1231. newContent = iconContent(params.iconHtml);
  1232. } else if (params.icon === "success") {
  1233. newContent = successIconHtml;
  1234. oldContent = oldContent.replace(/ style=".*?"/g, "");
  1235. } else if (params.icon === "error") {
  1236. newContent = errorIconHtml;
  1237. } else {
  1238. const defaultIconHtml = {
  1239. question: "?",
  1240. warning: "!",
  1241. info: "i"
  1242. };
  1243. newContent = iconContent(defaultIconHtml[params.icon]);
  1244. }
  1245. if (oldContent.trim() !== newContent.trim()) {
  1246. setInnerHtml(icon, newContent);
  1247. }
  1248. };
  1249. const setColor = (icon, params) => {
  1250. if (!params.iconColor) {
  1251. return;
  1252. }
  1253. icon.style.color = params.iconColor;
  1254. icon.style.borderColor = params.iconColor;
  1255. for (const sel of [".swal2-success-line-tip", ".swal2-success-line-long", ".swal2-x-mark-line-left", ".swal2-x-mark-line-right"]) {
  1256. setStyle(icon, sel, "backgroundColor", params.iconColor);
  1257. }
  1258. setStyle(icon, ".swal2-success-ring", "borderColor", params.iconColor);
  1259. };
  1260. const iconContent = (content) => `<div class="${swalClasses["icon-content"]}">${content}</div>`;
  1261. const renderImage = (instance, params) => {
  1262. const image = getImage();
  1263. if (!image) {
  1264. return;
  1265. }
  1266. if (!params.imageUrl) {
  1267. hide(image);
  1268. return;
  1269. }
  1270. show(image, "");
  1271. image.setAttribute("src", params.imageUrl);
  1272. image.setAttribute("alt", params.imageAlt || "");
  1273. applyNumericalStyle(image, "width", params.imageWidth);
  1274. applyNumericalStyle(image, "height", params.imageHeight);
  1275. image.className = swalClasses.image;
  1276. applyCustomClass(image, params, "image");
  1277. };
  1278. const renderPopup = (instance, params) => {
  1279. const container = getContainer();
  1280. const popup = getPopup();
  1281. if (!container || !popup) {
  1282. return;
  1283. }
  1284. if (params.toast) {
  1285. applyNumericalStyle(container, "width", params.width);
  1286. popup.style.width = "100%";
  1287. const loader = getLoader();
  1288. loader && popup.insertBefore(loader, getIcon());
  1289. } else {
  1290. applyNumericalStyle(popup, "width", params.width);
  1291. }
  1292. applyNumericalStyle(popup, "padding", params.padding);
  1293. if (params.color) {
  1294. popup.style.color = params.color;
  1295. }
  1296. if (params.background) {
  1297. popup.style.background = params.background;
  1298. }
  1299. hide(getValidationMessage());
  1300. addClasses$1(popup, params);
  1301. };
  1302. const addClasses$1 = (popup, params) => {
  1303. const showClass = params.showClass || {};
  1304. popup.className = `${swalClasses.popup} ${isVisible$1(popup) ? showClass.popup : ""}`;
  1305. if (params.toast) {
  1306. addClass([document.documentElement, document.body], swalClasses["toast-shown"]);
  1307. addClass(popup, swalClasses.toast);
  1308. } else {
  1309. addClass(popup, swalClasses.modal);
  1310. }
  1311. applyCustomClass(popup, params, "popup");
  1312. if (typeof params.customClass === "string") {
  1313. addClass(popup, params.customClass);
  1314. }
  1315. if (params.icon) {
  1316. addClass(popup, swalClasses[`icon-${params.icon}`]);
  1317. }
  1318. };
  1319. const renderProgressSteps = (instance, params) => {
  1320. const progressStepsContainer = getProgressSteps();
  1321. if (!progressStepsContainer) {
  1322. return;
  1323. }
  1324. const {
  1325. progressSteps,
  1326. currentProgressStep
  1327. } = params;
  1328. if (!progressSteps || progressSteps.length === 0 || currentProgressStep === void 0) {
  1329. hide(progressStepsContainer);
  1330. return;
  1331. }
  1332. show(progressStepsContainer);
  1333. progressStepsContainer.textContent = "";
  1334. if (currentProgressStep >= progressSteps.length) {
  1335. warn("Invalid currentProgressStep parameter, it should be less than progressSteps.length (currentProgressStep like JS arrays starts from 0)");
  1336. }
  1337. progressSteps.forEach((step, index) => {
  1338. const stepEl = createStepElement(step);
  1339. progressStepsContainer.appendChild(stepEl);
  1340. if (index === currentProgressStep) {
  1341. addClass(stepEl, swalClasses["active-progress-step"]);
  1342. }
  1343. if (index !== progressSteps.length - 1) {
  1344. const lineEl = createLineElement(params);
  1345. progressStepsContainer.appendChild(lineEl);
  1346. }
  1347. });
  1348. };
  1349. const createStepElement = (step) => {
  1350. const stepEl = document.createElement("li");
  1351. addClass(stepEl, swalClasses["progress-step"]);
  1352. setInnerHtml(stepEl, step);
  1353. return stepEl;
  1354. };
  1355. const createLineElement = (params) => {
  1356. const lineEl = document.createElement("li");
  1357. addClass(lineEl, swalClasses["progress-step-line"]);
  1358. if (params.progressStepsDistance) {
  1359. applyNumericalStyle(lineEl, "width", params.progressStepsDistance);
  1360. }
  1361. return lineEl;
  1362. };
  1363. const renderTitle = (instance, params) => {
  1364. const title = getTitle();
  1365. if (!title) {
  1366. return;
  1367. }
  1368. toggle(title, params.title || params.titleText, "block");
  1369. if (params.title) {
  1370. parseHtmlToContainer(params.title, title);
  1371. }
  1372. if (params.titleText) {
  1373. title.innerText = params.titleText;
  1374. }
  1375. applyCustomClass(title, params, "title");
  1376. };
  1377. const render = (instance, params) => {
  1378. renderPopup(instance, params);
  1379. renderContainer(instance, params);
  1380. renderProgressSteps(instance, params);
  1381. renderIcon(instance, params);
  1382. renderImage(instance, params);
  1383. renderTitle(instance, params);
  1384. renderCloseButton(instance, params);
  1385. renderContent(instance, params);
  1386. renderActions(instance, params);
  1387. renderFooter(instance, params);
  1388. const popup = getPopup();
  1389. if (typeof params.didRender === "function" && popup) {
  1390. params.didRender(popup);
  1391. }
  1392. };
  1393. const isVisible = () => {
  1394. return isVisible$1(getPopup());
  1395. };
  1396. const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
  1397. const clickDeny = () => getDenyButton() && getDenyButton().click();
  1398. const clickCancel = () => getCancelButton() && getCancelButton().click();
  1399. const DismissReason = Object.freeze({
  1400. cancel: "cancel",
  1401. backdrop: "backdrop",
  1402. close: "close",
  1403. esc: "esc",
  1404. timer: "timer"
  1405. });
  1406. const removeKeydownHandler = (globalState2) => {
  1407. if (globalState2.keydownTarget && globalState2.keydownHandlerAdded) {
  1408. globalState2.keydownTarget.removeEventListener("keydown", globalState2.keydownHandler, {
  1409. capture: globalState2.keydownListenerCapture
  1410. });
  1411. globalState2.keydownHandlerAdded = false;
  1412. }
  1413. };
  1414. const addKeydownHandler = (instance, globalState2, innerParams, dismissWith) => {
  1415. removeKeydownHandler(globalState2);
  1416. if (!innerParams.toast) {
  1417. globalState2.keydownHandler = (e) => keydownHandler(instance, e, dismissWith);
  1418. globalState2.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
  1419. globalState2.keydownListenerCapture = innerParams.keydownListenerCapture;
  1420. globalState2.keydownTarget.addEventListener("keydown", globalState2.keydownHandler, {
  1421. capture: globalState2.keydownListenerCapture
  1422. });
  1423. globalState2.keydownHandlerAdded = true;
  1424. }
  1425. };
  1426. const setFocus = (index, increment) => {
  1427. const focusableElements = getFocusableElements();
  1428. if (focusableElements.length) {
  1429. index = index + increment;
  1430. if (index === focusableElements.length) {
  1431. index = 0;
  1432. } else if (index === -1) {
  1433. index = focusableElements.length - 1;
  1434. }
  1435. focusableElements[index].focus();
  1436. return;
  1437. }
  1438. getPopup().focus();
  1439. };
  1440. const arrowKeysNextButton = ["ArrowRight", "ArrowDown"];
  1441. const arrowKeysPreviousButton = ["ArrowLeft", "ArrowUp"];
  1442. const keydownHandler = (instance, event, dismissWith) => {
  1443. const innerParams = privateProps.innerParams.get(instance);
  1444. if (!innerParams) {
  1445. return;
  1446. }
  1447. if (event.isComposing || event.keyCode === 229) {
  1448. return;
  1449. }
  1450. if (innerParams.stopKeydownPropagation) {
  1451. event.stopPropagation();
  1452. }
  1453. if (event.key === "Enter") {
  1454. handleEnter(instance, event, innerParams);
  1455. } else if (event.key === "Tab") {
  1456. handleTab(event);
  1457. } else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(event.key)) {
  1458. handleArrows(event.key);
  1459. } else if (event.key === "Escape") {
  1460. handleEsc(event, innerParams, dismissWith);
  1461. }
  1462. };
  1463. const handleEnter = (instance, event, innerParams) => {
  1464. if (!callIfFunction(innerParams.allowEnterKey)) {
  1465. return;
  1466. }
  1467. if (event.target && instance.getInput() && event.target instanceof HTMLElement && event.target.outerHTML === instance.getInput().outerHTML) {
  1468. if (["textarea", "file"].includes(innerParams.input)) {
  1469. return;
  1470. }
  1471. clickConfirm();
  1472. event.preventDefault();
  1473. }
  1474. };
  1475. const handleTab = (event) => {
  1476. const targetElement = event.target;
  1477. const focusableElements = getFocusableElements();
  1478. let btnIndex = -1;
  1479. for (let i = 0; i < focusableElements.length; i++) {
  1480. if (targetElement === focusableElements[i]) {
  1481. btnIndex = i;
  1482. break;
  1483. }
  1484. }
  1485. if (!event.shiftKey) {
  1486. setFocus(btnIndex, 1);
  1487. } else {
  1488. setFocus(btnIndex, -1);
  1489. }
  1490. event.stopPropagation();
  1491. event.preventDefault();
  1492. };
  1493. const handleArrows = (key) => {
  1494. const confirmButton = getConfirmButton();
  1495. const denyButton = getDenyButton();
  1496. const cancelButton = getCancelButton();
  1497. const buttons = [confirmButton, denyButton, cancelButton];
  1498. if (document.activeElement instanceof HTMLElement && !buttons.includes(document.activeElement)) {
  1499. return;
  1500. }
  1501. const sibling = arrowKeysNextButton.includes(key) ? "nextElementSibling" : "previousElementSibling";
  1502. let buttonToFocus = document.activeElement;
  1503. for (let i = 0; i < getActions().children.length; i++) {
  1504. buttonToFocus = buttonToFocus[sibling];
  1505. if (!buttonToFocus) {
  1506. return;
  1507. }
  1508. if (buttonToFocus instanceof HTMLButtonElement && isVisible$1(buttonToFocus)) {
  1509. break;
  1510. }
  1511. }
  1512. if (buttonToFocus instanceof HTMLButtonElement) {
  1513. buttonToFocus.focus();
  1514. }
  1515. };
  1516. const handleEsc = (event, innerParams, dismissWith) => {
  1517. if (callIfFunction(innerParams.allowEscapeKey)) {
  1518. event.preventDefault();
  1519. dismissWith(DismissReason.esc);
  1520. }
  1521. };
  1522. var privateMethods = {
  1523. swalPromiseResolve: /* @__PURE__ */ new WeakMap(),
  1524. swalPromiseReject: /* @__PURE__ */ new WeakMap()
  1525. };
  1526. const setAriaHidden = () => {
  1527. const bodyChildren = Array.from(document.body.children);
  1528. bodyChildren.forEach((el) => {
  1529. if (el === getContainer() || el.contains(getContainer())) {
  1530. return;
  1531. }
  1532. if (el.hasAttribute("aria-hidden")) {
  1533. el.setAttribute("data-previous-aria-hidden", el.getAttribute("aria-hidden") || "");
  1534. }
  1535. el.setAttribute("aria-hidden", "true");
  1536. });
  1537. };
  1538. const unsetAriaHidden = () => {
  1539. const bodyChildren = Array.from(document.body.children);
  1540. bodyChildren.forEach((el) => {
  1541. if (el.hasAttribute("data-previous-aria-hidden")) {
  1542. el.setAttribute("aria-hidden", el.getAttribute("data-previous-aria-hidden") || "");
  1543. el.removeAttribute("data-previous-aria-hidden");
  1544. } else {
  1545. el.removeAttribute("aria-hidden");
  1546. }
  1547. });
  1548. };
  1549. const isSafariOrIOS = typeof window !== "undefined" && !!window.GestureEvent;
  1550. const iOSfix = () => {
  1551. if (isSafariOrIOS && !hasClass(document.body, swalClasses.iosfix)) {
  1552. const offset = document.body.scrollTop;
  1553. document.body.style.top = `${offset * -1}px`;
  1554. addClass(document.body, swalClasses.iosfix);
  1555. lockBodyScroll();
  1556. }
  1557. };
  1558. const lockBodyScroll = () => {
  1559. const container = getContainer();
  1560. let preventTouchMove;
  1561. container.ontouchstart = (event) => {
  1562. preventTouchMove = shouldPreventTouchMove(event);
  1563. };
  1564. container.ontouchmove = (event) => {
  1565. if (preventTouchMove) {
  1566. event.preventDefault();
  1567. event.stopPropagation();
  1568. }
  1569. };
  1570. };
  1571. const shouldPreventTouchMove = (event) => {
  1572. const target = event.target;
  1573. const container = getContainer();
  1574. if (isStylus(event) || isZoom(event)) {
  1575. return false;
  1576. }
  1577. if (target === container) {
  1578. return true;
  1579. }
  1580. if (!isScrollable(container) && target instanceof HTMLElement && target.tagName !== "INPUT" && // #1603
  1581. target.tagName !== "TEXTAREA" && // #2266
  1582. !(isScrollable(getHtmlContainer()) && // #1944
  1583. getHtmlContainer().contains(target))) {
  1584. return true;
  1585. }
  1586. return false;
  1587. };
  1588. const isStylus = (event) => {
  1589. return event.touches && event.touches.length && event.touches[0].touchType === "stylus";
  1590. };
  1591. const isZoom = (event) => {
  1592. return event.touches && event.touches.length > 1;
  1593. };
  1594. const undoIOSfix = () => {
  1595. if (hasClass(document.body, swalClasses.iosfix)) {
  1596. const offset = parseInt(document.body.style.top, 10);
  1597. removeClass(document.body, swalClasses.iosfix);
  1598. document.body.style.top = "";
  1599. document.body.scrollTop = offset * -1;
  1600. }
  1601. };
  1602. const measureScrollbar = () => {
  1603. const scrollDiv = document.createElement("div");
  1604. scrollDiv.className = swalClasses["scrollbar-measure"];
  1605. document.body.appendChild(scrollDiv);
  1606. const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
  1607. document.body.removeChild(scrollDiv);
  1608. return scrollbarWidth;
  1609. };
  1610. let previousBodyPadding = null;
  1611. const fixScrollbar = () => {
  1612. if (previousBodyPadding !== null) {
  1613. return;
  1614. }
  1615. if (document.body.scrollHeight > window.innerHeight) {
  1616. previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"));
  1617. document.body.style.paddingRight = `${previousBodyPadding + measureScrollbar()}px`;
  1618. }
  1619. };
  1620. const undoScrollbar = () => {
  1621. if (previousBodyPadding !== null) {
  1622. document.body.style.paddingRight = `${previousBodyPadding}px`;
  1623. previousBodyPadding = null;
  1624. }
  1625. };
  1626. function removePopupAndResetState(instance, container, returnFocus, didClose) {
  1627. if (isToast()) {
  1628. triggerDidCloseAndDispose(instance, didClose);
  1629. } else {
  1630. restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
  1631. removeKeydownHandler(globalState);
  1632. }
  1633. if (isSafariOrIOS) {
  1634. container.setAttribute("style", "display:none !important");
  1635. container.removeAttribute("class");
  1636. container.innerHTML = "";
  1637. } else {
  1638. container.remove();
  1639. }
  1640. if (isModal()) {
  1641. undoScrollbar();
  1642. undoIOSfix();
  1643. unsetAriaHidden();
  1644. }
  1645. removeBodyClasses();
  1646. }
  1647. function removeBodyClasses() {
  1648. removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses["height-auto"], swalClasses["no-backdrop"], swalClasses["toast-shown"]]);
  1649. }
  1650. function close(resolveValue) {
  1651. resolveValue = prepareResolveValue(resolveValue);
  1652. const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
  1653. const didClose = triggerClosePopup(this);
  1654. if (this.isAwaitingPromise) {
  1655. if (!resolveValue.isDismissed) {
  1656. handleAwaitingPromise(this);
  1657. swalPromiseResolve(resolveValue);
  1658. }
  1659. } else if (didClose) {
  1660. swalPromiseResolve(resolveValue);
  1661. }
  1662. }
  1663. const triggerClosePopup = (instance) => {
  1664. const popup = getPopup();
  1665. if (!popup) {
  1666. return false;
  1667. }
  1668. const innerParams = privateProps.innerParams.get(instance);
  1669. if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
  1670. return false;
  1671. }
  1672. removeClass(popup, innerParams.showClass.popup);
  1673. addClass(popup, innerParams.hideClass.popup);
  1674. const backdrop = getContainer();
  1675. removeClass(backdrop, innerParams.showClass.backdrop);
  1676. addClass(backdrop, innerParams.hideClass.backdrop);
  1677. handlePopupAnimation(instance, popup, innerParams);
  1678. return true;
  1679. };
  1680. function rejectPromise(error2) {
  1681. const rejectPromise2 = privateMethods.swalPromiseReject.get(this);
  1682. handleAwaitingPromise(this);
  1683. if (rejectPromise2) {
  1684. rejectPromise2(error2);
  1685. }
  1686. }
  1687. const handleAwaitingPromise = (instance) => {
  1688. if (instance.isAwaitingPromise) {
  1689. delete instance.isAwaitingPromise;
  1690. if (!privateProps.innerParams.get(instance)) {
  1691. instance._destroy();
  1692. }
  1693. }
  1694. };
  1695. const prepareResolveValue = (resolveValue) => {
  1696. if (typeof resolveValue === "undefined") {
  1697. return {
  1698. isConfirmed: false,
  1699. isDenied: false,
  1700. isDismissed: true
  1701. };
  1702. }
  1703. return Object.assign({
  1704. isConfirmed: false,
  1705. isDenied: false,
  1706. isDismissed: false
  1707. }, resolveValue);
  1708. };
  1709. const handlePopupAnimation = (instance, popup, innerParams) => {
  1710. const container = getContainer();
  1711. const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
  1712. if (typeof innerParams.willClose === "function") {
  1713. innerParams.willClose(popup);
  1714. }
  1715. if (animationIsSupported) {
  1716. animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
  1717. } else {
  1718. removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
  1719. }
  1720. };
  1721. const animatePopup = (instance, popup, container, returnFocus, didClose) => {
  1722. globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
  1723. popup.addEventListener(animationEndEvent, function(e) {
  1724. if (e.target === popup) {
  1725. globalState.swalCloseEventFinishedCallback();
  1726. delete globalState.swalCloseEventFinishedCallback;
  1727. }
  1728. });
  1729. };
  1730. const triggerDidCloseAndDispose = (instance, didClose) => {
  1731. setTimeout(() => {
  1732. if (typeof didClose === "function") {
  1733. didClose.bind(instance.params)();
  1734. }
  1735. if (instance._destroy) {
  1736. instance._destroy();
  1737. }
  1738. });
  1739. };
  1740. const showLoading = (buttonToReplace) => {
  1741. let popup = getPopup();
  1742. if (!popup) {
  1743. new Swal2();
  1744. }
  1745. popup = getPopup();
  1746. const loader = getLoader();
  1747. if (isToast()) {
  1748. hide(getIcon());
  1749. } else {
  1750. replaceButton(popup, buttonToReplace);
  1751. }
  1752. show(loader);
  1753. popup.setAttribute("data-loading", "true");
  1754. popup.setAttribute("aria-busy", "true");
  1755. popup.focus();
  1756. };
  1757. const replaceButton = (popup, buttonToReplace) => {
  1758. const actions = getActions();
  1759. const loader = getLoader();
  1760. if (!buttonToReplace && isVisible$1(getConfirmButton())) {
  1761. buttonToReplace = getConfirmButton();
  1762. }
  1763. show(actions);
  1764. if (buttonToReplace) {
  1765. hide(buttonToReplace);
  1766. loader.setAttribute("data-button-to-replace", buttonToReplace.className);
  1767. }
  1768. loader.parentNode.insertBefore(loader, buttonToReplace);
  1769. addClass([popup, actions], swalClasses.loading);
  1770. };
  1771. const handleInputOptionsAndValue = (instance, params) => {
  1772. if (params.input === "select" || params.input === "radio") {
  1773. handleInputOptions(instance, params);
  1774. } else if (["text", "email", "number", "tel", "textarea"].includes(params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
  1775. showLoading(getConfirmButton());
  1776. handleInputValue(instance, params);
  1777. }
  1778. };
  1779. const getInputValue = (instance, innerParams) => {
  1780. const input = instance.getInput();
  1781. if (!input) {
  1782. return null;
  1783. }
  1784. switch (innerParams.input) {
  1785. case "checkbox":
  1786. return getCheckboxValue(input);
  1787. case "radio":
  1788. return getRadioValue(input);
  1789. case "file":
  1790. return getFileValue(input);
  1791. default:
  1792. return innerParams.inputAutoTrim ? input.value.trim() : input.value;
  1793. }
  1794. };
  1795. const getCheckboxValue = (input) => input.checked ? 1 : 0;
  1796. const getRadioValue = (input) => input.checked ? input.value : null;
  1797. const getFileValue = (input) => input.files.length ? input.getAttribute("multiple") !== null ? input.files : input.files[0] : null;
  1798. const handleInputOptions = (instance, params) => {
  1799. const popup = getPopup();
  1800. const processInputOptions = (inputOptions) => {
  1801. populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
  1802. };
  1803. if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
  1804. showLoading(getConfirmButton());
  1805. asPromise(params.inputOptions).then((inputOptions) => {
  1806. instance.hideLoading();
  1807. processInputOptions(inputOptions);
  1808. });
  1809. } else if (typeof params.inputOptions === "object") {
  1810. processInputOptions(params.inputOptions);
  1811. } else {
  1812. error(`Unexpected type of inputOptions! Expected object, Map or Promise, got ${typeof params.inputOptions}`);
  1813. }
  1814. };
  1815. const handleInputValue = (instance, params) => {
  1816. const input = instance.getInput();
  1817. hide(input);
  1818. asPromise(params.inputValue).then((inputValue) => {
  1819. input.value = params.input === "number" ? `${parseFloat(inputValue) || 0}` : `${inputValue}`;
  1820. show(input);
  1821. input.focus();
  1822. instance.hideLoading();
  1823. }).catch((err) => {
  1824. error(`Error in inputValue promise: ${err}`);
  1825. input.value = "";
  1826. show(input);
  1827. input.focus();
  1828. instance.hideLoading();
  1829. });
  1830. };
  1831. const populateInputOptions = {
  1832. /**
  1833. * @param {HTMLElement} popup
  1834. * @param {Record<string, any>} inputOptions
  1835. * @param {SweetAlertOptions} params
  1836. */
  1837. select: (popup, inputOptions, params) => {
  1838. const select = getDirectChildByClass(popup, swalClasses.select);
  1839. const renderOption = (parent, optionLabel, optionValue) => {
  1840. const option = document.createElement("option");
  1841. option.value = optionValue;
  1842. setInnerHtml(option, optionLabel);
  1843. option.selected = isSelected(optionValue, params.inputValue);
  1844. parent.appendChild(option);
  1845. };
  1846. inputOptions.forEach((inputOption) => {
  1847. const optionValue = inputOption[0];
  1848. const optionLabel = inputOption[1];
  1849. if (Array.isArray(optionLabel)) {
  1850. const optgroup = document.createElement("optgroup");
  1851. optgroup.label = optionValue;
  1852. optgroup.disabled = false;
  1853. select.appendChild(optgroup);
  1854. optionLabel.forEach((o) => renderOption(optgroup, o[1], o[0]));
  1855. } else {
  1856. renderOption(select, optionLabel, optionValue);
  1857. }
  1858. });
  1859. select.focus();
  1860. },
  1861. /**
  1862. * @param {HTMLElement} popup
  1863. * @param {Record<string, any>} inputOptions
  1864. * @param {SweetAlertOptions} params
  1865. */
  1866. radio: (popup, inputOptions, params) => {
  1867. const radio = getDirectChildByClass(popup, swalClasses.radio);
  1868. inputOptions.forEach((inputOption) => {
  1869. const radioValue = inputOption[0];
  1870. const radioLabel = inputOption[1];
  1871. const radioInput = document.createElement("input");
  1872. const radioLabelElement = document.createElement("label");
  1873. radioInput.type = "radio";
  1874. radioInput.name = swalClasses.radio;
  1875. radioInput.value = radioValue;
  1876. if (isSelected(radioValue, params.inputValue)) {
  1877. radioInput.checked = true;
  1878. }
  1879. const label = document.createElement("span");
  1880. setInnerHtml(label, radioLabel);
  1881. label.className = swalClasses.label;
  1882. radioLabelElement.appendChild(radioInput);
  1883. radioLabelElement.appendChild(label);
  1884. radio.appendChild(radioLabelElement);
  1885. });
  1886. const radios = radio.querySelectorAll("input");
  1887. if (radios.length) {
  1888. radios[0].focus();
  1889. }
  1890. }
  1891. };
  1892. const formatInputOptions = (inputOptions) => {
  1893. const result = [];
  1894. if (typeof Map !== "undefined" && inputOptions instanceof Map) {
  1895. inputOptions.forEach((value, key) => {
  1896. let valueFormatted = value;
  1897. if (typeof valueFormatted === "object") {
  1898. valueFormatted = formatInputOptions(valueFormatted);
  1899. }
  1900. result.push([key, valueFormatted]);
  1901. });
  1902. } else {
  1903. Object.keys(inputOptions).forEach((key) => {
  1904. let valueFormatted = inputOptions[key];
  1905. if (typeof valueFormatted === "object") {
  1906. valueFormatted = formatInputOptions(valueFormatted);
  1907. }
  1908. result.push([key, valueFormatted]);
  1909. });
  1910. }
  1911. return result;
  1912. };
  1913. const isSelected = (optionValue, inputValue) => {
  1914. return inputValue && inputValue.toString() === optionValue.toString();
  1915. };
  1916. const handleConfirmButtonClick = (instance) => {
  1917. const innerParams = privateProps.innerParams.get(instance);
  1918. instance.disableButtons();
  1919. if (innerParams.input) {
  1920. handleConfirmOrDenyWithInput(instance, "confirm");
  1921. } else {
  1922. confirm(instance, true);
  1923. }
  1924. };
  1925. const handleDenyButtonClick = (instance) => {
  1926. const innerParams = privateProps.innerParams.get(instance);
  1927. instance.disableButtons();
  1928. if (innerParams.returnInputValueOnDeny) {
  1929. handleConfirmOrDenyWithInput(instance, "deny");
  1930. } else {
  1931. deny(instance, false);
  1932. }
  1933. };
  1934. const handleCancelButtonClick = (instance, dismissWith) => {
  1935. instance.disableButtons();
  1936. dismissWith(DismissReason.cancel);
  1937. };
  1938. const handleConfirmOrDenyWithInput = (instance, type) => {
  1939. const innerParams = privateProps.innerParams.get(instance);
  1940. if (!innerParams.input) {
  1941. error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`);
  1942. return;
  1943. }
  1944. const inputValue = getInputValue(instance, innerParams);
  1945. if (innerParams.inputValidator) {
  1946. handleInputValidator(instance, inputValue, type);
  1947. } else if (!instance.getInput().checkValidity()) {
  1948. instance.enableButtons();
  1949. instance.showValidationMessage(innerParams.validationMessage);
  1950. } else if (type === "deny") {
  1951. deny(instance, inputValue);
  1952. } else {
  1953. confirm(instance, inputValue);
  1954. }
  1955. };
  1956. const handleInputValidator = (instance, inputValue, type) => {
  1957. const innerParams = privateProps.innerParams.get(instance);
  1958. instance.disableInput();
  1959. const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
  1960. validationPromise.then((validationMessage) => {
  1961. instance.enableButtons();
  1962. instance.enableInput();
  1963. if (validationMessage) {
  1964. instance.showValidationMessage(validationMessage);
  1965. } else if (type === "deny") {
  1966. deny(instance, inputValue);
  1967. } else {
  1968. confirm(instance, inputValue);
  1969. }
  1970. });
  1971. };
  1972. const deny = (instance, value) => {
  1973. const innerParams = privateProps.innerParams.get(instance || void 0);
  1974. if (innerParams.showLoaderOnDeny) {
  1975. showLoading(getDenyButton());
  1976. }
  1977. if (innerParams.preDeny) {
  1978. instance.isAwaitingPromise = true;
  1979. const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
  1980. preDenyPromise.then((preDenyValue) => {
  1981. if (preDenyValue === false) {
  1982. instance.hideLoading();
  1983. handleAwaitingPromise(instance);
  1984. } else {
  1985. instance.close({
  1986. isDenied: true,
  1987. value: typeof preDenyValue === "undefined" ? value : preDenyValue
  1988. });
  1989. }
  1990. }).catch((error2) => rejectWith(instance || void 0, error2));
  1991. } else {
  1992. instance.close({
  1993. isDenied: true,
  1994. value
  1995. });
  1996. }
  1997. };
  1998. const succeedWith = (instance, value) => {
  1999. instance.close({
  2000. isConfirmed: true,
  2001. value
  2002. });
  2003. };
  2004. const rejectWith = (instance, error2) => {
  2005. instance.rejectPromise(error2);
  2006. };
  2007. const confirm = (instance, value) => {
  2008. const innerParams = privateProps.innerParams.get(instance || void 0);
  2009. if (innerParams.showLoaderOnConfirm) {
  2010. showLoading();
  2011. }
  2012. if (innerParams.preConfirm) {
  2013. instance.resetValidationMessage();
  2014. instance.isAwaitingPromise = true;
  2015. const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
  2016. preConfirmPromise.then((preConfirmValue) => {
  2017. if (isVisible$1(getValidationMessage()) || preConfirmValue === false) {
  2018. instance.hideLoading();
  2019. handleAwaitingPromise(instance);
  2020. } else {
  2021. succeedWith(instance, typeof preConfirmValue === "undefined" ? value : preConfirmValue);
  2022. }
  2023. }).catch((error2) => rejectWith(instance || void 0, error2));
  2024. } else {
  2025. succeedWith(instance, value);
  2026. }
  2027. };
  2028. function hideLoading() {
  2029. const innerParams = privateProps.innerParams.get(this);
  2030. if (!innerParams) {
  2031. return;
  2032. }
  2033. const domCache = privateProps.domCache.get(this);
  2034. hide(domCache.loader);
  2035. if (isToast()) {
  2036. if (innerParams.icon) {
  2037. show(getIcon());
  2038. }
  2039. } else {
  2040. showRelatedButton(domCache);
  2041. }
  2042. removeClass([domCache.popup, domCache.actions], swalClasses.loading);
  2043. domCache.popup.removeAttribute("aria-busy");
  2044. domCache.popup.removeAttribute("data-loading");
  2045. domCache.confirmButton.disabled = false;
  2046. domCache.denyButton.disabled = false;
  2047. domCache.cancelButton.disabled = false;
  2048. }
  2049. const showRelatedButton = (domCache) => {
  2050. const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute("data-button-to-replace"));
  2051. if (buttonToReplace.length) {
  2052. show(buttonToReplace[0], "inline-block");
  2053. } else if (allButtonsAreHidden()) {
  2054. hide(domCache.actions);
  2055. }
  2056. };
  2057. function getInput() {
  2058. const innerParams = privateProps.innerParams.get(this);
  2059. const domCache = privateProps.domCache.get(this);
  2060. if (!domCache) {
  2061. return null;
  2062. }
  2063. return getInput$1(domCache.popup, innerParams.input);
  2064. }
  2065. function setButtonsDisabled(instance, buttons, disabled) {
  2066. const domCache = privateProps.domCache.get(instance);
  2067. buttons.forEach((button) => {
  2068. domCache[button].disabled = disabled;
  2069. });
  2070. }
  2071. function setInputDisabled(input, disabled) {
  2072. if (!input) {
  2073. return;
  2074. }
  2075. if (input.type === "radio") {
  2076. const radiosContainer = input.parentNode.parentNode;
  2077. const radios = radiosContainer.querySelectorAll("input");
  2078. for (let i = 0; i < radios.length; i++) {
  2079. radios[i].disabled = disabled;
  2080. }
  2081. } else {
  2082. input.disabled = disabled;
  2083. }
  2084. }
  2085. function enableButtons() {
  2086. setButtonsDisabled(this, ["confirmButton", "denyButton", "cancelButton"], false);
  2087. }
  2088. function disableButtons() {
  2089. setButtonsDisabled(this, ["confirmButton", "denyButton", "cancelButton"], true);
  2090. }
  2091. function enableInput() {
  2092. setInputDisabled(this.getInput(), false);
  2093. }
  2094. function disableInput() {
  2095. setInputDisabled(this.getInput(), true);
  2096. }
  2097. function showValidationMessage(error2) {
  2098. const domCache = privateProps.domCache.get(this);
  2099. const params = privateProps.innerParams.get(this);
  2100. setInnerHtml(domCache.validationMessage, error2);
  2101. domCache.validationMessage.className = swalClasses["validation-message"];
  2102. if (params.customClass && params.customClass.validationMessage) {
  2103. addClass(domCache.validationMessage, params.customClass.validationMessage);
  2104. }
  2105. show(domCache.validationMessage);
  2106. const input = this.getInput();
  2107. if (input) {
  2108. input.setAttribute("aria-invalid", true);
  2109. input.setAttribute("aria-describedby", swalClasses["validation-message"]);
  2110. focusInput(input);
  2111. addClass(input, swalClasses.inputerror);
  2112. }
  2113. }
  2114. function resetValidationMessage() {
  2115. const domCache = privateProps.domCache.get(this);
  2116. if (domCache.validationMessage) {
  2117. hide(domCache.validationMessage);
  2118. }
  2119. const input = this.getInput();
  2120. if (input) {
  2121. input.removeAttribute("aria-invalid");
  2122. input.removeAttribute("aria-describedby");
  2123. removeClass(input, swalClasses.inputerror);
  2124. }
  2125. }
  2126. const defaultParams = {
  2127. title: "",
  2128. titleText: "",
  2129. text: "",
  2130. html: "",
  2131. footer: "",
  2132. icon: void 0,
  2133. iconColor: void 0,
  2134. iconHtml: void 0,
  2135. template: void 0,
  2136. toast: false,
  2137. showClass: {
  2138. popup: "swal2-show",
  2139. backdrop: "swal2-backdrop-show",
  2140. icon: "swal2-icon-show"
  2141. },
  2142. hideClass: {
  2143. popup: "swal2-hide",
  2144. backdrop: "swal2-backdrop-hide",
  2145. icon: "swal2-icon-hide"
  2146. },
  2147. customClass: {},
  2148. target: "body",
  2149. color: void 0,
  2150. backdrop: true,
  2151. heightAuto: true,
  2152. allowOutsideClick: true,
  2153. allowEscapeKey: true,
  2154. allowEnterKey: true,
  2155. stopKeydownPropagation: true,
  2156. keydownListenerCapture: false,
  2157. showConfirmButton: true,
  2158. showDenyButton: false,
  2159. showCancelButton: false,
  2160. preConfirm: void 0,
  2161. preDeny: void 0,
  2162. confirmButtonText: "OK",
  2163. confirmButtonAriaLabel: "",
  2164. confirmButtonColor: void 0,
  2165. denyButtonText: "No",
  2166. denyButtonAriaLabel: "",
  2167. denyButtonColor: void 0,
  2168. cancelButtonText: "Cancel",
  2169. cancelButtonAriaLabel: "",
  2170. cancelButtonColor: void 0,
  2171. buttonsStyling: true,
  2172. reverseButtons: false,
  2173. focusConfirm: true,
  2174. focusDeny: false,
  2175. focusCancel: false,
  2176. returnFocus: true,
  2177. showCloseButton: false,
  2178. closeButtonHtml: "&times;",
  2179. closeButtonAriaLabel: "Close this dialog",
  2180. loaderHtml: "",
  2181. showLoaderOnConfirm: false,
  2182. showLoaderOnDeny: false,
  2183. imageUrl: void 0,
  2184. imageWidth: void 0,
  2185. imageHeight: void 0,
  2186. imageAlt: "",
  2187. timer: void 0,
  2188. timerProgressBar: false,
  2189. width: void 0,
  2190. padding: void 0,
  2191. background: void 0,
  2192. input: void 0,
  2193. inputPlaceholder: "",
  2194. inputLabel: "",
  2195. inputValue: "",
  2196. inputOptions: {},
  2197. inputAutoFocus: true,
  2198. inputAutoTrim: true,
  2199. inputAttributes: {},
  2200. inputValidator: void 0,
  2201. returnInputValueOnDeny: false,
  2202. validationMessage: void 0,
  2203. grow: false,
  2204. position: "center",
  2205. progressSteps: [],
  2206. currentProgressStep: void 0,
  2207. progressStepsDistance: void 0,
  2208. willOpen: void 0,
  2209. didOpen: void 0,
  2210. didRender: void 0,
  2211. willClose: void 0,
  2212. didClose: void 0,
  2213. didDestroy: void 0,
  2214. scrollbarPadding: true
  2215. };
  2216. const updatableParams = ["allowEscapeKey", "allowOutsideClick", "background", "buttonsStyling", "cancelButtonAriaLabel", "cancelButtonColor", "cancelButtonText", "closeButtonAriaLabel", "closeButtonHtml", "color", "confirmButtonAriaLabel", "confirmButtonColor", "confirmButtonText", "currentProgressStep", "customClass", "denyButtonAriaLabel", "denyButtonColor", "denyButtonText", "didClose", "didDestroy", "footer", "hideClass", "html", "icon", "iconColor", "iconHtml", "imageAlt", "imageHeight", "imageUrl", "imageWidth", "preConfirm", "preDeny", "progressSteps", "returnFocus", "reverseButtons", "showCancelButton", "showCloseButton", "showConfirmButton", "showDenyButton", "text", "title", "titleText", "willClose"];
  2217. const deprecatedParams = {};
  2218. const toastIncompatibleParams = ["allowOutsideClick", "allowEnterKey", "backdrop", "focusConfirm", "focusDeny", "focusCancel", "returnFocus", "heightAuto", "keydownListenerCapture"];
  2219. const isValidParameter = (paramName) => {
  2220. return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
  2221. };
  2222. const isUpdatableParameter = (paramName) => {
  2223. return updatableParams.indexOf(paramName) !== -1;
  2224. };
  2225. const isDeprecatedParameter = (paramName) => {
  2226. return deprecatedParams[paramName];
  2227. };
  2228. const checkIfParamIsValid = (param) => {
  2229. if (!isValidParameter(param)) {
  2230. warn(`Unknown parameter "${param}"`);
  2231. }
  2232. };
  2233. const checkIfToastParamIsValid = (param) => {
  2234. if (toastIncompatibleParams.includes(param)) {
  2235. warn(`The parameter "${param}" is incompatible with toasts`);
  2236. }
  2237. };
  2238. const checkIfParamIsDeprecated = (param) => {
  2239. const isDeprecated = isDeprecatedParameter(param);
  2240. if (isDeprecated) {
  2241. warnAboutDeprecation(param, isDeprecated);
  2242. }
  2243. };
  2244. const showWarningsForParams = (params) => {
  2245. if (params.backdrop === false && params.allowOutsideClick) {
  2246. warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
  2247. }
  2248. for (const param in params) {
  2249. checkIfParamIsValid(param);
  2250. if (params.toast) {
  2251. checkIfToastParamIsValid(param);
  2252. }
  2253. checkIfParamIsDeprecated(param);
  2254. }
  2255. };
  2256. function update(params) {
  2257. const popup = getPopup();
  2258. const innerParams = privateProps.innerParams.get(this);
  2259. if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
  2260. 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.`);
  2261. return;
  2262. }
  2263. const validUpdatableParams = filterValidParams(params);
  2264. const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
  2265. render(this, updatedParams);
  2266. privateProps.innerParams.set(this, updatedParams);
  2267. Object.defineProperties(this, {
  2268. params: {
  2269. value: Object.assign({}, this.params, params),
  2270. writable: false,
  2271. enumerable: true
  2272. }
  2273. });
  2274. }
  2275. const filterValidParams = (params) => {
  2276. const validUpdatableParams = {};
  2277. Object.keys(params).forEach((param) => {
  2278. if (isUpdatableParameter(param)) {
  2279. validUpdatableParams[param] = params[param];
  2280. } else {
  2281. warn(`Invalid parameter to update: ${param}`);
  2282. }
  2283. });
  2284. return validUpdatableParams;
  2285. };
  2286. function _destroy() {
  2287. const domCache = privateProps.domCache.get(this);
  2288. const innerParams = privateProps.innerParams.get(this);
  2289. if (!innerParams) {
  2290. disposeWeakMaps(this);
  2291. return;
  2292. }
  2293. if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
  2294. globalState.swalCloseEventFinishedCallback();
  2295. delete globalState.swalCloseEventFinishedCallback;
  2296. }
  2297. if (typeof innerParams.didDestroy === "function") {
  2298. innerParams.didDestroy();
  2299. }
  2300. disposeSwal(this);
  2301. }
  2302. const disposeSwal = (instance) => {
  2303. disposeWeakMaps(instance);
  2304. delete instance.params;
  2305. delete globalState.keydownHandler;
  2306. delete globalState.keydownTarget;
  2307. delete globalState.currentInstance;
  2308. };
  2309. const disposeWeakMaps = (instance) => {
  2310. if (instance.isAwaitingPromise) {
  2311. unsetWeakMaps(privateProps, instance);
  2312. instance.isAwaitingPromise = true;
  2313. } else {
  2314. unsetWeakMaps(privateMethods, instance);
  2315. unsetWeakMaps(privateProps, instance);
  2316. delete instance.isAwaitingPromise;
  2317. delete instance.disableButtons;
  2318. delete instance.enableButtons;
  2319. delete instance.getInput;
  2320. delete instance.disableInput;
  2321. delete instance.enableInput;
  2322. delete instance.hideLoading;
  2323. delete instance.disableLoading;
  2324. delete instance.showValidationMessage;
  2325. delete instance.resetValidationMessage;
  2326. delete instance.close;
  2327. delete instance.closePopup;
  2328. delete instance.closeModal;
  2329. delete instance.closeToast;
  2330. delete instance.rejectPromise;
  2331. delete instance.update;
  2332. delete instance._destroy;
  2333. }
  2334. };
  2335. const unsetWeakMaps = (obj, instance) => {
  2336. for (const i in obj) {
  2337. obj[i].delete(instance);
  2338. }
  2339. };
  2340. var instanceMethods = /* @__PURE__ */ Object.freeze({
  2341. __proto__: null,
  2342. _destroy,
  2343. close,
  2344. closeModal: close,
  2345. closePopup: close,
  2346. closeToast: close,
  2347. disableButtons,
  2348. disableInput,
  2349. disableLoading: hideLoading,
  2350. enableButtons,
  2351. enableInput,
  2352. getInput,
  2353. handleAwaitingPromise,
  2354. hideLoading,
  2355. rejectPromise,
  2356. resetValidationMessage,
  2357. showValidationMessage,
  2358. update
  2359. });
  2360. const handlePopupClick = (instance, domCache, dismissWith) => {
  2361. const innerParams = privateProps.innerParams.get(instance);
  2362. if (innerParams.toast) {
  2363. handleToastClick(instance, domCache, dismissWith);
  2364. } else {
  2365. handleModalMousedown(domCache);
  2366. handleContainerMousedown(domCache);
  2367. handleModalClick(instance, domCache, dismissWith);
  2368. }
  2369. };
  2370. const handleToastClick = (instance, domCache, dismissWith) => {
  2371. domCache.popup.onclick = () => {
  2372. const innerParams = privateProps.innerParams.get(instance);
  2373. if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
  2374. return;
  2375. }
  2376. dismissWith(DismissReason.close);
  2377. };
  2378. };
  2379. const isAnyButtonShown = (innerParams) => {
  2380. return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
  2381. };
  2382. let ignoreOutsideClick = false;
  2383. const handleModalMousedown = (domCache) => {
  2384. domCache.popup.onmousedown = () => {
  2385. domCache.container.onmouseup = function(e) {
  2386. domCache.container.onmouseup = void 0;
  2387. if (e.target === domCache.container) {
  2388. ignoreOutsideClick = true;
  2389. }
  2390. };
  2391. };
  2392. };
  2393. const handleContainerMousedown = (domCache) => {
  2394. domCache.container.onmousedown = () => {
  2395. domCache.popup.onmouseup = function(e) {
  2396. domCache.popup.onmouseup = void 0;
  2397. if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
  2398. ignoreOutsideClick = true;
  2399. }
  2400. };
  2401. };
  2402. };
  2403. const handleModalClick = (instance, domCache, dismissWith) => {
  2404. domCache.container.onclick = (e) => {
  2405. const innerParams = privateProps.innerParams.get(instance);
  2406. if (ignoreOutsideClick) {
  2407. ignoreOutsideClick = false;
  2408. return;
  2409. }
  2410. if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
  2411. dismissWith(DismissReason.backdrop);
  2412. }
  2413. };
  2414. };
  2415. const isJqueryElement = (elem) => typeof elem === "object" && elem.jquery;
  2416. const isElement = (elem) => elem instanceof Element || isJqueryElement(elem);
  2417. const argsToParams = (args) => {
  2418. const params = {};
  2419. if (typeof args[0] === "object" && !isElement(args[0])) {
  2420. Object.assign(params, args[0]);
  2421. } else {
  2422. ["title", "html", "icon"].forEach((name, index) => {
  2423. const arg = args[index];
  2424. if (typeof arg === "string" || isElement(arg)) {
  2425. params[name] = arg;
  2426. } else if (arg !== void 0) {
  2427. error(`Unexpected type of ${name}! Expected "string" or "Element", got ${typeof arg}`);
  2428. }
  2429. });
  2430. }
  2431. return params;
  2432. };
  2433. function fire() {
  2434. const Swal3 = this;
  2435. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2436. args[_key] = arguments[_key];
  2437. }
  2438. return new Swal3(...args);
  2439. }
  2440. function mixin(mixinParams) {
  2441. class MixinSwal extends this {
  2442. _main(params, priorityMixinParams) {
  2443. return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
  2444. }
  2445. }
  2446. return MixinSwal;
  2447. }
  2448. const getTimerLeft = () => {
  2449. return globalState.timeout && globalState.timeout.getTimerLeft();
  2450. };
  2451. const stopTimer = () => {
  2452. if (globalState.timeout) {
  2453. stopTimerProgressBar();
  2454. return globalState.timeout.stop();
  2455. }
  2456. };
  2457. const resumeTimer = () => {
  2458. if (globalState.timeout) {
  2459. const remaining = globalState.timeout.start();
  2460. animateTimerProgressBar(remaining);
  2461. return remaining;
  2462. }
  2463. };
  2464. const toggleTimer = () => {
  2465. const timer = globalState.timeout;
  2466. return timer && (timer.running ? stopTimer() : resumeTimer());
  2467. };
  2468. const increaseTimer = (n) => {
  2469. if (globalState.timeout) {
  2470. const remaining = globalState.timeout.increase(n);
  2471. animateTimerProgressBar(remaining, true);
  2472. return remaining;
  2473. }
  2474. };
  2475. const isTimerRunning = () => {
  2476. return !!(globalState.timeout && globalState.timeout.isRunning());
  2477. };
  2478. let bodyClickListenerAdded = false;
  2479. const clickHandlers = {};
  2480. function bindClickHandler() {
  2481. let attr = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "data-swal-template";
  2482. clickHandlers[attr] = this;
  2483. if (!bodyClickListenerAdded) {
  2484. document.body.addEventListener("click", bodyClickListener);
  2485. bodyClickListenerAdded = true;
  2486. }
  2487. }
  2488. const bodyClickListener = (event) => {
  2489. for (let el = event.target; el && el !== document; el = el.parentNode) {
  2490. for (const attr in clickHandlers) {
  2491. const template = el.getAttribute(attr);
  2492. if (template) {
  2493. clickHandlers[attr].fire({
  2494. template
  2495. });
  2496. return;
  2497. }
  2498. }
  2499. }
  2500. };
  2501. var staticMethods = /* @__PURE__ */ Object.freeze({
  2502. __proto__: null,
  2503. argsToParams,
  2504. bindClickHandler,
  2505. clickCancel,
  2506. clickConfirm,
  2507. clickDeny,
  2508. enableLoading: showLoading,
  2509. fire,
  2510. getActions,
  2511. getCancelButton,
  2512. getCloseButton,
  2513. getConfirmButton,
  2514. getContainer,
  2515. getDenyButton,
  2516. getFocusableElements,
  2517. getFooter,
  2518. getHtmlContainer,
  2519. getIcon,
  2520. getIconContent,
  2521. getImage,
  2522. getInputLabel,
  2523. getLoader,
  2524. getPopup,
  2525. getProgressSteps,
  2526. getTimerLeft,
  2527. getTimerProgressBar,
  2528. getTitle,
  2529. getValidationMessage,
  2530. increaseTimer,
  2531. isDeprecatedParameter,
  2532. isLoading,
  2533. isTimerRunning,
  2534. isUpdatableParameter,
  2535. isValidParameter,
  2536. isVisible,
  2537. mixin,
  2538. resumeTimer,
  2539. showLoading,
  2540. stopTimer,
  2541. toggleTimer
  2542. });
  2543. class Timer {
  2544. /**
  2545. * @param {Function} callback
  2546. * @param {number} delay
  2547. */
  2548. constructor(callback, delay) {
  2549. this.callback = callback;
  2550. this.remaining = delay;
  2551. this.running = false;
  2552. this.start();
  2553. }
  2554. /**
  2555. * @returns {number}
  2556. */
  2557. start() {
  2558. if (!this.running) {
  2559. this.running = true;
  2560. this.started = /* @__PURE__ */ new Date();
  2561. this.id = setTimeout(this.callback, this.remaining);
  2562. }
  2563. return this.remaining;
  2564. }
  2565. /**
  2566. * @returns {number}
  2567. */
  2568. stop() {
  2569. if (this.started && this.running) {
  2570. this.running = false;
  2571. clearTimeout(this.id);
  2572. this.remaining -= (/* @__PURE__ */ new Date()).getTime() - this.started.getTime();
  2573. }
  2574. return this.remaining;
  2575. }
  2576. /**
  2577. * @param {number} n
  2578. * @returns {number}
  2579. */
  2580. increase(n) {
  2581. const running = this.running;
  2582. if (running) {
  2583. this.stop();
  2584. }
  2585. this.remaining += n;
  2586. if (running) {
  2587. this.start();
  2588. }
  2589. return this.remaining;
  2590. }
  2591. /**
  2592. * @returns {number}
  2593. */
  2594. getTimerLeft() {
  2595. if (this.running) {
  2596. this.stop();
  2597. this.start();
  2598. }
  2599. return this.remaining;
  2600. }
  2601. /**
  2602. * @returns {boolean}
  2603. */
  2604. isRunning() {
  2605. return this.running;
  2606. }
  2607. }
  2608. const swalStringParams = ["swal-title", "swal-html", "swal-footer"];
  2609. const getTemplateParams = (params) => {
  2610. const template = typeof params.template === "string" ? document.querySelector(params.template) : params.template;
  2611. if (!template) {
  2612. return {};
  2613. }
  2614. const templateContent = template.content;
  2615. showWarningsForElements(templateContent);
  2616. const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
  2617. return result;
  2618. };
  2619. const getSwalParams = (templateContent) => {
  2620. const result = {};
  2621. const swalParams = Array.from(templateContent.querySelectorAll("swal-param"));
  2622. swalParams.forEach((param) => {
  2623. showWarningsForAttributes(param, ["name", "value"]);
  2624. const paramName = param.getAttribute("name");
  2625. const value = param.getAttribute("value");
  2626. if (typeof defaultParams[paramName] === "boolean") {
  2627. result[paramName] = value !== "false";
  2628. } else if (typeof defaultParams[paramName] === "object") {
  2629. result[paramName] = JSON.parse(value);
  2630. } else {
  2631. result[paramName] = value;
  2632. }
  2633. });
  2634. return result;
  2635. };
  2636. const getSwalFunctionParams = (templateContent) => {
  2637. const result = {};
  2638. const swalFunctions = Array.from(templateContent.querySelectorAll("swal-function-param"));
  2639. swalFunctions.forEach((param) => {
  2640. const paramName = param.getAttribute("name");
  2641. const value = param.getAttribute("value");
  2642. result[paramName] = new Function(`return ${value}`)();
  2643. });
  2644. return result;
  2645. };
  2646. const getSwalButtons = (templateContent) => {
  2647. const result = {};
  2648. const swalButtons = Array.from(templateContent.querySelectorAll("swal-button"));
  2649. swalButtons.forEach((button) => {
  2650. showWarningsForAttributes(button, ["type", "color", "aria-label"]);
  2651. const type = button.getAttribute("type");
  2652. result[`${type}ButtonText`] = button.innerHTML;
  2653. result[`show${capitalizeFirstLetter(type)}Button`] = true;
  2654. if (button.hasAttribute("color")) {
  2655. result[`${type}ButtonColor`] = button.getAttribute("color");
  2656. }
  2657. if (button.hasAttribute("aria-label")) {
  2658. result[`${type}ButtonAriaLabel`] = button.getAttribute("aria-label");
  2659. }
  2660. });
  2661. return result;
  2662. };
  2663. const getSwalImage = (templateContent) => {
  2664. const result = {};
  2665. const image = templateContent.querySelector("swal-image");
  2666. if (image) {
  2667. showWarningsForAttributes(image, ["src", "width", "height", "alt"]);
  2668. if (image.hasAttribute("src")) {
  2669. result.imageUrl = image.getAttribute("src");
  2670. }
  2671. if (image.hasAttribute("width")) {
  2672. result.imageWidth = image.getAttribute("width");
  2673. }
  2674. if (image.hasAttribute("height")) {
  2675. result.imageHeight = image.getAttribute("height");
  2676. }
  2677. if (image.hasAttribute("alt")) {
  2678. result.imageAlt = image.getAttribute("alt");
  2679. }
  2680. }
  2681. return result;
  2682. };
  2683. const getSwalIcon = (templateContent) => {
  2684. const result = {};
  2685. const icon = templateContent.querySelector("swal-icon");
  2686. if (icon) {
  2687. showWarningsForAttributes(icon, ["type", "color"]);
  2688. if (icon.hasAttribute("type")) {
  2689. result.icon = icon.getAttribute("type");
  2690. }
  2691. if (icon.hasAttribute("color")) {
  2692. result.iconColor = icon.getAttribute("color");
  2693. }
  2694. result.iconHtml = icon.innerHTML;
  2695. }
  2696. return result;
  2697. };
  2698. const getSwalInput = (templateContent) => {
  2699. const result = {};
  2700. const input = templateContent.querySelector("swal-input");
  2701. if (input) {
  2702. showWarningsForAttributes(input, ["type", "label", "placeholder", "value"]);
  2703. result.input = input.getAttribute("type") || "text";
  2704. if (input.hasAttribute("label")) {
  2705. result.inputLabel = input.getAttribute("label");
  2706. }
  2707. if (input.hasAttribute("placeholder")) {
  2708. result.inputPlaceholder = input.getAttribute("placeholder");
  2709. }
  2710. if (input.hasAttribute("value")) {
  2711. result.inputValue = input.getAttribute("value");
  2712. }
  2713. }
  2714. const inputOptions = Array.from(templateContent.querySelectorAll("swal-input-option"));
  2715. if (inputOptions.length) {
  2716. result.inputOptions = {};
  2717. inputOptions.forEach((option) => {
  2718. showWarningsForAttributes(option, ["value"]);
  2719. const optionValue = option.getAttribute("value");
  2720. const optionName = option.innerHTML;
  2721. result.inputOptions[optionValue] = optionName;
  2722. });
  2723. }
  2724. return result;
  2725. };
  2726. const getSwalStringParams = (templateContent, paramNames) => {
  2727. const result = {};
  2728. for (const i in paramNames) {
  2729. const paramName = paramNames[i];
  2730. const tag = templateContent.querySelector(paramName);
  2731. if (tag) {
  2732. showWarningsForAttributes(tag, []);
  2733. result[paramName.replace(/^swal-/, "")] = tag.innerHTML.trim();
  2734. }
  2735. }
  2736. return result;
  2737. };
  2738. const showWarningsForElements = (templateContent) => {
  2739. const allowedElements = swalStringParams.concat(["swal-param", "swal-function-param", "swal-button", "swal-image", "swal-icon", "swal-input", "swal-input-option"]);
  2740. Array.from(templateContent.children).forEach((el) => {
  2741. const tagName = el.tagName.toLowerCase();
  2742. if (!allowedElements.includes(tagName)) {
  2743. warn(`Unrecognized element <${tagName}>`);
  2744. }
  2745. });
  2746. };
  2747. const showWarningsForAttributes = (el, allowedAttributes) => {
  2748. Array.from(el.attributes).forEach((attribute) => {
  2749. if (allowedAttributes.indexOf(attribute.name) === -1) {
  2750. 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."}`]);
  2751. }
  2752. });
  2753. };
  2754. const SHOW_CLASS_TIMEOUT = 10;
  2755. const openPopup = (params) => {
  2756. const container = getContainer();
  2757. const popup = getPopup();
  2758. if (typeof params.willOpen === "function") {
  2759. params.willOpen(popup);
  2760. }
  2761. const bodyStyles = window.getComputedStyle(document.body);
  2762. const initialBodyOverflow = bodyStyles.overflowY;
  2763. addClasses(container, popup, params);
  2764. setTimeout(() => {
  2765. setScrollingVisibility(container, popup);
  2766. }, SHOW_CLASS_TIMEOUT);
  2767. if (isModal()) {
  2768. fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
  2769. setAriaHidden();
  2770. }
  2771. if (!isToast() && !globalState.previousActiveElement) {
  2772. globalState.previousActiveElement = document.activeElement;
  2773. }
  2774. if (typeof params.didOpen === "function") {
  2775. setTimeout(() => params.didOpen(popup));
  2776. }
  2777. removeClass(container, swalClasses["no-transition"]);
  2778. };
  2779. const swalOpenAnimationFinished = (event) => {
  2780. const popup = getPopup();
  2781. if (event.target !== popup) {
  2782. return;
  2783. }
  2784. const container = getContainer();
  2785. popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
  2786. container.style.overflowY = "auto";
  2787. };
  2788. const setScrollingVisibility = (container, popup) => {
  2789. if (animationEndEvent && hasCssAnimation(popup)) {
  2790. container.style.overflowY = "hidden";
  2791. popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
  2792. } else {
  2793. container.style.overflowY = "auto";
  2794. }
  2795. };
  2796. const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
  2797. iOSfix();
  2798. if (scrollbarPadding && initialBodyOverflow !== "hidden") {
  2799. fixScrollbar();
  2800. }
  2801. setTimeout(() => {
  2802. container.scrollTop = 0;
  2803. });
  2804. };
  2805. const addClasses = (container, popup, params) => {
  2806. addClass(container, params.showClass.backdrop);
  2807. popup.style.setProperty("opacity", "0", "important");
  2808. show(popup, "grid");
  2809. setTimeout(() => {
  2810. addClass(popup, params.showClass.popup);
  2811. popup.style.removeProperty("opacity");
  2812. }, SHOW_CLASS_TIMEOUT);
  2813. addClass([document.documentElement, document.body], swalClasses.shown);
  2814. if (params.heightAuto && params.backdrop && !params.toast) {
  2815. addClass([document.documentElement, document.body], swalClasses["height-auto"]);
  2816. }
  2817. };
  2818. var defaultInputValidators = {
  2819. /**
  2820. * @param {string} string
  2821. * @param {string} validationMessage
  2822. * @returns {Promise<void | string>}
  2823. */
  2824. email: (string, validationMessage) => {
  2825. return /^[a-zA-Z0-9.+_-]+@[a-zA-Z0-9.-]+\.[a-zA-Z0-9-]{2,24}$/.test(string) ? Promise.resolve() : Promise.resolve(validationMessage || "Invalid email address");
  2826. },
  2827. /**
  2828. * @param {string} string
  2829. * @param {string} validationMessage
  2830. * @returns {Promise<void | string>}
  2831. */
  2832. url: (string, validationMessage) => {
  2833. 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");
  2834. }
  2835. };
  2836. function setDefaultInputValidators(params) {
  2837. if (!params.inputValidator) {
  2838. Object.keys(defaultInputValidators).forEach((key) => {
  2839. if (params.input === key) {
  2840. params.inputValidator = defaultInputValidators[key];
  2841. }
  2842. });
  2843. }
  2844. }
  2845. function validateCustomTargetElement(params) {
  2846. if (!params.target || typeof params.target === "string" && !document.querySelector(params.target) || typeof params.target !== "string" && !params.target.appendChild) {
  2847. warn('Target parameter is not valid, defaulting to "body"');
  2848. params.target = "body";
  2849. }
  2850. }
  2851. function setParameters(params) {
  2852. setDefaultInputValidators(params);
  2853. if (params.showLoaderOnConfirm && !params.preConfirm) {
  2854. warn("showLoaderOnConfirm is set to true, but preConfirm is not defined.\nshowLoaderOnConfirm should be used together with preConfirm, see usage example:\nhttps://sweetalert2.github.io/#ajax-request");
  2855. }
  2856. validateCustomTargetElement(params);
  2857. if (typeof params.title === "string") {
  2858. params.title = params.title.split("\n").join("<br />");
  2859. }
  2860. init(params);
  2861. }
  2862. let currentInstance;
  2863. class SweetAlert {
  2864. /**
  2865. * @param {...any} args
  2866. * @this {SweetAlert}
  2867. */
  2868. constructor() {
  2869. if (typeof window === "undefined") {
  2870. return;
  2871. }
  2872. currentInstance = this;
  2873. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  2874. args[_key] = arguments[_key];
  2875. }
  2876. const outerParams = Object.freeze(this.constructor.argsToParams(args));
  2877. this.params = outerParams;
  2878. this.isAwaitingPromise = false;
  2879. const promise = currentInstance._main(currentInstance.params);
  2880. privateProps.promise.set(this, promise);
  2881. }
  2882. _main(userParams) {
  2883. let mixinParams = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  2884. showWarningsForParams(Object.assign({}, mixinParams, userParams));
  2885. if (globalState.currentInstance) {
  2886. globalState.currentInstance._destroy();
  2887. if (isModal()) {
  2888. unsetAriaHidden();
  2889. }
  2890. }
  2891. globalState.currentInstance = currentInstance;
  2892. const innerParams = prepareParams(userParams, mixinParams);
  2893. setParameters(innerParams);
  2894. Object.freeze(innerParams);
  2895. if (globalState.timeout) {
  2896. globalState.timeout.stop();
  2897. delete globalState.timeout;
  2898. }
  2899. clearTimeout(globalState.restoreFocusTimeout);
  2900. const domCache = populateDomCache(currentInstance);
  2901. render(currentInstance, innerParams);
  2902. privateProps.innerParams.set(currentInstance, innerParams);
  2903. return swalPromise(currentInstance, domCache, innerParams);
  2904. }
  2905. // `catch` cannot be the name of a module export, so we define our thenable methods here instead
  2906. then(onFulfilled) {
  2907. const promise = privateProps.promise.get(this);
  2908. return promise.then(onFulfilled);
  2909. }
  2910. finally(onFinally) {
  2911. const promise = privateProps.promise.get(this);
  2912. return promise.finally(onFinally);
  2913. }
  2914. }
  2915. const swalPromise = (instance, domCache, innerParams) => {
  2916. return new Promise((resolve, reject) => {
  2917. const dismissWith = (dismiss) => {
  2918. instance.close({
  2919. isDismissed: true,
  2920. dismiss
  2921. });
  2922. };
  2923. privateMethods.swalPromiseResolve.set(instance, resolve);
  2924. privateMethods.swalPromiseReject.set(instance, reject);
  2925. domCache.confirmButton.onclick = () => {
  2926. handleConfirmButtonClick(instance);
  2927. };
  2928. domCache.denyButton.onclick = () => {
  2929. handleDenyButtonClick(instance);
  2930. };
  2931. domCache.cancelButton.onclick = () => {
  2932. handleCancelButtonClick(instance, dismissWith);
  2933. };
  2934. domCache.closeButton.onclick = () => {
  2935. dismissWith(DismissReason.close);
  2936. };
  2937. handlePopupClick(instance, domCache, dismissWith);
  2938. addKeydownHandler(instance, globalState, innerParams, dismissWith);
  2939. handleInputOptionsAndValue(instance, innerParams);
  2940. openPopup(innerParams);
  2941. setupTimer(globalState, innerParams, dismissWith);
  2942. initFocus(domCache, innerParams);
  2943. setTimeout(() => {
  2944. domCache.container.scrollTop = 0;
  2945. });
  2946. });
  2947. };
  2948. const prepareParams = (userParams, mixinParams) => {
  2949. const templateParams = getTemplateParams(userParams);
  2950. const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams);
  2951. params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
  2952. params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
  2953. return params;
  2954. };
  2955. const populateDomCache = (instance) => {
  2956. const domCache = {
  2957. popup: getPopup(),
  2958. container: getContainer(),
  2959. actions: getActions(),
  2960. confirmButton: getConfirmButton(),
  2961. denyButton: getDenyButton(),
  2962. cancelButton: getCancelButton(),
  2963. loader: getLoader(),
  2964. closeButton: getCloseButton(),
  2965. validationMessage: getValidationMessage(),
  2966. progressSteps: getProgressSteps()
  2967. };
  2968. privateProps.domCache.set(instance, domCache);
  2969. return domCache;
  2970. };
  2971. const setupTimer = (globalState2, innerParams, dismissWith) => {
  2972. const timerProgressBar = getTimerProgressBar();
  2973. hide(timerProgressBar);
  2974. if (innerParams.timer) {
  2975. globalState2.timeout = new Timer(() => {
  2976. dismissWith("timer");
  2977. delete globalState2.timeout;
  2978. }, innerParams.timer);
  2979. if (innerParams.timerProgressBar) {
  2980. show(timerProgressBar);
  2981. applyCustomClass(timerProgressBar, innerParams, "timerProgressBar");
  2982. setTimeout(() => {
  2983. if (globalState2.timeout && globalState2.timeout.running) {
  2984. animateTimerProgressBar(innerParams.timer);
  2985. }
  2986. });
  2987. }
  2988. }
  2989. };
  2990. const initFocus = (domCache, innerParams) => {
  2991. if (innerParams.toast) {
  2992. return;
  2993. }
  2994. if (!callIfFunction(innerParams.allowEnterKey)) {
  2995. blurActiveElement();
  2996. return;
  2997. }
  2998. if (!focusButton(domCache, innerParams)) {
  2999. setFocus(-1, 1);
  3000. }
  3001. };
  3002. const focusButton = (domCache, innerParams) => {
  3003. if (innerParams.focusDeny && isVisible$1(domCache.denyButton)) {
  3004. domCache.denyButton.focus();
  3005. return true;
  3006. }
  3007. if (innerParams.focusCancel && isVisible$1(domCache.cancelButton)) {
  3008. domCache.cancelButton.focus();
  3009. return true;
  3010. }
  3011. if (innerParams.focusConfirm && isVisible$1(domCache.confirmButton)) {
  3012. domCache.confirmButton.focus();
  3013. return true;
  3014. }
  3015. return false;
  3016. };
  3017. const blurActiveElement = () => {
  3018. if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === "function") {
  3019. document.activeElement.blur();
  3020. }
  3021. };
  3022. SweetAlert.prototype.disableButtons = disableButtons;
  3023. SweetAlert.prototype.enableButtons = enableButtons;
  3024. SweetAlert.prototype.getInput = getInput;
  3025. SweetAlert.prototype.disableInput = disableInput;
  3026. SweetAlert.prototype.enableInput = enableInput;
  3027. SweetAlert.prototype.hideLoading = hideLoading;
  3028. SweetAlert.prototype.disableLoading = hideLoading;
  3029. SweetAlert.prototype.showValidationMessage = showValidationMessage;
  3030. SweetAlert.prototype.resetValidationMessage = resetValidationMessage;
  3031. SweetAlert.prototype.close = close;
  3032. SweetAlert.prototype.closePopup = close;
  3033. SweetAlert.prototype.closeModal = close;
  3034. SweetAlert.prototype.closeToast = close;
  3035. SweetAlert.prototype.rejectPromise = rejectPromise;
  3036. SweetAlert.prototype.update = update;
  3037. SweetAlert.prototype._destroy = _destroy;
  3038. Object.assign(SweetAlert, staticMethods);
  3039. Object.keys(instanceMethods).forEach((key) => {
  3040. SweetAlert[key] = function() {
  3041. if (currentInstance && currentInstance[key]) {
  3042. return currentInstance[key](...arguments);
  3043. }
  3044. return null;
  3045. };
  3046. });
  3047. SweetAlert.DismissReason = DismissReason;
  3048. SweetAlert.version = "11.7.18";
  3049. const Swal2 = SweetAlert;
  3050. Swal2.default = Swal2;
  3051. return Swal2;
  3052. });
  3053. if (typeof exports !== "undefined" && exports.Sweetalert2) {
  3054. exports.swal = exports.sweetAlert = exports.Swal = exports.SweetAlert = exports.Sweetalert2;
  3055. }
  3056. "undefined" != typeof document && function(e, t) {
  3057. var n = e.createElement("style");
  3058. if (e.getElementsByTagName("head")[0].appendChild(n), n.styleSheet)
  3059. n.styleSheet.disabled || (n.styleSheet.cssText = t);
  3060. else
  3061. try {
  3062. n.innerHTML = t;
  3063. } catch (e2) {
  3064. n.innerText = t;
  3065. }
  3066. }(document, '.swal2-popup.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;background:#fff;box-shadow:0 0 1px rgba(0,0,0,.075),0 1px 2px rgba(0,0,0,.075),1px 2px 4px rgba(0,0,0,.075),1px 3px 8px rgba(0,0,0,.075),2px 4px 16px rgba(0,0,0,.075);pointer-events:all}.swal2-popup.swal2-toast>*{grid-column:2}.swal2-popup.swal2-toast .swal2-title{margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{height:2em;margin:.5em;font-size:1em}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-popup.swal2-toast .swal2-close{grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-popup.swal2-toast .swal2-html-container{margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-popup.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-popup.swal2-toast .swal2-styled{margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;transform:rotate(45deg);border-radius:50%}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}div:where(.swal2-container){display:grid;position:fixed;z-index: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:.625em;overflow-x:hidden;transition:background-color .1s;-webkit-overflow-scrolling:touch}div:where(.swal2-container).swal2-backdrop-show,div:where(.swal2-container).swal2-noanimation{background:rgba(0,0,0,.4)}div:where(.swal2-container).swal2-backdrop-hide{background:rgba(0,0,0,0) !important}div:where(.swal2-container).swal2-top-start,div:where(.swal2-container).swal2-center-start,div:where(.swal2-container).swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}div:where(.swal2-container).swal2-top,div:where(.swal2-container).swal2-center,div:where(.swal2-container).swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}div:where(.swal2-container).swal2-top-end,div:where(.swal2-container).swal2-center-end,div:where(.swal2-container).swal2-bottom-end{grid-template-columns:auto auto minmax(0, 1fr)}div:where(.swal2-container).swal2-top-start>.swal2-popup{align-self:start}div:where(.swal2-container).swal2-top>.swal2-popup{grid-column:2;align-self:start;justify-self:center}div:where(.swal2-container).swal2-top-end>.swal2-popup,div:where(.swal2-container).swal2-top-right>.swal2-popup{grid-column:3;align-self:start;justify-self:end}div:where(.swal2-container).swal2-center-start>.swal2-popup,div:where(.swal2-container).swal2-center-left>.swal2-popup{grid-row:2;align-self:center}div:where(.swal2-container).swal2-center>.swal2-popup{grid-column:2;grid-row:2;align-self:center;justify-self:center}div:where(.swal2-container).swal2-center-end>.swal2-popup,div:where(.swal2-container).swal2-center-right>.swal2-popup{grid-column:3;grid-row:2;align-self:center;justify-self:end}div:where(.swal2-container).swal2-bottom-start>.swal2-popup,div:where(.swal2-container).swal2-bottom-left>.swal2-popup{grid-column:1;grid-row:3;align-self:end}div:where(.swal2-container).swal2-bottom>.swal2-popup{grid-column:2;grid-row:3;justify-self:center;align-self:end}div:where(.swal2-container).swal2-bottom-end>.swal2-popup,div:where(.swal2-container).swal2-bottom-right>.swal2-popup{grid-column:3;grid-row:3;align-self:end;justify-self:end}div:where(.swal2-container).swal2-grow-row>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-column:1/4;width:100%}div:where(.swal2-container).swal2-grow-column>.swal2-popup,div:where(.swal2-container).swal2-grow-fullscreen>.swal2-popup{grid-row:1/4;align-self:stretch}div:where(.swal2-container).swal2-no-transition{transition:none !important}div:where(.swal2-container) div:where(.swal2-popup){display:none;position:relative;box-sizing:border-box;grid-template-columns:minmax(0, 100%);width:32em;max-width:100%;padding:0 0 1.25em;border:none;border-radius:5px;background:#fff;color:#545454;font-family:inherit;font-size:1rem}div:where(.swal2-container) div:where(.swal2-popup):focus{outline:none}div:where(.swal2-container) div:where(.swal2-popup).swal2-loading{overflow-y:hidden}div:where(.swal2-container) h2:where(.swal2-title){position:relative;max-width:100%;margin:0;padding:.8em 1em 0;color:inherit;font-size:1.875em;font-weight:600;text-align:center;text-transform:none;word-wrap:break-word}div:where(.swal2-container) div:where(.swal2-actions){display:flex;z-index:1;box-sizing:border-box;flex-wrap:wrap;align-items:center;justify-content:center;width:auto;margin:1.25em auto 0;padding:0}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1))}div:where(.swal2-container) div:where(.swal2-actions):not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2))}div:where(.swal2-container) div:where(.swal2-loader){display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 rgba(0,0,0,0) #2778c4 rgba(0,0,0,0)}div:where(.swal2-container) button:where(.swal2-styled){margin:.3125em;padding:.625em 1.1em;transition:box-shadow .1s;box-shadow:0 0 0 3px rgba(0,0,0,0);font-weight:500}div:where(.swal2-container) button:where(.swal2-styled):not([disabled]){cursor:pointer}div:where(.swal2-container) button:where(.swal2-styled).swal2-confirm{border:0;border-radius:.25em;background:initial;background-color:#7066e0;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-confirm:focus{box-shadow:0 0 0 3px rgba(112,102,224,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-deny{border:0;border-radius:.25em;background:initial;background-color:#dc3741;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-deny:focus{box-shadow:0 0 0 3px rgba(220,55,65,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-cancel{border:0;border-radius:.25em;background:initial;background-color:#6e7881;color:#fff;font-size:1em}div:where(.swal2-container) button:where(.swal2-styled).swal2-cancel:focus{box-shadow:0 0 0 3px rgba(110,120,129,.5)}div:where(.swal2-container) button:where(.swal2-styled).swal2-default-outline:focus{box-shadow:0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) button:where(.swal2-styled):focus{outline:none}div:where(.swal2-container) button:where(.swal2-styled)::-moz-focus-inner{border:0}div:where(.swal2-container) div:where(.swal2-footer){justify-content:center;margin:1em 0 0;padding:1em 1em 0;border-top:1px solid #eee;color:inherit;font-size:1em}div:where(.swal2-container) .swal2-timer-progress-bar-container{position:absolute;right:0;bottom:0;left:0;grid-column:auto !important;overflow:hidden;border-bottom-right-radius:5px;border-bottom-left-radius:5px}div:where(.swal2-container) div:where(.swal2-timer-progress-bar){width:100%;height:.25em;background:rgba(0,0,0,.2)}div:where(.swal2-container) img:where(.swal2-image){max-width:100%;margin:2em auto 1em}div:where(.swal2-container) button:where(.swal2-close){z-index:2;align-items:center;justify-content:center;width:1.2em;height:1.2em;margin-top:0;margin-right:0;margin-bottom:-1.2em;padding:0;overflow:hidden;transition:color .1s,box-shadow .1s;border:none;border-radius:5px;background:rgba(0,0,0,0);color:#ccc;font-family:monospace;font-size:2.5em;cursor:pointer;justify-self:end}div:where(.swal2-container) button:where(.swal2-close):hover{transform:none;background:rgba(0,0,0,0);color:#f27474}div:where(.swal2-container) button:where(.swal2-close):focus{outline:none;box-shadow:inset 0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) button:where(.swal2-close)::-moz-focus-inner{border:0}div:where(.swal2-container) .swal2-html-container{z-index:1;justify-content:center;margin:1em 1.6em .3em;padding:0;overflow:auto;color:inherit;font-size:1.125em;font-weight:normal;line-height:normal;text-align:center;word-wrap:break-word;word-break:break-word}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea),div:where(.swal2-container) select:where(.swal2-select),div:where(.swal2-container) div:where(.swal2-radio),div:where(.swal2-container) label:where(.swal2-checkbox){margin:1em 2em 3px}div:where(.swal2-container) input:where(.swal2-input),div:where(.swal2-container) input:where(.swal2-file),div:where(.swal2-container) textarea:where(.swal2-textarea){box-sizing:border-box;width:auto;transition:border-color .1s,box-shadow .1s;border:1px solid #d9d9d9;border-radius:.1875em;background:rgba(0,0,0,0);box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(0,0,0,0);color:inherit;font-size:1.125em}div:where(.swal2-container) input:where(.swal2-input).swal2-inputerror,div:where(.swal2-container) input:where(.swal2-file).swal2-inputerror,div:where(.swal2-container) textarea:where(.swal2-textarea).swal2-inputerror{border-color:#f27474 !important;box-shadow:0 0 2px #f27474 !important}div:where(.swal2-container) input:where(.swal2-input):focus,div:where(.swal2-container) input:where(.swal2-file):focus,div:where(.swal2-container) textarea:where(.swal2-textarea):focus{border:1px solid #b4dbed;outline:none;box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(100,150,200,.5)}div:where(.swal2-container) input:where(.swal2-input)::placeholder,div:where(.swal2-container) input:where(.swal2-file)::placeholder,div:where(.swal2-container) textarea:where(.swal2-textarea)::placeholder{color:#ccc}div:where(.swal2-container) .swal2-range{margin:1em 2em 3px;background:#fff}div:where(.swal2-container) .swal2-range input{width:80%}div:where(.swal2-container) .swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}div:where(.swal2-container) .swal2-range input,div:where(.swal2-container) .swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}div:where(.swal2-container) .swal2-input{height:2.625em;padding:0 .75em}div:where(.swal2-container) .swal2-file{width:75%;margin-right:auto;margin-left:auto;background:rgba(0,0,0,0);font-size:1.125em}div:where(.swal2-container) .swal2-textarea{height:6.75em;padding:.75em}div:where(.swal2-container) .swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:rgba(0,0,0,0);color:inherit;font-size:1.125em}div:where(.swal2-container) .swal2-radio,div:where(.swal2-container) .swal2-checkbox{align-items:center;justify-content:center;background:#fff;color:inherit}div:where(.swal2-container) .swal2-radio label,div:where(.swal2-container) .swal2-checkbox label{margin:0 .6em;font-size:1.125em}div:where(.swal2-container) .swal2-radio input,div:where(.swal2-container) .swal2-checkbox input{flex-shrink:0;margin:0 .4em}div:where(.swal2-container) label:where(.swal2-input-label){display:flex;justify-content:center;margin:1em auto 0}div:where(.swal2-container) div:where(.swal2-validation-message){align-items:center;justify-content:center;margin:1em 0 0;padding:.625em;overflow:hidden;background:#f0f0f0;color:#666;font-size:1em;font-weight:300}div:where(.swal2-container) div:where(.swal2-validation-message)::before{content:"!";display:inline-block;width:1.5em;min-width:1.5em;height:1.5em;margin:0 .625em;border-radius:50%;background-color:#f27474;color:#fff;font-weight:600;line-height:1.5em;text-align:center}div:where(.swal2-container) .swal2-progress-steps{flex-wrap:wrap;align-items:center;max-width:100%;margin:1.25em auto;padding:0;background:rgba(0,0,0,0);font-weight:600}div:where(.swal2-container) .swal2-progress-steps li{display:inline-block;position:relative}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step{z-index:20;flex-shrink:0;width:2em;height:2em;border-radius:2em;background:#2778c4;color:#fff;line-height:2em;text-align:center}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}div:where(.swal2-container) .swal2-progress-steps .swal2-progress-step-line{z-index:10;flex-shrink:0;width:2.5em;height:.4em;margin:0 -1px;background:#2778c4}div:where(.swal2-icon){position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:2.5em auto .6em;border:0.25em solid rgba(0,0,0,0);border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;user-select:none}div:where(.swal2-icon) .swal2-icon-content{display:flex;align-items:center;font-size:3.75em}div:where(.swal2-icon).swal2-error{border-color:#f27474;color:#f27474}div:where(.swal2-icon).swal2-error .swal2-x-mark{position:relative;flex-grow:1}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line]{display:block;position:absolute;top:2.3125em;width:2.9375em;height:.3125em;border-radius:.125em;background-color:#f27474}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}div:where(.swal2-icon).swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}div:where(.swal2-icon).swal2-error.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}div:where(.swal2-icon).swal2-warning{border-color:#facea8;color:#f8bb86}div:where(.swal2-icon).swal2-warning.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-warning.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .5s}div:where(.swal2-icon).swal2-info{border-color:#9de0f6;color:#3fc3ee}div:where(.swal2-icon).swal2-info.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-info.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .8s}div:where(.swal2-icon).swal2-question{border-color:#c9dae1;color:#87adbd}div:where(.swal2-icon).swal2-question.swal2-icon-show{animation:swal2-animate-error-icon .5s}div:where(.swal2-icon).swal2-question.swal2-icon-show .swal2-icon-content{animation:swal2-animate-question-mark .8s}div:where(.swal2-icon).swal2-success{border-color:#a5dc86;color:#a5dc86}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;transform:rotate(45deg);border-radius:50%}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.4375em;left:-2.0635em;transform:rotate(-45deg);transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}div:where(.swal2-icon).swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.6875em;left:1.875em;transform:rotate(-45deg);transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}div:where(.swal2-icon).swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-0.25em;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)}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-animate-success-line-tip .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}div:where(.swal2-icon).swal2-success.swal2-icon-show .swal2-success-circular-line-right{animation:swal2-rotate-success-circular-line 4.25s ease-in}[class^=swal2]{-webkit-tap-highlight-color:rgba(0,0,0,0)}.swal2-show{animation:swal2-show .3s}.swal2-hide{animation:swal2-hide .15s forwards}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}.swal2-rtl .swal2-close{margin-right:initial;margin-left:0}.swal2-rtl .swal2-timer-progress-bar{right:0;left:auto}@keyframes swal2-toast-show{0%{transform:translateY(-0.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(0.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0deg)}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-0.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}@keyframes swal2-show{0%{transform:scale(0.7)}45%{transform:scale(1.05)}80%{transform:scale(0.95)}100%{transform:scale(1)}}@keyframes swal2-hide{0%{transform:scale(1);opacity:1}100%{transform:scale(0.5);opacity:0}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-0.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(0.4);opacity:0}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}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto !important}body.swal2-no-backdrop .swal2-container{background-color:rgba(0,0,0,0) !important;pointer-events:none}body.swal2-no-backdrop .swal2-container .swal2-popup{pointer-events:all}body.swal2-no-backdrop .swal2-container .swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll !important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static !important}}body.swal2-toast-shown .swal2-container{box-sizing:border-box;width:360px;max-width:100%;background-color:rgba(0,0,0,0);pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{inset:0 auto auto 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{inset:0 0 auto auto}body.swal2-toast-shown .swal2-container.swal2-top-start,body.swal2-toast-shown .swal2-container.swal2-top-left{inset:0 auto auto 0}body.swal2-toast-shown .swal2-container.swal2-center-start,body.swal2-toast-shown .swal2-container.swal2-center-left{inset:50% auto auto 0;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{inset:50% auto auto 50%;transform:translate(-50%, -50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{inset:50% 0 auto auto;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-start,body.swal2-toast-shown .swal2-container.swal2-bottom-left{inset:auto auto 0 0}body.swal2-toast-shown .swal2-container.swal2-bottom{inset:auto auto 0 50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{inset:auto 0 0 auto}');
  3067. }
  3068. });
  3069.  
  3070. // src/index.ts
  3071. var import_chatgpt = __toESM(require_chatgpt2(), 1);
  3072.  
  3073. // ../../packages/page-button/dist/index.mjs
  3074. var import_sweetalert2 = __toESM(require_sweetalert2_all(), 1);
  3075. function displayHTML(html) {
  3076. return __async(this, null, function* () {
  3077. let screenWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  3078. let swalWidth = screenWidth < 800 ? "80%" : "800px";
  3079. if (!document.head.querySelector("#readModeStyle")) {
  3080. let style = document.createElement("style");
  3081. style.type = "text/css";
  3082. style.id = "readModeStyle";
  3083. style.innerHTML = `
  3084. .text-left { text-align: left !important; }
  3085. .scrollable { max-height: 90vh; overflow-y: auto; }
  3086. `;
  3087. document.head.appendChild(style);
  3088. }
  3089. import_sweetalert2.default.fire({
  3090. title: "",
  3091. html: html.join("<br />"),
  3092. width: swalWidth,
  3093. padding: "0em",
  3094. background: "#fff",
  3095. backdrop: "rgba(128,128,128,0.4)",
  3096. showConfirmButton: false,
  3097. showClass: { popup: "", backdrop: "" },
  3098. customClass: { htmlContainer: "text-left scrollable swal-font" },
  3099. willClose: () => {
  3100. const scrollable = document.querySelector(".scrollable");
  3101. if (scrollable) {
  3102. localStorage.setItem("scrollPos" + window.location.href, `${scrollable.scrollTop}`);
  3103. }
  3104. },
  3105. didOpen: () => {
  3106. const scrollable = document.querySelector(".scrollable");
  3107. if (scrollable) {
  3108. scrollable.scrollTop = parseInt(localStorage.getItem("scrollPos" + window.location.href) || "0");
  3109. }
  3110. }
  3111. });
  3112. });
  3113. }
  3114.  
  3115. // src/index.ts
  3116. function initialize() {
  3117. return __async(this, null, function* () {
  3118. yield new Promise((r) => window.addEventListener("load", r));
  3119. yield new Promise((r) => setTimeout(r, 1e3));
  3120. });
  3121. }
  3122. (() => __async(void 0, null, function* () {
  3123. yield initialize();
  3124. function displayReadMode() {
  3125. let html = (0, import_chatgpt.getResponseElementHTMLs)();
  3126. if (html.length === 0) {
  3127. html = ["<p>No responses available.</p>"];
  3128. }
  3129. displayHTML(html);
  3130. }
  3131. GM_registerMenuCommand("\u{1F4D6} Read Mode", displayReadMode);
  3132. }))();
  3133. })();
  3134. /*! Bundled license information:
  3135.  
  3136. sweetalert2/dist/sweetalert2.all.js:
  3137. (*!
  3138. * sweetalert2 v11.7.18
  3139. * Released under the MIT License.
  3140. *)
  3141. */

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址