/** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ const t="undefined"!=typeof window&&null!=window.customElements&&void 0!==window.customElements.polyfillWrapFlushCallback,e=(t,e,s=null,i=null)=>{for(;e!==s;){const s=e.nextSibling;t.insertBefore(e,i),e=s}},s=(t,e,s=null)=>{for(;e!==s;){const s=e.nextSibling;t.removeChild(e),e=s}},i=`{{lit-${String(Math.random()).slice(2)}}}`,o=`\x3c!--${i}--\x3e`,a=new RegExp(`${i}|${o}`),n="$lit$";class r{constructor(t,e){this.parts=[],this.element=e;const s=[],o=[],r=document.createTreeWalker(e.content,133,null,!1);let l=0,g=-1,u=0;const{strings:m,values:{length:p}}=t;for(;u0;){const e=m[u],s=d.exec(e)[2],i=s.toLowerCase()+n,o=t.getAttribute(i);t.removeAttribute(i);const r=o.split(a);this.parts.push({type:"attribute",index:g,name:s,strings:r}),u+=r.length-1}}"TEMPLATE"===t.tagName&&(o.push(t),r.currentNode=t.content)}else if(3===t.nodeType){const e=t.data;if(e.indexOf(i)>=0){const i=t.parentNode,o=e.split(a),r=o.length-1;for(let e=0;e{const s=t.length-e.length;return s>=0&&t.slice(s)===e},l=t=>-1!==t.index,c=()=>document.createComment(""),d=/([ \x09\x0a\x0c\x0d])([^\0-\x1F\x7F-\x9F "'>=/]+)([ \x09\x0a\x0c\x0d]*=[ \x09\x0a\x0c\x0d]*(?:[^ \x09\x0a\x0c\x0d"'`<>=]*|"[^"]*|'[^']*))$/;function g(t,e){const{element:{content:s},parts:i}=t,o=document.createTreeWalker(s,133,null,!1);let a=m(i),n=i[a],r=-1,h=0;const l=[];let c=null;for(;o.nextNode();){r++;const t=o.currentNode;for(t.previousSibling===c&&(c=null),e.has(t)&&(l.push(t),null===c&&(c=t)),null!==c&&h++;void 0!==n&&n.index===r;)n.index=null!==c?-1:n.index-h,a=m(i,a),n=i[a]}l.forEach((t=>t.parentNode.removeChild(t)))}const u=t=>{let e=11===t.nodeType?0:1;const s=document.createTreeWalker(t,133,null,!1);for(;s.nextNode();)e++;return e},m=(t,e=-1)=>{for(let s=e+1;s(...e)=>{const s=t(...e);return p.set(s,!0),s},f=t=>"function"==typeof t&&p.has(t),y={},_={}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ class b{constructor(t,e,s){this.__parts=[],this.template=t,this.processor=e,this.options=s}update(t){let e=0;for(const s of this.__parts)void 0!==s&&s.setValue(t[e]),e++;for(const s of this.__parts)void 0!==s&&s.commit()}_clone(){const e=t?this.template.element.content.cloneNode(!0):document.importNode(this.template.element.content,!0),s=[],i=this.template.parts,o=document.createTreeWalker(e,133,null,!1);let a,n=0,r=0,h=o.nextNode();for(;nt}),x=` ${i} `;class S{constructor(t,e,s,i){this.strings=t,this.values=e,this.type=s,this.processor=i}getHTML(){const t=this.strings.length-1;let e="",s=!1;for(let a=0;a-1||s)&&-1===t.indexOf("--\x3e",r+1);const h=d.exec(t);e+=null===h?t+(s?x:o):t.substr(0,h.index)+h[1]+h[2]+n+h[3]+i}return e+=this.strings[t],e}getTemplateElement(){const t=document.createElement("template");let e=this.getHTML();return void 0!==w&&(e=w.createHTML(e)),t.innerHTML=e,t}}class $ extends S{getHTML(){return`${super.getHTML()}`}getTemplateElement(){const t=super.getTemplateElement(),s=t.content,i=s.firstChild;return s.removeChild(i),e(s,i.firstChild),t}} /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */const k=t=>null===t||!("object"==typeof t||"function"==typeof t),E=t=>Array.isArray(t)||!(!t||!t[Symbol.iterator]);class C{constructor(t,e,s){this.dirty=!0,this.element=t,this.name=e,this.strings=s,this.parts=[];for(let i=0;i{try{const t={get capture(){return N=!0,!1}};window.addEventListener("test",t,t),window.removeEventListener("test",t,t)}catch(t){}})();class D{constructor(t,e,s){this.value=void 0,this.__pendingValue=void 0,this.element=t,this.eventName=e,this.eventContext=s,this.__boundHandleEvent=t=>this.handleEvent(t)}setValue(t){this.__pendingValue=t}commit(){for(;f(this.__pendingValue);){const t=this.__pendingValue;this.__pendingValue=y,t(this)}if(this.__pendingValue===y)return;const t=this.__pendingValue,e=this.value,s=null==t||null!=e&&(t.capture!==e.capture||t.once!==e.once||t.passive!==e.passive),i=null!=t&&(null==e||s);s&&this.element.removeEventListener(this.eventName,this.__boundHandleEvent,this.__options),i&&(this.__options=P(t),this.element.addEventListener(this.eventName,this.__boundHandleEvent,this.__options)),this.value=t,this.__pendingValue=y}handleEvent(t){"function"==typeof this.value?this.value.call(this.eventContext||this.element,t):this.value.handleEvent(t)}}const P=t=>t&&(N?{capture:t.capture,passive:t.passive,once:t.once}:t.capture) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */;function O(t){let e=R.get(t.type);void 0===e&&(e={stringsArray:new WeakMap,keyString:new Map},R.set(t.type,e));let s=e.stringsArray.get(t.strings);if(void 0!==s)return s;const o=t.strings.join(i);return s=e.keyString.get(o),void 0===s&&(s=new r(t,t.getTemplateElement()),e.keyString.set(o,s)),e.stringsArray.set(t.strings,s),s}const R=new Map,L=new WeakMap; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */const z=new /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ class{handleAttributeExpressions(t,e,s,i){const o=e[0];if("."===o){return new M(t,e.slice(1),s).parts}if("@"===o)return[new D(t,e.slice(1),i.eventContext)];if("?"===o)return[new A(t,e.slice(1),s)];return new C(t,e,s).parts}handleTextExpression(t){return new T(t)}}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */"undefined"!=typeof window&&(window.litHtmlVersions||(window.litHtmlVersions=[])).push("1.4.1");const F=(t,...e)=>new S(t,e,"html",z),U=(t,...e)=>new $(t,e,"svg",z) /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */,B=(t,e)=>`${t}--${e}`;let j=!0;void 0===window.ShadyCSS?j=!1:void 0===window.ShadyCSS.prepareTemplateDom&&(console.warn("Incompatible ShadyCSS version detected. Please update to at least @webcomponents/webcomponentsjs@2.0.2 and @webcomponents/shadycss@1.3.1."),j=!1);const q=t=>e=>{const s=B(e.type,t);let o=R.get(s);void 0===o&&(o={stringsArray:new WeakMap,keyString:new Map},R.set(s,o));let a=o.stringsArray.get(e.strings);if(void 0!==a)return a;const n=e.strings.join(i);if(a=o.keyString.get(n),void 0===a){const s=e.getTemplateElement();j&&window.ShadyCSS.prepareTemplateDom(s,t),a=new r(e,s),o.keyString.set(n,a)}return o.stringsArray.set(e.strings,a),a},H=["html","svg"],G=new Set,W=(t,e,s)=>{G.add(t);const i=s?s.element:document.createElement("template"),o=e.querySelectorAll("style"),{length:a}=o;if(0===a)return void window.ShadyCSS.prepareTemplateStyles(i,t);const n=document.createElement("style");for(let l=0;l{H.forEach((e=>{const s=R.get(B(e,t));void 0!==s&&s.keyString.forEach((t=>{const{element:{content:e}}=t,s=new Set;Array.from(e.querySelectorAll("style")).forEach((t=>{s.add(t)})),g(t,s)}))}))})(t);const r=i.content;s?function(t,e,s=null){const{element:{content:i},parts:o}=t;if(null==s)return void i.appendChild(e);const a=document.createTreeWalker(i,133,null,!1);let n=m(o),r=0,h=-1;for(;a.nextNode();)for(h++,a.currentNode===s&&(r=u(e),s.parentNode.insertBefore(e,s));-1!==n&&o[n].index===h;){if(r>0){for(;-1!==n;)o[n].index+=r,n=m(o,n);return}n=m(o,n)}}(s,n,r.firstChild):r.insertBefore(n,r.firstChild),window.ShadyCSS.prepareTemplateStyles(i,t);const h=r.querySelector("style");if(window.ShadyCSS.nativeShadow&&null!==h)e.insertBefore(h.cloneNode(!0),e.firstChild);else if(s){r.insertBefore(n,r.firstChild);const t=new Set;t.add(n),g(s,t)}};window.JSCompiler_renameProperty=(t,e)=>t;const J={toAttribute(t,e){switch(e){case Boolean:return t?"":null;case Object:case Array:return null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){switch(e){case Boolean:return null!==t;case Number:return null===t?null:Number(t);case Object:case Array:return JSON.parse(t)}return t}},Y=(t,e)=>e!==t&&(e==e||t==t),X={attribute:!0,type:String,converter:J,reflect:!1,hasChanged:Y},Z="finalized";class K extends HTMLElement{constructor(){super(),this.initialize()}static get observedAttributes(){this.finalize();const t=[];return this._classProperties.forEach(((e,s)=>{const i=this._attributeNameForProperty(s,e);void 0!==i&&(this._attributeToPropertyMap.set(i,s),t.push(i))})),t}static _ensureClassProperties(){if(!this.hasOwnProperty(JSCompiler_renameProperty("_classProperties",this))){this._classProperties=new Map;const t=Object.getPrototypeOf(this)._classProperties;void 0!==t&&t.forEach(((t,e)=>this._classProperties.set(e,t)))}}static createProperty(t,e=X){if(this._ensureClassProperties(),this._classProperties.set(t,e),e.noAccessor||this.prototype.hasOwnProperty(t))return;const s="symbol"==typeof t?Symbol():`__${t}`,i=this.getPropertyDescriptor(t,s,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}static getPropertyDescriptor(t,e,s){return{get(){return this[e]},set(i){const o=this[t];this[e]=i,this.requestUpdateInternal(t,o,s)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this._classProperties&&this._classProperties.get(t)||X}static finalize(){const t=Object.getPrototypeOf(this);if(t.hasOwnProperty(Z)||t.finalize(),this[Z]=!0,this._ensureClassProperties(),this._attributeToPropertyMap=new Map,this.hasOwnProperty(JSCompiler_renameProperty("properties",this))){const t=this.properties,e=[...Object.getOwnPropertyNames(t),..."function"==typeof Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(t):[]];for(const s of e)this.createProperty(s,t[s])}}static _attributeNameForProperty(t,e){const s=e.attribute;return!1===s?void 0:"string"==typeof s?s:"string"==typeof t?t.toLowerCase():void 0}static _valueHasChanged(t,e,s=Y){return s(t,e)}static _propertyValueFromAttribute(t,e){const s=e.type,i=e.converter||J,o="function"==typeof i?i:i.fromAttribute;return o?o(t,s):t}static _propertyValueToAttribute(t,e){if(void 0===e.reflect)return;const s=e.type,i=e.converter;return(i&&i.toAttribute||J.toAttribute)(t,s)}initialize(){this._updateState=0,this._updatePromise=new Promise((t=>this._enableUpdatingResolver=t)),this._changedProperties=new Map,this._saveInstanceProperties(),this.requestUpdateInternal()}_saveInstanceProperties(){this.constructor._classProperties.forEach(((t,e)=>{if(this.hasOwnProperty(e)){const t=this[e];delete this[e],this._instanceProperties||(this._instanceProperties=new Map),this._instanceProperties.set(e,t)}}))}_applyInstanceProperties(){this._instanceProperties.forEach(((t,e)=>this[e]=t)),this._instanceProperties=void 0}connectedCallback(){this.enableUpdating()}enableUpdating(){void 0!==this._enableUpdatingResolver&&(this._enableUpdatingResolver(),this._enableUpdatingResolver=void 0)}disconnectedCallback(){}attributeChangedCallback(t,e,s){e!==s&&this._attributeToProperty(t,s)}_propertyToAttribute(t,e,s=X){const i=this.constructor,o=i._attributeNameForProperty(t,s);if(void 0!==o){const t=i._propertyValueToAttribute(e,s);if(void 0===t)return;this._updateState=8|this._updateState,null==t?this.removeAttribute(o):this.setAttribute(o,t),this._updateState=-9&this._updateState}}_attributeToProperty(t,e){if(8&this._updateState)return;const s=this.constructor,i=s._attributeToPropertyMap.get(t);if(void 0!==i){const t=s.getPropertyOptions(i);this._updateState=16|this._updateState,this[i]=s._propertyValueFromAttribute(e,t),this._updateState=-17&this._updateState}}requestUpdateInternal(t,e,s){let i=!0;if(void 0!==t){const o=this.constructor;s=s||o.getPropertyOptions(t),o._valueHasChanged(this[t],e,s.hasChanged)?(this._changedProperties.has(t)||this._changedProperties.set(t,e),!0!==s.reflect||16&this._updateState||(void 0===this._reflectingProperties&&(this._reflectingProperties=new Map),this._reflectingProperties.set(t,s))):i=!1}!this._hasRequestedUpdate&&i&&(this._updatePromise=this._enqueueUpdate())}requestUpdate(t,e){return this.requestUpdateInternal(t,e),this.updateComplete}async _enqueueUpdate(){this._updateState=4|this._updateState;try{await this._updatePromise}catch(e){}const t=this.performUpdate();return null!=t&&await t,!this._hasRequestedUpdate}get _hasRequestedUpdate(){return 4&this._updateState}get hasUpdated(){return 1&this._updateState}performUpdate(){if(!this._hasRequestedUpdate)return;this._instanceProperties&&this._applyInstanceProperties();let t=!1;const e=this._changedProperties;try{t=this.shouldUpdate(e),t?this.update(e):this._markUpdated()}catch(s){throw t=!1,this._markUpdated(),s}t&&(1&this._updateState||(this._updateState=1|this._updateState,this.firstUpdated(e)),this.updated(e))}_markUpdated(){this._changedProperties=new Map,this._updateState=-5&this._updateState}get updateComplete(){return this._getUpdateComplete()}_getUpdateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._updatePromise}shouldUpdate(t){return!0}update(t){void 0!==this._reflectingProperties&&this._reflectingProperties.size>0&&(this._reflectingProperties.forEach(((t,e)=>this._propertyToAttribute(e,this[e],t))),this._reflectingProperties=void 0),this._markUpdated()}updated(t){}firstUpdated(t){}}K[Z]=!0; /** @license Copyright (c) 2019 The Polymer Project Authors. All rights reserved. This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by Google as part of the polymer project is also subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt */ const Q=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,tt=Symbol();class et{constructor(t,e){if(e!==tt)throw new Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){return void 0===this._styleSheet&&(Q?(this._styleSheet=new CSSStyleSheet,this._styleSheet.replaceSync(this.cssText)):this._styleSheet=null),this._styleSheet}toString(){return this.cssText}}const st=t=>new et(String(t),tt),it=(t,...e)=>{const s=e.reduce(((e,s,i)=>e+(t=>{if(t instanceof et)return t.cssText;if("number"==typeof t)return t;throw new Error(`Value passed to 'css' function must be a 'css' function result: ${t}. Use 'unsafeCSS' to pass non-literal values, but\n take care to ensure page security.`)})(s)+t[i+1]),t[0]);return new et(s,tt)}; /** * @license * Copyright (c) 2017 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ (window.litElementVersions||(window.litElementVersions=[])).push("2.5.1");const ot={};class at extends K{static getStyles(){return this.styles}static _getUniqueStyles(){if(this.hasOwnProperty(JSCompiler_renameProperty("_styles",this)))return;const t=this.getStyles();if(Array.isArray(t)){const e=(t,s)=>t.reduceRight(((t,s)=>Array.isArray(s)?e(s,t):(t.add(s),t)),s),s=e(t,new Set),i=[];s.forEach((t=>i.unshift(t))),this._styles=i}else this._styles=void 0===t?[]:[t];this._styles=this._styles.map((t=>{if(t instanceof CSSStyleSheet&&!Q){const e=Array.prototype.slice.call(t.cssRules).reduce(((t,e)=>t+e.cssText),"");return st(e)}return t}))}initialize(){super.initialize(),this.constructor._getUniqueStyles(),this.renderRoot=this.createRenderRoot(),window.ShadowRoot&&this.renderRoot instanceof window.ShadowRoot&&this.adoptStyles()}createRenderRoot(){return this.attachShadow(this.constructor.shadowRootOptions)}adoptStyles(){const t=this.constructor._styles;0!==t.length&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow?Q?this.renderRoot.adoptedStyleSheets=t.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):this._needsShimAdoptedStyleSheets=!0:window.ShadyCSS.ScopingShim.prepareAdoptedCssText(t.map((t=>t.cssText)),this.localName))}connectedCallback(){super.connectedCallback(),this.hasUpdated&&void 0!==window.ShadyCSS&&window.ShadyCSS.styleElement(this)}update(t){const e=this.render();super.update(t),e!==ot&&this.constructor.render(e,this.renderRoot,{scopeName:this.localName,eventContext:this}),this._needsShimAdoptedStyleSheets&&(this._needsShimAdoptedStyleSheets=!1,this.constructor._styles.forEach((t=>{const e=document.createElement("style");e.textContent=t.cssText,this.renderRoot.appendChild(e)})))}render(){return ot}}at.finalized=!0,at.render=(t,e,i)=>{if(!i||"object"!=typeof i||!i.scopeName)throw new Error("The `scopeName` option is required.");const o=i.scopeName,a=L.has(e),n=j&&11===e.nodeType&&!!e.host,r=n&&!G.has(o),h=r?document.createDocumentFragment():e;if(((t,e,i)=>{let o=L.get(e);void 0===o&&(s(e,e.firstChild),L.set(e,o=new T(Object.assign({templateFactory:O},i))),o.appendInto(e)),o.setValue(t),o.commit()})(t,h,Object.assign({templateFactory:q(o)},i)),r){const t=L.get(h);L.delete(h);const i=t.value instanceof b?t.value.template:void 0;W(o,h,i),s(e,e.firstChild),e.appendChild(h),L.set(e,t)}!a&&n&&window.ShadyCSS.styleElement(e.host)},at.shadowRootOptions={mode:"open"}; /** * @license * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */ const nt=new WeakMap,rt=v((t=>e=>{if(!(e instanceof I)||e instanceof V||"style"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `styleMap` directive must be used in the style attribute and must be the only part in the attribute.");const{committer:s}=e,{style:i}=s.element;let o=nt.get(e);void 0===o&&(i.cssText=s.strings.join(" "),nt.set(e,o=new Set)),o.forEach((e=>{e in t||(o.delete(e),-1===e.indexOf("-")?i[e]=null:i.removeProperty(e))}));for(const a in t)o.add(a),-1===a.indexOf("-")?i[a]=t[a]:i.setProperty(a,t[a])})),ht=new WeakMap,lt=window.navigator.userAgent.indexOf("Trident/")>0,ct=v((t=>s=>{if(!(s instanceof T))throw new Error("unsafeSVG can only be used in text bindings");const i=ht.get(s);if(void 0!==i&&k(t)&&t===i.value&&s.value===i.fragment)return;const o=document.createElement("template"),a=o.content;let n;lt?(o.innerHTML=`${t}`,n=a.firstChild):(n=document.createElementNS("http://www.w3.org/2000/svg","svg"),a.appendChild(n),n.innerHTML=t),a.removeChild(n),e(a,n.firstChild);const r=document.importNode(a,!0);s.setValue(r),ht.set(s,{value:t,fragment:r})})),dt=new WeakMap,gt=v((t=>e=>{const s=dt.get(e);if(void 0===t&&e instanceof I){if(void 0!==s||!dt.has(e)){const t=e.committer.name;e.committer.element.removeAttribute(t)}}else t!==s&&e.setValue(t);dt.set(e,t)}));var ut="2.5.1";const mt=400,pt=200,vt=mt,ft=(t,e,s)=>t<0||s<0?e+360:e,yt=(t,e)=>Math.abs(t-e);class _t{static mergeDeep(...t){const e=t=>t&&"object"==typeof t;return t.reduce(((t,s)=>(Object.keys(s).forEach((i=>{const o=t[i],a=s[i];Array.isArray(o)&&Array.isArray(a)?t[i]=o.concat(...a):e(o)&&e(a)?t[i]=this.mergeDeep(o,a):t[i]=a})),t)),{})}}class bt{static calculateValueBetween(t,e,s){return isNaN(s)?0:s?(Math.min(Math.max(s,t),e)-t)/(e-t):0}static calculateSvgCoordinate(t,e){return t/100*mt+(e-pt)}static calculateSvgDimension(t){return t/100*mt}static getLovelace(){let t=window.document.querySelector("home-assistant");if(t=t&&t.shadowRoot,t=t&&t.querySelector("home-assistant-main"),t=t&&t.shadowRoot,t=t&&t.querySelector("app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver"),t=t&&t.shadowRoot||t,t=t&&t.querySelector("ha-panel-lovelace"),t=t&&t.shadowRoot,t=t&&t.querySelector("hui-root"),t){const e=t.lovelace;return e.current_view=t.___curView,e}return null}}class wt{static replaceVariables3(t,e){if(!t&&!e.template.defaults)return e[e.template.type];let s=t?.slice(0)??[];e.template.defaults&&(s=s.concat(e.template.defaults));let i=JSON.stringify(e[e.template.type]);return s.forEach((t=>{const e=Object.keys(t)[0],s=Object.values(t)[0];if("number"==typeof s||"boolean"==typeof s){const t=new RegExp(`"\\[\\[${e}\\]\\]"`,"gm");i=i.replace(t,s)}if("object"==typeof s){const t=new RegExp(`"\\[\\[${e}\\]\\]"`,"gm"),o=JSON.stringify(s);i=i.replace(t,o)}else{const t=new RegExp(`\\[\\[${e}\\]\\]`,"gm");i=i.replace(t,s)}})),JSON.parse(i)}static getJsTemplateOrValueConfig(t,e){if(!e)return e;if(["number","boolean","bigint","symbol"].includes(typeof e))return e;if("object"==typeof e)return Object.keys(e).forEach((s=>{e[s]=wt.getJsTemplateOrValueConfig(t,e[s])})),e;const s=e.trim();return"[[[["===s.substring(0,4)&&"]]]]"===s.slice(-4)?wt.evaluateJsTemplateConfig(t,s.slice(4,-4)):e}static evaluateJsTemplateConfig(t,e){try{return new Function("tool_config",`'use strict'; ${e}`).call(this,t)}catch(s){throw s.name="Sak-evaluateJsTemplateConfig-Error",s}}static evaluateJsTemplate(t,e,s){try{return new Function("state","states","entity","user","hass","tool_config","entity_config",`'use strict'; ${s}`).call(this,e,t._card._hass.states,t.config.hasOwnProperty("entity_index")?t._card.entities[t.config.entity_index]:void 0,t._card._hass.user,t._card._hass,t.config,t.config.hasOwnProperty("entity_index")?t._card.config.entities[t.config.entity_index]:void 0)}catch(i){throw i.name="Sak-evaluateJsTemplate-Error",i}}static getJsTemplateOrValue(t,e,s){if(!s)return s;if(["number","boolean","bigint","symbol"].includes(typeof s))return s;if("object"==typeof s)return Object.keys(s).forEach((i=>{s[i]=wt.getJsTemplateOrValue(t,e,s[i])})),s;const i=s.trim();return"[[["===i.substring(0,3)&&"]]]"===i.slice(-3)?wt.evaluateJsTemplate(t,e,i.slice(3,-3)):s}} /** * @license * Copyright (c) 2018 The Polymer Project Authors. All rights reserved. * This code may only be used under the BSD style license found at * http://polymer.github.io/LICENSE.txt * The complete set of authors may be found at * http://polymer.github.io/AUTHORS.txt * The complete set of contributors may be found at * http://polymer.github.io/CONTRIBUTORS.txt * Code distributed by Google as part of the polymer project is also * subject to an additional IP rights grant found at * http://polymer.github.io/PATENTS.txt */class xt{constructor(t){this.classes=new Set,this.changed=!1,this.element=t;const e=(t.getAttribute("class")||"").split(/\s+/);for(const s of e)this.classes.add(s)}add(t){this.classes.add(t),this.changed=!0}remove(t){this.classes.delete(t),this.changed=!0}commit(){if(this.changed){let t="";this.classes.forEach((e=>t+=e+" ")),this.element.setAttribute("class",t)}}}const St=new WeakMap,$t=v((t=>e=>{if(!(e instanceof I)||e instanceof V||"class"!==e.committer.name||e.committer.parts.length>1)throw new Error("The `classMap` directive must be used in the `class` attribute and must be the only part in the attribute.");const{committer:s}=e,{element:i}=s;let o=St.get(e);void 0===o&&(i.setAttribute("class",s.strings.join(" ")),St.set(e,o=new Set));const a=i.classList||new xt(i);o.forEach((e=>{e in t||(a.remove(e),o.delete(e))}));for(const n in t){const e=t[n];e!=o.has(n)&&(e?(a.add(n),o.add(n)):(a.remove(n),o.delete(n)))}"function"==typeof a.commit&&a.commit()})),kt=(t,e,s,i)=>{i=i||{},s=null==s?{}:s;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=s,t.dispatchEvent(o),o};class Et{static{Et.colorCache={},Et.element=void 0}static _prefixKeys(t){let e={};return Object.keys(t).forEach((s=>{const i=`--${s}`,o=String(t[s]);e[i]=`${o}`})),e}static processTheme(t){let e={},s={},i={},o={};const{modes:a,...n}=t;return a&&(s={...n,...a.dark},e={...n,...a.light}),i=Et._prefixKeys(e),o=Et._prefixKeys(s),{themeLight:i,themeDark:o}}static processPalette(t){let e={},s={},i={},o={},a={};return Object.values(t).forEach((t=>{const{modes:o,...a}=t;e={...e,...a},o&&(i={...i,...a,...o.dark},s={...s,...a,...o.light})})),o=Et._prefixKeys(s),a=Et._prefixKeys(i),{paletteLight:o,paletteDark:a}}static setElement(t){Et.element=t}static calculateColor(t,e,s){const i=Object.keys(e).map((t=>Number(t))).sort(((t,e)=>t-e));let o,a,n;const r=i.length;if(t<=i[0])return e[i[0]];if(t>=i[r-1])return e[i[r-1]];for(let h=0;h=r&&tNumber(t))).sort(((t,e)=>t-e));let n,r,h;const l=a.length;if(t<=a[0])return e[a[0]];if(t>=a[l-1])return e[a[l-1]];for(let c=0;c=l&&t1&&(s-=1),s<1/6?t+6*(e-t)*s:s<.5?e:s<2/3?t+(e-t)*(2/3-s)*6:t}const h=i<.5?i*(1+s):i+s-i*s,l=2*i-h;o=r(l,h,e+1/3),a=r(l,h,e),n=r(l,h,e-1/3)}return o*=255,a*=255,n*=255,{r:o,g:a,b:n}}}class Ct{constructor(t,e,s){this.toolId=Math.random().toString(36).substr(2,9),this.toolset=t,this._card=this.toolset._card,this.config=e,this.dev={...this._card.dev},this.toolsetPos=s,this.svg={},this.svg.cx=bt.calculateSvgCoordinate(e.position.cx,0),this.svg.cy=bt.calculateSvgCoordinate(e.position.cy,0),this.svg.height=e.position.height?bt.calculateSvgDimension(e.position.height):0,this.svg.width=e.position.width?bt.calculateSvgDimension(e.position.width):0,this.svg.x=this.svg.cx-this.svg.width/2,this.svg.y=this.svg.cy-this.svg.height/2,this.classes={},this.classes.card={},this.classes.toolset={},this.classes.tool={},this.styles={},this.styles.card={},this.styles.toolset={},this.styles.tool={},this.animationClass={},this.animationClassHasChanged=!0,this.animationStyle={},this.animationStyleHasChanged=!0,this.config?.show?.style||(this.config.show||(this.config.show={}),this.config.show.style="default"),this.colorStops={},this.config.colorstops&&this.config.colorstops.colors&&Object.keys(this.config.colorstops.colors).forEach((t=>{this.colorStops[t]=this.config.colorstops.colors[t]})),"colorstop"===this.config.show.style&&this.config?.colorstops.colors&&(this.sortedColorStops=Object.keys(this.config.colorstops.colors).map((t=>Number(t))).sort(((t,e)=>t-e))),this.csnew={},this.config.csnew&&this.config.csnew.colors&&(this.config.csnew.colors.forEach(((t,e)=>{this.csnew[t.stop]=this.config.csnew.colors[e]})),this.sortedcsnew=Object.keys(this.csnew).map((t=>Number(t))).sort(((t,e)=>t-e)))}textEllipsis(t,e){return e&&e{const e=JSON.parse(JSON.stringify(this.config.animations[t])),i=wt.getJsTemplateOrValue(this,this._stateValue,_t.mergeDeep(e));if(s)return!0;switch(i.operator?i.operator:"=="){case"==":s=void 0===this._stateValue?void 0===i.state||"undefined"===i.state.toLowerCase():this._stateValue.toLowerCase()===i.state.toLowerCase();break;case"!=":s=void 0===this._stateValue?"undefined"!==i.state.toLowerCase():this._stateValue.toLowerCase()!==i.state.toLowerCase();break;case">":void 0!==this._stateValue&&(s=Number(this._stateValue.toLowerCase())>Number(i.state.toLowerCase()));break;case"<":void 0!==this._stateValue&&(s=Number(this._stateValue.toLowerCase())=":void 0!==this._stateValue&&(s=Number(this._stateValue.toLowerCase())>=Number(i.state.toLowerCase()));break;case"<=":void 0!==this._stateValue&&(s=Number(this._stateValue.toLowerCase())<=Number(i.state.toLowerCase()));break;default:s=!1}return this.dev.debug&&console.log("BaseTool, animation, match, value, config, operator",s,this._stateValue,i.state,i.operator),!s||(this.animationClass&&i.reuse||(this.animationClass={}),i.classes&&(this.animationClass=_t.mergeDeep(this.animationClass,i.classes)),this.animationStyle&&i.reuse||(this.animationStyle={}),i.styles&&(this.animationStyle=_t.mergeDeep(this.animationStyle,i.styles)),this.animationStyleHasChanged=!0,this.item=i,this.activeAnimation=i,s)}))}getEntityIndexFromAnimation(t){return t.hasOwnProperty("entity_index")?t.entity_index:this.config.hasOwnProperty("entity_index")?this.config.entity_index:this.config.entity_indexes?this.config.entity_indexes[0].entity_index:void 0}getIndexInEntityIndexes(t){return this.config.entity_indexes.findIndex((e=>e.entity_index===t))}stateIsMatch(t,e){let s;const i=JSON.parse(JSON.stringify(t)),o=wt.getJsTemplateOrValue(this,e,_t.mergeDeep(i));switch(o.operator?o.operator:"=="){case"==":s=void 0===e?void 0===o.state||"undefined"===o.state.toLowerCase():e.toLowerCase()===o.state.toLowerCase();break;case"!=":s=void 0===e?void 0!==o.state||"undefined"!==o.state.toLowerCase():e.toLowerCase()!==o.state.toLowerCase();break;case">":void 0!==e&&(s=Number(e.toLowerCase())>Number(o.state.toLowerCase()));break;case"<":void 0!==e&&(s=Number(e.toLowerCase())=":void 0!==e&&(s=Number(e.toLowerCase())>=Number(o.state.toLowerCase()));break;case"<=":void 0!==e&&(s=Number(e.toLowerCase())<=Number(o.state.toLowerCase()));break;default:s=!1}return s}mergeAnimationData(t){this.animationClass&&t.reuse||(this.animationClass={}),t.classes&&(this.animationClass=_t.mergeDeep(this.animationClass,t.classes)),this.animationStyle&&t.reuse||(this.animationStyle={}),t.styles&&(this.animationStyle=_t.mergeDeep(this.animationStyle,t.styles)),this.animationStyleHasChanged=!0,this.item||(this.item={}),this.item=_t.mergeDeep(this.item,t),this.activeAnimation={...t}}set values(t){this._lastStateValues||(this._lastStateValues=[]),this._stateValues||(this._stateValues=[]);const e=[...t];this.dev.debug&&console.log("BaseTool set values(state)",e);for(let s=0;s{const o=this.getIndexInEntityIndexes(this.getEntityIndexFromAnimation(e));return i=this.stateIsMatch(e,t[o]),!!i&&(this.mergeAnimationData(e),!0)})))}this._stateValue=this._stateValues[this.getIndexInEntityIndexes(this.defaultEntityIndex())],this._stateValuePrev=this._lastStateValues[this.getIndexInEntityIndexes(this.defaultEntityIndex())]}EnableHoverForInteraction(){const t=this.config.hasOwnProperty("entity_index")||this.config?.user_actions?.tap_action;this.classes.tool.hover=!!t}MergeAnimationStyleIfChanged(t){this.animationStyleHasChanged&&(this.animationStyleHasChanged=!1,this.styles=t?_t.mergeDeep(t,this.config.styles,this.animationStyle):_t.mergeDeep(this.config.styles,this.animationStyle),this.styles.card&&0!==Object.keys(this.styles.card).length&&(this._card.styles.card=_t.mergeDeep(this.styles.card)))}MergeAnimationClassIfChanged(t){this.animationClassHasChanged=!0,this.animationClassHasChanged&&(this.animationClassHasChanged=!1,this.classes=t?_t.mergeDeep(t,this.config.classes,this.animationClass):_t.mergeDeep(this.config.classes,this.animationClass))}MergeColorFromState(t){if(this.config.hasOwnProperty("entity_index")){const e=this.getColorFromState(this._stateValue);""!==e&&(t.fill=this.config[this.config.show.style].fill?e:"",t.stroke=this.config[this.config.show.style].stroke?e:"")}}MergeColorFromState2(t,e){if(this.config.hasOwnProperty("entity_index")){const s=this.config[this.config.show.style].fill?this.getColorFromState2(this._stateValue,e,"fill"):"",i=this.config[this.config.show.style].stroke?this.getColorFromState2(this._stateValue,e,"stroke"):"";""!==s&&(t.fill=s),""!==i&&(t.stroke=i)}}getColorFromState(t){let e="";switch(this.config.show.style){case"default":break;case"fixedcolor":e=this.config.color;break;case"colorstop":case"colorstops":case"colorstopgradient":e=Et.calculateColor(t,this.colorStops,"colorstopgradient"===this.config.show.style);break;case"minmaxgradient":e=Et.calculateColor(t,this.colorStopsMinMax,!0)}return e}getColorFromState2(t,e,s){let i="";switch(this.config.show.style){case"colorstop":case"colorstops":case"colorstopgradient":i=Et.calculateColor2(t,this.csnew,e,s,"colorstopgradient"===this.config.show.style);break;case"minmaxgradient":i=Et.calculateColor2(t,this.colorStopsMinMax,e,s,!0)}return i}_processTapEvent(t,e,s,i,o,a){let n;if(i){kt(t,"haptic",i.haptic||"medium"),this.dev.debug&&console.log("_processTapEvent",s,i,o,a);for(let s=0;s `,U`${t}`}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderBadge()} `}}class Tt extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,radius:50},classes:{tool:{"sak-circle":!0,hover:!0},circle:{"sak-circle__circle":!0}},styles:{tool:{},circle:{}}},e),s),this.EnableHoverForInteraction(),this.svg.radius=bt.calculateSvgDimension(e.position.radius),this.classes.tool={},this.classes.circle={},this.styles.tool={},this.styles.circle={},this.dev.debug&&console.log("CircleTool constructor config, svg",this.toolId,this.config,this.svg)}set value(t){super.value=t}_renderCircle(){return this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.circle),U` `}render(){return this.styles.tool.overflow="visible",this.styles["transform-origin"]=`${this.svg.cx} ${this.svg.cy}`,U` this.handleTapEvent(t,this.config)}> ${this._renderCircle()} `}}class At extends Ct{constructor(t,e,s){switch(super(t,_t.mergeDeep({position:{cx:50,cy:50,radius:45,start_angle:30,end_angle:230,track:{width:2},active:{width:4},thumb:{height:10,width:10,radius:5},capture:{height:25,width:25,radius:25},label:{placement:"none",cx:10,cy:10}},show:{uom:"end",active:!1},classes:{tool:{"sak-circslider":!0,hover:!0},capture:{"sak-circslider__capture":!0,hover:!0},active:{"sak-circslider__active":!0},track:{"sak-circslider__track":!0},thumb:{"sak-circslider__thumb":!0,hover:!0},label:{"sak-circslider__value":!0},uom:{"sak-circslider__uom":!0}},styles:{tool:{},active:{},capture:{},track:{},thumb:{},label:{},uom:{}},scale:{min:0,max:100,step:1}},e),s),this.svg.radius=bt.calculateSvgDimension(this.config.position.radius),this.arc={},this.arc.startAngle=this.config.position.start_angle,this.arc.endAngle=this.config.position.end_angle,this.arc.size=yt(this.config.position.end_angle,this.config.position.start_angle),this.arc.clockwise=this.config.position.end_angle>this.config.position.start_angle,this.arc.direction=this.arc.clockwise?1:-1,this.arc.pathLength=2*this.arc.size/360*Math.PI*this.svg.radius,this.arc.arcLength=2*Math.PI*this.svg.radius,this.arc.startAngle360=ft(this.arc.startAngle,this.arc.startAngle,this.arc.endAngle),this.arc.endAngle360=ft(this.arc.startAngle,this.arc.endAngle,this.arc.endAngle),this.arc.startAngleSvgPoint=this.polarToCartesian(this.svg.cx,this.svg.cy,this.svg.radius,this.svg.radius,this.arc.startAngle360),this.arc.endAngleSvgPoint=this.polarToCartesian(this.svg.cx,this.svg.cy,this.svg.radius,this.svg.radius,this.arc.endAngle360),this.arc.scaleDasharray=2*this.arc.size/360*Math.PI*this.svg.radius,this.arc.dashOffset=this.arc.clockwise?0:-this.arc.scaleDasharray-this.arc.arcLength,this.arc.currentAngle=this.arc.startAngle,this.svg.startAngle=this.config.position.start_angle,this.svg.endAngle=this.config.position.end_angle,this.svg.diffAngle=this.config.position.end_angle-this.config.position.start_angle,this.svg.pathLength=2*this.arc.size/360*Math.PI*this.svg.radius,this.svg.circleLength=2*Math.PI*this.svg.radius,this.svg.label={},this.config.position.label.placement){case"position":this.svg.label.cx=bt.calculateSvgCoordinate(this.config.position.label.cx,0),this.svg.label.cy=bt.calculateSvgCoordinate(this.config.position.label.cy,0);break;case"thumb":this.svg.label.cx=this.svg.cx,this.svg.label.cy=this.svg.cy;break;case"none":break;default:throw console.error("CircularSliderTool - constructor: invalid label placement [none, position, thumb] = ",this.config.position.label.placement),Error("CircularSliderTool::constructor - invalid label placement [none, position, thumb] = ",this.config.position.label.placement)}this.svg.track={},this.svg.track.width=bt.calculateSvgDimension(this.config.position.track.width),this.svg.active={},this.svg.active.width=bt.calculateSvgDimension(this.config.position.active.width),this.svg.thumb={},this.svg.thumb.width=bt.calculateSvgDimension(this.config.position.thumb.width),this.svg.thumb.height=bt.calculateSvgDimension(this.config.position.thumb.height),this.svg.thumb.radius=bt.calculateSvgDimension(this.config.position.thumb.radius),this.svg.thumb.cx=this.svg.cx,this.svg.thumb.cy=this.svg.cy,this.svg.thumb.x1=this.svg.cx-this.svg.thumb.width/2,this.svg.thumb.y1=this.svg.cy-this.svg.thumb.height/2,this.svg.capture={},this.svg.capture.width=bt.calculateSvgDimension(Math.max(this.config.position.capture.width,1.2*this.config.position.thumb.width)),this.svg.capture.height=bt.calculateSvgDimension(Math.max(this.config.position.capture.height,1.2*this.config.position.thumb.height)),this.svg.capture.radius=bt.calculateSvgDimension(this.config.position.capture.radius),this.svg.capture.x1=this.svg.cx-this.svg.capture.width/2,this.svg.capture.y1=this.svg.cy-this.svg.capture.height/2,this.svg.rotate={},this.svg.rotate.degrees=this.arc.clockwise?-90+this.arc.startAngle:this.arc.endAngle360-90,this.svg.rotate.cx=this.svg.cx,this.svg.rotate.cy=this.svg.cy,this.classes.track={},this.classes.active={},this.classes.thumb={},this.classes.label={},this.classes.uom={},this.styles.track={},this.styles.active={},this.styles.thumb={},this.styles.label={},this.styles.uom={},this.svg.scale={},this.svg.scale.min=this.config.scale.min,this.svg.scale.max=this.config.scale.max,this.svg.scale.center=Math.abs(this.svg.scale.max-this.svg.scale.min)/2+this.svg.scale.min,this.svg.scale.svgPointMin=this.sliderValueToPoint(this.svg.scale.min),this.svg.scale.svgPointMax=this.sliderValueToPoint(this.svg.scale.max),this.svg.scale.svgPointCenter=this.sliderValueToPoint(this.svg.scale.center),this.svg.scale.step=this.config.scale.step,this.rid=null,this.thumbPos=this.sliderValueToPoint(this.config.scale.min),this.svg.thumb.x1=this.thumbPos.x-this.svg.thumb.width/2,this.svg.thumb.y1=this.thumbPos.y-this.svg.thumb.height/2,this.svg.capture.x1=this.thumbPos.x-this.svg.capture.width/2,this.svg.capture.y1=this.thumbPos.y-this.svg.capture.height/2,this.dev.debug&&console.log("CircularSliderTool::constructor",this.config,this.svg)}pointToAngle360(t,e,s){let i=-Math.atan2(t.y-e.y,e.x-t.x)/(Math.PI/180);return i+=-90,i<0&&(i+=360),this.arc.clockwise&&i=this.arc.startAngle360&&t<=this.arc.endAngle360:t<=this.arc.startAngle360&&t>=this.arc.endAngle360,!!e}polarToCartesian(t,e,s,i,o){const a=(o-90)*Math.PI/180;return{x:t+s*Math.cos(a),y:e+i*Math.sin(a)}}pointToSliderValue(t){let e,s;const i={};i.x=this.svg.cx,i.y=this.svg.cy;const o=this.pointToAngle360(t,i,!0);let{myAngle:a}=this;const n=this.isAngle360InBetween(o);var r,h,l;return n&&(this.myAngle=o,a=o,this.arc.currentAngle=a),this.arc.currentAngle=a,this.arc.clockwise&&(s=(a-this.arc.startAngle360)/this.arc.size),this.arc.clockwise||(s=(this.arc.startAngle360-a)/this.arc.size),e=(this.config.scale.max-this.config.scale.min)*s+this.config.scale.min,e=Math.round(e/this.svg.scale.step)*this.svg.scale.step,e=Math.max(Math.min(this.config.scale.max,e),this.config.scale.min),this.arc.currentAngle=a,this.dragging&&!n&&(r=this.svg.scale.min,h=e,l=this.svg.scale.max,e=Math.abs(h-r)>Math.abs(l-h)?l:r,this.m=this.sliderValueToPoint(e)),e}sliderValueToPoint(t){let e,s=bt.calculateValueBetween(this.config.scale.min,this.config.scale.max,t);isNaN(s)&&(s=0),e=this.arc.clockwise?this.arc.size*s+this.arc.startAngle360:this.arc.size*(1-s)+this.arc.endAngle360,e<0&&(e+=360);const i=this.polarToCartesian(this.svg.cx,this.svg.cy,this.svg.radius,this.svg.radius,e);return this.arc.currentAngle=e,i}updateValue(t){this._value=this.pointToSliderValue(t);Math.abs(0)<.01&&this.rid&&(window.cancelAnimationFrame(this.rid),this.rid=null)}updateThumb(t){if(this.dragging){this.thumbPos=this.sliderValueToPoint(this._value),this.svg.thumb.x1=this.thumbPos.x-this.svg.thumb.width/2,this.svg.thumb.y1=this.thumbPos.y-this.svg.thumb.height/2,this.svg.capture.x1=this.thumbPos.x-this.svg.capture.width/2,this.svg.capture.y1=this.thumbPos.y-this.svg.capture.height/2;const t=`rotate(${this.arc.currentAngle} ${this.svg.capture.width/2} ${this.svg.capture.height/2})`;this.elements.thumb.setAttribute("transform",t),this.elements.thumbGroup.setAttribute("x",this.svg.capture.x1),this.elements.thumbGroup.setAttribute("y",this.svg.capture.y1)}this.updateLabel(t)}updateActiveTrack(t){const e=this.config.scale.min||0,s=this.config.scale.max||100;let i=bt.calculateValueBetween(e,s,this.labelValue);isNaN(i)&&(i=0);const o=i*this.svg.pathLength;this.dashArray=`${o} ${this.svg.circleLength}`,this.dragging&&this.elements.activeTrack.setAttribute("stroke-dasharray",this.dashArray)}updateLabel(t){this.dev.debug&&console.log("SLIDER - updateLabel start",t,this.config.position.orientation);const e=this._card.config.entities[this.defaultEntityIndex()].decimals||0,s=10**e;this.labelValue2=(Math.round(this.pointToSliderValue(t)*s)/s).toFixed(e),console.log("updateLabel, labelvalue ",this.labelValue2),"none"!==this.config.position.label.placement&&(this.elements.label.textContent=this.labelValue2)}mouseEventToPoint(t){let e=this.elements.svg.createSVGPoint();e.x=t.touches?t.touches[0].clientX:t.clientX,e.y=t.touches?t.touches[0].clientY:t.clientY;const s=this.elements.svg.getScreenCTM().inverse();return e=e.matrixTransform(s),e}callDragService(){void 0!==this.labelValue2&&(this.labelValuePrev!==this.labelValue2&&(this.labelValuePrev=this.labelValue2,this._processTapEvent(this._card,this._card._hass,this.config,this.config.user_actions.tap_action,this._card.config.entities[this.defaultEntityIndex()]?.entity,this.labelValue2)),this.dragging&&(this.timeOutId=setTimeout((()=>this.callDragService()),this.config.user_actions.drag_action.update_interval)))}callTapService(){void 0!==this.labelValue2&&this._processTapEvent(this._card,this._card._hass,this.config,this.config.user_actions?.tap_action,this._card.config.entities[this.defaultEntityIndex()]?.entity,this.labelValue2)}firstUpdated(t){function e(){this.rid=window.requestAnimationFrame(e),this.updateValue(this.m),this.updateThumb(this.m),this.updateActiveTrack(this.m)}this.labelValue=this._stateValue,this.dev.debug&&console.log("circslider - firstUpdated"),this.elements={},this.elements.svg=this._card.shadowRoot.getElementById("circslider-".concat(this.toolId)),this.elements.track=this.elements.svg.querySelector("#track"),this.elements.activeTrack=this.elements.svg.querySelector("#active-track"),this.elements.capture=this.elements.svg.querySelector("#capture"),this.elements.thumbGroup=this.elements.svg.querySelector("#thumb-group"),this.elements.thumb=this.elements.svg.querySelector("#thumb"),this.elements.label=this.elements.svg.querySelector("#label tspan"),this.dev.debug&&console.log("circslider - firstUpdated svg = ",this.elements.svg,"activeTrack=",this.elements.activeTrack,"thumb=",this.elements.thumb,"label=",this.elements.label,"text=",this.elements.text);const s=()=>{const t=yt(this.svg.scale.max,this.labelValue)<=this.rangeMax,e=yt(this.svg.scale.min,this.labelValue)<=this.rangeMin,s=!(!e||!this.diffMax),i=!(!t||!this.diffMin);s?(this.labelValue=this.svg.scale.max,this.m=this.sliderValueToPoint(this.labelValue),this.rangeMax=this.svg.scale.max/10,this.rangeMin=yt(this.svg.scale.max,this.svg.scale.min+this.svg.scale.max/5)):i?(this.labelValue=this.svg.scale.min,this.m=this.sliderValueToPoint(this.labelValue),this.rangeMax=yt(this.svg.scale.min,this.svg.scale.max-this.svg.scale.max/5),this.rangeMin=this.svg.scale.max/10):(this.diffMax=t,this.diffMin=e,this.rangeMin=this.svg.scale.max/5,this.rangeMax=this.svg.scale.max/5)},i=t=>{t.preventDefault(),this.dragging&&(this.m=this.mouseEventToPoint(t),this.labelValue=this.pointToSliderValue(this.m),s(),e.call(this))},o=t=>{t.preventDefault(),this.dragging=!0,window.addEventListener("pointermove",i,!1),window.addEventListener("pointerup",a,!1),this.config.user_actions?.drag_action&&this.config.user_actions?.drag_action.update_interval&&(this.config.user_actions.drag_action.update_interval>0?this.timeOutId=setTimeout((()=>this.callDragService()),this.config.user_actions.drag_action.update_interval):this.timeOutId=null),this.m=this.mouseEventToPoint(t),this.labelValue=this.pointToSliderValue(this.m),s(),this.dev.debug&&console.log("pointerDOWN",Math.round(100*this.m.x)/100),e.call(this)},a=t=>{t.preventDefault(),this.dev.debug&&console.log("pointerUP"),window.removeEventListener("pointermove",i,!1),window.removeEventListener("pointerup",a,!1),window.removeEventListener("mousemove",i,!1),window.removeEventListener("touchmove",i,!1),window.removeEventListener("mouseup",a,!1),window.removeEventListener("touchend",a,!1),this.labelValuePrev=this.labelValue,this.dragging?(this.dragging=!1,clearTimeout(this.timeOutId),this.timeOutId=null,this.target=0,this.labelValue2=this.labelValue,e.call(this),this.callTapService()):s()};this.elements.thumbGroup.addEventListener("touchstart",o,!1),this.elements.thumbGroup.addEventListener("mousedown",o,!1),this.elements.svg.addEventListener("wheel",(t=>{t.preventDefault(),clearTimeout(this.wheelTimeOutId),this.dragging=!0,this.wheelTimeOutId=setTimeout((()=>{clearTimeout(this.timeOutId),this.timeOutId=null,this.labelValue2=this.labelValue,this.dragging=!1,this.callTapService()}),500),this.config.user_actions?.drag_action&&this.config.user_actions?.drag_action.update_interval&&(this.config.user_actions.drag_action.update_interval>0?this.timeOutId=setTimeout((()=>this.callDragService()),this.config.user_actions.drag_action.update_interval):this.timeOutId=null);const s=+this.labelValue+ +(t.altKey?10*this.svg.scale.step:this.svg.scale.step)*Math.sign(t.deltaY);var i,o,a;this.labelValue=(i=this.svg.scale.min,o=s,a=this.svg.scale.max,Math.min(Math.max(o,i),a)),this.m=this.sliderValueToPoint(this.labelValue),this.pointToSliderValue(this.m),e.call(this),this.labelValue2=this.labelValue}),!1)}set value(t){if(super.value=t,this.dragging||(this.labelValue=this._stateValue),!this.dragging){const t=this.config.scale.min||0,e=this.config.scale.max||100;let s=Math.min(bt.calculateValueBetween(t,e,this._stateValue),1);isNaN(s)&&(s=0);const i=s*this.svg.pathLength;this.dashArray=`${i} ${this.svg.circleLength}`;const o=this.sliderValueToPoint(this._stateValue);this.svg.thumb.x1=o.x-this.svg.thumb.width/2,this.svg.thumb.y1=o.y-this.svg.thumb.height/2,this.svg.capture.x1=o.x-this.svg.capture.width/2,this.svg.capture.y1=o.y-this.svg.capture.height/2}}set values(t){if(super.values=t,this.dragging||(this.labelValue=this._stateValues[this.getIndexInEntityIndexes(this.defaultEntityIndex())]),!this.dragging){const t=this.config.scale.min||0,e=this.config.scale.max||100;let s=Math.min(bt.calculateValueBetween(t,e,this._stateValues[this.getIndexInEntityIndexes(this.defaultEntityIndex())]),1);isNaN(s)&&(s=0);const i=s*this.svg.pathLength;this.dashArray=`${i} ${this.svg.circleLength}`;const o=this.sliderValueToPoint(this._stateValues[this.getIndexInEntityIndexes(this.defaultEntityIndex())]);this.svg.thumb.x1=o.x-this.svg.thumb.width/2,this.svg.thumb.y1=o.y-this.svg.thumb.height/2,this.svg.capture.x1=o.x-this.svg.capture.width/2,this.svg.capture.y1=o.y-this.svg.capture.height/2}}_renderUom(){if("none"===this.config.show.uom)return U``;{this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.uom);let t=this.styles.label["font-size"],e=.5,s="em";const i=t.match(/\D+|\d*\.?\d+/g);2===i.length?(e=.6*Number(i[0]),s=i[1]):console.error("Cannot determine font-size for state/unit",t),t={"font-size":e+s},this.styles.uom=_t.mergeDeep(this.config.styles.uom,t);const o=this._card._buildUom(this.derivedEntity,this._card.entities[this.defaultEntityIndex()],this._card.config.entities[this.defaultEntityIndex()]);return"end"===this.config.show.uom?U` ${o} `:"bottom"===this.config.show.uom?U` ${o} `:"top"===this.config.show.uom?U` ${o} `:U` ERR `}}_renderCircSlider(){return this.MergeAnimationClassIfChanged(),this.MergeColorFromState(),this.MergeAnimationStyleIfChanged(),this.renderValue=this._stateValue,this.dragging?this.renderValue=this.labelValue2:this.elements?.label&&(this.elements.label.textContent="undefined"===this.renderValue?"":this.renderValue),U` ${function(){return U` `}.call(this)} ${function(t){return"thumb"===this.config.position.label.placement&&t?U` ${void 0===this.renderValue?"":this.renderValue} ${void 0===this.renderValue?"":this._renderUom()} `:"position"!==this.config.position.label.placement||t?void 0:U` ${void 0===this.renderValue?"":this.renderValue} ${void 0===this.renderValue?"":this._renderUom()} `}.call(this,!1)} `}render(){return U` ${this._renderCircSlider()} `}}class Mt extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,radiusx:50,radiusy:25},classes:{tool:{"sak-ellipse":!0,hover:!0},ellipse:{"sak-ellipse__ellipse":!0}},styles:{tool:{},ellipse:{}}},e),s),this.svg.radiusx=bt.calculateSvgDimension(e.position.radiusx),this.svg.radiusy=bt.calculateSvgDimension(e.position.radiusy),this.classes.tool={},this.classes.ellipse={},this.styles.tool={},this.styles.ellipse={},this.dev.debug&&console.log("EllipseTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}_renderEllipse(){return this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.ellipse),this.dev.debug&&console.log("EllipseTool - renderEllipse",this.svg.cx,this.svg.cy,this.svg.radiusx,this.svg.radiusy),U` `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderEllipse()} `}}class Vt extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({classes:{tool:{},area:{"sak-area__area":!0,hover:!0}},styles:{tool:{},area:{}}},e),s),this.classes.tool={},this.classes.area={},this.styles.tool={},this.styles.area={},this.dev.debug&&console.log("EntityAreaTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}_buildArea(t,e){return e.area||"?"}_renderEntityArea(){this.MergeAnimationClassIfChanged(),this.MergeColorFromState(this.styles.area),this.MergeAnimationStyleIfChanged();const t=this.textEllipsis(this._buildArea(this._card.entities[this.defaultEntityIndex()],this._card.config.entities[this.defaultEntityIndex()]),this.config?.show?.ellipsis);return U` ${t} `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderEntityArea()} `}}const Nt="mdi:bookmark",Dt={air_quality:"mdi:air-filter",alert:"mdi:alert",calendar:"mdi:calendar",climate:"mdi:thermostat",configurator:"mdi:cog",conversation:"mdi:microphone-message",counter:"mdi:counter",datetime:"mdi:calendar-clock",date:"mdi:calendar",demo:"mdi:home-assistant",google_assistant:"mdi:google-assistant",group:"mdi:google-circles-communities",homeassistant:"mdi:home-assistant",homekit:"mdi:home-automation",image_processing:"mdi:image-filter-frames",input_button:"mdi:gesture-tap-button",input_datetime:"mdi:calendar-clock",input_number:"mdi:ray-vertex",input_select:"mdi:format-list-bulleted",input_text:"mdi:form-textbox",light:"mdi:lightbulb",mailbox:"mdi:mailbox",notify:"mdi:comment-alert",number:"mdi:ray-vertex",persistent_notification:"mdi:bell",plant:"mdi:Flower",proximity:"mdi:apple-safari",remote:"mdi:remote",scene:"mdi:palette",schedule:"mdi:calendar-clock",script:"mdi:script-text",select:"mdi:format-list-bulleted",sensor:"mdi:Eye",simple_alarm:"mdi:bell",siren:"mdi:bullhorn",stt:"mdi:microphone-message",text:"mdi:form-textbox",time:"mdi:clock",timer:"mdi:timer-outline",tts:"mdi:speaker-message",updater:"mdi:cloud-upload",vacuum:"mdi:robot-vacuum",zone:"mdi:map-marker-radius"},Pt={apparent_power:"mdi:flash",aqi:"mdi:air-filter",atmospheric_pressure:"mdi:thermometer-lines",carbon_dioxide:"mdi:molecule-co2",carbon_monoxide:"mdi:molecule-co",current:"mdi:current-ac",data_rate:"mdi:transmission-tower",data_size:"mdi:database",date:"mdi:calendar",distance:"mdi:arrow-left-right",duration:"mdi:progress-clock",energy:"mdi:lightning-bolt",frequency:"mdi:sine-wave",gas:"mdi:meter-gas",humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",irradiance:"mdi:sun-wireless",moisture:"mdi:water-percent",monetary:"mdi:cash",nitrogen_dioxide:"mdi:molecule",nitrogen_monoxide:"mdi:molecule",nitrous_oxide:"mdi:molecule",ozone:"mdi:molecule",pm1:"mdi:molecule",pm10:"mdi:molecule",pm25:"mdi:molecule",power:"mdi:flash",power_factor:"mdi:angle-acute",precipitation:"mdi:weather-rainy",precipitation_intensity:"mdi:weather-pouring",pressure:"mdi:gauge",reactive_power:"mdi:flash",signal_strength:"mdi:wifi",sound_pressure:"mdi:ear-hearing",speed:"mdi:speedometer",sulphur_dioxide:"mdi:molecule",temperature:"mdi:thermometer",timestamp:"mdi:clock",volatile_organic_compounds:"mdi:molecule",volatile_organic_compounds_parts:"mdi:molecule",voltage:"mdi:sine-wave",volume:"mdi:car-coolant-level",water:"mdi:water",weight:"mdi:weight",wind_speed:"mdi:weather-windy"},Ot=t=>t.substr(0,t.indexOf("."));new Set(["fan","input_boolean","light","switch","group","automation","humidifier"]),new Set(["camera","media_player"]);const Rt={10:"mdi:battery-10",20:"mdi:battery-20",30:"mdi:battery-30",40:"mdi:battery-40",50:"mdi:battery-50",60:"mdi:battery-60",70:"mdi:battery-70",80:"mdi:battery-80",90:"mdi:battery-90",100:"mdi:battery"},Lt={10:"mdi:battery-charging-10",20:"mdi:battery-charging-20",30:"mdi:battery-charging-30",40:"mdi:battery-charging-40",50:"mdi:battery-charging-50",60:"mdi:battery-charging-60",70:"mdi:battery-charging-70",80:"mdi:battery-charging-80",90:"mdi:battery-charging-90",100:"mdi:battery-charging"},zt=(t,e)=>{const s=Number(t);if(isNaN(s))return"off"===t?"mdi:battery":"on"===t?"mdi:battery-alert":"mdi:battery-unknown";const i=10*Math.round(s/10);return e&&s>=10?Lt[i]:e?"mdi:battery-charging-outline":s<=5?"mdi:battery-alert-variant-outline":Rt[i]},Ft=t=>{const e=t?.attributes.device_class;if(e&&e in Pt)return Pt[e];if("battery"===e)return t?((t,e)=>{const s=t.state,i=e&&"on"===e.state;return zt(s,i)})(t):"mdi:battery";const s=t?.attributes.unit_of_measurement;return"°C"===s||"°F"===s?"mdi-thermometer":void 0},Ut=(t,e,s)=>{const i=void 0!==s?s:e?.state;switch(t){case"alarm_control_panel":return(t=>{switch(t){case"armed_away":return"mdi:shield-lock";case"armed_vacation":return"mdi:shield-airplane";case"armed_home":return"mdi:shield-home";case"armed_night":return"mdi:shield-moon";case"armed_custom_bypass":return"mdi:security";case"pending":return"mdi:shield-outline";case"triggered":return"mdi:bell-ring";case"disarmed":return"mdi:shield-off";default:return"mdi:shield"}})(i);case"automation":return"off"===i?"mdi:robot-off":"mdi:robot";case"binary_sensor":return((t,e)=>{const s="off"===t;switch(e?.attributes.device_class){case"battery":return s?"mdi:battery":"mdi:battery-outline";case"battery_charging":return s?"mdi:battery":"mdi:battery-charging";case"carbon_monoxide":return s?"mdi:smoke-detector":"mdi:smoke-detector-alert";case"cold":return s?"mdi:thermometer":"mdi:Snowflake";case"connectivity":return s?"mdi:close-network-outline":"mdi:check-network-outline";case"door":return s?"mdi:door-closed":"mdi:door-open";case"garage_door":return s?"mdi:garage":"mdi:garage-open";case"power":case"plug":return s?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return s?"mdi:check-circle":"mdi:alert-circle";case"smoke":return s?"mdi:smoke-detector-variant":"mdi:smoke-detector-variant-alert";case"heat":return s?"mdi:thermometer":"mdi:fire";case"light":return s?"mdi:brightness-5":"mdi:brightness-7";case"lock":return s?"mdi:lock":"mdi:lock-open";case"moisture":return s?"mdi:water-off":"mdi:water";case"motion":return s?"mdi:motion-sensor-off":"mdi:motion-sensor";case"occupancy":return s?"mdi:home-outline":"mdi:Home";case"opening":return s?"mdi:square":"mdi:square-outline";case"presence":return s?"mdi:home-outline":"mdi:home";case"running":return s?"mdi:stop":"mdi:play";case"sound":return s?"mdi:music-note-off":"mdi:music-note";case"update":return s?"mdi:package":"mdi:package-up";case"vibration":return s?"mdi:crop-portrait":"mdi:vibrate";case"window":return s?"mdi:window-closed":"mdi:window-open";default:return s?"mdi:radiobox-blank":"mdi:checkbox-marked-circle"}})(i,e);case"button":switch(e?.attributes.device_class){case"restart":return"mdi:restart";case"update":return"mdi:package-up";default:return"mdi:gesture-tap-button"}case"camera":return"off"===i?"mdi:video-off":"mdi:video";case"cover":return((t,e)=>{const s="closed"!==t;switch(e?.attributes.device_class){case"garage":switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdigarage";default:return"mdi:Garage-open"}case"gate":switch(t){case"opening":case"closing":return"mdi:gate-arrow-right";case"closed":return"mdi:gate";default:return"mdi:gate-open"}case"door":return s?"mdi:door-open":"mdi:door-closed";case"damper":return s?"mdi:circle":"mdi:circle-slice-8";case"shutter":switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdi:window-shutter";default:return"mdi:window-shutter-open"}case"curtain":switch(t){case"opening":return"mdi:arrow-split-vertical";case"closing":return"mdi:arrow-collapse-horizontal";case"closed":return"mdi:curtains-closed";default:return"mdi:curtains"}case"blind":switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdi:blinds-horizontal-closed";default:return"mdi:blinds-horizontal"}case"shade":switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdi:roller-shade-closed";default:return"mdi:roller-shade"}case"window":switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdi:window--closed";default:return"mdi:window--open"}}switch(t){case"opening":return"mdi:arrow-up-box";case"closing":return"mdi:arrow-down-box";case"closed":return"mdi:window--closed";default:return"mdi:window--open"}})(i,e);case"device_tracker":return"router"===e?.attributes.source_type?"home"===i?"mdi:lan-connect":"mdi:lan-cisconnect":["bluetooth","bluetooth_le"].includes(e?.attributes.source_type)?"home"===i?"mdi:bluetooth-connect":"mdi:bluetooth":"not_home"===i?"mdi:account-arrow-right":"mdi:account";case"fan":return"off"===i?"mdi:fan-off":"mdi:fan";case"humidifier":return"off"===i?"mdi:air-humidifier-off":"mdi:air-humidifier";case"input_boolean":return"on"===i?"mdi:check-circle-outline":"mdi:close-circle-outline";case"input_datetime":if(!e?.attributes.has_date)return"mdi:clock";if(!e.attributes.has_time)return"mdi:calendar";break;case"lock":switch(i){case"unlocked":return"mdi:lock-open";case"jammed":return"mdi:lock-alert";case"locking":case"unlocking":return"mdi:lock-clock";default:return"mdi:lock"}case"media_player":switch(e?.attributes.device_class){case"speaker":switch(i){case"playing":return"mdi:speaker-play";case"paused":return"mdi:speaker-pause";case"off":return"mdi:speaker-off";default:return"mdi:speaker"}case"tv":switch(i){case"playing":return"mdi:television-play";case"paused":return"mdi:television-pause";case"off":return"mdi:television-off";default:return"mdi:television"}case"receiver":return"off"===i?"mdi:audio-video-off":"mdi:audio-video";default:switch(i){case"playing":case"paused":return"mdi:cast-connected";case"off":return"mdi:cast-off";default:return"mdi:cast"}}case"number":{const t=(t=>{const e=t?.attributes.device_class;if(e&&e in Pt)return Pt[e]})(e);if(t)return t;break}case"person":return"not_home"===i?"mdi:account-arrow-right":"mdi:account";case"switch":switch(e?.attributes.device_class){case"outlet":return"on"===i?"mdi:power-plug":"mdi:power-plug-off";case"switch":return"on"===i?"mdi:toggle-switch-variant":"mdi:toggle-switch-variant-off";default:return"mdi:toggle-switch-variant"}case"sensor":{const t=Ft(e);if(t)return t;break}case"sun":return"above_horizon"===e?.state?"mdi:white-balance-sunny":"mdi:weather-night";case"switch_as_x":return"mdi:swap-horizontal";case"threshold":return"mdi:chart-sankey";case"water_heater":return"off"===i?"mdi:water-boiler-off":"mdi:water-boiler"}if(t in Dt)return Dt[t]},Bt=t=>t?((t,e,s)=>{const i=Ut(t,e,s);return i||(console.warn(`Unable to find icon for domain ${t}`),Nt)})(Ot(t.entity_id),t):Nt;class jt extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({classes:{tool:{"sak-icon":!0,hover:!0},icon:{"sak-icon__icon":!0}},styles:{tool:{},icon:{}}},e),s),this.svg.iconSize=this.config.position.icon_size?this.config.position.icon_size:3,this.svg.iconPixels=4*this.svg.iconSize;const i=this.config.position.align?this.config.position.align:"center",o="center"===i?.5:"start"===i?-1:1,a=400/this._card.viewBox.width;this.svg.xpx=this.svg.cx,this.svg.ypx=this.svg.cy,!this._card.isSafari&&!this._card.iOS||this._card.isSafari16?(this.svg.xpx-=this.svg.iconPixels*o,this.svg.ypx=this.svg.ypx-.5*this.svg.iconPixels-.25*this.svg.iconPixels):(this.svg.iconSize*=a,this.svg.xpx=this.svg.xpx*a-this.svg.iconPixels*o*a,this.svg.ypx=this.svg.ypx*a-.5*this.svg.iconPixels*a-.25*this.svg.iconPixels*a),this.classes.tool={},this.classes.icon={},this.styles.tool={},this.styles.icon={},this.dev.debug&&console.log("EntityIconTool constructor coords, dimensions, config",this.coords,this.dimensions,this.config)}static{jt.sakIconCache={}}_buildIcon(t,e,s){return this.activeAnimation?.icon||s||e?.icon||t?.attributes?.icon||Bt(t)}_renderIcon(){this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.icon);const t=this._buildIcon(this._card.entities[this.defaultEntityIndex()],void 0!==this.defaultEntityIndex()?this._card.config.entities[this.defaultEntityIndex()]:void 0,this.config.icon);{this.svg.iconSize=this.config.position.icon_size?this.config.position.icon_size:2,this.svg.iconPixels=4*this.svg.iconSize,this.svg.iconSize=this.config.position.icon_size?this.config.position.icon_size:2,this.svg.iconPixels=bt.calculateSvgDimension(this.svg.iconSize);const t=this.config.position.align?this.config.position.align:"center",e="center"===t?.5:"start"===t?-1:1,s=400/this._card.viewBox.width;this.svg.xpx=this.svg.cx,this.svg.ypx=this.svg.cy,!this._card.isSafari&&!this._card.iOS||this._card.isSafari16?(this.svg.xpx=this.svg.cx-this.svg.iconPixels*e,this.svg.ypx=this.svg.cy-this.svg.iconPixels*e,this.dev.debug&&console.log("EntityIconTool::_renderIcon - svg values =",this.toolId,this.svg,this.config.cx,this.config.cy,t,e)):(this.svg.iconSize*=s,this.svg.iconPixels*=s,this.svg.xpx=this.svg.xpx*s-this.svg.iconPixels*e*s,this.svg.ypx=this.svg.ypx*s-.9*this.svg.iconPixels*s,this.svg.xpx=this.svg.cx*s-this.svg.iconPixels*e*s,this.svg.ypx=this.svg.cy*s-this.svg.iconPixels*e*s)}if(this.alternateColor||(this.alternateColor="rgba(0,0,0,0)"),jt.sakIconCache[t])this.iconSvg=jt.sakIconCache[t];else{const e=this._card.shadowRoot.getElementById("icon-".concat(this.toolId))?.shadowRoot?.querySelectorAll("*");this.iconSvg=e?e[0]?.path:void 0,this.iconSvg&&(jt.sakIconCache[t]=this.iconSvg)}let e;return this.iconSvg?(this.svg.iconSize=this.config.position.icon_size?this.config.position.icon_size:2,this.svg.iconPixels=bt.calculateSvgDimension(this.svg.iconSize),this.svg.x1=this.svg.cx-this.svg.iconPixels/2,this.svg.y1=this.svg.cy-this.svg.iconPixels/2,this.svg.x1=this.svg.cx-.5*this.svg.iconPixels,this.svg.y1=this.svg.cy-.5*this.svg.iconPixels,e=this.svg.iconPixels/24,U` `):U`
this._handleAnimationEvent(t,this)} @animationiteration=${t=>this._handleAnimationEvent(t,this)} style="animation: flash 0.15s 20;">
`}_handleAnimationEvent(t,e){t.stopPropagation(),t.preventDefault(),e.iconSvg=this._card.shadowRoot.getElementById("icon-".concat(this.toolId))?.shadowRoot?.querySelectorAll("*")[0]?.path,e.iconSvg&&e._card.requestUpdate()}firstUpdated(t){}render(){return U` this.handleTapEvent(t,this.config)} > ${this._renderIcon()} `}}class qt extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({classes:{tool:{"sak-name":!0,hover:!0},name:{"sak-name__name":!0}},styles:{tool:{},name:{}}},e),s),this._name={},this.classes.tool={},this.classes.name={},this.styles.tool={},this.styles.name={},this.dev.debug&&console.log("EntityName constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}_buildName(t,e){return this.activeAnimation?.name||e.name||t.attributes.friendly_name}_renderEntityName(){this.MergeAnimationClassIfChanged(),this.MergeColorFromState(this.styles.name),this.MergeAnimationStyleIfChanged();const t=this.textEllipsis(this._buildName(this._card.entities[this.defaultEntityIndex()],this._card.config.entities[this.defaultEntityIndex()]),this.config?.show?.ellipsis);return U` ${t} `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderEntityName()} `}}var Ht=function(){return Ht=Object.assign||function(t){for(var e,s=1,i=arguments.length;s{const i=e?(t=>{switch(t.number_format){case Gt.comma_decimal:return["en-US","en"];case Gt.decimal_comma:return["de","es","it"];case Gt.space_comma:return["fr","sv","cs"];case Gt.system:return;default:return t.language}})(e):void 0;if(Number.isNaN=Number.isNaN||function t(e){return"number"==typeof e&&t(e)},e?.number_format!==Gt.none&&!Number.isNaN(Number(t))&&Intl)try{return new Intl.NumberFormat(i,Yt(t,s)).format(Number(t))}catch(o){return console.error(o),new Intl.NumberFormat(void 0,Yt(t,s)).format(Number(t))}return!Number.isNaN(Number(t))&&""!==t&&e?.number_format===Gt.none&&Intl?new Intl.NumberFormat("en-US",Yt(t,{...s,useGrouping:!1})).format(Number(t)):"string"==typeof t?t:`${((t,e=2)=>Math.round(t*10**e)/10**e)(t,s?.maximumFractionDigits).toString()}${"currency"===s?.style?` ${s.currency}`:""}`},Yt=(t,e)=>{const s={maximumFractionDigits:2,...e};if("string"!=typeof t)return s;if(!e||void 0===e.minimumFractionDigits&&void 0===e.maximumFractionDigits){const e=t.indexOf(".")>-1?t.split(".")[1].length:0;s.minimumFractionDigits=e,s.maximumFractionDigits=e}return s};var Xt=Number.isNaN||function(t){return"number"==typeof t&&t!=t};function Zt(t,e){if(t.length!==e.length)return!1;for(var s=0;snew Intl.DateTimeFormat(t.language,{weekday:"long",month:"long",day:"numeric"}))),te=Kt((t=>new Intl.DateTimeFormat(t.language,{year:"numeric",month:"long",day:"numeric"}))),ee=Kt((t=>new Intl.DateTimeFormat(t.language,{year:"numeric",month:"numeric",day:"numeric"}))),se=Kt((t=>new Intl.DateTimeFormat(t.language,{day:"numeric",month:"short"}))),ie=Kt((t=>new Intl.DateTimeFormat(t.language,{month:"long",year:"numeric"}))),oe=Kt((t=>new Intl.DateTimeFormat(t.language,{month:"long"})));Kt((t=>new Intl.DateTimeFormat(t.language,{year:"numeric"})));const ae=Kt((t=>new Intl.DateTimeFormat(t.language,{weekday:"long"}))),ne=Kt((t=>new Intl.DateTimeFormat(t.language,{weekday:"short"})));var re;!function(t){t.language="language",t.system="system",t.am_pm="12",t.twenty_four="24"}(re=re||(re={}));const he=Kt((t=>{if(t.time_format===re.language||t.time_format===re.system){const e=t.time_format===re.language?t.language:void 0,s=(new Date).toLocaleString(e);return s.includes("AM")||s.includes("PM")}return t.time_format===re.am_pm})),le=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{hour:"numeric",minute:"2-digit",hour12:he(t)}))),ce=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{hour:he(t)?"numeric":"2-digit",minute:"2-digit",second:"2-digit",hour12:he(t)}))),de=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{weekday:"long",hour:he(t)?"numeric":"2-digit",minute:"2-digit",hour12:he(t)}))),ge=Kt((()=>new Intl.DateTimeFormat("en-GB",{hour:"numeric",minute:"2-digit",hour12:!1}))),ue=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{year:"numeric",month:"long",day:"numeric",hour:he(t)?"numeric":"2-digit",minute:"2-digit",hour12:he(t)}))),me=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{year:"numeric",month:"short",day:"numeric",hour:he(t)?"numeric":"2-digit",minute:"2-digit",hour12:he(t)}))),pe=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{month:"short",day:"numeric",hour:he(t)?"numeric":"2-digit",minute:"2-digit",hour12:he(t)}))),ve=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{year:"numeric",month:"long",day:"numeric",hour:he(t)?"numeric":"2-digit",minute:"2-digit",second:"2-digit",hour12:he(t)}))),fe=Kt((t=>new Intl.DateTimeFormat("en"!==t.language||he(t)?t.language:"en-u-hc-h23",{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"2-digit",hour12:he(t)}))),ye=(t,e=2)=>{let s=`${t}`;for(let i=1;ifunction(t){const e=Math.floor(t/1e3/3600),s=Math.floor(t/1e3%3600/60),i=Math.floor(t/1e3%3600%60),o=Math.floor(t%1e3);return e>0?`${e}:${ye(s)}:${ye(i)}`:s>0?`${s}:${ye(i)}`:i>0||o>0?`${i}${o>0?`.${ye(o,3)}`:""}`:null}(parseFloat(t)*_e[e])||"0";class we extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({show:{uom:"end"},classes:{tool:{"sak-state":!0,hover:!0},state:{"sak-state__value":!0},uom:{"sak-state__uom":!0}},styles:{tool:{},state:{},uom:{}}},e),s),this.classes.tool={},this.classes.state={},this.classes.uom={},this.styles.tool={},this.styles.state={},this.styles.uom={},this.dev.debug&&console.log("EntityStateTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}static testTimeDate=!1;set value(t){super.value=t}formatStateString(t,e){const s=this._card._hass.selectedLanguage||this._card._hass.language;let i={};if(i.language=s,["relative","total","datetime","datetime-short","datetime-short_with-year","datetime_seconds","datetime-numeric","date","date_month","date_month_year","date-short","date-numeric","date_weekday","date_weekday_day","date_weekday-short","time","time-24h","time_weekday","time_seconds"].includes(e.format)){const a=new Date(t);if(!(a instanceof Date)||isNaN(a.getTime()))return t;let n;switch(e.format){case"relative":const t=function(t,e,s){void 0===e&&(e=Date.now()),void 0===s&&(s={});var i=Ht(Ht({},Wt),s||{}),o=(+t-+e)/1e3;if(Math.abs(o)0)return{value:Math.round(c),unit:"year"};var d=12*c+h.getMonth()-l.getMonth();if(Math.round(Math.abs(d))>0)return{value:Math.round(d),unit:"month"};var g=o/604800;return{value:Math.round(g),unit:"week"}}(a,new Date);n=new Intl.RelativeTimeFormat(s,{numeric:"auto"}).format(t.value,t.unit);break;case"total":case"precision":n="Not Yet Supported";break;case"datetime":n=((t,e)=>ue(e).format(t))(a,i);break;case"datetime-short":n=((t,e)=>pe(e).format(t))(a,i);break;case"datetime-short_with-year":n=((t,e)=>me(e).format(t))(a,i);break;case"datetime_seconds":n=((t,e)=>ve(e).format(t))(a,i);break;case"datetime-numeric":n=((t,e)=>fe(e).format(t))(a,i);break;case"date":n=((t,e)=>te(e).format(t))(a,i);break;case"date_month":n=((t,e)=>oe(e).format(t))(a,i);break;case"date_month_year":n=((t,e)=>ie(e).format(t))(a,i);break;case"date-short":n=((t,e)=>se(e).format(t))(a,i);break;case"date-numeric":n=((t,e)=>ee(e).format(t))(a,i);break;case"date_weekday":n=((t,e)=>ae(e).format(t))(a,i);break;case"date_weekday-short":n=((t,e)=>ne(e).format(t))(a,i);break;case"date_weekday_day":n=((t,e)=>Qt(e).format(t))(a,i);break;case"time":n=((t,e)=>le(e).format(t))(a,i);break;case"time-24h":o=a,n=ge().format(o);break;case"time_weekday":n=((t,e)=>de(e).format(t))(a,i);break;case"time_seconds":n=((t,e)=>ce(e).format(t))(a,i)}return n}var o;return isNaN(parseFloat(t))||!isFinite(t)?t:"brightness"===e.format||"brightness_pct"===e.format?`${Math.round(t/255*100)} %`:"duration"===e.format?be(t,"s"):void 0}_renderState(){this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.state);let t=this._stateValue;const e=this._card.entities[this.defaultEntityIndex()];if(void 0===e)return U``;if([void 0,"undefined"].includes(t))return U``;if(void 0===t)return U``;const s=this._card._hass.entities[e.entity_id],i=this._card.config.entities[this.defaultEntityIndex()],o=Ot(this._card.entities[this.defaultEntityIndex()].entity_id),a=this.config.locale_tag?this.config.locale_tag+t.toLowerCase():void 0;if(void 0!==i.format&&void 0!==t&&(t=this.formatStateString(t,i)),(t&&isNaN(t)&&!i.secondary_info||i.attribute)&&(t=a&&this._card._hass.localize(a)||s?.translation_key&&this._card._hass.localize(`component.${s.platform}.entity.${o}.${s.translation_key}.state.${t}`)||s?.attributes?.device_class&&this._card._hass.localize(`component.${o}.entity_component.${s.attributes.device_class}.state.${t}`)||this._card._hass.localize(`component.${o}.entity_component._.state.${t}`)||t,t=this.textEllipsis(t,this.config?.show?.ellipsis)),["undefined","unknown","unavailable","-ua-"].includes(t)&&(t=this._card._hass.localize(`state.default.${t}`)),!isNaN(t)){let e={};e=Yt(t,e),void 0!==this._card.config.entities[this.defaultEntityIndex()].decimals&&(e.maximumFractionDigits=this._card.config.entities[this.defaultEntityIndex()].decimals,e.minimumFractionDigits=e.maximumFractionDigits),t=Jt(t,this._card._hass.locale,e)}return U` ${this.config?.text?.before?this.config.text.before:""}${t}${this.config?.text?.after?this.config.text.after:""} `}_renderUom(){if("none"===this.config.show.uom||void 0===this._stateValue)return U``;{this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.uom);let t=this.styles.state["font-size"],e=.5,s="em";const i=t.match(/\D+|\d*\.?\d+/g);2===i.length?(e=.6*Number(i[0]),s=i[1]):console.error("Cannot determine font-size for state/unit",t),t={"font-size":e+s},this.styles.uom=_t.mergeDeep(this.config.styles.uom,this.styles.uom,t);const o=this._card._buildUom(this.derivedEntity,this._card.entities[this.defaultEntityIndex()],this._card.config.entities[this.defaultEntityIndex()]);return"end"===this.config.show.uom?U` ${o} `:"bottom"===this.config.show.uom?U` ${o} `:"top"===this.config.show.uom?U` ${o} `:U``}}firstUpdated(t){}updated(t){}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderState()} ${this._renderUom()} `}}class xe extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,radius:45},card_filter:"card--filter-none",horseshoe_scale:{min:0,max:100,width:3,color:"var(--primary-background-color)"},horseshoe_state:{width:6,color:"var(--primary-color)"},show:{horseshoe:!0,scale_tickmarks:!1,horseshoe_style:"fixed"}},e),s),this.HORSESHOE_RADIUS_SIZE=180,this.TICKMARKS_RADIUS_SIZE=172,this.HORSESHOE_PATH_LENGTH=520/360*Math.PI*this.HORSESHOE_RADIUS_SIZE,this.config.entity_index=this.config.entity_index?this.config.entity_index:0,this.svg.radius=bt.calculateSvgDimension(this.config.position.radius),this.svg.radius_ticks=bt.calculateSvgDimension(.95*this.config.position.radius),this.svg.horseshoe_scale={},this.svg.horseshoe_scale.width=bt.calculateSvgDimension(this.config.horseshoe_scale.width),this.svg.horseshoe_state={},this.svg.horseshoe_state.width=bt.calculateSvgDimension(this.config.horseshoe_state.width),this.svg.horseshoe_scale.dasharray=52/36*Math.PI*this.svg.radius,this.svg.rotate={},this.svg.rotate.degrees=-220,this.svg.rotate.cx=this.svg.cx,this.svg.rotate.cy=this.svg.cy,this.colorStops={},this.config.color_stops&&Object.keys(this.config.color_stops).forEach((t=>{this.colorStops[t]=this.config.color_stops[t]})),this.sortedStops=Object.keys(this.colorStops).map((t=>Number(t))).sort(((t,e)=>t-e)),this.colorStopsMinMax={},this.colorStopsMinMax[this.config.horseshoe_scale.min]=this.colorStops[this.sortedStops[0]],this.colorStopsMinMax[this.config.horseshoe_scale.max]=this.colorStops[this.sortedStops[this.sortedStops.length-1]],this.color0=this.colorStops[this.sortedStops[0]],this.color1=this.colorStops[this.sortedStops[this.sortedStops.length-1]],this.angleCoords={x1:"0%",y1:"0%",x2:"100%",y2:"0%"},this.color1_offset="0%",this.dev.debug&&console.log("HorseshoeTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}set value(t){if(this._stateValue===t)return;this._stateValuePrev=this._stateValue||t,this._stateValue=t,this._stateValueIsDirty=!0;const e=this.config.horseshoe_scale.min||0,s=this.config.horseshoe_scale.max||100,i=Math.min(bt.calculateValueBetween(e,s,t),1),o=i*this.HORSESHOE_PATH_LENGTH,a=10*this.HORSESHOE_RADIUS_SIZE;this.dashArray=`${o} ${a}`;const n=this.config.show.horseshoe_style;if("fixed"===n)this.stroke_color=this.config.horseshoe_state.color,this.color0=this.config.horseshoe_state.color,this.color1=this.config.horseshoe_state.color,this.color1_offset="0%";else if("autominmax"===n){const e=Et.calculateColor(t,this.colorStopsMinMax,!0);this.color0=e,this.color1=e,this.color1_offset="0%"}else if("colorstop"===n||"colorstopgradient"===n){const e=Et.calculateColor(t,this.colorStops,"colorstopgradient"===n);this.color0=e,this.color1=e,this.color1_offset="0%"}else if("lineargradient"===n){const t={x1:"0%",y1:"0%",x2:"100%",y2:"0%"};this.color1_offset=`${Math.round(100*(1-i))}%`,this.angleCoords=t}this.dev.debug&&console.log("HorseshoeTool set value",this.cardId,t)}_renderTickMarks(){const{config:t}=this;if(!t.show.scale_tickmarks)return;const e=t.horseshoe_scale.color?t.horseshoe_scale.color:"var(--primary-background-color)",s=t.horseshoe_scale.ticksize?t.horseshoe_scale.ticksize:(t.horseshoe_scale.max-t.horseshoe_scale.min)/10,i=t.horseshoe_scale.min%s,o=t.horseshoe_scale.min+(0===i?0:s-i),a=(o-t.horseshoe_scale.min)/(t.horseshoe_scale.max-t.horseshoe_scale.min)*260,n=(t.horseshoe_scale.max-o)/s;let r=Math.floor(n);const h=(260-a)/n;Math.floor(r*s+o)<=t.horseshoe_scale.max&&(r+=1);const l=this.svg.horseshoe_scale.width?this.svg.horseshoe_scale.width/2:3;let c;const d=[];let g;for(g=0;g `;return U`${d}`}_renderHorseShoe(){if(this.config.show.horseshoe)return U` ${this._renderTickMarks()} `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderHorseShoe()} `}}class Se extends Ct{constructor(t,e,s){if(super(t,_t.mergeDeep({position:{orientation:"vertical",length:"10",cx:"50",cy:"50"},classes:{tool:{"sak-line":!0,hover:!0},line:{"sak-line__line":!0}},styles:{tool:{},line:{}}},e),s),!["horizontal","vertical","fromto"].includes(this.config.position.orientation))throw Error("LineTool::constructor - invalid orientation [vertical, horizontal, fromto] = ",this.config.position.orientation);["horizontal","vertical"].includes(this.config.position.orientation)&&(this.svg.length=bt.calculateSvgDimension(e.position.length)),"fromto"===this.config.position.orientation?(this.svg.x1=bt.calculateSvgCoordinate(e.position.x1,this.toolsetPos.cx),this.svg.y1=bt.calculateSvgCoordinate(e.position.y1,this.toolsetPos.cy),this.svg.x2=bt.calculateSvgCoordinate(e.position.x2,this.toolsetPos.cx),this.svg.y2=bt.calculateSvgCoordinate(e.position.y2,this.toolsetPos.cy)):"vertical"===this.config.position.orientation?(this.svg.x1=this.svg.cx,this.svg.y1=this.svg.cy-this.svg.length/2,this.svg.x2=this.svg.cx,this.svg.y2=this.svg.cy+this.svg.length/2):"horizontal"===this.config.position.orientation&&(this.svg.x1=this.svg.cx-this.svg.length/2,this.svg.y1=this.svg.cy,this.svg.x2=this.svg.cx+this.svg.length/2,this.svg.y2=this.svg.cy),this.classes.line={},this.styles.line={},this.dev.debug&&console.log("LineTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}_renderLine(){return this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.line),this.dev.debug&&console.log("_renderLine",this.config.position.orientation,this.svg.x1,this.svg.y1,this.svg.x2,this.svg.y2),U` `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderLine()} `}}class $e extends Ct{constructor(t,e,s){switch(super(t,_t.mergeDeep({descr:"none",position:{cx:50,cy:50,orientation:"horizontal",active:{width:0,height:0,radius:0},track:{width:16,height:7,radius:3.5},thumb:{width:9,height:9,radius:4.5,offset:4.5},label:{placement:"none"}},show:{uom:"end",active:!1},classes:{tool:{"sak-slider":!0,hover:!0},capture:{"sak-slider__capture":!0},active:{"sak-slider__active":!0},track:{"sak-slider__track":!0},thumb:{"sak-slider__thumb":!0},label:{"sak-slider__value":!0},uom:{"sak-slider__uom":!0}},styles:{tool:{},capture:{},active:{},track:{},thumb:{},label:{},uom:{}}},e),s),this.svg.activeTrack={},this.svg.activeTrack.radius=bt.calculateSvgDimension(this.config.position.active.radius),this.svg.activeTrack.height=bt.calculateSvgDimension(this.config.position.active.height),this.svg.activeTrack.width=bt.calculateSvgDimension(this.config.position.active.width),this.svg.track={},this.svg.track.radius=bt.calculateSvgDimension(this.config.position.track.radius),this.svg.thumb={},this.svg.thumb.radius=bt.calculateSvgDimension(this.config.position.thumb.radius),this.svg.thumb.offset=bt.calculateSvgDimension(this.config.position.thumb.offset),this.svg.capture={},this.svg.label={},this.config.position.orientation){case"horizontal":case"vertical":this.svg.capture.width=bt.calculateSvgDimension(this.config.position.capture.width||1.1*this.config.position.track.width),this.svg.capture.height=bt.calculateSvgDimension(this.config.position.capture.height||3*this.config.position.thumb.height),this.svg.track.width=bt.calculateSvgDimension(this.config.position.track.width),this.svg.track.height=bt.calculateSvgDimension(this.config.position.track.height),this.svg.thumb.width=bt.calculateSvgDimension(this.config.position.thumb.width),this.svg.thumb.height=bt.calculateSvgDimension(this.config.position.thumb.height),this.svg.capture.x1=this.svg.cx-this.svg.capture.width/2,this.svg.capture.y1=this.svg.cy-this.svg.capture.height/2,this.svg.track.x1=this.svg.cx-this.svg.track.width/2,this.svg.track.y1=this.svg.cy-this.svg.track.height/2,this.svg.activeTrack.x1="horizontal"===this.config.position.orientation?this.svg.track.x1:this.svg.cx-this.svg.activeTrack.width/2,this.svg.activeTrack.y1=this.svg.cy-this.svg.activeTrack.height/2,this.svg.thumb.x1=this.svg.cx-this.svg.thumb.width/2,this.svg.thumb.y1=this.svg.cy-this.svg.thumb.height/2;break;default:throw console.error("RangeSliderTool - constructor: invalid orientation [vertical, horizontal] = ",this.config.position.orientation),Error("RangeSliderTool::constructor - invalid orientation [vertical, horizontal] = ",this.config.position.orientation)}if("vertical"===this.config.position.orientation)this.svg.track.y2=this.svg.cy+this.svg.track.height/2,this.svg.activeTrack.y2=this.svg.track.y2;switch(this.config.position.label.placement){case"position":this.svg.label.cx=bt.calculateSvgCoordinate(this.config.position.label.cx,0),this.svg.label.cy=bt.calculateSvgCoordinate(this.config.position.label.cy,0);break;case"thumb":this.svg.label.cx=this.svg.cx,this.svg.label.cy=this.svg.cy;break;case"none":break;default:throw console.error("RangeSliderTool - constructor: invalid label placement [none, position, thumb] = ",this.config.position.label.placement),Error("RangeSliderTool::constructor - invalid label placement [none, position, thumb] = ",this.config.position.label.placement)}this.classes.capture={},this.classes.track={},this.classes.thumb={},this.classes.label={},this.classes.uom={},this.styles.capture={},this.styles.track={},this.styles.thumb={},this.styles.label={},this.styles.uom={},this.svg.scale={},this.svg.scale.min=this.valueToSvg(this,this.config.scale.min),this.svg.scale.max=this.valueToSvg(this,this.config.scale.max),this.svg.scale.step=this.config.scale.step,this.dev.debug&&console.log("RangeSliderTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}svgCoordinateToSliderValue(t,e){let s,i,o,a;switch(t.config.position.orientation){case"horizontal":o=e.x-t.svg.track.x1-this.svg.thumb.width/2,i=o/(t.svg.track.width-this.svg.thumb.width);break;case"vertical":a=t.svg.track.y2-this.svg.thumb.height/2-e.y,i=a/(t.svg.track.height-this.svg.thumb.height)}return s=(t.config.scale.max-t.config.scale.min)*i+t.config.scale.min,s=Math.round(s/this.svg.scale.step)*this.svg.scale.step,s=Math.max(Math.min(this.config.scale.max,s),this.config.scale.min),s}valueToSvg(t,e){if("horizontal"===t.config.position.orientation){const s=bt.calculateValueBetween(t.config.scale.min,t.config.scale.max,e)*(t.svg.track.width-this.svg.thumb.width);return t.svg.track.x1+this.svg.thumb.width/2+s}if("vertical"===t.config.position.orientation){const s=bt.calculateValueBetween(t.config.scale.min,t.config.scale.max,e)*(t.svg.track.height-this.svg.thumb.height);return t.svg.track.y2-this.svg.thumb.height/2-s}}updateValue(t,e){this._value=this.svgCoordinateToSliderValue(t,e);Math.abs(0)<.01&&this.rid&&(window.cancelAnimationFrame(this.rid),this.rid=null)}updateThumb(t,e){switch(t.config.position.orientation){default:case"horizontal":if(this.config.position.label.placement,this.dragging){const s="thumb"===this.config.position.label.placement?-50:0,i=`translate(${e.x-this.svg.cx}px , ${s}px)`;t.elements.thumbGroup.style.transform=i}else t.elements.thumbGroup.style.transform=`translate(${e.x-this.svg.cx}px, 0px)`;break;case"vertical":if(this.dragging){const s=`translate(${"thumb"===this.config.position.label.placement?-50:0}px, ${e.y-this.svg.cy}px)`;t.elements.thumbGroup.style.transform=s}else t.elements.thumbGroup.style.transform=`translate(0px, ${e.y-this.svg.cy}px)`}t.updateLabel(t,e)}updateActiveTrack(t,e){if(t.config.show.active)switch(t.config.position.orientation){default:case"horizontal":this.dragging&&t.elements.activeTrack.setAttribute("width",Math.abs(this.svg.activeTrack.x1-e.x+this.svg.cx));break;case"vertical":this.dragging&&(t.elements.activeTrack.setAttribute("y",e.y-this.svg.cy),t.elements.activeTrack.setAttribute("height",Math.abs(t.svg.activeTrack.y2-e.y+this.svg.cx)))}}updateLabel(t,e){this.dev.debug&&console.log("SLIDER - updateLabel start",e,t.config.position.orientation);const s=this._card.config.entities[this.defaultEntityIndex()].decimals||0,i=10**s;t.labelValue2=(Math.round(t.svgCoordinateToSliderValue(t,e)*i)/i).toFixed(s),"none"!==this.config.position.label.placement&&(t.elements.label.textContent=t.labelValue2)}mouseEventToPoint(t){let e=this.elements.svg.createSVGPoint();e.x=t.touches?t.touches[0].clientX:t.clientX,e.y=t.touches?t.touches[0].clientY:t.clientY;const s=this.elements.svg.getScreenCTM().inverse();return e=e.matrixTransform(s),e}callDragService(){void 0!==this.labelValue2&&(this.labelValuePrev!==this.labelValue2&&(this.labelValuePrev=this.labelValue2,this._processTapEvent(this._card,this._card._hass,this.config,this.config.user_actions.tap_action,this._card.config.entities[this.defaultEntityIndex()]?.entity,this.labelValue2)),this.dragging&&(this.timeOutId=setTimeout((()=>this.callDragService()),this.config.user_actions.drag_action.update_interval)))}callTapService(){void 0!==this.labelValue2&&this.labelValuePrev!==this.labelValue2&&(this.labelValuePrev=this.labelValue2,this._processTapEvent(this._card,this._card._hass,this.config,this.config.user_actions?.tap_action,this._card.config.entities[this.defaultEntityIndex()]?.entity,this.labelValue2))}firstUpdated(t){function e(){this.rid=window.requestAnimationFrame(e),this.updateValue(this,this.m),this.updateThumb(this,this.m),this.updateActiveTrack(this,this.m)}function s(t){let s;if(t.preventDefault(),this.dragging){switch(this.m=this.mouseEventToPoint(t),this.config.position.orientation){case"horizontal":s=this.svgCoordinateToSliderValue(this,this.m),this.m.x=this.valueToSvg(this,s),this.m.x=Math.max(this.svg.scale.min,Math.min(this.m.x,this.svg.scale.max)),this.m.x=Math.round(this.m.x/this.svg.scale.step)*this.svg.scale.step;break;case"vertical":s=this.svgCoordinateToSliderValue(this,this.m),this.m.y=this.valueToSvg(this,s),this.m.y=Math.round(this.m.y/this.svg.scale.step)*this.svg.scale.step}e.call(this)}}function i(t){t.preventDefault(),window.addEventListener("pointermove",s.bind(this),!1),window.addEventListener("pointerup",o.bind(this),!1);const i=this.mouseEventToPoint(t),a=this.svg.thumb.x1+this.svg.thumb.cx;i.x>a-10&&i.x0?this.timeOutId=setTimeout((()=>this.callDragService()),this.config.user_actions.drag_action.update_interval):this.timeOutId=null),this.m=this.mouseEventToPoint(t),"horizontal"===this.config.position.orientation?this.m.x=Math.round(this.m.x/this.svg.scale.step)*this.svg.scale.step:this.m.y=Math.round(this.m.y/this.svg.scale.step)*this.svg.scale.step,this.dev.debug&&console.log("pointerDOWN",Math.round(100*this.m.x)/100),e.call(this)):kt(window,"haptic","error")}function o(t){t.preventDefault(),window.removeEventListener("pointermove",s.bind(this),!1),window.removeEventListener("pointerup",o.bind(this),!1),window.removeEventListener("mousemove",s.bind(this),!1),window.removeEventListener("touchmove",s.bind(this),!1),window.removeEventListener("mouseup",o.bind(this),!1),window.removeEventListener("touchend",o.bind(this),!1),this.dragging&&(this.dragging=!1,clearTimeout(this.timeOutId),this.target=0,this.dev.debug&&console.log("pointerUP"),e.call(this),this.callTapService())}this.labelValue=this._stateValue,this.dev.debug&&console.log("slider - firstUpdated"),this.elements={},this.elements.svg=this._card.shadowRoot.getElementById("rangeslider-".concat(this.toolId)),this.elements.capture=this.elements.svg.querySelector("#capture"),this.elements.track=this.elements.svg.querySelector("#rs-track"),this.elements.activeTrack=this.elements.svg.querySelector("#active-track"),this.elements.thumbGroup=this.elements.svg.querySelector("#rs-thumb-group"),this.elements.thumb=this.elements.svg.querySelector("#rs-thumb"),this.elements.label=this.elements.svg.querySelector("#rs-label tspan"),this.dev.debug&&console.log("slider - firstUpdated svg = ",this.elements.svg,"path=",this.elements.path,"thumb=",this.elements.thumb,"label=",this.elements.label,"text=",this.elements.text),this.elements.svg.addEventListener("touchstart",i.bind(this),!1),this.elements.svg.addEventListener("mousedown",i.bind(this),!1)}set value(t){super.value=t,this.dragging||(this.labelValue=this._stateValue)}_renderUom(){if("none"===this.config.show.uom)return U``;{this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.uom);let t=this.styles.label["font-size"],e=.5,s="em";const i=t.match(/\D+|\d*\.?\d+/g);2===i.length?(e=.6*Number(i[0]),s=i[1]):console.error("Cannot determine font-size for state/unit",t),t={"font-size":e+s},this.styles.uom=_t.mergeDeep(this.config.styles.uom,t);const o=this._card._buildUom(this.derivedEntity,this._card.entities[this.defaultEntityIndex()],this._card.config.entities[this.defaultEntityIndex()]);return"end"===this.config.show.uom?U` ${o} `:"bottom"===this.config.show.uom?U` ${o} `:"top"===this.config.show.uom?U` ${o} `:U` ERRR `}}_renderRangeSlider(){let t,e;switch(this.dev.debug&&console.log("slider - _renderRangeSlider"),this.MergeAnimationClassIfChanged(),this.MergeColorFromState(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(),this.renderValue=this._stateValue,this.dragging?this.renderValue=this.labelValue2:this.elements?.label&&(this.elements.label.textContent=this.renderValue),this.config.position.label.placement){case"none":this.styles.label.display="none",this.styles.uom.display="none";break;case"position":t="horizontal"===this.config.position.orientation?this.valueToSvg(this,Number(this.renderValue))-this.svg.cx:0,e="vertical"===this.config.position.orientation?this.valueToSvg(this,Number(this.renderValue))-this.svg.cy:0;break;case"thumb":t="horizontal"===this.config.position.orientation?-this.svg.label.cx+this.valueToSvg(this,Number(this.renderValue)):0,e="vertical"===this.config.position.orientation?this.valueToSvg(this,Number(this.renderValue)):0,this.dragging&&("horizontal"===this.config.position.orientation?e-=50:t-=50);break;default:console.error("_renderRangeSlider(), invalid label placement",this.config.position.label.placement)}function s(t){return"thumb"===this.config.position.label.placement&&t?U` ${this.renderValue} ${this._renderUom()} `:"position"!==this.config.position.label.placement||t?void 0:U` ${this.renderValue?this.renderValue:""} ${this.renderValue?this._renderUom():""} `}this.svg.thumb.cx=t,this.svg.thumb.cy=e;const i=[];return i.push(U` ${function(){return this.config.show.active?"horizontal"===this.config.position.orientation?U` `:U` `:U``}.call(this)} ${function(){return U` ${s.call(this,!0)} `}.call(this)} ${s.call(this,!1)} `),i}render(){return U` ${this._renderRangeSlider()} `}}class ke extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,width:50,height:50,rx:0},classes:{tool:{"sak-rectangle":!0,hover:!0},rectangle:{"sak-rectangle__rectangle":!0}},styles:{rectangle:{}}},e),s),this.svg.rx=e.position.rx?bt.calculateSvgDimension(e.position.rx):0,this.classes.rectangle={},this.styles.rectangle={},this.dev.debug&&console.log("RectangleTool constructor config, svg",this.toolId,this.config,this.svg)}set value(t){super.value=t}_renderRectangle(){return this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.rectangle),U` `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderRectangle()} `}}class Ee extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,width:50,height:50,radius:{all:0}},classes:{tool:{"sak-rectex":!0,hover:!0},rectex:{"sak-rectex__rectex":!0}},styles:{tool:{},rectex:{}}},e),s),this.classes.tool={},this.classes.rectex={},this.styles.tool={},this.styles.rectex={};const i=Math.min(this.svg.height,this.svg.width)/2;let o=0;o=bt.calculateSvgDimension(this.config.position.radius.all),this.svg.radiusTopLeft=+Math.min(i,Math.max(0,bt.calculateSvgDimension(this.config.position.radius.top_left||this.config.position.radius.left||this.config.position.radius.top||o)))||0,this.svg.radiusTopRight=+Math.min(i,Math.max(0,bt.calculateSvgDimension(this.config.position.radius.top_right||this.config.position.radius.right||this.config.position.radius.top||o)))||0,this.svg.radiusBottomLeft=+Math.min(i,Math.max(0,bt.calculateSvgDimension(this.config.position.radius.bottom_left||this.config.position.radius.left||this.config.position.radius.bottom||o)))||0,this.svg.radiusBottomRight=+Math.min(i,Math.max(0,bt.calculateSvgDimension(this.config.position.radius.bottom_right||this.config.position.radius.right||this.config.position.radius.bottom||o)))||0,this.dev.debug&&console.log("RectangleToolEx constructor config, svg",this.toolId,this.config,this.svg)}set value(t){super.value=t}_renderRectangleEx(){this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(this.styles),this.MergeAnimationStyleIfChanged(),this.config.hasOwnProperty("csnew")?this.MergeColorFromState2(this.styles.rectex,"rectex"):this.MergeColorFromState(this.styles.rectex),this.counter||(this.counter=0),this.counter+=1;const t=U` `;return U`${t}`}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderRectangleEx()} `}}class Ce extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,radius:50,side_count:6,side_skip:1,angle_offset:0},classes:{tool:{"sak-polygon":!0,hover:!0},regpoly:{"sak-polygon__regpoly":!0}},styles:{tool:{},regpoly:{}}},e),s),this.svg.radius=bt.calculateSvgDimension(e.position.radius),this.classes.regpoly={},this.styles.regpoly={},this.dev.debug&&console.log("RegPolyTool constructor config, svg",this.toolId,this.config,this.svg)}set value(t){super.value=t}_renderRegPoly(){return this.MergeAnimationStyleIfChanged(),this.MergeColorFromState(this.styles.regpoly),U` 0&&(l+=n,r=o+~~(s*Math.cos(l)),h=a+~~(s*Math.sin(l)),c+=`M${r} ${h} `);return c+="z",c}(this.config.position.side_count,this.config.position.side_skip,this.svg.radius,this.config.position.angle_offset,this.svg.cx,this.svg.cy)}" style="${rt(this.styles.regpoly)}" /> `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderRegPoly()} `}}class Ie extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,radius:45,width:3,margin:1.5},color:"var(--primary-color)",classes:{tool:{"sak-segarc":!0},foreground:{},background:{}},styles:{tool:{},foreground:{},background:{}},segments:{},colorstops:[],scale:{min:0,max:100,width:2,offset:-3.5},show:{style:"fixedcolor",scale:!1},isScale:!1,animation:{duration:1.5}},e),s),this.dev.performance&&console.time(`--\x3e ${this.toolId} PERFORMANCE SegmentedArcTool::constructor`),this.svg.radius=bt.calculateSvgDimension(e.position.radius),this.svg.radiusX=bt.calculateSvgDimension(e.position.radius_x||e.position.radius),this.svg.radiusY=bt.calculateSvgDimension(e.position.radius_y||e.position.radius),this.svg.segments={},this.svg.segments.gap=bt.calculateSvgDimension(this.config.segments.gap),this.svg.scale_offset=bt.calculateSvgDimension(this.config.scale.offset),this._firstUpdatedCalled=!1,this._stateValue=null,this._stateValuePrev=null,this._stateValueIsDirty=!1,this._renderFrom=null,this._renderTo=null,this.rAFid=null,this.cancelAnimation=!1,this.arcId=null,this._cache=[],this._segmentAngles=[],this._segments={},this._arc={},this._arc.size=Math.abs(this.config.position.end_angle-this.config.position.start_angle),this._arc.clockwise=this.config.position.end_angle>this.config.position.start_angle,this._arc.direction=this._arc.clockwise?1:-1;let i={},o=null;if(this.config.segments.colorlist?.template&&(o=this.config.segments.colorlist,this._card.lovelace.config.sak_user_templates.templates[o.template.name]&&(this.dev.debug&&console.log("SegmentedArcTool::constructor - templates colorlist found",o.template.name),i=wt.replaceVariables2(o.template.variables,this._card.lovelace.config.sak_user_templates.templates[o.template.name]),this.config.segments.colorlist=i)),"fixedcolor"===this.config.show.style);else if("colorlist"===this.config.show.style){this._segments.count=this.config.segments.colorlist.colors.length,this._segments.size=this._arc.size/this._segments.count,this._segments.gap="undefined"!==this.config.segments.colorlist.gap?this.config.segments.colorlist.gap:1,this._segments.sizeList=[];for(var a=0;a{t>=this.config.scale.min&&t<=this.config.scale.max&&(this._segments.colorStops[t]=this.config.segments.colorstops.colors[t])})),this._segments.sortedStops=Object.keys(this._segments.colorStops).map((t=>Number(t))).sort(((t,e)=>t-e)),void 0===this._segments.colorStops[this.config.scale.max]&&(this._segments.colorStops[this.config.scale.max]=this._segments.colorStops[this._segments.sortedStops[this._segments.sortedStops.length-1]],this._segments.sortedStops=Object.keys(this._segments.colorStops).map((t=>Number(t))).sort(((t,e)=>t-e))),this._segments.count=this._segments.sortedStops.length-1,this._segments.gap="undefined"!==this.config.segments.colorstops.gap?this.config.segments.colorstops.gap:1;let t=this.config.scale.min;const e=this.config.scale.max-this.config.scale.min;this._segments.sizeList=[];for(a=0;a0&&(this._segmentAngles[a]={boundsStart:this.config.position.start_angle+a*this.config.segments.dash*this._arc.direction,boundsEnd:this.config.position.start_angle+(a+0)*this.config.segments.dash*this._arc.direction+this._arc.partsPartialSize*this._arc.direction,drawStart:this.config.position.start_angle+a*this.config.segments.dash*this._arc.direction+this.config.segments.gap*this._arc.direction,drawEnd:this.config.position.start_angle+(a+0)*this.config.segments.dash*this._arc.direction+this._arc.partsPartialSize*this._arc.direction-this.config.segments.gap*this._arc.direction})}this.starttime=null,this.dev.debug&&console.log("SegmentedArcTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config),this.dev.debug&&console.log("SegmentedArcTool - init",this.toolId,this.config.isScale,this._segmentAngles),this.dev.performance&&console.timeEnd(`--\x3e ${this.toolId} PERFORMANCE SegmentedArcTool::constructor`)}get objectId(){return this.toolId}set value(t){if(this.dev.debug&&console.log("SegmentedArcTool - set value IN"),this.config.isScale)return!1;if(this._stateValue===t)return!1;return super.value=t}firstUpdated(t){this.dev.debug&&console.log("SegmentedArcTool - firstUpdated IN with _arcId/id",this._arcId,this.toolId,this.config.isScale),this._arcId=this._card.shadowRoot.getElementById("arc-".concat(this.toolId)),this._firstUpdatedCalled=!0,this._segmentedArcScale?.firstUpdated(t),this.skipOriginal&&(this.dev.debug&&console.log("RENDERNEW - firstUpdated IN with _arcId/id/isScale/scale/connected",this._arcId,this.toolId,this.config.isScale,this._segmentedArcScale,this._card.connected),this.config.isScale||(this._stateValuePrev=null),this._initialDraw=!0,this._card.requestUpdate())}updated(t){this.dev.debug&&console.log("SegmentedArcTool - updated IN")}render(){return this.dev.debug&&console.log("SegmentedArcTool RENDERNEW - Render IN"),U` ${this._renderSegments()} ${this._renderScale()} `}_renderScale(){if(this._segmentedArcScale)return this._segmentedArcScale.render()}_renderSegments(){if(this.skipOriginal){let t,e;const s=this.svg.width,i=this.svg.radiusX,o=this.svg.radiusY;let a;this.dev.debug&&console.log("RENDERNEW - IN _arcId, firstUpdatedCalled",this._arcId,this._firstUpdatedCalled);const n=bt.calculateValueBetween(this.config.scale.min,this.config.scale.max,this._stateValue),r=bt.calculateValueBetween(this.config.scale.min,this.config.scale.max,this._stateValuePrev);this.dev.debug&&(this._stateValuePrev||console.log("*****UNDEFINED",this._stateValue,this._stateValuePrev,r)),n!==r&&this.dev.debug&&console.log("RENDERNEW _renderSegments diff value old new",this.toolId,r,n),t=n*this._arc.size*this._arc.direction+this.config.position.start_angle,e=r*this._arc.size*this._arc.direction+this.config.position.start_angle;const h=[];if(!this.config.isScale)for(let l=0;l`);if(this._firstUpdatedCalled){this.dev.debug&&console.log("RENDERNEW _arcId DOES exist",this._arcId,this.toolId,this._firstUpdatedCalled),this._cache.forEach(((t,e)=>{if(a=t,this.config.isScale){let t=this.config.color;"colorlist"===this.config.show.style&&(t=this.config.segments.colorlist.colors[e]),"colorstops"===this.config.show.style&&(t=this._segments.colorStops[this._segments.sortedStops[e]]),this.styles.foreground[e]||(this.styles.foreground[e]=_t.mergeDeep(this.config.styles.foreground)),this.styles.foreground[e].fill=t}h.push(U``)}));const c={};function d(t,e){let n,r;t=t||(new Date).getTime();c.startTime||(c.startTime=t,c.runningAngle=c.fromAngle),e.debug&&console.log("RENDERNEW - in animateSegmentsNEW",e.toolId,c);const h=t-c.startTime;var l;c.progress=Math.min(h/c.duration,1),c.progress=(l=c.progress,--l**5+1);const g=e._arc.clockwise?c.toAngle>c.fromAngle:c.fromAngle>c.toAngle;c.frameAngle=c.fromAngle+(c.toAngle-c.fromAngle)*c.progress,n=e._segmentAngles.findIndex(((t,s)=>e._arc.clockwise?c.frameAngle<=t.boundsEnd&&c.frameAngle>=t.boundsStart:c.frameAngle<=t.boundsStart&&c.frameAngle>=t.boundsEnd)),-1===n&&(console.log("RENDERNEW animateSegments frameAngle not found",c,e._segmentAngles),console.log("config",e.config)),r=e._segmentAngles.findIndex(((t,s)=>e._arc.clockwise?c.runningAngle<=t.boundsEnd&&c.runningAngle>=t.boundsStart:c.runningAngle<=t.boundsStart&&c.runningAngle>=t.boundsEnd));do{const t=e._segmentAngles[r].drawStart;var u=e._arc.clockwise?Math.min(e._segmentAngles[r].boundsEnd,c.frameAngle):Math.max(e._segmentAngles[r].boundsEnd,c.frameAngle);const n=e._arc.clockwise?Math.min(e._segmentAngles[r].drawEnd,c.frameAngle):Math.max(e._segmentAngles[r].drawEnd,c.frameAngle);let h;a=e.buildArcPath(t,n,e._arc.clockwise,i,o,s),e.myarc||(e.myarc={}),e.as||(e.as={});const l="arc-segment-".concat(e.toolId).concat("-").concat(r);if(e.as[r]||(e.as[r]=e._card.shadowRoot.getElementById(l)),h=e.as[r],e.myarc[r]=l,h&&(h.setAttribute("d",a),"colorlist"===e.config.show.style&&(h.style.fill=e.config.segments.colorlist.colors[r],e.styles.foreground[r].fill=e.config.segments.colorlist.colors[r]),e.config.show.lastcolor)){var m;const t=e._arc.clockwise?e._segmentAngles[r].drawStart:e._segmentAngles[r].drawEnd,s=e._arc.clockwise?e._segmentAngles[r].drawEnd:e._segmentAngles[r].drawStart,i=Math.min(Math.max(0,(u-t)/(s-t)),1);if("colorstops"===e.config.show.style?m=Et.getGradientValue(e._segments.colorStops[e._segments.sortedStops[r]],e._segments.colorStops[e._segments.sortedStops[r]],i):"colorlist"===e.config.show.style&&(m=e.config.segments.colorlist.colors[r]),e.styles.foreground[0].fill=m,e.as[0].style.fill=m,r>0)for(let o=r;o>=0;o--)e.styles.foreground[o].fill!==m&&(e.styles.foreground[o].fill=m,e.as[o].style.fill=m),e.styles.foreground[o].fill=m,e.as[o].style.fill=m}e._cache[r]=a,c.frameAngle!==u&&(u+=1e-6*e._arc.direction);var p=r;r=e._segmentAngles.findIndex(((t,s)=>e._arc.clockwise?u<=t.boundsEnd&&u>=t.boundsStart:u<=t.boundsStart&&u>=t.boundsEnd)),g||p!==r&&(e.debug&&console.log("RENDERNEW movit - remove path",e.toolId,p),e._arc.clockwise,h.removeAttribute("d"),e._cache[p]=null),c.runningAngle=u,e.debug&&console.log("RENDERNEW - animation loop tween",e.toolId,c,r,p)}while(c.runningAngle!==c.frameAngle);1!==c.progress?e.rAFid=requestAnimationFrame((t=>{d(t,e)})):(c.startTime=null,e.debug&&console.log("RENDERNEW - animation loop ENDING tween",e.toolId,c,r,p))}const g=this;return!0===this._card.connected&&this._renderTo!==this._stateValue&&(this._renderTo=this._stateValue,this.rAFid&&cancelAnimationFrame(this.rAFid),c.fromAngle=e,c.toAngle=t,c.runningAngle=e,c.duration=Math.min(Math.max(this._initialDraw?100:500,this._initialDraw?16:1e3*this.config.animation.duration),5e3),c.startTime=null,this.dev.debug&&console.log("RENDERNEW - tween",this.toolId,c),this.rAFid=requestAnimationFrame((t=>{d(t,g)})),this._initialDraw=!1),U`${h}`}this.dev.debug&&console.log("RENDERNEW _arcId does NOT exist",this._arcId,this.toolId);for(let u=0;u0)for(let p=u-1;p>0;p--)this.styles.foreground[p].fill=m;h.push(U``)}return this.dev.debug&&console.log("RENDERNEW - svgItems",h,this._firstUpdatedCalled),U`${h}`}}polarToCartesian(t,e,s,i,o){const a=(o-90)*Math.PI/180;return{x:t+s*Math.cos(a),y:e+i*Math.sin(a)}}buildArcPath(t,e,s,i,o,a){const n=this.polarToCartesian(this.svg.cx,this.svg.cy,i,o,e),r=this.polarToCartesian(this.svg.cx,this.svg.cy,i,o,t),h=Math.abs(e-t)<=180?"0":"1",l=s?"0":"1",c=i-a,d=o-a,g=this.polarToCartesian(this.svg.cx,this.svg.cy,c,d,e),u=this.polarToCartesian(this.svg.cx,this.svg.cy,c,d,t);return["M",n.x,n.y,"A",i,o,0,h,l,r.x,r.y,"L",u.x,u.y,"A",c,d,0,h,"0"===l?"1":"0",g.x,g.y,"Z"].join(" ")}}class Te extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({position:{cx:50,cy:50,height:25,width:25,margin:.5,orientation:"vertical"},hours:24,barhours:1,color:"var(--primary-color)",classes:{tool:{"sak-barchart":!0,hover:!0},bar:{},line:{"sak-barchart__line":!0,hover:!0}},styles:{tool:{},line:{},bar:{}},colorstops:[],show:{style:"fixedcolor"}},e),s),this.svg.margin=bt.calculateSvgDimension(this.config.position.margin);const i="vertical"===this.config.position.orientation?this.svg.width:this.svg.height;this.svg.barWidth=(i-(this.config.hours/this.config.barhours-1)*this.svg.margin)/(this.config.hours/this.config.barhours),this._data=[],this._bars=[],this._scale={},this._needsRendering=!1,this.classes.tool={},this.classes.bar={},this.styles.tool={},this.styles.line={},this.stylesBar={},this.dev.debug&&console.log("SparkleBarChart constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}computeMinMax(){let t=this._series[0],e=this._series[0];for(let s=1,i=this._series.length;se?i:e}this._scale.min=t,this._scale.max=e,this._scale.size=e-t,this._scale.size=1.05*(e-t),this._scale.min=e-this._scale.size}set data(t){this._series=Object.assign(t),this.computeBars(),this._needsRendering=!0}set series(t){this._series=Object.assign(t),this.computeBars(),this._needsRendering=!0}hasSeries(){return this.defaultEntityIndex()}computeBars({_bars:t}=this){this.computeMinMax(),"minmaxgradient"===this.config.show.style&&(this.colorStopsMinMax={},this.colorStopsMinMax={[this._scale.min.toString()]:this.config.minmaxgradient.colors.min,[this._scale.max.toString()]:this.config.minmaxgradient.colors.max}),"vertical"===this.config.position.orientation?(this.dev.debug&&console.log("bar is vertical"),this._series.forEach(((e,s)=>{t[s]||(t[s]={}),t[s].length=0===this._scale.size?0:(e-this._scale.min)/this._scale.size*this.svg.height,t[s].x1=this.svg.x+this.svg.barWidth/2+(this.svg.barWidth+this.svg.margin)*s,t[s].x2=t[s].x1,t[s].y1=this.svg.y+this.svg.height,t[s].y2=t[s].y1-this._bars[s].length,t[s].dataLength=this._bars[s].length}))):"horizontal"===this.config.position.orientation?(this.dev.debug&&console.log("bar is horizontal"),this._data.forEach(((e,s)=>{t[s]||(t[s]={}),t[s].length=0===this._scale.size?0:(e-this._scale.min)/this._scale.size*this.svg.width,t[s].y1=this.svg.y+this.svg.barWidth/2+(this.svg.barWidth+this.svg.margin)*s,t[s].y2=t[s].y1,t[s].x1=this.svg.x,t[s].x2=t[s].x1+this._bars[s].length,t[s].dataLength=this._bars[s].length}))):this.dev.debug&&console.log("SparklineBarChartTool - unknown barchart orientation (horizontal or vertical)")}_renderBars(){const t=[];if(0!==this._bars.length)return this.dev.debug&&console.log("_renderBars IN",this.toolId),this._bars.forEach(((e,s)=>{this.dev.debug&&console.log("_renderBars - bars",e,s);const i=this.getColorFromState(this._series[s]);this.stylesBar[s]||(this.stylesBar[s]={...this.config.styles.bar}),this._bars[s].y2||console.log("sparklebarchart y2 invalid",this._bars[s]),t.push(U` `)})),this.dev.debug&&console.log("_renderBars OUT",this.toolId),U`${t}`}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderBars()} `}}class Ae extends Ct{constructor(t,e,s){const i={position:{cx:50,cy:50,orientation:"horizontal",track:{width:16,height:7,radius:3.5},thumb:{width:9,height:9,radius:4.5,offset:4.5}},classes:{tool:{"sak-switch":!0,hover:!0},track:{"sak-switch__track":!0},thumb:{"sak-switch__thumb":!0}},styles:{tool:{overflow:"visible"},track:{},thumb:{}}},o={animations:[{state:"on",id:1,styles:{track:{fill:"var(--switch-checked-track-color)","pointer-events":"auto"},thumb:{fill:"var(--switch-checked-button-color)",transform:"translateX(4.5em)","pointer-events":"auto"}}},{state:"off",id:0,styles:{track:{fill:"var(--switch-unchecked-track-color)","pointer-events":"auto"},thumb:{fill:"var(--switch-unchecked-button-color)",transform:"translateX(-4.5em)","pointer-events":"auto"}}}]},a={animations:[{state:"on",id:1,styles:{track:{fill:"var(--switch-checked-track-color)","pointer-events":"auto"},thumb:{fill:"var(--switch-checked-button-color)",transform:"translateY(-4.5em)","pointer-events":"auto"}}},{state:"off",id:0,styles:{track:{fill:"var(--switch-unchecked-track-color)","pointer-events":"auto"},thumb:{fill:"var(--switch-unchecked-button-color)",transform:"translateY(4.5em)","pointer-events":"auto"}}}]};if(super(t,_t.mergeDeep(i,e),s),!["horizontal","vertical"].includes(this.config.position.orientation))throw Error("SwitchTool::constructor - invalid orientation [vertical, horizontal] = ",this.config.position.orientation);switch(this.svg.track={},this.svg.track.radius=bt.calculateSvgDimension(this.config.position.track.radius),this.svg.thumb={},this.svg.thumb.radius=bt.calculateSvgDimension(this.config.position.thumb.radius),this.svg.thumb.offset=bt.calculateSvgDimension(this.config.position.thumb.offset),this.config.position.orientation){default:case"horizontal":this.config=_t.mergeDeep(i,o,e),this.svg.track.width=bt.calculateSvgDimension(this.config.position.track.width),this.svg.track.height=bt.calculateSvgDimension(this.config.position.track.height),this.svg.thumb.width=bt.calculateSvgDimension(this.config.position.thumb.width),this.svg.thumb.height=bt.calculateSvgDimension(this.config.position.thumb.height),this.svg.track.x1=this.svg.cx-this.svg.track.width/2,this.svg.track.y1=this.svg.cy-this.svg.track.height/2,this.svg.thumb.x1=this.svg.cx-this.svg.thumb.width/2,this.svg.thumb.y1=this.svg.cy-this.svg.thumb.height/2;break;case"vertical":this.config=_t.mergeDeep(i,a,e),this.svg.track.width=bt.calculateSvgDimension(this.config.position.track.height),this.svg.track.height=bt.calculateSvgDimension(this.config.position.track.width),this.svg.thumb.width=bt.calculateSvgDimension(this.config.position.thumb.height),this.svg.thumb.height=bt.calculateSvgDimension(this.config.position.thumb.width),this.svg.track.x1=this.svg.cx-this.svg.track.width/2,this.svg.track.y1=this.svg.cy-this.svg.track.height/2,this.svg.thumb.x1=this.svg.cx-this.svg.thumb.width/2,this.svg.thumb.y1=this.svg.cy-this.svg.thumb.height/2}this.classes.track={},this.classes.thumb={},this.styles.track={},this.styles.thumb={},this.dev.debug&&console.log("SwitchTool constructor config, svg",this.toolId,this.config,this.svg)}set value(t){super.value=t}_renderSwitch(){return this.MergeAnimationClassIfChanged(),this.MergeAnimationStyleIfChanged(this.styles),U` `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderSwitch()} `}}class Me extends Ct{constructor(t,e,s){super(t,_t.mergeDeep({classes:{tool:{"sak-text":!0},text:{"sak-text__text":!0,hover:!1}},styles:{tool:{},text:{}}},e),s),this.EnableHoverForInteraction(),this.text=this.config.text,this.classes.tool={},this.classes.text={},this.styles.tool={},this.styles.text={},this.dev.debug&&console.log("TextTool constructor coords, dimensions",this.coords,this.dimensions,this.svg,this.config)}_renderText(){return this.MergeAnimationClassIfChanged(),this.MergeColorFromState(this.styles.text),this.MergeAnimationStyleIfChanged(),U` ${this.text} `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderText()} `}}function Ve(t,e,s){if(s||2===arguments.length)for(var i,o=0,a=e.length;o0&&("always"===e||"once"===e&&!Je[r])){for(var C=0,I=$.length;C{e._card.requestUpdate()}),0)},afterEach(t,s){if(t)throw e.injector.error=t,e.config.options.svginject=!1,t;e.injector.error="",e.injector.cache[e.imageCur]=s},beforeEach(t){t.removeAttribute("height"),t.removeAttribute("width")},cacheRequests:!1,evalScripts:"once",httpRequestWithCredentials:!1,renumerateIRIElements:!1}))}_renderUserSvg(){this.MergeAnimationStyleIfChanged();const t=wt.getJsTemplateOrValue(this,this._stateValue,_t.mergeDeep(this.images));if(this.imagePrev=this.imageCur,this.imageCur=t[this.item.image],"none"===t[this.item.image])return U``;let e=this.injector.cache[this.imageCur],s=U``,i="",o="";this.config.clip_path&&(i=`url(#clip-path-${this.toolId})`,o=`url(#mask-${this.toolId})`,s=U` `);const a=t[this.item.image].lastIndexOf(".");return"svg"!==t[this.item.image].substring(-1===a?1/0:a+1)?U` "${s}" `:e&&this.config.options.svginject?(e.classList.remove("hidden"),U` "${s}" ${e}; `):U` "${s}" `}render(){return U` this.handleTapEvent(t,this.config)}> ${this._renderUserSvg()} `}}class Ke{constructor(t,e){if(this.toolsetId=Math.random().toString(36).substr(2,9),this._card=t,this.dev={...this._card.dev},this.dev.performance&&console.time(`--\x3e ${this.toolsetId} PERFORMANCE Toolset::constructor`),this.config=e,this.tools=[],this.palette={},this.palette.light={},this.palette.dark={},this.config.palette){const{paletteLight:t,paletteDark:e}=Et.processPalette(this.config.palette);this.palette.light=t,this.palette.dark=e}this.svg={},this.svg.cx=bt.calculateSvgCoordinate(e.position.cx,pt),this.svg.cy=bt.calculateSvgCoordinate(e.position.cy,pt),this.svg.x=this.svg.cx-pt,this.svg.y=this.svg.cy-pt,this.transform={},this.transform.scale={},this.transform.scale.x=this.transform.scale.y=1,this.transform.rotate={},this.transform.rotate.x=this.transform.rotate.y=0,this.transform.skew={},this.transform.skew.x=this.transform.skew.y=0,this.config.position.scale&&(this.transform.scale.x=this.transform.scale.y=this.config.position.scale),this.config.position.rotate&&(this.transform.rotate.x=this.transform.rotate.y=this.config.position.rotate),this.transform.scale.x=this.config.position.scale_x||this.config.position.scale||1,this.transform.scale.y=this.config.position.scale_y||this.config.position.scale||1,this.transform.rotate.x=this.config.position.rotate_x||this.config.position.rotate||0,this.transform.rotate.y=this.config.position.rotate_y||this.config.position.rotate||0,this.dev.debug&&console.log("Toolset::constructor config/svg",this.toolsetId,this.config,this.svg);const s={area:Vt,circslider:At,badge:It,bar:Te,circle:Tt,ellipse:Mt,horseshoe:xe,icon:jt,line:Se,name:qt,rectangle:ke,rectex:Ee,regpoly:Ce,segarc:Ie,state:we,slider:$e,switch:Ae,text:Me,usersvg:Ze};this.config.tools.map((t=>{const e={...t},i={cx:0,cy:0,scale:this.config.position.scale?this.config.position.scale:1};if(this.dev.debug&&console.log("Toolset::constructor toolConfig",this.toolsetId,e,i),!t.disabled){const o=new s[t.type](this,e,i);this._card.entityHistory.needed|="bar"===t.type,this.tools.push({type:t.type,index:t.id,tool:o})}return!0})),this.dev.performance&&console.timeEnd(`--\x3e ${this.toolsetId} PERFORMANCE Toolset::constructor`)}updateValues(){this.dev.performance&&console.time(`--\x3e ${this.toolsetId} PERFORMANCE Toolset::updateValues`),this.tools&&this.tools.map(((t,e)=>{if(t.tool.config.hasOwnProperty("entity_index")&&(this.dev.debug&&console.log("Toolset::updateValues",t,e),t.tool.value=this._card.attributesStr[t.tool.config.entity_index]?this._card.attributesStr[t.tool.config.entity_index]:this._card.secondaryInfoStr[t.tool.config.entity_index]?this._card.secondaryInfoStr[t.tool.config.entity_index]:this._card.entitiesStr[t.tool.config.entity_index]),t.tool.config.hasOwnProperty("entity_indexes")){const e=[];for(let s=0;s"function"==typeof e.tool.firstUpdated&&(e.tool.firstUpdated(t),!0)))}updated(t){this.dev.debug&&console.log("*****Event - Updated",this.toolsetId,(new Date).getTime()),this.tools&&this.tools.map((e=>"function"==typeof e.tool.updated&&(e.tool.updated(t),!0)))}renderToolset(){this.dev.debug&&console.log("*****Event - renderToolset",this.toolsetId,(new Date).getTime());const t=this.tools.map((t=>U` ${t.tool.render()} `));return U`${t}`}render(){return!this._card.isSafari&&!this._card.iOS||this._card.isSafari16?U` ${this.renderToolset()} `:U` ${this.renderToolset()} `}}const Qe=t=>{const e=Math.round(Math.min(Math.max(t,0),255)).toString(16);return 1===e.length?`0${e}`:e},ts=t=>`#${Qe(t[0])}${Qe(t[1])}${Qe(t[2])}`,es=t=>{const[e,s,i]=t,o=Math.max(e,s,i),a=o-Math.min(e,s,i),n=a&&(o===e?(s-i)/a:o===s?2+(i-e)/a:4+(e-s)/a);return[60*(n<0?n+6:n),o&&a/o,o]},ss=t=>{const[e,s,i]=t,o=t=>{const o=(t+e/60)%6;return i-i*s*Math.max(Math.min(o,4-o,1),0)};return[o(5),o(3),o(1)]},is=t=>ss([t[0],t[1],255]),os=(t,e,s)=>Math.min(Math.max(t,e),s),as=t=>{if(t<=66)return 255;return os(329.698727446*(t-60)**-.1332047592,0,255)},ns=t=>{let e;return e=t<=66?99.4708025861*Math.log(t)-161.1195681661:288.1221695283*(t-60)**-.0755148492,os(e,0,255)},rs=t=>{if(t>=66)return 255;if(t<=19)return 0;const e=138.5177312231*Math.log(t-10)-305.0447927307;return os(e,0,255)},hs=t=>{const e=t/100;return[as(e),ns(e),rs(e)]},ls=(t,e)=>{const s=Math.max(...t),i=Math.max(...e);let o;return o=0===i?0:s/i,e.map((t=>Math.round(t*o)))},cs=t=>Math.floor(1e6/t),ds=(t,e,s)=>{const[i,o,a,n,r]=t,h=cs(e??2700),l=cs(s??6500),c=h-l;let d;try{d=r/(n+r)}catch(_){d=.5}const g=l+d*c,u=g?(m=g,Math.floor(1e6/m)):0;var m;const[p,v,f]=hs(u),y=Math.max(n,r)/255;return ls([i,o,a,n,r],[i+p*y,o+v*y,a+f*y])};console.info(`%c SWISS-ARMY-KNIFE-CARD \n%c Version ${ut} `,"color: yellow; font-weight: bold; background: black","color: white; font-weight: bold; background: dimgray");class gs extends at{constructor(){if(super(),this.connected=!1,Et.setElement(this),this.cardId=Math.random().toString(36).substr(2,9),this.entities=[],this.entitiesStr=[],this.attributesStr=[],this.secondaryInfoStr=[],this.iconStr=[],this.viewBoxSize=vt,this.viewBox={width:vt,height:vt},this.toolsets=[],this.tools=[],this.styles={},this.styles.card={},this.styles.card.default={},this.styles.card.light={},this.styles.card.dark={},this.entityHistory={},this.entityHistory.needed=!1,this.stateChanged=!0,this.entityHistory.updating=!1,this.entityHistory.update_interval=300,this.dev={},this.dev.debug=!1,this.dev.performance=!1,this.dev.m3=!1,this.configIsSet=!1,this.theme={},this.theme.checked=!1,this.theme.isLoaded=!1,this.theme.modeChanged=!1,this.theme.darkMode=!1,this.theme.light={},this.theme.dark={},this.isSafari=!!window.navigator.userAgent.match(/Version\/[\d\.]+.*Safari/),this.iOS=(/iPad|iPhone|iPod/.test(window.navigator.userAgent)||"MacIntel"===window.navigator.platform&&window.navigator.maxTouchPoints>1)&&!window.MSStream,this.isSafari14=this.isSafari&&/Version\/14\.[0-9]/.test(window.navigator.userAgent),this.isSafari15=this.isSafari&&/Version\/15\.[0-9]/.test(window.navigator.userAgent),this.isSafari16=this.isSafari&&/Version\/16\.[0-9]/.test(window.navigator.userAgent),this.isSafari16=this.isSafari&&/Version\/16\.[0-9]/.test(window.navigator.userAgent),this.isSafari14=this.isSafari14||/os 15.*like safari/.test(window.navigator.userAgent.toLowerCase()),this.isSafari15=this.isSafari15||/os 14.*like safari/.test(window.navigator.userAgent.toLowerCase()),this.isSafari16=this.isSafari16||/os 16.*like safari/.test(window.navigator.userAgent.toLowerCase()),this.lovelace=gs.lovelace,!this.lovelace)throw console.error("card::constructor - Can't get Lovelace panel"),Error("card::constructor - Can't get Lovelace panel");gs.colorCache||(gs.colorCache=[]),this.palette={},this.palette.light={},this.palette.dark={},this.dev.debug&&console.log("*****Event - card - constructor",this.cardId,(new Date).getTime())}static getSystemStyles(){return it` :host { cursor: default; font-size: ${4}px; } /* Default settings for the card */ /* - default cursor */ /* - SVG overflow is not displayed, ie cutoff by the card edges */ ha-card { cursor: default; overflow: hidden; -webkit-touch-callout: none; } /* For disabled parts of tools/toolsets */ /* - No input */ ha-card.disabled { pointer-events: none; cursor: default; } .disabled { pointer-events: none !important; cursor: default !important; } /* For 'active' tools/toolsets */ /* - Show cursor as pointer */ .hover { cursor: pointer; } /* For hidden tools/toolsets where state for instance is undefined */ .hidden { opacity: 0; visibility: hidden; transition: visibility 0s 1s, opacity 0.5s linear; } focus { outline: none; } focus-visible { outline: 3px solid blanchedalmond; /* That'll show 'em */ } @media (print), (prefers-reduced-motion: reduce) { .animated { animation-duration: 1ms !important; transition-duration: 1ms !important; animation-iteration-count: 1 !important; } } /* Set default host font-size to 10 pixels. * In that case 1em = 10 pixels = 1% of 100x100 matrix used */ @media screen and (min-width: 467px) { :host { font-size: ${4}px; } } @media screen and (max-width: 466px) { :host { font-size: ${4}px; } } :host ha-card { padding: 0px 0px 0px 0px; } .container { position: relative; height: 100%; display: flex; flex-direction: column; } .labelContainer { position: absolute; top: 0; left: 0; width: 100%; height: 65%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; } .ellipsis { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; } .state { position: relative; display: flex; flex-wrap: wrap; max-width: 100%; min-width: 0px; } #label { display: flex; line-height: 1; } #label.bold { font-weight: bold; } #label, #name { margin: 3% 0; } .shadow { font-size: 30px; font-weight: 700; text-anchor: middle; } .card--dropshadow-5 { filter: drop-shadow(0 1px 0 #ccc) drop-shadow(0 2px 0 #c9c9c9) drop-shadow(0 3px 0 #bbb) drop-shadow(0 4px 0 #b9b9b9) drop-shadow(0 5px 0 #aaa) drop-shadow(0 6px 1px rgba(0,0,0,.1)) drop-shadow(0 0 5px rgba(0,0,0,.1)) drop-shadow(0 1px 3px rgba(0,0,0,.3)) drop-shadow(0 3px 5px rgba(0,0,0,.2)) drop-shadow(0 5px 10px rgba(0,0,0,.25)) drop-shadow(0 10px 10px rgba(0,0,0,.2)) drop-shadow(0 20px 20px rgba(0,0,0,.15)); } .card--dropshadow-medium--opaque--sepia90 { filter: drop-shadow(0.0em 0.05em 0px #b2a98f22) drop-shadow(0.0em 0.07em 0px #b2a98f55) drop-shadow(0.0em 0.10em 0px #b2a98f88) drop-shadow(0px 0.6em 0.9em rgba(0,0,0,0.15)) drop-shadow(0px 1.2em 0.15em rgba(0,0,0,0.1)) drop-shadow(0px 2.4em 2.5em rgba(0,0,0,0.1)) sepia(90%); } .card--dropshadow-heavy--sepia90 { filter: drop-shadow(0.0em 0.05em 0px #b2a98f22) drop-shadow(0.0em 0.07em 0px #b2a98f55) drop-shadow(0.0em 0.10em 0px #b2a98f88) drop-shadow(0px 0.3em 0.45em rgba(0,0,0,0.5)) drop-shadow(0px 0.6em 0.07em rgba(0,0,0,0.3)) drop-shadow(0px 1.2em 1.25em rgba(0,0,0,1)) drop-shadow(0px 1.8em 1.6em rgba(0,0,0,0.1)) drop-shadow(0px 2.4em 2.0em rgba(0,0,0,0.1)) drop-shadow(0px 3.0em 2.5em rgba(0,0,0,0.1)) sepia(90%); } .card--dropshadow-heavy { filter: drop-shadow(0.0em 0.05em 0px #b2a98f22) drop-shadow(0.0em 0.07em 0px #b2a98f55) drop-shadow(0.0em 0.10em 0px #b2a98f88) drop-shadow(0px 0.3em 0.45em rgba(0,0,0,0.5)) drop-shadow(0px 0.6em 0.07em rgba(0,0,0,0.3)) drop-shadow(0px 1.2em 1.25em rgba(0,0,0,1)) drop-shadow(0px 1.8em 1.6em rgba(0,0,0,0.1)) drop-shadow(0px 2.4em 2.0em rgba(0,0,0,0.1)) drop-shadow(0px 3.0em 2.5em rgba(0,0,0,0.1)); } .card--dropshadow-medium--sepia90 { filter: drop-shadow(0.0em 0.05em 0px #b2a98f) drop-shadow(0.0em 0.15em 0px #b2a98f) drop-shadow(0.0em 0.15em 0px #b2a98f) drop-shadow(0px 0.6em 0.9em rgba(0,0,0,0.15)) drop-shadow(0px 1.2em 0.15em rgba(0,0,0,0.1)) drop-shadow(0px 2.4em 2.5em rgba(0,0,0,0.1)) sepia(90%); } .card--dropshadow-medium { filter: drop-shadow(0.0em 0.05em 0px #b2a98f) drop-shadow(0.0em 0.15em 0px #b2a98f) drop-shadow(0.0em 0.15em 0px #b2a98f) drop-shadow(0px 0.6em 0.9em rgba(0,0,0,0.15)) drop-shadow(0px 1.2em 0.15em rgba(0,0,0,0.1)) drop-shadow(0px 2.4em 2.5em rgba(0,0,0,0.1)); } .card--dropshadow-light--sepia90 { filter: drop-shadow(0px 0.10em 0px #b2a98f) drop-shadow(0.1em 0.5em 0.2em rgba(0, 0, 0, .5)) sepia(90%); } .card--dropshadow-light { filter: drop-shadow(0px 0.10em 0px #b2a98f) drop-shadow(0.1em 0.5em 0.2em rgba(0, 0, 0, .5)); } .card--dropshadow-down-and-distant { filter: drop-shadow(0px 0.05em 0px #b2a98f) drop-shadow(0px 14px 10px rgba(0,0,0,0.15)) drop-shadow(0px 24px 2px rgba(0,0,0,0.1)) drop-shadow(0px 34px 30px rgba(0,0,0,0.1)); } .card--filter-none { } .horseshoe__svg__group { transform: translateY(15%); } `}static getUserStyles(){return this.userContent="",gs.lovelace.config.sak_user_templates&&gs.lovelace.config.sak_user_templates.definitions.user_css_definitions&&(this.userContent=gs.lovelace.config.sak_user_templates.definitions.user_css_definitions.reduce(((t,e)=>t+e.content),"")),it`${st(this.userContent)}`}static getSakStyles(){return this.sakContent="",gs.lovelace.config.sak_sys_templates&&gs.lovelace.config.sak_sys_templates.definitions.sak_css_definitions&&(this.sakContent=gs.lovelace.config.sak_sys_templates.definitions.sak_css_definitions.reduce(((t,e)=>t+e.content),"")),it`${st(this.sakContent)}`}static getSakSvgDefinitions(){gs.lovelace.sakSvgContent=null;let t="";gs.lovelace.config.sak_sys_templates&&gs.lovelace.config.sak_sys_templates.definitions.sak_svg_definitions&&(t=gs.lovelace.config.sak_sys_templates.definitions.sak_svg_definitions.reduce(((t,e)=>t+e.content),"")),gs.sakSvgContent=ct(t)}static getUserSvgDefinitions(){gs.lovelace.userSvgContent=null;let t="";gs.lovelace.config.sak_user_templates&&gs.lovelace.config.sak_user_templates.definitions.user_svg_definitions&&(t=gs.lovelace.config.sak_user_templates.definitions.user_svg_definitions.reduce(((t,e)=>t+e.content),"")),gs.userSvgContent=ct(t)}static get styles(){if(gs.lovelace||(gs.lovelace=bt.getLovelace()),!gs.lovelace)throw console.error("SAK - Can't get reference to Lovelace"),Error("card::get styles - Can't get Lovelace panel");if(!gs.lovelace.config.sak_sys_templates)throw console.error(ut," - SAK - System Templates reference NOT defined."),Error(ut," - card::get styles - System Templates reference NOT defined!");return gs.lovelace.config.sak_user_templates||console.warning(ut," - SAK - User Templates reference NOT defined. Did you NOT include them?"),gs.getSakSvgDefinitions(),gs.getUserSvgDefinitions(),it` ${gs.getSystemStyles()} ${gs.getSakStyles()} ${gs.getUserStyles()} `}set hass(t){if(this.counter||(this.counter=0),this.counter+=1,this.theme.modeChanged=t.themes.darkMode!==this.theme.darkMode,this.theme.modeChanged&&(this.theme.darkMode=t.themes.darkMode),!this.theme.checked){if(this.theme.checked=!0,this.config.theme&&t.themes.themes[this.config.theme]){const{themeLight:e,themeDark:s}=Et.processTheme(t.themes.themes[this.config.theme]);this.theme.light=e,this.theme.dark=s,this.theme.isLoaded=!0}this.styles.card.light={...this.styles.card.default,...this.theme.light,...this.palette.light},this.styles.card.dark={...this.styles.card.default,...this.theme.dark,...this.palette.dark}}if(this.dev.debug&&console.log("*****Event - card::set hass",this.cardId,(new Date).getTime()),this._hass=t,this.connected||this.dev.debug&&console.log("set hass but NOT connected",this.cardId),!this.config.entities)return;let e,s,i,o,a,n=!1,r=0,h=!1,l=!1,c=!1;for(e of this.config.entities){if(this.entities[r]=t.states[this.config.entities[r].entity],c=void 0===this.entities[r],c&&console.error("SAK - set hass, entity undefined: ",this.config.entities[r].entity),this.config.entities[r].secondary_info&&(h=!0,s=c?void 0:this.entities[r][this.config.entities[r].secondary_info],i=this._buildStateString(s,this.config.entities[r]),i!==this.secondaryInfoStr[r]&&(this.secondaryInfoStr[r]=i,n=!0)),this.config.entities[r].icon||(o=c?void 0:t.states[this.config.entities[r].entity].attributes.icon,o!==this.iconStr[r]&&(this.iconStr[r]=o,n=!0)),this.config.entities[r].attribute){let{attribute:t}=this.config.entities[r],e="",s="";const i=this.config.entities[r].attribute.indexOf("["),o=this.config.entities[r].attribute.indexOf(".");let h=0,c="";-1!==i?(t=this.config.entities[r].attribute.substr(0,i),e=this.config.entities[r].attribute.substr(i,this.config.entities[r].attribute.length-i),h=e[1],c=e.substr(4,e.length-4),s=this.entities[r].attributes[t][h][c]):-1!==o?(t=this.config.entities[r].attribute.substr(0,o),e=this.config.entities[r].attribute.substr(i,this.config.entities[r].attribute.length-i),c=e.substr(1,e.length-1),s=this.entities[r].attributes[t][c],console.log("set hass, attributes with map",this.config.entities[r].attribute,t,e)):s=this.entities[r].attributes[t],a=this._buildStateString(s,this.config.entities[r]),a!==this.attributesStr[r]&&(this.attributesStr[r]=a,n=!0),l=!0}l||h||(a=c?void 0:this._buildStateString(this.entities[r].state,this.config.entities[r]),a!==this.entitiesStr[r]&&(this.entitiesStr[r]=a,n=!0),this.dev.debug&&console.log("set hass - attrSet=false",this.cardId,`${(new Date).getSeconds().toString()}.${(new Date).getMilliseconds().toString()}`,a)),n||=l||h,r+=1,l=!1,h=!1}(n||this.theme.modeChanged)&&(this.toolsets&&this.toolsets.map((t=>(t.updateValues(),!0))),this.requestUpdate(),this.theme.modeChanged=!1,this.counter-=1)}setConfig(t){if(this.dev.performance&&console.time(`--\x3e ${this.cardId} PERFORMANCE card::setConfig`),this.dev.debug&&console.log("*****Event - setConfig",this.cardId,(new Date).getTime()),(t=JSON.parse(JSON.stringify(t))).dev&&(this.dev={...this.dev,...t.dev}),this.dev.debug&&console.log("setConfig",this.cardId),!t.layout)throw Error("card::setConfig - No layout defined");if(t.entities){if("sensor"!==Ot(t.entities[0].entity)&&t.entities[0].attribute&&!isNaN(t.entities[0].attribute))throw Error("card::setConfig - First entity or attribute must be a numbered sensorvalue, but is NOT")}const e=_t.mergeDeep(t);this.config=e,this.toolset=[];const s=this;function i(t,e){if(e?.template){const t=s.lovelace.config.sak_user_templates.templates[e.template.name];t||console.error("Template not found...",e.template,t);const i=wt.replaceVariables3(e.template.variables,t);return _t.mergeDeep(i)}return"template"===t?(console.log("findTemplate return key=template/value",t,void 0),e):e}const o=JSON.stringify(this.config,i);if(this.config.palette){this.config.palette=JSON.parse(o).palette;const{paletteLight:r,paletteDark:h}=Et.processPalette(this.config.palette);this.palette.light=r,this.palette.dark=h}const a=JSON.parse(o).layout.toolsets;if(this.config.layout.template&&(this.config.layout=JSON.parse(o).layout),this.config.layout.toolsets.map(((t,e)=>{let s=null;this.toolsets||(this.toolsets=[]);{let o=!1,n=[];s=a[e].tools,t.tools&&t.tools.map(((r,h)=>(a[e].tools.map(((n,l)=>(r.id===n.id&&(t.template&&(this.config.layout.toolsets[e].position&&(a[e].position=_t.mergeDeep(this.config.layout.toolsets[e].position)),s[l]=_t.mergeDeep(s[l],r),s[l]=JSON.parse(JSON.stringify(s[l],i)),o=!0),this.dev.debug&&console.log("card::setConfig - got toolsetCfg toolid",r,h,n,l,r)),a[e].tools[l]=wt.getJsTemplateOrValueConfig(a[e].tools[l],_t.mergeDeep(a[e].tools[l])),o))),o||(n=n.concat(t.tools[h])),o))),s=s.concat(n)}t=a[e];const o=new Ke(this,t);return this.toolsets.push(o),!0})),this.dev.m3&&(console.log("*** M3 - Checking for m3.yaml template to convert..."),this.lovelace.config.sak_user_templates.templates.m3)){const{m3:l}=this.lovelace.config.sak_user_templates.templates;console.log("*** M3 - Found. Material 3 conversion starting...");let c="",d="",g="",u="",m="",p="",v="",f="",y="",_="";const b={},w={},x={};l.entities.map((t=>(["ref.palette","sys.color","sys.color.light","sys.color.dark"].includes(t.category_id)&&(t.tags.includes("alias")||(b[t.id]={value:t.value,tags:t.tags})),"ref.palette"===t.category_id&&(c+=`${t.id}: '${t.value}'\n`,"md.ref.palette.primary40"===t.id&&(p=t.value),"md.ref.palette.primary80"===t.id&&(y=t.value),"md.ref.palette.neutral40"===t.id&&(v=t.value),"md.ref.palette.neutral80"===t.id&&(_=t.value)),"sys.color"===t.category_id&&(d+=`${t.id}: '${t.value}'\n`),"sys.color.light"===t.category_id&&(g+=`${t.id}: '${t.value}'\n`,"md.sys.color.surface.light"===t.id&&(m=t.value)),"sys.color.dark"===t.category_id&&(u+=`${t.id}: '${t.value}'\n`,"md.sys.color.surface.dark"===t.id&&(f=t.value)),!0))),["primary","secondary","tertiary","error","neutral","neutral-variant"].forEach((t=>{[5,15,25,35,45,65,75,85].forEach((e=>{b[`md.ref.palette.${t}${e.toString()}`]={value:Et.getGradientValue(b[`md.ref.palette.${t}${(e-5).toString()}`].value,b[`md.ref.palette.${t}${(e+5).toString()}`].value,.5),tags:[...b[`md.ref.palette.${t}${(e-5).toString()}`].tags]},b[`md.ref.palette.${t}${e.toString()}`].tags[3]=t+e.toString()})),b[`md.ref.palette.${t}7`]={value:Et.getGradientValue(b[`md.ref.palette.${t}5`].value,b[`md.ref.palette.${t}10`].value,.5),tags:[...b[`md.ref.palette.${t}10`].tags]},b[`md.ref.palette.${t}7`].tags[3]=`${t}7`,b[`md.ref.palette.${t}92`]={value:Et.getGradientValue(b[`md.ref.palette.${t}90`].value,b[`md.ref.palette.${t}95`].value,.5),tags:[...b[`md.ref.palette.${t}90`].tags]},b[`md.ref.palette.${t}92`].tags[3]=`${t}92`,b[`md.ref.palette.${t}97`]={value:Et.getGradientValue(b[`md.ref.palette.${t}95`].value,b[`md.ref.palette.${t}99`].value,.5),tags:[...b[`md.ref.palette.${t}90`].tags]},b[`md.ref.palette.${t}97`].tags[3]=`${t}97`}));for(const[J,Y]of Object.entries(b))w[J]=`theme-${Y.tags[1]}-${Y.tags[2]}-${Y.tags[3]}: rgb(${S(Y.value)})`,x[J]=`theme-${Y.tags[1]}-${Y.tags[2]}-${Y.tags[3]}-rgb: ${S(Y.value)}`;function S(t){const e={};e.r=Math.round(parseInt(t.substr(1,2),16)),e.g=Math.round(parseInt(t.substr(3,2),16)),e.b=Math.round(parseInt(t.substr(5,2),16));return`${e.r},${e.g},${e.b}`}function $(t,e,s,i,o){const a={},n={};a.r=Math.round(parseInt(t.substr(1,2),16)),a.g=Math.round(parseInt(t.substr(3,2),16)),a.b=Math.round(parseInt(t.substr(5,2),16)),n.r=Math.round(parseInt(e.substr(1,2),16)),n.g=Math.round(parseInt(e.substr(3,2),16)),n.b=Math.round(parseInt(e.substr(5,2),16));let r,h,l,c="";return s.forEach(((t,e)=>{r=Math.round(t*n.r+(1-t)*a.r),h=Math.round(t*n.g+(1-t)*a.g),l=Math.round(t*n.b+(1-t)*a.b),c+=`${i+(e+1).toString()}-${o}: rgb(${r},${h},${l})\n`,c+=`${i+(e+1).toString()}-${o}-rgb: ${r},${h},${l}\n`})),c}const k=[.03,.05,.08,.11,.15,.19,.24,.29,.35,.4],E=[.05,.08,.11,.15,.19,.24,.29,.35,.4,.45],C=$(m,v,k," theme-ref-elevation-surface-neutral","light"),I=b["md.ref.palette.neutral-variant40"].value,T=$(m,I,k," theme-ref-elevation-surface-neutral-variant","light"),A=$(m,p,k," theme-ref-elevation-surface-primary","light"),M=b["md.ref.palette.secondary40"].value,V=$(m,M,k," theme-ref-elevation-surface-secondary","light"),N=b["md.ref.palette.tertiary40"].value,D=$(m,N,k," theme-ref-elevation-surface-tertiary","light"),P=b["md.ref.palette.error40"].value,O=$(m,P,k," theme-ref-elevation-surface-error","light"),R=$(f,_,E," theme-ref-elevation-surface-neutral","dark"),L=b["md.ref.palette.neutral-variant80"].value,z=$(f,L,E," theme-ref-elevation-surface-neutral-variant","dark"),F=$(f,y,E," theme-ref-elevation-surface-primary","dark"),U=b["md.ref.palette.secondary80"].value,B=$(f,U,E," theme-ref-elevation-surface-secondary","dark"),j=b["md.ref.palette.tertiary80"].value,q=$(f,j,E," theme-ref-elevation-surface-tertiary","dark"),H=b["md.ref.palette.error80"].value,G=$(f,H,E," theme-ref-elevation-surface-error","dark");let W="";for(const[X,Z]of Object.entries(w))"theme-ref"===Z.substring(0,9)&&(W+=` ${Z}\n`,W+=` ${x[X]}\n`);console.log(C+T+A+V+D+O+R+z+F+B+q+G+W),console.log("*** M3 - Material 3 conversion DONE. You should copy the above output...")}this.aspectratio=(this.config.layout.aspectratio||this.config.aspectratio||"1/1").trim();const n=this.aspectratio.split("/");this.viewBox||(this.viewBox={}),this.viewBox.width=n[0]*mt,this.viewBox.height=n[1]*mt,this.config.layout.styles?.card&&(this.styles.card.default=this.config.layout.styles.card),this.dev.debug&&console.log("Step 5: toolconfig, list of toolsets",this.toolsets),this.dev.debug&&console.log("debug - setConfig",this.cardId,this.config),this.dev.performance&&console.timeEnd(`--\x3e ${this.cardId} PERFORMANCE card::setConfig`),this.configIsSet=!0}connectedCallback(){this.dev.performance&&console.time(`--\x3e ${this.cardId} PERFORMANCE card::connectedCallback`),this.dev.debug&&console.log("*****Event - connectedCallback",this.cardId,(new Date).getTime()),this.connected=!0,super.connectedCallback(),this.entityHistory.update_interval&&(this.updateOnInterval(),clearInterval(this.interval),this.interval=setInterval((()=>this.updateOnInterval()),this._hass?1e3*this.entityHistory.update_interval:1e3)),this.dev.debug&&console.log("ConnectedCallback",this.cardId),this.requestUpdate(),this.dev.performance&&console.timeEnd(`--\x3e ${this.cardId} PERFORMANCE card::connectedCallback`)}disconnectedCallback(){this.dev.performance&&console.time(`--\x3e ${this.cardId} PERFORMANCE card::disconnectedCallback`),this.dev.debug&&console.log("*****Event - disconnectedCallback",this.cardId,(new Date).getTime()),this.interval&&(clearInterval(this.interval),this.interval=0),super.disconnectedCallback(),this.dev.debug&&console.log("disconnectedCallback",this.cardId),this.connected=!1,this.dev.performance&&console.timeEnd(`--\x3e ${this.cardId} PERFORMANCE card::disconnectedCallback`)}firstUpdated(t){this.dev.debug&&console.log("*****Event - card::firstUpdated",this.cardId,(new Date).getTime()),this.toolsets&&this.toolsets.map((async e=>(e.firstUpdated(t),!0)))}updated(t){this.dev.debug&&console.log("*****Event - Updated",this.cardId,(new Date).getTime()),this.toolsets&&this.toolsets.map((async e=>(e.updated(t),!0)))}render(){if(this.dev.performance&&console.time(`--\x3e ${this.cardId} PERFORMANCE card::render`),this.dev.debug&&console.log("*****Event - render",this.cardId,(new Date).getTime()),!this.connected)return void(this.dev.debug&&console.log("render but NOT connected",this.cardId,(new Date).getTime()));let t;try{t=this.config.disable_card?F`
${this._renderSvg()}
`:F`
${this._renderSvg()}
`}catch(e){console.error(e)}return this.dev.performance&&console.timeEnd(`--\x3e ${this.cardId} PERFORMANCE card::render`),t}_renderSakSvgDefinitions(){return U` ${gs.sakSvgContent} `}_renderUserSvgDefinitions(){return U` ${gs.userSvgContent} `}themeIsDarkMode(){return!0===this.theme.darkMode}themeIsLightMode(){return!1===this.theme.darkMode}_RenderToolsets(){return this.dev.debug&&console.log("all the tools in renderTools",this.tools),U` ${this.toolsets.map((t=>t.render()))} ${this._renderSakSvgDefinitions()} ${this._renderUserSvgDefinitions()} `}_renderCardAttributes(){let t;const e=[];this._attributes="";for(let s=0;s ${s} `),U`${e}`}_buildUom(t,e,s){return t?.unit||s?.unit||e?.attributes.unit_of_measurement||""}toLocale(t,e="unknown"){const s=this._hass.selectedLanguage||this._hass.language,i=this._hass.resources[s];return i&&i[t]?i[t]:e}_buildStateString(t,e){if(void 0===t)return t;if(e.convert){let s,i,o=e.convert.match(/(^\w+)\((\d+)\)/);switch(null===o?s=e.convert:3===o.length&&(s=o[1],i=Number(o[2])),s){case"brightness_pct":t="undefined"===t?"undefined":`${Math.round(t/255*100)}`;break;case"multiply":t=`${Math.round(t*i)}`;break;case"divide":t=`${Math.round(t/i)}`;break;case"rgb_csv":case"rgb_hex":if(e.attribute){let i=this._hass.states[e.entity];switch(i.attributes.color_mode){case"unknown":case"onoff":case"brightness":case"white":break;case"color_temp":if(i.attributes.color_temp_kelvin){let e=hs(i.attributes.color_temp_kelvin);const o=es(e);o[1]<.4&&(o[1]<.1?o[2]=225:o[1]=.4),e=ss(o),e[0]=Math.round(e[0]),e[1]=Math.round(e[1]),e[2]=Math.round(e[2]),t="rgb_csv"===s?`${e[0]},${e[1]},${e[2]}`:ts(e)}else t="rgb_csv"===s?"255,255,255":"#ffffff00";break;case"hs":{let e=is([i.attributes.hs_color[0],i.attributes.hs_color[1]/100]);e[0]=Math.round(e[0]),e[1]=Math.round(e[1]),e[2]=Math.round(e[2]),t="rgb_csv"===s?`${e[0]},${e[1]},${e[2]}`:ts(e)}break;case"rgb":{const e=es(this.stateObj.attributes.rgb_color);e[1]<.4&&(e[1]<.1?e[2]=225:e[1]=.4);const i=ss(e);t="rgb_csv"===s?i.toString():ts(i)}break;case"rgbw":{let e=(t=>{const[e,s,i,o]=t;return ls([e,s,i,o],[e+o,s+o,i+o])})(i.attributes.rgbw_color);e[0]=Math.round(e[0]),e[1]=Math.round(e[1]),e[2]=Math.round(e[2]),t="rgb_csv"===s?`${e[0]},${e[1]},${e[2]}`:ts(e)}break;case"rgbww":{let e=ds(i.attributes.rgbww_color,i.attributes?.min_color_temp_kelvin,i.attributes?.max_color_temp_kelvin);e[0]=Math.round(e[0]),e[1]=Math.round(e[1]),e[2]=Math.round(e[2]),t="rgb_csv"===s?`${e[0]},${e[1]},${e[2]}`:ts(e)}break;case"xy":if(i.attributes.hs_color){let e=is([i.attributes.hs_color[0],i.attributes.hs_color[1]/100]);const o=es(e);o[1]<.4&&(o[1]<.1?o[2]=225:o[1]=.4),e=ss(o),e[0]=Math.round(e[0]),e[1]=Math.round(e[1]),e[2]=Math.round(e[2]),t="rgb_csv"===s?`${e[0]},${e[1]},${e[2]}`:ts(e)}else if(i.attributes.color){let e={};e.l=i.attributes.brightness,e.h=i.attributes.color.h||i.attributes.color.hue,e.s=i.attributes.color.s||i.attributes.color.saturation;let{r:o,g:a,b:n}=Et.hslToRgb(e);if("rgb_csv"===s)t=`${o},${a},${n}`;else{t=`#${Et.padZero(o.toString(16))}${Et.padZero(a.toString(16))}${Et.padZero(n.toString(16))}`}}else i.attributes.xy_color}}break;default:console.error(`Unknown converter [${s}] specified for entity [${e.entity}]!`)}}return void 0!==t?Number.isNaN(t)?t:t.toString():void 0}_computeEntity(t){return t.substr(t.indexOf(".")+1)}updateOnInterval(){this._hass?(this.stateChanged&&!this.entityHistory.updating&&this.updateData(),this.entityHistory.needed?(window.clearInterval(this.interval),this.interval=setInterval((()=>this.updateOnInterval()),1e3*this.entityHistory.update_interval)):this.interval&&(window.clearInterval(this.interval),this.interval=0)):this.dev.debug&&console.log("UpdateOnInterval - NO hass, returning")}async fetchRecent(t,e,s,i){let o="history/period";return e&&(o+=`/${e.toISOString()}`),o+=`?filter_entity_id=${t}`,s&&(o+=`&end_time=${s.toISOString()}`),i&&(o+="&skip_initial_state"),o+="&minimal_response",this._hass.callApi("GET",o)}async updateData(){this.entityHistory.updating=!0,this.dev.debug&&console.log("card::updateData - ENTRY",this.cardId);const t=[];let e=0;this.toolsets.map(((s,i)=>(s.tools.map(((s,o)=>{if("bar"===s.type){const a=new Date,n=new Date;n.setHours(a.getHours()-s.tool.config.hours);const r=this.config.entities[s.tool.config.entity_index].attribute?this.config.entities[s.tool.config.entity_index].attribute:null;t[e]={tsidx:i,entityIndex:s.tool.config.entity_index,entityId:this.entities[s.tool.config.entity_index].entity_id,attrId:r,start:n,end:a,type:"bar",idx:o},e+=1}return!0})),!0))),this.dev.debug&&console.log("card::updateData - LENGTH",this.cardId,t.length,t),this.stateChanged=!1,this.dev.debug&&console.log("card::updateData, entityList from tools",t);try{const e=t.map(((t,e)=>this.updateEntity(t,e,t.start,t.end)));await Promise.all(e)}finally{this.entityHistory.updating=!1}}async updateEntity(t,e,s,i){let o=[];const a=s;let n,r=await this.fetchRecent(t.entityId,a,i,!1);r[0]&&r[0].length>0&&(t.attrId&&(n=this.entities[t.entityIndex].attributes[this.config.entities[t.entityIndex].attribute],t.state=n),r=r[0].filter((e=>t.attrId?!isNaN(parseFloat(e.attributes[t.attrId])):!isNaN(parseFloat(e.state)))),r=r.map((e=>({last_changed:e.last_changed,state:t.attrId?Number(e.attributes[t.attrId]):Number(e.state)})))),o=[...o,...r],this.uppdate(t,o)}uppdate(t,e){if(!e)return;const s=(new Date).getTime();let i=24,o=2;"bar"===t.type&&(this.dev.debug&&console.log("entity.type == bar",t),i=this.toolsets[t.tsidx].tools[t.idx].tool.config.hours,o=this.toolsets[t.tsidx].tools[t.idx].tool.config.barhours);const a=e.reduce(((t,e)=>((t,e)=>{const a=(s-new Date(e.last_changed).getTime())/36e5/o-i/o,n=Math.floor(Math.abs(a));return t[n]||(t[n]=[]),t[n].push(e),t})(t,e)),[]);if(a.length=Math.ceil(i/o),0===Object.keys(a).length)return;const n=Object.keys(a)[0];"0"!==n&&(a[0]=[],a[0].push(a[n][0]));for(let h=0;h{return s="state",(e=t).reduce(((t,e)=>t+Number(e[s])),0)/e.length;var e,s})),"bar"===t.type&&(this.toolsets[t.tsidx].tools[t.idx].tool.series=[...r]),this.requestUpdate()}getCardSize(){return 4}}customElements.define("swiss-army-knife-card",gs);