ChatGPT 阅读模式

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

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

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

QingJ © 2025

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