PT 助手

私密种子站点的助手

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

  1. // ==UserScript==
  2. // @name PT Helper
  3. // @name:zh-CN PT 助手
  4. // @version 0.1.4
  5. // @namespace https://github.com/amorphobia/pt-helper
  6. // @description A helper for private trackers
  7. // @description:zh-CN 私密种子站点的助手
  8. // @author amorphobia
  9. // @homepage https://github.com/amorphobia/pt-helper
  10. // @icon data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48ZGVmcz48c3R5bGU+Lmd7ZmlsbDojMDVmZmExfS5ie2ZpbGw6IzcxYzdlY30ucntmaWxsOiNmZjUyNTJ9LnB7ZmlsbDojNjU3MzdlfTwvc3R5bGU+PC9kZWZzPjx0aXRsZT5zaGFyZS1maWxsZWQ8L3RpdGxlPjxwYXRoIGNsYXNzPSJwIiBkPSJNNDA1LjMzLDI5OC42N2ExMDYuNTQsMTA2LjU0LDAsMCwwLTgzLjksNDAuODZMMjA5LjY5LDI4My42NmExMDYuNzgsMTA2Ljc4LDAsMCwwLDAtNTUuMzFsMTExLjc1LTU1Ljg3YTEwNi4yNywxMDYuMjcsMCwxLDAtMTkuMTMtMzguMTVMMTkwLjU2LDE5MC4yYTEwNi42NywxMDYuNjcsMCwxLDAsMCwxMzEuNmwxMTEuNzUsNTUuODdhMTA2LjY3LDEwNi42NywwLDEsMCwxMDMtNzlaIi8+PGNpcmNsZSBjbGFzcz0iZyIgY3g9IjQwNS4zMyIgY3k9IjEwNi42NyIgcj0iNjQiLz48Y2lyY2xlIGNsYXNzPSJiIiBjeD0iNDA1LjMzIiBjeT0iNDA1LjMzIiByPSI2NCIvPjxjaXJjbGUgY2xhc3M9InIiIGN4PSIxMDYuNjciIGN5PSIyNTYiIHI9IjY0Ii8+PC9zdmc+
  11. // @supportURL https://github.com/amorphobia/pt-helper/issues
  12. // @license AGPL-3.0-or-later
  13. // @match *://hhanclub.top/*
  14. // @match *://nanyangpt.com/*
  15. // @match *://pt.sjtu.edu.cn/*
  16. // @match *://tjupt.org/*
  17. // @require https://cdn.jsdelivr.net/npm/sweetalert2@11.4.8
  18. // @require https://cdn.jsdelivr.net/npm/clipboard@2.0.11
  19. // @grant GM_addStyle
  20. // @grant GM_registerMenuCommand
  21. // @grant GM_unregisterMenuCommand
  22. // @grant GM_openInTab
  23. // @grant GM_getValue
  24. // @grant GM_setValue
  25. // @grant GM_notification
  26. // @grant GM_xmlhttpRequest
  27. // @noframes
  28. // ==/UserScript==
  29.  
  30. /******/ (() => { // webpackBootstrap
  31. /******/ var __webpack_modules__ = ([
  32. /* 0 */,
  33. /* 1 */
  34. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  35.  
  36. "use strict";
  37.  
  38. Object.defineProperty(exports, "__esModule", ({ value: true }));
  39. exports.Hhanclub = void 0;
  40. const index_1 = __webpack_require__(2);
  41. class Hhanclub extends index_1.NexusPHP {
  42. constructor() {
  43. super("hhanclub.top");
  44. this.menu_items = [
  45. {
  46. "id": "bannerFold",
  47. "type": "switch",
  48. "display": "自动折叠横幅(隐藏时折叠设置无效)",
  49. "name": "自动折叠横幅",
  50. "value": true
  51. },
  52. {
  53. "id": "bannerHide",
  54. "type": "switch",
  55. "display": "隐藏横幅(隐藏时折叠设置无效)",
  56. "name": "隐藏横幅",
  57. "value": false
  58. }
  59. ].concat(this.menu_items);
  60. }
  61. onLoad() {
  62. super.onLoad();
  63. }
  64. tweakBanner() {
  65. if (this.getHostValue("bannerHide")) {
  66. this.css += `
  67. td.clear.nowrap img {
  68. display: none;
  69. }`;
  70. }
  71. else if (this.getHostValue("bannerFold")) {
  72. const banner = document.querySelector("td.clear.nowrap");
  73. const original_height = banner === null || banner === void 0 ? void 0 : banner.clientHeight;
  74. this.css += `
  75. td.clear.nowrap img {
  76. height: 10px;
  77. overflow: hidden;
  78. transition: height 0.5s;
  79. }
  80.  
  81. td.clear.nowrap img:hover {
  82. height: ${original_height}px;
  83. }`;
  84. }
  85. }
  86. }
  87. exports.Hhanclub = Hhanclub;
  88.  
  89.  
  90. /***/ }),
  91. /* 2 */
  92. /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
  93.  
  94. "use strict";
  95.  
  96. var __importDefault = (this && this.__importDefault) || function (mod) {
  97. return (mod && mod.__esModule) ? mod : { "default": mod };
  98. };
  99. Object.defineProperty(exports, "__esModule", ({ value: true }));
  100. exports.NexusPHP = void 0;
  101. const common_1 = __webpack_require__(3);
  102. const clipboard_1 = __importDefault(__webpack_require__(4));
  103. const sweetalert2_1 = __importDefault(__webpack_require__(5));
  104. class NexusPHP extends common_1.Common {
  105. constructor(host) {
  106. super(host);
  107. this.passkey = "";
  108. this.menu_items = [
  109. {
  110. "id": "thanks",
  111. "type": "switch",
  112. "display": "自动说谢谢",
  113. "name": "自动说谢谢",
  114. "value": true
  115. },
  116. {
  117. "id": "directLink",
  118. "type": "switch",
  119. "display": "种子直链按钮(左键点击按钮复制直链)",
  120. "name": "种子直链",
  121. "value": true
  122. }
  123. ].concat(this.menu_items);
  124. }
  125. onLoad() {
  126. super.onLoad();
  127. this.getPasskey();
  128. this.tweakBanner();
  129. this.sayThanks();
  130. this.addDirectLink();
  131. }
  132. getPasskey() {
  133. const value = this.getHostValue("passkey");
  134. let passkey = "";
  135. if (value) {
  136. passkey = String(value);
  137. }
  138. if (passkey != "") {
  139. this.passkey = passkey;
  140. return;
  141. }
  142. const cp_url = "https://" + this.host + "/usercp.php";
  143. GM_xmlhttpRequest({
  144. method: "GET",
  145. url: cp_url,
  146. onload: (response) => {
  147. if (response.status != 200) {
  148. console.log("Failed to get passkey.");
  149. return;
  150. }
  151. const container = document.implementation.createHTMLDocument().documentElement;
  152. container.innerHTML = response.responseText;
  153. const tds = container.querySelectorAll("td.rowfollow");
  154. for (const td of tds) {
  155. const tc = td;
  156. const re = /[\w\d]{32}/;
  157. const result = re.exec(tc.innerText);
  158. if (result) {
  159. this.setHostValue("passkey", result[0]);
  160. this.passkey = result[0];
  161. return;
  162. }
  163. }
  164. },
  165. onabort: () => {
  166. console.log("Abort to get passkey");
  167. },
  168. onerror: () => {
  169. console.log("Error to get passkey");
  170. }
  171. });
  172. }
  173. tweakBanner() { }
  174. sayThanks() {
  175. if (!this.getHostValue("thanks") || location.href.indexOf("/details.php") < 0) {
  176. return;
  177. }
  178. this.wait(2000).then(() => {
  179. const input = document.querySelector("#saythanks");
  180. if (input && !input.disabled) {
  181. input.click();
  182. }
  183. }).catch(() => { console.log("Failed to say thanks."); });
  184. }
  185. addDirectLink() {
  186. var _a;
  187. if (!this.getHostValue("directLink") || this.passkey == "") {
  188. return;
  189. }
  190. const id_re = /id=[\d]+/;
  191. const trs = document.querySelectorAll("table.torrentname > tbody > tr:nth-of-type(1)");
  192. for (const tr of trs) {
  193. const tds = tr.querySelectorAll("td");
  194. const td = tds.length < 3 ? tds[1] : tds[2];
  195. const dl = td.querySelector("a");
  196. const result = id_re.exec((_a = dl === null || dl === void 0 ? void 0 : dl.href) !== null && _a !== void 0 ? _a : "");
  197. if (!result) {
  198. continue;
  199. }
  200. const direct_link = `https://${this.host}/download.php?${result[0]}&passkey=${this.passkey}`;
  201. const img = document.createElement("img");
  202. img.setAttribute("src", "pic/trans.gif");
  203. img.setAttribute("class", "torrent_direct_link");
  204. img.setAttribute("alt", "DL");
  205. const a = document.createElement("a");
  206. a.setAttribute("title", "左键单击复制,链接中包含个人秘钥Passkey,切勿泄露!");
  207. a.setAttribute("onclick", "return false");
  208. a.setAttribute("id", "direct_link");
  209. a.setAttribute("href", direct_link);
  210. a.setAttribute("data-clipboard-text", direct_link);
  211. a.appendChild(img);
  212. td.prepend(a);
  213. }
  214. this.css += `
  215. .swal2-container {
  216. z-index: 4294967295;
  217. }
  218. h2#swal2-title {
  219. background-color: transparent;
  220. background-image: none;
  221. border: none;
  222. }
  223. img.torrent_direct_link {
  224. width: 16px;
  225. height: 16px;
  226. background: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAH5QTFRFR3BMyKN4cz0Td3d3sLCw6enp////qHg4oaGhcz0TlpaWkV8opnU2lmQrjVklqHg4m2kvo3I03ruJiFMhn24y4r+N2raG5cSP9+jQg04e1rKD68uUnYpv6ceS0q5/fkkaoaGhzqp8h4eHr6+v+Pj4ekQXdkAV+/v78fHxy6Z6f0p3WgAAAAp0Uk5TAP///////5aWlrne7esAAACHSURBVBjTbc5HEsIwEERRA5qxLeecc77/BTEN0oq/m1ddKhnG36xxtPRhBq2UxyFlG5gAt5zXk+hc59IFRM3yQksTAdKOf3UpICxYCEFEXIQAL2NCnHkAJ/4s7jh2AH6uFrkPSOrvgrhOAFWvFn0FGCYWhDemAbBd6h/XBtgfuh1gP3X2fb4BlrkIUt3i2kgAAAAASUVORK5CYII=');
  227. padding-bottom: 1px;
  228. }`;
  229. this.registerClipboard("#direct_link");
  230. }
  231. registerClipboard(id) {
  232. const clip = new clipboard_1.default(id);
  233. clip.on("success", () => {
  234. sweetalert2_1.default.fire({
  235. position: "top-end",
  236. icon: "success",
  237. title: "复制成功",
  238. showConfirmButton: false,
  239. timer: 2500,
  240. toast: true
  241. });
  242. });
  243. clip.on("error", err => {
  244. sweetalert2_1.default.fire({
  245. icon: "error",
  246. title: "复制失败",
  247. html: `请手动复制<br><input id="cb-input" style="width: 80%" value="${err.text}">`,
  248. didOpen: () => {
  249. var _a;
  250. (_a = document.getElementById("cb-input")) === null || _a === void 0 ? void 0 : _a.focus();
  251. }
  252. });
  253. });
  254. return clip;
  255. }
  256. }
  257. exports.NexusPHP = NexusPHP;
  258.  
  259.  
  260. /***/ }),
  261. /* 3 */
  262. /***/ ((__unused_webpack_module, exports) => {
  263.  
  264. "use strict";
  265.  
  266. Object.defineProperty(exports, "__esModule", ({ value: true }));
  267. exports.Common = void 0;
  268. const helper_home = "https://github.com/amorphobia/pt-helper";
  269. const num_emoji = ["0️⃣", "1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣", "6️⃣", "7️⃣", "8️⃣", "9️⃣", "🔟"];
  270. class Common {
  271. constructor(host) {
  272. this.host = "";
  273. this.menu_items = [{
  274. "id": "feedback",
  275. "type": "link",
  276. "display": "💬反馈与建议",
  277. "value": helper_home + "/issues"
  278. }];
  279. this.host = host;
  280. this.registered_items = [];
  281. this.css = "";
  282. }
  283. init() {
  284. for (const item of this.menu_items) {
  285. item.id = this.host + "_" + item.id;
  286. if ((item.type == "switch" || item.type == "selection") && GM_getValue(item.id) == null) {
  287. GM_setValue(item.id, item.value);
  288. }
  289. }
  290. this.registerMenu();
  291. }
  292. onLoad() { }
  293. addStyle() {
  294. if (typeof GM_addStyle !== "undefined") {
  295. GM_addStyle(this.css);
  296. }
  297. else {
  298. const style = document.createElement("style");
  299. style.appendChild(document.createTextNode(this.css));
  300. (document.querySelector("head") || document.documentElement).appendChild(style);
  301. }
  302. }
  303. registerMenu() {
  304. for (const item of this.registered_items) {
  305. GM_unregisterMenuCommand(item);
  306. }
  307. this.registered_items = [];
  308. for (const item of this.menu_items) {
  309. const value = GM_getValue(item.id);
  310. if (value != undefined && value != null) {
  311. item.value = value;
  312. }
  313. let reg_item;
  314. switch (item.type) {
  315. case "switch":
  316. reg_item = GM_registerMenuCommand(`${item.value ? "✅" : "❌"}${item.display}`, () => {
  317. this.toggleSwitch(item);
  318. });
  319. break;
  320. case "selection":
  321. reg_item = GM_registerMenuCommand(`${num_emoji[item.value]}${item.display[item.value]}`, () => {
  322. this.nextSelection(item);
  323. });
  324. break;
  325. case "link":
  326. reg_item = GM_registerMenuCommand(`${item.display}`, () => {
  327. GM_openInTab(item.value, { active: true, insert: true, setParent: true });
  328. });
  329. break;
  330. case "text":
  331. reg_item = GM_registerMenuCommand(`${item.display}`, () => { });
  332. break;
  333. default:
  334. console.log(`Unrecognized menu item: ${item.id}`);
  335. break;
  336. }
  337. if (reg_item !== undefined) {
  338. this.registered_items.push(reg_item);
  339. }
  340. }
  341. }
  342. toggleSwitch(item) {
  343. const status = item.value ? "关闭" : "开启";
  344. GM_setValue(item.id, !item.value);
  345. GM_notification({
  346. text: `已${status}「${item.name}」\n(点击刷新网页后生效)`,
  347. timeout: 3500,
  348. onclick: () => { location.reload(); }
  349. });
  350. this.registerMenu();
  351. }
  352. nextSelection(item) {
  353. const new_value = (item.value + 1) % item.display.length;
  354. GM_setValue(item.id, new_value);
  355. GM_notification({
  356. text: `切换为「${item.display[new_value]}」\n(点击刷新网页后生效)`,
  357. timeout: 3500,
  358. onclick: () => { location.reload(); }
  359. });
  360. this.registerMenu();
  361. }
  362. wait(ms) {
  363. return new Promise((resolve, reject) => {
  364. setTimeout(resolve, ms);
  365. });
  366. }
  367. getHostValue(id) {
  368. return GM_getValue(this.host + "_" + id);
  369. }
  370. setHostValue(id, value) {
  371. GM_setValue(this.host + "_" + id, value);
  372. }
  373. }
  374. exports.Common = Common;
  375.  
  376.  
  377. /***/ }),
  378. /* 4 */
  379. /***/ (function(module) {
  380.  
  381. /*!
  382. * clipboard.js v2.0.11
  383. * https://clipboardjs.com/
  384. *
  385. * Licensed MIT © Zeno Rocha
  386. */
  387. (function webpackUniversalModuleDefinition(root, factory) {
  388. if(true)
  389. module.exports = factory();
  390. else {}
  391. })(this, function() {
  392. return /******/ (function() { // webpackBootstrap
  393. /******/ var __webpack_modules__ = ({
  394.  
  395. /***/ 686:
  396. /***/ (function(__unused_webpack_module, __webpack_exports__, __nested_webpack_require_623__) {
  397.  
  398. "use strict";
  399.  
  400. // EXPORTS
  401. __nested_webpack_require_623__.d(__webpack_exports__, {
  402. "default": function() { return /* binding */ clipboard; }
  403. });
  404.  
  405. // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js
  406. var tiny_emitter = __nested_webpack_require_623__(279);
  407. var tiny_emitter_default = /*#__PURE__*/__nested_webpack_require_623__.n(tiny_emitter);
  408. // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js
  409. var listen = __nested_webpack_require_623__(370);
  410. var listen_default = /*#__PURE__*/__nested_webpack_require_623__.n(listen);
  411. // EXTERNAL MODULE: ./node_modules/select/src/select.js
  412. var src_select = __nested_webpack_require_623__(817);
  413. var select_default = /*#__PURE__*/__nested_webpack_require_623__.n(src_select);
  414. ;// CONCATENATED MODULE: ./src/common/command.js
  415. /**
  416. * Executes a given operation type.
  417. * @param {String} type
  418. * @return {Boolean}
  419. */
  420. function command(type) {
  421. try {
  422. return document.execCommand(type);
  423. } catch (err) {
  424. return false;
  425. }
  426. }
  427. ;// CONCATENATED MODULE: ./src/actions/cut.js
  428.  
  429.  
  430. /**
  431. * Cut action wrapper.
  432. * @param {String|HTMLElement} target
  433. * @return {String}
  434. */
  435.  
  436. var ClipboardActionCut = function ClipboardActionCut(target) {
  437. var selectedText = select_default()(target);
  438. command('cut');
  439. return selectedText;
  440. };
  441.  
  442. /* harmony default export */ var actions_cut = (ClipboardActionCut);
  443. ;// CONCATENATED MODULE: ./src/common/create-fake-element.js
  444. /**
  445. * Creates a fake textarea element with a value.
  446. * @param {String} value
  447. * @return {HTMLElement}
  448. */
  449. function createFakeElement(value) {
  450. var isRTL = document.documentElement.getAttribute('dir') === 'rtl';
  451. var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS
  452.  
  453. fakeElement.style.fontSize = '12pt'; // Reset box model
  454.  
  455. fakeElement.style.border = '0';
  456. fakeElement.style.padding = '0';
  457. fakeElement.style.margin = '0'; // Move element out of screen horizontally
  458.  
  459. fakeElement.style.position = 'absolute';
  460. fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
  461.  
  462. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  463. fakeElement.style.top = "".concat(yPosition, "px");
  464. fakeElement.setAttribute('readonly', '');
  465. fakeElement.value = value;
  466. return fakeElement;
  467. }
  468. ;// CONCATENATED MODULE: ./src/actions/copy.js
  469.  
  470.  
  471.  
  472. /**
  473. * Create fake copy action wrapper using a fake element.
  474. * @param {String} target
  475. * @param {Object} options
  476. * @return {String}
  477. */
  478.  
  479. var fakeCopyAction = function fakeCopyAction(value, options) {
  480. var fakeElement = createFakeElement(value);
  481. options.container.appendChild(fakeElement);
  482. var selectedText = select_default()(fakeElement);
  483. command('copy');
  484. fakeElement.remove();
  485. return selectedText;
  486. };
  487. /**
  488. * Copy action wrapper.
  489. * @param {String|HTMLElement} target
  490. * @param {Object} options
  491. * @return {String}
  492. */
  493.  
  494.  
  495. var ClipboardActionCopy = function ClipboardActionCopy(target) {
  496. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  497. container: document.body
  498. };
  499. var selectedText = '';
  500.  
  501. if (typeof target === 'string') {
  502. selectedText = fakeCopyAction(target, options);
  503. } else if (target instanceof HTMLInputElement && !['text', 'search', 'url', 'tel', 'password'].includes(target === null || target === void 0 ? void 0 : target.type)) {
  504. // If input type doesn't support `setSelectionRange`. Simulate it. https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange
  505. selectedText = fakeCopyAction(target.value, options);
  506. } else {
  507. selectedText = select_default()(target);
  508. command('copy');
  509. }
  510.  
  511. return selectedText;
  512. };
  513.  
  514. /* harmony default export */ var actions_copy = (ClipboardActionCopy);
  515. ;// CONCATENATED MODULE: ./src/actions/default.js
  516. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  517.  
  518.  
  519.  
  520. /**
  521. * Inner function which performs selection from either `text` or `target`
  522. * properties and then executes copy or cut operations.
  523. * @param {Object} options
  524. */
  525.  
  526. var ClipboardActionDefault = function ClipboardActionDefault() {
  527. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  528. // Defines base properties passed from constructor.
  529. var _options$action = options.action,
  530. action = _options$action === void 0 ? 'copy' : _options$action,
  531. container = options.container,
  532. target = options.target,
  533. text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.
  534.  
  535. if (action !== 'copy' && action !== 'cut') {
  536. throw new Error('Invalid "action" value, use either "copy" or "cut"');
  537. } // Sets the `target` property using an element that will be have its content copied.
  538.  
  539.  
  540. if (target !== undefined) {
  541. if (target && _typeof(target) === 'object' && target.nodeType === 1) {
  542. if (action === 'copy' && target.hasAttribute('disabled')) {
  543. throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  544. }
  545.  
  546. if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
  547. throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  548. }
  549. } else {
  550. throw new Error('Invalid "target" value, use a valid Element');
  551. }
  552. } // Define selection strategy based on `text` property.
  553.  
  554.  
  555. if (text) {
  556. return actions_copy(text, {
  557. container: container
  558. });
  559. } // Defines which selection strategy based on `target` property.
  560.  
  561.  
  562. if (target) {
  563. return action === 'cut' ? actions_cut(target) : actions_copy(target, {
  564. container: container
  565. });
  566. }
  567. };
  568.  
  569. /* harmony default export */ var actions_default = (ClipboardActionDefault);
  570. ;// CONCATENATED MODULE: ./src/clipboard.js
  571. function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); }
  572.  
  573. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  574.  
  575. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  576.  
  577. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  578.  
  579. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  580.  
  581. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  582.  
  583. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  584.  
  585. function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  586.  
  587. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  588.  
  589. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  590.  
  591. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598. /**
  599. * Helper function to retrieve attribute value.
  600. * @param {String} suffix
  601. * @param {Element} element
  602. */
  603.  
  604. function getAttributeValue(suffix, element) {
  605. var attribute = "data-clipboard-".concat(suffix);
  606.  
  607. if (!element.hasAttribute(attribute)) {
  608. return;
  609. }
  610.  
  611. return element.getAttribute(attribute);
  612. }
  613. /**
  614. * Base class which takes one or more elements, adds event listeners to them,
  615. * and instantiates a new `ClipboardAction` on each click.
  616. */
  617.  
  618.  
  619. var Clipboard = /*#__PURE__*/function (_Emitter) {
  620. _inherits(Clipboard, _Emitter);
  621.  
  622. var _super = _createSuper(Clipboard);
  623.  
  624. /**
  625. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  626. * @param {Object} options
  627. */
  628. function Clipboard(trigger, options) {
  629. var _this;
  630.  
  631. _classCallCheck(this, Clipboard);
  632.  
  633. _this = _super.call(this);
  634.  
  635. _this.resolveOptions(options);
  636.  
  637. _this.listenClick(trigger);
  638.  
  639. return _this;
  640. }
  641. /**
  642. * Defines if attributes would be resolved using internal setter functions
  643. * or custom functions that were passed in the constructor.
  644. * @param {Object} options
  645. */
  646.  
  647.  
  648. _createClass(Clipboard, [{
  649. key: "resolveOptions",
  650. value: function resolveOptions() {
  651. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  652. this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
  653. this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
  654. this.text = typeof options.text === 'function' ? options.text : this.defaultText;
  655. this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
  656. }
  657. /**
  658. * Adds a click event listener to the passed trigger.
  659. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  660. */
  661.  
  662. }, {
  663. key: "listenClick",
  664. value: function listenClick(trigger) {
  665. var _this2 = this;
  666.  
  667. this.listener = listen_default()(trigger, 'click', function (e) {
  668. return _this2.onClick(e);
  669. });
  670. }
  671. /**
  672. * Defines a new `ClipboardAction` on each click event.
  673. * @param {Event} e
  674. */
  675.  
  676. }, {
  677. key: "onClick",
  678. value: function onClick(e) {
  679. var trigger = e.delegateTarget || e.currentTarget;
  680. var action = this.action(trigger) || 'copy';
  681. var text = actions_default({
  682. action: action,
  683. container: this.container,
  684. target: this.target(trigger),
  685. text: this.text(trigger)
  686. }); // Fires an event based on the copy operation result.
  687.  
  688. this.emit(text ? 'success' : 'error', {
  689. action: action,
  690. text: text,
  691. trigger: trigger,
  692. clearSelection: function clearSelection() {
  693. if (trigger) {
  694. trigger.focus();
  695. }
  696.  
  697. window.getSelection().removeAllRanges();
  698. }
  699. });
  700. }
  701. /**
  702. * Default `action` lookup function.
  703. * @param {Element} trigger
  704. */
  705.  
  706. }, {
  707. key: "defaultAction",
  708. value: function defaultAction(trigger) {
  709. return getAttributeValue('action', trigger);
  710. }
  711. /**
  712. * Default `target` lookup function.
  713. * @param {Element} trigger
  714. */
  715.  
  716. }, {
  717. key: "defaultTarget",
  718. value: function defaultTarget(trigger) {
  719. var selector = getAttributeValue('target', trigger);
  720.  
  721. if (selector) {
  722. return document.querySelector(selector);
  723. }
  724. }
  725. /**
  726. * Allow fire programmatically a copy action
  727. * @param {String|HTMLElement} target
  728. * @param {Object} options
  729. * @returns Text copied.
  730. */
  731.  
  732. }, {
  733. key: "defaultText",
  734.  
  735. /**
  736. * Default `text` lookup function.
  737. * @param {Element} trigger
  738. */
  739. value: function defaultText(trigger) {
  740. return getAttributeValue('text', trigger);
  741. }
  742. /**
  743. * Destroy lifecycle.
  744. */
  745.  
  746. }, {
  747. key: "destroy",
  748. value: function destroy() {
  749. this.listener.destroy();
  750. }
  751. }], [{
  752. key: "copy",
  753. value: function copy(target) {
  754. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  755. container: document.body
  756. };
  757. return actions_copy(target, options);
  758. }
  759. /**
  760. * Allow fire programmatically a cut action
  761. * @param {String|HTMLElement} target
  762. * @returns Text cutted.
  763. */
  764.  
  765. }, {
  766. key: "cut",
  767. value: function cut(target) {
  768. return actions_cut(target);
  769. }
  770. /**
  771. * Returns the support of the given action, or all actions if no action is
  772. * given.
  773. * @param {String} [action]
  774. */
  775.  
  776. }, {
  777. key: "isSupported",
  778. value: function isSupported() {
  779. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
  780. var actions = typeof action === 'string' ? [action] : action;
  781. var support = !!document.queryCommandSupported;
  782. actions.forEach(function (action) {
  783. support = support && !!document.queryCommandSupported(action);
  784. });
  785. return support;
  786. }
  787. }]);
  788.  
  789. return Clipboard;
  790. }((tiny_emitter_default()));
  791.  
  792. /* harmony default export */ var clipboard = (Clipboard);
  793.  
  794. /***/ }),
  795.  
  796. /***/ 828:
  797. /***/ (function(module) {
  798.  
  799. var DOCUMENT_NODE_TYPE = 9;
  800.  
  801. /**
  802. * A polyfill for Element.matches()
  803. */
  804. if (typeof Element !== 'undefined' && !Element.prototype.matches) {
  805. var proto = Element.prototype;
  806.  
  807. proto.matches = proto.matchesSelector ||
  808. proto.mozMatchesSelector ||
  809. proto.msMatchesSelector ||
  810. proto.oMatchesSelector ||
  811. proto.webkitMatchesSelector;
  812. }
  813.  
  814. /**
  815. * Finds the closest parent that matches a selector.
  816. *
  817. * @param {Element} element
  818. * @param {String} selector
  819. * @return {Function}
  820. */
  821. function closest (element, selector) {
  822. while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
  823. if (typeof element.matches === 'function' &&
  824. element.matches(selector)) {
  825. return element;
  826. }
  827. element = element.parentNode;
  828. }
  829. }
  830.  
  831. module.exports = closest;
  832.  
  833.  
  834. /***/ }),
  835.  
  836. /***/ 438:
  837. /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_15749__) {
  838.  
  839. var closest = __nested_webpack_require_15749__(828);
  840.  
  841. /**
  842. * Delegates event to a selector.
  843. *
  844. * @param {Element} element
  845. * @param {String} selector
  846. * @param {String} type
  847. * @param {Function} callback
  848. * @param {Boolean} useCapture
  849. * @return {Object}
  850. */
  851. function _delegate(element, selector, type, callback, useCapture) {
  852. var listenerFn = listener.apply(this, arguments);
  853.  
  854. element.addEventListener(type, listenerFn, useCapture);
  855.  
  856. return {
  857. destroy: function() {
  858. element.removeEventListener(type, listenerFn, useCapture);
  859. }
  860. }
  861. }
  862.  
  863. /**
  864. * Delegates event to a selector.
  865. *
  866. * @param {Element|String|Array} [elements]
  867. * @param {String} selector
  868. * @param {String} type
  869. * @param {Function} callback
  870. * @param {Boolean} useCapture
  871. * @return {Object}
  872. */
  873. function delegate(elements, selector, type, callback, useCapture) {
  874. // Handle the regular Element usage
  875. if (typeof elements.addEventListener === 'function') {
  876. return _delegate.apply(null, arguments);
  877. }
  878.  
  879. // Handle Element-less usage, it defaults to global delegation
  880. if (typeof type === 'function') {
  881. // Use `document` as the first parameter, then apply arguments
  882. // This is a short way to .unshift `arguments` without running into deoptimizations
  883. return _delegate.bind(null, document).apply(null, arguments);
  884. }
  885.  
  886. // Handle Selector-based usage
  887. if (typeof elements === 'string') {
  888. elements = document.querySelectorAll(elements);
  889. }
  890.  
  891. // Handle Array-like based usage
  892. return Array.prototype.map.call(elements, function (element) {
  893. return _delegate(element, selector, type, callback, useCapture);
  894. });
  895. }
  896.  
  897. /**
  898. * Finds closest match and invokes callback.
  899. *
  900. * @param {Element} element
  901. * @param {String} selector
  902. * @param {String} type
  903. * @param {Function} callback
  904. * @return {Function}
  905. */
  906. function listener(element, selector, type, callback) {
  907. return function(e) {
  908. e.delegateTarget = closest(e.target, selector);
  909.  
  910. if (e.delegateTarget) {
  911. callback.call(element, e);
  912. }
  913. }
  914. }
  915.  
  916. module.exports = delegate;
  917.  
  918.  
  919. /***/ }),
  920.  
  921. /***/ 879:
  922. /***/ (function(__unused_webpack_module, exports) {
  923.  
  924. /**
  925. * Check if argument is a HTML element.
  926. *
  927. * @param {Object} value
  928. * @return {Boolean}
  929. */
  930. exports.node = function(value) {
  931. return value !== undefined
  932. && value instanceof HTMLElement
  933. && value.nodeType === 1;
  934. };
  935.  
  936. /**
  937. * Check if argument is a list of HTML elements.
  938. *
  939. * @param {Object} value
  940. * @return {Boolean}
  941. */
  942. exports.nodeList = function(value) {
  943. var type = Object.prototype.toString.call(value);
  944.  
  945. return value !== undefined
  946. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  947. && ('length' in value)
  948. && (value.length === 0 || exports.node(value[0]));
  949. };
  950.  
  951. /**
  952. * Check if argument is a string.
  953. *
  954. * @param {Object} value
  955. * @return {Boolean}
  956. */
  957. exports.string = function(value) {
  958. return typeof value === 'string'
  959. || value instanceof String;
  960. };
  961.  
  962. /**
  963. * Check if argument is a function.
  964. *
  965. * @param {Object} value
  966. * @return {Boolean}
  967. */
  968. exports.fn = function(value) {
  969. var type = Object.prototype.toString.call(value);
  970.  
  971. return type === '[object Function]';
  972. };
  973.  
  974.  
  975. /***/ }),
  976.  
  977. /***/ 370:
  978. /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_19113__) {
  979.  
  980. var is = __nested_webpack_require_19113__(879);
  981. var delegate = __nested_webpack_require_19113__(438);
  982.  
  983. /**
  984. * Validates all params and calls the right
  985. * listener function based on its target type.
  986. *
  987. * @param {String|HTMLElement|HTMLCollection|NodeList} target
  988. * @param {String} type
  989. * @param {Function} callback
  990. * @return {Object}
  991. */
  992. function listen(target, type, callback) {
  993. if (!target && !type && !callback) {
  994. throw new Error('Missing required arguments');
  995. }
  996.  
  997. if (!is.string(type)) {
  998. throw new TypeError('Second argument must be a String');
  999. }
  1000.  
  1001. if (!is.fn(callback)) {
  1002. throw new TypeError('Third argument must be a Function');
  1003. }
  1004.  
  1005. if (is.node(target)) {
  1006. return listenNode(target, type, callback);
  1007. }
  1008. else if (is.nodeList(target)) {
  1009. return listenNodeList(target, type, callback);
  1010. }
  1011. else if (is.string(target)) {
  1012. return listenSelector(target, type, callback);
  1013. }
  1014. else {
  1015. throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
  1016. }
  1017. }
  1018.  
  1019. /**
  1020. * Adds an event listener to a HTML element
  1021. * and returns a remove listener function.
  1022. *
  1023. * @param {HTMLElement} node
  1024. * @param {String} type
  1025. * @param {Function} callback
  1026. * @return {Object}
  1027. */
  1028. function listenNode(node, type, callback) {
  1029. node.addEventListener(type, callback);
  1030.  
  1031. return {
  1032. destroy: function() {
  1033. node.removeEventListener(type, callback);
  1034. }
  1035. }
  1036. }
  1037.  
  1038. /**
  1039. * Add an event listener to a list of HTML elements
  1040. * and returns a remove listener function.
  1041. *
  1042. * @param {NodeList|HTMLCollection} nodeList
  1043. * @param {String} type
  1044. * @param {Function} callback
  1045. * @return {Object}
  1046. */
  1047. function listenNodeList(nodeList, type, callback) {
  1048. Array.prototype.forEach.call(nodeList, function(node) {
  1049. node.addEventListener(type, callback);
  1050. });
  1051.  
  1052. return {
  1053. destroy: function() {
  1054. Array.prototype.forEach.call(nodeList, function(node) {
  1055. node.removeEventListener(type, callback);
  1056. });
  1057. }
  1058. }
  1059. }
  1060.  
  1061. /**
  1062. * Add an event listener to a selector
  1063. * and returns a remove listener function.
  1064. *
  1065. * @param {String} selector
  1066. * @param {String} type
  1067. * @param {Function} callback
  1068. * @return {Object}
  1069. */
  1070. function listenSelector(selector, type, callback) {
  1071. return delegate(document.body, selector, type, callback);
  1072. }
  1073.  
  1074. module.exports = listen;
  1075.  
  1076.  
  1077. /***/ }),
  1078.  
  1079. /***/ 817:
  1080. /***/ (function(module) {
  1081.  
  1082. function select(element) {
  1083. var selectedText;
  1084.  
  1085. if (element.nodeName === 'SELECT') {
  1086. element.focus();
  1087.  
  1088. selectedText = element.value;
  1089. }
  1090. else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
  1091. var isReadOnly = element.hasAttribute('readonly');
  1092.  
  1093. if (!isReadOnly) {
  1094. element.setAttribute('readonly', '');
  1095. }
  1096.  
  1097. element.select();
  1098. element.setSelectionRange(0, element.value.length);
  1099.  
  1100. if (!isReadOnly) {
  1101. element.removeAttribute('readonly');
  1102. }
  1103.  
  1104. selectedText = element.value;
  1105. }
  1106. else {
  1107. if (element.hasAttribute('contenteditable')) {
  1108. element.focus();
  1109. }
  1110.  
  1111. var selection = window.getSelection();
  1112. var range = document.createRange();
  1113.  
  1114. range.selectNodeContents(element);
  1115. selection.removeAllRanges();
  1116. selection.addRange(range);
  1117.  
  1118. selectedText = selection.toString();
  1119. }
  1120.  
  1121. return selectedText;
  1122. }
  1123.  
  1124. module.exports = select;
  1125.  
  1126.  
  1127. /***/ }),
  1128.  
  1129. /***/ 279:
  1130. /***/ (function(module) {
  1131.  
  1132. function E () {
  1133. // Keep this empty so it's easier to inherit from
  1134. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  1135. }
  1136.  
  1137. E.prototype = {
  1138. on: function (name, callback, ctx) {
  1139. var e = this.e || (this.e = {});
  1140.  
  1141. (e[name] || (e[name] = [])).push({
  1142. fn: callback,
  1143. ctx: ctx
  1144. });
  1145.  
  1146. return this;
  1147. },
  1148.  
  1149. once: function (name, callback, ctx) {
  1150. var self = this;
  1151. function listener () {
  1152. self.off(name, listener);
  1153. callback.apply(ctx, arguments);
  1154. };
  1155.  
  1156. listener._ = callback
  1157. return this.on(name, listener, ctx);
  1158. },
  1159.  
  1160. emit: function (name) {
  1161. var data = [].slice.call(arguments, 1);
  1162. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  1163. var i = 0;
  1164. var len = evtArr.length;
  1165.  
  1166. for (i; i < len; i++) {
  1167. evtArr[i].fn.apply(evtArr[i].ctx, data);
  1168. }
  1169.  
  1170. return this;
  1171. },
  1172.  
  1173. off: function (name, callback) {
  1174. var e = this.e || (this.e = {});
  1175. var evts = e[name];
  1176. var liveEvents = [];
  1177.  
  1178. if (evts && callback) {
  1179. for (var i = 0, len = evts.length; i < len; i++) {
  1180. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  1181. liveEvents.push(evts[i]);
  1182. }
  1183. }
  1184.  
  1185. // Remove event from queue to prevent memory leak
  1186. // Suggested by https://github.com/lazd
  1187. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  1188.  
  1189. (liveEvents.length)
  1190. ? e[name] = liveEvents
  1191. : delete e[name];
  1192.  
  1193. return this;
  1194. }
  1195. };
  1196.  
  1197. module.exports = E;
  1198. module.exports.TinyEmitter = E;
  1199.  
  1200.  
  1201. /***/ })
  1202.  
  1203. /******/ });
  1204. /************************************************************************/
  1205. /******/ // The module cache
  1206. /******/ var __webpack_module_cache__ = {};
  1207. /******/
  1208. /******/ // The require function
  1209. /******/ function __nested_webpack_require_24495__(moduleId) {
  1210. /******/ // Check if module is in cache
  1211. /******/ if(__webpack_module_cache__[moduleId]) {
  1212. /******/ return __webpack_module_cache__[moduleId].exports;
  1213. /******/ }
  1214. /******/ // Create a new module (and put it into the cache)
  1215. /******/ var module = __webpack_module_cache__[moduleId] = {
  1216. /******/ // no module.id needed
  1217. /******/ // no module.loaded needed
  1218. /******/ exports: {}
  1219. /******/ };
  1220. /******/
  1221. /******/ // Execute the module function
  1222. /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_24495__);
  1223. /******/
  1224. /******/ // Return the exports of the module
  1225. /******/ return module.exports;
  1226. /******/ }
  1227. /******/
  1228. /************************************************************************/
  1229. /******/ /* webpack/runtime/compat get default export */
  1230. /******/ !function() {
  1231. /******/ // getDefaultExport function for compatibility with non-harmony modules
  1232. /******/ __nested_webpack_require_24495__.n = function(module) {
  1233. /******/ var getter = module && module.__esModule ?
  1234. /******/ function() { return module['default']; } :
  1235. /******/ function() { return module; };
  1236. /******/ __nested_webpack_require_24495__.d(getter, { a: getter });
  1237. /******/ return getter;
  1238. /******/ };
  1239. /******/ }();
  1240. /******/
  1241. /******/ /* webpack/runtime/define property getters */
  1242. /******/ !function() {
  1243. /******/ // define getter functions for harmony exports
  1244. /******/ __nested_webpack_require_24495__.d = function(exports, definition) {
  1245. /******/ for(var key in definition) {
  1246. /******/ if(__nested_webpack_require_24495__.o(definition, key) && !__nested_webpack_require_24495__.o(exports, key)) {
  1247. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  1248. /******/ }
  1249. /******/ }
  1250. /******/ };
  1251. /******/ }();
  1252. /******/
  1253. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  1254. /******/ !function() {
  1255. /******/ __nested_webpack_require_24495__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  1256. /******/ }();
  1257. /******/
  1258. /************************************************************************/
  1259. /******/ // module exports must be returned from runtime so entry inlining is disabled
  1260. /******/ // startup
  1261. /******/ // Load entry module and return exports
  1262. /******/ return __nested_webpack_require_24495__(686);
  1263. /******/ })()
  1264. .default;
  1265. });
  1266.  
  1267. /***/ }),
  1268. /* 5 */
  1269. /***/ (function(module) {
  1270.  
  1271. /*!
  1272. * sweetalert2 v11.4.8
  1273. * Released under the MIT License.
  1274. */
  1275. (function (global, factory) {
  1276. true ? module.exports = factory() :
  1277. 0;
  1278. }(this, function () { 'use strict';
  1279.  
  1280. const consolePrefix = 'SweetAlert2:';
  1281. /**
  1282. * Filter the unique values into a new array
  1283. * @param arr
  1284. */
  1285.  
  1286. const uniqueArray = arr => {
  1287. const result = [];
  1288.  
  1289. for (let i = 0; i < arr.length; i++) {
  1290. if (result.indexOf(arr[i]) === -1) {
  1291. result.push(arr[i]);
  1292. }
  1293. }
  1294.  
  1295. return result;
  1296. };
  1297. /**
  1298. * Capitalize the first letter of a string
  1299. * @param {string} str
  1300. * @returns {string}
  1301. */
  1302.  
  1303. const capitalizeFirstLetter = str => str.charAt(0).toUpperCase() + str.slice(1);
  1304. /**
  1305. * @param {NodeList | HTMLCollection | NamedNodeMap} nodeList
  1306. * @returns {array}
  1307. */
  1308.  
  1309. const toArray = nodeList => Array.prototype.slice.call(nodeList);
  1310. /**
  1311. * Standardize console warnings
  1312. * @param {string | array} message
  1313. */
  1314.  
  1315. const warn = message => {
  1316. console.warn("".concat(consolePrefix, " ").concat(typeof message === 'object' ? message.join(' ') : message));
  1317. };
  1318. /**
  1319. * Standardize console errors
  1320. * @param {string} message
  1321. */
  1322.  
  1323. const error = message => {
  1324. console.error("".concat(consolePrefix, " ").concat(message));
  1325. };
  1326. /**
  1327. * Private global state for `warnOnce`
  1328. * @type {Array}
  1329. * @private
  1330. */
  1331.  
  1332. const previousWarnOnceMessages = [];
  1333. /**
  1334. * Show a console warning, but only if it hasn't already been shown
  1335. * @param {string} message
  1336. */
  1337.  
  1338. const warnOnce = message => {
  1339. if (!previousWarnOnceMessages.includes(message)) {
  1340. previousWarnOnceMessages.push(message);
  1341. warn(message);
  1342. }
  1343. };
  1344. /**
  1345. * Show a one-time console warning about deprecated params/methods
  1346. */
  1347.  
  1348. const warnAboutDeprecation = (deprecatedParam, useInstead) => {
  1349. warnOnce("\"".concat(deprecatedParam, "\" is deprecated and will be removed in the next major release. Please use \"").concat(useInstead, "\" instead."));
  1350. };
  1351. /**
  1352. * If `arg` is a function, call it (with no arguments or context) and return the result.
  1353. * Otherwise, just pass the value through
  1354. * @param arg
  1355. */
  1356.  
  1357. const callIfFunction = arg => typeof arg === 'function' ? arg() : arg;
  1358. const hasToPromiseFn = arg => arg && typeof arg.toPromise === 'function';
  1359. const asPromise = arg => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
  1360. const isPromise = arg => arg && Promise.resolve(arg) === arg;
  1361.  
  1362. const defaultParams = {
  1363. title: '',
  1364. titleText: '',
  1365. text: '',
  1366. html: '',
  1367. footer: '',
  1368. icon: undefined,
  1369. iconColor: undefined,
  1370. iconHtml: undefined,
  1371. template: undefined,
  1372. toast: false,
  1373. showClass: {
  1374. popup: 'swal2-show',
  1375. backdrop: 'swal2-backdrop-show',
  1376. icon: 'swal2-icon-show'
  1377. },
  1378. hideClass: {
  1379. popup: 'swal2-hide',
  1380. backdrop: 'swal2-backdrop-hide',
  1381. icon: 'swal2-icon-hide'
  1382. },
  1383. customClass: {},
  1384. target: 'body',
  1385. color: undefined,
  1386. backdrop: true,
  1387. heightAuto: true,
  1388. allowOutsideClick: true,
  1389. allowEscapeKey: true,
  1390. allowEnterKey: true,
  1391. stopKeydownPropagation: true,
  1392. keydownListenerCapture: false,
  1393. showConfirmButton: true,
  1394. showDenyButton: false,
  1395. showCancelButton: false,
  1396. preConfirm: undefined,
  1397. preDeny: undefined,
  1398. confirmButtonText: 'OK',
  1399. confirmButtonAriaLabel: '',
  1400. confirmButtonColor: undefined,
  1401. denyButtonText: 'No',
  1402. denyButtonAriaLabel: '',
  1403. denyButtonColor: undefined,
  1404. cancelButtonText: 'Cancel',
  1405. cancelButtonAriaLabel: '',
  1406. cancelButtonColor: undefined,
  1407. buttonsStyling: true,
  1408. reverseButtons: false,
  1409. focusConfirm: true,
  1410. focusDeny: false,
  1411. focusCancel: false,
  1412. returnFocus: true,
  1413. showCloseButton: false,
  1414. closeButtonHtml: '&times;',
  1415. closeButtonAriaLabel: 'Close this dialog',
  1416. loaderHtml: '',
  1417. showLoaderOnConfirm: false,
  1418. showLoaderOnDeny: false,
  1419. imageUrl: undefined,
  1420. imageWidth: undefined,
  1421. imageHeight: undefined,
  1422. imageAlt: '',
  1423. timer: undefined,
  1424. timerProgressBar: false,
  1425. width: undefined,
  1426. padding: undefined,
  1427. background: undefined,
  1428. input: undefined,
  1429. inputPlaceholder: '',
  1430. inputLabel: '',
  1431. inputValue: '',
  1432. inputOptions: {},
  1433. inputAutoTrim: true,
  1434. inputAttributes: {},
  1435. inputValidator: undefined,
  1436. returnInputValueOnDeny: false,
  1437. validationMessage: undefined,
  1438. grow: false,
  1439. position: 'center',
  1440. progressSteps: [],
  1441. currentProgressStep: undefined,
  1442. progressStepsDistance: undefined,
  1443. willOpen: undefined,
  1444. didOpen: undefined,
  1445. didRender: undefined,
  1446. willClose: undefined,
  1447. didClose: undefined,
  1448. didDestroy: undefined,
  1449. scrollbarPadding: true
  1450. };
  1451. 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'];
  1452. const deprecatedParams = {};
  1453. const toastIncompatibleParams = ['allowOutsideClick', 'allowEnterKey', 'backdrop', 'focusConfirm', 'focusDeny', 'focusCancel', 'returnFocus', 'heightAuto', 'keydownListenerCapture'];
  1454. /**
  1455. * Is valid parameter
  1456. * @param {string} paramName
  1457. */
  1458.  
  1459. const isValidParameter = paramName => {
  1460. return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
  1461. };
  1462. /**
  1463. * Is valid parameter for Swal.update() method
  1464. * @param {string} paramName
  1465. */
  1466.  
  1467. const isUpdatableParameter = paramName => {
  1468. return updatableParams.indexOf(paramName) !== -1;
  1469. };
  1470. /**
  1471. * Is deprecated parameter
  1472. * @param {string} paramName
  1473. */
  1474.  
  1475. const isDeprecatedParameter = paramName => {
  1476. return deprecatedParams[paramName];
  1477. };
  1478.  
  1479. const checkIfParamIsValid = param => {
  1480. if (!isValidParameter(param)) {
  1481. warn("Unknown parameter \"".concat(param, "\""));
  1482. }
  1483. };
  1484.  
  1485. const checkIfToastParamIsValid = param => {
  1486. if (toastIncompatibleParams.includes(param)) {
  1487. warn("The parameter \"".concat(param, "\" is incompatible with toasts"));
  1488. }
  1489. };
  1490.  
  1491. const checkIfParamIsDeprecated = param => {
  1492. if (isDeprecatedParameter(param)) {
  1493. warnAboutDeprecation(param, isDeprecatedParameter(param));
  1494. }
  1495. };
  1496. /**
  1497. * Show relevant warnings for given params
  1498. *
  1499. * @param params
  1500. */
  1501.  
  1502.  
  1503. const showWarningsForParams = params => {
  1504. if (!params.backdrop && params.allowOutsideClick) {
  1505. warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
  1506. }
  1507.  
  1508. for (const param in params) {
  1509. checkIfParamIsValid(param);
  1510.  
  1511. if (params.toast) {
  1512. checkIfToastParamIsValid(param);
  1513. }
  1514.  
  1515. checkIfParamIsDeprecated(param);
  1516. }
  1517. };
  1518.  
  1519. const swalPrefix = 'swal2-';
  1520. const prefix = items => {
  1521. const result = {};
  1522.  
  1523. for (const i in items) {
  1524. result[items[i]] = swalPrefix + items[i];
  1525. }
  1526.  
  1527. return result;
  1528. };
  1529. const swalClasses = prefix(['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']);
  1530. const iconTypes = prefix(['success', 'warning', 'info', 'question', 'error']);
  1531.  
  1532. /**
  1533. * Gets the popup container which contains the backdrop and the popup itself.
  1534. *
  1535. * @returns {HTMLElement | null}
  1536. */
  1537.  
  1538. const getContainer = () => document.body.querySelector(".".concat(swalClasses.container));
  1539. const elementBySelector = selectorString => {
  1540. const container = getContainer();
  1541. return container ? container.querySelector(selectorString) : null;
  1542. };
  1543.  
  1544. const elementByClass = className => {
  1545. return elementBySelector(".".concat(className));
  1546. };
  1547.  
  1548. const getPopup = () => elementByClass(swalClasses.popup);
  1549. const getIcon = () => elementByClass(swalClasses.icon);
  1550. const getTitle = () => elementByClass(swalClasses.title);
  1551. const getHtmlContainer = () => elementByClass(swalClasses['html-container']);
  1552. const getImage = () => elementByClass(swalClasses.image);
  1553. const getProgressSteps = () => elementByClass(swalClasses['progress-steps']);
  1554. const getValidationMessage = () => elementByClass(swalClasses['validation-message']);
  1555. const getConfirmButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.confirm));
  1556. const getDenyButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.deny));
  1557. const getInputLabel = () => elementByClass(swalClasses['input-label']);
  1558. const getLoader = () => elementBySelector(".".concat(swalClasses.loader));
  1559. const getCancelButton = () => elementBySelector(".".concat(swalClasses.actions, " .").concat(swalClasses.cancel));
  1560. const getActions = () => elementByClass(swalClasses.actions);
  1561. const getFooter = () => elementByClass(swalClasses.footer);
  1562. const getTimerProgressBar = () => elementByClass(swalClasses['timer-progress-bar']);
  1563. const getCloseButton = () => elementByClass(swalClasses.close); // https://github.com/jkup/focusable/blob/master/index.js
  1564.  
  1565. const focusable = "\n a[href],\n area[href],\n input:not([disabled]),\n select:not([disabled]),\n textarea:not([disabled]),\n button:not([disabled]),\n iframe,\n object,\n embed,\n [tabindex=\"0\"],\n [contenteditable],\n audio[controls],\n video[controls],\n summary\n";
  1566. const getFocusableElements = () => {
  1567. const focusableElementsWithTabindex = toArray(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')) // sort according to tabindex
  1568. .sort((a, b) => {
  1569. const tabindexA = parseInt(a.getAttribute('tabindex'));
  1570. const tabindexB = parseInt(b.getAttribute('tabindex'));
  1571.  
  1572. if (tabindexA > tabindexB) {
  1573. return 1;
  1574. } else if (tabindexA < tabindexB) {
  1575. return -1;
  1576. }
  1577.  
  1578. return 0;
  1579. });
  1580. const otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(el => el.getAttribute('tabindex') !== '-1');
  1581. return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el));
  1582. };
  1583. const isModal = () => {
  1584. return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses['toast-shown']) && !hasClass(document.body, swalClasses['no-backdrop']);
  1585. };
  1586. const isToast = () => {
  1587. return getPopup() && hasClass(getPopup(), swalClasses.toast);
  1588. };
  1589. const isLoading = () => {
  1590. return getPopup().hasAttribute('data-loading');
  1591. };
  1592.  
  1593. const states = {
  1594. previousBodyPadding: null
  1595. };
  1596. /**
  1597. * Securely set innerHTML of an element
  1598. * https://github.com/sweetalert2/sweetalert2/issues/1926
  1599. *
  1600. * @param {HTMLElement} elem
  1601. * @param {string} html
  1602. */
  1603.  
  1604. const setInnerHtml = (elem, html) => {
  1605. elem.textContent = '';
  1606.  
  1607. if (html) {
  1608. const parser = new DOMParser();
  1609. const parsed = parser.parseFromString(html, "text/html");
  1610. toArray(parsed.querySelector('head').childNodes).forEach(child => {
  1611. elem.appendChild(child);
  1612. });
  1613. toArray(parsed.querySelector('body').childNodes).forEach(child => {
  1614. elem.appendChild(child);
  1615. });
  1616. }
  1617. };
  1618. /**
  1619. * @param {HTMLElement} elem
  1620. * @param {string} className
  1621. * @returns {boolean}
  1622. */
  1623.  
  1624. const hasClass = (elem, className) => {
  1625. if (!className) {
  1626. return false;
  1627. }
  1628.  
  1629. const classList = className.split(/\s+/);
  1630.  
  1631. for (let i = 0; i < classList.length; i++) {
  1632. if (!elem.classList.contains(classList[i])) {
  1633. return false;
  1634. }
  1635. }
  1636.  
  1637. return true;
  1638. };
  1639.  
  1640. const removeCustomClasses = (elem, params) => {
  1641. toArray(elem.classList).forEach(className => {
  1642. if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass).includes(className)) {
  1643. elem.classList.remove(className);
  1644. }
  1645. });
  1646. };
  1647.  
  1648. const applyCustomClass = (elem, params, className) => {
  1649. removeCustomClasses(elem, params);
  1650.  
  1651. if (params.customClass && params.customClass[className]) {
  1652. if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
  1653. return warn("Invalid type of customClass.".concat(className, "! Expected string or iterable object, got \"").concat(typeof params.customClass[className], "\""));
  1654. }
  1655.  
  1656. addClass(elem, params.customClass[className]);
  1657. }
  1658. };
  1659. /**
  1660. * @param {HTMLElement} popup
  1661. * @param {string} inputType
  1662. * @returns {HTMLInputElement | null}
  1663. */
  1664.  
  1665. const getInput = (popup, inputType) => {
  1666. if (!inputType) {
  1667. return null;
  1668. }
  1669.  
  1670. switch (inputType) {
  1671. case 'select':
  1672. case 'textarea':
  1673. case 'file':
  1674. return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses[inputType]));
  1675.  
  1676. case 'checkbox':
  1677. return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.checkbox, " input"));
  1678.  
  1679. case 'radio':
  1680. return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:checked")) || popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.radio, " input:first-child"));
  1681.  
  1682. case 'range':
  1683. return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.range, " input"));
  1684.  
  1685. default:
  1686. return popup.querySelector(".".concat(swalClasses.popup, " > .").concat(swalClasses.input));
  1687. }
  1688. };
  1689. /**
  1690. * @param {HTMLInputElement} input
  1691. */
  1692.  
  1693. const focusInput = input => {
  1694. input.focus(); // place cursor at end of text in text input
  1695.  
  1696. if (input.type !== 'file') {
  1697. // http://stackoverflow.com/a/2345915
  1698. const val = input.value;
  1699. input.value = '';
  1700. input.value = val;
  1701. }
  1702. };
  1703. /**
  1704. * @param {HTMLElement | HTMLElement[] | null} target
  1705. * @param {string | string[]} classList
  1706. * @param {boolean} condition
  1707. */
  1708.  
  1709. const toggleClass = (target, classList, condition) => {
  1710. if (!target || !classList) {
  1711. return;
  1712. }
  1713.  
  1714. if (typeof classList === 'string') {
  1715. classList = classList.split(/\s+/).filter(Boolean);
  1716. }
  1717.  
  1718. classList.forEach(className => {
  1719. if (Array.isArray(target)) {
  1720. target.forEach(elem => {
  1721. condition ? elem.classList.add(className) : elem.classList.remove(className);
  1722. });
  1723. } else {
  1724. condition ? target.classList.add(className) : target.classList.remove(className);
  1725. }
  1726. });
  1727. };
  1728. /**
  1729. * @param {HTMLElement | HTMLElement[] | null} target
  1730. * @param {string | string[]} classList
  1731. */
  1732.  
  1733. const addClass = (target, classList) => {
  1734. toggleClass(target, classList, true);
  1735. };
  1736. /**
  1737. * @param {HTMLElement | HTMLElement[] | null} target
  1738. * @param {string | string[]} classList
  1739. */
  1740.  
  1741. const removeClass = (target, classList) => {
  1742. toggleClass(target, classList, false);
  1743. };
  1744. /**
  1745. * Get direct child of an element by class name
  1746. *
  1747. * @param {HTMLElement} elem
  1748. * @param {string} className
  1749. * @returns {HTMLElement | null}
  1750. */
  1751.  
  1752. const getDirectChildByClass = (elem, className) => {
  1753. const childNodes = toArray(elem.childNodes);
  1754.  
  1755. for (let i = 0; i < childNodes.length; i++) {
  1756. if (hasClass(childNodes[i], className)) {
  1757. return childNodes[i];
  1758. }
  1759. }
  1760. };
  1761. /**
  1762. * @param {HTMLElement} elem
  1763. * @param {string} property
  1764. * @param {*} value
  1765. */
  1766.  
  1767. const applyNumericalStyle = (elem, property, value) => {
  1768. if (value === "".concat(parseInt(value))) {
  1769. value = parseInt(value);
  1770. }
  1771.  
  1772. if (value || parseInt(value) === 0) {
  1773. elem.style[property] = typeof value === 'number' ? "".concat(value, "px") : value;
  1774. } else {
  1775. elem.style.removeProperty(property);
  1776. }
  1777. };
  1778. /**
  1779. * @param {HTMLElement} elem
  1780. * @param {string} display
  1781. */
  1782.  
  1783. const show = function (elem) {
  1784. let display = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'flex';
  1785. elem.style.display = display;
  1786. };
  1787. /**
  1788. * @param {HTMLElement} elem
  1789. */
  1790.  
  1791. const hide = elem => {
  1792. elem.style.display = 'none';
  1793. };
  1794. const setStyle = (parent, selector, property, value) => {
  1795. const el = parent.querySelector(selector);
  1796.  
  1797. if (el) {
  1798. el.style[property] = value;
  1799. }
  1800. };
  1801. const toggle = (elem, condition, display) => {
  1802. condition ? show(elem, display) : hide(elem);
  1803. }; // borrowed from jquery $(elem).is(':visible') implementation
  1804.  
  1805. const isVisible = elem => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
  1806. const allButtonsAreHidden = () => !isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton());
  1807. const isScrollable = elem => !!(elem.scrollHeight > elem.clientHeight); // borrowed from https://stackoverflow.com/a/46352119
  1808.  
  1809. const hasCssAnimation = elem => {
  1810. const style = window.getComputedStyle(elem);
  1811. const animDuration = parseFloat(style.getPropertyValue('animation-duration') || '0');
  1812. const transDuration = parseFloat(style.getPropertyValue('transition-duration') || '0');
  1813. return animDuration > 0 || transDuration > 0;
  1814. };
  1815. const animateTimerProgressBar = function (timer) {
  1816. let reset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  1817. const timerProgressBar = getTimerProgressBar();
  1818.  
  1819. if (isVisible(timerProgressBar)) {
  1820. if (reset) {
  1821. timerProgressBar.style.transition = 'none';
  1822. timerProgressBar.style.width = '100%';
  1823. }
  1824.  
  1825. setTimeout(() => {
  1826. timerProgressBar.style.transition = "width ".concat(timer / 1000, "s linear");
  1827. timerProgressBar.style.width = '0%';
  1828. }, 10);
  1829. }
  1830. };
  1831. const stopTimerProgressBar = () => {
  1832. const timerProgressBar = getTimerProgressBar();
  1833. const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  1834. timerProgressBar.style.removeProperty('transition');
  1835. timerProgressBar.style.width = '100%';
  1836. const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  1837. const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
  1838. timerProgressBar.style.removeProperty('transition');
  1839. timerProgressBar.style.width = "".concat(timerProgressBarPercent, "%");
  1840. };
  1841.  
  1842. /**
  1843. * Detect Node env
  1844. *
  1845. * @returns {boolean}
  1846. */
  1847. const isNodeEnv = () => typeof window === 'undefined' || typeof document === 'undefined';
  1848.  
  1849. const RESTORE_FOCUS_TIMEOUT = 100;
  1850.  
  1851. const globalState = {};
  1852.  
  1853. const focusPreviousActiveElement = () => {
  1854. if (globalState.previousActiveElement && globalState.previousActiveElement.focus) {
  1855. globalState.previousActiveElement.focus();
  1856. globalState.previousActiveElement = null;
  1857. } else if (document.body) {
  1858. document.body.focus();
  1859. }
  1860. }; // Restore previous active (focused) element
  1861.  
  1862.  
  1863. const restoreActiveElement = returnFocus => {
  1864. return new Promise(resolve => {
  1865. if (!returnFocus) {
  1866. return resolve();
  1867. }
  1868.  
  1869. const x = window.scrollX;
  1870. const y = window.scrollY;
  1871. globalState.restoreFocusTimeout = setTimeout(() => {
  1872. focusPreviousActiveElement();
  1873. resolve();
  1874. }, RESTORE_FOCUS_TIMEOUT); // issues/900
  1875.  
  1876. window.scrollTo(x, y);
  1877. });
  1878. };
  1879.  
  1880. const sweetHTML = "\n <div aria-labelledby=\"".concat(swalClasses.title, "\" aria-describedby=\"").concat(swalClasses['html-container'], "\" class=\"").concat(swalClasses.popup, "\" tabindex=\"-1\">\n <button type=\"button\" class=\"").concat(swalClasses.close, "\"></button>\n <ul class=\"").concat(swalClasses['progress-steps'], "\"></ul>\n <div class=\"").concat(swalClasses.icon, "\"></div>\n <img class=\"").concat(swalClasses.image, "\" />\n <h2 class=\"").concat(swalClasses.title, "\" id=\"").concat(swalClasses.title, "\"></h2>\n <div class=\"").concat(swalClasses['html-container'], "\" id=\"").concat(swalClasses['html-container'], "\"></div>\n <input class=\"").concat(swalClasses.input, "\" />\n <input type=\"file\" class=\"").concat(swalClasses.file, "\" />\n <div class=\"").concat(swalClasses.range, "\">\n <input type=\"range\" />\n <output></output>\n </div>\n <select class=\"").concat(swalClasses.select, "\"></select>\n <div class=\"").concat(swalClasses.radio, "\"></div>\n <label for=\"").concat(swalClasses.checkbox, "\" class=\"").concat(swalClasses.checkbox, "\">\n <input type=\"checkbox\" />\n <span class=\"").concat(swalClasses.label, "\"></span>\n </label>\n <textarea class=\"").concat(swalClasses.textarea, "\"></textarea>\n <div class=\"").concat(swalClasses['validation-message'], "\" id=\"").concat(swalClasses['validation-message'], "\"></div>\n <div class=\"").concat(swalClasses.actions, "\">\n <div class=\"").concat(swalClasses.loader, "\"></div>\n <button type=\"button\" class=\"").concat(swalClasses.confirm, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.deny, "\"></button>\n <button type=\"button\" class=\"").concat(swalClasses.cancel, "\"></button>\n </div>\n <div class=\"").concat(swalClasses.footer, "\"></div>\n <div class=\"").concat(swalClasses['timer-progress-bar-container'], "\">\n <div class=\"").concat(swalClasses['timer-progress-bar'], "\"></div>\n </div>\n </div>\n").replace(/(^|\n)\s*/g, '');
  1881.  
  1882. const resetOldContainer = () => {
  1883. const oldContainer = getContainer();
  1884.  
  1885. if (!oldContainer) {
  1886. return false;
  1887. }
  1888.  
  1889. oldContainer.remove();
  1890. removeClass([document.documentElement, document.body], [swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]);
  1891. return true;
  1892. };
  1893.  
  1894. const resetValidationMessage = () => {
  1895. globalState.currentInstance.resetValidationMessage();
  1896. };
  1897.  
  1898. const addInputChangeListeners = () => {
  1899. const popup = getPopup();
  1900. const input = getDirectChildByClass(popup, swalClasses.input);
  1901. const file = getDirectChildByClass(popup, swalClasses.file);
  1902. const range = popup.querySelector(".".concat(swalClasses.range, " input"));
  1903. const rangeOutput = popup.querySelector(".".concat(swalClasses.range, " output"));
  1904. const select = getDirectChildByClass(popup, swalClasses.select);
  1905. const checkbox = popup.querySelector(".".concat(swalClasses.checkbox, " input"));
  1906. const textarea = getDirectChildByClass(popup, swalClasses.textarea);
  1907. input.oninput = resetValidationMessage;
  1908. file.onchange = resetValidationMessage;
  1909. select.onchange = resetValidationMessage;
  1910. checkbox.onchange = resetValidationMessage;
  1911. textarea.oninput = resetValidationMessage;
  1912.  
  1913. range.oninput = () => {
  1914. resetValidationMessage();
  1915. rangeOutput.value = range.value;
  1916. };
  1917.  
  1918. range.onchange = () => {
  1919. resetValidationMessage();
  1920. range.nextSibling.value = range.value;
  1921. };
  1922. };
  1923.  
  1924. const getTarget = target => typeof target === 'string' ? document.querySelector(target) : target;
  1925.  
  1926. const setupAccessibility = params => {
  1927. const popup = getPopup();
  1928. popup.setAttribute('role', params.toast ? 'alert' : 'dialog');
  1929. popup.setAttribute('aria-live', params.toast ? 'polite' : 'assertive');
  1930.  
  1931. if (!params.toast) {
  1932. popup.setAttribute('aria-modal', 'true');
  1933. }
  1934. };
  1935.  
  1936. const setupRTL = targetElement => {
  1937. if (window.getComputedStyle(targetElement).direction === 'rtl') {
  1938. addClass(getContainer(), swalClasses.rtl);
  1939. }
  1940. };
  1941. /*
  1942. * Add modal + backdrop to DOM
  1943. */
  1944.  
  1945.  
  1946. const init = params => {
  1947. // Clean up the old popup container if it exists
  1948. const oldContainerExisted = resetOldContainer();
  1949. /* istanbul ignore if */
  1950.  
  1951. if (isNodeEnv()) {
  1952. error('SweetAlert2 requires document to initialize');
  1953. return;
  1954. }
  1955.  
  1956. const container = document.createElement('div');
  1957. container.className = swalClasses.container;
  1958.  
  1959. if (oldContainerExisted) {
  1960. addClass(container, swalClasses['no-transition']);
  1961. }
  1962.  
  1963. setInnerHtml(container, sweetHTML);
  1964. const targetElement = getTarget(params.target);
  1965. targetElement.appendChild(container);
  1966. setupAccessibility(params);
  1967. setupRTL(targetElement);
  1968. addInputChangeListeners();
  1969. };
  1970.  
  1971. /**
  1972. * @param {HTMLElement | object | string} param
  1973. * @param {HTMLElement} target
  1974. */
  1975.  
  1976. const parseHtmlToContainer = (param, target) => {
  1977. // DOM element
  1978. if (param instanceof HTMLElement) {
  1979. target.appendChild(param);
  1980. } // Object
  1981. else if (typeof param === 'object') {
  1982. handleObject(param, target);
  1983. } // Plain string
  1984. else if (param) {
  1985. setInnerHtml(target, param);
  1986. }
  1987. };
  1988. /**
  1989. * @param {object} param
  1990. * @param {HTMLElement} target
  1991. */
  1992.  
  1993. const handleObject = (param, target) => {
  1994. // JQuery element(s)
  1995. if (param.jquery) {
  1996. handleJqueryElem(target, param);
  1997. } // For other objects use their string representation
  1998. else {
  1999. setInnerHtml(target, param.toString());
  2000. }
  2001. };
  2002.  
  2003. const handleJqueryElem = (target, elem) => {
  2004. target.textContent = '';
  2005.  
  2006. if (0 in elem) {
  2007. for (let i = 0; (i in elem); i++) {
  2008. target.appendChild(elem[i].cloneNode(true));
  2009. }
  2010. } else {
  2011. target.appendChild(elem.cloneNode(true));
  2012. }
  2013. };
  2014.  
  2015. const animationEndEvent = (() => {
  2016. // Prevent run in Node env
  2017.  
  2018. /* istanbul ignore if */
  2019. if (isNodeEnv()) {
  2020. return false;
  2021. }
  2022.  
  2023. const testEl = document.createElement('div');
  2024. const transEndEventNames = {
  2025. WebkitAnimation: 'webkitAnimationEnd',
  2026. // Chrome, Safari and Opera
  2027. animation: 'animationend' // Standard syntax
  2028.  
  2029. };
  2030.  
  2031. for (const i in transEndEventNames) {
  2032. if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') {
  2033. return transEndEventNames[i];
  2034. }
  2035. }
  2036.  
  2037. return false;
  2038. })();
  2039.  
  2040. // https://github.com/twbs/bootstrap/blob/master/js/src/modal.js
  2041.  
  2042. const measureScrollbar = () => {
  2043. const scrollDiv = document.createElement('div');
  2044. scrollDiv.className = swalClasses['scrollbar-measure'];
  2045. document.body.appendChild(scrollDiv);
  2046. const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
  2047. document.body.removeChild(scrollDiv);
  2048. return scrollbarWidth;
  2049. };
  2050.  
  2051. const renderActions = (instance, params) => {
  2052. const actions = getActions();
  2053. const loader = getLoader(); // Actions (buttons) wrapper
  2054.  
  2055. if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
  2056. hide(actions);
  2057. } else {
  2058. show(actions);
  2059. } // Custom class
  2060.  
  2061.  
  2062. applyCustomClass(actions, params, 'actions'); // Render all the buttons
  2063.  
  2064. renderButtons(actions, loader, params); // Loader
  2065.  
  2066. setInnerHtml(loader, params.loaderHtml);
  2067. applyCustomClass(loader, params, 'loader');
  2068. };
  2069.  
  2070. function renderButtons(actions, loader, params) {
  2071. const confirmButton = getConfirmButton();
  2072. const denyButton = getDenyButton();
  2073. const cancelButton = getCancelButton(); // Render buttons
  2074.  
  2075. renderButton(confirmButton, 'confirm', params);
  2076. renderButton(denyButton, 'deny', params);
  2077. renderButton(cancelButton, 'cancel', params);
  2078. handleButtonsStyling(confirmButton, denyButton, cancelButton, params);
  2079.  
  2080. if (params.reverseButtons) {
  2081. if (params.toast) {
  2082. actions.insertBefore(cancelButton, confirmButton);
  2083. actions.insertBefore(denyButton, confirmButton);
  2084. } else {
  2085. actions.insertBefore(cancelButton, loader);
  2086. actions.insertBefore(denyButton, loader);
  2087. actions.insertBefore(confirmButton, loader);
  2088. }
  2089. }
  2090. }
  2091.  
  2092. function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
  2093. if (!params.buttonsStyling) {
  2094. return removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
  2095. }
  2096.  
  2097. addClass([confirmButton, denyButton, cancelButton], swalClasses.styled); // Buttons background colors
  2098.  
  2099. if (params.confirmButtonColor) {
  2100. confirmButton.style.backgroundColor = params.confirmButtonColor;
  2101. addClass(confirmButton, swalClasses['default-outline']);
  2102. }
  2103.  
  2104. if (params.denyButtonColor) {
  2105. denyButton.style.backgroundColor = params.denyButtonColor;
  2106. addClass(denyButton, swalClasses['default-outline']);
  2107. }
  2108.  
  2109. if (params.cancelButtonColor) {
  2110. cancelButton.style.backgroundColor = params.cancelButtonColor;
  2111. addClass(cancelButton, swalClasses['default-outline']);
  2112. }
  2113. }
  2114.  
  2115. function renderButton(button, buttonType, params) {
  2116. toggle(button, params["show".concat(capitalizeFirstLetter(buttonType), "Button")], 'inline-block');
  2117. setInnerHtml(button, params["".concat(buttonType, "ButtonText")]); // Set caption text
  2118.  
  2119. button.setAttribute('aria-label', params["".concat(buttonType, "ButtonAriaLabel")]); // ARIA label
  2120. // Add buttons custom classes
  2121.  
  2122. button.className = swalClasses[buttonType];
  2123. applyCustomClass(button, params, "".concat(buttonType, "Button"));
  2124. addClass(button, params["".concat(buttonType, "ButtonClass")]);
  2125. }
  2126.  
  2127. function handleBackdropParam(container, backdrop) {
  2128. if (typeof backdrop === 'string') {
  2129. container.style.background = backdrop;
  2130. } else if (!backdrop) {
  2131. addClass([document.documentElement, document.body], swalClasses['no-backdrop']);
  2132. }
  2133. }
  2134.  
  2135. function handlePositionParam(container, position) {
  2136. if (position in swalClasses) {
  2137. addClass(container, swalClasses[position]);
  2138. } else {
  2139. warn('The "position" parameter is not valid, defaulting to "center"');
  2140. addClass(container, swalClasses.center);
  2141. }
  2142. }
  2143.  
  2144. function handleGrowParam(container, grow) {
  2145. if (grow && typeof grow === 'string') {
  2146. const growClass = "grow-".concat(grow);
  2147.  
  2148. if (growClass in swalClasses) {
  2149. addClass(container, swalClasses[growClass]);
  2150. }
  2151. }
  2152. }
  2153.  
  2154. const renderContainer = (instance, params) => {
  2155. const container = getContainer();
  2156.  
  2157. if (!container) {
  2158. return;
  2159. }
  2160.  
  2161. handleBackdropParam(container, params.backdrop);
  2162. handlePositionParam(container, params.position);
  2163. handleGrowParam(container, params.grow); // Custom class
  2164.  
  2165. applyCustomClass(container, params, 'container');
  2166. };
  2167.  
  2168. /**
  2169. * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
  2170. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  2171. * This is the approach that Babel will probably take to implement private methods/fields
  2172. * https://github.com/tc39/proposal-private-methods
  2173. * https://github.com/babel/babel/pull/7555
  2174. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  2175. * then we can use that language feature.
  2176. */
  2177. var privateProps = {
  2178. awaitingPromise: new WeakMap(),
  2179. promise: new WeakMap(),
  2180. innerParams: new WeakMap(),
  2181. domCache: new WeakMap()
  2182. };
  2183.  
  2184. const inputTypes = ['input', 'file', 'range', 'select', 'radio', 'checkbox', 'textarea'];
  2185. const renderInput = (instance, params) => {
  2186. const popup = getPopup();
  2187. const innerParams = privateProps.innerParams.get(instance);
  2188. const rerender = !innerParams || params.input !== innerParams.input;
  2189. inputTypes.forEach(inputType => {
  2190. const inputClass = swalClasses[inputType];
  2191. const inputContainer = getDirectChildByClass(popup, inputClass); // set attributes
  2192.  
  2193. setAttributes(inputType, params.inputAttributes); // set class
  2194.  
  2195. inputContainer.className = inputClass;
  2196.  
  2197. if (rerender) {
  2198. hide(inputContainer);
  2199. }
  2200. });
  2201.  
  2202. if (params.input) {
  2203. if (rerender) {
  2204. showInput(params);
  2205. } // set custom class
  2206.  
  2207.  
  2208. setCustomClass(params);
  2209. }
  2210. };
  2211.  
  2212. const showInput = params => {
  2213. if (!renderInputType[params.input]) {
  2214. return error("Unexpected type of input! Expected \"text\", \"email\", \"password\", \"number\", \"tel\", \"select\", \"radio\", \"checkbox\", \"textarea\", \"file\" or \"url\", got \"".concat(params.input, "\""));
  2215. }
  2216.  
  2217. const inputContainer = getInputContainer(params.input);
  2218. const input = renderInputType[params.input](inputContainer, params);
  2219. show(input); // input autofocus
  2220.  
  2221. setTimeout(() => {
  2222. focusInput(input);
  2223. });
  2224. };
  2225.  
  2226. const removeAttributes = input => {
  2227. for (let i = 0; i < input.attributes.length; i++) {
  2228. const attrName = input.attributes[i].name;
  2229.  
  2230. if (!['type', 'value', 'style'].includes(attrName)) {
  2231. input.removeAttribute(attrName);
  2232. }
  2233. }
  2234. };
  2235.  
  2236. const setAttributes = (inputType, inputAttributes) => {
  2237. const input = getInput(getPopup(), inputType);
  2238.  
  2239. if (!input) {
  2240. return;
  2241. }
  2242.  
  2243. removeAttributes(input);
  2244.  
  2245. for (const attr in inputAttributes) {
  2246. input.setAttribute(attr, inputAttributes[attr]);
  2247. }
  2248. };
  2249.  
  2250. const setCustomClass = params => {
  2251. const inputContainer = getInputContainer(params.input);
  2252.  
  2253. if (params.customClass) {
  2254. addClass(inputContainer, params.customClass.input);
  2255. }
  2256. };
  2257.  
  2258. const setInputPlaceholder = (input, params) => {
  2259. if (!input.placeholder || params.inputPlaceholder) {
  2260. input.placeholder = params.inputPlaceholder;
  2261. }
  2262. };
  2263.  
  2264. const setInputLabel = (input, prependTo, params) => {
  2265. if (params.inputLabel) {
  2266. input.id = swalClasses.input;
  2267. const label = document.createElement('label');
  2268. const labelClass = swalClasses['input-label'];
  2269. label.setAttribute('for', input.id);
  2270. label.className = labelClass;
  2271. addClass(label, params.customClass.inputLabel);
  2272. label.innerText = params.inputLabel;
  2273. prependTo.insertAdjacentElement('beforebegin', label);
  2274. }
  2275. };
  2276.  
  2277. const getInputContainer = inputType => {
  2278. const inputClass = swalClasses[inputType] ? swalClasses[inputType] : swalClasses.input;
  2279. return getDirectChildByClass(getPopup(), inputClass);
  2280. };
  2281.  
  2282. const renderInputType = {};
  2283.  
  2284. renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = (input, params) => {
  2285. if (typeof params.inputValue === 'string' || typeof params.inputValue === 'number') {
  2286. input.value = params.inputValue;
  2287. } else if (!isPromise(params.inputValue)) {
  2288. warn("Unexpected type of inputValue! Expected \"string\", \"number\" or \"Promise\", got \"".concat(typeof params.inputValue, "\""));
  2289. }
  2290.  
  2291. setInputLabel(input, input, params);
  2292. setInputPlaceholder(input, params);
  2293. input.type = params.input;
  2294. return input;
  2295. };
  2296.  
  2297. renderInputType.file = (input, params) => {
  2298. setInputLabel(input, input, params);
  2299. setInputPlaceholder(input, params);
  2300. return input;
  2301. };
  2302.  
  2303. renderInputType.range = (range, params) => {
  2304. const rangeInput = range.querySelector('input');
  2305. const rangeOutput = range.querySelector('output');
  2306. rangeInput.value = params.inputValue;
  2307. rangeInput.type = params.input;
  2308. rangeOutput.value = params.inputValue;
  2309. setInputLabel(rangeInput, range, params);
  2310. return range;
  2311. };
  2312.  
  2313. renderInputType.select = (select, params) => {
  2314. select.textContent = '';
  2315.  
  2316. if (params.inputPlaceholder) {
  2317. const placeholder = document.createElement('option');
  2318. setInnerHtml(placeholder, params.inputPlaceholder);
  2319. placeholder.value = '';
  2320. placeholder.disabled = true;
  2321. placeholder.selected = true;
  2322. select.appendChild(placeholder);
  2323. }
  2324.  
  2325. setInputLabel(select, select, params);
  2326. return select;
  2327. };
  2328.  
  2329. renderInputType.radio = radio => {
  2330. radio.textContent = '';
  2331. return radio;
  2332. };
  2333.  
  2334. renderInputType.checkbox = (checkboxContainer, params) => {
  2335. /** @type {HTMLInputElement} */
  2336. const checkbox = getInput(getPopup(), 'checkbox');
  2337. checkbox.value = '1';
  2338. checkbox.id = swalClasses.checkbox;
  2339. checkbox.checked = Boolean(params.inputValue);
  2340. const label = checkboxContainer.querySelector('span');
  2341. setInnerHtml(label, params.inputPlaceholder);
  2342. return checkboxContainer;
  2343. };
  2344.  
  2345. renderInputType.textarea = (textarea, params) => {
  2346. textarea.value = params.inputValue;
  2347. setInputPlaceholder(textarea, params);
  2348. setInputLabel(textarea, textarea, params);
  2349.  
  2350. const getMargin = el => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight); // https://github.com/sweetalert2/sweetalert2/issues/2291
  2351.  
  2352.  
  2353. setTimeout(() => {
  2354. // https://github.com/sweetalert2/sweetalert2/issues/1699
  2355. if ('MutationObserver' in window) {
  2356. const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
  2357.  
  2358. const textareaResizeHandler = () => {
  2359. const textareaWidth = textarea.offsetWidth + getMargin(textarea);
  2360.  
  2361. if (textareaWidth > initialPopupWidth) {
  2362. getPopup().style.width = "".concat(textareaWidth, "px");
  2363. } else {
  2364. getPopup().style.width = null;
  2365. }
  2366. };
  2367.  
  2368. new MutationObserver(textareaResizeHandler).observe(textarea, {
  2369. attributes: true,
  2370. attributeFilter: ['style']
  2371. });
  2372. }
  2373. });
  2374. return textarea;
  2375. };
  2376.  
  2377. const renderContent = (instance, params) => {
  2378. const htmlContainer = getHtmlContainer();
  2379. applyCustomClass(htmlContainer, params, 'htmlContainer'); // Content as HTML
  2380.  
  2381. if (params.html) {
  2382. parseHtmlToContainer(params.html, htmlContainer);
  2383. show(htmlContainer, 'block');
  2384. } // Content as plain text
  2385. else if (params.text) {
  2386. htmlContainer.textContent = params.text;
  2387. show(htmlContainer, 'block');
  2388. } // No content
  2389. else {
  2390. hide(htmlContainer);
  2391. }
  2392.  
  2393. renderInput(instance, params);
  2394. };
  2395.  
  2396. const renderFooter = (instance, params) => {
  2397. const footer = getFooter();
  2398. toggle(footer, params.footer);
  2399.  
  2400. if (params.footer) {
  2401. parseHtmlToContainer(params.footer, footer);
  2402. } // Custom class
  2403.  
  2404.  
  2405. applyCustomClass(footer, params, 'footer');
  2406. };
  2407.  
  2408. const renderCloseButton = (instance, params) => {
  2409. const closeButton = getCloseButton();
  2410. setInnerHtml(closeButton, params.closeButtonHtml); // Custom class
  2411.  
  2412. applyCustomClass(closeButton, params, 'closeButton');
  2413. toggle(closeButton, params.showCloseButton);
  2414. closeButton.setAttribute('aria-label', params.closeButtonAriaLabel);
  2415. };
  2416.  
  2417. const renderIcon = (instance, params) => {
  2418. const innerParams = privateProps.innerParams.get(instance);
  2419. const icon = getIcon(); // if the given icon already rendered, apply the styling without re-rendering the icon
  2420.  
  2421. if (innerParams && params.icon === innerParams.icon) {
  2422. // Custom or default content
  2423. setContent(icon, params);
  2424. applyStyles(icon, params);
  2425. return;
  2426. }
  2427.  
  2428. if (!params.icon && !params.iconHtml) {
  2429. return hide(icon);
  2430. }
  2431.  
  2432. if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
  2433. error("Unknown icon! Expected \"success\", \"error\", \"warning\", \"info\" or \"question\", got \"".concat(params.icon, "\""));
  2434. return hide(icon);
  2435. }
  2436.  
  2437. show(icon); // Custom or default content
  2438.  
  2439. setContent(icon, params);
  2440. applyStyles(icon, params); // Animate icon
  2441.  
  2442. addClass(icon, params.showClass.icon);
  2443. };
  2444.  
  2445. const applyStyles = (icon, params) => {
  2446. for (const iconType in iconTypes) {
  2447. if (params.icon !== iconType) {
  2448. removeClass(icon, iconTypes[iconType]);
  2449. }
  2450. }
  2451.  
  2452. addClass(icon, iconTypes[params.icon]); // Icon color
  2453.  
  2454. setColor(icon, params); // Success icon background color
  2455.  
  2456. adjustSuccessIconBackgroundColor(); // Custom class
  2457.  
  2458. applyCustomClass(icon, params, 'icon');
  2459. }; // Adjust success icon background color to match the popup background color
  2460.  
  2461.  
  2462. const adjustSuccessIconBackgroundColor = () => {
  2463. const popup = getPopup();
  2464. const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue('background-color');
  2465. const successIconParts = popup.querySelectorAll('[class^=swal2-success-circular-line], .swal2-success-fix');
  2466.  
  2467. for (let i = 0; i < successIconParts.length; i++) {
  2468. successIconParts[i].style.backgroundColor = popupBackgroundColor;
  2469. }
  2470. };
  2471.  
  2472. const successIconHtml = "\n <div class=\"swal2-success-circular-line-left\"></div>\n <span class=\"swal2-success-line-tip\"></span> <span class=\"swal2-success-line-long\"></span>\n <div class=\"swal2-success-ring\"></div> <div class=\"swal2-success-fix\"></div>\n <div class=\"swal2-success-circular-line-right\"></div>\n";
  2473. const errorIconHtml = "\n <span class=\"swal2-x-mark\">\n <span class=\"swal2-x-mark-line-left\"></span>\n <span class=\"swal2-x-mark-line-right\"></span>\n </span>\n";
  2474.  
  2475. const setContent = (icon, params) => {
  2476. icon.textContent = '';
  2477.  
  2478. if (params.iconHtml) {
  2479. setInnerHtml(icon, iconContent(params.iconHtml));
  2480. } else if (params.icon === 'success') {
  2481. setInnerHtml(icon, successIconHtml);
  2482. } else if (params.icon === 'error') {
  2483. setInnerHtml(icon, errorIconHtml);
  2484. } else {
  2485. const defaultIconHtml = {
  2486. question: '?',
  2487. warning: '!',
  2488. info: 'i'
  2489. };
  2490. setInnerHtml(icon, iconContent(defaultIconHtml[params.icon]));
  2491. }
  2492. };
  2493.  
  2494. const setColor = (icon, params) => {
  2495. if (!params.iconColor) {
  2496. return;
  2497. }
  2498.  
  2499. icon.style.color = params.iconColor;
  2500. icon.style.borderColor = params.iconColor;
  2501.  
  2502. for (const sel of ['.swal2-success-line-tip', '.swal2-success-line-long', '.swal2-x-mark-line-left', '.swal2-x-mark-line-right']) {
  2503. setStyle(icon, sel, 'backgroundColor', params.iconColor);
  2504. }
  2505.  
  2506. setStyle(icon, '.swal2-success-ring', 'borderColor', params.iconColor);
  2507. };
  2508.  
  2509. const iconContent = content => "<div class=\"".concat(swalClasses['icon-content'], "\">").concat(content, "</div>");
  2510.  
  2511. const renderImage = (instance, params) => {
  2512. const image = getImage();
  2513.  
  2514. if (!params.imageUrl) {
  2515. return hide(image);
  2516. }
  2517.  
  2518. show(image, ''); // Src, alt
  2519.  
  2520. image.setAttribute('src', params.imageUrl);
  2521. image.setAttribute('alt', params.imageAlt); // Width, height
  2522.  
  2523. applyNumericalStyle(image, 'width', params.imageWidth);
  2524. applyNumericalStyle(image, 'height', params.imageHeight); // Class
  2525.  
  2526. image.className = swalClasses.image;
  2527. applyCustomClass(image, params, 'image');
  2528. };
  2529.  
  2530. const createStepElement = step => {
  2531. const stepEl = document.createElement('li');
  2532. addClass(stepEl, swalClasses['progress-step']);
  2533. setInnerHtml(stepEl, step);
  2534. return stepEl;
  2535. };
  2536.  
  2537. const createLineElement = params => {
  2538. const lineEl = document.createElement('li');
  2539. addClass(lineEl, swalClasses['progress-step-line']);
  2540.  
  2541. if (params.progressStepsDistance) {
  2542. lineEl.style.width = params.progressStepsDistance;
  2543. }
  2544.  
  2545. return lineEl;
  2546. };
  2547.  
  2548. const renderProgressSteps = (instance, params) => {
  2549. const progressStepsContainer = getProgressSteps();
  2550.  
  2551. if (!params.progressSteps || params.progressSteps.length === 0) {
  2552. return hide(progressStepsContainer);
  2553. }
  2554.  
  2555. show(progressStepsContainer);
  2556. progressStepsContainer.textContent = '';
  2557.  
  2558. if (params.currentProgressStep >= params.progressSteps.length) {
  2559. warn('Invalid currentProgressStep parameter, it should be less than progressSteps.length ' + '(currentProgressStep like JS arrays starts from 0)');
  2560. }
  2561.  
  2562. params.progressSteps.forEach((step, index) => {
  2563. const stepEl = createStepElement(step);
  2564. progressStepsContainer.appendChild(stepEl);
  2565.  
  2566. if (index === params.currentProgressStep) {
  2567. addClass(stepEl, swalClasses['active-progress-step']);
  2568. }
  2569.  
  2570. if (index !== params.progressSteps.length - 1) {
  2571. const lineEl = createLineElement(params);
  2572. progressStepsContainer.appendChild(lineEl);
  2573. }
  2574. });
  2575. };
  2576.  
  2577. const renderTitle = (instance, params) => {
  2578. const title = getTitle();
  2579. toggle(title, params.title || params.titleText, 'block');
  2580.  
  2581. if (params.title) {
  2582. parseHtmlToContainer(params.title, title);
  2583. }
  2584.  
  2585. if (params.titleText) {
  2586. title.innerText = params.titleText;
  2587. } // Custom class
  2588.  
  2589.  
  2590. applyCustomClass(title, params, 'title');
  2591. };
  2592.  
  2593. const renderPopup = (instance, params) => {
  2594. const container = getContainer();
  2595. const popup = getPopup(); // Width
  2596. // https://github.com/sweetalert2/sweetalert2/issues/2170
  2597.  
  2598. if (params.toast) {
  2599. applyNumericalStyle(container, 'width', params.width);
  2600. popup.style.width = '100%';
  2601. popup.insertBefore(getLoader(), getIcon());
  2602. } else {
  2603. applyNumericalStyle(popup, 'width', params.width);
  2604. } // Padding
  2605.  
  2606.  
  2607. applyNumericalStyle(popup, 'padding', params.padding); // Color
  2608.  
  2609. if (params.color) {
  2610. popup.style.color = params.color;
  2611. } // Background
  2612.  
  2613.  
  2614. if (params.background) {
  2615. popup.style.background = params.background;
  2616. }
  2617.  
  2618. hide(getValidationMessage()); // Classes
  2619.  
  2620. addClasses(popup, params);
  2621. };
  2622.  
  2623. const addClasses = (popup, params) => {
  2624. // Default Class + showClass when updating Swal.update({})
  2625. popup.className = "".concat(swalClasses.popup, " ").concat(isVisible(popup) ? params.showClass.popup : '');
  2626.  
  2627. if (params.toast) {
  2628. addClass([document.documentElement, document.body], swalClasses['toast-shown']);
  2629. addClass(popup, swalClasses.toast);
  2630. } else {
  2631. addClass(popup, swalClasses.modal);
  2632. } // Custom class
  2633.  
  2634.  
  2635. applyCustomClass(popup, params, 'popup');
  2636.  
  2637. if (typeof params.customClass === 'string') {
  2638. addClass(popup, params.customClass);
  2639. } // Icon class (#1842)
  2640.  
  2641.  
  2642. if (params.icon) {
  2643. addClass(popup, swalClasses["icon-".concat(params.icon)]);
  2644. }
  2645. };
  2646.  
  2647. const render = (instance, params) => {
  2648. renderPopup(instance, params);
  2649. renderContainer(instance, params);
  2650. renderProgressSteps(instance, params);
  2651. renderIcon(instance, params);
  2652. renderImage(instance, params);
  2653. renderTitle(instance, params);
  2654. renderCloseButton(instance, params);
  2655. renderContent(instance, params);
  2656. renderActions(instance, params);
  2657. renderFooter(instance, params);
  2658.  
  2659. if (typeof params.didRender === 'function') {
  2660. params.didRender(getPopup());
  2661. }
  2662. };
  2663.  
  2664. const DismissReason = Object.freeze({
  2665. cancel: 'cancel',
  2666. backdrop: 'backdrop',
  2667. close: 'close',
  2668. esc: 'esc',
  2669. timer: 'timer'
  2670. });
  2671.  
  2672. // Adding aria-hidden="true" to elements outside of the active modal dialog ensures that
  2673. // elements not within the active modal dialog will not be surfaced if a user opens a screen
  2674. // reader’s list of elements (headings, form controls, landmarks, etc.) in the document.
  2675.  
  2676. const setAriaHidden = () => {
  2677. const bodyChildren = toArray(document.body.children);
  2678. bodyChildren.forEach(el => {
  2679. if (el === getContainer() || el.contains(getContainer())) {
  2680. return;
  2681. }
  2682.  
  2683. if (el.hasAttribute('aria-hidden')) {
  2684. el.setAttribute('data-previous-aria-hidden', el.getAttribute('aria-hidden'));
  2685. }
  2686.  
  2687. el.setAttribute('aria-hidden', 'true');
  2688. });
  2689. };
  2690. const unsetAriaHidden = () => {
  2691. const bodyChildren = toArray(document.body.children);
  2692. bodyChildren.forEach(el => {
  2693. if (el.hasAttribute('data-previous-aria-hidden')) {
  2694. el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'));
  2695. el.removeAttribute('data-previous-aria-hidden');
  2696. } else {
  2697. el.removeAttribute('aria-hidden');
  2698. }
  2699. });
  2700. };
  2701.  
  2702. const swalStringParams = ['swal-title', 'swal-html', 'swal-footer'];
  2703. const getTemplateParams = params => {
  2704. const template = typeof params.template === 'string' ? document.querySelector(params.template) : params.template;
  2705.  
  2706. if (!template) {
  2707. return {};
  2708. }
  2709. /** @type {DocumentFragment} */
  2710.  
  2711.  
  2712. const templateContent = template.content;
  2713. showWarningsForElements(templateContent);
  2714. const result = Object.assign(getSwalParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
  2715. return result;
  2716. };
  2717. /**
  2718. * @param {DocumentFragment} templateContent
  2719. */
  2720.  
  2721. const getSwalParams = templateContent => {
  2722. const result = {};
  2723. toArray(templateContent.querySelectorAll('swal-param')).forEach(param => {
  2724. showWarningsForAttributes(param, ['name', 'value']);
  2725. const paramName = param.getAttribute('name');
  2726. const value = param.getAttribute('value');
  2727.  
  2728. if (typeof defaultParams[paramName] === 'boolean' && value === 'false') {
  2729. result[paramName] = false;
  2730. }
  2731.  
  2732. if (typeof defaultParams[paramName] === 'object') {
  2733. result[paramName] = JSON.parse(value);
  2734. }
  2735. });
  2736. return result;
  2737. };
  2738. /**
  2739. * @param {DocumentFragment} templateContent
  2740. */
  2741.  
  2742.  
  2743. const getSwalButtons = templateContent => {
  2744. const result = {};
  2745. toArray(templateContent.querySelectorAll('swal-button')).forEach(button => {
  2746. showWarningsForAttributes(button, ['type', 'color', 'aria-label']);
  2747. const type = button.getAttribute('type');
  2748. result["".concat(type, "ButtonText")] = button.innerHTML;
  2749. result["show".concat(capitalizeFirstLetter(type), "Button")] = true;
  2750.  
  2751. if (button.hasAttribute('color')) {
  2752. result["".concat(type, "ButtonColor")] = button.getAttribute('color');
  2753. }
  2754.  
  2755. if (button.hasAttribute('aria-label')) {
  2756. result["".concat(type, "ButtonAriaLabel")] = button.getAttribute('aria-label');
  2757. }
  2758. });
  2759. return result;
  2760. };
  2761. /**
  2762. * @param {DocumentFragment} templateContent
  2763. */
  2764.  
  2765.  
  2766. const getSwalImage = templateContent => {
  2767. const result = {};
  2768. /** @type {HTMLElement} */
  2769.  
  2770. const image = templateContent.querySelector('swal-image');
  2771.  
  2772. if (image) {
  2773. showWarningsForAttributes(image, ['src', 'width', 'height', 'alt']);
  2774.  
  2775. if (image.hasAttribute('src')) {
  2776. result.imageUrl = image.getAttribute('src');
  2777. }
  2778.  
  2779. if (image.hasAttribute('width')) {
  2780. result.imageWidth = image.getAttribute('width');
  2781. }
  2782.  
  2783. if (image.hasAttribute('height')) {
  2784. result.imageHeight = image.getAttribute('height');
  2785. }
  2786.  
  2787. if (image.hasAttribute('alt')) {
  2788. result.imageAlt = image.getAttribute('alt');
  2789. }
  2790. }
  2791.  
  2792. return result;
  2793. };
  2794. /**
  2795. * @param {DocumentFragment} templateContent
  2796. */
  2797.  
  2798.  
  2799. const getSwalIcon = templateContent => {
  2800. const result = {};
  2801. /** @type {HTMLElement} */
  2802.  
  2803. const icon = templateContent.querySelector('swal-icon');
  2804.  
  2805. if (icon) {
  2806. showWarningsForAttributes(icon, ['type', 'color']);
  2807.  
  2808. if (icon.hasAttribute('type')) {
  2809. result.icon = icon.getAttribute('type');
  2810. }
  2811.  
  2812. if (icon.hasAttribute('color')) {
  2813. result.iconColor = icon.getAttribute('color');
  2814. }
  2815.  
  2816. result.iconHtml = icon.innerHTML;
  2817. }
  2818.  
  2819. return result;
  2820. };
  2821. /**
  2822. * @param {DocumentFragment} templateContent
  2823. */
  2824.  
  2825.  
  2826. const getSwalInput = templateContent => {
  2827. const result = {};
  2828. /** @type {HTMLElement} */
  2829.  
  2830. const input = templateContent.querySelector('swal-input');
  2831.  
  2832. if (input) {
  2833. showWarningsForAttributes(input, ['type', 'label', 'placeholder', 'value']);
  2834. result.input = input.getAttribute('type') || 'text';
  2835.  
  2836. if (input.hasAttribute('label')) {
  2837. result.inputLabel = input.getAttribute('label');
  2838. }
  2839.  
  2840. if (input.hasAttribute('placeholder')) {
  2841. result.inputPlaceholder = input.getAttribute('placeholder');
  2842. }
  2843.  
  2844. if (input.hasAttribute('value')) {
  2845. result.inputValue = input.getAttribute('value');
  2846. }
  2847. }
  2848.  
  2849. const inputOptions = templateContent.querySelectorAll('swal-input-option');
  2850.  
  2851. if (inputOptions.length) {
  2852. result.inputOptions = {};
  2853. toArray(inputOptions).forEach(option => {
  2854. showWarningsForAttributes(option, ['value']);
  2855. const optionValue = option.getAttribute('value');
  2856. const optionName = option.innerHTML;
  2857. result.inputOptions[optionValue] = optionName;
  2858. });
  2859. }
  2860.  
  2861. return result;
  2862. };
  2863. /**
  2864. * @param {DocumentFragment} templateContent
  2865. * @param {string[]} paramNames
  2866. */
  2867.  
  2868.  
  2869. const getSwalStringParams = (templateContent, paramNames) => {
  2870. const result = {};
  2871.  
  2872. for (const i in paramNames) {
  2873. const paramName = paramNames[i];
  2874. /** @type {HTMLElement} */
  2875.  
  2876. const tag = templateContent.querySelector(paramName);
  2877.  
  2878. if (tag) {
  2879. showWarningsForAttributes(tag, []);
  2880. result[paramName.replace(/^swal-/, '')] = tag.innerHTML.trim();
  2881. }
  2882. }
  2883.  
  2884. return result;
  2885. };
  2886. /**
  2887. * @param {DocumentFragment} templateContent
  2888. */
  2889.  
  2890.  
  2891. const showWarningsForElements = templateContent => {
  2892. const allowedElements = swalStringParams.concat(['swal-param', 'swal-button', 'swal-image', 'swal-icon', 'swal-input', 'swal-input-option']);
  2893. toArray(templateContent.children).forEach(el => {
  2894. const tagName = el.tagName.toLowerCase();
  2895.  
  2896. if (allowedElements.indexOf(tagName) === -1) {
  2897. warn("Unrecognized element <".concat(tagName, ">"));
  2898. }
  2899. });
  2900. };
  2901. /**
  2902. * @param {HTMLElement} el
  2903. * @param {string[]} allowedAttributes
  2904. */
  2905.  
  2906.  
  2907. const showWarningsForAttributes = (el, allowedAttributes) => {
  2908. toArray(el.attributes).forEach(attribute => {
  2909. if (allowedAttributes.indexOf(attribute.name) === -1) {
  2910. warn(["Unrecognized attribute \"".concat(attribute.name, "\" on <").concat(el.tagName.toLowerCase(), ">."), "".concat(allowedAttributes.length ? "Allowed attributes are: ".concat(allowedAttributes.join(', ')) : 'To set the value, use HTML within the element.')]);
  2911. }
  2912. });
  2913. };
  2914.  
  2915. var defaultInputValidators = {
  2916. email: (string, validationMessage) => {
  2917. 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');
  2918. },
  2919. url: (string, validationMessage) => {
  2920. // taken from https://stackoverflow.com/a/3809435 with a small change from #1306 and #2013
  2921. 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');
  2922. }
  2923. };
  2924.  
  2925. function setDefaultInputValidators(params) {
  2926. // Use default `inputValidator` for supported input types if not provided
  2927. if (!params.inputValidator) {
  2928. Object.keys(defaultInputValidators).forEach(key => {
  2929. if (params.input === key) {
  2930. params.inputValidator = defaultInputValidators[key];
  2931. }
  2932. });
  2933. }
  2934. }
  2935.  
  2936. function validateCustomTargetElement(params) {
  2937. // Determine if the custom target element is valid
  2938. if (!params.target || typeof params.target === 'string' && !document.querySelector(params.target) || typeof params.target !== 'string' && !params.target.appendChild) {
  2939. warn('Target parameter is not valid, defaulting to "body"');
  2940. params.target = 'body';
  2941. }
  2942. }
  2943. /**
  2944. * Set type, text and actions on popup
  2945. *
  2946. * @param params
  2947. */
  2948.  
  2949.  
  2950. function setParameters(params) {
  2951. setDefaultInputValidators(params); // showLoaderOnConfirm && preConfirm
  2952.  
  2953. if (params.showLoaderOnConfirm && !params.preConfirm) {
  2954. warn('showLoaderOnConfirm is set to true, but preConfirm is not defined.\n' + 'showLoaderOnConfirm should be used together with preConfirm, see usage example:\n' + 'https://sweetalert2.github.io/#ajax-request');
  2955. }
  2956.  
  2957. validateCustomTargetElement(params); // Replace newlines with <br> in title
  2958.  
  2959. if (typeof params.title === 'string') {
  2960. params.title = params.title.split('\n').join('<br />');
  2961. }
  2962.  
  2963. init(params);
  2964. }
  2965.  
  2966. class Timer {
  2967. constructor(callback, delay) {
  2968. this.callback = callback;
  2969. this.remaining = delay;
  2970. this.running = false;
  2971. this.start();
  2972. }
  2973.  
  2974. start() {
  2975. if (!this.running) {
  2976. this.running = true;
  2977. this.started = new Date();
  2978. this.id = setTimeout(this.callback, this.remaining);
  2979. }
  2980.  
  2981. return this.remaining;
  2982. }
  2983.  
  2984. stop() {
  2985. if (this.running) {
  2986. this.running = false;
  2987. clearTimeout(this.id);
  2988. this.remaining -= new Date().getTime() - this.started.getTime();
  2989. }
  2990.  
  2991. return this.remaining;
  2992. }
  2993.  
  2994. increase(n) {
  2995. const running = this.running;
  2996.  
  2997. if (running) {
  2998. this.stop();
  2999. }
  3000.  
  3001. this.remaining += n;
  3002.  
  3003. if (running) {
  3004. this.start();
  3005. }
  3006.  
  3007. return this.remaining;
  3008. }
  3009.  
  3010. getTimerLeft() {
  3011. if (this.running) {
  3012. this.stop();
  3013. this.start();
  3014. }
  3015.  
  3016. return this.remaining;
  3017. }
  3018.  
  3019. isRunning() {
  3020. return this.running;
  3021. }
  3022.  
  3023. }
  3024.  
  3025. const fixScrollbar = () => {
  3026. // for queues, do not do this more than once
  3027. if (states.previousBodyPadding !== null) {
  3028. return;
  3029. } // if the body has overflow
  3030.  
  3031.  
  3032. if (document.body.scrollHeight > window.innerHeight) {
  3033. // add padding so the content doesn't shift after removal of scrollbar
  3034. states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue('padding-right'));
  3035. document.body.style.paddingRight = "".concat(states.previousBodyPadding + measureScrollbar(), "px");
  3036. }
  3037. };
  3038. const undoScrollbar = () => {
  3039. if (states.previousBodyPadding !== null) {
  3040. document.body.style.paddingRight = "".concat(states.previousBodyPadding, "px");
  3041. states.previousBodyPadding = null;
  3042. }
  3043. };
  3044.  
  3045. /* istanbul ignore file */
  3046.  
  3047. const iOSfix = () => {
  3048. const iOS = // @ts-ignore
  3049. /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1;
  3050.  
  3051. if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
  3052. const offset = document.body.scrollTop;
  3053. document.body.style.top = "".concat(offset * -1, "px");
  3054. addClass(document.body, swalClasses.iosfix);
  3055. lockBodyScroll();
  3056. addBottomPaddingForTallPopups();
  3057. }
  3058. };
  3059. /**
  3060. * https://github.com/sweetalert2/sweetalert2/issues/1948
  3061. */
  3062.  
  3063. const addBottomPaddingForTallPopups = () => {
  3064. const ua = navigator.userAgent;
  3065. const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
  3066. const webkit = !!ua.match(/WebKit/i);
  3067. const iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
  3068.  
  3069. if (iOSSafari) {
  3070. const bottomPanelHeight = 44;
  3071.  
  3072. if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
  3073. getContainer().style.paddingBottom = "".concat(bottomPanelHeight, "px");
  3074. }
  3075. }
  3076. };
  3077. /**
  3078. * https://github.com/sweetalert2/sweetalert2/issues/1246
  3079. */
  3080.  
  3081.  
  3082. const lockBodyScroll = () => {
  3083. const container = getContainer();
  3084. let preventTouchMove;
  3085.  
  3086. container.ontouchstart = e => {
  3087. preventTouchMove = shouldPreventTouchMove(e);
  3088. };
  3089.  
  3090. container.ontouchmove = e => {
  3091. if (preventTouchMove) {
  3092. e.preventDefault();
  3093. e.stopPropagation();
  3094. }
  3095. };
  3096. };
  3097.  
  3098. const shouldPreventTouchMove = event => {
  3099. const target = event.target;
  3100. const container = getContainer();
  3101.  
  3102. if (isStylus(event) || isZoom(event)) {
  3103. return false;
  3104. }
  3105.  
  3106. if (target === container) {
  3107. return true;
  3108. }
  3109.  
  3110. if (!isScrollable(container) && target.tagName !== 'INPUT' && // #1603
  3111. target.tagName !== 'TEXTAREA' && // #2266
  3112. !(isScrollable(getHtmlContainer()) && // #1944
  3113. getHtmlContainer().contains(target))) {
  3114. return true;
  3115. }
  3116.  
  3117. return false;
  3118. };
  3119. /**
  3120. * https://github.com/sweetalert2/sweetalert2/issues/1786
  3121. *
  3122. * @param {*} event
  3123. * @returns {boolean}
  3124. */
  3125.  
  3126.  
  3127. const isStylus = event => {
  3128. return event.touches && event.touches.length && event.touches[0].touchType === 'stylus';
  3129. };
  3130. /**
  3131. * https://github.com/sweetalert2/sweetalert2/issues/1891
  3132. *
  3133. * @param {TouchEvent} event
  3134. * @returns {boolean}
  3135. */
  3136.  
  3137.  
  3138. const isZoom = event => {
  3139. return event.touches && event.touches.length > 1;
  3140. };
  3141.  
  3142. const undoIOSfix = () => {
  3143. if (hasClass(document.body, swalClasses.iosfix)) {
  3144. const offset = parseInt(document.body.style.top, 10);
  3145. removeClass(document.body, swalClasses.iosfix);
  3146. document.body.style.top = '';
  3147. document.body.scrollTop = offset * -1;
  3148. }
  3149. };
  3150.  
  3151. const SHOW_CLASS_TIMEOUT = 10;
  3152. /**
  3153. * Open popup, add necessary classes and styles, fix scrollbar
  3154. *
  3155. * @param params
  3156. */
  3157.  
  3158. const openPopup = params => {
  3159. const container = getContainer();
  3160. const popup = getPopup();
  3161.  
  3162. if (typeof params.willOpen === 'function') {
  3163. params.willOpen(popup);
  3164. }
  3165.  
  3166. const bodyStyles = window.getComputedStyle(document.body);
  3167. const initialBodyOverflow = bodyStyles.overflowY;
  3168. addClasses$1(container, popup, params); // scrolling is 'hidden' until animation is done, after that 'auto'
  3169.  
  3170. setTimeout(() => {
  3171. setScrollingVisibility(container, popup);
  3172. }, SHOW_CLASS_TIMEOUT);
  3173.  
  3174. if (isModal()) {
  3175. fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
  3176. setAriaHidden();
  3177. }
  3178.  
  3179. if (!isToast() && !globalState.previousActiveElement) {
  3180. globalState.previousActiveElement = document.activeElement;
  3181. }
  3182.  
  3183. if (typeof params.didOpen === 'function') {
  3184. setTimeout(() => params.didOpen(popup));
  3185. }
  3186.  
  3187. removeClass(container, swalClasses['no-transition']);
  3188. };
  3189.  
  3190. const swalOpenAnimationFinished = event => {
  3191. const popup = getPopup();
  3192.  
  3193. if (event.target !== popup) {
  3194. return;
  3195. }
  3196.  
  3197. const container = getContainer();
  3198. popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
  3199. container.style.overflowY = 'auto';
  3200. };
  3201.  
  3202. const setScrollingVisibility = (container, popup) => {
  3203. if (animationEndEvent && hasCssAnimation(popup)) {
  3204. container.style.overflowY = 'hidden';
  3205. popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
  3206. } else {
  3207. container.style.overflowY = 'auto';
  3208. }
  3209. };
  3210.  
  3211. const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
  3212. iOSfix();
  3213.  
  3214. if (scrollbarPadding && initialBodyOverflow !== 'hidden') {
  3215. fixScrollbar();
  3216. } // sweetalert2/issues/1247
  3217.  
  3218.  
  3219. setTimeout(() => {
  3220. container.scrollTop = 0;
  3221. });
  3222. };
  3223.  
  3224. const addClasses$1 = (container, popup, params) => {
  3225. addClass(container, params.showClass.backdrop); // this workaround with opacity is needed for https://github.com/sweetalert2/sweetalert2/issues/2059
  3226.  
  3227. popup.style.setProperty('opacity', '0', 'important');
  3228. show(popup, 'grid');
  3229. setTimeout(() => {
  3230. // Animate popup right after showing it
  3231. addClass(popup, params.showClass.popup); // and remove the opacity workaround
  3232.  
  3233. popup.style.removeProperty('opacity');
  3234. }, SHOW_CLASS_TIMEOUT); // 10ms in order to fix #2062
  3235.  
  3236. addClass([document.documentElement, document.body], swalClasses.shown);
  3237.  
  3238. if (params.heightAuto && params.backdrop && !params.toast) {
  3239. addClass([document.documentElement, document.body], swalClasses['height-auto']);
  3240. }
  3241. };
  3242.  
  3243. /**
  3244. * Shows loader (spinner), this is useful with AJAX requests.
  3245. * By default the loader be shown instead of the "Confirm" button.
  3246. */
  3247.  
  3248. const showLoading = buttonToReplace => {
  3249. let popup = getPopup();
  3250.  
  3251. if (!popup) {
  3252. new Swal(); // eslint-disable-line no-new
  3253. }
  3254.  
  3255. popup = getPopup();
  3256. const loader = getLoader();
  3257.  
  3258. if (isToast()) {
  3259. hide(getIcon());
  3260. } else {
  3261. replaceButton(popup, buttonToReplace);
  3262. }
  3263.  
  3264. show(loader);
  3265. popup.setAttribute('data-loading', true);
  3266. popup.setAttribute('aria-busy', true);
  3267. popup.focus();
  3268. };
  3269.  
  3270. const replaceButton = (popup, buttonToReplace) => {
  3271. const actions = getActions();
  3272. const loader = getLoader();
  3273.  
  3274. if (!buttonToReplace && isVisible(getConfirmButton())) {
  3275. buttonToReplace = getConfirmButton();
  3276. }
  3277.  
  3278. show(actions);
  3279.  
  3280. if (buttonToReplace) {
  3281. hide(buttonToReplace);
  3282. loader.setAttribute('data-button-to-replace', buttonToReplace.className);
  3283. }
  3284.  
  3285. loader.parentNode.insertBefore(loader, buttonToReplace);
  3286. addClass([popup, actions], swalClasses.loading);
  3287. };
  3288.  
  3289. const handleInputOptionsAndValue = (instance, params) => {
  3290. if (params.input === 'select' || params.input === 'radio') {
  3291. handleInputOptions(instance, params);
  3292. } else if (['text', 'email', 'number', 'tel', 'textarea'].includes(params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
  3293. showLoading(getConfirmButton());
  3294. handleInputValue(instance, params);
  3295. }
  3296. };
  3297. const getInputValue = (instance, innerParams) => {
  3298. const input = instance.getInput();
  3299.  
  3300. if (!input) {
  3301. return null;
  3302. }
  3303.  
  3304. switch (innerParams.input) {
  3305. case 'checkbox':
  3306. return getCheckboxValue(input);
  3307.  
  3308. case 'radio':
  3309. return getRadioValue(input);
  3310.  
  3311. case 'file':
  3312. return getFileValue(input);
  3313.  
  3314. default:
  3315. return innerParams.inputAutoTrim ? input.value.trim() : input.value;
  3316. }
  3317. };
  3318.  
  3319. const getCheckboxValue = input => input.checked ? 1 : 0;
  3320.  
  3321. const getRadioValue = input => input.checked ? input.value : null;
  3322.  
  3323. const getFileValue = input => input.files.length ? input.getAttribute('multiple') !== null ? input.files : input.files[0] : null;
  3324.  
  3325. const handleInputOptions = (instance, params) => {
  3326. const popup = getPopup();
  3327.  
  3328. const processInputOptions = inputOptions => populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
  3329.  
  3330. if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
  3331. showLoading(getConfirmButton());
  3332. asPromise(params.inputOptions).then(inputOptions => {
  3333. instance.hideLoading();
  3334. processInputOptions(inputOptions);
  3335. });
  3336. } else if (typeof params.inputOptions === 'object') {
  3337. processInputOptions(params.inputOptions);
  3338. } else {
  3339. error("Unexpected type of inputOptions! Expected object, Map or Promise, got ".concat(typeof params.inputOptions));
  3340. }
  3341. };
  3342.  
  3343. const handleInputValue = (instance, params) => {
  3344. const input = instance.getInput();
  3345. hide(input);
  3346. asPromise(params.inputValue).then(inputValue => {
  3347. input.value = params.input === 'number' ? parseFloat(inputValue) || 0 : "".concat(inputValue);
  3348. show(input);
  3349. input.focus();
  3350. instance.hideLoading();
  3351. }).catch(err => {
  3352. error("Error in inputValue promise: ".concat(err));
  3353. input.value = '';
  3354. show(input);
  3355. input.focus();
  3356. instance.hideLoading();
  3357. });
  3358. };
  3359.  
  3360. const populateInputOptions = {
  3361. select: (popup, inputOptions, params) => {
  3362. const select = getDirectChildByClass(popup, swalClasses.select);
  3363.  
  3364. const renderOption = (parent, optionLabel, optionValue) => {
  3365. const option = document.createElement('option');
  3366. option.value = optionValue;
  3367. setInnerHtml(option, optionLabel);
  3368. option.selected = isSelected(optionValue, params.inputValue);
  3369. parent.appendChild(option);
  3370. };
  3371.  
  3372. inputOptions.forEach(inputOption => {
  3373. const optionValue = inputOption[0];
  3374. const optionLabel = inputOption[1]; // <optgroup> spec:
  3375. // https://www.w3.org/TR/html401/interact/forms.html#h-17.6
  3376. // "...all OPTGROUP elements must be specified directly within a SELECT element (i.e., groups may not be nested)..."
  3377. // check whether this is a <optgroup>
  3378.  
  3379. if (Array.isArray(optionLabel)) {
  3380. // if it is an array, then it is an <optgroup>
  3381. const optgroup = document.createElement('optgroup');
  3382. optgroup.label = optionValue;
  3383. optgroup.disabled = false; // not configurable for now
  3384.  
  3385. select.appendChild(optgroup);
  3386. optionLabel.forEach(o => renderOption(optgroup, o[1], o[0]));
  3387. } else {
  3388. // case of <option>
  3389. renderOption(select, optionLabel, optionValue);
  3390. }
  3391. });
  3392. select.focus();
  3393. },
  3394. radio: (popup, inputOptions, params) => {
  3395. const radio = getDirectChildByClass(popup, swalClasses.radio);
  3396. inputOptions.forEach(inputOption => {
  3397. const radioValue = inputOption[0];
  3398. const radioLabel = inputOption[1];
  3399. const radioInput = document.createElement('input');
  3400. const radioLabelElement = document.createElement('label');
  3401. radioInput.type = 'radio';
  3402. radioInput.name = swalClasses.radio;
  3403. radioInput.value = radioValue;
  3404.  
  3405. if (isSelected(radioValue, params.inputValue)) {
  3406. radioInput.checked = true;
  3407. }
  3408.  
  3409. const label = document.createElement('span');
  3410. setInnerHtml(label, radioLabel);
  3411. label.className = swalClasses.label;
  3412. radioLabelElement.appendChild(radioInput);
  3413. radioLabelElement.appendChild(label);
  3414. radio.appendChild(radioLabelElement);
  3415. });
  3416. const radios = radio.querySelectorAll('input');
  3417.  
  3418. if (radios.length) {
  3419. radios[0].focus();
  3420. }
  3421. }
  3422. };
  3423. /**
  3424. * Converts `inputOptions` into an array of `[value, label]`s
  3425. * @param inputOptions
  3426. */
  3427.  
  3428. const formatInputOptions = inputOptions => {
  3429. const result = [];
  3430.  
  3431. if (typeof Map !== 'undefined' && inputOptions instanceof Map) {
  3432. inputOptions.forEach((value, key) => {
  3433. let valueFormatted = value;
  3434.  
  3435. if (typeof valueFormatted === 'object') {
  3436. // case of <optgroup>
  3437. valueFormatted = formatInputOptions(valueFormatted);
  3438. }
  3439.  
  3440. result.push([key, valueFormatted]);
  3441. });
  3442. } else {
  3443. Object.keys(inputOptions).forEach(key => {
  3444. let valueFormatted = inputOptions[key];
  3445.  
  3446. if (typeof valueFormatted === 'object') {
  3447. // case of <optgroup>
  3448. valueFormatted = formatInputOptions(valueFormatted);
  3449. }
  3450.  
  3451. result.push([key, valueFormatted]);
  3452. });
  3453. }
  3454.  
  3455. return result;
  3456. };
  3457.  
  3458. const isSelected = (optionValue, inputValue) => {
  3459. return inputValue && inputValue.toString() === optionValue.toString();
  3460. };
  3461.  
  3462. /**
  3463. * Hides loader and shows back the button which was hidden by .showLoading()
  3464. */
  3465.  
  3466. function hideLoading() {
  3467. // do nothing if popup is closed
  3468. const innerParams = privateProps.innerParams.get(this);
  3469.  
  3470. if (!innerParams) {
  3471. return;
  3472. }
  3473.  
  3474. const domCache = privateProps.domCache.get(this);
  3475. hide(domCache.loader);
  3476.  
  3477. if (isToast()) {
  3478. if (innerParams.icon) {
  3479. show(getIcon());
  3480. }
  3481. } else {
  3482. showRelatedButton(domCache);
  3483. }
  3484.  
  3485. removeClass([domCache.popup, domCache.actions], swalClasses.loading);
  3486. domCache.popup.removeAttribute('aria-busy');
  3487. domCache.popup.removeAttribute('data-loading');
  3488. domCache.confirmButton.disabled = false;
  3489. domCache.denyButton.disabled = false;
  3490. domCache.cancelButton.disabled = false;
  3491. }
  3492.  
  3493. const showRelatedButton = domCache => {
  3494. const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute('data-button-to-replace'));
  3495.  
  3496. if (buttonToReplace.length) {
  3497. show(buttonToReplace[0], 'inline-block');
  3498. } else if (allButtonsAreHidden()) {
  3499. hide(domCache.actions);
  3500. }
  3501. };
  3502.  
  3503. /**
  3504. * Gets the input DOM node, this method works with input parameter.
  3505. * @returns {HTMLElement | null}
  3506. */
  3507.  
  3508. function getInput$1(instance) {
  3509. const innerParams = privateProps.innerParams.get(instance || this);
  3510. const domCache = privateProps.domCache.get(instance || this);
  3511.  
  3512. if (!domCache) {
  3513. return null;
  3514. }
  3515.  
  3516. return getInput(domCache.popup, innerParams.input);
  3517. }
  3518.  
  3519. /**
  3520. * This module contains `WeakMap`s for each effectively-"private property" that a `Swal` has.
  3521. * For example, to set the private property "foo" of `this` to "bar", you can `privateProps.foo.set(this, 'bar')`
  3522. * This is the approach that Babel will probably take to implement private methods/fields
  3523. * https://github.com/tc39/proposal-private-methods
  3524. * https://github.com/babel/babel/pull/7555
  3525. * Once we have the changes from that PR in Babel, and our core class fits reasonable in *one module*
  3526. * then we can use that language feature.
  3527. */
  3528. var privateMethods = {
  3529. swalPromiseResolve: new WeakMap(),
  3530. swalPromiseReject: new WeakMap()
  3531. };
  3532.  
  3533. /*
  3534. * Global function to determine if SweetAlert2 popup is shown
  3535. */
  3536.  
  3537. const isVisible$1 = () => {
  3538. return isVisible(getPopup());
  3539. };
  3540. /*
  3541. * Global function to click 'Confirm' button
  3542. */
  3543.  
  3544. const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
  3545. /*
  3546. * Global function to click 'Deny' button
  3547. */
  3548.  
  3549. const clickDeny = () => getDenyButton() && getDenyButton().click();
  3550. /*
  3551. * Global function to click 'Cancel' button
  3552. */
  3553.  
  3554. const clickCancel = () => getCancelButton() && getCancelButton().click();
  3555.  
  3556. const removeKeydownHandler = globalState => {
  3557. if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
  3558. globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
  3559. capture: globalState.keydownListenerCapture
  3560. });
  3561. globalState.keydownHandlerAdded = false;
  3562. }
  3563. };
  3564. const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
  3565. removeKeydownHandler(globalState);
  3566.  
  3567. if (!innerParams.toast) {
  3568. globalState.keydownHandler = e => keydownHandler(instance, e, dismissWith);
  3569.  
  3570. globalState.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
  3571. globalState.keydownListenerCapture = innerParams.keydownListenerCapture;
  3572. globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
  3573. capture: globalState.keydownListenerCapture
  3574. });
  3575. globalState.keydownHandlerAdded = true;
  3576. }
  3577. }; // Focus handling
  3578.  
  3579. const setFocus = (innerParams, index, increment) => {
  3580. const focusableElements = getFocusableElements(); // search for visible elements and select the next possible match
  3581.  
  3582. if (focusableElements.length) {
  3583. index = index + increment; // rollover to first item
  3584.  
  3585. if (index === focusableElements.length) {
  3586. index = 0; // go to last item
  3587. } else if (index === -1) {
  3588. index = focusableElements.length - 1;
  3589. }
  3590.  
  3591. return focusableElements[index].focus();
  3592. } // no visible focusable elements, focus the popup
  3593.  
  3594.  
  3595. getPopup().focus();
  3596. };
  3597. const arrowKeysNextButton = ['ArrowRight', 'ArrowDown'];
  3598. const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp'];
  3599.  
  3600. const keydownHandler = (instance, e, dismissWith) => {
  3601. const innerParams = privateProps.innerParams.get(instance);
  3602.  
  3603. if (!innerParams) {
  3604. return; // This instance has already been destroyed
  3605. } // Ignore keydown during IME composition
  3606. // https://developer.mozilla.org/en-US/docs/Web/API/Document/keydown_event#ignoring_keydown_during_ime_composition
  3607. // https://github.com/sweetalert2/sweetalert2/issues/720
  3608. // https://github.com/sweetalert2/sweetalert2/issues/2406
  3609.  
  3610.  
  3611. if (e.isComposing || e.keyCode === 229) {
  3612. return;
  3613. }
  3614.  
  3615. if (innerParams.stopKeydownPropagation) {
  3616. e.stopPropagation();
  3617. } // ENTER
  3618.  
  3619.  
  3620. if (e.key === 'Enter') {
  3621. handleEnter(instance, e, innerParams);
  3622. } // TAB
  3623. else if (e.key === 'Tab') {
  3624. handleTab(e, innerParams);
  3625. } // ARROWS - switch focus between buttons
  3626. else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
  3627. handleArrows(e.key);
  3628. } // ESC
  3629. else if (e.key === 'Escape') {
  3630. handleEsc(e, innerParams, dismissWith);
  3631. }
  3632. };
  3633.  
  3634. const handleEnter = (instance, e, innerParams) => {
  3635. // https://github.com/sweetalert2/sweetalert2/issues/2386
  3636. if (!callIfFunction(innerParams.allowEnterKey)) {
  3637. return;
  3638. }
  3639.  
  3640. if (e.target && instance.getInput() && e.target.outerHTML === instance.getInput().outerHTML) {
  3641. if (['textarea', 'file'].includes(innerParams.input)) {
  3642. return; // do not submit
  3643. }
  3644.  
  3645. clickConfirm();
  3646. e.preventDefault();
  3647. }
  3648. };
  3649.  
  3650. const handleTab = (e, innerParams) => {
  3651. const targetElement = e.target;
  3652. const focusableElements = getFocusableElements();
  3653. let btnIndex = -1;
  3654.  
  3655. for (let i = 0; i < focusableElements.length; i++) {
  3656. if (targetElement === focusableElements[i]) {
  3657. btnIndex = i;
  3658. break;
  3659. }
  3660. } // Cycle to the next button
  3661.  
  3662.  
  3663. if (!e.shiftKey) {
  3664. setFocus(innerParams, btnIndex, 1);
  3665. } // Cycle to the prev button
  3666. else {
  3667. setFocus(innerParams, btnIndex, -1);
  3668. }
  3669.  
  3670. e.stopPropagation();
  3671. e.preventDefault();
  3672. };
  3673.  
  3674. const handleArrows = key => {
  3675. const confirmButton = getConfirmButton();
  3676. const denyButton = getDenyButton();
  3677. const cancelButton = getCancelButton();
  3678.  
  3679. if (![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
  3680. return;
  3681. }
  3682.  
  3683. const sibling = arrowKeysNextButton.includes(key) ? 'nextElementSibling' : 'previousElementSibling';
  3684. let buttonToFocus = document.activeElement;
  3685.  
  3686. for (let i = 0; i < getActions().children.length; i++) {
  3687. buttonToFocus = buttonToFocus[sibling];
  3688.  
  3689. if (!buttonToFocus) {
  3690. return;
  3691. }
  3692.  
  3693. if (isVisible(buttonToFocus) && buttonToFocus instanceof HTMLButtonElement) {
  3694. break;
  3695. }
  3696. }
  3697.  
  3698. if (buttonToFocus instanceof HTMLButtonElement) {
  3699. buttonToFocus.focus();
  3700. }
  3701. };
  3702.  
  3703. const handleEsc = (e, innerParams, dismissWith) => {
  3704. if (callIfFunction(innerParams.allowEscapeKey)) {
  3705. e.preventDefault();
  3706. dismissWith(DismissReason.esc);
  3707. }
  3708. };
  3709.  
  3710. /*
  3711. * Instance method to close sweetAlert
  3712. */
  3713.  
  3714. function removePopupAndResetState(instance, container, returnFocus, didClose) {
  3715. if (isToast()) {
  3716. triggerDidCloseAndDispose(instance, didClose);
  3717. } else {
  3718. restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
  3719. removeKeydownHandler(globalState);
  3720. }
  3721.  
  3722. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); // workaround for #2088
  3723. // for some reason removing the container in Safari will scroll the document to bottom
  3724.  
  3725. if (isSafari) {
  3726. container.setAttribute('style', 'display:none !important');
  3727. container.removeAttribute('class');
  3728. container.innerHTML = '';
  3729. } else {
  3730. container.remove();
  3731. }
  3732.  
  3733. if (isModal()) {
  3734. undoScrollbar();
  3735. undoIOSfix();
  3736. unsetAriaHidden();
  3737. }
  3738.  
  3739. removeBodyClasses();
  3740. }
  3741.  
  3742. function removeBodyClasses() {
  3743. removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses['height-auto'], swalClasses['no-backdrop'], swalClasses['toast-shown']]);
  3744. }
  3745.  
  3746. function close(resolveValue) {
  3747. resolveValue = prepareResolveValue(resolveValue);
  3748. const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
  3749. const didClose = triggerClosePopup(this);
  3750.  
  3751. if (this.isAwaitingPromise()) {
  3752. // A swal awaiting for a promise (after a click on Confirm or Deny) cannot be dismissed anymore #2335
  3753. if (!resolveValue.isDismissed) {
  3754. handleAwaitingPromise(this);
  3755. swalPromiseResolve(resolveValue);
  3756. }
  3757. } else if (didClose) {
  3758. // Resolve Swal promise
  3759. swalPromiseResolve(resolveValue);
  3760. }
  3761. }
  3762. function isAwaitingPromise() {
  3763. return !!privateProps.awaitingPromise.get(this);
  3764. }
  3765.  
  3766. const triggerClosePopup = instance => {
  3767. const popup = getPopup();
  3768.  
  3769. if (!popup) {
  3770. return false;
  3771. }
  3772.  
  3773. const innerParams = privateProps.innerParams.get(instance);
  3774.  
  3775. if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
  3776. return false;
  3777. }
  3778.  
  3779. removeClass(popup, innerParams.showClass.popup);
  3780. addClass(popup, innerParams.hideClass.popup);
  3781. const backdrop = getContainer();
  3782. removeClass(backdrop, innerParams.showClass.backdrop);
  3783. addClass(backdrop, innerParams.hideClass.backdrop);
  3784. handlePopupAnimation(instance, popup, innerParams);
  3785. return true;
  3786. };
  3787.  
  3788. function rejectPromise(error) {
  3789. const rejectPromise = privateMethods.swalPromiseReject.get(this);
  3790. handleAwaitingPromise(this);
  3791.  
  3792. if (rejectPromise) {
  3793. // Reject Swal promise
  3794. rejectPromise(error);
  3795. }
  3796. }
  3797. const handleAwaitingPromise = instance => {
  3798. if (instance.isAwaitingPromise()) {
  3799. privateProps.awaitingPromise.delete(instance); // The instance might have been previously partly destroyed, we must resume the destroy process in this case #2335
  3800.  
  3801. if (!privateProps.innerParams.get(instance)) {
  3802. instance._destroy();
  3803. }
  3804. }
  3805. };
  3806.  
  3807. const prepareResolveValue = resolveValue => {
  3808. // When user calls Swal.close()
  3809. if (typeof resolveValue === 'undefined') {
  3810. return {
  3811. isConfirmed: false,
  3812. isDenied: false,
  3813. isDismissed: true
  3814. };
  3815. }
  3816.  
  3817. return Object.assign({
  3818. isConfirmed: false,
  3819. isDenied: false,
  3820. isDismissed: false
  3821. }, resolveValue);
  3822. };
  3823.  
  3824. const handlePopupAnimation = (instance, popup, innerParams) => {
  3825. const container = getContainer(); // If animation is supported, animate
  3826.  
  3827. const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
  3828.  
  3829. if (typeof innerParams.willClose === 'function') {
  3830. innerParams.willClose(popup);
  3831. }
  3832.  
  3833. if (animationIsSupported) {
  3834. animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
  3835. } else {
  3836. // Otherwise, remove immediately
  3837. removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
  3838. }
  3839. };
  3840.  
  3841. const animatePopup = (instance, popup, container, returnFocus, didClose) => {
  3842. globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
  3843. popup.addEventListener(animationEndEvent, function (e) {
  3844. if (e.target === popup) {
  3845. globalState.swalCloseEventFinishedCallback();
  3846. delete globalState.swalCloseEventFinishedCallback;
  3847. }
  3848. });
  3849. };
  3850.  
  3851. const triggerDidCloseAndDispose = (instance, didClose) => {
  3852. setTimeout(() => {
  3853. if (typeof didClose === 'function') {
  3854. didClose.bind(instance.params)();
  3855. }
  3856.  
  3857. instance._destroy();
  3858. });
  3859. };
  3860.  
  3861. function setButtonsDisabled(instance, buttons, disabled) {
  3862. const domCache = privateProps.domCache.get(instance);
  3863. buttons.forEach(button => {
  3864. domCache[button].disabled = disabled;
  3865. });
  3866. }
  3867.  
  3868. function setInputDisabled(input, disabled) {
  3869. if (!input) {
  3870. return false;
  3871. }
  3872.  
  3873. if (input.type === 'radio') {
  3874. const radiosContainer = input.parentNode.parentNode;
  3875. const radios = radiosContainer.querySelectorAll('input');
  3876.  
  3877. for (let i = 0; i < radios.length; i++) {
  3878. radios[i].disabled = disabled;
  3879. }
  3880. } else {
  3881. input.disabled = disabled;
  3882. }
  3883. }
  3884.  
  3885. function enableButtons() {
  3886. setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false);
  3887. }
  3888. function disableButtons() {
  3889. setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true);
  3890. }
  3891. function enableInput() {
  3892. return setInputDisabled(this.getInput(), false);
  3893. }
  3894. function disableInput() {
  3895. return setInputDisabled(this.getInput(), true);
  3896. }
  3897.  
  3898. function showValidationMessage(error) {
  3899. const domCache = privateProps.domCache.get(this);
  3900. const params = privateProps.innerParams.get(this);
  3901. setInnerHtml(domCache.validationMessage, error);
  3902. domCache.validationMessage.className = swalClasses['validation-message'];
  3903.  
  3904. if (params.customClass && params.customClass.validationMessage) {
  3905. addClass(domCache.validationMessage, params.customClass.validationMessage);
  3906. }
  3907.  
  3908. show(domCache.validationMessage);
  3909. const input = this.getInput();
  3910.  
  3911. if (input) {
  3912. input.setAttribute('aria-invalid', true);
  3913. input.setAttribute('aria-describedby', swalClasses['validation-message']);
  3914. focusInput(input);
  3915. addClass(input, swalClasses.inputerror);
  3916. }
  3917. } // Hide block with validation message
  3918.  
  3919. function resetValidationMessage$1() {
  3920. const domCache = privateProps.domCache.get(this);
  3921.  
  3922. if (domCache.validationMessage) {
  3923. hide(domCache.validationMessage);
  3924. }
  3925.  
  3926. const input = this.getInput();
  3927.  
  3928. if (input) {
  3929. input.removeAttribute('aria-invalid');
  3930. input.removeAttribute('aria-describedby');
  3931. removeClass(input, swalClasses.inputerror);
  3932. }
  3933. }
  3934.  
  3935. function getProgressSteps$1() {
  3936. const domCache = privateProps.domCache.get(this);
  3937. return domCache.progressSteps;
  3938. }
  3939.  
  3940. /**
  3941. * Updates popup parameters.
  3942. */
  3943.  
  3944. function update(params) {
  3945. const popup = getPopup();
  3946. const innerParams = privateProps.innerParams.get(this);
  3947.  
  3948. if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
  3949. return 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.");
  3950. }
  3951.  
  3952. const validUpdatableParams = filterValidParams(params);
  3953. const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
  3954. render(this, updatedParams);
  3955. privateProps.innerParams.set(this, updatedParams);
  3956. Object.defineProperties(this, {
  3957. params: {
  3958. value: Object.assign({}, this.params, params),
  3959. writable: false,
  3960. enumerable: true
  3961. }
  3962. });
  3963. }
  3964.  
  3965. const filterValidParams = params => {
  3966. const validUpdatableParams = {};
  3967. Object.keys(params).forEach(param => {
  3968. if (isUpdatableParameter(param)) {
  3969. validUpdatableParams[param] = params[param];
  3970. } else {
  3971. warn("Invalid parameter to update: \"".concat(param, "\". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md"));
  3972. }
  3973. });
  3974. return validUpdatableParams;
  3975. };
  3976.  
  3977. function _destroy() {
  3978. const domCache = privateProps.domCache.get(this);
  3979. const innerParams = privateProps.innerParams.get(this);
  3980.  
  3981. if (!innerParams) {
  3982. disposeWeakMaps(this); // The WeakMaps might have been partly destroyed, we must recall it to dispose any remaining WeakMaps #2335
  3983.  
  3984. return; // This instance has already been destroyed
  3985. } // Check if there is another Swal closing
  3986.  
  3987.  
  3988. if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
  3989. globalState.swalCloseEventFinishedCallback();
  3990. delete globalState.swalCloseEventFinishedCallback;
  3991. } // Check if there is a swal disposal defer timer
  3992.  
  3993.  
  3994. if (globalState.deferDisposalTimer) {
  3995. clearTimeout(globalState.deferDisposalTimer);
  3996. delete globalState.deferDisposalTimer;
  3997. }
  3998.  
  3999. if (typeof innerParams.didDestroy === 'function') {
  4000. innerParams.didDestroy();
  4001. }
  4002.  
  4003. disposeSwal(this);
  4004. }
  4005.  
  4006. const disposeSwal = instance => {
  4007. disposeWeakMaps(instance); // Unset this.params so GC will dispose it (#1569)
  4008.  
  4009. delete instance.params; // Unset globalState props so GC will dispose globalState (#1569)
  4010.  
  4011. delete globalState.keydownHandler;
  4012. delete globalState.keydownTarget; // Unset currentInstance
  4013.  
  4014. delete globalState.currentInstance;
  4015. };
  4016.  
  4017. const disposeWeakMaps = instance => {
  4018. // If the current instance is awaiting a promise result, we keep the privateMethods to call them once the promise result is retrieved #2335
  4019. if (instance.isAwaitingPromise()) {
  4020. unsetWeakMaps(privateProps, instance);
  4021. privateProps.awaitingPromise.set(instance, true);
  4022. } else {
  4023. unsetWeakMaps(privateMethods, instance);
  4024. unsetWeakMaps(privateProps, instance);
  4025. }
  4026. };
  4027.  
  4028. const unsetWeakMaps = (obj, instance) => {
  4029. for (const i in obj) {
  4030. obj[i].delete(instance);
  4031. }
  4032. };
  4033.  
  4034.  
  4035.  
  4036. var instanceMethods = /*#__PURE__*/Object.freeze({
  4037. hideLoading: hideLoading,
  4038. disableLoading: hideLoading,
  4039. getInput: getInput$1,
  4040. close: close,
  4041. isAwaitingPromise: isAwaitingPromise,
  4042. rejectPromise: rejectPromise,
  4043. handleAwaitingPromise: handleAwaitingPromise,
  4044. closePopup: close,
  4045. closeModal: close,
  4046. closeToast: close,
  4047. enableButtons: enableButtons,
  4048. disableButtons: disableButtons,
  4049. enableInput: enableInput,
  4050. disableInput: disableInput,
  4051. showValidationMessage: showValidationMessage,
  4052. resetValidationMessage: resetValidationMessage$1,
  4053. getProgressSteps: getProgressSteps$1,
  4054. update: update,
  4055. _destroy: _destroy
  4056. });
  4057.  
  4058. const handleConfirmButtonClick = instance => {
  4059. const innerParams = privateProps.innerParams.get(instance);
  4060. instance.disableButtons();
  4061.  
  4062. if (innerParams.input) {
  4063. handleConfirmOrDenyWithInput(instance, 'confirm');
  4064. } else {
  4065. confirm(instance, true);
  4066. }
  4067. };
  4068. const handleDenyButtonClick = instance => {
  4069. const innerParams = privateProps.innerParams.get(instance);
  4070. instance.disableButtons();
  4071.  
  4072. if (innerParams.returnInputValueOnDeny) {
  4073. handleConfirmOrDenyWithInput(instance, 'deny');
  4074. } else {
  4075. deny(instance, false);
  4076. }
  4077. };
  4078. const handleCancelButtonClick = (instance, dismissWith) => {
  4079. instance.disableButtons();
  4080. dismissWith(DismissReason.cancel);
  4081. };
  4082.  
  4083. const handleConfirmOrDenyWithInput = (instance, type
  4084. /* 'confirm' | 'deny' */
  4085. ) => {
  4086. const innerParams = privateProps.innerParams.get(instance);
  4087.  
  4088. if (!innerParams.input) {
  4089. return error("The \"input\" parameter is needed to be set when using returnInputValueOn".concat(capitalizeFirstLetter(type)));
  4090. }
  4091.  
  4092. const inputValue = getInputValue(instance, innerParams);
  4093.  
  4094. if (innerParams.inputValidator) {
  4095. handleInputValidator(instance, inputValue, type);
  4096. } else if (!instance.getInput().checkValidity()) {
  4097. instance.enableButtons();
  4098. instance.showValidationMessage(innerParams.validationMessage);
  4099. } else if (type === 'deny') {
  4100. deny(instance, inputValue);
  4101. } else {
  4102. confirm(instance, inputValue);
  4103. }
  4104. };
  4105.  
  4106. const handleInputValidator = (instance, inputValue, type
  4107. /* 'confirm' | 'deny' */
  4108. ) => {
  4109. const innerParams = privateProps.innerParams.get(instance);
  4110. instance.disableInput();
  4111. const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
  4112. validationPromise.then(validationMessage => {
  4113. instance.enableButtons();
  4114. instance.enableInput();
  4115.  
  4116. if (validationMessage) {
  4117. instance.showValidationMessage(validationMessage);
  4118. } else if (type === 'deny') {
  4119. deny(instance, inputValue);
  4120. } else {
  4121. confirm(instance, inputValue);
  4122. }
  4123. });
  4124. };
  4125.  
  4126. const deny = (instance, value) => {
  4127. const innerParams = privateProps.innerParams.get(instance || undefined);
  4128.  
  4129. if (innerParams.showLoaderOnDeny) {
  4130. showLoading(getDenyButton());
  4131. }
  4132.  
  4133. if (innerParams.preDeny) {
  4134. privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preDeny's promise is received
  4135.  
  4136. const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
  4137. preDenyPromise.then(preDenyValue => {
  4138. if (preDenyValue === false) {
  4139. instance.hideLoading();
  4140. handleAwaitingPromise(instance);
  4141. } else {
  4142. instance.closePopup({
  4143. isDenied: true,
  4144. value: typeof preDenyValue === 'undefined' ? value : preDenyValue
  4145. });
  4146. }
  4147. }).catch(error$$1 => rejectWith(instance || undefined, error$$1));
  4148. } else {
  4149. instance.closePopup({
  4150. isDenied: true,
  4151. value
  4152. });
  4153. }
  4154. };
  4155.  
  4156. const succeedWith = (instance, value) => {
  4157. instance.closePopup({
  4158. isConfirmed: true,
  4159. value
  4160. });
  4161. };
  4162.  
  4163. const rejectWith = (instance, error$$1) => {
  4164. instance.rejectPromise(error$$1);
  4165. };
  4166.  
  4167. const confirm = (instance, value) => {
  4168. const innerParams = privateProps.innerParams.get(instance || undefined);
  4169.  
  4170. if (innerParams.showLoaderOnConfirm) {
  4171. showLoading();
  4172. }
  4173.  
  4174. if (innerParams.preConfirm) {
  4175. instance.resetValidationMessage();
  4176. privateProps.awaitingPromise.set(instance || undefined, true); // Flagging the instance as awaiting a promise so it's own promise's reject/resolve methods doesn't get destroyed until the result from this preConfirm's promise is received
  4177.  
  4178. const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
  4179. preConfirmPromise.then(preConfirmValue => {
  4180. if (isVisible(getValidationMessage()) || preConfirmValue === false) {
  4181. instance.hideLoading();
  4182. handleAwaitingPromise(instance);
  4183. } else {
  4184. succeedWith(instance, typeof preConfirmValue === 'undefined' ? value : preConfirmValue);
  4185. }
  4186. }).catch(error$$1 => rejectWith(instance || undefined, error$$1));
  4187. } else {
  4188. succeedWith(instance, value);
  4189. }
  4190. };
  4191.  
  4192. const handlePopupClick = (instance, domCache, dismissWith) => {
  4193. const innerParams = privateProps.innerParams.get(instance);
  4194.  
  4195. if (innerParams.toast) {
  4196. handleToastClick(instance, domCache, dismissWith);
  4197. } else {
  4198. // Ignore click events that had mousedown on the popup but mouseup on the container
  4199. // This can happen when the user drags a slider
  4200. handleModalMousedown(domCache); // Ignore click events that had mousedown on the container but mouseup on the popup
  4201.  
  4202. handleContainerMousedown(domCache);
  4203. handleModalClick(instance, domCache, dismissWith);
  4204. }
  4205. };
  4206.  
  4207. const handleToastClick = (instance, domCache, dismissWith) => {
  4208. // Closing toast by internal click
  4209. domCache.popup.onclick = () => {
  4210. const innerParams = privateProps.innerParams.get(instance);
  4211.  
  4212. if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
  4213. return;
  4214. }
  4215.  
  4216. dismissWith(DismissReason.close);
  4217. };
  4218. };
  4219. /**
  4220. * @param {*} innerParams
  4221. * @returns {boolean}
  4222. */
  4223.  
  4224.  
  4225. const isAnyButtonShown = innerParams => {
  4226. return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
  4227. };
  4228.  
  4229. let ignoreOutsideClick = false;
  4230.  
  4231. const handleModalMousedown = domCache => {
  4232. domCache.popup.onmousedown = () => {
  4233. domCache.container.onmouseup = function (e) {
  4234. domCache.container.onmouseup = undefined; // We only check if the mouseup target is the container because usually it doesn't
  4235. // have any other direct children aside of the popup
  4236.  
  4237. if (e.target === domCache.container) {
  4238. ignoreOutsideClick = true;
  4239. }
  4240. };
  4241. };
  4242. };
  4243.  
  4244. const handleContainerMousedown = domCache => {
  4245. domCache.container.onmousedown = () => {
  4246. domCache.popup.onmouseup = function (e) {
  4247. domCache.popup.onmouseup = undefined; // We also need to check if the mouseup target is a child of the popup
  4248.  
  4249. if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
  4250. ignoreOutsideClick = true;
  4251. }
  4252. };
  4253. };
  4254. };
  4255.  
  4256. const handleModalClick = (instance, domCache, dismissWith) => {
  4257. domCache.container.onclick = e => {
  4258. const innerParams = privateProps.innerParams.get(instance);
  4259.  
  4260. if (ignoreOutsideClick) {
  4261. ignoreOutsideClick = false;
  4262. return;
  4263. }
  4264.  
  4265. if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
  4266. dismissWith(DismissReason.backdrop);
  4267. }
  4268. };
  4269. };
  4270.  
  4271. const isJqueryElement = elem => typeof elem === 'object' && elem.jquery;
  4272.  
  4273. const isElement = elem => elem instanceof Element || isJqueryElement(elem);
  4274.  
  4275. const argsToParams = args => {
  4276. const params = {};
  4277.  
  4278. if (typeof args[0] === 'object' && !isElement(args[0])) {
  4279. Object.assign(params, args[0]);
  4280. } else {
  4281. ['title', 'html', 'icon'].forEach((name, index) => {
  4282. const arg = args[index];
  4283.  
  4284. if (typeof arg === 'string' || isElement(arg)) {
  4285. params[name] = arg;
  4286. } else if (arg !== undefined) {
  4287. error("Unexpected type of ".concat(name, "! Expected \"string\" or \"Element\", got ").concat(typeof arg));
  4288. }
  4289. });
  4290. }
  4291.  
  4292. return params;
  4293. };
  4294.  
  4295. function fire() {
  4296. const Swal = this; // eslint-disable-line @typescript-eslint/no-this-alias
  4297.  
  4298. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4299. args[_key] = arguments[_key];
  4300. }
  4301.  
  4302. return new Swal(...args);
  4303. }
  4304.  
  4305. /**
  4306. * Returns an extended version of `Swal` containing `params` as defaults.
  4307. * Useful for reusing Swal configuration.
  4308. *
  4309. * For example:
  4310. *
  4311. * Before:
  4312. * const textPromptOptions = { input: 'text', showCancelButton: true }
  4313. * const {value: firstName} = await Swal.fire({ ...textPromptOptions, title: 'What is your first name?' })
  4314. * const {value: lastName} = await Swal.fire({ ...textPromptOptions, title: 'What is your last name?' })
  4315. *
  4316. * After:
  4317. * const TextPrompt = Swal.mixin({ input: 'text', showCancelButton: true })
  4318. * const {value: firstName} = await TextPrompt('What is your first name?')
  4319. * const {value: lastName} = await TextPrompt('What is your last name?')
  4320. *
  4321. * @param mixinParams
  4322. */
  4323. function mixin(mixinParams) {
  4324. class MixinSwal extends this {
  4325. _main(params, priorityMixinParams) {
  4326. return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
  4327. }
  4328.  
  4329. }
  4330.  
  4331. return MixinSwal;
  4332. }
  4333.  
  4334. /**
  4335. * If `timer` parameter is set, returns number of milliseconds of timer remained.
  4336. * Otherwise, returns undefined.
  4337. */
  4338.  
  4339. const getTimerLeft = () => {
  4340. return globalState.timeout && globalState.timeout.getTimerLeft();
  4341. };
  4342. /**
  4343. * Stop timer. Returns number of milliseconds of timer remained.
  4344. * If `timer` parameter isn't set, returns undefined.
  4345. */
  4346.  
  4347. const stopTimer = () => {
  4348. if (globalState.timeout) {
  4349. stopTimerProgressBar();
  4350. return globalState.timeout.stop();
  4351. }
  4352. };
  4353. /**
  4354. * Resume timer. Returns number of milliseconds of timer remained.
  4355. * If `timer` parameter isn't set, returns undefined.
  4356. */
  4357.  
  4358. const resumeTimer = () => {
  4359. if (globalState.timeout) {
  4360. const remaining = globalState.timeout.start();
  4361. animateTimerProgressBar(remaining);
  4362. return remaining;
  4363. }
  4364. };
  4365. /**
  4366. * Resume timer. Returns number of milliseconds of timer remained.
  4367. * If `timer` parameter isn't set, returns undefined.
  4368. */
  4369.  
  4370. const toggleTimer = () => {
  4371. const timer = globalState.timeout;
  4372. return timer && (timer.running ? stopTimer() : resumeTimer());
  4373. };
  4374. /**
  4375. * Increase timer. Returns number of milliseconds of an updated timer.
  4376. * If `timer` parameter isn't set, returns undefined.
  4377. */
  4378.  
  4379. const increaseTimer = n => {
  4380. if (globalState.timeout) {
  4381. const remaining = globalState.timeout.increase(n);
  4382. animateTimerProgressBar(remaining, true);
  4383. return remaining;
  4384. }
  4385. };
  4386. /**
  4387. * Check if timer is running. Returns true if timer is running
  4388. * or false if timer is paused or stopped.
  4389. * If `timer` parameter isn't set, returns undefined
  4390. */
  4391.  
  4392. const isTimerRunning = () => {
  4393. return globalState.timeout && globalState.timeout.isRunning();
  4394. };
  4395.  
  4396. let bodyClickListenerAdded = false;
  4397. const clickHandlers = {};
  4398. function bindClickHandler() {
  4399. let attr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'data-swal-template';
  4400. clickHandlers[attr] = this;
  4401.  
  4402. if (!bodyClickListenerAdded) {
  4403. document.body.addEventListener('click', bodyClickListener);
  4404. bodyClickListenerAdded = true;
  4405. }
  4406. }
  4407.  
  4408. const bodyClickListener = event => {
  4409. for (let el = event.target; el && el !== document; el = el.parentNode) {
  4410. for (const attr in clickHandlers) {
  4411. const template = el.getAttribute(attr);
  4412.  
  4413. if (template) {
  4414. clickHandlers[attr].fire({
  4415. template
  4416. });
  4417. return;
  4418. }
  4419. }
  4420. }
  4421. };
  4422.  
  4423.  
  4424.  
  4425. var staticMethods = /*#__PURE__*/Object.freeze({
  4426. isValidParameter: isValidParameter,
  4427. isUpdatableParameter: isUpdatableParameter,
  4428. isDeprecatedParameter: isDeprecatedParameter,
  4429. argsToParams: argsToParams,
  4430. isVisible: isVisible$1,
  4431. clickConfirm: clickConfirm,
  4432. clickDeny: clickDeny,
  4433. clickCancel: clickCancel,
  4434. getContainer: getContainer,
  4435. getPopup: getPopup,
  4436. getTitle: getTitle,
  4437. getHtmlContainer: getHtmlContainer,
  4438. getImage: getImage,
  4439. getIcon: getIcon,
  4440. getInputLabel: getInputLabel,
  4441. getCloseButton: getCloseButton,
  4442. getActions: getActions,
  4443. getConfirmButton: getConfirmButton,
  4444. getDenyButton: getDenyButton,
  4445. getCancelButton: getCancelButton,
  4446. getLoader: getLoader,
  4447. getFooter: getFooter,
  4448. getTimerProgressBar: getTimerProgressBar,
  4449. getFocusableElements: getFocusableElements,
  4450. getValidationMessage: getValidationMessage,
  4451. isLoading: isLoading,
  4452. fire: fire,
  4453. mixin: mixin,
  4454. showLoading: showLoading,
  4455. enableLoading: showLoading,
  4456. getTimerLeft: getTimerLeft,
  4457. stopTimer: stopTimer,
  4458. resumeTimer: resumeTimer,
  4459. toggleTimer: toggleTimer,
  4460. increaseTimer: increaseTimer,
  4461. isTimerRunning: isTimerRunning,
  4462. bindClickHandler: bindClickHandler
  4463. });
  4464.  
  4465. let currentInstance;
  4466.  
  4467. class SweetAlert {
  4468. constructor() {
  4469. // Prevent run in Node env
  4470. if (typeof window === 'undefined') {
  4471. return;
  4472. }
  4473.  
  4474. currentInstance = this; // @ts-ignore
  4475.  
  4476. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  4477. args[_key] = arguments[_key];
  4478. }
  4479.  
  4480. const outerParams = Object.freeze(this.constructor.argsToParams(args));
  4481. Object.defineProperties(this, {
  4482. params: {
  4483. value: outerParams,
  4484. writable: false,
  4485. enumerable: true,
  4486. configurable: true
  4487. }
  4488. }); // @ts-ignore
  4489.  
  4490. const promise = this._main(this.params);
  4491.  
  4492. privateProps.promise.set(this, promise);
  4493. }
  4494.  
  4495. _main(userParams) {
  4496. let mixinParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  4497. showWarningsForParams(Object.assign({}, mixinParams, userParams));
  4498.  
  4499. if (globalState.currentInstance) {
  4500. globalState.currentInstance._destroy();
  4501.  
  4502. if (isModal()) {
  4503. unsetAriaHidden();
  4504. }
  4505. }
  4506.  
  4507. globalState.currentInstance = this;
  4508. const innerParams = prepareParams(userParams, mixinParams);
  4509. setParameters(innerParams);
  4510. Object.freeze(innerParams); // clear the previous timer
  4511.  
  4512. if (globalState.timeout) {
  4513. globalState.timeout.stop();
  4514. delete globalState.timeout;
  4515. } // clear the restore focus timeout
  4516.  
  4517.  
  4518. clearTimeout(globalState.restoreFocusTimeout);
  4519. const domCache = populateDomCache(this);
  4520. render(this, innerParams);
  4521. privateProps.innerParams.set(this, innerParams);
  4522. return swalPromise(this, domCache, innerParams);
  4523. } // `catch` cannot be the name of a module export, so we define our thenable methods here instead
  4524.  
  4525.  
  4526. then(onFulfilled) {
  4527. const promise = privateProps.promise.get(this);
  4528. return promise.then(onFulfilled);
  4529. }
  4530.  
  4531. finally(onFinally) {
  4532. const promise = privateProps.promise.get(this);
  4533. return promise.finally(onFinally);
  4534. }
  4535.  
  4536. }
  4537.  
  4538. const swalPromise = (instance, domCache, innerParams) => {
  4539. return new Promise((resolve, reject) => {
  4540. // functions to handle all closings/dismissals
  4541. const dismissWith = dismiss => {
  4542. instance.closePopup({
  4543. isDismissed: true,
  4544. dismiss
  4545. });
  4546. };
  4547.  
  4548. privateMethods.swalPromiseResolve.set(instance, resolve);
  4549. privateMethods.swalPromiseReject.set(instance, reject);
  4550.  
  4551. domCache.confirmButton.onclick = () => handleConfirmButtonClick(instance);
  4552.  
  4553. domCache.denyButton.onclick = () => handleDenyButtonClick(instance);
  4554.  
  4555. domCache.cancelButton.onclick = () => handleCancelButtonClick(instance, dismissWith);
  4556.  
  4557. domCache.closeButton.onclick = () => dismissWith(DismissReason.close);
  4558.  
  4559. handlePopupClick(instance, domCache, dismissWith);
  4560. addKeydownHandler(instance, globalState, innerParams, dismissWith);
  4561. handleInputOptionsAndValue(instance, innerParams);
  4562. openPopup(innerParams);
  4563. setupTimer(globalState, innerParams, dismissWith);
  4564. initFocus(domCache, innerParams); // Scroll container to top on open (#1247, #1946)
  4565.  
  4566. setTimeout(() => {
  4567. domCache.container.scrollTop = 0;
  4568. });
  4569. });
  4570. };
  4571.  
  4572. const prepareParams = (userParams, mixinParams) => {
  4573. const templateParams = getTemplateParams(userParams);
  4574. const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams); // precedence is described in #2131
  4575.  
  4576. params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
  4577. params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
  4578. return params;
  4579. };
  4580.  
  4581. const populateDomCache = instance => {
  4582. const domCache = {
  4583. popup: getPopup(),
  4584. container: getContainer(),
  4585. actions: getActions(),
  4586. confirmButton: getConfirmButton(),
  4587. denyButton: getDenyButton(),
  4588. cancelButton: getCancelButton(),
  4589. loader: getLoader(),
  4590. closeButton: getCloseButton(),
  4591. validationMessage: getValidationMessage(),
  4592. progressSteps: getProgressSteps()
  4593. };
  4594. privateProps.domCache.set(instance, domCache);
  4595. return domCache;
  4596. };
  4597.  
  4598. const setupTimer = (globalState$$1, innerParams, dismissWith) => {
  4599. const timerProgressBar = getTimerProgressBar();
  4600. hide(timerProgressBar);
  4601.  
  4602. if (innerParams.timer) {
  4603. globalState$$1.timeout = new Timer(() => {
  4604. dismissWith('timer');
  4605. delete globalState$$1.timeout;
  4606. }, innerParams.timer);
  4607.  
  4608. if (innerParams.timerProgressBar) {
  4609. show(timerProgressBar);
  4610. applyCustomClass(timerProgressBar, innerParams, 'timerProgressBar');
  4611. setTimeout(() => {
  4612. if (globalState$$1.timeout && globalState$$1.timeout.running) {
  4613. // timer can be already stopped or unset at this point
  4614. animateTimerProgressBar(innerParams.timer);
  4615. }
  4616. });
  4617. }
  4618. }
  4619. };
  4620.  
  4621. const initFocus = (domCache, innerParams) => {
  4622. if (innerParams.toast) {
  4623. return;
  4624. }
  4625.  
  4626. if (!callIfFunction(innerParams.allowEnterKey)) {
  4627. return blurActiveElement();
  4628. }
  4629.  
  4630. if (!focusButton(domCache, innerParams)) {
  4631. setFocus(innerParams, -1, 1);
  4632. }
  4633. };
  4634.  
  4635. const focusButton = (domCache, innerParams) => {
  4636. if (innerParams.focusDeny && isVisible(domCache.denyButton)) {
  4637. domCache.denyButton.focus();
  4638. return true;
  4639. }
  4640.  
  4641. if (innerParams.focusCancel && isVisible(domCache.cancelButton)) {
  4642. domCache.cancelButton.focus();
  4643. return true;
  4644. }
  4645.  
  4646. if (innerParams.focusConfirm && isVisible(domCache.confirmButton)) {
  4647. domCache.confirmButton.focus();
  4648. return true;
  4649. }
  4650.  
  4651. return false;
  4652. };
  4653.  
  4654. const blurActiveElement = () => {
  4655. if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === 'function') {
  4656. document.activeElement.blur();
  4657. }
  4658. }; // Assign instance methods from src/instanceMethods/*.js to prototype
  4659.  
  4660.  
  4661. Object.assign(SweetAlert.prototype, instanceMethods); // Assign static methods from src/staticMethods/*.js to constructor
  4662.  
  4663. Object.assign(SweetAlert, staticMethods); // Proxy to instance methods to constructor, for now, for backwards compatibility
  4664.  
  4665. Object.keys(instanceMethods).forEach(key => {
  4666. SweetAlert[key] = function () {
  4667. if (currentInstance) {
  4668. return currentInstance[key](...arguments);
  4669. }
  4670. };
  4671. });
  4672. SweetAlert.DismissReason = DismissReason;
  4673. SweetAlert.version = '11.4.8';
  4674.  
  4675. const Swal = SweetAlert; // @ts-ignore
  4676.  
  4677. Swal.default = Swal;
  4678.  
  4679. return Swal;
  4680.  
  4681. }));
  4682. if (typeof this !== 'undefined' && this.Sweetalert2){ this.swal = this.sweetAlert = this.Swal = this.SweetAlert = this.Sweetalert2}
  4683.  
  4684. "undefined"!=typeof document&&function(e,t){var n=e.createElement("style");if(e.getElementsByTagName("head")[0].appendChild(n),n.styleSheet)n.styleSheet.disabled||(n.styleSheet.cssText=t);else try{n.innerHTML=t}catch(e){n.innerText=t}}(document,".swal2-popup.swal2-toast{box-sizing:border-box;grid-column:1/4!important;grid-row:1/4!important;grid-template-columns:1fr 99fr 1fr;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;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:700}.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:-.8em;left:-.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:-.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{-webkit-animation:swal2-toast-animate-success-line-tip .75s;animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{-webkit-animation:swal2-toast-animate-success-line-long .75s;animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{-webkit-animation:swal2-toast-show .5s;animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{-webkit-animation:swal2-toast-hide .1s forwards;animation:swal2-toast-hide .1s forwards}.swal2-container{display:grid;position:fixed;z-index:1060;top:0;right:0;bottom:0;left: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(-webkit-min-content,auto) minmax(-webkit-min-content,auto) minmax(-webkit-min-content,auto);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}.swal2-container.swal2-backdrop-show,.swal2-container.swal2-noanimation{background:rgba(0,0,0,.4)}.swal2-container.swal2-backdrop-hide{background:0 0!important}.swal2-container.swal2-bottom-start,.swal2-container.swal2-center-start,.swal2-container.swal2-top-start{grid-template-columns:minmax(0,1fr) auto auto}.swal2-container.swal2-bottom,.swal2-container.swal2-center,.swal2-container.swal2-top{grid-template-columns:auto minmax(0,1fr) auto}.swal2-container.swal2-bottom-end,.swal2-container.swal2-center-end,.swal2-container.swal2-top-end{grid-template-columns:auto auto minmax(0,1fr)}.swal2-container.swal2-top-start>.swal2-popup{align-self:start}.swal2-container.swal2-top>.swal2-popup{grid-column:2;align-self:start;justify-self:center}.swal2-container.swal2-top-end>.swal2-popup,.swal2-container.swal2-top-right>.swal2-popup{grid-column:3;align-self:start;justify-self:end}.swal2-container.swal2-center-left>.swal2-popup,.swal2-container.swal2-center-start>.swal2-popup{grid-row:2;align-self:center}.swal2-container.swal2-center>.swal2-popup{grid-column:2;grid-row:2;align-self:center;justify-self:center}.swal2-container.swal2-center-end>.swal2-popup,.swal2-container.swal2-center-right>.swal2-popup{grid-column:3;grid-row:2;align-self:center;justify-self:end}.swal2-container.swal2-bottom-left>.swal2-popup,.swal2-container.swal2-bottom-start>.swal2-popup{grid-column:1;grid-row:3;align-self:end}.swal2-container.swal2-bottom>.swal2-popup{grid-column:2;grid-row:3;justify-self:center;align-self:end}.swal2-container.swal2-bottom-end>.swal2-popup,.swal2-container.swal2-bottom-right>.swal2-popup{grid-column:3;grid-row:3;align-self:end;justify-self:end}.swal2-container.swal2-grow-fullscreen>.swal2-popup,.swal2-container.swal2-grow-row>.swal2-popup{grid-column:1/4;width:100%}.swal2-container.swal2-grow-column>.swal2-popup,.swal2-container.swal2-grow-fullscreen>.swal2-popup{grid-row:1/4;align-self:stretch}.swal2-container.swal2-no-transition{transition:none!important}.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}.swal2-popup:focus{outline:0}.swal2-popup.swal2-loading{overflow-y:hidden}.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}.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}.swal2-actions:not(.swal2-loading) .swal2-styled[disabled]{opacity:.4}.swal2-actions:not(.swal2-loading) .swal2-styled:hover{background-image:linear-gradient(rgba(0,0,0,.1),rgba(0,0,0,.1))}.swal2-actions:not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0,0,0,.2),rgba(0,0,0,.2))}.swal2-loader{display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;-webkit-animation:swal2-rotate-loading 1.5s linear 0s infinite normal;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 transparent #2778c4 transparent}.swal2-styled{margin:.3125em;padding:.625em 1.1em;transition:box-shadow .1s;box-shadow:0 0 0 3px transparent;font-weight:500}.swal2-styled:not([disabled]){cursor:pointer}.swal2-styled.swal2-confirm{border:0;border-radius:.25em;background:initial;background-color:#7066e0;color:#fff;font-size:1em}.swal2-styled.swal2-confirm:focus{box-shadow:0 0 0 3px rgba(112,102,224,.5)}.swal2-styled.swal2-deny{border:0;border-radius:.25em;background:initial;background-color:#dc3741;color:#fff;font-size:1em}.swal2-styled.swal2-deny:focus{box-shadow:0 0 0 3px rgba(220,55,65,.5)}.swal2-styled.swal2-cancel{border:0;border-radius:.25em;background:initial;background-color:#6e7881;color:#fff;font-size:1em}.swal2-styled.swal2-cancel:focus{box-shadow:0 0 0 3px rgba(110,120,129,.5)}.swal2-styled.swal2-default-outline:focus{box-shadow:0 0 0 3px rgba(100,150,200,.5)}.swal2-styled:focus{outline:0}.swal2-styled::-moz-focus-inner{border:0}.swal2-footer{justify-content:center;margin:1em 0 0;padding:1em 1em 0;border-top:1px solid #eee;color:inherit;font-size:1em}.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}.swal2-timer-progress-bar{width:100%;height:.25em;background:rgba(0,0,0,.2)}.swal2-image{max-width:100%;margin:2em auto 1em}.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:0 0;color:#ccc;font-family:serif;font-family:monospace;font-size:2.5em;cursor:pointer;justify-self:end}.swal2-close:hover{transform:none;background:0 0;color:#f27474}.swal2-close:focus{outline:0;box-shadow:inset 0 0 0 3px rgba(100,150,200,.5)}.swal2-close::-moz-focus-inner{border:0}.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:400;line-height:normal;text-align:center;word-wrap:break-word;word-break:break-word}.swal2-checkbox,.swal2-file,.swal2-input,.swal2-radio,.swal2-select,.swal2-textarea{margin:1em 2em 3px}.swal2-file,.swal2-input,.swal2-textarea{box-sizing:border-box;width:auto;transition:border-color .1s,box-shadow .1s;border:1px solid #d9d9d9;border-radius:.1875em;background:inherit;box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px transparent;color:inherit;font-size:1.125em}.swal2-file.swal2-inputerror,.swal2-input.swal2-inputerror,.swal2-textarea.swal2-inputerror{border-color:#f27474!important;box-shadow:0 0 2px #f27474!important}.swal2-file:focus,.swal2-input:focus,.swal2-textarea:focus{border:1px solid #b4dbed;outline:0;box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(100,150,200,.5)}.swal2-file::-moz-placeholder,.swal2-input::-moz-placeholder,.swal2-textarea::-moz-placeholder{color:#ccc}.swal2-file:-ms-input-placeholder,.swal2-input:-ms-input-placeholder,.swal2-textarea:-ms-input-placeholder{color:#ccc}.swal2-file::placeholder,.swal2-input::placeholder,.swal2-textarea::placeholder{color:#ccc}.swal2-range{margin:1em 2em 3px;background:#fff}.swal2-range input{width:80%}.swal2-range output{width:20%;color:inherit;font-weight:600;text-align:center}.swal2-range input,.swal2-range output{height:2.625em;padding:0;font-size:1.125em;line-height:2.625em}.swal2-input{height:2.625em;padding:0 .75em}.swal2-file{width:75%;margin-right:auto;margin-left:auto;background:inherit;font-size:1.125em}.swal2-textarea{height:6.75em;padding:.75em}.swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:inherit;color:inherit;font-size:1.125em}.swal2-checkbox,.swal2-radio{align-items:center;justify-content:center;background:#fff;color:inherit}.swal2-checkbox label,.swal2-radio label{margin:0 .6em;font-size:1.125em}.swal2-checkbox input,.swal2-radio input{flex-shrink:0;margin:0 .4em}.swal2-input-label{display:flex;justify-content:center;margin:1em auto 0}.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}.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}.swal2-icon{position:relative;box-sizing:content-box;justify-content:center;width:5em;height:5em;margin:2.5em auto .6em;border:.25em solid transparent;border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:3.75em}.swal2-icon.swal2-error{border-color:#f27474;color:#f27474}.swal2-icon.swal2-error .swal2-x-mark{position:relative;flex-grow:1}.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}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:1.0625em;transform:rotate(45deg)}.swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:1em;transform:rotate(-45deg)}.swal2-icon.swal2-error.swal2-icon-show{-webkit-animation:swal2-animate-error-icon .5s;animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-error.swal2-icon-show .swal2-x-mark{-webkit-animation:swal2-animate-error-x-mark .5s;animation:swal2-animate-error-x-mark .5s}.swal2-icon.swal2-warning{border-color:#facea8;color:#f8bb86}.swal2-icon.swal2-warning.swal2-icon-show{-webkit-animation:swal2-animate-error-icon .5s;animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-warning.swal2-icon-show .swal2-icon-content{-webkit-animation:swal2-animate-i-mark .5s;animation:swal2-animate-i-mark .5s}.swal2-icon.swal2-info{border-color:#9de0f6;color:#3fc3ee}.swal2-icon.swal2-info.swal2-icon-show{-webkit-animation:swal2-animate-error-icon .5s;animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-info.swal2-icon-show .swal2-icon-content{-webkit-animation:swal2-animate-i-mark .8s;animation:swal2-animate-i-mark .8s}.swal2-icon.swal2-question{border-color:#c9dae1;color:#87adbd}.swal2-icon.swal2-question.swal2-icon-show{-webkit-animation:swal2-animate-error-icon .5s;animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-question.swal2-icon-show .swal2-icon-content{-webkit-animation:swal2-animate-question-mark .8s;animation:swal2-animate-question-mark .8s}.swal2-icon.swal2-success{border-color:#a5dc86;color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-circular-line]{position:absolute;width:3.75em;height:7.5em;transform:rotate(45deg);border-radius:50%}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=left]{top:-.4375em;left:-2.0635em;transform:rotate(-45deg);transform-origin:3.75em 3.75em;border-radius:7.5em 0 0 7.5em}.swal2-icon.swal2-success [class^=swal2-success-circular-line][class$=right]{top:-.6875em;left:1.875em;transform:rotate(-45deg);transform-origin:0 3.75em;border-radius:0 7.5em 7.5em 0}.swal2-icon.swal2-success .swal2-success-ring{position:absolute;z-index:2;top:-.25em;left:-.25em;box-sizing:content-box;width:100%;height:100%;border:.25em solid rgba(165,220,134,.3);border-radius:50%}.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)}.swal2-icon.swal2-success [class^=swal2-success-line]{display:block;position:absolute;z-index:2;height:.3125em;border-radius:.125em;background-color:#a5dc86}.swal2-icon.swal2-success [class^=swal2-success-line][class$=tip]{top:2.875em;left:.8125em;width:1.5625em;transform:rotate(45deg)}.swal2-icon.swal2-success [class^=swal2-success-line][class$=long]{top:2.375em;right:.5em;width:2.9375em;transform:rotate(-45deg)}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-tip{-webkit-animation:swal2-animate-success-line-tip .75s;animation:swal2-animate-success-line-tip .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-long{-webkit-animation:swal2-animate-success-line-long .75s;animation:swal2-animate-success-line-long .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-circular-line-right{-webkit-animation:swal2-rotate-success-circular-line 4.25s ease-in;animation:swal2-rotate-success-circular-line 4.25s ease-in}.swal2-progress-steps{flex-wrap:wrap;align-items:center;max-width:100%;margin:1.25em auto;padding:0;background:inherit;font-weight:600}.swal2-progress-steps li{display:inline-block;position:relative}.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}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step{background:#2778c4}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step{background:#add8e6;color:#fff}.swal2-progress-steps .swal2-progress-step.swal2-active-progress-step~.swal2-progress-step-line{background:#add8e6}.swal2-progress-steps .swal2-progress-step-line{z-index:10;flex-shrink:0;width:2.5em;height:.4em;margin:0 -1px;background:#2778c4}[class^=swal2]{-webkit-tap-highlight-color:transparent}.swal2-show{-webkit-animation:swal2-show .3s;animation:swal2-show .3s}.swal2-hide{-webkit-animation:swal2-hide .15s forwards;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}@-webkit-keyframes swal2-toast-show{0%{transform:translateY(-.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0)}}@keyframes swal2-toast-show{0%{transform:translateY(-.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0)}}@-webkit-keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@-webkit-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:-.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-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@-webkit-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-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}}@-webkit-keyframes swal2-show{0%{transform:scale(.7)}45%{transform:scale(1.05)}80%{transform:scale(.95)}100%{transform:scale(1)}}@keyframes swal2-show{0%{transform:scale(.7)}45%{transform:scale(1.05)}80%{transform:scale(.95)}100%{transform:scale(1)}}@-webkit-keyframes swal2-hide{0%{transform:scale(1);opacity:1}100%{transform:scale(.5);opacity:0}}@keyframes swal2-hide{0%{transform:scale(1);opacity:1}100%{transform:scale(.5);opacity:0}}@-webkit-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:-.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-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@-webkit-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-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}}@-webkit-keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@-webkit-keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(.4);opacity:0}50%{margin-top:1.625em;transform:scale(.4);opacity:0}80%{margin-top:-.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(.4);opacity:0}50%{margin-top:1.625em;transform:scale(.4);opacity:0}80%{margin-top:-.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@-webkit-keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0);opacity:1}}@keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0);opacity:1}}@-webkit-keyframes swal2-rotate-loading{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}@keyframes swal2-rotate-loading{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}@-webkit-keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@-webkit-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}}@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:transparent!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:transparent;pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{top:0;right:auto;bottom:auto;left:50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-top-end,body.swal2-toast-shown .swal2-container.swal2-top-right{top:0;right:0;bottom:auto;left:auto}body.swal2-toast-shown .swal2-container.swal2-top-left,body.swal2-toast-shown .swal2-container.swal2-top-start{top:0;right:auto;bottom:auto;left:0}body.swal2-toast-shown .swal2-container.swal2-center-left,body.swal2-toast-shown .swal2-container.swal2-center-start{top:50%;right:auto;bottom:auto;left:0;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-center{top:50%;right:auto;bottom:auto;left:50%;transform:translate(-50%,-50%)}body.swal2-toast-shown .swal2-container.swal2-center-end,body.swal2-toast-shown .swal2-container.swal2-center-right{top:50%;right:0;bottom:auto;left:auto;transform:translateY(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-left,body.swal2-toast-shown .swal2-container.swal2-bottom-start{top:auto;right:auto;bottom:0;left:0}body.swal2-toast-shown .swal2-container.swal2-bottom{top:auto;right:auto;bottom:0;left:50%;transform:translateX(-50%)}body.swal2-toast-shown .swal2-container.swal2-bottom-end,body.swal2-toast-shown .swal2-container.swal2-bottom-right{top:auto;right:0;bottom:0;left:auto}");
  4685.  
  4686. /***/ }),
  4687. /* 6 */
  4688. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4689.  
  4690. "use strict";
  4691.  
  4692. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4693. exports.NanyangPT = void 0;
  4694. const NexusPHP_1 = __webpack_require__(2);
  4695. class NanyangPT extends NexusPHP_1.NexusPHP {
  4696. constructor() {
  4697. super("nanyangpt.com");
  4698. this.menu_items = [
  4699. {
  4700. "id": "bannerHide",
  4701. "type": "switch",
  4702. "display": "隐藏横幅",
  4703. "name": "隐藏横幅",
  4704. "value": false
  4705. }
  4706. ].concat(this.menu_items);
  4707. }
  4708. onLoad() {
  4709. super.onLoad();
  4710. }
  4711. tweakBanner() {
  4712. if (this.getHostValue("bannerHide")) {
  4713. const info = document.querySelector("#info_block");
  4714. const info_height = (info === null || info === void 0 ? void 0 : info.clientHeight) ? info.clientHeight + 5 : 30;
  4715. this.css += `
  4716. table.head {
  4717. display: none;
  4718. }
  4719.  
  4720. table.mainouter {
  4721. margin-top: ${info_height}px;
  4722. }`;
  4723. }
  4724. }
  4725. }
  4726. exports.NanyangPT = NanyangPT;
  4727.  
  4728.  
  4729. /***/ }),
  4730. /* 7 */
  4731. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4732.  
  4733. "use strict";
  4734.  
  4735. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4736. exports.SJTU = void 0;
  4737. const index_1 = __webpack_require__(2);
  4738. class SJTU extends index_1.NexusPHP {
  4739. constructor() {
  4740. super("pt.sjtu.edu.cn");
  4741. this.menu_items = [
  4742. {
  4743. "id": "bannerHide",
  4744. "type": "switch",
  4745. "display": "隐藏横幅",
  4746. "name": "隐藏横幅",
  4747. "value": false
  4748. }
  4749. ].concat(this.menu_items);
  4750. }
  4751. tweakBanner() {
  4752. if (this.getHostValue("bannerHide")) {
  4753. const info = document.querySelector("#userbar");
  4754. const info_height = (info === null || info === void 0 ? void 0 : info.clientHeight) ? info.clientHeight + 5 : 30;
  4755. this.css += `
  4756. table.head {
  4757. display: none;
  4758. }
  4759.  
  4760. table.mainouter {
  4761. margin-top: ${info_height}px;
  4762. }`;
  4763. }
  4764. }
  4765. }
  4766. exports.SJTU = SJTU;
  4767.  
  4768.  
  4769. /***/ }),
  4770. /* 8 */
  4771. /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
  4772.  
  4773. "use strict";
  4774.  
  4775. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4776. exports.TJUPT = void 0;
  4777. const index_1 = __webpack_require__(2);
  4778. class TJUPT extends index_1.NexusPHP {
  4779. constructor() {
  4780. super("tjupt.org");
  4781. this.menu_items = [
  4782. {
  4783. "id": "bannerFold",
  4784. "type": "switch",
  4785. "display": "自动折叠横幅(隐藏时折叠设置无效)",
  4786. "name": "自动折叠横幅",
  4787. "value": true
  4788. },
  4789. {
  4790. "id": "bannerHide",
  4791. "type": "switch",
  4792. "display": "隐藏横幅(隐藏时折叠设置无效)",
  4793. "name": "隐藏横幅",
  4794. "value": false
  4795. },
  4796. {
  4797. "id": "stickyHide",
  4798. "type": "selection",
  4799. "display": [
  4800. "显示所有置顶",
  4801. "隐藏一重置顶",
  4802. "隐藏一、二重置顶",
  4803. "隐藏所有置顶"
  4804. ],
  4805. "value": 0
  4806. },
  4807. {
  4808. "id": "colorBlind",
  4809. "type": "switch",
  4810. "display": "色盲模式",
  4811. "name": "色盲模式",
  4812. "value": false
  4813. }
  4814. ].concat(this.menu_items);
  4815. }
  4816. onLoad() {
  4817. super.onLoad();
  4818. switch (this.getHostValue("stickyHide")) {
  4819. case 3:
  4820. this.css += `
  4821. .triple_sticky_bg {
  4822. display: none;
  4823. }`;
  4824. case 2:
  4825. this.css += `
  4826. .double_sticky_bg {
  4827. display: none;
  4828. }`;
  4829. case 1:
  4830. this.css += `
  4831. .sticky_bg {
  4832. display: none;
  4833. }`;
  4834. default:
  4835. break;
  4836. }
  4837. if (this.getHostValue("colorBlind")) {
  4838. if (location.href.indexOf("/classes.php") >= 0) {
  4839. const spans = document.querySelectorAll("table.main > tbody > tr > td:nth-of-type(2) > ul > li > span[style=\"color: green\"]");
  4840. for (const span of spans) {
  4841. span.setAttribute("style", "color: blue");
  4842. }
  4843. }
  4844. }
  4845. }
  4846. getPasskey() {
  4847. const value = this.getHostValue("passkey");
  4848. let passkey = "";
  4849. if (value) {
  4850. passkey = String(value);
  4851. }
  4852. if (passkey != "") {
  4853. this.passkey = passkey;
  4854. return;
  4855. }
  4856. const link = document.querySelector("[title=\"Latest Torrents\"]");
  4857. const re = /passkey=([\d\w]+)/;
  4858. const result = re.exec(link.href);
  4859. this.passkey = result && result.length > 1 ? result[1] : "";
  4860. if (this.passkey != "") {
  4861. this.setHostValue("passkey", this.passkey);
  4862. }
  4863. }
  4864. tweakBanner() {
  4865. if (this.getHostValue("bannerHide")) {
  4866. this.css += `
  4867. .logo_img img {
  4868. display: none;
  4869. }`;
  4870. }
  4871. else if (this.getHostValue("bannerFold")) {
  4872. const logo_img = document.querySelector(".logo_img");
  4873. const original_height = logo_img === null || logo_img === void 0 ? void 0 : logo_img.clientHeight;
  4874. this.css += `
  4875. .logo_img {
  4876. height: 10px;
  4877. overflow: hidden;
  4878. transition: height 0.5s;
  4879. }
  4880.  
  4881. .logo_img:hover {
  4882. height: ${original_height}px;
  4883. }`;
  4884. }
  4885. }
  4886. }
  4887. exports.TJUPT = TJUPT;
  4888.  
  4889.  
  4890. /***/ })
  4891. /******/ ]);
  4892. /************************************************************************/
  4893. /******/ // The module cache
  4894. /******/ var __webpack_module_cache__ = {};
  4895. /******/
  4896. /******/ // The require function
  4897. /******/ function __webpack_require__(moduleId) {
  4898. /******/ // Check if module is in cache
  4899. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  4900. /******/ if (cachedModule !== undefined) {
  4901. /******/ return cachedModule.exports;
  4902. /******/ }
  4903. /******/ // Create a new module (and put it into the cache)
  4904. /******/ var module = __webpack_module_cache__[moduleId] = {
  4905. /******/ // no module.id needed
  4906. /******/ // no module.loaded needed
  4907. /******/ exports: {}
  4908. /******/ };
  4909. /******/
  4910. /******/ // Execute the module function
  4911. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  4912. /******/
  4913. /******/ // Return the exports of the module
  4914. /******/ return module.exports;
  4915. /******/ }
  4916. /******/
  4917. /************************************************************************/
  4918. var __webpack_exports__ = {};
  4919. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  4920. (() => {
  4921. "use strict";
  4922. var exports = __webpack_exports__;
  4923.  
  4924. Object.defineProperty(exports, "__esModule", ({ value: true }));
  4925. const hhanclub_top_1 = __webpack_require__(1);
  4926. const nanyangpt_com_1 = __webpack_require__(6);
  4927. const pt_sjtu_edu_cn_1 = __webpack_require__(7);
  4928. const index_1 = __webpack_require__(8);
  4929. const host = window.location.host;
  4930. const sites = new Map([
  4931. ["hhanclub.top", new hhanclub_top_1.Hhanclub()],
  4932. ["nanyangpt.com", new nanyangpt_com_1.NanyangPT()],
  4933. ["pt.sjtu.edu.cn", new pt_sjtu_edu_cn_1.SJTU()],
  4934. ["tjupt.org", new index_1.TJUPT()]
  4935. ]);
  4936. const site = sites.get(host);
  4937. if (site) {
  4938. site.init();
  4939. site.onLoad();
  4940. site.addStyle();
  4941. }
  4942.  
  4943. })();
  4944.  
  4945. /******/ })()
  4946. ;