From e2967359426d334dac1fddf2434006b278b526fd Mon Sep 17 00:00:00 2001 From: Cloos <36499953+Clooos@users.noreply.github.com> Date: Tue, 10 Oct 2023 14:32:09 +0200 Subject: [PATCH] v1.1.0 --- bubble-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bubble-card.js b/bubble-card.js index 8c56fb1..17484bc 100644 --- a/bubble-card.js +++ b/bubble-card.js @@ -1 +1 @@ -var version="v1.0.3";let editor;class BubbleCard extends HTMLElement{constructor(){if(super(),!window.eventAdded){const t=history.pushState;window.popUpIntialized=!1,history.pushState=function(){t.apply(history,arguments),window.dispatchEvent(new Event("pushstate"))};const e=history.replaceState;history.replaceState=function(){e.apply(history,arguments),window.dispatchEvent(new Event("replacestate"))},["pushstate","replacestate","click","popstate","mousedown","touchstart"].forEach((t=>{window.addEventListener(t,i)}));const n=new Event("urlChanged");function i(){const t=window.location.href;t!==this.currentUrl&&(window.dispatchEvent(n),this.currentUrl=t)}const o=()=>{window.dispatchEvent(n),window.addEventListener("popstate",i),console.log(n),setTimeout((()=>{window.removeEventListener("popUpInitialized",o)}),1e3)};window.addEventListener("popUpInitialized",o),window.eventAdded=!0}}set hass(hass){function toggleEntity(t){hass.callService("homeassistant","toggle",{entity_id:t})}this.content||(this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML='\n \n
\n
\n
\n ',this.card=this.shadowRoot.querySelector("ha-card"),this.content=this.shadowRoot.querySelector("div"),this.editorElement=document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("ha-drawer > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("div")),editor=this.editorElement.classList.contains("edit-mode");const addStyles=function(context,styles,customStyles,state,entityId,path="",element=context.content){const customStylesEval=customStyles?eval("`"+customStyles+"`"):"";let styleAddedKey=styles+"Added";if(!context[styleAddedKey]||context.previousStyle!==customStylesEval){if(!context[styleAddedKey]){if(context.styleElement=context.content.querySelector("style"),!context.styleElement){context.styleElement=document.createElement("style");const t=path?context.content.querySelector(path):element;t.appendChild(context.styleElement)}context[styleAddedKey]=!0}context.styleElement.innerHTML=customStylesEval+styles,context.previousStyle=customStylesEval}},forwardHaptic=t=>{fireEvent(window,"haptic",t)},navigate=(t,e,n=!1)=>{n?history.replaceState(null,"",e):history.pushState(null,"",e),fireEvent(window,"location-changed",{replace:n})},handleActionConfig=(t,e,n,i)=>{if(!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some((t=>t.user===e.user.id))||(forwardHaptic("warning"),confirm(i.confirmation.text||`Are you sure you want to ${i.action}?`)))switch(i.action){case"more-info":(this.config.entity||this.config.camera_image)&&fireEvent(t,"hass-more-info",{entityId:this.config.entity?this.config.entity:this.config.camera_image});break;case"navigate":i.navigation_path&&navigate(t,i.navigation_path);break;case"url":i.url_path&&window.open(i.url_path);break;case"toggle":this.config.entity&&(toggleEntity(this.config.entity),forwardHaptic("success"));break;case"call-service":{if(!i.service)return void forwardHaptic("failure");const[t,n]=i.service.split(".",2);e.callService(t,n,i.service_data,i.target),forwardHaptic("success");break}case"fire-dom-event":fireEvent(t,"ll-custom",i)}},handleAction=(t,e,n,i)=>{let o;"double_tap"===i&&this.config.double_tap_action?o=this.config.double_tap_action:"hold"===i&&this.config.hold_action?o=this.config.hold_action:"tap"===i&&this.config.tap_action?o=this.config.tap_action:"double_tap"!==i||this.config.double_tap_action?("hold"!==i||this.config.hold_action)&&("tap"!==i||this.config.tap_action)||(o={action:"more-info"}):o={action:"toggle"},handleActionConfig(t,e,n,o)},addAction=function(){let t,e;return function(n,i,o,a){o.addEventListener(n,(()=>{const i=(new Date).getTime();"click"===n?i-(e||0)<250?(clearTimeout(t),handleAction(a,hass,{},"double_tap")):t=setTimeout((()=>{handleAction(a,hass,{},"tap")}),250):handleAction(a,hass,{},"hold"),e=i}))}}();function addActions(t,e){addAction("click","tap",e,t),addAction("contextmenu","hold",e,t)}let customStyles=this.config.styles?this.config.styles:"",entityId=this.config.entity?this.config.entity:"",icon=!this.config.icon&&this.config.entity?hass.states[entityId].attributes.icon||hass.states[entityId].attributes.entity_picture||"":this.config.icon||"",name=this.config.name?this.config.name:this.config.entity?hass.states[entityId].attributes.friendly_name:"",widthDesktop=this.config.width_desktop||"540px",widthDesktopDivided=widthDesktop?widthDesktop.match(/(\d+)(\D+)/):"",isSidebarHidden=this.config.is_sidebar_hidden||!1,state=entityId?hass.states[entityId].state:"",formatedState,autoClose=this.config.auto_close||!1,marginCenter=this.config.margin?"0"!==this.config.margin?this.config.margin:"0px":"7px",backOpen=this.config.back_open,popUpOpen;switch(this.config.card_type){case"pop-up":if(this.getRootNode().host){const U=this.config.hash;if(!this.popUp&&(this.card.style.marginTop="0",this.verticalStack=this.getRootNode(),this.popUp=this.verticalStack.querySelector("#root"),!window.popUpIntialized)){if(backOpen){window.backOpen=!0;const ot=new Event("popUpInitialized");setTimeout((()=>{window.dispatchEvent(ot)}),10)}else window.backOpen=!1,popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),console.log("Delete hash");window.popUpIntialized=!0}const F=this.popUp,j=this.config.text||"",R=this.config.trigger_entity?this.config.trigger_entity:"",X=this.config.trigger_state?this.config.trigger_state:"",P=!!this.config.trigger_close&&this.config.trigger_close;formatedState=this.config.state?hass.formatEntityState(hass.states[this.config.state])+" "+j:j;const W=this.config.margin_top_mobile&&"0"!==this.config.margin_top_mobile?this.config.margin_top_mobile:"0px",N=this.config.margin_top_desktop&&"0"!==this.config.margin_top_desktop?this.config.margin_top_desktop:"0px",G=this.config.entity?"flex":"none";let K;if(state=this.config.state?hass.states[this.config.state].state:"",this.headerAdded){if(this.headerAdded){const at=this.content.querySelector("#header-container .header-icon");if(at.innerHTML="",hass&&hass.states&&hass.states[entityId]&&hass.states[entityId].attributes.entity_picture&&!this.config.icon){const ct=document.createElement("img");ct.setAttribute("src",hass.states[entityId].attributes.entity_picture),ct.setAttribute("class","entity-picture"),ct.setAttribute("alt","Icon"),at.appendChild(ct)}else{const dt=document.createElement("ha-icon");dt.setAttribute("icon",icon),dt.setAttribute("class","icon"),at.appendChild(dt)}const st=this.content.querySelector("#header-container h2");st.textContent=name;const rt=this.content.querySelector("#header-container p");rt.textContent=formatedState;const lt=this.content.querySelector("#header-container .power-button");lt.setAttribute("style",`display: ${G};`)}}else{const ht=document.createElement("div");ht.setAttribute("id","header-container");const pt=document.createElement("div");ht.appendChild(pt);const ut=document.createElement("div");if(ut.setAttribute("class","header-icon"),pt.appendChild(ut),hass&&hass.states&&hass.states[entityId]&&hass.states[entityId].attributes.entity_picture&&!this.config.icon){const vt=document.createElement("img");vt.setAttribute("src",hass.states[entityId].attributes.entity_picture),vt.setAttribute("class","entity-picture"),vt.setAttribute("alt","Icon"),ut.appendChild(vt)}else{const _t=document.createElement("ha-icon");_t.setAttribute("icon",icon),_t.setAttribute("class","icon"),ut.appendChild(_t)}addActions(this,ut);const gt=document.createElement("h2");gt.textContent=name,pt.appendChild(gt);const mt=document.createElement("p");mt.textContent=formatedState,pt.appendChild(mt);const ft=document.createElement("ha-icon");ft.setAttribute("class","power-button"),ft.setAttribute("icon","mdi:power"),ft.setAttribute("style",`display: ${G};`),pt.appendChild(ft);const bt=document.createElement("button");bt.setAttribute("class","close-pop-up"),bt.onclick=function(){history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0)},ht.appendChild(bt);const yt=document.createElement("ha-icon");yt.setAttribute("icon","mdi:close"),bt.appendChild(yt),this.content.appendChild(ht),this.header=pt,this.headerAdded=!0}if(!this.eventAdded){window["checkHashRef_"+U]=Z,window.addEventListener("urlChanged",window["checkHashRef_"+U]),this.content.querySelector(".power-button").addEventListener("click",(()=>{toggleEntity(entityId)}));let wt=location.hash,xt,kt;window.addEventListener("click",(function(t){location.hash===U&&tt(),location.hash===wt?location.hash!==U||t.composedPath().some((t=>"HA-MORE-INFO-DIALOG"===t.nodeName))||t.composedPath().some((t=>"root"===t.id&&!t.classList.contains("close-pop-up")))||(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0)):wt=location.hash})),window.addEventListener("keydown",(function(t){"Escape"===t.key&&(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0))})),F.addEventListener("touchstart",(function(t){location.hash===U&&tt(),xt=t.touches[0].clientY,kt=xt})),F.addEventListener("touchmove",(function(t){t.touches[0].clientY-xt>300&&t.touches[0].clientY>kt&&(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=U+!1,localStorage.setItem("isManuallyClosed_"+U,!0)),kt=t.touches[0].clientY})),this.eventAdded=!0}if(R){null===localStorage.getItem("previousTriggerState_"+U)&&localStorage.setItem("previousTriggerState_"+U,""),null===localStorage.getItem("isManuallyClosed_"+U)&&localStorage.setItem("isManuallyClosed_"+U,"false"),null===localStorage.getItem("isTriggered_"+U)&&localStorage.setItem("isTriggered_"+U,"false");let $t=localStorage.getItem("previousTriggerState_"+U),Ct="true"===localStorage.getItem("isManuallyClosed_"+U),St="true"===localStorage.getItem("isTriggered_"+U);hass.states[R].state!==X||null!==$t||St||(navigate("",U),St=!0,localStorage.setItem("isTriggered_"+U,St)),hass.states[R].state!==$t&&(Ct=!1,localStorage.setItem("previousTriggerState_"+U,hass.states[R].state),localStorage.setItem("isManuallyClosed_"+U,Ct)),hass.states[R].state!==X||Ct?hass.states[R].state!==X&&P&&F.classList.contains("open-pop-up")&&St&&!Ct&&(history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=U+!1,St=!1,Ct=!0,localStorage.setItem("isManuallyClosed_"+U,Ct),localStorage.setItem("isTriggered_"+U,St)):(navigate("",U),St=!0,localStorage.setItem("isTriggered_"+U,St))}if(""!==entityId){const Et=hass.states[entityId].attributes.rgb_color,It=Et?`rgba(${Et[0]}, ${Et[1]}, ${Et[2]}, 0.5)`:"off"!==hass.states[entityId].state?"var(--accent-color)":"var(--background-color,var(--secondary-background-color))";this.header.style.backgroundColor=It}function Z(){if(!editor){location.hash.split("?")[0]===U?J():F.classList.contains("open-pop-up")&&Q()}}function J(){F.classList.remove("close-pop-up"),F.classList.add("open-pop-up"),popUpOpen=U+!0,tt()}function Q(){F.classList.remove("open-pop-up"),F.classList.add("close-pop-up"),popUpOpen=U+!1,clearTimeout(K)}function tt(){clearTimeout(K),autoClose>0&&(K=setTimeout(et,autoClose))}function et(){history.replaceState(null,null,location.href.split("#")[0])}const nt=`\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n border: none !important;\n }\n .card-content {\n width: 100% !important;\n padding: 0 !important;\n }\n #root {\n position: fixed !important;\n margin: 0 -${marginCenter}; /* 7px */\n width: 100%;\n background-color: var(--ha-card-background,var(--card-background-color));\n border-radius: 42px;\n box-sizing: border-box;\n top: calc(100% + ${W} + var(--header-height));\n grid-gap: 12px !important;\n gap: 12px !important;\n grid-auto-rows: min-content;\n padding: 18px 18px 220px 18px !important;\n height: 100% !important;\n -ms-overflow-style: none; /* for Internet Explorer, Edge */\n scrollbar-width: none; /* for Firefox */\n overflow-y: auto; \n overflow-x: hidden; \n z-index: 1 !important; /* Higher value hide the more-info panel */\n /* For older Safari but not working with Firefox */\n /* display: grid !important; */ \n }\n #root > bubble-card:first-child::after {\n content: '';\n display: block;\n position: sticky;\n top: 0;\n left: -50px;\n margin: -70px 0 -35px 0;\n width: 200%;\n height: 100px;\n background: linear-gradient(0deg, rgba(79, 69, 87, 0) 0%, var(--ha-card-background,var(--card-background-color)) 80%);\n z-index: 0;\n }\n #root::-webkit-scrollbar {\n display: none; /* for Chrome, Safari, and Opera */\n }\n #root > bubble-card:first-child {\n position: sticky;\n top: 0;\n z-index: 1;\n background: none !important;\n }\n #root.open-pop-up {\n transform: translateY(-100%);\n transition: transform .4s !important;\n }\n #root.open-pop-up > * {\n /* Block child items to overflow and if they do clip them */\n /*max-width: calc(100vw - 38px);*/\n max-width: 100% !important;\n overflow-x: clip;\n }\n #root.close-pop-up { \n transform: translateY(0%);\n transition: transform .4s !important;\n /* animation: hide 1s forwards; */\n }\n @media only screen and (min-width: 768px) {\n #root {\n top: calc(100% + ${N} + var(--header-height));\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]});\n margin: 0 !important;\n }\n } \n @media only screen and (min-width: 870px) {\n #root {\n top: calc(100% + ${N} + var(--header-height));\n width: calc(${widthDesktop}${"%"!==widthDesktopDivided[2]||isSidebarHidden?"":" - var(--mdc-drawer-width)"}) !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]} + ${isSidebarHidden?"0px":"var(--mdc-drawer-width) "+("%"===widthDesktopDivided[2]?"":"/ 2")});\n margin: 0 !important;\n }\n } \n #root.editor {\n position: inherit !important;\n width: 100% !important;\n padding: 18px !important;\n }\n `,it=`\n #header-container {\n display: inline-flex;\n ${icon||name||entityId||state||j?"":"flex-direction: row-reverse;"}\n width: 100%;\n margin: 0;\n padding: 0;\n }\n #header-container > div {\n display: ${icon||name||entityId||state||j?"inline-flex":"none"};\n align-items: center;\n position: relative;\n padding: 6px;\n z-index: 1;\n flex-grow: 1;\n background-color: var(--background-color,var(--secondary-background-color));\n transition: background 1s;\n border-radius: 25px;\n margin-right: 14px;\n }\n .header-icon {\n display: inline-flex;\n width: 22px;\n height: 22px;\n padding: 8px;\n background-color: var(--card-background-color,var(--ha-card-background));\n border-radius: 100%;\n margin: 0 10px 0 0;\n cursor: ${this.config.entity||this.config.double_tap_action||this.config.tap_action||this.config.hold_action?"pointer":"default"}; \n flex-wrap: wrap;\n align-content: center;\n justify-content: center;\n overflow: hidden;\n }\n .entity-picture {\n height: calc(100% + 16px);\n width: calc(100% + 16px);\n }\n #header-container h2 {\n display: inline-flex;\n margin: 0 18px 0 0;\n /*line-height: 0px;*/\n z-index: 1;\n font-size: 20px;\n }\n #header-container p {\n display: inline-flex;\n line-height: 0px;\n font-size: 16px;\n }\n .power-button {\n cursor: pointer; \n flex-grow: inherit; \n width: 24px;\n height: 24px;\n border-radius: 12px;\n margin: 0 10px;\n background: none !important;\n justify-content: flex-end;\n background-color: var(--background-color,var(--secondary-background-color));\n }\n .close-pop-up {\n height: 50px;\n width: 50px;\n border: none;\n border-radius: 50%;\n z-index: 1;\n background: var(--background-color,var(--secondary-background-color));\n color: var(--primary-text-color);\n flex-shrink: 0;\n cursor: pointer;\n }\n `;addStyles(this,nt,customStyles,state,entityId,"",F),addStyles(this,it,customStyles,state,entityId),!0===editor?(F.classList.add("editor"),F.classList.remove("open-pop-up"),F.classList.remove("close-pop-up")):F.classList.remove("editor")}else!0!==editor&&(this.card.style.marginTop="2000px");break;case"horizontal-buttons-stack":const t=(t,e,n)=>{const i=document.createElement("button");return i.setAttribute("class",`button ${e.substring(1)}`),i.innerHTML=`\n ${""!==n?``:""}\n ${""!==t?`

${t}

`:""}\n `,i.addEventListener("click",(t=>{t.stopPropagation(),popUpOpen=location.hash+!0;localStorage.getItem("isManuallyClosed_"+e);popUpOpen!==e+!0?(navigate("",e),popUpOpen=e+!0):(history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=e+!1)})),i};if(!this.buttonsAdded){const At=document.createElement("div");At.setAttribute("class","horizontal-buttons-stack-container"),this.content.appendChild(At),this.buttonsContainer=At}const e=(t,e)=>{if(hass.states[e].attributes.rgb_color){const n=hass.states[e].attributes.rgb_color,i=`rgba(${n[0]}, ${n[1]}, ${n[2]}, 0.5)`;t.style.backgroundColor=i,t.style.border="1px solid rgba(0,0,0,0)"}else hass.states[e].attributes.rgb_color||"on"!=hass.states[e].state?(t.style.backgroundColor="rgba(0,0,0,0)",t.style.border="1px solid var(--primary-text-color)"):(t.style.backgroundColor="rgba(255,255,255,0.5)",t.style.border="1px solid rgba(0,0,0,0)")};let n=[],i=1;for(;this.config[i+"_link"];){const Lt=i+"_",Ot=this.config[Lt+"name"]||"",Dt=this.config[Lt+"pir_sensor"];icon=this.config[Lt+"icon"]||"";const Tt=this.config[Lt+"link"],zt=this.config[Lt+"entity"];n.push({button:Ot,pirSensor:Dt,icon:icon,link:Tt,lightEntity:zt}),i++}if(this.config.auto_order&&n.sort(((t,e)=>{if(t.pirSensor&&e.pirSensor){if("on"===hass.states[t.pirSensor].state&&"on"===hass.states[e.pirSensor].state){return hass.states[t.pirSensor].last_updated{const n=t(e.button,e.link,e.icon);Vt[e.link]=n,this.buttonsContainer.appendChild(n)})),this.buttonsAdded=!0,this.buttons=Vt}editor?localStorage.setItem("justExitedEditor",!1):"false"===localStorage.getItem("justExitedEditor")&&localStorage.setItem("justExitedEditor",!0);let o=0,a=12;const s="true"===localStorage.getItem("editorMode")&&!editor;n.forEach(((t,n)=>{let i=this.buttons[t.link];if(i){let e=localStorage.getItem(`buttonWidth-${t.link}`),n=localStorage.getItem(`buttonContent-${t.link}`);(!e||"0"===e||n!==i.innerHTML||editor||s)&&(e=i.offsetWidth,localStorage.setItem(`buttonWidth-${t.link}`,e),localStorage.setItem(`buttonContent-${t.link}`,i.innerHTML),editor?a=36:s&&(a=12)),i.style.transform=`translateX(${o}px)`,o+=parseInt(e)+a}t.lightEntity&&e(i,t.lightEntity)}));const r=`\n ha-card {\n border-radius: 0;\n }\n .horizontal-buttons-stack {\n width: 100%;\n margin-top: 0 !important;\n background: none !important;\n position: fixed;\n height: 51px;\n bottom: 16px;\n left: ${marginCenter};\n /* transform: translateY(200px); */\n /* animation: from-bottom 1.3s forwards; */\n z-index: 1 !important; /* Higher value hide the more-info panel */\n }\n @keyframes from-bottom {\n 0% {transform: translateY(200px);}\n 20% {transform: translateY(200px);}\n 46% {transform: translateY(-8px);}\n 56% {transform: translateY(1px);}\n 62% {transform: translateY(-2px);}\n 70% {transform: translateY(0);}\n 100% {transform: translateY(0);}\n }\n .horizontal-buttons-stack-container {\n width: max-content;\n position: relative;\n height: 51px;\n }\n .button {\n display: flex;\n position: absolute;\n box-sizing: border-box !important;\n border: 1px solid var(--primary-text-color);\n align-items: center;\n height: 50px;\n white-space: nowrap;\n width: auto;\n border-radius: 25px;\n z-index: 1;\n padding: 16px;\n background: none;\n transition: background-color 1s, border 1s, transform 1s;\n color: var(--primary-text-color);\n }\n .icon {\n height: 24px;\n }\n .card-content {\n width: calc(100% + 18px);\n box-sizing: border-box !important;\n margin: 0 -36px !important;\n padding: 0 36px !important;\n overflow: scroll !important;\n -ms-overflow-style: none;\n scrollbar-width: none;\n -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 1) calc(0% + 28px), rgba(0, 0, 0, 1) calc(100% - 28px), transparent 100%);\n /* mask-image: linear-gradient(90deg, transparent 2%, rgba(0, 0, 0, 1) 6%, rgba(0, 0, 0, 1) 96%, transparent 100%); */\n /* -webkit-mask-image: linear-gradient(90deg, transparent 2%, rgba(0, 0, 0, 1) 6%, rgba(0, 0, 0, 1) 96%, transparent 100%); */\n }\n .horizontal-buttons-stack::before {\n content: '';\n position: absolute;\n top: -32px;\n left: -100%;\n display: block;\n background: linear-gradient(0deg, var(--background-color, var(--primary-background-color)) 50%, rgba(79, 69, 87, 0));\n width: 200%;\n height: 100px;\n }\n .card-content::-webkit-scrollbar {\n display: none;\n }\n @media only screen and (min-width: 768px) {\n .card-content {\n position: fixed;\n width: ${widthDesktop} !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]});\n margin-left: -13px !important;\n padding: 0 26px !important;\n }\n }\n @media only screen and (min-width: 870px) {\n .card-content {\n position: fixed;\n width: calc(${widthDesktop}${"%"!==widthDesktopDivided[2]||isSidebarHidden?"":" - var(--mdc-drawer-width)"}) !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]} + ${!0===isSidebarHidden?"0px":"var(--mdc-drawer-width) "+("%"===widthDesktopDivided[2]?"":"/ 2")});\n margin-left: -13px !important;\n padding: 0 26px !important;\n }\n }\n \n .horizontal-buttons-stack.editor {\n position: relative;\n bottom: 0;\n left: 0;\n overflow: hidden;\n }\n \n .horizontal-buttons-stack.editor::before {\n top: -32px;\n left: -100%;\n background: none;\n width: 100%;\n height: 0;\n }\n \n .horizontal-buttons-stack-container.editor > .button {\n transition: background-color 0s, border 0s, transform 0s;\n }\n \n .horizontal-buttons-stack-container.editor {\n margin-left: 1px;\n }\n \n .horizontal-buttons-stack.editor > .card-content {\n position: relative;\n width: calc(100% + 26px) !important;\n left: -26px;\n margin: 0 !important;\n padding: 0;\n }\n `;addStyles(this,r,customStyles),editor?(this.buttonsContainer.classList.add("editor"),this.card.classList.add("editor")):(this.buttonsContainer.classList.remove("editor"),this.card.classList.remove("editor"));break;case"button":if(!this.buttonAdded){const Mt=document.createElement("div");Mt.setAttribute("class","button-container"),this.content.appendChild(Mt)}const l=this.config.button_type||"switch";formatedState=hass.formatEntityState(hass.states[entityId]);const c=!!this.config.show_state&&this.config.show_state;let d=entityId?hass.states[entityId].attributes.brightness||0:"",h=entityId?hass.states[entityId].attributes.volume_level||0:"",p=!1,u=d,g=h,m=0,f=0,b=0,y=!1,v=null;const _=document.createElement("div");_.setAttribute("class","icon-container"),this.iconContainer=_;const w=document.createElement("div");w.setAttribute("class","name-container");const x=document.createElement("div");x.setAttribute("class","switch-button");const k=document.createElement("div");k.setAttribute("class","range-slider");const $=document.createElement("div");if($.setAttribute("class","range-fill"),entityId&&entityId.startsWith("light.")&&"slider"===l?$.style.transform=`translateX(${d/255*100}%)`:entityId&&entityId.startsWith("media_player.")&&"slider"===l&&($.style.transform=`translateX(${100*h}%)`),!this.buttonContainer||editor){if(editor&&this.buttonContainer){for(;this.buttonContainer.firstChild;)this.buttonContainer.removeChild(this.buttonContainer.firstChild);this.eventAdded=!1}this.buttonContainer=this.content.querySelector(".button-container"),"slider"!==l||this.buttonAdded&&!editor?("switch"===l||"custom"===l||editor)&&(this.buttonContainer.appendChild(x),x.appendChild(_),x.appendChild(w),this.switchButton=this.content.querySelector(".switch-button")):(this.buttonContainer.appendChild(k),k.appendChild(_),k.appendChild(w),k.appendChild($),this.rangeFill=this.content.querySelector(".range-fill")),!hass.states[entityId].attributes.entity_picture&&!icon.startsWith("/api/image/")||this.config.icon?_.innerHTML=``:_.innerHTML=`Icon`,w.innerHTML=`\n

${name}

\n ${c?`

${formatedState}

`:""}\n `,this.buttonAdded=!0}function C(t){let e=t.querySelector(".feedback-element");e||(e=document.createElement("div"),e.setAttribute("class","feedback-element"),t.appendChild(e)),e.style.animation="tap-feedback .5s",setTimeout((()=>{e.style.animation="none",t.removeChild(e)}),500)}function S(t){m=t.pageX||(t.touches?t.touches[0].pageX:0),f=t.pageY||(t.touches?t.touches[0].pageY:0),b=k.value,t.target!==_.querySelector("ha-icon")&&(p=!0,document.addEventListener("mouseup",I),document.addEventListener("touchend",I),document.addEventListener("mousemove",E),document.addEventListener("touchmove",E),v=setTimeout((()=>{D(t.pageX||t.touches[0].pageX),A(),v=null}),200))}function E(t){const e=t.pageX||(t.touches?t.touches[0].pageX:0),n=t.pageY||(t.touches?t.touches[0].pageY:0);Math.abs(n-f)>Math.abs(e-m)?(clearTimeout(v),I()):(document.removeEventListener("mousemove",E),document.removeEventListener("touchmove",E),document.addEventListener("mousemove",L),document.addEventListener("touchmove",L))}function I(){p=!1,y=!1,A(),document.removeEventListener("mouseup",I),document.removeEventListener("touchend",I),document.removeEventListener("mousemove",L),document.removeEventListener("touchmove",L)}function A(){entityId.startsWith("light.")?(d=u,hass.callService("light","turn_on",{entity_id:entityId,brightness:d})):h!==g&&entityId.startsWith("media_player.")&&(h=g,hass.callService("media_player","volume_set",{entity_id:entityId,volume_level:h}))}function L(t){const e=t.pageX||(t.touches?t.touches[0].pageX:0),n=t.pageY||(t.touches?t.touches[0].pageY:0);p&&Math.abs(e-m)>10?D(e):p&&Math.abs(n-f)>10&&(p=!1,k.value=b)}function O(t,e){if(e.buttonContainer.style.opacity="unavailable"!==t?"1":"0.5",["switch","custom"].includes(l)){const n=["on","open","cleaning","true","home","playing"].includes(t)?"var(--accent-color)":"rgba(0,0,0,0)";e.switchButton.style.backgroundColor=n}}function D(t){const e=k.getBoundingClientRect(),n=Math.min(Math.max(t-e.left,0),e.width)/e.width;entityId.startsWith("light.")?u=Math.round(255*n):entityId.startsWith("media_player.")&&(g=n),$.style.transition="none",$.style.transform=`translateX(${100*n}%)`}if(c&&(this.content.querySelector(".state").textContent=formatedState),this.eventAdded||"switch"!==l?this.eventAdded||"slider"!==l?this.eventAdded||"custom"!==l||(x.addEventListener("click",(()=>C(this.switchButton))),addActions(this,this.switchButton),this.eventAdded=!0):(k.addEventListener("mousedown",S),k.addEventListener("touchstart",S),addActions(this,this.iconContainer),this.eventAdded=!0):(x.addEventListener("click",(()=>C(this.switchButton))),x.addEventListener("click",(function(t){t.target.closest("ha-icon")||toggleEntity(entityId)})),addActions(this,this.iconContainer),this.eventAdded=!0),this.isDragging||"slider"!==l||(this.rangeFill.style.transition="all .2s",entityId.startsWith("light.")?this.rangeFill.style.transform=`translateX(${d/255*100}%)`:entityId.startsWith("media_player.")&&(this.rangeFill.style.transform=`translateX(${100*h}%)`)),O(state,this),"slider"===l)if(entityId.startsWith("light.")){const Ht=hass.states[entityId].attributes.rgb_color,Bt=Ht?`rgba(${Ht[0]}, ${Ht[1]}, ${Ht[2]}, 0.5)`:"rgba(255, 255, 255, 0.5)";this.rangeFill.style.backgroundColor=Bt}else this.rangeFill.style.backgroundColor="var(--accent-color)";const T=`\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n }\n \n .button-container {\n position: relative;\n width: 100%;\n height: 50px;\n z-index: 0;\n background-color: var(--background-color-2,var(--secondary-background-color));\n border-radius: 25px;\n mask-image: radial-gradient(white, black);\n -webkit-mask-image: radial-gradient(white, black);\n -webkit-backface-visibility: hidden;\n -moz-backface-visibility: hidden;\n -webkit-transform: translateZ(0);\n overflow: hidden;\n }\n \n .switch-button,\n .range-slider {\n display: inline-flex;\n position: absolute;\n height: 100%;\n width: 100%;\n transition: background-color 1.5s;\n }\n \n .range-fill {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n }\n \n .switch-button {\n cursor: pointer !important;\n }\n \n .range-slider {\n cursor: ew-resize;\n }\n \n .range-fill {\n z-index: 0;\n width: 100%;\n left: -100%;\n }\n \n .icon-container {\n position: absolute;\n z-index: 1;\n width: 38px;\n height: 38px;\n margin: 6px;\n border-radius: 50%;\n background-color: var(--card-background-color,var(--ha-card-background));\n cursor: pointer !important;\n }\n \n ha-icon {\n display: flex;\n position: absolute;\n margin: inherit;\n padding: 1px 2px;\n width: 22px; \n height: 22px;\n }\n \n .entity-picture {\n height: inherit;\n border-radius: 100%;\n }\n \n .name-container {\n position: relative;\n display: ${c?"block":"inline-flex"};\n margin-left: 58px;\n z-index: 1;\n font-weight: 600;\n align-items: center;\n line-height: ${c?"4px":"16px"};\n }\n \n .state {\n font-size: 12px;\n opacity: 0.7;\n }\n \n .feedback-element {\n position: absolute;\n top: 0;\n left: 0;\n opacity: 0;\n width: 100%;\n height: 100%;\n background-color: rgb(0,0,0);\n }\n \n @keyframes tap-feedback {\n 0% {transform: translateX(-100%); opacity: 0;}\n 64% {transform: translateX(0); opacity: 0.1;}\n 100% {transform: translateX(100%); opacity: 0;}\n }\n `;addStyles(this,T,customStyles,state,entityId);break;case"separator":if(!this.separatorAdded||editor){if(editor&&this.separatorContainer)for(;this.separatorContainer.firstChild;)this.separatorContainer.removeChild(this.separatorContainer.firstChild);this.separatorAdded||(this.separatorContainer=document.createElement("div"),this.separatorContainer.setAttribute("class","separator-container")),this.separatorContainer.innerHTML=`\n
\n \n

${name}

\n
\n
\n `,this.content.appendChild(this.separatorContainer),this.separatorAdded=!0}const z="\n .separator-container {\n display: inline-flex;\n width: 100%;\n }\n .separator-container div:first-child {\n display: inline-flex;\n max-width: calc(100% - 38px);\n }\n .separator-container div ha-icon{\n display: inline-flex;\n height: 24px;\n width: 24px;\n margin: 0 20px 0 8px;\n transform: translateY(-2px);\n }\n .separator-container div h4{\n display: inline-flex;\n margin: 0 20px 0 0;\n font-size: 17px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n .separator-container div:last-child{\n display: inline-flex; \n border-radius: 6px; \n opacity: 0.3; \n margin-left: 10px; \n flex-grow: 1; \n height: 6px; \n align-self: center; \n background-color: var(--background-color,var(--secondary-background-color));\n ";addStyles(this,z,customStyles);break;case"cover":const V=this.config.icon_open?this.config.icon_open:"mdi:window-shutter-open",M=this.config.icon_close?this.config.icon_close:"mdi:window-shutter",H=this.config.open_service?this.config.open_service:"cover.open_cover",B=this.config.close_service?this.config.close_service:"cover.close_cover",Y=this.config.stop_service?this.config.stop_service:"cover.stop_cover";if(icon="open"===hass.states[this.config.entity].state?V:M,formatedState=this.config.entity?hass.formatEntityState(hass.states[this.config.entity]):"",!this.coverAdded||editor){if(editor&&this.coverContainer)for(;this.coverContainer.firstChild;)this.coverContainer.removeChild(this.coverContainer.firstChild);this.coverContainer=document.createElement("div"),this.coverContainer.setAttribute("class","cover-container"),this.coverContainer.innerHTML=`\n
\n
\n
\n
\n

${name}

\n

${formatedState}

\n
\n
\n
\n \n \n \n
\n `,this.content.appendChild(this.coverContainer);const Yt=this.coverContainer.querySelector(".open"),qt=this.coverContainer.querySelector(".stop"),Ut=this.coverContainer.querySelector(".close");Yt.addEventListener("click",(()=>{hass.callService(H.split(".")[0],H.split(".")[1],{entity_id:entityId})})),qt.addEventListener("click",(()=>{hass.callService(Y.split(".")[0],Y.split(".")[1],{entity_id:entityId})})),Ut.addEventListener("click",(()=>{hass.callService(B.split(".")[0],B.split(".")[1],{entity_id:entityId})})),this.iconContainer=this.content.querySelector(".icon-container"),addActions(this,this.iconContainer),this.coverAdded=!0}this.iconContainer&&(this.iconContainer.innerHTML=``,this.content.querySelector(".state").textContent=formatedState);const q="\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n }\n \n .header-container {\n display: flex;\n align-items: center;\n margin-bottom: 10px;\n }\n \n .cover-container {\n display: grid;\n }\n \n .icon-container {\n display: flex;\n margin: 0 !important;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n /*z-index: 1;*/\n width: 48px;\n height: 48px;\n margin: 6px;\n border-radius: 50%;\n background-color: var(--card-background-color,var(--ha-card-background));\n border: 6px solid var(--background-color-2,var(--secondary-background-color));\n box-sizing: border-box;\n }\n \n .name-container {\n font-weight: 600;\n margin-left: 10px;\n line-height: 4px;\n }\n \n .buttons-container {\n display: grid;\n align-self: center;\n grid-auto-flow: column;\n grid-gap: 18px; \n }\n \n .state {\n font-size: 12px;\n opacity: 0.7;\n }\n \n ha-icon {\n display: flex; \n height: 24px; \n width: 24px; \n color: var(--primary-text-color);\n }\n \n .button {\n display: flex;\n background: var(--background-color-2,var(--secondary-background-color));\n height: 42px;\n border-radius: 32px;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border: none;\n }\n ";addStyles(this,q,customStyles,state,entityId);break;case"empty-column":if(!this.emptyCollumnAdded){const Ft=document.createElement("div");Ft.setAttribute("class","empty-column"),Ft.innerHTML='\n
\n
\n ',this.content.appendChild(Ft),this.emptyColumnAdded=!0}}}setConfig(t){if("pop-up"===t.card_type){if(!t.hash)throw new Error("You need to define an hash. Please note that this card must be placed inside a vertical_stack to work as a pop-up.")}else if("horizontal-buttons-stack"===t.card_type){var e={};for(var n in t)if(n.match(/^\d+_icon$/)){var i=n.replace("_icon","_link");if(void 0===t[i])throw new Error("You need to define "+i);if(e[t[i]])throw new Error("You can't use "+t[i]+" twice");e[t[i]]=!0}}else if(("button"===t.card_type||"cover"===t.card_type)&&!t.entity)throw new Error("You need to define an entity");this.config=t}getCardSize(){return 1}static getConfigElement(){return document.createElement("bubble-card-editor")}}console.info(`%c Bubble Card %c ${version} `,"background-color: #555;color: #fff;padding: 3px 2px 3px 3px;border-radius: 14px 0 0 14px;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)","background-color: #506eac;color: #fff;padding: 3px 3px 3px 2px;border-radius: 0 14px 14px 0;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)"),customElements.define("bubble-card",BubbleCard);const fireEvent=(t,e,n,i)=>{i=i||{},n=null==n?{}:n;const o=new Event(e,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return o.detail=n,t.dispatchEvent(o),o};customElements.get("ha-switch");const LitElement=Object.getPrototypeOf(customElements.get("ha-panel-lovelace")),html=LitElement.prototype.html,css=LitElement.prototype.css;class BubbleCardEditor extends LitElement{setConfig(t){this._config={...t}}static get properties(){return{hass:{},_config:{}}}get _card_type(){return this._config.card_type||""}get _button_type(){return this._config.button_type||"switch"}get _entity(){return this._config.entity||""}get _name(){return this._config.name||""}get _icon(){return this._config.icon||""}get _state(){return this._config.state||""}get _text(){return this._config.text||""}get _hash(){return this._config.hash||"#pop-up-name"}get _trigger_entity(){return this._config.trigger_entity||""}get _trigger_state(){return this._config.trigger_state||""}get _trigger_close(){return this._config.trigger_close||!1}get _margin(){return this._config.margin||"7px"}get _margin_top_mobile(){return this._config.margin_top_mobile||"0px"}get _margin_top_desktop(){return this._config.margin_top_desktop||"0px"}get _width_desktop(){return this._config.width_desktop||"540px"}get _is_sidebar_hidden(){return this._config.is_sidebar_hidden||!1}get _auto_close(){return this._config.auto_close||""}get _back_open(){return this._config.back_open||!1}get _icon_open(){return this._config.icon_open||""}get _icon_close(){return this._config.icon_close||""}get _open_service(){return this._config.open_service||"cover.open_cover"}get _close_service(){return this._config.open_service||"cover.close_cover"}get _stop_service(){return this._config.open_service||"cover.stop_cover"}get _auto_order(){return this._config.auto_order||!1}get _show_state(){return this._config.show_state||!1}render(){if(!this.hass)return html``;if(!this.listsUpdated){const t=t=>({label:t,value:t});this.allEntitiesList=Object.keys(this.hass.states).map(t),this.lightList=Object.keys(this.hass.states).filter((t=>"light"===t.substr(0,t.indexOf(".")))).map(t),this.sensorList=Object.keys(this.hass.states).filter((t=>"sensor"===t.substr(0,t.indexOf(".")))).map(t),this.binarySensorList=Object.keys(this.hass.states).filter((t=>"binary_sensor"===t.substr(0,t.indexOf(".")))).map(t),this.coverList=Object.keys(this.hass.states).filter((t=>"cover"===t.substr(0,t.indexOf(".")))).map(t),this.cardTypeList=[{label:"Button",value:"button"},{label:"Cover",value:"cover"},{label:"Empty column",value:"empty-column"},{label:"Horizontal buttons stack",value:"horizontal-buttons-stack"},{label:"Pop-up",value:"pop-up"},{label:"Separator",value:"separator"}],this.buttonTypeList=[{label:"Switch",value:"switch"},{label:"Slider",value:"slider"}],this.listsUpdated=!0}const t=this.allEntitiesList,e=(this.lightList,this.sensorList,this.coverList),n=this.cardTypeList,i=this.buttonTypeList;if("pop-up"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Pop-up

This card allows you to convert any vertical-stack into a pop-up. Each pop-up can be opened by targeting its link (e.g. '#pop-up-name'), with navigation_path or with the horizontal buttons stack that is included.

It must be placed within a vertical-stack card at the top most position to function properly. The pop-up will be hidden by default until you open it.
${this.makeDropdown("Optional - Icon","icon")} ${this.makeDropdown("Optional - Entity to toggle (e.g. room light group)","entity",t)} ${this.makeDropdown("Optional - Entity state to display (e.g. room temperature)","state",t)}

Pop-up trigger

This allows you to open this pop-up based on the state of any entity, for example you can open a "Security" pop-up with a camera when a person is in front of your house. You can also create a toggle helper (input_boolean) and trigger its opening/closing in an automation. ${this.makeDropdown("Optional - Entity to open the pop-up based on its state","trigger_entity",t)}

Styling options

Advanced settings

Back button/event support : This allow you to navigate through your pop-ups when you press the back button of your browser. This setting can be applied only once, you don't need to change it in all pop-ups. Beta users: This was the previous default behavior, set it to true to keep everything like before the update. ${this.makeVersion()}
`;if("button"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Button

This card can be a slider or a button, allowing you to toggle your entities, control the brightness of your lights and the volume of your media players. To access color / control of an entity, simply tap on the icon. ${this.makeDropdown("slider"!==this._button_type?"Entity (toggle)":"Entity (light or media_player)","entity",t)} ${this.makeDropdown("Button type","button_type",i)} ${this.makeDropdown("Optional - Icon","icon")}
${this.makeVersion()}
`;if("separator"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Separator

This card is a simple separator for dividing your pop-up into categories / sections. e.g. Lights, Devices, Covers, Settings, Automations... ${this.makeDropdown("Icon","icon")} ${this.makeVersion()}
`;if("horizontal-buttons-stack"===this._config.card_type){if(!this.buttonAdded&&this.shadowRoot.querySelector("#add-button")){const t=this.shadowRoot.querySelector("#add-button");for(this.buttonIndex=0;this._config[this.buttonIndex+1+"_link"];)this.buttonIndex++;t.addEventListener("click",(()=>{this.buttonIndex++;const e=t.style.opacity,n=t.innerText;t.style.opacity="0.6",t.style.transition="opacity 1s",t.innerText="Loading...",setTimeout((()=>{t.style.opacity=e,t.innerText=n}),5e3)})),this.buttonAdded=!0}return html`
${this.makeDropdown("Card type","card_type",n)}

Horizontal buttons stack

This card is the companion to the pop-up card, allowing you to open the corresponding pop-ups. It also allows you to open any page of your dashboard. In addition, you can add your motion sensors so that the order of the buttons adapts according to the room you just entered. This card is scrollable, remains visible and acts as a footer.

Please note that this card may take some time to load in edit mode.
${this.makeButton()}

Styling options

${this.makeVersion()}
`}return"cover"===this._config.card_type?html`
${this.makeDropdown("Card type","card_type",n)}

Cover

This card allows you to control your covers. ${this.makeDropdown("Entity","entity",e)} ${this.makeDropdown("Optional - Open icon","icon_open")} ${this.makeDropdown("Optional - Closed icon","icon_close")} ${this.makeVersion()}
`:"empty-column"===this._config.card_type?html`
${this.makeDropdown("Card type","card_type",n)}

Empty column

Just an empty card to fill any empty column. ${this.makeVersion()}
`:this._config.card_type?void 0:html`
${this.makeDropdown("Card type","card_type",n)} You need to add a card type first.

Almost everything is available in the GUI editor, but in the YAML editor you can add your own custom styles, create custom buttons or modify the tap actions of all cards. You can find more details on my GitHub page.

And if you like my project and want to support me, please consider making a donation. Any amount is welcome and very much appreciated! 🍻

${this.makeVersion()}
`}makeDropdown(t,e,n){this.hass;return t.includes("icon")||t.includes("Icon")?html`
`:html`
`}makeButton(){let t=[];for(let e=1;e<=this.buttonIndex;e++)t.push(html`
this.removeButton(e)}> Button ${e}
`);return t}makeVersion(){return html`

Bubble Card ${version}

`}removeButton(t){delete this._config[t+"_name"],delete this._config[t+"_icon"],delete this._config[t+"_link"],delete this._config[t+"_entity"],delete this._config[t+"_pir_sensor"];for(let e=t;e{window.addEventListener(t,i)}));const n=new Event("urlChanged");function i(){const t=window.location.href;t!==this.currentUrl&&(window.dispatchEvent(n),this.currentUrl=t)}const o=()=>{window.dispatchEvent(n),window.addEventListener("popstate",i),setTimeout((()=>{window.removeEventListener("popUpInitialized",o)}),1e3)};window.addEventListener("popUpInitialized",o),window.eventAdded=!0}}set hass(hass){function toggleEntity(t){hass.callService("homeassistant","toggle",{entity_id:t})}this.content||(this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML='\n \n
\n
\n
\n ',this.card=this.shadowRoot.querySelector("ha-card"),this.content=this.shadowRoot.querySelector("div"),this.editorElement=document.querySelector("body > home-assistant").shadowRoot.querySelector("home-assistant-main").shadowRoot.querySelector("ha-drawer > partial-panel-resolver > ha-panel-lovelace").shadowRoot.querySelector("hui-root").shadowRoot.querySelector("div")),editor=this.editorElement.classList.contains("edit-mode");const addStyles=function(context,styles,customStyles,state,entityId,path="",element=context.content){const customStylesEval=customStyles?eval("`"+customStyles+"`"):"";let styleAddedKey=styles+"Added";if(!context[styleAddedKey]||context.previousStyle!==customStylesEval){if(!context[styleAddedKey]){if(context.styleElement=context.content.querySelector("style"),!context.styleElement){context.styleElement=document.createElement("style");const t=path?context.content.querySelector(path):element;t.appendChild(context.styleElement)}context[styleAddedKey]=!0}context.styleElement.innerHTML=customStylesEval+styles,context.previousStyle=customStylesEval}},forwardHaptic=t=>{fireEvent(window,"haptic",t)},navigate=(t,e,n=!1)=>{n?history.replaceState(null,"",e):history.pushState(null,"",e),fireEvent(window,"location-changed",{replace:n})},handleActionConfig=(t,e,n,i)=>{if(!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some((t=>t.user===e.user.id))||(forwardHaptic("warning"),confirm(i.confirmation.text||`Are you sure you want to ${i.action}?`)))switch(i.action){case"more-info":(this.config.entity||this.config.camera_image)&&fireEvent(t,"hass-more-info",{entityId:this.config.entity?this.config.entity:this.config.camera_image});break;case"navigate":i.navigation_path&&navigate(t,i.navigation_path);break;case"url":i.url_path&&window.open(i.url_path);break;case"toggle":this.config.entity&&(toggleEntity(this.config.entity),forwardHaptic("success"));break;case"call-service":{if(!i.service)return void forwardHaptic("failure");const[t,n]=i.service.split(".",2);e.callService(t,n,i.service_data,i.target),forwardHaptic("success");break}case"fire-dom-event":fireEvent(t,"ll-custom",i)}},handleAction=(t,e,n,i)=>{let o;"double_tap"===i&&this.config.double_tap_action?o=this.config.double_tap_action:"hold"===i&&this.config.hold_action?o=this.config.hold_action:"tap"===i&&this.config.tap_action?o=this.config.tap_action:"double_tap"!==i||this.config.double_tap_action?("hold"!==i||this.config.hold_action)&&("tap"!==i||this.config.tap_action)||(o={action:"more-info"}):o={action:"toggle"},handleActionConfig(t,e,n,o)},addAction=function(){let t,e;return function(n,i,o,a){o.addEventListener(n,(()=>{const i=(new Date).getTime();"click"===n?i-(e||0)<250?(clearTimeout(t),handleAction(a,hass,{},"double_tap")):t=setTimeout((()=>{handleAction(a,hass,{},"tap")}),250):handleAction(a,hass,{},"hold"),e=i}))}}();function addActions(t,e){addAction("click","tap",e,t),addAction("contextmenu","hold",e,t)}let haStyle=getComputedStyle(document.body),color=this.config.bg_color?this.config.bg_color:haStyle.getPropertyValue("--ha-card-background")||haStyle.getPropertyValue("--card-background-color"),bgOpacity=void 0!==this.config.bg_opacity?this.config.bg_opacity:"88",rgbaColor;function convertToRGBA(t,e){let n="";if(t.startsWith("#")){n="rgba("+parseInt(t.slice(1,3),16)+", "+parseInt(t.slice(3,5),16)+", "+parseInt(t.slice(5,7),16)+", "+e+")"}else if(t.startsWith("rgb")){let i=t.match(/\d+/g);n="rgba("+i[0]+", "+i[1]+", "+i[2]+", "+e+")"}return n}rgbaColor&&!editor||(rgbaColor=convertToRGBA(color,bgOpacity/100),window.color=color);let customStyles=this.config.styles?this.config.styles:"",entityId=this.config.entity?this.config.entity:"",icon=!this.config.icon&&this.config.entity?hass.states[entityId].attributes.icon||hass.states[entityId].attributes.entity_picture||"":this.config.icon||"",name=this.config.name?this.config.name:this.config.entity?hass.states[entityId].attributes.friendly_name:"",widthDesktop=this.config.width_desktop||"540px",widthDesktopDivided=widthDesktop?widthDesktop.match(/(\d+)(\D+)/):"",shadowOpacity=void 0!==this.config.shadow_opacity?this.config.shadow_opacity:"10",bgBlur=void 0!==this.config.bg_blur?this.config.bg_blur:"14",isSidebarHidden=this.config.is_sidebar_hidden||!1,state=entityId?hass.states[entityId].state:"",formatedState,autoClose=this.config.auto_close||!1,riseAnimation=void 0===this.config.rise_animation||this.config.rise_animation,marginCenter=this.config.margin?"0"!==this.config.margin?this.config.margin:"0px":"7px",backOpen=this.config.back_open,popUpOpen;switch(this.config.card_type){case"pop-up":if(this.getRootNode().host){const U=this.config.hash;if(!this.popUp&&(this.card.style.marginTop="0",this.verticalStack=this.getRootNode(),this.popUp=this.verticalStack.querySelector("#root"),!window.popUpIntialized)){if(backOpen){window.backOpen=!0;const ot=new Event("popUpInitialized");setTimeout((()=>{window.dispatchEvent(ot)}),1)}else window.backOpen=!1,popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),console.log("Delete hash");window.popUpIntialized=!0}const R=this.popUp,F=this.config.text||"",j=this.config.trigger_entity?this.config.trigger_entity:"",P=this.config.trigger_state?this.config.trigger_state:"",W=!!this.config.trigger_close&&this.config.trigger_close;formatedState=this.config.state?hass.formatEntityState(hass.states[this.config.state])+" "+F:F;const X=this.config.margin_top_mobile&&"0"!==this.config.margin_top_mobile?this.config.margin_top_mobile:"0px",N=this.config.margin_top_desktop&&"0"!==this.config.margin_top_desktop?this.config.margin_top_desktop:"0px",G=this.config.entity?"flex":"none";let K;if(state=this.config.state?hass.states[this.config.state].state:"",this.headerAdded){if(this.headerAdded){const at=this.content.querySelector("#header-container .header-icon");if(at.innerHTML="",hass&&hass.states&&hass.states[entityId]&&hass.states[entityId].attributes.entity_picture&&!this.config.icon){const ct=document.createElement("img");ct.setAttribute("src",hass.states[entityId].attributes.entity_picture),ct.setAttribute("class","entity-picture"),ct.setAttribute("alt","Icon"),at.appendChild(ct)}else{const dt=document.createElement("ha-icon");dt.setAttribute("icon",icon),dt.setAttribute("class","icon"),at.appendChild(dt)}const st=this.content.querySelector("#header-container h2");st.textContent=name;const rt=this.content.querySelector("#header-container p");rt.textContent=formatedState;const lt=this.content.querySelector("#header-container .power-button");lt.setAttribute("style",`display: ${G};`)}}else{const ht=document.createElement("div");ht.setAttribute("id","header-container");const pt=document.createElement("div");ht.appendChild(pt);const ut=document.createElement("div");if(ut.setAttribute("class","header-icon"),pt.appendChild(ut),hass&&hass.states&&hass.states[entityId]&&hass.states[entityId].attributes.entity_picture&&!this.config.icon){const vt=document.createElement("img");vt.setAttribute("src",hass.states[entityId].attributes.entity_picture),vt.setAttribute("class","entity-picture"),vt.setAttribute("alt","Icon"),ut.appendChild(vt)}else{const _t=document.createElement("ha-icon");_t.setAttribute("icon",icon),_t.setAttribute("class","icon"),ut.appendChild(_t)}addActions(this,ut);const gt=document.createElement("h2");gt.textContent=name,pt.appendChild(gt);const mt=document.createElement("p");mt.textContent=formatedState,pt.appendChild(mt);const ft=document.createElement("ha-icon");ft.setAttribute("class","power-button"),ft.setAttribute("icon","mdi:power"),ft.setAttribute("style",`display: ${G};`),pt.appendChild(ft);const bt=document.createElement("button");bt.setAttribute("class","close-pop-up"),bt.onclick=function(){history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0)},ht.appendChild(bt);const yt=document.createElement("ha-icon");yt.setAttribute("icon","mdi:close"),bt.appendChild(yt),this.content.appendChild(ht),this.header=pt,this.headerAdded=!0}if(!this.eventAdded&&!editor){window["checkHashRef_"+U]=Z,window.addEventListener("urlChanged",window["checkHashRef_"+U]),this.content.querySelector(".power-button").addEventListener("click",(()=>{toggleEntity(entityId)}));let wt=location.hash,xt,kt;window.addEventListener("click",(function(t){location.hash===U&&tt(),location.hash===wt?location.hash!==U||t.composedPath().some((t=>"HA-MORE-INFO-DIALOG"===t.nodeName))||t.composedPath().some((t=>"root"===t.id&&!t.classList.contains("close-pop-up")))||(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0)):wt=location.hash})),window.addEventListener("keydown",(function(t){"Escape"===t.key&&(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),localStorage.setItem("isManuallyClosed_"+U,!0))})),R.addEventListener("touchstart",(function(t){location.hash===U&&tt(),xt=t.touches[0].clientY,kt=xt})),R.addEventListener("touchmove",(function(t){t.touches[0].clientY-xt>300&&t.touches[0].clientY>kt&&(popUpOpen=U+!1,history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=U+!1,localStorage.setItem("isManuallyClosed_"+U,!0)),kt=t.touches[0].clientY})),this.eventAdded=!0}if(j){null===localStorage.getItem("previousTriggerState_"+U)&&localStorage.setItem("previousTriggerState_"+U,""),null===localStorage.getItem("isManuallyClosed_"+U)&&localStorage.setItem("isManuallyClosed_"+U,"false"),null===localStorage.getItem("isTriggered_"+U)&&localStorage.setItem("isTriggered_"+U,"false");let $t=localStorage.getItem("previousTriggerState_"+U),Ct="true"===localStorage.getItem("isManuallyClosed_"+U),St="true"===localStorage.getItem("isTriggered_"+U);hass.states[j].state!==P||null!==$t||St||(navigate("",U),St=!0,localStorage.setItem("isTriggered_"+U,St)),hass.states[j].state!==$t&&(Ct=!1,localStorage.setItem("previousTriggerState_"+U,hass.states[j].state),localStorage.setItem("isManuallyClosed_"+U,Ct)),hass.states[j].state!==P||Ct?hass.states[j].state!==P&&W&&R.classList.contains("open-pop-up")&&St&&!Ct&&(history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=U+!1,St=!1,Ct=!0,localStorage.setItem("isManuallyClosed_"+U,Ct),localStorage.setItem("isTriggered_"+U,St)):(navigate("",U),St=!0,localStorage.setItem("isTriggered_"+U,St))}if(""!==entityId){const Et=hass.states[entityId].attributes.rgb_color,It=Et?`rgba(${Et[0]}, ${Et[1]}, ${Et[2]}, 0.5)`:"off"!==hass.states[entityId].state?"var(--accent-color)":"var(--background-color,var(--secondary-background-color))";this.header.style.backgroundColor=It}function Z(){if(!editor){location.hash.split("?")[0]===U?J():R.classList.contains("open-pop-up")&&Q()}}function J(){R.classList.remove("close-pop-up"),R.classList.add("open-pop-up"),popUpOpen=U+!0,tt()}function Q(){R.classList.remove("open-pop-up"),R.classList.add("close-pop-up"),popUpOpen=U+!1,clearTimeout(K)}function tt(){clearTimeout(K),autoClose>0&&(K=setTimeout(et,autoClose))}function et(){history.replaceState(null,null,location.href.split("#")[0])}const nt=`\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n border: none !important;\n }\n .card-content {\n width: 100% !important;\n padding: 0 !important;\n }\n #root {\n position: fixed !important;\n margin: 0 -${marginCenter}; /* 7px */\n width: 100%;\n background-color: ${rgbaColor};\n box-shadow: 0px 0px 50px rgba(0,0,0,${shadowOpacity/100});\n backdrop-filter: blur(${bgBlur}px);\n border-radius: 42px;\n box-sizing: border-box;\n top: calc(100% + ${X} + var(--header-height));\n grid-gap: 12px !important;\n gap: 12px !important;\n grid-auto-rows: min-content;\n padding: 18px 18px 220px 18px !important;\n height: 100% !important;\n -ms-overflow-style: none; /* for Internet Explorer, Edge */\n scrollbar-width: none; /* for Firefox */\n overflow-y: auto; \n overflow-x: hidden; \n z-index: 1 !important; /* Higher value hide the more-info panel */\n /* For older Safari but not working with Firefox */\n /* display: grid !important; */ \n }\n /* \n #root > bubble-card:first-child::after {\n content: '';\n display: block;\n position: sticky;\n top: 0;\n left: -50px;\n margin: -70px 0 -35px 0;\n width: 200%;\n height: 100px;\n background: linear-gradient(0deg, rgba(79, 69, 87, 0) 0%, ${rgbaColor} 80%);\n z-index: 0;\n } \n */\n #root::-webkit-scrollbar {\n display: none; /* for Chrome, Safari, and Opera */\n }\n #root > bubble-card:first-child {\n position: sticky;\n top: 0;\n z-index: 1;\n background: none !important;\n }\n #root.open-pop-up {\n transform: translateY(-100%);\n transition: transform .4s !important;\n }\n #root.open-pop-up > * {\n /* Block child items to overflow and if they do clip them */\n /*max-width: calc(100vw - 38px);*/\n max-width: 100% !important;\n overflow-x: clip;\n }\n #root.close-pop-up { \n transform: translateY(0%);\n transition: transform .4s !important;\n /* animation: hide 1s forwards; */\n }\n @media only screen and (min-width: 768px) {\n #root {\n top: calc(100% + ${N} + var(--header-height));\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]});\n margin: 0 !important;\n }\n } \n @media only screen and (min-width: 870px) {\n #root {\n top: calc(100% + ${N} + var(--header-height));\n width: calc(${widthDesktop}${"%"!==widthDesktopDivided[2]||isSidebarHidden?"":" - var(--mdc-drawer-width)"}) !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]} + ${isSidebarHidden?"0px":"var(--mdc-drawer-width) "+("%"===widthDesktopDivided[2]?"":"/ 2")});\n margin: 0 !important;\n }\n } \n #root.editor {\n position: inherit !important;\n width: 100% !important;\n padding: 18px !important;\n }\n `,it=`\n #header-container {\n display: inline-flex;\n ${icon||name||entityId||state||F?"":"flex-direction: row-reverse;"}\n width: 100%;\n margin: 0;\n padding: 0;\n }\n #header-container > div {\n display: ${icon||name||entityId||state||F?"inline-flex":"none"};\n align-items: center;\n position: relative;\n padding: 6px;\n z-index: 1;\n flex-grow: 1;\n background-color: var(--background-color,var(--secondary-background-color));\n transition: background 1s;\n border-radius: 25px;\n margin-right: 14px;\n backdrop-filter: blur(14px);\n }\n .header-icon {\n display: inline-flex;\n width: 22px;\n height: 22px;\n padding: 8px;\n background-color: var(--card-background-color,var(--ha-card-background));\n border-radius: 100%;\n margin: 0 10px 0 0;\n cursor: ${this.config.entity||this.config.double_tap_action||this.config.tap_action||this.config.hold_action?"pointer":"default"}; \n flex-wrap: wrap;\n align-content: center;\n justify-content: center;\n overflow: hidden;\n }\n .entity-picture {\n height: calc(100% + 16px);\n width: calc(100% + 16px);\n }\n #header-container h2 {\n display: inline-flex;\n margin: 0 18px 0 0;\n /*line-height: 0px;*/\n z-index: 1;\n font-size: 20px;\n }\n #header-container p {\n display: inline-flex;\n line-height: 0px;\n font-size: 16px;\n }\n .power-button {\n cursor: pointer; \n flex-grow: inherit; \n width: 24px;\n height: 24px;\n border-radius: 12px;\n margin: 0 10px;\n background: none !important;\n justify-content: flex-end;\n background-color: var(--background-color,var(--secondary-background-color));\n }\n .close-pop-up {\n height: 50px;\n width: 50px;\n border: none;\n border-radius: 50%;\n z-index: 1;\n background: var(--background-color,var(--secondary-background-color));\n color: var(--primary-text-color);\n flex-shrink: 0;\n cursor: pointer;\n }\n `;addStyles(this,nt,customStyles,state,entityId,"",R),addStyles(this,it,customStyles,state,entityId),!0===editor?(R.classList.add("editor"),R.classList.remove("open-pop-up"),R.classList.remove("close-pop-up")):R.classList.remove("editor")}else!0!==editor&&(this.card.style.marginTop="2000px");break;case"horizontal-buttons-stack":const t=(t,e,n)=>{const i=document.createElement("button");return i.setAttribute("class",`button ${e.substring(1)}`),i.innerHTML=`\n ${""!==n?``:""}\n ${""!==t?`

${t}

`:""}\n `,i.addEventListener("click",(t=>{t.stopPropagation(),popUpOpen=location.hash+!0;localStorage.getItem("isManuallyClosed_"+e);popUpOpen!==e+!0?(navigate("",e),popUpOpen=e+!0):(history.replaceState(null,null,location.href.split("#")[0]),popUpOpen=e+!1)})),i};if(!this.buttonsAdded){const At=document.createElement("div");At.setAttribute("class","horizontal-buttons-stack-container"),this.content.appendChild(At),this.buttonsContainer=At}const e=(t,e)=>{if(hass.states[e].attributes.rgb_color){const n=hass.states[e].attributes.rgb_color,i=`rgba(${n[0]}, ${n[1]}, ${n[2]}, 0.5)`;t.style.backgroundColor=i,t.style.border="1px solid rgba(0,0,0,0)"}else hass.states[e].attributes.rgb_color||"on"!=hass.states[e].state?(t.style.backgroundColor="rgba(0,0,0,0)",t.style.border="1px solid var(--primary-text-color)"):(t.style.backgroundColor="rgba(255,255,255,0.5)",t.style.border="1px solid rgba(0,0,0,0)")};let n=[],i=1;for(;this.config[i+"_link"];){const Lt=i+"_",Ot=this.config[Lt+"name"]||"",Dt=this.config[Lt+"pir_sensor"];icon=this.config[Lt+"icon"]||"";const Tt=this.config[Lt+"link"],Vt=this.config[Lt+"entity"];n.push({button:Ot,pirSensor:Dt,icon:icon,link:Tt,lightEntity:Vt}),i++}if(this.config.auto_order&&n.sort(((t,e)=>{if(t.pirSensor&&e.pirSensor){if("on"===hass.states[t.pirSensor].state&&"on"===hass.states[e.pirSensor].state){return hass.states[t.pirSensor].last_updated{const n=t(e.button,e.link,e.icon);zt[e.link]=n,this.buttonsContainer.appendChild(n)})),this.buttonsAdded=!0,this.buttons=zt}editor?localStorage.setItem("justExitedEditor",!1):"false"===localStorage.getItem("justExitedEditor")&&localStorage.setItem("justExitedEditor",!0);let o=0,a=12;const s="true"===localStorage.getItem("editorMode")&&!editor;n.forEach(((t,n)=>{let i=this.buttons[t.link];if(i){let e=localStorage.getItem(`buttonWidth-${t.link}`),n=localStorage.getItem(`buttonContent-${t.link}`);(!e||"0"===e||n!==i.innerHTML||editor||s)&&(e=i.offsetWidth,localStorage.setItem(`buttonWidth-${t.link}`,e),localStorage.setItem(`buttonContent-${t.link}`,i.innerHTML),editor?a=36:s&&(a=12)),i.style.transform=`translateX(${o}px)`,o+=parseInt(e)+a}t.lightEntity&&e(i,t.lightEntity)}));const r=`\n ha-card {\n border-radius: 0;\n }\n .horizontal-buttons-stack {\n width: 100%;\n margin-top: 0 !important;\n background: none !important;\n position: fixed;\n height: 51px;\n bottom: 16px;\n left: ${marginCenter};\n animation: ${!0===riseAnimation?"from-bottom 1.3s forwards":"none"};\n z-index: 1 !important; /* Higher value hide the more-info panel */\n }\n @keyframes from-bottom {\n 0% {transform: translateY(200px);}\n 20% {transform: translateY(200px);}\n 46% {transform: translateY(-8px);}\n 56% {transform: translateY(1px);}\n 62% {transform: translateY(-2px);}\n 70% {transform: translateY(0);}\n 100% {transform: translateY(0);}\n }\n .horizontal-buttons-stack-container {\n width: max-content;\n position: relative;\n height: 51px;\n }\n .button {\n display: flex;\n position: absolute;\n box-sizing: border-box !important;\n border: 1px solid var(--primary-text-color);\n align-items: center;\n height: 50px;\n white-space: nowrap;\n width: auto;\n border-radius: 25px;\n z-index: 1;\n padding: 16px;\n background: none;\n transition: background-color 1s, border 1s, transform 1s;\n color: var(--primary-text-color);\n }\n .icon {\n height: 24px;\n }\n .card-content {\n width: calc(100% + 18px);\n box-sizing: border-box !important;\n margin: 0 -36px !important;\n padding: 0 36px !important;\n overflow: scroll !important;\n -ms-overflow-style: none;\n scrollbar-width: none;\n -webkit-mask-image: linear-gradient(90deg, transparent 0%, rgba(0, 0, 0, 1) calc(0% + 28px), rgba(0, 0, 0, 1) calc(100% - 28px), transparent 100%);\n /* mask-image: linear-gradient(90deg, transparent 2%, rgba(0, 0, 0, 1) 6%, rgba(0, 0, 0, 1) 96%, transparent 100%); */\n /* -webkit-mask-image: linear-gradient(90deg, transparent 2%, rgba(0, 0, 0, 1) 6%, rgba(0, 0, 0, 1) 96%, transparent 100%); */\n }\n .horizontal-buttons-stack::before {\n content: '';\n position: absolute;\n top: -32px;\n left: -100%;\n display: block;\n background: linear-gradient(0deg, var(--background-color, var(--primary-background-color)) 50%, rgba(79, 69, 87, 0));\n width: 200%;\n height: 100px;\n }\n .card-content::-webkit-scrollbar {\n display: none;\n }\n @media only screen and (min-width: 768px) {\n .card-content {\n position: fixed;\n width: ${widthDesktop} !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]});\n margin-left: -13px !important;\n padding: 0 26px !important;\n }\n }\n @media only screen and (min-width: 870px) {\n .card-content {\n position: fixed;\n width: calc(${widthDesktop}${"%"!==widthDesktopDivided[2]||isSidebarHidden?"":" - var(--mdc-drawer-width)"}) !important;\n left: calc(50% - ${widthDesktopDivided[1]/2}${widthDesktopDivided[2]} + ${!0===isSidebarHidden?"0px":"var(--mdc-drawer-width) "+("%"===widthDesktopDivided[2]?"":"/ 2")});\n margin-left: -18px !important;\n padding: 0 26px !important;\n }\n }\n \n .horizontal-buttons-stack.editor {\n position: relative;\n bottom: 0;\n left: 0;\n overflow: hidden;\n }\n \n .horizontal-buttons-stack.editor::before {\n top: -32px;\n left: -100%;\n background: none;\n width: 100%;\n height: 0;\n }\n \n .horizontal-buttons-stack-container.editor > .button {\n transition: background-color 0s, border 0s, transform 0s;\n }\n \n .horizontal-buttons-stack-container.editor {\n margin-left: 1px;\n }\n \n .horizontal-buttons-stack.editor > .card-content {\n position: relative;\n width: calc(100% + 26px) !important;\n left: -26px;\n margin: 0 !important;\n padding: 0;\n }\n `;addStyles(this,r,customStyles),editor?(this.buttonsContainer.classList.add("editor"),this.card.classList.add("editor")):(this.buttonsContainer.classList.remove("editor"),this.card.classList.remove("editor"));break;case"button":if(!this.buttonAdded){const Bt=document.createElement("div");Bt.setAttribute("class","button-container"),this.content.appendChild(Bt)}const l=this.config.button_type||"switch";formatedState=hass.formatEntityState(hass.states[entityId]);const c=!!this.config.show_state&&this.config.show_state;let d=entityId?hass.states[entityId].attributes.brightness||0:"",h=entityId?hass.states[entityId].attributes.volume_level||0:"",p=!1,u=d,g=h,m=0,f=0,b=0,y=!1,v=null;const _=document.createElement("div");_.setAttribute("class","icon-container"),this.iconContainer=_;const w=document.createElement("div");w.setAttribute("class","name-container");const x=document.createElement("div");x.setAttribute("class","switch-button");const k=document.createElement("div");k.setAttribute("class","range-slider");const $=document.createElement("div");if($.setAttribute("class","range-fill"),entityId&&entityId.startsWith("light.")&&"slider"===l?$.style.transform=`translateX(${d/255*100}%)`:entityId&&entityId.startsWith("media_player.")&&"slider"===l&&($.style.transform=`translateX(${100*h}%)`),!this.buttonContainer||editor){if(editor&&this.buttonContainer){for(;this.buttonContainer.firstChild;)this.buttonContainer.removeChild(this.buttonContainer.firstChild);this.eventAdded=!1}this.buttonContainer=this.content.querySelector(".button-container"),"slider"!==l||this.buttonAdded&&!editor?("switch"===l||"custom"===l||editor)&&(this.buttonContainer.appendChild(x),x.appendChild(_),x.appendChild(w),this.switchButton=this.content.querySelector(".switch-button")):(this.buttonContainer.appendChild(k),k.appendChild(_),k.appendChild(w),k.appendChild($),this.rangeFill=this.content.querySelector(".range-fill")),!hass.states[entityId].attributes.entity_picture&&!icon.startsWith("/api/image/")||this.config.icon?_.innerHTML=``:_.innerHTML=`Icon`,w.innerHTML=`\n

${name}

\n ${c?`

${formatedState}

`:""}\n `,this.buttonAdded=!0}function C(t){let e=t.querySelector(".feedback-element");e||(e=document.createElement("div"),e.setAttribute("class","feedback-element"),t.appendChild(e)),e.style.animation="tap-feedback .5s",setTimeout((()=>{e.style.animation="none",t.removeChild(e)}),500)}function S(t){m=t.pageX||(t.touches?t.touches[0].pageX:0),f=t.pageY||(t.touches?t.touches[0].pageY:0),b=k.value,t.target!==_.querySelector("ha-icon")&&(p=!0,document.addEventListener("mouseup",I),document.addEventListener("touchend",I),document.addEventListener("mousemove",E),document.addEventListener("touchmove",E),v=setTimeout((()=>{D(t.pageX||t.touches[0].pageX),A(),v=null}),200))}function E(t){const e=t.pageX||(t.touches?t.touches[0].pageX:0),n=t.pageY||(t.touches?t.touches[0].pageY:0);Math.abs(n-f)>Math.abs(e-m)?(clearTimeout(v),I()):(document.removeEventListener("mousemove",E),document.removeEventListener("touchmove",E),document.addEventListener("mousemove",L),document.addEventListener("touchmove",L))}function I(){p=!1,y=!1,A(),document.removeEventListener("mouseup",I),document.removeEventListener("touchend",I),document.removeEventListener("mousemove",L),document.removeEventListener("touchmove",L)}function A(){entityId.startsWith("light.")?(d=u,hass.callService("light","turn_on",{entity_id:entityId,brightness:d})):h!==g&&entityId.startsWith("media_player.")&&(h=g,hass.callService("media_player","volume_set",{entity_id:entityId,volume_level:h}))}function L(t){const e=t.pageX||(t.touches?t.touches[0].pageX:0),n=t.pageY||(t.touches?t.touches[0].pageY:0);p&&Math.abs(e-m)>10?D(e):p&&Math.abs(n-f)>10&&(p=!1,k.value=b)}function O(t,e){if(e.buttonContainer.style.opacity="unavailable"!==t?"1":"0.5",["switch","custom"].includes(l)){const n=["on","open","cleaning","true","home","playing"].includes(t)?"var(--accent-color)":"rgba(0,0,0,0)";e.switchButton.style.backgroundColor=n}}function D(t){const e=k.getBoundingClientRect(),n=Math.min(Math.max(t-e.left,0),e.width)/e.width;entityId.startsWith("light.")?u=Math.round(255*n):entityId.startsWith("media_player.")&&(g=n),$.style.transition="none",$.style.transform=`translateX(${100*n}%)`}if(c&&(this.content.querySelector(".state").textContent=formatedState),this.eventAdded||"switch"!==l?this.eventAdded||"slider"!==l?this.eventAdded||"custom"!==l||(x.addEventListener("click",(()=>C(this.switchButton))),addActions(this,this.switchButton),this.eventAdded=!0):(k.addEventListener("mousedown",S),k.addEventListener("touchstart",S),addActions(this,this.iconContainer),this.eventAdded=!0):(x.addEventListener("click",(()=>C(this.switchButton))),x.addEventListener("click",(function(t){t.target.closest("ha-icon")||toggleEntity(entityId)})),addActions(this,this.iconContainer),this.eventAdded=!0),this.isDragging||"slider"!==l||(this.rangeFill.style.transition="all .2s",entityId.startsWith("light.")?this.rangeFill.style.transform=`translateX(${d/255*100}%)`:entityId.startsWith("media_player.")&&(this.rangeFill.style.transform=`translateX(${100*h}%)`)),O(state,this),"slider"===l)if(entityId.startsWith("light.")){const Mt=hass.states[entityId].attributes.rgb_color,Ht=Mt?`rgba(${Mt[0]}, ${Mt[1]}, ${Mt[2]}, 0.5)`:"rgba(255, 255, 255, 0.5)";this.rangeFill.style.backgroundColor=Ht}else this.rangeFill.style.backgroundColor="var(--accent-color)";const T=`\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n }\n \n .button-container {\n position: relative;\n width: 100%;\n height: 50px;\n z-index: 0;\n background-color: var(--background-color-2,var(--secondary-background-color));\n border-radius: 25px;\n mask-image: radial-gradient(white, black);\n -webkit-mask-image: radial-gradient(white, black);\n -webkit-backface-visibility: hidden;\n -moz-backface-visibility: hidden;\n -webkit-transform: translateZ(0);\n overflow: hidden;\n }\n \n .switch-button,\n .range-slider {\n display: inline-flex;\n position: absolute;\n height: 100%;\n width: 100%;\n transition: background-color 1.5s;\n }\n \n .range-fill {\n position: absolute;\n top: 0;\n bottom: 0;\n left: 0;\n }\n \n .switch-button {\n cursor: pointer !important;\n }\n \n .range-slider {\n cursor: ew-resize;\n }\n \n .range-fill {\n z-index: 0;\n width: 100%;\n left: -100%;\n }\n \n .icon-container {\n position: absolute;\n z-index: 1;\n width: 38px;\n height: 38px;\n margin: 6px;\n border-radius: 50%;\n background-color: var(--card-background-color,var(--ha-card-background));\n cursor: pointer !important;\n }\n \n ha-icon {\n display: flex;\n position: absolute;\n margin: inherit;\n padding: 1px 2px;\n width: 22px; \n height: 22px;\n }\n \n .entity-picture {\n height: inherit;\n border-radius: 100%;\n }\n \n .name-container {\n position: relative;\n display: ${c?"block":"inline-flex"};\n margin-left: 58px;\n z-index: 1;\n font-weight: 600;\n align-items: center;\n line-height: ${c?"4px":"16px"};\n }\n \n .state {\n font-size: 12px;\n opacity: 0.7;\n }\n \n .feedback-element {\n position: absolute;\n top: 0;\n left: 0;\n opacity: 0;\n width: 100%;\n height: 100%;\n background-color: rgb(0,0,0);\n }\n \n @keyframes tap-feedback {\n 0% {transform: translateX(-100%); opacity: 0;}\n 64% {transform: translateX(0); opacity: 0.1;}\n 100% {transform: translateX(100%); opacity: 0;}\n }\n `;addStyles(this,T,customStyles,state,entityId);break;case"separator":if(!this.separatorAdded||editor){if(editor&&this.separatorContainer)for(;this.separatorContainer.firstChild;)this.separatorContainer.removeChild(this.separatorContainer.firstChild);this.separatorAdded||(this.separatorContainer=document.createElement("div"),this.separatorContainer.setAttribute("class","separator-container")),this.separatorContainer.innerHTML=`\n
\n \n

${name}

\n
\n
\n `,this.content.appendChild(this.separatorContainer),this.separatorAdded=!0}const V="\n .separator-container {\n display: inline-flex;\n width: 100%;\n }\n .separator-container div:first-child {\n display: inline-flex;\n max-width: calc(100% - 38px);\n }\n .separator-container div ha-icon{\n display: inline-flex;\n height: 24px;\n width: 24px;\n margin: 0 20px 0 8px;\n transform: translateY(-2px);\n }\n .separator-container div h4{\n display: inline-flex;\n margin: 0 20px 0 0;\n font-size: 17px;\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n }\n .separator-container div:last-child{\n display: inline-flex; \n border-radius: 6px; \n opacity: 0.3; \n margin-left: 10px; \n flex-grow: 1; \n height: 6px; \n align-self: center; \n background-color: var(--background-color,var(--secondary-background-color));\n ";addStyles(this,V,customStyles);break;case"cover":const z=this.config.icon_open?this.config.icon_open:"mdi:window-shutter-open",B=this.config.icon_close?this.config.icon_close:"mdi:window-shutter",M=this.config.open_service?this.config.open_service:"cover.open_cover",H=this.config.close_service?this.config.close_service:"cover.close_cover",Y=this.config.stop_service?this.config.stop_service:"cover.stop_cover";if(icon="open"===hass.states[this.config.entity].state?z:B,formatedState=this.config.entity?hass.formatEntityState(hass.states[this.config.entity]):"",!this.coverAdded||editor){if(editor&&this.coverContainer)for(;this.coverContainer.firstChild;)this.coverContainer.removeChild(this.coverContainer.firstChild);this.coverContainer=document.createElement("div"),this.coverContainer.setAttribute("class","cover-container"),this.coverContainer.innerHTML=`\n
\n
\n
\n
\n

${name}

\n

${formatedState}

\n
\n
\n
\n \n \n \n
\n `,this.content.appendChild(this.coverContainer);const Yt=this.coverContainer.querySelector(".open"),qt=this.coverContainer.querySelector(".stop"),Ut=this.coverContainer.querySelector(".close");Yt.addEventListener("click",(()=>{hass.callService(M.split(".")[0],M.split(".")[1],{entity_id:entityId})})),qt.addEventListener("click",(()=>{hass.callService(Y.split(".")[0],Y.split(".")[1],{entity_id:entityId})})),Ut.addEventListener("click",(()=>{hass.callService(H.split(".")[0],H.split(".")[1],{entity_id:entityId})})),this.iconContainer=this.content.querySelector(".icon-container"),addActions(this,this.iconContainer),this.coverAdded=!0}this.iconContainer&&(this.iconContainer.innerHTML=``,this.content.querySelector(".state").textContent=formatedState);const q="\n ha-card {\n margin-top: 0 !important;\n background: none !important;\n }\n \n .header-container {\n display: flex;\n align-items: center;\n margin-bottom: 10px;\n }\n \n .cover-container {\n display: grid;\n }\n \n .icon-container {\n display: flex;\n margin: 0 !important;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n /*z-index: 1;*/\n width: 48px;\n height: 48px;\n margin: 6px;\n border-radius: 50%;\n background-color: var(--card-background-color,var(--ha-card-background));\n border: 6px solid var(--background-color-2,var(--secondary-background-color));\n box-sizing: border-box;\n }\n \n .name-container {\n font-weight: 600;\n margin-left: 10px;\n line-height: 4px;\n }\n \n .buttons-container {\n display: grid;\n align-self: center;\n grid-auto-flow: column;\n grid-gap: 18px; \n }\n \n .state {\n font-size: 12px;\n opacity: 0.7;\n }\n \n ha-icon {\n display: flex; \n height: 24px; \n width: 24px; \n color: var(--primary-text-color);\n }\n \n .button {\n display: flex;\n background: var(--background-color-2,var(--secondary-background-color));\n height: 42px;\n border-radius: 32px;\n align-items: center;\n justify-content: center;\n cursor: pointer;\n border: none;\n }\n ";addStyles(this,q,customStyles,state,entityId);break;case"empty-column":if(!this.emptyCollumnAdded){const Rt=document.createElement("div");Rt.setAttribute("class","empty-column"),Rt.innerHTML='\n
\n
\n ',this.content.appendChild(Rt),this.emptyColumnAdded=!0}}}setConfig(t){if("pop-up"===t.card_type){if(!t.hash)throw new Error("You need to define an hash. Please note that this card must be placed inside a vertical_stack to work as a pop-up.")}else if("horizontal-buttons-stack"===t.card_type){var e={};for(var n in t)if(n.match(/^\d+_icon$/)){var i=n.replace("_icon","_link");if(void 0===t[i])throw new Error("You need to define "+i);if(e[t[i]])throw new Error("You can't use "+t[i]+" twice");e[t[i]]=!0}}else if(("button"===t.card_type||"cover"===t.card_type)&&!t.entity)throw new Error("You need to define an entity");this.config=t}getCardSize(){return 1}static getConfigElement(){return document.createElement("bubble-card-editor")}}console.info(`%c Bubble Card %c ${version} `,"background-color: #555;color: #fff;padding: 3px 2px 3px 3px;border-radius: 14px 0 0 14px;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)","background-color: #506eac;color: #fff;padding: 3px 3px 3px 2px;border-radius: 0 14px 14px 0;font-family: DejaVu Sans,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)"),customElements.define("bubble-card",BubbleCard);const fireEvent=(t,e,n,i)=>{i=i||{},n=null==n?{}:n;const o=new Event(e,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return o.detail=n,t.dispatchEvent(o),o};customElements.get("ha-switch");const LitElement=Object.getPrototypeOf(customElements.get("ha-panel-lovelace")),html=LitElement.prototype.html,css=LitElement.prototype.css;class BubbleCardEditor extends LitElement{setConfig(t){this._config={...t}}static get properties(){return{hass:{},_config:{}}}get _card_type(){return this._config.card_type||""}get _button_type(){return this._config.button_type||"switch"}get _entity(){return this._config.entity||""}get _name(){return this._config.name||""}get _icon(){return this._config.icon||""}get _state(){return this._config.state||""}get _text(){return this._config.text||""}get _hash(){return this._config.hash||"#pop-up-name"}get _trigger_entity(){return this._config.trigger_entity||""}get _trigger_state(){return this._config.trigger_state||""}get _trigger_close(){return this._config.trigger_close||!1}get _margin(){return this._config.margin||"7px"}get _margin_top_mobile(){return this._config.margin_top_mobile||"0px"}get _margin_top_desktop(){return this._config.margin_top_desktop||"0px"}get _width_desktop(){return this._config.width_desktop||"540px"}get _bg_color(){return this._config.bg_color||window.color}get _bg_opacity(){return void 0!==this._config.bg_opacity?this._config.bg_opacity:"88"}get _bg_blur(){return void 0!==this._config.bg_blur?this._config.bg_blur:"14"}get _shadow_opacity(){return void 0!==this._config.shadow_opacity?this._config.shadow_opacity:"10"}get _is_sidebar_hidden(){return this._config.is_sidebar_hidden||!1}get _rise_animation(){return void 0===this._config.rise_animation||this._config.rise_animation}get _auto_close(){return this._config.auto_close||""}get _back_open(){return this._config.back_open||!1}get _icon_open(){return this._config.icon_open||""}get _icon_close(){return this._config.icon_close||""}get _open_service(){return this._config.open_service||"cover.open_cover"}get _close_service(){return this._config.open_service||"cover.close_cover"}get _stop_service(){return this._config.open_service||"cover.stop_cover"}get _auto_order(){return this._config.auto_order||!1}get _show_state(){return this._config.show_state||!1}render(){if(!this.hass)return html``;if(!this.listsUpdated){const t=t=>({label:t,value:t});this.allEntitiesList=Object.keys(this.hass.states).map(t),this.lightList=Object.keys(this.hass.states).filter((t=>"light"===t.substr(0,t.indexOf(".")))).map(t),this.sensorList=Object.keys(this.hass.states).filter((t=>"sensor"===t.substr(0,t.indexOf(".")))).map(t),this.binarySensorList=Object.keys(this.hass.states).filter((t=>"binary_sensor"===t.substr(0,t.indexOf(".")))).map(t),this.coverList=Object.keys(this.hass.states).filter((t=>"cover"===t.substr(0,t.indexOf(".")))).map(t),this.cardTypeList=[{label:"Button",value:"button"},{label:"Cover",value:"cover"},{label:"Empty column",value:"empty-column"},{label:"Horizontal buttons stack",value:"horizontal-buttons-stack"},{label:"Pop-up",value:"pop-up"},{label:"Separator",value:"separator"}],this.buttonTypeList=[{label:"Switch",value:"switch"},{label:"Slider",value:"slider"}],this.listsUpdated=!0}const t=this.allEntitiesList,e=(this.lightList,this.sensorList,this.coverList),n=this.cardTypeList,i=this.buttonTypeList;if("pop-up"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Pop-up

This card allows you to convert any vertical-stack into a pop-up. Each pop-up can be opened by targeting its link (e.g. '#pop-up-name'), with navigation_path or with the horizontal buttons stack that is included.

It must be placed within a vertical-stack card at the top most position to function properly. The pop-up will be hidden by default until you open it.
${this.makeDropdown("Optional - Icon","icon")} ${this.makeDropdown("Optional - Entity to toggle (e.g. room light group)","entity",t)} ${this.makeDropdown("Optional - Entity state to display (e.g. room temperature)","state",t)}

Pop-up trigger

This allows you to open this pop-up based on the state of any entity, for example you can open a "Security" pop-up with a camera when a person is in front of your house. You can also create a toggle helper (input_boolean) and trigger its opening/closing in an automation. ${this.makeDropdown("Optional - Entity to open the pop-up based on its state","trigger_entity",t)}

Styling options

Advanced settings

Back button/event support : This allow you to navigate through your pop-ups when you press the back button of your browser. This setting can be applied only once, you don't need to change it in all pop-ups. Beta users: This was the previous default behavior, set it to true to keep everything like before the update. ${this.makeVersion()}
`;if("button"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Button

This card can be a slider or a button, allowing you to toggle your entities, control the brightness of your lights and the volume of your media players. To access color / control of an entity, simply tap on the icon. ${this.makeDropdown("slider"!==this._button_type?"Entity (toggle)":"Entity (light or media_player)","entity",t)} ${this.makeDropdown("Button type","button_type",i)} ${this.makeDropdown("Optional - Icon","icon")}
${this.makeVersion()}
`;if("separator"===this._config.card_type)return html`
${this.makeDropdown("Card type","card_type",n)}

Separator

This card is a simple separator for dividing your pop-up into categories / sections. e.g. Lights, Devices, Covers, Settings, Automations... ${this.makeDropdown("Icon","icon")} ${this.makeVersion()}
`;if("horizontal-buttons-stack"===this._config.card_type){if(!this.buttonAdded&&this.shadowRoot.querySelector("#add-button")){const t=this.shadowRoot.querySelector("#add-button");for(this.buttonIndex=0;this._config[this.buttonIndex+1+"_link"];)this.buttonIndex++;t.addEventListener("click",(()=>{this.buttonIndex++;const e=t.style.opacity,n=t.innerText;t.style.opacity="0.6",t.style.transition="opacity 1s",t.innerText="Loading...",setTimeout((()=>{t.style.opacity=e,t.innerText=n}),5e3)})),this.buttonAdded=!0}return html`
${this.makeDropdown("Card type","card_type",n)}

Horizontal buttons stack

This card is the companion to the pop-up card, allowing you to open the corresponding pop-ups. It also allows you to open any page of your dashboard. In addition, you can add your motion sensors so that the order of the buttons adapts according to the room you just entered. This card is scrollable, remains visible and acts as a footer.

Please note that this card may take some time to load in edit mode.
${this.makeButton()}

Styling options

${this.makeVersion()}
`}return"cover"===this._config.card_type?html`
${this.makeDropdown("Card type","card_type",n)}

Cover

This card allows you to control your covers. ${this.makeDropdown("Entity","entity",e)} ${this.makeDropdown("Optional - Open icon","icon_open")} ${this.makeDropdown("Optional - Closed icon","icon_close")} ${this.makeVersion()}
`:"empty-column"===this._config.card_type?html`
${this.makeDropdown("Card type","card_type",n)}

Empty column

Just an empty card to fill any empty column. ${this.makeVersion()}
`:this._config.card_type?void 0:html`
${this.makeDropdown("Card type","card_type",n)} You need to add a card type first.

Almost everything is available in the GUI editor, but in the YAML editor you can add your own custom styles, create custom buttons or modify the tap actions of all cards. You can find more details on my GitHub page.

And if you like my project and want to support me, please consider making a donation. Any amount is welcome and very much appreciated! 🍻

${this.makeVersion()}
`}makeDropdown(t,e,n){this.hass;return t.includes("icon")||t.includes("Icon")?html`
`:html`
`}makeButton(){let t=[];for(let e=1;e<=this.buttonIndex;e++)t.push(html`
this.removeButton(e)}> Button ${e}
`);return t}makeVersion(){return html`

Bubble Card ${version}

`}removeButton(t){delete this._config[t+"_name"],delete this._config[t+"_icon"],delete this._config[t+"_link"],delete this._config[t+"_entity"],delete this._config[t+"_pir_sensor"];for(let e=t;e