PT 助手

私密种子站点的助手

目前为 2023-03-03 提交的版本。查看 最新版本

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