@yamcs/opi 1.3.11 → 1.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/opi.js CHANGED
@@ -1,22 +1,22 @@
1
- function Vu(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}red;green;blue;alpha;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 Pe=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};var ve=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 Rr=p=>(document.removeEventListener("click",Rr,!0),p.preventDefault(),p.stopPropagation(),!1);function _r(p){return(p.buttons&1)===1||p.buttons===void 0&&p.which==1}var xs=5;function Mu(p,t,e,i){return Math.sqrt((e-p)*(e-p)+(i-t)*(i-t))}function ws(p,t){return p&&t&&p.id===t.id}var He=class{constructor(t,e,i){this.display=t;this.canvas=e;this.hitCanvas=i;e.addEventListener("click",r=>this.onCanvasClick(r),!1),e.addEventListener("mousedown",r=>this.onCanvasMouseDown(r),!1),e.addEventListener("mouseup",r=>this.onCanvasMouseUp(r),!1),e.addEventListener("mouseout",r=>this.onCanvasMouseOut(r),!1),e.addEventListener("mousemove",r=>this.onCanvasMouseMove(r),!1)}display;canvas;hitCanvas;grabbing=!1;grabTarget;grabPoint;documentMouseMoveListener=t=>this.onDocumentMouseMove(t);documentMouseUpListener=t=>this.onDocumentMouseUp(t);prevEnteredRegion;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})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",Rr,!0),_r(t))){let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);return i&&i.mouseDown&&i.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),i&&i.grab&&(this.grabPoint={...e},this.grabTarget=i),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){let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(ws(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(ws(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i;let r=i&&i.cursor?i.cursor:"auto";if(r!=this.canvas.style.cursor&&(this.canvas.style.cursor=r),!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&_r(t)){let s=Mu(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(s)>xs&&(this.initiateGrab(),xs>0&&this.grabPoint&&(this.grabPoint=e))}this.grabbing&&this.grabTarget&&_r(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",Rr,!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 ke=class{constructor(t){this.utc=t}utc;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 ys="rgb(255,255,255)",Iu=!!navigator.brave,De=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}parent;ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=ys,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!==ys)return Iu?(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 wt(p,t,e,i,r){return D({x:p,y:t,width:e,height:i},r/2)}function Ct(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 Tr(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 bs(p,t){let e=p.x,i=p.y,r=e+p.width,s=i+p.height;if(r<e){let u=e;e=r,r=u}if(s<i){let u=i;i=s,s=u}let o=t.x,n=t.y,a=o+t.width,l=n+t.height;if(a<o){let u=o;o=a,a=u}if(l<n){let u=n;n=l,l=u}let c=Math.max(e,o),h=Math.max(i,n);return{x:c,y:h,width:Math.min(r,a)-c,height:Math.min(s,l)-h}}function yt(p,t,e){return{x:p.x+t,y:p.y+e}}function Zt(p,t,e){return p.map(i=>yt(i,t,e))}function $(p){return p*Math.PI/180}function bt(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 Ne(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 lt(Math.floor(r),s)}var lt=class{constructor(t,e){this.r=t;this.theta=e}r;theta;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 Nt(p,t){return p.map(e=>({x:e.x*t,y:e.y*t}))}function Ps(p){return p.map(t=>({x:t.x+.5,y:t.y+.5}))}function Fe(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 Ft(p,t,e,i){return p===null?"":typeof p=="string"?i==="BINARY_STRING"?Bu(p):p:typeof p=="number"?e===-1?vs(t,p,void 0,3):vs(t,p,e,e):p instanceof Date?p.toISOString().replace("T"," ").replace("Z",""):String(p)}function Bu(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 vs(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)}}var Ge=class p{constructor(t,e){this.canvas=t;this.ctx=t.getContext("2d"),this.hitCanvas=e||new De,this.hitCtx=this.hitCanvas.ctx}canvas;ctx;hitCanvas;hitCtx;createChild(t,e){let i=this.hitCanvas.createChild(t,e),r=document.createElement("canvas");return r.width=t,r.height=e,new p(r,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,r,s){let{width:o,height:n}=t.canvas,a=o/n,l=r,c=l/a;c>s&&(c=s,l=c*a),this.copyScaled(t,e,i,l,c)}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.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){(this.ctx.canvas.width!=t||this.ctx.canvas.height!=e)&&(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){"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?(Fe(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?(Fe(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?(Fe(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 Cr(this.hitCanvas.ctx)}},_=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}},Cr=class{constructor(t){this.ctx=t}ctx;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 Jt=class{constructor(t,e=[]){this.widget=t;for(let i of e)this.properties.set(i.name,i)}widget;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 Se)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof w)e.value=t.getBoolean(e.name);else if(e instanceof Gt)e.value=t.getColorMap(e.name);else if(e instanceof S)e.value=t.getColor(e.name);else if(e instanceof B)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 $t)e.value=t.getMacros(e.name);else if(e instanceof vt)e.value=t.getPoints(e.name);else if(!(e instanceof Pt))if(e instanceof Te)e.value=t.getRules(e.name);else if(e instanceof Ce)e.value=t.getScaleOptions(e.name);else if(e instanceof Re)e.value=t.getScripts(e.name);else if(e instanceof R)e.rawValue=t.getString(e.name);else if(e instanceof _t)e.value=t.getStringList(e.name);else if(e instanceof Ut)e.value=t.getStringMap(e.name);else if(e instanceof Qt)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 R){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}},Z=class{constructor(t,e){this.name=t;this.defaultValue=e;this.value=e}name;defaultValue;_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)}},R=class extends Z{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},Pt=class extends Z{constructor(e,i){super(e);this.pvPropertyName=i}pvPropertyName},P=class extends Z{},B=class extends Z{},w=class extends Z{},S=class extends Z{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},H=class extends Z{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},Gt=class extends Z{printScriptValue(t){return`${t.code}`}},vt=class extends Z{},_e=class extends Z{},$t=class extends Z{},Re=class extends Z{},_t=class extends Z{},Ut=class extends Z{},Qt=class extends Z{},Te=class extends Z{},Ce=class extends Z{},Se=class extends Z{};var te=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?String(this.actions[0]):`${this.actions.length} actions`}};var _s="description",K=class{properties;constructor(){this.properties=new Jt(null,[new R(_s,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(_s)}};var Rs="command",Ts="command_directory",Cs="wait_time",$e=class extends K{constructor(){super(),this.properties.add(new R(Rs,"")),this.properties.add(new R(Ts,"$(user.home)")),this.properties.add(new P(Cs,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(Rs)}get commandDirectory(){return this.properties.getValue(Ts)}get waitTime(){return this.properties.getValue(Cs)}toString(){return`Execute Command ${this.command}`}};var Hu=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],q=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=Math.ceil(e*4/3)}name;style;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 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 Hu.indexOf(this.name)!==-1}};var Ue=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 q(t,e,i,!1)}};var Ye=class{constructor(t){this.display=t}display;writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}};var Xe=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var ze=class{constructor(t,e){this.spreadsheet=t;this.scriptEngine=e}spreadsheet;scriptEngine;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 Yt=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]]))}code;interpolate;autoscale;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]),c=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,c]}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 qe=class{constructor(t,e){this.action=t;this.widget=e}action;widget;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 R?(e=e!==void 0?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}};var Ke=class{constructor(t){this.array=t}array;get(t){return this.array[t]}};var St=class{constructor(t){this._pv=t}_pv;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){this._pv.addListener(()=>{t.valueChanged(this)})}removeListener(t){this._pv.removeListener(t)}};var Lt=class{constructor(t){this.widget=t}widget;executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){let e=this.widget.display.getPV(t);return e?new St(e):null}getPV(t="pv_name"){let e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getHookedActions(){let t=this.widget.getHookedActions().map(e=>new qe(e,this.widget));return new Ke(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 R)e=e!==void 0?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof Gt){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 Yt(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 je=class extends Lt{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new ze(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var Ze=class extends Lt{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 Je(p,t){switch(p.widgetType){case"Table":return new je(p,t);case"XY Graph":return new Ze(p);default:return new Lt(p)}}var Qe=class{constructor(t,e){this.display=t;this.scriptEngine=e}display;scriptEngine;isActive(){return!0}getWidget(t){let e=this.display.findWidgetByName(t);if(e)return Je(e,this.scriptEngine)}};var ti=class{constructor(t){this.display=t}display;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 ei=class{constructor(t){this.display=t}display;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 ii=class{constructor(t){this.display=t}display;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 Xt=class{constructor(t,e){this.name=t;this.pvEngine=e}name;pvEngine;_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.addListener(this.name,t)}toString(){if(this.value!==void 0)return String(this.value)}},ee=(s=>(s.NONE="NONE",s.MINOR="MINOR",s.MAJOR="MAJOR",s.INVALID="INVALID",s.UNDEFINED="UNDEFINED",s))(ee||{});var ku=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],ri=class{constructor(t){this.display=t;this.pvEngine=t.pvEngine}display;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 St(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),Ft(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 ku)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 si=class{constructor(t){this.display=t}display;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 Ss(p){let t=p.widget,e=p.widget.display,i=function(c){this.run=c.run},r=function(c){this.runnable=c};r.prototype.start=function(){p.schedule(()=>this.runnable.run())},r.sleep=function(c){let h=Date.now(),u=0;for(;Date.now()<h+c;)u++;u||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(c,h){p.schedule(c,h)};let o=function(c){this.valueChanged=h=>{p.schedule(()=>{let u=c.valueChanged;u(h)})}},l={ITableModifiedListener:function(c){this.modified=h=>{let u=c.modified;u(h)}},ITableSelectionChangedListener:function(c){this.selectionChanged=h=>{let u=c.selectionChanged;u(h)}}};return{display:new Qe(t.display,p),widget:Je(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 Ue,ConsoleUtil:new Ye(e),DataUtil:new Xe,FileUtil:new ti(e),GUIUtil:new ei(e),MessageDialog:new ii(e),PVUtil:new ri(e),ScriptUtil:new si(e),SpreadSheetTable:l,Java:{type:function(c){switch(c){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: "+c)}},to:function(c,h){return c}}}}var zt,rt,oi;function Du(){zt=document.createElement("iframe"),zt.id="script-e",zt.style.display="none",document.body.appendChild(zt),rt=zt.contentWindow,oi=rt.eval,!oi&&rt.execScript&&(rt.execScript.call(rt,"null"),oi=rt.eval)}var At=class{constructor(t,e,i=[]){this.widget=t;this.scriptText=e;zt||Du(),this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context={pvs:i.map(r=>new St(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...Ss(this)}}widget;scriptText;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(()=>{oi.call(rt,this.scriptText)})})}schedule(t,e){window.setTimeout(()=>this.runWithContext(t),e)}runWithContext(t){let e=[];for(let i in zt.contentWindow)e.push(i);try{for(let r in this.context)this.context.hasOwnProperty(r)&&(rt[r]=this.context[r]);t();let i={};for(let r in rt)e.indexOf(r)===-1&&(i[r]=rt[r]);this.context=i}finally{for(let i in rt)e.indexOf(i)===-1&&delete rt[i]}}};var Ls="path",As="embedded",Es="scriptText",ni=class extends K{constructor(){super(),this.properties.add(new R(Ls,"")),this.properties.add(new w(As,!1)),this.properties.add(new R(Es,""))}execute(t){this.embedded?new At(t,this.scriptText).run():t.display.getScriptLoader().load(this.path).then(i=>{i&&new At(t.display.instance,i).run()})}get path(){return this.properties.getValue(Ls)}get embedded(){return this.properties.getValue(As)}get scriptText(){return this.properties.getValue(Es)}toString(){return"Execute JavaScript"}};var Os="macros",Vs="mode",Ms="path",ai=class extends K{constructor(){super(),this.properties.add(new R(Ms,"")),this.properties.add(new $t(Os)),this.properties.add(new P(Vs,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(Os)}get path(){return this.properties.getValue(Ms)}get mode(){return this.properties.getValue(Vs)}toString(){return`Open ${this.path}`}};var Is="path",li=class extends K{constructor(){super(),this.properties.add(new R(Is,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Is)}toString(){return`Open ${this.path}`}};var Bs="hyperlink",hi=class extends K{constructor(){super(),this.properties.add(new R(Bs,"http://"))}execute(t){this.hyperlink&&(window.location.href=this.hyperlink)}get hyperlink(){return this.properties.getValue(Bs)}toString(){return`Open Webpage ${this.hyperlink}`}};var Ws="path",ci=class extends K{constructor(){super(),this.properties.add(new R(Ws,""))}execute(t){this.path&&new Audio(t.display.resolvePath(this.path)).play()}get path(){return this.properties.getValue(Ws)}toString(){return`Play WAV File ${this.path}`}};var Hs="command",ks="args",Ds="confirm_message",pi=class extends K{constructor(){super(),this.properties.add(new R(Hs,"")),this.properties.add(new Ut(ks,{})),this.properties.add(new R(Ds,""))}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(Hs)}get args(){return this.properties.getValue(ks)}get confirmMessage(){return this.properties.getValue(Ds)}toString(){return`Run ${this.command}`}};var Ns="procedure",Fs="args",Gs="confirm_message",di=class extends K{constructor(){super(),this.properties.add(new R(Ns,"")),this.properties.add(new Ut(Fs,{})),this.properties.add(new R(Gs,""))}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(Ns)}get args(){return this.properties.getValue(Fs)}get confirmMessage(){return this.properties.getValue(Gs)}toString(){return`Run ${this.procedure}`}};var $s="path",Us="confirm_message",ui=class extends K{constructor(){super(),this.properties.add(new R($s,"")),this.properties.add(new R(Us,""))}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($s)}get confirmMessage(){return this.properties.getValue(Us)}toString(){return`Run ${this.path}`}};var Ys="pv_name",Xs="value",zs="timeout",qs="confirm_message",gi=class extends K{constructor(){super(),this.properties.add(new R(Ys,"$(pv_name)")),this.properties.add(new R(Xs,"")),this.properties.add(new P(zs,10)),this.properties.add(new R(qs,""))}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(Ys)}get value(){return this.properties.getValue(Xs)}get timeout(){return this.properties.getValue(zs)}get confirmMessage(){return this.properties.getValue(qs)}toString(){return`Write ${this.value} to ${this.pvName}`}};var mi=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 ie=class{rules=[]};var fi=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}autoScaleWidgets;minWidth;minHeight},xi=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}widthScalable;heightScalable;keepWidthHeightRatio};var wi=class{scripts=[]};var re=class p{constructor(t){this.node=t}node;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 q(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 q(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}getScripts(t){let e=this.getNode(t),i=new wi;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 xi(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new fi(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 Yt(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 Yt(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"))}getRules(t){let e=this.getNode(t),i=new ie;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")){let a=n.getNode("value");a.hasNode("color")?o.push({type:"color",expression:n.getStringAttribute("bool_exp"),outputValue:n.getColor("value")}):a.hasAttribute("bool_exp")&&o.push({type:"string",expression:n.getStringAttribute("bool_exp"),outputValue:n.getString("value")})}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 mi;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 te;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 ai;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new li;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new $e;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 gi;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new ci;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new hi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new pi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new ui;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new di;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)}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 Ks="actions",js="background_color",Zs="backcolor_alarm_sensitive",Js="border_alarm_sensitive",Qs="border_color",to="border_width",eo="border_style",io="enabled",ro="foreground_color",so="forecolor_alarm_sensitive",Sr="height",oo="name",Lr="pv_name",no="pv_value",ao="rules",lo="scale_options",ho="scripts",Ar="text",co="tooltip",po="transparent",uo="visible",go="widget_type",Er="width",mo="wuid",Or="x",Vr="y",V=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new Jt(this,[new _e(Ks,new te),new w(Zs,!1),new S(js,m.TRANSPARENT),new w(Js,!1),new S(Qs),new P(eo),new P(to),new w(io,!0),new w(so,!1),new S(ro),new P(Sr),new R(oo),new R(Lr),new Pt(no,Lr),new Te(ao,new ie),new Re(ho),new R(Ar,""),new R(co,""),new w(po,!1),new w(uo),new R(go),new P(Er),new R(mo),new P(Or),new P(Vr),new Ce(lo)])}display;parent;x=0;y=0;width=0;height=0;_value;fillRoundRectangleBackgroundBorder=!0;customSize;customHolderWidth;customHolderHeight;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)}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)this.properties.getProperty(e.propertyName)?this.display.pvEngine.createRule(this,e):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:q.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,q.ARIAL_11.scale(e)),r=1,s=wt(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:q.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=wt(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=wt(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(Or),y:this.properties.getValue(Vr),width:this.properties.getValue(Er),height:this.properties.getValue(Sr)}}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,c=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new _(c,l).lineTo(c,n).moveTo(c,l).lineTo(a,l)}),t.strokePath({color:i,path:new _(c-o,l-o).lineTo(c-o,n+o).moveTo(c-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new _(a,n).lineTo(c-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new _(a+o,n+o).lineTo(c-o-o,n+o).moveTo(a+o,n+o).lineTo(a+o,l-o-o)})}drawDashedBorder(t,e){let i=wt(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){t.execute(this)}expandMacro(t){if(t.indexOf("$")===-1)return t;for(let e of this.properties.all())if(e instanceof Pt){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),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(mo)}get name(){return this.properties.getValue(oo)}get holderX(){return this.scale*this.properties.getValue(Or)}get holderY(){return this.scale*this.properties.getValue(Vr)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(Er)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(Sr)}get borderAlarmSensitive(){return this.properties.getValue(Js)}get backgroundAlarmSensitive(){return this.properties.getValue(Zs)}get foregroundAlarmSensitive(){return this.properties.getValue(so)}get pvName(){return this.properties.getValue(Lr,!0)}get pvValue(){return this.properties.getValue(no,!0)}get borderColor(){return this.properties.getValue(Qs)}get borderStyle(){return this.properties.getValue(eo)}get borderWidth(){return this.scale*this.properties.getValue(to)}get backgroundColor(){return this.properties.getValue(js)}get enabled(){return this.properties.getValue(io)}get foregroundColor(){return this.properties.getValue(ro)}get tooltip(){let t=this.properties.getProperty(co);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(po)}get visible(){return this.properties.getValue(uo)}get actions(){return this.properties.getValue(Ks)}get scripts(){return this.properties.getValue(ho)}get rules(){return this.properties.getValue(ao)}get scaleOptions(){return this.properties.getValue(lo)}get widgetType(){return this.properties.getValue(go,!0)}get text(){return this.display.editMode?(this.properties.getProperty(Ar).rawValue||"").split(" ").join("\xA0"):this.properties.getValue(Ar).split(" ").join("\xA0")}init(){}hide(){}destroy(){}};var fo="macros",gt=class p extends V{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new $t(fo))}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()}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(fo)}};var xo="arrow_length",wo="arrows",yo="fill_arrow",bo="name",Po="line_color",vo="line_style",_o="line_width",Ro="src_wuid",To="src_term",Co="tgt_wuid",So="tgt_term",Lo="router",Ao="points",Nu="wuid",Et="LEFT",Ot="UP",Vt="DOWN",Mt="RIGHT",yi=class extends V{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(xo)),this.properties.add(new P(wo)),this.properties.add(new w(yo)),this.properties.add(new R(bo)),this.properties.add(new S(Po)),this.properties.add(new P(vo)),this.properties.add(new P(_o)),this.properties.add(new R(Ro)),this.properties.add(new R(To)),this.properties.add(new R(Co)),this.properties.add(new R(So)),this.properties.add(new P(Lo)),this.properties.add(new vt(Ao)),this.properties.add(new R(Nu))}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=_.fromPoints(r).translate(.5*this.scale,.5*this.scale);t.strokePath({path:s,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,r[1],r[0]),this.drawStopArrow(t,r[r.length-2],r[r.length-1])}drawManhattanConnection(t){let e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),r=this.route(e,i),s=_.fromPoints(r);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:s,dash:this.getDashArray()}),this.drawStartArrow(t,r[r.length-2],r[r.length-1]),this.drawStopArrow(t,r[1],r[0])}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}`)}}drawDirectConnection(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new _(e.x,e.y).lineTo(i.x,i.y),lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,i,e),this.drawStopArrow(t,e,i)}getManhattanAnchor(t,e){let i;switch(e){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":i=Ot;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=Vt;break;case"LEFT":i=Et;break;case"RIGHT":i=Mt;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?Et:Mt:i=a<l?Ot:Vt,{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=Nt(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:c,minDist:h}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===Et?i>0&&r*r<c&&e.direction===Mt?(s=e,o=e.direction):(i<0?s={x:t.x-h,y:t.y}:r>0&&e.direction===Vt||r<0&&e.direction===Ot?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.min(t.x,e.x)-h,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=Ot:o=Vt):t.direction===Mt?i<0&&r*r<c&&e.direction===Et?(s=e,o=e.direction):(i>0?s={x:t.x+h,y:t.y}:r>0&&e.direction===Vt||r<0&&e.direction===Ot?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.max(t.x,e.x)+h,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=Ot:o=Vt):t.direction===Vt?i*i<c&&r<0&&e.direction===Ot?(s=e,o=e.direction):(r>0?s={x:t.x,y:t.y+h}:i>0&&e.direction===Mt||i<0&&e.direction===Et?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.max(t.y,e.y)+h,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Et:o=Mt):t.direction===Ot&&(i*i<c&&r>0&&e.direction===Vt?(s=e,o=e.direction):(r<0?s={x:t.x,y:t.y-h}:i>0&&e.direction===Mt||i<0&&e.direction===Et?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.min(t.y,e.y)-h,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=Et:o=Mt));let u={...s,direction:o};return a=a.concat(this.route(u,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=Ne(e,t),r=Math.PI/10,s=new lt(this.arrowLength,i.theta-r),o=new lt(this.arrowLength,i.theta+r),n=new lt(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=yt(s.toPoint(),e.x,e.y),l=yt(o.toPoint(),e.x,e.y),c=yt(n.toPoint(),e.x,e.y);return[a,l,c]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(bo)}get arrows(){return this.properties.getValue(wo)}get fillArrow(){return this.properties.getValue(yo)}get arrowLength(){return this.scale*this.properties.getValue(xo)}get lineColor(){return this.properties.getValue(Po)}get lineStyle(){return this.properties.getValue(vo)}get lineWidth(){return this.scale*this.properties.getValue(_o)}get router(){return this.properties.getValue(Lo)}get sourceTerm(){return this.properties.getValue(To)}get sourceWuid(){return this.properties.getValue(Ro)}get targetTerm(){return this.properties.getValue(So)}get targetWuid(){return this.properties.getValue(Co)}get points(){return Nt(this.properties.getValue(Ao),this.scale)}};var Fu=0,Eo="auto_scale_widgets",se=class extends gt{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new Se(Eo))}async parseNode(t){await super.parseNode(t);let e=Fu++;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))}for(let r of t.getNodes("connection")){let s=new yi(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(Eo)}};var Gu=0,Oo="group_name",Vo="opi_file",Mo="resize_behaviour",oe=class extends gt{linkedDisplay;resolvedOpiFile;constructor(t,e){super(t,e),this.properties.add(new R(Oo)),this.properties.add(new R(Vo)),this.properties.add(new P(Mo,0))}async parseNode(t){await super.parseNode(t);let e=Gu++;this.macros.set("LCID",`LCID_${e}`)}async init(){if(this.opiFile){this.resolvedOpiFile=this.display.resolvePath(this.opiFile);let t=await fetch(this.resolvedOpiFile,{credentials:"same-origin"});if(t.ok){let e=await t.text();this.linkedDisplay=new se(this.display,this);let i=re.parseFromXML(e);await this.linkedDisplay.parseNode(i),this.requestRepaint()}}if(this.linkedDisplay&&this.resizeBehavior===1){let t=this.linkedDisplay.measureContentBounds(!0);this.customSize={width:t.width,height:t.height}}}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.linkedDisplay.measureContentBounds(!1),{width:r,height:s}=i,o=this.display.scale;r*=o,s*=o;let n=r/s,a=this.width,l=a/n,c=a/r;l>this.height&&(l=this.height,a=l*n,c=l/r),this.linkedDisplay.relativeScale=c;let h=t.createChild(Math.ceil(a),Math.ceil(l));h.translate(i.x,i.y),this.linkedDisplay.draw(h),t.copy(h,this.x,this.y)}else if(this.resizeBehavior===1){let i=this.linkedDisplay.measureContentBounds(!0),r=t.createChild(i.width,i.height);r.translate(-i.x,-i.y),this.linkedDisplay.draw(r),t.copy(r,this.x,this.y)}else if(this.resizeBehavior===2){let i=this.linkedDisplay.measureContentBounds(!0),r=t.createChild(i.width,i.height);r.translate(i.x,i.y),this.linkedDisplay.draw(r),t.copy(r,this.x,this.y)}else this.resizeBehavior===3&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&this.groupName!==""?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(Vo)}get groupName(){return this.properties.getValue(Oo)}get resizeBehavior(){return this.properties.getValue(Mo)}};var Le=class{constructor(t){this.display=t}display;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 oe){let r=i.resolvedOpiFile,s=r.lastIndexOf("/")+1;return`${r.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}};var bi=class{constructor(t){this.display=t}display;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 Ae=class{constructor(t,e){this.pvName=t;this.formula=e}pvName;formula;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 Ee=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," "),c=i[s.line-1],u=(s.line===a.line?a.column:c.length+1)-s.column||1;e+=`
1
+ function Bu(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}red;green;blue;alpha;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 ye=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};var be=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 Tr=p=>(document.removeEventListener("click",Tr,!0),p.preventDefault(),p.stopPropagation(),!1);function Rr(p){return(p.buttons&1)===1||p.buttons===void 0&&p.which==1}var Ps=5;function Wu(p,t,e,i){return Math.sqrt((e-p)*(e-p)+(i-t)*(i-t))}function vs(p,t){return p&&t&&p.id===t.id}var We=class{constructor(t,e,i){this.display=t;this.canvas=e;this.hitCanvas=i;e.addEventListener("click",r=>this.onCanvasClick(r),!1),e.addEventListener("mousedown",r=>this.onCanvasMouseDown(r),!1),e.addEventListener("mouseup",r=>this.onCanvasMouseUp(r),!1),e.addEventListener("mouseout",r=>this.onCanvasMouseOut(r),!1),e.addEventListener("mousemove",r=>this.onCanvasMouseMove(r),!1)}display;canvas;hitCanvas;grabbing=!1;grabTarget;grabPoint;documentMouseMoveListener=t=>this.onDocumentMouseMove(t);documentMouseUpListener=t=>this.onDocumentMouseUp(t);prevEnteredRegion;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})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",Tr,!0),Rr(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){let e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(vs(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(vs(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i;let r=i&&i.cursor?i.cursor:"auto";if(r!=this.canvas.style.cursor&&(this.canvas.style.cursor=r),!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&Rr(t)){let s=Wu(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(s)>Ps&&(this.initiateGrab(),Ps>0&&this.grabPoint&&(this.grabPoint=e))}this.grabbing&&this.grabTarget&&Rr(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",Tr,!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 He=class{constructor(t){this.utc=t}utc;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 _s="rgb(255,255,255)",Hu=!!navigator.brave,ke=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}parent;ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=_s,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!==_s)return Hu?(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 xt(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 Cr(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 Rs(p,t){let e=p.x,i=p.y,r=e+p.width,s=i+p.height;if(r<e){let u=e;e=r,r=u}if(s<i){let u=i;i=s,s=u}let o=t.x,n=t.y,a=o+t.width,l=n+t.height;if(a<o){let u=o;o=a,a=u}if(l<n){let u=n;n=l,l=u}let c=Math.max(e,o),h=Math.max(i,n);return{x:c,y:h,width:Math.min(r,a)-c,height:Math.min(s,l)-h}}function wt(p,t,e){return{x:p.x+t,y:p.y+e}}function Kt(p,t,e){return p.map(i=>wt(i,t,e))}function $(p){return p*Math.PI/180}function yt(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 De(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 at(Math.floor(r),s)}var at=class{constructor(t,e){this.r=t;this.theta=e}r;theta;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 Dt(p,t){return p.map(e=>({x:e.x*t,y:e.y*t}))}function Ne(p){return p.map(t=>({x:t.x+.5,y:t.y+.5}))}function Fe(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 Nt(p,t,e,i){return p===null?"":typeof p=="string"?i==="BINARY_STRING"?ku(p):p:typeof p=="number"?e===-1?Ts(t,p,void 0,3):Ts(t,p,e,e):p instanceof Date?p.toISOString().replace("T"," ").replace("Z",""):String(p)}function ku(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 Ts(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)}}var Ge=class p{constructor(t,e){this.canvas=t;this.ctx=t.getContext("2d"),this.hitCanvas=e||new ke,this.hitCtx=this.hitCanvas.ctx}canvas;ctx;hitCanvas;hitCtx;createChild(t,e){let i=this.hitCanvas.createChild(t,e),r=document.createElement("canvas");return r.width=t,r.height=e,new p(r,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,r,s){let{width:o,height:n}=t.canvas,a=o/n,l=r,c=l/a;c>s&&(c=s,l=c*a),this.copyScaled(t,e,i,l,c)}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.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){(this.ctx.canvas.width!=t||this.ctx.canvas.height!=e)&&(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){"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?(Fe(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?(Fe(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?(Fe(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 Sr(this.hitCanvas.ctx)}},_=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}},Sr=class{constructor(t){this.ctx=t}ctx;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 Pe=class{load(t){return Promise.resolve(t)}};var jt=class{constructor(t,e=[]){this.widget=t;for(let i of e)this.properties.set(i.name,i)}widget;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 ve)e.value=t.getActions(e.name);else if(e instanceof Ce)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof w)e.value=t.getBoolean(e.name);else if(e instanceof Ft)e.value=t.getColorMap(e.name);else if(e instanceof S)e.value=t.getColor(e.name);else if(e instanceof B)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 Gt)e.value=t.getMacros(e.name);else if(e instanceof Pt)e.value=t.getPoints(e.name);else if(!(e instanceof bt))if(e instanceof Re)e.value=t.getRules(e.name);else if(e instanceof Te)e.value=t.getScaleOptions(e.name);else if(e instanceof _e)e.value=t.getScripts(e.name);else if(e instanceof R)e.rawValue=t.getString(e.name);else if(e instanceof vt)e.value=t.getStringList(e.name);else if(e instanceof $t)e.value=t.getStringMap(e.name);else if(e instanceof Zt)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 R){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}},Z=class{constructor(t,e){this.name=t;this.defaultValue=e;this.value=e}name;defaultValue;_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)}},R=class extends Z{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},bt=class extends Z{constructor(e,i){super(e);this.pvPropertyName=i}pvPropertyName},P=class extends Z{},B=class extends Z{},w=class extends Z{},S=class extends Z{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},H=class extends Z{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},Ft=class extends Z{printScriptValue(t){return`${t.code}`}},Pt=class extends Z{},ve=class extends Z{},Gt=class extends Z{},_e=class extends Z{},vt=class extends Z{},$t=class extends Z{},Zt=class extends Z{},Re=class extends Z{},Te=class extends Z{},Ce=class extends Z{};var Jt=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?String(this.actions[0]):`${this.actions.length} actions`}};var Cs="description",K=class{properties;constructor(){this.properties=new jt(null,[new R(Cs,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(Cs)}};var Ss="command",Ls="command_directory",As="wait_time",$e=class extends K{constructor(){super(),this.properties.add(new R(Ss,"")),this.properties.add(new R(Ls,"$(user.home)")),this.properties.add(new P(As,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(Ss)}get commandDirectory(){return this.properties.getValue(Ls)}get waitTime(){return this.properties.getValue(As)}toString(){return`Execute Command ${this.command}`}};var Nu=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],q=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=Math.ceil(e*4/3)}name;style;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 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 Nu.indexOf(this.name)!==-1}};var Ue=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 q(t,e,i,!1)}};var Ye=class{constructor(t){this.display=t}display;writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}};var Xe=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var ze=class{constructor(t,e){this.spreadsheet=t;this.scriptEngine=e}spreadsheet;scriptEngine;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 Ut=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]]))}code;interpolate;autoscale;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]),c=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,c]}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 qe=class{constructor(t,e){this.action=t;this.widget=e}action;widget;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 R?(e=e!==void 0?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}};var Ke=class{constructor(t){this.array=t}array;get(t){return this.array[t]}};var Ct=class{constructor(t){this._pv=t}_pv;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){this._pv.addListener(()=>{t.valueChanged(this)})}removeListener(t){this._pv.removeListener(t)}};var St=class{constructor(t){this.widget=t}widget;executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){let e=this.widget.display.getPV(t);return e?new Ct(e):null}getPV(t="pv_name"){let e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getHookedActions(){let t=this.widget.getHookedActions().map(e=>new qe(e,this.widget));return new Ke(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 R)e=e!==void 0?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof Ft){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 Ut(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 je=class extends St{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new ze(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var Ze=class extends St{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 Je(p,t){switch(p.widgetType){case"Table":return new je(p,t);case"XY Graph":return new Ze(p);default:return new St(p)}}var Qe=class{constructor(t,e){this.display=t;this.scriptEngine=e}display;scriptEngine;isActive(){return!0}getWidget(t){let e=this.display.findWidgetByName(t);if(e)return Je(e,this.scriptEngine)}};var ti=class{constructor(t){this.display=t}display;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 ei=class{constructor(t){this.display=t}display;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 ii=class{constructor(t){this.display=t}display;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 Yt=class{constructor(t,e){this.name=t;this.pvEngine=e}name;pvEngine;_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.addListener(this.name,t)}toString(){if(this.value!==void 0)return String(this.value)}},Qt=(s=>(s.NONE="NONE",s.MINOR="MINOR",s.MAJOR="MAJOR",s.INVALID="INVALID",s.UNDEFINED="UNDEFINED",s))(Qt||{});var Fu=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],ri=class{constructor(t){this.display=t;this.pvEngine=t.pvEngine}display;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 Ct(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),Nt(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 Fu)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 si=class{constructor(t){this.display=t}display;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 Es(p){let t=p.widget,e=p.widget.display,i=function(c){this.run=c.run},r=function(c){this.runnable=c};r.prototype.start=function(){p.schedule(()=>this.runnable.run())},r.sleep=function(c){let h=Date.now(),u=0;for(;Date.now()<h+c;)u++;u||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(c,h){p.schedule(c,h)};let o=function(c){this.valueChanged=h=>{p.schedule(()=>{let u=c.valueChanged;u(h)})}},l={ITableModifiedListener:function(c){this.modified=h=>{let u=c.modified;u(h)}},ITableSelectionChangedListener:function(c){this.selectionChanged=h=>{let u=c.selectionChanged;u(h)}}};return{display:new Qe(t.display,p),widget:Je(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 Ue,ConsoleUtil:new Ye(e),DataUtil:new Xe,FileUtil:new ti(e),GUIUtil:new ei(e),MessageDialog:new ii(e),PVUtil:new ri(e),ScriptUtil:new si(e),SpreadSheetTable:l,Java:{type:function(c){switch(c){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: "+c)}},to:function(c,h){return c}}}}var Lt=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 Ct(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...Es(this)}}widget;scriptText;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 Os="path",Vs="embedded",Ms="scriptText",oi=class extends K{constructor(){super(),this.properties.add(new R(Os,"")),this.properties.add(new w(Vs,!1)),this.properties.add(new R(Ms,""))}execute(t){this.embedded?new Lt(t,this.scriptText).run():t.display.getScriptLoader().load(this.path).then(i=>{i&&new Lt(t.display.instance,i).run()})}get path(){return this.properties.getValue(Os)}get embedded(){return this.properties.getValue(Vs)}get scriptText(){return this.properties.getValue(Ms)}toString(){return"Execute JavaScript"}};var Is="macros",Bs="mode",Ws="path",ni=class extends K{constructor(){super(),this.properties.add(new R(Ws,"")),this.properties.add(new Gt(Is)),this.properties.add(new P(Bs,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(Is)}get path(){return this.properties.getValue(Ws)}get mode(){return this.properties.getValue(Bs)}toString(){return`Open ${this.path}`}};var Hs="path",ai=class extends K{constructor(){super(),this.properties.add(new R(Hs,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Hs)}toString(){return`Open ${this.path}`}};var ks="hyperlink",li=class extends K{constructor(){super(),this.properties.add(new R(ks,"http://"))}execute(t){this.hyperlink&&window.parent.postMessage({type:"openwebpage",url:this.hyperlink},"*")}get hyperlink(){return this.properties.getValue(ks)}toString(){return`Open Webpage ${this.hyperlink}`}};var Ds="path",hi=class extends K{constructor(){super(),this.properties.add(new R(Ds,""))}execute(t){this.path&&new Audio(t.display.resolvePath(this.path)).play()}get path(){return this.properties.getValue(Ds)}toString(){return`Play WAV File ${this.path}`}};var Ns="command",Fs="args",Gs="confirm_message",ci=class extends K{constructor(){super(),this.properties.add(new R(Ns,"")),this.properties.add(new $t(Fs,{})),this.properties.add(new R(Gs,""))}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(Ns)}get args(){return this.properties.getValue(Fs)}get confirmMessage(){return this.properties.getValue(Gs)}toString(){return`Run ${this.command}`}};var $s="procedure",Us="args",Ys="confirm_message",pi=class extends K{constructor(){super(),this.properties.add(new R($s,"")),this.properties.add(new $t(Us,{})),this.properties.add(new R(Ys,""))}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($s)}get args(){return this.properties.getValue(Us)}get confirmMessage(){return this.properties.getValue(Ys)}toString(){return`Run ${this.procedure}`}};var Xs="path",zs="confirm_message",di=class extends K{constructor(){super(),this.properties.add(new R(Xs,"")),this.properties.add(new R(zs,""))}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(Xs)}get confirmMessage(){return this.properties.getValue(zs)}toString(){return`Run ${this.path}`}};var qs="pv_name",Ks="value",js="timeout",Zs="confirm_message",ui=class extends K{constructor(){super(),this.properties.add(new R(qs,"$(pv_name)")),this.properties.add(new R(Ks,"")),this.properties.add(new P(js,10)),this.properties.add(new R(Zs,""))}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(qs)}get value(){return this.properties.getValue(Ks)}get timeout(){return this.properties.getValue(js)}get confirmMessage(){return this.properties.getValue(Zs)}toString(){return`Write ${this.value} to ${this.pvName}`}};var gi=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{rules=[]};var mi=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}autoScaleWidgets;minWidth;minHeight},fi=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}widthScalable;heightScalable;keepWidthHeightRatio};var xi=class{scripts=[]};var ee=class p{constructor(t){this.node=t}node;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 q(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 q(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}getScripts(t){let e=this.getNode(t),i=new xi;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 fi(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new mi(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 Ut(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 Ut(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 gi;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 Jt;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 ni;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new ai;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new $e;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_JAVASCRIPT"){let o=new oi;o.parseNode(r),i.add(o)}else if(s==="WRITE_PV"){let o=new ui;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new hi;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new li;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new ci;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new di;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new pi;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)}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 Js="actions",Qs="background_color",to="backcolor_alarm_sensitive",eo="border_alarm_sensitive",io="border_color",ro="border_width",so="border_style",oo="enabled",no="foreground_color",ao="forecolor_alarm_sensitive",Lr="height",lo="name",Ar="pv_name",ho="pv_value",co="rules",po="scale_options",uo="scripts",Er="text",go="tooltip",mo="transparent",fo="visible",xo="widget_type",Or="width",wo="wuid",Vr="x",Mr="y",V=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new jt(this,[new ve(Js,new Jt),new w(to,!1),new S(Qs,m.TRANSPARENT),new w(eo,!1),new S(io),new P(so),new P(ro),new w(oo,!0),new w(ao,!1),new S(no),new P(Lr),new R(lo),new R(Ar),new bt(ho,Ar),new Re(co,new te),new _e(uo),new R(Er,""),new R(go,""),new w(mo,!1),new w(fo),new R(xo),new P(Or),new R(wo),new P(Vr),new P(Mr),new Te(po)])}display;parent;x=0;y=0;width=0;height=0;_value;fillRoundRectangleBackgroundBorder=!0;customSize;customHolderWidth;customHolderHeight;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)}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)this.properties.getProperty(e.propertyName)?this.display.pvEngine.createRule(this,e):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:q.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,q.ARIAL_11.scale(e)),r=1,s=xt(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:q.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=xt(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=xt(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(Vr),y:this.properties.getValue(Mr),width:this.properties.getValue(Or),height:this.properties.getValue(Lr)}}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,c=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new _(c,l).lineTo(c,n).moveTo(c,l).lineTo(a,l)}),t.strokePath({color:i,path:new _(c-o,l-o).lineTo(c-o,n+o).moveTo(c-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new _(a,n).lineTo(c-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new _(a+o,n+o).lineTo(c-o-o,n+o).moveTo(a+o,n+o).lineTo(a+o,l-o-o)})}drawDashedBorder(t,e){let i=xt(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){t.execute(this)}expandMacro(t){if(t.indexOf("$")===-1)return t;for(let e of this.properties.all())if(e instanceof bt){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),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(wo)}get name(){return this.properties.getValue(lo)}get holderX(){return this.scale*this.properties.getValue(Vr)}get holderY(){return this.scale*this.properties.getValue(Mr)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(Or)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(Lr)}get borderAlarmSensitive(){return this.properties.getValue(eo)}get backgroundAlarmSensitive(){return this.properties.getValue(to)}get foregroundAlarmSensitive(){return this.properties.getValue(ao)}get pvName(){return this.properties.getValue(Ar,!0)}get pvValue(){return this.properties.getValue(ho,!0)}get borderColor(){return this.properties.getValue(io)}get borderStyle(){return this.properties.getValue(so)}get borderWidth(){return this.scale*this.properties.getValue(ro)}get backgroundColor(){return this.properties.getValue(Qs)}get enabled(){return this.properties.getValue(oo)}get foregroundColor(){return this.properties.getValue(no)}get tooltip(){let t=this.properties.getProperty(go);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(mo)}get visible(){return this.properties.getValue(fo)}get actions(){return this.properties.getValue(Js)}get scripts(){return this.properties.getValue(uo)}get rules(){return this.properties.getValue(co)}get scaleOptions(){return this.properties.getValue(po)}get widgetType(){return this.properties.getValue(xo,!0)}get text(){return this.display.editMode?(this.properties.getProperty(Er).rawValue||"").split(" ").join("\xA0"):this.properties.getValue(Er).split(" ").join("\xA0")}init(){}hide(){}destroy(){}};var yo="macros",ut=class p extends V{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new Gt(yo))}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()}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(yo)}};var bo="arrow_length",Po="arrows",vo="fill_arrow",_o="name",Ro="line_color",To="line_style",Co="line_width",So="src_wuid",Lo="src_term",Ao="tgt_wuid",Eo="tgt_term",Oo="router",Vo="points",Gu="wuid",At="LEFT",Et="UP",Ot="DOWN",Vt="RIGHT",wi=class extends V{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(bo)),this.properties.add(new P(Po)),this.properties.add(new w(vo)),this.properties.add(new R(_o)),this.properties.add(new S(Ro)),this.properties.add(new P(To)),this.properties.add(new P(Co)),this.properties.add(new R(So)),this.properties.add(new R(Lo)),this.properties.add(new R(Ao)),this.properties.add(new R(Eo)),this.properties.add(new P(Oo)),this.properties.add(new Pt(Vo)),this.properties.add(new R(Gu))}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=_.fromPoints(r).translate(.5*this.scale,.5*this.scale);t.strokePath({path:s,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,r[1],r[0]),this.drawStopArrow(t,r[r.length-2],r[r.length-1])}drawManhattanConnection(t){let e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),r=this.route(e,i),s=_.fromPoints(r);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:s,dash:this.getDashArray()}),this.drawStartArrow(t,r[r.length-2],r[r.length-1]),this.drawStopArrow(t,r[1],r[0])}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}`)}}drawDirectConnection(t){let e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new _(e.x,e.y).lineTo(i.x,i.y),lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,i,e),this.drawStopArrow(t,e,i)}getManhattanAnchor(t,e){let i;switch(e){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":i=Et;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=Ot;break;case"LEFT":i=At;break;case"RIGHT":i=Vt;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?At:Vt:i=a<l?Et:Ot,{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=Dt(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:c,minDist:h}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===At?i>0&&r*r<c&&e.direction===Vt?(s=e,o=e.direction):(i<0?s={x:t.x-h,y:t.y}:r>0&&e.direction===Ot||r<0&&e.direction===Et?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.min(t.x,e.x)-h,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=Et:o=Ot):t.direction===Vt?i<0&&r*r<c&&e.direction===At?(s=e,o=e.direction):(i>0?s={x:t.x+h,y:t.y}:r>0&&e.direction===Ot||r<0&&e.direction===Et?s={x:e.x,y:t.y}:t.direction===e.direction?(n=Math.max(t.x,e.x)+h,s={x:n,y:t.y}):s={x:t.x-i/2,y:t.y},r>0?o=Et:o=Ot):t.direction===Ot?i*i<c&&r<0&&e.direction===Et?(s=e,o=e.direction):(r>0?s={x:t.x,y:t.y+h}:i>0&&e.direction===Vt||i<0&&e.direction===At?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.max(t.y,e.y)+h,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=At:o=Vt):t.direction===Et&&(i*i<c&&r>0&&e.direction===Ot?(s=e,o=e.direction):(r<0?s={x:t.x,y:t.y-h}:i>0&&e.direction===Vt||i<0&&e.direction===At?s={x:t.x,y:e.y}:t.direction===e.direction?(n=Math.min(t.y,e.y)-h,s={x:t.x,y:n}):s={x:t.x,y:t.y-r/2},i>0?o=At:o=Vt));let u={...s,direction:o};return a=a.concat(this.route(u,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=De(e,t),r=Math.PI/10,s=new at(this.arrowLength,i.theta-r),o=new at(this.arrowLength,i.theta+r),n=new at(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=wt(s.toPoint(),e.x,e.y),l=wt(o.toPoint(),e.x,e.y),c=wt(n.toPoint(),e.x,e.y);return[a,l,c]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(_o)}get arrows(){return this.properties.getValue(Po)}get fillArrow(){return this.properties.getValue(vo)}get arrowLength(){return this.scale*this.properties.getValue(bo)}get lineColor(){return this.properties.getValue(Ro)}get lineStyle(){return this.properties.getValue(To)}get lineWidth(){return this.scale*this.properties.getValue(Co)}get router(){return this.properties.getValue(Oo)}get sourceTerm(){return this.properties.getValue(Lo)}get sourceWuid(){return this.properties.getValue(So)}get targetTerm(){return this.properties.getValue(Eo)}get targetWuid(){return this.properties.getValue(Ao)}get points(){return Dt(this.properties.getValue(Vo),this.scale)}};var $u=0,Mo="auto_scale_widgets",ie=class extends ut{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new Ce(Mo))}async parseNode(t){await super.parseNode(t);let e=$u++;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))}for(let r of t.getNodes("connection")){let s=new wi(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(Mo)}};var Uu=0,Io="group_name",Bo="opi_file",Wo="resize_behaviour",re=class extends ut{linkedDisplay;resolvedOpiFile;constructor(t,e){super(t,e),this.properties.add(new R(Io)),this.properties.add(new R(Bo)),this.properties.add(new P(Wo,0))}async parseNode(t){await super.parseNode(t);let e=Uu++;this.macros.set("LCID",`LCID_${e}`)}async init(){if(this.opiFile){this.resolvedOpiFile=this.display.resolvePath(this.opiFile);let t=await this.display.loadContent(this.resolvedOpiFile);if(t!==null){this.linkedDisplay=new ie(this.display,this);let e=ee.parseFromXML(t);await this.linkedDisplay.parseNode(e),this.requestRepaint()}}if(this.linkedDisplay&&this.resizeBehavior===1){let t=this.linkedDisplay.measureContentBounds(!0);this.customSize={width:t.width,height:t.height}}}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.linkedDisplay.measureContentBounds(!1),{width:r,height:s}=i,o=this.display.scale;r*=o,s*=o;let n=r/s,a=this.width,l=a/n,c=a/r;l>this.height&&(l=this.height,a=l*n,c=l/r),this.linkedDisplay.relativeScale=c;let h=t.createChild(Math.ceil(a),Math.ceil(l));h.translate(i.x,i.y),this.linkedDisplay.draw(h),t.copy(h,this.x,this.y)}else if(this.resizeBehavior===1){let i=this.linkedDisplay.measureContentBounds(!0),r=t.createChild(i.width,i.height);r.translate(-i.x,-i.y),this.linkedDisplay.draw(r),t.copy(r,this.x,this.y)}else if(this.resizeBehavior===2){let i=this.linkedDisplay.measureContentBounds(!0),r=t.createChild(i.width,i.height);r.translate(i.x,i.y),this.linkedDisplay.draw(r),t.copy(r,this.x,this.y)}else this.resizeBehavior===3&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&this.groupName!==""?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(Bo)}get groupName(){return this.properties.getValue(Io)}get resizeBehavior(){return this.properties.getValue(Wo)}};var Se=class{constructor(t){this.display=t}display;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 re){let r=i.resolvedOpiFile,s=r.lastIndexOf("/")+1;return`${r.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}};var yi=class{constructor(t){this.display=t}display;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 Le=class{constructor(t,e){this.pvName=t;this.formula=e}pvName;formula;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 Ae=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," "),c=i[s.line-1],u=(s.line===a.line?a.column:c.length+1)-s.column||1;e+=`
2
2
  --> `+n+`
3
3
  `+l+` |
4
4
  `+o.line+" | "+c+`
5
5
  `+l+" | "+"".padEnd(s.column-1," ")+"".padEnd(u,"^")}else e+=`
6
- at `+n}return e}static buildMessage(t,e){function i(u){return u.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(u){return r?u.replace(r,g=>"\\u{"+i(g)+"}"):u}function o(u){return s(u.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(u){return s(u.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(u){return'"'+o(u.text)+'"'},class(u){let g=u.parts.map(v=>Array.isArray(v)?n(v[0])+"-"+n(v[1]):n(v));return"["+(u.inverted?"^":"")+g.join("")+"]"+(u.unicode?"u":"")},any(){return"any character"},end(){return"end of input"},other(u){return u.description}};function l(u){return a[u.type](u)}function c(u){let g=u.map(l);if(g.sort(),g.length>0){let v=1;for(let b=1;b<g.length;b++)g[b-1]!==g[b]&&(g[v]=g[b],v++);g.length=v}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 h(u){return u?'"'+o(u)+'"':"end of input"}return"Expected "+c(t)+" but "+h(e)+" found."}};function Io(p,t){t=t!==void 0?t:{};let e={},i=t.grammarSource,r={Start:ps},s=ps,o="=",n="false",a="true",l="pi",c="e",h=".",u="0",g='"',v="'",b="(",T=")",W=",",O="<=",L=">=",M="==",N="!=",F="&&",X="||",j=/^[\t ]/,pt=/^[A-Z_a-z]/,it=/^[a-zA-Z0-9_]/,dt=/^[0-9]/,ot=/^[1-9]/,Bt=/^[^\n\r\f"]/,ue=/^[^\n\r\f']/,tt=/^[+\-]/,mt=/^[%*\/\^]/,Rt=/^[<>]/,Wt=J("=",!1),qt=ut([" "," "],!1,!1,!1),Ht=J("false",!0),kt=J("true",!0),Tt=J("PI",!0),ft=J("E",!0),nt=Dt("identifier"),xt=ut([["A","Z"],"_",["a","z"]],!1,!1,!1),ge=ut([["a","z"],["A","Z"],["0","9"],"_"],!1,!1,!1),me=Dt("boolean"),fe=Dt("constant"),xe=Dt("number"),zr=J(".",!1),Id=J("0",!1),Bd=ut([["0","9"]],!1,!1,!1),Wd=ut([["1","9"]],!1,!1,!1),Hd=Dt("string"),qr=J('"',!1),Kr=ut([`
7
- `,"\r","\f",'"'],!0,!1,!1),kd=Dt("parameter"),jr=J("'",!1),Zr=ut([`
8
- `,"\r","\f","'"],!0,!1,!1),Jr=J("(",!1),Qr=J(")",!1),mr=ut(["+","-"],!1,!1,!1),ts=J(",",!1),es=ut(["%","*","/","^"],!1,!1,!1),is=J("<=",!1),rs=J(">=",!1),ss=ut(["<",">"],!1,!1,!1),os=J("==",!1),ns=J("!=",!1),as=J("&&",!1),ls=J("||",!1);function em(d){return d}function Dd(d){return{type:"Formula",expression:d}}function im(d){return d}function Nd(d,x){return{type:"Symbol",name:d+x.join("")}}function Fd(){return{type:"BooleanLiteral",value:!0}}function Gd(){return{type:"BooleanLiteral",value:!1}}function $d(){return{type:"ConstantLiteral",value:Math.PI}}function Ud(){return{type:"ConstantLiteral",value:Math.E}}function Yd(){return{type:"NumericLiteral",value:parseFloat(fr())}}function Xd(){return{type:"NumericLiteral",value:parseFloat(fr())}}function zd(){return{type:"NumericLiteral",value:parseFloat(fr())}}function qd(d){return{type:"StringLiteral",value:d.join("")}}function Kd(d){return{type:"ParameterLiteral",value:d.join("")}}function rm(d){return d}function jd(d,x){return{type:"UnaryExpression",operator:d,argument:x}}function Zd(d,x){return{type:"CallExpression",callee:d,arguments:x}}function Jd(d){return Ou(Lu(d,0))}function Qd(d,x){return Au(d,x,3)}function tu(d,x){return We(d,x)}function eu(d,x){return We(d,x)}function iu(d,x){return We(d,x)}function ru(d,x){return We(d,x)}function su(d,x){return Eu(d,x)}let f=t.peg$currPos|0,Y=f,Kt=[{line:1,column:1}],at=f,Be=t.peg$maxFailExpected||[],I=t.peg$silentFails|0,we;if(t.startRule){if(!(t.startRule in r))throw new Error(`Can't start parsing from rule "`+t.startRule+'".');s=r[t.startRule]}function fr(){return p.substring(Y,f)}function sm(){return Y}function om(){return{source:i,start:Y,end:f}}function nm(){return ye(Y,f)}function am(d,x){throw x=x!==void 0?x:ye(Y,f),cs([Dt(d)],p.substring(Y,f),x)}function lm(d,x){throw x=x!==void 0?x:ye(Y,f),au(d,x)}function ou(d=f){let x=p.codePointAt(d);return x===void 0?"":String.fromCodePoint(x)}function J(d,x){return{type:"literal",text:d,ignoreCase:x}}function ut(d,x,A,y){return{type:"class",parts:d,inverted:x,ignoreCase:A,unicode:y}}function hm(){return{type:"any"}}function nu(){return{type:"end"}}function Dt(d){return{type:"other",description:d}}function hs(d){let x=Kt[d],A;if(x)return x;if(d>=Kt.length)A=Kt.length-1;else for(A=d;!Kt[--A];);for(x=Kt[A],x={line:x.line,column:x.column};A<d;)p.charCodeAt(A)===10?(x.line++,x.column=1):x.column++,A++;return Kt[d]=x,x}function ye(d,x,A){let y=hs(d),E=hs(x),C={source:i,start:{offset:d,line:y.line,column:y.column},end:{offset:x,line:E.line,column:E.column}};return A&&i&&typeof i.offset=="function"&&(C.start=i.offset(C.start),C.end=i.offset(C.end)),C}function k(d){f<at||(f>at&&(at=f,Be=[]),Be.push(d))}function au(d,x){return new Ee(d,null,null,x)}function cs(d,x,A){return new Ee(Ee.buildMessage(d,x),d,x,A)}function ps(){let d,x,A,y,E;return d=f,p.charCodeAt(f)===61?(x=o,f++):(x=e,I===0&&k(Wt)),x!==e?(A=U(),y=lu(),y!==e?(E=U(),Y=d,d=y):(f=d,d=e)):(f=d,d=e),d}function lu(){let d,x;return d=f,x=be(),x!==e&&(Y=d,x=Dd(x)),d=x,d}function U(){let d,x;for(d=[],x=ds();x!==e;)d.push(x),x=ds();return d}function ds(){let d;return d=p.charAt(f),j.test(d)?f++:(d=e,I===0&&k(qt)),d}function hu(){let d;return d=p.substr(f,5),d.toLowerCase()===n?f+=5:(d=e,I===0&&k(Ht)),d}function cu(){let d;return d=p.substr(f,4),d.toLowerCase()===a?f+=4:(d=e,I===0&&k(kt)),d}function pu(){let d;return d=p.substr(f,2),d.toLowerCase()===l?f+=2:(d=e,I===0&&k(Tt)),d}function du(){let d;return d=p.charAt(f),d.toLowerCase()===c?f++:(d=e,I===0&&k(ft)),d}function uu(){let d,x;return d=f,x=gu(),x!==e&&(Y=d,x=x),d=x,d}function gu(){let d,x,A,y;if(I++,d=f,x=mu(),x!==e){for(A=[],y=us();y!==e;)A.push(y),y=us();Y=d,d=Nd(x,A)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(nt)),d}function mu(){let d;return d=p.charAt(f),pt.test(d)?f++:(d=e,I===0&&k(xt)),d}function us(){let d;return d=p.charAt(f),it.test(d)?f++:(d=e,I===0&&k(ge)),d}function fu(){let d;return d=xu(),d===e&&(d=wu(),d===e&&(d=yu(),d===e&&(d=Pu(),d===e&&(d=vu())))),d}function xu(){let d,x;return I++,d=f,x=cu(),x!==e&&(Y=d,x=Fd()),d=x,d===e&&(d=f,x=hu(),x!==e&&(Y=d,x=Gd()),d=x),I--,d===e&&(x=e,I===0&&k(me)),d}function wu(){let d,x;return I++,d=f,x=pu(),x!==e&&(Y=d,x=$d()),d=x,d===e&&(d=f,x=du(),x!==e&&(Y=d,x=Ud()),d=x),I--,d===e&&(x=e,I===0&&k(fe)),d}function yu(){let d,x,A,y,E;if(I++,d=f,x=gs(),x!==e)if(p.charCodeAt(f)===46?(A=h,f++):(A=e,I===0&&k(zr)),A!==e){for(y=[],E=jt();E!==e;)y.push(E),E=jt();Y=d,d=Yd()}else f=d,d=e;else f=d,d=e;if(d===e){if(d=f,p.charCodeAt(f)===46?(x=h,f++):(x=e,I===0&&k(zr)),x!==e){if(A=[],y=jt(),y!==e)for(;y!==e;)A.push(y),y=jt();else A=e;A!==e?(Y=d,d=Xd()):(f=d,d=e)}else f=d,d=e;d===e&&(d=f,x=gs(),x!==e&&(Y=d,x=zd()),d=x)}return I--,d===e&&(x=e,I===0&&k(xe)),d}function gs(){let d,x,A,y;if(p.charCodeAt(f)===48?(d=u,f++):(d=e,I===0&&k(Id)),d===e)if(d=f,x=bu(),x!==e){for(A=[],y=jt();y!==e;)A.push(y),y=jt();x=[x,A],d=x}else f=d,d=e;return d}function jt(){let d;return d=p.charAt(f),dt.test(d)?f++:(d=e,I===0&&k(Bd)),d}function bu(){let d;return d=p.charAt(f),ot.test(d)?f++:(d=e,I===0&&k(Wd)),d}function Pu(){let d,x,A,y;if(I++,d=f,p.charCodeAt(f)===34?(x=g,f++):(x=e,I===0&&k(qr)),x!==e){for(A=[],y=p.charAt(f),Bt.test(y)?f++:(y=e,I===0&&k(Kr));y!==e;)A.push(y),y=p.charAt(f),Bt.test(y)?f++:(y=e,I===0&&k(Kr));p.charCodeAt(f)===34?(y=g,f++):(y=e,I===0&&k(qr)),y!==e?(Y=d,d=qd(A)):(f=d,d=e)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(Hd)),d}function vu(){let d,x,A,y;if(I++,d=f,p.charCodeAt(f)===39?(x=v,f++):(x=e,I===0&&k(jr)),x!==e){for(A=[],y=p.charAt(f),ue.test(y)?f++:(y=e,I===0&&k(Zr));y!==e;)A.push(y),y=p.charAt(f),ue.test(y)?f++:(y=e,I===0&&k(Zr));p.charCodeAt(f)===39?(y=v,f++):(y=e,I===0&&k(jr)),y!==e?(Y=d,d=Kd(A)):(f=d,d=e)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(kd)),d}function _u(){let d,x,A,y,E,C;return d=fu(),d===e&&(d=f,p.charCodeAt(f)===40?(x=b,f++):(x=e,I===0&&k(Jr)),x!==e?(A=U(),y=be(),y!==e?(E=U(),p.charCodeAt(f)===41?(C=T,f++):(C=e,I===0&&k(Qr)),C!==e?(Y=d,d=y):(f=d,d=e)):(f=d,d=e)):(f=d,d=e)),d}function ms(){let d,x,A,y,E;return d=_u(),d===e&&(d=f,x=Ru(),x!==e?(A=U(),y=ms(),y!==e?(E=U(),Y=d,d=jd(x,y)):(f=d,d=e)):(f=d,d=e)),d}function Ru(){let d;return d=p.charAt(f),tt.test(d)?f++:(d=e,I===0&&k(mr)),d}function xr(){let d,x,A,y;return d=f,x=uu(),x!==e?(A=U(),y=Tu(),y!==e?(Y=d,d=Zd(x,y)):(f=d,d=e)):(f=d,d=e),d===e&&(d=ms()),d}function Tu(){let d,x,A,y,E,C;return d=f,p.charCodeAt(f)===40?(x=b,f++):(x=e,I===0&&k(Jr)),x!==e?(A=U(),y=f,E=Cu(),E!==e?(C=U(),E=[E,C],y=E):(f=y,y=e),y===e&&(y=null),p.charCodeAt(f)===41?(E=T,f++):(E=e,I===0&&k(Qr)),E!==e?(Y=d,d=Jd(y)):(f=d,d=e)):(f=d,d=e),d}function Cu(){let d,x,A,y,E,C,z,G;if(d=f,x=be(),x!==e){for(A=[],y=f,E=U(),p.charCodeAt(f)===44?(C=W,f++):(C=e,I===0&&k(ts)),C!==e?(z=U(),G=be(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.charCodeAt(f)===44?(C=W,f++):(C=e,I===0&&k(ts)),C!==e?(z=U(),G=be(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=Qd(x,A)}else f=d,d=e;return d}function wr(){let d,x,A,y,E,C,z,G;if(d=f,x=xr(),x!==e){for(A=[],y=f,E=U(),C=p.charAt(f),mt.test(C)?f++:(C=e,I===0&&k(es)),C!==e?(z=U(),G=xr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),C=p.charAt(f),mt.test(C)?f++:(C=e,I===0&&k(es)),C!==e?(z=U(),G=xr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=tu(x,A)}else f=d,d=e;return d}function yr(){let d,x,A,y,E,C,z,G;if(d=f,x=wr(),x!==e){for(A=[],y=f,E=U(),C=p.charAt(f),tt.test(C)?f++:(C=e,I===0&&k(mr)),C!==e?(z=U(),G=wr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),C=p.charAt(f),tt.test(C)?f++:(C=e,I===0&&k(mr)),C!==e?(z=U(),G=wr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=eu(x,A)}else f=d,d=e;return d}function br(){let d,x,A,y,E,C,z,G;if(d=f,x=yr(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===O?(C=O,f+=2):(C=e,I===0&&k(is)),C===e&&(p.substr(f,2)===L?(C=L,f+=2):(C=e,I===0&&k(rs)),C===e&&(C=p.charAt(f),Rt.test(C)?f++:(C=e,I===0&&k(ss)))),C!==e?(z=U(),G=yr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===O?(C=O,f+=2):(C=e,I===0&&k(is)),C===e&&(p.substr(f,2)===L?(C=L,f+=2):(C=e,I===0&&k(rs)),C===e&&(C=p.charAt(f),Rt.test(C)?f++:(C=e,I===0&&k(ss)))),C!==e?(z=U(),G=yr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=iu(x,A)}else f=d,d=e;return d}function Pr(){let d,x,A,y,E,C,z,G;if(d=f,x=br(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===M?(C=M,f+=2):(C=e,I===0&&k(os)),C===e&&(p.substr(f,2)===N?(C=N,f+=2):(C=e,I===0&&k(ns))),C!==e?(z=U(),G=br(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===M?(C=M,f+=2):(C=e,I===0&&k(os)),C===e&&(p.substr(f,2)===N?(C=N,f+=2):(C=e,I===0&&k(ns))),C!==e?(z=U(),G=br(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=ru(x,A)}else f=d,d=e;return d}function be(){let d,x,A,y,E,C,z,G;if(d=f,x=Pr(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===F?(C=F,f+=2):(C=e,I===0&&k(as)),C===e&&(p.substr(f,2)===X?(C=X,f+=2):(C=e,I===0&&k(ls))),C!==e?(z=U(),G=Pr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===F?(C=F,f+=2):(C=e,I===0&&k(as)),C===e&&(p.substr(f,2)===X?(C=X,f+=2):(C=e,I===0&&k(ls))),C!==e?(z=U(),G=Pr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=su(x,A)}else f=d,d=e;return d}function Su(d,x){return d.map(function(A){return A[x]})}function Lu(d,x){return d?d[x]:null}function Au(d,x,A){return[d].concat(Su(x,A))}function We(d,x){return x.reduce(function(A,y){return{type:"BinaryExpression",operator:y[1],left:A,right:y[3]}},d)}function Eu(d,x){return x.reduce(function(A,y){return{type:"LogicalExpression",operator:y[1],left:A,right:y[3]}},d)}function Ou(d){return d!==null?d:[]}we=s();let vr=we!==e&&f===p.length;function fs(){throw we!==e&&f<p.length&&k(nu()),cs(Be,at<p.length?ou(at):null,at<p.length?ye(at,at+1):ye(at,at))}if(t.peg$library)return{peg$result:we,peg$currPos:f,peg$FAILED:e,peg$maxFailExpected:Be,peg$maxFailPos:at,peg$success:vr,peg$throw:vr?void 0:fs};if(vr)return we;fs()}var Oe=class{compile(t){let e=Io(t,{});return new Ae(t,e)}execute(t){return this.compile(t).execute()}};var Pi=class{pvs=new Map;canProvide(t){return t.startsWith("=")}startProviding(t){for(let e of t)this.pvs.set(e.name,new Mr(e))}stopProviding(t){for(let e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}},Mr=class{constructor(t){this.pv=t;let e=new Oe;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()}pv;compiledFormula;trigger(){let t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}};function Ho(p){return!isNaN(p)&&(Number.isInteger(parseFloat(p))||p%1!==0)}function Bo(p){return Ho(p)?parseFloat(p):(console.warn(`Not a valid float: ${p}`),p)}function Wo(p){return p!=null?String(p):p}var vi=class extends Xt{constructor(e,i,r,s){super(e,i);this.type=r;this.initializer=s;this.writable=!0}type;initializer;setSample(e){if(this.type==="VDouble")e.value=Bo(e.value);else if(this.type==="VDoubleArray")for(let i=0;i<e.value.length;i++)e.value[i]=Bo(e.value);else if(this.type==="VString")e.value=Wo(e.value);else if(this.type==="VStringArray")for(let i=0;i<e.value.length;i++)e.value[i]=Wo(e.value);else typeof e.value=="string"&&Ho(e.value)&&(e.value=parseFloat(e.value));super.setSample(e)}};var ko=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function ne(p){if(!p.startsWith("loc://"))return p;let t=p.match(ko);return t?t[1]:p}var _i=class{constructor(t){this.display=t}display;rules=[];scripts=[];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.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){let e=ne(t);return this.pvs.has(e)}getPV(t){let e=ne(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 Xt(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(ko),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 vi(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=ne(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=ne(e),l=this.pvs.get(a);if(l){l.setSample({time:t,value:i,severity:r,units:s});for(let c of this.listeners.get(a)||[])c()}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 Ir(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);this.addListener(l,()=>{if(e.checkConnect)for(let c=0;c<e.inputs.length;c++){let h=r[c],u=e.inputs[c].trigger,g=h.value!==null&&h.value!==void 0;if(h.disconnected||u&&!g)return}s.scriptEngine.run(a)},!1)}}return s}createRule(t,e){let i=[];for(let o of e.inputs){let n=t.expandMacro(o.pvName);i.push(this.createPV(n))}let r=new Br(t,e,i);this.rules.push(r);let s=()=>r.scriptEngine.run();for(let o of e.inputs)if(o.trigger){let n=t.expandMacro(o.pvName);this.addListener(n,s,!1)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){let r=ne(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=ne(t),r=this.listeners.get(i);if(r){let s=r.indexOf(e);s!==-1&&r.splice(s,1)}}},Ir=class{constructor(t,e,i,r){this.widget=t;this.script=e;this.text=i;this.pvs=r;this.scriptEngine=new At(t,i,r)}widget;script;text;pvs;scriptEngine},Br=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 u of e.expressions)u.expression.match(/pv[0-9]+/)&&(o=!0),e.outputExpression&&u.outputValue.toString().match(/pv[0-9]+/)&&(o=!0),u.expression.indexOf("pvInt")!==-1&&(n=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvInt")!==-1&&(n=!0),u.expression.indexOf("pvStr")!==-1&&(a=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvStr")!==-1&&(a=!0),u.expression.indexOf("pvSev")!==-1&&(l=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvSev")!==-1&&(l=!0);for(let u=0;u<i.length;u++)o&&(r+=`var pv${u} = PVUtil.getDouble(pvs[${u}]);
6
+ at `+n}return e}static buildMessage(t,e){function i(u){return u.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(u){return r?u.replace(r,g=>"\\u{"+i(g)+"}"):u}function o(u){return s(u.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(u){return s(u.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(u){return'"'+o(u.text)+'"'},class(u){let g=u.parts.map(v=>Array.isArray(v)?n(v[0])+"-"+n(v[1]):n(v));return"["+(u.inverted?"^":"")+g.join("")+"]"+(u.unicode?"u":"")},any(){return"any character"},end(){return"end of input"},other(u){return u.description}};function l(u){return a[u.type](u)}function c(u){let g=u.map(l);if(g.sort(),g.length>0){let v=1;for(let b=1;b<g.length;b++)g[b-1]!==g[b]&&(g[v]=g[b],v++);g.length=v}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 h(u){return u?'"'+o(u)+'"':"end of input"}return"Expected "+c(t)+" but "+h(e)+" found."}};function Ho(p,t){t=t!==void 0?t:{};let e={},i=t.grammarSource,r={Start:ms},s=ms,o="=",n="false",a="true",l="pi",c="e",h=".",u="0",g='"',v="'",b="(",T=")",W=",",O="<=",L=">=",M="==",N="!=",F="&&",X="||",j=/^[\t ]/,ct=/^[A-Z_a-z]/,it=/^[a-zA-Z0-9_]/,pt=/^[0-9]/,st=/^[1-9]/,It=/^[^\n\r\f"]/,pe=/^[^\n\r\f']/,tt=/^[+\-]/,gt=/^[%*\/\^]/,_t=/^[<>]/,Bt=J("=",!1),Xt=dt([" "," "],!1,!1,!1),Wt=J("false",!0),Ht=J("true",!0),Rt=J("PI",!0),mt=J("E",!0),ot=kt("identifier"),ft=dt([["A","Z"],"_",["a","z"]],!1,!1,!1),de=dt([["a","z"],["A","Z"],["0","9"],"_"],!1,!1,!1),ue=kt("boolean"),ge=kt("constant"),me=kt("number"),Zr=J(".",!1),Hd=J("0",!1),kd=dt([["0","9"]],!1,!1,!1),Dd=dt([["1","9"]],!1,!1,!1),Nd=kt("string"),Jr=J('"',!1),Qr=dt([`
7
+ `,"\r","\f",'"'],!0,!1,!1),Fd=kt("parameter"),ts=J("'",!1),es=dt([`
8
+ `,"\r","\f","'"],!0,!1,!1),is=J("(",!1),rs=J(")",!1),fr=dt(["+","-"],!1,!1,!1),ss=J(",",!1),os=dt(["%","*","/","^"],!1,!1,!1),ns=J("<=",!1),as=J(">=",!1),ls=dt(["<",">"],!1,!1,!1),hs=J("==",!1),cs=J("!=",!1),ps=J("&&",!1),ds=J("||",!1);function rm(d){return d}function Gd(d){return{type:"Formula",expression:d}}function sm(d){return d}function $d(d,x){return{type:"Symbol",name:d+x.join("")}}function Ud(){return{type:"BooleanLiteral",value:!0}}function Yd(){return{type:"BooleanLiteral",value:!1}}function Xd(){return{type:"ConstantLiteral",value:Math.PI}}function zd(){return{type:"ConstantLiteral",value:Math.E}}function qd(){return{type:"NumericLiteral",value:parseFloat(xr())}}function Kd(){return{type:"NumericLiteral",value:parseFloat(xr())}}function jd(){return{type:"NumericLiteral",value:parseFloat(xr())}}function Zd(d){return{type:"StringLiteral",value:d.join("")}}function Jd(d){return{type:"ParameterLiteral",value:d.join("")}}function om(d){return d}function Qd(d,x){return{type:"UnaryExpression",operator:d,argument:x}}function tu(d,x){return{type:"CallExpression",callee:d,arguments:x}}function eu(d){return Iu(Ou(d,0))}function iu(d,x){return Vu(d,x,3)}function ru(d,x){return Be(d,x)}function su(d,x){return Be(d,x)}function ou(d,x){return Be(d,x)}function nu(d,x){return Be(d,x)}function au(d,x){return Mu(d,x)}let f=t.peg$currPos|0,Y=f,zt=[{line:1,column:1}],nt=f,Ie=t.peg$maxFailExpected||[],I=t.peg$silentFails|0,fe;if(t.startRule){if(!(t.startRule in r))throw new Error(`Can't start parsing from rule "`+t.startRule+'".');s=r[t.startRule]}function xr(){return p.substring(Y,f)}function nm(){return Y}function am(){return{source:i,start:Y,end:f}}function lm(){return xe(Y,f)}function hm(d,x){throw x=x!==void 0?x:xe(Y,f),gs([kt(d)],p.substring(Y,f),x)}function cm(d,x){throw x=x!==void 0?x:xe(Y,f),cu(d,x)}function lu(d=f){let x=p.codePointAt(d);return x===void 0?"":String.fromCodePoint(x)}function J(d,x){return{type:"literal",text:d,ignoreCase:x}}function dt(d,x,A,y){return{type:"class",parts:d,inverted:x,ignoreCase:A,unicode:y}}function pm(){return{type:"any"}}function hu(){return{type:"end"}}function kt(d){return{type:"other",description:d}}function us(d){let x=zt[d],A;if(x)return x;if(d>=zt.length)A=zt.length-1;else for(A=d;!zt[--A];);for(x=zt[A],x={line:x.line,column:x.column};A<d;)p.charCodeAt(A)===10?(x.line++,x.column=1):x.column++,A++;return zt[d]=x,x}function xe(d,x,A){let y=us(d),E=us(x),C={source:i,start:{offset:d,line:y.line,column:y.column},end:{offset:x,line:E.line,column:E.column}};return A&&i&&typeof i.offset=="function"&&(C.start=i.offset(C.start),C.end=i.offset(C.end)),C}function k(d){f<nt||(f>nt&&(nt=f,Ie=[]),Ie.push(d))}function cu(d,x){return new Ae(d,null,null,x)}function gs(d,x,A){return new Ae(Ae.buildMessage(d,x),d,x,A)}function ms(){let d,x,A,y,E;return d=f,p.charCodeAt(f)===61?(x=o,f++):(x=e,I===0&&k(Bt)),x!==e?(A=U(),y=pu(),y!==e?(E=U(),Y=d,d=y):(f=d,d=e)):(f=d,d=e),d}function pu(){let d,x;return d=f,x=we(),x!==e&&(Y=d,x=Gd(x)),d=x,d}function U(){let d,x;for(d=[],x=fs();x!==e;)d.push(x),x=fs();return d}function fs(){let d;return d=p.charAt(f),j.test(d)?f++:(d=e,I===0&&k(Xt)),d}function du(){let d;return d=p.substr(f,5),d.toLowerCase()===n?f+=5:(d=e,I===0&&k(Wt)),d}function uu(){let d;return d=p.substr(f,4),d.toLowerCase()===a?f+=4:(d=e,I===0&&k(Ht)),d}function gu(){let d;return d=p.substr(f,2),d.toLowerCase()===l?f+=2:(d=e,I===0&&k(Rt)),d}function mu(){let d;return d=p.charAt(f),d.toLowerCase()===c?f++:(d=e,I===0&&k(mt)),d}function fu(){let d,x;return d=f,x=xu(),x!==e&&(Y=d,x=x),d=x,d}function xu(){let d,x,A,y;if(I++,d=f,x=wu(),x!==e){for(A=[],y=xs();y!==e;)A.push(y),y=xs();Y=d,d=$d(x,A)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(ot)),d}function wu(){let d;return d=p.charAt(f),ct.test(d)?f++:(d=e,I===0&&k(ft)),d}function xs(){let d;return d=p.charAt(f),it.test(d)?f++:(d=e,I===0&&k(de)),d}function yu(){let d;return d=bu(),d===e&&(d=Pu(),d===e&&(d=vu(),d===e&&(d=Ru(),d===e&&(d=Tu())))),d}function bu(){let d,x;return I++,d=f,x=uu(),x!==e&&(Y=d,x=Ud()),d=x,d===e&&(d=f,x=du(),x!==e&&(Y=d,x=Yd()),d=x),I--,d===e&&(x=e,I===0&&k(ue)),d}function Pu(){let d,x;return I++,d=f,x=gu(),x!==e&&(Y=d,x=Xd()),d=x,d===e&&(d=f,x=mu(),x!==e&&(Y=d,x=zd()),d=x),I--,d===e&&(x=e,I===0&&k(ge)),d}function vu(){let d,x,A,y,E;if(I++,d=f,x=ws(),x!==e)if(p.charCodeAt(f)===46?(A=h,f++):(A=e,I===0&&k(Zr)),A!==e){for(y=[],E=qt();E!==e;)y.push(E),E=qt();Y=d,d=qd()}else f=d,d=e;else f=d,d=e;if(d===e){if(d=f,p.charCodeAt(f)===46?(x=h,f++):(x=e,I===0&&k(Zr)),x!==e){if(A=[],y=qt(),y!==e)for(;y!==e;)A.push(y),y=qt();else A=e;A!==e?(Y=d,d=Kd()):(f=d,d=e)}else f=d,d=e;d===e&&(d=f,x=ws(),x!==e&&(Y=d,x=jd()),d=x)}return I--,d===e&&(x=e,I===0&&k(me)),d}function ws(){let d,x,A,y;if(p.charCodeAt(f)===48?(d=u,f++):(d=e,I===0&&k(Hd)),d===e)if(d=f,x=_u(),x!==e){for(A=[],y=qt();y!==e;)A.push(y),y=qt();x=[x,A],d=x}else f=d,d=e;return d}function qt(){let d;return d=p.charAt(f),pt.test(d)?f++:(d=e,I===0&&k(kd)),d}function _u(){let d;return d=p.charAt(f),st.test(d)?f++:(d=e,I===0&&k(Dd)),d}function Ru(){let d,x,A,y;if(I++,d=f,p.charCodeAt(f)===34?(x=g,f++):(x=e,I===0&&k(Jr)),x!==e){for(A=[],y=p.charAt(f),It.test(y)?f++:(y=e,I===0&&k(Qr));y!==e;)A.push(y),y=p.charAt(f),It.test(y)?f++:(y=e,I===0&&k(Qr));p.charCodeAt(f)===34?(y=g,f++):(y=e,I===0&&k(Jr)),y!==e?(Y=d,d=Zd(A)):(f=d,d=e)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(Nd)),d}function Tu(){let d,x,A,y;if(I++,d=f,p.charCodeAt(f)===39?(x=v,f++):(x=e,I===0&&k(ts)),x!==e){for(A=[],y=p.charAt(f),pe.test(y)?f++:(y=e,I===0&&k(es));y!==e;)A.push(y),y=p.charAt(f),pe.test(y)?f++:(y=e,I===0&&k(es));p.charCodeAt(f)===39?(y=v,f++):(y=e,I===0&&k(ts)),y!==e?(Y=d,d=Jd(A)):(f=d,d=e)}else f=d,d=e;return I--,d===e&&(x=e,I===0&&k(Fd)),d}function Cu(){let d,x,A,y,E,C;return d=yu(),d===e&&(d=f,p.charCodeAt(f)===40?(x=b,f++):(x=e,I===0&&k(is)),x!==e?(A=U(),y=we(),y!==e?(E=U(),p.charCodeAt(f)===41?(C=T,f++):(C=e,I===0&&k(rs)),C!==e?(Y=d,d=y):(f=d,d=e)):(f=d,d=e)):(f=d,d=e)),d}function ys(){let d,x,A,y,E;return d=Cu(),d===e&&(d=f,x=Su(),x!==e?(A=U(),y=ys(),y!==e?(E=U(),Y=d,d=Qd(x,y)):(f=d,d=e)):(f=d,d=e)),d}function Su(){let d;return d=p.charAt(f),tt.test(d)?f++:(d=e,I===0&&k(fr)),d}function wr(){let d,x,A,y;return d=f,x=fu(),x!==e?(A=U(),y=Lu(),y!==e?(Y=d,d=tu(x,y)):(f=d,d=e)):(f=d,d=e),d===e&&(d=ys()),d}function Lu(){let d,x,A,y,E,C;return d=f,p.charCodeAt(f)===40?(x=b,f++):(x=e,I===0&&k(is)),x!==e?(A=U(),y=f,E=Au(),E!==e?(C=U(),E=[E,C],y=E):(f=y,y=e),y===e&&(y=null),p.charCodeAt(f)===41?(E=T,f++):(E=e,I===0&&k(rs)),E!==e?(Y=d,d=eu(y)):(f=d,d=e)):(f=d,d=e),d}function Au(){let d,x,A,y,E,C,z,G;if(d=f,x=we(),x!==e){for(A=[],y=f,E=U(),p.charCodeAt(f)===44?(C=W,f++):(C=e,I===0&&k(ss)),C!==e?(z=U(),G=we(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.charCodeAt(f)===44?(C=W,f++):(C=e,I===0&&k(ss)),C!==e?(z=U(),G=we(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=iu(x,A)}else f=d,d=e;return d}function yr(){let d,x,A,y,E,C,z,G;if(d=f,x=wr(),x!==e){for(A=[],y=f,E=U(),C=p.charAt(f),gt.test(C)?f++:(C=e,I===0&&k(os)),C!==e?(z=U(),G=wr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),C=p.charAt(f),gt.test(C)?f++:(C=e,I===0&&k(os)),C!==e?(z=U(),G=wr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=ru(x,A)}else f=d,d=e;return d}function br(){let d,x,A,y,E,C,z,G;if(d=f,x=yr(),x!==e){for(A=[],y=f,E=U(),C=p.charAt(f),tt.test(C)?f++:(C=e,I===0&&k(fr)),C!==e?(z=U(),G=yr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),C=p.charAt(f),tt.test(C)?f++:(C=e,I===0&&k(fr)),C!==e?(z=U(),G=yr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=su(x,A)}else f=d,d=e;return d}function Pr(){let d,x,A,y,E,C,z,G;if(d=f,x=br(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===O?(C=O,f+=2):(C=e,I===0&&k(ns)),C===e&&(p.substr(f,2)===L?(C=L,f+=2):(C=e,I===0&&k(as)),C===e&&(C=p.charAt(f),_t.test(C)?f++:(C=e,I===0&&k(ls)))),C!==e?(z=U(),G=br(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===O?(C=O,f+=2):(C=e,I===0&&k(ns)),C===e&&(p.substr(f,2)===L?(C=L,f+=2):(C=e,I===0&&k(as)),C===e&&(C=p.charAt(f),_t.test(C)?f++:(C=e,I===0&&k(ls)))),C!==e?(z=U(),G=br(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=ou(x,A)}else f=d,d=e;return d}function vr(){let d,x,A,y,E,C,z,G;if(d=f,x=Pr(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===M?(C=M,f+=2):(C=e,I===0&&k(hs)),C===e&&(p.substr(f,2)===N?(C=N,f+=2):(C=e,I===0&&k(cs))),C!==e?(z=U(),G=Pr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===M?(C=M,f+=2):(C=e,I===0&&k(hs)),C===e&&(p.substr(f,2)===N?(C=N,f+=2):(C=e,I===0&&k(cs))),C!==e?(z=U(),G=Pr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=nu(x,A)}else f=d,d=e;return d}function we(){let d,x,A,y,E,C,z,G;if(d=f,x=vr(),x!==e){for(A=[],y=f,E=U(),p.substr(f,2)===F?(C=F,f+=2):(C=e,I===0&&k(ps)),C===e&&(p.substr(f,2)===X?(C=X,f+=2):(C=e,I===0&&k(ds))),C!==e?(z=U(),G=vr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);y!==e;)A.push(y),y=f,E=U(),p.substr(f,2)===F?(C=F,f+=2):(C=e,I===0&&k(ps)),C===e&&(p.substr(f,2)===X?(C=X,f+=2):(C=e,I===0&&k(ds))),C!==e?(z=U(),G=vr(),G!==e?(E=[E,C,z,G],y=E):(f=y,y=e)):(f=y,y=e);Y=d,d=au(x,A)}else f=d,d=e;return d}function Eu(d,x){return d.map(function(A){return A[x]})}function Ou(d,x){return d?d[x]:null}function Vu(d,x,A){return[d].concat(Eu(x,A))}function Be(d,x){return x.reduce(function(A,y){return{type:"BinaryExpression",operator:y[1],left:A,right:y[3]}},d)}function Mu(d,x){return x.reduce(function(A,y){return{type:"LogicalExpression",operator:y[1],left:A,right:y[3]}},d)}function Iu(d){return d!==null?d:[]}fe=s();let _r=fe!==e&&f===p.length;function bs(){throw fe!==e&&f<p.length&&k(hu()),gs(Ie,nt<p.length?lu(nt):null,nt<p.length?xe(nt,nt+1):xe(nt,nt))}if(t.peg$library)return{peg$result:fe,peg$currPos:f,peg$FAILED:e,peg$maxFailExpected:Ie,peg$maxFailPos:nt,peg$success:_r,peg$throw:_r?void 0:bs};if(_r)return fe;bs()}var Ee=class{compile(t){let e=Ho(t,{});return new Le(t,e)}execute(t){return this.compile(t).execute()}};var bi=class{pvs=new Map;canProvide(t){return t.startsWith("=")}startProviding(t){for(let e of t)this.pvs.set(e.name,new Ir(e))}stopProviding(t){for(let e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}},Ir=class{constructor(t){this.pv=t;let e=new Ee;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()}pv;compiledFormula;trigger(){let t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}};function No(p){return!isNaN(p)&&(Number.isInteger(parseFloat(p))||p%1!==0)}function ko(p){return No(p)?parseFloat(p):(console.warn(`Not a valid float: ${p}`),p)}function Do(p){return p!=null?String(p):p}var Pi=class extends Yt{constructor(e,i,r,s){super(e,i);this.type=r;this.initializer=s;this.writable=!0}type;initializer;setSample(e){if(this.type==="VDouble")e.value=ko(e.value);else if(this.type==="VDoubleArray")for(let i=0;i<e.value.length;i++)e.value[i]=ko(e.value);else if(this.type==="VString")e.value=Do(e.value);else if(this.type==="VStringArray")for(let i=0;i<e.value.length;i++)e.value[i]=Do(e.value);else typeof e.value=="string"&&No(e.value)&&(e.value=parseFloat(e.value));super.setSample(e)}};var Fo=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function se(p){if(!p.startsWith("loc://"))return p;let t=p.match(Fo);return t?t[1]:p}var vi=class{constructor(t){this.display=t}display;rules=[];scripts=[];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.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){let e=se(t);return this.pvs.has(e)}getPV(t){let e=se(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 Yt(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(Fo),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 Pi(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=se(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=se(e),l=this.pvs.get(a);if(l){l.setSample({time:t,value:i,severity:r,units:s});for(let c of this.listeners.get(a)||[])c()}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 Br(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);this.addListener(l,()=>{if(e.checkConnect)for(let c=0;c<e.inputs.length;c++){let h=r[c],u=e.inputs[c].trigger,g=h.value!==null&&h.value!==void 0;if(h.disconnected||u&&!g)return}s.scriptEngine.run(a)},!1)}}return s}createRule(t,e){let i=[];for(let o of e.inputs){let n=t.expandMacro(o.pvName);i.push(this.createPV(n))}let r=new Wr(t,e,i);this.rules.push(r);let s=()=>r.scriptEngine.run();for(let o of e.inputs)if(o.trigger){let n=t.expandMacro(o.pvName);this.addListener(n,s,!1)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){let r=se(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=se(t),r=this.listeners.get(i);if(r){let s=r.indexOf(e);s!==-1&&r.splice(s,1)}}},Br=class{constructor(t,e,i,r){this.widget=t;this.script=e;this.text=i;this.pvs=r;this.scriptEngine=new Lt(t,i,r)}widget;script;text;pvs;scriptEngine},Wr=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 u of e.expressions)u.expression.match(/pv[0-9]+/)&&(o=!0),e.outputExpression&&u.outputValue.toString().match(/pv[0-9]+/)&&(o=!0),u.expression.indexOf("pvInt")!==-1&&(n=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvInt")!==-1&&(n=!0),u.expression.indexOf("pvStr")!==-1&&(a=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvStr")!==-1&&(a=!0),u.expression.indexOf("pvSev")!==-1&&(l=!0),e.outputExpression&&u.outputValue.toString().indexOf("pvSev")!==-1&&(l=!0);for(let u=0;u<i.length;u++)o&&(r+=`var pv${u} = PVUtil.getDouble(pvs[${u}]);
9
9
  `),n&&(r+=`var pvInt${u} = PVUtil.getLong(pvs[${u}]);
10
10
  `),a&&(r+=`var pvStr${u} = PVUtil.getString(pvs[${u}]);
11
11
  `),l&&(r+=`var pvSev${u} = PVUtil.getSeverity(pvs[${u}]);
12
12
  `);for(let u=0;u<e.expressions.length;u++){let g=e.expressions[u].expression,v=e.expressions[u].outputValue;if(u>0&&(r+="else "),r+=`if (${g}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)r+=`${v});
13
13
  `;else{let b=this.printScriptValue(s,v);r+=`${b});
14
14
  `}}let c=s.value,h=this.printScriptValue(s,c);r+=`else widget.setPropertyValue("${e.propertyName}", `,r+=`${h});
15
- `}this.scriptEngine=new At(t,r,i)}widget;rule;scriptEngine;printScriptValue(t,e){return e==null?"null":t.printScriptValue(e)}};var It=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))}pv;interval;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)}},ht=class extends It{constructor(t,e){super(t,-1,e)}generateSample(){}},Ri=class extends It{constructor(e,i){super(e,1e3);this.formatter=i}formatter;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 Ve=class extends It{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}min;max;generateSample(e){let i=Math.random()*(this.max-this.min)+this.min;this.emit(e,i)}},Me=class extends It{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}avg;stddev;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 It{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}min;max;samplesPerCycle;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)}},le=class extends It{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}min;max;inc;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 $u=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/,Ti=class{pvs=new Map;canProvide(t){return t.startsWith("sim://")}startProviding(t){for(let e of t){let i=new Wr(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()}},Wr=class{constructor(t){this.pv=t;let e=t.name.match($u);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 ht(t,void 0)}pv;fn;createGenerator(t,e){switch(t){case"const":let i=this.saferEval(e[0]);return new ht(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 ht(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(t.length===0)return new Ve(this.pv,-5,5,1e3);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new Ve(this.pv,e,i,r)}}createGaussianNoise(t){if(t.length===0)return new Me(this.pv,0,1,100);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new Me(this.pv,e,i,r)}}createRamp(t){let e;if(t.length===0)e=new le(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 le(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 le(this.pv,i,r,s,o)}else return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new ht(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 ht(this.pv,void 0);return e}};var Uu=/sys\:\/\/([a-zA-Z]+)/,Ci=class{constructor(t){this.formatter=t}formatter;pvs=new Map;canProvide(t){return t==="sys://time"}startProviding(t){for(let e of t){let i=new Hr(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()}},Hr=class{constructor(t,e){this.pv=t;this.formatter=e;let i=t.name.match(Uu);i?this.fn=this.createGenerator(i[1]):(console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new ht(t,void 0))}pv;formatter;fn;createGenerator(t){return t==="time"?new Ri(this.pv,this.formatter):(console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new ht(this.pv,void 0))}};var Do="font",No="push_action_index",Fo="release_action_index",Go="toggle_button",$o="image",he=class extends V{areaRegion;pushed=!1;imageElement;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new H(Do)),this.properties.add(new w(Go)),this.properties.add(new P(No)),this.properties.add(new P(Fo)),this.properties.add(new R($o))}init(){this.image&&(this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()},this.imageElement.src=this.resolvePath(this.image)),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"}}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)});let c=this.text.split(`
16
- `);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString();let h,u;if(this.imageElement&&this.imageLoaded){let g=e.measureText(c[0]).width,v=this.font.height,b=this.imageElement.naturalHeight*i,T=this.imageElement.naturalWidth*i,W=(this.height-b)/v,O=(this.width-T)/g,L=5*i;if(O>W){e.textBaseline="middle",e.textAlign="left",h=this.x+(this.width-g)/2+L,u=this.y+this.height/2;let M=this.x+(this.width-g)/2-T,N=this.y+(this.height-b)/2;e.drawImage(this.imageElement,M,N,T,b)}else{e.textAlign="center",e.textBaseline="top";let M=v+b;h=this.x+this.width/2,u=this.y+(this.height-M)/2+b;let N=this.x+(this.width-T)/2,F=this.y+(this.height-M)/2;e.drawImage(this.imageElement,N,F,T,b)}this.pushed&&(h+=1*i,u+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(c[0],h,u)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(c[0],h+1*i,u+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(c[0],h,u))}else{e.textAlign="start",e.textBaseline="top";let g=0;for(let b of c){let T=e.measureText(b).width;g=Math.max(g,T)}h=this.x+(this.width-g)/2;let v=c.length*this.font.height+(c.length-1)*this.font.height*.2;u=this.y+(this.height-v)/2;for(let b of c){let T=h,W=u;this.pushed&&(T+=1*i,W+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(b,T,W)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(b,T+1*i,W+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(b,T,W)),u+=this.font.height*1.2}}}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(Do).scale(this.scale)}get image(){return this.properties.getValue($o)}get toggleButton(){return this.properties.getValue(Go)}get pushActionIndex(){return this.properties.getValue(No)}get releaseActionIndex(){return this.properties.getValue(Fo)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}};var Uo="bit",Yo="data_type",Xo="effect_3d",zo="font",qo="off_color",Ko="off_label",jo="off_state",Zo="on_color",Jo="on_label",Qo="on_state",tn="push_action_index",en="released_action_index",rn="show_led",sn="show_boolean_label",on="square_button",nn="toggle_button",Si=class extends V{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(Uo)),this.properties.add(new P(Yo)),this.properties.add(new w(on)),this.properties.add(new w(rn)),this.properties.add(new w(Xo)),this.properties.add(new S(Zo)),this.properties.add(new R(Jo)),this.properties.add(new R(Qo)),this.properties.add(new S(qo)),this.properties.add(new R(Ko)),this.properties.add(new R(jo)),this.properties.add(new H(zo)),this.properties.add(new w(nn)),this.properties.add(new P(tn)),this.properties.add(new P(en)),this.properties.add(new w(sn))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===this.onState:!1:this.manualToggleState}draw(t){let e=this.booleanValue;this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:e?this.onLabel:this.offLabel})}drawSquare(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&&(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,c=this.height/2,h=Math.sqrt(l*l+c*c),u=this.x+l+(c-l-h)/2-1*i,g=this.y+c-(c-l+h)/2-1*i,v=this.x+l+(c-l+h)/2+5*i,b=this.y+c-(c-l-h)/2+5*i,T=t.createLinearGradient(u,g,v,b);e?(T.addColorStop(0,m.DARK_GRAY.toString()),T.addColorStop(1,m.WHITE.toString())):(T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,m.DARK_GRAY.toString())),t.ctx.fillStyle=T}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?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,c=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:a,ry:l,color:c}),this.effect3d){let h=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);h.addColorStop(0,"white"),h.addColorStop(1,c.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,a,l,0,0,2*Math.PI),t.ctx.fillStyle=h,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,c=s.height/2;if(t.fillEllipse({cx:n,cy:a,rx:l,ry:c,color:o}),this.effect3d){let h=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);h.addColorStop(0,m.WHITE.toString()),h.addColorStop(1,o.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(n,a,l,c,0,0,2*Math.PI),t.ctx.fillStyle=h,t.ctx.fill()}}}get bit(){return this.properties.getValue(Uo)}get dataType(){return this.properties.getValue(Yo)}get toggleButton(){return this.properties.getValue(nn)}get pushActionIndex(){return this.properties.getValue(tn)}get releaseActionIndex(){return this.properties.getValue(en)}get squareButton(){return this.properties.getValue(on)}get showLed(){return this.properties.getValue(rn)}get showBooleanLabel(){return this.properties.getValue(sn)}get effect3d(){return this.properties.getValue(Xo)}get onColor(){return this.properties.getValue(Zo)}get onLabel(){return this.properties.getValue(Jo)}get onState(){return this.properties.getValue(Qo)}get offColor(){return this.properties.getValue(qo)}get offLabel(){return this.properties.getValue(Ko)}get offState(){return this.properties.getValue(jo)}get font(){return this.properties.getValue(zo).scale(this.scale)}};var an="bit",ln="data_type",hn="effect_3d",cn="off_color",pn="off_label",dn="off_state",un="on_color",gn="on_label",mn="on_state",fn="push_action_index",xn="released_action_index",wn="toggle_button",Li=class extends V{manualToggleState=!1;shaftRegion;constructor(t,e){super(t,e),this.properties.add(new P(an)),this.properties.add(new P(ln)),this.properties.add(new w(hn)),this.properties.add(new S(un)),this.properties.add(new R(gn)),this.properties.add(new R(mn)),this.properties.add(new S(cn)),this.properties.add(new R(pn)),this.properties.add(new R(dn)),this.properties.add(new P(fn)),this.properties.add(new P(xn)),this.properties.add(new w(wn))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===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),c=Math.floor(1/7*s.width);if(e){let h={x:2*s.x+s.width-o,y:s.height/2-n/2,width:o,height:n},u={x:s.x+s.width/2-a/2+c,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,u,h,!0)}else{let h={x:0,y:s.height/2-n/2,width:o,height:n},u={x:s.x+s.width/2-a/2-c,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,u,h,!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 c={x:s.width/2-o/2,y:0,width:o,height:n},h={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};h.y-=Math.floor(1/7*s.height),this.drawVerticalBar(t,h,c,!0)}else{let c=s.y+s.height/2+l/2+2*this.scale,h={x:s.width/2-o/2,y:s.y+s.height/2-l/2+c-n,width:o,height:n},u={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};u.y+=Math.floor(1/7*s.height),this.drawVerticalBar(t,u,h,!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,c=this.y+e.y+e.height/2,h=e.width/2,u=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(l,c,h,u,0,0,2*Math.PI),a.addEllipse(l,c,h,u,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,c=this.y+i.y+i.height/2,h=i.width/2,u=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(l,c,h,u,0,0,2*Math.PI),a.addEllipse(l,c,h,u,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let{scale:v}=this,b=Math.sqrt(h*h+u*u),T=u-h,W=this.x+i.x+h+(T-b)/2-1*v,O=this.x+i.y+u-(T+b)/2-1*v,L=this.x+i.x+h+(T+b)/2+5*v,M=this.x+i.y+u-(T-b)/2+5*v,N=t.createLinearGradient(W,O,L,M);N.addColorStop(0,`rgba(0,0,0,${s})`),N.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=N,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 c=i.width/2,h=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,a,c,h,0,0,2*Math.PI),o.addEllipse(n,a,c,h,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let u=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);u.addColorStop(0,`rgba(0,0,0,${(r?5:10)/255})`),u.addColorStop(1,`rgba(0,0,0,${(r?180:160)/255})`),t.ctx.fillStyle=u,t.ctx.fill()}}get bit(){return this.properties.getValue(an)}get dataType(){return this.properties.getValue(ln)}get toggleButton(){return this.properties.getValue(wn)}get pushActionIndex(){return this.properties.getValue(fn)}get releaseActionIndex(){return this.properties.getValue(xn)}get effect3d(){return this.properties.getValue(hn)}get onColor(){return this.properties.getValue(un)}get onLabel(){return this.properties.getValue(gn)}get onState(){return this.properties.getValue(mn)}get offColor(){return this.properties.getValue(cn)}get offLabel(){return this.properties.getValue(pn)}get offState(){return this.properties.getValue(dn)}};var yn="bit",bn="enabled",Pn="font",vn="label",_n="selected_color",Yu=16,Xu=new m(130,130,130),zu=new m(94,151,230),qu=4,Ai=class extends V{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(yn)),this.properties.add(new w(bn)),this.properties.add(new H(Pn)),this.properties.add(new R(vn)),this.properties.add(new S(_n,new m(64,64,64)))}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.pv.value!==void 0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.manualToggleState}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(zu,.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:Xu}),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*Yu}get gap(){return this.scale*qu}get bit(){return this.properties.getValue(yn)}get enabled(){return this.properties.getValue(bn)}get selectedColor(){return this.properties.getValue(_n)}get font(){return this.properties.getValue(Pn).scale(this.scale)}get label(){return this.properties.getValue(vn)}};var Rn="enabled",Tn="font",Cn="horizontal",Sn="items",Ln="items_from_pv",An="selected_color",Ei=class extends V{pushedItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new w(Rn)),this.properties.add(new H(Tn)),this.properties.add(new w(Cn)),this.properties.add(new _t(Sn,[])),this.properties.add(new w(Ln)),this.properties.add(new S(An))}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.pv?.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,c=e.y+e.height-n+n/2,h=e.x+e.width-n+n/2;t.strokePath({lineWidth:n,color:s?m.BUTTON_LIGHTEST:m.BLACK,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c)}),t.strokePath({lineWidth:n,color:s?this.backgroundColor:m.BUTTON_DARKER,path:new _(h-n,c-n).lineTo(h-n,a+n).moveTo(h-n,c-n).lineTo(l+n,c-n)}),t.strokePath({lineWidth:n,color:s?m.BLACK:m.BUTTON_LIGHTEST,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n)}),t.strokePath({lineWidth:n,color:s?m.BUTTON_DARKER:this.backgroundColor,path:new _(l+n,a+n).lineTo(h-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,c-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(Rn)}get font(){return this.properties.getValue(Tn).scale(this.scale)}get horizontal(){return this.properties.getValue(Cn)}get items(){return this.properties.getValue(Sn)}get itemsFromPV(){return this.properties.getValue(Ln)}get selectedColor(){return this.properties.getValue(An)}};var En="enabled",On="font",Vn="items",Mn="items_from_pv",Ku=8,ju=new m(0,0,0,.1),Oi=class extends V{areaRegion;selectEl;renderedItems;constructor(t,e){super(t,e),this.properties.add(new w(En)),this.properties.add(new H(On)),this.properties.add(new _t(Vn,[])),this.properties.add(new w(Mn))}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:ju,crispen:!0}),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height);let r=this.pv?.value??this.value;if(r){let a=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let l of a){let c=l===r;if(!c)try{c=parseFloat(l)===r}catch{}c&&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*Ku}get enabled(){return this.properties.getValue(En)}get font(){return this.properties.getValue(On).scale(this.scale)}get items(){return this.properties.getValue(Vn)}get itemsFromPV(){return this.properties.getValue(Mn)}};var In="bit",Bn="data_type",Wn="effect_3d",Hn="font",kn="off_image",Dn="off_label",Nn="off_state",Fn="on_image",Gn="on_label",$n="on_state",Un="push_action_index",Yn="released_action_index",Xn="show_boolean_label",zn="toggle_button",Vi=class extends V{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(In)),this.properties.add(new P(Bn)),this.properties.add(new w(Wn)),this.properties.add(new R(Fn)),this.properties.add(new R(Gn)),this.properties.add(new R($n)),this.properties.add(new R(kn)),this.properties.add(new R(Dn)),this.properties.add(new R(Nn)),this.properties.add(new H(Hn)),this.properties.add(new w(zn)),this.properties.add(new P(Un)),this.properties.add(new P(Yn)),this.properties.add(new w(Xn))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage)),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===this.onState:!1:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=D(e,2*this.scale,2*this.scale));let i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue(In)}get dataType(){return this.properties.getValue(Bn)}get toggleButton(){return this.properties.getValue(zn)}get pushActionIndex(){return this.properties.getValue(Un)}get releaseActionIndex(){return this.properties.getValue(Yn)}get showBooleanLabel(){return this.properties.getValue(Xn)}get effect3d(){return this.properties.getValue(Wn)}get onImage(){return this.properties.getValue(Fn)}get onLabel(){return this.properties.getValue(Gn)}get onState(){return this.properties.getValue($n)}get offImage(){return this.properties.getValue(kn)}get offLabel(){return this.properties.getValue(Dn)}get offState(){return this.properties.getValue(Nn)}get font(){return this.properties.getValue(Hn).scale(this.scale)}};var qn="font",Kn="label",Mi=class extends V{areaRegion;selectEl;constructor(t,e){super(t,e),this.properties.add(new H(qn)),this.properties.add(new R(Kn))}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]?.toString()??"",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(qn).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(Kn)}};var Ii=class extends he{};var jn="enabled",Zn="font",Jn="horizontal",Qn="items",ta="items_from_pv",ea="selected_color",Zu=7,Ju=2,Qu=4,tg=new m(120,120,120),eg=new m(94,151,230),Bi=class extends V{hoveredItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new w(jn)),this.properties.add(new H(Zn)),this.properties.add(new w(Jn)),this.properties.add(new _t(Qn,[])),this.properties.add(new w(ta)),this.properties.add(new S(ea))}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(eg,.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:tg,lineWidth:l}),(this.pv?.value??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*Zu}get dotRadius(){return this.scale*Ju}get gap(){return this.scale*Qu}get enabled(){return this.properties.getValue(jn)}get font(){return this.properties.getValue(Zn).scale(this.scale)}get horizontal(){return this.properties.getValue(Jn)}get items(){return this.properties.getValue(Qn)}get itemsFromPV(){return this.properties.getValue(ta)}get selectedColor(){return this.properties.getValue(ea)}};var ia="enabled",ra="font",sa="maximum",oa="minimum",na="horizontal",aa="step_increment",la="page_increment",ha="bar_length",ca="show_value_tip",pa=new m(243,243,243),ce=new m(232,232,231),Wi=150,Hi=class extends V{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 w(ia)),this.properties.add(new w(na)),this.properties.add(new w(ca)),this.properties.add(new H(ra)),this.properties.add(new B(sa)),this.properties.add(new B(oa)),this.properties.add(new B(aa)),this.properties.add(new B(la)),this.properties.add(new B(ha))}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:pa});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,c=i.width-r-r,h=Math.floor(Math.max(6*e,c*s/a));this.dragRange=c-h;let u=this.getCoercedValue(),g=Math.floor((c-h)*(u-n)/l),v=c-g-h,b={x:i.x+r+g,y:i.y,width:h,height:i.height};t.fillRect({...b,color:ce}),this.drawRaisedButtonBorder(t,b),t.addHitRegion(this.thumbRegion).addRect(b.x,b.y,b.width,b.height);let W={x:i.x+r,y:i.y,width:g,height:i.height};t.addHitRegion(this.pageDecreaseRegion).addRect(W.x,W.y,W.width,W.height),this.pageDecreasePressed&&t.fillRect({...W,color:m.BLACK});let L={x:i.x+r+g+h,y:i.y,width:v,height:i.height};t.addHitRegion(this.pageIncreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageIncreasePressed&&t.fillRect({...L,color:m.BLACK})}drawVertical(t){let{scale:e}=this,i=D(this.bounds,e);t.fillRect({...i,color:pa});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,c=i.height-r-r,h=Math.floor(Math.max(6*e,c*s/a));this.dragRange=c-h;let u=this.getCoercedValue(),g=Math.floor((c-h)*(u-n)/l),v=c-g-h,b={x:i.x,y:i.y+r+g,width:i.width,height:h};t.fillRect({...b,color:ce}),this.drawRaisedButtonBorder(t,b),t.addHitRegion(this.thumbRegion).addRect(b.x,b.y,b.width,b.height);let W={x:i.x,y:i.y+r,width:i.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(W.x,W.y,W.width,W.height),this.pageDecreasePressed&&t.fillRect({...W,color:m.BLACK});let L={x:i.x,y:i.y+r+g+h,width:i.width,height:v};t.addHitRegion(this.pageIncreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageIncreasePressed&&t.fillRect({...L,color:m.BLACK})}drawLeftButton(t,e){t.fillRect({...e,color:ce}),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 _(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:ce}),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 _(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:ce}),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 _(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:ce}),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 _(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,c=e.y+e.height-n+n/2,h=e.x+e.width-n+n/2;t.strokePath({color:i,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c)}),t.strokePath({color:r,path:new _(h-n,c-n).lineTo(h-n,a+n).moveTo(h-n,c-n).lineTo(l+n,c-n)}),t.strokePath({color:s,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n)}),t.strokePath({color:o,path:new _(l+n,a+n).lineTo(h-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,c-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepIncreaseRepeatedly(),Wi)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepDecreaseRepeatedly(),Wi)}stepIncrease(){let t=this.pv?.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.stepIncrement)}stepDecrease(){let t=this.pv?.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(),Wi)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageDecreaseRepeatedly(),Wi)}pageIncrease(){let t=this.pv?.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.pageIncrement)}pageDecrease(){let t=this.pv?.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.pv?.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(ia)}get horizontal(){return this.properties.getValue(na)}get showValueTip(){return this.properties.getValue(ca)}get font(){return this.properties.getValue(ra).scale(this.scale)}get minimum(){return this.properties.getValue(oa)}get maximum(){return this.properties.getValue(sa)}get stepIncrement(){return this.properties.getValue(aa)}get pageIncrement(){return this.properties.getValue(la)}get barLength(){return this.properties.getValue(ha)}};var da="confirm_message",ua="font",ga="format_type",ma="horizontal_alignment",fa="multiline_input",xa="password_input",wa="precision",ya="precision_from_pv",ba="show_units",ig="text",Pa="vertical_alignment",ki=class extends V{areaRegion;inputEl;editing=!1;constructor(t,e){super(t,e),this.properties.add(new R(da)),this.properties.add(new H(ua)),this.properties.add(new P(ga)),this.properties.add(new P(ma)),this.properties.add(new w(fa)),this.properties.add(new w(xa,!1)),this.properties.add(new P(wa)),this.properties.add(new w(ya)),this.properties.add(new w(ba,!0)),this.properties.add(new P(Pa,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.pv?.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||"";!this.confirmMessage||confirm(this.confirmMessage)?(this.value=e,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,e),this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()):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)}cancelInput(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){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 r=document.createElement("canvas");r.width=this.area.width,r.height=this.area.height;let s=r.getContext("2d");s.fillStyle=this.alarmSensitiveForegroundColor.toString(),s.font=this.font.getFontString();let o=this.x;this.horizAlignment===0?s.textAlign="start":this.horizAlignment===1?(o+=this.width/2,s.textAlign="center"):this.horizAlignment===2&&(o+=this.width,s.textAlign="end");let n=this.y;this.vertAlignment===0?s.textBaseline="top":this.vertAlignment===1?(n=n+this.height/2,s.textBaseline="middle"):this.vertAlignment===2&&(n=n+this.height,s.textBaseline="bottom");let a=this.text;if(this.pv&&this.pv.value!==void 0){let l=this.precisionFromPV?this.pv.precision:this.precision;l===-1&&(l=this.pv.precision??-1),a=Ft(this.pv.value,this.formatType,l,this.pv.typeHint),this.showUnits&&this.pv?.units&&(a+=" "+this.pv.units)}s.fillText(a,o-this.area.x,n-this.area.y),i.drawImage(r,this.area.x,this.area.y)}hide(){this.editing=!1,this.inputEl&&(this.inputEl.style.display="none")}destroy(){this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0)}get value(){return this.text}set value(t){this.properties.setValue(ig,t),this.requestRepaint()}get confirmMessage(){return this.properties.getValue(da)}get font(){return this.properties.getValue(ua).scale(this.scale)}get formatType(){return this.properties.getValue(ga)}get horizAlignment(){return this.properties.getValue(ma)}get multilineInput(){return this.properties.getValue(fa)}get passwordInput(){return this.properties.getValue(xa)}get precision(){return this.properties.getValue(wa)}get precisionFromPV(){return this.properties.getValue(ya)}get showUnits(){return this.properties.getValue(ba)}get vertAlignment(){return this.properties.getValue(Pa)}};var va="alpha",_a="fill",Ra="line_width",Ta="line_style",Ca="start_angle",Sa="total_angle",Di=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(va,255)),this.properties.add(new P(Ra)),this.properties.add(new P(Ca)),this.properties.add(new P(Sa)),this.properties.add(new w(_a)),this.properties.add(new P(Ta))}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=-$(this.startAngle),n=-$(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,ry:s,startAngle:o,endAngle:n,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:a})}}get alpha(){return this.properties.getValue(va)}get lineWidth(){return this.scale*this.properties.getValue(Ra)}get lineStyle(){return this.properties.getValue(Ta)}get startAngle(){return this.properties.getValue(Ca)}get totalAngle(){return this.properties.getValue(Sa)}get fill(){return this.properties.getValue(_a)}};var La="alpha",Aa="bg_gradient_color",Ea="fg_gradient_color",Oa="fill_level",Va="gradient",Ma="horizontal_fill",Ia="line_color",Ba="line_width",Wa="line_style",Ni=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(La,255)),this.properties.add(new S(Aa)),this.properties.add(new S(Ea)),this.properties.add(new w(Va)),this.properties.add(new P(Ba)),this.properties.add(new B(Oa)),this.properties.add(new w(Ma)),this.properties.add(new S(Ia)),this.properties.add(new P(Wa))}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})}this.lineWidth&&(this.lineStyle===0?t.strokeEllipse({cx:e,cy:i,rx:r,ry:s,color:this.lineColor,lineWidth:this.lineWidth}):this.lineStyle===1?t.strokeEllipse({cx:e,cy:i,rx:r,ry:s,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,c=t.createLinearGradient(this.x,this.y,a,l);c.addColorStop(0,this.foregroundGradientStartColor.toString()),c.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:c})}else t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(La)}get lineWidth(){return this.scale*this.properties.getValue(Ba)}get fillLevel(){return this.properties.getValue(Oa)}get horizontalFill(){return this.properties.getValue(Ma)}get lineColor(){return this.properties.getValue(Ia)}get lineStyle(){return this.properties.getValue(Wa)}get gradient(){return this.properties.getValue(Va)}get backgroundGradientStartColor(){return this.properties.getValue(Aa)}get foregroundGradientStartColor(){return this.properties.getValue(Ea)}};var Ha="image_file",ka="no_animation",Da="transparency",Fi=class extends V{currentImageFile;imageElement;imageSnapshot;imageLoading=!1;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new R(Ha)),this.properties.add(new R(ka)),this.properties.add(new w(Da,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoading&&this.imageSnapshot?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile&&(this.currentImageFile=this.imageFile,this.imageElement.src=this.resolvePath(this.imageFile))}snapshotImage(t){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue(Da)}get imageFile(){return this.properties.getValue(Ha)}get noAnimation(){return this.properties.getValue(ka)}};var Na="font",Fa="horizontal_alignment",Ga="vertical_alignment",$a="wrap_words",Gi=class extends V{constructor(t,e){super(t,e),this.properties.add(new H(Na)),this.properties.add(new P(Fa)),this.properties.add(new P(Ga)),this.properties.add(new w($a))}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=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let r=0;for(let a of i){let l=e.measureText(a).width;r=Math.max(r,l)}let s=this.x;this.horizAlignment===1?s=this.x+(this.width-r)/2:this.horizAlignment===2&&(s=this.x+(this.width-r));let o=i.length*this.font.height+(i.length-1)*this.font.height*.2,n=this.y;this.vertAlignment===1?n+=(this.height-o)/2:this.vertAlignment===2&&(n+=this.height-o);for(let a of i)e.fillText(a,s,n),n+=this.font.height*1.2}wrapText(t,e,i){let r=[];for(let s of e.split(`
18
- `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[],s,o,n,a=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(s=e.substr(0,o),o!==e.length)for(n=0;s.indexOf(" ",n)!==-1;n=s.indexOf(" ",n)+1);r.push(s.substr(0,n||s.length)),a=Math.max(a,t.measureText(r[r.length-1],this.font).width),e=e.substr(r[r.length-1].length,e.length)}return r}get font(){return this.properties.getValue(Na).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Fa)}get vertAlignment(){return this.properties.getValue(Ga)}get wrapWords(){return this.properties.getValue($a)}};var Ua="alpha",Ya="fill_level",Xa="horizontal_fill",za="line_color",qa="line_style",Ka="line_width",pe="points",$i=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(Ua,255)),this.properties.add(new P(Ka)),this.properties.add(new B(Ya)),this.properties.add(new w(Xa)),this.properties.add(new S(za)),this.properties.add(new P(qa)),this.properties.add(new vt(pe,[]))}init(){this.addPropertyListener("x",(t,e)=>{let i=this.properties.getValue(pe),r=Zt(i,t-e,0);this.properties.setValue(pe,r),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=this.properties.getValue(pe),r=Zt(i,0,t-e);this.properties.setValue(pe,r),this.requestRepaint()})}draw(t){let{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;let i=_.fromPoints(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+=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 c=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:c}),t.ctx.restore()}get alpha(){return this.properties.getValue(Ua)}get lineWidth(){return this.scale*this.properties.getValue(Ka)}get fillLevel(){return this.properties.getValue(Ya)}get horizontalFill(){return this.properties.getValue(Xa)}get lineColor(){return this.properties.getValue(za)}get lineStyle(){return this.properties.getValue(qa)}get points(){return Nt(this.properties.getValue(pe),this.scale)}};var ja="alpha",Za="arrows",Ja="arrow_length",Qa="fill_arrow",tl="fill_level",el="horizontal_fill",il="line_width",rl="points",Ui=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(ja,255)),this.properties.add(new P(il)),this.properties.add(new B(tl)),this.properties.add(new w(el)),this.properties.add(new vt(rl,[])),this.properties.add(new P(Ja)),this.properties.add(new w(Qa)),this.properties.add(new P(Za))}draw(t){let e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,r=this.height;this.horizontalFill?i*=this.fillLevel/100:(r*=this.fillLevel/100,e+=r),t.save();let s=this.x-this.lineWidth/2,o=e-this.lineWidth/2,n=i+this.lineWidth,a=r+this.lineWidth;t.beginPath(),t.rect(s,o,n,a),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let i=0;i<this.points.length;i++)i===0?t.moveTo(this.points[i].x,this.points[i].y):t.lineTo(this.points[i].x,this.points[i].y);if(t.stroke(),this.points.length>=2){let i=this.points[0],r=this.points[this.points.length-1];if(this.arrows===2||this.arrows===3){let s=this.calculateArrowPoints(this.points[this.points.length-2],r);if(s[2]=r,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let o=0;o<s.length;o++)o===0?t.moveTo(s[o].x,s[o].y):t.lineTo(s[o].x,s[o].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(s[0].x,s[0].y),t.moveTo(r.x,r.y),t.lineTo(s[1].x,s[1].y),t.stroke()}if(this.arrows===1||this.arrows===3){let s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let o=0;o<s.length;o++)o===0?t.moveTo(s[o].x,s[o].y):t.lineTo(s[o].x,s[o].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){let i=Ne(e,t),r=Math.PI/10,s=new lt(this.arrowLength,i.theta-r),o=new lt(this.arrowLength,i.theta+r),n=new lt(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=yt(s.toPoint(),e.x,e.y),l=yt(o.toPoint(),e.x,e.y),c=yt(n.toPoint(),e.x,e.y);return[a,l,c]}get alpha(){return this.properties.getValue(ja)}get lineWidth(){return this.scale*this.properties.getValue(il)}get fillLevel(){return this.properties.getValue(tl)}get horizontalFill(){return this.properties.getValue(el)}get points(){let t=Nt(this.properties.getValue(rl),this.scale);return Ps(t)}get arrows(){return this.properties.getValue(Za)}get fillArrow(){return this.properties.getValue(Qa)}get arrowLength(){return this.properties.getValue(Ja)}};var sl="alpha",ol="bg_gradient_color",nl="fg_gradient_color",al="fill_level",ll="gradient",hl="horizontal_fill",cl="line_color",pl="line_width",dl="line_style",Yi=class extends V{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(sl,255)),this.properties.add(new S(ol)),this.properties.add(new S(nl)),this.properties.add(new w(ll)),this.properties.add(new P(pl)),this.properties.add(new B(al)),this.properties.add(new w(hl)),this.properties.add(new S(cl)),this.properties.add(new P(dl))}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(sl)}get lineWidth(){return this.scale*this.properties.getValue(pl)}get fillLevel(){return this.properties.getValue(al)}get horizontalFill(){return this.properties.getValue(hl)}get lineColor(){return this.properties.getValue(cl)}get lineStyle(){return this.properties.getValue(dl)}get gradient(){return this.properties.getValue(ll)}get backgroundGradientStartColor(){return this.properties.getValue(ol)}get foregroundGradientStartColor(){return this.properties.getValue(nl)}};var ul="alpha",gl="bg_gradient_color",ml="corner_width",fl="corner_height",xl="fg_gradient_color",wl="fill_level",yl="gradient",bl="horizontal_fill",Pl="line_color",vl="line_width",_l="line_style",Xi=class extends V{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(ul,255)),this.properties.add(new S(gl)),this.properties.add(new S(xl)),this.properties.add(new w(yl)),this.properties.add(new P(vl)),this.properties.add(new B(wl)),this.properties.add(new w(bl)),this.properties.add(new S(Pl)),this.properties.add(new P(ml)),this.properties.add(new P(fl)),this.properties.add(new P(_l))}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(ul)}get lineWidth(){return this.scale*this.properties.getValue(vl)}get fillLevel(){return this.properties.getValue(wl)}get horizontalFill(){return this.properties.getValue(bl)}get lineColor(){return this.properties.getValue(Pl)}get lineStyle(){return this.properties.getValue(_l)}get gradient(){return this.properties.getValue(yl)}get cornerWidth(){return this.scale*this.properties.getValue(ml)}get cornerHeight(){return this.scale*this.properties.getValue(fl)}get backgroundGradientStartColor(){return this.properties.getValue(gl)}get foregroundGradientStartColor(){return this.properties.getValue(xl)}};var Rl="bitReverse",Tl="effect_3d",Cl="horizontal",Sl="led_border",Ll="led_border_color",Al="led_packed",El="numBits",Ol="off_color",Vl="on_color",Ml="startBit",Il="square_led",zi=class extends V{constructor(t,e){super(t,e),this.properties.add(new w(Rl)),this.properties.add(new w(Tl)),this.properties.add(new w(Cl)),this.properties.add(new P(El)),this.properties.add(new S(Ol)),this.properties.add(new S(Vl)),this.properties.add(new P(Ml)),this.properties.add(new w(Il)),this.properties.add(new P(Sl,3)),this.properties.add(new S(Ll,m.DARK_GRAY)),this.properties.add(new w(Al,!1))}getLedColor(t){let e=!1;if(this.pv?.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.pv?.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,c=e.height-2*this.ledBorder;o=l/2,n=c/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=wt(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(Rl)}get horizontal(){return this.properties.getValue(Cl)}get numBits(){return this.properties.getValue(El)}get startBit(){return this.properties.getValue(Ml)}get ledPacked(){return this.properties.getValue(Al)}get ledBorder(){return this.scale*this.properties.getValue(Sl)}get ledBorderColor(){return this.properties.getValue(Ll)}get offColor(){return this.properties.getValue(Ol)}get onColor(){return this.properties.getValue(Vl)}get effect3d(){return this.properties.getValue(Tl)}get squareLed(){return this.properties.getValue(Il)}};var st=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,c=this.maxFrac;if(n&&(a-=2,l+=2,c+=2),o.length>c){let g=+("0."+o);g=c==0?Math.round(g):g.toFixed(c),o=g.toString(10).substr(2);let v=g>=1?1:0,b,T=s.length-1;for(;v;)if(T==-1){s="1"+s;break}else b=Number(s.charAt(T)),b===9?(b="0",v=1):(b=++b+"",v=0),s=s.substring(0,T)+b+s.substring(T+1,s.length),T--}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 h=0;for(let g=s.length;g>0;g--)h!=0&&h%this.comma==0&&(s=s.substring(0,g)+","+s.substring(g),h=0),h++;let u;return o.length>0?u=this.prefix+s+"."+o+this.suffix:u=this.prefix+s+this.suffix,i&&(u="-"+u),u}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 rg=1,sg=8,Q=2,de=class{constructor(t,e,i){this.rampWidth=t;this.startAngle=e;this.endAngle=i}rampWidth;startAngle;endAngle;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){if(this.labelsOutside){let r=rg+sg;this.radius=e.width/2-r}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(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 v=n,b=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:$(v),endAngle:$(b),color:this.loloColor})}if(this.showLo){let v;this.showLoLo?v=this.lolo:v=this.minimum;let b=360-this.getValuePosition(v,!0),T=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){let W=$(this.getValuePosition(v,!0)-Q),O=bt(e.width/2,W,e),L=$(this.getValuePosition(this.lo,!0)+Q),M=bt(e.width/2,L,e),N=t.createLinearGradient(O.x,O.y,M.x,M.y);N.addColorStop(0,this.loloColor.toString()),N.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:$(b-Q/2),endAngle:$(T+Q/2),gradient:N})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b),endAngle:$(T),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let c=this.maximum;this.showHi?c=this.hi:this.showHiHi&&(c=this.hihi);let h=(l+c)/2,u=360-this.getValuePosition(l,!0),g=360-this.getValuePosition(h,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){let v=$(this.getValuePosition(l,!0)-Q),b=bt(e.width/2,v,e),T=$(this.getValuePosition(h,!0)+Q),W=bt(e.width/2,T,e),O=t.createLinearGradient(b.x,b.y,W.x,W.y);O.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),O.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:$(u-Q/2),endAngle:$(g+Q/2),gradient:O})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u),endAngle:$(g),color:m.GREEN});if(u=360-this.getValuePosition(h,!0),g=360-this.getValuePosition(c,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){let v=$(this.getValuePosition(h,!0)-Q),b=bt(e.width/2,v,e),T=$(this.getValuePosition(c,!0)+Q),W=bt(e.width/2,T,e),O=t.createLinearGradient(b.x,b.y,W.x,W.y);O.addColorStop(0,m.GREEN.toString()),O.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());let L=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:$(u-Q/2),endAngle:$(g+L),gradient:O})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u),endAngle:$(g),color:m.GREEN});if(this.showHi){let v;this.showHiHi?v=this.hihi:v=this.maximum;let b=360-this.getValuePosition(this.hi,!0),T=360-this.getValuePosition(v,!0);if(this.effect3d&&this.gradient&&this.showHiHi){let W=$(this.getValuePosition(this.hi,!0)-Q),O=bt(e.width/2,W,e),L=$(this.getValuePosition(v,!0)+Q),M=bt(e.width/2,L,e),N=t.createLinearGradient(O.x,O.y,M.x,M.y);N.addColorStop(0,this.hiColor.toString()),N.addColorStop(1,this.hihiColor.toString());let F=T!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b-Q/2),endAngle:$(T+F),gradient:N})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b),endAngle:$(T),color:this.hiColor})}if(this.showHiHi){u=360-this.getValuePosition(this.hihi,!0),g=a;let v=this.gradient?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u-v),endAngle:$(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 Bl=new m(100,100,100),og=16,ng=8,ag=5,lg=-1,Wl="color_hi",Hl="color_hihi",kl="color_lo",Dl="color_lolo",Nl="effect_3d",Fl="font",Gl="value_label_format",$l="level_hi",Ul="level_hihi",Yl="level_lo",Xl="level_lolo",zl="limits_from_pv",ql="log_scale",Kl="minimum",jl="maximum",Zl="needle_color",Jl="ramp_gradient",Ql="show_ramp",kr=225,hg=315;var qi=class extends V{constructor(t,e){super(t,e),this.properties.add(new S(Wl)),this.properties.add(new S(Hl)),this.properties.add(new S(kl)),this.properties.add(new S(Dl)),this.properties.add(new w(Nl)),this.properties.add(new H(Fl)),this.properties.add(new B($l)),this.properties.add(new B(Ul)),this.properties.add(new B(Yl)),this.properties.add(new B(Xl)),this.properties.add(new w(ql)),this.properties.add(new w(zl)),this.properties.add(new B(jl)),this.properties.add(new B(Kl)),this.properties.add(new S(Zl)),this.properties.add(new w(Jl)),this.properties.add(new w(Ql,!0)),this.properties.add(new R(Gl))}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.drawLabel(t,i,r),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,Bl.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=$(0),c=$(35),h={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)},u=t.createLinearGradient(h.x,h.y,h.x,h.y+h.height);u.addColorStop(0,m.WHITE.withAlpha(90/255).toString()),u.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:h.x+h.width/2,cy:h.y+h.height/2,rx:h.width/2,ry:h.height/2,gradient:u}),h={x:Math.floor(this.x+e/2-s*a*Math.sin(c)),y:Math.floor(Math.ceil(this.y+i/2+s*n)),width:Math.floor(2*s*a*Math.sin(c)),height:Math.floor(Math.ceil(s*o-s*n))},u=t.createLinearGradient(h.x,h.y,h.x,h.y+h.height),u.addColorStop(0,m.WHITE.withAlpha(0).toString()),u.addColorStop(1,m.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:h.x+h.width/2,cy:h.y+h.height/2,rx:h.width/2,ry:h.height/2,gradient:u})}}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 de(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)}drawLabel(t,e,i){let r=q.ARIAL_12_BOLD.scale(this.scale);if(this.pv?.value!==void 0){let s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+i*7/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,r){let s=this.x+e/2,o=this.y+i/2,n;if(this.pv?.value!==void 0){let T=this.getValueInRange(this.pv.value,r);n=360-this.getValuePosition(T,r),r.max>r.min?T>r.max?n+=10:T<r.min&&(n-=10):T>r.min?n-=10:T<r.max&&(n+=10)}else n=360-this.getValuePosition((r.min+r.max)/2,r);let a=$(n),{scale:l}=this,{needleDiameter:c,majorTickLength:h,gapBetweenNeedleScale:u}=this,g=Ct(s,o-c/2+3*l,s,o,a),v=Ct(s+e/2-h-u,o,s,o,a),b=Ct(s,o+c/2-3*l,s,o,a);t.fillPath({color:this.needleColor,path:new _(g.x,g.y).lineTo(v.x,v.y).lineTo(b.x,b.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,Bl.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-(hg-kr),r;return this.logScale?r=kr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*i:r=kr-(t-e.min)/(e.max-e.min)*i,r<0&&(r+=360),r}formatLabelValue(t){return this.valueLabelFormat?new st(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return this.scale*og}get majorTickLength(){return this.scale*ng}get minorTickLength(){return this.scale*ag}get gapBetweenNeedleScale(){return this.scale*lg}get colorLo(){return this.properties.getValue(kl)}get colorLoLo(){return this.properties.getValue(Dl)}get colorHi(){return this.properties.getValue(Wl)}get colorHiHi(){return this.properties.getValue(Hl)}get effect3d(){return this.properties.getValue(Nl)}get font(){return this.properties.getValue(Fl).scale(this.scale)}get levelLo(){return this.properties.getValue(Yl)}get levelLoLo(){return this.properties.getValue(Xl)}get levelHi(){return this.properties.getValue($l)}get levelHiHi(){return this.properties.getValue(Ul)}get limitsFromPv(){return this.properties.getValue(zl)}get logScale(){return this.properties.getValue(ql)}get minimum(){return this.properties.getValue(Kl)}get maximum(){return this.properties.getValue(jl)}get needleColor(){return this.properties.getValue(Zl)}get rampGradient(){return this.properties.getValue(Jl)}get showRamp(){return this.properties.getValue(Ql)}get valueLabelFormat(){return this.properties.getValue(Gl)}};var th="bit",eh="data_type",ih="off_image",rh="off_label",sh="font",oh="on_image",nh="on_label",ah="show_boolean_label",Ki=class extends V{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new P(th)),this.properties.add(new P(eh)),this.properties.add(new R(ih)),this.properties.add(new R(rh)),this.properties.add(new R(oh)),this.properties.add(new R(nh)),this.properties.add(new H(sh)),this.properties.add(new w(ah))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage))}get booleanValue(){return this.bit<0?!!this.pv?.toNumber():this.pv?.value!==void 0?(this.pv?.value>>this.bit&1)>0:!1}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue(th)}get dataType(){return this.properties.getValue(eh)}get showBooleanLabel(){return this.properties.getValue(ah)}get font(){return this.properties.getValue(sh).scale(this.scale)}get offLabel(){return this.properties.getValue(rh)}get offImage(){return this.properties.getValue(ih)}get onLabel(){return this.properties.getValue(nh)}get onImage(){return this.properties.getValue(oh)}};var cg=["January","February","March","April","May","June","July","August","September","October","November","December"],et=class{constructor(t,e,i,r,s,o,n,a,l,c){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=c}formatter;scale;scaleFont;minimum;maximum;logScale;majorTickStepHint;foregroundColor;showMinorTicks;showScale;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 c=t.measureText(this.labels[l],this.scaleFont);c.height>n&&(n=c.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 c=this.x+this.labelPositions[l],h=this.y,u=0;if(this.labelVisibilities[l]?u=this.majorTickLength:u=this.minorTickLength,this.labelVisibilities[l]||this.showMinorTicks){let g=Math.round(c)-s*.5;t.strokePath({path:new _(g,h).lineTo(g,h+u),color:this.foregroundColor,lineWidth:s*1,opacity:100/255})}this.labelVisibilities[l]&&t.fillText({x:c,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 c=e+this.labelPositions[l];this.labelVisibilities[l]&&t.fillText({x:c,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]});let h=Math.round(c)-s*.5;t.strokePath({path:new _(h,i).lineTo(h,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 h=0;h<this.labels.length;h++){let u=t.measureText(this.labels[h],this.scaleFont);u.width>l&&(l=u.width)}let c=this.showScale?l+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(s||(e=e-c),this.x=e,this.y=i,this.logScale)for(let h=0;h<this.labelPositions.length;h++){let u;this.labelVisibilities[h]?u=this.majorTickLength:u=this.minorTickLength;let g=e+l+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-u,v=Math.round(i+r-this.labelPositions[h])-n*.5;if((this.labelVisibilities[h]||this.showMinorTicks)&&t.strokePath({path:new _(g,v).lineTo(g+u,v),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[h]){let b=i+r-this.labelPositions[h];t.fillText({x:e,y:b,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]})}}else for(let h=0;h<this.labels.length;h++){let u=i+r-this.labelPositions[h],g=Math.round(u)-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[h]){let v=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:v,y:u,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]})}}else{this.labelVisibilities[h]&&t.fillText({x:e,y:u,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]});let v=e+l+this.spaceBetweenMarkAndLabel-n*1;t.strokePath({path:new _(v,g).lineTo(v+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,h,v,i+r)}}return c}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:c}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let h=a[1];for(;h-a[0]>n+3*c;){h=h-n;let u=Math.round(i+h)-c*.5;t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let h=a[e-1];for(;a[e]-h>n+3*c;){h=h+n;let u=Math.round(i+h)-c*.5;t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else for(let h=0;h<o;h++){let u=i+a[e-1]+(a[e]-a[e-1])*h/o;u=Math.round(u)-c*.5,t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*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:c,scale:h}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let u=a[1];for(;u-a[0]>n+3*h;){u-=n;let g=Math.round(r-u)-h*.5;t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let u=a[e-1];for(;a[e]-u>n+3*h;){u+=n;let g=Math.round(r-u)-h*.5;t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else for(let u=0;u<o;u++){let g=r-a[e-1]-(a[e]-a[e-1])*u/o;g=Math.round(g)-h*.5,t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*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 h=e;e=i,i=h}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 c;return a>7.5?c=10*Math.pow(10,l):a>3.5?c=5*Math.pow(10,l):a>1.5?c=2*Math.pow(10,l):c=Math.pow(10,l),r&&(c=-c),c}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 c=o;r?c>=n:c<=n;c+=r?-1:1)if(Math.abs(n-o)>20){let h=Math.pow(10,c);if(h>e)break;this.addTickInfo(h,e,s,i)}else{for(let h=l;(r?h>=Math.pow(10,c-1):h<=Math.pow(10,c))&&!(r?h<e:h>e);h=r?h-a:h+a)this.addTickInfo(h,e,s,i);a=r?a/Math.pow(10,1):a*Math.pow(10,1),l=r?Math.pow(10,c-1):a+Math.pow(10,c)}(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 c=o;e>=t?c<e:c>e;c=o+n++*r){let h=c*a;this.labels.push(this.format(h)),this.labelValues.push(h);let u=Math.floor((c-t)/l*i)+this.margin;this.labelPositions.push(u)}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 c=Number(this.labels[r]);l=this.isMajorTick(c)||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),c=!0,h=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){c=a>l+this.tickLabelGap;let u=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+u.width/2:o.height),h=a>l+this.tickLabelGap}return c&&h}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 st(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})+`
15
+ `}this.scriptEngine=new Lt(t,r,i)}widget;rule;scriptEngine;printScriptValue(t,e){return e==null?"null":t.printScriptValue(e)}};var Mt=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))}pv;interval;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 Mt{constructor(t,e){super(t,-1,e)}generateSample(){}},_i=class extends Mt{constructor(e,i){super(e,1e3);this.formatter=i}formatter;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 Oe=class extends Mt{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}min;max;generateSample(e){let i=Math.random()*(this.max-this.min)+this.min;this.emit(e,i)}},Ve=class extends Mt{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}avg;stddev;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)}},oe=class extends Mt{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}min;max;samplesPerCycle;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)}},ne=class extends Mt{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}min;max;inc;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 Yu=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/,Ri=class{pvs=new Map;canProvide(t){return t.startsWith("sim://")}startProviding(t){for(let e of t){let i=new Hr(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()}},Hr=class{constructor(t){this.pv=t;let e=t.name.match(Yu);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)}pv;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 Oe(this.pv,-5,5,1e3);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new Oe(this.pv,e,i,r)}}createGaussianNoise(t){if(t.length===0)return new Ve(this.pv,0,1,100);{let e=parseFloat(t[0]),i=parseFloat(t[1]),r=parseFloat(t[2])*1e3;return new Ve(this.pv,e,i,r)}}createRamp(t){let e;if(t.length===0)e=new ne(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 ne(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 ne(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 oe(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 oe(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 oe(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 Xu=/sys\:\/\/([a-zA-Z]+)/,Ti=class{constructor(t){this.formatter=t}formatter;pvs=new Map;canProvide(t){return t==="sys://time"}startProviding(t){for(let e of t){let i=new kr(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()}},kr=class{constructor(t,e){this.pv=t;this.formatter=e;let i=t.name.match(Xu);i?this.fn=this.createGenerator(i[1]):(console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new lt(t,void 0))}pv;formatter;fn;createGenerator(t){return t==="time"?new _i(this.pv,this.formatter):(console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new lt(this.pv,void 0))}};var Go="font",$o="push_action_index",Uo="release_action_index",Yo="toggle_button",Xo="image",ae=class extends V{areaRegion;pushed=!1;imageElement;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new H(Go)),this.properties.add(new w(Yo)),this.properties.add(new P($o)),this.properties.add(new P(Uo)),this.properties.add(new R(Xo))}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"}}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)});let c=this.text.split(`
16
+ `);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString();let h,u;if(this.imageElement&&this.imageLoaded){let g=e.measureText(c[0]).width,v=this.font.height,b=this.imageElement.naturalHeight*i,T=this.imageElement.naturalWidth*i,W=(this.height-b)/v,O=(this.width-T)/g,L=5*i;if(O>W){e.textBaseline="middle",e.textAlign="left",h=this.x+(this.width-g)/2+L,u=this.y+this.height/2;let M=this.x+(this.width-g)/2-T,N=this.y+(this.height-b)/2;e.drawImage(this.imageElement,M,N,T,b)}else{e.textAlign="center",e.textBaseline="top";let M=v+b;h=this.x+this.width/2,u=this.y+(this.height-M)/2+b;let N=this.x+(this.width-T)/2,F=this.y+(this.height-M)/2;e.drawImage(this.imageElement,N,F,T,b)}this.pushed&&(h+=1*i,u+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(c[0],h,u)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(c[0],h+1*i,u+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(c[0],h,u))}else{e.textAlign="start",e.textBaseline="top";let g=0;for(let b of c){let T=e.measureText(b).width;g=Math.max(g,T)}h=this.x+(this.width-g)/2;let v=c.length*this.font.height+(c.length-1)*this.font.height*.2;u=this.y+(this.height-v)/2;for(let b of c){let T=h,W=u;this.pushed&&(T+=1*i,W+=1*i),this.enabled?(e.fillStyle=this.foregroundColor.toString(),e.fillText(b,T,W)):(e.fillStyle=m.BUTTON_LIGHTEST.toString(),e.fillText(b,T+1*i,W+1*i),e.fillStyle=m.BUTTON_DARKER.toString(),e.fillText(b,T,W)),u+=this.font.height*1.2}}}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(Go).scale(this.scale)}get image(){return this.properties.getValue(Xo)}get toggleButton(){return this.properties.getValue(Yo)}get pushActionIndex(){return this.properties.getValue($o)}get releaseActionIndex(){return this.properties.getValue(Uo)}get backgroundColor(){let t=this.properties.getProperty("background_color");return t&&t.value!==m.TRANSPARENT?t.value:m.BUTTON}};var zo="bit",qo="data_type",Ko="effect_3d",jo="font",Zo="off_color",Jo="off_label",Qo="off_state",tn="on_color",en="on_label",rn="on_state",sn="push_action_index",on="released_action_index",nn="show_led",an="show_boolean_label",ln="square_button",hn="toggle_button",Ci=class extends V{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(zo)),this.properties.add(new P(qo)),this.properties.add(new w(ln)),this.properties.add(new w(nn)),this.properties.add(new w(Ko)),this.properties.add(new S(tn)),this.properties.add(new R(en)),this.properties.add(new R(rn)),this.properties.add(new S(Zo)),this.properties.add(new R(Jo)),this.properties.add(new R(Qo)),this.properties.add(new H(jo)),this.properties.add(new w(hn)),this.properties.add(new P(sn)),this.properties.add(new P(on)),this.properties.add(new w(an))}init(){let t=this;this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.enabled&&(this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():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"}}}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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===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,c=this.height/2,h=Math.sqrt(l*l+c*c),u=this.x+l+(c-l-h)/2-1*i,g=this.y+c-(c-l+h)/2-1*i,v=this.x+l+(c-l+h)/2+5*i,b=this.y+c-(c-l-h)/2+5*i,T=t.createLinearGradient(u,g,v,b);e?(T.addColorStop(0,m.DARK_GRAY.toString()),T.addColorStop(1,m.WHITE.toString())):(T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,m.DARK_GRAY.toString())),t.ctx.fillStyle=T}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,c=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:a,ry:l,color:c}),this.effect3d){let h=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);h.addColorStop(0,"white"),h.addColorStop(1,c.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,a,l,0,0,2*Math.PI),t.ctx.fillStyle=h,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,c=s.height/2;if(t.fillEllipse({cx:n,cy:a,rx:l,ry:c,color:o}),this.effect3d){let h=t.createLinearGradient(s.x,s.y,s.x+s.width,s.y+s.height);h.addColorStop(0,m.WHITE.toString()),h.addColorStop(1,o.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(n,a,l,c,0,0,2*Math.PI),t.ctx.fillStyle=h,t.ctx.fill()}}}get bit(){return this.properties.getValue(zo)}get dataType(){return this.properties.getValue(qo)}get toggleButton(){return this.properties.getValue(hn)}get pushActionIndex(){return this.properties.getValue(sn)}get releaseActionIndex(){return this.properties.getValue(on)}get squareButton(){return this.properties.getValue(ln)}get showLed(){return this.properties.getValue(nn)}get showBooleanLabel(){return this.properties.getValue(an)}get effect3d(){return this.properties.getValue(Ko)}get onColor(){return this.properties.getValue(tn)}get onLabel(){return this.properties.getValue(en)}get onState(){return this.properties.getValue(rn)}get offColor(){return this.properties.getValue(Zo)}get offLabel(){return this.properties.getValue(Jo)}get offState(){return this.properties.getValue(Qo)}get font(){return this.properties.getValue(jo).scale(this.scale)}};var cn="bit",pn="data_type",dn="effect_3d",un="off_color",gn="off_label",mn="off_state",fn="on_color",xn="on_label",wn="on_state",yn="push_action_index",bn="released_action_index",Pn="toggle_button",Si=class extends V{manualToggleState=!1;shaftRegion;constructor(t,e){super(t,e),this.properties.add(new P(cn)),this.properties.add(new P(pn)),this.properties.add(new w(dn)),this.properties.add(new S(fn)),this.properties.add(new R(xn)),this.properties.add(new R(wn)),this.properties.add(new S(un)),this.properties.add(new R(gn)),this.properties.add(new R(mn)),this.properties.add(new P(yn)),this.properties.add(new P(bn)),this.properties.add(new w(Pn))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===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),c=Math.floor(1/7*s.width);if(e){let h={x:2*s.x+s.width-o,y:s.height/2-n/2,width:o,height:n},u={x:s.x+s.width/2-a/2+c,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,u,h,!0)}else{let h={x:0,y:s.height/2-n/2,width:o,height:n},u={x:s.x+s.width/2-a/2-c,y:s.y+s.height/2-l/2,width:a,height:l};this.drawHorizontalBar(t,u,h,!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 c={x:s.width/2-o/2,y:0,width:o,height:n},h={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};h.y-=Math.floor(1/7*s.height),this.drawVerticalBar(t,h,c,!0)}else{let c=s.y+s.height/2+l/2+2*this.scale,h={x:s.width/2-o/2,y:s.y+s.height/2-l/2+c-n,width:o,height:n},u={x:s.x+s.width/2-a/2,y:s.y+s.height/2-l/2,width:a,height:l};u.y+=Math.floor(1/7*s.height),this.drawVerticalBar(t,u,h,!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,c=this.y+e.y+e.height/2,h=e.width/2,u=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(l,c,h,u,0,0,2*Math.PI),a.addEllipse(l,c,h,u,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,c=this.y+i.y+i.height/2,h=i.width/2,u=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(l,c,h,u,0,0,2*Math.PI),a.addEllipse(l,c,h,u,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let{scale:v}=this,b=Math.sqrt(h*h+u*u),T=u-h,W=this.x+i.x+h+(T-b)/2-1*v,O=this.x+i.y+u-(T+b)/2-1*v,L=this.x+i.x+h+(T+b)/2+5*v,M=this.x+i.y+u-(T-b)/2+5*v,N=t.createLinearGradient(W,O,L,M);N.addColorStop(0,`rgba(0,0,0,${s})`),N.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=N,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 c=i.width/2,h=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,a,c,h,0,0,2*Math.PI),o.addEllipse(n,a,c,h,0,0,2*Math.PI),t.ctx.fillStyle=r?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){let u=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);u.addColorStop(0,`rgba(0,0,0,${(r?5:10)/255})`),u.addColorStop(1,`rgba(0,0,0,${(r?180:160)/255})`),t.ctx.fillStyle=u,t.ctx.fill()}}get bit(){return this.properties.getValue(cn)}get dataType(){return this.properties.getValue(pn)}get toggleButton(){return this.properties.getValue(Pn)}get pushActionIndex(){return this.properties.getValue(yn)}get releaseActionIndex(){return this.properties.getValue(bn)}get effect3d(){return this.properties.getValue(dn)}get onColor(){return this.properties.getValue(fn)}get onLabel(){return this.properties.getValue(xn)}get onState(){return this.properties.getValue(wn)}get offColor(){return this.properties.getValue(un)}get offLabel(){return this.properties.getValue(gn)}get offState(){return this.properties.getValue(mn)}};var vn="bit",_n="enabled",Rn="font",Tn="label",Cn="selected_color",zu=16,qu=new m(130,130,130),Ku=new m(94,151,230),ju=4,Li=class extends V{hovered=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(vn)),this.properties.add(new w(_n)),this.properties.add(new H(Rn)),this.properties.add(new R(Tn)),this.properties.add(new S(Cn,new m(64,64,64)))}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.pv.value!==void 0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.manualToggleState}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(Ku,.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:qu}),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*zu}get gap(){return this.scale*ju}get bit(){return this.properties.getValue(vn)}get enabled(){return this.properties.getValue(_n)}get selectedColor(){return this.properties.getValue(Cn)}get font(){return this.properties.getValue(Rn).scale(this.scale)}get label(){return this.properties.getValue(Tn)}};var Sn="enabled",Ln="font",An="horizontal",En="items",On="items_from_pv",Vn="selected_color",Ai=class extends V{pushedItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new w(Sn)),this.properties.add(new H(Ln)),this.properties.add(new w(An)),this.properties.add(new vt(En,[])),this.properties.add(new w(On)),this.properties.add(new S(Vn))}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.pv?.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,c=e.y+e.height-n+n/2,h=e.x+e.width-n+n/2;t.strokePath({lineWidth:n,color:s?m.BUTTON_LIGHTEST:m.BLACK,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c)}),t.strokePath({lineWidth:n,color:s?this.backgroundColor:m.BUTTON_DARKER,path:new _(h-n,c-n).lineTo(h-n,a+n).moveTo(h-n,c-n).lineTo(l+n,c-n)}),t.strokePath({lineWidth:n,color:s?m.BLACK:m.BUTTON_LIGHTEST,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n)}),t.strokePath({lineWidth:n,color:s?m.BUTTON_DARKER:this.backgroundColor,path:new _(l+n,a+n).lineTo(h-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,c-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(Sn)}get font(){return this.properties.getValue(Ln).scale(this.scale)}get horizontal(){return this.properties.getValue(An)}get items(){return this.properties.getValue(En)}get itemsFromPV(){return this.properties.getValue(On)}get selectedColor(){return this.properties.getValue(Vn)}};var Mn="enabled",In="font",Bn="items",Wn="items_from_pv",Zu=8,Ju=new m(0,0,0,.1),Ei=class extends V{areaRegion;selectEl;renderedItems;constructor(t,e){super(t,e),this.properties.add(new w(Mn)),this.properties.add(new H(In)),this.properties.add(new vt(Bn,[])),this.properties.add(new w(Wn))}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:Ju,crispen:!0}),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height);let r=this.pv?.value??this.value;if(r){let a=this.itemsFromPV?this.pv?.labels??[]:this.items;for(let l of a){let c=l===r;if(!c)try{c=parseFloat(l)===r}catch{}c&&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*Zu}get enabled(){return this.properties.getValue(Mn)}get font(){return this.properties.getValue(In).scale(this.scale)}get items(){return this.properties.getValue(Bn)}get itemsFromPV(){return this.properties.getValue(Wn)}};var Hn="bit",kn="data_type",Dn="effect_3d",Nn="font",Fn="off_image",Gn="off_label",$n="off_state",Un="on_image",Yn="on_label",Xn="on_state",zn="push_action_index",qn="released_action_index",Kn="show_boolean_label",jn="toggle_button",Oi=class extends V{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;manualToggleState=!1;areaRegion;constructor(t,e){super(t,e),this.properties.add(new P(Hn)),this.properties.add(new P(kn)),this.properties.add(new w(Dn)),this.properties.add(new R(Un)),this.properties.add(new R(Yn)),this.properties.add(new R(Xn)),this.properties.add(new R(Fn)),this.properties.add(new R(Gn)),this.properties.add(new R($n)),this.properties.add(new H(Nn)),this.properties.add(new w(jn)),this.properties.add(new P(zn)),this.properties.add(new P(qn)),this.properties.add(new w(Kn))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage){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:()=>{this.toggleButton?this.booleanValue?this.toggleOff():this.toggleOn():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(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.pv.value!==void 0?this.dataType===0?this.bit<0?!!this.pv?.toNumber():(this.pv?.value>>this.bit&1)>0:this.dataType===1?this.pv.toString()===this.onState:!1:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=D(e,2*this.scale,2*this.scale));let i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height),t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue(Hn)}get dataType(){return this.properties.getValue(kn)}get toggleButton(){return this.properties.getValue(jn)}get pushActionIndex(){return this.properties.getValue(zn)}get releaseActionIndex(){return this.properties.getValue(qn)}get showBooleanLabel(){return this.properties.getValue(Kn)}get effect3d(){return this.properties.getValue(Dn)}get onImage(){return this.properties.getValue(Un)}get onLabel(){return this.properties.getValue(Yn)}get onState(){return this.properties.getValue(Xn)}get offImage(){return this.properties.getValue(Fn)}get offLabel(){return this.properties.getValue(Gn)}get offState(){return this.properties.getValue($n)}get font(){return this.properties.getValue(Nn).scale(this.scale)}};var Zn="font",Jn="label",Vi=class extends V{areaRegion;selectEl;constructor(t,e){super(t,e),this.properties.add(new H(Zn)),this.properties.add(new R(Jn))}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]?.toString()??"",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(Zn).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(Jn)}};var Mi=class extends ae{};var Qn="enabled",ta="font",ea="horizontal",ia="items",ra="items_from_pv",sa="selected_color",Qu=7,tg=2,eg=4,ig=new m(120,120,120),rg=new m(94,151,230),Ii=class extends V{hoveredItem;itemRegions=[];constructor(t,e){super(t,e),this.properties.add(new w(Qn)),this.properties.add(new H(ta)),this.properties.add(new w(ea)),this.properties.add(new vt(ia,[])),this.properties.add(new w(ra)),this.properties.add(new S(sa))}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(rg,.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:ig,lineWidth:l}),(this.pv?.value??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*Qu}get dotRadius(){return this.scale*tg}get gap(){return this.scale*eg}get enabled(){return this.properties.getValue(Qn)}get font(){return this.properties.getValue(ta).scale(this.scale)}get horizontal(){return this.properties.getValue(ea)}get items(){return this.properties.getValue(ia)}get itemsFromPV(){return this.properties.getValue(ra)}get selectedColor(){return this.properties.getValue(sa)}};var oa="enabled",na="font",aa="maximum",la="minimum",ha="horizontal",ca="step_increment",pa="page_increment",da="bar_length",ua="show_value_tip",ga=new m(243,243,243),le=new m(232,232,231),Bi=150,Wi=class extends V{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 w(oa)),this.properties.add(new w(ha)),this.properties.add(new w(ua)),this.properties.add(new H(na)),this.properties.add(new B(aa)),this.properties.add(new B(la)),this.properties.add(new B(ca)),this.properties.add(new B(pa)),this.properties.add(new B(da))}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:ga});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,c=i.width-r-r,h=Math.floor(Math.max(6*e,c*s/a));this.dragRange=c-h;let u=this.getCoercedValue(),g=Math.floor((c-h)*(u-n)/l),v=c-g-h,b={x:i.x+r+g,y:i.y,width:h,height:i.height};t.fillRect({...b,color:le}),this.drawRaisedButtonBorder(t,b),t.addHitRegion(this.thumbRegion).addRect(b.x,b.y,b.width,b.height);let W={x:i.x+r,y:i.y,width:g,height:i.height};t.addHitRegion(this.pageDecreaseRegion).addRect(W.x,W.y,W.width,W.height),this.pageDecreasePressed&&t.fillRect({...W,color:m.BLACK});let L={x:i.x+r+g+h,y:i.y,width:v,height:i.height};t.addHitRegion(this.pageIncreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageIncreasePressed&&t.fillRect({...L,color:m.BLACK})}drawVertical(t){let{scale:e}=this,i=D(this.bounds,e);t.fillRect({...i,color:ga});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,c=i.height-r-r,h=Math.floor(Math.max(6*e,c*s/a));this.dragRange=c-h;let u=this.getCoercedValue(),g=Math.floor((c-h)*(u-n)/l),v=c-g-h,b={x:i.x,y:i.y+r+g,width:i.width,height:h};t.fillRect({...b,color:le}),this.drawRaisedButtonBorder(t,b),t.addHitRegion(this.thumbRegion).addRect(b.x,b.y,b.width,b.height);let W={x:i.x,y:i.y+r,width:i.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(W.x,W.y,W.width,W.height),this.pageDecreasePressed&&t.fillRect({...W,color:m.BLACK});let L={x:i.x,y:i.y+r+g+h,width:i.width,height:v};t.addHitRegion(this.pageIncreaseRegion).addRect(L.x,L.y,L.width,L.height),this.pageIncreasePressed&&t.fillRect({...L,color:m.BLACK})}drawLeftButton(t,e){t.fillRect({...e,color:le}),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 _(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:le}),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 _(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:le}),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 _(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:le}),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 _(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,c=e.y+e.height-n+n/2,h=e.x+e.width-n+n/2;t.strokePath({color:i,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c)}),t.strokePath({color:r,path:new _(h-n,c-n).lineTo(h-n,a+n).moveTo(h-n,c-n).lineTo(l+n,c-n)}),t.strokePath({color:s,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n)}),t.strokePath({color:o,path:new _(l+n,a+n).lineTo(h-n-n,a+n).moveTo(l+n,a+n).lineTo(l+n,c-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepIncreaseRepeatedly(),Bi)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.stepDecreaseRepeatedly(),Bi)}stepIncrease(){let t=this.pv?.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.stepIncrement)}stepDecrease(){let t=this.pv?.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(),Bi)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout(()=>this.pageDecreaseRepeatedly(),Bi)}pageIncrease(){let t=this.pv?.value??(this.maximum-this.minimum)/2;this.setCoercedValue(t+this.pageIncrement)}pageDecrease(){let t=this.pv?.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.pv?.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(oa)}get horizontal(){return this.properties.getValue(ha)}get showValueTip(){return this.properties.getValue(ua)}get font(){return this.properties.getValue(na).scale(this.scale)}get minimum(){return this.properties.getValue(la)}get maximum(){return this.properties.getValue(aa)}get stepIncrement(){return this.properties.getValue(ca)}get pageIncrement(){return this.properties.getValue(pa)}get barLength(){return this.properties.getValue(da)}};var ma="confirm_message",fa="font",xa="format_type",wa="horizontal_alignment",ya="multiline_input",ba="password_input",Pa="precision",va="precision_from_pv",_a="show_units",sg="text",Ra="vertical_alignment",Hi=class extends V{areaRegion;inputEl;editing=!1;scratchCanvas;scratchCtx;constructor(t,e){super(t,e),this.properties.add(new R(ma)),this.properties.add(new H(fa)),this.properties.add(new P(xa)),this.properties.add(new P(wa)),this.properties.add(new w(ya)),this.properties.add(new w(ba,!1)),this.properties.add(new P(Pa)),this.properties.add(new w(va)),this.properties.add(new w(_a,!0)),this.properties.add(new P(Ra,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.pv?.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||"";!this.confirmMessage||confirm(this.confirmMessage)?(this.value=e,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,e),this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()):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")}cancelInput(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){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}),this.scratchCanvas.width=this.area.width,this.scratchCanvas.height=this.area.height;let r=this.scratchCtx;r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.font=this.font.getFontString();let s=this.x;this.horizAlignment===0?r.textAlign="start":this.horizAlignment===1?(s+=this.width/2,r.textAlign="center"):this.horizAlignment===2&&(s+=this.width,r.textAlign="end");let o=this.y;this.vertAlignment===0?r.textBaseline="top":this.vertAlignment===1?(o=o+this.height/2,r.textBaseline="middle"):this.vertAlignment===2&&(o=o+this.height,r.textBaseline="bottom");let n=this.text;if(this.pv&&this.pv.value!==void 0){let a=this.precisionFromPV?this.pv.precision:this.precision;a===-1&&(a=this.pv.precision??-1),n=Nt(this.pv.value,this.formatType,a,this.pv.typeHint),this.showUnits&&this.pv?.units&&(n+=" "+this.pv.units)}r.fillText(n,s-this.area.x,o-this.area.y),i.drawImage(this.scratchCanvas,this.area.x,this.area.y)}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 value(){return this.text}set value(t){this.properties.setValue(sg,t),this.requestRepaint()}get confirmMessage(){return this.properties.getValue(ma)}get font(){return this.properties.getValue(fa).scale(this.scale)}get formatType(){return this.properties.getValue(xa)}get horizAlignment(){return this.properties.getValue(wa)}get multilineInput(){return this.properties.getValue(ya)}get passwordInput(){return this.properties.getValue(ba)}get precision(){return this.properties.getValue(Pa)}get precisionFromPV(){return this.properties.getValue(va)}get showUnits(){return this.properties.getValue(_a)}get vertAlignment(){return this.properties.getValue(Ra)}};var Ta="alpha",Ca="fill",Sa="line_width",La="line_style",Aa="start_angle",Ea="total_angle",ki=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(Ta,255)),this.properties.add(new P(Sa)),this.properties.add(new P(Aa)),this.properties.add(new P(Ea)),this.properties.add(new w(Ca)),this.properties.add(new P(La))}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=-$(this.startAngle),n=-$(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(Ta)}get lineWidth(){return this.scale*this.properties.getValue(Sa)}get lineStyle(){return this.properties.getValue(La)}get startAngle(){return this.properties.getValue(Aa)}get totalAngle(){return this.properties.getValue(Ea)}get fill(){return this.properties.getValue(Ca)}};var Oa="alpha",Va="bg_gradient_color",Ma="fg_gradient_color",Ia="fill_level",Ba="gradient",Wa="horizontal_fill",Ha="line_color",ka="line_width",Da="line_style",Di=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(Oa,255)),this.properties.add(new S(Va)),this.properties.add(new S(Ma)),this.properties.add(new w(Ba)),this.properties.add(new P(ka)),this.properties.add(new B(Ia)),this.properties.add(new w(Wa)),this.properties.add(new S(Ha)),this.properties.add(new P(Da))}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,c=t.createLinearGradient(this.x,this.y,a,l);c.addColorStop(0,this.foregroundGradientStartColor.toString()),c.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:r,rx:s,ry:o,gradient:c})}else t.fillEllipse({cx:i,cy:r,rx:s,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(Oa)}get lineWidth(){return this.scale*this.properties.getValue(ka)}get fillLevel(){return this.properties.getValue(Ia)}get horizontalFill(){return this.properties.getValue(Wa)}get lineColor(){return this.properties.getValue(Ha)}get lineStyle(){return this.properties.getValue(Da)}get gradient(){return this.properties.getValue(Ba)}get backgroundGradientStartColor(){return this.properties.getValue(Va)}get foregroundGradientStartColor(){return this.properties.getValue(Ma)}};var Na="image_file",Fa="no_animation",Ga="transparency",Ni=class extends V{currentImageFile;imageElement;imageSnapshot;imageLoading=!1;imageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new R(Na)),this.properties.add(new R(Fa)),this.properties.add(new w(Ga,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoading&&this.imageSnapshot?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){if(this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile){this.currentImageFile=this.imageFile;let t=this.imageElement;this.display.getImageLoader().load(this.resolvePath(this.imageFile)).then(e=>{t.src=e})}}snapshotImage(t){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue(Ga)}get imageFile(){return this.properties.getValue(Na)}get noAnimation(){return this.properties.getValue(Fa)}};var $a="font",Ua="horizontal_alignment",Ya="vertical_alignment",Xa="wrap_words",Fi=class extends V{constructor(t,e){super(t,e),this.properties.add(new H($a)),this.properties.add(new P(Ua)),this.properties.add(new P(Ya)),this.properties.add(new w(Xa))}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=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let r=0;for(let a of i){let l=e.measureText(a).width;r=Math.max(r,l)}let s=this.x;this.horizAlignment===1?s=this.x+(this.width-r)/2:this.horizAlignment===2&&(s=this.x+(this.width-r));let o=i.length*this.font.height+(i.length-1)*this.font.height*.2,n=this.y;this.vertAlignment===1?n+=(this.height-o)/2:this.vertAlignment===2&&(n+=this.height-o);for(let a of i)e.fillText(a,s,n),n+=this.font.height*1.2}wrapText(t,e,i){let r=[];for(let s of e.split(`
18
+ `))r=r.concat(this.wrapLine(t,s,i));return r}wrapLine(t,e,i){if(!e)return[""];let r=[],s,o,n,a=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(s=e.substr(0,o),o!==e.length)for(n=0;s.indexOf(" ",n)!==-1;n=s.indexOf(" ",n)+1);r.push(s.substr(0,n||s.length)),a=Math.max(a,t.measureText(r[r.length-1],this.font).width),e=e.substr(r[r.length-1].length,e.length)}return r}get font(){return this.properties.getValue($a).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Ua)}get vertAlignment(){return this.properties.getValue(Ya)}get wrapWords(){return this.properties.getValue(Xa)}};var za="alpha",qa="fill_level",Ka="horizontal_fill",ja="line_color",Za="line_style",Ja="line_width",he="points",Gi=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(za,255)),this.properties.add(new P(Ja)),this.properties.add(new B(qa)),this.properties.add(new w(Ka)),this.properties.add(new S(ja)),this.properties.add(new P(Za)),this.properties.add(new Pt(he,[]))}init(){this.addPropertyListener("x",(t,e)=>{let i=this.properties.getValue(he),r=Kt(i,t-e,0);this.properties.setValue(he,r),this.requestRepaint()}),this.addPropertyListener("y",(t,e)=>{let i=this.properties.getValue(he),r=Kt(i,0,t-e);this.properties.setValue(he,r),this.requestRepaint()})}draw(t){let{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;let i=_.fromPoints(Ne(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+=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 c=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:c}),t.ctx.restore()}get alpha(){return this.properties.getValue(za)}get lineWidth(){return this.scale*this.properties.getValue(Ja)}get fillLevel(){return this.properties.getValue(qa)}get horizontalFill(){return this.properties.getValue(Ka)}get lineColor(){return this.properties.getValue(ja)}get lineStyle(){return this.properties.getValue(Za)}get points(){return Dt(this.properties.getValue(he),this.scale)}};var Qa="alpha",tl="arrows",el="arrow_length",il="fill_arrow",rl="fill_level",sl="horizontal_fill",ol="line_width",nl="points",$i=class extends V{constructor(t,e){super(t,e),this.properties.add(new P(Qa,255)),this.properties.add(new P(ol)),this.properties.add(new B(rl)),this.properties.add(new w(sl)),this.properties.add(new Pt(nl,[])),this.properties.add(new P(el)),this.properties.add(new w(il)),this.properties.add(new P(tl))}draw(t){let e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,r=this.height;this.horizontalFill?i*=this.fillLevel/100:(r*=this.fillLevel/100,e+=r),t.save();let s=this.x-this.lineWidth/2,o=e-this.lineWidth/2,n=i+this.lineWidth,a=r+this.lineWidth;t.beginPath(),t.rect(s,o,n,a),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let i=0;i<this.points.length;i++)i===0?t.moveTo(this.points[i].x,this.points[i].y):t.lineTo(this.points[i].x,this.points[i].y);if(t.stroke(),this.points.length>=2){let i=this.points[0],r=this.points[this.points.length-1];if(this.arrows===2||this.arrows===3){let s=this.calculateArrowPoints(this.points[this.points.length-2],r);if(s[2]=r,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let o=0;o<s.length;o++)o===0?t.moveTo(s[o].x,s[o].y):t.lineTo(s[o].x,s[o].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(r.x,r.y),t.lineTo(s[0].x,s[0].y),t.moveTo(r.x,r.y),t.lineTo(s[1].x,s[1].y),t.stroke()}if(this.arrows===1||this.arrows===3){let s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let o=0;o<s.length;o++)o===0?t.moveTo(s[o].x,s[o].y):t.lineTo(s[o].x,s[o].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){let i=De(e,t),r=Math.PI/10,s=new at(this.arrowLength,i.theta-r),o=new at(this.arrowLength,i.theta+r),n=new at(Math.floor(this.arrowLength*Math.cos(r)),i.theta),a=wt(s.toPoint(),e.x,e.y),l=wt(o.toPoint(),e.x,e.y),c=wt(n.toPoint(),e.x,e.y);return[a,l,c]}get alpha(){return this.properties.getValue(Qa)}get lineWidth(){return this.scale*this.properties.getValue(ol)}get fillLevel(){return this.properties.getValue(rl)}get horizontalFill(){return this.properties.getValue(sl)}get points(){let t=Dt(this.properties.getValue(nl),this.scale);return Ne(t)}get arrows(){return this.properties.getValue(tl)}get fillArrow(){return this.properties.getValue(il)}get arrowLength(){return this.properties.getValue(el)}};var al="alpha",ll="bg_gradient_color",hl="fg_gradient_color",cl="fill_level",pl="gradient",dl="horizontal_fill",ul="line_color",gl="line_width",ml="line_style",Ui=class extends V{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(al,255)),this.properties.add(new S(ll)),this.properties.add(new S(hl)),this.properties.add(new w(pl)),this.properties.add(new P(gl)),this.properties.add(new B(cl)),this.properties.add(new w(dl)),this.properties.add(new S(ul)),this.properties.add(new P(ml))}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(al)}get lineWidth(){return this.scale*this.properties.getValue(gl)}get fillLevel(){return this.properties.getValue(cl)}get horizontalFill(){return this.properties.getValue(dl)}get lineColor(){return this.properties.getValue(ul)}get lineStyle(){return this.properties.getValue(ml)}get gradient(){return this.properties.getValue(pl)}get backgroundGradientStartColor(){return this.properties.getValue(ll)}get foregroundGradientStartColor(){return this.properties.getValue(hl)}};var fl="alpha",xl="bg_gradient_color",wl="corner_width",yl="corner_height",bl="fg_gradient_color",Pl="fill_level",vl="gradient",_l="horizontal_fill",Rl="line_color",Tl="line_width",Cl="line_style",Yi=class extends V{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new P(fl,255)),this.properties.add(new S(xl)),this.properties.add(new S(bl)),this.properties.add(new w(vl)),this.properties.add(new P(Tl)),this.properties.add(new B(Pl)),this.properties.add(new w(_l)),this.properties.add(new S(Rl)),this.properties.add(new P(wl)),this.properties.add(new P(yl)),this.properties.add(new P(Cl))}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(fl)}get lineWidth(){return this.scale*this.properties.getValue(Tl)}get fillLevel(){return this.properties.getValue(Pl)}get horizontalFill(){return this.properties.getValue(_l)}get lineColor(){return this.properties.getValue(Rl)}get lineStyle(){return this.properties.getValue(Cl)}get gradient(){return this.properties.getValue(vl)}get cornerWidth(){return this.scale*this.properties.getValue(wl)}get cornerHeight(){return this.scale*this.properties.getValue(yl)}get backgroundGradientStartColor(){return this.properties.getValue(xl)}get foregroundGradientStartColor(){return this.properties.getValue(bl)}};var Sl="bitReverse",Ll="effect_3d",Al="horizontal",El="led_border",Ol="led_border_color",Vl="led_packed",Ml="numBits",Il="off_color",Bl="on_color",Wl="startBit",Hl="square_led",Xi=class extends V{constructor(t,e){super(t,e),this.properties.add(new w(Sl)),this.properties.add(new w(Ll)),this.properties.add(new w(Al)),this.properties.add(new P(Ml)),this.properties.add(new S(Il)),this.properties.add(new S(Bl)),this.properties.add(new P(Wl)),this.properties.add(new w(Hl)),this.properties.add(new P(El,3)),this.properties.add(new S(Ol,m.DARK_GRAY)),this.properties.add(new w(Vl,!1))}getLedColor(t){let e=!1;if(this.pv?.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.pv?.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,c=e.height-2*this.ledBorder;o=l/2,n=c/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=xt(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(Sl)}get horizontal(){return this.properties.getValue(Al)}get numBits(){return this.properties.getValue(Ml)}get startBit(){return this.properties.getValue(Wl)}get ledPacked(){return this.properties.getValue(Vl)}get ledBorder(){return this.scale*this.properties.getValue(El)}get ledBorderColor(){return this.properties.getValue(Ol)}get offColor(){return this.properties.getValue(Il)}get onColor(){return this.properties.getValue(Bl)}get effect3d(){return this.properties.getValue(Ll)}get squareLed(){return this.properties.getValue(Hl)}};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,c=this.maxFrac;if(n&&(a-=2,l+=2,c+=2),o.length>c){let g=+("0."+o);g=c==0?Math.round(g):g.toFixed(c),o=g.toString(10).substr(2);let v=g>=1?1:0,b,T=s.length-1;for(;v;)if(T==-1){s="1"+s;break}else b=Number(s.charAt(T)),b===9?(b="0",v=1):(b=++b+"",v=0),s=s.substring(0,T)+b+s.substring(T+1,s.length),T--}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 h=0;for(let g=s.length;g>0;g--)h!=0&&h%this.comma==0&&(s=s.substring(0,g)+","+s.substring(g),h=0),h++;let u;return o.length>0?u=this.prefix+s+"."+o+this.suffix:u=this.prefix+s+this.suffix,i&&(u="-"+u),u}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 og=1,ng=8,Q=2,ce=class{constructor(t,e,i){this.rampWidth=t;this.startAngle=e;this.endAngle=i}rampWidth;startAngle;endAngle;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){if(this.labelsOutside){let r=og+ng;this.radius=e.width/2-r}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(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 v=n,b=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:$(v),endAngle:$(b),color:this.loloColor})}if(this.showLo){let v;this.showLoLo?v=this.lolo:v=this.minimum;let b=360-this.getValuePosition(v,!0),T=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){let W=$(this.getValuePosition(v,!0)-Q),O=yt(e.width/2,W,e),L=$(this.getValuePosition(this.lo,!0)+Q),M=yt(e.width/2,L,e),N=t.createLinearGradient(O.x,O.y,M.x,M.y);N.addColorStop(0,this.loloColor.toString()),N.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:$(b-Q/2),endAngle:$(T+Q/2),gradient:N})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b),endAngle:$(T),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let c=this.maximum;this.showHi?c=this.hi:this.showHiHi&&(c=this.hihi);let h=(l+c)/2,u=360-this.getValuePosition(l,!0),g=360-this.getValuePosition(h,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){let v=$(this.getValuePosition(l,!0)-Q),b=yt(e.width/2,v,e),T=$(this.getValuePosition(h,!0)+Q),W=yt(e.width/2,T,e),O=t.createLinearGradient(b.x,b.y,W.x,W.y);O.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),O.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:$(u-Q/2),endAngle:$(g+Q/2),gradient:O})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u),endAngle:$(g),color:m.GREEN});if(u=360-this.getValuePosition(h,!0),g=360-this.getValuePosition(c,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){let v=$(this.getValuePosition(h,!0)-Q),b=yt(e.width/2,v,e),T=$(this.getValuePosition(c,!0)+Q),W=yt(e.width/2,T,e),O=t.createLinearGradient(b.x,b.y,W.x,W.y);O.addColorStop(0,m.GREEN.toString()),O.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());let L=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:$(u-Q/2),endAngle:$(g+L),gradient:O})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u),endAngle:$(g),color:m.GREEN});if(this.showHi){let v;this.showHiHi?v=this.hihi:v=this.maximum;let b=360-this.getValuePosition(this.hi,!0),T=360-this.getValuePosition(v,!0);if(this.effect3d&&this.gradient&&this.showHiHi){let W=$(this.getValuePosition(this.hi,!0)-Q),O=yt(e.width/2,W,e),L=$(this.getValuePosition(v,!0)+Q),M=yt(e.width/2,L,e),N=t.createLinearGradient(O.x,O.y,M.x,M.y);N.addColorStop(0,this.hiColor.toString()),N.addColorStop(1,this.hihiColor.toString());let F=T!==a?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b-Q/2),endAngle:$(T+F),gradient:N})}else t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(b),endAngle:$(T),color:this.hiColor})}if(this.showHiHi){u=360-this.getValuePosition(this.hihi,!0),g=a;let v=this.gradient?Q/2:0;t.strokeEllipse({cx:i,cy:r,rx:s-this.rampWidth/2,ry:o-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:$(u-v),endAngle:$(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 kl=new m(100,100,100),ag=16,lg=8,hg=5,cg=-1,Dl="color_hi",Nl="color_hihi",Fl="color_lo",Gl="color_lolo",$l="effect_3d",Ul="font",Yl="value_label_format",Xl="level_hi",zl="level_hihi",ql="level_lo",Kl="level_lolo",jl="limits_from_pv",Zl="log_scale",Jl="minimum",Ql="maximum",th="needle_color",eh="ramp_gradient",ih="show_ramp",Dr=225,pg=315;var zi=class extends V{constructor(t,e){super(t,e),this.properties.add(new S(Dl)),this.properties.add(new S(Nl)),this.properties.add(new S(Fl)),this.properties.add(new S(Gl)),this.properties.add(new w($l)),this.properties.add(new H(Ul)),this.properties.add(new B(Xl)),this.properties.add(new B(zl)),this.properties.add(new B(ql)),this.properties.add(new B(Kl)),this.properties.add(new w(Zl)),this.properties.add(new w(jl)),this.properties.add(new B(Ql)),this.properties.add(new B(Jl)),this.properties.add(new S(th)),this.properties.add(new w(eh)),this.properties.add(new w(ih,!0)),this.properties.add(new R(Yl))}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.drawLabel(t,i,r),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,kl.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=$(0),c=$(35),h={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)},u=t.createLinearGradient(h.x,h.y,h.x,h.y+h.height);u.addColorStop(0,m.WHITE.withAlpha(90/255).toString()),u.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:h.x+h.width/2,cy:h.y+h.height/2,rx:h.width/2,ry:h.height/2,gradient:u}),h={x:Math.floor(this.x+e/2-s*a*Math.sin(c)),y:Math.floor(Math.ceil(this.y+i/2+s*n)),width:Math.floor(2*s*a*Math.sin(c)),height:Math.floor(Math.ceil(s*o-s*n))},u=t.createLinearGradient(h.x,h.y,h.x,h.y+h.height),u.addColorStop(0,m.WHITE.withAlpha(0).toString()),u.addColorStop(1,m.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:h.x+h.width/2,cy:h.y+h.height/2,rx:h.width/2,ry:h.height/2,gradient:u})}}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 ce(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)}drawLabel(t,e,i){let r=q.ARIAL_12_BOLD.scale(this.scale);if(this.pv?.value!==void 0){let s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+i*7/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,r){let s=this.x+e/2,o=this.y+i/2,n;if(this.pv?.value!==void 0){let T=this.getValueInRange(this.pv.value,r);n=360-this.getValuePosition(T,r),r.max>r.min?T>r.max?n+=10:T<r.min&&(n-=10):T>r.min?n-=10:T<r.max&&(n+=10)}else n=360-this.getValuePosition((r.min+r.max)/2,r);let a=$(n),{scale:l}=this,{needleDiameter:c,majorTickLength:h,gapBetweenNeedleScale:u}=this,g=Tt(s,o-c/2+3*l,s,o,a),v=Tt(s+e/2-h-u,o,s,o,a),b=Tt(s,o+c/2-3*l,s,o,a);t.fillPath({color:this.needleColor,path:new _(g.x,g.y).lineTo(v.x,v.y).lineTo(b.x,b.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,kl.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-(pg-Dr),r;return this.logScale?r=Dr-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*i:r=Dr-(t-e.min)/(e.max-e.min)*i,r<0&&(r+=360),r}formatLabelValue(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return this.scale*ag}get majorTickLength(){return this.scale*lg}get minorTickLength(){return this.scale*hg}get gapBetweenNeedleScale(){return this.scale*cg}get colorLo(){return this.properties.getValue(Fl)}get colorLoLo(){return this.properties.getValue(Gl)}get colorHi(){return this.properties.getValue(Dl)}get colorHiHi(){return this.properties.getValue(Nl)}get effect3d(){return this.properties.getValue($l)}get font(){return this.properties.getValue(Ul).scale(this.scale)}get levelLo(){return this.properties.getValue(ql)}get levelLoLo(){return this.properties.getValue(Kl)}get levelHi(){return this.properties.getValue(Xl)}get levelHiHi(){return this.properties.getValue(zl)}get limitsFromPv(){return this.properties.getValue(jl)}get logScale(){return this.properties.getValue(Zl)}get minimum(){return this.properties.getValue(Jl)}get maximum(){return this.properties.getValue(Ql)}get needleColor(){return this.properties.getValue(th)}get rampGradient(){return this.properties.getValue(eh)}get showRamp(){return this.properties.getValue(ih)}get valueLabelFormat(){return this.properties.getValue(Yl)}};var rh="bit",sh="data_type",oh="off_image",nh="off_label",ah="font",lh="on_image",hh="on_label",ch="show_boolean_label",qi=class extends V{onImageElement;onImageLoaded=!1;offImageElement;offImageLoaded=!1;constructor(t,e){super(t,e),this.properties.add(new P(rh)),this.properties.add(new P(sh)),this.properties.add(new R(oh)),this.properties.add(new R(nh)),this.properties.add(new R(lh)),this.properties.add(new R(hh)),this.properties.add(new H(ah)),this.properties.add(new w(ch))}init(){if(this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage){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.pv?.toNumber():this.pv?.value!==void 0?(this.pv?.value>>this.bit&1)>0:!1}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue(rh)}get dataType(){return this.properties.getValue(sh)}get showBooleanLabel(){return this.properties.getValue(ch)}get font(){return this.properties.getValue(ah).scale(this.scale)}get offLabel(){return this.properties.getValue(nh)}get offImage(){return this.properties.getValue(oh)}get onLabel(){return this.properties.getValue(hh)}get onImage(){return this.properties.getValue(lh)}};var dg=["January","February","March","April","May","June","July","August","September","October","November","December"],et=class{constructor(t,e,i,r,s,o,n,a,l,c){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=c}formatter;scale;scaleFont;minimum;maximum;logScale;majorTickStepHint;foregroundColor;showMinorTicks;showScale;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 c=t.measureText(this.labels[l],this.scaleFont);c.height>n&&(n=c.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 c=this.x+this.labelPositions[l],h=this.y,u=0;if(this.labelVisibilities[l]?u=this.majorTickLength:u=this.minorTickLength,this.labelVisibilities[l]||this.showMinorTicks){let g=Math.round(c)-s*.5;t.strokePath({path:new _(g,h).lineTo(g,h+u),color:this.foregroundColor,lineWidth:s*1,opacity:100/255})}this.labelVisibilities[l]&&t.fillText({x:c,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 c=e+this.labelPositions[l];this.labelVisibilities[l]&&t.fillText({x:c,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[l]});let h=Math.round(c)-s*.5;t.strokePath({path:new _(h,i).lineTo(h,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 h=0;h<this.labels.length;h++){let u=t.measureText(this.labels[h],this.scaleFont);u.width>l&&(l=u.width)}let c=this.showScale?l+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(s||(e=e-c),this.x=e,this.y=i,this.logScale)for(let h=0;h<this.labelPositions.length;h++){let u;this.labelVisibilities[h]?u=this.majorTickLength:u=this.minorTickLength;let g=e+l+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-u,v=Math.round(i+r-this.labelPositions[h])-n*.5;if((this.labelVisibilities[h]||this.showMinorTicks)&&t.strokePath({path:new _(g,v).lineTo(g+u,v),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.labelVisibilities[h]){let b=i+r-this.labelPositions[h];t.fillText({x:e,y:b,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]})}}else for(let h=0;h<this.labels.length;h++){let u=i+r-this.labelPositions[h],g=Math.round(u)-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[h]){let v=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:v,y:u,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]})}}else{this.labelVisibilities[h]&&t.fillText({x:e,y:u,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[h]});let v=e+l+this.spaceBetweenMarkAndLabel-n*1;t.strokePath({path:new _(v,g).lineTo(v+this.majorTickLength,g),color:this.foregroundColor,lineWidth:n*1,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,h,v,i+r)}}return c}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:c}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let h=a[1];for(;h-a[0]>n+3*c;){h=h-n;let u=Math.round(i+h)-c*.5;t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let h=a[e-1];for(;a[e]-h>n+3*c;){h=h+n;let u=Math.round(i+h)-c*.5;t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*1,opacity:100/255})}}else for(let h=0;h<o;h++){let u=i+a[e-1]+(a[e]-a[e-1])*h/o;u=Math.round(u)-c*.5,t.strokePath({path:new _(u,r).lineTo(u,r+l),color:this.foregroundColor,lineWidth:c*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:c,scale:h}=this;if(e>0)if(e===1&&a[1]-a[0]<s){let u=a[1];for(;u-a[0]>n+3*h;){u-=n;let g=Math.round(r-u)-h*.5;t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else if(e===a.length-1&&a[e]-a[e-1]<s){let u=a[e-1];for(;a[e]-u>n+3*h;){u+=n;let g=Math.round(r-u)-h*.5;t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*1,opacity:100/255})}}else for(let u=0;u<o;u++){let g=r-a[e-1]-(a[e]-a[e-1])*u/o;g=Math.round(g)-h*.5,t.strokePath({path:new _(i+c-l,g).lineTo(i+c,g),color:this.foregroundColor,lineWidth:h*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 h=e;e=i,i=h}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 c;return a>7.5?c=10*Math.pow(10,l):a>3.5?c=5*Math.pow(10,l):a>1.5?c=2*Math.pow(10,l):c=Math.pow(10,l),r&&(c=-c),c}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 c=o;r?c>=n:c<=n;c+=r?-1:1)if(Math.abs(n-o)>20){let h=Math.pow(10,c);if(h>e)break;this.addTickInfo(h,e,s,i)}else{for(let h=l;(r?h>=Math.pow(10,c-1):h<=Math.pow(10,c))&&!(r?h<e:h>e);h=r?h-a:h+a)this.addTickInfo(h,e,s,i);a=r?a/Math.pow(10,1):a*Math.pow(10,1),l=r?Math.pow(10,c-1):a+Math.pow(10,c)}(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 c=o;e>=t?c<e:c>e;c=o+n++*r){let h=c*a;this.labels.push(this.format(h)),this.labelValues.push(h);let u=Math.floor((c-t)/l*i)+this.margin;this.labelPositions.push(u)}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 c=Number(this.labels[r]);l=this.isMajorTick(c)||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),c=!0,h=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){c=a>l+this.tickLabelGap;let u=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+u.width/2:o.height),h=a>l+this.tickLabelGap}return c&&h}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})+`
19
19
  `+i.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return i.formatDate(e,{year:!0,month:!0,day:!0})+`
20
- `+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=cg[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})+`
21
- `+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 lh="color_map",hh="crop_bottom",ch="crop_left",ph="crop_right",dh="crop_top",uh="data_height",gh="data_width",mh="font",fh="graph_area_height",xh="graph_area_width",wh="maximum",yh="minimum",bh="show_ramp",Ph="x_axis_axis_color",vh="x_axis_axis_title",_h="x_axis_major_tick_step_hint",Rh="x_axis_maximum",Th="x_axis_minimum",Ch="x_axis_scale_font",Sh="x_axis_show_minor_ticks",Lh="x_axis_title_font",Ah="x_axis_visible",Eh="y_axis_axis_color",Oh="y_axis_axis_title",Vh="y_axis_major_tick_step_hint",Mh="y_axis_maximum",Ih="y_axis_minimum",Bh="y_axis_scale_font",Wh="y_axis_show_minor_ticks",Hh="y_axis_title_font",kh="y_axis_visible",ji=class extends V{constructor(t,e){super(t,e),this.properties.add(new Gt(lh)),this.properties.add(new P(hh)),this.properties.add(new P(ch)),this.properties.add(new P(ph)),this.properties.add(new P(dh)),this.properties.add(new P(uh)),this.properties.add(new P(gh)),this.properties.add(new P(fh)),this.properties.add(new P(xh)),this.properties.add(new H(mh)),this.properties.add(new B(wh)),this.properties.add(new B(yh)),this.properties.add(new w(bh)),this.properties.add(new S(Ph)),this.properties.add(new R(vh)),this.properties.add(new P(_h)),this.properties.add(new B(Rh)),this.properties.add(new B(Th)),this.properties.add(new H(Ch)),this.properties.add(new w(Sh)),this.properties.add(new H(Lh)),this.properties.add(new w(Ah)),this.properties.add(new S(Eh)),this.properties.add(new R(Oh)),this.properties.add(new P(Vh)),this.properties.add(new B(Mh)),this.properties.add(new B(Ih)),this.properties.add(new H(Bh)),this.properties.add(new w(Wh)),this.properties.add(new H(Hh)),this.properties.add(new w(kh))}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{graphAreaWidth:s,graphAreaHeight: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=new et(this.display.formatter,e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),c=l.calculateMargin(t,!0),h=new et(this.display.formatter,e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),u=h.calculateMargin(t,!1),g=l.measureHorizontalHeight(t),v=o+2*u,b=h.drawVertical(t,i.x+a,i.y,v,!0),T=s+2*c,W=i.x+a+b-c,O=i.y+v+g-u;l.drawHorizontal(t,W,O,T);let L=e*1,M=Math.round(i.x+a+b)-L/2,N=Math.round(i.y+u)-L/2;t.strokePath({path:new _(M,N).lineTo(M,N+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:L});let F=M,X=N+o+L;t.strokePath({path:new _(F,X).lineTo(F+s,X),color:this.xAxisAxisColor,opacity:100/255,lineWidth:L});let{dataWidth:j,dataHeight:pt,colorMap:it}=this,{minimum:dt,maximum:ot}=this,[Bt,ue]=it.getMinMax();if(this.value&&this.value.length){let tt=document.createElement("canvas"),{cropLeft:mt,cropRight:Rt,cropTop:Wt,cropBottom:qt}=this;tt.width=j-mt-Rt,tt.height=pt-Wt-qt;let Ht=tt.getContext("2d");for(let ft=mt;ft<j-Rt;ft++)for(let nt=Wt;nt<pt-qt;nt++){let xt=this.value[nt*j+ft];if(it.autoscale){let xe=(xt-dt)/(ot-dt);xt=Bt+xe*(ue-Bt)}let[ge,me,fe]=it.lookup(xt);Ht.fillStyle=`rgb(${ge},${me},${fe})`,Ht.fillRect(ft-mt,nt-Wt,1,1)}let kt=Math.round(i.x+a+b),Tt=Math.round(i.y+h.margin);t.ctx.drawImage(tt,kt,Tt,s,o)}if(this.showRamp){let tt=new et(this.display.formatter,e,this.font,dt,ot,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),mt=i.y+h.margin,Rt=o,Wt=tt.drawVertical(t,i.x+i.width,mt,Rt,!1,!0),qt=i.x+a+b+s+this.gap,Ht=i.width-a-b-s-Wt-this.gap,kt=Rt-2*tt.margin,Tt=document.createElement("canvas");Tt.width=Ht,Tt.height=kt;let ft=Tt.getContext("2d");for(let nt=0;nt<kt;nt++){let xt=ot-nt/kt*(ot-dt);if(it.autoscale){let xe=(xt-dt)/(ot-dt);xt=Bt+xe*(ue-Bt)}let[ge,me,fe]=it.lookup(xt);ft.fillStyle=`rgb(${ge},${me},${fe})`,ft.fillRect(0,nt,Ht,1)}t.ctx.drawImage(Tt,qt,mt+tt.margin)}if(this.xAxisVisible){let tt=i.x+b+s/2;this.yAxisVisible&&(tt+=a),t.fillText({x:tt,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+v/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return this.scale*3}get colorMap(){return this.properties.getValue(lh)}get cropBottom(){return this.properties.getValue(hh)}get cropLeft(){return this.properties.getValue(ch)}get cropRight(){return this.properties.getValue(ph)}get cropTop(){return this.properties.getValue(dh)}get dataHeight(){return this.properties.getValue(uh)}get dataWidth(){return this.properties.getValue(gh)}get font(){return this.properties.getValue(mh).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(fh)}get graphAreaWidth(){return this.scale*this.properties.getValue(xh)}get maximum(){return this.properties.getValue(wh)}get minimum(){return this.properties.getValue(yh)}get showRamp(){return this.properties.getValue(bh)}get xAxisAxisColor(){return this.properties.getValue(Ph)}get xAxisAxisTitle(){return this.properties.getValue(vh)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(_h)}get xAxisMaximum(){return this.properties.getValue(Rh)}get xAxisMinimum(){return this.properties.getValue(Th)}get xAxisScaleFont(){return this.properties.getValue(Ch).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Sh)}get xAxisTitleFont(){return this.properties.getValue(Lh).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Ah)}get yAxisAxisColor(){return this.properties.getValue(Eh)}get yAxisAxisTitle(){return this.properties.getValue(Oh)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Vh)}get yAxisMaximum(){return this.properties.getValue(Mh)}get yAxisMinimum(){return this.properties.getValue(Ih)}get yAxisScaleFont(){return this.properties.getValue(Bh).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(Wh)}get yAxisTitleFont(){return this.properties.getValue(Hh).scale(this.scale)}get yAxisVisible(){return this.properties.getValue(kh)}};var Dh="bit",Nh="data_type",Fh="effect_3d",Gh="state_count",$h="square_led",Uh="off_color",Yh="off_label",Xh="off_state",zh="font",qh="on_color",Kh="on_label",jh="on_state",Zh="bulb_border",Jh="bulb_border_color",Qh="state_color_fallback",tc="state_label_fallback",ec="show_boolean_label",Zi=class extends V{areaRegion;states=[];constructor(t,e){super(t,e),this.properties.add(new P(Dh)),this.properties.add(new P(Nh)),this.properties.add(new w(Fh)),this.properties.add(new w($h)),this.properties.add(new P(Gh,2)),this.properties.add(new S(Uh)),this.properties.add(new R(Yh)),this.properties.add(new R(Xh)),this.properties.add(new S(qh)),this.properties.add(new R(Kh)),this.properties.add(new R(jh)),this.properties.add(new H(zh)),this.properties.add(new w(ec)),this.properties.add(new S(Qh)),this.properties.add(new R(tc)),this.properties.add(new P(Zh,3)),this.properties.add(new S(Jh,m.DARK_GRAY))}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 R(`state_label_${e}`);r.value=t.getString(`state_label_${e}`),this.properties.add(r);let s=new B(`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.pv?.toNumber()??this.value):this.pv?.value!==void 0?(this.pv?.value>>this.bit&1)>0:this.value!==void 0?(this.value>>this.bit&1)>0:!1:this.dataType===1?(this.pv?.toString()??this.value)===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.pv?.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.pv?.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=wt(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(Dh)}get dataType(){return this.properties.getValue(Nh)}get squareLed(){return this.properties.getValue($h)}get showBooleanLabel(){return this.properties.getValue(ec)}get font(){return this.properties.getValue(zh).scale(this.scale)}get effect3d(){return this.properties.getValue(Fh)}get stateCount(){return this.properties.getValue(Gh)}get bulbBorder(){return this.scale*this.properties.getValue(Zh)}get bulbBorderColor(){return this.properties.getValue(Jh)}get offLabel(){return this.properties.getValue(Yh)}get offColor(){return this.properties.getValue(Uh)}get offState(){return this.properties.getValue(Xh)}get onLabel(){return this.properties.getValue(Kh)}get onColor(){return this.properties.getValue(qh)}get onState(){return this.properties.getValue(jh)}get stateLabelFallback(){return this.properties.getValue(tc)}get stateColorFallback(){return this.properties.getValue(Qh)}};var pg=16,dg=12,ug=-5,gg=45,Ji=$(gg),ic=(1-Math.sin(Ji)/2)/(2*Math.cos(Ji)),rc="color_hi",sc="color_hihi",oc="color_lo",nc="color_lolo",ac="font",lc="level_hi",hc="level_hihi",cc="level_lo",pc="level_lolo",dc="log_scale",uc="minimum",gc="maximum",mc="needle_color",fc="ramp_gradient",xc="scale_font",wc="show_hi",yc="show_hihi",bc="show_lo",Pc="show_lolo",vc="show_ramp",_c="value_label_format",Qi=class extends V{areaRegion;constructor(t,e){super(t,e),this.properties.add(new S(rc)),this.properties.add(new S(sc)),this.properties.add(new S(oc)),this.properties.add(new S(nc)),this.properties.add(new H(ac)),this.properties.add(new P(lc)),this.properties.add(new P(hc)),this.properties.add(new P(cc)),this.properties.add(new P(pc)),this.properties.add(new w(dc)),this.properties.add(new P(gc)),this.properties.add(new P(uc)),this.properties.add(new S(mc)),this.properties.add(new w(fc)),this.properties.add(new H(xc)),this.properties.add(new w(wc)),this.properties.add(new w(yc)),this.properties.add(new w(bc)),this.properties.add(new w(Pc)),this.properties.add(new w(vc,!0)),this.properties.add(new R(_c))}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.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}drawRamp(t){let e=String(this.minimum),i=t.measureText(e,this.scaleFont),r=String(this.maximum),s=t.measureText(r,this.scaleFont),o=Math.max(i.width,s.width)/2,n=this.height,a=this.width;n>ic*(a-2*o)&&(n=Math.floor(ic*(a-2*o)));let l=n/(1-Math.sin(Ji)/2),c=Math.floor(this.x-l*(1-Math.cos(Ji))+o),h=this.y,u={x:c,y:h,width:Math.floor(2*l),height:Math.floor(2*l)},{rampWidth:g}=this,v=D(u,u.width/4-g,u.height/4-g);v.width=Math.min(v.width,v.height),v.height=v.width;let b=new de(g,135,45);b.lolo=this.levelLoLo,b.loloColor=this.colorLoLo,b.showLoLo=!0,b.lo=this.levelLo,b.loColor=this.colorLo,b.showLo=!0,b.hi=this.levelHi,b.hiColor=this.colorHi,b.showHi=!0,b.hihi=this.levelHiHi,b.hihiColor=this.colorHiHi,b.showHiHi=!0,b.minimum=this.minimum,b.maximum=this.maximum,b.gradient=this.rampGradient,b.logScale=this.logScale,b.draw(t,u,v),this.drawNeedle(t,u,b);let T=q.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&this.pv.value!==void 0){let W=this.format(this.pv.value),O=t.measureText(W,T);t.fillText({x:u.x+u.width/2-O.width/2,y:u.y+u.height/2-u.height/4-(b.getRadius()-u.height/4)/2-O.height/2,align:"left",baseline:"top",font:T,text:W,color:this.foregroundColor})}}drawNeedle(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o;if(this.pv&&this.pv.value!==void 0){let v=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(v),this.maximum>this.minimum?v>this.maximum?o+=8:v<this.minimum&&(o-=8):v>this.minimum?o-=8:v<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);let n=$(o),{needleWidth:a,gapBetweenNeedleScale:l,scale:c}=this,h=Ct(r+e.width/4,s-a/2+3*c,r,s,n),u=Ct(r+i.getRadius()-l,s,r,s,n),g=Ct(r+e.width/4,s+a/2-3*c,r,s,n);t.fillPath({color:this.needleColor,path:new _(h.x,h.y).lineTo(u.x,u.y).lineTo(g.x,g.y).closePath()})}get needleWidth(){return this.scale*pg}get gapBetweenNeedleScale(){return this.scale*ug}get rampWidth(){return this.scale*dg}format(t){return this.valueLabelFormat?new st(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(oc)}get colorLoLo(){return this.properties.getValue(nc)}get colorHi(){return this.properties.getValue(rc)}get colorHiHi(){return this.properties.getValue(sc)}get font(){return this.properties.getValue(ac).scale(this.scale)}get levelLo(){return this.properties.getValue(cc)}get levelLoLo(){return this.properties.getValue(pc)}get levelHi(){return this.properties.getValue(lc)}get levelHiHi(){return this.properties.getValue(hc)}get logScale(){return this.properties.getValue(dc)}get minimum(){return this.properties.getValue(uc)}get maximum(){return this.properties.getValue(gc)}get needleColor(){return this.properties.getValue(mc)}get rampGradient(){return this.properties.getValue(fc)}get scaleFont(){return this.properties.getValue(xc).scale(this.scale)}get showLo(){return this.properties.getValue(bc)}get showLoLo(){return this.properties.getValue(Pc)}get showHi(){return this.properties.getValue(wc)}get showHiHi(){return this.properties.getValue(yc)}get showRamp(){return this.properties.getValue(vc)}get valueLabelFormat(){return this.properties.getValue(_c)}};var Rc="color_hi",Tc="color_hihi",Cc="color_lo",Sc="color_lolo",Lc="color_fillbackground",Ac="effect_3d",Ec="fill_color",Oc="fillcolor_alarm_sensitive",Vc="font",Mc="horizontal",Ic="indicator_mode",Bc="level_hi",Wc="level_hihi",Hc="level_lo",kc="level_lolo",Dc="limits_from_pv",Nc="log_scale",Fc="maximum",Gc="major_tick_step_hint",$c="minimum",Uc="origin",Yc="origin_ignored",Xc="scale_font",zc="scale_format",qc="show_hi",Kc="show_hihi",jc="show_label",Zc="show_lo",Jc="show_lolo",Qc="show_markers",tp="show_minor_ticks",ep="show_scale",ip="transparent_background",rp="value_label_format",tr=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(Rc)),this.properties.add(new S(Tc)),this.properties.add(new S(Cc)),this.properties.add(new S(Sc)),this.properties.add(new S(Lc)),this.properties.add(new w(Ac)),this.properties.add(new S(Ec)),this.properties.add(new w(Oc,!1)),this.properties.add(new H(Vc)),this.properties.add(new w(Mc)),this.properties.add(new w(Ic)),this.properties.add(new B(Bc)),this.properties.add(new B(Wc)),this.properties.add(new B(Hc)),this.properties.add(new B(kc)),this.properties.add(new w(Dc)),this.properties.add(new w(Nc)),this.properties.add(new B(Fc)),this.properties.add(new B(Gc)),this.properties.add(new B($c)),this.properties.add(new B(Uc,0)),this.properties.add(new w(Yc,!0)),this.properties.add(new H(Xc)),this.properties.add(new R(zc)),this.properties.add(new w(qc)),this.properties.add(new w(Kc)),this.properties.add(new w(jc)),this.properties.add(new w(Zc)),this.properties.add(new w(Jc)),this.properties.add(new w(Qc)),this.properties.add(new w(tp)),this.properties.add(new w(ep)),this.properties.add(new w(ip)),this.properties.add(new R(rp))}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 et(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=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.width)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.width)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.width)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.width)}let c=i.x+i.width;if(this.showLoLo&&r!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(r));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(s));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(o));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(n));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,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,c=Zt([{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),h=_.fromPoints(c);if(this.effect3d){let{x:u,y:g}=c[0],{x:v,y:b}=c[2],T=t.createLinearGradient(u,g,v,b);T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,s.toString()),t.fillPath({path:h,gradient:T}),t.strokePath({path:h,color:m.GRAY,lineWidth:r})}else t.fillPath({path:h,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let u=n;n=a,a=u}let l=Math.round(e.getValuePosition(n)),c=Math.round(e.getValuePosition(a)),h=D({...i,y:l,height:c-l},r);if(t.fillRect({...h,color:s}),this.effect3d){let u=t.createLinearGradient(h.x,0,h.x+h.width,0);u.addColorStop(0,m.WHITE.toString()),u.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...h,gradient:u})}}let o=this.pv?.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 et(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=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.height)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.height)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.height)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.height)}let c=i.y;if(this.showLoLo&&r!==void 0){let h=Math.round(e.getValuePosition(r)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=Math.round(e.getValuePosition(s)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=Math.round(e.getValuePosition(o)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=Math.round(e.getValuePosition(n)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,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,c=Zt([{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),h=_.fromPoints(c);if(this.effect3d){let{x:u,y:g}=c[0],{x:v,y:b}=c[2],T=t.createLinearGradient(u,g,v,b);T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,s.toString()),t.fillPath({path:h,gradient:T}),t.strokePath({path:h,color:m.GRAY,lineWidth:r})}else t.fillPath({path:h,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let u=n;n=a,a=u}let l=Math.round(e.getValuePosition(n)),c=Math.round(e.getValuePosition(a)),h=D({...i,x:l,width:c-l},r);if(t.fillRect({...h,color:s}),this.effect3d){let u=t.createLinearGradient(0,h.y,0,h.y+h.height);u.addColorStop(0,m.WHITE.toString()),u.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...h,gradient:u})}}let o=this.pv?.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.pv?.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new st(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Cc)}get colorLoLo(){return this.properties.getValue(Sc)}get colorHi(){return this.properties.getValue(Rc)}get colorHiHi(){return this.properties.getValue(Tc)}get colorFillbackground(){return this.properties.getValue(Lc)}get effect3d(){return this.properties.getValue(Ac)}get fillColorAlarmSensitive(){return this.properties.getValue(Oc)}get fillColor(){return this.properties.getValue(Ec)}get font(){return this.properties.getValue(Vc).scale(this.scale)}get horizontal(){return this.properties.getValue(Mc)}get indicatorMode(){return this.properties.getValue(Ic)}get levelLo(){return this.properties.getValue(Hc)}get levelLoLo(){return this.properties.getValue(kc)}get levelHi(){return this.properties.getValue(Bc)}get levelHiHi(){return this.properties.getValue(Wc)}get limitsFromPv(){return this.properties.getValue(Dc)}get logScale(){return this.properties.getValue(Nc)}get minimum(){return this.properties.getValue($c)}get majorTickStepHint(){return this.scale*this.properties.getValue(Gc)}get maximum(){return this.properties.getValue(Fc)}get origin(){return this.properties.getValue(Uc)}get originIgnored(){return this.properties.getValue(Yc)}get scaleFont(){return this.properties.getValue(Xc).scale(this.scale)}get scaleFormat(){return this.properties.getValue(zc)}get showHi(){return this.properties.getValue(qc)}get showHiHi(){return this.properties.getValue(Kc)}get showLabel(){return this.properties.getValue(jc)}get showLo(){return this.properties.getValue(Zc)}get showLoLo(){return this.properties.getValue(Jc)}get showMarkers(){return this.properties.getValue(Qc)}get showMinorTicks(){return this.properties.getValue(tp)}get showScale(){return this.properties.getValue(ep)}get transparentBackground(){return this.properties.getValue(ip)}get valueLabelFormat(){return this.properties.getValue(rp)}};var sp="color_hi",op="color_hihi",np="color_lo",ap="color_lolo",lp="color_fillbackground",hp="fill_color",cp="fillcolor_alarm_sensitive",pp="effect_3d",dp="level_hi",up="level_hihi",gp="level_lo",mp="level_lolo",fp="limits_from_pv",xp="log_scale",wp="maximum",yp="major_tick_step_hint",bp="minimum",Pp="scale_font",vp="scale_format",_p="show_hi",Rp="show_hihi",Tp="show_lo",Cp="show_lolo",Sp="show_markers",Lp="show_minor_ticks",Ap="show_scale",Ep="transparent_background",mg=new m(160,160,160),er=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(sp)),this.properties.add(new S(op)),this.properties.add(new S(np)),this.properties.add(new S(ap)),this.properties.add(new S(lp)),this.properties.add(new w(pp)),this.properties.add(new S(hp)),this.properties.add(new w(cp,!1)),this.properties.add(new B(dp)),this.properties.add(new B(up)),this.properties.add(new B(gp)),this.properties.add(new B(mp)),this.properties.add(new w(fp)),this.properties.add(new w(xp)),this.properties.add(new B(wp)),this.properties.add(new B(yp)),this.properties.add(new B(bp)),this.properties.add(new H(Pp)),this.properties.add(new R(vp)),this.properties.add(new w(_p)),this.properties.add(new w(Rp)),this.properties.add(new w(Tp)),this.properties.add(new w(Cp)),this.properties.add(new w(Sp)),this.properties.add(new w(Lp)),this.properties.add(new w(Ap)),this.properties.add(new w(Ep))}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 et(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),c=0;this.showMarkers&&(c=this.drawMarkers(t,s,a)),this.drawTank(t,s,l,c,a)}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.width)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.width)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.width)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.width)}let c=e.x+e.width-l-this.markerGap-this.markerTickLength;if(this.showLoLo&&r!==void 0){let h=Math.round(i.getValuePosition(r));t.strokePath({path:new _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerTickLength+this.markerGap,y:h,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,c=e.y+s.margin,h=e.width-i-r,u=e.height-2*s.margin,g=this.defaultCorner,v=11/20;h<2*g&&(v=12/20);let b=Math.floor(h*v);g>2*b-h-2*a&&(g=2*b-h);let T=s.getValuePosition(this.getFillValue()),W=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:c,width:h,height:u,rx:g/2,ry:g/2,color:m.WHITE});let L=t.createLinearGradient(l,c,l+b+2*n,c);L.addColorStop(0,this.colorFillbackground.toString()),L.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:c,width:b,height:u,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(l+h-b-2*n,c,l+h,c),L.addColorStop(0,m.WHITE.withAlpha(0).toString()),L.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+h-b,y:c,width:b,height:u,rx:g/2,ry:g/2,gradient:L});let M=T,N=c+u-T;L=t.createLinearGradient(l,M,l+b+2*n,M),L.addColorStop(0,W.toString()),L.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:M,width:b,height:N,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(l+h-b-2*n,M,l+h,M),L.addColorStop(0,m.WHITE.withAlpha(0).toString()),L.addColorStop(1,W.toString()),t.fillRect({x:l+h-b,y:M,width:b,height:N,rx:g/2,ry:g/2,gradient:L})}else t.fillRect({x:l,y:c,width:h,height:u,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:T,width:h,height:c+u-T,rx:g/2,ry:g/2,color:W});let O=D({x:l,y:c,width:h,height:u},a/2);t.strokeRect({...O,rx:g/2,ry:g/2,color:this.effect3d?mg: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.pv?.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}get colorLo(){return this.properties.getValue(np)}get colorLoLo(){return this.properties.getValue(ap)}get colorHi(){return this.properties.getValue(sp)}get colorHiHi(){return this.properties.getValue(op)}get colorFillbackground(){return this.properties.getValue(lp)}get fillColorAlarmSensitive(){return this.properties.getValue(cp)}get fillColor(){return this.properties.getValue(hp)}get effect3d(){return this.properties.getValue(pp)}get levelLo(){return this.properties.getValue(gp)}get levelLoLo(){return this.properties.getValue(mp)}get levelHi(){return this.properties.getValue(dp)}get levelHiHi(){return this.properties.getValue(up)}get limitsFromPv(){return this.properties.getValue(fp)}get logScale(){return this.properties.getValue(xp)}get minimum(){return this.properties.getValue(bp)}get majorTickStepHint(){return this.scale*this.properties.getValue(yp)}get maximum(){return this.properties.getValue(wp)}get scaleFont(){return this.properties.getValue(Pp).scale(this.scale)}get scaleFormat(){return this.properties.getValue(vp)}get showLo(){return this.properties.getValue(Tp)}get showLoLo(){return this.properties.getValue(Cp)}get showHi(){return this.properties.getValue(_p)}get showHiHi(){return this.properties.getValue(Rp)}get showMarkers(){return this.properties.getValue(Sp)}get showMinorTicks(){return this.properties.getValue(Lp)}get showScale(){return this.properties.getValue(Ap)}get transparentBackground(){return this.properties.getValue(Ep)}};var Op="font",Vp="format_type",Mp="horizontal_alignment",Ip="precision",Bp="precision_from_pv",Wp="show_lohi",Hp="show_units",kp="vertical_alignment",ir=class extends V{areaRegion;tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new H(Op)),this.properties.add(new P(Vp)),this.properties.add(new P(Mp)),this.properties.add(new P(Ip)),this.properties.add(new w(Bp)),this.properties.add(new w(Wp,!0)),this.properties.add(new w(Hp,!0)),this.properties.add(new P(kp))}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}}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.text;if(this.pv?.value!==void 0){let h=this.precisionFromPV?this.pv.precision:this.precision;h===-1&&(h=this.pv.precision??-1),s=Ft(this.pv.value,this.formatType,h,this.pv.typeHint)}else this.value!==void 0&&(s=Ft(this.value,this.formatType,this.precision,void 0));this.showUnits&&this.pv?.units&&(s+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?s+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(s+=" \u2191"));let o=t.measureText(s,this.font,!0);e.font=this.font.getFontString(),e.textBaseline="alphabetic";let a=e.measureText(s).fontBoundingBoxAscent,l={x:r.x,y:r.y,width:o.width,height:o.height};this.horizAlignment===0||(this.horizAlignment===1?l.x+=(r.width-o.width)/2:this.horizAlignment===2&&(l.x+=r.width-o.width)),this.vertAlignment===0||r.height<=o.height||(this.vertAlignment===1?l.y+=r.height/2-o.height/2:this.vertAlignment===2&&(l.y+=r.height-o.height)),e.textAlign="start",e.textBaseline="top",l.y+=l.height/2-a/2,e.save(),e.beginPath();let c=this.area;e.rect(c.x,c.y,c.width,c.height),e.clip(),e.fillStyle=this.alarmSensitiveForegroundColor.toString(),e.fillText(s,l.x,l.y),e.restore()}get font(){return this.properties.getValue(Op).scale(this.scale)}get formatType(){return this.properties.getValue(Vp)}get horizAlignment(){return this.properties.getValue(Mp)}get precision(){return this.properties.getValue(Ip)}get precisionFromPV(){return this.properties.getValue(Bp)}get showLohi(){return this.properties.getValue(Wp)}get showUnits(){return this.properties.getValue(Hp)}get vertAlignment(){return this.properties.getValue(kp)}};var Dp="color_hi",Np="color_hihi",Fp="color_lo",Gp="color_lolo",$p="color_fillbackground",Up="fill_color",Yp="fillcolor_alarm_sensitive",Xp="font",zp="effect_3d",qp="level_hi",Kp="level_hihi",jp="level_lo",Zp="level_lolo",Jp="limits_from_pv",Qp="log_scale",td="maximum",ed="major_tick_step_hint",id="minimum",rd="scale_font",sd="scale_format",od="show_bulb",nd="show_hi",ad="show_hihi",ld="show_lo",hd="show_lolo",cd="show_markers",pd="show_minor_ticks",dd="show_scale",ud="transparent_background",gd="unit",md="value_label_format",fd=new m(160,160,160),rr=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(Dp)),this.properties.add(new S(Np)),this.properties.add(new S(Fp)),this.properties.add(new S(Gp)),this.properties.add(new S($p)),this.properties.add(new S(Up)),this.properties.add(new w(Yp,!1)),this.properties.add(new w(zp)),this.properties.add(new B(qp)),this.properties.add(new B(Kp)),this.properties.add(new B(jp)),this.properties.add(new B(Zp)),this.properties.add(new w(Jp)),this.properties.add(new H(Xp)),this.properties.add(new w(Qp)),this.properties.add(new B(td)),this.properties.add(new B(ed)),this.properties.add(new B(id)),this.properties.add(new H(rd)),this.properties.add(new R(sd)),this.properties.add(new w(od)),this.properties.add(new w(nd)),this.properties.add(new w(ad)),this.properties.add(new w(ld)),this.properties.add(new w(hd)),this.properties.add(new w(cd)),this.properties.add(new w(pd)),this.properties.add(new w(dd)),this.properties.add(new w(ud)),this.properties.add(new P(gd)),this.properties.add(new R(md))}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 O=Math.min(s.width/2,this.bulbMaxDiameter);l=s.height<O?0:s.height-O}let c={...s,height:l},h=new et(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);h.scaleFormat=this.scaleFormat;let u=0,g="";if(this.unit===0?g="\xB0C":this.unit===1?g="\xB0F":this.unit===2&&(g="K"),g){let O=q.ARIAL_9.scale(e),L=t.measureText(g,O),M=2*e;u=L.height+2*M,t.fillText({x:s.x+s.width/2-this.pipeWidth/2-M,y:s.y+M,baseline:"top",align:"right",color:n,font:O,text:g})}let v=c.x+c.width/2-this.pipeWidth/2-1*e,b={...c,y:c.y+u,height:c.height-u+h.calculateMargin(t,!1)},T=h.drawVertical(t,v,b.y,b.height,!1),W=Math.floor(this.pipeWidth/2);if(c={...c,y:h.getValuePosition(r)-W,height:h.scaleLength+2*W},this.drawPipe(t,c,h),this.showMarkers&&this.drawMarkers(t,s,h),this.showBulb){let O=Math.min(s.width/2,this.bulbMaxDiameter),L=1*e,M=s.x+s.width/2,N=s.y+l+O/2,F=O/2,X=O/2;if(t.fillEllipse({cx:M,cy:N,rx:F,ry:X,color:a}),this.effect3d){let it=t.createLinearGradient(M-F,N-X,M+F,N+X);it.addColorStop(0,m.WHITE.toString()),it.addColorStop(1,a.withAlpha(0).toString()),t.fillEllipse({cx:M,cy:N,rx:F,ry:X,gradient:it})}t.strokeEllipse({cx:M,cy:N,rx:F-L/2,ry:X-L/2,color:this.effect3d?fd:n,lineWidth:L});let j={x:Math.round(c.x+c.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(h.getValuePosition(i)),width:this.pipeWidth-2*this.outlineWidth,height:e*3};if(this.effect3d){let it=Math.round(c.x+c.width/2-this.pipeWidth/2),dt=it+this.pipeWidth,ot=t.createLinearGradient(it,j.y,dt,j.y);ot.addColorStop(0,m.WHITE.toString()),ot.addColorStop(1,a.toString()),t.fillRect({...j,gradient:ot})}else t.fillRect({...j,color:a});let pt=this.pv?.value;pt&&t.fillText({x:M,y:N,align:"center",baseline:"middle",color:a.contrast(),font:this.font,text:this.format(pt)})}}drawPipe(t,e,i){let{scale:r,outlineWidth:s,min:o,max:n}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,c={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},h=this.getFillValue(),u=i.getValuePosition(h);n>o?h>n?u-=10*r:h<o&&(u+=10*r):h>o?u+=10*r:h<n&&(u-=10*r);let g=this.pipeWidth/2,{x:v,y:b,width:T,height:W}=c;if(this.effect3d){let L=t.createLinearGradient(v,b,v+T,b);L.addColorStop(0,m.WHITE.toString()),L.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({...c,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(v,b,v+T,b),L.addColorStop(0,m.WHITE.toString()),L.addColorStop(1,l.toString()),t.fillRect({x:v,y:u,width:T,height:b+W-u,rx:g/2,ry:g/2,gradient:L})}else t.fillRect({...c,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:v,y:u,width:T,height:b+W-u,rx:g/2,ry:g/2,color:l});let O=D(c,s/2);t.strokeRect({...O,rx:g/2,ry:g/2,color:this.effect3d?fd:a,lineWidth:s})}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=q.ARIAL_9.scale(this.scale),l=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&r!==void 0){let c=Math.round(i.getValuePosition(r));t.strokePath({path:new _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:c,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.pv?.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}format(t){return this.valueLabelFormat?new st(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(Fp)}get colorLoLo(){return this.properties.getValue(Gp)}get colorHi(){return this.properties.getValue(Dp)}get colorHiHi(){return this.properties.getValue(Np)}get colorFillbackground(){return this.properties.getValue($p)}get fillColorAlarmSensitive(){return this.properties.getValue(Yp)}get fillColor(){return this.properties.getValue(Up)}get font(){return this.properties.getValue(Xp).scale(this.scale)}get effect3d(){return this.properties.getValue(zp)}get levelLo(){return this.properties.getValue(jp)}get levelLoLo(){return this.properties.getValue(Zp)}get levelHi(){return this.properties.getValue(qp)}get levelHiHi(){return this.properties.getValue(Kp)}get limitsFromPv(){return this.properties.getValue(Jp)}get logScale(){return this.properties.getValue(Qp)}get minimum(){return this.properties.getValue(id)}get majorTickStepHint(){return this.scale*this.properties.getValue(ed)}get maximum(){return this.properties.getValue(td)}get scaleFont(){return this.properties.getValue(rd).scale(this.scale)}get scaleFormat(){return this.properties.getValue(sd)}get showBulb(){return this.properties.getValue(od)}get showMarkers(){return this.properties.getValue(cd)}get showMinorTicks(){return this.properties.getValue(pd)}get showLo(){return this.properties.getValue(ld)}get showLoLo(){return this.properties.getValue(hd)}get showHi(){return this.properties.getValue(nd)}get showHiHi(){return this.properties.getValue(ad)}get showScale(){return this.properties.getValue(dd)}get transparentBackground(){return this.properties.getValue(ud)}get unit(){return this.properties.getValue(gd)}get valueLabelFormat(){return this.properties.getValue(md)}};var xd=-323.3062,wd=308.2547,sr=class{constructor(t,e){this.widget=t;this.index=e}widget;index;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<xd&&(s=xd),s=Math.pow(10,s),o>wd&&(o=wd),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 autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}};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})}xAxis;yAxis;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}}},or=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 nr=class{constructor(t,e){this.widget=e;this.id=t}widget;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,c=n.getValuePosition(a.stop)+r;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(c)}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,c=n.getValuePosition(a.stop)+s;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(c)}}}};var Dr=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)}}},ar=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 Dr(t)}bufferSize;plotMode;updateMode;concatenateData;chronological;historicalDataProvider;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 lr=class{constructor(t,e){this.widget=t;this.i=e}widget;i;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 ar(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:_.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 fg=new m(236,236,236),xg=new m(130,130,130),Nr=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}}imageFile;disabledImageFile;action;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}},hr=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)}xyGraph;buttons=[];showLegend;autoScale;rubberbandZoom;horizontalZoom;verticalZoom;zoomIn;zoomOut;panning;mouseArrow;undo;redo;camera;imagesLoaded=!1;currentTool="default";commandBuffer=new or;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 Nr(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:xg,lineWidth:s})}drawButton(t,e,i,r){let{buttonSize:s,scale:o}=this;t.fillRect({x:e,y:i,width:s,height:s,color:fg}),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,c=Math.round(i+s-n+n/2)-.5,h=Math.round(e+s-n+n/2)-.5;if(t.strokePath({color:r.pushed?m.WHITE:m.BLACK,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c),lineWidth:n}),t.strokePath({color:r.pushed?m.BLACK:m.WHITE,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n),lineWidth:n}),this.imagesLoaded){let u=r.disabled?r.disabledImageElement:r.imageElement,g=u.naturalHeight*o,v=u.naturalWidth*o,b=Math.round(e+(s-v)/2),T=Math.round(i+(s-g)/2);t.ctx.drawImage(u,b,T,v,g)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}};var Fr="axis_count",yd="plot_area_background_color",bd="show_legend",Pd="show_plot_area_border",vd="show_toolbar",_d="title",Rd="title_font",Gr="trace_count",Td="transparent",cr=class extends V{toolbar;plotAreaRegion;axes=[];traces=[];autoScaleAllowed=!0;constructor(t,e){super(t,e),this.properties.add(new P(Fr)),this.properties.add(new S(yd)),this.properties.add(new w(bd)),this.properties.add(new w(Pd)),this.properties.add(new w(vd)),this.properties.add(new R(_d)),this.properties.add(new H(Rd)),this.properties.add(new P(Gr)),this.properties.add(new w(Td)),this.properties.addGenerator(()=>{let i=[];this.axes=[];let r=this.properties.getValue(Fr);for(let o=0;o<r;o++)this.axes.push(new sr(this,o)),i.push(new w(`axis_${o}_auto_scale`),new B(`axis_${o}_auto_scale_treshold`),new S(`axis_${o}_axis_color`),new R(`axis_${o}_axis_title`),new w(`axis_${o}_dash_grid_line`),new S(`axis_${o}_grid_color`),new w(`axis_${o}_log_scale`),new B(`axis_${o}_maximum`),new B(`axis_${o}_minimum`),new H(`axis_${o}_scale_font`),new R(`axis_${o}_scale_format`),new w(`axis_${o}_show_grid`),new P(`axis_${o}_time_format`),new H(`axis_${o}_title_font`),new w(`axis_${o}_visible`)),o>1&&i.push(new w(`axis_${o}_left_bottom_side`),new w(`axis_${o}_y_axis`));this.traces=[];let s=this.properties.getValue(Gr);for(let o=0;o<s;o++)this.traces.push(new lr(this,o)),i.push(new w(`trace_${o}_anti_alias`),new P(`trace_${o}_buffer_size`),new w(`trace_${o}_concatenate_data`),new P(`trace_${o}_line_width`),new R(`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 w(`trace_${o}_visible`),new P(`trace_${o}_x_axis_index`),new R(`trace_${o}_x_pv`),new Pt(`trace_${o}_x_pv_value`,`trace_${o}_x_pv`),new P(`trace_${o}_y_axis_index`),new R(`trace_${o}_y_pv`),new Pt(`trace_${o}_y_pv_value`,`trace_${o}_y_pv`));return i})}init(){this.plotAreaRegion=new nr(`${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},c=this.calculateAutoscaledRange(o,l);c&&(o.effectiveMinimum=c.start,o.effectiveMaximum=c.stop)}let n=o.effectiveMinimum,a=o.effectiveMaximum;o.linearScale=new et(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,bs(r,s))}drawToolbar(t,e){this.toolbar||(this.toolbar=new hr(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 h of this.getXAxes())if(h.visible){let u=0;h.axisTitle&&(u=r+t.measureText(h.axisTitle,h.titleFont).height),o+=u,n+=u+h.linearScale.measureHorizontalHeight(t)}let a=0,l=0;for(let h of this.getYAxes().reverse()){let u=h.linearScale;if(h.visible){let g=u.calculateMargin(t,!1),v=s.height-n+(n>0?g:0),b=0;h.axisTitle&&(b=t.measureText(h.axisTitle,h.titleFont).height,t.ctx.save(),t.ctx.translate(s.x+r+b/2,e.y+v/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:h.titleFont,color:h.axisColor,text:h.axisTitle}),t.ctx.restore(),b+=r);let T=b+u.drawVertical(t,s.x+b,e.y,v,!0,!1);s.x+=T,s.width-=T,a+=T;let W=u.margin;l=l===0?W:Math.min(l,W);let O=i*1,L=Math.round(s.x)-O/2,M=Math.round(e.y+g)-O/2;t.strokePath({path:new _(L,M).lineTo(L,M+v-2*g),color:h.axisColor,opacity:100/255,lineWidth:O})}else{let g=s.height-n;u.setDimensions(0,e.y,g,!1)}}let c=0;for(let h of this.getXAxes().reverse()){let u=h.linearScale;if(h.visible){let g=u.calculateMargin(t,!0),v=a-g,b=0;if(h.axisTitle){b=t.measureText(h.axisTitle,h.titleFont).height;let N=e.x+a+(e.width-a)/2;t.fillText({x:N,y:s.y+s.height-b/2,align:"center",baseline:"middle",font:h.titleFont,color:h.axisColor,text:h.axisTitle}),b+=r}let T=b+u.drawHorizontal(t,e.x+v,s.y+s.height-b,e.width-v);s.height-=T;let W=u.margin;c=c===0?W:Math.min(c,W);let O=i*1,L=Math.round(e.x+v+g)-O/2,M=Math.round(s.y+s.height)-O/2;t.strokePath({path:new _(L,M).lineTo(L+s.width-g,M),color:h.axisColor,opacity:100/255,lineWidth:O})}else{let g=e.x+a,v=e.width-a;u.setDimensions(g,0,v,!0)}}return s.y+=l,s.width-=c,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 _(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 c=o.getValuePosition(l.x),h=l.y!==null?n.getValuePosition(l.y):null;a.push({x:c,y:h})}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({...Tr(s),color:m.BLACK,lineWidth:1*r});break;case"vertical-zoom":let o=i;o.x=e.x,o.width=e.width,t.strokeRect({...Tr(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=q.ARIAL_10.scale(i);for(let a of this.getYAxes()){let l=this.traces.filter(O=>O.visible&&O.yAxisIndex===a.index),c=[],h=[],u=0,g=0;for(let O of l){let L=r+s+o;O.name&&(L+=t.measureText(O.name,n).width),u+L<e.width?(h.push(O),u+=L):(c.push(h),L=Math.max(L,u),h=[O],u=L)}if(h.length&&(c.push(h),g=Math.max(g,u)),!c.length)continue;let v=r*c.length,b={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-v),width:g,height:v};e.height-=b.height,this.transparent||t.fillRect({...b,color:this.plotAreaBackgroundColor}),t.strokeRect({...D(b,1*i/2),color:a.axisColor});let T=b.x,W=b.y;for(let O=0;O<c.length;O++){let L=c[O],M=W+O*r,N=M+r/2;for(let F of L){let X=F.pointSize>Math.floor((r-o)/2)?Math.floor(r-o):F.pointSize;switch(F.traceType){case 3:let j=T+r/2;t.strokePath({path:new _(j,M+X).lineTo(j,M+r),lineWidth:F.lineWidth,color:F.traceColor,opacity:100/255}),F.drawPoint(t,{x:j,y:M+X});break;case 4:case 5:let pt=[{x:T,y:M+r/2},{x:T+r/2,y:M+X},{x:T+r,y:M+r/2},{x:T+r,y:M+r},{x:T,y:M+r}];t.fillPath({path:_.fromPoints(pt),color:F.traceColor,opacity:100/255}),F.traceType===5&&t.strokePath({path:_.fromPoints(pt.slice(0,3)),color:F.traceColor,lineWidth:1*i}),F.drawPoint(t,{x:T+r/2,y:M+X});break;default:F.drawTrace(t,[{x:T,y:N},{x:T+r,y:N}]),F.drawPoint(t,{x:T+r/2,y:N})}T+=r+s,F.name&&(t.fillText({x:T,y:N,align:"left",baseline:"middle",color:F.traceColor,font:n,text:F.name}),T+=t.measureText(F.name,n).width),T+=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(Fr)}get plotAreaBackgroundColor(){return this.properties.getValue(yd)}get showLegend(){return this.properties.getValue(bd)}get showPlotAreaBorder(){return this.properties.getValue(Pd)}get showToolbar(){return this.properties.getValue(vd)}get title(){return this.properties.getValue(_d)}get titleFont(){return this.properties.getValue(Rd).scale(this.scale)}get traceCount(){return this.properties.getValue(Gr)}get transparent(){return this.properties.getValue(Td)}destroy(){for(let t of this.traces)t.destroy()}};var pr=class extends gt{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))}}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.createChild(this.width,this.height);for(let i of this.widgets.filter(r=>r.visible))i.drawHolder(e),i.draw(e),i.drawDecoration(e);for(let i of this.widgets.filter(r=>r.visible))i.drawOverlay(e);t.copy(e,this.x,this.y)}};var Cd="minimum_tab_height",Ur="active_tab",Sd="horizontal_tabs",$r="tab_count",Yr=class{constructor(t,e){this.widget=t;this.i=e;this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(Ur,e),t.requestRepaint())},cursor:"pointer"}}widget;i;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)}},Ie=class extends gt{tabs=[];constructor(t,e){super(t,e),this.properties.add(new P(Cd)),this.properties.add(new P(Ur)),this.properties.add(new w(Sd)),this.properties.add(new P($r)),this.properties.addGenerator(()=>{this.tabs=[];let i=this.properties.getValue($r),r=[];for(let s=0;s<i;s++)this.tabs.push(new Yr(this,s)),r.push(new R(`tab_${s}_title`),new S(`tab_${s}_background_color`),new S(`tab_${s}_foreground_color`),new w(`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],c=t.measureText(l.title,l.font),h,u,g,v,b;this.activeTab===a?(h=n,u=this.y,g=c.width+o+e+i,v=s,b=l.backgroundColor):(h=n+i,u=this.y+2*r,g=c.width+o+e-i,v=s-2*r,b=this.darken(l.backgroundColor)),t.fillRect({x:h,y:u,width:g,height:v,color:b}),t.addHitRegion(l.headerRegion).addRect(h,u,g,v);let W=t.createLinearGradient(h,u,h,u+v);if(W.addColorStop(0,m.WHITE.toString()),W.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:h,y:u,width:g,height:v,gradient:W}),t.fillText({x:h+g/2,y:u+v/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=c.width+o+e-1*r,this.activeTab===a){let O=this.x,L=this.y+s,M=this.width,N=this.height-s;t.fillRect({x:O,y:L,width:M,height:N,color:l.backgroundColor});let F=this.widgets[a],X=t.createChild(M,N);F.drawHolder(X),F.draw(X),F.drawDecoration(X),F.drawOverlay(X),t.copy(X,O,L)}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],c=t.measureText(l.title,l.font),h=Math.max(c.height+o+o,this.minimumTabHeight),u,g,v,b,T;this.activeTab===a?(u=this.x,g=n,v=s,b=h+e+i,T=l.backgroundColor):(u=this.x+2*r,g=n+i,v=s-2*r,b=h+e-i,T=this.darken(l.backgroundColor)),t.fillRect({x:u,y:g,width:v,height:b,color:T}),t.addHitRegion(l.headerRegion).addRect(u,g,v,b);let O=t.createLinearGradient(u,g,u+v,g);if(O.addColorStop(0,m.WHITE.toString()),O.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:u,y:g,width:v,height:b,gradient:O}),t.fillText({x:u+v/2,y:g+b/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=h+e-1*r,this.activeTab===a){let L=this.x+s-1*r,M=this.y,N=this.width-s,F=this.height-1*r;t.fillRect({x:L,y:M,width:N,height:F,color:l.backgroundColor});let X=this.widgets[a],j=t.createChild(N,F);X.drawHolder(j),X.draw(j),X.drawDecoration(j),X.drawOverlay(j),t.copy(j,L,M)}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(Cd)}get activeTab(){return this.properties.getValue(Ur)}get tabCount(){return this.properties.getValue($r)}get horizontalTabs(){return this.properties.getValue(Sd)}};var dr=class{constructor(t){this.table=t}table;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 Ld="columns_count",Ad="column_headers",Ed="column_header_visible",Od="default_content",Vd="font",ur=class extends V{tableWrapper;table;spreadsheet;constructor(t,e){super(t,e),this.properties.add(new P(Ld)),this.properties.add(new Qt(Ad)),this.properties.add(new w(Ed)),this.properties.add(new Qt(Od)),this.properties.add(new H(Vd)),this.spreadsheet=new dr(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 c=s?m.WHITE:r[n].foregroundColor;c&&(a.style.color=c.toString());let h=document.createTextNode(r[n].text||"");a.appendChild(h)}}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(Ld)}get columnHeaders(){return this.properties.getValue(Ad)}get columnHeaderVisible(){return this.properties.getValue(Ed)}get defaultContent(){return this.properties.getValue(Od)}get font(){return this.properties.getValue(Vd).scale(this.scale)}};var Md="url",gr=class extends V{iframe;prevUrl;constructor(t,e){super(t,e),this.properties.add(new R(Md))}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(Md)}};var wg="Action Button",yg="Arc",bg="Boolean Button",Pg="Boolean Switch",vg="Byte Monitor",_g="Check Box",Rg="Choice Button",Tg="Combo",Cg="Combo Box",Sg="Ellipse",Lg="Gauge",Ag="Grouping Container",Eg="Image",Og="Image Boolean Button",Vg="Image Boolean Indicator",Mg="Intensity Graph",Ig="Label",Bg="LED",Wg="Linking Container",Hg="Menu Button",kg="Meter",Dg="Button",Ng="Polygon",Fg="Polyline",Gg="Progress Bar",$g="Radio Box",Ug="Rectangle",Yg="Rounded Rectangle",Xg="Scrollbar",zg="Tabbed Container",qg="Table",Kg="Tank",jg="Text Input",Zg="Text Update",Jg="Thermometer",Qg="Web Browser",tm="XY Graph",Xr=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",t.appendChild(this.rootPanel);let e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new Ge(e),this.ctx=this.g.ctx,this.formatter=new ke(!1),this.pvEngine=new _i(this),this.pvEngine.addProvider(new Ti),this.pvEngine.addProvider(new Ci(this.formatter)),this.pvEngine.addProvider(new Pi),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 Le(this),this.scriptLoader=new bi(this),this.consoleHandler=new Pe,this.dialogHandler=new ve,window.setTimeout(()=>this.step()),new He(this,e,this.g.hitCanvas)}targetElement;rootPanel;g;ctx;pvEngine;pathResolver;fontResolver;scriptLoader;consoleHandler;dialogHandler;formatter;repaintRequested=!1;_editMode=!1;_showGrid=!1;_showOutline=!1;_showRuler=!1;_selection=[];_scale=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;imagesPrefix="";absPrefix="";relPrefix="";instance;eventListeners={closedisplay:[],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}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.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.setTimeout(()=>this.step(),this.refreshCycle)}drawScreen(){if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=16,e.height=16,i.fillStyle="#d6d6d6",i.fillRect(0,0,8,8),i.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(e,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),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.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=25,e.height=25,i.fillStyle=this.instance.foregroundColor.toString(),i.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(e,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let e=0;for(;e<=this.ctx.canvas.width;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(e-75+.5,this.ctx.canvas.height),this.ctx.lineTo(e-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(e-50+.5,this.ctx.canvas.height),this.ctx.lineTo(e-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(e-25+.5,this.ctx.canvas.height),this.ctx.lineTo(e-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(e+.5,this.ctx.canvas.height),this.ctx.lineTo(e+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(e),e,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let i=0;for(;i<=this.ctx.canvas.height;)i+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,i-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,i-75+.5),this.ctx.moveTo(this.ctx.canvas.width,i-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,i-50+.5),this.ctx.moveTo(this.ctx.canvas.width,i-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,i-25+.5),this.ctx.moveTo(this.ctx.canvas.width,i+.5),this.ctx.lineTo(this.ctx.canvas.width-8,i+.5),this.ctx.stroke(),this.ctx.fillText(String(i),this.ctx.canvas.width-8,i)}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 e of this.selection){let i=this.findWidget(e);i&&i.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){this.rootPanel.title=t?.trim()??""}createWidget(t,e){switch(t){case wg:return new he(this,e);case yg:return new Di(this,e);case bg:return new Si(this,e);case Pg:return new Li(this,e);case vg:return new zi(this,e);case _g:return new Ai(this,e);case Rg:return new Ei(this,e);case Tg:case Cg:return new Oi(this,e);case Sg:return new Ni(this,e);case Lg:return new qi(this,e);case Ag:return new pr(this,e);case Eg:return new Fi(this,e);case Og:return new Vi(this,e);case Vg:return new Ki(this,e);case Mg:return new ji(this,e);case Ig:return new Gi(this,e);case Bg:return new Zi(this,e);case Wg:return new oe(this,e);case Hg:return new Mi(this,e);case kg:return new Qi(this,e);case Dg:return new Ii(this,e);case Ng:return new $i(this,e);case Fg:return new Ui(this,e);case Gg:return new tr(this,e);case $g:return new Bi(this,e);case Ug:return new Yi(this,e);case Yg:return new Xi(this,e);case Xg:return new Hi(this,e);case zg:return new Ie(this,e);case qg:return new ur(this,e);case Kg:return new er(this,e);case jg:return new ki(this,e);case Zg:return new ir(this,e);case Jg:return new rr(this,e);case Qg:return new gr(this,e);case tm:return new cr(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){this.instance?.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}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=re.parseFromXML(t);this.instance.parseNode(i).then(()=>{this.pvEngine.init(),this.requestRepaint()})}getRefreshCycle(){return this.refreshCycle}setRefreshCycle(t){this.refreshCycle=t}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0)}measureAbsoluteArea(t){let e=t.bounds,i=t.parent;for(;i;){if(e.x+=i.x,e.y+=i.y,i instanceof Ie){let{x:r,y:s}=i.measureTabOffset(this.g);e.x+=r,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=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 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){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});let e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}};export{ee as AlarmSeverity,m as Color,Ae as CompiledFormula,Pe as DefaultConsoleHandler,ve as DefaultDialogHandler,Le as DefaultPathResolver,Xr as Display,q as Font,Oe as FormulaCompiler,Xt as PV,V as Widget,Vu as colorFromCssColor};
20
+ `+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=dg[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})+`
21
+ `+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 ph="color_map",dh="crop_bottom",uh="crop_left",gh="crop_right",mh="crop_top",fh="data_height",xh="data_width",wh="font",yh="graph_area_height",bh="graph_area_width",Ph="maximum",vh="minimum",_h="show_ramp",Rh="x_axis_axis_color",Th="x_axis_axis_title",Ch="x_axis_major_tick_step_hint",Sh="x_axis_maximum",Lh="x_axis_minimum",Ah="x_axis_scale_font",Eh="x_axis_show_minor_ticks",Oh="x_axis_title_font",Vh="x_axis_visible",Mh="y_axis_axis_color",Ih="y_axis_axis_title",Bh="y_axis_major_tick_step_hint",Wh="y_axis_maximum",Hh="y_axis_minimum",kh="y_axis_scale_font",Dh="y_axis_show_minor_ticks",Nh="y_axis_title_font",Fh="y_axis_visible",Ki=class extends V{constructor(t,e){super(t,e),this.properties.add(new Ft(ph)),this.properties.add(new P(dh)),this.properties.add(new P(uh)),this.properties.add(new P(gh)),this.properties.add(new P(mh)),this.properties.add(new P(fh)),this.properties.add(new P(xh)),this.properties.add(new P(yh)),this.properties.add(new P(bh)),this.properties.add(new H(wh)),this.properties.add(new B(Ph)),this.properties.add(new B(vh)),this.properties.add(new w(_h)),this.properties.add(new S(Rh)),this.properties.add(new R(Th)),this.properties.add(new P(Ch)),this.properties.add(new B(Sh)),this.properties.add(new B(Lh)),this.properties.add(new H(Ah)),this.properties.add(new w(Eh)),this.properties.add(new H(Oh)),this.properties.add(new w(Vh)),this.properties.add(new S(Mh)),this.properties.add(new R(Ih)),this.properties.add(new P(Bh)),this.properties.add(new B(Wh)),this.properties.add(new B(Hh)),this.properties.add(new H(kh)),this.properties.add(new w(Dh)),this.properties.add(new H(Nh)),this.properties.add(new w(Fh))}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{graphAreaWidth:s,graphAreaHeight: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=new et(this.display.formatter,e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),c=l.calculateMargin(t,!0),h=new et(this.display.formatter,e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),u=h.calculateMargin(t,!1),g=l.measureHorizontalHeight(t),v=o+2*u,b=h.drawVertical(t,i.x+a,i.y,v,!0),T=s+2*c,W=i.x+a+b-c,O=i.y+v+g-u;l.drawHorizontal(t,W,O,T);let L=e*1,M=Math.round(i.x+a+b)-L/2,N=Math.round(i.y+u)-L/2;t.strokePath({path:new _(M,N).lineTo(M,N+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:L});let F=M,X=N+o+L;t.strokePath({path:new _(F,X).lineTo(F+s,X),color:this.xAxisAxisColor,opacity:100/255,lineWidth:L});let{dataWidth:j,dataHeight:ct,colorMap:it}=this,{minimum:pt,maximum:st}=this,[It,pe]=it.getMinMax();if(this.value&&this.value.length){let tt=document.createElement("canvas"),{cropLeft:gt,cropRight:_t,cropTop:Bt,cropBottom:Xt}=this;tt.width=j-gt-_t,tt.height=ct-Bt-Xt;let Wt=tt.getContext("2d");for(let mt=gt;mt<j-_t;mt++)for(let ot=Bt;ot<ct-Xt;ot++){let ft=this.value[ot*j+mt];if(it.autoscale){let me=(ft-pt)/(st-pt);ft=It+me*(pe-It)}let[de,ue,ge]=it.lookup(ft);Wt.fillStyle=`rgb(${de},${ue},${ge})`,Wt.fillRect(mt-gt,ot-Bt,1,1)}let Ht=Math.round(i.x+a+b),Rt=Math.round(i.y+h.margin);t.ctx.drawImage(tt,Ht,Rt,s,o)}if(this.showRamp){let tt=new et(this.display.formatter,e,this.font,pt,st,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),gt=i.y+h.margin,_t=o,Bt=tt.drawVertical(t,i.x+i.width,gt,_t,!1,!0),Xt=i.x+a+b+s+this.gap,Wt=i.width-a-b-s-Bt-this.gap,Ht=_t-2*tt.margin,Rt=document.createElement("canvas");Rt.width=Wt,Rt.height=Ht;let mt=Rt.getContext("2d");for(let ot=0;ot<Ht;ot++){let ft=st-ot/Ht*(st-pt);if(it.autoscale){let me=(ft-pt)/(st-pt);ft=It+me*(pe-It)}let[de,ue,ge]=it.lookup(ft);mt.fillStyle=`rgb(${de},${ue},${ge})`,mt.fillRect(0,ot,Wt,1)}t.ctx.drawImage(Rt,Xt,gt+tt.margin)}if(this.xAxisVisible){let tt=i.x+b+s/2;this.yAxisVisible&&(tt+=a),t.fillText({x:tt,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+v/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return this.scale*3}get colorMap(){return this.properties.getValue(ph)}get cropBottom(){return this.properties.getValue(dh)}get cropLeft(){return this.properties.getValue(uh)}get cropRight(){return this.properties.getValue(gh)}get cropTop(){return this.properties.getValue(mh)}get dataHeight(){return this.properties.getValue(fh)}get dataWidth(){return this.properties.getValue(xh)}get font(){return this.properties.getValue(wh).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(yh)}get graphAreaWidth(){return this.scale*this.properties.getValue(bh)}get maximum(){return this.properties.getValue(Ph)}get minimum(){return this.properties.getValue(vh)}get showRamp(){return this.properties.getValue(_h)}get xAxisAxisColor(){return this.properties.getValue(Rh)}get xAxisAxisTitle(){return this.properties.getValue(Th)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Ch)}get xAxisMaximum(){return this.properties.getValue(Sh)}get xAxisMinimum(){return this.properties.getValue(Lh)}get xAxisScaleFont(){return this.properties.getValue(Ah).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Eh)}get xAxisTitleFont(){return this.properties.getValue(Oh).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Vh)}get yAxisAxisColor(){return this.properties.getValue(Mh)}get yAxisAxisTitle(){return this.properties.getValue(Ih)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Bh)}get yAxisMaximum(){return this.properties.getValue(Wh)}get yAxisMinimum(){return this.properties.getValue(Hh)}get yAxisScaleFont(){return this.properties.getValue(kh).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(Dh)}get yAxisTitleFont(){return this.properties.getValue(Nh).scale(this.scale)}get yAxisVisible(){return this.properties.getValue(Fh)}};var Gh="bit",$h="data_type",Uh="effect_3d",Yh="state_count",Xh="square_led",zh="off_color",qh="off_label",Kh="off_state",jh="font",Zh="on_color",Jh="on_label",Qh="on_state",tc="bulb_border",ec="bulb_border_color",ic="state_color_fallback",rc="state_label_fallback",sc="show_boolean_label",ji=class extends V{areaRegion;states=[];constructor(t,e){super(t,e),this.properties.add(new P(Gh)),this.properties.add(new P($h)),this.properties.add(new w(Uh)),this.properties.add(new w(Xh)),this.properties.add(new P(Yh,2)),this.properties.add(new S(zh)),this.properties.add(new R(qh)),this.properties.add(new R(Kh)),this.properties.add(new S(Zh)),this.properties.add(new R(Jh)),this.properties.add(new R(Qh)),this.properties.add(new H(jh)),this.properties.add(new w(sc)),this.properties.add(new S(ic)),this.properties.add(new R(rc)),this.properties.add(new P(tc,3)),this.properties.add(new S(ec,m.DARK_GRAY))}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 R(`state_label_${e}`);r.value=t.getString(`state_label_${e}`),this.properties.add(r);let s=new B(`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.pv?.toNumber()??this.value):this.pv?.value!==void 0?(this.pv?.value>>this.bit&1)>0:this.value!==void 0?(this.value>>this.bit&1)>0:!1:this.dataType===1?(this.pv?.toString()??this.value)===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.pv?.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.pv?.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=xt(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(Gh)}get dataType(){return this.properties.getValue($h)}get squareLed(){return this.properties.getValue(Xh)}get showBooleanLabel(){return this.properties.getValue(sc)}get font(){return this.properties.getValue(jh).scale(this.scale)}get effect3d(){return this.properties.getValue(Uh)}get stateCount(){return this.properties.getValue(Yh)}get bulbBorder(){return this.scale*this.properties.getValue(tc)}get bulbBorderColor(){return this.properties.getValue(ec)}get offLabel(){return this.properties.getValue(qh)}get offColor(){return this.properties.getValue(zh)}get offState(){return this.properties.getValue(Kh)}get onLabel(){return this.properties.getValue(Jh)}get onColor(){return this.properties.getValue(Zh)}get onState(){return this.properties.getValue(Qh)}get stateLabelFallback(){return this.properties.getValue(rc)}get stateColorFallback(){return this.properties.getValue(ic)}};var ug=16,gg=12,mg=-5,fg=45,Zi=$(fg),oc=(1-Math.sin(Zi)/2)/(2*Math.cos(Zi)),nc="color_hi",ac="color_hihi",lc="color_lo",hc="color_lolo",cc="font",pc="level_hi",dc="level_hihi",uc="level_lo",gc="level_lolo",mc="log_scale",fc="minimum",xc="maximum",wc="needle_color",yc="ramp_gradient",bc="scale_font",Pc="show_hi",vc="show_hihi",_c="show_lo",Rc="show_lolo",Tc="show_ramp",Cc="value_label_format",Ji=class extends V{areaRegion;constructor(t,e){super(t,e),this.properties.add(new S(nc)),this.properties.add(new S(ac)),this.properties.add(new S(lc)),this.properties.add(new S(hc)),this.properties.add(new H(cc)),this.properties.add(new P(pc)),this.properties.add(new P(dc)),this.properties.add(new P(uc)),this.properties.add(new P(gc)),this.properties.add(new w(mc)),this.properties.add(new P(xc)),this.properties.add(new P(fc)),this.properties.add(new S(wc)),this.properties.add(new w(yc)),this.properties.add(new H(bc)),this.properties.add(new w(Pc)),this.properties.add(new w(vc)),this.properties.add(new w(_c)),this.properties.add(new w(Rc)),this.properties.add(new w(Tc,!0)),this.properties.add(new R(Cc))}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.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected&&t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}drawRamp(t){let e=String(this.minimum),i=t.measureText(e,this.scaleFont),r=String(this.maximum),s=t.measureText(r,this.scaleFont),o=Math.max(i.width,s.width)/2,n=this.height,a=this.width;n>oc*(a-2*o)&&(n=Math.floor(oc*(a-2*o)));let l=n/(1-Math.sin(Zi)/2),c=Math.floor(this.x-l*(1-Math.cos(Zi))+o),h=this.y,u={x:c,y:h,width:Math.floor(2*l),height:Math.floor(2*l)},{rampWidth:g}=this,v=D(u,u.width/4-g,u.height/4-g);v.width=Math.min(v.width,v.height),v.height=v.width;let b=new ce(g,135,45);b.lolo=this.levelLoLo,b.loloColor=this.colorLoLo,b.showLoLo=!0,b.lo=this.levelLo,b.loColor=this.colorLo,b.showLo=!0,b.hi=this.levelHi,b.hiColor=this.colorHi,b.showHi=!0,b.hihi=this.levelHiHi,b.hihiColor=this.colorHiHi,b.showHiHi=!0,b.minimum=this.minimum,b.maximum=this.maximum,b.gradient=this.rampGradient,b.logScale=this.logScale,b.draw(t,u,v),this.drawNeedle(t,u,b);let T=q.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&this.pv.value!==void 0){let W=this.format(this.pv.value),O=t.measureText(W,T);t.fillText({x:u.x+u.width/2-O.width/2,y:u.y+u.height/2-u.height/4-(b.getRadius()-u.height/4)/2-O.height/2,align:"left",baseline:"top",font:T,text:W,color:this.foregroundColor})}}drawNeedle(t,e,i){let r=e.x+e.width/2,s=e.y+e.height/2,o;if(this.pv&&this.pv.value!==void 0){let v=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(v),this.maximum>this.minimum?v>this.maximum?o+=8:v<this.minimum&&(o-=8):v>this.minimum?o-=8:v<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);let n=$(o),{needleWidth:a,gapBetweenNeedleScale:l,scale:c}=this,h=Tt(r+e.width/4,s-a/2+3*c,r,s,n),u=Tt(r+i.getRadius()-l,s,r,s,n),g=Tt(r+e.width/4,s+a/2-3*c,r,s,n);t.fillPath({color:this.needleColor,path:new _(h.x,h.y).lineTo(u.x,u.y).lineTo(g.x,g.y).closePath()})}get needleWidth(){return this.scale*ug}get gapBetweenNeedleScale(){return this.scale*mg}get rampWidth(){return this.scale*gg}format(t){return this.valueLabelFormat?new rt(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(lc)}get colorLoLo(){return this.properties.getValue(hc)}get colorHi(){return this.properties.getValue(nc)}get colorHiHi(){return this.properties.getValue(ac)}get font(){return this.properties.getValue(cc).scale(this.scale)}get levelLo(){return this.properties.getValue(uc)}get levelLoLo(){return this.properties.getValue(gc)}get levelHi(){return this.properties.getValue(pc)}get levelHiHi(){return this.properties.getValue(dc)}get logScale(){return this.properties.getValue(mc)}get minimum(){return this.properties.getValue(fc)}get maximum(){return this.properties.getValue(xc)}get needleColor(){return this.properties.getValue(wc)}get rampGradient(){return this.properties.getValue(yc)}get scaleFont(){return this.properties.getValue(bc).scale(this.scale)}get showLo(){return this.properties.getValue(_c)}get showLoLo(){return this.properties.getValue(Rc)}get showHi(){return this.properties.getValue(Pc)}get showHiHi(){return this.properties.getValue(vc)}get showRamp(){return this.properties.getValue(Tc)}get valueLabelFormat(){return this.properties.getValue(Cc)}};var Sc="color_hi",Lc="color_hihi",Ac="color_lo",Ec="color_lolo",Oc="color_fillbackground",Vc="effect_3d",Mc="fill_color",Ic="fillcolor_alarm_sensitive",Bc="font",Wc="horizontal",Hc="indicator_mode",kc="level_hi",Dc="level_hihi",Nc="level_lo",Fc="level_lolo",Gc="limits_from_pv",$c="log_scale",Uc="maximum",Yc="major_tick_step_hint",Xc="minimum",zc="origin",qc="origin_ignored",Kc="scale_font",jc="scale_format",Zc="show_hi",Jc="show_hihi",Qc="show_label",tp="show_lo",ep="show_lolo",ip="show_markers",rp="show_minor_ticks",sp="show_scale",op="transparent_background",np="value_label_format",Qi=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(Sc)),this.properties.add(new S(Lc)),this.properties.add(new S(Ac)),this.properties.add(new S(Ec)),this.properties.add(new S(Oc)),this.properties.add(new w(Vc)),this.properties.add(new S(Mc)),this.properties.add(new w(Ic,!1)),this.properties.add(new H(Bc)),this.properties.add(new w(Wc)),this.properties.add(new w(Hc)),this.properties.add(new B(kc)),this.properties.add(new B(Dc)),this.properties.add(new B(Nc)),this.properties.add(new B(Fc)),this.properties.add(new w(Gc)),this.properties.add(new w($c)),this.properties.add(new B(Uc)),this.properties.add(new B(Yc)),this.properties.add(new B(Xc)),this.properties.add(new B(zc,0)),this.properties.add(new w(qc,!0)),this.properties.add(new H(Kc)),this.properties.add(new R(jc)),this.properties.add(new w(Zc)),this.properties.add(new w(Jc)),this.properties.add(new w(Qc)),this.properties.add(new w(tp)),this.properties.add(new w(ep)),this.properties.add(new w(ip)),this.properties.add(new w(rp)),this.properties.add(new w(sp)),this.properties.add(new w(op)),this.properties.add(new R(np))}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 et(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=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.width)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.width)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.width)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.width)}let c=i.x+i.width;if(this.showLoLo&&r!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(r));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(s));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(o));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=c-l-this.markerGap,u=Math.round(e.getValuePosition(n));t.strokePath({path:new _(h,u).lineTo(h-this.markerTickLength,u),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h+this.markerGap,y:u,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,c=Kt([{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),h=_.fromPoints(c);if(this.effect3d){let{x:u,y:g}=c[0],{x:v,y:b}=c[2],T=t.createLinearGradient(u,g,v,b);T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,s.toString()),t.fillPath({path:h,gradient:T}),t.strokePath({path:h,color:m.GRAY,lineWidth:r})}else t.fillPath({path:h,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let u=n;n=a,a=u}let l=Math.round(e.getValuePosition(n)),c=Math.round(e.getValuePosition(a)),h=D({...i,y:l,height:c-l},r);if(t.fillRect({...h,color:s}),this.effect3d){let u=t.createLinearGradient(h.x,0,h.x+h.width,0);u.addColorStop(0,m.WHITE.toString()),u.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...h,gradient:u})}}let o=this.pv?.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 et(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=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.height)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.height)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.height)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.height)}let c=i.y;if(this.showLoLo&&r!==void 0){let h=Math.round(e.getValuePosition(r)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:a})}if(this.showLo&&s!==void 0){let h=Math.round(e.getValuePosition(s)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:a})}if(this.showHi&&o!==void 0){let h=Math.round(e.getValuePosition(o)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:a})}if(this.showHiHi&&n!==void 0){let h=Math.round(e.getValuePosition(n)),u=c+l+this.markerGap;t.strokePath({path:new _(h,u).lineTo(h,u+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:h,y:c,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,c=Kt([{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),h=_.fromPoints(c);if(this.effect3d){let{x:u,y:g}=c[0],{x:v,y:b}=c[2],T=t.createLinearGradient(u,g,v,b);T.addColorStop(0,m.WHITE.toString()),T.addColorStop(1,s.toString()),t.fillPath({path:h,gradient:T}),t.strokePath({path:h,color:m.GRAY,lineWidth:r})}else t.fillPath({path:h,color:s})}else{let n=this.originIgnored?this.min:this.origin,a=this.getFillValue();if(a<n){let u=n;n=a,a=u}let l=Math.round(e.getValuePosition(n)),c=Math.round(e.getValuePosition(a)),h=D({...i,x:l,width:c-l},r);if(t.fillRect({...h,color:s}),this.effect3d){let u=t.createLinearGradient(0,h.y,0,h.y+h.height);u.addColorStop(0,m.WHITE.toString()),u.addColorStop(1,s.withAlpha(0).toString()),t.fillRect({...h,gradient:u})}}let o=this.pv?.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.pv?.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(Ac)}get colorLoLo(){return this.properties.getValue(Ec)}get colorHi(){return this.properties.getValue(Sc)}get colorHiHi(){return this.properties.getValue(Lc)}get colorFillbackground(){return this.properties.getValue(Oc)}get effect3d(){return this.properties.getValue(Vc)}get fillColorAlarmSensitive(){return this.properties.getValue(Ic)}get fillColor(){return this.properties.getValue(Mc)}get font(){return this.properties.getValue(Bc).scale(this.scale)}get horizontal(){return this.properties.getValue(Wc)}get indicatorMode(){return this.properties.getValue(Hc)}get levelLo(){return this.properties.getValue(Nc)}get levelLoLo(){return this.properties.getValue(Fc)}get levelHi(){return this.properties.getValue(kc)}get levelHiHi(){return this.properties.getValue(Dc)}get limitsFromPv(){return this.properties.getValue(Gc)}get logScale(){return this.properties.getValue($c)}get minimum(){return this.properties.getValue(Xc)}get majorTickStepHint(){return this.scale*this.properties.getValue(Yc)}get maximum(){return this.properties.getValue(Uc)}get origin(){return this.properties.getValue(zc)}get originIgnored(){return this.properties.getValue(qc)}get scaleFont(){return this.properties.getValue(Kc).scale(this.scale)}get scaleFormat(){return this.properties.getValue(jc)}get showHi(){return this.properties.getValue(Zc)}get showHiHi(){return this.properties.getValue(Jc)}get showLabel(){return this.properties.getValue(Qc)}get showLo(){return this.properties.getValue(tp)}get showLoLo(){return this.properties.getValue(ep)}get showMarkers(){return this.properties.getValue(ip)}get showMinorTicks(){return this.properties.getValue(rp)}get showScale(){return this.properties.getValue(sp)}get transparentBackground(){return this.properties.getValue(op)}get valueLabelFormat(){return this.properties.getValue(np)}};var ap="color_hi",lp="color_hihi",hp="color_lo",cp="color_lolo",pp="color_fillbackground",dp="fill_color",up="fillcolor_alarm_sensitive",gp="effect_3d",mp="level_hi",fp="level_hihi",xp="level_lo",wp="level_lolo",yp="limits_from_pv",bp="log_scale",Pp="maximum",vp="major_tick_step_hint",_p="minimum",Rp="scale_font",Tp="scale_format",Cp="show_hi",Sp="show_hihi",Lp="show_lo",Ap="show_lolo",Ep="show_markers",Op="show_minor_ticks",Vp="show_scale",Mp="transparent_background",xg=new m(160,160,160),tr=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(ap)),this.properties.add(new S(lp)),this.properties.add(new S(hp)),this.properties.add(new S(cp)),this.properties.add(new S(pp)),this.properties.add(new w(gp)),this.properties.add(new S(dp)),this.properties.add(new w(up,!1)),this.properties.add(new B(mp)),this.properties.add(new B(fp)),this.properties.add(new B(xp)),this.properties.add(new B(wp)),this.properties.add(new w(yp)),this.properties.add(new w(bp)),this.properties.add(new B(Pp)),this.properties.add(new B(vp)),this.properties.add(new B(_p)),this.properties.add(new H(Rp)),this.properties.add(new R(Tp)),this.properties.add(new w(Cp)),this.properties.add(new w(Sp)),this.properties.add(new w(Lp)),this.properties.add(new w(Ap)),this.properties.add(new w(Ep)),this.properties.add(new w(Op)),this.properties.add(new w(Vp)),this.properties.add(new w(Mp))}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 et(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),c=0;this.showMarkers&&(c=this.drawMarkers(t,s,a)),this.drawTank(t,s,l,c,a)}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=q.ARIAL_9.scale(this.scale),l=0;if(this.showLoLo&&r!==void 0){let h=t.measureText("LOLO",a);l=Math.max(l,h.width)}if(this.showLo&&s!==void 0){let h=t.measureText("LO",a);l=Math.max(l,h.width)}if(this.showHi&&o!==void 0){let h=t.measureText("HI",a);l=Math.max(l,h.width)}if(this.showHiHi&&n!==void 0){let h=t.measureText("HIHI",a);l=Math.max(l,h.width)}let c=e.x+e.width-l-this.markerGap-this.markerTickLength;if(this.showLoLo&&r!==void 0){let h=Math.round(i.getValuePosition(r));t.strokePath({path:new _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+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 _(c,h).lineTo(c+this.markerTickLength,h),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:c+this.markerTickLength+this.markerGap,y:h,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,c=e.y+s.margin,h=e.width-i-r,u=e.height-2*s.margin,g=this.defaultCorner,v=11/20;h<2*g&&(v=12/20);let b=Math.floor(h*v);g>2*b-h-2*a&&(g=2*b-h);let T=s.getValuePosition(this.getFillValue()),W=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:c,width:h,height:u,rx:g/2,ry:g/2,color:m.WHITE});let L=t.createLinearGradient(l,c,l+b+2*n,c);L.addColorStop(0,this.colorFillbackground.toString()),L.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:c,width:b,height:u,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(l+h-b-2*n,c,l+h,c),L.addColorStop(0,m.WHITE.withAlpha(0).toString()),L.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+h-b,y:c,width:b,height:u,rx:g/2,ry:g/2,gradient:L});let M=T,N=c+u-T;L=t.createLinearGradient(l,M,l+b+2*n,M),L.addColorStop(0,W.toString()),L.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:M,width:b,height:N,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(l+h-b-2*n,M,l+h,M),L.addColorStop(0,m.WHITE.withAlpha(0).toString()),L.addColorStop(1,W.toString()),t.fillRect({x:l+h-b,y:M,width:b,height:N,rx:g/2,ry:g/2,gradient:L})}else t.fillRect({x:l,y:c,width:h,height:u,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:T,width:h,height:c+u-T,rx:g/2,ry:g/2,color:W});let O=D({x:l,y:c,width:h,height:u},a/2);t.strokeRect({...O,rx:g/2,ry:g/2,color:this.effect3d?xg: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.pv?.value??this.min;return t=Math.max(this.min,t),t=Math.min(this.max,t),t}get colorLo(){return this.properties.getValue(hp)}get colorLoLo(){return this.properties.getValue(cp)}get colorHi(){return this.properties.getValue(ap)}get colorHiHi(){return this.properties.getValue(lp)}get colorFillbackground(){return this.properties.getValue(pp)}get fillColorAlarmSensitive(){return this.properties.getValue(up)}get fillColor(){return this.properties.getValue(dp)}get effect3d(){return this.properties.getValue(gp)}get levelLo(){return this.properties.getValue(xp)}get levelLoLo(){return this.properties.getValue(wp)}get levelHi(){return this.properties.getValue(mp)}get levelHiHi(){return this.properties.getValue(fp)}get limitsFromPv(){return this.properties.getValue(yp)}get logScale(){return this.properties.getValue(bp)}get minimum(){return this.properties.getValue(_p)}get majorTickStepHint(){return this.scale*this.properties.getValue(vp)}get maximum(){return this.properties.getValue(Pp)}get scaleFont(){return this.properties.getValue(Rp).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Tp)}get showLo(){return this.properties.getValue(Lp)}get showLoLo(){return this.properties.getValue(Ap)}get showHi(){return this.properties.getValue(Cp)}get showHiHi(){return this.properties.getValue(Sp)}get showMarkers(){return this.properties.getValue(Ep)}get showMinorTicks(){return this.properties.getValue(Op)}get showScale(){return this.properties.getValue(Vp)}get transparentBackground(){return this.properties.getValue(Mp)}};var Ip="font",Bp="format_type",Wp="horizontal_alignment",Hp="precision",kp="precision_from_pv",Dp="show_lohi",Np="show_units",Fp="vertical_alignment",er=class extends V{areaRegion;tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new H(Ip)),this.properties.add(new P(Bp)),this.properties.add(new P(Wp)),this.properties.add(new P(Hp)),this.properties.add(new w(kp)),this.properties.add(new w(Dp,!0)),this.properties.add(new w(Np,!0)),this.properties.add(new P(Fp))}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}}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.text;if(this.pv?.value!==void 0){let h=this.precisionFromPV?this.pv.precision:this.precision;h===-1&&(h=this.pv.precision??-1),s=Nt(this.pv.value,this.formatType,h,this.pv.typeHint)}else this.value!==void 0&&(s=Nt(this.value,this.formatType,this.precision,void 0));this.showUnits&&this.pv?.units&&(s+=" "+this.pv.units),this.showLohi&&(this.pv?.alarmName==="LOLO"||this.pv?.alarmName==="LOW"?s+=" \u2193":(this.pv?.alarmName==="HIHI"||this.pv?.alarmName==="HIGH")&&(s+=" \u2191"));let o=t.measureText(s,this.font,!0);e.font=this.font.getFontString(),e.textBaseline="alphabetic";let a=e.measureText(s).fontBoundingBoxAscent,l={x:r.x,y:r.y,width:o.width,height:o.height};this.horizAlignment===0||(this.horizAlignment===1?l.x+=(r.width-o.width)/2:this.horizAlignment===2&&(l.x+=r.width-o.width)),this.vertAlignment===0||r.height<=o.height||(this.vertAlignment===1?l.y+=r.height/2-o.height/2:this.vertAlignment===2&&(l.y+=r.height-o.height)),e.textAlign="start",e.textBaseline="top",l.y+=l.height/2-a/2,e.save(),e.beginPath();let c=this.area;e.rect(c.x,c.y,c.width,c.height),e.clip(),e.fillStyle=this.alarmSensitiveForegroundColor.toString(),e.fillText(s,l.x,l.y),e.restore()}get font(){return this.properties.getValue(Ip).scale(this.scale)}get formatType(){return this.properties.getValue(Bp)}get horizAlignment(){return this.properties.getValue(Wp)}get precision(){return this.properties.getValue(Hp)}get precisionFromPV(){return this.properties.getValue(kp)}get showLohi(){return this.properties.getValue(Dp)}get showUnits(){return this.properties.getValue(Np)}get vertAlignment(){return this.properties.getValue(Fp)}};var Gp="color_hi",$p="color_hihi",Up="color_lo",Yp="color_lolo",Xp="color_fillbackground",zp="fill_color",qp="fillcolor_alarm_sensitive",Kp="font",jp="effect_3d",Zp="level_hi",Jp="level_hihi",Qp="level_lo",td="level_lolo",ed="limits_from_pv",id="log_scale",rd="maximum",sd="major_tick_step_hint",od="minimum",nd="scale_font",ad="scale_format",ld="show_bulb",hd="show_hi",cd="show_hihi",pd="show_lo",dd="show_lolo",ud="show_markers",gd="show_minor_ticks",md="show_scale",fd="transparent_background",xd="unit",wd="value_label_format",yd=new m(160,160,160),ir=class extends V{tooltipRegion;constructor(t,e){super(t,e),this.properties.add(new S(Gp)),this.properties.add(new S($p)),this.properties.add(new S(Up)),this.properties.add(new S(Yp)),this.properties.add(new S(Xp)),this.properties.add(new S(zp)),this.properties.add(new w(qp,!1)),this.properties.add(new w(jp)),this.properties.add(new B(Zp)),this.properties.add(new B(Jp)),this.properties.add(new B(Qp)),this.properties.add(new B(td)),this.properties.add(new w(ed)),this.properties.add(new H(Kp)),this.properties.add(new w(id)),this.properties.add(new B(rd)),this.properties.add(new B(sd)),this.properties.add(new B(od)),this.properties.add(new H(nd)),this.properties.add(new R(ad)),this.properties.add(new w(ld)),this.properties.add(new w(hd)),this.properties.add(new w(cd)),this.properties.add(new w(pd)),this.properties.add(new w(dd)),this.properties.add(new w(ud)),this.properties.add(new w(gd)),this.properties.add(new w(md)),this.properties.add(new w(fd)),this.properties.add(new P(xd)),this.properties.add(new R(wd))}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 O=Math.min(s.width/2,this.bulbMaxDiameter);l=s.height<O?0:s.height-O}let c={...s,height:l},h=new et(this.display.formatter,e,this.scaleFont,i,r,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);h.scaleFormat=this.scaleFormat;let u=0,g="";if(this.unit===0?g="\xB0C":this.unit===1?g="\xB0F":this.unit===2&&(g="K"),g){let O=q.ARIAL_9.scale(e),L=t.measureText(g,O),M=2*e;u=L.height+2*M,t.fillText({x:s.x+s.width/2-this.pipeWidth/2-M,y:s.y+M,baseline:"top",align:"right",color:n,font:O,text:g})}let v=c.x+c.width/2-this.pipeWidth/2-1*e,b={...c,y:c.y+u,height:c.height-u+h.calculateMargin(t,!1)},T=h.drawVertical(t,v,b.y,b.height,!1),W=Math.floor(this.pipeWidth/2);if(c={...c,y:h.getValuePosition(r)-W,height:h.scaleLength+2*W},this.drawPipe(t,c,h),this.showMarkers&&this.drawMarkers(t,s,h),this.showBulb){let O=Math.min(s.width/2,this.bulbMaxDiameter),L=1*e,M=s.x+s.width/2,N=s.y+l+O/2,F=O/2,X=O/2;if(t.fillEllipse({cx:M,cy:N,rx:F,ry:X,color:a}),this.effect3d){let it=t.createLinearGradient(M-F,N-X,M+F,N+X);it.addColorStop(0,m.WHITE.toString()),it.addColorStop(1,a.withAlpha(0).toString()),t.fillEllipse({cx:M,cy:N,rx:F,ry:X,gradient:it})}t.strokeEllipse({cx:M,cy:N,rx:F-L/2,ry:X-L/2,color:this.effect3d?yd:n,lineWidth:L});let j={x:Math.round(c.x+c.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(h.getValuePosition(i)),width:this.pipeWidth-2*this.outlineWidth,height:e*3};if(this.effect3d){let it=Math.round(c.x+c.width/2-this.pipeWidth/2),pt=it+this.pipeWidth,st=t.createLinearGradient(it,j.y,pt,j.y);st.addColorStop(0,m.WHITE.toString()),st.addColorStop(1,a.toString()),t.fillRect({...j,gradient:st})}else t.fillRect({...j,color:a});let ct=this.pv?.value;ct&&t.fillText({x:M,y:N,align:"center",baseline:"middle",color:a.contrast(),font:this.font,text:this.format(ct)})}}drawPipe(t,e,i){let{scale:r,outlineWidth:s,min:o,max:n}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,c={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},h=this.getFillValue(),u=i.getValuePosition(h);n>o?h>n?u-=10*r:h<o&&(u+=10*r):h>o?u+=10*r:h<n&&(u-=10*r);let g=this.pipeWidth/2,{x:v,y:b,width:T,height:W}=c;if(this.effect3d){let L=t.createLinearGradient(v,b,v+T,b);L.addColorStop(0,m.WHITE.toString()),L.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({...c,rx:g/2,ry:g/2,gradient:L}),L=t.createLinearGradient(v,b,v+T,b),L.addColorStop(0,m.WHITE.toString()),L.addColorStop(1,l.toString()),t.fillRect({x:v,y:u,width:T,height:b+W-u,rx:g/2,ry:g/2,gradient:L})}else t.fillRect({...c,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:v,y:u,width:T,height:b+W-u,rx:g/2,ry:g/2,color:l});let O=D(c,s/2);t.strokeRect({...O,rx:g/2,ry:g/2,color:this.effect3d?yd:a,lineWidth:s})}drawMarkers(t,e,i){let{lolo:r,lo:s,hi:o,hihi:n}=this,a=q.ARIAL_9.scale(this.scale),l=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&r!==void 0){let c=Math.round(i.getValuePosition(r));t.strokePath({path:new _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+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 _(l,c).lineTo(l+this.markerTickLength,c),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:c,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.pv?.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(Up)}get colorLoLo(){return this.properties.getValue(Yp)}get colorHi(){return this.properties.getValue(Gp)}get colorHiHi(){return this.properties.getValue($p)}get colorFillbackground(){return this.properties.getValue(Xp)}get fillColorAlarmSensitive(){return this.properties.getValue(qp)}get fillColor(){return this.properties.getValue(zp)}get font(){return this.properties.getValue(Kp).scale(this.scale)}get effect3d(){return this.properties.getValue(jp)}get levelLo(){return this.properties.getValue(Qp)}get levelLoLo(){return this.properties.getValue(td)}get levelHi(){return this.properties.getValue(Zp)}get levelHiHi(){return this.properties.getValue(Jp)}get limitsFromPv(){return this.properties.getValue(ed)}get logScale(){return this.properties.getValue(id)}get minimum(){return this.properties.getValue(od)}get majorTickStepHint(){return this.scale*this.properties.getValue(sd)}get maximum(){return this.properties.getValue(rd)}get scaleFont(){return this.properties.getValue(nd).scale(this.scale)}get scaleFormat(){return this.properties.getValue(ad)}get showBulb(){return this.properties.getValue(ld)}get showMarkers(){return this.properties.getValue(ud)}get showMinorTicks(){return this.properties.getValue(gd)}get showLo(){return this.properties.getValue(pd)}get showLoLo(){return this.properties.getValue(dd)}get showHi(){return this.properties.getValue(hd)}get showHiHi(){return this.properties.getValue(cd)}get showScale(){return this.properties.getValue(md)}get transparentBackground(){return this.properties.getValue(fd)}get unit(){return this.properties.getValue(xd)}get valueLabelFormat(){return this.properties.getValue(wd)}};var bd=-323.3062,Pd=308.2547,rr=class{constructor(t,e){this.widget=t;this.index=e}widget;index;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<bd&&(s=bd),s=Math.pow(10,s),o>Pd&&(o=Pd),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 autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}};var ht=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})}xAxis;yAxis;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}}},sr=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 or=class{constructor(t,e){this.widget=e;this.id=t}widget;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 ht(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 ht(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 ht(i.getXAxes(),i.getYAxes());this.rangeZoomXAxes(e),r.saveState(),i.toolbar.addCommand(r)}break;case"vertical-zoom":if(e){let r=new ht(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 ht(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 ht(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,c=n.getValuePosition(a.stop)+r;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(c)}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,c=n.getValuePosition(a.stop)+s;o.effectiveMinimum=n.getPositionValue(l),o.effectiveMaximum=n.getPositionValue(c)}}}};var Nr=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)}}},nr=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 Nr(t)}bufferSize;plotMode;updateMode;concatenateData;chronological;historicalDataProvider;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 ar=class{constructor(t,e){this.widget=t;this.i=e}widget;i;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 nr(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:_.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 wg=new m(236,236,236),yg=new m(130,130,130),Fr=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}}imageFile;disabledImageFile;action;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}},lr=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 ht(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)}xyGraph;buttons=[];showLegend;autoScale;rubberbandZoom;horizontalZoom;verticalZoom;zoomIn;zoomOut;panning;mouseArrow;undo;redo;camera;imagesLoaded=!1;currentTool="default";commandBuffer=new sr;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 Fr(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:yg,lineWidth:s})}drawButton(t,e,i,r){let{buttonSize:s,scale:o}=this;t.fillRect({x:e,y:i,width:s,height:s,color:wg}),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,c=Math.round(i+s-n+n/2)-.5,h=Math.round(e+s-n+n/2)-.5;if(t.strokePath({color:r.pushed?m.WHITE:m.BLACK,path:new _(h,c).lineTo(h,a).moveTo(h,c).lineTo(l,c),lineWidth:n}),t.strokePath({color:r.pushed?m.BLACK:m.WHITE,path:new _(l,a).lineTo(h-n,a).moveTo(l,a).lineTo(l,c-n),lineWidth:n}),this.imagesLoaded){let u=r.disabled?r.disabledImageElement:r.imageElement,g=u.naturalHeight*o,v=u.naturalWidth*o,b=Math.round(e+(s-v)/2),T=Math.round(i+(s-g)/2);t.ctx.drawImage(u,b,T,v,g)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}};var Gr="axis_count",vd="plot_area_background_color",_d="show_legend",Rd="show_plot_area_border",Td="show_toolbar",Cd="title",Sd="title_font",$r="trace_count",Ld="transparent",hr=class extends V{toolbar;plotAreaRegion;axes=[];traces=[];autoScaleAllowed=!0;constructor(t,e){super(t,e),this.properties.add(new P(Gr)),this.properties.add(new S(vd)),this.properties.add(new w(_d)),this.properties.add(new w(Rd)),this.properties.add(new w(Td)),this.properties.add(new R(Cd)),this.properties.add(new H(Sd)),this.properties.add(new P($r)),this.properties.add(new w(Ld)),this.properties.addGenerator(()=>{let i=[];this.axes=[];let r=this.properties.getValue(Gr);for(let o=0;o<r;o++)this.axes.push(new rr(this,o)),i.push(new w(`axis_${o}_auto_scale`),new B(`axis_${o}_auto_scale_treshold`),new S(`axis_${o}_axis_color`),new R(`axis_${o}_axis_title`),new w(`axis_${o}_dash_grid_line`),new S(`axis_${o}_grid_color`),new w(`axis_${o}_log_scale`),new B(`axis_${o}_maximum`),new B(`axis_${o}_minimum`),new H(`axis_${o}_scale_font`),new R(`axis_${o}_scale_format`),new w(`axis_${o}_show_grid`),new P(`axis_${o}_time_format`),new H(`axis_${o}_title_font`),new w(`axis_${o}_visible`)),o>1&&i.push(new w(`axis_${o}_left_bottom_side`),new w(`axis_${o}_y_axis`));this.traces=[];let s=this.properties.getValue($r);for(let o=0;o<s;o++)this.traces.push(new ar(this,o)),i.push(new w(`trace_${o}_anti_alias`),new P(`trace_${o}_buffer_size`),new w(`trace_${o}_concatenate_data`),new P(`trace_${o}_line_width`),new R(`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 w(`trace_${o}_visible`),new P(`trace_${o}_x_axis_index`),new R(`trace_${o}_x_pv`),new bt(`trace_${o}_x_pv_value`,`trace_${o}_x_pv`),new P(`trace_${o}_y_axis_index`),new R(`trace_${o}_y_pv`),new bt(`trace_${o}_y_pv_value`,`trace_${o}_y_pv`));return i})}init(){this.plotAreaRegion=new or(`${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},c=this.calculateAutoscaledRange(o,l);c&&(o.effectiveMinimum=c.start,o.effectiveMaximum=c.stop)}let n=o.effectiveMinimum,a=o.effectiveMaximum;o.linearScale=new et(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,Rs(r,s))}drawToolbar(t,e){this.toolbar||(this.toolbar=new lr(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 h of this.getXAxes())if(h.visible){let u=0;h.axisTitle&&(u=r+t.measureText(h.axisTitle,h.titleFont).height),o+=u,n+=u+h.linearScale.measureHorizontalHeight(t)}let a=0,l=0;for(let h of this.getYAxes().reverse()){let u=h.linearScale;if(h.visible){let g=u.calculateMargin(t,!1),v=s.height-n+(n>0?g:0),b=0;h.axisTitle&&(b=t.measureText(h.axisTitle,h.titleFont).height,t.ctx.save(),t.ctx.translate(s.x+r+b/2,e.y+v/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:h.titleFont,color:h.axisColor,text:h.axisTitle}),t.ctx.restore(),b+=r);let T=b+u.drawVertical(t,s.x+b,e.y,v,!0,!1);s.x+=T,s.width-=T,a+=T;let W=u.margin;l=l===0?W:Math.min(l,W);let O=i*1,L=Math.round(s.x)-O/2,M=Math.round(e.y+g)-O/2;t.strokePath({path:new _(L,M).lineTo(L,M+v-2*g),color:h.axisColor,opacity:100/255,lineWidth:O})}else{let g=s.height-n;u.setDimensions(0,e.y,g,!1)}}let c=0;for(let h of this.getXAxes().reverse()){let u=h.linearScale;if(h.visible){let g=u.calculateMargin(t,!0),v=a-g,b=0;if(h.axisTitle){b=t.measureText(h.axisTitle,h.titleFont).height;let N=e.x+a+(e.width-a)/2;t.fillText({x:N,y:s.y+s.height-b/2,align:"center",baseline:"middle",font:h.titleFont,color:h.axisColor,text:h.axisTitle}),b+=r}let T=b+u.drawHorizontal(t,e.x+v,s.y+s.height-b,e.width-v);s.height-=T;let W=u.margin;c=c===0?W:Math.min(c,W);let O=i*1,L=Math.round(e.x+v+g)-O/2,M=Math.round(s.y+s.height)-O/2;t.strokePath({path:new _(L,M).lineTo(L+s.width-g,M),color:h.axisColor,opacity:100/255,lineWidth:O})}else{let g=e.x+a,v=e.width-a;u.setDimensions(g,0,v,!0)}}return s.y+=l,s.width-=c,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 _(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 c=o.getValuePosition(l.x),h=l.y!==null?n.getValuePosition(l.y):null;a.push({x:c,y:h})}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({...Cr(s),color:m.BLACK,lineWidth:1*r});break;case"vertical-zoom":let o=i;o.x=e.x,o.width=e.width,t.strokeRect({...Cr(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=q.ARIAL_10.scale(i);for(let a of this.getYAxes()){let l=this.traces.filter(O=>O.visible&&O.yAxisIndex===a.index),c=[],h=[],u=0,g=0;for(let O of l){let L=r+s+o;O.name&&(L+=t.measureText(O.name,n).width),u+L<e.width?(h.push(O),u+=L):(c.push(h),L=Math.max(L,u),h=[O],u=L)}if(h.length&&(c.push(h),g=Math.max(g,u)),!c.length)continue;let v=r*c.length,b={x:Math.round(e.x+(e.width-g)/2),y:Math.round(e.y+e.height-v),width:g,height:v};e.height-=b.height,this.transparent||t.fillRect({...b,color:this.plotAreaBackgroundColor}),t.strokeRect({...D(b,1*i/2),color:a.axisColor});let T=b.x,W=b.y;for(let O=0;O<c.length;O++){let L=c[O],M=W+O*r,N=M+r/2;for(let F of L){let X=F.pointSize>Math.floor((r-o)/2)?Math.floor(r-o):F.pointSize;switch(F.traceType){case 3:let j=T+r/2;t.strokePath({path:new _(j,M+X).lineTo(j,M+r),lineWidth:F.lineWidth,color:F.traceColor,opacity:100/255}),F.drawPoint(t,{x:j,y:M+X});break;case 4:case 5:let ct=[{x:T,y:M+r/2},{x:T+r/2,y:M+X},{x:T+r,y:M+r/2},{x:T+r,y:M+r},{x:T,y:M+r}];t.fillPath({path:_.fromPoints(ct),color:F.traceColor,opacity:100/255}),F.traceType===5&&t.strokePath({path:_.fromPoints(ct.slice(0,3)),color:F.traceColor,lineWidth:1*i}),F.drawPoint(t,{x:T+r/2,y:M+X});break;default:F.drawTrace(t,[{x:T,y:N},{x:T+r,y:N}]),F.drawPoint(t,{x:T+r/2,y:N})}T+=r+s,F.name&&(t.fillText({x:T,y:N,align:"left",baseline:"middle",color:F.traceColor,font:n,text:F.name}),T+=t.measureText(F.name,n).width),T+=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(Gr)}get plotAreaBackgroundColor(){return this.properties.getValue(vd)}get showLegend(){return this.properties.getValue(_d)}get showPlotAreaBorder(){return this.properties.getValue(Rd)}get showToolbar(){return this.properties.getValue(Td)}get title(){return this.properties.getValue(Cd)}get titleFont(){return this.properties.getValue(Sd).scale(this.scale)}get traceCount(){return this.properties.getValue($r)}get transparent(){return this.properties.getValue(Ld)}destroy(){for(let t of this.traces)t.destroy()}};var cr=class extends ut{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))}}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.createChild(this.width,this.height);for(let i of this.widgets.filter(r=>r.visible))i.drawHolder(e),i.draw(e),i.drawDecoration(e);for(let i of this.widgets.filter(r=>r.visible))i.drawOverlay(e);t.copy(e,this.x,this.y)}};var Ad="minimum_tab_height",Yr="active_tab",Ed="horizontal_tabs",Ur="tab_count",Xr=class{constructor(t,e){this.widget=t;this.i=e;this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(Yr,e),t.requestRepaint())},cursor:"pointer"}}widget;i;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)}},Me=class extends ut{tabs=[];constructor(t,e){super(t,e),this.properties.add(new P(Ad)),this.properties.add(new P(Yr)),this.properties.add(new w(Ed)),this.properties.add(new P(Ur)),this.properties.addGenerator(()=>{this.tabs=[];let i=this.properties.getValue(Ur),r=[];for(let s=0;s<i;s++)this.tabs.push(new Xr(this,s)),r.push(new R(`tab_${s}_title`),new S(`tab_${s}_background_color`),new S(`tab_${s}_foreground_color`),new w(`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],c=t.measureText(l.title,l.font),h,u,g,v,b;this.activeTab===a?(h=n,u=this.y,g=c.width+o+e+i,v=s,b=l.backgroundColor):(h=n+i,u=this.y+2*r,g=c.width+o+e-i,v=s-2*r,b=this.darken(l.backgroundColor)),t.fillRect({x:h,y:u,width:g,height:v,color:b}),t.addHitRegion(l.headerRegion).addRect(h,u,g,v);let W=t.createLinearGradient(h,u,h,u+v);if(W.addColorStop(0,m.WHITE.toString()),W.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:h,y:u,width:g,height:v,gradient:W}),t.fillText({x:h+g/2,y:u+v/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=c.width+o+e-1*r,this.activeTab===a){let O=this.x,L=this.y+s,M=this.width,N=this.height-s;t.fillRect({x:O,y:L,width:M,height:N,color:l.backgroundColor});let F=this.widgets[a],X=t.createChild(M,N);F.drawHolder(X),F.draw(X),F.drawDecoration(X),F.drawOverlay(X),t.copy(X,O,L)}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],c=t.measureText(l.title,l.font),h=Math.max(c.height+o+o,this.minimumTabHeight),u,g,v,b,T;this.activeTab===a?(u=this.x,g=n,v=s,b=h+e+i,T=l.backgroundColor):(u=this.x+2*r,g=n+i,v=s-2*r,b=h+e-i,T=this.darken(l.backgroundColor)),t.fillRect({x:u,y:g,width:v,height:b,color:T}),t.addHitRegion(l.headerRegion).addRect(u,g,v,b);let O=t.createLinearGradient(u,g,u+v,g);if(O.addColorStop(0,m.WHITE.toString()),O.addColorStop(1,m.WHITE.withAlpha(0).toString()),t.fillRect({x:u,y:g,width:v,height:b,gradient:O}),t.fillText({x:u+v/2,y:g+b/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),n+=h+e-1*r,this.activeTab===a){let L=this.x+s-1*r,M=this.y,N=this.width-s,F=this.height-1*r;t.fillRect({x:L,y:M,width:N,height:F,color:l.backgroundColor});let X=this.widgets[a],j=t.createChild(N,F);X.drawHolder(j),X.draw(j),X.drawDecoration(j),X.drawOverlay(j),t.copy(j,L,M)}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(Ad)}get activeTab(){return this.properties.getValue(Yr)}get tabCount(){return this.properties.getValue(Ur)}get horizontalTabs(){return this.properties.getValue(Ed)}};var pr=class{constructor(t){this.table=t}table;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 Od="columns_count",Vd="column_headers",Md="column_header_visible",Id="default_content",Bd="font",dr=class extends V{tableWrapper;table;spreadsheet;constructor(t,e){super(t,e),this.properties.add(new P(Od)),this.properties.add(new Zt(Vd)),this.properties.add(new w(Md)),this.properties.add(new Zt(Id)),this.properties.add(new H(Bd)),this.spreadsheet=new pr(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 c=s?m.WHITE:r[n].foregroundColor;c&&(a.style.color=c.toString());let h=document.createTextNode(r[n].text||"");a.appendChild(h)}}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(Od)}get columnHeaders(){return this.properties.getValue(Vd)}get columnHeaderVisible(){return this.properties.getValue(Md)}get defaultContent(){return this.properties.getValue(Id)}get font(){return this.properties.getValue(Bd).scale(this.scale)}};var Wd="url",ur=class extends V{iframe;prevUrl;constructor(t,e){super(t,e),this.properties.add(new R(Wd))}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(Wd)}};var bg="Action Button",Pg="Arc",vg="Boolean Button",_g="Boolean Switch",Rg="Byte Monitor",Tg="Check Box",Cg="Choice Button",Sg="Combo",Lg="Combo Box",Ag="Ellipse",Eg="Gauge",Og="Grouping Container",Vg="Image",Mg="Image Boolean Button",Ig="Image Boolean Indicator",Bg="Intensity Graph",Wg="Label",Hg="LED",kg="Linking Container",Dg="Menu Button",Ng="Meter",Fg="Button",Gg="Polygon",$g="Polyline",Ug="Progress Bar",Yg="Radio Box",Xg="Rectangle",zg="Rounded Rectangle",qg="Scrollbar",Kg="Tabbed Container",jg="Table",Zg="Tank",Jg="Text Input",Qg="Text Update",tm="Thermometer",em="Web Browser",im="XY Graph",zr=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",t.appendChild(this.rootPanel);let e=document.createElement("canvas");this.rootPanel.appendChild(e),this.g=new Ge(e),this.ctx=this.g.ctx,this.formatter=new He(!1),this.pvEngine=new vi(this),this.pvEngine.addProvider(new Ri),this.pvEngine.addProvider(new Ti(this.formatter)),this.pvEngine.addProvider(new bi),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 Se(this),this.scriptLoader=new yi(this),this.consoleHandler=new ye,this.dialogHandler=new be,this.imageLoader=new Pe,window.setTimeout(()=>this.step()),new We(this,e,this.g.hitCanvas)}targetElement;rootPanel;g;ctx;pvEngine;pathResolver;fontResolver;scriptLoader;imageLoader;consoleHandler;dialogHandler;formatter;repaintRequested=!1;_editMode=!1;_showGrid=!1;_showOutline=!1;_showRuler=!1;_selection=[];_scale=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;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.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.setTimeout(()=>this.step(),this.refreshCycle)}drawScreen(){if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=16,e.height=16,i.fillStyle="#d6d6d6",i.fillRect(0,0,8,8),i.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(e,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),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.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){let e=document.createElement("canvas"),i=e.getContext("2d");e.width=25,e.height=25,i.fillStyle=this.instance.foregroundColor.toString(),i.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(e,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let e=0;for(;e<=this.ctx.canvas.width;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(e-75+.5,this.ctx.canvas.height),this.ctx.lineTo(e-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(e-50+.5,this.ctx.canvas.height),this.ctx.lineTo(e-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(e-25+.5,this.ctx.canvas.height),this.ctx.lineTo(e-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(e+.5,this.ctx.canvas.height),this.ctx.lineTo(e+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(e),e,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let i=0;for(;i<=this.ctx.canvas.height;)i+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,i-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,i-75+.5),this.ctx.moveTo(this.ctx.canvas.width,i-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,i-50+.5),this.ctx.moveTo(this.ctx.canvas.width,i-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,i-25+.5),this.ctx.moveTo(this.ctx.canvas.width,i+.5),this.ctx.lineTo(this.ctx.canvas.width-8,i+.5),this.ctx.stroke(),this.ctx.fillText(String(i),this.ctx.canvas.width-8,i)}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 e of this.selection){let i=this.findWidget(e);i&&i.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){this.rootPanel.title=t?.trim()??""}createWidget(t,e){switch(t){case bg:return new ae(this,e);case Pg:return new ki(this,e);case vg:return new Ci(this,e);case _g:return new Si(this,e);case Rg:return new Xi(this,e);case Tg:return new Li(this,e);case Cg:return new Ai(this,e);case Sg:case Lg:return new Ei(this,e);case Ag:return new Di(this,e);case Eg:return new zi(this,e);case Og:return new cr(this,e);case Vg:return new Ni(this,e);case Mg:return new Oi(this,e);case Ig:return new qi(this,e);case Bg:return new Ki(this,e);case Wg:return new Fi(this,e);case Hg:return new ji(this,e);case kg:return new re(this,e);case Dg:return new Vi(this,e);case Ng:return new Ji(this,e);case Fg:return new Mi(this,e);case Gg:return new Gi(this,e);case $g:return new $i(this,e);case Ug:return new Qi(this,e);case Yg:return new Ii(this,e);case Xg:return new Ui(this,e);case zg:return new Yi(this,e);case qg:return new Wi(this,e);case Kg:return new Me(this,e);case jg:return new dr(this,e);case Zg:return new tr(this,e);case Jg:return new Hi(this,e);case Qg:return new er(this,e);case tm:return new ir(this,e);case em:return new ur(this,e);case im:return new hr(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){this.instance?.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}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 ie(this,void 0,e);let i=ee.parseFromXML(t);this.instance.parseNode(i).then(()=>{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)}measureAbsoluteArea(t){let e=t.bounds,i=t.parent;for(;i;){if(e.x+=i.x,e.y+=i.y,i instanceof Me){let{x:r,y:s}=i.measureTabOffset(this.g);e.x+=r,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=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 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){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});let e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}};var qr=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 Kr=class{pending=new Map;async load(t){return new Promise(e=>{this.pending.set(t,e),window.parent.postMessage({type:"loadScript",path:t},"*")})}receiveContent(t,e){let i=this.pending.get(t);i&&(this.pending.delete(t),i(e))}};var gr=new Map;var mr=class{constructor(t,e){this.pvName=t;this.widget=e;let i=gr.get(t)??[],r=i.length>0;i.push(this),gr.set(t,i),r||window.parent.postMessage({type:"historySubscribe",pvName:t},"*")}pvName;widget;samples=[];getSamples(){return this.samples}updateSamples(t){this.samples=t,this.widget.requestRepaint()}disconnect(){let t=gr.get(this.pvName)??[],e=t.indexOf(this);e!==-1&&t.splice(e,1),t.length===0&&(gr.delete(this.pvName),window.parent.postMessage({type:"historyUnsubscribe",pvName:this.pvName},"*"))}};var jr=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 mr(t,e)}shutdown(){}};export{Qt as AlarmSeverity,m as Color,Le as CompiledFormula,ye as DefaultConsoleHandler,be as DefaultDialogHandler,Pe as DefaultImageLoader,Se as DefaultPathResolver,zr as Display,q as Font,Ee as FormulaCompiler,Yt as PV,qr as PostMessageImageLoader,jr as PostMessagePVProvider,Kr as PostMessageScriptLoader,V as Widget,Bu as colorFromCssColor};
22
22
  //# sourceMappingURL=opi.js.map