primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 4.84 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/hooks"),n=require("primereact/utils");function r(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=r(e);function o(){return o=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},o.apply(this,arguments)}function i(e){if(Array.isArray(e))return e}function l(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var r,a,o,i,l=[],c=!0,u=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;c=!1}else for(;!(c=(r=o.call(n)).done)&&(l.push(r.value),l.length!==t);c=!0);}catch(e){u=!0,a=e}finally{try{if(!c&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw a}}return l}}function c(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 u(e,t){if(e){if("string"==typeof e)return c(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)?c(e,t):void 0}}function s(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(e,t){return i(e)||l(e,t)||u(e,t)||s()}var d={defaultProps:{__TYPE:"Knob",id:null,style:null,className:null,value:null,size:100,disabled:!1,readOnly:!1,showValue:!0,step:1,min:0,max:100,strokeWidth:14,name:null,valueColor:"var(--primary-color, Black)",rangeColor:"var(--surface-border, LightGray)",textColor:"var(--text-color-secondary, Black)",valueTemplate:"{value}",onChange:null,children:void 0},getProps:function(e){return n.ObjectUtils.getMergedProps(e,d.defaultProps)},getOtherProps:function(e){return n.ObjectUtils.getDiffProps(e,d.defaultProps)}},h=40,p=4*Math.PI/3,m=-Math.PI/3,v=a.memo(a.forwardRef((function(e,r){var i=d.getProps(e),l=a.useRef(null),c=!i.disabled&&!i.readOnly,u=f(t.useEventListener({target:"window",type:"mousemove",listener:function(e){N(e.offsetX,e.offsetY),e.preventDefault()},when:c}),2),s=u[0],v=u[1],y=f(t.useEventListener({target:"window",type:"mouseup",listener:function(e){v(),g(),e.preventDefault()},when:c}),2),b=y[0],g=y[1],M=f(t.useEventListener({target:"window",type:"touchmove",listener:function(e){if(1===e.touches.length){var t=l.current.getBoundingClientRect(),n=e.targetTouches.item(0);N(n.clientX-t.left,n.clientY-t.top),e.preventDefault()}},when:c}),2),w=M[0],O=M[1],P=f(t.useEventListener({target:"window",type:"touchend",listener:function(){O(),j()},when:c}),2),x=P[0],j=P[1],k=function(e,t,n,r,a){return(e-t)*(a-r)/(n-t)+r},E=function(){return k(i.min>0&&i.max>0?i.min:0,i.min,i.max,p,m)},C=function(){return k(i.value,i.min,i.max,p,m)},I="M ".concat(50+Math.cos(p)*h," ").concat(50-Math.sin(p)*h," A ").concat(h," ").concat(h," 0 1 1 ").concat(50+Math.cos(m)*h," ").concat(50-Math.sin(m)*h),A="M ".concat(50+Math.cos(E())*h," ").concat(50-Math.sin(E())*h," A ").concat(h," ").concat(h," 0 ").concat(Math.abs(E()-C())<Math.PI?0:1," ").concat(C()>E()?0:1," ").concat(50+Math.cos(C())*h," ").concat(50-Math.sin(C())*h),N=function(e,t){var n=Math.atan2(i.size/2-t,e-i.size/2),r=-Math.PI/2-Math.PI/6;D(n,r)},D=function(e,t){var n;if(e>m)n=k(e,p,m,i.min,i.max);else{if(!(e<t))return;n=k(e+2*Math.PI,p,m,i.min,i.max)}i.onChange&&i.onChange({value:Math.round((n-i.min)/i.step)*i.step+i.min})};a.useImperativeHandle(r,(function(){return{props:i,getElement:function(){return l.current}}}));var S=d.getOtherProps(i),T=n.classNames("p-knob p-component",{"p-disabled":i.disabled},i.className),z=i.showValue&&a.createElement("text",{x:50,y:57,textAnchor:"middle",fill:i.textColor,className:"p-knob-text",name:i.name},i.valueTemplate.replace("{value}",i.value.toString()));return a.createElement("div",o({ref:l,id:i.id,className:T,style:i.style},S),a.createElement("svg",{viewBox:"0 0 100 100",width:i.size,height:i.size,onClick:function(e){i.disabled||i.readOnly||N(e.nativeEvent.offsetX,e.nativeEvent.offsetY)},onMouseDown:function(e){s(),b(),e.preventDefault()},onMouseUp:function(){v(),g()},onTouchStart:function(){w(),x()},onTouchEnd:function(){O(),j()}},a.createElement("path",{d:I,strokeWidth:i.strokeWidth,stroke:i.rangeColor,className:"p-knob-range"}),a.createElement("path",{d:A,strokeWidth:i.strokeWidth,stroke:i.valueColor,className:"p-knob-value"}),z))})));v.displayName="Knob",exports.Knob=v;
;