🏠 返回首頁 

Greasy Fork is available in English.

Режим чтения ChatGPT

🍞 Показать модальное окно для чтения


Установить этот скрипт?
Рекомендуемый автором скрипт

Вам также может понравится ChatGPT Авто-Продолжение 🔄.


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