ChatGPT 阅读模式

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

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

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