@yamcs/opi 1.4.3 → 1.4.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.
@@ -1,22 +1,22 @@
1
- "use strict";(()=>{function Ne(p){let t=document.createElement("canvas").getContext("2d");t.fillStyle=p;let e=String(t.fillStyle),i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return i?new m(parseInt(i[1],16),parseInt(i[2],16),parseInt(i[3],16)):m.BLACK}var m=class p{constructor(t,e,i,r=255){this.red=t;this.green=e;this.blue=i;this.alpha=r}static TRANSPARENT=new p(0,0,0,0);static BLACK=new p(0,0,0);static BLUE=new p(0,0,255);static CYAN=new p(0,255,255);static DARK_GRAY=new p(150,150,150);static GRAY=new p(200,200,200);static GREEN=new p(0,255,0);static LIGHT_BLUE=new p(153,186,243);static ORANGE=new p(255,128,0);static PINK=new p(255,0,255);static PURPLE=new p(128,0,255);static RED=new p(255,0,0);static WHITE=new p(255,255,255);static YELLOW=new p(255,255,0);static BUTTON=new p(239,240,241);static BUTTON_DARKER=new p(164,168,172);static BUTTON_DARKEST=p.BLACK;static BUTTON_LIGHTEST=p.WHITE;withAlpha(t){return new p(this.red,this.green,this.blue,t)}mixWith(t,e){let i=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),s=Math.floor(this.blue*e+t.blue*(1-e));return new p(i,r,s)}brighter(){let{red:t,green:e,blue:i}=this,r=Math.floor(1/(1-.7));return t===0&&e===0&&i===0?new p(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),new p(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 p(Math.max(Math.floor(this.red*.7),0),Math.max(Math.floor(this.green*.7),0),Math.max(Math.floor(this.blue*.7),0))}contrast(){return new p(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=t.length==1?"0"+t:t;let e=this.green.toString(16);e=e.length==1?"0"+e:e;let i=this.blue.toString(16);i=i.length==1?"0"+i:i;let r=this.alpha.toString(16);return r=r.length==1?"0"+r:r,`#${t}${e}${i}${r}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}};var li=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};var hi=class{openConfirmDialog(t,e){return confirm(e)}openInformationDialog(t,e){alert(e)}openWarningDialog(t,e){alert(e)}openErrorDialog(t,e){alert(e)}openPasswordDialog(t,e,i){let r=prompt(e);return r?r===i:!1}};var ci=p=>(document.removeEventListener("click",ci,!0),p.preventDefault(),p.stopPropagation(),!1);function Rs(p){return(p.buttons&1)===1||p.buttons===void 0&&p.which==1}var Lo=5;function sx(p,t,e,i){return Math.sqrt((e-p)*(e-p)+(i-t)*(i-t))}function Co(p,t){return p&&t&&p.id===t.id}var pi=class{constructor(t,e,i){this.display=t;this.canvas=e;this.hitCanvas=i;let{signal:r}=this.abortController;e.addEventListener("click",s=>this.onCanvasClick(s),{signal:r}),e.addEventListener("dblclick",s=>this.onCanvasDblClick(s),{signal:r}),e.addEventListener("mousedown",s=>this.onCanvasMouseDown(s),{signal:r}),e.addEventListener("mouseup",s=>this.onCanvasMouseUp(s),{signal:r}),e.addEventListener("mouseout",s=>this.onCanvasMouseOut(s),{signal:r}),e.addEventListener("mousemove",s=>this.onCanvasMouseMove(s),{signal:r})}grabbing=!1;grabTarget;grabPoint;documentMouseMoveListener=t=>this.onDocumentMouseMove(t);documentMouseUpListener=t=>this.onDocumentMouseUp(t);prevEnteredRegion;pendingMouseMoveEvent;mouseMoveRafHandle;abortController=new AbortController;destroy(){this.abortController.abort(),document.removeEventListener("click",ci,!0),document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener),this.mouseMoveRafHandle!==void 0&&cancelAnimationFrame(this.mouseMoveRafHandle)}toPoint(t){let e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();let e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{let i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasDblClick(t){if(this.display.editMode)return;let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.dblclick&&i.dblclick({clientX:t.clientX,clientY:t.clientY,point:e})}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",ci,!0),Rs(t))){let e=this.toPoint(t),i=document.activeElement;this.display.rootPanel.contains(i)&&(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&i.blur();let r=this.hitCanvas.getActiveRegion(e.x,e.y);return r&&r.mouseDown&&r.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),r&&r.grab&&(this.grabPoint={...e},this.grabTarget=r),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;let 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){this.pendingMouseMoveEvent=t,this.mouseMoveRafHandle===void 0&&(this.mouseMoveRafHandle=requestAnimationFrame(()=>{this.mouseMoveRafHandle=void 0;let e=this.pendingMouseMoveEvent;this.pendingMouseMoveEvent=void 0,this.processMouseMove(e)}))}processMouseMove(t){let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);if(this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(Co(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(Co(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i,!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&Rs(t)){let o=sx(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(o)>Lo&&(this.initiateGrab(),Lo>0&&this.grabPoint&&(this.grabPoint=e))}let r=this.grabbing?this.grabTarget:i,s=r&&r.cursor?r.cursor:"auto";s!=this.canvas.style.cursor&&(this.canvas.style.cursor=s),this.grabbing&&this.grabTarget&&Rs(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",ci,!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);let e=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,e?.grabEnd&&e.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){let i=this.display.instance;if(i)for(let r of i.widgets.slice().reverse()){let s=r.holderX,o=r.holderY,n=r.holderX+r.holderWidth,a=r.holderY+r.holderHeight;if(s<t&&t<n&&o<e&&e<a)return this.display.selection=[r.wuid],!1}}};var di=class{constructor(t){this.utc=t}formatDate(t,e){let i=this.utc,r="";if(e.year&&(r+=i?t.getUTCFullYear():t.getFullYear()),e.month){e.year&&(r+="-");let s=(i?t.getUTCMonth():t.getMonth())+1;r+=(s<10?"0":"")+s}if(e.day){e.month&&(r+="-");let s=i?t.getUTCDate():t.getDate();r+=(s<10?"0":"")+s}return r}formatTime(t,e){let i=this.utc,r="";if(e.hours){let s=i?t.getUTCHours():t.getHours();r+=(s<10?"0":"")+s}if(e.minutes){e.hours&&(r+=":");let s=i?t.getUTCMinutes():t.getMinutes();r+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(r+=":");let s=i?t.getUTCSeconds():t.getSeconds();r+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(r+=".");let s=i?t.getUTCMilliseconds():t.getMilliseconds();r+=(s<10?"00":s<100?"0":"")+s}return r}};var Ao="rgb(255,255,255)",ox=!!navigator.brave,ui=class p{constructor(t,e,i){this.parent=t;let r=document.createElement("canvas");r.width=e??r.width,r.height=i??r.height,this.ctx=r.getContext("2d",{willReadFrequently:!0}),this.root=t?.root||t}ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=Ao,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){let e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){let i=this.ctx.getImageData(t,e,1,1).data,r=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(r)||void 0}createChild(t,e){return new p(this,t,e)}transferToParent(t,e,i,r){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,r)}generateUniqueColor(t){for(;;){let e=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=Math.round(Math.random()*255),s=`rgb(${e},${i},${r})`;if(!this.regionsByColor.has(s)&&s!==Ao)return ox?(this.regionsByColor.set(`rgb(${e-1},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i},${r})`,t),this.regionsByColor.set(`rgb(${e},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r+1})`,t)):this.regionsByColor.set(s,t),s}}};function Bt(p,t,e,i,r){return D({x:p,y:t,width:e,height:i},r/2)}function Tt(p,t,e,i,r){let s=Math.sin(r),o=Math.cos(r),n=p-e,a=t-i;return{x:n*o-a*s+e,y:n*s+a*o+i}}function D(p,t,e){return e===void 0&&(e=t),{x:p.x+e,y:p.y+t,width:p.width-(e+e),height:p.height-(t+t)}}function _s(p){return{x:Math.round(p.x)+.5,y:Math.round(p.y)+.5,width:Math.round(p.width),height:Math.round(p.height)}}function gi(p,t){let e=p.x,i=p.y,r=e+p.width,s=i+p.height;if(r<e){let d=e;e=r,r=d}if(s<i){let d=i;i=s,s=d}let o=t.x,n=t.y,a=o+t.width,l=n+t.height;if(a<o){let d=o;o=a,a=d}if(l<n){let d=n;n=l,l=d}let h=Math.max(e,o),c=Math.max(i,n);return{x:h,y:c,width:Math.min(r,a)-h,height:Math.min(s,l)-c}}function Ht(p,t,e){return{x:p.x+t,y:p.y+e}}function ht(p,t,e){return p.map(i=>Ht(i,t,e))}function G(p){return p*Math.PI/180}function Fe(p,t){return Math.sqrt((t.x-p.x)*(t.x-p.x)+(t.y-p.y)*(t.y-p.y))}function ft(p,t,e){let i=Math.floor(p*Math.cos(t)),r=Math.floor(-p*Math.sin(t));return{x:e.x+e.width/2+i,y:e.y+e.height/2+r}}function mi(p,t){let e=t.x-p.x,i=t.y-p.y,r=Math.sqrt(Math.pow(e,2)+Math.pow(i,2)),s=Math.acos(e/r);return i>0&&(s=2*Math.PI-s),new _t(Math.floor(r),s)}var _t=class{constructor(t,e){this.r=t;this.theta=e}toPoint(){let t=Math.floor(this.r*Math.cos(this.theta)),e=Math.floor(-this.r*Math.sin(this.theta));return{x:t,y:e}}};function re(p,t){return p.map(e=>({x:e.x*t,y:e.y*t}))}function Oo(p){let t=p[0].x,e=p[0].x,i=p[0].y,r=p[0].y;for(let s of p)t=Math.min(t,s.x),e=Math.max(e,s.x),i=Math.min(i,s.y),r=Math.max(r,s.y);return{x:(t+e)/2,y:(i+r)/2}}function ge(p,t){if(p.length===0)return p;let e=Oo(p),i=G(t),r=p.map(o=>Tt(o.x,o.y,e.x,e.y,i)),s=Oo(r);return s.x!==e.x||s.y!==e.y?ht(r,e.x-s.x,e.y-s.y):r}function fi(p){return p.map(t=>({x:t.x+.5,y:t.y+.5}))}function wi(p,t,e,i,r){let s=e*Math.PI/180,o=Math.cos(s),n=Math.sin(s),a=p.width/2;if(i===1)if(e<=90){let h=t.width*o+t.height*n;a=(p.width-h)/2+t.height*n}else if(e<=180){let h=t.height*n-t.width*o;a=p.width-(p.width-h)/2}else if(e<=270){let h=-t.width*o-t.height*n;a=(p.width-h)/2-t.width*o}else{let h=t.width*o-t.height*n;a=(p.width-h)/2}else i===2?e<=90?a=p.width-t.width*o:e<=180?a=p.width:e<=270?a=p.width- -t.height*n:a=p.width-(t.width*o-t.height*n):e<=90?a=t.height*n:e<=180?a=t.height*n-t.width*o:e<=270?a=-t.width*o:a=0;let l=p.height/2;if(r===1)if(e<=90){let h=t.width*n+t.height*o;l=(p.height-h)/2}else if(e<=180){let h=t.width*n-t.height*o;l=(p.height-h)/2-t.height*o}else if(e<=270){let h=-t.width*n-t.height*o;l=p.height-(p.height-h)/2}else{let h=t.height*o-t.width*n;l=(p.height-h)/2-t.height*n}else r===2?e<=90?l=p.height-(t.width*n+t.height*o):e<=180?l=p.height-t.width*n:e<=270?l=p.height:l=p.height-t.height*o:e<=90?l=0:e<=180?l=-t.height*o:e<=270?l=-t.width*n-t.height*o:l=-t.width*n;return{x:a,y:l}}function xi(p,t,e,i,r,s,o){p.beginPath(),!s&&!o?p.rect(t,e,i,r):(i<2*s&&(s=i/2),r<2*o&&(o=r/2),p.moveTo(t+s,e),p.lineTo(t+i-s,e),p.quadraticCurveTo(t+i,e,t+i,e+o),p.lineTo(t+i,e+r-o),p.quadraticCurveTo(t+i,e+r,t+i-s,e+r),p.lineTo(t+s,e+r),p.quadraticCurveTo(t,e+r,t,e+r-o),p.lineTo(t,e+o),p.quadraticCurveTo(t,e,t+s,e))}function me(p,t,e,i){return p===null?"":typeof p=="string"?i==="BINARY_STRING"?nx(p):p:typeof p=="number"?e===-1?Eo(t,p,void 0,3):Eo(t,p,e,e):p instanceof Date?p.toISOString().replace("T"," ").replace("Z",""):String(p)}function nx(p){let t="";for(let e=0;e<p.length;e++){let i=p.charCodeAt(e).toString(16);t+=i.length===2?i:"0"+i}return t&&`0x${t.toUpperCase()}`}function Eo(p,t,e,i){if(t==null||t==null)return"";switch(p){case 0:case 1:let r={minimumFractionDigits:e,maximumFractionDigits:i,useGrouping:!1,roundingMode:"halfEven"};return Intl.NumberFormat("en-US",r).format(t);case 2:return t.toExponential(i).replace("e+","E").toUpperCase();case 3:return"0x"+t.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${p}`),String(t)}}function fe(p,t,e){let{a:i,d:r,e:s,f:o}=p.getTransform(),n=t*i+s,a=e*r+o,l=Math.floor(n),h=Math.floor(a);return{x:(l-s)/i,y:(h-o)/r,subPixelX:(n-l)/i,subPixelY:(a-h)/r}}var yi=class p{constructor(t,e,i=1){this.canvas=t;this.pixelRatio=i;this.ctx=t.getContext("2d"),this.hitCanvas=e||new ui,this.hitCtx=this.hitCanvas.ctx}ctx;hitCanvas;hitCtx;parentOffset;get cssWidth(){return this.canvas.width/this.pixelRatio}get cssHeight(){return this.canvas.height/this.pixelRatio}createChild(t,e){let i=this.hitCanvas.createChild(Math.ceil(t),Math.ceil(e)),r=document.createElement("canvas");r.width=Math.ceil(t*this.pixelRatio),r.height=Math.ceil(e*this.pixelRatio);let s=new p(r,i,this.pixelRatio);return s.ctx.scale(this.pixelRatio,this.pixelRatio),s}createChildAt(t,e,i,r){let{x:s,y:o,subPixelX:n,subPixelY:a}=fe(this.ctx,t,e),l=this.createChild(Math.ceil(i+n),Math.ceil(r+a));return l.ctx.translate(n,a),l.parentOffset={x:s,y:o},l}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copyChild(t){if(!t.parentOffset)throw new Error("Buffer was not created with createChildAt");this.copy(t,t.parentOffset.x,t.parentOffset.y)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i,t.cssWidth,t.cssHeight);let r=fe(this.hitCtx,e,i);t.hitCanvas.transferToParent(r.x,r.y,t.hitCtx.canvas.width,t.hitCtx.canvas.height)}copyFitted(t,e,i,r,s){let{width:o,height:n}=t.canvas,a=o/n,l=r,h=l/a;h>s&&(h=s,l=h*a),this.copyScaled(t,e,i,l,h)}copyScaled(t,e,i,r,s){this.ctx.drawImage(t.canvas,e,i,r,s),t.hitCanvas.transferToParent(e,i,r,s)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height),this.ctx.restore()}clearCanvas(){this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.restore()}resize(t,e){let i=Math.ceil(t*this.pixelRatio),r=Math.ceil(e*this.pixelRatio);(this.canvas.width!==i||this.canvas.height!==r)&&(this.canvas.width=i,this.canvas.height=r,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e),this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)}fillRect(t){"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(xi(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),t.opacity!==void 0&&(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();let e=t.startAngle||0,i=t.endAngle===void 0?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),t.opacity!==void 0&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();let e=t.startAngle||0,i=t.endAngle===void 0?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),"color"in t?this.ctx.strokeStyle=t.color.toString():this.ctx.strokeStyle=t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e,i=!1){this.ctx.font=e.getFontString();let r=this.ctx.measureText(t),s;return r.fontBoundingBoxAscent!==void 0&&r.fontBoundingBoxDescent!==void 0?s={width:r.width,height:r.fontBoundingBoxAscent+r.fontBoundingBoxDescent}:s={width:r.width,height:e.height},i&&(s.width=Math.ceil(s.width),s.height=Math.ceil(s.height)),s}createLinearGradient(t,e,i,r){return this.ctx.createLinearGradient(t,e,i,r)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);let e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){let i=D(t,e/2,e/2);t.rx||t.ry?(xi(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?(xi(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(let 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(),t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),t.opacity!==void 0&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(let e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),t.opacity!==void 0&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new Ts(this.hitCanvas.ctx)}},R=class p{segments=[];constructor(t,e){this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){let e=t.findIndex(r=>r.y!==null);if(e===-1){let r=new p(0,0);return r.segments.length=0,r}let i=new p(t[e].x,t[e].y);for(let r=e+1;r<t.length;r++){let{x:s,y:o}=t[r];o!==null&&(r>0&&t[r-1].y===null?i.moveTo(s,o):i.lineTo(s,o))}return i}getBoundingBox(){let 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++){let r=this.segments[i];r.x<t.x&&(t.x=r.x),r.x>e.x&&(e.x=r.x),r.y<t.y&&(t.y=r.y),r.y>e.y&&(e.y=r.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(){if(this.segments.length){let t=this.segments[0];this.segments.push({x:t.x,y:t.y,line:!0})}return this}translate(t,e){for(let i of this.segments)i.x+=t,i.y+=e;return this}},Ts=class{constructor(t){this.ctx=t}addRect(t,e,i,r){return this.ctx.fillRect(t,e,i,r),this}addEllipse(t,e,i,r,s,o,n,a){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,r,s,o,n,a),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(let e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}};var Pi=class{load(t){return Promise.resolve(t)}};var we=class{constructor(t,e=[]){this.widget=t;for(let i of e)this.properties.set(i.name,i)}properties=new Map;generators=[];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 $e)e.value=t.getActions(e.name);else if(e instanceof ze)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof f)e.value=t.getBoolean(e.name);else if(e instanceof se)e.value=t.getColorMap(e.name);else if(e instanceof S)e.value=t.getColor(e.name);else if(e instanceof C)e.value=t.getFloat(e.name);else if(e instanceof H)e.value=t.getFont(e.name);else if(e instanceof P)e.value=t.getInt(e.name);else if(e instanceof oe)e.value=t.getMacros(e.name);else if(e instanceof Ge)e.value=t.getMatrix(e.name);else if(e instanceof Wt)e.value=t.getPoints(e.name);else if(!(e instanceof Dt))if(e instanceof Ye)e.value=t.getRules(e.name);else if(e instanceof tt)e.value=t.getScaleOptions(e.name);else if(e instanceof Ue)e.value=t.getScripts(e.name);else if(e instanceof T)e.rawValue=t.getString(e.name);else if(e instanceof kt)e.value=t.getStringList(e.name);else if(e instanceof ne)e.value=t.getStringMap(e.name);else if(e instanceof xe)e.value=t.getStringTable(e.name);else throw new Error(`Property ${e.name} has an unexpected type`)}}loadXMLValues(t){this.properties.forEach(e=>{this.loadProperty(t,e)}),this.resolveStringProperties();for(let e of this.generators)for(let 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(e=>{if(e instanceof T){let i=e;i.rawValue!==void 0&&this.widget?e.value=this.widget.expandMacro(i.rawValue):e.value=i.rawValue}})}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){let i=this.properties.get(t);if(i&&i.value!==void 0)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){let i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}},it=class{constructor(t,e){this.name=t;this.defaultValue=e;this.value=e}_value;listeners;get value(){return this._value}set value(t){if(this.value!==t){let e=this._value;if(this._value=t,this.listeners)for(let i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){let e=this.listeners||[],i=e.indexOf(t);i!==-1&&e.splice(i,1)}printScriptValue(t){return String(t)}},T=class extends it{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},Dt=class extends it{constructor(e,i){super(e);this.pvPropertyName=i}},P=class extends it{},C=class extends it{},f=class extends it{},S=class extends it{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},H=class extends it{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},se=class extends it{printScriptValue(t){return`${t.code}`}},Wt=class extends it{},Ge=class extends it{},$e=class extends it{},oe=class extends it{},Ue=class extends it{},kt=class extends it{},ne=class extends it{},xe=class extends it{},Ye=class extends it{},tt=class extends it{},ze=class extends it{};var ye=class{actions=[];hookFirstActionToClick=!1;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]}toString(){return this.actions.length===1?this.actions[0]?.getDescription()??"":`${this.actions.length} actions`}};var lx=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],Pe={Arial:"Liberation Sans","Times New Roman":"Liberation Serif","Courier New":"Liberation Mono"},Mo=new Set;function Vo(p){Mo.add(p)}var Y=class p{constructor(t,e,i,r){this.name=t;this.style=i;r?this.height=e:p.LEGACY_FONT_SIZING?this.height=Math.round(e*16/15):this.height=e*4/3}static LEGACY_FONT_SIZING=!1;static ARIAL_9=new p("Arial",9,0,!1);static ARIAL_10=new p("Arial",10,0,!1);static ARIAL_11=new p("Arial",11,0,!1);static ARIAL_12_BOLD=new p("Arial",12,1,!1);height;scale(t){return new p(this.name,t*this.height,this.style,!0)}getFontString(){let t=this.name;return Mo.has(t)&&(t=Pe[t]),t.indexOf(" ")!==-1&&(t=`"${t}"`),this.style===1?`bold ${this.height}px ${t}`:this.style===2?`italic ${this.height}px ${t}`:this.style===3?`italic bold ${this.height}px ${t}`:(this.style!==0&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${t}`)}get bold(){return this.style===1||this.style===3}get italic(){return this.style===2||this.style===3}isWebSafe(){return lx.indexOf(this.name)!==-1&&!Pe[this.name]}};var be=class{constructor(t,e){this.name=t;this.pvEngine=e}_writable=!1;_units;_labels;_typeHint;_lowerDisplayLimit;_lowerAlarmLimit;_lowerWarningLimit;_upperWarningLimit;_upperAlarmLimit;_upperDisplayLimit;_time;_value;_severity="NONE";_indexValue;_precision=-1;_disconnected=!1;provider;get navigable(){return this.provider?.isNavigable()||!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get labels(){return this._labels}set labels(t){this._labels=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}get typeHint(){return this._typeHint}get alarmName(){let t=this.toNumber();return t==null?"NONE":t<=(this.lowerAlarmLimit??NaN)?"LOLO":t>=(this.upperAlarmLimit??NaN)?"HIHI":t<=(this.lowerWarningLimit??NaN)?"LOW":t>=(this.upperWarningLimit??NaN)?"HIGH":"NONE"}toNumber(){if(this.value===null)return null;if(typeof this.value=="number")return this.value;if(typeof this.value=="boolean")return this.value?1:0;if(typeof this.indexValue!==void 0)return this.indexValue}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this._units=t.units,this._typeHint=t.typeHint,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.removeListener(this.name,t)}toString(){if(this.value!==void 0)return String(this.value)}};var ve=class{rules=[]};var Re=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}},J=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}};function bi(p,t,e,i){let{widthScalable:r,heightScalable:s,keepWidthHeightRatio:o}=i;if(o&&r&&s)if(t<=e){let n=Math.round(p.width*t),a=Math.trunc(p.height*n/p.width);return{width:n,height:a}}else{let n=Math.round(p.height*e);return{width:Math.trunc(p.width*n/p.height),height:n}}return{width:r?Math.round(p.width*t):p.width,height:s?Math.round(p.height*e):p.height}}function vi(p,t,e){let{widthScalable:i,heightScalable:r,keepWidthHeightRatio:s}=e;return s&&r&&i?(p=Math.min(p,t),t=p):r?i||(p=1):t=1,{widthRatio:p,heightRatio:t}}var _e=class{scripts=[]};var Io="actions",Bo="background_color",Ho="backcolor_alarm_sensitive",Do="border_alarm_sensitive",Wo="border_color",ko="border_width",No="border_style",Fo="enabled",Go="foreground_color",$o="forecolor_alarm_sensitive",Xe="height",Uo="name",Ss="pv_name",Yo="pv_value",zo="rules",Xo="scale_options",qo="scripts",Ls="text",Ko="tooltip",jo="transparent",Zo="visible",Jo="widget_type",qe="width",Qo="wuid",Ke="x",je="y",M=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new we(this,[new $e(Io,new ye),new f(Ho,!1),new S(Bo,m.TRANSPARENT),new f(Do,!1),new S(Wo),new P(No),new P(ko),new f(Fo,!0),new f($o,!1),new S(Go),new P(Xe),new T(Uo),new T(Ss),new Dt(Yo,Ss),new Ye(zo,new ve),new Ue(qo,new _e),new T(Ls,""),new T(Ko,""),new f(jo,!1),new f(Zo),new T(Jo),new P(qe),new T(Qo),new P(Ke),new P(je),new tt(Xo,new J(!0,!0,!1))])}x=0;y=0;width=0;height=0;_value;fillRoundRectangleBackgroundBorder=!0;customSize;customHolderWidth;customHolderHeight;originBounds;holderRegion;properties;vars=new Map;pvs=[];async parseNode(t){this.properties.loadXMLValues(t);for(let e of this.properties.all())if(e instanceof H){let i=e.value;this.loadFont(i)}if(this.pvName){let e=this.display.pvEngine.createPV(this.pvName);this.pvs.push(e),this.display.pvEngine.trackListener(this,e.name,()=>this._value=e.value)}for(let e of this.scripts.scripts){let i=[];for(let r of e.inputs){let s=this.expandMacro(r.pvName);i.push(this.display.pvEngine.createPV(s))}if(this.pvs.push(...i),e.embedded)this.display.pvEngine.createScript(this,e,e.text,i);else{let s=await this.display.getScriptLoader().load(e.path);s&&this.display.pvEngine.createScript(this,e,s,i)}}for(let e of this.rules.rules)if(this.properties.getProperty(e.propertyName)){let i=[];for(let r of e.inputs){let s=this.expandMacro(r.pvName);i.push(this.display.pvEngine.createPV(s))}this.pvs.push(...i),this.display.pvEngine.createRule(this,e,i)}else console.warn(`Cannot create rule for unsupported property ${e.propertyName}`);this.actions.isClickable()&&(this.holderRegion={id:`${this.wuid}-holder`},this.tooltip&&(this.holderRegion.tooltip=()=>this.tooltip),this.actions.isClickable()&&(this.holderRegion.click=()=>{for(let e of this.getHookedActions())this.executeAction(e)},this.holderRegion.cursor="pointer")),await this.init()}getHookedActions(){let{actions:t}=this,e=[];for(let i=0;i<t.actions.length;i++)i===0?(t.hookFirstActionToClick||t.hookAllActionsToClick)&&e.push(t.actions[i]):t.hookAllActionsToClick&&e.push(t.actions[i]);return e}drawHolder(t){let{scale:e}=this,i=[0,0,0,0],r=this.borderAlarmSensitive&&(this.pv?.severity==="MINOR"||this.pv?.severity==="MAJOR");if(!r)switch(this.borderStyle){case 0:break;case 1:i=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:i=[1*e,1*e,1*e,1*e];break;case 4:case 5:case 6:i=[2*e,2*e,2*e,2*e];break;case 7:i=[2*e,2*e,1*e,1*e];break;case 8:case 9:case 10:case 11:i=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 12:i=[17*e,1*e,1*e,1*e];break;case 13:i=[16*e,16*e,16*e,16*e];break;case 14:let s=this.borderWidth*2;i=[s,s,s,s];break}this.customSize?(this.customHolderWidth=this.customSize.width+i[1]+i[3],this.customHolderHeight=this.customSize.height+i[0]+i[2]):(this.customHolderWidth=void 0,this.customHolderHeight=void 0),this.x=this.holderX+i[1],this.y=this.holderY+i[0],this.width=this.holderWidth-i[1]-i[3],this.height=this.holderHeight-i[0]-i[2],r||(this.beforeDrawBorder(t),this.drawBorderStyle(t)),this.holderRegion&&t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}beforeDrawBorder(t){}drawBorderStyle(t){let{scale:e}=this;if(this.borderStyle!==0)if(this.borderStyle===1)t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(this.borderStyle===2){let i=1*e,r=this.holderY+i/2,s=this.holderX+i/2,o=this.holderY+this.holderHeight-i+i/2,n=this.holderX+this.holderWidth-i+i/2;t.strokePath({color:m.BLACK,path:new R(n,o).lineTo(n,r).moveTo(n,o).lineTo(s,o)}),t.strokePath({color:m.WHITE,path:new R(s,r).lineTo(n-i,r).moveTo(s,r).lineTo(s,o-i)})}else if(this.borderStyle===3){if(this.isAnyPvInvalid())return;let i=1*e,r=this.holderY+i/2,s=this.holderX+i/2,o=this.holderY+this.holderHeight-i+i/2,n=this.holderX+this.holderWidth-i+i/2;t.strokePath({color:m.WHITE,path:new R(n,o).lineTo(n,r).moveTo(n,o).lineTo(s,o)}),t.strokePath({color:m.BLACK,path:new R(s,r).lineTo(n-i,r).moveTo(s,r).lineTo(s,o-i)})}else if(this.borderStyle===4)this.drawShadowBorder(t,m.BUTTON_LIGHTEST,m.BUTTON_DARKER,m.BUTTON_DARKER,m.BUTTON_LIGHTEST);else if(this.borderStyle===5)this.drawShadowBorder(t,m.BUTTON_DARKER,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKER);else if(this.borderStyle===6)this.drawShadowBorder(t,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST);else if(this.borderStyle===7)this.drawShadowBorder(t,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER);else if(this.borderStyle===8)this.drawDashedBorder(t,[2*e,2*e]);else if(this.borderStyle===9)this.drawDashedBorder(t,[6*e,2*e]);else if(this.borderStyle===10)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e]);else if(this.borderStyle===11)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e,2*e,2*e]);else if(this.borderStyle===12)t.fillRect({x:this.holderX,y:this.holderY+1*e,width:this.holderWidth,height:16*e,color:this.borderColor}),t.fillText({x:this.holderX+1*e+3*e,y:this.holderY+1*e+16/2*e,baseline:"middle",align:"left",font:Y.ARIAL_11.scale(e),color:m.BLACK,text:this.name}),t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:m.BLACK,crispen:!0});else if(this.borderStyle===13){let i=t.measureText(this.name,Y.ARIAL_11.scale(e)),r=1,s=Bt(this.holderX+8*e,this.holderY+8*e,this.holderWidth-16*e-r,this.holderHeight-16*e-r,r);this.transparent||(t.fillRect({...D(s,8*e),color:this.backgroundColor}),t.fillRect({x:this.holderX+16*e,y:this.holderY,width:i.width,height:16*e,color:this.backgroundColor})),t.fillText({x:this.holderX+16*e,y:this.holderY+8*e,baseline:"middle",align:"left",font:Y.ARIAL_11.scale(e),color:this.borderColor,text:this.name}),t.strokePath({color:this.backgroundColor.darker(),path:new R(s.x,s.y).lineTo(s.x+8*e,s.y).moveTo(s.x+8*e+i.width,s.y).lineTo(s.x+s.width,s.y).lineTo(s.x+s.width,s.y+s.height).lineTo(s.x,s.y+s.height).lineTo(s.x,s.y)}),s=Bt(this.holderX+8*e+r,this.holderY+8*e+r,this.holderWidth-16*e-r,this.holderHeight-16*e-r,r),t.strokePath({color:this.backgroundColor.brighter(),path:new R(s.x,s.y).lineTo(s.x+8*e-r,s.y).moveTo(s.x+8*e-r+i.width,s.y).lineTo(s.x+s.width,s.y).lineTo(s.x+s.width,s.y+s.height).lineTo(s.x,s.y+s.height).lineTo(s.x,s.y)})}else if(this.borderStyle===14){let i=Bt(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&t.fillRect({...i,rx:4*e,ry:4*e,color:this.backgroundColor}),this.borderWidth&&t.strokeRect({...i,rx:4*e,ry:4*e,color:this.borderColor,lineWidth:this.borderWidth})}else this.borderStyle===15||console.warn(`Unsupported border style: ${this.borderStyle}`)}isAnyPvDisconnected(){let t=this.pvName&&(!this.pv||this.pv.disconnected),e=this.pvs.find(i=>i.disconnected)!==void 0;return t||e}isAnyPvInvalid(){let t=!1;for(let e of this.pvs)if(e.value===void 0){t=!0;break}return this.pvs.length&&t}drawDecoration(t){if(this.display.editMode)return;let{scale:e}=this;if(this.isAnyPvDisconnected()){let i=1*e;t.fillRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:this.display.disconnectedColor,opacity:.4}),t.strokeRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:this.display.disconnectedColor})}else this.isAnyPvInvalid()&&t.strokeRect({...this.bounds,dash:[2*e,2*e],lineWidth:2*e,color:this.display.invalidColor,crispen:!0});if(this.borderAlarmSensitive){let i;this.borderStyle===8?i=[2*e,2*e]:this.borderStyle===9?i=[6*e,2*e]:this.borderStyle===10?i=[6*e,2*e,2*e,2*e]:this.borderStyle===11&&(i=[6*e,2*e,2*e,2*e,2*e,2*e]),this.pv?.severity==="MAJOR"?t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.majorColor,crispen:!0,dash:i}):this.pv?.severity==="MINOR"?t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.minorColor,crispen:!0,dash:i}):this.pv?.severity==="INVALID"&&t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.invalidColor,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()}resolvePath(t){return this.display.resolvePath(t,this)}get bounds(){return{x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight}}get unscaledBounds(){return{x:this.properties.getValue(Ke),y:this.properties.getValue(je),width:this.properties.getValue(qe),height:this.properties.getValue(Xe)}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,r,s){let o=1*this.scale,n=this.holderY+o/2,a=this.holderX+o/2,l=this.holderY+this.holderHeight-o+o/2,h=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new R(h,l).lineTo(h,n).moveTo(h,l).lineTo(a,l)}),t.strokePath({color:i,path:new R(h-o,l-o).lineTo(h-o,n+o).moveTo(h-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new R(a,n).lineTo(h-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new R(a+o,n+o).lineTo(h-o-o,n+o).moveTo(a+o,n+o).lineTo(a+o,l-o-o)})}drawDashedBorder(t,e){let i=Bt(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new R(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()})}executeActionByIndex(t){let e=this.actions.getAction(t);e&&this.executeAction(e)}executeAction(t){t.execute(this)}expandMacro(t){if(t.indexOf("$")===-1)return t;for(let e of this.properties.all())if(e instanceof Dt){let i=this.properties.getProperty(e.pvPropertyName),r="",s=i?.value;s&&(r=this.display.getPV(s)?.value??""),t=t.replace(`$(${e.name})`,r),t=t.replace(`\${${e.name}}`,r)}else t=t.replace(`$(${e.name})`,e.value||""),t=t.replace(`\${${e.name}}`,e.value||"");return this.parent?this.parent.expandContainerMacros(t):t}loadFont(t){if(t.isWebSafe())return;let e=this.display.getFontResolver();if(!e){console.warn(`Failed to load font '${t.getFontString()}'.`);return}let i=e.resolve(t);if(!i){console.warn(`Failed to load font '${t.getFontString()}'.`);return}i.load().then(r=>{document.fonts.add(r),Pe[t.name]&&Vo(t.name),this.requestRepaint()}).catch(r=>{console.warn(`Failed to load font '${t.getFontString()}'.`,r)})}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){return this.pv?.severity==="MINOR"}isMajorSeverity(){return this.pv?.severity==="MAJOR"}get alarm(){return this.pv?.severity==="MINOR"||this.pv?.severity==="MAJOR"||this.pv?.severity==="INVALID"}get alarmSensitiveBackgroundColor(){if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor;if(this.pv?.severity==="INVALID")return this.display.invalidColor}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}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){let i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue(Qo)}get name(){return this.properties.getValue(Uo)}get holderX(){return this.scale*this.properties.getValue(Ke)}get holderY(){return this.scale*this.properties.getValue(je)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(qe)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(Xe)}get borderAlarmSensitive(){return this.properties.getValue(Do)}get backgroundAlarmSensitive(){return this.properties.getValue(Ho)}get foregroundAlarmSensitive(){return this.properties.getValue($o)}get pvName(){return this.properties.getValue(Ss,!0)}get pvValue(){return this.properties.getValue(Yo,!0)}get borderColor(){return this.properties.getValue(Wo)}get borderStyle(){return this.properties.getValue(No)}get borderWidth(){return this.scale*this.properties.getValue(ko)}get backgroundColor(){return this.properties.getValue(Bo)}get enabled(){return this.properties.getValue(Fo)}get foregroundColor(){return this.properties.getValue(Go)}get tooltip(){let t=this.properties.getProperty(Ko);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(jo)}get visible(){return this.properties.getValue(Zo)}get actions(){return this.properties.getValue(Io)}get scripts(){return this.properties.getValue(qo)}get rules(){return this.properties.getValue(zo)}get scaleOptions(){return this.properties.getValue(Xo)}autoScale(t,e){this.originBounds||(this.originBounds={x:this.properties.getValue(Ke),y:this.properties.getValue(je),width:this.properties.getValue(qe),height:this.properties.getValue(Xe)});let i=this.originBounds;this.properties.setValue(Ke,Math.round(i.x*t)),this.properties.setValue(je,Math.round(i.y*e));let{widthScalable:r,heightScalable:s}=this.scaleOptions;if(r||s){let{width:o,height:n}=bi(i,t,e,this.scaleOptions);this.properties.setValue(qe,o),this.properties.setValue(Xe,n)}}get widgetType(){return this.properties.getValue(Jo,!0)}get text(){return this.display.editMode?this.properties.getProperty(Ls).rawValue||"":this.properties.getValue(Ls)}init(){}hide(){}destroy(){}};var tn="description",et=class{properties;constructor(){this.properties=new we(null,[new T(tn,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(tn)}getDescription(){return this.description||this.getDefaultDescription()}getDefaultDescription(){return"Action"}};var en="command",rn="command_directory",sn="wait_time",Ri=class extends et{constructor(){super(),this.properties.add(new T(en,"")),this.properties.add(new T(rn,"$(user.home)")),this.properties.add(new P(sn,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(en)}get commandDirectory(){return this.properties.getValue(rn)}get waitTime(){return this.properties.getValue(sn)}getDefaultDescription(){return`Execute Command ${this.command}`}};var _i=class{BLACK=m.BLACK;BLUE=m.BLUE;CYAN=m.CYAN;DARK_GRAY=m.DARK_GRAY;GRAY=m.GRAY;GREEN=m.GREEN;LIGHT_BLUE=m.LIGHT_BLUE;ORANGE=m.ORANGE;PINK=m.PINK;PURPLE=m.PURPLE;RED=m.RED;WHITE=m.WHITE;YELLOW=m.YELLOW;getColorFromRGB(t,e,i){return new m(t,e,i)}getFont(t,e,i){return new Y(t,e,i,!1)}};var Ti=class{constructor(t){this.display=t}writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}};var Si=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var ae=class{constructor(t,e,i){this.code=t;this.interpolate=e;this.autoscale=i;t===0||(t===1?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):t===2?(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]]):t===3?(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]]):t===4?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):t===5?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):t===6&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}values=[];colors=[];entries=[];dirty=!0;addMapping(t,e,i,r){this.values.push(t),this.colors.push([e,i,r]),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,e===0)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){let[i,r]=this.entries[e-1],[s,o]=this.entries[e],n=(t-i)/(s-i),a=Math.floor((o[0]-r[0])*n+r[0]),l=Math.floor((o[1]-r[1])*n+r[1]),h=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,h]}else return this.entries[e-1][1]}getMinMax(){let t=Math.min.apply(Math,this.values),e=Math.max.apply(Math,this.values);return[t,e]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){let r=i+e>>1;if(t>this.entries[r][0])e=r+1;else if(t<this.entries[r][0])i=r-1;else return r}return-e-1}};var on="macros",st=class p extends M{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new oe(on))}expandContainerMacros(t){for(let e in this.macros.macros)t=t.replace(`$(${e})`,this.macros.macros[e]),t=t.replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(let e of this.widgets){if(e.wuid===t)return e;if(e instanceof p){let i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(let e of this.widgets){if(e.name===t)return e;if(e instanceof p){let i=e.findWidgetByName(t);if(i)return i}}for(let e of this.connections)if(e.name===t)return e}hide(){for(let t of this.widgets)t.hide()}autoScale(t,e){super.autoScale(t,e);for(let i of this.widgets)i.autoScale(t,e)}destroy(){for(let t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue(on)}};var Li=class{constructor(t,e){this.action=t;this.widget=e}getPropertyValue(t){let e=this.action.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){let i=this.action.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i instanceof T?(e=e!==void 0?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}};var Ci=class{constructor(t){this.array=t}get(t){return this.array[t]}};var $t=class{constructor(t){this._pv=t}listeners=new Map;getName(){return this._pv.name}getValue(){return this._pv.value??null}setValue(t,e){this._pv.pvEngine.setValue(new Date,this._pv.name,t)}isConnected(){return!this._pv.disconnected}isWriteAllowed(){return this._pv.writable}addListener(t){let e=()=>{t.valueChanged(this)};this.listeners.set(t,e),this._pv.addListener(e)}removeListener(t){let e=this.listeners.get(t);e&&(this._pv.removeListener(e),this.listeners.delete(t))}};var It=class p{constructor(t){this.widget=t}getWidget(){return this.widget}executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){let e=this.widget.display.getPV(t);return e?new $t(e):null}getPV(t="pv_name"){let e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getChild(t){if(this.widget instanceof st){let e=this.widget.widgets.find(i=>i.name===t);if(e)return new p(e)}return null}getHookedActions(){let t=this.widget.getHookedActions().map(e=>new Li(e,this.widget));return new Ci(t)}getVar(t){return this.widget.vars.get(t)??null}setVar(t,e){this.widget.vars.set(t,e)}getPropertyValue(t){let e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){let i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof T)e=e!==void 0?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof se){let r=0;switch(e){case"GrayScale":r=1;break;case"JET":r=2;break;case"ColorSpectrum":r=3;break;case"Hot":r=4;break;case"Cool":r=5;break;case"Shaded":r=6;break}let s=new ae(r,!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)}setEnabled(t){this.setPropertyValue("enabled",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){return this.widget.value??null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}};var Ai=class extends It{constructor(e){super(e);this.array=e}getArrayFigure(){return{getIndex:()=>this.array.getScrollIndex(),setIndex:e=>this.array.setScrollIndex(e),getArrayLength:()=>this.array.effectiveArrayLength}}getIndex(e){return this.array.widgets.indexOf(e.getWidget())}getArrayLength(){return this.array.effectiveArrayLength}setArrayLength(e){this.array.properties.setValue("array_length",e)}getDataType(){return this.array.dataType}setDataType(e){this.array.properties.setValue("data_type",e)}isHorizontal(){return this.array.horizontal}isShowSpinner(){return this.array.showSpinner}isShowScrollbar(){return this.array.showScrollbar}getSpinnerWidth(){return this.array.spinnerWidth}getVisibleElementsCount(){return this.array.vec}};var Oi=class{constructor(t,e){this.spreadsheet=t;this.scriptEngine=e}addModifiedListener(t){}addSelectionChangedListener(t){this.spreadsheet.addSelectionChangedListener(()=>{this.scriptEngine.schedule(()=>{let e=t.selectionChanged;e(this.spreadsheet.getSelection())})})}appendRow(){return this.spreadsheet.appendRow()}deleteColumn(t){this.spreadsheet.deleteColumn(t)}deleteRow(t){this.spreadsheet.deleteRow(t)}getCellText(t,e){return this.spreadsheet.getCellText(t,e)}getColumnCount(){return this.spreadsheet.getColumnCount()}getContent(){return this.spreadsheet.getContent()}getRowCount(){return this.spreadsheet.getRowCount()}getSelection(){return this.spreadsheet.getSelection()}insertColumn(t){this.spreadsheet.insertColumn(t)}insertRow(t){this.spreadsheet.insertRow(t)}isEmpty(){return this.spreadsheet.isEmpty()}refresh(){this.spreadsheet.refresh()}setCellBackground(t,e,i){this.spreadsheet.setCellBackground(t,e,i)}setCellForeground(t,e,i){this.spreadsheet.setCellForeground(t,e,i)}setCellText(t,e,i){this.spreadsheet.setCellText(t,e,i)}setColumnCellEditorData(t,e){this.spreadsheet.setColumnCellEditorData(t,e)}setColumnsCount(t){this.spreadsheet.setColumnsCount(t)}setContent(t){this.spreadsheet.setContent(t)}setRowBackground(t,e){this.spreadsheet.setRowBackground(t,e)}setRowForeground(t,e){this.spreadsheet.setRowForeground(t,e)}revealRow(t){}};var Ei=class extends It{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new Oi(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var Mi=class extends It{xyGraph;constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map(i=>i.x)}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map(i=>i.y)}};function Vi(p,t){switch(p.widgetType){case"Array":return new Ai(p);case"Table":return new Ei(p,t);case"XY Graph":return new Mi(p);default:return new It(p)}}var Ii=class{constructor(t,e){this.display=t;this.scriptEngine=e}isActive(){return!0}getWidget(t){let e=this.display.findWidgetByName(t);if(e)return Vi(e,this.scriptEngine)}};var Bi=class{constructor(t){this.display=t}readTextFile(t){let e=this.display.resolvePath(t);var i=new XMLHttpRequest;if(i.open("GET",e,!1),i.send(null),i.status===200)return i.responseText;throw Error(`Cannot open ${e}`)}};var Hi=class{constructor(t){this.display=t}fullScreen(){document.documentElement.requestFullscreen()}openConfirmDialog(t){return this.display.getDialogHandler().openConfirmDialog("Confirm Dialog",t)}openInformationDialog(t){this.display.getDialogHandler().openInformationDialog("Information",t)}openWarningDialog(t){this.display.getDialogHandler().openWarningDialog("Warning",t)}openErrorDialog(t){this.display.getDialogHandler().openErrorDialog("Error",t)}openPasswordDialog(t,e){return this.display.getDialogHandler().openPasswordDialog("Password Input Dialog",t,e)}};var Di=class{constructor(t){this.display=t}openInformation(t,e,i){this.display.getDialogHandler().openInformationDialog(e,i)}openConfirm(t,e,i){return this.display.getDialogHandler().openConfirmDialog(e,i)}openError(t,e,i){this.display.getDialogHandler().openErrorDialog(e,i)}};var hx=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],Wi=class{constructor(t){this.display=t;this.pvEngine=t.pvEngine}pvEngine;checkPVValue(t){if(t.getValue()===null)throw new Error(`PV ${t.getName()} has no value.`)}createPV(t,e){let i=this.pvEngine.createPV(t);return new $t(i)}writePV(t,e,i){this.pvEngine.createPV(t),this.pvEngine.setValue(new Date,t,e)}getDouble(t){this.checkPVValue(t);let e=t._pv.toNumber();return parseFloat(e??t.getValue())}getDoubleArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>parseFloat(i)):[parseFloat(e)]}getLong(t){this.checkPVValue(t);let e=t._pv.toNumber();return typeof e=="number"&&(e=Math.floor(e)),parseInt(e??t.getValue(),10)}getLongArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>(typeof i=="number"&&(i=Math.floor(i)),parseInt(i,10))):(typeof e=="number"&&(e=Math.floor(e)),[parseInt(e,10)])}getString(t){return this.checkPVValue(t),me(t._pv.value,0,-1,t._pv.typeHint)}getStringArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>String(i)):[String(e)]}getTimeInMilliseconds(t){return this.checkPVValue(t),t._pv.time?.getTime()??0}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){this.checkPVValue(t);let i=t._pv.time;if(i){let r=e;for(let s of hx)r=r.replace(s,this.formatDate(i,s));return r}return null}getSeverity(t){switch(this.checkPVValue(t),t._pv.severity){case"NONE":return 0;case"MAJOR":return 1;case"MINOR":return 2;default:return-1}}getSeverityString(t){return this.checkPVValue(t),String(t._pv.severity)}getStatus(t){return this.checkPVValue(t),t._pv.alarmName}getUnits(t){return this.checkPVValue(t),t._pv.units||null}formatDate(t,e){let{utc:i}=this.display;if(e==="yyyy")return String(i?t.getUTCFullYear():t.getFullYear());if(e==="MM"){let r=(i?t.getUTCMonth():t.getMonth())+1;return r<10?"0"+r:""+r}else if(e==="dd"){let r=i?t.getUTCDate():t.getDate();return r<10?"0"+r:""+r}else if(e==="HH"){let r=i?t.getUTCHours():t.getHours();return r<10?"0"+r:""+r}else if(e==="mm"){let r=i?t.getUTCMinutes():t.getMinutes();return r<10?"0"+r:""+r}else if(e==="ss"){let r=i?t.getUTCSeconds():t.getSeconds();return r<10?"0"+r:""+r}else if(e==="nnnnnnnnn"){let r=i?t.getUTCMilliseconds():t.getMilliseconds();return r<10?"00"+r:r<100?"0"+r:""+r}else throw new Error(`Unexpected format '${e}'`)}};var ki=class{constructor(t){this.display=t}openOPI(t,e,i,r){if(i===0){let s={path:e,replace:i===0};this.display.fireEvent("opendisplay",s)}else throw new Error(`Unsupported target ${i}`)}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}};function nn(p){let t=p.widget,e=p.widget.display,i=function(h){this.run=h.run},r=function(h){this.runnable=h};r.prototype.start=function(){p.schedule(()=>this.runnable.run())},r.sleep=function(h){let c=Date.now(),d=0;for(;Date.now()<c+h;)d++;d||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(h,c){p.schedule(h,c)};let o=function(h){this.valueChanged=c=>{p.schedule(()=>{let d=h.valueChanged;d(c)})}},l={ITableModifiedListener:function(h){this.modified=c=>{let d=h.modified;d(c)}},ITableSelectionChangedListener:function(h){this.selectionChanged=c=>{let d=h.selectionChanged;d(c)}}};return{display:new Ii(t.display,p),widget:Vi(t,p),java:{lang:{Runnable:i,Thread:r},util:{Timer:s}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:l}}}},yamcs:{studio:{data:{IPVListener:o}}}},ColorFontUtil:new _i,ConsoleUtil:new Ti(e),DataUtil:new Si,FileUtil:new Bi(e),GUIUtil:new Hi(e),MessageDialog:new Di(e),PVUtil:new Wi(e),ScriptUtil:new ki(e),SpreadSheetTable:l,Java:{type:function(h){switch(h){case"java.lang.Runnable":return i;case"java.lang.Thread":return r;case"java.util.Timer":return s;case"org.csstudio.swt.widgets.natives.SpreadSheetTable":return l;case"org.yamcs.studio.data.IPVListener":return o;default:throw new Error("Unexpected class name: "+h)}},to:function(h,c){return h}}}}var Ut=class{constructor(t,e,i=[]){this.widget=t;this.scriptText=e;this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context={pvs:i.map(r=>new $t(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...nn(this)}}context;run(t){window.setTimeout(()=>{if(this.context.triggerPV=null,t)for(let e of this.context.pvs)e._pv===t&&(this.context.triggerPV=e);this.runWithContext(()=>{(0,eval)(this.scriptText)})})}schedule(t,e){window.setTimeout(()=>this.runWithContext(t),e)}runWithContext(t){let e=[];for(let i in window)e.push(i);try{for(let r in this.context)this.context.hasOwnProperty(r)&&(window[r]=this.context[r]);t();let i={};for(let r in window)e.indexOf(r)===-1&&(i[r]=window[r]);this.context=i}finally{for(let i in window)e.indexOf(i)===-1&&delete window[i]}}};var an="path",ln="embedded",hn="scriptText",Ni=class extends et{constructor(){super(),this.properties.add(new T(an,"")),this.properties.add(new f(ln,!1)),this.properties.add(new T(hn,""))}execute(t){this.embedded?new Ut(t,this.scriptText).run():t.display.getScriptLoader().load(this.path).then(i=>{i&&new Ut(t.display.instance,i).run()})}get path(){return this.properties.getValue(an)}get embedded(){return this.properties.getValue(ln)}get scriptText(){return this.properties.getValue(hn)}getDefaultDescription(){return"Execute JavaScript"}};var cn="macros",pn="mode",dn="path",Fi=class extends et{constructor(){super(),this.properties.add(new T(dn,"")),this.properties.add(new oe(cn)),this.properties.add(new P(pn,0))}execute(t){let e={...this.macros.macros},i={path:this.path,replace:this.mode===0,args:e};t.display.fireEvent("opendisplay",i)}get macros(){return this.properties.getValue(cn)}get path(){return this.properties.getValue(dn)}get mode(){return this.properties.getValue(pn)}getDefaultDescription(){return`Open ${this.path}`}};var un="path",Gi=class extends et{constructor(){super(),this.properties.add(new T(un,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(un)}getDefaultDescription(){return`Open ${this.path}`}};var gn="hyperlink",$i=class extends et{constructor(){super(),this.properties.add(new T(gn,"http://"))}execute(t){this.hyperlink&&window.parent.postMessage({type:"openwebpage",url:this.hyperlink},"*")}get hyperlink(){return this.properties.getValue(gn)}getDefaultDescription(){return`Open Webpage ${this.hyperlink}`}};var mn="path",Ui=class extends et{constructor(){super(),this.properties.add(new T(mn,""))}execute(t){this.path&&new Audio(t.display.resolvePath(this.path)).play()}get path(){return this.properties.getValue(mn)}getDefaultDescription(){return`Play WAV File ${this.path}`}};var fn="command",wn="args",xn="confirm_message",Yi=class extends et{constructor(){super(),this.properties.add(new T(fn,"")),this.properties.add(new ne(wn,{})),this.properties.add(new T(xn,""))}execute(t){if(this.confirmMessage&&!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return;let e=t.expandMacro(this.command),i={};for(let s in this.args)i[s]=t.expandMacro(this.args[s]);let r={command:e,args:i};t.display.fireEvent("runcommand",r)}get command(){return this.properties.getValue(fn)}get args(){return this.properties.getValue(wn)}get confirmMessage(){return this.properties.getValue(xn)}getDefaultDescription(){return`Run ${this.command}`}};var yn="procedure",Pn="args",bn="confirm_message",zi=class extends et{constructor(){super(),this.properties.add(new T(yn,"")),this.properties.add(new ne(Pn,{})),this.properties.add(new T(bn,""))}execute(t){if(this.confirmMessage&&!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return;let e={procedure:this.procedure,args:this.args};t.display.fireEvent("runprocedure",e)}get procedure(){return this.properties.getValue(yn)}get args(){return this.properties.getValue(Pn)}get confirmMessage(){return this.properties.getValue(bn)}getDefaultDescription(){return`Run ${this.procedure}`}};var vn="path",Rn="confirm_message",Xi=class extends et{constructor(){super(),this.properties.add(new T(vn,"")),this.properties.add(new T(Rn,""))}execute(t){if(this.confirmMessage&&!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return;let i={path:t.display.resolvePath(this.path)};t.display.fireEvent("runstack",i)}get path(){return this.properties.getValue(vn)}get confirmMessage(){return this.properties.getValue(Rn)}getDefaultDescription(){return`Run ${this.path}`}};var _n="pv_name",Tn="value",Sn="timeout",Ln="confirm_message",qi=class extends et{constructor(){super(),this.properties.add(new T(_n,"$(pv_name)")),this.properties.add(new T(Tn,"")),this.properties.add(new P(Sn,10)),this.properties.add(new T(Ln,""))}execute(t){if(!(this.confirmMessage&&!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))&&this.pvName){let e=t.expandMacro(this.pvName);t.display.pvEngine.createPV(e),t.display.pvEngine.setValue(new Date,e,this.value)}}get pvName(){return this.properties.getValue(_n)}get value(){return this.properties.getValue(Tn)}get timeout(){return this.properties.getValue(Sn)}get confirmMessage(){return this.properties.getValue(Ln)}getDefaultDescription(){return`Write ${this.value} to ${this.pvName}`}};var Ki=class{includeParentMacros=!0;macros={};clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}};var Te=class p{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){let i=new DOMParser().parseFromString(t,"text/xml");return new p(i.documentElement)}getNode(t){let e=this.findChild(t);return new p(e)}getNodes(t){let e=[];for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];r.nodeType!==3&&(!t||r.nodeName===t)&&e.push(new p(r))}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 i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return r.textContent}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseFloat(r.textContent)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseInt(r.textContent,10)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t)return r.textContent==="true"}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){let i=this.node.attributes.getNamedItem(t);if(i===null){if(e!==void 0)return e;throw new Error(`No attribute named ${t}`)}else return i.textContent==="true"}getColor(t,e){let i=this.findChild(t);for(let r=0;r<i.childNodes.length;r++){let s=i.childNodes[r];if(s.nodeName==="color")return this.parseColorNode(new p(s))}if(e!==void 0)return e;throw new Error("No child node named 'color' could be found")}getFont(t){let e=this.getNode(t);if(e.hasNode("opifont.name")){let i=e.getNode("opifont.name"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new Y(r,s,o,n)}else{let i=e.getNode("fontdata"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new Y(r,s,o,n)}}getPoints(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("point"))i.push({x:r.getIntAttribute("x"),y:r.getIntAttribute("y")});return i}getStringList(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("s"))i.push(r.getTextContent());return i}getStringMap(t){let e=this.getNode(t),i={};for(let r of e.getNodes())i[r.name]=e.getString(r.name);return i}getStringTable(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("row")){let s=[];for(let o of r.getNodes("col"))s.push(o.getTextContent());i.push(s)}return i}getMatrix(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("row")){let s=[];for(let o of r.getNodes("col"))s.push(Number(o.getTextContent()));i.push(s)}return i}getScripts(t){let e=this.getNode(t),i=new _e;for(let r of e.getNodes("path")){let s=[];for(let n of r.getNodes("pv"))s.push({pvName:n.getTextContent(),trigger:n.getBooleanAttribute("trig")});let o=r.getStringAttribute("pathString");o==="EmbeddedJs"?i.scripts.push({embedded:!0,text:r.getString("scriptText"),checkConnect:r.getBooleanAttribute("checkConnect"),skipFirstExecution:r.getBooleanAttribute("sfe",!1),inputs:s}):o==="EmbeddedPy"?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:o,checkConnect:r.getBooleanAttribute("checkConnect"),skipFirstExecution:r.getBooleanAttribute("sfe",!1),inputs:s})}return i}getScaleOptions(t){let e=this.getNode(t);return new J(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new Re(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){let e=this.getNode(t);if(e.hasNode("e")){let i=new ae(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(let r of e.getNodes("e")){let s=Number(r.getTextContent()),o=r.getIntAttribute("red"),n=r.getIntAttribute("green"),a=r.getIntAttribute("blue");i.addMapping(s,o,n,a)}}else return new ae(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"))}getRules(t){let e=this.getNode(t),i=new ve;for(let r of e.getNodes("rule")){let s=[];for(let n of r.getNodes("pv"))s.push({pvName:n.getTextContent(),trigger:n.getBooleanAttribute("trig")});let o=[];for(let n of r.getNodes("exp"))if(n.getNode("value").hasNode("color"))o.push({type:"color",expression:n.getStringAttribute("bool_exp"),outputValue:n.getColor("value")});else{let l=n.getString("value");l.trim()!==""&&o.push({type:"string",expression:n.getStringAttribute("bool_exp"),outputValue:l})}i.rules.push({name:r.getStringAttribute("name"),propertyName:r.getStringAttribute("prop_id"),outputExpression:r.getBooleanAttribute("out_exp"),inputs:s,expressions:o})}return i}getMacros(t){let e=this.getNode(t),i=new Ki;i.includeParentMacros=e.getBoolean("include_parent_macros");for(let r of e.getNodes())r.name!=="include_parent_macros"&&i.set(r.name,e.getString(r.name));return i}getActions(t){let e=this.getNode(t),i=new ye;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(let r of e.getNodes("action")){let s=r.getStringAttribute("type");if(s==="OPEN_DISPLAY"){let o=new Fi;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new Gi;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new Ri;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_JAVASCRIPT"){let o=new Ni;o.parseNode(r),i.add(o)}else if(s==="WRITE_PV"){let o=new qi;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new Ui;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new $i;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new Yi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new Xi;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new zi;o.parseNode(r),i.add(o)}else console.warn(`Unsupported action type ${s}`),i.add(null)}return i}parseColorNode(t){let e=t.getIntAttribute("red"),i=t.getIntAttribute("green"),r=t.getIntAttribute("blue");return new m(e,i,r)}cloneWithOverrides(t){let e=this.node.cloneNode(!0);if(t.pvName!==void 0)for(let i of Array.from(e.querySelectorAll("pv_name")))i.textContent=t.pvName;if(t.wuidSuffix)for(let i of Array.from(e.querySelectorAll("wuid")))i.textContent=(i.textContent||"")+t.wuidSuffix;return new p(e)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){let i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}};var Cn="arrow_length",An="arrows",On="fill_arrow",En="name",Mn="line_color",Vn="line_jump_add",In="line_jump_size",Bn="line_jump_style",Hn="line_style",Dn="line_width",Wn="src_wuid",kn="src_term",Nn="tgt_wuid",Fn="tgt_term",Gn="router",$n="points",cx="wuid",Un=0,px=1,dx=2,Yn=0;var ux=2,gx=3,mx=.577350269,Yt="LEFT",zt="UP",Xt="DOWN",qt="RIGHT",Zi=class extends M{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(Cn)),this.properties.add(new P(An)),this.properties.add(new f(On)),this.properties.add(new T(En)),this.properties.add(new S(Mn)),this.properties.add(new P(Vn,Un)),this.properties.add(new P(In,10)),this.properties.add(new P(Bn,Yn)),this.properties.add(new P(Hn)),this.properties.add(new P(Dn)),this.properties.add(new T(Wn)),this.properties.add(new T(kn)),this.properties.add(new T(Nn)),this.properties.add(new T(Fn)),this.properties.add(new P(Gn)),this.properties.add(new Wt($n)),this.properties.add(new T(cx))}async 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):this.router===0?this.drawManhattanConnection(t):this.router===1&&this.drawDirectConnection(t))}drawPath(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),r=[e,...this.points,i],s=r.length-1,o=[...r];(this.arrows===1||this.arrows===3)&&(o[0]=this.getShaftEnd(r[1],r[0])),(this.arrows===2||this.arrows===3)&&(o[s]=this.getShaftEnd(r[s-1],r[s]));let n=ht(o,.5*this.scale,.5*this.scale);this.strokeJumpAwarePath(t,n,this.getDashArray()),this.drawStartArrow(t,r[1],r[0]),this.drawStopArrow(t,r[s-1],r[s])}drawManhattanConnection(t){let e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),r=this.route(e,i),s=r.length-1,o=[...r];(this.arrows===1||this.arrows===3)&&(o[s]=this.getShaftEnd(r[s-1],r[s])),(this.arrows===2||this.arrows===3)&&(o[0]=this.getShaftEnd(r[1],r[0])),this.lineWidth&&this.strokeJumpAwarePath(t,o,this.getDashArray()),this.drawStartArrow(t,r[s-1],r[s]),this.drawStopArrow(t,r[1],r[0])}getShaftEnd(t,e){return this.fillArrow?this.calculateArrowPoints(t,e)[2]:e}getDashArray(){let{scale:t}=this;if(this.lineWidth){if(this.lineStyle===0)return[];if(this.lineStyle===1)return[6*t,2*t];if(this.lineStyle===2)return[2*t,2*t];if(this.lineStyle===3)return[6*t,2*t,2*t,2*t];if(this.lineStyle===4)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}getVertices(){if(!this.sourceWidget||!this.targetWidget)return[];if(this.points.length){let t=this.getPosition(this.sourceWidget,this.sourceTerm),e=this.getPosition(this.targetWidget,this.targetTerm);return[t,...this.points,e]}else if(this.router===0){let t=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),e=this.getManhattanAnchor(this.targetWidget,this.targetTerm);return this.route(t,e)}else if(this.router===1){let t=this.getPosition(this.sourceWidget,this.sourceTerm),e=this.getPosition(this.targetWidget,this.targetTerm);return[t,e]}return[]}strokeJumpAwarePath(t,e,i){if(this.lineJumpAdd===Un||e.length<2){t.strokePath({path:R.fromPoints(e),lineWidth:this.lineWidth,color:this.lineColor,dash:i});return}for(let r of this.buildJumpAwareRuns(e))r.length<2||t.strokePath({path:R.fromPoints(r),lineWidth:this.lineWidth,color:this.lineColor,dash:i})}buildJumpAwareRuns(t){let e=[],i=[];for(let o of this.display.instance?.connections??[])o!==this&&i.push(o.getVertices());let r=[t[0]],s=0;for(;s+1<t.length;){let o=t[s],n=s+1,a=t[n],l=n+1;for(;l<t.length;){let h=t[l];if(h.x===o.x||h.y===o.y)a=h,n=l,l++;else break}for(let h of this.findCrossings(o,a,i))switch(r.push(h.notch1),this.lineJumpStyle){case Yn:r.push(...xx(h.point,this.lineJumpSize,[h.notch1,h.notch2])),r.push(h.notch2);break;case ux:r.push(...wx(h.notch1,h.notch2),h.notch2);break;case gx:r.push(fx(h.notch1,h.notch2),h.notch2);break;default:e.push(r),r=[h.notch2]}r.push(a),s=n}return e.push(r),e}findCrossings(t,e,i){let r=t.y===e.y,s=t.x===e.x;if(r&&this.lineJumpAdd!==px)return[];if(s&&this.lineJumpAdd!==dx)return[];if(!r&&!s)return[];let o=this.lineJumpSize,n=t.x,a=t.y,l=e.x,h=e.y,c=[];for(let d of i)for(let g=0;g+1<d.length;g++){let w=d[g],x=d[g+1],_=w.x,L=w.y,A=x.x,E=x.y,I=(n-l)*(L-E)-(a-h)*(_-A);if(I===0)continue;let k={x:((n*h-a*l)*(_-A)-(n-l)*(_*E-L*A))/I,y:((n*h-a*l)*(L-E)-(a-h)*(_*E-L*A))/I};if(Fe(k,t)<o||Fe(k,e)<o||!ji(k,t,e)||!ji(k,w,x))continue;let F=zn(k,t,o),z=zn(k,e,o);c.push({point:k,notch1:ji(F,t,e)?F:t,notch2:ji(z,t,e)?z:e,distance:Fe(t,k)})}return c.sort((d,g)=>d.distance-g.distance),c}drawDirectConnection(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);if(this.lineWidth){let r=e,s=i;(this.arrows===1||this.arrows===3)&&(r=this.getShaftEnd(i,e)),(this.arrows===2||this.arrows===3)&&(s=this.getShaftEnd(e,i)),this.strokeJumpAwarePath(t,[r,s],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=zt;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=Xt;break;case"LEFT":i=Yt;break;case"RIGHT":i=qt;break;default:}let r=t.bounds,s=this.getPosition(t,e),o=s.x-r.x,n=r.x+r.width-s.x,a=s.y-r.y,l=r.y+r.height-s.y;return Math.min(o,n)<Math.min(a,l)?i=o<n?Yt:qt:i=a<l?zt:Xt,{x:s.x,y:s.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:let i=parseInt(e,10),r=t.properties.getProperty("points");if(r){let s=r.value;return s=re(s,this.scale),s[i]}else throw Error(`Unexpected term ${e}`)}}route(t,e){let i=t.x-e.x,r=t.y-e.y,s={x:0,y:0},o,n,a=[],{tolxtol:l,tol:h,minDist:c}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===Yt?i>0&&r*r<h&&e.direction===qt?(s=e,o=e.direction):(i<0?s={x:t.x-c,y:t.y}:r>0&&e.direction===Xt||r<0&&e.direction===zt?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.min(t.x,e.x)-c,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=zt:o=Xt):t.direction===qt?i<0&&r*r<h&&e.direction===Yt?(s=e,o=e.direction):(i>0?s={x:t.x+c,y:t.y}:r>0&&e.direction===Xt||r<0&&e.direction===zt?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.max(t.x,e.x)+c,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=zt:o=Xt):t.direction===Xt?i*i<h&&r<0&&e.direction===zt?(s=e,o=e.direction):(r>0?s={x:t.x,y:t.y+c}:i>0&&e.direction===qt||i<0&&e.direction===Yt?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.max(t.y,e.y)+c,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Yt:o=qt):t.direction===zt&&(i*i<h&&r>0&&e.direction===Xt?(s=e,o=e.direction):(r<0?s={x:t.x,y:t.y-c}:i>0&&e.direction===qt||i<0&&e.direction===Yt?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.min(t.y,e.y)-c,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Yt:o=qt));let d={...s,direction:o};return a=a.concat(this.route(d,e)),a.push(t),a}drawStartArrow(t,e,i){let r=t.ctx;if(this.arrows===1||this.arrows===3){let s=this.calculateArrowPoints(e,i);if(s[2]=i,this.fillArrow){r.fillStyle=this.lineColor.toString(),r.beginPath();for(let o=0;o<s.length;o++)o===0?r.moveTo(s[o].x,s[o].y):r.lineTo(s[o].x,s[o].y);r.fill()}else r.strokeStyle=this.lineColor.toString(),r.lineWidth=this.lineWidth,r.beginPath(),r.moveTo(i.x,i.y),r.lineTo(s[0].x,s[0].y),r.moveTo(i.x,i.y),r.lineTo(s[1].x,s[1].y),r.stroke()}}drawStopArrow(t,e,i){let r=t.ctx;if(this.arrows===2||this.arrows===3){let s=this.calculateArrowPoints(e,i);if(s[2]=i,this.fillArrow){r.fillStyle=this.lineColor.toString(),r.beginPath();for(let o=0;o<s.length;o++)o===0?r.moveTo(s[o].x,s[o].y):r.lineTo(s[o].x,s[o].y);r.fill()}else r.strokeStyle=this.lineColor.toString(),r.lineWidth=this.lineWidth,r.beginPath(),r.moveTo(i.x,i.y),r.lineTo(s[0].x,s[0].y),r.moveTo(i.x,i.y),r.lineTo(s[1].x,s[1].y),r.stroke()}}calculateArrowPoints(t,e){let i=mi(e,t),r=Math.PI/10,s=new _t(this.arrowLength,i.theta-r),o=new _t(this.arrowLength,i.theta+r),n=new _t(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=Ht(s.toPoint(),e.x,e.y),l=Ht(o.toPoint(),e.x,e.y),h=Ht(n.toPoint(),e.x,e.y);return[a,l,h]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(En)}get arrows(){return this.properties.getValue(An)}get fillArrow(){return this.properties.getValue(On)}get arrowLength(){return this.scale*this.properties.getValue(Cn)}get lineColor(){return this.properties.getValue(Mn)}get lineJumpAdd(){return this.properties.getValue(Vn)}get lineJumpSize(){return this.scale*this.properties.getValue(In)}get lineJumpStyle(){return this.properties.getValue(Bn)}get lineStyle(){return this.properties.getValue(Hn)}get lineWidth(){return this.scale*this.properties.getValue(Dn)}get router(){return this.properties.getValue(Gn)}get sourceTerm(){return this.properties.getValue(kn)}get sourceWuid(){return this.properties.getValue(Wn)}get targetTerm(){return this.properties.getValue(Fn)}get targetWuid(){return this.properties.getValue(Nn)}get points(){return re(this.properties.getValue($n),this.scale)}};function ji(p,t,e,i=1e-6){return p.x>=Math.min(t.x,e.x)-i&&p.x<=Math.max(t.x,e.x)+i&&p.y>=Math.min(t.y,e.y)-i&&p.y<=Math.max(t.y,e.y)+i}function zn(p,t,e){let i=Fe(p,t);if(Math.round(i)===0)return t;let r=e/i;return{x:(1-r)*p.x+r*t.x,y:(1-r)*p.y+r*t.y}}function Xn(p,t,e){let i=t.x-p.x,r=t.y-p.y,s=Math.sqrt(i*i+r*r);if(s===0)return{x:p.x,y:p.y};let o=i/s,n=r/s,a=Math.sqrt(3)/2*s,l=p.x+i*.5,h=p.y+r*.5,c=-n,d=o;return e?{x:l+a*c,y:h+a*d}:{x:l-a*c,y:h-a*d}}function fx(p,t){let e=Xn(p,t,!0);return e.x>p.x?Xn(p,t,!1):e}function wx(p,t){let e=mx,i=p.x-e*(t.y-p.y),r=p.y-e*(t.x-p.x);Math.abs(p.x-t.x)<5&&i>p.x&&(i=p.x-Math.abs(p.x-i)),Math.abs(p.y-t.y)<5&&r>p.y&&(r=p.y-Math.abs(p.y-r));let s=t.x+e*(p.y-t.y),o=t.y+e*(p.x-t.x);return Math.abs(p.x-t.x)<5&&s>t.x&&(s=t.x-Math.abs(t.x-s)),Math.abs(p.y-t.y)<5&&o>t.y&&(o=t.y-Math.abs(t.y-o)),[{x:i,y:r},{x:s,y:o}]}function xx(p,t,[e,i],r=16){let s=e.y===i.y,o,n;if(s){let l=e.x<i.x;o=l?Math.PI:2*Math.PI,n=l?2*Math.PI:Math.PI}else{let l=e.y<i.y;o=l?Math.PI/2:3*Math.PI/2,n=l?3*Math.PI/2:Math.PI/2}let a=[];for(let l=1;l<r;l++){let h=o+(n-o)*l/r;a.push({x:p.x+t*Math.cos(h),y:p.y+t*Math.sin(h)})}return a}var Zn="x",Jn="y",As="width",Os="height",yx="visible",qn="fill_grids",Kn="grid_gap",jn="number_of_columns",Ze=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(Zn,0)),this.properties.add(new P(Jn,0)),this.properties.add(new P(As,16)),this.properties.add(new P(Os,16)),this.properties.add(new f(yx,!1)),this.properties.add(new P(jn,3)),this.properties.add(new f(qn,!1)),this.properties.add(new P(Kn,2))}get numberOfColumns(){return this.properties.getValue(jn)}get fillGrids(){return this.properties.getValue(qn)}get gridGap(){return this.properties.getValue(Kn)}draw(t){}};function Ji(p){let t=p.findIndex(d=>d instanceof Ze);if(t===-1)return;let e=p[t];if(!e.enabled)return;let i=p.filter((d,g)=>g!==t);if(!i.length)return;let r=Math.max(1,e.numberOfColumns||1),s=Math.ceil(i.length/r),o=e.gridGap,n=e.fillGrids,a=new Array(r).fill(0),l=new Array(s).fill(0);i.forEach((d,g)=>{let w=g%r,x=Math.floor(g/r);a[w]=Math.max(a[w],d.properties.getValue(As)),l[x]=Math.max(l[x],d.properties.getValue(Os))});let h=[0];for(let d=1;d<r;d++)h.push(h[d-1]+a[d-1]+o);let c=[0];for(let d=1;d<s;d++)c.push(c[d-1]+l[d-1]+o);i.forEach((d,g)=>{let w=g%r,x=Math.floor(g/r);d.properties.setValue(Zn,h[w]),d.properties.setValue(Jn,c[x]),n&&(d.properties.setValue(As,a[w]),d.properties.setValue(Os,l[x]))})}var Px=0,Qn="auto_scale_widgets",bx="width",vx="height",Se=class extends st{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new ze(Qn,new Re(!1,-1,-1)))}async parseNode(t){await super.parseNode(t);let e=Px++;this.macros.set("DID",`DID_${e}`);let i=this.properties.getValue("name");this.macros.set("DNAME",i);for(let r in this.displayArgs)this.macros.set(r,this.displayArgs[r]);for(let r of t.getNodes("widget")){let s=r.getString("widget_type"),o=this.display.createWidget(s,this);o&&(await o.parseNode(r),this.widgets.push(o))}Ji(this.widgets);for(let r of t.getNodes("connection")){let s=new Zi(this.display);s.parseNode(r),this.connections.push(s)}}draw(t){for(let e of this.widgets.filter(i=>i.visible))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(let e of this.connections)e.draw(t);for(let e of this.widgets.filter(i=>i.visible))e.drawOverlay(t)}measureContentBounds(t){let e=this.widgets.filter(n=>n.visible);if(e.length===0)return{x:0,y:0,width:0,height:0};let i=1/0,r=1/0,s=-1/0,o=-1/0;for(let n of e){let a=t?n.bounds:n.unscaledBounds;i=Math.min(i,a.x),r=Math.min(r,a.y),s=Math.max(s,a.x+a.width),o=Math.max(o,a.y+a.height)}return{x:i,y:r,width:s-i,height:o-r}}get autoScaleWidgets(){return this.properties.getValue(Qn)}get designSize(){return{width:this.properties.getValue(bx),height:this.properties.getValue(vx)}}};var Rx=0,ta="group_name",Es="opi_file",ea="resize_behaviour",Le=class extends st{linkedDisplay;resolvedOpiFile;reloadGeneration=0;constructor(t,e){super(t,e),this.properties.add(new T(ta)),this.properties.add(new T(Es)),this.properties.add(new P(ea,0))}async parseNode(t){await super.parseNode(t);let e=Rx++;this.macros.set("LCID",`LCID_${e}`)}async init(){await this.reload(),this.addPropertyListener(Es,()=>this.reload())}async reload(){let t=++this.reloadGeneration;if(this.linkedDisplay&&(this.display.pvEngine.removeWidget(this.linkedDisplay),this.linkedDisplay.destroy(),this.linkedDisplay=void 0),this.opiFile){this.resolvedOpiFile=this.display.resolvePath(this.opiFile);let e=await this.display.loadContent(this.opiFile);if(t!==this.reloadGeneration)return;if(e!==null){let i=new Se(this.display,this),r=Te.parseFromXML(e);if(await i.parseNode(r),t!==this.reloadGeneration){this.display.pvEngine.removeWidget(i),i.destroy();return}this.linkedDisplay=i}}else this.resolvedOpiFile=void 0;if(this.linkedDisplay&&this.resizeBehavior===1){let e=this.measureFrameBounds(!0);this.customSize={width:e.width,height:e.height}}this.requestRepaint()}draw(t){this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect({...this.area,color:this.linkedDisplay.backgroundColor}),this.resizeBehavior===0){let i=this.measureFrameBounds(!1),{width:r,height:s}=i,o=this.display.scale;r*=o,s*=o;let n=r/s,a=this.width,l=a/n,h=a/r;l>this.height&&(l=this.height,a=l*n,h=l/s),this.linkedDisplay.relativeScale=h;let c=t.createChildAt(this.x,this.y,a,l);c.translate(-i.x*h*o,-i.y*h*o),this.drawLinkedContent(c),t.copyChild(c)}else if(this.resizeBehavior===1){let i=this.measureFrameBounds(!0),r=t.createChildAt(this.x,this.y,i.width,i.height);r.translate(-i.x,-i.y),this.drawLinkedContent(r),t.copyChild(r)}else if(this.resizeBehavior===2){let i=this.measureFrameBounds(!0),r=t.createChildAt(this.x,this.y,i.width,i.height);r.translate(i.x,i.y),this.drawLinkedContent(r),t.copyChild(r)}else this.resizeBehavior===3&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}measureFrameBounds(t){let e=this.getLinkedWidget();return e&&e!==this.linkedDisplay?t?e.bounds:e.unscaledBounds:this.linkedDisplay?.measureContentBounds(t)??{x:0,y:0,width:0,height:0}}drawLinkedContent(t){let e=this.getLinkedWidget();e&&e!==this.linkedDisplay?e.visible&&(e.drawHolder(t),e.draw(t),e.drawDecoration(t),e.drawOverlay(t)):this.linkedDisplay&&this.linkedDisplay.draw(t)}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:[]}autoScale(t,e){M.prototype.autoScale.call(this,t,e)}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(Es)}get groupName(){return this.properties.getValue(ta)}get resizeBehavior(){return this.properties.getValue(ea)}};var Qi=class{constructor(t){this.display=t}resolve(t,e){if(t.startsWith("/"))return`${this.display.absPrefix}${t.slice(1)}`;if(t.startsWith("http://")||t.startsWith("https://"))return t;if(e){let i=e.parent;for(;i;){if(i instanceof Le){let r=i.resolvedOpiFile,s=r.lastIndexOf("/")+1;return`${r.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}};var tr=class{constructor(t){this.display=t}cache=new Map;ttl=5e3;async load(t){this.removeOldEntries();let e=this.cache.get(t);if(e)return e.text;let i=await fetch(this.display.resolvePath(t),{credentials:"same-origin"});if(i.ok){let r=await i.text();return this.cache.set(t,{timestamp:Date.now(),text:r}),r}else return null}removeOldEntries(){let t=Date.now();this.cache.forEach((e,i)=>{e.timestamp+this.ttl<=t&&this.cache.delete(i)})}};var er=class{constructor(t,e){this.pvName=t;this.formula=e}pvValues=new Map;updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){let t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":e.indexOf(t.value)===-1&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(let i of t.arguments)this.getExpressionParameters(i,e);break}}execute(){let t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":return t.value;case"ParameterLiteral":let e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConstantLiteral":return t.value;case"NumericLiteral":return t.value;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){let 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){let 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){let e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(t.alternate===void 0)return e?i:null;{let r=this.executeExpression(t.alternate);return e?i:r}}executeUnaryExpression(t){let 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){let e=t.callee.name,i=[];for(let r of t.arguments)i.push(this.executeExpression(r));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 i[0]*180/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){let e=this.pvValues.get(t);if(e)return e.acquisitionStatus}};var Je=class extends SyntaxError{constructor(t,e,i,r){super(t),this.expected=e,this.found=i,this.location=r,this.name="SyntaxError"}format(t){let e="Error: "+this.message;if(this.location){let i=null,r=t.find(a=>a.source===this.location.source);r&&(i=r.text.split(/\r\n|\n|\r/g));let s=this.location.start,o=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(s):s,n=this.location.source+":"+o.line+":"+o.column;if(i){let a=this.location.end,l="".padEnd(o.line.toString().length," "),h=i[s.line-1],d=(s.line===a.line?a.column:h.length+1)-s.column||1;e+=`
1
+ "use strict";(()=>{function $e(c){let t=document.createElement("canvas").getContext("2d");t.fillStyle=c;let e=String(t.fillStyle),i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return i?new m(parseInt(i[1],16),parseInt(i[2],16),parseInt(i[3],16)):m.BLACK}var m=class c{constructor(t,e,i,r=255){this.red=t;this.green=e;this.blue=i;this.alpha=r}static TRANSPARENT=new c(0,0,0,0);static BLACK=new c(0,0,0);static BLUE=new c(0,0,255);static CYAN=new c(0,255,255);static DARK_GRAY=new c(150,150,150);static GRAY=new c(200,200,200);static GREEN=new c(0,255,0);static LIGHT_BLUE=new c(153,186,243);static ORANGE=new c(255,128,0);static PINK=new c(255,0,255);static PURPLE=new c(128,0,255);static RED=new c(255,0,0);static WHITE=new c(255,255,255);static YELLOW=new c(255,255,0);static BUTTON=new c(239,240,241);static BUTTON_DARKER=new c(164,168,172);static BUTTON_DARKEST=c.BLACK;static BUTTON_LIGHTEST=c.WHITE;withAlpha(t){return new c(this.red,this.green,this.blue,t)}mixWith(t,e){let i=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),s=Math.floor(this.blue*e+t.blue*(1-e));return new c(i,r,s)}brighter(){let{red:t,green:e,blue:i}=this,r=Math.floor(1/(1-.7));return t===0&&e===0&&i===0?new c(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),new c(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 c(Math.max(Math.floor(this.red*.7),0),Math.max(Math.floor(this.green*.7),0),Math.max(Math.floor(this.blue*.7),0))}contrast(){return new c(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=t.length==1?"0"+t:t;let e=this.green.toString(16);e=e.length==1?"0"+e:e;let i=this.blue.toString(16);i=i.length==1?"0"+i:i;let r=this.alpha.toString(16);return r=r.length==1?"0"+r:r,`#${t}${e}${i}${r}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}};var pi=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};function nt(c,t,e){return c.openConfirmDialogAsync?c.openConfirmDialogAsync(t,e):Promise.resolve(c.openConfirmDialog(t,e))}function Ut(c,t,e,i){return c.openPasswordDialogAsync?c.openPasswordDialogAsync(t,e,i):Promise.resolve(c.openPasswordDialog(t,e,i))}var fe=class{openConfirmDialogAsync(t,e){return Promise.resolve(this.openConfirmDialog(t,e))}openPasswordDialogAsync(t,e,i){return Promise.resolve(this.openPasswordDialog(t,e,i))}openConfirmDialog(t,e){return confirm(e)}openInformationDialog(t,e){alert(e)}openWarningDialog(t,e){alert(e)}openErrorDialog(t,e){alert(e)}openPasswordDialog(t,e,i){let r=prompt(e);return r?r===i:!1}};var di=c=>(document.removeEventListener("click",di,!0),c.preventDefault(),c.stopPropagation(),!1);function Ss(c){return(c.buttons&1)===1||c.buttons===void 0&&c.which==1}var Eo=5;function lx(c,t,e,i){return Math.sqrt((e-c)*(e-c)+(i-t)*(i-t))}function Mo(c,t){return c&&t&&c.id===t.id}var ui=class{constructor(t,e,i){this.display=t;this.canvas=e;this.hitCanvas=i;let{signal:r}=this.abortController;e.addEventListener("click",s=>this.onCanvasClick(s),{signal:r}),e.addEventListener("dblclick",s=>this.onCanvasDblClick(s),{signal:r}),e.addEventListener("mousedown",s=>this.onCanvasMouseDown(s),{signal:r}),e.addEventListener("mouseup",s=>this.onCanvasMouseUp(s),{signal:r}),e.addEventListener("mouseout",s=>this.onCanvasMouseOut(s),{signal:r}),e.addEventListener("mousemove",s=>this.onCanvasMouseMove(s),{signal:r})}grabbing=!1;grabTarget;grabPoint;documentMouseMoveListener=t=>this.onDocumentMouseMove(t);documentMouseUpListener=t=>this.onDocumentMouseUp(t);prevEnteredRegion;pendingMouseMoveEvent;mouseMoveRafHandle;abortController=new AbortController;destroy(){this.abortController.abort(),document.removeEventListener("click",di,!0),document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener),this.mouseMoveRafHandle!==void 0&&cancelAnimationFrame(this.mouseMoveRafHandle)}toPoint(t){let e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();let e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{let i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasDblClick(t){if(this.display.editMode)return;let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.dblclick&&i.dblclick({clientX:t.clientX,clientY:t.clientY,point:e})}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",di,!0),Ss(t))){let e=this.toPoint(t),i=document.activeElement;this.display.rootPanel.contains(i)&&(i instanceof HTMLInputElement||i instanceof HTMLTextAreaElement||i instanceof HTMLSelectElement)&&i.blur();let r=this.hitCanvas.getActiveRegion(e.x,e.y);return r&&r.mouseDown&&r.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),r&&r.grab&&(this.grabPoint={...e},this.grabTarget=r),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;let 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){this.pendingMouseMoveEvent=t,this.mouseMoveRafHandle===void 0&&(this.mouseMoveRafHandle=requestAnimationFrame(()=>{this.mouseMoveRafHandle=void 0;let e=this.pendingMouseMoveEvent;this.pendingMouseMoveEvent=void 0,this.processMouseMove(e)}))}processMouseMove(t){let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);if(this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(Mo(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(Mo(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i,!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&Ss(t)){let o=lx(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(o)>Eo&&(this.initiateGrab(),Eo>0&&this.grabPoint&&(this.grabPoint=e))}let r=this.grabbing?this.grabTarget:i,s=r&&r.cursor?r.cursor:"auto";s!=this.canvas.style.cursor&&(this.canvas.style.cursor=s),this.grabbing&&this.grabTarget&&Ss(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",di,!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);let e=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,e?.grabEnd&&e.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){let i=this.display.instance;if(i)for(let r of i.widgets.slice().reverse()){let s=r.holderX,o=r.holderY,n=r.holderX+r.holderWidth,a=r.holderY+r.holderHeight;if(s<t&&t<n&&o<e&&e<a)return this.display.selection=[r.wuid],!1}}};var gi=class{constructor(t){this.utc=t}formatDate(t,e){let i=this.utc,r="";if(e.year&&(r+=i?t.getUTCFullYear():t.getFullYear()),e.month){e.year&&(r+="-");let s=(i?t.getUTCMonth():t.getMonth())+1;r+=(s<10?"0":"")+s}if(e.day){e.month&&(r+="-");let s=i?t.getUTCDate():t.getDate();r+=(s<10?"0":"")+s}return r}formatTime(t,e){let i=this.utc,r="";if(e.hours){let s=i?t.getUTCHours():t.getHours();r+=(s<10?"0":"")+s}if(e.minutes){e.hours&&(r+=":");let s=i?t.getUTCMinutes():t.getMinutes();r+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(r+=":");let s=i?t.getUTCSeconds():t.getSeconds();r+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(r+=".");let s=i?t.getUTCMilliseconds():t.getMilliseconds();r+=(s<10?"00":s<100?"0":"")+s}return r}};var Vo="rgb(255,255,255)",hx=!!navigator.brave,mi=class c{constructor(t,e,i){this.parent=t;let r=document.createElement("canvas");r.width=e??r.width,r.height=i??r.height,this.ctx=r.getContext("2d",{willReadFrequently:!0}),this.root=t?.root||t}ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=Vo,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){let e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){let i=this.ctx.getImageData(t,e,1,1).data,r=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(r)||void 0}createChild(t,e){return new c(this,t,e)}transferToParent(t,e,i,r){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,r)}generateUniqueColor(t){for(;;){let e=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=Math.round(Math.random()*255),s=`rgb(${e},${i},${r})`;if(!this.regionsByColor.has(s)&&s!==Vo)return hx?(this.regionsByColor.set(`rgb(${e-1},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i},${r})`,t),this.regionsByColor.set(`rgb(${e},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${r+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${r+1})`,t)):this.regionsByColor.set(s,t),s}}};function Ht(c,t,e,i,r){return W({x:c,y:t,width:e,height:i},r/2)}function St(c,t,e,i,r){let s=Math.sin(r),o=Math.cos(r),n=c-e,a=t-i;return{x:n*o-a*s+e,y:n*s+a*o+i}}function W(c,t,e){return e===void 0&&(e=t),{x:c.x+e,y:c.y+t,width:c.width-(e+e),height:c.height-(t+t)}}function Ls(c){return{x:Math.round(c.x)+.5,y:Math.round(c.y)+.5,width:Math.round(c.width),height:Math.round(c.height)}}function fi(c,t){let e=c.x,i=c.y,r=e+c.width,s=i+c.height;if(r<e){let d=e;e=r,r=d}if(s<i){let d=i;i=s,s=d}let o=t.x,n=t.y,a=o+t.width,l=n+t.height;if(a<o){let d=o;o=a,a=d}if(l<n){let d=n;n=l,l=d}let h=Math.max(e,o),p=Math.max(i,n);return{x:h,y:p,width:Math.min(r,a)-h,height:Math.min(s,l)-p}}function Dt(c,t,e){return{x:c.x+t,y:c.y+e}}function pt(c,t,e){return c.map(i=>Dt(i,t,e))}function G(c){return c*Math.PI/180}function Ue(c,t){return Math.sqrt((t.x-c.x)*(t.x-c.x)+(t.y-c.y)*(t.y-c.y))}function xt(c,t,e){let i=Math.floor(c*Math.cos(t)),r=Math.floor(-c*Math.sin(t));return{x:e.x+e.width/2+i,y:e.y+e.height/2+r}}function wi(c,t){let e=t.x-c.x,i=t.y-c.y,r=Math.sqrt(Math.pow(e,2)+Math.pow(i,2)),s=Math.acos(e/r);return i>0&&(s=2*Math.PI-s),new Tt(Math.floor(r),s)}var Tt=class{constructor(t,e){this.r=t;this.theta=e}toPoint(){let t=Math.floor(this.r*Math.cos(this.theta)),e=Math.floor(-this.r*Math.sin(this.theta));return{x:t,y:e}}};function oe(c,t){return c.map(e=>({x:e.x*t,y:e.y*t}))}function Io(c){let t=c[0].x,e=c[0].x,i=c[0].y,r=c[0].y;for(let s of c)t=Math.min(t,s.x),e=Math.max(e,s.x),i=Math.min(i,s.y),r=Math.max(r,s.y);return{x:(t+e)/2,y:(i+r)/2}}function we(c,t){if(c.length===0)return c;let e=Io(c),i=G(t),r=c.map(o=>St(o.x,o.y,e.x,e.y,i)),s=Io(r);return s.x!==e.x||s.y!==e.y?pt(r,e.x-s.x,e.y-s.y):r}function xi(c){return c.map(t=>({x:t.x+.5,y:t.y+.5}))}function yi(c,t,e,i,r){let s=e*Math.PI/180,o=Math.cos(s),n=Math.sin(s),a=c.width/2;if(i===1)if(e<=90){let h=t.width*o+t.height*n;a=(c.width-h)/2+t.height*n}else if(e<=180){let h=t.height*n-t.width*o;a=c.width-(c.width-h)/2}else if(e<=270){let h=-t.width*o-t.height*n;a=(c.width-h)/2-t.width*o}else{let h=t.width*o-t.height*n;a=(c.width-h)/2}else i===2?e<=90?a=c.width-t.width*o:e<=180?a=c.width:e<=270?a=c.width- -t.height*n:a=c.width-(t.width*o-t.height*n):e<=90?a=t.height*n:e<=180?a=t.height*n-t.width*o:e<=270?a=-t.width*o:a=0;let l=c.height/2;if(r===1)if(e<=90){let h=t.width*n+t.height*o;l=(c.height-h)/2}else if(e<=180){let h=t.width*n-t.height*o;l=(c.height-h)/2-t.height*o}else if(e<=270){let h=-t.width*n-t.height*o;l=c.height-(c.height-h)/2}else{let h=t.height*o-t.width*n;l=(c.height-h)/2-t.height*n}else r===2?e<=90?l=c.height-(t.width*n+t.height*o):e<=180?l=c.height-t.width*n:e<=270?l=c.height:l=c.height-t.height*o:e<=90?l=0:e<=180?l=-t.height*o:e<=270?l=-t.width*n-t.height*o:l=-t.width*n;return{x:a,y:l}}function Pi(c,t,e,i,r,s,o){c.beginPath(),!s&&!o?c.rect(t,e,i,r):(i<2*s&&(s=i/2),r<2*o&&(o=r/2),c.moveTo(t+s,e),c.lineTo(t+i-s,e),c.quadraticCurveTo(t+i,e,t+i,e+o),c.lineTo(t+i,e+r-o),c.quadraticCurveTo(t+i,e+r,t+i-s,e+r),c.lineTo(t+s,e+r),c.quadraticCurveTo(t,e+r,t,e+r-o),c.lineTo(t,e+o),c.quadraticCurveTo(t,e,t+s,e))}function xe(c,t,e,i){return c===null?"":typeof c=="string"?i==="BINARY_STRING"?cx(c):c:typeof c=="number"?e===-1?Bo(t,c,void 0,3):Bo(t,c,e,e):c instanceof Date?c.toISOString().replace("T"," ").replace("Z",""):String(c)}function cx(c){let t="";for(let e=0;e<c.length;e++){let i=c.charCodeAt(e).toString(16);t+=i.length===2?i:"0"+i}return t&&`0x${t.toUpperCase()}`}function Bo(c,t,e,i){if(t==null||t==null)return"";switch(c){case 0:case 1:let r={minimumFractionDigits:e,maximumFractionDigits:i,useGrouping:!1,roundingMode:"halfEven"};return Intl.NumberFormat("en-US",r).format(t);case 2:return t.toExponential(i).replace("e+","E").toUpperCase();case 3:return"0x"+t.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${c}`),String(t)}}function ye(c,t,e){let{a:i,d:r,e:s,f:o}=c.getTransform(),n=t*i+s,a=e*r+o,l=Math.floor(n),h=Math.floor(a);return{x:(l-s)/i,y:(h-o)/r,subPixelX:(n-l)/i,subPixelY:(a-h)/r}}var bi=class c{constructor(t,e,i=1){this.canvas=t;this.pixelRatio=i;this.ctx=t.getContext("2d"),this.hitCanvas=e||new mi,this.hitCtx=this.hitCanvas.ctx}ctx;hitCanvas;hitCtx;parentOffset;get cssWidth(){return this.canvas.width/this.pixelRatio}get cssHeight(){return this.canvas.height/this.pixelRatio}createChild(t,e){let i=this.hitCanvas.createChild(Math.ceil(t),Math.ceil(e)),r=document.createElement("canvas");r.width=Math.ceil(t*this.pixelRatio),r.height=Math.ceil(e*this.pixelRatio);let s=new c(r,i,this.pixelRatio);return s.ctx.scale(this.pixelRatio,this.pixelRatio),s}createChildAt(t,e,i,r){let{x:s,y:o,subPixelX:n,subPixelY:a}=ye(this.ctx,t,e),l=this.createChild(Math.ceil(i+n),Math.ceil(r+a));return l.ctx.translate(n,a),l.parentOffset={x:s,y:o},l}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copyChild(t){if(!t.parentOffset)throw new Error("Buffer was not created with createChildAt");this.copy(t,t.parentOffset.x,t.parentOffset.y)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i,t.cssWidth,t.cssHeight);let r=ye(this.hitCtx,e,i);t.hitCanvas.transferToParent(r.x,r.y,t.hitCtx.canvas.width,t.hitCtx.canvas.height)}copyFitted(t,e,i,r,s){let{width:o,height:n}=t.canvas,a=o/n,l=r,h=l/a;h>s&&(h=s,l=h*a),this.copyScaled(t,e,i,l,h)}copyScaled(t,e,i,r,s){this.ctx.drawImage(t.canvas,e,i,r,s),t.hitCanvas.transferToParent(e,i,r,s)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height),this.ctx.restore()}clearCanvas(){this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height),this.ctx.restore()}resize(t,e){let i=Math.ceil(t*this.pixelRatio),r=Math.ceil(e*this.pixelRatio);(this.canvas.width!==i||this.canvas.height!==r)&&(this.canvas.width=i,this.canvas.height=r,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e),this.canvas.style.width=t+"px",this.canvas.style.height=e+"px",this.ctx.setTransform(this.pixelRatio,0,0,this.pixelRatio,0,0)}fillRect(t){"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(Pi(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),t.opacity!==void 0&&(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();let e=t.startAngle||0,i=t.endAngle===void 0?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),t.opacity!==void 0&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();let e=t.startAngle||0,i=t.endAngle===void 0?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),"color"in t?this.ctx.strokeStyle=t.color.toString():this.ctx.strokeStyle=t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e,i=!1){this.ctx.font=e.getFontString();let r=this.ctx.measureText(t),s;return r.fontBoundingBoxAscent!==void 0&&r.fontBoundingBoxDescent!==void 0?s={width:r.width,height:r.fontBoundingBoxAscent+r.fontBoundingBoxDescent}:s={width:r.width,height:e.height},i&&(s.width=Math.ceil(s.width),s.height=Math.ceil(s.height)),s}createLinearGradient(t,e,i,r){return this.ctx.createLinearGradient(t,e,i,r)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);let e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){let i=W(t,e/2,e/2);t.rx||t.ry?(Pi(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?(Pi(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(let 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(),t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),t.opacity!==void 0&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(let e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);"color"in t?this.ctx.fillStyle=t.color.toString():this.ctx.fillStyle=t.gradient,t.opacity!==void 0&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),t.opacity!==void 0&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new Cs(this.hitCanvas.ctx)}},_=class c{segments=[];constructor(t,e){this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){let e=t.findIndex(r=>r.y!==null);if(e===-1){let r=new c(0,0);return r.segments.length=0,r}let i=new c(t[e].x,t[e].y);for(let r=e+1;r<t.length;r++){let{x:s,y:o}=t[r];o!==null&&(r>0&&t[r-1].y===null?i.moveTo(s,o):i.lineTo(s,o))}return i}getBoundingBox(){let 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++){let r=this.segments[i];r.x<t.x&&(t.x=r.x),r.x>e.x&&(e.x=r.x),r.y<t.y&&(t.y=r.y),r.y>e.y&&(e.y=r.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(){if(this.segments.length){let t=this.segments[0];this.segments.push({x:t.x,y:t.y,line:!0})}return this}translate(t,e){for(let i of this.segments)i.x+=t,i.y+=e;return this}},Cs=class{constructor(t){this.ctx=t}addRect(t,e,i,r){return this.ctx.fillRect(t,e,i,r),this}addEllipse(t,e,i,r,s,o,n,a){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,r,s,o,n,a),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(let e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}};var vi=class{load(t){return Promise.resolve(t)}};var Pe=class{constructor(t,e=[]){this.widget=t;for(let i of e)this.properties.set(i.name,i)}properties=new Map;generators=[];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 ze)e.value=t.getActions(e.name);else if(e instanceof Ke)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof f)e.value=t.getBoolean(e.name);else if(e instanceof ne)e.value=t.getColorMap(e.name);else if(e instanceof L)e.value=t.getColor(e.name);else if(e instanceof O)e.value=t.getFloat(e.name);else if(e instanceof H)e.value=t.getFont(e.name);else if(e instanceof P)e.value=t.getInt(e.name);else if(e instanceof ae)e.value=t.getMacros(e.name);else if(e instanceof Ye)e.value=t.getMatrix(e.name);else if(e instanceof kt)e.value=t.getPoints(e.name);else if(!(e instanceof Wt))if(e instanceof qe)e.value=t.getRules(e.name);else if(e instanceof tt)e.value=t.getScaleOptions(e.name);else if(e instanceof Xe)e.value=t.getScripts(e.name);else if(e instanceof T)e.rawValue=t.getString(e.name);else if(e instanceof Nt)e.value=t.getStringList(e.name);else if(e instanceof le)e.value=t.getStringMap(e.name);else if(e instanceof be)e.value=t.getStringTable(e.name);else throw new Error(`Property ${e.name} has an unexpected type`)}}loadXMLValues(t){this.properties.forEach(e=>{this.loadProperty(t,e)}),this.resolveStringProperties();for(let e of this.generators)for(let 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(e=>{if(e instanceof T){let i=e;i.rawValue!==void 0&&this.widget?e.value=this.widget.expandMacro(i.rawValue):e.value=i.rawValue}})}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){let i=this.properties.get(t);if(i&&i.value!==void 0)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){let i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}},it=class{constructor(t,e){this.name=t;this.defaultValue=e;this.value=e}_value;listeners;get value(){return this._value}set value(t){if(this.value!==t){let e=this._value;if(this._value=t,this.listeners)for(let i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){let e=this.listeners||[],i=e.indexOf(t);i!==-1&&e.splice(i,1)}printScriptValue(t){return String(t)}},T=class extends it{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},Wt=class extends it{constructor(e,i){super(e);this.pvPropertyName=i}},P=class extends it{},O=class extends it{},f=class extends it{},L=class extends it{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},H=class extends it{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},ne=class extends it{printScriptValue(t){return`${t.code}`}},kt=class extends it{},Ye=class extends it{},ze=class extends it{},ae=class extends it{},Xe=class extends it{},Nt=class extends it{},le=class extends it{},be=class extends it{},qe=class extends it{},tt=class extends it{},Ke=class extends it{};var ve=class{actions=[];hookFirstActionToClick=!1;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]}toString(){return this.actions.length===1?this.actions[0]?.getDescription()??"":`${this.actions.length} actions`}};var dx=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],Re={Arial:"Liberation Sans","Times New Roman":"Liberation Serif","Courier New":"Liberation Mono"},Ho=new Set;function Do(c){Ho.add(c)}var X=class c{constructor(t,e,i,r){this.name=t;this.style=i;r?this.height=e:c.LEGACY_FONT_SIZING?this.height=Math.round(e*16/15):this.height=e*4/3}static LEGACY_FONT_SIZING=!1;static ARIAL_9=new c("Arial",9,0,!1);static ARIAL_10=new c("Arial",10,0,!1);static ARIAL_11=new c("Arial",11,0,!1);static ARIAL_12_BOLD=new c("Arial",12,1,!1);height;scale(t){return new c(this.name,t*this.height,this.style,!0)}getFontString(){let t=this.name;return Ho.has(t)&&(t=Re[t]),t.indexOf(" ")!==-1&&(t=`"${t}"`),this.style===1?`bold ${this.height}px ${t}`:this.style===2?`italic ${this.height}px ${t}`:this.style===3?`italic bold ${this.height}px ${t}`:(this.style!==0&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${t}`)}get bold(){return this.style===1||this.style===3}get italic(){return this.style===2||this.style===3}isWebSafe(){return dx.indexOf(this.name)!==-1&&!Re[this.name]}};var _e=class{constructor(t,e){this.name=t;this.pvEngine=e}_writable=!1;_units;_labels;_typeHint;_lowerDisplayLimit;_lowerAlarmLimit;_lowerWarningLimit;_upperWarningLimit;_upperAlarmLimit;_upperDisplayLimit;_time;_value;_severity="NONE";_indexValue;_precision=-1;_disconnected=!1;provider;get navigable(){return this.provider?.isNavigable()||!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get labels(){return this._labels}set labels(t){this._labels=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}get typeHint(){return this._typeHint}get alarmName(){let t=this.toNumber();return t==null?"NONE":t<=(this.lowerAlarmLimit??NaN)?"LOLO":t>=(this.upperAlarmLimit??NaN)?"HIHI":t<=(this.lowerWarningLimit??NaN)?"LOW":t>=(this.upperWarningLimit??NaN)?"HIGH":"NONE"}toNumber(){if(this.value===null)return null;if(typeof this.value=="number")return this.value;if(typeof this.value=="boolean")return this.value?1:0;if(typeof this.indexValue!==void 0)return this.indexValue}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this._units=t.units,this._typeHint=t.typeHint,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.removeListener(this.name,t)}toString(){if(this.value!==void 0)return String(this.value)}};var Te=class{rules=[]};var Se=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}},J=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}};function Ri(c,t,e,i){let{widthScalable:r,heightScalable:s,keepWidthHeightRatio:o}=i;if(o&&r&&s)if(t<=e){let n=Math.round(c.width*t),a=Math.trunc(c.height*n/c.width);return{width:n,height:a}}else{let n=Math.round(c.height*e);return{width:Math.trunc(c.width*n/c.height),height:n}}return{width:r?Math.round(c.width*t):c.width,height:s?Math.round(c.height*e):c.height}}function _i(c,t,e){let{widthScalable:i,heightScalable:r,keepWidthHeightRatio:s}=e;return s&&r&&i?(c=Math.min(c,t),t=c):r?i||(c=1):t=1,{widthRatio:c,heightRatio:t}}var Le=class{scripts=[]};var Wo="actions",ko="background_color",No="backcolor_alarm_sensitive",Fo="border_alarm_sensitive",Go="border_color",$o="border_width",Uo="border_style",Yo="enabled",zo="foreground_color",Xo="forecolor_alarm_sensitive",je="height",qo="name",As="pv_name",Ko="pv_value",jo="rules",Zo="scale_options",Jo="scripts",Os="text",Qo="tooltip",tn="transparent",en="visible",rn="widget_type",Ze="width",sn="wuid",Je="x",Qe="y",M=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new Pe(this,[new ze(Wo,new ve),new f(No,!1),new L(ko,m.TRANSPARENT),new f(Fo,!1),new L(Go),new P(Uo),new P($o),new f(Yo,!0),new f(Xo,!1),new L(zo),new P(je),new T(qo),new T(As),new Wt(Ko,As),new qe(jo,new Te),new Xe(Jo,new Le),new T(Os,""),new T(Qo,""),new f(tn,!1),new f(en),new T(rn),new P(Ze),new T(sn),new P(Je),new P(Qe),new tt(Zo,new J(!0,!0,!1))])}x=0;y=0;width=0;height=0;_value;fillRoundRectangleBackgroundBorder=!0;customSize;customHolderWidth;customHolderHeight;originBounds;holderRegion;properties;vars=new Map;pvs=[];async parseNode(t){this.properties.loadXMLValues(t);for(let e of this.properties.all())if(e instanceof H){let i=e.value;this.loadFont(i)}if(this.pvName){let e=this.display.pvEngine.createPV(this.pvName);this.pvs.push(e),this.display.pvEngine.trackListener(this,e.name,()=>this._value=e.value)}for(let e of this.scripts.scripts){let i=[];for(let r of e.inputs){let s=this.expandMacro(r.pvName);i.push(this.display.pvEngine.createPV(s))}if(this.pvs.push(...i),e.embedded)this.display.pvEngine.createScript(this,e,e.text,i);else{let s=await this.display.getScriptLoader().load(this.resolvePath(e.path));s&&this.display.pvEngine.createScript(this,e,s,i)}}for(let e of this.rules.rules)if(this.properties.getProperty(e.propertyName)){let i=[];for(let r of e.inputs){let s=this.expandMacro(r.pvName);i.push(this.display.pvEngine.createPV(s))}this.pvs.push(...i),this.display.pvEngine.createRule(this,e,i)}else console.warn(`Cannot create rule for unsupported property ${e.propertyName}`);this.actions.isClickable()&&(this.holderRegion={id:`${this.wuid}-holder`},this.tooltip&&(this.holderRegion.tooltip=()=>this.tooltip),this.actions.isClickable()&&(this.holderRegion.click=()=>{for(let e of this.getHookedActions())this.executeAction(e)},this.holderRegion.cursor="pointer")),await this.init()}getHookedActions(){let{actions:t}=this,e=[];for(let i=0;i<t.actions.length;i++)i===0?(t.hookFirstActionToClick||t.hookAllActionsToClick)&&e.push(t.actions[i]):t.hookAllActionsToClick&&e.push(t.actions[i]);return e}drawHolder(t){let{scale:e}=this,i=[0,0,0,0],r=this.borderAlarmSensitive&&(this.pv?.severity==="MINOR"||this.pv?.severity==="MAJOR");if(!r)switch(this.borderStyle){case 0:break;case 1:i=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:i=[1*e,1*e,1*e,1*e];break;case 4:case 5:case 6:i=[2*e,2*e,2*e,2*e];break;case 7:i=[2*e,2*e,1*e,1*e];break;case 8:case 9:case 10:case 11:i=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 12:i=[17*e,1*e,1*e,1*e];break;case 13:i=[16*e,16*e,16*e,16*e];break;case 14:let s=this.borderWidth*2;i=[s,s,s,s];break}this.customSize?(this.customHolderWidth=this.customSize.width+i[1]+i[3],this.customHolderHeight=this.customSize.height+i[0]+i[2]):(this.customHolderWidth=void 0,this.customHolderHeight=void 0),this.x=this.holderX+i[1],this.y=this.holderY+i[0],this.width=this.holderWidth-i[1]-i[3],this.height=this.holderHeight-i[0]-i[2],r||(this.beforeDrawBorder(t),this.drawBorderStyle(t)),this.holderRegion&&t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}beforeDrawBorder(t){}drawBorderStyle(t){let{scale:e}=this;if(this.borderStyle!==0)if(this.borderStyle===1)t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(this.borderStyle===2){let i=1*e,r=this.holderY+i/2,s=this.holderX+i/2,o=this.holderY+this.holderHeight-i+i/2,n=this.holderX+this.holderWidth-i+i/2;t.strokePath({color:m.BLACK,path:new _(n,o).lineTo(n,r).moveTo(n,o).lineTo(s,o)}),t.strokePath({color:m.WHITE,path:new _(s,r).lineTo(n-i,r).moveTo(s,r).lineTo(s,o-i)})}else if(this.borderStyle===3){if(this.isAnyPvInvalid())return;let i=1*e,r=this.holderY+i/2,s=this.holderX+i/2,o=this.holderY+this.holderHeight-i+i/2,n=this.holderX+this.holderWidth-i+i/2;t.strokePath({color:m.WHITE,path:new _(n,o).lineTo(n,r).moveTo(n,o).lineTo(s,o)}),t.strokePath({color:m.BLACK,path:new _(s,r).lineTo(n-i,r).moveTo(s,r).lineTo(s,o-i)})}else if(this.borderStyle===4)this.drawShadowBorder(t,m.BUTTON_LIGHTEST,m.BUTTON_DARKER,m.BUTTON_DARKER,m.BUTTON_LIGHTEST);else if(this.borderStyle===5)this.drawShadowBorder(t,m.BUTTON_DARKER,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKER);else if(this.borderStyle===6)this.drawShadowBorder(t,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST);else if(this.borderStyle===7)this.drawShadowBorder(t,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER);else if(this.borderStyle===8)this.drawDashedBorder(t,[2*e,2*e]);else if(this.borderStyle===9)this.drawDashedBorder(t,[6*e,2*e]);else if(this.borderStyle===10)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e]);else if(this.borderStyle===11)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e,2*e,2*e]);else if(this.borderStyle===12)t.fillRect({x:this.holderX,y:this.holderY+1*e,width:this.holderWidth,height:16*e,color:this.borderColor}),t.fillText({x:this.holderX+1*e+3*e,y:this.holderY+1*e+16/2*e,baseline:"middle",align:"left",font:X.ARIAL_11.scale(e),color:m.BLACK,text:this.name}),t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:m.BLACK,crispen:!0});else if(this.borderStyle===13){let i=t.measureText(this.name,X.ARIAL_11.scale(e)),r=1,s=Ht(this.holderX+8*e,this.holderY+8*e,this.holderWidth-16*e-r,this.holderHeight-16*e-r,r);this.transparent||(t.fillRect({...W(s,8*e),color:this.backgroundColor}),t.fillRect({x:this.holderX+16*e,y:this.holderY,width:i.width,height:16*e,color:this.backgroundColor})),t.fillText({x:this.holderX+16*e,y:this.holderY+8*e,baseline:"middle",align:"left",font:X.ARIAL_11.scale(e),color:this.borderColor,text:this.name}),t.strokePath({color:this.backgroundColor.darker(),path:new _(s.x,s.y).lineTo(s.x+8*e,s.y).moveTo(s.x+8*e+i.width,s.y).lineTo(s.x+s.width,s.y).lineTo(s.x+s.width,s.y+s.height).lineTo(s.x,s.y+s.height).lineTo(s.x,s.y)}),s=Ht(this.holderX+8*e+r,this.holderY+8*e+r,this.holderWidth-16*e-r,this.holderHeight-16*e-r,r),t.strokePath({color:this.backgroundColor.brighter(),path:new _(s.x,s.y).lineTo(s.x+8*e-r,s.y).moveTo(s.x+8*e-r+i.width,s.y).lineTo(s.x+s.width,s.y).lineTo(s.x+s.width,s.y+s.height).lineTo(s.x,s.y+s.height).lineTo(s.x,s.y)})}else if(this.borderStyle===14){let i=Ht(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&t.fillRect({...i,rx:4*e,ry:4*e,color:this.backgroundColor}),this.borderWidth&&t.strokeRect({...i,rx:4*e,ry:4*e,color:this.borderColor,lineWidth:this.borderWidth})}else this.borderStyle===15||console.warn(`Unsupported border style: ${this.borderStyle}`)}isAnyPvDisconnected(){let t=this.pvName&&(!this.pv||this.pv.disconnected),e=this.pvs.find(i=>i.disconnected)!==void 0;return t||e}isAnyPvInvalid(){let t=!1;for(let e of this.pvs)if(e.value===void 0){t=!0;break}return this.pvs.length&&t}drawDecoration(t){if(this.display.editMode)return;let{scale:e}=this;if(this.isAnyPvDisconnected()){let i=1*e;t.fillRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:this.display.disconnectedColor,opacity:.4}),t.strokeRect({x:this.holderX-i/2,y:this.holderY-i/2,width:this.holderWidth+i,height:this.holderHeight+i,color:this.display.disconnectedColor})}else this.isAnyPvInvalid()&&t.strokeRect({...this.bounds,dash:[2*e,2*e],lineWidth:2*e,color:this.display.invalidColor,crispen:!0});if(this.borderAlarmSensitive){let i;this.borderStyle===8?i=[2*e,2*e]:this.borderStyle===9?i=[6*e,2*e]:this.borderStyle===10?i=[6*e,2*e,2*e,2*e]:this.borderStyle===11&&(i=[6*e,2*e,2*e,2*e,2*e,2*e]),this.pv?.severity==="MAJOR"?t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.majorColor,crispen:!0,dash:i}):this.pv?.severity==="MINOR"?t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.minorColor,crispen:!0,dash:i}):this.pv?.severity==="INVALID"&&t.strokeRect({...this.bounds,lineWidth:2*e,color:this.display.invalidColor,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()}resolvePath(t){return this.display.resolvePath(t,this)}get bounds(){return{x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight}}get unscaledBounds(){return{x:this.properties.getValue(Je),y:this.properties.getValue(Qe),width:this.properties.getValue(Ze),height:this.properties.getValue(je)}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,r,s){let o=1*this.scale,n=this.holderY+o/2,a=this.holderX+o/2,l=this.holderY+this.holderHeight-o+o/2,h=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new _(h,l).lineTo(h,n).moveTo(h,l).lineTo(a,l)}),t.strokePath({color:i,path:new _(h-o,l-o).lineTo(h-o,n+o).moveTo(h-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new _(a,n).lineTo(h-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new _(a+o,n+o).lineTo(h-o-o,n+o).moveTo(a+o,n+o).lineTo(a+o,l-o-o)})}drawDashedBorder(t,e){let i=Ht(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new _(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()})}executeActionByIndex(t){let e=this.actions.getAction(t);e&&this.executeAction(e)}executeAction(t){this.display.runSequenced(()=>t.execute(this))}expandMacro(t){if(t.indexOf("$")===-1)return t;for(let e of this.properties.all())if(e instanceof Wt){let i=this.properties.getProperty(e.pvPropertyName),r="",s=i?.value;s&&(r=this.display.getPV(s)?.value??""),t=t.replace(`$(${e.name})`,r),t=t.replace(`\${${e.name}}`,r)}else t=t.replace(`$(${e.name})`,e.value||""),t=t.replace(`\${${e.name}}`,e.value||"");return this.parent?this.parent.expandContainerMacros(t):t}loadFont(t){if(t.isWebSafe())return;let e=this.display.getFontResolver();if(!e){console.warn(`Failed to load font '${t.getFontString()}'.`);return}let i=e.resolve(t);if(!i){console.warn(`Failed to load font '${t.getFontString()}'.`);return}i.load().then(r=>{document.fonts.add(r),Re[t.name]&&Do(t.name),this.requestRepaint()}).catch(r=>{console.warn(`Failed to load font '${t.getFontString()}'.`,r)})}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){return this.pv?.severity==="MINOR"}isMajorSeverity(){return this.pv?.severity==="MAJOR"}get alarm(){return this.pv?.severity==="MINOR"||this.pv?.severity==="MAJOR"||this.pv?.severity==="INVALID"}get alarmSensitiveBackgroundColor(){if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor;if(this.pv?.severity==="INVALID")return this.display.invalidColor}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}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){let i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue(sn)}get name(){return this.properties.getValue(qo)}get holderX(){return this.scale*this.properties.getValue(Je)}get holderY(){return this.scale*this.properties.getValue(Qe)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(Ze)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(je)}get borderAlarmSensitive(){return this.properties.getValue(Fo)}get backgroundAlarmSensitive(){return this.properties.getValue(No)}get foregroundAlarmSensitive(){return this.properties.getValue(Xo)}get pvName(){return this.properties.getValue(As,!0)}get pvValue(){return this.properties.getValue(Ko,!0)}get borderColor(){return this.properties.getValue(Go)}get borderStyle(){return this.properties.getValue(Uo)}get borderWidth(){return this.scale*this.properties.getValue($o)}get backgroundColor(){return this.properties.getValue(ko)}get enabled(){return this.properties.getValue(Yo)}get foregroundColor(){return this.properties.getValue(zo)}get tooltip(){let t=this.properties.getProperty(Qo);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(tn)}get visible(){return this.properties.getValue(en)}get actions(){return this.properties.getValue(Wo)}get scripts(){return this.properties.getValue(Jo)}get rules(){return this.properties.getValue(jo)}get scaleOptions(){return this.properties.getValue(Zo)}autoScale(t,e){this.originBounds||(this.originBounds={x:this.properties.getValue(Je),y:this.properties.getValue(Qe),width:this.properties.getValue(Ze),height:this.properties.getValue(je)});let i=this.originBounds;this.properties.setValue(Je,Math.round(i.x*t)),this.properties.setValue(Qe,Math.round(i.y*e));let{widthScalable:r,heightScalable:s}=this.scaleOptions;if(r||s){let{width:o,height:n}=Ri(i,t,e,this.scaleOptions);this.properties.setValue(Ze,o),this.properties.setValue(je,n)}}get widgetType(){return this.properties.getValue(rn,!0)}get text(){return this.display.editMode?this.properties.getProperty(Os).rawValue||"":this.properties.getValue(Os)}init(){}hide(){}destroy(){}};var on="description",et=class{properties;constructor(){this.properties=new Pe(null,[new T(on,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(on)}getDescription(){return this.description||this.getDefaultDescription()}getDefaultDescription(){return"Action"}};var nn="command",an="command_directory",ln="wait_time",Ti=class extends et{constructor(){super(),this.properties.add(new T(nn,"")),this.properties.add(new T(an,"$(user.home)")),this.properties.add(new P(ln,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(nn)}get commandDirectory(){return this.properties.getValue(an)}get waitTime(){return this.properties.getValue(ln)}getDefaultDescription(){return`Execute Command ${this.command}`}};var Si=class{BLACK=m.BLACK;BLUE=m.BLUE;CYAN=m.CYAN;DARK_GRAY=m.DARK_GRAY;GRAY=m.GRAY;GREEN=m.GREEN;LIGHT_BLUE=m.LIGHT_BLUE;ORANGE=m.ORANGE;PINK=m.PINK;PURPLE=m.PURPLE;RED=m.RED;WHITE=m.WHITE;YELLOW=m.YELLOW;getColorFromRGB(t,e,i){return new m(t,e,i)}getFont(t,e,i){return new X(t,e,i,!1)}};var Li=class{constructor(t){this.display=t}writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}};var Ci=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var he=class{constructor(t,e,i){this.code=t;this.interpolate=e;this.autoscale=i;t===0||(t===1?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):t===2?(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]]):t===3?(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]]):t===4?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):t===5?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):t===6&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}values=[];colors=[];entries=[];dirty=!0;addMapping(t,e,i,r){this.values.push(t),this.colors.push([e,i,r]),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,e===0)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){let[i,r]=this.entries[e-1],[s,o]=this.entries[e],n=(t-i)/(s-i),a=Math.floor((o[0]-r[0])*n+r[0]),l=Math.floor((o[1]-r[1])*n+r[1]),h=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,h]}else return this.entries[e-1][1]}getMinMax(){let t=Math.min.apply(Math,this.values),e=Math.max.apply(Math,this.values);return[t,e]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){let r=i+e>>1;if(t>this.entries[r][0])e=r+1;else if(t<this.entries[r][0])i=r-1;else return r}return-e-1}};var hn="macros",st=class c extends M{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new ae(hn))}expandContainerMacros(t){for(let e in this.macros.macros)t=t.replace(`$(${e})`,this.macros.macros[e]),t=t.replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(let e of this.widgets){if(e.wuid===t)return e;if(e instanceof c){let i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(let e of this.widgets){if(e.name===t)return e;if(e instanceof c){let i=e.findWidgetByName(t);if(i)return i}}for(let e of this.connections)if(e.name===t)return e}hide(){for(let t of this.widgets)t.hide()}autoScale(t,e){super.autoScale(t,e);for(let i of this.widgets)i.autoScale(t,e)}destroy(){for(let t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue(hn)}};var Ai=class{constructor(t,e){this.action=t;this.widget=e}getPropertyValue(t){let e=this.action.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){let i=this.action.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i instanceof T?(e=e!==void 0?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}};var Oi=class{constructor(t){this.array=t}get(t){return this.array[t]}};var Yt=class{constructor(t){this._pv=t}listeners=new Map;getName(){return this._pv.name}getValue(){return this._pv.value??null}setValue(t,e){this._pv.pvEngine.setValue(new Date,this._pv.name,t)}isConnected(){return!this._pv.disconnected}isWriteAllowed(){return this._pv.writable}addListener(t){let e=()=>{t.valueChanged(this)};this.listeners.set(t,e),this._pv.addListener(e)}removeListener(t){let e=this.listeners.get(t);e&&(this._pv.removeListener(e),this.listeners.delete(t))}};var Bt=class c{constructor(t){this.widget=t}getWidget(){return this.widget}executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){let e=this.widget.display.getPV(t);return e?new Yt(e):null}getPV(t="pv_name"){let e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getChild(t){if(this.widget instanceof st){let e=this.widget.widgets.find(i=>i.name===t);if(e)return new c(e)}return null}getHookedActions(){let t=this.widget.getHookedActions().map(e=>new Ai(e,this.widget));return new Oi(t)}getVar(t){return this.widget.vars.get(t)??null}setVar(t,e){this.widget.vars.set(t,e)}getPropertyValue(t){let e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){let i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof T)e=e!==void 0?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof ne){let r=0;switch(e){case"GrayScale":r=1;break;case"JET":r=2;break;case"ColorSpectrum":r=3;break;case"Hot":r=4;break;case"Cool":r=5;break;case"Shaded":r=6;break}let s=new he(r,!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)}setEnabled(t){this.setPropertyValue("enabled",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){return this.widget.value??null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}};var Ei=class extends Bt{constructor(e){super(e);this.array=e}getArrayFigure(){return{getIndex:()=>this.array.getScrollIndex(),setIndex:e=>this.array.setScrollIndex(e),getArrayLength:()=>this.array.effectiveArrayLength}}getIndex(e){return this.array.widgets.indexOf(e.getWidget())}getArrayLength(){return this.array.effectiveArrayLength}setArrayLength(e){this.array.properties.setValue("array_length",e)}getDataType(){return this.array.dataType}setDataType(e){this.array.properties.setValue("data_type",e)}isHorizontal(){return this.array.horizontal}isShowSpinner(){return this.array.showSpinner}isShowScrollbar(){return this.array.showScrollbar}getSpinnerWidth(){return this.array.spinnerWidth}getVisibleElementsCount(){return this.array.vec}};var Mi=class{constructor(t,e){this.spreadsheet=t;this.scriptEngine=e}addModifiedListener(t){}addSelectionChangedListener(t){this.spreadsheet.addSelectionChangedListener(()=>{this.scriptEngine.schedule(()=>{let e=t.selectionChanged;e(this.spreadsheet.getSelection())})})}appendRow(){return this.spreadsheet.appendRow()}deleteColumn(t){this.spreadsheet.deleteColumn(t)}deleteRow(t){this.spreadsheet.deleteRow(t)}getCellText(t,e){return this.spreadsheet.getCellText(t,e)}getColumnCount(){return this.spreadsheet.getColumnCount()}getContent(){return this.spreadsheet.getContent()}getRowCount(){return this.spreadsheet.getRowCount()}getSelection(){return this.spreadsheet.getSelection()}insertColumn(t){this.spreadsheet.insertColumn(t)}insertRow(t){this.spreadsheet.insertRow(t)}isEmpty(){return this.spreadsheet.isEmpty()}refresh(){this.spreadsheet.refresh()}setCellBackground(t,e,i){this.spreadsheet.setCellBackground(t,e,i)}setCellForeground(t,e,i){this.spreadsheet.setCellForeground(t,e,i)}setCellText(t,e,i){this.spreadsheet.setCellText(t,e,i)}setColumnCellEditorData(t,e){this.spreadsheet.setColumnCellEditorData(t,e)}setColumnsCount(t){this.spreadsheet.setColumnsCount(t)}setContent(t){this.spreadsheet.setContent(t)}setRowBackground(t,e){this.spreadsheet.setRowBackground(t,e)}setRowForeground(t,e){this.spreadsheet.setRowForeground(t,e)}revealRow(t){}};var Vi=class extends Bt{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new Mi(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var Ii=class extends Bt{xyGraph;constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map(i=>i.x)}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map(i=>i.y)}};function Bi(c,t){switch(c.widgetType){case"Array":return new Ei(c);case"Table":return new Vi(c,t);case"XY Graph":return new Ii(c);default:return new Bt(c)}}var Hi=class{constructor(t,e){this.display=t;this.scriptEngine=e}isActive(){return!0}getWidget(t){let e=this.display.findWidgetByName(t);if(e)return Bi(e,this.scriptEngine)}};var Di=class{constructor(t,e){this.display=t;this.scriptEngine=e}readTextFile(t,e){let i=this.display.resolvePath(t,e?.getWidget());var r=new XMLHttpRequest;if(r.open("GET",i,!1),r.send(null),r.status===200)return r.responseText;throw Error(`Cannot open ${i}`)}readTextFileAsync(t,e,i,r){let s=this.display.resolvePath(t,e?.getWidget());this.display.loadContent(s).then(o=>{o!==null?this.scriptEngine.schedule(()=>i(o)):this.fail(`Cannot open ${s}`,r)},o=>this.fail(`Cannot open ${s}: ${o}`,r))}fail(t,e){e?this.scriptEngine.schedule(()=>e(t)):this.display.getConsoleHandler().writeError(t)}};var Wi=class{constructor(t,e){this.display=t;this.scriptEngine=e}fullScreen(){document.documentElement.requestFullscreen()}openConfirmDialog(t){return this.display.getDialogHandler().openConfirmDialog("Confirm Dialog",t)}openConfirmDialogAsync(t,e){let i=this.display.getDialogHandler();nt(i,"Confirm Dialog",t).then(r=>this.scriptEngine.schedule(()=>e(r)))}openInformationDialog(t){this.display.getDialogHandler().openInformationDialog("Information",t)}openWarningDialog(t){this.display.getDialogHandler().openWarningDialog("Warning",t)}openErrorDialog(t){this.display.getDialogHandler().openErrorDialog("Error",t)}openPasswordDialog(t,e){return this.display.getDialogHandler().openPasswordDialog("Password Input Dialog",t,e)}openPasswordDialogAsync(t,e,i){let r=this.display.getDialogHandler();Ut(r,"Password Input Dialog",t,e).then(s=>this.scriptEngine.schedule(()=>i(s)))}};var ki=class{constructor(t){this.display=t}openInformation(t,e,i){this.display.getDialogHandler().openInformationDialog(e,i)}openConfirm(t,e,i){return this.display.getDialogHandler().openConfirmDialog(e,i)}openError(t,e,i){this.display.getDialogHandler().openErrorDialog(e,i)}};var ux=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],Ni=class{constructor(t){this.display=t;this.pvEngine=t.pvEngine}pvEngine;checkPVValue(t){if(t.getValue()===null)throw new Error(`PV ${t.getName()} has no value.`)}createPV(t,e){let i=this.pvEngine.createPV(t);return new Yt(i)}writePV(t,e,i){this.pvEngine.createPV(t),this.pvEngine.setValue(new Date,t,e)}getDouble(t){this.checkPVValue(t);let e=t._pv.toNumber();return parseFloat(e??t.getValue())}getDoubleArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>parseFloat(i)):[parseFloat(e)]}getLong(t){this.checkPVValue(t);let e=t._pv.toNumber();return typeof e=="number"&&(e=Math.floor(e)),parseInt(e??t.getValue(),10)}getLongArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>(typeof i=="number"&&(i=Math.floor(i)),parseInt(i,10))):(typeof e=="number"&&(e=Math.floor(e)),[parseInt(e,10)])}getString(t){return this.checkPVValue(t),xe(t._pv.value,0,-1,t._pv.typeHint)}getStringArray(t){this.checkPVValue(t);let e=t.getValue();return Array.isArray(e)?e.map(i=>String(i)):[String(e)]}getTimeInMilliseconds(t){return this.checkPVValue(t),t._pv.time?.getTime()??0}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){this.checkPVValue(t);let i=t._pv.time;if(i){let r=e;for(let s of ux)r=r.replace(s,this.formatDate(i,s));return r}return null}getSeverity(t){switch(this.checkPVValue(t),t._pv.severity){case"NONE":return 0;case"MAJOR":return 1;case"MINOR":return 2;default:return-1}}getSeverityString(t){return this.checkPVValue(t),String(t._pv.severity)}getStatus(t){return this.checkPVValue(t),t._pv.alarmName}getUnits(t){return this.checkPVValue(t),t._pv.units||null}formatDate(t,e){let{utc:i}=this.display;if(e==="yyyy")return String(i?t.getUTCFullYear():t.getFullYear());if(e==="MM"){let r=(i?t.getUTCMonth():t.getMonth())+1;return r<10?"0"+r:""+r}else if(e==="dd"){let r=i?t.getUTCDate():t.getDate();return r<10?"0"+r:""+r}else if(e==="HH"){let r=i?t.getUTCHours():t.getHours();return r<10?"0"+r:""+r}else if(e==="mm"){let r=i?t.getUTCMinutes():t.getMinutes();return r<10?"0"+r:""+r}else if(e==="ss"){let r=i?t.getUTCSeconds():t.getSeconds();return r<10?"0"+r:""+r}else if(e==="nnnnnnnnn"){let r=i?t.getUTCMilliseconds():t.getMilliseconds();return r<10?"00"+r:r<100?"0"+r:""+r}else throw new Error(`Unexpected format '${e}'`)}};var Fi=class{constructor(t){this.display=t}openOPI(t,e,i,r){if(i===0){let s=this.display.resolvePath(e,t?.getWidget()),o={path:e,absolutePath:this.display.toRootPath(s),replace:i===0};this.display.fireEvent("opendisplay",o)}else throw new Error(`Unsupported target ${i}`)}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}};function cn(c){let t=c.widget,e=c.widget.display,i=function(h){this.run=h.run},r=function(h){this.runnable=h};r.prototype.start=function(){c.schedule(()=>this.runnable.run())},r.sleep=function(h){let p=Date.now(),d=0;for(;Date.now()<p+h;)d++;d||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(h,p){c.schedule(h,p)};let o=function(h){this.valueChanged=p=>{c.schedule(()=>{let d=h.valueChanged;d(p)})}},l={ITableModifiedListener:function(h){this.modified=p=>{let d=h.modified;d(p)}},ITableSelectionChangedListener:function(h){this.selectionChanged=p=>{let d=h.selectionChanged;d(p)}}};return{display:new Hi(t.display,c),widget:Bi(t,c),java:{lang:{Runnable:i,Thread:r},util:{Timer:s}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:l}}}},yamcs:{studio:{data:{IPVListener:o}}}},ColorFontUtil:new Si,ConsoleUtil:new Li(e),DataUtil:new Ci,FileUtil:new Di(e,c),GUIUtil:new Wi(e,c),MessageDialog:new ki(e),PVUtil:new Ni(e),ScriptUtil:new Fi(e),SpreadSheetTable:l,Java:{type:function(h){switch(h){case"java.lang.Runnable":return i;case"java.lang.Thread":return r;case"java.util.Timer":return s;case"org.csstudio.swt.widgets.natives.SpreadSheetTable":return l;case"org.yamcs.studio.data.IPVListener":return o;default:throw new Error("Unexpected class name: "+h)}},to:function(h,p){return h}}}}var zt=class{constructor(t,e,i=[]){this.widget=t;this.scriptText=e;this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context={pvs:i.map(r=>new Yt(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...cn(this)}}context;run(t){window.setTimeout(()=>{if(this.context.triggerPV=null,t)for(let e of this.context.pvs)e._pv===t&&(this.context.triggerPV=e);this.runWithContext(()=>{(0,eval)(this.scriptText)})})}schedule(t,e){window.setTimeout(()=>this.runWithContext(t),e)}runWithContext(t){let e=[];for(let i in window)e.push(i);try{for(let r in this.context)this.context.hasOwnProperty(r)&&(window[r]=this.context[r]);t();let i={};for(let r in window)e.indexOf(r)===-1&&(i[r]=window[r]);this.context=i}finally{for(let i in window)e.indexOf(i)===-1&&delete window[i]}}};var pn="path",dn="embedded",un="scriptText",Gi=class extends et{constructor(){super(),this.properties.add(new T(pn,"")),this.properties.add(new f(dn,!1)),this.properties.add(new T(un,""))}execute(t){this.embedded?new zt(t,this.scriptText).run():t.display.getScriptLoader().load(t.resolvePath(this.path)).then(i=>{i&&new zt(t.display.instance,i).run()})}get path(){return this.properties.getValue(pn)}get embedded(){return this.properties.getValue(dn)}get scriptText(){return this.properties.getValue(un)}getDefaultDescription(){return"Execute JavaScript"}};var gn="macros",mn="mode",fn="path",$i=class extends et{constructor(){super(),this.properties.add(new T(fn,"")),this.properties.add(new ae(gn)),this.properties.add(new P(mn,0))}execute(t){let e={...this.macros.macros},i=t.display,r={path:this.path,absolutePath:i.toRootPath(t.resolvePath(this.path)),replace:this.mode===0,args:e};i.fireEvent("opendisplay",r)}get macros(){return this.properties.getValue(gn)}get path(){return this.properties.getValue(fn)}get mode(){return this.properties.getValue(mn)}getDefaultDescription(){return`Open ${this.path}`}};var wn="path",Ui=class extends et{constructor(){super(),this.properties.add(new T(wn,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(wn)}getDefaultDescription(){return`Open ${this.path}`}};var xn="hyperlink",Yi=class extends et{constructor(){super(),this.properties.add(new T(xn,"http://"))}execute(t){this.hyperlink&&window.parent.postMessage({type:"openwebpage",url:this.hyperlink},"*")}get hyperlink(){return this.properties.getValue(xn)}getDefaultDescription(){return`Open Webpage ${this.hyperlink}`}};var yn="path",zi=class extends et{constructor(){super(),this.properties.add(new T(yn,""))}execute(t){this.path&&new Audio(t.resolvePath(this.path)).play()}get path(){return this.properties.getValue(yn)}getDefaultDescription(){return`Play WAV File ${this.path}`}};var Pn="command",bn="args",vn="confirm_message",Xi=class extends et{constructor(){super(),this.properties.add(new T(Pn,"")),this.properties.add(new le(bn,{})),this.properties.add(new T(vn,""))}execute(t){if(this.confirmMessage){let e=t.display.getDialogHandler();return nt(e,"Confirm Dialog",this.confirmMessage).then(i=>{i&&this.run(t)})}this.run(t)}run(t){let e=t.expandMacro(this.command),i={};for(let s in this.args)i[s]=t.expandMacro(this.args[s]);let r={command:e,args:i};t.display.fireEvent("runcommand",r)}get command(){return this.properties.getValue(Pn)}get args(){return this.properties.getValue(bn)}get confirmMessage(){return this.properties.getValue(vn)}getDefaultDescription(){return`Run ${this.command}`}};var Rn="procedure",_n="args",Tn="confirm_message",qi=class extends et{constructor(){super(),this.properties.add(new T(Rn,"")),this.properties.add(new le(_n,{})),this.properties.add(new T(Tn,""))}execute(t){if(this.confirmMessage){let e=t.display.getDialogHandler();return nt(e,"Confirm Dialog",this.confirmMessage).then(i=>{i&&this.run(t)})}this.run(t)}run(t){let e={procedure:this.procedure,args:this.args};t.display.fireEvent("runprocedure",e)}get procedure(){return this.properties.getValue(Rn)}get args(){return this.properties.getValue(_n)}get confirmMessage(){return this.properties.getValue(Tn)}getDefaultDescription(){return`Run ${this.procedure}`}};var Sn="path",Ln="confirm_message",Ki=class extends et{constructor(){super(),this.properties.add(new T(Sn,"")),this.properties.add(new T(Ln,""))}execute(t){if(this.confirmMessage){let e=t.display.getDialogHandler();return nt(e,"Confirm Dialog",this.confirmMessage).then(i=>{i&&this.run(t)})}this.run(t)}run(t){let e=t.resolvePath(this.path),i={path:e,absolutePath:t.display.toRootPath(e)};t.display.fireEvent("runstack",i)}get path(){return this.properties.getValue(Sn)}get confirmMessage(){return this.properties.getValue(Ln)}getDefaultDescription(){return`Run ${this.path}`}};var Cn="pv_name",An="value",On="timeout",En="confirm_message",ji=class extends et{constructor(){super(),this.properties.add(new T(Cn,"$(pv_name)")),this.properties.add(new T(An,"")),this.properties.add(new P(On,10)),this.properties.add(new T(En,""))}execute(t){if(this.confirmMessage){let e=t.display.getDialogHandler();return nt(e,"Confirm Dialog",this.confirmMessage).then(i=>{i&&this.run(t)})}this.run(t)}run(t){if(this.pvName){let e=t.expandMacro(this.pvName);t.display.pvEngine.createPV(e),t.display.pvEngine.setValue(new Date,e,this.value)}}get pvName(){return this.properties.getValue(Cn)}get value(){return this.properties.getValue(An)}get timeout(){return this.properties.getValue(On)}get confirmMessage(){return this.properties.getValue(En)}getDefaultDescription(){return`Write ${this.value} to ${this.pvName}`}};var Zi=class{includeParentMacros=!0;macros={};clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}};var Ce=class c{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){let i=new DOMParser().parseFromString(t,"text/xml");return new c(i.documentElement)}getNode(t){let e=this.findChild(t);return new c(e)}getNodes(t){let e=[];for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];r.nodeType!==3&&(!t||r.nodeName===t)&&e.push(new c(r))}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 i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return r.textContent}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseFloat(r.textContent)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseInt(r.textContent,10)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t)return r.textContent==="true"}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){let i=this.node.attributes.getNamedItem(t);if(i===null){if(e!==void 0)return e;throw new Error(`No attribute named ${t}`)}else return i.textContent==="true"}getColor(t,e){let i=this.findChild(t);for(let r=0;r<i.childNodes.length;r++){let s=i.childNodes[r];if(s.nodeName==="color")return this.parseColorNode(new c(s))}if(e!==void 0)return e;throw new Error("No child node named 'color' could be found")}getFont(t){let e=this.getNode(t);if(e.hasNode("opifont.name")){let i=e.getNode("opifont.name"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new X(r,s,o,n)}else{let i=e.getNode("fontdata"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new X(r,s,o,n)}}getPoints(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("point"))i.push({x:r.getIntAttribute("x"),y:r.getIntAttribute("y")});return i}getStringList(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("s"))i.push(r.getTextContent());return i}getStringMap(t){let e=this.getNode(t),i={};for(let r of e.getNodes())i[r.name]=e.getString(r.name);return i}getStringTable(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("row")){let s=[];for(let o of r.getNodes("col"))s.push(o.getTextContent());i.push(s)}return i}getMatrix(t){let e=this.getNode(t),i=[];for(let r of e.getNodes("row")){let s=[];for(let o of r.getNodes("col"))s.push(Number(o.getTextContent()));i.push(s)}return i}getScripts(t){let e=this.getNode(t),i=new Le;for(let r of e.getNodes("path")){let s=[];for(let n of r.getNodes("pv"))s.push({pvName:n.getTextContent(),trigger:n.getBooleanAttribute("trig")});let o=r.getStringAttribute("pathString");o==="EmbeddedJs"?i.scripts.push({embedded:!0,text:r.getString("scriptText"),checkConnect:r.getBooleanAttribute("checkConnect"),skipFirstExecution:r.getBooleanAttribute("sfe",!1),inputs:s}):o==="EmbeddedPy"?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:o,checkConnect:r.getBooleanAttribute("checkConnect"),skipFirstExecution:r.getBooleanAttribute("sfe",!1),inputs:s})}return i}getScaleOptions(t){let e=this.getNode(t);return new J(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new Se(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){let e=this.getNode(t);if(e.hasNode("e")){let i=new he(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(let r of e.getNodes("e")){let s=Number(r.getTextContent()),o=r.getIntAttribute("red"),n=r.getIntAttribute("green"),a=r.getIntAttribute("blue");i.addMapping(s,o,n,a)}}else return new he(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"))}getRules(t){let e=this.getNode(t),i=new Te;for(let r of e.getNodes("rule")){let s=[];for(let n of r.getNodes("pv"))s.push({pvName:n.getTextContent(),trigger:n.getBooleanAttribute("trig")});let o=[];for(let n of r.getNodes("exp"))if(n.getNode("value").hasNode("color"))o.push({type:"color",expression:n.getStringAttribute("bool_exp"),outputValue:n.getColor("value")});else{let l=n.getString("value");l.trim()!==""&&o.push({type:"string",expression:n.getStringAttribute("bool_exp"),outputValue:l})}i.rules.push({name:r.getStringAttribute("name"),propertyName:r.getStringAttribute("prop_id"),outputExpression:r.getBooleanAttribute("out_exp"),inputs:s,expressions:o})}return i}getMacros(t){let e=this.getNode(t),i=new Zi;i.includeParentMacros=e.getBoolean("include_parent_macros");for(let r of e.getNodes())r.name!=="include_parent_macros"&&i.set(r.name,e.getString(r.name));return i}getActions(t){let e=this.getNode(t),i=new ve;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(let r of e.getNodes("action")){let s=r.getStringAttribute("type");if(s==="OPEN_DISPLAY"){let o=new $i;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new Ui;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new Ti;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_JAVASCRIPT"){let o=new Gi;o.parseNode(r),i.add(o)}else if(s==="WRITE_PV"){let o=new ji;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new zi;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new Yi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new Xi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new Ki;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new qi;o.parseNode(r),i.add(o)}else console.warn(`Unsupported action type ${s}`),i.add(null)}return i}parseColorNode(t){let e=t.getIntAttribute("red"),i=t.getIntAttribute("green"),r=t.getIntAttribute("blue");return new m(e,i,r)}cloneWithOverrides(t){let e=this.node.cloneNode(!0);if(t.pvName!==void 0)for(let i of Array.from(e.querySelectorAll("pv_name")))i.textContent=t.pvName;if(t.wuidSuffix)for(let i of Array.from(e.querySelectorAll("wuid")))i.textContent=(i.textContent||"")+t.wuidSuffix;return new c(e)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){let i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}};var Mn="arrow_length",Vn="arrows",In="fill_arrow",Bn="name",Hn="line_color",Dn="line_jump_add",Wn="line_jump_size",kn="line_jump_style",Nn="line_style",Fn="line_width",Gn="src_wuid",$n="src_term",Un="tgt_wuid",Yn="tgt_term",zn="router",Xn="points",gx="wuid",qn=0,mx=1,fx=2,Kn=0;var wx=2,xx=3,yx=.577350269,Xt="LEFT",qt="UP",Kt="DOWN",jt="RIGHT",Qi=class extends M{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(Mn)),this.properties.add(new P(Vn)),this.properties.add(new f(In)),this.properties.add(new T(Bn)),this.properties.add(new L(Hn)),this.properties.add(new P(Dn,qn)),this.properties.add(new P(Wn,10)),this.properties.add(new P(kn,Kn)),this.properties.add(new P(Nn)),this.properties.add(new P(Fn)),this.properties.add(new T(Gn)),this.properties.add(new T($n)),this.properties.add(new T(Un)),this.properties.add(new T(Yn)),this.properties.add(new P(zn)),this.properties.add(new kt(Xn)),this.properties.add(new T(gx))}async 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):this.router===0?this.drawManhattanConnection(t):this.router===1&&this.drawDirectConnection(t))}drawPath(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),r=[e,...this.points,i],s=r.length-1,o=[...r];(this.arrows===1||this.arrows===3)&&(o[0]=this.getShaftEnd(r[1],r[0])),(this.arrows===2||this.arrows===3)&&(o[s]=this.getShaftEnd(r[s-1],r[s]));let n=pt(o,.5*this.scale,.5*this.scale);this.strokeJumpAwarePath(t,n,this.getDashArray()),this.drawStartArrow(t,r[1],r[0]),this.drawStopArrow(t,r[s-1],r[s])}drawManhattanConnection(t){let e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),r=this.route(e,i),s=r.length-1,o=[...r];(this.arrows===1||this.arrows===3)&&(o[s]=this.getShaftEnd(r[s-1],r[s])),(this.arrows===2||this.arrows===3)&&(o[0]=this.getShaftEnd(r[1],r[0])),this.lineWidth&&this.strokeJumpAwarePath(t,o,this.getDashArray()),this.drawStartArrow(t,r[s-1],r[s]),this.drawStopArrow(t,r[1],r[0])}getShaftEnd(t,e){return this.fillArrow?this.calculateArrowPoints(t,e)[2]:e}getDashArray(){let{scale:t}=this;if(this.lineWidth){if(this.lineStyle===0)return[];if(this.lineStyle===1)return[6*t,2*t];if(this.lineStyle===2)return[2*t,2*t];if(this.lineStyle===3)return[6*t,2*t,2*t,2*t];if(this.lineStyle===4)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}getVertices(){if(!this.sourceWidget||!this.targetWidget)return[];if(this.points.length){let t=this.getPosition(this.sourceWidget,this.sourceTerm),e=this.getPosition(this.targetWidget,this.targetTerm);return[t,...this.points,e]}else if(this.router===0){let t=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),e=this.getManhattanAnchor(this.targetWidget,this.targetTerm);return this.route(t,e)}else if(this.router===1){let t=this.getPosition(this.sourceWidget,this.sourceTerm),e=this.getPosition(this.targetWidget,this.targetTerm);return[t,e]}return[]}strokeJumpAwarePath(t,e,i){if(this.lineJumpAdd===qn||e.length<2){t.strokePath({path:_.fromPoints(e),lineWidth:this.lineWidth,color:this.lineColor,dash:i});return}for(let r of this.buildJumpAwareRuns(e))r.length<2||t.strokePath({path:_.fromPoints(r),lineWidth:this.lineWidth,color:this.lineColor,dash:i})}buildJumpAwareRuns(t){let e=[],i=[];for(let o of this.display.instance?.connections??[])o!==this&&i.push(o.getVertices());let r=[t[0]],s=0;for(;s+1<t.length;){let o=t[s],n=s+1,a=t[n],l=n+1;for(;l<t.length;){let h=t[l];if(h.x===o.x||h.y===o.y)a=h,n=l,l++;else break}for(let h of this.findCrossings(o,a,i))switch(r.push(h.notch1),this.lineJumpStyle){case Kn:r.push(...vx(h.point,this.lineJumpSize,[h.notch1,h.notch2])),r.push(h.notch2);break;case wx:r.push(...bx(h.notch1,h.notch2),h.notch2);break;case xx:r.push(Px(h.notch1,h.notch2),h.notch2);break;default:e.push(r),r=[h.notch2]}r.push(a),s=n}return e.push(r),e}findCrossings(t,e,i){let r=t.y===e.y,s=t.x===e.x;if(r&&this.lineJumpAdd!==mx)return[];if(s&&this.lineJumpAdd!==fx)return[];if(!r&&!s)return[];let o=this.lineJumpSize,n=t.x,a=t.y,l=e.x,h=e.y,p=[];for(let d of i)for(let g=0;g+1<d.length;g++){let x=d[g],w=d[g+1],v=x.x,S=x.y,A=w.x,C=w.y,V=(n-l)*(S-C)-(a-h)*(v-A);if(V===0)continue;let D={x:((n*h-a*l)*(v-A)-(n-l)*(v*C-S*A))/V,y:((n*h-a*l)*(S-C)-(a-h)*(v*C-S*A))/V};if(Ue(D,t)<o||Ue(D,e)<o||!Ji(D,t,e)||!Ji(D,x,w))continue;let N=jn(D,t,o),$=jn(D,e,o);p.push({point:D,notch1:Ji(N,t,e)?N:t,notch2:Ji($,t,e)?$:e,distance:Ue(t,D)})}return p.sort((d,g)=>d.distance-g.distance),p}drawDirectConnection(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);if(this.lineWidth){let r=e,s=i;(this.arrows===1||this.arrows===3)&&(r=this.getShaftEnd(i,e)),(this.arrows===2||this.arrows===3)&&(s=this.getShaftEnd(e,i)),this.strokeJumpAwarePath(t,[r,s],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=qt;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=Kt;break;case"LEFT":i=Xt;break;case"RIGHT":i=jt;break;default:}let r=t.bounds,s=this.getPosition(t,e),o=s.x-r.x,n=r.x+r.width-s.x,a=s.y-r.y,l=r.y+r.height-s.y;return Math.min(o,n)<Math.min(a,l)?i=o<n?Xt:jt:i=a<l?qt:Kt,{x:s.x,y:s.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:let i=parseInt(e,10),r=t.properties.getProperty("points");if(r){let s=r.value;return s=oe(s,this.scale),s[i]}else throw Error(`Unexpected term ${e}`)}}route(t,e){let i=t.x-e.x,r=t.y-e.y,s={x:0,y:0},o,n,a=[],{tolxtol:l,tol:h,minDist:p}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===Xt?i>0&&r*r<h&&e.direction===jt?(s=e,o=e.direction):(i<0?s={x:t.x-p,y:t.y}:r>0&&e.direction===Kt||r<0&&e.direction===qt?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.min(t.x,e.x)-p,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=qt:o=Kt):t.direction===jt?i<0&&r*r<h&&e.direction===Xt?(s=e,o=e.direction):(i>0?s={x:t.x+p,y:t.y}:r>0&&e.direction===Kt||r<0&&e.direction===qt?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.max(t.x,e.x)+p,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=qt:o=Kt):t.direction===Kt?i*i<h&&r<0&&e.direction===qt?(s=e,o=e.direction):(r>0?s={x:t.x,y:t.y+p}:i>0&&e.direction===jt||i<0&&e.direction===Xt?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.max(t.y,e.y)+p,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Xt:o=jt):t.direction===qt&&(i*i<h&&r>0&&e.direction===Kt?(s=e,o=e.direction):(r<0?s={x:t.x,y:t.y-p}:i>0&&e.direction===jt||i<0&&e.direction===Xt?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.min(t.y,e.y)-p,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Xt:o=jt));let d={...s,direction:o};return a=a.concat(this.route(d,e)),a.push(t),a}drawStartArrow(t,e,i){let r=t.ctx;if(this.arrows===1||this.arrows===3){let s=this.calculateArrowPoints(e,i);if(s[2]=i,this.fillArrow){r.fillStyle=this.lineColor.toString(),r.beginPath();for(let o=0;o<s.length;o++)o===0?r.moveTo(s[o].x,s[o].y):r.lineTo(s[o].x,s[o].y);r.fill()}else r.strokeStyle=this.lineColor.toString(),r.lineWidth=this.lineWidth,r.beginPath(),r.moveTo(i.x,i.y),r.lineTo(s[0].x,s[0].y),r.moveTo(i.x,i.y),r.lineTo(s[1].x,s[1].y),r.stroke()}}drawStopArrow(t,e,i){let r=t.ctx;if(this.arrows===2||this.arrows===3){let s=this.calculateArrowPoints(e,i);if(s[2]=i,this.fillArrow){r.fillStyle=this.lineColor.toString(),r.beginPath();for(let o=0;o<s.length;o++)o===0?r.moveTo(s[o].x,s[o].y):r.lineTo(s[o].x,s[o].y);r.fill()}else r.strokeStyle=this.lineColor.toString(),r.lineWidth=this.lineWidth,r.beginPath(),r.moveTo(i.x,i.y),r.lineTo(s[0].x,s[0].y),r.moveTo(i.x,i.y),r.lineTo(s[1].x,s[1].y),r.stroke()}}calculateArrowPoints(t,e){let i=wi(e,t),r=Math.PI/10,s=new Tt(this.arrowLength,i.theta-r),o=new Tt(this.arrowLength,i.theta+r),n=new Tt(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=Dt(s.toPoint(),e.x,e.y),l=Dt(o.toPoint(),e.x,e.y),h=Dt(n.toPoint(),e.x,e.y);return[a,l,h]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(Bn)}get arrows(){return this.properties.getValue(Vn)}get fillArrow(){return this.properties.getValue(In)}get arrowLength(){return this.scale*this.properties.getValue(Mn)}get lineColor(){return this.properties.getValue(Hn)}get lineJumpAdd(){return this.properties.getValue(Dn)}get lineJumpSize(){return this.scale*this.properties.getValue(Wn)}get lineJumpStyle(){return this.properties.getValue(kn)}get lineStyle(){return this.properties.getValue(Nn)}get lineWidth(){return this.scale*this.properties.getValue(Fn)}get router(){return this.properties.getValue(zn)}get sourceTerm(){return this.properties.getValue($n)}get sourceWuid(){return this.properties.getValue(Gn)}get targetTerm(){return this.properties.getValue(Yn)}get targetWuid(){return this.properties.getValue(Un)}get points(){return oe(this.properties.getValue(Xn),this.scale)}};function Ji(c,t,e,i=1e-6){return c.x>=Math.min(t.x,e.x)-i&&c.x<=Math.max(t.x,e.x)+i&&c.y>=Math.min(t.y,e.y)-i&&c.y<=Math.max(t.y,e.y)+i}function jn(c,t,e){let i=Ue(c,t);if(Math.round(i)===0)return t;let r=e/i;return{x:(1-r)*c.x+r*t.x,y:(1-r)*c.y+r*t.y}}function Zn(c,t,e){let i=t.x-c.x,r=t.y-c.y,s=Math.sqrt(i*i+r*r);if(s===0)return{x:c.x,y:c.y};let o=i/s,n=r/s,a=Math.sqrt(3)/2*s,l=c.x+i*.5,h=c.y+r*.5,p=-n,d=o;return e?{x:l+a*p,y:h+a*d}:{x:l-a*p,y:h-a*d}}function Px(c,t){let e=Zn(c,t,!0);return e.x>c.x?Zn(c,t,!1):e}function bx(c,t){let e=yx,i=c.x-e*(t.y-c.y),r=c.y-e*(t.x-c.x);Math.abs(c.x-t.x)<5&&i>c.x&&(i=c.x-Math.abs(c.x-i)),Math.abs(c.y-t.y)<5&&r>c.y&&(r=c.y-Math.abs(c.y-r));let s=t.x+e*(c.y-t.y),o=t.y+e*(c.x-t.x);return Math.abs(c.x-t.x)<5&&s>t.x&&(s=t.x-Math.abs(t.x-s)),Math.abs(c.y-t.y)<5&&o>t.y&&(o=t.y-Math.abs(t.y-o)),[{x:i,y:r},{x:s,y:o}]}function vx(c,t,[e,i],r=16){let s=e.y===i.y,o,n;if(s){let l=e.x<i.x;o=l?Math.PI:2*Math.PI,n=l?2*Math.PI:Math.PI}else{let l=e.y<i.y;o=l?Math.PI/2:3*Math.PI/2,n=l?3*Math.PI/2:Math.PI/2}let a=[];for(let l=1;l<r;l++){let h=o+(n-o)*l/r;a.push({x:c.x+t*Math.cos(h),y:c.y+t*Math.sin(h)})}return a}var ea="x",ia="y",Ms="width",Vs="height",Rx="visible",Jn="fill_grids",Qn="grid_gap",ta="number_of_columns",ti=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(ea,0)),this.properties.add(new P(ia,0)),this.properties.add(new P(Ms,16)),this.properties.add(new P(Vs,16)),this.properties.add(new f(Rx,!1)),this.properties.add(new P(ta,3)),this.properties.add(new f(Jn,!1)),this.properties.add(new P(Qn,2))}get numberOfColumns(){return this.properties.getValue(ta)}get fillGrids(){return this.properties.getValue(Jn)}get gridGap(){return this.properties.getValue(Qn)}draw(t){}};function tr(c){let t=c.findIndex(d=>d instanceof ti);if(t===-1)return;let e=c[t];if(!e.enabled)return;let i=c.filter((d,g)=>g!==t);if(!i.length)return;let r=Math.max(1,e.numberOfColumns||1),s=Math.ceil(i.length/r),o=e.gridGap,n=e.fillGrids,a=new Array(r).fill(0),l=new Array(s).fill(0);i.forEach((d,g)=>{let x=g%r,w=Math.floor(g/r);a[x]=Math.max(a[x],d.properties.getValue(Ms)),l[w]=Math.max(l[w],d.properties.getValue(Vs))});let h=[0];for(let d=1;d<r;d++)h.push(h[d-1]+a[d-1]+o);let p=[0];for(let d=1;d<s;d++)p.push(p[d-1]+l[d-1]+o);i.forEach((d,g)=>{let x=g%r,w=Math.floor(g/r);d.properties.setValue(ea,h[x]),d.properties.setValue(ia,p[w]),n&&(d.properties.setValue(Ms,a[x]),d.properties.setValue(Vs,l[w]))})}var _x=0,ra="auto_scale_widgets",Tx="width",Sx="height",Ae=class extends st{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new Ke(ra,new Se(!1,-1,-1)))}async parseNode(t){await super.parseNode(t);let e=_x++;this.macros.set("DID",`DID_${e}`);let i=this.properties.getValue("name");this.macros.set("DNAME",i);for(let r in this.displayArgs)this.macros.set(r,this.displayArgs[r]);for(let r of t.getNodes("widget")){let s=r.getString("widget_type"),o=this.display.createWidget(s,this);o&&(await o.parseNode(r),this.widgets.push(o))}tr(this.widgets);for(let r of t.getNodes("connection")){let s=new Qi(this.display);s.parseNode(r),this.connections.push(s)}}draw(t){for(let e of this.widgets.filter(i=>i.visible))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(let e of this.connections)e.draw(t);for(let e of this.widgets.filter(i=>i.visible))e.drawOverlay(t)}measureContentBounds(t){let e=this.widgets.filter(n=>n.visible);if(e.length===0)return{x:0,y:0,width:0,height:0};let i=1/0,r=1/0,s=-1/0,o=-1/0;for(let n of e){let a=t?n.bounds:n.unscaledBounds;i=Math.min(i,a.x),r=Math.min(r,a.y),s=Math.max(s,a.x+a.width),o=Math.max(o,a.y+a.height)}return{x:i,y:r,width:s-i,height:o-r}}get autoScaleWidgets(){return this.properties.getValue(ra)}get designSize(){return{width:this.properties.getValue(Tx),height:this.properties.getValue(Sx)}}};var Lx=0,sa="group_name",Is="opi_file",oa="resize_behaviour",Oe=class extends st{linkedDisplay;resolvedOpiFile;reloadGeneration=0;constructor(t,e){super(t,e),this.properties.add(new T(sa)),this.properties.add(new T(Is)),this.properties.add(new P(oa,0))}async parseNode(t){await super.parseNode(t);let e=Lx++;this.macros.set("LCID",`LCID_${e}`)}async init(){await this.reload(),this.addPropertyListener(Is,()=>this.reload())}async reload(){let t=++this.reloadGeneration;if(this.linkedDisplay&&(this.display.pvEngine.removeWidget(this.linkedDisplay),this.linkedDisplay.destroy(),this.linkedDisplay=void 0),this.opiFile){this.resolvedOpiFile=this.resolvePath(this.opiFile);let e=await this.display.loadContent(this.resolvedOpiFile);if(t!==this.reloadGeneration)return;if(e!==null){let i=new Ae(this.display,this),r=Ce.parseFromXML(e);if(await i.parseNode(r),t!==this.reloadGeneration){this.display.pvEngine.removeWidget(i),i.destroy();return}this.linkedDisplay=i}}else this.resolvedOpiFile=void 0;if(this.linkedDisplay&&this.resizeBehavior===1){let e=this.measureFrameBounds(!0);this.customSize={width:e.width,height:e.height}}this.requestRepaint()}draw(t){this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect({...this.area,color:this.linkedDisplay.backgroundColor}),this.resizeBehavior===0){let i=this.measureFrameBounds(!1),{width:r,height:s}=i,o=this.display.scale;r*=o,s*=o;let n=r/s,a=this.width,l=a/n,h=a/r;l>this.height&&(l=this.height,a=l*n,h=l/s),this.linkedDisplay.relativeScale=h;let p=t.createChildAt(this.x,this.y,a,l);p.translate(-i.x*h*o,-i.y*h*o),this.drawLinkedContent(p),t.copyChild(p)}else if(this.resizeBehavior===1){let i=this.measureFrameBounds(!0),r=t.createChildAt(this.x,this.y,i.width,i.height);r.translate(-i.x,-i.y),this.drawLinkedContent(r),t.copyChild(r)}else if(this.resizeBehavior===2){let i=this.measureFrameBounds(!0),r=t.createChildAt(this.x,this.y,i.width,i.height);r.translate(i.x,i.y),this.drawLinkedContent(r),t.copyChild(r)}else this.resizeBehavior===3&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}measureFrameBounds(t){let e=this.getLinkedWidget();return e&&e!==this.linkedDisplay?t?e.bounds:e.unscaledBounds:this.linkedDisplay?.measureContentBounds(t)??{x:0,y:0,width:0,height:0}}drawLinkedContent(t){let e=this.getLinkedWidget();e&&e!==this.linkedDisplay?e.visible&&(e.drawHolder(t),e.draw(t),e.drawDecoration(t),e.drawOverlay(t)):this.linkedDisplay&&this.linkedDisplay.draw(t)}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:[]}autoScale(t,e){M.prototype.autoScale.call(this,t,e)}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(Is)}get groupName(){return this.properties.getValue(sa)}get resizeBehavior(){return this.properties.getValue(oa)}};var er=class{constructor(t){this.display=t}resolve(t,e){if(t.startsWith("/"))return`${this.display.absPrefix}${t.slice(1)}`;if(/^[a-z][a-z0-9+.-]*:/i.test(t))return t;if(e){let i=e.parent;for(;i;){if(i instanceof Oe){let r=i.resolvedOpiFile,s=r.lastIndexOf("/")+1;return`${r.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}};var ir=class{constructor(t){this.display=t}cache=new Map;ttl=5e3;async load(t){this.removeOldEntries();let e=this.cache.get(t);if(e)return e.text;let i=await fetch(this.display.resolvePath(t),{credentials:"same-origin"});if(i.ok){let r=await i.text();return this.cache.set(t,{timestamp:Date.now(),text:r}),r}else return null}removeOldEntries(){let t=Date.now();this.cache.forEach((e,i)=>{e.timestamp+this.ttl<=t&&this.cache.delete(i)})}};var rr=class{constructor(t,e){this.pvName=t;this.formula=e}pvValues=new Map;updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){let t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":e.indexOf(t.value)===-1&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(let i of t.arguments)this.getExpressionParameters(i,e);break}}execute(){let t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":return t.value;case"ParameterLiteral":let e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConstantLiteral":return t.value;case"NumericLiteral":return t.value;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){let 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){let 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){let e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(t.alternate===void 0)return e?i:null;{let r=this.executeExpression(t.alternate);return e?i:r}}executeUnaryExpression(t){let 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){let e=t.callee.name,i=[];for(let r of t.arguments)i.push(this.executeExpression(r));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 i[0]*180/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){let e=this.pvValues.get(t);if(e)return e.acquisitionStatus}};var ei=class extends SyntaxError{constructor(t,e,i,r){super(t),this.expected=e,this.found=i,this.location=r,this.name="SyntaxError"}format(t){let e="Error: "+this.message;if(this.location){let i=null,r=t.find(a=>a.source===this.location.source);r&&(i=r.text.split(/\r\n|\n|\r/g));let s=this.location.start,o=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(s):s,n=this.location.source+":"+o.line+":"+o.column;if(i){let a=this.location.end,l="".padEnd(o.line.toString().length," "),h=i[s.line-1],d=(s.line===a.line?a.column:h.length+1)-s.column||1;e+=`
2
2
  --> `+n+`
3
3
  `+l+` |
4
4
  `+o.line+" | "+h+`
5
5
  `+l+" | "+"".padEnd(s.column-1," ")+"".padEnd(d,"^")}else e+=`
6
- at `+n}return e}static buildMessage(t,e){function i(d){return d.codePointAt(0).toString(16).toUpperCase()}let r=Object.prototype.hasOwnProperty.call(RegExp.prototype,"unicode")?new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]","gu"):null;function s(d){return r?d.replace(r,g=>"\\u{"+i(g)+"}"):d}function o(d){return s(d.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,g=>"\\x0"+i(g)).replace(/[\x10-\x1F\x7F-\x9F]/g,g=>"\\x"+i(g)))}function n(d){return s(d.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,g=>"\\x0"+i(g)).replace(/[\x10-\x1F\x7F-\x9F]/g,g=>"\\x"+i(g)))}let a={literal(d){return'"'+o(d.text)+'"'},class(d){let g=d.parts.map(w=>Array.isArray(w)?n(w[0])+"-"+n(w[1]):n(w));return"["+(d.inverted?"^":"")+g.join("")+"]"+(d.unicode?"u":"")},any(){return"any character"},end(){return"end of input"},other(d){return d.description}};function l(d){return a[d.type](d)}function h(d){let g=d.map(l);if(g.sort(),g.length>0){let w=1;for(let x=1;x<g.length;x++)g[x-1]!==g[x]&&(g[w]=g[x],w++);g.length=w}switch(g.length){case 1:return g[0];case 2:return g[0]+" or "+g[1];default:return g.slice(0,-1).join(", ")+", or "+g[g.length-1]}}function c(d){return d?'"'+o(d)+'"':"end of input"}return"Expected "+h(t)+" but "+c(e)+" found."}};function ia(p,t){t=t!==void 0?t:{};let e={},i=t.grammarSource,r={Start:bo},s=bo,o="=",n="false",a="true",l="pi",h="e",c=".",d="0",g='"',w="'",x="(",_=")",L=",",A="<=",E=">=",I="==",k="!=",F="&&",z="||",j=/^[\t ]/,wt=/^[A-Z_a-z]/,ct=/^[a-zA-Z0-9_]/,Ct=/^[0-9]/,ut=/^[1-9]/,Pt=/^[^\n\r\f"]/,bt=/^[^\n\r\f']/,Nt=/^[+\-]/,Qt=/^[%*\/\^]/,Ft=/^[<>]/,Ie=ot("=",!1),te=Vt([" "," "],!1,!1,!1),pe=ot("false",!0),ri=ot("true",!0),Be=ot("PI",!0),He=ot("E",!0),si=ie("identifier"),lo=Vt([["A","Z"],"_",["a","z"]],!1,!1,!1),oi=Vt([["a","z"],["A","Z"],["0","9"],"_"],!1,!1,!1),pt=ie("boolean"),At=ie("constant"),Gt=ie("number"),mt=ot(".",!1),ee=ot("0",!1),Ot=Vt([["0","9"]],!1,!1,!1),gt=Vt([["1","9"]],!1,!1,!1),xt=ie("string"),at=ot('"',!1),dt=Vt([`
7
- `,"\r","\f",'"'],!0,!1,!1),lt=ie("parameter"),Et=ot("'",!1),yt=Vt([`
8
- `,"\r","\f","'"],!0,!1,!1),Z=ot("(",!1),Mt=ot(")",!1),vt=Vt(["+","-"],!1,!1,!1),ho=ot(",",!1),co=Vt(["%","*","/","^"],!1,!1,!1),po=ot("<=",!1),uo=ot(">=",!1),go=Vt(["<",">"],!1,!1,!1),mo=ot("==",!1),fo=ot("!=",!1),wo=ot("&&",!1),xo=ot("||",!1);function hb(u){return u}function pw(u){return{type:"Formula",expression:u}}function cb(u){return u}function dw(u,b){return{type:"Symbol",name:u+b.join("")}}function uw(){return{type:"BooleanLiteral",value:!0}}function gw(){return{type:"BooleanLiteral",value:!1}}function mw(){return{type:"ConstantLiteral",value:Math.PI}}function fw(){return{type:"ConstantLiteral",value:Math.E}}function ww(){return{type:"NumericLiteral",value:parseFloat(fs())}}function xw(){return{type:"NumericLiteral",value:parseFloat(fs())}}function yw(){return{type:"NumericLiteral",value:parseFloat(fs())}}function Pw(u){return{type:"StringLiteral",value:u.join("")}}function bw(u){return{type:"ParameterLiteral",value:u.join("")}}function pb(u){return u}function vw(u,b){return{type:"UnaryExpression",operator:u,argument:b}}function Rw(u,b){return{type:"CallExpression",callee:u,arguments:b}}function _w(u){return rx(tx(u,0))}function Tw(u,b){return ex(u,b,3)}function Sw(u,b){return ai(u,b)}function Lw(u,b){return ai(u,b)}function Cw(u,b){return ai(u,b)}function Aw(u,b){return ai(u,b)}function Ow(u,b){return ix(u,b)}let y=t.peg$currPos|0,q=y,de=[{line:1,column:1}],Rt=y,ni=t.peg$maxFailExpected||[],W=t.peg$silentFails|0,De;if(t.startRule){if(!(t.startRule in r))throw new Error(`Can't start parsing from rule "`+t.startRule+'".');s=r[t.startRule]}function fs(){return p.substring(q,y)}function db(){return q}function ub(){return{source:i,start:q,end:y}}function gb(){return We(q,y)}function mb(u,b){throw b=b!==void 0?b:We(q,y),Po([ie(u)],p.substring(q,y),b)}function fb(u,b){throw b=b!==void 0?b:We(q,y),Vw(u,b)}function Ew(u=y){let b=p.codePointAt(u);return b===void 0?"":String.fromCodePoint(b)}function ot(u,b){return{type:"literal",text:u,ignoreCase:b}}function Vt(u,b,V,v){return{type:"class",parts:u,inverted:b,ignoreCase:V,unicode:v}}function wb(){return{type:"any"}}function Mw(){return{type:"end"}}function ie(u){return{type:"other",description:u}}function yo(u){let b=de[u],V;if(b)return b;if(u>=de.length)V=de.length-1;else for(V=u;!de[--V];);for(b=de[V],b={line:b.line,column:b.column};V<u;)p.charCodeAt(V)===10?(b.line++,b.column=1):b.column++,V++;return de[u]=b,b}function We(u,b,V){let v=yo(u),B=yo(b),O={source:i,start:{offset:u,line:v.line,column:v.column},end:{offset:b,line:B.line,column:B.column}};return V&&i&&typeof i.offset=="function"&&(O.start=i.offset(O.start),O.end=i.offset(O.end)),O}function N(u){y<Rt||(y>Rt&&(Rt=y,ni=[]),ni.push(u))}function Vw(u,b){return new Je(u,null,null,b)}function Po(u,b,V){return new Je(Je.buildMessage(u,b),u,b,V)}function bo(){let u,b,V,v,B;return u=y,p.charCodeAt(y)===61?(b=o,y++):(b=e,W===0&&N(Ie)),b!==e?(V=X(),v=Iw(),v!==e?(B=X(),q=u,u=v):(y=u,u=e)):(y=u,u=e),u}function Iw(){let u,b;return u=y,b=ke(),b!==e&&(q=u,b=pw(b)),u=b,u}function X(){let u,b;for(u=[],b=vo();b!==e;)u.push(b),b=vo();return u}function vo(){let u;return u=p.charAt(y),j.test(u)?y++:(u=e,W===0&&N(te)),u}function Bw(){let u;return u=p.substr(y,5),u.toLowerCase()===n?y+=5:(u=e,W===0&&N(pe)),u}function Hw(){let u;return u=p.substr(y,4),u.toLowerCase()===a?y+=4:(u=e,W===0&&N(ri)),u}function Dw(){let u;return u=p.substr(y,2),u.toLowerCase()===l?y+=2:(u=e,W===0&&N(Be)),u}function Ww(){let u;return u=p.charAt(y),u.toLowerCase()===h?y++:(u=e,W===0&&N(He)),u}function kw(){let u,b;return u=y,b=Nw(),b!==e&&(q=u,b=b),u=b,u}function Nw(){let u,b,V,v;if(W++,u=y,b=Fw(),b!==e){for(V=[],v=Ro();v!==e;)V.push(v),v=Ro();q=u,u=dw(b,V)}else y=u,u=e;return W--,u===e&&(b=e,W===0&&N(si)),u}function Fw(){let u;return u=p.charAt(y),wt.test(u)?y++:(u=e,W===0&&N(lo)),u}function Ro(){let u;return u=p.charAt(y),ct.test(u)?y++:(u=e,W===0&&N(oi)),u}function Gw(){let u;return u=$w(),u===e&&(u=Uw(),u===e&&(u=Yw(),u===e&&(u=Xw(),u===e&&(u=qw())))),u}function $w(){let u,b;return W++,u=y,b=Hw(),b!==e&&(q=u,b=uw()),u=b,u===e&&(u=y,b=Bw(),b!==e&&(q=u,b=gw()),u=b),W--,u===e&&(b=e,W===0&&N(pt)),u}function Uw(){let u,b;return W++,u=y,b=Dw(),b!==e&&(q=u,b=mw()),u=b,u===e&&(u=y,b=Ww(),b!==e&&(q=u,b=fw()),u=b),W--,u===e&&(b=e,W===0&&N(At)),u}function Yw(){let u,b,V,v,B;if(W++,u=y,b=_o(),b!==e)if(p.charCodeAt(y)===46?(V=c,y++):(V=e,W===0&&N(mt)),V!==e){for(v=[],B=ue();B!==e;)v.push(B),B=ue();q=u,u=ww()}else y=u,u=e;else y=u,u=e;if(u===e){if(u=y,p.charCodeAt(y)===46?(b=c,y++):(b=e,W===0&&N(mt)),b!==e){if(V=[],v=ue(),v!==e)for(;v!==e;)V.push(v),v=ue();else V=e;V!==e?(q=u,u=xw()):(y=u,u=e)}else y=u,u=e;u===e&&(u=y,b=_o(),b!==e&&(q=u,b=yw()),u=b)}return W--,u===e&&(b=e,W===0&&N(Gt)),u}function _o(){let u,b,V,v;if(p.charCodeAt(y)===48?(u=d,y++):(u=e,W===0&&N(ee)),u===e)if(u=y,b=zw(),b!==e){for(V=[],v=ue();v!==e;)V.push(v),v=ue();b=[b,V],u=b}else y=u,u=e;return u}function ue(){let u;return u=p.charAt(y),Ct.test(u)?y++:(u=e,W===0&&N(Ot)),u}function zw(){let u;return u=p.charAt(y),ut.test(u)?y++:(u=e,W===0&&N(gt)),u}function Xw(){let u,b,V,v;if(W++,u=y,p.charCodeAt(y)===34?(b=g,y++):(b=e,W===0&&N(at)),b!==e){for(V=[],v=p.charAt(y),Pt.test(v)?y++:(v=e,W===0&&N(dt));v!==e;)V.push(v),v=p.charAt(y),Pt.test(v)?y++:(v=e,W===0&&N(dt));p.charCodeAt(y)===34?(v=g,y++):(v=e,W===0&&N(at)),v!==e?(q=u,u=Pw(V)):(y=u,u=e)}else y=u,u=e;return W--,u===e&&(b=e,W===0&&N(xt)),u}function qw(){let u,b,V,v;if(W++,u=y,p.charCodeAt(y)===39?(b=w,y++):(b=e,W===0&&N(Et)),b!==e){for(V=[],v=p.charAt(y),bt.test(v)?y++:(v=e,W===0&&N(yt));v!==e;)V.push(v),v=p.charAt(y),bt.test(v)?y++:(v=e,W===0&&N(yt));p.charCodeAt(y)===39?(v=w,y++):(v=e,W===0&&N(Et)),v!==e?(q=u,u=bw(V)):(y=u,u=e)}else y=u,u=e;return W--,u===e&&(b=e,W===0&&N(lt)),u}function Kw(){let u,b,V,v,B,O;return u=Gw(),u===e&&(u=y,p.charCodeAt(y)===40?(b=x,y++):(b=e,W===0&&N(Z)),b!==e?(V=X(),v=ke(),v!==e?(B=X(),p.charCodeAt(y)===41?(O=_,y++):(O=e,W===0&&N(Mt)),O!==e?(q=u,u=v):(y=u,u=e)):(y=u,u=e)):(y=u,u=e)),u}function To(){let u,b,V,v,B;return u=Kw(),u===e&&(u=y,b=jw(),b!==e?(V=X(),v=To(),v!==e?(B=X(),q=u,u=vw(b,v)):(y=u,u=e)):(y=u,u=e)),u}function jw(){let u;return u=p.charAt(y),Nt.test(u)?y++:(u=e,W===0&&N(vt)),u}function ws(){let u,b,V,v;return u=y,b=kw(),b!==e?(V=X(),v=Zw(),v!==e?(q=u,u=Rw(b,v)):(y=u,u=e)):(y=u,u=e),u===e&&(u=To()),u}function Zw(){let u,b,V,v,B,O;return u=y,p.charCodeAt(y)===40?(b=x,y++):(b=e,W===0&&N(Z)),b!==e?(V=X(),v=y,B=Jw(),B!==e?(O=X(),B=[B,O],v=B):(y=v,v=e),v===e&&(v=null),p.charCodeAt(y)===41?(B=_,y++):(B=e,W===0&&N(Mt)),B!==e?(q=u,u=_w(v)):(y=u,u=e)):(y=u,u=e),u}function Jw(){let u,b,V,v,B,O,K,$;if(u=y,b=ke(),b!==e){for(V=[],v=y,B=X(),p.charCodeAt(y)===44?(O=L,y++):(O=e,W===0&&N(ho)),O!==e?(K=X(),$=ke(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),p.charCodeAt(y)===44?(O=L,y++):(O=e,W===0&&N(ho)),O!==e?(K=X(),$=ke(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Tw(b,V)}else y=u,u=e;return u}function xs(){let u,b,V,v,B,O,K,$;if(u=y,b=ws(),b!==e){for(V=[],v=y,B=X(),O=p.charAt(y),Qt.test(O)?y++:(O=e,W===0&&N(co)),O!==e?(K=X(),$=ws(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),O=p.charAt(y),Qt.test(O)?y++:(O=e,W===0&&N(co)),O!==e?(K=X(),$=ws(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Sw(b,V)}else y=u,u=e;return u}function ys(){let u,b,V,v,B,O,K,$;if(u=y,b=xs(),b!==e){for(V=[],v=y,B=X(),O=p.charAt(y),Nt.test(O)?y++:(O=e,W===0&&N(vt)),O!==e?(K=X(),$=xs(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),O=p.charAt(y),Nt.test(O)?y++:(O=e,W===0&&N(vt)),O!==e?(K=X(),$=xs(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Lw(b,V)}else y=u,u=e;return u}function Ps(){let u,b,V,v,B,O,K,$;if(u=y,b=ys(),b!==e){for(V=[],v=y,B=X(),p.substr(y,2)===A?(O=A,y+=2):(O=e,W===0&&N(po)),O===e&&(p.substr(y,2)===E?(O=E,y+=2):(O=e,W===0&&N(uo)),O===e&&(O=p.charAt(y),Ft.test(O)?y++:(O=e,W===0&&N(go)))),O!==e?(K=X(),$=ys(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),p.substr(y,2)===A?(O=A,y+=2):(O=e,W===0&&N(po)),O===e&&(p.substr(y,2)===E?(O=E,y+=2):(O=e,W===0&&N(uo)),O===e&&(O=p.charAt(y),Ft.test(O)?y++:(O=e,W===0&&N(go)))),O!==e?(K=X(),$=ys(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Cw(b,V)}else y=u,u=e;return u}function bs(){let u,b,V,v,B,O,K,$;if(u=y,b=Ps(),b!==e){for(V=[],v=y,B=X(),p.substr(y,2)===I?(O=I,y+=2):(O=e,W===0&&N(mo)),O===e&&(p.substr(y,2)===k?(O=k,y+=2):(O=e,W===0&&N(fo))),O!==e?(K=X(),$=Ps(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),p.substr(y,2)===I?(O=I,y+=2):(O=e,W===0&&N(mo)),O===e&&(p.substr(y,2)===k?(O=k,y+=2):(O=e,W===0&&N(fo))),O!==e?(K=X(),$=Ps(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Aw(b,V)}else y=u,u=e;return u}function ke(){let u,b,V,v,B,O,K,$;if(u=y,b=bs(),b!==e){for(V=[],v=y,B=X(),p.substr(y,2)===F?(O=F,y+=2):(O=e,W===0&&N(wo)),O===e&&(p.substr(y,2)===z?(O=z,y+=2):(O=e,W===0&&N(xo))),O!==e?(K=X(),$=bs(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);v!==e;)V.push(v),v=y,B=X(),p.substr(y,2)===F?(O=F,y+=2):(O=e,W===0&&N(wo)),O===e&&(p.substr(y,2)===z?(O=z,y+=2):(O=e,W===0&&N(xo))),O!==e?(K=X(),$=bs(),$!==e?(B=[B,O,K,$],v=B):(y=v,v=e)):(y=v,v=e);q=u,u=Ow(b,V)}else y=u,u=e;return u}function Qw(u,b){return u.map(function(V){return V[b]})}function tx(u,b){return u?u[b]:null}function ex(u,b,V){return[u].concat(Qw(b,V))}function ai(u,b){return b.reduce(function(V,v){return{type:"BinaryExpression",operator:v[1],left:V,right:v[3]}},u)}function ix(u,b){return b.reduce(function(V,v){return{type:"LogicalExpression",operator:v[1],left:V,right:v[3]}},u)}function rx(u){return u!==null?u:[]}De=s();let vs=De!==e&&y===p.length;function So(){throw De!==e&&y<p.length&&N(Mw()),Po(ni,Rt<p.length?Ew(Rt):null,Rt<p.length?We(Rt,Rt+1):We(Rt,Rt))}if(t.peg$library)return{peg$result:De,peg$currPos:y,peg$FAILED:e,peg$maxFailExpected:ni,peg$maxFailPos:Rt,peg$success:vs,peg$throw:vs?void 0:So};if(vs)return De;So()}var ir=class{compile(t){let e=ia(t,{});return new er(t,e)}execute(t){return this.compile(t).execute()}};var rr=class{pvs=new Map;canProvide(t){return t.startsWith("=")}startProviding(t){for(let e of t)this.pvs.set(e.name,new Ms(e))}stopProviding(t){for(let e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}},Ms=class{constructor(t){this.pv=t;let e=new ir;this.compiledFormula=e.compile(t.name);for(let i of this.compiledFormula.getPVNames()){let r=t.pvEngine.createPV(i);this.compiledFormula.updateDataSource(r.name,{value:r.value,acquisitionStatus:"good"}),t.pvEngine.addListener(i,()=>{this.compiledFormula.updateDataSource(i,{value:t.pvEngine.getValue(i),acquisitionStatus:"good"}),this.trigger()})}this.trigger()}compiledFormula;trigger(){let t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}};function oa(p){return!isNaN(p)&&(Number.isInteger(parseFloat(p))||p%1!==0)}function ra(p){return oa(p)?parseFloat(p):(console.warn(`Not a valid float: ${p}`),p)}function sa(p){return p!=null?String(p):p}var sr=class extends be{constructor(e,i,r,s){super(e,i);this.type=r;this.initializer=s;this.writable=!0}setSample(e){if(this.type==="VDouble")e.value=ra(e.value);else if(this.type==="VDoubleArray")for(let i=0;i<e.value.length;i++)e.value[i]=ra(e.value);else if(this.type==="VString")e.value=sa(e.value);else if(this.type==="VStringArray")for(let i=0;i<e.value.length;i++)e.value[i]=sa(e.value);else typeof e.value=="string"&&oa(e.value)&&(e.value=parseFloat(e.value));super.setSample(e)}};var na=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function Ce(p){if(!p.startsWith("loc://"))return p;let t=p.match(na);return t?t[1]:p}var or=class{constructor(t){this.display=t}rules=[];scripts=[];valueListeners=[];pvs=new Map;providers=[];scriptLibraries={};listeners=new Map;init(){for(let t of this.listeners.entries()){let e=this.pvs.get(t[0]);if(e&&e.value!==null&&e.value!==void 0)for(let i of t[1])i()}}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.valueListeners=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){let e=Ce(t);return this.pvs.has(e)}getPV(t){let e=Ce(t);return this.pvs.get(e)}disconnectAll(){for(let t of this.providers){let e=[];for(let 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 be(t,this),this.pvs.set(t,e);let i=this.findProvider(t);return i?(e.provider=i,i.startProviding([e]),e):(console.warn(`No provider for PV ${t}`),e.disconnected=!0,e)}createHistoricalDataProvider(t,e){let i=this.findProvider(t);if(i?.createHistoricalDataProvider)return i.createHistoricalDataProvider(t,e)}findProvider(t){for(let e of this.providers)if(e.canProvide(t))return e;return null}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){let e=t.match(na),i,r;if(e){if(t=e[1],e[3])switch(e[3]){case"VDouble":case"VDoubleArray":case"VString":case"VStringArray":i=e[3];break;default:console.warn(`Unknown local PV type information: ${e[3]}`)}if(e[5]!==void 0){let n=e[5];n.startsWith('"')&&n.endsWith('"')?r=n.substring(1,n.length-1):n.indexOf(",")!==-1?r=n.split(",").map(a=>{let l=a.trim();return l.startsWith('"')&&l.endsWith('"')?l.substring(1,l.length-1):Number(l)}):r=Number(n)}}let s=this.pvs.get(t),o=!1;if(s){let n=s;n.type&&i&&n.type!==i&&console.warn(`PV ${t} is defined with different types: ${n.type} !== ${i}`),n.initializer!==void 0&&r!==void 0&&!this.initializerEquals(n.initializer,r)?console.warn(`PV ${t} is defined with different initializers: ${n.initializer} !== ${r}`):n.initializer===void 0&&r!==void 0&&(o=!0)}return s?i&&!s.type&&(s.type=i):(s=new sr(t,this,i,r),this.pvs.set(t,s),o=!0),o&&r!==void 0&&this.setValue(new Date,t,r),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}else return t===e}getValue(t){let e=Ce(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,r="NONE",s=void 0){let o=e.startsWith("loc://"),n=this.findProvider(e);if(!o&&n?.writeValue)n.writeValue(e,i);else{let a=Ce(e),l=this.pvs.get(a);if(l){l.setSample({time:t,value:i,severity:r,units:s});for(let h of this.listeners.get(a)||[])h()}else throw new Error(`Cannot set value of unknown PV ${e}`)}}setExternalValues(t){let e=[];for(let i of t.keys()){let r=this.pvs.get(i);if(r){r.setSample(t.get(i));for(let s of this.listeners.get(i)||[])e.push(s)}else console.warn(`Received an update for unknown pv ${i}`)}for(let i of e)i()}createScript(t,e,i,r){let s=new Vs(t,e,i,r);this.scripts.push(s);for(let o=0;o<e.inputs.length;o++){let n=e.inputs[o],a=r[o];if(n.trigger){let l=t.expandMacro(n.pvName),h=()=>{if(e.checkConnect)for(let c=0;c<e.inputs.length;c++){let d=r[c],g=e.inputs[c].trigger,w=d.value!==null&&d.value!==void 0;if(d.disconnected||g&&!w)return}s.scriptEngine.run(a)};s.triggerListeners.push({pvName:l,listener:h}),this.addListener(l,h,!1)}}return s}createRule(t,e,i){let r=new Is(t,e,i);this.rules.push(r);let s=()=>{for(let o=0;o<e.inputs.length;o++){let n=i[o],a=e.inputs[o].trigger,l=n.value!==null&&n.value!==void 0;if(n.disconnected||a&&!l)return}r.scriptEngine.run()};for(let o of e.inputs)if(o.trigger){let n=t.expandMacro(o.pvName);r.triggerListeners.push({pvName:n,listener:s}),this.addListener(n,s,!1)}}trackListener(t,e,i,r=!0){this.addListener(e,i,r),this.valueListeners.push({widget:t,pvName:e,listener:i})}removeWidget(t){let e=new Set,i=r=>{if(e.add(r),r instanceof st)for(let s of r.widgets)i(s)};i(t),this.rules=this.rules.filter(r=>{if(!e.has(r.widget))return!0;for(let{pvName:s,listener:o}of r.triggerListeners)this.removeListener(s,o);return!1}),this.scripts=this.scripts.filter(r=>{if(!e.has(r.widget))return!0;for(let{pvName:s,listener:o}of r.triggerListeners)this.removeListener(s,o);return!1}),this.valueListeners=this.valueListeners.filter(r=>e.has(r.widget)?(this.removeListener(r.pvName,r.listener),!1):!0)}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){let r=Ce(t),s=this.listeners.get(r);if(s?s.push(e):this.listeners.set(r,[e]),i){let o=this.pvs.get(r);o&&o.value!==null&&o.value!==void 0&&e()}}removeListener(t,e){let i=Ce(t),r=this.listeners.get(i);if(r){let s=r.indexOf(e);s!==-1&&r.splice(s,1)}}},Vs=class{constructor(t,e,i,r){this.widget=t;this.script=e;this.text=i;this.pvs=r;this.scriptEngine=new Ut(t,i,r)}scriptEngine;triggerListeners=[]},Is=class{constructor(t,e,i){this.widget=t;this.rule=e;let r="",s=t.properties.getProperty(e.propertyName);if(!s)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let o=!1,n=!1,a=!1,l=!1;for(let d of e.expressions)d.expression.match(/pv[0-9]+/)&&(o=!0),e.outputExpression&&d.outputValue.toString().match(/pv[0-9]+/)&&(o=!0),d.expression.indexOf("pvInt")!==-1&&(n=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvInt")!==-1&&(n=!0),d.expression.indexOf("pvStr")!==-1&&(a=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvStr")!==-1&&(a=!0),d.expression.indexOf("pvSev")!==-1&&(l=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvSev")!==-1&&(l=!0);for(let d=0;d<i.length;d++)o&&(r+=`var pv${d} = PVUtil.getDouble(pvs[${d}]);
6
+ at `+n}return e}static buildMessage(t,e){function i(d){return d.codePointAt(0).toString(16).toUpperCase()}let r=Object.prototype.hasOwnProperty.call(RegExp.prototype,"unicode")?new RegExp("[\\p{C}\\p{Mn}\\p{Mc}]","gu"):null;function s(d){return r?d.replace(r,g=>"\\u{"+i(g)+"}"):d}function o(d){return s(d.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,g=>"\\x0"+i(g)).replace(/[\x10-\x1F\x7F-\x9F]/g,g=>"\\x"+i(g)))}function n(d){return s(d.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,g=>"\\x0"+i(g)).replace(/[\x10-\x1F\x7F-\x9F]/g,g=>"\\x"+i(g)))}let a={literal(d){return'"'+o(d.text)+'"'},class(d){let g=d.parts.map(x=>Array.isArray(x)?n(x[0])+"-"+n(x[1]):n(x));return"["+(d.inverted?"^":"")+g.join("")+"]"+(d.unicode?"u":"")},any(){return"any character"},end(){return"end of input"},other(d){return d.description}};function l(d){return a[d.type](d)}function h(d){let g=d.map(l);if(g.sort(),g.length>0){let x=1;for(let w=1;w<g.length;w++)g[w-1]!==g[w]&&(g[x]=g[w],x++);g.length=x}switch(g.length){case 1:return g[0];case 2:return g[0]+" or "+g[1];default:return g.slice(0,-1).join(", ")+", or "+g[g.length-1]}}function p(d){return d?'"'+o(d)+'"':"end of input"}return"Expected "+h(t)+" but "+p(e)+" found."}};function na(c,t){t=t!==void 0?t:{};let e={},i=t.grammarSource,r={Start:To},s=To,o="=",n="false",a="true",l="pi",h="e",p=".",d="0",g='"',x="'",w="(",v=")",S=",",A="<=",C=">=",V="==",D="!=",N="&&",$="||",z=/^[\t ]/,lt=/^[A-Z_a-z]/,dt=/^[a-zA-Z0-9_]/,At=/^[0-9]/,mt=/^[1-9]/,bt=/^[^\n\r\f"]/,vt=/^[^\n\r\f']/,Ft=/^[+\-]/,ee=/^[%*\/\^]/,Gt=/^[<>]/,De=ot("=",!1),ie=It([" "," "],!1,!1,!1),ue=ot("false",!0),ni=ot("true",!0),We=ot("PI",!0),ke=ot("E",!0),ai=se("identifier"),uo=It([["A","Z"],"_",["a","z"]],!1,!1,!1),li=It([["a","z"],["A","Z"],["0","9"],"_"],!1,!1,!1),ut=se("boolean"),Ot=se("constant"),$t=se("number"),wt=ot(".",!1),re=ot("0",!1),Et=It([["0","9"]],!1,!1,!1),ft=It([["1","9"]],!1,!1,!1),yt=se("string"),ht=ot('"',!1),gt=It([`
7
+ `,"\r","\f",'"'],!0,!1,!1),ct=se("parameter"),Mt=ot("'",!1),Pt=It([`
8
+ `,"\r","\f","'"],!0,!1,!1),Z=ot("(",!1),Vt=ot(")",!1),Rt=It(["+","-"],!1,!1,!1),go=ot(",",!1),mo=It(["%","*","/","^"],!1,!1,!1),fo=ot("<=",!1),wo=ot(">=",!1),xo=It(["<",">"],!1,!1,!1),yo=ot("==",!1),Po=ot("!=",!1),bo=ot("&&",!1),vo=ot("||",!1);function ub(u){return u}function mw(u){return{type:"Formula",expression:u}}function gb(u){return u}function fw(u,b){return{type:"Symbol",name:u+b.join("")}}function ww(){return{type:"BooleanLiteral",value:!0}}function xw(){return{type:"BooleanLiteral",value:!1}}function yw(){return{type:"ConstantLiteral",value:Math.PI}}function Pw(){return{type:"ConstantLiteral",value:Math.E}}function bw(){return{type:"NumericLiteral",value:parseFloat(ys())}}function vw(){return{type:"NumericLiteral",value:parseFloat(ys())}}function Rw(){return{type:"NumericLiteral",value:parseFloat(ys())}}function _w(u){return{type:"StringLiteral",value:u.join("")}}function Tw(u){return{type:"ParameterLiteral",value:u.join("")}}function mb(u){return u}function Sw(u,b){return{type:"UnaryExpression",operator:u,argument:b}}function Lw(u,b){return{type:"CallExpression",callee:u,arguments:b}}function Cw(u){return ax(sx(u,0))}function Aw(u,b){return ox(u,b,3)}function Ow(u,b){return ci(u,b)}function Ew(u,b){return ci(u,b)}function Mw(u,b){return ci(u,b)}function Vw(u,b){return ci(u,b)}function Iw(u,b){return nx(u,b)}let y=t.peg$currPos|0,K=y,ge=[{line:1,column:1}],_t=y,hi=t.peg$maxFailExpected||[],k=t.peg$silentFails|0,Ne;if(t.startRule){if(!(t.startRule in r))throw new Error(`Can't start parsing from rule "`+t.startRule+'".');s=r[t.startRule]}function ys(){return c.substring(K,y)}function fb(){return K}function wb(){return{source:i,start:K,end:y}}function xb(){return Fe(K,y)}function yb(u,b){throw b=b!==void 0?b:Fe(K,y),_o([se(u)],c.substring(K,y),b)}function Pb(u,b){throw b=b!==void 0?b:Fe(K,y),Dw(u,b)}function Bw(u=y){let b=c.codePointAt(u);return b===void 0?"":String.fromCodePoint(b)}function ot(u,b){return{type:"literal",text:u,ignoreCase:b}}function It(u,b,I,R){return{type:"class",parts:u,inverted:b,ignoreCase:I,unicode:R}}function bb(){return{type:"any"}}function Hw(){return{type:"end"}}function se(u){return{type:"other",description:u}}function Ro(u){let b=ge[u],I;if(b)return b;if(u>=ge.length)I=ge.length-1;else for(I=u;!ge[--I];);for(b=ge[I],b={line:b.line,column:b.column};I<u;)c.charCodeAt(I)===10?(b.line++,b.column=1):b.column++,I++;return ge[u]=b,b}function Fe(u,b,I){let R=Ro(u),B=Ro(b),E={source:i,start:{offset:u,line:R.line,column:R.column},end:{offset:b,line:B.line,column:B.column}};return I&&i&&typeof i.offset=="function"&&(E.start=i.offset(E.start),E.end=i.offset(E.end)),E}function F(u){y<_t||(y>_t&&(_t=y,hi=[]),hi.push(u))}function Dw(u,b){return new ei(u,null,null,b)}function _o(u,b,I){return new ei(ei.buildMessage(u,b),u,b,I)}function To(){let u,b,I,R,B;return u=y,c.charCodeAt(y)===61?(b=o,y++):(b=e,k===0&&F(De)),b!==e?(I=q(),R=Ww(),R!==e?(B=q(),K=u,u=R):(y=u,u=e)):(y=u,u=e),u}function Ww(){let u,b;return u=y,b=Ge(),b!==e&&(K=u,b=mw(b)),u=b,u}function q(){let u,b;for(u=[],b=So();b!==e;)u.push(b),b=So();return u}function So(){let u;return u=c.charAt(y),z.test(u)?y++:(u=e,k===0&&F(ie)),u}function kw(){let u;return u=c.substr(y,5),u.toLowerCase()===n?y+=5:(u=e,k===0&&F(ue)),u}function Nw(){let u;return u=c.substr(y,4),u.toLowerCase()===a?y+=4:(u=e,k===0&&F(ni)),u}function Fw(){let u;return u=c.substr(y,2),u.toLowerCase()===l?y+=2:(u=e,k===0&&F(We)),u}function Gw(){let u;return u=c.charAt(y),u.toLowerCase()===h?y++:(u=e,k===0&&F(ke)),u}function $w(){let u,b;return u=y,b=Uw(),b!==e&&(K=u,b=b),u=b,u}function Uw(){let u,b,I,R;if(k++,u=y,b=Yw(),b!==e){for(I=[],R=Lo();R!==e;)I.push(R),R=Lo();K=u,u=fw(b,I)}else y=u,u=e;return k--,u===e&&(b=e,k===0&&F(ai)),u}function Yw(){let u;return u=c.charAt(y),lt.test(u)?y++:(u=e,k===0&&F(uo)),u}function Lo(){let u;return u=c.charAt(y),dt.test(u)?y++:(u=e,k===0&&F(li)),u}function zw(){let u;return u=Xw(),u===e&&(u=qw(),u===e&&(u=Kw(),u===e&&(u=Zw(),u===e&&(u=Jw())))),u}function Xw(){let u,b;return k++,u=y,b=Nw(),b!==e&&(K=u,b=ww()),u=b,u===e&&(u=y,b=kw(),b!==e&&(K=u,b=xw()),u=b),k--,u===e&&(b=e,k===0&&F(ut)),u}function qw(){let u,b;return k++,u=y,b=Fw(),b!==e&&(K=u,b=yw()),u=b,u===e&&(u=y,b=Gw(),b!==e&&(K=u,b=Pw()),u=b),k--,u===e&&(b=e,k===0&&F(Ot)),u}function Kw(){let u,b,I,R,B;if(k++,u=y,b=Co(),b!==e)if(c.charCodeAt(y)===46?(I=p,y++):(I=e,k===0&&F(wt)),I!==e){for(R=[],B=me();B!==e;)R.push(B),B=me();K=u,u=bw()}else y=u,u=e;else y=u,u=e;if(u===e){if(u=y,c.charCodeAt(y)===46?(b=p,y++):(b=e,k===0&&F(wt)),b!==e){if(I=[],R=me(),R!==e)for(;R!==e;)I.push(R),R=me();else I=e;I!==e?(K=u,u=vw()):(y=u,u=e)}else y=u,u=e;u===e&&(u=y,b=Co(),b!==e&&(K=u,b=Rw()),u=b)}return k--,u===e&&(b=e,k===0&&F($t)),u}function Co(){let u,b,I,R;if(c.charCodeAt(y)===48?(u=d,y++):(u=e,k===0&&F(re)),u===e)if(u=y,b=jw(),b!==e){for(I=[],R=me();R!==e;)I.push(R),R=me();b=[b,I],u=b}else y=u,u=e;return u}function me(){let u;return u=c.charAt(y),At.test(u)?y++:(u=e,k===0&&F(Et)),u}function jw(){let u;return u=c.charAt(y),mt.test(u)?y++:(u=e,k===0&&F(ft)),u}function Zw(){let u,b,I,R;if(k++,u=y,c.charCodeAt(y)===34?(b=g,y++):(b=e,k===0&&F(ht)),b!==e){for(I=[],R=c.charAt(y),bt.test(R)?y++:(R=e,k===0&&F(gt));R!==e;)I.push(R),R=c.charAt(y),bt.test(R)?y++:(R=e,k===0&&F(gt));c.charCodeAt(y)===34?(R=g,y++):(R=e,k===0&&F(ht)),R!==e?(K=u,u=_w(I)):(y=u,u=e)}else y=u,u=e;return k--,u===e&&(b=e,k===0&&F(yt)),u}function Jw(){let u,b,I,R;if(k++,u=y,c.charCodeAt(y)===39?(b=x,y++):(b=e,k===0&&F(Mt)),b!==e){for(I=[],R=c.charAt(y),vt.test(R)?y++:(R=e,k===0&&F(Pt));R!==e;)I.push(R),R=c.charAt(y),vt.test(R)?y++:(R=e,k===0&&F(Pt));c.charCodeAt(y)===39?(R=x,y++):(R=e,k===0&&F(Mt)),R!==e?(K=u,u=Tw(I)):(y=u,u=e)}else y=u,u=e;return k--,u===e&&(b=e,k===0&&F(ct)),u}function Qw(){let u,b,I,R,B,E;return u=zw(),u===e&&(u=y,c.charCodeAt(y)===40?(b=w,y++):(b=e,k===0&&F(Z)),b!==e?(I=q(),R=Ge(),R!==e?(B=q(),c.charCodeAt(y)===41?(E=v,y++):(E=e,k===0&&F(Vt)),E!==e?(K=u,u=R):(y=u,u=e)):(y=u,u=e)):(y=u,u=e)),u}function Ao(){let u,b,I,R,B;return u=Qw(),u===e&&(u=y,b=tx(),b!==e?(I=q(),R=Ao(),R!==e?(B=q(),K=u,u=Sw(b,R)):(y=u,u=e)):(y=u,u=e)),u}function tx(){let u;return u=c.charAt(y),Ft.test(u)?y++:(u=e,k===0&&F(Rt)),u}function Ps(){let u,b,I,R;return u=y,b=$w(),b!==e?(I=q(),R=ex(),R!==e?(K=u,u=Lw(b,R)):(y=u,u=e)):(y=u,u=e),u===e&&(u=Ao()),u}function ex(){let u,b,I,R,B,E;return u=y,c.charCodeAt(y)===40?(b=w,y++):(b=e,k===0&&F(Z)),b!==e?(I=q(),R=y,B=ix(),B!==e?(E=q(),B=[B,E],R=B):(y=R,R=e),R===e&&(R=null),c.charCodeAt(y)===41?(B=v,y++):(B=e,k===0&&F(Vt)),B!==e?(K=u,u=Cw(R)):(y=u,u=e)):(y=u,u=e),u}function ix(){let u,b,I,R,B,E,j,U;if(u=y,b=Ge(),b!==e){for(I=[],R=y,B=q(),c.charCodeAt(y)===44?(E=S,y++):(E=e,k===0&&F(go)),E!==e?(j=q(),U=Ge(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),c.charCodeAt(y)===44?(E=S,y++):(E=e,k===0&&F(go)),E!==e?(j=q(),U=Ge(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Aw(b,I)}else y=u,u=e;return u}function bs(){let u,b,I,R,B,E,j,U;if(u=y,b=Ps(),b!==e){for(I=[],R=y,B=q(),E=c.charAt(y),ee.test(E)?y++:(E=e,k===0&&F(mo)),E!==e?(j=q(),U=Ps(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),E=c.charAt(y),ee.test(E)?y++:(E=e,k===0&&F(mo)),E!==e?(j=q(),U=Ps(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Ow(b,I)}else y=u,u=e;return u}function vs(){let u,b,I,R,B,E,j,U;if(u=y,b=bs(),b!==e){for(I=[],R=y,B=q(),E=c.charAt(y),Ft.test(E)?y++:(E=e,k===0&&F(Rt)),E!==e?(j=q(),U=bs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),E=c.charAt(y),Ft.test(E)?y++:(E=e,k===0&&F(Rt)),E!==e?(j=q(),U=bs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Ew(b,I)}else y=u,u=e;return u}function Rs(){let u,b,I,R,B,E,j,U;if(u=y,b=vs(),b!==e){for(I=[],R=y,B=q(),c.substr(y,2)===A?(E=A,y+=2):(E=e,k===0&&F(fo)),E===e&&(c.substr(y,2)===C?(E=C,y+=2):(E=e,k===0&&F(wo)),E===e&&(E=c.charAt(y),Gt.test(E)?y++:(E=e,k===0&&F(xo)))),E!==e?(j=q(),U=vs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),c.substr(y,2)===A?(E=A,y+=2):(E=e,k===0&&F(fo)),E===e&&(c.substr(y,2)===C?(E=C,y+=2):(E=e,k===0&&F(wo)),E===e&&(E=c.charAt(y),Gt.test(E)?y++:(E=e,k===0&&F(xo)))),E!==e?(j=q(),U=vs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Mw(b,I)}else y=u,u=e;return u}function _s(){let u,b,I,R,B,E,j,U;if(u=y,b=Rs(),b!==e){for(I=[],R=y,B=q(),c.substr(y,2)===V?(E=V,y+=2):(E=e,k===0&&F(yo)),E===e&&(c.substr(y,2)===D?(E=D,y+=2):(E=e,k===0&&F(Po))),E!==e?(j=q(),U=Rs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),c.substr(y,2)===V?(E=V,y+=2):(E=e,k===0&&F(yo)),E===e&&(c.substr(y,2)===D?(E=D,y+=2):(E=e,k===0&&F(Po))),E!==e?(j=q(),U=Rs(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Vw(b,I)}else y=u,u=e;return u}function Ge(){let u,b,I,R,B,E,j,U;if(u=y,b=_s(),b!==e){for(I=[],R=y,B=q(),c.substr(y,2)===N?(E=N,y+=2):(E=e,k===0&&F(bo)),E===e&&(c.substr(y,2)===$?(E=$,y+=2):(E=e,k===0&&F(vo))),E!==e?(j=q(),U=_s(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);R!==e;)I.push(R),R=y,B=q(),c.substr(y,2)===N?(E=N,y+=2):(E=e,k===0&&F(bo)),E===e&&(c.substr(y,2)===$?(E=$,y+=2):(E=e,k===0&&F(vo))),E!==e?(j=q(),U=_s(),U!==e?(B=[B,E,j,U],R=B):(y=R,R=e)):(y=R,R=e);K=u,u=Iw(b,I)}else y=u,u=e;return u}function rx(u,b){return u.map(function(I){return I[b]})}function sx(u,b){return u?u[b]:null}function ox(u,b,I){return[u].concat(rx(b,I))}function ci(u,b){return b.reduce(function(I,R){return{type:"BinaryExpression",operator:R[1],left:I,right:R[3]}},u)}function nx(u,b){return b.reduce(function(I,R){return{type:"LogicalExpression",operator:R[1],left:I,right:R[3]}},u)}function ax(u){return u!==null?u:[]}Ne=s();let Ts=Ne!==e&&y===c.length;function Oo(){throw Ne!==e&&y<c.length&&F(Hw()),_o(hi,_t<c.length?Bw(_t):null,_t<c.length?Fe(_t,_t+1):Fe(_t,_t))}if(t.peg$library)return{peg$result:Ne,peg$currPos:y,peg$FAILED:e,peg$maxFailExpected:hi,peg$maxFailPos:_t,peg$success:Ts,peg$throw:Ts?void 0:Oo};if(Ts)return Ne;Oo()}var sr=class{compile(t){let e=na(t,{});return new rr(t,e)}execute(t){return this.compile(t).execute()}};var or=class{pvs=new Map;canProvide(t){return t.startsWith("=")}startProviding(t){for(let e of t)this.pvs.set(e.name,new Bs(e))}stopProviding(t){for(let e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}},Bs=class{constructor(t){this.pv=t;let e=new sr;this.compiledFormula=e.compile(t.name);for(let i of this.compiledFormula.getPVNames()){let r=t.pvEngine.createPV(i);this.compiledFormula.updateDataSource(r.name,{value:r.value,acquisitionStatus:"good"}),t.pvEngine.addListener(i,()=>{this.compiledFormula.updateDataSource(i,{value:t.pvEngine.getValue(i),acquisitionStatus:"good"}),this.trigger()})}this.trigger()}compiledFormula;trigger(){let t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}};function ha(c){return!isNaN(c)&&(Number.isInteger(parseFloat(c))||c%1!==0)}function aa(c){return ha(c)?parseFloat(c):(console.warn(`Not a valid float: ${c}`),c)}function la(c){return c!=null?String(c):c}var nr=class extends _e{constructor(e,i,r,s){super(e,i);this.type=r;this.initializer=s;this.writable=!0}setSample(e){if(this.type==="VDouble")e.value=aa(e.value);else if(this.type==="VDoubleArray")for(let i=0;i<e.value.length;i++)e.value[i]=aa(e.value);else if(this.type==="VString")e.value=la(e.value);else if(this.type==="VStringArray")for(let i=0;i<e.value.length;i++)e.value[i]=la(e.value);else typeof e.value=="string"&&ha(e.value)&&(e.value=parseFloat(e.value));super.setSample(e)}};var ca=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function Ee(c){if(!c.startsWith("loc://"))return c;let t=c.match(ca);return t?t[1]:c}var ar=class{constructor(t){this.display=t}rules=[];scripts=[];valueListeners=[];pvs=new Map;providers=[];scriptLibraries={};listeners=new Map;init(){for(let t of this.listeners.entries()){let e=this.pvs.get(t[0]);if(e&&e.value!==null&&e.value!==void 0)for(let i of t[1])i()}}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.valueListeners=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){let e=Ee(t);return this.pvs.has(e)}getPV(t){let e=Ee(t);return this.pvs.get(e)}disconnectAll(){for(let t of this.providers){let e=[];for(let 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 _e(t,this),this.pvs.set(t,e);let i=this.findProvider(t);return i?(e.provider=i,i.startProviding([e]),e):(console.warn(`No provider for PV ${t}`),e.disconnected=!0,e)}createHistoricalDataProvider(t,e){let i=this.findProvider(t);if(i?.createHistoricalDataProvider)return i.createHistoricalDataProvider(t,e)}findProvider(t){for(let e of this.providers)if(e.canProvide(t))return e;return null}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){let e=t.match(ca),i,r;if(e){if(t=e[1],e[3])switch(e[3]){case"VDouble":case"VDoubleArray":case"VString":case"VStringArray":i=e[3];break;default:console.warn(`Unknown local PV type information: ${e[3]}`)}if(e[5]!==void 0){let n=e[5];n.startsWith('"')&&n.endsWith('"')?r=n.substring(1,n.length-1):n.indexOf(",")!==-1?r=n.split(",").map(a=>{let l=a.trim();return l.startsWith('"')&&l.endsWith('"')?l.substring(1,l.length-1):Number(l)}):r=Number(n)}}let s=this.pvs.get(t),o=!1;if(s){let n=s;n.type&&i&&n.type!==i&&console.warn(`PV ${t} is defined with different types: ${n.type} !== ${i}`),n.initializer!==void 0&&r!==void 0&&!this.initializerEquals(n.initializer,r)?console.warn(`PV ${t} is defined with different initializers: ${n.initializer} !== ${r}`):n.initializer===void 0&&r!==void 0&&(o=!0)}return s?i&&!s.type&&(s.type=i):(s=new nr(t,this,i,r),this.pvs.set(t,s),o=!0),o&&r!==void 0&&this.setValue(new Date,t,r),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}else return t===e}getValue(t){let e=Ee(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,r="NONE",s=void 0){let o=e.startsWith("loc://"),n=this.findProvider(e);if(!o&&n?.writeValue)n.writeValue(e,i);else{let a=Ee(e),l=this.pvs.get(a);if(l){l.setSample({time:t,value:i,severity:r,units:s});for(let h of this.listeners.get(a)||[])h()}else throw new Error(`Cannot set value of unknown PV ${e}`)}}setExternalValues(t){let e=[];for(let i of t.keys()){let r=this.pvs.get(i);if(r){r.setSample(t.get(i));for(let s of this.listeners.get(i)||[])e.push(s)}else console.warn(`Received an update for unknown pv ${i}`)}for(let i of e)i()}createScript(t,e,i,r){let s=new Hs(t,e,i,r);this.scripts.push(s);for(let o=0;o<e.inputs.length;o++){let n=e.inputs[o],a=r[o];if(n.trigger){let l=t.expandMacro(n.pvName),h=()=>{if(e.checkConnect)for(let p=0;p<e.inputs.length;p++){let d=r[p],g=e.inputs[p].trigger,x=d.value!==null&&d.value!==void 0;if(d.disconnected||g&&!x)return}s.scriptEngine.run(a)};s.triggerListeners.push({pvName:l,listener:h}),this.addListener(l,h,!1)}}return s}createRule(t,e,i){let r=new Ds(t,e,i);this.rules.push(r);let s=()=>{for(let o=0;o<e.inputs.length;o++){let n=i[o],a=e.inputs[o].trigger,l=n.value!==null&&n.value!==void 0;if(n.disconnected||a&&!l)return}r.scriptEngine.run()};for(let o of e.inputs)if(o.trigger){let n=t.expandMacro(o.pvName);r.triggerListeners.push({pvName:n,listener:s}),this.addListener(n,s,!1)}}trackListener(t,e,i,r=!0){this.addListener(e,i,r),this.valueListeners.push({widget:t,pvName:e,listener:i})}removeWidget(t){let e=new Set,i=r=>{if(e.add(r),r instanceof st)for(let s of r.widgets)i(s)};i(t),this.rules=this.rules.filter(r=>{if(!e.has(r.widget))return!0;for(let{pvName:s,listener:o}of r.triggerListeners)this.removeListener(s,o);return!1}),this.scripts=this.scripts.filter(r=>{if(!e.has(r.widget))return!0;for(let{pvName:s,listener:o}of r.triggerListeners)this.removeListener(s,o);return!1}),this.valueListeners=this.valueListeners.filter(r=>e.has(r.widget)?(this.removeListener(r.pvName,r.listener),!1):!0)}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){let r=Ee(t),s=this.listeners.get(r);if(s?s.push(e):this.listeners.set(r,[e]),i){let o=this.pvs.get(r);o&&o.value!==null&&o.value!==void 0&&e()}}removeListener(t,e){let i=Ee(t),r=this.listeners.get(i);if(r){let s=r.indexOf(e);s!==-1&&r.splice(s,1)}}},Hs=class{constructor(t,e,i,r){this.widget=t;this.script=e;this.text=i;this.pvs=r;this.scriptEngine=new zt(t,i,r)}scriptEngine;triggerListeners=[]},Ds=class{constructor(t,e,i){this.widget=t;this.rule=e;let r="",s=t.properties.getProperty(e.propertyName);if(!s)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let o=!1,n=!1,a=!1,l=!1;for(let d of e.expressions)d.expression.match(/pv[0-9]+/)&&(o=!0),e.outputExpression&&d.outputValue.toString().match(/pv[0-9]+/)&&(o=!0),d.expression.indexOf("pvInt")!==-1&&(n=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvInt")!==-1&&(n=!0),d.expression.indexOf("pvStr")!==-1&&(a=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvStr")!==-1&&(a=!0),d.expression.indexOf("pvSev")!==-1&&(l=!0),e.outputExpression&&d.outputValue.toString().indexOf("pvSev")!==-1&&(l=!0);for(let d=0;d<i.length;d++)o&&(r+=`var pv${d} = PVUtil.getDouble(pvs[${d}]);
9
9
  `),n&&(r+=`var pvInt${d} = PVUtil.getLong(pvs[${d}]);
10
10
  `),a&&(r+=`var pvStr${d} = PVUtil.getString(pvs[${d}]);
11
11
  `),l&&(r+=`var pvSev${d} = PVUtil.getSeverity(pvs[${d}]);
12
- `);for(let d=0;d<e.expressions.length;d++){let g=e.expressions[d].expression,w=e.expressions[d].outputValue;if(d>0&&(r+="else "),r+=`if (${g}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)r+=`${w});
13
- `;else{let x=this.printScriptValue(s,w);r+=`${x});
14
- `}}let h=s.value,c=this.printScriptValue(s,h);r+=`else widget.setPropertyValue("${e.propertyName}", `,r+=`${c});
15
- `}this.scriptEngine=new Ut(t,r,i)}scriptEngine;triggerListeners=[];printScriptValue(t,e){return e==null?"null":t.printScriptValue(e)}};var Kt=class{constructor(t,e,i){this.pv=t;this.interval=e;i!==void 0&&t.pvEngine.setValue(new Date,t.name,i,"NONE",t.units),this.interval>0&&(this.timer=window.setInterval(()=>{this.generateSample(new Date)},e))}timer;emit(t,e){let i="NONE";this.pv.lowerAlarmLimit!==void 0&&e<this.pv.lowerAlarmLimit?i="MAJOR":this.pv.upperAlarmLimit!==void 0&&e>this.pv.upperAlarmLimit?i="MAJOR":this.pv.lowerWarningLimit!==void 0&&e<this.pv.lowerWarningLimit?i="MINOR":this.pv.upperWarningLimit!==void 0&&e>this.pv.upperWarningLimit&&(i="MINOR"),this.pv.pvEngine.setValue(t,this.pv.name,e,i,this.pv.units)}stop(){window.clearInterval(this.timer)}},St=class extends Kt{constructor(t,e){super(t,-1,e)}generateSample(){}},nr=class extends Kt{constructor(e,i){super(e,1e3);this.formatter=i}generateSample(e){let i=this.formatter.formatDate(e,{year:!0,month:!0,day:!0})+" "+this.formatter.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});this.emit(e,i)}};var Qe=class extends Kt{constructor(e,i,r,s){super(e,s);this.min=i;this.max=r;let o=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+o*.1,e.lowerWarningLimit=i+o*.2,e.upperWarningLimit=i+o*.8,e.upperAlarmLimit=i+o*.9,e.upperDisplayLimit=r}generateSample(e){let i=Math.random()*(this.max-this.min)+this.min;this.emit(e,i)}},ti=class extends Kt{constructor(e,i,r,s){super(e,s);this.avg=i;this.stddev=r;e.units="x",e.lowerDisplayLimit=i-4*r,e.lowerAlarmLimit=i-2*r,e.lowerWarningLimit=i-r,e.upperWarningLimit=i+r,e.upperAlarmLimit=i+2*r,e.upperDisplayLimit=i+4*r}generateSample(e){let i,r,s;do i=2*Math.random()-1,r=2*Math.random()-1,s=i*i+r*r;while(s>=1||s===0);let o=Math.sqrt(-2*Math.log(s)/s),n=i*o;this.emit(e,this.avg+n*this.stddev)}},Ae=class extends Kt{constructor(e,i,r,s,o){super(e,o);this.min=i;this.max=r;this.samplesPerCycle=s;let n=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+n*.1,e.lowerWarningLimit=i+n*.2,e.upperWarningLimit=i+n*.8,e.upperAlarmLimit=i+n*.9,e.upperDisplayLimit=r}currentValue=0;generateSample(e){let i=this.max-this.min,r=Math.sin(this.currentValue*2*Math.PI/this.samplesPerCycle)*i/2+this.min+i/2;this.currentValue++,this.emit(e,r)}},Oe=class extends Kt{constructor(e,i,r,s,o){super(e,o);this.min=i;this.max=r;this.inc=s;s>=0?this.currentValue=i-s:this.currentValue=r-s;let n=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+n*.1,e.lowerWarningLimit=i+n*.2,e.upperWarningLimit=i+n*.8,e.upperAlarmLimit=i+n*.9,e.upperDisplayLimit=r}currentValue=0;generateSample(e){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(e,this.currentValue)}};var _x=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/,ar=class{pvs=new Map;canProvide(t){return t.startsWith("sim://")}startProviding(t){for(let e of t){let i=new Bs(e);this.pvs.set(e.name,i)}}stopProviding(t){for(let e of t){let i=this.pvs.get(e.name);i&&(i.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(let t of this.pvs.values())t.fn.stop()}},Bs=class{constructor(t){this.pv=t;let e=t.name.match(_x);if(e){let i=e[3]?e[3].split(","):[];for(let r=0;r<i.length;r++)i[r]=i[r].trim();this.fn=this.createGenerator(e[1],i)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new St(t,void 0)}fn;createGenerator(t,e){switch(t){case"const":let 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(t.length===0)return new Qe(this.pv,-5,5,1e3);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new Qe(this.pv,e,i,r)}}createGaussianNoise(t){if(t.length===0)return new ti(this.pv,0,1,100);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new ti(this.pv,e,i,r)}}createRamp(t){let e;if(t.length===0)e=new Oe(this.pv,-5,5,1,1e3);else if(t.length===3){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2])*1e3;e=new Oe(this.pv,i,r,1,s)}else if(t.length===4){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2]),o=parseFloat(t[3])*1e3;e=new Oe(this.pv,i,r,s,o)}else return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new St(this.pv,void 0);return e}createSine(t){let e;if(t.length===0)e=new Ae(this.pv,-5,5,10,1e3);else if(t.length===3){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2])*1e3;e=new Ae(this.pv,i,r,10,s)}else if(t.length===4){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2]),o=parseFloat(t[3])*1e3;e=new Ae(this.pv,i,r,s,o)}else return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new St(this.pv,void 0);return e}};var Tx=/sys\:\/\/([a-zA-Z]+)/,lr=class{constructor(t){this.formatter=t}pvs=new Map;canProvide(t){return t==="sys://time"}startProviding(t){for(let e of t){let i=new Hs(e,this.formatter);this.pvs.set(e.name,i)}}stopProviding(t){for(let e of t){let i=this.pvs.get(e.name);i&&(i.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(let t of this.pvs.values())t.fn.stop()}},Hs=class{constructor(t,e){this.pv=t;this.formatter=e;let i=t.name.match(Tx);i?this.fn=this.createGenerator(i[1]):(console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new St(t,void 0))}fn;createGenerator(t){return t==="time"?new nr(this.pv,this.formatter):(console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new St(this.pv,void 0))}};var aa="font",la="push_action_index",ha="release_action_index",ca="toggle_button",pa="image",Ee=class extends M{areaRegion;pushed=!1;imageElement;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new H(aa)),this.properties.add(new f(ca)),this.properties.add(new P(la)),this.properties.add(new P(ha)),this.properties.add(new T(pa))}init(){if(this.image){this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()};let t=this.imageElement;this.display.getImageLoader().load(this.resolvePath(this.image)).then(e=>{t.src=e})}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.enabled&&!this.toggleButton&&(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.enabled&&(this.pushed=!1),this.requestRepaint()},mouseUp:()=>{this.enabled&&!this.toggleButton&&(this.pushed=!1,this.requestRepaint())},click:()=>{this.enabled&&(this.executeActionByIndex(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed))},tooltip:()=>this.tooltip,cursor:"pointer"}}truncateWithEllipsis(t,e,i){if(t.measureText(e).width<=i)return e;let r="...",s=t.measureText(r).width,o=0,n=e.length;for(;o<n;){let a=Math.ceil((o+n)/2);t.measureText(e.slice(0,a)).width+s<=i?o=a:n=a-1}return e.slice(0,o)+r}draw(t){let e=t.ctx,{scale:i}=this;t.fillRect({...this.area,color:this.backgroundColor}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let s=1*i,o=this.holderY+s/2,n=this.holderX+s/2,a=this.holderY+this.holderHeight-s+s/2,l=this.holderX+this.holderWidth-s+s/2;t.strokePath({lineWidth:s,color:this.pushed?m.BUTTON_LIGHTEST:m.BLACK,path:new R(l,a).lineTo(l,o).moveTo(l,a).lineTo(n,a)}),t.strokePath({lineWidth:s,color:this.pushed?this.backgroundColor:m.BUTTON_DARKER,path:new R(l-s,a-s).lineTo(l-s,o+s).moveTo(l-s,a-s).lineTo(n+s,a-s)}),t.strokePath({lineWidth:s,color:this.pushed?m.BLACK:m.BUTTON_LIGHTEST,path:new R(n,o).lineTo(l-s,o).moveTo(n,o).lineTo(n,a-s)}),t.strokePath({lineWidth:s,color:this.pushed?m.BUTTON_DARKER:this.backgroundColor,path:new R(n+s,o+s).lineTo(l-s-s,o+s).moveTo(n+s,o+s).lineTo(n+s,a-s-s)}),e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString();let h=this.text.split(`
16
- `).map(g=>this.truncateWithEllipsis(e,g,this.width)),c,d;if(this.imageElement&&this.imageLoaded){let g=e.measureText(h[0]).width,w=this.font.height,x=this.imageElement.naturalHeight*i,_=this.imageElement.naturalWidth*i,L=(this.height-x)/w,A=(this.width-_)/g,E=5*i;if(A>L){e.textBaseline="middle",e.textAlign="left",c=this.x+(this.width-g)/2+E,d=this.y+this.height/2;let I=this.x+(this.width-g)/2-_,k=this.y+(this.height-x)/2;e.drawImage(this.imageElement,I,k,_,x)}else{e.textAlign="center",e.textBaseline="top";let I=w+x;c=this.x+this.width/2,d=this.y+(this.height-I)/2+x;let k=this.x+(this.width-_)/2,F=this.y+(this.height-I)/2;e.drawImage(this.imageElement,k,F,_,x)}this.pushed&&(c+=1*i,d+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(h[0],c,d)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(h[0],c+1*i,d+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(h[0],c,d))}else{e.textAlign="start",e.textBaseline="top";let g=0;for(let _ of h){let L=e.measureText(_).width;g=Math.max(g,L)}c=this.x+(this.width-g)/2;let w=t.measureText("Mg",this.font).height,x=h.length*w;d=this.y+(this.height-x)/2;for(let _ of h){let L=c,A=d;this.pushed&&(L+=1*i,A+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(_,L,A)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(_,L+1*i,A+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(_,L,A)),d+=w}}}getHookedActions(){let{actions:t}=this;if(t.hookAllActionsToClick)return t.actions;if(this.pushed){let e=this.releaseActionIndex;return[t.getAction(e)]}else{let e=this.pushActionIndex;return[t.getAction(e)]}}get font(){return this.properties.getValue(aa).scale(this.scale)}get image(){return this.properties.getValue(pa)}get toggleButton(){return this.properties.getValue(ca)}get pushActionIndex(){return this.properties.getValue(la)}get releaseActionIndex(){return this.properties.getValue(ha)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}};var da="bit",ua="data_type",ga="effect_3d",ma="font",fa="off_color",wa="off_label",xa="off_state",ya="on_color",Pa="on_label",ba="on_state",va="password",Ra="push_action_index",_a="released_action_index",Ta="show_confirm_dialog",Sa="confirm_message",La="show_led",Ca="show_boolean_label",Aa="square_button",Oa="toggle_button",Sx="scale_options",hr=class extends M{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(da)),this.properties.add(new P(ua)),this.properties.add(new f(Aa)),this.properties.add(new f(La)),this.properties.add(new f(ga)),this.properties.add(new S(ya)),this.properties.add(new T(Pa)),this.properties.add(new T(ba)),this.properties.add(new S(fa)),this.properties.add(new T(wa)),this.properties.add(new T(xa)),this.properties.add(new H(ma)),this.properties.add(new f(Oa)),this.properties.add(new P(Ra)),this.properties.add(new P(_a)),this.properties.add(new P(Ta,0)),this.properties.add(new T(va,"")),this.properties.add(new T(Sa,"Are you sure you want to do this?")),this.properties.add(new f(Ca)),this.properties.add(new tt(Sx,new J(!0,!0,!0)))}init(){let t=this;this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{if(this.enabled){if(this.toggleButton){let e=!this.booleanValue,i;switch(this.showConfirmDialog){case 1:i=!0;break;case 2:i=e;break;case 3:i=!e;break;default:i=!1}(!i||this.openConfirmDialog())&&(e?this.toggleOn():this.toggleOff())}else(!(this.showConfirmDialog!==0)||this.openConfirmDialog())&&this.toggleOn();this.requestRepaint()}},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.enabled&&this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.enabled&&this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,get cursor(){return t.enabled?"pointer":"default"}}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?t.openPasswordDialog("Password Input Dialog","Please input the password",this.password):t.openConfirmDialog("Confirm Dialog",this.confirmMessage)}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}draw(t){let e=this.booleanValue;if(this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel){let i=e?this.onLabel:this.offLabel;this.enabled?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}):(t.fillText({x:this.x+this.width/2+this.scale,y:this.y+this.height/2+this.scale,font:this.font,color:m.BUTTON_LIGHTEST,align:"center",baseline:"middle",text:i}),t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:m.BUTTON_DARKER,align:"center",baseline:"middle",text:i}))}}drawSquare(t,e){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:m.DARK_GRAY}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let r=2*this.scale,s=e?m.DARK_GRAY:m.WHITE,o=e?m.WHITE:m.DARK_GRAY;this.effect3d&&(t.fillPath({color:s,path:new R(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+r,this.y+this.height-r).lineTo(this.x+r,this.y+r).lineTo(this.x+this.width-r,this.y+r).lineTo(this.x+this.width,this.y).closePath()}),t.fillPath({color:o,path:new R(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-r,this.y+r).lineTo(this.x+this.width-r,this.y+this.height-r).lineTo(this.x+r,this.y+this.height-r).closePath()}));let n=this.backgroundColor;this.hovered&&this.enabled&&(n=this.backgroundColor.mixWith(m.WHITE,.5)),t.fillRect({x:this.x+r,y:this.y+r,width:this.width-r-r,height:this.height-r-r,color:n})}drawEllipse(t,e){let{scale:i}=this;if(this.effect3d){let l=this.width/2,h=this.height/2,c=Math.sqrt(l*l+h*h),d=this.x+l+(h-l-c)/2-1*i,g=this.y+h-(h-l+c)/2-1*i,w=this.x+l+(h-l+c)/2+5*i,x=this.y+h-(h-l-c)/2+5*i,_=t.createLinearGradient(d,g,w,x);e?(_.addColorStop(0,m.DARK_GRAY.toString()),_.addColorStop(1,m.WHITE.toString())):(_.addColorStop(0,m.WHITE.toString()),_.addColorStop(1,m.DARK_GRAY.toString())),t.ctx.fillStyle=_}else e?t.ctx.fillStyle=m.WHITE.toString():t.ctx.fillStyle=m.DARK_GRAY.toString();let r=this.x+this.width/2,s=this.y+this.height/2,o=this.width/2,n=this.height/2;t.ctx.beginPath(),t.ctx.ellipse(r,s,o,n,0,0,2*Math.PI),t.ctx.fill(),t.addHitRegion(this.areaRegion).addEllipse(r,s,o,n,0,0,2*Math.PI),this.hovered&&this.enabled?t.ctx.fillStyle=this.backgroundColor.mixWith(m.WHITE,.5).toString():t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,s,o-i*2,n-i*2,0,0,2*Math.PI),t.ctx.fill()}drawHorizontal(t,e){let{scale:i}=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*i)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*i));let s={x:Math.floor(this.x+this.width*.79999-r/2),y:Math.floor(this.y+this.height/2-r/2),width:r,height:r},o=s.x+s.width/2,n=s.y+s.height/2,a=s.width/2,l=s.height/2,h=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:a,ry:l,color:h}),this.effect3d){let c=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);c.addColorStop(0,"white"),c.addColorStop(1,h.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,a,l,0,0,2*Math.PI),t.ctx.fillStyle=c,t.ctx.fill()}}}drawVertical(t,e){let{scale:i}=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*i)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*i));let s={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},o=e?this.onColor:this.offColor,n=s.x+s.width/2,a=s.y+s.height/2,l=s.width/2,h=s.height/2;if(t.fillEllipse({cx:n,cy:a,rx:l,ry:h,color:o}),this.effect3d){let c=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);c.addColorStop(0,m.WHITE.toString()),c.addColorStop(1,o.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(n,a,l,h,0,0,2*Math.PI),t.ctx.fillStyle=c,t.ctx.fill()}}}get bit(){return this.properties.getValue(da)}get dataType(){return this.properties.getValue(ua)}get toggleButton(){return this.properties.getValue(Oa)}get pushActionIndex(){return this.properties.getValue(Ra)}get releaseActionIndex(){return this.properties.getValue(_a)}get showConfirmDialog(){return this.properties.getValue(Ta)}get password(){return this.properties.getValue(va)}get confirmMessage(){return this.properties.getValue(Sa)}get squareButton(){return this.properties.getValue(Aa)}get showLed(){return this.properties.getValue(La)}get showBooleanLabel(){return this.properties.getValue(Ca)}get effect3d(){return this.properties.getValue(ga)}get onColor(){return this.properties.getValue(ya)}get onLabel(){return this.properties.getValue(Pa)}get onState(){return this.properties.getValue(ba)}get offColor(){return this.properties.getValue(fa)}get offLabel(){return this.properties.getValue(wa)}get offState(){return this.properties.getValue(xa)}get font(){return this.properties.getValue(ma).scale(this.scale)}};var Ea="bit",Ma="data_type",Va="effect_3d",Ia="off_color",Ba="off_label",Ha="off_state",Da="on_color",Wa="on_label",ka="on_state",Na="password",Fa="push_action_index",Ga="released_action_index",$a="show_confirm_dialog",Ua="confirm_message",Ya="toggle_button",cr=class extends M{manualToggleState=!1;shaftRegion;constructor(t,e){super(t,e),this.properties.add(new P(Ea)),this.properties.add(new P(Ma)),this.properties.add(new f(Va)),this.properties.add(new S(Da)),this.properties.add(new T(Wa)),this.properties.add(new T(ka)),this.properties.add(new S(Ia)),this.properties.add(new T(Ba)),this.properties.add(new T(Ha)),this.properties.add(new P(Fa)),this.properties.add(new P(Ga)),this.properties.add(new P($a,0)),this.properties.add(new T(Na,"")),this.properties.add(new T(Ua,"Are you sure you want to do this?")),this.properties.add(new f(Ya))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{if(this.toggleButton){let t=!this.booleanValue,e;switch(this.showConfirmDialog){case 1:e=!0;break;case 2:e=t;break;case 3:e=!t;break;default:e=!1}(!e||this.openConfirmDialog())&&(t?this.toggleOn():this.toggleOff())}else(!(this.showConfirmDialog!==0)||this.openConfirmDialog())&&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"}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?t.openPasswordDialog("Password Input Dialog","Please input the password",this.password):t.openConfirmDialog("Confirm Dialog",this.confirmMessage)}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}draw(t){let e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,r=this.height;r>i/2?r=Math.floor(this.width/2):i=Math.floor(2*this.height);let s={x:Math.floor(63/218*i),y:0,width:r/2,height:r/2};this.drawPedestal(t,s,e);let o=Math.floor(35/218*i),n=Math.floor(45/105*r),a=Math.floor(43/218*i),l=Math.floor(35/105*r),h=Math.floor(1/7*s.width);if(e){let c={x:2*s.x+s.width-o,y:s.height/2-n/2,width:o,height:n},d={x:s.x+s.width/2-a/2+h,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,d,c,!0)}else{let c={x:0,y:s.height/2-n/2,width:o,height:n},d={x:s.x+s.width/2-a/2-h,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,d,c,!1)}}drawVertical(t,e){let i=this.width,r=this.height;i>r/2?i=Math.floor(this.height/2):r=Math.floor(2*this.width);let s={x:0,y:Math.floor(63/218*r),width:i/2,height:i/2};this.drawPedestal(t,s,e);let o=Math.floor(45/105*i),n=Math.floor(35/218*r),a=Math.floor(35/105*i),l=Math.floor(43/218*r);if(e){let h={x:s.width/2-o/2,y:0,width:o,height:n},c={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};c.y-=Math.floor(1/7*s.height),this.drawVerticalBar(t,c,h,!0)}else{let h=s.y+s.height/2+l/2+2*this.scale,c={x:s.width/2-o/2,y:s.y+s.height/2-l/2+h-n,width:o,height:n},d={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};d.y+=Math.floor(1/7*s.height),this.drawVerticalBar(t,d,c,!1)}}drawPedestal(t,e,i){let r=this.x+e.x+e.width/2,s=this.y+e.y+e.height/2,o=e.width/2,n=e.height/2;if(t.ctx.fillStyle=this.effect3d?m.WHITE.toString():m.GRAY.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,s,o,n,0,0,2*Math.PI),t.ctx.fill(),this.effect3d){let a=t.createLinearGradient(this.x+e.x,this.y+e.y,this.x+e.x+e.width,this.y+e.y+e.height);i?(a.addColorStop(0,`rgba(255,255,255,${10/255})`),a.addColorStop(1,`rgba(0,0,0,${100/255})`)):(a.addColorStop(0,"rgba(0,0,0,0)"),a.addColorStop(1,`rgba(0,0,0,${150/255})`)),t.ctx.fillStyle=a,t.ctx.fill()}}drawHorizontalBar(t,e,i,r){let s=(r?0:10)/255,o=(r?150:220)/255,n=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);n.addColorStop(0,`rgba(0,0,0,${s})`),n.addColorStop(1,`rgba(0,0,0,${o})`);let a=t.addHitRegion(this.shaftRegion),l=this.x+e.x+e.width/2,h=this.y+e.y+e.height/2,c=e.width/2,d=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(l,h,c,d,0,0,2*Math.PI),a.addEllipse(l,h,c,d,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill());let g=[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(g[0],g[1]),t.ctx.lineTo(g[2],g[3]),t.ctx.lineTo(g[4],g[5]),t.ctx.lineTo(g[6],g[7]),t.ctx.closePath(),a.addPath(new R(g[0],g[1]).lineTo(g[2],g[3]).lineTo(g[4],g[5]).lineTo(g[6],g[7]).closePath()),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill()),l=this.x+i.x+i.width/2,h=this.y+i.y+i.height/2,c=i.width/2,d=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(l,h,c,d,0,0,2*Math.PI),a.addEllipse(l,h,c,d,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let{scale:w}=this,x=Math.sqrt(c*c+d*d),_=d-c,L=this.x+i.x+c+(_-x)/2-1*w,A=this.x+i.y+d-(_+x)/2-1*w,E=this.x+i.x+c+(_+x)/2+5*w,I=this.x+i.y+d-(_-x)/2+5*w,k=t.createLinearGradient(L,A,E,I);k.addColorStop(0,`rgba(0,0,0,${s})`),k.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=k,t.ctx.fill()}}drawVerticalBar(t,e,i,r){let s=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);s.addColorStop(0,`rgba(0,0,0,${10/255})`),s.addColorStop(1,`rgba(0,0,0,${r?210/255:160/255})`);let o=t.addHitRegion(this.shaftRegion),n=this.x+e.x+e.width/2,a=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(n,a,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(n,a,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=s,t.ctx.fill());let l=[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(l[0],l[1]),t.ctx.lineTo(l[2],l[3]),t.ctx.lineTo(l[4],l[5]),t.ctx.lineTo(l[6],l[7]),t.ctx.closePath(),o.addPath(new R(l[0],l[1]).lineTo(l[2],l[3]).lineTo(l[4],l[5]).lineTo(l[6],l[7]).closePath()),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=s,t.ctx.fill()),n=this.x+i.x+i.width/2,a=this.y+i.y+i.height/2;let h=i.width/2,c=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,a,h,c,0,0,2*Math.PI),o.addEllipse(n,a,h,c,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let d=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);d.addColorStop(0,`rgba(0,0,0,${(r?5:10)/255})`),d.addColorStop(1,`rgba(0,0,0,${(r?180:160)/255})`),t.ctx.fillStyle=d,t.ctx.fill()}}get bit(){return this.properties.getValue(Ea)}get dataType(){return this.properties.getValue(Ma)}get toggleButton(){return this.properties.getValue(Ya)}get pushActionIndex(){return this.properties.getValue(Fa)}get releaseActionIndex(){return this.properties.getValue(Ga)}get showConfirmDialog(){return this.properties.getValue($a)}get password(){return this.properties.getValue(Na)}get confirmMessage(){return this.properties.getValue(Ua)}get effect3d(){return this.properties.getValue(Va)}get onColor(){return this.properties.getValue(Da)}get onLabel(){return this.properties.getValue(Wa)}get onState(){return this.properties.getValue(ka)}get offColor(){return this.properties.getValue(Ia)}get offLabel(){return this.properties.getValue(Ba)}get offState(){return this.properties.getValue(Ha)}};var za="auto_size",Xa="bit",qa="enabled",Ds="font",Ka="label",ja="selected_color",Lx="scale_options",Za=16,Cx=new m(130,130,130),Ax=new m(94,151,230),Ja=4,pr=class extends M{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new f(za)),this.properties.add(new P(Xa)),this.properties.add(new f(qa)),this.properties.add(new H(Ds)),this.properties.add(new T(Ka)),this.properties.add(new S(ja,new m(64,64,64))),this.properties.add(new tt(Lx,new J(!0,!1,!1)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.enabled&&(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{let 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{let t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){return this.pv&&this.value!==void 0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.manualToggleState}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(Ds).scale(1),i=t.measureText(this.label,e,!0);this.customSize={width:i.width+Za+Ja,height:i.height}}super.drawHolder(t)}draw(t){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let i=this.booleanValue,{boxSize:r,gap:s,scale:o}=this,n=this.backgroundColor;this.hovered&&(n=n.mixWith(Ax,.7));let a={x:this.x,y:this.y+this.height/2-r/2,width:r,height:r},l=t.createLinearGradient(a.x,a.y+1*o,a.x,a.y+a.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,n.toString()),t.fillRect({...a,rx:2*o,ry:2*o,gradient:l}),t.strokeRect({x:a.x+.5*o,y:a.y+.5*o,width:a.width-1*o,height:a.height-1*o,rx:2*o,ry:2*o,color:Cx}),i&&t.strokePath({lineWidth:3*o,color:this.selectedColor,path:new R(a.x+3*o,a.y+Math.floor(r*.45)).lineTo(a.x+Math.floor(r*.45),a.y+r*3/4-1*o).lineTo(a.x+r-2*o,a.y+3*o)}),this.enabled?t.fillText({x:a.x+a.width+s,y:a.y+a.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(t.fillText({x:a.x+a.width+s+1*o,y:a.y+a.height/2+1*o,align:"left",baseline:"middle",color:m.BUTTON_LIGHTEST,font:this.font,text:this.label}),t.fillText({x:a.x+a.width+s,y:a.y+a.height/2,align:"left",baseline:"middle",color:m.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return this.scale*Za}get gap(){return this.scale*Ja}get autoSize(){return this.properties.getValue(za)}get bit(){return this.properties.getValue(Xa)}get enabled(){return this.properties.getValue(qa)}get selectedColor(){return this.properties.getValue(ja)}get font(){return this.properties.getValue(Ds).scale(this.scale)}get label(){return this.properties.getValue(Ka)}};var Qa="enabled",tl="font",el="horizontal",il="items",rl="items_from_pv",sl="selected_color",dr=class extends M{pushedItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new f(Qa)),this.properties.add(new H(tl)),this.properties.add(new f(el)),this.properties.add(new kt(il,[])),this.properties.add(new f(rl)),this.properties.add(new S(sl))}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){let e=this.area.width/this.items.length,i=this.area.x;for(let r=0;r<this.items.length;r++){let s={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,s,r)}}drawVertical(t){let e=this.area.height/this.items.length,i=this.area.y;for(let r=0;r<this.items.length;r++){let s={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,s,r)}}drawButton(t,e,i){let r=this.value===this.items[i],s=r||i===this.pushedItem;t.fillRect({...e,color:r?this.selectedColor:this.backgroundColor}),t.addHitRegion(this.itemRegions[i]).addRect(e.x,e.y,e.width,e.height);let n=1*this.scale,a=e.y+n/2,l=e.x+n/2,h=e.y+e.height-n+n/2,c=e.x+e.width-n+n/2;t.strokePath({lineWidth:n,color:s?m.BUTTON_LIGHTEST:m.BLACK,path:new R(c,h).lineTo(c,a).moveTo(c,h).lineTo(l,h)}),t.strokePath({lineWidth:n,color:s?this.backgroundColor:m.BUTTON_DARKER,path:new R(c-n,h-n).lineTo(c-n,a+n).moveTo(c-n,h-n).lineTo(l+n,h-n)}),t.strokePath({lineWidth:n,color:s?m.BLACK:m.BUTTON_LIGHTEST,path:new R(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,h-n)}),t.strokePath({lineWidth:n,color:s?m.BUTTON_DARKER:this.backgroundColor,path:new R(l+n,a+n).lineTo(c-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)}),t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:this.items[i],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(Qa)}get font(){return this.properties.getValue(tl).scale(this.scale)}get horizontal(){return this.properties.getValue(el)}get items(){return this.properties.getValue(il)}get itemsFromPV(){return this.properties.getValue(rl)}get selectedColor(){return this.properties.getValue(sl)}};var ol="enabled",nl="font",al="items",ll="items_from_pv",Ox=8,Ex=new m(0,0,0,.1),ur=class extends M{areaRegion;selectEl;renderedItems;constructor(t,e){super(t,e),this.properties.add(new f(ol)),this.properties.add(new H(nl)),this.properties.add(new kt(al,[])),this.properties.add(new f(ll))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",()=>{this.writeValue(this.selectEl?.value??""),this.requestRepaint()}),this.display.rootPanel.appendChild(this.selectEl)}draw(t){let e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`,this.updateSelectOptions(),e=D(this.bounds,2*this.scale),t.fillRect({...e,color:this.backgroundColor}),t.strokeRect({...e,color:Ex,crispen:!0}),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height);let r=this.value;if(r){let a=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let l of a){let h=l===r;if(!h)try{h=parseFloat(l)===r}catch{}h&&t.fillText({x:5*this.scale+e.x,y:e.y+e.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:r})}}let{selectorWidth:s}=this,o=Math.min(e.height,s/2),n={x:e.x+e.width-s-5*this.scale+s/2,y:e.y+(e.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new R(n.x,n.y).lineTo(n.x-o,n.y-o).lineTo(n.x+o,n.y-o).closePath()})}writeValue(t){this.pv?this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t):this.value=t}hide(){this.selectEl&&(this.selectEl.style.display="none")}updateSelectOptions(){let t=this.itemsFromPV?this.pv?.labels??[]:this.items,e=!1;if(this.renderedItems===void 0)e=!0;else if(t.length!==this.renderedItems.length)e=!0;else for(let i=0;i<t.length;i++)if(t[i]!==this.renderedItems[i]){e=!0;break}if(e){let i=this.selectEl;for(;i.firstChild;)i.removeChild(i.lastChild);let r=document.createElement("option");r.disabled=!0,r.value="",r.defaultSelected=!0,r.text=" -- select an option -- ",i.add(r);let s=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let o=0;o<s.length;o++){let n=document.createElement("option");n.value=s[o],n.text=s[o],i.add(n)}this.renderedItems=s}}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get selectorWidth(){return this.scale*Ox}get enabled(){return this.properties.getValue(ol)}get font(){return this.properties.getValue(nl).scale(this.scale)}get items(){return this.properties.getValue(al)}get itemsFromPV(){return this.properties.getValue(ll)}};var hl="auto_size",cl="bit",pl="data_type",dl="effect_3d",ul="font",Mx="height",gl="off_image",ml="off_label",fl="off_state",wl="on_image",xl="on_label",yl="on_state",Pl="password",bl="push_action_index",vl="released_action_index",Rl="show_confirm_dialog",_l="confirm_message",Tl="show_boolean_label",Sl="stretch_to_fit",Ll="toggle_button",Cl="transparency",Vx="width",gr=class extends M{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new f(hl,!0)),this.properties.add(new P(cl)),this.properties.add(new P(pl)),this.properties.add(new f(dl)),this.properties.add(new T(wl)),this.properties.add(new T(xl)),this.properties.add(new T(yl)),this.properties.add(new T(gl)),this.properties.add(new T(ml)),this.properties.add(new T(fl)),this.properties.add(new H(ul)),this.properties.add(new f(Ll)),this.properties.add(new P(bl)),this.properties.add(new P(vl)),this.properties.add(new P(Rl,0)),this.properties.add(new T(Pl,"")),this.properties.add(new T(_l,"Are you sure you want to do this?")),this.properties.add(new f(Tl)),this.properties.add(new f(Sl,!1)),this.properties.add(new f(Cl,!1))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.onImage){let t=this.onImageElement;this.display.getImageLoader().load(this.resolvePath(this.onImage)).then(e=>{t.src=e})}if(this.offImage){let t=this.offImageElement;this.display.getImageLoader().load(this.resolvePath(this.offImage)).then(e=>{t.src=e})}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{if(this.toggleButton){let t=!this.booleanValue,e;switch(this.showConfirmDialog){case 1:e=!0;break;case 2:e=t;break;case 3:e=!t;break;default:e=!1}(!e||this.openConfirmDialog())&&(t?this.toggleOn():this.toggleOff())}else(!(this.showConfirmDialog!==0)||this.openConfirmDialog())&&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"}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?t.openPasswordDialog("Password Input Dialog","Please input the password",this.password):t.openConfirmDialog("Confirm Dialog",this.confirmMessage)}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}applyAutoSize(){if(!this.autoSize||this.stretchToFit)return;let t=this.booleanValue?this.onImageElement:this.offImageElement,e=this.booleanValue?this.onImageLoaded:this.offImageLoaded;t&&e&&(this.properties.setValue(Vx,t.naturalWidth),this.properties.setValue(Mx,t.naturalHeight))}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=D(e,2*this.scale,2*this.scale));let i=this.booleanValue,r=i?this.onImageElement:this.offImageElement,s=i?this.onImageLoaded:this.offImageLoaded,o=this.stretchToFit?e.width:r?.naturalWidth,n=this.stretchToFit?e.height:r?.naturalHeight;s&&(this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(e.x,e.y,o,n)),t.ctx.drawImage(r,e.x,e.y,o,n)),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 autoSize(){return this.properties.getValue(hl)}get stretchToFit(){return this.properties.getValue(Sl)}get transparency(){return this.properties.getValue(Cl)}get bit(){return this.properties.getValue(cl)}get dataType(){return this.properties.getValue(pl)}get toggleButton(){return this.properties.getValue(Ll)}get pushActionIndex(){return this.properties.getValue(bl)}get releaseActionIndex(){return this.properties.getValue(vl)}get showConfirmDialog(){return this.properties.getValue(Rl)}get password(){return this.properties.getValue(Pl)}get confirmMessage(){return this.properties.getValue(_l)}get showBooleanLabel(){return this.properties.getValue(Tl)}get effect3d(){return this.properties.getValue(dl)}get onImage(){return this.properties.getValue(wl)}get onLabel(){return this.properties.getValue(xl)}get onState(){return this.properties.getValue(yl)}get offImage(){return this.properties.getValue(gl)}get offLabel(){return this.properties.getValue(ml)}get offState(){return this.properties.getValue(fl)}get font(){return this.properties.getValue(ul).scale(this.scale)}};function jt(p,t){let e=Math.max(Math.abs(p),Math.abs(t)),i=Math.abs(t/e-p/e);if(i>.1/e)return"############.##";let r="##.##";for(;i<1/e;)i*=10,r+="#";return r}var rt=class{prefix="";suffix="";comma=0;minInt=1;minFrac=0;maxFrac=0;constructor(t){for(let a=0;a<t.length;a++)if(t.charAt(a)=="#"||t.charAt(a)=="0"){this.prefix=t.substring(0,a),t=t.substring(a);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");let e=t.replace(/[^0#,.]/g,""),i="",r="",s=e.indexOf(".");s!==-1?(i=e.substring(0,s),r=e.substring(s+1)):i=e;let o=i.lastIndexOf(",");o!==-1&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),r=r.replace(/[,]|[.]+/g,""),this.maxFrac=r.length;let n=i.replace(/[^0]/g,"");n.length>this.minInt&&(this.minInt=n.length),n=r.replace(/[^0]/g,""),this.minFrac=n.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||e.length==0)return t;if(e.indexOf("e")!=-1){let g=Number(e);if(g===1/0||g===-1/0||(e=g+"",e.indexOf("e")!==-1))return e}let i=!1;e.charAt(0)==="-"?(i=!0,e=e.substring(1)):e.charAt(0)==="+"&&(e=e.substring(1));let r=e.indexOf("."),s="",o="";r!=-1?(s=e.substring(0,r),o=e.substring(r+1)):s=e,o=o.replace(/[.]/,"");let n=this.suffix&&this.suffix.charAt(0)==="%",a=this.minInt,l=this.minFrac,h=this.maxFrac;if(n&&(a-=2,l+=2,h+=2),o.length>h){let g=+("0."+o);g=h==0?Math.round(g):g.toFixed(h),o=g.toString(10).substr(2);let w=g>=1?1:0,x,_=s.length-1;for(;w;)if(_==-1){s="1"+s;break}else x=Number(s.charAt(_)),x===9?(x="0",w=1):(x=++x+"",w=0),s=s.substring(0,_)+x+s.substring(_+1,s.length),_--}for(let g=o.length;g<l;g++)o=o+"0";for(;o.length>l&&o.charAt(o.length-1)=="0";)o=o.substring(0,o.length-1);for(let g=s.length;g<a;g++)s="0"+s;for(;s.length>a&&s.charAt(0)=="0";)s=s.substring(1);n&&(s+=o.substring(0,2),o=o.substring(2));let c=0;for(let g=s.length;g>0;g--)c!=0&&c%this.comma==0&&(s=s.substring(0,g)+","+s.substring(g),c=0),c++;let d;return o.length>0?d=this.prefix+s+"."+o+this.suffix:d=this.prefix+s+this.suffix,i&&(d="-"+d),d}formatBack(t){if(t+="",!t)return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;t.charAt(0)==="-"&&(e=e.substr(1),i=!0);let r=e.indexOf(this.prefix),s=this.suffix==""?e.length:e.indexOf(this.suffix,this.prefix.length+1);return r==0&&s>0&&(e=e.substr(0,s),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){let i=Number(t)+"";if(t.indexOf(".")>-1&&i.indexOf(".")<0){for(var r=t.indexOf(".")+1;r<t.length;r++)if(t.charAt(r)!=="0")return t;return i}return t}};var Ix=1,Bx=8,Q=2,Zt=class{constructor(t,e,i){this.rampWidth=t;this.startAngle=e;this.endAngle=i}lolo=10;loloColor=m.RED;showLoLo=!0;lo=25;loColor=m.ORANGE;showLo=!0;hi=75;hiColor=m.ORANGE;showHi=!0;hihi=90;hihiColor=m.RED;showHiHi=!0;minimum=0;maximum=100;gradient=!0;logScale=!1;effect3d=!0;labelsOutside=!0;range={min:this.minimum,max:this.maximum};lengthInDegrees=0;radius=0;draw(t,e,i,r=!0){if(this.labelsOutside){let s=Ix+Bx;this.radius=e.width/2-s}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,r&&this.drawRamp(t,i)}drawRamp(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2,n,a=360-this.endAngle;if(this.endAngle-this.startAngle>0?n=this.startAngle-90:n=this.startAngle+90,this.showLoLo){let w=n,x=360-this.getValuePosition(this.lolo,!0);t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(w),endAngle:G(x),color:this.loloColor})}if(this.showLo){let w;this.showLoLo?w=this.lolo:w=this.minimum;let x=360-this.getValuePosition(w,!0),_=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){let L=G(this.getValuePosition(w,!0)-Q),A=ft(e.width/2,L,e),E=G(this.getValuePosition(this.lo,!0)+Q),I=ft(e.width/2,E,e),k=t.createLinearGradient(A.x,A.y,I.x,I.y);k.addColorStop(0,this.loloColor.toString()),k.addColorStop(1,this.loColor.toString()),t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(x-Q/2),endAngle:G(_+Q/2),gradient:k})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(x-Q/2),endAngle:G(_+Q/2),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let h=this.maximum;this.showHi?h=this.hi:this.showHiHi&&(h=this.hihi);let c=(l+h)/2,d=360-this.getValuePosition(l,!0),g=360-this.getValuePosition(c,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){let w=G(this.getValuePosition(l,!0)-Q),x=ft(e.width/2,w,e),_=G(this.getValuePosition(c,!0)+Q),L=ft(e.width/2,_,e),A=t.createLinearGradient(x.x,x.y,L.x,L.y);A.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),A.addColorStop(1,m.GREEN.toString()),t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+Q/2),gradient:A})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+Q/2),color:m.GREEN});if(d=360-this.getValuePosition(c,!0),g=360-this.getValuePosition(h,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){let w=G(this.getValuePosition(c,!0)-Q),x=ft(e.width/2,w,e),_=G(this.getValuePosition(h,!0)+Q),L=ft(e.width/2,_,e),A=t.createLinearGradient(x.x,x.y,L.x,L.y);A.addColorStop(0,m.GREEN.toString()),A.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());let E=g!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+E),gradient:A})}else{let w=g!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+w),color:m.GREEN})}if(this.showHi){let w;this.showHiHi?w=this.hihi:w=this.maximum;let x=360-this.getValuePosition(this.hi,!0),_=360-this.getValuePosition(w,!0);if(this.effect3d&&this.gradient&&this.showHiHi){let L=G(this.getValuePosition(this.hi,!0)-Q),A=ft(e.width/2,L,e),E=G(this.getValuePosition(w,!0)+Q),I=ft(e.width/2,E,e),k=t.createLinearGradient(A.x,A.y,I.x,I.y);k.addColorStop(0,this.hiColor.toString()),k.addColorStop(1,this.hihiColor.toString());let F=_!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(x-Q/2),endAngle:G(_+F),gradient:k})}else{let L=_!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(x-Q/2),endAngle:G(_+L),color:this.hiColor})}}if(this.showHiHi){d=360-this.getValuePosition(this.hihi,!0),g=a;let w=Q/2;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-w),endAngle:G(g),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){e&&(t=this.getValueInRange(t));let i;return this.logScale?i=this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:i=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(){let 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}};var Al=1,Hx=8,Dx=5,Wx=2,kx=1,Nx=6,Jt=class{constructor(t,e,i){this.startAngle=t;this.endAngle=e;this.direction=i}minimum=0;maximum=100;logScale=!1;showMinorTicks=!0;visible=!0;majorTickStepHint=50;majorTickLength=Hx;minorTickLength=Dx;majorLineWidth=Wx;minorLineWidth=kx;format="";font=Y.ARIAL_9;foregroundColor=m.BLACK;radius=0;getRadius(){return this.radius}formatText(t){let e=this.getRenderedRange();return this.formatValue(t,this.getAutoFormatPattern(e))}layoutTicks;layoutGeometry;layout(t,e){let i=this.getRenderedRange(),r=this.getAutoFormatPattern(i);if(this.direction==="outward"){let o=Math.max(t.measureText(this.formatValue(i.min,r),this.font).width,t.measureText(this.formatValue(i.max,r),this.font).width)+Al+this.majorTickLength,n=e.width/2-o,a=this.computeGeometry(t,e,i,r,n),l=this.getTickLabelMaxOutLength(e,a.ticks);this.radius=n-l}else this.radius=e.width/2-1;let s=this.computeGeometry(t,e,i,r,this.radius);this.layoutTicks=s.ticks,this.layoutGeometry=s}paint(t,e){if(!this.visible||!this.layoutTicks||!this.layoutGeometry)return;let i=this.layoutTicks,{lengthInDegrees:r,lengthInPixels:s,gridStepInRadians:o}=this.layoutGeometry;this.logScale?this.drawLogTickMarks(t,e,this.radius,i):this.drawLinearTickMarks(t,e,this.radius,i,o,r,s),this.drawTickLabels(t,i)}draw(t,e){this.layout(t,e),this.paint(t,e)}computeGeometry(t,e,i,r,s){let o=this.endAngle-this.startAngle>0?360-(this.endAngle-this.startAngle):this.startAngle-this.endAngle,n=Math.max(1,2*Math.PI*s*(o/360)),a,l;if(this.logScale)a=this.computeLogTicks(i,o,r);else{let h=this.getGridStep(n,i.min,i.max);l=G(o)*h/(i.max-i.min),a=this.computeLinearTicks(i,o,h,r)}return this.computeLabelAreas(t,e,s,a),this.computeLabelVisibility(a),{ticks:a,lengthInDegrees:o,lengthInPixels:n,gridStepInRadians:l}}getTickLabelMaxOutLength(t,e){let i=0,r=0,s=0,o=0;for(let n of e){let a=n.labelCenter.x-t.x-n.labelSize.width/2,l=n.labelCenter.y-t.y-n.labelSize.height/2,{width:h,height:c}=n.labelSize;a<i&&(i=a),a+h>r&&(r=a+h),l<s&&(s=l),l+c>o&&(o=l+c)}return Math.max(Math.max(r-t.width,-i),Math.max(o-t.height,-s))}getRenderedRange(){let{minimum:t,maximum:e}=this;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{min:t,max:e}}getAutoFormatPattern(t){if(this.format)return this.format;let{min:e,max:i}=t;if(i!==0&&Math.abs(Math.log10(Math.abs(i)))>=4||e!==0&&Math.abs(Math.log10(Math.abs(e)))>=4)return"scientific";if(Math.abs(i-e)>.1)return"############.##";let r="##.##",s=Math.abs(i-e);for(;s>0&&s<1;)s*=10,r+="#";return r}formatValue(t,e){return e==="scientific"?t.toExponential(4).replace(/e\+?(-?)(\d+)/,"E$1$2").replace(/(\.\d*?)0+E/,"$1E").replace(/\.E/,"E"):new rt(e).format(t)}getGridStep(t,e,i){let r=e,s=i;t<=0&&(t=1);let o=!1;if(r>=s)if(s===r)s++;else{o=!0;let g=r;r=s,s=g}let n=Math.abs(s-r),a=this.majorTickStepHint;a>t&&(a=t);let h=n/t*a,c=0;if(h<1){if(h!==0)for(;h<1;)h*=10,c--}else for(;h>=10;)h/=10,c++;let d;return h>7.5?d=10*Math.pow(10,c):h>3.5?d=5*Math.pow(10,c):h>1.5?d=2*Math.pow(10,c):d=Math.pow(10,c),o&&(d=-d),d}computeLinearTicks(t,e,i,r){let{min:s,max:o}=t,n=o<s,a=[],l;s%i<=0?l=s-s%i:l=s-s%i+i,s>l===n&&a.push(s);for(let c=l;o>=s?c<=o:c>=o;c+=i)a.push(c);let h=a[a.length-1];return(n?o<h:o>h)&&a.push(o),a.map(c=>({value:c,angle:G(this.startAngle-(c-s)/(o-s)*e),text:this.formatValue(c,r),visible:!0}))}computeLogTicks(t,e,i){let{min:r,max:s}=t,o=s<r,n=Math.log10(r),a=Math.ceil(n),l=Math.ceil(Math.log10(s)),h=Math.pow(10,a-1),c,d=r%h;d<=0||o?c=r-d:c=r-d+h;let g=[];(o?r>c:r<c)&&g.push(r);for(let w=a;o?w>=l:w<=l;w+=o?-1:1)if(Math.abs(l-a)>20){let x=Math.pow(10,w);if(x>s)break;g.push(x)}else{for(let x=c;(o?x>=Math.pow(10,w-1):x<=Math.pow(10,w))&&!(o?x<s:x>s);x+=o?-h:h)g.push(x);h=o?h/10:h*10,c=o?Math.pow(10,w-1):h+Math.pow(10,w)}return(g.length===0||s>g[g.length-1])&&g.push(s),g.map(w=>({value:w,angle:G(this.startAngle-(Math.log10(w)-n)/(Math.log10(s)-n)*e),text:this.formatValue(w,i),visible:!0}))}computeLabelAreas(t,e,i,r){for(let s of r){let o=t.measureText(s.text,this.font),n=this.majorTickLength+Al+o.width/2*Math.abs(Math.cos(s.angle))+o.height/2*Math.abs(Math.sin(s.angle)),a=this.direction==="outward"?i+n:i-n;s.labelCenter=ft(a,s.angle,e),s.labelSize=o}}computeLabelVisibility(t){if(t.length===0)return;let e=o=>({x:o.labelCenter.x-o.labelSize.width/2,y:o.labelCenter.y-o.labelSize.height/2,width:o.labelSize.width,height:o.labelSize.height}),i=(o,n)=>!(o.x+o.width<=n.x||n.x+n.width<=o.x||o.y+o.height<=n.y||n.y+n.height<=o.y),r=e(t[0]),s=null;for(let o=0;o<t.length;o++){let n=!0;if(o!==0){let c=e(t[o]);o!==t.length-1?n=!i(r,c)&&!i(c,e(t[t.length-1])):n=!i(r,c)&&!i(e(t[0]),c)}let a=t[o].text,l=a===s&&o!==0&&o!==t.length-1;s=a;let h=!0;this.logScale&&(h=this.isMajorLogTick(t[o].value)||o===0||o===t.length-1),!n||l||!h?t[o].visible=!1:r=e(t[o])}}isMajorLogTick(t){let e=Math.log10(t);return Math.abs(e-Math.round(e))<1e-9}drawTickLine(t,e,i,r,s,o){let n=ft(i,r,e),a=this.direction==="outward"?i+s:i-s,l=ft(a,r,e);t.strokePath({path:new R(n.x,n.y).lineTo(l.x,l.y),color:this.foregroundColor,lineWidth:o})}drawLinearTickMarks(t,e,i,r,s,o,n){let a=G(o)*Nx/n,l;s/5>=a?l=5:s/4>=a?l=4:l=2;let h=s/l,c=G(o)*2/n;for(let d=0;d<r.length;d++)if(this.drawTickLine(t,e,i,r[d].angle,this.majorTickLength,this.majorLineWidth),this.showMinorTicks&&d>0)if(d===1&&Math.abs(r[0].angle-r[1].angle)<s){let g=r[1].angle;for(;Math.abs(r[0].angle-g)>h+c;)g+=h,this.drawTickLine(t,e,i,g,this.minorTickLength,this.minorLineWidth)}else if(d===r.length-1&&Math.abs(r[d-1].angle-r[d].angle)<s){let g=r[d-1].angle;for(;Math.abs(g-r[d].angle)>h+c;)g-=h,this.drawTickLine(t,e,i,g,this.minorTickLength,this.minorLineWidth)}else for(let g=1;g<l;g++){let w=r[d-1].angle+(r[d].angle-r[d-1].angle)*g/l;this.drawTickLine(t,e,i,w,this.minorTickLength,this.minorLineWidth)}}drawLogTickMarks(t,e,i,r){for(let s of r){let o=s.visible?this.majorTickLength:this.minorTickLength,n=s.visible?this.majorLineWidth:this.minorLineWidth;this.drawTickLine(t,e,i,s.angle,o,n)}}drawTickLabels(t,e){for(let i of e)i.visible&&t.fillText({x:i.labelCenter.x,y:i.labelCenter.y,align:"center",baseline:"middle",font:this.font,color:this.foregroundColor,text:i.text})}};var Fx=2,Gx=4,$x=12,Ux=8,Yx=5,zx=100/255,mr=225,Ws=315,le=270,Ol="color_hi",El="color_hihi",Ml="color_lo",Vl="color_lolo",Il="effect_3d",Bl="font",Hl="increment",Dl="knob_color",Wl="level_hi",kl="level_hihi",Nl="level_lo",Fl="level_lolo",Gl="limits_from_pv",$l="log_scale",Ul="major_tick_step_hint",Yl="maximum",zl="minimum",Xl="ramp_gradient",ks="scale_font",ql="scale_format",Kl="show_hi",jl="show_hihi",Zl="show_lo",Jl="show_lolo",Ql="show_markers",th="show_minor_ticks",eh="show_scale",ih="show_value_label",rh="thumb_color",sh="transparent_background",oh="value_label_format",Xx="scale_options",fr=class extends M{thumbRegion;dragValue;dragAngle;scaleLayoutCache;valueLabelFormatCache;constructor(t,e){super(t,e),this.properties.add(new S(Ol)),this.properties.add(new S(El)),this.properties.add(new S(Ml)),this.properties.add(new S(Vl)),this.properties.add(new f(Il)),this.properties.add(new H(Bl)),this.properties.add(new C(Hl,1)),this.properties.add(new S(Dl)),this.properties.add(new C(Wl)),this.properties.add(new C(kl)),this.properties.add(new C(Nl)),this.properties.add(new C(Fl)),this.properties.add(new f(Gl,!0)),this.properties.add(new f($l)),this.properties.add(new P(Ul,50)),this.properties.add(new C(Yl)),this.properties.add(new C(zl)),this.properties.add(new f(Xl)),this.properties.add(new H(ks)),this.properties.add(new T(ql)),this.properties.add(new f(Kl,!0)),this.properties.add(new f(jl,!0)),this.properties.add(new f(Zl,!0)),this.properties.add(new f(Jl,!0)),this.properties.add(new f(Ql,!0)),this.properties.add(new f(th,!0)),this.properties.add(new f(eh,!0)),this.properties.add(new f(ih,!0)),this.properties.add(new S(rh)),this.properties.add(new f(sh,!0)),this.properties.add(new T(oh)),this.properties.add(new tt(Xx,new J(!0,!0,!0)))}init(){this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{if(!this.enabled)return;let t=this.computeLimits();this.dragValue=this.value!==void 0?this.getValueInRange(this.value,t):(t.min+t.max)/2,this.dragAngle=this.toRelativeAngle(this.getValuePosition(this.dragValue,t))},grab:t=>{if(!this.enabled||this.dragValue===void 0||this.dragAngle===void 0)return;let e=this.computeLimits(),i=Math.min(this.width,this.height),{x:r,y:s}=this.getAbsoluteCenter(i),o=this.toRelativeAngle(this.pointToAbsoluteAngle(t.point,r,s));if(o>le){let h=(le+360)/2;o=o<h?le:0}let n=o-this.dragAngle,a=this.calcValueChange(n,this.dragValue,e),{increment:l}=this;if(l<=0||Math.abs(a)>l/2){let h=l>0?this.dragValue+l*Math.round(a/l):this.dragValue+a;h=Math.min(e.max,Math.max(e.min,h)),this.setCoercedValue(h,e),this.dragValue=h,this.dragAngle=this.toRelativeAngle(this.getValuePosition(h,e)),this.requestRepaint()}},cursor:"pointer",tooltip:()=>this.tooltip}}draw(t){this.transparentBackground||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});let e=this.computeLimits(),i=Math.min(this.width,this.height),r=D({x:this.x,y:this.y,width:i,height:i},Fx*this.scale),s=this.getLayoutScale(e,t,r);s.visible=this.showScale,s.showMinorTicks=this.showMinorTicks,s.foregroundColor=this.foregroundColor;let o=s.getRadius(),n=r.width/2-o+Gx*this.scale,a=D(r,n),l=$x*this.scale,h=r.width/2-o-l+2*this.scale,c=D(r,h);this.showMarkers&&this.drawRamp(t,r,c,l,e),this.drawBulb(t,a),s.paint(t,r),this.drawValueLabel(t,a,e),this.drawThumb(t,r,a,e),this.enabled||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:m.GRAY,opacity:zx})}computeLimits(){let t;return this.limitsFromPv&&this.pv&&!this.pv.disconnected?t={min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:t={min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(t.min=Math.max(.1,t.min),t.max<=t.min&&(t.max=t.min+100)),t}buildScale(t){let e=new Jt(mr,Ws,"outward");return e.minimum=t.min,e.maximum=t.max,e.logScale=this.logScale,e.majorTickStepHint=this.majorTickStepHint*this.scale,e.majorTickLength=this.majorTickLength,e.minorTickLength=this.minorTickLength,e.majorLineWidth=2*this.scale,e.minorLineWidth=1*this.scale,e.format=this.scaleFormat,e.font=this.scaleFont,e}getLayoutScale(t,e,i){let r=this.properties.getValue(ks),s=this.scale,o=this.majorTickStepHint,n=this.scaleFormat,a=this.scaleLayoutCache;if(a!==void 0&&a.min===t.min&&a.max===t.max&&a.logScale===this.logScale&&a.majorTickStepHint===o&&a.format===n&&a.fontRaw===r&&a.widgetScale===s&&a.areaX===i.x&&a.areaY===i.y&&a.areaWidth===i.width&&a.areaHeight===i.height)return a.scale;let h=this.buildScale(t);return h.layout(e,i),this.scaleLayoutCache={scale:h,min:t.min,max:t.max,logScale:this.logScale,majorTickStepHint:o,format:n,fontRaw:r,widgetScale:s,areaX:i.x,areaY:i.y,areaWidth:i.width,areaHeight:i.height},h}drawRamp(t,e,i,r,s){let o=new Zt(r,mr,Ws);o.lolo=s.lolo,o.loloColor=this.colorLoLo,o.showLoLo=this.showLoLo,o.lo=s.lo,o.loColor=this.colorLo,o.showLo=this.showLo,o.hi=s.hi,o.hiColor=this.colorHi,o.showHi=this.showHi,o.hihi=s.hihi,o.hihiColor=this.colorHiHi,o.showHiHi=this.showHiHi,o.minimum=s.min,o.maximum=s.max,o.effect3d=this.effect3d,o.gradient=this.rampGradient,o.logScale=this.logScale,o.draw(t,e,i)}drawBulb(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;if(t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.knobColor}),this.effect3d){let n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.knobColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n})}}drawValueLabel(t,e,i){if(!this.showValueLabel||this.value===void 0)return;let r=Y.ARIAL_12_BOLD.scale(this.scale),s=this.formatLabelValue(this.value,i),o=t.measureText(s,r);t.fillText({x:e.x+e.width/2-o.width/2,y:e.y+e.height*3/4-o.height/2,align:"left",baseline:"top",font:r,text:s,color:this.foregroundColor})}drawThumb(t,e,i,r){let s=e.x+e.width/2,o=e.y+e.height/2,n=this.value!==void 0?this.getValueInRange(this.value,r):(r.min+r.max)/2,a=360-this.getValuePosition(n,r),l=G(a),h=i.x+i.width*7/8,c=i.y+i.height/2,d=Tt(h,c,s,o,l),g=i.width/12;if(t.fillEllipse({cx:d.x,cy:d.y,rx:g,ry:g,color:this.thumbColor}),this.effect3d){let x=t.createLinearGradient(d.x-g,d.y-g,d.x+g,d.y+g);x.addColorStop(0,m.WHITE.toString()),x.addColorStop(1,this.thumbColor.withAlpha(0).toString()),t.fillEllipse({cx:d.x,cy:d.y,rx:g,ry:g,gradient:x})}t.addHitRegion(this.thumbRegion).addEllipse(d.x,d.y,g,g,0,0,2*Math.PI)}getValuePosition(t,e){let i;return this.logScale?i=mr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*le:i=mr-(t-e.min)/(e.max-e.min)*le,i<0&&(i+=360),i}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getAbsoluteCenter(t){let e=this.display.measureAbsoluteOffset(this);return{x:this.x+t/2+e.x,y:this.y+t/2+e.y}}pointToAbsoluteAngle(t,e,i){let r=Math.atan2(t.y-i,t.x-e)*180/Math.PI;return r<0&&(r+=360),((360-r)%360+360)%360}toRelativeAngle(t){return((t-Ws)%360+360)%360}calcValueChange(t,e,i){if(this.logScale){let r=le/(Math.log10(i.max)-Math.log10(i.min));return e*(Math.pow(10,-t/r)-1)}else return-(i.max-i.min)*t/le}setCoercedValue(t,e){t=t<e.min?e.min:t>e.max?e.max:t,this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,t):this.pv||(this.value=t)}formatLabelValue(t,e){let i=this.valueLabelFormat,r=this.valueLabelFormatCache,s=r!==void 0&&r.formatProp===i&&(i!==""||r.min===e.min&&r.max===e.max),o;if(s)o=r.formatter;else{let n=i||jt(e.min,e.max);o=new rt(n),this.valueLabelFormatCache={formatProp:i,min:e.min,max:e.max,formatter:o}}return o.format(t)}get majorTickLength(){return this.scale*Ux}get minorTickLength(){return this.scale*Yx}get colorLo(){return this.properties.getValue(Ml)}get colorLoLo(){return this.properties.getValue(Vl)}get colorHi(){return this.properties.getValue(Ol)}get colorHiHi(){return this.properties.getValue(El)}get effect3d(){return this.properties.getValue(Il)}get font(){return this.properties.getValue(Bl).scale(this.scale)}get increment(){return this.properties.getValue(Hl)}get knobColor(){return this.properties.getValue(Dl)}get levelLo(){return this.properties.getValue(Nl)}get levelLoLo(){return this.properties.getValue(Fl)}get levelHi(){return this.properties.getValue(Wl)}get levelHiHi(){return this.properties.getValue(kl)}get limitsFromPv(){return this.properties.getValue(Gl)}get logScale(){return this.properties.getValue($l)}get majorTickStepHint(){return this.properties.getValue(Ul)}get maximum(){return this.properties.getValue(Yl)}get minimum(){return this.properties.getValue(zl)}get rampGradient(){return this.properties.getValue(Xl)}get scaleFont(){return this.properties.getValue(ks).scale(this.scale)}get scaleFormat(){return this.properties.getValue(ql)}get showHi(){return this.properties.getValue(Kl)}get showHiHi(){return this.properties.getValue(jl)}get showLo(){return this.properties.getValue(Zl)}get showLoLo(){return this.properties.getValue(Jl)}get showMarkers(){return this.properties.getValue(Ql)}get showMinorTicks(){return this.properties.getValue(th)}get showScale(){return this.properties.getValue(eh)}get showValueLabel(){return this.properties.getValue(ih)}get thumbColor(){return this.properties.getValue(rh)}get transparentBackground(){return this.properties.getValue(sh)}get valueLabelFormat(){return this.properties.getValue(oh)}};var nh="font",ah="label",wr=class extends M{areaRegion;selectEl;constructor(t,e){super(t,e),this.properties.add(new H(nh)),this.properties.add(new T(ah))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip,cursor:"pointer"},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",i=>{let r=this.selectEl?.value;if(r){this.selectEl.selectedIndex=0;let s=Number(r.substring(7));this.executeActionByIndex(s)}});let t=document.createElement("option");t.disabled=!0,t.value="",t.defaultSelected=!0,t.text=" -- select an option -- ",this.selectEl.add(t);let e=this.actions.actions;for(let i=0;i<e.length;i++){let r=document.createElement("option");r.value=`action-${i}`,r.text=e[i]?.getDescription()??"",this.selectEl.add(r)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){let e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`;let i=t.ctx;t.fillRect({...this.area,color:this.backgroundColor}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let s=this.label.split(`
17
- `);i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),i.textBaseline="middle",i.textAlign="center";let o=this.x+this.width/2,n=this.y+this.height/2;i.fillText(s[0],o,n)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get font(){return this.properties.getValue(nh).scale(this.scale)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}get label(){return this.properties.getValue(ah)}};var xr=class extends Ee{};var lh="enabled",hh="font",ch="horizontal",ph="items",dh="items_from_pv",uh="selected_color",qx=7,Kx=2,jx=4,Zx=new m(120,120,120),Jx=new m(94,151,230),yr=class extends M{hoveredItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new f(lh)),this.properties.add(new H(hh)),this.properties.add(new f(ch)),this.properties.add(new kt(ph,[])),this.properties.add(new f(dh)),this.properties.add(new S(uh))}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){let e=this.area.width/this.items.length,i=this.area.x;for(let r=0;r<this.items.length;r++){let s={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,s,r)}}drawVertical(t){let e=this.area.height/this.items.length,i=this.area.y;for(let r=0;r<this.items.length;r++){let s={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,s,r)}}drawRadio(t,e,i){let{radioRadius:r,dotRadius:s,gap:o}=this,n=this.backgroundColor;i===this.hoveredItem&&(n=n.mixWith(Jx,.7));let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,m.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:r,ry:r,gradient:a});let l=1*this.scale;t.strokeEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:r,ry:r,color:Zx,lineWidth:l}),this.value===this.items[i]&&t.fillEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:s+l/2,ry:s+l/2,color:this.selectedColor}),t.addHitRegion(this.itemRegions[i]).addRect(e.x,e.y,e.width,e.height),t.fillText({x:e.x+r+r+o,y:e.y+e.height/2,text:this.items[i],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&!this.pv.writable||(this.value=t,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,t))}get radioRadius(){return this.scale*qx}get dotRadius(){return this.scale*Kx}get gap(){return this.scale*jx}get enabled(){return this.properties.getValue(lh)}get font(){return this.properties.getValue(hh).scale(this.scale)}get horizontal(){return this.properties.getValue(ch)}get items(){return this.properties.getValue(ph)}get itemsFromPV(){return this.properties.getValue(dh)}get selectedColor(){return this.properties.getValue(uh)}};var Qx=["January","February","March","April","May","June","July","August","September","October","November","December"],nt=class{constructor(t,e,i,r,s,o,n,a,l,h){this.formatter=t;this.scale=e;this.scaleFont=i;this.minimum=r;this.maximum=s;this.logScale=o;this.majorTickStepHint=n;this.foregroundColor=a;this.showMinorTicks=l;this.showScale=h}labels=[];labelValues=[];labelPositions=[];labelVisibilities=[];gridStepInPixel=0;horizontal=!1;x=0;y=0;scaleFormat="";timeFormat=0;length=0;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(e=>this.length-e)),t.pop(),t.shift(),t}setDimensions(t,e,i,r){this.x=t,this.y=e,this.length=i,this.horizontal=r}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),r=0,s=this.length-2*this.margin;if(this.logScale)t<=0?r=this.margin:r=(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*s+this.margin;else{let o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;let n=i-e;r=(t/o-e)/n*s+this.margin}return this.horizontal?r+this.x:this.length-r+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){let e=this.getMinMax(),{start:i,stop:r}=e,s=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin,n;if(this.logScale)n=Math.pow(10,(s-this.margin)*(Math.log10(r)-Math.log10(i))/o+Math.log10(i));else{let a=Math.max(Math.abs(i),Math.abs(r));r/=a,i/=a;let l=r-i;n=((s-this.margin)/o*l+i)*a}return n}calculateMargin(t,e){if(this.showScale){let i=t.measureText(this.format(this.minimum),this.scaleFont),r=t.measureText(this.format(this.maximum),this.scaleFont);return Math.ceil(e?Math.max(i.width,r.width)/2:Math.max(i.height,r.height)/2)}else return 0}measureHorizontalHeight(t){let e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,r){let{scale:s}=this;this.length=r,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);let o=r-2*this.margin;o>0&&this.updateLabels(t,o);let n=0;for(let l=0;l<this.labels.length;l++){let h=t.measureText(this.labels[l],this.scaleFont);h.height>n&&(n=h.height)}let a=this.showScale?n+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i=i-a,this.x=e,this.y=i,this.logScale)for(let l=0;l<this.labelPositions.length;l++){let h=this.x+this.labelPositions[l],c=this.y,d=0;if(this.labelVisibilities[l]?d=this.majorTickLength:d=this.minorTickLength,this.labelVisibilities[l]||this.showMinorTicks){let g=Math.round(h)-s*.5;t.strokePath({path:new R(g,c).lineTo(g,c+d),color:this.foregroundColor,lineWidth:s*1,opacity:100/255})}this.labelVisibilities[l]&&t.fillText({x:h,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]})}else for(let l=0;l<this.labels.length;l++){let h=e+this.labelPositions[l];this.labelVisibilities[l]&&t.fillText({x:h,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]});let c=Math.round(h)-s*.5;t.strokePath({path:new R(c,i).lineTo(c,i+this.majorTickLength),color:this.foregroundColor,lineWidth:s*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,l,e,i)}return a}drawVertical(t,e,i,r,s,o=!1){let{scale:n}=this;this.length=r,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);let a=r-2*this.margin;a>0&&this.updateLabels(t,a);let l=0;for(let c=0;c<this.labels.length;c++){let d=t.measureText(this.labels[c],this.scaleFont);d.width>l&&(l=d.width)}let h=this.showScale?l+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(s||(e=e-h),this.x=e,this.y=i,this.logScale)for(let c=0;c<this.labelPositions.length;c++){let d;this.labelVisibilities[c]?d=this.majorTickLength:d=this.minorTickLength;let g=Math.round(i+r-this.labelPositions[c])-n*.5;if(o){if((this.labelVisibilities[c]||this.showMinorTicks)&&t.strokePath({path:new R(e,g).lineTo(e+d,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[c]){let w=i+r-this.labelPositions[c];t.fillText({x:e+this.majorTickLength+this.spaceBetweenMarkAndLabel,y:w,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[c]})}}else{let w=e+l+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-d;if((this.labelVisibilities[c]||this.showMinorTicks)&&t.strokePath({path:new R(w,g).lineTo(w+d,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[c]){let x=i+r-this.labelPositions[c];t.fillText({x:e,y:x,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[c]})}}}else for(let c=0;c<this.labels.length;c++){let d=i+r-this.labelPositions[c],g=Math.round(d)-n*.5;if(o){if(t.strokePath({path:new R(e,g).lineTo(e+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[c]){let w=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:w,y:d,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[c]})}}else{this.labelVisibilities[c]&&t.fillText({x:e,y:d,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[c]});let w=e+l+this.spaceBetweenMarkAndLabel-n*1;t.strokePath({path:new R(w,g).lineTo(w+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,c,w,i+r)}}return h}drawMinorXTicks(t,e,i,r){let{gridStepInPixel:s}=this,o,n;s/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(s/5)):s/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(s/4)):(o=2,n=Math.floor(s/2));let{labelPositions:a,minorTickLength:l,scale:h}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let c=a[1];for(;c-a[0]>n+3*h;){c=c-n;let d=Math.round(i+c)-h*.5;t.strokePath({path:new R(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let c=a[e-1];for(;a[e]-c>n+3*h;){c=c+n;let d=Math.round(i+c)-h*.5;t.strokePath({path:new R(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else for(let c=0;c<o;c++){let d=i+a[e-1]+(a[e]-a[e-1])*c/o;d=Math.round(d)-h*.5,t.strokePath({path:new R(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}drawMinorYTicks(t,e,i,r){let{gridStepInPixel:s}=this,o,n;s/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(s/5)):s/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(s/4)):(o=2,n=Math.floor(s/2));let{labelPositions:a,minorTickLength:l,majorTickLength:h,scale:c}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let d=a[1];for(;d-a[0]>n+3*c;){d-=n;let g=Math.round(r-d)-c*.5;t.strokePath({path:new R(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let d=a[e-1];for(;a[e]-d>n+3*c;){d+=n;let g=Math.round(r-d)-c*.5;t.strokePath({path:new R(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else for(let d=0;d<o;d++){let g=r-a[e-1]-(a[e]-a[e-1])*d/o;g=Math.round(g)-c*.5,t.strokePath({path:new R(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:c*1,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{let i=this.getGridStep(e,this.minimum,this.maximum),r=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/r-this.minimum/r;this.gridStepInPixel=Math.floor(e*(i/r)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,i)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let r=!1;if(e>=i)if(i===e)i++;else{r=!0;let c=e;e=i,i=c}let s=Math.abs(i-e),o=this.majorTickStepHint;o>t&&(o=t);let a=s/t*o,l=0;if(a<1){if(a!=0)for(;a<1;)a*=10,l--}else for(;a>=10;)a/=10,l++;let h;return a>7.5?h=10*Math.pow(10,l):a>3.5?h=5*Math.pow(10,l):a>1.5?h=2*Math.pow(10,l):h=Math.pow(10,l),r&&(h=-h),h}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);let r=e<t,s=Math.log10(t),o=Math.ceil(s),n=Math.ceil(Math.log10(e)),a=Math.pow(10,o-1),l;t%a<=0||r?l=t-t%a:l=t-t%a+a,r&&t>l?this.addMinMaxTickInfo(t,i,!0):!r&&t<l&&this.addMinMaxTickInfo(t,i,!0);for(let h=o;r?h>=n:h<=n;h+=r?-1:1)if(Math.abs(n-o)>20){let c=Math.pow(10,h);if(c>e)break;this.addTickInfo(c,e,s,i)}else{for(let c=l;(r?c>=Math.pow(10,h-1):c<=Math.pow(10,h))&&!(r?c<e:c>e);c=r?c-a:c+a)this.addTickInfo(c,e,s,i);a=r?a/Math.pow(10,1):a*Math.pow(10,1),l=r?Math.pow(10,h-1):a+Math.pow(10,h)}(r?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,r){this.labels.push(this.format(t));let s=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*r)+this.margin;this.labelPositions.push(s),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,r){let s=e<t,o;t%r<=0?o=t-t%r:o=t-t%r+r,t>o==s&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let n=1,a=Math.max(Math.abs(t),Math.abs(e));e/=a,t/=a,r/=a,o/=a;let l=e-t;for(let h=o;e>=t?h<e:h>e;h=o+n++*r){let c=h*a;this.labels.push(this.format(c)),this.labelValues.push(c);let d=Math.floor((h-t)/l*i)+this.margin;this.labelPositions.push(d)}e*=a,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 r=0;r<this.labelPositions.length;r++)this.labelVisibilities.push(!0);let e=0,i=null;for(let r=0;r<this.labelPositions.length;r++){let s=!0,o=this.labels[r],n=this.labelPositions[r];r!==0&&(s=this.hasSpaceToDraw(t,e,n,i||"",o));let a=o===i&&r!==0&&r!==this.labelPositions.length-1,l=!0;if(this.logScale){let h=Number(this.labels[r]);l=this.isMajorTick(h)||r===0||r===this.labelPositions.length-1}!s||a||!l?this.labelVisibilities[r]=!1:(e=n,i=o)}}hasSpaceToDraw(t,e,i,r,s){let o=t.measureText(s,this.scaleFont),n=t.measureText(r,this.scaleFont),a=i-e,l=Math.floor(this.horizontal?o.width/2+n.width/2:o.height),h=!0,c=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){h=a>l+this.tickLabelGap;let d=t.measureText(this.labels[this.labels.length-1],this.scaleFont);a=this.labelPositions[this.labelPositions.length-1]-i,l=Math.floor(this.horizontal?o.width/2+d.width/2:o.height),c=a>l+this.tickLabelGap}return h&&c}isMajorTick(t){if(!this.logScale)return!0;let e=Math.log10(t);return e===Math.round(e)}format(t){if(this.timeFormat===0)return this.scaleFormat?new rt(this.scaleFormat).format(t):String(Number(t.toFixed(2)));let e=new Date(t),i=this.formatter;switch(this.timeFormat){case 1:return i.formatDate(e,{year:!0,month:!0,day:!0})+`
12
+ `);for(let d=0;d<e.expressions.length;d++){let g=e.expressions[d].expression,x=e.expressions[d].outputValue;if(d>0&&(r+="else "),r+=`if (${g}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)r+=`${x});
13
+ `;else{let w=this.printScriptValue(s,x);r+=`${w});
14
+ `}}let h=s.value,p=this.printScriptValue(s,h);r+=`else widget.setPropertyValue("${e.propertyName}", `,r+=`${p});
15
+ `}this.scriptEngine=new zt(t,r,i)}scriptEngine;triggerListeners=[];printScriptValue(t,e){return e==null?"null":t.printScriptValue(e)}};var Zt=class{constructor(t,e,i){this.pv=t;this.interval=e;i!==void 0&&t.pvEngine.setValue(new Date,t.name,i,"NONE",t.units),this.interval>0&&(this.timer=window.setInterval(()=>{this.generateSample(new Date)},e))}timer;emit(t,e){let i="NONE";this.pv.lowerAlarmLimit!==void 0&&e<this.pv.lowerAlarmLimit?i="MAJOR":this.pv.upperAlarmLimit!==void 0&&e>this.pv.upperAlarmLimit?i="MAJOR":this.pv.lowerWarningLimit!==void 0&&e<this.pv.lowerWarningLimit?i="MINOR":this.pv.upperWarningLimit!==void 0&&e>this.pv.upperWarningLimit&&(i="MINOR"),this.pv.pvEngine.setValue(t,this.pv.name,e,i,this.pv.units)}stop(){window.clearInterval(this.timer)}},Lt=class extends Zt{constructor(t,e){super(t,-1,e)}generateSample(){}},lr=class extends Zt{constructor(e,i){super(e,1e3);this.formatter=i}generateSample(e){let i=this.formatter.formatDate(e,{year:!0,month:!0,day:!0})+" "+this.formatter.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});this.emit(e,i)}};var ii=class extends Zt{constructor(e,i,r,s){super(e,s);this.min=i;this.max=r;let o=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+o*.1,e.lowerWarningLimit=i+o*.2,e.upperWarningLimit=i+o*.8,e.upperAlarmLimit=i+o*.9,e.upperDisplayLimit=r}generateSample(e){let i=Math.random()*(this.max-this.min)+this.min;this.emit(e,i)}},ri=class extends Zt{constructor(e,i,r,s){super(e,s);this.avg=i;this.stddev=r;e.units="x",e.lowerDisplayLimit=i-4*r,e.lowerAlarmLimit=i-2*r,e.lowerWarningLimit=i-r,e.upperWarningLimit=i+r,e.upperAlarmLimit=i+2*r,e.upperDisplayLimit=i+4*r}generateSample(e){let i,r,s;do i=2*Math.random()-1,r=2*Math.random()-1,s=i*i+r*r;while(s>=1||s===0);let o=Math.sqrt(-2*Math.log(s)/s),n=i*o;this.emit(e,this.avg+n*this.stddev)}},Me=class extends Zt{constructor(e,i,r,s,o){super(e,o);this.min=i;this.max=r;this.samplesPerCycle=s;let n=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+n*.1,e.lowerWarningLimit=i+n*.2,e.upperWarningLimit=i+n*.8,e.upperAlarmLimit=i+n*.9,e.upperDisplayLimit=r}currentValue=0;generateSample(e){let i=this.max-this.min,r=Math.sin(this.currentValue*2*Math.PI/this.samplesPerCycle)*i/2+this.min+i/2;this.currentValue++,this.emit(e,r)}},Ve=class extends Zt{constructor(e,i,r,s,o){super(e,o);this.min=i;this.max=r;this.inc=s;s>=0?this.currentValue=i-s:this.currentValue=r-s;let n=this.max-this.min;e.units="x",e.lowerDisplayLimit=i,e.lowerAlarmLimit=i+n*.1,e.lowerWarningLimit=i+n*.2,e.upperWarningLimit=i+n*.8,e.upperAlarmLimit=i+n*.9,e.upperDisplayLimit=r}currentValue=0;generateSample(e){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(e,this.currentValue)}};var Cx=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/,hr=class{pvs=new Map;canProvide(t){return t.startsWith("sim://")}startProviding(t){for(let e of t){let i=new Ws(e);this.pvs.set(e.name,i)}}stopProviding(t){for(let e of t){let i=this.pvs.get(e.name);i&&(i.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(let t of this.pvs.values())t.fn.stop()}},Ws=class{constructor(t){this.pv=t;let e=t.name.match(Cx);if(e){let i=e[3]?e[3].split(","):[];for(let r=0;r<i.length;r++)i[r]=i[r].trim();this.fn=this.createGenerator(e[1],i)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new Lt(t,void 0)}fn;createGenerator(t,e){switch(t){case"const":let i=this.saferEval(e[0]);return new Lt(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 Lt(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(t.length===0)return new ii(this.pv,-5,5,1e3);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new ii(this.pv,e,i,r)}}createGaussianNoise(t){if(t.length===0)return new ri(this.pv,0,1,100);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new ri(this.pv,e,i,r)}}createRamp(t){let e;if(t.length===0)e=new Ve(this.pv,-5,5,1,1e3);else if(t.length===3){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2])*1e3;e=new Ve(this.pv,i,r,1,s)}else if(t.length===4){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2]),o=parseFloat(t[3])*1e3;e=new Ve(this.pv,i,r,s,o)}else return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new Lt(this.pv,void 0);return e}createSine(t){let e;if(t.length===0)e=new Me(this.pv,-5,5,10,1e3);else if(t.length===3){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2])*1e3;e=new Me(this.pv,i,r,10,s)}else if(t.length===4){let i=parseFloat(t[0]),r=parseFloat(t[1]),s=parseFloat(t[2]),o=parseFloat(t[3])*1e3;e=new Me(this.pv,i,r,s,o)}else return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new Lt(this.pv,void 0);return e}};var Ax=/sys\:\/\/([a-zA-Z]+)/,cr=class{constructor(t){this.formatter=t}pvs=new Map;canProvide(t){return t==="sys://time"}startProviding(t){for(let e of t){let i=new ks(e,this.formatter);this.pvs.set(e.name,i)}}stopProviding(t){for(let e of t){let i=this.pvs.get(e.name);i&&(i.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(let t of this.pvs.values())t.fn.stop()}},ks=class{constructor(t,e){this.pv=t;this.formatter=e;let i=t.name.match(Ax);i?this.fn=this.createGenerator(i[1]):(console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new Lt(t,void 0))}fn;createGenerator(t){return t==="time"?new lr(this.pv,this.formatter):(console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new Lt(this.pv,void 0))}};var pa="font",da="push_action_index",ua="release_action_index",ga="toggle_button",ma="image",Ie=class extends M{areaRegion;pushed=!1;imageElement;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new H(pa)),this.properties.add(new f(ga)),this.properties.add(new P(da)),this.properties.add(new P(ua)),this.properties.add(new T(ma))}init(){if(this.image){this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()};let t=this.imageElement;this.display.getImageLoader().load(this.resolvePath(this.image)).then(e=>{t.src=e})}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.enabled&&!this.toggleButton&&(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.enabled&&(this.pushed=!1),this.requestRepaint()},mouseUp:()=>{this.enabled&&!this.toggleButton&&(this.pushed=!1,this.requestRepaint())},click:()=>{this.enabled&&(this.executeActionByIndex(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed))},tooltip:()=>this.tooltip,cursor:"pointer"}}truncateWithEllipsis(t,e,i){if(t.measureText(e).width<=i)return e;let r="...",s=t.measureText(r).width,o=0,n=e.length;for(;o<n;){let a=Math.ceil((o+n)/2);t.measureText(e.slice(0,a)).width+s<=i?o=a:n=a-1}return e.slice(0,o)+r}draw(t){let e=t.ctx,{scale:i}=this;t.fillRect({...this.area,color:this.backgroundColor}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let s=1*i,o=this.holderY+s/2,n=this.holderX+s/2,a=this.holderY+this.holderHeight-s+s/2,l=this.holderX+this.holderWidth-s+s/2;t.strokePath({lineWidth:s,color:this.pushed?m.BUTTON_LIGHTEST:m.BLACK,path:new _(l,a).lineTo(l,o).moveTo(l,a).lineTo(n,a)}),t.strokePath({lineWidth:s,color:this.pushed?this.backgroundColor:m.BUTTON_DARKER,path:new _(l-s,a-s).lineTo(l-s,o+s).moveTo(l-s,a-s).lineTo(n+s,a-s)}),t.strokePath({lineWidth:s,color:this.pushed?m.BLACK:m.BUTTON_LIGHTEST,path:new _(n,o).lineTo(l-s,o).moveTo(n,o).lineTo(n,a-s)}),t.strokePath({lineWidth:s,color:this.pushed?m.BUTTON_DARKER:this.backgroundColor,path:new _(n+s,o+s).lineTo(l-s-s,o+s).moveTo(n+s,o+s).lineTo(n+s,a-s-s)}),e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString();let h=this.text.split(`
16
+ `).map(g=>this.truncateWithEllipsis(e,g,this.width)),p,d;if(this.imageElement&&this.imageLoaded){let g=e.measureText(h[0]).width,x=this.font.height,w=this.imageElement.naturalHeight*i,v=this.imageElement.naturalWidth*i,S=(this.height-w)/x,A=(this.width-v)/g,C=5*i;if(A>S){e.textBaseline="middle",e.textAlign="left",p=this.x+(this.width-g)/2+C,d=this.y+this.height/2;let V=this.x+(this.width-g)/2-v,D=this.y+(this.height-w)/2;e.drawImage(this.imageElement,V,D,v,w)}else{e.textAlign="center",e.textBaseline="top";let V=x+w;p=this.x+this.width/2,d=this.y+(this.height-V)/2+w;let D=this.x+(this.width-v)/2,N=this.y+(this.height-V)/2;e.drawImage(this.imageElement,D,N,v,w)}this.pushed&&(p+=1*i,d+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(h[0],p,d)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(h[0],p+1*i,d+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(h[0],p,d))}else{e.textAlign="start",e.textBaseline="top";let g=0;for(let v of h){let S=e.measureText(v).width;g=Math.max(g,S)}p=this.x+(this.width-g)/2;let x=t.measureText("Mg",this.font).height,w=h.length*x;d=this.y+(this.height-w)/2;for(let v of h){let S=p,A=d;this.pushed&&(S+=1*i,A+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(v,S,A)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(v,S+1*i,A+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(v,S,A)),d+=x}}}getHookedActions(){let{actions:t}=this;if(t.hookAllActionsToClick)return t.actions;if(this.pushed){let e=this.releaseActionIndex;return[t.getAction(e)]}else{let e=this.pushActionIndex;return[t.getAction(e)]}}get font(){return this.properties.getValue(pa).scale(this.scale)}get image(){return this.properties.getValue(ma)}get toggleButton(){return this.properties.getValue(ga)}get pushActionIndex(){return this.properties.getValue(da)}get releaseActionIndex(){return this.properties.getValue(ua)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}};var fa="bit",wa="data_type",xa="effect_3d",ya="font",Pa="off_color",ba="off_label",va="off_state",Ra="on_color",_a="on_label",Ta="on_state",Sa="password",La="push_action_index",Ca="released_action_index",Aa="show_confirm_dialog",Oa="confirm_message",Ea="show_led",Ma="show_boolean_label",Va="square_button",Ia="toggle_button",Ox="scale_options",pr=class extends M{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(fa)),this.properties.add(new P(wa)),this.properties.add(new f(Va)),this.properties.add(new f(Ea)),this.properties.add(new f(xa)),this.properties.add(new L(Ra)),this.properties.add(new T(_a)),this.properties.add(new T(Ta)),this.properties.add(new L(Pa)),this.properties.add(new T(ba)),this.properties.add(new T(va)),this.properties.add(new H(ya)),this.properties.add(new f(Ia)),this.properties.add(new P(La)),this.properties.add(new P(Ca)),this.properties.add(new P(Aa,0)),this.properties.add(new T(Sa,"")),this.properties.add(new T(Oa,"Are you sure you want to do this?")),this.properties.add(new f(Ma)),this.properties.add(new tt(Ox,new J(!0,!0,!0)))}init(){let t=this;this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{if(this.enabled){if(this.toggleButton){let e=!this.booleanValue,i;switch(this.showConfirmDialog){case 1:i=!0;break;case 2:i=e;break;case 3:i=!e;break;default:i=!1}this.confirmThen(i,()=>e?this.toggleOn():this.toggleOff())}else{let e=this.showConfirmDialog!==0;this.confirmThen(e,()=>{this.toggleOn(),e&&setTimeout(()=>{this.toggleOff(),this.requestRepaint()},100)})}this.requestRepaint()}},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.enabled&&this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.enabled&&this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,get cursor(){return t.enabled?"pointer":"default"}}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?Ut(t,"Password Input Dialog","Please input the password",this.password):nt(t,"Confirm Dialog",this.confirmMessage)}confirmThen(t,e){if(!t){e();return}this.display.runSequenced(()=>this.openConfirmDialog().then(i=>{i&&(e(),this.requestRepaint())}))}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}draw(t){let e=this.booleanValue;if(this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel){let i=e?this.onLabel:this.offLabel;this.enabled?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}):(t.fillText({x:this.x+this.width/2+this.scale,y:this.y+this.height/2+this.scale,font:this.font,color:m.BUTTON_LIGHTEST,align:"center",baseline:"middle",text:i}),t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:m.BUTTON_DARKER,align:"center",baseline:"middle",text:i}))}}drawSquare(t,e){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:m.DARK_GRAY}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let r=2*this.scale,s=e?m.DARK_GRAY:m.WHITE,o=e?m.WHITE:m.DARK_GRAY;this.effect3d&&(t.fillPath({color:s,path:new _(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+r,this.y+this.height-r).lineTo(this.x+r,this.y+r).lineTo(this.x+this.width-r,this.y+r).lineTo(this.x+this.width,this.y).closePath()}),t.fillPath({color:o,path:new _(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-r,this.y+r).lineTo(this.x+this.width-r,this.y+this.height-r).lineTo(this.x+r,this.y+this.height-r).closePath()}));let n=this.backgroundColor;this.hovered&&this.enabled&&(n=this.backgroundColor.mixWith(m.WHITE,.5)),t.fillRect({x:this.x+r,y:this.y+r,width:this.width-r-r,height:this.height-r-r,color:n})}drawEllipse(t,e){let{scale:i}=this;if(this.effect3d){let l=this.width/2,h=this.height/2,p=Math.sqrt(l*l+h*h),d=this.x+l+(h-l-p)/2-1*i,g=this.y+h-(h-l+p)/2-1*i,x=this.x+l+(h-l+p)/2+5*i,w=this.y+h-(h-l-p)/2+5*i,v=t.createLinearGradient(d,g,x,w);e?(v.addColorStop(0,m.DARK_GRAY.toString()),v.addColorStop(1,m.WHITE.toString())):(v.addColorStop(0,m.WHITE.toString()),v.addColorStop(1,m.DARK_GRAY.toString())),t.ctx.fillStyle=v}else e?t.ctx.fillStyle=m.WHITE.toString():t.ctx.fillStyle=m.DARK_GRAY.toString();let r=this.x+this.width/2,s=this.y+this.height/2,o=this.width/2,n=this.height/2;t.ctx.beginPath(),t.ctx.ellipse(r,s,o,n,0,0,2*Math.PI),t.ctx.fill(),t.addHitRegion(this.areaRegion).addEllipse(r,s,o,n,0,0,2*Math.PI),this.hovered&&this.enabled?t.ctx.fillStyle=this.backgroundColor.mixWith(m.WHITE,.5).toString():t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,s,o-i*2,n-i*2,0,0,2*Math.PI),t.ctx.fill()}drawHorizontal(t,e){let{scale:i}=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*i)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*i));let s={x:Math.floor(this.x+this.width*.79999-r/2),y:Math.floor(this.y+this.height/2-r/2),width:r,height:r},o=s.x+s.width/2,n=s.y+s.height/2,a=s.width/2,l=s.height/2,h=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:a,ry:l,color:h}),this.effect3d){let p=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);p.addColorStop(0,"white"),p.addColorStop(1,h.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,a,l,0,0,2*Math.PI),t.ctx.fillStyle=p,t.ctx.fill()}}}drawVertical(t,e){let{scale:i}=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*i)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*i));let s={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},o=e?this.onColor:this.offColor,n=s.x+s.width/2,a=s.y+s.height/2,l=s.width/2,h=s.height/2;if(t.fillEllipse({cx:n,cy:a,rx:l,ry:h,color:o}),this.effect3d){let p=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);p.addColorStop(0,m.WHITE.toString()),p.addColorStop(1,o.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(n,a,l,h,0,0,2*Math.PI),t.ctx.fillStyle=p,t.ctx.fill()}}}get bit(){return this.properties.getValue(fa)}get dataType(){return this.properties.getValue(wa)}get toggleButton(){return this.properties.getValue(Ia)}get pushActionIndex(){return this.properties.getValue(La)}get releaseActionIndex(){return this.properties.getValue(Ca)}get showConfirmDialog(){return this.properties.getValue(Aa)}get password(){return this.properties.getValue(Sa)}get confirmMessage(){return this.properties.getValue(Oa)}get squareButton(){return this.properties.getValue(Va)}get showLed(){return this.properties.getValue(Ea)}get showBooleanLabel(){return this.properties.getValue(Ma)}get effect3d(){return this.properties.getValue(xa)}get onColor(){return this.properties.getValue(Ra)}get onLabel(){return this.properties.getValue(_a)}get onState(){return this.properties.getValue(Ta)}get offColor(){return this.properties.getValue(Pa)}get offLabel(){return this.properties.getValue(ba)}get offState(){return this.properties.getValue(va)}get font(){return this.properties.getValue(ya).scale(this.scale)}};var Ba="bit",Ha="data_type",Da="effect_3d",Wa="off_color",ka="off_label",Na="off_state",Fa="on_color",Ga="on_label",$a="on_state",Ua="password",Ya="push_action_index",za="released_action_index",Xa="show_confirm_dialog",qa="confirm_message",Ka="toggle_button",dr=class extends M{manualToggleState=!1;shaftRegion;constructor(t,e){super(t,e),this.properties.add(new P(Ba)),this.properties.add(new P(Ha)),this.properties.add(new f(Da)),this.properties.add(new L(Fa)),this.properties.add(new T(Ga)),this.properties.add(new T($a)),this.properties.add(new L(Wa)),this.properties.add(new T(ka)),this.properties.add(new T(Na)),this.properties.add(new P(Ya)),this.properties.add(new P(za)),this.properties.add(new P(Xa,0)),this.properties.add(new T(Ua,"")),this.properties.add(new T(qa,"Are you sure you want to do this?")),this.properties.add(new f(Ka))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{if(this.toggleButton){let t=!this.booleanValue,e;switch(this.showConfirmDialog){case 1:e=!0;break;case 2:e=t;break;case 3:e=!t;break;default:e=!1}this.confirmThen(e,()=>t?this.toggleOn():this.toggleOff())}else{let t=this.showConfirmDialog!==0;this.confirmThen(t,()=>{this.toggleOn(),t&&setTimeout(()=>{this.toggleOff(),this.requestRepaint()},100)})}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"}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?Ut(t,"Password Input Dialog","Please input the password",this.password):nt(t,"Confirm Dialog",this.confirmMessage)}confirmThen(t,e){if(!t){e();return}this.display.runSequenced(()=>this.openConfirmDialog().then(i=>{i&&(e(),this.requestRepaint())}))}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}draw(t){let e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,r=this.height;r>i/2?r=Math.floor(this.width/2):i=Math.floor(2*this.height);let s={x:Math.floor(63/218*i),y:0,width:r/2,height:r/2};this.drawPedestal(t,s,e);let o=Math.floor(35/218*i),n=Math.floor(45/105*r),a=Math.floor(43/218*i),l=Math.floor(35/105*r),h=Math.floor(1/7*s.width);if(e){let p={x:2*s.x+s.width-o,y:s.height/2-n/2,width:o,height:n},d={x:s.x+s.width/2-a/2+h,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,d,p,!0)}else{let p={x:0,y:s.height/2-n/2,width:o,height:n},d={x:s.x+s.width/2-a/2-h,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,d,p,!1)}}drawVertical(t,e){let i=this.width,r=this.height;i>r/2?i=Math.floor(this.height/2):r=Math.floor(2*this.width);let s={x:0,y:Math.floor(63/218*r),width:i/2,height:i/2};this.drawPedestal(t,s,e);let o=Math.floor(45/105*i),n=Math.floor(35/218*r),a=Math.floor(35/105*i),l=Math.floor(43/218*r);if(e){let h={x:s.width/2-o/2,y:0,width:o,height:n},p={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};p.y-=Math.floor(1/7*s.height),this.drawVerticalBar(t,p,h,!0)}else{let h=s.y+s.height/2+l/2+2*this.scale,p={x:s.width/2-o/2,y:s.y+s.height/2-l/2+h-n,width:o,height:n},d={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};d.y+=Math.floor(1/7*s.height),this.drawVerticalBar(t,d,p,!1)}}drawPedestal(t,e,i){let r=this.x+e.x+e.width/2,s=this.y+e.y+e.height/2,o=e.width/2,n=e.height/2;if(t.ctx.fillStyle=this.effect3d?m.WHITE.toString():m.GRAY.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,s,o,n,0,0,2*Math.PI),t.ctx.fill(),this.effect3d){let a=t.createLinearGradient(this.x+e.x,this.y+e.y,this.x+e.x+e.width,this.y+e.y+e.height);i?(a.addColorStop(0,`rgba(255,255,255,${10/255})`),a.addColorStop(1,`rgba(0,0,0,${100/255})`)):(a.addColorStop(0,"rgba(0,0,0,0)"),a.addColorStop(1,`rgba(0,0,0,${150/255})`)),t.ctx.fillStyle=a,t.ctx.fill()}}drawHorizontalBar(t,e,i,r){let s=(r?0:10)/255,o=(r?150:220)/255,n=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);n.addColorStop(0,`rgba(0,0,0,${s})`),n.addColorStop(1,`rgba(0,0,0,${o})`);let a=t.addHitRegion(this.shaftRegion),l=this.x+e.x+e.width/2,h=this.y+e.y+e.height/2,p=e.width/2,d=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(l,h,p,d,0,0,2*Math.PI),a.addEllipse(l,h,p,d,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill());let g=[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(g[0],g[1]),t.ctx.lineTo(g[2],g[3]),t.ctx.lineTo(g[4],g[5]),t.ctx.lineTo(g[6],g[7]),t.ctx.closePath(),a.addPath(new _(g[0],g[1]).lineTo(g[2],g[3]).lineTo(g[4],g[5]).lineTo(g[6],g[7]).closePath()),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill()),l=this.x+i.x+i.width/2,h=this.y+i.y+i.height/2,p=i.width/2,d=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(l,h,p,d,0,0,2*Math.PI),a.addEllipse(l,h,p,d,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let{scale:x}=this,w=Math.sqrt(p*p+d*d),v=d-p,S=this.x+i.x+p+(v-w)/2-1*x,A=this.x+i.y+d-(v+w)/2-1*x,C=this.x+i.x+p+(v+w)/2+5*x,V=this.x+i.y+d-(v-w)/2+5*x,D=t.createLinearGradient(S,A,C,V);D.addColorStop(0,`rgba(0,0,0,${s})`),D.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=D,t.ctx.fill()}}drawVerticalBar(t,e,i,r){let s=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);s.addColorStop(0,`rgba(0,0,0,${10/255})`),s.addColorStop(1,`rgba(0,0,0,${r?210/255:160/255})`);let o=t.addHitRegion(this.shaftRegion),n=this.x+e.x+e.width/2,a=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(n,a,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(n,a,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=s,t.ctx.fill());let l=[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(l[0],l[1]),t.ctx.lineTo(l[2],l[3]),t.ctx.lineTo(l[4],l[5]),t.ctx.lineTo(l[6],l[7]),t.ctx.closePath(),o.addPath(new _(l[0],l[1]).lineTo(l[2],l[3]).lineTo(l[4],l[5]).lineTo(l[6],l[7]).closePath()),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=s,t.ctx.fill()),n=this.x+i.x+i.width/2,a=this.y+i.y+i.height/2;let h=i.width/2,p=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,a,h,p,0,0,2*Math.PI),o.addEllipse(n,a,h,p,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let d=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);d.addColorStop(0,`rgba(0,0,0,${(r?5:10)/255})`),d.addColorStop(1,`rgba(0,0,0,${(r?180:160)/255})`),t.ctx.fillStyle=d,t.ctx.fill()}}get bit(){return this.properties.getValue(Ba)}get dataType(){return this.properties.getValue(Ha)}get toggleButton(){return this.properties.getValue(Ka)}get pushActionIndex(){return this.properties.getValue(Ya)}get releaseActionIndex(){return this.properties.getValue(za)}get showConfirmDialog(){return this.properties.getValue(Xa)}get password(){return this.properties.getValue(Ua)}get confirmMessage(){return this.properties.getValue(qa)}get effect3d(){return this.properties.getValue(Da)}get onColor(){return this.properties.getValue(Fa)}get onLabel(){return this.properties.getValue(Ga)}get onState(){return this.properties.getValue($a)}get offColor(){return this.properties.getValue(Wa)}get offLabel(){return this.properties.getValue(ka)}get offState(){return this.properties.getValue(Na)}};var ja="auto_size",Za="bit",Ja="enabled",Ns="font",Qa="label",tl="selected_color",Ex="scale_options",el=16,Mx=new m(130,130,130),Vx=new m(94,151,230),il=4,ur=class extends M{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new f(ja)),this.properties.add(new P(Za)),this.properties.add(new f(Ja)),this.properties.add(new H(Ns)),this.properties.add(new T(Qa)),this.properties.add(new L(tl,new m(64,64,64))),this.properties.add(new tt(Ex,new J(!0,!1,!1)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.enabled&&(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{let 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{let t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){return this.pv&&this.value!==void 0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.manualToggleState}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(Ns).scale(1),i=t.measureText(this.label,e,!0);this.customSize={width:i.width+el+il,height:i.height}}super.drawHolder(t)}draw(t){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let i=this.booleanValue,{boxSize:r,gap:s,scale:o}=this,n=this.backgroundColor;this.hovered&&(n=n.mixWith(Vx,.7));let a={x:this.x,y:this.y+this.height/2-r/2,width:r,height:r},l=t.createLinearGradient(a.x,a.y+1*o,a.x,a.y+a.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,n.toString()),t.fillRect({...a,rx:2*o,ry:2*o,gradient:l}),t.strokeRect({x:a.x+.5*o,y:a.y+.5*o,width:a.width-1*o,height:a.height-1*o,rx:2*o,ry:2*o,color:Mx}),i&&t.strokePath({lineWidth:3*o,color:this.selectedColor,path:new _(a.x+3*o,a.y+Math.floor(r*.45)).lineTo(a.x+Math.floor(r*.45),a.y+r*3/4-1*o).lineTo(a.x+r-2*o,a.y+3*o)}),this.enabled?t.fillText({x:a.x+a.width+s,y:a.y+a.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(t.fillText({x:a.x+a.width+s+1*o,y:a.y+a.height/2+1*o,align:"left",baseline:"middle",color:m.BUTTON_LIGHTEST,font:this.font,text:this.label}),t.fillText({x:a.x+a.width+s,y:a.y+a.height/2,align:"left",baseline:"middle",color:m.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return this.scale*el}get gap(){return this.scale*il}get autoSize(){return this.properties.getValue(ja)}get bit(){return this.properties.getValue(Za)}get enabled(){return this.properties.getValue(Ja)}get selectedColor(){return this.properties.getValue(tl)}get font(){return this.properties.getValue(Ns).scale(this.scale)}get label(){return this.properties.getValue(Qa)}};var rl="enabled",sl="font",ol="horizontal",nl="items",al="items_from_pv",ll="selected_color",gr=class extends M{pushedItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new f(rl)),this.properties.add(new H(sl)),this.properties.add(new f(ol)),this.properties.add(new Nt(nl,[])),this.properties.add(new f(al)),this.properties.add(new L(ll))}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){let e=this.area.width/this.items.length,i=this.area.x;for(let r=0;r<this.items.length;r++){let s={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,s,r)}}drawVertical(t){let e=this.area.height/this.items.length,i=this.area.y;for(let r=0;r<this.items.length;r++){let s={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,s,r)}}drawButton(t,e,i){let r=this.value===this.items[i],s=r||i===this.pushedItem;t.fillRect({...e,color:r?this.selectedColor:this.backgroundColor}),t.addHitRegion(this.itemRegions[i]).addRect(e.x,e.y,e.width,e.height);let n=1*this.scale,a=e.y+n/2,l=e.x+n/2,h=e.y+e.height-n+n/2,p=e.x+e.width-n+n/2;t.strokePath({lineWidth:n,color:s?m.BUTTON_LIGHTEST:m.BLACK,path:new _(p,h).lineTo(p,a).moveTo(p,h).lineTo(l,h)}),t.strokePath({lineWidth:n,color:s?this.backgroundColor:m.BUTTON_DARKER,path:new _(p-n,h-n).lineTo(p-n,a+n).moveTo(p-n,h-n).lineTo(l+n,h-n)}),t.strokePath({lineWidth:n,color:s?m.BLACK:m.BUTTON_LIGHTEST,path:new _(l,a).lineTo(p-n,a).moveTo(l,a).lineTo(l,h-n)}),t.strokePath({lineWidth:n,color:s?m.BUTTON_DARKER:this.backgroundColor,path:new _(l+n,a+n).lineTo(p-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)}),t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:this.items[i],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(rl)}get font(){return this.properties.getValue(sl).scale(this.scale)}get horizontal(){return this.properties.getValue(ol)}get items(){return this.properties.getValue(nl)}get itemsFromPV(){return this.properties.getValue(al)}get selectedColor(){return this.properties.getValue(ll)}};var hl="enabled",cl="font",pl="items",dl="items_from_pv",Ix=8,Bx=new m(0,0,0,.1),mr=class extends M{areaRegion;selectEl;renderedItems;constructor(t,e){super(t,e),this.properties.add(new f(hl)),this.properties.add(new H(cl)),this.properties.add(new Nt(pl,[])),this.properties.add(new f(dl))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",()=>{this.writeValue(this.selectEl?.value??""),this.requestRepaint()}),this.display.rootPanel.appendChild(this.selectEl)}draw(t){let e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`,this.updateSelectOptions(),e=W(this.bounds,2*this.scale),t.fillRect({...e,color:this.backgroundColor}),t.strokeRect({...e,color:Bx,crispen:!0}),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height);let r=this.value;if(r){let a=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let l of a){let h=l===r;if(!h)try{h=parseFloat(l)===r}catch{}h&&t.fillText({x:5*this.scale+e.x,y:e.y+e.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:r})}}let{selectorWidth:s}=this,o=Math.min(e.height,s/2),n={x:e.x+e.width-s-5*this.scale+s/2,y:e.y+(e.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new _(n.x,n.y).lineTo(n.x-o,n.y-o).lineTo(n.x+o,n.y-o).closePath()})}writeValue(t){this.pv?this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t):this.value=t}hide(){this.selectEl&&(this.selectEl.style.display="none")}updateSelectOptions(){let t=this.itemsFromPV?this.pv?.labels??[]:this.items,e=!1;if(this.renderedItems===void 0)e=!0;else if(t.length!==this.renderedItems.length)e=!0;else for(let i=0;i<t.length;i++)if(t[i]!==this.renderedItems[i]){e=!0;break}if(e){let i=this.selectEl;for(;i.firstChild;)i.removeChild(i.lastChild);let r=document.createElement("option");r.disabled=!0,r.value="",r.defaultSelected=!0,r.text=" -- select an option -- ",i.add(r);let s=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let o=0;o<s.length;o++){let n=document.createElement("option");n.value=s[o],n.text=s[o],i.add(n)}this.renderedItems=s}}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get selectorWidth(){return this.scale*Ix}get enabled(){return this.properties.getValue(hl)}get font(){return this.properties.getValue(cl).scale(this.scale)}get items(){return this.properties.getValue(pl)}get itemsFromPV(){return this.properties.getValue(dl)}};var ul="auto_size",gl="bit",ml="data_type",fl="effect_3d",wl="font",Hx="height",xl="off_image",yl="off_label",Pl="off_state",bl="on_image",vl="on_label",Rl="on_state",_l="password",Tl="push_action_index",Sl="released_action_index",Ll="show_confirm_dialog",Cl="confirm_message",Al="show_boolean_label",Ol="stretch_to_fit",El="toggle_button",Ml="transparency",Dx="width",fr=class extends M{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new f(ul,!0)),this.properties.add(new P(gl)),this.properties.add(new P(ml)),this.properties.add(new f(fl)),this.properties.add(new T(bl)),this.properties.add(new T(vl)),this.properties.add(new T(Rl)),this.properties.add(new T(xl)),this.properties.add(new T(yl)),this.properties.add(new T(Pl)),this.properties.add(new H(wl)),this.properties.add(new f(El)),this.properties.add(new P(Tl)),this.properties.add(new P(Sl)),this.properties.add(new P(Ll,0)),this.properties.add(new T(_l,"")),this.properties.add(new T(Cl,"Are you sure you want to do this?")),this.properties.add(new f(Al)),this.properties.add(new f(Ol,!1)),this.properties.add(new f(Ml,!1))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.onImage){let t=this.onImageElement;this.display.getImageLoader().load(this.resolvePath(this.onImage)).then(e=>{t.src=e})}if(this.offImage){let t=this.offImageElement;this.display.getImageLoader().load(this.resolvePath(this.offImage)).then(e=>{t.src=e})}this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{if(this.toggleButton){let t=!this.booleanValue,e;switch(this.showConfirmDialog){case 1:e=!0;break;case 2:e=t;break;case 3:e=!t;break;default:e=!1}this.confirmThen(e,()=>t?this.toggleOn():this.toggleOff())}else{let t=this.showConfirmDialog!==0;this.confirmThen(t,()=>{this.toggleOn(),t&&setTimeout(()=>{this.toggleOff(),this.requestRepaint()},100)})}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"}}openConfirmDialog(){let t=this.display.getDialogHandler();return this.password?Ut(t,"Password Input Dialog","Please input the password",this.password):nt(t,"Confirm Dialog",this.confirmMessage)}confirmThen(t,e){if(!t){e();return}this.display.runSequenced(()=>this.openConfirmDialog().then(i=>{i&&(e(),this.requestRepaint())}))}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{let 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.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.dataType===0)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{let 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);this.releaseActionIndex!==void 0&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){return this.pv&&this.value!==void 0?this.dataType===0?this.bit<0?!!this.value:(this.value>>this.bit&1)>0:this.dataType===1?String(this.value)===this.onState:!1:this.manualToggleState}applyAutoSize(){if(!this.autoSize||this.stretchToFit)return;let t=this.booleanValue?this.onImageElement:this.offImageElement,e=this.booleanValue?this.onImageLoaded:this.offImageLoaded;t&&e&&(this.properties.setValue(Dx,t.naturalWidth),this.properties.setValue(Hx,t.naturalHeight))}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=W(e,2*this.scale,2*this.scale));let i=this.booleanValue,r=i?this.onImageElement:this.offImageElement,s=i?this.onImageLoaded:this.offImageLoaded,o=this.stretchToFit?e.width:r?.naturalWidth,n=this.stretchToFit?e.height:r?.naturalHeight;s&&(this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(e.x,e.y,o,n)),t.ctx.drawImage(r,e.x,e.y,o,n)),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 autoSize(){return this.properties.getValue(ul)}get stretchToFit(){return this.properties.getValue(Ol)}get transparency(){return this.properties.getValue(Ml)}get bit(){return this.properties.getValue(gl)}get dataType(){return this.properties.getValue(ml)}get toggleButton(){return this.properties.getValue(El)}get pushActionIndex(){return this.properties.getValue(Tl)}get releaseActionIndex(){return this.properties.getValue(Sl)}get showConfirmDialog(){return this.properties.getValue(Ll)}get password(){return this.properties.getValue(_l)}get confirmMessage(){return this.properties.getValue(Cl)}get showBooleanLabel(){return this.properties.getValue(Al)}get effect3d(){return this.properties.getValue(fl)}get onImage(){return this.properties.getValue(bl)}get onLabel(){return this.properties.getValue(vl)}get onState(){return this.properties.getValue(Rl)}get offImage(){return this.properties.getValue(xl)}get offLabel(){return this.properties.getValue(yl)}get offState(){return this.properties.getValue(Pl)}get font(){return this.properties.getValue(wl).scale(this.scale)}};function Jt(c,t){let e=Math.max(Math.abs(c),Math.abs(t)),i=Math.abs(t/e-c/e);if(i>.1/e)return"############.##";let r="##.##";for(;i<1/e;)i*=10,r+="#";return r}var rt=class{prefix="";suffix="";comma=0;minInt=1;minFrac=0;maxFrac=0;constructor(t){for(let a=0;a<t.length;a++)if(t.charAt(a)=="#"||t.charAt(a)=="0"){this.prefix=t.substring(0,a),t=t.substring(a);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");let e=t.replace(/[^0#,.]/g,""),i="",r="",s=e.indexOf(".");s!==-1?(i=e.substring(0,s),r=e.substring(s+1)):i=e;let o=i.lastIndexOf(",");o!==-1&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),r=r.replace(/[,]|[.]+/g,""),this.maxFrac=r.length;let n=i.replace(/[^0]/g,"");n.length>this.minInt&&(this.minInt=n.length),n=r.replace(/[^0]/g,""),this.minFrac=n.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||e.length==0)return t;if(e.indexOf("e")!=-1){let g=Number(e);if(g===1/0||g===-1/0||(e=g+"",e.indexOf("e")!==-1))return e}let i=!1;e.charAt(0)==="-"?(i=!0,e=e.substring(1)):e.charAt(0)==="+"&&(e=e.substring(1));let r=e.indexOf("."),s="",o="";r!=-1?(s=e.substring(0,r),o=e.substring(r+1)):s=e,o=o.replace(/[.]/,"");let n=this.suffix&&this.suffix.charAt(0)==="%",a=this.minInt,l=this.minFrac,h=this.maxFrac;if(n&&(a-=2,l+=2,h+=2),o.length>h){let g=+("0."+o);g=h==0?Math.round(g):g.toFixed(h),o=g.toString(10).substr(2);let x=g>=1?1:0,w,v=s.length-1;for(;x;)if(v==-1){s="1"+s;break}else w=Number(s.charAt(v)),w===9?(w="0",x=1):(w=++w+"",x=0),s=s.substring(0,v)+w+s.substring(v+1,s.length),v--}for(let g=o.length;g<l;g++)o=o+"0";for(;o.length>l&&o.charAt(o.length-1)=="0";)o=o.substring(0,o.length-1);for(let g=s.length;g<a;g++)s="0"+s;for(;s.length>a&&s.charAt(0)=="0";)s=s.substring(1);n&&(s+=o.substring(0,2),o=o.substring(2));let p=0;for(let g=s.length;g>0;g--)p!=0&&p%this.comma==0&&(s=s.substring(0,g)+","+s.substring(g),p=0),p++;let d;return o.length>0?d=this.prefix+s+"."+o+this.suffix:d=this.prefix+s+this.suffix,i&&(d="-"+d),d}formatBack(t){if(t+="",!t)return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;t.charAt(0)==="-"&&(e=e.substr(1),i=!0);let r=e.indexOf(this.prefix),s=this.suffix==""?e.length:e.indexOf(this.suffix,this.prefix.length+1);return r==0&&s>0&&(e=e.substr(0,s),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){let i=Number(t)+"";if(t.indexOf(".")>-1&&i.indexOf(".")<0){for(var r=t.indexOf(".")+1;r<t.length;r++)if(t.charAt(r)!=="0")return t;return i}return t}};var Wx=1,kx=8,Q=2,Qt=class{constructor(t,e,i){this.rampWidth=t;this.startAngle=e;this.endAngle=i}lolo=10;loloColor=m.RED;showLoLo=!0;lo=25;loColor=m.ORANGE;showLo=!0;hi=75;hiColor=m.ORANGE;showHi=!0;hihi=90;hihiColor=m.RED;showHiHi=!0;minimum=0;maximum=100;gradient=!0;logScale=!1;effect3d=!0;labelsOutside=!0;range={min:this.minimum,max:this.maximum};lengthInDegrees=0;radius=0;draw(t,e,i,r=!0){if(this.labelsOutside){let s=Wx+kx;this.radius=e.width/2-s}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,r&&this.drawRamp(t,i)}drawRamp(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2,n,a=360-this.endAngle;if(this.endAngle-this.startAngle>0?n=this.startAngle-90:n=this.startAngle+90,this.showLoLo){let x=n,w=360-this.getValuePosition(this.lolo,!0);t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(x),endAngle:G(w),color:this.loloColor})}if(this.showLo){let x;this.showLoLo?x=this.lolo:x=this.minimum;let w=360-this.getValuePosition(x,!0),v=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){let S=G(this.getValuePosition(x,!0)-Q),A=xt(e.width/2,S,e),C=G(this.getValuePosition(this.lo,!0)+Q),V=xt(e.width/2,C,e),D=t.createLinearGradient(A.x,A.y,V.x,V.y);D.addColorStop(0,this.loloColor.toString()),D.addColorStop(1,this.loColor.toString()),t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(w-Q/2),endAngle:G(v+Q/2),gradient:D})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(w-Q/2),endAngle:G(v+Q/2),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let h=this.maximum;this.showHi?h=this.hi:this.showHiHi&&(h=this.hihi);let p=(l+h)/2,d=360-this.getValuePosition(l,!0),g=360-this.getValuePosition(p,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){let x=G(this.getValuePosition(l,!0)-Q),w=xt(e.width/2,x,e),v=G(this.getValuePosition(p,!0)+Q),S=xt(e.width/2,v,e),A=t.createLinearGradient(w.x,w.y,S.x,S.y);A.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),A.addColorStop(1,m.GREEN.toString()),t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+Q/2),gradient:A})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+Q/2),color:m.GREEN});if(d=360-this.getValuePosition(p,!0),g=360-this.getValuePosition(h,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){let x=G(this.getValuePosition(p,!0)-Q),w=xt(e.width/2,x,e),v=G(this.getValuePosition(h,!0)+Q),S=xt(e.width/2,v,e),A=t.createLinearGradient(w.x,w.y,S.x,S.y);A.addColorStop(0,m.GREEN.toString()),A.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());let C=g!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+C),gradient:A})}else{let x=g!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-Q/2),endAngle:G(g+x),color:m.GREEN})}if(this.showHi){let x;this.showHiHi?x=this.hihi:x=this.maximum;let w=360-this.getValuePosition(this.hi,!0),v=360-this.getValuePosition(x,!0);if(this.effect3d&&this.gradient&&this.showHiHi){let S=G(this.getValuePosition(this.hi,!0)-Q),A=xt(e.width/2,S,e),C=G(this.getValuePosition(x,!0)+Q),V=xt(e.width/2,C,e),D=t.createLinearGradient(A.x,A.y,V.x,V.y);D.addColorStop(0,this.hiColor.toString()),D.addColorStop(1,this.hihiColor.toString());let N=v!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(w-Q/2),endAngle:G(v+N),gradient:D})}else{let S=v!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(w-Q/2),endAngle:G(v+S),color:this.hiColor})}}if(this.showHiHi){d=360-this.getValuePosition(this.hihi,!0),g=a;let x=Q/2;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:G(d-x),endAngle:G(g),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){e&&(t=this.getValueInRange(t));let i;return this.logScale?i=this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:i=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(){let 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}};var Vl=1,Nx=8,Fx=5,Gx=2,$x=1,Ux=6,te=class{constructor(t,e,i){this.startAngle=t;this.endAngle=e;this.direction=i}minimum=0;maximum=100;logScale=!1;showMinorTicks=!0;visible=!0;majorTickStepHint=50;majorTickLength=Nx;minorTickLength=Fx;majorLineWidth=Gx;minorLineWidth=$x;format="";font=X.ARIAL_9;foregroundColor=m.BLACK;radius=0;getRadius(){return this.radius}formatText(t){let e=this.getRenderedRange();return this.formatValue(t,this.getAutoFormatPattern(e))}layoutTicks;layoutGeometry;layout(t,e){let i=this.getRenderedRange(),r=this.getAutoFormatPattern(i);if(this.direction==="outward"){let o=Math.max(t.measureText(this.formatValue(i.min,r),this.font).width,t.measureText(this.formatValue(i.max,r),this.font).width)+Vl+this.majorTickLength,n=e.width/2-o,a=this.computeGeometry(t,e,i,r,n),l=this.getTickLabelMaxOutLength(e,a.ticks);this.radius=n-l}else this.radius=e.width/2-1;let s=this.computeGeometry(t,e,i,r,this.radius);this.layoutTicks=s.ticks,this.layoutGeometry=s}paint(t,e){if(!this.visible||!this.layoutTicks||!this.layoutGeometry)return;let i=this.layoutTicks,{lengthInDegrees:r,lengthInPixels:s,gridStepInRadians:o}=this.layoutGeometry;this.logScale?this.drawLogTickMarks(t,e,this.radius,i):this.drawLinearTickMarks(t,e,this.radius,i,o,r,s),this.drawTickLabels(t,i)}draw(t,e){this.layout(t,e),this.paint(t,e)}computeGeometry(t,e,i,r,s){let o=this.endAngle-this.startAngle>0?360-(this.endAngle-this.startAngle):this.startAngle-this.endAngle,n=Math.max(1,2*Math.PI*s*(o/360)),a,l;if(this.logScale)a=this.computeLogTicks(i,o,r);else{let h=this.getGridStep(n,i.min,i.max);l=G(o)*h/(i.max-i.min),a=this.computeLinearTicks(i,o,h,r)}return this.computeLabelAreas(t,e,s,a),this.computeLabelVisibility(a),{ticks:a,lengthInDegrees:o,lengthInPixels:n,gridStepInRadians:l}}getTickLabelMaxOutLength(t,e){let i=0,r=0,s=0,o=0;for(let n of e){let a=n.labelCenter.x-t.x-n.labelSize.width/2,l=n.labelCenter.y-t.y-n.labelSize.height/2,{width:h,height:p}=n.labelSize;a<i&&(i=a),a+h>r&&(r=a+h),l<s&&(s=l),l+p>o&&(o=l+p)}return Math.max(Math.max(r-t.width,-i),Math.max(o-t.height,-s))}getRenderedRange(){let{minimum:t,maximum:e}=this;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{min:t,max:e}}getAutoFormatPattern(t){if(this.format)return this.format;let{min:e,max:i}=t;if(i!==0&&Math.abs(Math.log10(Math.abs(i)))>=4||e!==0&&Math.abs(Math.log10(Math.abs(e)))>=4)return"scientific";if(Math.abs(i-e)>.1)return"############.##";let r="##.##",s=Math.abs(i-e);for(;s>0&&s<1;)s*=10,r+="#";return r}formatValue(t,e){return e==="scientific"?t.toExponential(4).replace(/e\+?(-?)(\d+)/,"E$1$2").replace(/(\.\d*?)0+E/,"$1E").replace(/\.E/,"E"):new rt(e).format(t)}getGridStep(t,e,i){let r=e,s=i;t<=0&&(t=1);let o=!1;if(r>=s)if(s===r)s++;else{o=!0;let g=r;r=s,s=g}let n=Math.abs(s-r),a=this.majorTickStepHint;a>t&&(a=t);let h=n/t*a,p=0;if(h<1){if(h!==0)for(;h<1;)h*=10,p--}else for(;h>=10;)h/=10,p++;let d;return h>7.5?d=10*Math.pow(10,p):h>3.5?d=5*Math.pow(10,p):h>1.5?d=2*Math.pow(10,p):d=Math.pow(10,p),o&&(d=-d),d}computeLinearTicks(t,e,i,r){let{min:s,max:o}=t,n=o<s,a=[],l;s%i<=0?l=s-s%i:l=s-s%i+i,s>l===n&&a.push(s);for(let p=l;o>=s?p<=o:p>=o;p+=i)a.push(p);let h=a[a.length-1];return(n?o<h:o>h)&&a.push(o),a.map(p=>({value:p,angle:G(this.startAngle-(p-s)/(o-s)*e),text:this.formatValue(p,r),visible:!0}))}computeLogTicks(t,e,i){let{min:r,max:s}=t,o=s<r,n=Math.log10(r),a=Math.ceil(n),l=Math.ceil(Math.log10(s)),h=Math.pow(10,a-1),p,d=r%h;d<=0||o?p=r-d:p=r-d+h;let g=[];(o?r>p:r<p)&&g.push(r);for(let x=a;o?x>=l:x<=l;x+=o?-1:1)if(Math.abs(l-a)>20){let w=Math.pow(10,x);if(w>s)break;g.push(w)}else{for(let w=p;(o?w>=Math.pow(10,x-1):w<=Math.pow(10,x))&&!(o?w<s:w>s);w+=o?-h:h)g.push(w);h=o?h/10:h*10,p=o?Math.pow(10,x-1):h+Math.pow(10,x)}return(g.length===0||s>g[g.length-1])&&g.push(s),g.map(x=>({value:x,angle:G(this.startAngle-(Math.log10(x)-n)/(Math.log10(s)-n)*e),text:this.formatValue(x,i),visible:!0}))}computeLabelAreas(t,e,i,r){for(let s of r){let o=t.measureText(s.text,this.font),n=this.majorTickLength+Vl+o.width/2*Math.abs(Math.cos(s.angle))+o.height/2*Math.abs(Math.sin(s.angle)),a=this.direction==="outward"?i+n:i-n;s.labelCenter=xt(a,s.angle,e),s.labelSize=o}}computeLabelVisibility(t){if(t.length===0)return;let e=o=>({x:o.labelCenter.x-o.labelSize.width/2,y:o.labelCenter.y-o.labelSize.height/2,width:o.labelSize.width,height:o.labelSize.height}),i=(o,n)=>!(o.x+o.width<=n.x||n.x+n.width<=o.x||o.y+o.height<=n.y||n.y+n.height<=o.y),r=e(t[0]),s=null;for(let o=0;o<t.length;o++){let n=!0;if(o!==0){let p=e(t[o]);o!==t.length-1?n=!i(r,p)&&!i(p,e(t[t.length-1])):n=!i(r,p)&&!i(e(t[0]),p)}let a=t[o].text,l=a===s&&o!==0&&o!==t.length-1;s=a;let h=!0;this.logScale&&(h=this.isMajorLogTick(t[o].value)||o===0||o===t.length-1),!n||l||!h?t[o].visible=!1:r=e(t[o])}}isMajorLogTick(t){let e=Math.log10(t);return Math.abs(e-Math.round(e))<1e-9}drawTickLine(t,e,i,r,s,o){let n=xt(i,r,e),a=this.direction==="outward"?i+s:i-s,l=xt(a,r,e);t.strokePath({path:new _(n.x,n.y).lineTo(l.x,l.y),color:this.foregroundColor,lineWidth:o})}drawLinearTickMarks(t,e,i,r,s,o,n){let a=G(o)*Ux/n,l;s/5>=a?l=5:s/4>=a?l=4:l=2;let h=s/l,p=G(o)*2/n;for(let d=0;d<r.length;d++)if(this.drawTickLine(t,e,i,r[d].angle,this.majorTickLength,this.majorLineWidth),this.showMinorTicks&&d>0)if(d===1&&Math.abs(r[0].angle-r[1].angle)<s){let g=r[1].angle;for(;Math.abs(r[0].angle-g)>h+p;)g+=h,this.drawTickLine(t,e,i,g,this.minorTickLength,this.minorLineWidth)}else if(d===r.length-1&&Math.abs(r[d-1].angle-r[d].angle)<s){let g=r[d-1].angle;for(;Math.abs(g-r[d].angle)>h+p;)g-=h,this.drawTickLine(t,e,i,g,this.minorTickLength,this.minorLineWidth)}else for(let g=1;g<l;g++){let x=r[d-1].angle+(r[d].angle-r[d-1].angle)*g/l;this.drawTickLine(t,e,i,x,this.minorTickLength,this.minorLineWidth)}}drawLogTickMarks(t,e,i,r){for(let s of r){let o=s.visible?this.majorTickLength:this.minorTickLength,n=s.visible?this.majorLineWidth:this.minorLineWidth;this.drawTickLine(t,e,i,s.angle,o,n)}}drawTickLabels(t,e){for(let i of e)i.visible&&t.fillText({x:i.labelCenter.x,y:i.labelCenter.y,align:"center",baseline:"middle",font:this.font,color:this.foregroundColor,text:i.text})}};var Yx=2,zx=4,Xx=12,qx=8,Kx=5,jx=100/255,wr=225,Fs=315,ce=270,Il="color_hi",Bl="color_hihi",Hl="color_lo",Dl="color_lolo",Wl="effect_3d",kl="font",Nl="increment",Fl="knob_color",Gl="level_hi",$l="level_hihi",Ul="level_lo",Yl="level_lolo",zl="limits_from_pv",Xl="log_scale",ql="major_tick_step_hint",Kl="maximum",jl="minimum",Zl="ramp_gradient",Gs="scale_font",Jl="scale_format",Ql="show_hi",th="show_hihi",eh="show_lo",ih="show_lolo",rh="show_markers",sh="show_minor_ticks",oh="show_scale",nh="show_value_label",ah="thumb_color",lh="transparent_background",hh="value_label_format",Zx="scale_options",xr=class extends M{thumbRegion;dragValue;dragAngle;scaleLayoutCache;valueLabelFormatCache;constructor(t,e){super(t,e),this.properties.add(new L(Il)),this.properties.add(new L(Bl)),this.properties.add(new L(Hl)),this.properties.add(new L(Dl)),this.properties.add(new f(Wl)),this.properties.add(new H(kl)),this.properties.add(new O(Nl,1)),this.properties.add(new L(Fl)),this.properties.add(new O(Gl)),this.properties.add(new O($l)),this.properties.add(new O(Ul)),this.properties.add(new O(Yl)),this.properties.add(new f(zl,!0)),this.properties.add(new f(Xl)),this.properties.add(new P(ql,50)),this.properties.add(new O(Kl)),this.properties.add(new O(jl)),this.properties.add(new f(Zl)),this.properties.add(new H(Gs)),this.properties.add(new T(Jl)),this.properties.add(new f(Ql,!0)),this.properties.add(new f(th,!0)),this.properties.add(new f(eh,!0)),this.properties.add(new f(ih,!0)),this.properties.add(new f(rh,!0)),this.properties.add(new f(sh,!0)),this.properties.add(new f(oh,!0)),this.properties.add(new f(nh,!0)),this.properties.add(new L(ah)),this.properties.add(new f(lh,!0)),this.properties.add(new T(hh)),this.properties.add(new tt(Zx,new J(!0,!0,!0)))}init(){this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{if(!this.enabled)return;let t=this.computeLimits();this.dragValue=this.value!==void 0?this.getValueInRange(this.value,t):(t.min+t.max)/2,this.dragAngle=this.toRelativeAngle(this.getValuePosition(this.dragValue,t))},grab:t=>{if(!this.enabled||this.dragValue===void 0||this.dragAngle===void 0)return;let e=this.computeLimits(),i=Math.min(this.width,this.height),{x:r,y:s}=this.getAbsoluteCenter(i),o=this.toRelativeAngle(this.pointToAbsoluteAngle(t.point,r,s));if(o>ce){let h=(ce+360)/2;o=o<h?ce:0}let n=o-this.dragAngle,a=this.calcValueChange(n,this.dragValue,e),{increment:l}=this;if(l<=0||Math.abs(a)>l/2){let h=l>0?this.dragValue+l*Math.round(a/l):this.dragValue+a;h=Math.min(e.max,Math.max(e.min,h)),this.setCoercedValue(h,e),this.dragValue=h,this.dragAngle=this.toRelativeAngle(this.getValuePosition(h,e)),this.requestRepaint()}},cursor:"pointer",tooltip:()=>this.tooltip}}draw(t){this.transparentBackground||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});let e=this.computeLimits(),i=Math.min(this.width,this.height),r=W({x:this.x,y:this.y,width:i,height:i},Yx*this.scale),s=this.getLayoutScale(e,t,r);s.visible=this.showScale,s.showMinorTicks=this.showMinorTicks,s.foregroundColor=this.foregroundColor;let o=s.getRadius(),n=r.width/2-o+zx*this.scale,a=W(r,n),l=Xx*this.scale,h=r.width/2-o-l+2*this.scale,p=W(r,h);this.showMarkers&&this.drawRamp(t,r,p,l,e),this.drawBulb(t,a),s.paint(t,r),this.drawValueLabel(t,a,e),this.drawThumb(t,r,a,e),this.enabled||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:m.GRAY,opacity:jx})}computeLimits(){let t;return this.limitsFromPv&&this.pv&&!this.pv.disconnected?t={min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:t={min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(t.min=Math.max(.1,t.min),t.max<=t.min&&(t.max=t.min+100)),t}buildScale(t){let e=new te(wr,Fs,"outward");return e.minimum=t.min,e.maximum=t.max,e.logScale=this.logScale,e.majorTickStepHint=this.majorTickStepHint*this.scale,e.majorTickLength=this.majorTickLength,e.minorTickLength=this.minorTickLength,e.majorLineWidth=2*this.scale,e.minorLineWidth=1*this.scale,e.format=this.scaleFormat,e.font=this.scaleFont,e}getLayoutScale(t,e,i){let r=this.properties.getValue(Gs),s=this.scale,o=this.majorTickStepHint,n=this.scaleFormat,a=this.scaleLayoutCache;if(a!==void 0&&a.min===t.min&&a.max===t.max&&a.logScale===this.logScale&&a.majorTickStepHint===o&&a.format===n&&a.fontRaw===r&&a.widgetScale===s&&a.areaX===i.x&&a.areaY===i.y&&a.areaWidth===i.width&&a.areaHeight===i.height)return a.scale;let h=this.buildScale(t);return h.layout(e,i),this.scaleLayoutCache={scale:h,min:t.min,max:t.max,logScale:this.logScale,majorTickStepHint:o,format:n,fontRaw:r,widgetScale:s,areaX:i.x,areaY:i.y,areaWidth:i.width,areaHeight:i.height},h}drawRamp(t,e,i,r,s){let o=new Qt(r,wr,Fs);o.lolo=s.lolo,o.loloColor=this.colorLoLo,o.showLoLo=this.showLoLo,o.lo=s.lo,o.loColor=this.colorLo,o.showLo=this.showLo,o.hi=s.hi,o.hiColor=this.colorHi,o.showHi=this.showHi,o.hihi=s.hihi,o.hihiColor=this.colorHiHi,o.showHiHi=this.showHiHi,o.minimum=s.min,o.maximum=s.max,o.effect3d=this.effect3d,o.gradient=this.rampGradient,o.logScale=this.logScale,o.draw(t,e,i)}drawBulb(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;if(t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.knobColor}),this.effect3d){let n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.knobColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n})}}drawValueLabel(t,e,i){if(!this.showValueLabel||this.value===void 0)return;let r=X.ARIAL_12_BOLD.scale(this.scale),s=this.formatLabelValue(this.value,i),o=t.measureText(s,r);t.fillText({x:e.x+e.width/2-o.width/2,y:e.y+e.height*3/4-o.height/2,align:"left",baseline:"top",font:r,text:s,color:this.foregroundColor})}drawThumb(t,e,i,r){let s=e.x+e.width/2,o=e.y+e.height/2,n=this.value!==void 0?this.getValueInRange(this.value,r):(r.min+r.max)/2,a=360-this.getValuePosition(n,r),l=G(a),h=i.x+i.width*7/8,p=i.y+i.height/2,d=St(h,p,s,o,l),g=i.width/12;if(t.fillEllipse({cx:d.x,cy:d.y,rx:g,ry:g,color:this.thumbColor}),this.effect3d){let w=t.createLinearGradient(d.x-g,d.y-g,d.x+g,d.y+g);w.addColorStop(0,m.WHITE.toString()),w.addColorStop(1,this.thumbColor.withAlpha(0).toString()),t.fillEllipse({cx:d.x,cy:d.y,rx:g,ry:g,gradient:w})}t.addHitRegion(this.thumbRegion).addEllipse(d.x,d.y,g,g,0,0,2*Math.PI)}getValuePosition(t,e){let i;return this.logScale?i=wr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*ce:i=wr-(t-e.min)/(e.max-e.min)*ce,i<0&&(i+=360),i}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getAbsoluteCenter(t){let e=this.display.measureAbsoluteOffset(this);return{x:this.x+t/2+e.x,y:this.y+t/2+e.y}}pointToAbsoluteAngle(t,e,i){let r=Math.atan2(t.y-i,t.x-e)*180/Math.PI;return r<0&&(r+=360),((360-r)%360+360)%360}toRelativeAngle(t){return((t-Fs)%360+360)%360}calcValueChange(t,e,i){if(this.logScale){let r=ce/(Math.log10(i.max)-Math.log10(i.min));return e*(Math.pow(10,-t/r)-1)}else return-(i.max-i.min)*t/ce}setCoercedValue(t,e){t=t<e.min?e.min:t>e.max?e.max:t,this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,t):this.pv||(this.value=t)}formatLabelValue(t,e){let i=this.valueLabelFormat,r=this.valueLabelFormatCache,s=r!==void 0&&r.formatProp===i&&(i!==""||r.min===e.min&&r.max===e.max),o;if(s)o=r.formatter;else{let n=i||Jt(e.min,e.max);o=new rt(n),this.valueLabelFormatCache={formatProp:i,min:e.min,max:e.max,formatter:o}}return o.format(t)}get majorTickLength(){return this.scale*qx}get minorTickLength(){return this.scale*Kx}get colorLo(){return this.properties.getValue(Hl)}get colorLoLo(){return this.properties.getValue(Dl)}get colorHi(){return this.properties.getValue(Il)}get colorHiHi(){return this.properties.getValue(Bl)}get effect3d(){return this.properties.getValue(Wl)}get font(){return this.properties.getValue(kl).scale(this.scale)}get increment(){return this.properties.getValue(Nl)}get knobColor(){return this.properties.getValue(Fl)}get levelLo(){return this.properties.getValue(Ul)}get levelLoLo(){return this.properties.getValue(Yl)}get levelHi(){return this.properties.getValue(Gl)}get levelHiHi(){return this.properties.getValue($l)}get limitsFromPv(){return this.properties.getValue(zl)}get logScale(){return this.properties.getValue(Xl)}get majorTickStepHint(){return this.properties.getValue(ql)}get maximum(){return this.properties.getValue(Kl)}get minimum(){return this.properties.getValue(jl)}get rampGradient(){return this.properties.getValue(Zl)}get scaleFont(){return this.properties.getValue(Gs).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Jl)}get showHi(){return this.properties.getValue(Ql)}get showHiHi(){return this.properties.getValue(th)}get showLo(){return this.properties.getValue(eh)}get showLoLo(){return this.properties.getValue(ih)}get showMarkers(){return this.properties.getValue(rh)}get showMinorTicks(){return this.properties.getValue(sh)}get showScale(){return this.properties.getValue(oh)}get showValueLabel(){return this.properties.getValue(nh)}get thumbColor(){return this.properties.getValue(ah)}get transparentBackground(){return this.properties.getValue(lh)}get valueLabelFormat(){return this.properties.getValue(hh)}};var ch="font",ph="label",yr=class extends M{areaRegion;selectEl;constructor(t,e){super(t,e),this.properties.add(new H(ch)),this.properties.add(new T(ph))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip,cursor:"pointer"},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",i=>{let r=this.selectEl?.value;if(r){this.selectEl.selectedIndex=0;let s=Number(r.substring(7));this.executeActionByIndex(s)}});let t=document.createElement("option");t.disabled=!0,t.value="",t.defaultSelected=!0,t.text=" -- select an option -- ",this.selectEl.add(t);let e=this.actions.actions;for(let i=0;i<e.length;i++){let r=document.createElement("option");r.value=`action-${i}`,r.text=e[i]?.getDescription()??"",this.selectEl.add(r)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){let e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`;let i=t.ctx;t.fillRect({...this.area,color:this.backgroundColor}),t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let s=this.label.split(`
17
+ `);i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),i.textBaseline="middle",i.textAlign="center";let o=this.x+this.width/2,n=this.y+this.height/2;i.fillText(s[0],o,n)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get font(){return this.properties.getValue(ch).scale(this.scale)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}get label(){return this.properties.getValue(ph)}};var Pr=class extends Ie{};var dh="enabled",uh="font",gh="horizontal",mh="items",fh="items_from_pv",wh="selected_color",Jx=7,Qx=2,ty=4,ey=new m(120,120,120),iy=new m(94,151,230),br=class extends M{hoveredItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new f(dh)),this.properties.add(new H(uh)),this.properties.add(new f(gh)),this.properties.add(new Nt(mh,[])),this.properties.add(new f(fh)),this.properties.add(new L(wh))}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){let e=this.area.width/this.items.length,i=this.area.x;for(let r=0;r<this.items.length;r++){let s={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,s,r)}}drawVertical(t){let e=this.area.height/this.items.length,i=this.area.y;for(let r=0;r<this.items.length;r++){let s={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,s,r)}}drawRadio(t,e,i){let{radioRadius:r,dotRadius:s,gap:o}=this,n=this.backgroundColor;i===this.hoveredItem&&(n=n.mixWith(iy,.7));let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,m.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:r,ry:r,gradient:a});let l=1*this.scale;t.strokeEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:r,ry:r,color:ey,lineWidth:l}),this.value===this.items[i]&&t.fillEllipse({cx:e.x+r,cy:e.y+e.height/2,rx:s+l/2,ry:s+l/2,color:this.selectedColor}),t.addHitRegion(this.itemRegions[i]).addRect(e.x,e.y,e.width,e.height),t.fillText({x:e.x+r+r+o,y:e.y+e.height/2,text:this.items[i],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&!this.pv.writable||(this.value=t,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,t))}get radioRadius(){return this.scale*Jx}get dotRadius(){return this.scale*Qx}get gap(){return this.scale*ty}get enabled(){return this.properties.getValue(dh)}get font(){return this.properties.getValue(uh).scale(this.scale)}get horizontal(){return this.properties.getValue(gh)}get items(){return this.properties.getValue(mh)}get itemsFromPV(){return this.properties.getValue(fh)}get selectedColor(){return this.properties.getValue(wh)}};var ry=["January","February","March","April","May","June","July","August","September","October","November","December"],at=class{constructor(t,e,i,r,s,o,n,a,l,h){this.formatter=t;this.scale=e;this.scaleFont=i;this.minimum=r;this.maximum=s;this.logScale=o;this.majorTickStepHint=n;this.foregroundColor=a;this.showMinorTicks=l;this.showScale=h}labels=[];labelValues=[];labelPositions=[];labelVisibilities=[];gridStepInPixel=0;horizontal=!1;x=0;y=0;scaleFormat="";timeFormat=0;length=0;margin=0;snapToPixels=!1;pixelRatio=1;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(e=>this.length-e)),t.pop(),t.shift(),t}setDimensions(t,e,i,r){this.x=t,this.y=e,this.length=i,this.horizontal=r,this.snapRange(i-2*this.margin)}snapRange(t){let e=this.maximum-this.minimum;if(!this.snapToPixels||this.logScale||t<=0||!(e>0))return;let i=e/(t*this.pixelRatio);this.minimum=Math.ceil(this.minimum/i)*i,this.maximum=this.minimum+e}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),r=0,s=this.length-2*this.margin;if(this.logScale)t<=0?r=this.margin:r=(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*s+this.margin;else{let o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;let n=i-e;r=(t/o-e)/n*s+this.margin}return this.horizontal?r+this.x:this.length-r+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){let e=this.getMinMax(),{start:i,stop:r}=e,s=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin,n;if(this.logScale)n=Math.pow(10,(s-this.margin)*(Math.log10(r)-Math.log10(i))/o+Math.log10(i));else{let a=Math.max(Math.abs(i),Math.abs(r));r/=a,i/=a;let l=r-i;n=((s-this.margin)/o*l+i)*a}return n}calculateMargin(t,e){if(this.showScale){let i=t.measureText(this.format(this.minimum),this.scaleFont),r=t.measureText(this.format(this.maximum),this.scaleFont);return Math.ceil(e?Math.max(i.width,r.width)/2:Math.max(i.height,r.height)/2)}else return 0}measureHorizontalHeight(t){let e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,r){let{scale:s}=this;this.length=r,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);let o=r-2*this.margin;this.snapRange(o),o>0&&this.updateLabels(t,o);let n=0;for(let l=0;l<this.labels.length;l++){let h=t.measureText(this.labels[l],this.scaleFont);h.height>n&&(n=h.height)}let a=this.showScale?n+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i=i-a,this.x=e,this.y=i,this.logScale)for(let l=0;l<this.labelPositions.length;l++){let h=this.x+this.labelPositions[l],p=this.y,d=0;if(this.labelVisibilities[l]?d=this.majorTickLength:d=this.minorTickLength,this.labelVisibilities[l]||this.showMinorTicks){let g=Math.round(h)-s*.5;t.strokePath({path:new _(g,p).lineTo(g,p+d),color:this.foregroundColor,lineWidth:s*1,opacity:100/255})}this.labelVisibilities[l]&&t.fillText({x:h,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]})}else for(let l=0;l<this.labels.length;l++){let h=e+this.labelPositions[l];this.labelVisibilities[l]&&t.fillText({x:h,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]});let p=Math.round(h)-s*.5;t.strokePath({path:new _(p,i).lineTo(p,i+this.majorTickLength),color:this.foregroundColor,lineWidth:s*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,l,e,i)}return a}drawVertical(t,e,i,r,s,o=!1){let{scale:n}=this;this.length=r,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);let a=r-2*this.margin;a>0&&this.updateLabels(t,a);let l=0;for(let p=0;p<this.labels.length;p++){let d=t.measureText(this.labels[p],this.scaleFont);d.width>l&&(l=d.width)}let h=this.showScale?l+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(s||(e=e-h),this.x=e,this.y=i,this.logScale)for(let p=0;p<this.labelPositions.length;p++){let d;this.labelVisibilities[p]?d=this.majorTickLength:d=this.minorTickLength;let g=Math.round(i+r-this.labelPositions[p])-n*.5;if(o){if((this.labelVisibilities[p]||this.showMinorTicks)&&t.strokePath({path:new _(e,g).lineTo(e+d,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[p]){let x=i+r-this.labelPositions[p];t.fillText({x:e+this.majorTickLength+this.spaceBetweenMarkAndLabel,y:x,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[p]})}}else{let x=e+l+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-d;if((this.labelVisibilities[p]||this.showMinorTicks)&&t.strokePath({path:new _(x,g).lineTo(x+d,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[p]){let w=i+r-this.labelPositions[p];t.fillText({x:e,y:w,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[p]})}}}else for(let p=0;p<this.labels.length;p++){let d=i+r-this.labelPositions[p],g=Math.round(d)-n*.5;if(o){if(t.strokePath({path:new _(e,g).lineTo(e+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[p]){let x=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x,y:d,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[p]})}}else{this.labelVisibilities[p]&&t.fillText({x:e,y:d,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[p]});let x=e+l+this.spaceBetweenMarkAndLabel-n*1;t.strokePath({path:new _(x,g).lineTo(x+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,p,x,i+r)}}return h}drawMinorXTicks(t,e,i,r){let{gridStepInPixel:s}=this,o,n;s/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(s/5)):s/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(s/4)):(o=2,n=Math.floor(s/2));let{labelPositions:a,minorTickLength:l,scale:h}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let p=a[1];for(;p-a[0]>n+3*h;){p=p-n;let d=Math.round(i+p)-h*.5;t.strokePath({path:new _(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let p=a[e-1];for(;a[e]-p>n+3*h;){p=p+n;let d=Math.round(i+p)-h*.5;t.strokePath({path:new _(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else for(let p=0;p<o;p++){let d=i+a[e-1]+(a[e]-a[e-1])*p/o;d=Math.round(d)-h*.5,t.strokePath({path:new _(d,r).lineTo(d,r+l),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}drawMinorYTicks(t,e,i,r){let{gridStepInPixel:s}=this,o,n;s/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(s/5)):s/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(s/4)):(o=2,n=Math.floor(s/2));let{labelPositions:a,minorTickLength:l,majorTickLength:h,scale:p}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let d=a[1];for(;d-a[0]>n+3*p;){d-=n;let g=Math.round(r-d)-p*.5;t.strokePath({path:new _(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:p*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let d=a[e-1];for(;a[e]-d>n+3*p;){d+=n;let g=Math.round(r-d)-p*.5;t.strokePath({path:new _(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:p*1,opacity:100/255})}}else for(let d=0;d<o;d++){let g=r-a[e-1]-(a[e]-a[e-1])*d/o;g=Math.round(g)-p*.5,t.strokePath({path:new _(i+h-l,g).lineTo(i+h,g),color:this.foregroundColor,lineWidth:p*1,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{let i=this.getGridStep(e,this.minimum,this.maximum),r=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/r-this.minimum/r;this.gridStepInPixel=Math.floor(e*(i/r)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,i)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let r=!1;if(e>=i)if(i===e)i++;else{r=!0;let p=e;e=i,i=p}let s=Math.abs(i-e),o=this.majorTickStepHint;o>t&&(o=t);let a=s/t*o,l=0;if(a<1){if(a!=0)for(;a<1;)a*=10,l--}else for(;a>=10;)a/=10,l++;let h;return a>7.5?h=10*Math.pow(10,l):a>3.5?h=5*Math.pow(10,l):a>1.5?h=2*Math.pow(10,l):h=Math.pow(10,l),r&&(h=-h),h}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);let r=e<t,s=Math.log10(t),o=Math.ceil(s),n=Math.ceil(Math.log10(e)),a=Math.pow(10,o-1),l;t%a<=0||r?l=t-t%a:l=t-t%a+a,r&&t>l?this.addMinMaxTickInfo(t,i,!0):!r&&t<l&&this.addMinMaxTickInfo(t,i,!0);for(let h=o;r?h>=n:h<=n;h+=r?-1:1)if(Math.abs(n-o)>20){let p=Math.pow(10,h);if(p>e)break;this.addTickInfo(p,e,s,i)}else{for(let p=l;(r?p>=Math.pow(10,h-1):p<=Math.pow(10,h))&&!(r?p<e:p>e);p=r?p-a:p+a)this.addTickInfo(p,e,s,i);a=r?a/Math.pow(10,1):a*Math.pow(10,1),l=r?Math.pow(10,h-1):a+Math.pow(10,h)}(r?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,r){this.labels.push(this.format(t));let s=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*r)+this.margin;this.labelPositions.push(s),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,r){let s=e<t,o;t%r<=0?o=t-t%r:o=t-t%r+r,t>o==s&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let n=1,a=Math.max(Math.abs(t),Math.abs(e));e/=a,t/=a,r/=a,o/=a;let l=e-t;for(let h=o;e>=t?h<e:h>e;h=o+n++*r){let p=h*a;this.labels.push(this.format(p)),this.labelValues.push(p);let d=Math.floor((h-t)/l*i)+this.margin;this.labelPositions.push(d)}e*=a,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 r=0;r<this.labelPositions.length;r++)this.labelVisibilities.push(!0);let e=0,i=null;for(let r=0;r<this.labelPositions.length;r++){let s=!0,o=this.labels[r],n=this.labelPositions[r];r!==0&&(s=this.hasSpaceToDraw(t,e,n,i||"",o));let a=o===i&&r!==0&&r!==this.labelPositions.length-1,l=!0;if(this.logScale){let h=Number(this.labels[r]);l=this.isMajorTick(h)||r===0||r===this.labelPositions.length-1}!s||a||!l?this.labelVisibilities[r]=!1:(e=n,i=o)}}hasSpaceToDraw(t,e,i,r,s){let o=t.measureText(s,this.scaleFont),n=t.measureText(r,this.scaleFont),a=i-e,l=Math.floor(this.horizontal?o.width/2+n.width/2:o.height),h=!0,p=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){h=a>l+this.tickLabelGap;let d=t.measureText(this.labels[this.labels.length-1],this.scaleFont);a=this.labelPositions[this.labelPositions.length-1]-i,l=Math.floor(this.horizontal?o.width/2+d.width/2:o.height),p=a>l+this.tickLabelGap}return h&&p}isMajorTick(t){if(!this.logScale)return!0;let e=Math.log10(t);return e===Math.round(e)}format(t){if(this.timeFormat===0)return this.scaleFormat?new rt(this.scaleFormat).format(t):String(Number(t.toFixed(2)));let e=new Date(t),i=this.formatter;switch(this.timeFormat){case 1:return i.formatDate(e,{year:!0,month:!0,day:!0})+`
18
18
  `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return i.formatDate(e,{year:!0,month:!0,day:!0})+`
19
- `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return i.formatDate(e,{year:!0,month:!0,day:!0});case 7:let r=this.formatter.utc,s=Qx[r?e.getUTCMonth():e.getMonth()],o=r?e.getUTCDate():e.getDate();return`${s} ${o}`;case 8:let n=Math.abs(this.maximum-this.minimum);return n<=5e3?i.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):n<=18e5?i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):n<=864e5?i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):n<=6048e5?i.formatDate(e,{year:!1,month:!0,day:!0})+`
20
- `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):n<=2592e6?i.formatDate(e,{year:!1,month:!0,day:!0}):i.formatDate(e,{year:!0,month:!0,day:!0})}return""}get spaceBetweenMarkAndLabel(){return this.scale*2}get majorTickLength(){return this.scale*6}get minorTickLength(){return this.scale*3}get minorTickMarkStepHint(){return this.scale*4}get tickLabelGap(){return this.horizontal?this.scale*10:this.scale*2}};var ty=100/255,ey=20,iy=11,ry=6,sy=5,oy=150,gh="color_hi",mh="color_hihi",fh="color_lo",wh="color_lolo",xh="color_fillbackground",yh="effect_3d",Ph="fill_color",bh="font",vh="horizontal",Rh="level_hi",_h="level_hihi",Th="level_lo",Sh="level_lolo",Lh="limits_from_pv",Ch="log_scale",Ah="major_tick_step_hint",Oh="maximum",Eh="minimum",Mh="page_increment",Vh="scale_font",Ih="scale_format",Bh="show_hi",Hh="show_hihi",Dh="show_lo",Wh="show_lolo",kh="show_markers",Nh="show_minor_ticks",Fh="show_scale",Gh="step_increment",$h="thumb_color",Uh="transparent_background",Yh="value_label_format",Pr=class extends M{trackRegion;thumbRegion;grabStartValue;trackScale;pageTimeout;pageUp=!1;pagePressedValue=0;hoveringThumb=!1;draggingThumb=!1;constructor(t,e){super(t,e),this.properties.add(new S(gh,new m(255,128,0))),this.properties.add(new S(mh,new m(255,0,0))),this.properties.add(new S(fh,new m(255,128,0))),this.properties.add(new S(wh,new m(255,0,0))),this.properties.add(new S(xh,new m(200,200,200))),this.properties.add(new f(yh,!0)),this.properties.add(new S(Ph,m.BLUE)),this.properties.add(new H(bh)),this.properties.add(new f(vh,!1)),this.properties.add(new C(Rh)),this.properties.add(new C(_h)),this.properties.add(new C(Th)),this.properties.add(new C(Sh)),this.properties.add(new f(Lh,!0)),this.properties.add(new f(Ch)),this.properties.add(new P(Ah,50)),this.properties.add(new C(Oh,100)),this.properties.add(new C(Eh,0)),this.properties.add(new C(Mh,10)),this.properties.add(new H(Vh)),this.properties.add(new T(Ih)),this.properties.add(new f(Bh,!0)),this.properties.add(new f(Hh,!0)),this.properties.add(new f(Dh,!0)),this.properties.add(new f(Wh,!0)),this.properties.add(new f(kh,!0)),this.properties.add(new f(Nh,!0)),this.properties.add(new f(Fh,!0)),this.properties.add(new C(Gh,1)),this.properties.add(new S($h,new m(172,172,172))),this.properties.add(new f(Uh)),this.properties.add(new T(Yh))}init(){this.trackRegion={id:`${this.wuid}-track`,mouseDown:t=>{if(!this.enabled||!this.trackScale)return;let e=this.getAncestorOffset(),i=this.horizontal?t.point.x-e.x:t.point.y-e.y;this.pagePressedValue=this.trackScale.getPositionValue(i),this.pageUp=this.pagePressedValue>this.getCoercedValue(),this.pageRepeatedly()},mouseUp:()=>this.stopPaging(),mouseOut:()=>this.stopPaging(),tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseEnter:()=>{this.hoveringThumb=!0,this.requestRepaint()},mouseOut:()=>{this.hoveringThumb=!1,this.requestRepaint()},mouseDown:()=>{this.enabled&&(this.grabStartValue=this.getCoercedValue(),this.draggingThumb=!0,this.requestRepaint())},mouseUp:()=>{this.draggingThumb=!1,this.requestRepaint()},grabEnd:()=>{this.draggingThumb=!1,this.requestRepaint()},grab:t=>{if(!this.enabled||this.grabStartValue===void 0||!this.trackScale)return;let e=this.trackScale.scaleLength;if(e<=0)return;let i=this.horizontal?t.dx:-t.dy,{min:r,max:s}=this,o;if(this.logScale){let a=e/(Math.log10(s)-Math.log10(r));o=this.grabStartValue*Math.pow(10,i/a)}else{let a=(s-r)*i/e;o=this.grabStartValue+a}let{stepIncrement:n}=this;if(n>0){let a=o-this.grabStartValue,l=n*Math.round(a/n);o=this.grabStartValue+l}this.setCoercedValue(o),this.requestRepaint()},cursor:"pointer",tooltip:()=>this.tooltip}}draw(t){let e=this.area;this.transparentBackground||t.fillRect({...e,color:this.backgroundColor}),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e),this.enabled||t.fillRect({...e,color:m.GRAY,opacity:ty})}drawVertical(t,e){let i=new nt(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,this.foregroundColor,this.showMinorTicks,this.showScale);i.scaleFormat=this.scaleFormat;let r=e.x+e.width/2,s=this.thumbLength/2+this.gapBtwThumbScale;i.drawVertical(t,r+s,e.y,e.height,!0,!0),this.showMarkers&&this.drawVerticalMarkers(t,i,r-s);let o={x:r-this.trackBreadth/2,y:e.y+i.margin,width:this.trackBreadth,height:e.height-2*i.margin};this.trackScale=i,this.drawVerticalTrack(t,i,o)}drawVerticalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=0;this.showLoLo&&r!==void 0&&(l=Math.max(l,t.measureText("LOLO",a).width)),this.showLo&&s!==void 0&&(l=Math.max(l,t.measureText("LO",a).width)),this.showHi&&o!==void 0&&(l=Math.max(l,t.measureText("HI",a).width)),this.showHiHi&&n!==void 0&&(l=Math.max(l,t.measureText("HIHI",a).width));let h=this.markerTickLength+this.markerGap+l,c=i-h,d=(g,w,x)=>{let _=c+l+this.markerGap,L=Math.round(e.getValuePosition(g));t.strokePath({path:new R(_,L).lineTo(_+this.markerTickLength,L),color:w,lineWidth:this.markerTickLineWidth}),t.fillText({x:c,y:L,text:x,align:"left",baseline:"middle",color:w,font:a})};this.showLoLo&&r!==void 0&&d(r,this.colorLoLo,"LOLO"),this.showLo&&s!==void 0&&d(s,this.colorLo,"LO"),this.showHi&&o!==void 0&&d(o,this.colorHi,"HI"),this.showHiHi&&n!==void 0&&d(n,this.colorHiHi,"HIHI")}drawVerticalTrack(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let l=t.createLinearGradient(i.x,0,i.x+i.width,0);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:l});let h=D(i,r/2);t.strokeRect({...h,color:m.GRAY,lineWidth:r})}let s=e.getValuePosition(this.getCoercedValue()),o=D({...i,y:s,height:i.y+i.height-s},r);if(t.fillRect({...o,color:this.fillColor}),this.effect3d){let l=t.createLinearGradient(o.x,0,o.x+o.width,0);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.fillColor.withAlpha(0).toString()),t.fillRect({...o,gradient:l})}t.addHitRegion(this.trackRegion).addRect(i.x,i.y,i.width,i.height);let a={x:i.x+i.width/2,y:s};this.drawThumb(t,a,!0),this.drawValueLabel(t,{x:a.x-this.thumbLength/2-this.markerGap,y:a.y},"right","middle")}drawHorizontal(t,e){let i=new nt(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,this.foregroundColor,this.showMinorTicks,this.showScale);i.scaleFormat=this.scaleFormat;let r=e.y+e.height/2,s=this.thumbLength/2+this.gapBtwThumbScale,o=i.measureHorizontalHeight(t);i.drawHorizontal(t,e.x,r+s+o,e.width),this.showMarkers&&this.drawHorizontalMarkers(t,i,r-s);let n={x:e.x+i.margin,y:r-this.trackBreadth/2,width:e.width-2*i.margin,height:this.trackBreadth};this.trackScale=i,this.drawHorizontalTrack(t,i,n)}drawHorizontalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=0;this.showLoLo&&r!==void 0&&(l=Math.max(l,t.measureText("LOLO",a).height)),this.showLo&&s!==void 0&&(l=Math.max(l,t.measureText("LO",a).height)),this.showHi&&o!==void 0&&(l=Math.max(l,t.measureText("HI",a).height)),this.showHiHi&&n!==void 0&&(l=Math.max(l,t.measureText("HIHI",a).height));let h=i-(this.markerTickLength+this.markerGap+l),c=(d,g,w)=>{let x=Math.round(e.getValuePosition(d)),_=h+l+this.markerGap;t.strokePath({path:new R(x,_).lineTo(x,_+this.markerTickLength),color:g,lineWidth:this.markerTickLineWidth}),t.fillText({x,y:h,text:w,align:"center",baseline:"top",color:g,font:a})};this.showLoLo&&r!==void 0&&c(r,this.colorLoLo,"LOLO"),this.showLo&&s!==void 0&&c(s,this.colorLo,"LO"),this.showHi&&o!==void 0&&c(o,this.colorHi,"HI"),this.showHiHi&&n!==void 0&&c(n,this.colorHiHi,"HIHI")}drawHorizontalTrack(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let l=t.createLinearGradient(0,i.y,0,i.y+i.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:l});let h=D(i,r/2);t.strokeRect({...h,color:m.GRAY,lineWidth:r})}let s=e.getValuePosition(this.getCoercedValue()),o=D({...i,width:s-i.x},r);if(t.fillRect({...o,color:this.fillColor}),this.effect3d){let l=t.createLinearGradient(0,o.y,0,o.y+o.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.fillColor.withAlpha(0).toString()),t.fillRect({...o,gradient:l})}t.addHitRegion(this.trackRegion).addRect(i.x,i.y,i.width,i.height);let a={x:s,y:i.y+i.height/2};this.drawThumb(t,a,!1),this.drawValueLabel(t,{x:a.x,y:a.y-this.thumbLength/2-this.markerGap},"center","bottom")}drawThumb(t,e,i){let r=this.thumbLength,s=this.thumbBreadth,o;if(i){let l=e.x-r/2,h=e.y-s/2;o=[{x:l,y:h},{x:l,y:h+s},{x:l+r*4/5,y:h+s},{x:l+r,y:h+s/2},{x:l+r*4/5,y:h}]}else{let l=e.x-s/2,h=e.y-r/2;o=[{x:l,y:h},{x:l+s,y:h},{x:l+s,y:h+r*4/5},{x:l+s/2,y:h+r},{x:l,y:h+r*4/5}]}let n=R.fromPoints(o).closePath();if(this.effect3d){let l=o[0],h=o[3],c=t.createLinearGradient(l.x,l.y,h.x,h.y);c.addColorStop(0,m.WHITE.toString()),c.addColorStop(1,this.thumbColor.toString()),t.fillPath({path:n,gradient:c})}else t.fillPath({path:n,color:this.thumbColor});t.strokePath({path:n,color:m.GRAY,lineWidth:1*this.scale}),t.addHitRegion(this.thumbRegion).addPath(n)}drawValueLabel(t,e,i,r){this.value!==void 0&&(!this.hoveringThumb&&!this.draggingThumb||t.fillText({x:e.x,y:e.y,text:this.formatLabelValue(this.value),align:i,baseline:r,color:this.foregroundColor,font:this.font}))}pageRepeatedly(){window.clearTimeout(this.pageTimeout);let t=this.getCoercedValue();(this.pageUp?t>=this.pagePressedValue:t<=this.pagePressedValue)||(this.setCoercedValue(t+(this.pageUp?this.pageIncrement:-this.pageIncrement)),this.requestRepaint(),this.pageTimeout=window.setTimeout(()=>this.pageRepeatedly(),oy))}stopPaging(){window.clearTimeout(this.pageTimeout)}getAncestorOffset(){let t=0,e=0,i=this.parent;for(;i;)t+=i.x,e+=i.y,i=i.parent;return{x:t,y:e}}setCoercedValue(t){let{min:e,max:i}=this;t=Math.min(i,Math.max(e,t)),this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,t):this.pv||(this.value=t)}getCoercedValue(){let{min:t,max:e}=this,i=this.value??(t+e)/2;return Math.min(e,Math.max(t,i))}formatLabelValue(t){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let e=jt(this.min,this.max);return new rt(e).format(t)}}destroy(){window.clearTimeout(this.pageTimeout)}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get outlineWidth(){return this.scale*1}get trackBreadth(){return this.scale*ry}get thumbLength(){return this.scale*ey}get thumbBreadth(){return this.scale*iy}get gapBtwThumbScale(){return this.scale*sy}get colorHi(){return this.properties.getValue(gh)}get colorHiHi(){return this.properties.getValue(mh)}get colorLo(){return this.properties.getValue(fh)}get colorLoLo(){return this.properties.getValue(wh)}get colorFillbackground(){return this.properties.getValue(xh)}get effect3d(){return this.properties.getValue(yh)}get fillColor(){return this.properties.getValue(Ph)}get font(){return this.properties.getValue(bh).scale(this.scale)}get horizontal(){return this.properties.getValue(vh)}get levelHi(){return this.properties.getValue(Rh)}get levelHiHi(){return this.properties.getValue(_h)}get levelLo(){return this.properties.getValue(Th)}get levelLoLo(){return this.properties.getValue(Sh)}get limitsFromPv(){return this.properties.getValue(Lh)}get logScale(){return this.properties.getValue(Ch)}get majorTickStepHint(){return this.scale*this.properties.getValue(Ah)}get maximum(){return this.properties.getValue(Oh)}get minimum(){return this.properties.getValue(Eh)}get pageIncrement(){return this.properties.getValue(Mh)}get scaleFont(){return this.properties.getValue(Vh).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Ih)}get showHi(){return this.properties.getValue(Bh)}get showHiHi(){return this.properties.getValue(Hh)}get showLo(){return this.properties.getValue(Dh)}get showLoLo(){return this.properties.getValue(Wh)}get showMarkers(){return this.properties.getValue(kh)}get showMinorTicks(){return this.properties.getValue(Nh)}get showScale(){return this.properties.getValue(Fh)}get stepIncrement(){return this.properties.getValue(Gh)}get thumbColor(){return this.properties.getValue($h)}get transparentBackground(){return this.properties.getValue(Uh)}get valueLabelFormat(){return this.properties.getValue(Yh)}};var zh="enabled",Xh="font",qh="maximum",Kh="minimum",jh="horizontal",Zh="step_increment",Jh="page_increment",Qh="bar_length",tc="show_value_tip",ec=new m(243,243,243),Me=new m(232,232,231),br=150,vr=class extends M{decreaseRegion;decreasePressed=!1;increaseRegion;increasePressed=!1;pageDecreaseRegion;pageDecreasePressed=!1;pageIncreaseRegion;pageIncreasePressed=!1;thumbRegion;grabStartValue;dragRange;actionTimeout;constructor(t,e){super(t,e),this.properties.add(new f(zh)),this.properties.add(new f(jh)),this.properties.add(new f(tc)),this.properties.add(new H(Xh)),this.properties.add(new C(qh)),this.properties.add(new C(Kh)),this.properties.add(new C(Zh)),this.properties.add(new C(Jh)),this.properties.add(new C(Qh))}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=>{let 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(t){let{scale:e}=this,i=D(this.bounds,2*e);t.fillRect({...i,color:ec});let r=Math.min(i.height,i.width/2);this.drawLeftButton(t,{x:i.x,y:i.y,width:r,height:i.height}),this.drawRightButton(t,{x:i.x+i.width-r,y:i.y,width:r,height:i.height});let s=this.barLength,o=this.maximum+s,n=this.minimum,a=o-n,l=a-s,h=i.width-r-r,c=Math.floor(Math.max(6*e,h*s/a));this.dragRange=h-c;let d=this.getCoercedValue(),g=Math.floor((h-c)*(d-n)/l),w=h-g-c,x={x:i.x+r+g,y:i.y,width:c,height:i.height};t.fillRect({...x,color:Me}),this.drawRaisedButtonBorder(t,x),t.addHitRegion(this.thumbRegion).addRect(x.x,x.y,x.width,x.height);let L={x:i.x+r,y:i.y,width:g,height:i.height};t.addHitRegion(this.pageDecreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageDecreasePressed&&t.fillRect({...L,color:m.BLACK});let E={x:i.x+r+g+c,y:i.y,width:w,height:i.height};t.addHitRegion(this.pageIncreaseRegion).addRect(E.x,E.y,E.width,E.height),this.pageIncreasePressed&&t.fillRect({...E,color:m.BLACK})}drawVertical(t){let{scale:e}=this,i=D(this.bounds,e);t.fillRect({...i,color:ec});let r=Math.min(i.width,i.height/2);this.drawUpButton(t,{x:i.x,y:i.y,width:i.width,height:r}),this.drawDownButton(t,{x:i.x,y:i.y+i.height-r,width:i.width,height:r});let s=this.barLength,o=this.maximum+s,n=this.minimum,a=o-n,l=a-s,h=i.height-r-r,c=Math.floor(Math.max(6*e,h*s/a));this.dragRange=h-c;let d=this.getCoercedValue(),g=Math.floor((h-c)*(d-n)/l),w=h-g-c,x={x:i.x,y:i.y+r+g,width:i.width,height:c};t.fillRect({...x,color:Me}),this.drawRaisedButtonBorder(t,x),t.addHitRegion(this.thumbRegion).addRect(x.x,x.y,x.width,x.height);let L={x:i.x,y:i.y+r,width:i.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageDecreasePressed&&t.fillRect({...L,color:m.BLACK});let E={x:i.x,y:i.y+r+g+c,width:i.width,height:w};t.addHitRegion(this.pageIncreaseRegion).addRect(E.x,E.y,E.width,E.height),this.pageIncreasePressed&&t.fillRect({...E,color:m.BLACK})}drawLeftButton(t,e){t.fillRect({...e,color:Me}),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height/2,r.width);r.x+=(r.width-s)/2,s=Math.max(s,1);let o={x:r.x,y:r.y+r.height/2};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x+s,o.y-s).lineTo(o.x+s,o.y+s).closePath()})}drawRightButton(t,e){t.fillRect({...e,color:Me}),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height/2,r.width);r.x+=(r.width-s)/2,s=Math.max(s,1);let o={x:r.x+s,y:r.y+r.height/2};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x-s,o.y+s).closePath()})}drawUpButton(t,e){t.fillRect({...e,color:Me}),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x-s,o.y+s).lineTo(o.x+s,o.y+s).closePath()})}drawDownButton(t,e){t.fillRect({...e,color:Me}),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y+s};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x+s,o.y-s).closePath()})}drawRaisedButtonBorder(t,e){this.drawButtonBorder(t,e,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST)}drawPressedButtonBorder(t,e){this.drawButtonBorder(t,e,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER)}drawButtonBorder(t,e,i,r,s,o){let n=1*this.scale,a=e.y+n/2,l=e.x+n/2,h=e.y+e.height-n+n/2,c=e.x+e.width-n+n/2;t.strokePath({color:i,path:new R(c,h).lineTo(c,a).moveTo(c,h).lineTo(l,h)}),t.strokePath({color:r,path:new R(c-n,h-n).lineTo(c-n,a+n).moveTo(c-n,h-n).lineTo(l+n,h-n)}),t.strokePath({color:s,path:new R(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,h-n)}),t.strokePath({color:o,path:new R(l+n,a+n).lineTo(c-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepIncreaseRepeatedly(),br)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepDecreaseRepeatedly(),br)}stepIncrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.stepIncrement)}stepDecrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageIncreaseRepeatedly(),br)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageDecreaseRepeatedly(),br)}pageIncrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.pageIncrement)}pageDecrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t-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(){let t=this.value??(this.maximum-this.minimum)/2;return t<this.minimum?this.minimum:t>this.maximum?this.maximum:t}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue(zh)}get horizontal(){return this.properties.getValue(jh)}get showValueTip(){return this.properties.getValue(tc)}get font(){return this.properties.getValue(Xh).scale(this.scale)}get minimum(){return this.properties.getValue(Kh)}get maximum(){return this.properties.getValue(qh)}get stepIncrement(){return this.properties.getValue(Zh)}get pageIncrement(){return this.properties.getValue(Jh)}get barLength(){return this.properties.getValue(Qh)}};var ic="minimum",rc="maximum",sc="step_increment",oc="page_increment",nc="limits_from_pv",ac="format",lc="precision",hc="precision_from_pv",cc="buttons_on_left",pc="horizontal_buttons_layout",dc="show_text",uc="font",gc="horizontal_alignment",mc="vertical_alignment",ny=100/255,ay=20,ly=250,hy=40,Rr=class extends M{upRegion;upPressed=!1;downRegion;downPressed=!1;areaRegion;repeatTimeout;editing=!1;inputEl;scratchCanvas;scratchCtx;constructor(t,e){super(t,e),this.properties.add(new C(ic,-Number.MAX_VALUE)),this.properties.add(new C(rc,Number.MAX_VALUE)),this.properties.add(new C(sc,1)),this.properties.add(new C(oc,10)),this.properties.add(new f(nc,!0)),this.properties.add(new P(ac,0)),this.properties.add(new P(lc,3)),this.properties.add(new f(hc,!1)),this.properties.add(new f(cc,!1)),this.properties.add(new f(pc,!1)),this.properties.add(new f(dc,!0)),this.properties.add(new H(uc)),this.properties.add(new P(gc,1)),this.properties.add(new P(mc,1))}init(){this.upRegion={id:`${this.wuid}-up`,mouseDown:()=>{this.upPressed=!0,this.stepRepeatedly(1,!0)},mouseUp:()=>this.stopRepeating("up"),mouseOut:()=>this.stopRepeating("up"),tooltip:()=>this.tooltip},this.downRegion={id:`${this.wuid}-down`,mouseDown:()=>{this.downPressed=!0,this.stepRepeatedly(-1,!0)},mouseUp:()=>this.stopRepeating("down"),mouseOut:()=>this.stopRepeating("down"),tooltip:()=>this.tooltip},this.areaRegion={id:`${this.wuid}-area`,click:()=>this.startEditing(),tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement("input"),this.inputEl.style.display="none",this.inputEl.autocomplete="off",this.inputEl.addEventListener("keyup",t=>{t.key==="Enter"?this.commitEditing():t.key==="Escape"&&this.cancelEditing()}),this.inputEl.addEventListener("blur",()=>this.cancelEditing()),this.display.rootPanel.appendChild(this.inputEl),this.scratchCanvas=document.createElement("canvas"),this.scratchCtx=this.scratchCanvas.getContext("2d")}stopRepeating(t){window.clearTimeout(this.repeatTimeout),t==="up"?this.upPressed=!1:this.downPressed=!1,this.requestRepaint()}stepRepeatedly(t,e){window.clearTimeout(this.repeatTimeout),this.step(t),this.requestRepaint(),this.repeatTimeout=window.setTimeout(()=>this.stepRepeatedly(t,!1),e?ly:hy)}step(t){let e=this.currentNumericValue(),i=this.clamp(e+t*this.stepIncrement);i!==e&&(this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,i):this.pv||(this.value=i))}currentNumericValue(){let t=Number(this.value);return isNaN(t)?0:t}clamp(t){let{minimum:e,maximum:i}=this;return t<e?e:t>i?i:t}startEditing(){if(this.pv&&!this.pv.writable)return;let{labelBounds:t}=this.computeLayout();if(!t)return;this.editing=!0;let e=this.display.measureAbsoluteArea(this),i={x:e.x+(t.x-this.area.x),y:e.y+(t.y-this.area.y),width:t.width,height:t.height};this.inputEl.value=this.formatSpinnerValue(this.currentNumericValue()),this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${i.x}px`,this.inputEl.style.top=`${i.y}px`,this.inputEl.style.width=`${i.width}px`,this.inputEl.style.height=`${i.height}px`,this.inputEl.focus(),this.inputEl.select(),this.requestRepaint()}commitEditing(){let t=this.inputEl.value;this.cancelEditing();let e=Number(t);if(isNaN(e))return;let i=this.clamp(e);this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,i):this.pv||(this.value=i)}cancelEditing(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let{labelBounds:e,upBounds:i,downBounds:r}=this.computeLayout();e&&!this.editing&&(t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.drawLabel(t,e)),this.drawUpButton(t,i),this.drawDownButton(t,r),this.enabled||t.fillRect({...this.area,color:m.GRAY,opacity:ny})}computeLayout(){let t=ay*this.scale,e=1*this.scale,i=this.area,r,s,o;if(this.showText)if(this.buttonsOnLeft)if(this.horizontalButtonsLayout)r={x:i.x+e+2*t,y:i.y,width:i.width-2*t-e,height:i.height},s={x:i.x,y:i.y,width:t,height:i.height},o={x:i.x+t,y:i.y,width:t,height:i.height};else{r={x:i.x+e+t,y:i.y,width:i.width-t-e,height:i.height};let n=Math.floor(i.height/2);s={x:i.x,y:i.y,width:t,height:n},o={x:i.x,y:i.y+n,width:t,height:n}}else if(this.horizontalButtonsLayout)r={x:i.x,y:i.y,width:i.width-2*t,height:i.height},s={x:i.x+i.width-2*t,y:i.y,width:t,height:i.height},o={x:i.x+i.width-t,y:i.y,width:t,height:i.height};else{r={x:i.x,y:i.y,width:i.width-t,height:i.height};let n=Math.floor(i.height/2);s={x:i.x+i.width-t,y:i.y,width:t,height:n},o={x:i.x+i.width-t,y:i.y+n,width:t,height:n}}else if(this.horizontalButtonsLayout){let n=Math.floor(i.width/2);s={x:i.x,y:i.y,width:n,height:i.height},o={x:i.x+n,y:i.y,width:n,height:i.height}}else{let n=Math.floor(i.height/2);s={x:i.x,y:i.y,width:i.width,height:n},o={x:i.x,y:i.y+n,width:i.width,height:n}}return{labelBounds:r,upBounds:s,downBounds:o}}drawLabel(t,e){let{pixelRatio:i}=t,r=fe(t.ctx,e.x,e.y),s=Math.max(1,Math.ceil(e.width+r.subPixelX)),o=Math.max(1,Math.ceil(e.height+r.subPixelY));this.scratchCanvas.width=Math.ceil(s*i),this.scratchCanvas.height=Math.ceil(o*i);let n=this.scratchCtx;n.clearRect(0,0,this.scratchCanvas.width,this.scratchCanvas.height),n.setTransform(i,0,0,i,0,0),n.translate(r.subPixelX,r.subPixelY),n.fillStyle=this.alarmSensitiveForegroundColor.toString(),n.font=this.font.getFontString();let a=e.x;this.horizAlignment===0?n.textAlign="start":this.horizAlignment===1?(a+=e.width/2,n.textAlign="center"):(a+=e.width,n.textAlign="end");let l=e.y;this.vertAlignment===0?n.textBaseline="top":this.vertAlignment===1?(l+=e.height/2,n.textBaseline="middle"):(l+=e.height,n.textBaseline="bottom");let h=this.formatSpinnerValue(this.currentNumericValue());n.fillText(h,a-e.x,l-e.y),t.ctx.drawImage(this.scratchCanvas,r.x,r.y,s,o)}formatSpinnerValue(t){let e=this.precisionFromPV&&this.pv&&this.pv.precision>=0?this.pv.precision:this.precision;switch(this.format){case 1:return t.toExponential(e).toUpperCase().replace("E+","E");case 2:return"0x"+Math.trunc(t).toString(16);default:{let i={minimumFractionDigits:0,maximumFractionDigits:e,useGrouping:!1,roundingMode:"halfEven"};return new Intl.NumberFormat("en-US",i).format(t)}}}drawUpButton(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawSpinnerButtonBorder(t,e,this.upPressed),t.addHitRegion(this.upRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x-s,o.y+s).lineTo(o.x+s,o.y+s).closePath()})}drawDownButton(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawSpinnerButtonBorder(t,e,this.downPressed),t.addHitRegion(this.downRegion).addRect(e.x,e.y,e.width,e.height);let r=D(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y+s};t.fillPath({color:m.BLACK,path:new R(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x+s,o.y-s).closePath()})}drawSpinnerButtonBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r/2,a=e.x+e.width-r/2,l=i?m.BUTTON_DARKEST:m.BUTTON_LIGHTEST,h=i?m.BUTTON_LIGHTEST:m.BUTTON_DARKEST;t.strokePath({color:l,lineWidth:r,path:new R(o,n).lineTo(o,s).lineTo(a,s)}),t.strokePath({color:h,lineWidth:r,path:new R(a,s).lineTo(a,n).lineTo(o,n)})}destroy(){window.clearTimeout(this.repeatTimeout),this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0),this.scratchCanvas=void 0,this.scratchCtx=void 0}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(ic)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(rc)}get stepIncrement(){return this.properties.getValue(sc)}get pageIncrement(){return this.properties.getValue(oc)}get limitsFromPV(){return this.properties.getValue(nc)}get format(){return this.properties.getValue(ac)}get precision(){return this.properties.getValue(lc)}get precisionFromPV(){return this.properties.getValue(hc)}get buttonsOnLeft(){return this.properties.getValue(cc)}get horizontalButtonsLayout(){return this.properties.getValue(pc)}get showText(){return this.properties.getValue(dc)}get font(){return this.properties.getValue(uc).scale(this.scale)}get horizAlignment(){return this.properties.getValue(gc)}get vertAlignment(){return this.properties.getValue(mc)}};var fc="auto_size",wc="confirm_message",Ns="font",xc="format_type",yc="horizontal_alignment",Pc="limits_from_pv",bc="maximum",vc="minimum",Rc="multiline_input",_c="password_input",Tc="precision",Sc="precision_from_pv",Lc="read_only",Cc="rotation_angle",Ac="show_h_scroll",Oc="show_lohi",Ec="show_native_border",Mc="show_units",Vc="show_v_scroll",Ic="style",Bc="vertical_alignment",Hc="wrap_words",cy=0,Fs=1,py=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/,_r=class extends M{areaRegion;inputEl;editing=!1;scratchCanvas;scratchCtx;constructor(t,e){super(t,e),this.properties.add(new f(fc)),this.properties.add(new T(wc)),this.properties.add(new H(Ns)),this.properties.add(new P(xc)),this.properties.add(new P(yc)),this.properties.add(new f(Pc,!1)),this.properties.add(new C(bc,1/0)),this.properties.add(new C(vc,-1/0)),this.properties.add(new f(Rc)),this.properties.add(new f(_c,!1)),this.properties.add(new P(Tc)),this.properties.add(new f(Sc)),this.properties.add(new f(Lc,!1)),this.properties.add(new C(Cc)),this.properties.add(new f(Ac,!1)),this.properties.add(new f(Oc,!0)),this.properties.add(new f(Ec,!0)),this.properties.add(new f(Mc,!0)),this.properties.add(new f(Vc,!1)),this.properties.add(new P(Ic,cy)),this.properties.add(new P(Bc,1)),this.properties.add(new f(Hc,!1))}init(){this.text&&(this.value=this.text),this.areaRegion={id:`${this.wuid}-area`,click:()=>{if(this.pv&&!this.pv.writable)return;this.editing=!0;let t=this.display.measureAbsoluteArea(this);if(t.x-=2*this.scale,t.y-=2*this.scale,t.width+=2*this.scale,t.height+=2*this.scale,this.inputEl.value=this.value??"",this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${t.x}px`,this.inputEl.style.top=`${t.y}px`,this.inputEl.style.width=`${t.width}px`,this.inputEl.style.height=`${t.height}px`,this.inputEl.autocomplete="off",this.multilineInput){let e=this.inputEl;e.style.resize="none"}else{let e=this.inputEl;this.passwordInput&&(e.type="password")}this.inputEl.focus(),this.inputEl.select()},tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement(this.multilineInput?"textarea":"input"),this.inputEl.style.display="none",this.inputEl.addEventListener("keyup",t=>{if(t.key==="Enter"){if(!this.multilineInput||t.ctrlKey){let e=this.inputEl?.value||"";if(typeof this.pv?.value=="number"){let i=Number(e);isNaN(i)||(e=this.clampToLimits(i))}else this.pv&&(e=this.coerceText(e));!this.confirmMessage||confirm(this.confirmMessage)?(this.value=e,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,e),this.finishEditing()):this.cancelInput()}}else t.key==="Escape"&&this.cancelInput()}),this.inputEl.addEventListener("blur",t=>{this.pv?this.cancelInput():(this.value=this.inputEl?.value||"",this.cancelInput())}),this.display.rootPanel.appendChild(this.inputEl),this.scratchCanvas=document.createElement("canvas"),this.scratchCtx=this.scratchCanvas.getContext("2d")}clampToLimits(t){let{minimum:e,maximum:i}=this;if(e<i){if(t<e)return e;if(t>i)return i}return t}coerceText(t){switch(this.formatType){case 0:case 1:case 2:case 6:{if(!py.test(t.trim()))return t;let e=parseFloat(t),{minimum:i,maximum:r}=this;if(i<r){if(e<i)return i;if(e>r)return r}return t}default:return t}}finishEditing(){this.style!==Fs&&(this.inputEl.style.display="none"),this.editing=!1,this.requestRepaint()}cancelInput(){this.style===Fs&&(this.inputEl.value=this.computeDisplayText()),this.finishEditing()}computeDisplayText(){let t=this.text;if(this.value!==void 0){let e=this.precisionFromPV?this.pv?.precision??-1:this.precision;t=me(this.value,this.formatType,e,this.pv?.typeHint),this.showUnits&&this.pv?.units&&(t+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?t+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(t+=" \u2191"))}return t}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(Ns).scale(1);this.customSize=t.measureText(this.computeDisplayText(),e,!0)}super.drawHolder(t)}draw(t){if(this.style===Fs){this.drawNative();return}if(this.editing)return;t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let i=t.ctx;this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let{pixelRatio:r}=t,s=fe(i,this.area.x,this.area.y),o=Math.ceil(this.area.width+s.subPixelX),n=Math.ceil(this.area.height+s.subPixelY);this.scratchCanvas.width=Math.ceil(o*r),this.scratchCanvas.height=Math.ceil(n*r);let a=this.scratchCtx;a.setTransform(r,0,0,r,0,0),a.translate(s.subPixelX,s.subPixelY),a.fillStyle=this.alarmSensitiveForegroundColor.toString(),a.font=this.font.getFontString();let l=this.computeDisplayText(),h=l.replace(/(\r\n|\r|\n)$/,"").split(/\r\n|\r|\n/);if(h.length>1){let c=t.measureText("Mg",this.font).height,d=h.length*c,g=0;for(let _ of h)g=Math.max(g,a.measureText(_).width);let w=0;this.horizAlignment===1?w=(this.width-g)/2:this.horizAlignment===2&&(w=this.width-g);let x=0;this.vertAlignment===1?x=(this.height-d)/2:this.vertAlignment===2&&(x=this.height-d),a.textAlign="start",a.textBaseline="top";for(let _=0;_<h.length;_++)a.fillText(h[_],w,x+_*c)}else if(this.rotationAngle){let c=t.measureText(l,this.font,!0),d=wi({width:this.area.width,height:this.area.height},c,this.rotationAngle,this.horizAlignment,this.vertAlignment);a.translate(d.x,d.y),a.rotate(this.rotationAngle*Math.PI/180),a.textAlign="left",a.textBaseline="top",a.fillText(l,0,0)}else{let c=this.x;this.horizAlignment===0?a.textAlign="start":this.horizAlignment===1?(c+=this.width/2,a.textAlign="center"):this.horizAlignment===2&&(c+=this.width,a.textAlign="end");let d=this.y;this.vertAlignment===0?a.textBaseline="top":this.vertAlignment===1?(d=d+this.height/2,a.textBaseline="middle"):this.vertAlignment===2&&(d=d+this.height,a.textBaseline="bottom"),a.fillText(l,c-this.area.x,d-this.area.y)}i.drawImage(this.scratchCanvas,s.x,s.y,o,n)}drawNative(){let t=this.inputEl,e=this.display.measureAbsoluteArea(this);t.style.display="block",t.style.position="absolute",t.style.boxSizing="border-box",t.style.left=`${e.x}px`,t.style.top=`${e.y}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.autocomplete="off",t.style.font=this.font.getFontString(),t.style.color=this.alarmSensitiveForegroundColor.toString(),this.backgroundAlarmSensitive&&this.alarm?t.style.backgroundColor=this.alarmSensitiveBackgroundColor.toString():t.style.backgroundColor=this.backgroundColor.toString(),t.style.border=this.showNativeBorder?"":"none";let i=["left","center","right"][this.horizAlignment]??"left";if(t.style.textAlign=i,t.readOnly=this.readOnly||!this.enabled,this.multilineInput){let r=t;r.style.resize="none",this.wrapWords?(r.wrap="soft",r.style.whiteSpace="pre-wrap",r.style.overflowWrap="break-word"):(r.wrap="off",r.style.whiteSpace="pre",r.style.overflowWrap="normal"),r.style.overflowX=this.showHScroll?"scroll":"hidden",r.style.overflowY=this.showVScroll?"scroll":"hidden"}else{let r=t;r.type=this.passwordInput?"password":"text"}if(document.activeElement!==t){let r=this.computeDisplayText();t.value!==r&&(t.value=r)}}hide(){this.editing=!1,this.inputEl&&(this.inputEl.style.display="none")}destroy(){this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0),this.scratchCanvas=void 0,this.scratchCtx=void 0}get autoSize(){return this.properties.getValue(fc)}get confirmMessage(){return this.properties.getValue(wc)}get font(){return this.properties.getValue(Ns).scale(this.scale)}get formatType(){return this.properties.getValue(xc)}get horizAlignment(){return this.properties.getValue(yc)}get limitsFromPV(){return this.properties.getValue(Pc)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(bc)}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(vc)}get multilineInput(){return this.properties.getValue(Rc)}get passwordInput(){return this.properties.getValue(_c)}get precision(){return this.properties.getValue(Tc)}get precisionFromPV(){return this.properties.getValue(Sc)}get readOnly(){return this.properties.getValue(Lc)}get rotationAngle(){return this.properties.getValue(Cc)}get showHScroll(){return this.properties.getValue(Ac)}get showLohi(){return this.properties.getValue(Oc)}get showNativeBorder(){return this.properties.getValue(Ec)}get showUnits(){return this.properties.getValue(Mc)}get showVScroll(){return this.properties.getValue(Vc)}get style(){return this.properties.getValue(Ic)}get vertAlignment(){return this.properties.getValue(Bc)}get wrapWords(){return this.properties.getValue(Hc)}};var Dc="minimum",Wc="maximum",kc="integerDigits",Nc="decimalDigits",Fc="internalFrameColor",Gc="focusedFrameColor",$c="internalFrameSize",Uc="limits_from_pv",Yc="show_buttons",zc="font",dy=100/255,uy=20,Xc=15,gy=250,my=40;function Tr(p,t){let e=Math.pow(10,t);return Math.round(p*e)/e}var Sr=class extends M{repeatTimeout;integerPressed=[];decimalPressed=[];constructor(t,e){super(t,e),this.properties.add(new C(Dc,0)),this.properties.add(new C(Wc,100)),this.properties.add(new P(kc,3)),this.properties.add(new P(Nc,2)),this.properties.add(new S(Fc,m.BLACK)),this.properties.add(new S(Gc,m.BLUE)),this.properties.add(new P($c,1)),this.properties.add(new f(Uc,!1)),this.properties.add(new f(Yc,!0)),this.properties.add(new H(zc))}ensurePressedArrays(){let{integerDigits:t,decimalDigits:e}=this;this.integerPressed.length!==t&&(this.integerPressed=new Array(t).fill(void 0)),this.decimalPressed.length!==e&&(this.decimalPressed=new Array(e).fill(void 0))}draw(t){this.ensurePressedArrays(),this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let e=this.computeLayout(),{integerCharsByPlace:i,decimalCharsByIndex:r,showMinus:s}=this.computeDigits(),{integerDigits:o,decimalDigits:n}=this;this.drawPlainCell(t,e.sign,s?"-":"");for(let a=0;a<e.integer.length;a++){let l=o-a-1;this.drawDigitCell(t,e.integer[a],i[l],!1,l)}this.drawPlainCell(t,e.dot,n>0?".":"");for(let a=0;a<e.decimal.length;a++)this.drawDigitCell(t,e.decimal[a],r[a],!0,a);this.enabled||t.fillRect({...this.area,color:m.GRAY,opacity:dy})}computeLayout(){let{integerDigits:t,decimalDigits:e,showButtons:i}=this,r=this.area,s=2+t+e,o=r.width/s,n=i?uy*this.scale:0,a=x=>({x:r.x+x*o,y:r.y,width:o,height:r.height}),l=x=>{let _=a(x);return i?{cell:_,up:{x:_.x,y:_.y,width:o,height:n},down:{x:_.x,y:_.y+_.height-n,width:o,height:n}}:{cell:_}},h=0,c=a(h++),d=[];for(let x=0;x<t;x++)d.push(l(h++));let g=a(h++),w=[];for(let x=0;x<e;x++)w.push(l(h++));return{sign:c,integer:d,dot:g,decimal:w}}computeDigits(){let{integerDigits:t,decimalDigits:e}=this,i=this.currentNumericValue(),{wheelMax:r}=this.computeWheelLimits(),s=i<0;if(Math.abs(i)>r)return{integerCharsByPlace:new Array(t).fill("X"),decimalCharsByIndex:new Array(e).fill("X"),showMinus:s};let o=Math.abs(i).toFixed(e),[n,a]=o.split("."),l=[];for(let c=0;c<t;c++){let d=n.length-1-c;l.push(d>=0?n[d]:"0")}let h=[];for(let c=0;c<e;c++)h.push(a?a[c]:"0");return{integerCharsByPlace:l,decimalCharsByIndex:h,showMinus:s}}computeWheelLimits(){let{integerDigits:t,decimalDigits:e}=this,i=t>0?"9".repeat(t):"0";e>0&&(i+="."+"9".repeat(e));let r=Number(i);return{wheelMin:-r,wheelMax:r}}currentNumericValue(){let t=Number(this.value);return isNaN(t)?0:t}drawPlainCell(t,e,i){this.drawCellBorder(t,e),this.drawCellText(t,e,i)}drawDigitCell(t,e,i,r,s){if(this.drawCellBorder(t,e.cell),this.drawCellText(t,this.computeLabelBounds(e),i),!e.up||!e.down)return;let o=r?this.decimalPressed:this.integerPressed,n={id:`${this.wuid}-${r?"dec":"int"}-${s}-up`,mouseDown:()=>{this.enabled&&(o[s]=1,this.clickRepeatedly(r,s,1,!0))},mouseUp:()=>this.stopRepeating(o,s),mouseOut:()=>this.stopRepeating(o,s),tooltip:()=>this.tooltip},a={id:`${this.wuid}-${r?"dec":"int"}-${s}-down`,mouseDown:()=>{this.enabled&&(o[s]=-1,this.clickRepeatedly(r,s,-1,!0))},mouseUp:()=>this.stopRepeating(o,s),mouseOut:()=>this.stopRepeating(o,s),tooltip:()=>this.tooltip};this.drawUpButton(t,e.up,n,o[s]===1),this.drawDownButton(t,e.down,a,o[s]===-1)}computeLabelBounds(t){return!t.up||!t.down?t.cell:{x:t.cell.x,y:t.up.y+t.up.height,width:t.cell.width,height:t.cell.height-t.up.height-t.down.height}}drawCellBorder(t,e){this.internalFrameSize<=0||t.strokeRect({...e,color:this.internalFrameColor,lineWidth:this.internalFrameSize*this.scale})}drawCellText(t,e,i){i&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:i,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font})}drawUpButton(t,e,i,r){t.fillRect({...e,color:m.BUTTON}),this.drawButtonBorder(t,e,r),t.addHitRegion(i).addRect(e.x,e.y,e.width,e.height);let o=D(e,3*this.scale),n=Math.min(o.height,o.width/2);o.y+=(o.height-n)/2,n=Math.max(n,1);let a={x:o.x+o.width/2,y:o.y};t.fillPath({color:m.BLACK,path:new R(a.x,a.y).lineTo(a.x-n,a.y+n).lineTo(a.x+n,a.y+n).closePath()})}drawDownButton(t,e,i,r){t.fillRect({...e,color:m.BUTTON}),this.drawButtonBorder(t,e,r),t.addHitRegion(i).addRect(e.x,e.y,e.width,e.height);let o=D(e,3*this.scale),n=Math.min(o.height,o.width/2);o.y+=(o.height-n)/2,n=Math.max(n,1);let a={x:o.x+o.width/2,y:o.y+n};t.fillPath({color:m.BLACK,path:new R(a.x,a.y).lineTo(a.x-n,a.y-n).lineTo(a.x+n,a.y-n).closePath()})}drawButtonBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r/2,a=e.x+e.width-r/2,l=i?m.BUTTON_DARKEST:m.BUTTON_LIGHTEST,h=i?m.BUTTON_LIGHTEST:m.BUTTON_DARKEST;t.strokePath({color:l,lineWidth:r,path:new R(o,n).lineTo(o,s).lineTo(a,s)}),t.strokePath({color:h,lineWidth:r,path:new R(a,s).lineTo(a,n).lineTo(o,n)})}stopRepeating(t,e){window.clearTimeout(this.repeatTimeout),t[e]=void 0,this.requestRepaint()}clickRepeatedly(t,e,i,r){window.clearTimeout(this.repeatTimeout),this.click(t,e,i),this.requestRepaint(),this.repeatTimeout=window.setTimeout(()=>this.clickRepeatedly(t,e,i,!1),r?gy:my)}click(t,e,i){if(!this.enabled)return;let r=i*(t?Math.pow(10,-(e+1)):Math.pow(10,e)),s=this.currentNumericValue(),o=i>0?this.increment(s,r):this.decrement(s,r);this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,o):this.pv||(this.value=o)}increment(t,e){let{decimalDigits:i,minimum:r,maximum:s}=this,{wheelMin:o,wheelMax:n}=this.computeWheelLimits(),a=Tr(t+e,i);return a!==0&&Math.sign(a)!==Math.sign(t)&&(a=Tr(-t+e,i)),t>s||t>n?t:t<r?r:t<o?o:a>n?n:a>s?s:a}decrement(t,e){let{decimalDigits:i,minimum:r,maximum:s}=this,{wheelMin:o,wheelMax:n}=this.computeWheelLimits(),a=Tr(t+e,i);return a!==0&&Math.sign(a)!==Math.sign(t)&&(a=Tr(-t+e,i)),t<r||t<o?t:t>s?s:t>n?n:a<r?r:a<o?o:a}destroy(){window.clearTimeout(this.repeatTimeout)}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(Dc)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(Wc)}get integerDigits(){return Math.min(this.properties.getValue(kc),Xc)}get decimalDigits(){let t=this.properties.getValue(Nc);return Math.min(t,Math.max(0,Xc-this.integerDigits))}get internalFrameColor(){return this.properties.getValue(Fc)}get focusedFrameColor(){return this.properties.getValue(Gc)}get internalFrameSize(){return this.properties.getValue($c)}get limitsFromPV(){return this.properties.getValue(Uc)}get showButtons(){return this.properties.getValue(Yc)}get font(){return this.properties.getValue(zc).scale(this.scale)}};var qc="alpha",Kc="fill",jc="line_width",Zc="line_style",Jc="start_angle",Qc="total_angle",fy="scale_options",Lr=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(qc,255)),this.properties.add(new P(jc)),this.properties.add(new P(Jc)),this.properties.add(new P(Qc)),this.properties.add(new f(Kc)),this.properties.add(new P(Zc)),this.properties.add(new tt(fy,new J(!0,!0,!0)))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){let e=this.x+this.width/2,i=this.y+this.height/2,r=this.width/2,s=this.height/2,o=-G(this.startAngle),n=-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,r,s,0,o,n,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&this.totalAngle!==0){let a,{scale:l}=this;this.lineStyle===0?a=[]:this.lineStyle===1?a=[6*l,2*l]:this.lineStyle===2?a=[2*l,2*l]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:r-this.lineWidth/2,ry:s-this.lineWidth/2,startAngle:o,endAngle:n,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:a})}}get alpha(){return this.properties.getValue(qc)}get lineWidth(){return this.scale*this.properties.getValue(jc)}get lineStyle(){return this.properties.getValue(Zc)}get startAngle(){return this.properties.getValue(Jc)}get totalAngle(){return this.properties.getValue(Qc)}get fill(){return this.properties.getValue(Kc)}};var tp="alpha",ep="bg_gradient_color",ip="fg_gradient_color",rp="fill_level",sp="gradient",op="horizontal_fill",np="line_color",ap="line_width",lp="line_style",wy="scale_options",Cr=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(tp,255)),this.properties.add(new S(ep)),this.properties.add(new S(ip)),this.properties.add(new f(sp)),this.properties.add(new P(ap)),this.properties.add(new C(rp)),this.properties.add(new f(op)),this.properties.add(new S(np)),this.properties.add(new P(lp)),this.properties.add(new tt(wy,new J(!0,!0,!0)))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){let e=this.x+this.width/2,i=this.y+this.height/2,r=this.width/2,s=this.height/2;if(!this.transparent){let o=this.alarmSensitiveBackgroundColor;if(this.gradient){let n=this.horizontalFill?this.x:this.x+this.width,a=this.horizontalFill?this.y+this.height:this.y,l=t.createLinearGradient(this.x,this.y,n,a);l.addColorStop(0,this.backgroundGradientStartColor.toString()),l.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:r,ry:s,gradient:l})}else t.fillEllipse({cx:e,cy:i,rx:r,ry:s,color:o})}if(this.lineWidth){let o=r-this.lineWidth/2,n=s-this.lineWidth/2;this.lineStyle===0?t.strokeEllipse({cx:e,cy:i,rx:o,ry:n,color:this.lineColor,lineWidth:this.lineWidth}):this.lineStyle===1?t.strokeEllipse({cx:e,cy:i,rx:o,ry:n,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`)}}drawFill(t){let e=D(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let a=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,a,e.height)}else{let a=e.height*(this.fillLevel/100),l=e.y+e.height-a;t.ctx.beginPath(),t.ctx.rect(e.x,l,e.width,e.height)}t.ctx.clip();let i=this.x+this.width/2,r=this.y+this.height/2,s=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,n=this.alarmSensitiveForegroundColor;if(this.gradient){let a=this.horizontalFill?this.x:this.x+this.width,l=this.horizontalFill?this.y+this.height:this.y,h=t.createLinearGradient(this.x,this.y,a,l);h.addColorStop(0,this.foregroundGradientStartColor.toString()),h.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:h})}else t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(tp)}get lineWidth(){return this.scale*this.properties.getValue(ap)}get fillLevel(){return this.properties.getValue(rp)}get horizontalFill(){return this.properties.getValue(op)}get lineColor(){return this.properties.getValue(np)}get lineStyle(){return this.properties.getValue(lp)}get gradient(){return this.properties.getValue(sp)}get backgroundGradientStartColor(){return this.properties.getValue(ep)}get foregroundGradientStartColor(){return this.properties.getValue(ip)}};var hp="auto_size",cp="crop_bottom",pp="crop_left",dp="crop_right",up="crop_top",gp="degree",mp="flip_horizontal",fp="flip_vertical",xy="height",wp="image_file",xp="no_animation",Gs="permutation_matrix",yp="stretch_to_fit",Pp="transparency",yy="width",Py=[[1,0],[0,1]],bp=[0,90,180,270],by=[[-1,0],[0,1]],vy=[[1,0],[0,-1]];function vp(p){return p[0][0]===1&&p[0][1]===0&&p[1][0]===0&&p[1][1]===1}function Rp(p){return Math.round(p*1e4)/1e4}function Ry(p){let t=p*Math.PI/180,e=Rp(Math.cos(t)),i=Rp(Math.sin(t));return[[e,-i],[i,e]]}function _y(p,t){return[[p[0][0]*t[0][0]+p[0][1]*t[1][0],p[0][0]*t[0][1]+p[0][1]*t[1][1]],[p[1][0]*t[0][0]+p[1][1]*t[1][0],p[1][0]*t[0][1]+p[1][1]*t[1][1]]]}function Ty(p){return p.map(t=>t.map(e=>Math.round(e)))}function Sy(p,t,e){let[[i,r],[s,o]]=e,a=[[0,0],[p-1,0],[p-1,t-1],[0,t-1]].map(([x,_])=>[i*x+r*_,s*x+o*_]),l=a.map(x=>x[0]),h=a.map(x=>x[1]),c=Math.min(...l),d=Math.min(...h),g=Math.max(...l),w=Math.max(...h);return{width:Math.round(g-c),height:Math.round(w-d),a:i,b:s,c:r,d:o,e:-c,f:-d}}var Ar=class extends M{currentImageFile;imageElement;imageSnapshot;imageLoading=!1;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new f(hp,!0)),this.properties.add(new P(cp,0)),this.properties.add(new P(pp,0)),this.properties.add(new P(dp,0)),this.properties.add(new P(up,0)),this.properties.add(new T(wp)),this.properties.add(new T(xp)),this.properties.add(new Ge(Gs,Py)),this.properties.add(new P(gp,0)),this.properties.add(new f(mp,!1)),this.properties.add(new f(fp,!1)),this.properties.add(new f(yp,!1)),this.properties.add(new f(Pp,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.triggerImageLoad(),this.addPropertyListener(gp,(t,e)=>{let i=bp[t]-bp[e];this.applyPermutationDelta(Ry(i))}),this.addPropertyListener(mp,()=>{this.applyPermutationDelta(by)}),this.addPropertyListener(fp,()=>{this.applyPermutationDelta(vy)})}applyPermutationDelta(t){let e=Ty(_y(t,this.permutationMatrix));this.properties.setValue(Gs,e),this.imageElement&&this.imageLoaded&&(this.snapshotImage(this.imageElement),this.applyAutoSize()),this.requestRepaint()}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}applyAutoSize(){if(this.autoSize&&!this.stretchToFit&&this.imageSnapshot){let t=this.getCropRegion(this.imageSnapshot);this.properties.setValue(yy,t.width),this.properties.setValue(xy,t.height)}}getCropRegion(t){let e=t.width,i=t.height,r=this.cropTop>i?0:this.cropTop,s=this.cropLeft>e?0:this.cropLeft,o=i-r-this.cropBottom<0?0:this.cropBottom,n=e-s-this.cropRight<0?0:this.cropRight;return{x:s,y:r,width:e-s-n,height:i-r-o}}draw(t){if(this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.imageLoading&&this.imageSnapshot)this.drawSource(t,this.imageSnapshot,this.imageSnapshot);else if(this.imageLoaded)if(this.noAnimation)this.drawSource(t,this.imageSnapshot,this.imageSnapshot);else{let e=vp(this.permutationMatrix)?this.imageElement:this.renderOriented(this.imageElement,this.imageElement.naturalWidth,this.imageElement.naturalHeight);this.drawSource(t,e,this.imageSnapshot)}else this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height))}drawSource(t,e,i){let r=this.stretchToFit?this.getStretchedSourceRect(i):this.getUnstretchedSourceRect(i);r&&(this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,r.destWidth,r.destHeight)),t.ctx.drawImage(e,r.sx,r.sy,r.sw,r.sh,this.x,this.y,r.destWidth,r.destHeight))}getUnstretchedSourceRect(t){let e=this.getCropRegion(t);if(!(e.width<=0||e.height<=0))return{sx:e.x,sy:e.y,sw:e.width,sh:e.height,destWidth:e.width,destHeight:e.height}}getStretchedSourceRect(t){let e=this.width+this.cropLeft+this.cropRight,i=this.height+this.cropTop+this.cropBottom;if(e<=0||i<=0)return;let r=t.width/e,s=t.height/i;return{sx:this.cropLeft*r,sy:this.cropTop*s,sw:this.width*r,sh:this.height*s,destWidth:this.width,destHeight:this.height}}triggerImageLoad(){if(this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile){this.currentImageFile=this.imageFile;let t=this.imageElement;this.display.getImageLoader().load(this.resolvePath(this.imageFile)).then(e=>{t.src=e})}}snapshotImage(t){this.imageSnapshot=this.renderOriented(t,t.naturalWidth,t.naturalHeight)}renderOriented(t,e,i){let r=document.createElement("canvas"),s=r.getContext("2d"),o=this.permutationMatrix;if(vp(o))r.width=e,r.height=i,s.drawImage(t,0,0);else{let n=Sy(e,i,o);r.width=n.width,r.height=n.height,s.setTransform(n.a,n.b,n.c,n.d,n.e,n.f),s.drawImage(t,0,0)}return r}get transparency(){return this.properties.getValue(Pp)}get imageFile(){return this.properties.getValue(wp)}get noAnimation(){return this.properties.getValue(xp)}get autoSize(){return this.properties.getValue(hp)}get stretchToFit(){return this.properties.getValue(yp)}get cropTop(){return this.properties.getValue(up)}get cropBottom(){return this.properties.getValue(cp)}get cropLeft(){return this.properties.getValue(pp)}get cropRight(){return this.properties.getValue(dp)}get permutationMatrix(){return this.properties.getValue(Gs)}};function _p(p,t,e,i,r,s,o){let n=1*e,a=t.y+n/2,l=t.x+n/2,h=t.y+t.height-n+n/2,c=t.x+t.width-n+n/2;p.strokePath({color:i,path:new R(c,h).lineTo(c,a).moveTo(c,h).lineTo(l,h)}),p.strokePath({color:r,path:new R(c-n,h-n).lineTo(c-n,a+n).moveTo(c-n,h-n).lineTo(l+n,h-n)}),p.strokePath({color:s,path:new R(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,h-n)}),p.strokePath({color:o,path:new R(l+n,a+n).lineTo(c-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)})}function Ve(p,t,e){_p(p,t,e,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST)}function Or(p,t,e){_p(p,t,e,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER)}function Er(p,t,e,i,r=m.BLACK){let s=3*e,o={x:t.x+s,y:t.y+s,width:t.width-2*s,height:t.height-2*s},n=i==="left"||i==="right",a=n?Math.min(o.width,o.height/2):Math.min(o.height,o.width/2);n?o.x+=(o.width-a)/2:o.y+=(o.height-a)/2,a=Math.max(a,1);let l;switch(i){case"up":l={x:o.x+o.width/2,y:o.y};break;case"down":l={x:o.x+o.width/2,y:o.y+a};break;case"left":l={x:o.x,y:o.y+o.height/2};break;case"right":l={x:o.x+a,y:o.y+o.height/2};break}let h;switch(i){case"up":h=new R(l.x,l.y).lineTo(l.x-a,l.y+a).lineTo(l.x+a,l.y+a).closePath();break;case"down":h=new R(l.x,l.y).lineTo(l.x-a,l.y-a).lineTo(l.x+a,l.y-a).closePath();break;case"left":h=new R(l.x,l.y).lineTo(l.x+a,l.y-a).lineTo(l.x+a,l.y+a).closePath();break;case"right":h=new R(l.x,l.y).lineTo(l.x-a,l.y-a).lineTo(l.x-a,l.y+a).closePath();break}p.fillPath({color:r,path:h})}var Tp="auto_size",$s="font",Sp="horizontal_alignment",Lp="show_scrollbar",Cp="vertical_alignment",Ap="wrap_words",Ly=16,Cy=new m(243,243,243),Op=new m(232,232,231),Ep=150,Mr=class extends M{scrollOffset=0;maxScroll=0;dragRange;grabStartOffset;actionTimeout;upPressed=!1;downPressed=!1;thumbRegion;upRegion;downRegion;trackAboveRegion;trackBelowRegion;constructor(t,e){super(t,e),this.properties.add(new f(Tp)),this.properties.add(new H($s)),this.properties.add(new P(Sp)),this.properties.add(new f(Lp)),this.properties.add(new P(Cp)),this.properties.add(new f(Ap))}init(){this.thumbRegion={id:`${this.wuid}-scrollbar-thumb`,mouseDown:()=>{this.grabStartOffset=this.scrollOffset},grab:t=>{let e=this.maxScroll*t.dy/(this.dragRange||1);this.setScrollOffset((this.grabStartOffset??0)+e)},tooltip:()=>this.tooltip},this.upRegion={id:`${this.wuid}-scrollbar-up`,mouseDown:()=>{this.upPressed=!0,this.stepScrollRepeatedly(-1)},mouseUp:()=>this.endScrollAction(()=>this.upPressed=!1),mouseOut:()=>this.endScrollAction(()=>this.upPressed=!1),tooltip:()=>this.tooltip},this.downRegion={id:`${this.wuid}-scrollbar-down`,mouseDown:()=>{this.downPressed=!0,this.stepScrollRepeatedly(1)},mouseUp:()=>this.endScrollAction(()=>this.downPressed=!1),mouseOut:()=>this.endScrollAction(()=>this.downPressed=!1),tooltip:()=>this.tooltip},this.trackAboveRegion={id:`${this.wuid}-scrollbar-track-above`,mouseDown:()=>this.pageScrollRepeatedly(-1),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip},this.trackBelowRegion={id:`${this.wuid}-scrollbar-track-below`,mouseDown:()=>this.pageScrollRepeatedly(1),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip}}destroy(){window.clearTimeout(this.actionTimeout)}setScrollOffset(t){this.scrollOffset=Math.min(Math.max(t,0),this.maxScroll),this.requestRepaint()}stepScrollRepeatedly(t){window.clearTimeout(this.actionTimeout),this.setScrollOffset(this.scrollOffset+t*this.font.height*1.2),this.actionTimeout=window.setTimeout(()=>this.stepScrollRepeatedly(t),Ep)}pageScrollRepeatedly(t){window.clearTimeout(this.actionTimeout),this.setScrollOffset(this.scrollOffset+t*this.height),this.actionTimeout=window.setTimeout(()=>this.pageScrollRepeatedly(t),Ep)}endScrollAction(t){window.clearTimeout(this.actionTimeout),t?.(),this.requestRepaint()}drawHolder(t){if(this.autoSize){let e=this.properties.getValue($s).scale(1);this.customSize=t.measureText(this.text,e,!0)}super.drawHolder(t)}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.wrapWords?this.drawWrapped(t):this.drawText(t)}drawText(t){let e=t.ctx,i={...this.area},r=t.measureText(this.text,this.font,!0);e.font=this.font.getFontString(),e.textBaseline="alphabetic";let o=e.measureText(this.text).fontBoundingBoxAscent,n={x:i.x,y:i.y,width:r.width,height:r.height};this.horizAlignment===0||(this.horizAlignment===1?n.x+=(i.width-r.width)/2:this.horizAlignment===2&&(n.x+=i.width-r.width)),this.vertAlignment===0||i.height<=r.height||(this.vertAlignment===1?n.y+=i.height/2-r.height/2:this.vertAlignment===2&&(n.y+=i.height-r.height)),e.textAlign="start",e.textBaseline="top",n.y+=n.height/2-o/2,e.save(),e.beginPath();let a=this.area;e.rect(a.x,a.y,a.width,a.height),e.clip(),e.fillStyle=this.foregroundColor.toString(),e.fillText(this.text,n.x,n.y),e.restore()}drawWrapped(t){let e=t.ctx,i=t.measureText("Mg",this.font).height,r=this.wrapText(t,this.text,this.width),s=r.length*i,o=this.width,n=!1,a=Ly*this.scale;this.showScrollbar&&s>this.height&&(n=!0,o=Math.max(0,this.width-a),r=this.wrapText(t,this.text,o),s=r.length*i),this.maxScroll=Math.max(0,s-this.height),this.scrollOffset=Math.min(Math.max(this.scrollOffset,0),this.maxScroll),e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let l=this.y;this.height>s&&(this.vertAlignment===1?l+=(this.height-s)/2:this.vertAlignment===2&&(l+=this.height-s)),l-=this.scrollOffset,e.save(),e.beginPath(),e.rect(this.x,this.y,o,this.height),e.clip();for(let h of r){let c=this.x;if(this.horizAlignment===1){let d=e.measureText(h).width;c=this.x+(o-d)/2}else if(this.horizAlignment===2){let d=e.measureText(h).width;c=this.x+(o-d)}e.fillText(h,c,l),l+=i}e.restore(),n&&this.drawScrollbar(t,{x:this.x+o,y:this.y,width:a,height:this.height})}drawScrollbar(t,e){let{scale:i}=this;t.fillRect({...e,color:Cy});let r=Math.min(e.width,e.height/2);this.drawScrollButton(t,"up",{x:e.x,y:e.y,width:e.width,height:r}),this.drawScrollButton(t,"down",{x:e.x,y:e.y+e.height-r,width:e.width,height:r});let s=e.height-2*r,o=Math.min(1,this.height/(this.height+this.maxScroll)),n=Math.max(6*i,s*o);this.dragRange=s-n;let a=this.maxScroll>0?this.scrollOffset/this.maxScroll:0,l=e.y+r+this.dragRange*a,h={x:e.x,y:l,width:e.width,height:n};t.fillRect({...h,color:Op}),Ve(t,h,i),t.addHitRegion(this.thumbRegion).addRect(h.x,h.y,h.width,h.height);let c=e.y+r,d=e.y+e.height-r;t.addHitRegion(this.trackAboveRegion).addRect(e.x,c,e.width,l-c),t.addHitRegion(this.trackBelowRegion).addRect(e.x,l+n,e.width,d-(l+n))}drawScrollButton(t,e,i){let{scale:r}=this,s=e==="up"?this.upPressed:this.downPressed;t.fillRect({...i,color:Op}),s?Or(t,i,r):Ve(t,i,r);let o=e==="up"?this.upRegion:this.downRegion;t.addHitRegion(o).addRect(i.x,i.y,i.width,i.height),Er(t,i,r,e)}wrapText(t,e,i){let r=[];for(let s of e.replace(/\n$/,"").split(`
21
- `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[];for(;e.length;){let s;for(s=e.length;t.measureText(e.substr(0,s),this.font).width>i;s--);let o;if(s===e.length)o=e;else if(e[s]===" ")o=e.substr(0,s+1);else{let n=e.substr(0,s),a=0;for(;n.indexOf(" ",a)!==-1;a=n.indexOf(" ",a)+1);if(a)o=n.substr(0,a);else{let l=e.indexOf(" ");o=l===-1?e:e.substr(0,l)}}r.push(o),e=e.substr(o.length)}return r}get autoSize(){return this.properties.getValue(Tp)}get font(){return this.properties.getValue($s).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Sp)}get showScrollbar(){return this.properties.getValue(Lp)}get vertAlignment(){return this.properties.getValue(Cp)}get wrapWords(){return this.properties.getValue(Ap)}};var Mp="alpha",Vp="fill_level",Ip="horizontal_fill",Bp="line_color",Hp="line_style",Dp="line_width",he="points",Us="rotation_angle",Vr=class extends M{zeroDegreePoints=[];originPoints;updatingPoints=!1;constructor(t,e){super(t,e),this.properties.add(new P(Mp,255)),this.properties.add(new P(Dp)),this.properties.add(new C(Vp)),this.properties.add(new f(Ip)),this.properties.add(new S(Bp)),this.properties.add(new P(Hp)),this.properties.add(new Wt(he,[])),this.properties.add(new C(Us))}init(){this.addPropertyListener("x",(t,e)=>{let i=t-e,r=this.properties.getValue(he);this.setPointsInternal(ht(r,i,0)),this.zeroDegreePoints=ht(this.zeroDegreePoints,i,0),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=t-e,r=this.properties.getValue(he);this.setPointsInternal(ht(r,0,i)),this.zeroDegreePoints=ht(this.zeroDegreePoints,0,i),this.requestRepaint()}),this.addPropertyListener(he,()=>{this.updatingPoints||(this.updateZeroDegreePoints(),this.requestRepaint())}),this.updateZeroDegreePoints(),this.addPropertyListener(Us,()=>this.requestRepaint())}setPointsInternal(t){this.updatingPoints=!0;try{this.properties.setValue(he,t)}finally{this.updatingPoints=!1}}updateZeroDegreePoints(){let t=this.properties.getValue(he),e=this.rotationAngle;this.zeroDegreePoints=e?ge(t,-e):t}autoScale(t,e){this.originPoints||(this.originPoints=this.properties.getValue(he)),M.prototype.autoScale.call(this,t,e);let i=Math.min(...this.originPoints.map(l=>l.x)),r=Math.min(...this.originPoints.map(l=>l.y)),s=Math.round(i*t),o=Math.round(r*e),n=vi(t,e,this.scaleOptions),a=this.originPoints.map(l=>({x:Math.trunc((l.x-i)*n.widthRatio)+s,y:Math.trunc((l.y-r)*n.heightRatio)+o}));this.setPointsInternal(a),this.updateZeroDegreePoints()}draw(t){let{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;let i=R.fromPoints(fi(this.points)).closePath();if(!this.transparent){let r=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:r})}this.lineWidth&&(this.lineStyle===0?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):this.lineStyle===2?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,r=this.width,s=this.height;this.horizontalFill?r*=this.fillLevel/100:(s*=this.fillLevel/100,i+=this.height-s),t.ctx.save();let o=this.x-this.lineWidth/2,n=i-this.lineWidth/2,a=r+this.lineWidth,l=s+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,n,a,l),t.ctx.clip();let h=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:h}),t.ctx.restore()}get alpha(){return this.properties.getValue(Mp)}get lineWidth(){return this.scale*this.properties.getValue(Dp)}get fillLevel(){return this.properties.getValue(Vp)}get horizontalFill(){return this.properties.getValue(Ip)}get lineColor(){return this.properties.getValue(Bp)}get lineStyle(){return this.properties.getValue(Hp)}get points(){let t=this.rotationAngle,e=t?ge(this.zeroDegreePoints,t):this.zeroDegreePoints;return re(e,this.scale)}get rotationAngle(){return this.properties.getValue(Us)}};var Wp="alpha",kp="arrows",Np="arrow_length",Fp="fill_arrow",Gp="fill_level",$p="horizontal_fill",Up="line_width",ce="points",Ys="rotation_angle",Ir=class extends M{zeroDegreePoints=[];originPoints;updatingPoints=!1;constructor(t,e){super(t,e),this.properties.add(new P(Wp,255)),this.properties.add(new P(Up)),this.properties.add(new C(Gp)),this.properties.add(new f($p)),this.properties.add(new Wt(ce,[])),this.properties.add(new P(Np)),this.properties.add(new f(Fp)),this.properties.add(new P(kp)),this.properties.add(new C(Ys))}init(){this.addPropertyListener("x",(t,e)=>{let i=t-e,r=this.properties.getValue(ce);this.setPointsInternal(ht(r,i,0)),this.zeroDegreePoints=ht(this.zeroDegreePoints,i,0),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=t-e,r=this.properties.getValue(ce);this.setPointsInternal(ht(r,0,i)),this.zeroDegreePoints=ht(this.zeroDegreePoints,0,i),this.requestRepaint()}),this.addPropertyListener(ce,()=>{this.updatingPoints||(this.updateZeroDegreePoints(),this.requestRepaint())}),this.updateZeroDegreePoints(),this.addPropertyListener(Ys,()=>this.requestRepaint())}setPointsInternal(t){this.updatingPoints=!0;try{this.properties.setValue(ce,t)}finally{this.updatingPoints=!1}}updateZeroDegreePoints(){let t=this.properties.getValue(ce),e=this.rotationAngle;this.zeroDegreePoints=e?ge(t,-e):t}autoScale(t,e){this.originPoints||(this.originPoints=this.properties.getValue(ce)),M.prototype.autoScale.call(this,t,e);let i=Math.min(...this.originPoints.map(l=>l.x)),r=Math.min(...this.originPoints.map(l=>l.y)),s=Math.round(i*t),o=Math.round(r*e),n=vi(t,e,this.scaleOptions),a=this.originPoints.map(l=>({x:Math.trunc((l.x-i)*n.widthRatio)+s,y:Math.trunc((l.y-r)*n.heightRatio)+o}));this.setPointsInternal(a),this.updateZeroDegreePoints()}draw(t){let e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.alarmSensitiveBackgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.getFillBounds(),i=e.y,r=e.width,s=e.height;this.horizontalFill?r*=this.fillLevel/100:(s*=this.fillLevel/100,i+=e.height-s),t.save(),t.beginPath(),t.rect(e.x,i,r,s),t.clip(),this.drawShape(t,this.alarmSensitiveForegroundColor),t.restore()}getFillBounds(){let t=this.points,e=t[0].x,i=t[0].x,r=t[0].y,s=t[0].y,o=a=>{e=Math.min(e,a.x),i=Math.max(i,a.x),r=Math.min(r,a.y),s=Math.max(s,a.y)};for(let a of t)o(a);if(this.arrows!==0&&t.length>=2){let a=t[0],l=t[t.length-1];if(this.arrows===2||this.arrows===3)for(let h of this.calculateArrowPoints(t[t.length-2],l))o(h);if(this.arrows===1||this.arrows===3)for(let h of this.calculateArrowPoints(t[1],a))o(h)}let n=this.lineWidth/2;return{x:e-n,y:r-n,width:i-e+this.lineWidth,height:s-r+this.lineWidth}}drawShape(t,e){let i=[...this.points];if(i.length>=2){let r=i[0],s=i[i.length-1];if(this.arrows===2||this.arrows===3){let o=this.calculateArrowPoints(i[i.length-2],s);this.fillArrow&&(i[i.length-1]=o[2]),o[2]=s,this.drawArrowhead(t,e,o,s)}if(this.arrows===1||this.arrows===3){let o=this.calculateArrowPoints(i[1],r);this.fillArrow&&(i[0]=o[2]),o[2]=r,this.drawArrowhead(t,e,o,r)}}t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let r=0;r<i.length;r++)r===0?t.moveTo(i[r].x,i[r].y):t.lineTo(i[r].x,i[r].y);t.stroke()}drawArrowhead(t,e,i,r){if(this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let s=0;s<i.length;s++)s===0?t.moveTo(i[s].x,i[s].y):t.lineTo(i[s].x,i[s].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(i[0].x,i[0].y),t.moveTo(r.x,r.y),t.lineTo(i[1].x,i[1].y),t.stroke()}calculateArrowPoints(t,e){let i=mi(e,t),r=Math.PI/10,s=new _t(this.arrowLength,i.theta-r),o=new _t(this.arrowLength,i.theta+r),n=new _t(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=Ht(s.toPoint(),e.x,e.y),l=Ht(o.toPoint(),e.x,e.y),h=Ht(n.toPoint(),e.x,e.y);return[a,l,h]}get alpha(){return this.properties.getValue(Wp)}get lineWidth(){return this.scale*this.properties.getValue(Up)}get fillLevel(){return this.properties.getValue(Gp)}get horizontalFill(){return this.properties.getValue($p)}get points(){let t=this.rotationAngle,e=t?ge(this.zeroDegreePoints,t):this.zeroDegreePoints,i=re(e,this.scale);return fi(i)}get rotationAngle(){return this.properties.getValue(Ys)}get arrows(){return this.properties.getValue(kp)}get fillArrow(){return this.properties.getValue(Fp)}get arrowLength(){return this.scale*this.properties.getValue(Np)}};var Yp="alpha",zp="bg_gradient_color",Xp="fg_gradient_color",qp="fill_level",Kp="gradient",jp="horizontal_fill",Zp="line_color",Jp="line_width",Qp="line_style",Br=class extends M{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(Yp,255)),this.properties.add(new S(zp)),this.properties.add(new S(Xp)),this.properties.add(new f(Kp)),this.properties.add(new P(Jp)),this.properties.add(new C(qp)),this.properties.add(new f(jp)),this.properties.add(new S(Zp)),this.properties.add(new P(Qp))}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){let e=this.alarmSensitiveBackgroundColor;if(this.gradient){let i=this.horizontalFill?this.x:this.x+this.width,r=this.horizontalFill?this.y+this.height:this.y,s=t.createLinearGradient(this.x,this.y,i,r);s.addColorStop(0,this.backgroundGradientStartColor.toString()),s.addColorStop(1,e.toString()),t.fillRect({...this.area,gradient:s})}else t.fillRect({...this.area,color:e})}this.lineWidth&&(this.lineStyle===0?t.strokeRect({...this.area,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0}):this.lineStyle===1?t.strokeRect({...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){let e=D(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let r=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,r,e.height)}else{let r=e.height*(this.fillLevel/100),s=e.y+e.height-r;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();let i=this.alarmSensitiveForegroundColor;if(this.gradient){let r=this.horizontalFill?e.x:e.x+e.width,s=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,r,s);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect({...e,gradient:o})}else t.fillRect({...e,color:i});t.ctx.restore()}get alpha(){return this.properties.getValue(Yp)}get lineWidth(){return this.scale*this.properties.getValue(Jp)}get fillLevel(){return this.properties.getValue(qp)}get horizontalFill(){return this.properties.getValue(jp)}get lineColor(){return this.properties.getValue(Zp)}get lineStyle(){return this.properties.getValue(Qp)}get gradient(){return this.properties.getValue(Kp)}get backgroundGradientStartColor(){return this.properties.getValue(zp)}get foregroundGradientStartColor(){return this.properties.getValue(Xp)}};var td="alpha",ed="bg_gradient_color",id="corner_width",rd="corner_height",sd="fg_gradient_color",od="fill_level",nd="gradient",ad="horizontal_fill",ld="line_color",hd="line_width",cd="line_style",Hr=class extends M{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(td,255)),this.properties.add(new S(ed)),this.properties.add(new S(sd)),this.properties.add(new f(nd)),this.properties.add(new P(hd)),this.properties.add(new C(od)),this.properties.add(new f(ad)),this.properties.add(new S(ld)),this.properties.add(new P(id)),this.properties.add(new P(rd)),this.properties.add(new P(cd))}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){let e=this.alarmSensitiveBackgroundColor;if(this.gradient){let i=this.horizontalFill?this.x:this.x+this.width,r=this.horizontalFill?this.y+this.height:this.y,s=t.createLinearGradient(this.x,this.y,i,r);s.addColorStop(0,this.backgroundGradientStartColor.toString()),s.addColorStop(1,e.toString()),t.fillRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:s})}else t.fillRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e})}this.lineWidth&&(this.lineStyle===0?t.strokeRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0}):this.lineStyle===1?t.strokeRect({...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){let e=this.cornerWidth/2,i=this.cornerHeight/2,r=D(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let o=r.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(r.x,r.y,o,r.height)}else{let o=r.height*(this.fillLevel/100),n=r.y+r.height-o;t.ctx.beginPath(),t.ctx.rect(r.x,n,r.width,r.height)}t.ctx.clip();let s=this.alarmSensitiveForegroundColor;if(this.gradient){let o=this.horizontalFill?r.x:r.x+r.width,n=this.horizontalFill?r.y+r.height:r.y,a=t.createLinearGradient(r.x,r.y,o,n);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,s.toString()),t.fillRect({...r,rx:e,ry:i,gradient:a})}else t.fillRect({...r,rx:e,ry:i,color:s});t.ctx.restore()}get alpha(){return this.properties.getValue(td)}get lineWidth(){return this.scale*this.properties.getValue(hd)}get fillLevel(){return this.properties.getValue(od)}get horizontalFill(){return this.properties.getValue(ad)}get lineColor(){return this.properties.getValue(ld)}get lineStyle(){return this.properties.getValue(cd)}get gradient(){return this.properties.getValue(nd)}get cornerWidth(){return this.scale*this.properties.getValue(id)}get cornerHeight(){return this.scale*this.properties.getValue(rd)}get backgroundGradientStartColor(){return this.properties.getValue(ed)}get foregroundGradientStartColor(){return this.properties.getValue(sd)}};var pd="bitReverse",dd="effect_3d",ud="horizontal",gd="led_border",md="led_border_color",fd="led_packed",wd="numBits",xd="off_color",yd="on_color",Pd="startBit",bd="square_led",Dr=class extends M{constructor(t,e){super(t,e),this.properties.add(new f(pd)),this.properties.add(new f(dd)),this.properties.add(new f(ud)),this.properties.add(new P(wd)),this.properties.add(new S(xd)),this.properties.add(new S(yd)),this.properties.add(new P(Pd)),this.properties.add(new f(bd)),this.properties.add(new P(gd,3)),this.properties.add(new S(md,m.DARK_GRAY)),this.properties.add(new f(fd,!1))}getLedColor(t){let e=!1;if(this.value!==void 0)for(let i=this.startBit;i<this.startBit+this.numBits;i++){let r=0;if(this.bitReverse?r=i-this.startBit:r=this.numBits-1-(i-this.startBit),r===t){e=(this.value>>i&1)>0;break}}return e?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=D(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,r;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),r=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),r=i);let s=0;i>e.height||this.squareLed?s=e.height:s=i;for(let o=0;o<this.numBits;o++)if(this.squareLed){let n={x:e.x+o*r,y:e.y,width:i,height:s};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{let n=Math.min(i,s),a={x:e.x+o*r,y:e.y,width:n,height:n};this.effect3d?this.drawCircle3d(t,a,o):this.drawCircle2d(t,a,o)}}drawVertical(t,e){let i,r;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),r=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),r=i);let s=0;i>e.width||this.squareLed?s=e.width:s=i;for(let o=0;o<this.numBits;o++)if(this.squareLed){let n={x:e.x,y:e.y+o*r,width:s,height:i};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{let n=Math.min(s,i),a={x:e.x,y:e.y+o*r,width:n,height:n};this.effect3d?this.drawCircle3d(t,a,o):this.drawCircle2d(t,a,o)}}drawCircle2d(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o=e.width/2,n=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,n-=this.ledBorder/2),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:this.getLedColor(i)}),t.strokeEllipse({cx:r,cy:s,rx:o,ry:n,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o=e.width/2,n=e.height/2;t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:m.WHITE});let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,gradient:a});let l=e.width-2*this.ledBorder,h=e.height-2*this.ledBorder;o=l/2,n=h/2,t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:this.getLedColor(i)}),a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),a.addColorStop(0,m.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,gradient:a})}drawSquare2d(t,e,i){let r=Bt(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect({...r,color:this.getLedColor(i)}),t.strokeRect({...r,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawSquare3d(t,e,i){t.fillRect({...e,color:this.ledBorderColor});let r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);r.addColorStop(0,"rgba(0,0,0,0.078)"),r.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:r,path:new R(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)}),r=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),r.addColorStop(0,"rgba(0,0,0,0.078)"),r.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:r,path:new R(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)}),r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),r.addColorStop(0,"rgba(255,255,255,0.078)"),r.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:r,path:new R(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)}),r=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),r.addColorStop(0,"rgba(255,255,255,0.078)"),r.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:r,path:new R(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)});let s=e.x+this.ledBorder,o=e.y+this.ledBorder,n=e.width-2*this.ledBorder,a=e.height-2*this.ledBorder,l=this.getLedColor(i);t.fillRect({x:s,y:o,width:n,height:a,color:l}),r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),r.addColorStop(0,"rgba(255,255,255,0.784)"),r.addColorStop(1,l.withAlpha(0).toString()),t.fillRect({x:s,y:o,width:n,height:a,gradient:r})}get bitReverse(){return this.properties.getValue(pd)}get horizontal(){return this.properties.getValue(ud)}get numBits(){return this.properties.getValue(wd)}get startBit(){return this.properties.getValue(Pd)}get ledPacked(){return this.properties.getValue(fd)}get ledBorder(){return this.scale*this.properties.getValue(gd)}get ledBorderColor(){return this.properties.getValue(md)}get offColor(){return this.properties.getValue(xd)}get onColor(){return this.properties.getValue(yd)}get effect3d(){return this.properties.getValue(dd)}get squareLed(){return this.properties.getValue(bd)}};var vd=new m(100,100,100),Ay=16,Oy=8,Ey=5,My=-1,Rd="color_hi",_d="color_hihi",Td="color_lo",Sd="color_lolo",Ld="effect_3d",Cd="font",Ad="value_label_format",Od="level_hi",Ed="level_hihi",Md="level_lo",Vd="level_lolo",Id="limits_from_pv",Bd="log_scale",Hd="major_tick_step_hint",Dd="minimum",Wd="maximum",kd="needle_color",Nd="ramp_gradient",Fd="scale_font",Gd="scale_format",$d="show_minor_ticks",Ud="show_markers",Yd="show_scale",Vy="scale_options",Wr=225,zd=315;var kr=class extends M{constructor(t,e){super(t,e),this.properties.add(new S(Rd)),this.properties.add(new S(_d)),this.properties.add(new S(Td)),this.properties.add(new S(Sd)),this.properties.add(new f(Ld)),this.properties.add(new H(Cd)),this.properties.add(new C(Od)),this.properties.add(new C(Ed)),this.properties.add(new C(Md)),this.properties.add(new C(Vd)),this.properties.add(new f(Bd)),this.properties.add(new f(Id,!0)),this.properties.add(new P(Hd,50)),this.properties.add(new C(Wd)),this.properties.add(new C(Dd)),this.properties.add(new S(kd)),this.properties.add(new f(Nd)),this.properties.add(new H(Fd)),this.properties.add(new T(Gd)),this.properties.add(new f($d,!0)),this.properties.add(new f(Ud,!0)),this.properties.add(new f(Yd,!0)),this.properties.add(new T(Ad)),this.properties.add(new tt(Vy,new J(!0,!0,!0)))}draw(t){let e;this.limitsFromPv&&this.pv&&!this.pv.disconnected?e={min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:e={min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(e.min=Math.max(.1,e.min),e.max<=e.min&&(e.max=e.min+100));let i=Math.min(this.width,this.height),r=i;this.drawBackground(t,i,r),this.showRamp&&this.drawRamp(t,i,r,e),this.showScale&&this.drawScale(t,i,r,e),this.drawLabel(t,i,r,e),this.drawNeedle(t,i,r,e),this.drawNeedleCenter(t,i,r)}drawBackground(t,e,i){if(t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2,ry:i/2,color:m.GRAY}),this.effect3d){let s=t.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);s.addColorStop(0,vd.toString()),s.addColorStop(1,m.WHITE.toString()),t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2,ry:i/2,gradient:s})}let r=(this.effect3d?2:1)*this.scale;if(t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2-r,ry:i/2-r,color:this.backgroundColor}),this.effect3d){let s=e/2,o=9.5/10,n=1/2,a=8.5/10,l=G(0),h=G(35),c={x:Math.floor(this.x+e/2-s*a*Math.cos(l)),y:Math.floor(this.y+i/2-s*o),width:Math.floor(2*s*a*Math.cos(l)),height:Math.floor(s*o+s*n)},d=t.createLinearGradient(c.x,c.y,c.x,c.y+c.height);d.addColorStop(0,m.WHITE.withAlpha(90/255).toString()),d.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:c.x+c.width/2,cy:c.y+c.height/2,rx:c.width/2,ry:c.height/2,gradient:d}),c={x:Math.floor(this.x+e/2-s*a*Math.sin(h)),y:Math.floor(Math.ceil(this.y+i/2+s*n)),width:Math.floor(2*s*a*Math.sin(h)),height:Math.floor(Math.ceil(s*o-s*n))},d=t.createLinearGradient(c.x,c.y,c.x,c.y+c.height),d.addColorStop(0,m.WHITE.withAlpha(0).toString()),d.addColorStop(1,m.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:c.x+c.width/2,cy:c.y+c.height/2,rx:c.width/2,ry:c.height/2,gradient:d})}}drawRamp(t,e,i,r){let s=D({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o={...s};o.width=Math.min(s.width,s.height),o.height=s.width;let n=new Zt(10*this.scale,225,315);n.lolo=r.lolo,n.loloColor=this.colorLoLo,n.lo=r.lo,n.loColor=this.colorLo,n.hi=r.hi,n.hiColor=this.colorHi,n.hihi=r.hihi,n.hihiColor=this.colorHiHi,n.minimum=r.min,n.maximum=r.max,n.effect3d=this.effect3d,n.gradient=this.rampGradient,n.logScale=this.logScale,n.draw(t,s,o)}drawScale(t,e,i,r){let s=new Jt(Wr,zd,"inward");s.minimum=r.min,s.maximum=r.max,s.logScale=this.logScale,s.showMinorTicks=this.showMinorTicks,s.majorTickStepHint=this.majorTickStepHint*this.scale,s.majorTickLength=this.majorTickLength,s.minorTickLength=this.minorTickLength,s.majorLineWidth=2*this.scale,s.minorLineWidth=1*this.scale,s.format=this.scaleFormat,s.font=this.scaleFont,s.foregroundColor=this.foregroundColor,s.draw(t,{x:this.x,y:this.y,width:e,height:i})}drawLabel(t,e,i,r){let s=Y.ARIAL_12_BOLD.scale(this.scale);if(this.value!==void 0){let o=this.formatLabelValue(this.value,r),n=t.measureText(o,s);t.fillText({x:this.x+e/2-n.width/2,y:this.y+i*7/8-n.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:s,text:o})}}drawNeedle(t,e,i,r){let s=this.x+e/2,o=this.y+i/2,n;if(this.value!==void 0){let _=this.getValueInRange(this.value,r);n=360-this.getValuePosition(_,r),r.max>r.min?_>r.max?n+=10:_<r.min&&(n-=10):_>r.min?n-=10:_<r.max&&(n+=10)}else n=360-this.getValuePosition((r.min+r.max)/2,r);let a=G(n),{scale:l}=this,{needleDiameter:h,majorTickLength:c,gapBetweenNeedleScale:d}=this,g=Tt(s,o-h/2+3*l,s,o,a),w=Tt(s+e/2-c-d,o,s,o,a),x=Tt(s,o+h/2-3*l,s,o,a);t.fillPath({color:this.needleColor,path:new R(g.x,g.y).lineTo(w.x,w.y).lineTo(x.x,x.y).closePath()})}drawNeedleCenter(t,e,i){let{needleDiameter:r}=this,s=this.x+e/2,o=this.y+i/2,n=r/2,a=r/2;if(this.effect3d){let l=t.createLinearGradient(s-n,o-a,s+n,o+a);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,vd.toString()),t.fillEllipse({cx:s,cy:o,rx:n,ry:a,gradient:l})}else t.fillEllipse({cx:s,cy:o,rx:n,ry:a,color:m.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i=360-(zd-Wr),r;return this.logScale?r=Wr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*i:r=Wr-(t-e.min)/(e.max-e.min)*i,r<0&&(r+=360),r}formatLabelValue(t,e){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let i=jt(e.min,e.max);return new rt(i).format(t)}}get needleDiameter(){return this.scale*Ay}get majorTickLength(){return this.scale*Oy}get minorTickLength(){return this.scale*Ey}get gapBetweenNeedleScale(){return this.scale*My}get colorLo(){return this.properties.getValue(Td)}get colorLoLo(){return this.properties.getValue(Sd)}get colorHi(){return this.properties.getValue(Rd)}get colorHiHi(){return this.properties.getValue(_d)}get effect3d(){return this.properties.getValue(Ld)}get font(){return this.properties.getValue(Cd).scale(this.scale)}get levelLo(){return this.properties.getValue(Md)}get levelLoLo(){return this.properties.getValue(Vd)}get levelHi(){return this.properties.getValue(Od)}get levelHiHi(){return this.properties.getValue(Ed)}get limitsFromPv(){return this.properties.getValue(Id)}get logScale(){return this.properties.getValue(Bd)}get majorTickStepHint(){return this.properties.getValue(Hd)}get minimum(){return this.properties.getValue(Dd)}get maximum(){return this.properties.getValue(Wd)}get needleColor(){return this.properties.getValue(kd)}get rampGradient(){return this.properties.getValue(Nd)}get scaleFont(){return this.properties.getValue(Fd).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Gd)}get showMinorTicks(){return this.properties.getValue($d)}get showRamp(){return this.properties.getValue(Ud)}get showScale(){return this.properties.getValue(Yd)}get valueLabelFormat(){return this.properties.getValue(Ad)}};var Xd="auto_size",qd="bit",Kd="data_type",Iy="height",jd="off_image",Zd="off_label",Jd="font",Qd="on_image",tu="on_label",eu="show_boolean_label",iu="stretch_to_fit",By="width",Nr=class extends M{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new f(Xd,!0)),this.properties.add(new P(qd)),this.properties.add(new P(Kd)),this.properties.add(new T(jd)),this.properties.add(new T(Zd)),this.properties.add(new T(Qd)),this.properties.add(new T(tu)),this.properties.add(new H(Jd)),this.properties.add(new f(eu)),this.properties.add(new f(iu,!1))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.onImage){let t=this.onImageElement;this.display.getImageLoader().load(this.resolvePath(this.onImage)).then(e=>{t.src=e})}if(this.offImage){let t=this.offImageElement;this.display.getImageLoader().load(this.resolvePath(this.offImage)).then(e=>{t.src=e})}}get booleanValue(){return this.bit<0?!!this.value:this.value!==void 0?(this.value>>this.bit&1)>0:!1}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}applyAutoSize(){if(!this.autoSize||this.stretchToFit)return;let t=this.booleanValue?this.onImageElement:this.offImageElement,e=this.booleanValue?this.onImageLoaded:this.offImageLoaded;t&&e&&(this.properties.setValue(By,t.naturalWidth),this.properties.setValue(Iy,t.naturalHeight))}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}draw(t){let e=this.booleanValue?this.onImageElement:this.offImageElement,i=this.booleanValue?this.onImageLoaded:this.offImageLoaded,r=this.stretchToFit?this.width:e?.naturalWidth,s=this.stretchToFit?this.height:e?.naturalHeight;this.transparent||t.fillRect({x:this.x,y:this.y,width:i?r:this.width,height:i?s:this.height,color:this.backgroundColor}),e&&i&&t.ctx.drawImage(e,this.x,this.y,r,s),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 autoSize(){return this.properties.getValue(Xd)}get stretchToFit(){return this.properties.getValue(iu)}get bit(){return this.properties.getValue(qd)}get dataType(){return this.properties.getValue(Kd)}get showBooleanLabel(){return this.properties.getValue(eu)}get font(){return this.properties.getValue(Jd).scale(this.scale)}get offLabel(){return this.properties.getValue(Zd)}get offImage(){return this.properties.getValue(jd)}get onLabel(){return this.properties.getValue(tu)}get onImage(){return this.properties.getValue(Qd)}};var Fr=class{constructor(t,e){this.widget=e;this.id=t}id;selection;grabStart;mouseDown(t){this.grabStart=t}grab(t){this.grabStart&&(this.selection={...this.grabStart.point,width:t.dx,height:t.dy},this.widget.requestRepaint())}grabEnd(){let{selection:t}=this;t&&t.width&&t.height&&this.widget.applyRubberBandZoom(t),this.selection=void 0,this.grabStart=void 0,this.widget.requestRepaint()}dblclick(){this.widget.resetZoom(),this.widget.requestRepaint()}};var ru="color_depth",Hy=0,Dy=1,Wy=2,ky=3,Ny=4,Fy=5,su="color_map",ou="crop_bottom",nu="crop_left",au="crop_right",lu="crop_top",hu="data_height",cu="data_width",pu="font",du="graph_area_height",uu="graph_area_width",Gy=25,gu="horizon_profile_x_pv_name",mu="horizon_profile_y_pv_name",fu="vertical_profile_x_pv_name",wu="vertical_profile_y_pv_name",xu="maximum",yu="minimum",Pu="rgb_mode",bu="show_ramp",vu="x_axis_axis_color",Ru="x_axis_axis_title",_u="x_axis_major_tick_step_hint",Tu="x_axis_maximum",Su="x_axis_minimum",Lu="x_axis_scale_font",Cu="x_axis_show_minor_ticks",Au="x_axis_title_font",Ou="x_axis_visible",Eu="y_axis_axis_color",Mu="y_axis_axis_title",Vu="y_axis_major_tick_step_hint",Iu="y_axis_maximum",Bu="y_axis_minimum",Hu="y_axis_scale_font",Du="y_axis_show_minor_ticks",Wu="y_axis_title_font",ku="y_axis_visible",$y="scale_options",Gr=class extends M{region;xScale;yScale;graphAreaX=0;graphAreaY=0;renderedGraphAreaWidth=0;renderedGraphAreaHeight=0;_effectiveCropLeft;_effectiveCropRight;_effectiveCropTop;_effectiveCropBottom;_effectiveXAxisMinimum;_effectiveXAxisMaximum;_effectiveYAxisMinimum;_effectiveYAxisMaximum;originalState;constructor(t,e){super(t,e),this.properties.add(new P(ru,Hy)),this.properties.add(new se(su)),this.properties.add(new P(ou)),this.properties.add(new P(nu)),this.properties.add(new P(au)),this.properties.add(new P(lu)),this.properties.add(new P(hu)),this.properties.add(new P(cu)),this.properties.add(new P(du)),this.properties.add(new P(uu)),this.properties.add(new T(gu)),this.properties.add(new T(mu)),this.properties.add(new T(fu)),this.properties.add(new T(wu)),this.properties.add(new H(pu)),this.properties.add(new C(xu)),this.properties.add(new C(yu)),this.properties.add(new f(Pu,!1)),this.properties.add(new f(bu)),this.properties.add(new S(vu)),this.properties.add(new T(Ru)),this.properties.add(new P(_u)),this.properties.add(new C(Tu)),this.properties.add(new C(Su)),this.properties.add(new H(Lu)),this.properties.add(new f(Cu)),this.properties.add(new H(Au)),this.properties.add(new f(Ou)),this.properties.add(new S(Eu)),this.properties.add(new T(Mu)),this.properties.add(new P(Vu)),this.properties.add(new C(Iu)),this.properties.add(new C(Bu)),this.properties.add(new H(Hu)),this.properties.add(new f(Du)),this.properties.add(new H(Wu)),this.properties.add(new f(ku)),this.properties.add(new tt($y,new J(!0,!0,!0)))}init(){this.region=new Fr(`${this.wuid}-graph`,this)}draw(t){let{scale:e}=this,i=this.area;this.borderAlarmSensitive&&(i=D(i,2*e));let r=this.alarmSensitiveBackgroundColor;t.fillRect({...i,color:r});let{minimum:s,maximum:o}=this,n=0;this.xAxisVisible&&(n=t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height);let a=0;this.yAxisVisible&&(a=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);let l=this.xScale=new nt(this.display.formatter,e,this.xAxisScaleFont,this.effectiveXAxisMinimum,this.effectiveXAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),h=l.calculateMargin(t,!0),c=this.yScale=new nt(this.display.formatter,e,this.yAxisScaleFont,this.effectiveYAxisMinimum,this.effectiveYAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),d=c.calculateMargin(t,!1),g=l.measureHorizontalHeight(t),w=i.height-n-g-d,x=w+2*d,_=c.drawVertical(t,i.x+a,i.y,x,!0),L=this.showRamp&&!this.rgbMode,A,E=0,I=0,k=0;L&&(A=new nt(this.display.formatter,e,this.font,s,o,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),E=i.y+d,I=w,k=A.drawVertical(t,i.x+i.width,E,I,!1,!0));let F=e*Gy,z=L?F+k+this.gap:0,j=i.width-a-_-z,wt=j+2*h,ct=i.x+a+_-h,Ct=i.y+x+g-d;l.drawHorizontal(t,ct,Ct,wt);let ut=e*1,Pt=Math.round(i.x+a+_)-ut/2,bt=Math.round(i.y+d)-ut/2;t.strokePath({path:new R(Pt,bt).lineTo(Pt,bt+w),color:this.yAxisAxisColor,opacity:100/255,lineWidth:ut});let Nt=Pt,Qt=bt+w+ut;t.strokePath({path:new R(Nt,Qt).lineTo(Nt+j,Qt),color:this.xAxisAxisColor,opacity:100/255,lineWidth:ut});let{dataWidth:Ft,dataHeight:Ie,colorMap:te}=this,[pe,ri]=te.getMinMax(),Be=this.graphAreaX=Math.round(i.x+a+_),He=this.graphAreaY=Math.round(i.y+c.margin);this.renderedGraphAreaWidth=j,this.renderedGraphAreaHeight=w,this.region&&t.addHitRegion(this.region).addRect(Be,He,j,w);let si=this.rgbMode;if(this.value&&this.value.length&&(!si||this.value.length>=3*Ft*Ie)){let pt=document.createElement("canvas"),{effectiveCropLeft:At,effectiveCropRight:Gt,effectiveCropTop:mt,effectiveCropBottom:ee}=this;pt.width=Ft-At-Gt,pt.height=Ie-mt-ee;let Ot=pt.getContext("2d");for(let at=At;at<Ft-Gt;at++)for(let dt=mt;dt<Ie-ee;dt++){if(si){let lt=(dt*Ft+at)*3,Et=this.applyColorDepth(this.value[lt],s,o),yt=this.applyColorDepth(this.value[lt+1],s,o),Z=this.applyColorDepth(this.value[lt+2],s,o);Ot.fillStyle=`rgb(${Et},${yt},${Z})`}else{let lt=this.value[dt*Ft+at];if(te.autoscale){let Mt=(lt-s)/(o-s);lt=pe+Mt*(ri-pe)}let[Et,yt,Z]=te.lookup(lt);Ot.fillStyle=`rgb(${Et},${yt},${Z})`}Ot.fillRect(at-At,dt-mt,1,1)}t.ctx.drawImage(pt,Be,He,j,w);let gt=pt.width,xt=pt.height;if(this.horizonProfileXPvName||this.horizonProfileYPvName){let at=new Array(gt);for(let Z=0;Z<gt;Z++){let Mt=0;for(let vt=0;vt<xt;vt++)Mt+=this.pixelValueAt(mt+vt,At+Z);at[Z]=Mt/xt}let{effectiveXAxisMinimum:dt,effectiveXAxisMaximum:lt}=this,Et=gt>1?(lt-dt)/(gt-1):0,yt=new Array(gt);for(let Z=0;Z<gt;Z++)yt[Z]=dt+Z*Et;this.pushProfilePV(this.horizonProfileXPvName,yt),this.pushProfilePV(this.horizonProfileYPvName,at)}if(this.verticalProfileXPvName||this.verticalProfileYPvName){let at=new Array(xt);for(let Z=0;Z<xt;Z++){let Mt=0;for(let vt=0;vt<gt;vt++)Mt+=this.pixelValueAt(mt+Z,At+vt);at[Z]=Mt/gt}let{effectiveYAxisMinimum:dt,effectiveYAxisMaximum:lt}=this,Et=xt>1?(lt-dt)/(xt-1):0,yt=new Array(xt);for(let Z=0;Z<xt;Z++)yt[Z]=lt-Z*Et;this.pushProfilePV(this.verticalProfileXPvName,yt),this.pushProfilePV(this.verticalProfileYPvName,at)}}if(L&&A){let pt=i.x+i.width-k-F,At=F,Gt=I-2*A.margin,mt=document.createElement("canvas");mt.width=At,mt.height=Gt;let ee=mt.getContext("2d");for(let Ot=0;Ot<Gt;Ot++){let gt=o-Ot/Gt*(o-s);if(te.autoscale){let lt=(gt-s)/(o-s);gt=pe+lt*(ri-pe)}let[xt,at,dt]=te.lookup(gt);ee.fillStyle=`rgb(${xt},${at},${dt})`,ee.fillRect(0,Ot,At,1)}t.ctx.drawImage(mt,pt,E+A.margin)}if(this.xAxisVisible){let pt=i.x+_+j/2;this.yAxisVisible&&(pt+=a),t.fillText({x:pt,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+a/2,i.y+x/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());let oi=this.region?.selection;if(oi){let pt={x:Be,y:He,width:j,height:w};t.strokeRect({...gi(pt,oi),color:m.BLACK,lineWidth:e,dash:[2*e,2*e]})}}applyRubberBandZoom(t){if(!this.xScale||!this.yScale||!this.renderedGraphAreaWidth||!this.renderedGraphAreaHeight)return;this.originalState||(this.originalState={cropLeft:this.effectiveCropLeft,cropRight:this.effectiveCropRight,cropTop:this.effectiveCropTop,cropBottom:this.effectiveCropBottom,xAxisMinimum:this.effectiveXAxisMinimum,xAxisMaximum:this.effectiveXAxisMaximum,yAxisMinimum:this.effectiveYAxisMinimum,yAxisMaximum:this.effectiveYAxisMaximum});let{dataWidth:e,dataHeight:i,graphAreaX:r,graphAreaY:s}=this,{renderedGraphAreaWidth:o,renderedGraphAreaHeight:n}=this,a=this.effectiveCropLeft,l=this.effectiveCropRight,h=this.effectiveCropTop,c=this.effectiveCropBottom,d=e-a-l,g=i-h-c,w=Math.min(t.x,t.x+t.width),x=Math.max(t.x,t.x+t.width),_=Math.min(t.y,t.y+t.height),L=Math.max(t.y,t.y+t.height),A=(Nt,Qt)=>({x:Math.round(d*(Nt-r)/o),y:Math.round(g*(Qt-s)/n)}),E=A(w,_),I=A(x,L),k=a+E.x,F=h+E.y,z=l+d-I.x,j=c+g-I.y;if(k+z>=e||F+j>=i)return;this.effectiveCropLeft=k,this.effectiveCropTop=F,this.effectiveCropRight=z,this.effectiveCropBottom=j;let wt=this.xScale.getMinMax(),ct=this.xScale.getPositionValue(t.x),Ct=this.xScale.getPositionValue(t.x+t.width);ct>Ct&&([ct,Ct]=[Ct,ct]),this.effectiveXAxisMinimum=Math.max(wt.start,ct),this.effectiveXAxisMaximum=Math.min(wt.stop,Ct);let ut=this.yScale.getMinMax(),Pt=this.yScale.getPositionValue(t.y),bt=this.yScale.getPositionValue(t.y+t.height);Pt>bt&&([Pt,bt]=[bt,Pt]),this.effectiveYAxisMinimum=Math.max(ut.start,Pt),this.effectiveYAxisMaximum=Math.min(ut.stop,bt)}resetZoom(){let{originalState:t}=this;t&&(this.effectiveCropLeft=t.cropLeft,this.effectiveCropRight=t.cropRight,this.effectiveCropTop=t.cropTop,this.effectiveCropBottom=t.cropBottom,this.effectiveXAxisMinimum=t.xAxisMinimum,this.effectiveXAxisMaximum=t.xAxisMaximum,this.effectiveYAxisMinimum=t.yAxisMinimum,this.effectiveYAxisMaximum=t.yAxisMaximum)}pushProfilePV(t,e){t&&(this.display.pvEngine.createPV(t),this.display.pvEngine.setValue(new Date,t,e))}applyColorDepth(t,e,i){let r=Math.trunc(t);switch(this.colorDepth){case Dy:return r>>8;case Wy:return r>>16;case ky:return r>>22;case Fy:return r&255;case Ny:return Math.trunc((t-e)/(i-e)*255);default:return r}}pixelValueAt(t,e){if(this.rgbMode){let i=(t*this.dataWidth+e)*3;return(this.value[i]+this.value[i+1]+this.value[i+2])/3}return this.value[t*this.dataWidth+e]}get effectiveCropLeft(){return this._effectiveCropLeft??this.cropLeft}set effectiveCropLeft(t){this._effectiveCropLeft=t}get effectiveCropRight(){return this._effectiveCropRight??this.cropRight}set effectiveCropRight(t){this._effectiveCropRight=t}get effectiveCropTop(){return this._effectiveCropTop??this.cropTop}set effectiveCropTop(t){this._effectiveCropTop=t}get effectiveCropBottom(){return this._effectiveCropBottom??this.cropBottom}set effectiveCropBottom(t){this._effectiveCropBottom=t}get effectiveXAxisMinimum(){return this._effectiveXAxisMinimum??this.xAxisMinimum}set effectiveXAxisMinimum(t){this._effectiveXAxisMinimum=t}get effectiveXAxisMaximum(){return this._effectiveXAxisMaximum??this.xAxisMaximum}set effectiveXAxisMaximum(t){this._effectiveXAxisMaximum=t}get effectiveYAxisMinimum(){return this._effectiveYAxisMinimum??this.yAxisMinimum}set effectiveYAxisMinimum(t){this._effectiveYAxisMinimum=t}get effectiveYAxisMaximum(){return this._effectiveYAxisMaximum??this.yAxisMaximum}set effectiveYAxisMaximum(t){this._effectiveYAxisMaximum=t}get gap(){return this.scale*3}get colorDepth(){return this.properties.getValue(ru)}get colorMap(){return this.properties.getValue(su)}get cropBottom(){return this.properties.getValue(ou)}get cropLeft(){return this.properties.getValue(nu)}get cropRight(){return this.properties.getValue(au)}get cropTop(){return this.properties.getValue(lu)}get dataHeight(){return this.properties.getValue(hu)}get dataWidth(){return this.properties.getValue(cu)}get font(){return this.properties.getValue(pu).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(du)}get graphAreaWidth(){return this.scale*this.properties.getValue(uu)}get horizonProfileXPvName(){return this.properties.getValue(gu)}get horizonProfileYPvName(){return this.properties.getValue(mu)}get verticalProfileXPvName(){return this.properties.getValue(fu)}get verticalProfileYPvName(){return this.properties.getValue(wu)}get maximum(){return this.properties.getValue(xu)}get minimum(){return this.properties.getValue(yu)}get rgbMode(){return this.properties.getValue(Pu)}get showRamp(){return this.properties.getValue(bu)}get xAxisAxisColor(){return this.properties.getValue(vu)}get xAxisAxisTitle(){return this.properties.getValue(Ru)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(_u)}get xAxisMaximum(){return this.properties.getValue(Tu)}get xAxisMinimum(){return this.properties.getValue(Su)}get xAxisScaleFont(){return this.properties.getValue(Lu).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Cu)}get xAxisTitleFont(){return this.properties.getValue(Au).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Ou)}get yAxisAxisColor(){return this.properties.getValue(Eu)}get yAxisAxisTitle(){return this.properties.getValue(Mu)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Vu)}get yAxisMaximum(){return this.properties.getValue(Iu)}get yAxisMinimum(){return this.properties.getValue(Bu)}get yAxisScaleFont(){return this.properties.getValue(Hu).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(Du)}get yAxisTitleFont(){return this.properties.getValue(Wu).scale(this.scale)}get yAxisVisible(){return this.properties.getValue(ku)}};var Nu="bit",Fu="data_type",Gu="effect_3d",$u="state_count",Uu="square_led",Yu="off_color",zu="off_label",Xu="off_state",qu="font",Ku="on_color",ju="on_label",Zu="on_state",Ju="bulb_border",Qu="bulb_border_color",tg="state_color_fallback",eg="state_label_fallback",ig="show_boolean_label",Uy="scale_options",$r=class extends M{areaRegion;states=[];constructor(t,e){super(t,e),this.properties.add(new P(Nu)),this.properties.add(new P(Fu)),this.properties.add(new f(Gu)),this.properties.add(new f(Uu)),this.properties.add(new P($u,2)),this.properties.add(new S(Yu)),this.properties.add(new T(zu)),this.properties.add(new T(Xu)),this.properties.add(new S(Ku)),this.properties.add(new T(ju)),this.properties.add(new T(Zu)),this.properties.add(new H(qu)),this.properties.add(new f(ig)),this.properties.add(new S(tg)),this.properties.add(new T(eg)),this.properties.add(new P(Ju,3)),this.properties.add(new S(Qu,m.DARK_GRAY)),this.properties.add(new tt(Uy,new J(!0,!0,!0)))}async parseNode(t){if(await super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){let i=new S(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);let r=new T(`state_label_${e}`);r.value=t.getString(`state_label_${e}`),this.properties.add(r);let s=new C(`state_value_${e}`);s.value=t.getFloat(`state_value_${e}`),this.properties.add(s),this.states.push({label:this.properties.getValue(r.name),color:this.properties.getValue(i.name),value:this.properties.getValue(s.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){return this.dataType===0?this.bit<0?!!this.value:this.value!==void 0?(this.value>>this.bit&1)>0:!1:this.dataType===1?(this.value!==void 0?String(this.value):void 0)===this.onState:!1}get bulbColor(){if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(let t of this.states)if(t.value===this.value)return t.color;return this.stateColorFallback}get label(){if(this.stateCount===2)return this.booleanValue?this.onLabel:this.offLabel;for(let t of this.states)if(t.value===this.value)return t.label;return this.stateLabelFallback}draw(t){let e=D(this.bounds,3*this.scale);if(this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel){let i=this.bulbColor;i.red*299+i.green*587+i.blue*114>105e3?i=m.BLACK:i=m.WHITE,t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:i,text:this.label})}}drawCircle2d(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;this.bulbBorder>0&&(s-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addEllipse(i,r,s,o,0,0,2*Math.PI)}drawCircle3d(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:m.WHITE});let n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);n.addColorStop(0,this.bulbBorderColor.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n});let a=e.width-2*this.bulbBorder,l=e.height-2*this.bulbBorder;s=a/2,o=l/2,t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbColor}),n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n}),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addEllipse(i,r,s,o,0,0,2*Math.PI)}drawSquare2d(t,e){let i=Bt(e.x,e.y,e.width,e.height,this.bulbBorder);t.fillRect({...i,color:this.bulbColor}),t.strokeRect({...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){t.fillRect({...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 R(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 R(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 R(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 R(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)});let r=e.x+this.bulbBorder,s=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,n=e.height-2*this.bulbBorder;t.fillRect({x:r,y:s,width:o,height:n,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:r,y:s,width:o,height:n,gradient:i})}get bit(){return this.properties.getValue(Nu)}get dataType(){return this.properties.getValue(Fu)}get squareLed(){return this.properties.getValue(Uu)}get showBooleanLabel(){return this.properties.getValue(ig)}get font(){return this.properties.getValue(qu).scale(this.scale)}get effect3d(){return this.properties.getValue(Gu)}get stateCount(){return this.properties.getValue($u)}get bulbBorder(){return this.scale*this.properties.getValue(Ju)}get bulbBorderColor(){return this.properties.getValue(Qu)}get offLabel(){return this.properties.getValue(zu)}get offColor(){return this.properties.getValue(Yu)}get offState(){return this.properties.getValue(Xu)}get onLabel(){return this.properties.getValue(ju)}get onColor(){return this.properties.getValue(Ku)}get onState(){return this.properties.getValue(Zu)}get stateLabelFallback(){return this.properties.getValue(eg)}get stateColorFallback(){return this.properties.getValue(tg)}};var Yy=16,zy=12,Xy=-5,zs=45,Ur=G(zs),rg=(1-Math.sin(Ur)/2)/(2*Math.cos(Ur)),qy=8,Ky=5,jy=180-zs,Zy=zs,sg="color_hi",og="color_hihi",ng="color_lo",ag="color_lolo",lg="font",hg="level_hi",cg="level_hihi",pg="level_lo",dg="level_lolo",ug="limits_from_pv",gg="log_scale",mg="major_tick_step_hint",fg="minimum",wg="maximum",xg="needle_color",yg="ramp_gradient",Pg="scale_font",bg="scale_format",vg="show_hi",Rg="show_hihi",_g="show_lo",Tg="show_lolo",Sg="show_minor_ticks",Lg="show_markers",Cg="show_scale",Ag="show_value_label",Og="value_label_format",Jy="scale_options",Yr=class extends M{areaRegion;constructor(t,e){super(t,e),this.properties.add(new S(sg)),this.properties.add(new S(og)),this.properties.add(new S(ng)),this.properties.add(new S(ag)),this.properties.add(new H(lg)),this.properties.add(new P(hg)),this.properties.add(new P(cg)),this.properties.add(new P(pg)),this.properties.add(new P(dg)),this.properties.add(new f(gg)),this.properties.add(new f(ug,!0)),this.properties.add(new P(mg,50)),this.properties.add(new P(wg)),this.properties.add(new P(fg)),this.properties.add(new S(xg)),this.properties.add(new f(yg)),this.properties.add(new H(Pg)),this.properties.add(new T(bg)),this.properties.add(new f(vg)),this.properties.add(new f(Rg)),this.properties.add(new f(_g)),this.properties.add(new f(Tg)),this.properties.add(new f(Sg,!0)),this.properties.add(new f(Lg,!0)),this.properties.add(new f(Cg,!0)),this.properties.add(new f(Ag,!0)),this.properties.add(new T(Og)),this.properties.add(new tt(Jy,new J(!0,!0,!0)))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.drawRamp(t,this.computeLimits()),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}computeLimits(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum}}drawRamp(t,e){let i=new Jt(jy,Zy,"outward");i.minimum=e.min,i.maximum=e.max,i.logScale=this.logScale,i.showMinorTicks=this.showMinorTicks,i.visible=this.showScale,i.majorTickStepHint=this.majorTickStepHint*this.scale,i.majorTickLength=this.majorTickLength,i.minorTickLength=this.minorTickLength,i.majorLineWidth=2*this.scale,i.minorLineWidth=1*this.scale,i.format=this.scaleFormat,i.font=this.scaleFont,i.foregroundColor=this.foregroundColor;let r=i.formatText(e.min),s=t.measureText(r,this.scaleFont),o=i.formatText(e.max),n=t.measureText(o,this.scaleFont),a=Math.max(s.width,n.width)/2,l=this.height,h=this.width;l>rg*(h-2*a)&&(l=Math.floor(rg*(h-2*a)));let c=l/(1-Math.sin(Ur)/2),d=Math.floor(this.x-c*(1-Math.cos(Ur))+a),g=this.y,w={x:d,y:g,width:Math.floor(2*c),height:Math.floor(2*c)},{rampWidth:x}=this,_=D(w,w.width/4-x,w.height/4-x);_.width=Math.min(_.width,_.height),_.height=_.width;let L=new Zt(x,135,45);L.lolo=e.lolo,L.loloColor=this.colorLoLo,L.showLoLo=!0,L.lo=e.lo,L.loColor=this.colorLo,L.showLo=!0,L.hi=e.hi,L.hiColor=this.colorHi,L.showHi=!0,L.hihi=e.hihi,L.hihiColor=this.colorHiHi,L.showHiHi=!0,L.minimum=e.min,L.maximum=e.max,L.gradient=this.rampGradient,L.logScale=this.logScale,L.draw(t,w,_,this.showRamp),i.draw(t,w),this.drawNeedle(t,w,L,i.getRadius(),e);let A=Y.ARIAL_12_BOLD.scale(this.scale);if(this.showValueLabel&&this.value!==void 0){let E=this.format(this.value,e),I=t.measureText(E,A);t.fillText({x:w.x+w.width/2-I.width/2,y:w.y+w.height/2-w.height/4-(i.getRadius()-w.height/4)/2-I.height/2,align:"left",baseline:"top",font:A,text:E,color:this.foregroundColor})}}drawNeedle(t,e,i,r,s){let o=e.x+e.width/2,n=e.y+e.height/2,a;if(this.value!==void 0){let _=i.getValueInRange(this.value);a=360-i.getValuePosition(_),s.max>s.min?_>s.max?a+=8:_<s.min&&(a-=8):_>s.min?a-=8:_<s.max&&(a+=8)}else a=360-i.getValuePosition(s.min+s.max/2);let l=G(a),{needleWidth:h,gapBetweenNeedleScale:c,scale:d}=this,g=Tt(o+e.width/4,n-h/2+3*d,o,n,l),w=Tt(o+r-c,n,o,n,l),x=Tt(o+e.width/4,n+h/2-3*d,o,n,l);t.fillPath({color:this.needleColor,path:new R(g.x,g.y).lineTo(w.x,w.y).lineTo(x.x,x.y).closePath()})}get needleWidth(){return this.scale*Yy}get gapBetweenNeedleScale(){return this.scale*Xy}get rampWidth(){return this.scale*zy}format(t,e){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let i=jt(e.min,e.max);return new rt(i).format(t)}}get colorLo(){return this.properties.getValue(ng)}get colorLoLo(){return this.properties.getValue(ag)}get colorHi(){return this.properties.getValue(sg)}get colorHiHi(){return this.properties.getValue(og)}get font(){return this.properties.getValue(lg).scale(this.scale)}get levelLo(){return this.properties.getValue(pg)}get levelLoLo(){return this.properties.getValue(dg)}get levelHi(){return this.properties.getValue(hg)}get levelHiHi(){return this.properties.getValue(cg)}get limitsFromPv(){return this.properties.getValue(ug)}get logScale(){return this.properties.getValue(gg)}get majorTickStepHint(){return this.properties.getValue(mg)}get majorTickLength(){return this.scale*qy}get minorTickLength(){return this.scale*Ky}get minimum(){return this.properties.getValue(fg)}get maximum(){return this.properties.getValue(wg)}get needleColor(){return this.properties.getValue(xg)}get rampGradient(){return this.properties.getValue(yg)}get scaleFont(){return this.properties.getValue(Pg).scale(this.scale)}get scaleFormat(){return this.properties.getValue(bg)}get showLo(){return this.properties.getValue(_g)}get showLoLo(){return this.properties.getValue(Tg)}get showHi(){return this.properties.getValue(vg)}get showHiHi(){return this.properties.getValue(Rg)}get showMinorTicks(){return this.properties.getValue(Sg)}get showRamp(){return this.properties.getValue(Lg)}get showScale(){return this.properties.getValue(Cg)}get showValueLabel(){return this.properties.getValue(Ag)}get valueLabelFormat(){return this.properties.getValue(Og)}};var Eg="color_hi",Mg="color_hihi",Vg="color_lo",Ig="color_lolo",Bg="color_fillbackground",Hg="effect_3d",Dg="fill_color",Wg="fillcolor_alarm_sensitive",kg="font",Ng="horizontal",Fg="indicator_mode",Gg="level_hi",$g="level_hihi",Ug="level_lo",Yg="level_lolo",zg="limits_from_pv",Xg="log_scale",qg="maximum",Kg="major_tick_step_hint",jg="minimum",Zg="origin",Jg="origin_ignored",Qg="scale_font",tm="scale_format",em="show_hi",im="show_hihi",rm="show_label",sm="show_lo",om="show_lolo",nm="show_markers",am="show_minor_ticks",lm="show_scale",hm="transparent_background",cm="value_label_format",zr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(Eg)),this.properties.add(new S(Mg)),this.properties.add(new S(Vg)),this.properties.add(new S(Ig)),this.properties.add(new S(Bg)),this.properties.add(new f(Hg)),this.properties.add(new S(Dg)),this.properties.add(new f(Wg,!1)),this.properties.add(new H(kg)),this.properties.add(new f(Ng)),this.properties.add(new f(Fg)),this.properties.add(new C(Gg)),this.properties.add(new C($g)),this.properties.add(new C(Ug)),this.properties.add(new C(Yg)),this.properties.add(new f(zg,!0)),this.properties.add(new f(Xg)),this.properties.add(new C(qg)),this.properties.add(new C(Kg)),this.properties.add(new C(jg)),this.properties.add(new C(Zg,0)),this.properties.add(new f(Jg,!0)),this.properties.add(new H(Qg)),this.properties.add(new T(tm)),this.properties.add(new f(em)),this.properties.add(new f(im)),this.properties.add(new f(rm)),this.properties.add(new f(sm)),this.properties.add(new f(om)),this.properties.add(new f(nm)),this.properties.add(new f(am)),this.properties.add(new f(lm)),this.properties.add(new f(hm)),this.properties.add(new T(cm))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=D(this.area,2*this.scale));let i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect({...e,color:i}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){let i=this.alarmSensitiveForegroundColor,r=new nt(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);r.scaleFormat=this.scaleFormat;let s=r.drawVertical(t,e.x,e.y,e.height,!0),o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,r,e)),this.drawVerticalBar(t,r,{x:e.x+s,y:e.y+r.margin,width:e.width-s-o,height:e.height-2*r.margin})}drawVerticalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let c=t.measureText("LOLO",a);l=Math.max(l,c.width)}if(this.showLo&&s!==void 0){let c=t.measureText("LO",a);l=Math.max(l,c.width)}if(this.showHi&&o!==void 0){let c=t.measureText("HI",a);l=Math.max(l,c.width)}if(this.showHiHi&&n!==void 0){let c=t.measureText("HIHI",a);l=Math.max(l,c.width)}let h=i.x+i.width;if(this.showLoLo&&r!==void 0){let c=h-l-this.markerGap,d=Math.round(e.getValuePosition(r));t.strokePath({path:new R(c,d).lineTo(c-this.markerTickLength,d),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerGap,y:d,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let c=h-l-this.markerGap,d=Math.round(e.getValuePosition(s));t.strokePath({path:new R(c,d).lineTo(c-this.markerTickLength,d),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerGap,y:d,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let c=h-l-this.markerGap,d=Math.round(e.getValuePosition(o));t.strokePath({path:new R(c,d).lineTo(c-this.markerTickLength,d),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerGap,y:d,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let c=h-l-this.markerGap,d=Math.round(e.getValuePosition(n));t.strokePath({path:new R(c,d).lineTo(c-this.markerTickLength,d),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerGap,y:d,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawVerticalBar(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let n=t.createLinearGradient(i.x,0,i.x+i.width,0);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:n});let a=D(i,r/2);t.strokeRect({...a,color:m.GRAY,lineWidth:r})}let s=this.alarmSensitiveFillColor;if(this.indicatorMode){let n=Math.round(e.getValuePosition(this.getFillValue())),a=i.width,l=this.thumbBreadth,h=ht([{x:0,y:l/2},{x:a/2,y:0},{x:a-1,y:l/2},{x:a/2,y:l}],i.x,n-l/2),c=R.fromPoints(h);if(this.effect3d){let{x:d,y:g}=h[0],{x:w,y:x}=h[2],_=t.createLinearGradient(d,g,w,x);_.addColorStop(0,m.WHITE.toString()),_.addColorStop(1,s.toString()),t.fillPath({path:c,gradient:_}),t.strokePath({path:c,color:m.GRAY,lineWidth:r})}else t.fillPath({path:c,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let d=n;n=a,a=d}let l=Math.round(e.getValuePosition(n)),h=Math.round(e.getValuePosition(a)),c=D({...i,y:l,height:h-l},r);if(t.fillRect({...c,color:s}),this.effect3d){let d=t.createLinearGradient(c.x,0,c.x+c.width,0);d.addColorStop(0,m.WHITE.toString()),d.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...c,gradient:d})}}let o=this.value;this.showLabel&&o!==void 0&&t.fillText({x:i.x+i.width/2,y:i.y+i.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(o)})}drawHorizontal(t,e){let i=this.alarmSensitiveForegroundColor,r=new nt(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);r.scaleFormat=this.scaleFormat;let s=r.drawHorizontal(t,e.x,e.y+e.height,e.width),o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,r,e)),this.drawHorizontalBar(t,r,{x:e.x+r.margin,y:e.y+o,width:e.width-2*r.margin,height:e.height-s-o})}drawHorizontalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let c=t.measureText("LOLO",a);l=Math.max(l,c.height)}if(this.showLo&&s!==void 0){let c=t.measureText("LO",a);l=Math.max(l,c.height)}if(this.showHi&&o!==void 0){let c=t.measureText("HI",a);l=Math.max(l,c.height)}if(this.showHiHi&&n!==void 0){let c=t.measureText("HIHI",a);l=Math.max(l,c.height)}let h=i.y;if(this.showLoLo&&r!==void 0){let c=Math.round(e.getValuePosition(r)),d=h+l+this.markerGap;t.strokePath({path:new R(c,d).lineTo(c,d+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c,y:h,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let c=Math.round(e.getValuePosition(s)),d=h+l+this.markerGap;t.strokePath({path:new R(c,d).lineTo(c,d+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c,y:h,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let c=Math.round(e.getValuePosition(o)),d=h+l+this.markerGap;t.strokePath({path:new R(c,d).lineTo(c,d+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c,y:h,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let c=Math.round(e.getValuePosition(n)),d=h+l+this.markerGap;t.strokePath({path:new R(c,d).lineTo(c,d+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c,y:h,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawHorizontalBar(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let n=t.createLinearGradient(0,i.y,0,i.y+i.height);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:n});let a=D(i,r/2);t.strokeRect({...a,color:m.GRAY,lineWidth:r})}let s=this.alarmSensitiveFillColor;if(this.indicatorMode){let n=Math.round(e.getValuePosition(this.getFillValue())),a=i.height,l=this.thumbBreadth,h=ht([{x:l/2,y:0},{x:l,y:a/2},{x:l/2,y:a-1},{x:0,y:a/2}],n-l/2,i.y),c=R.fromPoints(h);if(this.effect3d){let{x:d,y:g}=h[0],{x:w,y:x}=h[2],_=t.createLinearGradient(d,g,w,x);_.addColorStop(0,m.WHITE.toString()),_.addColorStop(1,s.toString()),t.fillPath({path:c,gradient:_}),t.strokePath({path:c,color:m.GRAY,lineWidth:r})}else t.fillPath({path:c,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let d=n;n=a,a=d}let l=Math.round(e.getValuePosition(n)),h=Math.round(e.getValuePosition(a)),c=D({...i,x:l,width:h-l},r);if(t.fillRect({...c,color:s}),this.effect3d){let d=t.createLinearGradient(0,c.y,0,c.y+c.height);d.addColorStop(0,m.WHITE.toString()),d.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...c,gradient:d})}}let o=this.value;this.showLabel&&o!==void 0&&t.fillText({x:i.x+i.width/2,y:i.y+i.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(o)})}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get thumbBreadth(){return this.scale*13}get outlineWidth(){return this.scale*1}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Vg)}get colorLoLo(){return this.properties.getValue(Ig)}get colorHi(){return this.properties.getValue(Eg)}get colorHiHi(){return this.properties.getValue(Mg)}get colorFillbackground(){return this.properties.getValue(Bg)}get effect3d(){return this.properties.getValue(Hg)}get fillColorAlarmSensitive(){return this.properties.getValue(Wg)}get fillColor(){return this.properties.getValue(Dg)}get font(){return this.properties.getValue(kg).scale(this.scale)}get horizontal(){return this.properties.getValue(Ng)}get indicatorMode(){return this.properties.getValue(Fg)}get levelLo(){return this.properties.getValue(Ug)}get levelLoLo(){return this.properties.getValue(Yg)}get levelHi(){return this.properties.getValue(Gg)}get levelHiHi(){return this.properties.getValue($g)}get limitsFromPv(){return this.properties.getValue(zg)}get logScale(){return this.properties.getValue(Xg)}get minimum(){return this.properties.getValue(jg)}get majorTickStepHint(){return this.scale*this.properties.getValue(Kg)}get maximum(){return this.properties.getValue(qg)}get origin(){return this.properties.getValue(Zg)}get originIgnored(){return this.properties.getValue(Jg)}get scaleFont(){return this.properties.getValue(Qg).scale(this.scale)}get scaleFormat(){return this.properties.getValue(tm)}get showHi(){return this.properties.getValue(em)}get showHiHi(){return this.properties.getValue(im)}get showLabel(){return this.properties.getValue(rm)}get showLo(){return this.properties.getValue(sm)}get showLoLo(){return this.properties.getValue(om)}get showMarkers(){return this.properties.getValue(nm)}get showMinorTicks(){return this.properties.getValue(am)}get showScale(){return this.properties.getValue(lm)}get transparentBackground(){return this.properties.getValue(hm)}get valueLabelFormat(){return this.properties.getValue(cm)}};var pm="color_hi",dm="color_hihi",um="color_lo",gm="color_lolo",mm="color_fillbackground",fm="fill_color",wm="fillcolor_alarm_sensitive",xm="effect_3d",ym="level_hi",Pm="level_hihi",bm="level_lo",vm="level_lolo",Rm="limits_from_pv",_m="log_scale",Tm="maximum",Sm="major_tick_step_hint",Lm="minimum",Cm="scale_font",Am="scale_format",Om="show_hi",Em="show_hihi",Mm="show_lo",Vm="show_lolo",Im="show_markers",Bm="show_minor_ticks",Hm="show_scale",Dm="transparent_background",Qy=new m(160,160,160),Xr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(pm)),this.properties.add(new S(dm)),this.properties.add(new S(um)),this.properties.add(new S(gm)),this.properties.add(new S(mm)),this.properties.add(new f(xm)),this.properties.add(new S(fm)),this.properties.add(new f(wm,!1)),this.properties.add(new C(ym)),this.properties.add(new C(Pm)),this.properties.add(new C(bm)),this.properties.add(new C(vm)),this.properties.add(new f(Rm,!0)),this.properties.add(new f(_m)),this.properties.add(new C(Tm)),this.properties.add(new C(Sm)),this.properties.add(new C(Lm)),this.properties.add(new H(Cm)),this.properties.add(new T(Am)),this.properties.add(new f(Om)),this.properties.add(new f(Em)),this.properties.add(new f(Mm)),this.properties.add(new f(Vm)),this.properties.add(new f(Im)),this.properties.add(new f(Bm)),this.properties.add(new f(Hm)),this.properties.add(new f(Dm))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let{scale:e,min:i,max:r}=this,s=this.area;this.borderAlarmSensitive&&(s=D(s,2*e));let o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect({...s,color:o}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let n=this.alarmSensitiveForegroundColor,a=new nt(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);a.scaleFormat=this.scaleFormat;let l=a.drawVertical(t,s.x,s.y,s.height,!0),h=0;this.showMarkers&&(h=this.drawMarkers(t,s,a)),this.drawTank(t,s,l,h,a)}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let c=t.measureText("LOLO",a);l=Math.max(l,c.width)}if(this.showLo&&s!==void 0){let c=t.measureText("LO",a);l=Math.max(l,c.width)}if(this.showHi&&o!==void 0){let c=t.measureText("HI",a);l=Math.max(l,c.width)}if(this.showHiHi&&n!==void 0){let c=t.measureText("HIHI",a);l=Math.max(l,c.width)}let h=e.x+e.width-l-this.markerGap-this.markerTickLength;if(this.showLoLo&&r!==void 0){let c=Math.round(i.getValuePosition(r));t.strokePath({path:new R(h,c).lineTo(h+this.markerTickLength,c),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:c,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let c=Math.round(i.getValuePosition(s));t.strokePath({path:new R(h,c).lineTo(h+this.markerTickLength,c),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:c,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let c=Math.round(i.getValuePosition(o));t.strokePath({path:new R(h,c).lineTo(h+this.markerTickLength,c),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:c,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let c=Math.round(i.getValuePosition(n));t.strokePath({path:new R(h,c).lineTo(h+this.markerTickLength,c),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:c,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawTank(t,e,i,r,s){let o=this.alarmSensitiveForegroundColor,{scale:n,outlineWidth:a}=this,l=e.x+i,h=e.y+s.margin,c=e.width-i-r,d=e.height-2*s.margin,g=this.defaultCorner,w=11/20;c<2*g&&(w=12/20);let x=Math.floor(c*w);g>2*x-c-2*a&&(g=2*x-c);let _=s.getValuePosition(this.getFillValue()),L=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:h,width:c,height:d,rx:g/2,ry:g/2,color:m.WHITE});let E=t.createLinearGradient(l,h,l+x+2*n,h);E.addColorStop(0,this.colorFillbackground.toString()),E.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:h,width:x,height:d,rx:g/2,ry:g/2,gradient:E}),E=t.createLinearGradient(l+c-x-2*n,h,l+c,h),E.addColorStop(0,m.WHITE.withAlpha(0).toString()),E.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+c-x,y:h,width:x,height:d,rx:g/2,ry:g/2,gradient:E});let I=_,k=h+d-_;E=t.createLinearGradient(l,I,l+x+2*n,I),E.addColorStop(0,L.toString()),E.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:I,width:x,height:k,rx:g/2,ry:g/2,gradient:E}),E=t.createLinearGradient(l+c-x-2*n,I,l+c,I),E.addColorStop(0,m.WHITE.withAlpha(0).toString()),E.addColorStop(1,L.toString()),t.fillRect({x:l+c-x,y:I,width:x,height:k,rx:g/2,ry:g/2,gradient:E})}else t.fillRect({x:l,y:h,width:c,height:d,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:_,width:c,height:h+d-_,rx:g/2,ry:g/2,color:L});let A=D({x:l,y:h,width:c,height:d},a/2);t.strokeRect({...A,rx:g/2,ry:g/2,color:this.effect3d?Qy:o,lineWidth:a})}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*15}get markerTickLength(){return this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get outlineWidth(){return this.scale*1}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}get colorLo(){return this.properties.getValue(um)}get colorLoLo(){return this.properties.getValue(gm)}get colorHi(){return this.properties.getValue(pm)}get colorHiHi(){return this.properties.getValue(dm)}get colorFillbackground(){return this.properties.getValue(mm)}get fillColorAlarmSensitive(){return this.properties.getValue(wm)}get fillColor(){return this.properties.getValue(fm)}get effect3d(){return this.properties.getValue(xm)}get levelLo(){return this.properties.getValue(bm)}get levelLoLo(){return this.properties.getValue(vm)}get levelHi(){return this.properties.getValue(ym)}get levelHiHi(){return this.properties.getValue(Pm)}get limitsFromPv(){return this.properties.getValue(Rm)}get logScale(){return this.properties.getValue(_m)}get minimum(){return this.properties.getValue(Lm)}get majorTickStepHint(){return this.scale*this.properties.getValue(Sm)}get maximum(){return this.properties.getValue(Tm)}get scaleFont(){return this.properties.getValue(Cm).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Am)}get showLo(){return this.properties.getValue(Mm)}get showLoLo(){return this.properties.getValue(Vm)}get showHi(){return this.properties.getValue(Om)}get showHiHi(){return this.properties.getValue(Em)}get showMarkers(){return this.properties.getValue(Im)}get showMinorTicks(){return this.properties.getValue(Bm)}get showScale(){return this.properties.getValue(Hm)}get transparentBackground(){return this.properties.getValue(Dm)}};var Wm="auto_size",Xs="font",km="format_type",Nm="horizontal_alignment",Fm="precision",Gm="precision_from_pv",$m="rotation_angle",Um="show_lohi",Ym="show_units",zm="vertical_alignment",Xm="wrap_words",qr=class extends M{areaRegion;tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new f(Wm)),this.properties.add(new H(Xs)),this.properties.add(new P(km)),this.properties.add(new P(Nm)),this.properties.add(new P(Fm)),this.properties.add(new f(Gm)),this.properties.add(new C($m)),this.properties.add(new f(Um,!0)),this.properties.add(new f(Ym,!0)),this.properties.add(new P(zm)),this.properties.add(new f(Xm))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"},this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(Xs).scale(1);this.customSize=t.measureText(this.computeDisplayText(),e,!0)}super.drawHolder(t)}computeDisplayText(){let t=this.text;if(this.value!==void 0){let e=this.precisionFromPV?this.pv?.precision??-1:this.precision;t=me(this.value,this.formatType,e,this.pv?.typeHint)}return this.showUnits&&this.pv?.units&&(t+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?t+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(t+=" \u2191")),t}draw(t){let e=t.ctx;this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...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):this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let{scale:i}=this,r=this.area;this.borderAlarmSensitive&&(r=D(r,2*i,2*i));let s=this.computeDisplayText();this.wrapWords?this.drawWrapped(t,s,r):this.drawSingleLine(t,s,r)}drawSingleLine(t,e,i){let r=t.ctx,s=t.measureText(e,this.font,!0);if(r.font=this.font.getFontString(),this.rotationAngle){this.drawRotated(t,e,i,s);return}r.textBaseline="alphabetic";let n=r.measureText(e).fontBoundingBoxAscent,a={x:i.x,y:i.y,width:s.width,height:s.height};this.horizAlignment===0||(this.horizAlignment===1?a.x+=(i.width-s.width)/2:this.horizAlignment===2&&(a.x+=i.width-s.width)),this.vertAlignment===0||i.height<=s.height||(this.vertAlignment===1?a.y+=i.height/2-s.height/2:this.vertAlignment===2&&(a.y+=i.height-s.height)),r.textAlign="start",r.textBaseline="top",a.y+=a.height/2-n/2,r.save(),r.beginPath();let l=this.area;r.rect(l.x,l.y,l.width,l.height),r.clip(),r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.fillText(e,a.x,a.y),r.restore()}drawRotated(t,e,i,r){let s=t.ctx,o=wi(i,r,this.rotationAngle,this.horizAlignment,this.vertAlignment);s.save(),s.beginPath();let n=this.area;s.rect(n.x,n.y,n.width,n.height),s.clip(),s.translate(i.x+o.x,i.y+o.y),s.rotate(this.rotationAngle*Math.PI/180),s.textAlign="left",s.textBaseline="top",s.fillStyle=this.alarmSensitiveForegroundColor.toString(),s.fillText(e,0,0),s.restore()}drawWrapped(t,e,i){let r=t.ctx,s=this.wrapText(t,e,i.width);r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.font=this.font.getFontString(),r.textAlign="start",r.textBaseline="top";let o=t.measureText("Mg",this.font).height,n=s.length*o,a=i.y;i.height>n&&(this.vertAlignment===1?a+=(i.height-n)/2:this.vertAlignment===2&&(a+=i.height-n)),r.save(),r.beginPath();let l=this.area;r.rect(l.x,l.y,l.width,l.height),r.clip();for(let h of s){let c=i.x;if(this.horizAlignment===1){let d=r.measureText(h).width;c=i.x+(i.width-d)/2}else if(this.horizAlignment===2){let d=r.measureText(h).width;c=i.x+(i.width-d)}r.fillText(h,c,a),a+=o}r.restore()}wrapText(t,e,i){let r=[];for(let s of e.replace(/\n$/,"").split(`
22
- `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[];for(;e.length;){let s;for(s=e.length;t.measureText(e.substr(0,s),this.font).width>i;s--);let o;if(s===e.length)o=e;else if(e[s]===" ")o=e.substr(0,s+1);else{let n=e.substr(0,s),a=0;for(;n.indexOf(" ",a)!==-1;a=n.indexOf(" ",a)+1);if(a)o=n.substr(0,a);else{let l=e.indexOf(" ");o=l===-1?e:e.substr(0,l)}}r.push(o),e=e.substr(o.length)}return r}get autoSize(){return this.properties.getValue(Wm)}get font(){return this.properties.getValue(Xs).scale(this.scale)}get formatType(){return this.properties.getValue(km)}get horizAlignment(){return this.properties.getValue(Nm)}get precision(){return this.properties.getValue(Fm)}get precisionFromPV(){return this.properties.getValue(Gm)}get rotationAngle(){return this.properties.getValue($m)}get showLohi(){return this.properties.getValue(Um)}get showUnits(){return this.properties.getValue(Ym)}get vertAlignment(){return this.properties.getValue(zm)}get wrapWords(){return this.properties.getValue(Xm)}};var qm="color_hi",Km="color_hihi",jm="color_lo",Zm="color_lolo",Jm="color_fillbackground",Qm="fill_color",tf="fillcolor_alarm_sensitive",ef="font",rf="effect_3d",sf="level_hi",of="level_hihi",nf="level_lo",af="level_lolo",lf="limits_from_pv",hf="log_scale",cf="maximum",pf="major_tick_step_hint",df="minimum",uf="scale_font",gf="scale_format",mf="show_bulb",ff="show_hi",wf="show_hihi",xf="show_lo",yf="show_lolo",Pf="show_markers",bf="show_minor_ticks",vf="show_scale",Rf="transparent_background",_f="unit",Tf="value_label_format",Sf=new m(160,160,160),Kr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(qm)),this.properties.add(new S(Km)),this.properties.add(new S(jm)),this.properties.add(new S(Zm)),this.properties.add(new S(Jm)),this.properties.add(new S(Qm)),this.properties.add(new f(tf,!1)),this.properties.add(new f(rf)),this.properties.add(new C(sf)),this.properties.add(new C(of)),this.properties.add(new C(nf)),this.properties.add(new C(af)),this.properties.add(new f(lf,!0)),this.properties.add(new H(ef)),this.properties.add(new f(hf)),this.properties.add(new C(cf)),this.properties.add(new C(pf)),this.properties.add(new C(df)),this.properties.add(new H(uf)),this.properties.add(new T(gf)),this.properties.add(new f(mf)),this.properties.add(new f(ff)),this.properties.add(new f(wf)),this.properties.add(new f(xf)),this.properties.add(new f(yf)),this.properties.add(new f(Pf)),this.properties.add(new f(bf)),this.properties.add(new f(vf)),this.properties.add(new f(Rf)),this.properties.add(new P(_f)),this.properties.add(new T(Tf))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let{scale:e,min:i,max:r}=this,s=this.area;this.borderAlarmSensitive&&(s=D(this.area,2*this.scale));let o=this.alarmSensitiveBackgroundColor,n=this.alarmSensitiveForegroundColor,a=this.alarmSensitiveFillColor;this.transparentBackground||t.fillRect({...s,color:o}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let l=s.height;if(this.showBulb){let A=Math.min(s.width/2,this.bulbMaxDiameter);l=s.height<A?0:s.height-A}let h={...s,height:l},c=new nt(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);c.scaleFormat=this.scaleFormat;let d=0,g="";if(this.unit===0?g="\xB0C":this.unit===1?g="\xB0F":this.unit===2&&(g="K"),g){let A=Y.ARIAL_9.scale(e),E=t.measureText(g,A),I=2*e;d=E.height+2*I,t.fillText({x:s.x+s.width/2-this.pipeWidth/2-I,y:s.y+I,baseline:"top",align:"right",color:n,font:A,text:g})}let w=h.x+h.width/2-this.pipeWidth/2-1*e,x={...h,y:h.y+d,height:h.height-d+c.calculateMargin(t,!1)},_=c.drawVertical(t,w,x.y,x.height,!1),L=Math.floor(this.pipeWidth/2);if(h={...h,y:c.getValuePosition(r)-L,height:c.scaleLength+2*L},this.drawPipe(t,h,c),this.showMarkers&&this.drawMarkers(t,s,c),this.showBulb){let A=Math.min(s.width/2,this.bulbMaxDiameter),E=1*e,I=s.x+s.width/2,k=s.y+l+A/2,F=A/2,z=A/2;if(t.fillEllipse({cx:I,cy:k,rx:F,ry:z,color:a}),this.effect3d){let ct=t.createLinearGradient(I-F,k-z,I+F,k+z);ct.addColorStop(0,m.WHITE.toString()),ct.addColorStop(1,a.withAlpha(0).toString()),t.fillEllipse({cx:I,cy:k,rx:F,ry:z,gradient:ct})}t.strokeEllipse({cx:I,cy:k,rx:F-E/2,ry:z-E/2,color:this.effect3d?Sf:n,lineWidth:E});let j={x:Math.round(h.x+h.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(c.getValuePosition(i)),width:this.pipeWidth-2*this.outlineWidth,height:e*3};if(this.effect3d){let ct=Math.round(h.x+h.width/2-this.pipeWidth/2),Ct=ct+this.pipeWidth,ut=t.createLinearGradient(ct,j.y,Ct,j.y);ut.addColorStop(0,m.WHITE.toString()),ut.addColorStop(1,a.toString()),t.fillRect({...j,gradient:ut})}else t.fillRect({...j,color:a});let wt=this.value;wt!==void 0&&t.fillText({x:I,y:k,align:"center",baseline:"middle",color:a.contrast(),font:this.font,text:this.format(wt)})}}drawPipe(t,e,i){let{scale:r,outlineWidth:s,min:o,max:n}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,h={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},c=this.getFillValue(),d=i.getValuePosition(c);n>o?c>n?d-=10*r:c<o&&(d+=10*r):c>o?d+=10*r:c<n&&(d-=10*r);let g=this.pipeWidth/2,{x:w,y:x,width:_,height:L}=h;if(this.effect3d){let E=t.createLinearGradient(w,x,w+_,x);E.addColorStop(0,m.WHITE.toString()),E.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({...h,rx:g/2,ry:g/2,gradient:E}),E=t.createLinearGradient(w,x,w+_,x),E.addColorStop(0,m.WHITE.toString()),E.addColorStop(1,l.toString()),t.fillRect({x:w,y:d,width:_,height:x+L-d,rx:g/2,ry:g/2,gradient:E})}else t.fillRect({...h,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:w,y:d,width:_,height:x+L-d,rx:g/2,ry:g/2,color:l});let A=D(h,s/2);t.strokeRect({...A,rx:g/2,ry:g/2,color:this.effect3d?Sf:a,lineWidth:s})}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=Y.ARIAL_9.scale(this.scale),l=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&r!==void 0){let h=Math.round(i.getValuePosition(r));t.strokePath({path:new R(l,h).lineTo(l+this.markerTickLength,h),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=Math.round(i.getValuePosition(s));t.strokePath({path:new R(l,h).lineTo(l+this.markerTickLength,h),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=Math.round(i.getValuePosition(o));t.strokePath({path:new R(l,h).lineTo(l+this.markerTickLength,h),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=Math.round(i.getValuePosition(n));t.strokePath({path:new R(l,h).lineTo(l+this.markerTickLength,h),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*15}get bulbMaxDiameter(){return this.scale*40}get outlineWidth(){return this.scale*1}get markerTickLength(){return this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(jm)}get colorLoLo(){return this.properties.getValue(Zm)}get colorHi(){return this.properties.getValue(qm)}get colorHiHi(){return this.properties.getValue(Km)}get colorFillbackground(){return this.properties.getValue(Jm)}get fillColorAlarmSensitive(){return this.properties.getValue(tf)}get fillColor(){return this.properties.getValue(Qm)}get font(){return this.properties.getValue(ef).scale(this.scale)}get effect3d(){return this.properties.getValue(rf)}get levelLo(){return this.properties.getValue(nf)}get levelLoLo(){return this.properties.getValue(af)}get levelHi(){return this.properties.getValue(sf)}get levelHiHi(){return this.properties.getValue(of)}get limitsFromPv(){return this.properties.getValue(lf)}get logScale(){return this.properties.getValue(hf)}get minimum(){return this.properties.getValue(df)}get majorTickStepHint(){return this.scale*this.properties.getValue(pf)}get maximum(){return this.properties.getValue(cf)}get scaleFont(){return this.properties.getValue(uf).scale(this.scale)}get scaleFormat(){return this.properties.getValue(gf)}get showBulb(){return this.properties.getValue(mf)}get showMarkers(){return this.properties.getValue(Pf)}get showMinorTicks(){return this.properties.getValue(bf)}get showLo(){return this.properties.getValue(xf)}get showLoLo(){return this.properties.getValue(yf)}get showHi(){return this.properties.getValue(ff)}get showHiHi(){return this.properties.getValue(wf)}get showScale(){return this.properties.getValue(vf)}get transparentBackground(){return this.properties.getValue(Rf)}get unit(){return this.properties.getValue(_f)}get valueLabelFormat(){return this.properties.getValue(Tf)}};var Lf=-323.3062,Cf=308.2547,jr=class{constructor(t,e){this.widget=t;this.index=e}linearScale;_effectiveMinimum;_effectiveMaximum;get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return this.timeFormat!==0}isHorizontal(){return this.index===0||this.index!==1&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){return this._effectiveMinimum??this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){return this._effectiveMaximum??this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){let t={start:this.minimum,stop:this.maximum},e=this.widget.calculateAutoscaledRange(this,t);e&&(this.effectiveMinimum=e.start,this.effectiveMaximum=e.stop,this.widget.requestRepaint())}applyZoom(t,e){let i=this.effectiveMinimum,r=this.effectiveMaximum,s,o;if(this.logScale){r=Math.log10(r),i=Math.log10(i);let n=Math.log10(t)*e,a=1-e;s=n+i*a,o=n+r*a,s<Lf&&(s=Lf),s=Math.pow(10,s),o>Cf&&(o=Cf),o=Math.pow(10,o)}else{let n=Math.max(Math.abs(i),Math.abs(r));i/=n,r/=n;let a=t/n*e,l=1-e;s=(a+i*l)*n,o=(a+r*l)*n}this.effectiveMinimum=s,this.effectiveMaximum=o,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleThreshold(){return this.getValue("auto_scale_threshold")}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")}};var Lt=class{constructor(t,e){this.xAxis=t;this.yAxis=e;for(let i of t)this.beforeXRanges.push({min:i.effectiveMinimum,max:i.effectiveMaximum});for(let i of e)this.beforeYRanges.push({min:i.effectiveMinimum,max:i.effectiveMaximum})}beforeXRanges=[];beforeYRanges=[];afterXRanges=[];afterYRanges=[];saveState(){for(let t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(let t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){let 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++){let 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++){let 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++){let e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}},Zr=class{undoStack=[];redoStack=[];canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){let t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){let t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}};var Jr=class{constructor(t,e){this.widget=e;this.id=t}id;cursor;selection;grabStart;prevGrabEvent;grabZoomCommand;tooltip(){return this.widget.tooltip}mouseDown(t){let{widget:e}=this;switch(e.toolbar?.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new Lt(e.getXAxes(),e.getYAxes());break}}grab(t){switch(this.widget.toolbar?.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection={...this.grabStart.point,width:t.dx,height:t.dy},this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint();break}}grabEnd(){let{grabZoomCommand:t,selection:e,widget:i}=this;switch(i.toolbar?.currentTool){case"rubberband-zoom":if(e){let r=new Lt(i.getXAxes(),i.getYAxes());this.rangeZoomXAxes(e),this.rangeZoomYAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"horizontal-zoom":if(e){let r=new Lt(i.getXAxes(),i.getYAxes());this.rangeZoomXAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"vertical-zoom":if(e){let r=new Lt(i.getXAxes(),i.getYAxes());this.rangeZoomYAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"panning":t&&(t.saveState(),i.toolbar.addCommand(t));break}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){let{widget:e}=this;switch(e.toolbar?.currentTool){case"zoom-in":let i=new Lt(e.getXAxes(),e.getYAxes());for(let s of e.getAxes()){let o=s.isHorizontal()?t.point.x:t.point.y,n=s.linearScale.getPositionValue(o);s.applyZoom(n,.1)}i.saveState(),e.toolbar.addCommand(i);break;case"zoom-out":let r=new Lt(e.getXAxes(),e.getYAxes());for(let s of e.getAxes()){let o=s.isHorizontal()?t.point.x:t.point.y,n=s.linearScale.getPositionValue(o);s.applyZoom(n,-.1)}r.saveState(),e.toolbar.addCommand(r);break}}rangeZoomXAxes(t){for(let e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),r=e.linearScale.getPositionValue(t.x+t.width);if(i>r){let o=i;i=r,r=o}let s=e.linearScale.getMinMax();i=Math.max(s.start,i),r=Math.min(s.stop,r),e.effectiveMinimum=i,e.effectiveMaximum=r}}rangeZoomYAxes(t){for(let e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),r=e.linearScale.getPositionValue(t.y+t.height);if(i>r){let o=i;i=r,r=o}let s=e.linearScale.getMinMax();i=Math.max(s.start,i),r=Math.min(s.stop,r),e.effectiveMinimum=i,e.effectiveMaximum=r}}pan(t){let{prevGrabEvent:e,widget:i}=this;if(e){let r=e.dx-t.dx;if(r!==0)for(let o of i.getXAxes()){let n=o.linearScale,a=n.getMinMax(),l=n.getValuePosition(a.start)+r,h=n.getValuePosition(a.stop)+r;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(h)}let s=e.dy-t.dy;if(s!==0)for(let o of i.getYAxes()){let n=o.linearScale,a=n.getMinMax(),l=n.getValuePosition(a.start)+s,h=n.getValuePosition(a.stop)+s;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(h)}}}};var qs=class{pointer=0;samples=[];constructor(t){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(){let t=(this.pointer+1)%this.samples.length;return this.samples[t]!==void 0}isEmpty(){return this.tail()===void 0}tail(){return this.pointer===0?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t)return this.samples.filter(i=>i!==void 0).sort((i,r)=>i.x-r.x);{let e=this.samples.slice(this.pointer).filter(r=>r!==void 0),i=this.samples.slice(0,this.pointer).filter(r=>r!==void 0);return e.concat(i)}}},Qr=class{constructor(t,e,i,r,s,o){this.bufferSize=t;this.plotMode=e;this.updateMode=i;this.concatenateData=r;this.chronological=s;this.historicalDataProvider=o;this.traceData=new qs(t)}traceData;x=0;xPending=!1;y=0;yTimestamp=0;yPending=!1;xArray=[];xArrayPending=!1;yArray=[];yArrayPending=!1;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.historicalDataProvider?this.historicalDataProvider.getSamples():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(this.plotMode===1&&this.traceData.isFull())return;let{xPending:t,yPending:e,chronological:i,updateMode:r}=this;r===0?(i&&e||!i&&(t||e))&&this.addPoint():r===1?(i&&e||!i&&t&&e)&&this.addPoint():r===2?(i&&e||!i&&t)&&this.addPoint():r===3&&this.yPending&&this.addPoint()}maybeAddArray(){if(this.plotMode===1&&this.traceData.isFull())return;let{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:r}=this;r===0?(i&&e||!i&&(t||e))&&this.addArray():r===1?(i&&e||!i&&t&&e)&&this.addArray():r===2?(i&&e||!i&&t)&&this.addArray():r===3&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(this.updateMode===5)t=new Date().getTime();else if(this.yTimestamp!==void 0)t=this.yTimestamp;else{let 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 s=0;s<e.length;s++)t[s]=s;else{let s=this.traceData.tail();for(let o=1;o<e.length;o++)t[o-1]=s.x+o}let i=Math.min(t.length,e.length),r=Math.min(i,this.bufferSize);for(let s=0;s<r;s++)this.traceData.push(t[s],e[s]);this.xArrayPending=!1,this.yArrayPending=!1}};var ts=class{constructor(t,e){this.widget=t;this.i=e}traceData;historicalDataProvider;xPVInstance;yPVInstance;xPVListener=()=>{let t=this.xPVInstance;if(t)if(Array.isArray(t.value))this.traceData?.updateXArray(t.value);else{let e=t.toNumber();e!=null&&this.traceData?.updateX(e)}};yPVListener=()=>{let t=this.yPVInstance;if(t)if(Array.isArray(t.value))this.traceData?.updateYArray(t.value);else{let e=this.widget.getAxis(this.xAxisIndex),i=t.toNumber();if(i!=null)if(e.isDateEnabled()){let r=(t.time||new Date).getTime();this.traceData?.updateY(i,r)}else this.traceData?.updateY(i)}};init(){let{bufferSize:t,plotMode:e,updateMode:i,concatenateData:r,widget:s}=this,o=!this.xPV,{pvEngine:n}=s.display;this.historicalDataProvider=void 0,o&&this.yPV&&(this.historicalDataProvider=n.createHistoricalDataProvider(this.yPV,s)||void 0),this.traceData=new Qr(t,e,i,r,o,this.historicalDataProvider),this.xPV&&(this.xPVInstance=n.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=n.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),s.addPropertyListener(`trace_${this.i}_x_pv`,()=>{let a=n.createPV(this.xPV);a!==this.xPVInstance&&(this.xPVInstance?.removeListener(this.xPVListener),this.xPVInstance=a,this.xPVInstance.addListener(this.xPVListener))}),s.addPropertyListener(`trace_${this.i}_y_pv`,()=>{let a=n.createPV(this.yPV);a!==this.yPVInstance&&(this.yPVInstance?.removeListener(this.yPVListener),this.yPVInstance=a,this.yPVInstance.addListener(this.yPVListener))})}snapshot(){return this.traceData?.snapshot()||[]}drawTrace(t,e){let{lineWidth:i}=this;if(this.traceType===0)t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i});else if(this.traceType===1)t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(this.traceType!==2){if(this.traceType===3){let s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let o of e)o.y!==null&&t.strokePath({path:new R(o.x,o.y).lineTo(o.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(this.traceType===4||this.traceType===5){let s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let o=1;o<e.length;o++){let n=e[o-1],a=e[o];n.y!==null&&a.y!==null&&t.fillPath({path:new R(n.x,n.y).lineTo(n.x,s).lineTo(a.x,s).lineTo(a.x,a.y),color:this.traceColor,opacity:100/255})}this.traceType===5&&t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(this.traceType===6)for(let r=1;r<e.length;r++){let s=e[r-1],o=e[r];s.y!==null&&o.y!==null&&t.strokePath({path:new R(s.x,s.y).lineTo(s.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(this.traceType===7)for(let r=1;r<e.length;r++){let s=e[r-1],o=e[r];s.y!==null&&o.y!==null&&t.strokePath({path:new R(s.x,s.y).lineTo(o.x,s.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(this.traceType===8){let{scale:r}=this;t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*r,2*r,2*r,2*r]})}else if(this.traceType===9){let{scale:r}=this;t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*r,2*r,2*r,2*r,2*r,2*r]})}else if(this.traceType===10){let{scale:r}=this;t.strokePath({path:R.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*r,2*r]})}}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;let i=this.pointSize/2,r=e.x,s=e.y;switch(this.pointStyle){case 1:t.ctx.beginPath(),t.ctx.ellipse(r,s,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(r,s,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 3:t.ctx.beginPath(),t.ctx.ellipse(r,s,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(r-i,s+i),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(r-i,s+i),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(r-i,s-i,2*i,2*i);break;case 7:t.ctx.fillRect(r-i,s-i,2*i,2*i);break;case 8:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s),t.ctx.lineTo(r,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 9:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s),t.ctx.lineTo(r,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(r-i,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.moveTo(r+i,s-i),t.ctx.lineTo(r-i,s+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r+i,s),t.ctx.moveTo(r,s-i),t.ctx.lineTo(r,s+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(r,s-i),t.ctx.lineTo(r,s+i),t.ctx.stroke()}}clearData(){this.traceData?.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")}destroy(){this.historicalDataProvider?.disconnect()}};var tP=new m(236,236,236),eP=new m(130,130,130),Ks=class{constructor(t,e,i,r,s){this.imageFile=e;this.disabledImageFile=i;this.action=s;this.loadPromise=new Promise((o,n)=>{this.imageElement.onload=()=>o()}),this.disabledLoadPromise=new Promise((o,n)=>{this.disabledImageElement.onload=()=>o()}),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:()=>r}}imageElement=new Image;disabledImageElement=new Image;loadPromise;disabledLoadPromise;toggleButton=!1;toolButton=!1;pushed=!1;disabled=!1;region;loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}},es=class{constructor(t){this.xyGraph=t;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",i=>{this.showLegend.pushed=i}),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",()=>{let i=new Lt(t.getXAxes(),t.getYAxes());t.performAutoScale(),i.saveState(),this.addCommand(i)}),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",()=>{let i=document.createElement("a");try{i.href=t.toDataURL(),i.download=`${t.name}_export.png`,document.body.appendChild(i),i.click()}finally{document.body.removeChild(i)}}),this.toggleTool(this.mouseArrow);let e=this.buttons.map(i=>i.loadPromise).concat(this.buttons.map(i=>i.disabledLoadPromise));Promise.all(e).finally(()=>{this.imagesLoaded=!0,t.requestRepaint()});for(let i of this.buttons)i.loadImage(t.display.imagesPrefix)}buttons=[];showLegend;autoScale;rubberbandZoom;horizontalZoom;verticalZoom;zoomIn;zoomOut;panning;mouseArrow;undo;redo;camera;imagesLoaded=!1;currentTool="default";commandBuffer=new Zr;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){let e=t.pushed;for(let i of this.buttons)i.toolButton&&(i.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){let r=this.createToggleButton(t,e,i);return r.toolButton=!0,r}createToggleButton(t,e,i){let r=this.createButton(t,t,e,i);return r.toggleButton=!0,r}createButton(t,e,i,r){let s=new Ks(this,t,e,i,r);return this.buttons.push(s),s}draw(t,e){let{buttonSize:i}=this,r={x:e.x,y:e.y};return this.drawButton(t,r.x,r.y,this.showLegend),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.autoScale),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.rubberbandZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.horizontalZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.verticalZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.zoomIn),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.zoomOut),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.panning),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.mouseArrow),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.undo),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.redo),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.camera),r.x+=i,r.y+i-e.y}maybeWrap(t,e,i){i=i??this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){let{buttonSize:r}=this,s=1*this.scale,o=Math.round(e+r/4)-s/2;t.strokePath({path:new R(o,i).lineTo(o,i+r),color:eP,lineWidth:s})}drawButton(t,e,i,r){let{buttonSize:s,scale:o}=this;t.fillRect({x:e,y:i,width:s,height:s,color:tP}),this.xyGraph.enabled&&!r.disabled&&t.addHitRegion(r.region).addRect(e,i,s,s);let n=1*o,a=Math.round(i+n/2)-.5,l=Math.round(e+n/2)-.5,h=Math.round(i+s-n+n/2)-.5,c=Math.round(e+s-n+n/2)-.5;if(t.strokePath({color:r.pushed?m.WHITE:m.BLACK,path:new R(c,h).lineTo(c,a).moveTo(c,h).lineTo(l,h),lineWidth:n}),t.strokePath({color:r.pushed?m.BLACK:m.WHITE,path:new R(l,a).lineTo(c-n,a).moveTo(l,a).lineTo(l,h-n),lineWidth:n}),this.imagesLoaded){let d=r.disabled?r.disabledImageElement:r.imageElement,g=d.naturalHeight*o,w=d.naturalWidth*o,x=Math.round(e+(s-w)/2),_=Math.round(i+(s-g)/2);t.ctx.drawImage(d,x,_,w,g)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}};var js="axis_count",Af="plot_area_background_color",Of="show_legend",Ef="show_plot_area_border",Mf="show_toolbar",Vf="title",If="title_font",Zs="trace_count",Bf="transparent",is=class extends M{toolbar;plotAreaRegion;axes=[];traces=[];autoScaleAllowed=!0;constructor(t,e){super(t,e),this.properties.add(new P(js)),this.properties.add(new S(Af)),this.properties.add(new f(Of)),this.properties.add(new f(Ef)),this.properties.add(new f(Mf)),this.properties.add(new T(Vf)),this.properties.add(new H(If)),this.properties.add(new P(Zs)),this.properties.add(new f(Bf)),this.properties.addGenerator(()=>{let i=[];this.axes=[];let r=this.properties.getValue(js);for(let o=0;o<r;o++)this.axes.push(new jr(this,o)),i.push(new f(`axis_${o}_auto_scale`),new C(`axis_${o}_auto_scale_threshold`),new S(`axis_${o}_axis_color`),new T(`axis_${o}_axis_title`),new f(`axis_${o}_dash_grid_line`),new S(`axis_${o}_grid_color`),new f(`axis_${o}_log_scale`),new C(`axis_${o}_maximum`),new C(`axis_${o}_minimum`),new H(`axis_${o}_scale_font`),new T(`axis_${o}_scale_format`),new f(`axis_${o}_show_grid`),new P(`axis_${o}_time_format`),new H(`axis_${o}_title_font`),new f(`axis_${o}_visible`)),o>1&&i.push(new f(`axis_${o}_left_bottom_side`),new f(`axis_${o}_y_axis`));this.traces=[];let s=this.properties.getValue(Zs);for(let o=0;o<s;o++)this.traces.push(new ts(this,o)),i.push(new f(`trace_${o}_anti_alias`),new P(`trace_${o}_buffer_size`),new f(`trace_${o}_concatenate_data`),new P(`trace_${o}_line_width`),new T(`trace_${o}_name`),new P(`trace_${o}_plot_mode`),new P(`trace_${o}_point_size`),new P(`trace_${o}_point_style`),new S(`trace_${o}_trace_color`),new P(`trace_${o}_trace_type`),new P(`trace_${o}_update_delay`),new P(`trace_${o}_update_mode`),new f(`trace_${o}_visible`),new P(`trace_${o}_x_axis_index`),new T(`trace_${o}_x_pv`),new Dt(`trace_${o}_x_pv_value`,`trace_${o}_x_pv`),new P(`trace_${o}_y_axis_index`),new T(`trace_${o}_y_pv`),new Dt(`trace_${o}_y_pv_value`,`trace_${o}_y_pv`));return i})}init(){this.plotAreaRegion=new Jr(`${this.wuid}-plotarea`,this),this.traces.forEach(t=>t.init())}draw(t){let{scale:e}=this,i=this.area;if(this.borderAlarmSensitive&&(i=D(this.area,2*e)),!this.transparent){let o=this.alarmSensitiveBackgroundColor;t.fillRect({...i,color:o})}this.showToolbar&&this.drawToolbar(t,i),this.title&&this.drawTitle(t,i);for(let o of this.axes){if(o.autoScale&&this.autoScaleAllowed){let l={start:o.minimum,stop:o.maximum},h=this.calculateAutoscaledRange(o,l);h&&(o.effectiveMinimum=h.start,o.effectiveMaximum=h.stop)}let n=o.effectiveMinimum,a=o.effectiveMaximum;o.linearScale=new nt(this.display.formatter,e,o.scaleFont,n,a,o.logScale,50*e,o.axisColor,!0,o.visible),o.linearScale.scaleFormat=o.scaleFormat,o.linearScale.timeFormat=o.timeFormat}this.showLegend&&this.drawLegend(t,i),t.addHitRegion(this.plotAreaRegion).addRect(i.x,i.y,i.width,i.height);let r=this.drawAxes(t,i);this.drawPlotArea(t,r);let s=this.plotAreaRegion?.selection;s&&this.drawZoomSelection(t,r,gi(r,s))}drawToolbar(t,e){this.toolbar||(this.toolbar=new es(this));let i=3*this.scale,r=D(e,i),s=this.toolbar.draw(t,r);e.y+=i+s+i,e.height-=i+s+i}drawTitle(t,e){let 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});let r=2*this.scale;e.y+=i+r,e.height-=i+r}drawAxes(t,e){let{scale:i}=this,r=5*i,s={...e},o=0,n=0;for(let c of this.getXAxes())if(c.visible){let d=0;c.axisTitle&&(d=r+t.measureText(c.axisTitle,c.titleFont).height),o+=d,n+=d+c.linearScale.measureHorizontalHeight(t)}let a=0,l=0;for(let c of this.getYAxes().reverse()){let d=c.linearScale;if(c.visible){let g=d.calculateMargin(t,!1),w=s.height-n+(n>0?g:0),x=0;c.axisTitle&&(x=t.measureText(c.axisTitle,c.titleFont).height,t.ctx.save(),t.ctx.translate(s.x+r+x/2,e.y+w/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:c.titleFont,color:c.axisColor,text:c.axisTitle}),t.ctx.restore(),x+=r);let _=x+d.drawVertical(t,s.x+x,e.y,w,!0,!1);s.x+=_,s.width-=_,a+=_;let L=d.margin;l=l===0?L:Math.min(l,L);let A=i*1,E=Math.round(s.x)-A/2,I=Math.round(e.y+g)-A/2;t.strokePath({path:new R(E,I).lineTo(E,I+w-2*g),color:c.axisColor,opacity:100/255,lineWidth:A})}else{let g=s.height-n;d.setDimensions(0,e.y,g,!1)}}let h=0;for(let c of this.getXAxes().reverse()){let d=c.linearScale;if(c.visible){let g=d.calculateMargin(t,!0),w=a-g,x=0;if(c.axisTitle){x=t.measureText(c.axisTitle,c.titleFont).height;let k=e.x+a+(e.width-a)/2;t.fillText({x:k,y:s.y+s.height-x/2,align:"center",baseline:"middle",font:c.titleFont,color:c.axisColor,text:c.axisTitle}),x+=r}let _=x+d.drawHorizontal(t,e.x+w,s.y+s.height-x,e.width-w);s.height-=_;let L=d.margin;h=h===0?L:Math.min(h,L);let A=i*1,E=Math.round(e.x+w+g)-A/2,I=Math.round(s.y+s.height)-A/2;t.strokePath({path:new R(E,I).lineTo(E+s.width-g,I),color:c.axisColor,opacity:100/255,lineWidth:A})}else{let g=e.x+a,w=e.width-a;d.setDimensions(g,0,w,!0)}}return s.y+=l,s.width-=h,n>0?s.height-=l:s.height-=2*l,s}drawPlotArea(t,e){let{scale:i}=this,r=1*i;if(this.transparent||t.fillRect({...e,color:this.plotAreaBackgroundColor}),this.showPlotAreaBorder){let{x:s,y:o,width:n,height:a}=D(e,r/2);t.strokePath({path:new R(s,o).lineTo(s+n,o).lineTo(s+n,o+a),color:m.BLACK,lineWidth:r})}for(let s of this.axes.filter(o=>o.visible&&o.showGrid)){let o=s.linearScale;if(s.isHorizontal())for(let n of o.getGridPositions()){let a=Math.round(o.getX()+n)-r/2;t.strokePath({path:new R(a,e.y).lineTo(a,e.y+e.height),color:s.gridColor,lineWidth:r,dash:s.dashGridLine?[6*i,2*i]:void 0})}else for(let n of o.getGridPositions()){let a=Math.round(o.getY()+n)-r/2;t.strokePath({path:new R(e.x,a).lineTo(e.x+e.width,a),color:s.gridColor,lineWidth:r,dash:s.dashGridLine?[6*i,2*i]:void 0})}}t.ctx.save(),t.ctx.beginPath(),t.ctx.rect(e.x,e.y,e.width,e.height),t.ctx.clip();for(let s of this.traces.filter(o=>o.visible)){let o=this.getAxis(s.xAxisIndex).linearScale,n=this.getAxis(s.yAxisIndex).linearScale,a=[];for(let l of s.snapshot()){let h=o.getValuePosition(l.x),c=l.y!==null?n.getValuePosition(l.y):null;a.push({x:h,y:c})}if(a.length){s.drawTrace(t,a);for(let l of a)l.y!==null&&s.drawPoint(t,l)}}t.ctx.restore()}drawZoomSelection(t,e,i){let{scale:r}=this;switch(this.toolbar?.currentTool){case"rubberband-zoom":t.strokeRect({...i,color:m.BLACK,lineWidth:1*r});break;case"horizontal-zoom":let s=i;s.y=e.y,s.height=e.height,t.strokeRect({..._s(s),color:m.BLACK,lineWidth:1*r});break;case"vertical-zoom":let o=i;o.x=e.x,o.width=e.width,t.strokeRect({..._s(o),color:m.BLACK,lineWidth:1*r});break}}drawLegend(t,e){let{scale:i}=this,r=25*i,s=2*i,o=5*i,n=Y.ARIAL_10.scale(i);for(let a of this.getYAxes()){let l=this.traces.filter(A=>A.visible&&A.yAxisIndex===a.index),h=[],c=[],d=0,g=0;for(let A of l){let E=r+s+o;A.name&&(E+=t.measureText(A.name,n).width),d+E<e.width?(c.push(A),d+=E):(h.push(c),E=Math.max(E,d),c=[A],d=E)}if(c.length&&(h.push(c),g=Math.max(g,d)),!h.length)continue;let w=r*h.length,x={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-w),width:g,height:w};e.height-=x.height,this.transparent||t.fillRect({...x,color:this.plotAreaBackgroundColor}),t.strokeRect({...D(x,1*i/2),color:a.axisColor});let _=x.x,L=x.y;for(let A=0;A<h.length;A++){let E=h[A],I=L+A*r,k=I+r/2;for(let F of E){let z=F.pointSize>Math.floor((r-o)/2)?Math.floor(r-o):F.pointSize;switch(F.traceType){case 3:let j=_+r/2;t.strokePath({path:new R(j,I+z).lineTo(j,I+r),lineWidth:F.lineWidth,color:F.traceColor,opacity:100/255}),F.drawPoint(t,{x:j,y:I+z});break;case 4:case 5:let wt=[{x:_,y:I+r/2},{x:_+r/2,y:I+z},{x:_+r,y:I+r/2},{x:_+r,y:I+r},{x:_,y:I+r}];t.fillPath({path:R.fromPoints(wt),color:F.traceColor,opacity:100/255}),F.traceType===5&&t.strokePath({path:R.fromPoints(wt.slice(0,3)),color:F.traceColor,lineWidth:1*i}),F.drawPoint(t,{x:_+r/2,y:I+z});break;default:F.drawTrace(t,[{x:_,y:k},{x:_+r,y:k}]),F.drawPoint(t,{x:_+r/2,y:k})}_+=r+s,F.name&&(t.fillText({x:_,y:k,align:"left",baseline:"middle",color:F.traceColor,font:n,text:F.name}),_+=t.measureText(F.name,n).width),_+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t,e){let i,r,s=t.logScale;for(let o of this.traces)if(o.visible&&!(this.axes[o.xAxisIndex]!==t&&this.axes[o.yAxisIndex]!==t))for(let n of o.snapshot()){let a=t.isHorizontal()?n.x:n.y;a!==null&&((i===void 0||i>a)&&(!s||a>0)&&(i=a),(r===void 0||r<a)&&(!s||a>0)&&(r=a))}if(i!==void 0&&r!==void 0)return i===r?{start:Math.min(i,e.start),stop:Math.max(r,e.stop)}:{start:i,stop:r}}performAutoScale(){for(let t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(let 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(js)}get plotAreaBackgroundColor(){return this.properties.getValue(Af)}get showLegend(){return this.properties.getValue(Of)}get showPlotAreaBorder(){return this.properties.getValue(Ef)}get showToolbar(){return this.properties.getValue(Mf)}get title(){return this.properties.getValue(Vf)}get titleFont(){return this.properties.getValue(If).scale(this.scale)}get traceCount(){return this.properties.getValue(Zs)}get transparent(){return this.properties.getValue(Bf)}destroy(){for(let t of this.traces)t.destroy()}};var Hf="array_length",Df="spinner_width",Wf="horizontal",kf="show_spinner",Nf="show_scrollbar",Ff="vec",Gf="data_type",iP="scale_options",$f=1,Uf=25,rP=16,Yf=16,sP=new m(64,64,64),oP=250,nP=40,aP=150,lP=new m(243,243,243),rs=class extends st{templateNode;templateWidgetType="";elementWidth=0;elementHeight=0;originalEnabled=new WeakMap;scrollIndex=0;fullValue=[];redistributing=!1;spinnerUpRegion;spinnerUpPressed=!1;spinnerDownRegion;spinnerDownPressed=!1;spinnerRepeatTimeout;spinnerLabelRegion;spinnerLabelBounds;editingIndex=!1;indexInputEl;scrollDecreaseRegion;scrollDecreasePressed=!1;scrollIncreaseRegion;scrollIncreasePressed=!1;scrollPageDecreaseRegion;scrollPageIncreaseRegion;scrollThumbRegion;scrollGrabStartIndex=0;scrollDragRange=0;scrollRepeatTimeout;constructor(t,e){super(t,e),this.properties.add(new P(Hf,10)),this.properties.add(new P(Df,40)),this.properties.add(new f(Wf,!1)),this.properties.add(new f(kf,!0)),this.properties.add(new f(Nf,!0)),this.properties.add(new P(Ff,1)),this.properties.add(new P(Gf,0))}async parseNode(t){await super.parseNode(t);let e=t.getNodes("widget");if(e.length){this.templateNode=e[0],this.templateWidgetType=this.templateNode.getString("widget_type"),this.elementWidth=this.templateNode.getInt("width",0),this.elementHeight=this.templateNode.getInt("height",0);for(let i=0;i<this.vec;i++){let r=this.templateNode.cloneWithOverrides({pvName:this.slotPvName(i),wuidSuffix:`-slot${i}`}),s=r.getString("widget_type"),o=this.display.createWidget(s,this);o&&(await o.parseNode(r),this.forEachDescendant(o,n=>this.originalEnabled.set(n,n.enabled)),o.properties.setValue(iP,new J(!1,!1,!1)),this.widgets.push(o),this.hookSlotWriteBack(i))}this.layoutSlots(),this.pvName&&this.display.pvEngine.trackListener(this,this.pvName,()=>this.value=this.pv.value)}}init(){this.spinnerUpRegion={id:`${this.wuid}-array-spinner-up`,mouseDown:()=>{this.spinnerUpPressed=!0,this.stepSpinnerRepeatedly(1,!0)},mouseUp:()=>this.stopSpinnerRepeating("up"),mouseOut:()=>this.stopSpinnerRepeating("up")},this.spinnerDownRegion={id:`${this.wuid}-array-spinner-down`,mouseDown:()=>{this.spinnerDownPressed=!0,this.stepSpinnerRepeatedly(-1,!0)},mouseUp:()=>this.stopSpinnerRepeating("down"),mouseOut:()=>this.stopSpinnerRepeating("down")},this.scrollDecreaseRegion={id:`${this.wuid}-array-scroll-decrease`,mouseDown:()=>{this.scrollDecreasePressed=!0,this.stepScrollbarRepeatedly(-1)},mouseUp:()=>this.stopScrollbarRepeating("decrease"),mouseOut:()=>this.stopScrollbarRepeating("decrease")},this.scrollIncreaseRegion={id:`${this.wuid}-array-scroll-increase`,mouseDown:()=>{this.scrollIncreasePressed=!0,this.stepScrollbarRepeatedly(1)},mouseUp:()=>this.stopScrollbarRepeating("increase"),mouseOut:()=>this.stopScrollbarRepeating("increase")},this.scrollPageDecreaseRegion={id:`${this.wuid}-array-scroll-page-decrease`,mouseDown:()=>this.setScrollbarIndex(this.scrollIndex-this.vec)},this.scrollPageIncreaseRegion={id:`${this.wuid}-array-scroll-page-increase`,mouseDown:()=>this.setScrollbarIndex(this.scrollIndex+this.vec)},this.scrollThumbRegion={id:`${this.wuid}-array-scroll-thumb`,mouseDown:()=>{this.scrollGrabStartIndex=this.scrollIndex},grab:t=>{if(this.scrollDragRange<=0)return;let e=this.horizontal?t.dx:t.dy,r=Math.max(0,this.effectiveArrayLength-this.vec)*e/this.scrollDragRange;this.setScrollbarIndex(this.scrollGrabStartIndex+r)}},this.spinnerLabelRegion={id:`${this.wuid}-array-spinner-label`,click:()=>this.startEditingIndex(),cursor:"text"},this.indexInputEl=document.createElement("input"),this.indexInputEl.style.display="none",this.indexInputEl.autocomplete="off",this.indexInputEl.addEventListener("keyup",t=>{t.key==="Enter"?this.commitEditingIndex():t.key==="Escape"&&this.cancelEditingIndex()}),this.indexInputEl.addEventListener("blur",()=>this.cancelEditingIndex()),this.display.rootPanel.appendChild(this.indexInputEl)}destroy(){window.clearTimeout(this.spinnerRepeatTimeout),window.clearTimeout(this.scrollRepeatTimeout),this.indexInputEl&&(this.display.rootPanel.removeChild(this.indexInputEl),this.indexInputEl=void 0),super.destroy()}forEachDescendant(t,e){if(e(t),t instanceof st)for(let i of t.widgets)this.forEachDescendant(i,e)}startEditingIndex(){if(!this.spinnerLabelBounds||!this.indexInputEl)return;this.editingIndex=!0;let t=this.display.measureAbsoluteArea(this),e=this.spinnerLabelBounds;this.indexInputEl.value=String(this.scrollIndex),this.indexInputEl.style.display="block",this.indexInputEl.style.position="absolute",this.indexInputEl.style.boxSizing="border-box",this.indexInputEl.style.left=`${t.x+e.x}px`,this.indexInputEl.style.top=`${t.y+e.y}px`,this.indexInputEl.style.width=`${e.width}px`,this.indexInputEl.style.height=`${e.height}px`,this.indexInputEl.style.textAlign="center",this.indexInputEl.focus(),this.indexInputEl.select(),this.requestRepaint()}commitEditingIndex(){let t=this.indexInputEl.value;this.cancelEditingIndex();let e=Number(t);isNaN(e)||this.setSpinnerIndex(e)}cancelEditingIndex(){this.indexInputEl.style.display="none",this.editingIndex=!1,this.requestRepaint()}slotPvName(t){return`loc://__array_${this.wuid}_slot${t}`}hookSlotWriteBack(t){let e=this.display.pvEngine.getPV(this.slotPvName(t));e&&this.display.pvEngine.trackListener(this,e.name,()=>{if(this.redistributing)return;let i=this.scrollIndex+t;i>=this.effectiveArrayLength||(this.fullValue[i]=this.coerceElement(e.value),this.pvName&&this.display.pvEngine.setValue(new Date,this.pvName,this.fullValue))})}coerceElement(t){if(this.dataType===$f)return String(t);let e=Number(t);return isNaN(e)?t:e}defaultElementValue(){return this.dataType===$f||this.templateWidgetType==="Text Update"?"":0}get value(){return super.value}set value(t){super.value=t,this.fullValue=Array.isArray(t)?t.slice():t!==void 0?[t]:[],this.scrollIndex=this.clampScrollbarIndex(this.scrollIndex),this.redistribute()}get effectiveArrayLength(){return this.pvName?this.fullValue.length:this.arrayLength}redistribute(){this.redistributing=!0;try{let t=this.effectiveArrayLength;for(let e=0;e<this.widgets.length;e++){let i=this.scrollIndex+e,r=i<t,s=r?this.fullValue[i]:this.defaultElementValue(),o=this.display.pvEngine.getPV(this.slotPvName(e));o&&(o.writable=r),this.display.pvEngine.setValue(new Date,this.slotPvName(e),s),this.forEachDescendant(this.widgets[e],n=>{n.properties.setValue("enabled",r?this.originalEnabled.get(n)??!0:!1)})}}finally{this.redistributing=!1}this.requestRepaint()}clampSpinnerIndex(t){let e=Math.max(0,this.effectiveArrayLength-1);return Math.min(Math.max(0,Math.round(t)),e)}clampScrollbarIndex(t){let e=Math.max(0,this.effectiveArrayLength-this.vec);return Math.min(Math.max(0,Math.round(t)),e)}setSpinnerIndex(t){let e=this.clampSpinnerIndex(t);e!==this.scrollIndex&&(this.scrollIndex=e,this.redistribute())}setScrollbarIndex(t){let e=this.clampScrollbarIndex(t);e!==this.scrollIndex&&(this.scrollIndex=e,this.redistribute())}setScrollIndex(t){this.setSpinnerIndex(t)}getScrollIndex(){return this.scrollIndex}stopSpinnerRepeating(t){window.clearTimeout(this.spinnerRepeatTimeout),t==="up"?this.spinnerUpPressed=!1:this.spinnerDownPressed=!1,this.requestRepaint()}stepSpinnerRepeatedly(t,e){window.clearTimeout(this.spinnerRepeatTimeout),this.setSpinnerIndex(this.scrollIndex+t),this.spinnerRepeatTimeout=window.setTimeout(()=>this.stepSpinnerRepeatedly(t,!1),e?oP:nP)}stopScrollbarRepeating(t){window.clearTimeout(this.scrollRepeatTimeout),t==="decrease"?this.scrollDecreasePressed=!1:this.scrollIncreasePressed=!1,this.requestRepaint()}stepScrollbarRepeatedly(t){window.clearTimeout(this.scrollRepeatTimeout),this.setScrollbarIndex(this.scrollIndex+t),this.scrollRepeatTimeout=window.setTimeout(()=>this.stepScrollbarRepeatedly(t),aP)}computeRegions(t,e,i,r,s){let o,n,a=0,l=0,h=t,c=e;return i>0&&(o={x:0,y:0,width:i,height:Math.min(s,e)},a+=i,h-=i),r>0&&(this.horizontal?(n={x:a,y:e-r,width:h,height:r},c-=r):(n={x:t-r,y:0,width:r,height:e},h-=r)),{spinnerBounds:o,scrollbarBounds:n,paneBounds:{x:a,y:l,width:h,height:c}}}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.layoutSlots()}layoutSlots(){if(!this.widgets.length)return;let t=this.properties.getValue("width"),e=this.properties.getValue("height"),{paneBounds:i}=this.computeRegions(t,e,this.showSpinner?this.spinnerWidth:0,this.showScrollbar?Yf:0,Uf);for(let r=0;r<this.widgets.length;r++){let s=this.widgets[r],o=this.horizontal?i.x+r*this.elementWidth:i.x,n=this.horizontal?i.y:i.y+r*this.elementHeight;s.properties.setValue("x",o),s.properties.setValue("y",n)}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){let e=t.createChildAt(this.x,this.y,this.width,this.height);for(let s of this.widgets.filter(o=>o.visible))s.drawHolder(e),s.draw(e),s.drawDecoration(e);let{scale:i}=this,r=this.computeRegions(this.width,this.height,this.showSpinner?this.spinnerWidth*i:0,this.showScrollbar?Yf*i:0,Uf*i);r.spinnerBounds&&this.drawSpinner(e,r.spinnerBounds),r.scrollbarBounds&&this.drawScrollbar(e,r.scrollbarBounds),this.drawGrayOverlay(e,r.paneBounds);for(let s of this.widgets.filter(o=>o.visible))s.drawOverlay(e);t.copyChild(e)}drawGrayOverlay(t,e){let i=Math.max(0,this.scrollIndex+this.vec-this.effectiveArrayLength);if(i<=0||!this.elementWidth||!this.elementHeight)return;let{scale:r}=this,s=this.vec-i,o=this.horizontal?{x:e.x+s*this.elementWidth*r,y:e.y,width:i*this.elementWidth*r,height:e.height}:{x:e.x,y:e.y+s*this.elementHeight*r,width:e.width,height:i*this.elementHeight*r};o.width<=0||o.height<=0||t.fillRect({...o,color:sP,opacity:40/255})}drawSpinner(t,e){let i=Math.min(e.width,rP*this.scale),r={x:e.x,y:e.y,width:i,height:e.height},s={x:e.x+i,y:e.y,width:Math.max(0,e.width-i),height:e.height},o=Math.floor(r.height/2),n={x:r.x,y:r.y,width:r.width,height:o},a={x:r.x,y:r.y+o,width:r.width,height:r.height-o};this.drawArrowButton(t,n,this.spinnerUpPressed,"up"),t.addHitRegion(this.spinnerUpRegion).addRect(n.x,n.y,n.width,n.height),this.drawArrowButton(t,a,this.spinnerDownPressed,"down"),t.addHitRegion(this.spinnerDownRegion).addRect(a.x,a.y,a.width,a.height),this.drawSpinnerLabel(t,s)}drawSpinnerLabel(t,e){if(this.spinnerLabelBounds=e,e.width<=0)return;t.fillRect({...e,color:m.WHITE}),t.strokeRect({...e,color:m.BUTTON_DARKER}),this.editingIndex||t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,baseline:"middle",align:"center",font:Y.ARIAL_11.scale(this.scale),color:m.BLACK,text:String(this.scrollIndex)}),t.addHitRegion(this.spinnerLabelRegion).addRect(e.x,e.y,e.width,e.height)}drawScrollbar(t,e){t.fillRect({...e,color:lP});let i=this.effectiveArrayLength,r=Math.max(1,Math.min(this.vec,Math.max(i,1))),s=Math.max(i,r,1),o=Math.max(1,s-r);if(this.horizontal){let n=Math.min(e.height,e.width/2),a={x:e.x,y:e.y,width:n,height:e.height},l={x:e.x+e.width-n,y:e.y,width:n,height:e.height};this.drawArrowButton(t,a,this.scrollDecreasePressed,"left"),this.drawArrowButton(t,l,this.scrollIncreasePressed,"right"),t.addHitRegion(this.scrollDecreaseRegion).addRect(a.x,a.y,a.width,a.height),t.addHitRegion(this.scrollIncreaseRegion).addRect(l.x,l.y,l.width,l.height);let d=e.x+n,g=Math.max(0,e.width-2*n),w=Math.min(g,Math.max(6*this.scale,Math.floor(g*r/s)));this.scrollDragRange=g-w;let x=Math.floor((g-w)*Math.min(this.scrollIndex,o)/o),_={x:d+x,y:e.y,width:w,height:e.height};this.drawThumb(t,_),this.registerPageRegion(t,this.scrollPageDecreaseRegion,d,e.y,x,e.height),this.registerPageRegion(t,this.scrollPageIncreaseRegion,d+x+w,e.y,g-x-w,e.height)}else{let n=Math.min(e.width,e.height/2),a={x:e.x,y:e.y,width:e.width,height:n},l={x:e.x,y:e.y+e.height-n,width:e.width,height:n};this.drawArrowButton(t,a,this.scrollDecreasePressed,"up"),this.drawArrowButton(t,l,this.scrollIncreasePressed,"down"),t.addHitRegion(this.scrollDecreaseRegion).addRect(a.x,a.y,a.width,a.height),t.addHitRegion(this.scrollIncreaseRegion).addRect(l.x,l.y,l.width,l.height);let d=e.y+n,g=Math.max(0,e.height-2*n),w=Math.min(g,Math.max(6*this.scale,Math.floor(g*r/s)));this.scrollDragRange=g-w;let x=Math.floor((g-w)*Math.min(this.scrollIndex,o)/o),_={x:e.x,y:d+x,width:e.width,height:w};this.drawThumb(t,_),this.registerPageRegion(t,this.scrollPageDecreaseRegion,e.x,d,e.width,x),this.registerPageRegion(t,this.scrollPageIncreaseRegion,e.x,d+x+w,e.width,g-x-w)}}registerPageRegion(t,e,i,r,s,o){if(s<=0||o<=0)return;t.addHitRegion(e).addRect(i,r,s,o)}drawThumb(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawBevelBorder(t,e,!1),t.addHitRegion(this.scrollThumbRegion).addRect(e.x,e.y,e.width,e.height)}drawBevelBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r+r/2,a=e.x+e.width-r+r/2,[l,h,c,d]=i?[m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER]:[m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST];t.strokePath({color:l,path:new R(a,n).lineTo(a,s).moveTo(a,n).lineTo(o,n)}),t.strokePath({color:h,path:new R(a-r,n-r).lineTo(a-r,s+r).moveTo(a-r,n-r).lineTo(o+r,n-r)}),t.strokePath({color:c,path:new R(o,s).lineTo(a-r,s).moveTo(o,s).lineTo(o,n-r)}),t.strokePath({color:d,path:new R(o+r,s+r).lineTo(a-r-r,s+r).moveTo(o+r,s+r).lineTo(o+r,n-r-r)})}drawArrowButton(t,e,i,r){t.fillRect({...e,color:i?m.BUTTON_DARKER:m.BUTTON}),this.drawBevelBorder(t,e,i);let s=Math.max(1,Math.min(3*this.scale,e.width/2-1,e.height/2-1)),o=Math.max(1,Math.min(2*this.scale,s)),n=e.x+e.width/2,a=e.y+e.height/2,l;r==="up"?l=new R(n,a-o).lineTo(n-s,a+o).lineTo(n+s,a+o).closePath():r==="down"?l=new R(n,a+o).lineTo(n-s,a-o).lineTo(n+s,a-o).closePath():r==="left"?l=new R(n-o,a).lineTo(n+o,a-s).lineTo(n+o,a+s).closePath():l=new R(n+o,a).lineTo(n-o,a-s).lineTo(n-o,a+s).closePath(),t.fillPath({color:m.BLACK,path:l})}get arrayLength(){return this.properties.getValue(Hf)}get spinnerWidth(){return this.properties.getValue(Df)}get horizontal(){return this.properties.getValue(Wf)}get showSpinner(){return this.properties.getValue(kf)}get showScrollbar(){return this.properties.getValue(Nf)}get vec(){return this.properties.getValue(Ff)}get dataType(){return this.properties.getValue(Gf)}};var Js="fc",zf="show_scrollbar",Xf="background_color",qf="foreground_color",hP=16,cP=20,Kf=150,pP=new m(243,243,243),jf=new m(232,232,231),ss=class extends st{scrollX=0;scrollY=0;maxScrollX=0;maxScrollY=0;contentWidth=0;contentHeight=0;dragRangeX;dragRangeY;grabStartX;grabStartY;actionTimeout;xDecPressed=!1;xIncPressed=!1;yDecPressed=!1;yIncPressed=!1;thumbXRegion;thumbYRegion;xDecRegion;xIncRegion;yDecRegion;yIncRegion;trackXBeforeRegion;trackXAfterRegion;trackYBeforeRegion;trackYAfterRegion;constructor(t,e){super(t,e),this.properties.add(new f(Js,!1)),this.properties.add(new f(zf,!0))}async parseNode(t){await super.parseNode(t);for(let i of t.getNodes("widget")){let r=i.getString("widget_type"),s=this.display.createWidget(r,this);s&&(await s.parseNode(i),this.widgets.push(s))}Ji(this.widgets);let e=()=>{if(this.forwardColors)for(let i of this.widgets)i.properties.setValue(Xf,this.backgroundColor),i.properties.setValue(qf,this.foregroundColor),i.requestRepaint()};this.addPropertyListener(Js,e),this.addPropertyListener(Xf,e),this.addPropertyListener(qf,e)}init(){this.thumbXRegion=this.makeThumbRegion("x"),this.thumbYRegion=this.makeThumbRegion("y"),this.xDecRegion=this.makeStepRegion("x",-1),this.xIncRegion=this.makeStepRegion("x",1),this.yDecRegion=this.makeStepRegion("y",-1),this.yIncRegion=this.makeStepRegion("y",1),this.trackXBeforeRegion=this.makePageRegion("x",-1),this.trackXAfterRegion=this.makePageRegion("x",1),this.trackYBeforeRegion=this.makePageRegion("y",-1),this.trackYAfterRegion=this.makePageRegion("y",1)}destroy(){window.clearTimeout(this.actionTimeout),super.destroy()}makeThumbRegion(t){return{id:`${this.wuid}-scrollbar-${t}-thumb`,mouseDown:()=>{t==="x"?this.grabStartX=this.scrollX:this.grabStartY=this.scrollY},grab:e=>{let i=t==="x"?this.maxScrollX:this.maxScrollY,r=(t==="x"?this.dragRangeX:this.dragRangeY)||1,s=t==="x"?e.dx:e.dy,o=(t==="x"?this.grabStartX:this.grabStartY)??0;this.setScrollOffset(t,o+i*s/r)},tooltip:()=>this.tooltip}}makeStepRegion(t,e){let i=r=>{t==="x"?e<0?this.xDecPressed=r:this.xIncPressed=r:e<0?this.yDecPressed=r:this.yIncPressed=r};return{id:`${this.wuid}-scrollbar-${t}-${e<0?"dec":"inc"}`,mouseDown:()=>{i(!0),this.stepScrollRepeatedly(t,e)},mouseUp:()=>this.endScrollAction(()=>i(!1)),mouseOut:()=>this.endScrollAction(()=>i(!1)),tooltip:()=>this.tooltip}}makePageRegion(t,e){return{id:`${this.wuid}-scrollbar-${t}-page-${e<0?"before":"after"}`,mouseDown:()=>this.pageScrollRepeatedly(t,e),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip}}setScrollOffset(t,e){let i=t==="x"?this.maxScrollX:this.maxScrollY,r=Math.min(Math.max(e,0),i);t==="x"?this.scrollX=r:this.scrollY=r,this.requestRepaint()}stepScrollRepeatedly(t,e){window.clearTimeout(this.actionTimeout);let i=t==="x"?this.scrollX:this.scrollY;this.setScrollOffset(t,i+e*cP*this.scale),this.actionTimeout=window.setTimeout(()=>this.stepScrollRepeatedly(t,e),Kf)}pageScrollRepeatedly(t,e){window.clearTimeout(this.actionTimeout);let i=t==="x"?this.scrollX:this.scrollY,r=t==="x"?this.contentWidth:this.contentHeight;this.setScrollOffset(t,i+e*r),this.actionTimeout=window.setTimeout(()=>this.pageScrollRepeatedly(t,e),Kf)}endScrollAction(t){window.clearTimeout(this.actionTimeout),t?.(),this.requestRepaint()}get forwardColors(){return this.properties.getValue(Js)}get showScrollbar(){return this.properties.getValue(zf)}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}measureContentExtent(){let t=this.width,e=this.height;for(let i of this.widgets.filter(r=>r.visible)){let r=i.bounds;t=Math.max(t,r.x+r.width),e=Math.max(e,r.y+r.height)}return{width:t,height:e}}resolveScrollbars(t,e,i){if(!this.showScrollbar)return{showH:!1,showV:!1};let r=t>this.width,s=e>this.height;return r&&!s&&e>this.height-i?s=!0:s&&!r&&t>this.width-i&&(r=!0),{showH:r,showV:s}}draw(t){let e=hP*this.scale,i=this.measureContentExtent(),{showH:r,showV:s}=this.resolveScrollbars(i.width,i.height,e);this.contentWidth=this.width-(s?e:0),this.contentHeight=this.height-(r?e:0),this.maxScrollX=Math.max(0,i.width-this.contentWidth),this.maxScrollY=Math.max(0,i.height-this.contentHeight),this.scrollX=Math.min(Math.max(this.scrollX,0),this.maxScrollX),this.scrollY=Math.min(Math.max(this.scrollY,0),this.maxScrollY);let o=t.createChildAt(this.x,this.y,this.width,this.height);o.translate(-this.scrollX,-this.scrollY),o.ctx.save(),o.ctx.beginPath(),o.ctx.rect(this.scrollX,this.scrollY,this.contentWidth,this.contentHeight),o.ctx.clip();for(let n of this.widgets.filter(a=>a.visible))n.drawHolder(o),n.draw(o),n.drawDecoration(o);for(let n of this.widgets.filter(a=>a.visible))n.drawOverlay(o);o.ctx.restore(),o.translate(this.scrollX,this.scrollY),r&&this.drawScrollbar(o,"x",{x:0,y:this.contentHeight,width:this.contentWidth,height:e}),s&&this.drawScrollbar(o,"y",{x:this.contentWidth,y:0,width:e,height:this.contentHeight}),t.copyChild(o)}drawScrollbar(t,e,i){let{scale:r}=this;t.fillRect({...i,color:pP});let s=e==="x",o=s?Math.min(i.height,i.width/2):Math.min(i.width,i.height/2),n=s?{x:i.x,y:i.y,width:o,height:i.height}:{x:i.x,y:i.y,width:i.width,height:o},a=s?{x:i.x+i.width-o,y:i.y,width:o,height:i.height}:{x:i.x,y:i.y+i.height-o,width:i.width,height:o};this.drawScrollButton(t,e,-1,n),this.drawScrollButton(t,e,1,a);let l=s?i.x+o:i.y+o,h=(s?i.width:i.height)-2*o,c=s?this.contentWidth:this.contentHeight,d=s?this.maxScrollX:this.maxScrollY,g=Math.min(1,c/(c+d)),w=Math.max(6*r,h*g);s?this.dragRangeX=h-w:this.dragRangeY=h-w;let x=s?this.scrollX:this.scrollY,_=d>0?x/d:0,L=l+(h-w)*_,A=s?{x:L,y:i.y,width:w,height:i.height}:{x:i.x,y:L,width:i.width,height:w};t.fillRect({...A,color:jf}),Ve(t,A,r);let E=s?this.thumbXRegion:this.thumbYRegion;t.addHitRegion(E).addRect(A.x,A.y,A.width,A.height);let I=l+h,k=s?this.trackXBeforeRegion:this.trackYBeforeRegion,F=s?this.trackXAfterRegion:this.trackYAfterRegion;s?(t.addHitRegion(k).addRect(l,i.y,L-l,i.height),t.addHitRegion(F).addRect(L+w,i.y,I-(L+w),i.height)):(t.addHitRegion(k).addRect(i.x,l,i.width,L-l),t.addHitRegion(F).addRect(i.x,L+w,i.width,I-(L+w)))}drawScrollButton(t,e,i,r){let{scale:s}=this,o=e==="x"?i<0?this.xDecPressed:this.xIncPressed:i<0?this.yDecPressed:this.yIncPressed;t.fillRect({...r,color:jf}),o?Or(t,r,s):Ve(t,r,s);let n=e==="x"?i<0?this.xDecRegion:this.xIncRegion:i<0?this.yDecRegion:this.yIncRegion;t.addHitRegion(n).addRect(r.x,r.y,r.width,r.height);let a=e==="x"?i<0?"left":"right":i<0?"up":"down";Er(t,r,s,a)}};var Zf="horizontal",Jf="panel1_auto_scale_children",Qf="panel2_auto_scale_children",Qs="sash_position",tw="sash_style",ew="sash_width",to="x",eo="y",os="width",ns="height",dP=0,uP=1,gP=2,mP=3,fP=4,wP=5,xP=12,as=class extends st{sashRegion;grabStartPosition;grabClientSize;panelOriginSizes=new Map;childOriginBounds=new Map;constructor(t,e){super(t,e),this.properties.add(new f(Zf,!0)),this.properties.add(new f(Jf,!1)),this.properties.add(new f(Qf,!1)),this.properties.add(new C(Qs,.5)),this.properties.add(new P(tw,gP)),this.properties.add(new P(ew,3))}async parseNode(t){await super.parseNode(t);for(let e of t.getNodes("widget")){let i=e.getString("widget_type"),r=this.display.createWidget(i,this);r&&(await r.parseNode(e),this.widgets.push(r))}}init(){this.sashRegion={id:`${this.wuid}-sash`,mouseDown:()=>{this.grabStartPosition=this.sashPosition,this.grabClientSize=this.horizontal?this.width:this.height},grab:t=>{if(this.grabStartPosition===void 0||!this.grabClientSize)return;let e=this.horizontal?t.dx:t.dy,i=this.sashWidth*this.scale,r=this.minPaneSize,s=r+i/2,o=this.grabClientSize-r-i/2,n=this.grabStartPosition*this.grabClientSize+e;n=Math.min(o,Math.max(s,n)),this.properties.setValue(Qs,n/this.grabClientSize),this.requestRepaint()}}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){let e=t.createChildAt(this.x,this.y,this.width,this.height),[i,r]=this.widgets;if(i&&r){let{boundsA:s,boundsB:o,sashBounds:n}=this.measureLayout();this.applyPanelBounds(i,s,this.panel1AutoScaleChildren),this.applyPanelBounds(r,o,this.panel2AutoScaleChildren);for(let a of[i,r])a.drawHolder(e),a.draw(e),a.drawDecoration(e);for(let a of[i,r])a.drawOverlay(e);this.drawSash(e,n,s,o)}t.copyChild(e)}measureLayout(){let{horizontal:t}=this,e=t?this.width:this.height,i=t?this.height:this.width,r=this.sashWidth*this.scale,s=Math.floor(r/2),o=this.minPaneSize,n=e-r-o,a=Math.floor(this.sashPosition*e-s);a=Math.min(n,Math.max(o,a));let l=e-a-r,h,c,d;return t?(h={x:0,y:0,width:a,height:i},c={x:a+r,y:0,width:l,height:i},d={x:a,y:0,width:r,height:i}):(h={x:0,y:0,width:i,height:a},c={x:0,y:a+r,width:i,height:l},d={x:0,y:a,width:i,height:r}),{boundsA:h,boundsB:c,sashBounds:d}}applyPanelBounds(t,e,i){let{scale:r}=this,s={x:e.x/r,y:e.y/r,width:e.width/r,height:e.height/r};i&&t instanceof st&&this.scalePanelChildren(t,s),t.properties.setValue(to,s.x),t.properties.setValue(eo,s.y),t.properties.setValue(os,s.width),t.properties.setValue(ns,s.height)}scalePanelChildren(t,e){let i=this.panelOriginSizes.get(t);i||(i={x:0,y:0,width:t.properties.getValue(os),height:t.properties.getValue(ns)},this.panelOriginSizes.set(t,i));let r=i.width?e.width/i.width:1,s=i.height?e.height/i.height:1;for(let o of t.widgets){let n=this.childOriginBounds.get(o);n||(n={x:o.properties.getValue(to),y:o.properties.getValue(eo),width:o.properties.getValue(os),height:o.properties.getValue(ns)},this.childOriginBounds.set(o,n)),o.properties.setValue(to,Math.round(n.x*r)),o.properties.setValue(eo,Math.round(n.y*s));let{widthScalable:a,heightScalable:l}=o.scaleOptions;if(a||l){let{width:h,height:c}=bi(n,r,s,o.scaleOptions);o.properties.setValue(os,h),o.properties.setValue(ns,c)}}}autoScale(t,e){M.prototype.autoScale.call(this,t,e)}drawSash(t,e,i,r){let{sashStyle:s}=this;if(s!==dP)if(s===uP){let o=6*this.scale;for(let n of[i,r])t.strokeRect({x:n.x+1,y:n.y+1,width:n.width-2,height:n.height-2,rx:o,ry:o,color:m.BUTTON_DARKER})}else if(s===fP){let o=this.horizontal?e.width:e.height,n=e.x+e.width/2,a=e.y+e.height/2,l=this.horizontal?new R(n,e.y).lineTo(n,e.y+e.height):new R(e.x,a).lineTo(e.x+e.width,a);t.strokePath({path:l,color:this.foregroundColor,lineWidth:o})}else if(s===wP)this.drawSashEdge(t,e,"near",m.BUTTON_DARKER),this.drawSashEdge(t,e,"far",m.BUTTON_DARKER);else{let o=s===mP;t.fillRect({...e,color:m.BUTTON}),this.drawSashEdge(t,e,"near",o?m.BUTTON_DARKER:m.BUTTON_LIGHTEST),this.drawSashEdge(t,e,"far",o?m.BUTTON_LIGHTEST:m.BUTTON_DARKER)}this.sashRegion&&(this.sashRegion.cursor=this.horizontal?"col-resize":"row-resize",t.addHitRegion(this.sashRegion).addRect(e.x,e.y,e.width,e.height))}drawSashEdge(t,e,i,r){let s=1*this.scale,o;if(this.horizontal){let n=i==="near"?e.x:e.x+e.width-s;o=new R(n,e.y).lineTo(n,e.y+e.height)}else{let n=i==="near"?e.y:e.y+e.height-s;o=new R(e.x,n).lineTo(e.x+e.width,n)}t.strokePath({path:o,color:r,lineWidth:s})}get horizontal(){return this.properties.getValue(Zf)}get minPaneSize(){return xP*this.scale}get panel1AutoScaleChildren(){return this.properties.getValue(Jf)}get panel2AutoScaleChildren(){return this.properties.getValue(Qf)}get sashPosition(){return this.properties.getValue(Qs)}get sashStyle(){return this.properties.getValue(tw)}get sashWidth(){return this.properties.getValue(ew)}};var iw="minimum_tab_height",ro="active_tab",rw="horizontal_tabs",io="tab_count",so=class{constructor(t,e){this.widget=t;this.i=e;this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(ro,e),t.requestRepaint())},cursor:"pointer"}}headerRegion;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)}},ei=class extends st{tabs=[];constructor(t,e){super(t,e),this.properties.add(new P(iw)),this.properties.add(new P(ro)),this.properties.add(new f(rw)),this.properties.add(new P(io)),this.properties.addGenerator(()=>{this.tabs=[];let i=this.properties.getValue(io),r=[];for(let s=0;s<i;s++)this.tabs.push(new so(this,s)),r.push(new T(`tab_${s}_title`),new S(`tab_${s}_background_color`),new S(`tab_${s}_foreground_color`),new f(`tab_${s}_enabled`),new H(`tab_${s}_font`));return r})}async parseNode(t){await super.parseNode(t);for(let e of t.getNodes("widget")){let i=e.getString("widget_type"),r=this.display.createWidget(i,this);r&&(await r.parseNode(e),this.widgets.push(r))}}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){let{scale:e}=this,i=1*e,r=this.minimumTabHeight;for(let s=0;s<this.tabs.length;s++){let o=this.tabs[s],a=t.measureText(o.title,o.font).height+i;a>r&&(r=a)}return r+this.margin}measureLabelWidth(t){let{scale:e}=this,i=1*e,r=this.minimumTabWidth;for(let s=0;s<this.tabs.length;s++){let o=this.tabs[s],a=t.measureText(o.title,o.font).width+i;a>r&&(r=a)}return r+this.margin}drawHorizontalTabs(t){let{margin:e,gap:i,scale:r}=this,s=this.measureLabelHeight(t),o=1*r,n=this.x;for(let a=0;a<this.tabs.length;a++){let l=this.tabs[a],h=t.measureText(l.title,l.font),c,d,g,w,x;this.activeTab===a?(c=n,d=this.y,g=h.width+o+e+i,w=s,x=l.backgroundColor):(c=n+i,d=this.y+2*r,g=h.width+o+e-i,w=s-2*r,x=this.darken(l.backgroundColor)),t.fillRect({x:c,y:d,width:g,height:w,color:x}),t.addHitRegion(l.headerRegion).addRect(c,d,g,w);let L=t.createLinearGradient(c,d,c,d+w);if(L.addColorStop(0,m.WHITE.toString()),L.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:c,y:d,width:g,height:w,gradient:L}),t.fillText({x:c+g/2,y:d+w/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=h.width+o+e-1*r,this.activeTab===a){let A=this.x,E=this.y+s,I=this.width,k=this.height-s;t.fillRect({x:A,y:E,width:I,height:k,color:l.backgroundColor});let F=this.widgets[a],z=t.createChildAt(A,E,I,k);F.drawHolder(z),F.draw(z),F.drawDecoration(z),F.drawOverlay(z),t.copyChild(z)}else this.widgets[a].hide()}}drawVerticalTabs(t){let{margin:e,gap:i,scale:r}=this,s=this.measureLabelWidth(t),o=1*r,n=this.y;for(let a=0;a<this.tabs.length;a++){let l=this.tabs[a],h=t.measureText(l.title,l.font),c=Math.max(h.height+o+o,this.minimumTabHeight),d,g,w,x,_;this.activeTab===a?(d=this.x,g=n,w=s,x=c+e+i,_=l.backgroundColor):(d=this.x+2*r,g=n+i,w=s-2*r,x=c+e-i,_=this.darken(l.backgroundColor)),t.fillRect({x:d,y:g,width:w,height:x,color:_}),t.addHitRegion(l.headerRegion).addRect(d,g,w,x);let A=t.createLinearGradient(d,g,d+w,g);if(A.addColorStop(0,m.WHITE.toString()),A.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:d,y:g,width:w,height:x,gradient:A}),t.fillText({x:d+w/2,y:g+x/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=c+e-1*r,this.activeTab===a){let E=this.x+s-1*r,I=this.y,k=this.width-s,F=this.height-1*r;t.fillRect({x:E,y:I,width:k,height:F,color:l.backgroundColor});let z=this.widgets[a],j=t.createChildAt(E,I,k,F);z.drawHolder(j),z.draw(j),z.drawDecoration(j),z.drawOverlay(j),t.copyChild(j)}else this.widgets[a].destroy()}}darken(t){let e=Math.max(0,t.red-30),i=Math.max(0,t.green-30),r=Math.max(0,t.blue-30);return new m(e,i,r)}get margin(){return this.scale*10}get gap(){return this.scale*2}get minimumTabWidth(){return this.scale*20}get minimumTabHeight(){return this.scale*this.properties.getValue(iw)}get activeTab(){return this.properties.getValue(ro)}get tabCount(){return this.properties.getValue(io)}get horizontalTabs(){return this.properties.getValue(rw)}};var ls=class{constructor(t){this.table=t}columnCount=0;cells=[];selectedRowIndex;dirty=!1;modifiedListeners=[];selectionChangedListeners=[];isEmpty(){return!this.cells.length}refresh(){this.dirty=!0}getCells(){return this.cells}getContent(){let t=[];for(let e of this.cells)t.push(e.map(i=>i.text||""));return t}setContent(t){this.cells.length=0;for(let e=0;e<t.length;e++)e===0&&(this.columnCount=t[e].length),this.cells.push(t[e].map(i=>({text:i})));this.dirty=!0}getColumnCount(){return this.columnCount}getRowCount(){return this.cells.length}setSelectedRowIndex(t){this.selectedRowIndex=t,this.selectionChangedListeners.forEach(e=>e()),this.dirty=!0}getSelection(){return this.selectedRowIndex===void 0?[]:[[...this.cells[this.selectedRowIndex].map(e=>e.text??null)]]}getCellText(t,e){let i=this.cells[t];return i?i[e]?.text??null:null}setColumnsCount(t){if(t<this.columnCount)for(let e of this.cells)e.length=t;if(t>this.columnCount){let e=t-this.columnCount;for(let i of this.cells)for(let r=0;r<e;r++)i.push({text:""})}this.columnCount=t,this.dirty=!0}addModifiedListener(t){this.modifiedListeners.push(t)}addSelectionChangedListener(t){this.selectionChangedListeners.push(t)}appendRow(){let t=[];for(let e=0;e<this.columnCount;e++)t[e]={text:""};return this.cells.push(t),this.dirty=!0,this.cells.length-1}deleteRow(t){this.cells.splice(t,1),this.dirty=!0}deleteColumn(t){for(let e of this.cells)e.splice(t,1);this.columnCount--,this.dirty=!0}insertRow(t){let e=[];for(let i=0;i<this.columnCount;i++)e.push({text:""});this.cells.splice(t,0,e),this.dirty=!0}insertColumn(t){for(let e of this.cells)e.splice(t,0,{text:""});this.columnCount++,this.dirty=!0}getCell(t,e){this.cells[t]=this.cells[t]??[];let i=this.cells[t][e]??{};return this.cells[t][e]=i,i}setCellText(t,e,i){let r=this.getCell(t,e);r.text=i,this.dirty=!0}setRowBackground(t,e){let i=this.cells[t];for(let r of i)r.backgroundColor=e;this.dirty=!0}setRowForeground(t,e){let i=this.cells[t];for(let r of i)r.foregroundColor=e;this.dirty=!0}setCellBackground(t,e,i){let r=this.getCell(t,e);r.backgroundColor=i,this.dirty=!0}setCellForeground(t,e,i){let r=this.getCell(t,e);r.foregroundColor=i,this.dirty=!0}setColumnCellEditorData(t,e){}};var sw="columns_count",ow="column_headers",nw="column_header_visible",aw="default_content",lw="font",hs=class extends M{tableWrapper;table;spreadsheet;constructor(t,e){super(t,e),this.properties.add(new P(sw)),this.properties.add(new xe(ow)),this.properties.add(new f(nw)),this.properties.add(new xe(aw)),this.properties.add(new H(lw)),this.spreadsheet=new ls(this)}init(){this.tableWrapper=document.createElement("div"),this.tableWrapper.style.display="none",this.tableWrapper.style.overflow="auto",this.table=document.createElement("table"),this.table.style.tableLayout="fixed",this.table.style.borderSpacing="0",this.table.style.borderCollapse="collapse",this.tableWrapper.appendChild(this.table),this.display.rootPanel.appendChild(this.tableWrapper),this.table.addEventListener("click",t=>{let e=t.target;if(e.tagName==="TD"){let i=e.parentElement;i.rowIndex>0&&this.spreadsheet.setSelectedRowIndex(i.rowIndex-1)}else this.spreadsheet.setSelectedRowIndex(void 0);this.requestRepaint()}),this.spreadsheet.setContent(this.defaultContent)}draw(t){if(this.tableWrapper){let{x:e,y:i,width:r,height:s}=this.display.measureAbsoluteArea(this);this.tableWrapper.style.backgroundColor="white",this.tableWrapper.style.position="absolute",this.tableWrapper.style.display="block",this.tableWrapper.style.left=`${e}px`,this.tableWrapper.style.top=`${i}px`,this.tableWrapper.style.width=`${r}px`,this.tableWrapper.style.height=`${s}px`,this.tableWrapper.style.border="1px solid rgba(0, 0, 0, 0.1)",this.table.style.font=this.font.getFontString(),this.spreadsheet.dirty&&(this.generateTableContent(),this.spreadsheet.dirty=!1)}}generateTableContent(){let t=this.table.rows.length;for(let i=t-1;i>=0;i--)this.table.deleteRow(i);if(this.columnHeaderVisible){let i=this.table.insertRow();for(let r=0;r<this.columnsCount;r++){let s=this.columnHeaders[r],o=i.insertCell();o.style.color="#aaa",o.style.textAlign="left",s?.length>=2&&s[1]!==""&&(o.style.width=Number(s[1])*this.scale+"px"),o.style.overflow="hidden",o.style.padding=`${4*this.scale}px`,o.style.borderBottom="1px solid rgba(0, 0, 0, 0.1)",r!==0&&(o.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)");let n="";s?.length>=1&&(n=s[0]);let a=document.createTextNode(n);o.appendChild(a)}i.insertCell()}let e=this.spreadsheet.getCells();for(let i=0;i<e.length;i++){let r=e[i],s=i===this.spreadsheet.selectedRowIndex,o=this.table.insertRow();for(let n=0;n<this.columnsCount;n++){let a=o.insertCell();if(a.style.textAlign="left",a.style.overflow="hidden",a.style.wordWrap="break-word",a.style.textOverflow="ellipsis",a.style.padding=`${4*this.scale}px`,n!==0&&(a.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)"),r[n]!==void 0){let l=s?m.BLUE:r[n].backgroundColor;l&&(a.style.backgroundColor=l.toString());let h=s?m.WHITE:r[n].foregroundColor;h&&(a.style.color=h.toString());let c=document.createTextNode(r[n].text||"");a.appendChild(c)}}o.insertCell()}}hide(){this.tableWrapper&&(this.tableWrapper.style.display="none")}destroy(){this.tableWrapper&&(this.display.rootPanel.removeChild(this.tableWrapper),this.tableWrapper=void 0,this.table=void 0)}get columnsCount(){return this.properties.getValue(sw)}get columnHeaders(){return this.properties.getValue(ow)}get columnHeaderVisible(){return this.properties.getValue(nw)}get defaultContent(){return this.properties.getValue(aw)}get font(){return this.properties.getValue(lw).scale(this.scale)}};var hw="url",cs=class extends M{iframe;prevUrl;constructor(t,e){super(t,e),this.properties.add(new T(hw))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){let{x:e,y:i,width:r,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${e}px`,this.iframe.style.top=`${i}px`,this.iframe.style.width=`${r}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(hw)}};var yP="Action Button",PP="Arc",bP="Array",vP="Boolean Button",RP="Boolean Switch",_P="Byte Monitor",TP="Check Box",SP="Choice Button",LP="Combo",CP="Combo Box",AP="Ellipse",OP="Gauge",EP="Grid Layout",MP="Grouping Container",VP="Image",IP="Image Boolean Button",BP="Image Boolean Indicator",HP="Intensity Graph",DP="Knob",WP="Label",kP="LED",NP="Linking Container",FP="Menu Button",GP="Meter",$P="Button",UP="Polygon",YP="Polyline",zP="Progress Bar",XP="Radio Box",qP="Rectangle",KP="Rounded Rectangle",jP="Sash Container",ZP="Scaled Slider",JP="Scrollbar",QP="Spinner",tb="Tabbed Container",eb="Table",ib="Tank",rb="Text Input",sb="Text Update",ob="Thermometer",nb="Thumb Wheel",ab="Web Browser",lb="XY Graph";function oo(){return window.devicePixelRatio||1}var ps=class{constructor(t){this.targetElement=t;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",this.rootPanel.style.flexShrink="0",this.rootPanel.style.margin="auto",t.appendChild(this.rootPanel),t.style.position="relative",t.style.display="flex";let e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new yi(e),this.ctx=this.g.ctx,this.formatter=new di(!1),this.pvEngine=new or(this),this.pvEngine.addProvider(new ar),this.pvEngine.addProvider(new lr(this.formatter)),this.pvEngine.addProvider(new rr),this.displayRegion={id:"display-root",click:()=>{for(let i of this.rootPanel.getElementsByTagName("input"))i.blur();for(let i of this.rootPanel.getElementsByTagName("textarea"))i.blur();for(let i of this.rootPanel.getElementsByTagName("select"))i.blur()}},this.pathResolver=new Qi(this),this.scriptLoader=new tr(this),this.consoleHandler=new li,this.dialogHandler=new hi,this.imageLoader=new Pi,this.stepTimer=window.setTimeout(()=>this.step()),this.eventHandler=new pi(this,e,this.g.hitCanvas),this.resizeObserver=new ResizeObserver(()=>this.requestRepaint()),this.resizeObserver.observe(t)}rootPanel;g;ctx;pvEngine;pathResolver;fontResolver;scriptLoader;imageLoader;consoleHandler;dialogHandler;formatter;repaintRequested=!1;_editMode=!1;_showGrid=!1;_showOutline=!1;_showRuler=!1;_selection=[];_scale=1;_pixelRatio=oo();pixelRatioOverridden=!1;_transparent=!1;_disconnectedColor=new m(160,32,240);_invalidColor=new m(255,0,255);_majorColor=new m(255,0,0);_minorColor=new m(255,128,0);refreshCycle=100;originDesignSize;wasAutoScaleActive=!1;_autoScaleOverride="DEFAULT";resizeObserver;eventHandler;stepTimer;imagesPrefix="";absPrefix="";relPrefix="";instance;eventListeners={closedisplay:[],displayloaded:[],opendisplay:[],openpv:[],runcommand:[],runprocedure:[],runstack:[],selection:[],scale:[]};displayRegion;addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}setPathResolver(t){this.pathResolver=t}getPathResolver(){return this.pathResolver}setScriptLoader(t){this.scriptLoader=t}getScriptLoader(){return this.scriptLoader}loadContent(t){return this.scriptLoader.load(t)}setImageLoader(t){this.imageLoader=t}getImageLoader(){return this.imageLoader}setConsoleHandler(t){this.consoleHandler=t}getConsoleHandler(){return this.consoleHandler}setDialogHandler(t){this.dialogHandler=t}getDialogHandler(){return this.dialogHandler}setFontResolver(t){this.fontResolver=t}getFontResolver(){return this.fontResolver}step(){!this.pixelRatioOverridden&&this._pixelRatio!==oo()&&(this._pixelRatio=oo(),this.requestRepaint()),this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),this.stepTimer=window.setTimeout(()=>this.step(),this.refreshCycle)}drawScreen(){let t=this.rootPanel.style;if(t.position="relative",t.inset="",t.width="",t.height="",this.instance){let i=this.measureContainerSize();i&&this.isAutoScaleActive()?(t.position="absolute",t.inset="0",this.applyAutoScale(i)):(this.revertAutoScale(),t.width=this.instance.holderWidth+"px",t.height=this.instance.holderHeight+"px")}else t.width="0px",t.height="0px";if(this.g.pixelRatio=this._pixelRatio,this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){let i=document.createElement("canvas"),r=i.getContext("2d");i.width=16,i.height=16,r.fillStyle="#d6d6d6",r.fillRect(0,0,8,8),r.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(i,"repeat"),this.ctx.fillRect(0,0,this.g.cssWidth,this.g.cssHeight),this.instance&&this.g.fillRect({...this.instance.bounds,color:this.instance.backgroundColor})}else this.transparent||this.g.fillCanvas(this.instance?.backgroundColor||m.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.g.cssWidth,this.g.cssHeight),this.showGrid&&this.instance){let i=document.createElement("canvas"),r=i.getContext("2d");i.width=25,i.height=25,r.fillStyle=this.instance.foregroundColor.toString(),r.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(i,"repeat"),this.ctx.fillRect(25,25,this.g.cssWidth-50,this.g.cssHeight-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 i=0;for(;i<=this.g.cssWidth;)i+=100,this.ctx.beginPath(),this.ctx.moveTo(i-75+.5,this.g.cssHeight),this.ctx.lineTo(i-75+.5,this.g.cssHeight-4),this.ctx.moveTo(i-50+.5,this.g.cssHeight),this.ctx.lineTo(i-50+.5,this.g.cssHeight-6),this.ctx.moveTo(i-25+.5,this.g.cssHeight),this.ctx.lineTo(i-25+.5,this.g.cssHeight-4),this.ctx.moveTo(i+.5,this.g.cssHeight),this.ctx.lineTo(i+.5,this.g.cssHeight-8),this.ctx.stroke(),this.ctx.fillText(String(i),i,this.g.cssHeight-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let r=0;for(;r<=this.g.cssHeight;)r+=100,this.ctx.beginPath(),this.ctx.moveTo(this.g.cssWidth,r-75+.5),this.ctx.lineTo(this.g.cssWidth-4,r-75+.5),this.ctx.moveTo(this.g.cssWidth,r-50+.5),this.ctx.lineTo(this.g.cssWidth-6,r-50+.5),this.ctx.moveTo(this.g.cssWidth,r-25+.5),this.ctx.lineTo(this.g.cssWidth-4,r-25+.5),this.ctx.moveTo(this.g.cssWidth,r+.5),this.ctx.lineTo(this.g.cssWidth-8,r+.5),this.ctx.stroke(),this.ctx.fillText(String(r),this.g.cssWidth-8,r)}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(let i of this.selection){let r=this.findWidget(i);r&&r.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){this.rootPanel.title=t?.trim()??""}createWidget(t,e){switch(t){case yP:return new Ee(this,e);case PP:return new Lr(this,e);case bP:return new rs(this,e);case vP:return new hr(this,e);case RP:return new cr(this,e);case _P:return new Dr(this,e);case TP:return new pr(this,e);case SP:return new dr(this,e);case LP:case CP:return new ur(this,e);case AP:return new Cr(this,e);case OP:return new kr(this,e);case EP:return new Ze(this,e);case MP:return new ss(this,e);case VP:return new Ar(this,e);case IP:return new gr(this,e);case BP:return new Nr(this,e);case HP:return new Gr(this,e);case DP:return new fr(this,e);case WP:return new Mr(this,e);case kP:return new $r(this,e);case NP:return new Le(this,e);case FP:return new wr(this,e);case GP:return new Yr(this,e);case $P:return new xr(this,e);case UP:return new Vr(this,e);case YP:return new Ir(this,e);case zP:return new zr(this,e);case XP:return new yr(this,e);case qP:return new Br(this,e);case KP:return new Hr(this,e);case jP:return new as(this,e);case ZP:return new Pr(this,e);case JP:return new vr(this,e);case QP:return new Rr(this,e);case tb:return new ei(this,e);case eb:return new hs(this,e);case ib:return new Xr(this,e);case rb:return new _r(this,e);case sb:return new qr(this,e);case ob:return new Kr(this,e);case nb:return new Sr(this,e);case ab:return new cs(this,e);case lb:return new is(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){this.instance?.destroy(),this.instance=void 0,this.pvEngine.clearState(),window.clearTimeout(this.stepTimer),this.resizeObserver.disconnect(),this.eventHandler.destroy(),this.rootPanel.remove(),this.targetElement.style.position="",this.targetElement.style.display=""}resolvePath(t,e){return this.pathResolver.resolve(t,e)}setSource(t,e){this.reset();let i=t.lastIndexOf("/")+1;return this.relPrefix=t.substring(0,i),new Promise((r,s)=>{fetch(t,{credentials:"same-origin"}).then(o=>{o.ok&&o.text().then(n=>{this.setSourceString(n,e),r()}).catch(n=>s(n))}).catch(o=>s(o))})}setSourceString(t,e){this.reset(),this.instance=new Se(this,void 0,e);let i=Te.parseFromXML(t);this.instance.parseNode(i).then(()=>{this.originDesignSize=this.instance.designSize,this.pvEngine.init(),this.requestRepaint();let r={backgroundColor:this.instance.backgroundColor.toString()};this.fireEvent("displayloaded",r)})}getRefreshCycle(){return this.refreshCycle}setRefreshCycle(t){this.refreshCycle=t}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0),this.originDesignSize=void 0,this.wasAutoScaleActive=!1}measureAbsoluteOffset(t){let e=0,i=0,r=t.parent;for(;r;){if(e+=r.x,i+=r.y,r instanceof ei){let s=r.measureTabOffset(this.g);e+=s.x,i+=s.y}r=r.parent}return{x:e,y:i}}measureAbsoluteArea(t){let e=t.bounds,i=this.measureAbsoluteOffset(t);return e.x+=i.x,e.y+=i.y,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+=this.scale*1,e.y+=this.scale*1,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(i=>i!==e)}fireEvent(t,e){this.eventListeners[t].forEach(r=>r(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();let 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();let e={scale:t};this.fireEvent("scale",e)}get autoScaleOverride(){return this._autoScaleOverride}set autoScaleOverride(t){this._autoScaleOverride=t,this.requestRepaint()}isAutoScaleActive(){if(!this.instance)return!1;switch(this._autoScaleOverride){case"ENABLED":return!0;case"DISABLED":return!1;case"DEFAULT":return this.instance.autoScaleWidgets.autoScaleWidgets}}measureContainerSize(){let t=this.targetElement.clientWidth,e=this.targetElement.clientHeight;return t&&e?{width:t,height:e}:void 0}applyAutoScale(t){if(!this.instance||!this.originDesignSize)return;this.wasAutoScaleActive=!0;let{width:e,height:i}=this.originDesignSize;if(!e||!i)return;let r=t.width/e,s=t.height/i,{minWidth:o,minHeight:n}=this.instance.autoScaleWidgets,a=o<0?e:o,l=n<0?i:n;e*r<a&&(r=a/e),i*s<l&&(s=l/i),this.instance.autoScale(r,s)}revertAutoScale(){this.instance&&this.wasAutoScaleActive&&this.instance.autoScale(1,1),this.wasAutoScaleActive=!1}get pixelRatio(){return this._pixelRatio}set pixelRatio(t){this._pixelRatio=t,this.pixelRatioOverridden=!0,this.requestRepaint()}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get utc(){return this.formatter.utc}set utc(t){this.formatter.utc=t,this.requestRepaint()}get disconnectedColor(){return this._disconnectedColor}set disconnectedColor(t){this._disconnectedColor=t,this.requestRepaint()}get invalidColor(){return this._invalidColor}set invalidColor(t){this._invalidColor=t,this.requestRepaint()}get majorColor(){return this._majorColor}set majorColor(t){this._majorColor=t,this.requestRepaint()}get minorColor(){return this._minorColor}set minorColor(t){this._minorColor=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.setExternalValues(t)}copyCanvas(t){let e=this.g.pixelRatio,i=t?{x:t.x*e,y:t.y*e,width:t.width*e,height:t.height*e}:{x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height},r=document.createElement("canvas");return r.width=i.width,r.height=i.height,r.getContext("2d").drawImage(this.g.canvas,i.x,i.y,i.width,i.height,0,0,i.width,i.height),r}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}};var ds=class{pending=new Map;load(t){return new Promise(e=>{let i=this.pending.get(t);i?i.push(e):(this.pending.set(t,[e]),window.parent.postMessage({type:"loadImage",url:t},"*"))})}receiveData(t,e){let i=this.pending.get(t)??[];this.pending.delete(t);let r=e??t;for(let s of i)s(r)}};var us=class{cache=new Map;ttl=5e3;pending=new Map;async load(t){this.removeOldEntries();let e=this.cache.get(t);if(e)return e.text;let i=this.pending.get(t);return i?new Promise(r=>i.push(r)):new Promise(r=>{this.pending.set(t,[r]),window.parent.postMessage({type:"loadScript",path:t},"*")})}receiveContent(t,e){e!==null&&this.cache.set(t,{timestamp:Date.now(),text:e});let i=this.pending.get(t);if(i){this.pending.delete(t);for(let r of i)r(e)}}removeOldEntries(){let t=Date.now();this.cache.forEach((e,i)=>{e.timestamp+this.ttl<=t&&this.cache.delete(i)})}};var ii=new Map;function cw(p,t){for(let e of ii.get(p)??[])e.updateSamples(t)}var gs=class{constructor(t,e){this.pvName=t;this.widget=e;let i=ii.get(t)??[],r=i.length>0;i.push(this),ii.set(t,i),r||window.parent.postMessage({type:"historySubscribe",pvName:t},"*")}samples=[];getSamples(){return this.samples}updateSamples(t){this.samples=t,this.widget.requestRepaint()}disconnect(){let t=ii.get(this.pvName)??[],e=t.indexOf(this);e!==-1&&t.splice(e,1),t.length===0&&(ii.delete(this.pvName),window.parent.postMessage({type:"historyUnsubscribe",pvName:this.pvName},"*"))}};var ms=class{canProvide(t){return!0}startProviding(t){window.parent.postMessage({type:"subscribe",pvNames:t.map(e=>e.name)},"*")}stopProviding(t){window.parent.postMessage({type:"unsubscribe",pvNames:t.map(e=>e.name)},"*")}isNavigable(){return!0}writeValue(t,e){window.parent.postMessage({type:"write",pvName:t,value:e},"*")}createHistoricalDataProvider(t,e){return new gs(t,e)}shutdown(){}};var U=null,no=null,ao=null;window.addEventListener("message",p=>{if(p.source!==window.parent)return;let t=p.data;if(t?.type)switch(t.type){case"init":{let e=document.getElementById("display");if(!e)break;U=new ps(e),no=new us,ao=new ds,U.setImageLoader(ao);let{config:i}=t;i.legacyFontSizing&&(Y.LEGACY_FONT_SIZING=!0),U.disconnectedColor=Ne(i.disconnectedColor),U.invalidColor=Ne(i.invalidColor),U.majorColor=Ne(i.majorColor),U.minorColor=Ne(i.minorColor),U.utc=i.utc,U.imagesPrefix=t.imagesPrefix,U.absPrefix=t.absPrefix,U.relPrefix=t.relPrefix;let r=t.mediaPrefix;if(U.setFontResolver({resolve(s){let o;if(s.name==="Liberation Sans"?s.bold&&s.italic?o="LiberationSans-BoldItalic.woff2":s.bold?o="LiberationSans-Bold.woff2":s.italic?o="LiberationSans-Italic.woff2":o="LiberationSans-Regular.woff2":s.name==="Liberation Mono"?s.bold&&s.italic?o="LiberationMono-BoldItalic.woff2":s.bold?o="LiberationMono-Bold.woff2":s.italic?o="LiberationMono-Italic.woff2":o="LiberationMono-Regular.woff2":s.name==="Liberation Serif"?s.bold&&s.italic?o="LiberationSerif-BoldItalic.woff2":s.bold?o="LiberationSerif-Bold.woff2":s.italic?o="LiberationSerif-Italic.woff2":o="LiberationSerif-Regular.woff2":s.name==="Arial"?s.bold&&s.italic?o="LiberationSans-BoldItalic.woff2":s.bold?o="LiberationSans-Bold.woff2":s.italic?o="LiberationSans-Italic.woff2":o="LiberationSans-Regular.woff2":s.name==="Times New Roman"?s.bold&&s.italic?o="LiberationSerif-BoldItalic.woff2":s.bold?o="LiberationSerif-Bold.woff2":s.italic?o="LiberationSerif-Italic.woff2":o="LiberationSerif-Regular.woff2":s.name==="Courier New"&&(s.bold&&s.italic?o="LiberationMono-BoldItalic.woff2":s.bold?o="LiberationMono-Bold.woff2":s.italic?o="LiberationMono-Italic.woff2":o="LiberationMono-Regular.woff2"),o){let n=Pe[s.name]??s.name;return new FontFace(n,`url(${r}${o})`,{weight:s.bold?"bold":"normal",style:s.italic?"italic":"normal"})}}}),U.addProvider(new ms),U.setScriptLoader(no),U.addScriptLibrary("Yamcs",{issueCommand(s,o){window.parent.postMessage({type:"runcommand",command:s,args:o??{}},"*")},runProcedure(s,o){let n={};if(o)for(let a of Object.keys(o))n[a]=String(o[a]);window.parent.postMessage({type:"runprocedure",procedure:s,args:n},"*")}}),U.addEventListener("displayloaded",s=>{window.parent.postMessage({type:"displaybackground",color:s.backgroundColor},"*")}),U.addEventListener("opendisplay",s=>{window.parent.postMessage({type:"opendisplay",path:s.path,replace:s.replace,args:s.args},"*")}),U.addEventListener("closedisplay",()=>{window.parent.postMessage({type:"closedisplay"},"*")}),U.addEventListener("openpv",s=>{window.parent.postMessage({type:"openpv",pvName:s.pvName},"*")}),U.addEventListener("runcommand",s=>{window.parent.postMessage({type:"runcommand",command:s.command,args:s.args},"*")}),U.addEventListener("runstack",s=>{window.parent.postMessage({type:"runstack",path:s.path},"*")}),U.addEventListener("runprocedure",s=>{window.parent.postMessage({type:"runprocedure",procedure:s.procedure,args:s.args},"*")}),U.addEventListener("scale",s=>{window.parent.postMessage({type:"scale",scale:s.scale},"*")}),U.setSourceString(t.xml,t.args),t.zoomMode==="fit"&&U.instance){let{width:s,height:o}=U.instance.unscaledBounds;s&&o&&(U.scale=Math.min(t.containerWidth/s,t.containerHeight/o))}break}case"pvData":{if(!U)break;for(let[i,r]of Object.entries(t.meta)){let s=U.getPV(i);s&&(r.labels&&(s.labels=r.labels),s.writable=r.writable)}for(let i of t.disconnected){let r=U.getPV(i);r&&(r.disconnected=!0)}let e=new Map;for(let[i,r]of Object.entries(t.samples))e.set(i,r);e.size>0&&U.setValues(e);break}case"scriptContent":{no?.receiveContent(t.path,t.content);break}case"imageData":{ao?.receiveData(t.url,t.dataUrl);break}case"historySamples":{cw(t.pvName,t.samples);break}case"setScale":{U&&(U.scale=t.scale);break}case"fitZoom":{if(U?.instance){let{width:e,height:i}=U.instance.unscaledBounds;e&&i&&(U.scale=Math.min(t.containerWidth/e,t.containerHeight/i))}break}case"setAutoScaleOverride":{U&&(U.autoScaleOverride=t.value);break}}});})();
19
+ `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return i.formatDate(e,{year:!0,month:!0,day:!0});case 7:let r=this.formatter.utc,s=ry[r?e.getUTCMonth():e.getMonth()],o=r?e.getUTCDate():e.getDate();return`${s} ${o}`;case 8:let n=Math.abs(this.maximum-this.minimum);return n<=5e3?i.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):n<=18e5?i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):n<=864e5?i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):n<=6048e5?i.formatDate(e,{year:!1,month:!0,day:!0})+`
20
+ `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):n<=2592e6?i.formatDate(e,{year:!1,month:!0,day:!0}):i.formatDate(e,{year:!0,month:!0,day:!0})}return""}get spaceBetweenMarkAndLabel(){return this.scale*2}get majorTickLength(){return this.scale*6}get minorTickLength(){return this.scale*3}get minorTickMarkStepHint(){return this.scale*4}get tickLabelGap(){return this.horizontal?this.scale*10:this.scale*2}};var sy=100/255,oy=20,ny=11,ay=6,ly=5,hy=150,xh="color_hi",yh="color_hihi",Ph="color_lo",bh="color_lolo",vh="color_fillbackground",Rh="effect_3d",_h="fill_color",Th="font",Sh="horizontal",Lh="level_hi",Ch="level_hihi",Ah="level_lo",Oh="level_lolo",Eh="limits_from_pv",Mh="log_scale",Vh="major_tick_step_hint",Ih="maximum",Bh="minimum",Hh="page_increment",Dh="scale_font",Wh="scale_format",kh="show_hi",Nh="show_hihi",Fh="show_lo",Gh="show_lolo",$h="show_markers",Uh="show_minor_ticks",Yh="show_scale",zh="step_increment",Xh="thumb_color",qh="transparent_background",Kh="value_label_format",vr=class extends M{trackRegion;thumbRegion;grabStartValue;trackScale;pageTimeout;pageUp=!1;pagePressedValue=0;hoveringThumb=!1;draggingThumb=!1;constructor(t,e){super(t,e),this.properties.add(new L(xh,new m(255,128,0))),this.properties.add(new L(yh,new m(255,0,0))),this.properties.add(new L(Ph,new m(255,128,0))),this.properties.add(new L(bh,new m(255,0,0))),this.properties.add(new L(vh,new m(200,200,200))),this.properties.add(new f(Rh,!0)),this.properties.add(new L(_h,m.BLUE)),this.properties.add(new H(Th)),this.properties.add(new f(Sh,!1)),this.properties.add(new O(Lh)),this.properties.add(new O(Ch)),this.properties.add(new O(Ah)),this.properties.add(new O(Oh)),this.properties.add(new f(Eh,!0)),this.properties.add(new f(Mh)),this.properties.add(new P(Vh,50)),this.properties.add(new O(Ih,100)),this.properties.add(new O(Bh,0)),this.properties.add(new O(Hh,10)),this.properties.add(new H(Dh)),this.properties.add(new T(Wh)),this.properties.add(new f(kh,!0)),this.properties.add(new f(Nh,!0)),this.properties.add(new f(Fh,!0)),this.properties.add(new f(Gh,!0)),this.properties.add(new f($h,!0)),this.properties.add(new f(Uh,!0)),this.properties.add(new f(Yh,!0)),this.properties.add(new O(zh,1)),this.properties.add(new L(Xh,new m(172,172,172))),this.properties.add(new f(qh)),this.properties.add(new T(Kh))}init(){this.trackRegion={id:`${this.wuid}-track`,mouseDown:t=>{if(!this.enabled||!this.trackScale)return;let e=this.getAncestorOffset(),i=this.horizontal?t.point.x-e.x:t.point.y-e.y;this.pagePressedValue=this.trackScale.getPositionValue(i),this.pageUp=this.pagePressedValue>this.getCoercedValue(),this.pageRepeatedly()},mouseUp:()=>this.stopPaging(),mouseOut:()=>this.stopPaging(),tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseEnter:()=>{this.hoveringThumb=!0,this.requestRepaint()},mouseOut:()=>{this.hoveringThumb=!1,this.requestRepaint()},mouseDown:()=>{this.enabled&&(this.grabStartValue=this.getCoercedValue(),this.draggingThumb=!0,this.requestRepaint())},mouseUp:()=>{this.draggingThumb=!1,this.requestRepaint()},grabEnd:()=>{this.draggingThumb=!1,this.requestRepaint()},grab:t=>{if(!this.enabled||this.grabStartValue===void 0||!this.trackScale)return;let e=this.trackScale.scaleLength;if(e<=0)return;let i=this.horizontal?t.dx:-t.dy,{min:r,max:s}=this,o;if(this.logScale){let a=e/(Math.log10(s)-Math.log10(r));o=this.grabStartValue*Math.pow(10,i/a)}else{let a=(s-r)*i/e;o=this.grabStartValue+a}let{stepIncrement:n}=this;if(n>0){let a=o-this.grabStartValue,l=n*Math.round(a/n);o=this.grabStartValue+l}this.setCoercedValue(o),this.requestRepaint()},cursor:"pointer",tooltip:()=>this.tooltip}}draw(t){let e=this.area;this.transparentBackground||t.fillRect({...e,color:this.backgroundColor}),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e),this.enabled||t.fillRect({...e,color:m.GRAY,opacity:sy})}drawVertical(t,e){let i=new at(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,this.foregroundColor,this.showMinorTicks,this.showScale);i.scaleFormat=this.scaleFormat;let r=e.x+e.width/2,s=this.thumbLength/2+this.gapBtwThumbScale;i.drawVertical(t,r+s,e.y,e.height,!0,!0),this.showMarkers&&this.drawVerticalMarkers(t,i,r-s);let o={x:r-this.trackBreadth/2,y:e.y+i.margin,width:this.trackBreadth,height:e.height-2*i.margin};this.trackScale=i,this.drawVerticalTrack(t,i,o)}drawVerticalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=0;this.showLoLo&&r!==void 0&&(l=Math.max(l,t.measureText("LOLO",a).width)),this.showLo&&s!==void 0&&(l=Math.max(l,t.measureText("LO",a).width)),this.showHi&&o!==void 0&&(l=Math.max(l,t.measureText("HI",a).width)),this.showHiHi&&n!==void 0&&(l=Math.max(l,t.measureText("HIHI",a).width));let h=this.markerTickLength+this.markerGap+l,p=i-h,d=(g,x,w)=>{let v=p+l+this.markerGap,S=Math.round(e.getValuePosition(g));t.strokePath({path:new _(v,S).lineTo(v+this.markerTickLength,S),color:x,lineWidth:this.markerTickLineWidth}),t.fillText({x:p,y:S,text:w,align:"left",baseline:"middle",color:x,font:a})};this.showLoLo&&r!==void 0&&d(r,this.colorLoLo,"LOLO"),this.showLo&&s!==void 0&&d(s,this.colorLo,"LO"),this.showHi&&o!==void 0&&d(o,this.colorHi,"HI"),this.showHiHi&&n!==void 0&&d(n,this.colorHiHi,"HIHI")}drawVerticalTrack(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let l=t.createLinearGradient(i.x,0,i.x+i.width,0);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:l});let h=W(i,r/2);t.strokeRect({...h,color:m.GRAY,lineWidth:r})}let s=e.getValuePosition(this.getCoercedValue()),o=W({...i,y:s,height:i.y+i.height-s},r);if(t.fillRect({...o,color:this.fillColor}),this.effect3d){let l=t.createLinearGradient(o.x,0,o.x+o.width,0);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.fillColor.withAlpha(0).toString()),t.fillRect({...o,gradient:l})}t.addHitRegion(this.trackRegion).addRect(i.x,i.y,i.width,i.height);let a={x:i.x+i.width/2,y:s};this.drawThumb(t,a,!0),this.drawValueLabel(t,{x:a.x-this.thumbLength/2-this.markerGap,y:a.y},"right","middle")}drawHorizontal(t,e){let i=new at(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,this.foregroundColor,this.showMinorTicks,this.showScale);i.scaleFormat=this.scaleFormat;let r=e.y+e.height/2,s=this.thumbLength/2+this.gapBtwThumbScale,o=i.measureHorizontalHeight(t);i.drawHorizontal(t,e.x,r+s+o,e.width),this.showMarkers&&this.drawHorizontalMarkers(t,i,r-s);let n={x:e.x+i.margin,y:r-this.trackBreadth/2,width:e.width-2*i.margin,height:this.trackBreadth};this.trackScale=i,this.drawHorizontalTrack(t,i,n)}drawHorizontalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=0;this.showLoLo&&r!==void 0&&(l=Math.max(l,t.measureText("LOLO",a).height)),this.showLo&&s!==void 0&&(l=Math.max(l,t.measureText("LO",a).height)),this.showHi&&o!==void 0&&(l=Math.max(l,t.measureText("HI",a).height)),this.showHiHi&&n!==void 0&&(l=Math.max(l,t.measureText("HIHI",a).height));let h=i-(this.markerTickLength+this.markerGap+l),p=(d,g,x)=>{let w=Math.round(e.getValuePosition(d)),v=h+l+this.markerGap;t.strokePath({path:new _(w,v).lineTo(w,v+this.markerTickLength),color:g,lineWidth:this.markerTickLineWidth}),t.fillText({x:w,y:h,text:x,align:"center",baseline:"top",color:g,font:a})};this.showLoLo&&r!==void 0&&p(r,this.colorLoLo,"LOLO"),this.showLo&&s!==void 0&&p(s,this.colorLo,"LO"),this.showHi&&o!==void 0&&p(o,this.colorHi,"HI"),this.showHiHi&&n!==void 0&&p(n,this.colorHiHi,"HIHI")}drawHorizontalTrack(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let l=t.createLinearGradient(0,i.y,0,i.y+i.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:l});let h=W(i,r/2);t.strokeRect({...h,color:m.GRAY,lineWidth:r})}let s=e.getValuePosition(this.getCoercedValue()),o=W({...i,width:s-i.x},r);if(t.fillRect({...o,color:this.fillColor}),this.effect3d){let l=t.createLinearGradient(0,o.y,0,o.y+o.height);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,this.fillColor.withAlpha(0).toString()),t.fillRect({...o,gradient:l})}t.addHitRegion(this.trackRegion).addRect(i.x,i.y,i.width,i.height);let a={x:s,y:i.y+i.height/2};this.drawThumb(t,a,!1),this.drawValueLabel(t,{x:a.x,y:a.y-this.thumbLength/2-this.markerGap},"center","bottom")}drawThumb(t,e,i){let r=this.thumbLength,s=this.thumbBreadth,o;if(i){let l=e.x-r/2,h=e.y-s/2;o=[{x:l,y:h},{x:l,y:h+s},{x:l+r*4/5,y:h+s},{x:l+r,y:h+s/2},{x:l+r*4/5,y:h}]}else{let l=e.x-s/2,h=e.y-r/2;o=[{x:l,y:h},{x:l+s,y:h},{x:l+s,y:h+r*4/5},{x:l+s/2,y:h+r},{x:l,y:h+r*4/5}]}let n=_.fromPoints(o).closePath();if(this.effect3d){let l=o[0],h=o[3],p=t.createLinearGradient(l.x,l.y,h.x,h.y);p.addColorStop(0,m.WHITE.toString()),p.addColorStop(1,this.thumbColor.toString()),t.fillPath({path:n,gradient:p})}else t.fillPath({path:n,color:this.thumbColor});t.strokePath({path:n,color:m.GRAY,lineWidth:1*this.scale}),t.addHitRegion(this.thumbRegion).addPath(n)}drawValueLabel(t,e,i,r){this.value!==void 0&&(!this.hoveringThumb&&!this.draggingThumb||t.fillText({x:e.x,y:e.y,text:this.formatLabelValue(this.value),align:i,baseline:r,color:this.foregroundColor,font:this.font}))}pageRepeatedly(){window.clearTimeout(this.pageTimeout);let t=this.getCoercedValue();(this.pageUp?t>=this.pagePressedValue:t<=this.pagePressedValue)||(this.setCoercedValue(t+(this.pageUp?this.pageIncrement:-this.pageIncrement)),this.requestRepaint(),this.pageTimeout=window.setTimeout(()=>this.pageRepeatedly(),hy))}stopPaging(){window.clearTimeout(this.pageTimeout)}getAncestorOffset(){let t=0,e=0,i=this.parent;for(;i;)t+=i.x,e+=i.y,i=i.parent;return{x:t,y:e}}setCoercedValue(t){let{min:e,max:i}=this;t=Math.min(i,Math.max(e,t)),this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,t):this.pv||(this.value=t)}getCoercedValue(){let{min:t,max:e}=this,i=this.value??(t+e)/2;return Math.min(e,Math.max(t,i))}formatLabelValue(t){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let e=Jt(this.min,this.max);return new rt(e).format(t)}}destroy(){window.clearTimeout(this.pageTimeout)}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get outlineWidth(){return this.scale*1}get trackBreadth(){return this.scale*ay}get thumbLength(){return this.scale*oy}get thumbBreadth(){return this.scale*ny}get gapBtwThumbScale(){return this.scale*ly}get colorHi(){return this.properties.getValue(xh)}get colorHiHi(){return this.properties.getValue(yh)}get colorLo(){return this.properties.getValue(Ph)}get colorLoLo(){return this.properties.getValue(bh)}get colorFillbackground(){return this.properties.getValue(vh)}get effect3d(){return this.properties.getValue(Rh)}get fillColor(){return this.properties.getValue(_h)}get font(){return this.properties.getValue(Th).scale(this.scale)}get horizontal(){return this.properties.getValue(Sh)}get levelHi(){return this.properties.getValue(Lh)}get levelHiHi(){return this.properties.getValue(Ch)}get levelLo(){return this.properties.getValue(Ah)}get levelLoLo(){return this.properties.getValue(Oh)}get limitsFromPv(){return this.properties.getValue(Eh)}get logScale(){return this.properties.getValue(Mh)}get majorTickStepHint(){return this.scale*this.properties.getValue(Vh)}get maximum(){return this.properties.getValue(Ih)}get minimum(){return this.properties.getValue(Bh)}get pageIncrement(){return this.properties.getValue(Hh)}get scaleFont(){return this.properties.getValue(Dh).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Wh)}get showHi(){return this.properties.getValue(kh)}get showHiHi(){return this.properties.getValue(Nh)}get showLo(){return this.properties.getValue(Fh)}get showLoLo(){return this.properties.getValue(Gh)}get showMarkers(){return this.properties.getValue($h)}get showMinorTicks(){return this.properties.getValue(Uh)}get showScale(){return this.properties.getValue(Yh)}get stepIncrement(){return this.properties.getValue(zh)}get thumbColor(){return this.properties.getValue(Xh)}get transparentBackground(){return this.properties.getValue(qh)}get valueLabelFormat(){return this.properties.getValue(Kh)}};var jh="enabled",Zh="font",Jh="maximum",Qh="minimum",tc="horizontal",ec="step_increment",ic="page_increment",rc="bar_length",sc="show_value_tip",oc=new m(243,243,243),Be=new m(232,232,231),Rr=150,_r=class extends M{decreaseRegion;decreasePressed=!1;increaseRegion;increasePressed=!1;pageDecreaseRegion;pageDecreasePressed=!1;pageIncreaseRegion;pageIncreasePressed=!1;thumbRegion;grabStartValue;dragRange;actionTimeout;constructor(t,e){super(t,e),this.properties.add(new f(jh)),this.properties.add(new f(tc)),this.properties.add(new f(sc)),this.properties.add(new H(Zh)),this.properties.add(new O(Jh)),this.properties.add(new O(Qh)),this.properties.add(new O(ec)),this.properties.add(new O(ic)),this.properties.add(new O(rc))}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=>{let 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(t){let{scale:e}=this,i=W(this.bounds,2*e);t.fillRect({...i,color:oc});let r=Math.min(i.height,i.width/2);this.drawLeftButton(t,{x:i.x,y:i.y,width:r,height:i.height}),this.drawRightButton(t,{x:i.x+i.width-r,y:i.y,width:r,height:i.height});let s=this.barLength,o=this.maximum+s,n=this.minimum,a=o-n,l=a-s,h=i.width-r-r,p=Math.floor(Math.max(6*e,h*s/a));this.dragRange=h-p;let d=this.getCoercedValue(),g=Math.floor((h-p)*(d-n)/l),x=h-g-p,w={x:i.x+r+g,y:i.y,width:p,height:i.height};t.fillRect({...w,color:Be}),this.drawRaisedButtonBorder(t,w),t.addHitRegion(this.thumbRegion).addRect(w.x,w.y,w.width,w.height);let S={x:i.x+r,y:i.y,width:g,height:i.height};t.addHitRegion(this.pageDecreaseRegion).addRect(S.x,S.y,S.width,S.height),this.pageDecreasePressed&&t.fillRect({...S,color:m.BLACK});let C={x:i.x+r+g+p,y:i.y,width:x,height:i.height};t.addHitRegion(this.pageIncreaseRegion).addRect(C.x,C.y,C.width,C.height),this.pageIncreasePressed&&t.fillRect({...C,color:m.BLACK})}drawVertical(t){let{scale:e}=this,i=W(this.bounds,e);t.fillRect({...i,color:oc});let r=Math.min(i.width,i.height/2);this.drawUpButton(t,{x:i.x,y:i.y,width:i.width,height:r}),this.drawDownButton(t,{x:i.x,y:i.y+i.height-r,width:i.width,height:r});let s=this.barLength,o=this.maximum+s,n=this.minimum,a=o-n,l=a-s,h=i.height-r-r,p=Math.floor(Math.max(6*e,h*s/a));this.dragRange=h-p;let d=this.getCoercedValue(),g=Math.floor((h-p)*(d-n)/l),x=h-g-p,w={x:i.x,y:i.y+r+g,width:i.width,height:p};t.fillRect({...w,color:Be}),this.drawRaisedButtonBorder(t,w),t.addHitRegion(this.thumbRegion).addRect(w.x,w.y,w.width,w.height);let S={x:i.x,y:i.y+r,width:i.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(S.x,S.y,S.width,S.height),this.pageDecreasePressed&&t.fillRect({...S,color:m.BLACK});let C={x:i.x,y:i.y+r+g+p,width:i.width,height:x};t.addHitRegion(this.pageIncreaseRegion).addRect(C.x,C.y,C.width,C.height),this.pageIncreasePressed&&t.fillRect({...C,color:m.BLACK})}drawLeftButton(t,e){t.fillRect({...e,color:Be}),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height/2,r.width);r.x+=(r.width-s)/2,s=Math.max(s,1);let o={x:r.x,y:r.y+r.height/2};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x+s,o.y-s).lineTo(o.x+s,o.y+s).closePath()})}drawRightButton(t,e){t.fillRect({...e,color:Be}),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height/2,r.width);r.x+=(r.width-s)/2,s=Math.max(s,1);let o={x:r.x+s,y:r.y+r.height/2};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x-s,o.y+s).closePath()})}drawUpButton(t,e){t.fillRect({...e,color:Be}),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x-s,o.y+s).lineTo(o.x+s,o.y+s).closePath()})}drawDownButton(t,e){t.fillRect({...e,color:Be}),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e),t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y+s};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x+s,o.y-s).closePath()})}drawRaisedButtonBorder(t,e){this.drawButtonBorder(t,e,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST)}drawPressedButtonBorder(t,e){this.drawButtonBorder(t,e,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER)}drawButtonBorder(t,e,i,r,s,o){let n=1*this.scale,a=e.y+n/2,l=e.x+n/2,h=e.y+e.height-n+n/2,p=e.x+e.width-n+n/2;t.strokePath({color:i,path:new _(p,h).lineTo(p,a).moveTo(p,h).lineTo(l,h)}),t.strokePath({color:r,path:new _(p-n,h-n).lineTo(p-n,a+n).moveTo(p-n,h-n).lineTo(l+n,h-n)}),t.strokePath({color:s,path:new _(l,a).lineTo(p-n,a).moveTo(l,a).lineTo(l,h-n)}),t.strokePath({color:o,path:new _(l+n,a+n).lineTo(p-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepIncreaseRepeatedly(),Rr)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepDecreaseRepeatedly(),Rr)}stepIncrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.stepIncrement)}stepDecrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageIncreaseRepeatedly(),Rr)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageDecreaseRepeatedly(),Rr)}pageIncrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.pageIncrement)}pageDecrease(){let t=this.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t-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(){let t=this.value??(this.maximum-this.minimum)/2;return t<this.minimum?this.minimum:t>this.maximum?this.maximum:t}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue(jh)}get horizontal(){return this.properties.getValue(tc)}get showValueTip(){return this.properties.getValue(sc)}get font(){return this.properties.getValue(Zh).scale(this.scale)}get minimum(){return this.properties.getValue(Qh)}get maximum(){return this.properties.getValue(Jh)}get stepIncrement(){return this.properties.getValue(ec)}get pageIncrement(){return this.properties.getValue(ic)}get barLength(){return this.properties.getValue(rc)}};var nc="minimum",ac="maximum",lc="step_increment",hc="page_increment",cc="limits_from_pv",pc="format",dc="precision",uc="precision_from_pv",gc="buttons_on_left",mc="horizontal_buttons_layout",fc="show_text",wc="font",xc="horizontal_alignment",yc="vertical_alignment",cy=100/255,py=20,dy=250,uy=40,Tr=class extends M{upRegion;upPressed=!1;downRegion;downPressed=!1;areaRegion;repeatTimeout;editing=!1;inputEl;scratchCanvas;scratchCtx;constructor(t,e){super(t,e),this.properties.add(new O(nc,-Number.MAX_VALUE)),this.properties.add(new O(ac,Number.MAX_VALUE)),this.properties.add(new O(lc,1)),this.properties.add(new O(hc,10)),this.properties.add(new f(cc,!0)),this.properties.add(new P(pc,0)),this.properties.add(new P(dc,3)),this.properties.add(new f(uc,!1)),this.properties.add(new f(gc,!1)),this.properties.add(new f(mc,!1)),this.properties.add(new f(fc,!0)),this.properties.add(new H(wc)),this.properties.add(new P(xc,1)),this.properties.add(new P(yc,1))}init(){this.upRegion={id:`${this.wuid}-up`,mouseDown:()=>{this.upPressed=!0,this.stepRepeatedly(1,!0)},mouseUp:()=>this.stopRepeating("up"),mouseOut:()=>this.stopRepeating("up"),tooltip:()=>this.tooltip},this.downRegion={id:`${this.wuid}-down`,mouseDown:()=>{this.downPressed=!0,this.stepRepeatedly(-1,!0)},mouseUp:()=>this.stopRepeating("down"),mouseOut:()=>this.stopRepeating("down"),tooltip:()=>this.tooltip},this.areaRegion={id:`${this.wuid}-area`,click:()=>this.startEditing(),tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement("input"),this.inputEl.style.display="none",this.inputEl.autocomplete="off",this.inputEl.addEventListener("keyup",t=>{t.key==="Enter"?this.commitEditing():t.key==="Escape"&&this.cancelEditing()}),this.inputEl.addEventListener("blur",()=>this.cancelEditing()),this.display.rootPanel.appendChild(this.inputEl),this.scratchCanvas=document.createElement("canvas"),this.scratchCtx=this.scratchCanvas.getContext("2d")}stopRepeating(t){window.clearTimeout(this.repeatTimeout),t==="up"?this.upPressed=!1:this.downPressed=!1,this.requestRepaint()}stepRepeatedly(t,e){window.clearTimeout(this.repeatTimeout),this.step(t),this.requestRepaint(),this.repeatTimeout=window.setTimeout(()=>this.stepRepeatedly(t,!1),e?dy:uy)}step(t){let e=this.currentNumericValue(),i=this.clamp(e+t*this.stepIncrement);i!==e&&(this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,i):this.pv||(this.value=i))}currentNumericValue(){let t=Number(this.value);return isNaN(t)?0:t}clamp(t){let{minimum:e,maximum:i}=this;return t<e?e:t>i?i:t}startEditing(){if(this.pv&&!this.pv.writable)return;let{labelBounds:t}=this.computeLayout();if(!t)return;this.editing=!0;let e=this.display.measureAbsoluteArea(this),i={x:e.x+(t.x-this.area.x),y:e.y+(t.y-this.area.y),width:t.width,height:t.height};this.inputEl.value=this.formatSpinnerValue(this.currentNumericValue()),this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${i.x}px`,this.inputEl.style.top=`${i.y}px`,this.inputEl.style.width=`${i.width}px`,this.inputEl.style.height=`${i.height}px`,this.inputEl.focus(),this.inputEl.select(),this.requestRepaint()}commitEditing(){let t=this.inputEl.value;this.cancelEditing();let e=Number(t);if(isNaN(e))return;let i=this.clamp(e);this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,i):this.pv||(this.value=i)}cancelEditing(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let{labelBounds:e,upBounds:i,downBounds:r}=this.computeLayout();e&&!this.editing&&(t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.drawLabel(t,e)),this.drawUpButton(t,i),this.drawDownButton(t,r),this.enabled||t.fillRect({...this.area,color:m.GRAY,opacity:cy})}computeLayout(){let t=py*this.scale,e=1*this.scale,i=this.area,r,s,o;if(this.showText)if(this.buttonsOnLeft)if(this.horizontalButtonsLayout)r={x:i.x+e+2*t,y:i.y,width:i.width-2*t-e,height:i.height},s={x:i.x,y:i.y,width:t,height:i.height},o={x:i.x+t,y:i.y,width:t,height:i.height};else{r={x:i.x+e+t,y:i.y,width:i.width-t-e,height:i.height};let n=Math.floor(i.height/2);s={x:i.x,y:i.y,width:t,height:n},o={x:i.x,y:i.y+n,width:t,height:n}}else if(this.horizontalButtonsLayout)r={x:i.x,y:i.y,width:i.width-2*t,height:i.height},s={x:i.x+i.width-2*t,y:i.y,width:t,height:i.height},o={x:i.x+i.width-t,y:i.y,width:t,height:i.height};else{r={x:i.x,y:i.y,width:i.width-t,height:i.height};let n=Math.floor(i.height/2);s={x:i.x+i.width-t,y:i.y,width:t,height:n},o={x:i.x+i.width-t,y:i.y+n,width:t,height:n}}else if(this.horizontalButtonsLayout){let n=Math.floor(i.width/2);s={x:i.x,y:i.y,width:n,height:i.height},o={x:i.x+n,y:i.y,width:n,height:i.height}}else{let n=Math.floor(i.height/2);s={x:i.x,y:i.y,width:i.width,height:n},o={x:i.x,y:i.y+n,width:i.width,height:n}}return{labelBounds:r,upBounds:s,downBounds:o}}drawLabel(t,e){let{pixelRatio:i}=t,r=ye(t.ctx,e.x,e.y),s=Math.max(1,Math.ceil(e.width+r.subPixelX)),o=Math.max(1,Math.ceil(e.height+r.subPixelY));this.scratchCanvas.width=Math.ceil(s*i),this.scratchCanvas.height=Math.ceil(o*i);let n=this.scratchCtx;n.clearRect(0,0,this.scratchCanvas.width,this.scratchCanvas.height),n.setTransform(i,0,0,i,0,0),n.translate(r.subPixelX,r.subPixelY),n.fillStyle=this.alarmSensitiveForegroundColor.toString(),n.font=this.font.getFontString();let a=e.x;this.horizAlignment===0?n.textAlign="start":this.horizAlignment===1?(a+=e.width/2,n.textAlign="center"):(a+=e.width,n.textAlign="end");let l=e.y;this.vertAlignment===0?n.textBaseline="top":this.vertAlignment===1?(l+=e.height/2,n.textBaseline="middle"):(l+=e.height,n.textBaseline="bottom");let h=this.formatSpinnerValue(this.currentNumericValue());n.fillText(h,a-e.x,l-e.y),t.ctx.drawImage(this.scratchCanvas,r.x,r.y,s,o)}formatSpinnerValue(t){let e=this.precisionFromPV&&this.pv&&this.pv.precision>=0?this.pv.precision:this.precision;switch(this.format){case 1:return t.toExponential(e).toUpperCase().replace("E+","E");case 2:return"0x"+Math.trunc(t).toString(16);default:{let i={minimumFractionDigits:0,maximumFractionDigits:e,useGrouping:!1,roundingMode:"halfEven"};return new Intl.NumberFormat("en-US",i).format(t)}}}drawUpButton(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawSpinnerButtonBorder(t,e,this.upPressed),t.addHitRegion(this.upRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x-s,o.y+s).lineTo(o.x+s,o.y+s).closePath()})}drawDownButton(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawSpinnerButtonBorder(t,e,this.downPressed),t.addHitRegion(this.downRegion).addRect(e.x,e.y,e.width,e.height);let r=W(e,3*this.scale),s=Math.min(r.height,r.width/2);r.y+=(r.height-s)/2,s=Math.max(s,1);let o={x:r.x+r.width/2,y:r.y+s};t.fillPath({color:m.BLACK,path:new _(o.x,o.y).lineTo(o.x-s,o.y-s).lineTo(o.x+s,o.y-s).closePath()})}drawSpinnerButtonBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r/2,a=e.x+e.width-r/2,l=i?m.BUTTON_DARKEST:m.BUTTON_LIGHTEST,h=i?m.BUTTON_LIGHTEST:m.BUTTON_DARKEST;t.strokePath({color:l,lineWidth:r,path:new _(o,n).lineTo(o,s).lineTo(a,s)}),t.strokePath({color:h,lineWidth:r,path:new _(a,s).lineTo(a,n).lineTo(o,n)})}destroy(){window.clearTimeout(this.repeatTimeout),this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0),this.scratchCanvas=void 0,this.scratchCtx=void 0}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(nc)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(ac)}get stepIncrement(){return this.properties.getValue(lc)}get pageIncrement(){return this.properties.getValue(hc)}get limitsFromPV(){return this.properties.getValue(cc)}get format(){return this.properties.getValue(pc)}get precision(){return this.properties.getValue(dc)}get precisionFromPV(){return this.properties.getValue(uc)}get buttonsOnLeft(){return this.properties.getValue(gc)}get horizontalButtonsLayout(){return this.properties.getValue(mc)}get showText(){return this.properties.getValue(fc)}get font(){return this.properties.getValue(wc).scale(this.scale)}get horizAlignment(){return this.properties.getValue(xc)}get vertAlignment(){return this.properties.getValue(yc)}};var Pc="auto_size",bc="confirm_message",$s="font",vc="format_type",Rc="horizontal_alignment",_c="limits_from_pv",Tc="maximum",Sc="minimum",Lc="multiline_input",Cc="password_input",Ac="precision",Oc="precision_from_pv",Ec="read_only",Mc="rotation_angle",Vc="show_h_scroll",Ic="show_lohi",Bc="show_native_border",Hc="show_units",Dc="show_v_scroll",Wc="style",kc="vertical_alignment",Nc="wrap_words",gy=0,Us=1,my=/^[+-]?(\d+\.?\d*|\.\d+)([eE][+-]?\d+)?$/,Sr=class extends M{areaRegion;inputEl;editing=!1;confirming=!1;scratchCanvas;scratchCtx;constructor(t,e){super(t,e),this.properties.add(new f(Pc)),this.properties.add(new T(bc)),this.properties.add(new H($s)),this.properties.add(new P(vc)),this.properties.add(new P(Rc)),this.properties.add(new f(_c,!1)),this.properties.add(new O(Tc,1/0)),this.properties.add(new O(Sc,-1/0)),this.properties.add(new f(Lc)),this.properties.add(new f(Cc,!1)),this.properties.add(new P(Ac)),this.properties.add(new f(Oc)),this.properties.add(new f(Ec,!1)),this.properties.add(new O(Mc)),this.properties.add(new f(Vc,!1)),this.properties.add(new f(Ic,!0)),this.properties.add(new f(Bc,!0)),this.properties.add(new f(Hc,!0)),this.properties.add(new f(Dc,!1)),this.properties.add(new P(Wc,gy)),this.properties.add(new P(kc,1)),this.properties.add(new f(Nc,!1))}init(){this.text&&(this.value=this.text),this.areaRegion={id:`${this.wuid}-area`,click:()=>{if(this.pv&&!this.pv.writable)return;this.editing=!0;let t=this.display.measureAbsoluteArea(this);if(t.x-=2*this.scale,t.y-=2*this.scale,t.width+=2*this.scale,t.height+=2*this.scale,this.inputEl.value=this.value??"",this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${t.x}px`,this.inputEl.style.top=`${t.y}px`,this.inputEl.style.width=`${t.width}px`,this.inputEl.style.height=`${t.height}px`,this.inputEl.autocomplete="off",this.multilineInput){let e=this.inputEl;e.style.resize="none"}else{let e=this.inputEl;this.passwordInput&&(e.type="password")}this.inputEl.focus(),this.inputEl.select()},tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement(this.multilineInput?"textarea":"input"),this.inputEl.style.display="none",this.inputEl.addEventListener("keyup",t=>{if(t.key==="Enter"){if(!this.multilineInput||t.ctrlKey){let e=this.inputEl?.value||"";if(typeof this.pv?.value=="number"){let r=Number(e);isNaN(r)||(e=this.clampToLimits(r))}else this.pv&&(e=this.coerceText(e));let i=()=>{this.value=e,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,e),this.finishEditing()};if(!this.confirmMessage)i();else{this.confirming=!0;let r=this.display.getDialogHandler();this.display.runSequenced(()=>nt(r,"Confirm Dialog",this.confirmMessage).then(s=>{this.confirming=!1,s?i():this.cancelInput()}))}}}else t.key==="Escape"&&this.cancelInput()}),this.inputEl.addEventListener("blur",t=>{this.confirming||(this.pv?this.cancelInput():(this.value=this.inputEl?.value||"",this.cancelInput()))}),this.display.rootPanel.appendChild(this.inputEl),this.scratchCanvas=document.createElement("canvas"),this.scratchCtx=this.scratchCanvas.getContext("2d")}clampToLimits(t){let{minimum:e,maximum:i}=this;if(e<i){if(t<e)return e;if(t>i)return i}return t}coerceText(t){switch(this.formatType){case 0:case 1:case 2:case 6:{if(!my.test(t.trim()))return t;let e=parseFloat(t),{minimum:i,maximum:r}=this;if(i<r){if(e<i)return i;if(e>r)return r}return t}default:return t}}finishEditing(){this.style!==Us&&(this.inputEl.style.display="none"),this.editing=!1,this.requestRepaint()}cancelInput(){this.style===Us&&(this.inputEl.value=this.computeDisplayText()),this.finishEditing()}computeDisplayText(){let t=this.text;if(this.value!==void 0){let e=this.precisionFromPV?this.pv?.precision??-1:this.precision;t=xe(this.value,this.formatType,e,this.pv?.typeHint),this.showUnits&&this.pv?.units&&(t+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?t+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(t+=" \u2191"))}return t}drawHolder(t){if(this.autoSize){let e=this.properties.getValue($s).scale(1);this.customSize=t.measureText(this.computeDisplayText(),e,!0)}super.drawHolder(t)}draw(t){if(this.style===Us){this.drawNative();return}if(this.editing)return;t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);let i=t.ctx;this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let{pixelRatio:r}=t,s=ye(i,this.area.x,this.area.y),o=Math.ceil(this.area.width+s.subPixelX),n=Math.ceil(this.area.height+s.subPixelY);this.scratchCanvas.width=Math.ceil(o*r),this.scratchCanvas.height=Math.ceil(n*r);let a=this.scratchCtx;a.setTransform(r,0,0,r,0,0),a.translate(s.subPixelX,s.subPixelY),a.fillStyle=this.alarmSensitiveForegroundColor.toString(),a.font=this.font.getFontString();let l=this.computeDisplayText(),h=l.replace(/(\r\n|\r|\n)$/,"").split(/\r\n|\r|\n/);if(h.length>1){let p=t.measureText("Mg",this.font).height,d=h.length*p,g=0;for(let v of h)g=Math.max(g,a.measureText(v).width);let x=0;this.horizAlignment===1?x=(this.width-g)/2:this.horizAlignment===2&&(x=this.width-g);let w=0;this.vertAlignment===1?w=(this.height-d)/2:this.vertAlignment===2&&(w=this.height-d),a.textAlign="start",a.textBaseline="top";for(let v=0;v<h.length;v++)a.fillText(h[v],x,w+v*p)}else if(this.rotationAngle){let p=t.measureText(l,this.font,!0),d=yi({width:this.area.width,height:this.area.height},p,this.rotationAngle,this.horizAlignment,this.vertAlignment);a.translate(d.x,d.y),a.rotate(this.rotationAngle*Math.PI/180),a.textAlign="left",a.textBaseline="top",a.fillText(l,0,0)}else{let p=this.x;this.horizAlignment===0?a.textAlign="start":this.horizAlignment===1?(p+=this.width/2,a.textAlign="center"):this.horizAlignment===2&&(p+=this.width,a.textAlign="end");let d=this.y;this.vertAlignment===0?a.textBaseline="top":this.vertAlignment===1?(d=d+this.height/2,a.textBaseline="middle"):this.vertAlignment===2&&(d=d+this.height,a.textBaseline="bottom"),a.fillText(l,p-this.area.x,d-this.area.y)}i.drawImage(this.scratchCanvas,s.x,s.y,o,n)}drawNative(){let t=this.inputEl,e=this.display.measureAbsoluteArea(this);t.style.display="block",t.style.position="absolute",t.style.boxSizing="border-box",t.style.left=`${e.x}px`,t.style.top=`${e.y}px`,t.style.width=`${e.width}px`,t.style.height=`${e.height}px`,t.autocomplete="off",t.style.font=this.font.getFontString(),t.style.color=this.alarmSensitiveForegroundColor.toString(),this.backgroundAlarmSensitive&&this.alarm?t.style.backgroundColor=this.alarmSensitiveBackgroundColor.toString():t.style.backgroundColor=this.backgroundColor.toString(),t.style.border=this.showNativeBorder?"":"none";let i=["left","center","right"][this.horizAlignment]??"left";if(t.style.textAlign=i,t.readOnly=this.readOnly||!this.enabled,this.multilineInput){let r=t;r.style.resize="none",this.wrapWords?(r.wrap="soft",r.style.whiteSpace="pre-wrap",r.style.overflowWrap="break-word"):(r.wrap="off",r.style.whiteSpace="pre",r.style.overflowWrap="normal"),r.style.overflowX=this.showHScroll?"scroll":"hidden",r.style.overflowY=this.showVScroll?"scroll":"hidden"}else{let r=t;r.type=this.passwordInput?"password":"text"}if(document.activeElement!==t){let r=this.computeDisplayText();t.value!==r&&(t.value=r)}}hide(){this.editing=!1,this.inputEl&&(this.inputEl.style.display="none")}destroy(){this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0),this.scratchCanvas=void 0,this.scratchCtx=void 0}get autoSize(){return this.properties.getValue(Pc)}get confirmMessage(){return this.properties.getValue(bc)}get font(){return this.properties.getValue($s).scale(this.scale)}get formatType(){return this.properties.getValue(vc)}get horizAlignment(){return this.properties.getValue(Rc)}get limitsFromPV(){return this.properties.getValue(_c)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(Tc)}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(Sc)}get multilineInput(){return this.properties.getValue(Lc)}get passwordInput(){return this.properties.getValue(Cc)}get precision(){return this.properties.getValue(Ac)}get precisionFromPV(){return this.properties.getValue(Oc)}get readOnly(){return this.properties.getValue(Ec)}get rotationAngle(){return this.properties.getValue(Mc)}get showHScroll(){return this.properties.getValue(Vc)}get showLohi(){return this.properties.getValue(Ic)}get showNativeBorder(){return this.properties.getValue(Bc)}get showUnits(){return this.properties.getValue(Hc)}get showVScroll(){return this.properties.getValue(Dc)}get style(){return this.properties.getValue(Wc)}get vertAlignment(){return this.properties.getValue(kc)}get wrapWords(){return this.properties.getValue(Nc)}};var Fc="minimum",Gc="maximum",$c="integerDigits",Uc="decimalDigits",Yc="internalFrameColor",zc="focusedFrameColor",Xc="internalFrameSize",qc="limits_from_pv",Kc="show_buttons",jc="font",fy=100/255,wy=20,Zc=15,xy=250,yy=40;function Lr(c,t){let e=Math.pow(10,t);return Math.round(c*e)/e}var Cr=class extends M{repeatTimeout;integerPressed=[];decimalPressed=[];constructor(t,e){super(t,e),this.properties.add(new O(Fc,0)),this.properties.add(new O(Gc,100)),this.properties.add(new P($c,3)),this.properties.add(new P(Uc,2)),this.properties.add(new L(Yc,m.BLACK)),this.properties.add(new L(zc,m.BLUE)),this.properties.add(new P(Xc,1)),this.properties.add(new f(qc,!1)),this.properties.add(new f(Kc,!0)),this.properties.add(new H(jc))}ensurePressedArrays(){let{integerDigits:t,decimalDigits:e}=this;this.integerPressed.length!==t&&(this.integerPressed=new Array(t).fill(void 0)),this.decimalPressed.length!==e&&(this.decimalPressed=new Array(e).fill(void 0))}draw(t){this.ensurePressedArrays(),this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...this.area,color:this.backgroundColor});let e=this.computeLayout(),{integerCharsByPlace:i,decimalCharsByIndex:r,showMinus:s}=this.computeDigits(),{integerDigits:o,decimalDigits:n}=this;this.drawPlainCell(t,e.sign,s?"-":"");for(let a=0;a<e.integer.length;a++){let l=o-a-1;this.drawDigitCell(t,e.integer[a],i[l],!1,l)}this.drawPlainCell(t,e.dot,n>0?".":"");for(let a=0;a<e.decimal.length;a++)this.drawDigitCell(t,e.decimal[a],r[a],!0,a);this.enabled||t.fillRect({...this.area,color:m.GRAY,opacity:fy})}computeLayout(){let{integerDigits:t,decimalDigits:e,showButtons:i}=this,r=this.area,s=2+t+e,o=r.width/s,n=i?wy*this.scale:0,a=w=>({x:r.x+w*o,y:r.y,width:o,height:r.height}),l=w=>{let v=a(w);return i?{cell:v,up:{x:v.x,y:v.y,width:o,height:n},down:{x:v.x,y:v.y+v.height-n,width:o,height:n}}:{cell:v}},h=0,p=a(h++),d=[];for(let w=0;w<t;w++)d.push(l(h++));let g=a(h++),x=[];for(let w=0;w<e;w++)x.push(l(h++));return{sign:p,integer:d,dot:g,decimal:x}}computeDigits(){let{integerDigits:t,decimalDigits:e}=this,i=this.currentNumericValue(),{wheelMax:r}=this.computeWheelLimits(),s=i<0;if(Math.abs(i)>r)return{integerCharsByPlace:new Array(t).fill("X"),decimalCharsByIndex:new Array(e).fill("X"),showMinus:s};let o=Math.abs(i).toFixed(e),[n,a]=o.split("."),l=[];for(let p=0;p<t;p++){let d=n.length-1-p;l.push(d>=0?n[d]:"0")}let h=[];for(let p=0;p<e;p++)h.push(a?a[p]:"0");return{integerCharsByPlace:l,decimalCharsByIndex:h,showMinus:s}}computeWheelLimits(){let{integerDigits:t,decimalDigits:e}=this,i=t>0?"9".repeat(t):"0";e>0&&(i+="."+"9".repeat(e));let r=Number(i);return{wheelMin:-r,wheelMax:r}}currentNumericValue(){let t=Number(this.value);return isNaN(t)?0:t}drawPlainCell(t,e,i){this.drawCellBorder(t,e),this.drawCellText(t,e,i)}drawDigitCell(t,e,i,r,s){if(this.drawCellBorder(t,e.cell),this.drawCellText(t,this.computeLabelBounds(e),i),!e.up||!e.down)return;let o=r?this.decimalPressed:this.integerPressed,n={id:`${this.wuid}-${r?"dec":"int"}-${s}-up`,mouseDown:()=>{this.enabled&&(o[s]=1,this.clickRepeatedly(r,s,1,!0))},mouseUp:()=>this.stopRepeating(o,s),mouseOut:()=>this.stopRepeating(o,s),tooltip:()=>this.tooltip},a={id:`${this.wuid}-${r?"dec":"int"}-${s}-down`,mouseDown:()=>{this.enabled&&(o[s]=-1,this.clickRepeatedly(r,s,-1,!0))},mouseUp:()=>this.stopRepeating(o,s),mouseOut:()=>this.stopRepeating(o,s),tooltip:()=>this.tooltip};this.drawUpButton(t,e.up,n,o[s]===1),this.drawDownButton(t,e.down,a,o[s]===-1)}computeLabelBounds(t){return!t.up||!t.down?t.cell:{x:t.cell.x,y:t.up.y+t.up.height,width:t.cell.width,height:t.cell.height-t.up.height-t.down.height}}drawCellBorder(t,e){this.internalFrameSize<=0||t.strokeRect({...e,color:this.internalFrameColor,lineWidth:this.internalFrameSize*this.scale})}drawCellText(t,e,i){i&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:i,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font})}drawUpButton(t,e,i,r){t.fillRect({...e,color:m.BUTTON}),this.drawButtonBorder(t,e,r),t.addHitRegion(i).addRect(e.x,e.y,e.width,e.height);let o=W(e,3*this.scale),n=Math.min(o.height,o.width/2);o.y+=(o.height-n)/2,n=Math.max(n,1);let a={x:o.x+o.width/2,y:o.y};t.fillPath({color:m.BLACK,path:new _(a.x,a.y).lineTo(a.x-n,a.y+n).lineTo(a.x+n,a.y+n).closePath()})}drawDownButton(t,e,i,r){t.fillRect({...e,color:m.BUTTON}),this.drawButtonBorder(t,e,r),t.addHitRegion(i).addRect(e.x,e.y,e.width,e.height);let o=W(e,3*this.scale),n=Math.min(o.height,o.width/2);o.y+=(o.height-n)/2,n=Math.max(n,1);let a={x:o.x+o.width/2,y:o.y+n};t.fillPath({color:m.BLACK,path:new _(a.x,a.y).lineTo(a.x-n,a.y-n).lineTo(a.x+n,a.y-n).closePath()})}drawButtonBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r/2,a=e.x+e.width-r/2,l=i?m.BUTTON_DARKEST:m.BUTTON_LIGHTEST,h=i?m.BUTTON_LIGHTEST:m.BUTTON_DARKEST;t.strokePath({color:l,lineWidth:r,path:new _(o,n).lineTo(o,s).lineTo(a,s)}),t.strokePath({color:h,lineWidth:r,path:new _(a,s).lineTo(a,n).lineTo(o,n)})}stopRepeating(t,e){window.clearTimeout(this.repeatTimeout),t[e]=void 0,this.requestRepaint()}clickRepeatedly(t,e,i,r){window.clearTimeout(this.repeatTimeout),this.click(t,e,i),this.requestRepaint(),this.repeatTimeout=window.setTimeout(()=>this.clickRepeatedly(t,e,i,!1),r?xy:yy)}click(t,e,i){if(!this.enabled)return;let r=i*(t?Math.pow(10,-(e+1)):Math.pow(10,e)),s=this.currentNumericValue(),o=i>0?this.increment(s,r):this.decrement(s,r);this.pv&&this.pv.writable?this.display.pvEngine.setValue(new Date,this.pv.name,o):this.pv||(this.value=o)}increment(t,e){let{decimalDigits:i,minimum:r,maximum:s}=this,{wheelMin:o,wheelMax:n}=this.computeWheelLimits(),a=Lr(t+e,i);return a!==0&&Math.sign(a)!==Math.sign(t)&&(a=Lr(-t+e,i)),t>s||t>n?t:t<r?r:t<o?o:a>n?n:a>s?s:a}decrement(t,e){let{decimalDigits:i,minimum:r,maximum:s}=this,{wheelMin:o,wheelMax:n}=this.computeWheelLimits(),a=Lr(t+e,i);return a!==0&&Math.sign(a)!==Math.sign(t)&&(a=Lr(-t+e,i)),t<r||t<o?t:t>s?s:t>n?n:a<r?r:a<o?o:a}destroy(){window.clearTimeout(this.repeatTimeout)}get minimum(){return this.limitsFromPV&&this.pv?.lowerDisplayLimit!==void 0?this.pv.lowerDisplayLimit:this.properties.getValue(Fc)}get maximum(){return this.limitsFromPV&&this.pv?.upperDisplayLimit!==void 0?this.pv.upperDisplayLimit:this.properties.getValue(Gc)}get integerDigits(){return Math.min(this.properties.getValue($c),Zc)}get decimalDigits(){let t=this.properties.getValue(Uc);return Math.min(t,Math.max(0,Zc-this.integerDigits))}get internalFrameColor(){return this.properties.getValue(Yc)}get focusedFrameColor(){return this.properties.getValue(zc)}get internalFrameSize(){return this.properties.getValue(Xc)}get limitsFromPV(){return this.properties.getValue(qc)}get showButtons(){return this.properties.getValue(Kc)}get font(){return this.properties.getValue(jc).scale(this.scale)}};var Jc="alpha",Qc="fill",tp="line_width",ep="line_style",ip="start_angle",rp="total_angle",Py="scale_options",Ar=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(Jc,255)),this.properties.add(new P(tp)),this.properties.add(new P(ip)),this.properties.add(new P(rp)),this.properties.add(new f(Qc)),this.properties.add(new P(ep)),this.properties.add(new tt(Py,new J(!0,!0,!0)))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){let e=this.x+this.width/2,i=this.y+this.height/2,r=this.width/2,s=this.height/2,o=-G(this.startAngle),n=-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,r,s,0,o,n,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&this.totalAngle!==0){let a,{scale:l}=this;this.lineStyle===0?a=[]:this.lineStyle===1?a=[6*l,2*l]:this.lineStyle===2?a=[2*l,2*l]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:r-this.lineWidth/2,ry:s-this.lineWidth/2,startAngle:o,endAngle:n,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:a})}}get alpha(){return this.properties.getValue(Jc)}get lineWidth(){return this.scale*this.properties.getValue(tp)}get lineStyle(){return this.properties.getValue(ep)}get startAngle(){return this.properties.getValue(ip)}get totalAngle(){return this.properties.getValue(rp)}get fill(){return this.properties.getValue(Qc)}};var sp="alpha",op="bg_gradient_color",np="fg_gradient_color",ap="fill_level",lp="gradient",hp="horizontal_fill",cp="line_color",pp="line_width",dp="line_style",by="scale_options",Or=class extends M{constructor(t,e){super(t,e),this.properties.add(new P(sp,255)),this.properties.add(new L(op)),this.properties.add(new L(np)),this.properties.add(new f(lp)),this.properties.add(new P(pp)),this.properties.add(new O(ap)),this.properties.add(new f(hp)),this.properties.add(new L(cp)),this.properties.add(new P(dp)),this.properties.add(new tt(by,new J(!0,!0,!0)))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){let e=this.x+this.width/2,i=this.y+this.height/2,r=this.width/2,s=this.height/2;if(!this.transparent){let o=this.alarmSensitiveBackgroundColor;if(this.gradient){let n=this.horizontalFill?this.x:this.x+this.width,a=this.horizontalFill?this.y+this.height:this.y,l=t.createLinearGradient(this.x,this.y,n,a);l.addColorStop(0,this.backgroundGradientStartColor.toString()),l.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:r,ry:s,gradient:l})}else t.fillEllipse({cx:e,cy:i,rx:r,ry:s,color:o})}if(this.lineWidth){let o=r-this.lineWidth/2,n=s-this.lineWidth/2;this.lineStyle===0?t.strokeEllipse({cx:e,cy:i,rx:o,ry:n,color:this.lineColor,lineWidth:this.lineWidth}):this.lineStyle===1?t.strokeEllipse({cx:e,cy:i,rx:o,ry:n,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`)}}drawFill(t){let e=W(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let a=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,a,e.height)}else{let a=e.height*(this.fillLevel/100),l=e.y+e.height-a;t.ctx.beginPath(),t.ctx.rect(e.x,l,e.width,e.height)}t.ctx.clip();let i=this.x+this.width/2,r=this.y+this.height/2,s=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,n=this.alarmSensitiveForegroundColor;if(this.gradient){let a=this.horizontalFill?this.x:this.x+this.width,l=this.horizontalFill?this.y+this.height:this.y,h=t.createLinearGradient(this.x,this.y,a,l);h.addColorStop(0,this.foregroundGradientStartColor.toString()),h.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:h})}else t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(sp)}get lineWidth(){return this.scale*this.properties.getValue(pp)}get fillLevel(){return this.properties.getValue(ap)}get horizontalFill(){return this.properties.getValue(hp)}get lineColor(){return this.properties.getValue(cp)}get lineStyle(){return this.properties.getValue(dp)}get gradient(){return this.properties.getValue(lp)}get backgroundGradientStartColor(){return this.properties.getValue(op)}get foregroundGradientStartColor(){return this.properties.getValue(np)}};var up="auto_size",gp="crop_bottom",mp="crop_left",fp="crop_right",wp="crop_top",xp="degree",yp="flip_horizontal",Pp="flip_vertical",vy="height",bp="image_file",vp="no_animation",Ys="permutation_matrix",Rp="stretch_to_fit",_p="transparency",Ry="width",_y=[[1,0],[0,1]],Tp=[0,90,180,270],Ty=[[-1,0],[0,1]],Sy=[[1,0],[0,-1]];function Sp(c){return c[0][0]===1&&c[0][1]===0&&c[1][0]===0&&c[1][1]===1}function Lp(c){return Math.round(c*1e4)/1e4}function Ly(c){let t=c*Math.PI/180,e=Lp(Math.cos(t)),i=Lp(Math.sin(t));return[[e,-i],[i,e]]}function Cy(c,t){return[[c[0][0]*t[0][0]+c[0][1]*t[1][0],c[0][0]*t[0][1]+c[0][1]*t[1][1]],[c[1][0]*t[0][0]+c[1][1]*t[1][0],c[1][0]*t[0][1]+c[1][1]*t[1][1]]]}function Ay(c){return c.map(t=>t.map(e=>Math.round(e)))}function Oy(c,t,e){let[[i,r],[s,o]]=e,a=[[0,0],[c-1,0],[c-1,t-1],[0,t-1]].map(([w,v])=>[i*w+r*v,s*w+o*v]),l=a.map(w=>w[0]),h=a.map(w=>w[1]),p=Math.min(...l),d=Math.min(...h),g=Math.max(...l),x=Math.max(...h);return{width:Math.round(g-p),height:Math.round(x-d),a:i,b:s,c:r,d:o,e:-p,f:-d}}var Er=class extends M{currentImageFile;imageElement;imageSnapshot;imageLoading=!1;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new f(up,!0)),this.properties.add(new P(gp,0)),this.properties.add(new P(mp,0)),this.properties.add(new P(fp,0)),this.properties.add(new P(wp,0)),this.properties.add(new T(bp)),this.properties.add(new T(vp)),this.properties.add(new Ye(Ys,_y)),this.properties.add(new P(xp,0)),this.properties.add(new f(yp,!1)),this.properties.add(new f(Pp,!1)),this.properties.add(new f(Rp,!1)),this.properties.add(new f(_p,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.triggerImageLoad(),this.addPropertyListener(xp,(t,e)=>{let i=Tp[t]-Tp[e];this.applyPermutationDelta(Ly(i))}),this.addPropertyListener(yp,()=>{this.applyPermutationDelta(Ty)}),this.addPropertyListener(Pp,()=>{this.applyPermutationDelta(Sy)})}applyPermutationDelta(t){let e=Ay(Cy(t,this.permutationMatrix));this.properties.setValue(Ys,e),this.imageElement&&this.imageLoaded&&(this.snapshotImage(this.imageElement),this.applyAutoSize()),this.requestRepaint()}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}applyAutoSize(){if(this.autoSize&&!this.stretchToFit&&this.imageSnapshot){let t=this.getCropRegion(this.imageSnapshot);this.properties.setValue(Ry,t.width),this.properties.setValue(vy,t.height)}}getCropRegion(t){let e=t.width,i=t.height,r=this.cropTop>i?0:this.cropTop,s=this.cropLeft>e?0:this.cropLeft,o=i-r-this.cropBottom<0?0:this.cropBottom,n=e-s-this.cropRight<0?0:this.cropRight;return{x:s,y:r,width:e-s-n,height:i-r-o}}draw(t){if(this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.imageLoading&&this.imageSnapshot)this.drawSource(t,this.imageSnapshot,this.imageSnapshot);else if(this.imageLoaded)if(this.noAnimation)this.drawSource(t,this.imageSnapshot,this.imageSnapshot);else{let e=Sp(this.permutationMatrix)?this.imageElement:this.renderOriented(this.imageElement,this.imageElement.naturalWidth,this.imageElement.naturalHeight);this.drawSource(t,e,this.imageSnapshot)}else this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height))}drawSource(t,e,i){let r=this.stretchToFit?this.getStretchedSourceRect(i):this.getUnstretchedSourceRect(i);r&&(this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,r.destWidth,r.destHeight)),t.ctx.drawImage(e,r.sx,r.sy,r.sw,r.sh,this.x,this.y,r.destWidth,r.destHeight))}getUnstretchedSourceRect(t){let e=this.getCropRegion(t);if(!(e.width<=0||e.height<=0))return{sx:e.x,sy:e.y,sw:e.width,sh:e.height,destWidth:e.width,destHeight:e.height}}getStretchedSourceRect(t){let e=this.width+this.cropLeft+this.cropRight,i=this.height+this.cropTop+this.cropBottom;if(e<=0||i<=0)return;let r=t.width/e,s=t.height/i;return{sx:this.cropLeft*r,sy:this.cropTop*s,sw:this.width*r,sh:this.height*s,destWidth:this.width,destHeight:this.height}}triggerImageLoad(){if(this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile){this.currentImageFile=this.imageFile;let t=this.imageElement;this.display.getImageLoader().load(this.resolvePath(this.imageFile)).then(e=>{t.src=e})}}snapshotImage(t){this.imageSnapshot=this.renderOriented(t,t.naturalWidth,t.naturalHeight)}renderOriented(t,e,i){let r=document.createElement("canvas"),s=r.getContext("2d"),o=this.permutationMatrix;if(Sp(o))r.width=e,r.height=i,s.drawImage(t,0,0);else{let n=Oy(e,i,o);r.width=n.width,r.height=n.height,s.setTransform(n.a,n.b,n.c,n.d,n.e,n.f),s.drawImage(t,0,0)}return r}get transparency(){return this.properties.getValue(_p)}get imageFile(){return this.properties.getValue(bp)}get noAnimation(){return this.properties.getValue(vp)}get autoSize(){return this.properties.getValue(up)}get stretchToFit(){return this.properties.getValue(Rp)}get cropTop(){return this.properties.getValue(wp)}get cropBottom(){return this.properties.getValue(gp)}get cropLeft(){return this.properties.getValue(mp)}get cropRight(){return this.properties.getValue(fp)}get permutationMatrix(){return this.properties.getValue(Ys)}};function Cp(c,t,e,i,r,s,o){let n=1*e,a=t.y+n/2,l=t.x+n/2,h=t.y+t.height-n+n/2,p=t.x+t.width-n+n/2;c.strokePath({color:i,path:new _(p,h).lineTo(p,a).moveTo(p,h).lineTo(l,h)}),c.strokePath({color:r,path:new _(p-n,h-n).lineTo(p-n,a+n).moveTo(p-n,h-n).lineTo(l+n,h-n)}),c.strokePath({color:s,path:new _(l,a).lineTo(p-n,a).moveTo(l,a).lineTo(l,h-n)}),c.strokePath({color:o,path:new _(l+n,a+n).lineTo(p-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,h-n-n)})}function He(c,t,e){Cp(c,t,e,m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST)}function Mr(c,t,e){Cp(c,t,e,m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER)}function Vr(c,t,e,i,r=m.BLACK){let s=3*e,o={x:t.x+s,y:t.y+s,width:t.width-2*s,height:t.height-2*s},n=i==="left"||i==="right",a=n?Math.min(o.width,o.height/2):Math.min(o.height,o.width/2);n?o.x+=(o.width-a)/2:o.y+=(o.height-a)/2,a=Math.max(a,1);let l;switch(i){case"up":l={x:o.x+o.width/2,y:o.y};break;case"down":l={x:o.x+o.width/2,y:o.y+a};break;case"left":l={x:o.x,y:o.y+o.height/2};break;case"right":l={x:o.x+a,y:o.y+o.height/2};break}let h;switch(i){case"up":h=new _(l.x,l.y).lineTo(l.x-a,l.y+a).lineTo(l.x+a,l.y+a).closePath();break;case"down":h=new _(l.x,l.y).lineTo(l.x-a,l.y-a).lineTo(l.x+a,l.y-a).closePath();break;case"left":h=new _(l.x,l.y).lineTo(l.x+a,l.y-a).lineTo(l.x+a,l.y+a).closePath();break;case"right":h=new _(l.x,l.y).lineTo(l.x-a,l.y-a).lineTo(l.x-a,l.y+a).closePath();break}c.fillPath({color:r,path:h})}var Ap="auto_size",zs="font",Op="horizontal_alignment",Ep="show_scrollbar",Mp="vertical_alignment",Vp="wrap_words",Ey=16,My=new m(243,243,243),Ip=new m(232,232,231),Bp=150,Ir=class extends M{scrollOffset=0;maxScroll=0;dragRange;grabStartOffset;actionTimeout;upPressed=!1;downPressed=!1;thumbRegion;upRegion;downRegion;trackAboveRegion;trackBelowRegion;constructor(t,e){super(t,e),this.properties.add(new f(Ap)),this.properties.add(new H(zs)),this.properties.add(new P(Op)),this.properties.add(new f(Ep)),this.properties.add(new P(Mp)),this.properties.add(new f(Vp))}init(){this.thumbRegion={id:`${this.wuid}-scrollbar-thumb`,mouseDown:()=>{this.grabStartOffset=this.scrollOffset},grab:t=>{let e=this.maxScroll*t.dy/(this.dragRange||1);this.setScrollOffset((this.grabStartOffset??0)+e)},tooltip:()=>this.tooltip},this.upRegion={id:`${this.wuid}-scrollbar-up`,mouseDown:()=>{this.upPressed=!0,this.stepScrollRepeatedly(-1)},mouseUp:()=>this.endScrollAction(()=>this.upPressed=!1),mouseOut:()=>this.endScrollAction(()=>this.upPressed=!1),tooltip:()=>this.tooltip},this.downRegion={id:`${this.wuid}-scrollbar-down`,mouseDown:()=>{this.downPressed=!0,this.stepScrollRepeatedly(1)},mouseUp:()=>this.endScrollAction(()=>this.downPressed=!1),mouseOut:()=>this.endScrollAction(()=>this.downPressed=!1),tooltip:()=>this.tooltip},this.trackAboveRegion={id:`${this.wuid}-scrollbar-track-above`,mouseDown:()=>this.pageScrollRepeatedly(-1),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip},this.trackBelowRegion={id:`${this.wuid}-scrollbar-track-below`,mouseDown:()=>this.pageScrollRepeatedly(1),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip}}destroy(){window.clearTimeout(this.actionTimeout)}setScrollOffset(t){this.scrollOffset=Math.min(Math.max(t,0),this.maxScroll),this.requestRepaint()}stepScrollRepeatedly(t){window.clearTimeout(this.actionTimeout),this.setScrollOffset(this.scrollOffset+t*this.font.height*1.2),this.actionTimeout=window.setTimeout(()=>this.stepScrollRepeatedly(t),Bp)}pageScrollRepeatedly(t){window.clearTimeout(this.actionTimeout),this.setScrollOffset(this.scrollOffset+t*this.height),this.actionTimeout=window.setTimeout(()=>this.pageScrollRepeatedly(t),Bp)}endScrollAction(t){window.clearTimeout(this.actionTimeout),t?.(),this.requestRepaint()}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(zs).scale(1);this.customSize=t.measureText(this.text,e,!0)}super.drawHolder(t)}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.wrapWords?this.drawWrapped(t):this.drawText(t)}drawText(t){let e=t.ctx,i={...this.area},r=t.measureText(this.text,this.font,!0);e.font=this.font.getFontString(),e.textBaseline="alphabetic";let o=e.measureText(this.text).fontBoundingBoxAscent,n={x:i.x,y:i.y,width:r.width,height:r.height};this.horizAlignment===0||(this.horizAlignment===1?n.x+=(i.width-r.width)/2:this.horizAlignment===2&&(n.x+=i.width-r.width)),this.vertAlignment===0||i.height<=r.height||(this.vertAlignment===1?n.y+=i.height/2-r.height/2:this.vertAlignment===2&&(n.y+=i.height-r.height)),e.textAlign="start",e.textBaseline="top",n.y+=n.height/2-o/2,e.save(),e.beginPath();let a=this.area;e.rect(a.x,a.y,a.width,a.height),e.clip(),e.fillStyle=this.foregroundColor.toString(),e.fillText(this.text,n.x,n.y),e.restore()}drawWrapped(t){let e=t.ctx,i=t.measureText("Mg",this.font).height,r=this.wrapText(t,this.text,this.width),s=r.length*i,o=this.width,n=!1,a=Ey*this.scale;this.showScrollbar&&s>this.height&&(n=!0,o=Math.max(0,this.width-a),r=this.wrapText(t,this.text,o),s=r.length*i),this.maxScroll=Math.max(0,s-this.height),this.scrollOffset=Math.min(Math.max(this.scrollOffset,0),this.maxScroll),e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let l=this.y;this.height>s&&(this.vertAlignment===1?l+=(this.height-s)/2:this.vertAlignment===2&&(l+=this.height-s)),l-=this.scrollOffset,e.save(),e.beginPath(),e.rect(this.x,this.y,o,this.height),e.clip();for(let h of r){let p=this.x;if(this.horizAlignment===1){let d=e.measureText(h).width;p=this.x+(o-d)/2}else if(this.horizAlignment===2){let d=e.measureText(h).width;p=this.x+(o-d)}e.fillText(h,p,l),l+=i}e.restore(),n&&this.drawScrollbar(t,{x:this.x+o,y:this.y,width:a,height:this.height})}drawScrollbar(t,e){let{scale:i}=this;t.fillRect({...e,color:My});let r=Math.min(e.width,e.height/2);this.drawScrollButton(t,"up",{x:e.x,y:e.y,width:e.width,height:r}),this.drawScrollButton(t,"down",{x:e.x,y:e.y+e.height-r,width:e.width,height:r});let s=e.height-2*r,o=Math.min(1,this.height/(this.height+this.maxScroll)),n=Math.max(6*i,s*o);this.dragRange=s-n;let a=this.maxScroll>0?this.scrollOffset/this.maxScroll:0,l=e.y+r+this.dragRange*a,h={x:e.x,y:l,width:e.width,height:n};t.fillRect({...h,color:Ip}),He(t,h,i),t.addHitRegion(this.thumbRegion).addRect(h.x,h.y,h.width,h.height);let p=e.y+r,d=e.y+e.height-r;t.addHitRegion(this.trackAboveRegion).addRect(e.x,p,e.width,l-p),t.addHitRegion(this.trackBelowRegion).addRect(e.x,l+n,e.width,d-(l+n))}drawScrollButton(t,e,i){let{scale:r}=this,s=e==="up"?this.upPressed:this.downPressed;t.fillRect({...i,color:Ip}),s?Mr(t,i,r):He(t,i,r);let o=e==="up"?this.upRegion:this.downRegion;t.addHitRegion(o).addRect(i.x,i.y,i.width,i.height),Vr(t,i,r,e)}wrapText(t,e,i){let r=[];for(let s of e.replace(/\n$/,"").split(`
21
+ `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[];for(;e.length;){let s;for(s=e.length;t.measureText(e.substr(0,s),this.font).width>i;s--);let o;if(s===e.length)o=e;else if(e[s]===" ")o=e.substr(0,s+1);else{let n=e.substr(0,s),a=0;for(;n.indexOf(" ",a)!==-1;a=n.indexOf(" ",a)+1);if(a)o=n.substr(0,a);else{let l=e.indexOf(" ");o=l===-1?e:e.substr(0,l)}}r.push(o),e=e.substr(o.length)}return r}get autoSize(){return this.properties.getValue(Ap)}get font(){return this.properties.getValue(zs).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Op)}get showScrollbar(){return this.properties.getValue(Ep)}get vertAlignment(){return this.properties.getValue(Mp)}get wrapWords(){return this.properties.getValue(Vp)}};var Hp="alpha",Dp="fill_level",Wp="horizontal_fill",kp="line_color",Np="line_style",Fp="line_width",pe="points",Xs="rotation_angle",Br=class extends M{zeroDegreePoints=[];originPoints;updatingPoints=!1;constructor(t,e){super(t,e),this.properties.add(new P(Hp,255)),this.properties.add(new P(Fp)),this.properties.add(new O(Dp)),this.properties.add(new f(Wp)),this.properties.add(new L(kp)),this.properties.add(new P(Np)),this.properties.add(new kt(pe,[])),this.properties.add(new O(Xs))}init(){this.addPropertyListener("x",(t,e)=>{let i=t-e,r=this.properties.getValue(pe);this.setPointsInternal(pt(r,i,0)),this.zeroDegreePoints=pt(this.zeroDegreePoints,i,0),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=t-e,r=this.properties.getValue(pe);this.setPointsInternal(pt(r,0,i)),this.zeroDegreePoints=pt(this.zeroDegreePoints,0,i),this.requestRepaint()}),this.addPropertyListener(pe,()=>{this.updatingPoints||(this.updateZeroDegreePoints(),this.requestRepaint())}),this.updateZeroDegreePoints(),this.addPropertyListener(Xs,()=>this.requestRepaint())}setPointsInternal(t){this.updatingPoints=!0;try{this.properties.setValue(pe,t)}finally{this.updatingPoints=!1}}updateZeroDegreePoints(){let t=this.properties.getValue(pe),e=this.rotationAngle;this.zeroDegreePoints=e?we(t,-e):t}autoScale(t,e){this.originPoints||(this.originPoints=this.properties.getValue(pe)),M.prototype.autoScale.call(this,t,e);let i=Math.min(...this.originPoints.map(l=>l.x)),r=Math.min(...this.originPoints.map(l=>l.y)),s=Math.round(i*t),o=Math.round(r*e),n=_i(t,e,this.scaleOptions),a=this.originPoints.map(l=>({x:Math.trunc((l.x-i)*n.widthRatio)+s,y:Math.trunc((l.y-r)*n.heightRatio)+o}));this.setPointsInternal(a),this.updateZeroDegreePoints()}draw(t){let{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;let i=_.fromPoints(xi(this.points)).closePath();if(!this.transparent){let r=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:r})}this.lineWidth&&(this.lineStyle===0?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):this.lineStyle===2?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,r=this.width,s=this.height;this.horizontalFill?r*=this.fillLevel/100:(s*=this.fillLevel/100,i+=this.height-s),t.ctx.save();let o=this.x-this.lineWidth/2,n=i-this.lineWidth/2,a=r+this.lineWidth,l=s+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,n,a,l),t.ctx.clip();let h=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:h}),t.ctx.restore()}get alpha(){return this.properties.getValue(Hp)}get lineWidth(){return this.scale*this.properties.getValue(Fp)}get fillLevel(){return this.properties.getValue(Dp)}get horizontalFill(){return this.properties.getValue(Wp)}get lineColor(){return this.properties.getValue(kp)}get lineStyle(){return this.properties.getValue(Np)}get points(){let t=this.rotationAngle,e=t?we(this.zeroDegreePoints,t):this.zeroDegreePoints;return oe(e,this.scale)}get rotationAngle(){return this.properties.getValue(Xs)}};var Gp="alpha",$p="arrows",Up="arrow_length",Yp="fill_arrow",zp="fill_level",Xp="horizontal_fill",qp="line_width",de="points",qs="rotation_angle",Hr=class extends M{zeroDegreePoints=[];originPoints;updatingPoints=!1;constructor(t,e){super(t,e),this.properties.add(new P(Gp,255)),this.properties.add(new P(qp)),this.properties.add(new O(zp)),this.properties.add(new f(Xp)),this.properties.add(new kt(de,[])),this.properties.add(new P(Up)),this.properties.add(new f(Yp)),this.properties.add(new P($p)),this.properties.add(new O(qs))}init(){this.addPropertyListener("x",(t,e)=>{let i=t-e,r=this.properties.getValue(de);this.setPointsInternal(pt(r,i,0)),this.zeroDegreePoints=pt(this.zeroDegreePoints,i,0),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=t-e,r=this.properties.getValue(de);this.setPointsInternal(pt(r,0,i)),this.zeroDegreePoints=pt(this.zeroDegreePoints,0,i),this.requestRepaint()}),this.addPropertyListener(de,()=>{this.updatingPoints||(this.updateZeroDegreePoints(),this.requestRepaint())}),this.updateZeroDegreePoints(),this.addPropertyListener(qs,()=>this.requestRepaint())}setPointsInternal(t){this.updatingPoints=!0;try{this.properties.setValue(de,t)}finally{this.updatingPoints=!1}}updateZeroDegreePoints(){let t=this.properties.getValue(de),e=this.rotationAngle;this.zeroDegreePoints=e?we(t,-e):t}autoScale(t,e){this.originPoints||(this.originPoints=this.properties.getValue(de)),M.prototype.autoScale.call(this,t,e);let i=Math.min(...this.originPoints.map(l=>l.x)),r=Math.min(...this.originPoints.map(l=>l.y)),s=Math.round(i*t),o=Math.round(r*e),n=_i(t,e,this.scaleOptions),a=this.originPoints.map(l=>({x:Math.trunc((l.x-i)*n.widthRatio)+s,y:Math.trunc((l.y-r)*n.heightRatio)+o}));this.setPointsInternal(a),this.updateZeroDegreePoints()}draw(t){let e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.alarmSensitiveBackgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.getFillBounds(),i=e.y,r=e.width,s=e.height;this.horizontalFill?r*=this.fillLevel/100:(s*=this.fillLevel/100,i+=e.height-s),t.save(),t.beginPath(),t.rect(e.x,i,r,s),t.clip(),this.drawShape(t,this.alarmSensitiveForegroundColor),t.restore()}getFillBounds(){let t=this.points,e=t[0].x,i=t[0].x,r=t[0].y,s=t[0].y,o=a=>{e=Math.min(e,a.x),i=Math.max(i,a.x),r=Math.min(r,a.y),s=Math.max(s,a.y)};for(let a of t)o(a);if(this.arrows!==0&&t.length>=2){let a=t[0],l=t[t.length-1];if(this.arrows===2||this.arrows===3)for(let h of this.calculateArrowPoints(t[t.length-2],l))o(h);if(this.arrows===1||this.arrows===3)for(let h of this.calculateArrowPoints(t[1],a))o(h)}let n=this.lineWidth/2;return{x:e-n,y:r-n,width:i-e+this.lineWidth,height:s-r+this.lineWidth}}drawShape(t,e){let i=[...this.points];if(i.length>=2){let r=i[0],s=i[i.length-1];if(this.arrows===2||this.arrows===3){let o=this.calculateArrowPoints(i[i.length-2],s);this.fillArrow&&(i[i.length-1]=o[2]),o[2]=s,this.drawArrowhead(t,e,o,s)}if(this.arrows===1||this.arrows===3){let o=this.calculateArrowPoints(i[1],r);this.fillArrow&&(i[0]=o[2]),o[2]=r,this.drawArrowhead(t,e,o,r)}}t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let r=0;r<i.length;r++)r===0?t.moveTo(i[r].x,i[r].y):t.lineTo(i[r].x,i[r].y);t.stroke()}drawArrowhead(t,e,i,r){if(this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let s=0;s<i.length;s++)s===0?t.moveTo(i[s].x,i[s].y):t.lineTo(i[s].x,i[s].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(i[0].x,i[0].y),t.moveTo(r.x,r.y),t.lineTo(i[1].x,i[1].y),t.stroke()}calculateArrowPoints(t,e){let i=wi(e,t),r=Math.PI/10,s=new Tt(this.arrowLength,i.theta-r),o=new Tt(this.arrowLength,i.theta+r),n=new Tt(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=Dt(s.toPoint(),e.x,e.y),l=Dt(o.toPoint(),e.x,e.y),h=Dt(n.toPoint(),e.x,e.y);return[a,l,h]}get alpha(){return this.properties.getValue(Gp)}get lineWidth(){return this.scale*this.properties.getValue(qp)}get fillLevel(){return this.properties.getValue(zp)}get horizontalFill(){return this.properties.getValue(Xp)}get points(){let t=this.rotationAngle,e=t?we(this.zeroDegreePoints,t):this.zeroDegreePoints,i=oe(e,this.scale);return xi(i)}get rotationAngle(){return this.properties.getValue(qs)}get arrows(){return this.properties.getValue($p)}get fillArrow(){return this.properties.getValue(Yp)}get arrowLength(){return this.scale*this.properties.getValue(Up)}};var Kp="alpha",jp="bg_gradient_color",Zp="fg_gradient_color",Jp="fill_level",Qp="gradient",td="horizontal_fill",ed="line_color",id="line_width",rd="line_style",Dr=class extends M{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(Kp,255)),this.properties.add(new L(jp)),this.properties.add(new L(Zp)),this.properties.add(new f(Qp)),this.properties.add(new P(id)),this.properties.add(new O(Jp)),this.properties.add(new f(td)),this.properties.add(new L(ed)),this.properties.add(new P(rd))}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){let e=this.alarmSensitiveBackgroundColor;if(this.gradient){let i=this.horizontalFill?this.x:this.x+this.width,r=this.horizontalFill?this.y+this.height:this.y,s=t.createLinearGradient(this.x,this.y,i,r);s.addColorStop(0,this.backgroundGradientStartColor.toString()),s.addColorStop(1,e.toString()),t.fillRect({...this.area,gradient:s})}else t.fillRect({...this.area,color:e})}this.lineWidth&&(this.lineStyle===0?t.strokeRect({...this.area,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0}):this.lineStyle===1?t.strokeRect({...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){let e=W(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let r=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,r,e.height)}else{let r=e.height*(this.fillLevel/100),s=e.y+e.height-r;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();let i=this.alarmSensitiveForegroundColor;if(this.gradient){let r=this.horizontalFill?e.x:e.x+e.width,s=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,r,s);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect({...e,gradient:o})}else t.fillRect({...e,color:i});t.ctx.restore()}get alpha(){return this.properties.getValue(Kp)}get lineWidth(){return this.scale*this.properties.getValue(id)}get fillLevel(){return this.properties.getValue(Jp)}get horizontalFill(){return this.properties.getValue(td)}get lineColor(){return this.properties.getValue(ed)}get lineStyle(){return this.properties.getValue(rd)}get gradient(){return this.properties.getValue(Qp)}get backgroundGradientStartColor(){return this.properties.getValue(jp)}get foregroundGradientStartColor(){return this.properties.getValue(Zp)}};var sd="alpha",od="bg_gradient_color",nd="corner_width",ad="corner_height",ld="fg_gradient_color",hd="fill_level",cd="gradient",pd="horizontal_fill",dd="line_color",ud="line_width",gd="line_style",Wr=class extends M{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(sd,255)),this.properties.add(new L(od)),this.properties.add(new L(ld)),this.properties.add(new f(cd)),this.properties.add(new P(ud)),this.properties.add(new O(hd)),this.properties.add(new f(pd)),this.properties.add(new L(dd)),this.properties.add(new P(nd)),this.properties.add(new P(ad)),this.properties.add(new P(gd))}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){let e=this.alarmSensitiveBackgroundColor;if(this.gradient){let i=this.horizontalFill?this.x:this.x+this.width,r=this.horizontalFill?this.y+this.height:this.y,s=t.createLinearGradient(this.x,this.y,i,r);s.addColorStop(0,this.backgroundGradientStartColor.toString()),s.addColorStop(1,e.toString()),t.fillRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:s})}else t.fillRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e})}this.lineWidth&&(this.lineStyle===0?t.strokeRect({...this.area,rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0}):this.lineStyle===1?t.strokeRect({...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){let e=this.cornerWidth/2,i=this.cornerHeight/2,r=W(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){let o=r.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(r.x,r.y,o,r.height)}else{let o=r.height*(this.fillLevel/100),n=r.y+r.height-o;t.ctx.beginPath(),t.ctx.rect(r.x,n,r.width,r.height)}t.ctx.clip();let s=this.alarmSensitiveForegroundColor;if(this.gradient){let o=this.horizontalFill?r.x:r.x+r.width,n=this.horizontalFill?r.y+r.height:r.y,a=t.createLinearGradient(r.x,r.y,o,n);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,s.toString()),t.fillRect({...r,rx:e,ry:i,gradient:a})}else t.fillRect({...r,rx:e,ry:i,color:s});t.ctx.restore()}get alpha(){return this.properties.getValue(sd)}get lineWidth(){return this.scale*this.properties.getValue(ud)}get fillLevel(){return this.properties.getValue(hd)}get horizontalFill(){return this.properties.getValue(pd)}get lineColor(){return this.properties.getValue(dd)}get lineStyle(){return this.properties.getValue(gd)}get gradient(){return this.properties.getValue(cd)}get cornerWidth(){return this.scale*this.properties.getValue(nd)}get cornerHeight(){return this.scale*this.properties.getValue(ad)}get backgroundGradientStartColor(){return this.properties.getValue(od)}get foregroundGradientStartColor(){return this.properties.getValue(ld)}};var md="bitReverse",fd="effect_3d",wd="horizontal",xd="led_border",yd="led_border_color",Pd="led_packed",bd="numBits",vd="off_color",Rd="on_color",_d="startBit",Td="square_led",kr=class extends M{constructor(t,e){super(t,e),this.properties.add(new f(md)),this.properties.add(new f(fd)),this.properties.add(new f(wd)),this.properties.add(new P(bd)),this.properties.add(new L(vd)),this.properties.add(new L(Rd)),this.properties.add(new P(_d)),this.properties.add(new f(Td)),this.properties.add(new P(xd,3)),this.properties.add(new L(yd,m.DARK_GRAY)),this.properties.add(new f(Pd,!1))}getLedColor(t){let e=!1;if(this.value!==void 0)for(let i=this.startBit;i<this.startBit+this.numBits;i++){let r=0;if(this.bitReverse?r=i-this.startBit:r=this.numBits-1-(i-this.startBit),r===t){e=(this.value>>i&1)>0;break}}return e?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=W(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,r;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),r=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),r=i);let s=0;i>e.height||this.squareLed?s=e.height:s=i;for(let o=0;o<this.numBits;o++)if(this.squareLed){let n={x:e.x+o*r,y:e.y,width:i,height:s};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{let n=Math.min(i,s),a={x:e.x+o*r,y:e.y,width:n,height:n};this.effect3d?this.drawCircle3d(t,a,o):this.drawCircle2d(t,a,o)}}drawVertical(t,e){let i,r;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),r=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),r=i);let s=0;i>e.width||this.squareLed?s=e.width:s=i;for(let o=0;o<this.numBits;o++)if(this.squareLed){let n={x:e.x,y:e.y+o*r,width:s,height:i};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{let n=Math.min(s,i),a={x:e.x,y:e.y+o*r,width:n,height:n};this.effect3d?this.drawCircle3d(t,a,o):this.drawCircle2d(t,a,o)}}drawCircle2d(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o=e.width/2,n=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,n-=this.ledBorder/2),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:this.getLedColor(i)}),t.strokeEllipse({cx:r,cy:s,rx:o,ry:n,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o=e.width/2,n=e.height/2;t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:m.WHITE});let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,gradient:a});let l=e.width-2*this.ledBorder,h=e.height-2*this.ledBorder;o=l/2,n=h/2,t.fillEllipse({cx:r,cy:s,rx:o,ry:n,color:this.getLedColor(i)}),a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),a.addColorStop(0,m.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:s,rx:o,ry:n,gradient:a})}drawSquare2d(t,e,i){let r=Ht(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect({...r,color:this.getLedColor(i)}),t.strokeRect({...r,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawSquare3d(t,e,i){t.fillRect({...e,color:this.ledBorderColor});let r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);r.addColorStop(0,"rgba(0,0,0,0.078)"),r.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:r,path:new _(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)}),r=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),r.addColorStop(0,"rgba(0,0,0,0.078)"),r.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:r,path:new _(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)}),r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),r.addColorStop(0,"rgba(255,255,255,0.078)"),r.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:r,path:new _(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)}),r=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),r.addColorStop(0,"rgba(255,255,255,0.078)"),r.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:r,path:new _(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)});let s=e.x+this.ledBorder,o=e.y+this.ledBorder,n=e.width-2*this.ledBorder,a=e.height-2*this.ledBorder,l=this.getLedColor(i);t.fillRect({x:s,y:o,width:n,height:a,color:l}),r=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),r.addColorStop(0,"rgba(255,255,255,0.784)"),r.addColorStop(1,l.withAlpha(0).toString()),t.fillRect({x:s,y:o,width:n,height:a,gradient:r})}get bitReverse(){return this.properties.getValue(md)}get horizontal(){return this.properties.getValue(wd)}get numBits(){return this.properties.getValue(bd)}get startBit(){return this.properties.getValue(_d)}get ledPacked(){return this.properties.getValue(Pd)}get ledBorder(){return this.scale*this.properties.getValue(xd)}get ledBorderColor(){return this.properties.getValue(yd)}get offColor(){return this.properties.getValue(vd)}get onColor(){return this.properties.getValue(Rd)}get effect3d(){return this.properties.getValue(fd)}get squareLed(){return this.properties.getValue(Td)}};var Sd=new m(100,100,100),Vy=16,Iy=8,By=5,Hy=-1,Ld="color_hi",Cd="color_hihi",Ad="color_lo",Od="color_lolo",Ed="effect_3d",Md="font",Vd="value_label_format",Id="level_hi",Bd="level_hihi",Hd="level_lo",Dd="level_lolo",Wd="limits_from_pv",kd="log_scale",Nd="major_tick_step_hint",Fd="minimum",Gd="maximum",$d="needle_color",Ud="ramp_gradient",Yd="scale_font",zd="scale_format",Xd="show_minor_ticks",qd="show_markers",Kd="show_scale",Dy="scale_options",Nr=225,jd=315;var Fr=class extends M{constructor(t,e){super(t,e),this.properties.add(new L(Ld)),this.properties.add(new L(Cd)),this.properties.add(new L(Ad)),this.properties.add(new L(Od)),this.properties.add(new f(Ed)),this.properties.add(new H(Md)),this.properties.add(new O(Id)),this.properties.add(new O(Bd)),this.properties.add(new O(Hd)),this.properties.add(new O(Dd)),this.properties.add(new f(kd)),this.properties.add(new f(Wd,!0)),this.properties.add(new P(Nd,50)),this.properties.add(new O(Gd)),this.properties.add(new O(Fd)),this.properties.add(new L($d)),this.properties.add(new f(Ud)),this.properties.add(new H(Yd)),this.properties.add(new T(zd)),this.properties.add(new f(Xd,!0)),this.properties.add(new f(qd,!0)),this.properties.add(new f(Kd,!0)),this.properties.add(new T(Vd)),this.properties.add(new tt(Dy,new J(!0,!0,!0)))}draw(t){let e;this.limitsFromPv&&this.pv&&!this.pv.disconnected?e={min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:e={min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(e.min=Math.max(.1,e.min),e.max<=e.min&&(e.max=e.min+100));let i=Math.min(this.width,this.height),r=i;this.drawBackground(t,i,r),this.showRamp&&this.drawRamp(t,i,r,e),this.showScale&&this.drawScale(t,i,r,e),this.drawLabel(t,i,r,e),this.drawNeedle(t,i,r,e),this.drawNeedleCenter(t,i,r)}drawBackground(t,e,i){if(t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2,ry:i/2,color:m.GRAY}),this.effect3d){let s=t.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);s.addColorStop(0,Sd.toString()),s.addColorStop(1,m.WHITE.toString()),t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2,ry:i/2,gradient:s})}let r=(this.effect3d?2:1)*this.scale;if(t.fillEllipse({cx:this.x+e/2,cy:this.y+i/2,rx:e/2-r,ry:i/2-r,color:this.backgroundColor}),this.effect3d){let s=e/2,o=9.5/10,n=1/2,a=8.5/10,l=G(0),h=G(35),p={x:Math.floor(this.x+e/2-s*a*Math.cos(l)),y:Math.floor(this.y+i/2-s*o),width:Math.floor(2*s*a*Math.cos(l)),height:Math.floor(s*o+s*n)},d=t.createLinearGradient(p.x,p.y,p.x,p.y+p.height);d.addColorStop(0,m.WHITE.withAlpha(90/255).toString()),d.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:p.x+p.width/2,cy:p.y+p.height/2,rx:p.width/2,ry:p.height/2,gradient:d}),p={x:Math.floor(this.x+e/2-s*a*Math.sin(h)),y:Math.floor(Math.ceil(this.y+i/2+s*n)),width:Math.floor(2*s*a*Math.sin(h)),height:Math.floor(Math.ceil(s*o-s*n))},d=t.createLinearGradient(p.x,p.y,p.x,p.y+p.height),d.addColorStop(0,m.WHITE.withAlpha(0).toString()),d.addColorStop(1,m.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:p.x+p.width/2,cy:p.y+p.height/2,rx:p.width/2,ry:p.height/2,gradient:d})}}drawRamp(t,e,i,r){let s=W({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o={...s};o.width=Math.min(s.width,s.height),o.height=s.width;let n=new Qt(10*this.scale,225,315);n.lolo=r.lolo,n.loloColor=this.colorLoLo,n.lo=r.lo,n.loColor=this.colorLo,n.hi=r.hi,n.hiColor=this.colorHi,n.hihi=r.hihi,n.hihiColor=this.colorHiHi,n.minimum=r.min,n.maximum=r.max,n.effect3d=this.effect3d,n.gradient=this.rampGradient,n.logScale=this.logScale,n.draw(t,s,o)}drawScale(t,e,i,r){let s=new te(Nr,jd,"inward");s.minimum=r.min,s.maximum=r.max,s.logScale=this.logScale,s.showMinorTicks=this.showMinorTicks,s.majorTickStepHint=this.majorTickStepHint*this.scale,s.majorTickLength=this.majorTickLength,s.minorTickLength=this.minorTickLength,s.majorLineWidth=2*this.scale,s.minorLineWidth=1*this.scale,s.format=this.scaleFormat,s.font=this.scaleFont,s.foregroundColor=this.foregroundColor,s.draw(t,{x:this.x,y:this.y,width:e,height:i})}drawLabel(t,e,i,r){let s=X.ARIAL_12_BOLD.scale(this.scale);if(this.value!==void 0){let o=this.formatLabelValue(this.value,r),n=t.measureText(o,s);t.fillText({x:this.x+e/2-n.width/2,y:this.y+i*7/8-n.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:s,text:o})}}drawNeedle(t,e,i,r){let s=this.x+e/2,o=this.y+i/2,n;if(this.value!==void 0){let v=this.getValueInRange(this.value,r);n=360-this.getValuePosition(v,r),r.max>r.min?v>r.max?n+=10:v<r.min&&(n-=10):v>r.min?n-=10:v<r.max&&(n+=10)}else n=360-this.getValuePosition((r.min+r.max)/2,r);let a=G(n),{scale:l}=this,{needleDiameter:h,majorTickLength:p,gapBetweenNeedleScale:d}=this,g=St(s,o-h/2+3*l,s,o,a),x=St(s+e/2-p-d,o,s,o,a),w=St(s,o+h/2-3*l,s,o,a);t.fillPath({color:this.needleColor,path:new _(g.x,g.y).lineTo(x.x,x.y).lineTo(w.x,w.y).closePath()})}drawNeedleCenter(t,e,i){let{needleDiameter:r}=this,s=this.x+e/2,o=this.y+i/2,n=r/2,a=r/2;if(this.effect3d){let l=t.createLinearGradient(s-n,o-a,s+n,o+a);l.addColorStop(0,m.WHITE.toString()),l.addColorStop(1,Sd.toString()),t.fillEllipse({cx:s,cy:o,rx:n,ry:a,gradient:l})}else t.fillEllipse({cx:s,cy:o,rx:n,ry:a,color:m.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i=360-(jd-Nr),r;return this.logScale?r=Nr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*i:r=Nr-(t-e.min)/(e.max-e.min)*i,r<0&&(r+=360),r}formatLabelValue(t,e){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let i=Jt(e.min,e.max);return new rt(i).format(t)}}get needleDiameter(){return this.scale*Vy}get majorTickLength(){return this.scale*Iy}get minorTickLength(){return this.scale*By}get gapBetweenNeedleScale(){return this.scale*Hy}get colorLo(){return this.properties.getValue(Ad)}get colorLoLo(){return this.properties.getValue(Od)}get colorHi(){return this.properties.getValue(Ld)}get colorHiHi(){return this.properties.getValue(Cd)}get effect3d(){return this.properties.getValue(Ed)}get font(){return this.properties.getValue(Md).scale(this.scale)}get levelLo(){return this.properties.getValue(Hd)}get levelLoLo(){return this.properties.getValue(Dd)}get levelHi(){return this.properties.getValue(Id)}get levelHiHi(){return this.properties.getValue(Bd)}get limitsFromPv(){return this.properties.getValue(Wd)}get logScale(){return this.properties.getValue(kd)}get majorTickStepHint(){return this.properties.getValue(Nd)}get minimum(){return this.properties.getValue(Fd)}get maximum(){return this.properties.getValue(Gd)}get needleColor(){return this.properties.getValue($d)}get rampGradient(){return this.properties.getValue(Ud)}get scaleFont(){return this.properties.getValue(Yd).scale(this.scale)}get scaleFormat(){return this.properties.getValue(zd)}get showMinorTicks(){return this.properties.getValue(Xd)}get showRamp(){return this.properties.getValue(qd)}get showScale(){return this.properties.getValue(Kd)}get valueLabelFormat(){return this.properties.getValue(Vd)}};var Zd="auto_size",Jd="bit",Qd="data_type",Wy="height",tu="off_image",eu="off_label",iu="font",ru="on_image",su="on_label",ou="show_boolean_label",nu="stretch_to_fit",ky="width",Gr=class extends M{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new f(Zd,!0)),this.properties.add(new P(Jd)),this.properties.add(new P(Qd)),this.properties.add(new T(tu)),this.properties.add(new T(eu)),this.properties.add(new T(ru)),this.properties.add(new T(su)),this.properties.add(new H(iu)),this.properties.add(new f(ou)),this.properties.add(new f(nu,!1))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.applyAutoSize(),this.requestRepaint()},this.onImage){let t=this.onImageElement;this.display.getImageLoader().load(this.resolvePath(this.onImage)).then(e=>{t.src=e})}if(this.offImage){let t=this.offImageElement;this.display.getImageLoader().load(this.resolvePath(this.offImage)).then(e=>{t.src=e})}}get booleanValue(){return this.bit<0?!!this.value:this.value!==void 0?(this.value>>this.bit&1)>0:!1}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}applyAutoSize(){if(!this.autoSize||this.stretchToFit)return;let t=this.booleanValue?this.onImageElement:this.offImageElement,e=this.booleanValue?this.onImageLoaded:this.offImageLoaded;t&&e&&(this.properties.setValue(ky,t.naturalWidth),this.properties.setValue(Wy,t.naturalHeight))}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.applyAutoSize()}draw(t){let e=this.booleanValue?this.onImageElement:this.offImageElement,i=this.booleanValue?this.onImageLoaded:this.offImageLoaded,r=this.stretchToFit?this.width:e?.naturalWidth,s=this.stretchToFit?this.height:e?.naturalHeight;this.transparent||t.fillRect({x:this.x,y:this.y,width:i?r:this.width,height:i?s:this.height,color:this.backgroundColor}),e&&i&&t.ctx.drawImage(e,this.x,this.y,r,s),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 autoSize(){return this.properties.getValue(Zd)}get stretchToFit(){return this.properties.getValue(nu)}get bit(){return this.properties.getValue(Jd)}get dataType(){return this.properties.getValue(Qd)}get showBooleanLabel(){return this.properties.getValue(ou)}get font(){return this.properties.getValue(iu).scale(this.scale)}get offLabel(){return this.properties.getValue(eu)}get offImage(){return this.properties.getValue(tu)}get onLabel(){return this.properties.getValue(su)}get onImage(){return this.properties.getValue(ru)}};var $r=class{constructor(t,e){this.widget=e;this.id=t}id;selection;grabStart;mouseDown(t){this.grabStart=t}grab(t){this.grabStart&&(this.selection={...this.grabStart.point,width:t.dx,height:t.dy},this.widget.requestRepaint())}grabEnd(){let{selection:t}=this;t&&t.width&&t.height&&this.widget.applyRubberBandZoom(t),this.selection=void 0,this.grabStart=void 0,this.widget.requestRepaint()}dblclick(){this.widget.resetZoom(),this.widget.requestRepaint()}};var au="color_depth",Ny=0,Fy=1,Gy=2,$y=3,Uy=4,Yy=5,lu="color_map",hu="crop_bottom",cu="crop_left",pu="crop_right",du="crop_top",uu="data_height",gu="data_width",mu="font",fu="graph_area_height",wu="graph_area_width",zy=25,xu="horizon_profile_x_pv_name",yu="horizon_profile_y_pv_name",Pu="vertical_profile_x_pv_name",bu="vertical_profile_y_pv_name",vu="maximum",Ru="minimum",_u="rgb_mode",Tu="show_ramp",Su="x_axis_axis_color",Lu="x_axis_axis_title",Cu="x_axis_major_tick_step_hint",Au="x_axis_maximum",Ou="x_axis_minimum",Eu="x_axis_scale_font",Mu="x_axis_show_minor_ticks",Vu="x_axis_title_font",Iu="x_axis_visible",Bu="y_axis_axis_color",Hu="y_axis_axis_title",Du="y_axis_major_tick_step_hint",Wu="y_axis_maximum",ku="y_axis_minimum",Nu="y_axis_scale_font",Fu="y_axis_show_minor_ticks",Gu="y_axis_title_font",$u="y_axis_visible",Xy="scale_options",Ur=class extends M{region;xScale;yScale;graphAreaX=0;graphAreaY=0;renderedGraphAreaWidth=0;renderedGraphAreaHeight=0;_effectiveCropLeft;_effectiveCropRight;_effectiveCropTop;_effectiveCropBottom;_effectiveXAxisMinimum;_effectiveXAxisMaximum;_effectiveYAxisMinimum;_effectiveYAxisMaximum;originalState;constructor(t,e){super(t,e),this.properties.add(new P(au,Ny)),this.properties.add(new ne(lu)),this.properties.add(new P(hu)),this.properties.add(new P(cu)),this.properties.add(new P(pu)),this.properties.add(new P(du)),this.properties.add(new P(uu)),this.properties.add(new P(gu)),this.properties.add(new P(fu)),this.properties.add(new P(wu)),this.properties.add(new T(xu)),this.properties.add(new T(yu)),this.properties.add(new T(Pu)),this.properties.add(new T(bu)),this.properties.add(new H(mu)),this.properties.add(new O(vu)),this.properties.add(new O(Ru)),this.properties.add(new f(_u,!1)),this.properties.add(new f(Tu)),this.properties.add(new L(Su)),this.properties.add(new T(Lu)),this.properties.add(new P(Cu)),this.properties.add(new O(Au)),this.properties.add(new O(Ou)),this.properties.add(new H(Eu)),this.properties.add(new f(Mu)),this.properties.add(new H(Vu)),this.properties.add(new f(Iu)),this.properties.add(new L(Bu)),this.properties.add(new T(Hu)),this.properties.add(new P(Du)),this.properties.add(new O(Wu)),this.properties.add(new O(ku)),this.properties.add(new H(Nu)),this.properties.add(new f(Fu)),this.properties.add(new H(Gu)),this.properties.add(new f($u)),this.properties.add(new tt(Xy,new J(!0,!0,!0)))}init(){this.region=new $r(`${this.wuid}-graph`,this)}draw(t){let{scale:e}=this,i=this.area;this.borderAlarmSensitive&&(i=W(i,2*e));let r=this.alarmSensitiveBackgroundColor;t.fillRect({...i,color:r});let{minimum:s,maximum:o}=this,n=0;this.xAxisVisible&&(n=t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height);let a=0;this.yAxisVisible&&(a=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);let l=this.xScale=new at(this.display.formatter,e,this.xAxisScaleFont,this.effectiveXAxisMinimum,this.effectiveXAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),h=l.calculateMargin(t,!0),p=this.yScale=new at(this.display.formatter,e,this.yAxisScaleFont,this.effectiveYAxisMinimum,this.effectiveYAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),d=p.calculateMargin(t,!1),g=l.measureHorizontalHeight(t),x=i.height-n-g-d,w=x+2*d,v=p.drawVertical(t,i.x+a,i.y,w,!0),S=this.showRamp&&!this.rgbMode,A,C=0,V=0,D=0;S&&(A=new at(this.display.formatter,e,this.font,s,o,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),C=i.y+d,V=x,D=A.drawVertical(t,i.x+i.width,C,V,!1,!0));let N=e*zy,$=S?N+D+this.gap:0,z=i.width-a-v-$,lt=z+2*h,dt=i.x+a+v-h,At=i.y+w+g-d;l.drawHorizontal(t,dt,At,lt);let mt=e*1,bt=Math.round(i.x+a+v)-mt/2,vt=Math.round(i.y+d)-mt/2;t.strokePath({path:new _(bt,vt).lineTo(bt,vt+x),color:this.yAxisAxisColor,opacity:100/255,lineWidth:mt});let Ft=bt,ee=vt+x+mt;t.strokePath({path:new _(Ft,ee).lineTo(Ft+z,ee),color:this.xAxisAxisColor,opacity:100/255,lineWidth:mt});let{dataWidth:Gt,dataHeight:De,colorMap:ie}=this,[ue,ni]=ie.getMinMax(),We=this.graphAreaX=Math.round(i.x+a+v),ke=this.graphAreaY=Math.round(i.y+p.margin);this.renderedGraphAreaWidth=z,this.renderedGraphAreaHeight=x,this.region&&t.addHitRegion(this.region).addRect(We,ke,z,x);let ai=this.rgbMode;if(this.value&&this.value.length&&(!ai||this.value.length>=3*Gt*De)){let ut=document.createElement("canvas"),{effectiveCropLeft:Ot,effectiveCropRight:$t,effectiveCropTop:wt,effectiveCropBottom:re}=this;ut.width=Gt-Ot-$t,ut.height=De-wt-re;let Et=ut.getContext("2d");for(let ht=Ot;ht<Gt-$t;ht++)for(let gt=wt;gt<De-re;gt++){if(ai){let ct=(gt*Gt+ht)*3,Mt=this.applyColorDepth(this.value[ct],s,o),Pt=this.applyColorDepth(this.value[ct+1],s,o),Z=this.applyColorDepth(this.value[ct+2],s,o);Et.fillStyle=`rgb(${Mt},${Pt},${Z})`}else{let ct=this.value[gt*Gt+ht];if(ie.autoscale){let Vt=(ct-s)/(o-s);ct=ue+Vt*(ni-ue)}let[Mt,Pt,Z]=ie.lookup(ct);Et.fillStyle=`rgb(${Mt},${Pt},${Z})`}Et.fillRect(ht-Ot,gt-wt,1,1)}t.ctx.drawImage(ut,We,ke,z,x);let ft=ut.width,yt=ut.height;if(this.horizonProfileXPvName||this.horizonProfileYPvName){let ht=new Array(ft);for(let Z=0;Z<ft;Z++){let Vt=0;for(let Rt=0;Rt<yt;Rt++)Vt+=this.pixelValueAt(wt+Rt,Ot+Z);ht[Z]=Vt/yt}let{effectiveXAxisMinimum:gt,effectiveXAxisMaximum:ct}=this,Mt=ft>1?(ct-gt)/(ft-1):0,Pt=new Array(ft);for(let Z=0;Z<ft;Z++)Pt[Z]=gt+Z*Mt;this.pushProfilePV(this.horizonProfileXPvName,Pt),this.pushProfilePV(this.horizonProfileYPvName,ht)}if(this.verticalProfileXPvName||this.verticalProfileYPvName){let ht=new Array(yt);for(let Z=0;Z<yt;Z++){let Vt=0;for(let Rt=0;Rt<ft;Rt++)Vt+=this.pixelValueAt(wt+Z,Ot+Rt);ht[Z]=Vt/ft}let{effectiveYAxisMinimum:gt,effectiveYAxisMaximum:ct}=this,Mt=yt>1?(ct-gt)/(yt-1):0,Pt=new Array(yt);for(let Z=0;Z<yt;Z++)Pt[Z]=ct-Z*Mt;this.pushProfilePV(this.verticalProfileXPvName,Pt),this.pushProfilePV(this.verticalProfileYPvName,ht)}}if(S&&A){let ut=i.x+i.width-D-N,Ot=N,$t=V-2*A.margin,wt=document.createElement("canvas");wt.width=Ot,wt.height=$t;let re=wt.getContext("2d");for(let Et=0;Et<$t;Et++){let ft=o-Et/$t*(o-s);if(ie.autoscale){let ct=(ft-s)/(o-s);ft=ue+ct*(ni-ue)}let[yt,ht,gt]=ie.lookup(ft);re.fillStyle=`rgb(${yt},${ht},${gt})`,re.fillRect(0,Et,Ot,1)}t.ctx.drawImage(wt,ut,C+A.margin)}if(this.xAxisVisible){let ut=i.x+v+z/2;this.yAxisVisible&&(ut+=a),t.fillText({x:ut,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+a/2,i.y+w/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());let li=this.region?.selection;if(li){let ut={x:We,y:ke,width:z,height:x};t.strokeRect({...fi(ut,li),color:m.BLACK,lineWidth:e,dash:[2*e,2*e]})}}applyRubberBandZoom(t){if(!this.xScale||!this.yScale||!this.renderedGraphAreaWidth||!this.renderedGraphAreaHeight)return;this.originalState||(this.originalState={cropLeft:this.effectiveCropLeft,cropRight:this.effectiveCropRight,cropTop:this.effectiveCropTop,cropBottom:this.effectiveCropBottom,xAxisMinimum:this.effectiveXAxisMinimum,xAxisMaximum:this.effectiveXAxisMaximum,yAxisMinimum:this.effectiveYAxisMinimum,yAxisMaximum:this.effectiveYAxisMaximum});let{dataWidth:e,dataHeight:i,graphAreaX:r,graphAreaY:s}=this,{renderedGraphAreaWidth:o,renderedGraphAreaHeight:n}=this,a=this.effectiveCropLeft,l=this.effectiveCropRight,h=this.effectiveCropTop,p=this.effectiveCropBottom,d=e-a-l,g=i-h-p,x=Math.min(t.x,t.x+t.width),w=Math.max(t.x,t.x+t.width),v=Math.min(t.y,t.y+t.height),S=Math.max(t.y,t.y+t.height),A=(Ft,ee)=>({x:Math.round(d*(Ft-r)/o),y:Math.round(g*(ee-s)/n)}),C=A(x,v),V=A(w,S),D=a+C.x,N=h+C.y,$=l+d-V.x,z=p+g-V.y;if(D+$>=e||N+z>=i)return;this.effectiveCropLeft=D,this.effectiveCropTop=N,this.effectiveCropRight=$,this.effectiveCropBottom=z;let lt=this.xScale.getMinMax(),dt=this.xScale.getPositionValue(t.x),At=this.xScale.getPositionValue(t.x+t.width);dt>At&&([dt,At]=[At,dt]),this.effectiveXAxisMinimum=Math.max(lt.start,dt),this.effectiveXAxisMaximum=Math.min(lt.stop,At);let mt=this.yScale.getMinMax(),bt=this.yScale.getPositionValue(t.y),vt=this.yScale.getPositionValue(t.y+t.height);bt>vt&&([bt,vt]=[vt,bt]),this.effectiveYAxisMinimum=Math.max(mt.start,bt),this.effectiveYAxisMaximum=Math.min(mt.stop,vt)}resetZoom(){let{originalState:t}=this;t&&(this.effectiveCropLeft=t.cropLeft,this.effectiveCropRight=t.cropRight,this.effectiveCropTop=t.cropTop,this.effectiveCropBottom=t.cropBottom,this.effectiveXAxisMinimum=t.xAxisMinimum,this.effectiveXAxisMaximum=t.xAxisMaximum,this.effectiveYAxisMinimum=t.yAxisMinimum,this.effectiveYAxisMaximum=t.yAxisMaximum)}pushProfilePV(t,e){t&&(this.display.pvEngine.createPV(t),this.display.pvEngine.setValue(new Date,t,e))}applyColorDepth(t,e,i){let r=Math.trunc(t);switch(this.colorDepth){case Fy:return r>>8;case Gy:return r>>16;case $y:return r>>22;case Yy:return r&255;case Uy:return Math.trunc((t-e)/(i-e)*255);default:return r}}pixelValueAt(t,e){if(this.rgbMode){let i=(t*this.dataWidth+e)*3;return(this.value[i]+this.value[i+1]+this.value[i+2])/3}return this.value[t*this.dataWidth+e]}get effectiveCropLeft(){return this._effectiveCropLeft??this.cropLeft}set effectiveCropLeft(t){this._effectiveCropLeft=t}get effectiveCropRight(){return this._effectiveCropRight??this.cropRight}set effectiveCropRight(t){this._effectiveCropRight=t}get effectiveCropTop(){return this._effectiveCropTop??this.cropTop}set effectiveCropTop(t){this._effectiveCropTop=t}get effectiveCropBottom(){return this._effectiveCropBottom??this.cropBottom}set effectiveCropBottom(t){this._effectiveCropBottom=t}get effectiveXAxisMinimum(){return this._effectiveXAxisMinimum??this.xAxisMinimum}set effectiveXAxisMinimum(t){this._effectiveXAxisMinimum=t}get effectiveXAxisMaximum(){return this._effectiveXAxisMaximum??this.xAxisMaximum}set effectiveXAxisMaximum(t){this._effectiveXAxisMaximum=t}get effectiveYAxisMinimum(){return this._effectiveYAxisMinimum??this.yAxisMinimum}set effectiveYAxisMinimum(t){this._effectiveYAxisMinimum=t}get effectiveYAxisMaximum(){return this._effectiveYAxisMaximum??this.yAxisMaximum}set effectiveYAxisMaximum(t){this._effectiveYAxisMaximum=t}get gap(){return this.scale*3}get colorDepth(){return this.properties.getValue(au)}get colorMap(){return this.properties.getValue(lu)}get cropBottom(){return this.properties.getValue(hu)}get cropLeft(){return this.properties.getValue(cu)}get cropRight(){return this.properties.getValue(pu)}get cropTop(){return this.properties.getValue(du)}get dataHeight(){return this.properties.getValue(uu)}get dataWidth(){return this.properties.getValue(gu)}get font(){return this.properties.getValue(mu).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(fu)}get graphAreaWidth(){return this.scale*this.properties.getValue(wu)}get horizonProfileXPvName(){return this.properties.getValue(xu)}get horizonProfileYPvName(){return this.properties.getValue(yu)}get verticalProfileXPvName(){return this.properties.getValue(Pu)}get verticalProfileYPvName(){return this.properties.getValue(bu)}get maximum(){return this.properties.getValue(vu)}get minimum(){return this.properties.getValue(Ru)}get rgbMode(){return this.properties.getValue(_u)}get showRamp(){return this.properties.getValue(Tu)}get xAxisAxisColor(){return this.properties.getValue(Su)}get xAxisAxisTitle(){return this.properties.getValue(Lu)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Cu)}get xAxisMaximum(){return this.properties.getValue(Au)}get xAxisMinimum(){return this.properties.getValue(Ou)}get xAxisScaleFont(){return this.properties.getValue(Eu).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Mu)}get xAxisTitleFont(){return this.properties.getValue(Vu).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Iu)}get yAxisAxisColor(){return this.properties.getValue(Bu)}get yAxisAxisTitle(){return this.properties.getValue(Hu)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Du)}get yAxisMaximum(){return this.properties.getValue(Wu)}get yAxisMinimum(){return this.properties.getValue(ku)}get yAxisScaleFont(){return this.properties.getValue(Nu).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(Fu)}get yAxisTitleFont(){return this.properties.getValue(Gu).scale(this.scale)}get yAxisVisible(){return this.properties.getValue($u)}};var Uu="bit",Yu="data_type",zu="effect_3d",Xu="state_count",qu="square_led",Ku="off_color",ju="off_label",Zu="off_state",Ju="font",Qu="on_color",tg="on_label",eg="on_state",ig="bulb_border",rg="bulb_border_color",sg="state_color_fallback",og="state_label_fallback",ng="show_boolean_label",qy="scale_options",Yr=class extends M{areaRegion;states=[];constructor(t,e){super(t,e),this.properties.add(new P(Uu)),this.properties.add(new P(Yu)),this.properties.add(new f(zu)),this.properties.add(new f(qu)),this.properties.add(new P(Xu,2)),this.properties.add(new L(Ku)),this.properties.add(new T(ju)),this.properties.add(new T(Zu)),this.properties.add(new L(Qu)),this.properties.add(new T(tg)),this.properties.add(new T(eg)),this.properties.add(new H(Ju)),this.properties.add(new f(ng)),this.properties.add(new L(sg)),this.properties.add(new T(og)),this.properties.add(new P(ig,3)),this.properties.add(new L(rg,m.DARK_GRAY)),this.properties.add(new tt(qy,new J(!0,!0,!0)))}async parseNode(t){if(await super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){let i=new L(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);let r=new T(`state_label_${e}`);r.value=t.getString(`state_label_${e}`),this.properties.add(r);let s=new O(`state_value_${e}`);s.value=t.getFloat(`state_value_${e}`),this.properties.add(s),this.states.push({label:this.properties.getValue(r.name),color:this.properties.getValue(i.name),value:this.properties.getValue(s.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){return this.dataType===0?this.bit<0?!!this.value:this.value!==void 0?(this.value>>this.bit&1)>0:!1:this.dataType===1?(this.value!==void 0?String(this.value):void 0)===this.onState:!1}get bulbColor(){if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(let t of this.states)if(t.value===this.value)return t.color;return this.stateColorFallback}get label(){if(this.stateCount===2)return this.booleanValue?this.onLabel:this.offLabel;for(let t of this.states)if(t.value===this.value)return t.label;return this.stateLabelFallback}draw(t){let e=W(this.bounds,3*this.scale);if(this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel){let i=this.bulbColor;i.red*299+i.green*587+i.blue*114>105e3?i=m.BLACK:i=m.WHITE,t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:i,text:this.label})}}drawCircle2d(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;this.bulbBorder>0&&(s-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addEllipse(i,r,s,o,0,0,2*Math.PI)}drawCircle3d(t,e){let i=e.x+e.width/2,r=e.y+e.height/2,s=e.width/2,o=e.height/2;t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:m.WHITE});let n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);n.addColorStop(0,this.bulbBorderColor.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n});let a=e.width-2*this.bulbBorder,l=e.height-2*this.bulbBorder;s=a/2,o=l/2,t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:this.bulbColor}),n=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:n}),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addEllipse(i,r,s,o,0,0,2*Math.PI)}drawSquare2d(t,e){let i=Ht(e.x,e.y,e.width,e.height,this.bulbBorder);t.fillRect({...i,color:this.bulbColor}),t.strokeRect({...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){t.fillRect({...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 _(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 _(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 _(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 _(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)});let r=e.x+this.bulbBorder,s=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,n=e.height-2*this.bulbBorder;t.fillRect({x:r,y:s,width:o,height:n,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:r,y:s,width:o,height:n,gradient:i})}get bit(){return this.properties.getValue(Uu)}get dataType(){return this.properties.getValue(Yu)}get squareLed(){return this.properties.getValue(qu)}get showBooleanLabel(){return this.properties.getValue(ng)}get font(){return this.properties.getValue(Ju).scale(this.scale)}get effect3d(){return this.properties.getValue(zu)}get stateCount(){return this.properties.getValue(Xu)}get bulbBorder(){return this.scale*this.properties.getValue(ig)}get bulbBorderColor(){return this.properties.getValue(rg)}get offLabel(){return this.properties.getValue(ju)}get offColor(){return this.properties.getValue(Ku)}get offState(){return this.properties.getValue(Zu)}get onLabel(){return this.properties.getValue(tg)}get onColor(){return this.properties.getValue(Qu)}get onState(){return this.properties.getValue(eg)}get stateLabelFallback(){return this.properties.getValue(og)}get stateColorFallback(){return this.properties.getValue(sg)}};var Ky=16,jy=12,Zy=-5,Ks=45,zr=G(Ks),ag=(1-Math.sin(zr)/2)/(2*Math.cos(zr)),Jy=8,Qy=5,tP=180-Ks,eP=Ks,lg="color_hi",hg="color_hihi",cg="color_lo",pg="color_lolo",dg="font",ug="level_hi",gg="level_hihi",mg="level_lo",fg="level_lolo",wg="limits_from_pv",xg="log_scale",yg="major_tick_step_hint",Pg="minimum",bg="maximum",vg="needle_color",Rg="ramp_gradient",_g="scale_font",Tg="scale_format",Sg="show_hi",Lg="show_hihi",Cg="show_lo",Ag="show_lolo",Og="show_minor_ticks",Eg="show_markers",Mg="show_scale",Vg="show_value_label",Ig="value_label_format",iP="scale_options",Xr=class extends M{areaRegion;constructor(t,e){super(t,e),this.properties.add(new L(lg)),this.properties.add(new L(hg)),this.properties.add(new L(cg)),this.properties.add(new L(pg)),this.properties.add(new H(dg)),this.properties.add(new P(ug)),this.properties.add(new P(gg)),this.properties.add(new P(mg)),this.properties.add(new P(fg)),this.properties.add(new f(xg)),this.properties.add(new f(wg,!0)),this.properties.add(new P(yg,50)),this.properties.add(new P(bg)),this.properties.add(new P(Pg)),this.properties.add(new L(vg)),this.properties.add(new f(Rg)),this.properties.add(new H(_g)),this.properties.add(new T(Tg)),this.properties.add(new f(Sg)),this.properties.add(new f(Lg)),this.properties.add(new f(Cg)),this.properties.add(new f(Ag)),this.properties.add(new f(Og,!0)),this.properties.add(new f(Eg,!0)),this.properties.add(new f(Mg,!0)),this.properties.add(new f(Vg,!0)),this.properties.add(new T(Ig)),this.properties.add(new tt(iP,new J(!0,!0,!0)))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.drawRamp(t,this.computeLimits()),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}computeLimits(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:this.pv.lowerDisplayLimit??this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:this.pv.upperDisplayLimit??this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum}}drawRamp(t,e){let i=new te(tP,eP,"outward");i.minimum=e.min,i.maximum=e.max,i.logScale=this.logScale,i.showMinorTicks=this.showMinorTicks,i.visible=this.showScale,i.majorTickStepHint=this.majorTickStepHint*this.scale,i.majorTickLength=this.majorTickLength,i.minorTickLength=this.minorTickLength,i.majorLineWidth=2*this.scale,i.minorLineWidth=1*this.scale,i.format=this.scaleFormat,i.font=this.scaleFont,i.foregroundColor=this.foregroundColor;let r=i.formatText(e.min),s=t.measureText(r,this.scaleFont),o=i.formatText(e.max),n=t.measureText(o,this.scaleFont),a=Math.max(s.width,n.width)/2,l=this.height,h=this.width;l>ag*(h-2*a)&&(l=Math.floor(ag*(h-2*a)));let p=l/(1-Math.sin(zr)/2),d=Math.floor(this.x-p*(1-Math.cos(zr))+a),g=this.y,x={x:d,y:g,width:Math.floor(2*p),height:Math.floor(2*p)},{rampWidth:w}=this,v=W(x,x.width/4-w,x.height/4-w);v.width=Math.min(v.width,v.height),v.height=v.width;let S=new Qt(w,135,45);S.lolo=e.lolo,S.loloColor=this.colorLoLo,S.showLoLo=!0,S.lo=e.lo,S.loColor=this.colorLo,S.showLo=!0,S.hi=e.hi,S.hiColor=this.colorHi,S.showHi=!0,S.hihi=e.hihi,S.hihiColor=this.colorHiHi,S.showHiHi=!0,S.minimum=e.min,S.maximum=e.max,S.gradient=this.rampGradient,S.logScale=this.logScale,S.draw(t,x,v,this.showRamp),i.draw(t,x),this.drawNeedle(t,x,S,i.getRadius(),e);let A=X.ARIAL_12_BOLD.scale(this.scale);if(this.showValueLabel&&this.value!==void 0){let C=this.format(this.value,e),V=t.measureText(C,A);t.fillText({x:x.x+x.width/2-V.width/2,y:x.y+x.height/2-x.height/4-(i.getRadius()-x.height/4)/2-V.height/2,align:"left",baseline:"top",font:A,text:C,color:this.foregroundColor})}}drawNeedle(t,e,i,r,s){let o=e.x+e.width/2,n=e.y+e.height/2,a;if(this.value!==void 0){let v=i.getValueInRange(this.value);a=360-i.getValuePosition(v),s.max>s.min?v>s.max?a+=8:v<s.min&&(a-=8):v>s.min?a-=8:v<s.max&&(a+=8)}else a=360-i.getValuePosition(s.min+s.max/2);let l=G(a),{needleWidth:h,gapBetweenNeedleScale:p,scale:d}=this,g=St(o+e.width/4,n-h/2+3*d,o,n,l),x=St(o+r-p,n,o,n,l),w=St(o+e.width/4,n+h/2-3*d,o,n,l);t.fillPath({color:this.needleColor,path:new _(g.x,g.y).lineTo(x.x,x.y).lineTo(w.x,w.y).closePath()})}get needleWidth(){return this.scale*Ky}get gapBetweenNeedleScale(){return this.scale*Zy}get rampWidth(){return this.scale*jy}format(t,e){if(this.valueLabelFormat)return new rt(this.valueLabelFormat).format(t);{let i=Jt(e.min,e.max);return new rt(i).format(t)}}get colorLo(){return this.properties.getValue(cg)}get colorLoLo(){return this.properties.getValue(pg)}get colorHi(){return this.properties.getValue(lg)}get colorHiHi(){return this.properties.getValue(hg)}get font(){return this.properties.getValue(dg).scale(this.scale)}get levelLo(){return this.properties.getValue(mg)}get levelLoLo(){return this.properties.getValue(fg)}get levelHi(){return this.properties.getValue(ug)}get levelHiHi(){return this.properties.getValue(gg)}get limitsFromPv(){return this.properties.getValue(wg)}get logScale(){return this.properties.getValue(xg)}get majorTickStepHint(){return this.properties.getValue(yg)}get majorTickLength(){return this.scale*Jy}get minorTickLength(){return this.scale*Qy}get minimum(){return this.properties.getValue(Pg)}get maximum(){return this.properties.getValue(bg)}get needleColor(){return this.properties.getValue(vg)}get rampGradient(){return this.properties.getValue(Rg)}get scaleFont(){return this.properties.getValue(_g).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Tg)}get showLo(){return this.properties.getValue(Cg)}get showLoLo(){return this.properties.getValue(Ag)}get showHi(){return this.properties.getValue(Sg)}get showHiHi(){return this.properties.getValue(Lg)}get showMinorTicks(){return this.properties.getValue(Og)}get showRamp(){return this.properties.getValue(Eg)}get showScale(){return this.properties.getValue(Mg)}get showValueLabel(){return this.properties.getValue(Vg)}get valueLabelFormat(){return this.properties.getValue(Ig)}};var Bg="color_hi",Hg="color_hihi",Dg="color_lo",Wg="color_lolo",kg="color_fillbackground",Ng="effect_3d",Fg="fill_color",Gg="fillcolor_alarm_sensitive",$g="font",Ug="horizontal",Yg="indicator_mode",zg="level_hi",Xg="level_hihi",qg="level_lo",Kg="level_lolo",jg="limits_from_pv",Zg="log_scale",Jg="maximum",Qg="major_tick_step_hint",tm="minimum",em="origin",im="origin_ignored",rm="scale_font",sm="scale_format",om="show_hi",nm="show_hihi",am="show_label",lm="show_lo",hm="show_lolo",cm="show_markers",pm="show_minor_ticks",dm="show_scale",um="transparent_background",gm="value_label_format",qr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new L(Bg)),this.properties.add(new L(Hg)),this.properties.add(new L(Dg)),this.properties.add(new L(Wg)),this.properties.add(new L(kg)),this.properties.add(new f(Ng)),this.properties.add(new L(Fg)),this.properties.add(new f(Gg,!1)),this.properties.add(new H($g)),this.properties.add(new f(Ug)),this.properties.add(new f(Yg)),this.properties.add(new O(zg)),this.properties.add(new O(Xg)),this.properties.add(new O(qg)),this.properties.add(new O(Kg)),this.properties.add(new f(jg,!0)),this.properties.add(new f(Zg)),this.properties.add(new O(Jg)),this.properties.add(new O(Qg)),this.properties.add(new O(tm)),this.properties.add(new O(em,0)),this.properties.add(new f(im,!0)),this.properties.add(new H(rm)),this.properties.add(new T(sm)),this.properties.add(new f(om)),this.properties.add(new f(nm)),this.properties.add(new f(am)),this.properties.add(new f(lm)),this.properties.add(new f(hm)),this.properties.add(new f(cm)),this.properties.add(new f(pm)),this.properties.add(new f(dm)),this.properties.add(new f(um)),this.properties.add(new T(gm))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=W(this.area,2*this.scale));let i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect({...e,color:i}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){let i=this.alarmSensitiveForegroundColor,r=new at(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);r.scaleFormat=this.scaleFormat;let s=r.drawVertical(t,e.x,e.y,e.height,!0),o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,r,e)),this.drawVerticalBar(t,r,{x:e.x+s,y:e.y+r.margin,width:e.width-s-o,height:e.height-2*r.margin})}drawVerticalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let p=t.measureText("LOLO",a);l=Math.max(l,p.width)}if(this.showLo&&s!==void 0){let p=t.measureText("LO",a);l=Math.max(l,p.width)}if(this.showHi&&o!==void 0){let p=t.measureText("HI",a);l=Math.max(l,p.width)}if(this.showHiHi&&n!==void 0){let p=t.measureText("HIHI",a);l=Math.max(l,p.width)}let h=i.x+i.width;if(this.showLoLo&&r!==void 0){let p=h-l-this.markerGap,d=Math.round(e.getValuePosition(r));t.strokePath({path:new _(p,d).lineTo(p-this.markerTickLength,d),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:p+this.markerGap,y:d,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let p=h-l-this.markerGap,d=Math.round(e.getValuePosition(s));t.strokePath({path:new _(p,d).lineTo(p-this.markerTickLength,d),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:p+this.markerGap,y:d,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let p=h-l-this.markerGap,d=Math.round(e.getValuePosition(o));t.strokePath({path:new _(p,d).lineTo(p-this.markerTickLength,d),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:p+this.markerGap,y:d,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let p=h-l-this.markerGap,d=Math.round(e.getValuePosition(n));t.strokePath({path:new _(p,d).lineTo(p-this.markerTickLength,d),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:p+this.markerGap,y:d,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawVerticalBar(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let n=t.createLinearGradient(i.x,0,i.x+i.width,0);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:n});let a=W(i,r/2);t.strokeRect({...a,color:m.GRAY,lineWidth:r})}let s=this.alarmSensitiveFillColor;if(this.indicatorMode){let n=Math.round(e.getValuePosition(this.getFillValue())),a=i.width,l=this.thumbBreadth,h=pt([{x:0,y:l/2},{x:a/2,y:0},{x:a-1,y:l/2},{x:a/2,y:l}],i.x,n-l/2),p=_.fromPoints(h);if(this.effect3d){let{x:d,y:g}=h[0],{x,y:w}=h[2],v=t.createLinearGradient(d,g,x,w);v.addColorStop(0,m.WHITE.toString()),v.addColorStop(1,s.toString()),t.fillPath({path:p,gradient:v}),t.strokePath({path:p,color:m.GRAY,lineWidth:r})}else t.fillPath({path:p,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let d=n;n=a,a=d}let l=Math.round(e.getValuePosition(n)),h=Math.round(e.getValuePosition(a)),p=W({...i,y:l,height:h-l},r);if(t.fillRect({...p,color:s}),this.effect3d){let d=t.createLinearGradient(p.x,0,p.x+p.width,0);d.addColorStop(0,m.WHITE.toString()),d.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...p,gradient:d})}}let o=this.value;this.showLabel&&o!==void 0&&t.fillText({x:i.x+i.width/2,y:i.y+i.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(o)})}drawHorizontal(t,e){let i=this.alarmSensitiveForegroundColor,r=new at(this.display.formatter,this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);r.scaleFormat=this.scaleFormat;let s=r.drawHorizontal(t,e.x,e.y+e.height,e.width),o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,r,e)),this.drawHorizontalBar(t,r,{x:e.x+r.margin,y:e.y+o,width:e.width-2*r.margin,height:e.height-s-o})}drawHorizontalMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let p=t.measureText("LOLO",a);l=Math.max(l,p.height)}if(this.showLo&&s!==void 0){let p=t.measureText("LO",a);l=Math.max(l,p.height)}if(this.showHi&&o!==void 0){let p=t.measureText("HI",a);l=Math.max(l,p.height)}if(this.showHiHi&&n!==void 0){let p=t.measureText("HIHI",a);l=Math.max(l,p.height)}let h=i.y;if(this.showLoLo&&r!==void 0){let p=Math.round(e.getValuePosition(r)),d=h+l+this.markerGap;t.strokePath({path:new _(p,d).lineTo(p,d+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:p,y:h,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let p=Math.round(e.getValuePosition(s)),d=h+l+this.markerGap;t.strokePath({path:new _(p,d).lineTo(p,d+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:p,y:h,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let p=Math.round(e.getValuePosition(o)),d=h+l+this.markerGap;t.strokePath({path:new _(p,d).lineTo(p,d+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:p,y:h,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let p=Math.round(e.getValuePosition(n)),d=h+l+this.markerGap;t.strokePath({path:new _(p,d).lineTo(p,d+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:p,y:h,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawHorizontalBar(t,e,i){let{outlineWidth:r}=this;if(t.fillRect({...i,color:this.colorFillbackground}),this.effect3d){let n=t.createLinearGradient(0,i.y,0,i.y+i.height);n.addColorStop(0,m.WHITE.toString()),n.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect({...i,gradient:n});let a=W(i,r/2);t.strokeRect({...a,color:m.GRAY,lineWidth:r})}let s=this.alarmSensitiveFillColor;if(this.indicatorMode){let n=Math.round(e.getValuePosition(this.getFillValue())),a=i.height,l=this.thumbBreadth,h=pt([{x:l/2,y:0},{x:l,y:a/2},{x:l/2,y:a-1},{x:0,y:a/2}],n-l/2,i.y),p=_.fromPoints(h);if(this.effect3d){let{x:d,y:g}=h[0],{x,y:w}=h[2],v=t.createLinearGradient(d,g,x,w);v.addColorStop(0,m.WHITE.toString()),v.addColorStop(1,s.toString()),t.fillPath({path:p,gradient:v}),t.strokePath({path:p,color:m.GRAY,lineWidth:r})}else t.fillPath({path:p,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let d=n;n=a,a=d}let l=Math.round(e.getValuePosition(n)),h=Math.round(e.getValuePosition(a)),p=W({...i,x:l,width:h-l},r);if(t.fillRect({...p,color:s}),this.effect3d){let d=t.createLinearGradient(0,p.y,0,p.y+p.height);d.addColorStop(0,m.WHITE.toString()),d.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...p,gradient:d})}}let o=this.value;this.showLabel&&o!==void 0&&t.fillText({x:i.x+i.width/2,y:i.y+i.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(o)})}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get thumbBreadth(){return this.scale*13}get outlineWidth(){return this.scale*1}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Dg)}get colorLoLo(){return this.properties.getValue(Wg)}get colorHi(){return this.properties.getValue(Bg)}get colorHiHi(){return this.properties.getValue(Hg)}get colorFillbackground(){return this.properties.getValue(kg)}get effect3d(){return this.properties.getValue(Ng)}get fillColorAlarmSensitive(){return this.properties.getValue(Gg)}get fillColor(){return this.properties.getValue(Fg)}get font(){return this.properties.getValue($g).scale(this.scale)}get horizontal(){return this.properties.getValue(Ug)}get indicatorMode(){return this.properties.getValue(Yg)}get levelLo(){return this.properties.getValue(qg)}get levelLoLo(){return this.properties.getValue(Kg)}get levelHi(){return this.properties.getValue(zg)}get levelHiHi(){return this.properties.getValue(Xg)}get limitsFromPv(){return this.properties.getValue(jg)}get logScale(){return this.properties.getValue(Zg)}get minimum(){return this.properties.getValue(tm)}get majorTickStepHint(){return this.scale*this.properties.getValue(Qg)}get maximum(){return this.properties.getValue(Jg)}get origin(){return this.properties.getValue(em)}get originIgnored(){return this.properties.getValue(im)}get scaleFont(){return this.properties.getValue(rm).scale(this.scale)}get scaleFormat(){return this.properties.getValue(sm)}get showHi(){return this.properties.getValue(om)}get showHiHi(){return this.properties.getValue(nm)}get showLabel(){return this.properties.getValue(am)}get showLo(){return this.properties.getValue(lm)}get showLoLo(){return this.properties.getValue(hm)}get showMarkers(){return this.properties.getValue(cm)}get showMinorTicks(){return this.properties.getValue(pm)}get showScale(){return this.properties.getValue(dm)}get transparentBackground(){return this.properties.getValue(um)}get valueLabelFormat(){return this.properties.getValue(gm)}};var mm="color_hi",fm="color_hihi",wm="color_lo",xm="color_lolo",ym="color_fillbackground",Pm="fill_color",bm="fillcolor_alarm_sensitive",vm="effect_3d",Rm="level_hi",_m="level_hihi",Tm="level_lo",Sm="level_lolo",Lm="limits_from_pv",Cm="log_scale",Am="maximum",Om="major_tick_step_hint",Em="minimum",Mm="scale_font",Vm="scale_format",Im="show_hi",Bm="show_hihi",Hm="show_lo",Dm="show_lolo",Wm="show_markers",km="show_minor_ticks",Nm="show_scale",Fm="transparent_background",rP=new m(160,160,160),Kr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new L(mm)),this.properties.add(new L(fm)),this.properties.add(new L(wm)),this.properties.add(new L(xm)),this.properties.add(new L(ym)),this.properties.add(new f(vm)),this.properties.add(new L(Pm)),this.properties.add(new f(bm,!1)),this.properties.add(new O(Rm)),this.properties.add(new O(_m)),this.properties.add(new O(Tm)),this.properties.add(new O(Sm)),this.properties.add(new f(Lm,!0)),this.properties.add(new f(Cm)),this.properties.add(new O(Am)),this.properties.add(new O(Om)),this.properties.add(new O(Em)),this.properties.add(new H(Mm)),this.properties.add(new T(Vm)),this.properties.add(new f(Im)),this.properties.add(new f(Bm)),this.properties.add(new f(Hm)),this.properties.add(new f(Dm)),this.properties.add(new f(Wm)),this.properties.add(new f(km)),this.properties.add(new f(Nm)),this.properties.add(new f(Fm))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let{scale:e,min:i,max:r}=this,s=this.area;this.borderAlarmSensitive&&(s=W(s,2*e));let o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect({...s,color:o}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let n=this.alarmSensitiveForegroundColor,a=new at(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);a.scaleFormat=this.scaleFormat;let l=a.drawVertical(t,s.x,s.y,s.height,!0),h=0;this.showMarkers&&(h=this.drawMarkers(t,s,a)),this.drawTank(t,s,l,h,a)}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let p=t.measureText("LOLO",a);l=Math.max(l,p.width)}if(this.showLo&&s!==void 0){let p=t.measureText("LO",a);l=Math.max(l,p.width)}if(this.showHi&&o!==void 0){let p=t.measureText("HI",a);l=Math.max(l,p.width)}if(this.showHiHi&&n!==void 0){let p=t.measureText("HIHI",a);l=Math.max(l,p.width)}let h=e.x+e.width-l-this.markerGap-this.markerTickLength;if(this.showLoLo&&r!==void 0){let p=Math.round(i.getValuePosition(r));t.strokePath({path:new _(h,p).lineTo(h+this.markerTickLength,p),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:p,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let p=Math.round(i.getValuePosition(s));t.strokePath({path:new _(h,p).lineTo(h+this.markerTickLength,p),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:p,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let p=Math.round(i.getValuePosition(o));t.strokePath({path:new _(h,p).lineTo(h+this.markerTickLength,p),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:p,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let p=Math.round(i.getValuePosition(n));t.strokePath({path:new _(h,p).lineTo(h+this.markerTickLength,p),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerTickLength+this.markerGap,y:p,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}return this.markerTickLength+this.markerGap+l}drawTank(t,e,i,r,s){let o=this.alarmSensitiveForegroundColor,{scale:n,outlineWidth:a}=this,l=e.x+i,h=e.y+s.margin,p=e.width-i-r,d=e.height-2*s.margin,g=this.defaultCorner,x=11/20;p<2*g&&(x=12/20);let w=Math.floor(p*x);g>2*w-p-2*a&&(g=2*w-p);let v=s.getValuePosition(this.getFillValue()),S=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:h,width:p,height:d,rx:g/2,ry:g/2,color:m.WHITE});let C=t.createLinearGradient(l,h,l+w+2*n,h);C.addColorStop(0,this.colorFillbackground.toString()),C.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:h,width:w,height:d,rx:g/2,ry:g/2,gradient:C}),C=t.createLinearGradient(l+p-w-2*n,h,l+p,h),C.addColorStop(0,m.WHITE.withAlpha(0).toString()),C.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+p-w,y:h,width:w,height:d,rx:g/2,ry:g/2,gradient:C});let V=v,D=h+d-v;C=t.createLinearGradient(l,V,l+w+2*n,V),C.addColorStop(0,S.toString()),C.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:V,width:w,height:D,rx:g/2,ry:g/2,gradient:C}),C=t.createLinearGradient(l+p-w-2*n,V,l+p,V),C.addColorStop(0,m.WHITE.withAlpha(0).toString()),C.addColorStop(1,S.toString()),t.fillRect({x:l+p-w,y:V,width:w,height:D,rx:g/2,ry:g/2,gradient:C})}else t.fillRect({x:l,y:h,width:p,height:d,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:v,width:p,height:h+d-v,rx:g/2,ry:g/2,color:S});let A=W({x:l,y:h,width:p,height:d},a/2);t.strokeRect({...A,rx:g/2,ry:g/2,color:this.effect3d?rP:o,lineWidth:a})}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*15}get markerTickLength(){return this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get outlineWidth(){return this.scale*1}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}get colorLo(){return this.properties.getValue(wm)}get colorLoLo(){return this.properties.getValue(xm)}get colorHi(){return this.properties.getValue(mm)}get colorHiHi(){return this.properties.getValue(fm)}get colorFillbackground(){return this.properties.getValue(ym)}get fillColorAlarmSensitive(){return this.properties.getValue(bm)}get fillColor(){return this.properties.getValue(Pm)}get effect3d(){return this.properties.getValue(vm)}get levelLo(){return this.properties.getValue(Tm)}get levelLoLo(){return this.properties.getValue(Sm)}get levelHi(){return this.properties.getValue(Rm)}get levelHiHi(){return this.properties.getValue(_m)}get limitsFromPv(){return this.properties.getValue(Lm)}get logScale(){return this.properties.getValue(Cm)}get minimum(){return this.properties.getValue(Em)}get majorTickStepHint(){return this.scale*this.properties.getValue(Om)}get maximum(){return this.properties.getValue(Am)}get scaleFont(){return this.properties.getValue(Mm).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Vm)}get showLo(){return this.properties.getValue(Hm)}get showLoLo(){return this.properties.getValue(Dm)}get showHi(){return this.properties.getValue(Im)}get showHiHi(){return this.properties.getValue(Bm)}get showMarkers(){return this.properties.getValue(Wm)}get showMinorTicks(){return this.properties.getValue(km)}get showScale(){return this.properties.getValue(Nm)}get transparentBackground(){return this.properties.getValue(Fm)}};var Gm="auto_size",js="font",$m="format_type",Um="horizontal_alignment",Ym="precision",zm="precision_from_pv",Xm="rotation_angle",qm="show_lohi",Km="show_units",jm="vertical_alignment",Zm="wrap_words",jr=class extends M{areaRegion;tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new f(Gm)),this.properties.add(new H(js)),this.properties.add(new P($m)),this.properties.add(new P(Um)),this.properties.add(new P(Ym)),this.properties.add(new f(zm)),this.properties.add(new O(Xm)),this.properties.add(new f(qm,!0)),this.properties.add(new f(Km,!0)),this.properties.add(new P(jm)),this.properties.add(new f(Zm))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{let t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"},this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}drawHolder(t){if(this.autoSize){let e=this.properties.getValue(js).scale(1);this.customSize=t.measureText(this.computeDisplayText(),e,!0)}super.drawHolder(t)}computeDisplayText(){let t=this.text;if(this.value!==void 0){let e=this.precisionFromPV?this.pv?.precision??-1:this.precision;t=xe(this.value,this.formatType,e,this.pv?.typeHint)}return this.showUnits&&this.pv?.units&&(t+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?t+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(t+=" \u2191")),t}draw(t){let e=t.ctx;this.backgroundAlarmSensitive&&this.alarm?t.fillRect({...this.area,color:this.alarmSensitiveBackgroundColor}):this.transparent||t.fillRect({...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):this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let{scale:i}=this,r=this.area;this.borderAlarmSensitive&&(r=W(r,2*i,2*i));let s=this.computeDisplayText();this.wrapWords?this.drawWrapped(t,s,r):this.drawSingleLine(t,s,r)}drawSingleLine(t,e,i){let r=t.ctx,s=t.measureText(e,this.font,!0);if(r.font=this.font.getFontString(),this.rotationAngle){this.drawRotated(t,e,i,s);return}r.textBaseline="alphabetic";let n=r.measureText(e).fontBoundingBoxAscent,a={x:i.x,y:i.y,width:s.width,height:s.height};this.horizAlignment===0||(this.horizAlignment===1?a.x+=(i.width-s.width)/2:this.horizAlignment===2&&(a.x+=i.width-s.width)),this.vertAlignment===0||i.height<=s.height||(this.vertAlignment===1?a.y+=i.height/2-s.height/2:this.vertAlignment===2&&(a.y+=i.height-s.height)),r.textAlign="start",r.textBaseline="top",a.y+=a.height/2-n/2,r.save(),r.beginPath();let l=this.area;r.rect(l.x,l.y,l.width,l.height),r.clip(),r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.fillText(e,a.x,a.y),r.restore()}drawRotated(t,e,i,r){let s=t.ctx,o=yi(i,r,this.rotationAngle,this.horizAlignment,this.vertAlignment);s.save(),s.beginPath();let n=this.area;s.rect(n.x,n.y,n.width,n.height),s.clip(),s.translate(i.x+o.x,i.y+o.y),s.rotate(this.rotationAngle*Math.PI/180),s.textAlign="left",s.textBaseline="top",s.fillStyle=this.alarmSensitiveForegroundColor.toString(),s.fillText(e,0,0),s.restore()}drawWrapped(t,e,i){let r=t.ctx,s=this.wrapText(t,e,i.width);r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.font=this.font.getFontString(),r.textAlign="start",r.textBaseline="top";let o=t.measureText("Mg",this.font).height,n=s.length*o,a=i.y;i.height>n&&(this.vertAlignment===1?a+=(i.height-n)/2:this.vertAlignment===2&&(a+=i.height-n)),r.save(),r.beginPath();let l=this.area;r.rect(l.x,l.y,l.width,l.height),r.clip();for(let h of s){let p=i.x;if(this.horizAlignment===1){let d=r.measureText(h).width;p=i.x+(i.width-d)/2}else if(this.horizAlignment===2){let d=r.measureText(h).width;p=i.x+(i.width-d)}r.fillText(h,p,a),a+=o}r.restore()}wrapText(t,e,i){let r=[];for(let s of e.replace(/\n$/,"").split(`
22
+ `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[];for(;e.length;){let s;for(s=e.length;t.measureText(e.substr(0,s),this.font).width>i;s--);let o;if(s===e.length)o=e;else if(e[s]===" ")o=e.substr(0,s+1);else{let n=e.substr(0,s),a=0;for(;n.indexOf(" ",a)!==-1;a=n.indexOf(" ",a)+1);if(a)o=n.substr(0,a);else{let l=e.indexOf(" ");o=l===-1?e:e.substr(0,l)}}r.push(o),e=e.substr(o.length)}return r}get autoSize(){return this.properties.getValue(Gm)}get font(){return this.properties.getValue(js).scale(this.scale)}get formatType(){return this.properties.getValue($m)}get horizAlignment(){return this.properties.getValue(Um)}get precision(){return this.properties.getValue(Ym)}get precisionFromPV(){return this.properties.getValue(zm)}get rotationAngle(){return this.properties.getValue(Xm)}get showLohi(){return this.properties.getValue(qm)}get showUnits(){return this.properties.getValue(Km)}get vertAlignment(){return this.properties.getValue(jm)}get wrapWords(){return this.properties.getValue(Zm)}};var Jm="color_hi",Qm="color_hihi",tf="color_lo",ef="color_lolo",rf="color_fillbackground",sf="fill_color",of="fillcolor_alarm_sensitive",nf="font",af="effect_3d",lf="level_hi",hf="level_hihi",cf="level_lo",pf="level_lolo",df="limits_from_pv",uf="log_scale",gf="maximum",mf="major_tick_step_hint",ff="minimum",wf="scale_font",xf="scale_format",yf="show_bulb",Pf="show_hi",bf="show_hihi",vf="show_lo",Rf="show_lolo",_f="show_markers",Tf="show_minor_ticks",Sf="show_scale",Lf="transparent_background",Cf="unit",Af="value_label_format",Of=new m(160,160,160),Zr=class extends M{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new L(Jm)),this.properties.add(new L(Qm)),this.properties.add(new L(tf)),this.properties.add(new L(ef)),this.properties.add(new L(rf)),this.properties.add(new L(sf)),this.properties.add(new f(of,!1)),this.properties.add(new f(af)),this.properties.add(new O(lf)),this.properties.add(new O(hf)),this.properties.add(new O(cf)),this.properties.add(new O(pf)),this.properties.add(new f(df,!0)),this.properties.add(new H(nf)),this.properties.add(new f(uf)),this.properties.add(new O(gf)),this.properties.add(new O(mf)),this.properties.add(new O(ff)),this.properties.add(new H(wf)),this.properties.add(new T(xf)),this.properties.add(new f(yf)),this.properties.add(new f(Pf)),this.properties.add(new f(bf)),this.properties.add(new f(vf)),this.properties.add(new f(Rf)),this.properties.add(new f(_f)),this.properties.add(new f(Tf)),this.properties.add(new f(Sf)),this.properties.add(new f(Lf)),this.properties.add(new P(Cf)),this.properties.add(new T(Af))}init(){this.tooltipRegion={id:`${this.wuid}-tooltip`,tooltip:()=>this.tooltip}}draw(t){let{scale:e,min:i,max:r}=this,s=this.area;this.borderAlarmSensitive&&(s=W(this.area,2*this.scale));let o=this.alarmSensitiveBackgroundColor,n=this.alarmSensitiveForegroundColor,a=this.alarmSensitiveFillColor;this.transparentBackground||t.fillRect({...s,color:o}),this.tooltip&&t.addHitRegion(this.tooltipRegion).addRect(this.x,this.y,this.width,this.height);let l=s.height;if(this.showBulb){let A=Math.min(s.width/2,this.bulbMaxDiameter);l=s.height<A?0:s.height-A}let h={...s,height:l},p=new at(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);p.scaleFormat=this.scaleFormat;let d=0,g="";if(this.unit===0?g="\xB0C":this.unit===1?g="\xB0F":this.unit===2&&(g="K"),g){let A=X.ARIAL_9.scale(e),C=t.measureText(g,A),V=2*e;d=C.height+2*V,t.fillText({x:s.x+s.width/2-this.pipeWidth/2-V,y:s.y+V,baseline:"top",align:"right",color:n,font:A,text:g})}let x=h.x+h.width/2-this.pipeWidth/2-1*e,w={...h,y:h.y+d,height:h.height-d+p.calculateMargin(t,!1)},v=p.drawVertical(t,x,w.y,w.height,!1),S=Math.floor(this.pipeWidth/2);if(h={...h,y:p.getValuePosition(r)-S,height:p.scaleLength+2*S},this.drawPipe(t,h,p),this.showMarkers&&this.drawMarkers(t,s,p),this.showBulb){let A=Math.min(s.width/2,this.bulbMaxDiameter),C=1*e,V=s.x+s.width/2,D=s.y+l+A/2,N=A/2,$=A/2;if(t.fillEllipse({cx:V,cy:D,rx:N,ry:$,color:a}),this.effect3d){let dt=t.createLinearGradient(V-N,D-$,V+N,D+$);dt.addColorStop(0,m.WHITE.toString()),dt.addColorStop(1,a.withAlpha(0).toString()),t.fillEllipse({cx:V,cy:D,rx:N,ry:$,gradient:dt})}t.strokeEllipse({cx:V,cy:D,rx:N-C/2,ry:$-C/2,color:this.effect3d?Of:n,lineWidth:C});let z={x:Math.round(h.x+h.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(p.getValuePosition(i)),width:this.pipeWidth-2*this.outlineWidth,height:e*3};if(this.effect3d){let dt=Math.round(h.x+h.width/2-this.pipeWidth/2),At=dt+this.pipeWidth,mt=t.createLinearGradient(dt,z.y,At,z.y);mt.addColorStop(0,m.WHITE.toString()),mt.addColorStop(1,a.toString()),t.fillRect({...z,gradient:mt})}else t.fillRect({...z,color:a});let lt=this.value;lt!==void 0&&t.fillText({x:V,y:D,align:"center",baseline:"middle",color:a.contrast(),font:this.font,text:this.format(lt)})}}drawPipe(t,e,i){let{scale:r,outlineWidth:s,min:o,max:n}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,h={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},p=this.getFillValue(),d=i.getValuePosition(p);n>o?p>n?d-=10*r:p<o&&(d+=10*r):p>o?d+=10*r:p<n&&(d-=10*r);let g=this.pipeWidth/2,{x,y:w,width:v,height:S}=h;if(this.effect3d){let C=t.createLinearGradient(x,w,x+v,w);C.addColorStop(0,m.WHITE.toString()),C.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({...h,rx:g/2,ry:g/2,gradient:C}),C=t.createLinearGradient(x,w,x+v,w),C.addColorStop(0,m.WHITE.toString()),C.addColorStop(1,l.toString()),t.fillRect({x,y:d,width:v,height:w+S-d,rx:g/2,ry:g/2,gradient:C})}else t.fillRect({...h,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x,y:d,width:v,height:w+S-d,rx:g/2,ry:g/2,color:l});let A=W(h,s/2);t.strokeRect({...A,rx:g/2,ry:g/2,color:this.effect3d?Of:a,lineWidth:s})}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=X.ARIAL_9.scale(this.scale),l=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&r!==void 0){let h=Math.round(i.getValuePosition(r));t.strokePath({path:new _(l,h).lineTo(l+this.markerTickLength,h),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=Math.round(i.getValuePosition(s));t.strokePath({path:new _(l,h).lineTo(l+this.markerTickLength,h),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=Math.round(i.getValuePosition(o));t.strokePath({path:new _(l,h).lineTo(l+this.markerTickLength,h),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=Math.round(i.getValuePosition(n));t.strokePath({path:new _(l,h).lineTo(l+this.markerTickLength,h),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:h,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:a})}}get min(){return this.limitsFromPv?this.pv?.lowerDisplayLimit??this.minimum:this.minimum}get max(){return this.limitsFromPv?this.pv?.upperDisplayLimit??this.maximum: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 this.scale*15}get bulbMaxDiameter(){return this.scale*40}get outlineWidth(){return this.scale*1}get markerTickLength(){return this.scale*10}get markerTickLineWidth(){return this.scale*2}get markerGap(){return this.scale*3}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return this.display.majorColor;if(this.isMinorSeverity())return this.display.minorColor}return this.fillColor}getFillValue(){let t=this.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(tf)}get colorLoLo(){return this.properties.getValue(ef)}get colorHi(){return this.properties.getValue(Jm)}get colorHiHi(){return this.properties.getValue(Qm)}get colorFillbackground(){return this.properties.getValue(rf)}get fillColorAlarmSensitive(){return this.properties.getValue(of)}get fillColor(){return this.properties.getValue(sf)}get font(){return this.properties.getValue(nf).scale(this.scale)}get effect3d(){return this.properties.getValue(af)}get levelLo(){return this.properties.getValue(cf)}get levelLoLo(){return this.properties.getValue(pf)}get levelHi(){return this.properties.getValue(lf)}get levelHiHi(){return this.properties.getValue(hf)}get limitsFromPv(){return this.properties.getValue(df)}get logScale(){return this.properties.getValue(uf)}get minimum(){return this.properties.getValue(ff)}get majorTickStepHint(){return this.scale*this.properties.getValue(mf)}get maximum(){return this.properties.getValue(gf)}get scaleFont(){return this.properties.getValue(wf).scale(this.scale)}get scaleFormat(){return this.properties.getValue(xf)}get showBulb(){return this.properties.getValue(yf)}get showMarkers(){return this.properties.getValue(_f)}get showMinorTicks(){return this.properties.getValue(Tf)}get showLo(){return this.properties.getValue(vf)}get showLoLo(){return this.properties.getValue(Rf)}get showHi(){return this.properties.getValue(Pf)}get showHiHi(){return this.properties.getValue(bf)}get showScale(){return this.properties.getValue(Sf)}get transparentBackground(){return this.properties.getValue(Lf)}get unit(){return this.properties.getValue(Cf)}get valueLabelFormat(){return this.properties.getValue(Af)}};var Ef=-323.3062,Mf=308.2547,Jr=class{constructor(t,e){this.widget=t;this.index=e}linearScale;_effectiveMinimum;_effectiveMaximum;get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return this.timeFormat!==0}isHorizontal(){return this.index===0||this.index!==1&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){return this._effectiveMinimum??this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){return this._effectiveMaximum??this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){let t={start:this.minimum,stop:this.maximum},e=this.widget.calculateAutoscaledRange(this,t);e&&(this.effectiveMinimum=e.start,this.effectiveMaximum=e.stop,this.widget.requestRepaint())}applyZoom(t,e){let i=this.effectiveMinimum,r=this.effectiveMaximum,s,o;if(this.logScale){r=Math.log10(r),i=Math.log10(i);let n=Math.log10(t)*e,a=1-e;s=n+i*a,o=n+r*a,s<Ef&&(s=Ef),s=Math.pow(10,s),o>Mf&&(o=Mf),o=Math.pow(10,o)}else{let n=Math.max(Math.abs(i),Math.abs(r));i/=n,r/=n;let a=t/n*e,l=1-e;s=(a+i*l)*n,o=(a+r*l)*n}this.effectiveMinimum=s,this.effectiveMaximum=o,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleThreshold(){return this.getValue("auto_scale_threshold")}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.index<2||this.getValue("left_bottom_side")!==!1}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")}};var Ct=class{constructor(t,e){this.xAxis=t;this.yAxis=e;for(let i of t)this.beforeXRanges.push({min:i.effectiveMinimum,max:i.effectiveMaximum});for(let i of e)this.beforeYRanges.push({min:i.effectiveMinimum,max:i.effectiveMaximum})}beforeXRanges=[];beforeYRanges=[];afterXRanges=[];afterYRanges=[];saveState(){for(let t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(let t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){let 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++){let 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++){let 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++){let e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}},Qr=class{undoStack=[];redoStack=[];canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){let t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){let t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}};var ts=class{constructor(t,e){this.widget=e;this.id=t}id;cursor;selection;grabStart;prevGrabEvent;grabZoomCommand;tooltip(){return this.widget.tooltip}mouseDown(t){let{widget:e}=this;switch(e.toolbar?.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new Ct(e.getXAxes(),e.getYAxes());break}}grab(t){switch(this.widget.toolbar?.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection={...this.grabStart.point,width:t.dx,height:t.dy},this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint();break}}grabEnd(){let{grabZoomCommand:t,selection:e,widget:i}=this;switch(i.toolbar?.currentTool){case"rubberband-zoom":if(e){let r=new Ct(i.getXAxes(),i.getYAxes());this.rangeZoomXAxes(e),this.rangeZoomYAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"horizontal-zoom":if(e){let r=new Ct(i.getXAxes(),i.getYAxes());this.rangeZoomXAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"vertical-zoom":if(e){let r=new Ct(i.getXAxes(),i.getYAxes());this.rangeZoomYAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"panning":t&&(t.saveState(),i.toolbar.addCommand(t));break}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){let{widget:e}=this;switch(e.toolbar?.currentTool){case"zoom-in":let i=new Ct(e.getXAxes(),e.getYAxes());for(let s of e.getAxes()){let o=s.isHorizontal()?t.point.x:t.point.y,n=s.linearScale.getPositionValue(o);s.applyZoom(n,.1)}i.saveState(),e.toolbar.addCommand(i);break;case"zoom-out":let r=new Ct(e.getXAxes(),e.getYAxes());for(let s of e.getAxes()){let o=s.isHorizontal()?t.point.x:t.point.y,n=s.linearScale.getPositionValue(o);s.applyZoom(n,-.1)}r.saveState(),e.toolbar.addCommand(r);break}}rangeZoomXAxes(t){for(let e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),r=e.linearScale.getPositionValue(t.x+t.width);if(i>r){let o=i;i=r,r=o}let s=e.linearScale.getMinMax();i=Math.max(s.start,i),r=Math.min(s.stop,r),e.effectiveMinimum=i,e.effectiveMaximum=r}}rangeZoomYAxes(t){for(let e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),r=e.linearScale.getPositionValue(t.y+t.height);if(i>r){let o=i;i=r,r=o}let s=e.linearScale.getMinMax();i=Math.max(s.start,i),r=Math.min(s.stop,r),e.effectiveMinimum=i,e.effectiveMaximum=r}}pan(t){let{prevGrabEvent:e,widget:i}=this;if(e){let r=e.dx-t.dx;if(r!==0)for(let o of i.getXAxes()){let n=o.linearScale,a=n.getMinMax(),l=n.getValuePosition(a.start)+r,h=n.getValuePosition(a.stop)+r;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(h)}let s=e.dy-t.dy;if(s!==0)for(let o of i.getYAxes()){let n=o.linearScale,a=n.getMinMax(),l=n.getValuePosition(a.start)+s,h=n.getValuePosition(a.stop)+s;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(h)}}}};var Zs=class{pointer=0;samples=[];constructor(t){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(){let t=(this.pointer+1)%this.samples.length;return this.samples[t]!==void 0}isEmpty(){return this.tail()===void 0}tail(){return this.pointer===0?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t)return this.samples.filter(i=>i!==void 0).sort((i,r)=>i.x-r.x);{let e=this.samples.slice(this.pointer).filter(r=>r!==void 0),i=this.samples.slice(0,this.pointer).filter(r=>r!==void 0);return e.concat(i)}}},es=class{constructor(t,e,i,r,s,o){this.bufferSize=t;this.plotMode=e;this.updateMode=i;this.concatenateData=r;this.chronological=s;this.historicalDataProvider=o;this.traceData=new Zs(t)}traceData;x=0;xPending=!1;y=0;yTimestamp=0;yPending=!1;xArray=[];xArrayPending=!1;yArray=[];yArrayPending=!1;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.historicalDataProvider?this.historicalDataProvider.getSamples():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(this.plotMode===1&&this.traceData.isFull())return;let{xPending:t,yPending:e,chronological:i,updateMode:r}=this;r===0?(i&&e||!i&&(t||e))&&this.addPoint():r===1?(i&&e||!i&&t&&e)&&this.addPoint():r===2?(i&&e||!i&&t)&&this.addPoint():r===3&&this.yPending&&this.addPoint()}maybeAddArray(){if(this.plotMode===1&&this.traceData.isFull())return;let{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:r}=this;r===0?(i&&e||!i&&(t||e))&&this.addArray():r===1?(i&&e||!i&&t&&e)&&this.addArray():r===2?(i&&e||!i&&t)&&this.addArray():r===3&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(this.updateMode===5)t=new Date().getTime();else if(this.yTimestamp!==void 0)t=this.yTimestamp;else{let 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 s=0;s<e.length;s++)t[s]=s;else{let s=this.traceData.tail();for(let o=1;o<e.length;o++)t[o-1]=s.x+o}let i=Math.min(t.length,e.length),r=Math.min(i,this.bufferSize);for(let s=0;s<r;s++)this.traceData.push(t[s],e[s]);this.xArrayPending=!1,this.yArrayPending=!1}};var is=class{constructor(t,e){this.widget=t;this.i=e}traceData;historicalDataProvider;xPVInstance;yPVInstance;xPVListener=()=>{let t=this.xPVInstance;if(t)if(Array.isArray(t.value))this.traceData?.updateXArray(t.value);else{let e=t.toNumber();e!=null&&this.traceData?.updateX(e)}};yPVListener=()=>{let t=this.yPVInstance;if(t)if(Array.isArray(t.value))this.traceData?.updateYArray(t.value);else{let e=this.widget.getAxis(this.xAxisIndex),i=t.toNumber();if(i!=null)if(e.isDateEnabled()){let r=(t.time||new Date).getTime();this.traceData?.updateY(i,r)}else this.traceData?.updateY(i)}};init(){let{bufferSize:t,plotMode:e,updateMode:i,concatenateData:r,widget:s}=this,o=!this.xPV,{pvEngine:n}=s.display,a=s.getAxis(this.xAxisIndex)?.isDateEnabled();this.historicalDataProvider=void 0,o&&a&&this.yPV&&(this.historicalDataProvider=n.createHistoricalDataProvider(this.yPV,s)||void 0),this.traceData=new es(t,e,i,r,o,this.historicalDataProvider),this.xPV&&(this.xPVInstance=n.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=n.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),s.addPropertyListener(`trace_${this.i}_x_pv`,()=>{let l=n.createPV(this.xPV);l!==this.xPVInstance&&(this.xPVInstance?.removeListener(this.xPVListener),this.xPVInstance=l,this.xPVInstance.addListener(this.xPVListener))}),s.addPropertyListener(`trace_${this.i}_y_pv`,()=>{let l=n.createPV(this.yPV);l!==this.yPVInstance&&(this.yPVInstance?.removeListener(this.yPVListener),this.yPVInstance=l,this.yPVInstance.addListener(this.yPVListener))})}snapshot(){return this.traceData?.snapshot()||[]}drawTrace(t,e){let{lineWidth:i}=this;if(this.traceType===0)t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i});else if(this.traceType===1)t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(this.traceType!==2){if(this.traceType===3){let s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let o of e)o.y!==null&&t.strokePath({path:new _(o.x,o.y).lineTo(o.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(this.traceType===4||this.traceType===5){let s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let o=1;o<e.length;o++){let n=e[o-1],a=e[o];n.y!==null&&a.y!==null&&t.fillPath({path:new _(n.x,n.y).lineTo(n.x,s).lineTo(a.x,s).lineTo(a.x,a.y),color:this.traceColor,opacity:100/255})}this.traceType===5&&t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(this.traceType===6)for(let r=1;r<e.length;r++){let s=e[r-1],o=e[r];s.y!==null&&o.y!==null&&t.strokePath({path:new _(s.x,s.y).lineTo(s.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(this.traceType===7)for(let r=1;r<e.length;r++){let s=e[r-1],o=e[r];s.y!==null&&o.y!==null&&t.strokePath({path:new _(s.x,s.y).lineTo(o.x,s.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(this.traceType===8){let{scale:r}=this;t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*r,2*r,2*r,2*r]})}else if(this.traceType===9){let{scale:r}=this;t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*r,2*r,2*r,2*r,2*r,2*r]})}else if(this.traceType===10){let{scale:r}=this;t.strokePath({path:_.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*r,2*r]})}}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;let i=this.pointSize/2,r=e.x,s=e.y;switch(this.pointStyle){case 1:t.ctx.beginPath(),t.ctx.ellipse(r,s,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(r,s,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 3:t.ctx.beginPath(),t.ctx.ellipse(r,s,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(r-i,s+i),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(r-i,s+i),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(r-i,s-i,2*i,2*i);break;case 7:t.ctx.fillRect(r-i,s-i,2*i,2*i);break;case 8:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s),t.ctx.lineTo(r,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 9:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r,s-i),t.ctx.lineTo(r+i,s),t.ctx.lineTo(r,s+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(r-i,s-i),t.ctx.lineTo(r+i,s+i),t.ctx.moveTo(r+i,s-i),t.ctx.lineTo(r-i,s+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(r-i,s),t.ctx.lineTo(r+i,s),t.ctx.moveTo(r,s-i),t.ctx.lineTo(r,s+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(r,s-i),t.ctx.lineTo(r,s+i),t.ctx.stroke()}}clearData(){this.traceData?.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")}destroy(){this.historicalDataProvider?.disconnect()}};var sP=new m(236,236,236),oP=new m(130,130,130),Js=class{constructor(t,e,i,r,s){this.imageFile=e;this.disabledImageFile=i;this.action=s;this.loadPromise=new Promise((o,n)=>{this.imageElement.onload=()=>o()}),this.disabledLoadPromise=new Promise((o,n)=>{this.disabledImageElement.onload=()=>o()}),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:()=>r}}imageElement=new Image;disabledImageElement=new Image;loadPromise;disabledLoadPromise;toggleButton=!1;toolButton=!1;pushed=!1;disabled=!1;region;loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}},rs=class{constructor(t){this.xyGraph=t;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",i=>{this.showLegend.pushed=i}),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",()=>{let i=new Ct(t.getXAxes(),t.getYAxes());t.performAutoScale(),i.saveState(),this.addCommand(i)}),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",()=>{let i=document.createElement("a");try{i.href=t.toDataURL(),i.download=`${t.name}_export.png`,document.body.appendChild(i),i.click()}finally{document.body.removeChild(i)}}),this.toggleTool(this.mouseArrow);let e=this.buttons.map(i=>i.loadPromise).concat(this.buttons.map(i=>i.disabledLoadPromise));Promise.all(e).finally(()=>{this.imagesLoaded=!0,t.requestRepaint()});for(let i of this.buttons)i.loadImage(t.display.imagesPrefix)}buttons=[];showLegend;autoScale;rubberbandZoom;horizontalZoom;verticalZoom;zoomIn;zoomOut;panning;mouseArrow;undo;redo;camera;imagesLoaded=!1;currentTool="default";commandBuffer=new Qr;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){let e=t.pushed;for(let i of this.buttons)i.toolButton&&(i.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){let r=this.createToggleButton(t,e,i);return r.toolButton=!0,r}createToggleButton(t,e,i){let r=this.createButton(t,t,e,i);return r.toggleButton=!0,r}createButton(t,e,i,r){let s=new Js(this,t,e,i,r);return this.buttons.push(s),s}draw(t,e){let{buttonSize:i}=this,r={x:e.x,y:e.y};return this.drawButton(t,r.x,r.y,this.showLegend),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.autoScale),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.rubberbandZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.horizontalZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.verticalZoom),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.zoomIn),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.zoomOut),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.panning),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.mouseArrow),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.undo),r.x+=i,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.redo),r.x+=i,this.maybeWrap(r,e,i/2),this.drawSeparator(t,r.x,r.y),r.x+=i/2,this.maybeWrap(r,e),this.drawButton(t,r.x,r.y,this.camera),r.x+=i,r.y+i-e.y}maybeWrap(t,e,i){i=i??this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){let{buttonSize:r}=this,s=1*this.scale,o=Math.round(e+r/4)-s/2;t.strokePath({path:new _(o,i).lineTo(o,i+r),color:oP,lineWidth:s})}drawButton(t,e,i,r){let{buttonSize:s,scale:o}=this;t.fillRect({x:e,y:i,width:s,height:s,color:sP}),this.xyGraph.enabled&&!r.disabled&&t.addHitRegion(r.region).addRect(e,i,s,s);let n=1*o,a=Math.round(i+n/2)-.5,l=Math.round(e+n/2)-.5,h=Math.round(i+s-n+n/2)-.5,p=Math.round(e+s-n+n/2)-.5;if(t.strokePath({color:r.pushed?m.WHITE:m.BLACK,path:new _(p,h).lineTo(p,a).moveTo(p,h).lineTo(l,h),lineWidth:n}),t.strokePath({color:r.pushed?m.BLACK:m.WHITE,path:new _(l,a).lineTo(p-n,a).moveTo(l,a).lineTo(l,h-n),lineWidth:n}),this.imagesLoaded){let d=r.disabled?r.disabledImageElement:r.imageElement,g=d.naturalHeight*o,x=d.naturalWidth*o,w=Math.round(e+(s-x)/2),v=Math.round(i+(s-g)/2);t.ctx.drawImage(d,w,v,x,g)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}};var Qs="axis_count",Vf="plot_area_background_color",If="show_legend",Bf="show_plot_area_border",Hf="show_toolbar",Df="title",Wf="title_font",to="trace_count",kf="transparent",ss=class extends M{toolbar;plotAreaRegion;axes=[];traces=[];autoScaleAllowed=!0;constructor(t,e){super(t,e),this.properties.add(new P(Qs)),this.properties.add(new L(Vf)),this.properties.add(new f(If)),this.properties.add(new f(Bf)),this.properties.add(new f(Hf)),this.properties.add(new T(Df)),this.properties.add(new H(Wf)),this.properties.add(new P(to)),this.properties.add(new f(kf)),this.properties.addGenerator(()=>{let i=[];this.axes=[];let r=this.properties.getValue(Qs);for(let o=0;o<r;o++)this.axes.push(new Jr(this,o)),i.push(new f(`axis_${o}_auto_scale`),new O(`axis_${o}_auto_scale_threshold`),new L(`axis_${o}_axis_color`),new T(`axis_${o}_axis_title`),new f(`axis_${o}_dash_grid_line`),new L(`axis_${o}_grid_color`),new f(`axis_${o}_log_scale`),new O(`axis_${o}_maximum`),new O(`axis_${o}_minimum`),new H(`axis_${o}_scale_font`),new T(`axis_${o}_scale_format`),new f(`axis_${o}_show_grid`),new P(`axis_${o}_time_format`),new H(`axis_${o}_title_font`),new f(`axis_${o}_visible`)),o>1&&i.push(new f(`axis_${o}_left_bottom_side`),new f(`axis_${o}_y_axis`));this.traces=[];let s=this.properties.getValue(to);for(let o=0;o<s;o++)this.traces.push(new is(this,o)),i.push(new f(`trace_${o}_anti_alias`),new P(`trace_${o}_buffer_size`),new f(`trace_${o}_concatenate_data`),new P(`trace_${o}_line_width`),new T(`trace_${o}_name`),new P(`trace_${o}_plot_mode`),new P(`trace_${o}_point_size`),new P(`trace_${o}_point_style`),new L(`trace_${o}_trace_color`),new P(`trace_${o}_trace_type`),new P(`trace_${o}_update_delay`),new P(`trace_${o}_update_mode`),new f(`trace_${o}_visible`),new P(`trace_${o}_x_axis_index`),new T(`trace_${o}_x_pv`),new Wt(`trace_${o}_x_pv_value`,`trace_${o}_x_pv`),new P(`trace_${o}_y_axis_index`),new T(`trace_${o}_y_pv`),new Wt(`trace_${o}_y_pv_value`,`trace_${o}_y_pv`));return i})}init(){this.plotAreaRegion=new ts(`${this.wuid}-plotarea`,this),this.traces.forEach(t=>t.init())}draw(t){let{scale:e}=this,i=this.area;if(this.borderAlarmSensitive&&(i=W(this.area,2*e)),!this.transparent){let o=this.alarmSensitiveBackgroundColor;t.fillRect({...i,color:o})}this.showToolbar&&this.drawToolbar(t,i),this.title&&this.drawTitle(t,i);for(let o of this.axes){if(o.autoScale&&this.autoScaleAllowed){let l={start:o.minimum,stop:o.maximum},h=this.calculateAutoscaledRange(o,l);h&&(o.effectiveMinimum=h.start,o.effectiveMaximum=h.stop)}let n=o.effectiveMinimum,a=o.effectiveMaximum;o.linearScale=new at(this.display.formatter,e,o.scaleFont,n,a,o.logScale,50*e,o.axisColor,!0,o.visible),o.linearScale.scaleFormat=o.scaleFormat,o.linearScale.timeFormat=o.timeFormat,o.linearScale.snapToPixels=o.isHorizontal()&&o.isDateEnabled(),o.linearScale.pixelRatio=t.pixelRatio}this.showLegend&&this.drawLegend(t,i),t.addHitRegion(this.plotAreaRegion).addRect(i.x,i.y,i.width,i.height);let r=this.drawAxes(t,i);this.drawPlotArea(t,r);let s=this.plotAreaRegion?.selection;s&&this.drawZoomSelection(t,r,fi(r,s))}drawToolbar(t,e){this.toolbar||(this.toolbar=new rs(this));let i=3*this.scale,r=W(e,i),s=this.toolbar.draw(t,r);e.y+=i+s+i,e.height-=i+s+i}drawTitle(t,e){let 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});let r=2*this.scale;e.y+=i+r,e.height-=i+r}drawAxes(t,e){let{scale:i}=this,r=5*i,s={...e},o=0,n=0;for(let w of this.getXAxes())if(w.visible){let v=0;w.axisTitle&&(v=r+t.measureText(w.axisTitle,w.titleFont).height),o+=v,n+=v+w.linearScale.measureHorizontalHeight(t)}let a=0,l=0,h=this.getYAxes(),p=h.filter(w=>w.leftBottomSide),d=h.filter(w=>!w.leftBottomSide),g=0;for(let w of d.reverse()){let v=w.linearScale;if(w.visible){let S=v.calculateMargin(t,!1),A=s.height-n+(n>0?S:0),C=s.x+s.width,V=0;w.axisTitle&&(V=t.measureText(w.axisTitle,w.titleFont).height,t.ctx.save(),t.ctx.translate(C-r-V/2,e.y+A/2),t.ctx.rotate(Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:w.titleFont,color:w.axisColor,text:w.axisTitle}),t.ctx.restore(),V+=r);let D=V+v.drawVertical(t,C-V,e.y,A,!1,!0);s.width-=D,g+=D;let N=v.margin;l=l===0?N:Math.min(l,N);let $=i*1,z=Math.round(s.x+s.width)+$/2,lt=Math.round(e.y+S)-$/2;t.strokePath({path:new _(z,lt).lineTo(z,lt+A-2*S),color:w.axisColor,opacity:100/255,lineWidth:$})}else{let S=s.height-n;v.setDimensions(0,e.y,S,!1)}}for(let w of p.reverse()){let v=w.linearScale;if(w.visible){let S=v.calculateMargin(t,!1),A=s.height-n+(n>0?S:0),C=0;w.axisTitle&&(C=t.measureText(w.axisTitle,w.titleFont).height,t.ctx.save(),t.ctx.translate(s.x+r+C/2,e.y+A/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:w.titleFont,color:w.axisColor,text:w.axisTitle}),t.ctx.restore(),C+=r);let V=C+v.drawVertical(t,s.x+C,e.y,A,!0,!1);s.x+=V,s.width-=V,a+=V;let D=v.margin;l=l===0?D:Math.min(l,D);let N=i*1,$=Math.round(s.x)-N/2,z=Math.round(e.y+S)-N/2;t.strokePath({path:new _($,z).lineTo($,z+A-2*S),color:w.axisColor,opacity:100/255,lineWidth:N})}else{let S=s.height-n;v.setDimensions(0,e.y,S,!1)}}let x=0;for(let w of this.getXAxes().reverse()){let v=w.linearScale;if(w.visible){let S=v.calculateMargin(t,!0),A=a-S,C=0;if(w.axisTitle){C=t.measureText(w.axisTitle,w.titleFont).height;let lt=e.x+a+(e.width-a-g)/2;t.fillText({x:lt,y:s.y+s.height-C/2,align:"center",baseline:"middle",font:w.titleFont,color:w.axisColor,text:w.axisTitle}),C+=r}let V=C+v.drawHorizontal(t,e.x+A,s.y+s.height-C,e.width-A-g+(g>0?S:0));s.height-=V;let D=v.margin;x=x===0?D:Math.min(x,D);let N=i*1,$=Math.round(e.x+A+S)-N/2,z=Math.round(s.y+s.height)-N/2;t.strokePath({path:new _($,z).lineTo($+s.width-(g>0?0:S),z),color:w.axisColor,opacity:100/255,lineWidth:N})}else{let S=e.x+a,A=e.width-a-g;v.setDimensions(S,0,A,!0)}}return s.y+=l,g===0&&(s.width-=x),n>0?s.height-=l:s.height-=2*l,s}drawPlotArea(t,e){let{scale:i}=this,r=1*i;if(this.transparent||t.fillRect({...e,color:this.plotAreaBackgroundColor}),this.showPlotAreaBorder){let{x:s,y:o,width:n,height:a}=W(e,r/2);t.strokePath({path:new _(s,o).lineTo(s+n,o).lineTo(s+n,o+a),color:m.BLACK,lineWidth:r})}for(let s of this.axes.filter(o=>o.visible&&o.showGrid)){let o=s.linearScale;if(s.isHorizontal())for(let n of o.getGridPositions()){let a=Math.round(o.getX()+n)-r/2;t.strokePath({path:new _(a,e.y).lineTo(a,e.y+e.height),color:s.gridColor,lineWidth:r,dash:s.dashGridLine?[6*i,2*i]:void 0})}else for(let n of o.getGridPositions()){let a=Math.round(o.getY()+n)-r/2;t.strokePath({path:new _(e.x,a).lineTo(e.x+e.width,a),color:s.gridColor,lineWidth:r,dash:s.dashGridLine?[6*i,2*i]:void 0})}}t.ctx.save(),t.ctx.beginPath(),t.ctx.rect(e.x,e.y,e.width,e.height),t.ctx.clip();for(let s of this.traces.filter(o=>o.visible)){let o=this.getAxis(s.xAxisIndex).linearScale,n=this.getAxis(s.yAxisIndex).linearScale,a=[];for(let l of s.snapshot()){let h=o.getValuePosition(l.x),p=l.y!==null?n.getValuePosition(l.y):null;a.push({x:h,y:p})}if(a.length){s.drawTrace(t,a);for(let l of a)l.y!==null&&s.drawPoint(t,l)}}t.ctx.restore()}drawZoomSelection(t,e,i){let{scale:r}=this;switch(this.toolbar?.currentTool){case"rubberband-zoom":t.strokeRect({...i,color:m.BLACK,lineWidth:1*r});break;case"horizontal-zoom":let s=i;s.y=e.y,s.height=e.height,t.strokeRect({...Ls(s),color:m.BLACK,lineWidth:1*r});break;case"vertical-zoom":let o=i;o.x=e.x,o.width=e.width,t.strokeRect({...Ls(o),color:m.BLACK,lineWidth:1*r});break}}drawLegend(t,e){let{scale:i}=this,r=25*i,s=2*i,o=5*i,n=X.ARIAL_10.scale(i);for(let a of this.getYAxes()){let l=this.traces.filter(A=>A.visible&&A.yAxisIndex===a.index),h=[],p=[],d=0,g=0;for(let A of l){let C=r+s+o;A.name&&(C+=t.measureText(A.name,n).width),d+C<e.width?(p.push(A),d+=C):(h.push(p),C=Math.max(C,d),p=[A],d=C)}if(p.length&&(h.push(p),g=Math.max(g,d)),!h.length)continue;let x=r*h.length,w={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-x),width:g,height:x};e.height-=w.height,this.transparent||t.fillRect({...w,color:this.plotAreaBackgroundColor}),t.strokeRect({...W(w,1*i/2),color:a.axisColor});let v=w.x,S=w.y;for(let A=0;A<h.length;A++){let C=h[A],V=S+A*r,D=V+r/2;for(let N of C){let $=N.pointSize>Math.floor((r-o)/2)?Math.floor(r-o):N.pointSize;switch(N.traceType){case 3:let z=v+r/2;t.strokePath({path:new _(z,V+$).lineTo(z,V+r),lineWidth:N.lineWidth,color:N.traceColor,opacity:100/255}),N.drawPoint(t,{x:z,y:V+$});break;case 4:case 5:let lt=[{x:v,y:V+r/2},{x:v+r/2,y:V+$},{x:v+r,y:V+r/2},{x:v+r,y:V+r},{x:v,y:V+r}];t.fillPath({path:_.fromPoints(lt),color:N.traceColor,opacity:100/255}),N.traceType===5&&t.strokePath({path:_.fromPoints(lt.slice(0,3)),color:N.traceColor,lineWidth:1*i}),N.drawPoint(t,{x:v+r/2,y:V+$});break;default:N.drawTrace(t,[{x:v,y:D},{x:v+r,y:D}]),N.drawPoint(t,{x:v+r/2,y:D})}v+=r+s,N.name&&(t.fillText({x:v,y:D,align:"left",baseline:"middle",color:N.traceColor,font:n,text:N.name}),v+=t.measureText(N.name,n).width),v+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t,e){let i,r,s=t.logScale;for(let o of this.traces)if(o.visible&&!(this.axes[o.xAxisIndex]!==t&&this.axes[o.yAxisIndex]!==t))for(let n of o.snapshot()){let a=t.isHorizontal()?n.x:n.y;a!==null&&((i===void 0||i>a)&&(!s||a>0)&&(i=a),(r===void 0||r<a)&&(!s||a>0)&&(r=a))}if(i!==void 0&&r!==void 0)return i===r?{start:Math.min(i,e.start),stop:Math.max(r,e.stop)}:{start:i,stop:r}}performAutoScale(){for(let t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(let 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(Qs)}get plotAreaBackgroundColor(){return this.properties.getValue(Vf)}get showLegend(){return this.properties.getValue(If)}get showPlotAreaBorder(){return this.properties.getValue(Bf)}get showToolbar(){return this.properties.getValue(Hf)}get title(){return this.properties.getValue(Df)}get titleFont(){return this.properties.getValue(Wf).scale(this.scale)}get traceCount(){return this.properties.getValue(to)}get transparent(){return this.properties.getValue(kf)}destroy(){for(let t of this.traces)t.destroy()}};var Nf="array_length",Ff="spinner_width",Gf="horizontal",$f="show_spinner",Uf="show_scrollbar",Yf="vec",zf="data_type",nP="scale_options",Xf=1,qf=25,aP=16,Kf=16,lP=new m(64,64,64),hP=250,cP=40,pP=150,dP=new m(243,243,243),os=class extends st{templateNode;templateWidgetType="";elementWidth=0;elementHeight=0;originalEnabled=new WeakMap;scrollIndex=0;fullValue=[];redistributing=!1;spinnerUpRegion;spinnerUpPressed=!1;spinnerDownRegion;spinnerDownPressed=!1;spinnerRepeatTimeout;spinnerLabelRegion;spinnerLabelBounds;editingIndex=!1;indexInputEl;scrollDecreaseRegion;scrollDecreasePressed=!1;scrollIncreaseRegion;scrollIncreasePressed=!1;scrollPageDecreaseRegion;scrollPageIncreaseRegion;scrollThumbRegion;scrollGrabStartIndex=0;scrollDragRange=0;scrollRepeatTimeout;constructor(t,e){super(t,e),this.properties.add(new P(Nf,10)),this.properties.add(new P(Ff,40)),this.properties.add(new f(Gf,!1)),this.properties.add(new f($f,!0)),this.properties.add(new f(Uf,!0)),this.properties.add(new P(Yf,1)),this.properties.add(new P(zf,0))}async parseNode(t){await super.parseNode(t);let e=t.getNodes("widget");if(e.length){this.templateNode=e[0],this.templateWidgetType=this.templateNode.getString("widget_type"),this.elementWidth=this.templateNode.getInt("width",0),this.elementHeight=this.templateNode.getInt("height",0);for(let i=0;i<this.vec;i++){let r=this.templateNode.cloneWithOverrides({pvName:this.slotPvName(i),wuidSuffix:`-slot${i}`}),s=r.getString("widget_type"),o=this.display.createWidget(s,this);o&&(await o.parseNode(r),this.forEachDescendant(o,n=>this.originalEnabled.set(n,n.enabled)),o.properties.setValue(nP,new J(!1,!1,!1)),this.widgets.push(o),this.hookSlotWriteBack(i))}this.layoutSlots(),this.pvName&&this.display.pvEngine.trackListener(this,this.pvName,()=>this.value=this.pv.value)}}init(){this.spinnerUpRegion={id:`${this.wuid}-array-spinner-up`,mouseDown:()=>{this.spinnerUpPressed=!0,this.stepSpinnerRepeatedly(1,!0)},mouseUp:()=>this.stopSpinnerRepeating("up"),mouseOut:()=>this.stopSpinnerRepeating("up")},this.spinnerDownRegion={id:`${this.wuid}-array-spinner-down`,mouseDown:()=>{this.spinnerDownPressed=!0,this.stepSpinnerRepeatedly(-1,!0)},mouseUp:()=>this.stopSpinnerRepeating("down"),mouseOut:()=>this.stopSpinnerRepeating("down")},this.scrollDecreaseRegion={id:`${this.wuid}-array-scroll-decrease`,mouseDown:()=>{this.scrollDecreasePressed=!0,this.stepScrollbarRepeatedly(-1)},mouseUp:()=>this.stopScrollbarRepeating("decrease"),mouseOut:()=>this.stopScrollbarRepeating("decrease")},this.scrollIncreaseRegion={id:`${this.wuid}-array-scroll-increase`,mouseDown:()=>{this.scrollIncreasePressed=!0,this.stepScrollbarRepeatedly(1)},mouseUp:()=>this.stopScrollbarRepeating("increase"),mouseOut:()=>this.stopScrollbarRepeating("increase")},this.scrollPageDecreaseRegion={id:`${this.wuid}-array-scroll-page-decrease`,mouseDown:()=>this.setScrollbarIndex(this.scrollIndex-this.vec)},this.scrollPageIncreaseRegion={id:`${this.wuid}-array-scroll-page-increase`,mouseDown:()=>this.setScrollbarIndex(this.scrollIndex+this.vec)},this.scrollThumbRegion={id:`${this.wuid}-array-scroll-thumb`,mouseDown:()=>{this.scrollGrabStartIndex=this.scrollIndex},grab:t=>{if(this.scrollDragRange<=0)return;let e=this.horizontal?t.dx:t.dy,r=Math.max(0,this.effectiveArrayLength-this.vec)*e/this.scrollDragRange;this.setScrollbarIndex(this.scrollGrabStartIndex+r)}},this.spinnerLabelRegion={id:`${this.wuid}-array-spinner-label`,click:()=>this.startEditingIndex(),cursor:"text"},this.indexInputEl=document.createElement("input"),this.indexInputEl.style.display="none",this.indexInputEl.autocomplete="off",this.indexInputEl.addEventListener("keyup",t=>{t.key==="Enter"?this.commitEditingIndex():t.key==="Escape"&&this.cancelEditingIndex()}),this.indexInputEl.addEventListener("blur",()=>this.cancelEditingIndex()),this.display.rootPanel.appendChild(this.indexInputEl)}destroy(){window.clearTimeout(this.spinnerRepeatTimeout),window.clearTimeout(this.scrollRepeatTimeout),this.indexInputEl&&(this.display.rootPanel.removeChild(this.indexInputEl),this.indexInputEl=void 0),super.destroy()}forEachDescendant(t,e){if(e(t),t instanceof st)for(let i of t.widgets)this.forEachDescendant(i,e)}startEditingIndex(){if(!this.spinnerLabelBounds||!this.indexInputEl)return;this.editingIndex=!0;let t=this.display.measureAbsoluteArea(this),e=this.spinnerLabelBounds;this.indexInputEl.value=String(this.scrollIndex),this.indexInputEl.style.display="block",this.indexInputEl.style.position="absolute",this.indexInputEl.style.boxSizing="border-box",this.indexInputEl.style.left=`${t.x+e.x}px`,this.indexInputEl.style.top=`${t.y+e.y}px`,this.indexInputEl.style.width=`${e.width}px`,this.indexInputEl.style.height=`${e.height}px`,this.indexInputEl.style.textAlign="center",this.indexInputEl.focus(),this.indexInputEl.select(),this.requestRepaint()}commitEditingIndex(){let t=this.indexInputEl.value;this.cancelEditingIndex();let e=Number(t);isNaN(e)||this.setSpinnerIndex(e)}cancelEditingIndex(){this.indexInputEl.style.display="none",this.editingIndex=!1,this.requestRepaint()}slotPvName(t){return`loc://__array_${this.wuid}_slot${t}`}hookSlotWriteBack(t){let e=this.display.pvEngine.getPV(this.slotPvName(t));e&&this.display.pvEngine.trackListener(this,e.name,()=>{if(this.redistributing)return;let i=this.scrollIndex+t;i>=this.effectiveArrayLength||(this.fullValue[i]=this.coerceElement(e.value),this.pvName&&this.display.pvEngine.setValue(new Date,this.pvName,this.fullValue))})}coerceElement(t){if(this.dataType===Xf)return String(t);let e=Number(t);return isNaN(e)?t:e}defaultElementValue(){return this.dataType===Xf||this.templateWidgetType==="Text Update"?"":0}get value(){return super.value}set value(t){super.value=t,this.fullValue=Array.isArray(t)?t.slice():t!==void 0?[t]:[],this.scrollIndex=this.clampScrollbarIndex(this.scrollIndex),this.redistribute()}get effectiveArrayLength(){return this.pvName?this.fullValue.length:this.arrayLength}redistribute(){this.redistributing=!0;try{let t=this.effectiveArrayLength;for(let e=0;e<this.widgets.length;e++){let i=this.scrollIndex+e,r=i<t,s=r?this.fullValue[i]:this.defaultElementValue(),o=this.display.pvEngine.getPV(this.slotPvName(e));o&&(o.writable=r),this.display.pvEngine.setValue(new Date,this.slotPvName(e),s),this.forEachDescendant(this.widgets[e],n=>{n.properties.setValue("enabled",r?this.originalEnabled.get(n)??!0:!1)})}}finally{this.redistributing=!1}this.requestRepaint()}clampSpinnerIndex(t){let e=Math.max(0,this.effectiveArrayLength-1);return Math.min(Math.max(0,Math.round(t)),e)}clampScrollbarIndex(t){let e=Math.max(0,this.effectiveArrayLength-this.vec);return Math.min(Math.max(0,Math.round(t)),e)}setSpinnerIndex(t){let e=this.clampSpinnerIndex(t);e!==this.scrollIndex&&(this.scrollIndex=e,this.redistribute())}setScrollbarIndex(t){let e=this.clampScrollbarIndex(t);e!==this.scrollIndex&&(this.scrollIndex=e,this.redistribute())}setScrollIndex(t){this.setSpinnerIndex(t)}getScrollIndex(){return this.scrollIndex}stopSpinnerRepeating(t){window.clearTimeout(this.spinnerRepeatTimeout),t==="up"?this.spinnerUpPressed=!1:this.spinnerDownPressed=!1,this.requestRepaint()}stepSpinnerRepeatedly(t,e){window.clearTimeout(this.spinnerRepeatTimeout),this.setSpinnerIndex(this.scrollIndex+t),this.spinnerRepeatTimeout=window.setTimeout(()=>this.stepSpinnerRepeatedly(t,!1),e?hP:cP)}stopScrollbarRepeating(t){window.clearTimeout(this.scrollRepeatTimeout),t==="decrease"?this.scrollDecreasePressed=!1:this.scrollIncreasePressed=!1,this.requestRepaint()}stepScrollbarRepeatedly(t){window.clearTimeout(this.scrollRepeatTimeout),this.setScrollbarIndex(this.scrollIndex+t),this.scrollRepeatTimeout=window.setTimeout(()=>this.stepScrollbarRepeatedly(t),pP)}computeRegions(t,e,i,r,s){let o,n,a=0,l=0,h=t,p=e;return i>0&&(o={x:0,y:0,width:i,height:Math.min(s,e)},a+=i,h-=i),r>0&&(this.horizontal?(n={x:a,y:e-r,width:h,height:r},p-=r):(n={x:t-r,y:0,width:r,height:e},h-=r)),{spinnerBounds:o,scrollbarBounds:n,paneBounds:{x:a,y:l,width:h,height:p}}}autoScale(t,e){M.prototype.autoScale.call(this,t,e),this.layoutSlots()}layoutSlots(){if(!this.widgets.length)return;let t=this.properties.getValue("width"),e=this.properties.getValue("height"),{paneBounds:i}=this.computeRegions(t,e,this.showSpinner?this.spinnerWidth:0,this.showScrollbar?Kf:0,qf);for(let r=0;r<this.widgets.length;r++){let s=this.widgets[r],o=this.horizontal?i.x+r*this.elementWidth:i.x,n=this.horizontal?i.y:i.y+r*this.elementHeight;s.properties.setValue("x",o),s.properties.setValue("y",n)}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){let e=t.createChildAt(this.x,this.y,this.width,this.height);for(let s of this.widgets.filter(o=>o.visible))s.drawHolder(e),s.draw(e),s.drawDecoration(e);let{scale:i}=this,r=this.computeRegions(this.width,this.height,this.showSpinner?this.spinnerWidth*i:0,this.showScrollbar?Kf*i:0,qf*i);r.spinnerBounds&&this.drawSpinner(e,r.spinnerBounds),r.scrollbarBounds&&this.drawScrollbar(e,r.scrollbarBounds),this.drawGrayOverlay(e,r.paneBounds);for(let s of this.widgets.filter(o=>o.visible))s.drawOverlay(e);t.copyChild(e)}drawGrayOverlay(t,e){let i=Math.max(0,this.scrollIndex+this.vec-this.effectiveArrayLength);if(i<=0||!this.elementWidth||!this.elementHeight)return;let{scale:r}=this,s=this.vec-i,o=this.horizontal?{x:e.x+s*this.elementWidth*r,y:e.y,width:i*this.elementWidth*r,height:e.height}:{x:e.x,y:e.y+s*this.elementHeight*r,width:e.width,height:i*this.elementHeight*r};o.width<=0||o.height<=0||t.fillRect({...o,color:lP,opacity:40/255})}drawSpinner(t,e){let i=Math.min(e.width,aP*this.scale),r={x:e.x,y:e.y,width:i,height:e.height},s={x:e.x+i,y:e.y,width:Math.max(0,e.width-i),height:e.height},o=Math.floor(r.height/2),n={x:r.x,y:r.y,width:r.width,height:o},a={x:r.x,y:r.y+o,width:r.width,height:r.height-o};this.drawArrowButton(t,n,this.spinnerUpPressed,"up"),t.addHitRegion(this.spinnerUpRegion).addRect(n.x,n.y,n.width,n.height),this.drawArrowButton(t,a,this.spinnerDownPressed,"down"),t.addHitRegion(this.spinnerDownRegion).addRect(a.x,a.y,a.width,a.height),this.drawSpinnerLabel(t,s)}drawSpinnerLabel(t,e){if(this.spinnerLabelBounds=e,e.width<=0)return;t.fillRect({...e,color:m.WHITE}),t.strokeRect({...e,color:m.BUTTON_DARKER}),this.editingIndex||t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,baseline:"middle",align:"center",font:X.ARIAL_11.scale(this.scale),color:m.BLACK,text:String(this.scrollIndex)}),t.addHitRegion(this.spinnerLabelRegion).addRect(e.x,e.y,e.width,e.height)}drawScrollbar(t,e){t.fillRect({...e,color:dP});let i=this.effectiveArrayLength,r=Math.max(1,Math.min(this.vec,Math.max(i,1))),s=Math.max(i,r,1),o=Math.max(1,s-r);if(this.horizontal){let n=Math.min(e.height,e.width/2),a={x:e.x,y:e.y,width:n,height:e.height},l={x:e.x+e.width-n,y:e.y,width:n,height:e.height};this.drawArrowButton(t,a,this.scrollDecreasePressed,"left"),this.drawArrowButton(t,l,this.scrollIncreasePressed,"right"),t.addHitRegion(this.scrollDecreaseRegion).addRect(a.x,a.y,a.width,a.height),t.addHitRegion(this.scrollIncreaseRegion).addRect(l.x,l.y,l.width,l.height);let d=e.x+n,g=Math.max(0,e.width-2*n),x=Math.min(g,Math.max(6*this.scale,Math.floor(g*r/s)));this.scrollDragRange=g-x;let w=Math.floor((g-x)*Math.min(this.scrollIndex,o)/o),v={x:d+w,y:e.y,width:x,height:e.height};this.drawThumb(t,v),this.registerPageRegion(t,this.scrollPageDecreaseRegion,d,e.y,w,e.height),this.registerPageRegion(t,this.scrollPageIncreaseRegion,d+w+x,e.y,g-w-x,e.height)}else{let n=Math.min(e.width,e.height/2),a={x:e.x,y:e.y,width:e.width,height:n},l={x:e.x,y:e.y+e.height-n,width:e.width,height:n};this.drawArrowButton(t,a,this.scrollDecreasePressed,"up"),this.drawArrowButton(t,l,this.scrollIncreasePressed,"down"),t.addHitRegion(this.scrollDecreaseRegion).addRect(a.x,a.y,a.width,a.height),t.addHitRegion(this.scrollIncreaseRegion).addRect(l.x,l.y,l.width,l.height);let d=e.y+n,g=Math.max(0,e.height-2*n),x=Math.min(g,Math.max(6*this.scale,Math.floor(g*r/s)));this.scrollDragRange=g-x;let w=Math.floor((g-x)*Math.min(this.scrollIndex,o)/o),v={x:e.x,y:d+w,width:e.width,height:x};this.drawThumb(t,v),this.registerPageRegion(t,this.scrollPageDecreaseRegion,e.x,d,e.width,w),this.registerPageRegion(t,this.scrollPageIncreaseRegion,e.x,d+w+x,e.width,g-w-x)}}registerPageRegion(t,e,i,r,s,o){if(s<=0||o<=0)return;t.addHitRegion(e).addRect(i,r,s,o)}drawThumb(t,e){t.fillRect({...e,color:m.BUTTON}),this.drawBevelBorder(t,e,!1),t.addHitRegion(this.scrollThumbRegion).addRect(e.x,e.y,e.width,e.height)}drawBevelBorder(t,e,i){let r=1*this.scale,s=e.y+r/2,o=e.x+r/2,n=e.y+e.height-r+r/2,a=e.x+e.width-r+r/2,[l,h,p,d]=i?[m.BUTTON_LIGHTEST,m.BUTTON_LIGHTEST,m.BUTTON_DARKEST,m.BUTTON_DARKER]:[m.BUTTON_DARKEST,m.BUTTON_DARKER,m.BUTTON,m.BUTTON_LIGHTEST];t.strokePath({color:l,path:new _(a,n).lineTo(a,s).moveTo(a,n).lineTo(o,n)}),t.strokePath({color:h,path:new _(a-r,n-r).lineTo(a-r,s+r).moveTo(a-r,n-r).lineTo(o+r,n-r)}),t.strokePath({color:p,path:new _(o,s).lineTo(a-r,s).moveTo(o,s).lineTo(o,n-r)}),t.strokePath({color:d,path:new _(o+r,s+r).lineTo(a-r-r,s+r).moveTo(o+r,s+r).lineTo(o+r,n-r-r)})}drawArrowButton(t,e,i,r){t.fillRect({...e,color:i?m.BUTTON_DARKER:m.BUTTON}),this.drawBevelBorder(t,e,i);let s=Math.max(1,Math.min(3*this.scale,e.width/2-1,e.height/2-1)),o=Math.max(1,Math.min(2*this.scale,s)),n=e.x+e.width/2,a=e.y+e.height/2,l;r==="up"?l=new _(n,a-o).lineTo(n-s,a+o).lineTo(n+s,a+o).closePath():r==="down"?l=new _(n,a+o).lineTo(n-s,a-o).lineTo(n+s,a-o).closePath():r==="left"?l=new _(n-o,a).lineTo(n+o,a-s).lineTo(n+o,a+s).closePath():l=new _(n+o,a).lineTo(n-o,a-s).lineTo(n-o,a+s).closePath(),t.fillPath({color:m.BLACK,path:l})}get arrayLength(){return this.properties.getValue(Nf)}get spinnerWidth(){return this.properties.getValue(Ff)}get horizontal(){return this.properties.getValue(Gf)}get showSpinner(){return this.properties.getValue($f)}get showScrollbar(){return this.properties.getValue(Uf)}get vec(){return this.properties.getValue(Yf)}get dataType(){return this.properties.getValue(zf)}};var eo="fc",jf="show_scrollbar",Zf="background_color",Jf="foreground_color",uP=16,gP=20,Qf=150,mP=new m(243,243,243),tw=new m(232,232,231),ns=class extends st{scrollX=0;scrollY=0;maxScrollX=0;maxScrollY=0;contentWidth=0;contentHeight=0;dragRangeX;dragRangeY;grabStartX;grabStartY;actionTimeout;xDecPressed=!1;xIncPressed=!1;yDecPressed=!1;yIncPressed=!1;thumbXRegion;thumbYRegion;xDecRegion;xIncRegion;yDecRegion;yIncRegion;trackXBeforeRegion;trackXAfterRegion;trackYBeforeRegion;trackYAfterRegion;constructor(t,e){super(t,e),this.properties.add(new f(eo,!1)),this.properties.add(new f(jf,!0))}async parseNode(t){await super.parseNode(t);for(let i of t.getNodes("widget")){let r=i.getString("widget_type"),s=this.display.createWidget(r,this);s&&(await s.parseNode(i),this.widgets.push(s))}tr(this.widgets);let e=()=>{if(this.forwardColors)for(let i of this.widgets)i.properties.setValue(Zf,this.backgroundColor),i.properties.setValue(Jf,this.foregroundColor),i.requestRepaint()};this.addPropertyListener(eo,e),this.addPropertyListener(Zf,e),this.addPropertyListener(Jf,e)}init(){this.thumbXRegion=this.makeThumbRegion("x"),this.thumbYRegion=this.makeThumbRegion("y"),this.xDecRegion=this.makeStepRegion("x",-1),this.xIncRegion=this.makeStepRegion("x",1),this.yDecRegion=this.makeStepRegion("y",-1),this.yIncRegion=this.makeStepRegion("y",1),this.trackXBeforeRegion=this.makePageRegion("x",-1),this.trackXAfterRegion=this.makePageRegion("x",1),this.trackYBeforeRegion=this.makePageRegion("y",-1),this.trackYAfterRegion=this.makePageRegion("y",1)}destroy(){window.clearTimeout(this.actionTimeout),super.destroy()}makeThumbRegion(t){return{id:`${this.wuid}-scrollbar-${t}-thumb`,mouseDown:()=>{t==="x"?this.grabStartX=this.scrollX:this.grabStartY=this.scrollY},grab:e=>{let i=t==="x"?this.maxScrollX:this.maxScrollY,r=(t==="x"?this.dragRangeX:this.dragRangeY)||1,s=t==="x"?e.dx:e.dy,o=(t==="x"?this.grabStartX:this.grabStartY)??0;this.setScrollOffset(t,o+i*s/r)},tooltip:()=>this.tooltip}}makeStepRegion(t,e){let i=r=>{t==="x"?e<0?this.xDecPressed=r:this.xIncPressed=r:e<0?this.yDecPressed=r:this.yIncPressed=r};return{id:`${this.wuid}-scrollbar-${t}-${e<0?"dec":"inc"}`,mouseDown:()=>{i(!0),this.stepScrollRepeatedly(t,e)},mouseUp:()=>this.endScrollAction(()=>i(!1)),mouseOut:()=>this.endScrollAction(()=>i(!1)),tooltip:()=>this.tooltip}}makePageRegion(t,e){return{id:`${this.wuid}-scrollbar-${t}-page-${e<0?"before":"after"}`,mouseDown:()=>this.pageScrollRepeatedly(t,e),mouseUp:()=>this.endScrollAction(),mouseOut:()=>this.endScrollAction(),tooltip:()=>this.tooltip}}setScrollOffset(t,e){let i=t==="x"?this.maxScrollX:this.maxScrollY,r=Math.min(Math.max(e,0),i);t==="x"?this.scrollX=r:this.scrollY=r,this.requestRepaint()}stepScrollRepeatedly(t,e){window.clearTimeout(this.actionTimeout);let i=t==="x"?this.scrollX:this.scrollY;this.setScrollOffset(t,i+e*gP*this.scale),this.actionTimeout=window.setTimeout(()=>this.stepScrollRepeatedly(t,e),Qf)}pageScrollRepeatedly(t,e){window.clearTimeout(this.actionTimeout);let i=t==="x"?this.scrollX:this.scrollY,r=t==="x"?this.contentWidth:this.contentHeight;this.setScrollOffset(t,i+e*r),this.actionTimeout=window.setTimeout(()=>this.pageScrollRepeatedly(t,e),Qf)}endScrollAction(t){window.clearTimeout(this.actionTimeout),t?.(),this.requestRepaint()}get forwardColors(){return this.properties.getValue(eo)}get showScrollbar(){return this.properties.getValue(jf)}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}measureContentExtent(){let t=this.width,e=this.height;for(let i of this.widgets.filter(r=>r.visible)){let r=i.bounds;t=Math.max(t,r.x+r.width),e=Math.max(e,r.y+r.height)}return{width:t,height:e}}resolveScrollbars(t,e,i){if(!this.showScrollbar)return{showH:!1,showV:!1};let r=t>this.width,s=e>this.height;return r&&!s&&e>this.height-i?s=!0:s&&!r&&t>this.width-i&&(r=!0),{showH:r,showV:s}}draw(t){let e=uP*this.scale,i=this.measureContentExtent(),{showH:r,showV:s}=this.resolveScrollbars(i.width,i.height,e);this.contentWidth=this.width-(s?e:0),this.contentHeight=this.height-(r?e:0),this.maxScrollX=Math.max(0,i.width-this.contentWidth),this.maxScrollY=Math.max(0,i.height-this.contentHeight),this.scrollX=Math.min(Math.max(this.scrollX,0),this.maxScrollX),this.scrollY=Math.min(Math.max(this.scrollY,0),this.maxScrollY);let o=t.createChildAt(this.x,this.y,this.width,this.height);o.translate(-this.scrollX,-this.scrollY),o.ctx.save(),o.ctx.beginPath(),o.ctx.rect(this.scrollX,this.scrollY,this.contentWidth,this.contentHeight),o.ctx.clip();for(let n of this.widgets.filter(a=>a.visible))n.drawHolder(o),n.draw(o),n.drawDecoration(o);for(let n of this.widgets.filter(a=>a.visible))n.drawOverlay(o);o.ctx.restore(),o.translate(this.scrollX,this.scrollY),r&&this.drawScrollbar(o,"x",{x:0,y:this.contentHeight,width:this.contentWidth,height:e}),s&&this.drawScrollbar(o,"y",{x:this.contentWidth,y:0,width:e,height:this.contentHeight}),t.copyChild(o)}drawScrollbar(t,e,i){let{scale:r}=this;t.fillRect({...i,color:mP});let s=e==="x",o=s?Math.min(i.height,i.width/2):Math.min(i.width,i.height/2),n=s?{x:i.x,y:i.y,width:o,height:i.height}:{x:i.x,y:i.y,width:i.width,height:o},a=s?{x:i.x+i.width-o,y:i.y,width:o,height:i.height}:{x:i.x,y:i.y+i.height-o,width:i.width,height:o};this.drawScrollButton(t,e,-1,n),this.drawScrollButton(t,e,1,a);let l=s?i.x+o:i.y+o,h=(s?i.width:i.height)-2*o,p=s?this.contentWidth:this.contentHeight,d=s?this.maxScrollX:this.maxScrollY,g=Math.min(1,p/(p+d)),x=Math.max(6*r,h*g);s?this.dragRangeX=h-x:this.dragRangeY=h-x;let w=s?this.scrollX:this.scrollY,v=d>0?w/d:0,S=l+(h-x)*v,A=s?{x:S,y:i.y,width:x,height:i.height}:{x:i.x,y:S,width:i.width,height:x};t.fillRect({...A,color:tw}),He(t,A,r);let C=s?this.thumbXRegion:this.thumbYRegion;t.addHitRegion(C).addRect(A.x,A.y,A.width,A.height);let V=l+h,D=s?this.trackXBeforeRegion:this.trackYBeforeRegion,N=s?this.trackXAfterRegion:this.trackYAfterRegion;s?(t.addHitRegion(D).addRect(l,i.y,S-l,i.height),t.addHitRegion(N).addRect(S+x,i.y,V-(S+x),i.height)):(t.addHitRegion(D).addRect(i.x,l,i.width,S-l),t.addHitRegion(N).addRect(i.x,S+x,i.width,V-(S+x)))}drawScrollButton(t,e,i,r){let{scale:s}=this,o=e==="x"?i<0?this.xDecPressed:this.xIncPressed:i<0?this.yDecPressed:this.yIncPressed;t.fillRect({...r,color:tw}),o?Mr(t,r,s):He(t,r,s);let n=e==="x"?i<0?this.xDecRegion:this.xIncRegion:i<0?this.yDecRegion:this.yIncRegion;t.addHitRegion(n).addRect(r.x,r.y,r.width,r.height);let a=e==="x"?i<0?"left":"right":i<0?"up":"down";Vr(t,r,s,a)}};var ew="horizontal",iw="panel1_auto_scale_children",rw="panel2_auto_scale_children",io="sash_position",sw="sash_style",ow="sash_width",ro="x",so="y",as="width",ls="height",fP=0,wP=1,xP=2,yP=3,PP=4,bP=5,vP=12,hs=class extends st{sashRegion;grabStartPosition;grabClientSize;panelOriginSizes=new Map;childOriginBounds=new Map;constructor(t,e){super(t,e),this.properties.add(new f(ew,!0)),this.properties.add(new f(iw,!1)),this.properties.add(new f(rw,!1)),this.properties.add(new O(io,.5)),this.properties.add(new P(sw,xP)),this.properties.add(new P(ow,3))}async parseNode(t){await super.parseNode(t);for(let e of t.getNodes("widget")){let i=e.getString("widget_type"),r=this.display.createWidget(i,this);r&&(await r.parseNode(e),this.widgets.push(r))}}init(){this.sashRegion={id:`${this.wuid}-sash`,mouseDown:()=>{this.grabStartPosition=this.sashPosition,this.grabClientSize=this.horizontal?this.width:this.height},grab:t=>{if(this.grabStartPosition===void 0||!this.grabClientSize)return;let e=this.horizontal?t.dx:t.dy,i=this.sashWidth*this.scale,r=this.minPaneSize,s=r+i/2,o=this.grabClientSize-r-i/2,n=this.grabStartPosition*this.grabClientSize+e;n=Math.min(o,Math.max(s,n)),this.properties.setValue(io,n/this.grabClientSize),this.requestRepaint()}}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){let e=t.createChildAt(this.x,this.y,this.width,this.height),[i,r]=this.widgets;if(i&&r){let{boundsA:s,boundsB:o,sashBounds:n}=this.measureLayout();this.applyPanelBounds(i,s,this.panel1AutoScaleChildren),this.applyPanelBounds(r,o,this.panel2AutoScaleChildren);for(let a of[i,r])a.drawHolder(e),a.draw(e),a.drawDecoration(e);for(let a of[i,r])a.drawOverlay(e);this.drawSash(e,n,s,o)}t.copyChild(e)}measureLayout(){let{horizontal:t}=this,e=t?this.width:this.height,i=t?this.height:this.width,r=this.sashWidth*this.scale,s=Math.floor(r/2),o=this.minPaneSize,n=e-r-o,a=Math.floor(this.sashPosition*e-s);a=Math.min(n,Math.max(o,a));let l=e-a-r,h,p,d;return t?(h={x:0,y:0,width:a,height:i},p={x:a+r,y:0,width:l,height:i},d={x:a,y:0,width:r,height:i}):(h={x:0,y:0,width:i,height:a},p={x:0,y:a+r,width:i,height:l},d={x:0,y:a,width:i,height:r}),{boundsA:h,boundsB:p,sashBounds:d}}applyPanelBounds(t,e,i){let{scale:r}=this,s={x:e.x/r,y:e.y/r,width:e.width/r,height:e.height/r};i&&t instanceof st&&this.scalePanelChildren(t,s),t.properties.setValue(ro,s.x),t.properties.setValue(so,s.y),t.properties.setValue(as,s.width),t.properties.setValue(ls,s.height)}scalePanelChildren(t,e){let i=this.panelOriginSizes.get(t);i||(i={x:0,y:0,width:t.properties.getValue(as),height:t.properties.getValue(ls)},this.panelOriginSizes.set(t,i));let r=i.width?e.width/i.width:1,s=i.height?e.height/i.height:1;for(let o of t.widgets){let n=this.childOriginBounds.get(o);n||(n={x:o.properties.getValue(ro),y:o.properties.getValue(so),width:o.properties.getValue(as),height:o.properties.getValue(ls)},this.childOriginBounds.set(o,n)),o.properties.setValue(ro,Math.round(n.x*r)),o.properties.setValue(so,Math.round(n.y*s));let{widthScalable:a,heightScalable:l}=o.scaleOptions;if(a||l){let{width:h,height:p}=Ri(n,r,s,o.scaleOptions);o.properties.setValue(as,h),o.properties.setValue(ls,p)}}}autoScale(t,e){M.prototype.autoScale.call(this,t,e)}drawSash(t,e,i,r){let{sashStyle:s}=this;if(s!==fP)if(s===wP){let o=6*this.scale;for(let n of[i,r])t.strokeRect({x:n.x+1,y:n.y+1,width:n.width-2,height:n.height-2,rx:o,ry:o,color:m.BUTTON_DARKER})}else if(s===PP){let o=this.horizontal?e.width:e.height,n=e.x+e.width/2,a=e.y+e.height/2,l=this.horizontal?new _(n,e.y).lineTo(n,e.y+e.height):new _(e.x,a).lineTo(e.x+e.width,a);t.strokePath({path:l,color:this.foregroundColor,lineWidth:o})}else if(s===bP)this.drawSashEdge(t,e,"near",m.BUTTON_DARKER),this.drawSashEdge(t,e,"far",m.BUTTON_DARKER);else{let o=s===yP;t.fillRect({...e,color:m.BUTTON}),this.drawSashEdge(t,e,"near",o?m.BUTTON_DARKER:m.BUTTON_LIGHTEST),this.drawSashEdge(t,e,"far",o?m.BUTTON_LIGHTEST:m.BUTTON_DARKER)}this.sashRegion&&(this.sashRegion.cursor=this.horizontal?"col-resize":"row-resize",t.addHitRegion(this.sashRegion).addRect(e.x,e.y,e.width,e.height))}drawSashEdge(t,e,i,r){let s=1*this.scale,o;if(this.horizontal){let n=i==="near"?e.x:e.x+e.width-s;o=new _(n,e.y).lineTo(n,e.y+e.height)}else{let n=i==="near"?e.y:e.y+e.height-s;o=new _(e.x,n).lineTo(e.x+e.width,n)}t.strokePath({path:o,color:r,lineWidth:s})}get horizontal(){return this.properties.getValue(ew)}get minPaneSize(){return vP*this.scale}get panel1AutoScaleChildren(){return this.properties.getValue(iw)}get panel2AutoScaleChildren(){return this.properties.getValue(rw)}get sashPosition(){return this.properties.getValue(io)}get sashStyle(){return this.properties.getValue(sw)}get sashWidth(){return this.properties.getValue(ow)}};var nw="minimum_tab_height",no="active_tab",aw="horizontal_tabs",oo="tab_count",ao=class{constructor(t,e){this.widget=t;this.i=e;this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(no,e),t.requestRepaint())},cursor:"pointer"}}headerRegion;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)}},si=class extends st{tabs=[];constructor(t,e){super(t,e),this.properties.add(new P(nw)),this.properties.add(new P(no)),this.properties.add(new f(aw)),this.properties.add(new P(oo)),this.properties.addGenerator(()=>{this.tabs=[];let i=this.properties.getValue(oo),r=[];for(let s=0;s<i;s++)this.tabs.push(new ao(this,s)),r.push(new T(`tab_${s}_title`),new L(`tab_${s}_background_color`),new L(`tab_${s}_foreground_color`),new f(`tab_${s}_enabled`),new H(`tab_${s}_font`));return r})}async parseNode(t){await super.parseNode(t);for(let e of t.getNodes("widget")){let i=e.getString("widget_type"),r=this.display.createWidget(i,this);r&&(await r.parseNode(e),this.widgets.push(r))}}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){let{scale:e}=this,i=1*e,r=this.minimumTabHeight;for(let s=0;s<this.tabs.length;s++){let o=this.tabs[s],a=t.measureText(o.title,o.font).height+i;a>r&&(r=a)}return r+this.margin}measureLabelWidth(t){let{scale:e}=this,i=1*e,r=this.minimumTabWidth;for(let s=0;s<this.tabs.length;s++){let o=this.tabs[s],a=t.measureText(o.title,o.font).width+i;a>r&&(r=a)}return r+this.margin}drawHorizontalTabs(t){let{margin:e,gap:i,scale:r}=this,s=this.measureLabelHeight(t),o=1*r,n=this.x;for(let a=0;a<this.tabs.length;a++){let l=this.tabs[a],h=t.measureText(l.title,l.font),p,d,g,x,w;this.activeTab===a?(p=n,d=this.y,g=h.width+o+e+i,x=s,w=l.backgroundColor):(p=n+i,d=this.y+2*r,g=h.width+o+e-i,x=s-2*r,w=this.darken(l.backgroundColor)),t.fillRect({x:p,y:d,width:g,height:x,color:w}),t.addHitRegion(l.headerRegion).addRect(p,d,g,x);let S=t.createLinearGradient(p,d,p,d+x);if(S.addColorStop(0,m.WHITE.toString()),S.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:p,y:d,width:g,height:x,gradient:S}),t.fillText({x:p+g/2,y:d+x/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=h.width+o+e-1*r,this.activeTab===a){let A=this.x,C=this.y+s,V=this.width,D=this.height-s;t.fillRect({x:A,y:C,width:V,height:D,color:l.backgroundColor});let N=this.widgets[a],$=t.createChildAt(A,C,V,D);N.drawHolder($),N.draw($),N.drawDecoration($),N.drawOverlay($),t.copyChild($)}else this.widgets[a].hide()}}drawVerticalTabs(t){let{margin:e,gap:i,scale:r}=this,s=this.measureLabelWidth(t),o=1*r,n=this.y;for(let a=0;a<this.tabs.length;a++){let l=this.tabs[a],h=t.measureText(l.title,l.font),p=Math.max(h.height+o+o,this.minimumTabHeight),d,g,x,w,v;this.activeTab===a?(d=this.x,g=n,x=s,w=p+e+i,v=l.backgroundColor):(d=this.x+2*r,g=n+i,x=s-2*r,w=p+e-i,v=this.darken(l.backgroundColor)),t.fillRect({x:d,y:g,width:x,height:w,color:v}),t.addHitRegion(l.headerRegion).addRect(d,g,x,w);let A=t.createLinearGradient(d,g,d+x,g);if(A.addColorStop(0,m.WHITE.toString()),A.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:d,y:g,width:x,height:w,gradient:A}),t.fillText({x:d+x/2,y:g+w/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=p+e-1*r,this.activeTab===a){let C=this.x+s-1*r,V=this.y,D=this.width-s,N=this.height-1*r;t.fillRect({x:C,y:V,width:D,height:N,color:l.backgroundColor});let $=this.widgets[a],z=t.createChildAt(C,V,D,N);$.drawHolder(z),$.draw(z),$.drawDecoration(z),$.drawOverlay(z),t.copyChild(z)}else this.widgets[a].destroy()}}darken(t){let e=Math.max(0,t.red-30),i=Math.max(0,t.green-30),r=Math.max(0,t.blue-30);return new m(e,i,r)}get margin(){return this.scale*10}get gap(){return this.scale*2}get minimumTabWidth(){return this.scale*20}get minimumTabHeight(){return this.scale*this.properties.getValue(nw)}get activeTab(){return this.properties.getValue(no)}get tabCount(){return this.properties.getValue(oo)}get horizontalTabs(){return this.properties.getValue(aw)}};var cs=class{constructor(t){this.table=t}columnCount=0;cells=[];selectedRowIndex;dirty=!1;modifiedListeners=[];selectionChangedListeners=[];isEmpty(){return!this.cells.length}refresh(){this.dirty=!0}getCells(){return this.cells}getContent(){let t=[];for(let e of this.cells)t.push(e.map(i=>i.text||""));return t}setContent(t){this.cells.length=0;for(let e=0;e<t.length;e++)e===0&&(this.columnCount=t[e].length),this.cells.push(t[e].map(i=>({text:i})));this.dirty=!0}getColumnCount(){return this.columnCount}getRowCount(){return this.cells.length}setSelectedRowIndex(t){this.selectedRowIndex=t,this.selectionChangedListeners.forEach(e=>e()),this.dirty=!0}getSelection(){return this.selectedRowIndex===void 0?[]:[[...this.cells[this.selectedRowIndex].map(e=>e.text??null)]]}getCellText(t,e){let i=this.cells[t];return i?i[e]?.text??null:null}setColumnsCount(t){if(t<this.columnCount)for(let e of this.cells)e.length=t;if(t>this.columnCount){let e=t-this.columnCount;for(let i of this.cells)for(let r=0;r<e;r++)i.push({text:""})}this.columnCount=t,this.dirty=!0}addModifiedListener(t){this.modifiedListeners.push(t)}addSelectionChangedListener(t){this.selectionChangedListeners.push(t)}appendRow(){let t=[];for(let e=0;e<this.columnCount;e++)t[e]={text:""};return this.cells.push(t),this.dirty=!0,this.cells.length-1}deleteRow(t){this.cells.splice(t,1),this.dirty=!0}deleteColumn(t){for(let e of this.cells)e.splice(t,1);this.columnCount--,this.dirty=!0}insertRow(t){let e=[];for(let i=0;i<this.columnCount;i++)e.push({text:""});this.cells.splice(t,0,e),this.dirty=!0}insertColumn(t){for(let e of this.cells)e.splice(t,0,{text:""});this.columnCount++,this.dirty=!0}getCell(t,e){this.cells[t]=this.cells[t]??[];let i=this.cells[t][e]??{};return this.cells[t][e]=i,i}setCellText(t,e,i){let r=this.getCell(t,e);r.text=i,this.dirty=!0}setRowBackground(t,e){let i=this.cells[t];for(let r of i)r.backgroundColor=e;this.dirty=!0}setRowForeground(t,e){let i=this.cells[t];for(let r of i)r.foregroundColor=e;this.dirty=!0}setCellBackground(t,e,i){let r=this.getCell(t,e);r.backgroundColor=i,this.dirty=!0}setCellForeground(t,e,i){let r=this.getCell(t,e);r.foregroundColor=i,this.dirty=!0}setColumnCellEditorData(t,e){}};var lw="columns_count",hw="column_headers",cw="column_header_visible",pw="default_content",dw="font",ps=class extends M{tableWrapper;table;spreadsheet;constructor(t,e){super(t,e),this.properties.add(new P(lw)),this.properties.add(new be(hw)),this.properties.add(new f(cw)),this.properties.add(new be(pw)),this.properties.add(new H(dw)),this.spreadsheet=new cs(this)}init(){this.tableWrapper=document.createElement("div"),this.tableWrapper.style.display="none",this.tableWrapper.style.overflow="auto",this.table=document.createElement("table"),this.table.style.tableLayout="fixed",this.table.style.borderSpacing="0",this.table.style.borderCollapse="collapse",this.tableWrapper.appendChild(this.table),this.display.rootPanel.appendChild(this.tableWrapper),this.table.addEventListener("click",t=>{let e=t.target;if(e.tagName==="TD"){let i=e.parentElement;i.rowIndex>0&&this.spreadsheet.setSelectedRowIndex(i.rowIndex-1)}else this.spreadsheet.setSelectedRowIndex(void 0);this.requestRepaint()}),this.spreadsheet.setContent(this.defaultContent)}draw(t){if(this.tableWrapper){let{x:e,y:i,width:r,height:s}=this.display.measureAbsoluteArea(this);this.tableWrapper.style.backgroundColor="white",this.tableWrapper.style.position="absolute",this.tableWrapper.style.display="block",this.tableWrapper.style.left=`${e}px`,this.tableWrapper.style.top=`${i}px`,this.tableWrapper.style.width=`${r}px`,this.tableWrapper.style.height=`${s}px`,this.tableWrapper.style.border="1px solid rgba(0, 0, 0, 0.1)",this.table.style.font=this.font.getFontString(),this.spreadsheet.dirty&&(this.generateTableContent(),this.spreadsheet.dirty=!1)}}generateTableContent(){let t=this.table.rows.length;for(let i=t-1;i>=0;i--)this.table.deleteRow(i);if(this.columnHeaderVisible){let i=this.table.insertRow();for(let r=0;r<this.columnsCount;r++){let s=this.columnHeaders[r],o=i.insertCell();o.style.color="#aaa",o.style.textAlign="left",s?.length>=2&&s[1]!==""&&(o.style.width=Number(s[1])*this.scale+"px"),o.style.overflow="hidden",o.style.padding=`${4*this.scale}px`,o.style.borderBottom="1px solid rgba(0, 0, 0, 0.1)",r!==0&&(o.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)");let n="";s?.length>=1&&(n=s[0]);let a=document.createTextNode(n);o.appendChild(a)}i.insertCell()}let e=this.spreadsheet.getCells();for(let i=0;i<e.length;i++){let r=e[i],s=i===this.spreadsheet.selectedRowIndex,o=this.table.insertRow();for(let n=0;n<this.columnsCount;n++){let a=o.insertCell();if(a.style.textAlign="left",a.style.overflow="hidden",a.style.wordWrap="break-word",a.style.textOverflow="ellipsis",a.style.padding=`${4*this.scale}px`,n!==0&&(a.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)"),r[n]!==void 0){let l=s?m.BLUE:r[n].backgroundColor;l&&(a.style.backgroundColor=l.toString());let h=s?m.WHITE:r[n].foregroundColor;h&&(a.style.color=h.toString());let p=document.createTextNode(r[n].text||"");a.appendChild(p)}}o.insertCell()}}hide(){this.tableWrapper&&(this.tableWrapper.style.display="none")}destroy(){this.tableWrapper&&(this.display.rootPanel.removeChild(this.tableWrapper),this.tableWrapper=void 0,this.table=void 0)}get columnsCount(){return this.properties.getValue(lw)}get columnHeaders(){return this.properties.getValue(hw)}get columnHeaderVisible(){return this.properties.getValue(cw)}get defaultContent(){return this.properties.getValue(pw)}get font(){return this.properties.getValue(dw).scale(this.scale)}};var uw="url",ds=class extends M{iframe;prevUrl;constructor(t,e){super(t,e),this.properties.add(new T(uw))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){let{x:e,y:i,width:r,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${e}px`,this.iframe.style.top=`${i}px`,this.iframe.style.width=`${r}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(uw)}};var RP="Action Button",_P="Arc",TP="Array",SP="Boolean Button",LP="Boolean Switch",CP="Byte Monitor",AP="Check Box",OP="Choice Button",EP="Combo",MP="Combo Box",VP="Ellipse",IP="Gauge",BP="Grid Layout",HP="Grouping Container",DP="Image",WP="Image Boolean Button",kP="Image Boolean Indicator",NP="Intensity Graph",FP="Knob",GP="Label",$P="LED",UP="Linking Container",YP="Menu Button",zP="Meter",XP="Button",qP="Polygon",KP="Polyline",jP="Progress Bar",ZP="Radio Box",JP="Rectangle",QP="Rounded Rectangle",tb="Sash Container",eb="Scaled Slider",ib="Scrollbar",rb="Spinner",sb="Tabbed Container",ob="Table",nb="Tank",ab="Text Input",lb="Text Update",hb="Thermometer",cb="Thumb Wheel",pb="Web Browser",db="XY Graph";function lo(){return window.devicePixelRatio||1}var us=class{constructor(t){this.targetElement=t;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",this.rootPanel.style.flexShrink="0",this.rootPanel.style.margin="auto",t.appendChild(this.rootPanel),t.style.position="relative",t.style.display="flex";let e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new bi(e),this.ctx=this.g.ctx,this.formatter=new gi(!1),this.pvEngine=new ar(this),this.pvEngine.addProvider(new hr),this.pvEngine.addProvider(new cr(this.formatter)),this.pvEngine.addProvider(new or),this.displayRegion={id:"display-root",click:()=>{for(let i of this.rootPanel.getElementsByTagName("input"))i.blur();for(let i of this.rootPanel.getElementsByTagName("textarea"))i.blur();for(let i of this.rootPanel.getElementsByTagName("select"))i.blur()}},this.pathResolver=new er(this),this.scriptLoader=new ir(this),this.consoleHandler=new pi,this.dialogHandler=new fe,this.imageLoader=new vi,this.stepTimer=window.setTimeout(()=>this.step()),this.eventHandler=new ui(this,e,this.g.hitCanvas),this.resizeObserver=new ResizeObserver(()=>this.requestRepaint()),this.resizeObserver.observe(t)}rootPanel;g;ctx;pvEngine;pathResolver;fontResolver;scriptLoader;imageLoader;consoleHandler;dialogHandler;pendingTask;formatter;repaintRequested=!1;_editMode=!1;_showGrid=!1;_showOutline=!1;_showRuler=!1;_selection=[];_scale=1;_pixelRatio=lo();pixelRatioOverridden=!1;_transparent=!1;_disconnectedColor=new m(160,32,240);_invalidColor=new m(255,0,255);_majorColor=new m(255,0,0);_minorColor=new m(255,128,0);refreshCycle=100;originDesignSize;wasAutoScaleActive=!1;_autoScaleOverride="DEFAULT";resizeObserver;eventHandler;stepTimer;imagesPrefix="";absPrefix="";relPrefix="";instance;eventListeners={closedisplay:[],displayloaded:[],opendisplay:[],openpv:[],runcommand:[],runprocedure:[],runstack:[],selection:[],scale:[]};displayRegion;addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}setPathResolver(t){this.pathResolver=t}getPathResolver(){return this.pathResolver}setScriptLoader(t){this.scriptLoader=t}getScriptLoader(){return this.scriptLoader}loadContent(t){return this.scriptLoader.load(t)}setImageLoader(t){this.imageLoader=t}getImageLoader(){return this.imageLoader}setConsoleHandler(t){this.consoleHandler=t}getConsoleHandler(){return this.consoleHandler}setDialogHandler(t){this.dialogHandler=t}getDialogHandler(){return this.dialogHandler}runSequenced(t){if(this.pendingTask)this.trackTask(this.pendingTask.then(t));else{let e=t();e&&this.trackTask(e)}}trackTask(t){let e=t.catch(i=>console.error(i));this.pendingTask=e,e.then(()=>{this.pendingTask===e&&(this.pendingTask=void 0)})}setFontResolver(t){this.fontResolver=t}getFontResolver(){return this.fontResolver}step(){!this.pixelRatioOverridden&&this._pixelRatio!==lo()&&(this._pixelRatio=lo(),this.requestRepaint()),this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),this.stepTimer=window.setTimeout(()=>this.step(),this.refreshCycle)}drawScreen(){let t=this.rootPanel.style;if(t.position="relative",t.inset="",t.width="",t.height="",this.instance){let i=this.measureContainerSize();i&&this.isAutoScaleActive()?(t.position="absolute",t.inset="0",this.applyAutoScale(i)):(this.revertAutoScale(),t.width=this.instance.holderWidth+"px",t.height=this.instance.holderHeight+"px")}else t.width="0px",t.height="0px";if(this.g.pixelRatio=this._pixelRatio,this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){let i=document.createElement("canvas"),r=i.getContext("2d");i.width=16,i.height=16,r.fillStyle="#d6d6d6",r.fillRect(0,0,8,8),r.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(i,"repeat"),this.ctx.fillRect(0,0,this.g.cssWidth,this.g.cssHeight),this.instance&&this.g.fillRect({...this.instance.bounds,color:this.instance.backgroundColor})}else this.transparent||this.g.fillCanvas(this.instance?.backgroundColor||m.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.g.cssWidth,this.g.cssHeight),this.showGrid&&this.instance){let i=document.createElement("canvas"),r=i.getContext("2d");i.width=25,i.height=25,r.fillStyle=this.instance.foregroundColor.toString(),r.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(i,"repeat"),this.ctx.fillRect(25,25,this.g.cssWidth-50,this.g.cssHeight-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 i=0;for(;i<=this.g.cssWidth;)i+=100,this.ctx.beginPath(),this.ctx.moveTo(i-75+.5,this.g.cssHeight),this.ctx.lineTo(i-75+.5,this.g.cssHeight-4),this.ctx.moveTo(i-50+.5,this.g.cssHeight),this.ctx.lineTo(i-50+.5,this.g.cssHeight-6),this.ctx.moveTo(i-25+.5,this.g.cssHeight),this.ctx.lineTo(i-25+.5,this.g.cssHeight-4),this.ctx.moveTo(i+.5,this.g.cssHeight),this.ctx.lineTo(i+.5,this.g.cssHeight-8),this.ctx.stroke(),this.ctx.fillText(String(i),i,this.g.cssHeight-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let r=0;for(;r<=this.g.cssHeight;)r+=100,this.ctx.beginPath(),this.ctx.moveTo(this.g.cssWidth,r-75+.5),this.ctx.lineTo(this.g.cssWidth-4,r-75+.5),this.ctx.moveTo(this.g.cssWidth,r-50+.5),this.ctx.lineTo(this.g.cssWidth-6,r-50+.5),this.ctx.moveTo(this.g.cssWidth,r-25+.5),this.ctx.lineTo(this.g.cssWidth-4,r-25+.5),this.ctx.moveTo(this.g.cssWidth,r+.5),this.ctx.lineTo(this.g.cssWidth-8,r+.5),this.ctx.stroke(),this.ctx.fillText(String(r),this.g.cssWidth-8,r)}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(let i of this.selection){let r=this.findWidget(i);r&&r.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){this.rootPanel.title=t?.trim()??""}createWidget(t,e){switch(t){case RP:return new Ie(this,e);case _P:return new Ar(this,e);case TP:return new os(this,e);case SP:return new pr(this,e);case LP:return new dr(this,e);case CP:return new kr(this,e);case AP:return new ur(this,e);case OP:return new gr(this,e);case EP:case MP:return new mr(this,e);case VP:return new Or(this,e);case IP:return new Fr(this,e);case BP:return new ti(this,e);case HP:return new ns(this,e);case DP:return new Er(this,e);case WP:return new fr(this,e);case kP:return new Gr(this,e);case NP:return new Ur(this,e);case FP:return new xr(this,e);case GP:return new Ir(this,e);case $P:return new Yr(this,e);case UP:return new Oe(this,e);case YP:return new yr(this,e);case zP:return new Xr(this,e);case XP:return new Pr(this,e);case qP:return new Br(this,e);case KP:return new Hr(this,e);case jP:return new qr(this,e);case ZP:return new br(this,e);case JP:return new Dr(this,e);case QP:return new Wr(this,e);case tb:return new hs(this,e);case eb:return new vr(this,e);case ib:return new _r(this,e);case rb:return new Tr(this,e);case sb:return new si(this,e);case ob:return new ps(this,e);case nb:return new Kr(this,e);case ab:return new Sr(this,e);case lb:return new jr(this,e);case hb:return new Zr(this,e);case cb:return new Cr(this,e);case pb:return new ds(this,e);case db:return new ss(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){this.instance?.destroy(),this.instance=void 0,this.pvEngine.clearState(),window.clearTimeout(this.stepTimer),this.resizeObserver.disconnect(),this.eventHandler.destroy(),this.rootPanel.remove(),this.targetElement.style.position="",this.targetElement.style.display=""}resolvePath(t,e){let i=this.pathResolver.resolve(t,e);try{return new URL(i,document.baseURI).href}catch{return i}}toRootPath(t){if(this.absPrefix)try{let e=new URL(this.absPrefix,document.baseURI).href,i=new URL(t,document.baseURI).href;if(i.startsWith(e))return"/"+i.substring(e.length).split("/").map(s=>decodeURIComponent(s)).join("/")}catch{}}setSource(t,e){this.reset();let i=t.lastIndexOf("/")+1;return this.relPrefix=t.substring(0,i),new Promise((r,s)=>{fetch(t,{credentials:"same-origin"}).then(o=>{o.ok&&o.text().then(n=>{this.setSourceString(n,e),r()}).catch(n=>s(n))}).catch(o=>s(o))})}setSourceString(t,e){this.reset(),this.instance=new Ae(this,void 0,e);let i=Ce.parseFromXML(t);this.instance.parseNode(i).then(()=>{this.originDesignSize=this.instance.designSize,this.pvEngine.init(),this.requestRepaint();let r={backgroundColor:this.instance.backgroundColor.toString()};this.fireEvent("displayloaded",r)})}getRefreshCycle(){return this.refreshCycle}setRefreshCycle(t){this.refreshCycle=t}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0),this.originDesignSize=void 0,this.wasAutoScaleActive=!1}measureAbsoluteOffset(t){let e=0,i=0,r=t.parent;for(;r;){if(e+=r.x,i+=r.y,r instanceof si){let s=r.measureTabOffset(this.g);e+=s.x,i+=s.y}r=r.parent}return{x:e,y:i}}measureAbsoluteArea(t){let e=t.bounds,i=this.measureAbsoluteOffset(t);return e.x+=i.x,e.y+=i.y,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+=this.scale*1,e.y+=this.scale*1,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(i=>i!==e)}fireEvent(t,e){this.eventListeners[t].forEach(r=>r(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();let 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();let e={scale:t};this.fireEvent("scale",e)}get autoScaleOverride(){return this._autoScaleOverride}set autoScaleOverride(t){this._autoScaleOverride=t,this.requestRepaint()}isAutoScaleActive(){if(!this.instance)return!1;switch(this._autoScaleOverride){case"ENABLED":return!0;case"DISABLED":return!1;case"DEFAULT":return this.instance.autoScaleWidgets.autoScaleWidgets}}measureContainerSize(){let t=this.targetElement.clientWidth,e=this.targetElement.clientHeight;return t&&e?{width:t,height:e}:void 0}applyAutoScale(t){if(!this.instance||!this.originDesignSize)return;this.wasAutoScaleActive=!0;let{width:e,height:i}=this.originDesignSize;if(!e||!i)return;let r=t.width/e,s=t.height/i,{minWidth:o,minHeight:n}=this.instance.autoScaleWidgets,a=o<0?e:o,l=n<0?i:n;e*r<a&&(r=a/e),i*s<l&&(s=l/i),this.instance.autoScale(r,s)}revertAutoScale(){this.instance&&this.wasAutoScaleActive&&this.instance.autoScale(1,1),this.wasAutoScaleActive=!1}get pixelRatio(){return this._pixelRatio}set pixelRatio(t){this._pixelRatio=t,this.pixelRatioOverridden=!0,this.requestRepaint()}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get utc(){return this.formatter.utc}set utc(t){this.formatter.utc=t,this.requestRepaint()}get disconnectedColor(){return this._disconnectedColor}set disconnectedColor(t){this._disconnectedColor=t,this.requestRepaint()}get invalidColor(){return this._invalidColor}set invalidColor(t){this._invalidColor=t,this.requestRepaint()}get majorColor(){return this._majorColor}set majorColor(t){this._majorColor=t,this.requestRepaint()}get minorColor(){return this._minorColor}set minorColor(t){this._minorColor=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.setExternalValues(t)}copyCanvas(t){let e=this.g.pixelRatio,i=t?{x:t.x*e,y:t.y*e,width:t.width*e,height:t.height*e}:{x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height},r=document.createElement("canvas");return r.width=i.width,r.height=i.height,r.getContext("2d").drawImage(this.g.canvas,i.x,i.y,i.width,i.height,0,0,i.width,i.height),r}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}};var gs=class extends fe{nextId=1;pending=new Map;openConfirmDialogAsync(t,e){return this.request({kind:"confirm",title:t,message:e})}openPasswordDialogAsync(t,e,i){return this.request({kind:"password",title:t,message:e,password:i})}receiveResult(t,e){let i=this.pending.get(t);i&&(this.pending.delete(t),i(e))}request(t){let e=this.nextId++;return new Promise(i=>{this.pending.set(e,i),window.parent.postMessage({type:"dialog",id:e,...t},"*")})}};var ms=class{pending=new Map;load(t){return new Promise(e=>{let i=this.pending.get(t);i?i.push(e):(this.pending.set(t,[e]),window.parent.postMessage({type:"loadImage",url:t},"*"))})}receiveData(t,e){let i=this.pending.get(t)??[];this.pending.delete(t);let r=e??t;for(let s of i)s(r)}};var fs=class{cache=new Map;ttl=5e3;pending=new Map;async load(t){this.removeOldEntries();let e=this.cache.get(t);if(e)return e.text;let i=this.pending.get(t);return i?new Promise(r=>i.push(r)):new Promise(r=>{this.pending.set(t,[r]),window.parent.postMessage({type:"loadScript",path:t},"*")})}receiveContent(t,e){e!==null&&this.cache.set(t,{timestamp:Date.now(),text:e});let i=this.pending.get(t);if(i){this.pending.delete(t);for(let r of i)r(e)}}removeOldEntries(){let t=Date.now();this.cache.forEach((e,i)=>{e.timestamp+this.ttl<=t&&this.cache.delete(i)})}};var oi=new Map;function gw(c,t){for(let e of oi.get(c)??[])e.updateSamples(t)}var ws=class{constructor(t,e){this.pvName=t;this.widget=e;let i=oi.get(t)??[],r=i.length>0;i.push(this),oi.set(t,i),r||window.parent.postMessage({type:"historySubscribe",pvName:t},"*")}samples=[];getSamples(){return this.samples}updateSamples(t){this.samples=t,this.widget.requestRepaint()}disconnect(){let t=oi.get(this.pvName)??[],e=t.indexOf(this);e!==-1&&t.splice(e,1),t.length===0&&(oi.delete(this.pvName),window.parent.postMessage({type:"historyUnsubscribe",pvName:this.pvName},"*"))}};var xs=class{canProvide(t){return!0}startProviding(t){window.parent.postMessage({type:"subscribe",pvNames:t.map(e=>e.name)},"*")}stopProviding(t){window.parent.postMessage({type:"unsubscribe",pvNames:t.map(e=>e.name)},"*")}isNavigable(){return!0}writeValue(t,e){window.parent.postMessage({type:"write",pvName:t,value:e},"*")}createHistoricalDataProvider(t,e){return new ws(t,e)}shutdown(){}};var Y=null,ho=null,co=null,po=null;window.addEventListener("message",c=>{if(c.source!==window.parent)return;let t=c.data;if(t?.type)switch(t.type){case"init":{let e=document.getElementById("display");if(!e)break;Y=new us(e),ho=new fs,co=new ms,Y.setImageLoader(co),po=new gs,Y.setDialogHandler(po);let{config:i}=t;i.legacyFontSizing&&(X.LEGACY_FONT_SIZING=!0),Y.disconnectedColor=$e(i.disconnectedColor),Y.invalidColor=$e(i.invalidColor),Y.majorColor=$e(i.majorColor),Y.minorColor=$e(i.minorColor),Y.utc=i.utc,Y.imagesPrefix=t.imagesPrefix,Y.absPrefix=t.absPrefix,Y.relPrefix=t.relPrefix;let r=t.mediaPrefix;if(Y.setFontResolver({resolve(s){let o;if(s.name==="Liberation Sans"?s.bold&&s.italic?o="LiberationSans-BoldItalic.woff2":s.bold?o="LiberationSans-Bold.woff2":s.italic?o="LiberationSans-Italic.woff2":o="LiberationSans-Regular.woff2":s.name==="Liberation Mono"?s.bold&&s.italic?o="LiberationMono-BoldItalic.woff2":s.bold?o="LiberationMono-Bold.woff2":s.italic?o="LiberationMono-Italic.woff2":o="LiberationMono-Regular.woff2":s.name==="Liberation Serif"?s.bold&&s.italic?o="LiberationSerif-BoldItalic.woff2":s.bold?o="LiberationSerif-Bold.woff2":s.italic?o="LiberationSerif-Italic.woff2":o="LiberationSerif-Regular.woff2":s.name==="Arial"?s.bold&&s.italic?o="LiberationSans-BoldItalic.woff2":s.bold?o="LiberationSans-Bold.woff2":s.italic?o="LiberationSans-Italic.woff2":o="LiberationSans-Regular.woff2":s.name==="Times New Roman"?s.bold&&s.italic?o="LiberationSerif-BoldItalic.woff2":s.bold?o="LiberationSerif-Bold.woff2":s.italic?o="LiberationSerif-Italic.woff2":o="LiberationSerif-Regular.woff2":s.name==="Courier New"&&(s.bold&&s.italic?o="LiberationMono-BoldItalic.woff2":s.bold?o="LiberationMono-Bold.woff2":s.italic?o="LiberationMono-Italic.woff2":o="LiberationMono-Regular.woff2"),o){let n=Re[s.name]??s.name;return new FontFace(n,`url(${r}${o})`,{weight:s.bold?"bold":"normal",style:s.italic?"italic":"normal"})}}}),Y.addProvider(new xs),Y.setScriptLoader(ho),Y.addScriptLibrary("Yamcs",{issueCommand(s,o){window.parent.postMessage({type:"runcommand",command:s,args:o??{}},"*")},runProcedure(s,o){let n={};if(o)for(let a of Object.keys(o))n[a]=String(o[a]);window.parent.postMessage({type:"runprocedure",procedure:s,args:n},"*")}}),Y.addEventListener("displayloaded",s=>{window.parent.postMessage({type:"displaybackground",color:s.backgroundColor},"*")}),Y.addEventListener("opendisplay",s=>{window.parent.postMessage({type:"opendisplay",path:s.path,absolutePath:s.absolutePath,replace:s.replace,args:s.args},"*")}),Y.addEventListener("closedisplay",()=>{window.parent.postMessage({type:"closedisplay"},"*")}),Y.addEventListener("openpv",s=>{window.parent.postMessage({type:"openpv",pvName:s.pvName},"*")}),Y.addEventListener("runcommand",s=>{window.parent.postMessage({type:"runcommand",command:s.command,args:s.args},"*")}),Y.addEventListener("runstack",s=>{window.parent.postMessage({type:"runstack",path:s.path,absolutePath:s.absolutePath},"*")}),Y.addEventListener("runprocedure",s=>{window.parent.postMessage({type:"runprocedure",procedure:s.procedure,args:s.args},"*")}),Y.addEventListener("scale",s=>{window.parent.postMessage({type:"scale",scale:s.scale},"*")}),Y.setSourceString(t.xml,t.args),t.zoomMode==="fit"&&Y.instance){let{width:s,height:o}=Y.instance.unscaledBounds;s&&o&&(Y.scale=Math.min(t.containerWidth/s,t.containerHeight/o))}break}case"pvData":{if(!Y)break;for(let[i,r]of Object.entries(t.meta)){let s=Y.getPV(i);s&&(r.labels&&(s.labels=r.labels),s.writable=r.writable)}for(let i of t.disconnected){let r=Y.getPV(i);r&&(r.disconnected=!0)}let e=new Map;for(let[i,r]of Object.entries(t.samples))e.set(i,r);e.size>0&&Y.setValues(e);break}case"scriptContent":{ho?.receiveContent(t.path,t.content);break}case"imageData":{co?.receiveData(t.url,t.dataUrl);break}case"dialogResult":{po?.receiveResult(t.id,t.result);break}case"historySamples":{gw(t.pvName,t.samples);break}case"setScale":{Y&&(Y.scale=t.scale);break}case"fitZoom":{if(Y?.instance){let{width:e,height:i}=Y.instance.unscaledBounds;e&&i&&(Y.scale=Math.min(t.containerWidth/e,t.containerHeight/i))}break}case"setAutoScaleOverride":{Y&&(Y.autoScaleOverride=t.value);break}}});})();