@yamcs/opi 1.2.17 → 1.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/opi.js +1 -1
- package/dist/opi.js.map +1 -1
- package/dist/types/scripting/PVUtil.d.ts +1 -1
- package/package.json +1 -1
package/dist/opi.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}}class e{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){const s=prompt(e);return!!s&&s===i}}class i{constructor(t,e,i,s=255){this.red=t,this.green=e,this.blue=i,this.alpha=s}withAlpha(t){return new i(this.red,this.green,this.blue,t)}mixWith(t,e){const s=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),o=Math.floor(this.blue*e+t.blue*(1-e));return new i(s,r,o)}brighter(){let{red:t,green:e,blue:s}=this;const r=Math.floor(1/(1-.7));return 0===t&&0===e&&0===s?new i(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),s>0&&s<r&&(s=r),new i(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 i(Math.max(Math.floor(.7*this.red),0),Math.max(Math.floor(.7*this.green),0),Math.max(Math.floor(.7*this.blue),0))}contrast(){return new i(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=1==t.length?"0"+t:t;let e=this.green.toString(16);e=1==e.length?"0"+e:e;let i=this.blue.toString(16);i=1==i.length?"0"+i:i;let s=this.alpha.toString(16);return s=1==s.length?"0"+s:s,`#${t}${e}${i}${s}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}}i.TRANSPARENT=new i(0,0,0,0),i.BLACK=new i(0,0,0),i.BLUE=new i(0,0,255),i.CYAN=new i(0,255,255),i.DARK_GRAY=new i(150,150,150),i.GRAY=new i(200,200,200),i.GREEN=new i(0,255,0),i.LIGHT_BLUE=new i(153,186,243),i.ORANGE=new i(255,128,0),i.PINK=new i(255,0,255),i.PURPLE=new i(128,0,255),i.RED=new i(255,0,0),i.WHITE=new i(255,255,255),i.YELLOW=new i(255,255,0),i.BUTTON=new i(239,240,241),i.BUTTON_DARKER=new i(164,168,172),i.BUTTON_DARKEST=i.BLACK,i.BUTTON_LIGHTEST=i.WHITE;const s=t=>(document.removeEventListener("click",s,!0),t.preventDefault(),t.stopPropagation(),!1);function r(t){return!(1&~t.buttons)||void 0===t.buttons&&1==t.which}function o(t,e){return t&&e&&t.id===e.id}class n{constructor(t,e,i){this.display=t,this.canvas=e,this.hitCanvas=i,this.grabbing=!1,this.documentMouseMoveListener=t=>this.onDocumentMouseMove(t),this.documentMouseUpListener=t=>this.onDocumentMouseUp(t),e.addEventListener("click",(t=>this.onCanvasClick(t)),!1),e.addEventListener("mousedown",(t=>this.onCanvasMouseDown(t)),!1),e.addEventListener("mouseup",(t=>this.onCanvasMouseUp(t)),!1),e.addEventListener("mouseout",(t=>this.onCanvasMouseOut(t)),!1),e.addEventListener("mousemove",(t=>this.onCanvasMouseMove(t)),!1)}toPoint(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();const e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{const i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",s,!0),r(t))){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);return i&&i.mouseDown&&i.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),i&&i.grab&&(this.grabPoint=Object.assign({},e),this.grabTarget=i),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.mouseUp&&i.mouseUp()}onCanvasMouseOut(t){this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&this.prevEnteredRegion.mouseOut(),this.prevEnteredRegion=void 0,t.preventDefault(),t.stopPropagation()}onCanvasMouseMove(t){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(o(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(o(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i;const s=i&&i.cursor?i.cursor:"auto";if(s!=this.canvas.style.cursor&&(this.canvas.style.cursor=s),!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&r(t)){const t=(n=this.grabPoint.x,h=this.grabPoint.y,a=e.x,l=e.y,Math.sqrt((a-n)*(a-n)+(l-h)*(l-h)));Math.abs(t)>5&&(this.initiateGrab(),this.grabPoint&&(this.grabPoint=e))}var n,h,a,l;this.grabbing&&this.grabTarget&&r(t)&&this.grabTarget.grab({clientX:t.clientX,clientY:t.clientY,point:e,dx:e.x-this.grabPoint.x,dy:e.y-this.grabPoint.y})}initiateGrab(){document.addEventListener("click",s,!0),document.addEventListener("mouseup",this.documentMouseUpListener),document.addEventListener("mousemove",this.documentMouseMoveListener),this.grabbing=!0}onDocumentMouseUp(t){if(this.grabbing){document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener);const t=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,(null==t?void 0:t.grabEnd)&&t.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){const i=this.display.instance;if(i)for(const s of i.widgets.slice().reverse()){const i=s.holderX,r=s.holderY,o=s.holderX+s.holderWidth,n=s.holderY+s.holderHeight;if(i<t&&t<o&&r<e&&e<n)return this.display.selection=[s.wuid],!1}}}const h="rgb(255,255,255)",a=!!navigator.brave;class l{constructor(t,e,i){this.parent=t,this.regionsByColor=new Map;const s=document.createElement("canvas");s.width=null!=e?e:s.width,s.height=null!=i?i:s.height,this.ctx=s.getContext("2d",{willReadFrequently:!0}),this.root=(null==t?void 0:t.root)||t}clear(){this.regionsByColor.clear(),this.ctx.fillStyle=h,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){const e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){const i=this.ctx.getImageData(t,e,1,1).data,s=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(s)||void 0}createChild(t,e){return new l(this,t,e)}transferToParent(t,e,i,s){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,s)}generateUniqueColor(t){for(;;){const e=Math.round(255*Math.random()),i=Math.round(255*Math.random()),s=Math.round(255*Math.random()),r=`rgb(${e},${i},${s})`;if(!this.regionsByColor.has(r)&&r!==h)return a?(this.regionsByColor.set(`rgb(${e-1},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i},${s})`,t),this.regionsByColor.set(`rgb(${e},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s+1})`,t)):this.regionsByColor.set(r,t),r}}}function d(t,e,i,s,r){return p({x:t,y:e,width:i,height:s},r/2)}function c(t,e,i,s,r){const o=Math.sin(r),n=Math.cos(r),h=t-i,a=e-s;return{x:h*n-a*o+i,y:h*o+a*n+s}}function p(t,e,i){return void 0===i&&(i=e),{x:t.x+i,y:t.y+e,width:t.width-(i+i),height:t.height-(e+e)}}function u(t){return{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,width:Math.round(t.width),height:Math.round(t.height)}}function g(t,e,i){return{x:t.x+e,y:t.y+i}}function m(t,e,i){return t.map((t=>g(t,e,i)))}function f(t){return t*Math.PI/180}function x(t,e,i){const s=Math.floor(t*Math.cos(e)),r=Math.floor(-t*Math.sin(e));return{x:i.x+i.width/2+s,y:i.y+i.height/2+r}}function w(t,e){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));let o=Math.acos(i/r);return s>0&&(o=2*Math.PI-o),new y(Math.floor(r),o)}class y{constructor(t,e){this.r=t,this.theta=e}toPoint(){return{x:Math.floor(this.r*Math.cos(this.theta)),y:Math.floor(-this.r*Math.sin(this.theta))}}}function v(t,e){return t.map((t=>({x:t.x*e,y:t.y*e})))}function b(t,e,i,s,r,o,n){t.beginPath(),o||n?(s<2*o&&(o=s/2),r<2*n&&(n=r/2),t.moveTo(e+o,i),t.lineTo(e+s-o,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+r-n),t.quadraticCurveTo(e+s,i+r,e+s-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+o,i)):t.rect(e,i,s,r)}function T(t,e,i){return null===t?"":"string"==typeof t?t:"number"==typeof t?function(t,e,i){if(null==e||null==e)return"";switch(t){case 0:case 1:if(-1===i)return String(e);{const t=e.toFixed(i);return String(Number(t))}case 2:return-1===i?e.toExponential().replace("e+","E").toUpperCase():e.toExponential(i).replace("e+","E").toUpperCase();case 3:return"0x"+e.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${t}`),String(e)}}(e,t,i):t instanceof Date?t.toISOString().replace("T"," ").replace("Z",""):String(t)}class S{constructor(t,e){this.canvas=t,this.ctx=t.getContext("2d"),this.hitCanvas=e||new l,this.hitCtx=this.hitCanvas.ctx}createChild(t,e){const i=this.hitCanvas.createChild(t,e),s=document.createElement("canvas");return s.width=t,s.height=e,new S(s,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,s,r){const{width:o,height:n}=t.canvas,h=o/n;let a=s,l=a/h;l>r&&(l=r,a=l*h),this.copyScaled(t,e,i,a,l)}copyScaled(t,e,i,s,r){this.ctx.drawImage(t.canvas,e,i,s,r),t.hitCanvas.transferToParent(e,i,s,r)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){this.ctx.canvas.width==t&&this.ctx.canvas.height==e||(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(b(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.fill()):this.ctx.fillRect(t.x,t.y,t.width,t.height),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}fillText(t){this.ctx.textBaseline=t.baseline,this.ctx.textAlign=t.align,this.ctx.font=t.font.getFontString(),this.ctx.fillStyle=t.color.toString(),this.ctx.fillText(t.text,t.x,t.y)}fillEllipse(t){this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.strokeStyle="color"in t?t.color.toString():t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e){this.ctx.font=e.getFontString();return{width:this.ctx.measureText(t).width,height:e.height}}createLinearGradient(t,e,i,s){return this.ctx.createLinearGradient(t,e,i,s)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);const e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){const i=p(t,e/2,e/2);t.rx||t.ry?(b(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?(b(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(t.x,t.y,t.width,t.height);t.dash&&this.ctx.setLineDash([])}strokePath(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.lineWidth=t.lineWidth||1,this.ctx.strokeStyle=t.color.toString(),void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),void 0!==t.opacity&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new C(this.hitCanvas.ctx)}}class V{constructor(t,e){this.segments=[],this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){const e=t.findIndex((t=>null!==t.y));if(-1===e){const t=new V(0,0);return t.segments.length=0,t}const i=new V(t[e].x,t[e].y);for(let s=e+1;s<t.length;s++){const{x:e,y:r}=t[s];null!==r&&(s>0&&null===t[s-1].y?i.moveTo(e,r):i.lineTo(e,r))}return i}getBoundingBox(){const t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){const s=this.segments[i];s.x<t.x&&(t.x=s.x),s.x>e.x&&(e.x=s.x),s.y<t.y&&(t.y=s.y),s.y>e.y&&(e.y=s.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){const t=this.segments[0];return this.segments.push({x:t.x,y:t.y,line:!0}),this}translate(t,e){for(const i of this.segments)i.x+=t,i.y+=e;return this}}class C{constructor(t){this.ctx=t}addRect(t,e,i,s){return this.ctx.fillRect(t,e,i,s),this}addEllipse(t,e,i,s,r,o,n,h){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,s,r,o,n,h),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(const e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}}class _{constructor(t,e=[]){this.widget=t,this.properties=new Map,this.generators=[];for(const t of e)this.properties.set(t.name,t)}clear(){this.properties.clear()}add(t){this.properties.set(t.name,t)}addGenerator(t){this.generators.push(t)}all(){return this.properties.values()}loadProperty(t,e){if(t.hasNode(e.name))if(e instanceof H)e.value=t.getActions(e.name);else if(e instanceof z)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof R)e.value=t.getBoolean(e.name);else if(e instanceof W)e.value=t.getColorMap(e.name);else if(e instanceof E)e.value=t.getColor(e.name);else if(e instanceof M)e.value=t.getFloat(e.name);else if(e instanceof B)e.value=t.getFont(e.name);else if(e instanceof k)e.value=t.getInt(e.name);else if(e instanceof O)e.value=t.getMacros(e.name);else if(e instanceof I)e.value=t.getPoints(e.name);else if(e instanceof P);else if(e instanceof j)e.value=t.getRules(e.name);else if(e instanceof G)e.value=t.getScaleOptions(e.name);else if(e instanceof N)e.value=t.getScripts(e.name);else if(e instanceof L)e.rawValue=t.getString(e.name);else if(e instanceof D)e.value=t.getStringList(e.name);else if(e instanceof F)e.value=t.getStringMap(e.name);else{if(!(e instanceof $))throw new Error(`Property ${e.name} has an unexpected type`);e.value=t.getStringTable(e.name)}}loadXMLValues(t){this.properties.forEach((e=>{this.loadProperty(t,e)})),this.resolveStringProperties();for(const e of this.generators)for(const i of e())this.properties.set(i.name,i),this.loadProperty(t,i);this.resolveStringProperties()}resolveStringProperties(){for(let t=0;t<2;t++)this.properties.forEach((t=>{if(t instanceof L){const e=t;void 0!==e.rawValue&&this.widget?t.value=this.widget.expandMacro(e.rawValue):t.value=e.rawValue}}))}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){const i=this.properties.get(t);if(i&&void 0!==i.value)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){const i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}}class A{constructor(t,e){this.name=t,this.defaultValue=e,this.value=e}get value(){return this._value}set value(t){if(this.value!==t){const e=this._value;if(this._value=t,this.listeners)for(const i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){const e=this.listeners||[],i=e.indexOf(t);-1!==i&&e.splice(i,1)}printScriptValue(t){return String(t)}}class L extends A{printScriptValue(t){return`"${t.replace('"','\\"')}"`}}class P extends A{constructor(t,e){super(t),this.pvPropertyName=e}}class k extends A{}class M extends A{}class R extends A{}class E extends A{printScriptValue(t){const{red:e,green:i,blue:s}=Object.assign({},t);return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${s})`}}class B extends A{printScriptValue(t){const{name:e,height:i,style:s}=Object.assign({},t);return`ColorFontUtil.getFont("${e}", ${i}, ${s})`}}class W extends A{printScriptValue(t){return`${t.code}`}}class I extends A{}class H extends A{}class O extends A{}class N extends A{}class D extends A{}class F extends A{}class $ extends A{}class j extends A{}class G extends A{}class z extends A{}class U{constructor(){this.actions=[],this.hookFirstActionToClick=!1,this.hookAllActionsToClick=!1}add(t){this.actions.push(t)}isClickable(){return this.actions.length&&(this.hookFirstActionToClick||this.hookAllActionsToClick)}getAction(t){if(!(t>=this.actions.length))return this.actions[t]}toString(){return 1===this.actions.length?String(this.actions[0]):`${this.actions.length} actions`}}const q="description";class Y{constructor(){this.properties=new _(null,[new L(q,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(q)}}const X="command",K="command_directory",Z="wait_time";class J extends Y{constructor(){super(),this.properties.add(new L(X,"")),this.properties.add(new L(K,"$(user.home)")),this.properties.add(new k(Z,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(X)}get commandDirectory(){return this.properties.getValue(K)}get waitTime(){return this.properties.getValue(Z)}toString(){return`Execute Command ${this.command}`}}const Q=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"];class tt{constructor(t,e,i,s){this.name=t,this.style=i,this.height=s?e:Math.round(16*e/15)}scale(t){return new tt(this.name,t*this.height,this.style,!0)}getFontString(){return 1===this.style?`bold ${this.height}px ${this.name}`:2===this.style?`italic ${this.height}px ${this.name}`:3===this.style?`italic bold ${this.height}px ${this.name}`:(0!==this.style&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${this.name}`)}get bold(){return 1===this.style||3===this.style}get italic(){return 2===this.style||3===this.style}isWebSafe(){return-1!==Q.indexOf(this.name)}}tt.ARIAL_9=new tt("Arial",9,0,!1),tt.ARIAL_10=new tt("Arial",10,0,!1),tt.ARIAL_11=new tt("Arial",11,0,!1),tt.ARIAL_12_BOLD=new tt("Arial",12,1,!1);class et{constructor(){this.BLACK=i.BLACK,this.BLUE=i.BLUE,this.CYAN=i.CYAN,this.DARK_GRAY=i.DARK_GRAY,this.GRAY=i.GRAY,this.GREEN=i.GREEN,this.LIGHT_BLUE=i.LIGHT_BLUE,this.ORANGE=i.ORANGE,this.PINK=i.PINK,this.PURPLE=i.PURPLE,this.RED=i.RED,this.WHITE=i.WHITE,this.YELLOW=i.YELLOW}getColorFromRGB(t,e,s){return new i(t,e,s)}getFont(t,e,i){return new tt(t,e,i,!1)}}class it{constructor(t){this.display=t}writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}}class st{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}}class rt{constructor(t,e){this.spreadsheet=t,this.scriptEngine=e}addModifiedListener(t){}addSelectionChangedListener(t){this.spreadsheet.addSelectionChangedListener((()=>{this.scriptEngine.schedule((()=>{(0,t.selectionChanged)(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){}}class ot{constructor(t,e,i){this.code=t,this.interpolate=e,this.autoscale=i,this.values=[],this.colors=[],this.entries=[],this.dirty=!0,0===t||(1===t?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):2===t?(this.values=[0,.111,.365,.619,.873,1],this.colors=[[0,0,143],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[128,0,0]]):3===t?(this.values=[0,.126,.251,.375,.5,.625,.749,.874,1],this.colors=[[0,0,0],[255,0,255],[0,0,255],[0,255,255],[0,255,0],[255,255,0],[255,128,0],[255,0,0],[255,255,255]]):4===t?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):5===t?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):6===t&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}addMapping(t,e,i,s){this.values.push(t),this.colors.push([e,i,s]),this.dirty=!0}compile(){this.entries.length=0;for(let t=0;t<this.values.length;t++)this.entries.push([this.values[t],this.colors[t]]);this.entries.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0))}lookup(t){this.dirty&&(this.compile(),this.dirty=!1);let e=this.binarySearch(t);if(e>=0)return this.entries[e][1];if(e=-e-1,0===e)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){const[i,s]=this.entries[e-1],[r,o]=this.entries[e],n=(t-i)/(r-i);return[Math.floor((o[0]-s[0])*n+s[0]),Math.floor((o[1]-s[1])*n+s[1]),Math.floor((o[2]-s[2])*n+s[2])]}return this.entries[e-1][1]}getMinMax(){return[Math.min.apply(Math,this.values),Math.max.apply(Math,this.values)]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){const s=i+e>>1;if(t>this.entries[s][0])e=s+1;else{if(!(t<this.entries[s][0]))return s;i=s-1}}return-e-1}}class nt{constructor(t,e){this.action=t,this.widget=e}getPropertyValue(t){const e=this.action.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.action.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i instanceof L?(e=void 0!==e?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}}class ht{constructor(t){this.array=t}get(t){return this.array[t]}}class at{constructor(t){this._pv=t}getName(){return this._pv.name}getValue(){var t;return null!==(t=this._pv.value)&&void 0!==t?t:null}setValue(t){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)}))}}class lt{constructor(t){this.widget=t}executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){const e=this.widget.display.getPV(t);return e?new at(e):null}getPV(t="pv_name"){const e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getHookedActions(){const t=this.widget.getHookedActions().map((t=>new nt(t,this.widget)));return new ht(t)}getVar(t){var e;return null!==(e=this.widget.vars.get(t))&&void 0!==e?e:null}setVar(t,e){this.widget.vars.set(t,e)}getPropertyValue(t){const e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof L)e=void 0!==e?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof W){let i=0;switch(e){case"GrayScale":i=1;break;case"JET":i=2;break;case"ColorSpectrum":i=3;break;case"Hot":i=4;break;case"Cool":i=5;break;case"Shaded":i=6}const s=new ot(i,!0,!0);this.widget.properties.setValue(t,s)}else this.widget.properties.setValue(t,e);this.widget.requestRepaint()}getName(){return this.getPropertyValue("name")}setX(t){this.setPropertyValue("x",t)}setY(t){this.setPropertyValue("y",t)}setWidth(t){this.setPropertyValue("width",t)}setHeight(t){this.setPropertyValue("height",t)}setEnabled(t){this.setPropertyValue("enabled",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){var t;return null!==(t=this.widget.value)&&void 0!==t?t:null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}}class dt extends lt{constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new rt(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}}class ct extends lt{constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.x))}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.y))}}function pt(t,e){switch(t.widgetType){case"Table":return new dt(t,e);case"XY Graph":return new ct(t);default:return new lt(t)}}class ut{constructor(t,e){this.display=t,this.scriptEngine=e}isActive(){return!0}getWidget(t){const e=this.display.findWidgetByName(t);if(e)return pt(e,this.scriptEngine)}}class gt{constructor(t){this.display=t}readTextFile(t){const e=this.display.resolvePath(t);var i=new XMLHttpRequest;if(i.open("GET",e,!1),i.send(null),200===i.status)return i.responseText;throw Error(`Cannot open ${e}`)}}class mt{constructor(t){this.display=t}fullScreen(){document.documentElement.requestFullscreen()}openConfirmDialog(t){return this.display.getDialogHandler().openConfirmDialog("Confirm Dialog",t)}openInformationDialog(t){this.display.getDialogHandler().openInformationDialog("Information",t)}openWarningDialog(t){this.display.getDialogHandler().openWarningDialog("Warning",t)}openErrorDialog(t){this.display.getDialogHandler().openErrorDialog("Error",t)}openPasswordDialog(t,e){return this.display.getDialogHandler().openPasswordDialog("Password Input Dialog",t,e)}}class ft{constructor(t){this.display=t}openInformation(t,e,i){this.display.getDialogHandler().openInformationDialog(e,i)}openConfirm(t,e,i){return this.display.getDialogHandler().openConfirmDialog(e,i)}openError(t,e,i){this.display.getDialogHandler().openErrorDialog(e,i)}}class xt{constructor(t,e){this.name=t,this.pvEngine=e,this._writable=!1,this._severity=wt.NONE,this._precision=3,this._disconnected=!1,this.navigable=!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get lowerDisplayLimit(){return this._lowerDisplayLimit}set lowerDisplayLimit(t){this._lowerDisplayLimit=t,this.pvEngine.requestRepaint()}get lowerAlarmLimit(){return this._lowerAlarmLimit}set lowerAlarmLimit(t){this._lowerAlarmLimit=t,this.pvEngine.requestRepaint()}get lowerWarningLimit(){return this._lowerWarningLimit}set lowerWarningLimit(t){this._lowerWarningLimit=t,this.pvEngine.requestRepaint()}get upperWarningLimit(){return this._upperWarningLimit}set upperWarningLimit(t){this._upperWarningLimit=t,this.pvEngine.requestRepaint()}get upperAlarmLimit(){return this._upperAlarmLimit}set upperAlarmLimit(t){this._upperAlarmLimit=t,this.pvEngine.requestRepaint()}get upperDisplayLimit(){return this._upperDisplayLimit}set upperDisplayLimit(t){this._upperDisplayLimit=t,this.pvEngine.requestRepaint()}get precision(){return this._precision}set precision(t){this._precision=t,this.pvEngine.requestRepaint()}get writable(){return this._writable}set writable(t){this._writable=t,this.pvEngine.requestRepaint()}get disconnected(){return this._disconnected}set disconnected(t){this._disconnected=t,this.pvEngine.requestRepaint()}get time(){return this._time}get value(){return this._value}get indexValue(){return this._indexValue}get severity(){return this._severity}get alarmName(){var t,e,i,s;const r=this.toNumber();return null==r?"NONE":r<=(null!==(t=this.lowerAlarmLimit)&&void 0!==t?t:NaN)?"LOLO":r>=(null!==(e=this.upperAlarmLimit)&&void 0!==e?e:NaN)?"HIHI":r<=(null!==(i=this.lowerWarningLimit)&&void 0!==i?i:NaN)?"LOW":r>=(null!==(s=this.upperWarningLimit)&&void 0!==s?s:NaN)?"HIGH":"NONE"}toNumber(){return null===this.value?null:"number"==typeof this.value?this.value:"boolean"==typeof this.value?this.value?1:0:void 0!==typeof this.indexValue?this.indexValue:void 0}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this._units=t.units,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.addListener(this.name,t)}toString(){if(void 0!==this.value)return String(this.value)}}var wt;!function(t){t.NONE="NONE",t.MINOR="MINOR",t.MAJOR="MAJOR",t.INVALID="INVALID",t.UNDEFINED="UNDEFINED"}(wt||(wt={}));const yt=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"];class vt{constructor(t){this.pvEngine=t}checkPVValue(t){if(null===t.getValue())throw new Error(`PV ${t.getName()} has no value.`)}createPV(t,e){const i=this.pvEngine.createPV(t);return new at(i)}getDouble(t){this.checkPVValue(t);const e=t._pv.toNumber();return parseFloat(null!=e?e:t.getValue())}getLong(t){this.checkPVValue(t);let e=t._pv.toNumber();return"number"==typeof e&&(e=Math.floor(e)),parseInt(null!=e?e:t.getValue(),10)}getString(t){return this.checkPVValue(t),T(t._pv.value,0,-1)}getStringArray(t){this.checkPVValue(t);const e=t.getValue();return Array.isArray(e)?e.map((t=>String(t))):[String(e)]}getTimeInMilliseconds(t){var e;this.checkPVValue(t);const i=t._pv.time;return null!==(e=null==i?void 0:i.getTime())&&void 0!==e?e:0}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){this.checkPVValue(t);const i=t._pv.time;if(i){let t=e;for(const e of yt)t=t.replace(e,this.formatDate(i,e));return t}return null}getSeverity(t){switch(this.checkPVValue(t),t._pv.severity){case wt.NONE:return 0;case wt.MAJOR:return 1;case wt.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}formatDate(t,e){if("yyyy"===e)return String(t.getUTCFullYear());if("MM"===e){const e=t.getUTCMonth()+1;return e<10?"0"+e:""+e}if("dd"===e){const e=t.getUTCDate();return e<10?"0"+e:""+e}if("HH"===e){const e=t.getUTCHours();return e<10?"0"+e:""+e}if("mm"===e){const e=t.getUTCMinutes();return e<10?"0"+e:""+e}if("ss"===e){const e=t.getUTCSeconds();return e<10?"0"+e:""+e}if("nnnnnnnnn"===e){const e=t.getUTCMilliseconds();return e<10?"00"+e:e<100?"0"+e:""+e}throw new Error(`Unexpected format '${e}'`)}}class bt{constructor(t){this.display=t}openOPI(t,e,i,s){if(0!==i)throw new Error(`Unsupported target ${i}`);{const t={path:e,replace:0===i};this.display.fireEvent("opendisplay",t)}}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}}let Tt,St,Vt;class Ct{constructor(t,e,i=[]){this.widget=t,this.scriptText=e,Tt||(Tt=document.createElement("iframe"),Tt.id="script-e",Tt.style.display="none",document.body.appendChild(Tt),St=Tt.contentWindow,Vt=St.eval,!Vt&&St.execScript&&(St.execScript.call(St,"null"),Vt=St.eval)),this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context=Object.assign(Object.assign({pvs:i.map((t=>new at(t))),triggerPV:null},t.display.pvEngine.scriptLibraries),function(t){const e=t.widget,i=t.widget.display,s=function(t){this.run=t.run},r=function(t){this.runnable=t};r.prototype.start=function(){t.schedule((()=>this.runnable.run()))},r.sleep=function(t){const e=Date.now();let i=0;for(;Date.now()<e+t;)i++;i||console.trace("Should not happen")};const o=function(){};o.prototype.schedule=function(e,i){t.schedule(e,i)};const n=function(e){this.valueChanged=i=>{t.schedule((()=>{(0,e.valueChanged)(i)}))}},h={ITableModifiedListener:function(t){this.modified=e=>{(0,t.modified)(e)}},ITableSelectionChangedListener:function(t){this.selectionChanged=e=>{(0,t.selectionChanged)(e)}}};return{display:new ut(e.display,t),widget:pt(e,t),java:{lang:{Runnable:s,Thread:r},util:{Timer:o}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:h}}}},yamcs:{studio:{data:{IPVListener:n}}}},ColorFontUtil:new et,ConsoleUtil:new it(i),DataUtil:new st,FileUtil:new gt(i),GUIUtil:new mt(i),MessageDialog:new ft(i),PVUtil:new vt(i.pvEngine),ScriptUtil:new bt(i),SpreadSheetTable:h,Java:{type:function(t){switch(t){case"java.lang.Runnable":return s;case"java.lang.Thread":return r;case"java.util.Timer":return o;case"org.csstudio.swt.widgets.natives.SpreadSheetTable":return h;case"org.yamcs.studio.data.IPVListener":return n;default:throw new Error("Unexpected class name: "+t)}},to:function(t,e){return t}}}}(this))}run(t){window.setTimeout((()=>{if(this.context.triggerPV=null,t)for(const e of this.context.pvs)e._pv===t&&(this.context.triggerPV=e);this.runWithContext((()=>{Vt.call(St,this.scriptText)}))}))}schedule(t,e){window.setTimeout((()=>this.runWithContext(t)),e)}runWithContext(t){const e=[];for(const t in Tt.contentWindow)e.push(t);try{for(const t in this.context)this.context.hasOwnProperty(t)&&(St[t]=this.context[t]);t();const i={};for(const t in St)-1===e.indexOf(t)&&(i[t]=St[t]);this.context=i}finally{for(const t in St)-1===e.indexOf(t)&&delete St[t]}}}const _t="path",At="embedded",Lt="scriptText";class Pt extends Y{constructor(){super(),this.properties.add(new L(_t,"")),this.properties.add(new R(At,!1)),this.properties.add(new L(Lt,""))}execute(t){if(this.embedded){new Ct(t,this.scriptText).run()}else fetch(t.display.resolvePath(this.path),{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{new Ct(t.display.instance,e).run()}))}))}get path(){return this.properties.getValue(_t)}get embedded(){return this.properties.getValue(At)}get scriptText(){return this.properties.getValue(Lt)}toString(){return"Execute JavaScript"}}const kt="macros",Mt="mode",Rt="path";class Et extends Y{constructor(){super(),this.properties.add(new L(Rt,"")),this.properties.add(new O(kt)),this.properties.add(new k(Mt,0))}execute(t){const e=Object.assign({},this.macros.macros),i={path:this.path,replace:0===this.mode,args:e};t.display.fireEvent("opendisplay",i)}get macros(){return this.properties.getValue(kt)}get path(){return this.properties.getValue(Rt)}get mode(){return this.properties.getValue(Mt)}toString(){return`Open ${this.path}`}}const Bt="path";class Wt extends Y{constructor(){super(),this.properties.add(new L(Bt,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Bt)}toString(){return`Open ${this.path}`}}const It="hyperlink";class Ht extends Y{constructor(){super(),this.properties.add(new L(It,"http://"))}execute(t){this.hyperlink&&(window.location.href=this.hyperlink)}get hyperlink(){return this.properties.getValue(It)}toString(){return`Open Webpage ${this.hyperlink}`}}const Ot="path";class Nt extends Y{constructor(){super(),this.properties.add(new L(Ot,""))}execute(t){if(this.path){new Audio(t.display.resolvePath(this.path)).play()}}get path(){return this.properties.getValue(Ot)}toString(){return`Play WAV File ${this.path}`}}const Dt="command",Ft="args",$t="confirm_message";class jt extends Y{constructor(){super(),this.properties.add(new L(Dt,"")),this.properties.add(new F(Ft,{})),this.properties.add(new L($t,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}const e=t.expandMacro(this.command),i={};for(const e in this.args)i[e]=t.expandMacro(this.args[e]);const s={command:e,args:i};t.display.fireEvent("runcommand",s)}get command(){return this.properties.getValue(Dt)}get args(){return this.properties.getValue(Ft)}get confirmMessage(){return this.properties.getValue($t)}toString(){return`Run ${this.command}`}}const Gt="procedure",zt="args",Ut="confirm_message";class qt extends Y{constructor(){super(),this.properties.add(new L(Gt,"")),this.properties.add(new F(zt,{})),this.properties.add(new L(Ut,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}const e={procedure:this.procedure,args:this.args};t.display.fireEvent("runprocedure",e)}get procedure(){return this.properties.getValue(Gt)}get args(){return this.properties.getValue(zt)}get confirmMessage(){return this.properties.getValue(Ut)}toString(){return`Run ${this.procedure}`}}const Yt="pv_name",Xt="value",Kt="timeout",Zt="confirm_message";class Jt extends Y{constructor(){super(),this.properties.add(new L(Yt,"$(pv_name)")),this.properties.add(new L(Xt,"")),this.properties.add(new k(Kt,10)),this.properties.add(new L(Zt,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}if(this.pvName){const 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(Yt)}get value(){return this.properties.getValue(Xt)}get timeout(){return this.properties.getValue(Kt)}get confirmMessage(){return this.properties.getValue(Zt)}toString(){return`Write ${this.value} to ${this.pvName}`}}class Qt{constructor(){this.includeParentMacros=!0,this.macros={}}clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}}class te{constructor(){this.rules=[]}}class ee{constructor(t,e,i){this.autoScaleWidgets=t,this.minWidth=e,this.minHeight=i}}class ie{constructor(t,e,i){this.widthScalable=t,this.heightScalable=e,this.keepWidthHeightRatio=i}}class se{constructor(){this.scripts=[]}}class re{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){const e=(new DOMParser).parseFromString(t,"text/xml");return new re(e.documentElement)}getNode(t){const e=this.findChild(t);return new re(e)}getNodes(t){const e=[];for(let i=0;i<this.node.childNodes.length;i++){const s=this.node.childNodes[i];3!==s.nodeType&&(t&&s.nodeName!==t||e.push(new re(s)))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++){if(this.node.childNodes[e].nodeName===t)return!0}return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseFloat(i.textContent)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseInt(i.textContent,10)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return"true"===i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){const i=this.node.attributes.getNamedItem(t);if(null===i){if(void 0!==e)return e;throw new Error(`No attribute named ${t}`)}return"true"===i.textContent}getColor(t,e){const i=this.findChild(t);for(let t=0;t<i.childNodes.length;t++){const e=i.childNodes[t];if("color"===e.nodeName)return this.parseColorNode(new re(e))}if(void 0!==e)return e;throw new Error("No child node named 'color' could be found")}getFont(t){const e=this.getNode(t);if(e.hasNode("opifont.name")){const t=e.getNode("opifont.name"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");let o=!1;return t.hasAttribute("pixels")&&(o=t.getBooleanAttribute("pixels")),new tt(i,s,r,o)}{const t=e.getNode("fontdata"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");return new tt(i,s,r,!1)}}getPoints(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("point"))i.push({x:t.getIntAttribute("x"),y:t.getIntAttribute("y")});return i}getStringList(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("s"))i.push(t.getTextContent());return i}getStringMap(t){const e=this.getNode(t),i={};for(const t of e.getNodes())i[t.name]=e.getString(t.name);return i}getStringTable(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("row")){const e=[];for(const i of t.getNodes("col"))e.push(i.getTextContent());i.push(e)}return i}getScripts(t){const e=this.getNode(t),i=new se;for(const t of e.getNodes("path")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=t.getStringAttribute("pathString");"EmbeddedJs"===s?i.scripts.push({embedded:!0,text:t.getString("scriptText"),checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e}):"EmbeddedPy"===s?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:s,checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e})}return i}getScaleOptions(t){const e=this.getNode(t);return new ie(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){const e=this.getNode(t);return new ee(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){const e=this.getNode(t);if(!e.hasNode("e"))return new ot(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"));{const t=new ot(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(const i of e.getNodes("e")){const e=Number(i.getTextContent()),s=i.getIntAttribute("red"),r=i.getIntAttribute("green"),o=i.getIntAttribute("blue");t.addMapping(e,s,r,o)}}}getRules(t){const e=this.getNode(t),i=new te;for(const t of e.getNodes("rule")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=[];for(const e of t.getNodes("exp")){e.getNode("value").hasNode("color")?s.push({type:"color",expression:e.getStringAttribute("bool_exp"),outputValue:e.getColor("value")}):s.push({type:"string",expression:e.getStringAttribute("bool_exp"),outputValue:e.getString("value")})}i.rules.push({name:t.getStringAttribute("name"),propertyName:t.getStringAttribute("prop_id"),outputExpression:t.getBooleanAttribute("out_exp"),inputs:e,expressions:s})}return i}getMacros(t){const e=this.getNode(t),i=new Qt;i.includeParentMacros=e.getBoolean("include_parent_macros");for(const t of e.getNodes())"include_parent_macros"!==t.name&&i.set(t.name,e.getString(t.name));return i}getActions(t){const e=this.getNode(t),i=new U;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(const t of e.getNodes("action")){const e=t.getStringAttribute("type");if("OPEN_DISPLAY"===e){const e=new Et;e.parseNode(t),i.add(e)}else if("OPEN_FILE"===e){const e=new Wt;e.parseNode(t),i.add(e)}else if("EXECUTE_CMD"===e){const e=new J;e.parseNode(t),i.add(e)}else if("EXECUTE_JAVASCRIPT"===e){const e=new Pt;e.parseNode(t),i.add(e)}else if("WRITE_PV"===e){const e=new Jt;e.parseNode(t),i.add(e)}else if("PLAY_SOUND"===e){const e=new Nt;e.parseNode(t),i.add(e)}else if("OPEN_WEBPAGE"===e){const e=new Ht;e.parseNode(t),i.add(e)}else if("RUN_COMMAND"===e){const e=new jt;e.parseNode(t),i.add(e)}else if("RUN_PROCEDURE"===e){const e=new qt;e.parseNode(t),i.add(e)}else console.warn(`Unsupported action type ${e}`),i.add(null)}return i}parseColorNode(t){const e=t.getIntAttribute("red"),s=t.getIntAttribute("green"),r=t.getIntAttribute("blue");return new i(e,s,r)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}}const oe="actions",ne="background_color",he="backcolor_alarm_sensitive",ae="border_alarm_sensitive",le="border_color",de="border_width",ce="border_style",pe="enabled",ue="foreground_color",ge="forecolor_alarm_sensitive",me="height",fe="name",xe="pv_name",we="pv_value",ye="rules",ve="scale_options",be="scripts",Te="text",Se="tooltip",Ve="transparent",Ce="visible",_e="widget_type",Ae="width",Le="wuid";class Pe{constructor(t,e){this.display=t,this.parent=e,this.x=0,this.y=0,this.width=0,this.height=0,this.fillRoundRectangleBackgroundBorder=!0,this.vars=new Map,this.pvs=[],this.properties=new _(this,[new H(oe,new U),new R(he,!1),new E(ne,i.TRANSPARENT),new R(ae,!1),new E(le),new k(ce),new k(de),new R(pe,!0),new R(ge,!1),new E(ue),new k(me),new L(fe),new L(xe),new P(we,xe),new j(ye,new te),new N(be),new L(Te,""),new L(Se,""),new R(Ve,!1),new R(Ce),new L(_e),new k(Ae),new L(Le),new k("x"),new k("y"),new G(ve)])}parseNode(t){this.properties.loadXMLValues(t);for(const t of this.properties.all())if(t instanceof B){const e=t.value;this.loadFont(e)}if(this.pvName){const t=this.display.pvEngine.createPV(this.pvName);this.pvs.push(t)}for(const t of this.scripts.scripts)if(t.embedded){const e=this.display.pvEngine.createScript(this,t,t.text);this.pvs.push(...e.pvs)}else fetch(this.display.resolvePath(t.path),{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{const i=this.display.pvEngine.createScript(this,t,e);this.pvs.push(...i.pvs)}))}));for(const t of this.rules.rules)this.properties.getProperty(t.propertyName)?this.display.pvEngine.createRule(this,t):console.warn(`Cannot create rule for unsupported property ${t.propertyName}`);this.actions.isClickable()&&(this.holderRegion={id:`${this.wuid}-holder`},this.tooltip&&(this.holderRegion.tooltip=()=>this.tooltip),this.actions.isClickable()&&(this.holderRegion.click=()=>{for(const t of this.getHookedActions())this.executeAction(t)},this.holderRegion.cursor="pointer")),this.init()}getHookedActions(){const{actions:t}=this,e=[];for(let i=0;i<t.actions.length;i++)0===i?(t.hookFirstActionToClick||t.hookAllActionsToClick)&&e.push(t.actions[i]):t.hookAllActionsToClick&&e.push(t.actions[i]);return e}drawHolder(t){var e,i;const{scale:s}=this;let r=[0,0,0,0];const o=this.borderAlarmSensitive&&((null===(e=this.pv)||void 0===e?void 0:e.severity)===wt.MINOR||(null===(i=this.pv)||void 0===i?void 0:i.severity)===wt.MAJOR);if(!o)switch(this.borderStyle){case 0:break;case 1:case 8:case 9:case 10:case 11:r=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:r=[1*s,1*s,1*s,1*s];break;case 4:case 5:case 6:r=[2*s,2*s,2*s,2*s];break;case 7:r=[2*s,2*s,1*s,1*s];break;case 12:r=[17*s,1*s,1*s,1*s];break;case 13:r=[16*s,16*s,16*s,16*s];break;case 14:const t=2*this.borderWidth;r=[t,t,t,t]}this.x=this.holderX+r[1],this.y=this.holderY+r[0],this.width=this.holderWidth-r[1]-r[3],this.height=this.holderHeight-r[0]-r[2],o||(this.beforeDrawBorder(t),this.drawBorderStyle(t)),this.holderRegion&&t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}beforeDrawBorder(t){}drawBorderStyle(t){const{scale:e}=this;if(0===this.borderStyle);else if(1===this.borderStyle)t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(2===this.borderStyle){const s=1*e,r=this.holderY+s/2,o=this.holderX+s/2,n=this.holderY+this.holderHeight-s+s/2,h=this.holderX+this.holderWidth-s+s/2;t.strokePath({color:i.BLACK,path:new V(h,n).lineTo(h,r).moveTo(h,n).lineTo(o,n)}),t.strokePath({color:i.WHITE,path:new V(o,r).lineTo(h-s,r).moveTo(o,r).lineTo(o,n-s)})}else if(3===this.borderStyle){const s=1*e,r=this.holderY+s/2,o=this.holderX+s/2,n=this.holderY+this.holderHeight-s+s/2,h=this.holderX+this.holderWidth-s+s/2;t.strokePath({color:i.WHITE,path:new V(h,n).lineTo(h,r).moveTo(h,n).lineTo(o,n)}),t.strokePath({color:i.BLACK,path:new V(o,r).lineTo(h-s,r).moveTo(o,r).lineTo(o,n-s)})}else if(4===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_LIGHTEST,i.BUTTON_DARKER,i.BUTTON_DARKER,i.BUTTON_LIGHTEST);else if(5===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_DARKER,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKER);else if(6===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_DARKEST,i.BUTTON_DARKER,i.BUTTON,i.BUTTON_LIGHTEST);else if(7===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKEST,i.BUTTON_DARKER);else if(8===this.borderStyle)this.drawDashedBorder(t,[2*e,2*e]);else if(9===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e]);else if(10===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e]);else if(11===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e,2*e,2*e]);else if(12===this.borderStyle)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+8*e,baseline:"middle",align:"left",font:tt.ARIAL_11.scale(e),color:i.BLACK,text:this.name}),t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:i.BLACK,crispen:!0});else if(13===this.borderStyle){const i=t.measureText(this.name,tt.ARIAL_11.scale(e)),s=1;let r=d(this.holderX+8*e,this.holderY+8*e,this.holderWidth-16*e-s,this.holderHeight-16*e-s,s);this.transparent||(t.fillRect(Object.assign(Object.assign({},p(r,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:tt.ARIAL_11.scale(e),color:this.borderColor,text:this.name}),t.strokePath({color:this.backgroundColor.darker(),path:new V(r.x,r.y).lineTo(r.x+8*e,r.y).moveTo(r.x+8*e+i.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)}),r=d(this.holderX+8*e+s,this.holderY+8*e+s,this.holderWidth-16*e-s,this.holderHeight-16*e-s,s),t.strokePath({color:this.backgroundColor.brighter(),path:new V(r.x,r.y).lineTo(r.x+8*e-s,r.y).moveTo(r.x+8*e-s+i.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)})}else if(14===this.borderStyle){const i=d(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&t.fillRect(Object.assign(Object.assign({},i),{rx:4*e,ry:4*e,color:this.backgroundColor})),this.borderWidth&&t.strokeRect(Object.assign(Object.assign({},i),{rx:4*e,ry:4*e,color:this.borderColor,lineWidth:this.borderWidth}))}else 15===this.borderStyle||console.warn(`Unsupported border style: ${this.borderStyle}`)}isDisconnected(){for(const t of this.pvs)if(void 0===t.value)return!0;return!1}drawDecoration(t){var e,s,r;if(this.display.editMode)return;const{scale:o}=this;if(!this.pvName||this.pv&&!this.pv.disconnected)this.pvs.length&&this.isDisconnected()&&t.strokeRect(Object.assign(Object.assign({},this.bounds),{dash:[2*o,2*o],lineWidth:2*o,color:i.PINK,crispen:!0}));else{const e=1*o;t.fillRect({x:this.holderX-e/2,y:this.holderY-e/2,width:this.holderWidth+e,height:this.holderHeight+e,color:i.PURPLE,opacity:.4}),t.strokeRect({x:this.holderX-e/2,y:this.holderY-e/2,width:this.holderWidth+e,height:this.holderHeight+e,color:i.PURPLE})}if(this.borderAlarmSensitive){let n;8===this.borderStyle?n=[2*o,2*o]:9===this.borderStyle?n=[6*o,2*o]:10===this.borderStyle?n=[6*o,2*o,2*o,2*o]:11===this.borderStyle&&(n=[6*o,2*o,2*o,2*o,2*o,2*o]),(null===(e=this.pv)||void 0===e?void 0:e.severity)===wt.MAJOR?t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.RED,crispen:!0,dash:n})):(null===(s=this.pv)||void 0===s?void 0:s.severity)===wt.MINOR?t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.ORANGE,crispen:!0,dash:n})):(null===(r=this.pv)||void 0===r?void 0:r.severity)===wt.INVALID&&t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.PINK,crispen:!0}))}}drawOverlay(t){}drawSelection(t){t.lineWidth=1,t.strokeStyle="black",t.strokeRect(this.holderX-.5,this.holderY-.5,this.holderWidth+1,this.holderHeight+1),t.fillStyle="black";let e=2;t.fillRect(this.holderX-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight-e,e+e,e+e),t.strokeStyle="white",e=3,t.strokeRect(this.holderX-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1)}requestRepaint(){this.display.requestRepaint()}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("x"),y:this.properties.getValue("y"),width:this.properties.getValue(Ae),height:this.properties.getValue(me)}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,s,r){const o=1*this.scale,n=this.holderY+o/2,h=this.holderX+o/2,a=this.holderY+this.holderHeight-o+o/2,l=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new V(l,a).lineTo(l,n).moveTo(l,a).lineTo(h,a)}),t.strokePath({color:i,path:new V(l-o,a-o).lineTo(l-o,n+o).moveTo(l-o,a-o).lineTo(h+o,a-o)}),t.strokePath({color:s,path:new V(h,n).lineTo(l-o,n).moveTo(h,n).lineTo(h,a-o)}),t.strokePath({color:r,path:new V(h+o,n+o).lineTo(l-o-o,n+o).moveTo(h+o,n+o).lineTo(h+o,a-o-o)})}drawDashedBorder(t,e){const i=d(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new V(i.x,i.y).lineTo(i.x+i.width,i.y).lineTo(i.x+i.width,i.y+i.height).lineTo(i.x,i.y+i.height).closePath()})}executeActionByIndex(t){const e=this.actions.getAction(t);e&&this.executeAction(e)}executeAction(t){t.execute(this)}expandMacro(t){var e;if(-1===t.indexOf("$"))return t;for(const i of this.properties.all())if(i instanceof P){const s=this.properties.getProperty(i.pvPropertyName);let r="";const o=null==s?void 0:s.value;if(o){const t=this.display.getPV(o);r=null!==(e=null==t?void 0:t.value)&&void 0!==e?e:""}t=(t=t.replace(`$(${i.name})`,r)).replace(`\${${i.name}}`,r)}else t=(t=t.replace(`$(${i.name})`,i.value||"")).replace(`\${${i.name}}`,i.value||"");return this.parent?this.parent.expandContainerMacros(t):t}loadFont(t){if(t.isWebSafe())return;const e=this.display.getFontResolver();if(!e)return void console.warn(`Failed to load font '${t.getFontString()}'.`);const i=e.resolve(t);i?i.load().then((t=>{document.fonts.add(t),this.requestRepaint()})).catch((e=>{console.warn(`Failed to load font '${t.getFontString()}'.`,e)})):console.warn(`Failed to load font '${t.getFontString()}'.`)}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MINOR}isMajorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MAJOR}get alarm(){var t,e;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===wt.MINOR||(null===(e=this.pv)||void 0===e?void 0:e.severity)===wt.MAJOR}get alarmSensitiveBackgroundColor(){if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.foregroundColor}get scale(){let t=this.display.scale,e=this.parent;for(;e;)t*=e.relativeScale,e=e.parent;return t}get value(){return this._value}set value(t){this._value=t,this.requestRepaint()}addPropertyListener(t,e){this.properties.getProperty(t).addListener(e)}removePropertyListener(t,e){this.properties.getProperty(t).removeListener(e)}toDataURL(t="image/png",e){const i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue(Le)}get name(){return this.properties.getValue(fe)}get holderX(){return this.scale*this.properties.getValue("x")}get holderY(){return this.scale*this.properties.getValue("y")}get holderWidth(){return this.scale*this.properties.getValue(Ae)}get holderHeight(){return this.scale*this.properties.getValue(me)}get borderAlarmSensitive(){return this.properties.getValue(ae)}get backgroundAlarmSensitive(){return this.properties.getValue(he)}get foregroundAlarmSensitive(){return this.properties.getValue(ge)}get pvName(){return this.properties.getValue(xe,!0)}get pvValue(){return this.properties.getValue(we,!0)}get borderColor(){return this.properties.getValue(le)}get borderStyle(){return this.properties.getValue(ce)}get borderWidth(){return this.scale*this.properties.getValue(de)}get backgroundColor(){return this.properties.getValue(ne)}get enabled(){return this.properties.getValue(pe)}get foregroundColor(){return this.properties.getValue(ue)}get tooltip(){const t=this.properties.getProperty(Se);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(Ve)}get visible(){return this.properties.getValue(Ce)}get actions(){return this.properties.getValue(oe)}get scripts(){return this.properties.getValue(be)}get rules(){return this.properties.getValue(ye)}get scaleOptions(){return this.properties.getValue(ve)}get widgetType(){return this.properties.getValue(_e,!0)}get text(){if(this.display.editMode){return(this.properties.getProperty(Te).rawValue||"").split(" ").join(" ")}return this.properties.getValue(Te).split(" ").join(" ")}init(){}hide(){}destroy(){}}const ke="macros";class Me extends Pe{constructor(t,e){super(t,e),this._widgets=[],this._connections=[],this.relativeScale=1,this.properties.add(new O(ke))}expandContainerMacros(t){for(const e in this.macros.macros)t=(t=t.replace(`$(${e})`,this.macros.macros[e])).replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(const e of this.widgets){if(e.wuid===t)return e;if(e instanceof Me){const i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(const e of this.widgets){if(e.name===t)return e;if(e instanceof Me){const i=e.findWidgetByName(t);if(i)return i}}for(const e of this.connections)if(e.name===t)return e}hide(){for(const t of this.widgets)t.hide()}destroy(){for(const t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue(ke)}}const Re="arrow_length",Ee="arrows",Be="fill_arrow",We="name",Ie="line_color",He="line_style",Oe="line_width",Ne="src_wuid",De="src_term",Fe="tgt_wuid",$e="tgt_term",je="router",Ge="points",ze="LEFT",Ue="UP",qe="DOWN",Ye="RIGHT";class Xe extends Pe{constructor(t){super(t),this.properties.clear(),this.properties.add(new k(Re)),this.properties.add(new k(Ee)),this.properties.add(new R(Be)),this.properties.add(new L(We)),this.properties.add(new E(Ie)),this.properties.add(new k(He)),this.properties.add(new k(Oe)),this.properties.add(new L(Ne)),this.properties.add(new L(De)),this.properties.add(new L(Fe)),this.properties.add(new L($e)),this.properties.add(new k(je)),this.properties.add(new I(Ge)),this.properties.add(new L("wuid"))}parseNode(t){this.properties.loadXMLValues(t),this.sourceWidget=this.display.findWidget(this.sourceWuid),this.sourceWidget||console.warn(`Can't find source widget ${this.sourceWuid}`),this.targetWidget=this.display.findWidget(this.targetWuid),this.targetWidget||console.warn(`Can't find target widget ${this.targetWuid}`)}draw(t){this.sourceWidget&&this.targetWidget&&(this.points.length?this.drawPath(t):0===this.router?this.drawManhattanConnection(t):1===this.router&&this.drawDirectConnection(t))}drawPath(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),s=[e,...this.points,i],r=V.fromPoints(s).translate(.5*this.scale,.5*this.scale);t.strokePath({path:r,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,s[1],s[0]),this.drawStopArrow(t,s[s.length-2],s[s.length-1])}drawManhattanConnection(t){const e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),s=this.route(e,i),r=V.fromPoints(s);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:r,dash:this.getDashArray()}),this.drawStartArrow(t,s[s.length-2],s[s.length-1]),this.drawStopArrow(t,s[1],s[0])}getDashArray(){const{scale:t}=this;if(this.lineWidth){if(0===this.lineStyle)return[];if(1===this.lineStyle)return[6*t,2*t];if(2===this.lineStyle)return[2*t,2*t];if(3===this.lineStyle)return[6*t,2*t,2*t,2*t];if(4===this.lineStyle)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}drawDirectConnection(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new V(e.x,e.y).lineTo(i.x,i.y),lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,i,e),this.drawStopArrow(t,e,i)}getManhattanAnchor(t,e){let i;switch(e){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":i=Ue;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=qe;break;case"LEFT":i=ze;break;case"RIGHT":i=Ye}const s=t.bounds,r=this.getPosition(t,e),o=r.x-s.x,n=s.x+s.width-r.x,h=r.y-s.y,a=s.y+s.height-r.y;return i=Math.min(o,n)<Math.min(h,a)?o<n?ze:Ye:h<a?Ue:qe,{x:r.x,y:r.y,direction:i}}getPosition(t,e){switch(e){case"LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight/2};case"TOP":return{x:t.holderX+t.holderWidth/2,y:t.holderY};case"RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight/2};case"BOTTOM":return{x:t.holderX+t.holderWidth/2,y:t.holderY+t.holderHeight};case"TOP_LEFT":return{x:t.holderX,y:t.holderY};case"TOP_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY};case"BOTTOM_LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight};case"BOTTOM_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight};default:const i=parseInt(e,10);let s=t.properties.getProperty("points");if(s){let t=s.value;return t=v(t,this.scale),t[i]}throw Error(`Unexpected term ${e}`)}}route(t,e){let i,s,r=t.x-e.x,o=t.y-e.y,n={x:0,y:0},h=[];const{tolxtol:a,tol:l,minDist:d}=this;if(r*r<a&&o*o<a)return[{x:e.x,y:e.y}];t.direction===ze?r>0&&o*o<l&&e.direction===Ye?(n=e,i=e.direction):(r<0?n={x:t.x-d,y:t.y}:o>0&&e.direction===qe||o<0&&e.direction===Ue?n={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.min(t.x,e.x)-d,n={x:s,y:t.y}):n={x:t.x-r/2,y:t.y},i=o>0?Ue:qe):t.direction===Ye?r<0&&o*o<l&&e.direction===ze?(n=e,i=e.direction):(r>0?n={x:t.x+d,y:t.y}:o>0&&e.direction===qe||o<0&&e.direction===Ue?n={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.max(t.x,e.x)+d,n={x:s,y:t.y}):n={x:t.x-r/2,y:t.y},i=o>0?Ue:qe):t.direction===qe?r*r<l&&o<0&&e.direction===Ue?(n=e,i=e.direction):(o>0?n={x:t.x,y:t.y+d}:r>0&&e.direction===Ye||r<0&&e.direction===ze?n={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.max(t.y,e.y)+d,n={x:t.x,y:s}):n={x:t.x,y:t.y-o/2},i=r>0?ze:Ye):t.direction===Ue&&(r*r<l&&o>0&&e.direction===qe?(n=e,i=e.direction):(o<0?n={x:t.x,y:t.y-d}:r>0&&e.direction===Ye||r<0&&e.direction===ze?n={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.min(t.y,e.y)-d,n={x:t.x,y:s}):n={x:t.x,y:t.y-o/2},i=r>0?ze:Ye));const c=Object.assign(Object.assign({},n),{direction:i});return h=h.concat(this.route(c,e)),h.push(t),h}drawStartArrow(t,e,i){const s=t.ctx;if(1===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}drawStopArrow(t,e,i){const s=t.ctx;if(2===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}calculateArrowPoints(t,e){const i=w(e,t),s=Math.PI/10,r=new y(this.arrowLength,i.theta-s),o=new y(this.arrowLength,i.theta+s),n=new y(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[g(r.toPoint(),e.x,e.y),g(o.toPoint(),e.x,e.y),g(n.toPoint(),e.x,e.y)]}get minDist(){return 20*this.scale}get tol(){return.1*this.scale}get tolxtol(){return.01*this.scale}get name(){return this.properties.getValue(We)}get arrows(){return this.properties.getValue(Ee)}get fillArrow(){return this.properties.getValue(Be)}get arrowLength(){return this.scale*this.properties.getValue(Re)}get lineColor(){return this.properties.getValue(Ie)}get lineStyle(){return this.properties.getValue(He)}get lineWidth(){return this.scale*this.properties.getValue(Oe)}get router(){return this.properties.getValue(je)}get sourceTerm(){return this.properties.getValue(De)}get sourceWuid(){return this.properties.getValue(Ne)}get targetTerm(){return this.properties.getValue($e)}get targetWuid(){return this.properties.getValue(Fe)}get points(){return v(this.properties.getValue(Ge),this.scale)}}let Ke=0;const Ze="auto_scale_widgets";class Je extends Me{constructor(t,e,i){super(t,e),this.displayArgs=null!=i?i:{},this.properties.add(new z(Ze))}parseNode(t){super.parseNode(t);const e=Ke++;this.macros.set("DID",`DID_${e}`);const i=this.properties.getValue("name");this.macros.set("DNAME",i);for(const t in this.displayArgs)this.macros.set(t,this.displayArgs[t]);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}for(const e of t.getNodes("connection")){const t=new Xe(this.display);t.parseNode(e),this.connections.push(t)}}draw(t){for(const e of this.widgets.filter((t=>t.visible)))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(const e of this.connections)e.draw(t);for(const e of this.widgets.filter((t=>t.visible)))e.drawOverlay(t)}measureContentBounds(t){let e=0,i=0,s=0,r=0;for(const o of this.widgets.filter((t=>t.visible))){const n=t?o.bounds:o.unscaledBounds;e=Math.min(e,n.x),i=Math.min(i,n.y),s=Math.max(s,n.x+n.width),r=Math.max(r,n.y+n.height)}return{x:e,y:i,width:s-e,height:r-i}}get autoScaleWidgets(){return this.properties.getValue(Ze)}}let Qe=0;const ti="group_name",ei="opi_file",ii="resize_behaviour";class si extends Me{constructor(t,e){super(t,e),this.properties.add(new L(ti)),this.properties.add(new L(ei)),this.properties.add(new k(ii,0))}parseNode(t){super.parseNode(t);const e=Qe++;this.macros.set("LCID",`LCID_${e}`)}init(){this.opiFile&&(this.resolvedOpiFile=this.display.resolvePath(this.opiFile),fetch(this.resolvedOpiFile,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.linkedDisplay=new Je(this.display,this);const e=re.parseFromXML(t);this.linkedDisplay.parseNode(e),this.requestRepaint()}))})))}draw(t){this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect(Object.assign(Object.assign({},this.area),{color:this.linkedDisplay.backgroundColor})),0===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!1);let{width:i,height:s}=e;const r=this.display.scale;i*=r,s*=r;const o=i/s;let n=this.width,h=n/o,a=n/i;h>this.height&&(h=this.height,n=h*o,a=h/i),this.linkedDisplay.relativeScale=a;const l=t.createChild(Math.ceil(n),Math.ceil(h));l.translate(e.x,e.y),this.linkedDisplay.draw(l),t.copy(l,this.x,this.y)}else if(1===this.resizeBehavior)console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior);else if(2===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!0),i=t.createChild(e.width,e.height);i.translate(e.x,e.y),this.linkedDisplay.draw(i),t.copy(i,this.x,this.y)}else 3===this.resizeBehavior&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&""!==this.groupName?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(ei)}get groupName(){return this.properties.getValue(ti)}get resizeBehavior(){return this.properties.getValue(ii)}}class ri{constructor(t){this.display=t}resolve(t,e){if(t.startsWith("/"))return`${this.display.absPrefix}${t.slice(1)}`;if(t.startsWith("http://")||t.startsWith("https://"))return t;if(e){let i=e.parent;for(;i;){if(i instanceof si){const e=i.resolvedOpiFile,s=e.lastIndexOf("/")+1;return`${e.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}}class oi{constructor(t,e){this.pvName=t,this.formula=e,this.pvValues=new Map}updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){const t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":-1===e.indexOf(t.value)&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(const i of t.arguments)this.getExpressionParameters(i,e)}}execute(){const t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":case"ConstantLiteral":case"NumericLiteral":case"StringLiteral":return t.value;case"ParameterLiteral":const e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConditionalExpression":return this.executeConditionalExpression(t);case"BinaryExpression":return this.executeBinaryExpression(t);case"LogicalExpression":return this.executeLogicalExpression(t);case"UnaryExpression":return this.executeUnaryExpression(t);case"CallExpression":return this.executeCallExpression(t);default:throw new Error("Unexpected expression type")}}executeBinaryExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"+":return e+i;case"-":return e-i;case"*":return e*i;case"/":return e/i;case"^":return Math.pow(e,i);case"%":return e%i;case"==":return e===i;case"!=":return e!==i;case"<=":return e<=i;case"<":return e<i;case">=":return e>=i;case">":return e>i;default:throw new Error(`Unexpected binary operator ${t.operator}`)}}executeLogicalExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"&&":return e&&i;case"||":return e||i;default:throw new Error(`Unexpected logical operator ${t.operator}`)}}executeConditionalExpression(t){const e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(void 0===t.alternate)return e?i:null;{const s=this.executeExpression(t.alternate);return e?i:s}}executeUnaryExpression(t){const e=this.executeExpression(t.argument);switch(t.operator){case"-":return-e;case"+":return e;default:throw new Error(`Unexpected unary operator ${t.operator}`)}}executeCallExpression(t){const e=t.callee.name,i=[];for(const e of t.arguments)i.push(this.executeExpression(e));switch(e){case"abs":return Math.abs(i[0]);case"acos":return Math.acos(i[0]);case"asin":return Math.asin(i[0]);case"atan":return Math.atan(i[0]);case"cbrt":return Math.cbrt(i[0]);case"ceil":return Math.ceil(i[0]);case"cos":return Math.cos(i[0]);case"cosh":return Math.cosh(i[0]);case"exp":return Math.exp(i[0]);case"floor":return Math.floor(i[0]);case"log":return Math.log(i[0]);case"log10":return Math.log10(i[0]);case"round":return Math.round(i[0]);case"signum":return Math.sign(i[0]);case"sin":return Math.sin(i[0]);case"sinh":return Math.sinh(i[0]);case"sqrt":return Math.sqrt(i[0]);case"tan":return Math.tan(i[0]);case"tanh":return Math.tanh(i[0]);case"toDegrees":return 180*i[0]/Math.PI;case"toRadians":return i[0]/180*Math.PI;case"parameterAcquisitionStatus":return this.callParameterAcquisitionStatus(i[0]);default:throw new Error(`Unsupported function '${e}'`)}}callParameterAcquisitionStatus(t){const e=this.pvValues.get(t);if(e)return e.acquisitionStatus}}function ni(t,e,i,s){var r=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(r,ni.prototype),r.expected=e,r.found=i,r.location=s,r.name="SyntaxError",r}function hi(t,e,i){return i=i||" ",t.length>e?t:(e-=t.length,t+(i+=i.repeat(e)).slice(0,e))}function ai(t,e){var i,s,r,o,n={},h=(e=void 0!==e?e:{}).grammarSource,a={Start:te},l=te,d="=",c="false",p="true",u="pi",g="e",m=".",f="0",x='"',w="'",y="(",v=")",b=",",T="<=",S=">=",V="==",C="!=",_="&&",A="||",L=/^[\t ]/,P=/^[A-Z_a-z]/,k=/^[a-zA-Z0-9_]/,M=/^[0-9]/,R=/^[1-9]/,E=/^[^\n\r\f"]/,B=/^[^\n\r\f']/,W=/^[+\-]/,I=/^[%*\/\^]/,H=/^[<>]/,O=Yt("=",!1),N=Xt(["\t"," "],!1,!1),D=Yt("false",!0),F=Yt("true",!0),$=Yt("PI",!0),j=Yt("E",!0),G=Kt("identifier"),z=Xt([["A","Z"],"_",["a","z"]],!1,!1),U=Xt([["a","z"],["A","Z"],["0","9"],"_"],!1,!1),q=Kt("boolean"),Y=Kt("constant"),X=Kt("number"),K=Yt(".",!1),Z=Yt("0",!1),J=Xt([["0","9"]],!1,!1),Q=Xt([["1","9"]],!1,!1),tt=Kt("string"),et=Yt('"',!1),it=Xt(["\n","\r","\f",'"'],!0,!1),st=Kt("parameter"),rt=Yt("'",!1),ot=Xt(["\n","\r","\f","'"],!0,!1),nt=Yt("(",!1),ht=Yt(")",!1),at=Xt(["+","-"],!1,!1),lt=Yt(",",!1),dt=Xt(["%","*","/","^"],!1,!1),ct=Yt("<=",!1),pt=Yt(">=",!1),ut=Xt(["<",">"],!1,!1),gt=Yt("==",!1),mt=Yt("!=",!1),ft=Yt("&&",!1),xt=Yt("||",!1),wt=function(t){return t},yt=function(t){return{type:"Formula",expression:t}},vt=function(t){return t},bt=function(t,e){return{type:"Symbol",name:t+e.join("")}},Tt=function(){return{type:"BooleanLiteral",value:!0}},St=function(){return{type:"BooleanLiteral",value:!1}},Vt=function(){return{type:"ConstantLiteral",value:Math.PI}},Ct=function(){return{type:"ConstantLiteral",value:Math.E}},_t=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},At=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},Lt=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},Pt=function(t){return{type:"StringLiteral",value:t.join("")}},kt=function(t){return{type:"ParameterLiteral",value:t.join("")}},Mt=function(t){return t},Rt=function(t,e){return{type:"UnaryExpression",operator:t,argument:e}},Et=function(t,e){return{type:"CallExpression",callee:t,arguments:e}},Bt=function(t){return s=0,null!==(e=(i=t)?i[s]:null)?e:[];var e,i,s},Wt=function(t,e){return function(t,e,i){return[t].concat(function(t,e){return t.map((function(t){return t[e]}))}(e,i))}(t,e,3)},It=function(t,e){return me(t,e)},Ht=function(t,e){return me(t,e)},Ot=function(t,e){return me(t,e)},Nt=function(t,e){return me(t,e)},Dt=function(t,e){return function(t,e){return e.reduce((function(t,e){return{type:"LogicalExpression",operator:e[1],left:t,right:e[3]}}),t)}(t,e)},Ft=0|e.peg$currPos,$t=Ft,jt=[{line:1,column:1}],Gt=Ft,zt=e.peg$maxFailExpected||[],Ut=0|e.peg$silentFails;if(e.startRule){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');l=a[e.startRule]}function qt(){return t.substring($t,Ft)}function Yt(t,e){return{type:"literal",text:t,ignoreCase:e}}function Xt(t,e,i){return{type:"class",parts:t,inverted:e,ignoreCase:i}}function Kt(t){return{type:"other",description:t}}function Zt(e){var i,s=jt[e];if(s)return s;if(e>=jt.length)i=jt.length-1;else for(i=e;!jt[--i];);for(s={line:(s=jt[i]).line,column:s.column};i<e;)10===t.charCodeAt(i)?(s.line++,s.column=1):s.column++,i++;return jt[e]=s,s}function Jt(t,e,i){var s=Zt(t),r=Zt(e),o={source:h,start:{offset:t,line:s.line,column:s.column},end:{offset:e,line:r.line,column:r.column}};return i&&h&&"function"==typeof h.offset&&(o.start=h.offset(o.start),o.end=h.offset(o.end)),o}function Qt(t){Ft<Gt||(Ft>Gt&&(Gt=Ft,zt=[]),zt.push(t))}function te(){var e,i,s;return e=Ft,61===t.charCodeAt(Ft)?(i=d,Ft++):(i=n,0===Ut&&Qt(O)),i!==n?(ee(),s=function(){var t,e;t=Ft,e=ge(),e!==n&&($t=t,e=yt(e));return t=e,t}(),s!==n?(ee(),$t=e,e=wt(s)):(Ft=e,e=n)):(Ft=e,e=n),e}function ee(){var t,e;for(t=[],e=ie();e!==n;)t.push(e),e=ie();return t}function ie(){var e;return e=t.charAt(Ft),L.test(e)?Ft++:(e=n,0===Ut&&Qt(N)),e}function se(){var e,i;return e=Ft,i=function(){var e,i,s,r;if(Ut++,e=Ft,i=function(){var e;e=t.charAt(Ft),P.test(e)?Ft++:(e=n,0===Ut&&Qt(z));return e}(),i!==n){for(s=[],r=re();r!==n;)s.push(r),r=re();$t=e,e=bt(i,s)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(G));return e}(),i!==n&&($t=e,i=vt(i)),e=i}function re(){var e;return e=t.charAt(Ft),k.test(e)?Ft++:(e=n,0===Ut&&Qt(U)),e}function oe(){var e;return(e=function(){var e,i;Ut++,e=Ft,i=function(){var e;return(e=t.substr(Ft,4)).toLowerCase()===p?Ft+=4:(e=n,0===Ut&&Qt(F)),e}(),i!==n&&($t=e,i=Tt());e=i,e===n&&(e=Ft,i=function(){var e;return(e=t.substr(Ft,5)).toLowerCase()===c?Ft+=5:(e=n,0===Ut&&Qt(D)),e}(),i!==n&&($t=e,i=St()),e=i);Ut--,e===n&&(i=n,0===Ut&&Qt(q));return e}())===n&&(e=function(){var e,i;Ut++,e=Ft,i=function(){var e;return(e=t.substr(Ft,2)).toLowerCase()===u?Ft+=2:(e=n,0===Ut&&Qt($)),e}(),i!==n&&($t=e,i=Vt());e=i,e===n&&(e=Ft,i=function(){var e;return(e=t.charAt(Ft)).toLowerCase()===g?Ft++:(e=n,0===Ut&&Qt(j)),e}(),i!==n&&($t=e,i=Ct()),e=i);Ut--,e===n&&(i=n,0===Ut&&Qt(Y));return e}())===n&&(e=function(){var e,i,s,r,o;if(Ut++,e=Ft,(i=ne())!==n)if(46===t.charCodeAt(Ft)?(s=m,Ft++):(s=n,0===Ut&&Qt(K)),s!==n){for(r=[],o=he();o!==n;)r.push(o),o=he();$t=e,e=_t()}else Ft=e,e=n;else Ft=e,e=n;if(e===n){if(e=Ft,46===t.charCodeAt(Ft)?(i=m,Ft++):(i=n,0===Ut&&Qt(K)),i!==n){if(s=[],(r=he())!==n)for(;r!==n;)s.push(r),r=he();else s=n;s!==n?($t=e,e=At()):(Ft=e,e=n)}else Ft=e,e=n;e===n&&(e=Ft,(i=ne())!==n&&($t=e,i=Lt()),e=i)}Ut--,e===n&&(i=n,0===Ut&&Qt(X));return e}())===n&&(e=function(){var e,i,s,r;Ut++,e=Ft,34===t.charCodeAt(Ft)?(i=x,Ft++):(i=n,0===Ut&&Qt(et));if(i!==n){for(s=[],r=t.charAt(Ft),E.test(r)?Ft++:(r=n,0===Ut&&Qt(it));r!==n;)s.push(r),r=t.charAt(Ft),E.test(r)?Ft++:(r=n,0===Ut&&Qt(it));34===t.charCodeAt(Ft)?(r=x,Ft++):(r=n,0===Ut&&Qt(et)),r!==n?($t=e,e=Pt(s)):(Ft=e,e=n)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(tt));return e}())===n&&(e=function(){var e,i,s,r;Ut++,e=Ft,39===t.charCodeAt(Ft)?(i=w,Ft++):(i=n,0===Ut&&Qt(rt));if(i!==n){for(s=[],r=t.charAt(Ft),B.test(r)?Ft++:(r=n,0===Ut&&Qt(ot));r!==n;)s.push(r),r=t.charAt(Ft),B.test(r)?Ft++:(r=n,0===Ut&&Qt(ot));39===t.charCodeAt(Ft)?(r=w,Ft++):(r=n,0===Ut&&Qt(rt)),r!==n?($t=e,e=kt(s)):(Ft=e,e=n)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(st));return e}()),e}function ne(){var e,i,s,r;if(48===t.charCodeAt(Ft)?(e=f,Ft++):(e=n,0===Ut&&Qt(Z)),e===n)if(e=Ft,i=function(){var e;e=t.charAt(Ft),R.test(e)?Ft++:(e=n,0===Ut&&Qt(Q));return e}(),i!==n){for(s=[],r=he();r!==n;)s.push(r),r=he();e=i=[i,s]}else Ft=e,e=n;return e}function he(){var e;return e=t.charAt(Ft),M.test(e)?Ft++:(e=n,0===Ut&&Qt(J)),e}function ae(){var e,i,s;return e=function(){var e,i,s,r;return(e=oe())===n&&(e=Ft,40===t.charCodeAt(Ft)?(i=y,Ft++):(i=n,0===Ut&&Qt(nt)),i!==n?(ee(),(s=ge())!==n?(ee(),41===t.charCodeAt(Ft)?(r=v,Ft++):(r=n,0===Ut&&Qt(ht)),r!==n?($t=e,e=Mt(s)):(Ft=e,e=n)):(Ft=e,e=n)):(Ft=e,e=n)),e}(),e===n&&(e=Ft,i=function(){var e;e=t.charAt(Ft),W.test(e)?Ft++:(e=n,0===Ut&&Qt(at));return e}(),i!==n?(ee(),(s=ae())!==n?(ee(),$t=e,e=Rt(i,s)):(Ft=e,e=n)):(Ft=e,e=n)),e}function le(){var e,i,s;return e=Ft,(i=se())!==n?(ee(),s=function(){var e,i,s,r;e=Ft,40===t.charCodeAt(Ft)?(i=y,Ft++):(i=n,0===Ut&&Qt(nt));i!==n?(ee(),s=Ft,r=function(){var e,i,s,r,o,h,a,l;if(e=Ft,i=ge(),i!==n){for(s=[],r=Ft,o=ee(),44===t.charCodeAt(Ft)?(h=b,Ft++):(h=n,0===Ut&&Qt(lt)),h!==n?(a=ee(),(l=ge())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),44===t.charCodeAt(Ft)?(h=b,Ft++):(h=n,0===Ut&&Qt(lt)),h!==n?(a=ee(),(l=ge())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Wt(i,s)}else Ft=e,e=n;return e}(),r!==n?s=r=[r,ee()]:(Ft=s,s=n),s===n&&(s=null),41===t.charCodeAt(Ft)?(r=v,Ft++):(r=n,0===Ut&&Qt(ht)),r!==n?($t=e,e=Bt(s)):(Ft=e,e=n)):(Ft=e,e=n);return e}(),s!==n?($t=e,e=Et(i,s)):(Ft=e,e=n)):(Ft=e,e=n),e===n&&(e=ae()),e}function de(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=le())!==n){for(s=[],r=Ft,o=ee(),h=t.charAt(Ft),I.test(h)?Ft++:(h=n,0===Ut&&Qt(dt)),h!==n?(a=ee(),(l=le())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),h=t.charAt(Ft),I.test(h)?Ft++:(h=n,0===Ut&&Qt(dt)),h!==n?(a=ee(),(l=le())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=It(i,s)}else Ft=e,e=n;return e}function ce(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=de())!==n){for(s=[],r=Ft,o=ee(),h=t.charAt(Ft),W.test(h)?Ft++:(h=n,0===Ut&&Qt(at)),h!==n?(a=ee(),(l=de())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),h=t.charAt(Ft),W.test(h)?Ft++:(h=n,0===Ut&&Qt(at)),h!==n?(a=ee(),(l=de())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Ht(i,s)}else Ft=e,e=n;return e}function pe(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=ce())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===T?(h=T,Ft+=2):(h=n,0===Ut&&Qt(ct)),h===n&&(t.substr(Ft,2)===S?(h=S,Ft+=2):(h=n,0===Ut&&Qt(pt)),h===n&&(h=t.charAt(Ft),H.test(h)?Ft++:(h=n,0===Ut&&Qt(ut)))),h!==n?(a=ee(),(l=ce())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===T?(h=T,Ft+=2):(h=n,0===Ut&&Qt(ct)),h===n&&(t.substr(Ft,2)===S?(h=S,Ft+=2):(h=n,0===Ut&&Qt(pt)),h===n&&(h=t.charAt(Ft),H.test(h)?Ft++:(h=n,0===Ut&&Qt(ut)))),h!==n?(a=ee(),(l=ce())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Ot(i,s)}else Ft=e,e=n;return e}function ue(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=pe())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===V?(h=V,Ft+=2):(h=n,0===Ut&&Qt(gt)),h===n&&(t.substr(Ft,2)===C?(h=C,Ft+=2):(h=n,0===Ut&&Qt(mt))),h!==n?(a=ee(),(l=pe())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===V?(h=V,Ft+=2):(h=n,0===Ut&&Qt(gt)),h===n&&(t.substr(Ft,2)===C?(h=C,Ft+=2):(h=n,0===Ut&&Qt(mt))),h!==n?(a=ee(),(l=pe())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Nt(i,s)}else Ft=e,e=n;return e}function ge(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=ue())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===_?(h=_,Ft+=2):(h=n,0===Ut&&Qt(ft)),h===n&&(t.substr(Ft,2)===A?(h=A,Ft+=2):(h=n,0===Ut&&Qt(xt))),h!==n?(a=ee(),(l=ue())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===_?(h=_,Ft+=2):(h=n,0===Ut&&Qt(ft)),h===n&&(t.substr(Ft,2)===A?(h=A,Ft+=2):(h=n,0===Ut&&Qt(xt))),h!==n?(a=ee(),(l=ue())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Dt(i,s)}else Ft=e,e=n;return e}function me(t,e){return e.reduce((function(t,e){return{type:"BinaryExpression",operator:e[1],left:t,right:e[3]}}),t)}if(i=l(),e.peg$library)return{peg$result:i,peg$currPos:Ft,peg$FAILED:n,peg$maxFailExpected:zt,peg$maxFailPos:Gt};if(i!==n&&Ft===t.length)return i;throw i!==n&&Ft<t.length&&Qt({type:"end"}),s=zt,r=Gt<t.length?t.charAt(Gt):null,o=Gt<t.length?Jt(Gt,Gt+1):Jt(Gt,Gt),new ni(ni.buildMessage(s,r),s,r,o)}!function(t,e){function i(){this.constructor=t}i.prototype=e.prototype,t.prototype=new i}(ni,Error),ni.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var i,s=null;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){s=t[i].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(r):r,n=this.location.source+":"+o.line+":"+o.column;if(s){var h=this.location.end,a=hi("",o.line.toString().length," "),l=s[r.line-1],d=(r.line===h.line?h.column:l.length+1)-r.column||1;e+="\n --\x3e "+n+"\n"+a+" |\n"+o.line+" | "+l+"\n"+a+" | "+hi("",r.column-1," ")+hi("",d,"^")}else e+="\n at "+n}return e},ni.buildMessage=function(t,e){var i={literal:function(t){return'"'+r(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function s(t){return t.charCodeAt(0).toString(16).toUpperCase()}function r(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function n(t){return i[t.type](t)}return"Expected "+function(t){var e,i,s=t.map(n);if(s.sort(),s.length>0){for(e=1,i=1;e<s.length;e++)s[e-1]!==s[e]&&(s[i]=s[e],i++);s.length=i}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(t)+" but "+function(t){return t?'"'+r(t)+'"':"end of input"}(e)+" found."};class li{compile(t){const e=ai(t,{});return new oi(t,e)}execute(t){return this.compile(t).execute()}}class di{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("=")}startProviding(t){for(const e of t)this.pvs.set(e.name,new ci(e))}stopProviding(t){for(const e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}}class ci{constructor(t){this.pv=t;const e=new li;this.compiledFormula=e.compile(t.name);for(const e of this.compiledFormula.getPVNames()){const i=t.pvEngine.createPV(e);this.compiledFormula.updateDataSource(i.name,{value:i.value,acquisitionStatus:"good"}),t.pvEngine.addListener(e,(()=>{this.compiledFormula.updateDataSource(e,{value:t.pvEngine.getValue(e),acquisitionStatus:"good"}),this.trigger()}))}this.trigger()}trigger(){const t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}}function pi(t){return!isNaN(t)&&(Number.isInteger(parseFloat(t))||t%1!=0)}function ui(t){return pi(t)?parseFloat(t):(console.warn(`Not a valid float: ${t}`),t)}function gi(t){return null!=t?String(t):t}class mi extends xt{constructor(t,e,i,s){super(t,e),this.type=i,this.initializer=s,this.writable=!0}setSample(t){if("VDouble"===this.type)t.value=ui(t.value);else if("VDoubleArray"===this.type)for(let e=0;e<t.value.length;e++)t.value[e]=ui(t.value);else if("VString"===this.type)t.value=gi(t.value);else if("VStringArray"===this.type)for(let e=0;e<t.value.length;e++)t.value[e]=gi(t.value);else"string"==typeof t.value&&pi(t.value)&&(t.value=parseFloat(t.value));super.setSample(t)}}const fi=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function xi(t){if(!t.startsWith("loc://"))return t;const e=t.match(fi);return e?e[1]:t}class wi{constructor(t){this.display=t,this.rules=[],this.scripts=[],this.pvs=new Map,this.providers=[],this.scriptLibraries={},this.listeners=new Map}init(){for(const t of this.listeners.entries()){const e=this.pvs.get(t[0]);if(e&&null!==e.value&&void 0!==e.value)for(const e of t[1])e()}}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){const e=xi(t);return this.pvs.has(e)}getPV(t){const e=xi(t);return this.pvs.get(e)}disconnectAll(){for(const t of this.providers){const e=[];for(const i of this.pvs.values())t.canProvide(i.name)&&e.push(i);e.length&&t.stopProviding(e)}this.pvs.clear()}createPV(t){if(t.startsWith("loc://"))return this.createLocalPV(t);let e=this.pvs.get(t);if(e)return e;e=new xt(t,this),this.pvs.set(t,e);for(const i of this.providers)if(i.canProvide(t))return e.navigable=i.isNavigable(),i.startProviding([e]),e;return console.warn(`No provider for PV ${t}`),e.disconnected=!0,e}createHistoricalDataProvider(t,e){for(const i of this.providers)if(i.canProvide(t)){if(i.createHistoricalDataProvider)return i.createHistoricalDataProvider(t,e);break}}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){const e=t.match(fi);let i,s;if(e){if(t=e[1],e[3])switch(e[3]){case"VDouble":case"VDoubleArray":case"VString":case"VStringArray":i=e[3];break;default:console.warn(`Unknown local PV type information: ${e[3]}`)}if(void 0!==e[5]){const t=e[5];s=t.startsWith('"')&&t.endsWith('"')?t.substring(1,t.length-1):-1!==t.indexOf(",")?t.split(",").map((t=>{const e=t.trim();return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):Number(e)})):Number(t)}}let r=this.pvs.get(t),o=!1;if(r){const e=r;e.type&&i&&e.type!==i&&console.warn(`PV ${t} is defined with different types: ${e.type} !== ${i}`),void 0===e.initializer||void 0===s||this.initializerEquals(e.initializer,s)?void 0===e.initializer&&void 0!==s&&(o=!0):console.warn(`PV ${t} is defined with different initializers: ${e.initializer} !== ${s}`)}return r?i&&!r.type&&(r.type=i):(r=new mi(t,this,i,s),this.pvs.set(t,r),o=!0),o&&void 0!==s&&this.setValue(new Date,t,s),r}initializerEquals(t,e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}return t===e}getValue(t){const e=xi(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,s=wt.NONE){const r=xi(e),o=this.pvs.get(r);if(!o)throw new Error(`Cannot set value of unknown PV ${e}`);o.setSample({time:t,value:i,severity:s});for(const t of this.listeners.get(r)||[])t()}setValues(t){const e=[];for(const i of t.keys()){const s=this.pvs.get(i);if(s){s.setSample(t.get(i));for(const t of this.listeners.get(i)||[])e.push(t)}else console.warn(`Received an update for unknown pv ${i}`)}for(const t of e)t()}createScript(t,e,i){const s=[];for(const i of e.inputs){const e=t.expandMacro(i.pvName);s.push(this.createPV(e))}const r=new yi(t,e,i,s);this.scripts.push(r);for(let i=0;i<e.inputs.length;i++){const o=e.inputs[i],n=s[i];if(o.trigger){const i=t.expandMacro(o.pvName);this.addListener(i,(()=>{if(e.checkConnect)for(let t=0;t<e.inputs.length;t++){const i=s[t],r=e.inputs[t].trigger,o=null!==i.value&&void 0!==i.value;if(i.disconnected||r&&!o)return}r.scriptEngine.run(n)}),!1)}}return r}createRule(t,e){const i=[];for(const s of e.inputs){const e=t.expandMacro(s.pvName);i.push(this.createPV(e))}const s=new vi(t,e,i);this.rules.push(s);const r=()=>s.scriptEngine.run();for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,r,!1)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){const s=xi(t),r=this.listeners.get(s);if(r?r.push(e):this.listeners.set(s,[e]),i){const t=this.pvs.get(s);t&&null!==t.value&&void 0!==t.value&&e()}}removeListener(t,e){const i=xi(t),s=this.listeners.get(i);if(s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}}class yi{constructor(t,e,i,s){this.widget=t,this.script=e,this.text=i,this.pvs=s,this.scriptEngine=new Ct(t,i,s)}}class vi{constructor(t,e,i){this.widget=t,this.rule=e;let s="";const r=t.properties.getProperty(e.propertyName);if(!r)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let t=!1,o=!1,n=!1,h=!1;for(const i of e.expressions)i.expression.match(/pv[0-9]+/)&&(t=!0),e.outputExpression&&i.outputValue.toString().match(/pv[0-9]+/)&&(t=!0),-1!==i.expression.indexOf("pvInt")&&(o=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvInt")&&(o=!0),-1!==i.expression.indexOf("pvStr")&&(n=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvStr")&&(n=!0),-1!==i.expression.indexOf("pvSev")&&(h=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvSev")&&(h=!0);for(let e=0;e<i.length;e++)t&&(s+=`var pv${e} = PVUtil.getDouble(pvs[${e}]);\n`),o&&(s+=`var pvInt${e} = PVUtil.getLong(pvs[${e}]);\n`),n&&(s+=`var pvStr${e} = PVUtil.getString(pvs[${e}]);\n`),h&&(s+=`var pvSev${e} = PVUtil.getSeverity(pvs[${e}]);\n`);for(let t=0;t<e.expressions.length;t++){const i=e.expressions[t].expression,o=e.expressions[t].outputValue;if(t>0&&(s+="else "),s+=`if (${i}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)s+=`${o});\n`;else{s+=`${this.printScriptValue(r,o)});\n`}}const a=r.value,l=this.printScriptValue(r,a);s+=`else widget.setPropertyValue("${e.propertyName}", `,s+=`${l});\n`}this.scriptEngine=new Ct(t,s,i)}printScriptValue(t,e){return null==e?"null":t.printScriptValue(e)}}class bi{constructor(t,e,i){this.pv=t,this.interval=e,void 0!==i&&t.pvEngine.setValue(new Date,t.name,i),this.interval>0&&(this.timer=window.setInterval((()=>{this.generateSample(new Date)}),e))}emit(t,e){let i=wt.NONE;void 0!==this.pv.lowerAlarmLimit&&e<this.pv.lowerAlarmLimit||void 0!==this.pv.upperAlarmLimit&&e>this.pv.upperAlarmLimit?i=wt.MAJOR:(void 0!==this.pv.lowerWarningLimit&&e<this.pv.lowerWarningLimit||void 0!==this.pv.upperWarningLimit&&e>this.pv.upperWarningLimit)&&(i=wt.MINOR),this.pv.pvEngine.setValue(t,this.pv.name,e,i)}stop(){window.clearInterval(this.timer)}}class Ti extends bi{constructor(t,e){super(t,-1,e)}generateSample(){}}class Si extends bi{constructor(t,e,i,s){super(t,s),this.min=e,this.max=i;const r=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*r,t.lowerWarningLimit=e+.2*r,t.upperWarningLimit=e+.8*r,t.upperAlarmLimit=e+.9*r,t.upperDisplayLimit=i}generateSample(t){const e=Math.random()*(this.max-this.min)+this.min;this.emit(t,e)}}class Vi extends bi{constructor(t,e,i,s){super(t,s),this.avg=e,this.stddev=i,t.units="x",t.lowerDisplayLimit=e-4*i,t.lowerAlarmLimit=e-2*i,t.lowerWarningLimit=e-i,t.upperWarningLimit=e+i,t.upperAlarmLimit=e+2*i,t.upperDisplayLimit=e+4*i}generateSample(t){let e,i,s;do{e=2*Math.random()-1,i=2*Math.random()-1,s=e*e+i*i}while(s>=1||0===s);const r=e*Math.sqrt(-2*Math.log(s)/s);this.emit(t,this.avg+r*this.stddev)}}class Ci extends bi{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.samplesPerCycle=s,this.currentValue=0;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){const e=this.max-this.min,i=Math.sin(2*this.currentValue*Math.PI/this.samplesPerCycle)*e/2+this.min+e/2;this.currentValue++,this.emit(t,i)}}let _i=class extends bi{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.inc=s,this.currentValue=0,this.currentValue=s>=0?e-s:i-s;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(t,this.currentValue)}};const Ai=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/;class Li{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("sim://")}startProviding(t){for(const e of t){const t=new Pi(e);this.pvs.set(e.name,t)}}stopProviding(t){for(const e of t){const t=this.pvs.get(e.name);t&&(t.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(const t of this.pvs.values())t.fn.stop()}}class Pi{constructor(t){this.pv=t;const e=t.name.match(Ai);if(e){const t=e[3]?e[3].split(","):[];for(let e=0;e<t.length;e++)t[e]=t[e].trim();this.fn=this.createGenerator(e[1],t)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new Ti(t,void 0)}createGenerator(t,e){switch(t){case"const":const i=this.saferEval(e[0]);return new Ti(this.pv,i);case"gaussianNoise":return this.createGaussianNoise(e);case"noise":return this.createNoise(e);case"ramp":return this.createRamp(e);case"sine":return this.createSine(e);default:return console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new Ti(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(0===t.length)return new Si(this.pv,-5,5,1e3);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Si(this.pv,e,i,s)}}createGaussianNoise(t){if(0===t.length)return new Vi(this.pv,0,1,100);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Vi(this.pv,e,i,s)}}createRamp(t){let e;if(0===t.length)e=new _i(this.pv,-5,5,1,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new _i(this.pv,i,s,1,r)}else{if(4!==t.length)return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new Ti(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new _i(this.pv,i,s,r,o)}}return e}createSine(t){let e;if(0===t.length)e=new Ci(this.pv,-5,5,10,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new Ci(this.pv,i,s,10,r)}else{if(4!==t.length)return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new Ti(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new Ci(this.pv,i,s,r,o)}}return e}}const ki="font",Mi="push_action_index",Ri="release_action_index",Ei="toggle_button",Bi="image";class Wi extends Pe{constructor(t,e){super(t,e),this.pushed=!1,this.imageLoaded=!1,this.properties.add(new B(ki)),this.properties.add(new R(Ei)),this.properties.add(new k(Mi)),this.properties.add(new k(Ri)),this.properties.add(new L(Bi))}init(){this.image&&(this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()},this.imageElement.src=this.resolvePath(this.image)),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.pushed=!1,this.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,this.requestRepaint())},click:()=>{this.executeActionByIndex(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){const e=t.ctx,{scale:s}=this;t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const r=1*s,o=this.holderY+r/2,n=this.holderX+r/2,h=this.holderY+this.holderHeight-r+r/2,a=this.holderX+this.holderWidth-r+r/2;t.strokePath({lineWidth:r,color:this.pushed?i.BUTTON_LIGHTEST:i.BLACK,path:new V(a,h).lineTo(a,o).moveTo(a,h).lineTo(n,h)}),t.strokePath({lineWidth:r,color:this.pushed?this.backgroundColor:i.BUTTON_DARKER,path:new V(a-r,h-r).lineTo(a-r,o+r).moveTo(a-r,h-r).lineTo(n+r,h-r)}),t.strokePath({lineWidth:r,color:this.pushed?i.BLACK:i.BUTTON_LIGHTEST,path:new V(n,o).lineTo(a-r,o).moveTo(n,o).lineTo(n,h-r)}),t.strokePath({lineWidth:r,color:this.pushed?i.BUTTON_DARKER:this.backgroundColor,path:new V(n+r,o+r).lineTo(a-r-r,o+r).moveTo(n+r,o+r).lineTo(n+r,h-r-r)});const l=this.text.split("\n");let d,c;if(e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),this.imageElement&&this.imageLoaded){const t=e.measureText(l[0]).width,i=this.font.height,r=this.imageElement.naturalHeight*s,o=this.imageElement.naturalWidth*s,n=(this.height-r)/i,h=5*s;if((this.width-o)/t>n){e.textBaseline="middle",e.textAlign="left",d=this.x+(this.width-t)/2+h,c=this.y+this.height/2;const i=this.x+(this.width-t)/2-o,s=this.y+(this.height-r)/2;e.drawImage(this.imageElement,i,s,o,r)}else{e.textAlign="center",e.textBaseline="top";const t=i+r;d=this.x+this.width/2,c=this.y+(this.height-t)/2+r;const s=this.x+(this.width-o)/2,n=this.y+(this.height-t)/2;e.drawImage(this.imageElement,s,n,o,r)}this.pushed&&(d+=1*s,c+=1*s),e.fillText(l[0],d,c)}else{e.textAlign="start",e.textBaseline="top";let t=0;for(const i of l){const s=e.measureText(i).width;t=Math.max(t,s)}d=this.x+(this.width-t)/2;const i=l.length*this.font.height+(l.length-1)*this.font.height*.2;c=this.y+(this.height-i)/2;for(const t of l){let i=d,r=c;this.pushed&&(i+=1*s,r+=1*s),e.fillText(t,i,r),c+=1.2*this.font.height}}}getHookedActions(){const{actions:t}=this;if(t.hookAllActionsToClick)return t.actions;if(this.pushed){const e=this.releaseActionIndex;return[t.getAction(e)]}{const e=this.pushActionIndex;return[t.getAction(e)]}}get font(){return this.properties.getValue(ki).scale(this.scale)}get image(){return this.properties.getValue(Bi)}get toggleButton(){return this.properties.getValue(Ei)}get pushActionIndex(){return this.properties.getValue(Mi)}get releaseActionIndex(){return this.properties.getValue(Ri)}get backgroundColor(){const t=this.properties.getProperty("background_color");return t&&t.value!==i.TRANSPARENT?t.value:i.BUTTON}}const Ii="data_type",Hi="effect_3d",Oi="font",Ni="off_color",Di="off_label",Fi="off_state",$i="on_color",ji="on_label",Gi="on_state",zi="push_action_index",Ui="released_action_index",qi="show_led",Yi="show_boolean_label",Xi="square_button",Ki="toggle_button";class Zi extends Pe{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new k("bit")),this.properties.add(new k(Ii)),this.properties.add(new R(Xi)),this.properties.add(new R(qi)),this.properties.add(new R(Hi)),this.properties.add(new E($i)),this.properties.add(new L(ji)),this.properties.add(new L(Gi)),this.properties.add(new E(Ni)),this.properties.add(new L(Di)),this.properties.add(new L(Fi)),this.properties.add(new B(Oi)),this.properties.add(new R(Ki)),this.properties.add(new k(zi)),this.properties.add(new k(Ui)),this.properties.add(new R(Yi))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:e?this.onLabel:this.offLabel})}drawSquare(t,e){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:i.DARK_GRAY});t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=2*this.scale,r=e?i.DARK_GRAY:i.WHITE,o=e?i.WHITE:i.DARK_GRAY;this.effect3d&&(t.fillPath({color:r,path:new V(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+s,this.y+this.height-s).lineTo(this.x+s,this.y+s).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width,this.y).closePath()}),t.fillPath({color:o,path:new V(this.x,this.y+this.height).lineTo(this.x+this.width,this.y+this.height).lineTo(this.x+this.width,this.y).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width-s,this.y+this.height-s).lineTo(this.x+s,this.y+this.height-s).closePath()}));let n=this.backgroundColor;this.hovered&&(n=this.backgroundColor.mixWith(i.WHITE,.5)),t.fillRect({x:this.x+s,y:this.y+s,width:this.width-s-s,height:this.height-s-s,color:n})}drawEllipse(t,e){const{scale:s}=this;if(this.effect3d){const r=this.width/2,o=this.height/2,n=Math.sqrt(r*r+o*o),h=this.x+r+(o-r-n)/2-1*s,a=this.y+o-(o-r+n)/2-1*s,l=this.x+r+(o-r+n)/2+5*s,d=this.y+o-(o-r-n)/2+5*s,c=t.createLinearGradient(h,a,l,d);e?(c.addColorStop(0,i.DARK_GRAY.toString()),c.addColorStop(1,i.WHITE.toString())):(c.addColorStop(0,i.WHITE.toString()),c.addColorStop(1,i.DARK_GRAY.toString())),t.ctx.fillStyle=c}else t.ctx.fillStyle=e?i.WHITE.toString():i.DARK_GRAY.toString();const r=this.x+this.width/2,o=this.y+this.height/2,n=this.width/2,h=this.height/2;t.ctx.beginPath(),t.ctx.ellipse(r,o,n,h,0,0,2*Math.PI),t.ctx.fill();t.addHitRegion(this.areaRegion).addEllipse(r,o,n,h,0,0,2*Math.PI),this.hovered?t.ctx.fillStyle=this.backgroundColor.mixWith(i.WHITE,.5).toString():t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,o,n-2*s,h-2*s,0,0,2*Math.PI),t.ctx.fill()}drawHorizontal(t,e){const{scale:i}=this;if(this.showLed){let s;this.squareButton?(s=Math.floor(.3*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-2*i)):(s=Math.floor(.25*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-8*i));const r={x:Math.floor(this.x+.79999*this.width-s/2),y:Math.floor(this.y+this.height/2-s/2),width:s,height:s},o=r.x+r.width/2,n=r.y+r.height/2,h=r.width/2,a=r.height/2,l=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:h,ry:a,color:l}),this.effect3d){const e=t.createLinearGradient(r.x,r.y,r.x+r.width,r.y+r.height);e.addColorStop(0,"white"),e.addColorStop(1,l.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,h,a,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}drawVertical(t,e){const{scale:s}=this;if(this.showLed){let r;this.squareButton?(r=Math.floor(.3*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-2*s)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*s));const o={x:Math.floor(this.x+this.width/2-r/2),y:Math.floor(this.y+(1-.79999)*this.height-r/2),width:r,height:r},n=e?this.onColor:this.offColor,h=o.x+o.width/2,a=o.y+o.height/2,l=o.width/2,d=o.height/2;if(t.fillEllipse({cx:h,cy:a,rx:l,ry:d,color:n}),this.effect3d){const e=t.createLinearGradient(o.x,o.y,o.x+o.width,o.y+o.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(h,a,l,d,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(Ii)}get toggleButton(){return this.properties.getValue(Ki)}get pushActionIndex(){return this.properties.getValue(zi)}get releaseActionIndex(){return this.properties.getValue(Ui)}get squareButton(){return this.properties.getValue(Xi)}get showLed(){return this.properties.getValue(qi)}get showBooleanLabel(){return this.properties.getValue(Yi)}get effect3d(){return this.properties.getValue(Hi)}get onColor(){return this.properties.getValue($i)}get onLabel(){return this.properties.getValue(ji)}get onState(){return this.properties.getValue(Gi)}get offColor(){return this.properties.getValue(Ni)}get offLabel(){return this.properties.getValue(Di)}get offState(){return this.properties.getValue(Fi)}get font(){return this.properties.getValue(Oi).scale(this.scale)}}const Ji="data_type",Qi="effect_3d",ts="off_color",es="off_label",is="off_state",ss="on_color",rs="on_label",os="on_state",ns="push_action_index",hs="released_action_index",as="toggle_button";class ls extends Pe{constructor(t,e){super(t,e),this.manualToggleState=!1,this.properties.add(new k("bit")),this.properties.add(new k(Ji)),this.properties.add(new R(Qi)),this.properties.add(new E(ss)),this.properties.add(new L(rs)),this.properties.add(new L(os)),this.properties.add(new E(ts)),this.properties.add(new L(es)),this.properties.add(new L(is)),this.properties.add(new k(ns)),this.properties.add(new k(hs)),this.properties.add(new R(as))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,s=this.height;s>i/2?s=Math.floor(this.width/2):i=Math.floor(2*this.height);const r={x:Math.floor(63/218*i),y:0,width:s/2,height:s/2};this.drawPedestal(t,r,e);const o=Math.floor(35/218*i),n=Math.floor(45/105*s),h=Math.floor(43/218*i),a=Math.floor(35/105*s),l=Math.floor(1/7*r.width);if(e){const e={x:2*r.x+r.width-o,y:r.height/2-n/2,width:o,height:n},i={x:r.x+r.width/2-h/2+l,y:r.y+r.height/2-a/2,width:h,height:a};this.drawHorizontalBar(t,i,e,!0)}else{const e={x:0,y:r.height/2-n/2,width:o,height:n},i={x:r.x+r.width/2-h/2-l,y:r.y+r.height/2-a/2,width:h,height:a};this.drawHorizontalBar(t,i,e,!1)}}drawVertical(t,e){let i=this.width,s=this.height;i>s/2?i=Math.floor(this.height/2):s=Math.floor(2*this.width);const r={x:0,y:Math.floor(63/218*s),width:i/2,height:i/2};this.drawPedestal(t,r,e);const o=Math.floor(45/105*i),n=Math.floor(35/218*s),h=Math.floor(35/105*i),a=Math.floor(43/218*s);if(e){const e={x:r.width/2-o/2,y:0,width:o,height:n},i={x:r.x+r.width/2-h/2,y:r.y+r.height/2-a/2,width:h,height:a};i.y-=Math.floor(1/7*r.height),this.drawVerticalBar(t,i,e,!0)}else{const e=r.y+r.height/2+a/2+2*this.scale,i={x:r.width/2-o/2,y:r.y+r.height/2-a/2+e-n,width:o,height:n},s={x:r.x+r.width/2-h/2,y:r.y+r.height/2-a/2,width:h,height:a};s.y+=Math.floor(1/7*r.height),this.drawVerticalBar(t,s,i,!1)}}drawPedestal(t,e,s){let r=this.x+e.x+e.width/2,o=this.y+e.y+e.height/2,n=e.width/2,h=e.height/2;if(t.ctx.fillStyle=this.effect3d?i.WHITE.toString():i.GRAY.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,o,n,h,0,0,2*Math.PI),t.ctx.fill(),this.effect3d){const i=t.createLinearGradient(this.x+e.x,this.y+e.y,this.x+e.x+e.width,this.y+e.y+e.height);s?(i.addColorStop(0,`rgba(255,255,255,${10/255})`),i.addColorStop(1,`rgba(0,0,0,${100/255})`)):(i.addColorStop(0,"rgba(0,0,0,0)"),i.addColorStop(1,`rgba(0,0,0,${150/255})`)),t.ctx.fillStyle=i,t.ctx.fill()}}drawHorizontalBar(t,e,i,s){let r=(s?0:10)/255,o=(s?150:220)/255;const n=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);n.addColorStop(0,`rgba(0,0,0,${r})`),n.addColorStop(1,`rgba(0,0,0,${o})`);const h=t.addHitRegion(this.shaftRegion);let a=this.x+e.x+e.width/2,l=this.y+e.y+e.height/2,d=e.width/2,c=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),h.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill());const p=[Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y),Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y+i.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y+e.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y)];if(t.ctx.beginPath(),t.ctx.moveTo(p[0],p[1]),t.ctx.lineTo(p[2],p[3]),t.ctx.lineTo(p[4],p[5]),t.ctx.lineTo(p[6],p[7]),t.ctx.closePath(),h.addPath(new V(p[0],p[1]).lineTo(p[2],p[3]).lineTo(p[4],p[5]).lineTo(p[6],p[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill()),a=this.x+i.x+i.width/2,l=this.y+i.y+i.height/2,d=i.width/2,c=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),h.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const{scale:e}=this,s=Math.sqrt(d*d+c*c),n=c-d,h=this.x+i.x+d+(n-s)/2-1*e,a=this.x+i.y+c-(n+s)/2-1*e,l=this.x+i.x+d+(n+s)/2+5*e,p=this.x+i.y+c-(n-s)/2+5*e,u=t.createLinearGradient(h,a,l,p);u.addColorStop(0,`rgba(0,0,0,${r})`),u.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=u,t.ctx.fill()}}drawVerticalBar(t,e,i,s){const r=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);r.addColorStop(0,`rgba(0,0,0,${10/255})`),r.addColorStop(1,`rgba(0,0,0,${s?210/255:160/255})`);const o=t.addHitRegion(this.shaftRegion);let n=this.x+e.x+e.width/2,h=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(n,h,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(n,h,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill());const a=[Math.round(this.x+i.x),Math.round(this.y+i.y+i.height/2),Math.round(this.x+i.x+i.width),Math.round(this.y+i.y+i.height/2),Math.round(this.x+e.x+e.width),Math.round(this.y+e.y+e.height/2),Math.round(this.x+e.x),Math.round(this.y+e.y+e.height/2)];t.ctx.beginPath(),t.ctx.moveTo(a[0],a[1]),t.ctx.lineTo(a[2],a[3]),t.ctx.lineTo(a[4],a[5]),t.ctx.lineTo(a[6],a[7]),t.ctx.closePath(),o.addPath(new V(a[0],a[1]).lineTo(a[2],a[3]).lineTo(a[4],a[5]).lineTo(a[6],a[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill()),n=this.x+i.x+i.width/2,h=this.y+i.y+i.height/2;const l=i.width/2,d=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,h,l,d,0,0,2*Math.PI),o.addEllipse(n,h,l,d,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const e=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);e.addColorStop(0,`rgba(0,0,0,${(s?5:10)/255})`),e.addColorStop(1,`rgba(0,0,0,${(s?180:160)/255})`),t.ctx.fillStyle=e,t.ctx.fill()}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(Ji)}get toggleButton(){return this.properties.getValue(as)}get pushActionIndex(){return this.properties.getValue(ns)}get releaseActionIndex(){return this.properties.getValue(hs)}get effect3d(){return this.properties.getValue(Qi)}get onColor(){return this.properties.getValue(ss)}get onLabel(){return this.properties.getValue(rs)}get onState(){return this.properties.getValue(os)}get offColor(){return this.properties.getValue(ts)}get offLabel(){return this.properties.getValue(es)}get offState(){return this.properties.getValue(is)}}const ds="enabled",cs="font",ps="label",us="selected_color",gs=new i(130,130,130),ms=new i(94,151,230);class fs extends Pe{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new k("bit")),this.properties.add(new R(ds)),this.properties.add(new B(cs)),this.properties.add(new L(ps)),this.properties.add(new E(us,new i(64,64,64)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseOut:()=>{this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:this.manualToggleState}draw(t){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const e=this.booleanValue,{boxSize:s,gap:r,scale:o}=this;let n=this.backgroundColor;this.hovered&&(n=n.mixWith(ms,.7));const h={x:this.x,y:this.y+this.height/2-s/2,width:s,height:s},a=t.createLinearGradient(h.x,h.y+1*o,h.x,h.y+h.height);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillRect(Object.assign(Object.assign({},h),{rx:2*o,ry:2*o,gradient:a})),t.strokeRect({x:h.x+.5*o,y:h.y+.5*o,width:h.width-1*o,height:h.height-1*o,rx:2*o,ry:2*o,color:gs}),e&&t.strokePath({lineWidth:3*o,color:this.selectedColor,path:new V(h.x+3*o,h.y+Math.floor(.45*s)).lineTo(h.x+Math.floor(.45*s),h.y+3*s/4-1*o).lineTo(h.x+s-2*o,h.y+3*o)}),this.enabled?t.fillText({x:h.x+h.width+r,y:h.y+h.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(t.fillText({x:h.x+h.width+r+1*o,y:h.y+h.height/2+1*o,align:"left",baseline:"middle",color:i.BUTTON_LIGHTEST,font:this.font,text:this.label}),t.fillText({x:h.x+h.width+r,y:h.y+h.height/2,align:"left",baseline:"middle",color:i.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return 16*this.scale}get gap(){return 4*this.scale}get bit(){return this.properties.getValue("bit")}get enabled(){return this.properties.getValue(ds)}get selectedColor(){return this.properties.getValue(us)}get font(){return this.properties.getValue(cs).scale(this.scale)}get label(){return this.properties.getValue(ps)}}const xs="enabled",ws="font",ys="horizontal",vs="items",bs="items_from_pv",Ts="selected_color";class Ss extends Pe{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new R(xs)),this.properties.add(new B(ws)),this.properties.add(new R(ys)),this.properties.add(new D(vs,[])),this.properties.add(new R(bs)),this.properties.add(new E(Ts))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",mouseDown:()=>{this.pushedItem=t,this.requestRepaint()},mouseOut:()=>{this.pushedItem=void 0,this.requestRepaint()},mouseUp:()=>{this.pushedItem=void 0,this.requestRepaint()},click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:Math.round(this.area.x),y:Math.round(i),width:Math.round(this.area.width),height:Math.round(e)};i+=e,this.drawButton(t,r,s)}}drawButton(t,e,s){var r;const o=(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s],n=o||s===this.pushedItem;t.fillRect(Object.assign(Object.assign({},e),{color:o?this.selectedColor:this.backgroundColor}));t.addHitRegion(this.itemRegions[s]).addRect(e.x,e.y,e.width,e.height);const h=1*this.scale,a=e.y+h/2,l=e.x+h/2,d=e.y+e.height-h+h/2,c=e.x+e.width-h+h/2;t.strokePath({lineWidth:h,color:n?i.BUTTON_LIGHTEST:i.BLACK,path:new V(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d)}),t.strokePath({lineWidth:h,color:n?this.backgroundColor:i.BUTTON_DARKER,path:new V(c-h,d-h).lineTo(c-h,a+h).moveTo(c-h,d-h).lineTo(l+h,d-h)}),t.strokePath({lineWidth:h,color:n?i.BLACK:i.BUTTON_LIGHTEST,path:new V(l,a).lineTo(c-h,a).moveTo(l,a).lineTo(l,d-h)}),t.strokePath({lineWidth:h,color:n?i.BUTTON_DARKER:this.backgroundColor,path:new V(l+h,a+h).lineTo(c-h-h,a+h).moveTo(l+h,a+h).lineTo(l+h,d-h-h)}),t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:this.items[s],align:"center",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get enabled(){return this.properties.getValue(xs)}get font(){return this.properties.getValue(ws).scale(this.scale)}get horizontal(){return this.properties.getValue(ys)}get items(){return this.properties.getValue(vs)}get itemsFromPV(){return this.properties.getValue(bs)}get selectedColor(){return this.properties.getValue(Ts)}}const Vs="enabled",Cs="font",_s="items",As="items_from_pv",Ls=new i(0,0,0,.1);class Ps extends Pe{constructor(t,e){super(t,e),this.properties.add(new R(Vs)),this.properties.add(new B(Cs)),this.properties.add(new D(_s,[])),this.properties.add(new R(As))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",(()=>{var t,e;this.writeValue(null!==(e=null===(t=this.selectEl)||void 0===t?void 0:t.value)&&void 0!==e?e:"")}));const t=document.createElement("option");t.disabled=!0,t.value="",t.defaultSelected=!0,t.text=" -- select an option -- ",this.selectEl.add(t);for(let t=0;t<this.items.length;t++){const e=document.createElement("option");e.value=this.items[t],e.text=this.items[t],this.selectEl.add(e)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){var e,i;let s=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${s.x}px`,this.selectEl.style.top=`${s.y}px`,this.selectEl.style.width=`${s.width}px`,this.selectEl.style.height=`${s.height}px`,s=p(this.bounds,2*this.scale),t.fillRect(Object.assign(Object.assign({},s),{color:this.backgroundColor})),t.strokeRect(Object.assign(Object.assign({},s),{color:Ls,crispen:!0}));if(t.addHitRegion(this.areaRegion).addRect(s.x,s.y,s.width,s.height),null===(e=this.pv)||void 0===e?void 0:e.value)for(const e of this.items){let r=e===this.pv.value;if(!r)try{r=parseFloat(e)===this.pv.value}catch(t){}r&&t.fillText({x:5*this.scale+s.x,y:s.y+s.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:null===(i=this.pv)||void 0===i?void 0:i.value})}const{selectorWidth:r}=this,o=Math.min(s.height,r/2),n={x:s.x+s.width-r-5*this.scale+r/2,y:s.y+(s.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new V(n.x,n.y).lineTo(n.x-o,n.y-o).lineTo(n.x+o,n.y-o).closePath()})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get selectorWidth(){return 8*this.scale}get enabled(){return this.properties.getValue(Vs)}get font(){return this.properties.getValue(Cs).scale(this.scale)}get items(){return this.properties.getValue(_s)}get itemsFromPV(){return this.properties.getValue(As)}}const ks="data_type",Ms="effect_3d",Rs="font",Es="off_image",Bs="off_label",Ws="off_state",Is="on_image",Hs="on_label",Os="on_state",Ns="push_action_index",Ds="released_action_index",Fs="show_boolean_label",$s="toggle_button";class js extends Pe{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.manualToggleState=!1,this.properties.add(new k("bit")),this.properties.add(new k(ks)),this.properties.add(new R(Ms)),this.properties.add(new L(Is)),this.properties.add(new L(Hs)),this.properties.add(new L(Os)),this.properties.add(new L(Es)),this.properties.add(new L(Bs)),this.properties.add(new L(Ws)),this.properties.add(new B(Rs)),this.properties.add(new R($s)),this.properties.add(new k(Ns)),this.properties.add(new k(Ds)),this.properties.add(new R(Fs))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage)),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=p(e,2*this.scale,2*this.scale));const i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height);t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(ks)}get toggleButton(){return this.properties.getValue($s)}get pushActionIndex(){return this.properties.getValue(Ns)}get releaseActionIndex(){return this.properties.getValue(Ds)}get showBooleanLabel(){return this.properties.getValue(Fs)}get effect3d(){return this.properties.getValue(Ms)}get onImage(){return this.properties.getValue(Is)}get onLabel(){return this.properties.getValue(Hs)}get onState(){return this.properties.getValue(Os)}get offImage(){return this.properties.getValue(Es)}get offLabel(){return this.properties.getValue(Bs)}get offState(){return this.properties.getValue(Ws)}get font(){return this.properties.getValue(Rs).scale(this.scale)}}const Gs="font",zs="label";class Us extends Pe{constructor(t,e){super(t,e),this.properties.add(new B(Gs)),this.properties.add(new L(zs))}init(){var t,e;this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip,cursor:"pointer"},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",(t=>{var e;const i=null===(e=this.selectEl)||void 0===e?void 0:e.value;if(i){this.selectEl.selectedIndex=0;const t=Number(i.substring(7));this.executeActionByIndex(t)}}));const i=document.createElement("option");i.disabled=!0,i.value="",i.defaultSelected=!0,i.text=" -- select an option -- ",this.selectEl.add(i);const s=this.actions.actions;for(let i=0;i<s.length;i++){const r=document.createElement("option");r.value=`action-${i}`,r.text=null!==(e=null===(t=s[i])||void 0===t?void 0:t.toString())&&void 0!==e?e:"",this.selectEl.add(r)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){const e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`;const i=t.ctx;t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=this.label.split("\n");i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),i.textBaseline="middle",i.textAlign="center";let r=this.x+this.width/2,o=this.y+this.height/2;i.fillText(s[0],r,o)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get font(){return this.properties.getValue(Gs).scale(this.scale)}get backgroundColor(){const t=this.properties.getProperty("background_color");return t&&t.value!==i.TRANSPARENT?t.value:i.BUTTON}get label(){return this.properties.getValue(zs)}}class qs extends Wi{}const Ys="enabled",Xs="font",Ks="horizontal",Zs="items",Js="items_from_pv",Qs="selected_color",tr=new i(120,120,120),er=new i(94,151,230);class ir extends Pe{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new R(Ys)),this.properties.add(new B(Xs)),this.properties.add(new R(Ks)),this.properties.add(new D(Zs,[])),this.properties.add(new R(Js)),this.properties.add(new E(Qs))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,r,s)}}drawRadio(t,e,s){var r;const{radioRadius:o,dotRadius:n,gap:h}=this;let a=this.backgroundColor;s===this.hoveredItem&&(a=a.mixWith(er,.7));const l=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);l.addColorStop(0,i.WHITE.toString()),l.addColorStop(1,a.toString()),t.fillEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:o,ry:o,gradient:l});const d=1*this.scale;t.strokeEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:o,ry:o,color:tr,lineWidth:d}),(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s]&&t.fillEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:n+d/2,ry:n+d/2,color:this.selectedColor});t.addHitRegion(this.itemRegions[s]).addRect(e.x,e.y,e.width,e.height),t.fillText({x:e.x+o+o+h,y:e.y+e.height/2,text:this.items[s],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get radioRadius(){return 7*this.scale}get dotRadius(){return 2*this.scale}get gap(){return 4*this.scale}get enabled(){return this.properties.getValue(Ys)}get font(){return this.properties.getValue(Xs).scale(this.scale)}get horizontal(){return this.properties.getValue(Ks)}get items(){return this.properties.getValue(Zs)}get itemsFromPV(){return this.properties.getValue(Js)}get selectedColor(){return this.properties.getValue(Qs)}}const sr="enabled",rr="font",or="maximum",nr="minimum",hr="horizontal",ar="step_increment",lr="page_increment",dr="bar_length",cr="show_value_tip",pr=new i(243,243,243),ur=new i(232,232,231),gr=150;class mr extends Pe{constructor(t,e){super(t,e),this.decreasePressed=!1,this.increasePressed=!1,this.pageDecreasePressed=!1,this.pageIncreasePressed=!1,this.properties.add(new R(sr)),this.properties.add(new R(hr)),this.properties.add(new R(cr)),this.properties.add(new B(rr)),this.properties.add(new M(or)),this.properties.add(new M(nr)),this.properties.add(new M(ar)),this.properties.add(new M(lr)),this.properties.add(new M(dr))}init(){this.decreaseRegion={id:`${this.wuid}-decrease`,mouseDown:()=>{this.decreasePressed=!0,this.stepDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.increaseRegion={id:`${this.wuid}-increase`,mouseDown:()=>{this.increasePressed=!0,this.stepIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{this.grabStartValue=this.getCoercedValue()},grab:t=>{const e=this.horizontal?t.dx:t.dy,i=(this.maximum-this.minimum)*e/this.dragRange;this.setCoercedValue(this.grabStartValue+i),this.requestRepaint()},tooltip:()=>this.tooltip},this.pageDecreaseRegion={id:`${this.wuid}-page-decrease`,mouseDown:()=>{this.pageDecreasePressed=!0,this.pageDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.pageIncreaseRegion={id:`${this.wuid}-page-increase`,mouseDown:()=>{this.pageIncreasePressed=!0,this.pageIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip}}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const{scale:e}=this,s=p(this.bounds,2*e);t.fillRect(Object.assign(Object.assign({},s),{color:pr}));const r=Math.min(s.height,s.width/2);this.drawLeftButton(t,{x:s.x,y:s.y,width:r,height:s.height}),this.drawRightButton(t,{x:s.x+s.width-r,y:s.y,width:r,height:s.height});const o=this.barLength,n=this.maximum+o,h=this.minimum,a=n-h,l=a-o,d=s.width-r-r,c=Math.floor(Math.max(6*e,d*o/a));this.dragRange=d-c;const u=this.getCoercedValue(),g=Math.floor((d-c)*(u-h)/l),m=d-g-c,f={x:s.x+r+g,y:s.y,width:c,height:s.height};t.fillRect(Object.assign(Object.assign({},f),{color:ur})),this.drawRaisedButtonBorder(t,f);t.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x+r,y:s.y,width:g,height:s.height};t.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&t.fillRect(Object.assign(Object.assign({},x),{color:i.BLACK}));const w={x:s.x+r+g+c,y:s.y,width:m,height:s.height};t.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&t.fillRect(Object.assign(Object.assign({},w),{color:i.BLACK}))}drawVertical(t){const{scale:e}=this,s=p(this.bounds,e);t.fillRect(Object.assign(Object.assign({},s),{color:pr}));const r=Math.min(s.width,s.height/2);this.drawUpButton(t,{x:s.x,y:s.y,width:s.width,height:r}),this.drawDownButton(t,{x:s.x,y:s.y+s.height-r,width:s.width,height:r});const o=this.barLength,n=this.maximum+o,h=this.minimum,a=n-h,l=a-o,d=s.height-r-r,c=Math.floor(Math.max(6*e,d*o/a));this.dragRange=d-c;const u=this.getCoercedValue(),g=Math.floor((d-c)*(u-h)/l),m=d-g-c,f={x:s.x,y:s.y+r+g,width:s.width,height:c};t.fillRect(Object.assign(Object.assign({},f),{color:ur})),this.drawRaisedButtonBorder(t,f);t.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x,y:s.y+r,width:s.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&t.fillRect(Object.assign(Object.assign({},x),{color:i.BLACK}));const w={x:s.x,y:s.y+r+g+c,width:s.width,height:m};t.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&t.fillRect(Object.assign(Object.assign({},w),{color:i.BLACK}))}drawLeftButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:ur})),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x,y:s.y+s.height/2};t.fillPath({color:i.BLACK,path:new V(o.x,o.y).lineTo(o.x+r,o.y-r).lineTo(o.x+r,o.y+r).closePath()})}drawRightButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:ur})),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x+r,y:s.y+s.height/2};t.fillPath({color:i.BLACK,path:new V(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x-r,o.y+r).closePath()})}drawUpButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:ur})),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y};t.fillPath({color:i.BLACK,path:new V(o.x,o.y).lineTo(o.x-r,o.y+r).lineTo(o.x+r,o.y+r).closePath()})}drawDownButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:ur})),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y+r};t.fillPath({color:i.BLACK,path:new V(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x+r,o.y-r).closePath()})}drawRaisedButtonBorder(t,e){this.drawButtonBorder(t,e,i.BUTTON_DARKEST,i.BUTTON_DARKER,i.BUTTON,i.BUTTON_LIGHTEST)}drawPressedButtonBorder(t,e){this.drawButtonBorder(t,e,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKEST,i.BUTTON_DARKER)}drawButtonBorder(t,e,i,s,r,o){const n=1*this.scale,h=e.y+n/2,a=e.x+n/2,l=e.y+e.height-n+n/2,d=e.x+e.width-n+n/2;t.strokePath({color:i,path:new V(d,l).lineTo(d,h).moveTo(d,l).lineTo(a,l)}),t.strokePath({color:s,path:new V(d-n,l-n).lineTo(d-n,h+n).moveTo(d-n,l-n).lineTo(a+n,l-n)}),t.strokePath({color:r,path:new V(a,h).lineTo(d-n,h).moveTo(a,h).lineTo(a,l-n)}),t.strokePath({color:o,path:new V(a+n,h+n).lineTo(d-n-n,h+n).moveTo(a+n,h+n).lineTo(a+n,l-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepIncreaseRepeatedly()),gr)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepDecreaseRepeatedly()),gr)}stepIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.stepIncrement)}stepDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageIncreaseRepeatedly()),gr)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageDecreaseRepeatedly()),gr)}pageIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.pageIncrement)}pageDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.pageIncrement)}setCoercedValue(t){this.pv&&this.pv.writable&&(t=t<this.minimum?this.minimum:t>this.maximum?this.maximum:t,this.display.pvEngine.setValue(new Date,this.pv.name,t))}getCoercedValue(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;return i<this.minimum?this.minimum:i>this.maximum?this.maximum:i}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue(sr)}get horizontal(){return this.properties.getValue(hr)}get showValueTip(){return this.properties.getValue(cr)}get font(){return this.properties.getValue(rr).scale(this.scale)}get minimum(){return this.properties.getValue(nr)}get maximum(){return this.properties.getValue(or)}get stepIncrement(){return this.properties.getValue(ar)}get pageIncrement(){return this.properties.getValue(lr)}get barLength(){return this.properties.getValue(dr)}}const fr="confirm_message",xr="font",wr="format_type",yr="horizontal_alignment",vr="multiline_input",br="password_input",Tr="precision",Sr="precision_from_pv",Vr="show_units",Cr="vertical_alignment";class _r extends Pe{constructor(t,e){super(t,e),this.editing=!1,this.properties.add(new L(fr)),this.properties.add(new B(xr)),this.properties.add(new k(wr)),this.properties.add(new k(yr)),this.properties.add(new R(vr)),this.properties.add(new R(br,!1)),this.properties.add(new k(Tr)),this.properties.add(new R(Sr)),this.properties.add(new R(Vr,!0)),this.properties.add(new k(Cr,1))}init(){this.text&&(this.value=this.text),this.areaRegion={id:`${this.wuid}-area`,click:()=>{var t,e,i;if(this.pv&&!this.pv.writable)return;this.editing=!0;const s=this.display.measureAbsoluteArea(this);if(s.x-=2*this.scale,s.y-=2*this.scale,s.width+=2*this.scale,s.height+=2*this.scale,this.inputEl.value=null!==(i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.value)&&void 0!==i?i:"",this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${s.x}px`,this.inputEl.style.top=`${s.y}px`,this.inputEl.style.width=`${s.width}px`,this.inputEl.style.height=`${s.height}px`,this.inputEl.autocomplete="off",this.multilineInput){this.inputEl.style.resize="none"}else{const t=this.inputEl;this.passwordInput&&(t.type="password")}this.inputEl.focus(),this.inputEl.select()},tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement(this.multilineInput?"textarea":"input"),this.inputEl.style.display="none",this.inputEl.addEventListener("keyup",(t=>{var e;if("Enter"===t.key){if(!this.multilineInput||t.ctrlKey){const t=(null===(e=this.inputEl)||void 0===e?void 0:e.value)||"";!this.confirmMessage||confirm(this.confirmMessage)?(this.value=t,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,t),this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()):this.cancelInput()}}else"Escape"===t.key&&this.cancelInput()})),this.inputEl.addEventListener("blur",(t=>{this.cancelInput()})),this.display.rootPanel.appendChild(this.inputEl)}cancelInput(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){var e,i;if(this.editing)return;t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=t.ctx;this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const r=document.createElement("canvas");r.width=this.area.width,r.height=this.area.height;const o=r.getContext("2d");o.fillStyle=this.alarmSensitiveForegroundColor.toString(),o.font=this.font.getFontString();let n=this.x;0===this.horizAlignment?o.textAlign="start":1===this.horizAlignment?(n+=this.width/2,o.textAlign="center"):2===this.horizAlignment&&(n+=this.width,o.textAlign="end");let h=this.y;0===this.vertAlignment?o.textBaseline="top":1===this.vertAlignment?(h+=this.height/2,o.textBaseline="middle"):2===this.vertAlignment&&(h+=this.height,o.textBaseline="bottom");let a=this.text;if(this.pv&&void 0!==this.pv.value){let t=this.precisionFromPV?this.pv.precision:this.precision;-1===t&&(t=null!==(e=this.pv.precision)&&void 0!==e?e:-1),a=T(this.pv.value,this.formatType,t),this.showUnits&&(null===(i=this.pv)||void 0===i?void 0:i.units)&&(a+=" "+this.pv.units)}o.fillText(a,n-this.area.x,h-this.area.y),s.drawImage(r,this.area.x,this.area.y)}hide(){this.editing=!1,this.inputEl&&(this.inputEl.style.display="none")}destroy(){this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0)}get value(){return this.text}set value(t){this.properties.setValue("text",t),this.requestRepaint()}get confirmMessage(){return this.properties.getValue(fr)}get font(){return this.properties.getValue(xr).scale(this.scale)}get formatType(){return this.properties.getValue(wr)}get horizAlignment(){return this.properties.getValue(yr)}get multilineInput(){return this.properties.getValue(vr)}get passwordInput(){return this.properties.getValue(br)}get precision(){return this.properties.getValue(Tr)}get precisionFromPV(){return this.properties.getValue(Sr)}get showUnits(){return this.properties.getValue(Vr)}get vertAlignment(){return this.properties.getValue(Cr)}}const Ar="alpha",Lr="fill",Pr="line_width",kr="line_style",Mr="start_angle",Rr="total_angle";class Er extends Pe{constructor(t,e){super(t,e),this.properties.add(new k(Ar,255)),this.properties.add(new k(Pr)),this.properties.add(new k(Mr)),this.properties.add(new k(Rr)),this.properties.add(new R(Lr)),this.properties.add(new k(kr))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2,o=-f(this.startAngle),n=-f(this.totalAngle+this.startAngle);if(this.fill&&(t.ctx.fillStyle=this.alarmSensitiveBackgroundColor.toString(),t.ctx.beginPath(),t.ctx.moveTo(e,i),t.ctx.ellipse(e,i,s,r,0,o,n,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&0!==this.totalAngle){let h;const{scale:a}=this;0===this.lineStyle?h=[]:1===this.lineStyle?h=[6*a,2*a]:2===this.lineStyle?h=[2*a,2*a]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,startAngle:o,endAngle:n,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:h})}}get alpha(){return this.properties.getValue(Ar)}get lineWidth(){return this.scale*this.properties.getValue(Pr)}get lineStyle(){return this.properties.getValue(kr)}get startAngle(){return this.properties.getValue(Mr)}get totalAngle(){return this.properties.getValue(Rr)}get fill(){return this.properties.getValue(Lr)}}const Br="alpha",Wr="bg_gradient_color",Ir="fg_gradient_color",Hr="fill_level",Or="gradient",Nr="horizontal_fill",Dr="line_color",Fr="line_width",$r="line_style";class jr extends Pe{constructor(t,e){super(t,e),this.properties.add(new k(Br,255)),this.properties.add(new E(Wr)),this.properties.add(new E(Ir)),this.properties.add(new R(Or)),this.properties.add(new k(Fr)),this.properties.add(new M(Hr)),this.properties.add(new R(Nr)),this.properties.add(new E(Dr)),this.properties.add(new k($r))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2;if(!this.transparent){const o=this.alarmSensitiveBackgroundColor;if(this.gradient){const n=this.horizontalFill?this.x:this.x+this.width,h=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,n,h);a.addColorStop(0,this.backgroundGradientStartColor.toString()),a.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:s,ry:r,gradient:a})}else t.fillEllipse({cx:e,cy:i,rx:s,ry:r,color:o})}this.lineWidth&&(0===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth}):1===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`))}drawFill(t){const e=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.x+this.width/2,s=this.y+this.height/2,r=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,n=this.alarmSensitiveForegroundColor;if(this.gradient){const e=this.horizontalFill?this.x:this.x+this.width,h=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,e,h);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,gradient:a})}else t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(Br)}get lineWidth(){return this.scale*this.properties.getValue(Fr)}get fillLevel(){return this.properties.getValue(Hr)}get horizontalFill(){return this.properties.getValue(Nr)}get lineColor(){return this.properties.getValue(Dr)}get lineStyle(){return this.properties.getValue($r)}get gradient(){return this.properties.getValue(Or)}get backgroundGradientStartColor(){return this.properties.getValue(Wr)}get foregroundGradientStartColor(){return this.properties.getValue(Ir)}}const Gr="image_file",zr="no_animation",Ur="transparency";class qr extends Pe{constructor(t,e){super(t,e),this.imageLoading=!1,this.imageLoaded=!1,this.properties.add(new L(Gr)),this.properties.add(new L(zr)),this.properties.add(new R(Ur,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoading&&this.imageSnapshot?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile&&(this.currentImageFile=this.imageFile,this.imageElement.src=this.resolvePath(this.imageFile))}snapshotImage(t){const e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue(Ur)}get imageFile(){return this.properties.getValue(Gr)}get noAnimation(){return this.properties.getValue(zr)}}const Yr="font",Xr="horizontal_alignment",Kr="vertical_alignment",Zr="wrap_words";class Jr extends Pe{constructor(t,e){super(t,e),this.properties.add(new B(Yr)),this.properties.add(new k(Xr)),this.properties.add(new k(Kr)),this.properties.add(new R(Zr))}draw(t){const e=t.ctx;this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const i=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let s=0;for(const t of i){const i=e.measureText(t).width;s=Math.max(s,i)}let r=this.x;1===this.horizAlignment?r=this.x+(this.width-s)/2:2===this.horizAlignment&&(r=this.x+(this.width-s));const o=i.length*this.font.height+(i.length-1)*this.font.height*.2;let n=this.y;1===this.vertAlignment?n+=(this.height-o)/2:2===this.vertAlignment&&(n+=this.height-o);for(const t of i)e.fillText(t,r,n),n+=1.2*this.font.height}wrapText(t,e,i){let s=[];for(const r of e.split("\n"))s=s.concat(this.wrapLine(t,r,i));return s}wrapLine(t,e,i){if(!e)return[""];const s=[];let r,o,n,h=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(r=e.substr(0,o),o!==e.length)for(n=0;-1!==r.indexOf(" ",n);n=r.indexOf(" ",n)+1);s.push(r.substr(0,n||r.length)),h=Math.max(h,t.measureText(s[s.length-1],this.font).width),e=e.substr(s[s.length-1].length,e.length)}return s}get font(){return this.properties.getValue(Yr).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Xr)}get vertAlignment(){return this.properties.getValue(Kr)}get wrapWords(){return this.properties.getValue(Zr)}}const Qr="alpha",to="fill_level",eo="horizontal_fill",io="line_color",so="line_style",ro="line_width",oo="points";class no extends Pe{constructor(t,e){super(t,e),this.properties.add(new k(Qr,255)),this.properties.add(new k(ro)),this.properties.add(new M(to)),this.properties.add(new R(eo)),this.properties.add(new E(io)),this.properties.add(new k(so)),this.properties.add(new I(oo,[]))}init(){this.addPropertyListener("x",((t,e)=>{const i=m(this.properties.getValue(oo),t-e,0);this.properties.setValue(oo,i),this.requestRepaint()})),this.addPropertyListener("y",((t,e)=>{const i=m(this.properties.getValue(oo),0,t-e);this.properties.setValue(oo,i),this.requestRepaint()}))}draw(t){const{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;const i=V.fromPoints(this.points).closePath();if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:e})}this.lineWidth&&(0===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):2===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor,dash:[6*e,2*e]}):console.warn(`Unsupported polygon line style ${this.lineStyle}`)),this.fillLevel&&this.drawFill(t,i),t.ctx.globalAlpha=1}drawFill(t,e){let i=this.y,s=this.width,r=this.height;this.horizontalFill?s*=this.fillLevel/100:(r*=this.fillLevel/100,i+=r),t.ctx.save();let o=this.x-this.lineWidth/2,n=i-this.lineWidth/2,h=s+this.lineWidth,a=r+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,n,h,a),t.ctx.clip();const l=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:l}),t.ctx.restore()}get alpha(){return this.properties.getValue(Qr)}get lineWidth(){return this.scale*this.properties.getValue(ro)}get fillLevel(){return this.properties.getValue(to)}get horizontalFill(){return this.properties.getValue(eo)}get lineColor(){return this.properties.getValue(io)}get lineStyle(){return this.properties.getValue(so)}get points(){return v(this.properties.getValue(oo),this.scale)}}const ho="alpha",ao="arrows",lo="arrow_length",co="fill_arrow",po="fill_level",uo="horizontal_fill",go="line_width",mo="points";class fo extends Pe{constructor(t,e){super(t,e),this.properties.add(new k(ho,255)),this.properties.add(new k(go)),this.properties.add(new M(po)),this.properties.add(new R(uo)),this.properties.add(new I(mo,[])),this.properties.add(new k(lo)),this.properties.add(new R(co)),this.properties.add(new k(ao))}draw(t){const e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,s=this.height;this.horizontalFill?i*=this.fillLevel/100:(s*=this.fillLevel/100,e+=s),t.save();let r=this.x-this.lineWidth/2,o=e-this.lineWidth/2,n=i+this.lineWidth,h=s+this.lineWidth;t.beginPath(),t.rect(r,o,n,h),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let e=0;e<this.points.length;e++)0===e?t.moveTo(this.points[e].x,this.points[e].y):t.lineTo(this.points[e].x,this.points[e].y);if(t.stroke(),this.points.length>=2){const i=this.points[0],s=this.points[this.points.length-1];if(2===this.arrows||3===this.arrows){const i=this.calculateArrowPoints(this.points[this.points.length-2],s);if(i[2]=s,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<i.length;e++)0===e?t.moveTo(i[e].x,i[e].y):t.lineTo(i[e].x,i[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(i[0].x,i[0].y),t.moveTo(s.x,s.y),t.lineTo(i[1].x,i[1].y),t.stroke()}if(1===this.arrows||3===this.arrows){const s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<s.length;e++)0===e?t.moveTo(s[e].x,s[e].y):t.lineTo(s[e].x,s[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){const i=w(e,t),s=Math.PI/10,r=new y(this.arrowLength,i.theta-s),o=new y(this.arrowLength,i.theta+s),n=new y(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[g(r.toPoint(),e.x,e.y),g(o.toPoint(),e.x,e.y),g(n.toPoint(),e.x,e.y)]}get alpha(){return this.properties.getValue(ho)}get lineWidth(){return this.scale*this.properties.getValue(go)}get fillLevel(){return this.properties.getValue(po)}get horizontalFill(){return this.properties.getValue(uo)}get points(){return v(this.properties.getValue(mo),this.scale)}get arrows(){return this.properties.getValue(ao)}get fillArrow(){return this.properties.getValue(co)}get arrowLength(){return this.properties.getValue(lo)}}const xo="alpha",wo="bg_gradient_color",yo="fg_gradient_color",vo="fill_level",bo="gradient",To="horizontal_fill",So="line_color",Vo="line_width",Co="line_style";class _o extends Pe{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new k(xo,255)),this.properties.add(new E(wo)),this.properties.add(new E(yo)),this.properties.add(new R(bo)),this.properties.add(new k(Vo)),this.properties.add(new M(vo)),this.properties.add(new R(To)),this.properties.add(new E(So)),this.properties.add(new k(Co))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported rectangle line style ${this.lineStyle}`))}drawFill(t){const e=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.alarmSensitiveForegroundColor;if(this.gradient){const s=this.horizontalFill?e.x:e.x+e.width,r=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,s,r);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect(Object.assign(Object.assign({},e),{gradient:o}))}else t.fillRect(Object.assign(Object.assign({},e),{color:i}));t.ctx.restore()}get alpha(){return this.properties.getValue(xo)}get lineWidth(){return this.scale*this.properties.getValue(Vo)}get fillLevel(){return this.properties.getValue(vo)}get horizontalFill(){return this.properties.getValue(To)}get lineColor(){return this.properties.getValue(So)}get lineStyle(){return this.properties.getValue(Co)}get gradient(){return this.properties.getValue(bo)}get backgroundGradientStartColor(){return this.properties.getValue(wo)}get foregroundGradientStartColor(){return this.properties.getValue(yo)}}const Ao="alpha",Lo="bg_gradient_color",Po="corner_width",ko="corner_height",Mo="fg_gradient_color",Ro="fill_level",Eo="gradient",Bo="horizontal_fill",Wo="line_color",Io="line_width",Ho="line_style";class Oo extends Pe{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new k(Ao,255)),this.properties.add(new E(Lo)),this.properties.add(new E(Mo)),this.properties.add(new R(Eo)),this.properties.add(new k(Io)),this.properties.add(new M(Ro)),this.properties.add(new R(Bo)),this.properties.add(new E(Wo)),this.properties.add(new k(Po)),this.properties.add(new k(ko)),this.properties.add(new k(Ho))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported RoundedRectangle line style ${this.lineStyle}`))}drawFill(t){const e=this.cornerWidth/2,i=this.cornerHeight/2,s=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const e=s.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(s.x,s.y,e,s.height)}else{const e=s.height*(this.fillLevel/100),i=s.y+s.height-e;t.ctx.beginPath(),t.ctx.rect(s.x,i,s.width,s.height)}t.ctx.clip();const r=this.alarmSensitiveForegroundColor;if(this.gradient){const o=this.horizontalFill?s.x:s.x+s.width,n=this.horizontalFill?s.y+s.height:s.y,h=t.createLinearGradient(s.x,s.y,o,n);h.addColorStop(0,this.foregroundGradientStartColor.toString()),h.addColorStop(1,r.toString()),t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,gradient:h}))}else t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,color:r}));t.ctx.restore()}get alpha(){return this.properties.getValue(Ao)}get lineWidth(){return this.scale*this.properties.getValue(Io)}get fillLevel(){return this.properties.getValue(Ro)}get horizontalFill(){return this.properties.getValue(Bo)}get lineColor(){return this.properties.getValue(Wo)}get lineStyle(){return this.properties.getValue(Ho)}get gradient(){return this.properties.getValue(Eo)}get cornerWidth(){return this.scale*this.properties.getValue(Po)}get cornerHeight(){return this.scale*this.properties.getValue(ko)}get backgroundGradientStartColor(){return this.properties.getValue(Lo)}get foregroundGradientStartColor(){return this.properties.getValue(Mo)}}const No="bitReverse",Do="effect_3d",Fo="horizontal",$o="led_border",jo="led_border_color",Go="led_packed",zo="numBits",Uo="off_color",qo="on_color",Yo="startBit",Xo="square_led";class Ko extends Pe{constructor(t,e){super(t,e),this.properties.add(new R(No)),this.properties.add(new R(Do)),this.properties.add(new R(Fo)),this.properties.add(new k(zo)),this.properties.add(new E(Uo)),this.properties.add(new E(qo)),this.properties.add(new k(Yo)),this.properties.add(new R(Xo)),this.properties.add(new k($o,3)),this.properties.add(new E(jo,i.DARK_GRAY)),this.properties.add(new R(Go,!1))}getLedColor(t){var e,i;let s=!1;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value))for(let e=this.startBit;e<this.startBit+this.numBits;e++){let r=0;if(r=this.bitReverse?e-this.startBit:this.numBits-1-(e-this.startBit),r===t){s=((null===(i=this.pv)||void 0===i?void 0:i.value)>>e&1)>0;break}}return s?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=p(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,s;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),s=i);let r=0;r=i>e.height||this.squareLed?e.height:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const n={x:e.x+o*s,y:e.y,width:i,height:r};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{const n=Math.min(i,r),h={x:e.x+o*s,y:e.y,width:n,height:n};this.effect3d?this.drawCircle3d(t,h,o):this.drawCircle2d(t,h,o)}}drawVertical(t,e){let i,s;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),s=i);let r=0;r=i>e.width||this.squareLed?e.width:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const n={x:e.x,y:e.y+o*s,width:r,height:i};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{const n=Math.min(r,i),h={x:e.x,y:e.y+o*s,width:n,height:n};this.effect3d?this.drawCircle3d(t,h,o):this.drawCircle2d(t,h,o)}}drawCircle2d(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,n=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,n-=this.ledBorder/2),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:this.getLedColor(i)}),t.strokeEllipse({cx:s,cy:r,rx:o,ry:n,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(t,e,s){const r=e.x+e.width/2,o=e.y+e.height/2;let n=e.width/2,h=e.height/2;t.fillEllipse({cx:r,cy:o,rx:n,ry:h,color:i.WHITE});let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:o,rx:n,ry:h,gradient:a});n=(e.width-2*this.ledBorder)/2,h=(e.height-2*this.ledBorder)/2,t.fillEllipse({cx:r,cy:o,rx:n,ry:h,color:this.getLedColor(s)}),a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:o,rx:n,ry:h,gradient:a})}drawSquare2d(t,e,i){const s=d(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect(Object.assign(Object.assign({},s),{color:this.getLedColor(i)})),t.strokeRect(Object.assign(Object.assign({},s),{color:this.ledBorderColor,lineWidth:this.ledBorder}))}drawSquare3d(t,e,i){t.fillRect(Object.assign(Object.assign({},e),{color:this.ledBorderColor}));let s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new V(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new V(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width,e.y)}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new V(e.x+e.width,e.y).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new V(e.x,e.y+e.height).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)});const r=e.x+this.ledBorder,o=e.y+this.ledBorder,n=e.width-2*this.ledBorder,h=e.height-2*this.ledBorder,a=this.getLedColor(i);t.fillRect({x:r,y:o,width:n,height:h,color:a}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.784)"),s.addColorStop(1,a.withAlpha(0).toString()),t.fillRect({x:r,y:o,width:n,height:h,gradient:s})}get bitReverse(){return this.properties.getValue(No)}get horizontal(){return this.properties.getValue(Fo)}get numBits(){return this.properties.getValue(zo)}get startBit(){return this.properties.getValue(Yo)}get ledPacked(){return this.properties.getValue(Go)}get ledBorder(){return this.scale*this.properties.getValue($o)}get ledBorderColor(){return this.properties.getValue(jo)}get offColor(){return this.properties.getValue(Uo)}get onColor(){return this.properties.getValue(qo)}get effect3d(){return this.properties.getValue(Do)}get squareLed(){return this.properties.getValue(Xo)}}class Zo{constructor(t){this.prefix="",this.suffix="",this.comma=0,this.minInt=1,this.minFrac=0,this.maxFrac=0;for(let e=0;e<t.length;e++)if("#"==t.charAt(e)||"0"==t.charAt(e)){this.prefix=t.substring(0,e),t=t.substring(e);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");const e=t.replace(/[^0#,.]/g,"");let i="",s="";const r=e.indexOf(".");-1!==r?(i=e.substring(0,r),s=e.substring(r+1)):i=e;const o=i.lastIndexOf(",");-1!==o&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),s=s.replace(/[,]|[.]+/g,""),this.maxFrac=s.length;let n=i.replace(/[^0]/g,"");n.length>this.minInt&&(this.minInt=n.length),n=s.replace(/[^0]/g,""),this.minFrac=n.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||0==e.length)return t;if(-1!=e.indexOf("e")){const t=Number(e);if(t===1/0||t===-1/0)return e;if(e=t+"",-1!==e.indexOf("e"))return e}let i=!1;"-"===e.charAt(0)?(i=!0,e=e.substring(1)):"+"===e.charAt(0)&&(e=e.substring(1));const s=e.indexOf(".");let r="",o="";-1!=s?(r=e.substring(0,s),o=e.substring(s+1)):r=e,o=o.replace(/[.]/,"");const n=this.suffix&&"%"===this.suffix.charAt(0);let h=this.minInt,a=this.minFrac,l=this.maxFrac;if(n&&(h-=2,a+=2,l+=2),o.length>l){let t=Number("0."+o);t=0==l?Math.round(t):t.toFixed(l),o=t.toString(10).substr(2);let e,i=t>=1?1:0,s=r.length-1;for(;i;){if(-1==s){r="1"+r;break}e=Number(r.charAt(s)),9===e?(e="0",i=1):(e=++e+"",i=0),r=r.substring(0,s)+e+r.substring(s+1,r.length),s--}}for(let t=o.length;t<a;t++)o+="0";for(;o.length>a&&"0"==o.charAt(o.length-1);)o=o.substring(0,o.length-1);for(let t=r.length;t<h;t++)r="0"+r;for(;r.length>h&&"0"==r.charAt(0);)r=r.substring(1);n&&(r+=o.substring(0,2),o=o.substring(2));let d,c=0;for(let t=r.length;t>0;t--)0!=c&&c%this.comma==0&&(r=r.substring(0,t)+","+r.substring(t),c=0),c++;return d=o.length>0?this.prefix+r+"."+o+this.suffix:this.prefix+r+this.suffix,i&&(d="-"+d),d}formatBack(t){if(!(t+=""))return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;"-"===t.charAt(0)&&(e=e.substr(1),i=!0);const s=e.indexOf(this.prefix),r=""==this.suffix?e.length:e.indexOf(this.suffix,this.prefix.length+1);return 0==s&&r>0&&(e=e.substr(0,r),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){const e=Number(t)+"";if(t.indexOf(".")>-1&&e.indexOf(".")<0){for(var i=t.indexOf(".")+1;i<t.length;i++)if("0"!==t.charAt(i))return t;return e}return t}}class Jo{constructor(t,e,s){this.rampWidth=t,this.startAngle=e,this.endAngle=s,this.lolo=10,this.loloColor=i.RED,this.showLoLo=!0,this.lo=25,this.loColor=i.ORANGE,this.showLo=!0,this.hi=75,this.hiColor=i.ORANGE,this.showHi=!0,this.hihi=90,this.hihiColor=i.RED,this.showHiHi=!0,this.minimum=0,this.maximum=100,this.gradient=!0,this.logScale=!1,this.effect3d=!0,this.labelsOutside=!0,this.range={min:this.minimum,max:this.maximum},this.lengthInDegrees=0,this.radius=0}draw(t,e,i){if(this.labelsOutside){const t=9;this.radius=e.width/2-t}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(t,e){const s=e.x+e.width/2,r=e.y+e.height/2,o=e.width/2,n=e.height/2;let h,a=360-this.endAngle;if(h=this.endAngle-this.startAngle>0?this.startAngle-90:this.startAngle+90,this.showLoLo){let e=h,i=360-this.getValuePosition(this.lolo,!0);t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(e),endAngle:f(i),color:this.loloColor})}if(this.showLo){let i;i=this.showLoLo?this.lolo:this.minimum;const h=360-this.getValuePosition(i,!0),a=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){const l=f(this.getValuePosition(i,!0)-2),d=x(e.width/2,l,e),c=f(this.getValuePosition(this.lo,!0)+2),p=x(e.width/2,c,e),u=t.createLinearGradient(d.x,d.y,p.x,p.y);u.addColorStop(0,this.loloColor.toString()),u.addColorStop(1,this.loColor.toString()),t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h-1),endAngle:f(a+1),gradient:u})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h),endAngle:f(a),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let d=this.maximum;this.showHi?d=this.hi:this.showHiHi&&(d=this.hihi);const c=(l+d)/2;let p=360-this.getValuePosition(l,!0),u=360-this.getValuePosition(c,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){const h=f(this.getValuePosition(l,!0)-2),a=x(e.width/2,h,e),d=f(this.getValuePosition(c,!0)+2),g=x(e.width/2,d,e),m=t.createLinearGradient(a.x,a.y,g.x,g.y);m.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),m.addColorStop(1,i.GREEN.toString()),t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-1),endAngle:f(u+1),gradient:m})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p),endAngle:f(u),color:i.GREEN});if(p=360-this.getValuePosition(c,!0),u=360-this.getValuePosition(d,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){const h=f(this.getValuePosition(c,!0)-2),l=x(e.width/2,h,e),g=f(this.getValuePosition(d,!0)+2),m=x(e.width/2,g,e),w=t.createLinearGradient(l.x,l.y,m.x,m.y);w.addColorStop(0,i.GREEN.toString()),w.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());const y=u!==a?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-1),endAngle:f(u+y),gradient:w})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p),endAngle:f(u),color:i.GREEN});if(this.showHi){let i;i=this.showHiHi?this.hihi:this.maximum;const h=360-this.getValuePosition(this.hi,!0),l=360-this.getValuePosition(i,!0);if(this.effect3d&&this.gradient&&this.showHiHi){const d=f(this.getValuePosition(this.hi,!0)-2),c=x(e.width/2,d,e),p=f(this.getValuePosition(i,!0)+2),u=x(e.width/2,p,e),g=t.createLinearGradient(c.x,c.y,u.x,u.y);g.addColorStop(0,this.hiColor.toString()),g.addColorStop(1,this.hihiColor.toString());const m=l!==a?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h-1),endAngle:f(l+m),gradient:g})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h),endAngle:f(l),color:this.hiColor})}if(this.showHiHi){p=360-this.getValuePosition(this.hihi,!0),u=a;const e=this.gradient?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-e),endAngle:f(u),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){let i;return e&&(t=this.getValueInRange(t)),i=this.logScale?this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:this.startAngle-(t-this.range.min)/(this.range.max-this.range.min)*this.lengthInDegrees,i<0&&(i+=360),i}getValueInRange(t){return this.range.min<=t&&t<=this.range.max?t:t>this.range.max?this.range.max:this.range.min}getRenderedRange(){const t={min:this.minimum,max:this.maximum};return this.logScale&&(this.minimum<=0&&(t.min=.1),t.max<=this.minimum&&(t.max=t.min+100)),t}}const Qo=new i(100,100,100),tn="color_hi",en="color_hihi",sn="color_lo",rn="color_lolo",on="effect_3d",nn="font",hn="value_label_format",an="level_hi",ln="level_hihi",dn="level_lo",cn="level_lolo",pn="limits_from_pv",un="log_scale",gn="minimum",mn="maximum",fn="needle_color",xn="ramp_gradient",wn="show_ramp";class yn extends Pe{constructor(t,e){super(t,e),this.properties.add(new E(tn)),this.properties.add(new E(en)),this.properties.add(new E(sn)),this.properties.add(new E(rn)),this.properties.add(new R(on)),this.properties.add(new B(nn)),this.properties.add(new M(an)),this.properties.add(new M(ln)),this.properties.add(new M(dn)),this.properties.add(new M(cn)),this.properties.add(new R(un)),this.properties.add(new R(pn)),this.properties.add(new M(mn)),this.properties.add(new M(gn)),this.properties.add(new E(fn)),this.properties.add(new R(xn)),this.properties.add(new R(wn,!0)),this.properties.add(new L(hn))}draw(t){var e,i;let s;s=this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:null!==(e=this.pv.lowerDisplayLimit)&&void 0!==e?e:this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:null!==(i=this.pv.upperDisplayLimit)&&void 0!==i?i:this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(s.min=Math.max(.1,s.min),s.max<=s.min&&(s.max=s.min+100));const r=Math.min(this.width,this.height),o=r;this.drawBackground(t,r,o),this.showRamp&&this.drawRamp(t,r,o,s),this.drawLabel(t,r,o),this.drawNeedle(t,r,o,s),this.drawNeedleCenter(t,r,o)}drawBackground(t,e,s){if(t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2,ry:s/2,color:i.GRAY}),this.effect3d){const r=t.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);r.addColorStop(0,Qo.toString()),r.addColorStop(1,i.WHITE.toString()),t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2,ry:s/2,gradient:r})}const r=(this.effect3d?2:1)*this.scale;if(t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2-r,ry:s/2-r,color:this.backgroundColor}),this.effect3d){const r=e/2,o=.95,n=.5,h=.85,a=f(0),l=f(35);let d={x:Math.floor(this.x+e/2-r*h*Math.cos(a)),y:Math.floor(this.y+s/2-r*o),width:Math.floor(2*r*h*Math.cos(a)),height:Math.floor(r*o+r*n)},c=t.createLinearGradient(d.x,d.y,d.x,d.y+d.height);c.addColorStop(0,i.WHITE.withAlpha(90/255).toString()),c.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c}),d={x:Math.floor(this.x+e/2-r*h*Math.sin(l)),y:Math.floor(Math.ceil(this.y+s/2+r*n)),width:Math.floor(2*r*h*Math.sin(l)),height:Math.floor(Math.ceil(r*o-r*n))},c=t.createLinearGradient(d.x,d.y,d.x,d.y+d.height),c.addColorStop(0,i.WHITE.withAlpha(0).toString()),c.addColorStop(1,i.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c})}}drawRamp(t,e,i,s){const r=p({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o=Object.assign({},r);o.width=Math.min(r.width,r.height),o.height=r.width;const n=new Jo(10*this.scale,225,315);n.lolo=s.lolo,n.loloColor=this.colorLoLo,n.lo=s.lo,n.loColor=this.colorLo,n.hi=s.hi,n.hiColor=this.colorHi,n.hihi=s.hihi,n.hihiColor=this.colorHiHi,n.minimum=s.min,n.maximum=s.max,n.effect3d=this.effect3d,n.gradient=this.rampGradient,n.logScale=this.logScale,n.draw(t,r,o)}drawLabel(t,e,i){var s;const r=tt.ARIAL_12_BOLD.scale(this.scale);if(void 0!==(null===(s=this.pv)||void 0===s?void 0:s.value)){const s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+7*i/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,s){var r;const o=this.x+e/2,n=this.y+i/2;let h;if(void 0!==(null===(r=this.pv)||void 0===r?void 0:r.value)){const t=this.getValueInRange(this.pv.value,s);h=360-this.getValuePosition(t,s),s.max>s.min?t>s.max?h+=10:t<s.min&&(h-=10):t>s.min?h-=10:t<s.max&&(h+=10)}else h=360-this.getValuePosition((s.min+s.max)/2,s);const a=f(h),{scale:l}=this,{needleDiameter:d,majorTickLength:p,gapBetweenNeedleScale:u}=this,g=c(o,n-d/2+3*l,o,n,a),m=c(o+e/2-p-u,n,o,n,a),x=c(o,n+d/2-3*l,o,n,a);t.fillPath({color:this.needleColor,path:new V(g.x,g.y).lineTo(m.x,m.y).lineTo(x.x,x.y).closePath()})}drawNeedleCenter(t,e,s){const{needleDiameter:r}=this,o=this.x+e/2,n=this.y+s/2,h=r/2,a=r/2;if(this.effect3d){const e=t.createLinearGradient(o-h,n-a,o+h,n+a);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,Qo.toString()),t.fillEllipse({cx:o,cy:n,rx:h,ry:a,gradient:e})}else t.fillEllipse({cx:o,cy:n,rx:h,ry:a,color:i.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i;return i=this.logScale?225-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*270:225-(t-e.min)/(e.max-e.min)*270,i<0&&(i+=360),i}formatLabelValue(t){return this.valueLabelFormat?new Zo(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return 16*this.scale}get majorTickLength(){return 8*this.scale}get minorTickLength(){return 5*this.scale}get gapBetweenNeedleScale(){return-1*this.scale}get colorLo(){return this.properties.getValue(sn)}get colorLoLo(){return this.properties.getValue(rn)}get colorHi(){return this.properties.getValue(tn)}get colorHiHi(){return this.properties.getValue(en)}get effect3d(){return this.properties.getValue(on)}get font(){return this.properties.getValue(nn).scale(this.scale)}get levelLo(){return this.properties.getValue(dn)}get levelLoLo(){return this.properties.getValue(cn)}get levelHi(){return this.properties.getValue(an)}get levelHiHi(){return this.properties.getValue(ln)}get limitsFromPv(){return this.properties.getValue(pn)}get logScale(){return this.properties.getValue(un)}get minimum(){return this.properties.getValue(gn)}get maximum(){return this.properties.getValue(mn)}get needleColor(){return this.properties.getValue(fn)}get rampGradient(){return this.properties.getValue(xn)}get showRamp(){return this.properties.getValue(wn)}get valueLabelFormat(){return this.properties.getValue(hn)}}const vn="data_type",bn="off_image",Tn="off_label",Sn="font",Vn="on_image",Cn="on_label",_n="show_boolean_label";class An extends Pe{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.properties.add(new k("bit")),this.properties.add(new k(vn)),this.properties.add(new L(bn)),this.properties.add(new L(Tn)),this.properties.add(new L(Vn)),this.properties.add(new L(Cn)),this.properties.add(new B(Sn)),this.properties.add(new R(_n))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage))}get booleanValue(){var t,e,i;return this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(vn)}get showBooleanLabel(){return this.properties.getValue(_n)}get font(){return this.properties.getValue(Sn).scale(this.scale)}get offLabel(){return this.properties.getValue(Tn)}get offImage(){return this.properties.getValue(bn)}get onLabel(){return this.properties.getValue(Cn)}get onImage(){return this.properties.getValue(Vn)}}const Ln=["January","February","March","April","May","June","July","August","September","October","November","December"];class Pn{constructor(t,e,i,s,r,o,n,h,a){this.scale=t,this.scaleFont=e,this.minimum=i,this.maximum=s,this.logScale=r,this.majorTickStepHint=o,this.foregroundColor=n,this.showMinorTicks=h,this.showScale=a,this.labels=[],this.labelValues=[],this.labelPositions=[],this.labelVisibilities=[],this.gridStepInPixel=0,this.horizontal=!1,this.x=0,this.y=0,this.scaleFormat="",this.timeFormat=0,this.length=0,this.margin=0}get scaleLength(){return this.length-2*this.margin}getX(){return this.x}getY(){return this.y}getGridPositions(){let t=[...this.labelPositions];return this.horizontal||(t=t.map((t=>this.length-t))),t.pop(),t.shift(),t}setDimensions(t,e,i,s){this.x=t,this.y=e,this.length=i,this.horizontal=s}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),s=0;const r=this.length-2*this.margin;if(this.logScale)s=t<=0?this.margin:(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*r+this.margin;else{const o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;s=(t/o-e)/(i-e)*r+this.margin}return this.horizontal?s+this.x:this.length-s+this.y}getMinMax(){let t=this.minimum,e=this.maximum;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{start:t,stop:e}}getPositionValue(t){const e=this.getMinMax();let{start:i,stop:s}=e;const r=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin;let n;if(this.logScale)n=Math.pow(10,(r-this.margin)*(Math.log10(s)-Math.log10(i))/o+Math.log10(i));else{const t=Math.max(Math.abs(i),Math.abs(s));s/=t,i/=t;const e=s-i;n=((r-this.margin)/o*e+i)*t}return n}calculateMargin(t,e){if(this.showScale){const i=t.measureText(this.format(this.minimum),this.scaleFont),s=t.measureText(this.format(this.maximum),this.scaleFont);return e?Math.ceil(Math.max(i.width,s.width)/2):Math.ceil(Math.max(i.height,s.height)/2)}return 0}measureHorizontalHeight(t){const e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,s){const{scale:r}=this;this.length=s,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);const o=s-2*this.margin;o>0&&this.updateLabels(t,o);let n=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.height>n&&(n=i.height)}const h=this.showScale?n+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i-=h,this.x=e,this.y=i,this.logScale)for(let e=0;e<this.labelPositions.length;e++){const i=this.x+this.labelPositions[e],s=this.y;let o=0;if(o=this.labelVisibilities[e]?this.majorTickLength:this.minorTickLength,this.labelVisibilities[e]||this.showMinorTicks){const e=Math.round(i)-.5*r;t.strokePath({path:new V(e,s).lineTo(e,s+o),color:this.foregroundColor,lineWidth:1*r,opacity:100/255})}this.labelVisibilities[e]&&t.fillText({x:i,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[e]})}else for(let s=0;s<this.labels.length;s++){const o=e+this.labelPositions[s];this.labelVisibilities[s]&&t.fillText({x:o,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[s]});const n=Math.round(o)-.5*r;t.strokePath({path:new V(n,i).lineTo(n,i+this.majorTickLength),color:this.foregroundColor,lineWidth:1*r,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,s,e,i)}return h}drawVertical(t,e,i,s,r,o=!1){const{scale:n}=this;this.length=s,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);const h=s-2*this.margin;h>0&&this.updateLabels(t,h);let a=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.width>a&&(a=i.width)}const l=this.showScale?a+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(r||(e-=l),this.x=e,this.y=i,this.logScale)for(let r=0;r<this.labelPositions.length;r++){let o;o=this.labelVisibilities[r]?this.majorTickLength:this.minorTickLength;const h=e+a+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-o,l=Math.round(i+s-this.labelPositions[r])-.5*n;if((this.labelVisibilities[r]||this.showMinorTicks)&&t.strokePath({path:new V(h,l).lineTo(h+o,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.labelVisibilities[r]){const o=i+s-this.labelPositions[r];t.fillText({x:e,y:o,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else for(let r=0;r<this.labels.length;r++){const h=i+s-this.labelPositions[r],l=Math.round(h)-.5*n;if(o){if(t.strokePath({path:new V(e,l).lineTo(e+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.labelVisibilities[r]){const i=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:i,y:h,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else{this.labelVisibilities[r]&&t.fillText({x:e,y:h,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]});const o=e+a+this.spaceBetweenMarkAndLabel-1*n;t.strokePath({path:new V(o,l).lineTo(o+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,r,o,i+s)}}return l}drawMinorXTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,n;r/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(r/4)):(o=2,n=Math.floor(r/2));const{labelPositions:h,minorTickLength:a,scale:l}=this;if(e>0)if(1===e&&h[1]-h[0]<r){let e=h[1];for(;e-h[0]>n+3*l;){e-=n;const r=Math.round(i+e)-.5*l;t.strokePath({path:new V(r,s).lineTo(r,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else if(e===h.length-1&&h[e]-h[e-1]<r){let r=h[e-1];for(;h[e]-r>n+3*l;){r+=n;const e=Math.round(i+r)-.5*l;t.strokePath({path:new V(e,s).lineTo(e,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else for(let r=0;r<o;r++){let n=i+h[e-1]+(h[e]-h[e-1])*r/o;n=Math.round(n)-.5*l,t.strokePath({path:new V(n,s).lineTo(n,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}drawMinorYTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,n;r/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(r/4)):(o=2,n=Math.floor(r/2));const{labelPositions:h,minorTickLength:a,majorTickLength:l,scale:d}=this;if(e>0)if(1===e&&h[1]-h[0]<r){let e=h[1];for(;e-h[0]>n+3*d;){e-=n;const r=Math.round(s-e)-.5*d;t.strokePath({path:new V(i+l-a,r).lineTo(i+l,r),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else if(e===h.length-1&&h[e]-h[e-1]<r){let r=h[e-1];for(;h[e]-r>n+3*d;){r+=n;const e=Math.round(s-r)-.5*d;t.strokePath({path:new V(i+l-a,e).lineTo(i+l,e),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else for(let r=0;r<o;r++){let n=s-h[e-1]-(h[e]-h[e-1])*r/o;n=Math.round(n)-.5*d,t.strokePath({path:new V(i+l-a,n).lineTo(i+l,n),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}updateLabels(t,e){if(this.labels=[],this.labelValues=[],this.labelPositions=[],this.showScale)if(this.logScale)this.updateLabelsForLogScale(this.minimum,this.maximum,e);else{const t=this.getGridStep(e,this.minimum,this.maximum),i=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/i-this.minimum/i;this.gridStepInPixel=Math.floor(e*(t/i)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,t)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let s=!1;if(e>=i)if(i===e)i++;else{s=!0;const t=e;e=i,i=t}const r=Math.abs(i-e);let o=this.majorTickStepHint;o>t&&(o=t);let n,h=r/t*o,a=0;if(h<1){if(0!=h)for(;h<1;)h*=10,a--}else for(;h>=10;)h/=10,a++;return n=h>7.5?10*Math.pow(10,a):h>3.5?5*Math.pow(10,a):h>1.5?2*Math.pow(10,a):Math.pow(10,a),s&&(n=-n),n}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);const s=e<t,r=Math.log10(t),o=Math.ceil(r),n=Math.ceil(Math.log10(e));let h,a=Math.pow(10,o-1);h=t%a<=0||s?t-t%a:t-t%a+a,(s&&t>h||!s&&t<h)&&this.addMinMaxTickInfo(t,i,!0);for(let t=o;s?t>=n:t<=n;t+=s?-1:1)if(Math.abs(n-o)>20){const s=Math.pow(10,t);if(s>e)break;this.addTickInfo(s,e,r,i)}else{for(let o=h;(s?o>=Math.pow(10,t-1):o<=Math.pow(10,t))&&!(s?o<e:o>e);o=s?o-a:o+a)this.addTickInfo(o,e,r,i);a=s?a/Math.pow(10,1):a*Math.pow(10,1),h=s?Math.pow(10,t-1):a+Math.pow(10,t)}(s?e<this.labelValues[this.labelValues.length-1]:e>this.labelValues[this.labelValues.length-1])&&this.addMinMaxTickInfo(e,i,!1)}addMinMaxTickInfo(t,e,i){i?(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin)):(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin+e))}addTickInfo(t,e,i,s){this.labels.push(this.format(t));const r=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*s)+this.margin;this.labelPositions.push(r),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,s){let r;r=t%s<=0?t-t%s:t-t%s+s,t>r==e<t&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let o=1;const n=Math.max(Math.abs(t),Math.abs(e));s/=n,r/=n;const h=(e/=n)-(t/=n);for(let a=r;e>=t?a<e:a>e;a=r+o++*s){const e=a*n;this.labels.push(this.format(e)),this.labelValues.push(e);const s=Math.floor((a-t)/h*i)+this.margin;this.labelPositions.push(s)}e*=n,this.labelValues.push(e),this.labels.push(this.format(e)),this.labelPositions.push(this.margin+i)}updateVisibility(t){if(this.labelVisibilities=[],!this.labelPositions.length)return;for(let t=0;t<this.labelPositions.length;t++)this.labelVisibilities.push(!0);let e=0,i=null;for(let s=0;s<this.labelPositions.length;s++){let r=!0;const o=this.labels[s],n=this.labelPositions[s];0!==s&&(r=this.hasSpaceToDraw(t,e,n,i||"",o));const h=o===i&&0!==s&&s!==this.labelPositions.length-1;let a=!0;if(this.logScale){const t=Number(this.labels[s]);a=this.isMajorTick(t)||0===s||s===this.labelPositions.length-1}r&&!h&&a?(e=n,i=o):this.labelVisibilities[s]=!1}}hasSpaceToDraw(t,e,i,s,r){const o=t.measureText(r,this.scaleFont),n=t.measureText(s,this.scaleFont);let h=i-e,a=Math.floor(this.horizontal?o.width/2+n.width/2:o.height),l=!0,d=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){l=h>a+this.tickLabelGap;const e=t.measureText(this.labels[this.labels.length-1],this.scaleFont);h=this.labelPositions[this.labelPositions.length-1]-i,a=Math.floor(this.horizontal?o.width/2+e.width/2:o.height),d=h>a+this.tickLabelGap}return l&&d}isMajorTick(t){if(!this.logScale)return!0;const e=Math.log10(t);return e===Math.round(e)}format(t){if(0===this.timeFormat)return this.scaleFormat?new Zo(this.scaleFormat).format(t):String(Number(t.toFixed(2)));const e=new Date(t);switch(this.timeFormat){case 1:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return this.formatDate(e,{year:!0,month:!0,day:!0});case 7:return`${Ln[e.getUTCMonth()]} ${e.getUTCDate()}`;case 8:const t=Math.abs(this.maximum-this.minimum);return t<=5e3?this.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):t<=18e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):t<=864e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=6048e5?this.formatDate(e,{year:!1,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=2592e6?this.formatDate(e,{year:!1,month:!0,day:!0}):this.formatDate(e,{year:!0,month:!0,day:!0})}return""}formatDate(t,e){let i="";if(e.year&&(i+=t.getUTCFullYear()),e.month){e.year&&(i+="-");const s=t.getUTCMonth();i+=(s<10?"0":"")+s}if(e.day){e.month&&(i+="-");const s=t.getUTCDate();i+=(s<10?"0":"")+s}return i}formatTime(t,e){let i="";if(e.hours){const e=t.getUTCHours();i+=(e<10?"0":"")+e}if(e.minutes){e.hours&&(i+=":");const s=t.getUTCMinutes();i+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(i+=":");const s=t.getUTCSeconds();i+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(i+=".");const s=t.getUTCMilliseconds();i+=(s<10?"00":s<100?"0":"")+s}return i}get spaceBetweenMarkAndLabel(){return 2*this.scale}get majorTickLength(){return 6*this.scale}get minorTickLength(){return 3*this.scale}get minorTickMarkStepHint(){return 4*this.scale}get tickLabelGap(){return this.horizontal?10*this.scale:2*this.scale}}const kn="color_map",Mn="crop_bottom",Rn="crop_left",En="crop_right",Bn="crop_top",Wn="data_height",In="data_width",Hn="font",On="graph_area_height",Nn="graph_area_width",Dn="maximum",Fn="minimum",$n="show_ramp",jn="x_axis_axis_color",Gn="x_axis_axis_title",zn="x_axis_major_tick_step_hint",Un="x_axis_maximum",qn="x_axis_minimum",Yn="x_axis_scale_font",Xn="x_axis_show_minor_ticks",Kn="x_axis_title_font",Zn="x_axis_visible",Jn="y_axis_axis_color",Qn="y_axis_axis_title",th="y_axis_major_tick_step_hint",eh="y_axis_maximum",ih="y_axis_minimum",sh="y_axis_scale_font",rh="y_axis_show_minor_ticks",oh="y_axis_title_font",nh="y_axis_visible";class hh extends Pe{constructor(t,e){super(t,e),this.properties.add(new W(kn)),this.properties.add(new k(Mn)),this.properties.add(new k(Rn)),this.properties.add(new k(En)),this.properties.add(new k(Bn)),this.properties.add(new k(Wn)),this.properties.add(new k(In)),this.properties.add(new k(On)),this.properties.add(new k(Nn)),this.properties.add(new B(Hn)),this.properties.add(new M(Dn)),this.properties.add(new M(Fn)),this.properties.add(new R($n)),this.properties.add(new E(jn)),this.properties.add(new L(Gn)),this.properties.add(new k(zn)),this.properties.add(new M(Un)),this.properties.add(new M(qn)),this.properties.add(new B(Yn)),this.properties.add(new R(Xn)),this.properties.add(new B(Kn)),this.properties.add(new R(Zn)),this.properties.add(new E(Jn)),this.properties.add(new L(Qn)),this.properties.add(new k(th)),this.properties.add(new M(eh)),this.properties.add(new M(ih)),this.properties.add(new B(sh)),this.properties.add(new R(rh)),this.properties.add(new B(oh)),this.properties.add(new R(nh))}draw(t){const{scale:e}=this;let i=this.area;this.borderAlarmSensitive&&(i=p(i,2*e));const s=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},i),{color:s}));const{graphAreaWidth:r,graphAreaHeight:o}=this;this.xAxisVisible&&t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height;let n=0;this.yAxisVisible&&(n=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);const h=new Pn(e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),a=h.calculateMargin(t,!0),l=new Pn(e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),d=l.calculateMargin(t,!1),c=h.measureHorizontalHeight(t),u=o+2*d,g=l.drawVertical(t,i.x+n,i.y,u,!0),m=r+2*a,f=i.x+n+g-a,x=i.y+u+c-d;h.drawHorizontal(t,f,x,m);const w=1*e,y=Math.round(i.x+n+g)-w/2,v=Math.round(i.y+d)-w/2;t.strokePath({path:new V(y,v).lineTo(y,v+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:w});const b=y,T=v+o+w;t.strokePath({path:new V(b,T).lineTo(b+r,T),color:this.xAxisAxisColor,opacity:100/255,lineWidth:w});const{dataWidth:S,dataHeight:C,colorMap:_}=this,{minimum:A,maximum:L}=this,[P,k]=_.getMinMax();if(this.value&&this.value.length){const e=document.createElement("canvas"),{cropLeft:s,cropRight:h,cropTop:a,cropBottom:d}=this;e.width=S-s-h,e.height=C-a-d;const c=e.getContext("2d");for(let t=s;t<S-h;t++)for(let e=a;e<C-d;e++){let i=this.value[e*S+t];if(_.autoscale){i=P+(i-A)/(L-A)*(k-P)}const[r,o,n]=_.lookup(i);c.fillStyle=`rgb(${r},${o},${n})`,c.fillRect(t-s,e-a,1,1)}const p=Math.round(i.x+n+g),u=Math.round(i.y+l.margin);t.ctx.drawImage(e,p,u,r,o)}if(this.showRamp){const s=new Pn(e,this.font,A,L,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),h=i.y+l.margin,a=o,d=s.drawVertical(t,i.x+i.width,h,a,!1,!0),c=i.x+n+g+r+this.gap,p=i.width-n-g-r-d-this.gap,u=a-2*s.margin,m=document.createElement("canvas");m.width=p,m.height=u;const f=m.getContext("2d");for(let t=0;t<u;t++){let e=L-t/u*(L-A);if(_.autoscale){e=P+(e-A)/(L-A)*(k-P)}const[i,s,r]=_.lookup(e);f.fillStyle=`rgb(${i},${s},${r})`,f.fillRect(0,t,p,1)}t.ctx.drawImage(m,c,h+s.margin)}if(this.xAxisVisible){let e=i.x+g+r/2;this.yAxisVisible&&(e+=n),t.fillText({x:e,y:i.y+i.height,align:"center",baseline:"bottom",font:this.xAxisTitleFont,color:this.xAxisAxisColor,text:this.xAxisAxisTitle})}this.yAxisVisible&&(t.ctx.save(),t.ctx.translate(i.x+n/2,i.y+u/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return 3*this.scale}get colorMap(){return this.properties.getValue(kn)}get cropBottom(){return this.properties.getValue(Mn)}get cropLeft(){return this.properties.getValue(Rn)}get cropRight(){return this.properties.getValue(En)}get cropTop(){return this.properties.getValue(Bn)}get dataHeight(){return this.properties.getValue(Wn)}get dataWidth(){return this.properties.getValue(In)}get font(){return this.properties.getValue(Hn).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(On)}get graphAreaWidth(){return this.scale*this.properties.getValue(Nn)}get maximum(){return this.properties.getValue(Dn)}get minimum(){return this.properties.getValue(Fn)}get showRamp(){return this.properties.getValue($n)}get xAxisAxisColor(){return this.properties.getValue(jn)}get xAxisAxisTitle(){return this.properties.getValue(Gn)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(zn)}get xAxisMaximum(){return this.properties.getValue(Un)}get xAxisMinimum(){return this.properties.getValue(qn)}get xAxisScaleFont(){return this.properties.getValue(Yn).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Xn)}get xAxisTitleFont(){return this.properties.getValue(Kn).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Zn)}get yAxisAxisColor(){return this.properties.getValue(Jn)}get yAxisAxisTitle(){return this.properties.getValue(Qn)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(th)}get yAxisMaximum(){return this.properties.getValue(eh)}get yAxisMinimum(){return this.properties.getValue(ih)}get yAxisScaleFont(){return this.properties.getValue(sh).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(rh)}get yAxisTitleFont(){return this.properties.getValue(oh).scale(this.scale)}get yAxisVisible(){return this.properties.getValue(nh)}}const ah="data_type",lh="effect_3d",dh="state_count",ch="square_led",ph="off_color",uh="off_label",gh="font",mh="on_color",fh="on_label",xh="bulb_border",wh="bulb_border_color",yh="state_color_fallback",vh="state_label_fallback",bh="show_boolean_label";class Th extends Pe{constructor(t,e){super(t,e),this.states=[],this.properties.add(new k("bit")),this.properties.add(new k(ah)),this.properties.add(new R(lh)),this.properties.add(new R(ch)),this.properties.add(new k(dh,2)),this.properties.add(new E(ph)),this.properties.add(new L(uh)),this.properties.add(new E(mh)),this.properties.add(new L(fh)),this.properties.add(new B(gh)),this.properties.add(new R(bh)),this.properties.add(new E(yh)),this.properties.add(new L(vh)),this.properties.add(new k(xh,3)),this.properties.add(new E(wh,i.DARK_GRAY))}parseNode(t){if(super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){const i=new E(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);const s=new L(`state_label_${e}`);s.value=t.getString(`state_label_${e}`),this.properties.add(s);const r=new M(`state_value_${e}`);r.value=t.getFloat(`state_value_${e}`),this.properties.add(r),this.states.push({label:this.properties.getValue(s.name),color:this.properties.getValue(i.name),value:this.properties.getValue(r.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){var t,e,i;return 0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0:(this.dataType,!1)}get bulbColor(){var t;if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.color;return this.stateColorFallback}get label(){var t;if(2===this.stateCount)return this.booleanValue?this.onLabel:this.offLabel;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.label;return this.stateLabelFallback}draw(t){const e=p(this.bounds,3*this.scale);this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}drawCircle2d(t,e){const i=e.x+e.width/2,s=e.y+e.height/2;let r=e.width/2,o=e.height/2;if(this.bulbBorder>0&&(r-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(i,s,r,o,0,0,2*Math.PI)}}drawCircle3d(t,e){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,n=e.height/2;t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:i.WHITE});let h=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);h.addColorStop(0,this.bulbBorderColor.toString()),h.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,gradient:h});if(o=(e.width-2*this.bulbBorder)/2,n=(e.height-2*this.bulbBorder)/2,t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:this.bulbColor}),h=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),h.addColorStop(0,i.WHITE.toString()),h.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,gradient:h}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(s,r,o,n,0,0,2*Math.PI)}}drawSquare2d(t,e){const i=d(e.x,e.y,e.width,e.height,this.bulbBorder);if(t.fillRect(Object.assign(Object.assign({},i),{color:this.bulbColor})),t.strokeRect(Object.assign(Object.assign({},i),{color:this.bulbBorderColor,lineWidth:this.bulbBorder})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}}drawSquare3d(t,e){if(t.fillRect(Object.assign(Object.assign({},e),{color:this.bulbBorderColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}let i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new V(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new V(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width,e.y)}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new V(e.x+e.width,e.y).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new V(e.x,e.y+e.height).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)});const s=e.x+this.bulbBorder,r=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,n=e.height-2*this.bulbBorder;t.fillRect({x:s,y:r,width:o,height:n,color:this.bulbColor}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.784)"),i.addColorStop(1,this.bulbColor.withAlpha(0).toString()),t.fillRect({x:s,y:r,width:o,height:n,gradient:i})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(ah)}get squareLed(){return this.properties.getValue(ch)}get showBooleanLabel(){return this.properties.getValue(bh)}get font(){return this.properties.getValue(gh).scale(this.scale)}get effect3d(){return this.properties.getValue(lh)}get stateCount(){return this.properties.getValue(dh)}get bulbBorder(){return this.scale*this.properties.getValue(xh)}get bulbBorderColor(){return this.properties.getValue(wh)}get offLabel(){return this.properties.getValue(uh)}get offColor(){return this.properties.getValue(ph)}get onLabel(){return this.properties.getValue(fh)}get onColor(){return this.properties.getValue(mh)}get stateLabelFallback(){return this.properties.getValue(vh)}get stateColorFallback(){return this.properties.getValue(yh)}}const Sh=f(45),Vh=(1-Math.sin(Sh)/2)/(2*Math.cos(Sh)),Ch="color_hi",_h="color_hihi",Ah="color_lo",Lh="color_lolo",Ph="font",kh="level_hi",Mh="level_hihi",Rh="level_lo",Eh="level_lolo",Bh="log_scale",Wh="minimum",Ih="maximum",Hh="needle_color",Oh="ramp_gradient",Nh="scale_font",Dh="show_hi",Fh="show_hihi",$h="show_lo",jh="show_lolo",Gh="show_ramp",zh="value_label_format";class Uh extends Pe{constructor(t,e){super(t,e),this.properties.add(new E(Ch)),this.properties.add(new E(_h)),this.properties.add(new E(Ah)),this.properties.add(new E(Lh)),this.properties.add(new B(Ph)),this.properties.add(new k(kh)),this.properties.add(new k(Mh)),this.properties.add(new k(Rh)),this.properties.add(new k(Eh)),this.properties.add(new R(Bh)),this.properties.add(new k(Ih)),this.properties.add(new k(Wh)),this.properties.add(new E(Hh)),this.properties.add(new R(Oh)),this.properties.add(new B(Nh)),this.properties.add(new R(Dh)),this.properties.add(new R(Fh)),this.properties.add(new R($h)),this.properties.add(new R(jh)),this.properties.add(new R(Gh,!0)),this.properties.add(new L(zh))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){if(t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}}drawRamp(t){const e=String(this.minimum),i=t.measureText(e,this.scaleFont),s=String(this.maximum),r=t.measureText(s,this.scaleFont),o=Math.max(i.width,r.width)/2;let n=this.height,h=this.width;n>Vh*(h-2*o)&&(n=Math.floor(Vh*(h-2*o)));const a=n/(1-Math.sin(Sh)/2),l={x:Math.floor(this.x-a*(1-Math.cos(Sh))+o),y:this.y,width:Math.floor(2*a),height:Math.floor(2*a)},{rampWidth:d}=this,c=p(l,l.width/4-d,l.height/4-d);c.width=Math.min(c.width,c.height),c.height=c.width;const u=new Jo(d,135,45);u.lolo=this.levelLoLo,u.loloColor=this.colorLoLo,u.showLoLo=!0,u.lo=this.levelLo,u.loColor=this.colorLo,u.showLo=!0,u.hi=this.levelHi,u.hiColor=this.colorHi,u.showHi=!0,u.hihi=this.levelHiHi,u.hihiColor=this.colorHiHi,u.showHiHi=!0,u.minimum=this.minimum,u.maximum=this.maximum,u.gradient=this.rampGradient,u.logScale=this.logScale,u.draw(t,l,c),this.drawNeedle(t,l,u);const g=tt.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&void 0!==this.pv.value){const e=this.format(this.pv.value),i=t.measureText(e,g);t.fillText({x:l.x+l.width/2-i.width/2,y:l.y+l.height/2-l.height/4-(u.getRadius()-l.height/4)/2-i.height/2,align:"left",baseline:"top",font:g,text:e,color:this.foregroundColor})}}drawNeedle(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o;if(this.pv&&void 0!==this.pv.value){const t=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(t),this.maximum>this.minimum?t>this.maximum?o+=8:t<this.minimum&&(o-=8):t>this.minimum?o-=8:t<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);const n=f(o),{needleWidth:h,gapBetweenNeedleScale:a,scale:l}=this,d=c(s+e.width/4,r-h/2+3*l,s,r,n),p=c(s+i.getRadius()-a,r,s,r,n),u=c(s+e.width/4,r+h/2-3*l,s,r,n);t.fillPath({color:this.needleColor,path:new V(d.x,d.y).lineTo(p.x,p.y).lineTo(u.x,u.y).closePath()})}get needleWidth(){return 16*this.scale}get gapBetweenNeedleScale(){return-5*this.scale}get rampWidth(){return 12*this.scale}format(t){return this.valueLabelFormat?new Zo(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(Ah)}get colorLoLo(){return this.properties.getValue(Lh)}get colorHi(){return this.properties.getValue(Ch)}get colorHiHi(){return this.properties.getValue(_h)}get font(){return this.properties.getValue(Ph).scale(this.scale)}get levelLo(){return this.properties.getValue(Rh)}get levelLoLo(){return this.properties.getValue(Eh)}get levelHi(){return this.properties.getValue(kh)}get levelHiHi(){return this.properties.getValue(Mh)}get logScale(){return this.properties.getValue(Bh)}get minimum(){return this.properties.getValue(Wh)}get maximum(){return this.properties.getValue(Ih)}get needleColor(){return this.properties.getValue(Hh)}get rampGradient(){return this.properties.getValue(Oh)}get scaleFont(){return this.properties.getValue(Nh).scale(this.scale)}get showLo(){return this.properties.getValue($h)}get showLoLo(){return this.properties.getValue(jh)}get showHi(){return this.properties.getValue(Dh)}get showHiHi(){return this.properties.getValue(Fh)}get showRamp(){return this.properties.getValue(Gh)}get valueLabelFormat(){return this.properties.getValue(zh)}}const qh="color_hi",Yh="color_hihi",Xh="color_lo",Kh="color_lolo",Zh="color_fillbackground",Jh="effect_3d",Qh="fill_color",ta="fillcolor_alarm_sensitive",ea="font",ia="horizontal",sa="indicator_mode",ra="level_hi",oa="level_hihi",na="level_lo",ha="level_lolo",aa="limits_from_pv",la="log_scale",da="maximum",ca="major_tick_step_hint",pa="minimum",ua="origin",ga="origin_ignored",ma="scale_font",fa="scale_format",xa="show_hi",wa="show_hihi",ya="show_label",va="show_lo",ba="show_lolo",Ta="show_markers",Sa="show_minor_ticks",Va="show_scale",Ca="transparent_background",_a="value_label_format";class Aa extends Pe{constructor(t,e){super(t,e),this.properties.add(new E(qh)),this.properties.add(new E(Yh)),this.properties.add(new E(Xh)),this.properties.add(new E(Kh)),this.properties.add(new E(Zh)),this.properties.add(new R(Jh)),this.properties.add(new E(Qh)),this.properties.add(new R(ta,!1)),this.properties.add(new B(ea)),this.properties.add(new R(ia)),this.properties.add(new R(sa)),this.properties.add(new M(ra)),this.properties.add(new M(oa)),this.properties.add(new M(na)),this.properties.add(new M(ha)),this.properties.add(new R(aa)),this.properties.add(new R(la)),this.properties.add(new M(da)),this.properties.add(new M(ca)),this.properties.add(new M(pa)),this.properties.add(new M(ua,0)),this.properties.add(new R(ga,!0)),this.properties.add(new B(ma)),this.properties.add(new L(fa)),this.properties.add(new R(xa)),this.properties.add(new R(wa)),this.properties.add(new R(ya)),this.properties.add(new R(va)),this.properties.add(new R(ba)),this.properties.add(new R(Ta)),this.properties.add(new R(Sa)),this.properties.add(new R(Va)),this.properties.add(new R(Ca)),this.properties.add(new L(_a))}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=p(this.area,2*this.scale));const i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},e),{color:i})),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){const i=this.alarmSensitiveForegroundColor,s=new Pn(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawVertical(t,e.x,e.y,e.height,!0);let o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,s,e)),this.drawVerticalBar(t,s,{x:e.x+r,y:e.y+s.margin,width:e.width-r-o,height:e.height-2*s.margin})}drawVerticalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=tt.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.width)}const l=i.x+i.width;if(this.showLoLo&&void 0!==s){const i=l-a-this.markerGap,r=Math.round(e.getValuePosition(s));t.strokePath({path:new V(i,r).lineTo(i-this.markerTickLength,r),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:r,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(r));t.strokePath({path:new V(i,s).lineTo(i-this.markerTickLength,s),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(o));t.strokePath({path:new V(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(n));t.strokePath({path:new V(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawVerticalBar(t,e,s){var r;const{outlineWidth:o}=this;if(t.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const e=t.createLinearGradient(s.x,0,s.x+s.width,0);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},s),{gradient:e}));const r=p(s,o/2);t.strokeRect(Object.assign(Object.assign({},r),{color:i.GRAY,lineWidth:o}))}const n=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(e.getValuePosition(this.getFillValue())),h=s.width,a=this.thumbBreadth,l=m([{x:0,y:a/2},{x:h/2,y:0},{x:h-1,y:a/2},{x:h/2,y:a}],s.x,r-a/2),d=V.fromPoints(l);if(this.effect3d){const{x:e,y:s}=l[0],{x:r,y:h}=l[2],a=t.createLinearGradient(e,s,r,h);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillPath({path:d,gradient:a}),t.strokePath({path:d,color:i.GRAY,lineWidth:o})}else t.fillPath({path:d,color:n})}else{let r=this.originIgnored?this.min:this.origin,h=this.getFillValue();if(h<r){const t=r;r=h,h=t}const a=Math.round(e.getValuePosition(r)),l=Math.round(e.getValuePosition(h)),d=p(Object.assign(Object.assign({},s),{y:a,height:l-a}),o);if(t.fillRect(Object.assign(Object.assign({},d),{color:n})),this.effect3d){const e=t.createLinearGradient(d.x,0,d.x+d.width,0);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},d),{gradient:e}))}}const h=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==h&&t.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(h)})}drawHorizontal(t,e){const i=this.alarmSensitiveForegroundColor,s=new Pn(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawHorizontal(t,e.x,e.y+e.height,e.width);let o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,s,e)),this.drawHorizontalBar(t,s,{x:e.x+s.margin,y:e.y+o,width:e.width-2*s.margin,height:e.height-r-o})}drawHorizontalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=tt.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.height)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.height)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.height)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.height)}const l=i.y;if(this.showLoLo&&void 0!==s){const i=Math.round(e.getValuePosition(s)),r=l+a+this.markerGap;t.strokePath({path:new V(i,r).lineTo(i,r+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const i=Math.round(e.getValuePosition(r)),s=l+a+this.markerGap;t.strokePath({path:new V(i,s).lineTo(i,s+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const i=Math.round(e.getValuePosition(o)),s=l+a+this.markerGap;t.strokePath({path:new V(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const i=Math.round(e.getValuePosition(n)),s=l+a+this.markerGap;t.strokePath({path:new V(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawHorizontalBar(t,e,s){var r;const{outlineWidth:o}=this;if(t.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const e=t.createLinearGradient(0,s.y,0,s.y+s.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},s),{gradient:e}));const r=p(s,o/2);t.strokeRect(Object.assign(Object.assign({},r),{color:i.GRAY,lineWidth:o}))}const n=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(e.getValuePosition(this.getFillValue())),h=s.height,a=this.thumbBreadth,l=m([{x:a/2,y:0},{x:a,y:h/2},{x:a/2,y:h-1},{x:0,y:h/2}],r-a/2,s.y),d=V.fromPoints(l);if(this.effect3d){const{x:e,y:s}=l[0],{x:r,y:h}=l[2],a=t.createLinearGradient(e,s,r,h);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillPath({path:d,gradient:a}),t.strokePath({path:d,color:i.GRAY,lineWidth:o})}else t.fillPath({path:d,color:n})}else{let r=this.originIgnored?this.min:this.origin,h=this.getFillValue();if(h<r){const t=r;r=h,h=t}const a=Math.round(e.getValuePosition(r)),l=Math.round(e.getValuePosition(h)),d=p(Object.assign(Object.assign({},s),{x:a,width:l-a}),o);if(t.fillRect(Object.assign(Object.assign({},d),{color:n})),this.effect3d){const e=t.createLinearGradient(0,d.y,0,d.y+d.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},d),{gradient:e}))}}const h=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==h&&t.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(h)})}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get thumbBreadth(){return 13*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new Zo(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Xh)}get colorLoLo(){return this.properties.getValue(Kh)}get colorHi(){return this.properties.getValue(qh)}get colorHiHi(){return this.properties.getValue(Yh)}get colorFillbackground(){return this.properties.getValue(Zh)}get effect3d(){return this.properties.getValue(Jh)}get fillColorAlarmSensitive(){return this.properties.getValue(ta)}get fillColor(){return this.properties.getValue(Qh)}get font(){return this.properties.getValue(ea).scale(this.scale)}get horizontal(){return this.properties.getValue(ia)}get indicatorMode(){return this.properties.getValue(sa)}get levelLo(){return this.properties.getValue(na)}get levelLoLo(){return this.properties.getValue(ha)}get levelHi(){return this.properties.getValue(ra)}get levelHiHi(){return this.properties.getValue(oa)}get limitsFromPv(){return this.properties.getValue(aa)}get logScale(){return this.properties.getValue(la)}get minimum(){return this.properties.getValue(pa)}get majorTickStepHint(){return this.scale*this.properties.getValue(ca)}get maximum(){return this.properties.getValue(da)}get origin(){return this.properties.getValue(ua)}get originIgnored(){return this.properties.getValue(ga)}get scaleFont(){return this.properties.getValue(ma).scale(this.scale)}get scaleFormat(){return this.properties.getValue(fa)}get showHi(){return this.properties.getValue(xa)}get showHiHi(){return this.properties.getValue(wa)}get showLabel(){return this.properties.getValue(ya)}get showLo(){return this.properties.getValue(va)}get showLoLo(){return this.properties.getValue(ba)}get showMarkers(){return this.properties.getValue(Ta)}get showMinorTicks(){return this.properties.getValue(Sa)}get showScale(){return this.properties.getValue(Va)}get transparentBackground(){return this.properties.getValue(Ca)}get valueLabelFormat(){return this.properties.getValue(_a)}}const La="color_hi",Pa="color_hihi",ka="color_lo",Ma="color_lolo",Ra="color_fillbackground",Ea="fill_color",Ba="fillcolor_alarm_sensitive",Wa="effect_3d",Ia="level_hi",Ha="level_hihi",Oa="level_lo",Na="level_lolo",Da="limits_from_pv",Fa="log_scale",$a="maximum",ja="major_tick_step_hint",Ga="minimum",za="scale_font",Ua="scale_format",qa="show_hi",Ya="show_hihi",Xa="show_lo",Ka="show_lolo",Za="show_markers",Ja="show_minor_ticks",Qa="show_scale",tl="transparent_background",el=new i(160,160,160);class il extends Pe{constructor(t,e){super(t,e),this.properties.add(new E(La)),this.properties.add(new E(Pa)),this.properties.add(new E(ka)),this.properties.add(new E(Ma)),this.properties.add(new E(Ra)),this.properties.add(new R(Wa)),this.properties.add(new E(Ea)),this.properties.add(new R(Ba,!1)),this.properties.add(new M(Ia)),this.properties.add(new M(Ha)),this.properties.add(new M(Oa)),this.properties.add(new M(Na)),this.properties.add(new R(Da)),this.properties.add(new R(Fa)),this.properties.add(new M($a)),this.properties.add(new M(ja)),this.properties.add(new M(Ga)),this.properties.add(new B(za)),this.properties.add(new L(Ua)),this.properties.add(new R(qa)),this.properties.add(new R(Ya)),this.properties.add(new R(Xa)),this.properties.add(new R(Ka)),this.properties.add(new R(Za)),this.properties.add(new R(Ja)),this.properties.add(new R(Qa)),this.properties.add(new R(tl))}draw(t){const{scale:e,min:i,max:s}=this;let r=this.area;this.borderAlarmSensitive&&(r=p(r,2*e));const o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},r),{color:o}));const n=this.alarmSensitiveForegroundColor,h=new Pn(e,this.scaleFont,i,s,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);h.scaleFormat=this.scaleFormat;const a=h.drawVertical(t,r.x,r.y,r.height,!0);let l=0;this.showMarkers&&(l=this.drawMarkers(t,r,h)),this.drawTank(t,r,a,l,h)}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=tt.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.width)}const l=e.x+e.width-a-this.markerGap-this.markerTickLength;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new V(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new V(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new V(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const e=Math.round(i.getValuePosition(n));t.strokePath({path:new V(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawTank(t,e,s,r,o){const n=this.alarmSensitiveForegroundColor,{scale:h,outlineWidth:a}=this,l=e.x+s,d=e.y+o.margin,c=e.width-s-r,u=e.height-2*o.margin;let g=this.defaultCorner,m=.55;c<2*g&&(m=.6);const f=Math.floor(c*m);g>2*f-c-2*a&&(g=2*f-c);const x=o.getValuePosition(this.getFillValue()),w=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:d,width:c,height:u,rx:g/2,ry:g/2,color:i.WHITE});let e=t.createLinearGradient(l,d,l+f+2*h,d);e.addColorStop(0,this.colorFillbackground.toString()),e.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:d,width:f,height:u,rx:g/2,ry:g/2,gradient:e}),e=t.createLinearGradient(l+c-f-2*h,d,l+c,d),e.addColorStop(0,i.WHITE.withAlpha(0).toString()),e.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+c-f,y:d,width:f,height:u,rx:g/2,ry:g/2,gradient:e});const s=x,r=d+u-x;e=t.createLinearGradient(l,s,l+f+2*h,s),e.addColorStop(0,w.toString()),e.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:s,width:f,height:r,rx:g/2,ry:g/2,gradient:e}),e=t.createLinearGradient(l+c-f-2*h,s,l+c,s),e.addColorStop(0,i.WHITE.withAlpha(0).toString()),e.addColorStop(1,w.toString()),t.fillRect({x:l+c-f,y:s,width:f,height:r,rx:g/2,ry:g/2,gradient:e})}else t.fillRect({x:l,y:d,width:c,height:u,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:x,width:c,height:d+u-x,rx:g/2,ry:g/2,color:w});let y=p({x:l,y:d,width:c,height:u},a/2);t.strokeRect(Object.assign(Object.assign({},y),{rx:g/2,ry:g/2,color:this.effect3d?el:n,lineWidth:a}))}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get defaultCorner(){return 15*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}get colorLo(){return this.properties.getValue(ka)}get colorLoLo(){return this.properties.getValue(Ma)}get colorHi(){return this.properties.getValue(La)}get colorHiHi(){return this.properties.getValue(Pa)}get colorFillbackground(){return this.properties.getValue(Ra)}get fillColorAlarmSensitive(){return this.properties.getValue(Ba)}get fillColor(){return this.properties.getValue(Ea)}get effect3d(){return this.properties.getValue(Wa)}get levelLo(){return this.properties.getValue(Oa)}get levelLoLo(){return this.properties.getValue(Na)}get levelHi(){return this.properties.getValue(Ia)}get levelHiHi(){return this.properties.getValue(Ha)}get limitsFromPv(){return this.properties.getValue(Da)}get logScale(){return this.properties.getValue(Fa)}get minimum(){return this.properties.getValue(Ga)}get majorTickStepHint(){return this.scale*this.properties.getValue(ja)}get maximum(){return this.properties.getValue($a)}get scaleFont(){return this.properties.getValue(za).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Ua)}get showLo(){return this.properties.getValue(Xa)}get showLoLo(){return this.properties.getValue(Ka)}get showHi(){return this.properties.getValue(qa)}get showHiHi(){return this.properties.getValue(Ya)}get showMarkers(){return this.properties.getValue(Za)}get showMinorTicks(){return this.properties.getValue(Ja)}get showScale(){return this.properties.getValue(Qa)}get transparentBackground(){return this.properties.getValue(tl)}}const sl="font",rl="format_type",ol="horizontal_alignment",nl="precision",hl="precision_from_pv",al="show_units",ll="vertical_alignment";class dl extends Pe{constructor(t,e){super(t,e),this.properties.add(new B(sl)),this.properties.add(new k(rl)),this.properties.add(new k(ol)),this.properties.add(new k(nl)),this.properties.add(new R(hl)),this.properties.add(new R(al,!0)),this.properties.add(new k(ll))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){var e,i,s;const r=t.ctx;if(this.transparent?this.backgroundAlarmSensitive&&this.alarm&&t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.font=this.font.getFontString();const{scale:o}=this;let n=this.area;this.borderAlarmSensitive&&(n=p(n,2*o,2*o));let h=n.x;0===this.horizAlignment?r.textAlign="start":1===this.horizAlignment?(h+=n.width/2,r.textAlign="center"):2===this.horizAlignment&&(h+=n.width,r.textAlign="end");let a=n.y;0===this.vertAlignment?r.textBaseline="top":1===this.vertAlignment?(a+=n.height/2,r.textBaseline="middle"):2===this.vertAlignment&&(a+=n.height,r.textBaseline="bottom");let l=this.text;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)){let t=this.precisionFromPV?this.pv.precision:this.precision;-1===t&&(t=null!==(i=this.pv.precision)&&void 0!==i?i:-1),l=T(this.pv.value,this.formatType,t)}else void 0!==this.value&&(l=T(this.value,this.formatType,this.precision));this.showUnits&&(null===(s=this.pv)||void 0===s?void 0:s.units)&&(l+=" "+this.pv.units),r.fillText(l,h,a)}get font(){return this.properties.getValue(sl).scale(this.scale)}get formatType(){return this.properties.getValue(rl)}get horizAlignment(){return this.properties.getValue(ol)}get precision(){return this.properties.getValue(nl)}get precisionFromPV(){return this.properties.getValue(hl)}get showUnits(){return this.properties.getValue(al)}get vertAlignment(){return this.properties.getValue(ll)}}const cl="color_hi",pl="color_hihi",ul="color_lo",gl="color_lolo",ml="color_fillbackground",fl="fill_color",xl="fillcolor_alarm_sensitive",wl="font",yl="effect_3d",vl="level_hi",bl="level_hihi",Tl="level_lo",Sl="level_lolo",Vl="limits_from_pv",Cl="log_scale",_l="maximum",Al="major_tick_step_hint",Ll="minimum",Pl="scale_font",kl="scale_format",Ml="show_bulb",Rl="show_hi",El="show_hihi",Bl="show_lo",Wl="show_lolo",Il="show_markers",Hl="show_minor_ticks",Ol="show_scale",Nl="transparent_background",Dl="unit",Fl="value_label_format",$l=new i(160,160,160);class jl extends Pe{constructor(t,e){super(t,e),this.properties.add(new E(cl)),this.properties.add(new E(pl)),this.properties.add(new E(ul)),this.properties.add(new E(gl)),this.properties.add(new E(ml)),this.properties.add(new E(fl)),this.properties.add(new R(xl,!1)),this.properties.add(new R(yl)),this.properties.add(new M(vl)),this.properties.add(new M(bl)),this.properties.add(new M(Tl)),this.properties.add(new M(Sl)),this.properties.add(new R(Vl)),this.properties.add(new B(wl)),this.properties.add(new R(Cl)),this.properties.add(new M(_l)),this.properties.add(new M(Al)),this.properties.add(new M(Ll)),this.properties.add(new B(Pl)),this.properties.add(new L(kl)),this.properties.add(new R(Ml)),this.properties.add(new R(Rl)),this.properties.add(new R(El)),this.properties.add(new R(Bl)),this.properties.add(new R(Wl)),this.properties.add(new R(Il)),this.properties.add(new R(Hl)),this.properties.add(new R(Ol)),this.properties.add(new R(Nl)),this.properties.add(new k(Dl)),this.properties.add(new L(Fl))}draw(t){var e;const{scale:s,min:r,max:o}=this;let n=this.area;this.borderAlarmSensitive&&(n=p(this.area,2*this.scale));const h=this.alarmSensitiveBackgroundColor,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},n),{color:h}));let d=n.height;if(this.showBulb){let t=Math.min(n.width/2,this.bulbMaxDiameter);d=n.height<t?0:n.height-t}let c=Object.assign(Object.assign({},n),{height:d});const u=new Pn(s,this.scaleFont,r,o,this.logScale,this.majorTickStepHint,a,this.showMinorTicks,this.showScale);u.scaleFormat=this.scaleFormat;let g=0,m="";if(0===this.unit?m="°C":1===this.unit?m="°F":2===this.unit&&(m="K"),m){const e=tt.ARIAL_9.scale(s),i=2*s;g=t.measureText(m,e).height+2*i,t.fillText({x:n.x+n.width/2-this.pipeWidth/2-i,y:n.y+i,baseline:"top",align:"right",color:a,font:e,text:m})}const f=c.x+c.width/2-this.pipeWidth/2-1*s,x=Object.assign(Object.assign({},c),{y:c.y+g,height:c.height-g+u.calculateMargin(t,!1)});u.drawVertical(t,f,x.y,x.height,!1);const w=Math.floor(this.pipeWidth/2);if(c=Object.assign(Object.assign({},c),{y:u.getValuePosition(o)-w,height:u.scaleLength+2*w}),this.drawPipe(t,c,u),this.showMarkers&&this.drawMarkers(t,n,u),this.showBulb){let o=Math.min(n.width/2,this.bulbMaxDiameter);const h=1*s,p=n.x+n.width/2,g=n.y+d+o/2,m=o/2,f=o/2;if(t.fillEllipse({cx:p,cy:g,rx:m,ry:f,color:l}),this.effect3d){const e=t.createLinearGradient(p-m,g-f,p+m,g+f);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,l.withAlpha(0).toString()),t.fillEllipse({cx:p,cy:g,rx:m,ry:f,gradient:e})}t.strokeEllipse({cx:p,cy:g,rx:m-h/2,ry:f-h/2,color:this.effect3d?$l:a,lineWidth:h});const x={x:Math.round(c.x+c.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(u.getValuePosition(r)),width:this.pipeWidth-2*this.outlineWidth,height:3*s};if(this.effect3d){const e=Math.round(c.x+c.width/2-this.pipeWidth/2),s=e+this.pipeWidth,r=t.createLinearGradient(e,x.y,s,x.y);r.addColorStop(0,i.WHITE.toString()),r.addColorStop(1,l.toString()),t.fillRect(Object.assign(Object.assign({},x),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},x),{color:l}));const w=null===(e=this.pv)||void 0===e?void 0:e.value;w&&t.fillText({x:p,y:g,align:"center",baseline:"middle",color:l.contrast(),font:this.font,text:this.format(w)})}}drawPipe(t,e,s){const{scale:r,outlineWidth:o,min:n,max:h}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,d={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},c=this.getFillValue();let u=s.getValuePosition(c);h>n?c>h?u-=10*r:c<n&&(u+=10*r):c>n?u+=10*r:c<h&&(u-=10*r);const g=this.pipeWidth/2,{x:m,y:f,width:x,height:w}=d;if(this.effect3d){let e=t.createLinearGradient(m,f,m+x,f);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.toString()),t.fillRect(Object.assign(Object.assign({},d),{rx:g/2,ry:g/2,gradient:e})),e=t.createLinearGradient(m,f,m+x,f),e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,l.toString()),t.fillRect({x:m,y:u,width:x,height:f+w-u,rx:g/2,ry:g/2,gradient:e})}else t.fillRect(Object.assign(Object.assign({},d),{rx:g/2,ry:g/2,color:this.colorFillbackground})),t.fillRect({x:m,y:u,width:x,height:f+w-u,rx:g/2,ry:g/2,color:l});let y=p(d,o/2);t.strokeRect(Object.assign(Object.assign({},y),{rx:g/2,ry:g/2,color:this.effect3d?$l:a,lineWidth:o}))}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=tt.ARIAL_9.scale(this.scale),a=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new V(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new V(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new V(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const e=Math.round(i.getValuePosition(n));t.strokePath({path:new V(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get pipeWidth(){return 15*this.scale}get bulbMaxDiameter(){return 40*this.scale}get outlineWidth(){return 1*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new Zo(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(ul)}get colorLoLo(){return this.properties.getValue(gl)}get colorHi(){return this.properties.getValue(cl)}get colorHiHi(){return this.properties.getValue(pl)}get colorFillbackground(){return this.properties.getValue(ml)}get fillColorAlarmSensitive(){return this.properties.getValue(xl)}get fillColor(){return this.properties.getValue(fl)}get font(){return this.properties.getValue(wl).scale(this.scale)}get effect3d(){return this.properties.getValue(yl)}get levelLo(){return this.properties.getValue(Tl)}get levelLoLo(){return this.properties.getValue(Sl)}get levelHi(){return this.properties.getValue(vl)}get levelHiHi(){return this.properties.getValue(bl)}get limitsFromPv(){return this.properties.getValue(Vl)}get logScale(){return this.properties.getValue(Cl)}get minimum(){return this.properties.getValue(Ll)}get majorTickStepHint(){return this.scale*this.properties.getValue(Al)}get maximum(){return this.properties.getValue(_l)}get scaleFont(){return this.properties.getValue(Pl).scale(this.scale)}get scaleFormat(){return this.properties.getValue(kl)}get showBulb(){return this.properties.getValue(Ml)}get showMarkers(){return this.properties.getValue(Il)}get showMinorTicks(){return this.properties.getValue(Hl)}get showLo(){return this.properties.getValue(Bl)}get showLoLo(){return this.properties.getValue(Wl)}get showHi(){return this.properties.getValue(Rl)}get showHiHi(){return this.properties.getValue(El)}get showScale(){return this.properties.getValue(Ol)}get transparentBackground(){return this.properties.getValue(Nl)}get unit(){return this.properties.getValue(Dl)}get valueLabelFormat(){return this.properties.getValue(Fl)}}const Gl=-323.3062,zl=308.2547;class Ul{constructor(t,e){this.widget=t,this.index=e}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return 0!==this.timeFormat}isHorizontal(){return 0===this.index||1!==this.index&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){var t;return null!==(t=this._effectiveMinimum)&&void 0!==t?t:this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){var t;return null!==(t=this._effectiveMaximum)&&void 0!==t?t:this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){const t={start:this.minimum,stop:this.maximum},e=this.widget.calculateAutoscaledRange(this,t);e&&(this.effectiveMinimum=e.start,this.effectiveMaximum=e.stop,this.widget.requestRepaint())}applyZoom(t,e){let i,s,r=this.effectiveMinimum,o=this.effectiveMaximum;if(this.logScale){o=Math.log10(o),r=Math.log10(r);const n=Math.log10(t)*e,h=1-e;i=n+r*h,s=n+o*h,i<Gl&&(i=Gl),i=Math.pow(10,i),s>zl&&(s=zl),s=Math.pow(10,s)}else{const n=Math.max(Math.abs(r),Math.abs(o));r/=n,o/=n;const h=t/n*e,a=1-e;i=(h+r*a)*n,s=(h+o*a)*n}this.effectiveMinimum=i,this.effectiveMaximum=s,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}}class ql{constructor(t,e){this.xAxis=t,this.yAxis=e,this.beforeXRanges=[],this.beforeYRanges=[],this.afterXRanges=[],this.afterYRanges=[];for(const e of t)this.beforeXRanges.push({min:e.effectiveMinimum,max:e.effectiveMaximum});for(const t of e)this.beforeYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}saveState(){for(const t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(const t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.beforeXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.beforeYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}redo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.afterXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}}class Yl{constructor(){this.undoStack=[],this.redoStack=[]}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){const t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){const t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}}class Xl{constructor(t,e){this.widget=e,this.id=t}tooltip(){return this.widget.tooltip}mouseDown(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new ql(i.getXAxes(),i.getYAxes())}}grab(t){var e;switch(null===(e=this.widget.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection=Object.assign(Object.assign({},this.grabStart.point),{width:t.dx,height:t.dy}),this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint()}}grabEnd(){var t;const{grabZoomCommand:e,selection:i,widget:s}=this;switch(null===(t=s.toolbar)||void 0===t?void 0:t.currentTool){case"rubberband-zoom":if(i){const t=new ql(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"horizontal-zoom":if(i){const t=new ql(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"vertical-zoom":if(i){const t=new ql(s.getXAxes(),s.getYAxes());this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"panning":e&&(e.saveState(),s.toolbar.addCommand(e))}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"zoom-in":const e=new ql(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,.1)}e.saveState(),i.toolbar.addCommand(e);break;case"zoom-out":const s=new ql(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,-.1)}s.saveState(),i.toolbar.addCommand(s)}}rangeZoomXAxes(t){for(const e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),s=e.linearScale.getPositionValue(t.x+t.width);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}rangeZoomYAxes(t){for(const e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),s=e.linearScale.getPositionValue(t.y+t.height);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}pan(t){const{prevGrabEvent:e,widget:i}=this;if(e){const s=e.dx-t.dx;if(0!==s)for(const t of i.getXAxes()){const e=t.linearScale,i=e.getMinMax(),r=e.getValuePosition(i.start)+s,o=e.getValuePosition(i.stop)+s;t.effectiveMinimum=e.getPositionValue(r),t.effectiveMaximum=e.getPositionValue(o)}const r=e.dy-t.dy;if(0!==r)for(const t of i.getYAxes()){const e=t.linearScale,i=e.getMinMax(),s=e.getValuePosition(i.start)+r,o=e.getValuePosition(i.stop)+r;t.effectiveMinimum=e.getPositionValue(s),t.effectiveMaximum=e.getPositionValue(o)}}}}class Kl{constructor(t){this.pointer=0,this.samples=[],this.samples=Array(t).fill(void 0)}push(t,e){this.samples[this.pointer]={x:t,y:e},this.pointer=(this.pointer+1)%this.samples.length}clear(){this.samples.fill(void 0),this.pointer=0}isFull(){const t=(this.pointer+1)%this.samples.length;return void 0!==this.samples[t]}isEmpty(){return void 0===this.tail()}tail(){return 0===this.pointer?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t){return this.samples.filter((t=>void 0!==t)).sort(((t,e)=>t.x-e.x))}{const t=this.samples.slice(this.pointer).filter((t=>void 0!==t)),e=this.samples.slice(0,this.pointer).filter((t=>void 0!==t));return t.concat(e)}}}class Zl{constructor(t,e,i,s,r,o){this.bufferSize=t,this.plotMode=e,this.updateMode=i,this.concatenateData=s,this.chronological=r,this.historicalDataProvider=o,this.x=0,this.xPending=!1,this.y=0,this.yTimestamp=0,this.yPending=!1,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1,this.traceData=new Kl(t)}clear(){this.traceData.clear(),this.x=0,this.xPending=!1,this.y=0,this.yPending=!1,this.yTimestamp=0,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1}snapshot(){return this.historicalDataProvider?this.historicalDataProvider.getSamples():this.traceData.snapshot()}updateX(t){this.x=t,this.xPending=!0,this.maybeAddPoint()}updateY(t,e){this.y=t,this.yTimestamp=e,this.yPending=!0,this.maybeAddPoint()}updateXArray(t){this.xArray=t,this.xArrayPending=!0,this.maybeAddArray()}updateYArray(t){this.yArray=t,this.yArrayPending=!0,this.maybeAddArray()}maybeAddPoint(){if(1===this.plotMode&&this.traceData.isFull())return;const{xPending:t,yPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addPoint():1===s?(i&&e||!i&&t&&e)&&this.addPoint():2===s?(i&&e||!i&&t)&&this.addPoint():3===s&&this.yPending&&this.addPoint()}maybeAddArray(){if(1===this.plotMode&&this.traceData.isFull())return;const{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addArray():1===s?(i&&e||!i&&t&&e)&&this.addArray():2===s?(i&&e||!i&&t)&&this.addArray():3===s&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(5===this.updateMode)t=(new Date).getTime();else if(void 0!==this.yTimestamp)t=this.yTimestamp;else{const e=this.traceData.tail();t=e?e.x+1:0}this.traceData.push(t,this.y),this.xPending=!1,this.yPending=!1}addArray(){this.concatenateData||this.traceData.clear();let{xArray:t,yArray:e}=this;if(this.chronological)if(t=Array(e.length),this.traceData.isEmpty())for(let i=0;i<e.length;i++)t[i]=i;else{const i=this.traceData.tail();for(let s=1;s<e.length;s++)t[s-1]=i.x+s}let i=Math.min(t.length,e.length),s=Math.min(i,this.bufferSize);for(let i=0;i<s;i++)this.traceData.push(t[i],e[i]);this.xArrayPending=!1,this.yArrayPending=!1}}class Jl{constructor(t,e){this.widget=t,this.i=e,this.xPVListener=()=>{var t,e;const i=this.xPVInstance;if(i)if(Array.isArray(i.value))null===(t=this.traceData)||void 0===t||t.updateXArray(i.value);else{const t=i.toNumber();null!=t&&(null===(e=this.traceData)||void 0===e||e.updateX(t))}},this.yPVListener=()=>{var t,e,i;const s=this.yPVInstance;if(s)if(Array.isArray(s.value))null===(t=this.traceData)||void 0===t||t.updateYArray(s.value);else{const t=this.widget.getAxis(this.xAxisIndex),r=s.toNumber();if(null!=r)if(t.isDateEnabled()){const t=(s.time||new Date).getTime();null===(e=this.traceData)||void 0===e||e.updateY(r,t)}else null===(i=this.traceData)||void 0===i||i.updateY(r)}}}init(){const{bufferSize:t,plotMode:e,updateMode:i,concatenateData:s,widget:r}=this,o=!this.xPV,{pvEngine:n}=r.display;this.historicalDataProvider=void 0,o&&this.yPV&&(this.historicalDataProvider=n.createHistoricalDataProvider(this.yPV,r)||void 0),this.traceData=new Zl(t,e,i,s,o,this.historicalDataProvider),this.xPV&&(this.xPVInstance=n.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=n.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),r.addPropertyListener(`trace_${this.i}_x_pv`,(()=>{var t;const e=n.createPV(this.xPV);e!==this.xPVInstance&&(null===(t=this.xPVInstance)||void 0===t||t.removeListener(this.xPVListener),this.xPVInstance=e,this.xPVInstance.addListener(this.xPVListener))})),r.addPropertyListener(`trace_${this.i}_y_pv`,(()=>{var t;const e=n.createPV(this.yPV);e!==this.yPVInstance&&(null===(t=this.yPVInstance)||void 0===t||t.removeListener(this.yPVListener),this.yPVInstance=e,this.yPVInstance.addListener(this.yPVListener))}))}snapshot(){var t;return(null===(t=this.traceData)||void 0===t?void 0:t.snapshot())||[]}drawTrace(t,e){const{lineWidth:i}=this;if(0===this.traceType)t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i});else if(1===this.traceType)t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(2===this.traceType);else if(3===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(const r of e)null!==r.y&&t.strokePath({path:new V(r.x,r.y).lineTo(r.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(4===this.traceType||5===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];null!==r.y&&null!==o.y&&t.fillPath({path:new V(r.x,r.y).lineTo(r.x,s).lineTo(o.x,s).lineTo(o.x,o.y),color:this.traceColor,opacity:100/255})}5===this.traceType&&t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(6===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];null!==r.y&&null!==o.y&&t.strokePath({path:new V(r.x,r.y).lineTo(r.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(7===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];null!==r.y&&null!==o.y&&t.strokePath({path:new V(r.x,r.y).lineTo(o.x,r.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(8===this.traceType){const{scale:s}=this;t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s]})}else if(9===this.traceType){const{scale:s}=this;t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s,2*s,2*s]})}else if(10===this.traceType){const{scale:s}=this;t.strokePath({path:V.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*s,2*s]})}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;const i=this.pointSize/2,s=e.x,r=e.y;switch(this.pointStyle){case 1:case 3:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 4:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(s-i,r-i,2*i,2*i);break;case 7:t.ctx.fillRect(s-i,r-i,2*i,2*i);break;case 8:case 9:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r),t.ctx.lineTo(s,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(s-i,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.moveTo(s+i,r-i),t.ctx.lineTo(s-i,r+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s+i,r),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke()}}clearData(){var t;null===(t=this.traceData)||void 0===t||t.clear()}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`trace_${this.i}_${t}`)}get antiAlias(){return this.getValue("anti_alias")}get bufferSize(){return this.getValue("buffer_size")}get concatenateData(){return this.getValue("concatenate_data")}get lineWidth(){return this.scale*this.getValue("line_width")}get name(){return this.getValue("name")}get plotMode(){return this.getValue("plot_mode")}get pointSize(){return this.scale*this.getValue("point_size")}get pointStyle(){return this.getValue("point_style")}get traceColor(){return this.getValue("trace_color")}get traceType(){return this.getValue("trace_type")}get updateDelay(){return this.getValue("update_delay")}get updateMode(){return this.getValue("update_mode")}get visible(){return this.getValue("visible")}get xAxisIndex(){return this.getValue("x_axis_index")}get xPV(){return this.getValue("x_pv")}get yAxisIndex(){return this.getValue("y_axis_index")}get yPV(){return this.getValue("y_pv")}destroy(){var t;null===(t=this.historicalDataProvider)||void 0===t||t.disconnect()}}const Ql=new i(236,236,236),td=new i(130,130,130);class ed{constructor(t,e,i,s,r){this.imageFile=e,this.disabledImageFile=i,this.action=r,this.imageElement=new Image,this.disabledImageElement=new Image,this.toggleButton=!1,this.toolButton=!1,this.pushed=!1,this.disabled=!1,this.loadPromise=new Promise(((t,e)=>{this.imageElement.onload=()=>t()})),this.disabledLoadPromise=new Promise(((t,e)=>{this.disabledImageElement.onload=()=>t()})),this.region={id:`${t.xyGraph.wuid}-${e}`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,t.xyGraph.requestRepaint())},mouseOut:()=>{this.toggleButton||(this.pushed=!1),t.xyGraph.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,t.xyGraph.requestRepaint())},click:()=>{this.toggleButton&&(this.pushed=!this.pushed,this.toolButton&&t.toggleTool(this)),this.action(),t.updateState()},tooltip:()=>s}}loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}}class id{constructor(t){this.xyGraph=t,this.buttons=[],this.imagesLoaded=!1,this.currentTool="default",this.commandBuffer=new Yl,this.showLegend=this.createToggleButton("ShowLegend.png","Show Legend",(()=>{t.properties.setValue("show_legend",this.showLegend.pushed)})),this.showLegend.pushed=t.showLegend,t.addPropertyListener("show_legend",(t=>{this.showLegend.pushed=t})),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",(()=>{const e=new ql(t.getXAxes(),t.getYAxes());t.performAutoScale(),e.saveState(),this.addCommand(e)})),this.rubberbandZoom=this.createToolButton("RubberbandZoom.png","Rubberband Zoom",(()=>{this.rubberbandZoom.pushed?(this.currentTool="rubberband-zoom",t.setCursor("crosshair"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.horizontalZoom=this.createToolButton("HorizontalZoom.png","Horizontal Zoom",(()=>{this.horizontalZoom.pushed?(this.currentTool="horizontal-zoom",t.setCursor("col-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.verticalZoom=this.createToolButton("VerticalZoom.png","Vertical Zoom",(()=>{this.verticalZoom.pushed?(this.currentTool="vertical-zoom",t.setCursor("row-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomIn=this.createToolButton("ZoomIn.png","Zoom In",(()=>{this.zoomIn.pushed?(this.currentTool="zoom-in",t.setCursor("zoom-in"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomOut=this.createToolButton("ZoomOut.png","Zoom Out",(()=>{this.zoomOut.pushed?(this.currentTool="zoom-out",t.setCursor("zoom-out"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.panning=this.createToolButton("Panning.png","Panning",(()=>{this.panning.pushed?(this.currentTool="panning",t.setCursor("grab"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.mouseArrow=this.createToolButton("MouseArrow.png","None",(()=>{this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0})),this.undo=this.createButton("Undo.png","Undo_Gray.png","Undo",(()=>{this.commandBuffer.undo()})),this.undo.disabled=!0,this.redo=this.createButton("Redo.png","Redo_Gray.png","Redo",(()=>{this.commandBuffer.redo()})),this.redo.disabled=!0,this.camera=this.createButton("camera.png","camera.png","Save Snapshot to PNG File",(()=>{const e=document.createElement("a");try{e.href=t.toDataURL(),e.download=`${t.name}_export.png`,document.body.appendChild(e),e.click()}finally{document.body.removeChild(e)}})),this.toggleTool(this.mouseArrow);const e=this.buttons.map((t=>t.loadPromise)).concat(this.buttons.map((t=>t.disabledLoadPromise)));Promise.all(e).finally((()=>{this.imagesLoaded=!0,t.requestRepaint()}));for(const e of this.buttons)e.loadImage(t.display.imagesPrefix)}updateState(){this.undo.disabled=!this.commandBuffer.canUndo(),this.redo.disabled=!this.commandBuffer.canRedo(),this.xyGraph.requestRepaint()}addCommand(t){this.commandBuffer.add(t),this.updateState()}toggleTool(t){const e=t.pushed;for(const t of this.buttons)t.toolButton&&(t.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){const s=this.createToggleButton(t,e,i);return s.toolButton=!0,s}createToggleButton(t,e,i){const s=this.createButton(t,t,e,i);return s.toggleButton=!0,s}createButton(t,e,i,s){const r=new ed(this,t,e,i,s);return this.buttons.push(r),r}draw(t,e){const{buttonSize:i}=this,s={x:e.x,y:e.y};return this.drawButton(t,s.x,s.y,this.showLegend),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.autoScale),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.rubberbandZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.horizontalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.verticalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomIn),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomOut),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.panning),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.mouseArrow),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.undo),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.redo),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.camera),s.x+=i,s.y+i-e.y}maybeWrap(t,e,i){i=null!=i?i:this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){const{buttonSize:s}=this,r=1*this.scale,o=Math.round(e+s/4)-r/2;t.strokePath({path:new V(o,i).lineTo(o,i+s),color:td,lineWidth:r})}drawButton(t,e,s,r){const{buttonSize:o,scale:n}=this;t.fillRect({x:e,y:s,width:o,height:o,color:Ql}),this.xyGraph.enabled&&!r.disabled&&t.addHitRegion(r.region).addRect(e,s,o,o);const h=1*n,a=Math.round(s+h/2)-.5,l=Math.round(e+h/2)-.5,d=Math.round(s+o-h+h/2)-.5,c=Math.round(e+o-h+h/2)-.5;if(t.strokePath({color:r.pushed?i.WHITE:i.BLACK,path:new V(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d),lineWidth:h}),t.strokePath({color:r.pushed?i.BLACK:i.WHITE,path:new V(l,a).lineTo(c-h,a).moveTo(l,a).lineTo(l,d-h),lineWidth:h}),this.imagesLoaded){const i=r.disabled?r.disabledImageElement:r.imageElement,h=i.naturalHeight*n,a=i.naturalWidth*n,l=Math.round(e+(o-a)/2),d=Math.round(s+(o-h)/2);t.ctx.drawImage(i,l,d,a,h)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}}const sd="axis_count",rd="plot_area_background_color",od="show_legend",nd="show_plot_area_border",hd="show_toolbar",ad="title",ld="title_font",dd="trace_count",cd="transparent";class pd extends Pe{constructor(t,e){super(t,e),this.axes=[],this.traces=[],this.autoScaleAllowed=!0,this.properties.add(new k(sd)),this.properties.add(new E(rd)),this.properties.add(new R(od)),this.properties.add(new R(nd)),this.properties.add(new R(hd)),this.properties.add(new L(ad)),this.properties.add(new B(ld)),this.properties.add(new k(dd)),this.properties.add(new R(cd)),this.properties.addGenerator((()=>{const t=[];this.axes=[];const e=this.properties.getValue(sd);for(let i=0;i<e;i++)this.axes.push(new Ul(this,i)),t.push(new R(`axis_${i}_auto_scale`),new M(`axis_${i}_auto_scale_treshold`),new E(`axis_${i}_axis_color`),new L(`axis_${i}_axis_title`),new R(`axis_${i}_dash_grid_line`),new E(`axis_${i}_grid_color`),new R(`axis_${i}_log_scale`),new M(`axis_${i}_maximum`),new M(`axis_${i}_minimum`),new B(`axis_${i}_scale_font`),new L(`axis_${i}_scale_format`),new R(`axis_${i}_show_grid`),new k(`axis_${i}_time_format`),new B(`axis_${i}_title_font`),new R(`axis_${i}_visible`)),i>1&&t.push(new R(`axis_${i}_left_bottom_side`),new R(`axis_${i}_y_axis`));this.traces=[];const i=this.properties.getValue(dd);for(let e=0;e<i;e++)this.traces.push(new Jl(this,e)),t.push(new R(`trace_${e}_anti_alias`),new k(`trace_${e}_buffer_size`),new R(`trace_${e}_concatenate_data`),new k(`trace_${e}_line_width`),new L(`trace_${e}_name`),new k(`trace_${e}_plot_mode`),new k(`trace_${e}_point_size`),new k(`trace_${e}_point_style`),new E(`trace_${e}_trace_color`),new k(`trace_${e}_trace_type`),new k(`trace_${e}_update_delay`),new k(`trace_${e}_update_mode`),new R(`trace_${e}_visible`),new k(`trace_${e}_x_axis_index`),new L(`trace_${e}_x_pv`),new P(`trace_${e}_x_pv_value`,`trace_${e}_x_pv`),new k(`trace_${e}_y_axis_index`),new L(`trace_${e}_y_pv`),new P(`trace_${e}_y_pv_value`,`trace_${e}_y_pv`));return t}))}init(){this.plotAreaRegion=new Xl(`${this.wuid}-plotarea`,this),this.traces.forEach((t=>t.init()))}draw(t){var e;const{scale:i}=this;let s=this.area;if(this.borderAlarmSensitive&&(s=p(this.area,2*i)),!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},s),{color:e}))}this.showToolbar&&this.drawToolbar(t,s),this.title&&this.drawTitle(t,s);for(const t of this.axes){if(t.autoScale&&this.autoScaleAllowed){const e={start:t.minimum,stop:t.maximum},i=this.calculateAutoscaledRange(t,e);i&&(t.effectiveMinimum=i.start,t.effectiveMaximum=i.stop)}const e=t.effectiveMinimum,s=t.effectiveMaximum;t.linearScale=new Pn(i,t.scaleFont,e,s,t.logScale,50*i,t.axisColor,!0,t.visible),t.linearScale.scaleFormat=t.scaleFormat,t.linearScale.timeFormat=t.timeFormat}this.showLegend&&this.drawLegend(t,s),t.addHitRegion(this.plotAreaRegion).addRect(s.x,s.y,s.width,s.height);const r=this.drawAxes(t,s);this.drawPlotArea(t,r);const o=null===(e=this.plotAreaRegion)||void 0===e?void 0:e.selection;o&&this.drawZoomSelection(t,r,function(t,e){let i=t.x,s=t.y,r=i+t.width,o=s+t.height;if(r<i){const t=i;i=r,r=t}if(o<s){const t=s;s=o,o=t}let n=e.x,h=e.y,a=n+e.width,l=h+e.height;if(a<n){const t=n;n=a,a=t}if(l<h){const t=h;h=l,l=t}const d=Math.max(i,n),c=Math.max(s,h);return{x:d,y:c,width:Math.min(r,a)-d,height:Math.min(o,l)-c}}(r,o))}drawToolbar(t,e){this.toolbar||(this.toolbar=new id(this));const i=3*this.scale,s=p(e,i),r=this.toolbar.draw(t,s);e.y+=i+r+i,e.height-=i+r+i}drawTitle(t,e){const i=t.measureText(this.title,this.titleFont).height;t.fillText({x:e.x+e.width/2,y:e.y+i/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.titleFont,text:this.title});const s=2*this.scale;e.y+=i+s,e.height-=i+s}drawAxes(t,e){const{scale:i}=this,s=5*i,r=Object.assign({},e);let o=0;for(const e of this.getXAxes())if(e.visible){let i=0;e.axisTitle&&(i=s+t.measureText(e.axisTitle,e.titleFont).height),o+=i+e.linearScale.measureHorizontalHeight(t)}let n=0,h=0;for(const a of this.getYAxes().reverse()){const l=a.linearScale;if(a.visible){const d=l.calculateMargin(t,!1),c=r.height-o+(o>0?d:0);let p=0;a.axisTitle&&(p=t.measureText(a.axisTitle,a.titleFont).height,t.ctx.save(),t.ctx.translate(r.x+s+p/2,e.y+c/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:a.titleFont,color:a.axisColor,text:a.axisTitle}),t.ctx.restore(),p+=s);const u=p+l.drawVertical(t,r.x+p,e.y,c,!0,!1);r.x+=u,r.width-=u,n+=u;const g=l.margin;h=0===h?g:Math.min(h,g);const m=1*i,f=Math.round(r.x)-m/2,x=Math.round(e.y+d)-m/2;t.strokePath({path:new V(f,x).lineTo(f,x+c-2*d),color:a.axisColor,opacity:100/255,lineWidth:m})}else{const t=r.height-o;l.setDimensions(0,e.y,t,!1)}}let a=0;for(const o of this.getXAxes().reverse()){const h=o.linearScale;if(o.visible){const l=h.calculateMargin(t,!0),d=n-l;let c=0;if(o.axisTitle){c=t.measureText(o.axisTitle,o.titleFont).height;const i=e.x+n+(e.width-n)/2;t.fillText({x:i,y:r.y+r.height-c/2,align:"center",baseline:"middle",font:o.titleFont,color:o.axisColor,text:o.axisTitle}),c+=s}const p=c+h.drawHorizontal(t,e.x+d,r.y+r.height-c,e.width-d);r.height-=p;const u=h.margin;a=0===a?u:Math.min(a,u);const g=1*i,m=Math.round(e.x+d+l)-g/2,f=Math.round(r.y+r.height)-g/2;t.strokePath({path:new V(m,f).lineTo(m+r.width-l,f),color:o.axisColor,opacity:100/255,lineWidth:g})}else{const t=e.x+n,i=e.width-n;h.setDimensions(t,0,i,!0)}}return r.y+=h,r.width-=a,r.height-=o>0?h:2*h,r}drawPlotArea(t,e){const{scale:s}=this,r=1*s;if(t.fillRect(Object.assign(Object.assign({},e),{color:this.plotAreaBackgroundColor})),this.showPlotAreaBorder){const{x:s,y:o,width:n,height:h}=p(e,r/2);t.strokePath({path:new V(s,o).lineTo(s+n,o).lineTo(s+n,o+h),color:i.BLACK,lineWidth:r})}for(const i of this.axes.filter((t=>t.visible&&t.showGrid))){const o=i.linearScale;if(i.isHorizontal())for(const n of o.getGridPositions()){const h=Math.round(o.getX()+n)-r/2;t.strokePath({path:new V(h,e.y).lineTo(h,e.y+e.height),color:i.gridColor,lineWidth:r,dash:i.dashGridLine?[6*s,2*s]:void 0})}else for(const n of o.getGridPositions()){const h=Math.round(o.getY()+n)-r/2;t.strokePath({path:new V(e.x,h).lineTo(e.x+e.width,h),color:i.gridColor,lineWidth:r,dash:i.dashGridLine?[6*s,2*s]:void 0})}}t.ctx.save(),t.ctx.beginPath(),t.ctx.rect(e.x,e.y,e.width,e.height),t.ctx.clip();for(const e of this.traces.filter((t=>t.visible))){const i=this.getAxis(e.xAxisIndex).linearScale,s=this.getAxis(e.yAxisIndex).linearScale,r=[];for(const t of e.snapshot()){const e=i.getValuePosition(t.x),o=null!==t.y?s.getValuePosition(t.y):null;r.push({x:e,y:o})}if(r.length){e.drawTrace(t,r);for(const i of r)null!==i.y&&e.drawPoint(t,i)}}t.ctx.restore()}drawZoomSelection(t,e,s){var r;const{scale:o}=this;switch(null===(r=this.toolbar)||void 0===r?void 0:r.currentTool){case"rubberband-zoom":t.strokeRect(Object.assign(Object.assign({},s),{color:i.BLACK,lineWidth:1*o}));break;case"horizontal-zoom":const r=s;r.y=e.y,r.height=e.height,t.strokeRect(Object.assign(Object.assign({},u(r)),{color:i.BLACK,lineWidth:1*o}));break;case"vertical-zoom":const n=s;n.x=e.x,n.width=e.width,t.strokeRect(Object.assign(Object.assign({},u(n)),{color:i.BLACK,lineWidth:1*o}))}}drawLegend(t,e){const{scale:i}=this,s=25*i,r=2*i,o=5*i,n=tt.ARIAL_10.scale(i);for(const h of this.getYAxes()){const a=this.traces.filter((t=>t.visible&&t.yAxisIndex===h.index)),l=[];let d=[],c=0,u=0;for(const i of a){let h=s+r+o;i.name&&(h+=t.measureText(i.name,n).width),c+h<e.width?(d.push(i),c+=h):(l.push(d),h=Math.max(h,c),d=[i],c=h)}if(d.length&&(l.push(d),u=Math.max(u,c)),!l.length)continue;const g=s*l.length,m={x:Math.round(e.x+(e.width-u)/2),y:Math.round(e.y+e.height-g),width:u,height:g};e.height-=m.height,t.fillRect(Object.assign(Object.assign({},m),{color:this.plotAreaBackgroundColor})),t.strokeRect(Object.assign(Object.assign({},p(m,1*i/2)),{color:h.axisColor}));let f=m.x,x=m.y;for(let e=0;e<l.length;e++){const h=l[e],a=x+e*s,d=a+s/2;for(const e of h){const h=e.pointSize>Math.floor((s-o)/2)?Math.floor(s-o):e.pointSize;switch(e.traceType){case 3:const r=f+s/2;t.strokePath({path:new V(r,a+h).lineTo(r,a+s),lineWidth:e.lineWidth,color:e.traceColor,opacity:100/255}),e.drawPoint(t,{x:r,y:a+h});break;case 4:case 5:const o=[{x:f,y:a+s/2},{x:f+s/2,y:a+h},{x:f+s,y:a+s/2},{x:f+s,y:a+s},{x:f,y:a+s}];t.fillPath({path:V.fromPoints(o),color:e.traceColor,opacity:100/255}),5===e.traceType&&t.strokePath({path:V.fromPoints(o.slice(0,3)),color:e.traceColor,lineWidth:1*i}),e.drawPoint(t,{x:f+s/2,y:a+h});break;default:e.drawTrace(t,[{x:f,y:d},{x:f+s,y:d}]),e.drawPoint(t,{x:f+s/2,y:d})}f+=s+r,e.name&&(t.fillText({x:f,y:d,align:"left",baseline:"middle",color:e.traceColor,font:n,text:e.name}),f+=t.measureText(e.name,n).width),f+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t,e){let i,s;const r=t.logScale;for(const e of this.traces)if(e.visible&&(this.axes[e.xAxisIndex]===t||this.axes[e.yAxisIndex]===t))for(const o of e.snapshot()){const e=t.isHorizontal()?o.x:o.y;null!==e&&((void 0===i||i>e)&&(!r||e>0)&&(i=e),(void 0===s||s<e)&&(!r||e>0)&&(s=e))}if(void 0!==i&&void 0!==s)return i===s?{start:Math.min(i,e.start),stop:Math.max(s,e.stop)}:{start:i,stop:s}}performAutoScale(){for(const t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(const t of this.traces)t.clearData();this.requestRepaint()}getAxes(){return[...this.axes]}getXAxes(){return this.axes.filter((t=>t.isHorizontal()))}getYAxes(){return this.axes.filter((t=>t.isVertical()))}getAxis(t){return this.axes[t]}getTrace(t){return this.traces[t]}get axisCount(){return this.properties.getValue(sd)}get plotAreaBackgroundColor(){return this.properties.getValue(rd)}get showLegend(){return this.properties.getValue(od)}get showPlotAreaBorder(){return this.properties.getValue(nd)}get showToolbar(){return this.properties.getValue(hd)}get title(){return this.properties.getValue(ad)}get titleFont(){return this.properties.getValue(ld).scale(this.scale)}get traceCount(){return this.properties.getValue(dd)}get transparent(){return this.properties.getValue(cd)}destroy(){for(const t of this.traces)t.destroy()}}class ud extends Me{parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){const e=t.createChild(this.width,this.height);for(const t of this.widgets.filter((t=>t.visible)))t.drawHolder(e),t.draw(e),t.drawDecoration(e);for(const t of this.widgets.filter((t=>t.visible)))t.drawOverlay(e);t.copy(e,this.x,this.y)}}const gd="minimum_tab_height",md="active_tab",fd="horizontal_tabs",xd="tab_count";class wd{constructor(t,e){this.widget=t,this.i=e,this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(md,e),t.requestRepaint())},cursor:"pointer"}}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`tab_${this.i}_${t}`)}get title(){return this.getValue("title")}get backgroundColor(){return this.getValue("background_color")}get foregroundColor(){return this.getValue("foreground_color")}get enabled(){return this.getValue("enabled")}get font(){return this.getValue("font").scale(this.scale)}}class yd extends Me{constructor(t,e){super(t,e),this.tabs=[],this.properties.add(new k(gd)),this.properties.add(new k(md)),this.properties.add(new R(fd)),this.properties.add(new k(xd)),this.properties.addGenerator((()=>{this.tabs=[];const t=this.properties.getValue(xd),e=[];for(let i=0;i<t;i++)this.tabs.push(new wd(this,i)),e.push(new L(`tab_${i}_title`),new E(`tab_${i}_background_color`),new E(`tab_${i}_foreground_color`),new R(`tab_${i}_enabled`),new B(`tab_${i}_font`));return e}))}parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.horizontalTabs?this.drawHorizontalTabs(t):this.drawVerticalTabs(t)}measureTabOffset(t){return this.horizontalTabs?{x:0,y:this.measureLabelHeight(t)}:{x:this.measureLabelWidth(t),y:0}}measureLabelHeight(t){const{scale:e}=this,i=1*e;let s=this.minimumTabHeight;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).height+i;o>s&&(s=o)}return s+this.margin}measureLabelWidth(t){const{scale:e}=this,i=1*e;let s=this.minimumTabWidth;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).width+i;o>s&&(s=o)}return s+this.margin}drawHorizontalTabs(t){const{margin:e,gap:s,scale:r}=this,o=this.measureLabelHeight(t),n=1*r;let h=this.x;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=t.measureText(l.title,l.font);let c,p,u,g,m;this.activeTab===a?(c=h,p=this.y,u=d.width+n+e+s,g=o,m=l.backgroundColor):(c=h+s,p=this.y+2*r,u=d.width+n+e-s,g=o-2*r,m=this.darken(l.backgroundColor)),t.fillRect({x:c,y:p,width:u,height:g,color:m});t.addHitRegion(l.headerRegion).addRect(c,p,u,g);const f=t.createLinearGradient(c,p,c,p+g);if(f.addColorStop(0,i.WHITE.toString()),f.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:c,y:p,width:u,height:g,gradient:f}),t.fillText({x:c+u/2,y:p+g/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),h+=d.width+n+e-1*r,this.activeTab===a){const e=this.x,i=this.y+o,s=this.width,r=this.height-o;t.fillRect({x:e,y:i,width:s,height:r,color:l.backgroundColor});const n=this.widgets[a],h=t.createChild(s,r);n.drawHolder(h),n.draw(h),n.drawDecoration(h),n.drawOverlay(h),t.copy(h,e,i)}else{this.widgets[a].hide()}}}drawVerticalTabs(t){const{margin:e,gap:s,scale:r}=this,o=this.measureLabelWidth(t),n=1*r;let h=this.y;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=t.measureText(l.title,l.font),c=Math.max(d.height+n+n,this.minimumTabHeight);let p,u,g,m,f;this.activeTab===a?(p=this.x,u=h,g=o,m=c+e+s,f=l.backgroundColor):(p=this.x+2*r,u=h+s,g=o-2*r,m=c+e-s,f=this.darken(l.backgroundColor)),t.fillRect({x:p,y:u,width:g,height:m,color:f});t.addHitRegion(l.headerRegion).addRect(p,u,g,m);const x=t.createLinearGradient(p,u,p+g,u);if(x.addColorStop(0,i.WHITE.toString()),x.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:p,y:u,width:g,height:m,gradient:x}),t.fillText({x:p+g/2,y:u+m/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),h+=c+e-1*r,this.activeTab===a){const e=this.x+o-1*r,i=this.y,s=this.width-o,n=this.height-1*r;t.fillRect({x:e,y:i,width:s,height:n,color:l.backgroundColor});const h=this.widgets[a],d=t.createChild(s,n);h.drawHolder(d),h.draw(d),h.drawDecoration(d),h.drawOverlay(d),t.copy(d,e,i)}else{this.widgets[a].destroy()}}}darken(t){const e=Math.max(0,t.red-30),s=Math.max(0,t.green-30),r=Math.max(0,t.blue-30);return new i(e,s,r)}get margin(){return 10*this.scale}get gap(){return 2*this.scale}get minimumTabWidth(){return 20*this.scale}get minimumTabHeight(){return this.scale*this.properties.getValue(gd)}get activeTab(){return this.properties.getValue(md)}get tabCount(){return this.properties.getValue(xd)}get horizontalTabs(){return this.properties.getValue(fd)}}class vd{constructor(t){this.table=t,this.columnCount=0,this.cells=[],this.dirty=!1,this.modifiedListeners=[],this.selectionChangedListeners=[]}isEmpty(){return!this.cells.length}refresh(){this.dirty=!0}getCells(){return this.cells}getContent(){const t=[];for(const e of this.cells)t.push(e.map((t=>t.text||"")));return t}setContent(t){this.cells.length=0;for(let e=0;e<t.length;e++)0===e&&(this.columnCount=t[e].length),this.cells.push(t[e].map((t=>({text:t}))));this.dirty=!0}getColumnCount(){return this.columnCount}getRowCount(){return this.cells.length}setSelectedRowIndex(t){this.selectedRowIndex=t,this.selectionChangedListeners.forEach((t=>t())),this.dirty=!0}getSelection(){if(void 0===this.selectedRowIndex)return[];return[[...this.cells[this.selectedRowIndex].map((t=>{var e;return null!==(e=t.text)&&void 0!==e?e:null}))]]}getCellText(t,e){var i,s;const r=this.cells[t];return r&&null!==(s=null===(i=r[e])||void 0===i?void 0:i.text)&&void 0!==s?s:null}setColumnsCount(t){if(t<this.columnCount)for(const e of this.cells)e.length=t;if(t>this.columnCount){const e=t-this.columnCount;for(const t of this.cells)for(let i=0;i<e;i++)t.push({text:""})}this.columnCount=t,this.dirty=!0}addModifiedListener(t){this.modifiedListeners.push(t)}addSelectionChangedListener(t){this.selectionChangedListeners.push(t)}appendRow(){const t=[];for(let e=0;e<this.columnCount;e++)t[e]={text:""};return this.cells.push(t),this.dirty=!0,this.cells.length-1}deleteRow(t){this.cells.splice(t,1),this.dirty=!0}deleteColumn(t){for(const e of this.cells)e.splice(t,1);this.columnCount--,this.dirty=!0}insertRow(t){const e=[];for(let t=0;t<this.columnCount;t++)e.push({text:""});this.cells.splice(t,0,e),this.dirty=!0}insertColumn(t){for(const e of this.cells)e.splice(t,0,{text:""});this.columnCount++,this.dirty=!0}getCell(t,e){var i,s;this.cells[t]=null!==(i=this.cells[t])&&void 0!==i?i:[];const r=null!==(s=this.cells[t][e])&&void 0!==s?s:{};return this.cells[t][e]=r,r}setCellText(t,e,i){this.getCell(t,e).text=i,this.dirty=!0}setRowBackground(t,e){const i=this.cells[t];for(const t of i)t.backgroundColor=e;this.dirty=!0}setRowForeground(t,e){const i=this.cells[t];for(const t of i)t.foregroundColor=e;this.dirty=!0}setCellBackground(t,e,i){this.getCell(t,e).backgroundColor=i,this.dirty=!0}setCellForeground(t,e,i){this.getCell(t,e).foregroundColor=i,this.dirty=!0}setColumnCellEditorData(t,e){}}const bd="columns_count",Td="column_headers",Sd="column_header_visible",Vd="default_content",Cd="font";class _d extends Pe{constructor(t,e){super(t,e),this.properties.add(new k(bd)),this.properties.add(new $(Td)),this.properties.add(new R(Sd)),this.properties.add(new $(Vd)),this.properties.add(new B(Cd)),this.spreadsheet=new vd(this)}init(){this.tableWrapper=document.createElement("div"),this.tableWrapper.style.display="none",this.tableWrapper.style.overflow="auto",this.table=document.createElement("table"),this.table.style.tableLayout="fixed",this.table.style.borderSpacing="0",this.table.style.borderCollapse="collapse",this.tableWrapper.appendChild(this.table),this.display.rootPanel.appendChild(this.tableWrapper),this.table.addEventListener("click",(t=>{const e=t.target;if("TD"===e.tagName){const t=e.parentElement;t.rowIndex>0&&this.spreadsheet.setSelectedRowIndex(t.rowIndex-1)}else this.spreadsheet.setSelectedRowIndex(void 0);this.requestRepaint()})),this.spreadsheet.setContent(this.defaultContent)}draw(t){if(this.tableWrapper){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.tableWrapper.style.backgroundColor="white",this.tableWrapper.style.position="absolute",this.tableWrapper.style.display="block",this.tableWrapper.style.left=`${t}px`,this.tableWrapper.style.top=`${e}px`,this.tableWrapper.style.width=`${i}px`,this.tableWrapper.style.height=`${s}px`,this.tableWrapper.style.border="1px solid rgba(0, 0, 0, 0.1)",this.table.style.font=this.font.getFontString(),this.spreadsheet.dirty&&(this.generateTableContent(),this.spreadsheet.dirty=!1)}}generateTableContent(){for(let t=this.table.rows.length-1;t>=0;t--)this.table.deleteRow(t);if(this.columnHeaderVisible){const t=this.table.insertRow();for(let e=0;e<this.columnsCount;e++){const i=this.columnHeaders[e],s=t.insertCell();s.style.color="#aaa",s.style.textAlign="left",s.style.width=Number(i[1])*this.scale+"px",s.style.overflow="hidden",s.style.padding=4*this.scale+"px",s.style.borderBottom="1px solid rgba(0, 0, 0, 0.1)",0!==e&&(s.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)");const r=document.createTextNode(i[0]);s.appendChild(r)}t.insertCell()}const t=this.spreadsheet.getCells();for(let e=0;e<t.length;e++){const s=t[e],r=e===this.spreadsheet.selectedRowIndex,o=this.table.insertRow();for(let t=0;t<this.columnsCount;t++){const e=o.insertCell();if(e.style.textAlign="left",e.style.overflow="hidden",e.style.wordWrap="break-word",e.style.textOverflow="ellipsis",e.style.padding=4*this.scale+"px",0!==t&&(e.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)"),void 0!==s[t]){const o=r?i.BLUE:s[t].backgroundColor;o&&(e.style.backgroundColor=o.toString());const n=r?i.WHITE:s[t].foregroundColor;n&&(e.style.color=n.toString());const h=document.createTextNode(s[t].text||"");e.appendChild(h)}}o.insertCell()}}hide(){this.tableWrapper&&(this.tableWrapper.style.display="none")}destroy(){this.tableWrapper&&(this.display.rootPanel.removeChild(this.tableWrapper),this.tableWrapper=void 0,this.table=void 0)}get columnsCount(){return this.properties.getValue(bd)}get columnHeaders(){return this.properties.getValue(Td)}get columnHeaderVisible(){return this.properties.getValue(Sd)}get defaultContent(){return this.properties.getValue(Vd)}get font(){return this.properties.getValue(Cd).scale(this.scale)}}class Ad extends Pe{constructor(t,e){super(t,e),this.properties.add(new L("url"))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${t}px`,this.iframe.style.top=`${e}px`,this.iframe.style.width=`${i}px`,this.iframe.style.height=`${s}px`,this.url&&this.prevUrl!==this.url&&(this.iframe.src=this.url,this.prevUrl=this.url)}}hide(){this.iframe&&(this.iframe.style.display="none")}destroy(){this.iframe&&(this.display.rootPanel.removeChild(this.iframe),this.iframe=void 0)}get url(){return this.properties.getValue("url")}}class Ld{constructor(i){this.targetElement=i,this.repaintRequested=!1,this._editMode=!1,this._showGrid=!1,this._showOutline=!1,this._showRuler=!1,this._selection=[],this._scale=1,this._transparent=!1,this.refreshCycle=100,this.imagesPrefix="",this.absPrefix="",this.relPrefix="",this.eventListeners={closedisplay:[],opendisplay:[],openpv:[],runcommand:[],runprocedure:[],selection:[],scale:[]},this.rootPanel=document.createElement("div"),this.rootPanel.className="display-root",this.rootPanel.style.overflow="hidden",this.rootPanel.style.position="relative",this.rootPanel.style.fontSize="0",i.appendChild(this.rootPanel);const s=document.createElement("canvas");this.rootPanel.appendChild(s),this.g=new S(s),this.ctx=this.g.ctx,this.pvEngine=new wi(this),this.pvEngine.addProvider(new Li),this.pvEngine.addProvider(new di),this.displayRegion={id:"display-root",click:()=>{for(const t of this.rootPanel.getElementsByTagName("input"))t.blur();for(const t of this.rootPanel.getElementsByTagName("textarea"))t.blur();for(const t of this.rootPanel.getElementsByTagName("select"))t.blur()}},this.pathResolver=new ri(this),this.consoleHandler=new t,this.dialogHandler=new e,window.setTimeout((()=>this.step())),new n(this,s,this.g.hitCanvas)}addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}setPathResolver(t){this.pathResolver=t}getPathResolver(){return this.pathResolver}setConsoleHandler(t){this.consoleHandler=t}getConsoleHandler(){return this.consoleHandler}setDialogHandler(t){this.dialogHandler=t}getDialogHandler(){return this.dialogHandler}setFontResolver(t){this.fontResolver=t}getFontResolver(){return this.fontResolver}step(){this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.setTimeout((()=>this.step()),this.refreshCycle)}drawScreen(){var t;if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="#d6d6d6",e.fillRect(0,0,8,8),e.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.instance&&this.g.fillRect(Object.assign(Object.assign({},this.instance.bounds),{color:this.instance.backgroundColor}))}else this.transparent||this.g.fillCanvas((null===(t=this.instance)||void 0===t?void 0:t.backgroundColor)||i.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=25,t.height=25,e.fillStyle=this.instance.foregroundColor.toString(),e.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let t=0;for(;t<=this.ctx.canvas.width;)t+=100,this.ctx.beginPath(),this.ctx.moveTo(t-75+.5,this.ctx.canvas.height),this.ctx.lineTo(t-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t-50+.5,this.ctx.canvas.height),this.ctx.lineTo(t-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(t-25+.5,this.ctx.canvas.height),this.ctx.lineTo(t-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t+.5,this.ctx.canvas.height),this.ctx.lineTo(t+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(t),t,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let e=0;for(;e<=this.ctx.canvas.height;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,e-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-75+.5),this.ctx.moveTo(this.ctx.canvas.width,e-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,e-50+.5),this.ctx.moveTo(this.ctx.canvas.width,e-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-25+.5),this.ctx.moveTo(this.ctx.canvas.width,e+.5),this.ctx.lineTo(this.ctx.canvas.width-8,e+.5),this.ctx.stroke(),this.ctx.fillText(String(e),this.ctx.canvas.width-8,e)}this.showOutline&&this.instance&&(this.ctx.lineWidth=1,this.ctx.setLineDash([10,5]),this.ctx.strokeStyle="black",this.ctx.strokeRect(-.5,-.5,this.instance.holderWidth+1,this.instance.holderHeight+1),this.ctx.setLineDash([])),this.instance&&this.instance.draw(this.g);for(const t of this.selection){const e=this.findWidget(t);e&&e.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){var e;this.rootPanel.title=null!==(e=null==t?void 0:t.trim())&&void 0!==e?e:""}createWidget(t,e){switch(t){case"Action Button":return new Wi(this,e);case"Arc":return new Er(this,e);case"Boolean Button":return new Zi(this,e);case"Boolean Switch":return new ls(this,e);case"Byte Monitor":return new Ko(this,e);case"Check Box":return new fs(this,e);case"Choice Button":return new Ss(this,e);case"Combo":case"Combo Box":return new Ps(this,e);case"Ellipse":return new jr(this,e);case"Gauge":return new yn(this,e);case"Grouping Container":return new ud(this,e);case"Image":return new qr(this,e);case"Image Boolean Button":return new js(this,e);case"Image Boolean Indicator":return new An(this,e);case"Intensity Graph":return new hh(this,e);case"Label":return new Jr(this,e);case"LED":return new Th(this,e);case"Linking Container":return new si(this,e);case"Menu Button":return new Us(this,e);case"Meter":return new Uh(this,e);case"Button":return new qs(this,e);case"Polygon":return new no(this,e);case"Polyline":return new fo(this,e);case"Progress Bar":return new Aa(this,e);case"Radio Box":return new ir(this,e);case"Rectangle":return new _o(this,e);case"Rounded Rectangle":return new Oo(this,e);case"Scrollbar":return new mr(this,e);case"Tabbed Container":return new yd(this,e);case"Table":return new _d(this,e);case"Tank":return new il(this,e);case"Text Input":return new _r(this,e);case"Text Update":return new dl(this,e);case"Thermometer":return new jl(this,e);case"Web Browser":return new Ad(this,e);case"XY Graph":return new pd(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){var t;null===(t=this.instance)||void 0===t||t.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}resolvePath(t,e){return this.pathResolver.resolve(t,e)}setSource(t,e){this.reset();const i=t.lastIndexOf("/")+1;return this.relPrefix=t.substring(0,i),new Promise(((i,s)=>{fetch(t,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.setSourceString(t,e),i()})).catch((t=>s(t)))})).catch((t=>s(t)))}))}setSourceString(t,e){this.reset(),this.instance=new Je(this,void 0,e);const i=re.parseFromXML(t);this.instance.parseNode(i),this.pvEngine.init(),this.requestRepaint()}getRefreshCycle(){return this.refreshCycle}setRefreshCycle(t){this.refreshCycle=t}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0)}measureAbsoluteArea(t){const e=t.bounds;let i=t.parent;for(;i;){if(e.x+=i.x,e.y+=i.y,i instanceof yd){const{x:t,y:s}=i.measureTabOffset(this.g);e.x+=t,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=1*this.scale,e.y+=1*this.scale,e}addEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t].push(e)}removeEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t]=this.eventListeners[t].filter((t=>t!==e))}fireEvent(t,e){this.eventListeners[t].forEach((t=>t(e)))}get showGrid(){return this._showGrid}set showGrid(t){this._showGrid=t,this.requestRepaint()}get showOutline(){return this._showOutline}set showOutline(t){this._showOutline=t,this.requestRepaint()}get showRuler(){return this._showRuler}set showRuler(t){this._showRuler=t,this.requestRepaint()}get selection(){return this._selection}set selection(t){this._selection=t,this.requestRepaint();const e={selected:this._selection.slice()};this.fireEvent("selection",e)}get editMode(){return this._editMode}set editMode(t){this._editMode=t,this.requestRepaint()}get scale(){return this._scale}set scale(t){this._scale=t,this.requestRepaint();const e={scale:t};this.fireEvent("scale",e)}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get widgets(){return this.instance?this.instance.widgets:[]}clearSelection(){this.selection.length&&(this.selection=[])}findWidget(t){if(this.instance)return this.instance.findWidget(t)}findWidgetByName(t){if(this.instance)return this.instance.findWidgetByName(t)}getPVNames(){return this.pvEngine.getPVNames()}getPV(t){return this.pvEngine.getPV(t)}setValues(t){this.pvEngine.setValues(t)}copyCanvas(t){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}}export{wt as AlarmSeverity,oi as CompiledFormula,t as DefaultConsoleHandler,e as DefaultDialogHandler,ri as DefaultPathResolver,Ld as Display,tt as Font,li as FormulaCompiler,xt as PV,Pe as Widget};
|
|
1
|
+
class t{writeInfo(t){console.log(t)}writeError(t){console.error(t)}writeWarning(t){console.warn(t)}}class e{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){const s=prompt(e);return!!s&&s===i}}class i{constructor(t,e,i,s=255){this.red=t,this.green=e,this.blue=i,this.alpha=s}withAlpha(t){return new i(this.red,this.green,this.blue,t)}mixWith(t,e){const s=Math.floor(this.red*e+t.red*(1-e)),r=Math.floor(this.green*e+t.green*(1-e)),o=Math.floor(this.blue*e+t.blue*(1-e));return new i(s,r,o)}brighter(){let{red:t,green:e,blue:s}=this;const r=Math.floor(1/(1-.7));return 0===t&&0===e&&0===s?new i(r,r,r):(t>0&&t<r&&(t=r),e>0&&e<r&&(e=r),s>0&&s<r&&(s=r),new i(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 i(Math.max(Math.floor(.7*this.red),0),Math.max(Math.floor(.7*this.green),0),Math.max(Math.floor(.7*this.blue),0))}contrast(){return new i(this.red,255-this.green,255-this.blue)}hex(){let t=this.red.toString(16);t=1==t.length?"0"+t:t;let e=this.green.toString(16);e=1==e.length?"0"+e:e;let i=this.blue.toString(16);i=1==i.length?"0"+i:i;let s=this.alpha.toString(16);return s=1==s.length?"0"+s:s,`#${t}${e}${i}${s}`}getRGBValue(){return this}equals(t){return t&&this.toString()===t.toString()}toString(){return`rgba(${this.red},${this.green},${this.blue},${this.alpha})`}}i.TRANSPARENT=new i(0,0,0,0),i.BLACK=new i(0,0,0),i.BLUE=new i(0,0,255),i.CYAN=new i(0,255,255),i.DARK_GRAY=new i(150,150,150),i.GRAY=new i(200,200,200),i.GREEN=new i(0,255,0),i.LIGHT_BLUE=new i(153,186,243),i.ORANGE=new i(255,128,0),i.PINK=new i(255,0,255),i.PURPLE=new i(128,0,255),i.RED=new i(255,0,0),i.WHITE=new i(255,255,255),i.YELLOW=new i(255,255,0),i.BUTTON=new i(239,240,241),i.BUTTON_DARKER=new i(164,168,172),i.BUTTON_DARKEST=i.BLACK,i.BUTTON_LIGHTEST=i.WHITE;const s=t=>(document.removeEventListener("click",s,!0),t.preventDefault(),t.stopPropagation(),!1);function r(t){return!(1&~t.buttons)||void 0===t.buttons&&1==t.which}function o(t,e){return t&&e&&t.id===e.id}class n{constructor(t,e,i){this.display=t,this.canvas=e,this.hitCanvas=i,this.grabbing=!1,this.documentMouseMoveListener=t=>this.onDocumentMouseMove(t),this.documentMouseUpListener=t=>this.onDocumentMouseUp(t),e.addEventListener("click",(t=>this.onCanvasClick(t)),!1),e.addEventListener("mousedown",(t=>this.onCanvasMouseDown(t)),!1),e.addEventListener("mouseup",(t=>this.onCanvasMouseUp(t)),!1),e.addEventListener("mouseout",(t=>this.onCanvasMouseOut(t)),!1),e.addEventListener("mousemove",(t=>this.onCanvasMouseMove(t)),!1)}toPoint(t){const e=this.canvas.getBoundingClientRect();return{x:t.clientX-e.left,y:t.clientY-e.top}}onCanvasClick(t){this.display.clearSelection();const e=this.toPoint(t);if(this.display.editMode)this.selectSingleWidget(e.x,e.y);else{const i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.click&&i.click({clientX:t.clientX,clientY:t.clientY,point:e})}}onCanvasMouseDown(t){if(!this.display.editMode&&(document.removeEventListener("click",s,!0),r(t))){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);return i&&i.mouseDown&&i.mouseDown({clientX:t.clientX,clientY:t.clientY,point:e}),i&&i.grab&&(this.grabPoint=Object.assign({},e),this.grabTarget=i),t.preventDefault(),t.stopPropagation(),!1}}onCanvasMouseUp(t){if(this.display.editMode)return;const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);i&&i.mouseUp&&i.mouseUp()}onCanvasMouseOut(t){this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&this.prevEnteredRegion.mouseOut(),this.prevEnteredRegion=void 0,t.preventDefault(),t.stopPropagation()}onCanvasMouseMove(t){const e=this.toPoint(t),i=this.hitCanvas.getActiveRegion(e.x,e.y);this.prevEnteredRegion&&this.prevEnteredRegion.mouseOut&&(o(this.prevEnteredRegion,i)||this.prevEnteredRegion.mouseOut()),i&&i.mouseEnter&&(o(this.prevEnteredRegion,i)||i.mouseEnter()),this.prevEnteredRegion=i;const s=i&&i.cursor?i.cursor:"auto";if(s!=this.canvas.style.cursor&&(this.canvas.style.cursor=s),!this.grabbing&&i&&i.tooltip?this.display.setTooltip(i.tooltip()):this.display.setTooltip(void 0),this.grabPoint&&!this.grabbing&&r(t)){const t=(n=this.grabPoint.x,h=this.grabPoint.y,a=e.x,l=e.y,Math.sqrt((a-n)*(a-n)+(l-h)*(l-h)));Math.abs(t)>5&&(this.initiateGrab(),this.grabPoint&&(this.grabPoint=e))}var n,h,a,l;this.grabbing&&this.grabTarget&&r(t)&&this.grabTarget.grab({clientX:t.clientX,clientY:t.clientY,point:e,dx:e.x-this.grabPoint.x,dy:e.y-this.grabPoint.y})}initiateGrab(){document.addEventListener("click",s,!0),document.addEventListener("mouseup",this.documentMouseUpListener),document.addEventListener("mousemove",this.documentMouseMoveListener),this.grabbing=!0}onDocumentMouseUp(t){if(this.grabbing){document.removeEventListener("mouseup",this.documentMouseUpListener),document.removeEventListener("mousemove",this.documentMouseMoveListener);const t=this.grabTarget;this.grabbing=!1,this.grabPoint=void 0,this.grabTarget=void 0,(null==t?void 0:t.grabEnd)&&t.grabEnd()}}onDocumentMouseMove(t){this.onCanvasMouseMove(t)}selectSingleWidget(t,e){const i=this.display.instance;if(i)for(const s of i.widgets.slice().reverse()){const i=s.holderX,r=s.holderY,o=s.holderX+s.holderWidth,n=s.holderY+s.holderHeight;if(i<t&&t<o&&r<e&&e<n)return this.display.selection=[s.wuid],!1}}}const h="rgb(255,255,255)",a=!!navigator.brave;class l{constructor(t,e,i){this.parent=t,this.regionsByColor=new Map;const s=document.createElement("canvas");s.width=null!=e?e:s.width,s.height=null!=i?i:s.height,this.ctx=s.getContext("2d",{willReadFrequently:!0}),this.root=(null==t?void 0:t.root)||t}clear(){this.regionsByColor.clear(),this.ctx.fillStyle=h,this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}beginHitRegion(t){const e=(this.root||this).generateUniqueColor(t);return this.ctx.beginPath(),this.ctx.fillStyle=e,e}getActiveRegion(t,e){const i=this.ctx.getImageData(t,e,1,1).data,s=`rgb(${i[0]},${i[1]},${i[2]})`;return this.regionsByColor.get(s)||void 0}createChild(t,e){return new l(this,t,e)}transferToParent(t,e,i,s){if(!this.parent)throw new Error("No parent to transfer to");this.parent.ctx.drawImage(this.ctx.canvas,t,e,i,s)}generateUniqueColor(t){for(;;){const e=Math.round(255*Math.random()),i=Math.round(255*Math.random()),s=Math.round(255*Math.random()),r=`rgb(${e},${i},${s})`;if(!this.regionsByColor.has(r)&&r!==h)return a?(this.regionsByColor.set(`rgb(${e-1},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e-1},${i+1},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i},${s})`,t),this.regionsByColor.set(`rgb(${e},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e},${i+1},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i-1},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i},${s+1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s-1})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s})`,t),this.regionsByColor.set(`rgb(${e+1},${i+1},${s+1})`,t)):this.regionsByColor.set(r,t),r}}}function d(t,e,i,s,r){return p({x:t,y:e,width:i,height:s},r/2)}function c(t,e,i,s,r){const o=Math.sin(r),n=Math.cos(r),h=t-i,a=e-s;return{x:h*n-a*o+i,y:h*o+a*n+s}}function p(t,e,i){return void 0===i&&(i=e),{x:t.x+i,y:t.y+e,width:t.width-(i+i),height:t.height-(e+e)}}function u(t){return{x:Math.round(t.x)+.5,y:Math.round(t.y)+.5,width:Math.round(t.width),height:Math.round(t.height)}}function g(t,e,i){return{x:t.x+e,y:t.y+i}}function m(t,e,i){return t.map((t=>g(t,e,i)))}function f(t){return t*Math.PI/180}function x(t,e,i){const s=Math.floor(t*Math.cos(e)),r=Math.floor(-t*Math.sin(e));return{x:i.x+i.width/2+s,y:i.y+i.height/2+r}}function w(t,e){const i=e.x-t.x,s=e.y-t.y,r=Math.sqrt(Math.pow(i,2)+Math.pow(s,2));let o=Math.acos(i/r);return s>0&&(o=2*Math.PI-o),new y(Math.floor(r),o)}class y{constructor(t,e){this.r=t,this.theta=e}toPoint(){return{x:Math.floor(this.r*Math.cos(this.theta)),y:Math.floor(-this.r*Math.sin(this.theta))}}}function v(t,e){return t.map((t=>({x:t.x*e,y:t.y*e})))}function b(t,e,i,s,r,o,n){t.beginPath(),o||n?(s<2*o&&(o=s/2),r<2*n&&(n=r/2),t.moveTo(e+o,i),t.lineTo(e+s-o,i),t.quadraticCurveTo(e+s,i,e+s,i+n),t.lineTo(e+s,i+r-n),t.quadraticCurveTo(e+s,i+r,e+s-o,i+r),t.lineTo(e+o,i+r),t.quadraticCurveTo(e,i+r,e,i+r-n),t.lineTo(e,i+n),t.quadraticCurveTo(e,i,e+o,i)):t.rect(e,i,s,r)}function T(t,e,i){return null===t?"":"string"==typeof t?t:"number"==typeof t?-1===i?S(e,t,void 0,3):S(e,t,i,i):t instanceof Date?t.toISOString().replace("T"," ").replace("Z",""):String(t)}function S(t,e,i,s){if(null==e||null==e)return"";switch(t){case 0:case 1:const r={minimumFractionDigits:i,maximumFractionDigits:s,useGrouping:!1,roundingMode:"halfEven"};return Intl.NumberFormat("en-US",r).format(e);case 2:return e.toExponential(s).replace("e+","E").toUpperCase();case 3:return"0x"+e.toString(16).toUpperCase();default:return console.warn(`Unexpected format type ${t}`),String(e)}}class V{constructor(t,e){this.canvas=t,this.ctx=t.getContext("2d"),this.hitCanvas=e||new l,this.hitCtx=this.hitCanvas.ctx}createChild(t,e){const i=this.hitCanvas.createChild(t,e),s=document.createElement("canvas");return s.width=t,s.height=e,new V(s,i)}translate(t,e){this.ctx.translate(t,e),this.hitCtx.translate(t,e)}copy(t,e,i){this.ctx.drawImage(t.canvas,e,i),t.hitCanvas.transferToParent(e,i,t.canvas.width,t.canvas.height)}copyFitted(t,e,i,s,r){const{width:o,height:n}=t.canvas,h=o/n;let a=s,l=a/h;l>r&&(l=r,a=l*h),this.copyScaled(t,e,i,a,l)}copyScaled(t,e,i,s,r){this.ctx.drawImage(t.canvas,e,i,s,r),t.hitCanvas.transferToParent(e,i,s,r)}clearHitCanvas(){this.hitCanvas.clear()}fillCanvas(t){this.ctx.fillStyle=t.toString(),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}clearCanvas(){this.ctx.clearRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height)}scaleCanvas(t,e){this.ctx.canvas.style.width=t+"px",this.ctx.canvas.style.height=e+"px"}resize(t,e){this.ctx.canvas.width==t&&this.ctx.canvas.height==e||(this.ctx.canvas.width=t,this.ctx.canvas.height=e,this.hitCanvas.ctx.canvas.width=t,this.hitCanvas.ctx.canvas.height=e)}fillRect(t){this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),t.rx||t.ry?(b(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.fill()):this.ctx.fillRect(t.x,t.y,t.width,t.height),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}fillText(t){this.ctx.textBaseline=t.baseline,this.ctx.textAlign=t.align,this.ctx.font=t.font.getFontString(),this.ctx.fillStyle=t.color.toString(),this.ctx.fillText(t.text,t.x,t.y)}fillEllipse(t){this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill(),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}strokeEllipse(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.lineWidth=t.lineWidth||1,this.ctx.beginPath();const e=t.startAngle||0,i=void 0===t.endAngle?2*Math.PI:t.endAngle;this.ctx.ellipse(t.cx,t.cy,t.rx,t.ry,0,e,i,t.anticlockwise),this.ctx.strokeStyle="color"in t?t.color.toString():t.gradient,this.ctx.stroke(),t.dash&&this.ctx.setLineDash([])}measureText(t,e){this.ctx.font=e.getFontString();return{width:this.ctx.measureText(t).width,height:e.height}}createLinearGradient(t,e,i,s){return this.ctx.createLinearGradient(t,e,i,s)}strokeRect(t){t.dash&&this.ctx.setLineDash(t.dash);const e=t.lineWidth||1;if(this.ctx.lineWidth=e,this.ctx.strokeStyle=t.color.toString(),t.crispen&&e){const i=p(t,e/2,e/2);t.rx||t.ry?(b(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?(b(this.ctx,t.x,t.y,t.width,t.height,t.rx||0,t.ry||0),this.ctx.stroke()):this.ctx.strokeRect(t.x,t.y,t.width,t.height);t.dash&&this.ctx.setLineDash([])}strokePath(t){t.dash&&this.ctx.setLineDash(t.dash),this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.lineWidth=t.lineWidth||1,this.ctx.strokeStyle=t.color.toString(),void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.stroke(),void 0!==t.opacity&&(this.ctx.globalAlpha=1),t.dash&&this.ctx.setLineDash([])}fillPath(t){this.ctx.beginPath();for(const e of t.path.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fillStyle="color"in t?t.color.toString():t.gradient,void 0!==t.opacity&&(this.ctx.globalAlpha=t.opacity),this.ctx.fill("evenodd"),void 0!==t.opacity&&(this.ctx.globalAlpha=1)}addHitRegion(t){return this.hitCanvas.beginHitRegion(t),new _(this.hitCanvas.ctx)}}class C{constructor(t,e){this.segments=[],this.segments.push({x:t,y:e,line:!1})}static fromPoints(t){const e=t.findIndex((t=>null!==t.y));if(-1===e){const t=new C(0,0);return t.segments.length=0,t}const i=new C(t[e].x,t[e].y);for(let s=e+1;s<t.length;s++){const{x:e,y:r}=t[s];null!==r&&(s>0&&null===t[s-1].y?i.moveTo(e,r):i.lineTo(e,r))}return i}getBoundingBox(){const t={x:this.segments[0].x,y:this.segments[0].y},e={x:this.segments[0].x,y:this.segments[0].y};for(let i=0;i<this.segments.length;i++){const s=this.segments[i];s.x<t.x&&(t.x=s.x),s.x>e.x&&(e.x=s.x),s.y<t.y&&(t.y=s.y),s.y>e.y&&(e.y=s.y)}return{x:t.x,y:t.y,width:e.x-t.x,height:e.y-t.y}}lineTo(t,e){return this.segments.push({x:t,y:e,line:!0}),this}moveTo(t,e){return this.segments.push({x:t,y:e,line:!1}),this}closePath(){const t=this.segments[0];return this.segments.push({x:t.x,y:t.y,line:!0}),this}translate(t,e){for(const i of this.segments)i.x+=t,i.y+=e;return this}}class _{constructor(t){this.ctx=t}addRect(t,e,i,s){return this.ctx.fillRect(t,e,i,s),this}addEllipse(t,e,i,s,r,o,n,h){this.ctx.beginPath(),this.ctx.ellipse(t,e,i,s,r,o,n,h),this.ctx.fill()}addPath(t){this.ctx.beginPath();for(const e of t.segments)e.line?this.ctx.lineTo(e.x,e.y):this.ctx.moveTo(e.x,e.y);this.ctx.fill()}}class A{constructor(t,e=[]){this.widget=t,this.properties=new Map,this.generators=[];for(const t of e)this.properties.set(t.name,t)}clear(){this.properties.clear()}add(t){this.properties.set(t.name,t)}addGenerator(t){this.generators.push(t)}all(){return this.properties.values()}loadProperty(t,e){if(t.hasNode(e.name))if(e instanceof O)e.value=t.getActions(e.name);else if(e instanceof U)e.value=t.getAutoScaleWidgets(e.name);else if(e instanceof E)e.value=t.getBoolean(e.name);else if(e instanceof I)e.value=t.getColorMap(e.name);else if(e instanceof B)e.value=t.getColor(e.name);else if(e instanceof R)e.value=t.getFloat(e.name);else if(e instanceof W)e.value=t.getFont(e.name);else if(e instanceof M)e.value=t.getInt(e.name);else if(e instanceof D)e.value=t.getMacros(e.name);else if(e instanceof H)e.value=t.getPoints(e.name);else if(e instanceof k);else if(e instanceof G)e.value=t.getRules(e.name);else if(e instanceof z)e.value=t.getScaleOptions(e.name);else if(e instanceof N)e.value=t.getScripts(e.name);else if(e instanceof P)e.rawValue=t.getString(e.name);else if(e instanceof F)e.value=t.getStringList(e.name);else if(e instanceof $)e.value=t.getStringMap(e.name);else{if(!(e instanceof j))throw new Error(`Property ${e.name} has an unexpected type`);e.value=t.getStringTable(e.name)}}loadXMLValues(t){this.properties.forEach((e=>{this.loadProperty(t,e)})),this.resolveStringProperties();for(const e of this.generators)for(const i of e())this.properties.set(i.name,i),this.loadProperty(t,i);this.resolveStringProperties()}resolveStringProperties(){for(let t=0;t<2;t++)this.properties.forEach((t=>{if(t instanceof P){const e=t;void 0!==e.rawValue&&this.widget?t.value=this.widget.expandMacro(e.rawValue):t.value=e.rawValue}}))}getProperty(t){return this.properties.get(t)}getValue(t,e=!1){const i=this.properties.get(t);if(i&&void 0!==i.value)return i.value;if(!e)throw new Error(`Missing property ${t}`)}setValue(t,e){const i=this.properties.get(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i.value=e}}class L{constructor(t,e){this.name=t,this.defaultValue=e,this.value=e}get value(){return this._value}set value(t){if(this.value!==t){const e=this._value;if(this._value=t,this.listeners)for(const i of this.listeners)i(t,e)}}addListener(t){this.listeners=this.listeners||[],this.listeners.push(t)}removeListener(t){const e=this.listeners||[],i=e.indexOf(t);-1!==i&&e.splice(i,1)}printScriptValue(t){return String(t)}}class P extends L{printScriptValue(t){return`"${t.replace('"','\\"')}"`}}class k extends L{constructor(t,e){super(t),this.pvPropertyName=e}}class M extends L{}class R extends L{}class E extends L{}class B extends L{printScriptValue(t){const{red:e,green:i,blue:s}=Object.assign({},t);return`ColorFontUtil.getColorFromRGB(${e}, ${i}, ${s})`}}class W extends L{printScriptValue(t){const{name:e,height:i,style:s}=Object.assign({},t);return`ColorFontUtil.getFont("${e}", ${i}, ${s})`}}class I extends L{printScriptValue(t){return`${t.code}`}}class H extends L{}class O extends L{}class D extends L{}class N extends L{}class F extends L{}class $ extends L{}class j extends L{}class G extends L{}class z extends L{}class U extends L{}class q{constructor(){this.actions=[],this.hookFirstActionToClick=!1,this.hookAllActionsToClick=!1}add(t){this.actions.push(t)}isClickable(){return this.actions.length&&(this.hookFirstActionToClick||this.hookAllActionsToClick)}getAction(t){if(!(t>=this.actions.length))return this.actions[t]}toString(){return 1===this.actions.length?String(this.actions[0]):`${this.actions.length} actions`}}const Y="description";class X{constructor(){this.properties=new A(null,[new P(Y,"")])}parseNode(t){this.properties.loadXMLValues(t)}get description(){return this.properties.getValue(Y)}}const K="command",Z="command_directory",J="wait_time";class Q extends X{constructor(){super(),this.properties.add(new P(K,"")),this.properties.add(new P(Z,"$(user.home)")),this.properties.add(new M(J,10))}execute(t){throw new Error("Unsupported action EXECUTE_CMD")}get command(){return this.properties.getValue(K)}get commandDirectory(){return this.properties.getValue(Z)}get waitTime(){return this.properties.getValue(J)}toString(){return`Execute Command ${this.command}`}}const tt=["Arial","Arial Black","Courier New","Helvetica","Tahoma","Verdana"];class et{constructor(t,e,i,s){this.name=t,this.style=i,this.height=s?e:Math.round(16*e/15)}scale(t){return new et(this.name,t*this.height,this.style,!0)}getFontString(){return 1===this.style?`bold ${this.height}px ${this.name}`:2===this.style?`italic ${this.height}px ${this.name}`:3===this.style?`italic bold ${this.height}px ${this.name}`:(0!==this.style&&console.warn(`Unsupported font style ${this.style}`),`normal ${this.height}px ${this.name}`)}get bold(){return 1===this.style||3===this.style}get italic(){return 2===this.style||3===this.style}isWebSafe(){return-1!==tt.indexOf(this.name)}}et.ARIAL_9=new et("Arial",9,0,!1),et.ARIAL_10=new et("Arial",10,0,!1),et.ARIAL_11=new et("Arial",11,0,!1),et.ARIAL_12_BOLD=new et("Arial",12,1,!1);class it{constructor(){this.BLACK=i.BLACK,this.BLUE=i.BLUE,this.CYAN=i.CYAN,this.DARK_GRAY=i.DARK_GRAY,this.GRAY=i.GRAY,this.GREEN=i.GREEN,this.LIGHT_BLUE=i.LIGHT_BLUE,this.ORANGE=i.ORANGE,this.PINK=i.PINK,this.PURPLE=i.PURPLE,this.RED=i.RED,this.WHITE=i.WHITE,this.YELLOW=i.YELLOW}getColorFromRGB(t,e,s){return new i(t,e,s)}getFont(t,e,i){return new et(t,e,i,!1)}}class st{constructor(t){this.display=t}writeInfo(t){this.display.getConsoleHandler().writeInfo(t)}writeError(t){this.display.getConsoleHandler().writeError(t)}writeWarning(t){this.display.getConsoleHandler().writeWarning(t)}}class rt{createDoubleArray(t){return Array(t).fill(0)}createIntArray(t){return Array(t).fill(0)}toJavaDoubleArray(t){return[...t]}toJavaIntArray(t){return[...t]}}class ot{constructor(t,e){this.spreadsheet=t,this.scriptEngine=e}addModifiedListener(t){}addSelectionChangedListener(t){this.spreadsheet.addSelectionChangedListener((()=>{this.scriptEngine.schedule((()=>{(0,t.selectionChanged)(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){}}class nt{constructor(t,e,i){this.code=t,this.interpolate=e,this.autoscale=i,this.values=[],this.colors=[],this.entries=[],this.dirty=!0,0===t||(1===t?(this.values=[0,1],this.colors=[[0,0,0],[255,255,255]]):2===t?(this.values=[0,.111,.365,.619,.873,1],this.colors=[[0,0,143],[0,0,255],[0,255,255],[255,255,0],[255,0,0],[128,0,0]]):3===t?(this.values=[0,.126,.251,.375,.5,.625,.749,.874,1],this.colors=[[0,0,0],[255,0,255],[0,0,255],[0,255,255],[0,255,0],[255,255,0],[255,128,0],[255,0,0],[255,255,255]]):4===t?(this.values=[0,.365,.746,1],this.colors=[[11,0,0],[255,0,0],[255,255,0],[255,255,255]]):5===t?(this.values=[0,1],this.colors=[[0,255,255],[255,0,255]]):6===t&&(this.values=[0,.5,1],this.colors=[[0,0,0],[255,0,0],[255,255,255]]))}addMapping(t,e,i,s){this.values.push(t),this.colors.push([e,i,s]),this.dirty=!0}compile(){this.entries.length=0;for(let t=0;t<this.values.length;t++)this.entries.push([this.values[t],this.colors[t]]);this.entries.sort(((t,e)=>t[0]<e[0]?-1:t[0]>e[0]?1:0))}lookup(t){this.dirty&&(this.compile(),this.dirty=!1);let e=this.binarySearch(t);if(e>=0)return this.entries[e][1];if(e=-e-1,0===e)return this.entries[e][1];if(e===this.entries.length)return this.entries[e-1][1];if(this.interpolate){const[i,s]=this.entries[e-1],[r,o]=this.entries[e],n=(t-i)/(r-i);return[Math.floor((o[0]-s[0])*n+s[0]),Math.floor((o[1]-s[1])*n+s[1]),Math.floor((o[2]-s[2])*n+s[2])]}return this.entries[e-1][1]}getMinMax(){return[Math.min.apply(Math,this.values),Math.max.apply(Math,this.values)]}binarySearch(t){let e=0,i=this.entries.length-1;for(;e<=i;){const s=i+e>>1;if(t>this.entries[s][0])e=s+1;else{if(!(t<this.entries[s][0]))return s;i=s-1}}return-e-1}}class ht{constructor(t,e){this.action=t,this.widget=e}getPropertyValue(t){const e=this.action.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.action.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);i instanceof P?(e=void 0!==e?String(e):e,this.action.properties.setValue(t,e)):this.action.properties.setValue(t,e),this.widget.requestRepaint()}}class at{constructor(t){this.array=t}get(t){return this.array[t]}}class lt{constructor(t){this._pv=t}getName(){return this._pv.name}getValue(){var t;return null!==(t=this._pv.value)&&void 0!==t?t:null}setValue(t){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)}))}}class dt{constructor(t){this.widget=t}executeAction(t){this.widget.executeActionByIndex(t)}getPVByName(t){const e=this.widget.display.getPV(t);return e?new lt(e):null}getPV(t="pv_name"){const e=this.getPropertyValue(t);return e?this.getPVByName(e):null}getHookedActions(){const t=this.widget.getHookedActions().map((t=>new ht(t,this.widget)));return new at(t)}getVar(t){var e;return null!==(e=this.widget.vars.get(t))&&void 0!==e?e:null}setVar(t,e){this.widget.vars.set(t,e)}getPropertyValue(t){const e=this.widget.properties.getProperty(t);return e?e.value:null}setPropertyValue(t,e){const i=this.widget.properties.getProperty(t);if(!i)throw new Error(`Cannot set value of unknown property ${t}`);if(i instanceof P)e=void 0!==e?String(e):e,this.widget.properties.setValue(t,e);else if(i instanceof I){let i=0;switch(e){case"GrayScale":i=1;break;case"JET":i=2;break;case"ColorSpectrum":i=3;break;case"Hot":i=4;break;case"Cool":i=5;break;case"Shaded":i=6}const s=new nt(i,!0,!0);this.widget.properties.setValue(t,s)}else this.widget.properties.setValue(t,e);this.widget.requestRepaint()}getName(){return this.getPropertyValue("name")}setX(t){this.setPropertyValue("x",t)}setY(t){this.setPropertyValue("y",t)}setWidth(t){this.setPropertyValue("width",t)}setHeight(t){this.setPropertyValue("height",t)}setEnabled(t){this.setPropertyValue("enabled",t)}setVisible(t){this.setPropertyValue("visible",t)}getValue(){var t;return null!==(t=this.widget.value)&&void 0!==t?t:null}setValue(t){this.widget.value=t}setValueInUIThread(t){this.setValue(t)}}class ct extends dt{constructor(t,e){super(t),this.table=t,this.spreadSheetTable=new ot(this.table.spreadsheet,e)}getTable(){return this.spreadSheetTable}}class pt extends dt{constructor(t){super(t),this.xyGraph=t}clearGraph(){this.xyGraph.clearGraph()}getXBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.x))}getYBuffer(t){return this.xyGraph.getTrace(t).snapshot().map((t=>t.y))}}function ut(t,e){switch(t.widgetType){case"Table":return new ct(t,e);case"XY Graph":return new pt(t);default:return new dt(t)}}class gt{constructor(t,e){this.display=t,this.scriptEngine=e}isActive(){return!0}getWidget(t){const e=this.display.findWidgetByName(t);if(e)return ut(e,this.scriptEngine)}}class mt{constructor(t){this.display=t}readTextFile(t){const e=this.display.resolvePath(t);var i=new XMLHttpRequest;if(i.open("GET",e,!1),i.send(null),200===i.status)return i.responseText;throw Error(`Cannot open ${e}`)}}class ft{constructor(t){this.display=t}fullScreen(){document.documentElement.requestFullscreen()}openConfirmDialog(t){return this.display.getDialogHandler().openConfirmDialog("Confirm Dialog",t)}openInformationDialog(t){this.display.getDialogHandler().openInformationDialog("Information",t)}openWarningDialog(t){this.display.getDialogHandler().openWarningDialog("Warning",t)}openErrorDialog(t){this.display.getDialogHandler().openErrorDialog("Error",t)}openPasswordDialog(t,e){return this.display.getDialogHandler().openPasswordDialog("Password Input Dialog",t,e)}}class xt{constructor(t){this.display=t}openInformation(t,e,i){this.display.getDialogHandler().openInformationDialog(e,i)}openConfirm(t,e,i){return this.display.getDialogHandler().openConfirmDialog(e,i)}openError(t,e,i){this.display.getDialogHandler().openErrorDialog(e,i)}}class wt{constructor(t,e){this.name=t,this.pvEngine=e,this._writable=!1,this._severity=yt.NONE,this._precision=-1,this._disconnected=!1,this.navigable=!1}get units(){return this._units}set units(t){this._units=t,this.pvEngine.requestRepaint()}get lowerDisplayLimit(){return this._lowerDisplayLimit}set lowerDisplayLimit(t){this._lowerDisplayLimit=t,this.pvEngine.requestRepaint()}get lowerAlarmLimit(){return this._lowerAlarmLimit}set lowerAlarmLimit(t){this._lowerAlarmLimit=t,this.pvEngine.requestRepaint()}get lowerWarningLimit(){return this._lowerWarningLimit}set lowerWarningLimit(t){this._lowerWarningLimit=t,this.pvEngine.requestRepaint()}get upperWarningLimit(){return this._upperWarningLimit}set upperWarningLimit(t){this._upperWarningLimit=t,this.pvEngine.requestRepaint()}get upperAlarmLimit(){return this._upperAlarmLimit}set upperAlarmLimit(t){this._upperAlarmLimit=t,this.pvEngine.requestRepaint()}get upperDisplayLimit(){return this._upperDisplayLimit}set upperDisplayLimit(t){this._upperDisplayLimit=t,this.pvEngine.requestRepaint()}get precision(){return this._precision}set precision(t){this._precision=t,this.pvEngine.requestRepaint()}get writable(){return this._writable}set writable(t){this._writable=t,this.pvEngine.requestRepaint()}get disconnected(){return this._disconnected}set disconnected(t){this._disconnected=t,this.pvEngine.requestRepaint()}get time(){return this._time}get value(){return this._value}get indexValue(){return this._indexValue}get severity(){return this._severity}get alarmName(){var t,e,i,s;const r=this.toNumber();return null==r?"NONE":r<=(null!==(t=this.lowerAlarmLimit)&&void 0!==t?t:NaN)?"LOLO":r>=(null!==(e=this.upperAlarmLimit)&&void 0!==e?e:NaN)?"HIHI":r<=(null!==(i=this.lowerWarningLimit)&&void 0!==i?i:NaN)?"LOW":r>=(null!==(s=this.upperWarningLimit)&&void 0!==s?s:NaN)?"HIGH":"NONE"}toNumber(){return null===this.value?null:"number"==typeof this.value?this.value:"boolean"==typeof this.value?this.value?1:0:void 0!==typeof this.indexValue?this.indexValue:void 0}setSample(t){this._time=t.time,this._value=t.value,this._indexValue=t.valueIndex,this._severity=t.severity,this._units=t.units,this.pvEngine.requestRepaint()}addListener(t){this.pvEngine.addListener(this.name,t)}removeListener(t){this.pvEngine.addListener(this.name,t)}toString(){if(void 0!==this.value)return String(this.value)}}var yt;!function(t){t.NONE="NONE",t.MINOR="MINOR",t.MAJOR="MAJOR",t.INVALID="INVALID",t.UNDEFINED="UNDEFINED"}(yt||(yt={}));const vt=["yyyy","MM","dd","HH","mm","ss","nnnnnnnnn"];class bt{constructor(t){this.pvEngine=t}checkPVValue(t){if(null===t.getValue())throw new Error(`PV ${t.getName()} has no value.`)}createPV(t,e){const i=this.pvEngine.createPV(t);return new lt(i)}getDouble(t){this.checkPVValue(t);const e=t._pv.toNumber();return parseFloat(null!=e?e:t.getValue())}getLong(t){this.checkPVValue(t);let e=t._pv.toNumber();return"number"==typeof e&&(e=Math.floor(e)),parseInt(null!=e?e:t.getValue(),10)}getString(t){return this.checkPVValue(t),T(t._pv.value,0,-1)}getStringArray(t){this.checkPVValue(t);const e=t.getValue();return Array.isArray(e)?e.map((t=>String(t))):[String(e)]}getTimeInMilliseconds(t){var e;this.checkPVValue(t);const i=t._pv.time;return null!==(e=null==i?void 0:i.getTime())&&void 0!==e?e:0}getTimeString(t,e="yyyy-MM-dd HH:mm:ss.nnnnnnnnn"){this.checkPVValue(t);const i=t._pv.time;if(i){let t=e;for(const e of vt)t=t.replace(e,this.formatDate(i,e));return t}return null}getSeverity(t){switch(this.checkPVValue(t),t._pv.severity){case yt.NONE:return 0;case yt.MAJOR:return 1;case yt.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}formatDate(t,e){if("yyyy"===e)return String(t.getUTCFullYear());if("MM"===e){const e=t.getUTCMonth()+1;return e<10?"0"+e:""+e}if("dd"===e){const e=t.getUTCDate();return e<10?"0"+e:""+e}if("HH"===e){const e=t.getUTCHours();return e<10?"0"+e:""+e}if("mm"===e){const e=t.getUTCMinutes();return e<10?"0"+e:""+e}if("ss"===e){const e=t.getUTCSeconds();return e<10?"0"+e:""+e}if("nnnnnnnnn"===e){const e=t.getUTCMilliseconds();return e<10?"00"+e:e<100?"0"+e:""+e}throw new Error(`Unexpected format '${e}'`)}}class Tt{constructor(t){this.display=t}openOPI(t,e,i,s){if(0!==i)throw new Error(`Unsupported target ${i}`);{const t={path:e,replace:0===i};this.display.fireEvent("opendisplay",t)}}closeCurrentOPI(){this.display.fireEvent("closedisplay",{})}}let St,Vt,Ct;class _t{constructor(t,e,i=[]){this.widget=t,this.scriptText=e,St||(St=document.createElement("iframe"),St.id="script-e",St.style.display="none",document.body.appendChild(St),Vt=St.contentWindow,Ct=Vt.eval,!Ct&&Vt.execScript&&(Vt.execScript.call(Vt,"null"),Ct=Vt.eval)),this.scriptText=e.replace(/importClass\([^\)]*\)\s*\;?/gi,"").replace(/importPackage\([^\)]*\)\s*\;?/gi,"").trim(),this.context=Object.assign(Object.assign({pvs:i.map((t=>new lt(t))),triggerPV:null},t.display.pvEngine.scriptLibraries),function(t){const e=t.widget,i=t.widget.display,s=function(t){this.run=t.run},r=function(t){this.runnable=t};r.prototype.start=function(){t.schedule((()=>this.runnable.run()))},r.sleep=function(t){const e=Date.now();let i=0;for(;Date.now()<e+t;)i++;i||console.trace("Should not happen")};const o=function(){};o.prototype.schedule=function(e,i){t.schedule(e,i)};const n=function(e){this.valueChanged=i=>{t.schedule((()=>{(0,e.valueChanged)(i)}))}},h={ITableModifiedListener:function(t){this.modified=e=>{(0,t.modified)(e)}},ITableSelectionChangedListener:function(t){this.selectionChanged=e=>{(0,t.selectionChanged)(e)}}};return{display:new gt(e.display,t),widget:ut(e,t),java:{lang:{Runnable:s,Thread:r},util:{Timer:o}},org:{csstudio:{swt:{widgets:{natives:{SpreadSheetTable:h}}}},yamcs:{studio:{data:{IPVListener:n}}}},ColorFontUtil:new it,ConsoleUtil:new st(i),DataUtil:new rt,FileUtil:new mt(i),GUIUtil:new ft(i),MessageDialog:new xt(i),PVUtil:new bt(i.pvEngine),ScriptUtil:new Tt(i),SpreadSheetTable:h,Java:{type:function(t){switch(t){case"java.lang.Runnable":return s;case"java.lang.Thread":return r;case"java.util.Timer":return o;case"org.csstudio.swt.widgets.natives.SpreadSheetTable":return h;case"org.yamcs.studio.data.IPVListener":return n;default:throw new Error("Unexpected class name: "+t)}},to:function(t,e){return t}}}}(this))}run(t){window.setTimeout((()=>{if(this.context.triggerPV=null,t)for(const e of this.context.pvs)e._pv===t&&(this.context.triggerPV=e);this.runWithContext((()=>{Ct.call(Vt,this.scriptText)}))}))}schedule(t,e){window.setTimeout((()=>this.runWithContext(t)),e)}runWithContext(t){const e=[];for(const t in St.contentWindow)e.push(t);try{for(const t in this.context)this.context.hasOwnProperty(t)&&(Vt[t]=this.context[t]);t();const i={};for(const t in Vt)-1===e.indexOf(t)&&(i[t]=Vt[t]);this.context=i}finally{for(const t in Vt)-1===e.indexOf(t)&&delete Vt[t]}}}const At="path",Lt="embedded",Pt="scriptText";class kt extends X{constructor(){super(),this.properties.add(new P(At,"")),this.properties.add(new E(Lt,!1)),this.properties.add(new P(Pt,""))}execute(t){if(this.embedded){new _t(t,this.scriptText).run()}else fetch(t.display.resolvePath(this.path),{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{new _t(t.display.instance,e).run()}))}))}get path(){return this.properties.getValue(At)}get embedded(){return this.properties.getValue(Lt)}get scriptText(){return this.properties.getValue(Pt)}toString(){return"Execute JavaScript"}}const Mt="macros",Rt="mode",Et="path";class Bt extends X{constructor(){super(),this.properties.add(new P(Et,"")),this.properties.add(new D(Mt)),this.properties.add(new M(Rt,0))}execute(t){const e=Object.assign({},this.macros.macros),i={path:this.path,replace:0===this.mode,args:e};t.display.fireEvent("opendisplay",i)}get macros(){return this.properties.getValue(Mt)}get path(){return this.properties.getValue(Et)}get mode(){return this.properties.getValue(Rt)}toString(){return`Open ${this.path}`}}const Wt="path";class It extends X{constructor(){super(),this.properties.add(new P(Wt,""))}execute(t){throw new Error("Unsupported action OPEN_FILE")}get path(){return this.properties.getValue(Wt)}toString(){return`Open ${this.path}`}}const Ht="hyperlink";class Ot extends X{constructor(){super(),this.properties.add(new P(Ht,"http://"))}execute(t){this.hyperlink&&(window.location.href=this.hyperlink)}get hyperlink(){return this.properties.getValue(Ht)}toString(){return`Open Webpage ${this.hyperlink}`}}const Dt="path";class Nt extends X{constructor(){super(),this.properties.add(new P(Dt,""))}execute(t){if(this.path){new Audio(t.display.resolvePath(this.path)).play()}}get path(){return this.properties.getValue(Dt)}toString(){return`Play WAV File ${this.path}`}}const Ft="command",$t="args",jt="confirm_message";class Gt extends X{constructor(){super(),this.properties.add(new P(Ft,"")),this.properties.add(new $($t,{})),this.properties.add(new P(jt,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}const e=t.expandMacro(this.command),i={};for(const e in this.args)i[e]=t.expandMacro(this.args[e]);const s={command:e,args:i};t.display.fireEvent("runcommand",s)}get command(){return this.properties.getValue(Ft)}get args(){return this.properties.getValue($t)}get confirmMessage(){return this.properties.getValue(jt)}toString(){return`Run ${this.command}`}}const zt="procedure",Ut="args",qt="confirm_message";class Yt extends X{constructor(){super(),this.properties.add(new P(zt,"")),this.properties.add(new $(Ut,{})),this.properties.add(new P(qt,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}const e={procedure:this.procedure,args:this.args};t.display.fireEvent("runprocedure",e)}get procedure(){return this.properties.getValue(zt)}get args(){return this.properties.getValue(Ut)}get confirmMessage(){return this.properties.getValue(qt)}toString(){return`Run ${this.procedure}`}}const Xt="pv_name",Kt="value",Zt="timeout",Jt="confirm_message";class Qt extends X{constructor(){super(),this.properties.add(new P(Xt,"$(pv_name)")),this.properties.add(new P(Kt,"")),this.properties.add(new M(Zt,10)),this.properties.add(new P(Jt,""))}execute(t){if(this.confirmMessage){if(!t.display.getDialogHandler().openConfirmDialog("Confirm Dialog",this.confirmMessage))return}if(this.pvName){const 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(Xt)}get value(){return this.properties.getValue(Kt)}get timeout(){return this.properties.getValue(Zt)}get confirmMessage(){return this.properties.getValue(Jt)}toString(){return`Write ${this.value} to ${this.pvName}`}}class te{constructor(){this.includeParentMacros=!0,this.macros={}}clear(){this.macros={}}set(t,e){this.macros[t]=e}get(t){if(t in this.macros)return this.macros[t]}}class ee{constructor(){this.rules=[]}}class ie{constructor(t,e,i){this.autoScaleWidgets=t,this.minWidth=e,this.minHeight=i}}class se{constructor(t,e,i){this.widthScalable=t,this.heightScalable=e,this.keepWidthHeightRatio=i}}class re{constructor(){this.scripts=[]}}class oe{constructor(t){this.node=t}get name(){return this.node.nodeName}static parseFromXML(t){const e=(new DOMParser).parseFromString(t,"text/xml");return new oe(e.documentElement)}getNode(t){const e=this.findChild(t);return new oe(e)}getNodes(t){const e=[];for(let i=0;i<this.node.childNodes.length;i++){const s=this.node.childNodes[i];3!==s.nodeType&&(t&&s.nodeName!==t||e.push(new oe(s)))}return e}hasNode(t){for(let e=0;e<this.node.childNodes.length;e++){if(this.node.childNodes[e].nodeName===t)return!0}return!1}hasAttribute(t){return this.node.hasAttribute(t)}getTextContent(t){return this.node.textContent||t||""}getString(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getStringAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return e.textContent||""}getFloat(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseFloat(i.textContent)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getInt(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t&&null!==i.textContent)return parseInt(i.textContent,10)}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getIntAttribute(t){const e=this.node.attributes.getNamedItem(t);if(null===e)throw new Error(`No attribute named ${t}`);return parseInt(e.textContent||"",10)}getBoolean(t,e){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return"true"===i.textContent}if(void 0!==e)return e;throw new Error(`No child node named ${t} could be found`)}getBooleanAttribute(t,e){const i=this.node.attributes.getNamedItem(t);if(null===i){if(void 0!==e)return e;throw new Error(`No attribute named ${t}`)}return"true"===i.textContent}getColor(t,e){const i=this.findChild(t);for(let t=0;t<i.childNodes.length;t++){const e=i.childNodes[t];if("color"===e.nodeName)return this.parseColorNode(new oe(e))}if(void 0!==e)return e;throw new Error("No child node named 'color' could be found")}getFont(t){const e=this.getNode(t);if(e.hasNode("opifont.name")){const t=e.getNode("opifont.name"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");let o=!1;return t.hasAttribute("pixels")&&(o=t.getBooleanAttribute("pixels")),new et(i,s,r,o)}{const t=e.getNode("fontdata"),i=t.getStringAttribute("fontName"),s=t.getIntAttribute("height"),r=t.getIntAttribute("style");return new et(i,s,r,!1)}}getPoints(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("point"))i.push({x:t.getIntAttribute("x"),y:t.getIntAttribute("y")});return i}getStringList(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("s"))i.push(t.getTextContent());return i}getStringMap(t){const e=this.getNode(t),i={};for(const t of e.getNodes())i[t.name]=e.getString(t.name);return i}getStringTable(t){const e=this.getNode(t),i=[];for(const t of e.getNodes("row")){const e=[];for(const i of t.getNodes("col"))e.push(i.getTextContent());i.push(e)}return i}getScripts(t){const e=this.getNode(t),i=new re;for(const t of e.getNodes("path")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=t.getStringAttribute("pathString");"EmbeddedJs"===s?i.scripts.push({embedded:!0,text:t.getString("scriptText"),checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e}):"EmbeddedPy"===s?console.warn("Unsupported EmbeddedPy script"):i.scripts.push({embedded:!1,path:s,checkConnect:t.getBooleanAttribute("checkConnect"),skipFirstExecution:t.getBooleanAttribute("sfe",!1),inputs:e})}return i}getScaleOptions(t){const e=this.getNode(t);return new se(e.getBoolean("width_scalable"),e.getBoolean("height_scalable"),e.getBoolean("keep_wh_ratio"))}getAutoScaleWidgets(t){const e=this.getNode(t);return new ie(e.getBoolean("auto_scale_widgets"),e.getInt("min_width"),e.getInt("min_height"))}getColorMap(t){const e=this.getNode(t);if(!e.hasNode("e"))return new nt(e.getInt("map"),e.getBoolean("interpolate"),e.getBoolean("autoscale"));{const t=new nt(0,e.getBoolean("interpolate"),e.getBoolean("autoscale"));for(const i of e.getNodes("e")){const e=Number(i.getTextContent()),s=i.getIntAttribute("red"),r=i.getIntAttribute("green"),o=i.getIntAttribute("blue");t.addMapping(e,s,r,o)}}}getRules(t){const e=this.getNode(t),i=new ee;for(const t of e.getNodes("rule")){const e=[];for(const i of t.getNodes("pv"))e.push({pvName:i.getTextContent(),trigger:i.getBooleanAttribute("trig")});const s=[];for(const e of t.getNodes("exp")){e.getNode("value").hasNode("color")?s.push({type:"color",expression:e.getStringAttribute("bool_exp"),outputValue:e.getColor("value")}):s.push({type:"string",expression:e.getStringAttribute("bool_exp"),outputValue:e.getString("value")})}i.rules.push({name:t.getStringAttribute("name"),propertyName:t.getStringAttribute("prop_id"),outputExpression:t.getBooleanAttribute("out_exp"),inputs:e,expressions:s})}return i}getMacros(t){const e=this.getNode(t),i=new te;i.includeParentMacros=e.getBoolean("include_parent_macros");for(const t of e.getNodes())"include_parent_macros"!==t.name&&i.set(t.name,e.getString(t.name));return i}getActions(t){const e=this.getNode(t),i=new q;i.hookFirstActionToClick=e.getBooleanAttribute("hook"),i.hookAllActionsToClick=e.getBooleanAttribute("hook_all",!1);for(const t of e.getNodes("action")){const e=t.getStringAttribute("type");if("OPEN_DISPLAY"===e){const e=new Bt;e.parseNode(t),i.add(e)}else if("OPEN_FILE"===e){const e=new It;e.parseNode(t),i.add(e)}else if("EXECUTE_CMD"===e){const e=new Q;e.parseNode(t),i.add(e)}else if("EXECUTE_JAVASCRIPT"===e){const e=new kt;e.parseNode(t),i.add(e)}else if("WRITE_PV"===e){const e=new Qt;e.parseNode(t),i.add(e)}else if("PLAY_SOUND"===e){const e=new Nt;e.parseNode(t),i.add(e)}else if("OPEN_WEBPAGE"===e){const e=new Ot;e.parseNode(t),i.add(e)}else if("RUN_COMMAND"===e){const e=new Gt;e.parseNode(t),i.add(e)}else if("RUN_PROCEDURE"===e){const e=new Yt;e.parseNode(t),i.add(e)}else console.warn(`Unsupported action type ${e}`),i.add(null)}return i}parseColorNode(t){const e=t.getIntAttribute("red"),s=t.getIntAttribute("green"),r=t.getIntAttribute("blue");return new i(e,s,r)}findChild(t){for(let e=0;e<this.node.childNodes.length;e++){const i=this.node.childNodes[e];if(i.nodeName===t)return i}throw new Error(`No child node named ${t} could be found`)}}const ne="actions",he="background_color",ae="backcolor_alarm_sensitive",le="border_alarm_sensitive",de="border_color",ce="border_width",pe="border_style",ue="enabled",ge="foreground_color",me="forecolor_alarm_sensitive",fe="height",xe="name",we="pv_name",ye="pv_value",ve="rules",be="scale_options",Te="scripts",Se="text",Ve="tooltip",Ce="transparent",_e="visible",Ae="widget_type",Le="width",Pe="wuid";class ke{constructor(t,e){this.display=t,this.parent=e,this.x=0,this.y=0,this.width=0,this.height=0,this.fillRoundRectangleBackgroundBorder=!0,this.vars=new Map,this.pvs=[],this.properties=new A(this,[new O(ne,new q),new E(ae,!1),new B(he,i.TRANSPARENT),new E(le,!1),new B(de),new M(pe),new M(ce),new E(ue,!0),new E(me,!1),new B(ge),new M(fe),new P(xe),new P(we),new k(ye,we),new G(ve,new ee),new N(Te),new P(Se,""),new P(Ve,""),new E(Ce,!1),new E(_e),new P(Ae),new M(Le),new P(Pe),new M("x"),new M("y"),new z(be)])}parseNode(t){this.properties.loadXMLValues(t);for(const t of this.properties.all())if(t instanceof W){const e=t.value;this.loadFont(e)}if(this.pvName){const t=this.display.pvEngine.createPV(this.pvName);this.pvs.push(t)}for(const t of this.scripts.scripts)if(t.embedded){const e=this.display.pvEngine.createScript(this,t,t.text);this.pvs.push(...e.pvs)}else fetch(this.display.resolvePath(t.path),{credentials:"same-origin"}).then((e=>{e.ok&&e.text().then((e=>{const i=this.display.pvEngine.createScript(this,t,e);this.pvs.push(...i.pvs)}))}));for(const t of this.rules.rules)this.properties.getProperty(t.propertyName)?this.display.pvEngine.createRule(this,t):console.warn(`Cannot create rule for unsupported property ${t.propertyName}`);this.actions.isClickable()&&(this.holderRegion={id:`${this.wuid}-holder`},this.tooltip&&(this.holderRegion.tooltip=()=>this.tooltip),this.actions.isClickable()&&(this.holderRegion.click=()=>{for(const t of this.getHookedActions())this.executeAction(t)},this.holderRegion.cursor="pointer")),this.init()}getHookedActions(){const{actions:t}=this,e=[];for(let i=0;i<t.actions.length;i++)0===i?(t.hookFirstActionToClick||t.hookAllActionsToClick)&&e.push(t.actions[i]):t.hookAllActionsToClick&&e.push(t.actions[i]);return e}drawHolder(t){var e,i;const{scale:s}=this;let r=[0,0,0,0];const o=this.borderAlarmSensitive&&((null===(e=this.pv)||void 0===e?void 0:e.severity)===yt.MINOR||(null===(i=this.pv)||void 0===i?void 0:i.severity)===yt.MAJOR);if(!o)switch(this.borderStyle){case 0:break;case 1:case 8:case 9:case 10:case 11:r=[this.borderWidth,this.borderWidth,this.borderWidth,this.borderWidth];break;case 2:case 3:r=[1*s,1*s,1*s,1*s];break;case 4:case 5:case 6:r=[2*s,2*s,2*s,2*s];break;case 7:r=[2*s,2*s,1*s,1*s];break;case 12:r=[17*s,1*s,1*s,1*s];break;case 13:r=[16*s,16*s,16*s,16*s];break;case 14:const t=2*this.borderWidth;r=[t,t,t,t]}this.x=this.holderX+r[1],this.y=this.holderY+r[0],this.width=this.holderWidth-r[1]-r[3],this.height=this.holderHeight-r[0]-r[2],o||(this.beforeDrawBorder(t),this.drawBorderStyle(t)),this.holderRegion&&t.addHitRegion(this.holderRegion).addRect(this.holderX,this.holderY,this.holderWidth,this.holderHeight)}beforeDrawBorder(t){}drawBorderStyle(t){const{scale:e}=this;if(0===this.borderStyle);else if(1===this.borderStyle)t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.borderColor,lineWidth:this.borderWidth,crispen:!0});else if(2===this.borderStyle){const s=1*e,r=this.holderY+s/2,o=this.holderX+s/2,n=this.holderY+this.holderHeight-s+s/2,h=this.holderX+this.holderWidth-s+s/2;t.strokePath({color:i.BLACK,path:new C(h,n).lineTo(h,r).moveTo(h,n).lineTo(o,n)}),t.strokePath({color:i.WHITE,path:new C(o,r).lineTo(h-s,r).moveTo(o,r).lineTo(o,n-s)})}else if(3===this.borderStyle){const s=1*e,r=this.holderY+s/2,o=this.holderX+s/2,n=this.holderY+this.holderHeight-s+s/2,h=this.holderX+this.holderWidth-s+s/2;t.strokePath({color:i.WHITE,path:new C(h,n).lineTo(h,r).moveTo(h,n).lineTo(o,n)}),t.strokePath({color:i.BLACK,path:new C(o,r).lineTo(h-s,r).moveTo(o,r).lineTo(o,n-s)})}else if(4===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_LIGHTEST,i.BUTTON_DARKER,i.BUTTON_DARKER,i.BUTTON_LIGHTEST);else if(5===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_DARKER,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKER);else if(6===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_DARKEST,i.BUTTON_DARKER,i.BUTTON,i.BUTTON_LIGHTEST);else if(7===this.borderStyle)this.drawShadowBorder(t,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKEST,i.BUTTON_DARKER);else if(8===this.borderStyle)this.drawDashedBorder(t,[2*e,2*e]);else if(9===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e]);else if(10===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e]);else if(11===this.borderStyle)this.drawDashedBorder(t,[6*e,2*e,2*e,2*e,2*e,2*e]);else if(12===this.borderStyle)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+8*e,baseline:"middle",align:"left",font:et.ARIAL_11.scale(e),color:i.BLACK,text:this.name}),t.strokeRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:i.BLACK,crispen:!0});else if(13===this.borderStyle){const i=t.measureText(this.name,et.ARIAL_11.scale(e)),s=1;let r=d(this.holderX+8*e,this.holderY+8*e,this.holderWidth-16*e-s,this.holderHeight-16*e-s,s);this.transparent||(t.fillRect(Object.assign(Object.assign({},p(r,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:et.ARIAL_11.scale(e),color:this.borderColor,text:this.name}),t.strokePath({color:this.backgroundColor.darker(),path:new C(r.x,r.y).lineTo(r.x+8*e,r.y).moveTo(r.x+8*e+i.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)}),r=d(this.holderX+8*e+s,this.holderY+8*e+s,this.holderWidth-16*e-s,this.holderHeight-16*e-s,s),t.strokePath({color:this.backgroundColor.brighter(),path:new C(r.x,r.y).lineTo(r.x+8*e-s,r.y).moveTo(r.x+8*e-s+i.width,r.y).lineTo(r.x+r.width,r.y).lineTo(r.x+r.width,r.y+r.height).lineTo(r.x,r.y+r.height).lineTo(r.x,r.y)})}else if(14===this.borderStyle){const i=d(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);this.fillRoundRectangleBackgroundBorder&&t.fillRect(Object.assign(Object.assign({},i),{rx:4*e,ry:4*e,color:this.backgroundColor})),this.borderWidth&&t.strokeRect(Object.assign(Object.assign({},i),{rx:4*e,ry:4*e,color:this.borderColor,lineWidth:this.borderWidth}))}else 15===this.borderStyle||console.warn(`Unsupported border style: ${this.borderStyle}`)}isDisconnected(){for(const t of this.pvs)if(void 0===t.value)return!0;return!1}drawDecoration(t){var e,s,r;if(this.display.editMode)return;const{scale:o}=this;if(!this.pvName||this.pv&&!this.pv.disconnected)this.pvs.length&&this.isDisconnected()&&t.strokeRect(Object.assign(Object.assign({},this.bounds),{dash:[2*o,2*o],lineWidth:2*o,color:i.PINK,crispen:!0}));else{const e=1*o;t.fillRect({x:this.holderX-e/2,y:this.holderY-e/2,width:this.holderWidth+e,height:this.holderHeight+e,color:i.PURPLE,opacity:.4}),t.strokeRect({x:this.holderX-e/2,y:this.holderY-e/2,width:this.holderWidth+e,height:this.holderHeight+e,color:i.PURPLE})}if(this.borderAlarmSensitive){let n;8===this.borderStyle?n=[2*o,2*o]:9===this.borderStyle?n=[6*o,2*o]:10===this.borderStyle?n=[6*o,2*o,2*o,2*o]:11===this.borderStyle&&(n=[6*o,2*o,2*o,2*o,2*o,2*o]),(null===(e=this.pv)||void 0===e?void 0:e.severity)===yt.MAJOR?t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.RED,crispen:!0,dash:n})):(null===(s=this.pv)||void 0===s?void 0:s.severity)===yt.MINOR?t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.ORANGE,crispen:!0,dash:n})):(null===(r=this.pv)||void 0===r?void 0:r.severity)===yt.INVALID&&t.strokeRect(Object.assign(Object.assign({},this.bounds),{lineWidth:2*o,color:i.PINK,crispen:!0}))}}drawOverlay(t){}drawSelection(t){t.lineWidth=1,t.strokeStyle="black",t.strokeRect(this.holderX-.5,this.holderY-.5,this.holderWidth+1,this.holderHeight+1),t.fillStyle="black";let e=2;t.fillRect(this.holderX-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight/2-e,e+e,e+e),t.fillRect(this.holderX-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth/2-e,this.holderY+this.holderHeight-e,e+e,e+e),t.fillRect(this.holderX+this.holderWidth-e,this.holderY+this.holderHeight-e,e+e,e+e),t.strokeStyle="white",e=3,t.strokeRect(this.holderX-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight/2-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth/2-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1),t.strokeRect(this.holderX+this.holderWidth-e+.5,this.holderY+this.holderHeight-e+.5,e+e-1,e+e-1)}requestRepaint(){this.display.requestRepaint()}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("x"),y:this.properties.getValue("y"),width:this.properties.getValue(Le),height:this.properties.getValue(fe)}}get area(){return{x:this.x,y:this.y,width:this.width,height:this.height}}drawShadowBorder(t,e,i,s,r){const o=1*this.scale,n=this.holderY+o/2,h=this.holderX+o/2,a=this.holderY+this.holderHeight-o+o/2,l=this.holderX+this.holderWidth-o+o/2;t.strokePath({color:e,path:new C(l,a).lineTo(l,n).moveTo(l,a).lineTo(h,a)}),t.strokePath({color:i,path:new C(l-o,a-o).lineTo(l-o,n+o).moveTo(l-o,a-o).lineTo(h+o,a-o)}),t.strokePath({color:s,path:new C(h,n).lineTo(l-o,n).moveTo(h,n).lineTo(h,a-o)}),t.strokePath({color:r,path:new C(h+o,n+o).lineTo(l-o-o,n+o).moveTo(h+o,n+o).lineTo(h+o,a-o-o)})}drawDashedBorder(t,e){const i=d(this.holderX,this.holderY,this.holderWidth,this.holderHeight,this.borderWidth);t.strokePath({color:this.borderColor,lineWidth:this.borderWidth,dash:e,path:new C(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){const e=this.actions.getAction(t);e&&this.executeAction(e)}executeAction(t){t.execute(this)}expandMacro(t){var e;if(-1===t.indexOf("$"))return t;for(const i of this.properties.all())if(i instanceof k){const s=this.properties.getProperty(i.pvPropertyName);let r="";const o=null==s?void 0:s.value;if(o){const t=this.display.getPV(o);r=null!==(e=null==t?void 0:t.value)&&void 0!==e?e:""}t=(t=t.replace(`$(${i.name})`,r)).replace(`\${${i.name}}`,r)}else t=(t=t.replace(`$(${i.name})`,i.value||"")).replace(`\${${i.name}}`,i.value||"");return this.parent?this.parent.expandContainerMacros(t):t}loadFont(t){if(t.isWebSafe())return;const e=this.display.getFontResolver();if(!e)return void console.warn(`Failed to load font '${t.getFontString()}'.`);const i=e.resolve(t);i?i.load().then((t=>{document.fonts.add(t),this.requestRepaint()})).catch((e=>{console.warn(`Failed to load font '${t.getFontString()}'.`,e)})):console.warn(`Failed to load font '${t.getFontString()}'.`)}get pv(){if(this.pvName)return this.display.getPV(this.pvName)}isMinorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===yt.MINOR}isMajorSeverity(){var t;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===yt.MAJOR}get alarm(){var t,e,i;return(null===(t=this.pv)||void 0===t?void 0:t.severity)===yt.MINOR||(null===(e=this.pv)||void 0===e?void 0:e.severity)===yt.MAJOR||(null===(i=this.pv)||void 0===i?void 0:i.severity)===yt.INVALID}get alarmSensitiveBackgroundColor(){var t;if(this.backgroundAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE;if((null===(t=this.pv)||void 0===t?void 0:t.severity)===yt.INVALID)return i.PINK}return this.backgroundColor}get alarmSensitiveForegroundColor(){if(this.foregroundAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.foregroundColor}get scale(){let t=this.display.scale,e=this.parent;for(;e;)t*=e.relativeScale,e=e.parent;return t}get value(){return this._value}set value(t){this._value=t,this.requestRepaint()}addPropertyListener(t,e){this.properties.getProperty(t).addListener(e)}removePropertyListener(t,e){this.properties.getProperty(t).removeListener(e)}toDataURL(t="image/png",e){const i=this.display.measureAbsoluteArea(this);return this.display.copyCanvas(i).toDataURL(t,e)}get wuid(){return this.properties.getValue(Pe)}get name(){return this.properties.getValue(xe)}get holderX(){return this.scale*this.properties.getValue("x")}get holderY(){return this.scale*this.properties.getValue("y")}get holderWidth(){return this.scale*this.properties.getValue(Le)}get holderHeight(){return this.scale*this.properties.getValue(fe)}get borderAlarmSensitive(){return this.properties.getValue(le)}get backgroundAlarmSensitive(){return this.properties.getValue(ae)}get foregroundAlarmSensitive(){return this.properties.getValue(me)}get pvName(){return this.properties.getValue(we,!0)}get pvValue(){return this.properties.getValue(ye,!0)}get borderColor(){return this.properties.getValue(de)}get borderStyle(){return this.properties.getValue(pe)}get borderWidth(){return this.scale*this.properties.getValue(ce)}get backgroundColor(){return this.properties.getValue(he)}get enabled(){return this.properties.getValue(ue)}get foregroundColor(){return this.properties.getValue(ge)}get tooltip(){const t=this.properties.getProperty(Ve);if(t.rawValue)return this.expandMacro(t.rawValue)}get transparent(){return this.properties.getValue(Ce)}get visible(){return this.properties.getValue(_e)}get actions(){return this.properties.getValue(ne)}get scripts(){return this.properties.getValue(Te)}get rules(){return this.properties.getValue(ve)}get scaleOptions(){return this.properties.getValue(be)}get widgetType(){return this.properties.getValue(Ae,!0)}get text(){if(this.display.editMode){return(this.properties.getProperty(Se).rawValue||"").split(" ").join(" ")}return this.properties.getValue(Se).split(" ").join(" ")}init(){}hide(){}destroy(){}}const Me="macros";class Re extends ke{constructor(t,e){super(t,e),this._widgets=[],this._connections=[],this.relativeScale=1,this.properties.add(new D(Me))}expandContainerMacros(t){for(const e in this.macros.macros)t=(t=t.replace(`$(${e})`,this.macros.macros[e])).replace(`\${${e}}`,this.macros.macros[e]);return this.parent&&this.macros.includeParentMacros&&(t=this.parent.expandContainerMacros(t)),t}findWidget(t){for(const e of this.widgets){if(e.wuid===t)return e;if(e instanceof Re){const i=e.findWidget(t);if(i)return i}}}findWidgetByName(t){for(const e of this.widgets){if(e.name===t)return e;if(e instanceof Re){const i=e.findWidgetByName(t);if(i)return i}}for(const e of this.connections)if(e.name===t)return e}hide(){for(const t of this.widgets)t.hide()}destroy(){for(const t of this.widgets)t.destroy()}get widgets(){return this._widgets}get connections(){return this._connections}get macros(){return this.properties.getValue(Me)}}const Ee="arrow_length",Be="arrows",We="fill_arrow",Ie="name",He="line_color",Oe="line_style",De="line_width",Ne="src_wuid",Fe="src_term",$e="tgt_wuid",je="tgt_term",Ge="router",ze="points",Ue="LEFT",qe="UP",Ye="DOWN",Xe="RIGHT";class Ke extends ke{constructor(t){super(t),this.properties.clear(),this.properties.add(new M(Ee)),this.properties.add(new M(Be)),this.properties.add(new E(We)),this.properties.add(new P(Ie)),this.properties.add(new B(He)),this.properties.add(new M(Oe)),this.properties.add(new M(De)),this.properties.add(new P(Ne)),this.properties.add(new P(Fe)),this.properties.add(new P($e)),this.properties.add(new P(je)),this.properties.add(new M(Ge)),this.properties.add(new H(ze)),this.properties.add(new P("wuid"))}parseNode(t){this.properties.loadXMLValues(t),this.sourceWidget=this.display.findWidget(this.sourceWuid),this.sourceWidget||console.warn(`Can't find source widget ${this.sourceWuid}`),this.targetWidget=this.display.findWidget(this.targetWuid),this.targetWidget||console.warn(`Can't find target widget ${this.targetWuid}`)}draw(t){this.sourceWidget&&this.targetWidget&&(this.points.length?this.drawPath(t):0===this.router?this.drawManhattanConnection(t):1===this.router&&this.drawDirectConnection(t))}drawPath(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm),s=[e,...this.points,i],r=C.fromPoints(s).translate(.5*this.scale,.5*this.scale);t.strokePath({path:r,lineWidth:this.lineWidth,color:this.lineColor,dash:this.getDashArray()}),this.drawStartArrow(t,s[1],s[0]),this.drawStopArrow(t,s[s.length-2],s[s.length-1])}drawManhattanConnection(t){const e=this.getManhattanAnchor(this.sourceWidget,this.sourceTerm),i=this.getManhattanAnchor(this.targetWidget,this.targetTerm),s=this.route(e,i),r=C.fromPoints(s);this.lineWidth&&t.strokePath({lineWidth:this.lineWidth,color:this.lineColor,path:r,dash:this.getDashArray()}),this.drawStartArrow(t,s[s.length-2],s[s.length-1]),this.drawStopArrow(t,s[1],s[0])}getDashArray(){const{scale:t}=this;if(this.lineWidth){if(0===this.lineStyle)return[];if(1===this.lineStyle)return[6*t,2*t];if(2===this.lineStyle)return[2*t,2*t];if(3===this.lineStyle)return[6*t,2*t,2*t,2*t];if(4===this.lineStyle)return[6*t,2*t,2*t,2*t,2*t,2*t];console.warn(`Unsupported connection line style ${this.lineStyle}`)}}drawDirectConnection(t){const e=this.getPosition(this.sourceWidget,this.sourceTerm),i=this.getPosition(this.targetWidget,this.targetTerm);this.lineWidth&&t.strokePath({path:new C(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=qe;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":i=Ye;break;case"LEFT":i=Ue;break;case"RIGHT":i=Xe}const s=t.bounds,r=this.getPosition(t,e),o=r.x-s.x,n=s.x+s.width-r.x,h=r.y-s.y,a=s.y+s.height-r.y;return i=Math.min(o,n)<Math.min(h,a)?o<n?Ue:Xe:h<a?qe:Ye,{x:r.x,y:r.y,direction:i}}getPosition(t,e){switch(e){case"LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight/2};case"TOP":return{x:t.holderX+t.holderWidth/2,y:t.holderY};case"RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight/2};case"BOTTOM":return{x:t.holderX+t.holderWidth/2,y:t.holderY+t.holderHeight};case"TOP_LEFT":return{x:t.holderX,y:t.holderY};case"TOP_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY};case"BOTTOM_LEFT":return{x:t.holderX,y:t.holderY+t.holderHeight};case"BOTTOM_RIGHT":return{x:t.holderX+t.holderWidth,y:t.holderY+t.holderHeight};default:const i=parseInt(e,10);let s=t.properties.getProperty("points");if(s){let t=s.value;return t=v(t,this.scale),t[i]}throw Error(`Unexpected term ${e}`)}}route(t,e){let i,s,r=t.x-e.x,o=t.y-e.y,n={x:0,y:0},h=[];const{tolxtol:a,tol:l,minDist:d}=this;if(r*r<a&&o*o<a)return[{x:e.x,y:e.y}];t.direction===Ue?r>0&&o*o<l&&e.direction===Xe?(n=e,i=e.direction):(r<0?n={x:t.x-d,y:t.y}:o>0&&e.direction===Ye||o<0&&e.direction===qe?n={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.min(t.x,e.x)-d,n={x:s,y:t.y}):n={x:t.x-r/2,y:t.y},i=o>0?qe:Ye):t.direction===Xe?r<0&&o*o<l&&e.direction===Ue?(n=e,i=e.direction):(r>0?n={x:t.x+d,y:t.y}:o>0&&e.direction===Ye||o<0&&e.direction===qe?n={x:e.x,y:t.y}:t.direction===e.direction?(s=Math.max(t.x,e.x)+d,n={x:s,y:t.y}):n={x:t.x-r/2,y:t.y},i=o>0?qe:Ye):t.direction===Ye?r*r<l&&o<0&&e.direction===qe?(n=e,i=e.direction):(o>0?n={x:t.x,y:t.y+d}:r>0&&e.direction===Xe||r<0&&e.direction===Ue?n={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.max(t.y,e.y)+d,n={x:t.x,y:s}):n={x:t.x,y:t.y-o/2},i=r>0?Ue:Xe):t.direction===qe&&(r*r<l&&o>0&&e.direction===Ye?(n=e,i=e.direction):(o<0?n={x:t.x,y:t.y-d}:r>0&&e.direction===Xe||r<0&&e.direction===Ue?n={x:t.x,y:e.y}:t.direction===e.direction?(s=Math.min(t.y,e.y)-d,n={x:t.x,y:s}):n={x:t.x,y:t.y-o/2},i=r>0?Ue:Xe));const c=Object.assign(Object.assign({},n),{direction:i});return h=h.concat(this.route(c,e)),h.push(t),h}drawStartArrow(t,e,i){const s=t.ctx;if(1===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}drawStopArrow(t,e,i){const s=t.ctx;if(2===this.arrows||3===this.arrows){const t=this.calculateArrowPoints(e,i);if(t[2]=i,this.fillArrow){s.fillStyle=this.lineColor.toString(),s.beginPath();for(let e=0;e<t.length;e++)0===e?s.moveTo(t[e].x,t[e].y):s.lineTo(t[e].x,t[e].y);s.fill()}else s.strokeStyle=this.lineColor.toString(),s.lineWidth=this.lineWidth,s.beginPath(),s.moveTo(i.x,i.y),s.lineTo(t[0].x,t[0].y),s.moveTo(i.x,i.y),s.lineTo(t[1].x,t[1].y),s.stroke()}}calculateArrowPoints(t,e){const i=w(e,t),s=Math.PI/10,r=new y(this.arrowLength,i.theta-s),o=new y(this.arrowLength,i.theta+s),n=new y(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[g(r.toPoint(),e.x,e.y),g(o.toPoint(),e.x,e.y),g(n.toPoint(),e.x,e.y)]}get minDist(){return 20*this.scale}get tol(){return.1*this.scale}get tolxtol(){return.01*this.scale}get name(){return this.properties.getValue(Ie)}get arrows(){return this.properties.getValue(Be)}get fillArrow(){return this.properties.getValue(We)}get arrowLength(){return this.scale*this.properties.getValue(Ee)}get lineColor(){return this.properties.getValue(He)}get lineStyle(){return this.properties.getValue(Oe)}get lineWidth(){return this.scale*this.properties.getValue(De)}get router(){return this.properties.getValue(Ge)}get sourceTerm(){return this.properties.getValue(Fe)}get sourceWuid(){return this.properties.getValue(Ne)}get targetTerm(){return this.properties.getValue(je)}get targetWuid(){return this.properties.getValue($e)}get points(){return v(this.properties.getValue(ze),this.scale)}}let Ze=0;const Je="auto_scale_widgets";class Qe extends Re{constructor(t,e,i){super(t,e),this.displayArgs=null!=i?i:{},this.properties.add(new U(Je))}parseNode(t){super.parseNode(t);const e=Ze++;this.macros.set("DID",`DID_${e}`);const i=this.properties.getValue("name");this.macros.set("DNAME",i);for(const t in this.displayArgs)this.macros.set(t,this.displayArgs[t]);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}for(const e of t.getNodes("connection")){const t=new Ke(this.display);t.parseNode(e),this.connections.push(t)}}draw(t){for(const e of this.widgets.filter((t=>t.visible)))e.drawHolder(t),e.draw(t),e.drawDecoration(t);for(const e of this.connections)e.draw(t);for(const e of this.widgets.filter((t=>t.visible)))e.drawOverlay(t)}measureContentBounds(t){let e=0,i=0,s=0,r=0;for(const o of this.widgets.filter((t=>t.visible))){const n=t?o.bounds:o.unscaledBounds;e=Math.min(e,n.x),i=Math.min(i,n.y),s=Math.max(s,n.x+n.width),r=Math.max(r,n.y+n.height)}return{x:e,y:i,width:s-e,height:r-i}}get autoScaleWidgets(){return this.properties.getValue(Je)}}let ti=0;const ei="group_name",ii="opi_file",si="resize_behaviour";class ri extends Re{constructor(t,e){super(t,e),this.properties.add(new P(ei)),this.properties.add(new P(ii)),this.properties.add(new M(si,0))}parseNode(t){super.parseNode(t);const e=ti++;this.macros.set("LCID",`LCID_${e}`)}init(){this.opiFile&&(this.resolvedOpiFile=this.display.resolvePath(this.opiFile),fetch(this.resolvedOpiFile,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.linkedDisplay=new Qe(this.display,this);const e=oe.parseFromXML(t);this.linkedDisplay.parseNode(e),this.requestRepaint()}))})))}draw(t){this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const e=this.getLinkedWidget();if(this.linkedDisplay&&e)if(t.fillRect(Object.assign(Object.assign({},this.area),{color:this.linkedDisplay.backgroundColor})),0===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!1);let{width:i,height:s}=e;const r=this.display.scale;i*=r,s*=r;const o=i/s;let n=this.width,h=n/o,a=n/i;h>this.height&&(h=this.height,n=h*o,a=h/i),this.linkedDisplay.relativeScale=a;const l=t.createChild(Math.ceil(n),Math.ceil(h));l.translate(e.x,e.y),this.linkedDisplay.draw(l),t.copy(l,this.x,this.y)}else if(1===this.resizeBehavior)console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior);else if(2===this.resizeBehavior){const e=this.linkedDisplay.measureContentBounds(!0),i=t.createChild(e.width,e.height);i.translate(e.x,e.y),this.linkedDisplay.draw(i),t.copy(i,this.x,this.y)}else 3===this.resizeBehavior&&console.warn("Unsupported resize behavior of LinkingContainer",this.resizeBehavior)}getLinkedWidget(){return this.linkedDisplay&&""!==this.groupName?this.linkedDisplay.findWidgetByName(this.groupName):this.linkedDisplay}get widgets(){return this.linkedDisplay?this.linkedDisplay.widgets:[]}get connections(){return this.linkedDisplay?this.linkedDisplay.connections:[]}findWidget(t){if(this.linkedDisplay)return this.linkedDisplay.findWidget(t)}get opiFile(){return this.properties.getValue(ii)}get groupName(){return this.properties.getValue(ei)}get resizeBehavior(){return this.properties.getValue(si)}}class oi{constructor(t){this.display=t}resolve(t,e){if(t.startsWith("/"))return`${this.display.absPrefix}${t.slice(1)}`;if(t.startsWith("http://")||t.startsWith("https://"))return t;if(e){let i=e.parent;for(;i;){if(i instanceof ri){const e=i.resolvedOpiFile,s=e.lastIndexOf("/")+1;return`${e.substring(0,s)}${t}`}i=i.parent}}return`${this.display.relPrefix}${t}`}}class ni{constructor(t,e){this.pvName=t,this.formula=e,this.pvValues=new Map}updateDataSource(t,e){this.pvValues.set(t,e)}clearState(){this.pvValues.clear()}getPVNames(){const t=this.formula.expression,e=[];return this.getExpressionParameters(t,e),e}getExpressionParameters(t,e){switch(t.type){case"ParameterLiteral":-1===e.indexOf(t.value)&&e.push(t.value);break;case"ConditionalExpression":this.getExpressionParameters(t.consequent,e),t.alternate&&this.getExpressionParameters(t.alternate,e);break;case"BinaryExpression":case"LogicalExpression":this.getExpressionParameters(t.left,e),this.getExpressionParameters(t.right,e);break;case"UnaryExpression":this.getExpressionParameters(t.argument,e);break;case"CallExpression":for(const i of t.arguments)this.getExpressionParameters(i,e)}}execute(){const t=this.formula.expression;return this.executeExpression(t)}executeExpression(t){switch(t.type){case"BooleanLiteral":case"ConstantLiteral":case"NumericLiteral":case"StringLiteral":return t.value;case"ParameterLiteral":const e=this.pvValues.get(t.value);return e?e.value:void 0;case"ConditionalExpression":return this.executeConditionalExpression(t);case"BinaryExpression":return this.executeBinaryExpression(t);case"LogicalExpression":return this.executeLogicalExpression(t);case"UnaryExpression":return this.executeUnaryExpression(t);case"CallExpression":return this.executeCallExpression(t);default:throw new Error("Unexpected expression type")}}executeBinaryExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"+":return e+i;case"-":return e-i;case"*":return e*i;case"/":return e/i;case"^":return Math.pow(e,i);case"%":return e%i;case"==":return e===i;case"!=":return e!==i;case"<=":return e<=i;case"<":return e<i;case">=":return e>=i;case">":return e>i;default:throw new Error(`Unexpected binary operator ${t.operator}`)}}executeLogicalExpression(t){const e=this.executeExpression(t.left),i=this.executeExpression(t.right);switch(t.operator){case"&&":return e&&i;case"||":return e||i;default:throw new Error(`Unexpected logical operator ${t.operator}`)}}executeConditionalExpression(t){const e=this.executeExpression(t.test),i=this.executeExpression(t.consequent);if(void 0===t.alternate)return e?i:null;{const s=this.executeExpression(t.alternate);return e?i:s}}executeUnaryExpression(t){const e=this.executeExpression(t.argument);switch(t.operator){case"-":return-e;case"+":return e;default:throw new Error(`Unexpected unary operator ${t.operator}`)}}executeCallExpression(t){const e=t.callee.name,i=[];for(const e of t.arguments)i.push(this.executeExpression(e));switch(e){case"abs":return Math.abs(i[0]);case"acos":return Math.acos(i[0]);case"asin":return Math.asin(i[0]);case"atan":return Math.atan(i[0]);case"cbrt":return Math.cbrt(i[0]);case"ceil":return Math.ceil(i[0]);case"cos":return Math.cos(i[0]);case"cosh":return Math.cosh(i[0]);case"exp":return Math.exp(i[0]);case"floor":return Math.floor(i[0]);case"log":return Math.log(i[0]);case"log10":return Math.log10(i[0]);case"round":return Math.round(i[0]);case"signum":return Math.sign(i[0]);case"sin":return Math.sin(i[0]);case"sinh":return Math.sinh(i[0]);case"sqrt":return Math.sqrt(i[0]);case"tan":return Math.tan(i[0]);case"tanh":return Math.tanh(i[0]);case"toDegrees":return 180*i[0]/Math.PI;case"toRadians":return i[0]/180*Math.PI;case"parameterAcquisitionStatus":return this.callParameterAcquisitionStatus(i[0]);default:throw new Error(`Unsupported function '${e}'`)}}callParameterAcquisitionStatus(t){const e=this.pvValues.get(t);if(e)return e.acquisitionStatus}}function hi(t,e,i,s){var r=Error.call(this,t);return Object.setPrototypeOf&&Object.setPrototypeOf(r,hi.prototype),r.expected=e,r.found=i,r.location=s,r.name="SyntaxError",r}function ai(t,e,i){return i=i||" ",t.length>e?t:(e-=t.length,t+(i+=i.repeat(e)).slice(0,e))}function li(t,e){var i,s,r,o,n={},h=(e=void 0!==e?e:{}).grammarSource,a={Start:te},l=te,d="=",c="false",p="true",u="pi",g="e",m=".",f="0",x='"',w="'",y="(",v=")",b=",",T="<=",S=">=",V="==",C="!=",_="&&",A="||",L=/^[\t ]/,P=/^[A-Z_a-z]/,k=/^[a-zA-Z0-9_]/,M=/^[0-9]/,R=/^[1-9]/,E=/^[^\n\r\f"]/,B=/^[^\n\r\f']/,W=/^[+\-]/,I=/^[%*\/\^]/,H=/^[<>]/,O=Yt("=",!1),D=Xt(["\t"," "],!1,!1),N=Yt("false",!0),F=Yt("true",!0),$=Yt("PI",!0),j=Yt("E",!0),G=Kt("identifier"),z=Xt([["A","Z"],"_",["a","z"]],!1,!1),U=Xt([["a","z"],["A","Z"],["0","9"],"_"],!1,!1),q=Kt("boolean"),Y=Kt("constant"),X=Kt("number"),K=Yt(".",!1),Z=Yt("0",!1),J=Xt([["0","9"]],!1,!1),Q=Xt([["1","9"]],!1,!1),tt=Kt("string"),et=Yt('"',!1),it=Xt(["\n","\r","\f",'"'],!0,!1),st=Kt("parameter"),rt=Yt("'",!1),ot=Xt(["\n","\r","\f","'"],!0,!1),nt=Yt("(",!1),ht=Yt(")",!1),at=Xt(["+","-"],!1,!1),lt=Yt(",",!1),dt=Xt(["%","*","/","^"],!1,!1),ct=Yt("<=",!1),pt=Yt(">=",!1),ut=Xt(["<",">"],!1,!1),gt=Yt("==",!1),mt=Yt("!=",!1),ft=Yt("&&",!1),xt=Yt("||",!1),wt=function(t){return t},yt=function(t){return{type:"Formula",expression:t}},vt=function(t){return t},bt=function(t,e){return{type:"Symbol",name:t+e.join("")}},Tt=function(){return{type:"BooleanLiteral",value:!0}},St=function(){return{type:"BooleanLiteral",value:!1}},Vt=function(){return{type:"ConstantLiteral",value:Math.PI}},Ct=function(){return{type:"ConstantLiteral",value:Math.E}},_t=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},At=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},Lt=function(){return{type:"NumericLiteral",value:parseFloat(qt())}},Pt=function(t){return{type:"StringLiteral",value:t.join("")}},kt=function(t){return{type:"ParameterLiteral",value:t.join("")}},Mt=function(t){return t},Rt=function(t,e){return{type:"UnaryExpression",operator:t,argument:e}},Et=function(t,e){return{type:"CallExpression",callee:t,arguments:e}},Bt=function(t){return s=0,null!==(e=(i=t)?i[s]:null)?e:[];var e,i,s},Wt=function(t,e){return function(t,e,i){return[t].concat(function(t,e){return t.map((function(t){return t[e]}))}(e,i))}(t,e,3)},It=function(t,e){return me(t,e)},Ht=function(t,e){return me(t,e)},Ot=function(t,e){return me(t,e)},Dt=function(t,e){return me(t,e)},Nt=function(t,e){return function(t,e){return e.reduce((function(t,e){return{type:"LogicalExpression",operator:e[1],left:t,right:e[3]}}),t)}(t,e)},Ft=0|e.peg$currPos,$t=Ft,jt=[{line:1,column:1}],Gt=Ft,zt=e.peg$maxFailExpected||[],Ut=0|e.peg$silentFails;if(e.startRule){if(!(e.startRule in a))throw new Error("Can't start parsing from rule \""+e.startRule+'".');l=a[e.startRule]}function qt(){return t.substring($t,Ft)}function Yt(t,e){return{type:"literal",text:t,ignoreCase:e}}function Xt(t,e,i){return{type:"class",parts:t,inverted:e,ignoreCase:i}}function Kt(t){return{type:"other",description:t}}function Zt(e){var i,s=jt[e];if(s)return s;if(e>=jt.length)i=jt.length-1;else for(i=e;!jt[--i];);for(s={line:(s=jt[i]).line,column:s.column};i<e;)10===t.charCodeAt(i)?(s.line++,s.column=1):s.column++,i++;return jt[e]=s,s}function Jt(t,e,i){var s=Zt(t),r=Zt(e);return{source:h,start:{offset:t,line:s.line,column:s.column},end:{offset:e,line:r.line,column:r.column}}}function Qt(t){Ft<Gt||(Ft>Gt&&(Gt=Ft,zt=[]),zt.push(t))}function te(){var e,i,s;return e=Ft,61===t.charCodeAt(Ft)?(i=d,Ft++):(i=n,0===Ut&&Qt(O)),i!==n?(ee(),s=function(){var t,e;t=Ft,e=ge(),e!==n&&($t=t,e=yt(e));return t=e,t}(),s!==n?(ee(),$t=e,e=wt(s)):(Ft=e,e=n)):(Ft=e,e=n),e}function ee(){var t,e;for(t=[],e=ie();e!==n;)t.push(e),e=ie();return t}function ie(){var e;return e=t.charAt(Ft),L.test(e)?Ft++:(e=n,0===Ut&&Qt(D)),e}function se(){var e,i;return e=Ft,i=function(){var e,i,s,r;if(Ut++,e=Ft,i=function(){var e;e=t.charAt(Ft),P.test(e)?Ft++:(e=n,0===Ut&&Qt(z));return e}(),i!==n){for(s=[],r=re();r!==n;)s.push(r),r=re();$t=e,e=bt(i,s)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(G));return e}(),i!==n&&($t=e,i=vt(i)),e=i}function re(){var e;return e=t.charAt(Ft),k.test(e)?Ft++:(e=n,0===Ut&&Qt(U)),e}function oe(){var e;return(e=function(){var e,i;Ut++,e=Ft,i=function(){var e;return(e=t.substr(Ft,4)).toLowerCase()===p?Ft+=4:(e=n,0===Ut&&Qt(F)),e}(),i!==n&&($t=e,i=Tt());e=i,e===n&&(e=Ft,i=function(){var e;return(e=t.substr(Ft,5)).toLowerCase()===c?Ft+=5:(e=n,0===Ut&&Qt(N)),e}(),i!==n&&($t=e,i=St()),e=i);Ut--,e===n&&(i=n,0===Ut&&Qt(q));return e}())===n&&(e=function(){var e,i;Ut++,e=Ft,i=function(){var e;return(e=t.substr(Ft,2)).toLowerCase()===u?Ft+=2:(e=n,0===Ut&&Qt($)),e}(),i!==n&&($t=e,i=Vt());e=i,e===n&&(e=Ft,i=function(){var e;return(e=t.charAt(Ft)).toLowerCase()===g?Ft++:(e=n,0===Ut&&Qt(j)),e}(),i!==n&&($t=e,i=Ct()),e=i);Ut--,e===n&&(i=n,0===Ut&&Qt(Y));return e}())===n&&(e=function(){var e,i,s,r,o;if(Ut++,e=Ft,(i=ne())!==n)if(46===t.charCodeAt(Ft)?(s=m,Ft++):(s=n,0===Ut&&Qt(K)),s!==n){for(r=[],o=he();o!==n;)r.push(o),o=he();$t=e,e=_t()}else Ft=e,e=n;else Ft=e,e=n;if(e===n){if(e=Ft,46===t.charCodeAt(Ft)?(i=m,Ft++):(i=n,0===Ut&&Qt(K)),i!==n){if(s=[],(r=he())!==n)for(;r!==n;)s.push(r),r=he();else s=n;s!==n?($t=e,e=At()):(Ft=e,e=n)}else Ft=e,e=n;e===n&&(e=Ft,(i=ne())!==n&&($t=e,i=Lt()),e=i)}Ut--,e===n&&(i=n,0===Ut&&Qt(X));return e}())===n&&(e=function(){var e,i,s,r;Ut++,e=Ft,34===t.charCodeAt(Ft)?(i=x,Ft++):(i=n,0===Ut&&Qt(et));if(i!==n){for(s=[],r=t.charAt(Ft),E.test(r)?Ft++:(r=n,0===Ut&&Qt(it));r!==n;)s.push(r),r=t.charAt(Ft),E.test(r)?Ft++:(r=n,0===Ut&&Qt(it));34===t.charCodeAt(Ft)?(r=x,Ft++):(r=n,0===Ut&&Qt(et)),r!==n?($t=e,e=Pt(s)):(Ft=e,e=n)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(tt));return e}())===n&&(e=function(){var e,i,s,r;Ut++,e=Ft,39===t.charCodeAt(Ft)?(i=w,Ft++):(i=n,0===Ut&&Qt(rt));if(i!==n){for(s=[],r=t.charAt(Ft),B.test(r)?Ft++:(r=n,0===Ut&&Qt(ot));r!==n;)s.push(r),r=t.charAt(Ft),B.test(r)?Ft++:(r=n,0===Ut&&Qt(ot));39===t.charCodeAt(Ft)?(r=w,Ft++):(r=n,0===Ut&&Qt(rt)),r!==n?($t=e,e=kt(s)):(Ft=e,e=n)}else Ft=e,e=n;Ut--,e===n&&(i=n,0===Ut&&Qt(st));return e}()),e}function ne(){var e,i,s,r;if(48===t.charCodeAt(Ft)?(e=f,Ft++):(e=n,0===Ut&&Qt(Z)),e===n)if(e=Ft,i=function(){var e;e=t.charAt(Ft),R.test(e)?Ft++:(e=n,0===Ut&&Qt(Q));return e}(),i!==n){for(s=[],r=he();r!==n;)s.push(r),r=he();e=i=[i,s]}else Ft=e,e=n;return e}function he(){var e;return e=t.charAt(Ft),M.test(e)?Ft++:(e=n,0===Ut&&Qt(J)),e}function ae(){var e,i,s;return e=function(){var e,i,s,r;return(e=oe())===n&&(e=Ft,40===t.charCodeAt(Ft)?(i=y,Ft++):(i=n,0===Ut&&Qt(nt)),i!==n?(ee(),(s=ge())!==n?(ee(),41===t.charCodeAt(Ft)?(r=v,Ft++):(r=n,0===Ut&&Qt(ht)),r!==n?($t=e,e=Mt(s)):(Ft=e,e=n)):(Ft=e,e=n)):(Ft=e,e=n)),e}(),e===n&&(e=Ft,i=function(){var e;e=t.charAt(Ft),W.test(e)?Ft++:(e=n,0===Ut&&Qt(at));return e}(),i!==n?(ee(),(s=ae())!==n?(ee(),$t=e,e=Rt(i,s)):(Ft=e,e=n)):(Ft=e,e=n)),e}function le(){var e,i,s;return e=Ft,(i=se())!==n?(ee(),s=function(){var e,i,s,r;e=Ft,40===t.charCodeAt(Ft)?(i=y,Ft++):(i=n,0===Ut&&Qt(nt));i!==n?(ee(),s=Ft,r=function(){var e,i,s,r,o,h,a,l;if(e=Ft,i=ge(),i!==n){for(s=[],r=Ft,o=ee(),44===t.charCodeAt(Ft)?(h=b,Ft++):(h=n,0===Ut&&Qt(lt)),h!==n?(a=ee(),(l=ge())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),44===t.charCodeAt(Ft)?(h=b,Ft++):(h=n,0===Ut&&Qt(lt)),h!==n?(a=ee(),(l=ge())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Wt(i,s)}else Ft=e,e=n;return e}(),r!==n?s=r=[r,ee()]:(Ft=s,s=n),s===n&&(s=null),41===t.charCodeAt(Ft)?(r=v,Ft++):(r=n,0===Ut&&Qt(ht)),r!==n?($t=e,e=Bt(s)):(Ft=e,e=n)):(Ft=e,e=n);return e}(),s!==n?($t=e,e=Et(i,s)):(Ft=e,e=n)):(Ft=e,e=n),e===n&&(e=ae()),e}function de(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=le())!==n){for(s=[],r=Ft,o=ee(),h=t.charAt(Ft),I.test(h)?Ft++:(h=n,0===Ut&&Qt(dt)),h!==n?(a=ee(),(l=le())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),h=t.charAt(Ft),I.test(h)?Ft++:(h=n,0===Ut&&Qt(dt)),h!==n?(a=ee(),(l=le())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=It(i,s)}else Ft=e,e=n;return e}function ce(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=de())!==n){for(s=[],r=Ft,o=ee(),h=t.charAt(Ft),W.test(h)?Ft++:(h=n,0===Ut&&Qt(at)),h!==n?(a=ee(),(l=de())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),h=t.charAt(Ft),W.test(h)?Ft++:(h=n,0===Ut&&Qt(at)),h!==n?(a=ee(),(l=de())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Ht(i,s)}else Ft=e,e=n;return e}function pe(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=ce())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===T?(h=T,Ft+=2):(h=n,0===Ut&&Qt(ct)),h===n&&(t.substr(Ft,2)===S?(h=S,Ft+=2):(h=n,0===Ut&&Qt(pt)),h===n&&(h=t.charAt(Ft),H.test(h)?Ft++:(h=n,0===Ut&&Qt(ut)))),h!==n?(a=ee(),(l=ce())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===T?(h=T,Ft+=2):(h=n,0===Ut&&Qt(ct)),h===n&&(t.substr(Ft,2)===S?(h=S,Ft+=2):(h=n,0===Ut&&Qt(pt)),h===n&&(h=t.charAt(Ft),H.test(h)?Ft++:(h=n,0===Ut&&Qt(ut)))),h!==n?(a=ee(),(l=ce())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Ot(i,s)}else Ft=e,e=n;return e}function ue(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=pe())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===V?(h=V,Ft+=2):(h=n,0===Ut&&Qt(gt)),h===n&&(t.substr(Ft,2)===C?(h=C,Ft+=2):(h=n,0===Ut&&Qt(mt))),h!==n?(a=ee(),(l=pe())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===V?(h=V,Ft+=2):(h=n,0===Ut&&Qt(gt)),h===n&&(t.substr(Ft,2)===C?(h=C,Ft+=2):(h=n,0===Ut&&Qt(mt))),h!==n?(a=ee(),(l=pe())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Dt(i,s)}else Ft=e,e=n;return e}function ge(){var e,i,s,r,o,h,a,l;if(e=Ft,(i=ue())!==n){for(s=[],r=Ft,o=ee(),t.substr(Ft,2)===_?(h=_,Ft+=2):(h=n,0===Ut&&Qt(ft)),h===n&&(t.substr(Ft,2)===A?(h=A,Ft+=2):(h=n,0===Ut&&Qt(xt))),h!==n?(a=ee(),(l=ue())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);r!==n;)s.push(r),r=Ft,o=ee(),t.substr(Ft,2)===_?(h=_,Ft+=2):(h=n,0===Ut&&Qt(ft)),h===n&&(t.substr(Ft,2)===A?(h=A,Ft+=2):(h=n,0===Ut&&Qt(xt))),h!==n?(a=ee(),(l=ue())!==n?r=o=[o,h,a,l]:(Ft=r,r=n)):(Ft=r,r=n);$t=e,e=Nt(i,s)}else Ft=e,e=n;return e}function me(t,e){return e.reduce((function(t,e){return{type:"BinaryExpression",operator:e[1],left:t,right:e[3]}}),t)}if(i=l(),e.peg$library)return{peg$result:i,peg$currPos:Ft,peg$FAILED:n,peg$maxFailExpected:zt,peg$maxFailPos:Gt};if(i!==n&&Ft===t.length)return i;throw i!==n&&Ft<t.length&&Qt({type:"end"}),s=zt,r=Gt<t.length?t.charAt(Gt):null,o=Gt<t.length?Jt(Gt,Gt+1):Jt(Gt,Gt),new hi(hi.buildMessage(s,r),s,r,o)}!function(t,e){function i(){this.constructor=t}i.prototype=e.prototype,t.prototype=new i}(hi,Error),hi.prototype.format=function(t){var e="Error: "+this.message;if(this.location){var i,s=null;for(i=0;i<t.length;i++)if(t[i].source===this.location.source){s=t[i].text.split(/\r\n|\n|\r/g);break}var r=this.location.start,o=this.location.source&&"function"==typeof this.location.source.offset?this.location.source.offset(r):r,n=this.location.source+":"+o.line+":"+o.column;if(s){var h=this.location.end,a=ai("",o.line.toString().length," "),l=s[r.line-1],d=(r.line===h.line?h.column:l.length+1)-r.column||1;e+="\n --\x3e "+n+"\n"+a+" |\n"+o.line+" | "+l+"\n"+a+" | "+ai("",r.column-1," ")+ai("",d,"^")}else e+="\n at "+n}return e},hi.buildMessage=function(t,e){var i={literal:function(t){return'"'+r(t.text)+'"'},class:function(t){var e=t.parts.map((function(t){return Array.isArray(t)?o(t[0])+"-"+o(t[1]):o(t)}));return"["+(t.inverted?"^":"")+e.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(t){return t.description}};function s(t){return t.charCodeAt(0).toString(16).toUpperCase()}function r(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function o(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+s(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+s(t)}))}function n(t){return i[t.type](t)}return"Expected "+function(t){var e,i,s=t.map(n);if(s.sort(),s.length>0){for(e=1,i=1;e<s.length;e++)s[e-1]!==s[e]&&(s[i]=s[e],i++);s.length=i}switch(s.length){case 1:return s[0];case 2:return s[0]+" or "+s[1];default:return s.slice(0,-1).join(", ")+", or "+s[s.length-1]}}(t)+" but "+function(t){return t?'"'+r(t)+'"':"end of input"}(e)+" found."};class di{compile(t){const e=li(t,{});return new ni(t,e)}execute(t){return this.compile(t).execute()}}class ci{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("=")}startProviding(t){for(const e of t)this.pvs.set(e.name,new pi(e))}stopProviding(t){for(const e of t)this.pvs.delete(e.name)}isNavigable(){return!1}shutdown(){}}class pi{constructor(t){this.pv=t;const e=new di;this.compiledFormula=e.compile(t.name);for(const e of this.compiledFormula.getPVNames()){const i=t.pvEngine.createPV(e);this.compiledFormula.updateDataSource(i.name,{value:i.value,acquisitionStatus:"good"}),t.pvEngine.addListener(e,(()=>{this.compiledFormula.updateDataSource(e,{value:t.pvEngine.getValue(e),acquisitionStatus:"good"}),this.trigger()}))}this.trigger()}trigger(){const t=this.compiledFormula.execute();this.pv.pvEngine.setValue(new Date,this.pv.name,t)}}function ui(t){return!isNaN(t)&&(Number.isInteger(parseFloat(t))||t%1!=0)}function gi(t){return ui(t)?parseFloat(t):(console.warn(`Not a valid float: ${t}`),t)}function mi(t){return null!=t?String(t):t}class fi extends wt{constructor(t,e,i,s){super(t,e),this.type=i,this.initializer=s,this.writable=!0}setSample(t){if("VDouble"===this.type)t.value=gi(t.value);else if("VDoubleArray"===this.type)for(let e=0;e<t.value.length;e++)t.value[e]=gi(t.value);else if("VString"===this.type)t.value=mi(t.value);else if("VStringArray"===this.type)for(let e=0;e<t.value.length;e++)t.value[e]=mi(t.value);else"string"==typeof t.value&&ui(t.value)&&(t.value=parseFloat(t.value));super.setSample(t)}}const xi=/(loc\:\/\/[^\(<]+)(<(.*)>)?(\((.*)\))?/;function wi(t){if(!t.startsWith("loc://"))return t;const e=t.match(xi);return e?e[1]:t}class yi{constructor(t){this.display=t,this.rules=[],this.scripts=[],this.pvs=new Map,this.providers=[],this.scriptLibraries={},this.listeners=new Map}init(){for(const t of this.listeners.entries()){const e=this.pvs.get(t[0]);if(e&&null!==e.value&&void 0!==e.value)for(const e of t[1])e()}}clearState(){this.disconnectAll(),this.rules=[],this.scripts=[],this.listeners.clear()}getPVNames(){return[...this.pvs.keys()]}hasPV(t){const e=wi(t);return this.pvs.has(e)}getPV(t){const e=wi(t);return this.pvs.get(e)}disconnectAll(){for(const t of this.providers){const e=[];for(const i of this.pvs.values())t.canProvide(i.name)&&e.push(i);e.length&&t.stopProviding(e)}this.pvs.clear()}createPV(t){if(t.startsWith("loc://"))return this.createLocalPV(t);let e=this.pvs.get(t);if(e)return e;e=new wt(t,this),this.pvs.set(t,e);for(const i of this.providers)if(i.canProvide(t))return e.navigable=i.isNavigable(),i.startProviding([e]),e;return console.warn(`No provider for PV ${t}`),e.disconnected=!0,e}createHistoricalDataProvider(t,e){for(const i of this.providers)if(i.canProvide(t)){if(i.createHistoricalDataProvider)return i.createHistoricalDataProvider(t,e);break}}requestRepaint(){this.display.requestRepaint()}createLocalPV(t){const e=t.match(xi);let i,s;if(e){if(t=e[1],e[3])switch(e[3]){case"VDouble":case"VDoubleArray":case"VString":case"VStringArray":i=e[3];break;default:console.warn(`Unknown local PV type information: ${e[3]}`)}if(void 0!==e[5]){const t=e[5];s=t.startsWith('"')&&t.endsWith('"')?t.substring(1,t.length-1):-1!==t.indexOf(",")?t.split(",").map((t=>{const e=t.trim();return e.startsWith('"')&&e.endsWith('"')?e.substring(1,e.length-1):Number(e)})):Number(t)}}let r=this.pvs.get(t),o=!1;if(r){const e=r;e.type&&i&&e.type!==i&&console.warn(`PV ${t} is defined with different types: ${e.type} !== ${i}`),void 0===e.initializer||void 0===s||this.initializerEquals(e.initializer,s)?void 0===e.initializer&&void 0!==s&&(o=!0):console.warn(`PV ${t} is defined with different initializers: ${e.initializer} !== ${s}`)}return r?i&&!r.type&&(r.type=i):(r=new fi(t,this,i,s),this.pvs.set(t,r),o=!0),o&&void 0!==s&&this.setValue(new Date,t,s),r}initializerEquals(t,e){if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(t[i]!==e[i])return!1;return!0}return t===e}getValue(t){const e=wi(t),i=this.pvs.get(e);if(i)return i.value}setValue(t,e,i,s=yt.NONE){const r=wi(e),o=this.pvs.get(r);if(!o)throw new Error(`Cannot set value of unknown PV ${e}`);o.setSample({time:t,value:i,severity:s});for(const t of this.listeners.get(r)||[])t()}setValues(t){const e=[];for(const i of t.keys()){const s=this.pvs.get(i);if(s){s.setSample(t.get(i));for(const t of this.listeners.get(i)||[])e.push(t)}else console.warn(`Received an update for unknown pv ${i}`)}for(const t of e)t()}createScript(t,e,i){const s=[];for(const i of e.inputs){const e=t.expandMacro(i.pvName);s.push(this.createPV(e))}const r=new vi(t,e,i,s);this.scripts.push(r);for(let i=0;i<e.inputs.length;i++){const o=e.inputs[i],n=s[i];if(o.trigger){const i=t.expandMacro(o.pvName);this.addListener(i,(()=>{if(e.checkConnect)for(let t=0;t<e.inputs.length;t++){const i=s[t],r=e.inputs[t].trigger,o=null!==i.value&&void 0!==i.value;if(i.disconnected||r&&!o)return}r.scriptEngine.run(n)}),!1)}}return r}createRule(t,e){const i=[];for(const s of e.inputs){const e=t.expandMacro(s.pvName);i.push(this.createPV(e))}const s=new bi(t,e,i);this.rules.push(s);const r=()=>s.scriptEngine.run();for(const i of e.inputs)if(i.trigger){const e=t.expandMacro(i.pvName);this.addListener(e,r,!1)}}addProvider(t){this.providers.push(t)}addScriptLibrary(t,e){this.scriptLibraries[t]=e}addListener(t,e,i=!0){const s=wi(t),r=this.listeners.get(s);if(r?r.push(e):this.listeners.set(s,[e]),i){const t=this.pvs.get(s);t&&null!==t.value&&void 0!==t.value&&e()}}removeListener(t,e){const i=wi(t),s=this.listeners.get(i);if(s){const t=s.indexOf(e);-1!==t&&s.splice(t,1)}}}class vi{constructor(t,e,i,s){this.widget=t,this.script=e,this.text=i,this.pvs=s,this.scriptEngine=new _t(t,i,s)}}class bi{constructor(t,e,i){this.widget=t,this.rule=e;let s="";const r=t.properties.getProperty(e.propertyName);if(!r)throw new Error(`Cannot create rule for unsupported property ${e.propertyName}`);if(e.expressions.length){let t=!1,o=!1,n=!1,h=!1;for(const i of e.expressions)i.expression.match(/pv[0-9]+/)&&(t=!0),e.outputExpression&&i.outputValue.toString().match(/pv[0-9]+/)&&(t=!0),-1!==i.expression.indexOf("pvInt")&&(o=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvInt")&&(o=!0),-1!==i.expression.indexOf("pvStr")&&(n=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvStr")&&(n=!0),-1!==i.expression.indexOf("pvSev")&&(h=!0),e.outputExpression&&-1!==i.outputValue.toString().indexOf("pvSev")&&(h=!0);for(let e=0;e<i.length;e++)t&&(s+=`var pv${e} = PVUtil.getDouble(pvs[${e}]);\n`),o&&(s+=`var pvInt${e} = PVUtil.getLong(pvs[${e}]);\n`),n&&(s+=`var pvStr${e} = PVUtil.getString(pvs[${e}]);\n`),h&&(s+=`var pvSev${e} = PVUtil.getSeverity(pvs[${e}]);\n`);for(let t=0;t<e.expressions.length;t++){const i=e.expressions[t].expression,o=e.expressions[t].outputValue;if(t>0&&(s+="else "),s+=`if (${i}) widget.setPropertyValue("${e.propertyName}", `,e.outputExpression)s+=`${o});\n`;else{s+=`${this.printScriptValue(r,o)});\n`}}const a=r.value,l=this.printScriptValue(r,a);s+=`else widget.setPropertyValue("${e.propertyName}", `,s+=`${l});\n`}this.scriptEngine=new _t(t,s,i)}printScriptValue(t,e){return null==e?"null":t.printScriptValue(e)}}class Ti{constructor(t,e,i){this.pv=t,this.interval=e,void 0!==i&&t.pvEngine.setValue(new Date,t.name,i),this.interval>0&&(this.timer=window.setInterval((()=>{this.generateSample(new Date)}),e))}emit(t,e){let i=yt.NONE;void 0!==this.pv.lowerAlarmLimit&&e<this.pv.lowerAlarmLimit||void 0!==this.pv.upperAlarmLimit&&e>this.pv.upperAlarmLimit?i=yt.MAJOR:(void 0!==this.pv.lowerWarningLimit&&e<this.pv.lowerWarningLimit||void 0!==this.pv.upperWarningLimit&&e>this.pv.upperWarningLimit)&&(i=yt.MINOR),this.pv.pvEngine.setValue(t,this.pv.name,e,i)}stop(){window.clearInterval(this.timer)}}class Si extends Ti{constructor(t,e){super(t,-1,e)}generateSample(){}}class Vi extends Ti{constructor(t,e,i,s){super(t,s),this.min=e,this.max=i;const r=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*r,t.lowerWarningLimit=e+.2*r,t.upperWarningLimit=e+.8*r,t.upperAlarmLimit=e+.9*r,t.upperDisplayLimit=i}generateSample(t){const e=Math.random()*(this.max-this.min)+this.min;this.emit(t,e)}}class Ci extends Ti{constructor(t,e,i,s){super(t,s),this.avg=e,this.stddev=i,t.units="x",t.lowerDisplayLimit=e-4*i,t.lowerAlarmLimit=e-2*i,t.lowerWarningLimit=e-i,t.upperWarningLimit=e+i,t.upperAlarmLimit=e+2*i,t.upperDisplayLimit=e+4*i}generateSample(t){let e,i,s;do{e=2*Math.random()-1,i=2*Math.random()-1,s=e*e+i*i}while(s>=1||0===s);const r=e*Math.sqrt(-2*Math.log(s)/s);this.emit(t,this.avg+r*this.stddev)}}class _i extends Ti{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.samplesPerCycle=s,this.currentValue=0;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){const e=this.max-this.min,i=Math.sin(2*this.currentValue*Math.PI/this.samplesPerCycle)*e/2+this.min+e/2;this.currentValue++,this.emit(t,i)}}let Ai=class extends Ti{constructor(t,e,i,s,r){super(t,r),this.min=e,this.max=i,this.inc=s,this.currentValue=0,this.currentValue=s>=0?e-s:i-s;const o=this.max-this.min;t.units="x",t.lowerDisplayLimit=e,t.lowerAlarmLimit=e+.1*o,t.lowerWarningLimit=e+.2*o,t.upperWarningLimit=e+.8*o,t.upperAlarmLimit=e+.9*o,t.upperDisplayLimit=i}generateSample(t){this.currentValue=this.currentValue+this.inc,this.currentValue>this.max&&(this.currentValue=this.min),this.currentValue<this.min&&(this.currentValue=this.max),this.emit(t,this.currentValue)}};const Li=/sim\:\/\/([a-zA-Z]+)(\((.*)\))?/;class Pi{constructor(){this.pvs=new Map}canProvide(t){return t.startsWith("sim://")}startProviding(t){for(const e of t){const t=new ki(e);this.pvs.set(e.name,t)}}stopProviding(t){for(const e of t){const t=this.pvs.get(e.name);t&&(t.fn.stop(),this.pvs.delete(e.name))}}isNavigable(){return!1}shutdown(){for(const t of this.pvs.values())t.fn.stop()}}class ki{constructor(t){this.pv=t;const e=t.name.match(Li);if(e){const t=e[3]?e[3].split(","):[];for(let e=0;e<t.length;e++)t[e]=t[e].trim();this.fn=this.createGenerator(e[1],t)}else console.warn(`Unexpected pattern for PV ${t.name}`),this.fn=new Si(t,void 0)}createGenerator(t,e){switch(t){case"const":const i=this.saferEval(e[0]);return new Si(this.pv,i);case"gaussianNoise":return this.createGaussianNoise(e);case"noise":return this.createNoise(e);case"ramp":return this.createRamp(e);case"sine":return this.createSine(e);default:return console.warn(`Unexpected function ${t} for PV ${this.pv.name}`),new Si(this.pv,void 0)}}saferEval(t){return Function('"use strict";return ('+t+")")()}createNoise(t){if(0===t.length)return new Vi(this.pv,-5,5,1e3);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Vi(this.pv,e,i,s)}}createGaussianNoise(t){if(0===t.length)return new Ci(this.pv,0,1,100);{const e=parseFloat(t[0]),i=parseFloat(t[1]),s=1e3*parseFloat(t[2]);return new Ci(this.pv,e,i,s)}}createRamp(t){let e;if(0===t.length)e=new Ai(this.pv,-5,5,1,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new Ai(this.pv,i,s,1,r)}else{if(4!==t.length)return console.warn(`Unexpected ramp arguments for PV ${this.pv.name}`),new Si(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new Ai(this.pv,i,s,r,o)}}return e}createSine(t){let e;if(0===t.length)e=new _i(this.pv,-5,5,10,1e3);else if(3===t.length){const i=parseFloat(t[0]),s=parseFloat(t[1]),r=1e3*parseFloat(t[2]);e=new _i(this.pv,i,s,10,r)}else{if(4!==t.length)return console.warn(`Unexpected sine arguments for PV ${this.pv.name}`),new Si(this.pv,void 0);{const i=parseFloat(t[0]),s=parseFloat(t[1]),r=parseFloat(t[2]),o=1e3*parseFloat(t[3]);e=new _i(this.pv,i,s,r,o)}}return e}}const Mi="font",Ri="push_action_index",Ei="release_action_index",Bi="toggle_button",Wi="image";class Ii extends ke{constructor(t,e){super(t,e),this.pushed=!1,this.imageLoaded=!1,this.properties.add(new W(Mi)),this.properties.add(new E(Bi)),this.properties.add(new M(Ri)),this.properties.add(new M(Ei)),this.properties.add(new P(Wi))}init(){this.image&&(this.imageElement=new Image,this.imageElement.onload=()=>{this.imageLoaded=!0,this.requestRepaint()},this.imageElement.src=this.resolvePath(this.image)),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,this.requestRepaint())},mouseOut:()=>{this.pushed=!1,this.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,this.requestRepaint())},click:()=>{this.executeActionByIndex(this.pushed?this.releaseActionIndex:this.pushActionIndex),this.toggleButton&&(this.pushed=!this.pushed)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){const e=t.ctx,{scale:s}=this;t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const r=1*s,o=this.holderY+r/2,n=this.holderX+r/2,h=this.holderY+this.holderHeight-r+r/2,a=this.holderX+this.holderWidth-r+r/2;t.strokePath({lineWidth:r,color:this.pushed?i.BUTTON_LIGHTEST:i.BLACK,path:new C(a,h).lineTo(a,o).moveTo(a,h).lineTo(n,h)}),t.strokePath({lineWidth:r,color:this.pushed?this.backgroundColor:i.BUTTON_DARKER,path:new C(a-r,h-r).lineTo(a-r,o+r).moveTo(a-r,h-r).lineTo(n+r,h-r)}),t.strokePath({lineWidth:r,color:this.pushed?i.BLACK:i.BUTTON_LIGHTEST,path:new C(n,o).lineTo(a-r,o).moveTo(n,o).lineTo(n,h-r)}),t.strokePath({lineWidth:r,color:this.pushed?i.BUTTON_DARKER:this.backgroundColor,path:new C(n+r,o+r).lineTo(a-r-r,o+r).moveTo(n+r,o+r).lineTo(n+r,h-r-r)});const l=this.text.split("\n");let d,c;if(e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),this.imageElement&&this.imageLoaded){const t=e.measureText(l[0]).width,i=this.font.height,r=this.imageElement.naturalHeight*s,o=this.imageElement.naturalWidth*s,n=(this.height-r)/i,h=5*s;if((this.width-o)/t>n){e.textBaseline="middle",e.textAlign="left",d=this.x+(this.width-t)/2+h,c=this.y+this.height/2;const i=this.x+(this.width-t)/2-o,s=this.y+(this.height-r)/2;e.drawImage(this.imageElement,i,s,o,r)}else{e.textAlign="center",e.textBaseline="top";const t=i+r;d=this.x+this.width/2,c=this.y+(this.height-t)/2+r;const s=this.x+(this.width-o)/2,n=this.y+(this.height-t)/2;e.drawImage(this.imageElement,s,n,o,r)}this.pushed&&(d+=1*s,c+=1*s),e.fillText(l[0],d,c)}else{e.textAlign="start",e.textBaseline="top";let t=0;for(const i of l){const s=e.measureText(i).width;t=Math.max(t,s)}d=this.x+(this.width-t)/2;const i=l.length*this.font.height+(l.length-1)*this.font.height*.2;c=this.y+(this.height-i)/2;for(const t of l){let i=d,r=c;this.pushed&&(i+=1*s,r+=1*s),e.fillText(t,i,r),c+=1.2*this.font.height}}}getHookedActions(){const{actions:t}=this;if(t.hookAllActionsToClick)return t.actions;if(this.pushed){const e=this.releaseActionIndex;return[t.getAction(e)]}{const e=this.pushActionIndex;return[t.getAction(e)]}}get font(){return this.properties.getValue(Mi).scale(this.scale)}get image(){return this.properties.getValue(Wi)}get toggleButton(){return this.properties.getValue(Bi)}get pushActionIndex(){return this.properties.getValue(Ri)}get releaseActionIndex(){return this.properties.getValue(Ei)}get backgroundColor(){const t=this.properties.getProperty("background_color");return t&&t.value!==i.TRANSPARENT?t.value:i.BUTTON}}const Hi="data_type",Oi="effect_3d",Di="font",Ni="off_color",Fi="off_label",$i="off_state",ji="on_color",Gi="on_label",zi="on_state",Ui="push_action_index",qi="released_action_index",Yi="show_led",Xi="show_boolean_label",Ki="square_button",Zi="toggle_button";class Ji extends ke{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new M("bit")),this.properties.add(new M(Hi)),this.properties.add(new E(Ki)),this.properties.add(new E(Yi)),this.properties.add(new E(Oi)),this.properties.add(new B(ji)),this.properties.add(new P(Gi)),this.properties.add(new P(zi)),this.properties.add(new B(Ni)),this.properties.add(new P(Fi)),this.properties.add(new P($i)),this.properties.add(new W(Di)),this.properties.add(new E(Zi)),this.properties.add(new M(Ui)),this.properties.add(new M(qi)),this.properties.add(new E(Xi))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&this.toggleOff(),this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.squareButton?this.drawSquare(t,e):this.drawEllipse(t,e),this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:e?this.onLabel:this.offLabel})}drawSquare(t,e){t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:i.DARK_GRAY});t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=2*this.scale,r=e?i.DARK_GRAY:i.WHITE,o=e?i.WHITE:i.DARK_GRAY;this.effect3d&&(t.fillPath({color:r,path:new C(this.x,this.y).lineTo(this.x,this.y+this.height).lineTo(this.x+s,this.y+this.height-s).lineTo(this.x+s,this.y+s).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width,this.y).closePath()}),t.fillPath({color:o,path:new C(this.x,this.y+this.height).lineTo(this.x+this.width,this.y+this.height).lineTo(this.x+this.width,this.y).lineTo(this.x+this.width-s,this.y+s).lineTo(this.x+this.width-s,this.y+this.height-s).lineTo(this.x+s,this.y+this.height-s).closePath()}));let n=this.backgroundColor;this.hovered&&(n=this.backgroundColor.mixWith(i.WHITE,.5)),t.fillRect({x:this.x+s,y:this.y+s,width:this.width-s-s,height:this.height-s-s,color:n})}drawEllipse(t,e){const{scale:s}=this;if(this.effect3d){const r=this.width/2,o=this.height/2,n=Math.sqrt(r*r+o*o),h=this.x+r+(o-r-n)/2-1*s,a=this.y+o-(o-r+n)/2-1*s,l=this.x+r+(o-r+n)/2+5*s,d=this.y+o-(o-r-n)/2+5*s,c=t.createLinearGradient(h,a,l,d);e?(c.addColorStop(0,i.DARK_GRAY.toString()),c.addColorStop(1,i.WHITE.toString())):(c.addColorStop(0,i.WHITE.toString()),c.addColorStop(1,i.DARK_GRAY.toString())),t.ctx.fillStyle=c}else t.ctx.fillStyle=e?i.WHITE.toString():i.DARK_GRAY.toString();const r=this.x+this.width/2,o=this.y+this.height/2,n=this.width/2,h=this.height/2;t.ctx.beginPath(),t.ctx.ellipse(r,o,n,h,0,0,2*Math.PI),t.ctx.fill();t.addHitRegion(this.areaRegion).addEllipse(r,o,n,h,0,0,2*Math.PI),this.hovered?t.ctx.fillStyle=this.backgroundColor.mixWith(i.WHITE,.5).toString():t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,o,n-2*s,h-2*s,0,0,2*Math.PI),t.ctx.fill()}drawHorizontal(t,e){const{scale:i}=this;if(this.showLed){let s;this.squareButton?(s=Math.floor(.3*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-2*i)):(s=Math.floor(.25*(this.width+this.height)/2),s>Math.min(this.width,this.height)&&(s=Math.min(this.width,this.height)-8*i));const r={x:Math.floor(this.x+.79999*this.width-s/2),y:Math.floor(this.y+this.height/2-s/2),width:s,height:s},o=r.x+r.width/2,n=r.y+r.height/2,h=r.width/2,a=r.height/2,l=e?this.onColor:this.offColor;if(t.fillEllipse({cx:o,cy:n,rx:h,ry:a,color:l}),this.effect3d){const e=t.createLinearGradient(r.x,r.y,r.x+r.width,r.y+r.height);e.addColorStop(0,"white"),e.addColorStop(1,l.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(o,n,h,a,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}drawVertical(t,e){const{scale:s}=this;if(this.showLed){let r;this.squareButton?(r=Math.floor(.3*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-2*s)):(r=Math.floor(.25*(this.width+this.height)/2),r>Math.min(this.width,this.height)&&(r=Math.min(this.width,this.height)-8*s));const o={x:Math.floor(this.x+this.width/2-r/2),y:Math.floor(this.y+(1-.79999)*this.height-r/2),width:r,height:r},n=e?this.onColor:this.offColor,h=o.x+o.width/2,a=o.y+o.height/2,l=o.width/2,d=o.height/2;if(t.fillEllipse({cx:h,cy:a,rx:l,ry:d,color:n}),this.effect3d){const e=t.createLinearGradient(o.x,o.y,o.x+o.width,o.y+o.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.ctx.beginPath(),t.ctx.ellipse(h,a,l,d,0,0,2*Math.PI),t.ctx.fillStyle=e,t.ctx.fill()}}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(Hi)}get toggleButton(){return this.properties.getValue(Zi)}get pushActionIndex(){return this.properties.getValue(Ui)}get releaseActionIndex(){return this.properties.getValue(qi)}get squareButton(){return this.properties.getValue(Ki)}get showLed(){return this.properties.getValue(Yi)}get showBooleanLabel(){return this.properties.getValue(Xi)}get effect3d(){return this.properties.getValue(Oi)}get onColor(){return this.properties.getValue(ji)}get onLabel(){return this.properties.getValue(Gi)}get onState(){return this.properties.getValue(zi)}get offColor(){return this.properties.getValue(Ni)}get offLabel(){return this.properties.getValue(Fi)}get offState(){return this.properties.getValue($i)}get font(){return this.properties.getValue(Di).scale(this.scale)}}const Qi="data_type",ts="effect_3d",es="off_color",is="off_label",ss="off_state",rs="on_color",os="on_label",ns="on_state",hs="push_action_index",as="released_action_index",ls="toggle_button";class ds extends ke{constructor(t,e){super(t,e),this.manualToggleState=!1,this.properties.add(new M("bit")),this.properties.add(new M(Qi)),this.properties.add(new E(ts)),this.properties.add(new B(rs)),this.properties.add(new P(os)),this.properties.add(new P(ns)),this.properties.add(new B(es)),this.properties.add(new P(is)),this.properties.add(new P(ss)),this.properties.add(new M(hs)),this.properties.add(new M(as)),this.properties.add(new E(ls))}init(){this.shaftRegion={id:`${this.wuid}-shaft`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){const e=this.booleanValue;this.width>this.height?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i=this.width,s=this.height;s>i/2?s=Math.floor(this.width/2):i=Math.floor(2*this.height);const r={x:Math.floor(63/218*i),y:0,width:s/2,height:s/2};this.drawPedestal(t,r,e);const o=Math.floor(35/218*i),n=Math.floor(45/105*s),h=Math.floor(43/218*i),a=Math.floor(35/105*s),l=Math.floor(1/7*r.width);if(e){const e={x:2*r.x+r.width-o,y:r.height/2-n/2,width:o,height:n},i={x:r.x+r.width/2-h/2+l,y:r.y+r.height/2-a/2,width:h,height:a};this.drawHorizontalBar(t,i,e,!0)}else{const e={x:0,y:r.height/2-n/2,width:o,height:n},i={x:r.x+r.width/2-h/2-l,y:r.y+r.height/2-a/2,width:h,height:a};this.drawHorizontalBar(t,i,e,!1)}}drawVertical(t,e){let i=this.width,s=this.height;i>s/2?i=Math.floor(this.height/2):s=Math.floor(2*this.width);const r={x:0,y:Math.floor(63/218*s),width:i/2,height:i/2};this.drawPedestal(t,r,e);const o=Math.floor(45/105*i),n=Math.floor(35/218*s),h=Math.floor(35/105*i),a=Math.floor(43/218*s);if(e){const e={x:r.width/2-o/2,y:0,width:o,height:n},i={x:r.x+r.width/2-h/2,y:r.y+r.height/2-a/2,width:h,height:a};i.y-=Math.floor(1/7*r.height),this.drawVerticalBar(t,i,e,!0)}else{const e=r.y+r.height/2+a/2+2*this.scale,i={x:r.width/2-o/2,y:r.y+r.height/2-a/2+e-n,width:o,height:n},s={x:r.x+r.width/2-h/2,y:r.y+r.height/2-a/2,width:h,height:a};s.y+=Math.floor(1/7*r.height),this.drawVerticalBar(t,s,i,!1)}}drawPedestal(t,e,s){let r=this.x+e.x+e.width/2,o=this.y+e.y+e.height/2,n=e.width/2,h=e.height/2;if(t.ctx.fillStyle=this.effect3d?i.WHITE.toString():i.GRAY.toString(),t.ctx.beginPath(),t.ctx.ellipse(r,o,n,h,0,0,2*Math.PI),t.ctx.fill(),this.effect3d){const i=t.createLinearGradient(this.x+e.x,this.y+e.y,this.x+e.x+e.width,this.y+e.y+e.height);s?(i.addColorStop(0,`rgba(255,255,255,${10/255})`),i.addColorStop(1,`rgba(0,0,0,${100/255})`)):(i.addColorStop(0,"rgba(0,0,0,0)"),i.addColorStop(1,`rgba(0,0,0,${150/255})`)),t.ctx.fillStyle=i,t.ctx.fill()}}drawHorizontalBar(t,e,i,s){let r=(s?0:10)/255,o=(s?150:220)/255;const n=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x,this.y+i.y+i.height);n.addColorStop(0,`rgba(0,0,0,${r})`),n.addColorStop(1,`rgba(0,0,0,${o})`);const h=t.addHitRegion(this.shaftRegion);let a=this.x+e.x+e.width/2,l=this.y+e.y+e.height/2,d=e.width/2,c=e.height/2;t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),h.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill());const p=[Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y),Math.round(this.x+i.x+i.width/2),Math.round(this.y+i.y+i.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y+e.height),Math.round(this.x+e.x+e.width/2),Math.round(this.y+e.y)];if(t.ctx.beginPath(),t.ctx.moveTo(p[0],p[1]),t.ctx.lineTo(p[2],p[3]),t.ctx.lineTo(p[4],p[5]),t.ctx.lineTo(p[6],p[7]),t.ctx.closePath(),h.addPath(new C(p[0],p[1]).lineTo(p[2],p[3]).lineTo(p[4],p[5]).lineTo(p[6],p[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=n,t.ctx.fill()),a=this.x+i.x+i.width/2,l=this.y+i.y+i.height/2,d=i.width/2,c=i.height/2,t.ctx.beginPath(),t.ctx.ellipse(a,l,d,c,0,0,2*Math.PI),h.addEllipse(a,l,d,c,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const{scale:e}=this,s=Math.sqrt(d*d+c*c),n=c-d,h=this.x+i.x+d+(n-s)/2-1*e,a=this.x+i.y+c-(n+s)/2-1*e,l=this.x+i.x+d+(n+s)/2+5*e,p=this.x+i.y+c-(n-s)/2+5*e,u=t.createLinearGradient(h,a,l,p);u.addColorStop(0,`rgba(0,0,0,${r})`),u.addColorStop(1,`rgba(0,0,0,${o})`),t.ctx.fillStyle=u,t.ctx.fill()}}drawVerticalBar(t,e,i,s){const r=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.x+i.width,this.y+i.y);r.addColorStop(0,`rgba(0,0,0,${10/255})`),r.addColorStop(1,`rgba(0,0,0,${s?210/255:160/255})`);const o=t.addHitRegion(this.shaftRegion);let n=this.x+e.x+e.width/2,h=this.y+e.y+e.height/2;t.ctx.beginPath(),t.ctx.ellipse(n,h,e.width/2,e.height/2,0,0,2*Math.PI),o.addEllipse(n,h,e.width/2,e.height/2,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill());const a=[Math.round(this.x+i.x),Math.round(this.y+i.y+i.height/2),Math.round(this.x+i.x+i.width),Math.round(this.y+i.y+i.height/2),Math.round(this.x+e.x+e.width),Math.round(this.y+e.y+e.height/2),Math.round(this.x+e.x),Math.round(this.y+e.y+e.height/2)];t.ctx.beginPath(),t.ctx.moveTo(a[0],a[1]),t.ctx.lineTo(a[2],a[3]),t.ctx.lineTo(a[4],a[5]),t.ctx.lineTo(a[6],a[7]),t.ctx.closePath(),o.addPath(new C(a[0],a[1]).lineTo(a[2],a[3]).lineTo(a[4],a[5]).lineTo(a[6],a[7]).closePath()),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d&&(t.ctx.fillStyle=r,t.ctx.fill()),n=this.x+i.x+i.width/2,h=this.y+i.y+i.height/2;const l=i.width/2,d=i.height/2;if(t.ctx.beginPath(),t.ctx.ellipse(n,h,l,d,0,0,2*Math.PI),o.addEllipse(n,h,l,d,0,0,2*Math.PI),t.ctx.fillStyle=s?this.onColor.toString():this.offColor.toString(),t.ctx.fill(),this.effect3d){const e=t.createLinearGradient(this.x+i.x,this.y+i.y,this.x+i.width,this.y+i.height);e.addColorStop(0,`rgba(0,0,0,${(s?5:10)/255})`),e.addColorStop(1,`rgba(0,0,0,${(s?180:160)/255})`),t.ctx.fillStyle=e,t.ctx.fill()}}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(Qi)}get toggleButton(){return this.properties.getValue(ls)}get pushActionIndex(){return this.properties.getValue(hs)}get releaseActionIndex(){return this.properties.getValue(as)}get effect3d(){return this.properties.getValue(ts)}get onColor(){return this.properties.getValue(rs)}get onLabel(){return this.properties.getValue(os)}get onState(){return this.properties.getValue(ns)}get offColor(){return this.properties.getValue(es)}get offLabel(){return this.properties.getValue(is)}get offState(){return this.properties.getValue(ss)}}const cs="enabled",ps="font",us="label",gs="selected_color",ms=new i(130,130,130),fs=new i(94,151,230);class xs extends ke{constructor(t,e){super(t,e),this.hovered=!1,this.manualToggleState=!1,this.properties.add(new M("bit")),this.properties.add(new E(cs)),this.properties.add(new W(ps)),this.properties.add(new P(us)),this.properties.add(new B(gs,new i(64,64,64)))}init(){this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseEnter:()=>{this.hovered=!0,this.requestRepaint()},mouseOut:()=>{this.hovered=!1,this.requestRepaint()},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:this.manualToggleState}draw(t){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const e=this.booleanValue,{boxSize:s,gap:r,scale:o}=this;let n=this.backgroundColor;this.hovered&&(n=n.mixWith(fs,.7));const h={x:this.x,y:this.y+this.height/2-s/2,width:s,height:s},a=t.createLinearGradient(h.x,h.y+1*o,h.x,h.y+h.height);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillRect(Object.assign(Object.assign({},h),{rx:2*o,ry:2*o,gradient:a})),t.strokeRect({x:h.x+.5*o,y:h.y+.5*o,width:h.width-1*o,height:h.height-1*o,rx:2*o,ry:2*o,color:ms}),e&&t.strokePath({lineWidth:3*o,color:this.selectedColor,path:new C(h.x+3*o,h.y+Math.floor(.45*s)).lineTo(h.x+Math.floor(.45*s),h.y+3*s/4-1*o).lineTo(h.x+s-2*o,h.y+3*o)}),this.enabled?t.fillText({x:h.x+h.width+r,y:h.y+h.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:this.label}):(t.fillText({x:h.x+h.width+r+1*o,y:h.y+h.height/2+1*o,align:"left",baseline:"middle",color:i.BUTTON_LIGHTEST,font:this.font,text:this.label}),t.fillText({x:h.x+h.width+r,y:h.y+h.height/2,align:"left",baseline:"middle",color:i.BUTTON_DARKER,font:this.font,text:this.label}))}get boxSize(){return 16*this.scale}get gap(){return 4*this.scale}get bit(){return this.properties.getValue("bit")}get enabled(){return this.properties.getValue(cs)}get selectedColor(){return this.properties.getValue(gs)}get font(){return this.properties.getValue(ps).scale(this.scale)}get label(){return this.properties.getValue(us)}}const ws="enabled",ys="font",vs="horizontal",bs="items",Ts="items_from_pv",Ss="selected_color";class Vs extends ke{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new E(ws)),this.properties.add(new W(ys)),this.properties.add(new E(vs)),this.properties.add(new F(bs,[])),this.properties.add(new E(Ts)),this.properties.add(new B(Ss))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",mouseDown:()=>{this.pushedItem=t,this.requestRepaint()},mouseOut:()=>{this.pushedItem=void 0,this.requestRepaint()},mouseUp:()=>{this.pushedItem=void 0,this.requestRepaint()},click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawButton(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:Math.round(this.area.x),y:Math.round(i),width:Math.round(this.area.width),height:Math.round(e)};i+=e,this.drawButton(t,r,s)}}drawButton(t,e,s){var r;const o=(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s],n=o||s===this.pushedItem;t.fillRect(Object.assign(Object.assign({},e),{color:o?this.selectedColor:this.backgroundColor}));t.addHitRegion(this.itemRegions[s]).addRect(e.x,e.y,e.width,e.height);const h=1*this.scale,a=e.y+h/2,l=e.x+h/2,d=e.y+e.height-h+h/2,c=e.x+e.width-h+h/2;t.strokePath({lineWidth:h,color:n?i.BUTTON_LIGHTEST:i.BLACK,path:new C(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d)}),t.strokePath({lineWidth:h,color:n?this.backgroundColor:i.BUTTON_DARKER,path:new C(c-h,d-h).lineTo(c-h,a+h).moveTo(c-h,d-h).lineTo(l+h,d-h)}),t.strokePath({lineWidth:h,color:n?i.BLACK:i.BUTTON_LIGHTEST,path:new C(l,a).lineTo(c-h,a).moveTo(l,a).lineTo(l,d-h)}),t.strokePath({lineWidth:h,color:n?i.BUTTON_DARKER:this.backgroundColor,path:new C(l+h,a+h).lineTo(c-h-h,a+h).moveTo(l+h,a+h).lineTo(l+h,d-h-h)}),t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,text:this.items[s],align:"center",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get enabled(){return this.properties.getValue(ws)}get font(){return this.properties.getValue(ys).scale(this.scale)}get horizontal(){return this.properties.getValue(vs)}get items(){return this.properties.getValue(bs)}get itemsFromPV(){return this.properties.getValue(Ts)}get selectedColor(){return this.properties.getValue(Ss)}}const Cs="enabled",_s="font",As="items",Ls="items_from_pv",Ps=new i(0,0,0,.1);class ks extends ke{constructor(t,e){super(t,e),this.properties.add(new E(Cs)),this.properties.add(new W(_s)),this.properties.add(new F(As,[])),this.properties.add(new E(Ls))}init(){this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",(()=>{var t,e;this.writeValue(null!==(e=null===(t=this.selectEl)||void 0===t?void 0:t.value)&&void 0!==e?e:"")}));const t=document.createElement("option");t.disabled=!0,t.value="",t.defaultSelected=!0,t.text=" -- select an option -- ",this.selectEl.add(t);for(let t=0;t<this.items.length;t++){const e=document.createElement("option");e.value=this.items[t],e.text=this.items[t],this.selectEl.add(e)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){var e,i;let s=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${s.x}px`,this.selectEl.style.top=`${s.y}px`,this.selectEl.style.width=`${s.width}px`,this.selectEl.style.height=`${s.height}px`,s=p(this.bounds,2*this.scale),t.fillRect(Object.assign(Object.assign({},s),{color:this.backgroundColor})),t.strokeRect(Object.assign(Object.assign({},s),{color:Ps,crispen:!0}));if(t.addHitRegion(this.areaRegion).addRect(s.x,s.y,s.width,s.height),null===(e=this.pv)||void 0===e?void 0:e.value)for(const e of this.items){let r=e===this.pv.value;if(!r)try{r=parseFloat(e)===this.pv.value}catch(t){}r&&t.fillText({x:5*this.scale+s.x,y:s.y+s.height/2,align:"left",baseline:"middle",color:this.foregroundColor,font:this.font,text:null===(i=this.pv)||void 0===i?void 0:i.value})}const{selectorWidth:r}=this,o=Math.min(s.height,r/2),n={x:s.x+s.width-r-5*this.scale+r/2,y:s.y+(s.height-o)/2+o};t.fillPath({color:this.foregroundColor,path:new C(n.x,n.y).lineTo(n.x-o,n.y-o).lineTo(n.x+o,n.y-o).closePath()})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get selectorWidth(){return 8*this.scale}get enabled(){return this.properties.getValue(Cs)}get font(){return this.properties.getValue(_s).scale(this.scale)}get items(){return this.properties.getValue(As)}get itemsFromPV(){return this.properties.getValue(Ls)}}const Ms="data_type",Rs="effect_3d",Es="font",Bs="off_image",Ws="off_label",Is="off_state",Hs="on_image",Os="on_label",Ds="on_state",Ns="push_action_index",Fs="released_action_index",$s="show_boolean_label",js="toggle_button";class Gs extends ke{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.manualToggleState=!1,this.properties.add(new M("bit")),this.properties.add(new M(Ms)),this.properties.add(new E(Rs)),this.properties.add(new P(Hs)),this.properties.add(new P(Os)),this.properties.add(new P(Ds)),this.properties.add(new P(Bs)),this.properties.add(new P(Ws)),this.properties.add(new P(Is)),this.properties.add(new W(Es)),this.properties.add(new E(js)),this.properties.add(new M(Ns)),this.properties.add(new M(Fs)),this.properties.add(new E($s))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage)),this.areaRegion={id:`${this.wuid}-area`,mouseDown:()=>{this.toggleButton&&this.booleanValue?this.toggleOff():this.toggleOn(),this.requestRepaint()},mouseUp:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},mouseOut:()=>{this.booleanValue&&!this.toggleButton&&(this.toggleOff(),this.requestRepaint())},tooltip:()=>this.tooltip,cursor:"pointer"}}toggleOn(){if(this.manualToggleState=!0,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,1);else{const t=this.pv.value|1<<this.bit;this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.onState);this.executeActionByIndex(this.pushActionIndex)}toggleOff(){if(this.manualToggleState=!1,this.pv&&this.pv.writable)if(0===this.dataType)if(this.bit<0)this.display.pvEngine.setValue(new Date,this.pv.name,0);else{const t=this.pv.value&~(1<<this.bit);this.display.pvEngine.setValue(new Date,this.pv.name,t)}else this.display.pvEngine.setValue(new Date,this.pv.name,this.offState);void 0!==this.releaseActionIndex&&this.executeActionByIndex(this.releaseActionIndex)}get booleanValue(){var t,e;return this.pv&&void 0!==this.pv.value?0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):((null===(e=this.pv)||void 0===e?void 0:e.value)>>this.bit&1)>0:1===this.dataType&&this.pv.toString()===this.onState:this.manualToggleState}draw(t){let e=this.bounds;this.borderAlarmSensitive&&(e=p(e,2*this.scale,2*this.scale));const i=this.booleanValue;i?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,e.x,e.y,e.width,e.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,e.x,e.y,e.width,e.height);t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,color:this.foregroundColor,align:"center",baseline:"middle",text:i?this.onLabel:this.offLabel})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(Ms)}get toggleButton(){return this.properties.getValue(js)}get pushActionIndex(){return this.properties.getValue(Ns)}get releaseActionIndex(){return this.properties.getValue(Fs)}get showBooleanLabel(){return this.properties.getValue($s)}get effect3d(){return this.properties.getValue(Rs)}get onImage(){return this.properties.getValue(Hs)}get onLabel(){return this.properties.getValue(Os)}get onState(){return this.properties.getValue(Ds)}get offImage(){return this.properties.getValue(Bs)}get offLabel(){return this.properties.getValue(Ws)}get offState(){return this.properties.getValue(Is)}get font(){return this.properties.getValue(Es).scale(this.scale)}}const zs="font",Us="label";class qs extends ke{constructor(t,e){super(t,e),this.properties.add(new W(zs)),this.properties.add(new P(Us))}init(){var t,e;this.areaRegion={id:`${this.wuid}-area`,tooltip:()=>this.tooltip,cursor:"pointer"},this.selectEl=document.createElement("select"),this.selectEl.style.display="block",this.selectEl.style.position="absolute",this.selectEl.style.boxSizing="border-box",this.selectEl.style.opacity="0",this.selectEl.addEventListener("change",(t=>{var e;const i=null===(e=this.selectEl)||void 0===e?void 0:e.value;if(i){this.selectEl.selectedIndex=0;const t=Number(i.substring(7));this.executeActionByIndex(t)}}));const i=document.createElement("option");i.disabled=!0,i.value="",i.defaultSelected=!0,i.text=" -- select an option -- ",this.selectEl.add(i);const s=this.actions.actions;for(let i=0;i<s.length;i++){const r=document.createElement("option");r.value=`action-${i}`,r.text=null!==(e=null===(t=s[i])||void 0===t?void 0:t.toString())&&void 0!==e?e:"",this.selectEl.add(r)}this.display.rootPanel.appendChild(this.selectEl)}draw(t){const e=this.display.measureAbsoluteArea(this);this.selectEl.style.display="block",this.selectEl.style.left=`${e.x}px`,this.selectEl.style.top=`${e.y}px`,this.selectEl.style.width=`${e.width}px`,this.selectEl.style.height=`${e.height}px`;const i=t.ctx;t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=this.label.split("\n");i.fillStyle=this.foregroundColor.toString(),i.font=this.font.getFontString(),i.textBaseline="middle",i.textAlign="center";let r=this.x+this.width/2,o=this.y+this.height/2;i.fillText(s[0],r,o)}hide(){this.selectEl&&(this.selectEl.style.display="none")}destroy(){this.selectEl&&(this.display.rootPanel.removeChild(this.selectEl),this.selectEl=void 0)}get font(){return this.properties.getValue(zs).scale(this.scale)}get backgroundColor(){const t=this.properties.getProperty("background_color");return t&&t.value!==i.TRANSPARENT?t.value:i.BUTTON}get label(){return this.properties.getValue(Us)}}class Ys extends Ii{}const Xs="enabled",Ks="font",Zs="horizontal",Js="items",Qs="items_from_pv",tr="selected_color",er=new i(120,120,120),ir=new i(94,151,230);class sr extends ke{constructor(t,e){super(t,e),this.itemRegions=[],this.properties.add(new E(Xs)),this.properties.add(new W(Ks)),this.properties.add(new E(Zs)),this.properties.add(new F(Js,[])),this.properties.add(new E(Qs)),this.properties.add(new B(tr))}init(){for(let t=0;t<this.items.length;t++)this.itemRegions.push({id:`${this.wuid}-item-${t}`,cursor:"pointer",click:()=>{this.writeValue(this.items[t]),this.requestRepaint()},mouseEnter:()=>{this.hoveredItem=t,this.requestRepaint()},mouseOut:()=>{this.hoveredItem=void 0,this.requestRepaint()},tooltip:()=>this.tooltip})}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const e=this.area.width/this.items.length;let i=this.area.x;for(let s=0;s<this.items.length;s++){const r={x:i,y:this.area.y,width:e,height:this.area.height};i+=e,this.drawRadio(t,r,s)}}drawVertical(t){const e=this.area.height/this.items.length;let i=this.area.y;for(let s=0;s<this.items.length;s++){const r={x:this.area.x,y:i,width:this.area.width,height:e};i+=e,this.drawRadio(t,r,s)}}drawRadio(t,e,s){var r;const{radioRadius:o,dotRadius:n,gap:h}=this;let a=this.backgroundColor;s===this.hoveredItem&&(a=a.mixWith(ir,.7));const l=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);l.addColorStop(0,i.WHITE.toString()),l.addColorStop(1,a.toString()),t.fillEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:o,ry:o,gradient:l});const d=1*this.scale;t.strokeEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:o,ry:o,color:er,lineWidth:d}),(null===(r=this.pv)||void 0===r?void 0:r.value)===this.items[s]&&t.fillEllipse({cx:e.x+o,cy:e.y+e.height/2,rx:n+d/2,ry:n+d/2,color:this.selectedColor});t.addHitRegion(this.itemRegions[s]).addRect(e.x,e.y,e.width,e.height),t.fillText({x:e.x+o+o+h,y:e.y+e.height/2,text:this.items[s],align:"left",baseline:"middle",color:this.foregroundColor,font:this.font})}writeValue(t){this.pv&&this.pv.writable&&this.display.pvEngine.setValue(new Date,this.pv.name,t)}get radioRadius(){return 7*this.scale}get dotRadius(){return 2*this.scale}get gap(){return 4*this.scale}get enabled(){return this.properties.getValue(Xs)}get font(){return this.properties.getValue(Ks).scale(this.scale)}get horizontal(){return this.properties.getValue(Zs)}get items(){return this.properties.getValue(Js)}get itemsFromPV(){return this.properties.getValue(Qs)}get selectedColor(){return this.properties.getValue(tr)}}const rr="enabled",or="font",nr="maximum",hr="minimum",ar="horizontal",lr="step_increment",dr="page_increment",cr="bar_length",pr="show_value_tip",ur=new i(243,243,243),gr=new i(232,232,231),mr=150;class fr extends ke{constructor(t,e){super(t,e),this.decreasePressed=!1,this.increasePressed=!1,this.pageDecreasePressed=!1,this.pageIncreasePressed=!1,this.properties.add(new E(rr)),this.properties.add(new E(ar)),this.properties.add(new E(pr)),this.properties.add(new W(or)),this.properties.add(new R(nr)),this.properties.add(new R(hr)),this.properties.add(new R(lr)),this.properties.add(new R(dr)),this.properties.add(new R(cr))}init(){this.decreaseRegion={id:`${this.wuid}-decrease`,mouseDown:()=>{this.decreasePressed=!0,this.stepDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.decreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.increaseRegion={id:`${this.wuid}-increase`,mouseDown:()=>{this.increasePressed=!0,this.stepIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.increasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.thumbRegion={id:`${this.wuid}-thumb`,mouseDown:()=>{this.grabStartValue=this.getCoercedValue()},grab:t=>{const e=this.horizontal?t.dx:t.dy,i=(this.maximum-this.minimum)*e/this.dragRange;this.setCoercedValue(this.grabStartValue+i),this.requestRepaint()},tooltip:()=>this.tooltip},this.pageDecreaseRegion={id:`${this.wuid}-page-decrease`,mouseDown:()=>{this.pageDecreasePressed=!0,this.pageDecreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageDecreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip},this.pageIncreaseRegion={id:`${this.wuid}-page-increase`,mouseDown:()=>{this.pageIncreasePressed=!0,this.pageIncreaseRepeatedly()},mouseUp:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},mouseOut:()=>{window.clearTimeout(this.actionTimeout),this.pageIncreasePressed=!1,this.requestRepaint()},tooltip:()=>this.tooltip}}draw(t){this.horizontal?this.drawHorizontal(t):this.drawVertical(t)}drawHorizontal(t){const{scale:e}=this,s=p(this.bounds,2*e);t.fillRect(Object.assign(Object.assign({},s),{color:ur}));const r=Math.min(s.height,s.width/2);this.drawLeftButton(t,{x:s.x,y:s.y,width:r,height:s.height}),this.drawRightButton(t,{x:s.x+s.width-r,y:s.y,width:r,height:s.height});const o=this.barLength,n=this.maximum+o,h=this.minimum,a=n-h,l=a-o,d=s.width-r-r,c=Math.floor(Math.max(6*e,d*o/a));this.dragRange=d-c;const u=this.getCoercedValue(),g=Math.floor((d-c)*(u-h)/l),m=d-g-c,f={x:s.x+r+g,y:s.y,width:c,height:s.height};t.fillRect(Object.assign(Object.assign({},f),{color:gr})),this.drawRaisedButtonBorder(t,f);t.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x+r,y:s.y,width:g,height:s.height};t.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&t.fillRect(Object.assign(Object.assign({},x),{color:i.BLACK}));const w={x:s.x+r+g+c,y:s.y,width:m,height:s.height};t.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&t.fillRect(Object.assign(Object.assign({},w),{color:i.BLACK}))}drawVertical(t){const{scale:e}=this,s=p(this.bounds,e);t.fillRect(Object.assign(Object.assign({},s),{color:ur}));const r=Math.min(s.width,s.height/2);this.drawUpButton(t,{x:s.x,y:s.y,width:s.width,height:r}),this.drawDownButton(t,{x:s.x,y:s.y+s.height-r,width:s.width,height:r});const o=this.barLength,n=this.maximum+o,h=this.minimum,a=n-h,l=a-o,d=s.height-r-r,c=Math.floor(Math.max(6*e,d*o/a));this.dragRange=d-c;const u=this.getCoercedValue(),g=Math.floor((d-c)*(u-h)/l),m=d-g-c,f={x:s.x,y:s.y+r+g,width:s.width,height:c};t.fillRect(Object.assign(Object.assign({},f),{color:gr})),this.drawRaisedButtonBorder(t,f);t.addHitRegion(this.thumbRegion).addRect(f.x,f.y,f.width,f.height);const x={x:s.x,y:s.y+r,width:s.width,height:g};t.addHitRegion(this.pageDecreaseRegion).addRect(x.x,x.y,x.width,x.height),this.pageDecreasePressed&&t.fillRect(Object.assign(Object.assign({},x),{color:i.BLACK}));const w={x:s.x,y:s.y+r+g+c,width:s.width,height:m};t.addHitRegion(this.pageIncreaseRegion).addRect(w.x,w.y,w.width,w.height),this.pageIncreasePressed&&t.fillRect(Object.assign(Object.assign({},w),{color:i.BLACK}))}drawLeftButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:gr})),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x,y:s.y+s.height/2};t.fillPath({color:i.BLACK,path:new C(o.x,o.y).lineTo(o.x+r,o.y-r).lineTo(o.x+r,o.y+r).closePath()})}drawRightButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:gr})),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height/2,s.width);s.x+=(s.width-r)/2,r=Math.max(r,1);const o={x:s.x+r,y:s.y+s.height/2};t.fillPath({color:i.BLACK,path:new C(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x-r,o.y+r).closePath()})}drawUpButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:gr})),this.decreasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.decreaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y};t.fillPath({color:i.BLACK,path:new C(o.x,o.y).lineTo(o.x-r,o.y+r).lineTo(o.x+r,o.y+r).closePath()})}drawDownButton(t,e){t.fillRect(Object.assign(Object.assign({},e),{color:gr})),this.increasePressed?this.drawPressedButtonBorder(t,e):this.drawRaisedButtonBorder(t,e);t.addHitRegion(this.increaseRegion).addRect(e.x,e.y,e.width,e.height);const s=p(e,3*this.scale);let r=Math.min(s.height,s.width/2);s.y+=(s.height-r)/2,r=Math.max(r,1);const o={x:s.x+s.width/2,y:s.y+r};t.fillPath({color:i.BLACK,path:new C(o.x,o.y).lineTo(o.x-r,o.y-r).lineTo(o.x+r,o.y-r).closePath()})}drawRaisedButtonBorder(t,e){this.drawButtonBorder(t,e,i.BUTTON_DARKEST,i.BUTTON_DARKER,i.BUTTON,i.BUTTON_LIGHTEST)}drawPressedButtonBorder(t,e){this.drawButtonBorder(t,e,i.BUTTON_LIGHTEST,i.BUTTON_LIGHTEST,i.BUTTON_DARKEST,i.BUTTON_DARKER)}drawButtonBorder(t,e,i,s,r,o){const n=1*this.scale,h=e.y+n/2,a=e.x+n/2,l=e.y+e.height-n+n/2,d=e.x+e.width-n+n/2;t.strokePath({color:i,path:new C(d,l).lineTo(d,h).moveTo(d,l).lineTo(a,l)}),t.strokePath({color:s,path:new C(d-n,l-n).lineTo(d-n,h+n).moveTo(d-n,l-n).lineTo(a+n,l-n)}),t.strokePath({color:r,path:new C(a,h).lineTo(d-n,h).moveTo(a,h).lineTo(a,l-n)}),t.strokePath({color:o,path:new C(a+n,h+n).lineTo(d-n-n,h+n).moveTo(a+n,h+n).lineTo(a+n,l-n-n)})}stepIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepIncreaseRepeatedly()),mr)}stepDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.stepDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.stepDecreaseRepeatedly()),mr)}stepIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.stepIncrement)}stepDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.stepIncrement)}pageIncreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageIncrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageIncreaseRepeatedly()),mr)}pageDecreaseRepeatedly(){window.clearTimeout(this.actionTimeout),this.pageDecrease(),this.requestRepaint(),this.actionTimeout=window.setTimeout((()=>this.pageDecreaseRepeatedly()),mr)}pageIncrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i+this.pageIncrement)}pageDecrease(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;this.setCoercedValue(i-this.pageIncrement)}setCoercedValue(t){this.pv&&this.pv.writable&&(t=t<this.minimum?this.minimum:t>this.maximum?this.maximum:t,this.display.pvEngine.setValue(new Date,this.pv.name,t))}getCoercedValue(){var t,e;const i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:(this.maximum-this.minimum)/2;return i<this.minimum?this.minimum:i>this.maximum?this.maximum:i}destroy(){window.clearTimeout(this.actionTimeout)}get enabled(){return this.properties.getValue(rr)}get horizontal(){return this.properties.getValue(ar)}get showValueTip(){return this.properties.getValue(pr)}get font(){return this.properties.getValue(or).scale(this.scale)}get minimum(){return this.properties.getValue(hr)}get maximum(){return this.properties.getValue(nr)}get stepIncrement(){return this.properties.getValue(lr)}get pageIncrement(){return this.properties.getValue(dr)}get barLength(){return this.properties.getValue(cr)}}const xr="confirm_message",wr="font",yr="format_type",vr="horizontal_alignment",br="multiline_input",Tr="password_input",Sr="precision",Vr="precision_from_pv",Cr="show_units",_r="vertical_alignment";class Ar extends ke{constructor(t,e){super(t,e),this.editing=!1,this.properties.add(new P(xr)),this.properties.add(new W(wr)),this.properties.add(new M(yr)),this.properties.add(new M(vr)),this.properties.add(new E(br)),this.properties.add(new E(Tr,!1)),this.properties.add(new M(Sr)),this.properties.add(new E(Vr)),this.properties.add(new E(Cr,!0)),this.properties.add(new M(_r,1))}init(){this.text&&(this.value=this.text),this.areaRegion={id:`${this.wuid}-area`,click:()=>{var t,e,i;if(this.pv&&!this.pv.writable)return;this.editing=!0;const s=this.display.measureAbsoluteArea(this);if(s.x-=2*this.scale,s.y-=2*this.scale,s.width+=2*this.scale,s.height+=2*this.scale,this.inputEl.value=null!==(i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.value)&&void 0!==i?i:"",this.inputEl.style.display="block",this.inputEl.style.position="absolute",this.inputEl.style.boxSizing="border-box",this.inputEl.style.left=`${s.x}px`,this.inputEl.style.top=`${s.y}px`,this.inputEl.style.width=`${s.width}px`,this.inputEl.style.height=`${s.height}px`,this.inputEl.autocomplete="off",this.multilineInput){this.inputEl.style.resize="none"}else{const t=this.inputEl;this.passwordInput&&(t.type="password")}this.inputEl.focus(),this.inputEl.select()},tooltip:()=>this.tooltip,cursor:"text"},this.inputEl=document.createElement(this.multilineInput?"textarea":"input"),this.inputEl.style.display="none",this.inputEl.addEventListener("keyup",(t=>{var e;if("Enter"===t.key){if(!this.multilineInput||t.ctrlKey){const t=(null===(e=this.inputEl)||void 0===e?void 0:e.value)||"";!this.confirmMessage||confirm(this.confirmMessage)?(this.value=t,this.pv&&this.display.pvEngine.setValue(new Date,this.pv.name,t),this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()):this.cancelInput()}}else"Escape"===t.key&&this.cancelInput()})),this.inputEl.addEventListener("blur",(t=>{this.cancelInput()})),this.display.rootPanel.appendChild(this.inputEl)}cancelInput(){this.inputEl.style.display="none",this.editing=!1,this.requestRepaint()}draw(t){var e,i;if(this.editing)return;t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height);const s=t.ctx;this.backgroundAlarmSensitive&&this.alarm?t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor}));const r=document.createElement("canvas");r.width=this.area.width,r.height=this.area.height;const o=r.getContext("2d");o.fillStyle=this.alarmSensitiveForegroundColor.toString(),o.font=this.font.getFontString();let n=this.x;0===this.horizAlignment?o.textAlign="start":1===this.horizAlignment?(n+=this.width/2,o.textAlign="center"):2===this.horizAlignment&&(n+=this.width,o.textAlign="end");let h=this.y;0===this.vertAlignment?o.textBaseline="top":1===this.vertAlignment?(h+=this.height/2,o.textBaseline="middle"):2===this.vertAlignment&&(h+=this.height,o.textBaseline="bottom");let a=this.text;if(this.pv&&void 0!==this.pv.value){let t=this.precisionFromPV?this.pv.precision:this.precision;-1===t&&(t=null!==(e=this.pv.precision)&&void 0!==e?e:-1),a=T(this.pv.value,this.formatType,t),this.showUnits&&(null===(i=this.pv)||void 0===i?void 0:i.units)&&(a+=" "+this.pv.units)}o.fillText(a,n-this.area.x,h-this.area.y),s.drawImage(r,this.area.x,this.area.y)}hide(){this.editing=!1,this.inputEl&&(this.inputEl.style.display="none")}destroy(){this.inputEl&&(this.display.rootPanel.removeChild(this.inputEl),this.inputEl=void 0)}get value(){return this.text}set value(t){this.properties.setValue("text",t),this.requestRepaint()}get confirmMessage(){return this.properties.getValue(xr)}get font(){return this.properties.getValue(wr).scale(this.scale)}get formatType(){return this.properties.getValue(yr)}get horizAlignment(){return this.properties.getValue(vr)}get multilineInput(){return this.properties.getValue(br)}get passwordInput(){return this.properties.getValue(Tr)}get precision(){return this.properties.getValue(Sr)}get precisionFromPV(){return this.properties.getValue(Vr)}get showUnits(){return this.properties.getValue(Cr)}get vertAlignment(){return this.properties.getValue(_r)}}const Lr="alpha",Pr="fill",kr="line_width",Mr="line_style",Rr="start_angle",Er="total_angle";class Br extends ke{constructor(t,e){super(t,e),this.properties.add(new M(Lr,255)),this.properties.add(new M(kr)),this.properties.add(new M(Rr)),this.properties.add(new M(Er)),this.properties.add(new E(Pr)),this.properties.add(new M(Mr))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawShape(t),t.ctx.globalAlpha=1}drawShape(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2,o=-f(this.startAngle),n=-f(this.totalAngle+this.startAngle);if(this.fill&&(t.ctx.fillStyle=this.alarmSensitiveBackgroundColor.toString(),t.ctx.beginPath(),t.ctx.moveTo(e,i),t.ctx.ellipse(e,i,s,r,0,o,n,!0),t.ctx.closePath(),t.ctx.fill()),this.lineWidth&&0!==this.totalAngle){let h;const{scale:a}=this;0===this.lineStyle?h=[]:1===this.lineStyle?h=[6*a,2*a]:2===this.lineStyle?h=[2*a,2*a]:console.warn(`Unsupported arc line style ${this.lineStyle}`),t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,startAngle:o,endAngle:n,lineWidth:this.lineWidth,anticlockwise:!0,color:this.alarmSensitiveForegroundColor,dash:h})}}get alpha(){return this.properties.getValue(Lr)}get lineWidth(){return this.scale*this.properties.getValue(kr)}get lineStyle(){return this.properties.getValue(Mr)}get startAngle(){return this.properties.getValue(Rr)}get totalAngle(){return this.properties.getValue(Er)}get fill(){return this.properties.getValue(Pr)}}const Wr="alpha",Ir="bg_gradient_color",Hr="fg_gradient_color",Or="fill_level",Dr="gradient",Nr="horizontal_fill",Fr="line_color",$r="line_width",jr="line_style";class Gr extends ke{constructor(t,e){super(t,e),this.properties.add(new M(Wr,255)),this.properties.add(new B(Ir)),this.properties.add(new B(Hr)),this.properties.add(new E(Dr)),this.properties.add(new M($r)),this.properties.add(new R(Or)),this.properties.add(new E(Nr)),this.properties.add(new B(Fr)),this.properties.add(new M(jr))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){const e=this.x+this.width/2,i=this.y+this.height/2,s=this.width/2,r=this.height/2;if(!this.transparent){const o=this.alarmSensitiveBackgroundColor;if(this.gradient){const n=this.horizontalFill?this.x:this.x+this.width,h=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,n,h);a.addColorStop(0,this.backgroundGradientStartColor.toString()),a.addColorStop(1,o.toString()),t.fillEllipse({cx:e,cy:i,rx:s,ry:r,gradient:a})}else t.fillEllipse({cx:e,cy:i,rx:s,ry:r,color:o})}this.lineWidth&&(0===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth}):1===this.lineStyle?t.strokeEllipse({cx:e,cy:i,rx:s,ry:r,color:this.lineColor,lineWidth:this.lineWidth,dash:[6*this.scale,2*this.scale]}):console.warn(`Unsupported ellipse line style ${this.lineStyle}`))}drawFill(t){const e=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.x+this.width/2,s=this.y+this.height/2,r=(this.width-this.lineWidth)/2,o=(this.height-this.lineWidth)/2,n=this.alarmSensitiveForegroundColor;if(this.gradient){const e=this.horizontalFill?this.x:this.x+this.width,h=this.horizontalFill?this.y+this.height:this.y,a=t.createLinearGradient(this.x,this.y,e,h);a.addColorStop(0,this.foregroundGradientStartColor.toString()),a.addColorStop(1,n.toString()),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,gradient:a})}else t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:n});t.ctx.restore()}get alpha(){return this.properties.getValue(Wr)}get lineWidth(){return this.scale*this.properties.getValue($r)}get fillLevel(){return this.properties.getValue(Or)}get horizontalFill(){return this.properties.getValue(Nr)}get lineColor(){return this.properties.getValue(Fr)}get lineStyle(){return this.properties.getValue(jr)}get gradient(){return this.properties.getValue(Dr)}get backgroundGradientStartColor(){return this.properties.getValue(Ir)}get foregroundGradientStartColor(){return this.properties.getValue(Hr)}}const zr="image_file",Ur="no_animation",qr="transparency";class Yr extends ke{constructor(t,e){super(t,e),this.imageLoading=!1,this.imageLoaded=!1,this.properties.add(new P(zr)),this.properties.add(new P(Ur)),this.properties.add(new E(qr,!0))}init(){this.imageElement=new Image(this.width,this.height),this.imageElement.onload=()=>{this.snapshotImage(this.imageElement),this.imageLoading=!1,this.imageLoaded=!0,this.requestRepaint()},this.triggerImageLoad()}draw(t){this.imageFile&&this.currentImageFile!==this.imageFile&&this.triggerImageLoad(),this.transparency||(t.ctx.fillStyle=this.backgroundColor.toString(),t.ctx.fillRect(this.x,this.y,this.width,this.height)),this.imageLoading&&this.imageSnapshot?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):this.imageLoaded&&(this.noAnimation?t.ctx.drawImage(this.imageSnapshot,this.x,this.y,this.width,this.height):t.ctx.drawImage(this.imageElement,this.x,this.y,this.width,this.height))}triggerImageLoad(){this.imageLoading=!0,this.imageLoaded=!1,this.imageElement&&this.imageFile&&(this.currentImageFile=this.imageFile,this.imageElement.src=this.resolvePath(this.imageFile))}snapshotImage(t){const e=document.createElement("canvas"),i=e.getContext("2d");e.width=t.naturalWidth,e.height=t.naturalHeight,i.drawImage(t,0,0),this.imageSnapshot=e}get transparency(){return this.properties.getValue(qr)}get imageFile(){return this.properties.getValue(zr)}get noAnimation(){return this.properties.getValue(Ur)}}const Xr="font",Kr="horizontal_alignment",Zr="vertical_alignment",Jr="wrap_words";class Qr extends ke{constructor(t,e){super(t,e),this.properties.add(new W(Xr)),this.properties.add(new M(Kr)),this.properties.add(new M(Zr)),this.properties.add(new E(Jr))}draw(t){const e=t.ctx;this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor});const i=this.wrapText(t,this.text,this.width);e.fillStyle=this.foregroundColor.toString(),e.font=this.font.getFontString(),e.textAlign="start",e.textBaseline="top";let s=0;for(const t of i){const i=e.measureText(t).width;s=Math.max(s,i)}let r=this.x;1===this.horizAlignment?r=this.x+(this.width-s)/2:2===this.horizAlignment&&(r=this.x+(this.width-s));const o=i.length*this.font.height+(i.length-1)*this.font.height*.2;let n=this.y;1===this.vertAlignment?n+=(this.height-o)/2:2===this.vertAlignment&&(n+=this.height-o);for(const t of i)e.fillText(t,r,n),n+=1.2*this.font.height}wrapText(t,e,i){let s=[];for(const r of e.split("\n"))s=s.concat(this.wrapLine(t,r,i));return s}wrapLine(t,e,i){if(!e)return[""];const s=[];let r,o,n,h=0;for(;e.length;){for(o=e.length;t.measureText(e.substr(0,o),this.font).width>i;o--);if(r=e.substr(0,o),o!==e.length)for(n=0;-1!==r.indexOf(" ",n);n=r.indexOf(" ",n)+1);s.push(r.substr(0,n||r.length)),h=Math.max(h,t.measureText(s[s.length-1],this.font).width),e=e.substr(s[s.length-1].length,e.length)}return s}get font(){return this.properties.getValue(Xr).scale(this.scale)}get horizAlignment(){return this.properties.getValue(Kr)}get vertAlignment(){return this.properties.getValue(Zr)}get wrapWords(){return this.properties.getValue(Jr)}}const to="alpha",eo="fill_level",io="horizontal_fill",so="line_color",ro="line_style",oo="line_width",no="points";class ho extends ke{constructor(t,e){super(t,e),this.properties.add(new M(to,255)),this.properties.add(new M(oo)),this.properties.add(new R(eo)),this.properties.add(new E(io)),this.properties.add(new B(so)),this.properties.add(new M(ro)),this.properties.add(new H(no,[]))}init(){this.addPropertyListener("x",((t,e)=>{const i=m(this.properties.getValue(no),t-e,0);this.properties.setValue(no,i),this.requestRepaint()})),this.addPropertyListener("y",((t,e)=>{const i=m(this.properties.getValue(no),0,t-e);this.properties.setValue(no,i),this.requestRepaint()}))}draw(t){const{scale:e}=this;t.ctx.globalAlpha=this.alpha/255;const i=C.fromPoints(this.points).closePath();if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillPath({path:i,color:e})}this.lineWidth&&(0===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor}):2===this.lineStyle?t.strokePath({path:i,lineWidth:this.lineWidth,color:this.lineColor,dash:[6*e,2*e]}):console.warn(`Unsupported polygon line style ${this.lineStyle}`)),this.fillLevel&&this.drawFill(t,i),t.ctx.globalAlpha=1}drawFill(t,e){let i=this.y,s=this.width,r=this.height;this.horizontalFill?s*=this.fillLevel/100:(r*=this.fillLevel/100,i+=r),t.ctx.save();let o=this.x-this.lineWidth/2,n=i-this.lineWidth/2,h=s+this.lineWidth,a=r+this.lineWidth;t.ctx.beginPath(),t.ctx.rect(o,n,h,a),t.ctx.clip();const l=this.alarmSensitiveForegroundColor;t.fillPath({path:e,color:l}),t.ctx.restore()}get alpha(){return this.properties.getValue(to)}get lineWidth(){return this.scale*this.properties.getValue(oo)}get fillLevel(){return this.properties.getValue(eo)}get horizontalFill(){return this.properties.getValue(io)}get lineColor(){return this.properties.getValue(so)}get lineStyle(){return this.properties.getValue(ro)}get points(){return v(this.properties.getValue(no),this.scale)}}const ao="alpha",lo="arrows",co="arrow_length",po="fill_arrow",uo="fill_level",go="horizontal_fill",mo="line_width",fo="points";class xo extends ke{constructor(t,e){super(t,e),this.properties.add(new M(ao,255)),this.properties.add(new M(mo)),this.properties.add(new R(uo)),this.properties.add(new E(go)),this.properties.add(new H(fo,[])),this.properties.add(new M(co)),this.properties.add(new E(po)),this.properties.add(new M(lo))}draw(t){const e=t.ctx;e.globalAlpha=this.alpha/255,this.transparent&&(e.globalAlpha=0),this.drawShape(e,this.backgroundColor),this.fillLevel&&this.drawFill(e),e.globalAlpha=1}drawFill(t){let e=this.y,i=this.width,s=this.height;this.horizontalFill?i*=this.fillLevel/100:(s*=this.fillLevel/100,e+=s),t.save();let r=this.x-this.lineWidth/2,o=e-this.lineWidth/2,n=i+this.lineWidth,h=s+this.lineWidth;t.beginPath(),t.rect(r,o,n,h),t.clip(),this.drawShape(t,this.foregroundColor),t.restore()}drawShape(t,e){t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath();for(let e=0;e<this.points.length;e++)0===e?t.moveTo(this.points[e].x,this.points[e].y):t.lineTo(this.points[e].x,this.points[e].y);if(t.stroke(),this.points.length>=2){const i=this.points[0],s=this.points[this.points.length-1];if(2===this.arrows||3===this.arrows){const i=this.calculateArrowPoints(this.points[this.points.length-2],s);if(i[2]=s,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<i.length;e++)0===e?t.moveTo(i[e].x,i[e].y):t.lineTo(i[e].x,i[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(s.x,s.y),t.lineTo(i[0].x,i[0].y),t.moveTo(s.x,s.y),t.lineTo(i[1].x,i[1].y),t.stroke()}if(1===this.arrows||3===this.arrows){const s=this.calculateArrowPoints(this.points[1],i);if(s[2]=i,this.fillArrow){t.fillStyle=e.toString(),t.beginPath();for(let e=0;e<s.length;e++)0===e?t.moveTo(s[e].x,s[e].y):t.lineTo(s[e].x,s[e].y);t.fill()}else t.strokeStyle=e.toString(),t.lineWidth=this.lineWidth,t.beginPath(),t.moveTo(i.x,i.y),t.lineTo(s[0].x,s[0].y),t.moveTo(i.x,i.y),t.lineTo(s[1].x,s[1].y),t.stroke()}}}calculateArrowPoints(t,e){const i=w(e,t),s=Math.PI/10,r=new y(this.arrowLength,i.theta-s),o=new y(this.arrowLength,i.theta+s),n=new y(Math.floor(this.arrowLength*Math.cos(s)),i.theta);return[g(r.toPoint(),e.x,e.y),g(o.toPoint(),e.x,e.y),g(n.toPoint(),e.x,e.y)]}get alpha(){return this.properties.getValue(ao)}get lineWidth(){return this.scale*this.properties.getValue(mo)}get fillLevel(){return this.properties.getValue(uo)}get horizontalFill(){return this.properties.getValue(go)}get points(){return v(this.properties.getValue(fo),this.scale)}get arrows(){return this.properties.getValue(lo)}get fillArrow(){return this.properties.getValue(po)}get arrowLength(){return this.properties.getValue(co)}}const wo="alpha",yo="bg_gradient_color",vo="fg_gradient_color",bo="fill_level",To="gradient",So="horizontal_fill",Vo="line_color",Co="line_width",_o="line_style";class Ao extends ke{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new M(wo,255)),this.properties.add(new B(yo)),this.properties.add(new B(vo)),this.properties.add(new E(To)),this.properties.add(new M(Co)),this.properties.add(new R(bo)),this.properties.add(new E(So)),this.properties.add(new B(Vo)),this.properties.add(new M(_o))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported rectangle line style ${this.lineStyle}`))}drawFill(t){const e=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const i=e.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(e.x,e.y,i,e.height)}else{const i=e.height*(this.fillLevel/100),s=e.y+e.height-i;t.ctx.beginPath(),t.ctx.rect(e.x,s,e.width,e.height)}t.ctx.clip();const i=this.alarmSensitiveForegroundColor;if(this.gradient){const s=this.horizontalFill?e.x:e.x+e.width,r=this.horizontalFill?e.y+e.height:e.y,o=t.createLinearGradient(e.x,e.y,s,r);o.addColorStop(0,this.foregroundGradientStartColor.toString()),o.addColorStop(1,i.toString()),t.fillRect(Object.assign(Object.assign({},e),{gradient:o}))}else t.fillRect(Object.assign(Object.assign({},e),{color:i}));t.ctx.restore()}get alpha(){return this.properties.getValue(wo)}get lineWidth(){return this.scale*this.properties.getValue(Co)}get fillLevel(){return this.properties.getValue(bo)}get horizontalFill(){return this.properties.getValue(So)}get lineColor(){return this.properties.getValue(Vo)}get lineStyle(){return this.properties.getValue(_o)}get gradient(){return this.properties.getValue(To)}get backgroundGradientStartColor(){return this.properties.getValue(yo)}get foregroundGradientStartColor(){return this.properties.getValue(vo)}}const Lo="alpha",Po="bg_gradient_color",ko="corner_width",Mo="corner_height",Ro="fg_gradient_color",Eo="fill_level",Bo="gradient",Wo="horizontal_fill",Io="line_color",Ho="line_width",Oo="line_style";class Do extends ke{constructor(t,e){super(t,e),this.fillRoundRectangleBackgroundBorder=!1,this.properties.add(new M(Lo,255)),this.properties.add(new B(Po)),this.properties.add(new B(Ro)),this.properties.add(new E(Bo)),this.properties.add(new M(Ho)),this.properties.add(new R(Eo)),this.properties.add(new E(Wo)),this.properties.add(new B(Io)),this.properties.add(new M(ko)),this.properties.add(new M(Mo)),this.properties.add(new M(Oo))}draw(t){t.ctx.globalAlpha=this.alpha/255,this.drawBackground(t),this.fillLevel&&this.drawFill(t),t.ctx.globalAlpha=1}drawBackground(t){if(!this.transparent){const e=this.alarmSensitiveBackgroundColor;if(this.gradient){const i=this.horizontalFill?this.x:this.x+this.width,s=this.horizontalFill?this.y+this.height:this.y,r=t.createLinearGradient(this.x,this.y,i,s);r.addColorStop(0,this.backgroundGradientStartColor.toString()),r.addColorStop(1,e.toString()),t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,gradient:r}))}else t.fillRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:e}))}this.lineWidth&&(0===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0})):1===this.lineStyle?t.strokeRect(Object.assign(Object.assign({},this.area),{rx:this.cornerWidth/2,ry:this.cornerHeight/2,color:this.lineColor,lineWidth:this.lineWidth,crispen:!0,dash:[6*this.scale,2*this.scale]})):console.warn(`Unsupported RoundedRectangle line style ${this.lineStyle}`))}drawFill(t){const e=this.cornerWidth/2,i=this.cornerHeight/2,s=p(this,this.lineWidth);if(t.ctx.save(),this.horizontalFill){const e=s.width*(this.fillLevel/100);t.ctx.beginPath(),t.ctx.rect(s.x,s.y,e,s.height)}else{const e=s.height*(this.fillLevel/100),i=s.y+s.height-e;t.ctx.beginPath(),t.ctx.rect(s.x,i,s.width,s.height)}t.ctx.clip();const r=this.alarmSensitiveForegroundColor;if(this.gradient){const o=this.horizontalFill?s.x:s.x+s.width,n=this.horizontalFill?s.y+s.height:s.y,h=t.createLinearGradient(s.x,s.y,o,n);h.addColorStop(0,this.foregroundGradientStartColor.toString()),h.addColorStop(1,r.toString()),t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,gradient:h}))}else t.fillRect(Object.assign(Object.assign({},s),{rx:e,ry:i,color:r}));t.ctx.restore()}get alpha(){return this.properties.getValue(Lo)}get lineWidth(){return this.scale*this.properties.getValue(Ho)}get fillLevel(){return this.properties.getValue(Eo)}get horizontalFill(){return this.properties.getValue(Wo)}get lineColor(){return this.properties.getValue(Io)}get lineStyle(){return this.properties.getValue(Oo)}get gradient(){return this.properties.getValue(Bo)}get cornerWidth(){return this.scale*this.properties.getValue(ko)}get cornerHeight(){return this.scale*this.properties.getValue(Mo)}get backgroundGradientStartColor(){return this.properties.getValue(Po)}get foregroundGradientStartColor(){return this.properties.getValue(Ro)}}const No="bitReverse",Fo="effect_3d",$o="horizontal",jo="led_border",Go="led_border_color",zo="led_packed",Uo="numBits",qo="off_color",Yo="on_color",Xo="startBit",Ko="square_led";class Zo extends ke{constructor(t,e){super(t,e),this.properties.add(new E(No)),this.properties.add(new E(Fo)),this.properties.add(new E($o)),this.properties.add(new M(Uo)),this.properties.add(new B(qo)),this.properties.add(new B(Yo)),this.properties.add(new M(Xo)),this.properties.add(new E(Ko)),this.properties.add(new M(jo,3)),this.properties.add(new B(Go,i.DARK_GRAY)),this.properties.add(new E(zo,!1))}getLedColor(t){var e,i;let s=!1;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value))for(let e=this.startBit;e<this.startBit+this.numBits;e++){let r=0;if(r=this.bitReverse?e-this.startBit:this.numBits-1-(e-this.startBit),r===t){s=((null===(i=this.pv)||void 0===i?void 0:i.value)>>e&1)>0;break}}return s?this.onColor:this.offColor}draw(t){if(this.numBits<1)return;let e=this.bounds;this.borderAlarmSensitive&&(e=p(e,2*this.scale)),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawHorizontal(t,e){let i,s;this.ledPacked?(i=Math.floor((e.width-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.width/this.numBits),s=i);let r=0;r=i>e.height||this.squareLed?e.height:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const n={x:e.x+o*s,y:e.y,width:i,height:r};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{const n=Math.min(i,r),h={x:e.x+o*s,y:e.y,width:n,height:n};this.effect3d?this.drawCircle3d(t,h,o):this.drawCircle2d(t,h,o)}}drawVertical(t,e){let i,s;this.ledPacked?(i=Math.floor((e.height-this.ledBorder)/this.numBits+this.ledBorder),s=i-this.ledBorder):(i=Math.floor(e.height/this.numBits),s=i);let r=0;r=i>e.width||this.squareLed?e.width:i;for(let o=0;o<this.numBits;o++)if(this.squareLed){const n={x:e.x,y:e.y+o*s,width:r,height:i};this.effect3d?this.drawSquare3d(t,n,o):this.drawSquare2d(t,n,o)}else{const n=Math.min(r,i),h={x:e.x,y:e.y+o*s,width:n,height:n};this.effect3d?this.drawCircle3d(t,h,o):this.drawCircle2d(t,h,o)}}drawCircle2d(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,n=e.height/2;this.ledBorder>0&&(o-=this.ledBorder/2,n-=this.ledBorder/2),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:this.getLedColor(i)}),t.strokeEllipse({cx:s,cy:r,rx:o,ry:n,color:this.ledBorderColor,lineWidth:this.ledBorder})}drawCircle3d(t,e,s){const r=e.x+e.width/2,o=e.y+e.height/2;let n=e.width/2,h=e.height/2;t.fillEllipse({cx:r,cy:o,rx:n,ry:h,color:i.WHITE});let a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);a.addColorStop(0,this.ledBorderColor.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:o,rx:n,ry:h,gradient:a});n=(e.width-2*this.ledBorder)/2,h=(e.height-2*this.ledBorder)/2,t.fillEllipse({cx:r,cy:o,rx:n,ry:h,color:this.getLedColor(s)}),a=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,this.ledBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:r,cy:o,rx:n,ry:h,gradient:a})}drawSquare2d(t,e,i){const s=d(e.x,e.y,e.width,e.height,this.ledBorder);t.fillRect(Object.assign(Object.assign({},s),{color:this.getLedColor(i)})),t.strokeRect(Object.assign(Object.assign({},s),{color:this.ledBorderColor,lineWidth:this.ledBorder}))}drawSquare3d(t,e,i){t.fillRect(Object.assign(Object.assign({},e),{color:this.ledBorderColor}));let s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new C(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(0,0,0,0.078)"),s.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:s,path:new C(e.x,e.y).lineTo(e.x+this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width,e.y)}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new C(e.x+e.width,e.y).lineTo(e.x+e.width-this.ledBorder,e.y+this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)}),s=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.078)"),s.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:s,path:new C(e.x,e.y+e.height).lineTo(e.x+this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width-this.ledBorder,e.y+e.height-this.ledBorder).lineTo(e.x+e.width,e.y+e.height)});const r=e.x+this.ledBorder,o=e.y+this.ledBorder,n=e.width-2*this.ledBorder,h=e.height-2*this.ledBorder,a=this.getLedColor(i);t.fillRect({x:r,y:o,width:n,height:h,color:a}),s=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),s.addColorStop(0,"rgba(255,255,255,0.784)"),s.addColorStop(1,a.withAlpha(0).toString()),t.fillRect({x:r,y:o,width:n,height:h,gradient:s})}get bitReverse(){return this.properties.getValue(No)}get horizontal(){return this.properties.getValue($o)}get numBits(){return this.properties.getValue(Uo)}get startBit(){return this.properties.getValue(Xo)}get ledPacked(){return this.properties.getValue(zo)}get ledBorder(){return this.scale*this.properties.getValue(jo)}get ledBorderColor(){return this.properties.getValue(Go)}get offColor(){return this.properties.getValue(qo)}get onColor(){return this.properties.getValue(Yo)}get effect3d(){return this.properties.getValue(Fo)}get squareLed(){return this.properties.getValue(Ko)}}class Jo{constructor(t){this.prefix="",this.suffix="",this.comma=0,this.minInt=1,this.minFrac=0,this.maxFrac=0;for(let e=0;e<t.length;e++)if("#"==t.charAt(e)||"0"==t.charAt(e)){this.prefix=t.substring(0,e),t=t.substring(e);break}this.suffix=t.replace(/[#]|[0]|[,]|[.]/g,"");const e=t.replace(/[^0#,.]/g,"");let i="",s="";const r=e.indexOf(".");-1!==r?(i=e.substring(0,r),s=e.substring(r+1)):i=e;const o=i.lastIndexOf(",");-1!==o&&(this.comma=i.length-1-o),i=i.replace(/[,]/g,""),s=s.replace(/[,]|[.]+/g,""),this.maxFrac=s.length;let n=i.replace(/[^0]/g,"");n.length>this.minInt&&(this.minInt=n.length),n=s.replace(/[^0]/g,""),this.minFrac=n.length}format(t){let e=this.formatBack(t).toLowerCase();if(isNaN(e)||0==e.length)return t;if(-1!=e.indexOf("e")){const t=Number(e);if(t===1/0||t===-1/0)return e;if(e=t+"",-1!==e.indexOf("e"))return e}let i=!1;"-"===e.charAt(0)?(i=!0,e=e.substring(1)):"+"===e.charAt(0)&&(e=e.substring(1));const s=e.indexOf(".");let r="",o="";-1!=s?(r=e.substring(0,s),o=e.substring(s+1)):r=e,o=o.replace(/[.]/,"");const n=this.suffix&&"%"===this.suffix.charAt(0);let h=this.minInt,a=this.minFrac,l=this.maxFrac;if(n&&(h-=2,a+=2,l+=2),o.length>l){let t=Number("0."+o);t=0==l?Math.round(t):t.toFixed(l),o=t.toString(10).substr(2);let e,i=t>=1?1:0,s=r.length-1;for(;i;){if(-1==s){r="1"+r;break}e=Number(r.charAt(s)),9===e?(e="0",i=1):(e=++e+"",i=0),r=r.substring(0,s)+e+r.substring(s+1,r.length),s--}}for(let t=o.length;t<a;t++)o+="0";for(;o.length>a&&"0"==o.charAt(o.length-1);)o=o.substring(0,o.length-1);for(let t=r.length;t<h;t++)r="0"+r;for(;r.length>h&&"0"==r.charAt(0);)r=r.substring(1);n&&(r+=o.substring(0,2),o=o.substring(2));let d,c=0;for(let t=r.length;t>0;t--)0!=c&&c%this.comma==0&&(r=r.substring(0,t)+","+r.substring(t),c=0),c++;return d=o.length>0?this.prefix+r+"."+o+this.suffix:this.prefix+r+this.suffix,i&&(d="-"+d),d}formatBack(t){if(!(t+=""))return"";if(!isNaN(t))return this.getNumericString(t);let e=t,i=!1;"-"===t.charAt(0)&&(e=e.substr(1),i=!0);const s=e.indexOf(this.prefix),r=""==this.suffix?e.length:e.indexOf(this.suffix,this.prefix.length+1);return 0==s&&r>0&&(e=e.substr(0,r),e=e.substr(this.prefix.length),e=e.replace(/,/g,""),i&&(e="-"+e),!isNaN(e))?this.getNumericString(e):t}getNumericString(t){const e=Number(t)+"";if(t.indexOf(".")>-1&&e.indexOf(".")<0){for(var i=t.indexOf(".")+1;i<t.length;i++)if("0"!==t.charAt(i))return t;return e}return t}}class Qo{constructor(t,e,s){this.rampWidth=t,this.startAngle=e,this.endAngle=s,this.lolo=10,this.loloColor=i.RED,this.showLoLo=!0,this.lo=25,this.loColor=i.ORANGE,this.showLo=!0,this.hi=75,this.hiColor=i.ORANGE,this.showHi=!0,this.hihi=90,this.hihiColor=i.RED,this.showHiHi=!0,this.minimum=0,this.maximum=100,this.gradient=!0,this.logScale=!1,this.effect3d=!0,this.labelsOutside=!0,this.range={min:this.minimum,max:this.maximum},this.lengthInDegrees=0,this.radius=0}draw(t,e,i){if(this.labelsOutside){const t=9;this.radius=e.width/2-t}else this.radius=e.width/2-1;this.range=this.getRenderedRange(),this.endAngle-this.startAngle>0?this.lengthInDegrees=360-(this.endAngle-this.startAngle):this.lengthInDegrees=this.startAngle-this.endAngle,this.drawRamp(t,i)}drawRamp(t,e){const s=e.x+e.width/2,r=e.y+e.height/2,o=e.width/2,n=e.height/2;let h,a=360-this.endAngle;if(h=this.endAngle-this.startAngle>0?this.startAngle-90:this.startAngle+90,this.showLoLo){let e=h,i=360-this.getValuePosition(this.lolo,!0);t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(e),endAngle:f(i),color:this.loloColor})}if(this.showLo){let i;i=this.showLoLo?this.lolo:this.minimum;const h=360-this.getValuePosition(i,!0),a=360-this.getValuePosition(this.lo,!0);if(this.effect3d&&this.gradient&&this.showLoLo){const l=f(this.getValuePosition(i,!0)-2),d=x(e.width/2,l,e),c=f(this.getValuePosition(this.lo,!0)+2),p=x(e.width/2,c,e),u=t.createLinearGradient(d.x,d.y,p.x,p.y);u.addColorStop(0,this.loloColor.toString()),u.addColorStop(1,this.loColor.toString()),t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h-1),endAngle:f(a+1),gradient:u})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h),endAngle:f(a),color:this.loColor})}let l=this.minimum;this.showLo?l=this.lo:this.showLoLo&&(l=this.lolo);let d=this.maximum;this.showHi?d=this.hi:this.showHiHi&&(d=this.hihi);const c=(l+d)/2;let p=360-this.getValuePosition(l,!0),u=360-this.getValuePosition(c,!0);if(this.effect3d&&this.gradient&&(this.showLoLo||this.showLo)){const h=f(this.getValuePosition(l,!0)-2),a=x(e.width/2,h,e),d=f(this.getValuePosition(c,!0)+2),g=x(e.width/2,d,e),m=t.createLinearGradient(a.x,a.y,g.x,g.y);m.addColorStop(0,(this.showLo?this.loColor:this.loloColor).toString()),m.addColorStop(1,i.GREEN.toString()),t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-1),endAngle:f(u+1),gradient:m})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p),endAngle:f(u),color:i.GREEN});if(p=360-this.getValuePosition(c,!0),u=360-this.getValuePosition(d,!0),this.effect3d&&this.gradient&&(this.showHi||this.showHiHi)){const h=f(this.getValuePosition(c,!0)-2),l=x(e.width/2,h,e),g=f(this.getValuePosition(d,!0)+2),m=x(e.width/2,g,e),w=t.createLinearGradient(l.x,l.y,m.x,m.y);w.addColorStop(0,i.GREEN.toString()),w.addColorStop(1,(this.showHi?this.hiColor:this.hihiColor).toString());const y=u!==a?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-1),endAngle:f(u+y),gradient:w})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p),endAngle:f(u),color:i.GREEN});if(this.showHi){let i;i=this.showHiHi?this.hihi:this.maximum;const h=360-this.getValuePosition(this.hi,!0),l=360-this.getValuePosition(i,!0);if(this.effect3d&&this.gradient&&this.showHiHi){const d=f(this.getValuePosition(this.hi,!0)-2),c=x(e.width/2,d,e),p=f(this.getValuePosition(i,!0)+2),u=x(e.width/2,p,e),g=t.createLinearGradient(c.x,c.y,u.x,u.y);g.addColorStop(0,this.hiColor.toString()),g.addColorStop(1,this.hihiColor.toString());const m=l!==a?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h-1),endAngle:f(l+m),gradient:g})}else t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(h),endAngle:f(l),color:this.hiColor})}if(this.showHiHi){p=360-this.getValuePosition(this.hihi,!0),u=a;const e=this.gradient?1:0;t.strokeEllipse({cx:s,cy:r,rx:o-this.rampWidth/2,ry:n-this.rampWidth/2,lineWidth:this.rampWidth,startAngle:f(p-e),endAngle:f(u),color:this.hihiColor})}}getRadius(){return this.radius}getValuePosition(t,e=!1){let i;return e&&(t=this.getValueInRange(t)),i=this.logScale?this.startAngle-(Math.log10(t)-Math.log10(this.range.min))/(Math.log10(this.range.max)-Math.log10(this.range.min))*this.lengthInDegrees:this.startAngle-(t-this.range.min)/(this.range.max-this.range.min)*this.lengthInDegrees,i<0&&(i+=360),i}getValueInRange(t){return this.range.min<=t&&t<=this.range.max?t:t>this.range.max?this.range.max:this.range.min}getRenderedRange(){const t={min:this.minimum,max:this.maximum};return this.logScale&&(this.minimum<=0&&(t.min=.1),t.max<=this.minimum&&(t.max=t.min+100)),t}}const tn=new i(100,100,100),en="color_hi",sn="color_hihi",rn="color_lo",on="color_lolo",nn="effect_3d",hn="font",an="value_label_format",ln="level_hi",dn="level_hihi",cn="level_lo",pn="level_lolo",un="limits_from_pv",gn="log_scale",mn="minimum",fn="maximum",xn="needle_color",wn="ramp_gradient",yn="show_ramp";class vn extends ke{constructor(t,e){super(t,e),this.properties.add(new B(en)),this.properties.add(new B(sn)),this.properties.add(new B(rn)),this.properties.add(new B(on)),this.properties.add(new E(nn)),this.properties.add(new W(hn)),this.properties.add(new R(ln)),this.properties.add(new R(dn)),this.properties.add(new R(cn)),this.properties.add(new R(pn)),this.properties.add(new E(gn)),this.properties.add(new E(un)),this.properties.add(new R(fn)),this.properties.add(new R(mn)),this.properties.add(new B(xn)),this.properties.add(new E(wn)),this.properties.add(new E(yn,!0)),this.properties.add(new P(an))}draw(t){var e,i;let s;s=this.limitsFromPv&&this.pv&&!this.pv.disconnected?{min:null!==(e=this.pv.lowerDisplayLimit)&&void 0!==e?e:this.minimum,lolo:this.pv.lowerAlarmLimit,lo:this.pv.lowerWarningLimit,hi:this.pv.upperWarningLimit,hihi:this.pv.upperAlarmLimit,max:null!==(i=this.pv.upperDisplayLimit)&&void 0!==i?i:this.maximum}:{min:this.minimum,lolo:this.levelLoLo,lo:this.levelLo,hi:this.levelHi,hihi:this.levelHiHi,max:this.maximum},this.logScale&&(s.min=Math.max(.1,s.min),s.max<=s.min&&(s.max=s.min+100));const r=Math.min(this.width,this.height),o=r;this.drawBackground(t,r,o),this.showRamp&&this.drawRamp(t,r,o,s),this.drawLabel(t,r,o),this.drawNeedle(t,r,o,s),this.drawNeedleCenter(t,r,o)}drawBackground(t,e,s){if(t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2,ry:s/2,color:i.GRAY}),this.effect3d){const r=t.createLinearGradient(this.x,this.y,this.x+this.width,this.y+this.height);r.addColorStop(0,tn.toString()),r.addColorStop(1,i.WHITE.toString()),t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2,ry:s/2,gradient:r})}const r=(this.effect3d?2:1)*this.scale;if(t.fillEllipse({cx:this.x+e/2,cy:this.y+s/2,rx:e/2-r,ry:s/2-r,color:this.backgroundColor}),this.effect3d){const r=e/2,o=.95,n=.5,h=.85,a=f(0),l=f(35);let d={x:Math.floor(this.x+e/2-r*h*Math.cos(a)),y:Math.floor(this.y+s/2-r*o),width:Math.floor(2*r*h*Math.cos(a)),height:Math.floor(r*o+r*n)},c=t.createLinearGradient(d.x,d.y,d.x,d.y+d.height);c.addColorStop(0,i.WHITE.withAlpha(90/255).toString()),c.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c}),d={x:Math.floor(this.x+e/2-r*h*Math.sin(l)),y:Math.floor(Math.ceil(this.y+s/2+r*n)),width:Math.floor(2*r*h*Math.sin(l)),height:Math.floor(Math.ceil(r*o-r*n))},c=t.createLinearGradient(d.x,d.y,d.x,d.y+d.height),c.addColorStop(0,i.WHITE.withAlpha(0).toString()),c.addColorStop(1,i.WHITE.withAlpha(40/255).toString()),t.fillEllipse({cx:d.x+d.width/2,cy:d.y+d.height/2,rx:d.width/2,ry:d.height/2,gradient:c})}}drawRamp(t,e,i,s){const r=p({x:this.x,y:this.y,width:e,height:i},e/4,i/4),o=Object.assign({},r);o.width=Math.min(r.width,r.height),o.height=r.width;const n=new Qo(10*this.scale,225,315);n.lolo=s.lolo,n.loloColor=this.colorLoLo,n.lo=s.lo,n.loColor=this.colorLo,n.hi=s.hi,n.hiColor=this.colorHi,n.hihi=s.hihi,n.hihiColor=this.colorHiHi,n.minimum=s.min,n.maximum=s.max,n.effect3d=this.effect3d,n.gradient=this.rampGradient,n.logScale=this.logScale,n.draw(t,r,o)}drawLabel(t,e,i){var s;const r=et.ARIAL_12_BOLD.scale(this.scale);if(void 0!==(null===(s=this.pv)||void 0===s?void 0:s.value)){const s=this.formatLabelValue(this.pv.value),o=t.measureText(s,r);t.fillText({x:this.x+e/2-o.width/2,y:this.y+7*i/8-o.height/2,color:this.foregroundColor,align:"left",baseline:"top",font:r,text:s})}}drawNeedle(t,e,i,s){var r;const o=this.x+e/2,n=this.y+i/2;let h;if(void 0!==(null===(r=this.pv)||void 0===r?void 0:r.value)){const t=this.getValueInRange(this.pv.value,s);h=360-this.getValuePosition(t,s),s.max>s.min?t>s.max?h+=10:t<s.min&&(h-=10):t>s.min?h-=10:t<s.max&&(h+=10)}else h=360-this.getValuePosition((s.min+s.max)/2,s);const a=f(h),{scale:l}=this,{needleDiameter:d,majorTickLength:p,gapBetweenNeedleScale:u}=this,g=c(o,n-d/2+3*l,o,n,a),m=c(o+e/2-p-u,n,o,n,a),x=c(o,n+d/2-3*l,o,n,a);t.fillPath({color:this.needleColor,path:new C(g.x,g.y).lineTo(m.x,m.y).lineTo(x.x,x.y).closePath()})}drawNeedleCenter(t,e,s){const{needleDiameter:r}=this,o=this.x+e/2,n=this.y+s/2,h=r/2,a=r/2;if(this.effect3d){const e=t.createLinearGradient(o-h,n-a,o+h,n+a);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,tn.toString()),t.fillEllipse({cx:o,cy:n,rx:h,ry:a,gradient:e})}else t.fillEllipse({cx:o,cy:n,rx:h,ry:a,color:i.GRAY})}getValueInRange(t,e){return e.min<=t&&t<=e.max?t:t>e.max?e.max:e.min}getValuePosition(t,e){let i;return i=this.logScale?225-(Math.log10(t)-Math.log10(e.min))/(Math.log10(e.max)-Math.log10(e.min))*270:225-(t-e.min)/(e.max-e.min)*270,i<0&&(i+=360),i}formatLabelValue(t){return this.valueLabelFormat?new Jo(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get needleDiameter(){return 16*this.scale}get majorTickLength(){return 8*this.scale}get minorTickLength(){return 5*this.scale}get gapBetweenNeedleScale(){return-1*this.scale}get colorLo(){return this.properties.getValue(rn)}get colorLoLo(){return this.properties.getValue(on)}get colorHi(){return this.properties.getValue(en)}get colorHiHi(){return this.properties.getValue(sn)}get effect3d(){return this.properties.getValue(nn)}get font(){return this.properties.getValue(hn).scale(this.scale)}get levelLo(){return this.properties.getValue(cn)}get levelLoLo(){return this.properties.getValue(pn)}get levelHi(){return this.properties.getValue(ln)}get levelHiHi(){return this.properties.getValue(dn)}get limitsFromPv(){return this.properties.getValue(un)}get logScale(){return this.properties.getValue(gn)}get minimum(){return this.properties.getValue(mn)}get maximum(){return this.properties.getValue(fn)}get needleColor(){return this.properties.getValue(xn)}get rampGradient(){return this.properties.getValue(wn)}get showRamp(){return this.properties.getValue(yn)}get valueLabelFormat(){return this.properties.getValue(an)}}const bn="data_type",Tn="off_image",Sn="off_label",Vn="font",Cn="on_image",_n="on_label",An="show_boolean_label";class Ln extends ke{constructor(t,e){super(t,e),this.onImageLoaded=!1,this.offImageLoaded=!1,this.properties.add(new M("bit")),this.properties.add(new M(bn)),this.properties.add(new P(Tn)),this.properties.add(new P(Sn)),this.properties.add(new P(Cn)),this.properties.add(new P(_n)),this.properties.add(new W(Vn)),this.properties.add(new E(An))}init(){this.onImageElement=new Image,this.onImageElement.onload=()=>{this.onImageLoaded=!0,this.requestRepaint()},this.offImageElement=new Image,this.offImageElement.onload=()=>{this.offImageLoaded=!0,this.requestRepaint()},this.onImage&&(this.onImageElement.src=this.resolvePath(this.onImage)),this.offImage&&(this.offImageElement.src=this.resolvePath(this.offImage))}get booleanValue(){var t,e,i;return this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0}get image(){return this.booleanValue?this.onImage:this.offImage}get label(){return this.booleanValue?this.onLabel:this.offLabel}draw(t){this.transparent||t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.booleanValue?this.onImageLoaded&&t.ctx.drawImage(this.onImageElement,this.x,this.y,this.width,this.height):this.offImageLoaded&&t.ctx.drawImage(this.offImageElement,this.x,this.y,this.width,this.height),this.showBooleanLabel&&t.fillText({x:this.x+this.width/2,y:this.y+this.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(bn)}get showBooleanLabel(){return this.properties.getValue(An)}get font(){return this.properties.getValue(Vn).scale(this.scale)}get offLabel(){return this.properties.getValue(Sn)}get offImage(){return this.properties.getValue(Tn)}get onLabel(){return this.properties.getValue(_n)}get onImage(){return this.properties.getValue(Cn)}}const Pn=["January","February","March","April","May","June","July","August","September","October","November","December"];class kn{constructor(t,e,i,s,r,o,n,h,a){this.scale=t,this.scaleFont=e,this.minimum=i,this.maximum=s,this.logScale=r,this.majorTickStepHint=o,this.foregroundColor=n,this.showMinorTicks=h,this.showScale=a,this.labels=[],this.labelValues=[],this.labelPositions=[],this.labelVisibilities=[],this.gridStepInPixel=0,this.horizontal=!1,this.x=0,this.y=0,this.scaleFormat="",this.timeFormat=0,this.length=0,this.margin=0}get scaleLength(){return this.length-2*this.margin}getX(){return this.x}getY(){return this.y}getGridPositions(){let t=[...this.labelPositions];return this.horizontal||(t=t.map((t=>this.length-t))),t.pop(),t.shift(),t}setDimensions(t,e,i,s){this.x=t,this.y=e,this.length=i,this.horizontal=s}getValuePosition(t){let{start:e,stop:i}=this.getMinMax(),s=0;const r=this.length-2*this.margin;if(this.logScale)s=t<=0?this.margin:(Math.log10(t)-Math.log10(e))/(Math.log10(i)-Math.log10(e))*r+this.margin;else{const o=Math.max(Math.abs(e),Math.abs(i));i/=o,e/=o;s=(t/o-e)/(i-e)*r+this.margin}return this.horizontal?s+this.x:this.length-s+this.y}getMinMax(){let t=this.minimum,e=this.maximum;return this.logScale&&(t<=0&&(t=.1),e<=t&&(e=t+100)),{start:t,stop:e}}getPositionValue(t){const e=this.getMinMax();let{start:i,stop:s}=e;const r=this.horizontal?t-this.x:this.length+this.y-t,o=this.length-2*this.margin;let n;if(this.logScale)n=Math.pow(10,(r-this.margin)*(Math.log10(s)-Math.log10(i))/o+Math.log10(i));else{const t=Math.max(Math.abs(i),Math.abs(s));s/=t,i/=t;const e=s-i;n=((r-this.margin)/o*e+i)*t}return n}calculateMargin(t,e){if(this.showScale){const i=t.measureText(this.format(this.minimum),this.scaleFont),s=t.measureText(this.format(this.maximum),this.scaleFont);return e?Math.ceil(Math.max(i.width,s.width)/2):Math.ceil(Math.max(i.height,s.height)/2)}return 0}measureHorizontalHeight(t){const e=t.measureText("dummy",this.scaleFont);return this.showScale?e.height+this.spaceBetweenMarkAndLabel+this.majorTickLength:0}drawHorizontal(t,e,i,s){const{scale:r}=this;this.length=s,this.horizontal=!0,this.margin=this.calculateMargin(t,this.horizontal);const o=s-2*this.margin;o>0&&this.updateLabels(t,o);let n=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.height>n&&(n=i.height)}const h=this.showScale?n+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(i-=h,this.x=e,this.y=i,this.logScale)for(let e=0;e<this.labelPositions.length;e++){const i=this.x+this.labelPositions[e],s=this.y;let o=0;if(o=this.labelVisibilities[e]?this.majorTickLength:this.minorTickLength,this.labelVisibilities[e]||this.showMinorTicks){const e=Math.round(i)-.5*r;t.strokePath({path:new C(e,s).lineTo(e,s+o),color:this.foregroundColor,lineWidth:1*r,opacity:100/255})}this.labelVisibilities[e]&&t.fillText({x:i,y:this.y+this.spaceBetweenMarkAndLabel+this.majorTickLength,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[e]})}else for(let s=0;s<this.labels.length;s++){const o=e+this.labelPositions[s];this.labelVisibilities[s]&&t.fillText({x:o,y:i+this.majorTickLength+this.spaceBetweenMarkAndLabel,align:"center",baseline:"top",font:this.scaleFont,color:this.foregroundColor,text:this.labels[s]});const n=Math.round(o)-.5*r;t.strokePath({path:new C(n,i).lineTo(n,i+this.majorTickLength),color:this.foregroundColor,lineWidth:1*r,opacity:100/255}),this.showMinorTicks&&this.drawMinorXTicks(t,s,e,i)}return h}drawVertical(t,e,i,s,r,o=!1){const{scale:n}=this;this.length=s,this.horizontal=!1,this.margin=this.calculateMargin(t,this.horizontal);const h=s-2*this.margin;h>0&&this.updateLabels(t,h);let a=0;for(let e=0;e<this.labels.length;e++){const i=t.measureText(this.labels[e],this.scaleFont);i.width>a&&(a=i.width)}const l=this.showScale?a+this.spaceBetweenMarkAndLabel+this.majorTickLength:0;if(r||(e-=l),this.x=e,this.y=i,this.logScale)for(let r=0;r<this.labelPositions.length;r++){let o;o=this.labelVisibilities[r]?this.majorTickLength:this.minorTickLength;const h=e+a+this.spaceBetweenMarkAndLabel-1*n+this.majorTickLength-o,l=Math.round(i+s-this.labelPositions[r])-.5*n;if((this.labelVisibilities[r]||this.showMinorTicks)&&t.strokePath({path:new C(h,l).lineTo(h+o,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.labelVisibilities[r]){const o=i+s-this.labelPositions[r];t.fillText({x:e,y:o,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else for(let r=0;r<this.labels.length;r++){const h=i+s-this.labelPositions[r],l=Math.round(h)-.5*n;if(o){if(t.strokePath({path:new C(e,l).lineTo(e+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.labelVisibilities[r]){const i=e+this.majorTickLength+this.spaceBetweenMarkAndLabel;t.fillText({x:i,y:h,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]})}}else{this.labelVisibilities[r]&&t.fillText({x:e,y:h,align:"left",baseline:"middle",font:this.scaleFont,color:this.foregroundColor,text:this.labels[r]});const o=e+a+this.spaceBetweenMarkAndLabel-1*n;t.strokePath({path:new C(o,l).lineTo(o+this.majorTickLength,l),color:this.foregroundColor,lineWidth:1*n,opacity:100/255}),this.showMinorTicks&&this.drawMinorYTicks(t,r,o,i+s)}}return l}drawMinorXTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,n;r/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(r/4)):(o=2,n=Math.floor(r/2));const{labelPositions:h,minorTickLength:a,scale:l}=this;if(e>0)if(1===e&&h[1]-h[0]<r){let e=h[1];for(;e-h[0]>n+3*l;){e-=n;const r=Math.round(i+e)-.5*l;t.strokePath({path:new C(r,s).lineTo(r,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else if(e===h.length-1&&h[e]-h[e-1]<r){let r=h[e-1];for(;h[e]-r>n+3*l;){r+=n;const e=Math.round(i+r)-.5*l;t.strokePath({path:new C(e,s).lineTo(e,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}else for(let r=0;r<o;r++){let n=i+h[e-1]+(h[e]-h[e-1])*r/o;n=Math.round(n)-.5*l,t.strokePath({path:new C(n,s).lineTo(n,s+a),color:this.foregroundColor,lineWidth:1*l,opacity:100/255})}}drawMinorYTicks(t,e,i,s){const{gridStepInPixel:r}=this;let o,n;r/5>=this.minorTickMarkStepHint?(o=5,n=Math.floor(r/5)):r/4>=this.minorTickMarkStepHint?(o=4,n=Math.floor(r/4)):(o=2,n=Math.floor(r/2));const{labelPositions:h,minorTickLength:a,majorTickLength:l,scale:d}=this;if(e>0)if(1===e&&h[1]-h[0]<r){let e=h[1];for(;e-h[0]>n+3*d;){e-=n;const r=Math.round(s-e)-.5*d;t.strokePath({path:new C(i+l-a,r).lineTo(i+l,r),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else if(e===h.length-1&&h[e]-h[e-1]<r){let r=h[e-1];for(;h[e]-r>n+3*d;){r+=n;const e=Math.round(s-r)-.5*d;t.strokePath({path:new C(i+l-a,e).lineTo(i+l,e),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}else for(let r=0;r<o;r++){let n=s-h[e-1]-(h[e]-h[e-1])*r/o;n=Math.round(n)-.5*d,t.strokePath({path:new C(i+l-a,n).lineTo(i+l,n),color:this.foregroundColor,lineWidth:1*d,opacity:100/255})}}updateLabels(t,e){if(this.labels=[],this.labelValues=[],this.labelPositions=[],this.showScale)if(this.logScale)this.updateLabelsForLogScale(this.minimum,this.maximum,e);else{const t=this.getGridStep(e,this.minimum,this.maximum),i=Math.max(Math.abs(this.minimum),Math.abs(this.maximum)),s=this.maximum/i-this.minimum/i;this.gridStepInPixel=Math.floor(e*(t/i)/s),this.updateLabelsForLinearScale(this.minimum,this.maximum,e,t)}this.updateVisibility(t)}getGridStep(t,e,i){t<=0&&(t=1);let s=!1;if(e>=i)if(i===e)i++;else{s=!0;const t=e;e=i,i=t}const r=Math.abs(i-e);let o=this.majorTickStepHint;o>t&&(o=t);let n,h=r/t*o,a=0;if(h<1){if(0!=h)for(;h<1;)h*=10,a--}else for(;h>=10;)h/=10,a++;return n=h>7.5?10*Math.pow(10,a):h>3.5?5*Math.pow(10,a):h>1.5?2*Math.pow(10,a):Math.pow(10,a),s&&(n=-n),n}updateLabelsForLogScale(t,e,i){t<=0&&(t=.1),e<=t&&(e=t+100);const s=e<t,r=Math.log10(t),o=Math.ceil(r),n=Math.ceil(Math.log10(e));let h,a=Math.pow(10,o-1);h=t%a<=0||s?t-t%a:t-t%a+a,(s&&t>h||!s&&t<h)&&this.addMinMaxTickInfo(t,i,!0);for(let t=o;s?t>=n:t<=n;t+=s?-1:1)if(Math.abs(n-o)>20){const s=Math.pow(10,t);if(s>e)break;this.addTickInfo(s,e,r,i)}else{for(let o=h;(s?o>=Math.pow(10,t-1):o<=Math.pow(10,t))&&!(s?o<e:o>e);o=s?o-a:o+a)this.addTickInfo(o,e,r,i);a=s?a/Math.pow(10,1):a*Math.pow(10,1),h=s?Math.pow(10,t-1):a+Math.pow(10,t)}(s?e<this.labelValues[this.labelValues.length-1]:e>this.labelValues[this.labelValues.length-1])&&this.addMinMaxTickInfo(e,i,!1)}addMinMaxTickInfo(t,e,i){i?(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin)):(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin+e))}addTickInfo(t,e,i,s){this.labels.push(this.format(t));const r=Math.floor((Math.log10(t)-i)/(Math.log10(e)-i)*s)+this.margin;this.labelPositions.push(r),this.labelValues.push(t)}updateLabelsForLinearScale(t,e,i,s){let r;r=t%s<=0?t-t%s:t-t%s+s,t>r==e<t&&(this.labelValues.push(t),this.labels.push(this.format(t)),this.labelPositions.push(this.margin));let o=1;const n=Math.max(Math.abs(t),Math.abs(e));s/=n,r/=n;const h=(e/=n)-(t/=n);for(let a=r;e>=t?a<e:a>e;a=r+o++*s){const e=a*n;this.labels.push(this.format(e)),this.labelValues.push(e);const s=Math.floor((a-t)/h*i)+this.margin;this.labelPositions.push(s)}e*=n,this.labelValues.push(e),this.labels.push(this.format(e)),this.labelPositions.push(this.margin+i)}updateVisibility(t){if(this.labelVisibilities=[],!this.labelPositions.length)return;for(let t=0;t<this.labelPositions.length;t++)this.labelVisibilities.push(!0);let e=0,i=null;for(let s=0;s<this.labelPositions.length;s++){let r=!0;const o=this.labels[s],n=this.labelPositions[s];0!==s&&(r=this.hasSpaceToDraw(t,e,n,i||"",o));const h=o===i&&0!==s&&s!==this.labelPositions.length-1;let a=!0;if(this.logScale){const t=Number(this.labels[s]);a=this.isMajorTick(t)||0===s||s===this.labelPositions.length-1}r&&!h&&a?(e=n,i=o):this.labelVisibilities[s]=!1}}hasSpaceToDraw(t,e,i,s,r){const o=t.measureText(r,this.scaleFont),n=t.measureText(s,this.scaleFont);let h=i-e,a=Math.floor(this.horizontal?o.width/2+n.width/2:o.height),l=!0,d=!0;if(i!=this.labelPositions[this.labelPositions.length-1]){l=h>a+this.tickLabelGap;const e=t.measureText(this.labels[this.labels.length-1],this.scaleFont);h=this.labelPositions[this.labelPositions.length-1]-i,a=Math.floor(this.horizontal?o.width/2+e.width/2:o.height),d=h>a+this.tickLabelGap}return l&&d}isMajorTick(t){if(!this.logScale)return!0;const e=Math.log10(t);return e===Math.round(e)}format(t){if(0===this.timeFormat)return this.scaleFormat?new Jo(this.scaleFormat).format(t):String(Number(t.toFixed(2)));const e=new Date(t);switch(this.timeFormat){case 1:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 2:return this.formatDate(e,{year:!0,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 3:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1});case 4:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!0});case 5:return this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1});case 6:return this.formatDate(e,{year:!0,month:!0,day:!0});case 7:return`${Pn[e.getUTCMonth()]} ${e.getUTCDate()}`;case 8:const t=Math.abs(this.maximum-this.minimum);return t<=5e3?this.formatTime(e,{hours:!1,minutes:!1,seconds:!0,milliseconds:!0}):t<=18e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!0,milliseconds:!1}):t<=864e5?this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=6048e5?this.formatDate(e,{year:!1,month:!0,day:!0})+"\n"+this.formatTime(e,{hours:!0,minutes:!0,seconds:!1,milliseconds:!1}):t<=2592e6?this.formatDate(e,{year:!1,month:!0,day:!0}):this.formatDate(e,{year:!0,month:!0,day:!0})}return""}formatDate(t,e){let i="";if(e.year&&(i+=t.getUTCFullYear()),e.month){e.year&&(i+="-");const s=t.getUTCMonth();i+=(s<10?"0":"")+s}if(e.day){e.month&&(i+="-");const s=t.getUTCDate();i+=(s<10?"0":"")+s}return i}formatTime(t,e){let i="";if(e.hours){const e=t.getUTCHours();i+=(e<10?"0":"")+e}if(e.minutes){e.hours&&(i+=":");const s=t.getUTCMinutes();i+=(s<10?"0":"")+s}if(e.seconds){e.minutes&&(i+=":");const s=t.getUTCSeconds();i+=(s<10?"0":"")+s}if(e.milliseconds){e.seconds&&(i+=".");const s=t.getUTCMilliseconds();i+=(s<10?"00":s<100?"0":"")+s}return i}get spaceBetweenMarkAndLabel(){return 2*this.scale}get majorTickLength(){return 6*this.scale}get minorTickLength(){return 3*this.scale}get minorTickMarkStepHint(){return 4*this.scale}get tickLabelGap(){return this.horizontal?10*this.scale:2*this.scale}}const Mn="color_map",Rn="crop_bottom",En="crop_left",Bn="crop_right",Wn="crop_top",In="data_height",Hn="data_width",On="font",Dn="graph_area_height",Nn="graph_area_width",Fn="maximum",$n="minimum",jn="show_ramp",Gn="x_axis_axis_color",zn="x_axis_axis_title",Un="x_axis_major_tick_step_hint",qn="x_axis_maximum",Yn="x_axis_minimum",Xn="x_axis_scale_font",Kn="x_axis_show_minor_ticks",Zn="x_axis_title_font",Jn="x_axis_visible",Qn="y_axis_axis_color",th="y_axis_axis_title",eh="y_axis_major_tick_step_hint",ih="y_axis_maximum",sh="y_axis_minimum",rh="y_axis_scale_font",oh="y_axis_show_minor_ticks",nh="y_axis_title_font",hh="y_axis_visible";class ah extends ke{constructor(t,e){super(t,e),this.properties.add(new I(Mn)),this.properties.add(new M(Rn)),this.properties.add(new M(En)),this.properties.add(new M(Bn)),this.properties.add(new M(Wn)),this.properties.add(new M(In)),this.properties.add(new M(Hn)),this.properties.add(new M(Dn)),this.properties.add(new M(Nn)),this.properties.add(new W(On)),this.properties.add(new R(Fn)),this.properties.add(new R($n)),this.properties.add(new E(jn)),this.properties.add(new B(Gn)),this.properties.add(new P(zn)),this.properties.add(new M(Un)),this.properties.add(new R(qn)),this.properties.add(new R(Yn)),this.properties.add(new W(Xn)),this.properties.add(new E(Kn)),this.properties.add(new W(Zn)),this.properties.add(new E(Jn)),this.properties.add(new B(Qn)),this.properties.add(new P(th)),this.properties.add(new M(eh)),this.properties.add(new R(ih)),this.properties.add(new R(sh)),this.properties.add(new W(rh)),this.properties.add(new E(oh)),this.properties.add(new W(nh)),this.properties.add(new E(hh))}draw(t){const{scale:e}=this;let i=this.area;this.borderAlarmSensitive&&(i=p(i,2*e));const s=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},i),{color:s}));const{graphAreaWidth:r,graphAreaHeight:o}=this;this.xAxisVisible&&t.measureText(this.xAxisAxisTitle,this.xAxisTitleFont).height;let n=0;this.yAxisVisible&&(n=t.measureText(this.yAxisAxisTitle,this.yAxisTitleFont).height);const h=new kn(e,this.xAxisScaleFont,this.xAxisMinimum,this.xAxisMaximum,!1,this.xAxisMajorTickStepHint,this.xAxisAxisColor,this.xAxisShowMinorTicks,this.xAxisVisible),a=h.calculateMargin(t,!0),l=new kn(e,this.yAxisScaleFont,this.yAxisMinimum,this.yAxisMaximum,!1,this.yAxisMajorTickStepHint,this.yAxisAxisColor,this.yAxisShowMinorTicks,this.yAxisVisible),d=l.calculateMargin(t,!1),c=h.measureHorizontalHeight(t),u=o+2*d,g=l.drawVertical(t,i.x+n,i.y,u,!0),m=r+2*a,f=i.x+n+g-a,x=i.y+u+c-d;h.drawHorizontal(t,f,x,m);const w=1*e,y=Math.round(i.x+n+g)-w/2,v=Math.round(i.y+d)-w/2;t.strokePath({path:new C(y,v).lineTo(y,v+o),color:this.yAxisAxisColor,opacity:100/255,lineWidth:w});const b=y,T=v+o+w;t.strokePath({path:new C(b,T).lineTo(b+r,T),color:this.xAxisAxisColor,opacity:100/255,lineWidth:w});const{dataWidth:S,dataHeight:V,colorMap:_}=this,{minimum:A,maximum:L}=this,[P,k]=_.getMinMax();if(this.value&&this.value.length){const e=document.createElement("canvas"),{cropLeft:s,cropRight:h,cropTop:a,cropBottom:d}=this;e.width=S-s-h,e.height=V-a-d;const c=e.getContext("2d");for(let t=s;t<S-h;t++)for(let e=a;e<V-d;e++){let i=this.value[e*S+t];if(_.autoscale){i=P+(i-A)/(L-A)*(k-P)}const[r,o,n]=_.lookup(i);c.fillStyle=`rgb(${r},${o},${n})`,c.fillRect(t-s,e-a,1,1)}const p=Math.round(i.x+n+g),u=Math.round(i.y+l.margin);t.ctx.drawImage(e,p,u,r,o)}if(this.showRamp){const s=new kn(e,this.font,A,L,!1,50*e,this.alarmSensitiveForegroundColor,!1,!0),h=i.y+l.margin,a=o,d=s.drawVertical(t,i.x+i.width,h,a,!1,!0),c=i.x+n+g+r+this.gap,p=i.width-n-g-r-d-this.gap,u=a-2*s.margin,m=document.createElement("canvas");m.width=p,m.height=u;const f=m.getContext("2d");for(let t=0;t<u;t++){let e=L-t/u*(L-A);if(_.autoscale){e=P+(e-A)/(L-A)*(k-P)}const[i,s,r]=_.lookup(e);f.fillStyle=`rgb(${i},${s},${r})`,f.fillRect(0,t,p,1)}t.ctx.drawImage(m,c,h+s.margin)}if(this.xAxisVisible){let e=i.x+g+r/2;this.yAxisVisible&&(e+=n),t.fillText({x:e,y:i.y+i.height,align:"center",baseline:"bottom",font:this.xAxisTitleFont,color:this.xAxisAxisColor,text:this.xAxisAxisTitle})}this.yAxisVisible&&(t.ctx.save(),t.ctx.translate(i.x+n/2,i.y+u/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:this.yAxisTitleFont,color:this.yAxisAxisColor,text:this.yAxisAxisTitle}),t.ctx.restore())}get gap(){return 3*this.scale}get colorMap(){return this.properties.getValue(Mn)}get cropBottom(){return this.properties.getValue(Rn)}get cropLeft(){return this.properties.getValue(En)}get cropRight(){return this.properties.getValue(Bn)}get cropTop(){return this.properties.getValue(Wn)}get dataHeight(){return this.properties.getValue(In)}get dataWidth(){return this.properties.getValue(Hn)}get font(){return this.properties.getValue(On).scale(this.scale)}get graphAreaHeight(){return this.scale*this.properties.getValue(Dn)}get graphAreaWidth(){return this.scale*this.properties.getValue(Nn)}get maximum(){return this.properties.getValue(Fn)}get minimum(){return this.properties.getValue($n)}get showRamp(){return this.properties.getValue(jn)}get xAxisAxisColor(){return this.properties.getValue(Gn)}get xAxisAxisTitle(){return this.properties.getValue(zn)}get xAxisMajorTickStepHint(){return this.scale*this.properties.getValue(Un)}get xAxisMaximum(){return this.properties.getValue(qn)}get xAxisMinimum(){return this.properties.getValue(Yn)}get xAxisScaleFont(){return this.properties.getValue(Xn).scale(this.scale)}get xAxisShowMinorTicks(){return this.properties.getValue(Kn)}get xAxisTitleFont(){return this.properties.getValue(Zn).scale(this.scale)}get xAxisVisible(){return this.properties.getValue(Jn)}get yAxisAxisColor(){return this.properties.getValue(Qn)}get yAxisAxisTitle(){return this.properties.getValue(th)}get yAxisMajorTickStepHint(){return this.scale*this.properties.getValue(eh)}get yAxisMaximum(){return this.properties.getValue(ih)}get yAxisMinimum(){return this.properties.getValue(sh)}get yAxisScaleFont(){return this.properties.getValue(rh).scale(this.scale)}get yAxisShowMinorTicks(){return this.properties.getValue(oh)}get yAxisTitleFont(){return this.properties.getValue(nh).scale(this.scale)}get yAxisVisible(){return this.properties.getValue(hh)}}const lh="data_type",dh="effect_3d",ch="state_count",ph="square_led",uh="off_color",gh="off_label",mh="font",fh="on_color",xh="on_label",wh="bulb_border",yh="bulb_border_color",vh="state_color_fallback",bh="state_label_fallback",Th="show_boolean_label";class Sh extends ke{constructor(t,e){super(t,e),this.states=[],this.properties.add(new M("bit")),this.properties.add(new M(lh)),this.properties.add(new E(dh)),this.properties.add(new E(ph)),this.properties.add(new M(ch,2)),this.properties.add(new B(uh)),this.properties.add(new P(gh)),this.properties.add(new B(fh)),this.properties.add(new P(xh)),this.properties.add(new W(mh)),this.properties.add(new E(Th)),this.properties.add(new B(vh)),this.properties.add(new P(bh)),this.properties.add(new M(wh,3)),this.properties.add(new B(yh,i.DARK_GRAY))}parseNode(t){if(super.parseNode(t),this.stateCount>2)for(let e=0;e<this.stateCount;e++){const i=new B(`state_color_${e}`);i.value=t.getColor(`state_color_${e}`),this.properties.add(i);const s=new P(`state_label_${e}`);s.value=t.getString(`state_label_${e}`),this.properties.add(s);const r=new R(`state_value_${e}`);r.value=t.getFloat(`state_value_${e}`),this.properties.add(r),this.states.push({label:this.properties.getValue(s.name),color:this.properties.getValue(i.name),value:this.properties.getValue(r.name)})}}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},cursor:"pointer",tooltip:()=>this.tooltip}}get booleanValue(){var t,e,i;return 0===this.dataType?this.bit<0?Boolean(null===(t=this.pv)||void 0===t?void 0:t.toNumber()):void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)&&((null===(i=this.pv)||void 0===i?void 0:i.value)>>this.bit&1)>0:(this.dataType,!1)}get bulbColor(){var t;if(this.stateCount<=2)return this.booleanValue?this.onColor:this.offColor;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.color;return this.stateColorFallback}get label(){var t;if(2===this.stateCount)return this.booleanValue?this.onLabel:this.offLabel;for(const e of this.states)if(e.value===(null===(t=this.pv)||void 0===t?void 0:t.value))return e.label;return this.stateLabelFallback}draw(t){const e=p(this.bounds,3*this.scale);this.squareLed?this.effect3d?this.drawSquare3d(t,e):this.drawSquare2d(t,e):this.effect3d?this.drawCircle3d(t,e):this.drawCircle2d(t,e),this.showBooleanLabel&&t.fillText({x:e.x+e.width/2,y:e.y+e.height/2,font:this.font,baseline:"middle",align:"center",color:this.foregroundColor,text:this.label})}drawCircle2d(t,e){const i=e.x+e.width/2,s=e.y+e.height/2;let r=e.width/2,o=e.height/2;if(this.bulbBorder>0&&(r-=this.bulbBorder/2,o-=this.bulbBorder/2),t.fillEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbColor}),t.strokeEllipse({cx:i,cy:s,rx:r,ry:o,color:this.bulbBorderColor,lineWidth:this.bulbBorder}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(i,s,r,o,0,0,2*Math.PI)}}drawCircle3d(t,e){const s=e.x+e.width/2,r=e.y+e.height/2;let o=e.width/2,n=e.height/2;t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:i.WHITE});let h=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height);h.addColorStop(0,this.bulbBorderColor.toString()),h.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,gradient:h});if(o=(e.width-2*this.bulbBorder)/2,n=(e.height-2*this.bulbBorder)/2,t.fillEllipse({cx:s,cy:r,rx:o,ry:n,color:this.bulbColor}),h=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),h.addColorStop(0,i.WHITE.toString()),h.addColorStop(1,this.bulbBorderColor.withAlpha(0).toString()),t.fillEllipse({cx:s,cy:r,rx:o,ry:n,gradient:h}),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addEllipse(s,r,o,n,0,0,2*Math.PI)}}drawSquare2d(t,e){const i=d(e.x,e.y,e.width,e.height,this.bulbBorder);if(t.fillRect(Object.assign(Object.assign({},i),{color:this.bulbColor})),t.strokeRect(Object.assign(Object.assign({},i),{color:this.bulbBorderColor,lineWidth:this.bulbBorder})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}}drawSquare3d(t,e){if(t.fillRect(Object.assign(Object.assign({},e),{color:this.bulbBorderColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(e.x,e.y,e.width,e.height)}let i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y);i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new C(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(0,0,0,0.078)"),i.addColorStop(1,"rgba(0,0,0,0.39)"),t.fillPath({gradient:i,path:new C(e.x,e.y).lineTo(e.x+this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width,e.y)}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new C(e.x+e.width,e.y).lineTo(e.x+e.width-this.bulbBorder,e.y+this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)}),i=t.createLinearGradient(e.x,e.y,e.x,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.078)"),i.addColorStop(1,"rgba(255,255,255,0.39)"),t.fillPath({gradient:i,path:new C(e.x,e.y+e.height).lineTo(e.x+this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width-this.bulbBorder,e.y+e.height-this.bulbBorder).lineTo(e.x+e.width,e.y+e.height)});const s=e.x+this.bulbBorder,r=e.y+this.bulbBorder,o=e.width-2*this.bulbBorder,n=e.height-2*this.bulbBorder;t.fillRect({x:s,y:r,width:o,height:n,color:this.bulbColor}),i=t.createLinearGradient(e.x,e.y,e.x+e.width,e.y+e.height),i.addColorStop(0,"rgba(255,255,255,0.784)"),i.addColorStop(1,this.bulbColor.withAlpha(0).toString()),t.fillRect({x:s,y:r,width:o,height:n,gradient:i})}get bit(){return this.properties.getValue("bit")}get dataType(){return this.properties.getValue(lh)}get squareLed(){return this.properties.getValue(ph)}get showBooleanLabel(){return this.properties.getValue(Th)}get font(){return this.properties.getValue(mh).scale(this.scale)}get effect3d(){return this.properties.getValue(dh)}get stateCount(){return this.properties.getValue(ch)}get bulbBorder(){return this.scale*this.properties.getValue(wh)}get bulbBorderColor(){return this.properties.getValue(yh)}get offLabel(){return this.properties.getValue(gh)}get offColor(){return this.properties.getValue(uh)}get onLabel(){return this.properties.getValue(xh)}get onColor(){return this.properties.getValue(fh)}get stateLabelFallback(){return this.properties.getValue(bh)}get stateColorFallback(){return this.properties.getValue(vh)}}const Vh=f(45),Ch=(1-Math.sin(Vh)/2)/(2*Math.cos(Vh)),_h="color_hi",Ah="color_hihi",Lh="color_lo",Ph="color_lolo",kh="font",Mh="level_hi",Rh="level_hihi",Eh="level_lo",Bh="level_lolo",Wh="log_scale",Ih="minimum",Hh="maximum",Oh="needle_color",Dh="ramp_gradient",Nh="scale_font",Fh="show_hi",$h="show_hihi",jh="show_lo",Gh="show_lolo",zh="show_ramp",Uh="value_label_format";class qh extends ke{constructor(t,e){super(t,e),this.properties.add(new B(_h)),this.properties.add(new B(Ah)),this.properties.add(new B(Lh)),this.properties.add(new B(Ph)),this.properties.add(new W(kh)),this.properties.add(new M(Mh)),this.properties.add(new M(Rh)),this.properties.add(new M(Eh)),this.properties.add(new M(Bh)),this.properties.add(new E(Wh)),this.properties.add(new M(Hh)),this.properties.add(new M(Ih)),this.properties.add(new B(Oh)),this.properties.add(new E(Dh)),this.properties.add(new W(Nh)),this.properties.add(new E(Fh)),this.properties.add(new E($h)),this.properties.add(new E(jh)),this.properties.add(new E(Gh)),this.properties.add(new E(zh,!0)),this.properties.add(new P(Uh))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){if(t.fillRect({x:this.x,y:this.y,width:this.width,height:this.height,color:this.backgroundColor}),this.showRamp&&this.drawRamp(t),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}}drawRamp(t){const e=String(this.minimum),i=t.measureText(e,this.scaleFont),s=String(this.maximum),r=t.measureText(s,this.scaleFont),o=Math.max(i.width,r.width)/2;let n=this.height,h=this.width;n>Ch*(h-2*o)&&(n=Math.floor(Ch*(h-2*o)));const a=n/(1-Math.sin(Vh)/2),l={x:Math.floor(this.x-a*(1-Math.cos(Vh))+o),y:this.y,width:Math.floor(2*a),height:Math.floor(2*a)},{rampWidth:d}=this,c=p(l,l.width/4-d,l.height/4-d);c.width=Math.min(c.width,c.height),c.height=c.width;const u=new Qo(d,135,45);u.lolo=this.levelLoLo,u.loloColor=this.colorLoLo,u.showLoLo=!0,u.lo=this.levelLo,u.loColor=this.colorLo,u.showLo=!0,u.hi=this.levelHi,u.hiColor=this.colorHi,u.showHi=!0,u.hihi=this.levelHiHi,u.hihiColor=this.colorHiHi,u.showHiHi=!0,u.minimum=this.minimum,u.maximum=this.maximum,u.gradient=this.rampGradient,u.logScale=this.logScale,u.draw(t,l,c),this.drawNeedle(t,l,u);const g=et.ARIAL_12_BOLD.scale(this.scale);if(this.pv&&void 0!==this.pv.value){const e=this.format(this.pv.value),i=t.measureText(e,g);t.fillText({x:l.x+l.width/2-i.width/2,y:l.y+l.height/2-l.height/4-(u.getRadius()-l.height/4)/2-i.height/2,align:"left",baseline:"top",font:g,text:e,color:this.foregroundColor})}}drawNeedle(t,e,i){const s=e.x+e.width/2,r=e.y+e.height/2;let o;if(this.pv&&void 0!==this.pv.value){const t=i.getValueInRange(this.pv.value);o=360-i.getValuePosition(t),this.maximum>this.minimum?t>this.maximum?o+=8:t<this.minimum&&(o-=8):t>this.minimum?o-=8:t<this.maximum&&(o+=8)}else o=360-i.getValuePosition(this.minimum+this.maximum/2);const n=f(o),{needleWidth:h,gapBetweenNeedleScale:a,scale:l}=this,d=c(s+e.width/4,r-h/2+3*l,s,r,n),p=c(s+i.getRadius()-a,r,s,r,n),u=c(s+e.width/4,r+h/2-3*l,s,r,n);t.fillPath({color:this.needleColor,path:new C(d.x,d.y).lineTo(p.x,p.y).lineTo(u.x,u.y).closePath()})}get needleWidth(){return 16*this.scale}get gapBetweenNeedleScale(){return-5*this.scale}get rampWidth(){return 12*this.scale}format(t){return this.valueLabelFormat?new Jo(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Lh)}get colorLoLo(){return this.properties.getValue(Ph)}get colorHi(){return this.properties.getValue(_h)}get colorHiHi(){return this.properties.getValue(Ah)}get font(){return this.properties.getValue(kh).scale(this.scale)}get levelLo(){return this.properties.getValue(Eh)}get levelLoLo(){return this.properties.getValue(Bh)}get levelHi(){return this.properties.getValue(Mh)}get levelHiHi(){return this.properties.getValue(Rh)}get logScale(){return this.properties.getValue(Wh)}get minimum(){return this.properties.getValue(Ih)}get maximum(){return this.properties.getValue(Hh)}get needleColor(){return this.properties.getValue(Oh)}get rampGradient(){return this.properties.getValue(Dh)}get scaleFont(){return this.properties.getValue(Nh).scale(this.scale)}get showLo(){return this.properties.getValue(jh)}get showLoLo(){return this.properties.getValue(Gh)}get showHi(){return this.properties.getValue(Fh)}get showHiHi(){return this.properties.getValue($h)}get showRamp(){return this.properties.getValue(zh)}get valueLabelFormat(){return this.properties.getValue(Uh)}}const Yh="color_hi",Xh="color_hihi",Kh="color_lo",Zh="color_lolo",Jh="color_fillbackground",Qh="effect_3d",ta="fill_color",ea="fillcolor_alarm_sensitive",ia="font",sa="horizontal",ra="indicator_mode",oa="level_hi",na="level_hihi",ha="level_lo",aa="level_lolo",la="limits_from_pv",da="log_scale",ca="maximum",pa="major_tick_step_hint",ua="minimum",ga="origin",ma="origin_ignored",fa="scale_font",xa="scale_format",wa="show_hi",ya="show_hihi",va="show_label",ba="show_lo",Ta="show_lolo",Sa="show_markers",Va="show_minor_ticks",Ca="show_scale",_a="transparent_background",Aa="value_label_format";class La extends ke{constructor(t,e){super(t,e),this.properties.add(new B(Yh)),this.properties.add(new B(Xh)),this.properties.add(new B(Kh)),this.properties.add(new B(Zh)),this.properties.add(new B(Jh)),this.properties.add(new E(Qh)),this.properties.add(new B(ta)),this.properties.add(new E(ea,!1)),this.properties.add(new W(ia)),this.properties.add(new E(sa)),this.properties.add(new E(ra)),this.properties.add(new R(oa)),this.properties.add(new R(na)),this.properties.add(new R(ha)),this.properties.add(new R(aa)),this.properties.add(new E(la)),this.properties.add(new E(da)),this.properties.add(new R(ca)),this.properties.add(new R(pa)),this.properties.add(new R(ua)),this.properties.add(new R(ga,0)),this.properties.add(new E(ma,!0)),this.properties.add(new W(fa)),this.properties.add(new P(xa)),this.properties.add(new E(wa)),this.properties.add(new E(ya)),this.properties.add(new E(va)),this.properties.add(new E(ba)),this.properties.add(new E(Ta)),this.properties.add(new E(Sa)),this.properties.add(new E(Va)),this.properties.add(new E(Ca)),this.properties.add(new E(_a)),this.properties.add(new P(Aa))}draw(t){let e=this.area;this.borderAlarmSensitive&&(e=p(this.area,2*this.scale));const i=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},e),{color:i})),this.horizontal?this.drawHorizontal(t,e):this.drawVertical(t,e)}drawVertical(t,e){const i=this.alarmSensitiveForegroundColor,s=new kn(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawVertical(t,e.x,e.y,e.height,!0);let o=0;this.showMarkers&&(o=this.drawVerticalMarkers(t,s,e)),this.drawVerticalBar(t,s,{x:e.x+r,y:e.y+s.margin,width:e.width-r-o,height:e.height-2*s.margin})}drawVerticalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=et.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.width)}const l=i.x+i.width;if(this.showLoLo&&void 0!==s){const i=l-a-this.markerGap,r=Math.round(e.getValuePosition(s));t.strokePath({path:new C(i,r).lineTo(i-this.markerTickLength,r),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:r,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(r));t.strokePath({path:new C(i,s).lineTo(i-this.markerTickLength,s),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(o));t.strokePath({path:new C(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const i=l-a-this.markerGap,s=Math.round(e.getValuePosition(n));t.strokePath({path:new C(i,s).lineTo(i-this.markerTickLength,s),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i+this.markerGap,y:s,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawVerticalBar(t,e,s){var r;const{outlineWidth:o}=this;if(t.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const e=t.createLinearGradient(s.x,0,s.x+s.width,0);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},s),{gradient:e}));const r=p(s,o/2);t.strokeRect(Object.assign(Object.assign({},r),{color:i.GRAY,lineWidth:o}))}const n=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(e.getValuePosition(this.getFillValue())),h=s.width,a=this.thumbBreadth,l=m([{x:0,y:a/2},{x:h/2,y:0},{x:h-1,y:a/2},{x:h/2,y:a}],s.x,r-a/2),d=C.fromPoints(l);if(this.effect3d){const{x:e,y:s}=l[0],{x:r,y:h}=l[2],a=t.createLinearGradient(e,s,r,h);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillPath({path:d,gradient:a}),t.strokePath({path:d,color:i.GRAY,lineWidth:o})}else t.fillPath({path:d,color:n})}else{let r=this.originIgnored?this.min:this.origin,h=this.getFillValue();if(h<r){const t=r;r=h,h=t}const a=Math.round(e.getValuePosition(r)),l=Math.round(e.getValuePosition(h)),d=p(Object.assign(Object.assign({},s),{y:a,height:l-a}),o);if(t.fillRect(Object.assign(Object.assign({},d),{color:n})),this.effect3d){const e=t.createLinearGradient(d.x,0,d.x+d.width,0);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},d),{gradient:e}))}}const h=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==h&&t.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(h)})}drawHorizontal(t,e){const i=this.alarmSensitiveForegroundColor,s=new kn(this.scale,this.scaleFont,this.min,this.max,this.logScale,this.majorTickStepHint,i,this.showMinorTicks,this.showScale);s.scaleFormat=this.scaleFormat;const r=s.drawHorizontal(t,e.x,e.y+e.height,e.width);let o=0;this.showMarkers&&(o=this.drawHorizontalMarkers(t,s,e)),this.drawHorizontalBar(t,s,{x:e.x+s.margin,y:e.y+o,width:e.width-2*s.margin,height:e.height-r-o})}drawHorizontalMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=et.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.height)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.height)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.height)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.height)}const l=i.y;if(this.showLoLo&&void 0!==s){const i=Math.round(e.getValuePosition(s)),r=l+a+this.markerGap;t.strokePath({path:new C(i,r).lineTo(i,r+this.markerTickLength),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LOLO",align:"center",baseline:"top",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const i=Math.round(e.getValuePosition(r)),s=l+a+this.markerGap;t.strokePath({path:new C(i,s).lineTo(i,s+this.markerTickLength),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"LO",align:"center",baseline:"top",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const i=Math.round(e.getValuePosition(o)),s=l+a+this.markerGap;t.strokePath({path:new C(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HI",align:"center",baseline:"top",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const i=Math.round(e.getValuePosition(n)),s=l+a+this.markerGap;t.strokePath({path:new C(i,s).lineTo(i,s+this.markerTickLength),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:i,y:l,text:"HIHI",align:"center",baseline:"top",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawHorizontalBar(t,e,s){var r;const{outlineWidth:o}=this;if(t.fillRect(Object.assign(Object.assign({},s),{color:this.colorFillbackground})),this.effect3d){const e=t.createLinearGradient(0,s.y,0,s.y+s.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},s),{gradient:e}));const r=p(s,o/2);t.strokeRect(Object.assign(Object.assign({},r),{color:i.GRAY,lineWidth:o}))}const n=this.alarmSensitiveFillColor;if(this.indicatorMode){const r=Math.round(e.getValuePosition(this.getFillValue())),h=s.height,a=this.thumbBreadth,l=m([{x:a/2,y:0},{x:a,y:h/2},{x:a/2,y:h-1},{x:0,y:h/2}],r-a/2,s.y),d=C.fromPoints(l);if(this.effect3d){const{x:e,y:s}=l[0],{x:r,y:h}=l[2],a=t.createLinearGradient(e,s,r,h);a.addColorStop(0,i.WHITE.toString()),a.addColorStop(1,n.toString()),t.fillPath({path:d,gradient:a}),t.strokePath({path:d,color:i.GRAY,lineWidth:o})}else t.fillPath({path:d,color:n})}else{let r=this.originIgnored?this.min:this.origin,h=this.getFillValue();if(h<r){const t=r;r=h,h=t}const a=Math.round(e.getValuePosition(r)),l=Math.round(e.getValuePosition(h)),d=p(Object.assign(Object.assign({},s),{x:a,width:l-a}),o);if(t.fillRect(Object.assign(Object.assign({},d),{color:n})),this.effect3d){const e=t.createLinearGradient(0,d.y,0,d.y+d.height);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,n.withAlpha(0).toString()),t.fillRect(Object.assign(Object.assign({},d),{gradient:e}))}}const h=null===(r=this.pv)||void 0===r?void 0:r.value;this.showLabel&&void 0!==h&&t.fillText({x:s.x+s.width/2,y:s.y+s.height/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.font,text:this.format(h)})}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get thumbBreadth(){return 13*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new Jo(this.valueLabelFormat).format(t):String(Number(t.toFixed(2)))}get colorLo(){return this.properties.getValue(Kh)}get colorLoLo(){return this.properties.getValue(Zh)}get colorHi(){return this.properties.getValue(Yh)}get colorHiHi(){return this.properties.getValue(Xh)}get colorFillbackground(){return this.properties.getValue(Jh)}get effect3d(){return this.properties.getValue(Qh)}get fillColorAlarmSensitive(){return this.properties.getValue(ea)}get fillColor(){return this.properties.getValue(ta)}get font(){return this.properties.getValue(ia).scale(this.scale)}get horizontal(){return this.properties.getValue(sa)}get indicatorMode(){return this.properties.getValue(ra)}get levelLo(){return this.properties.getValue(ha)}get levelLoLo(){return this.properties.getValue(aa)}get levelHi(){return this.properties.getValue(oa)}get levelHiHi(){return this.properties.getValue(na)}get limitsFromPv(){return this.properties.getValue(la)}get logScale(){return this.properties.getValue(da)}get minimum(){return this.properties.getValue(ua)}get majorTickStepHint(){return this.scale*this.properties.getValue(pa)}get maximum(){return this.properties.getValue(ca)}get origin(){return this.properties.getValue(ga)}get originIgnored(){return this.properties.getValue(ma)}get scaleFont(){return this.properties.getValue(fa).scale(this.scale)}get scaleFormat(){return this.properties.getValue(xa)}get showHi(){return this.properties.getValue(wa)}get showHiHi(){return this.properties.getValue(ya)}get showLabel(){return this.properties.getValue(va)}get showLo(){return this.properties.getValue(ba)}get showLoLo(){return this.properties.getValue(Ta)}get showMarkers(){return this.properties.getValue(Sa)}get showMinorTicks(){return this.properties.getValue(Va)}get showScale(){return this.properties.getValue(Ca)}get transparentBackground(){return this.properties.getValue(_a)}get valueLabelFormat(){return this.properties.getValue(Aa)}}const Pa="color_hi",ka="color_hihi",Ma="color_lo",Ra="color_lolo",Ea="color_fillbackground",Ba="fill_color",Wa="fillcolor_alarm_sensitive",Ia="effect_3d",Ha="level_hi",Oa="level_hihi",Da="level_lo",Na="level_lolo",Fa="limits_from_pv",$a="log_scale",ja="maximum",Ga="major_tick_step_hint",za="minimum",Ua="scale_font",qa="scale_format",Ya="show_hi",Xa="show_hihi",Ka="show_lo",Za="show_lolo",Ja="show_markers",Qa="show_minor_ticks",tl="show_scale",el="transparent_background",il=new i(160,160,160);class sl extends ke{constructor(t,e){super(t,e),this.properties.add(new B(Pa)),this.properties.add(new B(ka)),this.properties.add(new B(Ma)),this.properties.add(new B(Ra)),this.properties.add(new B(Ea)),this.properties.add(new E(Ia)),this.properties.add(new B(Ba)),this.properties.add(new E(Wa,!1)),this.properties.add(new R(Ha)),this.properties.add(new R(Oa)),this.properties.add(new R(Da)),this.properties.add(new R(Na)),this.properties.add(new E(Fa)),this.properties.add(new E($a)),this.properties.add(new R(ja)),this.properties.add(new R(Ga)),this.properties.add(new R(za)),this.properties.add(new W(Ua)),this.properties.add(new P(qa)),this.properties.add(new E(Ya)),this.properties.add(new E(Xa)),this.properties.add(new E(Ka)),this.properties.add(new E(Za)),this.properties.add(new E(Ja)),this.properties.add(new E(Qa)),this.properties.add(new E(tl)),this.properties.add(new E(el))}draw(t){const{scale:e,min:i,max:s}=this;let r=this.area;this.borderAlarmSensitive&&(r=p(r,2*e));const o=this.alarmSensitiveBackgroundColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},r),{color:o}));const n=this.alarmSensitiveForegroundColor,h=new kn(e,this.scaleFont,i,s,this.logScale,this.majorTickStepHint,n,this.showMinorTicks,this.showScale);h.scaleFormat=this.scaleFormat;const a=h.drawVertical(t,r.x,r.y,r.height,!0);let l=0;this.showMarkers&&(l=this.drawMarkers(t,r,h)),this.drawTank(t,r,a,l,h)}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=et.ARIAL_9.scale(this.scale);let a=0;if(this.showLoLo&&void 0!==s){const e=t.measureText("LOLO",h);a=Math.max(a,e.width)}if(this.showLo&&void 0!==r){const e=t.measureText("LO",h);a=Math.max(a,e.width)}if(this.showHi&&void 0!==o){const e=t.measureText("HI",h);a=Math.max(a,e.width)}if(this.showHiHi&&void 0!==n){const e=t.measureText("HIHI",h);a=Math.max(a,e.width)}const l=e.x+e.width-a-this.markerGap-this.markerTickLength;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new C(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new C(l,e).lineTo(l+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new C(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const e=Math.round(i.getValuePosition(n));t.strokePath({path:new C(l,e).lineTo(l+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:l+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}return this.markerTickLength+this.markerGap+a}drawTank(t,e,s,r,o){const n=this.alarmSensitiveForegroundColor,{scale:h,outlineWidth:a}=this,l=e.x+s,d=e.y+o.margin,c=e.width-s-r,u=e.height-2*o.margin;let g=this.defaultCorner,m=.55;c<2*g&&(m=.6);const f=Math.floor(c*m);g>2*f-c-2*a&&(g=2*f-c);const x=o.getValuePosition(this.getFillValue()),w=this.alarmSensitiveFillColor;if(this.effect3d){t.fillRect({x:l,y:d,width:c,height:u,rx:g/2,ry:g/2,color:i.WHITE});let e=t.createLinearGradient(l,d,l+f+2*h,d);e.addColorStop(0,this.colorFillbackground.toString()),e.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:d,width:f,height:u,rx:g/2,ry:g/2,gradient:e}),e=t.createLinearGradient(l+c-f-2*h,d,l+c,d),e.addColorStop(0,i.WHITE.withAlpha(0).toString()),e.addColorStop(1,this.colorFillbackground.toString()),t.fillRect({x:l+c-f,y:d,width:f,height:u,rx:g/2,ry:g/2,gradient:e});const s=x,r=d+u-x;e=t.createLinearGradient(l,s,l+f+2*h,s),e.addColorStop(0,w.toString()),e.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:l,y:s,width:f,height:r,rx:g/2,ry:g/2,gradient:e}),e=t.createLinearGradient(l+c-f-2*h,s,l+c,s),e.addColorStop(0,i.WHITE.withAlpha(0).toString()),e.addColorStop(1,w.toString()),t.fillRect({x:l+c-f,y:s,width:f,height:r,rx:g/2,ry:g/2,gradient:e})}else t.fillRect({x:l,y:d,width:c,height:u,rx:g/2,ry:g/2,color:this.colorFillbackground}),t.fillRect({x:l,y:x,width:c,height:d+u-x,rx:g/2,ry:g/2,color:w});let y=p({x:l,y:d,width:c,height:u},a/2);t.strokeRect(Object.assign(Object.assign({},y),{rx:g/2,ry:g/2,color:this.effect3d?il:n,lineWidth:a}))}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get defaultCorner(){return 15*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get outlineWidth(){return 1*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}get colorLo(){return this.properties.getValue(Ma)}get colorLoLo(){return this.properties.getValue(Ra)}get colorHi(){return this.properties.getValue(Pa)}get colorHiHi(){return this.properties.getValue(ka)}get colorFillbackground(){return this.properties.getValue(Ea)}get fillColorAlarmSensitive(){return this.properties.getValue(Wa)}get fillColor(){return this.properties.getValue(Ba)}get effect3d(){return this.properties.getValue(Ia)}get levelLo(){return this.properties.getValue(Da)}get levelLoLo(){return this.properties.getValue(Na)}get levelHi(){return this.properties.getValue(Ha)}get levelHiHi(){return this.properties.getValue(Oa)}get limitsFromPv(){return this.properties.getValue(Fa)}get logScale(){return this.properties.getValue($a)}get minimum(){return this.properties.getValue(za)}get majorTickStepHint(){return this.scale*this.properties.getValue(Ga)}get maximum(){return this.properties.getValue(ja)}get scaleFont(){return this.properties.getValue(Ua).scale(this.scale)}get scaleFormat(){return this.properties.getValue(qa)}get showLo(){return this.properties.getValue(Ka)}get showLoLo(){return this.properties.getValue(Za)}get showHi(){return this.properties.getValue(Ya)}get showHiHi(){return this.properties.getValue(Xa)}get showMarkers(){return this.properties.getValue(Ja)}get showMinorTicks(){return this.properties.getValue(Qa)}get showScale(){return this.properties.getValue(tl)}get transparentBackground(){return this.properties.getValue(el)}}const rl="font",ol="format_type",nl="horizontal_alignment",hl="precision",al="precision_from_pv",ll="show_units",dl="vertical_alignment";class cl extends ke{constructor(t,e){super(t,e),this.properties.add(new W(rl)),this.properties.add(new M(ol)),this.properties.add(new M(nl)),this.properties.add(new M(hl)),this.properties.add(new E(al)),this.properties.add(new E(ll,!0)),this.properties.add(new M(dl))}init(){this.areaRegion={id:`${this.wuid}-area`,click:()=>{const t={pvName:this.pvName};this.display.fireEvent("openpv",t)},tooltip:()=>this.tooltip,cursor:"pointer"}}draw(t){var e,i,s;const r=t.ctx;if(this.backgroundAlarmSensitive&&this.alarm?t.fillRect(Object.assign(Object.assign({},this.area),{color:this.alarmSensitiveBackgroundColor})):this.transparent||t.fillRect(Object.assign(Object.assign({},this.area),{color:this.backgroundColor})),this.pv&&this.pv.navigable&&!this.pv.disconnected){t.addHitRegion(this.areaRegion).addRect(this.x,this.y,this.width,this.height)}r.fillStyle=this.alarmSensitiveForegroundColor.toString(),r.font=this.font.getFontString();const{scale:o}=this;let n=this.area;this.borderAlarmSensitive&&(n=p(n,2*o,2*o));let h=n.x;0===this.horizAlignment?r.textAlign="start":1===this.horizAlignment?(h+=n.width/2,r.textAlign="center"):2===this.horizAlignment&&(h+=n.width,r.textAlign="end");let a=n.y;0===this.vertAlignment?r.textBaseline="top":1===this.vertAlignment?(a+=n.height/2,r.textBaseline="middle"):2===this.vertAlignment&&(a+=n.height,r.textBaseline="bottom");let l=this.text;if(void 0!==(null===(e=this.pv)||void 0===e?void 0:e.value)){let t=this.precisionFromPV?this.pv.precision:this.precision;-1===t&&(t=null!==(i=this.pv.precision)&&void 0!==i?i:-1),l=T(this.pv.value,this.formatType,t)}else void 0!==this.value&&(l=T(this.value,this.formatType,this.precision));this.showUnits&&(null===(s=this.pv)||void 0===s?void 0:s.units)&&(l+=" "+this.pv.units),r.fillText(l,h,a)}get font(){return this.properties.getValue(rl).scale(this.scale)}get formatType(){return this.properties.getValue(ol)}get horizAlignment(){return this.properties.getValue(nl)}get precision(){return this.properties.getValue(hl)}get precisionFromPV(){return this.properties.getValue(al)}get showUnits(){return this.properties.getValue(ll)}get vertAlignment(){return this.properties.getValue(dl)}}const pl="color_hi",ul="color_hihi",gl="color_lo",ml="color_lolo",fl="color_fillbackground",xl="fill_color",wl="fillcolor_alarm_sensitive",yl="font",vl="effect_3d",bl="level_hi",Tl="level_hihi",Sl="level_lo",Vl="level_lolo",Cl="limits_from_pv",_l="log_scale",Al="maximum",Ll="major_tick_step_hint",Pl="minimum",kl="scale_font",Ml="scale_format",Rl="show_bulb",El="show_hi",Bl="show_hihi",Wl="show_lo",Il="show_lolo",Hl="show_markers",Ol="show_minor_ticks",Dl="show_scale",Nl="transparent_background",Fl="unit",$l="value_label_format",jl=new i(160,160,160);class Gl extends ke{constructor(t,e){super(t,e),this.properties.add(new B(pl)),this.properties.add(new B(ul)),this.properties.add(new B(gl)),this.properties.add(new B(ml)),this.properties.add(new B(fl)),this.properties.add(new B(xl)),this.properties.add(new E(wl,!1)),this.properties.add(new E(vl)),this.properties.add(new R(bl)),this.properties.add(new R(Tl)),this.properties.add(new R(Sl)),this.properties.add(new R(Vl)),this.properties.add(new E(Cl)),this.properties.add(new W(yl)),this.properties.add(new E(_l)),this.properties.add(new R(Al)),this.properties.add(new R(Ll)),this.properties.add(new R(Pl)),this.properties.add(new W(kl)),this.properties.add(new P(Ml)),this.properties.add(new E(Rl)),this.properties.add(new E(El)),this.properties.add(new E(Bl)),this.properties.add(new E(Wl)),this.properties.add(new E(Il)),this.properties.add(new E(Hl)),this.properties.add(new E(Ol)),this.properties.add(new E(Dl)),this.properties.add(new E(Nl)),this.properties.add(new M(Fl)),this.properties.add(new P($l))}draw(t){var e;const{scale:s,min:r,max:o}=this;let n=this.area;this.borderAlarmSensitive&&(n=p(this.area,2*this.scale));const h=this.alarmSensitiveBackgroundColor,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor;this.transparentBackground||t.fillRect(Object.assign(Object.assign({},n),{color:h}));let d=n.height;if(this.showBulb){let t=Math.min(n.width/2,this.bulbMaxDiameter);d=n.height<t?0:n.height-t}let c=Object.assign(Object.assign({},n),{height:d});const u=new kn(s,this.scaleFont,r,o,this.logScale,this.majorTickStepHint,a,this.showMinorTicks,this.showScale);u.scaleFormat=this.scaleFormat;let g=0,m="";if(0===this.unit?m="°C":1===this.unit?m="°F":2===this.unit&&(m="K"),m){const e=et.ARIAL_9.scale(s),i=2*s;g=t.measureText(m,e).height+2*i,t.fillText({x:n.x+n.width/2-this.pipeWidth/2-i,y:n.y+i,baseline:"top",align:"right",color:a,font:e,text:m})}const f=c.x+c.width/2-this.pipeWidth/2-1*s,x=Object.assign(Object.assign({},c),{y:c.y+g,height:c.height-g+u.calculateMargin(t,!1)});u.drawVertical(t,f,x.y,x.height,!1);const w=Math.floor(this.pipeWidth/2);if(c=Object.assign(Object.assign({},c),{y:u.getValuePosition(o)-w,height:u.scaleLength+2*w}),this.drawPipe(t,c,u),this.showMarkers&&this.drawMarkers(t,n,u),this.showBulb){let o=Math.min(n.width/2,this.bulbMaxDiameter);const h=1*s,p=n.x+n.width/2,g=n.y+d+o/2,m=o/2,f=o/2;if(t.fillEllipse({cx:p,cy:g,rx:m,ry:f,color:l}),this.effect3d){const e=t.createLinearGradient(p-m,g-f,p+m,g+f);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,l.withAlpha(0).toString()),t.fillEllipse({cx:p,cy:g,rx:m,ry:f,gradient:e})}t.strokeEllipse({cx:p,cy:g,rx:m-h/2,ry:f-h/2,color:this.effect3d?jl:a,lineWidth:h});const x={x:Math.round(c.x+c.width/2-this.pipeWidth/2)+this.outlineWidth,y:Math.floor(u.getValuePosition(r)),width:this.pipeWidth-2*this.outlineWidth,height:3*s};if(this.effect3d){const e=Math.round(c.x+c.width/2-this.pipeWidth/2),s=e+this.pipeWidth,r=t.createLinearGradient(e,x.y,s,x.y);r.addColorStop(0,i.WHITE.toString()),r.addColorStop(1,l.toString()),t.fillRect(Object.assign(Object.assign({},x),{gradient:r}))}else t.fillRect(Object.assign(Object.assign({},x),{color:l}));const w=null===(e=this.pv)||void 0===e?void 0:e.value;w&&t.fillText({x:p,y:g,align:"center",baseline:"middle",color:l.contrast(),font:this.font,text:this.format(w)})}}drawPipe(t,e,s){const{scale:r,outlineWidth:o,min:n,max:h}=this,a=this.alarmSensitiveForegroundColor,l=this.alarmSensitiveFillColor,d={x:Math.round(e.x+e.width/2-this.pipeWidth/2),y:e.y,width:this.pipeWidth,height:e.height},c=this.getFillValue();let u=s.getValuePosition(c);h>n?c>h?u-=10*r:c<n&&(u+=10*r):c>n?u+=10*r:c<h&&(u-=10*r);const g=this.pipeWidth/2,{x:m,y:f,width:x,height:w}=d;if(this.effect3d){let e=t.createLinearGradient(m,f,m+x,f);e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,this.colorFillbackground.toString()),t.fillRect(Object.assign(Object.assign({},d),{rx:g/2,ry:g/2,gradient:e})),e=t.createLinearGradient(m,f,m+x,f),e.addColorStop(0,i.WHITE.toString()),e.addColorStop(1,l.toString()),t.fillRect({x:m,y:u,width:x,height:f+w-u,rx:g/2,ry:g/2,gradient:e})}else t.fillRect(Object.assign(Object.assign({},d),{rx:g/2,ry:g/2,color:this.colorFillbackground})),t.fillRect({x:m,y:u,width:x,height:f+w-u,rx:g/2,ry:g/2,color:l});let y=p(d,o/2);t.strokeRect(Object.assign(Object.assign({},y),{rx:g/2,ry:g/2,color:this.effect3d?jl:a,lineWidth:o}))}drawMarkers(t,e,i){const{lolo:s,lo:r,hi:o,hihi:n}=this,h=et.ARIAL_9.scale(this.scale),a=e.x+e.width/2+this.pipeWidth/2;if(this.showLoLo&&void 0!==s){const e=Math.round(i.getValuePosition(s));t.strokePath({path:new C(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLoLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LOLO",align:"left",baseline:"middle",color:this.colorLoLo,font:h})}if(this.showLo&&void 0!==r){const e=Math.round(i.getValuePosition(r));t.strokePath({path:new C(a,e).lineTo(a+this.markerTickLength,e),color:this.colorLo,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"LO",align:"left",baseline:"middle",color:this.colorLo,font:h})}if(this.showHi&&void 0!==o){const e=Math.round(i.getValuePosition(o));t.strokePath({path:new C(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HI",align:"left",baseline:"middle",color:this.colorHi,font:h})}if(this.showHiHi&&void 0!==n){const e=Math.round(i.getValuePosition(n));t.strokePath({path:new C(a,e).lineTo(a+this.markerTickLength,e),color:this.colorHiHi,lineWidth:this.markerTickLineWidth}),t.fillText({x:a+this.markerTickLength+this.markerGap,y:e,text:"HIHI",align:"left",baseline:"middle",color:this.colorHiHi,font:h})}}get min(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.lowerDisplayLimit)&&void 0!==e?e:this.minimum}get max(){var t,e;return this.limitsFromPv&&null!==(e=null===(t=this.pv)||void 0===t?void 0:t.upperDisplayLimit)&&void 0!==e?e:this.maximum}get lolo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerAlarmLimit:this.levelLoLo}get lo(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.lowerWarningLimit:this.levelLo}get hi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperWarningLimit:this.levelHi}get hihi(){return this.limitsFromPv&&this.pv&&!this.pv.disconnected?this.pv.upperAlarmLimit:this.levelHiHi}get pipeWidth(){return 15*this.scale}get bulbMaxDiameter(){return 40*this.scale}get outlineWidth(){return 1*this.scale}get markerTickLength(){return 10*this.scale}get markerTickLineWidth(){return 2*this.scale}get markerGap(){return 3*this.scale}get alarmSensitiveFillColor(){if(this.fillColorAlarmSensitive){if(this.isMajorSeverity())return i.RED;if(this.isMinorSeverity())return i.ORANGE}return this.fillColor}getFillValue(){var t,e;let i=null!==(e=null===(t=this.pv)||void 0===t?void 0:t.value)&&void 0!==e?e:this.min;return i=Math.max(this.min,i),i=Math.min(this.max,i),i}format(t){return this.valueLabelFormat?new Jo(this.valueLabelFormat).format(t):String(Number(t.toFixed(3)))}get colorLo(){return this.properties.getValue(gl)}get colorLoLo(){return this.properties.getValue(ml)}get colorHi(){return this.properties.getValue(pl)}get colorHiHi(){return this.properties.getValue(ul)}get colorFillbackground(){return this.properties.getValue(fl)}get fillColorAlarmSensitive(){return this.properties.getValue(wl)}get fillColor(){return this.properties.getValue(xl)}get font(){return this.properties.getValue(yl).scale(this.scale)}get effect3d(){return this.properties.getValue(vl)}get levelLo(){return this.properties.getValue(Sl)}get levelLoLo(){return this.properties.getValue(Vl)}get levelHi(){return this.properties.getValue(bl)}get levelHiHi(){return this.properties.getValue(Tl)}get limitsFromPv(){return this.properties.getValue(Cl)}get logScale(){return this.properties.getValue(_l)}get minimum(){return this.properties.getValue(Pl)}get majorTickStepHint(){return this.scale*this.properties.getValue(Ll)}get maximum(){return this.properties.getValue(Al)}get scaleFont(){return this.properties.getValue(kl).scale(this.scale)}get scaleFormat(){return this.properties.getValue(Ml)}get showBulb(){return this.properties.getValue(Rl)}get showMarkers(){return this.properties.getValue(Hl)}get showMinorTicks(){return this.properties.getValue(Ol)}get showLo(){return this.properties.getValue(Wl)}get showLoLo(){return this.properties.getValue(Il)}get showHi(){return this.properties.getValue(El)}get showHiHi(){return this.properties.getValue(Bl)}get showScale(){return this.properties.getValue(Dl)}get transparentBackground(){return this.properties.getValue(Nl)}get unit(){return this.properties.getValue(Fl)}get valueLabelFormat(){return this.properties.getValue($l)}}const zl=-323.3062,Ul=308.2547;class ql{constructor(t,e){this.widget=t,this.index=e}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`axis_${this.index}_${t}`)}isDateEnabled(){return 0!==this.timeFormat}isHorizontal(){return 0===this.index||1!==this.index&&!this.yAxis}isVertical(){return!this.isHorizontal()}isPrimary(){return this.index<=1}get effectiveMinimum(){var t;return null!==(t=this._effectiveMinimum)&&void 0!==t?t:this.minimum}set effectiveMinimum(t){this._effectiveMinimum=t}get effectiveMaximum(){var t;return null!==(t=this._effectiveMaximum)&&void 0!==t?t:this.maximum}set effectiveMaximum(t){this._effectiveMaximum=t}performAutoScale(){const t={start:this.minimum,stop:this.maximum},e=this.widget.calculateAutoscaledRange(this,t);e&&(this.effectiveMinimum=e.start,this.effectiveMaximum=e.stop,this.widget.requestRepaint())}applyZoom(t,e){let i,s,r=this.effectiveMinimum,o=this.effectiveMaximum;if(this.logScale){o=Math.log10(o),r=Math.log10(r);const n=Math.log10(t)*e,h=1-e;i=n+r*h,s=n+o*h,i<zl&&(i=zl),i=Math.pow(10,i),s>Ul&&(s=Ul),s=Math.pow(10,s)}else{const n=Math.max(Math.abs(r),Math.abs(o));r/=n,o/=n;const h=t/n*e,a=1-e;i=(h+r*a)*n,s=(h+o*a)*n}this.effectiveMinimum=i,this.effectiveMaximum=s,this.widget.requestRepaint()}get autoScale(){return this.getValue("auto_scale")}get autoScaleTreshold(){return this.getValue("auto_scale_treshold")}get axisColor(){return this.getValue("axis_color")}get axisTitle(){return this.getValue("axis_title")}get dashGridLine(){return this.getValue("dash_grid_line")}get gridColor(){return this.getValue("grid_color")}get leftBottomSide(){return this.getValue("left_bottom_side")}get logScale(){return this.getValue("log_scale")}get maximum(){return this.getValue("maximum")}get minimum(){return this.getValue("minimum")}get scaleFont(){return this.getValue("scale_font").scale(this.scale)}get scaleFormat(){return this.getValue("scale_format")}get showGrid(){return this.getValue("show_grid")}get timeFormat(){return this.getValue("time_format")}get titleFont(){return this.getValue("title_font").scale(this.scale)}get visible(){return this.getValue("visible")}get yAxis(){return this.getValue("y_axis")}}class Yl{constructor(t,e){this.xAxis=t,this.yAxis=e,this.beforeXRanges=[],this.beforeYRanges=[],this.afterXRanges=[],this.afterYRanges=[];for(const e of t)this.beforeXRanges.push({min:e.effectiveMinimum,max:e.effectiveMaximum});for(const t of e)this.beforeYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}saveState(){for(const t of this.xAxis)this.afterXRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum});for(const t of this.yAxis)this.afterYRanges.push({min:t.effectiveMinimum,max:t.effectiveMaximum})}undo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.beforeXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.beforeYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}redo(){for(let t=0;t<this.xAxis.length;t++){const e=this.xAxis[t],i=this.afterXRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}for(let t=0;t<this.yAxis.length;t++){const e=this.yAxis[t],i=this.afterYRanges[t];e.effectiveMinimum=i.min,e.effectiveMaximum=i.max}}}class Xl{constructor(){this.undoStack=[],this.redoStack=[]}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}add(t){this.undoStack.push(t),this.redoStack.length=0}undo(){const t=this.undoStack.pop();t&&(t.undo(),this.redoStack.push(t))}redo(){const t=this.redoStack.pop();t&&(t.redo(),this.undoStack.push(t))}}class Kl{constructor(t,e){this.widget=e,this.id=t}tooltip(){return this.widget.tooltip}mouseDown(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart=t;break;case"panning":this.grabZoomCommand=new Yl(i.getXAxes(),i.getYAxes())}}grab(t){var e;switch(null===(e=this.widget.toolbar)||void 0===e?void 0:e.currentTool){case"rubberband-zoom":case"horizontal-zoom":case"vertical-zoom":this.grabStart&&(this.selection=Object.assign(Object.assign({},this.grabStart.point),{width:t.dx,height:t.dy}),this.widget.requestRepaint());break;case"panning":this.pan(t),this.prevGrabEvent=t,this.widget.requestRepaint()}}grabEnd(){var t;const{grabZoomCommand:e,selection:i,widget:s}=this;switch(null===(t=s.toolbar)||void 0===t?void 0:t.currentTool){case"rubberband-zoom":if(i){const t=new Yl(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"horizontal-zoom":if(i){const t=new Yl(s.getXAxes(),s.getYAxes());this.rangeZoomXAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"vertical-zoom":if(i){const t=new Yl(s.getXAxes(),s.getYAxes());this.rangeZoomYAxes(i),t.saveState(),s.toolbar.addCommand(t)}break;case"panning":e&&(e.saveState(),s.toolbar.addCommand(e))}this.selection=void 0,this.prevGrabEvent=void 0,this.grabZoomCommand=void 0,this.widget.requestRepaint()}click(t){var e;const{widget:i}=this;switch(null===(e=i.toolbar)||void 0===e?void 0:e.currentTool){case"zoom-in":const e=new Yl(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,.1)}e.saveState(),i.toolbar.addCommand(e);break;case"zoom-out":const s=new Yl(i.getXAxes(),i.getYAxes());for(const e of i.getAxes()){const i=e.isHorizontal()?t.point.x:t.point.y,s=e.linearScale.getPositionValue(i);e.applyZoom(s,-.1)}s.saveState(),i.toolbar.addCommand(s)}}rangeZoomXAxes(t){for(const e of this.widget.getXAxes()){let i=e.linearScale.getPositionValue(t.x),s=e.linearScale.getPositionValue(t.x+t.width);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}rangeZoomYAxes(t){for(const e of this.widget.getYAxes()){let i=e.linearScale.getPositionValue(t.y),s=e.linearScale.getPositionValue(t.y+t.height);if(i>s){const t=i;i=s,s=t}const r=e.linearScale.getMinMax();i=Math.max(r.start,i),s=Math.min(r.stop,s),e.effectiveMinimum=i,e.effectiveMaximum=s}}pan(t){const{prevGrabEvent:e,widget:i}=this;if(e){const s=e.dx-t.dx;if(0!==s)for(const t of i.getXAxes()){const e=t.linearScale,i=e.getMinMax(),r=e.getValuePosition(i.start)+s,o=e.getValuePosition(i.stop)+s;t.effectiveMinimum=e.getPositionValue(r),t.effectiveMaximum=e.getPositionValue(o)}const r=e.dy-t.dy;if(0!==r)for(const t of i.getYAxes()){const e=t.linearScale,i=e.getMinMax(),s=e.getValuePosition(i.start)+r,o=e.getValuePosition(i.stop)+r;t.effectiveMinimum=e.getPositionValue(s),t.effectiveMaximum=e.getPositionValue(o)}}}}class Zl{constructor(t){this.pointer=0,this.samples=[],this.samples=Array(t).fill(void 0)}push(t,e){this.samples[this.pointer]={x:t,y:e},this.pointer=(this.pointer+1)%this.samples.length}clear(){this.samples.fill(void 0),this.pointer=0}isFull(){const t=(this.pointer+1)%this.samples.length;return void 0!==this.samples[t]}isEmpty(){return void 0===this.tail()}tail(){return 0===this.pointer?this.samples[this.samples.length-1]:this.samples[this.pointer-1]}snapshot(t=!1){if(t){return this.samples.filter((t=>void 0!==t)).sort(((t,e)=>t.x-e.x))}{const t=this.samples.slice(this.pointer).filter((t=>void 0!==t)),e=this.samples.slice(0,this.pointer).filter((t=>void 0!==t));return t.concat(e)}}}class Jl{constructor(t,e,i,s,r,o){this.bufferSize=t,this.plotMode=e,this.updateMode=i,this.concatenateData=s,this.chronological=r,this.historicalDataProvider=o,this.x=0,this.xPending=!1,this.y=0,this.yTimestamp=0,this.yPending=!1,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1,this.traceData=new Zl(t)}clear(){this.traceData.clear(),this.x=0,this.xPending=!1,this.y=0,this.yPending=!1,this.yTimestamp=0,this.xArray=[],this.xArrayPending=!1,this.yArray=[],this.yArrayPending=!1}snapshot(){return this.historicalDataProvider?this.historicalDataProvider.getSamples():this.traceData.snapshot()}updateX(t){this.x=t,this.xPending=!0,this.maybeAddPoint()}updateY(t,e){this.y=t,this.yTimestamp=e,this.yPending=!0,this.maybeAddPoint()}updateXArray(t){this.xArray=t,this.xArrayPending=!0,this.maybeAddArray()}updateYArray(t){this.yArray=t,this.yArrayPending=!0,this.maybeAddArray()}maybeAddPoint(){if(1===this.plotMode&&this.traceData.isFull())return;const{xPending:t,yPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addPoint():1===s?(i&&e||!i&&t&&e)&&this.addPoint():2===s?(i&&e||!i&&t)&&this.addPoint():3===s&&this.yPending&&this.addPoint()}maybeAddArray(){if(1===this.plotMode&&this.traceData.isFull())return;const{xArrayPending:t,yArrayPending:e,chronological:i,updateMode:s}=this;0===s?(i&&e||!i&&(t||e))&&this.addArray():1===s?(i&&e||!i&&t&&e)&&this.addArray():2===s?(i&&e||!i&&t)&&this.addArray():3===s&&this.yArrayPending&&this.addArray()}addPoint(){this.concatenateData||this.traceData.clear();let t=this.x;if(this.chronological)if(5===this.updateMode)t=(new Date).getTime();else if(void 0!==this.yTimestamp)t=this.yTimestamp;else{const e=this.traceData.tail();t=e?e.x+1:0}this.traceData.push(t,this.y),this.xPending=!1,this.yPending=!1}addArray(){this.concatenateData||this.traceData.clear();let{xArray:t,yArray:e}=this;if(this.chronological)if(t=Array(e.length),this.traceData.isEmpty())for(let i=0;i<e.length;i++)t[i]=i;else{const i=this.traceData.tail();for(let s=1;s<e.length;s++)t[s-1]=i.x+s}let i=Math.min(t.length,e.length),s=Math.min(i,this.bufferSize);for(let i=0;i<s;i++)this.traceData.push(t[i],e[i]);this.xArrayPending=!1,this.yArrayPending=!1}}class Ql{constructor(t,e){this.widget=t,this.i=e,this.xPVListener=()=>{var t,e;const i=this.xPVInstance;if(i)if(Array.isArray(i.value))null===(t=this.traceData)||void 0===t||t.updateXArray(i.value);else{const t=i.toNumber();null!=t&&(null===(e=this.traceData)||void 0===e||e.updateX(t))}},this.yPVListener=()=>{var t,e,i;const s=this.yPVInstance;if(s)if(Array.isArray(s.value))null===(t=this.traceData)||void 0===t||t.updateYArray(s.value);else{const t=this.widget.getAxis(this.xAxisIndex),r=s.toNumber();if(null!=r)if(t.isDateEnabled()){const t=(s.time||new Date).getTime();null===(e=this.traceData)||void 0===e||e.updateY(r,t)}else null===(i=this.traceData)||void 0===i||i.updateY(r)}}}init(){const{bufferSize:t,plotMode:e,updateMode:i,concatenateData:s,widget:r}=this,o=!this.xPV,{pvEngine:n}=r.display;this.historicalDataProvider=void 0,o&&this.yPV&&(this.historicalDataProvider=n.createHistoricalDataProvider(this.yPV,r)||void 0),this.traceData=new Jl(t,e,i,s,o,this.historicalDataProvider),this.xPV&&(this.xPVInstance=n.createPV(this.xPV),this.xPVInstance.addListener(this.xPVListener)),this.yPV&&(this.yPVInstance=n.createPV(this.yPV),this.yPVInstance.addListener(this.yPVListener)),r.addPropertyListener(`trace_${this.i}_x_pv`,(()=>{var t;const e=n.createPV(this.xPV);e!==this.xPVInstance&&(null===(t=this.xPVInstance)||void 0===t||t.removeListener(this.xPVListener),this.xPVInstance=e,this.xPVInstance.addListener(this.xPVListener))})),r.addPropertyListener(`trace_${this.i}_y_pv`,(()=>{var t;const e=n.createPV(this.yPV);e!==this.yPVInstance&&(null===(t=this.yPVInstance)||void 0===t||t.removeListener(this.yPVListener),this.yPVInstance=e,this.yPVInstance.addListener(this.yPVListener))}))}snapshot(){var t;return(null===(t=this.traceData)||void 0===t?void 0:t.snapshot())||[]}drawTrace(t,e){const{lineWidth:i}=this;if(0===this.traceType)t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i});else if(1===this.traceType)t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*this.scale,2*this.scale]});else if(2===this.traceType);else if(3===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(const r of e)null!==r.y&&t.strokePath({path:new C(r.x,r.y).lineTo(r.x,s),lineWidth:i,color:this.traceColor,opacity:100/255})}else if(4===this.traceType||5===this.traceType){const s=this.widget.getAxis(this.yAxisIndex).linearScale.getValuePosition(0);for(let i=1;i<e.length;i++){const r=e[i-1],o=e[i];null!==r.y&&null!==o.y&&t.fillPath({path:new C(r.x,r.y).lineTo(r.x,s).lineTo(o.x,s).lineTo(o.x,o.y),color:this.traceColor,opacity:100/255})}5===this.traceType&&t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i})}else if(6===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];null!==r.y&&null!==o.y&&t.strokePath({path:new C(r.x,r.y).lineTo(r.x,o.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(7===this.traceType)for(let s=1;s<e.length;s++){const r=e[s-1],o=e[s];null!==r.y&&null!==o.y&&t.strokePath({path:new C(r.x,r.y).lineTo(o.x,r.y).lineTo(o.x,o.y),color:this.traceColor,lineWidth:i})}else if(8===this.traceType){const{scale:s}=this;t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s]})}else if(9===this.traceType){const{scale:s}=this;t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[6*s,2*s,2*s,2*s,2*s,2*s]})}else if(10===this.traceType){const{scale:s}=this;t.strokePath({path:C.fromPoints(e),color:this.traceColor,lineWidth:i,dash:[2*s,2*s]})}}drawPoint(t,e){t.ctx.fillStyle=this.traceColor.toString(),t.ctx.strokeStyle=this.traceColor.toString(),t.ctx.lineWidth=1*this.scale;const i=this.pointSize/2,s=e.x,r=e.y;switch(this.pointStyle){case 1:case 3:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.fill();break;case 2:t.ctx.beginPath(),t.ctx.ellipse(s,r,i,i,0,0,2*Math.PI),t.ctx.stroke();break;case 4:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 5:t.ctx.lineWidth=1*this.scale,t.ctx.beginPath(),t.ctx.moveTo(s-i,r+i),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.closePath(),t.ctx.fill();break;case 6:t.ctx.strokeRect(s-i,r-i,2*i,2*i);break;case 7:t.ctx.fillRect(s-i,r-i,2*i,2*i);break;case 8:case 9:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s,r-i),t.ctx.lineTo(s+i,r),t.ctx.lineTo(s,r+i),t.ctx.closePath(),t.ctx.stroke();break;case 10:t.ctx.beginPath(),t.ctx.moveTo(s-i,r-i),t.ctx.lineTo(s+i,r+i),t.ctx.moveTo(s+i,r-i),t.ctx.lineTo(s-i,r+i),t.ctx.stroke();break;case 11:t.ctx.beginPath(),t.ctx.moveTo(s-i,r),t.ctx.lineTo(s+i,r),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke();break;case 12:t.ctx.beginPath(),t.ctx.moveTo(s,r-i),t.ctx.lineTo(s,r+i),t.ctx.stroke()}}clearData(){var t;null===(t=this.traceData)||void 0===t||t.clear()}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`trace_${this.i}_${t}`)}get antiAlias(){return this.getValue("anti_alias")}get bufferSize(){return this.getValue("buffer_size")}get concatenateData(){return this.getValue("concatenate_data")}get lineWidth(){return this.scale*this.getValue("line_width")}get name(){return this.getValue("name")}get plotMode(){return this.getValue("plot_mode")}get pointSize(){return this.scale*this.getValue("point_size")}get pointStyle(){return this.getValue("point_style")}get traceColor(){return this.getValue("trace_color")}get traceType(){return this.getValue("trace_type")}get updateDelay(){return this.getValue("update_delay")}get updateMode(){return this.getValue("update_mode")}get visible(){return this.getValue("visible")}get xAxisIndex(){return this.getValue("x_axis_index")}get xPV(){return this.getValue("x_pv")}get yAxisIndex(){return this.getValue("y_axis_index")}get yPV(){return this.getValue("y_pv")}destroy(){var t;null===(t=this.historicalDataProvider)||void 0===t||t.disconnect()}}const td=new i(236,236,236),ed=new i(130,130,130);class id{constructor(t,e,i,s,r){this.imageFile=e,this.disabledImageFile=i,this.action=r,this.imageElement=new Image,this.disabledImageElement=new Image,this.toggleButton=!1,this.toolButton=!1,this.pushed=!1,this.disabled=!1,this.loadPromise=new Promise(((t,e)=>{this.imageElement.onload=()=>t()})),this.disabledLoadPromise=new Promise(((t,e)=>{this.disabledImageElement.onload=()=>t()})),this.region={id:`${t.xyGraph.wuid}-${e}`,mouseDown:()=>{this.toggleButton||(this.pushed=!0,t.xyGraph.requestRepaint())},mouseOut:()=>{this.toggleButton||(this.pushed=!1),t.xyGraph.requestRepaint()},mouseUp:()=>{this.toggleButton||(this.pushed=!1,t.xyGraph.requestRepaint())},click:()=>{this.toggleButton&&(this.pushed=!this.pushed,this.toolButton&&t.toggleTool(this)),this.action(),t.updateState()},tooltip:()=>s}}loadImage(t){this.imageElement.src=t+this.imageFile,this.disabledImageElement.src=t+this.disabledImageFile}}class sd{constructor(t){this.xyGraph=t,this.buttons=[],this.imagesLoaded=!1,this.currentTool="default",this.commandBuffer=new Xl,this.showLegend=this.createToggleButton("ShowLegend.png","Show Legend",(()=>{t.properties.setValue("show_legend",this.showLegend.pushed)})),this.showLegend.pushed=t.showLegend,t.addPropertyListener("show_legend",(t=>{this.showLegend.pushed=t})),this.autoScale=this.createButton("AutoScale.png","AutoScale.png","Perform Auto Scale",(()=>{const e=new Yl(t.getXAxes(),t.getYAxes());t.performAutoScale(),e.saveState(),this.addCommand(e)})),this.rubberbandZoom=this.createToolButton("RubberbandZoom.png","Rubberband Zoom",(()=>{this.rubberbandZoom.pushed?(this.currentTool="rubberband-zoom",t.setCursor("crosshair"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.horizontalZoom=this.createToolButton("HorizontalZoom.png","Horizontal Zoom",(()=>{this.horizontalZoom.pushed?(this.currentTool="horizontal-zoom",t.setCursor("col-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.verticalZoom=this.createToolButton("VerticalZoom.png","Vertical Zoom",(()=>{this.verticalZoom.pushed?(this.currentTool="vertical-zoom",t.setCursor("row-resize"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomIn=this.createToolButton("ZoomIn.png","Zoom In",(()=>{this.zoomIn.pushed?(this.currentTool="zoom-in",t.setCursor("zoom-in"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.zoomOut=this.createToolButton("ZoomOut.png","Zoom Out",(()=>{this.zoomOut.pushed?(this.currentTool="zoom-out",t.setCursor("zoom-out"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.panning=this.createToolButton("Panning.png","Panning",(()=>{this.panning.pushed?(this.currentTool="panning",t.setCursor("grab"),t.autoScaleAllowed=!1):(this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0)})),this.mouseArrow=this.createToolButton("MouseArrow.png","None",(()=>{this.currentTool="default",t.setCursor(void 0),t.autoScaleAllowed=!0})),this.undo=this.createButton("Undo.png","Undo_Gray.png","Undo",(()=>{this.commandBuffer.undo()})),this.undo.disabled=!0,this.redo=this.createButton("Redo.png","Redo_Gray.png","Redo",(()=>{this.commandBuffer.redo()})),this.redo.disabled=!0,this.camera=this.createButton("camera.png","camera.png","Save Snapshot to PNG File",(()=>{const e=document.createElement("a");try{e.href=t.toDataURL(),e.download=`${t.name}_export.png`,document.body.appendChild(e),e.click()}finally{document.body.removeChild(e)}})),this.toggleTool(this.mouseArrow);const e=this.buttons.map((t=>t.loadPromise)).concat(this.buttons.map((t=>t.disabledLoadPromise)));Promise.all(e).finally((()=>{this.imagesLoaded=!0,t.requestRepaint()}));for(const e of this.buttons)e.loadImage(t.display.imagesPrefix)}updateState(){this.undo.disabled=!this.commandBuffer.canUndo(),this.redo.disabled=!this.commandBuffer.canRedo(),this.xyGraph.requestRepaint()}addCommand(t){this.commandBuffer.add(t),this.updateState()}toggleTool(t){const e=t.pushed;for(const t of this.buttons)t.toolButton&&(t.pushed=!1);e?t.pushed=!0:this.mouseArrow.pushed=!0,this.xyGraph.requestRepaint()}createToolButton(t,e,i){const s=this.createToggleButton(t,e,i);return s.toolButton=!0,s}createToggleButton(t,e,i){const s=this.createButton(t,t,e,i);return s.toggleButton=!0,s}createButton(t,e,i,s){const r=new id(this,t,e,i,s);return this.buttons.push(r),r}draw(t,e){const{buttonSize:i}=this,s={x:e.x,y:e.y};return this.drawButton(t,s.x,s.y,this.showLegend),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.autoScale),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.rubberbandZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.horizontalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.verticalZoom),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomIn),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.zoomOut),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.panning),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.mouseArrow),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.undo),s.x+=i,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.redo),s.x+=i,this.maybeWrap(s,e,i/2),this.drawSeparator(t,s.x,s.y),s.x+=i/2,this.maybeWrap(s,e),this.drawButton(t,s.x,s.y,this.camera),s.x+=i,s.y+i-e.y}maybeWrap(t,e,i){i=null!=i?i:this.buttonSize,t.x+i>e.x+e.width&&(t.x=e.x,t.y+=this.buttonSize)}drawSeparator(t,e,i){const{buttonSize:s}=this,r=1*this.scale,o=Math.round(e+s/4)-r/2;t.strokePath({path:new C(o,i).lineTo(o,i+s),color:ed,lineWidth:r})}drawButton(t,e,s,r){const{buttonSize:o,scale:n}=this;t.fillRect({x:e,y:s,width:o,height:o,color:td}),this.xyGraph.enabled&&!r.disabled&&t.addHitRegion(r.region).addRect(e,s,o,o);const h=1*n,a=Math.round(s+h/2)-.5,l=Math.round(e+h/2)-.5,d=Math.round(s+o-h+h/2)-.5,c=Math.round(e+o-h+h/2)-.5;if(t.strokePath({color:r.pushed?i.WHITE:i.BLACK,path:new C(c,d).lineTo(c,a).moveTo(c,d).lineTo(l,d),lineWidth:h}),t.strokePath({color:r.pushed?i.BLACK:i.WHITE,path:new C(l,a).lineTo(c-h,a).moveTo(l,a).lineTo(l,d-h),lineWidth:h}),this.imagesLoaded){const i=r.disabled?r.disabledImageElement:r.imageElement,h=i.naturalHeight*n,a=i.naturalWidth*n,l=Math.round(e+(o-a)/2),d=Math.round(s+(o-h)/2);t.ctx.drawImage(i,l,d,a,h)}}get scale(){return this.xyGraph.scale}get buttonSize(){return 25*this.scale}}const rd="axis_count",od="plot_area_background_color",nd="show_legend",hd="show_plot_area_border",ad="show_toolbar",ld="title",dd="title_font",cd="trace_count",pd="transparent";class ud extends ke{constructor(t,e){super(t,e),this.axes=[],this.traces=[],this.autoScaleAllowed=!0,this.properties.add(new M(rd)),this.properties.add(new B(od)),this.properties.add(new E(nd)),this.properties.add(new E(hd)),this.properties.add(new E(ad)),this.properties.add(new P(ld)),this.properties.add(new W(dd)),this.properties.add(new M(cd)),this.properties.add(new E(pd)),this.properties.addGenerator((()=>{const t=[];this.axes=[];const e=this.properties.getValue(rd);for(let i=0;i<e;i++)this.axes.push(new ql(this,i)),t.push(new E(`axis_${i}_auto_scale`),new R(`axis_${i}_auto_scale_treshold`),new B(`axis_${i}_axis_color`),new P(`axis_${i}_axis_title`),new E(`axis_${i}_dash_grid_line`),new B(`axis_${i}_grid_color`),new E(`axis_${i}_log_scale`),new R(`axis_${i}_maximum`),new R(`axis_${i}_minimum`),new W(`axis_${i}_scale_font`),new P(`axis_${i}_scale_format`),new E(`axis_${i}_show_grid`),new M(`axis_${i}_time_format`),new W(`axis_${i}_title_font`),new E(`axis_${i}_visible`)),i>1&&t.push(new E(`axis_${i}_left_bottom_side`),new E(`axis_${i}_y_axis`));this.traces=[];const i=this.properties.getValue(cd);for(let e=0;e<i;e++)this.traces.push(new Ql(this,e)),t.push(new E(`trace_${e}_anti_alias`),new M(`trace_${e}_buffer_size`),new E(`trace_${e}_concatenate_data`),new M(`trace_${e}_line_width`),new P(`trace_${e}_name`),new M(`trace_${e}_plot_mode`),new M(`trace_${e}_point_size`),new M(`trace_${e}_point_style`),new B(`trace_${e}_trace_color`),new M(`trace_${e}_trace_type`),new M(`trace_${e}_update_delay`),new M(`trace_${e}_update_mode`),new E(`trace_${e}_visible`),new M(`trace_${e}_x_axis_index`),new P(`trace_${e}_x_pv`),new k(`trace_${e}_x_pv_value`,`trace_${e}_x_pv`),new M(`trace_${e}_y_axis_index`),new P(`trace_${e}_y_pv`),new k(`trace_${e}_y_pv_value`,`trace_${e}_y_pv`));return t}))}init(){this.plotAreaRegion=new Kl(`${this.wuid}-plotarea`,this),this.traces.forEach((t=>t.init()))}draw(t){var e;const{scale:i}=this;let s=this.area;if(this.borderAlarmSensitive&&(s=p(this.area,2*i)),!this.transparent){const e=this.alarmSensitiveBackgroundColor;t.fillRect(Object.assign(Object.assign({},s),{color:e}))}this.showToolbar&&this.drawToolbar(t,s),this.title&&this.drawTitle(t,s);for(const t of this.axes){if(t.autoScale&&this.autoScaleAllowed){const e={start:t.minimum,stop:t.maximum},i=this.calculateAutoscaledRange(t,e);i&&(t.effectiveMinimum=i.start,t.effectiveMaximum=i.stop)}const e=t.effectiveMinimum,s=t.effectiveMaximum;t.linearScale=new kn(i,t.scaleFont,e,s,t.logScale,50*i,t.axisColor,!0,t.visible),t.linearScale.scaleFormat=t.scaleFormat,t.linearScale.timeFormat=t.timeFormat}this.showLegend&&this.drawLegend(t,s),t.addHitRegion(this.plotAreaRegion).addRect(s.x,s.y,s.width,s.height);const r=this.drawAxes(t,s);this.drawPlotArea(t,r);const o=null===(e=this.plotAreaRegion)||void 0===e?void 0:e.selection;o&&this.drawZoomSelection(t,r,function(t,e){let i=t.x,s=t.y,r=i+t.width,o=s+t.height;if(r<i){const t=i;i=r,r=t}if(o<s){const t=s;s=o,o=t}let n=e.x,h=e.y,a=n+e.width,l=h+e.height;if(a<n){const t=n;n=a,a=t}if(l<h){const t=h;h=l,l=t}const d=Math.max(i,n),c=Math.max(s,h);return{x:d,y:c,width:Math.min(r,a)-d,height:Math.min(o,l)-c}}(r,o))}drawToolbar(t,e){this.toolbar||(this.toolbar=new sd(this));const i=3*this.scale,s=p(e,i),r=this.toolbar.draw(t,s);e.y+=i+r+i,e.height-=i+r+i}drawTitle(t,e){const i=t.measureText(this.title,this.titleFont).height;t.fillText({x:e.x+e.width/2,y:e.y+i/2,align:"center",baseline:"middle",color:this.alarmSensitiveForegroundColor,font:this.titleFont,text:this.title});const s=2*this.scale;e.y+=i+s,e.height-=i+s}drawAxes(t,e){const{scale:i}=this,s=5*i,r=Object.assign({},e);let o=0;for(const e of this.getXAxes())if(e.visible){let i=0;e.axisTitle&&(i=s+t.measureText(e.axisTitle,e.titleFont).height),o+=i+e.linearScale.measureHorizontalHeight(t)}let n=0,h=0;for(const a of this.getYAxes().reverse()){const l=a.linearScale;if(a.visible){const d=l.calculateMargin(t,!1),c=r.height-o+(o>0?d:0);let p=0;a.axisTitle&&(p=t.measureText(a.axisTitle,a.titleFont).height,t.ctx.save(),t.ctx.translate(r.x+s+p/2,e.y+c/2),t.ctx.rotate(-Math.PI/2),t.fillText({x:0,y:0,align:"center",baseline:"middle",font:a.titleFont,color:a.axisColor,text:a.axisTitle}),t.ctx.restore(),p+=s);const u=p+l.drawVertical(t,r.x+p,e.y,c,!0,!1);r.x+=u,r.width-=u,n+=u;const g=l.margin;h=0===h?g:Math.min(h,g);const m=1*i,f=Math.round(r.x)-m/2,x=Math.round(e.y+d)-m/2;t.strokePath({path:new C(f,x).lineTo(f,x+c-2*d),color:a.axisColor,opacity:100/255,lineWidth:m})}else{const t=r.height-o;l.setDimensions(0,e.y,t,!1)}}let a=0;for(const o of this.getXAxes().reverse()){const h=o.linearScale;if(o.visible){const l=h.calculateMargin(t,!0),d=n-l;let c=0;if(o.axisTitle){c=t.measureText(o.axisTitle,o.titleFont).height;const i=e.x+n+(e.width-n)/2;t.fillText({x:i,y:r.y+r.height-c/2,align:"center",baseline:"middle",font:o.titleFont,color:o.axisColor,text:o.axisTitle}),c+=s}const p=c+h.drawHorizontal(t,e.x+d,r.y+r.height-c,e.width-d);r.height-=p;const u=h.margin;a=0===a?u:Math.min(a,u);const g=1*i,m=Math.round(e.x+d+l)-g/2,f=Math.round(r.y+r.height)-g/2;t.strokePath({path:new C(m,f).lineTo(m+r.width-l,f),color:o.axisColor,opacity:100/255,lineWidth:g})}else{const t=e.x+n,i=e.width-n;h.setDimensions(t,0,i,!0)}}return r.y+=h,r.width-=a,r.height-=o>0?h:2*h,r}drawPlotArea(t,e){const{scale:s}=this,r=1*s;if(t.fillRect(Object.assign(Object.assign({},e),{color:this.plotAreaBackgroundColor})),this.showPlotAreaBorder){const{x:s,y:o,width:n,height:h}=p(e,r/2);t.strokePath({path:new C(s,o).lineTo(s+n,o).lineTo(s+n,o+h),color:i.BLACK,lineWidth:r})}for(const i of this.axes.filter((t=>t.visible&&t.showGrid))){const o=i.linearScale;if(i.isHorizontal())for(const n of o.getGridPositions()){const h=Math.round(o.getX()+n)-r/2;t.strokePath({path:new C(h,e.y).lineTo(h,e.y+e.height),color:i.gridColor,lineWidth:r,dash:i.dashGridLine?[6*s,2*s]:void 0})}else for(const n of o.getGridPositions()){const h=Math.round(o.getY()+n)-r/2;t.strokePath({path:new C(e.x,h).lineTo(e.x+e.width,h),color:i.gridColor,lineWidth:r,dash:i.dashGridLine?[6*s,2*s]:void 0})}}t.ctx.save(),t.ctx.beginPath(),t.ctx.rect(e.x,e.y,e.width,e.height),t.ctx.clip();for(const e of this.traces.filter((t=>t.visible))){const i=this.getAxis(e.xAxisIndex).linearScale,s=this.getAxis(e.yAxisIndex).linearScale,r=[];for(const t of e.snapshot()){const e=i.getValuePosition(t.x),o=null!==t.y?s.getValuePosition(t.y):null;r.push({x:e,y:o})}if(r.length){e.drawTrace(t,r);for(const i of r)null!==i.y&&e.drawPoint(t,i)}}t.ctx.restore()}drawZoomSelection(t,e,s){var r;const{scale:o}=this;switch(null===(r=this.toolbar)||void 0===r?void 0:r.currentTool){case"rubberband-zoom":t.strokeRect(Object.assign(Object.assign({},s),{color:i.BLACK,lineWidth:1*o}));break;case"horizontal-zoom":const r=s;r.y=e.y,r.height=e.height,t.strokeRect(Object.assign(Object.assign({},u(r)),{color:i.BLACK,lineWidth:1*o}));break;case"vertical-zoom":const n=s;n.x=e.x,n.width=e.width,t.strokeRect(Object.assign(Object.assign({},u(n)),{color:i.BLACK,lineWidth:1*o}))}}drawLegend(t,e){const{scale:i}=this,s=25*i,r=2*i,o=5*i,n=et.ARIAL_10.scale(i);for(const h of this.getYAxes()){const a=this.traces.filter((t=>t.visible)),l=[];let d=[],c=0,u=0;for(const i of a){let h=s+r+o;i.name&&(h+=t.measureText(i.name,n).width),c+h<e.width?(d.push(i),c+=h):(l.push(d),h=Math.max(h,c),d=[i],c=h)}if(d.length&&(l.push(d),u=Math.max(u,c)),!l.length)continue;const g=s*l.length,m={x:Math.round(e.x+(e.width-u)/2),y:Math.round(e.y+e.height-g),width:u,height:g};e.height-=m.height,t.fillRect(Object.assign(Object.assign({},m),{color:this.plotAreaBackgroundColor})),t.strokeRect(Object.assign(Object.assign({},p(m,1*i/2)),{color:h.axisColor}));let f=m.x,x=m.y;for(let e=0;e<l.length;e++){const h=l[e],a=x+e*s,d=a+s/2;for(const e of h){const h=e.pointSize>Math.floor((s-o)/2)?Math.floor(s-o):e.pointSize;switch(e.traceType){case 3:const r=f+s/2;t.strokePath({path:new C(r,a+h).lineTo(r,a+s),lineWidth:e.lineWidth,color:e.traceColor,opacity:100/255}),e.drawPoint(t,{x:r,y:a+h});break;case 4:case 5:const o=[{x:f,y:a+s/2},{x:f+s/2,y:a+h},{x:f+s,y:a+s/2},{x:f+s,y:a+s},{x:f,y:a+s}];t.fillPath({path:C.fromPoints(o),color:e.traceColor,opacity:100/255}),5===e.traceType&&t.strokePath({path:C.fromPoints(o.slice(0,3)),color:e.traceColor,lineWidth:1*i}),e.drawPoint(t,{x:f+s/2,y:a+h});break;default:e.drawTrace(t,[{x:f,y:d},{x:f+s,y:d}]),e.drawPoint(t,{x:f+s/2,y:d})}f+=s+r,e.name&&(t.fillText({x:f,y:d,align:"left",baseline:"middle",color:e.traceColor,font:n,text:e.name}),f+=t.measureText(e.name,n).width),f+=o}}}}setCursor(t){this.plotAreaRegion.cursor=t}calculateAutoscaledRange(t,e){let i,s;const r=t.logScale;for(const e of this.traces)if(e.visible&&(this.axes[e.xAxisIndex]===t||this.axes[e.yAxisIndex]===t))for(const o of e.snapshot()){const e=t.isHorizontal()?o.x:o.y;null!==e&&((void 0===i||i>e)&&(!r||e>0)&&(i=e),(void 0===s||s<e)&&(!r||e>0)&&(s=e))}if(void 0!==i&&void 0!==s)return i===s?{start:Math.min(i,e.start),stop:Math.max(s,e.stop)}:{start:i,stop:s}}performAutoScale(){for(const t of this.axes)t.visible&&t.performAutoScale()}clearGraph(){for(const t of this.traces)t.clearData();this.requestRepaint()}getAxes(){return[...this.axes]}getXAxes(){return this.axes.filter((t=>t.isHorizontal()))}getYAxes(){return this.axes.filter((t=>t.isVertical()))}getAxis(t){return this.axes[t]}getTrace(t){return this.traces[t]}get axisCount(){return this.properties.getValue(rd)}get plotAreaBackgroundColor(){return this.properties.getValue(od)}get showLegend(){return this.properties.getValue(nd)}get showPlotAreaBorder(){return this.properties.getValue(hd)}get showToolbar(){return this.properties.getValue(ad)}get title(){return this.properties.getValue(ld)}get titleFont(){return this.properties.getValue(dd).scale(this.scale)}get traceCount(){return this.properties.getValue(cd)}get transparent(){return this.properties.getValue(pd)}destroy(){for(const t of this.traces)t.destroy()}}class gd extends Re{parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}beforeDrawBorder(t){this.transparent||t.fillRect({x:this.holderX,y:this.holderY,width:this.holderWidth,height:this.holderHeight,color:this.backgroundColor})}draw(t){const e=t.createChild(this.width,this.height);for(const t of this.widgets.filter((t=>t.visible)))t.drawHolder(e),t.draw(e),t.drawDecoration(e);for(const t of this.widgets.filter((t=>t.visible)))t.drawOverlay(e);t.copy(e,this.x,this.y)}}const md="minimum_tab_height",fd="active_tab",xd="horizontal_tabs",wd="tab_count";class yd{constructor(t,e){this.widget=t,this.i=e,this.headerRegion={id:`${t.wuid}-header-${e}`,click:()=>{t.activeTab!==e&&(t.properties.setValue(fd,e),t.requestRepaint())},cursor:"pointer"}}get scale(){return this.widget.scale}getValue(t){return this.widget.properties.getValue(`tab_${this.i}_${t}`)}get title(){return this.getValue("title")}get backgroundColor(){return this.getValue("background_color")}get foregroundColor(){return this.getValue("foreground_color")}get enabled(){return this.getValue("enabled")}get font(){return this.getValue("font").scale(this.scale)}}class vd extends Re{constructor(t,e){super(t,e),this.tabs=[],this.properties.add(new M(md)),this.properties.add(new M(fd)),this.properties.add(new E(xd)),this.properties.add(new M(wd)),this.properties.addGenerator((()=>{this.tabs=[];const t=this.properties.getValue(wd),e=[];for(let i=0;i<t;i++)this.tabs.push(new yd(this,i)),e.push(new P(`tab_${i}_title`),new B(`tab_${i}_background_color`),new B(`tab_${i}_foreground_color`),new E(`tab_${i}_enabled`),new W(`tab_${i}_font`));return e}))}parseNode(t){super.parseNode(t);for(const e of t.getNodes("widget")){const t=e.getString("widget_type"),i=this.display.createWidget(t,this);i&&(i.parseNode(e),this.widgets.push(i))}}draw(t){this.horizontalTabs?this.drawHorizontalTabs(t):this.drawVerticalTabs(t)}measureTabOffset(t){return this.horizontalTabs?{x:0,y:this.measureLabelHeight(t)}:{x:this.measureLabelWidth(t),y:0}}measureLabelHeight(t){const{scale:e}=this,i=1*e;let s=this.minimumTabHeight;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).height+i;o>s&&(s=o)}return s+this.margin}measureLabelWidth(t){const{scale:e}=this,i=1*e;let s=this.minimumTabWidth;for(let e=0;e<this.tabs.length;e++){const r=this.tabs[e],o=t.measureText(r.title,r.font).width+i;o>s&&(s=o)}return s+this.margin}drawHorizontalTabs(t){const{margin:e,gap:s,scale:r}=this,o=this.measureLabelHeight(t),n=1*r;let h=this.x;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=t.measureText(l.title,l.font);let c,p,u,g,m;this.activeTab===a?(c=h,p=this.y,u=d.width+n+e+s,g=o,m=l.backgroundColor):(c=h+s,p=this.y+2*r,u=d.width+n+e-s,g=o-2*r,m=this.darken(l.backgroundColor)),t.fillRect({x:c,y:p,width:u,height:g,color:m});t.addHitRegion(l.headerRegion).addRect(c,p,u,g);const f=t.createLinearGradient(c,p,c,p+g);if(f.addColorStop(0,i.WHITE.toString()),f.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:c,y:p,width:u,height:g,gradient:f}),t.fillText({x:c+u/2,y:p+g/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),h+=d.width+n+e-1*r,this.activeTab===a){const e=this.x,i=this.y+o,s=this.width,r=this.height-o;t.fillRect({x:e,y:i,width:s,height:r,color:l.backgroundColor});const n=this.widgets[a],h=t.createChild(s,r);n.drawHolder(h),n.draw(h),n.drawDecoration(h),n.drawOverlay(h),t.copy(h,e,i)}else{this.widgets[a].hide()}}}drawVerticalTabs(t){const{margin:e,gap:s,scale:r}=this,o=this.measureLabelWidth(t),n=1*r;let h=this.y;for(let a=0;a<this.tabs.length;a++){const l=this.tabs[a],d=t.measureText(l.title,l.font),c=Math.max(d.height+n+n,this.minimumTabHeight);let p,u,g,m,f;this.activeTab===a?(p=this.x,u=h,g=o,m=c+e+s,f=l.backgroundColor):(p=this.x+2*r,u=h+s,g=o-2*r,m=c+e-s,f=this.darken(l.backgroundColor)),t.fillRect({x:p,y:u,width:g,height:m,color:f});t.addHitRegion(l.headerRegion).addRect(p,u,g,m);const x=t.createLinearGradient(p,u,p+g,u);if(x.addColorStop(0,i.WHITE.toString()),x.addColorStop(1,i.WHITE.withAlpha(0).toString()),t.fillRect({x:p,y:u,width:g,height:m,gradient:x}),t.fillText({x:p+g/2,y:u+m/2,baseline:"middle",align:"center",font:l.font,color:l.foregroundColor,text:l.title}),h+=c+e-1*r,this.activeTab===a){const e=this.x+o-1*r,i=this.y,s=this.width-o,n=this.height-1*r;t.fillRect({x:e,y:i,width:s,height:n,color:l.backgroundColor});const h=this.widgets[a],d=t.createChild(s,n);h.drawHolder(d),h.draw(d),h.drawDecoration(d),h.drawOverlay(d),t.copy(d,e,i)}else{this.widgets[a].destroy()}}}darken(t){const e=Math.max(0,t.red-30),s=Math.max(0,t.green-30),r=Math.max(0,t.blue-30);return new i(e,s,r)}get margin(){return 10*this.scale}get gap(){return 2*this.scale}get minimumTabWidth(){return 20*this.scale}get minimumTabHeight(){return this.scale*this.properties.getValue(md)}get activeTab(){return this.properties.getValue(fd)}get tabCount(){return this.properties.getValue(wd)}get horizontalTabs(){return this.properties.getValue(xd)}}class bd{constructor(t){this.table=t,this.columnCount=0,this.cells=[],this.dirty=!1,this.modifiedListeners=[],this.selectionChangedListeners=[]}isEmpty(){return!this.cells.length}refresh(){this.dirty=!0}getCells(){return this.cells}getContent(){const t=[];for(const e of this.cells)t.push(e.map((t=>t.text||"")));return t}setContent(t){this.cells.length=0;for(let e=0;e<t.length;e++)0===e&&(this.columnCount=t[e].length),this.cells.push(t[e].map((t=>({text:t}))));this.dirty=!0}getColumnCount(){return this.columnCount}getRowCount(){return this.cells.length}setSelectedRowIndex(t){this.selectedRowIndex=t,this.selectionChangedListeners.forEach((t=>t())),this.dirty=!0}getSelection(){if(void 0===this.selectedRowIndex)return[];return[[...this.cells[this.selectedRowIndex].map((t=>{var e;return null!==(e=t.text)&&void 0!==e?e:null}))]]}getCellText(t,e){var i,s;const r=this.cells[t];return r&&null!==(s=null===(i=r[e])||void 0===i?void 0:i.text)&&void 0!==s?s:null}setColumnsCount(t){if(t<this.columnCount)for(const e of this.cells)e.length=t;if(t>this.columnCount){const e=t-this.columnCount;for(const t of this.cells)for(let i=0;i<e;i++)t.push({text:""})}this.columnCount=t,this.dirty=!0}addModifiedListener(t){this.modifiedListeners.push(t)}addSelectionChangedListener(t){this.selectionChangedListeners.push(t)}appendRow(){const t=[];for(let e=0;e<this.columnCount;e++)t[e]={text:""};return this.cells.push(t),this.dirty=!0,this.cells.length-1}deleteRow(t){this.cells.splice(t,1),this.dirty=!0}deleteColumn(t){for(const e of this.cells)e.splice(t,1);this.columnCount--,this.dirty=!0}insertRow(t){const e=[];for(let t=0;t<this.columnCount;t++)e.push({text:""});this.cells.splice(t,0,e),this.dirty=!0}insertColumn(t){for(const e of this.cells)e.splice(t,0,{text:""});this.columnCount++,this.dirty=!0}getCell(t,e){var i,s;this.cells[t]=null!==(i=this.cells[t])&&void 0!==i?i:[];const r=null!==(s=this.cells[t][e])&&void 0!==s?s:{};return this.cells[t][e]=r,r}setCellText(t,e,i){this.getCell(t,e).text=i,this.dirty=!0}setRowBackground(t,e){const i=this.cells[t];for(const t of i)t.backgroundColor=e;this.dirty=!0}setRowForeground(t,e){const i=this.cells[t];for(const t of i)t.foregroundColor=e;this.dirty=!0}setCellBackground(t,e,i){this.getCell(t,e).backgroundColor=i,this.dirty=!0}setCellForeground(t,e,i){this.getCell(t,e).foregroundColor=i,this.dirty=!0}setColumnCellEditorData(t,e){}}const Td="columns_count",Sd="column_headers",Vd="column_header_visible",Cd="default_content",_d="font";class Ad extends ke{constructor(t,e){super(t,e),this.properties.add(new M(Td)),this.properties.add(new j(Sd)),this.properties.add(new E(Vd)),this.properties.add(new j(Cd)),this.properties.add(new W(_d)),this.spreadsheet=new bd(this)}init(){this.tableWrapper=document.createElement("div"),this.tableWrapper.style.display="none",this.tableWrapper.style.overflow="auto",this.table=document.createElement("table"),this.table.style.tableLayout="fixed",this.table.style.borderSpacing="0",this.table.style.borderCollapse="collapse",this.tableWrapper.appendChild(this.table),this.display.rootPanel.appendChild(this.tableWrapper),this.table.addEventListener("click",(t=>{const e=t.target;if("TD"===e.tagName){const t=e.parentElement;t.rowIndex>0&&this.spreadsheet.setSelectedRowIndex(t.rowIndex-1)}else this.spreadsheet.setSelectedRowIndex(void 0);this.requestRepaint()})),this.spreadsheet.setContent(this.defaultContent)}draw(t){if(this.tableWrapper){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.tableWrapper.style.backgroundColor="white",this.tableWrapper.style.position="absolute",this.tableWrapper.style.display="block",this.tableWrapper.style.left=`${t}px`,this.tableWrapper.style.top=`${e}px`,this.tableWrapper.style.width=`${i}px`,this.tableWrapper.style.height=`${s}px`,this.tableWrapper.style.border="1px solid rgba(0, 0, 0, 0.1)",this.table.style.font=this.font.getFontString(),this.spreadsheet.dirty&&(this.generateTableContent(),this.spreadsheet.dirty=!1)}}generateTableContent(){for(let t=this.table.rows.length-1;t>=0;t--)this.table.deleteRow(t);if(this.columnHeaderVisible){const t=this.table.insertRow();for(let e=0;e<this.columnsCount;e++){const i=this.columnHeaders[e],s=t.insertCell();s.style.color="#aaa",s.style.textAlign="left",s.style.width=Number(i[1])*this.scale+"px",s.style.overflow="hidden",s.style.padding=4*this.scale+"px",s.style.borderBottom="1px solid rgba(0, 0, 0, 0.1)",0!==e&&(s.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)");const r=document.createTextNode(i[0]);s.appendChild(r)}t.insertCell()}const t=this.spreadsheet.getCells();for(let e=0;e<t.length;e++){const s=t[e],r=e===this.spreadsheet.selectedRowIndex,o=this.table.insertRow();for(let t=0;t<this.columnsCount;t++){const e=o.insertCell();if(e.style.textAlign="left",e.style.overflow="hidden",e.style.wordWrap="break-word",e.style.textOverflow="ellipsis",e.style.padding=4*this.scale+"px",0!==t&&(e.style.borderLeft="1px solid rgba(0, 0, 0, 0.1)"),void 0!==s[t]){const o=r?i.BLUE:s[t].backgroundColor;o&&(e.style.backgroundColor=o.toString());const n=r?i.WHITE:s[t].foregroundColor;n&&(e.style.color=n.toString());const h=document.createTextNode(s[t].text||"");e.appendChild(h)}}o.insertCell()}}hide(){this.tableWrapper&&(this.tableWrapper.style.display="none")}destroy(){this.tableWrapper&&(this.display.rootPanel.removeChild(this.tableWrapper),this.tableWrapper=void 0,this.table=void 0)}get columnsCount(){return this.properties.getValue(Td)}get columnHeaders(){return this.properties.getValue(Sd)}get columnHeaderVisible(){return this.properties.getValue(Vd)}get defaultContent(){return this.properties.getValue(Cd)}get font(){return this.properties.getValue(_d).scale(this.scale)}}class Ld extends ke{constructor(t,e){super(t,e),this.properties.add(new P("url"))}init(){this.iframe=document.createElement("iframe"),this.iframe.src="",this.iframe.style.display="none",this.iframe.style.border="0",this.display.rootPanel.appendChild(this.iframe)}draw(t){if(this.iframe){const{x:t,y:e,width:i,height:s}=this.display.measureAbsoluteArea(this);this.iframe.style.position="absolute",this.iframe.style.display="block",this.iframe.style.left=`${t}px`,this.iframe.style.top=`${e}px`,this.iframe.style.width=`${i}px`,this.iframe.style.height=`${s}px`,this.url&&this.prevUrl!==this.url&&(this.iframe.src=this.url,this.prevUrl=this.url)}}hide(){this.iframe&&(this.iframe.style.display="none")}destroy(){this.iframe&&(this.display.rootPanel.removeChild(this.iframe),this.iframe=void 0)}get url(){return this.properties.getValue("url")}}class Pd{constructor(i){this.targetElement=i,this.repaintRequested=!1,this._editMode=!1,this._showGrid=!1,this._showOutline=!1,this._showRuler=!1,this._selection=[],this._scale=1,this._transparent=!1,this.refreshCycle=100,this.imagesPrefix="",this.absPrefix="",this.relPrefix="",this.eventListeners={closedisplay:[],opendisplay:[],openpv:[],runcommand:[],runprocedure:[],selection:[],scale:[]},this.rootPanel=document.createElement("div"),this.rootPanel.className="display-root",this.rootPanel.style.overflow="hidden",this.rootPanel.style.position="relative",this.rootPanel.style.fontSize="0",i.appendChild(this.rootPanel);const s=document.createElement("canvas");this.rootPanel.appendChild(s),this.g=new V(s),this.ctx=this.g.ctx,this.pvEngine=new yi(this),this.pvEngine.addProvider(new Pi),this.pvEngine.addProvider(new ci),this.displayRegion={id:"display-root",click:()=>{for(const t of this.rootPanel.getElementsByTagName("input"))t.blur();for(const t of this.rootPanel.getElementsByTagName("textarea"))t.blur();for(const t of this.rootPanel.getElementsByTagName("select"))t.blur()}},this.pathResolver=new oi(this),this.consoleHandler=new t,this.dialogHandler=new e,window.setTimeout((()=>this.step())),new n(this,s,this.g.hitCanvas)}addProvider(t){this.pvEngine.addProvider(t)}addScriptLibrary(t,e){this.pvEngine.addScriptLibrary(t,e)}setPathResolver(t){this.pathResolver=t}getPathResolver(){return this.pathResolver}setConsoleHandler(t){this.consoleHandler=t}getConsoleHandler(){return this.consoleHandler}setDialogHandler(t){this.dialogHandler=t}getDialogHandler(){return this.dialogHandler}setFontResolver(t){this.fontResolver=t}getFontResolver(){return this.fontResolver}step(){this.repaintRequested&&(this.g.clearHitCanvas(),this.drawScreen(),this.repaintRequested=!1),window.setTimeout((()=>this.step()),this.refreshCycle)}drawScreen(){var t;if(this.instance?(this.rootPanel.style.height=this.instance.holderHeight+"px",this.rootPanel.style.width=this.instance.holderWidth+"px"):(this.rootPanel.style.height="0px",this.rootPanel.style.width="0px"),this.g.resize(this.rootPanel.clientWidth,this.rootPanel.clientHeight),this.transparent&&this.g.clearCanvas(),this.editMode){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=16,t.height=16,e.fillStyle="#d6d6d6",e.fillRect(0,0,8,8),e.fillRect(8,8,8,8),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.instance&&this.g.fillRect(Object.assign(Object.assign({},this.instance.bounds),{color:this.instance.backgroundColor}))}else this.transparent||this.g.fillCanvas((null===(t=this.instance)||void 0===t?void 0:t.backgroundColor)||i.WHITE);if(this.g.addHitRegion(this.displayRegion).addRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height),this.showGrid&&this.instance){const t=document.createElement("canvas"),e=t.getContext("2d");t.width=25,t.height=25,e.fillStyle=this.instance.foregroundColor.toString(),e.fillRect(0,0,2,1),this.ctx.fillStyle=this.ctx.createPattern(t,"repeat"),this.ctx.fillRect(25,25,this.ctx.canvas.width-50,this.ctx.canvas.height-50)}if(this.showRuler){this.ctx.lineWidth=1,this.ctx.strokeStyle="grey",this.ctx.textBaseline="bottom",this.ctx.textAlign="center",this.ctx.fillStyle="grey",this.ctx.font="12px Arial";let t=0;for(;t<=this.ctx.canvas.width;)t+=100,this.ctx.beginPath(),this.ctx.moveTo(t-75+.5,this.ctx.canvas.height),this.ctx.lineTo(t-75+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t-50+.5,this.ctx.canvas.height),this.ctx.lineTo(t-50+.5,this.ctx.canvas.height-6),this.ctx.moveTo(t-25+.5,this.ctx.canvas.height),this.ctx.lineTo(t-25+.5,this.ctx.canvas.height-4),this.ctx.moveTo(t+.5,this.ctx.canvas.height),this.ctx.lineTo(t+.5,this.ctx.canvas.height-8),this.ctx.stroke(),this.ctx.fillText(String(t),t,this.ctx.canvas.height-8);this.ctx.textAlign="right",this.ctx.textBaseline="middle";let e=0;for(;e<=this.ctx.canvas.height;)e+=100,this.ctx.beginPath(),this.ctx.moveTo(this.ctx.canvas.width,e-75+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-75+.5),this.ctx.moveTo(this.ctx.canvas.width,e-50+.5),this.ctx.lineTo(this.ctx.canvas.width-6,e-50+.5),this.ctx.moveTo(this.ctx.canvas.width,e-25+.5),this.ctx.lineTo(this.ctx.canvas.width-4,e-25+.5),this.ctx.moveTo(this.ctx.canvas.width,e+.5),this.ctx.lineTo(this.ctx.canvas.width-8,e+.5),this.ctx.stroke(),this.ctx.fillText(String(e),this.ctx.canvas.width-8,e)}this.showOutline&&this.instance&&(this.ctx.lineWidth=1,this.ctx.setLineDash([10,5]),this.ctx.strokeStyle="black",this.ctx.strokeRect(-.5,-.5,this.instance.holderWidth+1,this.instance.holderHeight+1),this.ctx.setLineDash([])),this.instance&&this.instance.draw(this.g);for(const t of this.selection){const e=this.findWidget(t);e&&e.drawSelection(this.ctx)}}requestRepaint(){this.repaintRequested=!0}setTooltip(t){var e;this.rootPanel.title=null!==(e=null==t?void 0:t.trim())&&void 0!==e?e:""}createWidget(t,e){switch(t){case"Action Button":return new Ii(this,e);case"Arc":return new Br(this,e);case"Boolean Button":return new Ji(this,e);case"Boolean Switch":return new ds(this,e);case"Byte Monitor":return new Zo(this,e);case"Check Box":return new xs(this,e);case"Choice Button":return new Vs(this,e);case"Combo":case"Combo Box":return new ks(this,e);case"Ellipse":return new Gr(this,e);case"Gauge":return new vn(this,e);case"Grouping Container":return new gd(this,e);case"Image":return new Yr(this,e);case"Image Boolean Button":return new Gs(this,e);case"Image Boolean Indicator":return new Ln(this,e);case"Intensity Graph":return new ah(this,e);case"Label":return new Qr(this,e);case"LED":return new Sh(this,e);case"Linking Container":return new ri(this,e);case"Menu Button":return new qs(this,e);case"Meter":return new qh(this,e);case"Button":return new Ys(this,e);case"Polygon":return new ho(this,e);case"Polyline":return new xo(this,e);case"Progress Bar":return new La(this,e);case"Radio Box":return new sr(this,e);case"Rectangle":return new Ao(this,e);case"Rounded Rectangle":return new Do(this,e);case"Scrollbar":return new fr(this,e);case"Tabbed Container":return new vd(this,e);case"Table":return new Ad(this,e);case"Tank":return new sl(this,e);case"Text Input":return new Ar(this,e);case"Text Update":return new cl(this,e);case"Thermometer":return new Gl(this,e);case"Web Browser":return new Ld(this,e);case"XY Graph":return new ud(this,e);default:console.warn(`Unsupported widget type: ${t}`)}}destroy(){var t;null===(t=this.instance)||void 0===t||t.destroy(),this.instance=void 0,this.pvEngine.clearState(),this.requestRepaint()}resolvePath(t,e){return this.pathResolver.resolve(t,e)}setSource(t,e){this.reset();const i=t.lastIndexOf("/")+1;return this.relPrefix=t.substring(0,i),new Promise(((i,s)=>{fetch(t,{credentials:"same-origin"}).then((t=>{t.ok&&t.text().then((t=>{this.setSourceString(t,e),i()})).catch((t=>s(t)))})).catch((t=>s(t)))}))}setSourceString(t,e){this.reset(),this.instance=new Qe(this,void 0,e);const i=oe.parseFromXML(t);this.instance.parseNode(i),this.pvEngine.init(),this.requestRepaint()}getRefreshCycle(){return this.refreshCycle}setRefreshCycle(t){this.refreshCycle=t}reset(){this.instance&&(this.clearSelection(),this.pvEngine.clearState(),this.instance.destroy(),this.instance=void 0)}measureAbsoluteArea(t){const e=t.bounds;let i=t.parent;for(;i;){if(e.x+=i.x,e.y+=i.y,i instanceof vd){const{x:t,y:s}=i.measureTabOffset(this.g);e.x+=t,e.y+=s}i=i.parent}return e.x+=t.x-t.holderX,e.y+=t.y-t.holderY,e.width+=t.width-t.holderWidth,e.height+=t.height-t.holderHeight,e.x+=1*this.scale,e.y+=1*this.scale,e}addEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t].push(e)}removeEventListener(t,e){if(!(t in this.eventListeners))throw new Error(`Unknown event '${t}'`);this.eventListeners[t]=this.eventListeners[t].filter((t=>t!==e))}fireEvent(t,e){this.eventListeners[t].forEach((t=>t(e)))}get showGrid(){return this._showGrid}set showGrid(t){this._showGrid=t,this.requestRepaint()}get showOutline(){return this._showOutline}set showOutline(t){this._showOutline=t,this.requestRepaint()}get showRuler(){return this._showRuler}set showRuler(t){this._showRuler=t,this.requestRepaint()}get selection(){return this._selection}set selection(t){this._selection=t,this.requestRepaint();const e={selected:this._selection.slice()};this.fireEvent("selection",e)}get editMode(){return this._editMode}set editMode(t){this._editMode=t,this.requestRepaint()}get scale(){return this._scale}set scale(t){this._scale=t,this.requestRepaint();const e={scale:t};this.fireEvent("scale",e)}get transparent(){return this._transparent}set transparent(t){this._transparent=t,this.requestRepaint()}get widgets(){return this.instance?this.instance.widgets:[]}clearSelection(){this.selection.length&&(this.selection=[])}findWidget(t){if(this.instance)return this.instance.findWidget(t)}findWidgetByName(t){if(this.instance)return this.instance.findWidgetByName(t)}getPVNames(){return this.pvEngine.getPVNames()}getPV(t){return this.pvEngine.getPV(t)}setValues(t){this.pvEngine.setValues(t)}copyCanvas(t){t||(t={x:0,y:0,width:this.g.canvas.width,height:this.g.canvas.height});const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,e.getContext("2d").drawImage(this.g.canvas,t.x,t.y,t.width,t.height,0,0,t.width,t.height),e}toDataURL(t="image/png",e){return this.g.ctx.canvas.toDataURL(t,e)}}export{yt as AlarmSeverity,ni as CompiledFormula,t as DefaultConsoleHandler,e as DefaultDialogHandler,oi as DefaultPathResolver,Pd as Display,et as Font,di as FormulaCompiler,wt as PV,ke as Widget};
|
|
2
2
|
//# sourceMappingURL=opi.js.map
|