@node-projects/web-component-designer-visualization-addons 0.1.137 → 0.1.138

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/README.md CHANGED
@@ -15,6 +15,6 @@ It is used for example by the iobroker.webui.
15
15
 
16
16
  - long
17
17
  - blockly
18
- - @adobe/css-tools ( only if you use Bindingshelper.parseCssBindings() )
18
+ - @node-projects/css-parser ( only if you use Bindingshelper.parseCssBindings() )
19
19
 
20
20
  ## Usage
@@ -519,7 +519,7 @@ export class BindingsHelper {
519
519
  }
520
520
  static #cssBindingsVarId = 0;
521
521
  async parseCssBindings(sheet, element, relativeSignalPath, root) {
522
- const parser = (await import("@adobe/css-tools"));
522
+ const parser = (await import("@node-projects/css-parser"));
523
523
  const ast = parser.parse(sheet);
524
524
  let unsub;
525
525
  for (let r of ast.stylesheet.rules) {
package/dist/index-min.js CHANGED
@@ -386,5 +386,5 @@ export async function run(eventData, shadowRoot, parameters, relativeSignalsPath
386
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+n]:!l&&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(";")?";":"")+n]:!l&&e.target==f.class&&e.expression&&!e.expression.includes(`
387
387
  `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[R+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+n]:!l&&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(";")?";":"")+n]:!l&&e.target==f.css&&e.expression&&!e.expression.includes(`
388
388
  `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[V+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+n]:!l&&e.target==f.cssvar&&!e.expression&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[A+r.camelToDotCase(s.substring(2)),(e.inverted?"!":"")+e.signal+(!e.twoWay&&e.signal.includes(";")?";":"")+n]:!l&&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+n]:((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+r.camelToDotCase(s),JSON.stringify(i)]:e.target==f.css?[V+v.camelToDashCase(s),JSON.stringify(i)]:e.target==f.cssvar?[A+r.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+r.camelToDotCase(s):e==f.css?V+v.camelToDashCase(s):e==f.visible?F:e==f.cssvar?A+r.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){let n=[],l=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),a;for(;a=l.nextNode();){let p=this.getBindings(a);for(let o of p)try{let u=this.applyBinding(a,o,s,e,i);if(n.push(u),o[1].maybeLitElement&&a.localName.includes("-")&&!customElements.get(a.localName)){let g=a,d=o;customElements.whenDefined(a.localName).then(()=>{z(g)&&(u(),d[1].events=d[1].litEventNames,n.push(this.applyBinding(g,d,s,e,i)))})}}catch(u){console.warn("error applying binding",a,o,u)}}return n}static#e=0;async parseCssBindings(t,s,e,i){let n=await import("@adobe/css-tools"),l=n.parse(t),a;for(let o of l.stylesheet.rules)if(o.type===n.CssTypes.rule){for(let u of o.declarations)if(u.type===n.CssTypes.declaration&&u.value.includes(Pe)){let g=this.parseCssBinding(u.value,s,e,i);u.value=g[0],a?a.push(...g[1]):a=g[1]}}let p=n.stringify(l,{indent:"",compress:!0});return[Le(p),a]}parseCssBinding(t,s,e,i,n){t=t.trim();let l="",a="",p=!1,o="",u=!1,g=null,d=[];for(let h=0;h<t.length;h++){let c=t[h];if(p)if(u)o+=c;else if(g&&c==="\\")u=!0;else if(c===g)g=null;else if(g===null&&c===")"){let m=r.#e++,y=Me+m,x=[y,{signal:o,target:f.cssvar}];o.startsWith("{")&&(x=JSON.parse(o)),d.push(this.applyBinding(s,x,e,i,n)),l+="var("+y+")",p=!1,o=""}else o+=c;else c==="("?(a!=="bind"?(l+=a,l+=c):(p=!0,t[h+1]==="'"||t[h+1]==='"'?(h++,g=t[h]):g=null),a=""):c===" "||c===","||c==="("||c==="+"||c==="-"||c==="*"||c==="/"?(l+=a+c,a=""):a+=c}return[l+a,d]}applyBinding(t,s,e,i,n){let l=[],a,p=()=>{for(let d of l)this._visualizationHandler.unsubscribeState(d[0],d[1],d[2]);if(a)for(let d of a)d()},o=s[1].signal.split(";"),u=new Array(o.length);for(let d=0;d<o.length;d++){let h=o[d];if(u[d]="__"+d,h.includes(":")){let c=h.split(":");u[d]=c[0],h=c[1],o[d]=h}if(h[0]==="?"){if(i){let c=h.substring(1);if(c[0]=="?")o[d]=c;else{o[d]=i[c],c[0]==="$"&&(c=c.substring(1),o[d]="$"+i[c]);let m=()=>{p(),this.applyBinding(t,s,e,i,n)},y=this.getChangedEventName(i,c);i.addEventListener(y,m),a||(a=[]),a.push(()=>i.removeEventListener(y,m))}}}else if(h[0]==="#"){let c=h.substring(1);if(c[0]=="#")o[d]=c;else{o[d]=i[c],c[0]==="$"&&(c=c.substring(1),o[d]="$"+i[c]);let m=()=>{p(),this.applyBinding(t,s,e,i,n)},y=this.getChangedEventName(t,c);i.addEventListener(y,m),a||(a=[]),a.push(()=>i.removeEventListener(y,m))}}h[0]==="."&&(o[d]=this._visualizationHandler.getNormalizedSignalName(h,e,t))}let g=new Array(o.length);for(let d=0;d<o.length;d++){let h=o[d];if(h[0]==="?"){if(i){let c=h.substring(1),m=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,i[c],g,d,u,!1,e),y=!1)};i.addEventListener(v.camelToDashCase(c)+"-changed",m),a||(a=[]),a.push(()=>i.removeEventListener(v.camelToDashCase(c)+"-changed",m));try{this.handleValueChanged(t,i,s,i[c],g,d,u,!1,e)}catch(y){console.error(y)}s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,y=>i[c]=y)}}else if(h[0]==="#"){let c=h.substring(1),m=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,t[c],g,d,u,!1,e),y=!1)};t.addEventListener(v.camelToDashCase(c)+"-changed",m),a||(a=[]),a.push(()=>t.removeEventListener(v.camelToDashCase(c)+"-changed",m));try{this.handleValueChanged(t,i,s,t[c],g,d,u,!1,e)}catch(y){console.error(y)}s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,y=>t[c]=y)}else if(h[0]==="$"){let c=h.substring(1);c[0]==="."&&(c=this._visualizationHandler.getNormalizedSignalName(c,e,t)),this._visualizationHandler.getObject(c).then(m=>{this.handleValueChanged(t,i,s,m,g,d,u,!0,e)})}else if(h[0]==="\xA7"){let c=h.substring(1),m=n.valueProvider(c,{element:t,binding:s,relativeSignalPath:e,root:i});m instanceof Promise?m.then(x=>this.handleValueChanged(t,i,s,x,g,d,u,!0,e)):this.handleValueChanged(t,i,s,m,g,d,u,!0,e),n.valueChangedCallbacks||(n.valueChangedCallbacks=new Map);let y=n.valueChangedCallbacks.get(c);y==null&&(y=[],n.valueChangedCallbacks.set(c,y)),y.push(()=>{let x=n.valueProvider(c,{element:t,binding:s,relativeSignalPath:e,root:i});x instanceof Promise?x.then(ue=>this.handleValueChanged(t,i,s,ue,g,d,u,!0,e)):this.handleValueChanged(t,i,s,x,g,d,u,!0,e)})}else if(h.includes("{")){let c=new H(this,this._visualizationHandler,h,m=>this.handleValueChanged(t,i,s,m.val,g,d,u,!1,e),t,e,i,n);a||(a=[]),a.push(()=>c.dispose()),s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,m=>c.setState(m))}else if(s[1].historic)if(s[1].historic.reloadInterval){let c={timerId:-1},m=async()=>{let y=await this._visualizationHandler.getHistoricData(h,s[1].historic);this.handleValueChanged(t,i,s,y?.values,g,d,u,!0,e),c.timerId!==null&&(c.timerId=setTimeout(m,s[1].historic.reloadInterval))};m(),a||(a=[]),a.push(()=>{c.timerId>0&&clearTimeout(c.timerId),c.timerId=null})}else this._visualizationHandler.getHistoricData(h,s[1].historic).then(c=>this.handleValueChanged(t,i,s,c?.values,g,d,u,!0,e));else{let c=(m,y)=>this.handleValueChanged(t,i,s,y.val,g,d,u,!1,e);l.push([h,c,this._visualizationHandler.subscribeState(h,c)]),this._visualizationHandler.getState(h).then(m=>this.handleValueChanged(t,i,s,m?.val,g,d,u,!1,e)),s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,m=>this._visualizationHandler.setState(h,m))}}return p}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 n=s[i];n instanceof De?n.on(()=>{let l;t[1].target==f.attribute?l=s.getAttribute(t[0]):l=s[t[0]],l=r.parseValueWithType(l,t),t[1].compiledExpressionTwoWay&&(l=t[1].compiledExpressionTwoWay(l)),e(l)}):s.addEventListener(i,l=>{let a;t[1].target==f.attribute?a=s.getAttribute(t[0]):a=s[t[0]],a=r.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,n,l,a,p,o){let u=i;if(!p&&l==0&&(u=r.parseValueWithType(u,e)),n[l]=u,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)),n[a.length-1]={element:t,root:s,boundNames:e[1].signal,boundTargetName:e[0],boundTargetType:e[1].target},u=e[1].compiledExpression(...n),n[a.length-1]=u),e[1].converter)if(typeof e[1].converter=="string")u=this.namedConverterCallback(e[1].converter,u,t,e);else{let g=u!=null?u.toString():u;if(g in e[1].converter){let d=e[1].converter[g];typeof d=="string"?u=new Function(a,"return `"+e[1].converter[g]+"`")(...n):u=d}else{let d=!1,h=parseFloat(u);for(let c in e[1].converter)if(c.length>2&&c[0]===">"&&c[1]==="="){let m=parseFloat(c.substring(2));if(h>=m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>2&&c[0]==="<"&&c[1]==="="){let m=parseFloat(c.substring(2));if(h<=m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>1&&c[0]===">"){let m=parseFloat(c.substring(1));if(h>m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>1&&c[0]==="<"){let m=parseFloat(c.substring(1));if(h<m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else{let m=c.split("-");if(m.length>1&&(m[0]===""||h>=parseFloat(m[0]))&&(m[1]===""||parseFloat(m[1])>=h)){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}!d&&e[1].converterDefault!==void 0&&(u=e[1].converterDefault)}}if(e[1].inverted&&(u=!u),e[1].writeBackSignal){let g=e[1].writeBackSignal;g[0]==="."&&(g=o+g),this._visualizationHandler.setState(g,u,!0)}e[1].target==f.property?t[e[0]]=u:e[1].target==f.attribute?t.setAttribute(e[0],u):e[1].target==f.css?t.style[e[0]]=u:e[1].target==f.cssvar?t.style.setProperty(e[0],u):e[1].target==f.class?u?t.classList.add(e[0]):t.classList.remove(e[0]):e[1].target==f.visible&&(t.style.visibility=u?"":"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 te=class{name;relativeSignalsPath;commands;parameters};import{deepValue as _,setDeepValue as se,sleep as Fe}from"@node-projects/web-component-designer/dist/elements/helper/Helper.js";import j from"long";var ie=class{_visualizationHandler;_subscriptionCallback=()=>{};constructor(r){this._visualizationHandler=r}async execute(r,t){for(let s=0;s<r.length;s++){let e=r[s];if(e.type=="Exit")break;if(e.type=="Goto"){let i=await this.getValue(e.label,t);if(s=r.findIndex(n=>n.type=="Label"&&n.label==i),s<0)break}else if(e.type=="Condition"){let i=await this.getValue(e.value1,t),n=await this.getValue(e.value2,t),l=await this.getValue(e.comparisonType,t),a=!1;switch(l){case"==null":a=i==null;break;case"!=null":a=i!=null;break;case"==true":a=i==!0;break;case"==false":a=i==!1;break;case"==":a=i==n;break;case"!=":a=i!=n;break;case">":a=i>n;break;case"<":a=i<n;break;case">=":a=i>=n;break;case"<=":a=i<=n;break;case"&&":a=i&&n;break;case"||":a=i||n;break}if(a){await this.runExternalScript(await this.getValue(e.trueScriptName,t),await this.getValue(e.trueScriptType,t));let p=await this.getValue(e.trueGotoLabel,t);if(p&&(s=r.findIndex(o=>o.type=="Label"&&o.label==p),s<0))break}else{await this.runExternalScript(await this.getValue(e.falseScriptName,t),await this.getValue(e.falseScriptType,t));let p=await this.getValue(e.falseGotoLabel,t);if(p&&(s=r.findIndex(o=>o.type=="Label"&&o.label==p),s<0))break}}else if(!await this.runScriptCommand(e,t))break}}async getValueFromTarget(r,t,s){return r==="property"?_(s.root,t):r==="elementProperty"?_(s.element,t):(await this._visualizationHandler.getState(this.getSignalName(t,s)))?.val}async setValueOnTarget(r,t,s,e){r==="property"?se(s.root,t,e):r==="elementProperty"?se(s.element,t,e):await this._visualizationHandler.setState(this.getSignalName(t,s),e)}async runExternalScript(r,t){}async runScriptCommand(command,context){switch(command.type){case"Comment":case"Label":case"Condition":case"Goto":case"Exit":break;case"OpenUrl":{window.open(await this.getValue(command.url,context),command.target);break}case"Delay":{let r=await this.getValue(command.value??500,context);await Fe(r);break}case"Console":{let r=await this.getValue(command.target??"log",context),t=await this.getValue(command.message,context);console[r](t);break}case"ToggleSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),s=await this.getValueFromTarget(t,r,context);await this._visualizationHandler.setState(this.getSignalName(r,context),!s);break}case"ToggleSignalValueThroughList":{let r=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=r.indexOf(e)+1;i>=r.length&&(i=0);let n=r[i];await this._visualizationHandler.setState(this.getSignalName(t,context),n);break}case"SetSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context);await this.setValueOnTarget(t,r,context,await this.getValue(command.value,context));break}case"IncrementSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,r,context)+await this.getValue(command.value,context);await this.setValueOnTarget(t,r,context,e);break}case"DecrementSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,r,context)-await this.getValue(command.value,context);await this.setValueOnTarget(t,r,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 r=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,r,context),i=j.fromNumber(1).shiftLeft(t),n=j.fromNumber(e).or(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"ClearBitInSignal":{let r=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,r,context),i=j.fromNumber(1).shiftLeft(t);i.negate();let n=j.fromNumber(e).and(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"ToggleBitInSignal":{let r=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,r,context),i=j.fromNumber(1).shiftLeft(t),n=j.fromNumber(e).xor(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"Javascript":{let r=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",r)),command.compiledScript(t);break}case"SetElementProperty":{command=N.upgradeSetElementProperty(command);let r=await this.getValue(command.name,context);r===""&&(r=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),n=await this.getValue(command.targetSelector,context),l=await this.getValue(command.mode??"toggle",context),a=this.getTargetFromTargetSelector(context,i,s,n);for(let p of a)e=="attribute"?p.setAttribute(r,t):e=="property"?p[r]=t:e=="css"?p.style[r]=t:e=="class"&&(l==="toggle"?p.classList.toggle(r??t):l==="remove"?p.classList.remove(r??t):p.classList.add(r??t));break}case"SubscribeSignal":{let r=await this.getValue(command.signal,context);if(await this.getValue(command.oneTime,context)){let s=()=>{this._visualizationHandler.unsubscribeState(r,s,null)};this._visualizationHandler.subscribeState(r,s)}else this._visualizationHandler.subscribeState(r,this._subscriptionCallback);break}case"UnsubscribeSignal":{let r=await this.getValue(command.signal,context);this._visualizationHandler.unsubscribeState(r,this._subscriptionCallback,null);break}case"WriteSignalsInGroup":{let r=await this.getValue(command.group,context);this._visualizationHandler.writeSignalsInGroup(r);break}case"ClearSignalsInGroup":{let r=await this.getValue(command.group,context);this._visualizationHandler.clearSignalsInGroup(r);break}case"RunScript":{let r=await this.getValue(command.name,context),t=await this.getValue(command.scriptType,context);this.runExternalScript(r,t);break}case"ShowMessageBox":{let r=null;if(await this.getValue(command.buttons,context)=="yesNo"){let e=await this.getValue(command.message,context);confirm(e)?r=1:r=2}else{let e=await this.getValue(command.message,context);alert(e),r=1}let s=await this.getValue(command.resultSignal,context);s&&this._visualizationHandler.setState(s,r);break}case"ShowPrompt":{let r=await this.getValue(command.message,context),t=await this.getValue(command.default,context),s=prompt(r,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(r,t,s){if(t==="container"){let e=r.element.getRootNode().host;for(let i=0;i<(s??0);i++)e=e.getRootNode().host;return e}else if(t==="element"){let e=r.element;for(let i=0;i<(s??0);i++)e=e.parentElement;return e}return null}getTargetFromTargetSelector(r,t,s,e){let i=this.getTarget(r,t,s),n=[i];return e&&(t==="container"?n=i.shadowRoot.querySelectorAll(e):n=i.querySelectorAll(e)),n}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 r=_(outerContext.root,value.name);return(await this._visualizationHandler.getState(this.getSignalName(r,outerContext)))?.val}case"event":{let r=outerContext.event;return value.name&&(r=_(r,value.name)),r}case"parameter":return outerContext.parameters[value.name];case"context":return _(outerContext,value.name);case"complexString":{let r=value.name;return r!=null?await this.parseStringWithValues(r,outerContext):null}case"complexSignal":{let r=value.name;if(r!=null){let t=await this.parseStringWithValues(r,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(r,t){let s=J(r),e=await Promise.all(s.signals.map(n=>this.getStateOrFieldOrParameter(this.getSignalName(n,t),t))),i=s.parts[0];for(let n=0;n<s.parts.length-1;n++){let l=e[n];typeof l=="object"&&(l=l.val),l==null&&(l=""),i+=l+s.parts[n+1]}return i}getSignalName(r,t){return r[0]==="."?t.relativeSignalsPath+r:r}createScriptContext(r,t,s,e,i){return{root:r,event:t,element:s,parameters:e,relativeSignalsPath:i}}async assignAllScripts(r,t,s,e,i,n,l,a){let p=s.querySelectorAll("*");n??=this.createScriptContext;let o=null;if(t)try{o=await import(URL.createObjectURL(new Blob([t],{type:"application/javascript"}))),a?a(o):o.init&&o.init(e,s)}catch(u){console.error("error parsing javascript - "+r,u)}for(let u of p)for(let g of u.attributes)if(g.name[0]=="@")try{let d=g.name.substring(1),h=g.value.trim();if(h[0]=="{"){let c=JSON.parse(h);if("commands"in c)u.addEventListener(d,m=>this.execute(c.commands,n(e,m,u,c.parameters,c.relativeSignalsPath)));else if("blocks"in c){let m=null;u.addEventListener(d,async y=>{m||(m=await X(c)),m(y,s,c.parameters,c.relativeSignalsPath??"",i,n(e,y,u,c.parameters,c.relativeSignalsPath))})}else if(l)l(u,d,c);else if("name"in c){let m=c.name;u.addEventListener(d,y=>{o[m]?o[m](y,u,s,e,c.parameters):console.warn("javascript function named: "+m+' not found, maybe missing a "export" ?')})}}else u.addEventListener(d,c=>{o[h]?o[h](c,u,s,e):console.warn("javascript function named: "+h+' not found, maybe missing a "export" ?')})}catch{console.warn("error assigning script",u,g)}return o}};import{OverlayLayer as He,DesignItem as T,InsertAction as Je,BindingTarget as k,PropertyType as M}from"@node-projects/web-component-designer";var ae=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 n=t.getNormalizedElementCoordinates(e);this.rect=t.overlayLayer.drawRect("IobrokerWebuiBindableObjectDragDropService",n.x,n.y,n.width,n.height,"",null,He.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 n=this.rectMap.get(e);t.overlayLayer.removeOverlay(n),this.rectMap.delete(e)}}dragOver(t,s,e){return"copy"}async drop(t,s,e,i){for(let p of this.rectMap.values())t.overlayLayer.removeOverlay(p);this.rectMap.clear();let n=T.GetDesignItem(i),l=await this._visualizationHandler.getObject(e.fullName),a=this._visualizationHandler.getSignalInformation(l);if(n&&!n.isRootItem)if(i instanceof HTMLInputElement){let p={signal:e.fullName,target:k.property},o=this._bindingsHelper.serializeBinding(i,i.type=="checkbox"?"checked":"value",p);n.setAttribute(o[0],o[1])}else{let p={signal:e.fullName,target:k.content},o=this._bindingsHelper.serializeBinding(i,null,p);n.setAttribute(o[0],o[1])}else{let p=t.getNormalizedEventCoordinates(s),o,u,g=await this._visualizationHandler.getState(e.fullName);if(a.role==="url"&&typeof g?.val=="string")if(g.val.endsWith("jpg")||g.val.endsWith("jpeg")||g.val.endsWith("png")||g.val.endsWith("gif")||g.val.endsWith("svg")){let d=document.createElement("img");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}else if(g.val.endsWith("mp4")){let d=document.createElement("video");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}else{let d=document.createElement("iframe");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}if(!o){let d=document.createElement("input");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h=a.writeable!==!1,c={signal:e.fullName,target:k.property,twoWay:h},m=this._bindingsHelper.serializeBinding(d,"value",c);a.type==="boolean"?(m=this._bindingsHelper.serializeBinding(d,"checked",c),o.setAttribute("type","checkbox")):a.role=="date"?(c.twoWay=h,m=this._bindingsHelper.serializeBinding(d,"value-as-number",c),o.setAttribute("type","date"),o.setAttribute("readonly","")):a.role=="datetime"&&(c.twoWay=h,m=this._bindingsHelper.serializeBinding(d,"value-as-number",c),o.setAttribute("type","datetime-local"),o.setAttribute("readonly","")),o.setAttribute(m[0],m[1])}o.setStyle("position","absolute"),o.setStyle("left",p.x+"px"),o.setStyle("top",p.y+"px"),t.instanceServiceContainer.undoService.execute(new Je(t.rootDesignItem,t.rootDesignItem.childCount,o)),u.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 n={signal:e.fullName,target:k.property};s.propertyType==M.attribute&&(n.target=k.attribute),s.propertyType==M.cssValue&&(n.target=k.css),n.signal=e.fullName,n.twoWay=s.propertyType==M.property||s.propertyType==M.propertyAndAttribute;let l=i[0].openGroup("drop binding");for(let a of i){let p=this._bindingsHelper.serializeBinding(a.element,s.name,n);a.setAttribute(p[0],p[1])}l.commit()}};import{BindingMode as U,BindingTarget as ne,PropertiesHelper as Ue}from"@node-projects/web-component-designer";var re=class r{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===ne.css||e[1].target===ne.attribute?Ue.camelToDashCase(e[0]):e[0],target:e[1].target,mode:e[1].twoWay?U.twoWay:U.oneWay,invert:e[1].inverted,bindableObjectNames:e[1].signal.split(";"),expression:e[1].expression,expressionTwoWay:e[1].expressionTwoWay,converter:e[1].converter,type:r.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==U.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),n=t.openGroup("edit_binding");return t.setAttribute(i[0],i[1]),n.commit(),!0}clearBinding(t,s,e){let i=this._bindingsHelper.getBindingAttributeName(t.element,s,e);return t.removeAttribute(i),!0}};var le=class{getRefactorings(t){let s=[];for(let e of t){let i=e.serviceContainer.bindingService.getBindings(e);if(i)for(let n of i)for(let l of n.bindableObjectNames){let a="signal",p="";if(l.includes(":")){let o=l.split(":")[0],u=l.substring(o.length+1);u.startsWith("?")&&(u=u.substring(1),p="?",a="property",u.startsWith("?")&&(u=u.substring(1),p="??")),s.push({service:this,name:u,itemType:a,designItem:e,type:"binding",sourceObject:n,display:n.target+"/"+n.targetName+" - "+o+":",shortName:o,prefix:p})}else l.startsWith("?")&&(l=l.substring(1),p="?",a="property",l.startsWith("?")&&(l=l.substring(1),p="??")),s.push({service:this,name:l,itemType:a,designItem:e,type:"binding",sourceObject:n,display:n.target+"/"+n.targetName,prefix:p})}}return s}refactor(t,s,e){let i=t.sourceObject;t.shortName?i.bindableObjectNames=i.bindableObjectNames.map(n=>n==t.shortName+":"+t.prefix+s?t.shortName+":"+t.prefix+e:n):i.bindableObjectNames=i.bindableObjectNames.map(n=>n==t.prefix+s?t.prefix+e:n),t.designItem.serviceContainer.bindingService.setBinding(t.designItem,i)}};var oe=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 ce=class{getRefactorings(t){let s=[];for(let e of t)for(let i of e.attributes())if(i[0][0]=="@"){let n=i[1];if(n[0]=="{"){let l=JSON.parse(n);if("commands"in l)for(let a of l.commands){for(let p in a){let o=a[p];if(o!=null&&typeof o=="object"){let u=o;if(u.source==="signal")s.push({name:u.name,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[signal]",refactor:g=>u.name=g});else if(u.source==="property")s.push({name:u.name,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[property]",refactor:g=>u.name=g});else if(u.source==="complexString")for(let g of u.name.matchAll(/\{(.*?)\}/g)){let d=g[0],h=g[1];if(h[0]==="?"){let c="?";h=h.substring(1),h[0]==="?"&&(c="??",h=h.substring(1)),s.push({name:h,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[complexString]->property",refactor:m=>u.name=u.name.replace(d,"{"+c+m+"}")})}else s.push({name:h,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[complexString]->signal",refactor:c=>u.name=u.name.replace(d,"{"+c+"}")})}}}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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.screen=p});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:l,refactor:p=>a.screen=p});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:l,refactor:p=>a.targetSignal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.resultSignal=p});break}}else"blocks"in l;if("parameters"in l)for(let a in l.parameters)typeof l.parameters[a]=="string"&&s.push({name:l.parameters[a],itemType:"parameter",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:i[0].substring(1)+"/parameters/"+a,refactor:p=>l.parameters[a]=p})}}return s}refactor(t,s,e){t.refactor(e);let i=JSON.stringify(t.sourceObject);t.designItem.setAttribute(t.targetName,i)}};import{BasePropertyEditor as Xe}from"@node-projects/web-component-designer";var pe=class extends Xe{_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 n=new AbortController;i.objectDoubleclicked.on(()=>{n.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:n.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}};export{ae as BindableObjectDragDropService,D as BindingsEditor,E as BindingsEditorHistoric,ee as BindingsHelper,C as BlocklyScriptEditor,L as EventAssignment,O as ParameterEditor,oe as PropertyGridDragDropService,te as Script,ce as ScriptRefactorService,ie as ScriptSystem,pe as SignalPropertyEditor,I as SimpleScriptEditor,le as VisualizationBindingsRefactorService,re as VisualizationBindingsService,W as VisualizationPropertyGrid,B as bindingPrefixAttribute,R as bindingPrefixClass,w as bindingPrefixContent,V as bindingPrefixCss,A as bindingPrefixCssVar,Pe as bindingPrefixInsideCss,Me as bindingPrefixInsideCssVarName,S as bindingPrefixProperty,F as bindingPrefixVisible,Ft as bindingsInCssRegex,X as generateEventCodeFromBlockly,P as getNestedProperty,z as isLit,J as parseBindingString};
389
+ `)&&!e.expression.includes(";")&&!e.expressionTwoWay&&e.converter==null&&!e.historic&&!e.writeBackSignal?[A+v.camelToDashCase(s),(e.inverted?"!":"")+e.signal+";"+e.expression+n]:((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+r.camelToDotCase(s),JSON.stringify(i)]:e.target==f.css?[V+v.camelToDashCase(s),JSON.stringify(i)]:e.target==f.cssvar?[A+r.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+r.camelToDotCase(s):e==f.css?V+v.camelToDashCase(s):e==f.visible?F:e==f.cssvar?A+r.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){let n=[],l=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),a;for(;a=l.nextNode();){let p=this.getBindings(a);for(let o of p)try{let u=this.applyBinding(a,o,s,e,i);if(n.push(u),o[1].maybeLitElement&&a.localName.includes("-")&&!customElements.get(a.localName)){let g=a,d=o;customElements.whenDefined(a.localName).then(()=>{z(g)&&(u(),d[1].events=d[1].litEventNames,n.push(this.applyBinding(g,d,s,e,i)))})}}catch(u){console.warn("error applying binding",a,o,u)}}return n}static#e=0;async parseCssBindings(t,s,e,i){let n=await import("@node-projects/css-parser"),l=n.parse(t),a;for(let o of l.stylesheet.rules)if(o.type===n.CssTypes.rule){for(let u of o.declarations)if(u.type===n.CssTypes.declaration&&u.value.includes(Pe)){let g=this.parseCssBinding(u.value,s,e,i);u.value=g[0],a?a.push(...g[1]):a=g[1]}}let p=n.stringify(l,{indent:"",compress:!0});return[Le(p),a]}parseCssBinding(t,s,e,i,n){t=t.trim();let l="",a="",p=!1,o="",u=!1,g=null,d=[];for(let h=0;h<t.length;h++){let c=t[h];if(p)if(u)o+=c;else if(g&&c==="\\")u=!0;else if(c===g)g=null;else if(g===null&&c===")"){let m=r.#e++,y=Me+m,x=[y,{signal:o,target:f.cssvar}];o.startsWith("{")&&(x=JSON.parse(o)),d.push(this.applyBinding(s,x,e,i,n)),l+="var("+y+")",p=!1,o=""}else o+=c;else c==="("?(a!=="bind"?(l+=a,l+=c):(p=!0,t[h+1]==="'"||t[h+1]==='"'?(h++,g=t[h]):g=null),a=""):c===" "||c===","||c==="("||c==="+"||c==="-"||c==="*"||c==="/"?(l+=a+c,a=""):a+=c}return[l+a,d]}applyBinding(t,s,e,i,n){let l=[],a,p=()=>{for(let d of l)this._visualizationHandler.unsubscribeState(d[0],d[1],d[2]);if(a)for(let d of a)d()},o=s[1].signal.split(";"),u=new Array(o.length);for(let d=0;d<o.length;d++){let h=o[d];if(u[d]="__"+d,h.includes(":")){let c=h.split(":");u[d]=c[0],h=c[1],o[d]=h}if(h[0]==="?"){if(i){let c=h.substring(1);if(c[0]=="?")o[d]=c;else{o[d]=i[c],c[0]==="$"&&(c=c.substring(1),o[d]="$"+i[c]);let m=()=>{p(),this.applyBinding(t,s,e,i,n)},y=this.getChangedEventName(i,c);i.addEventListener(y,m),a||(a=[]),a.push(()=>i.removeEventListener(y,m))}}}else if(h[0]==="#"){let c=h.substring(1);if(c[0]=="#")o[d]=c;else{o[d]=i[c],c[0]==="$"&&(c=c.substring(1),o[d]="$"+i[c]);let m=()=>{p(),this.applyBinding(t,s,e,i,n)},y=this.getChangedEventName(t,c);i.addEventListener(y,m),a||(a=[]),a.push(()=>i.removeEventListener(y,m))}}h[0]==="."&&(o[d]=this._visualizationHandler.getNormalizedSignalName(h,e,t))}let g=new Array(o.length);for(let d=0;d<o.length;d++){let h=o[d];if(h[0]==="?"){if(i){let c=h.substring(1),m=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,i[c],g,d,u,!1,e),y=!1)};i.addEventListener(v.camelToDashCase(c)+"-changed",m),a||(a=[]),a.push(()=>i.removeEventListener(v.camelToDashCase(c)+"-changed",m));try{this.handleValueChanged(t,i,s,i[c],g,d,u,!1,e)}catch(y){console.error(y)}s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,y=>i[c]=y)}}else if(h[0]==="#"){let c=h.substring(1),m=()=>{let y=!1;y||(y=!0,this.handleValueChanged(t,i,s,t[c],g,d,u,!1,e),y=!1)};t.addEventListener(v.camelToDashCase(c)+"-changed",m),a||(a=[]),a.push(()=>t.removeEventListener(v.camelToDashCase(c)+"-changed",m));try{this.handleValueChanged(t,i,s,t[c],g,d,u,!1,e)}catch(y){console.error(y)}s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,y=>t[c]=y)}else if(h[0]==="$"){let c=h.substring(1);c[0]==="."&&(c=this._visualizationHandler.getNormalizedSignalName(c,e,t)),this._visualizationHandler.getObject(c).then(m=>{this.handleValueChanged(t,i,s,m,g,d,u,!0,e)})}else if(h[0]==="\xA7"){let c=h.substring(1),m=n.valueProvider(c,{element:t,binding:s,relativeSignalPath:e,root:i});m instanceof Promise?m.then(x=>this.handleValueChanged(t,i,s,x,g,d,u,!0,e)):this.handleValueChanged(t,i,s,m,g,d,u,!0,e),n.valueChangedCallbacks||(n.valueChangedCallbacks=new Map);let y=n.valueChangedCallbacks.get(c);y==null&&(y=[],n.valueChangedCallbacks.set(c,y)),y.push(()=>{let x=n.valueProvider(c,{element:t,binding:s,relativeSignalPath:e,root:i});x instanceof Promise?x.then(ue=>this.handleValueChanged(t,i,s,ue,g,d,u,!0,e)):this.handleValueChanged(t,i,s,x,g,d,u,!0,e)})}else if(h.includes("{")){let c=new H(this,this._visualizationHandler,h,m=>this.handleValueChanged(t,i,s,m.val,g,d,u,!1,e),t,e,i,n);a||(a=[]),a.push(()=>c.dispose()),s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,m=>c.setState(m))}else if(s[1].historic)if(s[1].historic.reloadInterval){let c={timerId:-1},m=async()=>{let y=await this._visualizationHandler.getHistoricData(h,s[1].historic);this.handleValueChanged(t,i,s,y?.values,g,d,u,!0,e),c.timerId!==null&&(c.timerId=setTimeout(m,s[1].historic.reloadInterval))};m(),a||(a=[]),a.push(()=>{c.timerId>0&&clearTimeout(c.timerId),c.timerId=null})}else this._visualizationHandler.getHistoricData(h,s[1].historic).then(c=>this.handleValueChanged(t,i,s,c?.values,g,d,u,!0,e));else{let c=(m,y)=>this.handleValueChanged(t,i,s,y.val,g,d,u,!1,e);l.push([h,c,this._visualizationHandler.subscribeState(h,c)]),this._visualizationHandler.getState(h).then(m=>this.handleValueChanged(t,i,s,m?.val,g,d,u,!1,e)),s[1].twoWay&&d==0&&this.addTwoWayBinding(s,t,m=>this._visualizationHandler.setState(h,m))}}return p}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 n=s[i];n instanceof De?n.on(()=>{let l;t[1].target==f.attribute?l=s.getAttribute(t[0]):l=s[t[0]],l=r.parseValueWithType(l,t),t[1].compiledExpressionTwoWay&&(l=t[1].compiledExpressionTwoWay(l)),e(l)}):s.addEventListener(i,l=>{let a;t[1].target==f.attribute?a=s.getAttribute(t[0]):a=s[t[0]],a=r.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,n,l,a,p,o){let u=i;if(!p&&l==0&&(u=r.parseValueWithType(u,e)),n[l]=u,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)),n[a.length-1]={element:t,root:s,boundNames:e[1].signal,boundTargetName:e[0],boundTargetType:e[1].target},u=e[1].compiledExpression(...n),n[a.length-1]=u),e[1].converter)if(typeof e[1].converter=="string")u=this.namedConverterCallback(e[1].converter,u,t,e);else{let g=u!=null?u.toString():u;if(g in e[1].converter){let d=e[1].converter[g];typeof d=="string"?u=new Function(a,"return `"+e[1].converter[g]+"`")(...n):u=d}else{let d=!1,h=parseFloat(u);for(let c in e[1].converter)if(c.length>2&&c[0]===">"&&c[1]==="="){let m=parseFloat(c.substring(2));if(h>=m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>2&&c[0]==="<"&&c[1]==="="){let m=parseFloat(c.substring(2));if(h<=m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>1&&c[0]===">"){let m=parseFloat(c.substring(1));if(h>m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else if(c.length>1&&c[0]==="<"){let m=parseFloat(c.substring(1));if(h<m){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}else{let m=c.split("-");if(m.length>1&&(m[0]===""||h>=parseFloat(m[0]))&&(m[1]===""||parseFloat(m[1])>=h)){let y=e[1].converter[c];typeof y=="string"?u=new Function(a,"return `"+e[1].converter[c]+"`")(...n):u=y,d=!0;break}}!d&&e[1].converterDefault!==void 0&&(u=e[1].converterDefault)}}if(e[1].inverted&&(u=!u),e[1].writeBackSignal){let g=e[1].writeBackSignal;g[0]==="."&&(g=o+g),this._visualizationHandler.setState(g,u,!0)}e[1].target==f.property?t[e[0]]=u:e[1].target==f.attribute?t.setAttribute(e[0],u):e[1].target==f.css?t.style[e[0]]=u:e[1].target==f.cssvar?t.style.setProperty(e[0],u):e[1].target==f.class?u?t.classList.add(e[0]):t.classList.remove(e[0]):e[1].target==f.visible&&(t.style.visibility=u?"":"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 te=class{name;relativeSignalsPath;commands;parameters};import{deepValue as _,setDeepValue as se,sleep as Fe}from"@node-projects/web-component-designer/dist/elements/helper/Helper.js";import j from"long";var ie=class{_visualizationHandler;_subscriptionCallback=()=>{};constructor(r){this._visualizationHandler=r}async execute(r,t){for(let s=0;s<r.length;s++){let e=r[s];if(e.type=="Exit")break;if(e.type=="Goto"){let i=await this.getValue(e.label,t);if(s=r.findIndex(n=>n.type=="Label"&&n.label==i),s<0)break}else if(e.type=="Condition"){let i=await this.getValue(e.value1,t),n=await this.getValue(e.value2,t),l=await this.getValue(e.comparisonType,t),a=!1;switch(l){case"==null":a=i==null;break;case"!=null":a=i!=null;break;case"==true":a=i==!0;break;case"==false":a=i==!1;break;case"==":a=i==n;break;case"!=":a=i!=n;break;case">":a=i>n;break;case"<":a=i<n;break;case">=":a=i>=n;break;case"<=":a=i<=n;break;case"&&":a=i&&n;break;case"||":a=i||n;break}if(a){await this.runExternalScript(await this.getValue(e.trueScriptName,t),await this.getValue(e.trueScriptType,t));let p=await this.getValue(e.trueGotoLabel,t);if(p&&(s=r.findIndex(o=>o.type=="Label"&&o.label==p),s<0))break}else{await this.runExternalScript(await this.getValue(e.falseScriptName,t),await this.getValue(e.falseScriptType,t));let p=await this.getValue(e.falseGotoLabel,t);if(p&&(s=r.findIndex(o=>o.type=="Label"&&o.label==p),s<0))break}}else if(!await this.runScriptCommand(e,t))break}}async getValueFromTarget(r,t,s){return r==="property"?_(s.root,t):r==="elementProperty"?_(s.element,t):(await this._visualizationHandler.getState(this.getSignalName(t,s)))?.val}async setValueOnTarget(r,t,s,e){r==="property"?se(s.root,t,e):r==="elementProperty"?se(s.element,t,e):await this._visualizationHandler.setState(this.getSignalName(t,s),e)}async runExternalScript(r,t){}async runScriptCommand(command,context){switch(command.type){case"Comment":case"Label":case"Condition":case"Goto":case"Exit":break;case"OpenUrl":{window.open(await this.getValue(command.url,context),command.target);break}case"Delay":{let r=await this.getValue(command.value??500,context);await Fe(r);break}case"Console":{let r=await this.getValue(command.target??"log",context),t=await this.getValue(command.message,context);console[r](t);break}case"ToggleSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),s=await this.getValueFromTarget(t,r,context);await this._visualizationHandler.setState(this.getSignalName(r,context),!s);break}case"ToggleSignalValueThroughList":{let r=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=r.indexOf(e)+1;i>=r.length&&(i=0);let n=r[i];await this._visualizationHandler.setState(this.getSignalName(t,context),n);break}case"SetSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context);await this.setValueOnTarget(t,r,context,await this.getValue(command.value,context));break}case"IncrementSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,r,context)+await this.getValue(command.value,context);await this.setValueOnTarget(t,r,context,e);break}case"DecrementSignalValue":{let r=await this.getValue(command.signal,context),t=await this.getValue(command.target,context),e=await this.getValueFromTarget(t,r,context)-await this.getValue(command.value,context);await this.setValueOnTarget(t,r,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 r=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,r,context),i=j.fromNumber(1).shiftLeft(t),n=j.fromNumber(e).or(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"ClearBitInSignal":{let r=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,r,context),i=j.fromNumber(1).shiftLeft(t);i.negate();let n=j.fromNumber(e).and(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"ToggleBitInSignal":{let r=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,r,context),i=j.fromNumber(1).shiftLeft(t),n=j.fromNumber(e).xor(i).toNumber();await this.setValueOnTarget(s,r,context,n);break}case"Javascript":{let r=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",r)),command.compiledScript(t);break}case"SetElementProperty":{command=N.upgradeSetElementProperty(command);let r=await this.getValue(command.name,context);r===""&&(r=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),n=await this.getValue(command.targetSelector,context),l=await this.getValue(command.mode??"toggle",context),a=this.getTargetFromTargetSelector(context,i,s,n);for(let p of a)e=="attribute"?p.setAttribute(r,t):e=="property"?p[r]=t:e=="css"?p.style[r]=t:e=="class"&&(l==="toggle"?p.classList.toggle(r??t):l==="remove"?p.classList.remove(r??t):p.classList.add(r??t));break}case"SubscribeSignal":{let r=await this.getValue(command.signal,context);if(await this.getValue(command.oneTime,context)){let s=()=>{this._visualizationHandler.unsubscribeState(r,s,null)};this._visualizationHandler.subscribeState(r,s)}else this._visualizationHandler.subscribeState(r,this._subscriptionCallback);break}case"UnsubscribeSignal":{let r=await this.getValue(command.signal,context);this._visualizationHandler.unsubscribeState(r,this._subscriptionCallback,null);break}case"WriteSignalsInGroup":{let r=await this.getValue(command.group,context);this._visualizationHandler.writeSignalsInGroup(r);break}case"ClearSignalsInGroup":{let r=await this.getValue(command.group,context);this._visualizationHandler.clearSignalsInGroup(r);break}case"RunScript":{let r=await this.getValue(command.name,context),t=await this.getValue(command.scriptType,context);this.runExternalScript(r,t);break}case"ShowMessageBox":{let r=null;if(await this.getValue(command.buttons,context)=="yesNo"){let e=await this.getValue(command.message,context);confirm(e)?r=1:r=2}else{let e=await this.getValue(command.message,context);alert(e),r=1}let s=await this.getValue(command.resultSignal,context);s&&this._visualizationHandler.setState(s,r);break}case"ShowPrompt":{let r=await this.getValue(command.message,context),t=await this.getValue(command.default,context),s=prompt(r,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(r,t,s){if(t==="container"){let e=r.element.getRootNode().host;for(let i=0;i<(s??0);i++)e=e.getRootNode().host;return e}else if(t==="element"){let e=r.element;for(let i=0;i<(s??0);i++)e=e.parentElement;return e}return null}getTargetFromTargetSelector(r,t,s,e){let i=this.getTarget(r,t,s),n=[i];return e&&(t==="container"?n=i.shadowRoot.querySelectorAll(e):n=i.querySelectorAll(e)),n}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 r=_(outerContext.root,value.name);return(await this._visualizationHandler.getState(this.getSignalName(r,outerContext)))?.val}case"event":{let r=outerContext.event;return value.name&&(r=_(r,value.name)),r}case"parameter":return outerContext.parameters[value.name];case"context":return _(outerContext,value.name);case"complexString":{let r=value.name;return r!=null?await this.parseStringWithValues(r,outerContext):null}case"complexSignal":{let r=value.name;if(r!=null){let t=await this.parseStringWithValues(r,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(r,t){let s=J(r),e=await Promise.all(s.signals.map(n=>this.getStateOrFieldOrParameter(this.getSignalName(n,t),t))),i=s.parts[0];for(let n=0;n<s.parts.length-1;n++){let l=e[n];typeof l=="object"&&(l=l.val),l==null&&(l=""),i+=l+s.parts[n+1]}return i}getSignalName(r,t){return r[0]==="."?t.relativeSignalsPath+r:r}createScriptContext(r,t,s,e,i){return{root:r,event:t,element:s,parameters:e,relativeSignalsPath:i}}async assignAllScripts(r,t,s,e,i,n,l,a){let p=s.querySelectorAll("*");n??=this.createScriptContext;let o=null;if(t)try{o=await import(URL.createObjectURL(new Blob([t],{type:"application/javascript"}))),a?a(o):o.init&&o.init(e,s)}catch(u){console.error("error parsing javascript - "+r,u)}for(let u of p)for(let g of u.attributes)if(g.name[0]=="@")try{let d=g.name.substring(1),h=g.value.trim();if(h[0]=="{"){let c=JSON.parse(h);if("commands"in c)u.addEventListener(d,m=>this.execute(c.commands,n(e,m,u,c.parameters,c.relativeSignalsPath)));else if("blocks"in c){let m=null;u.addEventListener(d,async y=>{m||(m=await X(c)),m(y,s,c.parameters,c.relativeSignalsPath??"",i,n(e,y,u,c.parameters,c.relativeSignalsPath))})}else if(l)l(u,d,c);else if("name"in c){let m=c.name;u.addEventListener(d,y=>{o[m]?o[m](y,u,s,e,c.parameters):console.warn("javascript function named: "+m+' not found, maybe missing a "export" ?')})}}else u.addEventListener(d,c=>{o[h]?o[h](c,u,s,e):console.warn("javascript function named: "+h+' not found, maybe missing a "export" ?')})}catch{console.warn("error assigning script",u,g)}return o}};import{OverlayLayer as He,DesignItem as T,InsertAction as Je,BindingTarget as k,PropertyType as M}from"@node-projects/web-component-designer";var ae=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 n=t.getNormalizedElementCoordinates(e);this.rect=t.overlayLayer.drawRect("IobrokerWebuiBindableObjectDragDropService",n.x,n.y,n.width,n.height,"",null,He.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 n=this.rectMap.get(e);t.overlayLayer.removeOverlay(n),this.rectMap.delete(e)}}dragOver(t,s,e){return"copy"}async drop(t,s,e,i){for(let p of this.rectMap.values())t.overlayLayer.removeOverlay(p);this.rectMap.clear();let n=T.GetDesignItem(i),l=await this._visualizationHandler.getObject(e.fullName),a=this._visualizationHandler.getSignalInformation(l);if(n&&!n.isRootItem)if(i instanceof HTMLInputElement){let p={signal:e.fullName,target:k.property},o=this._bindingsHelper.serializeBinding(i,i.type=="checkbox"?"checked":"value",p);n.setAttribute(o[0],o[1])}else{let p={signal:e.fullName,target:k.content},o=this._bindingsHelper.serializeBinding(i,null,p);n.setAttribute(o[0],o[1])}else{let p=t.getNormalizedEventCoordinates(s),o,u,g=await this._visualizationHandler.getState(e.fullName);if(a.role==="url"&&typeof g?.val=="string")if(g.val.endsWith("jpg")||g.val.endsWith("jpeg")||g.val.endsWith("png")||g.val.endsWith("gif")||g.val.endsWith("svg")){let d=document.createElement("img");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}else if(g.val.endsWith("mp4")){let d=document.createElement("video");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}else{let d=document.createElement("iframe");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h={signal:e.fullName,target:k.property},c=this._bindingsHelper.serializeBinding(d,"src",h);o.setAttribute(c[0],c[1]),o.element.src=g.val}if(!o){let d=document.createElement("input");o=T.createDesignItemFromInstance(d,t.serviceContainer,t.instanceServiceContainer),u=o.openGroup("Insert");let h=a.writeable!==!1,c={signal:e.fullName,target:k.property,twoWay:h},m=this._bindingsHelper.serializeBinding(d,"value",c);a.type==="boolean"?(m=this._bindingsHelper.serializeBinding(d,"checked",c),o.setAttribute("type","checkbox")):a.role=="date"?(c.twoWay=h,m=this._bindingsHelper.serializeBinding(d,"value-as-number",c),o.setAttribute("type","date"),o.setAttribute("readonly","")):a.role=="datetime"&&(c.twoWay=h,m=this._bindingsHelper.serializeBinding(d,"value-as-number",c),o.setAttribute("type","datetime-local"),o.setAttribute("readonly","")),o.setAttribute(m[0],m[1])}o.setStyle("position","absolute"),o.setStyle("left",p.x+"px"),o.setStyle("top",p.y+"px"),t.instanceServiceContainer.undoService.execute(new Je(t.rootDesignItem,t.rootDesignItem.childCount,o)),u.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 n={signal:e.fullName,target:k.property};s.propertyType==M.attribute&&(n.target=k.attribute),s.propertyType==M.cssValue&&(n.target=k.css),n.signal=e.fullName,n.twoWay=s.propertyType==M.property||s.propertyType==M.propertyAndAttribute;let l=i[0].openGroup("drop binding");for(let a of i){let p=this._bindingsHelper.serializeBinding(a.element,s.name,n);a.setAttribute(p[0],p[1])}l.commit()}};import{BindingMode as U,BindingTarget as ne,PropertiesHelper as Ue}from"@node-projects/web-component-designer";var re=class r{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===ne.css||e[1].target===ne.attribute?Ue.camelToDashCase(e[0]):e[0],target:e[1].target,mode:e[1].twoWay?U.twoWay:U.oneWay,invert:e[1].inverted,bindableObjectNames:e[1].signal.split(";"),expression:e[1].expression,expressionTwoWay:e[1].expressionTwoWay,converter:e[1].converter,type:r.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==U.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),n=t.openGroup("edit_binding");return t.setAttribute(i[0],i[1]),n.commit(),!0}clearBinding(t,s,e){let i=this._bindingsHelper.getBindingAttributeName(t.element,s,e);return t.removeAttribute(i),!0}};var le=class{getRefactorings(t){let s=[];for(let e of t){let i=e.serviceContainer.bindingService.getBindings(e);if(i)for(let n of i)for(let l of n.bindableObjectNames){let a="signal",p="";if(l.includes(":")){let o=l.split(":")[0],u=l.substring(o.length+1);u.startsWith("?")&&(u=u.substring(1),p="?",a="property",u.startsWith("?")&&(u=u.substring(1),p="??")),s.push({service:this,name:u,itemType:a,designItem:e,type:"binding",sourceObject:n,display:n.target+"/"+n.targetName+" - "+o+":",shortName:o,prefix:p})}else l.startsWith("?")&&(l=l.substring(1),p="?",a="property",l.startsWith("?")&&(l=l.substring(1),p="??")),s.push({service:this,name:l,itemType:a,designItem:e,type:"binding",sourceObject:n,display:n.target+"/"+n.targetName,prefix:p})}}return s}refactor(t,s,e){let i=t.sourceObject;t.shortName?i.bindableObjectNames=i.bindableObjectNames.map(n=>n==t.shortName+":"+t.prefix+s?t.shortName+":"+t.prefix+e:n):i.bindableObjectNames=i.bindableObjectNames.map(n=>n==t.prefix+s?t.prefix+e:n),t.designItem.serviceContainer.bindingService.setBinding(t.designItem,i)}};var oe=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 ce=class{getRefactorings(t){let s=[];for(let e of t)for(let i of e.attributes())if(i[0][0]=="@"){let n=i[1];if(n[0]=="{"){let l=JSON.parse(n);if("commands"in l)for(let a of l.commands){for(let p in a){let o=a[p];if(o!=null&&typeof o=="object"){let u=o;if(u.source==="signal")s.push({name:u.name,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[signal]",refactor:g=>u.name=g});else if(u.source==="property")s.push({name:u.name,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[property]",refactor:g=>u.name=g});else if(u.source==="complexString")for(let g of u.name.matchAll(/\{(.*?)\}/g)){let d=g[0],h=g[1];if(h[0]==="?"){let c="?";h=h.substring(1),h[0]==="?"&&(c="??",h=h.substring(1)),s.push({name:h,itemType:"property",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[complexString]->property",refactor:m=>u.name=u.name.replace(d,"{"+c+m+"}")})}else s.push({name:h,itemType:"signal",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:a.type+"/"+i[0].substring(1)+"/"+p+"[complexString]->signal",refactor:c=>u.name=u.name.replace(d,"{"+c+"}")})}}}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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.screen=p});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:l,refactor:p=>a.screen=p});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:l,refactor:p=>a.targetSignal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.signal=p});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:l,refactor:p=>a.resultSignal=p});break}}else"blocks"in l;if("parameters"in l)for(let a in l.parameters)typeof l.parameters[a]=="string"&&s.push({name:l.parameters[a],itemType:"parameter",target:b.event,targetName:i[0],service:this,designItem:e,type:"script",sourceObject:l,display:i[0].substring(1)+"/parameters/"+a,refactor:p=>l.parameters[a]=p})}}return s}refactor(t,s,e){t.refactor(e);let i=JSON.stringify(t.sourceObject);t.designItem.setAttribute(t.targetName,i)}};import{BasePropertyEditor as Xe}from"@node-projects/web-component-designer";var pe=class extends Xe{_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 n=new AbortController;i.objectDoubleclicked.on(()=>{n.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:n.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}};export{ae as BindableObjectDragDropService,D as BindingsEditor,E as BindingsEditorHistoric,ee as BindingsHelper,C as BlocklyScriptEditor,L as EventAssignment,O as ParameterEditor,oe as PropertyGridDragDropService,te as Script,ce as ScriptRefactorService,ie as ScriptSystem,pe as SignalPropertyEditor,I as SimpleScriptEditor,le as VisualizationBindingsRefactorService,re as VisualizationBindingsService,W as VisualizationPropertyGrid,B as bindingPrefixAttribute,R as bindingPrefixClass,w as bindingPrefixContent,V as bindingPrefixCss,A as bindingPrefixCssVar,Pe as bindingPrefixInsideCss,Me as bindingPrefixInsideCssVarName,S as bindingPrefixProperty,F as bindingPrefixVisible,Ft as bindingsInCssRegex,X as generateEventCodeFromBlockly,P as getNestedProperty,z as isLit,J as parseBindingString};
390
390
  //!varname => inverted
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "description": "web-component-designer addon for visualizations",
3
3
  "name": "@node-projects/web-component-designer-visualization-addons",
4
- "version": "0.1.137",
4
+ "version": "0.1.138",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "author": "jochen.kuehner@gmx.de",
@@ -11,12 +11,12 @@
11
11
  "build": "tsc",
12
12
  "link": "npm link",
13
13
  "prepublishOnly": "npm run build && npm run bundle",
14
- "bundle": "esbuild ./dist/index.js --format=esm --minify --external:@adobe/* --external:@blockly/* --external:blockly --external:long --external:wunderbaum --external:@node-projects/* --platform=neutral --bundle --outfile=./dist/index-min.js"
14
+ "bundle": "esbuild ./dist/index.js --format=esm --minify --external:@node-projects/css-parser --external:@blockly/* --external:blockly --external:long --external:wunderbaum --external:@node-projects/* --platform=neutral --bundle --outfile=./dist/index-min.js"
15
15
  },
16
16
  "dependencies": {
17
- "@adobe/css-tools": ">=4.4.0",
18
17
  "@blockly/zoom-to-fit": ">=6.0.9",
19
18
  "@node-projects/base-custom-webcomponent": ">=0.27.8",
19
+ "@node-projects/css-parser": "^5.2.0",
20
20
  "@node-projects/propertygrid.webcomponent": ">=1.2.3",
21
21
  "@node-projects/splitview.webcomponent": ">=1.0.1",
22
22
  "@node-projects/web-component-designer": ">=0.1.224",
@@ -25,7 +25,7 @@
25
25
  "blockly": ">=11.1.1",
26
26
  "long": ">=5.2.3"
27
27
  },
28
- "devDependencies": {
28
+ "devDependencies": {
29
29
  "esbuild": "^0.25.10"
30
30
  },
31
31
  "repository": {