From 4d873ee1412a5510e22268651521ffdc71440f23 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 2 Jan 2024 13:27:08 +0000 Subject: [PATCH] Add changes to dist and docs --- dist/floorplan-examples.js | 4 ++-- dist/floorplan.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/dist/floorplan-examples.js b/dist/floorplan-examples.js index 4a4342bd..b37220fd 100644 --- a/dist/floorplan-examples.js +++ b/dist/floorplan-examples.js @@ -51,7 +51,7 @@ const re=e=>t=>"function"==typeof t?((e,t)=>(customElements.define(e,t),t))(e,t) */ var oe;null===(oe=window.HTMLSlotElement)||void 0===oe||oe.prototype.assignedElements;class ce{constructor(){this.states={}}callWS(e){return console.log(e),Promise.resolve(null)}callService(e,t,i){const n={context:{id:"",parent_id:void 0,user_id:void 0}};return Promise.resolve(n)}clone(){const e=new ce;return e.callService=this.callService,e.states=JSON.parse(JSON.stringify(this.states)),e}}class le{}let he=/(-?(?:\d+\.?\d*|\d*\.?\d+)(?:e[-+]?\d+)?)\s*([\p{L}]*)/giu;function ue(e="",t="ms"){var i=null;return(e=(e+"").replace(/(\d)[,_](\d)/g,"$1$2")).replace(he,(function(e,t,n){(n=pe(n))&&(i=(i||0)+parseFloat(t,10)*n)})),i&&i/(pe(t)||1)}function pe(e){return ue[e]||ue[e.toLowerCase().replace(/s$/,"")]}ue.nanosecond=ue.ns=1e-6,ue["µs"]=ue["μs"]=ue.us=ue.microsecond=.001,ue.millisecond=ue.ms=ue[""]=1,ue.second=ue.sec=ue.s=1e3*ue.ms,ue.minute=ue.min=ue.m=60*ue.s,ue.hour=ue.hr=ue.h=60*ue.m,ue.day=ue.d=24*ue.h,ue.week=ue.wk=ue.w=7*ue.d,ue.month=ue.b=30.4375*ue.d,ue.year=ue.yr=ue.y=365.25*ue.d;const de=ue;class fe{static miredToRGB(e){return this.kelvinToRGB(1e6/e)}static kelvinToRGB(e){const t=e/100;let i,n,r;return t<=66?(i=255,n=t,n=99.4708025861*Math.log(n)-161.1195681661,t<=19?r=0:(r=t-10,r=138.5177312231*Math.log(r)-305.0447927307)):(i=t-60,i=329.698727446*Math.pow(i,-.1332047592),n=t-60,n=288.1221695283*Math.pow(n,-.0755148492),r=255),[Math.min(Math.max(Math.round(i),0),255),Math.min(Math.max(Math.round(n),0),255),Math.min(Math.max(Math.round(r),0),255)]}}var me,ge=i(1),ve=i.n(ge);class ye{static timeago(e){let t="second",i=0;const n=("string"==typeof e?new Date(e):e).getTime()-(new Date).getTime(),r=n/this.MILLISECONDS_IN_YEAR;if(Math.abs(r)>=1)t="year",i=r;else{const e=n/this.MILLISECONDS_IN_DAY;if(Math.abs(e)>=1)t="day",i=e;else{const e=n/this.MILLISECONDS_IN_HOUR;if(Math.abs(e)>=1)t="hour",i=e;else{const e=n/this.MILLISECONDS_IN_MINUTE;if(Math.abs(e)>=1)t="minute",i=e;else{t="second",i=n/this.MILLISECONDS_IN_SECOND}}}}return this.relativeTimeFormat.format(Math.round(i),t)}}ye.strftime=ve(),ye.MILLISECONDS_IN_SECOND=1e3,ye.MILLISECONDS_IN_MINUTE=6e4,ye.MILLISECONDS_IN_HOUR=36e5,ye.MILLISECONDS_IN_DAY=864e5,ye.MILLISECONDS_IN_YEAR=31536e6,ye.relativeTimeFormat=new Intl.RelativeTimeFormat(null!==(me=navigator.language)&&void 0!==me?me:"en",{numeric:"auto",style:"long"});var be=i(449),xe=i.n(be);function we(e){return(e=>{if("object"==typeof(t=e)&&null!==t&&"message"in t&&"string"==typeof t.message)return e;var t;try{return new Error(JSON.stringify(e))}catch(t){return new Error(String(e))}})(e).message}class Se{static isCode(e){return this.isCodeBlock(e)||this.isCodeLine(e)}static isCodeBlock(e){return e.trim().startsWith(">")}static isCodeLine(e){return e.includes("${")&&e.includes("}")}static evaluate(e,t){var i;this.expression=e.trim();const n=`${this.expression}_${null!==(i=t.entity_id)&&void 0!==i?i:""}`;this.parsedFunction=this.cache[n],void 0===this.parsedFunction&&(this.functionBody=this.expression,this.isCodeBlock(this.functionBody)?this.functionBody=this.functionBody.slice(1).trim():this.isCodeLine(this.functionBody)&&(this.functionBody.startsWith('"')&&this.functionBody.endsWith('"')&&(this.functionBody=this.functionBody.slice(1,this.functionBody.length-2)),this.functionBody=this.functionBody.replace(/\\"/g,'"'),this.functionBody=`\`${this.functionBody}\`;`,this.functionBody.includes("return")||(this.functionBody=`return ${this.functionBody}`)),this.parsedFunction=this.interpreter.parse(`exports.result = (() => { ${this.functionBody} })();`),this.cache[n]=this.parsedFunction,this.interpreter.import("util",this.util)),this.entityState=t,this.interpreter.import("entity",this.entityState);try{this.interpreter.run(this.parsedFunction)}catch(e){throw new EvalError(we(e))}return this.interpreter.exports.result}}Se.cache={},Se.interpreter=new(xe())({ecmaVer:2019,sandBox:!0}),Se.util={color:fe,date:ye};class _e{constructor(e,t){this.hassChanged=t,this.simulationProcessors=[],this.hass=new ce,this.hass.callService=this.callService.bind(this);for(const t of e.simulations){const e=new ke(t,this.hass,this.onEntityStatesChanged.bind(this));this.simulationProcessors.push(e)}}onEntityStatesChanged(e){for(const t of e)this.hass.states[t.entity_id]=t;this.hassChanged(this.hass.clone())}callService(e,t,i){switch(console.log("HassSimulator.callService()",e,t,i),e){case"homeassistant":case"light":case"fan":if("toggle"===t)this.homeAssistantToggle(i);break;case"media_player":switch(t){case"volume_up":this.homeAssistantVolumeUp(i);break;case"volume_down":this.homeAssistantVolumeDown(i)}}const n={context:{id:"",parent_id:void 0,user_id:void 0}};return Promise.resolve(n)}homeAssistantToggle(e){if(e.entity_id){const t=e.entity_id.split(".")[0],i=this.hass.states[e.entity_id];switch(t){case"switch":case"light":case"fan":case"binary_sensor":case"sensor":case"media_player":i.state="on"===i.state?"off":"on";for(const t of this.simulationProcessors)t.updateEntityState(e.entity_id,i)}}}homeAssistantVolumeUp(e){if(e.entity_id){const t=e.entity_id.split(".")[0],i=this.hass.states[e.entity_id];let n;if("media_player"===t){n=i.attributes.volume_level,i.attributes.volume_level=Math.min(1,n+.1);for(const t of this.simulationProcessors)t.updateEntityState(e.entity_id,i)}}}homeAssistantVolumeDown(e){if(e.entity_id){const t=e.entity_id.split(".")[0],i=this.hass.states[e.entity_id];let n;if("media_player"===t){n=i.attributes.volume_level,i.attributes.volume_level=Math.max(0,n-.1);for(const t of this.simulationProcessors)t.updateEntityState(e.entity_id,i)}}}}class ke{constructor(e,t,i){var n,r;this.simulation=e,this.hass=t,this.onEntityStatesChanged=i,this.currentIndex=0,this.entities=[],this.simulation.entities&&(this.entities=this.entities.concat(this.simulation.entities)),this.simulation.entity&&(this.entities=this.entities.concat(this.simulation.entity)),this.entities.length||console.error("Simulation must contain at least one entity",e),(null===(n=this.simulation.states)||void 0===n?void 0:n.length)||this.simulation.state||console.error("Simulation must contain at least one state",e),this.triggerState(null!==(r=this.simulation.state)&&void 0!==r?r:this.simulation.states[0])}triggerState(e){var t;if(this.simulation.enabled||void 0===this.simulation.enabled)for(const t of this.entities)this.updateEntityState(t,e);if(this.simulation.states){let i;if("string"==typeof this.simulation.states){const e=null!==(t=this.simulation.state)&&void 0!==t?t:{entity_id:this.simulation.entity};i=Se.evaluate(this.simulation.states,e),this.simulation.state=i}else{const t=(this.simulation.states.indexOf(e)+1)%this.simulation.states.length;i=this.simulation.states[t]}if(null==i?void 0:i.duration){const t=e,n="number"==typeof t.duration?1e3*t.duration:de(t.duration);setTimeout(this.triggerState.bind(this),n,i)}}}updateEntityState(e,t){var i,n,r;const s="string"==typeof e?e:e.entity_id,a=this.hass.states[s];let o;a?(o=Object.assign({},a),o.attributes=Object.assign({},a.attributes)):(o=new le,o.entity_id=s),"string"==typeof t?o.state="string"==typeof t?t:t.state:"object"==typeof t&&(o.state=t.state,t.attributes&&(o.attributes=Object.assign({},o.attributes,t.attributes))),o.attributes=null!==(i=o.attributes)&&void 0!==i?i:{},o.attributes.friendly_name=null!==(r=null===(n=o.attributes)||void 0===n?void 0:n.friendly_name)&&void 0!==r?r:s,o.last_changed=(new Date).toString(),o.last_updated=(new Date).toString(),this.onEntityStatesChanged([o])}} /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ -function Ee(e){return null==e}var Ae={isNothing:Ee,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:Ee(e)?[]:[e]},repeat:function(e,t){var i,n="";for(i=0;io&&(t=n-o+(s=" ... ").length),i-n>o&&(i=n+o-(a=" ...").length),{str:s+e.slice(t,i).replace(/\t/g,"→")+a,pos:n-t+s.length}}function Oe(e,t){return Ae.repeat(" ",t-e.length)+e}var Ne=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var i,n=/\r?\n|\r|\0/g,r=[0],s=[],a=-1;i=n.exec(e.buffer);)s.push(i.index),r.push(i.index+i[0].length),e.position<=i.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var o,c,l="",h=Math.min(e.line+t.linesAfter,s.length).toString().length,u=t.maxLength-(t.indent+h+3);for(o=1;o<=t.linesBefore&&!(a-o<0);o++)c=Pe(e.buffer,r[a-o],s[a-o],e.position-(r[a]-r[a-o]),u),l=Ae.repeat(" ",t.indent)+Oe((e.line-o+1).toString(),h)+" | "+c.str+"\n"+l;for(c=Pe(e.buffer,r[a],s[a],e.position,u),l+=Ae.repeat(" ",t.indent)+Oe((e.line+1).toString(),h)+" | "+c.str+"\n",l+=Ae.repeat("-",t.indent+h+3+c.pos)+"^\n",o=1;o<=t.linesAfter&&!(a+o>=s.length);o++)c=Pe(e.buffer,r[a+o],s[a+o],e.position-(r[a]-r[a+o]),u),l+=Ae.repeat(" ",t.indent)+Oe((e.line+o+1).toString(),h)+" | "+c.str+"\n";return l.replace(/\n$/,"")},Me=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],Le=["scalar","sequence","mapping"];var De=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===Me.indexOf(t))throw new Te('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(i){e[i].forEach((function(e){t[String(e)]=i}))})),t}(t.styleAliases||null),-1===Le.indexOf(this.kind))throw new Te('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function $e(e,t){var i=[];return e[t].forEach((function(e){var t=i.length;i.forEach((function(i,n){i.tag===e.tag&&i.kind===e.kind&&i.multi===e.multi&&(t=n)})),i[t]=e})),i}function Re(e){return this.extend(e)}Re.prototype.extend=function(e){var t=[],i=[];if(e instanceof De)i.push(e);else if(Array.isArray(e))i=i.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new Te("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(i=i.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof De))throw new Te("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new Te("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new Te("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),i.forEach((function(e){if(!(e instanceof De))throw new Te("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var n=Object.create(Re.prototype);return n.implicit=(this.implicit||[]).concat(t),n.explicit=(this.explicit||[]).concat(i),n.compiledImplicit=$e(n,"implicit"),n.compiledExplicit=$e(n,"explicit"),n.compiledTypeMap=function(){var e,t,i={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function n(e){e.multi?(i.multi[e.kind].push(e),i.multi.fallback.push(e)):i[e.kind][e.tag]=i.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),Je=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var Xe=/^[-+]?[0-9]+e/;var Ke=new De("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!Je.test(e)||"_"===e[e.length-1])},construct:function(e){var t,i;return i="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===i?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:i*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||Ae.isNegativeZero(e))},represent:function(e,t){var i;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(Ae.isNegativeZero(e))return"-0.0";return i=e.toString(10),Xe.test(i)?i.replace("e",".e"):i},defaultStyle:"lowercase"}),Qe=Ue.extend({implicit:[He,qe,Ge,Ke]}),Ze=Qe,et=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),tt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var it=new De("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==et.exec(e)||null!==tt.exec(e))},construct:function(e){var t,i,n,r,s,a,o,c,l=0,h=null;if(null===(t=et.exec(e))&&(t=tt.exec(e)),null===t)throw new Error("Date resolve error");if(i=+t[1],n=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(i,n,r));if(s=+t[4],a=+t[5],o=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(h=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(h=-h)),c=new Date(Date.UTC(i,n,r,s,a,o,l)),h&&c.setTime(c.getTime()-h),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var nt=new De("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var st=new De("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,i,n=0,r=e.length,s=rt;for(i=0;i64)){if(t<0)return!1;n+=6}return n%8==0},construct:function(e){var t,i,n=e.replace(/[\r\n=]/g,""),r=n.length,s=rt,a=0,o=[];for(t=0;t>16&255),o.push(a>>8&255),o.push(255&a)),a=a<<6|s.indexOf(n.charAt(t));return 0===(i=r%4*6)?(o.push(a>>16&255),o.push(a>>8&255),o.push(255&a)):18===i?(o.push(a>>10&255),o.push(a>>2&255)):12===i&&o.push(a>>4&255),new Uint8Array(o)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,i,n="",r=0,s=e.length,a=rt;for(t=0;t>18&63],n+=a[r>>12&63],n+=a[r>>6&63],n+=a[63&r]),r=(r<<8)+e[t];return 0===(i=s%3)?(n+=a[r>>18&63],n+=a[r>>12&63],n+=a[r>>6&63],n+=a[63&r]):2===i?(n+=a[r>>10&63],n+=a[r>>4&63],n+=a[r<<2&63],n+=a[64]):1===i&&(n+=a[r>>2&63],n+=a[r<<4&63],n+=a[64],n+=a[64]),n}}),at=Object.prototype.hasOwnProperty,ot=Object.prototype.toString;var ct=new De("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,i,n,r,s,a=[],o=e;for(t=0,i=o.length;t>10),56320+(e-65536&1023))}for(var Rt=new Array(256),jt=new Array(256),Bt=0;Bt<256;Bt++)Rt[Bt]=Dt(Bt)?1:0,jt[Bt]=Dt(Bt);function Vt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||dt,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Ft(e,t){var i={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return i.snippet=Ne(i),new Te(t,i)}function Ut(e,t){throw Ft(e,t)}function Ht(e,t){e.onWarning&&e.onWarning.call(null,Ft(e,t))}var qt={YAML:function(e,t,i){var n,r,s;null!==e.version&&Ut(e,"duplication of %YAML directive"),1!==i.length&&Ut(e,"YAML directive accepts exactly one argument"),null===(n=/^([0-9]+)\.([0-9]+)$/.exec(i[0]))&&Ut(e,"ill-formed argument of the YAML directive"),r=parseInt(n[1],10),s=parseInt(n[2],10),1!==r&&Ut(e,"unacceptable YAML version of the document"),e.version=i[0],e.checkLineBreaks=s<2,1!==s&&2!==s&&Ht(e,"unsupported YAML version of the document")},TAG:function(e,t,i){var n,r;2!==i.length&&Ut(e,"TAG directive accepts exactly two arguments"),n=i[0],r=i[1],Et.test(n)||Ut(e,"ill-formed tag handle (first argument) of the TAG directive"),ft.call(e.tagMap,n)&&Ut(e,'there is a previously declared suffix for "'+n+'" tag handle'),At.test(r)||Ut(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){Ut(e,"tag prefix is malformed: "+r)}e.tagMap[n]=r}};function zt(e,t,i,n){var r,s,a,o;if(t1&&(e.result+=Ae.repeat("\n",t-1))}function Qt(e,t){var i,n,r=e.tag,s=e.anchor,a=[],o=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),n=e.input.charCodeAt(e.position);0!==n&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Ut(e,"tab characters must not be used in indentation")),45===n)&&Pt(e.input.charCodeAt(e.position+1));)if(o=!0,e.position++,Jt(e,!0,-1)&&e.lineIndent<=t)a.push(null),n=e.input.charCodeAt(e.position);else if(i=e.line,ti(e,t,vt,!1,!0),a.push(e.result),Jt(e,!0,-1),n=e.input.charCodeAt(e.position),(e.line===i||e.lineIndent>t)&&0!==n)Ut(e,"bad indentation of a sequence entry");else if(e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt)&&(v&&(a=e.line,o=e.lineStart,c=e.position),ti(e,t,yt,!0,r)&&(v?m=e.result:g=e.result),v||(Yt(e,p,d,f,m,g,a,o,c),f=m=g=null),Jt(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===s||e.lineIndent>t)&&0!==l)Ut(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===r?Ut(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?Ut(e,"repeat of an indentation width identifier"):(l=t+r-1,c=!0)}if(Tt(s)){do{s=e.input.charCodeAt(++e.position)}while(Tt(s));if(35===s)do{s=e.input.charCodeAt(++e.position)}while(!It(s)&&0!==s)}for(;0!==s;){for(Gt(e),e.lineIndent=0,s=e.input.charCodeAt(e.position);(!c||e.lineIndentl&&(l=e.lineIndent),It(s))h++;else{if(e.lineIndent0){for(r=a,s=0;r>0;r--)(a=Nt(o=e.input.charCodeAt(++e.position)))>=0?s=(s<<4)+a:Ut(e,"expected hexadecimal character");e.result+=$t(s),e.position++}else Ut(e,"unknown escape sequence");i=n=e.position}else It(o)?(zt(e,i,n,!0),Kt(e,Jt(e,!1,t)),i=n=e.position):e.position===e.lineStart&&Xt(e)?Ut(e,"unexpected end of the document within a double quoted scalar"):(e.position++,n=e.position)}Ut(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?g=!0:!function(e){var t,i,n;if(42!==(n=e.input.charCodeAt(e.position)))return!1;for(n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!Pt(n)&&!Ot(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&Ut(e,"name of an alias node must contain at least one character"),i=e.input.slice(t,e.position),ft.call(e.anchorMap,i)||Ut(e,'unidentified alias "'+i+'"'),e.result=e.anchorMap[i],Jt(e,!0,-1),!0}(e)?function(e,t,i){var n,r,s,a,o,c,l,h,u=e.kind,p=e.result;if(Pt(h=e.input.charCodeAt(e.position))||Ot(h)||35===h||38===h||42===h||33===h||124===h||62===h||39===h||34===h||37===h||64===h||96===h)return!1;if((63===h||45===h)&&(Pt(n=e.input.charCodeAt(e.position+1))||i&&Ot(n)))return!1;for(e.kind="scalar",e.result="",r=s=e.position,a=!1;0!==h;){if(58===h){if(Pt(n=e.input.charCodeAt(e.position+1))||i&&Ot(n))break}else if(35===h){if(Pt(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&Xt(e)||i&&Ot(h))break;if(It(h)){if(o=e.line,c=e.lineStart,l=e.lineIndent,Jt(e,!1,-1),e.lineIndent>=t){a=!0,h=e.input.charCodeAt(e.position);continue}e.position=s,e.line=o,e.lineStart=c,e.lineIndent=l;break}}a&&(zt(e,r,s,!1),Kt(e,e.line-o),r=s=e.position,a=!1),Tt(h)||(s=e.position+1),h=e.input.charCodeAt(++e.position)}return zt(e,r,s,!1),!!e.result||(e.kind=u,e.result=p,!1)}(e,p,mt===i)&&(g=!0,null===e.tag&&(e.tag="?")):(g=!0,null===e.tag&&null===e.anchor||Ut(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===f&&(g=o&&Qt(e,d))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Ut(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),c=0,l=e.implicitTypes.length;c"),null!==e.result&&u.kind!==e.kind&&Ut(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+u.kind+'", not "'+e.kind+'"'),u.resolve(e.result,e.tag)?(e.result=u.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Ut(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||g}function ii(e){var t,i,n,r,s=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(Jt(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Pt(r);)r=e.input.charCodeAt(++e.position);for(n=[],(i=e.input.slice(t,e.position)).length<1&&Ut(e,"directive name must not be less than one character in length");0!==r;){for(;Tt(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!It(r));break}if(It(r))break;for(t=e.position;0!==r&&!Pt(r);)r=e.input.charCodeAt(++e.position);n.push(e.input.slice(t,e.position))}0!==r&&Gt(e),ft.call(qt,i)?qt[i](e,i,n):Ht(e,'unknown document directive "'+i+'"')}Jt(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,Jt(e,!0,-1)):a&&Ut(e,"directives end mark is expected"),ti(e,e.lineIndent-1,yt,!1,!0),Jt(e,!0,-1),e.checkLineBreaks&&_t.test(e.input.slice(s,e.position))&&Ht(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Xt(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,Jt(e,!0,-1)):e.position=55296&&n<=56319&&t+1=56320&&i<=57343?1024*(n-55296)+i-56320+65536:n}function Wi(e){return/^\n* /.test(e)}var Yi=1,Gi=2,Ji=3,Xi=4,Ki=5;function Qi(e,t,i,n,r,s,a,o){var c,l=0,h=null,u=!1,p=!1,d=-1!==n,f=-1,m=function(e){return Ui(e)&&e!==oi&&!Fi(e)&&e!==xi&&e!==ki&&e!==wi&&e!==bi&&e!==Ai&&e!==Ci&&e!==Ti&&e!==Oi&&e!==fi&&e!==gi&&e!==yi&&e!==pi&&e!==Pi&&e!==Si&&e!==_i&&e!==vi&&e!==di&&e!==mi&&e!==Ei&&e!==Ii}(zi(e,0))&&function(e){return!Fi(e)&&e!==wi}(zi(e,e.length-1));if(t||a)for(c=0;c=65536?c+=2:c++){if(!Ui(l=zi(e,c)))return Ki;m=m&&qi(l,h,o),h=l}else{for(c=0;c=65536?c+=2:c++){if((l=zi(e,c))===li)u=!0,d&&(p=p||c-f-1>n&&" "!==e[f+1],f=c);else if(!Ui(l))return Ki;m=m&&qi(l,h,o),h=l}p=p||d&&c-f-1>n&&" "!==e[f+1]}return u||p?i>9&&Wi(e)?Ki:a?s===Ri?Ki:Gi:p?Xi:Ji:!m||a||r(e)?s===Ri?Ki:Gi:Yi}function Zi(e,t,i,n,r){e.dump=function(){if(0===t.length)return e.quotingType===Ri?'""':"''";if(!e.noCompatMode&&(-1!==Mi.indexOf(t)||Li.test(t)))return e.quotingType===Ri?'"'+t+'"':"'"+t+"'";var s=e.indent*Math.max(1,i),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-s),o=n||e.flowLevel>-1&&i>=e.flowLevel;switch(Qi(t,o,e.indent,a,(function(t){return function(e,t){var i,n;for(i=0,n=e.implicitTypes.length;i"+en(t,e.indent)+tn(Bi(function(e,t){var i,n,r=/(\n+)([^\n]*)/g,s=(o=e.indexOf("\n"),o=-1!==o?o:e.length,r.lastIndex=o,nn(e.slice(0,o),t)),a="\n"===e[0]||" "===e[0];var o;for(;n=r.exec(e);){var c=n[1],l=n[2];i=" "===l[0],s+=c+(a||i||""===l?"":"\n")+nn(l,t),a=i}return s}(t,a),s));case Ki:return'"'+function(e){for(var t,i="",n=0,r=0;r=65536?r+=2:r++)n=zi(e,r),!(t=Ni[n])&&Ui(n)?(i+=e[r],n>=65536&&(i+=e[r+1])):i+=t||Di(n);return i}(t)+'"';default:throw new Te("impossible error: invalid scalar style")}}()}function en(e,t){var i=Wi(e)?String(t):"",n="\n"===e[e.length-1];return i+(n&&("\n"===e[e.length-2]||"\n"===e)?"+":n?"":"-")+"\n"}function tn(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function nn(e,t){if(""===e||" "===e[0])return e;for(var i,n,r=/ [^ ]/g,s=0,a=0,o=0,c="";i=r.exec(e);)(o=i.index)-s>t&&(n=a>s?a:o,c+="\n"+e.slice(s,n),s=n+1),a=o;return c+="\n",e.length-s>t&&a>s?c+=e.slice(s,a)+"\n"+e.slice(a+1):c+=e.slice(s),c.slice(1)}function rn(e,t,i,n){var r,s,a,o="",c=e.tag;for(r=0,s=i.length;r tag resolver accepts not "'+c+'" style');n=o.represent[c](t,c)}e.dump=n}return!0}return!1}function an(e,t,i,n,r,s,a){e.tag=null,e.dump=i,sn(e,i,!1)||sn(e,i,!0);var o,c=si.call(e.dump),l=n;n&&(n=e.flowLevel<0||e.flowLevel>t);var h,u,p="[object Object]"===c||"[object Array]"===c;if(p&&(u=-1!==(h=e.duplicates.indexOf(i))),(null!==e.tag&&"?"!==e.tag||u||2!==e.indent&&t>0)&&(r=!1),u&&e.usedDuplicates[h])e.dump="*ref_"+h;else{if(p&&u&&!e.usedDuplicates[h]&&(e.usedDuplicates[h]=!0),"[object Object]"===c)n&&0!==Object.keys(e.dump).length?(!function(e,t,i,n){var r,s,a,o,c,l,h="",u=e.tag,p=Object.keys(i);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new Te("sortKeys must be a boolean or a function");for(r=0,s=p.length;r1024)&&(e.dump&&li===e.dump.charCodeAt(0)?l+="?":l+="? "),l+=e.dump,c&&(l+=Vi(e,t)),an(e,t+1,o,!0,c)&&(e.dump&&li===e.dump.charCodeAt(0)?l+=":":l+=": ",h+=l+=e.dump));e.tag=u,e.dump=h||"{}"}(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,i){var n,r,s,a,o,c="",l=e.tag,h=Object.keys(i);for(n=0,r=h.length;n1024&&(o+="? "),o+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),an(e,t,a,!1,!1)&&(c+=o+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),u&&(e.dump="&ref_"+h+" "+e.dump));else if("[object Array]"===c)n&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?rn(e,t-1,e.dump,r):rn(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,i){var n,r,s,a="",o=e.tag;for(n=0,r=i.length;n",e.dump=o+" "+e.dump)}return!0}function on(e,t){var i,n,r=[],s=[];for(cn(e,r,s),i=0,n=s.length;ie.trim())).filter((e=>e.length));for(let t=0;te.trim()));e.style.setProperty(n[0],n[1])}}static setText(e,t,i){e instanceof SVGTextElement||(e=e.querySelector("text")||e);const n=t.replace(/\\n/g,"\n").split("\n"),r=n.length>1,s=e.querySelector("tspan");if(r){const t=null==s?void 0:s.getAttribute("x"),r=null==s?void 0:s.getAttribute("y");t&&!e.getAttribute("x")&&e.setAttribute("x",t),r&&!e.getAttribute("y")&&e.setAttribute("y",r);const a=e.querySelector("tspan")||!1;e.textContent="",e.dataset.ha_floorplan_notice="The text_set function split your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on the basis of the first tspan or text-element.";const o=e.getAttribute("x")||"0",c=i||"1em";n.forEach(((t,i)=>{const n=document.createElementNS("http://www.w3.org/2000/svg","tspan");if(n.textContent=t,n.setAttribute("x",o),n.setAttribute("dy",i>=1?c:"0"),a){const e=a.getAttribute("style");e&&n.setAttribute("style",e)}e.appendChild(n)}))}else{(s||e).textContent=t}}static waitForChildNodes(e,t,i){return new Promise(((n,r)=>{const s=setTimeout((()=>r("Timeout waiting for child element(s) to load")),i);new MutationObserver((e=>{for(const t of e)if("childList"===t.type&&t.addedNodes.length)return clearTimeout(s),n()})).observe(e,{childList:!0,subtree:!0}),t()}))}static formatDate(e){return e?"string"==typeof e?new Date(e).toLocaleString():e.toLocaleString():""}static parseYaml(e){return hn.load(e)}static fetchText(e,t,i,n){return un(this,void 0,void 0,(function*(){i&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${i}/`)),e=n?e:pn.cacheBuster(e);const r=new Request(e,{cache:n?"default":"no-store",mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){return yield e.text()}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static fetchImage(e,t,i,n){return un(this,void 0,void 0,(function*(){t&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${i}/`)),e=n?e:pn.cacheBuster(e);const r=new Request(e,{cache:n?"default":"no-store",headers:new Headers({"Content-Type":"text/plain; charset=x-user-defined"}),mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){const t=yield e.arrayBuffer();return`data:image/jpeg;base64,${pn.arrayBufferToBase64(t)}`}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static singleToArray(e){return null==e?[]:Array.isArray(e)?e:[e]}static getArray(e){if(null==e)return[];if(Array.isArray(e))return e;{const t=e;return Object.values(t)}}static getSet(e){if(Array.isArray(e))return new Set(e);{const t=e;return new Set(Object.values(t))}}static arrayBufferToBase64(e){let t="";[].slice.call(new Uint8Array(e)).forEach((e=>t+=String.fromCharCode(e)));let i=window.btoa(t);for(;i.length%4>0;)i+="=";return i}static cacheBuster(e){return`${e}${e.includes("?")?"&":"?"}_=${(new Date).getTime()}`}static equal(e,t){if(e===t)return!0;const i=Array.isArray(e),n=Array.isArray(t);let r=0;if(i&&n){if(e.length!=t.length)return!1;for(r=0;rMath.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage[e]=`${t()}${t()}_${t()}${t()}`}return localStorage[e]}}class dn{static closestElement(e,t){return function t(i){if(!i||i===document||i===window)return null;i.assignedSlot&&(i=i.assignedSlot);const n=i.closest(e);return n||t(i.getRootNode().host)}(t)}}const fn=(e,t,i,n)=>{n=n||{},i=null==i?{}:i;const r=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return r.detail=i,e.dispatchEvent(r),r},mn=(e,t,i=!1)=>{i?history.replaceState(null,"",t):history.pushState(null,"",t),fn(window,"location-changed",{replace:i})};class gn{constructor(e,t,i,n){this.entityId=e,this.svgElement=t,this.originalSvgElement=i,this.originalBBox=n}}class vn{constructor(e){this.rule=e,this.svgElementInfos={}}}class yn{constructor(e,t,i,n,r,s){this.instance=e,this.entityId=t,this.elementId=i,this.svgElementInfo=n,this.ruleInfo=r,this.actions=s}}const bn={},xn={};xn.click=xn.mousedown=xn.mouseup=xn.mousemove="MouseEvents";let wn=1;function Sn(e){return e._dtId||(e._dtId=wn++)}function _n(e){const t=e.indexOf(".");return t>0?{e:e.substring(0,e.indexOf(".")),ns:e.substring(t+1,e.length)}:{e}}function kn(e,t,i,n){const r=_n(i).e;if(!e._dtId)return!1;const s=bn[Sn(e)],a=function(e,t,i,n){return i=_n(i),(bn[Sn(e)]||[]).filter((e=>e&&(!i.e||e.e===i.e)&&(!i.ns||e.ns===i.ns)&&(!n||e.callback===n)&&(!t||e.selector===t)))}(e,t,i,n);a.forEach((t=>{e.removeEventListener?e.removeEventListener(r,t.delegator||t.callback):e.detachEvent&&e.detachEvent("on"+r,t.delegator||t.callback),s.splice(s.indexOf(t),1)}))}function En(e,t,i,n,r,s){const a=_n(i).e,o=_n(i).ns;e.addEventListener?e.addEventListener(a,r||n,s):e.attachEvent&&e.attachEvent("on"+a,r||n);const c=Sn(e);(bn[c]||(bn[c]=[])).push({delegator:r,callback:n,e:a,ns:o,selector:t})}const An={on(e,t,i,n=null){En(e,null,t,i,null,n)},off(e,t,i=null){kn(e,null,t,i)},once(e,t,i){const n=e=>(An.off(e.currentTarget,e.type,n),i(e));this.on(e,t,n)},delegate(e,t,i,n,r=null){En(e,t,i,n,(function(i){const r=e.querySelectorAll(t);let s=!1;for(let e=0;e{i=!1,t=setTimeout((()=>{i=!0,e.dispatchEvent(new Event("longClick"))}),400)},r=n=>{clearTimeout(t),i||e.dispatchEvent(new Event("short"+n.type[0].toUpperCase()+n.type.slice(1)))},s=e=>{i&&(e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation())};In.on(e,"mousedown",n.bind(this)),In.on(e,"tapstart",n.bind(this)),In.on(e,"touchstart",n.bind(this),{passive:!0}),In.on(e,"click",r.bind(this)),In.on(e,"mouseup",r.bind(this)),In.on(e,"tapend",r.bind(this)),In.on(e,"touchend",r.bind(this)),In.on(e,"tap",s.bind(this)),In.on(e,"touch",s.bind(this)),In.on(e,"mouseup",s.bind(this)),In.on(e,"tapend",s.bind(this)),In.on(e,"touchend",s.bind(this)),In.on(e,"click",(e=>{e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation()}).bind(this))}}const Pn=Cn,On=new Set;class Nn{static observe(e){if(On.has(e))return;On.add(e);let t,i=0;Pn.on(e,"click",(()=>{i++,t=setTimeout((()=>{1===i&&(i=0,e.dispatchEvent(new Event("singleClick")))}),400),2===i&&(clearTimeout(t),i=0,e.dispatchEvent(new Event("doubleClick")))}).bind(this))}}class Mn{static isCode(e){return this.isCodeBlock(e)||this.isCodeLine(e)}static isCodeBlock(e){return e.trim().startsWith(">")}static isCodeLine(e){return e.includes("${")&&e.includes("}")}static evaluate(e,t,i,n,r,s,a){this.expression=e.trim();const o=`${this.expression}_${null!=r?r:""}`;this.parsedFunction=this.cache[o],void 0===this.parsedFunction&&(this.functionBody=this.expression,this.isCodeBlock(this.functionBody)?this.functionBody=this.functionBody.slice(1).trim():this.isCodeLine(this.functionBody)&&(this.functionBody.startsWith('"')&&this.functionBody.endsWith('"')&&(this.functionBody=this.functionBody.slice(1,this.functionBody.length-2)),this.functionBody=this.functionBody.replace(/\\"/g,'"'),this.functionBody=`\`${this.functionBody}\`;`,this.functionBody.includes("return")||(this.functionBody=`return ${this.functionBody}`)),this.parsedFunction=this.interpreter.parse(`exports.result = (() => { ${this.functionBody} })();`),this.cache[o]=this.parsedFunction,this.interpreter.import("config",i),this.interpreter.import("util",this.util)),this.entityState=n?t.states[n]:void 0,this.interpreter.import("functions",a),this.interpreter.import("entity",this.entityState),this.interpreter.import("entities",t.states),this.interpreter.import("states",t.states),this.interpreter.import("hass",t),this.interpreter.import("element",r),this.interpreter.import("elements",s);try{this.interpreter.run(this.parsedFunction)}catch(e){throw new EvalError(we(e))}return this.interpreter.exports.result}}Mn.cache={},Mn.interpreter=new(xe())({ecmaVer:2019,sandBox:!0}),Mn.util={color:fe,date:ye};class Ln{constructor(e,t,i){this.element=e,this.logLevel=t,this.consoleLogLevel=i,this.logLevelGroups={error:["error"],warn:["error","warning","warn"],warning:["error","warning","warn"],info:["error","warning","warn","info"],debug:["error","warning","warn","info","debug"]}}log(e,t,i=!1){var n;const r=`${pn.formatDate(new Date)} ${e.toUpperCase()} ${t}`,s=this.logLevel&&this.logLevelGroups[this.logLevel.toLowerCase()],a=(null==s?void 0:s.length)&&s.includes(e.toLowerCase());if((i||a)&&this.element){const t=document.createElement("li");pn.addClass(t,e),t.textContent=r,null===(n=this.element.querySelector("ul"))||void 0===n||n.prepend(t),this.element.style.display="block"}this.consoleLog(e,t,i)}consoleLog(e,t,i=!1){const n=`${pn.formatDate(new Date)} ${e.toUpperCase()} ${t}`,r=this.consoleLogLevel&&this.logLevelGroups[this.consoleLogLevel.toLowerCase()],s=(null==r?void 0:r.length)&&r.includes(e.toLowerCase());if(i||s)switch(e){case"error":console.error(n);break;case"warn":case"warning":console.warn(n);break;case"info":console.info(n);break;default:console.log(n)}}}var Dn=function(e,t,i,n){var r,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,i,a):r(t,i))||a);return s>3&&a&&Object.defineProperty(t,i,a),a},$n=function(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};const Rn=Cn;console.info("%cFloorplan for Home Assistant (ha-floorplan)%c\nVersion 1.0.41","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: rgb(71, 170, 238)");let jn=class extends ie{constructor(){super(),this.pageInfos={},this.entityInfos={},this.elementInfos={},this.cssRules=[],this.functions={},this.variables={},this.svgElements={},this.isRulesLoaded=!1,window.onerror=this.handleWindowError.bind(this)}render(){return R` +function Ee(e){return null==e}var Ae={isNothing:Ee,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:Ee(e)?[]:[e]},repeat:function(e,t){var i,n="";for(i=0;io&&(t=n-o+(s=" ... ").length),i-n>o&&(i=n+o-(a=" ...").length),{str:s+e.slice(t,i).replace(/\t/g,"→")+a,pos:n-t+s.length}}function Oe(e,t){return Ae.repeat(" ",t-e.length)+e}var Ne=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var i,n=/\r?\n|\r|\0/g,r=[0],s=[],a=-1;i=n.exec(e.buffer);)s.push(i.index),r.push(i.index+i[0].length),e.position<=i.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var o,c,l="",h=Math.min(e.line+t.linesAfter,s.length).toString().length,u=t.maxLength-(t.indent+h+3);for(o=1;o<=t.linesBefore&&!(a-o<0);o++)c=Pe(e.buffer,r[a-o],s[a-o],e.position-(r[a]-r[a-o]),u),l=Ae.repeat(" ",t.indent)+Oe((e.line-o+1).toString(),h)+" | "+c.str+"\n"+l;for(c=Pe(e.buffer,r[a],s[a],e.position,u),l+=Ae.repeat(" ",t.indent)+Oe((e.line+1).toString(),h)+" | "+c.str+"\n",l+=Ae.repeat("-",t.indent+h+3+c.pos)+"^\n",o=1;o<=t.linesAfter&&!(a+o>=s.length);o++)c=Pe(e.buffer,r[a+o],s[a+o],e.position-(r[a]-r[a+o]),u),l+=Ae.repeat(" ",t.indent)+Oe((e.line+o+1).toString(),h)+" | "+c.str+"\n";return l.replace(/\n$/,"")},Me=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],Le=["scalar","sequence","mapping"];var De=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===Me.indexOf(t))throw new Te('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(i){e[i].forEach((function(e){t[String(e)]=i}))})),t}(t.styleAliases||null),-1===Le.indexOf(this.kind))throw new Te('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function $e(e,t){var i=[];return e[t].forEach((function(e){var t=i.length;i.forEach((function(i,n){i.tag===e.tag&&i.kind===e.kind&&i.multi===e.multi&&(t=n)})),i[t]=e})),i}function Re(e){return this.extend(e)}Re.prototype.extend=function(e){var t=[],i=[];if(e instanceof De)i.push(e);else if(Array.isArray(e))i=i.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new Te("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(i=i.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof De))throw new Te("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new Te("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new Te("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),i.forEach((function(e){if(!(e instanceof De))throw new Te("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var n=Object.create(Re.prototype);return n.implicit=(this.implicit||[]).concat(t),n.explicit=(this.explicit||[]).concat(i),n.compiledImplicit=$e(n,"implicit"),n.compiledExplicit=$e(n,"explicit"),n.compiledTypeMap=function(){var e,t,i={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function n(e){e.multi?(i.multi[e.kind].push(e),i.multi.fallback.push(e)):i[e.kind][e.tag]=i.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),Je=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var Xe=/^[-+]?[0-9]+e/;var Ke=new De("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!Je.test(e)||"_"===e[e.length-1])},construct:function(e){var t,i;return i="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===i?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:i*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||Ae.isNegativeZero(e))},represent:function(e,t){var i;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if(Ae.isNegativeZero(e))return"-0.0";return i=e.toString(10),Xe.test(i)?i.replace("e",".e"):i},defaultStyle:"lowercase"}),Qe=Ue.extend({implicit:[He,qe,Ge,Ke]}),Ze=Qe,et=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),tt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var it=new De("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==et.exec(e)||null!==tt.exec(e))},construct:function(e){var t,i,n,r,s,a,o,c,l=0,h=null;if(null===(t=et.exec(e))&&(t=tt.exec(e)),null===t)throw new Error("Date resolve error");if(i=+t[1],n=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(i,n,r));if(s=+t[4],a=+t[5],o=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(h=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(h=-h)),c=new Date(Date.UTC(i,n,r,s,a,o,l)),h&&c.setTime(c.getTime()-h),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var nt=new De("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),rt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var st=new De("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,i,n=0,r=e.length,s=rt;for(i=0;i64)){if(t<0)return!1;n+=6}return n%8==0},construct:function(e){var t,i,n=e.replace(/[\r\n=]/g,""),r=n.length,s=rt,a=0,o=[];for(t=0;t>16&255),o.push(a>>8&255),o.push(255&a)),a=a<<6|s.indexOf(n.charAt(t));return 0===(i=r%4*6)?(o.push(a>>16&255),o.push(a>>8&255),o.push(255&a)):18===i?(o.push(a>>10&255),o.push(a>>2&255)):12===i&&o.push(a>>4&255),new Uint8Array(o)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,i,n="",r=0,s=e.length,a=rt;for(t=0;t>18&63],n+=a[r>>12&63],n+=a[r>>6&63],n+=a[63&r]),r=(r<<8)+e[t];return 0===(i=s%3)?(n+=a[r>>18&63],n+=a[r>>12&63],n+=a[r>>6&63],n+=a[63&r]):2===i?(n+=a[r>>10&63],n+=a[r>>4&63],n+=a[r<<2&63],n+=a[64]):1===i&&(n+=a[r>>2&63],n+=a[r<<4&63],n+=a[64],n+=a[64]),n}}),at=Object.prototype.hasOwnProperty,ot=Object.prototype.toString;var ct=new De("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,i,n,r,s,a=[],o=e;for(t=0,i=o.length;t>10),56320+(e-65536&1023))}for(var Rt=new Array(256),jt=new Array(256),Bt=0;Bt<256;Bt++)Rt[Bt]=Dt(Bt)?1:0,jt[Bt]=Dt(Bt);function Vt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||dt,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Ft(e,t){var i={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return i.snippet=Ne(i),new Te(t,i)}function Ut(e,t){throw Ft(e,t)}function Ht(e,t){e.onWarning&&e.onWarning.call(null,Ft(e,t))}var qt={YAML:function(e,t,i){var n,r,s;null!==e.version&&Ut(e,"duplication of %YAML directive"),1!==i.length&&Ut(e,"YAML directive accepts exactly one argument"),null===(n=/^([0-9]+)\.([0-9]+)$/.exec(i[0]))&&Ut(e,"ill-formed argument of the YAML directive"),r=parseInt(n[1],10),s=parseInt(n[2],10),1!==r&&Ut(e,"unacceptable YAML version of the document"),e.version=i[0],e.checkLineBreaks=s<2,1!==s&&2!==s&&Ht(e,"unsupported YAML version of the document")},TAG:function(e,t,i){var n,r;2!==i.length&&Ut(e,"TAG directive accepts exactly two arguments"),n=i[0],r=i[1],Et.test(n)||Ut(e,"ill-formed tag handle (first argument) of the TAG directive"),ft.call(e.tagMap,n)&&Ut(e,'there is a previously declared suffix for "'+n+'" tag handle'),At.test(r)||Ut(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){Ut(e,"tag prefix is malformed: "+r)}e.tagMap[n]=r}};function zt(e,t,i,n){var r,s,a,o;if(t1&&(e.result+=Ae.repeat("\n",t-1))}function Qt(e,t){var i,n,r=e.tag,s=e.anchor,a=[],o=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),n=e.input.charCodeAt(e.position);0!==n&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Ut(e,"tab characters must not be used in indentation")),45===n)&&Pt(e.input.charCodeAt(e.position+1));)if(o=!0,e.position++,Jt(e,!0,-1)&&e.lineIndent<=t)a.push(null),n=e.input.charCodeAt(e.position);else if(i=e.line,ti(e,t,vt,!1,!0),a.push(e.result),Jt(e,!0,-1),n=e.input.charCodeAt(e.position),(e.line===i||e.lineIndent>t)&&0!==n)Ut(e,"bad indentation of a sequence entry");else if(e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt)&&(v&&(a=e.line,o=e.lineStart,c=e.position),ti(e,t,yt,!0,r)&&(v?m=e.result:g=e.result),v||(Yt(e,p,d,f,m,g,a,o,c),f=m=g=null),Jt(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===s||e.lineIndent>t)&&0!==l)Ut(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===r?Ut(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?Ut(e,"repeat of an indentation width identifier"):(l=t+r-1,c=!0)}if(Tt(s)){do{s=e.input.charCodeAt(++e.position)}while(Tt(s));if(35===s)do{s=e.input.charCodeAt(++e.position)}while(!It(s)&&0!==s)}for(;0!==s;){for(Gt(e),e.lineIndent=0,s=e.input.charCodeAt(e.position);(!c||e.lineIndentl&&(l=e.lineIndent),It(s))h++;else{if(e.lineIndent0){for(r=a,s=0;r>0;r--)(a=Nt(o=e.input.charCodeAt(++e.position)))>=0?s=(s<<4)+a:Ut(e,"expected hexadecimal character");e.result+=$t(s),e.position++}else Ut(e,"unknown escape sequence");i=n=e.position}else It(o)?(zt(e,i,n,!0),Kt(e,Jt(e,!1,t)),i=n=e.position):e.position===e.lineStart&&Xt(e)?Ut(e,"unexpected end of the document within a double quoted scalar"):(e.position++,n=e.position)}Ut(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?g=!0:!function(e){var t,i,n;if(42!==(n=e.input.charCodeAt(e.position)))return!1;for(n=e.input.charCodeAt(++e.position),t=e.position;0!==n&&!Pt(n)&&!Ot(n);)n=e.input.charCodeAt(++e.position);return e.position===t&&Ut(e,"name of an alias node must contain at least one character"),i=e.input.slice(t,e.position),ft.call(e.anchorMap,i)||Ut(e,'unidentified alias "'+i+'"'),e.result=e.anchorMap[i],Jt(e,!0,-1),!0}(e)?function(e,t,i){var n,r,s,a,o,c,l,h,u=e.kind,p=e.result;if(Pt(h=e.input.charCodeAt(e.position))||Ot(h)||35===h||38===h||42===h||33===h||124===h||62===h||39===h||34===h||37===h||64===h||96===h)return!1;if((63===h||45===h)&&(Pt(n=e.input.charCodeAt(e.position+1))||i&&Ot(n)))return!1;for(e.kind="scalar",e.result="",r=s=e.position,a=!1;0!==h;){if(58===h){if(Pt(n=e.input.charCodeAt(e.position+1))||i&&Ot(n))break}else if(35===h){if(Pt(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&Xt(e)||i&&Ot(h))break;if(It(h)){if(o=e.line,c=e.lineStart,l=e.lineIndent,Jt(e,!1,-1),e.lineIndent>=t){a=!0,h=e.input.charCodeAt(e.position);continue}e.position=s,e.line=o,e.lineStart=c,e.lineIndent=l;break}}a&&(zt(e,r,s,!1),Kt(e,e.line-o),r=s=e.position,a=!1),Tt(h)||(s=e.position+1),h=e.input.charCodeAt(++e.position)}return zt(e,r,s,!1),!!e.result||(e.kind=u,e.result=p,!1)}(e,p,mt===i)&&(g=!0,null===e.tag&&(e.tag="?")):(g=!0,null===e.tag&&null===e.anchor||Ut(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===f&&(g=o&&Qt(e,d))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Ut(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),c=0,l=e.implicitTypes.length;c"),null!==e.result&&u.kind!==e.kind&&Ut(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+u.kind+'", not "'+e.kind+'"'),u.resolve(e.result,e.tag)?(e.result=u.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Ut(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||g}function ii(e){var t,i,n,r,s=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(Jt(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Pt(r);)r=e.input.charCodeAt(++e.position);for(n=[],(i=e.input.slice(t,e.position)).length<1&&Ut(e,"directive name must not be less than one character in length");0!==r;){for(;Tt(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!It(r));break}if(It(r))break;for(t=e.position;0!==r&&!Pt(r);)r=e.input.charCodeAt(++e.position);n.push(e.input.slice(t,e.position))}0!==r&&Gt(e),ft.call(qt,i)?qt[i](e,i,n):Ht(e,'unknown document directive "'+i+'"')}Jt(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,Jt(e,!0,-1)):a&&Ut(e,"directives end mark is expected"),ti(e,e.lineIndent-1,yt,!1,!0),Jt(e,!0,-1),e.checkLineBreaks&&_t.test(e.input.slice(s,e.position))&&Ht(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&Xt(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,Jt(e,!0,-1)):e.position=55296&&n<=56319&&t+1=56320&&i<=57343?1024*(n-55296)+i-56320+65536:n}function Wi(e){return/^\n* /.test(e)}var Yi=1,Gi=2,Ji=3,Xi=4,Ki=5;function Qi(e,t,i,n,r,s,a,o){var c,l=0,h=null,u=!1,p=!1,d=-1!==n,f=-1,m=function(e){return Ui(e)&&e!==oi&&!Fi(e)&&e!==xi&&e!==ki&&e!==wi&&e!==bi&&e!==Ai&&e!==Ci&&e!==Ti&&e!==Oi&&e!==fi&&e!==gi&&e!==yi&&e!==pi&&e!==Pi&&e!==Si&&e!==_i&&e!==vi&&e!==di&&e!==mi&&e!==Ei&&e!==Ii}(zi(e,0))&&function(e){return!Fi(e)&&e!==wi}(zi(e,e.length-1));if(t||a)for(c=0;c=65536?c+=2:c++){if(!Ui(l=zi(e,c)))return Ki;m=m&&qi(l,h,o),h=l}else{for(c=0;c=65536?c+=2:c++){if((l=zi(e,c))===li)u=!0,d&&(p=p||c-f-1>n&&" "!==e[f+1],f=c);else if(!Ui(l))return Ki;m=m&&qi(l,h,o),h=l}p=p||d&&c-f-1>n&&" "!==e[f+1]}return u||p?i>9&&Wi(e)?Ki:a?s===Ri?Ki:Gi:p?Xi:Ji:!m||a||r(e)?s===Ri?Ki:Gi:Yi}function Zi(e,t,i,n,r){e.dump=function(){if(0===t.length)return e.quotingType===Ri?'""':"''";if(!e.noCompatMode&&(-1!==Mi.indexOf(t)||Li.test(t)))return e.quotingType===Ri?'"'+t+'"':"'"+t+"'";var s=e.indent*Math.max(1,i),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-s),o=n||e.flowLevel>-1&&i>=e.flowLevel;switch(Qi(t,o,e.indent,a,(function(t){return function(e,t){var i,n;for(i=0,n=e.implicitTypes.length;i"+en(t,e.indent)+tn(Bi(function(e,t){var i,n,r=/(\n+)([^\n]*)/g,s=(o=e.indexOf("\n"),o=-1!==o?o:e.length,r.lastIndex=o,nn(e.slice(0,o),t)),a="\n"===e[0]||" "===e[0];var o;for(;n=r.exec(e);){var c=n[1],l=n[2];i=" "===l[0],s+=c+(a||i||""===l?"":"\n")+nn(l,t),a=i}return s}(t,a),s));case Ki:return'"'+function(e){for(var t,i="",n=0,r=0;r=65536?r+=2:r++)n=zi(e,r),!(t=Ni[n])&&Ui(n)?(i+=e[r],n>=65536&&(i+=e[r+1])):i+=t||Di(n);return i}(t)+'"';default:throw new Te("impossible error: invalid scalar style")}}()}function en(e,t){var i=Wi(e)?String(t):"",n="\n"===e[e.length-1];return i+(n&&("\n"===e[e.length-2]||"\n"===e)?"+":n?"":"-")+"\n"}function tn(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function nn(e,t){if(""===e||" "===e[0])return e;for(var i,n,r=/ [^ ]/g,s=0,a=0,o=0,c="";i=r.exec(e);)(o=i.index)-s>t&&(n=a>s?a:o,c+="\n"+e.slice(s,n),s=n+1),a=o;return c+="\n",e.length-s>t&&a>s?c+=e.slice(s,a)+"\n"+e.slice(a+1):c+=e.slice(s),c.slice(1)}function rn(e,t,i,n){var r,s,a,o="",c=e.tag;for(r=0,s=i.length;r tag resolver accepts not "'+c+'" style');n=o.represent[c](t,c)}e.dump=n}return!0}return!1}function an(e,t,i,n,r,s,a){e.tag=null,e.dump=i,sn(e,i,!1)||sn(e,i,!0);var o,c=si.call(e.dump),l=n;n&&(n=e.flowLevel<0||e.flowLevel>t);var h,u,p="[object Object]"===c||"[object Array]"===c;if(p&&(u=-1!==(h=e.duplicates.indexOf(i))),(null!==e.tag&&"?"!==e.tag||u||2!==e.indent&&t>0)&&(r=!1),u&&e.usedDuplicates[h])e.dump="*ref_"+h;else{if(p&&u&&!e.usedDuplicates[h]&&(e.usedDuplicates[h]=!0),"[object Object]"===c)n&&0!==Object.keys(e.dump).length?(!function(e,t,i,n){var r,s,a,o,c,l,h="",u=e.tag,p=Object.keys(i);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new Te("sortKeys must be a boolean or a function");for(r=0,s=p.length;r1024)&&(e.dump&&li===e.dump.charCodeAt(0)?l+="?":l+="? "),l+=e.dump,c&&(l+=Vi(e,t)),an(e,t+1,o,!0,c)&&(e.dump&&li===e.dump.charCodeAt(0)?l+=":":l+=": ",h+=l+=e.dump));e.tag=u,e.dump=h||"{}"}(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,i){var n,r,s,a,o,c="",l=e.tag,h=Object.keys(i);for(n=0,r=h.length;n1024&&(o+="? "),o+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),an(e,t,a,!1,!1)&&(c+=o+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),u&&(e.dump="&ref_"+h+" "+e.dump));else if("[object Array]"===c)n&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?rn(e,t-1,e.dump,r):rn(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,i){var n,r,s,a="",o=e.tag;for(n=0,r=i.length;n",e.dump=o+" "+e.dump)}return!0}function on(e,t){var i,n,r=[],s=[];for(cn(e,r,s),i=0,n=s.length;ie.trim())).filter((e=>e.length));for(let t=0;te.trim()));e.style.setProperty(n[0],n[1])}}static setText(e,t,i){e instanceof SVGTextElement||(e=e.querySelector("text")||e);const n=t.replace(/\\n/g,"\n").split("\n"),r=n.length>1,s=e.querySelector("tspan");if(r){const t=null==s?void 0:s.getAttribute("x"),r=null==s?void 0:s.getAttribute("y");t&&!e.getAttribute("x")&&e.setAttribute("x",t),r&&!e.getAttribute("y")&&e.setAttribute("y",r);const a=e.querySelector("tspan")||!1;e.textContent="",e.dataset.ha_floorplan_notice="The text_set function split your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on the basis of the first tspan or text-element.";const o=e.getAttribute("x")||"0",c=i||"1em";n.forEach(((t,i)=>{const n=document.createElementNS("http://www.w3.org/2000/svg","tspan");if(n.textContent=t,n.setAttribute("x",o),n.setAttribute("dy",i>=1?c:"0"),a){const e=a.getAttribute("style");e&&n.setAttribute("style",e)}e.appendChild(n)}))}else{(s||e).textContent=t}}static waitForChildNodes(e,t,i){return new Promise(((n,r)=>{const s=setTimeout((()=>r("Timeout waiting for child element(s) to load")),i);new MutationObserver((e=>{for(const t of e)if("childList"===t.type&&t.addedNodes.length)return clearTimeout(s),n()})).observe(e,{childList:!0,subtree:!0}),t()}))}static formatDate(e){return e?"string"==typeof e?new Date(e).toLocaleString():e.toLocaleString():""}static parseYaml(e){return hn.load(e)}static fetchText(e,t,i,n){return un(this,void 0,void 0,(function*(){i&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${i}/`)),e=n?e:pn.cacheBuster(e);const r=new Request(e,{cache:n?"default":"no-store",mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){return yield e.text()}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static fetchImage(e,t,i,n){return un(this,void 0,void 0,(function*(){t&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${i}/`)),e=n?e:pn.cacheBuster(e);const r=new Request(e,{cache:n?"default":"no-store",headers:new Headers({"Content-Type":"text/plain; charset=x-user-defined"}),mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){const t=yield e.arrayBuffer();return`data:image/jpeg;base64,${pn.arrayBufferToBase64(t)}`}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static singleToArray(e){return null==e?[]:Array.isArray(e)?e:[e]}static getArray(e){if(null==e)return[];if(Array.isArray(e))return e;{const t=e;return Object.values(t)}}static getSet(e){if(Array.isArray(e))return new Set(e);{const t=e;return new Set(Object.values(t))}}static arrayBufferToBase64(e){let t="";[].slice.call(new Uint8Array(e)).forEach((e=>t+=String.fromCharCode(e)));let i=window.btoa(t);for(;i.length%4>0;)i+="=";return i}static cacheBuster(e){return`${e}${e.includes("?")?"&":"?"}_=${(new Date).getTime()}`}static equal(e,t){if(e===t)return!0;const i=Array.isArray(e),n=Array.isArray(t);let r=0;if(i&&n){if(e.length!=t.length)return!1;for(r=0;rMath.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage[e]=`${t()}${t()}_${t()}${t()}`}return localStorage[e]}}class dn{static closestElement(e,t){return function t(i){if(!i||i===document||i===window)return null;i.assignedSlot&&(i=i.assignedSlot);const n=i.closest(e);return n||t(i.getRootNode().host)}(t)}}const fn=(e,t,i,n)=>{n=n||{},i=null==i?{}:i;const r=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return r.detail=i,e.dispatchEvent(r),r},mn=(e,t,i=!1)=>{i?history.replaceState(null,"",t):history.pushState(null,"",t),fn(window,"location-changed",{replace:i})};class gn{constructor(e,t,i,n){this.entityId=e,this.svgElement=t,this.originalSvgElement=i,this.originalBBox=n}}class vn{constructor(e){this.rule=e,this.svgElementInfos={}}}class yn{constructor(e,t,i,n,r,s){this.instance=e,this.entityId=t,this.elementId=i,this.svgElementInfo=n,this.ruleInfo=r,this.actions=s}}const bn={},xn={};xn.click=xn.mousedown=xn.mouseup=xn.mousemove="MouseEvents";let wn=1;function Sn(e){return e._dtId||(e._dtId=wn++)}function _n(e){const t=e.indexOf(".");return t>0?{e:e.substring(0,e.indexOf(".")),ns:e.substring(t+1,e.length)}:{e}}function kn(e,t,i,n){const r=_n(i).e;if(!e._dtId)return!1;const s=bn[Sn(e)],a=function(e,t,i,n){return i=_n(i),(bn[Sn(e)]||[]).filter((e=>e&&(!i.e||e.e===i.e)&&(!i.ns||e.ns===i.ns)&&(!n||e.callback===n)&&(!t||e.selector===t)))}(e,t,i,n);a.forEach((t=>{e.removeEventListener?e.removeEventListener(r,t.delegator||t.callback):e.detachEvent&&e.detachEvent("on"+r,t.delegator||t.callback),s.splice(s.indexOf(t),1)}))}function En(e,t,i,n,r,s){const a=_n(i).e,o=_n(i).ns;e.addEventListener?e.addEventListener(a,r||n,s):e.attachEvent&&e.attachEvent("on"+a,r||n);const c=Sn(e);(bn[c]||(bn[c]=[])).push({delegator:r,callback:n,e:a,ns:o,selector:t})}const An={on(e,t,i,n=null){En(e,null,t,i,null,n)},off(e,t,i=null){kn(e,null,t,i)},once(e,t,i){const n=e=>(An.off(e.currentTarget,e.type,n),i(e));this.on(e,t,n)},delegate(e,t,i,n,r=null){En(e,t,i,n,(function(i){const r=e.querySelectorAll(t);let s=!1;for(let e=0;e{i=!1,t=setTimeout((()=>{i=!0,e.dispatchEvent(new Event("longClick"))}),400)},r=n=>{clearTimeout(t),i||e.dispatchEvent(new Event("short"+n.type[0].toUpperCase()+n.type.slice(1)))},s=e=>{i&&(e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation())};In.on(e,"mousedown",n.bind(this)),In.on(e,"tapstart",n.bind(this)),In.on(e,"touchstart",n.bind(this),{passive:!0}),In.on(e,"click",r.bind(this)),In.on(e,"mouseup",r.bind(this)),In.on(e,"tapend",r.bind(this)),In.on(e,"touchend",r.bind(this)),In.on(e,"tap",s.bind(this)),In.on(e,"touch",s.bind(this)),In.on(e,"mouseup",s.bind(this)),In.on(e,"tapend",s.bind(this)),In.on(e,"touchend",s.bind(this)),In.on(e,"click",(e=>{e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation()}).bind(this))}}const Pn=Cn,On=new Set;class Nn{static observe(e){if(On.has(e))return;On.add(e);let t,i=0;Pn.on(e,"click",(()=>{i++,t=setTimeout((()=>{1===i&&(i=0,e.dispatchEvent(new Event("singleClick")))}),400),2===i&&(clearTimeout(t),i=0,e.dispatchEvent(new Event("doubleClick")))}).bind(this))}}class Mn{static isCode(e){return this.isCodeBlock(e)||this.isCodeLine(e)}static isCodeBlock(e){return e.trim().startsWith(">")}static isCodeLine(e){return e.includes("${")&&e.includes("}")}static evaluate(e,t,i,n,r,s,a){this.expression=e.trim();const o=`${this.expression}_${null!=r?r:""}`;this.parsedFunction=this.cache[o],void 0===this.parsedFunction&&(this.functionBody=this.expression,this.isCodeBlock(this.functionBody)?this.functionBody=this.functionBody.slice(1).trim():this.isCodeLine(this.functionBody)&&(this.functionBody.startsWith('"')&&this.functionBody.endsWith('"')&&(this.functionBody=this.functionBody.slice(1,this.functionBody.length-2)),this.functionBody=this.functionBody.replace(/\\"/g,'"'),this.functionBody=`\`${this.functionBody}\`;`,this.functionBody.includes("return")||(this.functionBody=`return ${this.functionBody}`)),this.parsedFunction=this.interpreter.parse(`exports.result = (() => { ${this.functionBody} })();`),this.cache[o]=this.parsedFunction,this.interpreter.import("config",i),this.interpreter.import("util",this.util)),this.entityState=n?t.states[n]:void 0,this.interpreter.import("functions",a),this.interpreter.import("entity",this.entityState),this.interpreter.import("entities",t.states),this.interpreter.import("states",t.states),this.interpreter.import("hass",t),this.interpreter.import("element",r),this.interpreter.import("elements",s);try{this.interpreter.run(this.parsedFunction)}catch(e){throw new EvalError(we(e))}return this.interpreter.exports.result}}Mn.cache={},Mn.interpreter=new(xe())({ecmaVer:2019,sandBox:!0}),Mn.util={color:fe,date:ye};class Ln{constructor(e,t,i){this.element=e,this.logLevel=t,this.consoleLogLevel=i,this.logLevelGroups={error:["error"],warn:["error","warning","warn"],warning:["error","warning","warn"],info:["error","warning","warn","info"],debug:["error","warning","warn","info","debug"]}}log(e,t,i=!1){var n;const r=`${pn.formatDate(new Date)} ${e.toUpperCase()} ${t}`,s=this.logLevel&&this.logLevelGroups[this.logLevel.toLowerCase()],a=(null==s?void 0:s.length)&&s.includes(e.toLowerCase());if((i||a)&&this.element){const t=document.createElement("li");pn.addClass(t,e),t.textContent=r,null===(n=this.element.querySelector("ul"))||void 0===n||n.prepend(t),this.element.style.display="block"}this.consoleLog(e,t,i)}consoleLog(e,t,i=!1){const n=`${pn.formatDate(new Date)} ${e.toUpperCase()} ${t}`,r=this.consoleLogLevel&&this.logLevelGroups[this.consoleLogLevel.toLowerCase()],s=(null==r?void 0:r.length)&&r.includes(e.toLowerCase());if(i||s)switch(e){case"error":console.error(n);break;case"warn":case"warning":console.warn(n);break;case"info":console.info(n);break;default:console.log(n)}}}var Dn=function(e,t,i,n){var r,s=arguments.length,a=s<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,n);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,i,a):r(t,i))||a);return s>3&&a&&Object.defineProperty(t,i,a),a},$n=function(e,t,i,n){return new(i||(i=Promise))((function(r,s){function a(e){try{c(n.next(e))}catch(e){s(e)}}function o(e){try{c(n.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(a,o)}c((n=n.apply(e,t||[])).next())}))};const Rn=Cn;console.info("%cFloorplan for Home Assistant (ha-floorplan)%c\nVersion 1.0.43","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: rgb(71, 170, 238)");let jn=class extends ie{constructor(){super(),this.pageInfos={},this.entityInfos={},this.elementInfos={},this.cssRules=[],this.functions={},this.variables={},this.svgElements={},this.isRulesLoaded=!1,window.onerror=this.handleWindowError.bind(this)}render(){return R`
@@ -128,7 +128,7 @@ function Ee(e){return null==e}var Ae={isNothing:Ee,isObject:function(e){return"o .debug { color: #000000; } - `}clearLog(){this.logElement.querySelector("#log ul").innerHTML=""}updated(e){const t=Object.create(null,{updated:{get:()=>super.updated}});return $n(this,void 0,void 0,(function*(){t.updated.call(this,e),e.has("_config")&&(yield this._configChanged(),yield this.hassChanged()),e.has("hass")&&(yield this.hassChanged())}))}_configChanged(){return $n(this,void 0,void 0,(function*(){this._config&&(yield this.init())}))}hassChanged(){return $n(this,void 0,void 0,(function*(){if(!this.hass||!this.config||!this.svg)return;const e=pn.deviceId();this.hass.states[`sensor.ha_floorplan_${e}`]={entity_id:`sensor.ha_floorplan_${e}`,state:"on",last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{device_class:"ha-floorplan",friendly_name:"ha-floorplan - Floorplan for Home Assistant",icon:"mdi:floor-plan",assumed_state:!1,hidden:!0},context:{}},this.isRulesLoaded?this.handleEntities():(this.initFloorplanRules(this.svg,this.config),this.isRulesLoaded=!0,yield this.handleEntities(!0))}))}get floorplanElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("floorplan")}get logElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("log")}init(){return $n(this,void 0,void 0,(function*(){try{const e=yield this.loadConfig(this._config,!1);if(this.isShowLog=void 0!==e.log_level,this.logger=new Ln(this.logElement,e.log_level,e.console_log_level),this.logInfo("INIT","Floorplan for Home Assistant (ha-floorplan) v1.0.41"),!this.validateConfig(e))return;this.config=e,this.config.pages?yield this.initMultiPage():yield this.initSinglePage()}catch(e){this.handleError(e)}}))}initMultiPage(){return $n(this,void 0,void 0,(function*(){try{yield this.loadPages(),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}initSinglePage(){return $n(this,void 0,void 0,(function*(){try{yield this.loadStyleSheet(this.config.stylesheet);const e=this.getBestImage(this.config);this.svg=yield this.loadFloorplanSvg(e),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}loadConfig(e,t){return $n(this,void 0,void 0,(function*(){if("string"==typeof e){let i;try{i=yield pn.fetchText(e,this.isDemo,this.examplespath,t)}catch(t){throw this.logError("CONFIG",`Error loading config: ${e}`),t}return hn.load(i)}return JSON.parse(JSON.stringify(e))}))}loadScript(e,t){return e?new Promise(((i,n)=>{var r;const s=document.createElement("script");s.src=t?e:pn.cacheBuster(e),s.onload=()=>i(),s.onerror=e=>{n(new URIError(`${e.target.src}`))},null===(r=this.shadowRoot)||void 0===r||r.appendChild(s)})):Promise.resolve()}loadPages(){return $n(this,void 0,void 0,(function*(){for(const e of this.config.pages)yield this.loadPageConfig(e,this.config.pages.indexOf(e));const e=Object.keys(this.pageInfos).map((e=>this.pageInfos[e]));e.sort(((e,t)=>e.index-t.index));const t=e.find((e=>void 0!==e.config.master_page));if(!t)throw new Error("A master page is required");t.isMaster=!0;const i=e.find((e=>void 0===e.config.master_page));i&&(i.isDefault=!0),yield this.loadPageFloorplanSvg(t,t);const n=e.filter((e=>e!==t));for(const e of n)yield this.loadPageFloorplanSvg(e,t);this.svg=t.svg}))}loadPageConfig(e,t){return $n(this,void 0,void 0,(function*(){const i=yield this.loadConfig(e,!1),n=this.createPageInfo(i);return n.index=t,n}))}loadPageFloorplanSvg(e,t){return $n(this,void 0,void 0,(function*(){const i=this.getBestImage(e.config),n=yield this.loadFloorplanSvg(i,e,t);n.id=e.config.page_id,e.svg=n,yield this.loadStyleSheet(e.config.stylesheet),this.initFloorplanRules(e.svg,e.config)}))}getBestImage(e){var t;let i="",n=!0;if("string"==typeof e.image)i=pn.isMobile&&"string"==typeof e.image_mobile?e.image_mobile:e.image;else if(null===(t=e.image)||void 0===t?void 0:t.sizes){e.image.sizes.sort(((e,t)=>t.min_width-e.min_width));for(const t of e.image.sizes)if(screen.width>=t.min_width){i=t.location,n=!0===t.cache;break}}else pn.isMobile&&e.image_mobile?(i=e.image_mobile.location,n=!0===e.image_mobile.cache):(i=e.image.location,n=!0===e.image.cache);return{location:i,cache:n}}createPageInfo(e){const t={config:e};return t.config.rules&&this.config.rules&&(t.config.rules=t.config.rules.concat(this.config.rules)),this.pageInfos[t.config.page_id]=t,t}loadStyleSheet(e){return $n(this,void 0,void 0,(function*(){const t="string"==typeof e?e:e.location,i="string"!=typeof e&&!0===e.cache;if(!t)return;let n;try{n=yield pn.fetchText(t,this.isDemo,this.examplespath,i)}catch(e){throw this.logError("STYLESHEET",`Error loading stylesheet: ${t}`),e}const r=document.createElement("style"),s=()=>{var e;r.innerHTML=n,null===(e=this.shadowRoot)||void 0===e||e.appendChild(r)};try{yield pn.waitForChildNodes(r,s,1e4)}catch(e){this.logError("STYLESHEET","Error loading stylesheet")}const a=this.getCssRules(r);this.cssRules=this.cssRules.concat(a)}))}getCssRules(e){var t,i,n,r,s,a;let o;if(e.sheet)o=null!==(i=null===(t=e.sheet)||void 0===t?void 0:t.cssRules)&&void 0!==i?i:null===(n=e.sheet)||void 0===n?void 0:n.rules;else{const t=e;t.styleSheet&&(o=null!==(s=null===(r=t.styleSheet)||void 0===r?void 0:r.cssRules)&&void 0!==s?s:null===(a=t.styleSheet)||void 0===a?void 0:a.rules)}return o?pn.getArray(o):[]}loadFloorplanSvg(e,t,i){var n;return $n(this,void 0,void 0,(function*(){let r;try{r=yield pn.fetchText(e.location,this.isDemo,this.examplespath,e.cache)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e.location}`),t}const s=document.createElement("div");s.innerHTML=r;const a=s.querySelector("svg");if(t&&a.setAttribute("id",t.config.page_id),a.setAttribute("height","100%"),a.setAttribute("width","100%"),a.style.height="100%",a.style.width="100%",a.style.margin="auto",a.style.cursor="default",a.style.opacity="0",a.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),t&&i){const e=i.config.page_id,r=i.config.master_page.content_element;if(t.config.page_id===e)this.floorplanElement.replaceChildren(a);else{const e=this.floorplanElement.querySelector("#"+r),t=Number.parseFloat(a.getAttribute("height")),i=Number.parseFloat(a.getAttribute("width"));a.getAttribute("viewBox")||a.setAttribute("viewBox",`0 0 ${i} ${t}`),a.setAttribute("preserveAspectRatio","xMinYMin meet"),a.setAttribute("height",e.getAttribute("height")),a.setAttribute("width",e.getAttribute("width")),a.setAttribute("x",e.getAttribute("x")),a.setAttribute("y",e.getAttribute("y")),null===(n=e.parentElement)||void 0===n||n.replaceChildren(a)}}else this.floorplanElement.replaceChildren(a);return a}))}loadImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){return e.toLowerCase().includes(".svg")||"svg"===t.svgElement.nodeName||t.svgElement.querySelector("svg")?yield this.loadSvgImage(e,t,i,n,r):yield this.loadBitmapImage(e,t,i,n,r)}))}loadBitmapImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){e=r?e:pn.cacheBuster(e),this.logDebug("IMAGE",`${i} (setting image: ${e})`);let s=t.svgElement;return"image"!==s.nodeName&&(s=this.createImageElement(t.originalSvgElement),t.svgElement=this.replaceElement(t.svgElement,s),this.attachClickHandlers(s,t,i,void 0,n),s.onmouseover=()=>{this.handleEntityIdSetHoverOver(i,t)}),s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),s}))}loadSvgImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){let s;if(null==e?void 0:e.trim().length)try{s=yield pn.fetchText(e,this.isDemo,this.examplespath,r)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e}`),t}else{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 0 0"),s=e.outerHTML}this.logDebug("IMAGE",`${i} (setting image: ${e})`);const a="g"===t.svgElement.nodeName?t.svgElement:document.createElement("div");a.innerHTML=s;const o=a.querySelector("svg"),c=Number.parseFloat(o.getAttribute("height")),l=Number.parseFloat(o.getAttribute("width"));if(o.getAttribute("viewBox")||o.setAttribute("viewBox",`0 0 ${l} ${c}`),o.id=t.svgElement.id,o.setAttribute("preserveAspectRatio","xMinYMin meet"),null!==t.originalBBox&&(o.setAttribute("height",t.originalBBox.height.toString()),o.setAttribute("width",t.originalBBox.width.toString()),o.setAttribute("x",t.originalBBox.x.toString()),o.setAttribute("y",t.originalBBox.y.toString())),"g"!==t.svgElement.nodeName){const e=t.svgElement.getAttribute("transform");e&&o.setAttribute("transform",e),t.svgElement=this.replaceElement(t.svgElement,o)}return this.attachClickHandlers(o,t,i,void 0,n),t.svgElement.onmouseover=()=>{this.handleEntityIdSetHoverOver(i,t)},o}))}_querySelectorAll(e,t=void 0,i){let n=t?Array.from(e.querySelectorAll(t).values()):[];return n=i?[e].concat(n):n,n}replaceElement(e,t){const i=e.parentElement;for(const i of Array.from(e.classList))t.classList.add(i);return this._querySelectorAll(e,"*",!0).forEach((e=>{Rn.off(e,"click"),Rn.off(e,"longClick"),e.remove()})),e.remove(),null==i||i.appendChild(t),t}initPageDisplay(){if(this.config.pages)for(const e of Object.values(this.pageInfos))e.svg.style.opacity="1",e.svg.style.display=e.isMaster||e.isDefault?"initial":"none";else this.svg.style.opacity="1",this.svg.style.display="block"}initVariables(){if(this.config.variables)for(const e of this.config.variables)this.initVariable(e);if(this.config.pages)for(const e of Object.values(this.pageInfos))if(e.config.variables)for(const t of e.config.variables)this.initVariable(t)}initVariable(e){let t,i;if("string"==typeof e?t=e:(t=e.name,i=e.value,e.value&&(i=this.evaluate(e.value,t,void 0))),!this.entityInfos[t]){const e={entityId:t,ruleInfos:[],lastState:void 0};this.entityInfos[t]=e}this.hass.states[t]||(this.hass.states[t]={entity_id:t,state:i,last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{},context:{}}),this.setVariable(t,i,{},!0)}getActionConfigs(e){var t,i;if(null==e)return[];if(Array.isArray(e)){for(const i of e)i.action=null!==(t=i.action)&&void 0!==t?t:"call-service";return e}return"object"==typeof e?(e.action=null!==(i=e.action)&&void 0!==i?i:"call-service",[e]):"string"==typeof e?e.includes(".")?[{action:"call-service",service:e}]:[{action:e}]:[]}initStartupActions(){if(this.handleActions(this.config.startup_action,void 0,void 0,void 0),this.config.pages)for(const e of Object.values(this.pageInfos))this.handleActions(e.config.startup_action,void 0,void 0,void 0)}initFloorplanRules(e,t){if(!t.rules)return;const i=this._querySelectorAll(e,"*",!0);for(const e of i)e.id&&(this.svgElements[e.id]=e);this.initRules(t,e,i)}initRules(e,t,i){if(e.functions&&(this.functions=this.evaluate(e.functions)),e.defaults){const t=e.defaults;for(const i of e.rules)i.hover_action=void 0===i.hover_action?t.hover_action:i.hover_action,i.tap_action=void 0===i.tap_action?t.tap_action:i.tap_action,i.hold_action=void 0===i.hold_action?t.hold_action:i.hold_action,i.hover_info_filter=void 0===i.hover_info_filter?t.hover_info_filter:i.hover_info_filter}for(const n of e.rules)n.entity||n.entities?this.initEntityRule(n,t,i):(n.element||n.elements)&&this.initElementRule(n,t,i)}initEntityRule(e,t,i){const n=this.initGetEntityRuleEntities(e);for(const r of n){const n=r.entityId;let s=this.entityInfos[n];s||(s={entityId:n,ruleInfos:[],lastState:void 0},this.entityInfos[n]=s);const a=new vn(e);s.ruleInfos.push(a);for(const e of r.elementIds){const r=i.find((t=>t.id===e));if(!r){this.logWarning("CONFIG",`Cannot find element '${e}' in SVG file`);continue}const o=this.addSvgElementToRule(t,r,a);o.svgElement=r,r.querySelector("title")||r.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.onmouseenter=()=>{this.handleEntitySetHoverOver(s,o)},r.onmouseleave=()=>{this.handleEntitySetHoverOver(s,o)},this.attachClickHandlers(r,o,n,void 0,a)}}}initGetEntityRuleEntities(e){const t=[];e.groups=e.groups?e.groups:[];for(const i of e.groups){const e=this.hass.states[i];if(e)for(const i of e.attributes.entity_id)this.addTargetEntity(i,[i],t);else this.logWarning("CONFIG",`Cannot find '${i}' in Home Assistant groups`)}e.entities=e.entities?e.entities:[],e.entities=e.entity?e.entities.concat(e.entity):e.entities;const i=e.entities.filter((e=>"string"==typeof e));for(const n of i){let i=[];e.elements?i=i.concat(e.elements):e.element?i=i.concat(this.evaluate(e.element,n,void 0)):null!==e.element&&(i=i.concat(n)),this.addTargetEntity(n,i,t)}const n=e.entities.filter((e=>"string"!=typeof e));for(const e of n){const i=e;this.addTargetEntity(i.entity,[i.element],t)}return t}addTargetEntity(e,t,i){const n=this.hass.states[e],r="floorplan"===e.split(".")[0];n||r?i.push({entityId:e,elementIds:t}):this.logWarning("CONFIG",`Cannot find '${e}' in Home Assistant entities`)}initElementRule(e,t,i){if(e.element||e.elements){e.elements=e.elements?e.elements:[],e.elements=e.element?e.elements.concat(e.element):e.elements;for(const n of e.elements){const r=i.find((e=>e.id===n));if(r){let i=this.elementInfos[n];i||(i={ruleInfos:[],lastState:void 0},this.elementInfos[n]=i);const s=new vn(e);i.ruleInfos.push(s);const a=this.addSvgElementToRule(t,r,s);this.attachClickHandlers(r,a,void 0,n,s)}else this.logWarning("CONFIG",`Cannot find '${n}' in SVG file`)}}}attachClickHandlers(e,t,i,n,r){this._querySelectorAll(e,void 0,!0).forEach((s=>{const a=s,o=s===e;if(a.querySelector("title")||a.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.rule.tap_action||r.rule.double_tap_action){const e=!!r.rule.tap_action&&this.getActionConfigs(r.rule.tap_action),s=!!r.rule.double_tap_action&&this.getActionConfigs(r.rule.double_tap_action),c=!!e&&new yn(this,i,n,t,r,e);if(e&&!s&&Rn.on(a,"click",this.onClick.bind(c)),s){const o=!!s&&new yn(this,i,n,t,r,s);Nn.observe(a),e&&Rn.on(a,"singleClick",this.onClick.bind(c)),Rn.on(a,"doubleClick",this.onLongClick.bind(o))}a.style&&(a.style.cursor="pointer"),pn.addClass(a,"floorplan-click"+(o?"":"-child"))}if(r.rule.hold_action){const e=this.getActionConfigs(r.rule.hold_action),s=new yn(this,i,n,t,r,e);Tn.observe(a),Rn.on(a,"longClick",this.onLongClick.bind(s)),a.style&&(a.style.cursor="pointer"),pn.addClass(a,"floorplan-long-click"+(o?"":"-child"))}}))}addSvgElementToRule(e,t,i){const n=t.getBBox?t.getBBox():null,r=new gn(t.id,t,t,n);return i.svgElementInfos[t.id]=r,r}createImageElement(e){const t=document.createElementNS("http://www.w3.org/2000/svg","image");return t.setAttribute("id",e.getAttribute("id")),t.setAttribute("x",e.getAttribute("x")),t.setAttribute("y",e.getAttribute("y")),t.setAttribute("height",e.getAttribute("height")),t.setAttribute("width",e.getAttribute("width")),t}handleEntities(e=!1){return $n(this,void 0,void 0,(function*(){this.handleElements();const t=this.getChangedEntities(e);for(const e of Object.keys(this.variables))t.add(e);if(t.size)for(const e of t)yield this.handleEntity(e)}))}getChangedEntities(e){const t=new Set,i=Object.keys(this.hass.states),n=pn.deviceId();for(const r of i)if(r!==`sensor.ha_floorplan_${n}`||t.has(r)){const i=this.entityInfos[r];if(i){const n=this.hass.states[r];if(e)this.logDebug("STATE",`${r}: ${n.state} (initial load)`),t.has(r)||t.add(r);else if(i.lastState){const e=n.state;n.last_changed!==i.lastState.last_changed?(this.logDebug("STATE",`${r}: ${e} (last changed ${pn.formatDate(i.lastState.last_changed)})`),t.has(r)||t.add(r)):pn.equal(i.lastState.attributes,n.attributes)||(this.logDebug("STATE",`${r}: attributes (last updated ${pn.formatDate(i.lastState.last_changed)})`),t.has(r)||t.add(r))}}}else t.add(r);return t}handleEntity(e){return $n(this,void 0,void 0,(function*(){const t=this.hass.states[e],i=this.entityInfos[e];if(i){i.lastState=Object.assign({},t);for(const e of i.ruleInfos){const t=Object.values(e.svgElementInfos);if(t.length)for(const n of t)n.svgElement&&this.handleActions(e.rule.state_action,i.entityId,n,e);else this.handleActions(e.rule.state_action,i.entityId,void 0,e)}}}))}handleElements(){return $n(this,void 0,void 0,(function*(){for(const e of Object.values(this.elementInfos))for(const t of e.ruleInfos)for(const e of Object.values(t.svgElementInfos))this.handleActions(t.rule.state_action,void 0,e,t)}))}handleEntityIdSetHoverOver(e,t){const i=this.entityInfos[e];i&&this.handleEntitySetHoverOver(i,t)}handleEntitySetHoverOver(e,t){const i=e.entityId,n=this.hass.states[i];for(const i of e.ruleInfos)if(i.rule.hover_action){let r="string"==typeof i.rule.hover_action&&"hover-info"===i.rule.hover_action;if(r=r||"object"==typeof i.rule.hover_action&&"hover-info"===i.rule.hover_action.action,r=r||Array.isArray(i.rule.hover_action)&&i.rule.hover_action.some((e=>"hover-info"===e.action)),r){const e=new Set(i.rule.hover_info_filter);for(const t of Object.values(i.svgElementInfos))pn.addClass(t.svgElement,"floorplan-hover"),t.svgElement.style.cursor="pointer",t.svgElement.querySelectorAll("title").forEach((t=>{let i=`${n.attributes.friendly_name}\n`;i+=`State: ${n.state}\n\n`,Object.keys(n.attributes).map((t=>{e.has(t)||(i+=`${t}: ${n.attributes[t]}\n`)})),i+="\n",i+=`Last changed: ${ye.timeago(n.last_changed)}\n`,i+=`Last updated: ${ye.timeago(n.last_updated)}`,t.textContent=i}))}else i.rule.hover_action&&this.handleActions(i.rule.hover_action,e.entityId,t,i)}}isOptionEnabled(e){return null===e||void 0!==e}validateConfig(e){let t=!0;if(e.pages||e.rules)if(e.pages)e.pages.length||this.logWarning("CONFIG","The 'pages' section must contain one or more pages in floorplan configuration");else{e.rules||this.logWarning("CONFIG","Cannot find 'rules' in floorplan configuration");let i=e.rules.filter((e=>e.entities&&e.elements));i.length&&(this.logError("CONFIG","A rule cannot contain both 'entities' and 'elements' in floorplan configuration"),t=!1),i=e.rules.filter((e=>!(e.entity||e.entities||e.element||e.elements))),i.length&&(this.logError("CONFIG","A rule must contain either 'entities' or 'elements' in floorplan configuration"),t=!1)}else this.logWarning("CONFIG","Cannot find 'pages' nor 'rules' in floorplan configuration");return t}evaluate(e,t,i){if("string"!=typeof e||!Mn.isCode(e))return e;try{return Mn.evaluate(e,this.hass,this.config,t,i,this.svgElements,this.functions)}catch(n){return this.handleError(n,{expression:e,entityId:t,hass:this.hass,svgElement:i})}}onClick(e){e.stopPropagation(),e.preventDefault();const t=this;t.instance.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}onLongClick(e){e.stopPropagation(),e.preventDefault();const t=this,i=t.instance;setTimeout((()=>{i.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}),300)}handleActions(e,t,i,n){var r;const s=this.getActionConfigs(e);for(const e of s){if(e.confirmation&&(!e.confirmation.exemptions||!e.confirmation.exemptions.some((e=>e.user===this.hass.user.id)))&&!confirm(e.confirmation.text||`Are you sure you want to ${e.action}?`))return;switch(e.action){case"more-info":this.isDemo?this.notify(`Performing action: ${e.action} ${t}`):fn(this,"hass-more-info",{entityId:t});break;case"navigate":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.navigation_path}`);else{const n=this.evaluate(e.navigation_path,t,null==i?void 0:i.svgElement);mn(0,n,null!==(r=e.navigation_replace)&&void 0!==r&&r)}break;case"url":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.url_path}`);else{const t=e.same_tab?"_self":"_blank";window.open(e.url_path,t)}break;case"toggle":if(t){const e={action:"call-service",service:"homeassistant.toggle",service_data:{entity_id:t}};this.callService(e,t,i,n)}break;case"call-service":if(!e.service)return;this.callService(e,t,i,n);break;case"fire-dom-event":fn(this,"ll-custom",e)}}}getSvgElementsFromServiceData(e,t){let i=[],n=[];if(Array.isArray(null==e?void 0:e.elements)&&(n=n.concat(null==e?void 0:e.elements)),"string"==typeof(null==e?void 0:e.element)&&(n=n.concat([null==e?void 0:e.element])),n.length)for(const e of n)i=i.concat(this._querySelectorAll(this.svg,`#${e.replace(/\./g,"\\.")}`,!1));else t&&(i=[t]);return i}getServiceData(e,t,i){let n={};if("object"==typeof e.service_data)for(const r of Object.keys(e.service_data))n[r]=this.evaluate(e.service_data[r],t,i);else if("string"==typeof e.service_data){const r=this.evaluate(e.service_data,t,i);n="string"==typeof r&&r.trim().startsWith("{")?JSON.parse(r):r}else void 0!==e.service_data&&(n=e.service_data);return n}executeServiceData(e,t,i){try{if("object"==typeof e.service_data)for(const n of Object.keys(e.service_data))this.evaluate(e.service_data[n],t,i);else"string"==typeof e.service_data?this.evaluate(e.service_data,t,i):void 0!==e.service_data&&this.logWarning("CONFIG","Invalid execution data");return!0}catch(e){return this.logWarning("CONFIG","Error thrown while executing service"),!1}}callService(e,t,i,n){const r=this.evaluate(e.service,t,null==i?void 0:i.svgElement),[s,a]=r.split(".",2);if("floorplan"===s)this.callFloorplanService(s,a,e,t,i,n);else this.callHomeAssistantService(s,a,e,t,i)}callFloorplanService(e,t,i,n,r,s){var a,o,c;const l=null!==(a=null==r?void 0:r.svgElement)&&void 0!==a?a:void 0;let h,u,p,d,f,m,g,v,y,b=[],x=null;switch(x=!["execute"].includes(t)?this.getServiceData(i,n,l):{},t){case"class_toggle":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),p="string"==typeof x?x:x.class,pn.toggleClass(e,p);break;case"class_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),p="string"==typeof x?x:x.class,pn.setClass(e,p);break;case"dataset_set":{let e,t;if("string"==typeof x){const i=x.split(":");if(i.length<2){this.logError("FLOORPLAN_ACTION",`Service data "${x}" is not a valid dataset key value pair.`);break}e=i[1],t=i[0]}else e=x.value,t=x.key;b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const s of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,s)),pn.datasetSet(s,t,e);break}case"style_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),d="string"==typeof x?x:x.style,pn.setStyle(e,d);break;case"text_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b){y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),v="string"==typeof x?x:x.text;const t=(null===(o=i.service_data)||void 0===o?void 0:o.shift_y_axis)?null===(c=i.service_data)||void 0===c?void 0:c.shift_y_axis:"1em";pn.setText(e,v,t)}break;case"image_set":r&&s&&(x=this.getServiceData(i,n,null==r?void 0:r.svgElement),f="string"==typeof x?x:x.image,m="object"==typeof x?x.image_refresh_interval:0,g=!(m>0)&&("object"!=typeof x||!0===x.cache),s.imageLoader&&clearInterval(s.imageLoader),m&&(s.imageLoader=setInterval(this.loadImage.bind(this),1e3*m,f,r,n,s,g)),this.loadImage(f,r,n,s,g));break;case"page_navigate":x=this.getServiceData(i,n,null==r?void 0:r.svgElement),h=x.page_id,u=h?this.pageInfos[h]:void 0,u&&(Object.keys(this.pageInfos).map((e=>{const t=this.pageInfos[e];t.isMaster||"none"===t.svg.style.display||(t.svg.style.display="none")})),u.svg.style.display="block");break;case"variable_set":if(x=this.getServiceData(i,n,null==r?void 0:r.svgElement),x.variable){const e={};if(x.attributes){const t=x.attributes;for(const i of Object.keys(t))e[i]=this.getActionValue(t[i],n,l)}const t=x,i=this.getActionValue(t,n,l);this.setVariable(x.variable,i,e,!1)}break;case"execute":this.executeServiceData(i,n,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||this.executeServiceData(i,n,e)}}getActionValue(e,t,i){let n=e.value;return e.value&&(n=this.evaluate(e.value,t,i)),n}setVariable(e,t,i,n){if(this.variables[e]=t,this.hass.states[e]){this.hass.states[e].state=t.toString();for(const t of Object.keys(i))this.hass.states[e].attributes[t]=i[t]}for(const e of Object.keys(this.variables)){const t=this.hass.states[e];t&&(t.last_changed=(new Date).toString())}n||this.handleEntities()}callHomeAssistantService(e,t,i,n,r){const s=this.getServiceData(i,n,null==r?void 0:r.svgElement);"object"==typeof s&&(null===s.entity_id||Array.isArray(s.entity_id)&&!s.entity_id.length||!s.entity_id&&n&&(s.entity_id=n)),this.hass.callService(e,t,s),this.isDemo&&this.notify(`Calling service: ${e}.${t} (${s.entity_id})`)}handleWindowError(e,t,i,n,r){if(e.toLowerCase().includes("script error"))this.logError("SCRIPT","Script error: See browser console for detail");else{const s=[e,"URL: "+t,"Line: "+i+", column: "+n,"Error: "+JSON.stringify(r)].join("
");this.logError("ERROR",s)}return!1}handleError(e,t){console.error(e,t);let i="Error";"string"==typeof e&&(i=e),e.message?i=`${e.message} (See console for more info)`:e.stack&&(i=`${e.stack}`),this.logger.log("error",i)}logError(e,t){this.logger.log("error",`${e} ${t}`)}logWarning(e,t){this.logger.log("warning",`${e} ${t}`)}logInfo(e,t){this.logger.log("info",`${e} ${t}`)}logDebug(e,t){this.logger.log("debug",`${e} ${t}`)}};Dn([ae({type:String})],jn.prototype,"examplespath",void 0),Dn([ae({type:Object})],jn.prototype,"hass",void 0),Dn([ae({type:String||Object})],jn.prototype,"_config",void 0),Dn([ae({type:Boolean})],jn.prototype,"isDemo",void 0),Dn([ae({type:Boolean})],jn.prototype,"isShowLog",void 0),Dn([ae({type:Function})],jn.prototype,"notify",void 0),jn=Dn([re("floorplan-element")],jn); + `}clearLog(){this.logElement.querySelector("#log ul").innerHTML=""}updated(e){const t=Object.create(null,{updated:{get:()=>super.updated}});return $n(this,void 0,void 0,(function*(){t.updated.call(this,e),e.has("_config")&&(yield this._configChanged(),yield this.hassChanged()),e.has("hass")&&(yield this.hassChanged())}))}_configChanged(){return $n(this,void 0,void 0,(function*(){this._config&&(yield this.init())}))}hassChanged(){return $n(this,void 0,void 0,(function*(){if(!this.hass||!this.config||!this.svg)return;const e=pn.deviceId();this.hass.states[`sensor.ha_floorplan_${e}`]={entity_id:`sensor.ha_floorplan_${e}`,state:"on",last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{device_class:"ha-floorplan",friendly_name:"ha-floorplan - Floorplan for Home Assistant",icon:"mdi:floor-plan",assumed_state:!1,hidden:!0},context:{}},this.isRulesLoaded?this.handleEntities():(this.initFloorplanRules(this.svg,this.config),this.isRulesLoaded=!0,yield this.handleEntities(!0))}))}get floorplanElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("floorplan")}get logElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("log")}init(){return $n(this,void 0,void 0,(function*(){try{const e=yield this.loadConfig(this._config,!1);if(this.isShowLog=void 0!==e.log_level,this.logger=new Ln(this.logElement,e.log_level,e.console_log_level),this.logInfo("INIT","Floorplan for Home Assistant (ha-floorplan) v1.0.43"),!this.validateConfig(e))return;this.config=e,this.config.pages?yield this.initMultiPage():yield this.initSinglePage()}catch(e){this.handleError(e)}}))}initMultiPage(){return $n(this,void 0,void 0,(function*(){try{yield this.loadPages(),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}initSinglePage(){return $n(this,void 0,void 0,(function*(){try{yield this.loadStyleSheet(this.config.stylesheet);const e=this.getBestImage(this.config);this.svg=yield this.loadFloorplanSvg(e),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}loadConfig(e,t){return $n(this,void 0,void 0,(function*(){if("string"==typeof e){let i;try{i=yield pn.fetchText(e,this.isDemo,this.examplespath,t)}catch(t){throw this.logError("CONFIG",`Error loading config: ${e}`),t}return hn.load(i)}return JSON.parse(JSON.stringify(e))}))}loadScript(e,t){return e?new Promise(((i,n)=>{var r;const s=document.createElement("script");s.src=t?e:pn.cacheBuster(e),s.onload=()=>i(),s.onerror=e=>{n(new URIError(`${e.target.src}`))},null===(r=this.shadowRoot)||void 0===r||r.appendChild(s)})):Promise.resolve()}loadPages(){return $n(this,void 0,void 0,(function*(){for(const e of this.config.pages)yield this.loadPageConfig(e,this.config.pages.indexOf(e));const e=Object.keys(this.pageInfos).map((e=>this.pageInfos[e]));e.sort(((e,t)=>e.index-t.index));const t=e.find((e=>void 0!==e.config.master_page));if(!t)throw new Error("A master page is required");t.isMaster=!0;const i=e.find((e=>void 0===e.config.master_page));i&&(i.isDefault=!0),yield this.loadPageFloorplanSvg(t,t);const n=e.filter((e=>e!==t));for(const e of n)yield this.loadPageFloorplanSvg(e,t);this.svg=t.svg}))}loadPageConfig(e,t){return $n(this,void 0,void 0,(function*(){const i=yield this.loadConfig(e,!1),n=this.createPageInfo(i);return n.index=t,n}))}loadPageFloorplanSvg(e,t){return $n(this,void 0,void 0,(function*(){const i=this.getBestImage(e.config),n=yield this.loadFloorplanSvg(i,e,t);n.id=e.config.page_id,e.svg=n,yield this.loadStyleSheet(e.config.stylesheet),this.initFloorplanRules(e.svg,e.config)}))}getBestImage(e){var t;let i="",n=!0;if("string"==typeof e.image)i=pn.isMobile&&"string"==typeof e.image_mobile?e.image_mobile:e.image;else if(null===(t=e.image)||void 0===t?void 0:t.sizes){e.image.sizes.sort(((e,t)=>t.min_width-e.min_width));for(const t of e.image.sizes)if(screen.width>=t.min_width){i=t.location,n=!0===t.cache;break}}else pn.isMobile&&e.image_mobile?(i=e.image_mobile.location,n=!0===e.image_mobile.cache):(i=e.image.location,n=!0===e.image.cache);return{location:i,cache:n}}createPageInfo(e){const t={config:e};return t.config.rules&&this.config.rules&&(t.config.rules=t.config.rules.concat(this.config.rules)),this.pageInfos[t.config.page_id]=t,t}loadStyleSheet(e){return $n(this,void 0,void 0,(function*(){const t="string"==typeof e?e:e.location,i="string"!=typeof e&&!0===e.cache;if(!t)return;let n;try{n=yield pn.fetchText(t,this.isDemo,this.examplespath,i)}catch(e){throw this.logError("STYLESHEET",`Error loading stylesheet: ${t}`),e}const r=document.createElement("style"),s=()=>{var e;r.innerHTML=n,null===(e=this.shadowRoot)||void 0===e||e.appendChild(r)};try{yield pn.waitForChildNodes(r,s,1e4)}catch(e){this.logError("STYLESHEET","Error loading stylesheet")}const a=this.getCssRules(r);this.cssRules=this.cssRules.concat(a)}))}getCssRules(e){var t,i,n,r,s,a;let o;if(e.sheet)o=null!==(i=null===(t=e.sheet)||void 0===t?void 0:t.cssRules)&&void 0!==i?i:null===(n=e.sheet)||void 0===n?void 0:n.rules;else{const t=e;t.styleSheet&&(o=null!==(s=null===(r=t.styleSheet)||void 0===r?void 0:r.cssRules)&&void 0!==s?s:null===(a=t.styleSheet)||void 0===a?void 0:a.rules)}return o?pn.getArray(o):[]}loadFloorplanSvg(e,t,i){var n;return $n(this,void 0,void 0,(function*(){let r;try{r=yield pn.fetchText(e.location,this.isDemo,this.examplespath,e.cache)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e.location}`),t}const s=document.createElement("div");s.innerHTML=r;const a=s.querySelector("svg");if(t&&a.setAttribute("id",t.config.page_id),a.setAttribute("height","100%"),a.setAttribute("width","100%"),a.style.height="100%",a.style.width="100%",a.style.margin="auto",a.style.cursor="default",a.style.opacity="0",a.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),t&&i){const e=i.config.page_id,r=i.config.master_page.content_element;if(t.config.page_id===e)this.floorplanElement.replaceChildren(a);else{const e=this.floorplanElement.querySelector("#"+r),t=Number.parseFloat(a.getAttribute("height")),i=Number.parseFloat(a.getAttribute("width"));a.getAttribute("viewBox")||a.setAttribute("viewBox",`0 0 ${i} ${t}`),a.setAttribute("preserveAspectRatio","xMinYMin meet"),a.setAttribute("height",e.getAttribute("height")),a.setAttribute("width",e.getAttribute("width")),a.setAttribute("x",e.getAttribute("x")),a.setAttribute("y",e.getAttribute("y")),null===(n=e.parentElement)||void 0===n||n.replaceChildren(a)}}else this.floorplanElement.replaceChildren(a);return a}))}loadImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){return e.toLowerCase().includes(".svg")||"svg"===t.svgElement.nodeName||t.svgElement.querySelector("svg")?yield this.loadSvgImage(e,t,i,n,r):yield this.loadBitmapImage(e,t,i,n,r)}))}loadBitmapImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){e=r?e:pn.cacheBuster(e),this.logDebug("IMAGE",`${i} (setting image: ${e})`);let s=t.svgElement;return"image"!==s.nodeName&&(s=this.createImageElement(t.originalSvgElement),t.svgElement=this.replaceElement(t.svgElement,s),this.attachClickHandlers(s,t,i,void 0,n),s.onmouseover=()=>{this.handleEntityIdSetHoverOver(i,t)}),s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),s}))}loadSvgImage(e,t,i,n,r){return $n(this,void 0,void 0,(function*(){let s;if(null==e?void 0:e.trim().length)try{s=yield pn.fetchText(e,this.isDemo,this.examplespath,r)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e}`),t}else{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 0 0"),s=e.outerHTML}this.logDebug("IMAGE",`${i} (setting image: ${e})`);const a="g"===t.svgElement.nodeName?t.svgElement:document.createElement("div");a.innerHTML=s;const o=a.querySelector("svg"),c=Number.parseFloat(o.getAttribute("height")),l=Number.parseFloat(o.getAttribute("width"));if(o.getAttribute("viewBox")||o.setAttribute("viewBox",`0 0 ${l} ${c}`),o.id=t.svgElement.id,o.setAttribute("preserveAspectRatio","xMinYMin meet"),null!==t.originalBBox&&(o.setAttribute("height",t.originalBBox.height.toString()),o.setAttribute("width",t.originalBBox.width.toString()),o.setAttribute("x",t.originalBBox.x.toString()),o.setAttribute("y",t.originalBBox.y.toString())),"g"!==t.svgElement.nodeName){const e=t.svgElement.getAttribute("transform");e&&o.setAttribute("transform",e),t.svgElement=this.replaceElement(t.svgElement,o)}return this.attachClickHandlers(o,t,i,void 0,n),t.svgElement.onmouseover=()=>{this.handleEntityIdSetHoverOver(i,t)},o}))}_querySelectorAll(e,t=void 0,i){let n=t?Array.from(e.querySelectorAll(t).values()):[];return n=i?[e].concat(n):n,n}replaceElement(e,t){const i=e.parentElement;for(const i of Array.from(e.classList))t.classList.add(i);return this._querySelectorAll(e,"*",!0).forEach((e=>{Rn.off(e,"click"),Rn.off(e,"longClick"),e.remove()})),e.remove(),null==i||i.appendChild(t),t}initPageDisplay(){if(this.config.pages)for(const e of Object.values(this.pageInfos))e.svg.style.opacity="1",e.svg.style.display=e.isMaster||e.isDefault?"initial":"none";else this.svg.style.opacity="1",this.svg.style.display="block"}initVariables(){if(this.config.variables)for(const e of this.config.variables)this.initVariable(e);if(this.config.pages)for(const e of Object.values(this.pageInfos))if(e.config.variables)for(const t of e.config.variables)this.initVariable(t)}initVariable(e){let t,i;if("string"==typeof e?t=e:(t=e.name,i=e.value,e.value&&(i=this.evaluate(e.value,t,void 0))),!this.entityInfos[t]){const e={entityId:t,ruleInfos:[],lastState:void 0};this.entityInfos[t]=e}this.hass.states[t]||(this.hass.states[t]={entity_id:t,state:i,last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{},context:{}}),this.setVariable(t,i,{},!0)}getActionConfigs(e){var t,i;if(null==e)return[];if(Array.isArray(e)){for(const i of e)i.action=null!==(t=i.action)&&void 0!==t?t:"call-service";return e}return"object"==typeof e?(e.action=null!==(i=e.action)&&void 0!==i?i:"call-service",[e]):"string"==typeof e?e.includes(".")?[{action:"call-service",service:e}]:[{action:e}]:[]}initStartupActions(){if(this.handleActions(this.config.startup_action,void 0,void 0,void 0),this.config.pages)for(const e of Object.values(this.pageInfos))this.handleActions(e.config.startup_action,void 0,void 0,void 0)}initFloorplanRules(e,t){if(!t.rules)return;const i=this._querySelectorAll(e,"*",!0);for(const e of i)e.id&&(this.svgElements[e.id]=e);this.initRules(t,e,i)}initRules(e,t,i){if(e.functions&&(this.functions=this.evaluate(e.functions)),e.defaults){const t=e.defaults;for(const i of e.rules)i.hover_action=void 0===i.hover_action?t.hover_action:i.hover_action,i.tap_action=void 0===i.tap_action?t.tap_action:i.tap_action,i.hold_action=void 0===i.hold_action?t.hold_action:i.hold_action,i.hover_info_filter=void 0===i.hover_info_filter?t.hover_info_filter:i.hover_info_filter}for(const n of e.rules)n.entity||n.entities?this.initEntityRule(n,t,i):(n.element||n.elements)&&this.initElementRule(n,t,i)}initEntityRule(e,t,i){const n=this.initGetEntityRuleEntities(e);for(const r of n){const n=r.entityId;let s=this.entityInfos[n];s||(s={entityId:n,ruleInfos:[],lastState:void 0},this.entityInfos[n]=s);const a=new vn(e);s.ruleInfos.push(a);for(const e of r.elementIds){const r=i.find((t=>t.id===e));if(!r){this.logWarning("CONFIG",`Cannot find element '${e}' in SVG file`);continue}const o=this.addSvgElementToRule(t,r,a);o.svgElement=r,r.querySelector("title")||r.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.onmouseenter=()=>{this.handleEntitySetHoverOver(s,o)},r.onmouseleave=()=>{this.handleEntitySetHoverOver(s,o)},this.attachClickHandlers(r,o,n,void 0,a)}}}initGetEntityRuleEntities(e){const t=[];e.groups=e.groups?e.groups:[];for(const i of e.groups){const e=this.hass.states[i];if(e)for(const i of e.attributes.entity_id)this.addTargetEntity(i,[i],t);else this.logWarning("CONFIG",`Cannot find '${i}' in Home Assistant groups`)}e.entities=e.entities?e.entities:[],e.entities=e.entity?e.entities.concat(e.entity):e.entities;const i=e.entities.filter((e=>"string"==typeof e));for(const n of i){let i=[];e.elements?i=i.concat(e.elements):e.element?i=i.concat(this.evaluate(e.element,n,void 0)):null!==e.element&&(i=i.concat(n)),this.addTargetEntity(n,i,t)}const n=e.entities.filter((e=>"string"!=typeof e));for(const e of n){const i=e;this.addTargetEntity(i.entity,[i.element],t)}return t}addTargetEntity(e,t,i){const n=this.hass.states[e],r="floorplan"===e.split(".")[0];n||r?i.push({entityId:e,elementIds:t}):this.logWarning("CONFIG",`Cannot find '${e}' in Home Assistant entities`)}initElementRule(e,t,i){if(e.element||e.elements){e.elements=e.elements?e.elements:[],e.elements=e.element?e.elements.concat(e.element):e.elements;for(const n of e.elements){const r=i.find((e=>e.id===n));if(r){let i=this.elementInfos[n];i||(i={ruleInfos:[],lastState:void 0},this.elementInfos[n]=i);const s=new vn(e);i.ruleInfos.push(s);const a=this.addSvgElementToRule(t,r,s);this.attachClickHandlers(r,a,void 0,n,s)}else this.logWarning("CONFIG",`Cannot find '${n}' in SVG file`)}}}attachClickHandlers(e,t,i,n,r){this._querySelectorAll(e,void 0,!0).forEach((s=>{const a=s,o=s===e;if(a.querySelector("title")||a.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.rule.tap_action||r.rule.double_tap_action){const e=!!r.rule.tap_action&&this.getActionConfigs(r.rule.tap_action),s=!!r.rule.double_tap_action&&this.getActionConfigs(r.rule.double_tap_action),c=!!e&&new yn(this,i,n,t,r,e);if(e&&!s&&Rn.on(a,"click",this.onClick.bind(c)),s){const o=!!s&&new yn(this,i,n,t,r,s);Nn.observe(a),e&&Rn.on(a,"singleClick",this.onClick.bind(c)),Rn.on(a,"doubleClick",this.onLongClick.bind(o))}a.style&&(a.style.cursor="pointer"),pn.addClass(a,"floorplan-click"+(o?"":"-child"))}if(r.rule.hold_action){const e=this.getActionConfigs(r.rule.hold_action),s=new yn(this,i,n,t,r,e);Tn.observe(a),Rn.on(a,"longClick",this.onLongClick.bind(s)),a.style&&(a.style.cursor="pointer"),pn.addClass(a,"floorplan-long-click"+(o?"":"-child"))}}))}addSvgElementToRule(e,t,i){const n=t.getBBox?t.getBBox():null,r=new gn(t.id,t,t,n);return i.svgElementInfos[t.id]=r,r}createImageElement(e){const t=document.createElementNS("http://www.w3.org/2000/svg","image");return t.setAttribute("id",e.getAttribute("id")),t.setAttribute("x",e.getAttribute("x")),t.setAttribute("y",e.getAttribute("y")),t.setAttribute("height",e.getAttribute("height")),t.setAttribute("width",e.getAttribute("width")),t}handleEntities(e=!1){return $n(this,void 0,void 0,(function*(){this.handleElements();const t=this.getChangedEntities(e);for(const e of Object.keys(this.variables))t.add(e);if(t.size)for(const e of t)yield this.handleEntity(e)}))}getChangedEntities(e){const t=new Set,i=Object.keys(this.hass.states),n=pn.deviceId();for(const r of i)if(r!==`sensor.ha_floorplan_${n}`||t.has(r)){const i=this.entityInfos[r];if(i){const n=this.hass.states[r];if(e)this.logDebug("STATE",`${r}: ${n.state} (initial load)`),t.has(r)||t.add(r);else if(i.lastState){const e=n.state;n.last_changed!==i.lastState.last_changed?(this.logDebug("STATE",`${r}: ${e} (last changed ${pn.formatDate(i.lastState.last_changed)})`),t.has(r)||t.add(r)):pn.equal(i.lastState.attributes,n.attributes)||(this.logDebug("STATE",`${r}: attributes (last updated ${pn.formatDate(i.lastState.last_changed)})`),t.has(r)||t.add(r))}}}else t.add(r);return t}handleEntity(e){return $n(this,void 0,void 0,(function*(){const t=this.hass.states[e],i=this.entityInfos[e];if(i){i.lastState=Object.assign({},t);for(const e of i.ruleInfos){const t=Object.values(e.svgElementInfos);if(t.length)for(const n of t)n.svgElement&&this.handleActions(e.rule.state_action,i.entityId,n,e);else this.handleActions(e.rule.state_action,i.entityId,void 0,e)}}}))}handleElements(){return $n(this,void 0,void 0,(function*(){for(const e of Object.values(this.elementInfos))for(const t of e.ruleInfos)for(const e of Object.values(t.svgElementInfos))this.handleActions(t.rule.state_action,void 0,e,t)}))}handleEntityIdSetHoverOver(e,t){const i=this.entityInfos[e];i&&this.handleEntitySetHoverOver(i,t)}handleEntitySetHoverOver(e,t){const i=e.entityId,n=this.hass.states[i];for(const i of e.ruleInfos)if(i.rule.hover_action){let r="string"==typeof i.rule.hover_action&&"hover-info"===i.rule.hover_action;if(r=r||"object"==typeof i.rule.hover_action&&"hover-info"===i.rule.hover_action.action,r=r||Array.isArray(i.rule.hover_action)&&i.rule.hover_action.some((e=>"hover-info"===e.action)),r){const e=new Set(i.rule.hover_info_filter);for(const t of Object.values(i.svgElementInfos))pn.addClass(t.svgElement,"floorplan-hover"),t.svgElement.style.cursor="pointer",t.svgElement.querySelectorAll("title").forEach((t=>{let i=`${n.attributes.friendly_name}\n`;i+=`State: ${n.state}\n\n`,Object.keys(n.attributes).map((t=>{e.has(t)||(i+=`${t}: ${n.attributes[t]}\n`)})),i+="\n",i+=`Last changed: ${ye.timeago(n.last_changed)}\n`,i+=`Last updated: ${ye.timeago(n.last_updated)}`,t.textContent=i}))}else i.rule.hover_action&&this.handleActions(i.rule.hover_action,e.entityId,t,i)}}isOptionEnabled(e){return null===e||void 0!==e}validateConfig(e){let t=!0;if(e.pages||e.rules)if(e.pages)e.pages.length||this.logWarning("CONFIG","The 'pages' section must contain one or more pages in floorplan configuration");else{e.rules||this.logWarning("CONFIG","Cannot find 'rules' in floorplan configuration");let i=e.rules.filter((e=>e.entities&&e.elements));i.length&&(this.logError("CONFIG","A rule cannot contain both 'entities' and 'elements' in floorplan configuration"),t=!1),i=e.rules.filter((e=>!(e.entity||e.entities||e.element||e.elements))),i.length&&(this.logError("CONFIG","A rule must contain either 'entities' or 'elements' in floorplan configuration"),t=!1)}else this.logWarning("CONFIG","Cannot find 'pages' nor 'rules' in floorplan configuration");return t}evaluate(e,t,i){if("string"!=typeof e||!Mn.isCode(e))return e;try{return Mn.evaluate(e,this.hass,this.config,t,i,this.svgElements,this.functions)}catch(n){return this.handleError(n,{expression:e,entityId:t,hass:this.hass,svgElement:i})}}onClick(e){e.stopPropagation(),e.preventDefault();const t=this;t.instance.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}onLongClick(e){e.stopPropagation(),e.preventDefault();const t=this,i=t.instance;setTimeout((()=>{i.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}),300)}handleActions(e,t,i,n){var r;const s=this.getActionConfigs(e);for(const e of s){if(e.confirmation&&(!e.confirmation.exemptions||!e.confirmation.exemptions.some((e=>e.user===this.hass.user.id)))&&!confirm(e.confirmation.text||`Are you sure you want to ${e.action}?`))return;switch(e.action){case"more-info":this.isDemo?this.notify(`Performing action: ${e.action} ${t}`):fn(this,"hass-more-info",{entityId:t});break;case"navigate":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.navigation_path}`);else{const n=this.evaluate(e.navigation_path,t,null==i?void 0:i.svgElement);mn(0,n,null!==(r=e.navigation_replace)&&void 0!==r&&r)}break;case"url":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.url_path}`);else{const n=e.same_tab?"_self":"_blank",r=this.evaluate(e.url_path,t,null==i?void 0:i.svgElement);window.open(r,n)}break;case"toggle":if(t){const e={action:"call-service",service:"homeassistant.toggle",service_data:{entity_id:t}};this.callService(e,t,i,n)}break;case"call-service":if(!e.service)return;this.callService(e,t,i,n);break;case"fire-dom-event":fn(this,"ll-custom",e)}}}getSvgElementsFromServiceData(e,t){let i=[],n=[];if(Array.isArray(null==e?void 0:e.elements)&&(n=n.concat(null==e?void 0:e.elements)),"string"==typeof(null==e?void 0:e.element)&&(n=n.concat([null==e?void 0:e.element])),n.length)for(const e of n)i=i.concat(this._querySelectorAll(this.svg,`#${e.replace(/\./g,"\\.")}`,!1));else t&&(i=[t]);return i}getServiceData(e,t,i){let n={};if("object"==typeof e.service_data)for(const r of Object.keys(e.service_data))n[r]=this.evaluate(e.service_data[r],t,i);else if("string"==typeof e.service_data){const r=this.evaluate(e.service_data,t,i);n="string"==typeof r&&r.trim().startsWith("{")?JSON.parse(r):r}else void 0!==e.service_data&&(n=e.service_data);return n}executeServiceData(e,t,i){try{if("object"==typeof e.service_data)for(const n of Object.keys(e.service_data))this.evaluate(e.service_data[n],t,i);else"string"==typeof e.service_data?this.evaluate(e.service_data,t,i):void 0!==e.service_data&&this.logWarning("CONFIG","Invalid execution data");return!0}catch(e){return this.logWarning("CONFIG","Error thrown while executing service"),!1}}callService(e,t,i,n){const r=this.evaluate(e.service,t,null==i?void 0:i.svgElement),[s,a]=r.split(".",2);if("floorplan"===s)this.callFloorplanService(s,a,e,t,i,n);else this.callHomeAssistantService(s,a,e,t,i)}callFloorplanService(e,t,i,n,r,s){var a,o,c;const l=null!==(a=null==r?void 0:r.svgElement)&&void 0!==a?a:void 0;let h,u,p,d,f,m,g,v,y,b=[],x=null;switch(x=!["execute"].includes(t)?this.getServiceData(i,n,l):{},t){case"class_toggle":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),p="string"==typeof x?x:x.class,pn.toggleClass(e,p);break;case"class_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),p="string"==typeof x?x:x.class,pn.setClass(e,p);break;case"dataset_set":{let e,t;if("string"==typeof x){const i=x.split(":");if(i.length<2){this.logError("FLOORPLAN_ACTION",`Service data "${x}" is not a valid dataset key value pair.`);break}e=i[1],t=i[0]}else e=x.value,t=x.key;b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const s of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,s)),pn.datasetSet(s,t,e);break}case"style_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),d="string"==typeof x?x:x.style,pn.setStyle(e,d);break;case"text_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b){y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(i,n,e)),v="string"==typeof x?x:x.text;const t=(null===(o=i.service_data)||void 0===o?void 0:o.shift_y_axis)?null===(c=i.service_data)||void 0===c?void 0:c.shift_y_axis:"1em";pn.setText(e,v,t)}break;case"image_set":r&&s&&(x=this.getServiceData(i,n,null==r?void 0:r.svgElement),f="string"==typeof x?x:x.image,m="object"==typeof x?x.image_refresh_interval:0,g=!(m>0)&&("object"!=typeof x||!0===x.cache),s.imageLoader&&clearInterval(s.imageLoader),m&&(s.imageLoader=setInterval(this.loadImage.bind(this),1e3*m,f,r,n,s,g)),this.loadImage(f,r,n,s,g));break;case"page_navigate":x=this.getServiceData(i,n,null==r?void 0:r.svgElement),h=x.page_id,u=h?this.pageInfos[h]:void 0,u&&(Object.keys(this.pageInfos).map((e=>{const t=this.pageInfos[e];t.isMaster||"none"===t.svg.style.display||(t.svg.style.display="none")})),u.svg.style.display="block");break;case"variable_set":if(x=this.getServiceData(i,n,null==r?void 0:r.svgElement),x.variable){const e={};if(x.attributes){const t=x.attributes;for(const i of Object.keys(t))e[i]=this.getActionValue(t[i],n,l)}const t=x,i=this.getActionValue(t,n,l);this.setVariable(x.variable,i,e,!1)}break;case"execute":this.executeServiceData(i,n,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||this.executeServiceData(i,n,e)}}getActionValue(e,t,i){let n=e.value;return e.value&&(n=this.evaluate(e.value,t,i)),n}setVariable(e,t,i,n){if(this.variables[e]=t,this.hass.states[e]){this.hass.states[e].state=t.toString();for(const t of Object.keys(i))this.hass.states[e].attributes[t]=i[t]}for(const e of Object.keys(this.variables)){const t=this.hass.states[e];t&&(t.last_changed=(new Date).toString())}n||this.handleEntities()}callHomeAssistantService(e,t,i,n,r){const s=this.getServiceData(i,n,null==r?void 0:r.svgElement);"object"==typeof s&&(null===s.entity_id||Array.isArray(s.entity_id)&&!s.entity_id.length||!s.entity_id&&n&&(s.entity_id=n)),this.hass.callService(e,t,s),this.isDemo&&this.notify(`Calling service: ${e}.${t} (${s.entity_id})`)}handleWindowError(e,t,i,n,r){if(e.toLowerCase().includes("script error"))this.logError("SCRIPT","Script error: See browser console for detail");else{const s=[e,"URL: "+t,"Line: "+i+", column: "+n,"Error: "+JSON.stringify(r)].join("
");this.logError("ERROR",s)}return!1}handleError(e,t){console.error(e,t);let i="Error";"string"==typeof e&&(i=e),e.message?i=`${e.message} (See console for more info)`:e.stack&&(i=`${e.stack}`),this.logger.log("error",i)}logError(e,t){this.logger.log("error",`${e} ${t}`)}logWarning(e,t){this.logger.log("warning",`${e} ${t}`)}logInfo(e,t){this.logger.log("info",`${e} ${t}`)}logDebug(e,t){this.logger.log("debug",`${e} ${t}`)}};Dn([ae({type:String})],jn.prototype,"examplespath",void 0),Dn([ae({type:Object})],jn.prototype,"hass",void 0),Dn([ae({type:String||Object})],jn.prototype,"_config",void 0),Dn([ae({type:Boolean})],jn.prototype,"isDemo",void 0),Dn([ae({type:Boolean})],jn.prototype,"isShowLog",void 0),Dn([ae({type:Function})],jn.prototype,"notify",void 0),jn=Dn([re("floorplan-element")],jn); /** * @license * Copyright 2017 Google LLC diff --git a/dist/floorplan.js b/dist/floorplan.js index 78208174..3b4f9f9a 100644 --- a/dist/floorplan.js +++ b/dist/floorplan.js @@ -51,7 +51,7 @@ const re=e=>t=>"function"==typeof t?((e,t)=>(customElements.define(e,t),t))(e,t) */ var oe;null===(oe=window.HTMLSlotElement)||void 0===oe||oe.prototype.assignedElements;class ce{static closestElement(e,t){return function t(n){if(!n||n===document||n===window)return null;n.assignedSlot&&(n=n.assignedSlot);const i=n.closest(e);return i||t(n.getRootNode().host)}(t)}}const le=(e,t,n,i)=>{i=i||{},n=null==n?{}:n;const r=new Event(t,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return r.detail=n,e.dispatchEvent(r),r},he=(e,t,n=!1)=>{n?history.replaceState(null,"",t):history.pushState(null,"",t),le(window,"location-changed",{replace:n})};class ue{constructor(e,t,n,i){this.entityId=e,this.svgElement=t,this.originalSvgElement=n,this.originalBBox=i}}class pe{constructor(e){this.rule=e,this.svgElementInfos={}}}class de{constructor(e,t,n,i,r,s){this.instance=e,this.entityId=t,this.elementId=n,this.svgElementInfo=i,this.ruleInfo=r,this.actions=s}}const fe={},ge={};ge.click=ge.mousedown=ge.mouseup=ge.mousemove="MouseEvents";let me=1;function ve(e){return e._dtId||(e._dtId=me++)}function ye(e){const t=e.indexOf(".");return t>0?{e:e.substring(0,e.indexOf(".")),ns:e.substring(t+1,e.length)}:{e}}function be(e,t,n,i){const r=ye(n).e;if(!e._dtId)return!1;const s=fe[ve(e)],a=function(e,t,n,i){return n=ye(n),(fe[ve(e)]||[]).filter((e=>e&&(!n.e||e.e===n.e)&&(!n.ns||e.ns===n.ns)&&(!i||e.callback===i)&&(!t||e.selector===t)))}(e,t,n,i);a.forEach((t=>{e.removeEventListener?e.removeEventListener(r,t.delegator||t.callback):e.detachEvent&&e.detachEvent("on"+r,t.delegator||t.callback),s.splice(s.indexOf(t),1)}))}function xe(e,t,n,i,r,s){const a=ye(n).e,o=ye(n).ns;e.addEventListener?e.addEventListener(a,r||i,s):e.attachEvent&&e.attachEvent("on"+a,r||i);const c=ve(e);(fe[c]||(fe[c]=[])).push({delegator:r,callback:i,e:a,ns:o,selector:t})}const we={on(e,t,n,i=null){xe(e,null,t,n,null,i)},off(e,t,n=null){be(e,null,t,n)},once(e,t,n){const i=e=>(we.off(e.currentTarget,e.type,i),n(e));this.on(e,t,i)},delegate(e,t,n,i,r=null){xe(e,t,n,i,(function(n){const r=e.querySelectorAll(t);let s=!1;for(let e=0;e{n=!1,t=setTimeout((()=>{n=!0,e.dispatchEvent(new Event("longClick"))}),400)},r=i=>{clearTimeout(t),n||e.dispatchEvent(new Event("short"+i.type[0].toUpperCase()+i.type.slice(1)))},s=e=>{n&&(e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation())};_e.on(e,"mousedown",i.bind(this)),_e.on(e,"tapstart",i.bind(this)),_e.on(e,"touchstart",i.bind(this),{passive:!0}),_e.on(e,"click",r.bind(this)),_e.on(e,"mouseup",r.bind(this)),_e.on(e,"tapend",r.bind(this)),_e.on(e,"touchend",r.bind(this)),_e.on(e,"tap",s.bind(this)),_e.on(e,"touch",s.bind(this)),_e.on(e,"mouseup",s.bind(this)),_e.on(e,"tapend",s.bind(this)),_e.on(e,"touchend",s.bind(this)),_e.on(e,"click",(e=>{e.preventDefault(),e.stopImmediatePropagation&&e.stopImmediatePropagation()}).bind(this))}}const Ee=Se,Ae=new Set;class Ce{static observe(e){if(Ae.has(e))return;Ae.add(e);let t,n=0;Ee.on(e,"click",(()=>{n++,t=setTimeout((()=>{1===n&&(n=0,e.dispatchEvent(new Event("singleClick")))}),400),2===n&&(clearTimeout(t),n=0,e.dispatchEvent(new Event("doubleClick")))}).bind(this))}}var Ie,Te=n(1),Pe=n.n(Te);class Me{static timeago(e){let t="second",n=0;const i=("string"==typeof e?new Date(e):e).getTime()-(new Date).getTime(),r=i/this.MILLISECONDS_IN_YEAR;if(Math.abs(r)>=1)t="year",n=r;else{const e=i/this.MILLISECONDS_IN_DAY;if(Math.abs(e)>=1)t="day",n=e;else{const e=i/this.MILLISECONDS_IN_HOUR;if(Math.abs(e)>=1)t="hour",n=e;else{const e=i/this.MILLISECONDS_IN_MINUTE;if(Math.abs(e)>=1)t="minute",n=e;else{t="second",n=i/this.MILLISECONDS_IN_SECOND}}}}return this.relativeTimeFormat.format(Math.round(n),t)}}Me.strftime=Pe(),Me.MILLISECONDS_IN_SECOND=1e3,Me.MILLISECONDS_IN_MINUTE=6e4,Me.MILLISECONDS_IN_HOUR=36e5,Me.MILLISECONDS_IN_DAY=864e5,Me.MILLISECONDS_IN_YEAR=31536e6,Me.relativeTimeFormat=new Intl.RelativeTimeFormat(null!==(Ie=navigator.language)&&void 0!==Ie?Ie:"en",{numeric:"auto",style:"long"});var Ne=n(449),Oe=n.n(Ne);function Le(e){return(e=>{if("object"==typeof(t=e)&&null!==t&&"message"in t&&"string"==typeof t.message)return e;var t;try{return new Error(JSON.stringify(e))}catch(t){return new Error(String(e))}})(e).message}class De{static isCode(e){return this.isCodeBlock(e)||this.isCodeLine(e)}static isCodeBlock(e){return e.trim().startsWith(">")}static isCodeLine(e){return e.includes("${")&&e.includes("}")}static evaluate(e,t,n,i,r,s,a){this.expression=e.trim();const o=`${this.expression}_${null!=r?r:""}`;this.parsedFunction=this.cache[o],void 0===this.parsedFunction&&(this.functionBody=this.expression,this.isCodeBlock(this.functionBody)?this.functionBody=this.functionBody.slice(1).trim():this.isCodeLine(this.functionBody)&&(this.functionBody.startsWith('"')&&this.functionBody.endsWith('"')&&(this.functionBody=this.functionBody.slice(1,this.functionBody.length-2)),this.functionBody=this.functionBody.replace(/\\"/g,'"'),this.functionBody=`\`${this.functionBody}\`;`,this.functionBody.includes("return")||(this.functionBody=`return ${this.functionBody}`)),this.parsedFunction=this.interpreter.parse(`exports.result = (() => { ${this.functionBody} })();`),this.cache[o]=this.parsedFunction,this.interpreter.import("config",n),this.interpreter.import("util",this.util)),this.entityState=i?t.states[i]:void 0,this.interpreter.import("functions",a),this.interpreter.import("entity",this.entityState),this.interpreter.import("entities",t.states),this.interpreter.import("states",t.states),this.interpreter.import("hass",t),this.interpreter.import("element",r),this.interpreter.import("elements",s);try{this.interpreter.run(this.parsedFunction)}catch(e){throw new EvalError(Le(e))}return this.interpreter.exports.result}} /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ -function Re(e){return null==e}De.cache={},De.interpreter=new(Oe())({ecmaVer:2019,sandBox:!0}),De.util={color:class{static miredToRGB(e){return this.kelvinToRGB(1e6/e)}static kelvinToRGB(e){const t=e/100;let n,i,r;return t<=66?(n=255,i=t,i=99.4708025861*Math.log(i)-161.1195681661,t<=19?r=0:(r=t-10,r=138.5177312231*Math.log(r)-305.0447927307)):(n=t-60,n=329.698727446*Math.pow(n,-.1332047592),i=t-60,i=288.1221695283*Math.pow(i,-.0755148492),r=255),[Math.min(Math.max(Math.round(n),0),255),Math.min(Math.max(Math.round(i),0),255),Math.min(Math.max(Math.round(r),0),255)]}},date:Me};var $e={isNothing:Re,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:Re(e)?[]:[e]},repeat:function(e,t){var n,i="";for(n=0;no&&(t=i-o+(s=" ... ").length),n-i>o&&(n=i+o-(a=" ...").length),{str:s+e.slice(t,n).replace(/\t/g,"→")+a,pos:i-t+s.length}}function Ue(e,t){return $e.repeat(" ",t-e.length)+e}var He=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n,i=/\r?\n|\r|\0/g,r=[0],s=[],a=-1;n=i.exec(e.buffer);)s.push(n.index),r.push(n.index+n[0].length),e.position<=n.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var o,c,l="",h=Math.min(e.line+t.linesAfter,s.length).toString().length,u=t.maxLength-(t.indent+h+3);for(o=1;o<=t.linesBefore&&!(a-o<0);o++)c=Fe(e.buffer,r[a-o],s[a-o],e.position-(r[a]-r[a-o]),u),l=$e.repeat(" ",t.indent)+Ue((e.line-o+1).toString(),h)+" | "+c.str+"\n"+l;for(c=Fe(e.buffer,r[a],s[a],e.position,u),l+=$e.repeat(" ",t.indent)+Ue((e.line+1).toString(),h)+" | "+c.str+"\n",l+=$e.repeat("-",t.indent+h+3+c.pos)+"^\n",o=1;o<=t.linesAfter&&!(a+o>=s.length);o++)c=Fe(e.buffer,r[a+o],s[a+o],e.position-(r[a]-r[a+o]),u),l+=$e.repeat(" ",t.indent)+Ue((e.line+o+1).toString(),h)+" | "+c.str+"\n";return l.replace(/\n$/,"")},qe=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],ze=["scalar","sequence","mapping"];var We=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===qe.indexOf(t))throw new je('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}(t.styleAliases||null),-1===ze.indexOf(this.kind))throw new je('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function Ye(e,t){var n=[];return e[t].forEach((function(e){var t=n.length;n.forEach((function(n,i){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=i)})),n[t]=e})),n}function Ge(e){return this.extend(e)}Ge.prototype.extend=function(e){var t=[],n=[];if(e instanceof We)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new je("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof We))throw new je("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new je("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new je("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),n.forEach((function(e){if(!(e instanceof We))throw new je("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var i=Object.create(Ge.prototype);return i.implicit=(this.implicit||[]).concat(t),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=Ye(i,"implicit"),i.compiledExplicit=Ye(i,"explicit"),i.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function i(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),at=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var ot=/^[-+]?[0-9]+e/;var ct=new We("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!at.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||$e.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if($e.isNegativeZero(e))return"-0.0";return n=e.toString(10),ot.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"}),lt=Ze.extend({implicit:[et,tt,st,ct]}),ht=lt,ut=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),pt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var dt=new We("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==ut.exec(e)||null!==pt.exec(e))},construct:function(e){var t,n,i,r,s,a,o,c,l=0,h=null;if(null===(t=ut.exec(e))&&(t=pt.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(s=+t[4],a=+t[5],o=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(h=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(h=-h)),c=new Date(Date.UTC(n,i,r,s,a,o,l)),h&&c.setTime(c.getTime()-h),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var ft=new We("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),gt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var mt=new We("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=0,r=e.length,s=gt;for(n=0;n64)){if(t<0)return!1;i+=6}return i%8==0},construct:function(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,s=gt,a=0,o=[];for(t=0;t>16&255),o.push(a>>8&255),o.push(255&a)),a=a<<6|s.indexOf(i.charAt(t));return 0===(n=r%4*6)?(o.push(a>>16&255),o.push(a>>8&255),o.push(255&a)):18===n?(o.push(a>>10&255),o.push(a>>2&255)):12===n&&o.push(a>>4&255),new Uint8Array(o)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,i="",r=0,s=e.length,a=gt;for(t=0;t>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+e[t];return 0===(n=s%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}}),vt=Object.prototype.hasOwnProperty,yt=Object.prototype.toString;var bt=new We("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,s,a=[],o=e;for(t=0,n=o.length;t>10),56320+(e-65536&1023))}for(var Gt=new Array(256),Jt=new Array(256),Xt=0;Xt<256;Xt++)Gt[Xt]=Wt(Xt)?1:0,Jt[Xt]=Wt(Xt);function Kt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||kt,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Qt(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=He(n),new je(t,n)}function Zt(e,t){throw Qt(e,t)}function en(e,t){e.onWarning&&e.onWarning.call(null,Qt(e,t))}var tn={YAML:function(e,t,n){var i,r,s;null!==e.version&&Zt(e,"duplication of %YAML directive"),1!==n.length&&Zt(e,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&Zt(e,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),s=parseInt(i[2],10),1!==r&&Zt(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=s<2,1!==s&&2!==s&&en(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var i,r;2!==n.length&&Zt(e,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],Rt.test(i)||Zt(e,"ill-formed tag handle (first argument) of the TAG directive"),Et.call(e.tagMap,i)&&Zt(e,'there is a previously declared suffix for "'+i+'" tag handle'),$t.test(r)||Zt(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){Zt(e,"tag prefix is malformed: "+r)}e.tagMap[i]=r}};function nn(e,t,n,i){var r,s,a,o;if(t1&&(e.result+=$e.repeat("\n",t-1))}function hn(e,t){var n,i,r=e.tag,s=e.anchor,a=[],o=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),i=e.input.charCodeAt(e.position);0!==i&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Zt(e,"tab characters must not be used in indentation")),45===i)&&Ft(e.input.charCodeAt(e.position+1));)if(o=!0,e.position++,on(e,!0,-1)&&e.lineIndent<=t)a.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,dn(e,t,It,!1,!0),a.push(e.result),on(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)Zt(e,"bad indentation of a sequence entry");else if(e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt)&&(v&&(a=e.line,o=e.lineStart,c=e.position),dn(e,t,Tt,!0,r)&&(v?g=e.result:m=e.result),v||(sn(e,p,d,f,g,m,a,o,c),f=g=m=null),on(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===s||e.lineIndent>t)&&0!==l)Zt(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===r?Zt(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?Zt(e,"repeat of an indentation width identifier"):(l=t+r-1,c=!0)}if(jt(s)){do{s=e.input.charCodeAt(++e.position)}while(jt(s));if(35===s)do{s=e.input.charCodeAt(++e.position)}while(!Bt(s)&&0!==s)}for(;0!==s;){for(an(e),e.lineIndent=0,s=e.input.charCodeAt(e.position);(!c||e.lineIndentl&&(l=e.lineIndent),Bt(s))h++;else{if(e.lineIndent0){for(r=a,s=0;r>0;r--)(a=Ht(o=e.input.charCodeAt(++e.position)))>=0?s=(s<<4)+a:Zt(e,"expected hexadecimal character");e.result+=Yt(s),e.position++}else Zt(e,"unknown escape sequence");n=i=e.position}else Bt(o)?(nn(e,n,i,!0),ln(e,on(e,!1,t)),n=i=e.position):e.position===e.lineStart&&cn(e)?Zt(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}Zt(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?m=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!Ft(i)&&!Ut(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&Zt(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),Et.call(e.anchorMap,n)||Zt(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],on(e,!0,-1),!0}(e)?function(e,t,n){var i,r,s,a,o,c,l,h,u=e.kind,p=e.result;if(Ft(h=e.input.charCodeAt(e.position))||Ut(h)||35===h||38===h||42===h||33===h||124===h||62===h||39===h||34===h||37===h||64===h||96===h)return!1;if((63===h||45===h)&&(Ft(i=e.input.charCodeAt(e.position+1))||n&&Ut(i)))return!1;for(e.kind="scalar",e.result="",r=s=e.position,a=!1;0!==h;){if(58===h){if(Ft(i=e.input.charCodeAt(e.position+1))||n&&Ut(i))break}else if(35===h){if(Ft(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&cn(e)||n&&Ut(h))break;if(Bt(h)){if(o=e.line,c=e.lineStart,l=e.lineIndent,on(e,!1,-1),e.lineIndent>=t){a=!0,h=e.input.charCodeAt(e.position);continue}e.position=s,e.line=o,e.lineStart=c,e.lineIndent=l;break}}a&&(nn(e,r,s,!1),ln(e,e.line-o),r=s=e.position,a=!1),jt(h)||(s=e.position+1),h=e.input.charCodeAt(++e.position)}return nn(e,r,s,!1),!!e.result||(e.kind=u,e.result=p,!1)}(e,p,At===n)&&(m=!0,null===e.tag&&(e.tag="?")):(m=!0,null===e.tag&&null===e.anchor||Zt(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===f&&(m=o&&hn(e,d))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Zt(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),c=0,l=e.implicitTypes.length;c"),null!==e.result&&u.kind!==e.kind&&Zt(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+u.kind+'", not "'+e.kind+'"'),u.resolve(e.result,e.tag)?(e.result=u.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Zt(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function fn(e){var t,n,i,r,s=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(on(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Ft(r);)r=e.input.charCodeAt(++e.position);for(i=[],(n=e.input.slice(t,e.position)).length<1&&Zt(e,"directive name must not be less than one character in length");0!==r;){for(;jt(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!Bt(r));break}if(Bt(r))break;for(t=e.position;0!==r&&!Ft(r);)r=e.input.charCodeAt(++e.position);i.push(e.input.slice(t,e.position))}0!==r&&an(e),Et.call(tn,n)?tn[n](e,n,i):en(e,'unknown document directive "'+n+'"')}on(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,on(e,!0,-1)):a&&Zt(e,"directives end mark is expected"),dn(e,e.lineIndent-1,Tt,!1,!0),on(e,!0,-1),e.checkLineBreaks&&Lt.test(e.input.slice(s,e.position))&&en(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&cn(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,on(e,!0,-1)):e.position=55296&&i<=56319&&t+1=56320&&n<=57343?1024*(i-55296)+n-56320+65536:i}function ri(e){return/^\n* /.test(e)}var si=1,ai=2,oi=3,ci=4,li=5;function hi(e,t,n,i,r,s,a,o){var c,l=0,h=null,u=!1,p=!1,d=-1!==i,f=-1,g=function(e){return ei(e)&&e!==bn&&!Zn(e)&&e!==Nn&&e!==Rn&&e!==On&&e!==Mn&&e!==Vn&&e!==Bn&&e!==Fn&&e!==Hn&&e!==An&&e!==In&&e!==Pn&&e!==kn&&e!==Un&&e!==Ln&&e!==Dn&&e!==Tn&&e!==En&&e!==Cn&&e!==$n&&e!==jn}(ii(e,0))&&function(e){return!Zn(e)&&e!==On}(ii(e,e.length-1));if(t||a)for(c=0;c=65536?c+=2:c++){if(!ei(l=ii(e,c)))return li;g=g&&ni(l,h,o),h=l}else{for(c=0;c=65536?c+=2:c++){if((l=ii(e,c))===wn)u=!0,d&&(p=p||c-f-1>i&&" "!==e[f+1],f=c);else if(!ei(l))return li;g=g&&ni(l,h,o),h=l}p=p||d&&c-f-1>i&&" "!==e[f+1]}return u||p?n>9&&ri(e)?li:a?s===Jn?li:ai:p?ci:oi:!g||a||r(e)?s===Jn?li:ai:si}function ui(e,t,n,i,r){e.dump=function(){if(0===t.length)return e.quotingType===Jn?'""':"''";if(!e.noCompatMode&&(-1!==zn.indexOf(t)||Wn.test(t)))return e.quotingType===Jn?'"'+t+'"':"'"+t+"'";var s=e.indent*Math.max(1,n),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-s),o=i||e.flowLevel>-1&&n>=e.flowLevel;switch(hi(t,o,e.indent,a,(function(t){return function(e,t){var n,i;for(n=0,i=e.implicitTypes.length;n"+pi(t,e.indent)+di(Kn(function(e,t){var n,i,r=/(\n+)([^\n]*)/g,s=(o=e.indexOf("\n"),o=-1!==o?o:e.length,r.lastIndex=o,fi(e.slice(0,o),t)),a="\n"===e[0]||" "===e[0];var o;for(;i=r.exec(e);){var c=i[1],l=i[2];n=" "===l[0],s+=c+(a||n||""===l?"":"\n")+fi(l,t),a=n}return s}(t,a),s));case li:return'"'+function(e){for(var t,n="",i=0,r=0;r=65536?r+=2:r++)i=ii(e,r),!(t=qn[i])&&ei(i)?(n+=e[r],i>=65536&&(n+=e[r+1])):n+=t||Yn(i);return n}(t)+'"';default:throw new je("impossible error: invalid scalar style")}}()}function pi(e,t){var n=ri(e)?String(t):"",i="\n"===e[e.length-1];return n+(i&&("\n"===e[e.length-2]||"\n"===e)?"+":i?"":"-")+"\n"}function di(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function fi(e,t){if(""===e||" "===e[0])return e;for(var n,i,r=/ [^ ]/g,s=0,a=0,o=0,c="";n=r.exec(e);)(o=n.index)-s>t&&(i=a>s?a:o,c+="\n"+e.slice(s,i),s=i+1),a=o;return c+="\n",e.length-s>t&&a>s?c+=e.slice(s,a)+"\n"+e.slice(a+1):c+=e.slice(s),c.slice(1)}function gi(e,t,n,i){var r,s,a,o="",c=e.tag;for(r=0,s=n.length;r tag resolver accepts not "'+c+'" style');i=o.represent[c](t,c)}e.dump=i}return!0}return!1}function vi(e,t,n,i,r,s,a){e.tag=null,e.dump=n,mi(e,n,!1)||mi(e,n,!0);var o,c=vn.call(e.dump),l=i;i&&(i=e.flowLevel<0||e.flowLevel>t);var h,u,p="[object Object]"===c||"[object Array]"===c;if(p&&(u=-1!==(h=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||u||2!==e.indent&&t>0)&&(r=!1),u&&e.usedDuplicates[h])e.dump="*ref_"+h;else{if(p&&u&&!e.usedDuplicates[h]&&(e.usedDuplicates[h]=!0),"[object Object]"===c)i&&0!==Object.keys(e.dump).length?(!function(e,t,n,i){var r,s,a,o,c,l,h="",u=e.tag,p=Object.keys(n);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new je("sortKeys must be a boolean or a function");for(r=0,s=p.length;r1024)&&(e.dump&&wn===e.dump.charCodeAt(0)?l+="?":l+="? "),l+=e.dump,c&&(l+=Qn(e,t)),vi(e,t+1,o,!0,c)&&(e.dump&&wn===e.dump.charCodeAt(0)?l+=":":l+=": ",h+=l+=e.dump));e.tag=u,e.dump=h||"{}"}(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,n){var i,r,s,a,o,c="",l=e.tag,h=Object.keys(n);for(i=0,r=h.length;i1024&&(o+="? "),o+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),vi(e,t,a,!1,!1)&&(c+=o+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),u&&(e.dump="&ref_"+h+" "+e.dump));else if("[object Array]"===c)i&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?gi(e,t-1,e.dump,r):gi(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,n){var i,r,s,a="",o=e.tag;for(i=0,r=n.length;i",e.dump=o+" "+e.dump)}return!0}function yi(e,t){var n,i,r=[],s=[];for(bi(e,r,s),n=0,i=s.length;ne.trim())).filter((e=>e.length));for(let t=0;te.trim()));e.style.setProperty(i[0],i[1])}}static setText(e,t,n){e instanceof SVGTextElement||(e=e.querySelector("text")||e);const i=t.replace(/\\n/g,"\n").split("\n"),r=i.length>1,s=e.querySelector("tspan");if(r){const t=null==s?void 0:s.getAttribute("x"),r=null==s?void 0:s.getAttribute("y");t&&!e.getAttribute("x")&&e.setAttribute("x",t),r&&!e.getAttribute("y")&&e.setAttribute("y",r);const a=e.querySelector("tspan")||!1;e.textContent="",e.dataset.ha_floorplan_notice="The text_set function split your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on the basis of the first tspan or text-element.";const o=e.getAttribute("x")||"0",c=n||"1em";i.forEach(((t,n)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","tspan");if(i.textContent=t,i.setAttribute("x",o),i.setAttribute("dy",n>=1?c:"0"),a){const e=a.getAttribute("style");e&&i.setAttribute("style",e)}e.appendChild(i)}))}else{(s||e).textContent=t}}static waitForChildNodes(e,t,n){return new Promise(((i,r)=>{const s=setTimeout((()=>r("Timeout waiting for child element(s) to load")),n);new MutationObserver((e=>{for(const t of e)if("childList"===t.type&&t.addedNodes.length)return clearTimeout(s),i()})).observe(e,{childList:!0,subtree:!0}),t()}))}static formatDate(e){return e?"string"==typeof e?new Date(e).toLocaleString():e.toLocaleString():""}static parseYaml(e){return wi.load(e)}static fetchText(e,t,n,i){return Si(this,void 0,void 0,(function*(){n&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${n}/`)),e=i?e:_i.cacheBuster(e);const r=new Request(e,{cache:i?"default":"no-store",mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){return yield e.text()}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static fetchImage(e,t,n,i){return Si(this,void 0,void 0,(function*(){t&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${n}/`)),e=i?e:_i.cacheBuster(e);const r=new Request(e,{cache:i?"default":"no-store",headers:new Headers({"Content-Type":"text/plain; charset=x-user-defined"}),mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){const t=yield e.arrayBuffer();return`data:image/jpeg;base64,${_i.arrayBufferToBase64(t)}`}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static singleToArray(e){return null==e?[]:Array.isArray(e)?e:[e]}static getArray(e){if(null==e)return[];if(Array.isArray(e))return e;{const t=e;return Object.values(t)}}static getSet(e){if(Array.isArray(e))return new Set(e);{const t=e;return new Set(Object.values(t))}}static arrayBufferToBase64(e){let t="";[].slice.call(new Uint8Array(e)).forEach((e=>t+=String.fromCharCode(e)));let n=window.btoa(t);for(;n.length%4>0;)n+="=";return n}static cacheBuster(e){return`${e}${e.includes("?")?"&":"?"}_=${(new Date).getTime()}`}static equal(e,t){if(e===t)return!0;const n=Array.isArray(e),i=Array.isArray(t);let r=0;if(n&&i){if(e.length!=t.length)return!1;for(r=0;rMath.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage[e]=`${t()}${t()}_${t()}${t()}`}return localStorage[e]}}class ki{constructor(e,t,n){this.element=e,this.logLevel=t,this.consoleLogLevel=n,this.logLevelGroups={error:["error"],warn:["error","warning","warn"],warning:["error","warning","warn"],info:["error","warning","warn","info"],debug:["error","warning","warn","info","debug"]}}log(e,t,n=!1){var i;const r=`${_i.formatDate(new Date)} ${e.toUpperCase()} ${t}`,s=this.logLevel&&this.logLevelGroups[this.logLevel.toLowerCase()],a=(null==s?void 0:s.length)&&s.includes(e.toLowerCase());if((n||a)&&this.element){const t=document.createElement("li");_i.addClass(t,e),t.textContent=r,null===(i=this.element.querySelector("ul"))||void 0===i||i.prepend(t),this.element.style.display="block"}this.consoleLog(e,t,n)}consoleLog(e,t,n=!1){const i=`${_i.formatDate(new Date)} ${e.toUpperCase()} ${t}`,r=this.consoleLogLevel&&this.logLevelGroups[this.consoleLogLevel.toLowerCase()],s=(null==r?void 0:r.length)&&r.includes(e.toLowerCase());if(n||s)switch(e){case"error":console.error(i);break;case"warn":case"warning":console.warn(i);break;case"info":console.info(i);break;default:console.log(i)}}}var Ei=function(e,t,n,i){var r,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,n,a):r(t,n))||a);return s>3&&a&&Object.defineProperty(t,n,a),a},Ai=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function a(e){try{c(i.next(e))}catch(e){s(e)}}function o(e){try{c(i.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,o)}c((i=i.apply(e,t||[])).next())}))};const Ci=Se;console.info("%cFloorplan for Home Assistant (ha-floorplan)%c\nVersion 1.0.41","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: rgb(71, 170, 238)");let Ii=class extends ne{constructor(){super(),this.pageInfos={},this.entityInfos={},this.elementInfos={},this.cssRules=[],this.functions={},this.variables={},this.svgElements={},this.isRulesLoaded=!1,window.onerror=this.handleWindowError.bind(this)}render(){return $` +function Re(e){return null==e}De.cache={},De.interpreter=new(Oe())({ecmaVer:2019,sandBox:!0}),De.util={color:class{static miredToRGB(e){return this.kelvinToRGB(1e6/e)}static kelvinToRGB(e){const t=e/100;let n,i,r;return t<=66?(n=255,i=t,i=99.4708025861*Math.log(i)-161.1195681661,t<=19?r=0:(r=t-10,r=138.5177312231*Math.log(r)-305.0447927307)):(n=t-60,n=329.698727446*Math.pow(n,-.1332047592),i=t-60,i=288.1221695283*Math.pow(i,-.0755148492),r=255),[Math.min(Math.max(Math.round(n),0),255),Math.min(Math.max(Math.round(i),0),255),Math.min(Math.max(Math.round(r),0),255)]}},date:Me};var $e={isNothing:Re,isObject:function(e){return"object"==typeof e&&null!==e},toArray:function(e){return Array.isArray(e)?e:Re(e)?[]:[e]},repeat:function(e,t){var n,i="";for(n=0;no&&(t=i-o+(s=" ... ").length),n-i>o&&(n=i+o-(a=" ...").length),{str:s+e.slice(t,n).replace(/\t/g,"→")+a,pos:i-t+s.length}}function Ue(e,t){return $e.repeat(" ",t-e.length)+e}var He=function(e,t){if(t=Object.create(t||null),!e.buffer)return null;t.maxLength||(t.maxLength=79),"number"!=typeof t.indent&&(t.indent=1),"number"!=typeof t.linesBefore&&(t.linesBefore=3),"number"!=typeof t.linesAfter&&(t.linesAfter=2);for(var n,i=/\r?\n|\r|\0/g,r=[0],s=[],a=-1;n=i.exec(e.buffer);)s.push(n.index),r.push(n.index+n[0].length),e.position<=n.index&&a<0&&(a=r.length-2);a<0&&(a=r.length-1);var o,c,l="",h=Math.min(e.line+t.linesAfter,s.length).toString().length,u=t.maxLength-(t.indent+h+3);for(o=1;o<=t.linesBefore&&!(a-o<0);o++)c=Fe(e.buffer,r[a-o],s[a-o],e.position-(r[a]-r[a-o]),u),l=$e.repeat(" ",t.indent)+Ue((e.line-o+1).toString(),h)+" | "+c.str+"\n"+l;for(c=Fe(e.buffer,r[a],s[a],e.position,u),l+=$e.repeat(" ",t.indent)+Ue((e.line+1).toString(),h)+" | "+c.str+"\n",l+=$e.repeat("-",t.indent+h+3+c.pos)+"^\n",o=1;o<=t.linesAfter&&!(a+o>=s.length);o++)c=Fe(e.buffer,r[a+o],s[a+o],e.position-(r[a]-r[a+o]),u),l+=$e.repeat(" ",t.indent)+Ue((e.line+o+1).toString(),h)+" | "+c.str+"\n";return l.replace(/\n$/,"")},qe=["kind","multi","resolve","construct","instanceOf","predicate","represent","representName","defaultStyle","styleAliases"],ze=["scalar","sequence","mapping"];var We=function(e,t){if(t=t||{},Object.keys(t).forEach((function(t){if(-1===qe.indexOf(t))throw new je('Unknown option "'+t+'" is met in definition of "'+e+'" YAML type.')})),this.options=t,this.tag=e,this.kind=t.kind||null,this.resolve=t.resolve||function(){return!0},this.construct=t.construct||function(e){return e},this.instanceOf=t.instanceOf||null,this.predicate=t.predicate||null,this.represent=t.represent||null,this.representName=t.representName||null,this.defaultStyle=t.defaultStyle||null,this.multi=t.multi||!1,this.styleAliases=function(e){var t={};return null!==e&&Object.keys(e).forEach((function(n){e[n].forEach((function(e){t[String(e)]=n}))})),t}(t.styleAliases||null),-1===ze.indexOf(this.kind))throw new je('Unknown kind "'+this.kind+'" is specified for "'+e+'" YAML type.')};function Ye(e,t){var n=[];return e[t].forEach((function(e){var t=n.length;n.forEach((function(n,i){n.tag===e.tag&&n.kind===e.kind&&n.multi===e.multi&&(t=i)})),n[t]=e})),n}function Ge(e){return this.extend(e)}Ge.prototype.extend=function(e){var t=[],n=[];if(e instanceof We)n.push(e);else if(Array.isArray(e))n=n.concat(e);else{if(!e||!Array.isArray(e.implicit)&&!Array.isArray(e.explicit))throw new je("Schema.extend argument should be a Type, [ Type ], or a schema definition ({ implicit: [...], explicit: [...] })");e.implicit&&(t=t.concat(e.implicit)),e.explicit&&(n=n.concat(e.explicit))}t.forEach((function(e){if(!(e instanceof We))throw new je("Specified list of YAML types (or a single Type object) contains a non-Type object.");if(e.loadKind&&"scalar"!==e.loadKind)throw new je("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");if(e.multi)throw new je("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.")})),n.forEach((function(e){if(!(e instanceof We))throw new je("Specified list of YAML types (or a single Type object) contains a non-Type object.")}));var i=Object.create(Ge.prototype);return i.implicit=(this.implicit||[]).concat(t),i.explicit=(this.explicit||[]).concat(n),i.compiledImplicit=Ye(i,"implicit"),i.compiledExplicit=Ye(i,"explicit"),i.compiledTypeMap=function(){var e,t,n={scalar:{},sequence:{},mapping:{},fallback:{},multi:{scalar:[],sequence:[],mapping:[],fallback:[]}};function i(e){e.multi?(n.multi[e.kind].push(e),n.multi.fallback.push(e)):n[e.kind][e.tag]=n.fallback[e.tag]=e}for(e=0,t=arguments.length;e=0?"0b"+e.toString(2):"-0b"+e.toString(2).slice(1)},octal:function(e){return e>=0?"0o"+e.toString(8):"-0o"+e.toString(8).slice(1)},decimal:function(e){return e.toString(10)},hexadecimal:function(e){return e>=0?"0x"+e.toString(16).toUpperCase():"-0x"+e.toString(16).toUpperCase().slice(1)}},defaultStyle:"decimal",styleAliases:{binary:[2,"bin"],octal:[8,"oct"],decimal:[10,"dec"],hexadecimal:[16,"hex"]}}),at=new RegExp("^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$");var ot=/^[-+]?[0-9]+e/;var ct=new We("tag:yaml.org,2002:float",{kind:"scalar",resolve:function(e){return null!==e&&!(!at.test(e)||"_"===e[e.length-1])},construct:function(e){var t,n;return n="-"===(t=e.replace(/_/g,"").toLowerCase())[0]?-1:1,"+-".indexOf(t[0])>=0&&(t=t.slice(1)),".inf"===t?1===n?Number.POSITIVE_INFINITY:Number.NEGATIVE_INFINITY:".nan"===t?NaN:n*parseFloat(t,10)},predicate:function(e){return"[object Number]"===Object.prototype.toString.call(e)&&(e%1!=0||$e.isNegativeZero(e))},represent:function(e,t){var n;if(isNaN(e))switch(t){case"lowercase":return".nan";case"uppercase":return".NAN";case"camelcase":return".NaN"}else if(Number.POSITIVE_INFINITY===e)switch(t){case"lowercase":return".inf";case"uppercase":return".INF";case"camelcase":return".Inf"}else if(Number.NEGATIVE_INFINITY===e)switch(t){case"lowercase":return"-.inf";case"uppercase":return"-.INF";case"camelcase":return"-.Inf"}else if($e.isNegativeZero(e))return"-0.0";return n=e.toString(10),ot.test(n)?n.replace("e",".e"):n},defaultStyle:"lowercase"}),lt=Ze.extend({implicit:[et,tt,st,ct]}),ht=lt,ut=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9])-([0-9][0-9])$"),pt=new RegExp("^([0-9][0-9][0-9][0-9])-([0-9][0-9]?)-([0-9][0-9]?)(?:[Tt]|[ \\t]+)([0-9][0-9]?):([0-9][0-9]):([0-9][0-9])(?:\\.([0-9]*))?(?:[ \\t]*(Z|([-+])([0-9][0-9]?)(?::([0-9][0-9]))?))?$");var dt=new We("tag:yaml.org,2002:timestamp",{kind:"scalar",resolve:function(e){return null!==e&&(null!==ut.exec(e)||null!==pt.exec(e))},construct:function(e){var t,n,i,r,s,a,o,c,l=0,h=null;if(null===(t=ut.exec(e))&&(t=pt.exec(e)),null===t)throw new Error("Date resolve error");if(n=+t[1],i=+t[2]-1,r=+t[3],!t[4])return new Date(Date.UTC(n,i,r));if(s=+t[4],a=+t[5],o=+t[6],t[7]){for(l=t[7].slice(0,3);l.length<3;)l+="0";l=+l}return t[9]&&(h=6e4*(60*+t[10]+ +(t[11]||0)),"-"===t[9]&&(h=-h)),c=new Date(Date.UTC(n,i,r,s,a,o,l)),h&&c.setTime(c.getTime()-h),c},instanceOf:Date,represent:function(e){return e.toISOString()}});var ft=new We("tag:yaml.org,2002:merge",{kind:"scalar",resolve:function(e){return"<<"===e||null===e}}),gt="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";var mt=new We("tag:yaml.org,2002:binary",{kind:"scalar",resolve:function(e){if(null===e)return!1;var t,n,i=0,r=e.length,s=gt;for(n=0;n64)){if(t<0)return!1;i+=6}return i%8==0},construct:function(e){var t,n,i=e.replace(/[\r\n=]/g,""),r=i.length,s=gt,a=0,o=[];for(t=0;t>16&255),o.push(a>>8&255),o.push(255&a)),a=a<<6|s.indexOf(i.charAt(t));return 0===(n=r%4*6)?(o.push(a>>16&255),o.push(a>>8&255),o.push(255&a)):18===n?(o.push(a>>10&255),o.push(a>>2&255)):12===n&&o.push(a>>4&255),new Uint8Array(o)},predicate:function(e){return"[object Uint8Array]"===Object.prototype.toString.call(e)},represent:function(e){var t,n,i="",r=0,s=e.length,a=gt;for(t=0;t>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]),r=(r<<8)+e[t];return 0===(n=s%3)?(i+=a[r>>18&63],i+=a[r>>12&63],i+=a[r>>6&63],i+=a[63&r]):2===n?(i+=a[r>>10&63],i+=a[r>>4&63],i+=a[r<<2&63],i+=a[64]):1===n&&(i+=a[r>>2&63],i+=a[r<<4&63],i+=a[64],i+=a[64]),i}}),vt=Object.prototype.hasOwnProperty,yt=Object.prototype.toString;var bt=new We("tag:yaml.org,2002:omap",{kind:"sequence",resolve:function(e){if(null===e)return!0;var t,n,i,r,s,a=[],o=e;for(t=0,n=o.length;t>10),56320+(e-65536&1023))}for(var Gt=new Array(256),Jt=new Array(256),Xt=0;Xt<256;Xt++)Gt[Xt]=Wt(Xt)?1:0,Jt[Xt]=Wt(Xt);function Kt(e,t){this.input=e,this.filename=t.filename||null,this.schema=t.schema||kt,this.onWarning=t.onWarning||null,this.legacy=t.legacy||!1,this.json=t.json||!1,this.listener=t.listener||null,this.implicitTypes=this.schema.compiledImplicit,this.typeMap=this.schema.compiledTypeMap,this.length=e.length,this.position=0,this.line=0,this.lineStart=0,this.lineIndent=0,this.firstTabInLine=-1,this.documents=[]}function Qt(e,t){var n={name:e.filename,buffer:e.input.slice(0,-1),position:e.position,line:e.line,column:e.position-e.lineStart};return n.snippet=He(n),new je(t,n)}function Zt(e,t){throw Qt(e,t)}function en(e,t){e.onWarning&&e.onWarning.call(null,Qt(e,t))}var tn={YAML:function(e,t,n){var i,r,s;null!==e.version&&Zt(e,"duplication of %YAML directive"),1!==n.length&&Zt(e,"YAML directive accepts exactly one argument"),null===(i=/^([0-9]+)\.([0-9]+)$/.exec(n[0]))&&Zt(e,"ill-formed argument of the YAML directive"),r=parseInt(i[1],10),s=parseInt(i[2],10),1!==r&&Zt(e,"unacceptable YAML version of the document"),e.version=n[0],e.checkLineBreaks=s<2,1!==s&&2!==s&&en(e,"unsupported YAML version of the document")},TAG:function(e,t,n){var i,r;2!==n.length&&Zt(e,"TAG directive accepts exactly two arguments"),i=n[0],r=n[1],Rt.test(i)||Zt(e,"ill-formed tag handle (first argument) of the TAG directive"),Et.call(e.tagMap,i)&&Zt(e,'there is a previously declared suffix for "'+i+'" tag handle'),$t.test(r)||Zt(e,"ill-formed tag prefix (second argument) of the TAG directive");try{r=decodeURIComponent(r)}catch(t){Zt(e,"tag prefix is malformed: "+r)}e.tagMap[i]=r}};function nn(e,t,n,i){var r,s,a,o;if(t1&&(e.result+=$e.repeat("\n",t-1))}function hn(e,t){var n,i,r=e.tag,s=e.anchor,a=[],o=!1;if(-1!==e.firstTabInLine)return!1;for(null!==e.anchor&&(e.anchorMap[e.anchor]=a),i=e.input.charCodeAt(e.position);0!==i&&(-1!==e.firstTabInLine&&(e.position=e.firstTabInLine,Zt(e,"tab characters must not be used in indentation")),45===i)&&Ft(e.input.charCodeAt(e.position+1));)if(o=!0,e.position++,on(e,!0,-1)&&e.lineIndent<=t)a.push(null),i=e.input.charCodeAt(e.position);else if(n=e.line,dn(e,t,It,!1,!0),a.push(e.result),on(e,!0,-1),i=e.input.charCodeAt(e.position),(e.line===n||e.lineIndent>t)&&0!==i)Zt(e,"bad indentation of a sequence entry");else if(e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt?f=1:e.lineIndent===t?f=0:e.lineIndentt)&&(v&&(a=e.line,o=e.lineStart,c=e.position),dn(e,t,Tt,!0,r)&&(v?g=e.result:m=e.result),v||(sn(e,p,d,f,g,m,a,o,c),f=g=m=null),on(e,!0,-1),l=e.input.charCodeAt(e.position)),(e.line===s||e.lineIndent>t)&&0!==l)Zt(e,"bad indentation of a mapping entry");else if(e.lineIndent=0))break;0===r?Zt(e,"bad explicit indentation width of a block scalar; it cannot be less than one"):c?Zt(e,"repeat of an indentation width identifier"):(l=t+r-1,c=!0)}if(jt(s)){do{s=e.input.charCodeAt(++e.position)}while(jt(s));if(35===s)do{s=e.input.charCodeAt(++e.position)}while(!Bt(s)&&0!==s)}for(;0!==s;){for(an(e),e.lineIndent=0,s=e.input.charCodeAt(e.position);(!c||e.lineIndentl&&(l=e.lineIndent),Bt(s))h++;else{if(e.lineIndent0){for(r=a,s=0;r>0;r--)(a=Ht(o=e.input.charCodeAt(++e.position)))>=0?s=(s<<4)+a:Zt(e,"expected hexadecimal character");e.result+=Yt(s),e.position++}else Zt(e,"unknown escape sequence");n=i=e.position}else Bt(o)?(nn(e,n,i,!0),ln(e,on(e,!1,t)),n=i=e.position):e.position===e.lineStart&&cn(e)?Zt(e,"unexpected end of the document within a double quoted scalar"):(e.position++,i=e.position)}Zt(e,"unexpected end of the stream within a double quoted scalar")}(e,p)?m=!0:!function(e){var t,n,i;if(42!==(i=e.input.charCodeAt(e.position)))return!1;for(i=e.input.charCodeAt(++e.position),t=e.position;0!==i&&!Ft(i)&&!Ut(i);)i=e.input.charCodeAt(++e.position);return e.position===t&&Zt(e,"name of an alias node must contain at least one character"),n=e.input.slice(t,e.position),Et.call(e.anchorMap,n)||Zt(e,'unidentified alias "'+n+'"'),e.result=e.anchorMap[n],on(e,!0,-1),!0}(e)?function(e,t,n){var i,r,s,a,o,c,l,h,u=e.kind,p=e.result;if(Ft(h=e.input.charCodeAt(e.position))||Ut(h)||35===h||38===h||42===h||33===h||124===h||62===h||39===h||34===h||37===h||64===h||96===h)return!1;if((63===h||45===h)&&(Ft(i=e.input.charCodeAt(e.position+1))||n&&Ut(i)))return!1;for(e.kind="scalar",e.result="",r=s=e.position,a=!1;0!==h;){if(58===h){if(Ft(i=e.input.charCodeAt(e.position+1))||n&&Ut(i))break}else if(35===h){if(Ft(e.input.charCodeAt(e.position-1)))break}else{if(e.position===e.lineStart&&cn(e)||n&&Ut(h))break;if(Bt(h)){if(o=e.line,c=e.lineStart,l=e.lineIndent,on(e,!1,-1),e.lineIndent>=t){a=!0,h=e.input.charCodeAt(e.position);continue}e.position=s,e.line=o,e.lineStart=c,e.lineIndent=l;break}}a&&(nn(e,r,s,!1),ln(e,e.line-o),r=s=e.position,a=!1),jt(h)||(s=e.position+1),h=e.input.charCodeAt(++e.position)}return nn(e,r,s,!1),!!e.result||(e.kind=u,e.result=p,!1)}(e,p,At===n)&&(m=!0,null===e.tag&&(e.tag="?")):(m=!0,null===e.tag&&null===e.anchor||Zt(e,"alias node should not have any properties")),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):0===f&&(m=o&&hn(e,d))),null===e.tag)null!==e.anchor&&(e.anchorMap[e.anchor]=e.result);else if("?"===e.tag){for(null!==e.result&&"scalar"!==e.kind&&Zt(e,'unacceptable node kind for ! tag; it should be "scalar", not "'+e.kind+'"'),c=0,l=e.implicitTypes.length;c"),null!==e.result&&u.kind!==e.kind&&Zt(e,"unacceptable node kind for !<"+e.tag+'> tag; it should be "'+u.kind+'", not "'+e.kind+'"'),u.resolve(e.result,e.tag)?(e.result=u.construct(e.result,e.tag),null!==e.anchor&&(e.anchorMap[e.anchor]=e.result)):Zt(e,"cannot resolve a node with !<"+e.tag+"> explicit tag")}return null!==e.listener&&e.listener("close",e),null!==e.tag||null!==e.anchor||m}function fn(e){var t,n,i,r,s=e.position,a=!1;for(e.version=null,e.checkLineBreaks=e.legacy,e.tagMap=Object.create(null),e.anchorMap=Object.create(null);0!==(r=e.input.charCodeAt(e.position))&&(on(e,!0,-1),r=e.input.charCodeAt(e.position),!(e.lineIndent>0||37!==r));){for(a=!0,r=e.input.charCodeAt(++e.position),t=e.position;0!==r&&!Ft(r);)r=e.input.charCodeAt(++e.position);for(i=[],(n=e.input.slice(t,e.position)).length<1&&Zt(e,"directive name must not be less than one character in length");0!==r;){for(;jt(r);)r=e.input.charCodeAt(++e.position);if(35===r){do{r=e.input.charCodeAt(++e.position)}while(0!==r&&!Bt(r));break}if(Bt(r))break;for(t=e.position;0!==r&&!Ft(r);)r=e.input.charCodeAt(++e.position);i.push(e.input.slice(t,e.position))}0!==r&&an(e),Et.call(tn,n)?tn[n](e,n,i):en(e,'unknown document directive "'+n+'"')}on(e,!0,-1),0===e.lineIndent&&45===e.input.charCodeAt(e.position)&&45===e.input.charCodeAt(e.position+1)&&45===e.input.charCodeAt(e.position+2)?(e.position+=3,on(e,!0,-1)):a&&Zt(e,"directives end mark is expected"),dn(e,e.lineIndent-1,Tt,!1,!0),on(e,!0,-1),e.checkLineBreaks&&Lt.test(e.input.slice(s,e.position))&&en(e,"non-ASCII line breaks are interpreted as content"),e.documents.push(e.result),e.position===e.lineStart&&cn(e)?46===e.input.charCodeAt(e.position)&&(e.position+=3,on(e,!0,-1)):e.position=55296&&i<=56319&&t+1=56320&&n<=57343?1024*(i-55296)+n-56320+65536:i}function ri(e){return/^\n* /.test(e)}var si=1,ai=2,oi=3,ci=4,li=5;function hi(e,t,n,i,r,s,a,o){var c,l=0,h=null,u=!1,p=!1,d=-1!==i,f=-1,g=function(e){return ei(e)&&e!==bn&&!Zn(e)&&e!==Nn&&e!==Rn&&e!==On&&e!==Mn&&e!==Vn&&e!==Bn&&e!==Fn&&e!==Hn&&e!==An&&e!==In&&e!==Pn&&e!==kn&&e!==Un&&e!==Ln&&e!==Dn&&e!==Tn&&e!==En&&e!==Cn&&e!==$n&&e!==jn}(ii(e,0))&&function(e){return!Zn(e)&&e!==On}(ii(e,e.length-1));if(t||a)for(c=0;c=65536?c+=2:c++){if(!ei(l=ii(e,c)))return li;g=g&&ni(l,h,o),h=l}else{for(c=0;c=65536?c+=2:c++){if((l=ii(e,c))===wn)u=!0,d&&(p=p||c-f-1>i&&" "!==e[f+1],f=c);else if(!ei(l))return li;g=g&&ni(l,h,o),h=l}p=p||d&&c-f-1>i&&" "!==e[f+1]}return u||p?n>9&&ri(e)?li:a?s===Jn?li:ai:p?ci:oi:!g||a||r(e)?s===Jn?li:ai:si}function ui(e,t,n,i,r){e.dump=function(){if(0===t.length)return e.quotingType===Jn?'""':"''";if(!e.noCompatMode&&(-1!==zn.indexOf(t)||Wn.test(t)))return e.quotingType===Jn?'"'+t+'"':"'"+t+"'";var s=e.indent*Math.max(1,n),a=-1===e.lineWidth?-1:Math.max(Math.min(e.lineWidth,40),e.lineWidth-s),o=i||e.flowLevel>-1&&n>=e.flowLevel;switch(hi(t,o,e.indent,a,(function(t){return function(e,t){var n,i;for(n=0,i=e.implicitTypes.length;n"+pi(t,e.indent)+di(Kn(function(e,t){var n,i,r=/(\n+)([^\n]*)/g,s=(o=e.indexOf("\n"),o=-1!==o?o:e.length,r.lastIndex=o,fi(e.slice(0,o),t)),a="\n"===e[0]||" "===e[0];var o;for(;i=r.exec(e);){var c=i[1],l=i[2];n=" "===l[0],s+=c+(a||n||""===l?"":"\n")+fi(l,t),a=n}return s}(t,a),s));case li:return'"'+function(e){for(var t,n="",i=0,r=0;r=65536?r+=2:r++)i=ii(e,r),!(t=qn[i])&&ei(i)?(n+=e[r],i>=65536&&(n+=e[r+1])):n+=t||Yn(i);return n}(t)+'"';default:throw new je("impossible error: invalid scalar style")}}()}function pi(e,t){var n=ri(e)?String(t):"",i="\n"===e[e.length-1];return n+(i&&("\n"===e[e.length-2]||"\n"===e)?"+":i?"":"-")+"\n"}function di(e){return"\n"===e[e.length-1]?e.slice(0,-1):e}function fi(e,t){if(""===e||" "===e[0])return e;for(var n,i,r=/ [^ ]/g,s=0,a=0,o=0,c="";n=r.exec(e);)(o=n.index)-s>t&&(i=a>s?a:o,c+="\n"+e.slice(s,i),s=i+1),a=o;return c+="\n",e.length-s>t&&a>s?c+=e.slice(s,a)+"\n"+e.slice(a+1):c+=e.slice(s),c.slice(1)}function gi(e,t,n,i){var r,s,a,o="",c=e.tag;for(r=0,s=n.length;r tag resolver accepts not "'+c+'" style');i=o.represent[c](t,c)}e.dump=i}return!0}return!1}function vi(e,t,n,i,r,s,a){e.tag=null,e.dump=n,mi(e,n,!1)||mi(e,n,!0);var o,c=vn.call(e.dump),l=i;i&&(i=e.flowLevel<0||e.flowLevel>t);var h,u,p="[object Object]"===c||"[object Array]"===c;if(p&&(u=-1!==(h=e.duplicates.indexOf(n))),(null!==e.tag&&"?"!==e.tag||u||2!==e.indent&&t>0)&&(r=!1),u&&e.usedDuplicates[h])e.dump="*ref_"+h;else{if(p&&u&&!e.usedDuplicates[h]&&(e.usedDuplicates[h]=!0),"[object Object]"===c)i&&0!==Object.keys(e.dump).length?(!function(e,t,n,i){var r,s,a,o,c,l,h="",u=e.tag,p=Object.keys(n);if(!0===e.sortKeys)p.sort();else if("function"==typeof e.sortKeys)p.sort(e.sortKeys);else if(e.sortKeys)throw new je("sortKeys must be a boolean or a function");for(r=0,s=p.length;r1024)&&(e.dump&&wn===e.dump.charCodeAt(0)?l+="?":l+="? "),l+=e.dump,c&&(l+=Qn(e,t)),vi(e,t+1,o,!0,c)&&(e.dump&&wn===e.dump.charCodeAt(0)?l+=":":l+=": ",h+=l+=e.dump));e.tag=u,e.dump=h||"{}"}(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,n){var i,r,s,a,o,c="",l=e.tag,h=Object.keys(n);for(i=0,r=h.length;i1024&&(o+="? "),o+=e.dump+(e.condenseFlow?'"':"")+":"+(e.condenseFlow?"":" "),vi(e,t,a,!1,!1)&&(c+=o+=e.dump));e.tag=l,e.dump="{"+c+"}"}(e,t,e.dump),u&&(e.dump="&ref_"+h+" "+e.dump));else if("[object Array]"===c)i&&0!==e.dump.length?(e.noArrayIndent&&!a&&t>0?gi(e,t-1,e.dump,r):gi(e,t,e.dump,r),u&&(e.dump="&ref_"+h+e.dump)):(!function(e,t,n){var i,r,s,a="",o=e.tag;for(i=0,r=n.length;i",e.dump=o+" "+e.dump)}return!0}function yi(e,t){var n,i,r=[],s=[];for(bi(e,r,s),n=0,i=s.length;ne.trim())).filter((e=>e.length));for(let t=0;te.trim()));e.style.setProperty(i[0],i[1])}}static setText(e,t,n){e instanceof SVGTextElement||(e=e.querySelector("text")||e);const i=t.replace(/\\n/g,"\n").split("\n"),r=i.length>1,s=e.querySelector("tspan");if(r){const t=null==s?void 0:s.getAttribute("x"),r=null==s?void 0:s.getAttribute("y");t&&!e.getAttribute("x")&&e.setAttribute("x",t),r&&!e.getAttribute("y")&&e.setAttribute("y",r);const a=e.querySelector("tspan")||!1;e.textContent="",e.dataset.ha_floorplan_notice="The text_set function split your text into multiple tspans. Only the style of the first tspan is preserved. The style from the original tspan is reused on every tspan. The x and y are calculated on the basis of the first tspan or text-element.";const o=e.getAttribute("x")||"0",c=n||"1em";i.forEach(((t,n)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","tspan");if(i.textContent=t,i.setAttribute("x",o),i.setAttribute("dy",n>=1?c:"0"),a){const e=a.getAttribute("style");e&&i.setAttribute("style",e)}e.appendChild(i)}))}else{(s||e).textContent=t}}static waitForChildNodes(e,t,n){return new Promise(((i,r)=>{const s=setTimeout((()=>r("Timeout waiting for child element(s) to load")),n);new MutationObserver((e=>{for(const t of e)if("childList"===t.type&&t.addedNodes.length)return clearTimeout(s),i()})).observe(e,{childList:!0,subtree:!0}),t()}))}static formatDate(e){return e?"string"==typeof e?new Date(e).toLocaleString():e.toLocaleString():""}static parseYaml(e){return wi.load(e)}static fetchText(e,t,n,i){return Si(this,void 0,void 0,(function*(){n&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${n}/`)),e=i?e:_i.cacheBuster(e);const r=new Request(e,{cache:i?"default":"no-store",mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){return yield e.text()}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static fetchImage(e,t,n,i){return Si(this,void 0,void 0,(function*(){t&&(e=e.replace(/^\/local\/floorplan\/examples\//g,`${n}/`)),e=i?e:_i.cacheBuster(e);const r=new Request(e,{cache:i?"default":"no-store",headers:new Headers({"Content-Type":"text/plain; charset=x-user-defined"}),mode:t?"no-cors":void 0});try{const e=yield fetch(r);if(e.ok||t&&"opaque"===e.type){const t=yield e.arrayBuffer();return`data:image/jpeg;base64,${_i.arrayBufferToBase64(t)}`}throw new Error("Error fetching resource")}catch(t){throw new URIError(`${e}: ${t.message}`)}}))}static singleToArray(e){return null==e?[]:Array.isArray(e)?e:[e]}static getArray(e){if(null==e)return[];if(Array.isArray(e))return e;{const t=e;return Object.values(t)}}static getSet(e){if(Array.isArray(e))return new Set(e);{const t=e;return new Set(Object.values(t))}}static arrayBufferToBase64(e){let t="";[].slice.call(new Uint8Array(e)).forEach((e=>t+=String.fromCharCode(e)));let n=window.btoa(t);for(;n.length%4>0;)n+="=";return n}static cacheBuster(e){return`${e}${e.includes("?")?"&":"?"}_=${(new Date).getTime()}`}static equal(e,t){if(e===t)return!0;const n=Array.isArray(e),i=Array.isArray(t);let r=0;if(n&&i){if(e.length!=t.length)return!1;for(r=0;rMath.floor(1e5*(1+Math.random())).toString(16).substring(1);localStorage[e]=`${t()}${t()}_${t()}${t()}`}return localStorage[e]}}class ki{constructor(e,t,n){this.element=e,this.logLevel=t,this.consoleLogLevel=n,this.logLevelGroups={error:["error"],warn:["error","warning","warn"],warning:["error","warning","warn"],info:["error","warning","warn","info"],debug:["error","warning","warn","info","debug"]}}log(e,t,n=!1){var i;const r=`${_i.formatDate(new Date)} ${e.toUpperCase()} ${t}`,s=this.logLevel&&this.logLevelGroups[this.logLevel.toLowerCase()],a=(null==s?void 0:s.length)&&s.includes(e.toLowerCase());if((n||a)&&this.element){const t=document.createElement("li");_i.addClass(t,e),t.textContent=r,null===(i=this.element.querySelector("ul"))||void 0===i||i.prepend(t),this.element.style.display="block"}this.consoleLog(e,t,n)}consoleLog(e,t,n=!1){const i=`${_i.formatDate(new Date)} ${e.toUpperCase()} ${t}`,r=this.consoleLogLevel&&this.logLevelGroups[this.consoleLogLevel.toLowerCase()],s=(null==r?void 0:r.length)&&r.includes(e.toLowerCase());if(n||s)switch(e){case"error":console.error(i);break;case"warn":case"warning":console.warn(i);break;case"info":console.info(i);break;default:console.log(i)}}}var Ei=function(e,t,n,i){var r,s=arguments.length,a=s<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,i);else for(var o=e.length-1;o>=0;o--)(r=e[o])&&(a=(s<3?r(a):s>3?r(t,n,a):r(t,n))||a);return s>3&&a&&Object.defineProperty(t,n,a),a},Ai=function(e,t,n,i){return new(n||(n=Promise))((function(r,s){function a(e){try{c(i.next(e))}catch(e){s(e)}}function o(e){try{c(i.throw(e))}catch(e){s(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,o)}c((i=i.apply(e,t||[])).next())}))};const Ci=Se;console.info("%cFloorplan for Home Assistant (ha-floorplan)%c\nVersion 1.0.43","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: rgb(71, 170, 238)");let Ii=class extends ne{constructor(){super(),this.pageInfos={},this.entityInfos={},this.elementInfos={},this.cssRules=[],this.functions={},this.variables={},this.svgElements={},this.isRulesLoaded=!1,window.onerror=this.handleWindowError.bind(this)}render(){return $`
@@ -128,7 +128,7 @@ function Re(e){return null==e}De.cache={},De.interpreter=new(Oe())({ecmaVer:2019 .debug { color: #000000; } - `}clearLog(){this.logElement.querySelector("#log ul").innerHTML=""}updated(e){const t=Object.create(null,{updated:{get:()=>super.updated}});return Ai(this,void 0,void 0,(function*(){t.updated.call(this,e),e.has("_config")&&(yield this._configChanged(),yield this.hassChanged()),e.has("hass")&&(yield this.hassChanged())}))}_configChanged(){return Ai(this,void 0,void 0,(function*(){this._config&&(yield this.init())}))}hassChanged(){return Ai(this,void 0,void 0,(function*(){if(!this.hass||!this.config||!this.svg)return;const e=_i.deviceId();this.hass.states[`sensor.ha_floorplan_${e}`]={entity_id:`sensor.ha_floorplan_${e}`,state:"on",last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{device_class:"ha-floorplan",friendly_name:"ha-floorplan - Floorplan for Home Assistant",icon:"mdi:floor-plan",assumed_state:!1,hidden:!0},context:{}},this.isRulesLoaded?this.handleEntities():(this.initFloorplanRules(this.svg,this.config),this.isRulesLoaded=!0,yield this.handleEntities(!0))}))}get floorplanElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("floorplan")}get logElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("log")}init(){return Ai(this,void 0,void 0,(function*(){try{const e=yield this.loadConfig(this._config,!1);if(this.isShowLog=void 0!==e.log_level,this.logger=new ki(this.logElement,e.log_level,e.console_log_level),this.logInfo("INIT","Floorplan for Home Assistant (ha-floorplan) v1.0.41"),!this.validateConfig(e))return;this.config=e,this.config.pages?yield this.initMultiPage():yield this.initSinglePage()}catch(e){this.handleError(e)}}))}initMultiPage(){return Ai(this,void 0,void 0,(function*(){try{yield this.loadPages(),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}initSinglePage(){return Ai(this,void 0,void 0,(function*(){try{yield this.loadStyleSheet(this.config.stylesheet);const e=this.getBestImage(this.config);this.svg=yield this.loadFloorplanSvg(e),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}loadConfig(e,t){return Ai(this,void 0,void 0,(function*(){if("string"==typeof e){let n;try{n=yield _i.fetchText(e,this.isDemo,this.examplespath,t)}catch(t){throw this.logError("CONFIG",`Error loading config: ${e}`),t}return wi.load(n)}return JSON.parse(JSON.stringify(e))}))}loadScript(e,t){return e?new Promise(((n,i)=>{var r;const s=document.createElement("script");s.src=t?e:_i.cacheBuster(e),s.onload=()=>n(),s.onerror=e=>{i(new URIError(`${e.target.src}`))},null===(r=this.shadowRoot)||void 0===r||r.appendChild(s)})):Promise.resolve()}loadPages(){return Ai(this,void 0,void 0,(function*(){for(const e of this.config.pages)yield this.loadPageConfig(e,this.config.pages.indexOf(e));const e=Object.keys(this.pageInfos).map((e=>this.pageInfos[e]));e.sort(((e,t)=>e.index-t.index));const t=e.find((e=>void 0!==e.config.master_page));if(!t)throw new Error("A master page is required");t.isMaster=!0;const n=e.find((e=>void 0===e.config.master_page));n&&(n.isDefault=!0),yield this.loadPageFloorplanSvg(t,t);const i=e.filter((e=>e!==t));for(const e of i)yield this.loadPageFloorplanSvg(e,t);this.svg=t.svg}))}loadPageConfig(e,t){return Ai(this,void 0,void 0,(function*(){const n=yield this.loadConfig(e,!1),i=this.createPageInfo(n);return i.index=t,i}))}loadPageFloorplanSvg(e,t){return Ai(this,void 0,void 0,(function*(){const n=this.getBestImage(e.config),i=yield this.loadFloorplanSvg(n,e,t);i.id=e.config.page_id,e.svg=i,yield this.loadStyleSheet(e.config.stylesheet),this.initFloorplanRules(e.svg,e.config)}))}getBestImage(e){var t;let n="",i=!0;if("string"==typeof e.image)n=_i.isMobile&&"string"==typeof e.image_mobile?e.image_mobile:e.image;else if(null===(t=e.image)||void 0===t?void 0:t.sizes){e.image.sizes.sort(((e,t)=>t.min_width-e.min_width));for(const t of e.image.sizes)if(screen.width>=t.min_width){n=t.location,i=!0===t.cache;break}}else _i.isMobile&&e.image_mobile?(n=e.image_mobile.location,i=!0===e.image_mobile.cache):(n=e.image.location,i=!0===e.image.cache);return{location:n,cache:i}}createPageInfo(e){const t={config:e};return t.config.rules&&this.config.rules&&(t.config.rules=t.config.rules.concat(this.config.rules)),this.pageInfos[t.config.page_id]=t,t}loadStyleSheet(e){return Ai(this,void 0,void 0,(function*(){const t="string"==typeof e?e:e.location,n="string"!=typeof e&&!0===e.cache;if(!t)return;let i;try{i=yield _i.fetchText(t,this.isDemo,this.examplespath,n)}catch(e){throw this.logError("STYLESHEET",`Error loading stylesheet: ${t}`),e}const r=document.createElement("style"),s=()=>{var e;r.innerHTML=i,null===(e=this.shadowRoot)||void 0===e||e.appendChild(r)};try{yield _i.waitForChildNodes(r,s,1e4)}catch(e){this.logError("STYLESHEET","Error loading stylesheet")}const a=this.getCssRules(r);this.cssRules=this.cssRules.concat(a)}))}getCssRules(e){var t,n,i,r,s,a;let o;if(e.sheet)o=null!==(n=null===(t=e.sheet)||void 0===t?void 0:t.cssRules)&&void 0!==n?n:null===(i=e.sheet)||void 0===i?void 0:i.rules;else{const t=e;t.styleSheet&&(o=null!==(s=null===(r=t.styleSheet)||void 0===r?void 0:r.cssRules)&&void 0!==s?s:null===(a=t.styleSheet)||void 0===a?void 0:a.rules)}return o?_i.getArray(o):[]}loadFloorplanSvg(e,t,n){var i;return Ai(this,void 0,void 0,(function*(){let r;try{r=yield _i.fetchText(e.location,this.isDemo,this.examplespath,e.cache)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e.location}`),t}const s=document.createElement("div");s.innerHTML=r;const a=s.querySelector("svg");if(t&&a.setAttribute("id",t.config.page_id),a.setAttribute("height","100%"),a.setAttribute("width","100%"),a.style.height="100%",a.style.width="100%",a.style.margin="auto",a.style.cursor="default",a.style.opacity="0",a.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),t&&n){const e=n.config.page_id,r=n.config.master_page.content_element;if(t.config.page_id===e)this.floorplanElement.replaceChildren(a);else{const e=this.floorplanElement.querySelector("#"+r),t=Number.parseFloat(a.getAttribute("height")),n=Number.parseFloat(a.getAttribute("width"));a.getAttribute("viewBox")||a.setAttribute("viewBox",`0 0 ${n} ${t}`),a.setAttribute("preserveAspectRatio","xMinYMin meet"),a.setAttribute("height",e.getAttribute("height")),a.setAttribute("width",e.getAttribute("width")),a.setAttribute("x",e.getAttribute("x")),a.setAttribute("y",e.getAttribute("y")),null===(i=e.parentElement)||void 0===i||i.replaceChildren(a)}}else this.floorplanElement.replaceChildren(a);return a}))}loadImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){return e.toLowerCase().includes(".svg")||"svg"===t.svgElement.nodeName||t.svgElement.querySelector("svg")?yield this.loadSvgImage(e,t,n,i,r):yield this.loadBitmapImage(e,t,n,i,r)}))}loadBitmapImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){e=r?e:_i.cacheBuster(e),this.logDebug("IMAGE",`${n} (setting image: ${e})`);let s=t.svgElement;return"image"!==s.nodeName&&(s=this.createImageElement(t.originalSvgElement),t.svgElement=this.replaceElement(t.svgElement,s),this.attachClickHandlers(s,t,n,void 0,i),s.onmouseover=()=>{this.handleEntityIdSetHoverOver(n,t)}),s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),s}))}loadSvgImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){let s;if(null==e?void 0:e.trim().length)try{s=yield _i.fetchText(e,this.isDemo,this.examplespath,r)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e}`),t}else{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 0 0"),s=e.outerHTML}this.logDebug("IMAGE",`${n} (setting image: ${e})`);const a="g"===t.svgElement.nodeName?t.svgElement:document.createElement("div");a.innerHTML=s;const o=a.querySelector("svg"),c=Number.parseFloat(o.getAttribute("height")),l=Number.parseFloat(o.getAttribute("width"));if(o.getAttribute("viewBox")||o.setAttribute("viewBox",`0 0 ${l} ${c}`),o.id=t.svgElement.id,o.setAttribute("preserveAspectRatio","xMinYMin meet"),null!==t.originalBBox&&(o.setAttribute("height",t.originalBBox.height.toString()),o.setAttribute("width",t.originalBBox.width.toString()),o.setAttribute("x",t.originalBBox.x.toString()),o.setAttribute("y",t.originalBBox.y.toString())),"g"!==t.svgElement.nodeName){const e=t.svgElement.getAttribute("transform");e&&o.setAttribute("transform",e),t.svgElement=this.replaceElement(t.svgElement,o)}return this.attachClickHandlers(o,t,n,void 0,i),t.svgElement.onmouseover=()=>{this.handleEntityIdSetHoverOver(n,t)},o}))}_querySelectorAll(e,t=void 0,n){let i=t?Array.from(e.querySelectorAll(t).values()):[];return i=n?[e].concat(i):i,i}replaceElement(e,t){const n=e.parentElement;for(const n of Array.from(e.classList))t.classList.add(n);return this._querySelectorAll(e,"*",!0).forEach((e=>{Ci.off(e,"click"),Ci.off(e,"longClick"),e.remove()})),e.remove(),null==n||n.appendChild(t),t}initPageDisplay(){if(this.config.pages)for(const e of Object.values(this.pageInfos))e.svg.style.opacity="1",e.svg.style.display=e.isMaster||e.isDefault?"initial":"none";else this.svg.style.opacity="1",this.svg.style.display="block"}initVariables(){if(this.config.variables)for(const e of this.config.variables)this.initVariable(e);if(this.config.pages)for(const e of Object.values(this.pageInfos))if(e.config.variables)for(const t of e.config.variables)this.initVariable(t)}initVariable(e){let t,n;if("string"==typeof e?t=e:(t=e.name,n=e.value,e.value&&(n=this.evaluate(e.value,t,void 0))),!this.entityInfos[t]){const e={entityId:t,ruleInfos:[],lastState:void 0};this.entityInfos[t]=e}this.hass.states[t]||(this.hass.states[t]={entity_id:t,state:n,last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{},context:{}}),this.setVariable(t,n,{},!0)}getActionConfigs(e){var t,n;if(null==e)return[];if(Array.isArray(e)){for(const n of e)n.action=null!==(t=n.action)&&void 0!==t?t:"call-service";return e}return"object"==typeof e?(e.action=null!==(n=e.action)&&void 0!==n?n:"call-service",[e]):"string"==typeof e?e.includes(".")?[{action:"call-service",service:e}]:[{action:e}]:[]}initStartupActions(){if(this.handleActions(this.config.startup_action,void 0,void 0,void 0),this.config.pages)for(const e of Object.values(this.pageInfos))this.handleActions(e.config.startup_action,void 0,void 0,void 0)}initFloorplanRules(e,t){if(!t.rules)return;const n=this._querySelectorAll(e,"*",!0);for(const e of n)e.id&&(this.svgElements[e.id]=e);this.initRules(t,e,n)}initRules(e,t,n){if(e.functions&&(this.functions=this.evaluate(e.functions)),e.defaults){const t=e.defaults;for(const n of e.rules)n.hover_action=void 0===n.hover_action?t.hover_action:n.hover_action,n.tap_action=void 0===n.tap_action?t.tap_action:n.tap_action,n.hold_action=void 0===n.hold_action?t.hold_action:n.hold_action,n.hover_info_filter=void 0===n.hover_info_filter?t.hover_info_filter:n.hover_info_filter}for(const i of e.rules)i.entity||i.entities?this.initEntityRule(i,t,n):(i.element||i.elements)&&this.initElementRule(i,t,n)}initEntityRule(e,t,n){const i=this.initGetEntityRuleEntities(e);for(const r of i){const i=r.entityId;let s=this.entityInfos[i];s||(s={entityId:i,ruleInfos:[],lastState:void 0},this.entityInfos[i]=s);const a=new pe(e);s.ruleInfos.push(a);for(const e of r.elementIds){const r=n.find((t=>t.id===e));if(!r){this.logWarning("CONFIG",`Cannot find element '${e}' in SVG file`);continue}const o=this.addSvgElementToRule(t,r,a);o.svgElement=r,r.querySelector("title")||r.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.onmouseenter=()=>{this.handleEntitySetHoverOver(s,o)},r.onmouseleave=()=>{this.handleEntitySetHoverOver(s,o)},this.attachClickHandlers(r,o,i,void 0,a)}}}initGetEntityRuleEntities(e){const t=[];e.groups=e.groups?e.groups:[];for(const n of e.groups){const e=this.hass.states[n];if(e)for(const n of e.attributes.entity_id)this.addTargetEntity(n,[n],t);else this.logWarning("CONFIG",`Cannot find '${n}' in Home Assistant groups`)}e.entities=e.entities?e.entities:[],e.entities=e.entity?e.entities.concat(e.entity):e.entities;const n=e.entities.filter((e=>"string"==typeof e));for(const i of n){let n=[];e.elements?n=n.concat(e.elements):e.element?n=n.concat(this.evaluate(e.element,i,void 0)):null!==e.element&&(n=n.concat(i)),this.addTargetEntity(i,n,t)}const i=e.entities.filter((e=>"string"!=typeof e));for(const e of i){const n=e;this.addTargetEntity(n.entity,[n.element],t)}return t}addTargetEntity(e,t,n){const i=this.hass.states[e],r="floorplan"===e.split(".")[0];i||r?n.push({entityId:e,elementIds:t}):this.logWarning("CONFIG",`Cannot find '${e}' in Home Assistant entities`)}initElementRule(e,t,n){if(e.element||e.elements){e.elements=e.elements?e.elements:[],e.elements=e.element?e.elements.concat(e.element):e.elements;for(const i of e.elements){const r=n.find((e=>e.id===i));if(r){let n=this.elementInfos[i];n||(n={ruleInfos:[],lastState:void 0},this.elementInfos[i]=n);const s=new pe(e);n.ruleInfos.push(s);const a=this.addSvgElementToRule(t,r,s);this.attachClickHandlers(r,a,void 0,i,s)}else this.logWarning("CONFIG",`Cannot find '${i}' in SVG file`)}}}attachClickHandlers(e,t,n,i,r){this._querySelectorAll(e,void 0,!0).forEach((s=>{const a=s,o=s===e;if(a.querySelector("title")||a.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.rule.tap_action||r.rule.double_tap_action){const e=!!r.rule.tap_action&&this.getActionConfigs(r.rule.tap_action),s=!!r.rule.double_tap_action&&this.getActionConfigs(r.rule.double_tap_action),c=!!e&&new de(this,n,i,t,r,e);if(e&&!s&&Ci.on(a,"click",this.onClick.bind(c)),s){const o=!!s&&new de(this,n,i,t,r,s);Ce.observe(a),e&&Ci.on(a,"singleClick",this.onClick.bind(c)),Ci.on(a,"doubleClick",this.onLongClick.bind(o))}a.style&&(a.style.cursor="pointer"),_i.addClass(a,"floorplan-click"+(o?"":"-child"))}if(r.rule.hold_action){const e=this.getActionConfigs(r.rule.hold_action),s=new de(this,n,i,t,r,e);ke.observe(a),Ci.on(a,"longClick",this.onLongClick.bind(s)),a.style&&(a.style.cursor="pointer"),_i.addClass(a,"floorplan-long-click"+(o?"":"-child"))}}))}addSvgElementToRule(e,t,n){const i=t.getBBox?t.getBBox():null,r=new ue(t.id,t,t,i);return n.svgElementInfos[t.id]=r,r}createImageElement(e){const t=document.createElementNS("http://www.w3.org/2000/svg","image");return t.setAttribute("id",e.getAttribute("id")),t.setAttribute("x",e.getAttribute("x")),t.setAttribute("y",e.getAttribute("y")),t.setAttribute("height",e.getAttribute("height")),t.setAttribute("width",e.getAttribute("width")),t}handleEntities(e=!1){return Ai(this,void 0,void 0,(function*(){this.handleElements();const t=this.getChangedEntities(e);for(const e of Object.keys(this.variables))t.add(e);if(t.size)for(const e of t)yield this.handleEntity(e)}))}getChangedEntities(e){const t=new Set,n=Object.keys(this.hass.states),i=_i.deviceId();for(const r of n)if(r!==`sensor.ha_floorplan_${i}`||t.has(r)){const n=this.entityInfos[r];if(n){const i=this.hass.states[r];if(e)this.logDebug("STATE",`${r}: ${i.state} (initial load)`),t.has(r)||t.add(r);else if(n.lastState){const e=i.state;i.last_changed!==n.lastState.last_changed?(this.logDebug("STATE",`${r}: ${e} (last changed ${_i.formatDate(n.lastState.last_changed)})`),t.has(r)||t.add(r)):_i.equal(n.lastState.attributes,i.attributes)||(this.logDebug("STATE",`${r}: attributes (last updated ${_i.formatDate(n.lastState.last_changed)})`),t.has(r)||t.add(r))}}}else t.add(r);return t}handleEntity(e){return Ai(this,void 0,void 0,(function*(){const t=this.hass.states[e],n=this.entityInfos[e];if(n){n.lastState=Object.assign({},t);for(const e of n.ruleInfos){const t=Object.values(e.svgElementInfos);if(t.length)for(const i of t)i.svgElement&&this.handleActions(e.rule.state_action,n.entityId,i,e);else this.handleActions(e.rule.state_action,n.entityId,void 0,e)}}}))}handleElements(){return Ai(this,void 0,void 0,(function*(){for(const e of Object.values(this.elementInfos))for(const t of e.ruleInfos)for(const e of Object.values(t.svgElementInfos))this.handleActions(t.rule.state_action,void 0,e,t)}))}handleEntityIdSetHoverOver(e,t){const n=this.entityInfos[e];n&&this.handleEntitySetHoverOver(n,t)}handleEntitySetHoverOver(e,t){const n=e.entityId,i=this.hass.states[n];for(const n of e.ruleInfos)if(n.rule.hover_action){let r="string"==typeof n.rule.hover_action&&"hover-info"===n.rule.hover_action;if(r=r||"object"==typeof n.rule.hover_action&&"hover-info"===n.rule.hover_action.action,r=r||Array.isArray(n.rule.hover_action)&&n.rule.hover_action.some((e=>"hover-info"===e.action)),r){const e=new Set(n.rule.hover_info_filter);for(const t of Object.values(n.svgElementInfos))_i.addClass(t.svgElement,"floorplan-hover"),t.svgElement.style.cursor="pointer",t.svgElement.querySelectorAll("title").forEach((t=>{let n=`${i.attributes.friendly_name}\n`;n+=`State: ${i.state}\n\n`,Object.keys(i.attributes).map((t=>{e.has(t)||(n+=`${t}: ${i.attributes[t]}\n`)})),n+="\n",n+=`Last changed: ${Me.timeago(i.last_changed)}\n`,n+=`Last updated: ${Me.timeago(i.last_updated)}`,t.textContent=n}))}else n.rule.hover_action&&this.handleActions(n.rule.hover_action,e.entityId,t,n)}}isOptionEnabled(e){return null===e||void 0!==e}validateConfig(e){let t=!0;if(e.pages||e.rules)if(e.pages)e.pages.length||this.logWarning("CONFIG","The 'pages' section must contain one or more pages in floorplan configuration");else{e.rules||this.logWarning("CONFIG","Cannot find 'rules' in floorplan configuration");let n=e.rules.filter((e=>e.entities&&e.elements));n.length&&(this.logError("CONFIG","A rule cannot contain both 'entities' and 'elements' in floorplan configuration"),t=!1),n=e.rules.filter((e=>!(e.entity||e.entities||e.element||e.elements))),n.length&&(this.logError("CONFIG","A rule must contain either 'entities' or 'elements' in floorplan configuration"),t=!1)}else this.logWarning("CONFIG","Cannot find 'pages' nor 'rules' in floorplan configuration");return t}evaluate(e,t,n){if("string"!=typeof e||!De.isCode(e))return e;try{return De.evaluate(e,this.hass,this.config,t,n,this.svgElements,this.functions)}catch(i){return this.handleError(i,{expression:e,entityId:t,hass:this.hass,svgElement:n})}}onClick(e){e.stopPropagation(),e.preventDefault();const t=this;t.instance.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}onLongClick(e){e.stopPropagation(),e.preventDefault();const t=this,n=t.instance;setTimeout((()=>{n.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}),300)}handleActions(e,t,n,i){var r;const s=this.getActionConfigs(e);for(const e of s){if(e.confirmation&&(!e.confirmation.exemptions||!e.confirmation.exemptions.some((e=>e.user===this.hass.user.id)))&&!confirm(e.confirmation.text||`Are you sure you want to ${e.action}?`))return;switch(e.action){case"more-info":this.isDemo?this.notify(`Performing action: ${e.action} ${t}`):le(this,"hass-more-info",{entityId:t});break;case"navigate":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.navigation_path}`);else{const i=this.evaluate(e.navigation_path,t,null==n?void 0:n.svgElement);he(0,i,null!==(r=e.navigation_replace)&&void 0!==r&&r)}break;case"url":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.url_path}`);else{const t=e.same_tab?"_self":"_blank";window.open(e.url_path,t)}break;case"toggle":if(t){const e={action:"call-service",service:"homeassistant.toggle",service_data:{entity_id:t}};this.callService(e,t,n,i)}break;case"call-service":if(!e.service)return;this.callService(e,t,n,i);break;case"fire-dom-event":le(this,"ll-custom",e)}}}getSvgElementsFromServiceData(e,t){let n=[],i=[];if(Array.isArray(null==e?void 0:e.elements)&&(i=i.concat(null==e?void 0:e.elements)),"string"==typeof(null==e?void 0:e.element)&&(i=i.concat([null==e?void 0:e.element])),i.length)for(const e of i)n=n.concat(this._querySelectorAll(this.svg,`#${e.replace(/\./g,"\\.")}`,!1));else t&&(n=[t]);return n}getServiceData(e,t,n){let i={};if("object"==typeof e.service_data)for(const r of Object.keys(e.service_data))i[r]=this.evaluate(e.service_data[r],t,n);else if("string"==typeof e.service_data){const r=this.evaluate(e.service_data,t,n);i="string"==typeof r&&r.trim().startsWith("{")?JSON.parse(r):r}else void 0!==e.service_data&&(i=e.service_data);return i}executeServiceData(e,t,n){try{if("object"==typeof e.service_data)for(const i of Object.keys(e.service_data))this.evaluate(e.service_data[i],t,n);else"string"==typeof e.service_data?this.evaluate(e.service_data,t,n):void 0!==e.service_data&&this.logWarning("CONFIG","Invalid execution data");return!0}catch(e){return this.logWarning("CONFIG","Error thrown while executing service"),!1}}callService(e,t,n,i){const r=this.evaluate(e.service,t,null==n?void 0:n.svgElement),[s,a]=r.split(".",2);if("floorplan"===s)this.callFloorplanService(s,a,e,t,n,i);else this.callHomeAssistantService(s,a,e,t,n)}callFloorplanService(e,t,n,i,r,s){var a,o,c;const l=null!==(a=null==r?void 0:r.svgElement)&&void 0!==a?a:void 0;let h,u,p,d,f,g,m,v,y,b=[],x=null;switch(x=!["execute"].includes(t)?this.getServiceData(n,i,l):{},t){case"class_toggle":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),p="string"==typeof x?x:x.class,_i.toggleClass(e,p);break;case"class_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),p="string"==typeof x?x:x.class,_i.setClass(e,p);break;case"dataset_set":{let e,t;if("string"==typeof x){const n=x.split(":");if(n.length<2){this.logError("FLOORPLAN_ACTION",`Service data "${x}" is not a valid dataset key value pair.`);break}e=n[1],t=n[0]}else e=x.value,t=x.key;b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const s of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,s)),_i.datasetSet(s,t,e);break}case"style_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),d="string"==typeof x?x:x.style,_i.setStyle(e,d);break;case"text_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b){y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),v="string"==typeof x?x:x.text;const t=(null===(o=n.service_data)||void 0===o?void 0:o.shift_y_axis)?null===(c=n.service_data)||void 0===c?void 0:c.shift_y_axis:"1em";_i.setText(e,v,t)}break;case"image_set":r&&s&&(x=this.getServiceData(n,i,null==r?void 0:r.svgElement),f="string"==typeof x?x:x.image,g="object"==typeof x?x.image_refresh_interval:0,m=!(g>0)&&("object"!=typeof x||!0===x.cache),s.imageLoader&&clearInterval(s.imageLoader),g&&(s.imageLoader=setInterval(this.loadImage.bind(this),1e3*g,f,r,i,s,m)),this.loadImage(f,r,i,s,m));break;case"page_navigate":x=this.getServiceData(n,i,null==r?void 0:r.svgElement),h=x.page_id,u=h?this.pageInfos[h]:void 0,u&&(Object.keys(this.pageInfos).map((e=>{const t=this.pageInfos[e];t.isMaster||"none"===t.svg.style.display||(t.svg.style.display="none")})),u.svg.style.display="block");break;case"variable_set":if(x=this.getServiceData(n,i,null==r?void 0:r.svgElement),x.variable){const e={};if(x.attributes){const t=x.attributes;for(const n of Object.keys(t))e[n]=this.getActionValue(t[n],i,l)}const t=x,n=this.getActionValue(t,i,l);this.setVariable(x.variable,n,e,!1)}break;case"execute":this.executeServiceData(n,i,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||this.executeServiceData(n,i,e)}}getActionValue(e,t,n){let i=e.value;return e.value&&(i=this.evaluate(e.value,t,n)),i}setVariable(e,t,n,i){if(this.variables[e]=t,this.hass.states[e]){this.hass.states[e].state=t.toString();for(const t of Object.keys(n))this.hass.states[e].attributes[t]=n[t]}for(const e of Object.keys(this.variables)){const t=this.hass.states[e];t&&(t.last_changed=(new Date).toString())}i||this.handleEntities()}callHomeAssistantService(e,t,n,i,r){const s=this.getServiceData(n,i,null==r?void 0:r.svgElement);"object"==typeof s&&(null===s.entity_id||Array.isArray(s.entity_id)&&!s.entity_id.length||!s.entity_id&&i&&(s.entity_id=i)),this.hass.callService(e,t,s),this.isDemo&&this.notify(`Calling service: ${e}.${t} (${s.entity_id})`)}handleWindowError(e,t,n,i,r){if(e.toLowerCase().includes("script error"))this.logError("SCRIPT","Script error: See browser console for detail");else{const s=[e,"URL: "+t,"Line: "+n+", column: "+i,"Error: "+JSON.stringify(r)].join("
");this.logError("ERROR",s)}return!1}handleError(e,t){console.error(e,t);let n="Error";"string"==typeof e&&(n=e),e.message?n=`${e.message} (See console for more info)`:e.stack&&(n=`${e.stack}`),this.logger.log("error",n)}logError(e,t){this.logger.log("error",`${e} ${t}`)}logWarning(e,t){this.logger.log("warning",`${e} ${t}`)}logInfo(e,t){this.logger.log("info",`${e} ${t}`)}logDebug(e,t){this.logger.log("debug",`${e} ${t}`)}};Ei([ae({type:String})],Ii.prototype,"examplespath",void 0),Ei([ae({type:Object})],Ii.prototype,"hass",void 0),Ei([ae({type:String||Object})],Ii.prototype,"_config",void 0),Ei([ae({type:Boolean})],Ii.prototype,"isDemo",void 0),Ei([ae({type:Boolean})],Ii.prototype,"isShowLog",void 0),Ei([ae({type:Function})],Ii.prototype,"notify",void 0),Ii=Ei([re("floorplan-element")],Ii); + `}clearLog(){this.logElement.querySelector("#log ul").innerHTML=""}updated(e){const t=Object.create(null,{updated:{get:()=>super.updated}});return Ai(this,void 0,void 0,(function*(){t.updated.call(this,e),e.has("_config")&&(yield this._configChanged(),yield this.hassChanged()),e.has("hass")&&(yield this.hassChanged())}))}_configChanged(){return Ai(this,void 0,void 0,(function*(){this._config&&(yield this.init())}))}hassChanged(){return Ai(this,void 0,void 0,(function*(){if(!this.hass||!this.config||!this.svg)return;const e=_i.deviceId();this.hass.states[`sensor.ha_floorplan_${e}`]={entity_id:`sensor.ha_floorplan_${e}`,state:"on",last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{device_class:"ha-floorplan",friendly_name:"ha-floorplan - Floorplan for Home Assistant",icon:"mdi:floor-plan",assumed_state:!1,hidden:!0},context:{}},this.isRulesLoaded?this.handleEntities():(this.initFloorplanRules(this.svg,this.config),this.isRulesLoaded=!0,yield this.handleEntities(!0))}))}get floorplanElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("floorplan")}get logElement(){var e;return null===(e=this.shadowRoot)||void 0===e?void 0:e.getElementById("log")}init(){return Ai(this,void 0,void 0,(function*(){try{const e=yield this.loadConfig(this._config,!1);if(this.isShowLog=void 0!==e.log_level,this.logger=new ki(this.logElement,e.log_level,e.console_log_level),this.logInfo("INIT","Floorplan for Home Assistant (ha-floorplan) v1.0.43"),!this.validateConfig(e))return;this.config=e,this.config.pages?yield this.initMultiPage():yield this.initSinglePage()}catch(e){this.handleError(e)}}))}initMultiPage(){return Ai(this,void 0,void 0,(function*(){try{yield this.loadPages(),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}initSinglePage(){return Ai(this,void 0,void 0,(function*(){try{yield this.loadStyleSheet(this.config.stylesheet);const e=this.getBestImage(this.config);this.svg=yield this.loadFloorplanSvg(e),this.initPageDisplay(),this.initVariables(),this.initStartupActions()}catch(e){this.handleError(e)}}))}loadConfig(e,t){return Ai(this,void 0,void 0,(function*(){if("string"==typeof e){let n;try{n=yield _i.fetchText(e,this.isDemo,this.examplespath,t)}catch(t){throw this.logError("CONFIG",`Error loading config: ${e}`),t}return wi.load(n)}return JSON.parse(JSON.stringify(e))}))}loadScript(e,t){return e?new Promise(((n,i)=>{var r;const s=document.createElement("script");s.src=t?e:_i.cacheBuster(e),s.onload=()=>n(),s.onerror=e=>{i(new URIError(`${e.target.src}`))},null===(r=this.shadowRoot)||void 0===r||r.appendChild(s)})):Promise.resolve()}loadPages(){return Ai(this,void 0,void 0,(function*(){for(const e of this.config.pages)yield this.loadPageConfig(e,this.config.pages.indexOf(e));const e=Object.keys(this.pageInfos).map((e=>this.pageInfos[e]));e.sort(((e,t)=>e.index-t.index));const t=e.find((e=>void 0!==e.config.master_page));if(!t)throw new Error("A master page is required");t.isMaster=!0;const n=e.find((e=>void 0===e.config.master_page));n&&(n.isDefault=!0),yield this.loadPageFloorplanSvg(t,t);const i=e.filter((e=>e!==t));for(const e of i)yield this.loadPageFloorplanSvg(e,t);this.svg=t.svg}))}loadPageConfig(e,t){return Ai(this,void 0,void 0,(function*(){const n=yield this.loadConfig(e,!1),i=this.createPageInfo(n);return i.index=t,i}))}loadPageFloorplanSvg(e,t){return Ai(this,void 0,void 0,(function*(){const n=this.getBestImage(e.config),i=yield this.loadFloorplanSvg(n,e,t);i.id=e.config.page_id,e.svg=i,yield this.loadStyleSheet(e.config.stylesheet),this.initFloorplanRules(e.svg,e.config)}))}getBestImage(e){var t;let n="",i=!0;if("string"==typeof e.image)n=_i.isMobile&&"string"==typeof e.image_mobile?e.image_mobile:e.image;else if(null===(t=e.image)||void 0===t?void 0:t.sizes){e.image.sizes.sort(((e,t)=>t.min_width-e.min_width));for(const t of e.image.sizes)if(screen.width>=t.min_width){n=t.location,i=!0===t.cache;break}}else _i.isMobile&&e.image_mobile?(n=e.image_mobile.location,i=!0===e.image_mobile.cache):(n=e.image.location,i=!0===e.image.cache);return{location:n,cache:i}}createPageInfo(e){const t={config:e};return t.config.rules&&this.config.rules&&(t.config.rules=t.config.rules.concat(this.config.rules)),this.pageInfos[t.config.page_id]=t,t}loadStyleSheet(e){return Ai(this,void 0,void 0,(function*(){const t="string"==typeof e?e:e.location,n="string"!=typeof e&&!0===e.cache;if(!t)return;let i;try{i=yield _i.fetchText(t,this.isDemo,this.examplespath,n)}catch(e){throw this.logError("STYLESHEET",`Error loading stylesheet: ${t}`),e}const r=document.createElement("style"),s=()=>{var e;r.innerHTML=i,null===(e=this.shadowRoot)||void 0===e||e.appendChild(r)};try{yield _i.waitForChildNodes(r,s,1e4)}catch(e){this.logError("STYLESHEET","Error loading stylesheet")}const a=this.getCssRules(r);this.cssRules=this.cssRules.concat(a)}))}getCssRules(e){var t,n,i,r,s,a;let o;if(e.sheet)o=null!==(n=null===(t=e.sheet)||void 0===t?void 0:t.cssRules)&&void 0!==n?n:null===(i=e.sheet)||void 0===i?void 0:i.rules;else{const t=e;t.styleSheet&&(o=null!==(s=null===(r=t.styleSheet)||void 0===r?void 0:r.cssRules)&&void 0!==s?s:null===(a=t.styleSheet)||void 0===a?void 0:a.rules)}return o?_i.getArray(o):[]}loadFloorplanSvg(e,t,n){var i;return Ai(this,void 0,void 0,(function*(){let r;try{r=yield _i.fetchText(e.location,this.isDemo,this.examplespath,e.cache)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e.location}`),t}const s=document.createElement("div");s.innerHTML=r;const a=s.querySelector("svg");if(t&&a.setAttribute("id",t.config.page_id),a.setAttribute("height","100%"),a.setAttribute("width","100%"),a.style.height="100%",a.style.width="100%",a.style.margin="auto",a.style.cursor="default",a.style.opacity="0",a.setAttribute("xmlns:xlink","http://www.w3.org/1999/xlink"),t&&n){const e=n.config.page_id,r=n.config.master_page.content_element;if(t.config.page_id===e)this.floorplanElement.replaceChildren(a);else{const e=this.floorplanElement.querySelector("#"+r),t=Number.parseFloat(a.getAttribute("height")),n=Number.parseFloat(a.getAttribute("width"));a.getAttribute("viewBox")||a.setAttribute("viewBox",`0 0 ${n} ${t}`),a.setAttribute("preserveAspectRatio","xMinYMin meet"),a.setAttribute("height",e.getAttribute("height")),a.setAttribute("width",e.getAttribute("width")),a.setAttribute("x",e.getAttribute("x")),a.setAttribute("y",e.getAttribute("y")),null===(i=e.parentElement)||void 0===i||i.replaceChildren(a)}}else this.floorplanElement.replaceChildren(a);return a}))}loadImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){return e.toLowerCase().includes(".svg")||"svg"===t.svgElement.nodeName||t.svgElement.querySelector("svg")?yield this.loadSvgImage(e,t,n,i,r):yield this.loadBitmapImage(e,t,n,i,r)}))}loadBitmapImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){e=r?e:_i.cacheBuster(e),this.logDebug("IMAGE",`${n} (setting image: ${e})`);let s=t.svgElement;return"image"!==s.nodeName&&(s=this.createImageElement(t.originalSvgElement),t.svgElement=this.replaceElement(t.svgElement,s),this.attachClickHandlers(s,t,n,void 0,i),s.onmouseover=()=>{this.handleEntityIdSetHoverOver(n,t)}),s.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href",e),s}))}loadSvgImage(e,t,n,i,r){return Ai(this,void 0,void 0,(function*(){let s;if(null==e?void 0:e.trim().length)try{s=yield _i.fetchText(e,this.isDemo,this.examplespath,r)}catch(t){throw this.logError("IMAGE",`Error loading image: ${e}`),t}else{const e=document.createElementNS("http://www.w3.org/2000/svg","svg");e.setAttribute("viewBox","0 0 0 0"),s=e.outerHTML}this.logDebug("IMAGE",`${n} (setting image: ${e})`);const a="g"===t.svgElement.nodeName?t.svgElement:document.createElement("div");a.innerHTML=s;const o=a.querySelector("svg"),c=Number.parseFloat(o.getAttribute("height")),l=Number.parseFloat(o.getAttribute("width"));if(o.getAttribute("viewBox")||o.setAttribute("viewBox",`0 0 ${l} ${c}`),o.id=t.svgElement.id,o.setAttribute("preserveAspectRatio","xMinYMin meet"),null!==t.originalBBox&&(o.setAttribute("height",t.originalBBox.height.toString()),o.setAttribute("width",t.originalBBox.width.toString()),o.setAttribute("x",t.originalBBox.x.toString()),o.setAttribute("y",t.originalBBox.y.toString())),"g"!==t.svgElement.nodeName){const e=t.svgElement.getAttribute("transform");e&&o.setAttribute("transform",e),t.svgElement=this.replaceElement(t.svgElement,o)}return this.attachClickHandlers(o,t,n,void 0,i),t.svgElement.onmouseover=()=>{this.handleEntityIdSetHoverOver(n,t)},o}))}_querySelectorAll(e,t=void 0,n){let i=t?Array.from(e.querySelectorAll(t).values()):[];return i=n?[e].concat(i):i,i}replaceElement(e,t){const n=e.parentElement;for(const n of Array.from(e.classList))t.classList.add(n);return this._querySelectorAll(e,"*",!0).forEach((e=>{Ci.off(e,"click"),Ci.off(e,"longClick"),e.remove()})),e.remove(),null==n||n.appendChild(t),t}initPageDisplay(){if(this.config.pages)for(const e of Object.values(this.pageInfos))e.svg.style.opacity="1",e.svg.style.display=e.isMaster||e.isDefault?"initial":"none";else this.svg.style.opacity="1",this.svg.style.display="block"}initVariables(){if(this.config.variables)for(const e of this.config.variables)this.initVariable(e);if(this.config.pages)for(const e of Object.values(this.pageInfos))if(e.config.variables)for(const t of e.config.variables)this.initVariable(t)}initVariable(e){let t,n;if("string"==typeof e?t=e:(t=e.name,n=e.value,e.value&&(n=this.evaluate(e.value,t,void 0))),!this.entityInfos[t]){const e={entityId:t,ruleInfos:[],lastState:void 0};this.entityInfos[t]=e}this.hass.states[t]||(this.hass.states[t]={entity_id:t,state:n,last_changed:(new Date).toString(),last_updated:(new Date).toString(),attributes:{},context:{}}),this.setVariable(t,n,{},!0)}getActionConfigs(e){var t,n;if(null==e)return[];if(Array.isArray(e)){for(const n of e)n.action=null!==(t=n.action)&&void 0!==t?t:"call-service";return e}return"object"==typeof e?(e.action=null!==(n=e.action)&&void 0!==n?n:"call-service",[e]):"string"==typeof e?e.includes(".")?[{action:"call-service",service:e}]:[{action:e}]:[]}initStartupActions(){if(this.handleActions(this.config.startup_action,void 0,void 0,void 0),this.config.pages)for(const e of Object.values(this.pageInfos))this.handleActions(e.config.startup_action,void 0,void 0,void 0)}initFloorplanRules(e,t){if(!t.rules)return;const n=this._querySelectorAll(e,"*",!0);for(const e of n)e.id&&(this.svgElements[e.id]=e);this.initRules(t,e,n)}initRules(e,t,n){if(e.functions&&(this.functions=this.evaluate(e.functions)),e.defaults){const t=e.defaults;for(const n of e.rules)n.hover_action=void 0===n.hover_action?t.hover_action:n.hover_action,n.tap_action=void 0===n.tap_action?t.tap_action:n.tap_action,n.hold_action=void 0===n.hold_action?t.hold_action:n.hold_action,n.hover_info_filter=void 0===n.hover_info_filter?t.hover_info_filter:n.hover_info_filter}for(const i of e.rules)i.entity||i.entities?this.initEntityRule(i,t,n):(i.element||i.elements)&&this.initElementRule(i,t,n)}initEntityRule(e,t,n){const i=this.initGetEntityRuleEntities(e);for(const r of i){const i=r.entityId;let s=this.entityInfos[i];s||(s={entityId:i,ruleInfos:[],lastState:void 0},this.entityInfos[i]=s);const a=new pe(e);s.ruleInfos.push(a);for(const e of r.elementIds){const r=n.find((t=>t.id===e));if(!r){this.logWarning("CONFIG",`Cannot find element '${e}' in SVG file`);continue}const o=this.addSvgElementToRule(t,r,a);o.svgElement=r,r.querySelector("title")||r.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.onmouseenter=()=>{this.handleEntitySetHoverOver(s,o)},r.onmouseleave=()=>{this.handleEntitySetHoverOver(s,o)},this.attachClickHandlers(r,o,i,void 0,a)}}}initGetEntityRuleEntities(e){const t=[];e.groups=e.groups?e.groups:[];for(const n of e.groups){const e=this.hass.states[n];if(e)for(const n of e.attributes.entity_id)this.addTargetEntity(n,[n],t);else this.logWarning("CONFIG",`Cannot find '${n}' in Home Assistant groups`)}e.entities=e.entities?e.entities:[],e.entities=e.entity?e.entities.concat(e.entity):e.entities;const n=e.entities.filter((e=>"string"==typeof e));for(const i of n){let n=[];e.elements?n=n.concat(e.elements):e.element?n=n.concat(this.evaluate(e.element,i,void 0)):null!==e.element&&(n=n.concat(i)),this.addTargetEntity(i,n,t)}const i=e.entities.filter((e=>"string"!=typeof e));for(const e of i){const n=e;this.addTargetEntity(n.entity,[n.element],t)}return t}addTargetEntity(e,t,n){const i=this.hass.states[e],r="floorplan"===e.split(".")[0];i||r?n.push({entityId:e,elementIds:t}):this.logWarning("CONFIG",`Cannot find '${e}' in Home Assistant entities`)}initElementRule(e,t,n){if(e.element||e.elements){e.elements=e.elements?e.elements:[],e.elements=e.element?e.elements.concat(e.element):e.elements;for(const i of e.elements){const r=n.find((e=>e.id===i));if(r){let n=this.elementInfos[i];n||(n={ruleInfos:[],lastState:void 0},this.elementInfos[i]=n);const s=new pe(e);n.ruleInfos.push(s);const a=this.addSvgElementToRule(t,r,s);this.attachClickHandlers(r,a,void 0,i,s)}else this.logWarning("CONFIG",`Cannot find '${i}' in SVG file`)}}}attachClickHandlers(e,t,n,i,r){this._querySelectorAll(e,void 0,!0).forEach((s=>{const a=s,o=s===e;if(a.querySelector("title")||a.appendChild(document.createElementNS("http://www.w3.org/2000/svg","title")),r.rule.tap_action||r.rule.double_tap_action){const e=!!r.rule.tap_action&&this.getActionConfigs(r.rule.tap_action),s=!!r.rule.double_tap_action&&this.getActionConfigs(r.rule.double_tap_action),c=!!e&&new de(this,n,i,t,r,e);if(e&&!s&&Ci.on(a,"click",this.onClick.bind(c)),s){const o=!!s&&new de(this,n,i,t,r,s);Ce.observe(a),e&&Ci.on(a,"singleClick",this.onClick.bind(c)),Ci.on(a,"doubleClick",this.onLongClick.bind(o))}a.style&&(a.style.cursor="pointer"),_i.addClass(a,"floorplan-click"+(o?"":"-child"))}if(r.rule.hold_action){const e=this.getActionConfigs(r.rule.hold_action),s=new de(this,n,i,t,r,e);ke.observe(a),Ci.on(a,"longClick",this.onLongClick.bind(s)),a.style&&(a.style.cursor="pointer"),_i.addClass(a,"floorplan-long-click"+(o?"":"-child"))}}))}addSvgElementToRule(e,t,n){const i=t.getBBox?t.getBBox():null,r=new ue(t.id,t,t,i);return n.svgElementInfos[t.id]=r,r}createImageElement(e){const t=document.createElementNS("http://www.w3.org/2000/svg","image");return t.setAttribute("id",e.getAttribute("id")),t.setAttribute("x",e.getAttribute("x")),t.setAttribute("y",e.getAttribute("y")),t.setAttribute("height",e.getAttribute("height")),t.setAttribute("width",e.getAttribute("width")),t}handleEntities(e=!1){return Ai(this,void 0,void 0,(function*(){this.handleElements();const t=this.getChangedEntities(e);for(const e of Object.keys(this.variables))t.add(e);if(t.size)for(const e of t)yield this.handleEntity(e)}))}getChangedEntities(e){const t=new Set,n=Object.keys(this.hass.states),i=_i.deviceId();for(const r of n)if(r!==`sensor.ha_floorplan_${i}`||t.has(r)){const n=this.entityInfos[r];if(n){const i=this.hass.states[r];if(e)this.logDebug("STATE",`${r}: ${i.state} (initial load)`),t.has(r)||t.add(r);else if(n.lastState){const e=i.state;i.last_changed!==n.lastState.last_changed?(this.logDebug("STATE",`${r}: ${e} (last changed ${_i.formatDate(n.lastState.last_changed)})`),t.has(r)||t.add(r)):_i.equal(n.lastState.attributes,i.attributes)||(this.logDebug("STATE",`${r}: attributes (last updated ${_i.formatDate(n.lastState.last_changed)})`),t.has(r)||t.add(r))}}}else t.add(r);return t}handleEntity(e){return Ai(this,void 0,void 0,(function*(){const t=this.hass.states[e],n=this.entityInfos[e];if(n){n.lastState=Object.assign({},t);for(const e of n.ruleInfos){const t=Object.values(e.svgElementInfos);if(t.length)for(const i of t)i.svgElement&&this.handleActions(e.rule.state_action,n.entityId,i,e);else this.handleActions(e.rule.state_action,n.entityId,void 0,e)}}}))}handleElements(){return Ai(this,void 0,void 0,(function*(){for(const e of Object.values(this.elementInfos))for(const t of e.ruleInfos)for(const e of Object.values(t.svgElementInfos))this.handleActions(t.rule.state_action,void 0,e,t)}))}handleEntityIdSetHoverOver(e,t){const n=this.entityInfos[e];n&&this.handleEntitySetHoverOver(n,t)}handleEntitySetHoverOver(e,t){const n=e.entityId,i=this.hass.states[n];for(const n of e.ruleInfos)if(n.rule.hover_action){let r="string"==typeof n.rule.hover_action&&"hover-info"===n.rule.hover_action;if(r=r||"object"==typeof n.rule.hover_action&&"hover-info"===n.rule.hover_action.action,r=r||Array.isArray(n.rule.hover_action)&&n.rule.hover_action.some((e=>"hover-info"===e.action)),r){const e=new Set(n.rule.hover_info_filter);for(const t of Object.values(n.svgElementInfos))_i.addClass(t.svgElement,"floorplan-hover"),t.svgElement.style.cursor="pointer",t.svgElement.querySelectorAll("title").forEach((t=>{let n=`${i.attributes.friendly_name}\n`;n+=`State: ${i.state}\n\n`,Object.keys(i.attributes).map((t=>{e.has(t)||(n+=`${t}: ${i.attributes[t]}\n`)})),n+="\n",n+=`Last changed: ${Me.timeago(i.last_changed)}\n`,n+=`Last updated: ${Me.timeago(i.last_updated)}`,t.textContent=n}))}else n.rule.hover_action&&this.handleActions(n.rule.hover_action,e.entityId,t,n)}}isOptionEnabled(e){return null===e||void 0!==e}validateConfig(e){let t=!0;if(e.pages||e.rules)if(e.pages)e.pages.length||this.logWarning("CONFIG","The 'pages' section must contain one or more pages in floorplan configuration");else{e.rules||this.logWarning("CONFIG","Cannot find 'rules' in floorplan configuration");let n=e.rules.filter((e=>e.entities&&e.elements));n.length&&(this.logError("CONFIG","A rule cannot contain both 'entities' and 'elements' in floorplan configuration"),t=!1),n=e.rules.filter((e=>!(e.entity||e.entities||e.element||e.elements))),n.length&&(this.logError("CONFIG","A rule must contain either 'entities' or 'elements' in floorplan configuration"),t=!1)}else this.logWarning("CONFIG","Cannot find 'pages' nor 'rules' in floorplan configuration");return t}evaluate(e,t,n){if("string"!=typeof e||!De.isCode(e))return e;try{return De.evaluate(e,this.hass,this.config,t,n,this.svgElements,this.functions)}catch(i){return this.handleError(i,{expression:e,entityId:t,hass:this.hass,svgElement:n})}}onClick(e){e.stopPropagation(),e.preventDefault();const t=this;t.instance.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}onLongClick(e){e.stopPropagation(),e.preventDefault();const t=this,n=t.instance;setTimeout((()=>{n.handleActions(t.actions,t.entityId,t.svgElementInfo,t.ruleInfo)}),300)}handleActions(e,t,n,i){var r;const s=this.getActionConfigs(e);for(const e of s){if(e.confirmation&&(!e.confirmation.exemptions||!e.confirmation.exemptions.some((e=>e.user===this.hass.user.id)))&&!confirm(e.confirmation.text||`Are you sure you want to ${e.action}?`))return;switch(e.action){case"more-info":this.isDemo?this.notify(`Performing action: ${e.action} ${t}`):le(this,"hass-more-info",{entityId:t});break;case"navigate":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.navigation_path}`);else{const i=this.evaluate(e.navigation_path,t,null==n?void 0:n.svgElement);he(0,i,null!==(r=e.navigation_replace)&&void 0!==r&&r)}break;case"url":if(this.isDemo)this.notify(`Performing action: ${e.action} ${e.url_path}`);else{const i=e.same_tab?"_self":"_blank",r=this.evaluate(e.url_path,t,null==n?void 0:n.svgElement);window.open(r,i)}break;case"toggle":if(t){const e={action:"call-service",service:"homeassistant.toggle",service_data:{entity_id:t}};this.callService(e,t,n,i)}break;case"call-service":if(!e.service)return;this.callService(e,t,n,i);break;case"fire-dom-event":le(this,"ll-custom",e)}}}getSvgElementsFromServiceData(e,t){let n=[],i=[];if(Array.isArray(null==e?void 0:e.elements)&&(i=i.concat(null==e?void 0:e.elements)),"string"==typeof(null==e?void 0:e.element)&&(i=i.concat([null==e?void 0:e.element])),i.length)for(const e of i)n=n.concat(this._querySelectorAll(this.svg,`#${e.replace(/\./g,"\\.")}`,!1));else t&&(n=[t]);return n}getServiceData(e,t,n){let i={};if("object"==typeof e.service_data)for(const r of Object.keys(e.service_data))i[r]=this.evaluate(e.service_data[r],t,n);else if("string"==typeof e.service_data){const r=this.evaluate(e.service_data,t,n);i="string"==typeof r&&r.trim().startsWith("{")?JSON.parse(r):r}else void 0!==e.service_data&&(i=e.service_data);return i}executeServiceData(e,t,n){try{if("object"==typeof e.service_data)for(const i of Object.keys(e.service_data))this.evaluate(e.service_data[i],t,n);else"string"==typeof e.service_data?this.evaluate(e.service_data,t,n):void 0!==e.service_data&&this.logWarning("CONFIG","Invalid execution data");return!0}catch(e){return this.logWarning("CONFIG","Error thrown while executing service"),!1}}callService(e,t,n,i){const r=this.evaluate(e.service,t,null==n?void 0:n.svgElement),[s,a]=r.split(".",2);if("floorplan"===s)this.callFloorplanService(s,a,e,t,n,i);else this.callHomeAssistantService(s,a,e,t,n)}callFloorplanService(e,t,n,i,r,s){var a,o,c;const l=null!==(a=null==r?void 0:r.svgElement)&&void 0!==a?a:void 0;let h,u,p,d,f,g,m,v,y,b=[],x=null;switch(x=!["execute"].includes(t)?this.getServiceData(n,i,l):{},t){case"class_toggle":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),p="string"==typeof x?x:x.class,_i.toggleClass(e,p);break;case"class_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),p="string"==typeof x?x:x.class,_i.setClass(e,p);break;case"dataset_set":{let e,t;if("string"==typeof x){const n=x.split(":");if(n.length<2){this.logError("FLOORPLAN_ACTION",`Service data "${x}" is not a valid dataset key value pair.`);break}e=n[1],t=n[0]}else e=x.value,t=x.key;b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const s of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,s)),_i.datasetSet(s,t,e);break}case"style_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),d="string"==typeof x?x:x.style,_i.setStyle(e,d);break;case"text_set":b=this.getSvgElementsFromServiceData(x,null==r?void 0:r.svgElement);for(const e of b){y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||(x=this.getServiceData(n,i,e)),v="string"==typeof x?x:x.text;const t=(null===(o=n.service_data)||void 0===o?void 0:o.shift_y_axis)?null===(c=n.service_data)||void 0===c?void 0:c.shift_y_axis:"1em";_i.setText(e,v,t)}break;case"image_set":r&&s&&(x=this.getServiceData(n,i,null==r?void 0:r.svgElement),f="string"==typeof x?x:x.image,g="object"==typeof x?x.image_refresh_interval:0,m=!(g>0)&&("object"!=typeof x||!0===x.cache),s.imageLoader&&clearInterval(s.imageLoader),g&&(s.imageLoader=setInterval(this.loadImage.bind(this),1e3*g,f,r,i,s,m)),this.loadImage(f,r,i,s,m));break;case"page_navigate":x=this.getServiceData(n,i,null==r?void 0:r.svgElement),h=x.page_id,u=h?this.pageInfos[h]:void 0,u&&(Object.keys(this.pageInfos).map((e=>{const t=this.pageInfos[e];t.isMaster||"none"===t.svg.style.display||(t.svg.style.display="none")})),u.svg.style.display="block");break;case"variable_set":if(x=this.getServiceData(n,i,null==r?void 0:r.svgElement),x.variable){const e={};if(x.attributes){const t=x.attributes;for(const n of Object.keys(t))e[n]=this.getActionValue(t[n],i,l)}const t=x,n=this.getActionValue(t,i,l);this.setVariable(x.variable,n,e,!1)}break;case"execute":this.executeServiceData(n,i,null==r?void 0:r.svgElement);for(const e of b)y=1===b.length&&b[0]===(null==r?void 0:r.svgElement),y||this.executeServiceData(n,i,e)}}getActionValue(e,t,n){let i=e.value;return e.value&&(i=this.evaluate(e.value,t,n)),i}setVariable(e,t,n,i){if(this.variables[e]=t,this.hass.states[e]){this.hass.states[e].state=t.toString();for(const t of Object.keys(n))this.hass.states[e].attributes[t]=n[t]}for(const e of Object.keys(this.variables)){const t=this.hass.states[e];t&&(t.last_changed=(new Date).toString())}i||this.handleEntities()}callHomeAssistantService(e,t,n,i,r){const s=this.getServiceData(n,i,null==r?void 0:r.svgElement);"object"==typeof s&&(null===s.entity_id||Array.isArray(s.entity_id)&&!s.entity_id.length||!s.entity_id&&i&&(s.entity_id=i)),this.hass.callService(e,t,s),this.isDemo&&this.notify(`Calling service: ${e}.${t} (${s.entity_id})`)}handleWindowError(e,t,n,i,r){if(e.toLowerCase().includes("script error"))this.logError("SCRIPT","Script error: See browser console for detail");else{const s=[e,"URL: "+t,"Line: "+n+", column: "+i,"Error: "+JSON.stringify(r)].join("
");this.logError("ERROR",s)}return!1}handleError(e,t){console.error(e,t);let n="Error";"string"==typeof e&&(n=e),e.message?n=`${e.message} (See console for more info)`:e.stack&&(n=`${e.stack}`),this.logger.log("error",n)}logError(e,t){this.logger.log("error",`${e} ${t}`)}logWarning(e,t){this.logger.log("warning",`${e} ${t}`)}logInfo(e,t){this.logger.log("info",`${e} ${t}`)}logDebug(e,t){this.logger.log("debug",`${e} ${t}`)}};Ei([ae({type:String})],Ii.prototype,"examplespath",void 0),Ei([ae({type:Object})],Ii.prototype,"hass",void 0),Ei([ae({type:String||Object})],Ii.prototype,"_config",void 0),Ei([ae({type:Boolean})],Ii.prototype,"isDemo",void 0),Ei([ae({type:Boolean})],Ii.prototype,"isShowLog",void 0),Ei([ae({type:Function})],Ii.prototype,"notify",void 0),Ii=Ei([re("floorplan-element")],Ii); /** * @license * Copyright 2017 Google LLC