@yamcs/opi 1.2.3 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -20
- package/dist/opi.js +1 -1
- package/dist/opi.js.map +1 -1
- package/dist/opi.umd.js +1 -1
- package/dist/opi.umd.js.map +1 -1
- package/dist/types/AutoScaleWidgets.d.ts +6 -0
- package/dist/types/Display.d.ts +4 -0
- package/dist/types/ImageResolver.d.ts +9 -0
- package/dist/types/ScaleOptions.d.ts +6 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/scripting/GUIUtil.d.ts +8 -0
- package/dist/types/scripting/WidgetWrapper.d.ts +3 -0
- package/dist/types/widgets/graphics/ImageWidget.d.ts +1 -0
- package/dist/types/widgets/monitors/XYGraph.d.ts +19 -19
- package/package.json +7 -7
- package/dist/types/widgets/monitors/Axis.d.ts +0 -40
- package/dist/types/widgets/monitors/CommandBuffer.d.ts +0 -6
- package/dist/types/widgets/monitors/Trace.d.ts +0 -38
- package/dist/types/widgets/monitors/TraceBuffer.d.ts +0 -32
- package/dist/types/widgets/monitors/XYGraph2.d.ts +0 -46
- package/dist/types/widgets/monitors/XYGraphToolbar.d.ts +0 -51
package/dist/opi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t{constructor(t,e,i,s=255){this.red=t,this.green=e,this.blue=i,this.alpha=s}withAlpha(e){return new t(this.red,this.green,this.blue,e)}mixWith(e,i){const s=Math.floor(this.red*i+e.red*(1-i)),r=Math.floor(this.green*i+e.green*(1-i)),o=Math.floor(this.blue*i+e.blue*(1-i));return new t(s,r,o)}brighter(){let{red:e,green:i,blue:s}=this;const r=Math.floor(1/(1-.7));return 0===e&&0===i&&0===s?new t(r,r,r):(e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),s>0&&s<r&&(s=r),new t(Math.min(Math.floor(this.red/.7),255),Math.min(Math.floor(this.green/.7),255),Math.min(Math.floor(this.blue/.7),255)))}darker(){return new t(Math.max(Math.floor(.7*this.red),0),Math.max(Math.floor(.7*this.green),0),Math.max(Math.floor(.7*this.blue),0))}contrast(){return new t(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=1==t.length?"0"+t:t;let e=this.green.toString(16);e=1==e.length?"0"+e:e;let i=this.blue.toString(16);i=1==i.length?"0"+i:i;let s=this.alpha.toString(16);return s=1==s.length?"0"+s:s,`#${t}${e}${i}${s}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}}t.TRANSPARENT=new t(0,0,0,0),t.BLACK=new t(0,0,0),t.BLUE=new t(0,0,255),t.CYAN=new t(0,255,255),t.DARK_GRAY=new t(150,150,150),t.GRAY=new t(200,200,200),t.GREEN=new t(0,255,0),t.LIGHT_BLUE=new t(153,186,243),t.ORANGE=new t(255,128,0),t.PINK=new t(255,0,255),t.PURPLE=new t(128,0,255),t.RED=new t(255,0,0),t.WHITE=new t(255,255,255),t.YELLOW=new t(255,255,0),t.BUTTON=new t(239,240,241),t.BUTTON_DARKER=new t(164,168,172),t.BUTTON_DARKEST=t.BLACK,t.BUTTON_LIGHTEST=t.WHITE;const e=t=>(document.removeEventListener("click",e,!0),t.preventDefault(),t.stopPropagation(),!1);function i(t){return 1==(1&t.buttons)||void 0===t.buttons&&1==t.which}function s(t,e){return t&&e&&t.id===e.id}class r{constructor(t,e,i){this.display=t,this.canvas=e,this.hitCanvas=i,this.grabbing=!1,this.documentMouseMoveListener=t=>this.onDocumentMouseMove(t),this.documentMouseUpListener=t=>this.onDocumentMouseUp(t),e.addEventListener("click",(t=>this.onCanvasClick(t)),!1),e.addEventListener("mousedown",(t=>this.onCanvasMouseDown(t)),!1),e.addEventListener("mouseup",(t=>this.onCanvasMouseUp(t)),!1),e.addEventListener("mouseout",(t=>this.onCanvasMouseOut(t)),!1),e.addEventListener("mousemove",(t=>this.onCanvasMouseMove(t)),!1)}toPoint(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();const e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{const i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",e,!0),i(t))){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);return i&&i.mouseDown&&i.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),i&&i.grab&&(this.grabPoint=Object.assign({},e),this.grabTarget=i),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.mouseUp&&i.mouseUp()}onCanvasMouseOut(t){this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&this.prevEnteredRegion.mouseOut(),this.prevEnteredRegion=void 0,t.preventDefault(),t.stopPropagation()}onCanvasMouseMove(t){const e=this.toPoint(t),r=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(s(this.prevEnteredRegion,r)||this.prevEnteredRegion.mouseOut()),r&&r.mouseEnter&&(s(this.prevEnteredRegion,r)||r.mouseEnter()),this.prevEnteredRegion=r;const o=r&&r.cursor?r.cursor:"auto";if(o!=this.canvas.style.cursor&&(this.canvas.style.cursor=o),!this.grabbing&&r&&r.tooltip?this.display.setTooltip(r.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&i(t)){const t=(h=this.grabPoint.x,n=this.grabPoint.y,a=e.x,l=e.y,Math.sqrt((a-h)*(a-h)+(l-n)*(l-n)));Math.abs(t)>5&&(this.initiateGrab(),this.grabPoint&&(this.grabPoint=e))}var h,n,a,l;this.grabbing&&this.grabTarget&&i(t)&&this.grabTarget.grab({clientX:t.clientX,clientY:t.clientY,point:e,dx:e.x-this.grabPoint.x,dy:e.y-this.grabPoint.y})}initiateGrab(){document.addEventListener("click",e,!0),document.addEventListener("mouseup",this.documentMouseUpListener),document.addEventListener("mousemove",this.documentMouseMoveListener),this.grabbing=!0}onDocumentMouseUp(t){if(this.grabbing){document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener);const t=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,(null==t?void 0:t.grabEnd)&&t.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){const i=this.display.instance;if(i)for(const s of i.widgets.slice().reverse()){const i=s.holderX,r=s.holderY,o=s.holderX+s.holderWidth,h=s.holderY+s.holderHeight;if(i<t&&t<o&&r<e&&e<h)return this.display.selection=[s.wuid],!1}}}const o="rgb(255,255,255)";class h{constructor(t,e,i){this.parent=t,this.regions={};const s=document.createElement("canvas");s.width=null!=e?e:s.width,s.height=null!=i?i:s.height,this.ctx=s.getContext("2d"),this.root=(null==t?void 0:t.root)||t}clear(){this.regions={},this.ctx.fillStyle=o,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){const e=(this.root||this).generateUniqueColor();return(this.root||this).regions[e]=t,this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){const i=this.ctx.getImageData(t,e,1,1).data,s=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regions[s]||void 0}createChild(t,e){return new h(this,t,e)}transferToParent(t,e,i,s){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,s)}generateUniqueColor(){for(;;){const t=`rgb(${Math.round(255*Math.random())},${Math.round(255*Math.random())},${Math.round(255*Math.random())})`;if(!this.regions[t]&&t!=o)return t}}}function n(t,e,i,s,r){return l({x:t,y:e,width:i,height:s},r/2)}function a(t,e,i,s,r){const o=Math.sin(r),h=Math.cos(r),n=t-i,a=e-s;return{x:n*h-a*o+i,y:n*o+a*h+s}}function l(t,e,i){return void 0===i&&(i=e),{x:t.x+i,y:t.y+e,width:t.width-(i+i),height:t.height-(e+e)}}function d(t){return{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,width:Math.round(t.width),height:Math.round(t.height)}}function c(t,e,i){return{x:t.x+e,y:t.y+i}}function p(t,e,i){return t.map((t=>c(t,e,i)))}function g(t){return t*Math.PI/180}function u(t,e,i){const s=Math.floor(t*Math.cos(e)),r=Math.floor(-t*Math.sin(e));return{x:i.x+i.width/2+s,y:i.y+i.height/2+r}}function m(t,e){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));let o=Math.acos(i/r);return s>0&&(o=2*Math.PI-o),new f(Math.floor(r),o)}class f{constructor(t,e){this.r=t,this.theta=e}toPoint(){return{x:Math.floor(this.r*Math.cos(this.theta)),y:Math.floor(-this.r*Math.sin(this.theta))}}}function x(t,e){return t.map((t=>({x:t.x*e,y:t.y*e})))}function w(t,e,i,s,r,o,h){t.beginPath(),o||h?(s<2*o&&(o=s/2),r<2*h&&(h=r/2),t.moveTo(e+o,i),t.lineTo(e+s-o,i),t.quadraticCurveTo(e+s,i,e+s,i+h),t.lineTo(e+s,i+r-h),t.quadraticCurveTo(e+s,i+r,e+s-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-h),t.lineTo(e,i+h),t.quadraticCurveTo(e,i,e+o,i)):t.rect(e,i,s,r)}class y{constructor(t,e){this.canvas=t,this.ctx=t.getContext("2d"),this.hitCanvas=e||new h,this.hitCtx=this.hitCanvas.ctx}createChild(t,e){const i=this.hitCanvas.createChild(t,e),s=document.createElement("canvas");return s.width=t,s.height=e,new y(s,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,s,r){const{width:o,height:h}=t.canvas,n=o/h;let a=s,l=a/n;l>r&&(l=r,a=l*n),this.copyScaled(t,e,i,a,l)}copyScaled(t,e,i,s,r){this.ctx.drawImage(t.canvas,e,i,s,r),t.hitCanvas.transferToParent(e,i,s,r)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){this.ctx.canvas.width==t&&this.ctx.canvas.height==e||(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(w(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.fill()):this.ctx.fillRect(t.x,t.y,t.width,t.height),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}fillText(t){this.ctx.textBaseline=t.baseline,this.ctx.textAlign=t.align,this.ctx.font=t.font.getFontString(),this.ctx.fillStyle=t.color.toString(),this.ctx.fillText(t.text,t.x,t.y)}fillEllipse(t){this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.strokeStyle="color"in t?t.color.toString():t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e){this.ctx.font=e.getFontString();return{width:this.ctx.measureText(t).width,height:e.height}}createLinearGradient(t,e,i,s){return this.ctx.createLinearGradient(t,e,i,s)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);const e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){const i=l(t,e/2,e/2);t.rx||t.ry?(w(this.ctx,i.x,i.y,i.width,i.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(i.x,i.y,i.width,i.height)}else t.rx||t.ry?(w(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(t.x,t.y,t.width,t.height);t.dash&&this.ctx.setLineDash([])}strokePath(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.lineWidth=t.lineWidth||1,this.ctx.strokeStyle=t.color.toString(),void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),void 0!==t.opacity&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new b(this.hitCanvas.ctx)}}class v{constructor(t,e){this.segments=[],this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){const e=new v(t[0].x,t[0].y);for(let i=1;i<t.length;i++)e.lineTo(t[i].x,t[i].y);return e}getBoundingBox(){const t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){const s=this.segments[i];s.x<t.x&&(t.x=s.x),s.x>e.x&&(e.x=s.x),s.y<t.y&&(t.y=s.y),s.y>e.y&&(e.y=s.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){const t=this.segments[0];return this.segments.push({x:t.x,y:t.y,line:!0}),this}translate(t,e){for(const i of this.segments)i.x+=t,i.y+=e;return this}}class b{constructor(t){this.ctx=t}addRect(t,e,i,s){return this.ctx.fillRect(t,e,i,s),this}addEllipse(t,e,i,s,r,o,h,n){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,s,r,o,h,n),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(const e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}}class _{constructor(t,e){this.pvName=t,this.formula=e,this.pvValues=new Map}updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){const t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":-1===e.indexOf(t.value)&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(const i of t.arguments)this.getExpressionParameters(i,e)}}execute(){const t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":return t.value;case"ParameterLiteral":const e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConstantLiteral":case"NumericLiteral":case"StringLiteral":return t.value;case"ConditionalExpression":return this.executeConditionalExpression(t);case"BinaryExpression":return this.executeBinaryExpression(t);case"LogicalExpression":return this.executeLogicalExpression(t);case"UnaryExpression":return this.executeUnaryExpression(t);case"CallExpression":return this.executeCallExpression(t);default:throw new Error("Unexpected expression type")}}executeBinaryExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"+":return e+i;case"-":return e-i;case"*":return e*i;case"/":return e/i;case"^":return Math.pow(e,i);case"%":return e%i;case"==":return e===i;case"!=":return e!==i;case"<=":return e<=i;case"<":return e<i;case">=":return e>=i;case">":return e>i;default:throw new Error(`Unexpected binary operator ${t.operator}`)}}executeLogicalExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"&&":return e&&i;case"||":return e||i;default:throw new Error(`Unexpected logical operator ${t.operator}`)}}executeConditionalExpression(t){const e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(void 0===t.alternate)return e?i:null;{const s=this.executeExpression(t.alternate);return e?i:s}}executeUnaryExpression(t){const e=this.executeExpression(t.argument);switch(t.operator){case"-":return-e;case"+":return e;default:throw new Error(`Unexpected unary operator ${t.operator}`)}}executeCallExpression(t){const e=t.callee.name,i=[];for(const e of t.arguments)i.push(this.executeExpression(e));switch(e){case"abs":return Math.abs(i[0]);case"acos":return Math.acos(i[0]);case"asin":return Math.asin(i[0]);case"atan":return Math.atan(i[0]);case"cbrt":return Math.cbrt(i[0]);case"ceil":return Math.ceil(i[0]);case"cos":return Math.cos(i[0]);case"cosh":return Math.cosh(i[0]);case"exp":return Math.exp(i[0]);case"floor":return Math.floor(i[0]);case"log":return Math.log(i[0]);case"log10":return Math.log10(i[0]);case"round":return Math.round(i[0]);case"signum":return Math.sign(i[0]);case"sin":return Math.sin(i[0]);case"sinh":return Math.sinh(i[0]);case"sqrt":return Math.sqrt(i[0]);case"tan":return Math.tan(i[0]);case"tanh":return Math.tanh(i[0]);case"toDegrees":return 180*i[0]/Math.PI;case"toRadians":return i[0]/180*Math.PI;case"parameterAcquisitionStatus":return this.callParameterAcquisitionStatus(i[0]);default:throw new Error(`Unsupported function '${e}'`)}}callParameterAcquisitionStatus(t){const e=this.pvValues.get(t);if(e)return e.acquisitionStatus}}function T(t,e,i,s){var r=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(r,T.prototype),r.expected=e,r.found=i,r.location=s,r.name="SyntaxError",r}function S(t,e,i){return i=i||" ",t.length>e?t:(e-=t.length,t+(i+=i.repeat(e)).slice(0,e))}function V(t,e){var i,s,r,o,h={},n=(e=void 0!==e?e:{}).grammarSource,a={Start:Mt},l=Mt,d=".",c='"',p="'",g="-",u="+",m=",",f="<=",x=">=",w="==",y="!=",v="&&",b="||",_=/^[a-zA-Z]/,S=/^[a-zA-Z0-9_]/,V=/^[0-9]/,A=/^[1-9]/,L=/^[^\n\r\f"]/,C=/^[^\n\r\f']/,k=Vt("=",!1),P=Vt(" ",!1),M=Vt("\t",!1),R=Vt("false",!0),E=Vt("true",!0),W=Vt("PI",!0),B=Vt("E",!0),I=Lt("identifier"),O=At([["a","z"],["A","Z"]],!1,!1),H=Vt("_",!1),F=At([["a","z"],["A","Z"],["0","9"],"_"],!1,!1),N=Lt("boolean"),D=Lt("constant"),$=Lt("number"),G=Vt(".",!1),j=Vt("0",!1),z=At([["0","9"]],!1,!1),U=At([["1","9"]],!1,!1),q=Lt("string"),Y=Vt('"',!1),X=At(["\n","\r","\f",'"'],!0,!1),K=Lt("parameter"),Z=Vt("'",!1),J=At(["\n","\r","\f","'"],!0,!1),Q=Vt("(",!1),tt=Vt(")",!1),et=Vt("-",!1),it=Vt("+",!1),st=Vt(",",!1),rt=Vt("*",!1),ot=Vt("/",!1),ht=Vt("^",!1),nt=Vt("%",!1),at=Vt("<=",!1),lt=Vt(">=",!1),dt=Vt("<",!1),ct=Vt(">",!1),pt=Vt("==",!1),gt=Vt("!=",!1),ut=Vt("&&",!1),mt=Vt("||",!1),ft=function(){return{type:"NumericLiteral",value:parseFloat(t.substring(vt,yt))}},xt=function(t,e){return function(t,e,i){return[t].concat(function(t,e){return t.map((function(t){return t[e]}))}(e,i))}(t,e,3)},wt=function(t,e){return function(t,e){return e.reduce((function(t,e){return{type:"BinaryExpression",operator:e[1],left:t,right:e[3]}}),t)}(t,e)},yt=0,vt=0,bt=[{line:1,column:1}],_t=0,Tt=[],St=0;if("startRule"in e){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');l=a[e.startRule]}function Vt(t,e){return{type:"literal",text:t,ignoreCase:e}}function At(t,e,i){return{type:"class",parts:t,inverted:e,ignoreCase:i}}function Lt(t){return{type:"other",description:t}}function Ct(e){var i,s=bt[e];if(s)return s;for(i=e-1;!bt[i];)i--;for(s={line:(s=bt[i]).line,column:s.column};i<e;)10===t.charCodeAt(i)?(s.line++,s.column=1):s.column++,i++;return bt[e]=s,s}function kt(t,e){var i=Ct(t),s=Ct(e);return{source:n,start:{offset:t,line:i.line,column:i.column},end:{offset:e,line:s.line,column:s.column}}}function Pt(t){yt<_t||(yt>_t&&(_t=yt,Tt=[]),Tt.push(t))}function Mt(){var e,i,s;return e=yt,61===t.charCodeAt(yt)?(i="=",yt++):(i=h,0===St&&Pt(k)),i!==h?(Rt(),(s=function(){var t,e;t=yt,(e=zt())!==h&&(vt=t,e={type:"Formula",expression:e});return t=e}())!==h?(Rt(),vt=e,e=s):(yt=e,e=h)):(yt=e,e=h),e}function Rt(){var t,e;for(t=[],e=Et();e!==h;)t.push(e),e=Et();return t}function Et(){var e;return 32===t.charCodeAt(yt)?(e=" ",yt++):(e=h,0===St&&Pt(P)),e===h&&(9===t.charCodeAt(yt)?(e="\t",yt++):(e=h,0===St&&Pt(M))),e}function Wt(){var e,i;return e=yt,(i=function(){var e,i,s,r;if(St++,e=yt,(i=function(){var e;_.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(O));e===h&&(95===t.charCodeAt(yt)?(e="_",yt++):(e=h,0===St&&Pt(H)));return e}())!==h){for(s=[],r=Bt();r!==h;)s.push(r),r=Bt();vt=e,e={type:"Symbol",name:i+s.join("")}}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(I));return e}())!==h&&(vt=e,i=i),e=i}function Bt(){var e;return S.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(F)),e}function It(){var e;return(e=function(){var e,i;St++,e=yt,(i=function(){var e;return"true"===t.substr(yt,4).toLowerCase()?(e=t.substr(yt,4),yt+=4):(e=h,0===St&&Pt(E)),e}())!==h&&(vt=e,i={type:"BooleanLiteral",value:!0});(e=i)===h&&(e=yt,(i=function(){var e;return"false"===t.substr(yt,5).toLowerCase()?(e=t.substr(yt,5),yt+=5):(e=h,0===St&&Pt(R)),e}())!==h&&(vt=e,i={type:"BooleanLiteral",value:!1}),e=i);St--,e===h&&(i=h,0===St&&Pt(N));return e}())===h&&(e=function(){var e,i;St++,e=yt,(i=function(){var e;return"pi"===t.substr(yt,2).toLowerCase()?(e=t.substr(yt,2),yt+=2):(e=h,0===St&&Pt(W)),e}())!==h&&(vt=e,i={type:"ConstantLiteral",value:Math.PI});(e=i)===h&&(e=yt,(i=function(){var e;return"e"===t.substr(yt,1).toLowerCase()?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(B)),e}())!==h&&(vt=e,i={type:"ConstantLiteral",value:Math.E}),e=i);St--,e===h&&(i=h,0===St&&Pt(D));return e}())===h&&(e=function(){var e,i,s,r,o;if(St++,e=yt,(i=Ot())!==h)if(46===t.charCodeAt(yt)?(s=d,yt++):(s=h,0===St&&Pt(G)),s!==h){for(r=[],o=Ht();o!==h;)r.push(o),o=Ht();vt=e,e=ft()}else yt=e,e=h;else yt=e,e=h;if(e===h){if(e=yt,46===t.charCodeAt(yt)?(i=d,yt++):(i=h,0===St&&Pt(G)),i!==h){if(s=[],(r=Ht())!==h)for(;r!==h;)s.push(r),r=Ht();else s=h;s!==h?(vt=e,e=ft()):(yt=e,e=h)}else yt=e,e=h;e===h&&(e=yt,(i=Ot())!==h&&(vt=e,i=ft()),e=i)}St--,e===h&&(i=h,0===St&&Pt($));return e}())===h&&(e=function(){var e,i,s,r;St++,e=yt,34===t.charCodeAt(yt)?(i=c,yt++):(i=h,0===St&&Pt(Y));if(i!==h){for(s=[],L.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(X));r!==h;)s.push(r),L.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(X));34===t.charCodeAt(yt)?(r=c,yt++):(r=h,0===St&&Pt(Y)),r!==h?(vt=e,e={type:"StringLiteral",value:s.join("")}):(yt=e,e=h)}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(q));return e}())===h&&(e=function(){var e,i,s,r;St++,e=yt,39===t.charCodeAt(yt)?(i=p,yt++):(i=h,0===St&&Pt(Z));if(i!==h){for(s=[],C.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(J));r!==h;)s.push(r),C.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(J));39===t.charCodeAt(yt)?(r=p,yt++):(r=h,0===St&&Pt(Z)),r!==h?(vt=e,e={type:"ParameterLiteral",value:s.join("")}):(yt=e,e=h)}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(K));return e}()),e}function Ot(){var e,i,s,r;if(48===t.charCodeAt(yt)?(e="0",yt++):(e=h,0===St&&Pt(j)),e===h)if(e=yt,(i=function(){var e;A.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(U));return e}())!==h){for(s=[],r=Ht();r!==h;)s.push(r),r=Ht();e=i=[i,s]}else yt=e,e=h;return e}function Ht(){var e;return V.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(z)),e}function Ft(){var e,i,s;return(e=function(){var e,i,s,r;return(e=It())===h&&(e=yt,40===t.charCodeAt(yt)?(i="(",yt++):(i=h,0===St&&Pt(Q)),i!==h?(Rt(),(s=zt())!==h?(Rt(),41===t.charCodeAt(yt)?(r=")",yt++):(r=h,0===St&&Pt(tt)),r!==h?(vt=e,e=s):(yt=e,e=h)):(yt=e,e=h)):(yt=e,e=h)),e}())===h&&(e=yt,(i=function(){var e;45===t.charCodeAt(yt)?(e=g,yt++):(e=h,0===St&&Pt(et));e===h&&(43===t.charCodeAt(yt)?(e=u,yt++):(e=h,0===St&&Pt(it)));return e}())!==h?(Rt(),(s=Ft())!==h?(Rt(),vt=e,e={type:"UnaryExpression",operator:i,argument:s}):(yt=e,e=h)):(yt=e,e=h)),e}function Nt(){var e,i,s;return e=yt,(i=Wt())!==h?(Rt(),(s=function(){var e,i,s,r;e=yt,40===t.charCodeAt(yt)?(i="(",yt++):(i=h,0===St&&Pt(Q));i!==h?(Rt(),s=yt,(r=function(){var e,i,s,r,o,n,a,l;if(e=yt,(i=zt())!==h){for(s=[],r=yt,o=Rt(),44===t.charCodeAt(yt)?(n=m,yt++):(n=h,0===St&&Pt(st)),n!==h?(a=Rt(),(l=zt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),44===t.charCodeAt(yt)?(n=m,yt++):(n=h,0===St&&Pt(st)),n!==h?(a=Rt(),(l=zt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=xt(i,s)}else yt=e,e=h;return e}())!==h?s=r=[r,Rt()]:(yt=s,s=h),s===h&&(s=null),41===t.charCodeAt(yt)?(r=")",yt++):(r=h,0===St&&Pt(tt)),r!==h?(vt=e,a=0,e=null!==(o=(n=s)?n[a]:null)?o:[]):(yt=e,e=h)):(yt=e,e=h);var o,n,a;return e}())!==h?(vt=e,e={type:"CallExpression",callee:i,arguments:s}):(yt=e,e=h)):(yt=e,e=h),e===h&&(e=Ft()),e}function Dt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Nt())!==h){for(s=[],r=yt,o=Rt(),42===t.charCodeAt(yt)?(n="*",yt++):(n=h,0===St&&Pt(rt)),n===h&&(47===t.charCodeAt(yt)?(n="/",yt++):(n=h,0===St&&Pt(ot)),n===h&&(94===t.charCodeAt(yt)?(n="^",yt++):(n=h,0===St&&Pt(ht)),n===h&&(37===t.charCodeAt(yt)?(n="%",yt++):(n=h,0===St&&Pt(nt))))),n!==h?(a=Rt(),(l=Nt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),42===t.charCodeAt(yt)?(n="*",yt++):(n=h,0===St&&Pt(rt)),n===h&&(47===t.charCodeAt(yt)?(n="/",yt++):(n=h,0===St&&Pt(ot)),n===h&&(94===t.charCodeAt(yt)?(n="^",yt++):(n=h,0===St&&Pt(ht)),n===h&&(37===t.charCodeAt(yt)?(n="%",yt++):(n=h,0===St&&Pt(nt))))),n!==h?(a=Rt(),(l=Nt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function $t(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Dt())!==h){for(s=[],r=yt,o=Rt(),43===t.charCodeAt(yt)?(n=u,yt++):(n=h,0===St&&Pt(it)),n===h&&(45===t.charCodeAt(yt)?(n=g,yt++):(n=h,0===St&&Pt(et))),n!==h?(a=Rt(),(l=Dt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),43===t.charCodeAt(yt)?(n=u,yt++):(n=h,0===St&&Pt(it)),n===h&&(45===t.charCodeAt(yt)?(n=g,yt++):(n=h,0===St&&Pt(et))),n!==h?(a=Rt(),(l=Dt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function Gt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=$t())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===f?(n=f,yt+=2):(n=h,0===St&&Pt(at)),n===h&&(t.substr(yt,2)===x?(n=x,yt+=2):(n=h,0===St&&Pt(lt)),n===h&&(60===t.charCodeAt(yt)?(n="<",yt++):(n=h,0===St&&Pt(dt)),n===h&&(62===t.charCodeAt(yt)?(n=">",yt++):(n=h,0===St&&Pt(ct))))),n!==h?(a=Rt(),(l=$t())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===f?(n=f,yt+=2):(n=h,0===St&&Pt(at)),n===h&&(t.substr(yt,2)===x?(n=x,yt+=2):(n=h,0===St&&Pt(lt)),n===h&&(60===t.charCodeAt(yt)?(n="<",yt++):(n=h,0===St&&Pt(dt)),n===h&&(62===t.charCodeAt(yt)?(n=">",yt++):(n=h,0===St&&Pt(ct))))),n!==h?(a=Rt(),(l=$t())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function jt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Gt())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===w?(n=w,yt+=2):(n=h,0===St&&Pt(pt)),n===h&&(t.substr(yt,2)===y?(n=y,yt+=2):(n=h,0===St&&Pt(gt))),n!==h?(a=Rt(),(l=Gt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===w?(n=w,yt+=2):(n=h,0===St&&Pt(pt)),n===h&&(t.substr(yt,2)===y?(n=y,yt+=2):(n=h,0===St&&Pt(gt))),n!==h?(a=Rt(),(l=Gt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function zt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=jt())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===v?(n=v,yt+=2):(n=h,0===St&&Pt(ut)),n===h&&(t.substr(yt,2)===b?(n=b,yt+=2):(n=h,0===St&&Pt(mt))),n!==h?(a=Rt(),(l=jt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===v?(n=v,yt+=2):(n=h,0===St&&Pt(ut)),n===h&&(t.substr(yt,2)===b?(n=b,yt+=2):(n=h,0===St&&Pt(mt))),n!==h?(a=Rt(),(l=jt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=function(t,e){return e.reduce((function(t,e){return{type:"LogicalExpression",operator:e[1],left:t,right:e[3]}}),t)}(i,s)}else yt=e,e=h;return e}if((i=l())!==h&&yt===t.length)return i;throw i!==h&&yt<t.length&&Pt({type:"end"}),s=Tt,r=_t<t.length?t.charAt(_t):null,o=_t<t.length?kt(_t,_t+1):kt(_t,_t),new T(T.buildMessage(s,r),s,r,o)}!function(t,e){function i(){this.constructor=t}i.prototype=e.prototype,t.prototype=new i}(T,Error),T.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var i,s=null;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){s=t[i].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,o=this.location.source+":"+r.line+":"+r.column;if(s){var h=this.location.end,n=S("",r.line.toString().length),a=s[r.line-1],l=r.line===h.line?h.column:a.length+1;e+="\n --\x3e "+o+"\n"+n+" |\n"+r.line+" | "+a+"\n"+n+" | "+S("",r.column-1)+S("",l-r.column,"^")}else e+="\n at "+o}return e},T.buildMessage=function(t,e){var i={literal:function(t){return'"'+r(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function s(t){return t.charCodeAt(0).toString(16).toUpperCase()}function r(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function h(t){return i[t.type](t)}return"Expected "+function(t){var e,i,s=t.map(h);if(s.sort(),s.length>0){for(e=1,i=1;e<s.length;e++)s[e-1]!==s[e]&&(s[i]=s[e],i++);s.length=i}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(t)+" but "+function(t){return t?'"'+r(t)+'"':"end of input"}(e)+" found."};class A{compile(t){const e=V(t,{});return new _(t,e)}execute(t){return this.compile(t).execute()}}class L{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("=")}startProviding(t){for(const e of t)this.pvs.set(e.name,new C(e))}stopProviding(t){for(const e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}}class C{constructor(t){this.pv=t;const e=new A;this.compiledFormula=e.compile(t.name);for(const e of this.compiledFormula.getPVNames()){const i=t.pvEngine.createPV(e);this.compiledFormula.updateDataSource(i.name,{value:i.value,acquisitionStatus:"good"}),t.pvEngine.addListener(e,(()=>{this.compiledFormula.updateDataSource(e,{value:t.pvEngine.getValue(e),acquisitionStatus:"good"}),this.trigger()}))}this.trigger()}trigger(){const t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}}var k,P={exports:{}};k=P,function(){function t(t,e){document.addEventListener?t.addEventListener("scroll",e,!1):t.attachEvent("scroll",e)}function e(t){this.a=document.createElement("div"),this.a.setAttribute("aria-hidden","true"),this.a.appendChild(document.createTextNode(t)),this.b=document.createElement("span"),this.c=document.createElement("span"),this.h=document.createElement("span"),this.f=document.createElement("span"),this.g=-1,this.b.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.c.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.f.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.h.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;",this.b.appendChild(this.h),this.c.appendChild(this.f),this.a.appendChild(this.b),this.a.appendChild(this.c)}function i(t,e){t.a.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+e+";"}function s(t){var e=t.a.offsetWidth,i=e+100;return t.f.style.width=i+"px",t.c.scrollLeft=i,t.b.scrollLeft=t.b.scrollWidth+100,t.g!==e&&(t.g=e,!0)}function r(e,i){function r(){var t=o;s(t)&&t.a.parentNode&&i(t.g)}var o=e;t(e.b,r),t(e.c,r),s(e)}function o(t,e){var i=e||{};this.family=t,this.style=i.style||"normal",this.weight=i.weight||"normal",this.stretch=i.stretch||"normal"}var h=null,n=null,a=null,l=null;function d(){return null===l&&(l=!!document.fonts),l}function c(){if(null===a){var t=document.createElement("div");try{t.style.font="condensed 100px sans-serif"}catch(t){}a=""!==t.style.font}return a}function p(t,e){return[t.style,t.weight,c()?t.stretch:"","100px",e].join(" ")}o.prototype.load=function(t,s){var o=this,a=t||"BESbswy",l=0,c=s||3e3,g=(new Date).getTime();return new Promise((function(t,s){if(d()&&!function(){if(null===n)if(d()&&/Apple/.test(window.navigator.vendor)){var t=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent);n=!!t&&603>parseInt(t[1],10)}else n=!1;return n}()){var u=new Promise((function(t,e){!function i(){(new Date).getTime()-g>=c?e(Error(c+"ms timeout exceeded")):document.fonts.load(p(o,'"'+o.family+'"'),a).then((function(e){1<=e.length?t():setTimeout(i,25)}),e)}()})),m=new Promise((function(t,e){l=setTimeout((function(){e(Error(c+"ms timeout exceeded"))}),c)}));Promise.race([m,u]).then((function(){clearTimeout(l),t(o)}),s)}else!function(t){document.body?t():document.addEventListener?document.addEventListener("DOMContentLoaded",(function e(){document.removeEventListener("DOMContentLoaded",e),t()})):document.attachEvent("onreadystatechange",(function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),t())}))}((function(){function n(){var e;(e=-1!=f&&-1!=x||-1!=f&&-1!=w||-1!=x&&-1!=w)&&((e=f!=x&&f!=w&&x!=w)||(null===h&&(e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),h=!!e&&(536>parseInt(e[1],10)||536===parseInt(e[1],10)&&11>=parseInt(e[2],10))),e=h&&(f==y&&x==y&&w==y||f==v&&x==v&&w==v||f==b&&x==b&&w==b)),e=!e),e&&(_.parentNode&&_.parentNode.removeChild(_),clearTimeout(l),t(o))}var d=new e(a),u=new e(a),m=new e(a),f=-1,x=-1,w=-1,y=-1,v=-1,b=-1,_=document.createElement("div");_.dir="ltr",i(d,p(o,"sans-serif")),i(u,p(o,"serif")),i(m,p(o,"monospace")),_.appendChild(d.a),_.appendChild(u.a),_.appendChild(m.a),document.body.appendChild(_),y=d.a.offsetWidth,v=u.a.offsetWidth,b=m.a.offsetWidth,function t(){if((new Date).getTime()-g>=c)_.parentNode&&_.parentNode.removeChild(_),s(Error(c+"ms timeout exceeded"));else{var e=document.hidden;!0!==e&&void 0!==e||(f=d.a.offsetWidth,x=u.a.offsetWidth,w=m.a.offsetWidth,n()),l=setTimeout(t,50)}}(),r(d,(function(t){f=t,n()})),i(d,p(o,'"'+o.family+'",sans-serif')),r(u,(function(t){x=t,n()})),i(u,p(o,'"'+o.family+'",serif')),r(m,(function(t){w=t,n()})),i(m,p(o,'"'+o.family+'",monospace'))}))}))},k.exports=o}();var M=P.exports;const R=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"];class E{constructor(t,e,i,s){this.name=t,this.style=i,this.height=s?e:Math.round(16*e/15)}scale(t){return new E(this.name,t*this.height,this.style,!0)}getFontString(){return 1===this.style?`bold ${this.height}px ${this.name}`:2===this.style?`italic ${this.height}px ${this.name}`:(0!==this.style&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${this.name}`)}preload(){if(-1!==R.indexOf(this.name))return Promise.resolve();let t={weight:"normal",style:"normal"};return 1===this.style?t.weight="bold":2===this.style&&(t.style="italic"),new M(this.name,t).load()}}E.ARIAL_9=new E("Arial",9,0,!1),E.ARIAL_10=new E("Arial",10,0,!1),E.ARIAL_11=new E("Arial",11,0,!1),E.ARIAL_12_BOLD=new E("Arial",12,1,!1);class W{constructor(){this.BLACK=t.BLACK,this.BLUE=t.BLUE,this.CYAN=t.CYAN,this.DARK_GRAY=t.DARK_GRAY,this.GRAY=t.GRAY,this.GREEN=t.GREEN,this.LIGHT_BLUE=t.LIGHT_BLUE,this.ORANGE=t.ORANGE,this.PINK=t.PINK,this.PURPLE=t.PURPLE,this.RED=t.RED,this.WHITE=t.WHITE,this.YELLOW=t.YELLOW}getColorFromRGB(e,i,s){return new t(e,i,s)}getFont(t,e,i){return new E(t,e,i,!1)}}class B{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}}class I{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}}class O{constructor(t,e,i){this.code=t,this.interpolate=e,this.autoscale=i,this.values=[],this.colors=[],this.entries=[],this.dirty=!0,0===t||(1===t?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):2===t?(this.values=[0,.111,.365,.619,.873,1],this.colors=[[0,0,143],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[128,0,0]]):3===t?(this.values=[0,.126,.251,.375,.5,.625,.749,.874,1],this.colors=[[0,0,0],[255,0,255],[0,0,255],[0,255,255],[0,255,0],[255,255,0],[255,128,0],[255,0,0],[255,255,255]]):4===t?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):5===t?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):6===t&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}addMapping(t,e,i,s){this.values.push(t),this.colors.push([e,i,s]),this.dirty=!0}compile(){this.entries.length=0;for(let t=0;t<this.values.length;t++)this.entries.push([this.values[t],this.colors[t]]);this.entries.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0))}lookup(t){this.dirty&&(this.compile(),this.dirty=!1);let e=this.binarySearch(t);if(e>=0)return this.entries[e][1];if(e=-e-1,0===e)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){const[i,s]=this.entries[e-1],[r,o]=this.entries[e],h=(t-i)/(r-i);return[Math.floor((o[0]-s[0])*h+s[0]),Math.floor((o[1]-s[1])*h+s[1]),Math.floor((o[2]-s[2])*h+s[2])]}return this.entries[e-1][1]}getMinMax(){return[Math.min.apply(Math,this.values),Math.max.apply(Math,this.values)]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){const s=i+e>>1;if(t>this.entries[s][0])e=s+1;else{if(!(t<this.entries[s][0]))return s;i=s-1}}return-e-1}}class H{constructor(t,e=[]){this.widget=t,this.properties=new Map,this.generators=[];for(const t of e)this.properties.set(t.name,t)}clear(){this.properties.clear()}add(t){this.properties.set(t.name,t)}addGenerator(t){this.generators.push(t)}all(){return this.properties.values()}loadProperty(t,e){if(t.hasNode(e.name))if(e instanceof X)e.value=t.getActions(e.name);else if(e instanceof et)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof j)e.value=t.getBoolean(e.name);else if(e instanceof q)e.value=t.getColorMap(e.name);else if(e instanceof z)e.value=t.getColor(e.name);else if(e instanceof G)e.value=t.getFloat(e.name);else if(e instanceof U)e.value=t.getFont(e.name);else if(e instanceof $)e.value=t.getInt(e.name);else if(e instanceof K)e.value=t.getMacros(e.name);else if(e instanceof Y)e.value=t.getPoints(e.name);else if(e instanceof D);else if(e instanceof Q)e.value=t.getRules(e.name);else if(e instanceof tt)e.value=t.getScaleOptions(e.name);else if(e instanceof Z)e.value=t.getScripts(e.name);else if(e instanceof N)e.rawValue=t.getString(e.name);else{if(!(e instanceof J))throw new Error(`Property ${e.name} has an unexpected type`);e.value=t.getStringList(e.name)}}loadXMLValues(t){this.properties.forEach((e=>{this.loadProperty(t,e)})),this.resolveStringProperties();for(const e of this.generators)for(const i of e())this.properties.set(i.name,i),this.loadProperty(t,i);this.resolveStringProperties()}resolveStringProperties(){for(let t=0;t<2;t++)this.properties.forEach((t=>{if(t instanceof N){const e=t;void 0!==e.rawValue?t.value=this.widget.expandMacro(e.rawValue):t.value=e.rawValue}}))}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){const i=this.properties.get(t);if(i&&void 0!==i.value)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){const i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}}class F{constructor(t,e){this.name=t,this.defaultValue=e,this.value=e}get value(){return this._value}set value(t){if(this.value!==t){const e=this._value;if(this._value=t,this.listeners)for(const i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){const e=this.listeners||[],i=e.indexOf(t);-1!==i&&e.splice(i,1)}printScriptValue(t){return String(t)}}class N extends F{printScriptValue(t){return`"${t.replace('"','\\"')}"`}}class D extends F{constructor(t,e){super(t),this.pvPropertyName=e}}class $ extends F{}class G extends F{}class j extends F{}class z extends F{printScriptValue(t){const{red:e,green:i,blue:s}=Object.assign({},t);return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${s})`}}class U extends F{printScriptValue(t){const{name:e,height:i,style:s}=Object.assign({},t);return`ColorFontUtil.getFont("${e}", ${i}, ${s})`}}class q extends F{printScriptValue(t){return`${t.code}`}}class Y extends F{}class X extends F{}class K extends F{}class Z extends F{}class J extends F{}class Q extends F{}class tt extends F{}class et extends F{}class it{constructor(t){this.widget=t}getPropertyValue(t){const e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof N)e=void 0!==e?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof q){let i=0;switch(e){case"GrayScale":i=1;break;case"JET":i=2;break;case"ColorSpectrum":i=3;break;case"Hot":i=4;break;case"Cool":i=5;break;case"Shaded":i=6}const s=new O(i,!0,!0);this.widget.properties.setValue(t,s)}else this.widget.properties.setValue(t,e);this.widget.requestRepaint()}getName(){return this.getPropertyValue("name")}setX(t){this.setPropertyValue("x",t)}setY(t){this.setPropertyValue("y",t)}setWidth(t){this.setPropertyValue("width",t)}setHeight(t){this.setPropertyValue("height",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){var t;return null!==(t=this.widget.value)&&void 0!==t?t:null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}}class st extends it{constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.x))}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.y))}}function rt(t){switch(t.widgetType){case"XY Graph":return new st(t);default:return new it(t)}}class ot{constructor(t){this.display=t}getWidget(t){const e=this.display.findWidgetByName(t);if(e)return rt(e)}}class ht{openInformation(t,e,i){alert(i)}openConfirm(t,e,i){return confirm(i)}openError(t,e,i){alert(i)}}const nt=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"];class at{constructor(t){this.pvEngine=t}getDouble(t){return parseFloat(t.getValue())}getLong(t){return parseInt(t.getValue(),10)}getString(t){return String(t.getValue())}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){const i=t._pv.time;if(i){let t=e;for(const e of nt)t=t.replace(e,this.formatDate(i,e));return t}return null}formatDate(t,e){if("yyyy"===e)return String(t.getUTCFullYear());if("MM"===e){const e=t.getUTCMonth()+1;return e<10?"0"+e:""+e}if("dd"===e){const e=t.getUTCDate();return e<10?"0"+e:""+e}if("HH"===e){const e=t.getUTCHours();return e<10?"0"+e:""+e}if("mm"===e){const e=t.getUTCMinutes();return e<10?"0"+e:""+e}if("ss"===e){const e=t.getUTCSeconds();return e<10?"0"+e:""+e}if("nnnnnnnnn"===e){const e=t.getUTCMilliseconds();return e<10?"00"+e:e<100?"0"+e:""+e}throw new Error(`Unexpected format '${e}'`)}}class lt{constructor(t){this._pv=t}getName(){return this._pv.name}getValue(){return this._pv.value}setValue(t){this._pv.pvEngine.setValue(new Date,this._pv.name,t)}}class dt{constructor(t){this.display=t}openOPI(t,e,i,s){if(0!==i)throw new Error(`Unsupported target ${i}`);{const t={path:e,replace:0===i};this.display.fireEvent("opendisplay",t)}}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}}let ct,pt,gt;class ut{constructor(t,e,i=[]){this.scriptText=e,ct||(ct=document.createElement("iframe"),ct.id="script-e",ct.style.display="none",document.body.appendChild(ct),pt=ct.contentWindow,gt=pt.eval,!gt&&pt.execScript&&(pt.execScript.call(pt,"null"),gt=pt.eval)),this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context=Object.assign({display:new ot(t.display),pvs:i.map((t=>new lt(t))),widget:rt(t),ConsoleUtil:new B,ColorFontUtil:new W,DataUtil:new I,MessageDialog:new ht,PVUtil:new at(t.display.pvEngine),ScriptUtil:new dt(t.display)},t.display.pvEngine.scriptLibraries)}run(){const t=[];for(const e in ct.contentWindow)t.push(e);try{for(const t in this.context)this.context.hasOwnProperty(t)&&(pt[t]=this.context[t]);gt.call(pt,this.scriptText);const e={};for(const i in pt)-1===t.indexOf(i)&&(e[i]=pt[i]);this.context=e}finally{for(const e in pt)-1===t.indexOf(e)&&delete pt[e]}}}class mt{constructor(t,e){this.name=t,this.pvEngine=e,this._writable=!1,this._severity=ft.NONE,this._precision=3,this._disconnected=!1,this.navigable=!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get lowerDisplayLimit(){return this._lowerDisplayLimit}set lowerDisplayLimit(t){this._lowerDisplayLimit=t,this.pvEngine.requestRepaint()}get lowerAlarmLimit(){return this._lowerAlarmLimit}set lowerAlarmLimit(t){this._lowerAlarmLimit=t,this.pvEngine.requestRepaint()}get lowerWarningLimit(){return this._lowerWarningLimit}set lowerWarningLimit(t){this._lowerWarningLimit=t,this.pvEngine.requestRepaint()}get upperWarningLimit(){return this._upperWarningLimit}set upperWarningLimit(t){this._upperWarningLimit=t,this.pvEngine.requestRepaint()}get upperAlarmLimit(){return this._upperAlarmLimit}set upperAlarmLimit(t){this._upperAlarmLimit=t,this.pvEngine.requestRepaint()}get upperDisplayLimit(){return this._upperDisplayLimit}set upperDisplayLimit(t){this._upperDisplayLimit=t,this.pvEngine.requestRepaint()}get precision(){return this._precision}set precision(t){this._precision=t,this.pvEngine.requestRepaint()}get writable(){return this._writable}set writable(t){this._writable=t,this.pvEngine.requestRepaint()}get disconnected(){return this._disconnected}set disconnected(t){this._disconnected=t,this.pvEngine.requestRepaint()}get time(){return this._time}get value(){return this._value}get indexValue(){return this._indexValue}get severity(){return this._severity}toNumber(){return null===this.value?null:"number"==typeof this.value?this.value:"boolean"==typeof this.value?this.value?1:0:void 0!==typeof this.indexValue?this.indexValue:void 0}formatValue(t,e){return null===this.value?"":"string"==typeof this.value?this.value:"number"==typeof this.value?this.formatNumber(t,this.value,e):String(this.value)}formatNumber(t,e,i){if(null==e||null==e)return"";switch(t){case 0:case 1:return-1===i?String(e):e.toFixed(i);case 2:return e.toExponential().replace("e+","E").toUpperCase();case 3:return"0x"+e.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${t}`),String(e)}}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.addListener(this.name,t)}toString(){if(void 0!==this.value)return String(this.value)}}var ft;!function(t){t[t.NONE=0]="NONE",t[t.MINOR=1]="MINOR",t[t.MAJOR=2]="MAJOR",t[t.INVALID=3]="INVALID",t[t.UNDEFINED=4]="UNDEFINED"}(ft||(ft={}));class xt extends mt{constructor(t,e,i){super(t,e),this.initializer=i,this.writable=!0}}const wt=/(loc\:\/\/[^\(]+)(\((.*)\))?/;function yt(t){if(!t.startsWith("loc://"))return t;const e=t.match(wt);return e?e[1]:t}class vt{constructor(t){this.display=t,this.rules=[],this.scripts=[],this.pvs=new Map,this.providers=[],this.scriptLibraries={},this.listeners=new Map}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){const e=yt(t);return this.pvs.has(e)}getPV(t){const e=yt(t);return this.pvs.get(e)}disconnectAll(){for(const t of this.providers){const e=[];for(const i of this.pvs.values())t.canProvide(i.name)&&e.push(i);e.length&&t.stopProviding(e)}this.pvs.clear()}createPV(t){if(t.startsWith("loc://"))return this.createLocalPV(t);let e=this.pvs.get(t);if(e)return e;e=new mt(t,this),this.pvs.set(t,e);for(const i of this.providers)if(i.canProvide(t))return e.navigable=i.isNavigable(),i.startProviding([e]),e;return console.warn(`No provider for PV ${t}`),e.disconnected=!0,e}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){const e=t.match(wt);let i;if(e&&(t=e[1],void 0!==e[3])){const t=e[3];i=t.startsWith('"')&&t.endsWith('"')?t.substring(1,t.length-1):-1!==t.indexOf(",")?t.split(",").map((t=>Number(t.trim()))):Number(t)}let s=this.pvs.get(t),r=!1;if(s){const e=s;void 0===e.initializer||void 0===i||this.initializerEquals(e.initializer,i)?void 0===e.initializer&&void 0!==i&&(r=!0):console.warn(`PV ${t} is defined with different initializers: ${e.initializer} !== ${i}`)}return s||(s=new xt(t,this,i),this.pvs.set(t,s),r=!0),r&&void 0!==i&&this.setValue(new Date,t,i),s}initializerEquals(t,e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}return t===e}getValue(t){const e=yt(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,s=ft.NONE){const r=yt(e),o=this.pvs.get(r);if(!o)throw new Error(`Cannot set value of unknown PV ${e}`);o.setSample({time:t,value:i,severity:s});for(const t of this.listeners.get(e)||[])t()}setValues(t){const e=[];for(const i of t.keys()){const s=this.pvs.get(i);if(s){s.setSample(t.get(i));for(const t of this.listeners.get(i)||[])e.push(t)}else console.warn(`Received an update for unknown pv ${i}`)}for(const t of e)t()}createScript(t,e,i){const s=[];for(const i of e.inputs){const e=t.expandMacro(i.pvName);s.push(this.createPV(e))}const r=new bt(t,e,i,s);this.scripts.push(r);const o=()=>{if(e.checkConnect)for(const t of s)if(t.disconnected||null===t.value||void 0===t.value)return;r.scriptEngine.run()};for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,o)}}createRule(t,e){const i=[];for(const s of e.inputs){const e=t.expandMacro(s.pvName);i.push(this.createPV(e))}const s=new _t(t,e,i);this.rules.push(s);const r=()=>s.scriptEngine.run();for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,r)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e){const i=yt(t),s=this.listeners.get(i);s?s.push(e):this.listeners.set(i,[e]);const r=this.pvs.get(i);r&&null!==r.value&&void 0!==r.value&&e()}removeListener(t,e){const i=yt(t),s=this.listeners.get(i);if(s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}}class bt{constructor(t,e,i,s){this.widget=t,this.script=e,this.text=i,this.scriptEngine=new ut(t,i,s)}}class _t{constructor(t,e,i){this.widget=t,this.rule=e;let s="";const r=t.properties.getProperty(e.propertyName);if(!r)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let t=!1,o=!1,h=!1,n=!1;for(const i of e.expressions)i.expression.match(/pv[0-9]+/)&&(t=!0),e.outputExpression&&i.outputValue.toString().match(/pv[0-9]+/)&&(t=!0),-1!==i.expression.indexOf("pvInt")&&(o=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvInt")&&(o=!0),-1!==i.expression.indexOf("pvStr")&&(h=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvStr")&&(h=!0),-1!==i.expression.indexOf("pvSev")&&(n=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvSev")&&(n=!0);for(let e=0;e<i.length;e++)t&&(s+=`var pv${e} = PVUtil.getDouble(pvs[${e}]);\n`),o&&(s+=`var pvInt${e} = PVUtil.getLong(pvs[${e}]);\n`),h&&(s+=`var pvStr${e} = PVUtil.getString(pvs[${e}]);\n`),n&&(s+=`var pvSev${e} = PVUtil.getSeverity(pvs[${e}]);\n`);for(let t=0;t<e.expressions.length;t++){const i=e.expressions[t].expression,o=e.expressions[t].outputValue;if(t>0&&(s+="else "),s+=`if (${i}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)s+=`${o});\n`;else{s+=`${this.printScriptValue(r,o)});\n`}}const a=r.value,l=this.printScriptValue(r,a);s+=`else widget.setPropertyValue("${e.propertyName}", `,s+=`${l});\n`}this.scriptEngine=new ut(t,s,i)}printScriptValue(t,e){return null==e?"null":t.printScriptValue(e)}}class Tt{constructor(t,e,i){this.pv=t,this.interval=e,void 0!==i&&t.pvEngine.setValue(new Date,t.name,i),this.interval>0&&(this.timer=window.setInterval((()=>{this.generateSample(new Date)}),e))}emit(t,e){let i=ft.NONE;void 0!==this.pv.lowerAlarmLimit&&e<this.pv.lowerAlarmLimit||void 0!==this.pv.upperAlarmLimit&&e>this.pv.upperAlarmLimit?i=ft.MAJOR:(void 0!==this.pv.lowerWarningLimit&&e<this.pv.lowerWarningLimit||void 0!==this.pv.upperWarningLimit&&e>this.pv.upperWarningLimit)&&(i=ft.MINOR),this.pv.pvEngine.setValue(t,this.pv.name,e,i)}stop(){window.clearInterval(this.timer)}}class St extends Tt{constructor(t,e){super(t,-1,e)}generateSample(){}}class Vt extends Tt{constructor(t,e,i,s){super(t,s),this.min=e,this.max=i;const r=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*r,t.lowerWarningLimit=e+.2*r,t.upperWarningLimit=e+.8*r,t.upperAlarmLimit=e+.9*r,t.upperDisplayLimit=i}generateSample(t){const e=Math.random()*(this.max-this.min)+this.min;this.emit(t,e)}}class At extends Tt{constructor(t,e,i,s){super(t,s),this.avg=e,this.stddev=i,t.units="x",t.lowerDisplayLimit=e-4*i,t.lowerAlarmLimit=e-2*i,t.lowerWarningLimit=e-i,t.upperWarningLimit=e+i,t.upperAlarmLimit=e+2*i,t.upperDisplayLimit=e+4*i}generateSample(t){let e,i,s;do{e=2*Math.random()-1,i=2*Math.random()-1,s=e*e+i*i}while(s>=1||0===s);const r=e*Math.sqrt(-2*Math.log(s)/s);this.emit(t,this.avg+r*this.stddev)}}class Lt extends Tt{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.samplesPerCycle=s,this.currentValue=0;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){const e=this.max-this.min,i=Math.sin(2*this.currentValue*Math.PI/this.samplesPerCycle)*e/2+this.min+e/2;this.currentValue++,this.emit(t,i)}}class Ct extends Tt{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.inc=s,this.currentValue=0,this.currentValue=s>=0?e-s:i-s;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(t,this.currentValue)}}const kt=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/;class Pt{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("sim://")}startProviding(t){for(const e of t){const t=new Mt(e);this.pvs.set(e.name,t)}}stopProviding(t){for(const e of t){const t=this.pvs.get(e.name);t&&(t.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(const t of this.pvs.values())t.fn.stop()}}class Mt{constructor(t){this.pv=t;const e=t.name.match(kt);if(e){const t=e[3]?e[3].split(","):[];for(let e=0;e<t.length;e++)t[e]=t[e].trim();this.fn=this.createGenerator(e[1],t)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new St(t,void 0)}createGenerator(t,e){switch(t){case"const":const i=this.saferEval(e[0]);return new St(this.pv,i);case"gaussianNoise":return this.createGaussianNoise(e);case"noise":return this.createNoise(e);case"ramp":return this.createRamp(e);case"sine":return this.createSine(e);default:return console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new St(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(0===t.length)return new Vt(this.pv,-5,5,1e3);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Vt(this.pv,e,i,s)}}createGaussianNoise(t){if(0===t.length)return new At(this.pv,0,1,100);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new At(this.pv,e,i,s)}}createRamp(t){let e;if(0===t.length)e=new Ct(this.pv,-5,5,1,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new Ct(this.pv,i,s,1,r)}else{if(4!==t.length)return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new St(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new Ct(this.pv,i,s,r,o)}}return e}createSine(t){let e;if(0===t.length)e=new Lt(this.pv,-5,5,10,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new Lt(this.pv,i,s,10,r)}else{if(4!==t.length)return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new St(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new Lt(this.pv,i,s,r,o)}}return e}}class Rt{constructor(){this.actions=[],this.hookFirstActionToClick=!1,this.hookAllActionsToClick=!1}add(t){this.actions.push(t)}isClickable(){return this.actions.length&&(this.hookFirstActionToClick||this.hookAllActionsToClick)}getAction(t){if(!(t>=this.actions.length))return this.actions[t]}getClickActions(){const t=[];if(this.hookFirstActionToClick)t.push(0);else if(this.hookAllActionsToClick)for(let e=0;e<this.actions.length;e++)t.push(e);return t}toString(){return 1===this.actions.length?String(this.actions[0])||this.actions[0].type:`${this.actions.length} actions`}}class Et{constructor(t){this.path=t,this.type="OPEN_DISPLAY"}toString(){return`Open ${this.path}`}}class Wt{constructor(){this.type="OPEN_FILE"}toString(){return`Open ${this.path}`}}class Bt{constructor(t){this.embedded=t,this.type="EXECUTE_JAVASCRIPT"}toString(){return"Execute JavaScript"}}class It{constructor(){this.type="EXECUTE_CMD"}toString(){return`Execute Command ${this.command}`}}class Ot{constructor(t,e){this.pvName=t,this.value=e,this.type="WRITE_PV"}toString(){return`Write ${this.value} to ${this.pvName}`}}class Ht{constructor(){this.type="PLAY_SOUND"}toString(){return`Play WAV File ${this.path}`}}class Ft{constructor(){this.type="OPEN_WEBPAGE"}toString(){return`Open Webpage ${this.hyperlink}`}}class Nt{constructor(){this.rules=[]}}class Dt{constructor(e,i){this.display=e,this.parent=i,this.x=0,this.y=0,this.width=0,this.height=0,this.fillRoundRectangleBackgroundBorder=!0,this.properties=new H(this,[new X("actions",new Rt),new j("backcolor_alarm_sensitive",!1),new z("background_color",t.TRANSPARENT),new j("border_alarm_sensitive",!1),new z("border_color"),new $("border_style"),new $("border_width"),new j("enabled",!0),new j("forecolor_alarm_sensitive",!1),new z("foreground_color"),new $("height"),new N("name"),new N("pv_name"),new D("pv_value","pv_name"),new Q("rules",new Nt),new Z("scripts"),new N("text",""),new N("tooltip",""),new j("transparent",!1),new j("visible"),new N("widget_type"),new $("width"),new N("wuid"),new $("x"),new $("y"),new tt("scale_options")])}parseNode(t){this.properties.loadXMLValues(t);for(const t of this.properties.all())if(t instanceof U){const e=t.value;e.preload().then((()=>this.requestRepaint())).catch((()=>console.warn(`Failed to load font '${e.getFontString()}'.`)))}this.pvName&&this.display.pvEngine.createPV(this.pvName);for(const t of this.scripts.scripts)t.embedded?this.display.pvEngine.createScript(this,t,t.text):fetch(`${this.display.baseUrl}${t.path}`,{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{this.display.pvEngine.createScript(this,t,e)}))}));for(const t of this.rules.rules)this.properties.getProperty(t.propertyName)?this.display.pvEngine.createRule(this,t):console.warn(`Cannot create rule for unsupported property ${t.propertyName}`);this.holderRegion={id:`${this.wuid}-holder`,tooltip:()=>this.tooltip},this.actions.isClickable()&&(this.holderRegion.click=()=>{for(const t of this.actions.getClickActions())this.executeAction(t)},this.holderRegion.cursor="pointer"),this.init()}drawHolder(t){var e,i;const{scale:s}=this;let r=[0,0,0,0];const o=this.borderAlarmSensitive&&((null===(e=this.pv)||void 0===e?void 0:e.severity)===ft.MINOR||(null===(i=this.pv)||void 0===i?void 0:i.severity)===ft.MAJOR);if(!o)switch(this.borderStyle){case 0:break;case 1:r=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:r=[1*s,1*s,1*s,1*s];break;case 4:case 5:case 6:r=[2*s,2*s,2*s,2*s];break;case 7:r=[2*s,2*s,1*s,1*s];break;case 8:case 9:case 10:case 11:r=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 12:r=[17*s,1*s,1*s,1*s];break;case 13:r=[16*s,16*s,16*s,16*s];break;case 14:const t=2*this.borderWidth;r=[t,t,t,t]}this.x=this.holderX+r[1],this.y=this.holderY+r[0],this.width=this.holderWidth-r[1]-r[3],this.height=this.holderHeight-r[0]-r[2],o||this.drawBorderStyle(t),t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}drawBorderStyle(e){const{scale:i}=this;if(0===this.borderStyle);else if(1===this.borderStyle)e.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(2===this.borderStyle){const s=1*i,r=this.holderY+s/2,o=this.holderX+s/2,h=this.holderY+this.holderHeight-s+s/2,n=this.holderX+this.holderWidth-s+s/2;e.strokePath({color:t.BLACK,path:new v(n,h).lineTo(n,r).moveTo(n,h).lineTo(o,h)}),e.strokePath({color:t.WHITE,path:new v(o,r).lineTo(n-s,r).moveTo(o,r).lineTo(o,h-s)})}else if(3===this.borderStyle){const s=1*i,r=this.holderY+s/2,o=this.holderX+s/2,h=this.holderY+this.holderHeight-s+s/2,n=this.holderX+this.holderWidth-s+s/2;e.strokePath({color:t.WHITE,path:new v(n,h).lineTo(n,r).moveTo(n,h).lineTo(o,h)}),e.strokePath({color:t.BLACK,path:new v(o,r).lineTo(n-s,r).moveTo(o,r).lineTo(o,h-s)})}else if(4===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_LIGHTEST,t.BUTTON_DARKER,t.BUTTON_DARKER,t.BUTTON_LIGHTEST);else if(5===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_DARKER,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKER);else if(6===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_DARKEST,t.BUTTON_DARKER,t.BUTTON,t.BUTTON_LIGHTEST);else if(7===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKEST,t.BUTTON_DARKER);else if(8===this.borderStyle)this.drawDashedBorder(e,[2*i,2*i]);else if(9===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i]);else if(10===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i,2*i,2*i]);else if(11===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i,2*i,2*i,2*i,2*i]);else if(12===this.borderStyle)e.fillRect({x:this.holderX,y:this.holderY+1*i,width:this.holderWidth,height:16*i,color:this.borderColor}),e.fillText({x:this.holderX+1*i+3*i,y:this.holderY+1*i+8*i,baseline:"middle",align:"left",font:E.ARIAL_11.scale(i),color:t.BLACK,text:this.name}),e.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:t.BLACK,crispen:!0});else if(13===this.borderStyle){this.transparent||e.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor}),e.fillText({x:this.holderX+16*i,y:this.holderY+8*i,baseline:"middle",align:"left",font:E.ARIAL_11.scale(i),color:this.borderColor,text:this.name});const t=e.measureText(this.name,E.ARIAL_11.scale(i)),s=1;let r=n(this.holderX+8*i,this.holderY+8*i,this.holderWidth-16*i-s,this.holderHeight-16*i-s,s);e.strokePath({color:this.backgroundColor.darker(),path:new v(r.x,r.y).lineTo(r.x+8*i,r.y).moveTo(r.x+8*i+t.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)}),r=n(this.holderX+8*i+s,this.holderY+8*i+s,this.holderWidth-16*i-s,this.holderHeight-16*i-s,s),e.strokePath({color:this.backgroundColor.brighter(),path:new v(r.x,r.y).lineTo(r.x+8*i-s,r.y).moveTo(r.x+8*i-s+t.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)})}else if(14===this.borderStyle){const t=n(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&e.fillRect(Object.assign(Object.assign({},t),{rx:4*i,ry:4*i,color:this.backgroundColor})),this.borderWidth&&e.strokeRect(Object.assign(Object.assign({},t),{rx:4*i,ry:4*i,color:this.borderColor,lineWidth:this.borderWidth}))}else 15===this.borderStyle||console.warn(`Unsupported border style: ${this.borderStyle}`)}drawDecoration(e){var i,s,r;if(this.display.editMode)return;const{scale:o}=this;if(!this.pvName||this.pv&&!this.pv.disconnected)this.pv&&void 0===this.pv.value&&e.strokeRect(Object.assign(Object.assign({},this.bounds),{dash:[2*o,2*o],lineWidth:2*o,color:t.PINK,crispen:!0}));else{const i=1*o;e.fillRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:t.PURPLE,opacity:.4}),e.strokeRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:t.PURPLE})}if(this.borderAlarmSensitive){let h;8===this.borderStyle?h=[2*o,2*o]:9===this.borderStyle?h=[6*o,2*o]:10===this.borderStyle?h=[6*o,2*o,2*o,2*o]:11===this.borderStyle&&(h=[6*o,2*o,2*o,2*o,2*o,2*o]),(null===(i=this.pv)||void 0===i?void 0:i.severity)===ft.MAJOR?e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.RED,crispen:!0,dash:h})):(null===(s=this.pv)||void 0===s?void 0:s.severity)===ft.MINOR?e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.ORANGE,crispen:!0,dash:h})):(null===(r=this.pv)||void 0===r?void 0:r.severity)===ft.INVALID&&e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.PINK,crispen:!0}))}}drawOverlay(t){}drawSelection(t){t.lineWidth=1,t.strokeStyle="black",t.strokeRect(this.holderX-.5,this.holderY-.5,this.holderWidth+1,this.holderHeight+1),t.fillStyle="black";let e=2;t.fillRect(this.holderX-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight-e,e+e,e+e),t.strokeStyle="white",e=3,t.strokeRect(this.holderX-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1)}requestRepaint(){this.display.requestRepaint()}closeMenu(){}get bounds(){return{x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight}}get unscaledBounds(){return{x:this.properties.getValue("x"),y:this.properties.getValue("y"),width:this.properties.getValue("width"),height:this.properties.getValue("height")}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,s,r){const o=1*this.scale,h=this.holderY+o/2,n=this.holderX+o/2,a=this.holderY+this.holderHeight-o+o/2,l=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new v(l,a).lineTo(l,h).moveTo(l,a).lineTo(n,a)}),t.strokePath({color:i,path:new v(l-o,a-o).lineTo(l-o,h+o).moveTo(l-o,a-o).lineTo(n+o,a-o)}),t.strokePath({color:s,path:new v(n,h).lineTo(l-o,h).moveTo(n,h).lineTo(n,a-o)}),t.strokePath({color:r,path:new v(n+o,h+o).lineTo(l-o-o,h+o).moveTo(n+o,h+o).lineTo(n+o,a-o-o)})}drawDashedBorder(t,e){const i=n(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new v(i.x,i.y).lineTo(i.x+i.width,i.y).lineTo(i.x+i.width,i.y+i.height).lineTo(i.x,i.y+i.height).closePath()})}executeAction(t){const e=this.actions.getAction(t);if(e)switch(e.type){case"OPEN_DISPLAY":const t={path:e.path,replace:0===e.mode};this.display.fireEvent("opendisplay",t);break;case"EXECUTE_JAVASCRIPT":if(e.embedded){new ut(this.display.instance,e.text).run()}else fetch(`${this.display.baseUrl}${e.path}`,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{new ut(this.display.instance,t).run()}))}));break;case"WRITE_PV":if(e.pvName){const t=this.expandMacro(e.pvName);this.display.pvEngine.setValue(new Date,t,e.value)}break;case"PLAY_SOUND":if(e.path){new Audio(`${this.display.baseUrl}${e.path}`).play()}break;case"OPEN_WEBPAGE":e.hyperlink&&(window.location.href=e.hyperlink);break;default:throw new Error(`Unsupported command ${e.type}`)}}expandMacro(t){var e;if(-1===t.indexOf("$"))return t;for(const i of this.properties.all())if(i instanceof D){const s=this.properties.getProperty(i.pvPropertyName);let r="";const o=null==s?void 0:s.value;if(o){const t=this.display.getPV(o);r=null!==(e=null==t?void 0:t.value)&&void 0!==e?e:""}t=(t=t.replace(`$(${i.name})`,r)).replace(`\${${i.name}}`,r)}else t=(t=t.replace(`$(${i.name})`,i.value||"")).replace(`\${${i.name}}`,i.value||"");return this.parent?this.parent.expandContainerMacros(t):t}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===ft.MINOR}isMajorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===ft.MAJOR}get alarm(){var t,e;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===ft.MINOR||(null===(e=this.pv)||void 0===e?void 0:e.severity)===ft.MAJOR}get alarmSensitiveBackgroundColor(){if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.foregroundColor}get scale(){let t=this.display.scale,e=this.parent;for(;e;)t*=e.relativeScale,e=e.parent;return t}get value(){return this._value}set value(t){this._value=t,this.requestRepaint()}addPropertyListener(t,e){this.properties.getProperty(t).addListener(e)}removePropertyListener(t,e){this.properties.getProperty(t).removeListener(e)}toDataURL(t="image/png",e){const i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue("wuid")}get name(){return this.properties.getValue("name")}get holderX(){return this.scale*this.properties.getValue("x")}get holderY(){return this.scale*this.properties.getValue("y")}get holderWidth(){return this.scale*this.properties.getValue("width")}get holderHeight(){return this.scale*this.properties.getValue("height")}get borderAlarmSensitive(){return this.properties.getValue("border_alarm_sensitive")}get backgroundAlarmSensitive(){return this.properties.getValue("backcolor_alarm_sensitive")}get foregroundAlarmSensitive(){return this.properties.getValue("forecolor_alarm_sensitive")}get pvName(){return this.properties.getValue("pv_name",!0)}get pvValue(){return this.properties.getValue("pv_value",!0)}get borderColor(){return this.properties.getValue("border_color")}get borderStyle(){return this.properties.getValue("border_style")}get borderWidth(){return this.scale*this.properties.getValue("border_width")}get backgroundColor(){return this.properties.getValue("background_color")}get enabled(){return this.properties.getValue("enabled")}get foregroundColor(){return this.properties.getValue("foreground_color")}get tooltip(){const t=this.properties.getProperty("tooltip");if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue("transparent")}get visible(){return this.properties.getValue("visible")}get actions(){return this.properties.getValue("actions")}get scripts(){return this.properties.getValue("scripts")}get rules(){return this.properties.getValue("rules")}get scaleOptions(){return this.properties.getValue("scale_options")}get widgetType(){return this.properties.getValue("widget_type",!0)}get text(){if(this.display.editMode){return(this.properties.getProperty("text").rawValue||"").split(" ").join(" ")}return this.properties.getValue("text").split(" ").join(" ")}init(){}hide(){}destroy(){}}class $t extends Dt{constructor(t,e){super(t,e),this.pushed=!1,this.imageLoaded=!1,this.properties.add(new U("font")),this.properties.add(new j("toggle_button")),this.properties.add(new $("push_action_index")),this.properties.add(new $("release_action_index")),this.properties.add(new N("image"))}init(){this.image&&(this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()},this.imageElement.src=`${this.display.baseUrl}${this.image}`),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.pushed=!1,this.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,this.requestRepaint())},click:()=>{this.executeAction(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(e){const i=e.ctx,{scale:s}=this;e.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const r=1*s,o=this.holderY+r/2,h=this.holderX+r/2,n=this.holderY+this.holderHeight-r+r/2,a=this.holderX+this.holderWidth-r+r/2;e.strokePath({lineWidth:r,color:this.pushed?t.BUTTON_LIGHTEST:t.BLACK,path:new v(a,n).lineTo(a,o).moveTo(a,n).lineTo(h,n)}),e.strokePath({lineWidth:r,color:this.pushed?this.backgroundColor:t.BUTTON_DARKER,path:new v(a-r,n-r).lineTo(a-r,o+r).moveTo(a-r,n-r).lineTo(h+r,n-r)}),e.strokePath({lineWidth:r,color:this.pushed?t.BLACK:t.BUTTON_LIGHTEST,path:new v(h,o).lineTo(a-r,o).moveTo(h,o).lineTo(h,n-r)}),e.strokePath({lineWidth:r,color:this.pushed?t.BUTTON_DARKER:this.backgroundColor,path:new v(h+r,o+r).lineTo(a-r-r,o+r).moveTo(h+r,o+r).lineTo(h+r,n-r-r)});const l=this.text.split("\n");let d,c;if(i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),this.imageElement&&this.imageLoaded){const t=i.measureText(l[0]).width,e=this.font.height,r=this.imageElement.naturalHeight*s,o=this.imageElement.naturalWidth*s,h=(this.height-r)/e,n=5*s;if((this.width-o)/t>h){i.textBaseline="middle",i.textAlign="left",d=this.x+(this.width-t)/2+n,c=this.y+this.height/2;const e=this.x+(this.width-t)/2-o,s=this.y+(this.height-r)/2;i.drawImage(this.imageElement,e,s,o,r)}else{i.textAlign="center",i.textBaseline="top";const t=e+r;d=this.x+this.width/2,c=this.y+(this.height-t)/2+r;const s=this.x+(this.width-o)/2,h=this.y+(this.height-t)/2;i.drawImage(this.imageElement,s,h,o,r)}}else i.textBaseline="middle",i.textAlign="center",d=this.x+this.width/2,c=this.y+this.height/2;this.pushed&&(d+=1*s,c+=1*s),i.fillText(l[0],d,c)}get font(){return this.properties.getValue("font").scale(this.scale)}get image(){return this.properties.getValue("image")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("release_action_index")}get backgroundColor(){const e=this.properties.getProperty("background_color");return e&&e.value!==t.TRANSPARENT?e.value:t.BUTTON}}class Gt extends Dt{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new $("bit")),this.properties.add(new $("data_type")),this.properties.add(new j("square_button")),this.properties.add(new j("show_led")),this.properties.add(new j("effect_3d")),this.properties.add(new z("on_color")),this.properties.add(new N("on_label")),this.properties.add(new N("on_state")),this.properties.add(new z("off_color")),this.properties.add(new N("off_label")),this.properties.add(new N("off_state")),this.properties.add(new U("font")),this.properties.add(new j("toggle_button")),this.properties.add(new $("push_action_index")),this.properties.add(new $("released_action_index")),this.properties.add(new j("show_boolean_label"))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:e?this.onLabel:this.offLabel})}drawSquare(e,i){e.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:t.DARK_GRAY});e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=2*this.scale,r=i?t.DARK_GRAY:t.WHITE,o=i?t.WHITE:t.DARK_GRAY;this.effect3d&&(e.fillPath({color:r,path:new v(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+s,this.y+this.height-s).lineTo(this.x+s,this.y+s).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width,this.y).closePath()}),e.fillPath({color:o,path:new v(this.x,this.y+this.height).lineTo(this.x+this.width,this.y+this.height).lineTo(this.x+this.width,this.y).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width-s,this.y+this.height-s).lineTo(this.x+s,this.y+this.height-s).closePath()}));let h=this.backgroundColor;this.hovered&&(h=this.backgroundColor.mixWith(t.WHITE,.5)),e.fillRect({x:this.x+s,y:this.y+s,width:this.width-s-s,height:this.height-s-s,color:h})}drawEllipse(e,i){const{scale:s}=this;if(this.effect3d){const r=this.width/2,o=this.height/2,h=Math.sqrt(r*r+o*o),n=this.x+r+(o-r-h)/2-1*s,a=this.y+o-(o-r+h)/2-1*s,l=this.x+r+(o-r+h)/2+5*s,d=this.y+o-(o-r-h)/2+5*s,c=e.createLinearGradient(n,a,l,d);i?(c.addColorStop(0,t.DARK_GRAY.toString()),c.addColorStop(1,t.WHITE.toString())):(c.addColorStop(0,t.WHITE.toString()),c.addColorStop(1,t.DARK_GRAY.toString())),e.ctx.fillStyle=c}else e.ctx.fillStyle=i?t.WHITE.toString():t.DARK_GRAY.toString();const r=this.x+this.width/2,o=this.y+this.height/2,h=this.width/2,n=this.height/2;e.ctx.beginPath(),e.ctx.ellipse(r,o,h,n,0,0,2*Math.PI),e.ctx.fill();e.addHitRegion(this.areaRegion).addEllipse(r,o,h,n,0,0,2*Math.PI),this.hovered?e.ctx.fillStyle=this.backgroundColor.mixWith(t.WHITE,.5).toString():e.ctx.fillStyle=this.backgroundColor.toString(),e.ctx.beginPath(),e.ctx.ellipse(r,o,h-2*s,n-2*s,0,0,2*Math.PI),e.ctx.fill()}drawHorizontal(t,e){const{scale:i}=this;if(this.showLed){let s;this.squareButton?(s=Math.floor(.3*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-2*i)):(s=Math.floor(.25*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-8*i));const r={x:Math.floor(this.x+.79999*this.width-s/2),y:Math.floor(this.y+this.height/2-s/2),width:s,height:s},o=r.x+r.width/2,h=r.y+r.height/2,n=r.width/2,a=r.height/2,l=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:h,rx:n,ry:a,color:l}),this.effect3d){const e=t.createLinearGradient(r.x,r.y,r.x+r.width,r.y+r.height);e.addColorStop(0,"white"),e.addColorStop(1,l.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,h,n,a,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}drawVertical(e,i){const{scale:s}=this;if(this.showLed){let r;this.squareButton?(r=Math.floor(.3*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-2*s)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*s));const o={x:Math.floor(this.x+this.width/2-r/2),y:Math.floor(this.y+(1-.79999)*this.height-r/2),width:r,height:r},h=i?this.onColor:this.offColor,n=o.x+o.width/2,a=o.y+o.height/2,l=o.width/2,d=o.height/2;if(e.fillEllipse({cx:n,cy:a,rx:l,ry:d,color:h}),this.effect3d){const i=e.createLinearGradient(o.x,o.y,o.x+o.width,o.y+o.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.ctx.beginPath(),e.ctx.ellipse(n,a,l,d,0,0,2*Math.PI),e.ctx.fillStyle=i,e.ctx.fill()}}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get squareButton(){return this.properties.getValue("square_button")}get showLed(){return this.properties.getValue("show_led")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get effect3d(){return this.properties.getValue("effect_3d")}get onColor(){return this.properties.getValue("on_color")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offColor(){return this.properties.getValue("off_color")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}get font(){return this.properties.getValue("font").scale(this.scale)}}class jt extends Dt{constructor(t,e){super(t,e),this.manualToggleState=!1,this.properties.add(new $("bit")),this.properties.add(new $("data_type")),this.properties.add(new j("effect_3d")),this.properties.add(new z("on_color")),this.properties.add(new N("on_label")),this.properties.add(new N("on_state")),this.properties.add(new z("off_color")),this.properties.add(new N("off_label")),this.properties.add(new N("off_state")),this.properties.add(new $("push_action_index")),this.properties.add(new $("released_action_index")),this.properties.add(new j("toggle_button"))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,s=this.height;s>i/2?s=Math.floor(this.width/2):i=Math.floor(2*this.height);const r={x:Math.floor(63/218*i),y:0,width:s/2,height:s/2};this.drawPedestal(t,r,e);const o=Math.floor(35/218*i),h=Math.floor(45/105*s),n=Math.floor(43/218*i),a=Math.floor(35/105*s),l=Math.floor(1/7*r.width);if(e){const e={x:2*r.x+r.width-o,y:r.height/2-h/2,width:o,height:h},i={x:r.x+r.width/2-n/2+l,y:r.y+r.height/2-a/2,width:n,height:a};this.drawHorizontalBar(t,i,e,!0)}else{const e={x:0,y:r.height/2-h/2,width:o,height:h},i={x:r.x+r.width/2-n/2-l,y:r.y+r.height/2-a/2,width:n,height:a};this.drawHorizontalBar(t,i,e,!1)}}drawVertical(t,e){let i=this.width,s=this.height;i>s/2?i=Math.floor(this.height/2):s=Math.floor(2*this.width);const r={x:0,y:Math.floor(63/218*s),width:i/2,height:i/2};this.drawPedestal(t,r,e);const o=Math.floor(45/105*i),h=Math.floor(35/218*s),n=Math.floor(35/105*i),a=Math.floor(43/218*s);if(e){const e={x:r.width/2-o/2,y:0,width:o,height:h},i={x:r.x+r.width/2-n/2,y:r.y+r.height/2-a/2,width:n,height:a};i.y-=Math.floor(1/7*r.height),this.drawVerticalBar(t,i,e,!0)}else{const e=r.y+r.height/2+a/2+2*this.scale,i={x:r.width/2-o/2,y:r.y+r.height/2-a/2+e-h,width:o,height:h},s={x:r.x+r.width/2-n/2,y:r.y+r.height/2-a/2,width:n,height:a};s.y+=Math.floor(1/7*r.height),this.drawVerticalBar(t,s,i,!1)}}drawPedestal(e,i,s){let r=this.x+i.x+i.width/2,o=this.y+i.y+i.height/2,h=i.width/2,n=i.height/2;if(e.ctx.fillStyle=this.effect3d?t.WHITE.toString():t.GRAY.toString(),e.ctx.beginPath(),e.ctx.ellipse(r,o,h,n,0,0,2*Math.PI),e.ctx.fill(),this.effect3d){const t=e.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y+i.height);s?(t.addColorStop(0,`rgba(255,255,255,${10/255})`),t.addColorStop(1,`rgba(0,0,0,${100/255})`)):(t.addColorStop(0,"rgba(0,0,0,0)"),t.addColorStop(1,`rgba(0,0,0,${150/255})`)),e.ctx.fillStyle=t,e.ctx.fill()}}drawHorizontalBar(t,e,i,s){let r=(s?0:10)/255,o=(s?150:220)/255;const h=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);h.addColorStop(0,`rgba(0,0,0,${r})`),h.addColorStop(1,`rgba(0,0,0,${o})`);const n=t.addHitRegion(this.shaftRegion);let a=this.x+e.x+e.width/2,l=this.y+e.y+e.height/2,d=e.width/2,c=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),n.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=h,t.ctx.fill());const p=[Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y),Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y+i.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y+e.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y)];if(t.ctx.beginPath(),t.ctx.moveTo(p[0],p[1]),t.ctx.lineTo(p[2],p[3]),t.ctx.lineTo(p[4],p[5]),t.ctx.lineTo(p[6],p[7]),t.ctx.closePath(),n.addPath(new v(p[0],p[1]).lineTo(p[2],p[3]).lineTo(p[4],p[5]).lineTo(p[6],p[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=h,t.ctx.fill()),a=this.x+i.x+i.width/2,l=this.y+i.y+i.height/2,d=i.width/2,c=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),n.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const{scale:e}=this,s=Math.sqrt(d*d+c*c),h=c-d,n=this.x+i.x+d+(h-s)/2-1*e,a=this.x+i.y+c-(h+s)/2-1*e,l=this.x+i.x+d+(h+s)/2+5*e,p=this.x+i.y+c-(h-s)/2+5*e,g=t.createLinearGradient(n,a,l,p);g.addColorStop(0,`rgba(0,0,0,${r})`),g.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=g,t.ctx.fill()}}drawVerticalBar(t,e,i,s){const r=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);r.addColorStop(0,`rgba(0,0,0,${10/255})`),r.addColorStop(1,`rgba(0,0,0,${s?210/255:160/255})`);const o=t.addHitRegion(this.shaftRegion);let h=this.x+e.x+e.width/2,n=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(h,n,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(h,n,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill());const a=[Math.round(this.x+i.x),Math.round(this.y+i.y+i.height/2),Math.round(this.x+i.x+i.width),Math.round(this.y+i.y+i.height/2),Math.round(this.x+e.x+e.width),Math.round(this.y+e.y+e.height/2),Math.round(this.x+e.x),Math.round(this.y+e.y+e.height/2)];t.ctx.beginPath(),t.ctx.moveTo(a[0],a[1]),t.ctx.lineTo(a[2],a[3]),t.ctx.lineTo(a[4],a[5]),t.ctx.lineTo(a[6],a[7]),t.ctx.closePath(),o.addPath(new v(a[0],a[1]).lineTo(a[2],a[3]).lineTo(a[4],a[5]).lineTo(a[6],a[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill()),h=this.x+i.x+i.width/2,n=this.y+i.y+i.height/2;const l=i.width/2,d=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(h,n,l,d,0,0,2*Math.PI),o.addEllipse(h,n,l,d,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const e=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);e.addColorStop(0,`rgba(0,0,0,${(s?5:10)/255})`),e.addColorStop(1,`rgba(0,0,0,${(s?180:160)/255})`),t.ctx.fillStyle=e,t.ctx.fill()}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get effect3d(){return this.properties.getValue("effect_3d")}get onColor(){return this.properties.getValue("on_color")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offColor(){return this.properties.getValue("off_color")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}}const zt=new t(130,130,130),Ut=new t(94,151,230);class qt extends Dt{constructor(e,i){super(e,i),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new $("bit")),this.properties.add(new j("enabled")),this.properties.add(new U("font")),this.properties.add(new N("label")),this.properties.add(new z("selected_color",new t(64,64,64)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseOut:()=>{this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:this.manualToggleState}draw(e){e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const i=this.booleanValue,{boxSize:s,gap:r,scale:o}=this;let h=this.backgroundColor;this.hovered&&(h=h.mixWith(Ut,.7));const n={x:this.x,y:this.y+this.height/2-s/2,width:s,height:s},a=e.createLinearGradient(n.x,n.y+1*o,n.x,n.y+n.height);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillRect(Object.assign(Object.assign({},n),{rx:2*o,ry:2*o,gradient:a})),e.strokeRect({x:n.x+.5*o,y:n.y+.5*o,width:n.width-1*o,height:n.height-1*o,rx:2*o,ry:2*o,color:zt}),i&&e.strokePath({lineWidth:3*o,color:this.selectedColor,path:new v(n.x+3*o,n.y+Math.floor(.45*s)).lineTo(n.x+Math.floor(.45*s),n.y+3*s/4-1*o).lineTo(n.x+s-2*o,n.y+3*o)}),this.enabled?e.fillText({x:n.x+n.width+r,y:n.y+n.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(e.fillText({x:n.x+n.width+r+1*o,y:n.y+n.height/2+1*o,align:"left",baseline:"middle",color:t.BUTTON_LIGHTEST,font:this.font,text:this.label}),e.fillText({x:n.x+n.width+r,y:n.y+n.height/2,align:"left",baseline:"middle",color:t.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return 16*this.scale}get gap(){return 4*this.scale}get bit(){return this.properties.getValue("bit")}get enabled(){return this.properties.getValue("enabled")}get selectedColor(){return this.properties.getValue("selected_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get label(){return this.properties.getValue("label")}}class Yt extends Dt{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new j("enabled")),this.properties.add(new U("font")),this.properties.add(new j("horizontal")),this.properties.add(new J("items",[])),this.properties.add(new j("items_from_pv")),this.properties.add(new z("selected_color"))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",mouseDown:()=>{this.pushedItem=t,this.requestRepaint()},mouseOut:()=>{this.pushedItem=void 0,this.requestRepaint()},mouseUp:()=>{this.pushedItem=void 0,this.requestRepaint()},click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:Math.round(this.area.x),y:Math.round(i),width:Math.round(this.area.width),height:Math.round(e)};i+=e,this.drawButton(t,r,s)}}drawButton(e,i,s){var r;const o=(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s],h=o||s===this.pushedItem;e.fillRect(Object.assign(Object.assign({},i),{color:o?this.selectedColor:this.backgroundColor}));e.addHitRegion(this.itemRegions[s]).addRect(i.x,i.y,i.width,i.height);const n=1*this.scale,a=i.y+n/2,l=i.x+n/2,d=i.y+i.height-n+n/2,c=i.x+i.width-n+n/2;e.strokePath({lineWidth:n,color:h?t.BUTTON_LIGHTEST:t.BLACK,path:new v(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d)}),e.strokePath({lineWidth:n,color:h?this.backgroundColor:t.BUTTON_DARKER,path:new v(c-n,d-n).lineTo(c-n,a+n).moveTo(c-n,d-n).lineTo(l+n,d-n)}),e.strokePath({lineWidth:n,color:h?t.BLACK:t.BUTTON_LIGHTEST,path:new v(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,d-n)}),e.strokePath({lineWidth:n,color:h?t.BUTTON_DARKER:this.backgroundColor,path:new v(l+n,a+n).lineTo(c-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,d-n-n)}),e.fillText({x:i.x+i.width/2,y:i.y+i.height/2,text:this.items[s],align:"center",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}get selectedColor(){return this.properties.getValue("selected_color")}}const Xt=new t(240,240,240);class Kt extends Dt{constructor(t,e){super(t,e),this.listVisible=!1,this.itemRegions=[],this.properties.add(new j("enabled")),this.properties.add(new U("font")),this.properties.add(new J("items",[])),this.properties.add(new j("items_from_pv"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t=this.listVisible;this.display.closeMenu(),this.items.length&&!t&&(this.listVisible=!0,this.hoveredItem=0,this.requestRepaint())},tooltip:()=>this.tooltip};for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,click:()=>{this.writeValue(this.items[t]),this.listVisible=!1,this.hoveredItem=void 0,this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){var e,i;let s=l(this.bounds,2*this.scale);t.fillRect(Object.assign(Object.assign({},s),{color:this.backgroundColor})),t.strokeRect(Object.assign(Object.assign({},s),{color:Xt,crispen:!0}));t.addHitRegion(this.areaRegion).addRect(s.x,s.y,s.width,s.height),(null===(e=this.pv)||void 0===e?void 0:e.value)&&-1!==this.items.indexOf(this.pv.value)&&t.fillText({x:5*this.scale+s.x,y:s.y+s.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:null===(i=this.pv)||void 0===i?void 0:i.value});const{selectorWidth:r}=this,o=Math.min(s.height,r/2),h={x:s.x+s.width-r-5*this.scale+r/2,y:s.y+(s.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new v(h.x,h.y).lineTo(h.x-o,h.y-o).lineTo(h.x+o,h.y-o).closePath()})}closeMenu(){this.listVisible=!1,this.requestRepaint()}drawOverlay(e){if(!this.listVisible||!this.items.length)return;let i=0,s=0;for(const t of this.items){const r=e.measureText(t,this.font);i=Math.max(i,r.width),s=Math.max(s,r.height)}const{scale:r}=this,o=5*r,h=o+s+o,n={x:this.bounds.x+5*r,y:this.bounds.y+this.bounds.height-5*r,width:o+i+o,height:h*this.items.length+2*r+2*r};e.fillRect(Object.assign(Object.assign({},n),{color:this.backgroundColor}));for(let i=0;i<this.items.length;i++){const s={x:n.x,y:n.y+2*r+i*h,width:n.width,height:h};e.addHitRegion(this.itemRegions[i]).addRect(s.x,s.y,s.width,s.height),i===this.hoveredItem&&e.fillRect(Object.assign(Object.assign({},s),{color:t.LIGHT_BLUE}))}e.strokeRect(Object.assign(Object.assign({},n),{color:Xt,lineWidth:1*r,crispen:!0}));for(let t=0;t<this.items.length;t++)e.fillText({x:n.x+o,y:n.y+2*r+t*h+h/2,font:this.font,color:this.foregroundColor,align:"left",baseline:"middle",text:this.items[t]})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get selectorWidth(){return 8*this.scale}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}}class Zt extends Dt{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.manualToggleState=!1,this.properties.add(new $("bit")),this.properties.add(new $("data_type")),this.properties.add(new j("effect_3d")),this.properties.add(new N("on_image")),this.properties.add(new N("on_label")),this.properties.add(new N("on_state")),this.properties.add(new N("off_image")),this.properties.add(new N("off_label")),this.properties.add(new N("off_state")),this.properties.add(new U("font")),this.properties.add(new j("toggle_button")),this.properties.add(new $("push_action_index")),this.properties.add(new $("released_action_index")),this.properties.add(new j("show_boolean_label"))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=`${this.display.baseUrl}${this.onImage}`),this.offImage&&(this.offImageElement.src=`${this.display.baseUrl}${this.offImage}`),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=l(e,2*this.scale,2*this.scale));const i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height);t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get effect3d(){return this.properties.getValue("effect_3d")}get onImage(){return this.properties.getValue("on_image")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offImage(){return this.properties.getValue("off_image")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}get font(){return this.properties.getValue("font").scale(this.scale)}}class Jt extends $t{}const Qt=new t(120,120,120),te=new t(94,151,230);class ee extends Dt{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new j("enabled")),this.properties.add(new U("font")),this.properties.add(new j("horizontal")),this.properties.add(new J("items",[])),this.properties.add(new j("items_from_pv")),this.properties.add(new z("selected_color"))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,r,s)}}drawRadio(e,i,s){var r;const{radioRadius:o,dotRadius:h,gap:n}=this;let a=this.backgroundColor;s===this.hoveredItem&&(a=a.mixWith(te,.7));const l=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);l.addColorStop(0,t.WHITE.toString()),l.addColorStop(1,a.toString()),e.fillEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:o,ry:o,gradient:l});const d=1*this.scale;e.strokeEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:o,ry:o,color:Qt,lineWidth:d}),(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s]&&e.fillEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:h+d/2,ry:h+d/2,color:this.selectedColor});e.addHitRegion(this.itemRegions[s]).addRect(i.x,i.y,i.width,i.height),e.fillText({x:i.x+o+o+n,y:i.y+i.height/2,text:this.items[s],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get radioRadius(){return 7*this.scale}get dotRadius(){return 2*this.scale}get gap(){return 4*this.scale}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}get selectedColor(){return this.properties.getValue("selected_color")}}const ie=new t(243,243,243),se=new t(232,232,231);class re extends Dt{constructor(t,e){super(t,e),this.decreasePressed=!1,this.increasePressed=!1,this.pageDecreasePressed=!1,this.pageIncreasePressed=!1,this.properties.add(new j("enabled")),this.properties.add(new j("horizontal")),this.properties.add(new j("show_value_tip")),this.properties.add(new U("font")),this.properties.add(new G("maximum")),this.properties.add(new G("minimum")),this.properties.add(new G("step_increment")),this.properties.add(new G("page_increment")),this.properties.add(new G("bar_length"))}init(){this.decreaseRegion={id:`${this.wuid}-decrease`,mouseDown:()=>{this.decreasePressed=!0,this.stepDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.increaseRegion={id:`${this.wuid}-increase`,mouseDown:()=>{this.increasePressed=!0,this.stepIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{this.grabStartValue=this.getCoercedValue()},grab:t=>{const e=this.horizontal?t.dx:t.dy,i=(this.maximum-this.minimum)*e/this.dragRange;this.setCoercedValue(this.grabStartValue+i),this.requestRepaint()},tooltip:()=>this.tooltip},this.pageDecreaseRegion={id:`${this.wuid}-page-decrease`,mouseDown:()=>{this.pageDecreasePressed=!0,this.pageDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.pageIncreaseRegion={id:`${this.wuid}-page-increase`,mouseDown:()=>{this.pageIncreasePressed=!0,this.pageIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip}}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(e){const{scale:i}=this,s=l(this.bounds,2*i);e.fillRect(Object.assign(Object.assign({},s),{color:ie}));const r=Math.min(s.height,s.width/2);this.drawLeftButton(e,{x:s.x,y:s.y,width:r,height:s.height}),this.drawRightButton(e,{x:s.x+s.width-r,y:s.y,width:r,height:s.height});const o=this.barLength,h=this.maximum+o,n=this.minimum,a=h-n,d=a-o,c=s.width-r-r,p=Math.floor(Math.max(6*i,c*o/a));this.dragRange=c-p;const g=this.getCoercedValue(),u=Math.floor((c-p)*(g-n)/d),m=c-u-p,f={x:s.x+r+u,y:s.y,width:p,height:s.height};e.fillRect(Object.assign(Object.assign({},f),{color:se})),this.drawRaisedButtonBorder(e,f);e.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x+r,y:s.y,width:u,height:s.height};e.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&e.fillRect(Object.assign(Object.assign({},x),{color:t.BLACK}));const w={x:s.x+r+u+p,y:s.y,width:m,height:s.height};e.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&e.fillRect(Object.assign(Object.assign({},w),{color:t.BLACK}))}drawVertical(e){const{scale:i}=this,s=l(this.bounds,i);e.fillRect(Object.assign(Object.assign({},s),{color:ie}));const r=Math.min(s.width,s.height/2);this.drawUpButton(e,{x:s.x,y:s.y,width:s.width,height:r}),this.drawDownButton(e,{x:s.x,y:s.y+s.height-r,width:s.width,height:r});const o=this.barLength,h=this.maximum+o,n=this.minimum,a=h-n,d=a-o,c=s.height-r-r,p=Math.floor(Math.max(6*i,c*o/a));this.dragRange=c-p;const g=this.getCoercedValue(),u=Math.floor((c-p)*(g-n)/d),m=c-u-p,f={x:s.x,y:s.y+r+u,width:s.width,height:p};e.fillRect(Object.assign(Object.assign({},f),{color:se})),this.drawRaisedButtonBorder(e,f);e.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x,y:s.y+r,width:s.width,height:u};e.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&e.fillRect(Object.assign(Object.assign({},x),{color:t.BLACK}));const w={x:s.x,y:s.y+r+u+p,width:s.width,height:m};e.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&e.fillRect(Object.assign(Object.assign({},w),{color:t.BLACK}))}drawLeftButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:se})),this.decreasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.decreaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x,y:s.y+s.height/2};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x+r,o.y-r).lineTo(o.x+r,o.y+r).closePath()})}drawRightButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:se})),this.increasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.increaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x+r,y:s.y+s.height/2};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x-r,o.y+r).closePath()})}drawUpButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:se})),this.decreasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.decreaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y+r).lineTo(o.x+r,o.y+r).closePath()})}drawDownButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:se})),this.increasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.increaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y+r};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x+r,o.y-r).closePath()})}drawRaisedButtonBorder(e,i){this.drawButtonBorder(e,i,t.BUTTON_DARKEST,t.BUTTON_DARKER,t.BUTTON,t.BUTTON_LIGHTEST)}drawPressedButtonBorder(e,i){this.drawButtonBorder(e,i,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKEST,t.BUTTON_DARKER)}drawButtonBorder(t,e,i,s,r,o){const h=1*this.scale,n=e.y+h/2,a=e.x+h/2,l=e.y+e.height-h+h/2,d=e.x+e.width-h+h/2;t.strokePath({color:i,path:new v(d,l).lineTo(d,n).moveTo(d,l).lineTo(a,l)}),t.strokePath({color:s,path:new v(d-h,l-h).lineTo(d-h,n+h).moveTo(d-h,l-h).lineTo(a+h,l-h)}),t.strokePath({color:r,path:new v(a,n).lineTo(d-h,n).moveTo(a,n).lineTo(a,l-h)}),t.strokePath({color:o,path:new v(a+h,n+h).lineTo(d-h-h,n+h).moveTo(a+h,n+h).lineTo(a+h,l-h-h)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepIncreaseRepeatedly()),150)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepDecreaseRepeatedly()),150)}stepIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.stepIncrement)}stepDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageIncreaseRepeatedly()),150)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageDecreaseRepeatedly()),150)}pageIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.pageIncrement)}pageDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.pageIncrement)}setCoercedValue(t){this.pv&&this.pv.writable&&(t=t<this.minimum?this.minimum:t>this.maximum?this.maximum:t,this.display.pvEngine.setValue(new Date,this.pv.name,t))}getCoercedValue(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;return i<this.minimum?this.minimum:i>this.maximum?this.maximum:i}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue("enabled")}get horizontal(){return this.properties.getValue("horizontal")}get showValueTip(){return this.properties.getValue("show_value_tip")}get font(){return this.properties.getValue("font").scale(this.scale)}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get stepIncrement(){return this.properties.getValue("step_increment")}get pageIncrement(){return this.properties.getValue("page_increment")}get barLength(){return this.properties.getValue("bar_length")}}class oe extends Dt{constructor(t,e){super(t,e),this.properties.add(new U("font")),this.properties.add(new $("format_type")),this.properties.add(new $("horizontal_alignment")),this.properties.add(new $("precision")),this.properties.add(new j("precision_from_pv")),this.properties.add(new $("vertical_alignment",1))}draw(t){const e=t.ctx;this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const i=document.createElement("canvas");i.width=this.area.width,i.height=this.area.height;const s=i.getContext("2d");s.fillStyle=this.alarmSensitiveForegroundColor.toString(),s.font=this.font.getFontString();let r=this.x;0===this.horizAlignment?s.textAlign="start":1===this.horizAlignment?(r+=this.width/2,s.textAlign="center"):2===this.horizAlignment&&(r+=this.width,s.textAlign="end");let o=this.y;0===this.vertAlignment?s.textBaseline="top":1===this.vertAlignment?(o+=this.height/2,s.textBaseline="middle"):2===this.vertAlignment&&(o+=this.height,s.textBaseline="bottom");let h=this.text;if(this.pv&&void 0!==this.pv.value){const t=this.precisionFromPV?this.pv.precision:this.precision;h=this.pv.formatValue(this.formatType,t)}s.fillText(h,r-this.area.x,o-this.area.y),e.drawImage(i,this.area.x,this.area.y)}get font(){return this.properties.getValue("font").scale(this.scale)}get formatType(){return this.properties.getValue("format_type")}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get precision(){return this.properties.getValue("precision")}get precisionFromPV(){return this.properties.getValue("precision_from_pv")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}}class he extends Dt{constructor(t,e){super(t,e),this.properties.add(new $("alpha",255)),this.properties.add(new $("line_width")),this.properties.add(new $("start_angle")),this.properties.add(new $("total_angle")),this.properties.add(new j("fill")),this.properties.add(new $("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2,o=-g(this.startAngle),h=-g(this.totalAngle+this.startAngle);if(this.fill&&(t.ctx.fillStyle=this.alarmSensitiveBackgroundColor.toString(),t.ctx.beginPath(),t.ctx.moveTo(e,i),t.ctx.ellipse(e,i,s,r,0,o,h,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&0!==this.totalAngle){let n;const{scale:a}=this;0===this.lineStyle?n=[]:1===this.lineStyle?n=[6*a,2*a]:2===this.lineStyle?n=[2*a,2*a]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,startAngle:o,endAngle:h,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:n})}}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get lineStyle(){return this.properties.getValue("line_style")}get startAngle(){return this.properties.getValue("start_angle")}get totalAngle(){return this.properties.getValue("total_angle")}get fill(){return this.properties.getValue("fill")}}class ne extends Dt{constructor(t,e){super(t,e),this.properties.add(new $("alpha",255)),this.properties.add(new z("bg_gradient_color")),this.properties.add(new z("fg_gradient_color")),this.properties.add(new j("gradient")),this.properties.add(new $("line_width")),this.properties.add(new G("fill_level")),this.properties.add(new j("horizontal_fill")),this.properties.add(new z("line_color")),this.properties.add(new $("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2;if(!this.transparent){const o=this.alarmSensitiveBackgroundColor;if(this.gradient){const h=this.horizontalFill?this.x:this.x+this.width,n=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,h,n);a.addColorStop(0,this.backgroundGradientStartColor.toString()),a.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:s,ry:r,gradient:a})}else t.fillEllipse({cx:e,cy:i,rx:s,ry:r,color:o})}this.lineWidth&&(0===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth}):1===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`))}drawFill(t){const e=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.x+this.width/2,s=this.y+this.height/2,r=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,h=this.alarmSensitiveForegroundColor;if(this.gradient){const e=this.horizontalFill?this.x:this.x+this.width,n=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,e,n);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,h.toString()),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,gradient:a})}else t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:h});t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class ae extends Dt{constructor(t,e){super(t,e),this.imageLoaded=!1,this.properties.add(new N("image_file")),this.properties.add(new N("no_animation")),this.properties.add(new j("transparency",!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){this.imageLoaded=!1,this.imageElement&&this.imageFile&&(this.currentImageFile=this.imageFile,this.imageElement.src=`${this.display.baseUrl}${this.imageFile}`)}snapshotImage(t){const e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue("transparency")}get imageFile(){return this.properties.getValue("image_file")}get noAnimation(){return this.properties.getValue("no_animation")}}class le extends Dt{constructor(t,e){super(t,e),this.properties.add(new U("font")),this.properties.add(new $("horizontal_alignment")),this.properties.add(new $("vertical_alignment")),this.properties.add(new j("wrap_words"))}draw(t){const e=t.ctx;this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const i=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let s=0;for(const t of i){const i=e.measureText(t).width;s=Math.max(s,i)}let r=this.x;1===this.horizAlignment?r=this.x+(this.width-s)/2:2===this.horizAlignment&&(r=this.x+(this.width-s));const o=i.length*this.font.height+(i.length-1)*this.font.height*.2;let h=this.y;1===this.vertAlignment?h+=(this.height-o)/2:2===this.vertAlignment&&(h+=this.height-o);for(const t of i)e.fillText(t,r,h),h+=1.2*this.font.height}wrapText(t,e,i){let s=[];for(const r of e.split("\n"))s=s.concat(this.wrapLine(t,r,i));return s}wrapLine(t,e,i){const s=[];let r,o,h,n=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(r=e.substr(0,o),o!==e.length)for(h=0;-1!==r.indexOf(" ",h);h=r.indexOf(" ",h)+1);s.push(r.substr(0,h||r.length)),n=Math.max(n,t.measureText(s[s.length-1],this.font).width),e=e.substr(s[s.length-1].length,e.length)}return s}get font(){return this.properties.getValue("font").scale(this.scale)}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}get wrapWords(){return this.properties.getValue("wrap_words")}}class de extends Dt{constructor(t,e){super(t,e),this.properties.add(new $("alpha",255)),this.properties.add(new $("line_width")),this.properties.add(new G("fill_level")),this.properties.add(new j("horizontal_fill")),this.properties.add(new z("line_color")),this.properties.add(new $("line_style")),this.properties.add(new Y("points",[]))}init(){this.addPropertyListener("x",((t,e)=>{const i=p(this.properties.getValue("points"),t-e,0);this.properties.setValue("points",i),this.requestRepaint()})),this.addPropertyListener("y",((t,e)=>{const i=p(this.properties.getValue("points"),0,t-e);this.properties.setValue("points",i),this.requestRepaint()}))}draw(t){const{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;const i=v.fromPoints(this.points).closePath();if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:e})}this.lineWidth&&(0===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):2===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor,dash:[6*e,2*e]}):console.warn(`Unsupported polygon line style ${this.lineStyle}`)),this.fillLevel&&this.drawFill(t,i),t.ctx.globalAlpha=1}drawFill(t,e){let i=this.y,s=this.width,r=this.height;this.horizontalFill?s*=this.fillLevel/100:(r*=this.fillLevel/100,i+=r),t.ctx.save();let o=this.x-this.lineWidth/2,h=i-this.lineWidth/2,n=s+this.lineWidth,a=r+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,h,n,a),t.ctx.clip();const l=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:l}),t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get points(){return x(this.properties.getValue("points"),this.scale)}}class ce extends Dt{constructor(t,e){super(t,e),this.properties.add(new $("alpha",255)),this.properties.add(new $("line_width")),this.properties.add(new G("fill_level")),this.properties.add(new j("horizontal_fill")),this.properties.add(new Y("points",[])),this.properties.add(new $("arrow_length")),this.properties.add(new j("fill_arrow")),this.properties.add(new $("arrows"))}draw(t){const e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,s=this.height;this.horizontalFill?i*=this.fillLevel/100:(s*=this.fillLevel/100,e+=s),t.save();let r=this.x-this.lineWidth/2,o=e-this.lineWidth/2,h=i+this.lineWidth,n=s+this.lineWidth;t.beginPath(),t.rect(r,o,h,n),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let e=0;e<this.points.length;e++)0===e?t.moveTo(this.points[e].x,this.points[e].y):t.lineTo(this.points[e].x,this.points[e].y);if(t.stroke(),this.points.length>=2){const i=this.points[0],s=this.points[this.points.length-1];if(2===this.arrows||3===this.arrows){const i=this.calculateArrowPoints(this.points[this.points.length-2],s);if(i[2]=s,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<i.length;e++)0===e?t.moveTo(i[e].x,i[e].y):t.lineTo(i[e].x,i[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(i[0].x,i[0].y),t.moveTo(s.x,s.y),t.lineTo(i[1].x,i[1].y),t.stroke()}if(1===this.arrows||3===this.arrows){const s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<s.length;e++)0===e?t.moveTo(s[e].x,s[e].y):t.lineTo(s[e].x,s[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){const i=m(e,t),s=Math.PI/10,r=new f(this.arrowLength,i.theta-s),o=new f(this.arrowLength,i.theta+s),h=new f(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[c(r.toPoint(),e.x,e.y),c(o.toPoint(),e.x,e.y),c(h.toPoint(),e.x,e.y)]}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get points(){return x(this.properties.getValue("points"),this.scale)}get arrows(){return this.properties.getValue("arrows")}get fillArrow(){return this.properties.getValue("fill_arrow")}get arrowLength(){return this.properties.getValue("arrow_length")}}class pe extends Dt{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new $("alpha",255)),this.properties.add(new z("bg_gradient_color")),this.properties.add(new z("fg_gradient_color")),this.properties.add(new j("gradient")),this.properties.add(new $("line_width")),this.properties.add(new G("fill_level")),this.properties.add(new j("horizontal_fill")),this.properties.add(new z("line_color")),this.properties.add(new $("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported rectangle line style ${this.lineStyle}`))}drawFill(t){const e=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.alarmSensitiveForegroundColor;if(this.gradient){const s=this.horizontalFill?e.x:e.x+e.width,r=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,s,r);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect(Object.assign(Object.assign({},e),{gradient:o}))}else t.fillRect(Object.assign(Object.assign({},e),{color:i}));t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class ge extends Dt{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new $("alpha",255)),this.properties.add(new z("bg_gradient_color")),this.properties.add(new z("fg_gradient_color")),this.properties.add(new j("gradient")),this.properties.add(new $("line_width")),this.properties.add(new G("fill_level")),this.properties.add(new j("horizontal_fill")),this.properties.add(new z("line_color")),this.properties.add(new $("corner_width")),this.properties.add(new $("corner_height")),this.properties.add(new $("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported RoundedRectangle line style ${this.lineStyle}`))}drawFill(t){const e=this.cornerWidth/2,i=this.cornerHeight/2,s=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const e=s.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(s.x,s.y,e,s.height)}else{const e=s.height*(this.fillLevel/100),i=s.y+s.height-e;t.ctx.beginPath(),t.ctx.rect(s.x,i,s.width,s.height)}t.ctx.clip();const r=this.alarmSensitiveForegroundColor;if(this.gradient){const o=this.horizontalFill?s.x:s.x+s.width,h=this.horizontalFill?s.y+s.height:s.y,n=t.createLinearGradient(s.x,s.y,o,h);n.addColorStop(0,this.foregroundGradientStartColor.toString()),n.addColorStop(1,r.toString()),t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,gradient:n}))}else t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,color:r}));t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get cornerWidth(){return this.scale*this.properties.getValue("corner_width")}get cornerHeight(){return this.scale*this.properties.getValue("corner_height")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class ue extends Dt{constructor(e,i){super(e,i),this.properties.add(new j("bitReverse")),this.properties.add(new j("effect_3d")),this.properties.add(new j("horizontal")),this.properties.add(new $("numBits")),this.properties.add(new z("off_color")),this.properties.add(new z("on_color")),this.properties.add(new $("startBit")),this.properties.add(new j("square_led")),this.properties.add(new $("led_border",3)),this.properties.add(new z("led_border_color",t.DARK_GRAY)),this.properties.add(new j("led_packed",!1))}getLedColor(t){var e,i;let s=!1;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value))for(let e=this.startBit;e<this.startBit+this.numBits;e++){let r=0;if(r=this.bitReverse?e-this.startBit:this.numBits-1-(e-this.startBit),r===t){s=((null===(i=this.pv)||void 0===i?void 0:i.value)>>e&1)>0;break}}return s?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=l(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,s;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),s=i);let r=0;r=i>e.height||this.squareLed?e.height:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const h={x:e.x+o*s,y:e.y,width:i,height:r};this.effect3d?this.drawSquare3d(t,h,o):this.drawSquare2d(t,h,o)}else{const h=Math.min(i,r),n={x:e.x+o*s,y:e.y,width:h,height:h};this.effect3d?this.drawCircle3d(t,n,o):this.drawCircle2d(t,n,o)}}drawVertical(t,e){let i,s;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),s=i);let r=0;r=i>e.width||this.squareLed?e.width:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const h={x:e.x,y:e.y+o*s,width:r,height:i};this.effect3d?this.drawSquare3d(t,h,o):this.drawSquare2d(t,h,o)}else{const h=Math.min(r,i),n={x:e.x,y:e.y+o*s,width:h,height:h};this.effect3d?this.drawCircle3d(t,n,o):this.drawCircle2d(t,n,o)}}drawCircle2d(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,h=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,h-=this.ledBorder/2),t.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:this.getLedColor(i)}),t.strokeEllipse({cx:s,cy:r,rx:o,ry:h,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(e,i,s){const r=i.x+i.width/2,o=i.y+i.height/2;let h=i.width/2,n=i.height/2;e.fillEllipse({cx:r,cy:o,rx:h,ry:n,color:t.WHITE});let a=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:r,cy:o,rx:h,ry:n,gradient:a});h=(i.width-2*this.ledBorder)/2,n=(i.height-2*this.ledBorder)/2,e.fillEllipse({cx:r,cy:o,rx:h,ry:n,color:this.getLedColor(s)}),a=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height),a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:r,cy:o,rx:h,ry:n,gradient:a})}drawSquare2d(t,e,i){const s=n(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect(Object.assign(Object.assign({},s),{color:this.getLedColor(i)})),t.strokeRect(Object.assign(Object.assign({},s),{color:this.ledBorderColor,lineWidth:this.ledBorder}))}drawSquare3d(t,e,i){t.fillRect(Object.assign(Object.assign({},e),{color:this.ledBorderColor}));let s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width,e.y)}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new v(e.x+e.width,e.y).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y+e.height).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)});const r=e.x+this.ledBorder,o=e.y+this.ledBorder,h=e.width-2*this.ledBorder,n=e.height-2*this.ledBorder,a=this.getLedColor(i);t.fillRect({x:r,y:o,width:h,height:n,color:a}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.784)"),s.addColorStop(1,a.withAlpha(0).toString()),t.fillRect({x:r,y:o,width:h,height:n,gradient:s})}get bitReverse(){return this.properties.getValue("bitReverse")}get horizontal(){return this.properties.getValue("horizontal")}get numBits(){return this.properties.getValue("numBits")}get startBit(){return this.properties.getValue("startBit")}get ledPacked(){return this.properties.getValue("led_packed")}get ledBorder(){return this.scale*this.properties.getValue("led_border")}get ledBorderColor(){return this.properties.getValue("led_border_color")}get offColor(){return this.properties.getValue("off_color")}get onColor(){return this.properties.getValue("on_color")}get effect3d(){return this.properties.getValue("effect_3d")}get squareLed(){return this.properties.getValue("square_led")}}class me{constructor(t){this.prefix="",this.suffix="",this.comma=0,this.minInt=1,this.minFrac=0,this.maxFrac=0;for(let e=0;e<t.length;e++)if("#"==t.charAt(e)||"0"==t.charAt(e)){this.prefix=t.substring(0,e),t=t.substring(e);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");const e=t.replace(/[^0#,.]/g,"");let i="",s="";const r=e.indexOf(".");-1!==r?(i=e.substring(0,r),s=e.substring(r+1)):i=e;const o=i.lastIndexOf(",");-1!==o&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),s=s.replace(/[,]|[.]+/g,""),this.maxFrac=s.length;let h=i.replace(/[^0]/g,"");h.length>this.minInt&&(this.minInt=h.length),h=s.replace(/[^0]/g,""),this.minFrac=h.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||0==e.length)return t;if(-1!=e.indexOf("e")){const t=Number(e);if(t===1/0||t===-1/0)return e;if(e=t+"",-1!==e.indexOf("e"))return e}let i=!1;"-"===e.charAt(0)?(i=!0,e=e.substring(1)):"+"===e.charAt(0)&&(e=e.substring(1));const s=e.indexOf(".");let r="",o="";-1!=s?(r=e.substring(0,s),o=e.substring(s+1)):r=e,o=o.replace(/[.]/,"");const h=this.suffix&&"%"===this.suffix.charAt(0);let n=this.minInt,a=this.minFrac,l=this.maxFrac;if(h&&(n-=2,a+=2,l+=2),o.length>l){let t=Number("0."+o);t=0==l?Math.round(t):t.toFixed(l),o=t.toString(10).substr(2);let e,i=t>=1?1:0,s=r.length-1;for(;i;){if(-1==s){r="1"+r;break}e=Number(r.charAt(s)),9===e?(e="0",i=1):(e=++e+"",i=0),r=r.substring(0,s)+e+r.substring(s+1,r.length),s--}}for(let t=o.length;t<a;t++)o+="0";for(;o.length>a&&"0"==o.charAt(o.length-1);)o=o.substring(0,o.length-1);for(let t=r.length;t<n;t++)r="0"+r;for(;r.length>n&&"0"==r.charAt(0);)r=r.substring(1);h&&(r+=o.substring(0,2),o=o.substring(2));let d,c=0;for(let t=r.length;t>0;t--)0!=c&&c%this.comma==0&&(r=r.substring(0,t)+","+r.substring(t),c=0),c++;return d=o.length>0?this.prefix+r+"."+o+this.suffix:this.prefix+r+this.suffix,i&&(d="-"+d),d}formatBack(t){if(!(t+=""))return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;"-"===t.charAt(0)&&(e=e.substr(1),i=!0);const s=e.indexOf(this.prefix),r=""==this.suffix?e.length:e.indexOf(this.suffix,this.prefix.length+1);return 0==s&&r>0&&(e=e.substr(0,r),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){const e=Number(t)+"";if(t.indexOf(".")>-1&&e.indexOf(".")<0){for(var i=t.indexOf(".")+1;i<t.length;i++)if("0"!==t.charAt(i))return t;return e}return t}}class fe{constructor(e,i,s){this.rampWidth=e,this.startAngle=i,this.endAngle=s,this.lolo=10,this.loloColor=t.RED,this.showLoLo=!0,this.lo=25,this.loColor=t.ORANGE,this.showLo=!0,this.hi=75,this.hiColor=t.ORANGE,this.showHi=!0,this.hihi=90,this.hihiColor=t.RED,this.showHiHi=!0,this.minimum=0,this.maximum=100,this.gradient=!0,this.logScale=!1,this.effect3d=!0,this.labelsOutside=!0,this.range={min:this.minimum,max:this.maximum},this.lengthInDegrees=0,this.radius=0}draw(t,e,i){if(this.labelsOutside){const t=9;this.radius=e.width/2-t}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(e,i){const s=i.x+i.width/2,r=i.y+i.height/2,o=i.width/2,h=i.height/2;let n,a=360-this.endAngle;if(n=this.endAngle-this.startAngle>0?this.startAngle-90:this.startAngle+90,this.showLoLo){let t=n,i=360-this.getValuePosition(this.lolo,!0);e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(t),endAngle:g(i),color:this.loloColor})}if(this.showLo){let t;t=this.showLoLo?this.lolo:this.minimum;const n=360-this.getValuePosition(t,!0),a=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){const l=g(this.getValuePosition(t,!0)-2),d=u(i.width/2,l,i),c=g(this.getValuePosition(this.lo,!0)+2),p=u(i.width/2,c,i),m=e.createLinearGradient(d.x,d.y,p.x,p.y);m.addColorStop(0,this.loloColor.toString()),m.addColorStop(1,this.loColor.toString()),e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n-1),endAngle:g(a+1),gradient:m})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n),endAngle:g(a),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let d=this.maximum;this.showHi?d=this.hi:this.showHiHi&&(d=this.hihi);const c=(l+d)/2;let p=360-this.getValuePosition(l,!0),m=360-this.getValuePosition(c,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){const n=g(this.getValuePosition(l,!0)-2),a=u(i.width/2,n,i),d=g(this.getValuePosition(c,!0)+2),f=u(i.width/2,d,i),x=e.createLinearGradient(a.x,a.y,f.x,f.y);x.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),x.addColorStop(1,t.GREEN.toString()),e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-1),endAngle:g(m+1),gradient:x})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p),endAngle:g(m),color:t.GREEN});if(p=360-this.getValuePosition(c,!0),m=360-this.getValuePosition(d,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){const n=g(this.getValuePosition(c,!0)-2),l=u(i.width/2,n,i),f=g(this.getValuePosition(d,!0)+2),x=u(i.width/2,f,i),w=e.createLinearGradient(l.x,l.y,x.x,x.y);w.addColorStop(0,t.GREEN.toString()),w.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());const y=m!==a?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-1),endAngle:g(m+y),gradient:w})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p),endAngle:g(m),color:t.GREEN});if(this.showHi){let t;t=this.showHiHi?this.hihi:this.maximum;const n=360-this.getValuePosition(this.hi,!0),l=360-this.getValuePosition(t,!0);if(this.effect3d&&this.gradient&&this.showHiHi){const d=g(this.getValuePosition(this.hi,!0)-2),c=u(i.width/2,d,i),p=g(this.getValuePosition(t,!0)+2),m=u(i.width/2,p,i),f=e.createLinearGradient(c.x,c.y,m.x,m.y);f.addColorStop(0,this.hiColor.toString()),f.addColorStop(1,this.hihiColor.toString());const x=l!==a?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n-1),endAngle:g(l+x),gradient:f})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n),endAngle:g(l),color:this.hiColor})}if(this.showHiHi){p=360-this.getValuePosition(this.hihi,!0),m=a;const t=this.gradient?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-t),endAngle:g(m),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){let i;return e&&(t=this.getValueInRange(t)),i=this.logScale?this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:this.startAngle-(t-this.range.min)/(this.range.max-this.range.min)*this.lengthInDegrees,i<0&&(i+=360),i}getValueInRange(t){return this.range.min<=t&&t<=this.range.max?t:t>this.range.max?this.range.max:this.range.min}getRenderedRange(){const t={min:this.minimum,max:this.maximum};return this.logScale&&(this.minimum<=0&&(t.min=.1),t.max<=this.minimum&&(t.max=t.min+100)),t}}const xe=new t(100,100,100);class we extends Dt{constructor(t,e){super(t,e),this.properties.add(new z("color_hi")),this.properties.add(new z("color_hihi")),this.properties.add(new z("color_lo")),this.properties.add(new z("color_lolo")),this.properties.add(new j("effect_3d")),this.properties.add(new U("font")),this.properties.add(new G("level_hi")),this.properties.add(new G("level_hihi")),this.properties.add(new G("level_lo")),this.properties.add(new G("level_lolo")),this.properties.add(new j("log_scale")),this.properties.add(new j("limits_from_pv")),this.properties.add(new G("maximum")),this.properties.add(new G("minimum")),this.properties.add(new z("needle_color")),this.properties.add(new j("ramp_gradient")),this.properties.add(new j("show_ramp",!0)),this.properties.add(new N("value_label_format"))}draw(t){var e,i;let s;s=this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:null!==(e=this.pv.lowerDisplayLimit)&&void 0!==e?e:this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:null!==(i=this.pv.upperDisplayLimit)&&void 0!==i?i:this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(s.min=Math.max(.1,s.min),s.max<=s.min&&(s.max=s.min+100));const r=Math.min(this.width,this.height),o=r;this.drawBackground(t,r,o),this.showRamp&&this.drawRamp(t,r,o,s),this.drawLabel(t,r,o),this.drawNeedle(t,r,o,s),this.drawNeedleCenter(t,r,o)}drawBackground(e,i,s){if(e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2,ry:s/2,color:t.GRAY}),this.effect3d){const r=e.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);r.addColorStop(0,xe.toString()),r.addColorStop(1,t.WHITE.toString()),e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2,ry:s/2,gradient:r})}const r=(this.effect3d?2:1)*this.scale;if(e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2-r,ry:s/2-r,color:this.backgroundColor}),this.effect3d){const r=i/2,o=.95,h=.5,n=.85,a=g(0),l=g(35);let d={x:Math.floor(this.x+i/2-r*n*Math.cos(a)),y:Math.floor(this.y+s/2-r*o),width:Math.floor(2*r*n*Math.cos(a)),height:Math.floor(r*o+r*h)},c=e.createLinearGradient(d.x,d.y,d.x,d.y+d.height);c.addColorStop(0,t.WHITE.withAlpha(90/255).toString()),c.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c}),d={x:Math.floor(this.x+i/2-r*n*Math.sin(l)),y:Math.floor(Math.ceil(this.y+s/2+r*h)),width:Math.floor(2*r*n*Math.sin(l)),height:Math.floor(Math.ceil(r*o-r*h))},c=e.createLinearGradient(d.x,d.y,d.x,d.y+d.height),c.addColorStop(0,t.WHITE.withAlpha(0).toString()),c.addColorStop(1,t.WHITE.withAlpha(40/255).toString()),e.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c})}}drawRamp(t,e,i,s){const r=l({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o=Object.assign({},r);o.width=Math.min(r.width,r.height),o.height=r.width;const h=new fe(10*this.scale,225,315);h.lolo=s.lolo,h.loloColor=this.colorLoLo,h.lo=s.lo,h.loColor=this.colorLo,h.hi=s.hi,h.hiColor=this.colorHi,h.hihi=s.hihi,h.hihiColor=this.colorHiHi,h.minimum=s.min,h.maximum=s.max,h.effect3d=this.effect3d,h.gradient=this.rampGradient,h.logScale=this.logScale,h.draw(t,r,o)}drawLabel(t,e,i){var s;const r=E.ARIAL_12_BOLD.scale(this.scale);if(void 0!==(null===(s=this.pv)||void 0===s?void 0:s.value)){const s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+7*i/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,s){var r;const o=this.x+e/2,h=this.y+i/2;let n;if(void 0!==(null===(r=this.pv)||void 0===r?void 0:r.value)){const t=this.getValueInRange(this.pv.value,s);n=360-this.getValuePosition(t,s),s.max>s.min?t>s.max?n+=10:t<s.min&&(n-=10):t>s.min?n-=10:t<s.max&&(n+=10)}else n=360-this.getValuePosition((s.min+s.max)/2,s);const l=g(n),{scale:d}=this,{needleDiameter:c,majorTickLength:p,gapBetweenNeedleScale:u}=this,m=a(o,h-c/2+3*d,o,h,l),f=a(o+e/2-p-u,h,o,h,l),x=a(o,h+c/2-3*d,o,h,l);t.fillPath({color:this.needleColor,path:new v(m.x,m.y).lineTo(f.x,f.y).lineTo(x.x,x.y).closePath()})}drawNeedleCenter(e,i,s){const{needleDiameter:r}=this,o=this.x+i/2,h=this.y+s/2,n=r/2,a=r/2;if(this.effect3d){const i=e.createLinearGradient(o-n,h-a,o+n,h+a);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,xe.toString()),e.fillEllipse({cx:o,cy:h,rx:n,ry:a,gradient:i})}else e.fillEllipse({cx:o,cy:h,rx:n,ry:a,color:t.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i;return i=this.logScale?225-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*270:225-(t-e.min)/(e.max-e.min)*270,i<0&&(i+=360),i}formatLabelValue(t){return this.valueLabelFormat?new me(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return 16*this.scale}get majorTickLength(){return 8*this.scale}get minorTickLength(){return 5*this.scale}get gapBetweenNeedleScale(){return-1*this.scale}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get effect3d(){return this.properties.getValue("effect_3d")}get font(){return this.properties.getValue("font").scale(this.scale)}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get needleColor(){return this.properties.getValue("needle_color")}get rampGradient(){return this.properties.getValue("ramp_gradient")}get showRamp(){return this.properties.getValue("show_ramp")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class ye extends Dt{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.properties.add(new $("bit")),this.properties.add(new $("data_type")),this.properties.add(new N("off_image")),this.properties.add(new N("off_label")),this.properties.add(new N("on_image")),this.properties.add(new N("on_label")),this.properties.add(new U("font")),this.properties.add(new j("show_boolean_label"))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=`${this.display.baseUrl}${this.onImage}`),this.offImage&&(this.offImageElement.src=`${this.display.baseUrl}${this.offImage}`)}get booleanValue(){var t,e,i;return this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get font(){return this.properties.getValue("font").scale(this.scale)}get offLabel(){return this.properties.getValue("off_label")}get offImage(){return this.properties.getValue("off_image")}get onLabel(){return this.properties.getValue("on_label")}get onImage(){return this.properties.getValue("on_image")}}const ve=["January","February","March","April","May","June","July","August","September","October","November","December"];class be{constructor(t,e,i,s,r,o,h,n,a){this.scale=t,this.scaleFont=e,this.minimum=i,this.maximum=s,this.logScale=r,this.majorTickStepHint=o,this.foregroundColor=h,this.showMinorTicks=n,this.showScale=a,this.labels=[],this.labelValues=[],this.labelPositions=[],this.labelVisibilities=[],this.gridStepInPixel=0,this.horizontal=!1,this.x=0,this.y=0,this.scaleFormat="",this.timeFormat=0,this.length=0,this.margin=0}get scaleLength(){return this.length-2*this.margin}getX(){return this.x}getY(){return this.y}getGridPositions(){let t=[...this.labelPositions];return this.horizontal||(t=t.map((t=>this.length-t))),t.pop(),t.shift(),t}setDimensions(t,e,i,s){this.x=t,this.y=e,this.length=i,this.horizontal=s}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),s=0;const r=this.length-2*this.margin;if(this.logScale)s=t<=0?this.margin:(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*r+this.margin;else{const o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;s=(t/o-e)/(i-e)*r+this.margin}return this.horizontal?s+this.x:this.length-s+this.y}getMinMax(){let t=this.minimum,e=this.maximum;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{start:t,stop:e}}getPositionValue(t){const e=this.getMinMax();let{start:i,stop:s}=e;const r=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin;let h;if(this.logScale)h=Math.pow(10,(r-this.margin)*(Math.log10(s)-Math.log10(i))/o+Math.log10(i));else{const t=Math.max(Math.abs(i),Math.abs(s));s/=t,i/=t;const e=s-i;h=((r-this.margin)/o*e+i)*t}return h}calculateMargin(t,e){if(this.showScale){const i=t.measureText(this.format(this.minimum),this.scaleFont),s=t.measureText(this.format(this.maximum),this.scaleFont);return e?Math.ceil(Math.max(i.width,s.width)/2):Math.ceil(Math.max(i.height,s.height)/2)}return 0}measureHorizontalHeight(t){const e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,s){const{scale:r}=this;this.length=s,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);const o=s-2*this.margin;o>0&&this.updateLabels(t,o);let h=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.height>h&&(h=i.height)}const n=this.showScale?h+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i-=n,this.x=e,this.y=i,this.logScale)for(let e=0;e<this.labelPositions.length;e++){const i=this.x+this.labelPositions[e],s=this.y;let o=0;if(o=this.labelVisibilities[e]?this.majorTickLength:this.minorTickLength,this.labelVisibilities[e]||this.showMinorTicks){const e=Math.round(i)-.5*r;t.strokePath({path:new v(e,s).lineTo(e,s+o),color:this.foregroundColor,lineWidth:1*r,opacity:100/255})}this.labelVisibilities[e]&&t.fillText({x:i,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[e]})}else for(let s=0;s<this.labels.length;s++){const o=e+this.labelPositions[s];this.labelVisibilities[s]&&t.fillText({x:o,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[s]});const h=Math.round(o)-.5*r;t.strokePath({path:new v(h,i).lineTo(h,i+this.majorTickLength),color:this.foregroundColor,lineWidth:1*r,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,s,e,i)}return n}drawVertical(t,e,i,s,r,o=!1){const{scale:h}=this;this.length=s,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);const n=s-2*this.margin;n>0&&this.updateLabels(t,n);let a=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.width>a&&(a=i.width)}const l=this.showScale?a+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(r||(e-=l),this.x=e,this.y=i,this.logScale)for(let r=0;r<this.labelPositions.length;r++){let o;o=this.labelVisibilities[r]?this.majorTickLength:this.minorTickLength;const n=e+a+this.spaceBetweenMarkAndLabel-1*h+this.majorTickLength-o,l=Math.round(i+s-this.labelPositions[r])-.5*h;if((this.labelVisibilities[r]||this.showMinorTicks)&&t.strokePath({path:new v(n,l).lineTo(n+o,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.labelVisibilities[r]){const o=i+s-this.labelPositions[r];t.fillText({x:e,y:o,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else for(let r=0;r<this.labels.length;r++){const n=i+s-this.labelPositions[r],l=Math.round(n)-.5*h;if(o){if(t.strokePath({path:new v(e,l).lineTo(e+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.labelVisibilities[r]){const i=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:i,y:n,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else{this.labelVisibilities[r]&&t.fillText({x:e,y:n,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]});const o=e+a+this.spaceBetweenMarkAndLabel-1*h;t.strokePath({path:new v(o,l).lineTo(o+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,r,o,i+s)}}return l}drawMinorXTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,h;r/5>=this.minorTickMarkStepHint?(o=5,h=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,h=Math.floor(r/4)):(o=2,h=Math.floor(r/2));const{labelPositions:n,minorTickLength:a,scale:l}=this;if(e>0)if(1===e&&n[1]-n[0]<r){let e=n[1];for(;e-n[0]>h+3*l;){e-=h;const r=Math.round(i+e)-.5*l;t.strokePath({path:new v(r,s).lineTo(r,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else if(e===n.length-1&&n[e]-n[e-1]<r){let r=n[e-1];for(;n[e]-r>h+3*l;){r+=h;const e=Math.round(i+r)-.5*l;t.strokePath({path:new v(e,s).lineTo(e,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else for(let r=0;r<o;r++){let h=i+n[e-1]+(n[e]-n[e-1])*r/o;h=Math.round(h)-.5*l,t.strokePath({path:new v(h,s).lineTo(h,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}drawMinorYTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,h;r/5>=this.minorTickMarkStepHint?(o=5,h=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,h=Math.floor(r/4)):(o=2,h=Math.floor(r/2));const{labelPositions:n,minorTickLength:a,majorTickLength:l,scale:d}=this;if(e>0)if(1===e&&n[1]-n[0]<r){let e=n[1];for(;e-n[0]>h+3*d;){e-=h;const r=Math.round(s-e)-.5*d;t.strokePath({path:new v(i+l-a,r).lineTo(i+l,r),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else if(e===n.length-1&&n[e]-n[e-1]<r){let r=n[e-1];for(;n[e]-r>h+3*d;){r+=h;const e=Math.round(s-r)-.5*d;t.strokePath({path:new v(i+l-a,e).lineTo(i+l,e),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else for(let r=0;r<o;r++){let h=s-n[e-1]-(n[e]-n[e-1])*r/o;h=Math.round(h)-.5*d,t.strokePath({path:new v(i+l-a,h).lineTo(i+l,h),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}updateLabels(t,e){if(this.labels=[],this.labelValues=[],this.labelPositions=[],this.showScale)if(this.logScale)this.updateLabelsForLogScale(this.minimum,this.maximum,e);else{const t=this.getGridStep(e,this.minimum,this.maximum),i=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/i-this.minimum/i;this.gridStepInPixel=Math.floor(e*(t/i)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,t)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let s=!1;if(e>=i)if(i===e)i++;else{s=!0;const t=e;e=i,i=t}const r=Math.abs(i-e);let o=this.majorTickStepHint;o>t&&(o=t);let h,n=r/t*o,a=0;if(n<1){if(0!=n)for(;n<1;)n*=10,a--}else for(;n>=10;)n/=10,a++;return h=n>7.5?10*Math.pow(10,a):n>3.5?5*Math.pow(10,a):n>1.5?2*Math.pow(10,a):Math.pow(10,a),s&&(h=-h),h}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);const s=e<t,r=Math.log10(t),o=Math.ceil(r),h=Math.ceil(Math.log10(e));let n,a=Math.pow(10,o-1);n=t%a<=0||s?t-t%a:t-t%a+a,(s&&t>n||!s&&t<n)&&this.addMinMaxTickInfo(t,i,!0);for(let t=o;s?t>=h:t<=h;t+=s?-1:1)if(Math.abs(h-o)>20){const s=Math.pow(10,t);if(s>e)break;this.addTickInfo(s,e,r,i)}else{for(let o=n;(s?o>=Math.pow(10,t-1):o<=Math.pow(10,t))&&!(s?o<e:o>e);o=s?o-a:o+a)this.addTickInfo(o,e,r,i);a=s?a/Math.pow(10,1):a*Math.pow(10,1),n=s?Math.pow(10,t-1):a+Math.pow(10,t)}(s?e<this.labelValues[this.labelValues.length-1]:e>this.labelValues[this.labelValues.length-1])&&this.addMinMaxTickInfo(e,i,!1)}addMinMaxTickInfo(t,e,i){i?(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin)):(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin+e))}addTickInfo(t,e,i,s){this.labels.push(this.format(t));const r=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*s)+this.margin;this.labelPositions.push(r),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,s){let r;r=t%s<=0?t-t%s:t-t%s+s,t>r==e<t&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let o=1;const h=Math.max(Math.abs(t),Math.abs(e));s/=h,r/=h;const n=(e/=h)-(t/=h);for(let a=r;e>=t?a<e:a>e;a=r+o++*s){const e=a*h;this.labels.push(this.format(e)),this.labelValues.push(e);const s=Math.floor((a-t)/n*i)+this.margin;this.labelPositions.push(s)}e*=h,this.labelValues.push(e),this.labels.push(this.format(e)),this.labelPositions.push(this.margin+i)}updateVisibility(t){if(this.labelVisibilities=[],!this.labelPositions.length)return;for(let t=0;t<this.labelPositions.length;t++)this.labelVisibilities.push(!0);let e=0,i=null;for(let s=0;s<this.labelPositions.length;s++){let r=!0;const o=this.labels[s],h=this.labelPositions[s];0!==s&&(r=this.hasSpaceToDraw(t,e,h,i||"",o));const n=o===i&&0!==s&&s!==this.labelPositions.length-1;let a=!0;if(this.logScale){const t=Number(this.labels[s]);a=this.isMajorTick(t)||0===s||s===this.labelPositions.length-1}r&&!n&&a?(e=h,i=o):this.labelVisibilities[s]=!1}}hasSpaceToDraw(t,e,i,s,r){const o=t.measureText(r,this.scaleFont),h=t.measureText(s,this.scaleFont);let n=i-e,a=Math.floor(this.horizontal?o.width/2+h.width/2:o.height),l=!0,d=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){l=n>a+this.tickLabelGap;const e=t.measureText(this.labels[this.labels.length-1],this.scaleFont);n=this.labelPositions[this.labelPositions.length-1]-i,a=Math.floor(this.horizontal?o.width/2+e.width/2:o.height),d=n>a+this.tickLabelGap}return l&&d}isMajorTick(t){if(!this.logScale)return!0;const e=Math.log10(t);return e===Math.round(e)}format(t){if(0===this.timeFormat)return this.scaleFormat?new me(this.scaleFormat).format(t):String(Number(t.toFixed(2)));const e=new Date(t);switch(this.timeFormat){case 1:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return this.formatDate(e,{year:!0,month:!0,day:!0});case 7:return`${ve[e.getUTCMonth()]} ${e.getUTCDate()}`;case 8:const t=Math.abs(this.maximum-this.minimum);return t<=5e3?this.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):t<=18e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):t<=864e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=6048e5?this.formatDate(e,{year:!1,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=2592e6?this.formatDate(e,{year:!1,month:!0,day:!0}):this.formatDate(e,{year:!0,month:!0,day:!0})}return""}formatDate(t,e){let i="";if(e.year&&(i+=t.getUTCFullYear()),e.month){e.year&&(i+="-");const s=t.getUTCMonth();i+=(s<10?"0":"")+s}if(e.day){e.month&&(i+="-");const s=t.getUTCDate();i+=(s<10?"0":"")+s}return i}formatTime(t,e){let i="";if(e.hours){const e=t.getUTCHours();i+=(e<10?"0":"")+e}if(e.minutes){e.hours&&(i+=":");const s=t.getUTCMinutes();i+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(i+=":");const s=t.getUTCSeconds();i+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(i+=".");const s=t.getUTCMilliseconds();i+=(s<10?"00":s<100?"0":"")+s}return i}get spaceBetweenMarkAndLabel(){return 2*this.scale}get majorTickLength(){return 6*this.scale}get minorTickLength(){return 3*this.scale}get minorTickMarkStepHint(){return 4*this.scale}get tickLabelGap(){return 2*this.scale}}class _e extends Dt{constructor(t,e){super(t,e),this.properties.add(new q("color_map")),this.properties.add(new $("crop_bottom")),this.properties.add(new $("crop_left")),this.properties.add(new $("crop_right")),this.properties.add(new $("crop_top")),this.properties.add(new $("data_height")),this.properties.add(new $("data_width")),this.properties.add(new $("graph_area_height")),this.properties.add(new $("graph_area_width")),this.properties.add(new U("font")),this.properties.add(new G("maximum")),this.properties.add(new G("minimum")),this.properties.add(new j("show_ramp")),this.properties.add(new z("x_axis_axis_color")),this.properties.add(new N("x_axis_axis_title")),this.properties.add(new $("x_axis_major_tick_step_hint")),this.properties.add(new G("x_axis_maximum")),this.properties.add(new G("x_axis_minimum")),this.properties.add(new U("x_axis_scale_font")),this.properties.add(new j("x_axis_show_minor_ticks")),this.properties.add(new U("x_axis_title_font")),this.properties.add(new j("x_axis_visible")),this.properties.add(new z("y_axis_axis_color")),this.properties.add(new N("y_axis_axis_title")),this.properties.add(new $("y_axis_major_tick_step_hint")),this.properties.add(new G("y_axis_maximum")),this.properties.add(new G("y_axis_minimum")),this.properties.add(new U("y_axis_scale_font")),this.properties.add(new j("y_axis_show_minor_ticks")),this.properties.add(new U("y_axis_title_font")),this.properties.add(new j("y_axis_visible"))}draw(t){const{scale:e}=this;let i=this.area;this.borderAlarmSensitive&&(i=l(i,2*e));const s=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},i),{color:s}));const{graphAreaWidth:r,graphAreaHeight:o}=this;this.xAxisVisible&&t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height;let h=0;this.yAxisVisible&&(h=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);const n=new be(e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),a=n.calculateMargin(t,!0),d=new be(e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),c=d.calculateMargin(t,!1),p=n.measureHorizontalHeight(t),g=o+2*c,u=d.drawVertical(t,i.x+h,i.y,g,!0),m=r+2*a,f=i.x+h+u-a,x=i.y+g+p-c;n.drawHorizontal(t,f,x,m);const w=1*e,y=Math.round(i.x+h+u)-w/2,b=Math.round(i.y+c)-w/2;t.strokePath({path:new v(y,b).lineTo(y,b+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:w});const _=y,T=b+o+w;t.strokePath({path:new v(_,T).lineTo(_+r,T),color:this.xAxisAxisColor,opacity:100/255,lineWidth:w});const{dataWidth:S,dataHeight:V,colorMap:A}=this,{minimum:L,maximum:C}=this,[k,P]=A.getMinMax();if(this.value&&this.value.length){const e=document.createElement("canvas"),{cropLeft:s,cropRight:n,cropTop:a,cropBottom:l}=this;e.width=S-s-n,e.height=V-a-l;const c=e.getContext("2d");for(let t=s;t<S-n;t++)for(let e=a;e<V-l;e++){let i=this.value[e*S+t];if(A.autoscale){i=k+(i-L)/(C-L)*(P-k)}const[r,o,h]=A.lookup(i);c.fillStyle=`rgb(${r},${o},${h})`,c.fillRect(t-s,e-a,1,1)}const p=Math.round(i.x+h+u),g=Math.round(i.y+d.margin);t.ctx.drawImage(e,p,g,r,o)}if(this.showRamp){const s=new be(e,this.font,L,C,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),n=i.y+d.margin,a=o,l=s.drawVertical(t,i.x+i.width,n,a,!1,!0),c=i.x+h+u+r+this.gap,p=i.width-h-u-r-l-this.gap,g=a-2*s.margin,m=document.createElement("canvas");m.width=p,m.height=g;const f=m.getContext("2d");for(let t=0;t<g;t++){let e=C-t/g*(C-L);if(A.autoscale){e=k+(e-L)/(C-L)*(P-k)}const[i,s,r]=A.lookup(e);f.fillStyle=`rgb(${i},${s},${r})`,f.fillRect(0,t,p,1)}t.ctx.drawImage(m,c,n+s.margin)}if(this.xAxisVisible){let e=i.x+u+r/2;this.yAxisVisible&&(e+=h),t.fillText({x:e,y:i.y+i.height,align:"center",baseline:"bottom",font:this.xAxisTitleFont,color:this.xAxisAxisColor,text:this.xAxisAxisTitle})}this.yAxisVisible&&(t.ctx.save(),t.ctx.translate(i.x+h/2,i.y+g/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return 3*this.scale}get colorMap(){return this.properties.getValue("color_map")}get cropBottom(){return this.properties.getValue("crop_bottom")}get cropLeft(){return this.properties.getValue("crop_left")}get cropRight(){return this.properties.getValue("crop_right")}get cropTop(){return this.properties.getValue("crop_top")}get dataHeight(){return this.properties.getValue("data_height")}get dataWidth(){return this.properties.getValue("data_width")}get font(){return this.properties.getValue("font").scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue("graph_area_height")}get graphAreaWidth(){return this.scale*this.properties.getValue("graph_area_width")}get maximum(){return this.properties.getValue("maximum")}get minimum(){return this.properties.getValue("minimum")}get showRamp(){return this.properties.getValue("show_ramp")}get xAxisAxisColor(){return this.properties.getValue("x_axis_axis_color")}get xAxisAxisTitle(){return this.properties.getValue("x_axis_axis_title")}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue("x_axis_major_tick_step_hint")}get xAxisMaximum(){return this.properties.getValue("x_axis_maximum")}get xAxisMinimum(){return this.properties.getValue("x_axis_minimum")}get xAxisScaleFont(){return this.properties.getValue("x_axis_scale_font").scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue("x_axis_show_minor_ticks")}get xAxisTitleFont(){return this.properties.getValue("x_axis_title_font").scale(this.scale)}get xAxisVisible(){return this.properties.getValue("x_axis_visible")}get yAxisAxisColor(){return this.properties.getValue("y_axis_axis_color")}get yAxisAxisTitle(){return this.properties.getValue("y_axis_axis_title")}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue("y_axis_major_tick_step_hint")}get yAxisMaximum(){return this.properties.getValue("y_axis_maximum")}get yAxisMinimum(){return this.properties.getValue("y_axis_minimum")}get yAxisScaleFont(){return this.properties.getValue("y_axis_scale_font").scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue("y_axis_show_minor_ticks")}get yAxisTitleFont(){return this.properties.getValue("y_axis_title_font").scale(this.scale)}get yAxisVisible(){return this.properties.getValue("y_axis_visible")}}class Te extends Dt{constructor(e,i){super(e,i),this.states=[],this.properties.add(new $("bit")),this.properties.add(new $("data_type")),this.properties.add(new j("effect_3d")),this.properties.add(new j("square_led")),this.properties.add(new $("state_count",2)),this.properties.add(new z("off_color")),this.properties.add(new N("off_label")),this.properties.add(new z("on_color")),this.properties.add(new N("on_label")),this.properties.add(new U("font")),this.properties.add(new j("show_boolean_label")),this.properties.add(new z("state_color_fallback")),this.properties.add(new N("state_label_fallback")),this.properties.add(new $("bulb_border",3)),this.properties.add(new z("bulb_border_color",t.DARK_GRAY))}parseNode(t){if(super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){const i=new z(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);const s=new N(`state_label_${e}`);s.value=t.getString(`state_label_${e}`),this.properties.add(s);const r=new G(`state_value_${e}`);r.value=t.getFloat(`state_value_${e}`),this.properties.add(r),this.states.push({label:this.properties.getValue(s.name),color:this.properties.getValue(i.name),value:this.properties.getValue(r.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){var t,e,i;return 0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0:(this.dataType,!1)}get bulbColor(){var t;if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.color;return this.stateColorFallback}get label(){var t;if(2===this.stateCount)return this.booleanValue?this.onLabel:this.offLabel;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.label;return this.stateLabelFallback}draw(t){const e=l(this.bounds,3*this.scale);this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}drawCircle2d(t,e){const i=e.x+e.width/2,s=e.y+e.height/2;let r=e.width/2,o=e.height/2;if(this.bulbBorder>0&&(r-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(i,s,r,o,0,0,2*Math.PI)}}drawCircle3d(e,i){const s=i.x+i.width/2,r=i.y+i.height/2;let o=i.width/2,h=i.height/2;e.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:t.WHITE});let n=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);n.addColorStop(0,this.bulbBorderColor.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:s,cy:r,rx:o,ry:h,gradient:n});if(o=(i.width-2*this.bulbBorder)/2,h=(i.height-2*this.bulbBorder)/2,e.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:this.bulbColor}),n=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height),n.addColorStop(0,t.WHITE.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:s,cy:r,rx:o,ry:h,gradient:n}),this.pv&&this.pv.navigable&&!this.pv.disconnected){e.addHitRegion(this.areaRegion).addEllipse(s,r,o,h,0,0,2*Math.PI)}}drawSquare2d(t,e){const i=n(e.x,e.y,e.width,e.height,this.bulbBorder);if(t.fillRect(Object.assign(Object.assign({},i),{color:this.bulbColor})),t.strokeRect(Object.assign(Object.assign({},i),{color:this.bulbBorderColor,lineWidth:this.bulbBorder})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}}drawSquare3d(t,e){if(t.fillRect(Object.assign(Object.assign({},e),{color:this.bulbBorderColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}let i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width,e.y)}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new v(e.x+e.width,e.y).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y+e.height).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)});const s=e.x+this.bulbBorder,r=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,h=e.height-2*this.bulbBorder;t.fillRect({x:s,y:r,width:o,height:h,color:this.bulbColor}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.784)"),i.addColorStop(1,this.bulbColor.withAlpha(0).toString()),t.fillRect({x:s,y:r,width:o,height:h,gradient:i})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get squareLed(){return this.properties.getValue("square_led")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get font(){return this.properties.getValue("font").scale(this.scale)}get effect3d(){return this.properties.getValue("effect_3d")}get stateCount(){return this.properties.getValue("state_count")}get bulbBorder(){return this.scale*this.properties.getValue("bulb_border")}get bulbBorderColor(){return this.properties.getValue("bulb_border_color")}get offLabel(){return this.properties.getValue("off_label")}get offColor(){return this.properties.getValue("off_color")}get onLabel(){return this.properties.getValue("on_label")}get onColor(){return this.properties.getValue("on_color")}get stateLabelFallback(){return this.properties.getValue("state_label_fallback")}get stateColorFallback(){return this.properties.getValue("state_color_fallback")}}const Se=g(45),Ve=(1-Math.sin(Se)/2)/(2*Math.cos(Se));class Ae extends Dt{constructor(t,e){super(t,e),this.properties.add(new z("color_hi")),this.properties.add(new z("color_hihi")),this.properties.add(new z("color_lo")),this.properties.add(new z("color_lolo")),this.properties.add(new U("font")),this.properties.add(new $("level_hi")),this.properties.add(new $("level_hihi")),this.properties.add(new $("level_lo")),this.properties.add(new $("level_lolo")),this.properties.add(new j("log_scale")),this.properties.add(new $("maximum")),this.properties.add(new $("minimum")),this.properties.add(new z("needle_color")),this.properties.add(new j("ramp_gradient")),this.properties.add(new U("scale_font")),this.properties.add(new j("show_hi")),this.properties.add(new j("show_hihi")),this.properties.add(new j("show_lo")),this.properties.add(new j("show_lolo")),this.properties.add(new j("show_ramp",!0)),this.properties.add(new N("value_label_format"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){if(t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}}drawRamp(t){const e=String(this.minimum),i=t.measureText(e,this.scaleFont),s=String(this.maximum),r=t.measureText(s,this.scaleFont),o=Math.max(i.width,r.width)/2;let h=this.height,n=this.width;h>Ve*(n-2*o)&&(h=Math.floor(Ve*(n-2*o)));const a=h/(1-Math.sin(Se)/2),d={x:Math.floor(this.x-a*(1-Math.cos(Se))+o),y:this.y,width:Math.floor(2*a),height:Math.floor(2*a)},{rampWidth:c}=this,p=l(d,d.width/4-c,d.height/4-c);p.width=Math.min(p.width,p.height),p.height=p.width;const g=new fe(c,135,45);g.lolo=this.levelLoLo,g.loloColor=this.colorLoLo,g.showLoLo=!0,g.lo=this.levelLo,g.loColor=this.colorLo,g.showLo=!0,g.hi=this.levelHi,g.hiColor=this.colorHi,g.showHi=!0,g.hihi=this.levelHiHi,g.hihiColor=this.colorHiHi,g.showHiHi=!0,g.minimum=this.minimum,g.maximum=this.maximum,g.gradient=this.rampGradient,g.logScale=this.logScale,g.draw(t,d,p),this.drawNeedle(t,d,g);const u=E.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&void 0!==this.pv.value){const e=this.format(this.pv.value),i=t.measureText(e,u);t.fillText({x:d.x+d.width/2-i.width/2,y:d.y+d.height/2-d.height/4-(g.getRadius()-d.height/4)/2-i.height/2,align:"left",baseline:"top",font:u,text:e,color:this.foregroundColor})}}drawNeedle(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o;if(this.pv&&void 0!==this.pv.value){const t=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(t),this.maximum>this.minimum?t>this.maximum?o+=8:t<this.minimum&&(o-=8):t>this.minimum?o-=8:t<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);const h=g(o),{needleWidth:n,gapBetweenNeedleScale:l,scale:d}=this,c=a(s+e.width/4,r-n/2+3*d,s,r,h),p=a(s+i.getRadius()-l,r,s,r,h),u=a(s+e.width/4,r+n/2-3*d,s,r,h);t.fillPath({color:this.needleColor,path:new v(c.x,c.y).lineTo(p.x,p.y).lineTo(u.x,u.y).closePath()})}get needleWidth(){return 16*this.scale}get gapBetweenNeedleScale(){return-5*this.scale}get rampWidth(){return 12*this.scale}format(t){return this.valueLabelFormat?new me(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get font(){return this.properties.getValue("font").scale(this.scale)}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get needleColor(){return this.properties.getValue("needle_color")}get rampGradient(){return this.properties.getValue("ramp_gradient")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showRamp(){return this.properties.getValue("show_ramp")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class Le extends Dt{constructor(t,e){super(t,e),this.properties.add(new z("color_hi")),this.properties.add(new z("color_hihi")),this.properties.add(new z("color_lo")),this.properties.add(new z("color_lolo")),this.properties.add(new z("color_fillbackground")),this.properties.add(new j("effect_3d")),this.properties.add(new z("fill_color")),this.properties.add(new j("fillcolor_alarm_sensitive",!1)),this.properties.add(new U("font")),this.properties.add(new j("horizontal")),this.properties.add(new j("indicator_mode")),this.properties.add(new G("level_hi")),this.properties.add(new G("level_hihi")),this.properties.add(new G("level_lo")),this.properties.add(new G("level_lolo")),this.properties.add(new j("limits_from_pv")),this.properties.add(new j("log_scale")),this.properties.add(new G("maximum")),this.properties.add(new G("major_tick_step_hint")),this.properties.add(new G("minimum")),this.properties.add(new G("origin",0)),this.properties.add(new j("origin_ignored",!0)),this.properties.add(new U("scale_font")),this.properties.add(new N("scale_format")),this.properties.add(new j("show_hi")),this.properties.add(new j("show_hihi")),this.properties.add(new j("show_label")),this.properties.add(new j("show_lo")),this.properties.add(new j("show_lolo")),this.properties.add(new j("show_markers")),this.properties.add(new j("show_minor_ticks")),this.properties.add(new j("show_scale")),this.properties.add(new j("transparent_background")),this.properties.add(new N("value_label_format"))}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=l(this.area,2*this.scale));const i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},e),{color:i})),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){const i=this.alarmSensitiveForegroundColor,s=new be(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawVertical(t,e.x,e.y,e.height,!0);let o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,s,e)),this.drawVerticalBar(t,s,{x:e.x+r,y:e.y+s.margin,width:e.width-r-o,height:e.height-2*s.margin})}drawVerticalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=E.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.width)}const l=i.x+i.width;if(this.showLoLo&&void 0!==s){const i=l-a-this.markerGap,r=Math.round(e.getValuePosition(s));t.strokePath({path:new v(i,r).lineTo(i-this.markerTickLength,r),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:r,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(r));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(o));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(h));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawVerticalBar(e,i,s){var r;const{outlineWidth:o}=this;if(e.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const i=e.createLinearGradient(s.x,0,s.x+s.width,0);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},s),{gradient:i}));const r=l(s,o/2);e.strokeRect(Object.assign(Object.assign({},r),{color:t.GRAY,lineWidth:o}))}const h=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(i.getValuePosition(this.getFillValue())),n=s.width,a=this.thumbBreadth,l=p([{x:0,y:a/2},{x:n/2,y:0},{x:n-1,y:a/2},{x:n/2,y:a}],s.x,r-a/2),d=v.fromPoints(l);if(this.effect3d){const{x:i,y:s}=l[0],{x:r,y:n}=l[2],a=e.createLinearGradient(i,s,r,n);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillPath({path:d,gradient:a}),e.strokePath({path:d,color:t.GRAY,lineWidth:o})}else e.fillPath({path:d,color:h})}else{let r=this.originIgnored?this.min:this.origin,n=this.getFillValue();if(n<r){const t=r;r=n,n=t}const a=Math.round(i.getValuePosition(r)),d=Math.round(i.getValuePosition(n)),c=l(Object.assign(Object.assign({},s),{y:a,height:d-a}),o);if(e.fillRect(Object.assign(Object.assign({},c),{color:h})),this.effect3d){const i=e.createLinearGradient(c.x,0,c.x+c.width,0);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},c),{gradient:i}))}}const n=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==n&&e.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(n)})}drawHorizontal(t,e){const i=this.alarmSensitiveForegroundColor,s=new be(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawHorizontal(t,e.x,e.y+e.height,e.width);let o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,s,e)),this.drawHorizontalBar(t,s,{x:e.x+s.margin,y:e.y+o,width:e.width-2*s.margin,height:e.height-r-o})}drawHorizontalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=E.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.height)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.height)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.height)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.height)}const l=i.y;if(this.showLoLo&&void 0!==s){const i=Math.round(e.getValuePosition(s)),r=l+a+this.markerGap;t.strokePath({path:new v(i,r).lineTo(i,r+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const i=Math.round(e.getValuePosition(r)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const i=Math.round(e.getValuePosition(o)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const i=Math.round(e.getValuePosition(h)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawHorizontalBar(e,i,s){var r;const{outlineWidth:o}=this;if(e.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const i=e.createLinearGradient(0,s.y,0,s.y+s.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},s),{gradient:i}));const r=l(s,o/2);e.strokeRect(Object.assign(Object.assign({},r),{color:t.GRAY,lineWidth:o}))}const h=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(i.getValuePosition(this.getFillValue())),n=s.height,a=this.thumbBreadth,l=p([{x:a/2,y:0},{x:a,y:n/2},{x:a/2,y:n-1},{x:0,y:n/2}],r-a/2,s.y),d=v.fromPoints(l);if(this.effect3d){const{x:i,y:s}=l[0],{x:r,y:n}=l[2],a=e.createLinearGradient(i,s,r,n);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillPath({path:d,gradient:a}),e.strokePath({path:d,color:t.GRAY,lineWidth:o})}else e.fillPath({path:d,color:h})}else{let r=this.originIgnored?this.min:this.origin,n=this.getFillValue();if(n<r){const t=r;r=n,n=t}const a=Math.round(i.getValuePosition(r)),d=Math.round(i.getValuePosition(n)),c=l(Object.assign(Object.assign({},s),{x:a,width:d-a}),o);if(e.fillRect(Object.assign(Object.assign({},c),{color:h})),this.effect3d){const i=e.createLinearGradient(0,c.y,0,c.y+c.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},c),{gradient:i}))}}const n=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==n&&e.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(n)})}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get thumbBreadth(){return 13*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new me(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get effect3d(){return this.properties.getValue("effect_3d")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get indicatorMode(){return this.properties.getValue("indicator_mode")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get origin(){return this.properties.getValue("origin")}get originIgnored(){return this.properties.getValue("origin_ignored")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showLabel(){return this.properties.getValue("show_label")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}const Ce=new t(160,160,160);class ke extends Dt{constructor(t,e){super(t,e),this.properties.add(new z("color_hi")),this.properties.add(new z("color_hihi")),this.properties.add(new z("color_lo")),this.properties.add(new z("color_lolo")),this.properties.add(new z("color_fillbackground")),this.properties.add(new j("effect_3d")),this.properties.add(new z("fill_color")),this.properties.add(new j("fillcolor_alarm_sensitive",!1)),this.properties.add(new G("level_hi")),this.properties.add(new G("level_hihi")),this.properties.add(new G("level_lo")),this.properties.add(new G("level_lolo")),this.properties.add(new j("limits_from_pv")),this.properties.add(new j("log_scale")),this.properties.add(new G("maximum")),this.properties.add(new G("major_tick_step_hint")),this.properties.add(new G("minimum")),this.properties.add(new U("scale_font")),this.properties.add(new N("scale_format")),this.properties.add(new j("show_hi")),this.properties.add(new j("show_hihi")),this.properties.add(new j("show_lo")),this.properties.add(new j("show_lolo")),this.properties.add(new j("show_markers")),this.properties.add(new j("show_minor_ticks")),this.properties.add(new j("show_scale")),this.properties.add(new j("transparent_background"))}draw(t){const{scale:e,min:i,max:s}=this;let r=this.area;this.borderAlarmSensitive&&(r=l(r,2*e));const o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},r),{color:o}));const h=this.alarmSensitiveForegroundColor,n=new be(e,this.scaleFont,i,s,this.logScale,this.majorTickStepHint,h,this.showMinorTicks,this.showScale);n.scaleFormat=this.scaleFormat;const a=n.drawVertical(t,r.x,r.y,r.height,!0);let d=0;this.showMarkers&&(d=this.drawMarkers(t,r,n)),this.drawTank(t,r,a,d,n)}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=E.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.width)}const l=e.x+e.width-a-this.markerGap-this.markerTickLength;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const e=Math.round(i.getValuePosition(h));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawTank(e,i,s,r,o){const h=this.alarmSensitiveForegroundColor,{scale:n,outlineWidth:a}=this,d=i.x+s,c=i.y+o.margin,p=i.width-s-r,g=i.height-2*o.margin;let u=this.defaultCorner,m=.55;p<2*u&&(m=.6);const f=Math.floor(p*m);u>2*f-p-2*a&&(u=2*f-p);const x=o.getValuePosition(this.getFillValue()),w=this.alarmSensitiveFillColor;if(this.effect3d){e.fillRect({x:d,y:c,width:p,height:g,rx:u/2,ry:u/2,color:t.WHITE});let i=e.createLinearGradient(d,c,d+f+2*n,c);i.addColorStop(0,this.colorFillbackground.toString()),i.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:d,y:c,width:f,height:g,rx:u/2,ry:u/2,gradient:i}),i=e.createLinearGradient(d+p-f-2*n,c,d+p,c),i.addColorStop(0,t.WHITE.withAlpha(0).toString()),i.addColorStop(1,this.colorFillbackground.toString()),e.fillRect({x:d+p-f,y:c,width:f,height:g,rx:u/2,ry:u/2,gradient:i});const s=x,r=c+g-x;i=e.createLinearGradient(d,s,d+f+2*n,s),i.addColorStop(0,w.toString()),i.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:d,y:s,width:f,height:r,rx:u/2,ry:u/2,gradient:i}),i=e.createLinearGradient(d+p-f-2*n,s,d+p,s),i.addColorStop(0,t.WHITE.withAlpha(0).toString()),i.addColorStop(1,w.toString()),e.fillRect({x:d+p-f,y:s,width:f,height:r,rx:u/2,ry:u/2,gradient:i})}else e.fillRect({x:d,y:c,width:p,height:g,rx:u/2,ry:u/2,color:this.colorFillbackground}),e.fillRect({x:d,y:x,width:p,height:c+g-x,rx:u/2,ry:u/2,color:w});let y=l({x:d,y:c,width:p,height:g},a/2);e.strokeRect(Object.assign(Object.assign({},y),{rx:u/2,ry:u/2,color:this.effect3d?Ce:h,lineWidth:a}))}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get defaultCorner(){return 15*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get effect3d(){return this.properties.getValue("effect_3d")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}}class Pe extends Dt{constructor(t,e){super(t,e),this.properties.add(new U("font")),this.properties.add(new $("format_type")),this.properties.add(new $("horizontal_alignment")),this.properties.add(new $("precision")),this.properties.add(new j("precision_from_pv")),this.properties.add(new $("vertical_alignment"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){const e=t.ctx;if(this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}e.fillStyle=this.alarmSensitiveForegroundColor.toString(),e.font=this.font.getFontString();const{scale:i}=this;let s=this.area;this.borderAlarmSensitive&&(s=l(s,2*i,2*i));let r=s.x;0===this.horizAlignment?e.textAlign="start":1===this.horizAlignment?(r+=s.width/2,e.textAlign="center"):2===this.horizAlignment&&(r+=s.width,e.textAlign="end");let o=s.y;0===this.vertAlignment?e.textBaseline="top":1===this.vertAlignment?(o+=s.height/2,e.textBaseline="middle"):2===this.vertAlignment&&(o+=s.height,e.textBaseline="bottom");let h=this.text;if(this.pv&&void 0!==this.pv.value){const t=this.precisionFromPV?this.pv.precision:this.precision;h=this.pv.formatValue(this.formatType,t)}e.fillText(h,r,o)}get font(){return this.properties.getValue("font").scale(this.scale)}get formatType(){return this.properties.getValue("format_type")}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get precision(){return this.properties.getValue("precision")}get precisionFromPV(){return this.properties.getValue("precision_from_pv")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}}const Me=new t(160,160,160);class Re extends Dt{constructor(t,e){super(t,e),this.properties.add(new z("color_hi")),this.properties.add(new z("color_hihi")),this.properties.add(new z("color_lo")),this.properties.add(new z("color_lolo")),this.properties.add(new z("color_fillbackground")),this.properties.add(new z("fill_color")),this.properties.add(new j("fillcolor_alarm_sensitive",!1)),this.properties.add(new j("effect_3d")),this.properties.add(new G("level_hi")),this.properties.add(new G("level_hihi")),this.properties.add(new G("level_lo")),this.properties.add(new G("level_lolo")),this.properties.add(new j("limits_from_pv")),this.properties.add(new U("font")),this.properties.add(new j("log_scale")),this.properties.add(new G("maximum")),this.properties.add(new G("major_tick_step_hint")),this.properties.add(new G("minimum")),this.properties.add(new U("scale_font")),this.properties.add(new N("scale_format")),this.properties.add(new j("show_bulb")),this.properties.add(new j("show_hi")),this.properties.add(new j("show_hihi")),this.properties.add(new j("show_lo")),this.properties.add(new j("show_lolo")),this.properties.add(new j("show_markers")),this.properties.add(new j("show_minor_ticks")),this.properties.add(new j("show_scale")),this.properties.add(new j("transparent_background")),this.properties.add(new $("unit")),this.properties.add(new N("value_label_format"))}draw(e){var i;const{scale:s,min:r,max:o}=this;let h=this.area;this.borderAlarmSensitive&&(h=l(this.area,2*this.scale));const n=this.alarmSensitiveBackgroundColor,a=this.alarmSensitiveForegroundColor,d=this.alarmSensitiveFillColor;this.transparentBackground||e.fillRect(Object.assign(Object.assign({},h),{color:n}));let c=h.height;if(this.showBulb){let t=Math.min(h.width/2,this.bulbMaxDiameter);c=h.height<t?0:h.height-t}let p=Object.assign(Object.assign({},h),{height:c});const g=new be(s,this.scaleFont,r,o,this.logScale,this.majorTickStepHint,a,this.showMinorTicks,this.showScale);g.scaleFormat=this.scaleFormat;let u=0,m="";if(0===this.unit?m="°C":1===this.unit?m="°F":2===this.unit&&(m="K"),m){const t=E.ARIAL_9.scale(s),i=2*s;u=e.measureText(m,t).height+2*i,e.fillText({x:h.x+h.width/2-this.pipeWidth/2-i,y:h.y+i,baseline:"top",align:"right",color:a,font:t,text:m})}const f=p.x+p.width/2-this.pipeWidth/2-1*s,x=Object.assign(Object.assign({},p),{y:p.y+u,height:p.height-u+g.calculateMargin(e,!1)});g.drawVertical(e,f,x.y,x.height,!1);const w=Math.floor(this.pipeWidth/2);if(p=Object.assign(Object.assign({},p),{y:g.getValuePosition(o)-w,height:g.scaleLength+2*w}),this.drawPipe(e,p,g),this.showMarkers&&this.drawMarkers(e,h,g),this.showBulb){let o=Math.min(h.width/2,this.bulbMaxDiameter);const n=1*s,l=h.x+h.width/2,u=h.y+c+o/2,m=o/2,f=o/2;if(e.fillEllipse({cx:l,cy:u,rx:m,ry:f,color:d}),this.effect3d){const i=e.createLinearGradient(l-m,u-f,l+m,u+f);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,d.withAlpha(0).toString()),e.fillEllipse({cx:l,cy:u,rx:m,ry:f,gradient:i})}e.strokeEllipse({cx:l,cy:u,rx:m-n/2,ry:f-n/2,color:this.effect3d?Me:a,lineWidth:n});const x={x:Math.round(p.x+p.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(g.getValuePosition(r)),width:this.pipeWidth-2*this.outlineWidth,height:3*s};if(this.effect3d){const i=Math.round(p.x+p.width/2-this.pipeWidth/2),s=i+this.pipeWidth,r=e.createLinearGradient(i,x.y,s,x.y);r.addColorStop(0,t.WHITE.toString()),r.addColorStop(1,d.toString()),e.fillRect(Object.assign(Object.assign({},x),{gradient:r}))}else e.fillRect(Object.assign(Object.assign({},x),{color:d}));const w=null===(i=this.pv)||void 0===i?void 0:i.value;w&&e.fillText({x:l,y:u,align:"center",baseline:"middle",color:d.contrast(),font:this.font,text:this.format(w)})}}drawPipe(e,i,s){const{scale:r,outlineWidth:o,min:h,max:n}=this,a=this.alarmSensitiveForegroundColor,d=this.alarmSensitiveFillColor,c={x:Math.round(i.x+i.width/2-this.pipeWidth/2),y:i.y,width:this.pipeWidth,height:i.height},p=this.getFillValue();let g=s.getValuePosition(p);n>h?p>n?g-=10*r:p<h&&(g+=10*r):p>h?g+=10*r:p<n&&(g-=10*r);const u=this.pipeWidth/2,{x:m,y:f,width:x,height:w}=c;if(this.effect3d){let i=e.createLinearGradient(m,f,m+x,f);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.toString()),e.fillRect(Object.assign(Object.assign({},c),{rx:u/2,ry:u/2,gradient:i})),i=e.createLinearGradient(m,f,m+x,f),i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,d.toString()),e.fillRect({x:m,y:g,width:x,height:f+w-g,rx:u/2,ry:u/2,gradient:i})}else e.fillRect(Object.assign(Object.assign({},c),{rx:u/2,ry:u/2,color:this.colorFillbackground})),e.fillRect({x:m,y:g,width:x,height:f+w-g,rx:u/2,ry:u/2,color:d});let y=l(c,o/2);e.strokeRect(Object.assign(Object.assign({},y),{rx:u/2,ry:u/2,color:this.effect3d?Me:a,lineWidth:o}))}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=E.ARIAL_9.scale(this.scale),a=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const e=Math.round(i.getValuePosition(h));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get pipeWidth(){return 15*this.scale}get bulbMaxDiameter(){return 40*this.scale}get outlineWidth(){return 1*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new me(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get effect3d(){return this.properties.getValue("effect_3d")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showBulb(){return this.properties.getValue("show_bulb")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}get unit(){return this.properties.getValue("unit")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class Ee{constructor(t,e){this.widget=t,this.index=e}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return 0!==this.timeFormat}isHorizontal(){return 0===this.index||1!==this.index&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){var t;return null!==(t=this._effectiveMinimum)&&void 0!==t?t:this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){var t;return null!==(t=this._effectiveMaximum)&&void 0!==t?t:this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){const t=this.widget.calculateAutoscaledRange(this);t&&(this.effectiveMinimum=t.start,this.effectiveMaximum=t.stop,this.widget.requestRepaint())}applyZoom(t,e){let i,s,r=this.effectiveMinimum,o=this.effectiveMaximum;if(this.logScale){o=Math.log10(o),r=Math.log10(r);const h=Math.log10(t)*e,n=1-e;i=h+r*n,s=h+o*n,i<-323.3062&&(i=-323.3062),i=Math.pow(10,i),s>308.2547&&(s=308.2547),s=Math.pow(10,s)}else{const h=Math.max(Math.abs(r),Math.abs(o));r/=h,o/=h;const n=t/h*e,a=1-e;i=(n+r*a)*h,s=(n+o*a)*h}this.effectiveMinimum=i,this.effectiveMaximum=s,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}}class We{constructor(t,e){this.xAxis=t,this.yAxis=e,this.beforeXRanges=[],this.beforeYRanges=[],this.afterXRanges=[],this.afterYRanges=[];for(const e of t)this.beforeXRanges.push({min:e.effectiveMinimum,max:e.effectiveMaximum});for(const t of e)this.beforeYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}saveState(){for(const t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(const t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.beforeXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.beforeYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}redo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.afterXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}}class Be{constructor(){this.undoStack=[],this.redoStack=[]}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){const t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){const t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}}class Ie{constructor(t,e){this.widget=e,this.id=t}tooltip(){return this.widget.tooltip}mouseDown(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new We(i.getXAxes(),i.getYAxes())}}grab(t){var e;switch(null===(e=this.widget.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection=Object.assign(Object.assign({},this.grabStart.point),{width:t.dx,height:t.dy}),this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint()}}grabEnd(){var t;const{grabZoomCommand:e,selection:i,widget:s}=this;switch(null===(t=s.toolbar)||void 0===t?void 0:t.currentTool){case"rubberband-zoom":if(i){const t=new We(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"horizontal-zoom":if(i){const t=new We(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"vertical-zoom":if(i){const t=new We(s.getXAxes(),s.getYAxes());this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"panning":e&&(e.saveState(),s.toolbar.addCommand(e))}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"zoom-in":const e=new We(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,.1)}e.saveState(),i.toolbar.addCommand(e);break;case"zoom-out":const s=new We(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,-.1)}s.saveState(),i.toolbar.addCommand(s)}}rangeZoomXAxes(t){for(const e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),s=e.linearScale.getPositionValue(t.x+t.width);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}rangeZoomYAxes(t){for(const e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),s=e.linearScale.getPositionValue(t.y+t.height);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}pan(t){const{prevGrabEvent:e,widget:i}=this;if(e){const s=e.dx-t.dx;if(0!==s)for(const t of i.getXAxes()){const e=t.linearScale,i=e.getMinMax(),r=e.getValuePosition(i.start)+s,o=e.getValuePosition(i.stop)+s;t.effectiveMinimum=e.getPositionValue(r),t.effectiveMaximum=e.getPositionValue(o)}const r=e.dy-t.dy;if(0!==r)for(const t of i.getYAxes()){const e=t.linearScale,i=e.getMinMax(),s=e.getValuePosition(i.start)+r,o=e.getValuePosition(i.stop)+r;t.effectiveMinimum=e.getPositionValue(s),t.effectiveMaximum=e.getPositionValue(o)}}}}class Oe{constructor(t){this.pointer=0,this.samples=[],this.samples=Array(t).fill(void 0)}push(t,e){this.samples[this.pointer]={x:t,y:e},this.pointer=(this.pointer+1)%this.samples.length}clear(){this.samples.fill(void 0),this.pointer=0}isFull(){const t=(this.pointer+1)%this.samples.length;return void 0!==this.samples[t]}isEmpty(){return void 0===this.tail()}tail(){return 0===this.pointer?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t){return this.samples.filter((t=>void 0!==t)).sort(((t,e)=>t.x-e.x))}{const t=this.samples.slice(this.pointer).filter((t=>void 0!==t)),e=this.samples.slice(0,this.pointer).filter((t=>void 0!==t));return t.concat(e)}}}class He{constructor(t,e,i,s,r){this.bufferSize=t,this.plotMode=e,this.updateMode=i,this.concatenateData=s,this.chronological=r,this.x=0,this.xPending=!1,this.y=0,this.yTimestamp=0,this.yPending=!1,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1,this.traceData=new Oe(t)}clear(){this.traceData.clear(),this.x=0,this.xPending=!1,this.y=0,this.yPending=!1,this.yTimestamp=0,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1}snapshot(){return this.traceData.snapshot()}updateX(t){this.x=t,this.xPending=!0,this.maybeAddPoint()}updateY(t,e){this.y=t,this.yTimestamp=e,this.yPending=!0,this.maybeAddPoint()}updateXArray(t){this.xArray=t,this.xArrayPending=!0,this.maybeAddArray()}updateYArray(t){this.yArray=t,this.yArrayPending=!0,this.maybeAddArray()}maybeAddPoint(){if(1===this.plotMode&&this.traceData.isFull())return;const{xPending:t,yPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addPoint():1===s?(i&&e||!i&&t&&e)&&this.addPoint():2===s?(i&&e||!i&&t)&&this.addPoint():3===s&&this.yPending&&this.addPoint()}maybeAddArray(){if(1===this.plotMode&&this.traceData.isFull())return;const{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addArray():1===s?(i&&e||!i&&t&&e)&&this.addArray():2===s?(i&&e||!i&&t)&&this.addArray():3===s&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(5===this.updateMode)t=(new Date).getTime();else if(void 0!==this.yTimestamp)t=this.yTimestamp;else{const e=this.traceData.tail();t=e?e.x+1:0}this.traceData.push(t,this.y),this.xPending=!1,this.yPending=!1}addArray(){this.concatenateData||this.traceData.clear();let{xArray:t,yArray:e}=this;if(this.chronological)if(t=Array(e.length),this.traceData.isEmpty())for(let i=0;i<e.length;i++)t[i]=i;else{const i=this.traceData.tail();for(let s=1;s<e.length;s++)t[s-1]=i.x+s}let i=Math.min(t.length,e.length),s=Math.min(i,this.bufferSize);for(let i=0;i<s;i++)this.traceData.push(t[i],e[i]);this.xArrayPending=!1,this.yArrayPending=!1}}class Fe{constructor(t,e){this.widget=t,this.i=e,this.xPVListener=()=>{var t,e;const i=this.xPVInstance;if(i)if(Array.isArray(i.value))null===(t=this.traceData)||void 0===t||t.updateXArray(i.value);else{const t=i.toNumber();null!=t&&(null===(e=this.traceData)||void 0===e||e.updateX(t))}},this.yPVListener=()=>{var t,e,i;const s=this.yPVInstance;if(s)if(Array.isArray(s.value))null===(t=this.traceData)||void 0===t||t.updateYArray(s.value);else{const t=this.widget.getAxis(this.xAxisIndex),r=s.toNumber();if(null!=r)if(t.isDateEnabled()){const t=(s.time||new Date).getTime();null===(e=this.traceData)||void 0===e||e.updateY(r,t)}else null===(i=this.traceData)||void 0===i||i.updateY(r)}}}init(){const{bufferSize:t,plotMode:e,updateMode:i,concatenateData:s}=this,r=!this.xPV;this.traceData=new He(t,e,i,s,r),this.xPV&&(this.xPVInstance=this.widget.display.pvEngine.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=this.widget.display.pvEngine.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),this.widget.addPropertyListener(`trace_${this.i}_x_pv`,(()=>{var t;const e=this.widget.display.pvEngine.createPV(this.xPV);e!==this.xPVInstance&&(null===(t=this.xPVInstance)||void 0===t||t.removeListener(this.xPVListener),this.xPVInstance=e,this.xPVInstance.addListener(this.xPVListener))})),this.widget.addPropertyListener(`trace_${this.i}_y_pv`,(()=>{var t;const e=this.widget.display.pvEngine.createPV(this.yPV);e!==this.yPVInstance&&(null===(t=this.yPVInstance)||void 0===t||t.removeListener(this.yPVListener),this.yPVInstance=e,this.yPVInstance.addListener(this.yPVListener))}))}snapshot(){var t;return(null===(t=this.traceData)||void 0===t?void 0:t.snapshot())||[]}drawTrace(t,e){const{lineWidth:i}=this;if(0===this.traceType)t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i});else if(1===this.traceType)t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(2===this.traceType);else if(3===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(const r of e)t.strokePath({path:new v(r.x,r.y).lineTo(r.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(4===this.traceType||5===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];t.fillPath({path:new v(r.x,r.y).lineTo(r.x,s).lineTo(o.x,s).lineTo(o.x,o.y),color:this.traceColor,opacity:100/255})}5===this.traceType&&t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(6===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];t.strokePath({path:new v(r.x,r.y).lineTo(r.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(7===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];t.strokePath({path:new v(r.x,r.y).lineTo(o.x,r.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(8===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s]})}else if(9===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s,2*s,2*s]})}else if(10===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*s,2*s]})}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;const i=this.pointSize/2,s=e.x,r=e.y;switch(this.pointStyle){case 1:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 3:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 4:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(s-i,r-i,2*i,2*i);break;case 7:t.ctx.fillRect(s-i,r-i,2*i,2*i);break;case 8:case 9:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r),t.ctx.lineTo(s,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(s-i,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.moveTo(s+i,r-i),t.ctx.lineTo(s-i,r+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s+i,r),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke()}}clearData(){var t;null===(t=this.traceData)||void 0===t||t.clear()}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`trace_${this.i}_${t}`)}get antiAlias(){return this.getValue("anti_alias")}get bufferSize(){return this.getValue("buffer_size")}get concatenateData(){return this.getValue("concatenate_data")}get lineWidth(){return this.scale*this.getValue("line_width")}get name(){return this.getValue("name")}get plotMode(){return this.getValue("plot_mode")}get pointSize(){return this.scale*this.getValue("point_size")}get pointStyle(){return this.getValue("point_style")}get traceColor(){return this.getValue("trace_color")}get traceType(){return this.getValue("trace_type")}get updateDelay(){return this.getValue("update_delay")}get updateMode(){return this.getValue("update_mode")}get visible(){return this.getValue("visible")}get xAxisIndex(){return this.getValue("x_axis_index")}get xPV(){return this.getValue("x_pv")}get yAxisIndex(){return this.getValue("y_axis_index")}get yPV(){return this.getValue("y_pv")}}const Ne=new t(236,236,236),De=new t(130,130,130);class $e{constructor(t,e,i,s,r){this.imageFile=e,this.disabledImageFile=i,this.action=r,this.imageElement=new Image,this.disabledImageElement=new Image,this.toggleButton=!1,this.toolButton=!1,this.pushed=!1,this.disabled=!1,this.loadPromise=new Promise(((t,e)=>{this.imageElement.onload=()=>t()})),this.disabledLoadPromise=new Promise(((t,e)=>{this.disabledImageElement.onload=()=>t()})),this.region={id:`${t.xyGraph.wuid}-${e}`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,t.xyGraph.requestRepaint())},mouseOut:()=>{this.toggleButton||(this.pushed=!1),t.xyGraph.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,t.xyGraph.requestRepaint())},click:()=>{this.toggleButton&&(this.pushed=!this.pushed,this.toolButton&&t.toggleTool(this)),this.action(),t.updateState()},tooltip:()=>s}}loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}}class Ge{constructor(t){this.xyGraph=t,this.buttons=[],this.imagesLoaded=!1,this.currentTool="default",this.commandBuffer=new Be,this.showLegend=this.createToggleButton("ShowLegend.png","Show Legend",(()=>{t.properties.setValue("show_legend",this.showLegend.pushed)})),this.showLegend.pushed=t.showLegend,t.addPropertyListener("show_legend",(t=>{this.showLegend.pushed=t})),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",(()=>{const e=new We(t.getXAxes(),t.getYAxes());t.performAutoScale(),e.saveState(),this.addCommand(e)})),this.rubberbandZoom=this.createToolButton("RubberbandZoom.png","Rubberband Zoom",(()=>{this.rubberbandZoom.pushed?(this.currentTool="rubberband-zoom",t.setCursor("crosshair"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.horizontalZoom=this.createToolButton("HorizontalZoom.png","Horizontal Zoom",(()=>{this.horizontalZoom.pushed?(this.currentTool="horizontal-zoom",t.setCursor("col-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.verticalZoom=this.createToolButton("VerticalZoom.png","Vertical Zoom",(()=>{this.verticalZoom.pushed?(this.currentTool="vertical-zoom",t.setCursor("row-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomIn=this.createToolButton("ZoomIn.png","Zoom In",(()=>{this.zoomIn.pushed?(this.currentTool="zoom-in",t.setCursor("zoom-in"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomOut=this.createToolButton("ZoomOut.png","Zoom Out",(()=>{this.zoomOut.pushed?(this.currentTool="zoom-out",t.setCursor("zoom-out"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.panning=this.createToolButton("Panning.png","Panning",(()=>{this.panning.pushed?(this.currentTool="panning",t.setCursor("grab"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.mouseArrow=this.createToolButton("MouseArrow.png","None",(()=>{this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0})),this.undo=this.createButton("Undo.png","Undo_Gray.png","Undo",(()=>{this.commandBuffer.undo()})),this.undo.disabled=!0,this.redo=this.createButton("Redo.png","Redo_Gray.png","Redo",(()=>{this.commandBuffer.redo()})),this.redo.disabled=!0,this.camera=this.createButton("camera.png","camera.png","Save Snapshot to PNG File",(()=>{const e=document.createElement("a");try{e.href=t.toDataURL(),e.download=`${t.name}_export.png`,document.body.appendChild(e),e.click()}finally{document.body.removeChild(e)}})),this.toggleTool(this.mouseArrow);const e=this.buttons.map((t=>t.loadPromise)).concat(this.buttons.map((t=>t.disabledLoadPromise)));Promise.all(e).finally((()=>{this.imagesLoaded=!0,t.requestRepaint()}));for(const e of this.buttons)e.loadImage(t.display.imagesPrefix)}updateState(){this.undo.disabled=!this.commandBuffer.canUndo(),this.redo.disabled=!this.commandBuffer.canRedo(),this.xyGraph.requestRepaint()}addCommand(t){this.commandBuffer.add(t),this.updateState()}toggleTool(t){const e=t.pushed;for(const t of this.buttons)t.toolButton&&(t.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){const s=this.createToggleButton(t,e,i);return s.toolButton=!0,s}createToggleButton(t,e,i){const s=this.createButton(t,t,e,i);return s.toggleButton=!0,s}createButton(t,e,i,s){const r=new $e(this,t,e,i,s);return this.buttons.push(r),r}draw(t,e){const{buttonSize:i}=this,s={x:e.x,y:e.y};return this.drawButton(t,s.x,s.y,this.showLegend),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.autoScale),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.rubberbandZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.horizontalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.verticalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomIn),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomOut),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.panning),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.mouseArrow),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.undo),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.redo),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.camera),s.x+=i,s.y+i-e.y}maybeWrap(t,e,i){i=null!=i?i:this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){const{buttonSize:s}=this,r=1*this.scale,o=Math.round(e+s/4)-r/2;t.strokePath({path:new v(o,i).lineTo(o,i+s),color:De,lineWidth:r})}drawButton(e,i,s,r){const{buttonSize:o,scale:h}=this;e.fillRect({x:i,y:s,width:o,height:o,color:Ne}),this.xyGraph.enabled&&!r.disabled&&e.addHitRegion(r.region).addRect(i,s,o,o);const n=1*h,a=Math.round(s+n/2)-.5,l=Math.round(i+n/2)-.5,d=Math.round(s+o-n+n/2)-.5,c=Math.round(i+o-n+n/2)-.5;if(e.strokePath({color:r.pushed?t.WHITE:t.BLACK,path:new v(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d),lineWidth:n}),e.strokePath({color:r.pushed?t.BLACK:t.WHITE,path:new v(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,d-n),lineWidth:n}),this.imagesLoaded){const t=r.disabled?r.disabledImageElement:r.imageElement,n=t.naturalHeight*h,a=t.naturalWidth*h,l=Math.round(i+(o-a)/2),d=Math.round(s+(o-n)/2);e.ctx.drawImage(t,l,d,a,n)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}}class je extends Dt{constructor(t,e){super(t,e),this.axes=[],this.traces=[],this.autoScaleAllowed=!0,this.properties.add(new $("axis_count")),this.properties.add(new z("plot_area_background_color")),this.properties.add(new j("show_legend")),this.properties.add(new j("show_plot_area_border")),this.properties.add(new j("show_toolbar")),this.properties.add(new N("title")),this.properties.add(new U("title_font")),this.properties.add(new $("trace_count")),this.properties.add(new j("transparent")),this.properties.addGenerator((()=>{const t=[];this.axes=[];const e=this.properties.getValue("axis_count");for(let i=0;i<e;i++)this.axes.push(new Ee(this,i)),t.push(new j(`axis_${i}_auto_scale`),new G(`axis_${i}_auto_scale_treshold`),new z(`axis_${i}_axis_color`),new N(`axis_${i}_axis_title`),new j(`axis_${i}_dash_grid_line`),new z(`axis_${i}_grid_color`),new j(`axis_${i}_log_scale`),new G(`axis_${i}_maximum`),new G(`axis_${i}_minimum`),new U(`axis_${i}_scale_font`),new N(`axis_${i}_scale_format`),new j(`axis_${i}_show_grid`),new $(`axis_${i}_time_format`),new U(`axis_${i}_title_font`),new j(`axis_${i}_visible`)),i>1&&t.push(new j(`axis_${i}_left_bottom_side`),new j(`axis_${i}_y_axis`));this.traces=[];const i=this.properties.getValue("trace_count");for(let e=0;e<i;e++)this.traces.push(new Fe(this,e)),t.push(new j(`trace_${e}_anti_alias`),new $(`trace_${e}_buffer_size`),new j(`trace_${e}_concatenate_data`),new $(`trace_${e}_line_width`),new N(`trace_${e}_name`),new $(`trace_${e}_plot_mode`),new $(`trace_${e}_point_size`),new $(`trace_${e}_point_style`),new z(`trace_${e}_trace_color`),new $(`trace_${e}_trace_type`),new $(`trace_${e}_update_delay`),new $(`trace_${e}_update_mode`),new j(`trace_${e}_visible`),new $(`trace_${e}_x_axis_index`),new N(`trace_${e}_x_pv`),new D(`trace_${e}_x_pv_value`,`trace_${e}_x_pv`),new $(`trace_${e}_y_axis_index`),new N(`trace_${e}_y_pv`),new D(`trace_${e}_y_pv_value`,`trace_${e}_y_pv`));return t}))}init(){this.plotAreaRegion=new Ie(`${this.wuid}-plotarea`,this),this.traces.forEach((t=>t.init()))}draw(t){var e;const{scale:i}=this;let s=this.area;if(this.borderAlarmSensitive&&(s=l(this.area,2*i)),!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},s),{color:e}))}this.showToolbar&&this.drawToolbar(t,s),this.title&&this.drawTitle(t,s);for(const t of this.axes){if(t.autoScale&&this.autoScaleAllowed){const e=this.calculateAutoscaledRange(t);e&&(t.effectiveMinimum=e.start,t.effectiveMaximum=e.stop)}const e=t.effectiveMinimum,s=t.effectiveMaximum;t.linearScale=new be(i,t.scaleFont,e,s,t.logScale,50*i,t.axisColor,!0,t.visible),t.linearScale.scaleFormat=t.scaleFormat,t.linearScale.timeFormat=t.timeFormat}this.showLegend&&this.drawLegend(t,s),t.addHitRegion(this.plotAreaRegion).addRect(s.x,s.y,s.width,s.height);const r=this.drawAxes(t,s);this.drawPlotArea(t,r);const o=null===(e=this.plotAreaRegion)||void 0===e?void 0:e.selection;o&&this.drawZoomSelection(t,r,function(t,e){let i=t.x,s=t.y,r=i+t.width,o=s+t.height;if(r<i){const t=i;i=r,r=t}if(o<s){const t=s;s=o,o=t}let h=e.x,n=e.y,a=h+e.width,l=n+e.height;if(a<h){const t=h;h=a,a=t}if(l<n){const t=n;n=l,l=t}const d=Math.max(i,h),c=Math.max(s,n);return{x:d,y:c,width:Math.min(r,a)-d,height:Math.min(o,l)-c}}(r,o))}drawToolbar(t,e){this.toolbar||(this.toolbar=new Ge(this));const i=3*this.scale,s=l(e,i),r=this.toolbar.draw(t,s);e.y+=i+r+i,e.height-=i+r+i}drawTitle(t,e){const i=t.measureText(this.title,this.titleFont).height;t.fillText({x:e.x+e.width/2,y:e.y+i/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.titleFont,text:this.title});const s=2*this.scale;e.y+=i+s,e.height-=i+s}drawAxes(t,e){const{scale:i}=this,s=5*i,r=Object.assign({},e);let o=0;for(const e of this.getXAxes())if(e.visible){let i=0;e.axisTitle&&(i=s+t.measureText(e.axisTitle,e.titleFont).height),o+=i+e.linearScale.measureHorizontalHeight(t)}let h=0,n=0;for(const a of this.getYAxes().reverse()){const l=a.linearScale;if(a.visible){const d=l.calculateMargin(t,!1),c=r.height-o+(o>0?d:0);let p=0;a.axisTitle&&(p=t.measureText(a.axisTitle,a.titleFont).height,t.ctx.save(),t.ctx.translate(r.x+s+p/2,e.y+c/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:a.titleFont,color:a.axisColor,text:a.axisTitle}),t.ctx.restore(),p+=s);const g=p+l.drawVertical(t,r.x+p,e.y,c,!0,!1);r.x+=g,r.width-=g,h+=g;const u=l.margin;n=0===n?u:Math.min(n,u);const m=1*i,f=Math.round(r.x)-m/2,x=Math.round(e.y+d)-m/2;t.strokePath({path:new v(f,x).lineTo(f,x+c-2*d),color:a.axisColor,opacity:100/255,lineWidth:m})}else{const t=r.height-o;l.setDimensions(0,e.y,t,!1)}}let a=0;for(const o of this.getXAxes().reverse()){const n=o.linearScale;if(o.visible){const l=n.calculateMargin(t,!0),d=h-l;let c=0;if(o.axisTitle){c=t.measureText(o.axisTitle,o.titleFont).height;const i=e.x+h+(e.width-h)/2;t.fillText({x:i,y:r.y+r.height-c/2,align:"center",baseline:"middle",font:o.titleFont,color:o.axisColor,text:o.axisTitle}),c+=s}const p=c+n.drawHorizontal(t,e.x+d,r.y+r.height-c,e.width-d);r.height-=p;const g=n.margin;a=0===a?g:Math.min(a,g);const u=1*i,m=Math.round(e.x+d+l)-u/2,f=Math.round(r.y+r.height)-u/2;t.strokePath({path:new v(m,f).lineTo(m+r.width-l,f),color:o.axisColor,opacity:100/255,lineWidth:u})}else{const t=e.x+h,i=e.width-h;n.setDimensions(t,0,i,!0)}}return r.y+=n,r.width-=a,r.height-=o>0?n:2*n,r}drawPlotArea(e,i){const{scale:s}=this,r=1*s;if(e.fillRect(Object.assign(Object.assign({},i),{color:this.plotAreaBackgroundColor})),this.showPlotAreaBorder){const{x:s,y:o,width:h,height:n}=l(i,r/2);e.strokePath({path:new v(s,o).lineTo(s+h,o).lineTo(s+h,o+n),color:t.BLACK,lineWidth:r})}for(const t of this.axes.filter((t=>t.visible&&t.showGrid))){const o=t.linearScale;if(t.isHorizontal())for(const h of o.getGridPositions()){const n=Math.round(o.getX()+h)-r/2;e.strokePath({path:new v(n,i.y).lineTo(n,i.y+i.height),color:t.gridColor,lineWidth:r,dash:t.dashGridLine?[6*s,2*s]:void 0})}else for(const h of o.getGridPositions()){const n=Math.round(o.getY()+h)-r/2;e.strokePath({path:new v(i.x,n).lineTo(i.x+i.width,n),color:t.gridColor,lineWidth:r,dash:t.dashGridLine?[6*s,2*s]:void 0})}}e.ctx.save(),e.ctx.beginPath(),e.ctx.rect(i.x,i.y,i.width,i.height),e.ctx.clip();for(const t of this.traces.filter((t=>t.visible))){const i=this.getAxis(t.xAxisIndex).linearScale,s=this.getAxis(t.yAxisIndex).linearScale,r=[];for(const e of t.snapshot()){const t=i.getValuePosition(e.x),o=s.getValuePosition(e.y);r.push({x:t,y:o})}if(r.length){t.drawTrace(e,r);for(const i of r)t.drawPoint(e,i)}}e.ctx.restore()}drawZoomSelection(e,i,s){var r;const{scale:o}=this;switch(null===(r=this.toolbar)||void 0===r?void 0:r.currentTool){case"rubberband-zoom":e.strokeRect(Object.assign(Object.assign({},s),{color:t.BLACK,lineWidth:1*o}));break;case"horizontal-zoom":const r=s;r.y=i.y,r.height=i.height,e.strokeRect(Object.assign(Object.assign({},d(r)),{color:t.BLACK,lineWidth:1*o}));break;case"vertical-zoom":const h=s;h.x=i.x,h.width=i.width,e.strokeRect(Object.assign(Object.assign({},d(h)),{color:t.BLACK,lineWidth:1*o}))}}drawLegend(t,e){const{scale:i}=this,s=25*i,r=2*i,o=5*i,h=E.ARIAL_10.scale(i);for(const n of this.getYAxes()){const a=this.traces.filter((t=>t.visible&&t.yAxisIndex===n.index)),d=[];let c=[],p=0,g=0;for(const i of a){let n=s+r+o;i.name&&(n+=t.measureText(i.name,h).width),p+n<e.width?(c.push(i),p+=n):(d.push(c),n=Math.max(n,p),c=[i],p=n)}if(c.length&&(d.push(c),g=Math.max(g,p)),!d.length)continue;const u=s*d.length,m={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-u),width:g,height:u};e.height-=m.height,t.fillRect(Object.assign(Object.assign({},m),{color:this.plotAreaBackgroundColor})),t.strokeRect(Object.assign(Object.assign({},l(m,1*i/2)),{color:n.axisColor}));let f=m.x,x=m.y;for(let e=0;e<d.length;e++){const n=d[e],a=x+e*s,l=a+s/2;for(const e of n){const n=e.pointSize>Math.floor((s-o)/2)?Math.floor(s-o):e.pointSize;switch(e.traceType){case 3:const r=f+s/2;t.strokePath({path:new v(r,a+n).lineTo(r,a+s),lineWidth:e.lineWidth,color:e.traceColor,opacity:100/255}),e.drawPoint(t,{x:r,y:a+n});break;case 4:case 5:const o=[{x:f,y:a+s/2},{x:f+s/2,y:a+n},{x:f+s,y:a+s/2},{x:f+s,y:a+s},{x:f,y:a+s}];t.fillPath({path:v.fromPoints(o),color:e.traceColor,opacity:100/255}),5===e.traceType&&t.strokePath({path:v.fromPoints(o.slice(0,3)),color:e.traceColor,lineWidth:1*i}),e.drawPoint(t,{x:f+s/2,y:a+n});break;default:e.drawTrace(t,[{x:f,y:l},{x:f+s,y:l}]),e.drawPoint(t,{x:f+s/2,y:l})}f+=s+r,e.name&&(t.fillText({x:f,y:l,align:"left",baseline:"middle",color:e.traceColor,font:h,text:e.name}),f+=t.measureText(e.name,h).width),f+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t){let e,i;const s=t.logScale;for(const r of this.traces)if(r.visible&&(this.axes[r.xAxisIndex]===t||this.axes[r.yAxisIndex]===t))for(const o of r.snapshot()){const r=t.isHorizontal()?o.x:o.y;(void 0===e||e>r)&&(!s||r>0)&&(e=r),(void 0===i||i<r)&&(!s||r>0)&&(i=r)}if(void 0!==e&&void 0!==i)return{start:e,stop:i}}performAutoScale(){for(const t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(const t of this.traces)t.clearData();this.requestRepaint()}getAxes(){return[...this.axes]}getXAxes(){return this.axes.filter((t=>t.isHorizontal()))}getYAxes(){return this.axes.filter((t=>t.isVertical()))}getAxis(t){return this.axes[t]}getTrace(t){return this.traces[t]}get axisCount(){return this.properties.getValue("axis_count")}get plotAreaBackgroundColor(){return this.properties.getValue("plot_area_background_color")}get showLegend(){return this.properties.getValue("show_legend")}get showPlotAreaBorder(){return this.properties.getValue("show_plot_area_border")}get showToolbar(){return this.properties.getValue("show_toolbar")}get title(){return this.properties.getValue("title")}get titleFont(){return this.properties.getValue("title_font").scale(this.scale)}get traceCount(){return this.properties.getValue("trace_count")}get transparent(){return this.properties.getValue("transparent")}}class ze extends Dt{constructor(t,e){super(t,e),this._widgets=[],this._connections=[],this.relativeScale=1,this.properties.add(new K("macros"))}expandContainerMacros(t){for(const e in this.macros.macros)t=(t=t.replace(`$(${e})`,this.macros.macros[e])).replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(const e of this.widgets){if(e.wuid===t)return e;if(e instanceof ze){const i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(const e of this.widgets){if(e.name===t)return e;if(e instanceof ze){const i=e.findWidgetByName(t);if(i)return i}}for(const e of this.connections)if(e.name===t)return e}closeMenu(){for(const t of this.widgets)t.closeMenu()}hide(){for(const t of this.widgets)t.hide()}destroy(){for(const t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue("macros")}}class Ue extends Dt{constructor(t){super(t),this.properties.clear(),this.properties.add(new $("arrow_length")),this.properties.add(new $("arrows")),this.properties.add(new j("fill_arrow")),this.properties.add(new N("name")),this.properties.add(new z("line_color")),this.properties.add(new $("line_style")),this.properties.add(new $("line_width")),this.properties.add(new N("src_wuid")),this.properties.add(new N("src_term")),this.properties.add(new N("tgt_wuid")),this.properties.add(new N("tgt_term")),this.properties.add(new $("router")),this.properties.add(new Y("points")),this.properties.add(new N("wuid"))}parseNode(t){this.properties.loadXMLValues(t),this.sourceWidget=this.display.findWidget(this.sourceWuid),this.sourceWidget||console.warn(`Can't find source widget ${this.sourceWuid}`),this.targetWidget=this.display.findWidget(this.targetWuid),this.targetWidget||console.warn(`Can't find target widget ${this.targetWuid}`)}draw(t){this.sourceWidget&&this.targetWidget&&(this.points.length?this.drawPath(t):0===this.router?this.drawManhattanConnection(t):1===this.router&&this.drawDirectConnection(t))}drawPath(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),s=[e,...this.points,i],r=v.fromPoints(s).translate(.5*this.scale,.5*this.scale);t.strokePath({path:r,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,s[1],s[0]),this.drawStopArrow(t,s[s.length-2],s[s.length-1])}drawManhattanConnection(t){const e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),s=this.route(e,i),r=v.fromPoints(s);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:r,dash:this.getDashArray()}),this.drawStartArrow(t,s[s.length-2],s[s.length-1]),this.drawStopArrow(t,s[1],s[0])}getDashArray(){const{scale:t}=this;if(this.lineWidth){if(0===this.lineStyle)return[];if(1===this.lineStyle)return[6*t,2*t];if(2===this.lineStyle)return[2*t,2*t];if(3===this.lineStyle)return[6*t,2*t,2*t,2*t];if(4===this.lineStyle)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}drawDirectConnection(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new v(e.x,e.y).lineTo(i.x,i.y),lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,i,e),this.drawStopArrow(t,e,i)}getManhattanAnchor(t,e){let i;switch(e){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":i="UP";break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i="DOWN";break;case"LEFT":i="LEFT";break;case"RIGHT":i="RIGHT"}const s=t.bounds,r=this.getPosition(t,e),o=r.x-s.x,h=s.x+s.width-r.x,n=r.y-s.y,a=s.y+s.height-r.y;return i=Math.min(o,h)<Math.min(n,a)?o<h?"LEFT":"RIGHT":n<a?"UP":"DOWN",{x:r.x,y:r.y,direction:i}}getPosition(t,e){switch(e){case"LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight/2};case"TOP":return{x:t.holderX+t.holderWidth/2,y:t.holderY};case"RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight/2};case"BOTTOM":return{x:t.holderX+t.holderWidth/2,y:t.holderY+t.holderHeight};case"TOP_LEFT":return{x:t.holderX,y:t.holderY};case"TOP_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY};case"BOTTOM_LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight};case"BOTTOM_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight};default:const i=parseInt(e,10);let s=t.properties.getProperty("points");if(s){let t=s.value;return t=x(t,this.scale),t[i]}throw Error(`Unexpected term ${e}`)}}route(t,e){let i,s,r=t.x-e.x,o=t.y-e.y,h={x:0,y:0},n=[];const{tolxtol:a,tol:l,minDist:d}=this;if(r*r<a&&o*o<a)return[{x:e.x,y:e.y}];"LEFT"===t.direction?r>0&&o*o<l&&"RIGHT"===e.direction?(h=e,i=e.direction):(r<0?h={x:t.x-d,y:t.y}:o>0&&"DOWN"===e.direction||o<0&&"UP"===e.direction?h={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.min(t.x,e.x)-d,h={x:s,y:t.y}):h={x:t.x-r/2,y:t.y},i=o>0?"UP":"DOWN"):"RIGHT"===t.direction?r<0&&o*o<l&&"LEFT"===e.direction?(h=e,i=e.direction):(r>0?h={x:t.x+d,y:t.y}:o>0&&"DOWN"===e.direction||o<0&&"UP"===e.direction?h={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.max(t.x,e.x)+d,h={x:s,y:t.y}):h={x:t.x-r/2,y:t.y},i=o>0?"UP":"DOWN"):"DOWN"===t.direction?r*r<l&&o<0&&"UP"===e.direction?(h=e,i=e.direction):(o>0?h={x:t.x,y:t.y+d}:r>0&&"RIGHT"===e.direction||r<0&&"LEFT"===e.direction?h={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.max(t.y,e.y)+d,h={x:t.x,y:s}):h={x:t.x,y:t.y-o/2},i=r>0?"LEFT":"RIGHT"):"UP"===t.direction&&(r*r<l&&o>0&&"DOWN"===e.direction?(h=e,i=e.direction):(o<0?h={x:t.x,y:t.y-d}:r>0&&"RIGHT"===e.direction||r<0&&"LEFT"===e.direction?h={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.min(t.y,e.y)-d,h={x:t.x,y:s}):h={x:t.x,y:t.y-o/2},i=r>0?"LEFT":"RIGHT"));const c=Object.assign(Object.assign({},h),{direction:i});return n=n.concat(this.route(c,e)),n.push(t),n}drawStartArrow(t,e,i){const s=t.ctx;if(1===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}drawStopArrow(t,e,i){const s=t.ctx;if(2===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}calculateArrowPoints(t,e){const i=m(e,t),s=Math.PI/10,r=new f(this.arrowLength,i.theta-s),o=new f(this.arrowLength,i.theta+s),h=new f(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[c(r.toPoint(),e.x,e.y),c(o.toPoint(),e.x,e.y),c(h.toPoint(),e.x,e.y)]}get minDist(){return 20*this.scale}get tol(){return.1*this.scale}get tolxtol(){return.01*this.scale}get name(){return this.properties.getValue("name")}get arrows(){return this.properties.getValue("arrows")}get fillArrow(){return this.properties.getValue("fill_arrow")}get arrowLength(){return this.scale*this.properties.getValue("arrow_length")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get router(){return this.properties.getValue("router")}get sourceTerm(){return this.properties.getValue("src_term")}get sourceWuid(){return this.properties.getValue("src_wuid")}get targetTerm(){return this.properties.getValue("tgt_term")}get targetWuid(){return this.properties.getValue("tgt_wuid")}get points(){return x(this.properties.getValue("points"),this.scale)}}let qe=0;class Ye extends ze{constructor(t,e){super(t,e),this.properties.add(new et("auto_scale_widgets"))}parseNode(t){super.parseNode(t);const e=qe++;this.macros.set("DID",`DID_${e}`);const i=this.properties.getValue("name");this.macros.set("DNAME",i);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}for(const e of t.getNodes("connection")){const t=new Ue(this.display);t.parseNode(e),this.connections.push(t)}}draw(t){for(const e of this.widgets.filter((t=>t.visible)))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(const e of this.connections)e.draw(t);for(const e of this.widgets.filter((t=>t.visible)))e.drawOverlay(t)}measureContentBounds(t){let e=0,i=0,s=0,r=0;for(const o of this.widgets.filter((t=>t.visible))){const h=t?o.bounds:o.unscaledBounds;e=Math.min(e,h.x),i=Math.min(i,h.y),s=Math.max(s,h.x+h.width),r=Math.max(r,h.y+h.height)}return{x:e,y:i,width:s-e,height:r-i}}get autoScaleWidgets(){return this.properties.getValue("auto_scale_widgets")}}class Xe extends ze{parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const e=t.createChild(this.width,this.height);for(const t of this.widgets.filter((t=>t.visible)))t.drawHolder(e),t.draw(e),t.drawDecoration(e);for(const t of this.widgets.filter((t=>t.visible)))t.drawOverlay(e);t.copy(e,this.x,this.y)}}class Ke{constructor(){this.includeParentMacros=!0,this.macros={}}clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}}class Ze{constructor(t,e,i){this.autoScaleWidgets=t,this.minWidth=e,this.minHeight=i}}class Je{constructor(t,e,i){this.widthScalable=t,this.heightScalable=e,this.keepWidthHeightRatio=i}}class Qe{constructor(){this.scripts=[]}}class ti{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){const e=(new DOMParser).parseFromString(t,"text/xml");return new ti(e.documentElement)}getNode(t){const e=this.findChild(t);return new ti(e)}getNodes(t){const e=[];for(let i=0;i<this.node.childNodes.length;i++){const s=this.node.childNodes[i];3!==s.nodeType&&(t&&s.nodeName!==t||e.push(new ti(s)))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++){if(this.node.childNodes[e].nodeName===t)return!0}return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseFloat(i.textContent)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseInt(i.textContent,10)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return"true"===i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){const i=this.node.attributes.getNamedItem(t);if(null===i){if(void 0!==e)return e;throw new Error(`No attribute named ${t}`)}return"true"===i.textContent}getColor(t,e){const i=this.findChild(t);for(let t=0;t<i.childNodes.length;t++){const e=i.childNodes[t];if("color"===e.nodeName)return this.parseColorNode(new ti(e))}if(void 0!==e)return e;throw new Error("No child node named 'color' could be found")}getFont(t){const e=this.getNode(t);if(e.hasNode("opifont.name")){const t=e.getNode("opifont.name"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");let o=!1;return t.hasAttribute("pixels")&&(o=t.getBooleanAttribute("pixels")),new E(i,s,r,o)}{const t=e.getNode("fontdata"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");return new E(i,s,r,!1)}}getPoints(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("point"))i.push({x:t.getIntAttribute("x"),y:t.getIntAttribute("y")});return i}getStringList(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("s"))i.push(t.getTextContent());return i}getScripts(t){const e=this.getNode(t),i=new Qe;for(const t of e.getNodes("path")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=t.getStringAttribute("pathString");"EmbeddedJs"===s?i.scripts.push({embedded:!0,text:t.getString("scriptText"),checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe"),inputs:e}):"EmbeddedPy"===s?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:s,checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe"),inputs:e})}return i}getScaleOptions(t){const e=this.getNode(t);return new Je(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){const e=this.getNode(t);return new Ze(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){const e=this.getNode(t);if(!e.hasNode("e"))return new O(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"));{const t=new O(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(const i of e.getNodes("e")){const e=Number(i.getTextContent()),s=i.getIntAttribute("red"),r=i.getIntAttribute("green"),o=i.getIntAttribute("blue");t.addMapping(e,s,r,o)}}}getRules(t){const e=this.getNode(t),i=new Nt;for(const t of e.getNodes("rule")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=[];for(const e of t.getNodes("exp")){e.getNode("value").hasNode("color")?s.push({type:"color",expression:e.getStringAttribute("bool_exp"),outputValue:e.getColor("value")}):s.push({type:"string",expression:e.getStringAttribute("bool_exp"),outputValue:e.getString("value")})}i.rules.push({name:t.getStringAttribute("name"),propertyName:t.getStringAttribute("prop_id"),outputExpression:t.getBooleanAttribute("out_exp"),inputs:e,expressions:s})}return i}getMacros(t){const e=this.getNode(t),i=new Ke;i.includeParentMacros=e.getBoolean("include_parent_macros");for(const t of e.getNodes())"include_parent_macros"!==t.name&&i.set(t.name,e.getString(t.name));return i}getActions(t){const e=this.getNode(t),i=new Rt;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(const t of e.getNodes("action")){const e=t.getStringAttribute("type");if("OPEN_DISPLAY"===e){const e=new Et(t.getString("path"));t.hasNode("mode")&&(e.mode=t.getInt("mode")),e.description=t.getString("description"),i.add(e)}else if("OPEN_FILE"===e){const e=new Wt;e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("EXECUTE_CMD"===e){const e=new It;e.command=t.getString("command"),e.commandDirectory=t.getString("command_directory"),e.waitTime=t.getInt("wait_time"),e.description=t.getString("description"),i.add(e)}else if("EXECUTE_JAVASCRIPT"===e){const e=new Bt(t.getBoolean("embedded"));e.embedded?e.text=t.getString("scriptText"):e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("WRITE_PV"===e){const e=new Ot(t.getString("pv_name"),t.getString("value"));e.confirmMessage=t.getString("confirm_message",""),e.description=t.getString("description"),i.add(e)}else if("PLAY_SOUND"===e){const e=new Ht;e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("OPEN_WEBPAGE"===e){const e=new Ft;e.hyperlink=t.getString("hyperlink"),e.description=t.getString("description"),i.add(e)}else console.warn(`Unsupported action type ${e}`),i.add(null)}return i}parseColorNode(e){const i=e.getIntAttribute("red"),s=e.getIntAttribute("green"),r=e.getIntAttribute("blue");return new t(i,s,r)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}}let ei=0;class ii extends ze{constructor(t,e){super(t,e),this.properties.add(new N("group_name")),this.properties.add(new N("opi_file")),this.properties.add(new $("resize_behaviour",0))}parseNode(t){super.parseNode(t);const e=ei++;this.macros.set("LCID",`LCID_${e}`)}init(){this.opiFile&&fetch(this.display.baseUrl+this.opiFile,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.linkedDisplay=new Ye(this.display,this);const e=ti.parseFromXML(t);this.linkedDisplay.parseNode(e),this.requestRepaint()}))}))}draw(t){this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect(Object.assign(Object.assign({},this.area),{color:this.linkedDisplay.backgroundColor})),0===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!1);let{width:i,height:s}=e;const r=this.display.scale;i*=r,s*=r;const o=i/s;let h=this.width,n=h/o,a=h/i;n>this.height&&(n=this.height,h=n*o,a=n/i),this.linkedDisplay.relativeScale=a;const l=t.createChild(Math.ceil(h),Math.ceil(n));l.translate(e.x,e.y),this.linkedDisplay.draw(l),t.copy(l,this.x,this.y)}else if(1===this.resizeBehavior)console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior);else if(2===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!0),i=t.createChild(e.width,e.height);i.translate(e.x,e.y),this.linkedDisplay.draw(i),t.copy(i,this.x,this.y)}else 3===this.resizeBehavior&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&""!==this.groupName?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue("opi_file")}get groupName(){return this.properties.getValue("group_name")}get resizeBehavior(){return this.properties.getValue("resize_behaviour")}}class si{constructor(t,e){this.widget=t,this.i=e,this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue("active_tab",e),t.requestRepaint())},cursor:"pointer"}}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`tab_${this.i}_${t}`)}get title(){return this.getValue("title")}get backgroundColor(){return this.getValue("background_color")}get foregroundColor(){return this.getValue("foreground_color")}get enabled(){return this.getValue("enabled")}get font(){return this.getValue("font").scale(this.scale)}}class ri extends ze{constructor(t,e){super(t,e),this.tabs=[],this.properties.add(new $("minimum_tab_height")),this.properties.add(new $("active_tab")),this.properties.add(new j("horizontal_tabs")),this.properties.add(new $("tab_count")),this.properties.addGenerator((()=>{this.tabs=[];const t=this.properties.getValue("tab_count"),e=[];for(let i=0;i<t;i++)this.tabs.push(new si(this,i)),e.push(new N(`tab_${i}_title`),new z(`tab_${i}_background_color`),new z(`tab_${i}_foreground_color`),new j(`tab_${i}_enabled`),new U(`tab_${i}_font`));return e}))}parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.horizontalTabs?this.drawHorizontalTabs(t):this.drawVerticalTabs(t)}measureTabOffset(t){return this.horizontalTabs?{x:0,y:this.measureLabelHeight(t)}:{x:this.measureLabelWidth(t),y:0}}measureLabelHeight(t){const{scale:e}=this,i=1*e;let s=this.minimumTabHeight;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).height+i;o>s&&(s=o)}return s+this.margin}measureLabelWidth(t){const{scale:e}=this,i=1*e;let s=this.minimumTabWidth;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).width+i;o>s&&(s=o)}return s+this.margin}drawHorizontalTabs(e){const{margin:i,gap:s,scale:r}=this,o=this.measureLabelHeight(e),h=1*r;let n=this.x;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=e.measureText(l.title,l.font);let c,p,g,u,m;this.activeTab===a?(c=n,p=this.y,g=d.width+h+i+s,u=o,m=l.backgroundColor):(c=n+s,p=this.y+2*r,g=d.width+h+i-s,u=o-2*r,m=this.darken(l.backgroundColor)),e.fillRect({x:c,y:p,width:g,height:u,color:m});e.addHitRegion(l.headerRegion).addRect(c,p,g,u);const f=e.createLinearGradient(c,p,c,p+u);if(f.addColorStop(0,t.WHITE.toString()),f.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:c,y:p,width:g,height:u,gradient:f}),e.fillText({x:c+g/2,y:p+u/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=d.width+h+i-1*r,this.activeTab===a){const t=this.x,i=this.y+o,s=this.width,r=this.height-o;e.fillRect({x:t,y:i,width:s,height:r,color:l.backgroundColor});const h=this.widgets[a],n=e.createChild(s,r);h.drawHolder(n),h.draw(n),h.drawDecoration(n),h.drawOverlay(n),e.copy(n,t,i)}else{this.widgets[a].hide()}}}drawVerticalTabs(e){const{margin:i,gap:s,scale:r}=this,o=this.measureLabelWidth(e),h=1*r;let n=this.y;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=e.measureText(l.title,l.font),c=Math.max(d.height+h+h,this.minimumTabHeight);let p,g,u,m,f;this.activeTab===a?(p=this.x,g=n,u=o,m=c+i+s,f=l.backgroundColor):(p=this.x+2*r,g=n+s,u=o-2*r,m=c+i-s,f=this.darken(l.backgroundColor)),e.fillRect({x:p,y:g,width:u,height:m,color:f});e.addHitRegion(l.headerRegion).addRect(p,g,u,m);const x=e.createLinearGradient(p,g,p+u,g);if(x.addColorStop(0,t.WHITE.toString()),x.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:p,y:g,width:u,height:m,gradient:x}),e.fillText({x:p+u/2,y:g+m/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=c+i-1*r,this.activeTab===a){const t=this.x+o-1*r,i=this.y,s=this.width-o,h=this.height-1*r;e.fillRect({x:t,y:i,width:s,height:h,color:l.backgroundColor});const n=this.widgets[a],d=e.createChild(s,h);n.drawHolder(d),n.draw(d),n.drawDecoration(d),n.drawOverlay(d),e.copy(d,t,i)}else{this.widgets[a].destroy()}}}darken(e){const i=Math.max(0,e.red-30),s=Math.max(0,e.green-30),r=Math.max(0,e.blue-30);return new t(i,s,r)}get margin(){return 10*this.scale}get gap(){return 2*this.scale}get minimumTabWidth(){return 20*this.scale}get minimumTabHeight(){return this.scale*this.properties.getValue("minimum_tab_height")}get activeTab(){return this.properties.getValue("active_tab")}get tabCount(){return this.properties.getValue("tab_count")}get horizontalTabs(){return this.properties.getValue("horizontal_tabs")}}class oi extends Dt{constructor(t,e){super(t,e),this.properties.add(new N("url"))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="https://yamcs.org",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${t}px`,this.iframe.style.top=`${e}px`,this.iframe.style.width=`${i}px`,this.iframe.style.height=`${s}px`,this.url&&this.prevUrl!==this.url&&(this.iframe.src=this.url,this.prevUrl=this.url)}}hide(){this.iframe&&(this.iframe.style.display="none")}destroy(){this.iframe&&(this.display.rootPanel.removeChild(this.iframe),this.iframe=void 0)}get url(){return this.properties.getValue("url")}}class hi{constructor(t){this.targetElement=t,this.repaintRequested=!1,this._editMode=!1,this._showGrid=!1,this._showOutline=!1,this._showRuler=!1,this._selection=[],this._scale=1,this._transparent=!1,this.imagesPrefix="",this.baseUrl="",this.eventListeners={closedisplay:[],opendisplay:[],openpv:[],selection:[],scale:[]},this.rootPanel=document.createElement("div"),this.rootPanel.className="display-root",this.rootPanel.style.overflow="hidden",this.rootPanel.style.position="relative",this.rootPanel.style.fontSize="0",t.appendChild(this.rootPanel);const e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new y(e),this.ctx=this.g.ctx,this.pvEngine=new vt(this),this.pvEngine.addProvider(new Pt),this.pvEngine.addProvider(new L),this.displayRegion={id:"display-root",click:()=>this.closeMenu()},window.requestAnimationFrame((()=>this.step())),new r(this,e,this.g.hitCanvas)}addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}step(){this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.requestAnimationFrame((()=>this.step()))}drawScreen(){var e;if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="#d6d6d6",e.fillRect(0,0,8,8),e.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.instance&&this.g.fillRect(Object.assign(Object.assign({},this.instance.bounds),{color:this.instance.backgroundColor}))}else this.transparent||this.g.fillCanvas((null===(e=this.instance)||void 0===e?void 0:e.backgroundColor)||t.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=25,t.height=25,e.fillStyle=this.instance.foregroundColor.toString(),e.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let t=0;for(;t<=this.ctx.canvas.width;)t+=100,this.ctx.beginPath(),this.ctx.moveTo(t-75+.5,this.ctx.canvas.height),this.ctx.lineTo(t-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t-50+.5,this.ctx.canvas.height),this.ctx.lineTo(t-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(t-25+.5,this.ctx.canvas.height),this.ctx.lineTo(t-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t+.5,this.ctx.canvas.height),this.ctx.lineTo(t+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(t),t,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let e=0;for(;e<=this.ctx.canvas.height;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,e-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-75+.5),this.ctx.moveTo(this.ctx.canvas.width,e-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,e-50+.5),this.ctx.moveTo(this.ctx.canvas.width,e-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-25+.5),this.ctx.moveTo(this.ctx.canvas.width,e+.5),this.ctx.lineTo(this.ctx.canvas.width-8,e+.5),this.ctx.stroke(),this.ctx.fillText(String(e),this.ctx.canvas.width-8,e)}this.showOutline&&this.instance&&(this.ctx.lineWidth=1,this.ctx.setLineDash([10,5]),this.ctx.strokeStyle="black",this.ctx.strokeRect(-.5,-.5,this.instance.holderWidth+1,this.instance.holderHeight+1),this.ctx.setLineDash([])),this.instance&&this.instance.draw(this.g);for(const t of this.selection){const e=this.findWidget(t);e&&e.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){var e;this.rootPanel.title=null!==(e=null==t?void 0:t.trim())&&void 0!==e?e:""}closeMenu(){var t;null===(t=this.instance)||void 0===t||t.closeMenu()}createWidget(t,e){switch(t){case"Action Button":return new $t(this,e);case"Arc":return new he(this,e);case"Boolean Button":return new Gt(this,e);case"Boolean Switch":return new jt(this,e);case"Byte Monitor":return new ue(this,e);case"Check Box":return new qt(this,e);case"Choice Button":return new Yt(this,e);case"Combo":case"Combo Box":return new Kt(this,e);case"Ellipse":return new ne(this,e);case"Gauge":return new we(this,e);case"Grouping Container":return new Xe(this,e);case"Image":return new ae(this,e);case"Image Boolean Button":return new Zt(this,e);case"Image Boolean Indicator":return new ye(this,e);case"Intensity Graph":return new _e(this,e);case"Label":return new le(this,e);case"LED":return new Te(this,e);case"Linking Container":return new ii(this,e);case"Meter":return new Ae(this,e);case"Button":return new Jt(this,e);case"Polygon":return new de(this,e);case"Polyline":return new ce(this,e);case"Progress Bar":return new Le(this,e);case"Radio Box":return new ee(this,e);case"Rectangle":return new pe(this,e);case"Rounded Rectangle":return new ge(this,e);case"Scrollbar":return new re(this,e);case"Tabbed Container":return new ri(this,e);case"Tank":return new ke(this,e);case"Text Input":return new oe(this,e);case"Text Update":return new Pe(this,e);case"Thermometer":return new Re(this,e);case"Web Browser":return new oi(this,e);case"XY Graph":return new je(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){var t;null===(t=this.instance)||void 0===t||t.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}setSource(t){return this.reset(),new Promise(((e,i)=>{fetch(this.baseUrl+t,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.setSourceString(t),e()})).catch((t=>i(t)))})).catch((t=>i(t)))}))}setSourceString(t){this.reset(),this.instance=new Ye(this);const e=ti.parseFromXML(t);this.instance.parseNode(e),this.requestRepaint()}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0)}measureAbsoluteArea(t){const e=t.bounds;let i=t.parent;for(;i;){if(e.x+=i.holderX,e.y+=i.holderY,i instanceof ri){const{x:t,y:s}=i.measureTabOffset(this.g);e.x+=t,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=1*this.scale,e.y+=1*this.scale,e}addEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t].push(e)}removeEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t]=this.eventListeners[t].filter((t=>t!==e))}fireEvent(t,e){this.eventListeners[t].forEach((t=>t(e)))}get showGrid(){return this._showGrid}set showGrid(t){this._showGrid=t,this.requestRepaint()}get showOutline(){return this._showOutline}set showOutline(t){this._showOutline=t,this.requestRepaint()}get showRuler(){return this._showRuler}set showRuler(t){this._showRuler=t,this.requestRepaint()}get selection(){return this._selection}set selection(t){this._selection=t,this.requestRepaint();const e={selected:this._selection.slice()};this.fireEvent("selection",e)}get editMode(){return this._editMode}set editMode(t){this._editMode=t,this.requestRepaint()}get scale(){return this._scale}set scale(t){this._scale=t,this.requestRepaint();const e={scale:t};this.fireEvent("scale",e)}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get widgets(){return this.instance?this.instance.widgets:[]}clearSelection(){this.selection.length&&(this.selection=[])}findWidget(t){if(this.instance)return this.instance.findWidget(t)}findWidgetByName(t){if(this.instance)return this.instance.findWidgetByName(t)}getPVNames(){return this.pvEngine.getPVNames()}getPV(t){return this.pvEngine.getPV(t)}setValues(t){this.pvEngine.setValues(t)}copyCanvas(t){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}}export{ft as AlarmSeverity,_ as CompiledFormula,hi as Display,A as FormulaCompiler,mt as PV};
|
|
1
|
+
class t{constructor(t,e,i,s=255){this.red=t,this.green=e,this.blue=i,this.alpha=s}withAlpha(e){return new t(this.red,this.green,this.blue,e)}mixWith(e,i){const s=Math.floor(this.red*i+e.red*(1-i)),r=Math.floor(this.green*i+e.green*(1-i)),o=Math.floor(this.blue*i+e.blue*(1-i));return new t(s,r,o)}brighter(){let{red:e,green:i,blue:s}=this;const r=Math.floor(1/(1-.7));return 0===e&&0===i&&0===s?new t(r,r,r):(e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),s>0&&s<r&&(s=r),new t(Math.min(Math.floor(this.red/.7),255),Math.min(Math.floor(this.green/.7),255),Math.min(Math.floor(this.blue/.7),255)))}darker(){return new t(Math.max(Math.floor(.7*this.red),0),Math.max(Math.floor(.7*this.green),0),Math.max(Math.floor(.7*this.blue),0))}contrast(){return new t(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=1==t.length?"0"+t:t;let e=this.green.toString(16);e=1==e.length?"0"+e:e;let i=this.blue.toString(16);i=1==i.length?"0"+i:i;let s=this.alpha.toString(16);return s=1==s.length?"0"+s:s,`#${t}${e}${i}${s}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}}t.TRANSPARENT=new t(0,0,0,0),t.BLACK=new t(0,0,0),t.BLUE=new t(0,0,255),t.CYAN=new t(0,255,255),t.DARK_GRAY=new t(150,150,150),t.GRAY=new t(200,200,200),t.GREEN=new t(0,255,0),t.LIGHT_BLUE=new t(153,186,243),t.ORANGE=new t(255,128,0),t.PINK=new t(255,0,255),t.PURPLE=new t(128,0,255),t.RED=new t(255,0,0),t.WHITE=new t(255,255,255),t.YELLOW=new t(255,255,0),t.BUTTON=new t(239,240,241),t.BUTTON_DARKER=new t(164,168,172),t.BUTTON_DARKEST=t.BLACK,t.BUTTON_LIGHTEST=t.WHITE;const e=t=>(document.removeEventListener("click",e,!0),t.preventDefault(),t.stopPropagation(),!1);function i(t){return 1==(1&t.buttons)||void 0===t.buttons&&1==t.which}function s(t,e){return t&&e&&t.id===e.id}class r{constructor(t,e,i){this.display=t,this.canvas=e,this.hitCanvas=i,this.grabbing=!1,this.documentMouseMoveListener=t=>this.onDocumentMouseMove(t),this.documentMouseUpListener=t=>this.onDocumentMouseUp(t),e.addEventListener("click",(t=>this.onCanvasClick(t)),!1),e.addEventListener("mousedown",(t=>this.onCanvasMouseDown(t)),!1),e.addEventListener("mouseup",(t=>this.onCanvasMouseUp(t)),!1),e.addEventListener("mouseout",(t=>this.onCanvasMouseOut(t)),!1),e.addEventListener("mousemove",(t=>this.onCanvasMouseMove(t)),!1)}toPoint(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();const e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{const i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",e,!0),i(t))){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);return i&&i.mouseDown&&i.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),i&&i.grab&&(this.grabPoint=Object.assign({},e),this.grabTarget=i),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.mouseUp&&i.mouseUp()}onCanvasMouseOut(t){this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&this.prevEnteredRegion.mouseOut(),this.prevEnteredRegion=void 0,t.preventDefault(),t.stopPropagation()}onCanvasMouseMove(t){const e=this.toPoint(t),r=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(s(this.prevEnteredRegion,r)||this.prevEnteredRegion.mouseOut()),r&&r.mouseEnter&&(s(this.prevEnteredRegion,r)||r.mouseEnter()),this.prevEnteredRegion=r;const o=r&&r.cursor?r.cursor:"auto";if(o!=this.canvas.style.cursor&&(this.canvas.style.cursor=o),!this.grabbing&&r&&r.tooltip?this.display.setTooltip(r.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&i(t)){const t=(h=this.grabPoint.x,n=this.grabPoint.y,a=e.x,l=e.y,Math.sqrt((a-h)*(a-h)+(l-n)*(l-n)));Math.abs(t)>5&&(this.initiateGrab(),this.grabPoint&&(this.grabPoint=e))}var h,n,a,l;this.grabbing&&this.grabTarget&&i(t)&&this.grabTarget.grab({clientX:t.clientX,clientY:t.clientY,point:e,dx:e.x-this.grabPoint.x,dy:e.y-this.grabPoint.y})}initiateGrab(){document.addEventListener("click",e,!0),document.addEventListener("mouseup",this.documentMouseUpListener),document.addEventListener("mousemove",this.documentMouseMoveListener),this.grabbing=!0}onDocumentMouseUp(t){if(this.grabbing){document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener);const t=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,(null==t?void 0:t.grabEnd)&&t.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){const i=this.display.instance;if(i)for(const s of i.widgets.slice().reverse()){const i=s.holderX,r=s.holderY,o=s.holderX+s.holderWidth,h=s.holderY+s.holderHeight;if(i<t&&t<o&&r<e&&e<h)return this.display.selection=[s.wuid],!1}}}const o="rgb(255,255,255)";class h{constructor(t,e,i){this.parent=t,this.regions={};const s=document.createElement("canvas");s.width=null!=e?e:s.width,s.height=null!=i?i:s.height,this.ctx=s.getContext("2d"),this.root=(null==t?void 0:t.root)||t}clear(){this.regions={},this.ctx.fillStyle=o,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){const e=(this.root||this).generateUniqueColor();return(this.root||this).regions[e]=t,this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){const i=this.ctx.getImageData(t,e,1,1).data,s=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regions[s]||void 0}createChild(t,e){return new h(this,t,e)}transferToParent(t,e,i,s){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,s)}generateUniqueColor(){for(;;){const t=`rgb(${Math.round(255*Math.random())},${Math.round(255*Math.random())},${Math.round(255*Math.random())})`;if(!this.regions[t]&&t!=o)return t}}}function n(t,e,i,s,r){return l({x:t,y:e,width:i,height:s},r/2)}function a(t,e,i,s,r){const o=Math.sin(r),h=Math.cos(r),n=t-i,a=e-s;return{x:n*h-a*o+i,y:n*o+a*h+s}}function l(t,e,i){return void 0===i&&(i=e),{x:t.x+i,y:t.y+e,width:t.width-(i+i),height:t.height-(e+e)}}function d(t){return{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,width:Math.round(t.width),height:Math.round(t.height)}}function c(t,e,i){return{x:t.x+e,y:t.y+i}}function p(t,e,i){return t.map((t=>c(t,e,i)))}function g(t){return t*Math.PI/180}function u(t,e,i){const s=Math.floor(t*Math.cos(e)),r=Math.floor(-t*Math.sin(e));return{x:i.x+i.width/2+s,y:i.y+i.height/2+r}}function m(t,e){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));let o=Math.acos(i/r);return s>0&&(o=2*Math.PI-o),new f(Math.floor(r),o)}class f{constructor(t,e){this.r=t,this.theta=e}toPoint(){return{x:Math.floor(this.r*Math.cos(this.theta)),y:Math.floor(-this.r*Math.sin(this.theta))}}}function x(t,e){return t.map((t=>({x:t.x*e,y:t.y*e})))}function w(t,e,i,s,r,o,h){t.beginPath(),o||h?(s<2*o&&(o=s/2),r<2*h&&(h=r/2),t.moveTo(e+o,i),t.lineTo(e+s-o,i),t.quadraticCurveTo(e+s,i,e+s,i+h),t.lineTo(e+s,i+r-h),t.quadraticCurveTo(e+s,i+r,e+s-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-h),t.lineTo(e,i+h),t.quadraticCurveTo(e,i,e+o,i)):t.rect(e,i,s,r)}class y{constructor(t,e){this.canvas=t,this.ctx=t.getContext("2d"),this.hitCanvas=e||new h,this.hitCtx=this.hitCanvas.ctx}createChild(t,e){const i=this.hitCanvas.createChild(t,e),s=document.createElement("canvas");return s.width=t,s.height=e,new y(s,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,s,r){const{width:o,height:h}=t.canvas,n=o/h;let a=s,l=a/n;l>r&&(l=r,a=l*n),this.copyScaled(t,e,i,a,l)}copyScaled(t,e,i,s,r){this.ctx.drawImage(t.canvas,e,i,s,r),t.hitCanvas.transferToParent(e,i,s,r)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){this.ctx.canvas.width==t&&this.ctx.canvas.height==e||(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(w(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.fill()):this.ctx.fillRect(t.x,t.y,t.width,t.height),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}fillText(t){this.ctx.textBaseline=t.baseline,this.ctx.textAlign=t.align,this.ctx.font=t.font.getFontString(),this.ctx.fillStyle=t.color.toString(),this.ctx.fillText(t.text,t.x,t.y)}fillEllipse(t){this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.strokeStyle="color"in t?t.color.toString():t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e){this.ctx.font=e.getFontString();return{width:this.ctx.measureText(t).width,height:e.height}}createLinearGradient(t,e,i,s){return this.ctx.createLinearGradient(t,e,i,s)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);const e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){const i=l(t,e/2,e/2);t.rx||t.ry?(w(this.ctx,i.x,i.y,i.width,i.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(i.x,i.y,i.width,i.height)}else t.rx||t.ry?(w(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(t.x,t.y,t.width,t.height);t.dash&&this.ctx.setLineDash([])}strokePath(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.lineWidth=t.lineWidth||1,this.ctx.strokeStyle=t.color.toString(),void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),void 0!==t.opacity&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new b(this.hitCanvas.ctx)}}class v{constructor(t,e){this.segments=[],this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){const e=new v(t[0].x,t[0].y);for(let i=1;i<t.length;i++)e.lineTo(t[i].x,t[i].y);return e}getBoundingBox(){const t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){const s=this.segments[i];s.x<t.x&&(t.x=s.x),s.x>e.x&&(e.x=s.x),s.y<t.y&&(t.y=s.y),s.y>e.y&&(e.y=s.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){const t=this.segments[0];return this.segments.push({x:t.x,y:t.y,line:!0}),this}translate(t,e){for(const i of this.segments)i.x+=t,i.y+=e;return this}}class b{constructor(t){this.ctx=t}addRect(t,e,i,s){return this.ctx.fillRect(t,e,i,s),this}addEllipse(t,e,i,s,r,o,h,n){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,s,r,o,h,n),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(const e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}}class _{constructor(t){this.display=t}resolve(t){return`${this.display.baseUrl}${t}`}}class T{constructor(t,e){this.pvName=t,this.formula=e,this.pvValues=new Map}updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){const t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":-1===e.indexOf(t.value)&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(const i of t.arguments)this.getExpressionParameters(i,e)}}execute(){const t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":case"ConstantLiteral":case"NumericLiteral":case"StringLiteral":return t.value;case"ParameterLiteral":const e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConditionalExpression":return this.executeConditionalExpression(t);case"BinaryExpression":return this.executeBinaryExpression(t);case"LogicalExpression":return this.executeLogicalExpression(t);case"UnaryExpression":return this.executeUnaryExpression(t);case"CallExpression":return this.executeCallExpression(t);default:throw new Error("Unexpected expression type")}}executeBinaryExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"+":return e+i;case"-":return e-i;case"*":return e*i;case"/":return e/i;case"^":return Math.pow(e,i);case"%":return e%i;case"==":return e===i;case"!=":return e!==i;case"<=":return e<=i;case"<":return e<i;case">=":return e>=i;case">":return e>i;default:throw new Error(`Unexpected binary operator ${t.operator}`)}}executeLogicalExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"&&":return e&&i;case"||":return e||i;default:throw new Error(`Unexpected logical operator ${t.operator}`)}}executeConditionalExpression(t){const e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(void 0===t.alternate)return e?i:null;{const s=this.executeExpression(t.alternate);return e?i:s}}executeUnaryExpression(t){const e=this.executeExpression(t.argument);switch(t.operator){case"-":return-e;case"+":return e;default:throw new Error(`Unexpected unary operator ${t.operator}`)}}executeCallExpression(t){const e=t.callee.name,i=[];for(const e of t.arguments)i.push(this.executeExpression(e));switch(e){case"abs":return Math.abs(i[0]);case"acos":return Math.acos(i[0]);case"asin":return Math.asin(i[0]);case"atan":return Math.atan(i[0]);case"cbrt":return Math.cbrt(i[0]);case"ceil":return Math.ceil(i[0]);case"cos":return Math.cos(i[0]);case"cosh":return Math.cosh(i[0]);case"exp":return Math.exp(i[0]);case"floor":return Math.floor(i[0]);case"log":return Math.log(i[0]);case"log10":return Math.log10(i[0]);case"round":return Math.round(i[0]);case"signum":return Math.sign(i[0]);case"sin":return Math.sin(i[0]);case"sinh":return Math.sinh(i[0]);case"sqrt":return Math.sqrt(i[0]);case"tan":return Math.tan(i[0]);case"tanh":return Math.tanh(i[0]);case"toDegrees":return 180*i[0]/Math.PI;case"toRadians":return i[0]/180*Math.PI;case"parameterAcquisitionStatus":return this.callParameterAcquisitionStatus(i[0]);default:throw new Error(`Unsupported function '${e}'`)}}callParameterAcquisitionStatus(t){const e=this.pvValues.get(t);if(e)return e.acquisitionStatus}}function S(t,e,i,s){var r=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(r,S.prototype),r.expected=e,r.found=i,r.location=s,r.name="SyntaxError",r}function V(t,e,i){return i=i||" ",t.length>e?t:(e-=t.length,t+(i+=i.repeat(e)).slice(0,e))}function A(t,e){var i,s,r,o,h={},n=(e=void 0!==e?e:{}).grammarSource,a={Start:Mt},l=Mt,d=".",c='"',p="'",g="-",u="+",m=",",f="<=",x=">=",w="==",y="!=",v="&&",b="||",_=/^[a-zA-Z]/,T=/^[a-zA-Z0-9_]/,V=/^[0-9]/,A=/^[1-9]/,L=/^[^\n\r\f"]/,C=/^[^\n\r\f']/,k=Vt("=",!1),P=Vt(" ",!1),M=Vt("\t",!1),R=Vt("false",!0),E=Vt("true",!0),W=Vt("PI",!0),B=Vt("E",!0),I=Lt("identifier"),O=At([["a","z"],["A","Z"]],!1,!1),H=Vt("_",!1),F=At([["a","z"],["A","Z"],["0","9"],"_"],!1,!1),N=Lt("boolean"),D=Lt("constant"),G=Lt("number"),j=Vt(".",!1),$=Vt("0",!1),z=At([["0","9"]],!1,!1),U=At([["1","9"]],!1,!1),q=Lt("string"),Y=Vt('"',!1),X=At(["\n","\r","\f",'"'],!0,!1),K=Lt("parameter"),Z=Vt("'",!1),J=At(["\n","\r","\f","'"],!0,!1),Q=Vt("(",!1),tt=Vt(")",!1),et=Vt("-",!1),it=Vt("+",!1),st=Vt(",",!1),rt=Vt("*",!1),ot=Vt("/",!1),ht=Vt("^",!1),nt=Vt("%",!1),at=Vt("<=",!1),lt=Vt(">=",!1),dt=Vt("<",!1),ct=Vt(">",!1),pt=Vt("==",!1),gt=Vt("!=",!1),ut=Vt("&&",!1),mt=Vt("||",!1),ft=function(){return{type:"NumericLiteral",value:parseFloat(t.substring(vt,yt))}},xt=function(t,e){return function(t,e,i){return[t].concat(function(t,e){return t.map((function(t){return t[e]}))}(e,i))}(t,e,3)},wt=function(t,e){return function(t,e){return e.reduce((function(t,e){return{type:"BinaryExpression",operator:e[1],left:t,right:e[3]}}),t)}(t,e)},yt=0,vt=0,bt=[{line:1,column:1}],_t=0,Tt=[],St=0;if("startRule"in e){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');l=a[e.startRule]}function Vt(t,e){return{type:"literal",text:t,ignoreCase:e}}function At(t,e,i){return{type:"class",parts:t,inverted:e,ignoreCase:i}}function Lt(t){return{type:"other",description:t}}function Ct(e){var i,s=bt[e];if(s)return s;for(i=e-1;!bt[i];)i--;for(s={line:(s=bt[i]).line,column:s.column};i<e;)10===t.charCodeAt(i)?(s.line++,s.column=1):s.column++,i++;return bt[e]=s,s}function kt(t,e){var i=Ct(t),s=Ct(e);return{source:n,start:{offset:t,line:i.line,column:i.column},end:{offset:e,line:s.line,column:s.column}}}function Pt(t){yt<_t||(yt>_t&&(_t=yt,Tt=[]),Tt.push(t))}function Mt(){var e,i,s;return e=yt,61===t.charCodeAt(yt)?(i="=",yt++):(i=h,0===St&&Pt(k)),i!==h?(Rt(),s=function(){var t,e;t=yt,(e=zt())!==h&&(vt=t,e={type:"Formula",expression:e});return t=e}(),s!==h?(Rt(),vt=e,e=s):(yt=e,e=h)):(yt=e,e=h),e}function Rt(){var t,e;for(t=[],e=Et();e!==h;)t.push(e),e=Et();return t}function Et(){var e;return 32===t.charCodeAt(yt)?(e=" ",yt++):(e=h,0===St&&Pt(P)),e===h&&(9===t.charCodeAt(yt)?(e="\t",yt++):(e=h,0===St&&Pt(M))),e}function Wt(){var e,i;return e=yt,i=function(){var e,i,s,r;if(St++,e=yt,i=function(){var e;_.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(O));e===h&&(95===t.charCodeAt(yt)?(e="_",yt++):(e=h,0===St&&Pt(H)));return e}(),i!==h){for(s=[],r=Bt();r!==h;)s.push(r),r=Bt();vt=e,e={type:"Symbol",name:i+s.join("")}}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(I));return e}(),i!==h&&(vt=e,i=i),e=i}function Bt(){var e;return T.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(F)),e}function It(){var e;return(e=function(){var e,i;St++,e=yt,i=function(){var e;return"true"===t.substr(yt,4).toLowerCase()?(e=t.substr(yt,4),yt+=4):(e=h,0===St&&Pt(E)),e}(),i!==h&&(vt=e,i={type:"BooleanLiteral",value:!0});(e=i)===h&&(e=yt,i=function(){var e;return"false"===t.substr(yt,5).toLowerCase()?(e=t.substr(yt,5),yt+=5):(e=h,0===St&&Pt(R)),e}(),i!==h&&(vt=e,i={type:"BooleanLiteral",value:!1}),e=i);St--,e===h&&(i=h,0===St&&Pt(N));return e}())===h&&(e=function(){var e,i;St++,e=yt,i=function(){var e;return"pi"===t.substr(yt,2).toLowerCase()?(e=t.substr(yt,2),yt+=2):(e=h,0===St&&Pt(W)),e}(),i!==h&&(vt=e,i={type:"ConstantLiteral",value:Math.PI});(e=i)===h&&(e=yt,i=function(){var e;return"e"===t.substr(yt,1).toLowerCase()?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(B)),e}(),i!==h&&(vt=e,i={type:"ConstantLiteral",value:Math.E}),e=i);St--,e===h&&(i=h,0===St&&Pt(D));return e}())===h&&(e=function(){var e,i,s,r,o;if(St++,e=yt,(i=Ot())!==h)if(46===t.charCodeAt(yt)?(s=d,yt++):(s=h,0===St&&Pt(j)),s!==h){for(r=[],o=Ht();o!==h;)r.push(o),o=Ht();vt=e,e=ft()}else yt=e,e=h;else yt=e,e=h;if(e===h){if(e=yt,46===t.charCodeAt(yt)?(i=d,yt++):(i=h,0===St&&Pt(j)),i!==h){if(s=[],(r=Ht())!==h)for(;r!==h;)s.push(r),r=Ht();else s=h;s!==h?(vt=e,e=ft()):(yt=e,e=h)}else yt=e,e=h;e===h&&(e=yt,(i=Ot())!==h&&(vt=e,i=ft()),e=i)}St--,e===h&&(i=h,0===St&&Pt(G));return e}())===h&&(e=function(){var e,i,s,r;St++,e=yt,34===t.charCodeAt(yt)?(i=c,yt++):(i=h,0===St&&Pt(Y));if(i!==h){for(s=[],L.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(X));r!==h;)s.push(r),L.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(X));34===t.charCodeAt(yt)?(r=c,yt++):(r=h,0===St&&Pt(Y)),r!==h?(vt=e,e={type:"StringLiteral",value:s.join("")}):(yt=e,e=h)}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(q));return e}())===h&&(e=function(){var e,i,s,r;St++,e=yt,39===t.charCodeAt(yt)?(i=p,yt++):(i=h,0===St&&Pt(Z));if(i!==h){for(s=[],C.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(J));r!==h;)s.push(r),C.test(t.charAt(yt))?(r=t.charAt(yt),yt++):(r=h,0===St&&Pt(J));39===t.charCodeAt(yt)?(r=p,yt++):(r=h,0===St&&Pt(Z)),r!==h?(vt=e,e={type:"ParameterLiteral",value:s.join("")}):(yt=e,e=h)}else yt=e,e=h;St--,e===h&&(i=h,0===St&&Pt(K));return e}()),e}function Ot(){var e,i,s,r;if(48===t.charCodeAt(yt)?(e="0",yt++):(e=h,0===St&&Pt($)),e===h)if(e=yt,i=function(){var e;A.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(U));return e}(),i!==h){for(s=[],r=Ht();r!==h;)s.push(r),r=Ht();e=i=[i,s]}else yt=e,e=h;return e}function Ht(){var e;return V.test(t.charAt(yt))?(e=t.charAt(yt),yt++):(e=h,0===St&&Pt(z)),e}function Ft(){var e,i,s;return e=function(){var e,i,s,r;return(e=It())===h&&(e=yt,40===t.charCodeAt(yt)?(i="(",yt++):(i=h,0===St&&Pt(Q)),i!==h?(Rt(),(s=zt())!==h?(Rt(),41===t.charCodeAt(yt)?(r=")",yt++):(r=h,0===St&&Pt(tt)),r!==h?(vt=e,e=s):(yt=e,e=h)):(yt=e,e=h)):(yt=e,e=h)),e}(),e===h&&(e=yt,i=function(){var e;45===t.charCodeAt(yt)?(e=g,yt++):(e=h,0===St&&Pt(et));e===h&&(43===t.charCodeAt(yt)?(e=u,yt++):(e=h,0===St&&Pt(it)));return e}(),i!==h?(Rt(),(s=Ft())!==h?(Rt(),vt=e,e={type:"UnaryExpression",operator:i,argument:s}):(yt=e,e=h)):(yt=e,e=h)),e}function Nt(){var e,i,s;return e=yt,(i=Wt())!==h?(Rt(),s=function(){var e,i,s,r;e=yt,40===t.charCodeAt(yt)?(i="(",yt++):(i=h,0===St&&Pt(Q));i!==h?(Rt(),s=yt,r=function(){var e,i,s,r,o,n,a,l;if(e=yt,(i=zt())!==h){for(s=[],r=yt,o=Rt(),44===t.charCodeAt(yt)?(n=m,yt++):(n=h,0===St&&Pt(st)),n!==h?(a=Rt(),(l=zt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),44===t.charCodeAt(yt)?(n=m,yt++):(n=h,0===St&&Pt(st)),n!==h?(a=Rt(),(l=zt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=xt(i,s)}else yt=e,e=h;return e}(),r!==h?s=r=[r,Rt()]:(yt=s,s=h),s===h&&(s=null),41===t.charCodeAt(yt)?(r=")",yt++):(r=h,0===St&&Pt(tt)),r!==h?(vt=e,a=0,e=null!==(o=(n=s)?n[a]:null)?o:[]):(yt=e,e=h)):(yt=e,e=h);var o,n,a;return e}(),s!==h?(vt=e,e={type:"CallExpression",callee:i,arguments:s}):(yt=e,e=h)):(yt=e,e=h),e===h&&(e=Ft()),e}function Dt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Nt())!==h){for(s=[],r=yt,o=Rt(),42===t.charCodeAt(yt)?(n="*",yt++):(n=h,0===St&&Pt(rt)),n===h&&(47===t.charCodeAt(yt)?(n="/",yt++):(n=h,0===St&&Pt(ot)),n===h&&(94===t.charCodeAt(yt)?(n="^",yt++):(n=h,0===St&&Pt(ht)),n===h&&(37===t.charCodeAt(yt)?(n="%",yt++):(n=h,0===St&&Pt(nt))))),n!==h?(a=Rt(),(l=Nt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),42===t.charCodeAt(yt)?(n="*",yt++):(n=h,0===St&&Pt(rt)),n===h&&(47===t.charCodeAt(yt)?(n="/",yt++):(n=h,0===St&&Pt(ot)),n===h&&(94===t.charCodeAt(yt)?(n="^",yt++):(n=h,0===St&&Pt(ht)),n===h&&(37===t.charCodeAt(yt)?(n="%",yt++):(n=h,0===St&&Pt(nt))))),n!==h?(a=Rt(),(l=Nt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function Gt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Dt())!==h){for(s=[],r=yt,o=Rt(),43===t.charCodeAt(yt)?(n=u,yt++):(n=h,0===St&&Pt(it)),n===h&&(45===t.charCodeAt(yt)?(n=g,yt++):(n=h,0===St&&Pt(et))),n!==h?(a=Rt(),(l=Dt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),43===t.charCodeAt(yt)?(n=u,yt++):(n=h,0===St&&Pt(it)),n===h&&(45===t.charCodeAt(yt)?(n=g,yt++):(n=h,0===St&&Pt(et))),n!==h?(a=Rt(),(l=Dt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function jt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=Gt())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===f?(n=f,yt+=2):(n=h,0===St&&Pt(at)),n===h&&(t.substr(yt,2)===x?(n=x,yt+=2):(n=h,0===St&&Pt(lt)),n===h&&(60===t.charCodeAt(yt)?(n="<",yt++):(n=h,0===St&&Pt(dt)),n===h&&(62===t.charCodeAt(yt)?(n=">",yt++):(n=h,0===St&&Pt(ct))))),n!==h?(a=Rt(),(l=Gt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===f?(n=f,yt+=2):(n=h,0===St&&Pt(at)),n===h&&(t.substr(yt,2)===x?(n=x,yt+=2):(n=h,0===St&&Pt(lt)),n===h&&(60===t.charCodeAt(yt)?(n="<",yt++):(n=h,0===St&&Pt(dt)),n===h&&(62===t.charCodeAt(yt)?(n=">",yt++):(n=h,0===St&&Pt(ct))))),n!==h?(a=Rt(),(l=Gt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function $t(){var e,i,s,r,o,n,a,l;if(e=yt,(i=jt())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===w?(n=w,yt+=2):(n=h,0===St&&Pt(pt)),n===h&&(t.substr(yt,2)===y?(n=y,yt+=2):(n=h,0===St&&Pt(gt))),n!==h?(a=Rt(),(l=jt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===w?(n=w,yt+=2):(n=h,0===St&&Pt(pt)),n===h&&(t.substr(yt,2)===y?(n=y,yt+=2):(n=h,0===St&&Pt(gt))),n!==h?(a=Rt(),(l=jt())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=wt(i,s)}else yt=e,e=h;return e}function zt(){var e,i,s,r,o,n,a,l;if(e=yt,(i=$t())!==h){for(s=[],r=yt,o=Rt(),t.substr(yt,2)===v?(n=v,yt+=2):(n=h,0===St&&Pt(ut)),n===h&&(t.substr(yt,2)===b?(n=b,yt+=2):(n=h,0===St&&Pt(mt))),n!==h?(a=Rt(),(l=$t())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);r!==h;)s.push(r),r=yt,o=Rt(),t.substr(yt,2)===v?(n=v,yt+=2):(n=h,0===St&&Pt(ut)),n===h&&(t.substr(yt,2)===b?(n=b,yt+=2):(n=h,0===St&&Pt(mt))),n!==h?(a=Rt(),(l=$t())!==h?r=o=[o,n,a,l]:(yt=r,r=h)):(yt=r,r=h);vt=e,e=function(t,e){return e.reduce((function(t,e){return{type:"LogicalExpression",operator:e[1],left:t,right:e[3]}}),t)}(i,s)}else yt=e,e=h;return e}if((i=l())!==h&&yt===t.length)return i;throw i!==h&&yt<t.length&&Pt({type:"end"}),s=Tt,r=_t<t.length?t.charAt(_t):null,o=_t<t.length?kt(_t,_t+1):kt(_t,_t),new S(S.buildMessage(s,r),s,r,o)}!function(t,e){function i(){this.constructor=t}i.prototype=e.prototype,t.prototype=new i}(S,Error),S.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var i,s=null;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){s=t[i].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,o=this.location.source+":"+r.line+":"+r.column;if(s){var h=this.location.end,n=V("",r.line.toString().length),a=s[r.line-1],l=r.line===h.line?h.column:a.length+1;e+="\n --\x3e "+o+"\n"+n+" |\n"+r.line+" | "+a+"\n"+n+" | "+V("",r.column-1)+V("",l-r.column,"^")}else e+="\n at "+o}return e},S.buildMessage=function(t,e){var i={literal:function(t){return'"'+r(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function s(t){return t.charCodeAt(0).toString(16).toUpperCase()}function r(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function h(t){return i[t.type](t)}return"Expected "+function(t){var e,i,s=t.map(h);if(s.sort(),s.length>0){for(e=1,i=1;e<s.length;e++)s[e-1]!==s[e]&&(s[i]=s[e],i++);s.length=i}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(t)+" but "+function(t){return t?'"'+r(t)+'"':"end of input"}(e)+" found."};class L{compile(t){const e=A(t,{});return new T(t,e)}execute(t){return this.compile(t).execute()}}class C{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("=")}startProviding(t){for(const e of t)this.pvs.set(e.name,new k(e))}stopProviding(t){for(const e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}}class k{constructor(t){this.pv=t;const e=new L;this.compiledFormula=e.compile(t.name);for(const e of this.compiledFormula.getPVNames()){const i=t.pvEngine.createPV(e);this.compiledFormula.updateDataSource(i.name,{value:i.value,acquisitionStatus:"good"}),t.pvEngine.addListener(e,(()=>{this.compiledFormula.updateDataSource(e,{value:t.pvEngine.getValue(e),acquisitionStatus:"good"}),this.trigger()}))}this.trigger()}trigger(){const t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}}var P,M={exports:{}};P=M,function(){function t(t,e){document.addEventListener?t.addEventListener("scroll",e,!1):t.attachEvent("scroll",e)}function e(t){this.a=document.createElement("div"),this.a.setAttribute("aria-hidden","true"),this.a.appendChild(document.createTextNode(t)),this.b=document.createElement("span"),this.c=document.createElement("span"),this.h=document.createElement("span"),this.f=document.createElement("span"),this.g=-1,this.b.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.c.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.f.style.cssText="max-width:none;display:inline-block;position:absolute;height:100%;width:100%;overflow:scroll;font-size:16px;",this.h.style.cssText="display:inline-block;width:200%;height:200%;font-size:16px;max-width:none;",this.b.appendChild(this.h),this.c.appendChild(this.f),this.a.appendChild(this.b),this.a.appendChild(this.c)}function i(t,e){t.a.style.cssText="max-width:none;min-width:20px;min-height:20px;display:inline-block;overflow:hidden;position:absolute;width:auto;margin:0;padding:0;top:-999px;white-space:nowrap;font-synthesis:none;font:"+e+";"}function s(t){var e=t.a.offsetWidth,i=e+100;return t.f.style.width=i+"px",t.c.scrollLeft=i,t.b.scrollLeft=t.b.scrollWidth+100,t.g!==e&&(t.g=e,!0)}function r(e,i){function r(){var t=o;s(t)&&t.a.parentNode&&i(t.g)}var o=e;t(e.b,r),t(e.c,r),s(e)}function o(t,e){var i=e||{};this.family=t,this.style=i.style||"normal",this.weight=i.weight||"normal",this.stretch=i.stretch||"normal"}var h=null,n=null,a=null,l=null;function d(){return null===l&&(l=!!document.fonts),l}function c(){if(null===a){var t=document.createElement("div");try{t.style.font="condensed 100px sans-serif"}catch(t){}a=""!==t.style.font}return a}function p(t,e){return[t.style,t.weight,c()?t.stretch:"","100px",e].join(" ")}o.prototype.load=function(t,s){var o=this,a=t||"BESbswy",l=0,c=s||3e3,g=(new Date).getTime();return new Promise((function(t,s){if(d()&&!function(){if(null===n)if(d()&&/Apple/.test(window.navigator.vendor)){var t=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))(?:\.([0-9]+))/.exec(window.navigator.userAgent);n=!!t&&603>parseInt(t[1],10)}else n=!1;return n}()){var u=new Promise((function(t,e){!function i(){(new Date).getTime()-g>=c?e(Error(c+"ms timeout exceeded")):document.fonts.load(p(o,'"'+o.family+'"'),a).then((function(e){1<=e.length?t():setTimeout(i,25)}),e)}()})),m=new Promise((function(t,e){l=setTimeout((function(){e(Error(c+"ms timeout exceeded"))}),c)}));Promise.race([m,u]).then((function(){clearTimeout(l),t(o)}),s)}else!function(t){document.body?t():document.addEventListener?document.addEventListener("DOMContentLoaded",(function e(){document.removeEventListener("DOMContentLoaded",e),t()})):document.attachEvent("onreadystatechange",(function e(){"interactive"!=document.readyState&&"complete"!=document.readyState||(document.detachEvent("onreadystatechange",e),t())}))}((function(){function n(){var e;(e=-1!=f&&-1!=x||-1!=f&&-1!=w||-1!=x&&-1!=w)&&((e=f!=x&&f!=w&&x!=w)||(null===h&&(e=/AppleWebKit\/([0-9]+)(?:\.([0-9]+))/.exec(window.navigator.userAgent),h=!!e&&(536>parseInt(e[1],10)||536===parseInt(e[1],10)&&11>=parseInt(e[2],10))),e=h&&(f==y&&x==y&&w==y||f==v&&x==v&&w==v||f==b&&x==b&&w==b)),e=!e),e&&(_.parentNode&&_.parentNode.removeChild(_),clearTimeout(l),t(o))}var d=new e(a),u=new e(a),m=new e(a),f=-1,x=-1,w=-1,y=-1,v=-1,b=-1,_=document.createElement("div");_.dir="ltr",i(d,p(o,"sans-serif")),i(u,p(o,"serif")),i(m,p(o,"monospace")),_.appendChild(d.a),_.appendChild(u.a),_.appendChild(m.a),document.body.appendChild(_),y=d.a.offsetWidth,v=u.a.offsetWidth,b=m.a.offsetWidth,function t(){if((new Date).getTime()-g>=c)_.parentNode&&_.parentNode.removeChild(_),s(Error(c+"ms timeout exceeded"));else{var e=document.hidden;!0!==e&&void 0!==e||(f=d.a.offsetWidth,x=u.a.offsetWidth,w=m.a.offsetWidth,n()),l=setTimeout(t,50)}}(),r(d,(function(t){f=t,n()})),i(d,p(o,'"'+o.family+'",sans-serif')),r(u,(function(t){x=t,n()})),i(u,p(o,'"'+o.family+'",serif')),r(m,(function(t){w=t,n()})),i(m,p(o,'"'+o.family+'",monospace'))}))}))},P.exports=o}();var R=M.exports;const E=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"];class W{constructor(t,e,i,s){this.name=t,this.style=i,this.height=s?e:Math.round(16*e/15)}scale(t){return new W(this.name,t*this.height,this.style,!0)}getFontString(){return 1===this.style?`bold ${this.height}px ${this.name}`:2===this.style?`italic ${this.height}px ${this.name}`:(0!==this.style&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${this.name}`)}preload(){if(-1!==E.indexOf(this.name))return Promise.resolve();let t={weight:"normal",style:"normal"};return 1===this.style?t.weight="bold":2===this.style&&(t.style="italic"),new R(this.name,t).load()}}W.ARIAL_9=new W("Arial",9,0,!1),W.ARIAL_10=new W("Arial",10,0,!1),W.ARIAL_11=new W("Arial",11,0,!1),W.ARIAL_12_BOLD=new W("Arial",12,1,!1);class B{constructor(){this.BLACK=t.BLACK,this.BLUE=t.BLUE,this.CYAN=t.CYAN,this.DARK_GRAY=t.DARK_GRAY,this.GRAY=t.GRAY,this.GREEN=t.GREEN,this.LIGHT_BLUE=t.LIGHT_BLUE,this.ORANGE=t.ORANGE,this.PINK=t.PINK,this.PURPLE=t.PURPLE,this.RED=t.RED,this.WHITE=t.WHITE,this.YELLOW=t.YELLOW}getColorFromRGB(e,i,s){return new t(e,i,s)}getFont(t,e,i){return new W(t,e,i,!1)}}class I{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}}class O{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}}class H{constructor(t,e,i){this.code=t,this.interpolate=e,this.autoscale=i,this.values=[],this.colors=[],this.entries=[],this.dirty=!0,0===t||(1===t?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):2===t?(this.values=[0,.111,.365,.619,.873,1],this.colors=[[0,0,143],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[128,0,0]]):3===t?(this.values=[0,.126,.251,.375,.5,.625,.749,.874,1],this.colors=[[0,0,0],[255,0,255],[0,0,255],[0,255,255],[0,255,0],[255,255,0],[255,128,0],[255,0,0],[255,255,255]]):4===t?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):5===t?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):6===t&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}addMapping(t,e,i,s){this.values.push(t),this.colors.push([e,i,s]),this.dirty=!0}compile(){this.entries.length=0;for(let t=0;t<this.values.length;t++)this.entries.push([this.values[t],this.colors[t]]);this.entries.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0))}lookup(t){this.dirty&&(this.compile(),this.dirty=!1);let e=this.binarySearch(t);if(e>=0)return this.entries[e][1];if(e=-e-1,0===e)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){const[i,s]=this.entries[e-1],[r,o]=this.entries[e],h=(t-i)/(r-i);return[Math.floor((o[0]-s[0])*h+s[0]),Math.floor((o[1]-s[1])*h+s[1]),Math.floor((o[2]-s[2])*h+s[2])]}return this.entries[e-1][1]}getMinMax(){return[Math.min.apply(Math,this.values),Math.max.apply(Math,this.values)]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){const s=i+e>>1;if(t>this.entries[s][0])e=s+1;else{if(!(t<this.entries[s][0]))return s;i=s-1}}return-e-1}}class F{constructor(t,e=[]){this.widget=t,this.properties=new Map,this.generators=[];for(const t of e)this.properties.set(t.name,t)}clear(){this.properties.clear()}add(t){this.properties.set(t.name,t)}addGenerator(t){this.generators.push(t)}all(){return this.properties.values()}loadProperty(t,e){if(t.hasNode(e.name))if(e instanceof K)e.value=t.getActions(e.name);else if(e instanceof it)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof z)e.value=t.getBoolean(e.name);else if(e instanceof Y)e.value=t.getColorMap(e.name);else if(e instanceof U)e.value=t.getColor(e.name);else if(e instanceof $)e.value=t.getFloat(e.name);else if(e instanceof q)e.value=t.getFont(e.name);else if(e instanceof j)e.value=t.getInt(e.name);else if(e instanceof Z)e.value=t.getMacros(e.name);else if(e instanceof X)e.value=t.getPoints(e.name);else if(e instanceof G);else if(e instanceof tt)e.value=t.getRules(e.name);else if(e instanceof et)e.value=t.getScaleOptions(e.name);else if(e instanceof J)e.value=t.getScripts(e.name);else if(e instanceof D)e.rawValue=t.getString(e.name);else{if(!(e instanceof Q))throw new Error(`Property ${e.name} has an unexpected type`);e.value=t.getStringList(e.name)}}loadXMLValues(t){this.properties.forEach((e=>{this.loadProperty(t,e)})),this.resolveStringProperties();for(const e of this.generators)for(const i of e())this.properties.set(i.name,i),this.loadProperty(t,i);this.resolveStringProperties()}resolveStringProperties(){for(let t=0;t<2;t++)this.properties.forEach((t=>{if(t instanceof D){const e=t;void 0!==e.rawValue?t.value=this.widget.expandMacro(e.rawValue):t.value=e.rawValue}}))}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){const i=this.properties.get(t);if(i&&void 0!==i.value)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){const i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}}class N{constructor(t,e){this.name=t,this.defaultValue=e,this.value=e}get value(){return this._value}set value(t){if(this.value!==t){const e=this._value;if(this._value=t,this.listeners)for(const i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){const e=this.listeners||[],i=e.indexOf(t);-1!==i&&e.splice(i,1)}printScriptValue(t){return String(t)}}class D extends N{printScriptValue(t){return`"${t.replace('"','\\"')}"`}}class G extends N{constructor(t,e){super(t),this.pvPropertyName=e}}class j extends N{}class $ extends N{}class z extends N{}class U extends N{printScriptValue(t){const{red:e,green:i,blue:s}=Object.assign({},t);return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${s})`}}class q extends N{printScriptValue(t){const{name:e,height:i,style:s}=Object.assign({},t);return`ColorFontUtil.getFont("${e}", ${i}, ${s})`}}class Y extends N{printScriptValue(t){return`${t.code}`}}class X extends N{}class K extends N{}class Z extends N{}class J extends N{}class Q extends N{}class tt extends N{}class et extends N{}class it extends N{}class st{constructor(t){this._pv=t}getName(){return this._pv.name}getValue(){return this._pv.value}setValue(t){this._pv.pvEngine.setValue(new Date,this._pv.name,t)}}class rt{constructor(t){this.widget=t}getPVByName(t){const e=this.widget.display.getPV(t);return e?new st(e):null}getPV(t="pv_name"){const e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getPropertyValue(t){const e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof D)e=void 0!==e?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof Y){let i=0;switch(e){case"GrayScale":i=1;break;case"JET":i=2;break;case"ColorSpectrum":i=3;break;case"Hot":i=4;break;case"Cool":i=5;break;case"Shaded":i=6}const s=new H(i,!0,!0);this.widget.properties.setValue(t,s)}else this.widget.properties.setValue(t,e);this.widget.requestRepaint()}getName(){return this.getPropertyValue("name")}setX(t){this.setPropertyValue("x",t)}setY(t){this.setPropertyValue("y",t)}setWidth(t){this.setPropertyValue("width",t)}setHeight(t){this.setPropertyValue("height",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){var t;return null!==(t=this.widget.value)&&void 0!==t?t:null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}}class ot extends rt{constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.x))}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.y))}}function ht(t){return"XY Graph"===t.widgetType?new ot(t):new rt(t)}class nt{constructor(t){this.display=t}getWidget(t){const e=this.display.findWidgetByName(t);if(e)return ht(e)}}class at{fullScreen(){document.documentElement.requestFullscreen()}openConfirmDialog(t){return confirm(t)}openInformationDialog(t){alert(t)}openWarningDialog(t){alert(t)}openErrorDialog(t){alert(t)}openPasswordDialog(t,e){let i=prompt(t);if(i)return i===e}}class lt{openInformation(t,e,i){alert(i)}openConfirm(t,e,i){return confirm(i)}openError(t,e,i){alert(i)}}const dt=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"];class ct{constructor(t){this.pvEngine=t}getDouble(t){return parseFloat(t.getValue())}getLong(t){return parseInt(t.getValue(),10)}getString(t){return String(t.getValue())}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){const i=t._pv.time;if(i){let t=e;for(const e of dt)t=t.replace(e,this.formatDate(i,e));return t}return null}formatDate(t,e){if("yyyy"===e)return String(t.getUTCFullYear());if("MM"===e){const e=t.getUTCMonth()+1;return e<10?"0"+e:""+e}if("dd"===e){const e=t.getUTCDate();return e<10?"0"+e:""+e}if("HH"===e){const e=t.getUTCHours();return e<10?"0"+e:""+e}if("mm"===e){const e=t.getUTCMinutes();return e<10?"0"+e:""+e}if("ss"===e){const e=t.getUTCSeconds();return e<10?"0"+e:""+e}if("nnnnnnnnn"===e){const e=t.getUTCMilliseconds();return e<10?"00"+e:e<100?"0"+e:""+e}throw new Error(`Unexpected format '${e}'`)}}class pt{constructor(t){this.display=t}openOPI(t,e,i,s){if(0!==i)throw new Error(`Unsupported target ${i}`);{const t={path:e,replace:0===i};this.display.fireEvent("opendisplay",t)}}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}}let gt,ut,mt;class ft{constructor(t,e,i=[]){this.scriptText=e,gt||(gt=document.createElement("iframe"),gt.id="script-e",gt.style.display="none",document.body.appendChild(gt),ut=gt.contentWindow,mt=ut.eval,!mt&&ut.execScript&&(ut.execScript.call(ut,"null"),mt=ut.eval)),this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context=Object.assign({display:new nt(t.display),pvs:i.map((t=>new st(t))),widget:ht(t),ConsoleUtil:new I,ColorFontUtil:new B,DataUtil:new O,GUIUtil:new at,MessageDialog:new lt,PVUtil:new ct(t.display.pvEngine),ScriptUtil:new pt(t.display)},t.display.pvEngine.scriptLibraries)}run(){const t=[];for(const e in gt.contentWindow)t.push(e);try{for(const t in this.context)this.context.hasOwnProperty(t)&&(ut[t]=this.context[t]);mt.call(ut,this.scriptText);const e={};for(const i in ut)-1===t.indexOf(i)&&(e[i]=ut[i]);this.context=e}finally{for(const e in ut)-1===t.indexOf(e)&&delete ut[e]}}}class xt{constructor(t,e){this.name=t,this.pvEngine=e,this._writable=!1,this._severity=wt.NONE,this._precision=3,this._disconnected=!1,this.navigable=!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get lowerDisplayLimit(){return this._lowerDisplayLimit}set lowerDisplayLimit(t){this._lowerDisplayLimit=t,this.pvEngine.requestRepaint()}get lowerAlarmLimit(){return this._lowerAlarmLimit}set lowerAlarmLimit(t){this._lowerAlarmLimit=t,this.pvEngine.requestRepaint()}get lowerWarningLimit(){return this._lowerWarningLimit}set lowerWarningLimit(t){this._lowerWarningLimit=t,this.pvEngine.requestRepaint()}get upperWarningLimit(){return this._upperWarningLimit}set upperWarningLimit(t){this._upperWarningLimit=t,this.pvEngine.requestRepaint()}get upperAlarmLimit(){return this._upperAlarmLimit}set upperAlarmLimit(t){this._upperAlarmLimit=t,this.pvEngine.requestRepaint()}get upperDisplayLimit(){return this._upperDisplayLimit}set upperDisplayLimit(t){this._upperDisplayLimit=t,this.pvEngine.requestRepaint()}get precision(){return this._precision}set precision(t){this._precision=t,this.pvEngine.requestRepaint()}get writable(){return this._writable}set writable(t){this._writable=t,this.pvEngine.requestRepaint()}get disconnected(){return this._disconnected}set disconnected(t){this._disconnected=t,this.pvEngine.requestRepaint()}get time(){return this._time}get value(){return this._value}get indexValue(){return this._indexValue}get severity(){return this._severity}toNumber(){return null===this.value?null:"number"==typeof this.value?this.value:"boolean"==typeof this.value?this.value?1:0:void 0!==typeof this.indexValue?this.indexValue:void 0}formatValue(t,e){return null===this.value?"":"string"==typeof this.value?this.value:"number"==typeof this.value?this.formatNumber(t,this.value,e):this.value instanceof Date?this.value.toISOString().replace("T"," ").replace("Z",""):String(this.value)}formatNumber(t,e,i){if(null==e||null==e)return"";switch(t){case 0:case 1:return-1===i?String(e):e.toFixed(i);case 2:return e.toExponential().replace("e+","E").toUpperCase();case 3:return"0x"+e.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${t}`),String(e)}}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.addListener(this.name,t)}toString(){if(void 0!==this.value)return String(this.value)}}var wt;!function(t){t[t.NONE=0]="NONE",t[t.MINOR=1]="MINOR",t[t.MAJOR=2]="MAJOR",t[t.INVALID=3]="INVALID",t[t.UNDEFINED=4]="UNDEFINED"}(wt||(wt={}));class yt extends xt{constructor(t,e,i){super(t,e),this.initializer=i,this.writable=!0}}const vt=/(loc\:\/\/[^\(]+)(\((.*)\))?/;function bt(t){if(!t.startsWith("loc://"))return t;const e=t.match(vt);return e?e[1]:t}class _t{constructor(t){this.display=t,this.rules=[],this.scripts=[],this.pvs=new Map,this.providers=[],this.scriptLibraries={},this.listeners=new Map}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){const e=bt(t);return this.pvs.has(e)}getPV(t){const e=bt(t);return this.pvs.get(e)}disconnectAll(){for(const t of this.providers){const e=[];for(const i of this.pvs.values())t.canProvide(i.name)&&e.push(i);e.length&&t.stopProviding(e)}this.pvs.clear()}createPV(t){if(t.startsWith("loc://"))return this.createLocalPV(t);let e=this.pvs.get(t);if(e)return e;e=new xt(t,this),this.pvs.set(t,e);for(const i of this.providers)if(i.canProvide(t))return e.navigable=i.isNavigable(),i.startProviding([e]),e;return console.warn(`No provider for PV ${t}`),e.disconnected=!0,e}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){const e=t.match(vt);let i;if(e&&(t=e[1],void 0!==e[3])){const t=e[3];i=t.startsWith('"')&&t.endsWith('"')?t.substring(1,t.length-1):-1!==t.indexOf(",")?t.split(",").map((t=>Number(t.trim()))):Number(t)}let s=this.pvs.get(t),r=!1;if(s){const e=s;void 0===e.initializer||void 0===i||this.initializerEquals(e.initializer,i)?void 0===e.initializer&&void 0!==i&&(r=!0):console.warn(`PV ${t} is defined with different initializers: ${e.initializer} !== ${i}`)}return s||(s=new yt(t,this,i),this.pvs.set(t,s),r=!0),r&&void 0!==i&&this.setValue(new Date,t,i),s}initializerEquals(t,e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}return t===e}getValue(t){const e=bt(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,s=wt.NONE){const r=bt(e),o=this.pvs.get(r);if(!o)throw new Error(`Cannot set value of unknown PV ${e}`);o.setSample({time:t,value:i,severity:s});for(const t of this.listeners.get(e)||[])t()}setValues(t){const e=[];for(const i of t.keys()){const s=this.pvs.get(i);if(s){s.setSample(t.get(i));for(const t of this.listeners.get(i)||[])e.push(t)}else console.warn(`Received an update for unknown pv ${i}`)}for(const t of e)t()}createScript(t,e,i){const s=[];for(const i of e.inputs){const e=t.expandMacro(i.pvName);s.push(this.createPV(e))}const r=new Tt(t,e,i,s);this.scripts.push(r);const o=()=>{if(e.checkConnect)for(const t of s)if(t.disconnected||null===t.value||void 0===t.value)return;r.scriptEngine.run()};for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,o)}}createRule(t,e){const i=[];for(const s of e.inputs){const e=t.expandMacro(s.pvName);i.push(this.createPV(e))}const s=new St(t,e,i);this.rules.push(s);const r=()=>s.scriptEngine.run();for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,r)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e){const i=bt(t),s=this.listeners.get(i);s?s.push(e):this.listeners.set(i,[e]);const r=this.pvs.get(i);r&&null!==r.value&&void 0!==r.value&&e()}removeListener(t,e){const i=bt(t),s=this.listeners.get(i);if(s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}}class Tt{constructor(t,e,i,s){this.widget=t,this.script=e,this.text=i,this.scriptEngine=new ft(t,i,s)}}class St{constructor(t,e,i){this.widget=t,this.rule=e;let s="";const r=t.properties.getProperty(e.propertyName);if(!r)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let t=!1,o=!1,h=!1,n=!1;for(const i of e.expressions)i.expression.match(/pv[0-9]+/)&&(t=!0),e.outputExpression&&i.outputValue.toString().match(/pv[0-9]+/)&&(t=!0),-1!==i.expression.indexOf("pvInt")&&(o=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvInt")&&(o=!0),-1!==i.expression.indexOf("pvStr")&&(h=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvStr")&&(h=!0),-1!==i.expression.indexOf("pvSev")&&(n=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvSev")&&(n=!0);for(let e=0;e<i.length;e++)t&&(s+=`var pv${e} = PVUtil.getDouble(pvs[${e}]);\n`),o&&(s+=`var pvInt${e} = PVUtil.getLong(pvs[${e}]);\n`),h&&(s+=`var pvStr${e} = PVUtil.getString(pvs[${e}]);\n`),n&&(s+=`var pvSev${e} = PVUtil.getSeverity(pvs[${e}]);\n`);for(let t=0;t<e.expressions.length;t++){const i=e.expressions[t].expression,o=e.expressions[t].outputValue;if(t>0&&(s+="else "),s+=`if (${i}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)s+=`${o});\n`;else{s+=`${this.printScriptValue(r,o)});\n`}}const a=r.value,l=this.printScriptValue(r,a);s+=`else widget.setPropertyValue("${e.propertyName}", `,s+=`${l});\n`}this.scriptEngine=new ft(t,s,i)}printScriptValue(t,e){return null==e?"null":t.printScriptValue(e)}}class Vt{constructor(t,e,i){this.pv=t,this.interval=e,void 0!==i&&t.pvEngine.setValue(new Date,t.name,i),this.interval>0&&(this.timer=window.setInterval((()=>{this.generateSample(new Date)}),e))}emit(t,e){let i=wt.NONE;void 0!==this.pv.lowerAlarmLimit&&e<this.pv.lowerAlarmLimit||void 0!==this.pv.upperAlarmLimit&&e>this.pv.upperAlarmLimit?i=wt.MAJOR:(void 0!==this.pv.lowerWarningLimit&&e<this.pv.lowerWarningLimit||void 0!==this.pv.upperWarningLimit&&e>this.pv.upperWarningLimit)&&(i=wt.MINOR),this.pv.pvEngine.setValue(t,this.pv.name,e,i)}stop(){window.clearInterval(this.timer)}}class At extends Vt{constructor(t,e){super(t,-1,e)}generateSample(){}}class Lt extends Vt{constructor(t,e,i,s){super(t,s),this.min=e,this.max=i;const r=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*r,t.lowerWarningLimit=e+.2*r,t.upperWarningLimit=e+.8*r,t.upperAlarmLimit=e+.9*r,t.upperDisplayLimit=i}generateSample(t){const e=Math.random()*(this.max-this.min)+this.min;this.emit(t,e)}}class Ct extends Vt{constructor(t,e,i,s){super(t,s),this.avg=e,this.stddev=i,t.units="x",t.lowerDisplayLimit=e-4*i,t.lowerAlarmLimit=e-2*i,t.lowerWarningLimit=e-i,t.upperWarningLimit=e+i,t.upperAlarmLimit=e+2*i,t.upperDisplayLimit=e+4*i}generateSample(t){let e,i,s;do{e=2*Math.random()-1,i=2*Math.random()-1,s=e*e+i*i}while(s>=1||0===s);const r=e*Math.sqrt(-2*Math.log(s)/s);this.emit(t,this.avg+r*this.stddev)}}class kt extends Vt{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.samplesPerCycle=s,this.currentValue=0;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){const e=this.max-this.min,i=Math.sin(2*this.currentValue*Math.PI/this.samplesPerCycle)*e/2+this.min+e/2;this.currentValue++,this.emit(t,i)}}class Pt extends Vt{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.inc=s,this.currentValue=0,this.currentValue=s>=0?e-s:i-s;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(t,this.currentValue)}}const Mt=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/;class Rt{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("sim://")}startProviding(t){for(const e of t){const t=new Et(e);this.pvs.set(e.name,t)}}stopProviding(t){for(const e of t){const t=this.pvs.get(e.name);t&&(t.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(const t of this.pvs.values())t.fn.stop()}}class Et{constructor(t){this.pv=t;const e=t.name.match(Mt);if(e){const t=e[3]?e[3].split(","):[];for(let e=0;e<t.length;e++)t[e]=t[e].trim();this.fn=this.createGenerator(e[1],t)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new At(t,void 0)}createGenerator(t,e){switch(t){case"const":const i=this.saferEval(e[0]);return new At(this.pv,i);case"gaussianNoise":return this.createGaussianNoise(e);case"noise":return this.createNoise(e);case"ramp":return this.createRamp(e);case"sine":return this.createSine(e);default:return console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new At(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(0===t.length)return new Lt(this.pv,-5,5,1e3);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Lt(this.pv,e,i,s)}}createGaussianNoise(t){if(0===t.length)return new Ct(this.pv,0,1,100);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Ct(this.pv,e,i,s)}}createRamp(t){let e;if(0===t.length)e=new Pt(this.pv,-5,5,1,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new Pt(this.pv,i,s,1,r)}else{if(4!==t.length)return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new At(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new Pt(this.pv,i,s,r,o)}}return e}createSine(t){let e;if(0===t.length)e=new kt(this.pv,-5,5,10,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new kt(this.pv,i,s,10,r)}else{if(4!==t.length)return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new At(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new kt(this.pv,i,s,r,o)}}return e}}class Wt{constructor(){this.actions=[],this.hookFirstActionToClick=!1,this.hookAllActionsToClick=!1}add(t){this.actions.push(t)}isClickable(){return this.actions.length&&(this.hookFirstActionToClick||this.hookAllActionsToClick)}getAction(t){if(!(t>=this.actions.length))return this.actions[t]}getClickActions(){const t=[];if(this.hookFirstActionToClick)t.push(0);else if(this.hookAllActionsToClick)for(let e=0;e<this.actions.length;e++)t.push(e);return t}toString(){return 1===this.actions.length?String(this.actions[0])||this.actions[0].type:`${this.actions.length} actions`}}class Bt{constructor(t){this.path=t,this.type="OPEN_DISPLAY"}toString(){return`Open ${this.path}`}}class It{constructor(){this.type="OPEN_FILE"}toString(){return`Open ${this.path}`}}class Ot{constructor(t){this.embedded=t,this.type="EXECUTE_JAVASCRIPT"}toString(){return"Execute JavaScript"}}class Ht{constructor(){this.type="EXECUTE_CMD"}toString(){return`Execute Command ${this.command}`}}class Ft{constructor(t,e){this.pvName=t,this.value=e,this.type="WRITE_PV"}toString(){return`Write ${this.value} to ${this.pvName}`}}class Nt{constructor(){this.type="PLAY_SOUND"}toString(){return`Play WAV File ${this.path}`}}class Dt{constructor(){this.type="OPEN_WEBPAGE"}toString(){return`Open Webpage ${this.hyperlink}`}}class Gt{constructor(){this.rules=[]}}class jt{constructor(e,i){this.display=e,this.parent=i,this.x=0,this.y=0,this.width=0,this.height=0,this.fillRoundRectangleBackgroundBorder=!0,this.properties=new F(this,[new K("actions",new Wt),new z("backcolor_alarm_sensitive",!1),new U("background_color",t.TRANSPARENT),new z("border_alarm_sensitive",!1),new U("border_color"),new j("border_style"),new j("border_width"),new z("enabled",!0),new z("forecolor_alarm_sensitive",!1),new U("foreground_color"),new j("height"),new D("name"),new D("pv_name"),new G("pv_value","pv_name"),new tt("rules",new Gt),new J("scripts"),new D("text",""),new D("tooltip",""),new z("transparent",!1),new z("visible"),new D("widget_type"),new j("width"),new D("wuid"),new j("x"),new j("y"),new et("scale_options")])}parseNode(t){this.properties.loadXMLValues(t);for(const t of this.properties.all())if(t instanceof q){const e=t.value;e.preload().then((()=>this.requestRepaint())).catch((()=>console.warn(`Failed to load font '${e.getFontString()}'.`)))}this.pvName&&this.display.pvEngine.createPV(this.pvName);for(const t of this.scripts.scripts)t.embedded?this.display.pvEngine.createScript(this,t,t.text):fetch(`${this.display.baseUrl}${t.path}`,{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{this.display.pvEngine.createScript(this,t,e)}))}));for(const t of this.rules.rules)this.properties.getProperty(t.propertyName)?this.display.pvEngine.createRule(this,t):console.warn(`Cannot create rule for unsupported property ${t.propertyName}`);(this.tooltip||this.actions.isClickable())&&(this.holderRegion={id:`${this.wuid}-holder`},this.tooltip&&(this.holderRegion.tooltip=()=>this.tooltip),this.actions.isClickable()&&(this.holderRegion.click=()=>{for(const t of this.actions.getClickActions())this.executeAction(t)},this.holderRegion.cursor="pointer")),this.init()}drawHolder(t){var e,i;const{scale:s}=this;let r=[0,0,0,0];const o=this.borderAlarmSensitive&&((null===(e=this.pv)||void 0===e?void 0:e.severity)===wt.MINOR||(null===(i=this.pv)||void 0===i?void 0:i.severity)===wt.MAJOR);if(!o)switch(this.borderStyle){case 0:break;case 1:case 8:case 9:case 10:case 11:r=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:r=[1*s,1*s,1*s,1*s];break;case 4:case 5:case 6:r=[2*s,2*s,2*s,2*s];break;case 7:r=[2*s,2*s,1*s,1*s];break;case 12:r=[17*s,1*s,1*s,1*s];break;case 13:r=[16*s,16*s,16*s,16*s];break;case 14:const t=2*this.borderWidth;r=[t,t,t,t]}this.x=this.holderX+r[1],this.y=this.holderY+r[0],this.width=this.holderWidth-r[1]-r[3],this.height=this.holderHeight-r[0]-r[2],o||this.drawBorderStyle(t),this.holderRegion&&t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}drawBorderStyle(e){const{scale:i}=this;if(0===this.borderStyle);else if(1===this.borderStyle)e.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(2===this.borderStyle){const s=1*i,r=this.holderY+s/2,o=this.holderX+s/2,h=this.holderY+this.holderHeight-s+s/2,n=this.holderX+this.holderWidth-s+s/2;e.strokePath({color:t.BLACK,path:new v(n,h).lineTo(n,r).moveTo(n,h).lineTo(o,h)}),e.strokePath({color:t.WHITE,path:new v(o,r).lineTo(n-s,r).moveTo(o,r).lineTo(o,h-s)})}else if(3===this.borderStyle){const s=1*i,r=this.holderY+s/2,o=this.holderX+s/2,h=this.holderY+this.holderHeight-s+s/2,n=this.holderX+this.holderWidth-s+s/2;e.strokePath({color:t.WHITE,path:new v(n,h).lineTo(n,r).moveTo(n,h).lineTo(o,h)}),e.strokePath({color:t.BLACK,path:new v(o,r).lineTo(n-s,r).moveTo(o,r).lineTo(o,h-s)})}else if(4===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_LIGHTEST,t.BUTTON_DARKER,t.BUTTON_DARKER,t.BUTTON_LIGHTEST);else if(5===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_DARKER,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKER);else if(6===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_DARKEST,t.BUTTON_DARKER,t.BUTTON,t.BUTTON_LIGHTEST);else if(7===this.borderStyle)this.drawShadowBorder(e,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKEST,t.BUTTON_DARKER);else if(8===this.borderStyle)this.drawDashedBorder(e,[2*i,2*i]);else if(9===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i]);else if(10===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i,2*i,2*i]);else if(11===this.borderStyle)this.drawDashedBorder(e,[6*i,2*i,2*i,2*i,2*i,2*i]);else if(12===this.borderStyle)e.fillRect({x:this.holderX,y:this.holderY+1*i,width:this.holderWidth,height:16*i,color:this.borderColor}),e.fillText({x:this.holderX+1*i+3*i,y:this.holderY+1*i+8*i,baseline:"middle",align:"left",font:W.ARIAL_11.scale(i),color:t.BLACK,text:this.name}),e.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:t.BLACK,crispen:!0});else if(13===this.borderStyle){this.transparent||e.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor}),e.fillText({x:this.holderX+16*i,y:this.holderY+8*i,baseline:"middle",align:"left",font:W.ARIAL_11.scale(i),color:this.borderColor,text:this.name});const t=e.measureText(this.name,W.ARIAL_11.scale(i)),s=1;let r=n(this.holderX+8*i,this.holderY+8*i,this.holderWidth-16*i-s,this.holderHeight-16*i-s,s);e.strokePath({color:this.backgroundColor.darker(),path:new v(r.x,r.y).lineTo(r.x+8*i,r.y).moveTo(r.x+8*i+t.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)}),r=n(this.holderX+8*i+s,this.holderY+8*i+s,this.holderWidth-16*i-s,this.holderHeight-16*i-s,s),e.strokePath({color:this.backgroundColor.brighter(),path:new v(r.x,r.y).lineTo(r.x+8*i-s,r.y).moveTo(r.x+8*i-s+t.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)})}else if(14===this.borderStyle){const t=n(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&e.fillRect(Object.assign(Object.assign({},t),{rx:4*i,ry:4*i,color:this.backgroundColor})),this.borderWidth&&e.strokeRect(Object.assign(Object.assign({},t),{rx:4*i,ry:4*i,color:this.borderColor,lineWidth:this.borderWidth}))}else 15===this.borderStyle||console.warn(`Unsupported border style: ${this.borderStyle}`)}drawDecoration(e){var i,s,r;if(this.display.editMode)return;const{scale:o}=this;if(!this.pvName||this.pv&&!this.pv.disconnected)this.pv&&void 0===this.pv.value&&e.strokeRect(Object.assign(Object.assign({},this.bounds),{dash:[2*o,2*o],lineWidth:2*o,color:t.PINK,crispen:!0}));else{const i=1*o;e.fillRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:t.PURPLE,opacity:.4}),e.strokeRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:t.PURPLE})}if(this.borderAlarmSensitive){let h;8===this.borderStyle?h=[2*o,2*o]:9===this.borderStyle?h=[6*o,2*o]:10===this.borderStyle?h=[6*o,2*o,2*o,2*o]:11===this.borderStyle&&(h=[6*o,2*o,2*o,2*o,2*o,2*o]),(null===(i=this.pv)||void 0===i?void 0:i.severity)===wt.MAJOR?e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.RED,crispen:!0,dash:h})):(null===(s=this.pv)||void 0===s?void 0:s.severity)===wt.MINOR?e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.ORANGE,crispen:!0,dash:h})):(null===(r=this.pv)||void 0===r?void 0:r.severity)===wt.INVALID&&e.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:t.PINK,crispen:!0}))}}drawOverlay(t){}drawSelection(t){t.lineWidth=1,t.strokeStyle="black",t.strokeRect(this.holderX-.5,this.holderY-.5,this.holderWidth+1,this.holderHeight+1),t.fillStyle="black";let e=2;t.fillRect(this.holderX-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight-e,e+e,e+e),t.strokeStyle="white",e=3,t.strokeRect(this.holderX-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1)}requestRepaint(){this.display.requestRepaint()}closeMenu(){}get bounds(){return{x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight}}get unscaledBounds(){return{x:this.properties.getValue("x"),y:this.properties.getValue("y"),width:this.properties.getValue("width"),height:this.properties.getValue("height")}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,s,r){const o=1*this.scale,h=this.holderY+o/2,n=this.holderX+o/2,a=this.holderY+this.holderHeight-o+o/2,l=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new v(l,a).lineTo(l,h).moveTo(l,a).lineTo(n,a)}),t.strokePath({color:i,path:new v(l-o,a-o).lineTo(l-o,h+o).moveTo(l-o,a-o).lineTo(n+o,a-o)}),t.strokePath({color:s,path:new v(n,h).lineTo(l-o,h).moveTo(n,h).lineTo(n,a-o)}),t.strokePath({color:r,path:new v(n+o,h+o).lineTo(l-o-o,h+o).moveTo(n+o,h+o).lineTo(n+o,a-o-o)})}drawDashedBorder(t,e){const i=n(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new v(i.x,i.y).lineTo(i.x+i.width,i.y).lineTo(i.x+i.width,i.y+i.height).lineTo(i.x,i.y+i.height).closePath()})}executeAction(t){const e=this.actions.getAction(t);if(e)switch(e.type){case"OPEN_DISPLAY":const t={path:e.path,replace:0===e.mode};this.display.fireEvent("opendisplay",t);break;case"EXECUTE_JAVASCRIPT":if(e.embedded){new ft(this.display.instance,e.text).run()}else fetch(`${this.display.baseUrl}${e.path}`,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{new ft(this.display.instance,t).run()}))}));break;case"WRITE_PV":if(e.pvName){const t=this.expandMacro(e.pvName);this.display.pvEngine.setValue(new Date,t,e.value)}break;case"PLAY_SOUND":if(e.path){new Audio(`${this.display.baseUrl}${e.path}`).play()}break;case"OPEN_WEBPAGE":e.hyperlink&&(window.location.href=e.hyperlink);break;default:throw new Error(`Unsupported command ${e.type}`)}}expandMacro(t){var e;if(-1===t.indexOf("$"))return t;for(const i of this.properties.all())if(i instanceof G){const s=this.properties.getProperty(i.pvPropertyName);let r="";const o=null==s?void 0:s.value;if(o){const t=this.display.getPV(o);r=null!==(e=null==t?void 0:t.value)&&void 0!==e?e:""}t=(t=t.replace(`$(${i.name})`,r)).replace(`\${${i.name}}`,r)}else t=(t=t.replace(`$(${i.name})`,i.value||"")).replace(`\${${i.name}}`,i.value||"");return this.parent?this.parent.expandContainerMacros(t):t}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MINOR}isMajorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MAJOR}get alarm(){var t,e;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MINOR||(null===(e=this.pv)||void 0===e?void 0:e.severity)===wt.MAJOR}get alarmSensitiveBackgroundColor(){if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.foregroundColor}get scale(){let t=this.display.scale,e=this.parent;for(;e;)t*=e.relativeScale,e=e.parent;return t}get value(){return this._value}set value(t){this._value=t,this.requestRepaint()}addPropertyListener(t,e){this.properties.getProperty(t).addListener(e)}removePropertyListener(t,e){this.properties.getProperty(t).removeListener(e)}toDataURL(t="image/png",e){const i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue("wuid")}get name(){return this.properties.getValue("name")}get holderX(){return this.scale*this.properties.getValue("x")}get holderY(){return this.scale*this.properties.getValue("y")}get holderWidth(){return this.scale*this.properties.getValue("width")}get holderHeight(){return this.scale*this.properties.getValue("height")}get borderAlarmSensitive(){return this.properties.getValue("border_alarm_sensitive")}get backgroundAlarmSensitive(){return this.properties.getValue("backcolor_alarm_sensitive")}get foregroundAlarmSensitive(){return this.properties.getValue("forecolor_alarm_sensitive")}get pvName(){return this.properties.getValue("pv_name",!0)}get pvValue(){return this.properties.getValue("pv_value",!0)}get borderColor(){return this.properties.getValue("border_color")}get borderStyle(){return this.properties.getValue("border_style")}get borderWidth(){return this.scale*this.properties.getValue("border_width")}get backgroundColor(){return this.properties.getValue("background_color")}get enabled(){return this.properties.getValue("enabled")}get foregroundColor(){return this.properties.getValue("foreground_color")}get tooltip(){const t=this.properties.getProperty("tooltip");if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue("transparent")}get visible(){return this.properties.getValue("visible")}get actions(){return this.properties.getValue("actions")}get scripts(){return this.properties.getValue("scripts")}get rules(){return this.properties.getValue("rules")}get scaleOptions(){return this.properties.getValue("scale_options")}get widgetType(){return this.properties.getValue("widget_type",!0)}get text(){if(this.display.editMode){return(this.properties.getProperty("text").rawValue||"").split(" ").join(" ")}return this.properties.getValue("text").split(" ").join(" ")}init(){}hide(){}destroy(){}}class $t extends jt{constructor(t,e){super(t,e),this.pushed=!1,this.imageLoaded=!1,this.properties.add(new q("font")),this.properties.add(new z("toggle_button")),this.properties.add(new j("push_action_index")),this.properties.add(new j("release_action_index")),this.properties.add(new D("image"))}init(){if(this.image){this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()};const t=this.display.getImageResolver();this.imageElement.src=t.resolve(this.image)}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.pushed=!1,this.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,this.requestRepaint())},click:()=>{this.executeAction(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(e){const i=e.ctx,{scale:s}=this;e.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const r=1*s,o=this.holderY+r/2,h=this.holderX+r/2,n=this.holderY+this.holderHeight-r+r/2,a=this.holderX+this.holderWidth-r+r/2;e.strokePath({lineWidth:r,color:this.pushed?t.BUTTON_LIGHTEST:t.BLACK,path:new v(a,n).lineTo(a,o).moveTo(a,n).lineTo(h,n)}),e.strokePath({lineWidth:r,color:this.pushed?this.backgroundColor:t.BUTTON_DARKER,path:new v(a-r,n-r).lineTo(a-r,o+r).moveTo(a-r,n-r).lineTo(h+r,n-r)}),e.strokePath({lineWidth:r,color:this.pushed?t.BLACK:t.BUTTON_LIGHTEST,path:new v(h,o).lineTo(a-r,o).moveTo(h,o).lineTo(h,n-r)}),e.strokePath({lineWidth:r,color:this.pushed?t.BUTTON_DARKER:this.backgroundColor,path:new v(h+r,o+r).lineTo(a-r-r,o+r).moveTo(h+r,o+r).lineTo(h+r,n-r-r)});const l=this.text.split("\n");let d,c;if(i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),this.imageElement&&this.imageLoaded){const t=i.measureText(l[0]).width,e=this.font.height,r=this.imageElement.naturalHeight*s,o=this.imageElement.naturalWidth*s,h=(this.height-r)/e,n=5*s;if((this.width-o)/t>h){i.textBaseline="middle",i.textAlign="left",d=this.x+(this.width-t)/2+n,c=this.y+this.height/2;const e=this.x+(this.width-t)/2-o,s=this.y+(this.height-r)/2;i.drawImage(this.imageElement,e,s,o,r)}else{i.textAlign="center",i.textBaseline="top";const t=e+r;d=this.x+this.width/2,c=this.y+(this.height-t)/2+r;const s=this.x+(this.width-o)/2,h=this.y+(this.height-t)/2;i.drawImage(this.imageElement,s,h,o,r)}}else i.textBaseline="middle",i.textAlign="center",d=this.x+this.width/2,c=this.y+this.height/2;this.pushed&&(d+=1*s,c+=1*s),i.fillText(l[0],d,c)}get font(){return this.properties.getValue("font").scale(this.scale)}get image(){return this.properties.getValue("image")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("release_action_index")}get backgroundColor(){const e=this.properties.getProperty("background_color");return e&&e.value!==t.TRANSPARENT?e.value:t.BUTTON}}class zt extends jt{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new j("bit")),this.properties.add(new j("data_type")),this.properties.add(new z("square_button")),this.properties.add(new z("show_led")),this.properties.add(new z("effect_3d")),this.properties.add(new U("on_color")),this.properties.add(new D("on_label")),this.properties.add(new D("on_state")),this.properties.add(new U("off_color")),this.properties.add(new D("off_label")),this.properties.add(new D("off_state")),this.properties.add(new q("font")),this.properties.add(new z("toggle_button")),this.properties.add(new j("push_action_index")),this.properties.add(new j("released_action_index")),this.properties.add(new z("show_boolean_label"))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:e?this.onLabel:this.offLabel})}drawSquare(e,i){e.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:t.DARK_GRAY});e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=2*this.scale,r=i?t.DARK_GRAY:t.WHITE,o=i?t.WHITE:t.DARK_GRAY;this.effect3d&&(e.fillPath({color:r,path:new v(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+s,this.y+this.height-s).lineTo(this.x+s,this.y+s).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width,this.y).closePath()}),e.fillPath({color:o,path:new v(this.x,this.y+this.height).lineTo(this.x+this.width,this.y+this.height).lineTo(this.x+this.width,this.y).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width-s,this.y+this.height-s).lineTo(this.x+s,this.y+this.height-s).closePath()}));let h=this.backgroundColor;this.hovered&&(h=this.backgroundColor.mixWith(t.WHITE,.5)),e.fillRect({x:this.x+s,y:this.y+s,width:this.width-s-s,height:this.height-s-s,color:h})}drawEllipse(e,i){const{scale:s}=this;if(this.effect3d){const r=this.width/2,o=this.height/2,h=Math.sqrt(r*r+o*o),n=this.x+r+(o-r-h)/2-1*s,a=this.y+o-(o-r+h)/2-1*s,l=this.x+r+(o-r+h)/2+5*s,d=this.y+o-(o-r-h)/2+5*s,c=e.createLinearGradient(n,a,l,d);i?(c.addColorStop(0,t.DARK_GRAY.toString()),c.addColorStop(1,t.WHITE.toString())):(c.addColorStop(0,t.WHITE.toString()),c.addColorStop(1,t.DARK_GRAY.toString())),e.ctx.fillStyle=c}else e.ctx.fillStyle=i?t.WHITE.toString():t.DARK_GRAY.toString();const r=this.x+this.width/2,o=this.y+this.height/2,h=this.width/2,n=this.height/2;e.ctx.beginPath(),e.ctx.ellipse(r,o,h,n,0,0,2*Math.PI),e.ctx.fill();e.addHitRegion(this.areaRegion).addEllipse(r,o,h,n,0,0,2*Math.PI),this.hovered?e.ctx.fillStyle=this.backgroundColor.mixWith(t.WHITE,.5).toString():e.ctx.fillStyle=this.backgroundColor.toString(),e.ctx.beginPath(),e.ctx.ellipse(r,o,h-2*s,n-2*s,0,0,2*Math.PI),e.ctx.fill()}drawHorizontal(t,e){const{scale:i}=this;if(this.showLed){let s;this.squareButton?(s=Math.floor(.3*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-2*i)):(s=Math.floor(.25*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-8*i));const r={x:Math.floor(this.x+.79999*this.width-s/2),y:Math.floor(this.y+this.height/2-s/2),width:s,height:s},o=r.x+r.width/2,h=r.y+r.height/2,n=r.width/2,a=r.height/2,l=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:h,rx:n,ry:a,color:l}),this.effect3d){const e=t.createLinearGradient(r.x,r.y,r.x+r.width,r.y+r.height);e.addColorStop(0,"white"),e.addColorStop(1,l.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,h,n,a,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}drawVertical(e,i){const{scale:s}=this;if(this.showLed){let r;this.squareButton?(r=Math.floor(.3*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-2*s)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*s));const o={x:Math.floor(this.x+this.width/2-r/2),y:Math.floor(this.y+(1-.79999)*this.height-r/2),width:r,height:r},h=i?this.onColor:this.offColor,n=o.x+o.width/2,a=o.y+o.height/2,l=o.width/2,d=o.height/2;if(e.fillEllipse({cx:n,cy:a,rx:l,ry:d,color:h}),this.effect3d){const i=e.createLinearGradient(o.x,o.y,o.x+o.width,o.y+o.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.ctx.beginPath(),e.ctx.ellipse(n,a,l,d,0,0,2*Math.PI),e.ctx.fillStyle=i,e.ctx.fill()}}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get squareButton(){return this.properties.getValue("square_button")}get showLed(){return this.properties.getValue("show_led")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get effect3d(){return this.properties.getValue("effect_3d")}get onColor(){return this.properties.getValue("on_color")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offColor(){return this.properties.getValue("off_color")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}get font(){return this.properties.getValue("font").scale(this.scale)}}class Ut extends jt{constructor(t,e){super(t,e),this.manualToggleState=!1,this.properties.add(new j("bit")),this.properties.add(new j("data_type")),this.properties.add(new z("effect_3d")),this.properties.add(new U("on_color")),this.properties.add(new D("on_label")),this.properties.add(new D("on_state")),this.properties.add(new U("off_color")),this.properties.add(new D("off_label")),this.properties.add(new D("off_state")),this.properties.add(new j("push_action_index")),this.properties.add(new j("released_action_index")),this.properties.add(new z("toggle_button"))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,s=this.height;s>i/2?s=Math.floor(this.width/2):i=Math.floor(2*this.height);const r={x:Math.floor(63/218*i),y:0,width:s/2,height:s/2};this.drawPedestal(t,r,e);const o=Math.floor(35/218*i),h=Math.floor(45/105*s),n=Math.floor(43/218*i),a=Math.floor(35/105*s),l=Math.floor(1/7*r.width);if(e){const e={x:2*r.x+r.width-o,y:r.height/2-h/2,width:o,height:h},i={x:r.x+r.width/2-n/2+l,y:r.y+r.height/2-a/2,width:n,height:a};this.drawHorizontalBar(t,i,e,!0)}else{const e={x:0,y:r.height/2-h/2,width:o,height:h},i={x:r.x+r.width/2-n/2-l,y:r.y+r.height/2-a/2,width:n,height:a};this.drawHorizontalBar(t,i,e,!1)}}drawVertical(t,e){let i=this.width,s=this.height;i>s/2?i=Math.floor(this.height/2):s=Math.floor(2*this.width);const r={x:0,y:Math.floor(63/218*s),width:i/2,height:i/2};this.drawPedestal(t,r,e);const o=Math.floor(45/105*i),h=Math.floor(35/218*s),n=Math.floor(35/105*i),a=Math.floor(43/218*s);if(e){const e={x:r.width/2-o/2,y:0,width:o,height:h},i={x:r.x+r.width/2-n/2,y:r.y+r.height/2-a/2,width:n,height:a};i.y-=Math.floor(1/7*r.height),this.drawVerticalBar(t,i,e,!0)}else{const e=r.y+r.height/2+a/2+2*this.scale,i={x:r.width/2-o/2,y:r.y+r.height/2-a/2+e-h,width:o,height:h},s={x:r.x+r.width/2-n/2,y:r.y+r.height/2-a/2,width:n,height:a};s.y+=Math.floor(1/7*r.height),this.drawVerticalBar(t,s,i,!1)}}drawPedestal(e,i,s){let r=this.x+i.x+i.width/2,o=this.y+i.y+i.height/2,h=i.width/2,n=i.height/2;if(e.ctx.fillStyle=this.effect3d?t.WHITE.toString():t.GRAY.toString(),e.ctx.beginPath(),e.ctx.ellipse(r,o,h,n,0,0,2*Math.PI),e.ctx.fill(),this.effect3d){const t=e.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y+i.height);s?(t.addColorStop(0,`rgba(255,255,255,${10/255})`),t.addColorStop(1,`rgba(0,0,0,${100/255})`)):(t.addColorStop(0,"rgba(0,0,0,0)"),t.addColorStop(1,`rgba(0,0,0,${150/255})`)),e.ctx.fillStyle=t,e.ctx.fill()}}drawHorizontalBar(t,e,i,s){let r=(s?0:10)/255,o=(s?150:220)/255;const h=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);h.addColorStop(0,`rgba(0,0,0,${r})`),h.addColorStop(1,`rgba(0,0,0,${o})`);const n=t.addHitRegion(this.shaftRegion);let a=this.x+e.x+e.width/2,l=this.y+e.y+e.height/2,d=e.width/2,c=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),n.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=h,t.ctx.fill());const p=[Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y),Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y+i.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y+e.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y)];if(t.ctx.beginPath(),t.ctx.moveTo(p[0],p[1]),t.ctx.lineTo(p[2],p[3]),t.ctx.lineTo(p[4],p[5]),t.ctx.lineTo(p[6],p[7]),t.ctx.closePath(),n.addPath(new v(p[0],p[1]).lineTo(p[2],p[3]).lineTo(p[4],p[5]).lineTo(p[6],p[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=h,t.ctx.fill()),a=this.x+i.x+i.width/2,l=this.y+i.y+i.height/2,d=i.width/2,c=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),n.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const{scale:e}=this,s=Math.sqrt(d*d+c*c),h=c-d,n=this.x+i.x+d+(h-s)/2-1*e,a=this.x+i.y+c-(h+s)/2-1*e,l=this.x+i.x+d+(h+s)/2+5*e,p=this.x+i.y+c-(h-s)/2+5*e,g=t.createLinearGradient(n,a,l,p);g.addColorStop(0,`rgba(0,0,0,${r})`),g.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=g,t.ctx.fill()}}drawVerticalBar(t,e,i,s){const r=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);r.addColorStop(0,`rgba(0,0,0,${10/255})`),r.addColorStop(1,`rgba(0,0,0,${s?210/255:160/255})`);const o=t.addHitRegion(this.shaftRegion);let h=this.x+e.x+e.width/2,n=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(h,n,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(h,n,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill());const a=[Math.round(this.x+i.x),Math.round(this.y+i.y+i.height/2),Math.round(this.x+i.x+i.width),Math.round(this.y+i.y+i.height/2),Math.round(this.x+e.x+e.width),Math.round(this.y+e.y+e.height/2),Math.round(this.x+e.x),Math.round(this.y+e.y+e.height/2)];t.ctx.beginPath(),t.ctx.moveTo(a[0],a[1]),t.ctx.lineTo(a[2],a[3]),t.ctx.lineTo(a[4],a[5]),t.ctx.lineTo(a[6],a[7]),t.ctx.closePath(),o.addPath(new v(a[0],a[1]).lineTo(a[2],a[3]).lineTo(a[4],a[5]).lineTo(a[6],a[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill()),h=this.x+i.x+i.width/2,n=this.y+i.y+i.height/2;const l=i.width/2,d=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(h,n,l,d,0,0,2*Math.PI),o.addEllipse(h,n,l,d,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const e=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);e.addColorStop(0,`rgba(0,0,0,${(s?5:10)/255})`),e.addColorStop(1,`rgba(0,0,0,${(s?180:160)/255})`),t.ctx.fillStyle=e,t.ctx.fill()}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get effect3d(){return this.properties.getValue("effect_3d")}get onColor(){return this.properties.getValue("on_color")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offColor(){return this.properties.getValue("off_color")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}}const qt=new t(130,130,130),Yt=new t(94,151,230);class Xt extends jt{constructor(e,i){super(e,i),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new j("bit")),this.properties.add(new z("enabled")),this.properties.add(new q("font")),this.properties.add(new D("label")),this.properties.add(new U("selected_color",new t(64,64,64)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseOut:()=>{this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:this.manualToggleState}draw(e){e.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const i=this.booleanValue,{boxSize:s,gap:r,scale:o}=this;let h=this.backgroundColor;this.hovered&&(h=h.mixWith(Yt,.7));const n={x:this.x,y:this.y+this.height/2-s/2,width:s,height:s},a=e.createLinearGradient(n.x,n.y+1*o,n.x,n.y+n.height);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillRect(Object.assign(Object.assign({},n),{rx:2*o,ry:2*o,gradient:a})),e.strokeRect({x:n.x+.5*o,y:n.y+.5*o,width:n.width-1*o,height:n.height-1*o,rx:2*o,ry:2*o,color:qt}),i&&e.strokePath({lineWidth:3*o,color:this.selectedColor,path:new v(n.x+3*o,n.y+Math.floor(.45*s)).lineTo(n.x+Math.floor(.45*s),n.y+3*s/4-1*o).lineTo(n.x+s-2*o,n.y+3*o)}),this.enabled?e.fillText({x:n.x+n.width+r,y:n.y+n.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(e.fillText({x:n.x+n.width+r+1*o,y:n.y+n.height/2+1*o,align:"left",baseline:"middle",color:t.BUTTON_LIGHTEST,font:this.font,text:this.label}),e.fillText({x:n.x+n.width+r,y:n.y+n.height/2,align:"left",baseline:"middle",color:t.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return 16*this.scale}get gap(){return 4*this.scale}get bit(){return this.properties.getValue("bit")}get enabled(){return this.properties.getValue("enabled")}get selectedColor(){return this.properties.getValue("selected_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get label(){return this.properties.getValue("label")}}class Kt extends jt{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new z("enabled")),this.properties.add(new q("font")),this.properties.add(new z("horizontal")),this.properties.add(new Q("items",[])),this.properties.add(new z("items_from_pv")),this.properties.add(new U("selected_color"))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",mouseDown:()=>{this.pushedItem=t,this.requestRepaint()},mouseOut:()=>{this.pushedItem=void 0,this.requestRepaint()},mouseUp:()=>{this.pushedItem=void 0,this.requestRepaint()},click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:Math.round(this.area.x),y:Math.round(i),width:Math.round(this.area.width),height:Math.round(e)};i+=e,this.drawButton(t,r,s)}}drawButton(e,i,s){var r;const o=(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s],h=o||s===this.pushedItem;e.fillRect(Object.assign(Object.assign({},i),{color:o?this.selectedColor:this.backgroundColor}));e.addHitRegion(this.itemRegions[s]).addRect(i.x,i.y,i.width,i.height);const n=1*this.scale,a=i.y+n/2,l=i.x+n/2,d=i.y+i.height-n+n/2,c=i.x+i.width-n+n/2;e.strokePath({lineWidth:n,color:h?t.BUTTON_LIGHTEST:t.BLACK,path:new v(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d)}),e.strokePath({lineWidth:n,color:h?this.backgroundColor:t.BUTTON_DARKER,path:new v(c-n,d-n).lineTo(c-n,a+n).moveTo(c-n,d-n).lineTo(l+n,d-n)}),e.strokePath({lineWidth:n,color:h?t.BLACK:t.BUTTON_LIGHTEST,path:new v(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,d-n)}),e.strokePath({lineWidth:n,color:h?t.BUTTON_DARKER:this.backgroundColor,path:new v(l+n,a+n).lineTo(c-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,d-n-n)}),e.fillText({x:i.x+i.width/2,y:i.y+i.height/2,text:this.items[s],align:"center",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}get selectedColor(){return this.properties.getValue("selected_color")}}const Zt=new t(240,240,240);class Jt extends jt{constructor(t,e){super(t,e),this.listVisible=!1,this.itemRegions=[],this.properties.add(new z("enabled")),this.properties.add(new q("font")),this.properties.add(new Q("items",[])),this.properties.add(new z("items_from_pv"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t=this.listVisible;this.display.closeMenu(),this.items.length&&!t&&(this.listVisible=!0,this.hoveredItem=0,this.requestRepaint())},tooltip:()=>this.tooltip};for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,click:()=>{this.writeValue(this.items[t]),this.listVisible=!1,this.hoveredItem=void 0,this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){var e,i;let s=l(this.bounds,2*this.scale);t.fillRect(Object.assign(Object.assign({},s),{color:this.backgroundColor})),t.strokeRect(Object.assign(Object.assign({},s),{color:Zt,crispen:!0}));t.addHitRegion(this.areaRegion).addRect(s.x,s.y,s.width,s.height),(null===(e=this.pv)||void 0===e?void 0:e.value)&&-1!==this.items.indexOf(this.pv.value)&&t.fillText({x:5*this.scale+s.x,y:s.y+s.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:null===(i=this.pv)||void 0===i?void 0:i.value});const{selectorWidth:r}=this,o=Math.min(s.height,r/2),h={x:s.x+s.width-r-5*this.scale+r/2,y:s.y+(s.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new v(h.x,h.y).lineTo(h.x-o,h.y-o).lineTo(h.x+o,h.y-o).closePath()})}closeMenu(){this.listVisible=!1,this.requestRepaint()}drawOverlay(e){if(!this.listVisible||!this.items.length)return;let i=0,s=0;for(const t of this.items){const r=e.measureText(t,this.font);i=Math.max(i,r.width),s=Math.max(s,r.height)}const{scale:r}=this,o=5*r,h=o+s+o,n={x:this.bounds.x+5*r,y:this.bounds.y+this.bounds.height-5*r,width:o+i+o,height:h*this.items.length+2*r+2*r};e.fillRect(Object.assign(Object.assign({},n),{color:this.backgroundColor}));for(let i=0;i<this.items.length;i++){const s={x:n.x,y:n.y+2*r+i*h,width:n.width,height:h};e.addHitRegion(this.itemRegions[i]).addRect(s.x,s.y,s.width,s.height),i===this.hoveredItem&&e.fillRect(Object.assign(Object.assign({},s),{color:t.LIGHT_BLUE}))}e.strokeRect(Object.assign(Object.assign({},n),{color:Zt,lineWidth:1*r,crispen:!0}));for(let t=0;t<this.items.length;t++)e.fillText({x:n.x+o,y:n.y+2*r+t*h+h/2,font:this.font,color:this.foregroundColor,align:"left",baseline:"middle",text:this.items[t]})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get selectorWidth(){return 8*this.scale}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}}class Qt extends jt{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.manualToggleState=!1,this.properties.add(new j("bit")),this.properties.add(new j("data_type")),this.properties.add(new z("effect_3d")),this.properties.add(new D("on_image")),this.properties.add(new D("on_label")),this.properties.add(new D("on_state")),this.properties.add(new D("off_image")),this.properties.add(new D("off_label")),this.properties.add(new D("off_state")),this.properties.add(new q("font")),this.properties.add(new z("toggle_button")),this.properties.add(new j("push_action_index")),this.properties.add(new j("released_action_index")),this.properties.add(new z("show_boolean_label"))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage){const t=this.display.getImageResolver();this.onImageElement.src=t.resolve(this.onImage)}if(this.offImage){const t=this.display.getImageResolver();this.offImageElement.src=t.resolve(this.offImage)}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeAction(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeAction(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=l(e,2*this.scale,2*this.scale));const i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height);t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get toggleButton(){return this.properties.getValue("toggle_button")}get pushActionIndex(){return this.properties.getValue("push_action_index")}get releaseActionIndex(){return this.properties.getValue("released_action_index")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get effect3d(){return this.properties.getValue("effect_3d")}get onImage(){return this.properties.getValue("on_image")}get onLabel(){return this.properties.getValue("on_label")}get onState(){return this.properties.getValue("on_state")}get offImage(){return this.properties.getValue("off_image")}get offLabel(){return this.properties.getValue("off_label")}get offState(){return this.properties.getValue("off_state")}get font(){return this.properties.getValue("font").scale(this.scale)}}class te extends $t{}const ee=new t(120,120,120),ie=new t(94,151,230);class se extends jt{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new z("enabled")),this.properties.add(new q("font")),this.properties.add(new z("horizontal")),this.properties.add(new Q("items",[])),this.properties.add(new z("items_from_pv")),this.properties.add(new U("selected_color"))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,r,s)}}drawRadio(e,i,s){var r;const{radioRadius:o,dotRadius:h,gap:n}=this;let a=this.backgroundColor;s===this.hoveredItem&&(a=a.mixWith(ie,.7));const l=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);l.addColorStop(0,t.WHITE.toString()),l.addColorStop(1,a.toString()),e.fillEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:o,ry:o,gradient:l});const d=1*this.scale;e.strokeEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:o,ry:o,color:ee,lineWidth:d}),(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s]&&e.fillEllipse({cx:i.x+o,cy:i.y+i.height/2,rx:h+d/2,ry:h+d/2,color:this.selectedColor});e.addHitRegion(this.itemRegions[s]).addRect(i.x,i.y,i.width,i.height),e.fillText({x:i.x+o+o+n,y:i.y+i.height/2,text:this.items[s],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get radioRadius(){return 7*this.scale}get dotRadius(){return 2*this.scale}get gap(){return 4*this.scale}get enabled(){return this.properties.getValue("enabled")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get items(){return this.properties.getValue("items")}get itemsFromPV(){return this.properties.getValue("items_from_pv")}get selectedColor(){return this.properties.getValue("selected_color")}}const re=new t(243,243,243),oe=new t(232,232,231);class he extends jt{constructor(t,e){super(t,e),this.decreasePressed=!1,this.increasePressed=!1,this.pageDecreasePressed=!1,this.pageIncreasePressed=!1,this.properties.add(new z("enabled")),this.properties.add(new z("horizontal")),this.properties.add(new z("show_value_tip")),this.properties.add(new q("font")),this.properties.add(new $("maximum")),this.properties.add(new $("minimum")),this.properties.add(new $("step_increment")),this.properties.add(new $("page_increment")),this.properties.add(new $("bar_length"))}init(){this.decreaseRegion={id:`${this.wuid}-decrease`,mouseDown:()=>{this.decreasePressed=!0,this.stepDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.increaseRegion={id:`${this.wuid}-increase`,mouseDown:()=>{this.increasePressed=!0,this.stepIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{this.grabStartValue=this.getCoercedValue()},grab:t=>{const e=this.horizontal?t.dx:t.dy,i=(this.maximum-this.minimum)*e/this.dragRange;this.setCoercedValue(this.grabStartValue+i),this.requestRepaint()},tooltip:()=>this.tooltip},this.pageDecreaseRegion={id:`${this.wuid}-page-decrease`,mouseDown:()=>{this.pageDecreasePressed=!0,this.pageDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.pageIncreaseRegion={id:`${this.wuid}-page-increase`,mouseDown:()=>{this.pageIncreasePressed=!0,this.pageIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip}}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(e){const{scale:i}=this,s=l(this.bounds,2*i);e.fillRect(Object.assign(Object.assign({},s),{color:re}));const r=Math.min(s.height,s.width/2);this.drawLeftButton(e,{x:s.x,y:s.y,width:r,height:s.height}),this.drawRightButton(e,{x:s.x+s.width-r,y:s.y,width:r,height:s.height});const o=this.barLength,h=this.maximum+o,n=this.minimum,a=h-n,d=a-o,c=s.width-r-r,p=Math.floor(Math.max(6*i,c*o/a));this.dragRange=c-p;const g=this.getCoercedValue(),u=Math.floor((c-p)*(g-n)/d),m=c-u-p,f={x:s.x+r+u,y:s.y,width:p,height:s.height};e.fillRect(Object.assign(Object.assign({},f),{color:oe})),this.drawRaisedButtonBorder(e,f);e.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x+r,y:s.y,width:u,height:s.height};e.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&e.fillRect(Object.assign(Object.assign({},x),{color:t.BLACK}));const w={x:s.x+r+u+p,y:s.y,width:m,height:s.height};e.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&e.fillRect(Object.assign(Object.assign({},w),{color:t.BLACK}))}drawVertical(e){const{scale:i}=this,s=l(this.bounds,i);e.fillRect(Object.assign(Object.assign({},s),{color:re}));const r=Math.min(s.width,s.height/2);this.drawUpButton(e,{x:s.x,y:s.y,width:s.width,height:r}),this.drawDownButton(e,{x:s.x,y:s.y+s.height-r,width:s.width,height:r});const o=this.barLength,h=this.maximum+o,n=this.minimum,a=h-n,d=a-o,c=s.height-r-r,p=Math.floor(Math.max(6*i,c*o/a));this.dragRange=c-p;const g=this.getCoercedValue(),u=Math.floor((c-p)*(g-n)/d),m=c-u-p,f={x:s.x,y:s.y+r+u,width:s.width,height:p};e.fillRect(Object.assign(Object.assign({},f),{color:oe})),this.drawRaisedButtonBorder(e,f);e.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x,y:s.y+r,width:s.width,height:u};e.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&e.fillRect(Object.assign(Object.assign({},x),{color:t.BLACK}));const w={x:s.x,y:s.y+r+u+p,width:s.width,height:m};e.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&e.fillRect(Object.assign(Object.assign({},w),{color:t.BLACK}))}drawLeftButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:oe})),this.decreasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.decreaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x,y:s.y+s.height/2};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x+r,o.y-r).lineTo(o.x+r,o.y+r).closePath()})}drawRightButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:oe})),this.increasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.increaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x+r,y:s.y+s.height/2};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x-r,o.y+r).closePath()})}drawUpButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:oe})),this.decreasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.decreaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y+r).lineTo(o.x+r,o.y+r).closePath()})}drawDownButton(e,i){e.fillRect(Object.assign(Object.assign({},i),{color:oe})),this.increasePressed?this.drawPressedButtonBorder(e,i):this.drawRaisedButtonBorder(e,i);e.addHitRegion(this.increaseRegion).addRect(i.x,i.y,i.width,i.height);const s=l(i,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y+r};e.fillPath({color:t.BLACK,path:new v(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x+r,o.y-r).closePath()})}drawRaisedButtonBorder(e,i){this.drawButtonBorder(e,i,t.BUTTON_DARKEST,t.BUTTON_DARKER,t.BUTTON,t.BUTTON_LIGHTEST)}drawPressedButtonBorder(e,i){this.drawButtonBorder(e,i,t.BUTTON_LIGHTEST,t.BUTTON_LIGHTEST,t.BUTTON_DARKEST,t.BUTTON_DARKER)}drawButtonBorder(t,e,i,s,r,o){const h=1*this.scale,n=e.y+h/2,a=e.x+h/2,l=e.y+e.height-h+h/2,d=e.x+e.width-h+h/2;t.strokePath({color:i,path:new v(d,l).lineTo(d,n).moveTo(d,l).lineTo(a,l)}),t.strokePath({color:s,path:new v(d-h,l-h).lineTo(d-h,n+h).moveTo(d-h,l-h).lineTo(a+h,l-h)}),t.strokePath({color:r,path:new v(a,n).lineTo(d-h,n).moveTo(a,n).lineTo(a,l-h)}),t.strokePath({color:o,path:new v(a+h,n+h).lineTo(d-h-h,n+h).moveTo(a+h,n+h).lineTo(a+h,l-h-h)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepIncreaseRepeatedly()),150)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepDecreaseRepeatedly()),150)}stepIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.stepIncrement)}stepDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageIncreaseRepeatedly()),150)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageDecreaseRepeatedly()),150)}pageIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.pageIncrement)}pageDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.pageIncrement)}setCoercedValue(t){this.pv&&this.pv.writable&&(t=t<this.minimum?this.minimum:t>this.maximum?this.maximum:t,this.display.pvEngine.setValue(new Date,this.pv.name,t))}getCoercedValue(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;return i<this.minimum?this.minimum:i>this.maximum?this.maximum:i}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue("enabled")}get horizontal(){return this.properties.getValue("horizontal")}get showValueTip(){return this.properties.getValue("show_value_tip")}get font(){return this.properties.getValue("font").scale(this.scale)}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get stepIncrement(){return this.properties.getValue("step_increment")}get pageIncrement(){return this.properties.getValue("page_increment")}get barLength(){return this.properties.getValue("bar_length")}}class ne extends jt{constructor(t,e){super(t,e),this.properties.add(new q("font")),this.properties.add(new j("format_type")),this.properties.add(new j("horizontal_alignment")),this.properties.add(new j("precision")),this.properties.add(new z("precision_from_pv")),this.properties.add(new j("vertical_alignment",1))}draw(t){const e=t.ctx;this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const i=document.createElement("canvas");i.width=this.area.width,i.height=this.area.height;const s=i.getContext("2d");s.fillStyle=this.alarmSensitiveForegroundColor.toString(),s.font=this.font.getFontString();let r=this.x;0===this.horizAlignment?s.textAlign="start":1===this.horizAlignment?(r+=this.width/2,s.textAlign="center"):2===this.horizAlignment&&(r+=this.width,s.textAlign="end");let o=this.y;0===this.vertAlignment?s.textBaseline="top":1===this.vertAlignment?(o+=this.height/2,s.textBaseline="middle"):2===this.vertAlignment&&(o+=this.height,s.textBaseline="bottom");let h=this.text;if(this.pv&&void 0!==this.pv.value){const t=this.precisionFromPV?this.pv.precision:this.precision;h=this.pv.formatValue(this.formatType,t)}s.fillText(h,r-this.area.x,o-this.area.y),e.drawImage(i,this.area.x,this.area.y)}get font(){return this.properties.getValue("font").scale(this.scale)}get formatType(){return this.properties.getValue("format_type")}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get precision(){return this.properties.getValue("precision")}get precisionFromPV(){return this.properties.getValue("precision_from_pv")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}}class ae extends jt{constructor(t,e){super(t,e),this.properties.add(new j("alpha",255)),this.properties.add(new j("line_width")),this.properties.add(new j("start_angle")),this.properties.add(new j("total_angle")),this.properties.add(new z("fill")),this.properties.add(new j("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2,o=-g(this.startAngle),h=-g(this.totalAngle+this.startAngle);if(this.fill&&(t.ctx.fillStyle=this.alarmSensitiveBackgroundColor.toString(),t.ctx.beginPath(),t.ctx.moveTo(e,i),t.ctx.ellipse(e,i,s,r,0,o,h,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&0!==this.totalAngle){let n;const{scale:a}=this;0===this.lineStyle?n=[]:1===this.lineStyle?n=[6*a,2*a]:2===this.lineStyle?n=[2*a,2*a]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,startAngle:o,endAngle:h,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:n})}}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get lineStyle(){return this.properties.getValue("line_style")}get startAngle(){return this.properties.getValue("start_angle")}get totalAngle(){return this.properties.getValue("total_angle")}get fill(){return this.properties.getValue("fill")}}class le extends jt{constructor(t,e){super(t,e),this.properties.add(new j("alpha",255)),this.properties.add(new U("bg_gradient_color")),this.properties.add(new U("fg_gradient_color")),this.properties.add(new z("gradient")),this.properties.add(new j("line_width")),this.properties.add(new $("fill_level")),this.properties.add(new z("horizontal_fill")),this.properties.add(new U("line_color")),this.properties.add(new j("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2;if(!this.transparent){const o=this.alarmSensitiveBackgroundColor;if(this.gradient){const h=this.horizontalFill?this.x:this.x+this.width,n=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,h,n);a.addColorStop(0,this.backgroundGradientStartColor.toString()),a.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:s,ry:r,gradient:a})}else t.fillEllipse({cx:e,cy:i,rx:s,ry:r,color:o})}this.lineWidth&&(0===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth}):1===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`))}drawFill(t){const e=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.x+this.width/2,s=this.y+this.height/2,r=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,h=this.alarmSensitiveForegroundColor;if(this.gradient){const e=this.horizontalFill?this.x:this.x+this.width,n=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,e,n);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,h.toString()),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,gradient:a})}else t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:h});t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class de extends jt{constructor(t,e){super(t,e),this.imageLoading=!1,this.imageLoaded=!1,this.properties.add(new D("image_file")),this.properties.add(new D("no_animation")),this.properties.add(new z("transparency",!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoading&&this.imageSnapshot?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){if(this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile){this.currentImageFile=this.imageFile;const t=this.display.getImageResolver();this.imageElement.src=t.resolve(this.imageFile)}}snapshotImage(t){const e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue("transparency")}get imageFile(){return this.properties.getValue("image_file")}get noAnimation(){return this.properties.getValue("no_animation")}}class ce extends jt{constructor(t,e){super(t,e),this.properties.add(new q("font")),this.properties.add(new j("horizontal_alignment")),this.properties.add(new j("vertical_alignment")),this.properties.add(new z("wrap_words"))}draw(t){const e=t.ctx;this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const i=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let s=0;for(const t of i){const i=e.measureText(t).width;s=Math.max(s,i)}let r=this.x;1===this.horizAlignment?r=this.x+(this.width-s)/2:2===this.horizAlignment&&(r=this.x+(this.width-s));const o=i.length*this.font.height+(i.length-1)*this.font.height*.2;let h=this.y;1===this.vertAlignment?h+=(this.height-o)/2:2===this.vertAlignment&&(h+=this.height-o);for(const t of i)e.fillText(t,r,h),h+=1.2*this.font.height}wrapText(t,e,i){let s=[];for(const r of e.split("\n"))s=s.concat(this.wrapLine(t,r,i));return s}wrapLine(t,e,i){if(!e)return[""];const s=[];let r,o,h,n=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(r=e.substr(0,o),o!==e.length)for(h=0;-1!==r.indexOf(" ",h);h=r.indexOf(" ",h)+1);s.push(r.substr(0,h||r.length)),n=Math.max(n,t.measureText(s[s.length-1],this.font).width),e=e.substr(s[s.length-1].length,e.length)}return s}get font(){return this.properties.getValue("font").scale(this.scale)}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}get wrapWords(){return this.properties.getValue("wrap_words")}}class pe extends jt{constructor(t,e){super(t,e),this.properties.add(new j("alpha",255)),this.properties.add(new j("line_width")),this.properties.add(new $("fill_level")),this.properties.add(new z("horizontal_fill")),this.properties.add(new U("line_color")),this.properties.add(new j("line_style")),this.properties.add(new X("points",[]))}init(){this.addPropertyListener("x",((t,e)=>{const i=p(this.properties.getValue("points"),t-e,0);this.properties.setValue("points",i),this.requestRepaint()})),this.addPropertyListener("y",((t,e)=>{const i=p(this.properties.getValue("points"),0,t-e);this.properties.setValue("points",i),this.requestRepaint()}))}draw(t){const{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;const i=v.fromPoints(this.points).closePath();if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:e})}this.lineWidth&&(0===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):2===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor,dash:[6*e,2*e]}):console.warn(`Unsupported polygon line style ${this.lineStyle}`)),this.fillLevel&&this.drawFill(t,i),t.ctx.globalAlpha=1}drawFill(t,e){let i=this.y,s=this.width,r=this.height;this.horizontalFill?s*=this.fillLevel/100:(r*=this.fillLevel/100,i+=r),t.ctx.save();let o=this.x-this.lineWidth/2,h=i-this.lineWidth/2,n=s+this.lineWidth,a=r+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,h,n,a),t.ctx.clip();const l=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:l}),t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get points(){return x(this.properties.getValue("points"),this.scale)}}class ge extends jt{constructor(t,e){super(t,e),this.properties.add(new j("alpha",255)),this.properties.add(new j("line_width")),this.properties.add(new $("fill_level")),this.properties.add(new z("horizontal_fill")),this.properties.add(new X("points",[])),this.properties.add(new j("arrow_length")),this.properties.add(new z("fill_arrow")),this.properties.add(new j("arrows"))}draw(t){const e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,s=this.height;this.horizontalFill?i*=this.fillLevel/100:(s*=this.fillLevel/100,e+=s),t.save();let r=this.x-this.lineWidth/2,o=e-this.lineWidth/2,h=i+this.lineWidth,n=s+this.lineWidth;t.beginPath(),t.rect(r,o,h,n),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let e=0;e<this.points.length;e++)0===e?t.moveTo(this.points[e].x,this.points[e].y):t.lineTo(this.points[e].x,this.points[e].y);if(t.stroke(),this.points.length>=2){const i=this.points[0],s=this.points[this.points.length-1];if(2===this.arrows||3===this.arrows){const i=this.calculateArrowPoints(this.points[this.points.length-2],s);if(i[2]=s,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<i.length;e++)0===e?t.moveTo(i[e].x,i[e].y):t.lineTo(i[e].x,i[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(i[0].x,i[0].y),t.moveTo(s.x,s.y),t.lineTo(i[1].x,i[1].y),t.stroke()}if(1===this.arrows||3===this.arrows){const s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<s.length;e++)0===e?t.moveTo(s[e].x,s[e].y):t.lineTo(s[e].x,s[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){const i=m(e,t),s=Math.PI/10,r=new f(this.arrowLength,i.theta-s),o=new f(this.arrowLength,i.theta+s),h=new f(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[c(r.toPoint(),e.x,e.y),c(o.toPoint(),e.x,e.y),c(h.toPoint(),e.x,e.y)]}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get points(){return x(this.properties.getValue("points"),this.scale)}get arrows(){return this.properties.getValue("arrows")}get fillArrow(){return this.properties.getValue("fill_arrow")}get arrowLength(){return this.properties.getValue("arrow_length")}}class ue extends jt{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new j("alpha",255)),this.properties.add(new U("bg_gradient_color")),this.properties.add(new U("fg_gradient_color")),this.properties.add(new z("gradient")),this.properties.add(new j("line_width")),this.properties.add(new $("fill_level")),this.properties.add(new z("horizontal_fill")),this.properties.add(new U("line_color")),this.properties.add(new j("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported rectangle line style ${this.lineStyle}`))}drawFill(t){const e=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.alarmSensitiveForegroundColor;if(this.gradient){const s=this.horizontalFill?e.x:e.x+e.width,r=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,s,r);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect(Object.assign(Object.assign({},e),{gradient:o}))}else t.fillRect(Object.assign(Object.assign({},e),{color:i}));t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class me extends jt{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new j("alpha",255)),this.properties.add(new U("bg_gradient_color")),this.properties.add(new U("fg_gradient_color")),this.properties.add(new z("gradient")),this.properties.add(new j("line_width")),this.properties.add(new $("fill_level")),this.properties.add(new z("horizontal_fill")),this.properties.add(new U("line_color")),this.properties.add(new j("corner_width")),this.properties.add(new j("corner_height")),this.properties.add(new j("line_style"))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported RoundedRectangle line style ${this.lineStyle}`))}drawFill(t){const e=this.cornerWidth/2,i=this.cornerHeight/2,s=l(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const e=s.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(s.x,s.y,e,s.height)}else{const e=s.height*(this.fillLevel/100),i=s.y+s.height-e;t.ctx.beginPath(),t.ctx.rect(s.x,i,s.width,s.height)}t.ctx.clip();const r=this.alarmSensitiveForegroundColor;if(this.gradient){const o=this.horizontalFill?s.x:s.x+s.width,h=this.horizontalFill?s.y+s.height:s.y,n=t.createLinearGradient(s.x,s.y,o,h);n.addColorStop(0,this.foregroundGradientStartColor.toString()),n.addColorStop(1,r.toString()),t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,gradient:n}))}else t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,color:r}));t.ctx.restore()}get alpha(){return this.properties.getValue("alpha")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get fillLevel(){return this.properties.getValue("fill_level")}get horizontalFill(){return this.properties.getValue("horizontal_fill")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get gradient(){return this.properties.getValue("gradient")}get cornerWidth(){return this.scale*this.properties.getValue("corner_width")}get cornerHeight(){return this.scale*this.properties.getValue("corner_height")}get backgroundGradientStartColor(){return this.properties.getValue("bg_gradient_color")}get foregroundGradientStartColor(){return this.properties.getValue("fg_gradient_color")}}class fe extends jt{constructor(e,i){super(e,i),this.properties.add(new z("bitReverse")),this.properties.add(new z("effect_3d")),this.properties.add(new z("horizontal")),this.properties.add(new j("numBits")),this.properties.add(new U("off_color")),this.properties.add(new U("on_color")),this.properties.add(new j("startBit")),this.properties.add(new z("square_led")),this.properties.add(new j("led_border",3)),this.properties.add(new U("led_border_color",t.DARK_GRAY)),this.properties.add(new z("led_packed",!1))}getLedColor(t){var e,i;let s=!1;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value))for(let e=this.startBit;e<this.startBit+this.numBits;e++){let r=0;if(r=this.bitReverse?e-this.startBit:this.numBits-1-(e-this.startBit),r===t){s=((null===(i=this.pv)||void 0===i?void 0:i.value)>>e&1)>0;break}}return s?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=l(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,s;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),s=i);let r=0;r=i>e.height||this.squareLed?e.height:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const h={x:e.x+o*s,y:e.y,width:i,height:r};this.effect3d?this.drawSquare3d(t,h,o):this.drawSquare2d(t,h,o)}else{const h=Math.min(i,r),n={x:e.x+o*s,y:e.y,width:h,height:h};this.effect3d?this.drawCircle3d(t,n,o):this.drawCircle2d(t,n,o)}}drawVertical(t,e){let i,s;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),s=i);let r=0;r=i>e.width||this.squareLed?e.width:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const h={x:e.x,y:e.y+o*s,width:r,height:i};this.effect3d?this.drawSquare3d(t,h,o):this.drawSquare2d(t,h,o)}else{const h=Math.min(r,i),n={x:e.x,y:e.y+o*s,width:h,height:h};this.effect3d?this.drawCircle3d(t,n,o):this.drawCircle2d(t,n,o)}}drawCircle2d(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,h=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,h-=this.ledBorder/2),t.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:this.getLedColor(i)}),t.strokeEllipse({cx:s,cy:r,rx:o,ry:h,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(e,i,s){const r=i.x+i.width/2,o=i.y+i.height/2;let h=i.width/2,n=i.height/2;e.fillEllipse({cx:r,cy:o,rx:h,ry:n,color:t.WHITE});let a=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:r,cy:o,rx:h,ry:n,gradient:a});h=(i.width-2*this.ledBorder)/2,n=(i.height-2*this.ledBorder)/2,e.fillEllipse({cx:r,cy:o,rx:h,ry:n,color:this.getLedColor(s)}),a=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height),a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:r,cy:o,rx:h,ry:n,gradient:a})}drawSquare2d(t,e,i){const s=n(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect(Object.assign(Object.assign({},s),{color:this.getLedColor(i)})),t.strokeRect(Object.assign(Object.assign({},s),{color:this.ledBorderColor,lineWidth:this.ledBorder}))}drawSquare3d(t,e,i){t.fillRect(Object.assign(Object.assign({},e),{color:this.ledBorderColor}));let s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width,e.y)}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new v(e.x+e.width,e.y).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new v(e.x,e.y+e.height).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)});const r=e.x+this.ledBorder,o=e.y+this.ledBorder,h=e.width-2*this.ledBorder,n=e.height-2*this.ledBorder,a=this.getLedColor(i);t.fillRect({x:r,y:o,width:h,height:n,color:a}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.784)"),s.addColorStop(1,a.withAlpha(0).toString()),t.fillRect({x:r,y:o,width:h,height:n,gradient:s})}get bitReverse(){return this.properties.getValue("bitReverse")}get horizontal(){return this.properties.getValue("horizontal")}get numBits(){return this.properties.getValue("numBits")}get startBit(){return this.properties.getValue("startBit")}get ledPacked(){return this.properties.getValue("led_packed")}get ledBorder(){return this.scale*this.properties.getValue("led_border")}get ledBorderColor(){return this.properties.getValue("led_border_color")}get offColor(){return this.properties.getValue("off_color")}get onColor(){return this.properties.getValue("on_color")}get effect3d(){return this.properties.getValue("effect_3d")}get squareLed(){return this.properties.getValue("square_led")}}class xe{constructor(t){this.prefix="",this.suffix="",this.comma=0,this.minInt=1,this.minFrac=0,this.maxFrac=0;for(let e=0;e<t.length;e++)if("#"==t.charAt(e)||"0"==t.charAt(e)){this.prefix=t.substring(0,e),t=t.substring(e);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");const e=t.replace(/[^0#,.]/g,"");let i="",s="";const r=e.indexOf(".");-1!==r?(i=e.substring(0,r),s=e.substring(r+1)):i=e;const o=i.lastIndexOf(",");-1!==o&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),s=s.replace(/[,]|[.]+/g,""),this.maxFrac=s.length;let h=i.replace(/[^0]/g,"");h.length>this.minInt&&(this.minInt=h.length),h=s.replace(/[^0]/g,""),this.minFrac=h.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||0==e.length)return t;if(-1!=e.indexOf("e")){const t=Number(e);if(t===1/0||t===-1/0)return e;if(e=t+"",-1!==e.indexOf("e"))return e}let i=!1;"-"===e.charAt(0)?(i=!0,e=e.substring(1)):"+"===e.charAt(0)&&(e=e.substring(1));const s=e.indexOf(".");let r="",o="";-1!=s?(r=e.substring(0,s),o=e.substring(s+1)):r=e,o=o.replace(/[.]/,"");const h=this.suffix&&"%"===this.suffix.charAt(0);let n=this.minInt,a=this.minFrac,l=this.maxFrac;if(h&&(n-=2,a+=2,l+=2),o.length>l){let t=Number("0."+o);t=0==l?Math.round(t):t.toFixed(l),o=t.toString(10).substr(2);let e,i=t>=1?1:0,s=r.length-1;for(;i;){if(-1==s){r="1"+r;break}e=Number(r.charAt(s)),9===e?(e="0",i=1):(e=++e+"",i=0),r=r.substring(0,s)+e+r.substring(s+1,r.length),s--}}for(let t=o.length;t<a;t++)o+="0";for(;o.length>a&&"0"==o.charAt(o.length-1);)o=o.substring(0,o.length-1);for(let t=r.length;t<n;t++)r="0"+r;for(;r.length>n&&"0"==r.charAt(0);)r=r.substring(1);h&&(r+=o.substring(0,2),o=o.substring(2));let d,c=0;for(let t=r.length;t>0;t--)0!=c&&c%this.comma==0&&(r=r.substring(0,t)+","+r.substring(t),c=0),c++;return d=o.length>0?this.prefix+r+"."+o+this.suffix:this.prefix+r+this.suffix,i&&(d="-"+d),d}formatBack(t){if(!(t+=""))return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;"-"===t.charAt(0)&&(e=e.substr(1),i=!0);const s=e.indexOf(this.prefix),r=""==this.suffix?e.length:e.indexOf(this.suffix,this.prefix.length+1);return 0==s&&r>0&&(e=e.substr(0,r),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){const e=Number(t)+"";if(t.indexOf(".")>-1&&e.indexOf(".")<0){for(var i=t.indexOf(".")+1;i<t.length;i++)if("0"!==t.charAt(i))return t;return e}return t}}class we{constructor(e,i,s){this.rampWidth=e,this.startAngle=i,this.endAngle=s,this.lolo=10,this.loloColor=t.RED,this.showLoLo=!0,this.lo=25,this.loColor=t.ORANGE,this.showLo=!0,this.hi=75,this.hiColor=t.ORANGE,this.showHi=!0,this.hihi=90,this.hihiColor=t.RED,this.showHiHi=!0,this.minimum=0,this.maximum=100,this.gradient=!0,this.logScale=!1,this.effect3d=!0,this.labelsOutside=!0,this.range={min:this.minimum,max:this.maximum},this.lengthInDegrees=0,this.radius=0}draw(t,e,i){if(this.labelsOutside){const t=9;this.radius=e.width/2-t}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(e,i){const s=i.x+i.width/2,r=i.y+i.height/2,o=i.width/2,h=i.height/2;let n,a=360-this.endAngle;if(n=this.endAngle-this.startAngle>0?this.startAngle-90:this.startAngle+90,this.showLoLo){let t=n,i=360-this.getValuePosition(this.lolo,!0);e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(t),endAngle:g(i),color:this.loloColor})}if(this.showLo){let t;t=this.showLoLo?this.lolo:this.minimum;const n=360-this.getValuePosition(t,!0),a=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){const l=g(this.getValuePosition(t,!0)-2),d=u(i.width/2,l,i),c=g(this.getValuePosition(this.lo,!0)+2),p=u(i.width/2,c,i),m=e.createLinearGradient(d.x,d.y,p.x,p.y);m.addColorStop(0,this.loloColor.toString()),m.addColorStop(1,this.loColor.toString()),e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n-1),endAngle:g(a+1),gradient:m})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n),endAngle:g(a),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let d=this.maximum;this.showHi?d=this.hi:this.showHiHi&&(d=this.hihi);const c=(l+d)/2;let p=360-this.getValuePosition(l,!0),m=360-this.getValuePosition(c,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){const n=g(this.getValuePosition(l,!0)-2),a=u(i.width/2,n,i),d=g(this.getValuePosition(c,!0)+2),f=u(i.width/2,d,i),x=e.createLinearGradient(a.x,a.y,f.x,f.y);x.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),x.addColorStop(1,t.GREEN.toString()),e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-1),endAngle:g(m+1),gradient:x})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p),endAngle:g(m),color:t.GREEN});if(p=360-this.getValuePosition(c,!0),m=360-this.getValuePosition(d,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){const n=g(this.getValuePosition(c,!0)-2),l=u(i.width/2,n,i),f=g(this.getValuePosition(d,!0)+2),x=u(i.width/2,f,i),w=e.createLinearGradient(l.x,l.y,x.x,x.y);w.addColorStop(0,t.GREEN.toString()),w.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());const y=m!==a?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-1),endAngle:g(m+y),gradient:w})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p),endAngle:g(m),color:t.GREEN});if(this.showHi){let t;t=this.showHiHi?this.hihi:this.maximum;const n=360-this.getValuePosition(this.hi,!0),l=360-this.getValuePosition(t,!0);if(this.effect3d&&this.gradient&&this.showHiHi){const d=g(this.getValuePosition(this.hi,!0)-2),c=u(i.width/2,d,i),p=g(this.getValuePosition(t,!0)+2),m=u(i.width/2,p,i),f=e.createLinearGradient(c.x,c.y,m.x,m.y);f.addColorStop(0,this.hiColor.toString()),f.addColorStop(1,this.hihiColor.toString());const x=l!==a?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n-1),endAngle:g(l+x),gradient:f})}else e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(n),endAngle:g(l),color:this.hiColor})}if(this.showHiHi){p=360-this.getValuePosition(this.hihi,!0),m=a;const t=this.gradient?1:0;e.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:h-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:g(p-t),endAngle:g(m),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){let i;return e&&(t=this.getValueInRange(t)),i=this.logScale?this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:this.startAngle-(t-this.range.min)/(this.range.max-this.range.min)*this.lengthInDegrees,i<0&&(i+=360),i}getValueInRange(t){return this.range.min<=t&&t<=this.range.max?t:t>this.range.max?this.range.max:this.range.min}getRenderedRange(){const t={min:this.minimum,max:this.maximum};return this.logScale&&(this.minimum<=0&&(t.min=.1),t.max<=this.minimum&&(t.max=t.min+100)),t}}const ye=new t(100,100,100);class ve extends jt{constructor(t,e){super(t,e),this.properties.add(new U("color_hi")),this.properties.add(new U("color_hihi")),this.properties.add(new U("color_lo")),this.properties.add(new U("color_lolo")),this.properties.add(new z("effect_3d")),this.properties.add(new q("font")),this.properties.add(new $("level_hi")),this.properties.add(new $("level_hihi")),this.properties.add(new $("level_lo")),this.properties.add(new $("level_lolo")),this.properties.add(new z("log_scale")),this.properties.add(new z("limits_from_pv")),this.properties.add(new $("maximum")),this.properties.add(new $("minimum")),this.properties.add(new U("needle_color")),this.properties.add(new z("ramp_gradient")),this.properties.add(new z("show_ramp",!0)),this.properties.add(new D("value_label_format"))}draw(t){var e,i;let s;s=this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:null!==(e=this.pv.lowerDisplayLimit)&&void 0!==e?e:this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:null!==(i=this.pv.upperDisplayLimit)&&void 0!==i?i:this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(s.min=Math.max(.1,s.min),s.max<=s.min&&(s.max=s.min+100));const r=Math.min(this.width,this.height),o=r;this.drawBackground(t,r,o),this.showRamp&&this.drawRamp(t,r,o,s),this.drawLabel(t,r,o),this.drawNeedle(t,r,o,s),this.drawNeedleCenter(t,r,o)}drawBackground(e,i,s){if(e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2,ry:s/2,color:t.GRAY}),this.effect3d){const r=e.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);r.addColorStop(0,ye.toString()),r.addColorStop(1,t.WHITE.toString()),e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2,ry:s/2,gradient:r})}const r=(this.effect3d?2:1)*this.scale;if(e.fillEllipse({cx:this.x+i/2,cy:this.y+s/2,rx:i/2-r,ry:s/2-r,color:this.backgroundColor}),this.effect3d){const r=i/2,o=.95,h=.5,n=.85,a=g(0),l=g(35);let d={x:Math.floor(this.x+i/2-r*n*Math.cos(a)),y:Math.floor(this.y+s/2-r*o),width:Math.floor(2*r*n*Math.cos(a)),height:Math.floor(r*o+r*h)},c=e.createLinearGradient(d.x,d.y,d.x,d.y+d.height);c.addColorStop(0,t.WHITE.withAlpha(90/255).toString()),c.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c}),d={x:Math.floor(this.x+i/2-r*n*Math.sin(l)),y:Math.floor(Math.ceil(this.y+s/2+r*h)),width:Math.floor(2*r*n*Math.sin(l)),height:Math.floor(Math.ceil(r*o-r*h))},c=e.createLinearGradient(d.x,d.y,d.x,d.y+d.height),c.addColorStop(0,t.WHITE.withAlpha(0).toString()),c.addColorStop(1,t.WHITE.withAlpha(40/255).toString()),e.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c})}}drawRamp(t,e,i,s){const r=l({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o=Object.assign({},r);o.width=Math.min(r.width,r.height),o.height=r.width;const h=new we(10*this.scale,225,315);h.lolo=s.lolo,h.loloColor=this.colorLoLo,h.lo=s.lo,h.loColor=this.colorLo,h.hi=s.hi,h.hiColor=this.colorHi,h.hihi=s.hihi,h.hihiColor=this.colorHiHi,h.minimum=s.min,h.maximum=s.max,h.effect3d=this.effect3d,h.gradient=this.rampGradient,h.logScale=this.logScale,h.draw(t,r,o)}drawLabel(t,e,i){var s;const r=W.ARIAL_12_BOLD.scale(this.scale);if(void 0!==(null===(s=this.pv)||void 0===s?void 0:s.value)){const s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+7*i/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,s){var r;const o=this.x+e/2,h=this.y+i/2;let n;if(void 0!==(null===(r=this.pv)||void 0===r?void 0:r.value)){const t=this.getValueInRange(this.pv.value,s);n=360-this.getValuePosition(t,s),s.max>s.min?t>s.max?n+=10:t<s.min&&(n-=10):t>s.min?n-=10:t<s.max&&(n+=10)}else n=360-this.getValuePosition((s.min+s.max)/2,s);const l=g(n),{scale:d}=this,{needleDiameter:c,majorTickLength:p,gapBetweenNeedleScale:u}=this,m=a(o,h-c/2+3*d,o,h,l),f=a(o+e/2-p-u,h,o,h,l),x=a(o,h+c/2-3*d,o,h,l);t.fillPath({color:this.needleColor,path:new v(m.x,m.y).lineTo(f.x,f.y).lineTo(x.x,x.y).closePath()})}drawNeedleCenter(e,i,s){const{needleDiameter:r}=this,o=this.x+i/2,h=this.y+s/2,n=r/2,a=r/2;if(this.effect3d){const i=e.createLinearGradient(o-n,h-a,o+n,h+a);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,ye.toString()),e.fillEllipse({cx:o,cy:h,rx:n,ry:a,gradient:i})}else e.fillEllipse({cx:o,cy:h,rx:n,ry:a,color:t.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i;return i=this.logScale?225-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*270:225-(t-e.min)/(e.max-e.min)*270,i<0&&(i+=360),i}formatLabelValue(t){return this.valueLabelFormat?new xe(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return 16*this.scale}get majorTickLength(){return 8*this.scale}get minorTickLength(){return 5*this.scale}get gapBetweenNeedleScale(){return-1*this.scale}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get effect3d(){return this.properties.getValue("effect_3d")}get font(){return this.properties.getValue("font").scale(this.scale)}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get needleColor(){return this.properties.getValue("needle_color")}get rampGradient(){return this.properties.getValue("ramp_gradient")}get showRamp(){return this.properties.getValue("show_ramp")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class be extends jt{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.properties.add(new j("bit")),this.properties.add(new j("data_type")),this.properties.add(new D("off_image")),this.properties.add(new D("off_label")),this.properties.add(new D("on_image")),this.properties.add(new D("on_label")),this.properties.add(new q("font")),this.properties.add(new z("show_boolean_label"))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage){const t=this.display.getImageResolver();this.onImageElement.src=t.resolve(this.onImage)}if(this.offImage){const t=this.display.getImageResolver();this.offImageElement.src=t.resolve(this.offImage)}}get booleanValue(){var t,e,i;return this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get font(){return this.properties.getValue("font").scale(this.scale)}get offLabel(){return this.properties.getValue("off_label")}get offImage(){return this.properties.getValue("off_image")}get onLabel(){return this.properties.getValue("on_label")}get onImage(){return this.properties.getValue("on_image")}}const _e=["January","February","March","April","May","June","July","August","September","October","November","December"];class Te{constructor(t,e,i,s,r,o,h,n,a){this.scale=t,this.scaleFont=e,this.minimum=i,this.maximum=s,this.logScale=r,this.majorTickStepHint=o,this.foregroundColor=h,this.showMinorTicks=n,this.showScale=a,this.labels=[],this.labelValues=[],this.labelPositions=[],this.labelVisibilities=[],this.gridStepInPixel=0,this.horizontal=!1,this.x=0,this.y=0,this.scaleFormat="",this.timeFormat=0,this.length=0,this.margin=0}get scaleLength(){return this.length-2*this.margin}getX(){return this.x}getY(){return this.y}getGridPositions(){let t=[...this.labelPositions];return this.horizontal||(t=t.map((t=>this.length-t))),t.pop(),t.shift(),t}setDimensions(t,e,i,s){this.x=t,this.y=e,this.length=i,this.horizontal=s}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),s=0;const r=this.length-2*this.margin;if(this.logScale)s=t<=0?this.margin:(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*r+this.margin;else{const o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;s=(t/o-e)/(i-e)*r+this.margin}return this.horizontal?s+this.x:this.length-s+this.y}getMinMax(){let t=this.minimum,e=this.maximum;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{start:t,stop:e}}getPositionValue(t){const e=this.getMinMax();let{start:i,stop:s}=e;const r=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin;let h;if(this.logScale)h=Math.pow(10,(r-this.margin)*(Math.log10(s)-Math.log10(i))/o+Math.log10(i));else{const t=Math.max(Math.abs(i),Math.abs(s));s/=t,i/=t;const e=s-i;h=((r-this.margin)/o*e+i)*t}return h}calculateMargin(t,e){if(this.showScale){const i=t.measureText(this.format(this.minimum),this.scaleFont),s=t.measureText(this.format(this.maximum),this.scaleFont);return e?Math.ceil(Math.max(i.width,s.width)/2):Math.ceil(Math.max(i.height,s.height)/2)}return 0}measureHorizontalHeight(t){const e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,s){const{scale:r}=this;this.length=s,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);const o=s-2*this.margin;o>0&&this.updateLabels(t,o);let h=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.height>h&&(h=i.height)}const n=this.showScale?h+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i-=n,this.x=e,this.y=i,this.logScale)for(let e=0;e<this.labelPositions.length;e++){const i=this.x+this.labelPositions[e],s=this.y;let o=0;if(o=this.labelVisibilities[e]?this.majorTickLength:this.minorTickLength,this.labelVisibilities[e]||this.showMinorTicks){const e=Math.round(i)-.5*r;t.strokePath({path:new v(e,s).lineTo(e,s+o),color:this.foregroundColor,lineWidth:1*r,opacity:100/255})}this.labelVisibilities[e]&&t.fillText({x:i,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[e]})}else for(let s=0;s<this.labels.length;s++){const o=e+this.labelPositions[s];this.labelVisibilities[s]&&t.fillText({x:o,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[s]});const h=Math.round(o)-.5*r;t.strokePath({path:new v(h,i).lineTo(h,i+this.majorTickLength),color:this.foregroundColor,lineWidth:1*r,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,s,e,i)}return n}drawVertical(t,e,i,s,r,o=!1){const{scale:h}=this;this.length=s,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);const n=s-2*this.margin;n>0&&this.updateLabels(t,n);let a=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.width>a&&(a=i.width)}const l=this.showScale?a+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(r||(e-=l),this.x=e,this.y=i,this.logScale)for(let r=0;r<this.labelPositions.length;r++){let o;o=this.labelVisibilities[r]?this.majorTickLength:this.minorTickLength;const n=e+a+this.spaceBetweenMarkAndLabel-1*h+this.majorTickLength-o,l=Math.round(i+s-this.labelPositions[r])-.5*h;if((this.labelVisibilities[r]||this.showMinorTicks)&&t.strokePath({path:new v(n,l).lineTo(n+o,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.labelVisibilities[r]){const o=i+s-this.labelPositions[r];t.fillText({x:e,y:o,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else for(let r=0;r<this.labels.length;r++){const n=i+s-this.labelPositions[r],l=Math.round(n)-.5*h;if(o){if(t.strokePath({path:new v(e,l).lineTo(e+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.labelVisibilities[r]){const i=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:i,y:n,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else{this.labelVisibilities[r]&&t.fillText({x:e,y:n,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]});const o=e+a+this.spaceBetweenMarkAndLabel-1*h;t.strokePath({path:new v(o,l).lineTo(o+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*h,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,r,o,i+s)}}return l}drawMinorXTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,h;r/5>=this.minorTickMarkStepHint?(o=5,h=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,h=Math.floor(r/4)):(o=2,h=Math.floor(r/2));const{labelPositions:n,minorTickLength:a,scale:l}=this;if(e>0)if(1===e&&n[1]-n[0]<r){let e=n[1];for(;e-n[0]>h+3*l;){e-=h;const r=Math.round(i+e)-.5*l;t.strokePath({path:new v(r,s).lineTo(r,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else if(e===n.length-1&&n[e]-n[e-1]<r){let r=n[e-1];for(;n[e]-r>h+3*l;){r+=h;const e=Math.round(i+r)-.5*l;t.strokePath({path:new v(e,s).lineTo(e,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else for(let r=0;r<o;r++){let h=i+n[e-1]+(n[e]-n[e-1])*r/o;h=Math.round(h)-.5*l,t.strokePath({path:new v(h,s).lineTo(h,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}drawMinorYTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,h;r/5>=this.minorTickMarkStepHint?(o=5,h=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,h=Math.floor(r/4)):(o=2,h=Math.floor(r/2));const{labelPositions:n,minorTickLength:a,majorTickLength:l,scale:d}=this;if(e>0)if(1===e&&n[1]-n[0]<r){let e=n[1];for(;e-n[0]>h+3*d;){e-=h;const r=Math.round(s-e)-.5*d;t.strokePath({path:new v(i+l-a,r).lineTo(i+l,r),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else if(e===n.length-1&&n[e]-n[e-1]<r){let r=n[e-1];for(;n[e]-r>h+3*d;){r+=h;const e=Math.round(s-r)-.5*d;t.strokePath({path:new v(i+l-a,e).lineTo(i+l,e),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else for(let r=0;r<o;r++){let h=s-n[e-1]-(n[e]-n[e-1])*r/o;h=Math.round(h)-.5*d,t.strokePath({path:new v(i+l-a,h).lineTo(i+l,h),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}updateLabels(t,e){if(this.labels=[],this.labelValues=[],this.labelPositions=[],this.showScale)if(this.logScale)this.updateLabelsForLogScale(this.minimum,this.maximum,e);else{const t=this.getGridStep(e,this.minimum,this.maximum),i=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/i-this.minimum/i;this.gridStepInPixel=Math.floor(e*(t/i)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,t)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let s=!1;if(e>=i)if(i===e)i++;else{s=!0;const t=e;e=i,i=t}const r=Math.abs(i-e);let o=this.majorTickStepHint;o>t&&(o=t);let h,n=r/t*o,a=0;if(n<1){if(0!=n)for(;n<1;)n*=10,a--}else for(;n>=10;)n/=10,a++;return h=n>7.5?10*Math.pow(10,a):n>3.5?5*Math.pow(10,a):n>1.5?2*Math.pow(10,a):Math.pow(10,a),s&&(h=-h),h}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);const s=e<t,r=Math.log10(t),o=Math.ceil(r),h=Math.ceil(Math.log10(e));let n,a=Math.pow(10,o-1);n=t%a<=0||s?t-t%a:t-t%a+a,(s&&t>n||!s&&t<n)&&this.addMinMaxTickInfo(t,i,!0);for(let t=o;s?t>=h:t<=h;t+=s?-1:1)if(Math.abs(h-o)>20){const s=Math.pow(10,t);if(s>e)break;this.addTickInfo(s,e,r,i)}else{for(let o=n;(s?o>=Math.pow(10,t-1):o<=Math.pow(10,t))&&!(s?o<e:o>e);o=s?o-a:o+a)this.addTickInfo(o,e,r,i);a=s?a/Math.pow(10,1):a*Math.pow(10,1),n=s?Math.pow(10,t-1):a+Math.pow(10,t)}(s?e<this.labelValues[this.labelValues.length-1]:e>this.labelValues[this.labelValues.length-1])&&this.addMinMaxTickInfo(e,i,!1)}addMinMaxTickInfo(t,e,i){i?(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin)):(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin+e))}addTickInfo(t,e,i,s){this.labels.push(this.format(t));const r=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*s)+this.margin;this.labelPositions.push(r),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,s){let r;r=t%s<=0?t-t%s:t-t%s+s,t>r==e<t&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let o=1;const h=Math.max(Math.abs(t),Math.abs(e));s/=h,r/=h;const n=(e/=h)-(t/=h);for(let a=r;e>=t?a<e:a>e;a=r+o++*s){const e=a*h;this.labels.push(this.format(e)),this.labelValues.push(e);const s=Math.floor((a-t)/n*i)+this.margin;this.labelPositions.push(s)}e*=h,this.labelValues.push(e),this.labels.push(this.format(e)),this.labelPositions.push(this.margin+i)}updateVisibility(t){if(this.labelVisibilities=[],!this.labelPositions.length)return;for(let t=0;t<this.labelPositions.length;t++)this.labelVisibilities.push(!0);let e=0,i=null;for(let s=0;s<this.labelPositions.length;s++){let r=!0;const o=this.labels[s],h=this.labelPositions[s];0!==s&&(r=this.hasSpaceToDraw(t,e,h,i||"",o));const n=o===i&&0!==s&&s!==this.labelPositions.length-1;let a=!0;if(this.logScale){const t=Number(this.labels[s]);a=this.isMajorTick(t)||0===s||s===this.labelPositions.length-1}r&&!n&&a?(e=h,i=o):this.labelVisibilities[s]=!1}}hasSpaceToDraw(t,e,i,s,r){const o=t.measureText(r,this.scaleFont),h=t.measureText(s,this.scaleFont);let n=i-e,a=Math.floor(this.horizontal?o.width/2+h.width/2:o.height),l=!0,d=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){l=n>a+this.tickLabelGap;const e=t.measureText(this.labels[this.labels.length-1],this.scaleFont);n=this.labelPositions[this.labelPositions.length-1]-i,a=Math.floor(this.horizontal?o.width/2+e.width/2:o.height),d=n>a+this.tickLabelGap}return l&&d}isMajorTick(t){if(!this.logScale)return!0;const e=Math.log10(t);return e===Math.round(e)}format(t){if(0===this.timeFormat)return this.scaleFormat?new xe(this.scaleFormat).format(t):String(Number(t.toFixed(2)));const e=new Date(t);switch(this.timeFormat){case 1:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return this.formatDate(e,{year:!0,month:!0,day:!0});case 7:return`${_e[e.getUTCMonth()]} ${e.getUTCDate()}`;case 8:const t=Math.abs(this.maximum-this.minimum);return t<=5e3?this.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):t<=18e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):t<=864e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=6048e5?this.formatDate(e,{year:!1,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=2592e6?this.formatDate(e,{year:!1,month:!0,day:!0}):this.formatDate(e,{year:!0,month:!0,day:!0})}return""}formatDate(t,e){let i="";if(e.year&&(i+=t.getUTCFullYear()),e.month){e.year&&(i+="-");const s=t.getUTCMonth();i+=(s<10?"0":"")+s}if(e.day){e.month&&(i+="-");const s=t.getUTCDate();i+=(s<10?"0":"")+s}return i}formatTime(t,e){let i="";if(e.hours){const e=t.getUTCHours();i+=(e<10?"0":"")+e}if(e.minutes){e.hours&&(i+=":");const s=t.getUTCMinutes();i+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(i+=":");const s=t.getUTCSeconds();i+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(i+=".");const s=t.getUTCMilliseconds();i+=(s<10?"00":s<100?"0":"")+s}return i}get spaceBetweenMarkAndLabel(){return 2*this.scale}get majorTickLength(){return 6*this.scale}get minorTickLength(){return 3*this.scale}get minorTickMarkStepHint(){return 4*this.scale}get tickLabelGap(){return 2*this.scale}}class Se extends jt{constructor(t,e){super(t,e),this.properties.add(new Y("color_map")),this.properties.add(new j("crop_bottom")),this.properties.add(new j("crop_left")),this.properties.add(new j("crop_right")),this.properties.add(new j("crop_top")),this.properties.add(new j("data_height")),this.properties.add(new j("data_width")),this.properties.add(new j("graph_area_height")),this.properties.add(new j("graph_area_width")),this.properties.add(new q("font")),this.properties.add(new $("maximum")),this.properties.add(new $("minimum")),this.properties.add(new z("show_ramp")),this.properties.add(new U("x_axis_axis_color")),this.properties.add(new D("x_axis_axis_title")),this.properties.add(new j("x_axis_major_tick_step_hint")),this.properties.add(new $("x_axis_maximum")),this.properties.add(new $("x_axis_minimum")),this.properties.add(new q("x_axis_scale_font")),this.properties.add(new z("x_axis_show_minor_ticks")),this.properties.add(new q("x_axis_title_font")),this.properties.add(new z("x_axis_visible")),this.properties.add(new U("y_axis_axis_color")),this.properties.add(new D("y_axis_axis_title")),this.properties.add(new j("y_axis_major_tick_step_hint")),this.properties.add(new $("y_axis_maximum")),this.properties.add(new $("y_axis_minimum")),this.properties.add(new q("y_axis_scale_font")),this.properties.add(new z("y_axis_show_minor_ticks")),this.properties.add(new q("y_axis_title_font")),this.properties.add(new z("y_axis_visible"))}draw(t){const{scale:e}=this;let i=this.area;this.borderAlarmSensitive&&(i=l(i,2*e));const s=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},i),{color:s}));const{graphAreaWidth:r,graphAreaHeight:o}=this;this.xAxisVisible&&t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height;let h=0;this.yAxisVisible&&(h=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);const n=new Te(e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),a=n.calculateMargin(t,!0),d=new Te(e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),c=d.calculateMargin(t,!1),p=n.measureHorizontalHeight(t),g=o+2*c,u=d.drawVertical(t,i.x+h,i.y,g,!0),m=r+2*a,f=i.x+h+u-a,x=i.y+g+p-c;n.drawHorizontal(t,f,x,m);const w=1*e,y=Math.round(i.x+h+u)-w/2,b=Math.round(i.y+c)-w/2;t.strokePath({path:new v(y,b).lineTo(y,b+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:w});const _=y,T=b+o+w;t.strokePath({path:new v(_,T).lineTo(_+r,T),color:this.xAxisAxisColor,opacity:100/255,lineWidth:w});const{dataWidth:S,dataHeight:V,colorMap:A}=this,{minimum:L,maximum:C}=this,[k,P]=A.getMinMax();if(this.value&&this.value.length){const e=document.createElement("canvas"),{cropLeft:s,cropRight:n,cropTop:a,cropBottom:l}=this;e.width=S-s-n,e.height=V-a-l;const c=e.getContext("2d");for(let t=s;t<S-n;t++)for(let e=a;e<V-l;e++){let i=this.value[e*S+t];if(A.autoscale){i=k+(i-L)/(C-L)*(P-k)}const[r,o,h]=A.lookup(i);c.fillStyle=`rgb(${r},${o},${h})`,c.fillRect(t-s,e-a,1,1)}const p=Math.round(i.x+h+u),g=Math.round(i.y+d.margin);t.ctx.drawImage(e,p,g,r,o)}if(this.showRamp){const s=new Te(e,this.font,L,C,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),n=i.y+d.margin,a=o,l=s.drawVertical(t,i.x+i.width,n,a,!1,!0),c=i.x+h+u+r+this.gap,p=i.width-h-u-r-l-this.gap,g=a-2*s.margin,m=document.createElement("canvas");m.width=p,m.height=g;const f=m.getContext("2d");for(let t=0;t<g;t++){let e=C-t/g*(C-L);if(A.autoscale){e=k+(e-L)/(C-L)*(P-k)}const[i,s,r]=A.lookup(e);f.fillStyle=`rgb(${i},${s},${r})`,f.fillRect(0,t,p,1)}t.ctx.drawImage(m,c,n+s.margin)}if(this.xAxisVisible){let e=i.x+u+r/2;this.yAxisVisible&&(e+=h),t.fillText({x:e,y:i.y+i.height,align:"center",baseline:"bottom",font:this.xAxisTitleFont,color:this.xAxisAxisColor,text:this.xAxisAxisTitle})}this.yAxisVisible&&(t.ctx.save(),t.ctx.translate(i.x+h/2,i.y+g/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return 3*this.scale}get colorMap(){return this.properties.getValue("color_map")}get cropBottom(){return this.properties.getValue("crop_bottom")}get cropLeft(){return this.properties.getValue("crop_left")}get cropRight(){return this.properties.getValue("crop_right")}get cropTop(){return this.properties.getValue("crop_top")}get dataHeight(){return this.properties.getValue("data_height")}get dataWidth(){return this.properties.getValue("data_width")}get font(){return this.properties.getValue("font").scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue("graph_area_height")}get graphAreaWidth(){return this.scale*this.properties.getValue("graph_area_width")}get maximum(){return this.properties.getValue("maximum")}get minimum(){return this.properties.getValue("minimum")}get showRamp(){return this.properties.getValue("show_ramp")}get xAxisAxisColor(){return this.properties.getValue("x_axis_axis_color")}get xAxisAxisTitle(){return this.properties.getValue("x_axis_axis_title")}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue("x_axis_major_tick_step_hint")}get xAxisMaximum(){return this.properties.getValue("x_axis_maximum")}get xAxisMinimum(){return this.properties.getValue("x_axis_minimum")}get xAxisScaleFont(){return this.properties.getValue("x_axis_scale_font").scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue("x_axis_show_minor_ticks")}get xAxisTitleFont(){return this.properties.getValue("x_axis_title_font").scale(this.scale)}get xAxisVisible(){return this.properties.getValue("x_axis_visible")}get yAxisAxisColor(){return this.properties.getValue("y_axis_axis_color")}get yAxisAxisTitle(){return this.properties.getValue("y_axis_axis_title")}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue("y_axis_major_tick_step_hint")}get yAxisMaximum(){return this.properties.getValue("y_axis_maximum")}get yAxisMinimum(){return this.properties.getValue("y_axis_minimum")}get yAxisScaleFont(){return this.properties.getValue("y_axis_scale_font").scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue("y_axis_show_minor_ticks")}get yAxisTitleFont(){return this.properties.getValue("y_axis_title_font").scale(this.scale)}get yAxisVisible(){return this.properties.getValue("y_axis_visible")}}class Ve extends jt{constructor(e,i){super(e,i),this.states=[],this.properties.add(new j("bit")),this.properties.add(new j("data_type")),this.properties.add(new z("effect_3d")),this.properties.add(new z("square_led")),this.properties.add(new j("state_count",2)),this.properties.add(new U("off_color")),this.properties.add(new D("off_label")),this.properties.add(new U("on_color")),this.properties.add(new D("on_label")),this.properties.add(new q("font")),this.properties.add(new z("show_boolean_label")),this.properties.add(new U("state_color_fallback")),this.properties.add(new D("state_label_fallback")),this.properties.add(new j("bulb_border",3)),this.properties.add(new U("bulb_border_color",t.DARK_GRAY))}parseNode(t){if(super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){const i=new U(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);const s=new D(`state_label_${e}`);s.value=t.getString(`state_label_${e}`),this.properties.add(s);const r=new $(`state_value_${e}`);r.value=t.getFloat(`state_value_${e}`),this.properties.add(r),this.states.push({label:this.properties.getValue(s.name),color:this.properties.getValue(i.name),value:this.properties.getValue(r.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){var t,e,i;return 0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0:(this.dataType,!1)}get bulbColor(){var t;if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.color;return this.stateColorFallback}get label(){var t;if(2===this.stateCount)return this.booleanValue?this.onLabel:this.offLabel;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.label;return this.stateLabelFallback}draw(t){const e=l(this.bounds,3*this.scale);this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}drawCircle2d(t,e){const i=e.x+e.width/2,s=e.y+e.height/2;let r=e.width/2,o=e.height/2;if(this.bulbBorder>0&&(r-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(i,s,r,o,0,0,2*Math.PI)}}drawCircle3d(e,i){const s=i.x+i.width/2,r=i.y+i.height/2;let o=i.width/2,h=i.height/2;e.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:t.WHITE});let n=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height);n.addColorStop(0,this.bulbBorderColor.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:s,cy:r,rx:o,ry:h,gradient:n});if(o=(i.width-2*this.bulbBorder)/2,h=(i.height-2*this.bulbBorder)/2,e.fillEllipse({cx:s,cy:r,rx:o,ry:h,color:this.bulbColor}),n=e.createLinearGradient(i.x,i.y,i.x+i.width,i.y+i.height),n.addColorStop(0,t.WHITE.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),e.fillEllipse({cx:s,cy:r,rx:o,ry:h,gradient:n}),this.pv&&this.pv.navigable&&!this.pv.disconnected){e.addHitRegion(this.areaRegion).addEllipse(s,r,o,h,0,0,2*Math.PI)}}drawSquare2d(t,e){const i=n(e.x,e.y,e.width,e.height,this.bulbBorder);if(t.fillRect(Object.assign(Object.assign({},i),{color:this.bulbColor})),t.strokeRect(Object.assign(Object.assign({},i),{color:this.bulbBorderColor,lineWidth:this.bulbBorder})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}}drawSquare3d(t,e){if(t.fillRect(Object.assign(Object.assign({},e),{color:this.bulbBorderColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}let i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width,e.y)}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new v(e.x+e.width,e.y).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new v(e.x,e.y+e.height).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)});const s=e.x+this.bulbBorder,r=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,h=e.height-2*this.bulbBorder;t.fillRect({x:s,y:r,width:o,height:h,color:this.bulbColor}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.784)"),i.addColorStop(1,this.bulbColor.withAlpha(0).toString()),t.fillRect({x:s,y:r,width:o,height:h,gradient:i})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue("data_type")}get squareLed(){return this.properties.getValue("square_led")}get showBooleanLabel(){return this.properties.getValue("show_boolean_label")}get font(){return this.properties.getValue("font").scale(this.scale)}get effect3d(){return this.properties.getValue("effect_3d")}get stateCount(){return this.properties.getValue("state_count")}get bulbBorder(){return this.scale*this.properties.getValue("bulb_border")}get bulbBorderColor(){return this.properties.getValue("bulb_border_color")}get offLabel(){return this.properties.getValue("off_label")}get offColor(){return this.properties.getValue("off_color")}get onLabel(){return this.properties.getValue("on_label")}get onColor(){return this.properties.getValue("on_color")}get stateLabelFallback(){return this.properties.getValue("state_label_fallback")}get stateColorFallback(){return this.properties.getValue("state_color_fallback")}}const Ae=g(45),Le=(1-Math.sin(Ae)/2)/(2*Math.cos(Ae));class Ce extends jt{constructor(t,e){super(t,e),this.properties.add(new U("color_hi")),this.properties.add(new U("color_hihi")),this.properties.add(new U("color_lo")),this.properties.add(new U("color_lolo")),this.properties.add(new q("font")),this.properties.add(new j("level_hi")),this.properties.add(new j("level_hihi")),this.properties.add(new j("level_lo")),this.properties.add(new j("level_lolo")),this.properties.add(new z("log_scale")),this.properties.add(new j("maximum")),this.properties.add(new j("minimum")),this.properties.add(new U("needle_color")),this.properties.add(new z("ramp_gradient")),this.properties.add(new q("scale_font")),this.properties.add(new z("show_hi")),this.properties.add(new z("show_hihi")),this.properties.add(new z("show_lo")),this.properties.add(new z("show_lolo")),this.properties.add(new z("show_ramp",!0)),this.properties.add(new D("value_label_format"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){if(t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}}drawRamp(t){const e=String(this.minimum),i=t.measureText(e,this.scaleFont),s=String(this.maximum),r=t.measureText(s,this.scaleFont),o=Math.max(i.width,r.width)/2;let h=this.height,n=this.width;h>Le*(n-2*o)&&(h=Math.floor(Le*(n-2*o)));const a=h/(1-Math.sin(Ae)/2),d={x:Math.floor(this.x-a*(1-Math.cos(Ae))+o),y:this.y,width:Math.floor(2*a),height:Math.floor(2*a)},{rampWidth:c}=this,p=l(d,d.width/4-c,d.height/4-c);p.width=Math.min(p.width,p.height),p.height=p.width;const g=new we(c,135,45);g.lolo=this.levelLoLo,g.loloColor=this.colorLoLo,g.showLoLo=!0,g.lo=this.levelLo,g.loColor=this.colorLo,g.showLo=!0,g.hi=this.levelHi,g.hiColor=this.colorHi,g.showHi=!0,g.hihi=this.levelHiHi,g.hihiColor=this.colorHiHi,g.showHiHi=!0,g.minimum=this.minimum,g.maximum=this.maximum,g.gradient=this.rampGradient,g.logScale=this.logScale,g.draw(t,d,p),this.drawNeedle(t,d,g);const u=W.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&void 0!==this.pv.value){const e=this.format(this.pv.value),i=t.measureText(e,u);t.fillText({x:d.x+d.width/2-i.width/2,y:d.y+d.height/2-d.height/4-(g.getRadius()-d.height/4)/2-i.height/2,align:"left",baseline:"top",font:u,text:e,color:this.foregroundColor})}}drawNeedle(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o;if(this.pv&&void 0!==this.pv.value){const t=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(t),this.maximum>this.minimum?t>this.maximum?o+=8:t<this.minimum&&(o-=8):t>this.minimum?o-=8:t<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);const h=g(o),{needleWidth:n,gapBetweenNeedleScale:l,scale:d}=this,c=a(s+e.width/4,r-n/2+3*d,s,r,h),p=a(s+i.getRadius()-l,r,s,r,h),u=a(s+e.width/4,r+n/2-3*d,s,r,h);t.fillPath({color:this.needleColor,path:new v(c.x,c.y).lineTo(p.x,p.y).lineTo(u.x,u.y).closePath()})}get needleWidth(){return 16*this.scale}get gapBetweenNeedleScale(){return-5*this.scale}get rampWidth(){return 12*this.scale}format(t){return this.valueLabelFormat?new xe(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get font(){return this.properties.getValue("font").scale(this.scale)}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get maximum(){return this.properties.getValue("maximum")}get needleColor(){return this.properties.getValue("needle_color")}get rampGradient(){return this.properties.getValue("ramp_gradient")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showRamp(){return this.properties.getValue("show_ramp")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class ke extends jt{constructor(t,e){super(t,e),this.properties.add(new U("color_hi")),this.properties.add(new U("color_hihi")),this.properties.add(new U("color_lo")),this.properties.add(new U("color_lolo")),this.properties.add(new U("color_fillbackground")),this.properties.add(new z("effect_3d")),this.properties.add(new U("fill_color")),this.properties.add(new z("fillcolor_alarm_sensitive",!1)),this.properties.add(new q("font")),this.properties.add(new z("horizontal")),this.properties.add(new z("indicator_mode")),this.properties.add(new $("level_hi")),this.properties.add(new $("level_hihi")),this.properties.add(new $("level_lo")),this.properties.add(new $("level_lolo")),this.properties.add(new z("limits_from_pv")),this.properties.add(new z("log_scale")),this.properties.add(new $("maximum")),this.properties.add(new $("major_tick_step_hint")),this.properties.add(new $("minimum")),this.properties.add(new $("origin",0)),this.properties.add(new z("origin_ignored",!0)),this.properties.add(new q("scale_font")),this.properties.add(new D("scale_format")),this.properties.add(new z("show_hi")),this.properties.add(new z("show_hihi")),this.properties.add(new z("show_label")),this.properties.add(new z("show_lo")),this.properties.add(new z("show_lolo")),this.properties.add(new z("show_markers")),this.properties.add(new z("show_minor_ticks")),this.properties.add(new z("show_scale")),this.properties.add(new z("transparent_background")),this.properties.add(new D("value_label_format"))}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=l(this.area,2*this.scale));const i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},e),{color:i})),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){const i=this.alarmSensitiveForegroundColor,s=new Te(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawVertical(t,e.x,e.y,e.height,!0);let o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,s,e)),this.drawVerticalBar(t,s,{x:e.x+r,y:e.y+s.margin,width:e.width-r-o,height:e.height-2*s.margin})}drawVerticalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=W.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.width)}const l=i.x+i.width;if(this.showLoLo&&void 0!==s){const i=l-a-this.markerGap,r=Math.round(e.getValuePosition(s));t.strokePath({path:new v(i,r).lineTo(i-this.markerTickLength,r),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:r,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(r));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(o));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(h));t.strokePath({path:new v(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawVerticalBar(e,i,s){var r;const{outlineWidth:o}=this;if(e.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const i=e.createLinearGradient(s.x,0,s.x+s.width,0);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},s),{gradient:i}));const r=l(s,o/2);e.strokeRect(Object.assign(Object.assign({},r),{color:t.GRAY,lineWidth:o}))}const h=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(i.getValuePosition(this.getFillValue())),n=s.width,a=this.thumbBreadth,l=p([{x:0,y:a/2},{x:n/2,y:0},{x:n-1,y:a/2},{x:n/2,y:a}],s.x,r-a/2),d=v.fromPoints(l);if(this.effect3d){const{x:i,y:s}=l[0],{x:r,y:n}=l[2],a=e.createLinearGradient(i,s,r,n);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillPath({path:d,gradient:a}),e.strokePath({path:d,color:t.GRAY,lineWidth:o})}else e.fillPath({path:d,color:h})}else{let r=this.originIgnored?this.min:this.origin,n=this.getFillValue();if(n<r){const t=r;r=n,n=t}const a=Math.round(i.getValuePosition(r)),d=Math.round(i.getValuePosition(n)),c=l(Object.assign(Object.assign({},s),{y:a,height:d-a}),o);if(e.fillRect(Object.assign(Object.assign({},c),{color:h})),this.effect3d){const i=e.createLinearGradient(c.x,0,c.x+c.width,0);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},c),{gradient:i}))}}const n=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==n&&e.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(n)})}drawHorizontal(t,e){const i=this.alarmSensitiveForegroundColor,s=new Te(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawHorizontal(t,e.x,e.y+e.height,e.width);let o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,s,e)),this.drawHorizontalBar(t,s,{x:e.x+s.margin,y:e.y+o,width:e.width-2*s.margin,height:e.height-r-o})}drawHorizontalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=W.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.height)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.height)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.height)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.height)}const l=i.y;if(this.showLoLo&&void 0!==s){const i=Math.round(e.getValuePosition(s)),r=l+a+this.markerGap;t.strokePath({path:new v(i,r).lineTo(i,r+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const i=Math.round(e.getValuePosition(r)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const i=Math.round(e.getValuePosition(o)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const i=Math.round(e.getValuePosition(h)),s=l+a+this.markerGap;t.strokePath({path:new v(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawHorizontalBar(e,i,s){var r;const{outlineWidth:o}=this;if(e.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const i=e.createLinearGradient(0,s.y,0,s.y+s.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},s),{gradient:i}));const r=l(s,o/2);e.strokeRect(Object.assign(Object.assign({},r),{color:t.GRAY,lineWidth:o}))}const h=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(i.getValuePosition(this.getFillValue())),n=s.height,a=this.thumbBreadth,l=p([{x:a/2,y:0},{x:a,y:n/2},{x:a/2,y:n-1},{x:0,y:n/2}],r-a/2,s.y),d=v.fromPoints(l);if(this.effect3d){const{x:i,y:s}=l[0],{x:r,y:n}=l[2],a=e.createLinearGradient(i,s,r,n);a.addColorStop(0,t.WHITE.toString()),a.addColorStop(1,h.toString()),e.fillPath({path:d,gradient:a}),e.strokePath({path:d,color:t.GRAY,lineWidth:o})}else e.fillPath({path:d,color:h})}else{let r=this.originIgnored?this.min:this.origin,n=this.getFillValue();if(n<r){const t=r;r=n,n=t}const a=Math.round(i.getValuePosition(r)),d=Math.round(i.getValuePosition(n)),c=l(Object.assign(Object.assign({},s),{x:a,width:d-a}),o);if(e.fillRect(Object.assign(Object.assign({},c),{color:h})),this.effect3d){const i=e.createLinearGradient(0,c.y,0,c.y+c.height);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,h.withAlpha(0).toString()),e.fillRect(Object.assign(Object.assign({},c),{gradient:i}))}}const n=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==n&&e.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(n)})}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get thumbBreadth(){return 13*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new xe(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get effect3d(){return this.properties.getValue("effect_3d")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get horizontal(){return this.properties.getValue("horizontal")}get indicatorMode(){return this.properties.getValue("indicator_mode")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get origin(){return this.properties.getValue("origin")}get originIgnored(){return this.properties.getValue("origin_ignored")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showLabel(){return this.properties.getValue("show_label")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}const Pe=new t(160,160,160);class Me extends jt{constructor(t,e){super(t,e),this.properties.add(new U("color_hi")),this.properties.add(new U("color_hihi")),this.properties.add(new U("color_lo")),this.properties.add(new U("color_lolo")),this.properties.add(new U("color_fillbackground")),this.properties.add(new z("effect_3d")),this.properties.add(new U("fill_color")),this.properties.add(new z("fillcolor_alarm_sensitive",!1)),this.properties.add(new $("level_hi")),this.properties.add(new $("level_hihi")),this.properties.add(new $("level_lo")),this.properties.add(new $("level_lolo")),this.properties.add(new z("limits_from_pv")),this.properties.add(new z("log_scale")),this.properties.add(new $("maximum")),this.properties.add(new $("major_tick_step_hint")),this.properties.add(new $("minimum")),this.properties.add(new q("scale_font")),this.properties.add(new D("scale_format")),this.properties.add(new z("show_hi")),this.properties.add(new z("show_hihi")),this.properties.add(new z("show_lo")),this.properties.add(new z("show_lolo")),this.properties.add(new z("show_markers")),this.properties.add(new z("show_minor_ticks")),this.properties.add(new z("show_scale")),this.properties.add(new z("transparent_background"))}draw(t){const{scale:e,min:i,max:s}=this;let r=this.area;this.borderAlarmSensitive&&(r=l(r,2*e));const o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},r),{color:o}));const h=this.alarmSensitiveForegroundColor,n=new Te(e,this.scaleFont,i,s,this.logScale,this.majorTickStepHint,h,this.showMinorTicks,this.showScale);n.scaleFormat=this.scaleFormat;const a=n.drawVertical(t,r.x,r.y,r.height,!0);let d=0;this.showMarkers&&(d=this.drawMarkers(t,r,n)),this.drawTank(t,r,a,d,n)}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=W.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",n);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",n);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",n);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==h){const e=t.measureText("HIHI",n);a=Math.max(a,e.width)}const l=e.x+e.width-a-this.markerGap-this.markerTickLength;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const e=Math.round(i.getValuePosition(h));t.strokePath({path:new v(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}return this.markerTickLength+this.markerGap+a}drawTank(e,i,s,r,o){const h=this.alarmSensitiveForegroundColor,{scale:n,outlineWidth:a}=this,d=i.x+s,c=i.y+o.margin,p=i.width-s-r,g=i.height-2*o.margin;let u=this.defaultCorner,m=.55;p<2*u&&(m=.6);const f=Math.floor(p*m);u>2*f-p-2*a&&(u=2*f-p);const x=o.getValuePosition(this.getFillValue()),w=this.alarmSensitiveFillColor;if(this.effect3d){e.fillRect({x:d,y:c,width:p,height:g,rx:u/2,ry:u/2,color:t.WHITE});let i=e.createLinearGradient(d,c,d+f+2*n,c);i.addColorStop(0,this.colorFillbackground.toString()),i.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:d,y:c,width:f,height:g,rx:u/2,ry:u/2,gradient:i}),i=e.createLinearGradient(d+p-f-2*n,c,d+p,c),i.addColorStop(0,t.WHITE.withAlpha(0).toString()),i.addColorStop(1,this.colorFillbackground.toString()),e.fillRect({x:d+p-f,y:c,width:f,height:g,rx:u/2,ry:u/2,gradient:i});const s=x,r=c+g-x;i=e.createLinearGradient(d,s,d+f+2*n,s),i.addColorStop(0,w.toString()),i.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:d,y:s,width:f,height:r,rx:u/2,ry:u/2,gradient:i}),i=e.createLinearGradient(d+p-f-2*n,s,d+p,s),i.addColorStop(0,t.WHITE.withAlpha(0).toString()),i.addColorStop(1,w.toString()),e.fillRect({x:d+p-f,y:s,width:f,height:r,rx:u/2,ry:u/2,gradient:i})}else e.fillRect({x:d,y:c,width:p,height:g,rx:u/2,ry:u/2,color:this.colorFillbackground}),e.fillRect({x:d,y:x,width:p,height:c+g-x,rx:u/2,ry:u/2,color:w});let y=l({x:d,y:c,width:p,height:g},a/2);e.strokeRect(Object.assign(Object.assign({},y),{rx:u/2,ry:u/2,color:this.effect3d?Pe:h,lineWidth:a}))}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get defaultCorner(){return 15*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get effect3d(){return this.properties.getValue("effect_3d")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}}class Re extends jt{constructor(t,e){super(t,e),this.properties.add(new q("font")),this.properties.add(new j("format_type")),this.properties.add(new j("horizontal_alignment")),this.properties.add(new j("precision")),this.properties.add(new z("precision_from_pv")),this.properties.add(new j("vertical_alignment"))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){const e=t.ctx;if(this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}e.fillStyle=this.alarmSensitiveForegroundColor.toString(),e.font=this.font.getFontString();const{scale:i}=this;let s=this.area;this.borderAlarmSensitive&&(s=l(s,2*i,2*i));let r=s.x;0===this.horizAlignment?e.textAlign="start":1===this.horizAlignment?(r+=s.width/2,e.textAlign="center"):2===this.horizAlignment&&(r+=s.width,e.textAlign="end");let o=s.y;0===this.vertAlignment?e.textBaseline="top":1===this.vertAlignment?(o+=s.height/2,e.textBaseline="middle"):2===this.vertAlignment&&(o+=s.height,e.textBaseline="bottom");let h=this.text;if(this.pv&&void 0!==this.pv.value){const t=this.precisionFromPV?this.pv.precision:this.precision;h=this.pv.formatValue(this.formatType,t)}e.fillText(h,r,o)}get font(){return this.properties.getValue("font").scale(this.scale)}get formatType(){return this.properties.getValue("format_type")}get horizAlignment(){return this.properties.getValue("horizontal_alignment")}get precision(){return this.properties.getValue("precision")}get precisionFromPV(){return this.properties.getValue("precision_from_pv")}get vertAlignment(){return this.properties.getValue("vertical_alignment")}}const Ee=new t(160,160,160);class We extends jt{constructor(t,e){super(t,e),this.properties.add(new U("color_hi")),this.properties.add(new U("color_hihi")),this.properties.add(new U("color_lo")),this.properties.add(new U("color_lolo")),this.properties.add(new U("color_fillbackground")),this.properties.add(new U("fill_color")),this.properties.add(new z("fillcolor_alarm_sensitive",!1)),this.properties.add(new z("effect_3d")),this.properties.add(new $("level_hi")),this.properties.add(new $("level_hihi")),this.properties.add(new $("level_lo")),this.properties.add(new $("level_lolo")),this.properties.add(new z("limits_from_pv")),this.properties.add(new q("font")),this.properties.add(new z("log_scale")),this.properties.add(new $("maximum")),this.properties.add(new $("major_tick_step_hint")),this.properties.add(new $("minimum")),this.properties.add(new q("scale_font")),this.properties.add(new D("scale_format")),this.properties.add(new z("show_bulb")),this.properties.add(new z("show_hi")),this.properties.add(new z("show_hihi")),this.properties.add(new z("show_lo")),this.properties.add(new z("show_lolo")),this.properties.add(new z("show_markers")),this.properties.add(new z("show_minor_ticks")),this.properties.add(new z("show_scale")),this.properties.add(new z("transparent_background")),this.properties.add(new j("unit")),this.properties.add(new D("value_label_format"))}draw(e){var i;const{scale:s,min:r,max:o}=this;let h=this.area;this.borderAlarmSensitive&&(h=l(this.area,2*this.scale));const n=this.alarmSensitiveBackgroundColor,a=this.alarmSensitiveForegroundColor,d=this.alarmSensitiveFillColor;this.transparentBackground||e.fillRect(Object.assign(Object.assign({},h),{color:n}));let c=h.height;if(this.showBulb){let t=Math.min(h.width/2,this.bulbMaxDiameter);c=h.height<t?0:h.height-t}let p=Object.assign(Object.assign({},h),{height:c});const g=new Te(s,this.scaleFont,r,o,this.logScale,this.majorTickStepHint,a,this.showMinorTicks,this.showScale);g.scaleFormat=this.scaleFormat;let u=0,m="";if(0===this.unit?m="°C":1===this.unit?m="°F":2===this.unit&&(m="K"),m){const t=W.ARIAL_9.scale(s),i=2*s;u=e.measureText(m,t).height+2*i,e.fillText({x:h.x+h.width/2-this.pipeWidth/2-i,y:h.y+i,baseline:"top",align:"right",color:a,font:t,text:m})}const f=p.x+p.width/2-this.pipeWidth/2-1*s,x=Object.assign(Object.assign({},p),{y:p.y+u,height:p.height-u+g.calculateMargin(e,!1)});g.drawVertical(e,f,x.y,x.height,!1);const w=Math.floor(this.pipeWidth/2);if(p=Object.assign(Object.assign({},p),{y:g.getValuePosition(o)-w,height:g.scaleLength+2*w}),this.drawPipe(e,p,g),this.showMarkers&&this.drawMarkers(e,h,g),this.showBulb){let o=Math.min(h.width/2,this.bulbMaxDiameter);const n=1*s,l=h.x+h.width/2,u=h.y+c+o/2,m=o/2,f=o/2;if(e.fillEllipse({cx:l,cy:u,rx:m,ry:f,color:d}),this.effect3d){const i=e.createLinearGradient(l-m,u-f,l+m,u+f);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,d.withAlpha(0).toString()),e.fillEllipse({cx:l,cy:u,rx:m,ry:f,gradient:i})}e.strokeEllipse({cx:l,cy:u,rx:m-n/2,ry:f-n/2,color:this.effect3d?Ee:a,lineWidth:n});const x={x:Math.round(p.x+p.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(g.getValuePosition(r)),width:this.pipeWidth-2*this.outlineWidth,height:3*s};if(this.effect3d){const i=Math.round(p.x+p.width/2-this.pipeWidth/2),s=i+this.pipeWidth,r=e.createLinearGradient(i,x.y,s,x.y);r.addColorStop(0,t.WHITE.toString()),r.addColorStop(1,d.toString()),e.fillRect(Object.assign(Object.assign({},x),{gradient:r}))}else e.fillRect(Object.assign(Object.assign({},x),{color:d}));const w=null===(i=this.pv)||void 0===i?void 0:i.value;w&&e.fillText({x:l,y:u,align:"center",baseline:"middle",color:d.contrast(),font:this.font,text:this.format(w)})}}drawPipe(e,i,s){const{scale:r,outlineWidth:o,min:h,max:n}=this,a=this.alarmSensitiveForegroundColor,d=this.alarmSensitiveFillColor,c={x:Math.round(i.x+i.width/2-this.pipeWidth/2),y:i.y,width:this.pipeWidth,height:i.height},p=this.getFillValue();let g=s.getValuePosition(p);n>h?p>n?g-=10*r:p<h&&(g+=10*r):p>h?g+=10*r:p<n&&(g-=10*r);const u=this.pipeWidth/2,{x:m,y:f,width:x,height:w}=c;if(this.effect3d){let i=e.createLinearGradient(m,f,m+x,f);i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,this.colorFillbackground.toString()),e.fillRect(Object.assign(Object.assign({},c),{rx:u/2,ry:u/2,gradient:i})),i=e.createLinearGradient(m,f,m+x,f),i.addColorStop(0,t.WHITE.toString()),i.addColorStop(1,d.toString()),e.fillRect({x:m,y:g,width:x,height:f+w-g,rx:u/2,ry:u/2,gradient:i})}else e.fillRect(Object.assign(Object.assign({},c),{rx:u/2,ry:u/2,color:this.colorFillbackground})),e.fillRect({x:m,y:g,width:x,height:f+w-g,rx:u/2,ry:u/2,color:d});let y=l(c,o/2);e.strokeRect(Object.assign(Object.assign({},y),{rx:u/2,ry:u/2,color:this.effect3d?Ee:a,lineWidth:o}))}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:h}=this,n=W.ARIAL_9.scale(this.scale),a=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:n})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:n})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:n})}if(this.showHiHi&&void 0!==h){const e=Math.round(i.getValuePosition(h));t.strokePath({path:new v(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:n})}}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get pipeWidth(){return 15*this.scale}get bulbMaxDiameter(){return 40*this.scale}get outlineWidth(){return 1*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return t.RED;if(this.isMinorSeverity())return t.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new xe(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue("color_lo")}get colorLoLo(){return this.properties.getValue("color_lolo")}get colorHi(){return this.properties.getValue("color_hi")}get colorHiHi(){return this.properties.getValue("color_hihi")}get colorFillbackground(){return this.properties.getValue("color_fillbackground")}get fillColorAlarmSensitive(){return this.properties.getValue("fillcolor_alarm_sensitive")}get fillColor(){return this.properties.getValue("fill_color")}get font(){return this.properties.getValue("font").scale(this.scale)}get effect3d(){return this.properties.getValue("effect_3d")}get levelLo(){return this.properties.getValue("level_lo")}get levelLoLo(){return this.properties.getValue("level_lolo")}get levelHi(){return this.properties.getValue("level_hi")}get levelHiHi(){return this.properties.getValue("level_hihi")}get limitsFromPv(){return this.properties.getValue("limits_from_pv")}get logScale(){return this.properties.getValue("log_scale")}get minimum(){return this.properties.getValue("minimum")}get majorTickStepHint(){return this.scale*this.properties.getValue("major_tick_step_hint")}get maximum(){return this.properties.getValue("maximum")}get scaleFont(){return this.properties.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.properties.getValue("scale_format")}get showBulb(){return this.properties.getValue("show_bulb")}get showMarkers(){return this.properties.getValue("show_markers")}get showMinorTicks(){return this.properties.getValue("show_minor_ticks")}get showLo(){return this.properties.getValue("show_lo")}get showLoLo(){return this.properties.getValue("show_lolo")}get showHi(){return this.properties.getValue("show_hi")}get showHiHi(){return this.properties.getValue("show_hihi")}get showScale(){return this.properties.getValue("show_scale")}get transparentBackground(){return this.properties.getValue("transparent_background")}get unit(){return this.properties.getValue("unit")}get valueLabelFormat(){return this.properties.getValue("value_label_format")}}class Be{constructor(t,e){this.widget=t,this.index=e}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return 0!==this.timeFormat}isHorizontal(){return 0===this.index||1!==this.index&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){var t;return null!==(t=this._effectiveMinimum)&&void 0!==t?t:this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){var t;return null!==(t=this._effectiveMaximum)&&void 0!==t?t:this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){const t=this.widget.calculateAutoscaledRange(this);t&&(this.effectiveMinimum=t.start,this.effectiveMaximum=t.stop,this.widget.requestRepaint())}applyZoom(t,e){let i,s,r=this.effectiveMinimum,o=this.effectiveMaximum;if(this.logScale){o=Math.log10(o),r=Math.log10(r);const h=Math.log10(t)*e,n=1-e;i=h+r*n,s=h+o*n,i<-323.3062&&(i=-323.3062),i=Math.pow(10,i),s>308.2547&&(s=308.2547),s=Math.pow(10,s)}else{const h=Math.max(Math.abs(r),Math.abs(o));r/=h,o/=h;const n=t/h*e,a=1-e;i=(n+r*a)*h,s=(n+o*a)*h}this.effectiveMinimum=i,this.effectiveMaximum=s,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}}class Ie{constructor(t,e){this.xAxis=t,this.yAxis=e,this.beforeXRanges=[],this.beforeYRanges=[],this.afterXRanges=[],this.afterYRanges=[];for(const e of t)this.beforeXRanges.push({min:e.effectiveMinimum,max:e.effectiveMaximum});for(const t of e)this.beforeYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}saveState(){for(const t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(const t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.beforeXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.beforeYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}redo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.afterXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}}class Oe{constructor(){this.undoStack=[],this.redoStack=[]}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){const t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){const t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}}class He{constructor(t,e){this.widget=e,this.id=t}tooltip(){return this.widget.tooltip}mouseDown(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new Ie(i.getXAxes(),i.getYAxes())}}grab(t){var e;switch(null===(e=this.widget.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection=Object.assign(Object.assign({},this.grabStart.point),{width:t.dx,height:t.dy}),this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint()}}grabEnd(){var t;const{grabZoomCommand:e,selection:i,widget:s}=this;switch(null===(t=s.toolbar)||void 0===t?void 0:t.currentTool){case"rubberband-zoom":if(i){const t=new Ie(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"horizontal-zoom":if(i){const t=new Ie(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"vertical-zoom":if(i){const t=new Ie(s.getXAxes(),s.getYAxes());this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"panning":e&&(e.saveState(),s.toolbar.addCommand(e))}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"zoom-in":const e=new Ie(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,.1)}e.saveState(),i.toolbar.addCommand(e);break;case"zoom-out":const s=new Ie(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,-.1)}s.saveState(),i.toolbar.addCommand(s)}}rangeZoomXAxes(t){for(const e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),s=e.linearScale.getPositionValue(t.x+t.width);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}rangeZoomYAxes(t){for(const e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),s=e.linearScale.getPositionValue(t.y+t.height);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}pan(t){const{prevGrabEvent:e,widget:i}=this;if(e){const s=e.dx-t.dx;if(0!==s)for(const t of i.getXAxes()){const e=t.linearScale,i=e.getMinMax(),r=e.getValuePosition(i.start)+s,o=e.getValuePosition(i.stop)+s;t.effectiveMinimum=e.getPositionValue(r),t.effectiveMaximum=e.getPositionValue(o)}const r=e.dy-t.dy;if(0!==r)for(const t of i.getYAxes()){const e=t.linearScale,i=e.getMinMax(),s=e.getValuePosition(i.start)+r,o=e.getValuePosition(i.stop)+r;t.effectiveMinimum=e.getPositionValue(s),t.effectiveMaximum=e.getPositionValue(o)}}}}class Fe{constructor(t){this.pointer=0,this.samples=[],this.samples=Array(t).fill(void 0)}push(t,e){this.samples[this.pointer]={x:t,y:e},this.pointer=(this.pointer+1)%this.samples.length}clear(){this.samples.fill(void 0),this.pointer=0}isFull(){const t=(this.pointer+1)%this.samples.length;return void 0!==this.samples[t]}isEmpty(){return void 0===this.tail()}tail(){return 0===this.pointer?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t){return this.samples.filter((t=>void 0!==t)).sort(((t,e)=>t.x-e.x))}{const t=this.samples.slice(this.pointer).filter((t=>void 0!==t)),e=this.samples.slice(0,this.pointer).filter((t=>void 0!==t));return t.concat(e)}}}class Ne{constructor(t,e,i,s,r){this.bufferSize=t,this.plotMode=e,this.updateMode=i,this.concatenateData=s,this.chronological=r,this.x=0,this.xPending=!1,this.y=0,this.yTimestamp=0,this.yPending=!1,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1,this.traceData=new Fe(t)}clear(){this.traceData.clear(),this.x=0,this.xPending=!1,this.y=0,this.yPending=!1,this.yTimestamp=0,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1}snapshot(){return this.traceData.snapshot()}updateX(t){this.x=t,this.xPending=!0,this.maybeAddPoint()}updateY(t,e){this.y=t,this.yTimestamp=e,this.yPending=!0,this.maybeAddPoint()}updateXArray(t){this.xArray=t,this.xArrayPending=!0,this.maybeAddArray()}updateYArray(t){this.yArray=t,this.yArrayPending=!0,this.maybeAddArray()}maybeAddPoint(){if(1===this.plotMode&&this.traceData.isFull())return;const{xPending:t,yPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addPoint():1===s?(i&&e||!i&&t&&e)&&this.addPoint():2===s?(i&&e||!i&&t)&&this.addPoint():3===s&&this.yPending&&this.addPoint()}maybeAddArray(){if(1===this.plotMode&&this.traceData.isFull())return;const{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addArray():1===s?(i&&e||!i&&t&&e)&&this.addArray():2===s?(i&&e||!i&&t)&&this.addArray():3===s&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(5===this.updateMode)t=(new Date).getTime();else if(void 0!==this.yTimestamp)t=this.yTimestamp;else{const e=this.traceData.tail();t=e?e.x+1:0}this.traceData.push(t,this.y),this.xPending=!1,this.yPending=!1}addArray(){this.concatenateData||this.traceData.clear();let{xArray:t,yArray:e}=this;if(this.chronological)if(t=Array(e.length),this.traceData.isEmpty())for(let i=0;i<e.length;i++)t[i]=i;else{const i=this.traceData.tail();for(let s=1;s<e.length;s++)t[s-1]=i.x+s}let i=Math.min(t.length,e.length),s=Math.min(i,this.bufferSize);for(let i=0;i<s;i++)this.traceData.push(t[i],e[i]);this.xArrayPending=!1,this.yArrayPending=!1}}class De{constructor(t,e){this.widget=t,this.i=e,this.xPVListener=()=>{var t,e;const i=this.xPVInstance;if(i)if(Array.isArray(i.value))null===(t=this.traceData)||void 0===t||t.updateXArray(i.value);else{const t=i.toNumber();null!=t&&(null===(e=this.traceData)||void 0===e||e.updateX(t))}},this.yPVListener=()=>{var t,e,i;const s=this.yPVInstance;if(s)if(Array.isArray(s.value))null===(t=this.traceData)||void 0===t||t.updateYArray(s.value);else{const t=this.widget.getAxis(this.xAxisIndex),r=s.toNumber();if(null!=r)if(t.isDateEnabled()){const t=(s.time||new Date).getTime();null===(e=this.traceData)||void 0===e||e.updateY(r,t)}else null===(i=this.traceData)||void 0===i||i.updateY(r)}}}init(){const{bufferSize:t,plotMode:e,updateMode:i,concatenateData:s}=this,r=!this.xPV;this.traceData=new Ne(t,e,i,s,r),this.xPV&&(this.xPVInstance=this.widget.display.pvEngine.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=this.widget.display.pvEngine.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),this.widget.addPropertyListener(`trace_${this.i}_x_pv`,(()=>{var t;const e=this.widget.display.pvEngine.createPV(this.xPV);e!==this.xPVInstance&&(null===(t=this.xPVInstance)||void 0===t||t.removeListener(this.xPVListener),this.xPVInstance=e,this.xPVInstance.addListener(this.xPVListener))})),this.widget.addPropertyListener(`trace_${this.i}_y_pv`,(()=>{var t;const e=this.widget.display.pvEngine.createPV(this.yPV);e!==this.yPVInstance&&(null===(t=this.yPVInstance)||void 0===t||t.removeListener(this.yPVListener),this.yPVInstance=e,this.yPVInstance.addListener(this.yPVListener))}))}snapshot(){var t;return(null===(t=this.traceData)||void 0===t?void 0:t.snapshot())||[]}drawTrace(t,e){const{lineWidth:i}=this;if(0===this.traceType)t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i});else if(1===this.traceType)t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(2===this.traceType);else if(3===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(const r of e)t.strokePath({path:new v(r.x,r.y).lineTo(r.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(4===this.traceType||5===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];t.fillPath({path:new v(r.x,r.y).lineTo(r.x,s).lineTo(o.x,s).lineTo(o.x,o.y),color:this.traceColor,opacity:100/255})}5===this.traceType&&t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(6===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];t.strokePath({path:new v(r.x,r.y).lineTo(r.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(7===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];t.strokePath({path:new v(r.x,r.y).lineTo(o.x,r.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(8===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s]})}else if(9===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s,2*s,2*s]})}else if(10===this.traceType){const{scale:s}=this;t.strokePath({path:v.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*s,2*s]})}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;const i=this.pointSize/2,s=e.x,r=e.y;switch(this.pointStyle){case 1:case 3:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 4:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(s-i,r-i,2*i,2*i);break;case 7:t.ctx.fillRect(s-i,r-i,2*i,2*i);break;case 8:case 9:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r),t.ctx.lineTo(s,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(s-i,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.moveTo(s+i,r-i),t.ctx.lineTo(s-i,r+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s+i,r),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke()}}clearData(){var t;null===(t=this.traceData)||void 0===t||t.clear()}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`trace_${this.i}_${t}`)}get antiAlias(){return this.getValue("anti_alias")}get bufferSize(){return this.getValue("buffer_size")}get concatenateData(){return this.getValue("concatenate_data")}get lineWidth(){return this.scale*this.getValue("line_width")}get name(){return this.getValue("name")}get plotMode(){return this.getValue("plot_mode")}get pointSize(){return this.scale*this.getValue("point_size")}get pointStyle(){return this.getValue("point_style")}get traceColor(){return this.getValue("trace_color")}get traceType(){return this.getValue("trace_type")}get updateDelay(){return this.getValue("update_delay")}get updateMode(){return this.getValue("update_mode")}get visible(){return this.getValue("visible")}get xAxisIndex(){return this.getValue("x_axis_index")}get xPV(){return this.getValue("x_pv")}get yAxisIndex(){return this.getValue("y_axis_index")}get yPV(){return this.getValue("y_pv")}}const Ge=new t(236,236,236),je=new t(130,130,130);class $e{constructor(t,e,i,s,r){this.imageFile=e,this.disabledImageFile=i,this.action=r,this.imageElement=new Image,this.disabledImageElement=new Image,this.toggleButton=!1,this.toolButton=!1,this.pushed=!1,this.disabled=!1,this.loadPromise=new Promise(((t,e)=>{this.imageElement.onload=()=>t()})),this.disabledLoadPromise=new Promise(((t,e)=>{this.disabledImageElement.onload=()=>t()})),this.region={id:`${t.xyGraph.wuid}-${e}`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,t.xyGraph.requestRepaint())},mouseOut:()=>{this.toggleButton||(this.pushed=!1),t.xyGraph.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,t.xyGraph.requestRepaint())},click:()=>{this.toggleButton&&(this.pushed=!this.pushed,this.toolButton&&t.toggleTool(this)),this.action(),t.updateState()},tooltip:()=>s}}loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}}class ze{constructor(t){this.xyGraph=t,this.buttons=[],this.imagesLoaded=!1,this.currentTool="default",this.commandBuffer=new Oe,this.showLegend=this.createToggleButton("ShowLegend.png","Show Legend",(()=>{t.properties.setValue("show_legend",this.showLegend.pushed)})),this.showLegend.pushed=t.showLegend,t.addPropertyListener("show_legend",(t=>{this.showLegend.pushed=t})),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",(()=>{const e=new Ie(t.getXAxes(),t.getYAxes());t.performAutoScale(),e.saveState(),this.addCommand(e)})),this.rubberbandZoom=this.createToolButton("RubberbandZoom.png","Rubberband Zoom",(()=>{this.rubberbandZoom.pushed?(this.currentTool="rubberband-zoom",t.setCursor("crosshair"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.horizontalZoom=this.createToolButton("HorizontalZoom.png","Horizontal Zoom",(()=>{this.horizontalZoom.pushed?(this.currentTool="horizontal-zoom",t.setCursor("col-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.verticalZoom=this.createToolButton("VerticalZoom.png","Vertical Zoom",(()=>{this.verticalZoom.pushed?(this.currentTool="vertical-zoom",t.setCursor("row-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomIn=this.createToolButton("ZoomIn.png","Zoom In",(()=>{this.zoomIn.pushed?(this.currentTool="zoom-in",t.setCursor("zoom-in"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomOut=this.createToolButton("ZoomOut.png","Zoom Out",(()=>{this.zoomOut.pushed?(this.currentTool="zoom-out",t.setCursor("zoom-out"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.panning=this.createToolButton("Panning.png","Panning",(()=>{this.panning.pushed?(this.currentTool="panning",t.setCursor("grab"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.mouseArrow=this.createToolButton("MouseArrow.png","None",(()=>{this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0})),this.undo=this.createButton("Undo.png","Undo_Gray.png","Undo",(()=>{this.commandBuffer.undo()})),this.undo.disabled=!0,this.redo=this.createButton("Redo.png","Redo_Gray.png","Redo",(()=>{this.commandBuffer.redo()})),this.redo.disabled=!0,this.camera=this.createButton("camera.png","camera.png","Save Snapshot to PNG File",(()=>{const e=document.createElement("a");try{e.href=t.toDataURL(),e.download=`${t.name}_export.png`,document.body.appendChild(e),e.click()}finally{document.body.removeChild(e)}})),this.toggleTool(this.mouseArrow);const e=this.buttons.map((t=>t.loadPromise)).concat(this.buttons.map((t=>t.disabledLoadPromise)));Promise.all(e).finally((()=>{this.imagesLoaded=!0,t.requestRepaint()}));for(const e of this.buttons)e.loadImage(t.display.imagesPrefix)}updateState(){this.undo.disabled=!this.commandBuffer.canUndo(),this.redo.disabled=!this.commandBuffer.canRedo(),this.xyGraph.requestRepaint()}addCommand(t){this.commandBuffer.add(t),this.updateState()}toggleTool(t){const e=t.pushed;for(const t of this.buttons)t.toolButton&&(t.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){const s=this.createToggleButton(t,e,i);return s.toolButton=!0,s}createToggleButton(t,e,i){const s=this.createButton(t,t,e,i);return s.toggleButton=!0,s}createButton(t,e,i,s){const r=new $e(this,t,e,i,s);return this.buttons.push(r),r}draw(t,e){const{buttonSize:i}=this,s={x:e.x,y:e.y};return this.drawButton(t,s.x,s.y,this.showLegend),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.autoScale),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.rubberbandZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.horizontalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.verticalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomIn),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomOut),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.panning),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.mouseArrow),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.undo),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.redo),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.camera),s.x+=i,s.y+i-e.y}maybeWrap(t,e,i){i=null!=i?i:this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){const{buttonSize:s}=this,r=1*this.scale,o=Math.round(e+s/4)-r/2;t.strokePath({path:new v(o,i).lineTo(o,i+s),color:je,lineWidth:r})}drawButton(e,i,s,r){const{buttonSize:o,scale:h}=this;e.fillRect({x:i,y:s,width:o,height:o,color:Ge}),this.xyGraph.enabled&&!r.disabled&&e.addHitRegion(r.region).addRect(i,s,o,o);const n=1*h,a=Math.round(s+n/2)-.5,l=Math.round(i+n/2)-.5,d=Math.round(s+o-n+n/2)-.5,c=Math.round(i+o-n+n/2)-.5;if(e.strokePath({color:r.pushed?t.WHITE:t.BLACK,path:new v(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d),lineWidth:n}),e.strokePath({color:r.pushed?t.BLACK:t.WHITE,path:new v(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,d-n),lineWidth:n}),this.imagesLoaded){const t=r.disabled?r.disabledImageElement:r.imageElement,n=t.naturalHeight*h,a=t.naturalWidth*h,l=Math.round(i+(o-a)/2),d=Math.round(s+(o-n)/2);e.ctx.drawImage(t,l,d,a,n)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}}class Ue extends jt{constructor(t,e){super(t,e),this.axes=[],this.traces=[],this.autoScaleAllowed=!0,this.properties.add(new j("axis_count")),this.properties.add(new U("plot_area_background_color")),this.properties.add(new z("show_legend")),this.properties.add(new z("show_plot_area_border")),this.properties.add(new z("show_toolbar")),this.properties.add(new D("title")),this.properties.add(new q("title_font")),this.properties.add(new j("trace_count")),this.properties.add(new z("transparent")),this.properties.addGenerator((()=>{const t=[];this.axes=[];const e=this.properties.getValue("axis_count");for(let i=0;i<e;i++)this.axes.push(new Be(this,i)),t.push(new z(`axis_${i}_auto_scale`),new $(`axis_${i}_auto_scale_treshold`),new U(`axis_${i}_axis_color`),new D(`axis_${i}_axis_title`),new z(`axis_${i}_dash_grid_line`),new U(`axis_${i}_grid_color`),new z(`axis_${i}_log_scale`),new $(`axis_${i}_maximum`),new $(`axis_${i}_minimum`),new q(`axis_${i}_scale_font`),new D(`axis_${i}_scale_format`),new z(`axis_${i}_show_grid`),new j(`axis_${i}_time_format`),new q(`axis_${i}_title_font`),new z(`axis_${i}_visible`)),i>1&&t.push(new z(`axis_${i}_left_bottom_side`),new z(`axis_${i}_y_axis`));this.traces=[];const i=this.properties.getValue("trace_count");for(let e=0;e<i;e++)this.traces.push(new De(this,e)),t.push(new z(`trace_${e}_anti_alias`),new j(`trace_${e}_buffer_size`),new z(`trace_${e}_concatenate_data`),new j(`trace_${e}_line_width`),new D(`trace_${e}_name`),new j(`trace_${e}_plot_mode`),new j(`trace_${e}_point_size`),new j(`trace_${e}_point_style`),new U(`trace_${e}_trace_color`),new j(`trace_${e}_trace_type`),new j(`trace_${e}_update_delay`),new j(`trace_${e}_update_mode`),new z(`trace_${e}_visible`),new j(`trace_${e}_x_axis_index`),new D(`trace_${e}_x_pv`),new G(`trace_${e}_x_pv_value`,`trace_${e}_x_pv`),new j(`trace_${e}_y_axis_index`),new D(`trace_${e}_y_pv`),new G(`trace_${e}_y_pv_value`,`trace_${e}_y_pv`));return t}))}init(){this.plotAreaRegion=new He(`${this.wuid}-plotarea`,this),this.traces.forEach((t=>t.init()))}draw(t){var e;const{scale:i}=this;let s=this.area;if(this.borderAlarmSensitive&&(s=l(this.area,2*i)),!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},s),{color:e}))}this.showToolbar&&this.drawToolbar(t,s),this.title&&this.drawTitle(t,s);for(const t of this.axes){if(t.autoScale&&this.autoScaleAllowed){const e=this.calculateAutoscaledRange(t);e&&(t.effectiveMinimum=e.start,t.effectiveMaximum=e.stop)}const e=t.effectiveMinimum,s=t.effectiveMaximum;t.linearScale=new Te(i,t.scaleFont,e,s,t.logScale,50*i,t.axisColor,!0,t.visible),t.linearScale.scaleFormat=t.scaleFormat,t.linearScale.timeFormat=t.timeFormat}this.showLegend&&this.drawLegend(t,s),t.addHitRegion(this.plotAreaRegion).addRect(s.x,s.y,s.width,s.height);const r=this.drawAxes(t,s);this.drawPlotArea(t,r);const o=null===(e=this.plotAreaRegion)||void 0===e?void 0:e.selection;o&&this.drawZoomSelection(t,r,function(t,e){let i=t.x,s=t.y,r=i+t.width,o=s+t.height;if(r<i){const t=i;i=r,r=t}if(o<s){const t=s;s=o,o=t}let h=e.x,n=e.y,a=h+e.width,l=n+e.height;if(a<h){const t=h;h=a,a=t}if(l<n){const t=n;n=l,l=t}const d=Math.max(i,h),c=Math.max(s,n);return{x:d,y:c,width:Math.min(r,a)-d,height:Math.min(o,l)-c}}(r,o))}drawToolbar(t,e){this.toolbar||(this.toolbar=new ze(this));const i=3*this.scale,s=l(e,i),r=this.toolbar.draw(t,s);e.y+=i+r+i,e.height-=i+r+i}drawTitle(t,e){const i=t.measureText(this.title,this.titleFont).height;t.fillText({x:e.x+e.width/2,y:e.y+i/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.titleFont,text:this.title});const s=2*this.scale;e.y+=i+s,e.height-=i+s}drawAxes(t,e){const{scale:i}=this,s=5*i,r=Object.assign({},e);let o=0;for(const e of this.getXAxes())if(e.visible){let i=0;e.axisTitle&&(i=s+t.measureText(e.axisTitle,e.titleFont).height),o+=i+e.linearScale.measureHorizontalHeight(t)}let h=0,n=0;for(const a of this.getYAxes().reverse()){const l=a.linearScale;if(a.visible){const d=l.calculateMargin(t,!1),c=r.height-o+(o>0?d:0);let p=0;a.axisTitle&&(p=t.measureText(a.axisTitle,a.titleFont).height,t.ctx.save(),t.ctx.translate(r.x+s+p/2,e.y+c/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:a.titleFont,color:a.axisColor,text:a.axisTitle}),t.ctx.restore(),p+=s);const g=p+l.drawVertical(t,r.x+p,e.y,c,!0,!1);r.x+=g,r.width-=g,h+=g;const u=l.margin;n=0===n?u:Math.min(n,u);const m=1*i,f=Math.round(r.x)-m/2,x=Math.round(e.y+d)-m/2;t.strokePath({path:new v(f,x).lineTo(f,x+c-2*d),color:a.axisColor,opacity:100/255,lineWidth:m})}else{const t=r.height-o;l.setDimensions(0,e.y,t,!1)}}let a=0;for(const o of this.getXAxes().reverse()){const n=o.linearScale;if(o.visible){const l=n.calculateMargin(t,!0),d=h-l;let c=0;if(o.axisTitle){c=t.measureText(o.axisTitle,o.titleFont).height;const i=e.x+h+(e.width-h)/2;t.fillText({x:i,y:r.y+r.height-c/2,align:"center",baseline:"middle",font:o.titleFont,color:o.axisColor,text:o.axisTitle}),c+=s}const p=c+n.drawHorizontal(t,e.x+d,r.y+r.height-c,e.width-d);r.height-=p;const g=n.margin;a=0===a?g:Math.min(a,g);const u=1*i,m=Math.round(e.x+d+l)-u/2,f=Math.round(r.y+r.height)-u/2;t.strokePath({path:new v(m,f).lineTo(m+r.width-l,f),color:o.axisColor,opacity:100/255,lineWidth:u})}else{const t=e.x+h,i=e.width-h;n.setDimensions(t,0,i,!0)}}return r.y+=n,r.width-=a,r.height-=o>0?n:2*n,r}drawPlotArea(e,i){const{scale:s}=this,r=1*s;if(e.fillRect(Object.assign(Object.assign({},i),{color:this.plotAreaBackgroundColor})),this.showPlotAreaBorder){const{x:s,y:o,width:h,height:n}=l(i,r/2);e.strokePath({path:new v(s,o).lineTo(s+h,o).lineTo(s+h,o+n),color:t.BLACK,lineWidth:r})}for(const t of this.axes.filter((t=>t.visible&&t.showGrid))){const o=t.linearScale;if(t.isHorizontal())for(const h of o.getGridPositions()){const n=Math.round(o.getX()+h)-r/2;e.strokePath({path:new v(n,i.y).lineTo(n,i.y+i.height),color:t.gridColor,lineWidth:r,dash:t.dashGridLine?[6*s,2*s]:void 0})}else for(const h of o.getGridPositions()){const n=Math.round(o.getY()+h)-r/2;e.strokePath({path:new v(i.x,n).lineTo(i.x+i.width,n),color:t.gridColor,lineWidth:r,dash:t.dashGridLine?[6*s,2*s]:void 0})}}e.ctx.save(),e.ctx.beginPath(),e.ctx.rect(i.x,i.y,i.width,i.height),e.ctx.clip();for(const t of this.traces.filter((t=>t.visible))){const i=this.getAxis(t.xAxisIndex).linearScale,s=this.getAxis(t.yAxisIndex).linearScale,r=[];for(const e of t.snapshot()){const t=i.getValuePosition(e.x),o=s.getValuePosition(e.y);r.push({x:t,y:o})}if(r.length){t.drawTrace(e,r);for(const i of r)t.drawPoint(e,i)}}e.ctx.restore()}drawZoomSelection(e,i,s){var r;const{scale:o}=this;switch(null===(r=this.toolbar)||void 0===r?void 0:r.currentTool){case"rubberband-zoom":e.strokeRect(Object.assign(Object.assign({},s),{color:t.BLACK,lineWidth:1*o}));break;case"horizontal-zoom":const r=s;r.y=i.y,r.height=i.height,e.strokeRect(Object.assign(Object.assign({},d(r)),{color:t.BLACK,lineWidth:1*o}));break;case"vertical-zoom":const h=s;h.x=i.x,h.width=i.width,e.strokeRect(Object.assign(Object.assign({},d(h)),{color:t.BLACK,lineWidth:1*o}))}}drawLegend(t,e){const{scale:i}=this,s=25*i,r=2*i,o=5*i,h=W.ARIAL_10.scale(i);for(const n of this.getYAxes()){const a=this.traces.filter((t=>t.visible&&t.yAxisIndex===n.index)),d=[];let c=[],p=0,g=0;for(const i of a){let n=s+r+o;i.name&&(n+=t.measureText(i.name,h).width),p+n<e.width?(c.push(i),p+=n):(d.push(c),n=Math.max(n,p),c=[i],p=n)}if(c.length&&(d.push(c),g=Math.max(g,p)),!d.length)continue;const u=s*d.length,m={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-u),width:g,height:u};e.height-=m.height,t.fillRect(Object.assign(Object.assign({},m),{color:this.plotAreaBackgroundColor})),t.strokeRect(Object.assign(Object.assign({},l(m,1*i/2)),{color:n.axisColor}));let f=m.x,x=m.y;for(let e=0;e<d.length;e++){const n=d[e],a=x+e*s,l=a+s/2;for(const e of n){const n=e.pointSize>Math.floor((s-o)/2)?Math.floor(s-o):e.pointSize;switch(e.traceType){case 3:const r=f+s/2;t.strokePath({path:new v(r,a+n).lineTo(r,a+s),lineWidth:e.lineWidth,color:e.traceColor,opacity:100/255}),e.drawPoint(t,{x:r,y:a+n});break;case 4:case 5:const o=[{x:f,y:a+s/2},{x:f+s/2,y:a+n},{x:f+s,y:a+s/2},{x:f+s,y:a+s},{x:f,y:a+s}];t.fillPath({path:v.fromPoints(o),color:e.traceColor,opacity:100/255}),5===e.traceType&&t.strokePath({path:v.fromPoints(o.slice(0,3)),color:e.traceColor,lineWidth:1*i}),e.drawPoint(t,{x:f+s/2,y:a+n});break;default:e.drawTrace(t,[{x:f,y:l},{x:f+s,y:l}]),e.drawPoint(t,{x:f+s/2,y:l})}f+=s+r,e.name&&(t.fillText({x:f,y:l,align:"left",baseline:"middle",color:e.traceColor,font:h,text:e.name}),f+=t.measureText(e.name,h).width),f+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t){let e,i;const s=t.logScale;for(const r of this.traces)if(r.visible&&(this.axes[r.xAxisIndex]===t||this.axes[r.yAxisIndex]===t))for(const o of r.snapshot()){const r=t.isHorizontal()?o.x:o.y;(void 0===e||e>r)&&(!s||r>0)&&(e=r),(void 0===i||i<r)&&(!s||r>0)&&(i=r)}if(void 0!==e&&void 0!==i)return{start:e,stop:i}}performAutoScale(){for(const t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(const t of this.traces)t.clearData();this.requestRepaint()}getAxes(){return[...this.axes]}getXAxes(){return this.axes.filter((t=>t.isHorizontal()))}getYAxes(){return this.axes.filter((t=>t.isVertical()))}getAxis(t){return this.axes[t]}getTrace(t){return this.traces[t]}get axisCount(){return this.properties.getValue("axis_count")}get plotAreaBackgroundColor(){return this.properties.getValue("plot_area_background_color")}get showLegend(){return this.properties.getValue("show_legend")}get showPlotAreaBorder(){return this.properties.getValue("show_plot_area_border")}get showToolbar(){return this.properties.getValue("show_toolbar")}get title(){return this.properties.getValue("title")}get titleFont(){return this.properties.getValue("title_font").scale(this.scale)}get traceCount(){return this.properties.getValue("trace_count")}get transparent(){return this.properties.getValue("transparent")}}class qe extends jt{constructor(t,e){super(t,e),this._widgets=[],this._connections=[],this.relativeScale=1,this.properties.add(new Z("macros"))}expandContainerMacros(t){for(const e in this.macros.macros)t=(t=t.replace(`$(${e})`,this.macros.macros[e])).replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(const e of this.widgets){if(e.wuid===t)return e;if(e instanceof qe){const i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(const e of this.widgets){if(e.name===t)return e;if(e instanceof qe){const i=e.findWidgetByName(t);if(i)return i}}for(const e of this.connections)if(e.name===t)return e}closeMenu(){for(const t of this.widgets)t.closeMenu()}hide(){for(const t of this.widgets)t.hide()}destroy(){for(const t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue("macros")}}class Ye extends jt{constructor(t){super(t),this.properties.clear(),this.properties.add(new j("arrow_length")),this.properties.add(new j("arrows")),this.properties.add(new z("fill_arrow")),this.properties.add(new D("name")),this.properties.add(new U("line_color")),this.properties.add(new j("line_style")),this.properties.add(new j("line_width")),this.properties.add(new D("src_wuid")),this.properties.add(new D("src_term")),this.properties.add(new D("tgt_wuid")),this.properties.add(new D("tgt_term")),this.properties.add(new j("router")),this.properties.add(new X("points")),this.properties.add(new D("wuid"))}parseNode(t){this.properties.loadXMLValues(t),this.sourceWidget=this.display.findWidget(this.sourceWuid),this.sourceWidget||console.warn(`Can't find source widget ${this.sourceWuid}`),this.targetWidget=this.display.findWidget(this.targetWuid),this.targetWidget||console.warn(`Can't find target widget ${this.targetWuid}`)}draw(t){this.sourceWidget&&this.targetWidget&&(this.points.length?this.drawPath(t):0===this.router?this.drawManhattanConnection(t):1===this.router&&this.drawDirectConnection(t))}drawPath(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),s=[e,...this.points,i],r=v.fromPoints(s).translate(.5*this.scale,.5*this.scale);t.strokePath({path:r,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,s[1],s[0]),this.drawStopArrow(t,s[s.length-2],s[s.length-1])}drawManhattanConnection(t){const e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),s=this.route(e,i),r=v.fromPoints(s);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:r,dash:this.getDashArray()}),this.drawStartArrow(t,s[s.length-2],s[s.length-1]),this.drawStopArrow(t,s[1],s[0])}getDashArray(){const{scale:t}=this;if(this.lineWidth){if(0===this.lineStyle)return[];if(1===this.lineStyle)return[6*t,2*t];if(2===this.lineStyle)return[2*t,2*t];if(3===this.lineStyle)return[6*t,2*t,2*t,2*t];if(4===this.lineStyle)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}drawDirectConnection(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new v(e.x,e.y).lineTo(i.x,i.y),lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,i,e),this.drawStopArrow(t,e,i)}getManhattanAnchor(t,e){let i;switch(e){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":i="UP";break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i="DOWN";break;case"LEFT":i="LEFT";break;case"RIGHT":i="RIGHT"}const s=t.bounds,r=this.getPosition(t,e),o=r.x-s.x,h=s.x+s.width-r.x,n=r.y-s.y,a=s.y+s.height-r.y;return i=Math.min(o,h)<Math.min(n,a)?o<h?"LEFT":"RIGHT":n<a?"UP":"DOWN",{x:r.x,y:r.y,direction:i}}getPosition(t,e){switch(e){case"LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight/2};case"TOP":return{x:t.holderX+t.holderWidth/2,y:t.holderY};case"RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight/2};case"BOTTOM":return{x:t.holderX+t.holderWidth/2,y:t.holderY+t.holderHeight};case"TOP_LEFT":return{x:t.holderX,y:t.holderY};case"TOP_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY};case"BOTTOM_LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight};case"BOTTOM_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight};default:const i=parseInt(e,10);let s=t.properties.getProperty("points");if(s){let t=s.value;return t=x(t,this.scale),t[i]}throw Error(`Unexpected term ${e}`)}}route(t,e){let i,s,r=t.x-e.x,o=t.y-e.y,h={x:0,y:0},n=[];const{tolxtol:a,tol:l,minDist:d}=this;if(r*r<a&&o*o<a)return[{x:e.x,y:e.y}];"LEFT"===t.direction?r>0&&o*o<l&&"RIGHT"===e.direction?(h=e,i=e.direction):(r<0?h={x:t.x-d,y:t.y}:o>0&&"DOWN"===e.direction||o<0&&"UP"===e.direction?h={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.min(t.x,e.x)-d,h={x:s,y:t.y}):h={x:t.x-r/2,y:t.y},i=o>0?"UP":"DOWN"):"RIGHT"===t.direction?r<0&&o*o<l&&"LEFT"===e.direction?(h=e,i=e.direction):(r>0?h={x:t.x+d,y:t.y}:o>0&&"DOWN"===e.direction||o<0&&"UP"===e.direction?h={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.max(t.x,e.x)+d,h={x:s,y:t.y}):h={x:t.x-r/2,y:t.y},i=o>0?"UP":"DOWN"):"DOWN"===t.direction?r*r<l&&o<0&&"UP"===e.direction?(h=e,i=e.direction):(o>0?h={x:t.x,y:t.y+d}:r>0&&"RIGHT"===e.direction||r<0&&"LEFT"===e.direction?h={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.max(t.y,e.y)+d,h={x:t.x,y:s}):h={x:t.x,y:t.y-o/2},i=r>0?"LEFT":"RIGHT"):"UP"===t.direction&&(r*r<l&&o>0&&"DOWN"===e.direction?(h=e,i=e.direction):(o<0?h={x:t.x,y:t.y-d}:r>0&&"RIGHT"===e.direction||r<0&&"LEFT"===e.direction?h={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.min(t.y,e.y)-d,h={x:t.x,y:s}):h={x:t.x,y:t.y-o/2},i=r>0?"LEFT":"RIGHT"));const c=Object.assign(Object.assign({},h),{direction:i});return n=n.concat(this.route(c,e)),n.push(t),n}drawStartArrow(t,e,i){const s=t.ctx;if(1===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}drawStopArrow(t,e,i){const s=t.ctx;if(2===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}calculateArrowPoints(t,e){const i=m(e,t),s=Math.PI/10,r=new f(this.arrowLength,i.theta-s),o=new f(this.arrowLength,i.theta+s),h=new f(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[c(r.toPoint(),e.x,e.y),c(o.toPoint(),e.x,e.y),c(h.toPoint(),e.x,e.y)]}get minDist(){return 20*this.scale}get tol(){return.1*this.scale}get tolxtol(){return.01*this.scale}get name(){return this.properties.getValue("name")}get arrows(){return this.properties.getValue("arrows")}get fillArrow(){return this.properties.getValue("fill_arrow")}get arrowLength(){return this.scale*this.properties.getValue("arrow_length")}get lineColor(){return this.properties.getValue("line_color")}get lineStyle(){return this.properties.getValue("line_style")}get lineWidth(){return this.scale*this.properties.getValue("line_width")}get router(){return this.properties.getValue("router")}get sourceTerm(){return this.properties.getValue("src_term")}get sourceWuid(){return this.properties.getValue("src_wuid")}get targetTerm(){return this.properties.getValue("tgt_term")}get targetWuid(){return this.properties.getValue("tgt_wuid")}get points(){return x(this.properties.getValue("points"),this.scale)}}let Xe=0;class Ke extends qe{constructor(t,e){super(t,e),this.properties.add(new it("auto_scale_widgets"))}parseNode(t){super.parseNode(t);const e=Xe++;this.macros.set("DID",`DID_${e}`);const i=this.properties.getValue("name");this.macros.set("DNAME",i);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}for(const e of t.getNodes("connection")){const t=new Ye(this.display);t.parseNode(e),this.connections.push(t)}}draw(t){for(const e of this.widgets.filter((t=>t.visible)))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(const e of this.connections)e.draw(t);for(const e of this.widgets.filter((t=>t.visible)))e.drawOverlay(t)}measureContentBounds(t){let e=0,i=0,s=0,r=0;for(const o of this.widgets.filter((t=>t.visible))){const h=t?o.bounds:o.unscaledBounds;e=Math.min(e,h.x),i=Math.min(i,h.y),s=Math.max(s,h.x+h.width),r=Math.max(r,h.y+h.height)}return{x:e,y:i,width:s-e,height:r-i}}get autoScaleWidgets(){return this.properties.getValue("auto_scale_widgets")}}class Ze extends qe{parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const e=t.createChild(this.width,this.height);for(const t of this.widgets.filter((t=>t.visible)))t.drawHolder(e),t.draw(e),t.drawDecoration(e);for(const t of this.widgets.filter((t=>t.visible)))t.drawOverlay(e);t.copy(e,this.x,this.y)}}class Je{constructor(){this.includeParentMacros=!0,this.macros={}}clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}}class Qe{constructor(t,e,i){this.autoScaleWidgets=t,this.minWidth=e,this.minHeight=i}}class ti{constructor(t,e,i){this.widthScalable=t,this.heightScalable=e,this.keepWidthHeightRatio=i}}class ei{constructor(){this.scripts=[]}}class ii{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){const e=(new DOMParser).parseFromString(t,"text/xml");return new ii(e.documentElement)}getNode(t){const e=this.findChild(t);return new ii(e)}getNodes(t){const e=[];for(let i=0;i<this.node.childNodes.length;i++){const s=this.node.childNodes[i];3!==s.nodeType&&(t&&s.nodeName!==t||e.push(new ii(s)))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++){if(this.node.childNodes[e].nodeName===t)return!0}return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseFloat(i.textContent)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseInt(i.textContent,10)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return"true"===i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){const i=this.node.attributes.getNamedItem(t);if(null===i){if(void 0!==e)return e;throw new Error(`No attribute named ${t}`)}return"true"===i.textContent}getColor(t,e){const i=this.findChild(t);for(let t=0;t<i.childNodes.length;t++){const e=i.childNodes[t];if("color"===e.nodeName)return this.parseColorNode(new ii(e))}if(void 0!==e)return e;throw new Error("No child node named 'color' could be found")}getFont(t){const e=this.getNode(t);if(e.hasNode("opifont.name")){const t=e.getNode("opifont.name"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");let o=!1;return t.hasAttribute("pixels")&&(o=t.getBooleanAttribute("pixels")),new W(i,s,r,o)}{const t=e.getNode("fontdata"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");return new W(i,s,r,!1)}}getPoints(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("point"))i.push({x:t.getIntAttribute("x"),y:t.getIntAttribute("y")});return i}getStringList(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("s"))i.push(t.getTextContent());return i}getScripts(t){const e=this.getNode(t),i=new ei;for(const t of e.getNodes("path")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=t.getStringAttribute("pathString");"EmbeddedJs"===s?i.scripts.push({embedded:!0,text:t.getString("scriptText"),checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e}):"EmbeddedPy"===s?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:s,checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e})}return i}getScaleOptions(t){const e=this.getNode(t);return new ti(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){const e=this.getNode(t);return new Qe(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){const e=this.getNode(t);if(!e.hasNode("e"))return new H(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"));{const t=new H(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(const i of e.getNodes("e")){const e=Number(i.getTextContent()),s=i.getIntAttribute("red"),r=i.getIntAttribute("green"),o=i.getIntAttribute("blue");t.addMapping(e,s,r,o)}}}getRules(t){const e=this.getNode(t),i=new Gt;for(const t of e.getNodes("rule")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=[];for(const e of t.getNodes("exp")){e.getNode("value").hasNode("color")?s.push({type:"color",expression:e.getStringAttribute("bool_exp"),outputValue:e.getColor("value")}):s.push({type:"string",expression:e.getStringAttribute("bool_exp"),outputValue:e.getString("value")})}i.rules.push({name:t.getStringAttribute("name"),propertyName:t.getStringAttribute("prop_id"),outputExpression:t.getBooleanAttribute("out_exp"),inputs:e,expressions:s})}return i}getMacros(t){const e=this.getNode(t),i=new Je;i.includeParentMacros=e.getBoolean("include_parent_macros");for(const t of e.getNodes())"include_parent_macros"!==t.name&&i.set(t.name,e.getString(t.name));return i}getActions(t){const e=this.getNode(t),i=new Wt;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(const t of e.getNodes("action")){const e=t.getStringAttribute("type");if("OPEN_DISPLAY"===e){const e=new Bt(t.getString("path"));t.hasNode("mode")&&(e.mode=t.getInt("mode")),e.description=t.getString("description"),i.add(e)}else if("OPEN_FILE"===e){const e=new It;e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("EXECUTE_CMD"===e){const e=new Ht;e.command=t.getString("command"),e.commandDirectory=t.getString("command_directory"),e.waitTime=t.getInt("wait_time"),e.description=t.getString("description"),i.add(e)}else if("EXECUTE_JAVASCRIPT"===e){const e=new Ot(t.getBoolean("embedded"));e.embedded?e.text=t.getString("scriptText"):e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("WRITE_PV"===e){const e=new Ft(t.getString("pv_name"),t.getString("value"));e.confirmMessage=t.getString("confirm_message",""),e.description=t.getString("description"),i.add(e)}else if("PLAY_SOUND"===e){const e=new Nt;e.path=t.getString("path"),e.description=t.getString("description"),i.add(e)}else if("OPEN_WEBPAGE"===e){const e=new Dt;e.hyperlink=t.getString("hyperlink"),e.description=t.getString("description"),i.add(e)}else console.warn(`Unsupported action type ${e}`),i.add(null)}return i}parseColorNode(e){const i=e.getIntAttribute("red"),s=e.getIntAttribute("green"),r=e.getIntAttribute("blue");return new t(i,s,r)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}}let si=0;class ri extends qe{constructor(t,e){super(t,e),this.properties.add(new D("group_name")),this.properties.add(new D("opi_file")),this.properties.add(new j("resize_behaviour",0))}parseNode(t){super.parseNode(t);const e=si++;this.macros.set("LCID",`LCID_${e}`)}init(){this.opiFile&&fetch(this.display.baseUrl+this.opiFile,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.linkedDisplay=new Ke(this.display,this);const e=ii.parseFromXML(t);this.linkedDisplay.parseNode(e),this.requestRepaint()}))}))}draw(t){this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect(Object.assign(Object.assign({},this.area),{color:this.linkedDisplay.backgroundColor})),0===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!1);let{width:i,height:s}=e;const r=this.display.scale;i*=r,s*=r;const o=i/s;let h=this.width,n=h/o,a=h/i;n>this.height&&(n=this.height,h=n*o,a=n/i),this.linkedDisplay.relativeScale=a;const l=t.createChild(Math.ceil(h),Math.ceil(n));l.translate(e.x,e.y),this.linkedDisplay.draw(l),t.copy(l,this.x,this.y)}else if(1===this.resizeBehavior)console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior);else if(2===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!0),i=t.createChild(e.width,e.height);i.translate(e.x,e.y),this.linkedDisplay.draw(i),t.copy(i,this.x,this.y)}else 3===this.resizeBehavior&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&""!==this.groupName?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue("opi_file")}get groupName(){return this.properties.getValue("group_name")}get resizeBehavior(){return this.properties.getValue("resize_behaviour")}}class oi{constructor(t,e){this.widget=t,this.i=e,this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue("active_tab",e),t.requestRepaint())},cursor:"pointer"}}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`tab_${this.i}_${t}`)}get title(){return this.getValue("title")}get backgroundColor(){return this.getValue("background_color")}get foregroundColor(){return this.getValue("foreground_color")}get enabled(){return this.getValue("enabled")}get font(){return this.getValue("font").scale(this.scale)}}class hi extends qe{constructor(t,e){super(t,e),this.tabs=[],this.properties.add(new j("minimum_tab_height")),this.properties.add(new j("active_tab")),this.properties.add(new z("horizontal_tabs")),this.properties.add(new j("tab_count")),this.properties.addGenerator((()=>{this.tabs=[];const t=this.properties.getValue("tab_count"),e=[];for(let i=0;i<t;i++)this.tabs.push(new oi(this,i)),e.push(new D(`tab_${i}_title`),new U(`tab_${i}_background_color`),new U(`tab_${i}_foreground_color`),new z(`tab_${i}_enabled`),new q(`tab_${i}_font`));return e}))}parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.horizontalTabs?this.drawHorizontalTabs(t):this.drawVerticalTabs(t)}measureTabOffset(t){return this.horizontalTabs?{x:0,y:this.measureLabelHeight(t)}:{x:this.measureLabelWidth(t),y:0}}measureLabelHeight(t){const{scale:e}=this,i=1*e;let s=this.minimumTabHeight;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).height+i;o>s&&(s=o)}return s+this.margin}measureLabelWidth(t){const{scale:e}=this,i=1*e;let s=this.minimumTabWidth;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).width+i;o>s&&(s=o)}return s+this.margin}drawHorizontalTabs(e){const{margin:i,gap:s,scale:r}=this,o=this.measureLabelHeight(e),h=1*r;let n=this.x;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=e.measureText(l.title,l.font);let c,p,g,u,m;this.activeTab===a?(c=n,p=this.y,g=d.width+h+i+s,u=o,m=l.backgroundColor):(c=n+s,p=this.y+2*r,g=d.width+h+i-s,u=o-2*r,m=this.darken(l.backgroundColor)),e.fillRect({x:c,y:p,width:g,height:u,color:m});e.addHitRegion(l.headerRegion).addRect(c,p,g,u);const f=e.createLinearGradient(c,p,c,p+u);if(f.addColorStop(0,t.WHITE.toString()),f.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:c,y:p,width:g,height:u,gradient:f}),e.fillText({x:c+g/2,y:p+u/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=d.width+h+i-1*r,this.activeTab===a){const t=this.x,i=this.y+o,s=this.width,r=this.height-o;e.fillRect({x:t,y:i,width:s,height:r,color:l.backgroundColor});const h=this.widgets[a],n=e.createChild(s,r);h.drawHolder(n),h.draw(n),h.drawDecoration(n),h.drawOverlay(n),e.copy(n,t,i)}else{this.widgets[a].hide()}}}drawVerticalTabs(e){const{margin:i,gap:s,scale:r}=this,o=this.measureLabelWidth(e),h=1*r;let n=this.y;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=e.measureText(l.title,l.font),c=Math.max(d.height+h+h,this.minimumTabHeight);let p,g,u,m,f;this.activeTab===a?(p=this.x,g=n,u=o,m=c+i+s,f=l.backgroundColor):(p=this.x+2*r,g=n+s,u=o-2*r,m=c+i-s,f=this.darken(l.backgroundColor)),e.fillRect({x:p,y:g,width:u,height:m,color:f});e.addHitRegion(l.headerRegion).addRect(p,g,u,m);const x=e.createLinearGradient(p,g,p+u,g);if(x.addColorStop(0,t.WHITE.toString()),x.addColorStop(1,t.WHITE.withAlpha(0).toString()),e.fillRect({x:p,y:g,width:u,height:m,gradient:x}),e.fillText({x:p+u/2,y:g+m/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=c+i-1*r,this.activeTab===a){const t=this.x+o-1*r,i=this.y,s=this.width-o,h=this.height-1*r;e.fillRect({x:t,y:i,width:s,height:h,color:l.backgroundColor});const n=this.widgets[a],d=e.createChild(s,h);n.drawHolder(d),n.draw(d),n.drawDecoration(d),n.drawOverlay(d),e.copy(d,t,i)}else{this.widgets[a].destroy()}}}darken(e){const i=Math.max(0,e.red-30),s=Math.max(0,e.green-30),r=Math.max(0,e.blue-30);return new t(i,s,r)}get margin(){return 10*this.scale}get gap(){return 2*this.scale}get minimumTabWidth(){return 20*this.scale}get minimumTabHeight(){return this.scale*this.properties.getValue("minimum_tab_height")}get activeTab(){return this.properties.getValue("active_tab")}get tabCount(){return this.properties.getValue("tab_count")}get horizontalTabs(){return this.properties.getValue("horizontal_tabs")}}class ni extends jt{constructor(t,e){super(t,e),this.properties.add(new D("url"))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="https://yamcs.org",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${t}px`,this.iframe.style.top=`${e}px`,this.iframe.style.width=`${i}px`,this.iframe.style.height=`${s}px`,this.url&&this.prevUrl!==this.url&&(this.iframe.src=this.url,this.prevUrl=this.url)}}hide(){this.iframe&&(this.iframe.style.display="none")}destroy(){this.iframe&&(this.display.rootPanel.removeChild(this.iframe),this.iframe=void 0)}get url(){return this.properties.getValue("url")}}class ai{constructor(t){this.targetElement=t,this.repaintRequested=!1,this._editMode=!1,this._showGrid=!1,this._showOutline=!1,this._showRuler=!1,this._selection=[],this._scale=1,this._transparent=!1,this.imagesPrefix="",this.baseUrl="",this.eventListeners={closedisplay:[],opendisplay:[],openpv:[],selection:[],scale:[]},this.rootPanel=document.createElement("div"),this.rootPanel.className="display-root",this.rootPanel.style.overflow="hidden",this.rootPanel.style.position="relative",this.rootPanel.style.fontSize="0",t.appendChild(this.rootPanel);const e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new y(e),this.ctx=this.g.ctx,this.pvEngine=new _t(this),this.pvEngine.addProvider(new Rt),this.pvEngine.addProvider(new C),this.displayRegion={id:"display-root",click:()=>this.closeMenu()},this.imageResolver=new _(this),window.requestAnimationFrame((()=>this.step())),new r(this,e,this.g.hitCanvas)}addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}setImageResolver(t){this.imageResolver=t}getImageResolver(){return this.imageResolver}step(){this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.requestAnimationFrame((()=>this.step()))}drawScreen(){var e;if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="#d6d6d6",e.fillRect(0,0,8,8),e.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.instance&&this.g.fillRect(Object.assign(Object.assign({},this.instance.bounds),{color:this.instance.backgroundColor}))}else this.transparent||this.g.fillCanvas((null===(e=this.instance)||void 0===e?void 0:e.backgroundColor)||t.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=25,t.height=25,e.fillStyle=this.instance.foregroundColor.toString(),e.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let t=0;for(;t<=this.ctx.canvas.width;)t+=100,this.ctx.beginPath(),this.ctx.moveTo(t-75+.5,this.ctx.canvas.height),this.ctx.lineTo(t-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t-50+.5,this.ctx.canvas.height),this.ctx.lineTo(t-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(t-25+.5,this.ctx.canvas.height),this.ctx.lineTo(t-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t+.5,this.ctx.canvas.height),this.ctx.lineTo(t+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(t),t,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let e=0;for(;e<=this.ctx.canvas.height;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,e-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-75+.5),this.ctx.moveTo(this.ctx.canvas.width,e-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,e-50+.5),this.ctx.moveTo(this.ctx.canvas.width,e-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-25+.5),this.ctx.moveTo(this.ctx.canvas.width,e+.5),this.ctx.lineTo(this.ctx.canvas.width-8,e+.5),this.ctx.stroke(),this.ctx.fillText(String(e),this.ctx.canvas.width-8,e)}this.showOutline&&this.instance&&(this.ctx.lineWidth=1,this.ctx.setLineDash([10,5]),this.ctx.strokeStyle="black",this.ctx.strokeRect(-.5,-.5,this.instance.holderWidth+1,this.instance.holderHeight+1),this.ctx.setLineDash([])),this.instance&&this.instance.draw(this.g);for(const t of this.selection){const e=this.findWidget(t);e&&e.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){var e;this.rootPanel.title=null!==(e=null==t?void 0:t.trim())&&void 0!==e?e:""}closeMenu(){var t;null===(t=this.instance)||void 0===t||t.closeMenu()}createWidget(t,e){switch(t){case"Action Button":return new $t(this,e);case"Arc":return new ae(this,e);case"Boolean Button":return new zt(this,e);case"Boolean Switch":return new Ut(this,e);case"Byte Monitor":return new fe(this,e);case"Check Box":return new Xt(this,e);case"Choice Button":return new Kt(this,e);case"Combo":case"Combo Box":return new Jt(this,e);case"Ellipse":return new le(this,e);case"Gauge":return new ve(this,e);case"Grouping Container":return new Ze(this,e);case"Image":return new de(this,e);case"Image Boolean Button":return new Qt(this,e);case"Image Boolean Indicator":return new be(this,e);case"Intensity Graph":return new Se(this,e);case"Label":return new ce(this,e);case"LED":return new Ve(this,e);case"Linking Container":return new ri(this,e);case"Meter":return new Ce(this,e);case"Button":return new te(this,e);case"Polygon":return new pe(this,e);case"Polyline":return new ge(this,e);case"Progress Bar":return new ke(this,e);case"Radio Box":return new se(this,e);case"Rectangle":return new ue(this,e);case"Rounded Rectangle":return new me(this,e);case"Scrollbar":return new he(this,e);case"Tabbed Container":return new hi(this,e);case"Tank":return new Me(this,e);case"Text Input":return new ne(this,e);case"Text Update":return new Re(this,e);case"Thermometer":return new We(this,e);case"Web Browser":return new ni(this,e);case"XY Graph":return new Ue(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){var t;null===(t=this.instance)||void 0===t||t.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}setSource(t){return this.reset(),new Promise(((e,i)=>{fetch(this.baseUrl+t,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.setSourceString(t),e()})).catch((t=>i(t)))})).catch((t=>i(t)))}))}setSourceString(t){this.reset(),this.instance=new Ke(this);const e=ii.parseFromXML(t);this.instance.parseNode(e),this.requestRepaint()}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0)}measureAbsoluteArea(t){const e=t.bounds;let i=t.parent;for(;i;){if(e.x+=i.holderX,e.y+=i.holderY,i instanceof hi){const{x:t,y:s}=i.measureTabOffset(this.g);e.x+=t,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=1*this.scale,e.y+=1*this.scale,e}addEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t].push(e)}removeEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t]=this.eventListeners[t].filter((t=>t!==e))}fireEvent(t,e){this.eventListeners[t].forEach((t=>t(e)))}get showGrid(){return this._showGrid}set showGrid(t){this._showGrid=t,this.requestRepaint()}get showOutline(){return this._showOutline}set showOutline(t){this._showOutline=t,this.requestRepaint()}get showRuler(){return this._showRuler}set showRuler(t){this._showRuler=t,this.requestRepaint()}get selection(){return this._selection}set selection(t){this._selection=t,this.requestRepaint();const e={selected:this._selection.slice()};this.fireEvent("selection",e)}get editMode(){return this._editMode}set editMode(t){this._editMode=t,this.requestRepaint()}get scale(){return this._scale}set scale(t){this._scale=t,this.requestRepaint();const e={scale:t};this.fireEvent("scale",e)}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get widgets(){return this.instance?this.instance.widgets:[]}clearSelection(){this.selection.length&&(this.selection=[])}findWidget(t){if(this.instance)return this.instance.findWidget(t)}findWidgetByName(t){if(this.instance)return this.instance.findWidgetByName(t)}getPVNames(){return this.pvEngine.getPVNames()}getPV(t){return this.pvEngine.getPV(t)}setValues(t){this.pvEngine.setValues(t)}copyCanvas(t){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}}export{wt as AlarmSeverity,T as CompiledFormula,_ as DefaultImageResolver,ai as Display,L as FormulaCompiler,xt as PV};
|
|
2
2
|
//# sourceMappingURL=opi.js.map
|