@yamcs/opi 1.3.13 → 1.3.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";(()=>{function ye(c){let t=document.createElement("canvas").getContext("2d");t.fillStyle=c;let e=String(t.fillStyle),i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return i?new m(parseInt(i[1],16),parseInt(i[2],16),parseInt(i[3],16)):m.BLACK}var m=class c{constructor(t,e,i,r=255){this.red=t;this.green=e;this.blue=i;this.alpha=r}red;green;blue;alpha;static TRANSPARENT=new c(0,0,0,0);static BLACK=new c(0,0,0);static BLUE=new c(0,0,255);static CYAN=new c(0,255,255);static DARK_GRAY=new c(150,150,150);static GRAY=new c(200,200,200);static GREEN=new c(0,255,0);static LIGHT_BLUE=new c(153,186,243);static ORANGE=new c(255,128,0);static PINK=new c(255,0,255);static PURPLE=new c(128,0,255);static RED=new c(255,0,0);static WHITE=new c(255,255,255);static YELLOW=new c(255,255,0);static BUTTON=new c(239,240,241);static BUTTON_DARKER=new c(164,168,172);static BUTTON_DARKEST=c.BLACK;static BUTTON_LIGHTEST=c.WHITE;withAlpha(t){return new c(this.red,this.green,this.blue,t)}mixWith(t,e){let i=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),s=Math.floor(this.blue*e+t.blue*(1-e));return new c(i,r,s)}brighter(){let{red:t,green:e,blue:i}=this,r=Math.floor(1/(1-.7));return t===0&&e===0&&i===0?new c(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),new c(Math.min(Math.floor(this.red/.7),255),Math.min(Math.floor(this.green/.7),255),Math.min(Math.floor(this.blue/.7),255)))}darker(){return new c(Math.max(Math.floor(this.red*.7),0),Math.max(Math.floor(this.green*.7),0),Math.max(Math.floor(this.blue*.7),0))}contrast(){return new c(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=t.length==1?"0"+t:t;let e=this.green.toString(16);e=e.length==1?"0"+e:e;let i=this.blue.toString(16);i=i.length==1?"0"+i:i;let r=this.alpha.toString(16);return r=r.length==1?"0"+r:r,`#${t}${e}${i}${r}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}};var Ve=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};var Me=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 Er=c=>(document.removeEventListener("click",Er,!0),c.preventDefault(),c.stopPropagation(),!1);function Ar(c){return(c.buttons&1)===1||c.buttons===void 0&&c.which==1}var Ts=5;function Nu(c,t,e,i){return Math.sqrt((e-c)*(e-c)+(i-t)*(i-t))}function Cs(c,t){return c&&t&&c.id===t.id}var Ie=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",Er,!0),Ar(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&&(Cs(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(Cs(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&&Ar(t)){let s=Nu(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(s)>Ts&&(this.initiateGrab(),Ts>0&&this.grabPoint&&(this.grabPoint=e))}this.grabbing&&this.grabTarget&&Ar(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",Er,!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 Be=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 Ss="rgb(255,255,255)",Fu=!!navigator.brave,We=class c{constructor(t,e,i){this.parent=t;let r=document.createElement("canvas");r.width=e??r.width,r.height=i??r.height,this.ctx=r.getContext("2d",{willReadFrequently:!0}),this.root=t?.root||t}parent;ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=Ss,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){let e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){let i=this.ctx.getImageData(t,e,1,1).data,r=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(r)||void 0}createChild(t,e){return new c(this,t,e)}transferToParent(t,e,i,r){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,r)}generateUniqueColor(t){for(;;){let e=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=Math.round(Math.random()*255),s=`rgb(${e},${i},${r})`;if(!this.regionsByColor.has(s)&&s!==Ss)return Fu?(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(c,t,e,i,r){return D({x:c,y:t,width:e,height:i},r/2)}function Ct(c,t,e,i,r){let s=Math.sin(r),o=Math.cos(r),n=c-e,a=t-i;return{x:n*o-a*s+e,y:n*s+a*o+i}}function D(c,t,e){return e===void 0&&(e=t),{x:c.x+e,y:c.y+t,width:c.width-(e+e),height:c.height-(t+t)}}function Or(c){return{x:Math.round(c.x)+.5,y:Math.round(c.y)+.5,width:Math.round(c.width),height:Math.round(c.height)}}function Ls(c,t){let e=c.x,i=c.y,r=e+c.width,s=i+c.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 p=Math.max(e,o),h=Math.max(i,n);return{x:p,y:h,width:Math.min(r,a)-p,height:Math.min(s,l)-h}}function yt(c,t,e){return{x:c.x+t,y:c.y+e}}function Kt(c,t,e){return c.map(i=>yt(i,t,e))}function $(c){return c*Math.PI/180}function bt(c,t,e){let i=Math.floor(c*Math.cos(t)),r=Math.floor(-c*Math.sin(t));return{x:e.x+e.width/2+i,y:e.y+e.height/2+r}}function ke(c,t){let e=t.x-c.x,i=t.y-c.y,r=Math.sqrt(Math.pow(e,2)+Math.pow(i,2)),s=Math.acos(e/r);return i>0&&(s=2*Math.PI-s),new 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(c,t){return c.map(e=>({x:e.x*t,y:e.y*t}))}function He(c){return c.map(t=>({x:t.x+.5,y:t.y+.5}))}function De(c,t,e,i,r,s,o){c.beginPath(),!s&&!o?c.rect(t,e,i,r):(i<2*s&&(s=i/2),r<2*o&&(o=r/2),c.moveTo(t+s,e),c.lineTo(t+i-s,e),c.quadraticCurveTo(t+i,e,t+i,e+o),c.lineTo(t+i,e+r-o),c.quadraticCurveTo(t+i,e+r,t+i-s,e+r),c.lineTo(t+s,e+r),c.quadraticCurveTo(t,e+r,t,e+r-o),c.lineTo(t,e+o),c.quadraticCurveTo(t,e,t+s,e))}function Ft(c,t,e,i){return c===null?"":typeof c=="string"?i==="BINARY_STRING"?Gu(c):c:typeof c=="number"?e===-1?As(t,c,void 0,3):As(t,c,e,e):c instanceof Date?c.toISOString().replace("T"," ").replace("Z",""):String(c)}function Gu(c){let t="";for(let e=0;e<c.length;e++){let i=c.charCodeAt(e).toString(16);t+=i.length===2?i:"0"+i}return t&&`0x${t.toUpperCase()}`}function As(c,t,e,i){if(t==null||t==null)return"";switch(c){case 0:case 1:let r={minimumFractionDigits:e,maximumFractionDigits:i,useGrouping:!1,roundingMode:"halfEven"};return Intl.NumberFormat("en-US",r).format(t);case 2:return t.toExponential(i).replace("e+","E").toUpperCase();case 3:return"0x"+t.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${c}`),String(t)}}var Ne=class c{constructor(t,e){this.canvas=t;this.ctx=t.getContext("2d"),this.hitCanvas=e||new We,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 c(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,p=l/a;p>s&&(p=s,l=p*a),this.copyScaled(t,e,i,l,p)}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?(De(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?(De(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?(De(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 Vr(this.hitCanvas.ctx)}},_=class c{segments=[];constructor(t,e){this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){let e=t.findIndex(r=>r.y!==null);if(e===-1){let r=new c(0,0);return r.segments.length=0,r}let i=new c(t[e].x,t[e].y);for(let r=e+1;r<t.length;r++){let{x:s,y:o}=t[r];o!==null&&(r>0&&t[r-1].y===null?i.moveTo(s,o):i.lineTo(s,o))}return i}getBoundingBox(){let t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){let r=this.segments[i];r.x<t.x&&(t.x=r.x),r.x>e.x&&(e.x=r.x),r.y<t.y&&(t.y=r.y),r.y>e.y&&(e.y=r.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){if(this.segments.length){let t=this.segments[0];this.segments.push({x:t.x,y:t.y,line:!0})}return this}translate(t,e){for(let i of this.segments)i.x+=t,i.y+=e;return this}},Vr=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 Fe=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 be)e.value=t.getActions(e.name);else if(e instanceof Re)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 k)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 ve)e.value=t.getRules(e.name);else if(e instanceof _e)e.value=t.getScaleOptions(e.name);else if(e instanceof Pe)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 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}},J=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 J{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},Pt=class extends J{constructor(e,i){super(e);this.pvPropertyName=i}pvPropertyName},P=class extends J{},B=class extends J{},w=class extends J{},S=class extends J{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},k=class extends J{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},Gt=class extends J{printScriptValue(t){return`${t.code}`}},vt=class extends J{},be=class extends J{},$t=class extends J{},Pe=class extends J{},_t=class extends J{},Ut=class extends J{},Zt=class extends J{},ve=class extends J{},_e=class extends J{},Re=class extends J{};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 Es="description",j=class{properties;constructor(){this.properties=new jt(null,[new R(Es,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(Es)}};var Os="command",Vs="command_directory",Ms="wait_time",Ge=class extends j{constructor(){super(),this.properties.add(new R(Os,"")),this.properties.add(new R(Vs,"$(user.home)")),this.properties.add(new P(Ms,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(Os)}get commandDirectory(){return this.properties.getValue(Vs)}get waitTime(){return this.properties.getValue(Ms)}toString(){return`Execute Command ${this.command}`}};var Uu=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],K=class c{constructor(t,e,i,r){this.name=t;this.style=i;r?this.height=e:c.LEGACY_FONT_SIZING?this.height=Math.round(e*16/15):this.height=Math.ceil(e*4/3)}name;style;static LEGACY_FONT_SIZING=!1;static ARIAL_9=new c("Arial",9,0,!1);static ARIAL_10=new c("Arial",10,0,!1);static ARIAL_11=new c("Arial",11,0,!1);static ARIAL_12_BOLD=new c("Arial",12,1,!1);height;scale(t){return new c(this.name,t*this.height,this.style,!0)}getFontString(){let t=this.name;return 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 Uu.indexOf(this.name)!==-1}};var $e=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 K(t,e,i,!1)}};var Ue=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 Ye=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var Xe=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]),p=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,p]}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 ze=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 qe=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 ze(e,this.widget));return new qe(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 Ke=class extends Lt{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new Xe(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var je=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 Ze(c,t){switch(c.widgetType){case"Table":return new Ke(c,t);case"XY Graph":return new je(c);default:return new Lt(c)}}var Je=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 Ze(e,this.scriptEngine)}};var Qe=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 ti=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 ei=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 Qt=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)}};var Yu=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],ii=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 Yu)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 ri=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 Is(c){let t=c.widget,e=c.widget.display,i=function(p){this.run=p.run},r=function(p){this.runnable=p};r.prototype.start=function(){c.schedule(()=>this.runnable.run())},r.sleep=function(p){let h=Date.now(),u=0;for(;Date.now()<h+p;)u++;u||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(p,h){c.schedule(p,h)};let o=function(p){this.valueChanged=h=>{c.schedule(()=>{let u=p.valueChanged;u(h)})}},l={ITableModifiedListener:function(p){this.modified=h=>{let u=p.modified;u(h)}},ITableSelectionChangedListener:function(p){this.selectionChanged=h=>{let u=p.selectionChanged;u(h)}}};return{display:new Je(t.display,c),widget:Ze(t,c),java:{lang:{Runnable:i,Thread:r},util:{Timer:s}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:l}}}},yamcs:{studio:{data:{IPVListener:o}}}},ColorFontUtil:new $e,ConsoleUtil:new Ue(e),DataUtil:new Ye,FileUtil:new Qe(e),GUIUtil:new ti(e),MessageDialog:new ei(e),PVUtil:new ii(e),ScriptUtil:new ri(e),SpreadSheetTable:l,Java:{type:function(p){switch(p){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: "+p)}},to:function(p,h){return p}}}}var At=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 St(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...Is(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 Bs="path",Ws="embedded",ks="scriptText",si=class extends j{constructor(){super(),this.properties.add(new R(Bs,"")),this.properties.add(new w(Ws,!1)),this.properties.add(new R(ks,""))}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(Bs)}get embedded(){return this.properties.getValue(Ws)}get scriptText(){return this.properties.getValue(ks)}toString(){return"Execute JavaScript"}};var Hs="macros",Ds="mode",Ns="path",oi=class extends j{constructor(){super(),this.properties.add(new R(Ns,"")),this.properties.add(new $t(Hs)),this.properties.add(new P(Ds,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(Hs)}get path(){return this.properties.getValue(Ns)}get mode(){return this.properties.getValue(Ds)}toString(){return`Open ${this.path}`}};var Fs="path",ni=class extends j{constructor(){super(),this.properties.add(new R(Fs,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Fs)}toString(){return`Open ${this.path}`}};var Gs="hyperlink",ai=class extends j{constructor(){super(),this.properties.add(new R(Gs,"http://"))}execute(t){this.hyperlink&&window.parent.postMessage({type:"openwebpage",url:this.hyperlink},"*")}get hyperlink(){return this.properties.getValue(Gs)}toString(){return`Open Webpage ${this.hyperlink}`}};var $s="path",li=class extends j{constructor(){super(),this.properties.add(new R($s,""))}execute(t){this.path&&new Audio(t.display.resolvePath(this.path)).play()}get path(){return this.properties.getValue($s)}toString(){return`Play WAV File ${this.path}`}};var Us="command",Ys="args",Xs="confirm_message",hi=class extends j{constructor(){super(),this.properties.add(new R(Us,"")),this.properties.add(new Ut(Ys,{})),this.properties.add(new R(Xs,""))}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(Us)}get args(){return this.properties.getValue(Ys)}get confirmMessage(){return this.properties.getValue(Xs)}toString(){return`Run ${this.command}`}};var zs="procedure",qs="args",Ks="confirm_message",ci=class extends j{constructor(){super(),this.properties.add(new R(zs,"")),this.properties.add(new Ut(qs,{})),this.properties.add(new R(Ks,""))}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(zs)}get args(){return this.properties.getValue(qs)}get confirmMessage(){return this.properties.getValue(Ks)}toString(){return`Run ${this.procedure}`}};var js="path",Zs="confirm_message",pi=class extends j{constructor(){super(),this.properties.add(new R(js,"")),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(js)}get confirmMessage(){return this.properties.getValue(Zs)}toString(){return`Run ${this.path}`}};var Js="pv_name",Qs="value",to="timeout",eo="confirm_message",di=class extends j{constructor(){super(),this.properties.add(new R(Js,"$(pv_name)")),this.properties.add(new R(Qs,"")),this.properties.add(new P(to,10)),this.properties.add(new R(eo,""))}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(Js)}get value(){return this.properties.getValue(Qs)}get timeout(){return this.properties.getValue(to)}get confirmMessage(){return this.properties.getValue(eo)}toString(){return`Write ${this.value} to ${this.pvName}`}};var ui=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 gi=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}autoScaleWidgets;minWidth;minHeight},mi=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}widthScalable;heightScalable;keepWidthHeightRatio};var fi=class{scripts=[]};var ee=class c{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 c(i.documentElement)}getNode(t){let e=this.findChild(t);return new c(e)}getNodes(t){let e=[];for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];r.nodeType!==3&&(!t||r.nodeName===t)&&e.push(new c(r))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++)if(this.node.childNodes[e].nodeName===t)return!0;return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return r.textContent}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseFloat(r.textContent)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseInt(r.textContent,10)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t)return r.textContent==="true"}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){let i=this.node.attributes.getNamedItem(t);if(i===null){if(e!==void 0)return e;throw new Error(`No attribute named ${t}`)}else return i.textContent==="true"}getColor(t,e){let i=this.findChild(t);for(let r=0;r<i.childNodes.length;r++){let s=i.childNodes[r];if(s.nodeName==="color")return this.parseColorNode(new c(s))}if(e!==void 0)return e;throw new Error("No child node named 'color' could be found")}getFont(t){let e=this.getNode(t);if(e.hasNode("opifont.name")){let i=e.getNode("opifont.name"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new K(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 K(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 fi;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 mi(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new gi(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 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 ui;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 oi;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new ni;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new Ge;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_JAVASCRIPT"){let o=new si;o.parseNode(r),i.add(o)}else if(s==="WRITE_PV"){let o=new di;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new li;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new ai;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new hi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new pi;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new ci;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 io="actions",ro="background_color",so="backcolor_alarm_sensitive",oo="border_alarm_sensitive",no="border_color",ao="border_width",lo="border_style",ho="enabled",co="foreground_color",po="forecolor_alarm_sensitive",Ir="height",uo="name",Br="pv_name",go="pv_value",mo="rules",fo="scale_options",xo="scripts",Wr="text",wo="tooltip",yo="transparent",bo="visible",Po="widget_type",kr="width",vo="wuid",Hr="x",Dr="y",V=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new jt(this,[new be(io,new Jt),new w(so,!1),new S(ro,m.TRANSPARENT),new w(oo,!1),new S(no),new P(lo),new P(ao),new w(ho,!0),new w(po,!1),new S(co),new P(Ir),new R(uo),new R(Br),new Pt(go,Br),new ve(mo,new te),new Pe(xo),new R(Wr,""),new R(wo,""),new w(yo,!1),new w(bo),new R(Po),new P(kr),new R(vo),new P(Hr),new P(Dr),new _e(fo)])}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 k){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:K.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,K.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:K.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(Hr),y:this.properties.getValue(Dr),width:this.properties.getValue(kr),height:this.properties.getValue(Ir)}}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,p=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new _(p,l).lineTo(p,n).moveTo(p,l).lineTo(a,l)}),t.strokePath({color:i,path:new _(p-o,l-o).lineTo(p-o,n+o).moveTo(p-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new _(a,n).lineTo(p-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new _(a+o,n+o).lineTo(p-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(vo)}get name(){return this.properties.getValue(uo)}get holderX(){return this.scale*this.properties.getValue(Hr)}get holderY(){return this.scale*this.properties.getValue(Dr)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(kr)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(Ir)}get borderAlarmSensitive(){return this.properties.getValue(oo)}get backgroundAlarmSensitive(){return this.properties.getValue(so)}get foregroundAlarmSensitive(){return this.properties.getValue(po)}get pvName(){return this.properties.getValue(Br,!0)}get pvValue(){return this.properties.getValue(go,!0)}get borderColor(){return this.properties.getValue(no)}get borderStyle(){return this.properties.getValue(lo)}get borderWidth(){return this.scale*this.properties.getValue(ao)}get backgroundColor(){return this.properties.getValue(ro)}get enabled(){return this.properties.getValue(ho)}get foregroundColor(){return this.properties.getValue(co)}get tooltip(){let t=this.properties.getProperty(wo);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(yo)}get visible(){return this.properties.getValue(bo)}get actions(){return this.properties.getValue(io)}get scripts(){return this.properties.getValue(xo)}get rules(){return this.properties.getValue(mo)}get scaleOptions(){return this.properties.getValue(fo)}get widgetType(){return this.properties.getValue(Po,!0)}get text(){return this.display.editMode?(this.properties.getProperty(Wr).rawValue||"").split(" ").join("\xA0"):this.properties.getValue(Wr).split(" ").join("\xA0")}init(){}hide(){}destroy(){}};var _o="macros",gt=class c extends V{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new $t(_o))}expandContainerMacros(t){for(let e in this.macros.macros)t=t.replace(`$(${e})`,this.macros.macros[e]),t=t.replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(let e of this.widgets){if(e.wuid===t)return e;if(e instanceof c){let i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(let e of this.widgets){if(e.name===t)return e;if(e instanceof c){let i=e.findWidgetByName(t);if(i)return i}}for(let e of this.connections)if(e.name===t)return e}hide(){for(let t of this.widgets)t.hide()}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(_o)}};var Ro="arrow_length",To="arrows",Co="fill_arrow",So="name",Lo="line_color",Ao="line_style",Eo="line_width",Oo="src_wuid",Vo="src_term",Mo="tgt_wuid",Io="tgt_term",Bo="router",Wo="points",Xu="wuid",Et="LEFT",Ot="UP",Vt="DOWN",Mt="RIGHT",xi=class extends V{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(Ro)),this.properties.add(new P(To)),this.properties.add(new w(Co)),this.properties.add(new R(So)),this.properties.add(new S(Lo)),this.properties.add(new P(Ao)),this.properties.add(new P(Eo)),this.properties.add(new R(Oo)),this.properties.add(new R(Vo)),this.properties.add(new R(Mo)),this.properties.add(new R(Io)),this.properties.add(new P(Bo)),this.properties.add(new vt(Wo)),this.properties.add(new R(Xu))}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:p,minDist:h}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===Et?i>0&&r*r<p&&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<p&&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<p&&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<p&&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=ke(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),p=yt(n.toPoint(),e.x,e.y);return[a,l,p]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(So)}get arrows(){return this.properties.getValue(To)}get fillArrow(){return this.properties.getValue(Co)}get arrowLength(){return this.scale*this.properties.getValue(Ro)}get lineColor(){return this.properties.getValue(Lo)}get lineStyle(){return this.properties.getValue(Ao)}get lineWidth(){return this.scale*this.properties.getValue(Eo)}get router(){return this.properties.getValue(Bo)}get sourceTerm(){return this.properties.getValue(Vo)}get sourceWuid(){return this.properties.getValue(Oo)}get targetTerm(){return this.properties.getValue(Io)}get targetWuid(){return this.properties.getValue(Mo)}get points(){return Nt(this.properties.getValue(Wo),this.scale)}};var zu=0,ko="auto_scale_widgets",ie=class extends gt{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new Re(ko))}async parseNode(t){await super.parseNode(t);let e=zu++;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 xi(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(ko)}};var qu=0,Ho="group_name",Do="opi_file",No="resize_behaviour",re=class extends gt{linkedDisplay;resolvedOpiFile;constructor(t,e){super(t,e),this.properties.add(new R(Ho)),this.properties.add(new R(Do)),this.properties.add(new P(No,0))}async parseNode(t){await super.parseNode(t);let e=qu++;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,p=a/r;l>this.height&&(l=this.height,a=l*n,p=l/r),this.linkedDisplay.relativeScale=p;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(Do)}get groupName(){return this.properties.getValue(Ho)}get resizeBehavior(){return this.properties.getValue(No)}};var wi=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 bi=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 Te=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," "),p=i[s.line-1],u=(s.line===a.line?a.column:p.length+1)-s.column||1;e+=`
1
+ "use strict";(()=>{function ye(c){let t=document.createElement("canvas").getContext("2d");t.fillStyle=c;let e=String(t.fillStyle),i=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return i?new m(parseInt(i[1],16),parseInt(i[2],16),parseInt(i[3],16)):m.BLACK}var m=class c{constructor(t,e,i,r=255){this.red=t;this.green=e;this.blue=i;this.alpha=r}red;green;blue;alpha;static TRANSPARENT=new c(0,0,0,0);static BLACK=new c(0,0,0);static BLUE=new c(0,0,255);static CYAN=new c(0,255,255);static DARK_GRAY=new c(150,150,150);static GRAY=new c(200,200,200);static GREEN=new c(0,255,0);static LIGHT_BLUE=new c(153,186,243);static ORANGE=new c(255,128,0);static PINK=new c(255,0,255);static PURPLE=new c(128,0,255);static RED=new c(255,0,0);static WHITE=new c(255,255,255);static YELLOW=new c(255,255,0);static BUTTON=new c(239,240,241);static BUTTON_DARKER=new c(164,168,172);static BUTTON_DARKEST=c.BLACK;static BUTTON_LIGHTEST=c.WHITE;withAlpha(t){return new c(this.red,this.green,this.blue,t)}mixWith(t,e){let i=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),s=Math.floor(this.blue*e+t.blue*(1-e));return new c(i,r,s)}brighter(){let{red:t,green:e,blue:i}=this,r=Math.floor(1/(1-.7));return t===0&&e===0&&i===0?new c(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),i>0&&i<r&&(i=r),new c(Math.min(Math.floor(this.red/.7),255),Math.min(Math.floor(this.green/.7),255),Math.min(Math.floor(this.blue/.7),255)))}darker(){return new c(Math.max(Math.floor(this.red*.7),0),Math.max(Math.floor(this.green*.7),0),Math.max(Math.floor(this.blue*.7),0))}contrast(){return new c(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=t.length==1?"0"+t:t;let e=this.green.toString(16);e=e.length==1?"0"+e:e;let i=this.blue.toString(16);i=i.length==1?"0"+i:i;let r=this.alpha.toString(16);return r=r.length==1?"0"+r:r,`#${t}${e}${i}${r}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}};var Ve=class{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}};var Me=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 Er=c=>(document.removeEventListener("click",Er,!0),c.preventDefault(),c.stopPropagation(),!1);function Ar(c){return(c.buttons&1)===1||c.buttons===void 0&&c.which==1}var Ts=5;function Nu(c,t,e,i){return Math.sqrt((e-c)*(e-c)+(i-t)*(i-t))}function Cs(c,t){return c&&t&&c.id===t.id}var Ie=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",Er,!0),Ar(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&&(Cs(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(Cs(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&&Ar(t)){let s=Nu(this.grabPoint.x,this.grabPoint.y,e.x,e.y);Math.abs(s)>Ts&&(this.initiateGrab(),Ts>0&&this.grabPoint&&(this.grabPoint=e))}this.grabbing&&this.grabTarget&&Ar(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",Er,!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 Be=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 Ss="rgb(255,255,255)",Fu=!!navigator.brave,We=class c{constructor(t,e,i){this.parent=t;let r=document.createElement("canvas");r.width=e??r.width,r.height=i??r.height,this.ctx=r.getContext("2d",{willReadFrequently:!0}),this.root=t?.root||t}parent;ctx;regionsByColor=new Map;root;clear(){this.regionsByColor.clear(),this.ctx.fillStyle=Ss,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){let e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){let i=this.ctx.getImageData(t,e,1,1).data,r=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(r)||void 0}createChild(t,e){return new c(this,t,e)}transferToParent(t,e,i,r){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,r)}generateUniqueColor(t){for(;;){let e=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=Math.round(Math.random()*255),s=`rgb(${e},${i},${r})`;if(!this.regionsByColor.has(s)&&s!==Ss)return Fu?(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(c,t,e,i,r){return D({x:c,y:t,width:e,height:i},r/2)}function Ct(c,t,e,i,r){let s=Math.sin(r),o=Math.cos(r),n=c-e,a=t-i;return{x:n*o-a*s+e,y:n*s+a*o+i}}function D(c,t,e){return e===void 0&&(e=t),{x:c.x+e,y:c.y+t,width:c.width-(e+e),height:c.height-(t+t)}}function Or(c){return{x:Math.round(c.x)+.5,y:Math.round(c.y)+.5,width:Math.round(c.width),height:Math.round(c.height)}}function Ls(c,t){let e=c.x,i=c.y,r=e+c.width,s=i+c.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 p=Math.max(e,o),h=Math.max(i,n);return{x:p,y:h,width:Math.min(r,a)-p,height:Math.min(s,l)-h}}function yt(c,t,e){return{x:c.x+t,y:c.y+e}}function Kt(c,t,e){return c.map(i=>yt(i,t,e))}function $(c){return c*Math.PI/180}function bt(c,t,e){let i=Math.floor(c*Math.cos(t)),r=Math.floor(-c*Math.sin(t));return{x:e.x+e.width/2+i,y:e.y+e.height/2+r}}function ke(c,t){let e=t.x-c.x,i=t.y-c.y,r=Math.sqrt(Math.pow(e,2)+Math.pow(i,2)),s=Math.acos(e/r);return i>0&&(s=2*Math.PI-s),new 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(c,t){return c.map(e=>({x:e.x*t,y:e.y*t}))}function He(c){return c.map(t=>({x:t.x+.5,y:t.y+.5}))}function De(c,t,e,i,r,s,o){c.beginPath(),!s&&!o?c.rect(t,e,i,r):(i<2*s&&(s=i/2),r<2*o&&(o=r/2),c.moveTo(t+s,e),c.lineTo(t+i-s,e),c.quadraticCurveTo(t+i,e,t+i,e+o),c.lineTo(t+i,e+r-o),c.quadraticCurveTo(t+i,e+r,t+i-s,e+r),c.lineTo(t+s,e+r),c.quadraticCurveTo(t,e+r,t,e+r-o),c.lineTo(t,e+o),c.quadraticCurveTo(t,e,t+s,e))}function Ft(c,t,e,i){return c===null?"":typeof c=="string"?i==="BINARY_STRING"?Gu(c):c:typeof c=="number"?e===-1?As(t,c,void 0,3):As(t,c,e,e):c instanceof Date?c.toISOString().replace("T"," ").replace("Z",""):String(c)}function Gu(c){let t="";for(let e=0;e<c.length;e++){let i=c.charCodeAt(e).toString(16);t+=i.length===2?i:"0"+i}return t&&`0x${t.toUpperCase()}`}function As(c,t,e,i){if(t==null||t==null)return"";switch(c){case 0:case 1:let r={minimumFractionDigits:e,maximumFractionDigits:i,useGrouping:!1,roundingMode:"halfEven"};return Intl.NumberFormat("en-US",r).format(t);case 2:return t.toExponential(i).replace("e+","E").toUpperCase();case 3:return"0x"+t.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${c}`),String(t)}}var Ne=class c{constructor(t,e){this.canvas=t;this.ctx=t.getContext("2d"),this.hitCanvas=e||new We,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 c(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,p=l/a;p>s&&(p=s,l=p*a),this.copyScaled(t,e,i,l,p)}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?(De(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?(De(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?(De(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 Vr(this.hitCanvas.ctx)}},_=class c{segments=[];constructor(t,e){this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){let e=t.findIndex(r=>r.y!==null);if(e===-1){let r=new c(0,0);return r.segments.length=0,r}let i=new c(t[e].x,t[e].y);for(let r=e+1;r<t.length;r++){let{x:s,y:o}=t[r];o!==null&&(r>0&&t[r-1].y===null?i.moveTo(s,o):i.lineTo(s,o))}return i}getBoundingBox(){let t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){let r=this.segments[i];r.x<t.x&&(t.x=r.x),r.x>e.x&&(e.x=r.x),r.y<t.y&&(t.y=r.y),r.y>e.y&&(e.y=r.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){if(this.segments.length){let t=this.segments[0];this.segments.push({x:t.x,y:t.y,line:!0})}return this}translate(t,e){for(let i of this.segments)i.x+=t,i.y+=e;return this}},Vr=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 Fe=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 be)e.value=t.getActions(e.name);else if(e instanceof Re)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 k)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 ve)e.value=t.getRules(e.name);else if(e instanceof _e)e.value=t.getScaleOptions(e.name);else if(e instanceof Pe)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 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}},J=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 J{rawValue;printScriptValue(t){return`"${t.replace('"','\\"')}"`}},Pt=class extends J{constructor(e,i){super(e);this.pvPropertyName=i}pvPropertyName},P=class extends J{},B=class extends J{},w=class extends J{},S=class extends J{printScriptValue(t){let{red:e,green:i,blue:r}={...t};return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${r})`}},k=class extends J{printScriptValue(t){let{name:e,height:i,style:r}={...t};return`ColorFontUtil.getFont("${e}", ${i}, ${r})`}},Gt=class extends J{printScriptValue(t){return`${t.code}`}},vt=class extends J{},be=class extends J{},$t=class extends J{},Pe=class extends J{},_t=class extends J{},Ut=class extends J{},Zt=class extends J{},ve=class extends J{},_e=class extends J{},Re=class extends J{};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 Es="description",j=class{properties;constructor(){this.properties=new jt(null,[new R(Es,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(Es)}};var Os="command",Vs="command_directory",Ms="wait_time",Ge=class extends j{constructor(){super(),this.properties.add(new R(Os,"")),this.properties.add(new R(Vs,"$(user.home)")),this.properties.add(new P(Ms,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(Os)}get commandDirectory(){return this.properties.getValue(Vs)}get waitTime(){return this.properties.getValue(Ms)}toString(){return`Execute Command ${this.command}`}};var Uu=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"],K=class c{constructor(t,e,i,r){this.name=t;this.style=i;r?this.height=e:c.LEGACY_FONT_SIZING?this.height=Math.round(e*16/15):this.height=Math.ceil(e*4/3)}name;style;static LEGACY_FONT_SIZING=!1;static ARIAL_9=new c("Arial",9,0,!1);static ARIAL_10=new c("Arial",10,0,!1);static ARIAL_11=new c("Arial",11,0,!1);static ARIAL_12_BOLD=new c("Arial",12,1,!1);height;scale(t){return new c(this.name,t*this.height,this.style,!0)}getFontString(){let t=this.name;return 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 Uu.indexOf(this.name)!==-1}};var $e=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 K(t,e,i,!1)}};var Ue=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 Ye=class{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}};var Xe=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]),p=Math.floor((o[2]-r[2])*n+r[2]);return[a,l,p]}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 ze=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 qe=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 ze(e,this.widget));return new qe(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 Ke=class extends Lt{table;spreadSheetTable;constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new Xe(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}};var je=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 Ze(c,t){switch(c.widgetType){case"Table":return new Ke(c,t);case"XY Graph":return new je(c);default:return new Lt(c)}}var Je=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 Ze(e,this.scriptEngine)}};var Qe=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 ti=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 ei=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 Qt=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)}};var Yu=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"],ii=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 Yu)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 ri=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 Is(c){let t=c.widget,e=c.widget.display,i=function(p){this.run=p.run},r=function(p){this.runnable=p};r.prototype.start=function(){c.schedule(()=>this.runnable.run())},r.sleep=function(p){let h=Date.now(),u=0;for(;Date.now()<h+p;)u++;u||console.trace("Should not happen")};let s=function(){};s.prototype.schedule=function(p,h){c.schedule(p,h)};let o=function(p){this.valueChanged=h=>{c.schedule(()=>{let u=p.valueChanged;u(h)})}},l={ITableModifiedListener:function(p){this.modified=h=>{let u=p.modified;u(h)}},ITableSelectionChangedListener:function(p){this.selectionChanged=h=>{let u=p.selectionChanged;u(h)}}};return{display:new Je(t.display,c),widget:Ze(t,c),java:{lang:{Runnable:i,Thread:r},util:{Timer:s}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:l}}}},yamcs:{studio:{data:{IPVListener:o}}}},ColorFontUtil:new $e,ConsoleUtil:new Ue(e),DataUtil:new Ye,FileUtil:new Qe(e),GUIUtil:new ti(e),MessageDialog:new ei(e),PVUtil:new ii(e),ScriptUtil:new ri(e),SpreadSheetTable:l,Java:{type:function(p){switch(p){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: "+p)}},to:function(p,h){return p}}}}var At=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 St(r)),triggerPV:null,...t.display.pvEngine.scriptLibraries,...Is(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 Bs="path",Ws="embedded",ks="scriptText",si=class extends j{constructor(){super(),this.properties.add(new R(Bs,"")),this.properties.add(new w(Ws,!1)),this.properties.add(new R(ks,""))}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(Bs)}get embedded(){return this.properties.getValue(Ws)}get scriptText(){return this.properties.getValue(ks)}toString(){return"Execute JavaScript"}};var Hs="macros",Ds="mode",Ns="path",oi=class extends j{constructor(){super(),this.properties.add(new R(Ns,"")),this.properties.add(new $t(Hs)),this.properties.add(new P(Ds,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(Hs)}get path(){return this.properties.getValue(Ns)}get mode(){return this.properties.getValue(Ds)}toString(){return`Open ${this.path}`}};var Fs="path",ni=class extends j{constructor(){super(),this.properties.add(new R(Fs,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Fs)}toString(){return`Open ${this.path}`}};var Gs="hyperlink",ai=class extends j{constructor(){super(),this.properties.add(new R(Gs,"http://"))}execute(t){this.hyperlink&&window.parent.postMessage({type:"openwebpage",url:this.hyperlink},"*")}get hyperlink(){return this.properties.getValue(Gs)}toString(){return`Open Webpage ${this.hyperlink}`}};var $s="path",li=class extends j{constructor(){super(),this.properties.add(new R($s,""))}execute(t){this.path&&new Audio(t.display.resolvePath(this.path)).play()}get path(){return this.properties.getValue($s)}toString(){return`Play WAV File ${this.path}`}};var Us="command",Ys="args",Xs="confirm_message",hi=class extends j{constructor(){super(),this.properties.add(new R(Us,"")),this.properties.add(new Ut(Ys,{})),this.properties.add(new R(Xs,""))}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(Us)}get args(){return this.properties.getValue(Ys)}get confirmMessage(){return this.properties.getValue(Xs)}toString(){return`Run ${this.command}`}};var zs="procedure",qs="args",Ks="confirm_message",ci=class extends j{constructor(){super(),this.properties.add(new R(zs,"")),this.properties.add(new Ut(qs,{})),this.properties.add(new R(Ks,""))}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(zs)}get args(){return this.properties.getValue(qs)}get confirmMessage(){return this.properties.getValue(Ks)}toString(){return`Run ${this.procedure}`}};var js="path",Zs="confirm_message",pi=class extends j{constructor(){super(),this.properties.add(new R(js,"")),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(js)}get confirmMessage(){return this.properties.getValue(Zs)}toString(){return`Run ${this.path}`}};var Js="pv_name",Qs="value",to="timeout",eo="confirm_message",di=class extends j{constructor(){super(),this.properties.add(new R(Js,"$(pv_name)")),this.properties.add(new R(Qs,"")),this.properties.add(new P(to,10)),this.properties.add(new R(eo,""))}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(Js)}get value(){return this.properties.getValue(Qs)}get timeout(){return this.properties.getValue(to)}get confirmMessage(){return this.properties.getValue(eo)}toString(){return`Write ${this.value} to ${this.pvName}`}};var ui=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 gi=class{constructor(t,e,i){this.autoScaleWidgets=t;this.minWidth=e;this.minHeight=i}autoScaleWidgets;minWidth;minHeight},mi=class{constructor(t,e,i){this.widthScalable=t;this.heightScalable=e;this.keepWidthHeightRatio=i}widthScalable;heightScalable;keepWidthHeightRatio};var fi=class{scripts=[]};var ee=class c{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 c(i.documentElement)}getNode(t){let e=this.findChild(t);return new c(e)}getNodes(t){let e=[];for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];r.nodeType!==3&&(!t||r.nodeName===t)&&e.push(new c(r))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++)if(this.node.childNodes[e].nodeName===t)return!0;return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return r.textContent}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseFloat(r.textContent)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t&&r.textContent!==null)return parseInt(r.textContent,10)}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){let e=this.node.attributes.getNamedItem(t);if(e===null)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let i=0;i<this.node.childNodes.length;i++){let r=this.node.childNodes[i];if(r.nodeName===t)return r.textContent==="true"}if(e!==void 0)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){let i=this.node.attributes.getNamedItem(t);if(i===null){if(e!==void 0)return e;throw new Error(`No attribute named ${t}`)}else return i.textContent==="true"}getColor(t,e){let i=this.findChild(t);for(let r=0;r<i.childNodes.length;r++){let s=i.childNodes[r];if(s.nodeName==="color")return this.parseColorNode(new c(s))}if(e!==void 0)return e;throw new Error("No child node named 'color' could be found")}getFont(t){let e=this.getNode(t);if(e.hasNode("opifont.name")){let i=e.getNode("opifont.name"),r=i.getStringAttribute("fontName"),s=i.getIntAttribute("height"),o=i.getIntAttribute("style"),n=!1;return i.hasAttribute("pixels")&&(n=i.getBooleanAttribute("pixels")),new K(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 K(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 fi;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 mi(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){let e=this.getNode(t);return new gi(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 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 ui;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 oi;o.parseNode(r),i.add(o)}else if(s==="OPEN_FILE"){let o=new ni;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_CMD"){let o=new Ge;o.parseNode(r),i.add(o)}else if(s==="EXECUTE_JAVASCRIPT"){let o=new si;o.parseNode(r),i.add(o)}else if(s==="WRITE_PV"){let o=new di;o.parseNode(r),i.add(o)}else if(s==="PLAY_SOUND"){let o=new li;o.parseNode(r),i.add(o)}else if(s==="OPEN_WEBPAGE"){let o=new ai;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND"){let o=new hi;o.parseNode(r),i.add(o)}else if(s==="RUN_COMMAND_STACK"){let o=new pi;o.parseNode(r),i.add(o)}else if(s==="RUN_PROCEDURE"){let o=new ci;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 io="actions",ro="background_color",so="backcolor_alarm_sensitive",oo="border_alarm_sensitive",no="border_color",ao="border_width",lo="border_style",ho="enabled",co="foreground_color",po="forecolor_alarm_sensitive",Ir="height",uo="name",Br="pv_name",go="pv_value",mo="rules",fo="scale_options",xo="scripts",Wr="text",wo="tooltip",yo="transparent",bo="visible",Po="widget_type",kr="width",vo="wuid",Hr="x",Dr="y",V=class{constructor(t,e){this.display=t;this.parent=e;this.properties=new jt(this,[new be(io,new Jt),new w(so,!1),new S(ro,m.TRANSPARENT),new w(oo,!1),new S(no),new P(lo),new P(ao),new w(ho,!0),new w(po,!1),new S(co),new P(Ir),new R(uo),new R(Br),new Pt(go,Br),new ve(mo,new te),new Pe(xo),new R(Wr,""),new R(wo,""),new w(yo,!1),new w(bo),new R(Po),new P(kr),new R(vo),new P(Hr),new P(Dr),new _e(fo)])}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 k){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:K.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,K.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:K.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(Hr),y:this.properties.getValue(Dr),width:this.properties.getValue(kr),height:this.properties.getValue(Ir)}}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,p=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new _(p,l).lineTo(p,n).moveTo(p,l).lineTo(a,l)}),t.strokePath({color:i,path:new _(p-o,l-o).lineTo(p-o,n+o).moveTo(p-o,l-o).lineTo(a+o,l-o)}),t.strokePath({color:r,path:new _(a,n).lineTo(p-o,n).moveTo(a,n).lineTo(a,l-o)}),t.strokePath({color:s,path:new _(a+o,n+o).lineTo(p-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(vo)}get name(){return this.properties.getValue(uo)}get holderX(){return this.scale*this.properties.getValue(Hr)}get holderY(){return this.scale*this.properties.getValue(Dr)}get holderWidth(){return this.customHolderWidth!==void 0?this.scale*this.customHolderWidth:this.scale*this.properties.getValue(kr)}get holderHeight(){return this.customHolderHeight!==void 0?this.scale*this.customHolderHeight:this.scale*this.properties.getValue(Ir)}get borderAlarmSensitive(){return this.properties.getValue(oo)}get backgroundAlarmSensitive(){return this.properties.getValue(so)}get foregroundAlarmSensitive(){return this.properties.getValue(po)}get pvName(){return this.properties.getValue(Br,!0)}get pvValue(){return this.properties.getValue(go,!0)}get borderColor(){return this.properties.getValue(no)}get borderStyle(){return this.properties.getValue(lo)}get borderWidth(){return this.scale*this.properties.getValue(ao)}get backgroundColor(){return this.properties.getValue(ro)}get enabled(){return this.properties.getValue(ho)}get foregroundColor(){return this.properties.getValue(co)}get tooltip(){let t=this.properties.getProperty(wo);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(yo)}get visible(){return this.properties.getValue(bo)}get actions(){return this.properties.getValue(io)}get scripts(){return this.properties.getValue(xo)}get rules(){return this.properties.getValue(mo)}get scaleOptions(){return this.properties.getValue(fo)}get widgetType(){return this.properties.getValue(Po,!0)}get text(){return this.display.editMode?(this.properties.getProperty(Wr).rawValue||"").split(" ").join("\xA0"):this.properties.getValue(Wr).split(" ").join("\xA0")}init(){}hide(){}destroy(){}};var _o="macros",gt=class c extends V{_widgets=[];_connections=[];relativeScale=1;constructor(t,e){super(t,e),this.properties.add(new $t(_o))}expandContainerMacros(t){for(let e in this.macros.macros)t=t.replace(`$(${e})`,this.macros.macros[e]),t=t.replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(let e of this.widgets){if(e.wuid===t)return e;if(e instanceof c){let i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(let e of this.widgets){if(e.name===t)return e;if(e instanceof c){let i=e.findWidgetByName(t);if(i)return i}}for(let e of this.connections)if(e.name===t)return e}hide(){for(let t of this.widgets)t.hide()}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(_o)}};var Ro="arrow_length",To="arrows",Co="fill_arrow",So="name",Lo="line_color",Ao="line_style",Eo="line_width",Oo="src_wuid",Vo="src_term",Mo="tgt_wuid",Io="tgt_term",Bo="router",Wo="points",Xu="wuid",Et="LEFT",Ot="UP",Vt="DOWN",Mt="RIGHT",xi=class extends V{sourceWidget;targetWidget;constructor(t){super(t),this.properties.clear(),this.properties.add(new P(Ro)),this.properties.add(new P(To)),this.properties.add(new w(Co)),this.properties.add(new R(So)),this.properties.add(new S(Lo)),this.properties.add(new P(Ao)),this.properties.add(new P(Eo)),this.properties.add(new R(Oo)),this.properties.add(new R(Vo)),this.properties.add(new R(Mo)),this.properties.add(new R(Io)),this.properties.add(new P(Bo)),this.properties.add(new vt(Wo)),this.properties.add(new R(Xu))}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:p,minDist:h}=this;if(i*i<l&&r*r<l)return[{x:e.x,y:e.y}];t.direction===Et?i>0&&r*r<p&&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<p&&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<p&&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<p&&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=ke(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),p=yt(n.toPoint(),e.x,e.y);return[a,l,p]}get minDist(){return this.scale*20}get tol(){return this.scale*.1}get tolxtol(){return this.scale*.01}get name(){return this.properties.getValue(So)}get arrows(){return this.properties.getValue(To)}get fillArrow(){return this.properties.getValue(Co)}get arrowLength(){return this.scale*this.properties.getValue(Ro)}get lineColor(){return this.properties.getValue(Lo)}get lineStyle(){return this.properties.getValue(Ao)}get lineWidth(){return this.scale*this.properties.getValue(Eo)}get router(){return this.properties.getValue(Bo)}get sourceTerm(){return this.properties.getValue(Vo)}get sourceWuid(){return this.properties.getValue(Oo)}get targetTerm(){return this.properties.getValue(Io)}get targetWuid(){return this.properties.getValue(Mo)}get points(){return Nt(this.properties.getValue(Wo),this.scale)}};var zu=0,ko="auto_scale_widgets",ie=class extends gt{displayArgs;constructor(t,e,i){super(t,e),this.displayArgs=i??{},this.properties.add(new Re(ko))}async parseNode(t){await super.parseNode(t);let e=zu++;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 xi(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(ko)}};var qu=0,Ho="group_name",Do="opi_file",No="resize_behaviour",re=class extends gt{linkedDisplay;resolvedOpiFile;constructor(t,e){super(t,e),this.properties.add(new R(Ho)),this.properties.add(new R(Do)),this.properties.add(new P(No,0))}async parseNode(t){await super.parseNode(t);let e=qu++;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.opiFile);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,p=a/r;l>this.height&&(l=this.height,a=l*n,p=l/r),this.linkedDisplay.relativeScale=p;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(Do)}get groupName(){return this.properties.getValue(Ho)}get resizeBehavior(){return this.properties.getValue(No)}};var wi=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 bi=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 Te=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," "),p=i[s.line-1],u=(s.line===a.line?a.column:p.length+1)-s.column||1;e+=`
2
2
  --> `+n+`
3
3
  `+l+` |
4
4
  `+o.line+" | "+p+`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yamcs/opi",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "OPI Display Renderer",
5
5
  "author": "Yamcs Team <yamcs@spaceapplications.com>",
6
6
  "repository": {
@@ -36,5 +36,9 @@
36
36
  "prettier": "^3.5.3",
37
37
  "tslib": "^2.6.3",
38
38
  "typescript": "^6.0.3"
39
+ },
40
+ "allowScripts": {
41
+ "esbuild": true,
42
+ "fsevents": true
39
43
  }
40
44
  }