UNPKG

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.87 kB
this.primereact=this.primereact||{},this.primereact.knob=function(e,t,n,r){"use strict";function a(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 o=a(t);function i(){return i=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},i.apply(this,arguments)}function c(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,c=[],l=!0,u=!1;try{if(o=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=o.call(n)).done)&&(c.push(r.value),c.length!==t);l=!0);}catch(e){u=!0,a=e}finally{try{if(!l&&null!=n.return&&(i=n.return(),Object(i)!==i))return}finally{if(u)throw a}}return c}}function u(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,t){if(e){if("string"==typeof e)return u(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)?u(e,t):void 0}}function f(){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 h(e,t){return c(e)||l(e,t)||s(e,t)||f()}var p={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 r.ObjectUtils.getMergedProps(e,p.defaultProps)},getOtherProps:function(e){return r.ObjectUtils.getDiffProps(e,p.defaultProps)}},d=40,m=4*Math.PI/3,v=-Math.PI/3,b=o.memo(o.forwardRef((function(e,t){var a=p.getProps(e),c=o.useRef(null),l=!a.disabled&&!a.readOnly,u=h(n.useEventListener({target:"window",type:"mousemove",listener:function(e){N(e.offsetX,e.offsetY),e.preventDefault()},when:l}),2),s=u[0],f=u[1],b=h(n.useEventListener({target:"window",type:"mouseup",listener:function(e){f(),g(),e.preventDefault()},when:l}),2),y=b[0],g=b[1],M=h(n.useEventListener({target:"window",type:"touchmove",listener:function(e){if(1===e.touches.length){var t=c.current.getBoundingClientRect(),n=e.targetTouches.item(0);N(n.clientX-t.left,n.clientY-t.top),e.preventDefault()}},when:l}),2),w=M[0],O=M[1],P=h(n.useEventListener({target:"window",type:"touchend",listener:function(){O(),j()},when:l}),2),k=P[0],j=P[1],E=function(e,t,n,r,a){return(e-t)*(a-r)/(n-t)+r},x=function(){return E(a.min>0&&a.max>0?a.min:0,a.min,a.max,m,v)},C=function(){return E(a.value,a.min,a.max,m,v)},I="M ".concat(50+Math.cos(m)*d," ").concat(50-Math.sin(m)*d," A ").concat(d," ").concat(d," 0 1 1 ").concat(50+Math.cos(v)*d," ").concat(50-Math.sin(v)*d),A="M ".concat(50+Math.cos(x())*d," ").concat(50-Math.sin(x())*d," A ").concat(d," ").concat(d," 0 ").concat(Math.abs(x()-C())<Math.PI?0:1," ").concat(C()>x()?0:1," ").concat(50+Math.cos(C())*d," ").concat(50-Math.sin(C())*d),N=function(e,t){var n=Math.atan2(a.size/2-t,e-a.size/2),r=-Math.PI/2-Math.PI/6;D(n,r)},D=function(e,t){var n;if(e>v)n=E(e,m,v,a.min,a.max);else{if(!(e<t))return;n=E(e+2*Math.PI,m,v,a.min,a.max)}a.onChange&&a.onChange({value:Math.round((n-a.min)/a.step)*a.step+a.min})};o.useImperativeHandle(t,(function(){return{props:a,getElement:function(){return c.current}}}));var S=p.getOtherProps(a),T=r.classNames("p-knob p-component",{"p-disabled":a.disabled},a.className),z=a.showValue&&o.createElement("text",{x:50,y:57,textAnchor:"middle",fill:a.textColor,className:"p-knob-text",name:a.name},a.valueTemplate.replace("{value}",a.value.toString()));return o.createElement("div",i({ref:c,id:a.id,className:T,style:a.style},S),o.createElement("svg",{viewBox:"0 0 100 100",width:a.size,height:a.size,onClick:function(e){a.disabled||a.readOnly||N(e.nativeEvent.offsetX,e.nativeEvent.offsetY)},onMouseDown:function(e){s(),y(),e.preventDefault()},onMouseUp:function(){f(),g()},onTouchStart:function(){w(),k()},onTouchEnd:function(){O(),j()}},o.createElement("path",{d:I,strokeWidth:a.strokeWidth,stroke:a.rangeColor,className:"p-knob-range"}),o.createElement("path",{d:A,strokeWidth:a.strokeWidth,stroke:a.valueColor,className:"p-knob-value"}),z))})));return b.displayName="Knob",e.Knob=b,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.hooks,primereact.utils);