function t(t,e,n,r){var i,a=arguments.length,s=a<3?e:null===r?r=Object.getOwnPropertyDescriptor(e,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,n,r);else for(var o=t.length-1;o>=0;o--)(i=t[o])&&(s=(a<3?i(s):a>3?i(e,n,s):i(e,n))||s);return a>3&&s&&Object.defineProperty(e,n,s),s}console.groupCollapsed("%c🌊 SEA TEMPERATURES CARD%cv3.2.0","color: orange; font-weight: bold; background: black; padding: 2px 4px; border-radius: 2px 0 0 2px;","color: white; font-weight: bold; background: dimgray; padding: 2px 4px; border-radius: 0 2px 2px 0;"),console.info("A Lovelace card to display sea temperatures."),console.info("Github: https://github.com/timmaurice/sea-temperatures.git"),console.info("Sponsor: https://buymeacoffee.com/timmaurice"),console.groupEnd(),"function"==typeof SuppressedError&&SuppressedError; /** * @license * Copyright 2019 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const e=globalThis,n=e.ShadowRoot&&(void 0===e.ShadyCSS||e.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,r=Symbol(),i=new WeakMap;let a=class{constructor(t,e,n){if(this._$cssResult$=!0,n!==r)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(n&&void 0===t){const n=void 0!==e&&1===e.length;n&&(t=i.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&i.set(e,t))}return t}toString(){return this.cssText}};const s=t=>new a("string"==typeof t?t:t+"",void 0,r),o=(t,...e)=>{const n=1===t.length?t[0]:e.reduce((e,n,r)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[r+1],t[0]);return new a(n,t,r)},c=n?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return s(e)})(t):t,{is:l,defineProperty:h,getOwnPropertyDescriptor:u,getOwnPropertyNames:d,getOwnPropertySymbols:p,getPrototypeOf:f}=Object,g=globalThis,m=g.trustedTypes,_=m?m.emptyScript:"",y=g.reactiveElementPolyfillSupport,v=(t,e)=>t,b={toAttribute(t,e){switch(e){case Boolean:t=t?_:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},x=(t,e)=>!l(t,e),$={attribute:!0,type:String,converter:b,reflect:!1,useDefault:!1,hasChanged:x}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */Symbol.metadata??=Symbol("metadata"),g.litPropertyMetadata??=new WeakMap;let w=class extends HTMLElement{static addInitializer(t){this._$Ei(),(this.l??=[]).push(t)}static get observedAttributes(){return this.finalize(),this._$Eh&&[...this._$Eh.keys()]}static createProperty(t,e=$){if(e.state&&(e.attribute=!1),this._$Ei(),this.prototype.hasOwnProperty(t)&&((e=Object.create(e)).wrapped=!0),this.elementProperties.set(t,e),!e.noAccessor){const n=Symbol(),r=this.getPropertyDescriptor(t,n,e);void 0!==r&&h(this.prototype,t,r)}}static getPropertyDescriptor(t,e,n){const{get:r,set:i}=u(this.prototype,t)??{get(){return this[e]},set(t){this[e]=t}};return{get:r,set(e){const a=r?.call(this);i?.call(this,e),this.requestUpdate(t,a,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)??$}static _$Ei(){if(this.hasOwnProperty(v("elementProperties")))return;const t=f(this);t.finalize(),void 0!==t.l&&(this.l=[...t.l]),this.elementProperties=new Map(t.elementProperties)}static finalize(){if(this.hasOwnProperty(v("finalized")))return;if(this.finalized=!0,this._$Ei(),this.hasOwnProperty(v("properties"))){const t=this.properties,e=[...d(t),...p(t)];for(const n of e)this.createProperty(n,t[n])}const t=this[Symbol.metadata];if(null!==t){const e=litPropertyMetadata.get(t);if(void 0!==e)for(const[t,n]of e)this.elementProperties.set(t,n)}this._$Eh=new Map;for(const[t,e]of this.elementProperties){const n=this._$Eu(t,e);void 0!==n&&this._$Eh.set(n,t)}this.elementStyles=this.finalizeStyles(this.styles)}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(c(t))}else void 0!==t&&e.push(c(t));return e}static _$Eu(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof t?t.toLowerCase():void 0}constructor(){super(),this._$Ep=void 0,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Em=null,this._$Ev()}_$Ev(){this._$ES=new Promise(t=>this.enableUpdating=t),this._$AL=new Map,this._$E_(),this.requestUpdate(),this.constructor.l?.forEach(t=>t(this))}addController(t){(this._$EO??=new Set).add(t),void 0!==this.renderRoot&&this.isConnected&&t.hostConnected?.()}removeController(t){this._$EO?.delete(t)}_$E_(){const t=new Map,e=this.constructor.elementProperties;for(const n of e.keys())this.hasOwnProperty(n)&&(t.set(n,this[n]),delete this[n]);t.size>0&&(this._$Ep=t)}createRenderRoot(){const t=this.shadowRoot??this.attachShadow(this.constructor.shadowRootOptions);return((t,r)=>{if(n)t.adoptedStyleSheets=r.map(t=>t instanceof CSSStyleSheet?t:t.styleSheet);else for(const n of r){const r=document.createElement("style"),i=e.litNonce;void 0!==i&&r.setAttribute("nonce",i),r.textContent=n.cssText,t.appendChild(r)}})(t,this.constructor.elementStyles),t}connectedCallback(){this.renderRoot??=this.createRenderRoot(),this.enableUpdating(!0),this._$EO?.forEach(t=>t.hostConnected?.())}enableUpdating(t){}disconnectedCallback(){this._$EO?.forEach(t=>t.hostDisconnected?.())}attributeChangedCallback(t,e,n){this._$AK(t,n)}_$ET(t,e){const n=this.constructor.elementProperties.get(t),r=this.constructor._$Eu(t,n);if(void 0!==r&&!0===n.reflect){const i=(void 0!==n.converter?.toAttribute?n.converter:b).toAttribute(e,n.type);this._$Em=t,null==i?this.removeAttribute(r):this.setAttribute(r,i),this._$Em=null}}_$AK(t,e){const n=this.constructor,r=n._$Eh.get(t);if(void 0!==r&&this._$Em!==r){const t=n.getPropertyOptions(r),i="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==t.converter?.fromAttribute?t.converter:b;this._$Em=r;const a=i.fromAttribute(e,t.type);this[r]=a??this._$Ej?.get(r)??a,this._$Em=null}}requestUpdate(t,e,n,r=!1,i){if(void 0!==t){const a=this.constructor;if(!1===r&&(i=this[t]),n??=a.getPropertyOptions(t),!((n.hasChanged??x)(i,e)||n.useDefault&&n.reflect&&i===this._$Ej?.get(t)&&!this.hasAttribute(a._$Eu(t,n))))return;this.C(t,e,n)}!1===this.isUpdatePending&&(this._$ES=this._$EP())}C(t,e,{useDefault:n,reflect:r,wrapped:i},a){n&&!(this._$Ej??=new Map).has(t)&&(this._$Ej.set(t,a??e??this[t]),!0!==i||void 0!==a)||(this._$AL.has(t)||(this.hasUpdated||n||(e=void 0),this._$AL.set(t,e)),!0===r&&this._$Em!==t&&(this._$Eq??=new Set).add(t))}async _$EP(){this.isUpdatePending=!0;try{await this._$ES}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){if(!this.isUpdatePending)return;if(!this.hasUpdated){if(this.renderRoot??=this.createRenderRoot(),this._$Ep){for(const[t,e]of this._$Ep)this[t]=e;this._$Ep=void 0}const t=this.constructor.elementProperties;if(t.size>0)for(const[e,n]of t){const{wrapped:t}=n,r=this[e];!0!==t||this._$AL.has(e)||void 0===r||this.C(e,void 0,n,r)}}let t=!1;const e=this._$AL;try{t=this.shouldUpdate(e),t?(this.willUpdate(e),this._$EO?.forEach(t=>t.hostUpdate?.()),this.update(e)):this._$EM()}catch(e){throw t=!1,this._$EM(),e}t&&this._$AE(e)}willUpdate(t){}_$AE(t){this._$EO?.forEach(t=>t.hostUpdated?.()),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EM(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$ES}shouldUpdate(t){return!0}update(t){this._$Eq&&=this._$Eq.forEach(t=>this._$ET(t,this[t])),this._$EM()}updated(t){}firstUpdated(t){}};w.elementStyles=[],w.shadowRootOptions={mode:"open"},w[v("elementProperties")]=new Map,w[v("finalized")]=new Map,y?.({ReactiveElement:w}),(g.reactiveElementVersions??=[]).push("2.1.2"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const M=globalThis,A=t=>t,S=M.trustedTypes,T=S?S.createPolicy("lit-html",{createHTML:t=>t}):void 0,C="$lit$",N=`lit$${Math.random().toFixed(9).slice(2)}$`,E="?"+N,k=`<${E}>`,U=document,D=()=>U.createComment(""),P=t=>null===t||"object"!=typeof t&&"function"!=typeof t,O=Array.isArray,F="[ \t\n\f\r]",H=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,L=/-->/g,z=/>/g,j=RegExp(`>|${F}(?:([^\\s"'>=/]+)(${F}*=${F}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),R=/'/g,Y=/"/g,q=/^(?:script|style|textarea|title)$/i,I=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),W=I(1),Z=I(2),V=Symbol.for("lit-noChange"),B=Symbol.for("lit-nothing"),G=new WeakMap,X=U.createTreeWalker(U,129);function J(t,e){if(!O(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==T?T.createHTML(e):e}const Q=(t,e)=>{const n=t.length-1,r=[];let i,a=2===e?"":3===e?"":"",s=H;for(let e=0;e"===c[0]?(s=i??H,l=-1):void 0===c[1]?l=-2:(l=s.lastIndex-c[2].length,o=c[1],s=void 0===c[3]?j:'"'===c[3]?Y:R):s===Y||s===R?s=j:s===L||s===z?s=H:(s=j,i=void 0);const u=s===j&&t[e+1].startsWith("/>")?" ":"";a+=s===H?n+k:l>=0?(r.push(o),n.slice(0,l)+C+n.slice(l)+N+u):n+N+(-2===l?e:u)}return[J(t,a+(t[n]||"")+(2===e?"":3===e?"":"")),r]};class K{constructor({strings:t,_$litType$:e},n){let r;this.parts=[];let i=0,a=0;const s=t.length-1,o=this.parts,[c,l]=Q(t,e);if(this.el=K.createElement(c,n),X.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(r=X.nextNode())&&o.length0){r.textContent=S?S.emptyScript:"";for(let n=0;nO(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==B&&P(this._$AH)?this._$AA.nextSibling.data=t:this.T(U.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:n}=t,r="number"==typeof n?this._$AC(t):(void 0===n.el&&(n.el=K.createElement(J(n.h,n.h[0]),this.options)),n);if(this._$AH?._$AD===r)this._$AH.p(e);else{const t=new et(r,this),n=t.u(this.options);t.p(e),this.T(n),this._$AH=t}}_$AC(t){let e=G.get(t.strings);return void 0===e&&G.set(t.strings,e=new K(t)),e}k(t){O(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,r=0;for(const i of t)r===e.length?e.push(n=new nt(this.O(D()),this.O(D()),this,this.options)):n=e[r],n._$AI(i),r++;r2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=B}_$AI(t,e=this,n,r){const i=this.strings;let a=!1;if(void 0===i)t=tt(this,t,e,0),a=!P(t)||t!==this._$AH&&t!==V,a&&(this._$AH=t);else{const r=t;let s,o;for(t=i[0],s=0;s{const r=n?.renderBefore??e;let i=r._$litPart$;if(void 0===i){const t=n?.renderBefore??null;r._$litPart$=i=new nt(e.insertBefore(D(),t),t,void 0,n??{})}return i._$AI(t),i})(e,this.renderRoot,this.renderOptions)}connectedCallback(){super.connectedCallback(),this._$Do?.setConnected(!0)}disconnectedCallback(){super.disconnectedCallback(),this._$Do?.setConnected(!1)}render(){return V}}ht._$litElement$=!0,ht.finalized=!0,lt.litElementHydrateSupport?.({LitElement:ht});const ut=lt.litElementPolyfillSupport;ut?.({LitElement:ht}),(lt.litElementVersions??=[]).push("4.2.2"); /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ const dt={attribute:!0,type:String,converter:b,reflect:!1,hasChanged:x},pt=(t=dt,e,n)=>{const{kind:r,metadata:i}=n;let a=globalThis.litPropertyMetadata.get(i);if(void 0===a&&globalThis.litPropertyMetadata.set(i,a=new Map),"setter"===r&&((t=Object.create(t)).wrapped=!0),a.set(n.name,t),"accessor"===r){const{name:r}=n;return{set(n){const i=e.get.call(this);e.set.call(this,n),this.requestUpdate(r,i,t,!0,n)},init(e){return void 0!==e&&this.C(r,void 0,t,e),e}}}if("setter"===r){const{name:r}=n;return function(n){const i=this[r];e.call(this,n),this.requestUpdate(r,i,t,!0,n)}}throw Error("Unsupported decorator location: "+r)}; /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function ft(t){return(e,n)=>"object"==typeof n?pt(t,e,n):((t,e,n)=>{const r=e.hasOwnProperty(n);return e.constructor.createProperty(n,t),r?Object.getOwnPropertyDescriptor(e,n):void 0})(t,e,n)} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */function gt(t){return ft({...t,state:!0,attribute:!1})} /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */const mt={en:{editor:{groups:{display:"Display"},title:"Title (Optional)",places:"Places",show_trend:"Show trend indicators (vs Yesterday)",show_last_updated:"Show last updated",show_stats:"Show statistics (Yesterday, Last Week, 10-Year Avg)",show_chart:"Show historical chart (30d)",show_country:"Append country to place name",chart_smoothing:"Chart smoothing",chart_smoothing_options:{smooth:"Smooth",linear:"Linear",step:"Step"},sort_by:"Sort places by",sort_by_options:{default:"Default (Manual)",name:"Name (A-Z)",temp_asc:"Temperature (Coldest First)",temp_desc:"Temperature (Warmest First)"},add_place:"Add Place"},card:{yesterday:"Yesterday",last_week:"Last Week",average_avg:"10-Year Avg",averages:"Averages",min:"Min",max:"Max",avg:"Avg",chart_description:"30-day trend"},common:{errors:{no_places:"You need to define at least one place.",duplicate_place:"This place is already in your list."}}},de:{editor:{groups:{display:"Anzeige"},title:"Titel (Optional)",places:"Orte",show_trend:"Zeige Trend-Indikatoren (vs Gestern)",show_last_updated:"Zuletzt aktualisiert anzeigen",show_stats:"Statistiken anzeigen (Gestern, Letzte Woche, 10-Jahres-Ø)",show_chart:"Historisches Diagramm anzeigen (30t)",show_country:"Land an den Ortsnamen anhängen",chart_smoothing:"Kurvenglättung",chart_smoothing_options:{smooth:"Weich",linear:"Linear",step:"Stufen"},sort_by:"Orte sortieren nach",sort_by_options:{default:"Standard (Manuell)",name:"Name (A-Z)",temp_asc:"Temperatur (Kälteste zuerst)",temp_desc:"Temperatur (Wärmste zuerst)"},add_place:"Ort hinzufügen"},card:{yesterday:"Gestern",last_week:"Letzte Woche",average_avg:"10-Jahres-Ø",averages:"Durchschnitte",min:"Min",max:"Max",avg:"Ø",chart_description:"30-Tage-Trend"},common:{errors:{no_places:"Du musst mindestens einen Ort definieren.",duplicate_place:"Dieser Ort ist bereits in deiner Liste."}}},fr:{editor:{groups:{display:"Affichage"},title:"Titre (Optionnel)",places:"Lieux",show_trend:"Afficher les indicateurs de tendance (vs Hier)",show_last_updated:"Afficher la dernière mise à jour",show_stats:"Afficher les statistiques (Hier, La semaine dernière, Moy. 10 ans)",show_chart:"Afficher le graphique historique (30j)",show_country:"Ajouter le pays au nom du lieu",chart_smoothing:"Lissage du graphique",chart_smoothing_options:{smooth:"Lisse",linear:"Linéaire",step:"En escalier"},sort_by:"Trier les lieux par",sort_by_options:{default:"Défaut (Manuel)",name:"Nom (A-Z)",temp_asc:"Température (Le plus froid d'abord)",temp_desc:"Température (Le plus chaud d'abord)"},add_place:"Ajouter un lieu"},card:{yesterday:"Hier",last_week:"La semaine dernière",average_avg:"Moy. 10 ans",averages:"Moyennes",min:"Min",max:"Max",avg:"Moy",chart_description:"Tendance sur 30 jours"},common:{errors:{no_places:"Vous devez définir au moins un lieu.",duplicate_place:"Ce lieu est déjà dans votre liste."}}},es:{editor:{groups:{display:"Pantalla"},title:"Título (Opcional)",places:"Lugares",show_trend:"Mostrar indicadores de tendencia (vs Ayer)",show_last_updated:"Mostrar última actualización",show_stats:"Mostrar estadísticas (Ayer, Semana pasada, Media 10 años)",show_chart:"Mostrar gráfico histórico (30d)",show_country:"Añadir el país al nombre del lugar",chart_smoothing:"Suavizado del gráfico",chart_smoothing_options:{smooth:"Suave",linear:"Lineal",step:"Escalonado"},sort_by:"Ordenar lugares por",sort_by_options:{default:"Por defecto (Manual)",name:"Nombre (A-Z)",temp_asc:"Temperatura (Más frío primero)",temp_desc:"Temperatura (Más cálido primero)"},add_place:"Añadir Lugar"},card:{yesterday:"Ayer",last_week:"Semana Pasada",average_avg:"Media 10 años",averages:"Medias",min:"Mín",max:"Máx",avg:"Med",chart_description:"Tendencia de 30 días"},common:{errors:{no_places:"Debes definir al menos un lugar.",duplicate_place:"Este lugar ya está en tu lista."}}},it:{editor:{groups:{display:"Visualizzazione"},title:"Titolo (Opzionale)",places:"Luoghi",show_trend:"Mostra indicatori di tendenza (vs Ieri)",show_last_updated:"Mostra ultimo aggiornamento",show_stats:"Mostra statistiche (Ieri, Settimana scorsa, Media 10 anni)",show_chart:"Mostra grafico storico (30g)",show_country:"Aggiungi il paese al nome del luogo",chart_smoothing:"Arrotondamento grafico",chart_smoothing_options:{smooth:"Morbido",linear:"Lineare",step:"A gradini"},sort_by:"Ordina luoghi per",sort_by_options:{default:"Predefinito (Manuale)",name:"Nome (A-Z)",temp_asc:"Temperatura (Più freddo prima)",temp_desc:"Temperatura (Più caldo prima)"},add_place:"Aggiungi Luogo"},card:{yesterday:"Ieri",last_week:"Settimana Scorsa",average_avg:"Media 10 anni",averages:"Medie",min:"Min",max:"Max",avg:"Med",chart_description:"Andamento a 30 giorni"},common:{errors:{no_places:"Devi definire almeno un luogo.",duplicate_place:"Questo luogo è già nella tua lista."}}}};function _t(t,e){let n=mt[t];for(const t of e){if("object"!=typeof n||null===n)return;n=n[t]}return"string"==typeof n?n:void 0}function yt(t,e,n={}){const r=t?.language||"en",i=e.replace("component.sea-temperatures-card.","").split("."),a=_t(r,i)??_t("en",i);if("string"==typeof a){let t=a;for(const e in n)t=t.replace(`{${e}}`,String(n[e]));return t}return e}const vt=(t,e,n,r)=>{const i=new CustomEvent(e,{bubbles:!0,cancelable:!1,composed:!0,...r,detail:n});t.dispatchEvent(i)};function bt(t,e){return null==t||null==e?NaN:te?1:t>=e?0:NaN}function xt(t,e){return null==t||null==e?NaN:et?1:e>=t?0:NaN}function $t(t){let e,n,r;function i(t,r,i=0,a=t.length){if(i>>1;n(t[e],r)<0?i=e+1:a=e}while(ibt(t(e),n),r=(e,n)=>t(e)-n):(e=t===bt||t===xt?t:wt,n=t,r=t),{left:i,center:function(t,e,n=0,a=t.length){const s=i(t,e,n,a-1);return s>n&&r(t[s-1],e)>-r(t[s],e)?s-1:s},right:function(t,r,i=0,a=t.length){if(i>>1;n(t[e],r)<=0?i=e+1:a=e}while(i=e&&(n=r=e):(n>e&&(n=e),r=a&&(n=r=a):(n>a&&(n=a),r=St?10:a>=Tt?5:a>=Ct?2:1;let o,c,l;return i<0?(l=Math.pow(10,-i)/s,o=Math.round(t*l),c=Math.round(e*l),o/le&&--c,l=-l):(l=Math.pow(10,i)*s,o=Math.round(t/l),c=Math.round(e/l),o*le&&--c),c>8&15|e>>4&240,e>>4&15|240&e,(15&e)<<4|15&e,1):8===n?Kt(e>>24&255,e>>16&255,e>>8&255,(255&e)/255):4===n?Kt(e>>12&15|e>>8&240,e>>8&15|e>>4&240,e>>4&15|240&e,((15&e)<<4|15&e)/255):null):(e=Yt.exec(t))?new ee(e[1],e[2],e[3],1):(e=qt.exec(t))?new ee(255*e[1]/100,255*e[2]/100,255*e[3]/100,1):(e=It.exec(t))?Kt(e[1],e[2],e[3],e[4]):(e=Wt.exec(t))?Kt(255*e[1]/100,255*e[2]/100,255*e[3]/100,e[4]):(e=Zt.exec(t))?oe(e[1],e[2]/100,e[3]/100,1):(e=Vt.exec(t))?oe(e[1],e[2]/100,e[3]/100,e[4]):Bt.hasOwnProperty(t)?Qt(Bt[t]):"transparent"===t?new ee(NaN,NaN,NaN,0):null}function Qt(t){return new ee(t>>16&255,t>>8&255,255&t,1)}function Kt(t,e,n,r){return r<=0&&(t=e=n=NaN),new ee(t,e,n,r)}function te(t,e,n,r){return 1===arguments.length?function(t){return t instanceof Ot||(t=Jt(t)),t?new ee((t=t.rgb()).r,t.g,t.b,t.opacity):new ee}(t):new ee(t,e,n,null==r?1:r)}function ee(t,e,n,r){this.r=+t,this.g=+e,this.b=+n,this.opacity=+r}function ne(){return`#${se(this.r)}${se(this.g)}${se(this.b)}`}function re(){const t=ie(this.opacity);return`${1===t?"rgb(":"rgba("}${ae(this.r)}, ${ae(this.g)}, ${ae(this.b)}${1===t?")":`, ${t})`}`}function ie(t){return isNaN(t)?1:Math.max(0,Math.min(1,t))}function ae(t){return Math.max(0,Math.min(255,Math.round(t)||0))}function se(t){return((t=ae(t))<16?"0":"")+t.toString(16)}function oe(t,e,n,r){return r<=0?t=e=n=NaN:n<=0||n>=1?t=e=NaN:e<=0&&(t=NaN),new le(t,e,n,r)}function ce(t){if(t instanceof le)return new le(t.h,t.s,t.l,t.opacity);if(t instanceof Ot||(t=Jt(t)),!t)return new le;if(t instanceof le)return t;var e=(t=t.rgb()).r/255,n=t.g/255,r=t.b/255,i=Math.min(e,n,r),a=Math.max(e,n,r),s=NaN,o=a-i,c=(a+i)/2;return o?(s=e===a?(n-r)/o+6*(n0&&c<1?0:s,new le(s,o,c,t.opacity)}function le(t,e,n,r){this.h=+t,this.s=+e,this.l=+n,this.opacity=+r}function he(t){return(t=(t||0)%360)<0?t+360:t}function ue(t){return Math.max(0,Math.min(1,t||0))}function de(t,e,n){return 255*(t<60?e+(n-e)*t/60:t<180?n:t<240?e+(n-e)*(240-t)/60:e)}Dt(Ot,Jt,{copy(t){return Object.assign(new this.constructor,this,t)},displayable(){return this.rgb().displayable()},hex:Gt,formatHex:Gt,formatHex8:function(){return this.rgb().formatHex8()},formatHsl:function(){return ce(this).formatHsl()},formatRgb:Xt,toString:Xt}),Dt(ee,te,Pt(Ot,{brighter(t){return t=null==t?Ht:Math.pow(Ht,t),new ee(this.r*t,this.g*t,this.b*t,this.opacity)},darker(t){return t=null==t?Ft:Math.pow(Ft,t),new ee(this.r*t,this.g*t,this.b*t,this.opacity)},rgb(){return this},clamp(){return new ee(ae(this.r),ae(this.g),ae(this.b),ie(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:ne,formatHex:ne,formatHex8:function(){return`#${se(this.r)}${se(this.g)}${se(this.b)}${se(255*(isNaN(this.opacity)?1:this.opacity))}`},formatRgb:re,toString:re})),Dt(le,function(t,e,n,r){return 1===arguments.length?ce(t):new le(t,e,n,null==r?1:r)},Pt(Ot,{brighter(t){return t=null==t?Ht:Math.pow(Ht,t),new le(this.h,this.s,this.l*t,this.opacity)},darker(t){return t=null==t?Ft:Math.pow(Ft,t),new le(this.h,this.s,this.l*t,this.opacity)},rgb(){var t=this.h%360+360*(this.h<0),e=isNaN(t)||isNaN(this.s)?0:this.s,n=this.l,r=n+(n<.5?n:1-n)*e,i=2*n-r;return new ee(de(t>=240?t-240:t+120,i,r),de(t,i,r),de(t<120?t+240:t-120,i,r),this.opacity)},clamp(){return new le(he(this.h),ue(this.s),ue(this.l),ie(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const t=ie(this.opacity);return`${1===t?"hsl(":"hsla("}${he(this.h)}, ${100*ue(this.s)}%, ${100*ue(this.l)}%${1===t?")":`, ${t})`}`}}));var pe=t=>()=>t;function fe(t){return 1===(t=+t)?ge:function(e,n){return n-e?function(t,e,n){return t=Math.pow(t,n),e=Math.pow(e,n)-t,n=1/n,function(r){return Math.pow(t+r*e,n)}}(e,n,t):pe(isNaN(e)?n:e)}}function ge(t,e){var n=e-t;return n?function(t,e){return function(n){return t+n*e}}(t,n):pe(isNaN(t)?e:t)}var me=function t(e){var n=fe(e);function r(t,e){var r=n((t=te(t)).r,(e=te(e)).r),i=n(t.g,e.g),a=n(t.b,e.b),s=ge(t.opacity,e.opacity);return function(e){return t.r=r(e),t.g=i(e),t.b=a(e),t.opacity=s(e),t+""}}return r.gamma=t,r}(1);function _e(t,e){e||(e=[]);var n,r=t?Math.min(e.length,t.length):0,i=e.slice();return function(a){for(n=0;na&&(i=e.slice(a,i),o[s]?o[s]+=i:o[++s]=i),(n=n[0])===(r=r[0])?o[s]?o[s]+=r:o[++s]=r:(o[++s]=null,c.push({i:s,x:be(n,r)})),a=we.lastIndex;return ae&&(n=t,t=e,e=n),function(n){return Math.max(t,Math.min(e,n))}}(s[0],s[t-1])),r=t>2?Ue:ke,i=a=null,u}function u(e){return null==e||isNaN(e=+e)?n:(i||(i=r(s.map(t),o,c)))(t(l(e)))}return u.invert=function(n){return l(e((a||(a=r(o,s.map(t),be)))(n)))},u.domain=function(t){return arguments.length?(s=Array.from(t,Te),h()):s.slice()},u.range=function(t){return arguments.length?(o=Array.from(t),h()):o.slice()},u.rangeRound=function(t){return o=Array.from(t),c=Se,h()},u.clamp=function(t){return arguments.length?(l=!!t||Ne,h()):l!==Ne},u.interpolate=function(t){return arguments.length?(c=t,h()):c},u.unknown=function(t){return arguments.length?(n=t,u):n},function(n,r){return t=n,e=r,h()}}function Oe(){return Pe()(Ne,Ne)}function Fe(t,e){if(!isFinite(t)||0===t)return null;var n=(t=e?t.toExponential(e-1):t.toExponential()).indexOf("e"),r=t.slice(0,n);return[r.length>1?r[0]+r.slice(2):r,+t.slice(n+1)]}function He(t){return(t=Fe(Math.abs(t)))?t[1]:NaN}var Le,ze=/^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;function je(t){if(!(e=ze.exec(t)))throw new Error("invalid format: "+t);var e;return new Re({fill:e[1],align:e[2],sign:e[3],symbol:e[4],zero:e[5],width:e[6],comma:e[7],precision:e[8]&&e[8].slice(1),trim:e[9],type:e[10]})}function Re(t){this.fill=void 0===t.fill?" ":t.fill+"",this.align=void 0===t.align?">":t.align+"",this.sign=void 0===t.sign?"-":t.sign+"",this.symbol=void 0===t.symbol?"":t.symbol+"",this.zero=!!t.zero,this.width=void 0===t.width?void 0:+t.width,this.comma=!!t.comma,this.precision=void 0===t.precision?void 0:+t.precision,this.trim=!!t.trim,this.type=void 0===t.type?"":t.type+""}function Ye(t,e){var n=Fe(t,e);if(!n)return t+"";var r=n[0],i=n[1];return i<0?"0."+new Array(-i).join("0")+r:r.length>i+1?r.slice(0,i+1)+"."+r.slice(i+1):r+new Array(i-r.length+2).join("0")}je.prototype=Re.prototype,Re.prototype.toString=function(){return this.fill+this.align+this.sign+this.symbol+(this.zero?"0":"")+(void 0===this.width?"":Math.max(1,0|this.width))+(this.comma?",":"")+(void 0===this.precision?"":"."+Math.max(0,0|this.precision))+(this.trim?"~":"")+this.type};var qe={"%":(t,e)=>(100*t).toFixed(e),b:t=>Math.round(t).toString(2),c:t=>t+"",d:function(t){return Math.abs(t=Math.round(t))>=1e21?t.toLocaleString("en").replace(/,/g,""):t.toString(10)},e:(t,e)=>t.toExponential(e),f:(t,e)=>t.toFixed(e),g:(t,e)=>t.toPrecision(e),o:t=>Math.round(t).toString(8),p:(t,e)=>Ye(100*t,e),r:Ye,s:function(t,e){var n=Fe(t,e);if(!n)return Le=void 0,t.toPrecision(e);var r=n[0],i=n[1],a=i-(Le=3*Math.max(-8,Math.min(8,Math.floor(i/3))))+1,s=r.length;return a===s?r:a>s?r+new Array(a-s+1).join("0"):a>0?r.slice(0,a)+"."+r.slice(a):"0."+new Array(1-a).join("0")+Fe(t,Math.max(0,e+a-1))[0]},X:t=>Math.round(t).toString(16).toUpperCase(),x:t=>Math.round(t).toString(16)};function Ie(t){return t}var We,Ze,Ve,Be=Array.prototype.map,Ge=["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];function Xe(t){var e,n,r=void 0===t.grouping||void 0===t.thousands?Ie:(e=Be.call(t.grouping,Number),n=t.thousands+"",function(t,r){for(var i=t.length,a=[],s=0,o=e[0],c=0;i>0&&o>0&&(c+o+1>r&&(o=Math.max(1,r-c)),a.push(t.substring(i-=o,i+o)),!((c+=o+1)>r));)o=e[s=(s+1)%e.length];return a.reverse().join(n)}),i=void 0===t.currency?"":t.currency[0]+"",a=void 0===t.currency?"":t.currency[1]+"",s=void 0===t.decimal?".":t.decimal+"",o=void 0===t.numerals?Ie:function(t){return function(e){return e.replace(/[0-9]/g,function(e){return t[+e]})}}(Be.call(t.numerals,String)),c=void 0===t.percent?"%":t.percent+"",l=void 0===t.minus?"−":t.minus+"",h=void 0===t.nan?"NaN":t.nan+"";function u(t,e){var n=(t=je(t)).fill,u=t.align,d=t.sign,p=t.symbol,f=t.zero,g=t.width,m=t.comma,_=t.precision,y=t.trim,v=t.type;"n"===v?(m=!0,v="g"):qe[v]||(void 0===_&&(_=12),y=!0,v="g"),(f||"0"===n&&"="===u)&&(f=!0,n="0",u="=");var b=(e&&void 0!==e.prefix?e.prefix:"")+("$"===p?i:"#"===p&&/[boxX]/.test(v)?"0"+v.toLowerCase():""),x=("$"===p?a:/[%p]/.test(v)?c:"")+(e&&void 0!==e.suffix?e.suffix:""),$=qe[v],w=/[defgprs%]/.test(v);function M(t){var e,i,a,c=b,p=x;if("c"===v)p=$(t)+p,t="";else{var M=(t=+t)<0||1/t<0;if(t=isNaN(t)?h:$(Math.abs(t),_),y&&(t=function(t){t:for(var e,n=t.length,r=1,i=-1;r0&&(i=0)}return i>0?t.slice(0,i)+t.slice(e+1):t}(t)),M&&0===+t&&"+"!==d&&(M=!1),c=(M?"("===d?d:l:"-"===d||"("===d?"":d)+c,p=("s"!==v||isNaN(t)||void 0===Le?"":Ge[8+Le/3])+p+(M&&"("===d?")":""),w)for(e=-1,i=t.length;++e(a=t.charCodeAt(e))||a>57){p=(46===a?s+t.slice(e+1):t.slice(e))+p,t=t.slice(0,e);break}}m&&!f&&(t=r(t,1/0));var A=c.length+t.length+p.length,S=A>1)+c+t+p+S.slice(A);break;default:t=S+c+t+p}return o(t)}return _=void 0===_?6:/[gprs]/.test(v)?Math.max(1,Math.min(21,_)):Math.max(0,Math.min(20,_)),M.toString=function(){return t+""},M}return{format:u,formatPrefix:function(t,e){var n=3*Math.max(-8,Math.min(8,Math.floor(He(e)/3))),r=Math.pow(10,-n),i=u(((t=je(t)).type="f",t),{suffix:Ge[8+n/3]});return function(t){return i(r*t)}}}}function Je(t,e,n,r){var i,a=kt(t,e,n);switch((r=je(null==r?",f":r)).type){case"s":var s=Math.max(Math.abs(t),Math.abs(e));return null!=r.precision||isNaN(i=function(t,e){return Math.max(0,3*Math.max(-8,Math.min(8,Math.floor(He(e)/3)))-He(Math.abs(t)))}(a,s))||(r.precision=i),Ve(r,s);case"":case"e":case"g":case"p":case"r":null!=r.precision||isNaN(i=function(t,e){return t=Math.abs(t),e=Math.abs(e)-t,Math.max(0,He(e)-He(t))+1}(a,Math.max(Math.abs(t),Math.abs(e))))||(r.precision=i-("e"===r.type));break;case"f":case"%":null!=r.precision||isNaN(i=function(t){return Math.max(0,-He(Math.abs(t)))}(a))||(r.precision=i-2*("%"===r.type))}return Ze(r)}function Qe(t){var e=t.domain;return t.ticks=function(t){var n=e();return function(t,e,n){if(!((n=+n)>0))return[];if((t=+t)===(e=+e))return[t];const r=e=i))return[];const o=a-i+1,c=new Array(o);if(r)if(s<0)for(let t=0;t0;){if((i=Et(c,l,n))===r)return a[s]=c,a[o]=l,e(a);if(i>0)c=Math.floor(c/i)*i,l=Math.ceil(l/i)*i;else{if(!(i<0))break;c=Math.ceil(c*i)/i,l=Math.floor(l*i)/i}r=i}return t},t}function Ke(){var t=Oe();return t.copy=function(){return De(t,Ke())},Ut.apply(t,arguments),Qe(t)}We=Xe({thousands:",",grouping:[3],currency:["$",""]}),Ze=We.format,Ve=We.formatPrefix;const tn=new Date,en=new Date;function nn(t,e,n,r){function i(e){return t(e=0===arguments.length?new Date:new Date(+e)),e}return i.floor=e=>(t(e=new Date(+e)),e),i.ceil=n=>(t(n=new Date(n-1)),e(n,1),t(n),n),i.round=t=>{const e=i(t),n=i.ceil(t);return t-e(e(t=new Date(+t),null==n?1:Math.floor(n)),t),i.range=(n,r,a)=>{const s=[];if(n=i.ceil(n),a=null==a?1:Math.floor(a),!(n0))return s;let o;do{s.push(o=new Date(+n)),e(n,a),t(n)}while(onn(e=>{if(e>=e)for(;t(e),!n(e);)e.setTime(e-1)},(t,r)=>{if(t>=t)if(r<0)for(;++r<=0;)for(;e(t,-1),!n(t););else for(;--r>=0;)for(;e(t,1),!n(t););}),n&&(i.count=(e,r)=>(tn.setTime(+e),en.setTime(+r),t(tn),t(en),Math.floor(n(tn,en))),i.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?i.filter(r?e=>r(e)%t===0:e=>i.count(0,e)%t===0):i:null)),i}const rn=nn(()=>{},(t,e)=>{t.setTime(+t+e)},(t,e)=>e-t);rn.every=t=>(t=Math.floor(t),isFinite(t)&&t>0?t>1?nn(e=>{e.setTime(Math.floor(e/t)*t)},(e,n)=>{e.setTime(+e+n*t)},(e,n)=>(n-e)/t):rn:null),rn.range;const an=1e3,sn=6e4,on=36e5,cn=864e5,ln=6048e5,hn=2592e6,un=31536e6,dn=nn(t=>{t.setTime(t-t.getMilliseconds())},(t,e)=>{t.setTime(+t+e*an)},(t,e)=>(e-t)/an,t=>t.getUTCSeconds());dn.range;const pn=nn(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*an)},(t,e)=>{t.setTime(+t+e*sn)},(t,e)=>(e-t)/sn,t=>t.getMinutes());pn.range;const fn=nn(t=>{t.setUTCSeconds(0,0)},(t,e)=>{t.setTime(+t+e*sn)},(t,e)=>(e-t)/sn,t=>t.getUTCMinutes());fn.range;const gn=nn(t=>{t.setTime(t-t.getMilliseconds()-t.getSeconds()*an-t.getMinutes()*sn)},(t,e)=>{t.setTime(+t+e*on)},(t,e)=>(e-t)/on,t=>t.getHours());gn.range;const mn=nn(t=>{t.setUTCMinutes(0,0,0)},(t,e)=>{t.setTime(+t+e*on)},(t,e)=>(e-t)/on,t=>t.getUTCHours());mn.range;const _n=nn(t=>t.setHours(0,0,0,0),(t,e)=>t.setDate(t.getDate()+e),(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*sn)/cn,t=>t.getDate()-1);_n.range;const yn=nn(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/cn,t=>t.getUTCDate()-1);yn.range;const vn=nn(t=>{t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+e)},(t,e)=>(e-t)/cn,t=>Math.floor(t/cn));function bn(t){return nn(e=>{e.setDate(e.getDate()-(e.getDay()+7-t)%7),e.setHours(0,0,0,0)},(t,e)=>{t.setDate(t.getDate()+7*e)},(t,e)=>(e-t-(e.getTimezoneOffset()-t.getTimezoneOffset())*sn)/ln)}vn.range;const xn=bn(0),$n=bn(1),wn=bn(2),Mn=bn(3),An=bn(4),Sn=bn(5),Tn=bn(6);function Cn(t){return nn(e=>{e.setUTCDate(e.getUTCDate()-(e.getUTCDay()+7-t)%7),e.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCDate(t.getUTCDate()+7*e)},(t,e)=>(e-t)/ln)}xn.range,$n.range,wn.range,Mn.range,An.range,Sn.range,Tn.range;const Nn=Cn(0),En=Cn(1),kn=Cn(2),Un=Cn(3),Dn=Cn(4),Pn=Cn(5),On=Cn(6);Nn.range,En.range,kn.range,Un.range,Dn.range,Pn.range,On.range;const Fn=nn(t=>{t.setDate(1),t.setHours(0,0,0,0)},(t,e)=>{t.setMonth(t.getMonth()+e)},(t,e)=>e.getMonth()-t.getMonth()+12*(e.getFullYear()-t.getFullYear()),t=>t.getMonth());Fn.range;const Hn=nn(t=>{t.setUTCDate(1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCMonth(t.getUTCMonth()+e)},(t,e)=>e.getUTCMonth()-t.getUTCMonth()+12*(e.getUTCFullYear()-t.getUTCFullYear()),t=>t.getUTCMonth());Hn.range;const Ln=nn(t=>{t.setMonth(0,1),t.setHours(0,0,0,0)},(t,e)=>{t.setFullYear(t.getFullYear()+e)},(t,e)=>e.getFullYear()-t.getFullYear(),t=>t.getFullYear());Ln.every=t=>isFinite(t=Math.floor(t))&&t>0?nn(e=>{e.setFullYear(Math.floor(e.getFullYear()/t)*t),e.setMonth(0,1),e.setHours(0,0,0,0)},(e,n)=>{e.setFullYear(e.getFullYear()+n*t)}):null,Ln.range;const zn=nn(t=>{t.setUTCMonth(0,1),t.setUTCHours(0,0,0,0)},(t,e)=>{t.setUTCFullYear(t.getUTCFullYear()+e)},(t,e)=>e.getUTCFullYear()-t.getUTCFullYear(),t=>t.getUTCFullYear());zn.every=t=>isFinite(t=Math.floor(t))&&t>0?nn(e=>{e.setUTCFullYear(Math.floor(e.getUTCFullYear()/t)*t),e.setUTCMonth(0,1),e.setUTCHours(0,0,0,0)},(e,n)=>{e.setUTCFullYear(e.getUTCFullYear()+n*t)}):null,zn.range;const[jn,Rn]=function(t,e,n,r,i,a){const s=[[dn,1,an],[dn,5,5e3],[dn,15,15e3],[dn,30,3e4],[a,1,sn],[a,5,3e5],[a,15,9e5],[a,30,18e5],[i,1,on],[i,3,108e5],[i,6,216e5],[i,12,432e5],[r,1,cn],[r,2,1728e5],[n,1,ln],[e,1,hn],[e,3,7776e6],[t,1,un]];function o(e,n,r){const i=Math.abs(n-e)/r,a=$t(([,,t])=>t).right(s,i);if(a===s.length)return t.every(kt(e/un,n/un,r));if(0===a)return rn.every(Math.max(kt(e,n,r),1));const[o,c]=s[i/s[a-1][2][t.toLowerCase(),e]))}function er(t,e,n){var r=Bn.exec(e.slice(n,n+1));return r?(t.w=+r[0],n+r[0].length):-1}function nr(t,e,n){var r=Bn.exec(e.slice(n,n+1));return r?(t.u=+r[0],n+r[0].length):-1}function rr(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.U=+r[0],n+r[0].length):-1}function ir(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.V=+r[0],n+r[0].length):-1}function ar(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.W=+r[0],n+r[0].length):-1}function sr(t,e,n){var r=Bn.exec(e.slice(n,n+4));return r?(t.y=+r[0],n+r[0].length):-1}function or(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.y=+r[0]+(+r[0]>68?1900:2e3),n+r[0].length):-1}function cr(t,e,n){var r=/^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(e.slice(n,n+6));return r?(t.Z=r[1]?0:-(r[2]+(r[3]||"00")),n+r[0].length):-1}function lr(t,e,n){var r=Bn.exec(e.slice(n,n+1));return r?(t.q=3*r[0]-3,n+r[0].length):-1}function hr(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.m=r[0]-1,n+r[0].length):-1}function ur(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.d=+r[0],n+r[0].length):-1}function dr(t,e,n){var r=Bn.exec(e.slice(n,n+3));return r?(t.m=0,t.d=+r[0],n+r[0].length):-1}function pr(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.H=+r[0],n+r[0].length):-1}function fr(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.M=+r[0],n+r[0].length):-1}function gr(t,e,n){var r=Bn.exec(e.slice(n,n+2));return r?(t.S=+r[0],n+r[0].length):-1}function mr(t,e,n){var r=Bn.exec(e.slice(n,n+3));return r?(t.L=+r[0],n+r[0].length):-1}function _r(t,e,n){var r=Bn.exec(e.slice(n,n+6));return r?(t.L=Math.floor(r[0]/1e3),n+r[0].length):-1}function yr(t,e,n){var r=Gn.exec(e.slice(n,n+1));return r?n+r[0].length:-1}function vr(t,e,n){var r=Bn.exec(e.slice(n));return r?(t.Q=+r[0],n+r[0].length):-1}function br(t,e,n){var r=Bn.exec(e.slice(n));return r?(t.s=+r[0],n+r[0].length):-1}function xr(t,e){return Jn(t.getDate(),e,2)}function $r(t,e){return Jn(t.getHours(),e,2)}function wr(t,e){return Jn(t.getHours()%12||12,e,2)}function Mr(t,e){return Jn(1+_n.count(Ln(t),t),e,3)}function Ar(t,e){return Jn(t.getMilliseconds(),e,3)}function Sr(t,e){return Ar(t,e)+"000"}function Tr(t,e){return Jn(t.getMonth()+1,e,2)}function Cr(t,e){return Jn(t.getMinutes(),e,2)}function Nr(t,e){return Jn(t.getSeconds(),e,2)}function Er(t){var e=t.getDay();return 0===e?7:e}function kr(t,e){return Jn(xn.count(Ln(t)-1,t),e,2)}function Ur(t){var e=t.getDay();return e>=4||0===e?An(t):An.ceil(t)}function Dr(t,e){return t=Ur(t),Jn(An.count(Ln(t),t)+(4===Ln(t).getDay()),e,2)}function Pr(t){return t.getDay()}function Or(t,e){return Jn($n.count(Ln(t)-1,t),e,2)}function Fr(t,e){return Jn(t.getFullYear()%100,e,2)}function Hr(t,e){return Jn((t=Ur(t)).getFullYear()%100,e,2)}function Lr(t,e){return Jn(t.getFullYear()%1e4,e,4)}function zr(t,e){var n=t.getDay();return Jn((t=n>=4||0===n?An(t):An.ceil(t)).getFullYear()%1e4,e,4)}function jr(t){var e=t.getTimezoneOffset();return(e>0?"-":(e*=-1,"+"))+Jn(e/60|0,"0",2)+Jn(e%60,"0",2)}function Rr(t,e){return Jn(t.getUTCDate(),e,2)}function Yr(t,e){return Jn(t.getUTCHours(),e,2)}function qr(t,e){return Jn(t.getUTCHours()%12||12,e,2)}function Ir(t,e){return Jn(1+yn.count(zn(t),t),e,3)}function Wr(t,e){return Jn(t.getUTCMilliseconds(),e,3)}function Zr(t,e){return Wr(t,e)+"000"}function Vr(t,e){return Jn(t.getUTCMonth()+1,e,2)}function Br(t,e){return Jn(t.getUTCMinutes(),e,2)}function Gr(t,e){return Jn(t.getUTCSeconds(),e,2)}function Xr(t){var e=t.getUTCDay();return 0===e?7:e}function Jr(t,e){return Jn(Nn.count(zn(t)-1,t),e,2)}function Qr(t){var e=t.getUTCDay();return e>=4||0===e?Dn(t):Dn.ceil(t)}function Kr(t,e){return t=Qr(t),Jn(Dn.count(zn(t),t)+(4===zn(t).getUTCDay()),e,2)}function ti(t){return t.getUTCDay()}function ei(t,e){return Jn(En.count(zn(t)-1,t),e,2)}function ni(t,e){return Jn(t.getUTCFullYear()%100,e,2)}function ri(t,e){return Jn((t=Qr(t)).getUTCFullYear()%100,e,2)}function ii(t,e){return Jn(t.getUTCFullYear()%1e4,e,4)}function ai(t,e){var n=t.getUTCDay();return Jn((t=n>=4||0===n?Dn(t):Dn.ceil(t)).getUTCFullYear()%1e4,e,4)}function si(){return"+0000"}function oi(){return"%"}function ci(t){return+t}function li(t){return Math.floor(+t/1e3)}function hi(t){return new Date(t)}function ui(t){return t instanceof Date?+t:+new Date(+t)}function di(t,e,n,r,i,a,s,o,c,l){var h=Oe(),u=h.invert,d=h.domain,p=l(".%L"),f=l(":%S"),g=l("%I:%M"),m=l("%I %p"),_=l("%a %d"),y=l("%b %d"),v=l("%B"),b=l("%Y");function x(t){return(c(t)=12)]},q:function(t){return 1+~~(t.getMonth()/3)},Q:ci,s:li,S:Nr,u:Er,U:kr,V:Dr,w:Pr,W:Or,x:null,X:null,y:Fr,Y:Lr,Z:jr,"%":oi},b={a:function(t){return s[t.getUTCDay()]},A:function(t){return a[t.getUTCDay()]},b:function(t){return c[t.getUTCMonth()]},B:function(t){return o[t.getUTCMonth()]},c:null,d:Rr,e:Rr,f:Zr,g:ri,G:ai,H:Yr,I:qr,j:Ir,L:Wr,m:Vr,M:Br,p:function(t){return i[+(t.getUTCHours()>=12)]},q:function(t){return 1+~~(t.getUTCMonth()/3)},Q:ci,s:li,S:Gr,u:Xr,U:Jr,V:Kr,w:ti,W:ei,x:null,X:null,y:ni,Y:ii,Z:si,"%":oi},x={a:function(t,e,n){var r=p.exec(e.slice(n));return r?(t.w=f.get(r[0].toLowerCase()),n+r[0].length):-1},A:function(t,e,n){var r=u.exec(e.slice(n));return r?(t.w=d.get(r[0].toLowerCase()),n+r[0].length):-1},b:function(t,e,n){var r=_.exec(e.slice(n));return r?(t.m=y.get(r[0].toLowerCase()),n+r[0].length):-1},B:function(t,e,n){var r=g.exec(e.slice(n));return r?(t.m=m.get(r[0].toLowerCase()),n+r[0].length):-1},c:function(t,n,r){return M(t,e,n,r)},d:ur,e:ur,f:_r,g:or,G:sr,H:pr,I:pr,j:dr,L:mr,m:hr,M:fr,p:function(t,e,n){var r=l.exec(e.slice(n));return r?(t.p=h.get(r[0].toLowerCase()),n+r[0].length):-1},q:lr,Q:vr,s:br,S:gr,u:nr,U:rr,V:ir,w:er,W:ar,x:function(t,e,r){return M(t,n,e,r)},X:function(t,e,n){return M(t,r,e,n)},y:or,Y:sr,Z:cr,"%":yr};function $(t,e){return function(n){var r,i,a,s=[],o=-1,c=0,l=t.length;for(n instanceof Date||(n=new Date(+n));++o53)return null;"w"in a||(a.w=1),"Z"in a?(i=(r=qn(In(a.y,0,1))).getUTCDay(),r=i>4||0===i?En.ceil(r):En(r),r=yn.offset(r,7*(a.V-1)),a.y=r.getUTCFullYear(),a.m=r.getUTCMonth(),a.d=r.getUTCDate()+(a.w+6)%7):(i=(r=Yn(In(a.y,0,1))).getDay(),r=i>4||0===i?$n.ceil(r):$n(r),r=_n.offset(r,7*(a.V-1)),a.y=r.getFullYear(),a.m=r.getMonth(),a.d=r.getDate()+(a.w+6)%7)}else("W"in a||"U"in a)&&("w"in a||(a.w="u"in a?a.u%7:"W"in a?1:0),i="Z"in a?qn(In(a.y,0,1)).getUTCDay():Yn(In(a.y,0,1)).getDay(),a.m=0,a.d="W"in a?(a.w+6)%7+7*a.W-(i+5)%7:a.w+7*a.U-(i+6)%7);return"Z"in a?(a.H+=a.Z/100|0,a.M+=a.Z%100,qn(a)):Yn(a)}}function M(t,e,n,r){for(var i,a,s=0,o=e.length,c=n.length;s=c)return-1;if(37===(i=e.charCodeAt(s++))){if(i=e.charAt(s++),!(a=x[i in Vn?e.charAt(s++):i])||(r=a(t,n,r))<0)return-1}else if(i!=n.charCodeAt(r++))return-1}return r}return v.x=$(n,v),v.X=$(r,v),v.c=$(e,v),b.x=$(n,b),b.X=$(r,b),b.c=$(e,b),{format:function(t){var e=$(t+="",v);return e.toString=function(){return t},e},parse:function(t){var e=w(t+="",!1);return e.toString=function(){return t},e},utcFormat:function(t){var e=$(t+="",b);return e.toString=function(){return t},e},utcParse:function(t){var e=w(t+="",!0);return e.toString=function(){return t},e}}}(t),Zn=Wn.format,Wn.parse,Wn.utcFormat,Wn.utcParse}({dateTime:"%x, %X",date:"%-m/%-d/%Y",time:"%-I:%M:%S %p",periods:["AM","PM"],days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]});const gi=Math.PI,mi=2*gi,_i=1e-6,yi=mi-_i;function vi(t){this._+=t[0];for(let e=1,n=t.length;e=0))throw new Error(`invalid digits: ${t}`);if(e>15)return vi;const n=10**e;return function(t){this._+=t[0];for(let e=1,r=t.length;e_i)if(Math.abs(h*o-c*l)>_i&&i){let d=n-a,p=r-s,f=o*o+c*c,g=d*d+p*p,m=Math.sqrt(f),_=Math.sqrt(u),y=i*Math.tan((gi-Math.acos((f+u-g)/(2*m*_)))/2),v=y/_,b=y/m;Math.abs(v-1)>_i&&this._append`L${t+v*l},${e+v*h}`,this._append`A${i},${i},0,0,${+(h*d>l*p)},${this._x1=t+b*o},${this._y1=e+b*c}`}else this._append`L${this._x1=t},${this._y1=e}`;else;}arc(t,e,n,r,i,a){if(t=+t,e=+e,a=!!a,(n=+n)<0)throw new Error(`negative radius: ${n}`);let s=n*Math.cos(r),o=n*Math.sin(r),c=t+s,l=e+o,h=1^a,u=a?r-i:i-r;null===this._x1?this._append`M${c},${l}`:(Math.abs(this._x1-c)>_i||Math.abs(this._y1-l)>_i)&&this._append`L${c},${l}`,n&&(u<0&&(u=u%mi+mi),u>yi?this._append`A${n},${n},0,1,${h},${t-s},${e-o}A${n},${n},0,1,${h},${this._x1=c},${this._y1=l}`:u>_i&&this._append`A${n},${n},0,${+(u>=gi)},${h},${this._x1=t+n*Math.cos(i)},${this._y1=e+n*Math.sin(i)}`)}rect(t,e,n,r){this._append`M${this._x0=this._x1=+t},${this._y0=this._y1=+e}h${n=+n}v${+r}h${-n}Z`}toString(){return this._}}function xi(t){let e=3;return t.digits=function(n){if(!arguments.length)return e;if(null==n)e=null;else{const t=Math.floor(n);if(!(t>=0))throw new RangeError(`invalid digits: ${n}`);e=t}return t},()=>new bi(e)}function $i(t){return"object"==typeof t&&"length"in t?t:Array.from(t)}function wi(t){this._context=t}function Mi(t){return new wi(t)}function Ai(t){return t[0]}function Si(t){return t[1]}function Ti(t,e){var n=fi(!0),r=null,i=Mi,a=null,s=xi(o);function o(o){var c,l,h,u=(o=$i(o)).length,d=!1;for(null==r&&(a=i(h=s())),c=0;c<=u;++c)!(c=u;--d)o.point(_[d],y[d]);o.lineEnd(),o.areaEnd()}m&&(_[h]=+t(p,h,l),y[h]=+e(p,h,l),o.point(r?+r(p,h,l):_[h],n?+n(p,h,l):y[h]))}if(f)return o=null,f+""||null}function h(){return Ti().defined(i).curve(s).context(a)}return t="function"==typeof t?t:void 0===t?Ai:fi(+t),e="function"==typeof e?e:fi(void 0===e?0:+e),n="function"==typeof n?n:void 0===n?Si:fi(+n),l.x=function(e){return arguments.length?(t="function"==typeof e?e:fi(+e),r=null,l):t},l.x0=function(e){return arguments.length?(t="function"==typeof e?e:fi(+e),l):t},l.x1=function(t){return arguments.length?(r=null==t?null:"function"==typeof t?t:fi(+t),l):r},l.y=function(t){return arguments.length?(e="function"==typeof t?t:fi(+t),n=null,l):e},l.y0=function(t){return arguments.length?(e="function"==typeof t?t:fi(+t),l):e},l.y1=function(t){return arguments.length?(n=null==t?null:"function"==typeof t?t:fi(+t),l):n},l.lineX0=l.lineY0=function(){return h().x(t).y(e)},l.lineY1=function(){return h().x(t).y(n)},l.lineX1=function(){return h().x(r).y(e)},l.defined=function(t){return arguments.length?(i="function"==typeof t?t:fi(!!t),l):i},l.curve=function(t){return arguments.length?(s=t,null!=a&&(o=s(a)),l):s},l.context=function(t){return arguments.length?(null==t?a=o=null:o=s(a=t),l):a},l}function Ni(t){return t<0?-1:1}function Ei(t,e,n){var r=t._x1-t._x0,i=e-t._x1,a=(t._y1-t._y0)/(r||i<0&&-0),s=(n-t._y1)/(i||r<0&&-0),o=(a*i+s*r)/(r+i);return(Ni(a)+Ni(s))*Math.min(Math.abs(a),Math.abs(s),.5*Math.abs(o))||0}function ki(t,e){var n=t._x1-t._x0;return n?(3*(t._y1-t._y0)/n-e)/2:e}function Ui(t,e,n){var r=t._x0,i=t._y0,a=t._x1,s=t._y1,o=(a-r)/3;t._context.bezierCurveTo(r+o,i+o*e,a-o,s-o*n,a,s)}function Di(t){this._context=t}function Pi(t){return new Di(t)}function Oi(t,e){this._context=t,this._t=e}function Fi(t){return new Oi(t,1)}wi.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._point=0},lineEnd:function(){(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:this._context.lineTo(t,e)}}},Di.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x0=this._x1=this._y0=this._y1=this._t0=NaN,this._point=0},lineEnd:function(){switch(this._point){case 2:this._context.lineTo(this._x1,this._y1);break;case 3:Ui(this,this._t0,ki(this,this._t0))}(this._line||0!==this._line&&1===this._point)&&this._context.closePath(),this._line=1-this._line},point:function(t,e){var n=NaN;if(e=+e,(t=+t)!==this._x1||e!==this._y1){switch(this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;break;case 2:this._point=3,Ui(this,ki(this,n=Ei(this,t,e)),n);break;default:Ui(this,this._t0,n=Ei(this,t,e))}this._x0=this._x1,this._x1=t,this._y0=this._y1,this._y1=e,this._t0=n}}},Object.create(Di.prototype).point=function(t,e){Di.prototype.point.call(this,e,t)},Oi.prototype={areaStart:function(){this._line=0},areaEnd:function(){this._line=NaN},lineStart:function(){this._x=this._y=NaN,this._point=0},lineEnd:function(){0=0&&(this._t=1-this._t,this._line=1-this._line)},point:function(t,e){switch(t=+t,e=+e,this._point){case 0:this._point=1,this._line?this._context.lineTo(t,e):this._context.moveTo(t,e);break;case 1:this._point=2;default:if(this._t<=0)this._context.lineTo(this._x,e),this._context.lineTo(t,e);else{var n=this._x*(1-this._t)+t*this._t;this._context.lineTo(n,this._y),this._context.lineTo(n,e)}}this._x=t,this._y=e}};const Hi=o`:host{display:block}:host ::slotted(.card-content),.card-content{display:flex;flex-direction:column;gap:12px;padding:16px}.place-row{padding-bottom:16px;border-bottom:1px solid var(--divider-color, #eee)}.place-row:last-child{border-bottom:none;margin-bottom:0;padding-bottom:0}.place-row .chart-container{margin-top:16px;width:100%;height:120px;background:rgba(var(--rgb-primary-color, 0, 119, 190), 0.03);border-radius:8px;overflow:hidden}.place-row svg{width:100%;height:100%;display:block}.place-row .ref-line{stroke-dasharray:4,4;stroke-width:1;opacity:.5}.place-row .ref-line.min{stroke:#41bdf5}.place-row .ref-line.max{stroke:#ff9800}.place-row .ref-line.avg{stroke:var(--primary-color, #0077be);stroke-dasharray:none;opacity:.3}.place-row .chart-line{stroke-linecap:round;stroke-linejoin:round;filter:drop-shadow(0 2px 4px rgba(var(--rgb-primary-color, 0, 119, 190), 0.2))}.place-header{display:flex;justify-content:space-between;align-items:center;margin-bottom:12px;cursor:pointer;transition:opacity .2s ease;border-radius:6px}.place-header:hover{opacity:.7}.place-header:focus-visible{outline:2px solid var(--primary-color, #0077be);outline-offset:2px}.place-info{display:flex;flex-direction:column}.last-updated{font-size:.75rem;color:var(--secondary-text-color);margin-top:4px}.place-name-container{display:flex;align-items:baseline;gap:6px}.place-name{font-size:1.2rem;font-weight:500;color:var(--primary-text-color)}.place-country{font-size:.85rem;color:var(--secondary-text-color);font-weight:400}.current-temp{display:flex;align-items:baseline;gap:4px}.temp-value{font-size:2rem;font-weight:700;color:var(--primary-color, #0077be)}.temp-value.unavailable{color:var(--disabled-text-color, var(--secondary-text-color))}.temp-unit{font-size:1rem;font-weight:500;color:var(--secondary-text-color)}.stats-grid,.averages-grid{display:grid;grid-template-columns:repeat(3, 1fr);gap:8px;margin-top:8px}.stat-item{display:flex;flex-direction:column;align-items:center;background:var(--card-background-color);padding:8px;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,.05)}.stat-label{font-size:.75rem;text-transform:uppercase;color:var(--secondary-text-color);margin-bottom:4px}.stat-value{font-size:.9rem;font-weight:600}.stat-delta{font-size:.75rem;font-weight:500;margin-top:2px}.stat-delta.pos{color:var(--success-color, #4caf50)}.stat-delta.neg{color:var(--error-color, #db4437)}.stat-delta.neu{color:var(--secondary-text-color)}.averages-section{margin-top:16px;padding-top:12px;border-top:1px dashed var(--divider-color)}.averages-header{font-size:.85rem;font-weight:600;color:var(--secondary-text-color);margin-bottom:8px;text-align:center}.current-trend{font-size:1rem;margin-left:8px;margin-top:0}.warning{color:var(--error-color);padding:8px;text-align:center}.ref-label{font-size:8px;font-weight:500;fill:var(--secondary-text-color);dominant-baseline:middle}.ref-label.min{fill:#41bdf5}.ref-label.max{fill:#ff9800}.ref-label.avg{fill:var(--primary-color, #0077be)}.axis-label{font-size:8px;fill:var(--secondary-text-color);opacity:.7}.now-dot{filter:drop-shadow(0 1px 2px rgba(var(--rgb-primary-color, 0, 119, 190), 0.3))}.extrema-dot{filter:drop-shadow(0 1px 2px rgba(0, 0, 0, 0.2))}.extrema-dot.min{fill:#41bdf5}.extrema-dot.max{fill:#ff9800}.hover-group{pointer-events:none;transition:opacity .2s ease-in-out}.hover-line{stroke:var(--secondary-text-color);stroke-width:1;stroke-dasharray:2,2;opacity:.5}.hover-point{fill:var(--card-background-color);stroke:var(--primary-color, #0077be);stroke-width:2}.hover-tooltip-bg{fill:var(--card-background-color);stroke:var(--divider-color, #eee);stroke-width:1;opacity:.95;filter:drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2))}.hover-tooltip-text{fill:var(--primary-text-color);font-size:10px;font-weight:bold}.hover-tooltip-date{fill:var(--secondary-text-color);font-size:8px}.hover-overlay{cursor:crosshair;touch-action:pan-y}ha-card.narrow .card-content{padding:12px;gap:8px}ha-card.narrow .place-row{padding-bottom:12px}ha-card.narrow .place-row .chart-container{margin-top:12px}ha-card.narrow .place-name{font-size:1.05rem}ha-card.narrow .temp-value{font-size:1.6rem}ha-card.narrow .stats-grid{gap:6px;margin-top:6px}ha-card.narrow .stat-item{padding:6px 4px;border-radius:6px}ha-card.narrow .stat-label{font-size:.65rem;margin-bottom:2px}ha-card.narrow .stat-value{font-size:.8rem}ha-card.narrow .ref-label{font-size:7px}ha-card.narrow .axis-label{font-size:7px}`,Li="sea-temperatures-card",zi=`${Li}-editor`;class ji extends ht{constructor(){super(...arguments),this._chartData={},this._chartWidth=400,this._chartSources={}}setConfig(t){if(!t||!t.places||!Array.isArray(t.places)||0===t.places.length)throw new Error("You need to define at least one place.");this._config={show_last_updated:!0,show_trend:!0,show_stats:!0,show_chart:!0,show_country:!1,chart_smoothing:"smooth",...t}}connectedCallback(){super.connectedCallback(),this._resizeObserver=new ResizeObserver(t=>{for(const e of t)if(e.contentRect.width>0){const t=Math.max(200,e.contentRect.width-32);this._chartWidth!==t&&(this._chartWidth=t)}}),this._resizeObserver.observe(this)}disconnectedCallback(){super.disconnectedCallback(),this._resizeObserver?.disconnect()}static async getConfigElement(){return await Promise.resolve().then(function(){return Zi}),document.createElement(zi)}static getStubConfig(){return{title:"Sea Temperatures",places:[]}}getCardSize(){return(this._config?.places?.length||1)*this._rowsPerPlace()}_rowsPerPlace(){let t=1;return!1!==this._config?.show_stats&&(t+=1),!1!==this._config?.show_chart&&(t+=3),t}getGridOptions(){return{rows:(this._config?.places?.length||1)*this._rowsPerPlace(),columns:12,min_rows:2,min_columns:6}}_getPlacesData(t,e){const n=this._placesMemo;if(n&&n.states===t.states&&n.entities===t.entities&&n.devices===t.devices&&n.config===e)return n.places;const r=this._computePlacesData(t,e);return this._placesMemo={states:t.states,entities:t.entities,devices:t.devices,config:e,places:r},r}_computePlacesData(t,e){const n=[],r=Object.values(t.states);return e.places.forEach(i=>{const a="string"==typeof i?i:i.device,s="object"==typeof i?i.name:void 0;let o,c=t.states[a];if(c)o=t.entities[a]?.device_id;else{o=a;const e=r.filter(e=>t.entities[e.entity_id]?.device_id===o&&e.entity_id.startsWith("sensor."));if(0===e.length)return;c=e.find(t=>void 0!==t.attributes.yesterday)||e.find(t=>"°C"===t.attributes.unit_of_measurement||"°F"===t.attributes.unit_of_measurement)||e[0]}if(c){const r=c.attributes,i="unavailable"===c.state||"unknown"===c.state,a=o?t.devices[o]:void 0,l=a?.name_by_user||a?.name||r.friendly_name||"Unknown",h="°F"===r.unit_of_measurement||"F"===r.unit_of_measurement,u=t=>{if(null==t||isNaN(parseFloat(String(t))))return;const e=parseFloat(String(t));return String(h?Math.round(100*(1.8*e+32))/100:e)};n.push({name:s||l,country:e.show_country&&r.country?String(r.country):void 0,temperature:c.state,yesterday:u(r.yesterday),last_week:u(r.last_week),date:r.date?String(r.date):void 0,average_min:u(r.average_min),average_max:u(r.average_max),average_avg:u(r.average_avg),unit:r.unit_of_measurement||"°C",entity_id:c.entity_id,unavailable:i})}}),e.sort_by&&n.sort((t,n)=>{if("name"===e.sort_by)return t.name.localeCompare(n.name);if("temp_asc"===e.sort_by||"temp_desc"===e.sort_by){const r=parseFloat(t.temperature),i=parseFloat(n.temperature),a=isNaN(r)?null:r,s=isNaN(i)?null:i;return null===a||null===s?a===s?0:null===a?1:-1:"temp_asc"===e.sort_by?a-s:s-a}return 0}),n}willUpdate(){this.hass&&this._config&&this._chartSourcesChanged()&&this._fetchChartData()}_chartSourcesChanged(){if(!this._config?.places)return!1;const t=this._getPlacesData(this.hass,this._config);return 0!==t.length&&(!!t.some(t=>this._chartSources[t.entity_id]!==this.hass.states[t.entity_id]?.attributes?.charts)||Object.keys(this._chartSources).some(e=>!t.some(t=>t.entity_id===e)))}shouldUpdate(t){if(t.has("_config"))return!0;const e=t.get("hass");if(e){const n=this._getPlacesData(this.hass,this._config).some(t=>e.states[t.entity_id]!==this.hass.states[t.entity_id]);return n||e.language!==this.hass.language||t.has("_chartData")||t.has("_chartWidth")||this._chartSourcesChanged()}return!0}_parseChartLabel(t,e){const n=String(t).split("-");if(3===n.length){const[t,e,r]=n.map(t=>parseInt(t,10));if(isNaN(t)||isNaN(e)||isNaN(r))return;return new Date(t,e-1,r)}if(2===n.length){const t=parseInt(n[0],10),r=parseInt(n[1],10);if(isNaN(t)||isNaN(r))return;const i=new Date(e.getFullYear(),t-1,r);return i.getTime()>e.getTime()&&i.setFullYear(i.getFullYear()-1),i}}_fetchChartData(){if(!this.hass||!this._config.places)return;const t=this._getPlacesData(this.hass,this._config),e={},n={},r=new Date;t.forEach(({entity_id:t})=>{const i=this.hass?.states[t],a=i?.attributes?.charts;n[t]=i?.attributes?.charts;const s=a?.last_thirty?.labels,o=a?.last_thirty?.series;if(!Array.isArray(s)||!Array.isArray(o)||s.length!==o.length)return;const c="°F"===i?.attributes?.unit_of_measurement||"F"===i?.attributes?.unit_of_measurement,l=s.map((t,e)=>{const n=this._parseChartLabel(t,r);if(!n)return;let i=parseFloat(String(o[e]));return isNaN(i)?void 0:(c&&(i=Math.round(100*(1.8*i+32))/100),{date:n,value:i})}).filter(t=>void 0!==t).sort((t,e)=>t.date.getTime()-e.date.getTime());l.length>0&&(e[t]=l)}),this._chartSources=n,this._chartData=e}_handleHeaderKeydown(t,e){"Enter"!==t.key&&" "!==t.key||(t.preventDefault(),this._handleMoreInfo(e))}_placeAriaLabel(t){const e=[t.name];return t.country&&e.push(t.country),e.push(t.unavailable?t.temperature:`${t.temperature}${t.unit??""}`),e.join(", ")}_chartAriaLabel(t,e){const n=e.map(t=>t.value),r=t.unit??"",i=t=>`${new Intl.NumberFormat(this.hass?.language).format(t)}${r}`;return[t.name,yt(this.hass,"card.chart_description"),`${yt(this.hass,"card.min")} ${i(Math.min(...n))}`,`${yt(this.hass,"card.max")} ${i(Math.max(...n))}`].join(", ")}_handleMoreInfo(t){vt(this,"hass-more-info",{entityId:t})}_renderTrend(t,e,n=""){if(!this._config.show_trend)return W``;const r=t;if(void 0===r||isNaN(parseFloat(e))||isNaN(parseFloat(r)))return W``;const i=parseFloat(e)-parseFloat(r),a=Math.round(10*i)/10;if(Math.abs(a)>0){const t=a>0,e=new Intl.NumberFormat(this.hass?.language,{minimumFractionDigits:1,maximumFractionDigits:1}).format(Math.abs(a));return W`
${t?"↑":"↓"} ${t?"+":"-"}${e}${n}
`}return W`
→ 0.0${n}
`}render(){if(!this._config||!this.hass)return W``;const t=this._getPlacesData(this.hass,this._config),e=this._chartWidth<360;return W`
${t.map(t=>W`
this._handleMoreInfo(t.entity_id)} @keydown=${e=>this._handleHeaderKeydown(e,t.entity_id)} >
${t.name} ${t.country?W`${t.country}`:""}
${this._config.show_last_updated?W`
${this.hass.states[t.entity_id]?new Date(this.hass.states[t.entity_id].last_updated).toLocaleString(this.hass.language||void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}
`:""}
${t.unavailable?W``:W`${isNaN(Number(t.temperature))?t.temperature:new Intl.NumberFormat(this.hass?.language).format(Number(t.temperature))} ${t.unit} ${this._renderTrend(t.yesterday,t.temperature,t.unit)}`}
${!1!==this._config.show_stats?W`
${this._renderStat(yt(this.hass,"card.yesterday"),t.yesterday,t.unit)} ${this._renderStat(yt(this.hass,"card.last_week"),t.last_week,t.unit)} ${this._renderStat(yt(this.hass,"card.average_avg"),t.average_avg,t.unit)}
`:""} ${!1!==this._config.show_chart?this._renderChart(t):""}
`)}
`}_renderStat(t,e,n){if(!e||"unknown"===e||"unavailable"===e)return W``;const r=Number(e),i=isNaN(r)?e:new Intl.NumberFormat(this.hass?.language).format(r);return W`
${t} ${i}${n}
`}_renderChart(t){const e=this._chartData[t.entity_id];return!e||e.length<2?W``:W`
${this._drawChart(t.entity_id,e,t)}
`}_handlePointerMove(t,e,n,r,i,a){if("mouse"!==t.pointerType&&"pointermove"===t.type&&0===t.buttons)return;const s=t.currentTarget.ownerSVGElement;if(!s)return;const o=s.createSVGPoint();o.x=t.clientX,o.y=t.clientY;const c=s.getScreenCTM();if(!c)return;const l=o.matrixTransform(c.inverse()),h=r.invert(l.x),u=$t(t=>t.date).left,d=u(n,h,1),p=n[d-1],f=n[d];let g=p;if(p&&f?g=h.getTime()-p.date.getTime()>f.date.getTime()-h.getTime()?f:p:f&&(g=f),!g)return;const m=s.querySelector(".hover-group");if(!m)return;m.style.opacity="1";const _=r(g.date),y=i(g.value),v=m.querySelector(".hover-line");v.setAttribute("x1",String(_)),v.setAttribute("x2",String(_));const b=m.querySelector(".hover-point");b.setAttribute("cx",String(_)),b.setAttribute("cy",String(y));const x=m.querySelector(".hover-tooltip-bg"),$=m.querySelector(".hover-tooltip-text"),w=m.querySelector(".hover-tooltip-date"),M=this._chartWidth,A=Math.max(0,Math.min(_-35,M-70)),S=A+35,T="middle",C=Math.max(0,y-34),N=C+11,E=C+23;x.setAttribute("x",String(A)),x.setAttribute("y",String(C)),$.setAttribute("x",String(S)),$.setAttribute("y",String(N)),$.setAttribute("text-anchor",T);const k=new Intl.NumberFormat(this.hass?.language).format(g.value);$.textContent=`${k}${a}`,w.setAttribute("x",String(S)),w.setAttribute("y",String(E)),w.setAttribute("text-anchor",T),w.textContent=g.date.toLocaleDateString(this.hass?.language||void 0,{month:"short",day:"numeric"})}_handlePointerLeave(t){const e=t.currentTarget.ownerSVGElement;if(!e)return;const n=e.querySelector(".hover-group");n&&(n.style.opacity="0")}_drawChart(t,e,n){const r=this._chartWidth,i=120,a=r<360,s=15,o=a?48:65,c=25,l=10,h=pi().domain(At(e,t=>t.date)).range([l,r-o]),u=[...e.map(t=>t.value)];n.average_min&&u.push(parseFloat(n.average_min)),n.average_max&&u.push(parseFloat(n.average_max));const d=At(u),p=.1*(d[1]-d[0])||1,f=Ke().domain([d[0]-p,d[1]+p]).range([i-c,s]);let g=Pi;"linear"===this._config.chart_smoothing&&(g=Mi),"step"===this._config.chart_smoothing&&(g=Fi);const m=Ti().x(t=>h(t.date)).y(t=>f(t.value)).curve(g),_=Ci().x(t=>h(t.date)).y0(i-c).y1(t=>f(t.value)).curve(g),y=(t,e,i)=>{if(!t)return null;const s=parseFloat(t);if(isNaN(s))return null;const c=f(s),h=n.unit||"°C",u=i?a?`${s.toFixed(1)}${h}`:`${i} ${s.toFixed(1)}${h}`:"";return Z` ${u?Z`${u}`:""} `},v=t=>t.toLocaleDateString(this.hass?.language||void 0,{month:"short",day:"numeric"}),b=h.domain()[0],x=h.domain()[1],$=e[e.length-1],w=$?Z` `:"",M=e.reduce((t,e)=>e.valuee.value>t.value?e:t,e[0]),S=n.unit||"°C",T=Z` `;return Z` ${v(b)} ${v(x)} ${y(n.average_min,"min",yt(this.hass,"card.min"))} ${y(n.average_max,"max",yt(this.hass,"card.max"))} ${y(n.average_avg,"avg",yt(this.hass,"card.avg"))} ${M?Z``:""} ${A?Z``:""} ${w} ${T} `}static get styles(){return[s(Hi)]}}t([ft({attribute:!1})],ji.prototype,"hass",void 0),t([ /** * @license * Copyright 2017 Google LLC * SPDX-License-Identifier: BSD-3-Clause */ function(t){return(e,n,r)=>((t,e,n)=>(n.configurable=!0,n.enumerable=!0,Reflect.decorate&&"object"!=typeof e&&Object.defineProperty(t,e,n),n))(e,n,{get(){return(e=>e.renderRoot?.querySelector(t)??null)(this)}})}("ha-card")],ji.prototype,"_card",void 0),t([gt()],ji.prototype,"_config",void 0),t([gt()],ji.prototype,"_chartData",void 0),t([gt()],ji.prototype,"_chartWidth",void 0),customElements.get(Li)||customElements.define(Li,ji),window.customCards=window.customCards||[],window.customCards.push({type:Li,name:"Sea Temperatures Card",description:"Display current and historical sea temperatures.",preview:!0,documentationURL:"https://github.com/timmaurice/sea-temperatures",getEntitySuggestion:(t,e)=>e.startsWith("sensor.seatemperatures_")&&t.states[e]?{config:{type:`custom:${Li}`,places:[e]}}:null});const Ri=o`.card-config{display:flex;flex-direction:column;gap:12px}.group{border:1px solid var(--divider-color);border-radius:var(--ha-card-border-radius, 12px);margin-top:0;padding:16px}.group-header{color:var(--primary-text-color);font-size:16px;font-weight:500;margin-bottom:12px}ha-form{display:block}.places-list{border:1px solid var(--divider-color);border-radius:var(--ha-card-border-radius, 12px);padding:16px;margin-bottom:12px}.places-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.places-header h3{margin:0;font-size:16px;font-weight:500;color:var(--primary-text-color)}.places{display:flex;flex-direction:column;gap:8px}.place-item{display:flex;align-items:center;gap:8px}.place-item ha-selector{flex:1}.handle{cursor:grab;color:var(--secondary-text-color);display:flex;align-items:center;justify-content:center}.handle:active{cursor:grabbing}.add-place-container{display:flex;justify-content:flex-end;margin-top:8px}`;var Yi;const qi=[{name:"title",selector:{text:{}}}],Ii=[{name:"sort_by",selector:{select:{options:[{value:"default",label:"Default"},{value:"name",label:"Name"},{value:"temp_asc",label:"Temperature Asc"},{value:"temp_desc",label:"Temperature Desc"}]}}},{type:"expandable",title:"groups.display",schema:[{name:"show_last_updated",selector:{boolean:{}}},{name:"show_trend",selector:{boolean:{}}},{name:"show_stats",selector:{boolean:{}}},{name:"show_chart",selector:{boolean:{}}},{name:"show_country",selector:{boolean:{}}},{name:"chart_smoothing",selector:{select:{options:["smooth","linear","step"]}}}]}];let Wi=class extends ht{static{Yi=this}setConfig(t){this._config={sort_by:"default",show_trend:!0,show_last_updated:!0,show_stats:!0,show_chart:!0,show_country:!1,chart_smoothing:"smooth",...t}}_valueChanged(t){this.hass&&this._config&&vt(this,"config-changed",{config:{...this._config,...t.detail.value}})}_placeMoved(t){t.stopPropagation();const{oldIndex:e,newIndex:n}=t.detail;if(e===n)return;const r=[...this._config.places||[]],i=r.splice(e,1)[0];r.splice(n,0,i),this._config={...this._config,places:r},vt(this,"config-changed",{config:this._config})}static _targetOf(t){return t?"string"==typeof t?t:t.device||"":""}static _nameOf(t){return t&&"string"!=typeof t&&t.name||""}static _isEntityTarget(t){return t.includes(".")}static _buildPlace(t,e){return e?{device:t,name:e}:t}_commitPlace(t,e){const n=[...this._config.places||[]];n[t]=e,this._config={...this._config,places:n},vt(this,"config-changed",{config:this._config})}_placeChanged(t,e){const n=Yi._targetOf(e);if(!n)return void this._removePlace(t);const r=[...this._config.places||[]],i=r.some((e,r)=>r!==t&&e&&Yi._targetOf(e)===n);if(i)return vt(this,"hass-notification",{message:yt(this.hass,"common.errors.duplicate_place")}),void this.requestUpdate();const a=Yi._nameOf(r[t]);this._commitPlace(t,Yi._buildPlace(n,a))}_removePlace(t){const e=[...this._config.places||[]];e.splice(t,1),this._config={...this._config,places:e},vt(this,"config-changed",{config:this._config})}_addPlace(){const t=[...this._config.places||[],""];this._config={...this._config,places:t},vt(this,"config-changed",{config:this._config})}render(){if(!this.hass||!this._config)return W``;const t=t=>t.map(t=>{const e={...t};return"sort_by"===e.name&&(e.selector={select:{options:[{value:"default",label:yt(this.hass,"editor.sort_by_options.default")},{value:"name",label:yt(this.hass,"editor.sort_by_options.name")},{value:"temp_asc",label:yt(this.hass,"editor.sort_by_options.temp_asc")},{value:"temp_desc",label:yt(this.hass,"editor.sort_by_options.temp_desc")}]}}),"chart_smoothing"===e.name&&(e.selector={select:{options:[{value:"smooth",label:yt(this.hass,"editor.chart_smoothing_options.smooth")},{value:"linear",label:yt(this.hass,"editor.chart_smoothing_options.linear")},{value:"step",label:yt(this.hass,"editor.chart_smoothing_options.step")}]}}),"expandable"===e.type&&Array.isArray(e.schema)&&(e.title=yt(this.hass,`editor.${e.title}`),e.schema=e.schema.map(t=>({...t}))),e}),e=t(qi),n=t(Ii);return W`
yt(this.hass,`editor.${t.name}`)} @value-changed=${this._valueChanged} >

${yt(this.hass,"editor.places")}

${this._config.places?.map((t,e)=>{const n=Yi._targetOf(t),r=Yi._isEntityTarget(n)?{entity:{integration:"seatemperatures"}}:{device:{integration:"seatemperatures"}};return W`
this._placeChanged(e,t.detail.value)} >
`})}
${yt(this.hass,"editor.add_place")}
yt(this.hass,`editor.${t.name}`)} @value-changed=${this._valueChanged} >
`}static{this.styles=o` ${s(Ri)} `}};t([ft({attribute:!1})],Wi.prototype,"hass",void 0),t([gt()],Wi.prototype,"_config",void 0),Wi=Yi=t([(t=>(e,n)=>{void 0!==n?n.addInitializer(()=>{customElements.define(t,e)}):customElements.define(t,e)})("sea-temperatures-card-editor")],Wi);var Zi=Object.freeze({__proto__:null,get SeaTemperaturesCardEditor(){return Wi}});export{ji as SeaTemperaturesCard};