import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-c948674f.js";var Slider=function(){function e(e){var t=this;registerInstance(this,e);this.onChange=createEvent(this,"change",7);this.onChanging=createEvent(this,"changing",7);this.handleTouchStart=function(e){if(t.touching||t.disabled)return;t.touching=true;t.touchId=e.targetTouches[0].identifier;t.totalWidth=t.sliderInsRef.clientWidth||1;t.ogX=e.targetTouches[0].pageX;t.ogPercent=t.percent};this.handleTouchMove=function(e){var i=t,a=i.disabled,n=i.touching,r=i.touchId,o=i.totalWidth,l=i.max,h=i.min,s=i.ogX,c=i.ogPercent;if(!n||a)return;if(e.targetTouches[0].identifier!==r)return;e.preventDefault();var u=e.targetTouches[0].pageX;var d=u-s;var f=d/o*100+c;f=t.handleValueUpdate(f,0,100);var v=h+f*.01*(l-h);t.updateByStep(v);t.onChanging.emit({detail:e.detail,value:t.value})};this.handleTouchEnd=function(e){var i=t,a=i.disabled,n=i.touching;if(!n||a)return;if(t.percent!==t.ogPercent){t.onChange.emit({detail:e.detail,value:t.value})}t.touching=false;t.touchId=null;t.ogX=0;t.ogPercent=0};this.handleValueUpdate=function(e,i,a){if(i===void 0){i=t.min}if(a===void 0){a=t.max}e=isNaN(e)?0:e;return Math.max(i,Math.min(e,a))};this.min=0;this.max=100;this.step=1;this.disabled=false;this.value=0;this.activeColor="#1aad19";this.backgroundColor="#e9e9e9";this.blockSize=28;this.blockColor="#ffffff";this.showValue=false;this.name="";this.totalWidth=1;this.touching=false;this.ogX=0;this.touchId=null;this.percent=0;this.ogPercent=undefined;this.isWillLoadCalled=false}e.prototype.function=function(e){if(!this.isWillLoadCalled)return;var t=this,i=t.max,a=t.min;if(e!==null){var n=this.handleValueUpdate(e,a,i);this.updateByStep(n)}};e.prototype.componentDidLoad=function(){this.handler.addEventListener("touchstart",this.handleTouchStart);this.handler.addEventListener("touchmove",this.handleTouchMove);this.handler.addEventListener("touchend",this.handleTouchEnd)};e.prototype.componentWillLoad=function(){this.isWillLoadCalled=true;var e=this,t=e.value,i=e.max,a=e.min;var n=this.handleValueUpdate(t,a,i);this.updateByStep(n)};e.prototype.updateByStep=function(e){var t=this,i=t.max,a=t.min,n=t.step;var r=Math.floor((i-a)/n);for(var o=0;o<=r;o++){var l=a+n*o;var h=o===r?null:a+n*(o+1);if(e===l)break;if(!h&&e>l){e=l}if(h&&e>l&&e<h){if(e-l<n/2){e=l}else{e=h}break}}var s=(e-a)/(i-a)*100;this.value=e;this.percent=s};e.prototype.render=function(){var e=this;var t=this,i=t.showValue,a=t.backgroundColor,n=t.activeColor,r=t.blockColor,o=t.name,l=t.percent,s=t.value;var c=this.blockSize;var u={backgroundColor:a};var d=l>100?100:l;var f={width:"".concat(d,"%"),backgroundColor:n};if(c<12){c=12}if(c>28){c=28}var v={left:"".concat(d,"%"),width:"".concat(c,"px"),height:"".concat(c,"px"),backgroundColor:r,marginTop:"-".concat(Math.floor(c/2),"px"),marginLeft:"-".concat(Math.floor(c/2),"px")};return h(Host,{class:"weui-slider-box"},h("div",{class:"weui-slider"},h("div",{class:"weui-slider__inner",style:u,ref:function(t){return e.sliderInsRef=t}},h("div",{style:f,class:"weui-slider__track"}),h("div",{class:"weui-slider__handler",ref:function(t){if(t)e.handler=t},style:v}),h("input",{type:"hidden",name:o,value:s}))),i&&h("div",{class:"weui-slider-box__value"},s))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(e,"watchers",{get:function(){return{value:["function"]}},enumerable:false,configurable:true});return e}();export{Slider as taro_slider_core};
//# sourceMappingURL=taro-slider-core.entry.js.map