Home-AssistantConfig/config/www/community/clock-weather-card/clock-weather-card.js

252 lines
295 KiB
JavaScript
Raw Normal View History

2024-07-26 13:58:13 +00:00
function e(e,t,i,r){var s,a=arguments.length,n=a<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(e,t,i,r);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(n=(a<3?s(n):a>3?s(t,i,n):s(t,i))||n);return a>3&&n&&Object.defineProperty(t,i,n),n}function t(e,t,i,r){return new(i||(i=Promise))((function(s,a){function n(e){try{l(r.next(e))}catch(e){a(e)}}function o(e){try{l(r.throw(e))}catch(e){a(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(n,o)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;
/**
* @license
* Copyright 2019 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const i=window,r=i.ShadowRoot&&(void 0===i.ShadyCSS||i.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,s=Symbol(),a=new WeakMap;let n=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==s)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if(r&&void 0===e){const i=void 0!==t&&1===t.length;i&&(e=a.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&a.set(t,e))}return e}toString(){return this.cssText}};const o=r?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return(e=>new n("string"==typeof e?e:e+"",void 0,s))(t)})(e):e
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/;var l;const c=window,d=c.trustedTypes,u=d?d.emptyScript:"",h=c.reactiveElementPolyfillSupport,m={toAttribute(e,t){switch(t){case Boolean:e=e?u:null;break;case Object:case Array:e=null==e?e:JSON.stringify(e)}return e},fromAttribute(e,t){let i=e;switch(t){case Boolean:i=null!==e;break;case Number:i=null===e?null:Number(e);break;case Object:case Array:try{i=JSON.parse(e)}catch(e){i=null}}return i}},f=(e,t)=>t!==e&&(t==t||e==e),p={attribute:!0,type:String,converter:m,reflect:!1,hasChanged:f},y="finalized";let b=class extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this._$Eu()}static addInitializer(e){var t;this.finalize(),(null!==(t=this.h)&&void 0!==t?t:this.h=[]).push(e)}static get observedAttributes(){this.finalize();const e=[];return this.elementProperties.forEach(((t,i)=>{const r=this._$Ep(i,t);void 0!==r&&(this._$Ev.set(r,i),e.push(r))})),e}static createProperty(e,t=p){if(t.state&&(t.attribute=!1),this.finalize(),this.elementProperties.set(e,t),!t.noAccessor&&!this.prototype.hasOwnProperty(e)){const i="symbol"==typeof e?Symbol():"__"+e,r=this.getPropertyDescriptor(e,i,t);void 0!==r&&Object.defineProperty(this.prototype,e,r)}}static getPropertyDescriptor(e,t,i){return{get(){return this[t]},set(r){const s=this[e];this[t]=r,this.requestUpdate(e,s,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(e){return this.elementProperties.get(e)||p}static finalize(){if(this.hasOwnProperty(y))return!1;this[y]=!0;const e=Object.getPrototypeOf(this);if(e.finalize(),void 0!==e.h&&(this.h=[...e.h]),this.elementProperties=new Map(e.elementProperties),this._$Ev=new Map,this.hasOwnProperty("properties")){const e=this.properties,t=[...Object.getOwnPropertyNames(e),...Object.getOwnPropertySymbols(e)];for(const i of t)this.createProperty(i,e[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(e){const t=[];if(Array.isArray(e)){const i=new Set(e.flat(1/0).reverse());for(const e of i)t.unshift(o(e))}else void 0!==e&&t.push(o(e));return t}static _$Ep(e,t){const i=t.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof e?e.toLowerCase():void 0}_$Eu(){var e;this._$E_=new Promise((e=>this.enableUpdating=e)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(e=this.constructor.h)||void 0===e||e.forEach((e=>e(this)))}addController(e){var t,i;(null!==(t=this._$ES)&&void 0!==t?t:this._$ES=[]).push(e),void 0!==this.renderRoot&&this.isConnected&&(null===(i=e.hostConnected)||void 0===i||i.call(e))}removeController(e){var t;null===(t=this._$ES)||void 0===t||t.splice(this._$ES.indexOf(e)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((e,t)=>{this.hasOwnProperty(t)&&(this._$Ei.set(t,this[t]),delete this[t])}))}createRenderRoot(){var e;const t=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,t)=>{r?e.adoptedStyleSheets=t.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet)):t.forEach((t=>{const r=document.createElement("style"),s=i.litNonce;void 0!==s&&r.setAttribute("nonce",s),r.textContent=t.cssText,e.appendChild(r)}))})(t,this.constructor.elementStyles),t}connectedCallback(){var e;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostConnected)||void 0===t?void 0:t.call(e)}))}enableUpdating(e){}disconnectedCallback(){var e;null===(e=this._$ES)||void 0===e||e.forEach((e=>{var t;return null===(t=e.hostDisconnected)||void 0===t?void 0:t.call(e)}))}attributeChangedCallback(e,t,i){this._$AK(e,i)}_$EO(e,t,i=p){var r;const s=this.constructor._$Ep(e,i);if(void 0!==s&&!0===i.reflect){const a=(void 0!==(null===(r=i.converter)||void 0===r?void 0:r.toAttribute)?i.converter:m).toAttribute(t,i.type);this._$El=e,null==a?this.removeAttribute(s):this.setAttribute(s,a),this._$El=null}}_$AK(e,t){var i;const r=this.constructor,s=r._$Ev.get(e);if(void 0!==s&&this._$El!==s){const e=r.getPropertyOptions(s),a="function"==typeof e.converter?{fromAttribute:e.conve
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
var g;b[y]=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==h||h({ReactiveElement:b}),(null!==(l=c.reactiveElementVersions)&&void 0!==l?l:c.reactiveElementVersions=[]).push("1.6.3");const w=window,v=w.trustedTypes,k=v?v.createPolicy("lit-html",{createHTML:e=>e}):void 0,x="$lit$",T=`lit$${(Math.random()+"").slice(9)}$`,M="?"+T,S=`<${M}>`,_=document,N=()=>_.createComment(""),O=e=>null===e||"object"!=typeof e&&"function"!=typeof e,A=Array.isArray,$="[ \t\n\f\r]",Z=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,C=/-->/g,B=/>/g,U=RegExp(`>|${$}(?:([^\\s"'>=/]+)(${$}*=${$}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),V=/'/g,G=/"/g,E=/^(?:script|style|textarea|title)$/i,D=(e=>(t,...i)=>({_$litType$:e,strings:t,values:i}))(1),j=Symbol.for("lit-noChange"),I=Symbol.for("lit-nothing"),z=new WeakMap,L=_.createTreeWalker(_,129,null,!1);function F(e,t){if(!Array.isArray(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==k?k.createHTML(t):t}const P=(e,t)=>{const i=e.length-1,r=[];let s,a=2===t?"<svg>":"",n=Z;for(let t=0;t<i;t++){const i=e[t];let o,l,c=-1,d=0;for(;d<i.length&&(n.lastIndex=d,l=n.exec(i),null!==l);)d=n.lastIndex,n===Z?"!--"===l[1]?n=C:void 0!==l[1]?n=B:void 0!==l[2]?(E.test(l[2])&&(s=RegExp("</"+l[2],"g")),n=U):void 0!==l[3]&&(n=U):n===U?">"===l[0]?(n=null!=s?s:Z,c=-1):void 0===l[1]?c=-2:(c=n.lastIndex-l[2].length,o=l[1],n=void 0===l[3]?U:'"'===l[3]?G:V):n===G||n===V?n=U:n===C||n===B?n=Z:(n=U,s=void 0);const u=n===U&&e[t+1].startsWith("/>")?" ":"";a+=n===Z?i+S:c>=0?(r.push(o),i.slice(0,c)+x+i.slice(c)+T+u):i+T+(-2===c?(r.push(void 0),t):u)}return[F(e,a+(e[i]||"<?>")+(2===t?"</svg>":"")),r]};class H{constructor({strings:e,_$litType$:t},i){let r;this.parts=[];let s=0,a=0;const n=e.length-1,o=this.parts,[l,c]=P(e,t);if(this.el=H.createElement(l,i),L.currentNode=this.el.content,2===t){const e=this.el.content,t=e.firstChild;t.remove(),e.append(...t.childNodes)}for(;null!==(r=L.nextNode())&&o.length<n;){if(1===r.nodeType){if(r.hasAttributes()){const e=[];for(const t of r.getAttributeNames())if(t.endsWith(x)||t.startsWith(T)){const i=c[a++];if(e.push(t),void 0!==i){const e=r.getAttribute(i.toLowerCase()+x).split(T),t=/([.?@])?(.*)/.exec(i);o.push({type:1,index:s,name:t[2],strings:e,ctor:"."===t[1]?J:"?"===t[1]?K:"@"===t[1]?X:Y})}else o.push({type:6,index:s})}for(const t of e)r.removeAttribute(t)}if(E.test(r.tagName)){const e=r.textContent.split(T),t=e.length-1;if(t>0){r.textContent=v?v.emptyScript:"";for(let i=0;i<t;i++)r.append(e[i],N()),L.nextNode(),o.push({type:2,index:++s});r.append(e[t],N())}}}else if(8===r.nodeType)if(r.data===M)o.push({type:2,index:s});else{let e=-1;for(;-1!==(e=r.data.indexOf(T,e+1));)o.push({type:7,index:s}),e+=T.length-1}s++}}static createElement(e,t){const i=_.createElement("template");return i.innerHTML=e,i}}function W(e,t,i=e,r){var s,a,n,o;if(t===j)return t;let l=void 0!==r?null===(s=i._$Co)||void 0===s?void 0:s[r]:i._$Cl;const c=O(t)?void 0:t._$litDirective$;return(null==l?void 0:l.constructor)!==c&&(null===(a=null==l?void 0:l._$AO)||void 0===a||a.call(l,!1),void 0===c?l=void 0:(l=new c(e),l._$AT(e,i,r)),void 0!==r?(null!==(n=(o=i)._$Co)&&void 0!==n?n:o._$Co=[])[r]=l:i._$Cl=l),void 0!==l&&(t=W(e,l._$AS(e,t.values),l,r)),t}class q{constructor(e,t){this._$AV=[],this._$AN=void 0,this._$AD=e,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(e){var t;const{el:{content:i},parts:r}=this._$AD,s=(null!==(t=null==e?void 0:e.creationScope)&&void 0!==t?t:_).importNode(i,!0);L.currentNode=s;let a=L.nextNode(),n=0,o=0,l=r[0];for(;void 0!==l;){if(n===l.index){let t;2===l.type?t=new R(a,a.nextSibling,this,e):1===l.type?t=new l.ctor(a,l.name,l.strings,this,e):6===l.type&&(t=new ee(a,this,e)),this._$AV.push(t),l=r[++o]}n!==(null==l?void 0:l.index)&&(a=L.nextNode(),n++)}return L.currentNode=_,s}v(e){let t=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(e,i,t),t+=i.strings.length-2):i._$AI(e[t])),t++}}class R{constructor(e,t,i,r){var s;this.type=2,this._$AH=I,this._$AN=void
2024-07-26 13:58:13 +00:00
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
var ie,re;let se=class extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var e,t;const i=super.createRenderRoot();return null!==(e=(t=this.renderOptions).renderBefore)&&void 0!==e||(t.renderBefore=i.firstChild),i}update(e){const t=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(e),this._$Do=((e,t,i)=>{var r,s;const a=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:t;let n=a._$litPart$;if(void 0===n){const e=null!==(s=null==i?void 0:i.renderBefore)&&void 0!==s?s:null;a._$litPart$=n=new R(t.insertBefore(N(),e),e,void 0,null!=i?i:{})}return n._$AI(e),n})(t,this.renderRoot,this.renderOptions)}connectedCallback(){var e;super.connectedCallback(),null===(e=this._$Do)||void 0===e||e.setConnected(!0)}disconnectedCallback(){var e;super.disconnectedCallback(),null===(e=this._$Do)||void 0===e||e.setConnected(!1)}render(){return j}};se.finalized=!0,se._$litElement$=!0,null===(ie=globalThis.litElementHydrateSupport)||void 0===ie||ie.call(globalThis,{LitElement:se});const ae=globalThis.litElementPolyfillSupport;null==ae||ae({LitElement:se}),(null!==(re=globalThis.litElementVersions)&&void 0!==re?re:globalThis.litElementVersions=[]).push("3.3.3");
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
const ne=(e,t)=>"method"===t.kind&&t.descriptor&&!("value"in t.descriptor)?{...t,finisher(i){i.createProperty(t.key,e)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:t.key,initializer(){"function"==typeof t.initializer&&(this[t.key]=t.initializer.call(this))},finisher(i){i.createProperty(t.key,e)}},oe=(e,t,i)=>{t.constructor.createProperty(i,e)};
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/function le(e){return(t,i)=>void 0!==i?oe(e,t,i):ne(e,t)
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/}function ce(e){return le({...e,state:!0})}
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/var de,ue,he;null===(de=window.HTMLSlotElement)||void 0===de||de.prototype.assignedElements,function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(ue||(ue={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(he||(he={}));var me=["closed","locked","off"],fe=function(e,t,i,r){r=r||{},i=null==i?{}:i;var s=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return s.detail=i,e.dispatchEvent(s),s},pe=function(e){fe(window,"haptic",e)},ye=function(e,t,i,r){if(r||(r={action:"more-info"}),!r.confirmation||r.confirmation.exemptions&&r.confirmation.exemptions.some((function(e){return e.user===t.user.id}))||(pe("warning"),confirm(r.confirmation.text||"Are you sure you want to "+r.action+"?")))switch(r.action){case"more-info":(i.entity||i.camera_image)&&fe(e,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":r.navigation_path&&function(e,t,i){void 0===i&&(i=!1),i?history.replaceState(null,"",t):history.pushState(null,"",t),fe(window,"location-changed",{replace:i})}(0,r.navigation_path);break;case"url":r.url_path&&window.open(r.url_path);break;case"toggle":i.entity&&(function(e,t){(function(e,t,i){void 0===i&&(i=!0);var r,s=function(e){return e.substr(0,e.indexOf("."))}(t),a="group"===s?"homeassistant":s;switch(s){case"lock":r=i?"unlock":"lock";break;case"cover":r=i?"open_cover":"close_cover";break;default:r=i?"turn_on":"turn_off"}e.callService(a,r,{entity_id:t})})(e,t,me.includes(e.states[t].state))}(t,i.entity),pe("success"));break;case"call-service":if(!r.service)return void pe("failure");var s=r.service.split(".",2);t.callService(s[0],s[1],r.service_data,r.target),pe("success");break;case"fire-dom-event":fe(e,"ll-custom",r)}};function be(e){return void 0!==e&&"none"!==e.action}class ge{constructor(e,t,i){this.r=e,this.g=t,this.b=i}toRgbString(){return`rgb(${this.r}, ${this.g}, ${this.b})`}}var we=((e,...t)=>{const i=1===e.length?e[0]:t.reduce(((t,i,r)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+e[r+1]),e[0]);return new n(i,e,s)})`
ha-card {
--bar-height: 1.5rem;
height: 100%;
}
clock-weather-card-today {
display: flex;
}
clock-weather-card-today-left {
display: flex;
width: 35%;
align-items: center;
justify-content: center;
}
.grow-img {
max-width: 100%;
max-height: 100%;
}
clock-weather-card-today-right {
display: flex;
width: 65%;
justify-content: space-around;
align-items: center;
}
clock-weather-card-today-right-wrap {
display: flex;
flex-direction: column;
}
clock-weather-card-today-right-wrap-top {
width: 100%;
text-align: end;
display: block;
}
clock-weather-card-today-right-wrap-center {
display: flex;
height: 4rem;
font-size: 3.5rem;
white-space: nowrap;
align-items: center;
justify-content: center;
}
clock-weather-card-today-right-wrap-bottom {
display: flex;
justify-content: start;
}
clock-weather-card-forecast {
display: block;
}
clock-weather-card-forecast-row {
display: grid;
grid-template-columns: var(--col-one-size) 2rem 2.1rem auto 2.1rem;
align-items: center;
grid-gap: 0.5rem;
}
forecast-text {
text-align: var(--text-align);
white-space: nowrap;
text-overflow: clip;
}
forecast-icon {
display: flex;
align-items: center;
justify-content: center;
}
forecast-temperature-bar {
position: relative;
width: 100%;
height: var(--bar-height);
border-radius: calc(var(--bar-height) / 2);
overflow: hidden;
}
forecast-temperature-bar-background {
left: 0%;
right: 100%;
width: 100%;
opacity: 0.25;
background: var(--light-primary-color);
}
forecast-temperature-bar-current-indicator-dot {
--border-width: 2px;
background-color: var(--primary-text-color);
border-radius: 50%;
width: var(--bar-height);
box-shadow: inset 0 0 0 var(--border-width) var(--text-light-primary-color);
margin-left: calc(var(--move-right) * -1 * var(--bar-height));
}
forecast-temperature-bar-range {
border-radius: calc(var(--bar-height) / 2);
left: var(--start-percent);
right: calc(100% - var(--end-percent));
background: linear-gradient(to right, var(--gradient));
overflow: hidden;
min-width: var(--bar-height);
margin-left: calc(var(--move-right) * -1 * var(--bar-height));
}
forecast-temperature-bar-current-indicator {
opacity: 0.75;
left: var(--position);
}
forecast-temperature-bar-current-indicator,
forecast-temperature-bar-current-indicator-dot,
forecast-temperature-bar-background,
forecast-temperature-bar-range {
height: 100%;
position: absolute;
}
aqi {
padding: 2px;
border-radius: 5px;
}
`
/**
* @license
* Copyright 2017 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/;class ve{constructor(e){}get _$AU(){return this._$AM._$AU}_$AT(e,t,i){this._$Ct=e,this._$AM=t,this._$Ci=i}_$AS(e,t){return this.update(e,t)}update(e,t){return this.render(...t)}}const ke="ontouchstart"in window||navigator.maxTouchPoints>0||navigator.maxTouchPoints>0;class xe extends HTMLElement{constructor(){super(),this.holdTime=500,this.held=!1,this.ripple=document.createElement("mwc-ripple")}connectedCallback(){Object.assign(this.style,{position:"absolute",width:ke?"100px":"50px",height:ke?"100px":"50px",transform:"translate(-50%, -50%)",pointerEvents:"none",zIndex:"999"}),this.appendChild(this.ripple),this.ripple.primary=!0,["touchcancel","mouseout","mouseup","touchmove","mousewheel","wheel","scroll"].forEach((e=>{document.addEventListener(e,(()=>{clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0}),{passive:!0})}))}bind(e,t){if(e.actionHandler)return;e.actionHandler=!0,e.addEventListener("contextmenu",(e=>{const t=e||window.event;return t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble=!0,t.returnValue=!1,!1}));const i=e=>{var t,i;this.held=!1;const r=null!==(t=e.pageX)&&void 0!==t?t:e.touches[0].pageX,s=null!==(i=e.pageY)&&void 0!==i?i:e.touches[0].pageY;this.timer=window.setTimeout((()=>{this.startAnimation(r,s),this.held=!0}),this.holdTime)},r=i=>{i.preventDefault(),["touchend","touchcancel"].includes(i.type)&&void 0===this.timer||(clearTimeout(this.timer),this.stopAnimation(),this.timer=void 0,this.held?fe(e,"action",{action:"hold"}):t.hasDoubleClick?"click"===i.type&&i.detail<2||!this.dblClickTimeout?this.dblClickTimeout=window.setTimeout((()=>{this.dblClickTimeout=void 0,fe(e,"action",{action:"tap"})}),250):(clearTimeout(this.dblClickTimeout),this.dblClickTimeout=void 0,fe(e,"action",{action:"double_tap"})):fe(e,"action",{action:"tap"}))};e.addEventListener("touchstart",i,{passive:!0}),e.addEventListener("touchend",r),e.addEventListener("touchcancel",r),e.addEventListener("mousedown",i,{passive:!0}),e.addEventListener("click",r),e.addEventListener("keyup",(e=>{13===e.keyCode&&r(e)}))}startAnimation(e,t){Object.assign(this.style,{left:`${e}px`,top:`${t}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.get("action-handler-clock-weather")||customElements.define("action-handler-clock-weather",xe);const Te=(e,t)=>{const i=(()=>{const e=document.body;if(e.querySelector("action-handler-clock-weather"))return e.querySelector("action-handler-clock-weather");const t=document.createElement("action-handler-clock-weather");return e.appendChild(t),t})();i&&i.bind(e,t)},Me=(e=>(...t)=>({_$litDirective$:e,values:t}))(class extends ve{update(e,[t]){return Te(e.element,t),j}render(e){}});var Se={"clear-night":"Ясно",cloudy:"Облачно",fog:"Мъгла",hail:"Градушка",lightning:"Гръмотевични бури","lightning-rainy":"Дъждовни гръмотевични бури",partlycloudy:"Частична облачност",pouring:"Пороен дъжд",rainy:"Дъждовно",snowy:"Сняг","snowy-rainy":"Суграшица",sunny:"Слънчево",windy:"Ветровито","windy-variant":"Силен вятър",exceptional:"Изключително"},_e={1:"Пн",2:"Вт",3:"Ср",4:"Чт",5:"Пт",6:"Сб",7:"Нд"},Ne={aqi:"AQI",humidity:"Влажност","feels-like":"Усеща се като"},Oe={weather:Se,day:_e,misc:Ne},Ae=Object.freeze({__proto__:null,day:_e,default:Oe,misc:Ne,weather:Se}),$e={"clear-night":"Klart",cloudy:"Overskyet",fog:"Tåge",hail:"Hagl",lightning:"Lyn","lightning-rainy":"Lyn ,regnvejr",partlycloudy:"Delvis overskyet",pouring:"Regnvejr",rainy:"Regnfuldt",snowy:"Sne","snowy-rainy":"Slud",sunny:"Solrig",windy:"Blæsende","windy-variant":"Stærk vind",exceptional:"Kaos"},Ze={1:"Man",2:"Tir",3:"Ons",4:"Tor",5:"Fre",6:"Lør",7:"Søn"},Ce={aqi:"AQI",humidity:"fugtighed","feels-like":"Feels like"},Be={weather:$e,day:Ze,misc:Ce},Ue=Object.freeze({__proto__:null,day:Ze,defa
2024-07-26 13:58:13 +00:00
<ha-card
@action=${e=>{this.handleAction(e)}}
.actionHandler=${Me({hasHold:be(this.config.hold_action),hasDoubleClick:be(this.config.double_tap_action)})}
tabindex="0"
.label=${`Clock Weather Card: ${this.config.entity||"No Entity Defined"}`}
>
${this.config.title?D`
<div class="card-header">
${this.config.title}
</div>`:""}
<div class="card-content">
${e?D`
<clock-weather-card-today>
${Dr((()=>this.renderToday()))}
2024-07-26 13:58:13 +00:00
</clock-weather-card-today>`:""}
${t?D`
<clock-weather-card-forecast>
${Dr((()=>this.renderForecast()))}
2024-07-26 13:58:13 +00:00
</clock-weather-card-forecast>`:""}
</div>
</ha-card>
`}connectedCallback(){super.connectedCallback(),this.hasUpdated&&this.subscribeForecastEvents()}disconnectedCallback(){super.disconnectedCallback(),this.unsubscribeForecastEvents()}willUpdate(e){super.willUpdate(e),this.forecastSubscriber||this.subscribeForecastEvents()}renderToday(){const e=this.getWeather(),t=e.state,i=this.config.show_decimal?this.getCurrentTemperature():Tr(this.getCurrentTemperature()),r=e.attributes.temperature_unit,s=this.config.show_decimal?this.getApparentTemperature():Tr(this.getApparentTemperature()),a=this.getAqi(),n=this.getAqiColor(a),o=Tr(this.getCurrentHumidity()),l=this.config.weather_icon_type,c=this.toIcon(t,l,!1,this.getIconAnimationKind()),d=this.localize(`weather.${t}`),u=null!==i?this.toConfiguredTempWithUnit(r,i):null,h=null!==o?`${o}% ${this.localize("misc.humidity")}`:null,m=null!==s?this.toConfiguredTempWithUnit(r,s):null,f=this.localize("misc.feels-like"),p=this.localize("misc.aqi");return D`
2024-07-26 13:58:13 +00:00
<clock-weather-card-today-left>
<img class="grow-img" src=${c} />
</clock-weather-card-today-left>
<clock-weather-card-today-right>
<clock-weather-card-today-right-wrap>
<clock-weather-card-today-right-wrap-top>
${this.config.hide_clock?d:u?`${d}, ${u}`:d}
${this.config.show_humidity&&h?D`<br>${h}`:""}
${this.config.apparent_sensor&&s?D`<br>${f}: ${m}`:""}
${this.config.aqi_sensor&&null!==a?D`<br><aqi style="background-color: ${n}">${a} ${p}</aqi>`:""}
</clock-weather-card-today-right-wrap-top>
<clock-weather-card-today-right-wrap-center>
${this.config.hide_clock?null!=u?u:"n/a":this.time()}
</clock-weather-card-today-right-wrap-center>
<clock-weather-card-today-right-wrap-bottom>
${this.config.hide_date?"":this.date()}
</clock-weather-card-today-right-wrap-bottom>
</clock-weather-card-today-right-wrap>
</clock-weather-card-today-right>`}renderForecast(){const e=this.getWeather(),t=Tr(this.getCurrentTemperature()),i=this.config.forecast_rows,r=this.config.hourly_forecast,s=e.attributes.temperature_unit,a=this.mergeForecasts(i,r),n=a.map((e=>e.templow)),o=a.map((e=>e.temperature));null!==t&&(n.push(t),o.push(t));const l=Math.round(vr(n)),c=Math.round(wr(o)),d=this.gradientRange(l,c,s),u=a.map((e=>e.datetime)).map((e=>r?this.time(e):this.localize(`day.${e.weekday}`))),h=u.length?wr(u.map((e=>e.length))):0;return a.map(((e,i)=>Dr((()=>this.renderForecastItem(e,d,l,c,t,r,u[i],h)))))}renderForecastItem(e,t,i,r,s,a,n,o){const l="pouring"===e.condition?"raindrops":"rainy"===e.condition?"raindrop":e.condition,c=this.toIcon(l,"fill",!0,"static"),d=this.getWeather().attributes.temperature_unit,u=a?Ko.now().hour===e.datetime.hour:Ko.now().day===e.datetime.day,h=Math.round(u&&null!==s?Math.min(s,e.templow):e.templow),m=Math.round(u&&null!==s?Math.max(s,e.temperature):e.temperature);return D`
2024-07-26 13:58:13 +00:00
<clock-weather-card-forecast-row style="--col-one-size: ${.5*o}rem;">
${this.renderText(n)}
${this.renderIcon(c)}
${this.renderText(this.toConfiguredTempWithUnit(d,h),"right")}
${this.renderForecastTemperatureBar(t,i,r,h,m,u,s)}
${this.renderText(this.toConfiguredTempWithUnit(d,m))}
</clock-weather-card-forecast-row>
`}renderText(e,t="left"){return D`
<forecast-text style="--text-align: ${t};">
${e}
</forecast-text>
`}renderIcon(e){return D`
<forecast-icon>
<img class="grow-img" src=${e} />
</forecast-icon>
`}renderForecastTemperatureBar(e,t,i,r,s,a,n){const{startPercent:o,endPercent:l}=this.calculateBarRangePercents(t,i,r,s);return D`
<forecast-temperature-bar>
<forecast-temperature-bar-background> </forecast-temperature-bar-background>
<forecast-temperature-bar-range
style="--move-right: ${i===t?0:(r-t)/(i-t)}; --start-percent: ${o}%; --end-percent: ${l}%; --gradient: ${this.gradient(e,o,l)};"
>
${a?this.renderForecastCurrentTemp(r,s,n):""}
</forecast-temperature-bar-range>
</forecast-temperature-bar>
`}renderForecastCurrentTemp(e,t,i){if(null==i)return D``;return D`
<forecast-temperature-bar-current-indicator style="--position: ${e===t?0:100/(t-e)*(i-e)}%;">
<forecast-temperature-bar-current-indicator-dot style="--move-right: ${t===e?0:(i-e)/(t-e)}">
</forecast-temperature-bar-current-indicator-dot>
</forecast-temperature-bar-current-indicator>
`}static get styles(){return we}gradientRange(e,t,i){const r=this.toCelsius(i,e),s=this.toCelsius(i,t),a=Math.max(function(e,t=0){return t<=0?Math.floor(e):Math.floor(e/t)*t}(r,10),vr([...el.keys()])),n=Math.min(xr(s,10),wr([...el.keys()]));return Array.from(el.keys()).filter((e=>e>=a&&e<=n)).map((e=>el.get(e)))}gradient(e,t,i){var r;if(e.length<=1){const t=null!==(r=e[0])&&void 0!==r?r:new ge(255,255,255);return[t,t].map((e=>e.toRgbString())).join(",")}const[s,a]=this.calculateRgb(e,t,"left"),[n,o]=this.calculateRgb(e,i,"right");return[s,...e.slice(a+1,o),n].map((e=>e.toRgbString())).join(",")}calculateRgb(e,t,i){function r(e,t,i){const r=Math.abs(e-t)/100*i;return kr(e>t?e-r:e+r)}const s=100/(e.length-1),a=t/s,n=Math.round(a),o=100/s*(t-n*s),l=0===o?n:o<0?n-1:n+1,c=function(e,t,i,s){const a=s[e],n=s[t],o=i<0?100+i:i,l=i<0?n:a,c=i<0?a:n,d=r(l.r,c.r,o),u=r(l.g,c.g,o),h=r(l.b,c.b,o);return new ge(d,u,h)}(n,l,o,e);return[c,"left"===i?Math.min(n,l):Math.max(n,l)]}handleAction(e){this.hass&&this.config&&e.detail.action&&function(e,t,i,r){var s;"double_tap"===r&&i.double_tap_action?s=i.double_tap_action:"hold"===r&&i.hold_action?s=i.hold_action:"tap"===r&&i.tap_action&&(s=i.tap_action),ye(e,t,i,s)}(this,this.hass,this.config,e.detail.action)}mergeConfig(e){var t,i,r,s,a,n,o,l,c,d,u,h,m,f,p,y,b,g;return Object.assign(Object.assign({},e),{sun_entity:null!==(t=e.sun_entity)&&void 0!==t?t:"sun.sun",temperature_sensor:e.temperature_sensor,humidity_sensor:e.humidity_sensor,weather_icon_type:null!==(i=e.weather_icon_type)&&void 0!==i?i:"line",forecast_rows:null!==(r=e.forecast_rows)&&void 0!==r?r:5,hourly_forecast:null!==(s=e.hourly_forecast)&&void 0!==s&&s,animated_icon:null===(a=e.animated_icon)||void 0===a||a,time_format:null===(n=e.time_format)||void 0===n?void 0:n.toString(),time_pattern:null!==(o=e.time_pattern)&&void 0!==o?o:void 0,show_humidity:null!==(l=e.show_humidity)&&void 0!==l&&l,hide_forecast_section:null!==(c=e.hide_forecast_section)&&void 0!==c&&c,hide_today_section:null!==(d=e.hide_today_section)&&void 0!==d&&d,hide_clock:null!==(u=e.hide_clock)&&void 0!==u&&u,hide_date:null!==(h=e.hide_date)&&void 0!==h&&h,date_pattern:null!==(m=e.date_pattern)&&void 0!==m?m:"D",use_browser_time:null!==(f=e.use_browser_time)&&void 0!==f&&f,time_zone:null!==(p=e.time_zone)&&void 0!==p?p:void 0,show_decimal:null!==(y=e.show_decimal)&&void 0!==y&&y,apparent_sensor:null!==(b=e.apparent_sensor)&&void 0!==b?b:void 0,aqi_sensor:null!==(g=e.aqi_sensor)&&void 0!==g?g:void 0})}toIcon(e,t,i,r){var s;const a=i?"day":"below_horizon"===(null===(s=this.getSun())||void 0===s?void 0:s.state)?"night":"day",n=("animated"===r?Gr:Er)[t][e];return(null==n?void 0:n[a])||n}getWeather(){const e=this.hass.states[this.config.entity];if(!e)throw this.createError(`Weather entity "${this.config.entity}" could not be found.`);return e}getCurrentTemperature(){var e,t;if(this.config.temperature_sensor){const t=this.hass.states[this.config.temperature_sensor],i=(null==t?void 0:t.state)?parseFloat(t.state):void 0,r=null!==(e=null==t?void 0:t.attributes.unit_of_measurement)&&void 0!==e?e:this.getConfiguredTemperatureUnit();if(void 0!==i&&!isNaN(i))return this.toConfiguredTempWithoutUnit(r,i)}return null!==(t=this.getWeather().attributes.temperature)&&void 0!==t?t:null}getCurrentHumidity(){var e;if(this.config.humidity_sensor){const e=this.hass.states[this.config.humidity_sensor],t=(null==e?void 0:e.state)?parseFloat(e.state):void 0;if(void 0!==t&&!isNaN(t))return t}return null!==(e=this.getWeather().attributes.humidity)&&void 0!==e?e:null}getApparentTemperature(){var e;if(this.config.apparent_sensor){const t=this.hass.states[this.config.apparent_sensor],i=(null==t?void 0:t.state)?parseFloat(t.state):void 0,r=null!==(e=null==t?void 0:t.attributes.unit_of_measurement)&&void 0!==e?e:this.getConfiguredTemperatureUnit();if(void 0!==i&&!isNaN(i))return this.toConfiguredTempWithoutUnit(r,i)}return null}getAqi(){if(this.config.aqi_sensor){const e=this.hass.states[this.config.aqi_sensor],t=(null==e?void 0:e.state)?parseInt(e.state):void 0;if(void 0!==t&&!isNaN(t))return