PT 助手

私密种子站点的助手

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

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