diff --git a/dist/button-text-card.js b/dist/button-text-card.js index a95b69c..f7eb29b 100644 --- a/dist/button-text-card.js +++ b/dist/button-text-card.js @@ -183,7 +183,7 @@ found at http://polymer.github.io/PATENTS.txt * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ -(window.litElementVersions||(window.litElementVersions=[])).push("2.3.1");const Q={};class tt extends B{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(void 0===t)this._styles=[];else if(Array.isArray(t)){const e=(t,n)=>t.reduceRight((t,n)=>Array.isArray(n)?e(n,t):(t.add(n),t),n),n=e(t,new Set),i=[];n.forEach(t=>i.unshift(t)),this._styles=i}else this._styles=[t]}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 t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Z?this.renderRoot.adoptedStyleSheets=t.map(t=>t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==Q&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){return Q}}tt.finalized=!0,tt.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const s=i.scopeName,o=V.has(e),r=H&&11===e.nodeType&&!!e.host,a=r&&!z.has(s),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let s=V.get(e);void 0===s&&(n(e,e.firstChild),V.set(e,s=new P(Object.assign({templateFactory:D},i))),s.appendInto(e)),s.setValue(t),s.commit()})(t,c,Object.assign({templateFactory:j(s)},i)),a){const t=V.get(c);V.delete(c);const i=t.value instanceof y?t.value.template:void 0;L(s,c,i),n(e,e.firstChild),e.appendChild(c),V.set(e,t)}!o&&r&&window.ShadyCSS.styleElement(e.host)};var et={},nt=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,it="[^\\s]+",st=/\[([^]*?)\]/gm,ot=function(){};function rt(t,e){for(var n=[],i=0,s=t.length;i3?0:(t-t%10!=10)*t%10]}};var pt={D:function(t){return t.getDate()},DD:function(t){return ct(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return ct(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return ct(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return ct(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return ct(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return ct(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return ct(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return ct(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return ct(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return ct(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return ct(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+ct(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},mt={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+it,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var n=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?n-1:n)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",ot],ddd:[it,ot],MMM:[it,at("monthNamesShort")],MMMM:[it,at("monthNames")],a:[it,function(t,e,n){var i=e.toLowerCase();i===n.amPm[0]?t.isPm=!1:i===n.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var n,i=(e+"").match(/([+-]|\d\d)/gi);i&&(n=60*i[1]+parseInt(i[2],10),t.timezoneOffset="+"===i[0]?n:-n)}]};mt.dd=mt.d,mt.dddd=mt.ddd,mt.DD=mt.D,mt.mm=mt.m,mt.hh=mt.H=mt.HH=mt.h,mt.MM=mt.M,mt.ss=mt.s,mt.A=mt.a,et.masks={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},et.format=function(t,e,n){var i=n||et.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=et.masks[e]||e||et.masks.default;var s=[];return(e=(e=e.replace(st,(function(t,e){return s.push(e),"@@@"}))).replace(nt,(function(e){return e in pt?pt[e](t,i):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return s.shift()}))},et.parse=function(t,e,n){var i=n||et.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=et.masks[e]||e,t.length>1e3)return null;var s={},o=[],r=[];e=e.replace(st,(function(t,e){return r.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(nt,(function(t){if(mt[t]){var e=mt[t];return o.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return r.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var d=1;d0||navigator.msMaxTouchPoints>0;class bt extends HTMLElement{constructor(){super(),this.holdTime=500,this.ripple=document.createElement("mwc-ripple"),this.timer=void 0,this.held=!1,this.cooldownStart=!1,this.cooldownEnd=!1}connectedCallback(){Object.assign(this.style,{position:"absolute",width:wt?"100px":"50px",height:wt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach(t=>{document.addEventListener(t,()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0},{passive:!0})})}bind(t,e){if(t.actionHandler)return;t.actionHandler=!0,t.addEventListener("contextmenu",t=>{const e=t||window.event;e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1});const n=t=>{if(this.cooldownStart)return;let e,n;this.held=!1,t.touches?(e=t.touches[0].pageX,n=t.touches[0].pageY):(e=t.pageX,n=t.pageY),this.timer=window.setTimeout(()=>{this.startAnimation(e,n),this.held=!0},this.holdTime),this.cooldownStart=!0,window.setTimeout(()=>this.cooldownStart=!1,100)},i=n=>{this.cooldownEnd||["touchend","touchcancel"].includes(n.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?gt(t,"action",{action:"hold"}):e.hasDoubleTap?1===n.detail||"keyup"===n.type?this.dblClickTimeout=window.setTimeout(()=>{gt(t,"action",{action:"tap"})},250):(clearTimeout(this.dblClickTimeout),gt(t,"action",{action:"double_tap"})):gt(t,"action",{action:"tap"}),this.cooldownEnd=!0,window.setTimeout(()=>this.cooldownEnd=!1,100))};t.addEventListener("touchstart",n,{passive:!0}),t.addEventListener("touchend",i),t.addEventListener("touchcancel",i),t.addEventListener("keyup",t=>{if(13===t.keyCode)return i(t)}),/iPhone OS 13_/.test(window.navigator.userAgent)||(t.addEventListener("mousedown",n,{passive:!0}),t.addEventListener("click",i))}startAnimation(t,e){Object.assign(this.style,{left:t+"px",top:e+"px",display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("action-handler-button-text-card",bt);const St=(t,e)=>{const n=(()=>{const t=document.body;if(t.querySelector("action-handler-button-text-card"))return t.querySelector("action-handler-button-text-card");const e=document.createElement("action-handler-button-text-card");return t.appendChild(e),e})();n&&n.bind(t,e)},xt=(t=>(...e)=>{const n=t(...e);return m.set(n,!0),n})((t={})=>e=>{St(e.committer.element,t)});var Ct;console.info("%c BUTTON-TEXT-CARD \n%c v0.5.6 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray");let Pt=Ct=class extends tt{constructor(){super(...arguments),this._hasTemplate=!1}setConfig(t){if(!t||t.show_error)throw new Error("Invalid configuration.");this._config=Object.assign({name:"Button Text Card",title:"",subtitle:"",large:!1},t),this._renderedConfig=Object.assign({},this._config);for(const t of Ct.templateFields){const e=Ct.templateRegex.exec(this._config[t]);if(Ct.templateRegex.lastIndex=0,null!==e){this._hasTemplate=!0;break}}}shouldUpdate(t){var e;return!(null===(e=this._config)||void 0===e?void 0:e.entity)||function(t,e,n){if(e.has("config")||n)return!0;if(t._config.entity){var i=e.get("hass");return!i||i.states[t._config.entity]!==t.hass.states[t._config.entity]}return!1}(this,t,this._hasTemplate)}evaluateJsTemplates(){if(this._renderedConfig&&this._config)for(const t of Ct.templateFields){const e=Ct.templateRegex.exec(this._config[t]);Ct.templateRegex.lastIndex=0,e&&e.length>1?this._renderedConfig[t]=this._evalTemplate(this._stateObj,e[1]):this._renderedConfig[t]=this._config[t]}}render(){if(!this._config||!this.hass||!this._renderedConfig)return Y``;if(this._stateObj=this._config.entity?this.hass.states[this._config.entity]:void 0,this.evaluateJsTemplates(),!this._inEditMode()&&!0===this._renderedConfig.hide_condition)return Y``;if(!this._config.icon||""===this._config.icon){let t="mdi:alert-circle";if(this._config.entity){const e=this.hass.states[this._config.entity].attributes.icon;e&&(t=e)}this.setConfig(Object.assign(Object.assign({},this._config),{icon:t}))}return this._renderedConfig.background_color&&this.style.setProperty("--ha-card-background",this._renderedConfig.background_color),this._renderedConfig.font_color&&this.style.setProperty("--primary-text-color",this._renderedConfig.font_color),this._renderedConfig.icon_size&&this.style.setProperty("--mdc-icon-size",this._renderedConfig.icon_size+"px"),this._configureIconColor(),Y` +(window.litElementVersions||(window.litElementVersions=[])).push("2.3.1");const Q={};class tt extends B{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(void 0===t)this._styles=[];else if(Array.isArray(t)){const e=(t,n)=>t.reduceRight((t,n)=>Array.isArray(n)?e(n,t):(t.add(n),t),n),n=e(t,new Set),i=[];n.forEach(t=>i.unshift(t)),this._styles=i}else this._styles=[t]}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 t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Z?this.renderRoot.adoptedStyleSheets=t.map(t=>t.styleSheet):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map(t=>t.cssText),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==Q&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach(t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)}))}render(){return Q}}tt.finalized=!0,tt.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const s=i.scopeName,o=V.has(e),r=H&&11===e.nodeType&&!!e.host,a=r&&!z.has(s),c=a?document.createDocumentFragment():e;if(((t,e,i)=>{let s=V.get(e);void 0===s&&(n(e,e.firstChild),V.set(e,s=new P(Object.assign({templateFactory:D},i))),s.appendInto(e)),s.setValue(t),s.commit()})(t,c,Object.assign({templateFactory:j(s)},i)),a){const t=V.get(c);V.delete(c);const i=t.value instanceof y?t.value.template:void 0;L(s,c,i),n(e,e.firstChild),e.appendChild(c),V.set(e,t)}!o&&r&&window.ShadyCSS.styleElement(e.host)};var et={},nt=/d{1,4}|M{1,4}|YY(?:YY)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g,it="[^\\s]+",st=/\[([^]*?)\]/gm,ot=function(){};function rt(t,e){for(var n=[],i=0,s=t.length;i3?0:(t-t%10!=10)*t%10]}};var pt={D:function(t){return t.getDate()},DD:function(t){return ct(t.getDate())},Do:function(t,e){return e.DoFn(t.getDate())},d:function(t){return t.getDay()},dd:function(t){return ct(t.getDay())},ddd:function(t,e){return e.dayNamesShort[t.getDay()]},dddd:function(t,e){return e.dayNames[t.getDay()]},M:function(t){return t.getMonth()+1},MM:function(t){return ct(t.getMonth()+1)},MMM:function(t,e){return e.monthNamesShort[t.getMonth()]},MMMM:function(t,e){return e.monthNames[t.getMonth()]},YY:function(t){return ct(String(t.getFullYear()),4).substr(2)},YYYY:function(t){return ct(t.getFullYear(),4)},h:function(t){return t.getHours()%12||12},hh:function(t){return ct(t.getHours()%12||12)},H:function(t){return t.getHours()},HH:function(t){return ct(t.getHours())},m:function(t){return t.getMinutes()},mm:function(t){return ct(t.getMinutes())},s:function(t){return t.getSeconds()},ss:function(t){return ct(t.getSeconds())},S:function(t){return Math.round(t.getMilliseconds()/100)},SS:function(t){return ct(Math.round(t.getMilliseconds()/10),2)},SSS:function(t){return ct(t.getMilliseconds(),3)},a:function(t,e){return t.getHours()<12?e.amPm[0]:e.amPm[1]},A:function(t,e){return t.getHours()<12?e.amPm[0].toUpperCase():e.amPm[1].toUpperCase()},ZZ:function(t){var e=t.getTimezoneOffset();return(e>0?"-":"+")+ct(100*Math.floor(Math.abs(e)/60)+Math.abs(e)%60,4)}},mt={D:["\\d\\d?",function(t,e){t.day=e}],Do:["\\d\\d?"+it,function(t,e){t.day=parseInt(e,10)}],M:["\\d\\d?",function(t,e){t.month=e-1}],YY:["\\d\\d?",function(t,e){var n=+(""+(new Date).getFullYear()).substr(0,2);t.year=""+(e>68?n-1:n)+e}],h:["\\d\\d?",function(t,e){t.hour=e}],m:["\\d\\d?",function(t,e){t.minute=e}],s:["\\d\\d?",function(t,e){t.second=e}],YYYY:["\\d{4}",function(t,e){t.year=e}],S:["\\d",function(t,e){t.millisecond=100*e}],SS:["\\d{2}",function(t,e){t.millisecond=10*e}],SSS:["\\d{3}",function(t,e){t.millisecond=e}],d:["\\d\\d?",ot],ddd:[it,ot],MMM:[it,at("monthNamesShort")],MMMM:[it,at("monthNames")],a:[it,function(t,e,n){var i=e.toLowerCase();i===n.amPm[0]?t.isPm=!1:i===n.amPm[1]&&(t.isPm=!0)}],ZZ:["[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z",function(t,e){var n,i=(e+"").match(/([+-]|\d\d)/gi);i&&(n=60*i[1]+parseInt(i[2],10),t.timezoneOffset="+"===i[0]?n:-n)}]};mt.dd=mt.d,mt.dddd=mt.ddd,mt.DD=mt.D,mt.mm=mt.m,mt.hh=mt.H=mt.HH=mt.h,mt.MM=mt.M,mt.ss=mt.s,mt.A=mt.a,et.masks={default:"ddd MMM DD YYYY HH:mm:ss",shortDate:"M/D/YY",mediumDate:"MMM D, YYYY",longDate:"MMMM D, YYYY",fullDate:"dddd, MMMM D, YYYY",shortTime:"HH:mm",mediumTime:"HH:mm:ss",longTime:"HH:mm:ss.SSS"},et.format=function(t,e,n){var i=n||et.i18n;if("number"==typeof t&&(t=new Date(t)),"[object Date]"!==Object.prototype.toString.call(t)||isNaN(t.getTime()))throw new Error("Invalid Date in fecha.format");e=et.masks[e]||e||et.masks.default;var s=[];return(e=(e=e.replace(st,(function(t,e){return s.push(e),"@@@"}))).replace(nt,(function(e){return e in pt?pt[e](t,i):e.slice(1,e.length-1)}))).replace(/@@@/g,(function(){return s.shift()}))},et.parse=function(t,e,n){var i=n||et.i18n;if("string"!=typeof e)throw new Error("Invalid format in fecha.parse");if(e=et.masks[e]||e,t.length>1e3)return null;var s={},o=[],r=[];e=e.replace(st,(function(t,e){return r.push(e),"@@@"}));var a,c=(a=e,a.replace(/[|\\{()[^$+*?.-]/g,"\\$&")).replace(nt,(function(t){if(mt[t]){var e=mt[t];return o.push(e[1]),"("+e[0]+")"}return t}));c=c.replace(/@@@/g,(function(){return r.shift()}));var l=t.match(new RegExp(c,"i"));if(!l)return null;for(var d=1;d0||navigator.msMaxTouchPoints>0;class bt extends HTMLElement{constructor(){super(),this.holdTime=500,this.ripple=document.createElement("mwc-ripple"),this.timer=void 0,this.held=!1,this.cooldownStart=!1,this.cooldownEnd=!1}connectedCallback(){Object.assign(this.style,{position:"absolute",width:wt?"100px":"50px",height:wt?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach(t=>{document.addEventListener(t,()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0},{passive:!0})})}bind(t,e){if(t.actionHandler)return;t.actionHandler=!0,t.addEventListener("contextmenu",t=>{const e=t||window.event;e.preventDefault&&e.preventDefault(),e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0,e.returnValue=!1});const n=t=>{if(this.cooldownStart)return;let e,n;this.held=!1,t.touches?(e=t.touches[0].pageX,n=t.touches[0].pageY):(e=t.pageX,n=t.pageY),this.timer=window.setTimeout(()=>{this.startAnimation(e,n),this.held=!0},this.holdTime),this.cooldownStart=!0,window.setTimeout(()=>this.cooldownStart=!1,100)},i=n=>{this.cooldownEnd||["touchend","touchcancel"].includes(n.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?gt(t,"action",{action:"hold"}):e.hasDoubleTap?1===n.detail||"keyup"===n.type?this.dblClickTimeout=window.setTimeout(()=>{gt(t,"action",{action:"tap"})},250):(clearTimeout(this.dblClickTimeout),gt(t,"action",{action:"double_tap"})):gt(t,"action",{action:"tap"}),this.cooldownEnd=!0,window.setTimeout(()=>this.cooldownEnd=!1,100))};t.addEventListener("touchstart",n,{passive:!0}),t.addEventListener("touchend",i),t.addEventListener("touchcancel",i),t.addEventListener("keyup",t=>{if(13===t.keyCode)return i(t)}),/iPhone OS 13_/.test(window.navigator.userAgent)||(t.addEventListener("mousedown",n,{passive:!0}),t.addEventListener("click",i))}startAnimation(t,e){Object.assign(this.style,{left:t+"px",top:e+"px",display:null}),this.ripple.disabled=!1,this.ripple.active=!0,this.ripple.unbounded=!0}stopAnimation(){this.ripple.active=!1,this.ripple.disabled=!0,this.style.display="none"}}customElements.define("action-handler-button-text-card",bt);const St=(t,e)=>{const n=(()=>{const t=document.body;if(t.querySelector("action-handler-button-text-card"))return t.querySelector("action-handler-button-text-card");const e=document.createElement("action-handler-button-text-card");return t.appendChild(e),e})();n&&n.bind(t,e)},xt=(t=>(...e)=>{const n=t(...e);return m.set(n,!0),n})((t={})=>e=>{St(e.committer.element,t)});var Ct;console.info("%c BUTTON-TEXT-CARD \n%c v0.5.7 ","color: orange; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray");let Pt=Ct=class extends tt{constructor(){super(...arguments),this._hasTemplate=!1}setConfig(t){if(!t||t.show_error)throw new Error("Invalid configuration.");this._config=Object.assign({name:"Button Text Card",title:"",subtitle:"",large:!1},t),this._renderedConfig=Object.assign({},this._config);for(const t of Ct.templateFields){const e=Ct.templateRegex.exec(this._config[t]);if(Ct.templateRegex.lastIndex=0,null!==e){this._hasTemplate=!0;break}}}shouldUpdate(t){var e;return!(null===(e=this._config)||void 0===e?void 0:e.entity)||function(t,e,n){if(e.has("config")||n)return!0;if(t._config.entity){var i=e.get("hass");return!i||i.states[t._config.entity]!==t.hass.states[t._config.entity]}return!1}(this,t,this._hasTemplate)}evaluateJsTemplates(){if(this._renderedConfig&&this._config)for(const t of Ct.templateFields){const e=Ct.templateRegex.exec(this._config[t]);Ct.templateRegex.lastIndex=0,e&&e.length>1?this._renderedConfig[t]=this._evalTemplate(this._stateObj,e[1]):this._renderedConfig[t]=this._config[t]}}render(){if(!this._config||!this.hass||!this._renderedConfig)return Y``;if(this._stateObj=this._config.entity?this.hass.states[this._config.entity]:void 0,this.evaluateJsTemplates(),!this._inEditMode()&&!0===this._renderedConfig.hide_condition)return Y``;if(!this._config.icon||""===this._config.icon){let t="mdi:alert-circle";if(this._config.entity){const e=this.hass.states[this._config.entity].attributes.icon;e&&(t=e)}this.setConfig(Object.assign(Object.assign({},this._config),{icon:t}))}return this._renderedConfig.background_color&&this.style.setProperty("--ha-card-background",this._renderedConfig.background_color),this._renderedConfig.font_color&&this.style.setProperty("--primary-text-color",this._renderedConfig.font_color),this._renderedConfig.icon_size&&this.style.setProperty("--mdc-icon-size",this._renderedConfig.icon_size+"px"),this._configureIconColor(),Y` - `}_handleAction(t){this.hass&&this._config&&t.detail.action&&yt(this,this.hass,this._config,t.detail.action)}_configureIconColor(){var t,e,n,i,s;(null===(t=this._renderedConfig)||void 0===t?void 0:t.icon_color)&&"auto"!==this._renderedConfig.icon_color?this.style.setProperty("--icon-color",this._renderedConfig.icon_color):"auto"!==(null===(e=this._renderedConfig)||void 0===e?void 0:e.icon_color)||"on"!==(null===(n=this._stateObj)||void 0===n?void 0:n.state)?(null===(i=this._renderedConfig)||void 0===i?void 0:i.icon_color)||!(null===(s=this._renderedConfig)||void 0===s?void 0:s.font_color)?this.style.setProperty("--icon-color","var(--primary-text-color)"):this.style.setProperty("--icon-color",this._renderedConfig.font_color):this.style.setProperty("--icon-color","var(--paper-item-icon-active-color)")}_inEditMode(){var t,e,n,i,s,o,r,a;const c=null===(a=null===(r=null===(o=null===(s=null===(i=null===(n=null===(e=null===(t=document.querySelector("home-assistant"))||void 0===t?void 0:t.shadowRoot)||void 0===e?void 0:e.querySelector("home-assistant-main"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.querySelector("app-drawer-layout partial-panel-resolver ha-panel-lovelace"))||void 0===s?void 0:s.shadowRoot)||void 0===o?void 0:o.querySelector("hui-root"))||void 0===r?void 0:r.shadowRoot)||void 0===a?void 0:a.querySelector("ha-app-layout app-header");return!!c&&c.classList.contains("edit-mode")}_evalTemplate(t,e){return this.hass?new Function("states","entity","user","hass","variables","'use strict'; "+e).call(this,this.hass.states,t,this.hass.user,this.hass,[]):""}static get styles(){return K` + `}_handleAction(t){this.hass&&this._config&&t.detail.action&&yt(this,this.hass,this._config,t.detail.action)}_configureIconColor(){var t,e,n,i,s;(null===(t=this._renderedConfig)||void 0===t?void 0:t.icon_color)&&"auto"!==this._renderedConfig.icon_color?this.style.setProperty("--icon-color",this._renderedConfig.icon_color):"auto"!==(null===(e=this._renderedConfig)||void 0===e?void 0:e.icon_color)||"on"!==(null===(n=this._stateObj)||void 0===n?void 0:n.state)?(null===(i=this._renderedConfig)||void 0===i?void 0:i.icon_color)||!(null===(s=this._renderedConfig)||void 0===s?void 0:s.font_color)?this.style.setProperty("--icon-color","var(--primary-text-color)"):this.style.setProperty("--icon-color",this._renderedConfig.font_color):this.style.setProperty("--icon-color","var(--paper-item-icon-active-color)")}_inEditMode(){var t,e,n,i,s,o,r,a;const c=null===(a=null===(r=null===(o=null===(s=null===(i=null===(n=null===(e=null===(t=document.querySelector("home-assistant"))||void 0===t?void 0:t.shadowRoot)||void 0===e?void 0:e.querySelector("home-assistant-main"))||void 0===n?void 0:n.shadowRoot)||void 0===i?void 0:i.querySelector("app-drawer-layout partial-panel-resolver ha-panel-lovelace"))||void 0===s?void 0:s.shadowRoot)||void 0===o?void 0:o.querySelector("hui-root"))||void 0===r?void 0:r.shadowRoot)||void 0===a?void 0:a.querySelector("ha-app-layout app-header app-toolbar");return!!c&&c.classList.contains("edit-mode")}_evalTemplate(t,e){return this.hass?new Function("states","entity","user","hass","variables","'use strict'; "+e).call(this,this.hass.states,t,this.hass.user,this.hass,[]):""}static get styles(){return K` @-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); diff --git a/package.json b/package.json index 3438eb9..f280b3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "button-text-card", - "version": "0.5.6", + "version": "0.5.7", "description": "Button Text Card", "keywords": [ "home-assistant", diff --git a/src/button-text-card.ts b/src/button-text-card.ts index 7a7c06e..f058f56 100644 --- a/src/button-text-card.ts +++ b/src/button-text-card.ts @@ -230,7 +230,7 @@ export class BoilerplateCard extends LitElement { ?.shadowRoot?.querySelector('home-assistant-main') ?.shadowRoot?.querySelector('app-drawer-layout partial-panel-resolver ha-panel-lovelace') ?.shadowRoot?.querySelector('hui-root') - ?.shadowRoot?.querySelector('ha-app-layout app-header'); + ?.shadowRoot?.querySelector('ha-app-layout app-header app-toolbar'); if (el) { return el.classList.contains('edit-mode'); diff --git a/src/const.ts b/src/const.ts index 599f320..b2ae2da 100644 --- a/src/const.ts +++ b/src/const.ts @@ -1 +1 @@ -export const CARD_VERSION = '0.5.6'; +export const CARD_VERSION = '0.5.7';