{"version":3,"sources":["../../src/app/components/knob/knob.ts"],"names":["KNOB_VALUE_ACCESSOR","provide","NG_VALUE_ACCESSOR","useExisting","forwardRef","Knob","multi","cd","el","this","valueColor","rangeColor","textColor","valueTemplate","size","step","min","max","strokeWidth","showValue","readonly","onChange","EventEmitter","radius","midX","midY","minRadians","Math","PI","maxRadians","value","onModelChange","onModelTouched","prototype","mapRange","x","inMin","inMax","outMin","outMax","onClick","event","disabled","updateValue","offsetX","offsetY","dx","dy","angle","atan2","start","updateModel","mappedValue","newValue","round","emit","onMouseDown","windowMouseMoveListener","onMouseMove","bind","windowMouseUpListener","onMouseUp","window","addEventListener","preventDefault","removeEventListener","onTouchStart","windowTouchMoveListener","onTouchMove","windowTouchEndListener","onTouchEnd","touches","length","rect","nativeElement","children","getBoundingClientRect","touch","targetTouches","item","clientX","left","clientY","top","writeValue","markForCheck","registerOnChange","fn","registerOnTouched","setDisabledState","val","containerClass","p-knob p-component","p-disabled","rangePath","minX","minY","maxX","maxY","valuePath","zeroX","zeroY","largeArc","sweep","valueX","valueY","zeroRadians","valueRadians","_value","cos","sin","abs","valueToDisplay","replace","toString","Object","defineProperty","Component","args","selector","template","providers","changeDetection","ChangeDetectionStrategy","OnPush","encapsulation","ViewEncapsulation","None","ChangeDetectorRef","ElementRef","Input","Output","NgModule","imports","CommonModule","exports","declarations"],"mappings":"ycAIaA,EAA2B,CACpCC,QAASC,EAAAA,kBACTC,YAAaC,EAAAA,YAAW,WAAM,OAAAC,KAC9BC,OAAO,gBAgFP,SAAAD,EAAoBE,EAA+BC,GAA/BC,KAAAF,GAAAA,EAA+BE,KAAAD,GAAAA,EApD1CC,KAAAC,WAAqB,8BAErBD,KAAAE,WAAqB,8BAErBF,KAAAG,UAAoB,qCAEpBH,KAAAI,cAAwB,UAIxBJ,KAAAK,KAAe,IAEfL,KAAAM,KAAe,EAEfN,KAAAO,IAAc,EAEdP,KAAAQ,IAAc,IAEdR,KAAAS,YAAsB,GAItBT,KAAAU,WAAqB,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rG,EAAA4B,UAAA+E,eAAA,WACI,OAAOvG,KAAKI,cAAcoG,QAAQ,UAAWxG,KAAKmG,OAAOM,aAG7DC,OAAAC,eAAI/G,EAAA4B,UAAA,SAAM,KAAV,WACI,OAAqB,MAAdxB,KAAKqB,MAAgBrB,KAAKqB,MAAQrB,KAAKO,8DAlQrDqG,EAAAA,UAASC,KAAA,CAAC,CACPC,SAAU,SACVC,SAAU,k0BAUVC,UAAW,CAACzH,GACZ0H,gBAAiBC,EAAAA,wBAAwBC,OACzCC,cAAeC,EAAAA,kBAAkBC,iSAxBwDC,EAAAA,yBAAmBC,EAAAA,kDA6B3GC,EAAAA,qBAEAA,EAAAA,wBAEAA,EAAAA,0BAEAA,EAAAA,0BAEAA,EAAAA,yBAEAA,EAAAA,6BAEAA,EAAAA,oBAEAA,EAAAA,oBAEAA,EAAAA,oBAEAA,EAAAA,mBAEAA,EAAAA,mBAEAA,EAAAA,2BAEAA,EAAAA,wBAEAA,EAAAA,yBAEAA,EAAAA,wBAEAA,EAAAA,wBAEAC,EAAAA,gBAwNL,iCALCC,EAAAA,SAAQd,KAAA,CAAC,CACNe,QAAS,CAACC,EAAAA,cACVC,QAAS,CAAClI,GACVmI,aAAc,CAACnI","sourcesContent":["import { NgModule, Component, ChangeDetectionStrategy, ViewEncapsulation, Input, forwardRef, ChangeDetectorRef, ElementRef, Output, EventEmitter} from '@angular/core';\nimport { CommonModule } from '@angular/common';\nimport { NG_VALUE_ACCESSOR } from '@angular/forms';\n\nexport const KNOB_VALUE_ACCESSOR: any = {\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => Knob),\n multi: true\n};\n\n@Component({\n selector: 'p-knob',\n template: `\n
\n \n \n \n {{valueToDisplay()}}\n \n
\n `,\n providers: [KNOB_VALUE_ACCESSOR],\n changeDetection: ChangeDetectionStrategy.OnPush,\n encapsulation: ViewEncapsulation.None,\n styleUrls: ['./knob.css']\n})\nexport class Knob {\n\n @Input() styleClass: string;\n\n @Input() style: any;\n\n @Input() severity: string;\n\n @Input() valueColor: string = \"var(--primary-color, Black)\";\n\n @Input() rangeColor: string = \"var(--surface-d, LightGray)\";\n\n @Input() textColor: string = \"var(--text-color-secondary, Black)\";\n\n @Input() valueTemplate: string = \"{value}\";\n\n @Input() name: string;\n\n @Input() size: number = 100;\n\n @Input() step: number = 1;\n\n @Input() min: number = 0;\n\n @Input() max: number = 100;\n\n @Input() strokeWidth: number = 14;\n\n @Input() disabled: boolean;\n\n @Input() showValue: boolean = true;\n\n @Input() readonly: boolean = false;\n\n @Output() onChange: EventEmitter = new EventEmitter();\n\n radius: number = 40;\n\n midX: number = 50;\n\n midY: number = 50;\n\n minRadians: number = 4 * Math.PI / 3;\n\n maxRadians: number = -Math.PI / 3;\n \n value: number = null;\n\n windowMouseMoveListener: any;\n\n windowMouseUpListener: any;\n\n windowTouchMoveListener: any;\n\n windowTouchEndListener: any;\n\n onModelChange: Function = () => {};\n\n onModelTouched: Function = () => {};\n\n constructor(private cd: ChangeDetectorRef, private el: ElementRef) { }\n\n mapRange(x, inMin, inMax, outMin, outMax) {\n return (x - inMin) * (outMax - outMin) / (inMax - inMin) + outMin;\n }\n\n onClick(event) {\n if (!this.disabled && !this.readonly) {\n this.updateValue(event.offsetX, event.offsetY);\n }\n }\n\n updateValue(offsetX, offsetY) {\n let dx = offsetX - this.size / 2;\n let dy = this.size / 2 - offsetY;\n let angle = Math.atan2(dy, dx);\n let start = -Math.PI / 2 - Math.PI / 6;\n this.updateModel(angle, start);\n }\n\n updateModel(angle, start) {\n let mappedValue;\n if (angle > this.maxRadians)\n mappedValue = this.mapRange(angle, this.minRadians, this.maxRadians, this.min, this.max);\n else if (angle < start)\n mappedValue = this.mapRange(angle + 2 * Math.PI, this.minRadians, this.maxRadians, this.min, this.max);\n else\n return;\n\n let newValue = Math.round((mappedValue - this.min) / this.step) * this.step + this.min;\n this.value = newValue;\n this.onModelChange(this.value);\n this.onChange.emit(this.value);\n }\n\n onMouseDown(event) {\n if (!this.disabled && !this.readonly) {\n this.windowMouseMoveListener = this.onMouseMove.bind(this)\n this.windowMouseUpListener = this.onMouseUp.bind(this)\n window.addEventListener('mousemove', this.windowMouseMoveListener);\n window.addEventListener('mouseup', this.windowMouseUpListener);\n event.preventDefault();\n }\n }\n\n onMouseUp(event) {\n if (!this.disabled && !this.readonly) {\n window.removeEventListener('mousemove', this.windowMouseMoveListener);\n window.removeEventListener('mouseup', this.windowMouseUpListener);\n this.windowMouseUpListener = null;\n this.windowMouseMoveListener = null;\n event.preventDefault();\n }\n }\n\n onTouchStart(event) {\n if (!this.disabled && !this.readonly) {\n this.windowTouchMoveListener = this.onTouchMove.bind(this);\n this.windowTouchEndListener = this.onTouchEnd.bind(this);\n window.addEventListener('touchmove', this.windowTouchMoveListener);\n window.addEventListener('touchend', this.windowTouchEndListener);\n event.preventDefault();\n }\n }\n\n onTouchEnd(event) {\n if (!this.disabled && !this.readonly) {\n window.removeEventListener('touchmove', this.windowTouchMoveListener);\n window.removeEventListener('touchend', this.windowTouchEndListener);\n this.windowTouchMoveListener = null;\n this.windowTouchEndListener = null;\n event.preventDefault();\n }\n }\n\n onMouseMove(event) {\n if (!this.disabled && !this.readonly) {\n this.updateValue(event.offsetX, event.offsetY);\n event.preventDefault();\n }\n }\n\n onTouchMove(event) {\n if (!this.disabled && !this.readonly && event.touches.length == 1) {\n const rect = this.el.nativeElement.children[0].getBoundingClientRect();\n const touch = event.targetTouches.item(0);\n const offsetX = touch.clientX - rect.left;\n const offsetY = touch.clientY - rect.top;\n this.updateValue(offsetX, offsetY);\n }\n }\n\n writeValue(value: any) : void {\n this.value = value;\n this.cd.markForCheck();\n }\n\n registerOnChange(fn: Function): void {\n this.onModelChange = fn;\n }\n\n registerOnTouched(fn: Function): void {\n this.onModelTouched = fn;\n }\n\n setDisabledState(val: boolean): void {\n this.disabled = val;\n this.cd.markForCheck();\n }\n\n containerClass() {\n return {\n 'p-knob p-component': true,\n 'p-disabled': this.disabled\n };\n }\n\n rangePath() {\n return `M ${this.minX()} ${this.minY()} A ${this.radius} ${this.radius} 0 1 1 ${this.maxX()} ${this.maxY()}`;\n }\n\n valuePath() {\n return `M ${this.zeroX()} ${this.zeroY()} A ${this.radius} ${this.radius} 0 ${this.largeArc()} ${this.sweep()} ${this.valueX()} ${this.valueY()}`;\n }\n\n zeroRadians() {\n if (this.min > 0 && this.max > 0)\n return this.mapRange(this.min, this.min, this.max, this.minRadians, this.maxRadians);\n else\n return this.mapRange(0, this.min, this.max, this.minRadians, this.maxRadians);\n }\n\n valueRadians() {\n return this.mapRange(this._value, this.min, this.max, this.minRadians, this.maxRadians);\n }\n\n minX() {\n return this.midX + Math.cos(this.minRadians) * this.radius;\n }\n\n minY() {\n return this.midY - Math.sin(this.minRadians) * this.radius;\n }\n\n maxX() {\n return this.midX + Math.cos(this.maxRadians) * this.radius;\n }\n\n maxY() {\n return this.midY - Math.sin(this.maxRadians) * this.radius;\n }\n\n zeroX() {\n return this.midX + Math.cos(this.zeroRadians()) * this.radius;\n }\n\n zeroY() {\n return this.midY - Math.sin(this.zeroRadians()) * this.radius;\n }\n\n valueX() {\n return this.midX + Math.cos(this.valueRadians()) * this.radius;\n }\n\n valueY() {\n return this.midY - Math.sin(this.valueRadians()) * this.radius;\n }\n\n largeArc() {\n return Math.abs(this.zeroRadians() - this.valueRadians()) < Math.PI ? 0 : 1;\n }\n\n sweep() {\n return this.valueRadians() > this.zeroRadians() ? 0 : 1;\n }\n\n valueToDisplay() {\n return this.valueTemplate.replace(\"{value}\", this._value.toString());\n }\n\n get _value(): number {\n return this.value != null ? this.value : this.min;\n }\n}\n\n@NgModule({\n imports: [CommonModule],\n exports: [Knob],\n declarations: [Knob]\n})\nexport class KnobModule { }\n"]}