2 lines
7.8 KiB
JavaScript
2 lines
7.8 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 i=n(e);function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function r(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function u(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&&a(e,t)}function h(e){return h="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},h(e)}function l(e,t){if(t&&("object"===h(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return r(e)}function c(e){return c=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},c(e)}function p(){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 d,f,v,m=function(n){u(y,e.Component);var a,h,d,f,v,m=(a=y,h=p(),function(){var e,t=c(a);if(h){var n=c(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return l(this,e)});function y(e){var t;return o(this,y),(t=m.call(this,e)).state={},t.radius=40,t.midX=50,t.midY=50,t.minRadians=4*Math.PI/3,t.maxRadians=-Math.PI/3,t.onClick=t.onClick.bind(r(t)),t.onMouseDown=t.onMouseDown.bind(r(t)),t.onMouseUp=t.onMouseUp.bind(r(t)),t.onTouchStart=t.onTouchStart.bind(r(t)),t.onTouchEnd=t.onTouchEnd.bind(r(t)),t.onMouseMove=t.onMouseMove.bind(r(t)),t.onTouchMove=t.onTouchMove.bind(r(t)),t}return d=y,(f=[{key:"updateValue",value:function(e,t){var n=Math.atan2(this.props.size/2-t,e-this.props.size/2),i=-Math.PI/2-Math.PI/6;this.updateModel(n,i)}},{key:"updateModel",value:function(e,t){var n;if(e>this.maxRadians)n=this.mapRange(e,this.minRadians,this.maxRadians,this.props.min,this.props.max);else{if(!(e<t))return;n=this.mapRange(e+2*Math.PI,this.minRadians,this.maxRadians,this.props.min,this.props.max)}if(this.props.onChange){var i=Math.round((n-this.props.min)/this.props.step)*this.props.step+this.props.min;this.props.onChange({value:i})}}},{key:"mapRange",value:function(e,t,n,i,o){return(e-t)*(o-i)/(n-t)+i}},{key:"onClick",value:function(e){this.props.disabled||this.props.readOnly||this.updateValue(e.nativeEvent.offsetX,e.nativeEvent.offsetY)}},{key:"onMouseDown",value:function(e){this.props.disabled||this.props.readOnly||(this.windowMouseMoveListener=this.onMouseMove,this.windowMouseUpListener=this.onMouseUp,window.addEventListener("mousemove",this.windowMouseMoveListener),window.addEventListener("mouseup",this.windowMouseUpListener),e.preventDefault())}},{key:"onMouseUp",value:function(e){this.props.disabled||this.props.readOnly||(window.removeEventListener("mousemove",this.windowMouseMoveListener),window.removeEventListener("mouseup",this.windowMouseUpListener),this.windowMouseMoveListener=null,this.windowMouseUpListener=null,e.preventDefault())}},{key:"onTouchStart",value:function(e){this.props.disabled||this.props.readOnly||(this.windowTouchMoveListener=this.onTouchMove,this.windowTouchEndListener=this.onTouchEnd,window.addEventListener("touchmove",this.windowTouchMoveListener,{passive:!1,cancelable:!1}),window.addEventListener("touchend",this.windowTouchEndListener))}},{key:"o
|