From b8c48b925643389fea5b1c0185ad7e0cbbd2bb76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Mon, 3 Apr 2023 20:28:33 +0000 Subject: [PATCH] Remove card-tools dependency --- card-mod.js | 4 +-- hacs.json | 2 +- package-lock.json | 6 +---- package.json | 6 ++--- src/card-mod.ts | 9 ++++--- src/helpers.ts | 9 ++++--- src/helpers/browser_id.ts | 6 +++++ src/helpers/hass.ts | 20 ++++++++++++++ src/helpers/selecttree.ts | 45 ++++++++++++++++++++++++++++++++ src/{ => helpers}/templates.ts | 15 +++++++---- src/helpers/yaml2json.ts | 28 ++++++++++++++++++++ src/main.ts | 2 -- src/patch/ha-more-info-dialog.ts | 2 +- src/patch/ha-sidebar.ts | 2 +- src/patch/hui-root.ts | 2 +- src/theme-watcher.ts | 7 ++--- 16 files changed, 133 insertions(+), 32 deletions(-) create mode 100644 src/helpers/browser_id.ts create mode 100644 src/helpers/hass.ts create mode 100644 src/helpers/selecttree.ts rename src/{ => helpers}/templates.ts (87%) create mode 100644 src/helpers/yaml2json.ts diff --git a/card-mod.js b/card-mod.js index 82a730c..bbf7d76 100644 --- a/card-mod.js +++ b/card-mod.js @@ -1,5 +1,5 @@ -function t(){return document.querySelector("hc-main")?document.querySelector("hc-main").hass:document.querySelector("home-assistant")?document.querySelector("home-assistant").hass:void 0}function e(t,e,o,s){var i,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,s);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(n<3?i(r):n>3?i(e,o,r):i(e,o))||r);return n>3&&r&&Object.defineProperty(e,o,r),r}const o=window,s=o.ShadowRoot&&(void 0===o.ShadyCSS||o.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,i=Symbol(),n=new WeakMap;const r=t=>new class{constructor(t,e,o){if(this._$cssResult$=!0,o!==i)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(s&&void 0===t){const o=void 0!==e&&1===e.length;o&&(t=n.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),o&&n.set(e,t))}return t}toString(){return this.cssText}}("string"==typeof t?t:t+"",void 0,i),a=s?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const o of t.cssRules)e+=o.cssText;return r(e)})(t):t;var d;const l=window,c=l.trustedTypes,h=c?c.emptyScript:"",u=l.reactiveElementPolyfillSupport,p={toAttribute(t,e){switch(e){case Boolean:t=t?h:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let o=t;switch(e){case Boolean:o=null!==t;break;case Number:o=null===t?null:Number(t);break;case Object:case Array:try{o=JSON.parse(t)}catch(t){o=null}}return o}},m=(t,e)=>e!==t&&(e==e||t==t),f={attribute:!0,type:String,converter:p,reflect:!1,hasChanged:m};let v=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,o)=>{const s=this._$Ep(o,e);void 0!==s&&(this._$Ev.set(s,o),t.push(s))})),t}static createProperty(t,e=f){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const o="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,o,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,o){return{get(){return this[e]},set(s){const i=this[t];this[e]=s,this.requestUpdate(t,i,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||f}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const o of e)this.createProperty(o,t[o])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const o=new Set(t.flat(1/0).reverse());for(const t of o)e.unshift(a(t))}else void 0!==t&&e.push(a(t));return e}static _$Ep(t,e){const o=e.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,o;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(o=t.hostConnected)||void 0===o||o.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,e)=>{s?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const s=document.createElement("style"),i=o.litNonce;void 0!==i&&s.setAttribute("nonce",i),s.textContent=e.cssText,t.appendChild(s)}))})(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,o){this._$AK(t,o)}_$EO(t,e,o=f){var s;const i=this.constructor._$Ep(t,o);if(void 0!==i&&!0===o.reflect){const n=(void 0!==(null===(s=o.converter)||void 0===s?void 0:s.toAttribute)?o.converter:p).toAttribute(e,o.type);this._$El=t,null==n?this.removeAttribute(i):this.setAttribute(i,n),this._$El=null}}_$AK(t,e){var o;const s=this.constructor,i=s._$Ev.get(t);if(void 0!==i&&this._$El!==i){const t=s.getPropertyOptions(i),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(o=t.converter)||void 0===o?void 0:o.fromAttribute)?t.converter:p;this._$El=i,this[i]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,o){let s=!0;void 0!==t&&(((o=o||this.constructor.getPropertyOptions(t)).hasChanged||m)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===o.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,o))):s=!1),!this.isUpdatePending&&s&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const o=this._$AL;try{e=this.shouldUpdate(o),e?(this.willUpdate(o),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(o)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(o)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};var y;v.finalized=!0,v.elementProperties=new Map,v.elementStyles=[],v.shadowRootOptions={mode:"open"},null==u||u({ReactiveElement:v}),(null!==(d=l.reactiveElementVersions)&&void 0!==d?d:l.reactiveElementVersions=[]).push("1.4.2");const _=window,g=_.trustedTypes,$=g?g.createPolicy("lit-html",{createHTML:t=>t}):void 0,w=`lit$${(Math.random()+"").slice(9)}$`,E="?"+w,b=`<${E}>`,A=document,S=(t="")=>A.createComment(t),C=t=>null===t||"object"!=typeof t&&"function"!=typeof t,N=Array.isArray,P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,O=/-->/g,R=/>/g,U=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),M=/'/g,x=/"/g,D=/^(?:script|style|textarea|title)$/i,T=(t=>(e,...o)=>({_$litType$:t,strings:e,values:o}))(1),k=Symbol.for("lit-noChange"),H=Symbol.for("lit-nothing"),L=new WeakMap,q=A.createTreeWalker(A,129,null,!1),I=(t,e)=>{const o=t.length-1,s=[];let i,n=2===e?"":"",r=P;for(let e=0;e"===d[0]?(r=null!=i?i:P,l=-1):void 0===d[1]?l=-2:(l=r.lastIndex-d[2].length,a=d[1],r=void 0===d[3]?U:'"'===d[3]?x:M):r===x||r===M?r=U:r===O||r===R?r=P:(r=U,i=void 0);const h=r===U&&t[e+1].startsWith("/>")?" ":"";n+=r===P?o+b:l>=0?(s.push(a),o.slice(0,l)+"$lit$"+o.slice(l)+w+h):o+w+(-2===l?(s.push(void 0),e):h)}const a=n+(t[o]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==$?$.createHTML(a):a,s]};class j{constructor({strings:t,_$litType$:e},o){let s;this.parts=[];let i=0,n=0;const r=t.length-1,a=this.parts,[d,l]=I(t,e);if(this.el=j.createElement(d,o),q.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=q.nextNode())&&a.length0){s.textContent=g?g.emptyScript:"";for(let o=0;oN(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.k(t):this.g(t)}O(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}g(t){this._$AH!==H&&C(this._$AH)?this._$AA.nextSibling.data=t:this.T(A.createTextNode(t)),this._$AH=t}$(t){var e;const{values:o,_$litType$:s}=t,i="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=j.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===i)this._$AH.p(o);else{const t=new B(i,this),e=t.v(this.options);t.p(o),this.T(e),this._$AH=t}}_$AC(t){let e=L.get(t.strings);return void 0===e&&L.set(t.strings,e=new j(t)),e}k(t){N(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let o,s=0;for(const i of t)s===e.length?e.push(o=new V(this.O(S()),this.O(S()),this,this.options)):o=e[s],o._$AI(i),s++;s2||""!==o[0]||""!==o[1]?(this._$AH=Array(o.length-1).fill(new String),this.strings=o):this._$AH=H}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,o,s){const i=this.strings;let n=!1;if(void 0===i)t=z(this,t,e,0),n=!C(t)||t!==this._$AH&&t!==k,n&&(this._$AH=t);else{const s=t;let r,a;for(t=i[0],r=0;r{var s,i;const n=null!==(s=null==o?void 0:o.renderBefore)&&void 0!==s?s:e;let r=n._$litPart$;if(void 0===r){const t=null!==(i=null==o?void 0:o.renderBefore)&&void 0!==i?i:null;n._$litPart$=r=new V(e.insertBefore(S(),t),t,void 0,null!=o?o:{})}return r._$AI(t),r})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return k}}tt.finalized=!0,tt._$litElement$=!0,null===(Q=globalThis.litElementHydrateSupport)||void 0===Q||Q.call(globalThis,{LitElement:tt});const et=globalThis.litElementPolyfillSupport;null==et||et({LitElement:tt}),(null!==(X=globalThis.litElementVersions)&&void 0!==X?X:globalThis.litElementVersions=[]).push("3.2.2");const ot=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(o){o.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(o){o.createProperty(e.key,t)}};function st(t){return(e,o)=>void 0!==o?((t,e,o)=>{e.constructor.createProperty(o,t)})(t,e,o):ot(t,e)}var it;null===(it=window.HTMLSlotElement)||void 0===it||it.prototype.assignedElements;const nt="lovelace-player-device-id";function rt(){if(!localStorage[nt]){const t=()=>Math.floor(1e5*(1+Math.random())).toString(16).substring(1);window.fully&&"function"==typeof fully.getDeviceId?localStorage[nt]=fully.getDeviceId():localStorage[nt]=`${t()}${t()}-${t()}${t()}`}return localStorage[nt]}let at=rt();const dt=new URLSearchParams(window.location.search);var lt;dt.get("deviceID")&&null!==(lt=dt.get("deviceID"))&&("clear"===lt?localStorage.removeItem(nt):localStorage[nt]=lt,at=rt()),window.cardMod_template_cache=window.cardMod_template_cache||{};const ct=window.cardMod_template_cache;async function ht(e,o,s){const i=t().connection,n=JSON.stringify([o,s]);let r=ct[n];r?(r.callbacks.has(e)||ut(e),e(r.value),r.callbacks.add(e)):(ut(e),e(""),s=Object.assign({user:t().user.name,browser:at,hash:location.hash.substr(1)||""},s),ct[n]=r={template:o,variables:s,value:"",callbacks:new Set([e]),unsubscribe:i.subscribeMessage((t=>function(t,e){const o=ct[t];o&&(o.value=e.result,o.callbacks.forEach((t=>t(e.result))))}(n,t)),{type:"render_template",template:o,variables:s})})}async function ut(t){let e;for(const[o,s]of Object.entries(ct))if(s.callbacks.has(t)){s.callbacks.delete(t),0==s.callbacks.size&&(e=s.unsubscribe,delete ct[o]);break}e&&await(await e)()}var pt="3.2.1";async function mt(t,e,o=!1){let s=t;"string"==typeof e&&(e=e.split(/(\$| )/)),""===e[e.length-1]&&e.pop();for(const[t,i]of e.entries())if(i.trim().length){if(!s)return null;s.localName&&s.localName.includes("-")&&await customElements.whenDefined(s.localName),s.updateComplete&&await s.updateComplete,s="$"===i?o&&t==e.length-1?[s.shadowRoot]:s.shadowRoot:o&&t==e.length-1?s.querySelectorAll(i):s.querySelector(i)}return s}async function ft(t,e,o=!1,s=1e4){return Promise.race([mt(t,e,o),new Promise(((t,e)=>setTimeout((()=>e(new Error("timeout"))),s)))]).catch((t=>{if(!t.message||"timeout"!==t.message)throw t;return null}))}const vt=async t=>{await(async()=>{if(customElements.get("developer-tools-event"))return;await customElements.whenDefined("partial-panel-resolver");const t=document.createElement("partial-panel-resolver");t.hass={panels:[{url_path:"tmp",component_name:"developer-tools"}]},t._updateRoutes(),await t.routerOptions.routes.tmp.load(),await customElements.whenDefined("developer-tools-router");const e=document.createElement("developer-tools-router");await e.routerOptions.routes.event.load()})();return document.createElement("developer-tools-event")._computeParsedEventData(t)};async function yt(t,e,o="",s={},i=null,n=!0){var r;if(!t)return;let a;(null===(r=t.localName)||void 0===r?void 0:r.includes("-"))&&await customElements.whenDefined(t.localName),t.updateComplete&&await t.updateComplete,void 0===t._cardMod&&(t._cardMod=[]);for(const o of t._cardMod)if(o.type===e){a=o;break}return a||(a=document.createElement("card-mod"),a.type=e,t._cardMod.push(a)),queueMicrotask((async()=>{const e=t.modElement?t.modElement:n&&t.shadowRoot||t;e.contains(a)||e.appendChild(a),a.variables=s,a.styles=o})),a}function _t(t,e){const o=t=>t&&"object"==typeof t&&!Array.isArray(t);if(o(t)&&o(e))for(const s in e)o(e[s])?(t[s]||Object.assign(t,{[s]:{}}),"string"==typeof t[s]&&(t[s]={".":t[s]}),_t(t[s],e[s])):t[s]?t[s]=e[s]+t[s]:t[s]=e[s];return t}function gt(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(!(t instanceof Object&&e instanceof Object))return!1;for(const o in t)if(t.hasOwnProperty(o)){if(!e.hasOwnProperty(o))return!1;if(t[o]!==e[o]){if("object"!=typeof t[o])return!1;if(!gt(t[o],e[o]))return!1}}for(const o in e)if(e.hasOwnProperty(o)&&!t.hasOwnProperty(o))return!1;return!0}function $t(t){return t.config?t.config:t._config?t._config:t.host?$t(t.host):t.parentElement?$t(t.parentElement):t.parentNode?$t(t.parentNode):null}function wt(t,e){for(const o of e)t.add(o)}async function Et(t,e=0){let o=new Set;if(10==e)return o;if(!t)return o;if(t._cardMod)for(const e of t._cardMod)e.styles&&o.add(e);return t.updateComplete&&await t.updateComplete,t.parentElement?wt(o,await Et(t.parentElement,e+1)):t.parentNode&&wt(o,await Et(t.parentNode,e+1)),t.host&&wt(o,await Et(t.host,e+1)),o}class bt extends tt{static get applyToElement(){return yt}constructor(){super(),this._rendered_styles="",this._styleChildren=new Set,this._observer=new MutationObserver((t=>{for(const e of t){if("card-mod"===e.target.localName)return;e.addedNodes.length&&e.addedNodes.forEach((t=>{t.localName})),e.removedNodes.length&&e.removedNodes.forEach((t=>{t.localName}))}stop||this.refresh()})),document.addEventListener("cm_update",(()=>{this.refresh()}))}connectedCallback(){super.connectedCallback(),this._connect(),this.setAttribute("slot","none")}disconnectedCallback(){super.disconnectedCallback(),this._disconnect()}set styles(e){gt(e,this._input_styles)||(this._input_styles=e,(async()=>{let o=JSON.parse(JSON.stringify(e||{}));"string"==typeof o&&(o={".":o});_t(o,await async function(e){var o,s;if(!e.type)return null;const i=e.parentElement?e.parentElement:e,n=window.getComputedStyle(i).getPropertyValue("--card-mod-theme");if(!t())return{};const r=null!==(s=null===(o=t())||void 0===o?void 0:o.themes.themes)&&void 0!==s?s:{};return r[n]?r[n][`card-mod-${e.type}-yaml`]?vt(r[n][`card-mod-${e.type}-yaml`]):r[n][`card-mod-${e.type}`]?{".":r[n][`card-mod-${e.type}`]}:{}:{}}(this)),this._fixed_styles=o,this._connect()})())}get styles(){return this._styles}refresh(){this._connect()}async _styleChildEl(t,e){if(void 0===e){const o=this._fixed_styles;for(const[s,i]of Object.entries(o)){if("."===s)continue;if((await ft(this.parentElement||this.parentNode,s,!0)).forEach((o=>{o===t&&(e=i)})),void 0!==e)break}if(void 0===e)return}if(!t)return;const o=await yt(t,`${this.type}-child`,e,this.variables,null,!1);return o.refresh,o}async _connect(){var t;const e=null!==(t=this._fixed_styles)&&void 0!==t?t:{},o=new Set;let s="",i=!1;const n=this.parentElement||this.parentNode;for(const[t,r]of Object.entries(e))if("."===t)s=r;else{i=!0;const e=await ft(n,t,!0);if(!e)continue;for(const t of e){const e=await this._styleChildEl(t,r);e&&o.add(e)}}for(const t of this._styleChildren)o.has(t)||t&&(t.styles="");var r;(this._styleChildren=o,this._styles!==s)&&(this._styles=s,this._styles&&(r=this._styles,String(r).includes("{%")||String(r).includes("{{"))?(this._renderer=this._renderer||this._style_rendered.bind(this),ht(this._renderer,this._styles,this.variables)):this._style_rendered(this._styles||""),i&&(this._observer.disconnect(),this._observer.observe(function(t){if(!t)return;const e=t.parentElement||t.parentNode;return e?e.host?e.host:e:void 0}(this),{childList:!0})))}async _disconnect(){this._observer.disconnect(),this._styles="",await ut(this._renderer)}_style_rendered(t){this._rendered_styles!==t&&(this._rendered_styles=t),this.dispatchEvent(new Event("card-mod-update"))}createRenderRoot(){return this}render(){return T` +function t(t,e,o,s){var i,n=arguments.length,r=n<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(t,e,o,s);else for(var a=t.length-1;a>=0;a--)(i=t[a])&&(r=(n<3?i(r):n>3?i(e,o,r):i(e,o))||r);return n>3&&r&&Object.defineProperty(e,o,r),r}const e=window,o=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),i=new WeakMap;const n=t=>new class{constructor(t,e,o){if(this._$cssResult$=!0,o!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(o&&void 0===t){const o=void 0!==e&&1===e.length;o&&(t=i.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),o&&i.set(e,t))}return t}toString(){return this.cssText}}("string"==typeof t?t:t+"",void 0,s),r=o?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const o of t.cssRules)e+=o.cssText;return n(e)})(t):t;var a;const d=window,l=d.trustedTypes,c=l?l.emptyScript:"",h=d.reactiveElementPolyfillSupport,u={toAttribute(t,e){switch(e){case Boolean:t=t?c:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let o=t;switch(e){case Boolean:o=null!==t;break;case Number:o=null===t?null:Number(t);break;case Object:case Array:try{o=JSON.parse(t)}catch(t){o=null}}return o}},p=(t,e)=>e!==t&&(e==e||t==t),m={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:p};let f=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,o)=>{const s=this._$Ep(o,e);void 0!==s&&(this._$Ev.set(s,o),t.push(s))})),t}static createProperty(t,e=m){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const o="symbol"==typeof t?Symbol():"__"+t,s=this.getPropertyDescriptor(t,o,e);void 0!==s&&Object.defineProperty(this.prototype,t,s)}}static getPropertyDescriptor(t,e,o){return{get(){return this[e]},set(s){const i=this[t];this[e]=s,this.requestUpdate(t,i,o)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||m}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),this.elementProperties=new Map(t.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const o of e)this.createProperty(o,t[o])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const o=new Set(t.flat(1/0).reverse());for(const t of o)e.unshift(r(t))}else void 0!==t&&e.push(r(t));return e}static _$Ep(t,e){const o=e.attribute;return!1===o?void 0:"string"==typeof o?o:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,o;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(o=t.hostConnected)||void 0===o||o.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const s=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return((t,s)=>{o?t.adoptedStyleSheets=s.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):s.forEach((o=>{const s=document.createElement("style"),i=e.litNonce;void 0!==i&&s.setAttribute("nonce",i),s.textContent=o.cssText,t.appendChild(s)}))})(s,this.constructor.elementStyles),s}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,o){this._$AK(t,o)}_$EO(t,e,o=m){var s;const i=this.constructor._$Ep(t,o);if(void 0!==i&&!0===o.reflect){const n=(void 0!==(null===(s=o.converter)||void 0===s?void 0:s.toAttribute)?o.converter:u).toAttribute(e,o.type);this._$El=t,null==n?this.removeAttribute(i):this.setAttribute(i,n),this._$El=null}}_$AK(t,e){var o;const s=this.constructor,i=s._$Ev.get(t);if(void 0!==i&&this._$El!==i){const t=s.getPropertyOptions(i),n="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(o=t.converter)||void 0===o?void 0:o.fromAttribute)?t.converter:u;this._$El=i,this[i]=n.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,o){let s=!0;void 0!==t&&(((o=o||this.constructor.getPropertyOptions(t)).hasChanged||p)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===o.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,o))):s=!1),!this.isUpdatePending&&s&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const o=this._$AL;try{e=this.shouldUpdate(o),e?(this.willUpdate(o),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(o)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(o)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}};var v;f.finalized=!0,f.elementProperties=new Map,f.elementStyles=[],f.shadowRootOptions={mode:"open"},null==h||h({ReactiveElement:f}),(null!==(a=d.reactiveElementVersions)&&void 0!==a?a:d.reactiveElementVersions=[]).push("1.4.2");const _=window,y=_.trustedTypes,g=y?y.createPolicy("lit-html",{createHTML:t=>t}):void 0,$=`lit$${(Math.random()+"").slice(9)}$`,w="?"+$,E=`<${w}>`,b=document,A=(t="")=>b.createComment(t),S=t=>null===t||"object"!=typeof t&&"function"!=typeof t,C=Array.isArray,P=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,N=/-->/g,O=/>/g,T=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),U=/'/g,M=/"/g,x=/^(?:script|style|textarea|title)$/i,D=(t=>(e,...o)=>({_$litType$:t,strings:e,values:o}))(1),R=Symbol.for("lit-noChange"),k=Symbol.for("lit-nothing"),H=new WeakMap,L=b.createTreeWalker(b,129,null,!1),j=(t,e)=>{const o=t.length-1,s=[];let i,n=2===e?"":"",r=P;for(let e=0;e"===d[0]?(r=null!=i?i:P,l=-1):void 0===d[1]?l=-2:(l=r.lastIndex-d[2].length,a=d[1],r=void 0===d[3]?T:'"'===d[3]?M:U):r===M||r===U?r=T:r===N||r===O?r=P:(r=T,i=void 0);const h=r===T&&t[e+1].startsWith("/>")?" ":"";n+=r===P?o+E:l>=0?(s.push(a),o.slice(0,l)+"$lit$"+o.slice(l)+$+h):o+$+(-2===l?(s.push(void 0),e):h)}const a=n+(t[o]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==g?g.createHTML(a):a,s]};class I{constructor({strings:t,_$litType$:e},o){let s;this.parts=[];let i=0,n=0;const r=t.length-1,a=this.parts,[d,l]=j(t,e);if(this.el=I.createElement(d,o),L.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(s=L.nextNode())&&a.length0){s.textContent=y?y.emptyScript:"";for(let o=0;oC(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]))(t)?this.k(t):this.g(t)}O(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}g(t){this._$AH!==k&&S(this._$AH)?this._$AA.nextSibling.data=t:this.T(b.createTextNode(t)),this._$AH=t}$(t){var e;const{values:o,_$litType$:s}=t,i="number"==typeof s?this._$AC(t):(void 0===s.el&&(s.el=I.createElement(s.h,this.options)),s);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===i)this._$AH.p(o);else{const t=new q(i,this),e=t.v(this.options);t.p(o),this.T(e),this._$AH=t}}_$AC(t){let e=H.get(t.strings);return void 0===e&&H.set(t.strings,e=new I(t)),e}k(t){C(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let o,s=0;for(const i of t)s===e.length?e.push(o=new B(this.O(A()),this.O(A()),this,this.options)):o=e[s],o._$AI(i),s++;s2||""!==o[0]||""!==o[1]?(this._$AH=Array(o.length-1).fill(new String),this.strings=o):this._$AH=k}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,o,s){const i=this.strings;let n=!1;if(void 0===i)t=z(this,t,e,0),n=!S(t)||t!==this._$AH&&t!==R,n&&(this._$AH=t);else{const s=t;let r,a;for(t=i[0],r=0;r{var s,i;const n=null!==(s=null==o?void 0:o.renderBefore)&&void 0!==s?s:e;let r=n._$litPart$;if(void 0===r){const t=null!==(i=null==o?void 0:o.renderBefore)&&void 0!==i?i:null;n._$litPart$=r=new B(e.insertBefore(A(),t),t,void 0,null!=o?o:{})}return r._$AI(t),r})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return R}}X.finalized=!0,X._$litElement$=!0,null===(G=globalThis.litElementHydrateSupport)||void 0===G||G.call(globalThis,{LitElement:X});const tt=globalThis.litElementPolyfillSupport;null==tt||tt({LitElement:X}),(null!==(Q=globalThis.litElementVersions)&&void 0!==Q?Q:globalThis.litElementVersions=[]).push("3.2.2");const et=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(o){o.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(o){o.createProperty(e.key,t)}};function ot(t){return(e,o)=>void 0!==o?((t,e,o)=>{e.constructor.createProperty(o,t)})(t,e,o):et(t,e)}var st;async function it(){const t=await async function(){await Promise.race([customElements.whenDefined("home-assistant"),customElements.whenDefined("hc-main")]);const t=customElements.get("home-assistant")?"home-assistant":"hc-main";for(;!document.querySelector(t);)await new Promise((t=>window.setTimeout(t,100)));return document.querySelector(t)}();for(;!t.hass;)await new Promise((t=>window.setTimeout(t,100)));return t.hass}null===(st=window.HTMLSlotElement)||void 0===st||st.prototype.assignedElements;window.cardMod_template_cache=window.cardMod_template_cache||{};const nt=window.cardMod_template_cache;async function rt(t,e,o){const s=await it(),i=s.connection,n=JSON.stringify([e,o]);let r=nt[n];r?(r.callbacks.has(t)||at(t),t(r.value),r.callbacks.add(t)):(at(t),t(""),o=Object.assign({user:s.user.name,browser:document.querySelector("hc-main")?"CAST":localStorage["browser_mod-browser-id"]?localStorage["browser_mod-browser-id"]:"",hash:location.hash.substr(1)||""},o),nt[n]=r={template:e,variables:o,value:"",callbacks:new Set([t]),unsubscribe:i.subscribeMessage((t=>function(t,e){const o=nt[t];o&&(o.value=e.result,o.callbacks.forEach((t=>t(e.result))))}(n,t)),{type:"render_template",template:e,variables:o})})}async function at(t){let e;for(const[o,s]of Object.entries(nt))if(s.callbacks.has(t)){s.callbacks.delete(t),0==s.callbacks.size&&(e=s.unsubscribe,delete nt[o]);break}e&&await(await e)()}var dt="3.2.2";const lt=async t=>{await(async()=>{if(customElements.get("developer-tools-event"))return;await customElements.whenDefined("partial-panel-resolver");const t=document.createElement("partial-panel-resolver");t.hass={panels:[{url_path:"tmp",component_name:"developer-tools"}]},t._updateRoutes(),await t.routerOptions.routes.tmp.load(),await customElements.whenDefined("developer-tools-router");const e=document.createElement("developer-tools-router");await e.routerOptions.routes.event.load()})();return document.createElement("developer-tools-event")._computeParsedEventData(t)};async function ct(t,e,o="",s={},i=null,n=!0){var r;if(!t)return;let a;(null===(r=t.localName)||void 0===r?void 0:r.includes("-"))&&await customElements.whenDefined(t.localName),t.updateComplete&&await t.updateComplete,void 0===t._cardMod&&(t._cardMod=[]);for(const o of t._cardMod)if(o.type===e){a=o;break}return a||(a=document.createElement("card-mod"),a.type=e,t._cardMod.push(a)),queueMicrotask((async()=>{const e=t.modElement?t.modElement:n&&t.shadowRoot||t;e.contains(a)||e.appendChild(a),a.variables=s,a.styles=o})),a}function ht(t,e){const o=t=>t&&"object"==typeof t&&!Array.isArray(t);if(o(t)&&o(e))for(const s in e)o(e[s])?(t[s]||Object.assign(t,{[s]:{}}),"string"==typeof t[s]&&(t[s]={".":t[s]}),ht(t[s],e[s])):t[s]?t[s]=e[s]+t[s]:t[s]=e[s];return t}function ut(t,e){if(t===e)return!0;if(typeof t!=typeof e)return!1;if(!(t instanceof Object&&e instanceof Object))return!1;for(const o in t)if(t.hasOwnProperty(o)){if(!e.hasOwnProperty(o))return!1;if(t[o]!==e[o]){if("object"!=typeof t[o])return!1;if(!ut(t[o],e[o]))return!1}}for(const o in e)if(e.hasOwnProperty(o)&&!t.hasOwnProperty(o))return!1;return!0}function pt(t){return t.config?t.config:t._config?t._config:t.host?pt(t.host):t.parentElement?pt(t.parentElement):t.parentNode?pt(t.parentNode):null}function mt(t,e){for(const o of e)t.add(o)}async function ft(t,e=0){let o=new Set;if(10==e)return o;if(!t)return o;if(t._cardMod)for(const e of t._cardMod)e.styles&&o.add(e);return t.updateComplete&&await t.updateComplete,t.parentElement?mt(o,await ft(t.parentElement,e+1)):t.parentNode&&mt(o,await ft(t.parentNode,e+1)),t.host&&mt(o,await ft(t.host,e+1)),o}async function vt(t,e=!1){var o;if((null===(o=t.localName)||void 0===o?void 0:o.includes("-"))&&await customElements.whenDefined(t.localName),t.updateComplete&&await t.updateComplete,e&&(t.pageRendered&&await t.pageRendered,t._panelState)){let e=0;for(;"loaded"!==t._panelState&&e++<5;)await new Promise((t=>setTimeout(t,100)))}}async function _t(t,e,o=!1){let s=[t];for("string"==typeof e&&(e=e.split(/(\$| )/));""===e[e.length-1];)e.pop();for(const[t,o]of e.entries()){const t=s[0];if(!t)return null;o.trim().length&&(vt(t),s="$"===o?[t.shadowRoot]:t.querySelectorAll(o))}return o?s:s[0]}async function yt(t,e,o=!1,s=1e4){return Promise.race([_t(t,e,o),new Promise(((t,e)=>setTimeout((()=>e(new Error("SELECTTREE-TIMEOUT"))),s)))]).catch((t=>{if(!t.message||"SELECTTREE-TIMEOUT"!==t.message)throw t;return null}))}class gt extends X{static get applyToElement(){return ct}constructor(){super(),this._rendered_styles="",this._styleChildren=new Set,this._observer=new MutationObserver((t=>{for(const e of t){if("card-mod"===e.target.localName)return;e.addedNodes.length&&e.addedNodes.forEach((t=>{t.localName})),e.removedNodes.length&&e.removedNodes.forEach((t=>{t.localName}))}stop||this.refresh()})),document.addEventListener("cm_update",(()=>{this.refresh()}))}connectedCallback(){super.connectedCallback(),this._connect(),this.setAttribute("slot","none")}disconnectedCallback(){super.disconnectedCallback(),this._disconnect()}set styles(t){ut(t,this._input_styles)||(this._input_styles=t,(async()=>{let e=JSON.parse(JSON.stringify(t||{}));"string"==typeof e&&(e={".":e});ht(e,await async function(t){var e;if(!t.type)return null;const o=t.parentElement?t.parentElement:t,s=window.getComputedStyle(o).getPropertyValue("--card-mod-theme"),i=await it();if(!i)return{};const n=null!==(e=null==i?void 0:i.themes.themes)&&void 0!==e?e:{};return n[s]?n[s][`card-mod-${t.type}-yaml`]?lt(n[s][`card-mod-${t.type}-yaml`]):n[s][`card-mod-${t.type}`]?{".":n[s][`card-mod-${t.type}`]}:{}:{}}(this)),this._fixed_styles=e,this._connect()})())}get styles(){return this._styles}refresh(){this._connect()}async _styleChildEl(t,e){if(void 0===e){const o=this._fixed_styles;for(const[s,i]of Object.entries(o)){if("."===s)continue;if((await yt(this.parentElement||this.parentNode,s,!0)).forEach((o=>{o===t&&(e=i)})),void 0!==e)break}if(void 0===e)return}if(!t)return;const o=await ct(t,`${this.type}-child`,e,this.variables,null,!1);return o.refresh,o}async _connect(){var t;const e=null!==(t=this._fixed_styles)&&void 0!==t?t:{},o=new Set;let s="",i=!1;const n=this.parentElement||this.parentNode;for(const[t,r]of Object.entries(e))if("."===t)s=r;else{i=!0;const e=await yt(n,t,!0);if(!e)continue;for(const t of e){const e=await this._styleChildEl(t,r);e&&o.add(e)}}for(const t of this._styleChildren)o.has(t)||t&&(t.styles="");var r;(this._styleChildren=o,this._styles!==s)&&(this._styles=s,this._styles&&(r=this._styles,String(r).includes("{%")||String(r).includes("{{"))?(this._renderer=this._renderer||this._style_rendered.bind(this),rt(this._renderer,this._styles,this.variables)):this._style_rendered(this._styles||""),i&&(this._observer.disconnect(),this._observer.observe(function(t){if(!t)return;const e=t.parentElement||t.parentNode;return e?e.host?e.host:e:void 0}(this),{childList:!0})))}async _disconnect(){this._observer.disconnect(),this._styles="",await at(this._renderer)}_style_rendered(t){this._rendered_styles!==t&&(this._rendered_styles=t),this.dispatchEvent(new Event("card-mod-update"))}createRenderRoot(){return this}render(){return D` - `}}e([st()],bt.prototype,"_rendered_styles",void 0),(async()=>{for(;void 0===customElements.get("home-assistant");)await new Promise((t=>window.setTimeout(t,100)));customElements.get("card-mod")||(customElements.define("card-mod",bt),console.info(`%cCARD-MOD ${pt} IS INSTALLED`,"color: green; font-weight: bold"))})(),customElements.whenDefined("ha-card").then((()=>{const t=customElements.get("ha-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=function(...t){var o,s;null==e||e.bind(this)(...t);const i=$t(this);(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&this.classList.add(i.card_mod.class),(null==i?void 0:i.type)&&this.classList.add(`type-${i.type.replace(":","-")}`),yt(this,"card",(null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style)||(null==i?void 0:i.style)||"",{config:i},null,!1).then((t=>{var e;const o=null===(e=this.parentNode)||void 0===e?void 0:e.host;if(o){if(o.setConfig&&!o.setConfig.cm_patched){const e=o.setConfig;o.setConfig=function(o,...s){var i;e.bind(this)(o,...s),t.variables={config:o},t.styles=(null===(i=o.card_mod)||void 0===i?void 0:i.style)||{}},o.setConfig.cm_patched=!0}if(o.update&&!o.update.cm_patched){const e=o.update;o.update=function(...o){e.bind(this)(...o),this.updateComplete?this.updateComplete.then((()=>{t.refresh()})):t.refresh()},o.update.cm_patched=!0}}}))}})),customElements.whenDefined("hui-entities-card").then((()=>{const t=customElements.get("hui-entities-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.renderEntity;t.prototype.renderEntity=function(t,...o){var s;const i=e.bind(this)(t,...o);if(!i||!i.values)return i;const n=i.values[0];if(!n)return i;if("custom:mod-card"===(null==t?void 0:t.type))return i;(null===(s=null==t?void 0:t.card_mod)||void 0===s?void 0:s.class)&&n.classList.add(t.card_mod.class),(null==t?void 0:t.type)&&n.classList.add(`type-${t.type.replace(":","-")}`);const r=async()=>{var e;return yt(n,"row",(null===(e=null==t?void 0:t.card_mod)||void 0===e?void 0:e.style)||(null==t?void 0:t.style)||"",{config:t})};return(async()=>{const t=await r();if(n.update&&!n.update.cm_patched){const e=n.update;n.update=function(...o){e.bind(this)(...o),this.updateComplete?this.updateComplete.then((()=>{t.refresh()})):t.refresh()}}})(),this.updateComplete.then((()=>r())),i.values[0]&&i.values[0].addEventListener("ll-rebuild",r),i}}));customElements.whenDefined("hui-glance-card").then((()=>{const t=customElements.get("hui-glance-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){var o,s;null==e||e.bind(this)(...t);for(const t of this.shadowRoot.querySelectorAll("ha-card div.entity")){if(!t.cardmod_patched){t.cardmod_patched=!0;const e=t.attachShadow({mode:"open"});for(;t.firstChild;)e.append(t.firstChild);const o=document.createElement("style");e.appendChild(o),o.innerHTML="\ndiv {\n width: 100%;\n text-align: center;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.name {\n min-height: var(--paper-font-body1_-_line-height, 20px);\n}\nstate-badge {\n margin: 8px 0;\n}\n"}const e=t.config||t.entityConf;(null===(o=null==e?void 0:e.card_mod)||void 0===o?void 0:o.class)&&t.classList.add(e.card_mod.class),yt(t,"glance",(null===(s=null==e?void 0:e.card_mod)||void 0===s?void 0:s.style)||(null==e?void 0:e.style)||"",{config:e})}}})),customElements.whenDefined("hui-state-label-badge").then((()=>{const t=customElements.get("hui-state-label-badge");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=function(...t){var o,s;null==e||e.bind(this)(...t);const i=this._config;(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&this.classList.add(i.card_mod.class),yt(this,"badge",(null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style)||(null==i?void 0:i.style)||"",{config:i})}})),customElements.whenDefined("hui-view").then((()=>{const t=customElements.get("hui-view");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),yt(this,"view","",{},null,!1)}})),customElements.whenDefined("hui-root").then((()=>{const t=customElements.get("hui-root");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=async function(...t){null==e||e.bind(this)(...t),yt(this,"root")},ft(document,"home-assistant$home-assistant-main$mwc-drawer partial-panel-resolver ha-panel-lovelace$hui-root",!1).then((t=>{null==t||t.firstUpdated()}))})),customElements.whenDefined("ha-more-info-dialog").then((()=>{const t=customElements.get("ha-more-info-dialog");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.showDialog;t.prototype.showDialog=function(t,...o){null==e||e.bind(this)(t,...o),this.requestUpdate(),this.updateComplete.then((async()=>{const e=this.shadowRoot.querySelector("ha-dialog");e&&yt(e,"more-info","",{config:t},null,!1)}))},ft(document,"home-assistant$ha-more-info-dialog",!1).then((e=>{e&&(e.showDialog=t.prototype.showDialog.bind(e),e.showDialog({entityId:e.entityId}))}))})),customElements.whenDefined("ha-sidebar").then((()=>{const t=customElements.get("ha-sidebar");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=async function(...t){null==e||e.bind(this)(...t),yt(this,"sidebar")},ft(document,"home-assistant$home-assistant-main$mwc-drawer ha-sidebar",!1).then((t=>null==t?void 0:t.firstUpdated()))})),customElements.whenDefined("hui-card-element-editor").then((()=>{const t=customElements.get("hui-card-element-editor");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.getConfigElement;t.prototype.getConfigElement=async function(){const t=await e.bind(this)();if(t){const e=t.setConfig;t.setConfig=function(t,...o){var s,i;const n=JSON.parse(JSON.stringify(t));if(this._cardModData={card:n.card_mod,entities:[]},n.entities)for(const[t,e]of null===(s=n.entities)||void 0===s?void 0:s.entries())this._cardModData.entities[t]=e.card_mod,delete e.card_mod;if(delete n.card_mod,e.bind(this)(n,...o),n.entities)for(const[t,e]of null===(i=n.entities)||void 0===i?void 0:i.entries())this._cardModData.entities[t]&&(e.card_mod=this._cardModData.entities[t])}}return t};const o=t.prototype._handleUIConfigChanged;t.prototype._handleUIConfigChanged=function(t,...e){if(this._configElement&&this._configElement._cardModData){const e=this._configElement._cardModData;e.card&&(t.detail.config.card_mod=e.card)}o.bind(this)(t,...e)}})),customElements.whenDefined("hui-dialog-edit-card").then((()=>{const t=customElements.get("hui-dialog-edit-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),this.updateComplete.then((async()=>{var t,e,o;this._cardModIcon||(this._cardModIcon=document.createElement("ha-icon"),this._cardModIcon.icon="mdi:brush");const s=this.shadowRoot.querySelector("mwc-button[slot=secondaryAction]");s&&(s.appendChild(this._cardModIcon),(null===(t=this._cardConfig)||void 0===t?void 0:t.card_mod)||(null===(o=null===(e=this._cardConfig)||void 0===e?void 0:e.entities)||void 0===o?void 0:o.some((t=>t.card_mod)))?this._cardModIcon.style.visibility="visible":this._cardModIcon.style.visibility="hidden")}))}})),customElements.whenDefined("hui-picture-elements-card").then((()=>{const t=customElements.get("hui-picture-elements-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.setConfig;t.prototype.setConfig=function(...t){var o,s;null==e||e.bind(this)(...t);for(const[t,e]of this._elements.entries()){const i=this._config.elements[t];(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&e.classList.add(i.card_mod.class),(null==i?void 0:i.type)&&e.classList.add(`type-${i.type.replace(":","-")}`),yt(e,"element",null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style,{config:i})}}}));const At=t=>{const e=window.getComputedStyle(t);"none"===e.getPropertyValue("--card-mod-icon-dim")&&(t.style.filter="none");const o=e.getPropertyValue("--card-mod-icon");o&&(t.icon=o.trim());const s=e.getPropertyValue("--card-mod-icon-color");s&&(t.style.color=s)},St=async t=>{if(t.cardmod_bound)return;t.cardmod_bound=!0;const e=async()=>{const e=await Et(t);for(const o of e)o.addEventListener("card-mod-update",(async()=>{await o.updateComplete,At(t)}));return At(t),e};0==(await e()).size&&window.setTimeout((()=>e()),1e3)};customElements.whenDefined("ha-state-icon").then((()=>{const t=customElements.get("ha-state-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){e.bind(this)(...t),St(this),At(this)}})),customElements.whenDefined("ha-icon").then((()=>{const t=customElements.get("ha-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),St(this)}})),customElements.whenDefined("ha-svg-icon").then((()=>{const t=customElements.get("ha-svg-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){var o,s;null==e||e.bind(this)(...t),"ha-icon"!==(null===(s=null===(o=this.parentNode)||void 0===o?void 0:o.host)||void 0===s?void 0:s.localName)&&St(this)}}));const Ct="\nha-card {\n background: none;\n box-shadow: none;\n border: none;\n transition: none;\n}";class Nt extends tt{setConfig(t){var e;this._config=JSON.parse(JSON.stringify(t));let o=(null===(e=this._config.card_mod)||void 0===e?void 0:e.style)||this._config.style;void 0===o?o=Ct:"string"==typeof o?o=Ct+o:o["."]?o["."]=Ct+o["."]:o["."]=Ct,this._config.card_mod={style:o},this.build_card(t.card)}async build_card(t){void 0===this._hass&&await new Promise((t=>this._hassResolve=t)),this._hassResolve=void 0;const e=await window.loadCardHelpers();this.card=await e.createCardElement(t),this.card.hass=this._hass}firstUpdated(){window.setTimeout((()=>{var t,e;if(null===(e=null===(t=this.card)||void 0===t?void 0:t.shadowRoot)||void 0===e?void 0:e.querySelector("ha-card")){console.info("%cYou are doing it wrong!","color: red; font-weight: bold");let t=this.card.localName.replace(/hui-(.*)-card/,"$1");console.info(`mod-card should NEVER be used with a card that already has a ha-card element, such as ${t}`)}}),3e3)}set hass(t){this._hass=t,this.card&&(this.card.hass=t),this._hassResolve&&this._hassResolve()}render(){return T` ${this.card} `}getCardSize(){if(this._config.report_size)return this._config.report_size;let t=this.shadowRoot;return t&&(t=t.querySelector("ha-card card-maker")),t&&(t=t.getCardSize),t&&(t=t()),t||1}}function Pt(){document.dispatchEvent(new Event("cm_update"))}e([st()],Nt.prototype,"card",void 0),(async()=>{for(;void 0===customElements.get("home-assistant");)await new Promise((t=>window.setTimeout(t,100)));customElements.get("mod-card")||customElements.define("mod-card",Nt)})();const Ot=[customElements.whenDefined("home-assistant"),customElements.whenDefined("hc-main")];Promise.race(Ot).then((()=>{window.setTimeout((async()=>{for(var e,o;!t();)await new Promise((t=>window.setTimeout(t,500)));t().connection.subscribeEvents((()=>{window.setTimeout(Pt,500)}),"themes_updated"),null===(e=document.querySelector("home-assistant"))||void 0===e||e.addEventListener("settheme",Pt),null===(o=document.querySelector("hc-main"))||void 0===o||o.addEventListener("settheme",Pt)}),1e3)}));const Rt=function(){var t,e,o;const s=document.querySelectorAll("script"),i=[];for(const n of s)if(null===(e=null===(t=null==n?void 0:n.innerText)||void 0===t?void 0:t.trim())||void 0===e?void 0:e.startsWith("import(")){const t=null===(o=n.innerText.split("\n"))||void 0===o?void 0:o.map((t=>t.trim()));for(const e of t)i.push(e.replace(/^import\(\"/,"").replace(/\"\);/,""))}return i}();Rt.some((t=>t.endsWith("card-mod.js")))||(!function(t,e,o=null){if((t=new Event(t,{bubbles:!0,cancelable:!1,composed:!0})).detail=e||{},o)o.dispatchEvent(t);else{var s=function(){var t=document.querySelector("hc-main");return t?(t=(t=(t=t&&t.shadowRoot)&&t.querySelector("hc-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-view")||t.querySelector("hui-panel-view"):(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=(t=document.querySelector("home-assistant"))&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root"))&&t.shadowRoot)&&t.querySelector("ha-app-layout"))&&t.querySelector("#view"))&&t.firstElementChild}();s&&s.dispatchEvent(t)}}("ll-rebuild",{}),console.info("You may not be getting optimal performance out of card-mod.\nSee https://github.com/thomasloven/lovelace-card-mod#performance-improvements")); + `}}t([ot()],gt.prototype,"_rendered_styles",void 0),(async()=>{for(;void 0===customElements.get("home-assistant");)await new Promise((t=>window.setTimeout(t,100)));customElements.get("card-mod")||(customElements.define("card-mod",gt),console.info(`%cCARD-MOD ${dt} IS INSTALLED`,"color: green; font-weight: bold"))})(),customElements.whenDefined("ha-card").then((()=>{const t=customElements.get("ha-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=function(...t){var o,s;null==e||e.bind(this)(...t);const i=pt(this);(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&this.classList.add(i.card_mod.class),(null==i?void 0:i.type)&&this.classList.add(`type-${i.type.replace(":","-")}`),ct(this,"card",(null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style)||(null==i?void 0:i.style)||"",{config:i},null,!1).then((t=>{var e;const o=null===(e=this.parentNode)||void 0===e?void 0:e.host;if(o){if(o.setConfig&&!o.setConfig.cm_patched){const e=o.setConfig;o.setConfig=function(o,...s){var i;e.bind(this)(o,...s),t.variables={config:o},t.styles=(null===(i=o.card_mod)||void 0===i?void 0:i.style)||{}},o.setConfig.cm_patched=!0}if(o.update&&!o.update.cm_patched){const e=o.update;o.update=function(...o){e.bind(this)(...o),this.updateComplete?this.updateComplete.then((()=>{t.refresh()})):t.refresh()},o.update.cm_patched=!0}}}))}})),customElements.whenDefined("hui-entities-card").then((()=>{const t=customElements.get("hui-entities-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.renderEntity;t.prototype.renderEntity=function(t,...o){var s;const i=e.bind(this)(t,...o);if(!i||!i.values)return i;const n=i.values[0];if(!n)return i;if("custom:mod-card"===(null==t?void 0:t.type))return i;(null===(s=null==t?void 0:t.card_mod)||void 0===s?void 0:s.class)&&n.classList.add(t.card_mod.class),(null==t?void 0:t.type)&&n.classList.add(`type-${t.type.replace(":","-")}`);const r=async()=>{var e;return ct(n,"row",(null===(e=null==t?void 0:t.card_mod)||void 0===e?void 0:e.style)||(null==t?void 0:t.style)||"",{config:t})};return(async()=>{const t=await r();if(n.update&&!n.update.cm_patched){const e=n.update;n.update=function(...o){e.bind(this)(...o),this.updateComplete?this.updateComplete.then((()=>{t.refresh()})):t.refresh()}}})(),this.updateComplete.then((()=>r())),i.values[0]&&i.values[0].addEventListener("ll-rebuild",r),i}}));customElements.whenDefined("hui-glance-card").then((()=>{const t=customElements.get("hui-glance-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){var o,s;null==e||e.bind(this)(...t);for(const t of this.shadowRoot.querySelectorAll("ha-card div.entity")){if(!t.cardmod_patched){t.cardmod_patched=!0;const e=t.attachShadow({mode:"open"});for(;t.firstChild;)e.append(t.firstChild);const o=document.createElement("style");e.appendChild(o),o.innerHTML="\ndiv {\n width: 100%;\n text-align: center;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n}\n.name {\n min-height: var(--paper-font-body1_-_line-height, 20px);\n}\nstate-badge {\n margin: 8px 0;\n}\n"}const e=t.config||t.entityConf;(null===(o=null==e?void 0:e.card_mod)||void 0===o?void 0:o.class)&&t.classList.add(e.card_mod.class),ct(t,"glance",(null===(s=null==e?void 0:e.card_mod)||void 0===s?void 0:s.style)||(null==e?void 0:e.style)||"",{config:e})}}})),customElements.whenDefined("hui-state-label-badge").then((()=>{const t=customElements.get("hui-state-label-badge");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=function(...t){var o,s;null==e||e.bind(this)(...t);const i=this._config;(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&this.classList.add(i.card_mod.class),ct(this,"badge",(null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style)||(null==i?void 0:i.style)||"",{config:i})}})),customElements.whenDefined("hui-view").then((()=>{const t=customElements.get("hui-view");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),ct(this,"view","",{},null,!1)}})),customElements.whenDefined("hui-root").then((()=>{const t=customElements.get("hui-root");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=async function(...t){null==e||e.bind(this)(...t),ct(this,"root")},yt(document,"home-assistant$home-assistant-main$partial-panel-resolver ha-panel-lovelace$hui-root",!1).then((t=>{null==t||t.firstUpdated()}))})),customElements.whenDefined("ha-more-info-dialog").then((()=>{const t=customElements.get("ha-more-info-dialog");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.showDialog;t.prototype.showDialog=function(t,...o){null==e||e.bind(this)(t,...o),this.requestUpdate(),this.updateComplete.then((async()=>{const e=this.shadowRoot.querySelector("ha-dialog");e&&ct(e,"more-info","",{config:t},null,!1)}))},yt(document,"home-assistant$ha-more-info-dialog",!1).then((e=>{e&&(e.showDialog=t.prototype.showDialog.bind(e),e.showDialog({entityId:e.entityId}))}))})),customElements.whenDefined("ha-sidebar").then((()=>{const t=customElements.get("ha-sidebar");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.firstUpdated;t.prototype.firstUpdated=async function(...t){null==e||e.bind(this)(...t),ct(this,"sidebar")},yt(document,"home-assistant$home-assistant-main$ ha-sidebar",!1).then((t=>{null==t||t.firstUpdated()}))})),customElements.whenDefined("hui-card-element-editor").then((()=>{const t=customElements.get("hui-card-element-editor");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.getConfigElement;t.prototype.getConfigElement=async function(){const t=await e.bind(this)();if(t){const e=t.setConfig;t.setConfig=function(t,...o){var s,i;const n=JSON.parse(JSON.stringify(t));if(this._cardModData={card:n.card_mod,entities:[]},n.entities)for(const[t,e]of null===(s=n.entities)||void 0===s?void 0:s.entries())this._cardModData.entities[t]=e.card_mod,delete e.card_mod;if(delete n.card_mod,e.bind(this)(n,...o),n.entities)for(const[t,e]of null===(i=n.entities)||void 0===i?void 0:i.entries())this._cardModData.entities[t]&&(e.card_mod=this._cardModData.entities[t])}}return t};const o=t.prototype._handleUIConfigChanged;t.prototype._handleUIConfigChanged=function(t,...e){if(this._configElement&&this._configElement._cardModData){const e=this._configElement._cardModData;e.card&&(t.detail.config.card_mod=e.card)}o.bind(this)(t,...e)}})),customElements.whenDefined("hui-dialog-edit-card").then((()=>{const t=customElements.get("hui-dialog-edit-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),this.updateComplete.then((async()=>{var t,e,o;this._cardModIcon||(this._cardModIcon=document.createElement("ha-icon"),this._cardModIcon.icon="mdi:brush");const s=this.shadowRoot.querySelector("mwc-button[slot=secondaryAction]");s&&(s.appendChild(this._cardModIcon),(null===(t=this._cardConfig)||void 0===t?void 0:t.card_mod)||(null===(o=null===(e=this._cardConfig)||void 0===e?void 0:e.entities)||void 0===o?void 0:o.some((t=>t.card_mod)))?this._cardModIcon.style.visibility="visible":this._cardModIcon.style.visibility="hidden")}))}})),customElements.whenDefined("hui-picture-elements-card").then((()=>{const t=customElements.get("hui-picture-elements-card");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.setConfig;t.prototype.setConfig=function(...t){var o,s;null==e||e.bind(this)(...t);for(const[t,e]of this._elements.entries()){const i=this._config.elements[t];(null===(o=null==i?void 0:i.card_mod)||void 0===o?void 0:o.class)&&e.classList.add(i.card_mod.class),(null==i?void 0:i.type)&&e.classList.add(`type-${i.type.replace(":","-")}`),ct(e,"element",null===(s=null==i?void 0:i.card_mod)||void 0===s?void 0:s.style,{config:i})}}}));const $t=t=>{const e=window.getComputedStyle(t);"none"===e.getPropertyValue("--card-mod-icon-dim")&&(t.style.filter="none");const o=e.getPropertyValue("--card-mod-icon");o&&(t.icon=o.trim());const s=e.getPropertyValue("--card-mod-icon-color");s&&(t.style.color=s)},wt=async t=>{if(t.cardmod_bound)return;t.cardmod_bound=!0;const e=async()=>{const e=await ft(t);for(const o of e)o.addEventListener("card-mod-update",(async()=>{await o.updateComplete,$t(t)}));return $t(t),e};0==(await e()).size&&window.setTimeout((()=>e()),1e3)};customElements.whenDefined("ha-state-icon").then((()=>{const t=customElements.get("ha-state-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){e.bind(this)(...t),wt(this),$t(this)}})),customElements.whenDefined("ha-icon").then((()=>{const t=customElements.get("ha-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){null==e||e.bind(this)(...t),wt(this)}})),customElements.whenDefined("ha-svg-icon").then((()=>{const t=customElements.get("ha-svg-icon");if(t.prototype.cardmod_patched)return;t.prototype.cardmod_patched=!0;const e=t.prototype.updated;t.prototype.updated=function(...t){var o,s;null==e||e.bind(this)(...t),"ha-icon"!==(null===(s=null===(o=this.parentNode)||void 0===o?void 0:o.host)||void 0===s?void 0:s.localName)&&wt(this)}}));const Et="\nha-card {\n background: none;\n box-shadow: none;\n border: none;\n transition: none;\n}";class bt extends X{setConfig(t){var e;this._config=JSON.parse(JSON.stringify(t));let o=(null===(e=this._config.card_mod)||void 0===e?void 0:e.style)||this._config.style;void 0===o?o=Et:"string"==typeof o?o=Et+o:o["."]?o["."]=Et+o["."]:o["."]=Et,this._config.card_mod={style:o},this.build_card(t.card)}async build_card(t){void 0===this._hass&&await new Promise((t=>this._hassResolve=t)),this._hassResolve=void 0;const e=await window.loadCardHelpers();this.card=await e.createCardElement(t),this.card.hass=this._hass}firstUpdated(){window.setTimeout((()=>{var t,e;if(null===(e=null===(t=this.card)||void 0===t?void 0:t.shadowRoot)||void 0===e?void 0:e.querySelector("ha-card")){console.info("%cYou are doing it wrong!","color: red; font-weight: bold");let t=this.card.localName.replace(/hui-(.*)-card/,"$1");console.info(`mod-card should NEVER be used with a card that already has a ha-card element, such as ${t}`)}}),3e3)}set hass(t){this._hass=t,this.card&&(this.card.hass=t),this._hassResolve&&this._hassResolve()}render(){return D` ${this.card} `}getCardSize(){if(this._config.report_size)return this._config.report_size;let t=this.shadowRoot;return t&&(t=t.querySelector("ha-card card-maker")),t&&(t=t.getCardSize),t&&(t=t()),t||1}}function At(){document.dispatchEvent(new Event("cm_update"))}t([ot()],bt.prototype,"card",void 0),(async()=>{for(;void 0===customElements.get("home-assistant");)await new Promise((t=>window.setTimeout(t,100)));customElements.get("mod-card")||customElements.define("mod-card",bt)})();const St=[customElements.whenDefined("home-assistant"),customElements.whenDefined("hc-main")];Promise.race(St).then((()=>{window.setTimeout((async()=>{var t,e;const o=await it();for(;!o;)await new Promise((t=>window.setTimeout(t,500)));o.connection.subscribeEvents((()=>{window.setTimeout(At,500)}),"themes_updated"),null===(t=document.querySelector("home-assistant"))||void 0===t||t.addEventListener("settheme",At),null===(e=document.querySelector("hc-main"))||void 0===e||e.addEventListener("settheme",At)}),1e3)}));const Ct=function(){var t,e,o;const s=document.querySelectorAll("script"),i=[];for(const n of s)if(null===(e=null===(t=null==n?void 0:n.innerText)||void 0===t?void 0:t.trim())||void 0===e?void 0:e.startsWith("import(")){const t=null===(o=n.innerText.split("\n"))||void 0===o?void 0:o.map((t=>t.trim()));for(const e of t)i.push(e.replace(/^import\(\"/,"").replace(/\"\);/,""))}return i}();Ct.some((t=>t.endsWith("card-mod.js")))||console.info("You may not be getting optimal performance out of card-mod.\nSee https://github.com/thomasloven/lovelace-card-mod#performance-improvements"); diff --git a/hacs.json b/hacs.json index 43f0efd..f4b542c 100644 --- a/hacs.json +++ b/hacs.json @@ -1,5 +1,5 @@ { "name": "card-mod", "render_readme": true, - "homeassistant": "2023.4.0b0" + "homeassistant": "2023.4.0b5" } diff --git a/package-lock.json b/package-lock.json index 3f974f7..f031f95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "card-mod", - "version": "3.2.0", + "version": "3.2.2", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -703,10 +703,6 @@ "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001434.tgz", "integrity": "sha512-aOBHrLmTQw//WFa2rcF1If9fa3ypkC1wzqqiKHgfdrXTWcU8C4gKVZT77eQAPWN1APys3+uQ0Df07rKauXGEYA==" }, - "card-tools": { - "version": "github:thomasloven/lovelace-card-tools#477f3d4eeb5c70cab047d418d19afb6b0f07bf49", - "from": "github:thomasloven/lovelace-card-tools" - }, "chalk": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", diff --git a/package.json b/package.json index e3b3744..e07e476 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,11 @@ { "name": "card-mod", "private": true, - "version": "3.2.1", + "version": "3.2.2", "description": "", "scripts": { "build": "rollup -c", - "watch": "rollup -c --watch", - "update-card-tools": "npm uninstall card-tools && npm install thomasloven/lovelace-card-tools" + "watch": "rollup -c --watch" }, "keywords": [], "author": "Thomas Lovén", @@ -19,7 +18,6 @@ "@rollup/plugin-babel": "^6.0.2", "@rollup/plugin-json": "^5.0.1", "@rollup/plugin-node-resolve": "^15.0.1", - "card-tools": "github:thomasloven/lovelace-card-tools", "lit": "^2.4.1", "rollup": "^3.4.0", "rollup-plugin-typescript2": "^0.34.1", diff --git a/src/card-mod.ts b/src/card-mod.ts index 64f096a..e6b85bd 100644 --- a/src/card-mod.ts +++ b/src/card-mod.ts @@ -1,9 +1,11 @@ import { LitElement, html } from "lit"; import { property } from "lit/decorators.js"; -import { bind_template, unbind_template } from "./templates"; -import { hasTemplate } from "card-tools/src/templates"; +import { + hasTemplate, + bind_template, + unbind_template, +} from "./helpers/templates"; import pjson from "../package.json"; -import { selectTree } from "card-tools/src/helpers"; import { applyToElement, compare_deep, @@ -12,6 +14,7 @@ import { parentElement, Styles, } from "./helpers"; +import { selectTree } from "./helpers/selecttree"; export class CardMod extends LitElement { type: string; diff --git a/src/helpers.ts b/src/helpers.ts index ddf0b2d..81617c5 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,5 +1,5 @@ -import { hass } from "card-tools/src/hass"; -import { yaml2json } from "card-tools/src/yaml"; +import { hass } from "./helpers/hass"; +import { yaml2json } from "./helpers/yaml2json"; import { CardMod } from "./card-mod"; interface ModdedElement extends HTMLElement { @@ -67,8 +67,9 @@ export async function get_theme(root: CardMod): Promise { .getComputedStyle(el) .getPropertyValue("--card-mod-theme"); - if (!hass()) return {}; - const themes = hass()?.themes.themes ?? {}; + const hs = await hass(); + if (!hs) return {}; + const themes = hs?.themes.themes ?? {}; if (!themes[theme]) return {}; if (themes[theme][`card-mod-${root.type}-yaml`]) { diff --git a/src/helpers/browser_id.ts b/src/helpers/browser_id.ts new file mode 100644 index 0000000..5c50466 --- /dev/null +++ b/src/helpers/browser_id.ts @@ -0,0 +1,6 @@ +const ID_STORAGE_KEY = "browser_mod-browser-id"; +export function BrowserID() { + if (document.querySelector("hc-main")) return "CAST"; + if (localStorage[ID_STORAGE_KEY]) return localStorage[ID_STORAGE_KEY]; + return ""; +} diff --git a/src/helpers/hass.ts b/src/helpers/hass.ts new file mode 100644 index 0000000..b5693fe --- /dev/null +++ b/src/helpers/hass.ts @@ -0,0 +1,20 @@ +export async function hass_base_el() { + await Promise.race([ + customElements.whenDefined("home-assistant"), + customElements.whenDefined("hc-main"), + ]); + + const element = customElements.get("home-assistant") + ? "home-assistant" + : "hc-main"; + + while (!document.querySelector(element)) + await new Promise((r) => window.setTimeout(r, 100)); + return document.querySelector(element); +} + +export async function hass() { + const base: any = await hass_base_el(); + while (!base.hass) await new Promise((r) => window.setTimeout(r, 100)); + return base.hass; +} diff --git a/src/helpers/selecttree.ts b/src/helpers/selecttree.ts new file mode 100644 index 0000000..40ad537 --- /dev/null +++ b/src/helpers/selecttree.ts @@ -0,0 +1,45 @@ +const TIMEOUT_ERROR = "SELECTTREE-TIMEOUT"; + +export async function await_element(el, hard = false) { + if (el.localName?.includes("-")) + await customElements.whenDefined(el.localName); + if (el.updateComplete) await el.updateComplete; + if (hard) { + if (el.pageRendered) await el.pageRendered; + if (el._panelState) { + let rounds = 0; + while (el._panelState !== "loaded" && rounds++ < 5) + await new Promise((r) => setTimeout(r, 100)); + } + } +} + +async function _selectTree(root, path, all = false) { + let el = [root]; + if (typeof path === "string") { + path = path.split(/(\$| )/); + } + while (path[path.length - 1] === "") path.pop(); + for (const [i, p] of path.entries()) { + const e = el[0]; + if (!e) return null; + + if (!p.trim().length) continue; + + await_element(e); + el = p === "$" ? [e.shadowRoot] : e.querySelectorAll(p); + } + return all ? el : el[0]; +} + +export async function selectTree(root, path, all = false, timeout = 10000) { + return Promise.race([ + _selectTree(root, path, all), + new Promise((_, reject) => + setTimeout(() => reject(new Error(TIMEOUT_ERROR)), timeout) + ), + ]).catch((err) => { + if (!err.message || err.message !== TIMEOUT_ERROR) throw err; + return null; + }); +} diff --git a/src/templates.ts b/src/helpers/templates.ts similarity index 87% rename from src/templates.ts rename to src/helpers/templates.ts index 78c9c67..d32b9f9 100644 --- a/src/templates.ts +++ b/src/helpers/templates.ts @@ -1,5 +1,5 @@ -import { hass } from "card-tools/src/hass"; -import { deviceID } from "card-tools/src/deviceID"; +import { hass } from "./hass"; +import { BrowserID } from "./browser_id"; interface CachedTemplate { template: string; @@ -32,12 +32,17 @@ function template_updated( cache.callbacks.forEach((f) => f(result.result)); } +export function hasTemplate(str) { + return String(str).includes("{%") || String(str).includes("{{"); +} + export async function bind_template( callback: (string) => void, template: string, variables: object ): Promise { - const connection = hass().connection; + const hs = await hass(); + const connection = hs.connection; const cacheKey = JSON.stringify([template, variables]); let cache = cachedTemplates[cacheKey]; @@ -46,8 +51,8 @@ export async function bind_template( callback(""); variables = { - user: hass().user.name, - browser: deviceID, + user: hs.user.name, + browser: BrowserID(), hash: location.hash.substr(1) || "", ...variables, }; diff --git a/src/helpers/yaml2json.ts b/src/helpers/yaml2json.ts new file mode 100644 index 0000000..4f6b016 --- /dev/null +++ b/src/helpers/yaml2json.ts @@ -0,0 +1,28 @@ +const _load_yaml2json = async () => { + if (customElements.get("developer-tools-event")) return; + + await customElements.whenDefined("partial-panel-resolver"); + const ppr: any = document.createElement("partial-panel-resolver"); + + ppr.hass = { + panels: [ + { + url_path: "tmp", + component_name: "developer-tools", + }, + ], + }; + ppr._updateRoutes(); + + await ppr.routerOptions.routes.tmp.load(); + + await customElements.whenDefined("developer-tools-router"); + const dtr: any = document.createElement("developer-tools-router"); + await dtr.routerOptions.routes.event.load(); +}; + +export const yaml2json = async (yaml) => { + await _load_yaml2json(); + const el: any = document.createElement("developer-tools-event"); + return el._computeParsedEventData(yaml); +}; diff --git a/src/main.ts b/src/main.ts index 94cc91b..6669017 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,4 +1,3 @@ -import { fireEvent } from "card-tools/src/event.js"; import "./card-mod"; import "./patch/ha-card"; import "./patch/hui-entities-card"; @@ -20,7 +19,6 @@ const resources = getResources(); if (resources.some((r) => r.endsWith("card-mod.js"))) { // console.info("Card-mod is loaded as a module"); } else { - fireEvent("ll-rebuild", {}); console.info( "You may not be getting optimal performance out of card-mod.\nSee https://github.com/thomasloven/lovelace-card-mod#performance-improvements" ); diff --git a/src/patch/ha-more-info-dialog.ts b/src/patch/ha-more-info-dialog.ts index 6215799..c57fc68 100644 --- a/src/patch/ha-more-info-dialog.ts +++ b/src/patch/ha-more-info-dialog.ts @@ -1,4 +1,4 @@ -import { selectTree } from "card-tools/src/helpers"; +import { selectTree } from "../helpers/selecttree"; import { applyToElement } from "../helpers"; customElements.whenDefined("ha-more-info-dialog").then(() => { diff --git a/src/patch/ha-sidebar.ts b/src/patch/ha-sidebar.ts index df8b72d..b20fbcc 100644 --- a/src/patch/ha-sidebar.ts +++ b/src/patch/ha-sidebar.ts @@ -1,4 +1,4 @@ -import { selectTree } from "card-tools/src/helpers"; +import { selectTree } from "../helpers/selecttree"; import { applyToElement } from "../helpers"; customElements.whenDefined("ha-sidebar").then(() => { diff --git a/src/patch/hui-root.ts b/src/patch/hui-root.ts index 2ff82a9..e625b4b 100644 --- a/src/patch/hui-root.ts +++ b/src/patch/hui-root.ts @@ -1,4 +1,4 @@ -import { selectTree } from "card-tools/src/helpers"; +import { selectTree } from "../helpers/selecttree"; import { applyToElement } from "../helpers"; customElements.whenDefined("hui-root").then(() => { diff --git a/src/theme-watcher.ts b/src/theme-watcher.ts index f42893b..0754aad 100644 --- a/src/theme-watcher.ts +++ b/src/theme-watcher.ts @@ -1,4 +1,4 @@ -import { hass } from "card-tools/src/hass"; +import { hass } from "./helpers/hass"; function refresh_theme() { document.dispatchEvent(new Event("cm_update")); @@ -10,10 +10,11 @@ const bases = [ ]; Promise.race(bases).then(() => { window.setTimeout(async () => { - while (!hass()) { + const hs = await hass(); + while (!hs) { await new Promise((resolve) => window.setTimeout(resolve, 500)); } - hass().connection.subscribeEvents(() => { + hs.connection.subscribeEvents(() => { window.setTimeout(refresh_theme, 500); }, "themes_updated"); document