"use strict";var d=Object.defineProperty;var f=(r,e,t)=>e in r?d(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var c=(r,e,t)=>(f(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("fourdom");function u(r,e,t){return rt?t:r}function v(r,e){return(e?(1-r)*100:(-1+r)*100).toFixed(4)}const k=()=>{const r=[];function e(){const t=r.shift();t&&t(e)}return function(t){r.push(t),r.length==1&&e()}},P=k();var a=(r=>(r.wrapperSelectorId="trickling",r.customParentClassName="trickling-custom-parent",r.busyFlagClassName="trickling-busy",r.template=`
`,r.barSelector='[role="bar"]',r.spinnerSelector='[role="spinner"]',r.rtlClassName="rtl",r))(a||{}),h=(r=>(r.queryBarElementError="[Trickling]: Can not find 'barSelector' element!",r.queryAppendToElementError="[Trickling]: Can not find 'options.appendTo' element!",r))(h||{});const l=class l{constructor(e){c(this,"progressOffsetWidth",0);c(this,"status",null);c(this,"positionUsing","");c(this,"options",{speed:200,easing:"ease",appendTo:"body",customWrapperClassName:"",minimum:.08,maximum:.994,showSpinner:!0,trickleSpeed:1e3,trickle:!0,color:"#2299dd",progressBarHeight:"2px",spinnerOpacity:1,spinnerSize:"18px",spinnerStrokeWidth:"2px",zIndex:1031,rtl:!1,removeFromDOMWhenDone:!0,trickleIncrementalCurve:[{from:0,to:.2,value:.1},{from:.2,to:.5,value:.04},{from:.5,to:.8,value:.02},{from:.8,to:.99,value:.005}]});this.options=Object.assign(this.options,e),this.setPercent(null)}setOptions(e){return this.options=Object.assign(this.options,e),this}setCSSVars(e){i.css(e,{"--trickling-color":this.options.color,"--trickling-progress-bar-height":this.options.progressBarHeight,"--trickling-spinner-opacity":this.options.spinnerOpacity,"--trickling-spinner-size":this.options.spinnerSize,"--trickling-spinner-stroke-width":this.options.spinnerStrokeWidth,"--trickling-progress-bar-z-index":this.options.zIndex})}render(e){if(this.isRendered())return this.getWrapperElement();i.addClass(document.documentElement,a.busyFlagClassName);const t=document.createElement("div");t.id=a.wrapperSelectorId,t.innerHTML=a.template,this.options.rtl&&i.addClass(t,a.rtlClassName),this.options.customWrapperClassName&&i.addClass(t,this.options.customWrapperClassName),this.setCSSVars(t);const s=this.getBarElement(t),n=this.getAppendToElement();if(this.translateProgressBar(s,e),!this.options.showSpinner){const o=t.querySelector(a.spinnerSelector);o&&i.removeElement(o)}return n!=document.body&&i.addClass(n,a.customParentClassName),n&&n.appendChild(t),t}triggerRepaint(){const e=this.getWrapperElement();e&&(this.progressOffsetWidth=e.offsetWidth)}set(e){const t=this.isStarted();!t&&this.visible(),e=u(e,this.options.minimum,1),this.setPercent(e===1?null:e);const s=this.render(!t),n=this.getBarElement(s),o=this.options.speed,g=this.options.easing;return this.triggerRepaint(),P(m=>{this.positionUsing===""&&(this.positionUsing=this.getPositioningCSS()),i.css(n,this.barPositionCSS(e,o,g)),e===1?(i.css(s,{transition:"none",opacity:1}),this.triggerRepaint(),setTimeout(()=>{i.css(s,{transition:`all ${o}ms linear`,opacity:0}),setTimeout(()=>{this.remove(),m()},o)},o)):setTimeout(m,o)}),this}inc(e){let t=this.getPercent();if(t){if(t>1)return this;if(typeof e!="number"){const s=typeof this.options.trickleIncrementalCurve=="function"?this.options.trickleIncrementalCurve(t):this.options.trickleIncrementalCurve;if(typeof s=="number")e=s||0;else{const n=s.find(o=>t!==null&&t>=o.from&&t{setTimeout(()=>{this.getPercent()&&(this.trickle(),e())},this.options.trickleSpeed)};return this.options.trickle&&e(),this}done(e){return!e&&!this.getPercent()?this:this.inc(.3+.5*Math.random()).set(1)}translateProgressBar(e,t){const s=t?this.getBarPercentage(0):this.getBarPercentage(this.getPercent()||0);i.css(e,{transition:"all 0 linear",transform:`translate3d(${s}%, 0, 0)`})}visible(){if(this.isRendered()&&!this.options.removeFromDOMWhenDone){const e=this.getWrapperElement();e&&i.css(e,{display:"block",opacity:1}),this.setPercent(null)}}hidden(){const e=this.getWrapperElement();e&&(i.css(e,{display:"none"}),this.setPercent(null),this.translateProgressBar(this.getBarElement(e),!0))}remove(e){if(i.removeClass(document.documentElement,a.busyFlagClassName),!this.options.removeFromDOMWhenDone&&!e){this.hidden();return}const t=this.getAppendToElement();i.removeClass(t,a.customParentClassName);const s=this.getWrapperElement();s&&i.removeElement(s)}getWrapperElement(){return document.getElementById(a.wrapperSelectorId)}getBarElement(e){const t=e.querySelector(a.barSelector);if(!t)throw new Error(h.queryBarElementError);return t}getAppendToElement(){const e=typeof this.options.appendTo=="string"?document.querySelector(this.options.appendTo):this.options.appendTo;if(!e)throw new Error(h.queryAppendToElementError);return e}setPercent(e){this.status=e}getPercent(){return this.status}isRendered(){return!!this.getWrapperElement()}isStarted(){return typeof this.getPercent()=="number"}getBarPercentage(e){return v(e,this.options.rtl)}barPositionCSS(e,t,s){let n={};return this.positionUsing==="translate3d"?n={transform:`translate3d(${this.getBarPercentage(e)}%,0,0)`}:this.positionUsing==="translate"?n={transform:`translate(${this.getBarPercentage(e)}%,0)`}:n={"margin-left":`${this.getBarPercentage(e)}%`},n.transition=`all ${t}ms ${s} 0s`,n}getPositioningCSS(){const e=document.body.style,t="WebkitTransform"in e?"Webkit":"MozTransform"in e?"Moz":"msTransform"in e?"ms":"OTransform"in e?"O":"";return t+"Perspective"in e?"translate3d":t+"Transform"in e?"translate":"margin"}static createProgress(e){return l.instance||(l.instance=new l(e)),l.instance}};c(l,"instance");let p=l;const y=function(r){return p.createProgress(r)};exports.Trickling=p;exports.createTrickling=y;