katoikia-app/web-ui/web-react/node_modules/primereact/slider/slider.cjs.min.js

2 lines
9.1 KiB
JavaScript

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/utils");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=n(e);function i(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function s(e){if(Array.isArray(e))return i(e)}function o(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function a(e,t){if(e){if("string"==typeof e)return i(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?i(e,t):void 0}}function l(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function p(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function d(e,t){return d=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},d(e,t)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&d(e,t)}function f(e){return f="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},f(e)}function g(e,t){if(t&&("object"===f(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return p(e)}function m(e){return m=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},m(e)}function v(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var y,b,L,E=function(n){c(E,e.Component);var i,d,f,y,b,L=(i=E,d=v(),function(){var e,t=m(i);if(d){var n=m(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return g(this,e)});function E(e){var t;return u(this,E),(t=L.call(this,e)).onBarClick=t.onBarClick.bind(p(t)),t.onKeyDown=t.onKeyDown.bind(p(t)),t.handleIndex=0,t}return f=E,(y=[{key:"value",get:function(){return this.props.range?this.props.value||[0,100]:this.props.value||0}},{key:"spin",value:function(e,t){this.updateValue(e,(this.props.range?this.value[this.handleIndex]:this.value)+(this.props.step||1)*t),e.preventDefault()}},{key:"onDragStart",value:function(e,t){this.props.disabled||(this.dragging=!0,this.updateDomData(),this.sliderHandleClick=!0,this.handleIndex=t)}},{key:"onMouseDown",value:function(e,t){this.bindDragListeners(),this.onDragStart(e,t)}},{key:"onTouchStart",value:function(e,t){this.bindTouchListeners(),this.onDragStart(e,t)}},{key:"onKeyDown",value:function(e,t){if(!this.props.disabled){this.handleIndex=t;var n=e.key;"ArrowRight"===n||"ArrowUp"===n?this.spin(e,1):"ArrowLeft"!==n&&"ArrowDown"!==n||this.spin(e,-1)}}},{key:"onBarClick",value:function(e){if(!this.props.disabled){if(!this.sliderHandleClick){this.updateDomData();var t=this.setValue(e);this.props.onSlideEnd&&this.props.onSlideEnd({originalEvent:e,value:t})}this.sliderHandleClick=!1}}},{key:"onDrag",value:function(e){this.dragging&&(this.setValue(e),e.preventDefault())}},{key:"onDragEnd",value:function(e){this.dragging&&(this.dragging=!1,this.props.onSlideEnd&&this.props.onSlideEnd({originalEvent:e,value:this.props.value}),this.unbindDragListeners(),this.unbindTouchListeners())}},{key:"bindDragListeners",value:function(){this.dragListener||(this.dragListener=this.onDrag.bind(this),document.addEventListener("mousemove",this.dragListener)),this.dragEndListener||(this.dragEndListener=this.onDragEnd.bind(this),document.addEventListener("mouseup",this.dragEndListener))}},{key:"unbindDragListeners",value:function(){this.dragListener&&(document.removeEventListener("mousemove",this.dragListener),this.dragListener=null),this.dragEndListener&&(document.removeEventListener("mouseup",this.dragEndListener),this.dragEndListener=null)}},{key:"bindTouchListeners",value:function(){this.dragListener||(this.dragListener=this.onDrag.bind(this),document.addEventListener("touchmove",this.dragListener)),this.dragEndListener||(this.dragEndListener=this.onDragEnd.bind(this),document.addEventListener("touchend",this.dragEndListener))}},{key:"unbindTouchListeners",value:function(){this.dragListener&&(document.removeEventListener("touchmove",this.dragListener),this.dragListener=null),this.dragEndListener&&(document.removeEventListener("touchend",this.dragEndListener),this.dragEndListener=null)}},{key:"updateDomData",value:function(){var e=this.el.getBoundingClientRect();this.initX=e.left+t.DomHandler.getWindowScrollLeft(),this.initY=e.top+t.DomHandler.getWindowScrollTop(),this.barWidth=this.el.offsetWidth,this.barHeight=this.el.offsetHeight}},{key:"setValue",value:function(e){var t=("horizontal"===this.props.orientation?100*((e.touches?e.touches[0].pageX:e.pageX)-this.initX)/this.barWidth:100*(this.initY+this.barHeight-(e.touches?e.touches[0].pageY:e.pageY))/this.barHeight)/100*(this.props.max-this.props.min)+this.props.min;if(this.props.step){var n=this.props.range?this.value[this.handleIndex]:this.value,r=t-n;r<0?t=n+Math.ceil(t/this.props.step-n/this.props.step)*this.props.step:r>0&&(t=n+Math.floor(t/this.props.step-n/this.props.step)*this.props.step)}else t=Math.floor(t);return this.updateValue(e,t)}},{key:"updateValue",value:function(e,t){var n,r=parseFloat(t.toFixed(10)),i=r;return this.props.range?(0===this.handleIndex?r<this.props.min?r=this.props.min:r>this.value[1]&&(r=this.value[1]):r>this.props.max?r=this.props.max:r<this.value[0]&&(r=this.value[0]),(i=s(n=this.value)||o(n)||a(n)||l())[this.handleIndex]=r,this.props.onChange&&this.props.onChange({originalEvent:e,value:i})):(r<this.props.min?r=this.props.min:r>this.props.max&&(r=this.props.max),i=r,this.props.onChange&&this.props.onChange({originalEvent:e,value:i})),i}},{key:"componentWillUnmount",value:function(){this.unbindDragListeners(),this.unbindTouchListeners()}},{key:"renderHandle",value:function(e,n,i){var s=this,o=t.classNames("p-slider-handle",{"p-slider-handle-start":0===i,"p-slider-handle-end":1===i,"p-slider-handle-active":this.handleIndex===i});return r.default.createElement("span",{onMouseDown:function(e){return s.onMouseDown(e,i)},onTouchStart:function(e){return s.onTouchStart(e,i)},onKeyDown:function(e){return s.onKeyDown(e,i)},tabIndex:this.props.tabIndex,className:o,style:{transition:this.dragging?"none":null,left:null!==e&&e+"%",bottom:n&&n+"%"},role:"slider","aria-valuemin":this.props.min,"aria-valuemax":this.props.max,"aria-valuenow":e||n,"aria-labelledby":this.props.ariaLabelledBy})}},{key:"renderRangeSlider",value:function(){var e=this.value,t="horizontal"===this.props.orientation,n=100*(e[0]<this.props.min?0:e[0]-this.props.min)/(this.props.max-this.props.min),i=100*(e[1]>this.props.max?100:e[1]-this.props.min)/(this.props.max-this.props.min),s=t?this.renderHandle(n,null,0):this.renderHandle(null,n,0),o=t?this.renderHandle(i,null,1):this.renderHandle(null,i,1);return r.default.createElement(r.default.Fragment,null,r.default.createElement("span",{className:"p-slider-range",style:t?{left:n+"%",width:i-n+"%"}:{bottom:n+"%",height:i-n+"%"}}),s,o)}},{key:"renderSingleSlider",value:function(){var e,t=this.value;e=t<this.props.min?0:t>this.props.max?100:100*(t-this.props.min)/(this.props.max-this.props.min);var n="horizontal"===this.props.orientation?{width:e+"%"}:{height:e+"%"},i="horizontal"===this.props.orientation?this.renderHandle(e,null,null):this.renderHandle(null,e,null);return r.default.createElement(r.default.Fragment,null,r.default.createElement("span",{className:"p-slider-range",style:n}),i)}},{key:"render",value:function(){var e=this,n=t.classNames("p-slider p-component",this.props.className,{"p-disabled":this.props.disabled,"p-slider-horizontal":"horizontal"===this.props.orientation,"p-slider-vertical":"vertical"===this.props.orientation}),i=this.props.range?this.renderRangeSlider():this.renderSingleSlider();return r.default.createElement("div",{id:this.props.id,ref:function(t){return e.el=t},style:this.props.style,className:n,onClick:this.onBarClick},i)}}])&&h(f.prototype,y),b&&h(f,b),Object.defineProperty(f,"prototype",{writable:!1}),E}();L={id:null,value:null,min:0,max:100,orientation:"horizontal",step:null,range:!1,style:null,className:null,disabled:!1,tabIndex:0,ariaLabelledBy:null,onChange:null,onSlideEnd:null},(b="defaultProps")in(y=E)?Object.defineProperty(y,b,{value:L,enumerable:!0,configurable:!0,writable:!0}):y[b]=L,exports.Slider=E;