diff --git a/card-mod.js b/card-mod.js index 40b37af..6575169 100644 --- a/card-mod.js +++ b/card-mod.js @@ -1,4 +1,4 @@ -const e="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,t=(e,t,s=null)=>{for(;t!==s;){const s=t.nextSibling;e.removeChild(t),t=s}},s=`{{lit-${String(Math.random()).slice(2)}}}`,n=`\x3c!--${s}--\x3e`,o=new RegExp(`${s}|${n}`);class i{constructor(e,t){this.parts=[],this.element=t;const n=[],i=[],a=document.createTreeWalker(t.content,133,null,!1);let c=0,h=-1,p=0;const{strings:u,values:{length:m}}=e;for(;p0;){const t=u[p],s=l.exec(t)[2],n=s.toLowerCase()+"$lit$",i=e.getAttribute(n);e.removeAttribute(n);const r=i.split(o);this.parts.push({type:"attribute",index:h,name:s,strings:r}),p+=r.length-1}}"TEMPLATE"===e.tagName&&(i.push(e),a.currentNode=e.content)}else if(3===e.nodeType){const t=e.data;if(t.indexOf(s)>=0){const s=e.parentNode,i=t.split(o),a=i.length-1;for(let t=0;t{const s=e.length-t.length;return s>=0&&e.slice(s)===t},a=e=>-1!==e.index,d=()=>document.createComment(""),l=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function c(e,t){const{element:{content:s},parts:n}=e,o=document.createTreeWalker(s,133,null,!1);let i=p(n),r=n[i],a=-1,d=0;const l=[];let c=null;for(;o.nextNode();){a++;const e=o.currentNode;for(e.previousSibling===c&&(c=null),t.has(e)&&(l.push(e),null===c&&(c=e)),null!==c&&d++;void 0!==r&&r.index===a;)r.index=null!==c?-1:r.index-d,i=p(n,i),r=n[i]}l.forEach((e=>e.parentNode.removeChild(e)))}const h=e=>{let t=11===e.nodeType?0:1;const s=document.createTreeWalker(e,133,null,!1);for(;s.nextNode();)t++;return t},p=(e,t=-1)=>{for(let s=t+1;s"function"==typeof e&&u.has(e),f={},y={};class _{constructor(e,t,s){this.__parts=[],this.template=e,this.processor=t,this.options=s}update(e){let t=0;for(const s of this.__parts)void 0!==s&&s.setValue(e[t]),t++;for(const e of this.__parts)void 0!==e&&e.commit()}_clone(){const t=e?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),s=[],n=this.template.parts,o=document.createTreeWalker(t,133,null,!1);let i,r=0,d=0,l=o.nextNode();for(;re}),v=` ${s} `;class w{constructor(e,t,s,n){this.strings=e,this.values=t,this.type=s,this.processor=n}getHTML(){const e=this.strings.length-1;let t="",o=!1;for(let i=0;i-1||o)&&-1===e.indexOf("--\x3e",r+1);const a=l.exec(e);t+=null===a?e+(o?v:n):e.substr(0,a.index)+a[1]+a[2]+"$lit$"+a[3]+s}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");let t=this.getHTML();return void 0!==g&&(t=g.createHTML(t)),e.innerHTML=t,e}}const S=e=>null===e||!("object"==typeof e||"function"==typeof e),b=e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]);class E{constructor(e,t,s){this.dirty=!0,this.element=e,this.name=t,this.strings=s,this.parts=[];for(let e=0;e{try{const e={get capture(){return A=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();class O{constructor(e,t,s){this.value=void 0,this.__pendingValue=void 0,this.element=e,this.eventName=t,this.eventContext=s,this.__boundHandleEvent=e=>this.handleEvent(e)}setValue(e){this.__pendingValue=e}commit(){for(;m(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=f,e(this)}if(this.__pendingValue===f)return;const e=this.__pendingValue,t=this.value,s=null==e||null!=t&&(e.capture!==t.capture||e.once!==t.once||e.passive!==t.passive),n=null!=e&&(null==t||s);s&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=R(e),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=e,this.__pendingValue=f}handleEvent(e){"function"==typeof this.value?this.value.call(this.eventContext||this.element,e):this.value.handleEvent(e)}}const R=e=>e&&(A?{capture:e.capture,passive:e.passive,once:e.once}:e.capture);function U(e){let t=$.get(e.type);void 0===t&&(t={stringsArray:new WeakMap,keyString:new Map},$.set(e.type,t));let n=t.stringsArray.get(e.strings);if(void 0!==n)return n;const o=e.strings.join(s);return n=t.keyString.get(o),void 0===n&&(n=new i(e,e.getTemplateElement()),t.keyString.set(o,n)),t.stringsArray.set(e.strings,n),n}const $=new Map,M=new WeakMap;const k=new class{handleAttributeExpressions(e,t,s,n){const o=t[0];if("."===o){return new x(e,t.slice(1),s).parts}if("@"===o)return[new O(e,t.slice(1),n.eventContext)];if("?"===o)return[new P(e,t.slice(1),s)];return new E(e,t,s).parts}handleTextExpression(e){return new N(e)}};"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.3.0");const V=(e,...t)=>new w(e,t,"html",k),q=(e,t)=>`${e}--${t}`;let D=!0;void 0===window.ShadyCSS?D=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),D=!1);const L=e=>t=>{const n=q(t.type,e);let o=$.get(n);void 0===o&&(o={stringsArray:new WeakMap,keyString:new Map},$.set(n,o));let r=o.stringsArray.get(t.strings);if(void 0!==r)return r;const a=t.strings.join(s);if(r=o.keyString.get(a),void 0===r){const s=t.getTemplateElement();D&&window.ShadyCSS.prepareTemplateDom(s,e),r=new i(t,s),o.keyString.set(a,r)}return o.stringsArray.set(t.strings,r),r},I=["html","svg"],j=new Set,z=(e,t,s)=>{j.add(e);const n=s?s.element:document.createElement("template"),o=t.querySelectorAll("style"),{length:i}=o;if(0===i)return void window.ShadyCSS.prepareTemplateStyles(n,e);const r=document.createElement("style");for(let e=0;e{I.forEach((t=>{const s=$.get(q(t,e));void 0!==s&&s.keyString.forEach((e=>{const{element:{content:t}}=e,s=new Set;Array.from(t.querySelectorAll("style")).forEach((e=>{s.add(e)})),c(e,s)}))}))})(e);const a=n.content;s?function(e,t,s=null){const{element:{content:n},parts:o}=e;if(null==s)return void n.appendChild(t);const i=document.createTreeWalker(n,133,null,!1);let r=p(o),a=0,d=-1;for(;i.nextNode();)for(d++,i.currentNode===s&&(a=h(t),s.parentNode.insertBefore(t,s));-1!==r&&o[r].index===d;){if(a>0){for(;-1!==r;)o[r].index+=a,r=p(o,r);return}r=p(o,r)}}(s,r,a.firstChild):a.insertBefore(r,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,e);const d=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==d)t.insertBefore(d.cloneNode(!0),t.firstChild);else if(s){a.insertBefore(r,a.firstChild);const e=new Set;e.add(r),c(s,e)}};window.JSCompiler_renameProperty=(e,t)=>e;const H={toAttribute(e,t){switch(t){case Boolean:return e?"":null;case Object:case Array:return null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){switch(t){case Boolean:return null!==e;case Number:return null===e?null:Number(e);case Object:case Array:return JSON.parse(e)}return e}},J=(e,t)=>t!==e&&(t==t||e==e),F={attribute:!0,type:String,converter:H,reflect:!1,hasChanged:J};class B extends HTMLElement{constructor(){super(),this.initialize()}static get observedAttributes(){this.finalize();const e=[];return this._classProperties.forEach(((t,s)=>{const n=this._attributeNameForProperty(s,t);void 0!==n&&(this._attributeToPropertyMap.set(n,s),e.push(n))})),e}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const e=Object.getPrototypeOf(this)._classProperties;void 0!==e&&e.forEach(((e,t)=>this._classProperties.set(t,e)))}}static createProperty(e,t=F){if(this._ensureClassProperties(),this._classProperties.set(e,t),t.noAccessor||this.prototype.hasOwnProperty(e))return;const s="symbol"==typeof e?Symbol():`__${e}`,n=this.getPropertyDescriptor(e,s,t);void 0!==n&&Object.defineProperty(this.prototype,e,n)}static getPropertyDescriptor(e,t,s){return{get(){return this[t]},set(n){const o=this[e];this[t]=n,this.requestUpdateInternal(e,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this._classProperties&&this._classProperties.get(e)||F}static finalize(){const e=Object.getPrototypeOf(this);if(e.hasOwnProperty("finalized")||e.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const e=this.properties,t=[...Object.getOwnPropertyNames(e),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e):[]];for(const s of t)this.createProperty(s,e[s])}}static _attributeNameForProperty(e,t){const s=t.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof e?e.toLowerCase():void 0}static _valueHasChanged(e,t,s=J){return s(e,t)}static _propertyValueFromAttribute(e,t){const s=t.type,n=t.converter||H,o="function"==typeof n?n:n.fromAttribute;return o?o(e,s):e}static _propertyValueToAttribute(e,t){if(void 0===t.reflect)return;const s=t.type,n=t.converter;return(n&&n.toAttribute||H.toAttribute)(e,s)}initialize(){this._updateState=0,this._updatePromise=new Promise((e=>this._enableUpdatingResolver=e)),this._changedProperties=new Map,this._saveInstanceProperties(),this.requestUpdateInternal()}_saveInstanceProperties(){this.constructor._classProperties.forEach(((e,t)=>{if(this.hasOwnProperty(t)){const e=this[t];delete this[t],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(t,e)}}))}_applyInstanceProperties(){this._instanceProperties.forEach(((e,t)=>this[t]=e)),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(e,t,s){t!==s&&this._attributeToProperty(e,s)}_propertyToAttribute(e,t,s=F){const n=this.constructor,o=n._attributeNameForProperty(e,s);if(void 0!==o){const e=n._propertyValueToAttribute(t,s);if(void 0===e)return;this._updateState=8|this._updateState,null==e?this.removeAttribute(o):this.setAttribute(o,e),this._updateState=-9&this._updateState}}_attributeToProperty(e,t){if(8&this._updateState)return;const s=this.constructor,n=s._attributeToPropertyMap.get(e);if(void 0!==n){const e=s.getPropertyOptions(n);this._updateState=16|this._updateState,this[n]=s._propertyValueFromAttribute(t,e),this._updateState=-17&this._updateState}}requestUpdateInternal(e,t,s){let n=!0;if(void 0!==e){const o=this.constructor;s=s||o.getPropertyOptions(e),o._valueHasChanged(this[e],t,s.hasChanged)?(this._changedProperties.has(e)||this._changedProperties.set(e,t),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(e,s))):n=!1}!this._hasRequestedUpdate&&n&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(e,t){return this.requestUpdateInternal(e,t),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const e=this.performUpdate();return null!=e&&await e,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){if(!this._hasRequestedUpdate)return;this._instanceProperties&&this._applyInstanceProperties();let e=!1;const t=this._changedProperties;try{e=this.shouldUpdate(t),e?this.update(t):this._markUpdated()}catch(t){throw e=!1,this._markUpdated(),t}e&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(t)),this.updated(t))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(e){return!0}update(e){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach(((e,t)=>this._propertyToAttribute(t,this[t],e))),this._reflectingProperties=void 0),this._markUpdated()}updated(e){}firstUpdated(e){}}B.finalized=!0;const W=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?Object.assign(Object.assign({},t),{finisher(s){s.createProperty(t.key,e)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(s){s.createProperty(t.key,e)}};const Y=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,G=Symbol();class K{constructor(e,t){if(t!==G)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e}get styleSheet(){return void 0===this._styleSheet&&(Y?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}(window.litElementVersions||(window.litElementVersions=[])).push("2.4.0");const Q={};class X extends B{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const e=this.getStyles();if(Array.isArray(e)){const t=(e,s)=>e.reduceRight(((e,s)=>Array.isArray(s)?t(s,e):(e.add(s),e)),s),s=t(e,new Set),n=[];s.forEach((e=>n.unshift(e))),this._styles=n}else this._styles=void 0===e?[]:[e];this._styles=this._styles.map((e=>{if(e instanceof CSSStyleSheet&&!Y){const t=Array.prototype.slice.call(e.cssRules).reduce(((e,t)=>e+t.cssText),"");return new K(String(t),G)}return e}))}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const e=this.constructor._styles;0!==e.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Y?this.renderRoot.adoptedStyleSheets=e.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(e.map((e=>e.cssText)),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(e){const t=this.render();super.update(e),t!==Q&&this.constructor.render(t,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach((e=>{const t=document.createElement("style");t.textContent=e.cssText,this.renderRoot.appendChild(t)})))}render(){return Q}}function Z(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}X.finalized=!0,X.render=(e,s,n)=>{if(!n||"object"!=typeof n||!n.scopeName)throw new Error("The `scopeName` option is required.");const o=n.scopeName,i=M.has(s),r=D&&11===s.nodeType&&!!s.host,a=r&&!j.has(o),d=a?document.createDocumentFragment():s;if(((e,s,n)=>{let o=M.get(s);void 0===o&&(t(s,s.firstChild),M.set(s,o=new N(Object.assign({templateFactory:U},n))),o.appendInto(s)),o.setValue(e),o.commit()})(e,d,Object.assign({templateFactory:L(o)},n)),a){const e=M.get(d);M.delete(d);const n=e.value instanceof _?e.value.template:void 0;z(o,d,n),t(s,s.firstChild),s.appendChild(d),M.set(s,e)}!i&&r&&window.ShadyCSS.styleElement(s.host)};const ee="lovelace-player-device-id";function te(){if(!localStorage[ee]){const e=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[ee]=fully.getDeviceId():localStorage[ee]=`${e()}${e()}-${e()}${e()}`}return localStorage[ee]}let se=te();const ne=new URLSearchParams(window.location.search);var oe;ne.get("deviceID")&&null!==(oe=ne.get("deviceID"))&&("clear"===oe?localStorage.removeItem(ee):localStorage[ee]=oe,se=te()),window.cardMod_template_cache=window.cardMod_template_cache||{};const ie=window.cardMod_template_cache;async function re(e,t,s){const n=Z().connection,o=JSON.stringify([t,s]);let i=ie[o];i?(e(i.value),i.callbacks.add(e)):(e(""),s=Object.assign({user:Z().user.name,browser:se,hash:location.hash.substr(1)||""},s),ie[o]=i={template:t,variables:s,value:"",callbacks:new Set([e]),unsubscribe:n.subscribeMessage((e=>function(e,t){const s=ie[e];s&&(s.value=t.result,s.callbacks.forEach((e=>e(t.result))))}(o,e)),{type:"render_template",template:t,variables:s})})}var ae="3.0.3";async function de(e,t,s=!1){let n=e;"string"==typeof t&&(t=t.split(/(\$| )/)),""===t[t.length-1]&&t.pop();for(const[e,o]of t.entries())if(o.trim().length){if(!n)return null;n.localName&&n.localName.includes("-")&&await customElements.whenDefined(n.localName),n.updateComplete&&await n.updateComplete,n="$"===o?s&&e==t.length-1?[n.shadowRoot]:n.shadowRoot:s&&e==t.length-1?n.querySelectorAll(o):n.querySelector(o)}return n}async function le(e,t,s=!1,n=1e4){return Promise.race([de(e,t,s),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),n)))]).catch((e=>{if(!e.message||"timeout"!==e.message)throw e;return null}))}const ce=async e=>{await(async()=>{if(customElements.get("developer-tools-event"))return;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");e.hass={panels:[{url_path:"tmp",component_name:"developer-tools"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),await customElements.whenDefined("developer-tools-router");const t=document.createElement("developer-tools-router");await t.routerOptions.routes.event.load()})();return document.createElement("developer-tools-event")._computeParsedEventData(e)};async function he(e,t,s="",n={},o=null,i=!0){var r;let a;(null===(r=e.localName)||void 0===r?void 0:r.includes("-"))&&await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete,void 0===e._cardMod&&(e._cardMod=[]);for(const s of e._cardMod)if(s.type===t){a=s;break}a||(a=document.createElement("card-mod"),a.type=t,e._cardMod.push(a));return(e.modElement?e.modElement:i&&e.shadowRoot||e).appendChild(a),a.variables=n,a.styles=s,a}function pe(e,t){const s=e=>e&&"object"==typeof e&&!Array.isArray(e);if(s(e)&&s(t))for(const n in t)s(t[n])?(e[n]||Object.assign(e,{[n]:{}}),"string"==typeof e[n]&&(e[n]={".":e[n]}),pe(e[n],t[n])):e[n]?e[n]=t[n]+e[n]:e[n]=t[n];return e}function ue(e){return e.config?e.config:e._config?e._config:e.host?ue(e.host):e.parentElement?ue(e.parentElement):e.parentNode?ue(e.parentNode):null}function me(e,t){for(const s of t)e.add(s)}async function fe(e,t=0){let s=new Set;return 10==t?s:e?(e._cardMod&&e._cardMod.style&&s.add(e._cardMod),e.updateComplete&&await e.updateComplete,e.parentElement&&me(s,await fe(e.parentElement,t+1)),e.parentNode&&me(s,await fe(e.parentNode,t+1)),e.host&&me(s,await fe(e.host,t+1)),s):s}function ye(e){if(!e)return;const t=e.parentElement||e.parentNode;return t.host?t.host:t}class _e extends X{constructor(){super(),this._rendered_styles="",this._styleChildren=new Set,this._refreshCooldown={running:!1,repeat:!1},this._observer=new MutationObserver((e=>{for(const t of e){if("card-mod"===t.target.localName)return;let e=!0;if(t.addedNodes.length&&t.addedNodes.forEach((t=>{"card-mod"!==t.localName&&(e=!1)})),e)return;e=!0,t.removedNodes.length&&t.removedNodes.forEach((t=>{"card-mod"!==t.localName&&(e=!1)}))}this.refresh()})),document.querySelector("home-assistant").addEventListener("settheme",(()=>this.refresh()))}static get applyToElement(){return he}connectedCallback(){super.connectedCallback(),this.refresh(),this.setAttribute("slot","none")}disconnectedCallback(){super.disconnectedCallback(),this._disconnect()}set styles(e){this._input_styles=e,this.refresh()}refresh(){this._refreshCooldown.running?this._refreshCooldown.repeat=!0:(window.setTimeout((()=>{this._refreshCooldown.running=!1,this._refreshCooldown.repeat&&this.refresh()}),1),this._refreshCooldown.repeat=!1,this._disconnect().then((()=>this._connect(this._input_styles))))}async _connect(e){let t=JSON.parse(JSON.stringify(e||{}));"string"==typeof t&&(t={".":t});pe(t,await async function(e){if(!e.type)return null;const t=e.parentElement?e.parentElement:e,s=window.getComputedStyle(t).getPropertyValue("--card-mod-theme"),n=Z().themes.themes;return n[s]?n[s][`card-mod-${e.type}-yaml`]?ce(n[s][`card-mod-${e.type}-yaml`]):n[s][`card-mod-${e.type}`]?{".":n[s][`card-mod-${e.type}`]}:{}:{}}(this));const s=this.parentElement||this.parentNode;for(const[e,n]of Object.entries(t))if("."===e)this._styles=n;else for(const t of await le(s,e,!0))this._styleChildren.add(await he(t,`${this.type}-child`,n,this.variables,null,!1));var n;this._styles&&(n=this._styles,String(n).includes("{%")||String(n).includes("{{"))?(this._renderer=this._renderer||this._style_rendered.bind(this),re(this._renderer,this._styles,this.variables)):this._style_rendered(this._styles||""),this._observer.observe(ye(this),{childList:!0});const o=ye(ye(this));if(this._observer.observe(o,{childList:!0}),o&&o.updated&&!o._cm_update_patched){const e=o.updated,t=this;o.updated=function(s){e.bind(this)(s),this.updateComplete.then((()=>t.refresh()))},o._cm_update_patched=!0}}async _disconnect(){this._observer.disconnect(),await async function(e){let t;for(const[s,n]of Object.entries(ie))if(n.callbacks.has(e)){n.callbacks.delete(e),0==n.callbacks.size&&(t=n.unsubscribe,delete ie[s]);break}t&&await(await t)()}(this._renderer),this._rendered_styles="";for(const e of this._styleChildren)e&&(e.styles=""),this._styleChildren.delete(e)}_style_rendered(e){this._rendered_styles=e,this.dispatchEvent(new Event("card-mod-update"))}createRenderRoot(){return this}render(){return V` +const e="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,t=(e,t,s=null)=>{for(;t!==s;){const s=t.nextSibling;e.removeChild(t),t=s}},s=`{{lit-${String(Math.random()).slice(2)}}}`,n=`\x3c!--${s}--\x3e`,o=new RegExp(`${s}|${n}`);class i{constructor(e,t){this.parts=[],this.element=t;const n=[],i=[],a=document.createTreeWalker(t.content,133,null,!1);let c=0,h=-1,p=0;const{strings:u,values:{length:m}}=e;for(;p0;){const t=u[p],s=l.exec(t)[2],n=s.toLowerCase()+"$lit$",i=e.getAttribute(n);e.removeAttribute(n);const r=i.split(o);this.parts.push({type:"attribute",index:h,name:s,strings:r}),p+=r.length-1}}"TEMPLATE"===e.tagName&&(i.push(e),a.currentNode=e.content)}else if(3===e.nodeType){const t=e.data;if(t.indexOf(s)>=0){const s=e.parentNode,i=t.split(o),a=i.length-1;for(let t=0;t{const s=e.length-t.length;return s>=0&&e.slice(s)===t},a=e=>-1!==e.index,d=()=>document.createComment(""),l=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function c(e,t){const{element:{content:s},parts:n}=e,o=document.createTreeWalker(s,133,null,!1);let i=p(n),r=n[i],a=-1,d=0;const l=[];let c=null;for(;o.nextNode();){a++;const e=o.currentNode;for(e.previousSibling===c&&(c=null),t.has(e)&&(l.push(e),null===c&&(c=e)),null!==c&&d++;void 0!==r&&r.index===a;)r.index=null!==c?-1:r.index-d,i=p(n,i),r=n[i]}l.forEach((e=>e.parentNode.removeChild(e)))}const h=e=>{let t=11===e.nodeType?0:1;const s=document.createTreeWalker(e,133,null,!1);for(;s.nextNode();)t++;return t},p=(e,t=-1)=>{for(let s=t+1;s"function"==typeof e&&u.has(e),f={},y={};class _{constructor(e,t,s){this.__parts=[],this.template=e,this.processor=t,this.options=s}update(e){let t=0;for(const s of this.__parts)void 0!==s&&s.setValue(e[t]),t++;for(const e of this.__parts)void 0!==e&&e.commit()}_clone(){const t=e?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),s=[],n=this.template.parts,o=document.createTreeWalker(t,133,null,!1);let i,r=0,d=0,l=o.nextNode();for(;re}),v=` ${s} `;class w{constructor(e,t,s,n){this.strings=e,this.values=t,this.type=s,this.processor=n}getHTML(){const e=this.strings.length-1;let t="",o=!1;for(let i=0;i-1||o)&&-1===e.indexOf("--\x3e",r+1);const a=l.exec(e);t+=null===a?e+(o?v:n):e.substr(0,a.index)+a[1]+a[2]+"$lit$"+a[3]+s}return t+=this.strings[e],t}getTemplateElement(){const e=document.createElement("template");let t=this.getHTML();return void 0!==g&&(t=g.createHTML(t)),e.innerHTML=t,e}}const S=e=>null===e||!("object"==typeof e||"function"==typeof e),b=e=>Array.isArray(e)||!(!e||!e[Symbol.iterator]);class E{constructor(e,t,s){this.dirty=!0,this.element=e,this.name=t,this.strings=s,this.parts=[];for(let e=0;e{try{const e={get capture(){return A=!0,!1}};window.addEventListener("test",e,e),window.removeEventListener("test",e,e)}catch(e){}})();class O{constructor(e,t,s){this.value=void 0,this.__pendingValue=void 0,this.element=e,this.eventName=t,this.eventContext=s,this.__boundHandleEvent=e=>this.handleEvent(e)}setValue(e){this.__pendingValue=e}commit(){for(;m(this.__pendingValue);){const e=this.__pendingValue;this.__pendingValue=f,e(this)}if(this.__pendingValue===f)return;const e=this.__pendingValue,t=this.value,s=null==e||null!=t&&(e.capture!==t.capture||e.once!==t.once||e.passive!==t.passive),n=null!=e&&(null==t||s);s&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),n&&(this.__options=R(e),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=e,this.__pendingValue=f}handleEvent(e){"function"==typeof this.value?this.value.call(this.eventContext||this.element,e):this.value.handleEvent(e)}}const R=e=>e&&(A?{capture:e.capture,passive:e.passive,once:e.once}:e.capture);function U(e){let t=$.get(e.type);void 0===t&&(t={stringsArray:new WeakMap,keyString:new Map},$.set(e.type,t));let n=t.stringsArray.get(e.strings);if(void 0!==n)return n;const o=e.strings.join(s);return n=t.keyString.get(o),void 0===n&&(n=new i(e,e.getTemplateElement()),t.keyString.set(o,n)),t.stringsArray.set(e.strings,n),n}const $=new Map,M=new WeakMap;const k=new class{handleAttributeExpressions(e,t,s,n){const o=t[0];if("."===o){return new x(e,t.slice(1),s).parts}if("@"===o)return[new O(e,t.slice(1),n.eventContext)];if("?"===o)return[new P(e,t.slice(1),s)];return new E(e,t,s).parts}handleTextExpression(e){return new N(e)}};"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.3.0");const V=(e,...t)=>new w(e,t,"html",k),q=(e,t)=>`${e}--${t}`;let D=!0;void 0===window.ShadyCSS?D=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),D=!1);const L=e=>t=>{const n=q(t.type,e);let o=$.get(n);void 0===o&&(o={stringsArray:new WeakMap,keyString:new Map},$.set(n,o));let r=o.stringsArray.get(t.strings);if(void 0!==r)return r;const a=t.strings.join(s);if(r=o.keyString.get(a),void 0===r){const s=t.getTemplateElement();D&&window.ShadyCSS.prepareTemplateDom(s,e),r=new i(t,s),o.keyString.set(a,r)}return o.stringsArray.set(t.strings,r),r},I=["html","svg"],j=new Set,z=(e,t,s)=>{j.add(e);const n=s?s.element:document.createElement("template"),o=t.querySelectorAll("style"),{length:i}=o;if(0===i)return void window.ShadyCSS.prepareTemplateStyles(n,e);const r=document.createElement("style");for(let e=0;e{I.forEach((t=>{const s=$.get(q(t,e));void 0!==s&&s.keyString.forEach((e=>{const{element:{content:t}}=e,s=new Set;Array.from(t.querySelectorAll("style")).forEach((e=>{s.add(e)})),c(e,s)}))}))})(e);const a=n.content;s?function(e,t,s=null){const{element:{content:n},parts:o}=e;if(null==s)return void n.appendChild(t);const i=document.createTreeWalker(n,133,null,!1);let r=p(o),a=0,d=-1;for(;i.nextNode();)for(d++,i.currentNode===s&&(a=h(t),s.parentNode.insertBefore(t,s));-1!==r&&o[r].index===d;){if(a>0){for(;-1!==r;)o[r].index+=a,r=p(o,r);return}r=p(o,r)}}(s,r,a.firstChild):a.insertBefore(r,a.firstChild),window.ShadyCSS.prepareTemplateStyles(n,e);const d=a.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==d)t.insertBefore(d.cloneNode(!0),t.firstChild);else if(s){a.insertBefore(r,a.firstChild);const e=new Set;e.add(r),c(s,e)}};window.JSCompiler_renameProperty=(e,t)=>e;const H={toAttribute(e,t){switch(t){case Boolean:return e?"":null;case Object:case Array:return null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){switch(t){case Boolean:return null!==e;case Number:return null===e?null:Number(e);case Object:case Array:return JSON.parse(e)}return e}},J=(e,t)=>t!==e&&(t==t||e==e),F={attribute:!0,type:String,converter:H,reflect:!1,hasChanged:J};class B extends HTMLElement{constructor(){super(),this.initialize()}static get observedAttributes(){this.finalize();const e=[];return this._classProperties.forEach(((t,s)=>{const n=this._attributeNameForProperty(s,t);void 0!==n&&(this._attributeToPropertyMap.set(n,s),e.push(n))})),e}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const e=Object.getPrototypeOf(this)._classProperties;void 0!==e&&e.forEach(((e,t)=>this._classProperties.set(t,e)))}}static createProperty(e,t=F){if(this._ensureClassProperties(),this._classProperties.set(e,t),t.noAccessor||this.prototype.hasOwnProperty(e))return;const s="symbol"==typeof e?Symbol():`__${e}`,n=this.getPropertyDescriptor(e,s,t);void 0!==n&&Object.defineProperty(this.prototype,e,n)}static getPropertyDescriptor(e,t,s){return{get(){return this[t]},set(n){const o=this[e];this[t]=n,this.requestUpdateInternal(e,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this._classProperties&&this._classProperties.get(e)||F}static finalize(){const e=Object.getPrototypeOf(this);if(e.hasOwnProperty("finalized")||e.finalize(),this.finalized=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const e=this.properties,t=[...Object.getOwnPropertyNames(e),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e):[]];for(const s of t)this.createProperty(s,e[s])}}static _attributeNameForProperty(e,t){const s=t.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof e?e.toLowerCase():void 0}static _valueHasChanged(e,t,s=J){return s(e,t)}static _propertyValueFromAttribute(e,t){const s=t.type,n=t.converter||H,o="function"==typeof n?n:n.fromAttribute;return o?o(e,s):e}static _propertyValueToAttribute(e,t){if(void 0===t.reflect)return;const s=t.type,n=t.converter;return(n&&n.toAttribute||H.toAttribute)(e,s)}initialize(){this._updateState=0,this._updatePromise=new Promise((e=>this._enableUpdatingResolver=e)),this._changedProperties=new Map,this._saveInstanceProperties(),this.requestUpdateInternal()}_saveInstanceProperties(){this.constructor._classProperties.forEach(((e,t)=>{if(this.hasOwnProperty(t)){const e=this[t];delete this[t],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(t,e)}}))}_applyInstanceProperties(){this._instanceProperties.forEach(((e,t)=>this[t]=e)),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(e,t,s){t!==s&&this._attributeToProperty(e,s)}_propertyToAttribute(e,t,s=F){const n=this.constructor,o=n._attributeNameForProperty(e,s);if(void 0!==o){const e=n._propertyValueToAttribute(t,s);if(void 0===e)return;this._updateState=8|this._updateState,null==e?this.removeAttribute(o):this.setAttribute(o,e),this._updateState=-9&this._updateState}}_attributeToProperty(e,t){if(8&this._updateState)return;const s=this.constructor,n=s._attributeToPropertyMap.get(e);if(void 0!==n){const e=s.getPropertyOptions(n);this._updateState=16|this._updateState,this[n]=s._propertyValueFromAttribute(t,e),this._updateState=-17&this._updateState}}requestUpdateInternal(e,t,s){let n=!0;if(void 0!==e){const o=this.constructor;s=s||o.getPropertyOptions(e),o._valueHasChanged(this[e],t,s.hasChanged)?(this._changedProperties.has(e)||this._changedProperties.set(e,t),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(e,s))):n=!1}!this._hasRequestedUpdate&&n&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(e,t){return this.requestUpdateInternal(e,t),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const e=this.performUpdate();return null!=e&&await e,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){if(!this._hasRequestedUpdate)return;this._instanceProperties&&this._applyInstanceProperties();let e=!1;const t=this._changedProperties;try{e=this.shouldUpdate(t),e?this.update(t):this._markUpdated()}catch(t){throw e=!1,this._markUpdated(),t}e&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(t)),this.updated(t))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this._updatePromise}shouldUpdate(e){return!0}update(e){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach(((e,t)=>this._propertyToAttribute(t,this[t],e))),this._reflectingProperties=void 0),this._markUpdated()}updated(e){}firstUpdated(e){}}B.finalized=!0;const W=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?Object.assign(Object.assign({},t),{finisher(s){s.createProperty(t.key,e)}}):{kind:"field",key:Symbol(),placement:"own",descriptor:{},initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(s){s.createProperty(t.key,e)}};const Y=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,G=Symbol();class K{constructor(e,t){if(t!==G)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e}get styleSheet(){return void 0===this._styleSheet&&(Y?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}(window.litElementVersions||(window.litElementVersions=[])).push("2.4.0");const Q={};class X extends B{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const e=this.getStyles();if(Array.isArray(e)){const t=(e,s)=>e.reduceRight(((e,s)=>Array.isArray(s)?t(s,e):(e.add(s),e)),s),s=t(e,new Set),n=[];s.forEach((e=>n.unshift(e))),this._styles=n}else this._styles=void 0===e?[]:[e];this._styles=this._styles.map((e=>{if(e instanceof CSSStyleSheet&&!Y){const t=Array.prototype.slice.call(e.cssRules).reduce(((e,t)=>e+t.cssText),"");return new K(String(t),G)}return e}))}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow({mode:"open"})}adoptStyles(){const e=this.constructor._styles;0!==e.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Y?this.renderRoot.adoptedStyleSheets=e.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(e.map((e=>e.cssText)),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(e){const t=this.render();super.update(e),t!==Q&&this.constructor.render(t,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach((e=>{const t=document.createElement("style");t.textContent=e.cssText,this.renderRoot.appendChild(t)})))}render(){return Q}}function Z(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}X.finalized=!0,X.render=(e,s,n)=>{if(!n||"object"!=typeof n||!n.scopeName)throw new Error("The `scopeName` option is required.");const o=n.scopeName,i=M.has(s),r=D&&11===s.nodeType&&!!s.host,a=r&&!j.has(o),d=a?document.createDocumentFragment():s;if(((e,s,n)=>{let o=M.get(s);void 0===o&&(t(s,s.firstChild),M.set(s,o=new N(Object.assign({templateFactory:U},n))),o.appendInto(s)),o.setValue(e),o.commit()})(e,d,Object.assign({templateFactory:L(o)},n)),a){const e=M.get(d);M.delete(d);const n=e.value instanceof _?e.value.template:void 0;z(o,d,n),t(s,s.firstChild),s.appendChild(d),M.set(s,e)}!i&&r&&window.ShadyCSS.styleElement(s.host)};const ee="lovelace-player-device-id";function te(){if(!localStorage[ee]){const e=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[ee]=fully.getDeviceId():localStorage[ee]=`${e()}${e()}-${e()}${e()}`}return localStorage[ee]}let se=te();const ne=new URLSearchParams(window.location.search);var oe;ne.get("deviceID")&&null!==(oe=ne.get("deviceID"))&&("clear"===oe?localStorage.removeItem(ee):localStorage[ee]=oe,se=te()),window.cardMod_template_cache=window.cardMod_template_cache||{};const ie=window.cardMod_template_cache;async function re(e,t,s){const n=Z().connection,o=JSON.stringify([t,s]);let i=ie[o];i?(e(i.value),i.callbacks.add(e)):(e(""),s=Object.assign({user:Z().user.name,browser:se,hash:location.hash.substr(1)||""},s),ie[o]=i={template:t,variables:s,value:"",callbacks:new Set([e]),unsubscribe:n.subscribeMessage((e=>function(e,t){const s=ie[e];s&&(s.value=t.result,s.callbacks.forEach((e=>e(t.result))))}(o,e)),{type:"render_template",template:t,variables:s})})}var ae="3.0.4";async function de(e,t,s=!1){let n=e;"string"==typeof t&&(t=t.split(/(\$| )/)),""===t[t.length-1]&&t.pop();for(const[e,o]of t.entries())if(o.trim().length){if(!n)return null;n.localName&&n.localName.includes("-")&&await customElements.whenDefined(n.localName),n.updateComplete&&await n.updateComplete,n="$"===o?s&&e==t.length-1?[n.shadowRoot]:n.shadowRoot:s&&e==t.length-1?n.querySelectorAll(o):n.querySelector(o)}return n}async function le(e,t,s=!1,n=1e4){return Promise.race([de(e,t,s),new Promise(((e,t)=>setTimeout((()=>t(new Error("timeout"))),n)))]).catch((e=>{if(!e.message||"timeout"!==e.message)throw e;return null}))}const ce=async e=>{await(async()=>{if(customElements.get("developer-tools-event"))return;await customElements.whenDefined("partial-panel-resolver");const e=document.createElement("partial-panel-resolver");e.hass={panels:[{url_path:"tmp",component_name:"developer-tools"}]},e._updateRoutes(),await e.routerOptions.routes.tmp.load(),await customElements.whenDefined("developer-tools-router");const t=document.createElement("developer-tools-router");await t.routerOptions.routes.event.load()})();return document.createElement("developer-tools-event")._computeParsedEventData(e)};async function he(e,t,s="",n={},o=null,i=!0){var r;let a;(null===(r=e.localName)||void 0===r?void 0:r.includes("-"))&&await customElements.whenDefined(e.localName),e.updateComplete&&await e.updateComplete,void 0===e._cardMod&&(e._cardMod=[]);for(const s of e._cardMod)if(s.type===t){a=s;break}a||(a=document.createElement("card-mod"),a.type=t,e._cardMod.push(a));return(e.modElement?e.modElement:i&&e.shadowRoot||e).appendChild(a),a.variables=n,a.styles=s,a}function pe(e,t){const s=e=>e&&"object"==typeof e&&!Array.isArray(e);if(s(e)&&s(t))for(const n in t)s(t[n])?(e[n]||Object.assign(e,{[n]:{}}),"string"==typeof e[n]&&(e[n]={".":e[n]}),pe(e[n],t[n])):e[n]?e[n]=t[n]+e[n]:e[n]=t[n];return e}function ue(e){return e.config?e.config:e._config?e._config:e.host?ue(e.host):e.parentElement?ue(e.parentElement):e.parentNode?ue(e.parentNode):null}function me(e,t){for(const s of t)e.add(s)}async function fe(e,t=0){let s=new Set;return 10==t?s:e?(e._cardMod&&e._cardMod.style&&s.add(e._cardMod),e.updateComplete&&await e.updateComplete,e.parentElement&&me(s,await fe(e.parentElement,t+1)),e.parentNode&&me(s,await fe(e.parentNode,t+1)),e.host&&me(s,await fe(e.host,t+1)),s):s}function ye(e){if(!e)return;const t=e.parentElement||e.parentNode;return t?t.host?t.host:t:void 0}class _e extends X{constructor(){super(),this._rendered_styles="",this._styleChildren=new Set,this._refreshCooldown={running:!1,repeat:!1},this._observer=new MutationObserver((e=>{for(const t of e){if("card-mod"===t.target.localName)return;let e=!0;if(t.addedNodes.length&&t.addedNodes.forEach((t=>{"card-mod"!==t.localName&&(e=!1)})),e)return;e=!0,t.removedNodes.length&&t.removedNodes.forEach((t=>{"card-mod"!==t.localName&&(e=!1)}))}this.refresh(!0)})),document.querySelector("home-assistant").addEventListener("settheme",(()=>this.refresh(!0)))}static get applyToElement(){return he}connectedCallback(){super.connectedCallback(),this.refresh(),this.setAttribute("slot","none")}disconnectedCallback(){super.disconnectedCallback(),this._disconnect(!1)}set styles(e){this._input_styles=e,this.refresh(!0)}refresh(e=!1){this._refreshCooldown.running?this._refreshCooldown.repeat=!0:(window.setTimeout((()=>{this._refreshCooldown.running=!1,this._refreshCooldown.repeat&&this.refresh()}),1),this._refreshCooldown.repeat=!1,this._disconnect(e).then((()=>this._connect(this._input_styles))))}async _connect(e){let t=JSON.parse(JSON.stringify(e||{}));"string"==typeof t&&(t={".":t});pe(t,await async function(e){if(!e.type)return null;const t=e.parentElement?e.parentElement:e,s=window.getComputedStyle(t).getPropertyValue("--card-mod-theme"),n=Z().themes.themes;return n[s]?n[s][`card-mod-${e.type}-yaml`]?ce(n[s][`card-mod-${e.type}-yaml`]):n[s][`card-mod-${e.type}`]?{".":n[s][`card-mod-${e.type}`]}:{}:{}}(this));const s=this.parentElement||this.parentNode;for(const[e,n]of Object.entries(t))if("."===e)this._styles=n;else for(const t of await le(s,e,!0))this._styleChildren.add(await he(t,`${this.type}-child`,n,this.variables,null,!1));var n;if(this._styles&&(n=this._styles,String(n).includes("{%")||String(n).includes("{{"))?(this._renderer=this._renderer||this._style_rendered.bind(this),re(this._renderer,this._styles,this.variables)):this._style_rendered(this._styles||""),this._observer.observe(ye(this),{childList:!0}),"card"===this.type){const e=ye(ye(this));if(e&&this._observer.observe(e,{childList:!0}),e&&e.updated&&!e._cm_update_patched){const t=e.updated,s=this;e.updated=function(e){t.bind(this)(e),this.updateComplete.then((()=>s.refresh()))},e._cm_update_patched=!0}}}async _disconnect(e=!0){if(this._observer.disconnect(),await async function(e){let t;for(const[s,n]of Object.entries(ie))if(n.callbacks.has(e)){n.callbacks.delete(e),0==n.callbacks.size&&(t=n.unsubscribe,delete ie[s]);break}t&&await(await t)()}(this._renderer),e){this._rendered_styles="";for(const e of this._styleChildren)e&&(e.styles=""),this._styleChildren.delete(e)}}_style_rendered(e){this._rendered_styles=e,this.dispatchEvent(new Event("card-mod-update"))}createRenderRoot(){return this}render(){return V` diff --git a/package.json b/package.json index 432db58..646284d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "card-mod", "private": true, - "version": "3.0.3", + "version": "3.0.4", "description": "", "scripts": { "build": "rollup -c", diff --git a/src/card-mod.ts b/src/card-mod.ts index 8e4b95a..3cff0f3 100644 --- a/src/card-mod.ts +++ b/src/card-mod.ts @@ -38,7 +38,7 @@ export class CardMod extends LitElement { }); } - this.refresh(); + this.refresh(true); }); static get applyToElement() { @@ -49,7 +49,7 @@ export class CardMod extends LitElement { super(); document .querySelector("home-assistant") - .addEventListener("settheme", () => this.refresh()); + .addEventListener("settheme", () => this.refresh(true)); } connectedCallback() { @@ -60,15 +60,15 @@ export class CardMod extends LitElement { disconnectedCallback() { super.disconnectedCallback(); - this._disconnect(); + this._disconnect(false); } set styles(stl: Styles) { this._input_styles = stl; - this.refresh(); + this.refresh(true); } - refresh() { + refresh(forced = false) { if (this._refreshCooldown.running) { this._refreshCooldown.repeat = true; return; @@ -78,7 +78,7 @@ export class CardMod extends LitElement { if (this._refreshCooldown.repeat) this.refresh(); }, 1); this._refreshCooldown.repeat = false; - this._disconnect().then(() => this._connect(this._input_styles)); + this._disconnect(forced).then(() => this._connect(this._input_styles)); } private async _connect(stl: Styles) { @@ -119,26 +119,30 @@ export class CardMod extends LitElement { this._observer.observe(parentElement(this), { childList: true }); - const p = parentElement(parentElement(this)) as any; - this._observer.observe(p, { childList: true }); - if (p && p.updated && !p._cm_update_patched) { - const _updated = p.updated; - const _this = this; - p.updated = function (param) { - _updated.bind(this)(param); - this.updateComplete.then(() => _this.refresh()); - }; - p._cm_update_patched = true; + if (this.type === "card") { + const p = parentElement(parentElement(this)) as any; + if (p) this._observer.observe(p, { childList: true }); + if (p && p.updated && !p._cm_update_patched) { + const _updated = p.updated; + const _this = this; + p.updated = function (param) { + _updated.bind(this)(param); + this.updateComplete.then(() => _this.refresh()); + }; + p._cm_update_patched = true; + } } } - private async _disconnect() { + private async _disconnect(forced = true) { this._observer.disconnect(); await unbind_template(this._renderer); - this._rendered_styles = ""; - for (const c of this._styleChildren) { - if (c) c.styles = ""; - this._styleChildren.delete(c); + if (forced) { + this._rendered_styles = ""; + for (const c of this._styleChildren) { + if (c) c.styles = ""; + this._styleChildren.delete(c); + } } } diff --git a/src/helpers.ts b/src/helpers.ts index 107c1eb..9ac6d5c 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -133,5 +133,6 @@ export async function findParentCardMod( export function parentElement(el: Node): Node { if (!el) return undefined; const node = el.parentElement || el.parentNode; + if (!node) return undefined; return (node as any).host ? (node as any).host : node; }