@node-projects/web-component-designer-visualization-addons 0.1.145 → 0.1.147

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/index-min.js CHANGED
@@ -6,7 +6,7 @@ Blockly.Blocks.console={init:function(){this.appendDummyInput().appendField("con
6
6
  `:t==="STYLE"&&(r+=s+".style["+e+"] = "+i+`;
7
7
  `),r};Blockly.Blocks.set_state={init:function(){this.appendValueInput("OID").setCheck("String").appendField("set_state"),this.appendValueInput("VALUE").setCheck(null).appendField("with"),this.setInputsInline(!0),this.setPreviousStatement(!0,null),this.setNextStatement(!0,null),this.setColour(230)}};Blockly.JavaScript.forBlock.set_state=function(n){let t=Blockly.JavaScript.valueToCode(n,"OID",Blockly.JavaScript.ORDER_ATOMIC),s=Blockly.JavaScript.valueToCode(n,"VALUE",Blockly.JavaScript.ORDER_ATOMIC);return`await visualizationHandler.setState((${t}[0] === '.' ? relativeSignalsPath : '') + ${t}, ${s});
8
8
  `};Blockly.defineBlocksWithJsonArray([{type:"start_event",message0:"Event %1",nextStatement:null,style:"hat_blocks",args0:[{type:"field_variable",name:"EVENTVAR",variable:"event"}]}]);Blockly.JavaScript.forBlock.start_event=function(n){return Blockly.JavaScript.getVariableName(n.getField("EVENTVAR").variable.name)+` = eventData;
9
- `};var ge=`function extractPart(obj, propertyPath) {
9
+ `};var Pe=`function extractPart(obj, propertyPath) {
10
10
  let retVal = obj;
11
11
  for (let p of propertyPath.split('.')) {
12
12
  retVal = retVal?.[p];
@@ -21,16 +21,16 @@ function delay(ms) {
21
21
  }
22
22
 
23
23
  export async function run(eventData, shadowRoot, parameters, relativeSignalsPath, visualizationHandler, context) {
24
- `,ye="}";async function G(n){let t=new Blockly.Workspace;Blockly.serialization.workspaces.load(n,t),Blockly.JavaScript.addReservedWords("eventData"),Blockly.JavaScript.addReservedWords("shadowRoot"),Blockly.JavaScript.addReservedWords("extractPart"),Blockly.JavaScript.addReservedWords("parameters"),Blockly.JavaScript.addReservedWords("relativeSignalsPath"),Blockly.JavaScript.addReservedWords("delay"),Blockly.JavaScript.addReservedWords("visualizationHandler"),Blockly.JavaScript.addReservedWords("context");let s=Blockly.JavaScript.workspaceToCode(t);return(await import(URL.createObjectURL(new Blob([ge+s+ye],{type:"application/javascript"})))).run}import{BaseCustomWebComponentConstructorAppend as fe,html as ve,css as be}from"@node-projects/base-custom-webcomponent";var C=class n extends fe{static template=ve`
24
+ `,Fe="}";async function fe(n){let t=new Blockly.Workspace;Blockly.serialization.workspaces.load(n,t),Blockly.JavaScript.addReservedWords("eventData"),Blockly.JavaScript.addReservedWords("shadowRoot"),Blockly.JavaScript.addReservedWords("extractPart"),Blockly.JavaScript.addReservedWords("parameters"),Blockly.JavaScript.addReservedWords("relativeSignalsPath"),Blockly.JavaScript.addReservedWords("delay"),Blockly.JavaScript.addReservedWords("visualizationHandler"),Blockly.JavaScript.addReservedWords("context");let s=Blockly.JavaScript.workspaceToCode(t);return(await import(URL.createObjectURL(new Blob([Pe+s+Fe],{type:"application/javascript"})))).run}import{BaseCustomWebComponentConstructorAppend as He,html as Je,css as Ue}from"@node-projects/base-custom-webcomponent";var A=class n extends He{static template=Je`
25
25
  <div id="blocklyDiv" style="position: absolute; width: 100%; height: 100%;"></div>
26
- `;static style=be`
26
+ `;static style=Ue`
27
27
  :host {
28
28
  box-sizing: border-box;
29
29
  position: absolute;
30
30
  height: 100%;
31
31
  width: 100%;
32
32
  display: block;
33
- }`;static is="node-projects-blockly-script-editor";blocklyDiv;workspace;static blocklyStyle1;static blocklyStyle2;resizeObserver;_toolbox;constructor(t){super(),super._restoreCachedInititalValues(),this._toolbox=t,this.blocklyDiv=this._getDomElement("blocklyDiv"),this._assignEvents(),this.createBlockly()}createBlockly(){let t="zelos",s="webui",e=Blockly.Theme.defineTheme(s,{base:Blockly.Themes.Zelos,blockStyles:{hat_blocks:{colourPrimary:"#4a148c"}},categoryStyles:{start_category:{colour:"#4a148c"},system_category:{colour:"#01579b"}}});this.workspace=Blockly.inject(this.blocklyDiv,{theme:e,toolbox:this._toolbox,renderer:t,trashcan:!0,zoom:{controls:!0,wheel:!1,startScale:.7,maxScale:3,minScale:.3,scaleSpeed:1.2,pinch:!1},move:{scrollbars:{horizontal:!0,vertical:!0},drag:!0,wheel:!0},maxInstances:{start_event:1}}),n.blocklyStyle1||(n.blocklyStyle1=new CSSStyleSheet,n.blocklyStyle1.replaceSync(document.getElementById("blockly-renderer-style-"+t+"-"+s).innerText),n.blocklyStyle2=new CSSStyleSheet,n.blocklyStyle2.replaceSync(document.getElementById("blockly-common-style").innerText)),this.shadowRoot.adoptedStyleSheets=[n.blocklyStyle1,n.blocklyStyle2,n.style],new ZoomToFitControl(this.workspace).init()}ready(){Blockly.svgResize(this.workspace),this.resizeObserver=new ResizeObserver(t=>{Blockly.svgResize(this.workspace)}),this.resizeObserver.observe(this)}save(){return Blockly.serialization.workspaces.save(this.workspace)}load(t){Blockly.serialization.workspaces.load(t,this.workspace)}};customElements.define(C.is,C);import{BaseCustomWebComponentConstructorAppend as Se,html as _e,css as Te}from"@node-projects/base-custom-webcomponent";import{BindingMode as Ce,BindingTarget as $}from"@node-projects/web-component-designer";import{BaseCustomWebComponentConstructorAppend as xe,html as we,css as ke}from"@node-projects/base-custom-webcomponent";var E=class extends xe{static template=we`
33
+ }`;static is="node-projects-blockly-script-editor";blocklyDiv;workspace;static blocklyStyle1;static blocklyStyle2;resizeObserver;_toolbox;constructor(t){super(),super._restoreCachedInititalValues(),this._toolbox=t,this.blocklyDiv=this._getDomElement("blocklyDiv"),this._assignEvents(),this.createBlockly()}createBlockly(){let t="zelos",s="webui",e=Blockly.Theme.defineTheme(s,{base:Blockly.Themes.Zelos,blockStyles:{hat_blocks:{colourPrimary:"#4a148c"}},categoryStyles:{start_category:{colour:"#4a148c"},system_category:{colour:"#01579b"}}});this.workspace=Blockly.inject(this.blocklyDiv,{theme:e,toolbox:this._toolbox,renderer:t,trashcan:!0,zoom:{controls:!0,wheel:!1,startScale:.7,maxScale:3,minScale:.3,scaleSpeed:1.2,pinch:!1},move:{scrollbars:{horizontal:!0,vertical:!0},drag:!0,wheel:!0},maxInstances:{start_event:1}}),n.blocklyStyle1||(n.blocklyStyle1=new CSSStyleSheet,n.blocklyStyle1.replaceSync(document.getElementById("blockly-renderer-style-"+t+"-"+s).innerText),n.blocklyStyle2=new CSSStyleSheet,n.blocklyStyle2.replaceSync(document.getElementById("blockly-common-style").innerText)),this.shadowRoot.adoptedStyleSheets=[n.blocklyStyle1,n.blocklyStyle2,n.style],new ZoomToFitControl(this.workspace).init()}ready(){Blockly.svgResize(this.workspace),this.resizeObserver=new ResizeObserver(t=>{Blockly.svgResize(this.workspace)}),this.resizeObserver.observe(this)}save(){return Blockly.serialization.workspaces.save(this.workspace)}load(t){Blockly.serialization.workspaces.load(t,this.workspace)}};customElements.define(A.is,A);import{BaseCustomWebComponentConstructorAppend as qe,html as Ye,css as Ze}from"@node-projects/base-custom-webcomponent";import{BindingMode as Ke,BindingTarget as ye}from"@node-projects/web-component-designer";import{BaseCustomWebComponentConstructorAppend as $e,html as Ge,css as Xe}from"@node-projects/base-custom-webcomponent";var D=class extends $e{static template=Ge`
34
34
  <span style="position:absolute;left:30px;top:26px;">from</span>
35
35
  <span style="position:absolute;left:30px;top:77px;">count</span>
36
36
  <span style="position:absolute;left:30px;top:123px;">limit</span>
@@ -97,10 +97,10 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
97
97
  <input css:visibility="[[this.historic.aggregate == 'quantile' ? 'visible' : 'collapse']]" value="{{this.historic.quantile}}" type="number" id="quantile" style="position:absolute;left:107px;top:325px;width:153px;">
98
98
  <span css:visibility="[[this.historic.aggregate == 'quantile' ? 'visible' : 'collapse']]" id="lblQuantile" style="position:absolute;left:30px;top:325px;">quantile</span>
99
99
  <span style="position:absolute;left:34px;top:417px;">instance</span>
100
- <input type="text" value="{{?this.historic.instance}}" style="position:absolute;left:104px;top:419px;width:155px;">`;static style=ke`
100
+ <input type="text" value="{{?this.historic.instance}}" style="position:absolute;left:104px;top:419px;width:155px;">`;static style=Xe`
101
101
  :host {
102
102
  box-sizing: border-box;
103
- }`;static is="node-projects-visualization-bindings-editor-historic";historic;static properties={historic:Object};constructor(t){super(),this._restoreCachedInititalValues(),this.historic=t??{reloadInterval:2e3}}ready(){this._bindingsParse()}#e=!1;refresh(){this.#e||(this.#e=!0,this._bindingsRefresh(null,!0),this.#e=!1)}};customElements.define(E.is,E);var D=class extends Se{static template=_e`
103
+ }`;static is="node-projects-visualization-bindings-editor-historic";historic;static properties={historic:Object};constructor(t){super(),this._restoreCachedInititalValues(),this.historic=t??{reloadInterval:2e3}}ready(){this._bindingsParse()}#e=!1;refresh(){this.#e||(this.#e=!0,this._bindingsRefresh(null,!0),this.#e=!1)}};customElements.define(D.is,D);var K=class extends qe{static template=Ye`
104
104
  <div id="root">
105
105
  <div class="vertical-grid">
106
106
  <div style="grid-column: 1/3">
@@ -183,7 +183,7 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
183
183
  </button>
184
184
  </div>
185
185
  </div>
186
- </div>`;static style=Te`
186
+ </div>`;static style=Ze`
187
187
  :host {
188
188
  box-sizing: border-box;
189
189
  }
@@ -256,53 +256,581 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
256
256
 
257
257
  node-projects-code-view-monaco[readonly] {
258
258
  border: 1px lightgray solid;
259
- }`;static is="node-projects-visualization-bindings-editor";static properties={twoWayPossible:Boolean,twoWay:Boolean,expression:String,objectNames:String,events:String,invert:Boolean,converters:Array,historic:Object};twoWayPossible=!1;twoWay=!1;expression="";writeBackSignal="";expressionTwoWay="";historic;objectNames="";events="";invert=!1;converters=[];convertersString;objectValueType;_property;_binding;_bindingTarget;_serviceContainer;_instanceServiceContainer;_shell;_activeRow=-1;_objNmInput;constructor(t,s,e,i,r,o,a={namedConverters:!0}){super(),super._restoreCachedInititalValues(),this._objNmInput=this._getDomElement("objectName"),this._property=t,this._binding=s,this._bindingTarget=e,this._serviceContainer=i,this._instanceServiceContainer=r,this._shell=o,a?.namedConverters||(this._getDomElement("namedConverterInput").style.display="none")}ready(){if(this._parseAttributesToProperties(),this._assignEvents(),this.twoWayPossible=!1,(this._bindingTarget==$.property||this._bindingTarget==$.attribute)&&(this.twoWayPossible=!0),this._binding){if(this.twoWay=this._binding.mode==Ce.twoWay,this.expression=this._binding.expression,this.writeBackSignal=this._binding.writeBackSignal,this.expressionTwoWay=this._binding.expressionTwoWay,this.historic=this._binding.historic,this.invert=this._binding.invert,this.objectValueType=this._binding.type,this._binding.bindableObjectNames&&(this.objectNames=this._binding.bindableObjectNames.join(";")),this._binding.converter)if(typeof this._binding.converter=="string")this.convertersString=this._binding.converter;else for(let t in this._binding.converter)this.converters.push({key:t,value:this._binding.converter[t]});this._binding.changedEvents&&this._binding.changedEvents.length&&(this.events=this._binding.changedEvents.join(";"))}if(this.expression){let t=this._getDomElement("expression");this.expression.indexOf(`
259
+ }`;static is="node-projects-visualization-bindings-editor";static properties={twoWayPossible:Boolean,twoWay:Boolean,expression:String,objectNames:String,events:String,invert:Boolean,converters:Array,historic:Object};twoWayPossible=!1;twoWay=!1;expression="";writeBackSignal="";expressionTwoWay="";historic;objectNames="";events="";invert=!1;converters=[];convertersString;objectValueType;_property;_binding;_bindingTarget;_serviceContainer;_instanceServiceContainer;_shell;_activeRow=-1;_objNmInput;constructor(t,s,e,i,r,c,a={namedConverters:!0}){super(),super._restoreCachedInititalValues(),this._objNmInput=this._getDomElement("objectName"),this._property=t,this._binding=s,this._bindingTarget=e,this._serviceContainer=i,this._instanceServiceContainer=r,this._shell=c,a?.namedConverters||(this._getDomElement("namedConverterInput").style.display="none")}ready(){if(this._parseAttributesToProperties(),this._assignEvents(),this.twoWayPossible=!1,(this._bindingTarget==ye.property||this._bindingTarget==ye.attribute)&&(this.twoWayPossible=!0),this._binding){if(this.twoWay=this._binding.mode==Ke.twoWay,this.expression=this._binding.expression,this.writeBackSignal=this._binding.writeBackSignal,this.expressionTwoWay=this._binding.expressionTwoWay,this.historic=this._binding.historic,this.invert=this._binding.invert,this.objectValueType=this._binding.type,this._binding.bindableObjectNames&&(this.objectNames=this._binding.bindableObjectNames.join(";")),this._binding.converter)if(typeof this._binding.converter=="string")this.convertersString=this._binding.converter;else for(let t in this._binding.converter)this.converters.push({key:t,value:this._binding.converter[t]});this._binding.changedEvents&&this._binding.changedEvents.length&&(this.events=this._binding.changedEvents.join(";"))}if(this.expression){let t=this._getDomElement("expression");this.expression.indexOf(`
260
260
  `)>=0&&(t.style.height="51px")}if(this.expressionTwoWay){let t=this._getDomElement("expression2way");this.expressionTwoWay.indexOf(`
261
- `)>=0&&(t.style.height="51px")}this._bindingsParse(),this._objNmInput.focus()}_focusRow(t){this._activeRow=t,this._updatefocusedRow()}_updatefocusedRow(){let t=this._getDomElement("converterGrid");t.querySelectorAll("div").forEach(s=>s.style.background=""),this._activeRow>=0&&(t.children[this._activeRow+1].style.background="gray")}_clear(){this.objectNames="",this._bindingsRefresh()}_refresh(){requestAnimationFrame(()=>{this._bindingsRefresh()})}async _select(){let t=this._shell.createBindableObjectBrowser();t.initialize(this._serviceContainer,this._instanceServiceContainer,"binding"),t.title="select signal...";let s=new AbortController;t.objectDoubleclicked.on(()=>{s.abort(),this.objectNames!=""&&(this.objectNames+=";"),t.selectedObject.specialType=="signalProperty"?this.objectNames+="?":t.selectedObject.bindabletype==="property"&&(this.objectNames+="??"),this.objectNames+=t.selectedObject.fullName,this._bindingsRefresh()}),await this._shell.openConfirmation(t,{x:100,y:100,width:400,height:300,parent:this,abortSignal:s.signal})&&(this.objectNames!=""&&(this.objectNames+=";"),this.objectNames+=t.selectedObject.fullName,this._bindingsRefresh())}async showHistoric(){let t=new E(this.historic),s=new AbortController;t.title="Edit historic binding to: "+this._property.name,await this._shell.openConfirmation(t,{x:100,y:100,width:420,height:510,parent:this,abortSignal:s.signal,disableResize:!0,cancelText:"Remove"})?this.historic=t.historic:this.historic=null,this._bindingsRefresh()}addConverter(){this.converters.push({key:"",value:""}),this._activeRow=this.converters.length-1,this._bindingsRefresh(),this._updatefocusedRow()}removeConverter(){this.converters.splice(this._activeRow,1),this._activeRow=-1,this._bindingsRefresh(),this._updatefocusedRow()}};customElements.define(D.is,D);import{BaseCustomWebComponentConstructorAppend as Ne,css as Oe,html as Ie}from"@node-projects/base-custom-webcomponent";import{ContextMenu as Y}from"@node-projects/web-component-designer";import{typeInfoFromJsonSchema as Z}from"@node-projects/propertygrid.webcomponent";import{defaultOptions as Be}from"@node-projects/web-component-designer-widgets-wunderbaum";import{Wunderbaum as Re}from"wunderbaum";import Ve from"wunderbaum/dist/wunderbaum.css"with{type:"css"};import{PropertyGrid as Ee}from"@node-projects/propertygrid.webcomponent";import{CodeViewMonaco as q}from"@node-projects/web-component-designer-codeview-monaco";var j=class extends Ee{serviceContainer;instanceServiceContainer;visualizationHandler;visualizationShell;bindableObjectsTarget="property";constructor(){super()}bindingDoubleClicked;async getEditorForType(t,s,e,i,r){if(this.getSpecialEditorForType){let o=await this.getSpecialEditorForType(t,s,e,i,r);if(o)return o}switch(t.format){case"screen":{let o=document.createElement("select");o.style.width="100%";let a=document.createElement("option");a.value=s??"",a.innerText=s??"",o.appendChild(a);for(let l of await this.visualizationHandler.getAllNames("screen")){if(l==s)continue;let c=document.createElement("option");c.value=l,c.innerText=l,o.appendChild(c)}return o.onchange=()=>{this.setPropertyValue(e,o.value)},o.value=s,o}case"signal":{let o=document.createElement("div");o.style.display="flex";let a=document.createElement("input");a.value=s??"",a.style.flexGrow="1",a.style.width="0",a.onchange=c=>this.setPropertyValue(e,a.value),a.onfocus=c=>{a.selectionStart=0,a.selectionEnd=a.value?.length},o.appendChild(a);let l=document.createElement("button");return l.textContent="...",l.onclick=async()=>{let c=this.visualizationShell.createBindableObjectBrowser();c.initialize(this.serviceContainer,this.instanceServiceContainer,this.bindableObjectsTarget),c.title="select signal...";let p=new AbortController;c.objectDoubleclicked.on(()=>{this.bindingDoubleClicked&&this.bindingDoubleClicked(c.selectedObject),p.abort(),a.value=c.selectedObject.fullName,this.setPropertyValue(e,a.value)}),await this.visualizationShell.openConfirmation(c,{x:100,y:100,width:400,height:300,parent:this,abortSignal:p.signal})&&(a.value=c.selectedObject.fullName,this.setPropertyValue(e,a.value))},o.appendChild(l),o}case"html":case"script":{let o=document.createElement("div");o.style.boxSizing="border-box",o.style.width="100%",o.style.display="flex";let a=document.createElement("textarea");a.style.boxSizing="border-box",a.value=s??"",a.style.width="100%",a.onblur=c=>{this.setPropertyValue(e,a.value)},o.appendChild(a);let l=document.createElement("button");return l.innerHTML="...",l.style.boxSizing="border-box",l.onclick=async()=>{let c=new q,p=await q.getMonacoLib();if(t.format=="html")c.language="html";else{let m={content:`declare global {
261
+ `)>=0&&(t.style.height="51px")}this._bindingsParse(),this._objNmInput.focus()}_focusRow(t){this._activeRow=t,this._updatefocusedRow()}_updatefocusedRow(){let t=this._getDomElement("converterGrid");t.querySelectorAll("div").forEach(s=>s.style.background=""),this._activeRow>=0&&(t.children[this._activeRow+1].style.background="gray")}_clear(){this.objectNames="",this._bindingsRefresh()}_refresh(){requestAnimationFrame(()=>{this._bindingsRefresh()})}async _select(){let t=this._shell.createBindableObjectBrowser();t.initialize(this._serviceContainer,this._instanceServiceContainer,"binding"),t.title="select signal...";let s=new AbortController;t.objectDoubleclicked.on(()=>{s.abort(),this.objectNames!=""&&(this.objectNames+=";"),t.selectedObject.specialType=="signalProperty"?this.objectNames+="?":t.selectedObject.bindabletype==="property"&&(this.objectNames+="??"),this.objectNames+=t.selectedObject.fullName,this._bindingsRefresh()}),await this._shell.openConfirmation(t,{x:100,y:100,width:400,height:300,parent:this,abortSignal:s.signal})&&(this.objectNames!=""&&(this.objectNames+=";"),this.objectNames+=t.selectedObject.fullName,this._bindingsRefresh())}async showHistoric(){let t=new D(this.historic),s=new AbortController;t.title="Edit historic binding to: "+this._property.name,await this._shell.openConfirmation(t,{x:100,y:100,width:420,height:510,parent:this,abortSignal:s.signal,disableResize:!0,cancelText:"Remove"})?this.historic=t.historic:this.historic=null,this._bindingsRefresh()}addConverter(){this.converters.push({key:"",value:""}),this._activeRow=this.converters.length-1,this._bindingsRefresh(),this._updatefocusedRow()}removeConverter(){this.converters.splice(this._activeRow,1),this._activeRow=-1,this._bindingsRefresh(),this._updatefocusedRow()}};customElements.define(K.is,K);import{BaseCustomWebComponentConstructorAppend as lt,TypedEvent as ct,css as pt,html as dt}from"@node-projects/base-custom-webcomponent";import{ContextMenu as ut,assetsPath as pe}from"@node-projects/web-component-designer";import{typeInfoFromJsonSchema as _e}from"@node-projects/propertygrid.webcomponent";import{defaultOptions as ht,defaultStyle as mt}from"@node-projects/web-component-designer-widgets-wunderbaum";import{Wunderbaum as gt}from"wunderbaum";import ft from"wunderbaum/dist/wunderbaum.css"with{type:"css"};import{PropertyGrid as Qe}from"@node-projects/propertygrid.webcomponent";import{CodeViewMonaco as ve}from"@node-projects/web-component-designer-codeview-monaco";var X=class extends Qe{serviceContainer;instanceServiceContainer;visualizationHandler;visualizationShell;bindableObjectsTarget="property";constructor(){super()}bindingDoubleClicked;setNameColumnWidth(t){let s=this._tree?.columns?.[0];s&&(s.width=t+"px",this._tree.update("colStructure"))}async getEditorForType(t,s,e,i,r){if(this.getSpecialEditorForType){let c=await this.getSpecialEditorForType(t,s,e,i,r);if(c)return c}switch(t.format){case"screen":{let c=document.createElement("select");c.style.width="100%";let a=document.createElement("option");a.value=s??"",a.innerText=s??"",c.appendChild(a);for(let l of await this.visualizationHandler.getAllNames("screen")){if(l==s)continue;let o=document.createElement("option");o.value=l,o.innerText=l,c.appendChild(o)}return c.onchange=()=>{this.setPropertyValue(e,c.value)},c.value=s,c}case"signal":{let c=document.createElement("div");c.style.display="flex";let a=document.createElement("input");a.value=s??"",a.style.flexGrow="1",a.style.width="0",a.onchange=o=>this.setPropertyValue(e,a.value),a.onfocus=o=>{a.selectionStart=0,a.selectionEnd=a.value?.length},c.appendChild(a);let l=document.createElement("button");return l.textContent="...",l.onclick=async()=>{let o=this.visualizationShell.createBindableObjectBrowser();o.initialize(this.serviceContainer,this.instanceServiceContainer,this.bindableObjectsTarget),o.title="select signal...";let p=new AbortController;o.objectDoubleclicked.on(()=>{this.bindingDoubleClicked&&this.bindingDoubleClicked(o.selectedObject),p.abort(),a.value=o.selectedObject.fullName,this.setPropertyValue(e,a.value)}),await this.visualizationShell.openConfirmation(o,{x:100,y:100,width:400,height:300,parent:this,abortSignal:p.signal})&&(a.value=o.selectedObject.fullName,this.setPropertyValue(e,a.value))},c.appendChild(l),c}case"html":case"script":{let c=document.createElement("div");c.style.boxSizing="border-box",c.style.width="100%",c.style.display="flex";let a=document.createElement("textarea");a.style.boxSizing="border-box",a.value=s??"",a.style.width="100%",a.onblur=o=>{this.setPropertyValue(e,a.value)},c.appendChild(a);let l=document.createElement("button");return l.innerHTML="...",l.style.boxSizing="border-box",l.onclick=async()=>{let o=new ve,p=await ve.getMonacoLib();if(t.format=="html")o.language="html";else{let h={content:`declare global {
262
262
  var context: { event: Event, element: Element };
263
- }`,filePath:"global.d.ts"};p.languages.typescript.typescriptDefaults.setExtraLibs([m]),c.language="javascript"}c.code=a.value,c.style.position="relative",await this.visualizationShell.openConfirmation(c,{x:200,y:200,width:600,height:400,parent:this})&&(a.value=c.getText(),this.setPropertyValue(e,a.value))},o.appendChild(l),o}}return super.getEditorForType(t,s,e,i,r)}};customElements.define("node-projects-visualization-property-grid",j);import"@node-projects/splitview.webcomponent";var N=class n{static upgradeScriptCommand(t){return t.type==="SetElementProperty"?n.upgradeSetElementProperty(t):t}static upgradeSetElementProperty(t){return t.targetSelectorTarget==="currentScreen"?t.targetSelectorTarget="container":t.targetSelectorTarget==="parentScreen"?(t.targetSelectorTarget="container",t.parentIndex=1):t.targetSelectorTarget==="currentElement"?t.targetSelectorTarget="element":t.targetSelectorTarget==="parentElement"&&(t.targetSelectorTarget="element",t.parentIndex=1),t}};var O=class n extends Ne{static style=Oe`
263
+ }`,filePath:"global.d.ts"};p.languages.typescript.typescriptDefaults.setExtraLibs([h]),o.language="javascript"}o.code=a.value,o.style.position="relative",await this.visualizationShell.openConfirmation(o,{x:200,y:200,width:600,height:400,parent:this})&&(a.value=o.getText(),this.setPropertyValue(e,a.value))},c.appendChild(l),c}}return super.getEditorForType(t,s,e,i,r)}};customElements.define("node-projects-visualization-property-grid",X);import{CodeViewMonaco as ke}from"@node-projects/web-component-designer-codeview-monaco";import{BaseCustomWebComponentConstructorAppend as tt,TypedEvent as be,css as st,html as it}from"@node-projects/base-custom-webcomponent";import{defaultOptions as at,defaultStyle as nt}from"@node-projects/web-component-designer-widgets-wunderbaum";import{Wunderbaum as ot}from"wunderbaum";import rt from"wunderbaum/dist/wunderbaum.css"with{type:"css"};function et(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function I(n){return et(n).replace(/("(?:\\.|[^"\\])*")(\s*:)?|\b(true|false|null)\b|\b(-?\d+(?:\.\d+)?)\b/g,(s,e,i,r,c)=>e?`<span class="${i?"cs-key":"cs-str"}">${e}</span>${i??""}`:r?`<span class="cs-bool">${r}</span>`:c?`<span class="cs-num">${c}</span>`:s)}var z=class n extends tt{static style=st`
264
264
  :host {
265
+ display: block;
265
266
  background: white;
266
267
  }
267
- .list{
268
- display: grid;
269
- grid-template-columns: 1fr 40px;
270
- width: calc(100% - 6px);
268
+
269
+ .root {
270
+ width: calc(100% - 8px);
271
+ height: calc(100% - 8px);
272
+ margin: 4px;
271
273
  box-sizing: border-box;
272
- margin: 3px;
274
+ display: flex;
275
+ flex-direction: column;
273
276
  }
274
277
 
275
- .list button{
276
- padding: 5px 10px;
278
+ #filter {
279
+ width: 100%;
280
+ height: 26px;
277
281
  box-sizing: border-box;
282
+ }
283
+
284
+ .content {
285
+ flex: 1 1 auto;
286
+ min-height: 0;
278
287
  display: flex;
279
- justify-content: center;
280
- margin-right: 5px;
281
- margin-left: 5px;
282
288
  }
283
289
 
284
- node-projects-visualization-property-grid {
290
+ #commandList {
291
+ width: 40%;
292
+ overflow: auto;
293
+ box-sizing: border-box;
294
+ }
295
+
296
+ #description {
297
+ width: 60%;
298
+ }
299
+
300
+ .detail {
301
+ padding: 8px;
302
+ overflow: auto;
303
+ box-sizing: border-box;
304
+ }
305
+
306
+ .cmd-title {
307
+ font-size: 14px;
308
+ font-weight: bold;
309
+ color: #24405c;
310
+ border-bottom: 2px solid #2c6e9b;
311
+ padding-bottom: 4px;
312
+ margin-bottom: 6px;
313
+ }
314
+
315
+ .cmd-title .hint {
316
+ font-size: 11px;
317
+ font-weight: normal;
318
+ color: #808080;
319
+ margin-left: 6px;
320
+ }
321
+
322
+ .snippet {
323
+ font-family: Consolas, "Courier New", monospace;
324
+ font-size: 11px;
325
+ background: #f6f8fa;
326
+ color: #24292e;
327
+ border: 1px solid #e1e4e8;
328
+ border-radius: 4px;
329
+ padding: 6px 10px;
330
+ white-space: pre;
331
+ overflow-x: auto;
332
+ line-height: 1.5;
333
+ }
334
+
335
+ .cs-key { color: #22863a; }
336
+ .cs-str { color: #032f62; }
337
+ .cs-bool { color: #d73a49; }
338
+ .cs-num { color: #e36209; }
339
+
340
+ .note {
341
+ font-size: 11px;
342
+ color: #666;
343
+ font-style: italic;
344
+ margin-top: 6px;
345
+ }
346
+
347
+ .toolbar {
348
+ display: flex;
349
+ align-items: center;
350
+ gap: 8px;
351
+ box-sizing: border-box;
352
+ flex: 0 0 auto;
285
353
  width: 100%;
286
- height: 100%;
354
+ height: 40px;
355
+ padding: 4px 8px;
356
+ border-top: 1px solid #ccc;
357
+ background-color: rgb(230, 230, 230);
287
358
  }
288
- `;static template=Ie`
289
- <div style="width:100%; height:100%; overflow: hidden;">
290
- <node-projects-split-view style="height: 100%; width: 100%; position: relative;" orientation="horizontal">
291
- <div style="width: 40%; position: relative;">
292
- <div style="width:calc(100% - 4px); height:calc(100% - 4px)">
293
- <div id="commandList" style="overflow-x: hidden; overflow-y: auto; width:100%; height: calc(100% - 34px);"></div>
294
- <div class="list">
295
- <select id="possibleCommands" style="width: 100%"></select>
296
- <button @click="[[this.addItem()]]">Add</button>
297
- </div>
298
- </div>
299
- </div>
300
- <div style="width: 60%; position: relative;">
301
- <node-projects-visualization-property-grid id="propertygrid"></node-projects-visualization-property-grid>
302
- </div>
303
- </node-projects-split-view>
359
+
360
+ .toolbar button {
361
+ box-sizing: border-box;
362
+ padding: 6px 16px;
363
+ border-radius: 4px;
364
+ border: 1px solid #b0b0b0;
365
+ background: white;
366
+ font-size: 12px;
367
+ cursor: pointer;
368
+ }
369
+
370
+ .toolbar button:hover:not(:disabled) {
371
+ background: #f0f0f0;
372
+ border-color: #909090;
373
+ }
374
+
375
+ .toolbar button:active:not(:disabled) {
376
+ background: #e2e2e2;
377
+ }
378
+
379
+ .toolbar button:disabled {
380
+ opacity: 0.5;
381
+ cursor: not-allowed;
382
+ }
383
+
384
+ .toolbar button.primary {
385
+ background: #2c6e9b;
386
+ border-color: #2c6e9b;
387
+ color: white;
388
+ }
389
+
390
+ .toolbar button.primary:hover:not(:disabled) {
391
+ background: #255d83;
392
+ border-color: #255d83;
393
+ }
394
+
395
+ .toolbar button.primary:active:not(:disabled) {
396
+ background: #1e4d6b;
397
+ }
398
+
399
+ .toolbar .spacer {
400
+ flex: 1 1 auto;
401
+ }
402
+
403
+ .toolbar .hint {
404
+ font-size: 11px;
405
+ font-style: italic;
406
+ color: #666;
407
+ }
408
+ `;static template=it`
409
+ <div class="root">
410
+ <input id="filter" placeholder="Filter..." autocomplete="off">
411
+ <div class="content">
412
+ <div id="commandList"></div>
413
+ <div id="description" class="detail"></div>
414
+ </div>
415
+ <div class="toolbar">
416
+ <button id="addBtn" class="primary" disabled @click="[[this.addClicked()]]">Add</button>
417
+ <span class="hint">or drag a command into the script list</span>
418
+ <span class="spacer"></span>
419
+ <button id="closeBtn" @click="[[this.closeClicked()]]">Close</button>
420
+ </div>
304
421
  </div>
305
- `;static is="node-projects-visualization-simple-script-editor";serviceContainer;instanceServiceContainer;visualizationHandler;visualizationShell;scriptCommandsTypeInfo;propertiesTypeInfo;_script;_commandListDiv;_commandListFancyTree;_possibleCommands;_propertygrid;constructor(){super(),this._restoreCachedInititalValues(),this._commandListDiv=this._getDomElement("commandList"),this._possibleCommands=this._getDomElement("possibleCommands"),this._propertygrid=this._getDomElement("propertygrid"),this.shadowRoot.adoptedStyleSheets=[Ve,n.style]}async ready(){this.addPossibleCommands(),this._parseAttributesToProperties(),this._bindingsParse(null,!0),this._assignEvents();let t=async s=>{let e=new j;e.visualizationHandler=this.visualizationHandler,e.visualizationShell=this.visualizationShell,e.serviceContainer=this.serviceContainer,e.instanceServiceContainer=this.instanceServiceContainer,e.bindableObjectsTarget="script",e.getTypeInfo=(r,o)=>Z(this.propertiesTypeInfo,r,o),e.showHead=!1,e.typeName="IScriptMultiplexValue",e.title='Complex for "'+s.propertyPath+'"',typeof s.value=="object"?e.selectedObject=s.value??{}:e.selectedObject={},e.bindingDoubleClicked=r=>{r.bindabletype=="property"?e.setPropertyValue("source","property"):r.bindabletype=="context"?e.setPropertyValue("source","context"):e.setPropertyValue("source","signal"),e.setPropertyValue("name",r.fullName),e.refresh()},await this.visualizationShell.openConfirmation(e,{x:100,y:100,width:400,height:500,parent:this})&&(this._propertygrid.setPropertyValue(s.propertyPath,e.selectedObject),this._propertygrid.refresh())};this._propertygrid.visualizationHandler=this.visualizationHandler,this._propertygrid.visualizationShell=this.visualizationShell,this._propertygrid.serviceContainer=this.serviceContainer,this._propertygrid.instanceServiceContainer=this.instanceServiceContainer,this._propertygrid.bindableObjectsTarget="script",this._propertygrid.getTypeInfo=(s,e)=>Z(this.scriptCommandsTypeInfo,s,e),this._propertygrid.getSpecialEditorForType=async(s,e,i,r,o)=>{if(!s.specialAllreadyAdded&&(s.specialAllreadyAdded=!0,s.format!=="collection"))if(typeof e=="object"&&e!==null||s.format==="complex"){let a=document.createElement("button");a.style.height="calc(100% - 6px)",a.style.position="relative",a.style.display="flex",a.style.justifyContent="center",a.style.width="20px",a.style.boxSizing="content-box",a.innerText="del",a.onclick=()=>{this._propertygrid.setPropertyValue(i,void 0),this._propertygrid.refresh()},r.nodeElem.insertAdjacentElement("afterbegin",a);let l=document.createElement("div");l.style.display="flex";let c=document.createElement("span");e?c.innerText=(e.source??"")+": "+(e.name??""):c.innerText="",c.style.overflow="hidden",c.style.whiteSpace="nowrap",c.style.textOverflow="ellipsis",c.style.flexGrow="1",c.title=JSON.stringify(e),l.appendChild(c);let p=document.createElement("button");return p.innerText="...",p.onclick=()=>{t({value:e,propertyPath:i})},l.appendChild(p),r.nodeElem.style.display="flex",l}else{let a=document.createElement("button");a.style.height="calc(100% - 6px)",a.style.position="relative",a.style.display="flex",a.style.justifyContent="center",a.style.width="20px",a.style.boxSizing="content-box",a.title="complex property value",a.style.opacity="0.2",a.innerText="...",a.onclick=()=>{t({value:e,propertyPath:i})},r.nodeElem.insertAdjacentElement("afterbegin",a),r.nodeElem.style.display="flex"}return null},this._propertygrid.propertyNodeContextMenu.on(s=>{Y.show([{title:"edit complex value",action:async()=>{t(s)}},{title:"edit string",action:async()=>{let e=prompt("enter value:");e&&(this._propertygrid.setPropertyValue(s.propertyPath,e),this._propertygrid.refresh())}},{title:"remove complex value",action:async()=>{this._propertygrid.setPropertyValue(s.propertyPath,void 0),this._propertygrid.refresh()}}],s.event)})}async addPossibleCommands(){let t=Object.keys(this.scriptCommandsTypeInfo.definitions).filter(s=>this.scriptCommandsTypeInfo.definitions[s].type=="object");for(let s of t){if(s=="ScriptCommands")continue;let e=document.createElement("option");e.innerText=s,this._possibleCommands.add(e)}}loadScript(t){this._script=t;let s=[];for(let e of this._script.commands)e=N.upgradeScriptCommand(e),s.push(this.createTreeItem(e));this._commandListFancyTree=new Re({...Be,element:this._commandListDiv,icon:!1,source:s,activate:e=>{this._propertygrid.selectedObject=e.node.data.data.item},render:e=>{if(e.isNew){let i=e.nodeElem;i.oncontextmenu=r=>(e.node.setActive(),e.node.data.contextMenu&&e.node.data.contextMenu(r,e.node.data,e.node),r.preventDefault(),!1)}},dnd:{guessDropEffect:!0,preventRecursion:!0,preventVoidMoves:!1,serializeClipboardData:!1,dragStart:e=>(e.event.dataTransfer.effectAllowed="move",e.event.dataTransfer.dropEffect="move",!0),dragEnter:e=>(e.event.dataTransfer.dropEffect="move",!0),dragOver:e=>{e.event.dataTransfer.dropEffect="move"},drop:async e=>{e.sourceNode.moveTo(e.node,e.region=="before"?"before":"after")}}})}createTreeItem(t){return{title:t.type,data:{item:t},contextMenu:(e,i,r)=>{Y.show([{title:"Remove Item",action:o=>r.remove()}],e)}}}addItem(){let s={type:this._possibleCommands.value},e=this.createTreeItem(s);this._commandListFancyTree.addChildren(e)}getScriptCommands(){return this._commandListFancyTree.root.children.map(s=>s.data.data.item)}};customElements.define(O.is,O);import{BaseCustomWebComponentConstructorAppend as Ae,css as We,html as je}from"@node-projects/base-custom-webcomponent";var I=class extends Ae{static style=We`
422
+ `;static is="node-projects-visualization-simple-script-command-picker";_title;get title(){return this._title}set title(t){this._title=t}selectedType;commandTypeChosen=new be;closeRequested=new be;_tree;_filter;_descriptionDiv;_addBtn;_typeInfo;_descriptions;constructor(){super(),this._restoreCachedInititalValues(),this.shadowRoot.adoptedStyleSheets=[rt,nt,n.style],this._descriptionDiv=this._getDomElement("description"),this._addBtn=this._getDomElement("addBtn"),this._filter=this._getDomElement("filter"),this._filter.onkeyup=()=>{let t=this._filter.value;this._tree.filterNodes(s=>new RegExp(t,"i").test(s.title),{})},this._tree=new ot({...at,element:this._getDomElement("commandList"),icon:!1,filter:{autoExpand:!0,mode:"hide",highlight:!0},activate:t=>{this.selectedType=t.node.title,this._addBtn.disabled=!1,this._renderDescription(t.node.title)},dblclick:t=>(this.selectedType=t.node.title,this.commandTypeChosen.emit(),!1),render:t=>{t.isNew&&(t.nodeElem.oncontextmenu=s=>(s.preventDefault(),!1))},dnd:{guessDropEffect:!1,serializeClipboardData:!0,dragStart:t=>(t.event.dataTransfer.effectAllowed="copy",t.event.dataTransfer.dropEffect="copy",!0)}})}async ready(){this._parseAttributesToProperties(),this._bindingsParse(null,!0),this._assignEvents()}addClicked(){this.selectedType&&this.commandTypeChosen.emit()}closeClicked(){this.closeRequested.emit()}_renderDescription(t){let s=this._descriptions?.[t];if(s){this._descriptionDiv.innerHTML=`
423
+ <div class="cmd-title">${t}<span class="hint">${s.description}</span></div>
424
+ <pre class="snippet">${I(s.example)}</pre>
425
+ ${s.note?`<div class="note">${s.note}</div>`:""}
426
+ `;return}let e=this._typeInfo?.definitions?.[t]?.description;this._descriptionDiv.innerHTML=`
427
+ <div class="cmd-title">${t}</div>
428
+ ${e?`<div class="note">${e}</div>`:""}
429
+ `}loadCommands(t,s){this._typeInfo=t,this._descriptions=s??{};let e=Object.keys(t.definitions).filter(i=>t.definitions[i].type==="object"&&i!=="ScriptCommands");this._tree.root.addChildren(e.map(i=>({title:i})))}};customElements.define(z.is,z);function xe(n,t){return`<span class="cs-attr">${n}</span>='${I(t)}'`}var we=`<!DOCTYPE html>
430
+ <html>
431
+ <head>
432
+ <meta charset="UTF-8">
433
+ <style>
434
+ :root { --accent: #2c6e9b; }
435
+
436
+ *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
437
+
438
+ html, body {
439
+ width: 100%;
440
+ height: 100%;
441
+ font-family: Segoe UI, Arial, sans-serif;
442
+ font-size: 13px;
443
+ color: #333;
444
+ background: #f0f1f3;
445
+ }
446
+
447
+ .content {
448
+ height: 100%;
449
+ overflow-y: auto;
450
+ padding: 10px 14px 16px;
451
+ display: flex;
452
+ flex-direction: column;
453
+ gap: 12px;
454
+ }
455
+
456
+ .intro-banner {
457
+ background: #ffffff;
458
+ border-left: 4px solid var(--accent);
459
+ border-radius: 4px;
460
+ padding: 8px 12px;
461
+ font-size: 12px;
462
+ line-height: 1.5;
463
+ }
464
+
465
+ .intro-banner code {
466
+ font-family: Consolas, monospace;
467
+ background: #eef2f6;
468
+ padding: 1px 4px;
469
+ border-radius: 3px;
470
+ color: #2c4a68;
471
+ }
472
+
473
+ .content-section {
474
+ background: #ffffff;
475
+ border-radius: 6px;
476
+ padding: 8px 10px 10px;
477
+ display: flex;
478
+ flex-direction: column;
479
+ gap: 6px;
480
+ }
481
+
482
+ .section-title {
483
+ display: flex;
484
+ align-items: baseline;
485
+ gap: 8px;
486
+ border-bottom: 2px solid var(--accent);
487
+ font-size: 13px;
488
+ font-weight: bold;
489
+ padding-bottom: 4px;
490
+ color: #24405c;
491
+ }
492
+
493
+ .section-num {
494
+ display: inline-flex;
495
+ align-items: center;
496
+ justify-content: center;
497
+ width: 18px;
498
+ height: 18px;
499
+ border-radius: 50%;
500
+ background: var(--accent);
501
+ color: white;
502
+ font-size: 10px;
503
+ font-weight: bold;
504
+ flex-shrink: 0;
505
+ }
506
+
507
+ .section-hint {
508
+ font-size: 11px;
509
+ font-weight: normal;
510
+ color: #808080;
511
+ }
512
+
513
+ .snippet {
514
+ font-family: Consolas, "Courier New", monospace;
515
+ font-size: 11px;
516
+ background: #f6f8fa;
517
+ color: #24292e;
518
+ border: 1px solid #e1e4e8;
519
+ border-radius: 4px;
520
+ padding: 6px 10px;
521
+ white-space: pre;
522
+ overflow-x: auto;
523
+ line-height: 1.5;
524
+ }
525
+
526
+ .cs-attr { color: #005cc5; }
527
+ .cs-key { color: #22863a; }
528
+ .cs-str { color: #032f62; }
529
+ .cs-bool { color: #d73a49; }
530
+ .cs-num { color: #e36209; }
531
+ .cs-comment { color: #6a737d; font-style: italic; }
532
+
533
+ .note {
534
+ font-size: 11px;
535
+ color: #666;
536
+ font-style: italic;
537
+ }
538
+ </style>
539
+ </head>
540
+ <body>
541
+ <div class="content">
542
+
543
+ <div class="intro-banner">
544
+ Events (<code>@click</code>, <code>@change</code>, ...) run a command chain (a <code>Script</code>).<br>
545
+ General syntax: <code>@event='{"commands":[ {...}, {...} ]}'</code> \u2014 commands run top to bottom.
546
+ </div>
547
+
548
+ <div class="content-section">
549
+ <div class="section-title"><span class="section-num">1</span> Basic structure <span class="section-hint">commands array, sequential execution</span></div>
550
+ <pre class="snippet">${xe("@click",`{"commands":[
551
+ { "type": "SetSignalValue", "signal": ".Some.Signal", "value": true },
552
+ { "type": "SetSignalValue", "signal": ".Some.Other", "value": false }
553
+ ]}`)}</pre>
554
+ <div class="note">Commands run top to bottom. Some commands (Condition, Label, Goto, Repeat, Exit) can change that flow \u2014 see their own descriptions in the "Add Command" dialog.</div>
555
+ </div>
556
+
557
+ <div class="content-section">
558
+ <div class="section-title"><span class="section-num">2</span> Dynamic / indirect values <span class="section-hint">IScriptMultiplexValue</span></div>
559
+ <div class="note">Instead of a plain value, most command values can be an object <code>{ "source": ..., "name": ... }</code> that is resolved at runtime.</div>
560
+ <pre class="snippet">${I('{ "source": "expression", "name": "ctx.event.srcElement.value" }')} <span class="cs-comment">// js expression, 'ctx' is the context object</span>
561
+ ${I('{ "source": "complexString", "name": "prefix-{.Some.Signal}-suffix" }')} <span class="cs-comment">// signal names in {}</span>
562
+ ${I('{ "source": "parameter", "name": "myParam" }')} <span class="cs-comment">// a parameter handed into the script</span></pre>
563
+ <div class="note">Other sources: signal, property, signalInProperty, event, complexSignal, context, elementProperty. The property grid's "..." button opens an editor for these.</div>
564
+ </div>
565
+
566
+ <div class="content-section">
567
+ <div class="section-title"><span class="section-num">3</span> Cyclic events <span class="section-hint">re-triggering timer event</span></div>
568
+ <pre class="snippet">${xe("@cyclic:100",`{"commands":[
569
+ { "type": "SetSignalValue", "signal": ".Local.Tick", "value": true }
570
+ ]}`)}</pre>
571
+ <div class="note">A <code>@cyclic:&lt;ms&gt;</code> event retriggers itself automatically every &lt;ms&gt; milliseconds.</div>
572
+ </div>
573
+ </div>
574
+ </body>
575
+ </html>`;var Se={Comment:{description:"has no effect on script execution",example:'{ "type": "Comment", "comment": "explains the next step" }'},OpenScreen:{description:"navigate to a screen (with history)",example:'{ "type": "OpenScreen", "screen": "MyScreen" }'},OpenDialog:{description:"open a screen as a movable/closable dialog",example:`{ "type": "OpenDialog", "screen": "MyScreen", "title": "My Dialog",
576
+ "moveable": true, "closeable": true }`},CloseDialog:{description:"close the parent dialog this command runs in",example:'{ "type": "CloseDialog" }'},OpenUrl:{description:"open an URL, optionally as an in-app dialog",example:'{ "type": "OpenUrl", "url": "https://example.com", "target": "_blank", "openInDialog": false }'},ShowMessageBox:{description:"ask the user to confirm before continuing",example:`{ "type": "ShowMessageBox", "title": "Confirm", "message": "Are you sure?",
577
+ "messageType": "warning", "buttons": "yesNo", "resultSignal": ".Local.Result",
578
+ "exitScriptOnCancel": true }`,note:"exitScriptOnCancel: true stops the chain when the user picks a negative button."},ShowPrompt:{description:"ask the user for text input",example:`{ "type": "ShowPrompt", "title": "Name?", "message": "Enter a name",
579
+ "resultSignal": ".Local.Name", "exitScriptOnCancel": true }`},SetSignalValue:{description:"write a signal / property",example:'{ "type": "SetSignalValue", "signal": ".Some.Signal", "value": true }',note:'target: "signal" (default) | "property" (a screen/control property) | "elementProperty" (a property of the element raising the event).'},ToggleSignalValue:{description:"toggle a boolean signal / property",example:'{ "type": "ToggleSignalValue", "signal": ".Some.Toggle" }'},ToggleSignalValueThroughList:{description:"cycle a signal / property through a fixed list of values",example:'{ "type": "ToggleSignalValueThroughList", "signal": ".Some.Mode", "valueList": [1, 2, 3] }'},IncrementSignalValue:{description:"increment a numeric signal / property",example:'{ "type": "IncrementSignalValue", "signal": ".Some.Counter", "value": 1 }'},DecrementSignalValue:{description:"decrement a numeric signal / property",example:'{ "type": "DecrementSignalValue", "signal": ".Some.Counter", "value": 1 }'},CalculateSignalValue:{description:"calculate a new signal value from a formula",example:`{ "type": "CalculateSignalValue", "targetSignal": ".Some.Result",
580
+ "formula": "{adapter.0.level} * 100 + 30" }`,note:"The formula can reference other signals in curly braces: {signalName}."},SetBitInSignal:{description:"set a single bit (by number) in a signal / property",example:'{ "type": "SetBitInSignal", "signal": ".Some.Bits", "bitNumber": 3 }'},ClearBitInSignal:{description:"clear a single bit (by number) in a signal / property",example:'{ "type": "ClearBitInSignal", "signal": ".Some.Bits", "bitNumber": 3 }'},ToggleBitInSignal:{description:"toggle a single bit (by number) in a signal / property",example:'{ "type": "ToggleBitInSignal", "signal": ".Some.Bits", "bitNumber": 3 }'},Javascript:{description:"run a JavaScript snippet",example:'{ "type": "Javascript", "script": "console.log(context.element)" }',note:"context: { event, element, shadowRoot, instance }."},SetElementProperty:{description:"set a property/attribute/CSS value/class on matching elements",example:`{ "type": "SetElementProperty", "target": "property", "targetSelectorTarget": "container",
581
+ "targetSelector": ".my-class", "name": "disabled", "value": true }`,note:'target: "property" (default) | "attribute" | "css" | "class". targetSelectorTarget: "container" (screen/customControl, default) | "element" (current element).'},Delay:{description:"pause the script chain",example:'{ "type": "Delay", "value": 500 }'},Console:{description:"write a message to the browser console",example:'{ "type": "Console", "target": "log", "message": "done" }',note:'target: "log" (default) | "info" | "debug" | "warn" | "error".'},SwitchLanguage:{description:"switch the active UI language",example:'{ "type": "SwitchLanguage", "language": "en" }'},Login:{description:"log a user in",example:'{ "type": "Login", "username": "user", "password": "pass" }'},Logout:{description:"log the current user out",example:'{ "type": "Logout" }'},SubscribeSignal:{description:"subscribe to a signal so its updates are pushed to the client",example:'{ "type": "SubscribeSignal", "signal": ".Some.Signal", "oneTime": false }'},UnsubscribeSignal:{description:"unsubscribe from a previously subscribed signal",example:'{ "type": "UnsubscribeSignal", "signal": ".Some.Signal" }'},WriteSignalsInGroup:{description:"write all pending signal values of a named group",example:'{ "type": "WriteSignalsInGroup", "group": "MyGroup" }'},ClearSignalsInGroup:{description:"clear all pending signal values of a named group",example:'{ "type": "ClearSignalsInGroup", "group": "MyGroup" }'},RunScript:{description:"run another named script",example:'{ "type": "RunScript", "name": "MyScript", "scriptType": "SimpleScript" }'},CopySignalValuesFromFolder:{description:"copy signal values from one signal folder to another",example:'{ "type": "CopySignalValuesFromFolder", "sourceFolder": ".Source", "destinationFolder": ".Target" }'},ExportSignalValuesAsJson:{description:"export matching signal values as a downloadable JSON file",example:'{ "type": "ExportSignalValuesAsJson", "regex": "^\\\\.Some\\\\..*", "fileName": "export.json" }'},ImportSignalValuesFromJson:{description:"import signal values from a JSON string",example:'{ "type": "ImportSignalValuesFromJson", "data": "{ \\".Some.Signal\\": true }" }'},Repeat:{description:"jump back to a label a number of times, or indefinitely",example:'{ "type": "Repeat", "label": "lbl_loop", "count": 0, "mode": "eventValid" }',note:'mode: "eventValid" (default, repeats until the event is no longer active) | "always" (repeats until count is 0 or indefinitely when count is 0).'},Condition:{description:"compare two values and jump to a label depending on the result",example:`{ "type": "Condition", "value1": {"source":"signal","name":".Is.On"}, "value2": true,
582
+ "comparisonType": "==", "trueGotoLabel": "lbl_off", "falseGotoLabel": "lbl_on" }`,note:"comparisonType: ==null | !=null | ==true | ==false | == | != | > | < | >= | <= | && | ||."},If:{description:"evaluate a formula and run nested commands depending on the result",example:`{ "type": "If",
583
+ "signals": [{"source":"signal","name":".Is.On"}, {"varName":"ready","source":"signal","name":".Is.Ready"}],
584
+ "formula": "__0 == true && ready == false", "trueCommands": [], "elseCommands": [] }`,note:"signals is a list of values (like Condition.value1). Each is referenced in the formula either positionally as __0, __1, ... or, if varName is set, by that name. trueCommands/elseCommands are edited as nested commands in the tree, not as JSON here."},Exit:{description:"stop executing the current script chain",example:'{ "type": "Exit" }'},Label:{description:"a named jump target for Condition / Goto / Repeat",example:'{ "type": "Label", "label": "lbl_on" }'},Goto:{description:"jump unconditionally to a label",example:'{ "type": "Goto", "label": "lbl_on" }'}};import"@node-projects/splitview.webcomponent";var L=class n{static upgradeScriptCommand(t){return t.type==="SetElementProperty"?n.upgradeSetElementProperty(t):(t.type==="If"&&(t.trueCommands=(t.trueCommands??[]).map(s=>n.upgradeScriptCommand(s)),t.elseCommands=(t.elseCommands??[]).map(s=>n.upgradeScriptCommand(s))),t)}static upgradeSetElementProperty(t){return t.targetSelectorTarget==="currentScreen"?t.targetSelectorTarget="container":t.targetSelectorTarget==="parentScreen"?(t.targetSelectorTarget="container",t.parentIndex=1):t.targetSelectorTarget==="currentElement"?t.targetSelectorTarget="element":t.targetSelectorTarget==="parentElement"&&(t.targetSelectorTarget="element",t.parentIndex=1),t}};var j="application/x-simple-script-move",W=class n extends lt{static style=pt`
585
+ :host {
586
+ background: white;
587
+ }
588
+
589
+ .root {
590
+ width: 100%;
591
+ height: 100%;
592
+ overflow: hidden;
593
+ display: flex;
594
+ flex-direction: column;
595
+ box-sizing: border-box;
596
+ }
597
+
598
+ .content {
599
+ flex: 1 1 auto;
600
+ min-height: 0;
601
+ position: relative;
602
+ }
603
+
604
+ .split-view {
605
+ height: calc(100% - 4px);
606
+ width: calc(100% - 4px);
607
+ position: relative;
608
+ margin: 2px;
609
+ }
610
+
611
+ .list-pane {
612
+ width: 48%;
613
+ height: 100%;
614
+ position: relative;
615
+ box-sizing: border-box;
616
+ display: flex;
617
+ flex-direction: column;
618
+ }
619
+
620
+ .list-content {
621
+ flex: 1 1 auto;
622
+ min-height: 0;
623
+ position: relative;
624
+ }
625
+
626
+ .grid-pane {
627
+ width: 52%;
628
+ height: 100%;
629
+ position: relative;
630
+ box-sizing: border-box;
631
+ }
632
+
633
+ .split-view.code-mode .grid-pane {
634
+ display: none;
635
+ }
636
+
637
+ .split-view.code-mode::part(splitter) {
638
+ display: none;
639
+ }
640
+
641
+ #commandList {
642
+ position: absolute;
643
+ inset: 0;
644
+ overflow-x: hidden;
645
+ overflow-y: auto;
646
+ box-sizing: border-box;
647
+ }
648
+
649
+ #commandList.hidden {
650
+ display: none;
651
+ }
652
+
653
+ #commandList {
654
+ --wb-icon-outer-width: 22px;
655
+ }
656
+
657
+ #commandList i.wb-expander {
658
+ background-size: 9px 9px;
659
+ background-position-x: 6px;
660
+ background-position-y: 6px;
661
+ opacity: 0.55;
662
+ }
663
+
664
+ .code-view {
665
+ position: absolute;
666
+ inset: 0;
667
+ display: none;
668
+ }
669
+
670
+ .code-view.visible {
671
+ display: block;
672
+ }
673
+
674
+ node-projects-visualization-property-grid {
675
+ width: 100%;
676
+ height: 100%;
677
+ }
678
+
679
+ .toolbar {
680
+ display: flex;
681
+ align-items: center;
682
+ gap: 8px;
683
+ box-sizing: border-box;
684
+ flex: 0 0 auto;
685
+ width: 100%;
686
+ height: 36px;
687
+ padding: 4px 8px;
688
+ border-top: 1px solid #ccc;
689
+ background-color: rgb(230, 230, 230);
690
+ }
691
+
692
+ .toolbar button {
693
+ box-sizing: border-box;
694
+ padding: 6px 16px;
695
+ border-radius: 4px;
696
+ border: 1px solid #b0b0b0;
697
+ background: white;
698
+ font-size: 12px;
699
+ cursor: pointer;
700
+ }
701
+
702
+ .toolbar button:hover:not(:disabled) {
703
+ background: #f0f0f0;
704
+ border-color: #909090;
705
+ }
706
+
707
+ .toolbar button:active:not(:disabled) {
708
+ background: #e2e2e2;
709
+ }
710
+
711
+ .toolbar button:disabled {
712
+ opacity: 0.5;
713
+ cursor: not-allowed;
714
+ }
715
+
716
+ .toolbar button.primary {
717
+ background: #2c6e9b;
718
+ border-color: #2c6e9b;
719
+ color: white;
720
+ }
721
+
722
+ .toolbar button.primary:hover:not(:disabled) {
723
+ background: #255d83;
724
+ border-color: #255d83;
725
+ }
726
+
727
+ .toolbar button.primary:active:not(:disabled) {
728
+ background: #1e4d6b;
729
+ }
730
+
731
+ .toolbar .spacer {
732
+ flex: 1 1 auto;
733
+ }
734
+
735
+ .toolbar .icon-btn {
736
+ display: flex;
737
+ align-items: center;
738
+ justify-content: center;
739
+ width: 22px;
740
+ height: 22px;
741
+ padding: 0;
742
+ box-sizing: border-box;
743
+ border: none;
744
+ background: transparent;
745
+ cursor: pointer;
746
+ }
747
+
748
+ .toolbar .icon-btn:hover {
749
+ background: #eee;
750
+ }
751
+
752
+ .drag-handle {
753
+ position: absolute;
754
+ left: 0;
755
+ top: 0;
756
+ height: 100%;
757
+ width: 24px;
758
+ display: flex;
759
+ align-items: center;
760
+ justify-content: center;
761
+ color: #888;
762
+ cursor: grab;
763
+ }
764
+
765
+ .cmd {
766
+ position: absolute;
767
+ right: 0;
768
+ top: 0;
769
+ height: 100%;
770
+ display: flex;
771
+ align-items: center;
772
+ gap: 2px;
773
+ padding: 0 2px;
774
+ background: white;
775
+ }
776
+
777
+ .cmd img {
778
+ width: 12px;
779
+ height: 12px;
780
+ cursor: pointer;
781
+ }
782
+ `;static template=dt`
783
+ <div class="root">
784
+ <div class="content">
785
+ <node-projects-split-view
786
+ id="splitView"
787
+ class="split-view"
788
+ orientation="horizontal"
789
+ >
790
+ <div id="listPane" class="list-pane">
791
+ <div id="listContent" class="list-content">
792
+ <div id="commandList"></div>
793
+ <node-projects-code-view-monaco
794
+ id="codeView"
795
+ class="code-view"
796
+ language="json"
797
+ ></node-projects-code-view-monaco>
798
+ </div>
799
+ <div class="toolbar">
800
+ <button
801
+ id="addCommandBtn"
802
+ class="primary"
803
+ @click="[[this.addCommand()]]"
804
+ >
805
+ Add Command
806
+ </button>
807
+ <button id="codeToggleBtn" @click="[[this.toggleCodeView()]]">
808
+ Code
809
+ </button>
810
+ <span class="spacer"></span>
811
+ <button
812
+ class="icon-btn"
813
+ title="Help"
814
+ @click="[[this.helpClicked()]]"
815
+ >
816
+ <svg viewBox="0 0 512 512" width="16" height="16">
817
+ <path
818
+ d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336h24V272H216c-13.3 0-24-10.7-24-24s10.7-24 24-24h48c13.3 0 24 10.7 24 24v88h8c13.3 0 24 10.7 24 24s-10.7 24-24 24H216c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"
819
+ />
820
+ </svg>
821
+ </button>
822
+ </div>
823
+ </div>
824
+ <div class="grid-pane">
825
+ <node-projects-visualization-property-grid
826
+ id="propertygrid"
827
+ ></node-projects-visualization-property-grid>
828
+ </div>
829
+ </node-projects-split-view>
830
+ </div>
831
+ </div>
832
+ `;static is="node-projects-visualization-simple-script-editor";_title;get title(){return this._title}set title(t){this._title=t}serviceContainer;instanceServiceContainer;visualizationHandler;visualizationShell;scriptCommandsTypeInfo;propertiesTypeInfo;helpRequested=new ct;commandDescriptions={...Se};_script;_commandListDiv;_commandListFancyTree;_propertygrid;_splitView;_codeView;_codeToggleBtn;_addCommandBtn;_showingCode=!1;_dragFromHandle=!1;_draggedNode=null;constructor(){super(),this._restoreCachedInititalValues(),this._commandListDiv=this._getDomElement("commandList"),this._propertygrid=this._getDomElement("propertygrid"),this._splitView=this._getDomElement("splitView"),this._codeView=this._getDomElement("codeView"),this._codeToggleBtn=this._getDomElement("codeToggleBtn"),this._addCommandBtn=this._getDomElement("addCommandBtn");let t=this._getDomElement("listContent");t.addEventListener("mousedown",s=>{this._dragFromHandle=!!s.target?.closest(".drag-handle")}),document.addEventListener("dragend",()=>{this._draggedNode=null},!0),t.addEventListener("dragover",s=>{if(s.preventDefault(),s.dataTransfer){let e=s.dataTransfer.types.includes(j);s.dataTransfer.dropEffect=e?"move":"copy"}}),t.addEventListener("drop",s=>{if(s.preventDefault(),s.dataTransfer?.types.includes(j)&&this._draggedNode){let i=this._commandListFancyTree.root.children,r=i?.[i.length-1];r&&this._draggedNode.moveTo(r,"after"),this._draggedNode.setClass("wb-drag-source",!1)}else{let i=s.dataTransfer?.getData("text/plain");if(i){let r={type:i};this._commandListFancyTree.root.addChildren(this.createTreeItem(r))}}}),this.shadowRoot.adoptedStyleSheets=[ft,mt,n.style]}async ready(){this._parseAttributesToProperties(),this._bindingsParse(null,!0),this._assignEvents();let t=async l=>{let o=new X;o.visualizationHandler=this.visualizationHandler,o.visualizationShell=this.visualizationShell,o.serviceContainer=this.serviceContainer,o.instanceServiceContainer=this.instanceServiceContainer,o.bindableObjectsTarget="script",o.getTypeInfo=(m,h)=>_e(this.propertiesTypeInfo,m,h),o.showHead=!1,o.typeName="IScriptMultiplexValue",o.title='Complex for "'+l.propertyPath+'"',typeof l.value=="object"?o.selectedObject=l.value??{}:o.selectedObject={},o.bindingDoubleClicked=m=>{m.bindabletype=="property"?o.setPropertyValue("source","property"):m.bindabletype=="context"?o.setPropertyValue("source","context"):o.setPropertyValue("source","signal"),o.setPropertyValue("name",m.fullName),o.refresh()},await this.visualizationShell.openConfirmation(o,{x:100,y:100,width:400,height:500,parent:this})&&(this._propertygrid.setPropertyValue(l.propertyPath,o.selectedObject),this._propertygrid.refresh())},s=async l=>{let o=new ke;o.language="javascript",o.style.position="relative",o.code=l.value??"",await this.visualizationShell.openConfirmation(o,{title:"Edit formula",x:100,y:50,width:700,height:450,parent:this})&&(this._propertygrid.setPropertyValue(l.propertyPath,o.code),this._propertygrid.refresh())},e=["signal","property","elementProperty","signalInProperty","event","parameter","context","complexString","complexSignal","expression"],i=/^[A-Za-z_$][A-Za-z0-9_$]*$/,r=new Set(["break","case","catch","class","const","continue","debugger","default","delete","do","else","export","extends","finally","for","function","if","import","in","instanceof","new","return","super","switch","this","throw","try","typeof","var","void","while","with","yield","let","static","enum","await","implements","package","protected","interface","private","public","null","true","false","undefined","arguments","eval"]),c={signal:"read the value from a Signal",property:"read the value from a property of the customControl (not usable in screens)",elementProperty:"a property defined on the element raising the event",signalInProperty:"read the value from a Signal (wich name is in the Property)",event:"read the value of a property of the event object",parameter:"a parameter you hand over",context:"a value of the context",complexString:"a string with signals (contained in {})",complexSignal:"read the value from a signal wich name is build here (it can contain other signals in {})",expression:"js expression, 'ctx' is context object"},a=async l=>{let o=(l.value??[]).map(w=>({...w})),p=w=>{let S=(o[w].varName??"").trim();return S?i.test(S)?r.has(S)?`"${S}" is a reserved word and cannot be used as a variable name.`:o.some((_,k)=>k!==w&&(_.varName??"").trim()===S)?`"${S}" is used by more than one signal.`:null:`"${S}" is not a valid JavaScript variable name.`:null},m="height:22px; box-sizing:border-box; font-size:12px;",h=document.createElement("div");h.style.cssText="display:flex; flex-direction:column; gap:6px; padding:8px; height:100%; box-sizing:border-box; overflow-y:auto; font-size:12px;";let u=document.createElement("div");u.style.cssText="display:flex; align-items:center; gap:4px; font-weight:bold;";let d=document.createElement("span");d.textContent="Name",d.style.cssText="flex:0 0 120px;";let g=document.createElement("span");g.textContent="Typ",g.style.cssText="flex:0 0 130px;";let f=document.createElement("span");f.textContent="Signal",f.style.cssText="flex:1 1 auto;";let x=document.createElement("span");x.style.cssText="flex:0 0 22px;",u.append(d,g,f,x),h.appendChild(u);let T=document.createElement("div");T.style.cssText="display:flex; flex-direction:column; gap:4px;",h.appendChild(T);let $=document.createElement("div");$.style.cssText="flex:0 0 auto; margin-top:4px; padding-top:6px; border-top:1px solid #ccc; font-size:12px;";let ie=document.createElement("div");ie.style.cssText="font-weight:bold; margin-bottom:2px;";let ae=document.createElement("div");ae.style.cssText="color:#333; white-space:pre-line;",$.append(ie,ae);let ne=w=>{ie.textContent="Typ: "+w,ae.textContent=c[w]??""},oe=[],ge=()=>{o.forEach((w,S)=>{let _=oe[S];if(!_)return;let k=p(S);_.title=k??`Variable name used in the formula (defaults to __${S} if empty)`,_.style.borderColor=k?"#c0392b":"",_.style.backgroundColor=k?"#fdecea":""})},re=()=>{T.innerHTML="",oe.length=0,o.forEach((w,S)=>{let _=document.createElement("div");_.style.cssText="display:flex; align-items:center; gap:4px;";let k=document.createElement("input");k.value=w.varName??"",k.placeholder="__"+S,k.style.cssText=m+" flex:0 0 120px; min-width: 120px; font-family:monospace;",k.oninput=()=>{w.varName=k.value||void 0,ge()},oe.push(k),_.appendChild(k);let N=document.createElement("select");N.style.cssText=m+" flex:0 0 130px;";for(let ce of e){let Z=document.createElement("option");Z.value=ce,Z.textContent=ce,w.source===ce&&(Z.selected=!0),N.appendChild(Z)}N.onchange=()=>{w.source=N.value,ne(N.value)},N.onfocus=()=>ne(N.value),_.appendChild(N);let R=document.createElement("input");R.value=w.name??"",R.placeholder="e.g. srm.rbg{__tagRoot}.error",R.style.cssText=m+" flex:1 1 auto;",R.oninput=()=>{w.name=R.value},_.appendChild(R);let G=document.createElement("button");G.title="Remove signal",G.style.cssText=m+" flex:0 0 22px; width:22px; padding:0; display:flex; align-items:center; justify-content:center;";let le=document.createElement("img");le.src=pe+"icons/delete.svg",le.style.cssText="width:12px; height:12px;",G.appendChild(le),G.onclick=()=>{o.splice(S,1),re()},_.appendChild(G),T.appendChild(_)}),ge()};re();let Y=document.createElement("button");Y.textContent="+ Add signal",Y.style.cssText=m+" align-self:flex-start; padding:0 8px;",Y.onclick=()=>{o.push({source:"signal",name:""}),re()},h.appendChild(Y),ne(o[0]?.source??"signal"),h.appendChild($),await this.visualizationShell.openConfirmation(h,{title:"Edit signals",x:100,y:50,width:500,height:400,parent:this})&&(this._propertygrid.setPropertyValue(l.propertyPath,o),this._propertygrid.refresh())};this._propertygrid.visualizationHandler=this.visualizationHandler,this._propertygrid.visualizationShell=this.visualizationShell,this._propertygrid.serviceContainer=this.serviceContainer,this._propertygrid.instanceServiceContainer=this.instanceServiceContainer,this._propertygrid.bindableObjectsTarget="script",this._propertygrid.setNameColumnWidth(130),this._propertygrid.getTypeInfo=(l,o)=>{let p=_e(this.scriptCommandsTypeInfo,l,o);return p&&(o==="If"||l?.type==="If")&&(p.properties=p.properties.filter(m=>m.name!=="trueCommands"&&m.name!=="elseCommands")),p},this._propertygrid.getSpecialEditorForType=async(l,o,p,m,h)=>{if(!l.specialAllreadyAdded&&(l.specialAllreadyAdded=!0,l.format!=="collection"))if(l.format==="signalList"){let u=document.createElement("button");u.style.height="calc(100% - 6px)",u.style.position="relative",u.style.display="flex",u.style.justifyContent="center",u.style.width="20px",u.style.boxSizing="content-box",u.innerText="del",u.onclick=()=>{this._propertygrid.setPropertyValue(p,void 0),this._propertygrid.refresh()},m.nodeElem.insertAdjacentElement("afterbegin",u);let d=Array.isArray(o)?o:[],g=document.createElement("div");g.style.display="flex";let f=document.createElement("span");f.innerText=d.map((T,$)=>(T?.varName||"__"+$)+": "+(T?.source??"")+":"+(T?.name??"")).join(", "),f.style.overflow="hidden",f.style.whiteSpace="nowrap",f.style.textOverflow="ellipsis",f.style.flexGrow="1",f.title=JSON.stringify(d),g.appendChild(f);let x=document.createElement("button");return x.innerText="...",x.onclick=()=>{a({value:d,propertyPath:p})},g.appendChild(x),m.nodeElem.style.display="flex",g}else if(l.format==="formula"){let u=document.createElement("div");u.style.cssText="display:flex; width:100%; height:100%; align-items:stretch;";let d=new ke;d.language="javascript",d.singleRow=!0,d.style.cssText="flex:1 1 auto; min-width:0; height:100%; position:relative; overflow:hidden;",d.code=o??"",d.addEventListener("code-changed",()=>{this._propertygrid.setPropertyValue(p,d.code)}),u.appendChild(d);let g=document.createElement("button");return g.innerText="...",g.title="Open in larger editor",g.style.cssText="flex:0 0 28px; width:20px;",g.onclick=()=>s({value:d.code,propertyPath:p}),u.appendChild(g),m.nodeElem.style.display="flex",u}else if(typeof o=="object"&&o!==null||l.format==="complex"){let u=document.createElement("button");u.style.height="calc(100% - 6px)",u.style.position="relative",u.style.display="flex",u.style.justifyContent="center",u.style.width="20px",u.style.boxSizing="content-box",u.innerText="del",u.onclick=()=>{this._propertygrid.setPropertyValue(p,void 0),this._propertygrid.refresh()},m.nodeElem.insertAdjacentElement("afterbegin",u);let d=document.createElement("div");d.style.display="flex";let g=document.createElement("span");o?g.innerText=(o.source??"")+": "+(o.name??""):g.innerText="",g.style.overflow="hidden",g.style.whiteSpace="nowrap",g.style.textOverflow="ellipsis",g.style.flexGrow="1",g.title=JSON.stringify(o),d.appendChild(g);let f=document.createElement("button");return f.innerText="...",f.onclick=()=>{t({value:o,propertyPath:p})},d.appendChild(f),m.nodeElem.style.display="flex",d}else{let u=document.createElement("button");u.style.height="calc(100% - 6px)",u.style.position="relative",u.style.display="flex",u.style.justifyContent="center",u.style.width="20px",u.style.boxSizing="content-box",u.title="complex property value",u.style.opacity="0.2",u.innerText="...",u.onclick=()=>{t({value:o,propertyPath:p})},m.nodeElem.insertAdjacentElement("afterbegin",u),m.nodeElem.style.display="flex"}return null},this._propertygrid.propertyNodeContextMenu.on(l=>{ut.show([{title:"edit complex value",action:async()=>{t(l)}},{title:"edit string",action:async()=>{let o=prompt("enter value:");o&&(this._propertygrid.setPropertyValue(l.propertyPath,o),this._propertygrid.refresh())}},{title:"remove complex value",action:async()=>{this._propertygrid.setPropertyValue(l.propertyPath,void 0),this._propertygrid.refresh()}}],l.event)})}helpClicked(){let t=document.createElement("iframe");t.srcdoc=we,t.style.cssText="width:100%; height:100%; border:none; display:block;",this.visualizationShell.openModal(t,{title:"Simple Script Editor Help",parent:this,x:-650,y:-100,width:620,height:620}),this.helpRequested.emit()}toggleCodeView(){if(!this._showingCode){let s=JSON.stringify({commands:this.getScriptCommands()},null,2);this._codeView.update(s),this._showCodeView(!0);return}let t=this._parseCodeViewScript();t&&(this._showCodeView(!1),this.loadScript(t))}_showCodeView(t){this._codeView.classList.toggle("visible",t),this._commandListDiv.classList.toggle("hidden",t),this._splitView.classList.toggle("code-mode",t),this._addCommandBtn.disabled=t,this._codeToggleBtn.innerText=t?"Visual":"Code",this._showingCode=t,t&&requestAnimationFrame(()=>this._codeView.activated())}_parseCodeViewScript(){let t;try{t=JSON.parse(this._codeView.getText())}catch(s){return alert(`Invalid JSON:
833
+ `+s.message),null}return Array.isArray(t?.commands)?t:(alert('The JSON must have a "commands" array.'),null)}loadScript(t){this._script=t,this._commandListFancyTree&&(this._commandListFancyTree.destroy(),this._commandListDiv=this._getDomElement("commandList"));let s=[];for(let e of this._script.commands)e=L.upgradeScriptCommand(e),s.push(this.createTreeItem(e));this._commandListFancyTree=new gt({...ht,element:this._commandListDiv,icon:!1,source:s,activate:e=>{this._propertygrid.selectedObject=e.node.data.data.item??null},render:e=>{let i=!!e.node.data.data?.branch;if(e.isNew){e.nodeElem.oncontextmenu=a=>(a.preventDefault(),!1);let c=document.createElement("span");if(c.style.cssText="display:inline-block; width:24px;",e.nodeElem.prepend(c),i)e.nodeElem._reservedRowWidth=c.offsetWidth;else{let a=document.createElement("div");a.className="drag-handle",a.title="Drag to reorder",a.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14"><path d="M4 6h16M4 12h16M4 18h16" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>',e.nodeElem.prepend(a);let l=e.nodeElem.parentElement,o=document.createElement("span");o.style.cssText="display:inline-block; width:32px;",e.nodeElem.appendChild(o);let p=document.createElement("div");p.className="cmd";let m=document.createElement("img");m.src=pe+"icons/copy.svg",m.title="Duplicate",m.onclick=()=>{let u=structuredClone(e.node.data.data.item);e.node.parent.addChildren(this.createTreeItem(u)).moveTo(e.node,"after")};let h=document.createElement("img");h.src=pe+"icons/delete.svg",h.title="Remove",h.onclick=()=>e.node.remove(),p.append(m,h),l.appendChild(p),e.nodeElem._reservedRowWidth=c.offsetWidth+o.offsetWidth}}let r=e.nodeElem._reservedRowWidth??0;if(r){let c=e.nodeElem.querySelector("span.wb-title");if(c){let a=parseFloat(c.style.width);isNaN(a)||(c.style.width=Math.max(0,a-r)+"px")}}},dnd:{guessDropEffect:!0,preventRecursion:!0,preventVoidMoves:!1,serializeClipboardData:!1,dragStart:e=>this._dragFromHandle?(this._draggedNode=e.node,e.event.dataTransfer.effectAllowed="move",e.event.dataTransfer.dropEffect="move",e.event.dataTransfer.setData(j,"1"),!0):!1,dragEnd:()=>{this._draggedNode=null},dragEnter:e=>{let i=e.event.dataTransfer?.types.includes(j);return e.event.dataTransfer.dropEffect=i?"move":"copy",!!e.node.data.data?.branch?new Set(["over"]):new Set(["before","after"])},dragOver:e=>{let i=e.event.dataTransfer?.types.includes(j);e.event.dataTransfer.dropEffect=i?"move":"copy"},drop:async e=>{let i=e.event.dataTransfer?.types.includes(j);if(e.region==="over"){if(i&&this._draggedNode)this._draggedNode.moveTo(e.node,"appendChild"),this._draggedNode.setClass("wb-drag-source",!1);else{let c=e.event.dataTransfer?.getData("text/plain");c&&e.node.addChildren(this.createTreeItem({type:c}))}return}let r=e.region=="before"?"before":"after";if(i&&this._draggedNode)this._draggedNode.moveTo(e.node,r),this._draggedNode.setClass("wb-drag-source",!1);else{let c=e.event.dataTransfer?.getData("text/plain");if(c){let a={type:c},l=this.createTreeItem(a);e.node.parent.addChildren(l).moveTo(e.node,r)}}}}}),this._commandListFancyTree.root.children?.[0]?.setActive()}createTreeItem(t){if(t.type==="If"){let s=t;return s.trueCommands??=[],s.elseCommands??=[],{title:"If",expanded:!0,data:{item:t},children:[{title:"true",expanded:!0,data:{branch:"true"},children:s.trueCommands.map(e=>this.createTreeItem(e))},{title:"else",expanded:!0,data:{branch:"else"},children:s.elseCommands.map(e=>this.createTreeItem(e))}]}}return{title:t.type,data:{item:t}}}nodeToCommand(t){let s=t.data.data.item;if(s.type==="If"){let e=t.children?.find(r=>r.data.data?.branch==="true"),i=t.children?.find(r=>r.data.data?.branch==="else");s.trueCommands=(e?.children??[]).map(r=>this.nodeToCommand(r)),s.elseCommands=(i?.children??[]).map(r=>this.nodeToCommand(r))}return s}_getBranchContainerNode(t){let s=t;for(;s;){if(s.data?.data?.branch)return s;s=s.parent}return null}async addCommand(){let t=new z;t.loadCommands(this.scriptCommandsTypeInfo,this.commandDescriptions),t.title="Add Script Command",t.commandTypeChosen.on(()=>{if(t.selectedType){let e={type:t.selectedType},i=this.createTreeItem(e),r=this._getBranchContainerNode(this._commandListFancyTree.activeNode);r?r.addChildren(i):this._commandListFancyTree.addChildren(i)}});let s=new AbortController;t.closeRequested.on(()=>s.abort()),await this.visualizationShell.openModal(t,{title:"Add Script Command",x:300,y:50,width:620,height:400,parent:this,abortSignal:s.signal})}getScriptCommands(){if(this._showingCode){let s=this._parseCodeViewScript();s&&this.loadScript(s)}return this._commandListFancyTree.root.children.map(s=>this.nodeToCommand(s))}};customElements.define(W.is,W);import{BaseCustomWebComponentConstructorAppend as yt,css as vt,html as bt}from"@node-projects/base-custom-webcomponent";var M=class extends yt{static style=vt`
306
834
  :host {
307
835
  display: grid;
308
836
  grid-template-columns: 80px 80px 80px auto;
@@ -316,7 +844,7 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
316
844
 
317
845
  span {
318
846
  font-size: 10px;
319
- }`;static template=je`
847
+ }`;static template=bt`
320
848
  <span></span>
321
849
  <span>name</span>
322
850
  <span>type</span>
@@ -335,7 +863,7 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
335
863
  <input hidden="[[item.type !== 'boolean']]" type="checkbox" checked="{{item.value}}">
336
864
  <div hidden="[[item.type !== 'null']]">-null-</div>
337
865
  </template>
338
- <button @click="[[this._add()]]" style="width: 40px; height: 20px; align-self: center;">add</button>`;static is="node-projects-visualization-parameter-editor";constructor(){super(),this._restoreCachedInititalValues()}ready(){this._bindingsParse()}_parameterArray;setParametersObject(t){t!=null?this._parameterArray=Object.keys(t).map(s=>({key:s,type:typeof t[s]=="object"?"null":typeof t[s],value:t[s]})):this._parameterArray=[],this._bindingsRefresh()}getParametersObject(){let t=!1,s={};for(let e of this._parameterArray)if(e.key)switch(t=!0,s[e.key]=null,e.type){case"string":s[e.key]=e.value.toString();break;case"number":let i=parseFloat(e.value);s[e.key]=isNaN(i)?0:i;break;case"boolean":s[e.key]=!!e.value;break}return t?s:null}_remove(t){this._parameterArray.splice(t,1),this._bindingsRefresh()}_add(){this._parameterArray.push({type:"null"}),this._bindingsRefresh()}};customElements.define(I.is,I);import{BaseCustomWebComponentConstructorAppend as ze,css as De,html as K}from"@node-projects/base-custom-webcomponent";import{ContextMenu as Q,copyTextToClipboard as ee,getTextFromClipboard as te,PropertiesHelper as Pe}from"@node-projects/web-component-designer";var P=class n extends ze{static style=De`
866
+ <button @click="[[this._add()]]" style="width: 40px; height: 20px; align-self: center;">add</button>`;static is="node-projects-visualization-parameter-editor";constructor(){super(),this._restoreCachedInititalValues()}ready(){this._bindingsParse()}_parameterArray;setParametersObject(t){t!=null?this._parameterArray=Object.keys(t).map(s=>({key:s,type:typeof t[s]=="object"?"null":typeof t[s],value:t[s]})):this._parameterArray=[],this._bindingsRefresh()}getParametersObject(){let t=!1,s={};for(let e of this._parameterArray)if(e.key)switch(t=!0,s[e.key]=null,e.type){case"string":s[e.key]=e.value.toString();break;case"number":let i=parseFloat(e.value);s[e.key]=isNaN(i)?0:i;break;case"boolean":s[e.key]=!!e.value;break}return t?s:null}_remove(t){this._parameterArray.splice(t,1),this._bindingsRefresh()}_add(){this._parameterArray.push({type:"null"}),this._bindingsRefresh()}};customElements.define(M.is,M);import{BaseCustomWebComponentConstructorAppend as xt,css as wt,html as Te}from"@node-projects/base-custom-webcomponent";import{ContextMenu as Ce,copyTextToClipboard as Ee,getTextFromClipboard as Ne,PropertiesHelper as St}from"@node-projects/web-component-designer";var Q=class n extends xt{static style=wt`
339
867
  :host {
340
868
  display: grid;
341
869
  grid-template-columns: 20px 1fr auto;
@@ -369,22 +897,22 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
369
897
  }
370
898
  button {
371
899
  cursor: pointer;
372
- }`;static template=K`
900
+ }`;static template=Te`
373
901
  <template repeat:item="[[this.events]]">
374
902
  <div @click="[[this._ctxMenu(event, item)]]" @contextmenu="[[this._ctxMenu(event, item)]]" class="rect" title="[[this._getScriptType(item)]]" css:background-color="[[this._getScriptTypeColor(item)]]"></div>
375
903
  <a @click="[[this._showContextMenuAssignScript(event, item, false)]]" @contextmenu="[[this._ctxMenu(event, item)]]" title="[[item.name]]">[[item.name]]</a>
376
904
  <div>[[this._createControlsForScript(item)]]</div>
377
905
  </template>
378
906
  <span style="grid-column: 1 / span 3; margin-top: 8px; margin-left: 3px;">add event:</span>
379
- <input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress="[[this._addEvent(event)]]" type="text">`;static editRowTemplate=K`
907
+ <input id="addEventInput" style="grid-column: 1 / span 3; margin: 5px;" @keypress="[[this._addEvent(event)]]" type="text">`;static editRowTemplate=Te`
380
908
  <div style="display: flex; justify-content: flex-end;">
381
909
  <input value="[[this._getScriptName(item)]]" @keypress="[[this._changeScriptName(event, item)]]" hidden="[[this._getScriptType(item) !== 'js']]" placeholder="name" title="name" style="min-width: 50px; flex-basis: 30px; flex-grow: 2;" class="mth" type="text">
382
910
  <input value="[[this._getRelativeSignalsPath(item)]]" @keypress="[[this._changeRelativeSignalsPath(event, item)]]" placeholder="relative signals path" title="relative signals path" style="min-width: 50px; flex-basis: 20px; flex-grow: 1;" class="mth" type="text">
383
911
  <button css:background="[[this._hasParameters(item) ? 'lime' : '']]" style="display: flex; padding: 0; flex-grow: 0;" title="parameter" @click="[[this._editParameter(event, item)]]">p</button>
384
- </div>`;static scriptTypeColors={js:"purple",blockly:"yellow",script:"lightgreen",empty:"pink"};static is="node-projects-visualization-event-assignment";constructor(){super(),this._restoreCachedInititalValues()}ready(){this._bindingsParse()}_blocklyToolbox;_instanceServiceContainer;_selectionChangedHandler;_selectedItems;_visualizationHandler;_visualizationShell;_scriptCommandsTypeInfo;_propertiesTypeInfo;events;initialize(t,s,e,i,r){this._visualizationHandler=t,this._visualizationShell=s,this._scriptCommandsTypeInfo=e,this._propertiesTypeInfo=i,this._blocklyToolbox=r}set instanceServiceContainer(t){this._instanceServiceContainer=t,this._selectionChangedHandler?.dispose(),this._selectionChangedHandler=this._instanceServiceContainer.selectionService.onSelectionChanged.on(s=>{this.selectedItems=s.selectedElements}),this.selectedItems=this._instanceServiceContainer.selectionService.selectedElements}_createControlsForScript(t){switch(this._getScriptType(t)){case"none":return""}return this.constructor.editRowTemplate.content.cloneNode(!0)}_getScriptName(t){if(this.selectedItems[0].hasAttribute("@"+t.name)){let s=this.selectedItems[0].getAttribute("@"+t.name);if(s[0]==="{"){if(s.includes("name"))return JSON.parse(s).name}else return s}return null}async _changeScriptName(t,s){if(t.key=="Enter"&&this.selectedItems&&this.selectedItems.length&&this.selectedItems[0].hasAttribute("@"+s.name)){let e=t.target.value,i=this.selectedItems[0].getAttribute("@"+s.name);if(i.startsWith("{")){let r=JSON.parse(i);r.name=e,this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}else this._selectedItems[0].setAttribute("@"+s.name,e)}}_getRelativeSignalsPath(t){if(this.selectedItems[0].hasAttribute("@"+t.name)){let s=this.selectedItems[0].getAttribute("@"+t.name);if(s[0]==="{"&&s.includes("relativeSignalsPath"))return JSON.parse(s).relativeSignalsPath}return null}async _changeRelativeSignalsPath(t,s){if(t.key=="Enter"&&this.selectedItems&&this.selectedItems.length&&this.selectedItems[0].hasAttribute("@"+s.name)){let e=t.target.value,i=this.selectedItems[0].getAttribute("@"+s.name);if(i.startsWith("{")){let r=JSON.parse(i);r.relativeSignalsPath=e,this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}else{let r={name:i,relativeSignalsPath:e};this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}}}_hasParameters(t){return this.selectedItems[0].hasAttribute("@"+t.name)?this.selectedItems[0].getAttribute("@"+t.name).includes("parameters"):!1}_getScriptTypeColor(t){let s=this._getScriptType(t);return n.scriptTypeColors[s]??"white"}_getScriptType(t){if(t.designItem.hasAttribute("@"+t.name)){let s=t.designItem.getAttribute("@"+t.name);if(s.startsWith("{")){let e=JSON.parse(s);return"blocks"in e?"blockly":"commands"in e?"script":"js"}else return s==""?"empty":"js"}return"none"}_getEventMethodname(t){return this.selectedItems.length?this.selectedItems[0].getAttribute("@"+t.name):""}_inputMthName(t,s){let e=t.target;this.selectedItems[0].setAttribute("@"+s.name,e.value)}_ctxMenu(t,s){t.preventDefault();let e=this._getScriptType(s);if(e=="empty")this._showContextMenuAssignScript(t,s,!0);else if(e!="none"){let i=[{title:"remove",action:()=>{this.selectedItems[0].removeAttribute("@"+s.name),this._bindingsRefresh()}},{title:"-"},{title:"copy",action:()=>{ee(this.selectedItems[0].getAttribute("@"+s.name))}},{title:"paste",action:async()=>{this.selectedItems[0].setAttribute("@"+s.name,await te()),this._bindingsRefresh()}}];Q.show(i,t)}else this._showContextMenuAssignScript(t,s,!0)}async _addEvent(t){if(t.key=="Enter"){let s=this._getDomElement("addEventInput");this._selectedItems[0].setAttribute("@"+Pe.camelToDashCase(s.value.replaceAll(" ","-")),""),s.value="",this.scrollTop=0,this.refresh()}}_createAssignScriptContextMenu(t,s){let e=[{title:"Simple Script",action:()=>{this._editEvent("script",t,s)}},{title:"Javascript",action:()=>{let r=prompt("name of function ?");r&&(this._selectedItems[0].setAttribute("@"+s.name,r),this.refresh(),this._editEvent("js",null,s))}},{title:"Blockly",action:()=>{this._editBlockly(null,s)}}],i=this._getScriptType(s);return i!="none"&&(e.push({title:"-"}),e.push({title:"remove",action:()=>{this.selectedItems[0].removeAttribute("@"+s.name),this._bindingsRefresh()}})),i!="empty"&&e.push({title:"-"},{title:"copy",action:()=>{ee(this.selectedItems[0].getAttribute("@"+s.name))}},{title:"paste",action:async()=>{this.selectedItems[0].setAttribute("@"+s.name,await te()),this._bindingsRefresh()}}),e}async _showContextMenuAssignScript(t,s,e){t.preventDefault();let i=this._getScriptType(s);if(i!="none"&&i!="empty"&&!e)this._editEvent(i,t,s);else{let r=this._createAssignScriptContextMenu(t,s);Q.show(r,t)}}async _editParameter(t,s){let e=new I,i={};e.title="ParameterEditor for '"+s.name+"' of '"+s.designItem.name+"'";let r=s.designItem.getAttribute("@"+s.name);if(r&&r[0]=="{")try{i=JSON.parse(r).parameters}catch{}if(e.setParametersObject(i),await this._visualizationShell.openConfirmation(e,{x:100,y:100,width:700,height:500})){let a=e.getParametersObject(),l={name:r,parameters:a};r&&r[0]=="{"&&(l=JSON.parse(r),l.parameters=a),a==null&&delete l.parameters;let c=JSON.stringify(l);s.designItem.setAttribute("@"+s.name,c),this._bindingsRefresh()}}async _editBlockly(t,s){let e=new C(this._blocklyToolbox);e.title="Blockly Script for '"+s.name+"' of '"+s.designItem.name+"'";let i=s.designItem.getAttribute("@"+s.name),r=null,o=null;if(i){let l=JSON.parse(i);r=l.parameters,o=l.relativeSignalsPath,e.load(l)}if(await this._visualizationShell.openConfirmation(e,{x:100,y:100,width:700,height:500})){let l=e.save();r&&(l.parameters=r),o&&(l.relativeSignalsPath=o),s.designItem.setAttribute("@"+s.name,JSON.stringify(l)),this._bindingsRefresh()}}async _editJavascript(t,s){}async _editSimpleScript(t,s){let e=s.designItem.getAttribute("@"+s.name);if(!e||e.startsWith("{")){let i={commands:[]},r=null,o=null;e&&(i=JSON.parse(e),r=i.parameters,o=i.relativeSignalsPath);let a=new O;if(a.serviceContainer=s.designItem.serviceContainer,a.instanceServiceContainer=s.designItem.instanceServiceContainer,a.scriptCommandsTypeInfo=this._scriptCommandsTypeInfo,a.propertiesTypeInfo=this._propertiesTypeInfo,a.visualizationShell=this._visualizationShell,a.visualizationHandler=this._visualizationHandler,a.loadScript(i),a.title="Script '"+s.name+"' on "+s.designItem.name,await this._visualizationShell.openConfirmation(a,{x:100,y:100,width:600,height:500})){let c=a.getScriptCommands();if(c&&c.length){let p={commands:c};r&&(p.parameters=r),o&&(p.relativeSignalsPath=o);let d=JSON.stringify(p);s.designItem.setAttribute("@"+s.name,d),this._bindingsRefresh()}}}}async _editEvent(t,s,e){t=="js"?this._editJavascript(s,e):t=="blockly"?this._editBlockly(s,e):this._editSimpleScript(s,e)}refresh(){this._selectedItems!=null&&this._selectedItems.length?this.events=this._selectedItems[0].serviceContainer.getLastServiceWhere("eventsService",t=>t.isHandledElementFromEventsService(this._selectedItems[0])).getPossibleEvents(this._selectedItems[0]).map(t=>({...t,designItem:this._selectedItems[0]})):this.events=[],this._bindingsRefresh()}get selectedItems(){return this._selectedItems}set selectedItems(t){this._selectedItems!=t&&(this._selectedItems=t,this.refresh())}};customElements.define(P.is,P);import{TypedEvent as Le,cssFromString as Me}from"@node-projects/base-custom-webcomponent";import{BindingTarget as f}from"@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";import{PropertiesHelper as v}from"@node-projects/web-component-designer/dist/elements/services/propertiesService/services/PropertiesHelper.js";var S="bind-prop:",B="bind-attr:",R="bind-class:",V="bind-css:",A="bind-cssvar:",w="bind-content:",F="bind-visible:",He="bind(",Fe="--tmpBinding_",Xt=/{{(.*)}}/;function z(n){return n.constructor?.elementProperties!=null}function U(n){let t=[],s=[],e="";for(let i=0;i<n.length;i++)n[i]=="{"?(t.push(e),e=""):n[i]=="}"?(s.push(e),e=""):e+=n[i];return t.push(e),{parts:t,signals:s}}function L(n,t){let s=t.split("."),e=n;for(let i of s){if(e==null||typeof e!="object")return;e=e[i]}return e}var J=class{parts;signals;values;unsubscribeTargetValue;cleanupCalls=[];combinedName;disposed;valueChangedCb;visualizationHandler;element;relativeSignalPath;constructor(t,s,e,i,r,o,a,l){this.visualizationHandler=s,this.valueChangedCb=i,this.element=r,this.relativeSignalPath=o,this.parseIndirectBinding(e),this.values=new Array(this.signals.length);for(let c=0;c<this.signals.length;c++){let p=this.signals[c];if(p[0]==="?"&&p[1]==="?"){let h=p.substring(2);if(h.includes(".")){let u=L(a,h);this.handleValueChanged(u,c)}else{this.handleValueChanged(a[h],c);let u=()=>this.handleValueChanged(a[h],c),g=t.getChangedEventName(a,h);a.addEventListener(g,u),this.cleanupCalls.push(()=>a.removeEventListener(g,u))}continue}else if(p[0]==="#"&&p[1]==="#"){let h=p.substring(2);if(h.includes(".")){let u=L(r,h);this.handleValueChanged(u,c)}else{this.handleValueChanged(r[h],c);let u=()=>this.handleValueChanged(r[h],c),g=t.getChangedEventName(r,h);r.addEventListener(g,u),this.cleanupCalls.push(()=>r.removeEventListener(g,u))}continue}else if(p[0]==="\xA7"){let h=p.substring(1),u=l.valueProvider(h,{element:r,relativeSignalPath:o,root:a});u instanceof Promise?u.then(y=>this.handleValueChanged(y,c)):this.handleValueChanged(u,c),l.valueChangedCallbacks||(l.valueChangedCallbacks=new Map);let g=l.valueChangedCallbacks.get(h);g==null&&(g=[],l.valueChangedCallbacks.set(h,g)),g.push(()=>{let y=l.valueProvider(h,{element:r,relativeSignalPath:o,root:a});y instanceof Promise?y.then(x=>this.handleValueChanged(x,c)):this.handleValueChanged(y,c)})}else(p[0]==="?"||p[0]==="#")&&(p.includes(".")?p=L(a,p.substring(1)):p=a[p.substring(1)]);let d=(h,u)=>this.handleValueChanged(u.val,c),m=this.visualizationHandler.subscribeState(p,d);this.cleanupCalls.push(()=>this.visualizationHandler.unsubscribeState(this.signals[c],d,m))}}parseIndirectBinding(t){let{parts:s,signals:e}=U(t);this.parts=s,this.signals=e;for(let i=0;i<e.length;i++)e[i][0]=="."&&(e[i]=this.visualizationHandler.getNormalizedSignalName(e[i],this.relativeSignalPath,this.element))}handleValueChanged(t,s){this.values[s]=t;let e=this.parts[0];for(let i=0;i<this.parts.length-1;i++){let r=this.values[i];if(r==null)return;e+=r+this.parts[i+1]}if(e[0]=="."&&(e=this.visualizationHandler.getNormalizedSignalName(e,this.relativeSignalPath,this.element)),this.combinedName!=e&&(this.unsubscribeTargetValue&&this.visualizationHandler.unsubscribeState(this.combinedName,this.unsubscribeTargetValue[0],this.unsubscribeTargetValue[1]),!this.disposed)){this.combinedName=e;let i=(r,o)=>this.valueChangedCb(o);this.unsubscribeTargetValue=[i,this.visualizationHandler.subscribeState(e,i)]}}dispose(){this.disposed=!0,this.unsubscribeTargetValue&&(this.visualizationHandler.unsubscribeState(this.combinedName,this.unsubscribeTargetValue[0],this.unsubscribeTargetValue[1]),this.unsubscribeTargetValue=null);for(let t=0;t<this.signals.length;t++)this.cleanupCalls[t]()}setState(t){this.disposed||this.visualizationHandler.setState(this.combinedName,t)}},se=class n{_visualizationHandler;namedConverterCallback;constructor(t){this._visualizationHandler=t}getChangedEventName(t,s){let e=s.indexOf("::");return e>=0?s.substring(e+2):t instanceof HTMLInputElement||t instanceof HTMLSelectElement?"change":z(t)?v.camelToDashCase(s):v.camelToDashCase(s)+"-changed"}parseBinding(t,s,e,i,r){let o=s.substring(r.length);if(i===f.cssvar&&(o="--"+o),!e.startsWith("{")){let l={signal:e,target:i};if(e[0]==="="){if(e=e.substring(1),l.signal=e,e.includes("::")){let c=e.split("::");e=c[0],l.signal=e,l.events=c[1].split(",")}l.twoWay=!0,l.events||(t instanceof HTMLInputElement?l.events=[this.getChangedEventName(t,o)]:t instanceof HTMLSelectElement?l.events=[this.getChangedEventName(t,o)]:z(t)?l.events=[this.getChangedEventName(t,o)]:(l.events=[this.getChangedEventName(t,o)],l.maybeLitElement=!0,l.litEventNames=[this.getChangedEventName(t,o)]))}if(e[0]==="!"&&(l.signal=e.substring(1),l.inverted=!0),l.signal.includes(";")){let c=l.signal.split(";");l.expression=c.pop(),l.signal=c.join(";")}return i===f.cssvar||i===f.class?[n.dotToCamelCase(o),l]:i===f.attribute?[o,l]:[v.dashToCamelCase(o),l]}let a=JSON.parse(e);return a.target=i,a.twoWay&&(a.events==null||a.events.length==0)&&(t instanceof HTMLInputElement?a.events=["change"]:t instanceof HTMLSelectElement?a.events=["change"]:a.events=[this.getChangedEventName(t,o)]),i===f.cssvar||i===f.class?[n.dotToCamelCase(o),a]:i===f.attribute?[o,a]:[v.dashToCamelCase(o),a]}serializeBinding(t,s,e){let i={...e};delete i.type,e.twoWay?e.events!=null&&e.events.length==1&&(t instanceof HTMLInputElement&&e.events?.[0]=="change"||t instanceof HTMLSelectElement&&e.events?.[0]=="change"||z(t)&&e.events?.[0]==s||!z(t)&&e.events?.[0]==s+"-changed")&&delete i.events:(delete i.events,delete i.expressionTwoWay);let r=i.twoWay&&i.events?.length>0?"::"+i.events.join(","):"",o=!1;return(r&&e.expression?.includes("::")||e.expressionTwoWay?.includes("::"))&&(o=!0),e.signal.trim()[0]=="{"&&(o=!0),!o&&e.target==f.property&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?s=="textContent"?[w+"text",(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:s=="innerHTML"?[w+"html",(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:[S+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!o&&e.target==f.property&&e.expression&&!e.expression.includes(`
385
- `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?s=="textContent"?[w+"text",(e.inverted?"!":"")+e.signal+";"+e.expression+r]:s=="innerHTML"?[w+"html",(e.inverted?"!":"")+e.signal+";"+e.expression+r]:[S+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!o&&e.target==f.attribute&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[B+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!o&&e.target==f.attribute&&e.expression&&!e.expression.includes(`
386
- `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[B+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!o&&e.target==f.class&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[R+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!o&&e.target==f.class&&e.expression&&!e.expression.includes(`
387
- `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[R+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!o&&e.target==f.css&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[V+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!o&&e.target==f.css&&e.expression&&!e.expression.includes(`
388
- `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[V+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!o&&e.target==f.cssvar&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[A+n.camelToDotCase(s.substring(2)),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!o&&e.target==f.cssvar&&e.expression&&!e.expression.includes(`
389
- `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[A+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:((e.inverted===null||e.inverted===!1)&&delete i.inverted,(e.expression===null||e.expression==="")&&delete i.expression,(e.expressionTwoWay===null||e.expressionTwoWay==="")&&delete i.expressionTwoWay,(e.twoWay===null||e.twoWay===!1)&&delete i.twoWay,delete i.target,e.historic||delete i.historic,e.target==f.content?[w+"html",JSON.stringify(i)]:e.target==f.attribute?[B+v.camelToDashCase(s),JSON.stringify(i)]:e.target==f.class?[R+n.camelToDotCase(s),JSON.stringify(i)]:e.target==f.css?[V+v.camelToDashCase(s),JSON.stringify(i)]:e.target==f.cssvar?[A+n.camelToDotCase(s.substring(2)),JSON.stringify(i)]:e.target==f.property&&s=="innerHTML"?[w+"html",JSON.stringify(i)]:e.target==f.property&&s=="textContent"?[w+"text",JSON.stringify(i)]:[S+v.camelToDashCase(s),JSON.stringify(i)])}getBindingAttributeName(t,s,e){return e==f.attribute?B+v.camelToDashCase(s):e==f.class?R+n.camelToDotCase(s):e==f.css?V+v.camelToDashCase(s):e==f.visible?F:e==f.cssvar?A+n.camelToDotCase(s):e==f.property&&s=="innerHTML"?w+"html":e==f.property&&s=="textContent"?w+"text":S+v.camelToDashCase(s)}*getBindings(t){if(t.attributes)for(let s of t.attributes)s.name.startsWith(S)?yield this.parseBinding(t,s.name,s.value,f.property,S):s.name.startsWith(w)?yield this.parseBinding(t,s.name==="bind-content:html"?"bind-prop:inner-h-t-m-l":"bind-prop:text-content",s.value,f.property,S):s.name.startsWith(B)?yield this.parseBinding(t,s.name,s.value,f.attribute,B):s.name.startsWith(R)?yield this.parseBinding(t,s.name,s.value,f.class,R):s.name.startsWith(V)?yield this.parseBinding(t,s.name,s.value,f.css,V):s.name.startsWith(A)?yield this.parseBinding(t,s.name,s.value,f.cssvar,A):s.name.startsWith(F)&&(yield this.parseBinding(t,s.name,s.value,f.visible,F))}applyAllBindings(t,s,e,i,r){let o=[],a=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();){let c=this.getBindings(l);for(let p of c)try{let d=this.applyBinding(l,p,s,e,i);if(o.push(d),p[1].maybeLitElement&&l.localName.includes("-")&&!customElements.get(l.localName)){let m=l,h=p;customElements.whenDefined(l.localName).then(()=>{z(m)&&(d(),h[1].events=h[1].litEventNames,o.push(this.applyBinding(m,h,s,e,i)))})}}catch(d){console.warn("error applying binding",l,p,d)}if(r&&r(l)){l=a.nextSibling();continue}}return o}static#e=0;async parseCssBindings(t,s,e,i){let r=await import("@node-projects/css-parser"),o=r.parse(t),a;for(let c of o.stylesheet.rules)if(c.type===r.CssTypes.rule){for(let p of c.declarations)if(p.type===r.CssTypes.declaration&&p.value.includes(He)){let d=this.parseCssBinding(p.value,s,e,i);p.value=d[0],a?a.push(...d[1]):a=d[1]}}let l=r.stringify(o,{indent:"",compress:!0});return[Me(l),a]}parseCssBinding(t,s,e,i,r){t=t.trim();let o="",a="",l=!1,c="",p=!1,d=null,m=[];for(let h=0;h<t.length;h++){let u=t[h];if(l)if(p)c+=u;else if(d&&u==="\\")p=!0;else if(u===d)d=null;else if(d===null&&u===")"){let g=n.#e++,y=Fe+g,x=[y,{signal:c,target:f.cssvar}];c.startsWith("{")&&(x=JSON.parse(c)),m.push(this.applyBinding(s,x,e,i,r)),o+="var("+y+")",l=!1,c=""}else c+=u;else u==="("?(a!=="bind"?(o+=a,o+=u):(l=!0,t[h+1]==="'"||t[h+1]==='"'?(h++,d=t[h]):d=null),a=""):u===" "||u===","||u==="("||u==="+"||u==="-"||u==="*"||u==="/"?(o+=a+u,a=""):a+=u}return[o+a,m]}applyBinding(t,s,e,i,r){let o=[],a,l=()=>{for(let m of o)this._visualizationHandler.unsubscribeState(m[0],m[1],m[2]);if(a)for(let m of a)m()},c=s[1].signal.split(";"),p=new Array(c.length);for(let m=0;m<c.length;m++){let h=c[m];if(p[m]="__"+m,h.includes(":")){let u=h.split(":");p[m]=u[0],h=u[1],c[m]=h}if(h[0]==="?"){if(i){let u=h.substring(1);if(u[0]=="?")c[m]=u;else{c[m]=i[u],u[0]==="$"&&(u=u.substring(1),c[m]="$"+i[u]);let g=()=>{l(),this.applyBinding(t,s,e,i,r)},y=this.getChangedEventName(i,u);i.addEventListener(y,g),a||(a=[]),a.push(()=>i.removeEventListener(y,g))}}}else if(h[0]==="#"){let u=h.substring(1);if(u[0]=="#")c[m]=u;else{c[m]=i[u],u[0]==="$"&&(u=u.substring(1),c[m]="$"+i[u]);let g=()=>{l(),this.applyBinding(t,s,e,i,r)},y=this.getChangedEventName(t,u);i.addEventListener(y,g),a||(a=[]),a.push(()=>i.removeEventListener(y,g))}}h[0]==="."&&(c[m]=this._visualizationHandler.getNormalizedSignalName(h,e,t))}let d=new Array(c.length);for(let m=0;m<c.length;m++){let h=c[m];if(h[0]==="?"){if(i){let u=h.substring(1),g=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,i[u],d,m,p,!1,e),y=!1)};i.addEventListener(v.camelToDashCase(u)+"-changed",g),a||(a=[]),a.push(()=>i.removeEventListener(v.camelToDashCase(u)+"-changed",g));try{this.handleValueChanged(t,i,s,i[u],d,m,p,!1,e)}catch(y){console.error(y)}s[1].twoWay&&m==0&&this.addTwoWayBinding(s,t,y=>i[u]=y)}}else if(h[0]==="#"){let u=h.substring(1),g=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,t[u],d,m,p,!1,e),y=!1)};t.addEventListener(v.camelToDashCase(u)+"-changed",g),a||(a=[]),a.push(()=>t.removeEventListener(v.camelToDashCase(u)+"-changed",g));try{this.handleValueChanged(t,i,s,t[u],d,m,p,!1,e)}catch(y){console.error(y)}s[1].twoWay&&m==0&&this.addTwoWayBinding(s,t,y=>t[u]=y)}else if(h[0]==="$"){let u=h.substring(1);u[0]==="."&&(u=this._visualizationHandler.getNormalizedSignalName(u,e,t)),this._visualizationHandler.getObject(u).then(g=>{this.handleValueChanged(t,i,s,g,d,m,p,!0,e)})}else if(h[0]==="\xA7"){let u=h.substring(1),g=r.valueProvider(u,{element:t,binding:s,relativeSignalPath:e,root:i});g instanceof Promise?g.then(x=>this.handleValueChanged(t,i,s,x,d,m,p,!0,e)):this.handleValueChanged(t,i,s,g,d,m,p,!0,e),r.valueChangedCallbacks||(r.valueChangedCallbacks=new Map);let y=r.valueChangedCallbacks.get(u);y==null&&(y=[],r.valueChangedCallbacks.set(u,y)),y.push(()=>{let x=r.valueProvider(u,{element:t,binding:s,relativeSignalPath:e,root:i});x instanceof Promise?x.then(me=>this.handleValueChanged(t,i,s,me,d,m,p,!0,e)):this.handleValueChanged(t,i,s,x,d,m,p,!0,e)})}else if(h.includes("{")){let u=new J(this,this._visualizationHandler,h,g=>this.handleValueChanged(t,i,s,g.val,d,m,p,!1,e),t,e,i,r);a||(a=[]),a.push(()=>u.dispose()),s[1].twoWay&&m==0&&this.addTwoWayBinding(s,t,g=>u.setState(g))}else if(s[1].historic)if(s[1].historic.reloadInterval){let u={timerId:-1},g=async()=>{let y=await this._visualizationHandler.getHistoricData(h,s[1].historic);this.handleValueChanged(t,i,s,y?.values,d,m,p,!0,e),u.timerId!==null&&(u.timerId=setTimeout(g,s[1].historic.reloadInterval))};g(),a||(a=[]),a.push(()=>{u.timerId>0&&clearTimeout(u.timerId),u.timerId=null})}else this._visualizationHandler.getHistoricData(h,s[1].historic).then(u=>this.handleValueChanged(t,i,s,u?.values,d,m,p,!0,e));else{let u=(g,y)=>this.handleValueChanged(t,i,s,y.val,d,m,p,!1,e);o.push([h,u,this._visualizationHandler.subscribeState(h,u)]),this._visualizationHandler.getState(h).then(g=>this.handleValueChanged(t,i,s,g?.val,d,m,p,!1,e)),s[1].twoWay&&m==0&&this.addTwoWayBinding(s,t,g=>this._visualizationHandler.setState(h,g))}}return l}addTwoWayBinding(t,s,e){t[1].expressionTwoWay&&(t[1].compiledExpressionTwoWay||(t[1].expressionTwoWay.includes("return ")?t[1].compiledExpressionTwoWay=new Function(["value"],t[1].expressionTwoWay):t[1].compiledExpressionTwoWay=new Function(["value"],"return "+t[1].expressionTwoWay)));for(let i of t[1].events){let r=s[i];r instanceof Le?r.on(()=>{let o;t[1].target==f.attribute?o=s.getAttribute(t[0]):o=s[t[0]],o=n.parseValueWithType(o,t),t[1].compiledExpressionTwoWay&&(o=t[1].compiledExpressionTwoWay(o)),e(o)}):s.addEventListener(i,o=>{let a;t[1].target==f.attribute?a=s.getAttribute(t[0]):a=s[t[0]],a=n.parseValueWithType(a,t),t[1].compiledExpressionTwoWay&&(a=t[1].compiledExpressionTwoWay(a)),e(a)})}}static parseValueWithType(t,s){if(s[1].type)switch(s[1].type){case"number":return parseFloat(t);case"boolean":return t===!0||t==="true"||!!parseInt(t);case"string":return t?.toString();case"integer":return parseInt(t)}return t}handleValueChanged(t,s,e,i,r,o,a,l,c){let p=i;if(!l&&o==0&&(p=n.parseValueWithType(p,e)),r[o]=p,e[1].expression&&(e[1].compiledExpression||(a.push("__res"),a.push("__ctx"),e[1].expression.includes("return ")?e[1].compiledExpression=new Function(a,e[1].expression):e[1].compiledExpression=new Function(a,"return "+e[1].expression)),r[a.length-1]={element:t,root:s,boundNames:e[1].signal,boundTargetName:e[0],boundTargetType:e[1].target},p=e[1].compiledExpression(...r),r[a.length-1]=p),e[1].converter)if(typeof e[1].converter=="string")p=this.namedConverterCallback(e[1].converter,p,t,e);else{let d=p!=null?p.toString():p;if(d in e[1].converter){let m=e[1].converter[d];typeof m=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=m}else{let m=!1,h=parseFloat(p);for(let u in e[1].converter)if(u.length>2&&u[0]===">"&&u[1]==="="){let g=parseFloat(u.substring(2));if(h>=g){let y=e[1].converter[u];typeof y=="string"?p=new Function(a,"return `"+e[1].converter[u]+"`")(...r):p=y,m=!0;break}}else if(u.length>2&&u[0]==="<"&&u[1]==="="){let g=parseFloat(u.substring(2));if(h<=g){let y=e[1].converter[u];typeof y=="string"?p=new Function(a,"return `"+e[1].converter[u]+"`")(...r):p=y,m=!0;break}}else if(u.length>1&&u[0]===">"){let g=parseFloat(u.substring(1));if(h>g){let y=e[1].converter[u];typeof y=="string"?p=new Function(a,"return `"+e[1].converter[u]+"`")(...r):p=y,m=!0;break}}else if(u.length>1&&u[0]==="<"){let g=parseFloat(u.substring(1));if(h<g){let y=e[1].converter[u];typeof y=="string"?p=new Function(a,"return `"+e[1].converter[u]+"`")(...r):p=y,m=!0;break}}else{let g=u.split("-");if(g.length>1&&(g[0]===""||h>=parseFloat(g[0]))&&(g[1]===""||parseFloat(g[1])>=h)){let y=e[1].converter[u];typeof y=="string"?p=new Function(a,"return `"+e[1].converter[u]+"`")(...r):p=y,m=!0;break}}!m&&e[1].converterDefault!==void 0&&(p=e[1].converterDefault)}}if(e[1].inverted&&(p=!p),e[1].writeBackSignal){let d=e[1].writeBackSignal;d[0]==="."&&(d=c+d),this._visualizationHandler.setState(d,p,!0)}e[1].target==f.property?t[e[0]]=p:e[1].target==f.attribute?typeof p=="boolean"?p?t.setAttribute(e[0],""):t.removeAttribute(e[0]):t.setAttribute(e[0],p):e[1].target==f.css?t.style[e[0]]=p:e[1].target==f.cssvar?t.style.setProperty(e[0],p):e[1].target==f.class?p?t.classList.add(e[0]):t.classList.remove(e[0]):e[1].target==f.visible&&(t.style.visibility=p?"":"collapse")}static camelToDotCase(t){return t.replace(/([A-Z])/g,s=>`.${s[0].toLowerCase()}`)}static dotToCamelCase(t){return t.replace(/\.([a-z])/g,s=>s[1].toUpperCase())}};var ie=class{name;relativeSignalsPath;commands;parameters};import{deepValue as _,setDeepValue as ae,sleep as Je}from"@node-projects/web-component-designer/dist/elements/helper/Helper.js";import W from"long";var M="cyclic",Ue={pointerdown:"pointerup",pointerenter:"pointerleave",mouseenter:"mouseleave",mouseover:"mouseout",focus:"blur",focusin:"focusout",keydown:"keyup"},ne=class{_visualizationHandler;_subscriptionCallback=()=>{};constructor(n){this._visualizationHandler=n}async execute(n,t){let s=-1,e=!1,i=t.event?.type,r=i?Ue[i]:null;if(r){let o=t.element;i=="pointerdown"&&(o=window),o.addEventListener(r,()=>{e=!0},{once:!0})}for(let o=0;o<n.length;o++){let a=n[o];if(a.type=="Exit")break;if(a.type=="Goto"){let l=await this.getValue(a.label,t);if(o=n.findIndex(c=>c.type=="Label"&&c.label==l),o<0)break}else if(a.type=="Condition"){let l=await this.getValue(a.value1,t),c=await this.getValue(a.value2,t),p=await this.getValue(a.comparisonType,t),d=!1;switch(p){case"==null":d=l==null;break;case"!=null":d=l!=null;break;case"==true":d=l==!0;break;case"==false":d=l==!1;break;case"==":d=l==c;break;case"!=":d=l!=c;break;case">":d=l>c;break;case"<":d=l<c;break;case">=":d=l>=c;break;case"<=":d=l<=c;break;case"&&":d=l&&c;break;case"||":d=l||c;break}if(d){await this.runExternalScript(await this.getValue(a.trueScriptName,t),await this.getValue(a.trueScriptType,t));let m=await this.getValue(a.trueGotoLabel,t);if(m&&(o=n.findIndex(h=>h.type=="Label"&&h.label==m),o<0))break}else{await this.runExternalScript(await this.getValue(a.falseScriptName,t),await this.getValue(a.falseScriptType,t));let m=await this.getValue(a.falseGotoLabel,t);if(m&&(o=n.findIndex(h=>h.type=="Label"&&h.label==m),o<0))break}}else if(a.type=="Repeat"){let l=await this.getValue(a.label,t),c=await this.getValue(a.count,t);if(await this.getValue(a.mode,t)=="eventValid"&&e){e=!1;continue}if(c!=0&&s==-1&&(s=c-1),s==0||(s>0&&s--,o=-1,l&&(o=n.findIndex(d=>d.type=="Label"&&d.label==l),o<0)))continue}else if(!await this.runScriptCommand(a,t))break}}async getValueFromTarget(n,t,s){return n==="property"?_(s.root,t):n==="elementProperty"?_(s.element,t):(await this._visualizationHandler.getState(this.getSignalName(t,s)))?.val}async setValueOnTarget(n,t,s,e){n==="property"?ae(s.root,t,e):n==="elementProperty"?ae(s.element,t,e):await this._visualizationHandler.setState(this.getSignalName(t,s),e)}async runExternalScript(n,t){}async runScriptCommand(command,context){switch(command.type){case"Comment":case"Label":case"Condition":case"Goto":case"Exit":case"Repeat":break;case"OpenUrl":{window.open(await this.getValue(command.url,context),command.target);break}case"Delay":{let n=await this.getValue(command.value??500,context);await Je(n);break}case"Console":{let n=await this.getValue(command.target??"log",context),t=await this.getValue(command.message,context);console[n](t);break}case"ToggleSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),s=await this.getValueFromTarget(t,n,context);await this._visualizationHandler.setState(this.getSignalName(n,context),!s);break}case"ToggleSignalValueThroughList":{let n=await this.getValue(command.valueList,context),t=await this.getValue(command.signal,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,t,context),i=n.indexOf(e)+1;i>=n.length&&(i=0);let r=n[i];await this._visualizationHandler.setState(this.getSignalName(t,context),r);break}case"SetSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context);await this.setValueOnTarget(t,n,context,await this.getValue(command.value,context));break}case"IncrementSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,n,context)+await this.getValue(command.value,context);await this.setValueOnTarget(t,n,context,e);break}case"DecrementSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,n,context)-await this.getValue(command.value,context);await this.setValueOnTarget(t,n,context,e);break}case"CalculateSignalValue":{let formula=await this.getValue(command.formula,context),target=await this.getValue(command.target,context),targetSignal=await this.getValue(command.targetSignal,context),nm=await this.parseStringWithValues(formula,context),result=eval(nm);await this.setValueOnTarget(target,targetSignal,context,result);break}case"SetBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=W.fromNumber(1).shiftLeft(t),r=W.fromNumber(e).or(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"ClearBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=W.fromNumber(1).shiftLeft(t);i.negate();let r=W.fromNumber(e).and(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"ToggleBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=W.fromNumber(1).shiftLeft(t),r=W.fromNumber(e).xor(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"Javascript":{let n=await this.getValue(command.script,context),t=context;t.shadowRoot=context.element.getRootNode(),t.instance=context.shadowRoot.host,command.compiledScript||(command.compiledScript=new Function("context",n)),command.compiledScript(t);break}case"SetElementProperty":{command=N.upgradeSetElementProperty(command);let n=await this.getValue(command.name,context);n===""&&(n=null);let t=await this.getValue(command.value,context),s=await this.getValue(command.parentIndex??0,context),e=await this.getValue(command.target??"property",context),i=await this.getValue(command.targetSelectorTarget??"container",context),r=await this.getValue(command.targetSelector,context),o=await this.getValue(command.mode??"toggle",context),a=this.getTargetFromTargetSelector(context,i,s,r);for(let l of a)e=="attribute"?l.setAttribute(n,t):e=="property"?l[n]=t:e=="css"?l.style[n]=t:e=="class"&&(o==="toggle"?l.classList.toggle(n??t):o==="remove"?l.classList.remove(n??t):l.classList.add(n??t));break}case"SubscribeSignal":{let n=await this.getValue(command.signal,context);if(await this.getValue(command.oneTime,context)){let s=()=>{this._visualizationHandler.unsubscribeState(n,s,null)};this._visualizationHandler.subscribeState(n,s)}else this._visualizationHandler.subscribeState(n,this._subscriptionCallback);break}case"UnsubscribeSignal":{let n=await this.getValue(command.signal,context);this._visualizationHandler.unsubscribeState(n,this._subscriptionCallback,null);break}case"WriteSignalsInGroup":{let n=await this.getValue(command.group,context);this._visualizationHandler.writeSignalsInGroup(n);break}case"ClearSignalsInGroup":{let n=await this.getValue(command.group,context);this._visualizationHandler.clearSignalsInGroup(n);break}case"RunScript":{let n=await this.getValue(command.name,context),t=await this.getValue(command.scriptType,context);this.runExternalScript(n,t);break}case"ShowMessageBox":{let n=null,t=await this.getValue(command.exitScriptOnCancel,context);if(await this.getValue(command.buttons,context)=="yesNo"){let i=await this.getValue(command.message,context);confirm(i)?n=1:n=2}else{let i=await this.getValue(command.message,context);alert(i),n=1}let e=await this.getValue(command.resultSignal,context);if(e&&this._visualizationHandler.setState(e,n),t&&n!=1)return!1;break}case"ShowPrompt":{let n=await this.getValue(command.message,context),t=await this.getValue(command.default,context),s=prompt(n,t),e=await this.getValue(command.resultSignal,context);e&&s&&this._visualizationHandler.setState(e,s);break}case"Login":case"Logout":case"CloseDialog":case"OpenDialog":case"OpenScreen":case"SwitchLanguage":case"CopySignalValuesFromFolder":case"ExportSignalValuesAsJson":case"ImportSignalValuesFromJson":{alert('command: "'+command.type+'" is not yet implemented');break}}return!0}getTarget(n,t,s){if(t==="container"){let e=n.element.getRootNode().host;for(let i=0;i<(s??0);i++)e=e.getRootNode().host;return e}else if(t==="element"){let e=n.element;for(let i=0;i<(s??0);i++)e=e.parentElement;return e}return null}getTargetFromTargetSelector(n,t,s,e){let i=this.getTarget(n,t,s),r=[i];return e&&(t==="container"?r=i.shadowRoot.querySelectorAll(e):r=i.querySelectorAll(e)),r}async getValue(value,outerContext){if(value==null)return null;if(typeof value=="object")switch(value.source){case"property":return _(outerContext.root,value.name);case"elementProperty":return _(outerContext.element,value.name);case"signal":return(await this._visualizationHandler.getState(this.getSignalName(value.name,outerContext)))?.val;case"signalInProperty":{let n=_(outerContext.root,value.name);return(await this._visualizationHandler.getState(this.getSignalName(n,outerContext)))?.val}case"event":{let n=outerContext.event;return value.name&&(n=_(n,value.name)),n}case"parameter":return outerContext.parameters[value.name];case"context":return _(outerContext,value.name);case"complexString":{let n=value.name;return n!=null?await this.parseStringWithValues(n,outerContext):null}case"complexSignal":{let n=value.name;if(n!=null){let t=await this.parseStringWithValues(n,outerContext);return(await this._visualizationHandler.getState(this.getSignalName(t,outerContext)))?.val}return null}case"expression":{var ctx=outerContext;return eval(value.name)}}return value}async getStateOrFieldOrParameter(name,context){if(name[0]==="\xA7"){var ctx=context;return eval("ctx."+name.substring(1))}else{if(name[0]==="?"&&name[1]==="?")return context.root[name.substring(2)];if(name[0]==="?")return await this._visualizationHandler.getState(this.getSignalName(context.root[name.substring(1)],context))}return await this._visualizationHandler.getState(this.getSignalName(name,context))}async parseStringWithValues(n,t){let s=U(n),e=await Promise.all(s.signals.map(r=>this.getStateOrFieldOrParameter(this.getSignalName(r,t),t))),i=s.parts[0];for(let r=0;r<s.parts.length-1;r++){let o=e[r];typeof o=="object"&&(o=o.val),o==null&&(o=""),i+=o+s.parts[r+1]}return i}getSignalName(n,t){return n[0]==="."?t.relativeSignalsPath+n:n}createScriptContext(n,t,s,e,i){return{root:n,event:t,element:s,parameters:e,relativeSignalsPath:i}}async assignAllScripts(n,t,s,e,i,r,o,a){r??=this.createScriptContext;let l=await this.loadAndInitJsObject(n,t,s,e,a);for(let c of s.querySelectorAll("*"))for(let p of c.attributes)if(p.name[0]==="@")try{let d=p.name.substring(1),m=p.value.trim(),h=d.startsWith(M),u=h?parseInt(d.substring(d.indexOf(":")+1)):null,g=await this.resolveHandler(m,l,c,s,e,i,r,o,d);g&&this.bindHandler(c,d,h,u,g)}catch{console.warn("error assigning script",c,p)}return l}async loadAndInitJsObject(n,t,s,e,i){if(!t)return null;try{let o=await import(URL.createObjectURL(new Blob([t],{type:"application/javascript"})));return i?i(o):o.init?.(e,s),o}catch(r){return console.error("error parsing javascript - "+n,r),null}}async resolveHandler(n,t,s,e,i,r,o,a,l){if(n[0]!=="{")return p=>{t?.[n]?t[n](p,s,e,i):console.warn(`javascript function named: "${n}" not found, maybe missing a "export" ?`)};let c=JSON.parse(n);if("commands"in c)return p=>this.execute(c.commands,o(i,p,s,c.parameters,c.relativeSignalsPath));if("blocks"in c){let p=null;return async d=>{p??=await G(c),p(d,e,c.parameters,c.relativeSignalsPath??"",r,o(i,d,s,c.parameters,c.relativeSignalsPath))}}if("name"in c){if(a)return a(s,l,c),null;let p=c.name;return d=>{t?.[p]?t[p](d,s,e,i,c.parameters):console.warn(`javascript function named: "${p}" not found, maybe missing a "export" ?`)}}return null}bindHandler(n,t,s,e,i){if(!s){n.addEventListener(t,i);return}let r=setInterval(()=>{n.isConnected?i(null):clearInterval(r)},e)}};import{OverlayLayer as Xe,DesignItem as T,InsertAction as Ge,BindingTarget as k,PropertyType as H}from"@node-projects/web-component-designer";var re=class{constructor(t,s){this._bindingsHelper=t,this._visualizationHandler=s}_bindingsHelper;_visualizationHandler;rectMap=new Map;rect;dragEnter(t,s,e){let i=T.GetDesignItem(e);if(i&&!i.isRootItem){let r=t.getNormalizedElementCoordinates(e);this.rect=t.overlayLayer.drawRect("IobrokerWebuiBindableObjectDragDropService",r.x,r.y,r.width,r.height,"",null,Xe.Background),this.rect.style.fill="#ff0000",this.rect.style.opacity="0.3",this.rectMap.set(e,this.rect)}}dragLeave(t,s,e){let i=T.GetDesignItem(e);if(i&&!i.isRootItem){let r=this.rectMap.get(e);t.overlayLayer.removeOverlay(r),this.rectMap.delete(e)}}dragOver(t,s,e){return"copy"}async drop(t,s,e,i){for(let l of this.rectMap.values())t.overlayLayer.removeOverlay(l);this.rectMap.clear();let r=T.GetDesignItem(i),o=await this._visualizationHandler.getObject(e.fullName),a=this._visualizationHandler.getSignalInformation(o);if(r&&!r.isRootItem)if(i instanceof HTMLInputElement){let l={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(i,i.type=="checkbox"?"checked":"value",l);r.setAttribute(c[0],c[1])}else{let l={signal:e.fullName,target:k.content},c=this._bindingsHelper.serializeBinding(i,null,l);r.setAttribute(c[0],c[1])}else{let l=t.getNormalizedEventCoordinates(s),c,p,d=await this._visualizationHandler.getState(e.fullName);if(a.role==="url"&&typeof d?.val=="string")if(d.val.endsWith("jpg")||d.val.endsWith("jpeg")||d.val.endsWith("png")||d.val.endsWith("gif")||d.val.endsWith("svg")){let m=document.createElement("img");c=T.createDesignItemFromInstance(m,t.serviceContainer,t.instanceServiceContainer),p=c.openGroup("Insert");let h={signal:e.fullName,target:k.property},u=this._bindingsHelper.serializeBinding(m,"src",h);c.setAttribute(u[0],u[1]),c.element.src=d.val}else if(d.val.endsWith("mp4")){let m=document.createElement("video");c=T.createDesignItemFromInstance(m,t.serviceContainer,t.instanceServiceContainer),p=c.openGroup("Insert");let h={signal:e.fullName,target:k.property},u=this._bindingsHelper.serializeBinding(m,"src",h);c.setAttribute(u[0],u[1]),c.element.src=d.val}else{let m=document.createElement("iframe");c=T.createDesignItemFromInstance(m,t.serviceContainer,t.instanceServiceContainer),p=c.openGroup("Insert");let h={signal:e.fullName,target:k.property},u=this._bindingsHelper.serializeBinding(m,"src",h);c.setAttribute(u[0],u[1]),c.element.src=d.val}if(!c){let m=document.createElement("input");c=T.createDesignItemFromInstance(m,t.serviceContainer,t.instanceServiceContainer),p=c.openGroup("Insert");let h=a.writeable!==!1,u={signal:e.fullName,target:k.property,twoWay:h},g=this._bindingsHelper.serializeBinding(m,"value",u);a.type==="boolean"?(g=this._bindingsHelper.serializeBinding(m,"checked",u),c.setAttribute("type","checkbox")):a.role=="date"?(u.twoWay=h,g=this._bindingsHelper.serializeBinding(m,"value-as-number",u),c.setAttribute("type","date"),c.setAttribute("readonly","")):a.role=="datetime"&&(u.twoWay=h,g=this._bindingsHelper.serializeBinding(m,"value-as-number",u),c.setAttribute("type","datetime-local"),c.setAttribute("readonly","")),c.setAttribute(g[0],g[1])}c.setStyle("position","absolute"),c.setStyle("left",l.x+"px"),c.setStyle("top",l.y+"px"),t.instanceServiceContainer.undoService.execute(new Ge(t.rootDesignItem,t.rootDesignItem.childCount,c)),p.commit(),requestAnimationFrame(()=>t.instanceServiceContainer.selectionService.setSelectedElements([c]))}}dragOverOnProperty(t,s,e){return"copy"}dropOnProperty(t,s,e,i){if(s.type=="signal"){s.service.setValue(i,s,e.fullName);return}let r={signal:e.fullName,target:k.property};s.propertyType==H.attribute&&(r.target=k.attribute),s.propertyType==H.cssValue&&(r.target=k.css),r.signal=e.fullName,r.twoWay=s.propertyType==H.property||s.propertyType==H.propertyAndAttribute;let o=i[0].openGroup("drop binding");for(let a of i){let l=this._bindingsHelper.serializeBinding(a.element,s.name,r);a.setAttribute(l[0],l[1])}o.commit()}};import{BindingMode as X,BindingTarget as oe,PropertiesHelper as $e}from"@node-projects/web-component-designer";var le=class n{constructor(t){this._bindingsHelper=t}_bindingsHelper;static type="visualization-binding";getBindings(t){return Array.from(this._bindingsHelper.getBindings(t.element)).map(e=>({targetName:e[1].target===oe.css||e[1].target===oe.attribute?$e.camelToDashCase(e[0]):e[0],target:e[1].target,mode:e[1].twoWay?X.twoWay:X.oneWay,invert:e[1].inverted,bindableObjectNames:e[1].signal.split(";"),expression:e[1].expression,expressionTwoWay:e[1].expressionTwoWay,converter:e[1].converter,type:n.type,service:this,changedEvents:e[1].events,historic:e[1].historic,writeBackSignal:e[1].writeBackSignal}))}setBinding(t,s){let e={signal:s.bindableObjectNames.join(";"),target:s.target};e.inverted=s.invert,e.twoWay=s.mode==X.twoWay,e.expression=s.expression,e.expressionTwoWay=s.expressionTwoWay,e.historic=s.historic,e.type=s.type,e.converter=s.converters,e.target=s.target,e.events=s.changedEvents;let i=this._bindingsHelper.serializeBinding(t.element,s.targetName,e),r=t.openGroup("edit_binding");return t.setAttribute(i[0],i[1]),r.commit(),!0}clearBinding(t,s,e){let i=this._bindingsHelper.getBindingAttributeName(t.element,s,e);return t.removeAttribute(i),!0}};var ce=class{getRefactorings(t){let s=[];for(let e of t){let i=e.serviceContainer.bindingService.getBindings(e);if(i)for(let r of i)for(let o of r.bindableObjectNames){let a="signal",l="";if(o.includes(":")){let c=o.split(":")[0],p=o.substring(c.length+1);p.startsWith("?")&&(p=p.substring(1),l="?",a="property",p.startsWith("?")&&(p=p.substring(1),l="??")),s.push({service:this,name:p,itemType:a,designItem:e,type:"binding",sourceObject:r,display:r.target+"/"+r.targetName+" - "+c+":",shortName:c,prefix:l})}else o.startsWith("?")&&(o=o.substring(1),l="?",a="property",o.startsWith("?")&&(o=o.substring(1),l="??")),s.push({service:this,name:o,itemType:a,designItem:e,type:"binding",sourceObject:r,display:r.target+"/"+r.targetName,prefix:l})}}return s}refactor(t,s,e){let i=t.sourceObject;t.shortName?i.bindableObjectNames=i.bindableObjectNames.map(r=>r==t.shortName+":"+t.prefix+s?t.shortName+":"+t.prefix+e:r):i.bindableObjectNames=i.bindableObjectNames.map(r=>r==t.prefix+s?t.prefix+e:r),t.designItem.serviceContainer.bindingService.setBinding(t.designItem,i)}};var pe=class{dragOverOnProperty(t,s,e){return"copy"}dropOnProperty(t,s,e,i){s.service.setValue(i,s,e.text)}};import{BindingTarget as b}from"@node-projects/web-component-designer";var ue=class{getRefactorings(t){let s=[];for(let e of t)for(let i of e.attributes())if(i[0][0]=="@"){let r=i[1];if(r[0]=="{"){let o=JSON.parse(r);if("commands"in o)for(let a of o.commands){for(let l in a){let c=a[l];if(c!=null&&typeof c=="object"){let p=c;if(p.source==="signal")s.push({name:p.name,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:o,display:a.type+"/"+i[0].substring(1)+"/"+l+"[signal]",refactor:d=>p.name=d});else if(p.source==="property")s.push({name:p.name,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:o,display:a.type+"/"+i[0].substring(1)+"/"+l+"[property]",refactor:d=>p.name=d});else if(p.source==="complexString")for(let d of p.name.matchAll(/\{(.*?)\}/g)){let m=d[0],h=d[1];if(h[0]==="?"){let u="?";h=h.substring(1),h[0]==="?"&&(u="??",h=h.substring(1)),s.push({name:h,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:o,display:a.type+"/"+i[0].substring(1)+"/"+l+"[complexString]->property",refactor:g=>p.name=p.name.replace(m,"{"+u+g+"}")})}else s.push({name:h,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:o,display:a.type+"/"+i[0].substring(1)+"/"+l+"[complexString]->signal",refactor:u=>p.name=p.name.replace(m,"{"+u+"}")})}}}switch(a.type){case"SetSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"ToggleSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"IncrementSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"DecrementSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"SetBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"ClearBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"ToggleBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"OpenScreen":a.screen&&typeof a.screen=="string"&&s.push({name:a.screen,itemType:"screen",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/screen",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.screen=l});break;case"OpenDialog":a.screen&&typeof a.screen=="string"&&s.push({name:a.screen,itemType:"screen",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/screen",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.screen=l});break;case"CalculateSignalValue":a.targetSignal&&typeof a.targetSignal=="string"&&s.push({name:a.targetSignal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/targetSignal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.targetSignal=l});break;case"SubscribeSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"UnsubscribeSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.signal=l});break;case"ShowMessageBox":a.resultSignal&&typeof a.resultSignal=="string"&&s.push({name:a.resultSignal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/resultSignal",service:this,designItem:e,type:"script",sourceObject:o,refactor:l=>a.resultSignal=l});break}}else"blocks"in o;if("parameters"in o)for(let a in o.parameters)typeof o.parameters[a]=="string"&&s.push({name:o.parameters[a],itemType:"parameter",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:o,display:i[0].substring(1)+"/parameters/"+a,refactor:l=>o.parameters[a]=l})}}return s}refactor(t,s,e){t.refactor(e);let i=JSON.stringify(t.sourceObject);t.designItem.setAttribute(t.targetName,i)}};import{BasePropertyEditor as qe}from"@node-projects/web-component-designer";var de=class extends qe{_ip;_container;constructor(t,s){super(t),this._container=document.createElement("div"),this._container.style.display="flex",this._ip=document.createElement("input"),this._ip.onchange=i=>this._valueChanged(this._ip.value),this._ip.onfocus=i=>{this._ip.selectionStart=0,this._ip.selectionEnd=this._ip.value?.length},this._container.appendChild(this._ip);let e=document.createElement("button");e.textContent="...",e.onclick=async()=>{let i=s.createBindableObjectBrowser();i.initialize(this.designItems[0].serviceContainer,this.designItems[0].instanceServiceContainer,"property"),i.title="select signal...";let r=new AbortController;i.objectDoubleclicked.on(()=>{r.abort(),this._ip.value=i.selectedObject.fullName,this._valueChanged(this._ip.value)}),await s.openConfirmation(i,{x:100,y:100,width:400,height:300,abortSignal:r.signal})&&(this._ip.value=i.selectedObject.fullName,this._valueChanged(this._ip.value))},this._container.appendChild(e),this.element=this._container}refreshValue(t,s){s==null?this._ip.value="":this._ip.value=s}};import{EventsService as Ye}from"@node-projects/web-component-designer";var he=class n extends Ye{static _cyclicEvent=[{name:`${M}:100`,propertyName:void 0,eventObjectName:"Event",description:"this event will retrigger itself every 100 ms"}];getPossibleEvents(t){let s=super.getPossibleEvents(t);return s.push(...n._cyclicEvent),s}getEvent(t,s){return s.includes(M)?n._cyclicEvent.find(i=>i.name==s)??{name:s,propertyName:"on"+s,eventObjectName:"Event"}:super.getEvent(t,s)}};export{re as BindableObjectDragDropService,D as BindingsEditor,E as BindingsEditorHistoric,se as BindingsHelper,C as BlocklyScriptEditor,P as EventAssignment,I as ParameterEditor,pe as PropertyGridDragDropService,ie as Script,ue as ScriptRefactorService,ne as ScriptSystem,de as SignalPropertyEditor,O as SimpleScriptEditor,ce as VisualizationBindingsRefactorService,le as VisualizationBindingsService,he as VisualizationEventsService,j as VisualizationPropertyGrid,B as bindingPrefixAttribute,R as bindingPrefixClass,w as bindingPrefixContent,V as bindingPrefixCss,A as bindingPrefixCssVar,He as bindingPrefixInsideCss,Fe as bindingPrefixInsideCssVarName,S as bindingPrefixProperty,F as bindingPrefixVisible,Xt as bindingsInCssRegex,M as cyclicAttributeName,G as generateEventCodeFromBlockly,L as getNestedProperty,z as isLit,U as parseBindingString};
912
+ </div>`;static scriptTypeColors={js:"purple",blockly:"yellow",script:"lightgreen",empty:"pink"};static is="node-projects-visualization-event-assignment";constructor(){super(),this._restoreCachedInititalValues()}ready(){this._bindingsParse()}_blocklyToolbox;_instanceServiceContainer;_selectionChangedHandler;_selectedItems;_visualizationHandler;_visualizationShell;_scriptCommandsTypeInfo;_propertiesTypeInfo;_commandDescriptions;events;initialize(t,s,e,i,r,c){this._visualizationHandler=t,this._visualizationShell=s,this._scriptCommandsTypeInfo=e,this._propertiesTypeInfo=i,this._blocklyToolbox=r,this._commandDescriptions=c}set instanceServiceContainer(t){this._instanceServiceContainer=t,this._selectionChangedHandler?.dispose(),this._selectionChangedHandler=this._instanceServiceContainer.selectionService.onSelectionChanged.on(s=>{this.selectedItems=s.selectedElements}),this.selectedItems=this._instanceServiceContainer.selectionService.selectedElements}_createControlsForScript(t){switch(this._getScriptType(t)){case"none":return""}return this.constructor.editRowTemplate.content.cloneNode(!0)}_getScriptName(t){if(this.selectedItems[0].hasAttribute("@"+t.name)){let s=this.selectedItems[0].getAttribute("@"+t.name);if(s[0]==="{"){if(s.includes("name"))return JSON.parse(s).name}else return s}return null}async _changeScriptName(t,s){if(t.key=="Enter"&&this.selectedItems&&this.selectedItems.length&&this.selectedItems[0].hasAttribute("@"+s.name)){let e=t.target.value,i=this.selectedItems[0].getAttribute("@"+s.name);if(i.startsWith("{")){let r=JSON.parse(i);r.name=e,this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}else this._selectedItems[0].setAttribute("@"+s.name,e)}}_getRelativeSignalsPath(t){if(this.selectedItems[0].hasAttribute("@"+t.name)){let s=this.selectedItems[0].getAttribute("@"+t.name);if(s[0]==="{"&&s.includes("relativeSignalsPath"))return JSON.parse(s).relativeSignalsPath}return null}async _changeRelativeSignalsPath(t,s){if(t.key=="Enter"&&this.selectedItems&&this.selectedItems.length&&this.selectedItems[0].hasAttribute("@"+s.name)){let e=t.target.value,i=this.selectedItems[0].getAttribute("@"+s.name);if(i.startsWith("{")){let r=JSON.parse(i);r.relativeSignalsPath=e,this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}else{let r={name:i,relativeSignalsPath:e};this._selectedItems[0].setAttribute("@"+s.name,JSON.stringify(r))}}}_hasParameters(t){return this.selectedItems[0].hasAttribute("@"+t.name)?this.selectedItems[0].getAttribute("@"+t.name).includes("parameters"):!1}_getScriptTypeColor(t){let s=this._getScriptType(t);return n.scriptTypeColors[s]??"white"}_getScriptType(t){if(t.designItem.hasAttribute("@"+t.name)){let s=t.designItem.getAttribute("@"+t.name);if(s.startsWith("{")){let e=JSON.parse(s);return"blocks"in e?"blockly":"commands"in e?"script":"js"}else return s==""?"empty":"js"}return"none"}_getEventMethodname(t){return this.selectedItems.length?this.selectedItems[0].getAttribute("@"+t.name):""}_inputMthName(t,s){let e=t.target;this.selectedItems[0].setAttribute("@"+s.name,e.value)}_ctxMenu(t,s){t.preventDefault();let e=this._getScriptType(s);if(e=="empty")this._showContextMenuAssignScript(t,s,!0);else if(e!="none"){let i=[{title:"remove",action:()=>{this.selectedItems[0].removeAttribute("@"+s.name),this._bindingsRefresh()}},{title:"-"},{title:"copy",action:()=>{Ee(this.selectedItems[0].getAttribute("@"+s.name))}},{title:"paste",action:async()=>{this.selectedItems[0].setAttribute("@"+s.name,await Ne()),this._bindingsRefresh()}}];Ce.show(i,t)}else this._showContextMenuAssignScript(t,s,!0)}async _addEvent(t){if(t.key=="Enter"){let s=this._getDomElement("addEventInput");this._selectedItems[0].setAttribute("@"+St.camelToDashCase(s.value.replaceAll(" ","-")),""),s.value="",this.scrollTop=0,this.refresh()}}_createAssignScriptContextMenu(t,s){let e=[{title:"Simple Script",action:()=>{this._editEvent("script",t,s)}},{title:"Javascript",action:()=>{let r=prompt("name of function ?");r&&(this._selectedItems[0].setAttribute("@"+s.name,r),this.refresh(),this._editEvent("js",null,s))}},{title:"Blockly",action:()=>{this._editBlockly(null,s)}}],i=this._getScriptType(s);return i!="none"&&(e.push({title:"-"}),e.push({title:"remove",action:()=>{this.selectedItems[0].removeAttribute("@"+s.name),this._bindingsRefresh()}})),i!="empty"&&e.push({title:"-"},{title:"copy",action:()=>{Ee(this.selectedItems[0].getAttribute("@"+s.name))}},{title:"paste",action:async()=>{this.selectedItems[0].setAttribute("@"+s.name,await Ne()),this._bindingsRefresh()}}),e}async _showContextMenuAssignScript(t,s,e){t.preventDefault();let i=this._getScriptType(s);if(i!="none"&&i!="empty"&&!e)this._editEvent(i,t,s);else{let r=this._createAssignScriptContextMenu(t,s);Ce.show(r,t)}}async _editParameter(t,s){let e=new M,i={};e.title="ParameterEditor for '"+s.name+"' of '"+s.designItem.name+"'";let r=s.designItem.getAttribute("@"+s.name);if(r&&r[0]=="{")try{i=JSON.parse(r).parameters}catch{}if(e.setParametersObject(i),await this._visualizationShell.openConfirmation(e,{x:100,y:100,width:700,height:500})){let a=e.getParametersObject(),l={name:r,parameters:a};r&&r[0]=="{"&&(l=JSON.parse(r),l.parameters=a),a==null&&delete l.parameters;let o=JSON.stringify(l);s.designItem.setAttribute("@"+s.name,o),this._bindingsRefresh()}}async _editBlockly(t,s){let e=new A(this._blocklyToolbox);e.title="Blockly Script for '"+s.name+"' of '"+s.designItem.name+"'";let i=s.designItem.getAttribute("@"+s.name),r=null,c=null;if(i){let l=JSON.parse(i);r=l.parameters,c=l.relativeSignalsPath,e.load(l)}if(await this._visualizationShell.openConfirmation(e,{x:100,y:100,width:700,height:500})){let l=e.save();r&&(l.parameters=r),c&&(l.relativeSignalsPath=c),s.designItem.setAttribute("@"+s.name,JSON.stringify(l)),this._bindingsRefresh()}}async _editJavascript(t,s){}async _editSimpleScript(t,s){let e=s.designItem.getAttribute("@"+s.name);if(!e||e.startsWith("{")){let i={commands:[]},r=null,c=null;e&&(i=JSON.parse(e),r=i.parameters,c=i.relativeSignalsPath);let a=new W;if(a.serviceContainer=s.designItem.serviceContainer,a.instanceServiceContainer=s.designItem.instanceServiceContainer,a.scriptCommandsTypeInfo=this._scriptCommandsTypeInfo,a.propertiesTypeInfo=this._propertiesTypeInfo,a.visualizationShell=this._visualizationShell,a.visualizationHandler=this._visualizationHandler,this._commandDescriptions&&(a.commandDescriptions={...a.commandDescriptions,...this._commandDescriptions}),a.loadScript(i),a.title="Script '"+s.name+"' on "+s.designItem.name,await this._visualizationShell.openConfirmation(a,{title:a.title,width:600,height:500})){let o=a.getScriptCommands();if(o&&o.length){let p={commands:o};r&&(p.parameters=r),c&&(p.relativeSignalsPath=c);let m=JSON.stringify(p);s.designItem.setAttribute("@"+s.name,m),this._bindingsRefresh()}}}}async _editEvent(t,s,e){t=="js"?this._editJavascript(s,e):t=="blockly"?this._editBlockly(s,e):this._editSimpleScript(s,e)}refresh(){this._selectedItems!=null&&this._selectedItems.length?this.events=this._selectedItems[0].serviceContainer.getLastServiceWhere("eventsService",t=>t.isHandledElementFromEventsService(this._selectedItems[0])).getPossibleEvents(this._selectedItems[0]).map(t=>({...t,designItem:this._selectedItems[0]})):this.events=[],this._bindingsRefresh()}get selectedItems(){return this._selectedItems}set selectedItems(t){this._selectedItems!=t&&(this._selectedItems=t,this.refresh())}};customElements.define(Q.is,Q);import{TypedEvent as _t,cssFromString as kt}from"@node-projects/base-custom-webcomponent";import{BindingTarget as y}from"@node-projects/web-component-designer/dist/elements/item/BindingTarget.js";import{PropertiesHelper as v}from"@node-projects/web-component-designer/dist/elements/services/propertiesService/services/PropertiesHelper.js";var B="bind-prop:",P="bind-attr:",F="bind-class:",H="bind-css:",J="bind-cssvar:",C="bind-content:",de="bind-visible:",Tt="bind(",Ct="--tmpBinding_",Js=/{{(.*)}}/;function q(n){return n.constructor?.elementProperties!=null}function he(n){let t=[],s=[],e="";for(let i=0;i<n.length;i++)n[i]=="{"?(t.push(e),e=""):n[i]=="}"?(s.push(e),e=""):e+=n[i];return t.push(e),{parts:t,signals:s}}function ee(n,t){let s=t.split("."),e=n;for(let i of s){if(e==null||typeof e!="object")return;e=e[i]}return e}var ue=class{parts;signals;values;unsubscribeTargetValue;cleanupCalls=[];combinedName;disposed;valueChangedCb;visualizationHandler;element;relativeSignalPath;constructor(t,s,e,i,r,c,a,l){this.visualizationHandler=s,this.valueChangedCb=i,this.element=r,this.relativeSignalPath=c,this.parseIndirectBinding(e),this.values=new Array(this.signals.length);for(let o=0;o<this.signals.length;o++){let p=this.signals[o];if(p[0]==="?"&&p[1]==="?"){let u=p.substring(2);if(u.includes(".")){let d=ee(a,u);this.handleValueChanged(d,o)}else{this.handleValueChanged(a[u],o);let d=()=>this.handleValueChanged(a[u],o),g=t.getChangedEventName(a,u);a.addEventListener(g,d),this.cleanupCalls.push(()=>a.removeEventListener(g,d))}continue}else if(p[0]==="#"&&p[1]==="#"){let u=p.substring(2);if(u.includes(".")){let d=ee(r,u);this.handleValueChanged(d,o)}else{this.handleValueChanged(r[u],o);let d=()=>this.handleValueChanged(r[u],o),g=t.getChangedEventName(r,u);r.addEventListener(g,d),this.cleanupCalls.push(()=>r.removeEventListener(g,d))}continue}else if(p[0]==="\xA7"){let u=p.substring(1),d=l.valueProvider(u,{element:r,relativeSignalPath:c,root:a});d instanceof Promise?d.then(f=>this.handleValueChanged(f,o)):this.handleValueChanged(d,o),l.valueChangedCallbacks||(l.valueChangedCallbacks=new Map);let g=l.valueChangedCallbacks.get(u);g==null&&(g=[],l.valueChangedCallbacks.set(u,g)),g.push(()=>{let f=l.valueProvider(u,{element:r,relativeSignalPath:c,root:a});f instanceof Promise?f.then(x=>this.handleValueChanged(x,o)):this.handleValueChanged(f,o)})}else(p[0]==="?"||p[0]==="#")&&(p.includes(".")?p=ee(a,p.substring(1)):p=a[p.substring(1)]);let m=(u,d)=>this.handleValueChanged(d.val,o),h=this.visualizationHandler.subscribeState(p,m);this.cleanupCalls.push(()=>this.visualizationHandler.unsubscribeState(this.signals[o],m,h))}}parseIndirectBinding(t){let{parts:s,signals:e}=he(t);this.parts=s,this.signals=e;for(let i=0;i<e.length;i++)e[i][0]=="."&&(e[i]=this.visualizationHandler.getNormalizedSignalName(e[i],this.relativeSignalPath,this.element))}handleValueChanged(t,s){this.values[s]=t;let e=this.parts[0];for(let i=0;i<this.parts.length-1;i++){let r=this.values[i];if(r==null)return;e+=r+this.parts[i+1]}if(e[0]=="."&&(e=this.visualizationHandler.getNormalizedSignalName(e,this.relativeSignalPath,this.element)),this.combinedName!=e&&(this.unsubscribeTargetValue&&this.visualizationHandler.unsubscribeState(this.combinedName,this.unsubscribeTargetValue[0],this.unsubscribeTargetValue[1]),!this.disposed)){this.combinedName=e;let i=(r,c)=>this.valueChangedCb(c);this.unsubscribeTargetValue=[i,this.visualizationHandler.subscribeState(e,i)]}}dispose(){this.disposed=!0,this.unsubscribeTargetValue&&(this.visualizationHandler.unsubscribeState(this.combinedName,this.unsubscribeTargetValue[0],this.unsubscribeTargetValue[1]),this.unsubscribeTargetValue=null);for(let t=0;t<this.signals.length;t++)this.cleanupCalls[t]()}setState(t){this.disposed||this.visualizationHandler.setState(this.combinedName,t)}},Ie=class n{_visualizationHandler;namedConverterCallback;constructor(t){this._visualizationHandler=t}getChangedEventName(t,s){let e=s.indexOf("::");return e>=0?s.substring(e+2):t instanceof HTMLInputElement||t instanceof HTMLSelectElement?"change":q(t)?v.camelToDashCase(s):v.camelToDashCase(s)+"-changed"}parseBinding(t,s,e,i,r){let c=s.substring(r.length);if(i===y.cssvar&&(c="--"+c),!e.startsWith("{")){let l={signal:e,target:i};if(e[0]==="="){if(e=e.substring(1),l.signal=e,e.includes("::")){let o=e.split("::");e=o[0],l.signal=e,l.events=o[1].split(",")}l.twoWay=!0,l.events||(t instanceof HTMLInputElement?l.events=[this.getChangedEventName(t,c)]:t instanceof HTMLSelectElement?l.events=[this.getChangedEventName(t,c)]:q(t)?l.events=[this.getChangedEventName(t,c)]:(l.events=[this.getChangedEventName(t,c)],l.maybeLitElement=!0,l.litEventNames=[this.getChangedEventName(t,c)]))}if(e[0]==="!"&&(l.signal=e.substring(1),l.inverted=!0),l.signal.includes(";")){let o=l.signal.split(";");l.expression=o.pop(),l.signal=o.join(";")}return i===y.cssvar||i===y.class?[n.dotToCamelCase(c),l]:i===y.attribute?[c,l]:[v.dashToCamelCase(c),l]}let a=JSON.parse(e);return a.target=i,a.twoWay&&(a.events==null||a.events.length==0)&&(t instanceof HTMLInputElement?a.events=["change"]:t instanceof HTMLSelectElement?a.events=["change"]:a.events=[this.getChangedEventName(t,c)]),i===y.cssvar||i===y.class?[n.dotToCamelCase(c),a]:i===y.attribute?[c,a]:[v.dashToCamelCase(c),a]}serializeBinding(t,s,e){let i={...e};delete i.type,e.twoWay?e.events!=null&&e.events.length==1&&(t instanceof HTMLInputElement&&e.events?.[0]=="change"||t instanceof HTMLSelectElement&&e.events?.[0]=="change"||q(t)&&e.events?.[0]==s||!q(t)&&e.events?.[0]==s+"-changed")&&delete i.events:(delete i.events,delete i.expressionTwoWay);let r=i.twoWay&&i.events?.length>0?"::"+i.events.join(","):"",c=!1;return(r&&e.expression?.includes("::")||e.expressionTwoWay?.includes("::"))&&(c=!0),e.signal.trim()[0]=="{"&&(c=!0),!c&&e.target==y.property&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?s=="textContent"?[C+"text",(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:s=="innerHTML"?[C+"html",(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:[B+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!c&&e.target==y.property&&e.expression&&!e.expression.includes(`
913
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?s=="textContent"?[C+"text",(e.inverted?"!":"")+e.signal+";"+e.expression+r]:s=="innerHTML"?[C+"html",(e.inverted?"!":"")+e.signal+";"+e.expression+r]:[B+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!c&&e.target==y.attribute&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[P+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!c&&e.target==y.attribute&&e.expression&&!e.expression.includes(`
914
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[P+v.camelToDashCase(s),(e.twoWay?"=":"")+(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!c&&e.target==y.class&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[F+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!c&&e.target==y.class&&e.expression&&!e.expression.includes(`
915
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[F+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!c&&e.target==y.css&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[H+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!c&&e.target==y.css&&e.expression&&!e.expression.includes(`
916
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[H+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:!c&&e.target==y.cssvar&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[J+n.camelToDotCase(s.substring(2)),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+r]:!c&&e.target==y.cssvar&&e.expression&&!e.expression.includes(`
917
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[J+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+r]:((e.inverted===null||e.inverted===!1)&&delete i.inverted,(e.expression===null||e.expression==="")&&delete i.expression,(e.expressionTwoWay===null||e.expressionTwoWay==="")&&delete i.expressionTwoWay,(e.twoWay===null||e.twoWay===!1)&&delete i.twoWay,delete i.target,e.historic||delete i.historic,e.target==y.content?[C+"html",JSON.stringify(i)]:e.target==y.attribute?[P+v.camelToDashCase(s),JSON.stringify(i)]:e.target==y.class?[F+n.camelToDotCase(s),JSON.stringify(i)]:e.target==y.css?[H+v.camelToDashCase(s),JSON.stringify(i)]:e.target==y.cssvar?[J+n.camelToDotCase(s.substring(2)),JSON.stringify(i)]:e.target==y.property&&s=="innerHTML"?[C+"html",JSON.stringify(i)]:e.target==y.property&&s=="textContent"?[C+"text",JSON.stringify(i)]:[B+v.camelToDashCase(s),JSON.stringify(i)])}getBindingAttributeName(t,s,e){return e==y.attribute?P+v.camelToDashCase(s):e==y.class?F+n.camelToDotCase(s):e==y.css?H+v.camelToDashCase(s):e==y.visible?de:e==y.cssvar?J+n.camelToDotCase(s):e==y.property&&s=="innerHTML"?C+"html":e==y.property&&s=="textContent"?C+"text":B+v.camelToDashCase(s)}*getBindings(t){if(t.attributes)for(let s of t.attributes)s.name.startsWith(B)?yield this.parseBinding(t,s.name,s.value,y.property,B):s.name.startsWith(C)?yield this.parseBinding(t,s.name==="bind-content:html"?"bind-prop:inner-h-t-m-l":"bind-prop:text-content",s.value,y.property,B):s.name.startsWith(P)?yield this.parseBinding(t,s.name,s.value,y.attribute,P):s.name.startsWith(F)?yield this.parseBinding(t,s.name,s.value,y.class,F):s.name.startsWith(H)?yield this.parseBinding(t,s.name,s.value,y.css,H):s.name.startsWith(J)?yield this.parseBinding(t,s.name,s.value,y.cssvar,J):s.name.startsWith(de)&&(yield this.parseBinding(t,s.name,s.value,y.visible,de))}applyAllBindings(t,s,e,i,r){let c=[],a=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),l;for(;l=a.nextNode();){let o=this.getBindings(l);for(let p of o)try{let m=this.applyBinding(l,p,s,e,i);if(c.push(m),p[1].maybeLitElement&&l.localName.includes("-")&&!customElements.get(l.localName)){let h=l,u=p;customElements.whenDefined(l.localName).then(()=>{q(h)&&(m(),u[1].events=u[1].litEventNames,c.push(this.applyBinding(h,u,s,e,i)))})}}catch(m){console.warn("error applying binding",l,p,m)}if(r&&r(l)){l=a.nextSibling();continue}}return c}static#e=0;async parseCssBindings(t,s,e,i){let r=await import("@node-projects/css-parser"),c=r.parse(t),a;for(let o of c.stylesheet.rules)if(o.type===r.CssTypes.rule){for(let p of o.declarations)if(p.type===r.CssTypes.declaration&&p.value.includes(Tt)){let m=this.parseCssBinding(p.value,s,e,i);p.value=m[0],a?a.push(...m[1]):a=m[1]}}let l=r.stringify(c,{indent:"",compress:!0});return[kt(l),a]}parseCssBinding(t,s,e,i,r){t=t.trim();let c="",a="",l=!1,o="",p=!1,m=null,h=[];for(let u=0;u<t.length;u++){let d=t[u];if(l)if(p)o+=d;else if(m&&d==="\\")p=!0;else if(d===m)m=null;else if(m===null&&d===")"){let g=n.#e++,f=Ct+g,x=[f,{signal:o,target:y.cssvar}];o.startsWith("{")&&(x=JSON.parse(o)),h.push(this.applyBinding(s,x,e,i,r)),c+="var("+f+")",l=!1,o=""}else o+=d;else d==="("?(a!=="bind"?(c+=a,c+=d):(l=!0,t[u+1]==="'"||t[u+1]==='"'?(u++,m=t[u]):m=null),a=""):d===" "||d===","||d==="("||d==="+"||d==="-"||d==="*"||d==="/"?(c+=a+d,a=""):a+=d}return[c+a,h]}applyBinding(t,s,e,i,r){let c=[],a,l=()=>{for(let h of c)this._visualizationHandler.unsubscribeState(h[0],h[1],h[2]);if(a)for(let h of a)h()},o=s[1].signal.split(";"),p=new Array(o.length);for(let h=0;h<o.length;h++){let u=o[h];if(p[h]="__"+h,u.includes(":")){let d=u.split(":");p[h]=d[0],u=d[1],o[h]=u}if(u[0]==="?"){if(i){let d=u.substring(1);if(d[0]=="?")o[h]=d;else{o[h]=i[d],d[0]==="$"&&(d=d.substring(1),o[h]="$"+i[d]);let g=()=>{l(),this.applyBinding(t,s,e,i,r)},f=this.getChangedEventName(i,d);i.addEventListener(f,g),a||(a=[]),a.push(()=>i.removeEventListener(f,g))}}}else if(u[0]==="#"){let d=u.substring(1);if(d[0]=="#")o[h]=d;else{o[h]=i[d],d[0]==="$"&&(d=d.substring(1),o[h]="$"+i[d]);let g=()=>{l(),this.applyBinding(t,s,e,i,r)},f=this.getChangedEventName(t,d);i.addEventListener(f,g),a||(a=[]),a.push(()=>i.removeEventListener(f,g))}}u[0]==="."&&(o[h]=this._visualizationHandler.getNormalizedSignalName(u,e,t))}let m=new Array(o.length);for(let h=0;h<o.length;h++){let u=o[h];if(u[0]==="?"){if(i){let d=u.substring(1),g=()=>{let f=!1;f||(f=!0,this.handleValueChanged(t,i,s,i[d],m,h,p,!1,e),f=!1)};i.addEventListener(v.camelToDashCase(d)+"-changed",g),a||(a=[]),a.push(()=>i.removeEventListener(v.camelToDashCase(d)+"-changed",g));try{this.handleValueChanged(t,i,s,i[d],m,h,p,!1,e)}catch(f){console.error(f)}s[1].twoWay&&h==0&&this.addTwoWayBinding(s,t,f=>i[d]=f)}}else if(u[0]==="#"){let d=u.substring(1),g=()=>{let f=!1;f||(f=!0,this.handleValueChanged(t,i,s,t[d],m,h,p,!1,e),f=!1)};t.addEventListener(v.camelToDashCase(d)+"-changed",g),a||(a=[]),a.push(()=>t.removeEventListener(v.camelToDashCase(d)+"-changed",g));try{this.handleValueChanged(t,i,s,t[d],m,h,p,!1,e)}catch(f){console.error(f)}s[1].twoWay&&h==0&&this.addTwoWayBinding(s,t,f=>t[d]=f)}else if(u[0]==="$"){let d=u.substring(1);d[0]==="."&&(d=this._visualizationHandler.getNormalizedSignalName(d,e,t)),this._visualizationHandler.getObject(d).then(g=>{this.handleValueChanged(t,i,s,g,m,h,p,!0,e)})}else if(u[0]==="\xA7"){let d=u.substring(1),g=r.valueProvider(d,{element:t,binding:s,relativeSignalPath:e,root:i});g instanceof Promise?g.then(x=>this.handleValueChanged(t,i,s,x,m,h,p,!0,e)):this.handleValueChanged(t,i,s,g,m,h,p,!0,e),r.valueChangedCallbacks||(r.valueChangedCallbacks=new Map);let f=r.valueChangedCallbacks.get(d);f==null&&(f=[],r.valueChangedCallbacks.set(d,f)),f.push(()=>{let x=r.valueProvider(d,{element:t,binding:s,relativeSignalPath:e,root:i});x instanceof Promise?x.then(T=>this.handleValueChanged(t,i,s,T,m,h,p,!0,e)):this.handleValueChanged(t,i,s,x,m,h,p,!0,e)})}else if(u.includes("{")){let d=new ue(this,this._visualizationHandler,u,g=>this.handleValueChanged(t,i,s,g.val,m,h,p,!1,e),t,e,i,r);a||(a=[]),a.push(()=>d.dispose()),s[1].twoWay&&h==0&&this.addTwoWayBinding(s,t,g=>d.setState(g))}else if(s[1].historic)if(s[1].historic.reloadInterval){let d={timerId:-1},g=async()=>{let f=await this._visualizationHandler.getHistoricData(u,s[1].historic);this.handleValueChanged(t,i,s,f?.values,m,h,p,!0,e),d.timerId!==null&&(d.timerId=setTimeout(g,s[1].historic.reloadInterval))};g(),a||(a=[]),a.push(()=>{d.timerId>0&&clearTimeout(d.timerId),d.timerId=null})}else this._visualizationHandler.getHistoricData(u,s[1].historic).then(d=>this.handleValueChanged(t,i,s,d?.values,m,h,p,!0,e));else{let d=(g,f)=>this.handleValueChanged(t,i,s,f.val,m,h,p,!1,e);c.push([u,d,this._visualizationHandler.subscribeState(u,d)]),this._visualizationHandler.getState(u).then(g=>this.handleValueChanged(t,i,s,g?.val,m,h,p,!1,e)),s[1].twoWay&&h==0&&this.addTwoWayBinding(s,t,g=>this._visualizationHandler.setState(u,g))}}return l}addTwoWayBinding(t,s,e){t[1].expressionTwoWay&&(t[1].compiledExpressionTwoWay||(t[1].expressionTwoWay.includes("return ")?t[1].compiledExpressionTwoWay=new Function(["value"],t[1].expressionTwoWay):t[1].compiledExpressionTwoWay=new Function(["value"],"return "+t[1].expressionTwoWay)));for(let i of t[1].events){let r=s[i];r instanceof _t?r.on(()=>{let c;t[1].target==y.attribute?c=s.getAttribute(t[0]):c=s[t[0]],c=n.parseValueWithType(c,t),t[1].compiledExpressionTwoWay&&(c=t[1].compiledExpressionTwoWay(c)),e(c)}):s.addEventListener(i,c=>{let a;t[1].target==y.attribute?a=s.getAttribute(t[0]):a=s[t[0]],a=n.parseValueWithType(a,t),t[1].compiledExpressionTwoWay&&(a=t[1].compiledExpressionTwoWay(a)),e(a)})}}static parseValueWithType(t,s){if(s[1].type)switch(s[1].type){case"number":return parseFloat(t);case"boolean":return t===!0||t==="true"||!!parseInt(t);case"string":return t?.toString();case"integer":return parseInt(t)}return t}handleValueChanged(t,s,e,i,r,c,a,l,o){let p=i;if(!l&&c==0&&(p=n.parseValueWithType(p,e)),r[c]=p,e[1].expression&&(e[1].compiledExpression||(a.push("__res"),a.push("__ctx"),e[1].expression.includes("return ")?e[1].compiledExpression=new Function(a,e[1].expression):e[1].compiledExpression=new Function(a,"return "+e[1].expression)),r[a.length-1]={element:t,root:s,boundNames:e[1].signal,boundTargetName:e[0],boundTargetType:e[1].target},p=e[1].compiledExpression(...r),r[a.length-1]=p),e[1].converter)if(typeof e[1].converter=="string")p=this.namedConverterCallback(e[1].converter,p,t,e);else{let m=p!=null?p.toString():p;if(m in e[1].converter){let h=e[1].converter[m];typeof h=="string"?p=new Function(a,"return `"+e[1].converter[m]+"`")(...r):p=h}else{let h=!1,u=parseFloat(p);for(let d in e[1].converter)if(d.length>2&&d[0]===">"&&d[1]==="="){let g=parseFloat(d.substring(2));if(u>=g){let f=e[1].converter[d];typeof f=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=f,h=!0;break}}else if(d.length>2&&d[0]==="<"&&d[1]==="="){let g=parseFloat(d.substring(2));if(u<=g){let f=e[1].converter[d];typeof f=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=f,h=!0;break}}else if(d.length>1&&d[0]===">"){let g=parseFloat(d.substring(1));if(u>g){let f=e[1].converter[d];typeof f=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=f,h=!0;break}}else if(d.length>1&&d[0]==="<"){let g=parseFloat(d.substring(1));if(u<g){let f=e[1].converter[d];typeof f=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=f,h=!0;break}}else{let g=d.split("-");if(g.length>1&&(g[0]===""||u>=parseFloat(g[0]))&&(g[1]===""||parseFloat(g[1])>=u)){let f=e[1].converter[d];typeof f=="string"?p=new Function(a,"return `"+e[1].converter[d]+"`")(...r):p=f,h=!0;break}}!h&&e[1].converterDefault!==void 0&&(p=e[1].converterDefault)}}if(e[1].inverted&&(p=!p),e[1].writeBackSignal){let m=e[1].writeBackSignal;m[0]==="."&&(m=o+m),this._visualizationHandler.setState(m,p,!0)}e[1].target==y.property?t[e[0]]=p:e[1].target==y.attribute?typeof p=="boolean"?p?t.setAttribute(e[0],""):t.removeAttribute(e[0]):t.setAttribute(e[0],p):e[1].target==y.css?t.style[e[0]]=p:e[1].target==y.cssvar?t.style.setProperty(e[0],p):e[1].target==y.class?p?t.classList.add(e[0]):t.classList.remove(e[0]):e[1].target==y.visible&&(t.style.visibility=p?"":"collapse")}static camelToDotCase(t){return t.replace(/([A-Z])/g,s=>`.${s[0].toLowerCase()}`)}static dotToCamelCase(t){return t.replace(/\.([a-z])/g,s=>s[1].toUpperCase())}};var Be=class{name;relativeSignalsPath;commands;parameters};import{deepValue as O,setDeepValue as Oe,sleep as Et}from"@node-projects/web-component-designer/dist/elements/helper/Helper.js";import U from"long";var te="cyclic",Nt={pointerdown:"pointerup",pointerenter:"pointerleave",mouseenter:"mouseleave",mouseover:"mouseout",focus:"blur",focusin:"focusout",keydown:"keyup"},Ve=class{_visualizationHandler;_subscriptionCallback=()=>{};constructor(n){this._visualizationHandler=n}async execute(n,t){let s=-1,e=!1,i=!1,r=t.event?.type,c=r?Nt[r]:null;if(c){let a=t.element;r=="pointerdown"&&(a=window),a.addEventListener(c,()=>{e=!0},{once:!0})}for(let a=0;a<n.length;a++){let l=n[a];if(l.type=="Exit"){i=!0;break}else if(l.type=="If"){let p=(await this.evaluateIfFormula(l,t)?l.trueCommands:l.elseCommands)??[];if(!await this.execute(p,t)){i=!0;break}}else if(l.type=="Goto"){let o=await this.getValue(l.label,t);if(a=n.findIndex(p=>p.type=="Label"&&p.label==o),a<0)break}else if(l.type=="Condition"){let o=await this.getValue(l.value1,t),p=await this.getValue(l.value2,t),m=await this.getValue(l.comparisonType,t),h=!1;switch(m){case"==null":h=o==null;break;case"!=null":h=o!=null;break;case"==true":h=o==!0;break;case"==false":h=o==!1;break;case"==":h=o==p;break;case"!=":h=o!=p;break;case">":h=o>p;break;case"<":h=o<p;break;case">=":h=o>=p;break;case"<=":h=o<=p;break;case"&&":h=o&&p;break;case"||":h=o||p;break}if(h){await this.runExternalScript(await this.getValue(l.trueScriptName,t),await this.getValue(l.trueScriptType,t));let u=await this.getValue(l.trueGotoLabel,t);if(u&&(a=n.findIndex(d=>d.type=="Label"&&d.label==u),a<0))break}else{await this.runExternalScript(await this.getValue(l.falseScriptName,t),await this.getValue(l.falseScriptType,t));let u=await this.getValue(l.falseGotoLabel,t);if(u&&(a=n.findIndex(d=>d.type=="Label"&&d.label==u),a<0))break}}else if(l.type=="Repeat"){let o=await this.getValue(l.label,t),p=await this.getValue(l.count,t);if(await this.getValue(l.mode,t)=="eventValid"&&e){e=!1;continue}if(p!=0&&s==-1&&(s=p-1),s==0||(s>0&&s--,a=-1,o&&(a=n.findIndex(h=>h.type=="Label"&&h.label==o),a<0)))continue}else if(!await this.runScriptCommand(l,t)){i=!0;break}}return!i}async getValueFromTarget(n,t,s){return n==="property"?O(s.root,t):n==="elementProperty"?O(s.element,t):(await this._visualizationHandler.getState(this.getSignalName(t,s)))?.val}async setValueOnTarget(n,t,s,e){n==="property"?Oe(s.root,t,e):n==="elementProperty"?Oe(s.element,t,e):await this._visualizationHandler.setState(this.getSignalName(t,s),e)}async runExternalScript(n,t){}async runScriptCommand(command,context){switch(command.type){case"Comment":case"Label":case"Condition":case"If":case"Goto":case"Exit":case"Repeat":break;case"OpenUrl":{window.open(await this.getValue(command.url,context),command.target);break}case"Delay":{let n=await this.getValue(command.value??500,context);await Et(n);break}case"Console":{let n=await this.getValue(command.target??"log",context),t=await this.getValue(command.message,context);console[n](t);break}case"ToggleSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),s=await this.getValueFromTarget(t,n,context);await this._visualizationHandler.setState(this.getSignalName(n,context),!s);break}case"ToggleSignalValueThroughList":{let n=await this.getValue(command.valueList,context),t=await this.getValue(command.signal,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,t,context),i=n.indexOf(e)+1;i>=n.length&&(i=0);let r=n[i];await this._visualizationHandler.setState(this.getSignalName(t,context),r);break}case"SetSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context);await this.setValueOnTarget(t,n,context,await this.getValue(command.value,context));break}case"IncrementSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,n,context)+await this.getValue(command.value,context);await this.setValueOnTarget(t,n,context,e);break}case"DecrementSignalValue":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,n,context)-await this.getValue(command.value,context);await this.setValueOnTarget(t,n,context,e);break}case"CalculateSignalValue":{let formula=await this.getValue(command.formula,context),target=await this.getValue(command.target,context),targetSignal=await this.getValue(command.targetSignal,context),nm=await this.parseStringWithValues(formula,context),result=eval(nm);await this.setValueOnTarget(target,targetSignal,context,result);break}case"SetBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=U.fromNumber(1).shiftLeft(t),r=U.fromNumber(e).or(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"ClearBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=U.fromNumber(1).shiftLeft(t);i.negate();let r=U.fromNumber(e).and(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"ToggleBitInSignal":{let n=await this.getValue(command.signal,context),t=await this.getValue(command.bitNumber??0,context),s=await this.getValue(command.target,context),e=await this.getValueFromTarget(s,n,context),i=U.fromNumber(1).shiftLeft(t),r=U.fromNumber(e).xor(i).toNumber();await this.setValueOnTarget(s,n,context,r);break}case"Javascript":{let n=await this.getValue(command.script,context),t=context;t.shadowRoot=context.element.getRootNode(),t.instance=context.shadowRoot.host,command.compiledScript||(command.compiledScript=new Function("context",n)),command.compiledScript(t);break}case"SetElementProperty":{command=L.upgradeSetElementProperty(command);let n=await this.getValue(command.name,context);n===""&&(n=null);let t=await this.getValue(command.value,context),s=await this.getValue(command.parentIndex??0,context),e=await this.getValue(command.target??"property",context),i=await this.getValue(command.targetSelectorTarget??"container",context),r=await this.getValue(command.targetSelector,context),c=await this.getValue(command.mode??"toggle",context),a=this.getTargetFromTargetSelector(context,i,s,r);for(let l of a)e=="attribute"?l.setAttribute(n,t):e=="property"?l[n]=t:e=="css"?l.style[n]=t:e=="class"&&(c==="toggle"?l.classList.toggle(n??t):c==="remove"?l.classList.remove(n??t):l.classList.add(n??t));break}case"SubscribeSignal":{let n=await this.getValue(command.signal,context);if(await this.getValue(command.oneTime,context)){let s=()=>{this._visualizationHandler.unsubscribeState(n,s,null)};this._visualizationHandler.subscribeState(n,s)}else this._visualizationHandler.subscribeState(n,this._subscriptionCallback);break}case"UnsubscribeSignal":{let n=await this.getValue(command.signal,context);this._visualizationHandler.unsubscribeState(n,this._subscriptionCallback,null);break}case"WriteSignalsInGroup":{let n=await this.getValue(command.group,context);this._visualizationHandler.writeSignalsInGroup(n);break}case"ClearSignalsInGroup":{let n=await this.getValue(command.group,context);this._visualizationHandler.clearSignalsInGroup(n);break}case"RunScript":{let n=await this.getValue(command.name,context),t=await this.getValue(command.scriptType,context);this.runExternalScript(n,t);break}case"ShowMessageBox":{let n=null,t=await this.getValue(command.exitScriptOnCancel,context);if(await this.getValue(command.buttons,context)=="yesNo"){let i=await this.getValue(command.message,context);confirm(i)?n=1:n=2}else{let i=await this.getValue(command.message,context);alert(i),n=1}let e=await this.getValue(command.resultSignal,context);if(e&&this._visualizationHandler.setState(e,n),t&&n!=1)return!1;break}case"ShowPrompt":{let n=await this.getValue(command.message,context),t=await this.getValue(command.default,context),s=prompt(n,t),e=await this.getValue(command.resultSignal,context);e&&s&&this._visualizationHandler.setState(e,s);break}case"Login":case"Logout":case"CloseDialog":case"OpenDialog":case"OpenScreen":case"SwitchLanguage":case"CopySignalValuesFromFolder":case"ExportSignalValuesAsJson":case"ImportSignalValuesFromJson":{alert('command: "'+command.type+'" is not yet implemented');break}}return!0}getTarget(n,t,s){if(t==="container"){let e=n.element.getRootNode().host;for(let i=0;i<(s??0);i++)e=e.getRootNode().host;return e}else if(t==="element"){let e=n.element;for(let i=0;i<(s??0);i++)e=e.parentElement;return e}return null}getTargetFromTargetSelector(n,t,s,e){let i=this.getTarget(n,t,s),r=[i];return e&&(t==="container"?r=i.shadowRoot.querySelectorAll(e):r=i.querySelectorAll(e)),r}async getValue(value,outerContext){if(value==null)return null;if(typeof value=="object")switch(value.source){case"property":return O(outerContext.root,value.name);case"elementProperty":return O(outerContext.element,value.name);case"signal":return(await this._visualizationHandler.getState(this.getSignalName(value.name,outerContext)))?.val;case"signalInProperty":{let n=O(outerContext.root,value.name);return(await this._visualizationHandler.getState(this.getSignalName(n,outerContext)))?.val}case"event":{let n=outerContext.event;return value.name&&(n=O(n,value.name)),n}case"parameter":return outerContext.parameters[value.name];case"context":return O(outerContext,value.name);case"complexString":{let n=value.name;return n!=null?await this.parseStringWithValues(n,outerContext):null}case"complexSignal":{let n=value.name;if(n!=null){let t=await this.parseStringWithValues(n,outerContext);return(await this._visualizationHandler.getState(this.getSignalName(t,outerContext)))?.val}return null}case"expression":{var ctx=outerContext;return eval(value.name)}}return value}async getStateOrFieldOrParameter(name,context){if(name[0]==="\xA7"){var ctx=context;return eval("ctx."+name.substring(1))}else{if(name[0]==="?"&&name[1]==="?")return context.root[name.substring(2)];if(name[0]==="?")return await this._visualizationHandler.getState(this.getSignalName(context.root[name.substring(1)],context))}return await this._visualizationHandler.getState(this.getSignalName(name,context))}async parseStringWithValues(n,t){let s=he(n),e=await Promise.all(s.signals.map(r=>this.getStateOrFieldOrParameter(this.getSignalName(r,t),t))),i=s.parts[0];for(let r=0;r<s.parts.length-1;r++){let c=e[r];typeof c=="object"&&(c=c.val),c==null&&(c=""),i+=c+s.parts[r+1]}return i}async evaluateIfFormula(n,t){let s=n.signals??[],e=s.map((c,a)=>c.varName?.trim()||"__"+a),i=await Promise.all(s.map(c=>this.getValue(c,t))),r=await this.getValue(n.formula,t);return(!n.compiledFormula||n._compiledFormulaSrc!==r)&&(n.compiledFormula=new Function(...e,"return ("+r+");"),n._compiledFormulaSrc=r),!!n.compiledFormula(...i)}getSignalName(n,t){return n[0]==="."?t.relativeSignalsPath+n:n}createScriptContext(n,t,s,e,i){return{root:n,event:t,element:s,parameters:e,relativeSignalsPath:i}}async assignAllScripts(n,t,s,e,i,r,c,a){r??=this.createScriptContext;let l=await this.loadAndInitJsObject(n,t,s,e,a);for(let o of s.querySelectorAll("*"))for(let p of o.attributes)if(p.name[0]==="@")try{let m=p.name.substring(1),h=p.value.trim(),u=m.startsWith(te),d=u?parseInt(m.substring(m.indexOf(":")+1)):null,g=await this.resolveHandler(h,l,o,s,e,i,r,c,m);g&&this.bindHandler(o,m,u,d,g)}catch{console.warn("error assigning script",o,p)}return l}async loadAndInitJsObject(n,t,s,e,i){if(!t)return null;try{let c=await import(URL.createObjectURL(new Blob([t],{type:"application/javascript"})));return i?i(c):c.init?.(e,s),c}catch(r){return console.error("error parsing javascript - "+n,r),null}}async resolveHandler(n,t,s,e,i,r,c,a,l){if(n[0]!=="{")return p=>{t?.[n]?t[n](p,s,e,i):console.warn(`javascript function named: "${n}" not found, maybe missing a "export" ?`)};let o=JSON.parse(n);if("commands"in o)return p=>this.execute(o.commands,c(i,p,s,o.parameters,o.relativeSignalsPath));if("blocks"in o){let p=null;return async m=>{p??=await fe(o),p(m,e,o.parameters,o.relativeSignalsPath??"",r,c(i,m,s,o.parameters,o.relativeSignalsPath))}}if("name"in o){if(a)return a(s,l,o),null;let p=o.name;return m=>{t?.[p]?t[p](m,s,e,i,o.parameters):console.warn(`javascript function named: "${p}" not found, maybe missing a "export" ?`)}}return null}bindHandler(n,t,s,e,i){if(!s){n.addEventListener(t,i);return}let r=setInterval(()=>{n.isConnected?i(null):clearInterval(r)},e)}};import{OverlayLayer as It,DesignItem as V,InsertAction as Bt,BindingTarget as E,PropertyType as se}from"@node-projects/web-component-designer";var Re=class{constructor(t,s){this._bindingsHelper=t,this._visualizationHandler=s}_bindingsHelper;_visualizationHandler;rectMap=new Map;rect;dragEnter(t,s,e){let i=V.GetDesignItem(e);if(i&&!i.isRootItem){let r=t.getNormalizedElementCoordinates(e);this.rect=t.overlayLayer.drawRect("IobrokerWebuiBindableObjectDragDropService",r.x,r.y,r.width,r.height,"",null,It.Background),this.rect.style.fill="#ff0000",this.rect.style.opacity="0.3",this.rectMap.set(e,this.rect)}}dragLeave(t,s,e){let i=V.GetDesignItem(e);if(i&&!i.isRootItem){let r=this.rectMap.get(e);t.overlayLayer.removeOverlay(r),this.rectMap.delete(e)}}dragOver(t,s,e){return"copy"}async drop(t,s,e,i){for(let l of this.rectMap.values())t.overlayLayer.removeOverlay(l);this.rectMap.clear();let r=V.GetDesignItem(i),c=await this._visualizationHandler.getObject(e.fullName),a=this._visualizationHandler.getSignalInformation(c);if(r&&!r.isRootItem)if(i instanceof HTMLInputElement){let l={signal:e.fullName,target:E.property},o=this._bindingsHelper.serializeBinding(i,i.type=="checkbox"?"checked":"value",l);r.setAttribute(o[0],o[1])}else{let l={signal:e.fullName,target:E.content},o=this._bindingsHelper.serializeBinding(i,null,l);r.setAttribute(o[0],o[1])}else{let l=t.getNormalizedEventCoordinates(s),o,p,m=await this._visualizationHandler.getState(e.fullName);if(a.role==="url"&&typeof m?.val=="string")if(m.val.endsWith("jpg")||m.val.endsWith("jpeg")||m.val.endsWith("png")||m.val.endsWith("gif")||m.val.endsWith("svg")){let h=document.createElement("img");o=V.createDesignItemFromInstance(h,t.serviceContainer,t.instanceServiceContainer),p=o.openGroup("Insert");let u={signal:e.fullName,target:E.property},d=this._bindingsHelper.serializeBinding(h,"src",u);o.setAttribute(d[0],d[1]),o.element.src=m.val}else if(m.val.endsWith("mp4")){let h=document.createElement("video");o=V.createDesignItemFromInstance(h,t.serviceContainer,t.instanceServiceContainer),p=o.openGroup("Insert");let u={signal:e.fullName,target:E.property},d=this._bindingsHelper.serializeBinding(h,"src",u);o.setAttribute(d[0],d[1]),o.element.src=m.val}else{let h=document.createElement("iframe");o=V.createDesignItemFromInstance(h,t.serviceContainer,t.instanceServiceContainer),p=o.openGroup("Insert");let u={signal:e.fullName,target:E.property},d=this._bindingsHelper.serializeBinding(h,"src",u);o.setAttribute(d[0],d[1]),o.element.src=m.val}if(!o){let h=document.createElement("input");o=V.createDesignItemFromInstance(h,t.serviceContainer,t.instanceServiceContainer),p=o.openGroup("Insert");let u=a.writeable!==!1,d={signal:e.fullName,target:E.property,twoWay:u},g=this._bindingsHelper.serializeBinding(h,"value",d);a.type==="boolean"?(g=this._bindingsHelper.serializeBinding(h,"checked",d),o.setAttribute("type","checkbox")):a.role=="date"?(d.twoWay=u,g=this._bindingsHelper.serializeBinding(h,"value-as-number",d),o.setAttribute("type","date"),o.setAttribute("readonly","")):a.role=="datetime"&&(d.twoWay=u,g=this._bindingsHelper.serializeBinding(h,"value-as-number",d),o.setAttribute("type","datetime-local"),o.setAttribute("readonly","")),o.setAttribute(g[0],g[1])}o.setStyle("position","absolute"),o.setStyle("left",l.x+"px"),o.setStyle("top",l.y+"px"),t.instanceServiceContainer.undoService.execute(new Bt(t.rootDesignItem,t.rootDesignItem.childCount,o)),p.commit(),requestAnimationFrame(()=>t.instanceServiceContainer.selectionService.setSelectedElements([o]))}}dragOverOnProperty(t,s,e){return"copy"}dropOnProperty(t,s,e,i){if(s.type=="signal"){s.service.setValue(i,s,e.fullName);return}let r={signal:e.fullName,target:E.property};s.propertyType==se.attribute&&(r.target=E.attribute),s.propertyType==se.cssValue&&(r.target=E.css),r.signal=e.fullName,r.twoWay=s.propertyType==se.property||s.propertyType==se.propertyAndAttribute;let c=i[0].openGroup("drop binding");for(let a of i){let l=this._bindingsHelper.serializeBinding(a.element,s.name,r);a.setAttribute(l[0],l[1])}c.commit()}};import{BindingMode as me,BindingTarget as Ae,PropertiesHelper as Ot}from"@node-projects/web-component-designer";var De=class n{constructor(t){this._bindingsHelper=t}_bindingsHelper;static type="visualization-binding";getBindings(t){return Array.from(this._bindingsHelper.getBindings(t.element)).map(e=>({targetName:e[1].target===Ae.css||e[1].target===Ae.attribute?Ot.camelToDashCase(e[0]):e[0],target:e[1].target,mode:e[1].twoWay?me.twoWay:me.oneWay,invert:e[1].inverted,bindableObjectNames:e[1].signal.split(";"),expression:e[1].expression,expressionTwoWay:e[1].expressionTwoWay,converter:e[1].converter,type:n.type,service:this,changedEvents:e[1].events,historic:e[1].historic,writeBackSignal:e[1].writeBackSignal}))}setBinding(t,s){let e={signal:s.bindableObjectNames.join(";"),target:s.target};e.inverted=s.invert,e.twoWay=s.mode==me.twoWay,e.expression=s.expression,e.expressionTwoWay=s.expressionTwoWay,e.historic=s.historic,e.type=s.type,e.converter=s.converters,e.target=s.target,e.events=s.changedEvents;let i=this._bindingsHelper.serializeBinding(t.element,s.targetName,e),r=t.openGroup("edit_binding");return t.setAttribute(i[0],i[1]),r.commit(),!0}clearBinding(t,s,e){let i=this._bindingsHelper.getBindingAttributeName(t.element,s,e);return t.removeAttribute(i),!0}};var ze=class{getRefactorings(t){let s=[];for(let e of t){let i=e.serviceContainer.bindingService.getBindings(e);if(i)for(let r of i)for(let c of r.bindableObjectNames){let a="signal",l="";if(c.includes(":")){let o=c.split(":")[0],p=c.substring(o.length+1);p.startsWith("?")&&(p=p.substring(1),l="?",a="property",p.startsWith("?")&&(p=p.substring(1),l="??")),s.push({service:this,name:p,itemType:a,designItem:e,type:"binding",sourceObject:r,display:r.target+"/"+r.targetName+" - "+o+":",shortName:o,prefix:l})}else c.startsWith("?")&&(c=c.substring(1),l="?",a="property",c.startsWith("?")&&(c=c.substring(1),l="??")),s.push({service:this,name:c,itemType:a,designItem:e,type:"binding",sourceObject:r,display:r.target+"/"+r.targetName,prefix:l})}}return s}refactor(t,s,e){let i=t.sourceObject;t.shortName?i.bindableObjectNames=i.bindableObjectNames.map(r=>r==t.shortName+":"+t.prefix+s?t.shortName+":"+t.prefix+e:r):i.bindableObjectNames=i.bindableObjectNames.map(r=>r==t.prefix+s?t.prefix+e:r),t.designItem.serviceContainer.bindingService.setBinding(t.designItem,i)}};var Le=class{dragOverOnProperty(t,s,e){return"copy"}dropOnProperty(t,s,e,i){s.service.setValue(i,s,e.text)}};import{BindingTarget as b}from"@node-projects/web-component-designer";var je=class{getRefactorings(t){let s=[];for(let e of t)for(let i of e.attributes())if(i[0][0]=="@"){let r=i[1];if(r[0]=="{"){let c=JSON.parse(r);if("commands"in c)for(let a of c.commands){for(let l in a){let o=a[l];if(o!=null&&typeof o=="object"){let p=o;if(p.source==="signal")s.push({name:p.name,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:c,display:a.type+"/"+i[0].substring(1)+"/"+l+"[signal]",refactor:m=>p.name=m});else if(p.source==="property")s.push({name:p.name,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:c,display:a.type+"/"+i[0].substring(1)+"/"+l+"[property]",refactor:m=>p.name=m});else if(p.source==="complexString")for(let m of p.name.matchAll(/\{(.*?)\}/g)){let h=m[0],u=m[1];if(u[0]==="?"){let d="?";u=u.substring(1),u[0]==="?"&&(d="??",u=u.substring(1)),s.push({name:u,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:c,display:a.type+"/"+i[0].substring(1)+"/"+l+"[complexString]->property",refactor:g=>p.name=p.name.replace(h,"{"+d+g+"}")})}else s.push({name:u,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:c,display:a.type+"/"+i[0].substring(1)+"/"+l+"[complexString]->signal",refactor:d=>p.name=p.name.replace(h,"{"+d+"}")})}}}switch(a.type){case"SetSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"ToggleSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"IncrementSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"DecrementSignalValue":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"SetBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"ClearBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"ToggleBitInSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"OpenScreen":a.screen&&typeof a.screen=="string"&&s.push({name:a.screen,itemType:"screen",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/screen",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.screen=l});break;case"OpenDialog":a.screen&&typeof a.screen=="string"&&s.push({name:a.screen,itemType:"screen",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/screen",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.screen=l});break;case"CalculateSignalValue":a.targetSignal&&typeof a.targetSignal=="string"&&s.push({name:a.targetSignal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/targetSignal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.targetSignal=l});break;case"SubscribeSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"UnsubscribeSignal":a.signal&&typeof a.signal=="string"&&s.push({name:a.signal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/signal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.signal=l});break;case"ShowMessageBox":a.resultSignal&&typeof a.resultSignal=="string"&&s.push({name:a.resultSignal,itemType:"signal",target:b.event,targetName:i[0],display:a.type+"/"+i[0].substring(1)+"/resultSignal",service:this,designItem:e,type:"script",sourceObject:c,refactor:l=>a.resultSignal=l});break}}else"blocks"in c;if("parameters"in c)for(let a in c.parameters)typeof c.parameters[a]=="string"&&s.push({name:c.parameters[a],itemType:"parameter",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:c,display:i[0].substring(1)+"/parameters/"+a,refactor:l=>c.parameters[a]=l})}}return s}refactor(t,s,e){t.refactor(e);let i=JSON.stringify(t.sourceObject);t.designItem.setAttribute(t.targetName,i)}};import{BasePropertyEditor as Vt}from"@node-projects/web-component-designer";var We=class extends Vt{_ip;_container;constructor(t,s){super(t),this._container=document.createElement("div"),this._container.style.display="flex",this._ip=document.createElement("input"),this._ip.onchange=i=>this._valueChanged(this._ip.value),this._ip.onfocus=i=>{this._ip.selectionStart=0,this._ip.selectionEnd=this._ip.value?.length},this._container.appendChild(this._ip);let e=document.createElement("button");e.textContent="...",e.onclick=async()=>{let i=s.createBindableObjectBrowser();i.initialize(this.designItems[0].serviceContainer,this.designItems[0].instanceServiceContainer,"property"),i.title="select signal...";let r=new AbortController;i.objectDoubleclicked.on(()=>{r.abort(),this._ip.value=i.selectedObject.fullName,this._valueChanged(this._ip.value)}),await s.openConfirmation(i,{x:100,y:100,width:400,height:300,abortSignal:r.signal})&&(this._ip.value=i.selectedObject.fullName,this._valueChanged(this._ip.value))},this._container.appendChild(e),this.element=this._container}refreshValue(t,s){s==null?this._ip.value="":this._ip.value=s}};import{EventsService as Rt}from"@node-projects/web-component-designer";var Me=class n extends Rt{static _cyclicEvent=[{name:`${te}:100`,propertyName:void 0,eventObjectName:"Event",description:"this event will retrigger itself every 100 ms"}];getPossibleEvents(t){let s=super.getPossibleEvents(t);return s.push(...n._cyclicEvent),s}getEvent(t,s){return s.includes(te)?n._cyclicEvent.find(i=>i.name==s)??{name:s,propertyName:"on"+s,eventObjectName:"Event"}:super.getEvent(t,s)}};export{Re as BindableObjectDragDropService,K as BindingsEditor,D as BindingsEditorHistoric,Ie as BindingsHelper,A as BlocklyScriptEditor,Q as EventAssignment,M as ParameterEditor,Le as PropertyGridDragDropService,Be as Script,je as ScriptRefactorService,Ve as ScriptSystem,We as SignalPropertyEditor,z as SimpleScriptCommandPicker,W as SimpleScriptEditor,ze as VisualizationBindingsRefactorService,De as VisualizationBindingsService,Me as VisualizationEventsService,X as VisualizationPropertyGrid,P as bindingPrefixAttribute,F as bindingPrefixClass,C as bindingPrefixContent,H as bindingPrefixCss,J as bindingPrefixCssVar,Tt as bindingPrefixInsideCss,Ct as bindingPrefixInsideCssVarName,B as bindingPrefixProperty,de as bindingPrefixVisible,Js as bindingsInCssRegex,te as cyclicAttributeName,fe as generateEventCodeFromBlockly,ee as getNestedProperty,q as isLit,Se as nativeScriptCommandDescriptions,he as parseBindingString,we as simpleScriptEditorHelpHtml};
390
918
  //!varname => inverted