extra-map-card 1.2.5 β 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -24,9 +24,9 @@ export declare class EmcMap extends LitElement {
|
|
|
24
24
|
private _clusterIndex?;
|
|
25
25
|
private _clusters;
|
|
26
26
|
private _clustersZoom;
|
|
27
|
-
private _circleLoaded;
|
|
28
27
|
private _mapClusterItems;
|
|
29
28
|
private _mapClusterFocusItems;
|
|
29
|
+
private _circleLoaded;
|
|
30
30
|
private _loaded;
|
|
31
31
|
private _error?;
|
|
32
32
|
private _clustersLoaded;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function e(e,t,i,r){var n,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,r);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(o<3?n(a):o>3?n(t,i,a):n(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a}console.groupCollapsed("%cπ EXTRA-MAP-CARD πΊοΈ%cv1.2.
|
|
1
|
+
function e(e,t,i,r){var n,o=arguments.length,a=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,i,r);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(a=(o<3?n(a):o>3?n(t,i,a):n(t,i))||a);return o>3&&a&&Object.defineProperty(t,i,a),a}console.groupCollapsed("%cπ EXTRA-MAP-CARD πΊοΈ%cv1.2.6","background-color: #434347;color: #fff;padding: 2px 4px;border: 1px solid #434347;border-radius: 2px 0 0 2px;font-family: Roboto,Verdana,Geneva,sans-serif;text-shadow: 0 1px 0 rgba(1, 1, 1, 0.3)","background-color: transparent;color: #434347;padding: 2px 3px;border: 1px solid #434347; border-radius: 0 2px 2px 0;font-family: Roboto,Verdana,Geneva,sans-serif"),console.info("Lovelace custom map card for Home Assistant"),console.info("Github: git+https://github.com/ngocjohn/extra-map-card.git"),console.info("If you like the card, consider supporting the developer: https://github.com/sponsors/ngocjohn"),console.groupEnd(),"function"==typeof SuppressedError&&SuppressedError;const t=(e,t)=>e&&e.config.components.includes(t);function i(){let e=document.querySelector("home-assistant");if(e=e&&e.shadowRoot,e=e&&e.querySelector("home-assistant-main"),e=e&&e.shadowRoot,e=e&&e.querySelector("app-drawer-layout partial-panel-resolver, ha-drawer partial-panel-resolver"),e=e&&e.shadowRoot||e,e=e&&e.querySelector("ha-panel-lovelace"),e=e&&e.shadowRoot,e=e&&e.querySelector("hui-root"),e){const t=e.lovelace;return t.current_view=e.___curView,t}return null}const r=e=>{let t=e;for(;t;){if("HUI-CARD-OPTIONS"===t.tagName)return t;t=t.parentNode}return t};function n(e){const t=i();return t?(t.setEditMode(!0),new Promise((i=>{setTimeout((()=>{const n=r(e.parentNode);if(!n)return t.setEditMode(!1),void i(null);const o=n.__path,a=`${n.lovelace.urlPath}-${o.join("-")}`;t.setEditMode(!1),i(a)}),100)}))):Promise.reject("Lovelace not found")}const o=e=>2===e.length?{viewIndex:e[0],cardIndex:e[1]}:{viewIndex:e[0],sectionIndex:e[1],cardIndex:e[2]},a=e=>1===e.length?{viewIndex:e[0]}:{viewIndex:e[0],sectionIndex:e[1]},s=e=>e.slice(0,-1),l=(e,t)=>{var i;const{viewIndex:r,sectionIndex:n}=a(t),o=e.views[r];if(!o)throw new Error("View does not exist");if(void 0===n)return o;if(g(o))throw new Error("Can not find section in a strategy view");const s=null===(i=o.sections)||void 0===i?void 0:i[n];if(!s)throw new Error("Section does not exist");return s},c=(e,t)=>{var i;const{viewIndex:r,sectionIndex:n}=a(t),o=e.views[r];if(!o)throw new Error("View does not exist");if(g(o))throw new Error("Can not find cards in a strategy view");if(void 0===n)return o.cards;const s=null===(i=o.sections)||void 0===i?void 0:i[n];if(!s)throw new Error("Section does not exist");if(y(s))throw new Error("Can not find cards in a strategy section");return s.cards},u=(e,t,i)=>{const{viewIndex:r,sectionIndex:n}=a(t);let o=!1;const s=e.views.map(((e,t)=>{if(t!==r)return e;if(void 0===n)return o=!0,i;if(g(e))throw new Error("Can not update section in a strategy view");if(void 0===e.sections)throw new Error("Section does not exist");const a=e.sections.map(((e,t)=>t!==n?e:(o=!0,i)));return Object.assign(Object.assign({},e),{sections:a})}));if(!o)throw new Error("Can not update cards in a non-existing view/section");return Object.assign(Object.assign({},e),{views:s})},h=(e,t,i)=>{const{viewIndex:r,sectionIndex:n}=a(t);let o=!1;const s=e.views.map(((e,t)=>{if(t!==r)return e;if(g(e))throw new Error("Can not update cards in a strategy view");if(void 0===n)return o=!0,Object.assign(Object.assign({},e),{cards:i});if(void 0===e.sections)throw new Error("Section does not exist");const a=e.sections.map(((e,t)=>{if(t!==n)return e;if(y(e))throw new Error("Can not update cards in a strategy section");return o=!0,Object.assign(Object.assign({},e),{cards:i})}));return Object.assign(Object.assign({},e),{sections:a})}));if(!o)throw new Error("Can not update cards in a non-existing view/section");return Object.assign(Object.assign({},e),{views:s})};function p(e){return"strategy"in e}const d=(e,t,i)=>e.sendMessagePromise({type:"lovelace/config",url_path:t,force:i}),m=(e,t,i)=>e.callWS({type:"lovelace/config/save",url_path:t,config:i}),f=(e,t)=>e.callWS({type:"lovelace/config/delete",url_path:t});function g(e){return"strategy"in e}function y(e){return"strategy"in e}const _=e=>"string"==typeof e?{type:"entity",entity:e,show_name:!0}:"type"in e&&e.type?e:Object.assign({type:"entity"},e),v=e=>e.sendMessagePromise({type:"lovelace/resources"}),x=(e,t)=>e.callWS(Object.assign({type:"lovelace/resources/create"},t)),b=(e,t,i)=>e.callWS(Object.assign({type:"lovelace/resources/update",resource_id:t},i)),w=(e,t)=>e.callWS({type:"lovelace/resources/delete",resource_id:t}),C=(e,t,i,r)=>{r=r||{},i=null==i?{}:i;const n=new Event(t,{bubbles:void 0===r.bubbles||r.bubbles,cancelable:Boolean(r.cancelable),composed:void 0===r.composed||r.composed});return n.detail=i,e.dispatchEvent(n),n},T=(e,t,i)=>e.subscribeMessage((e=>t(e)),Object.assign({type:"render_template"},i));var S,A;!function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(S||(S={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(A||(A={}));var M=function(e){if(e.time_format===A.language||e.time_format===A.system){var t=e.time_format===A.language?e.language:void 0,i=(new Date).toLocaleString(t);return i.includes("AM")||i.includes("PM")}return e.time_format===A.am_pm},E=function(e,t){return P(t).format(e)},P=function(e){return new Intl.DateTimeFormat(e.language,{year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"2-digit",hour12:M(e)})},I=function(e,t){return k(t).format(e)},k=function(e){return new Intl.DateTimeFormat(e.language,{hour:M(e)?"numeric":"2-digit",minute:"2-digit",second:"2-digit",hour12:M(e)})};function z(e){return e.substr(0,e.indexOf("."))}function L(e){return z(e.entity_id)}const D=["climate","humidifier","input_datetime","thermostat","water_heater","person","device_tracker"];class F{constructor(e,t){this.hass=e,this.hoursToShow=t,this.combinedHistory={}}processMessage(e){if(!this.combinedHistory||!Object.keys(this.combinedHistory).length)return this.combinedHistory=e.states,this.combinedHistory;if(!Object.keys(e.states).length)return this.combinedHistory;const t=this.hoursToShow?((new Date).getTime()-3600*this.hoursToShow*1e3)/1e3:void 0,i={};for(const e of Object.keys(this.combinedHistory))i[e]=[];for(const t of Object.keys(e.states))i[t]=[];for(const r of Object.keys(i)){if(r in this.combinedHistory&&r in e.states){const t=this.combinedHistory[r],n=t[t.length-1];i[r]=t.concat(e.states[r]),e.states[r][0].lu<n.lu&&(i[r]=i[r].sort(((e,t)=>e.lu-t.lu)))}else r in this.combinedHistory?i[r]=this.combinedHistory[r]:i[r]=e.states[r];if(t&&r in this.combinedHistory){const e=i[r].filter((e=>e.lu<t));if(!e.length)continue;if(i[r]=i[r].filter((e=>e.lu>=t)),i[r].length&&i[r][0].lu===t)continue;const n=e[e.length-1];n.lu=t,i[r].unshift(n)}}return this.combinedHistory=i,this.combinedHistory}}const R=(e,t)=>!e.states[t]||D.includes(z(t)),B=(e,t,i,r)=>{const n={type:"history/history_during_period",start_time:t.toISOString(),end_time:i.toISOString(),minimal_response:!0,no_attributes:!r.some((t=>R(e,t)))};return 0!==r.length?e.callWS(Object.assign(Object.assign({},n),{entity_ids:r})):e.callWS(n)},O=(e,t,i,r,n,o=!0,a=!0)=>{const s={type:"history/stream",entity_ids:r,start_time:new Date((new Date).getTime()-3600*i*1e3).toISOString(),minimal_response:o,significant_changes_only:a,no_attributes:null!=n?n:!r.some((t=>R(e,t)))},l=new F(e,i);return e.connection.subscribeMessage((e=>t(l.processMessage(e))),s)},j=(e,t,i,r,n)=>{const o={type:"history/stream",entity_ids:n,start_time:i.toISOString(),end_time:r.toISOString(),minimal_response:!1,no_attributes:!1,significant_changes_only:!1},a=new F(e);return e.connection.subscribeMessage((e=>t(a.processMessage(e))),o)},N=globalThis,$=N.ShadowRoot&&(void 0===N.ShadyCSS||N.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,V=Symbol(),U=new WeakMap;let q=class{constructor(e,t,i){if(this._$cssResult$=!0,i!==V)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=e,this.t=t}get styleSheet(){let e=this.o;const t=this.t;if($&&void 0===e){const i=void 0!==t&&1===t.length;i&&(e=U.get(t)),void 0===e&&((this.o=e=new CSSStyleSheet).replaceSync(this.cssText),i&&U.set(t,e))}return e}toString(){return this.cssText}};const Z=e=>new q("string"==typeof e?e:e+"",void 0,V),G=(e,...t)=>{const i=1===e.length?e[0]:t.reduce(((t,i,r)=>t+(e=>{if(!0===e._$cssResult$)return e.cssText;if("number"==typeof e)return e;throw Error("Value passed to 'css' function must be a 'css' function result: "+e+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(i)+e[r+1]),e[0]);return new q(i,e,V)},H=(e,t)=>{if($)e.adoptedStyleSheets=t.map((e=>e instanceof CSSStyleSheet?e:e.styleSheet));else for(const i of t){const t=document.createElement("style"),r=N.litNonce;void 0!==r&&t.setAttribute("nonce",r),t.textContent=i.cssText,e.appendChild(t)}},W=$?e=>e:e=>e instanceof CSSStyleSheet?(e=>{let t="";for(const i of e.cssRules)t+=i.cssText;return Z(t)})(e):e
|
|
2
2
|
/**
|
|
3
3
|
* @license
|
|
4
4
|
* Copyright 2017 Google LLC
|
|
@@ -216,7 +216,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
216
216
|
font-weight: 300;
|
|
217
217
|
font-size: 16px;
|
|
218
218
|
max-width: calc(100% - 80px);
|
|
219
|
-
}`,Gh=6371008.8,Hh={centimeters:100*Gh,centimetres:100*Gh,degrees:360/(2*Math.PI),feet:3.28084*Gh,inches:39.37*Gh,kilometers:Gh/1e3,kilometres:Gh/1e3,meters:Gh,metres:Gh,miles:Gh/1609.344,millimeters:1e3*Gh,millimetres:1e3*Gh,nauticalmiles:Gh/1852,radians:1,yards:1.0936*Gh};function Wh(e,t,i={}){const r={type:"Feature"};return(0===i.id||i.id)&&(r.id=i.id),i.bbox&&(r.bbox=i.bbox),r.properties=t||{},r.geometry=e,r}function Kh(e,t,i={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!ep(e[0])||!ep(e[1]))throw new Error("coordinates must contain numbers");return Wh({type:"Point",coordinates:e},t,i)}function Xh(e,t,i={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Wh({type:"Polygon",coordinates:e},t,i)}function Yh(e,t="kilometers"){const i=Hh[t];if(!i)throw new Error(t+" units is invalid");return e/i}function Jh(e){return 180*(e%(2*Math.PI))/Math.PI}function Qh(e){return e%360*Math.PI/180}function ep(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function tp(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ip(e,t,i,r={}){const n=tp(e),o=Qh(n[0]),a=Qh(n[1]),s=Qh(i),l=Yh(t,r.units),c=Math.asin(Math.sin(a)*Math.cos(l)+Math.cos(a)*Math.sin(l)*Math.cos(s));return Kh([Jh(o+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(a),Math.cos(l)-Math.sin(a)*Math.sin(c))),Jh(c)],r.properties)}function rp(e,t,i={}){const r=i.steps||64,n=i.properties?i.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},o=[];for(let n=0;n<r;n++)o.push(ip(e,t,-360*n/r,i).geometry.coordinates);return o.push(o[0]),Xh([o],n)}var np="M17.5,12A1.5,1.5 0 0,1 16,10.5A1.5,1.5 0 0,1 17.5,9A1.5,1.5 0 0,1 19,10.5A1.5,1.5 0 0,1 17.5,12M14.5,8A1.5,1.5 0 0,1 13,6.5A1.5,1.5 0 0,1 14.5,5A1.5,1.5 0 0,1 16,6.5A1.5,1.5 0 0,1 14.5,8M9.5,8A1.5,1.5 0 0,1 8,6.5A1.5,1.5 0 0,1 9.5,5A1.5,1.5 0 0,1 11,6.5A1.5,1.5 0 0,1 9.5,8M6.5,12A1.5,1.5 0 0,1 5,10.5A1.5,1.5 0 0,1 6.5,9A1.5,1.5 0 0,1 8,10.5A1.5,1.5 0 0,1 6.5,12M12,3A9,9 0 0,0 3,12A9,9 0 0,0 12,21A1.5,1.5 0 0,0 13.5,19.5C13.5,19.11 13.35,18.76 13.11,18.5C12.88,18.23 12.73,17.88 12.73,17.5A1.5,1.5 0 0,1 14.23,16H16A5,5 0 0,0 21,11C21,6.58 16.97,3 12,3Z",op="1.2.5";const ap=op,sp=[{name:"Navigation and city exploration",selector:{select:{options:["STREETS","STREETS.DARK","STREETS.LIGHT","STREETS.PASTEL"]}}},{name:"Data visualization",selector:{select:{options:["DATAVIZ","DATAVIZ.DARK","DATAVIZ.LIGHT"]}}},{name:"Minimalist and general purpose",selector:{select:{options:["BASIC","BASIC.DARK","BASIC.LIGHT"]}}},{name:"High contrast navigation",selector:{select:{options:["BRIGHT","BRIGHT.DARK","BRIGHT.LIGHT","BRIGHT.PASTEL"]}}},{name:"Topographic study",selector:{select:{options:["TOPO","TOPO.SHINY","TOPO.PASTEL","TOPO.TOPOGRAPHIQUE"]}}},{name:"Minimalist",selector:{select:{options:["VOYAGER","VOYAGER.DARK","VOYAGER.LIGHT","VOYAGER.VINTAGE"]}}},{name:"High contrast",selector:{select:{options:["TONER","TONER.BACKGROUND","TONER.LITE","TONER.LINES"]}}},{name:"Neutral greyscale style with hillshading",selector:{select:{options:["BACKDROP","BACKDROP.DARK","BACKDROP.LIGHT"]}}},{name:"Other",selector:{select:{options:["OPENSTREETMAP","OUTDOOR","WINTER","SATELLITE","HYBRID"]}}}],lp=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],cp=()=>sp.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),up=cp(),hp=0,pp=13,dp=["auto","light","dark"],mp=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:pp,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:dp.map((e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)})))}}},{name:"hours_to_show",label:"Hours to Show",default:0,selector:{number:{mode:"box",min:0}}},{name:"history_period",label:"History Period",default:"",selector:{select:{mode:"dropdown",options:[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"}]}}},{name:"auto_fit",label:"Auto Fit",default:!1,selector:{boolean:{}}},{name:"fit_zones",label:"Fit Zones",default:!1,selector:{boolean:{}}},{name:"use_more_info",label:"Marker more info",default:!1,selector:{boolean:{}}}],fp={name:"custom_styles",type:"expandable",iconPath:np,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:up}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:up}}}]}]},gp=at((e=>[{name:"",type:"expandable",iconPath:np,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...mp]},fp]}])),yp=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),_p=at((e=>[...yp(),...gp(e)])),vp=Symbol.for("constructDateFrom");function xp(e,t){return"function"==typeof e?e(t):e&&"object"==typeof e&&vp in e?e[vp](t):e instanceof Date?new e.constructor(t):new Date(t)}function bp(e,t){return xp(e,e)}function wp(e,...t){const i=xp.bind(null,t.find((e=>"object"==typeof e)));return t.map(i)}function Cp(e,t){const i=bp(e);return i.setHours(0,0,0,0),i}function Tp(e){return xp(e,Date.now())}function Sp(e,t,i){const[r,n]=wp(i?.in,e,t);return+Cp(r)==+Cp(n)}function Ap(e,t){return Sp(xp(e,e),Tp(e))}const Mp=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],Ep=1,Pp=8;class Ip{static from(e){if(!(e instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[t,i]=new Uint8Array(e,0,2);if(219!==t)throw new Error("Data does not appear to be in a KDBush format.");const r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=Mp[15&i];if(!n)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(e,2,1),[a]=new Uint32Array(e,4,1);return new Ip(a,o,n,e)}constructor(e,t=64,i=Float64Array,r){if(isNaN(e)||e<0)throw new Error(`Unpexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.ArrayType=i,this.IndexArrayType=e<65536?Uint16Array:Uint32Array;const n=Mp.indexOf(this.ArrayType),o=2*e*this.ArrayType.BYTES_PER_ELEMENT,a=e*this.IndexArrayType.BYTES_PER_ELEMENT,s=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=2*e,this._finished=!0):(this.data=new ArrayBuffer(8+o+a+s),this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=t,new Uint32Array(this.data,4,1)[0]=e)}add(e,t){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=e,this.coords[this._pos++]=t,i}finish(){const e=this._pos>>1;if(e!==this.numItems)throw new Error(`Added ${e} items when expected ${this.numItems}.`);return kp(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(e,t,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:a}=this,s=[0,n.length-1,0],l=[];for(;s.length;){const c=s.pop()||0,u=s.pop()||0,h=s.pop()||0;if(u-h<=a){for(let a=h;a<=u;a++){const s=o[2*a],c=o[2*a+1];s>=e&&s<=i&&c>=t&&c<=r&&l.push(n[a])}continue}const p=h+u>>1,d=o[2*p],m=o[2*p+1];d>=e&&d<=i&&m>=t&&m<=r&&l.push(n[p]),(0===c?e<=d:t<=m)&&(s.push(h),s.push(p-1),s.push(1-c)),(0===c?i>=d:r>=m)&&(s.push(p+1),s.push(u),s.push(1-c))}return l}within(e,t,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:o}=this,a=[0,r.length-1,0],s=[],l=i*i;for(;a.length;){const c=a.pop()||0,u=a.pop()||0,h=a.pop()||0;if(u-h<=o){for(let i=h;i<=u;i++)Fp(n[2*i],n[2*i+1],e,t)<=l&&s.push(r[i]);continue}const p=h+u>>1,d=n[2*p],m=n[2*p+1];Fp(d,m,e,t)<=l&&s.push(r[p]),(0===c?e-i<=d:t-i<=m)&&(a.push(h),a.push(p-1),a.push(1-c)),(0===c?e+i>=d:t+i>=m)&&(a.push(p+1),a.push(u),a.push(1-c))}return s}}function kp(e,t,i,r,n,o){if(n-r<=i)return;const a=r+n>>1;zp(e,t,a,r,n,o),kp(e,t,i,r,a-1,1-o),kp(e,t,i,a+1,n,1-o)}function zp(e,t,i,r,n,o){for(;n>r;){if(n-r>600){const a=n-r+1,s=i-r+1,l=Math.log(a),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(a-c)/a)*(s-a/2<0?-1:1);zp(e,t,i,Math.max(r,Math.floor(i-s*c/a+u)),Math.min(n,Math.floor(i+(a-s)*c/a+u)),o)}const a=t[2*i+o];let s=r,l=n;for(Lp(e,t,r,i),t[2*n+o]>a&&Lp(e,t,r,n);s<l;){for(Lp(e,t,s,l),s++,l--;t[2*s+o]<a;)s++;for(;t[2*l+o]>a;)l--}t[2*r+o]===a?Lp(e,t,r,l):(l++,Lp(e,t,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function Lp(e,t,i,r){Dp(e,i,r),Dp(t,2*i,2*r),Dp(t,2*i+1,2*r+1)}function Dp(e,t,i){const r=e[t];e[t]=e[i],e[i]=r}function Fp(e,t,i,r){const n=e-i,o=t-r;return n*n+o*o}const Rp={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e},Bp=Math.fround||(e=>t=>(e[0]=+t,e[0]))(new Float32Array(1)),Op=2,jp=3,Np=4,$p=5,Vp=6;class Up{constructor(e){this.options=Object.assign(Object.create(Rp),e),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[]}load(e){const{log:t,minZoom:i,maxZoom:r}=this.options;t&&console.time("total time");const n=`prepare ${e.length} points`;t&&console.time(n),this.points=e;const o=[];for(let t=0;t<e.length;t++){const i=e[t];if(!i.geometry)continue;const[r,n]=i.geometry.coordinates,a=Bp(Gp(r)),s=Bp(Hp(n));o.push(a,s,1/0,t,-1,1),this.options.reduce&&o.push(0)}let a=this.trees[r+1]=this._createTree(o);t&&console.timeEnd(n);for(let e=r;e>=i;e--){Date.now();a=this.trees[e]=this._createTree(this._cluster(a,e))}return t&&console.timeEnd("total time"),this}getClusters(e,t){let i=((e[0]+180)%360+360)%360-180;const r=Math.max(-90,Math.min(90,e[1]));let n=180===e[2]?180:((e[2]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,e[3]));if(e[2]-e[0]>=360)i=-180,n=180;else if(i>n){const e=this.getClusters([i,r,180,o],t),a=this.getClusters([-180,r,n,o],t);return e.concat(a)}const a=this.trees[this._limitZoom(t)],s=a.range(Gp(i),Hp(o),Gp(n),Hp(r)),l=a.data,c=[];for(const e of s){const t=this.stride*e;c.push(l[t+5]>1?qp(l,t,this.clusterProps):this.points[l[t+3]])}return c}getChildren(e){const t=this._getOriginId(e),i=this._getOriginZoom(e),r="No cluster with the specified id.",n=this.trees[i];if(!n)throw new Error(r);const o=n.data;if(t*this.stride>=o.length)throw new Error(r);const a=this.options.radius/(this.options.extent*Math.pow(2,i-1)),s=o[t*this.stride],l=o[t*this.stride+1],c=n.within(s,l,a),u=[];for(const t of c){const i=t*this.stride;o[i+4]===e&&u.push(o[i+5]>1?qp(o,i,this.clusterProps):this.points[o[i+3]])}if(0===u.length)throw new Error(r);return u}getLeaves(e,t,i){t=t||10,i=i||0;const r=[];return this._appendLeaves(r,e,t,i,0),r}getTile(e,t,i){const r=this.trees[this._limitZoom(e)],n=Math.pow(2,e),{extent:o,radius:a}=this.options,s=a/o,l=(i-s)/n,c=(i+1+s)/n,u={features:[]};return this._addTileFeatures(r.range((t-s)/n,l,(t+1+s)/n,c),r.data,t,i,n,u),0===t&&this._addTileFeatures(r.range(1-s/n,l,1,c),r.data,n,i,n,u),t===n-1&&this._addTileFeatures(r.range(0,l,s/n,c),r.data,-1,i,n,u),u.features.length?u:null}getClusterExpansionZoom(e){let t=this._getOriginZoom(e)-1;for(;t<=this.options.maxZoom;){const i=this.getChildren(e);if(t++,1!==i.length)break;e=i[0].properties.cluster_id}return t}_appendLeaves(e,t,i,r,n){const o=this.getChildren(t);for(const t of o){const o=t.properties;if(o&&o.cluster?n+o.point_count<=r?n+=o.point_count:n=this._appendLeaves(e,o.cluster_id,i,r,n):n<r?n++:e.push(t),e.length===i)break}return n}_createTree(e){const t=new Ip(e.length/this.stride|0,this.options.nodeSize,Float32Array);for(let i=0;i<e.length;i+=this.stride)t.add(e[i],e[i+1]);return t.finish(),t.data=e,t}_addTileFeatures(e,t,i,r,n,o){for(const a of e){const e=a*this.stride,s=t[e+5]>1;let l,c,u;if(s)l=Zp(t,e,this.clusterProps),c=t[e],u=t[e+1];else{const i=this.points[t[e+3]];l=i.properties;const[r,n]=i.geometry.coordinates;c=Gp(r),u=Hp(n)}const h={type:1,geometry:[[Math.round(this.options.extent*(c*n-i)),Math.round(this.options.extent*(u*n-r))]],tags:l};let p;p=s||this.options.generateId?t[e+3]:this.points[t[e+3]].id,void 0!==p&&(h.id=p),o.features.push(h)}}_limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}_cluster(e,t){const{radius:i,extent:r,reduce:n,minPoints:o}=this.options,a=i/(r*Math.pow(2,t)),s=e.data,l=[],c=this.stride;for(let i=0;i<s.length;i+=c){if(s[i+2]<=t)continue;s[i+2]=t;const r=s[i],u=s[i+1],h=e.within(s[i],s[i+1],a),p=s[i+5];let d=p;for(const e of h){const i=e*c;s[i+2]>t&&(d+=s[i+5])}if(d>p&&d>=o){let e,o=r*p,a=u*p,m=-1;const f=(i/c<<5)+(t+1)+this.points.length;for(const r of h){const l=r*c;if(s[l+2]<=t)continue;s[l+2]=t;const u=s[l+5];o+=s[l]*u,a+=s[l+1]*u,s[l+4]=f,n&&(e||(e=this._map(s,i,!0),m=this.clusterProps.length,this.clusterProps.push(e)),n(e,this._map(s,l)))}s[i+4]=f,l.push(o/d,a/d,1/0,f,-1,d),n&&l.push(m)}else{for(let e=0;e<c;e++)l.push(s[i+e]);if(d>1)for(const e of h){const i=e*c;if(!(s[i+2]<=t)){s[i+2]=t;for(let e=0;e<c;e++)l.push(s[i+e])}}}}return l}_getOriginId(e){return e-this.points.length>>5}_getOriginZoom(e){return(e-this.points.length)%32}_map(e,t,i){if(e[t+5]>1){const r=this.clusterProps[e[t+6]];return i?Object.assign({},r):r}const r=this.points[e[t+3]].properties,n=this.options.map(r);return i&&n===r?Object.assign({},n):n}}function qp(e,t,i){return{type:"Feature",id:e[t+3],properties:Zp(e,t,i),geometry:{type:"Point",coordinates:[Wp(e[t]),Kp(e[t+1])]}}}function Zp(e,t,i){const r=e[t+5],n=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?Math.round(r/100)/10+"k":r,o=e[t+6],a=-1===o?{}:Object.assign({},i[o]);return Object.assign(a,{cluster:!0,cluster_id:e[t+3],point_count:r,point_count_abbreviated:n})}function Gp(e){return e/360+.5}function Hp(e){const t=Math.sin(e*Math.PI/180),i=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return i<0?0:i>1?1:i}function Wp(e){return 360*(e-.5)}function Kp(e){const t=(180-360*e)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}const Xp=window.loadCardHelpers?window.loadCardHelpers():void 0,Yp=()=>{var e,t,i,r,n,o;customElements.get("ha-entity-marker")||null===(e=customElements.get("hui-map-card"))||void 0===e||e.getConfigElement(),customElements.get("ha-form")||null===(t=customElements.get("hui-button-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-entity-picker")||null===(i=customElements.get("hui-entities-card"))||void 0===i||i.getConfigElement(),customElements.get("ha-card-conditions-editor")||null===(r=customElements.get("hui-conditional-card"))||void 0===r||r.getConfigElement(),customElements.get("ha-form-multi_select")||null===(n=customElements.get("hui-entities-card"))||void 0===n||n.getConfigElement(),customElements.get("hui-entity-editor")||null===(o=customElements.get("hui-glance-card"))||void 0===o||o.getConfigElement()},Jp=async e=>{if(!customElements.get("ha-entity-marker")){const t={type:"map",entities:e,theme_mode:"auto"};let i;if(window.loadCardHelpers?i=await window.loadCardHelpers():Xp&&(i=Xp),!i||!i.createCardElement)return;if(!await i.createCardElement(t))return}};var Qp,ed,td,id,rd,nd,od,ad;!function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(Qp||(Qp={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(ed||(ed={})),function(e){e.local="local",e.server="server"}(td||(td={})),function(e){e.language="language",e.system="system",e.DMY="DMY",e.MDY="MDY",e.YMD="YMD"}(id||(id={})),function(e){e.language="language",e.monday="monday",e.tuesday="tuesday",e.wednesday="wednesday",e.thursday="thursday",e.friday="friday",e.saturday="saturday",e.sunday="sunday"}(rd||(rd={}));const sd=e=>"string"==typeof e?e:e.entity_id,ld=at((async(e,t,i)=>{const r={address:"streetName",locality:"sublocality",municipality:"city"},n=`https://api.maptiler.com/geocoding/${t},${e}.json?key=${i}`;try{const e=await fetch(n);if(!e.ok)throw new Error("Failed to fetch address from MapTiler");const t=await e.json();if(t&&t.features&&t.features.length>0){let e={};if(t.features.forEach((t=>{const i=t.place_type[0];if(r[i]){const n=r[i],o=t.text;"address"===i&&(e.streetNumber=t.address?`${t.address}`:""),e[n]=`${o}`}})),e.streetName&&e.city)return e}return null}catch(e){return console.warn("Error fetching address from MapTiler:",e),null}})),cd=null===(ad=null===(nd=Intl.DateTimeFormat)||void 0===nd?void 0:(od=nd.call(Intl)).resolvedOptions)||void 0===ad?void 0:ad.call(od).timeZone,ud=null!=cd?cd:"UTC",hd=(e,t)=>e===td.local&&cd?ud:t,pd=at((e=>{if(e.time_format===ed.language||e.time_format===ed.system){const t=e.time_format===ed.language?e.language:void 0;return new Date("January 1, 2023 22:00:00").toLocaleString(t).includes("10")}return e.time_format===ed.am_pm})),dd=(e,t,i)=>md(t,i.time_zone).format(e),md=at(((e,t)=>new Intl.DateTimeFormat(e.language,{weekday:"long",hour:pd(e)?"numeric":"2-digit",minute:"2-digit",hour12:pd(e),timeZone:hd(e.time_zone,t)}))),fd={dark:ei.STREETS.DARK,light:ei.DATAVIZ.LIGHT,demo:"https://demotiles.maplibre.org/style.json"},gd={backgroundColor:{light:"#fff",dark:"#222222"},fill:{light:"#222222",dark:"#c1c1c1"},boxShadow:{light:"0 0 0 2px rgba(0, 0, 0, 0.1)",dark:"0 0 0 2px rgba(255, 255, 255, 0.1)"},borderTop:{light:"1px solid #ddd",dark:"1px solid #424242"},themeBtn:{light:"mdi:weather-sunny",dark:"mdi:weather-night"}};class yd extends Ke{constructor(){super(...arguments),this.autoFit=!1,this.fitZones=!1,this.zoom=pp,this.themeMode="auto",this.useMoreInfo=!1,this._darkStyle=!1,this._mapItems=[],this._zoneItems=[],this._mapFocusZones=[],this._mapFocusItems=[],this._mapPaths=[],this._mapHelper=gh,this._clusters=[],this._clustersZoom=0,this._circleLoaded=!1,this._mapClusterItems=[],this._mapClusterFocusItems=[],this._loaded=!1,this._clustersLoaded=!1,this._createButton=(e,t)=>{const i=document.createElement("div");i.classList.add("maplibregl-ctrl","maplibregl-ctrl-group");const r=document.createElement("button"),n=document.createElement("ha-icon");return n.setAttribute("icon",e),n.style.color="var(--emc-btn-color)",r.appendChild(n),r.title=t,i.appendChild(r),i.style.display="none",i},this.getModeColor=(e,t)=>t?gd[e][t]:this._darkMode?gd[e].dark:gd[e].light}get _darkMode(){return"dark"===this.themeMode||"auto"===this.themeMode&&Boolean(this.hass.themes.darkMode)}async firstUpdated(){await Jp(this.entities),await new Promise((e=>setTimeout(e,0))),this._initMap()}render(){const e=this._renderLoadError();return ke`
|
|
219
|
+
}`,Gh=6371008.8,Hh={centimeters:100*Gh,centimetres:100*Gh,degrees:360/(2*Math.PI),feet:3.28084*Gh,inches:39.37*Gh,kilometers:Gh/1e3,kilometres:Gh/1e3,meters:Gh,metres:Gh,miles:Gh/1609.344,millimeters:1e3*Gh,millimetres:1e3*Gh,nauticalmiles:Gh/1852,radians:1,yards:1.0936*Gh};function Wh(e,t,i={}){const r={type:"Feature"};return(0===i.id||i.id)&&(r.id=i.id),i.bbox&&(r.bbox=i.bbox),r.properties=t||{},r.geometry=e,r}function Kh(e,t,i={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!ep(e[0])||!ep(e[1]))throw new Error("coordinates must contain numbers");return Wh({type:"Point",coordinates:e},t,i)}function Xh(e,t,i={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Wh({type:"Polygon",coordinates:e},t,i)}function Yh(e,t="kilometers"){const i=Hh[t];if(!i)throw new Error(t+" units is invalid");return e/i}function Jh(e){return 180*(e%(2*Math.PI))/Math.PI}function Qh(e){return e%360*Math.PI/180}function ep(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function tp(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ip(e,t,i,r={}){const n=tp(e),o=Qh(n[0]),a=Qh(n[1]),s=Qh(i),l=Yh(t,r.units),c=Math.asin(Math.sin(a)*Math.cos(l)+Math.cos(a)*Math.sin(l)*Math.cos(s));return Kh([Jh(o+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(a),Math.cos(l)-Math.sin(a)*Math.sin(c))),Jh(c)],r.properties)}function rp(e,t,i={}){const r=i.steps||64,n=i.properties?i.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},o=[];for(let n=0;n<r;n++)o.push(ip(e,t,-360*n/r,i).geometry.coordinates);return o.push(o[0]),Xh([o],n)}var np="M17.5,12A1.5,1.5 0 0,1 16,10.5A1.5,1.5 0 0,1 17.5,9A1.5,1.5 0 0,1 19,10.5A1.5,1.5 0 0,1 17.5,12M14.5,8A1.5,1.5 0 0,1 13,6.5A1.5,1.5 0 0,1 14.5,5A1.5,1.5 0 0,1 16,6.5A1.5,1.5 0 0,1 14.5,8M9.5,8A1.5,1.5 0 0,1 8,6.5A1.5,1.5 0 0,1 9.5,5A1.5,1.5 0 0,1 11,6.5A1.5,1.5 0 0,1 9.5,8M6.5,12A1.5,1.5 0 0,1 5,10.5A1.5,1.5 0 0,1 6.5,9A1.5,1.5 0 0,1 8,10.5A1.5,1.5 0 0,1 6.5,12M12,3A9,9 0 0,0 3,12A9,9 0 0,0 12,21A1.5,1.5 0 0,0 13.5,19.5C13.5,19.11 13.35,18.76 13.11,18.5C12.88,18.23 12.73,17.88 12.73,17.5A1.5,1.5 0 0,1 14.23,16H16A5,5 0 0,0 21,11C21,6.58 16.97,3 12,3Z",op="1.2.6";const ap=op,sp=[{name:"Navigation and city exploration",selector:{select:{options:["STREETS","STREETS.DARK","STREETS.LIGHT","STREETS.PASTEL"]}}},{name:"Data visualization",selector:{select:{options:["DATAVIZ","DATAVIZ.DARK","DATAVIZ.LIGHT"]}}},{name:"Minimalist and general purpose",selector:{select:{options:["BASIC","BASIC.DARK","BASIC.LIGHT"]}}},{name:"High contrast navigation",selector:{select:{options:["BRIGHT","BRIGHT.DARK","BRIGHT.LIGHT","BRIGHT.PASTEL"]}}},{name:"Topographic study",selector:{select:{options:["TOPO","TOPO.SHINY","TOPO.PASTEL","TOPO.TOPOGRAPHIQUE"]}}},{name:"Minimalist",selector:{select:{options:["VOYAGER","VOYAGER.DARK","VOYAGER.LIGHT","VOYAGER.VINTAGE"]}}},{name:"High contrast",selector:{select:{options:["TONER","TONER.BACKGROUND","TONER.LITE","TONER.LINES"]}}},{name:"Neutral greyscale style with hillshading",selector:{select:{options:["BACKDROP","BACKDROP.DARK","BACKDROP.LIGHT"]}}},{name:"Other",selector:{select:{options:["OPENSTREETMAP","OUTDOOR","WINTER","SATELLITE","HYBRID"]}}}],lp=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],cp=()=>sp.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),up=cp(),hp=0,pp=13,dp=["auto","light","dark"],mp=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:pp,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:dp.map((e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)})))}}},{name:"hours_to_show",label:"Hours to Show",default:0,selector:{number:{mode:"box",min:0}}},{name:"history_period",label:"History Period",default:"",selector:{select:{mode:"dropdown",options:[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"}]}}},{name:"auto_fit",label:"Auto Fit",default:!1,selector:{boolean:{}}},{name:"fit_zones",label:"Fit Zones",default:!1,selector:{boolean:{}}},{name:"use_more_info",label:"Marker more info",default:!1,selector:{boolean:{}}}],fp={name:"custom_styles",type:"expandable",iconPath:np,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:up}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:up}}}]}]},gp=at((e=>[{name:"",type:"expandable",iconPath:np,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...mp]},fp]}])),yp=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),_p=at((e=>[...yp(),...gp(e)])),vp=Symbol.for("constructDateFrom");function xp(e,t){return"function"==typeof e?e(t):e&&"object"==typeof e&&vp in e?e[vp](t):e instanceof Date?new e.constructor(t):new Date(t)}function bp(e,t){return xp(e,e)}function wp(e,...t){const i=xp.bind(null,t.find((e=>"object"==typeof e)));return t.map(i)}function Cp(e,t){const i=bp(e);return i.setHours(0,0,0,0),i}function Tp(e){return xp(e,Date.now())}function Sp(e,t,i){const[r,n]=wp(i?.in,e,t);return+Cp(r)==+Cp(n)}function Ap(e,t){return Sp(xp(e,e),Tp(e))}const Mp=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],Ep=1,Pp=8;class Ip{static from(e){if(!(e instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[t,i]=new Uint8Array(e,0,2);if(219!==t)throw new Error("Data does not appear to be in a KDBush format.");const r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=Mp[15&i];if(!n)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(e,2,1),[a]=new Uint32Array(e,4,1);return new Ip(a,o,n,e)}constructor(e,t=64,i=Float64Array,r){if(isNaN(e)||e<0)throw new Error(`Unpexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.ArrayType=i,this.IndexArrayType=e<65536?Uint16Array:Uint32Array;const n=Mp.indexOf(this.ArrayType),o=2*e*this.ArrayType.BYTES_PER_ELEMENT,a=e*this.IndexArrayType.BYTES_PER_ELEMENT,s=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=2*e,this._finished=!0):(this.data=new ArrayBuffer(8+o+a+s),this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=t,new Uint32Array(this.data,4,1)[0]=e)}add(e,t){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=e,this.coords[this._pos++]=t,i}finish(){const e=this._pos>>1;if(e!==this.numItems)throw new Error(`Added ${e} items when expected ${this.numItems}.`);return kp(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(e,t,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:a}=this,s=[0,n.length-1,0],l=[];for(;s.length;){const c=s.pop()||0,u=s.pop()||0,h=s.pop()||0;if(u-h<=a){for(let a=h;a<=u;a++){const s=o[2*a],c=o[2*a+1];s>=e&&s<=i&&c>=t&&c<=r&&l.push(n[a])}continue}const p=h+u>>1,d=o[2*p],m=o[2*p+1];d>=e&&d<=i&&m>=t&&m<=r&&l.push(n[p]),(0===c?e<=d:t<=m)&&(s.push(h),s.push(p-1),s.push(1-c)),(0===c?i>=d:r>=m)&&(s.push(p+1),s.push(u),s.push(1-c))}return l}within(e,t,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:o}=this,a=[0,r.length-1,0],s=[],l=i*i;for(;a.length;){const c=a.pop()||0,u=a.pop()||0,h=a.pop()||0;if(u-h<=o){for(let i=h;i<=u;i++)Fp(n[2*i],n[2*i+1],e,t)<=l&&s.push(r[i]);continue}const p=h+u>>1,d=n[2*p],m=n[2*p+1];Fp(d,m,e,t)<=l&&s.push(r[p]),(0===c?e-i<=d:t-i<=m)&&(a.push(h),a.push(p-1),a.push(1-c)),(0===c?e+i>=d:t+i>=m)&&(a.push(p+1),a.push(u),a.push(1-c))}return s}}function kp(e,t,i,r,n,o){if(n-r<=i)return;const a=r+n>>1;zp(e,t,a,r,n,o),kp(e,t,i,r,a-1,1-o),kp(e,t,i,a+1,n,1-o)}function zp(e,t,i,r,n,o){for(;n>r;){if(n-r>600){const a=n-r+1,s=i-r+1,l=Math.log(a),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(a-c)/a)*(s-a/2<0?-1:1);zp(e,t,i,Math.max(r,Math.floor(i-s*c/a+u)),Math.min(n,Math.floor(i+(a-s)*c/a+u)),o)}const a=t[2*i+o];let s=r,l=n;for(Lp(e,t,r,i),t[2*n+o]>a&&Lp(e,t,r,n);s<l;){for(Lp(e,t,s,l),s++,l--;t[2*s+o]<a;)s++;for(;t[2*l+o]>a;)l--}t[2*r+o]===a?Lp(e,t,r,l):(l++,Lp(e,t,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function Lp(e,t,i,r){Dp(e,i,r),Dp(t,2*i,2*r),Dp(t,2*i+1,2*r+1)}function Dp(e,t,i){const r=e[t];e[t]=e[i],e[i]=r}function Fp(e,t,i,r){const n=e-i,o=t-r;return n*n+o*o}const Rp={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e},Bp=Math.fround||(e=>t=>(e[0]=+t,e[0]))(new Float32Array(1)),Op=2,jp=3,Np=4,$p=5,Vp=6;class Up{constructor(e){this.options=Object.assign(Object.create(Rp),e),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[]}load(e){const{log:t,minZoom:i,maxZoom:r}=this.options;t&&console.time("total time");const n=`prepare ${e.length} points`;t&&console.time(n),this.points=e;const o=[];for(let t=0;t<e.length;t++){const i=e[t];if(!i.geometry)continue;const[r,n]=i.geometry.coordinates,a=Bp(Gp(r)),s=Bp(Hp(n));o.push(a,s,1/0,t,-1,1),this.options.reduce&&o.push(0)}let a=this.trees[r+1]=this._createTree(o);t&&console.timeEnd(n);for(let e=r;e>=i;e--){Date.now();a=this.trees[e]=this._createTree(this._cluster(a,e))}return t&&console.timeEnd("total time"),this}getClusters(e,t){let i=((e[0]+180)%360+360)%360-180;const r=Math.max(-90,Math.min(90,e[1]));let n=180===e[2]?180:((e[2]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,e[3]));if(e[2]-e[0]>=360)i=-180,n=180;else if(i>n){const e=this.getClusters([i,r,180,o],t),a=this.getClusters([-180,r,n,o],t);return e.concat(a)}const a=this.trees[this._limitZoom(t)],s=a.range(Gp(i),Hp(o),Gp(n),Hp(r)),l=a.data,c=[];for(const e of s){const t=this.stride*e;c.push(l[t+5]>1?qp(l,t,this.clusterProps):this.points[l[t+3]])}return c}getChildren(e){const t=this._getOriginId(e),i=this._getOriginZoom(e),r="No cluster with the specified id.",n=this.trees[i];if(!n)throw new Error(r);const o=n.data;if(t*this.stride>=o.length)throw new Error(r);const a=this.options.radius/(this.options.extent*Math.pow(2,i-1)),s=o[t*this.stride],l=o[t*this.stride+1],c=n.within(s,l,a),u=[];for(const t of c){const i=t*this.stride;o[i+4]===e&&u.push(o[i+5]>1?qp(o,i,this.clusterProps):this.points[o[i+3]])}if(0===u.length)throw new Error(r);return u}getLeaves(e,t,i){t=t||10,i=i||0;const r=[];return this._appendLeaves(r,e,t,i,0),r}getTile(e,t,i){const r=this.trees[this._limitZoom(e)],n=Math.pow(2,e),{extent:o,radius:a}=this.options,s=a/o,l=(i-s)/n,c=(i+1+s)/n,u={features:[]};return this._addTileFeatures(r.range((t-s)/n,l,(t+1+s)/n,c),r.data,t,i,n,u),0===t&&this._addTileFeatures(r.range(1-s/n,l,1,c),r.data,n,i,n,u),t===n-1&&this._addTileFeatures(r.range(0,l,s/n,c),r.data,-1,i,n,u),u.features.length?u:null}getClusterExpansionZoom(e){let t=this._getOriginZoom(e)-1;for(;t<=this.options.maxZoom;){const i=this.getChildren(e);if(t++,1!==i.length)break;e=i[0].properties.cluster_id}return t}_appendLeaves(e,t,i,r,n){const o=this.getChildren(t);for(const t of o){const o=t.properties;if(o&&o.cluster?n+o.point_count<=r?n+=o.point_count:n=this._appendLeaves(e,o.cluster_id,i,r,n):n<r?n++:e.push(t),e.length===i)break}return n}_createTree(e){const t=new Ip(e.length/this.stride|0,this.options.nodeSize,Float32Array);for(let i=0;i<e.length;i+=this.stride)t.add(e[i],e[i+1]);return t.finish(),t.data=e,t}_addTileFeatures(e,t,i,r,n,o){for(const a of e){const e=a*this.stride,s=t[e+5]>1;let l,c,u;if(s)l=Zp(t,e,this.clusterProps),c=t[e],u=t[e+1];else{const i=this.points[t[e+3]];l=i.properties;const[r,n]=i.geometry.coordinates;c=Gp(r),u=Hp(n)}const h={type:1,geometry:[[Math.round(this.options.extent*(c*n-i)),Math.round(this.options.extent*(u*n-r))]],tags:l};let p;p=s||this.options.generateId?t[e+3]:this.points[t[e+3]].id,void 0!==p&&(h.id=p),o.features.push(h)}}_limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}_cluster(e,t){const{radius:i,extent:r,reduce:n,minPoints:o}=this.options,a=i/(r*Math.pow(2,t)),s=e.data,l=[],c=this.stride;for(let i=0;i<s.length;i+=c){if(s[i+2]<=t)continue;s[i+2]=t;const r=s[i],u=s[i+1],h=e.within(s[i],s[i+1],a),p=s[i+5];let d=p;for(const e of h){const i=e*c;s[i+2]>t&&(d+=s[i+5])}if(d>p&&d>=o){let e,o=r*p,a=u*p,m=-1;const f=(i/c<<5)+(t+1)+this.points.length;for(const r of h){const l=r*c;if(s[l+2]<=t)continue;s[l+2]=t;const u=s[l+5];o+=s[l]*u,a+=s[l+1]*u,s[l+4]=f,n&&(e||(e=this._map(s,i,!0),m=this.clusterProps.length,this.clusterProps.push(e)),n(e,this._map(s,l)))}s[i+4]=f,l.push(o/d,a/d,1/0,f,-1,d),n&&l.push(m)}else{for(let e=0;e<c;e++)l.push(s[i+e]);if(d>1)for(const e of h){const i=e*c;if(!(s[i+2]<=t)){s[i+2]=t;for(let e=0;e<c;e++)l.push(s[i+e])}}}}return l}_getOriginId(e){return e-this.points.length>>5}_getOriginZoom(e){return(e-this.points.length)%32}_map(e,t,i){if(e[t+5]>1){const r=this.clusterProps[e[t+6]];return i?Object.assign({},r):r}const r=this.points[e[t+3]].properties,n=this.options.map(r);return i&&n===r?Object.assign({},n):n}}function qp(e,t,i){return{type:"Feature",id:e[t+3],properties:Zp(e,t,i),geometry:{type:"Point",coordinates:[Wp(e[t]),Kp(e[t+1])]}}}function Zp(e,t,i){const r=e[t+5],n=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?Math.round(r/100)/10+"k":r,o=e[t+6],a=-1===o?{}:Object.assign({},i[o]);return Object.assign(a,{cluster:!0,cluster_id:e[t+3],point_count:r,point_count_abbreviated:n})}function Gp(e){return e/360+.5}function Hp(e){const t=Math.sin(e*Math.PI/180),i=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return i<0?0:i>1?1:i}function Wp(e){return 360*(e-.5)}function Kp(e){const t=(180-360*e)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}const Xp=window.loadCardHelpers?window.loadCardHelpers():void 0,Yp=()=>{var e,t,i,r,n,o;customElements.get("ha-entity-marker")||null===(e=customElements.get("hui-map-card"))||void 0===e||e.getConfigElement(),customElements.get("ha-form")||null===(t=customElements.get("hui-button-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-entity-picker")||null===(i=customElements.get("hui-entities-card"))||void 0===i||i.getConfigElement(),customElements.get("ha-card-conditions-editor")||null===(r=customElements.get("hui-conditional-card"))||void 0===r||r.getConfigElement(),customElements.get("ha-form-multi_select")||null===(n=customElements.get("hui-entities-card"))||void 0===n||n.getConfigElement(),customElements.get("hui-entity-editor")||null===(o=customElements.get("hui-glance-card"))||void 0===o||o.getConfigElement()},Jp=async e=>{if(!customElements.get("ha-entity-marker")){const t={type:"map",entities:e,theme_mode:"auto"};let i;if(window.loadCardHelpers?i=await window.loadCardHelpers():Xp&&(i=Xp),!i||!i.createCardElement)return;if(!await i.createCardElement(t))return}};var Qp,ed,td,id,rd,nd,od,ad;!function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(Qp||(Qp={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(ed||(ed={})),function(e){e.local="local",e.server="server"}(td||(td={})),function(e){e.language="language",e.system="system",e.DMY="DMY",e.MDY="MDY",e.YMD="YMD"}(id||(id={})),function(e){e.language="language",e.monday="monday",e.tuesday="tuesday",e.wednesday="wednesday",e.thursday="thursday",e.friday="friday",e.saturday="saturday",e.sunday="sunday"}(rd||(rd={}));const sd=e=>"string"==typeof e?e:e.entity_id,ld=at((async(e,t,i)=>{const r={address:"streetName",locality:"sublocality",municipality:"city"},n=`https://api.maptiler.com/geocoding/${t},${e}.json?key=${i}`;try{const e=await fetch(n);if(!e.ok)throw new Error("Failed to fetch address from MapTiler");const t=await e.json();if(t&&t.features&&t.features.length>0){let e={};if(t.features.forEach((t=>{const i=t.place_type[0];if(r[i]){const n=r[i],o=t.text;"address"===i&&(e.streetNumber=t.address?`${t.address}`:""),e[n]=`${o}`}})),e.streetName&&e.city)return e}return null}catch(e){return console.warn("Error fetching address from MapTiler:",e),null}})),cd=null===(ad=null===(nd=Intl.DateTimeFormat)||void 0===nd?void 0:(od=nd.call(Intl)).resolvedOptions)||void 0===ad?void 0:ad.call(od).timeZone,ud=null!=cd?cd:"UTC",hd=(e,t)=>e===td.local&&cd?ud:t,pd=at((e=>{if(e.time_format===ed.language||e.time_format===ed.system){const t=e.time_format===ed.language?e.language:void 0;return new Date("January 1, 2023 22:00:00").toLocaleString(t).includes("10")}return e.time_format===ed.am_pm})),dd=(e,t,i)=>md(t,i.time_zone).format(e),md=at(((e,t)=>new Intl.DateTimeFormat(e.language,{weekday:"long",hour:pd(e)?"numeric":"2-digit",minute:"2-digit",hour12:pd(e),timeZone:hd(e.time_zone,t)}))),fd={dark:ei.STREETS.DARK,light:ei.DATAVIZ.LIGHT,demo:"https://demotiles.maplibre.org/style.json"},gd={backgroundColor:{light:"#fff",dark:"#222222"},fill:{light:"#222222",dark:"#c1c1c1"},boxShadow:{light:"0 0 0 2px rgba(0, 0, 0, 0.1)",dark:"0 0 0 2px rgba(255, 255, 255, 0.1)"},borderTop:{light:"1px solid #ddd",dark:"1px solid #424242"},themeBtn:{light:"mdi:weather-sunny",dark:"mdi:weather-night"}};class yd extends Ke{constructor(){super(...arguments),this.autoFit=!1,this.fitZones=!1,this.zoom=pp,this.themeMode="auto",this.useMoreInfo=!1,this._darkStyle=!1,this._mapItems=[],this._zoneItems=[],this._mapFocusZones=[],this._mapFocusItems=[],this._mapPaths=[],this._mapHelper=gh,this._clusters=[],this._clustersZoom=0,this._mapClusterItems=[],this._mapClusterFocusItems=[],this._circleLoaded=!1,this._loaded=!1,this._clustersLoaded=!1,this._createButton=(e,t)=>{const i=document.createElement("div");i.classList.add("maplibregl-ctrl","maplibregl-ctrl-group");const r=document.createElement("button"),n=document.createElement("ha-icon");return n.setAttribute("icon",e),n.style.color="var(--emc-btn-color)",r.appendChild(n),r.title=t,i.appendChild(r),i.style.display="none",i},this.getModeColor=(e,t)=>t?gd[e][t]:this._darkMode?gd[e].dark:gd[e].light}get _darkMode(){return"dark"===this.themeMode||"auto"===this.themeMode&&Boolean(this.hass.themes.darkMode)}async firstUpdated(){await Jp(this.entities),await new Promise((e=>setTimeout(e,0))),this._initMap()}render(){const e=this._renderLoadError();return ke`
|
|
220
220
|
<div class="maptiler-map">
|
|
221
221
|
${e}
|
|
222
222
|
<div id="map"></div>
|
|
@@ -325,7 +325,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
325
325
|
.maplibregl-ctrl.maplibregl-ctrl-group > button:hover > ha-icon {
|
|
326
326
|
filter: invert(39%) sepia(77%) saturate(909%) hue-rotate(182deg) brightness(89%) contrast(85%);
|
|
327
327
|
}
|
|
328
|
-
`]}}e([Qe({attribute:!1})],yd.prototype,"hass",void 0),e([Qe({attribute:!1})],yd.prototype,"entities",void 0),e([Qe({attribute:!1})],yd.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],yd.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],yd.prototype,"fitZones",void 0),e([Qe({type:Number})],yd.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],yd.prototype,"themeMode",void 0),e([Qe({type:String})],yd.prototype,"apiKey",void 0),e([Qe({type:Boolean})],yd.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],yd.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],yd.prototype,"_darkStyle",void 0),e([et()],yd.prototype,"_loaded",void 0),e([et()],yd.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",yd);class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._zoom=pp,this._getHistoryPaths=at(((e,t)=>{var i,r,n,o;if(!t)return;const a=[];for(const s of Object.keys(t)){if("zone"===z(s))continue;const l=t[s];if(!(null==l?void 0:l.length))continue;const c=[];for(const e of l){const t=e.a.latitude,i=e.a.longitude;if(!t||!i)continue;const r={};r.point=[i,t],r.timestamp=new Date(1e3*e.lu),c.push(r)}const u=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===s)),h=null!==(r=null==u?void 0:u.name)&&void 0!==r?r:s in this.hass.states?ht(this.hass.states[s]):s,p=null!==(n=null==u?void 0:u.color)&&void 0!==n?n:this._getColor(s);a.push({points:c,name:h,fullDatetime:(null!==(o=e.hours_to_show)&&void 0!==o?o:0)>=144,color:p,gradualOpacity:.8})}return a}))}_getAllEntities(){const e=this.hass,t=new Set,i=[];return Object.values(e.states).forEach((e=>{"latitude"in e.attributes&&"longitude"in e.attributes&&(i.push(e.entity_id),"person"===L(e)&&e.attributes.source&&t.add(e.attributes.source))})),i.filter((e=>!t.has(e)))}static async getConfigElement(){return await Promise.resolve().then((function(){return wd})),document.createElement("extra-map-editor")}static getStubConfig(e,t,i){return{type:"custom:extra-map-card",entities:dt(e,2,t,i,["device_tracker"]),theme_mode:"auto",use_more_info:!0}}setConfig(e){var t;if(!e)throw new Error("Invalid configuration");if(!e.show_all&&!(null===(t=e.entities)||void 0===t?void 0:t.length))throw new Error("Either entities or show_all is required");if(e.entities&&!Array.isArray(e.entities))throw new Error("Entities need to be an array");if(e.show_all&&e.entities)throw new Error("Cannot specify show_all and entities at the same time");if(this._config=Object.assign({},e),this._config.default_zoom)this._zoom=this._config.default_zoom;else if(this._config.aspect_ratio){const e=Ct(this._config.aspect_ratio),t=e&&e.w>0&&e.h>0?`${(100*e.h/e.w).toFixed(2)}`:"100";t&&Number(t)<=100?this._zoom=12:this._zoom=pp}this.hass&&e.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?gt(this._config.entities):[],this._mapEntities=this._getMapEntities()}getCardSize(){var e;if(!(null===(e=this._config)||void 0===e?void 0:e.aspect_ratio))return 7;const t=Ct(this._config.aspect_ratio),i=t&&t.w>0&&t.h>0?`${(100*t.h/t.w).toFixed(2)}`:"100";return 1+Math.floor(Number(i)/25)||3}getGridOptions(){return{columns:"full",rows:"auto",min_columns:6,min_rows:2}}render(){var e;if(!this._config)return Le;if(this._error)return ke`<ha-alert alert-type="error">
|
|
328
|
+
`]}}e([Qe({attribute:!1})],yd.prototype,"hass",void 0),e([Qe({attribute:!1})],yd.prototype,"entities",void 0),e([Qe({attribute:!1})],yd.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],yd.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],yd.prototype,"fitZones",void 0),e([Qe({type:Number})],yd.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],yd.prototype,"themeMode",void 0),e([Qe({type:String})],yd.prototype,"apiKey",void 0),e([Qe({type:Boolean})],yd.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],yd.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],yd.prototype,"_darkStyle",void 0),e([et()],yd.prototype,"_circleLoaded",void 0),e([et()],yd.prototype,"_loaded",void 0),e([et()],yd.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",yd);class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._zoom=pp,this._getHistoryPaths=at(((e,t)=>{var i,r,n,o;if(!t)return;const a=[];for(const s of Object.keys(t)){if("zone"===z(s))continue;const l=t[s];if(!(null==l?void 0:l.length))continue;const c=[];for(const e of l){const t=e.a.latitude,i=e.a.longitude;if(!t||!i)continue;const r={};r.point=[i,t],r.timestamp=new Date(1e3*e.lu),c.push(r)}const u=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===s)),h=null!==(r=null==u?void 0:u.name)&&void 0!==r?r:s in this.hass.states?ht(this.hass.states[s]):s,p=null!==(n=null==u?void 0:u.color)&&void 0!==n?n:this._getColor(s);a.push({points:c,name:h,fullDatetime:(null!==(o=e.hours_to_show)&&void 0!==o?o:0)>=144,color:p,gradualOpacity:.8})}return a}))}_getAllEntities(){const e=this.hass,t=new Set,i=[];return Object.values(e.states).forEach((e=>{"latitude"in e.attributes&&"longitude"in e.attributes&&(i.push(e.entity_id),"person"===L(e)&&e.attributes.source&&t.add(e.attributes.source))})),i.filter((e=>!t.has(e)))}static async getConfigElement(){return await Promise.resolve().then((function(){return wd})),document.createElement("extra-map-editor")}static getStubConfig(e,t,i){return{type:"custom:extra-map-card",entities:dt(e,2,t,i,["device_tracker"]),theme_mode:"auto",use_more_info:!0}}setConfig(e){var t;if(!e)throw new Error("Invalid configuration");if(!e.show_all&&!(null===(t=e.entities)||void 0===t?void 0:t.length))throw new Error("Either entities or show_all is required");if(e.entities&&!Array.isArray(e.entities))throw new Error("Entities need to be an array");if(e.show_all&&e.entities)throw new Error("Cannot specify show_all and entities at the same time");if(this._config=Object.assign({},e),this._config.default_zoom)this._zoom=this._config.default_zoom;else if(this._config.aspect_ratio){const e=Ct(this._config.aspect_ratio),t=e&&e.w>0&&e.h>0?`${(100*e.h/e.w).toFixed(2)}`:"100";t&&Number(t)<=100?this._zoom=12:this._zoom=pp}this.hass&&e.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?gt(this._config.entities):[],this._mapEntities=this._getMapEntities()}getCardSize(){var e;if(!(null===(e=this._config)||void 0===e?void 0:e.aspect_ratio))return 7;const t=Ct(this._config.aspect_ratio),i=t&&t.w>0&&t.h>0?`${(100*t.h/t.w).toFixed(2)}`:"100";return 1+Math.floor(Number(i)/25)||3}getGridOptions(){return{columns:"full",rows:"auto",min_columns:6,min_rows:2}}render(){var e;if(!this._config)return Le;if(this._error)return ke`<ha-alert alert-type="error">
|
|
329
329
|
${this.hass.localize("ui.components.map.error")}: ${this._error.message} (${this._error.code})
|
|
330
330
|
</ha-alert>`;const t=this._config.theme_mode||(this._config.dark_mode?"dark":"auto"),i=this._config.custom_styles||{};return ke`
|
|
331
331
|
<ha-card id="card" .header=${this._config.title}>
|
package/dist/index.js
CHANGED
|
@@ -216,7 +216,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
216
216
|
font-weight: 300;
|
|
217
217
|
font-size: 16px;
|
|
218
218
|
max-width: calc(100% - 80px);
|
|
219
|
-
}`,Gh=6371008.8,Hh={centimeters:100*Gh,centimetres:100*Gh,degrees:360/(2*Math.PI),feet:3.28084*Gh,inches:39.37*Gh,kilometers:Gh/1e3,kilometres:Gh/1e3,meters:Gh,metres:Gh,miles:Gh/1609.344,millimeters:1e3*Gh,millimetres:1e3*Gh,nauticalmiles:Gh/1852,radians:1,yards:1.0936*Gh};function Wh(e,t,i={}){const r={type:"Feature"};return(0===i.id||i.id)&&(r.id=i.id),i.bbox&&(r.bbox=i.bbox),r.properties=t||{},r.geometry=e,r}function Kh(e,t,i={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!ep(e[0])||!ep(e[1]))throw new Error("coordinates must contain numbers");return Wh({type:"Point",coordinates:e},t,i)}function Xh(e,t,i={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Wh({type:"Polygon",coordinates:e},t,i)}function Yh(e,t="kilometers"){const i=Hh[t];if(!i)throw new Error(t+" units is invalid");return e/i}function Jh(e){return 180*(e%(2*Math.PI))/Math.PI}function Qh(e){return e%360*Math.PI/180}function ep(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function tp(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ip(e,t,i,r={}){const n=tp(e),o=Qh(n[0]),a=Qh(n[1]),s=Qh(i),l=Yh(t,r.units),c=Math.asin(Math.sin(a)*Math.cos(l)+Math.cos(a)*Math.sin(l)*Math.cos(s));return Kh([Jh(o+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(a),Math.cos(l)-Math.sin(a)*Math.sin(c))),Jh(c)],r.properties)}function rp(e,t,i={}){const r=i.steps||64,n=i.properties?i.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},o=[];for(let n=0;n<r;n++)o.push(ip(e,t,-360*n/r,i).geometry.coordinates);return o.push(o[0]),Xh([o],n)}var np="M17.5,12A1.5,1.5 0 0,1 16,10.5A1.5,1.5 0 0,1 17.5,9A1.5,1.5 0 0,1 19,10.5A1.5,1.5 0 0,1 17.5,12M14.5,8A1.5,1.5 0 0,1 13,6.5A1.5,1.5 0 0,1 14.5,5A1.5,1.5 0 0,1 16,6.5A1.5,1.5 0 0,1 14.5,8M9.5,8A1.5,1.5 0 0,1 8,6.5A1.5,1.5 0 0,1 9.5,5A1.5,1.5 0 0,1 11,6.5A1.5,1.5 0 0,1 9.5,8M6.5,12A1.5,1.5 0 0,1 5,10.5A1.5,1.5 0 0,1 6.5,9A1.5,1.5 0 0,1 8,10.5A1.5,1.5 0 0,1 6.5,12M12,3A9,9 0 0,0 3,12A9,9 0 0,0 12,21A1.5,1.5 0 0,0 13.5,19.5C13.5,19.11 13.35,18.76 13.11,18.5C12.88,18.23 12.73,17.88 12.73,17.5A1.5,1.5 0 0,1 14.23,16H16A5,5 0 0,0 21,11C21,6.58 16.97,3 12,3Z",op="1.2.5";const ap=op,sp=[{name:"Navigation and city exploration",selector:{select:{options:["STREETS","STREETS.DARK","STREETS.LIGHT","STREETS.PASTEL"]}}},{name:"Data visualization",selector:{select:{options:["DATAVIZ","DATAVIZ.DARK","DATAVIZ.LIGHT"]}}},{name:"Minimalist and general purpose",selector:{select:{options:["BASIC","BASIC.DARK","BASIC.LIGHT"]}}},{name:"High contrast navigation",selector:{select:{options:["BRIGHT","BRIGHT.DARK","BRIGHT.LIGHT","BRIGHT.PASTEL"]}}},{name:"Topographic study",selector:{select:{options:["TOPO","TOPO.SHINY","TOPO.PASTEL","TOPO.TOPOGRAPHIQUE"]}}},{name:"Minimalist",selector:{select:{options:["VOYAGER","VOYAGER.DARK","VOYAGER.LIGHT","VOYAGER.VINTAGE"]}}},{name:"High contrast",selector:{select:{options:["TONER","TONER.BACKGROUND","TONER.LITE","TONER.LINES"]}}},{name:"Neutral greyscale style with hillshading",selector:{select:{options:["BACKDROP","BACKDROP.DARK","BACKDROP.LIGHT"]}}},{name:"Other",selector:{select:{options:["OPENSTREETMAP","OUTDOOR","WINTER","SATELLITE","HYBRID"]}}}],lp=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],cp=()=>sp.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),up=cp(),hp=0,pp=13,dp=["auto","light","dark"],mp=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:pp,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:dp.map((e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)})))}}},{name:"hours_to_show",label:"Hours to Show",default:0,selector:{number:{mode:"box",min:0}}},{name:"history_period",label:"History Period",default:"",selector:{select:{mode:"dropdown",options:[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"}]}}},{name:"auto_fit",label:"Auto Fit",default:!1,selector:{boolean:{}}},{name:"fit_zones",label:"Fit Zones",default:!1,selector:{boolean:{}}},{name:"use_more_info",label:"Marker more info",default:!1,selector:{boolean:{}}}],fp={name:"custom_styles",type:"expandable",iconPath:np,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:up}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:up}}}]}]},gp=at((e=>[{name:"",type:"expandable",iconPath:np,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...mp]},fp]}])),yp=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),_p=at((e=>[...yp(),...gp(e)])),vp=Symbol.for("constructDateFrom");function xp(e,t){return"function"==typeof e?e(t):e&&"object"==typeof e&&vp in e?e[vp](t):e instanceof Date?new e.constructor(t):new Date(t)}function bp(e,t){return xp(e,e)}function wp(e,...t){const i=xp.bind(null,t.find((e=>"object"==typeof e)));return t.map(i)}function Cp(e,t){const i=bp(e);return i.setHours(0,0,0,0),i}function Tp(e){return xp(e,Date.now())}function Sp(e,t,i){const[r,n]=wp(i?.in,e,t);return+Cp(r)==+Cp(n)}function Ap(e,t){return Sp(xp(e,e),Tp(e))}const Mp=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],Ep=1,Pp=8;class Ip{static from(e){if(!(e instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[t,i]=new Uint8Array(e,0,2);if(219!==t)throw new Error("Data does not appear to be in a KDBush format.");const r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=Mp[15&i];if(!n)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(e,2,1),[a]=new Uint32Array(e,4,1);return new Ip(a,o,n,e)}constructor(e,t=64,i=Float64Array,r){if(isNaN(e)||e<0)throw new Error(`Unpexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.ArrayType=i,this.IndexArrayType=e<65536?Uint16Array:Uint32Array;const n=Mp.indexOf(this.ArrayType),o=2*e*this.ArrayType.BYTES_PER_ELEMENT,a=e*this.IndexArrayType.BYTES_PER_ELEMENT,s=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=2*e,this._finished=!0):(this.data=new ArrayBuffer(8+o+a+s),this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=t,new Uint32Array(this.data,4,1)[0]=e)}add(e,t){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=e,this.coords[this._pos++]=t,i}finish(){const e=this._pos>>1;if(e!==this.numItems)throw new Error(`Added ${e} items when expected ${this.numItems}.`);return kp(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(e,t,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:a}=this,s=[0,n.length-1,0],l=[];for(;s.length;){const c=s.pop()||0,u=s.pop()||0,h=s.pop()||0;if(u-h<=a){for(let a=h;a<=u;a++){const s=o[2*a],c=o[2*a+1];s>=e&&s<=i&&c>=t&&c<=r&&l.push(n[a])}continue}const p=h+u>>1,d=o[2*p],m=o[2*p+1];d>=e&&d<=i&&m>=t&&m<=r&&l.push(n[p]),(0===c?e<=d:t<=m)&&(s.push(h),s.push(p-1),s.push(1-c)),(0===c?i>=d:r>=m)&&(s.push(p+1),s.push(u),s.push(1-c))}return l}within(e,t,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:o}=this,a=[0,r.length-1,0],s=[],l=i*i;for(;a.length;){const c=a.pop()||0,u=a.pop()||0,h=a.pop()||0;if(u-h<=o){for(let i=h;i<=u;i++)Fp(n[2*i],n[2*i+1],e,t)<=l&&s.push(r[i]);continue}const p=h+u>>1,d=n[2*p],m=n[2*p+1];Fp(d,m,e,t)<=l&&s.push(r[p]),(0===c?e-i<=d:t-i<=m)&&(a.push(h),a.push(p-1),a.push(1-c)),(0===c?e+i>=d:t+i>=m)&&(a.push(p+1),a.push(u),a.push(1-c))}return s}}function kp(e,t,i,r,n,o){if(n-r<=i)return;const a=r+n>>1;zp(e,t,a,r,n,o),kp(e,t,i,r,a-1,1-o),kp(e,t,i,a+1,n,1-o)}function zp(e,t,i,r,n,o){for(;n>r;){if(n-r>600){const a=n-r+1,s=i-r+1,l=Math.log(a),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(a-c)/a)*(s-a/2<0?-1:1);zp(e,t,i,Math.max(r,Math.floor(i-s*c/a+u)),Math.min(n,Math.floor(i+(a-s)*c/a+u)),o)}const a=t[2*i+o];let s=r,l=n;for(Lp(e,t,r,i),t[2*n+o]>a&&Lp(e,t,r,n);s<l;){for(Lp(e,t,s,l),s++,l--;t[2*s+o]<a;)s++;for(;t[2*l+o]>a;)l--}t[2*r+o]===a?Lp(e,t,r,l):(l++,Lp(e,t,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function Lp(e,t,i,r){Dp(e,i,r),Dp(t,2*i,2*r),Dp(t,2*i+1,2*r+1)}function Dp(e,t,i){const r=e[t];e[t]=e[i],e[i]=r}function Fp(e,t,i,r){const n=e-i,o=t-r;return n*n+o*o}const Rp={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e},Bp=Math.fround||(e=>t=>(e[0]=+t,e[0]))(new Float32Array(1)),Op=2,jp=3,Np=4,$p=5,Vp=6;class Up{constructor(e){this.options=Object.assign(Object.create(Rp),e),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[]}load(e){const{log:t,minZoom:i,maxZoom:r}=this.options;t&&console.time("total time");const n=`prepare ${e.length} points`;t&&console.time(n),this.points=e;const o=[];for(let t=0;t<e.length;t++){const i=e[t];if(!i.geometry)continue;const[r,n]=i.geometry.coordinates,a=Bp(Gp(r)),s=Bp(Hp(n));o.push(a,s,1/0,t,-1,1),this.options.reduce&&o.push(0)}let a=this.trees[r+1]=this._createTree(o);t&&console.timeEnd(n);for(let e=r;e>=i;e--){Date.now();a=this.trees[e]=this._createTree(this._cluster(a,e))}return t&&console.timeEnd("total time"),this}getClusters(e,t){let i=((e[0]+180)%360+360)%360-180;const r=Math.max(-90,Math.min(90,e[1]));let n=180===e[2]?180:((e[2]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,e[3]));if(e[2]-e[0]>=360)i=-180,n=180;else if(i>n){const e=this.getClusters([i,r,180,o],t),a=this.getClusters([-180,r,n,o],t);return e.concat(a)}const a=this.trees[this._limitZoom(t)],s=a.range(Gp(i),Hp(o),Gp(n),Hp(r)),l=a.data,c=[];for(const e of s){const t=this.stride*e;c.push(l[t+5]>1?qp(l,t,this.clusterProps):this.points[l[t+3]])}return c}getChildren(e){const t=this._getOriginId(e),i=this._getOriginZoom(e),r="No cluster with the specified id.",n=this.trees[i];if(!n)throw new Error(r);const o=n.data;if(t*this.stride>=o.length)throw new Error(r);const a=this.options.radius/(this.options.extent*Math.pow(2,i-1)),s=o[t*this.stride],l=o[t*this.stride+1],c=n.within(s,l,a),u=[];for(const t of c){const i=t*this.stride;o[i+4]===e&&u.push(o[i+5]>1?qp(o,i,this.clusterProps):this.points[o[i+3]])}if(0===u.length)throw new Error(r);return u}getLeaves(e,t,i){t=t||10,i=i||0;const r=[];return this._appendLeaves(r,e,t,i,0),r}getTile(e,t,i){const r=this.trees[this._limitZoom(e)],n=Math.pow(2,e),{extent:o,radius:a}=this.options,s=a/o,l=(i-s)/n,c=(i+1+s)/n,u={features:[]};return this._addTileFeatures(r.range((t-s)/n,l,(t+1+s)/n,c),r.data,t,i,n,u),0===t&&this._addTileFeatures(r.range(1-s/n,l,1,c),r.data,n,i,n,u),t===n-1&&this._addTileFeatures(r.range(0,l,s/n,c),r.data,-1,i,n,u),u.features.length?u:null}getClusterExpansionZoom(e){let t=this._getOriginZoom(e)-1;for(;t<=this.options.maxZoom;){const i=this.getChildren(e);if(t++,1!==i.length)break;e=i[0].properties.cluster_id}return t}_appendLeaves(e,t,i,r,n){const o=this.getChildren(t);for(const t of o){const o=t.properties;if(o&&o.cluster?n+o.point_count<=r?n+=o.point_count:n=this._appendLeaves(e,o.cluster_id,i,r,n):n<r?n++:e.push(t),e.length===i)break}return n}_createTree(e){const t=new Ip(e.length/this.stride|0,this.options.nodeSize,Float32Array);for(let i=0;i<e.length;i+=this.stride)t.add(e[i],e[i+1]);return t.finish(),t.data=e,t}_addTileFeatures(e,t,i,r,n,o){for(const a of e){const e=a*this.stride,s=t[e+5]>1;let l,c,u;if(s)l=Zp(t,e,this.clusterProps),c=t[e],u=t[e+1];else{const i=this.points[t[e+3]];l=i.properties;const[r,n]=i.geometry.coordinates;c=Gp(r),u=Hp(n)}const h={type:1,geometry:[[Math.round(this.options.extent*(c*n-i)),Math.round(this.options.extent*(u*n-r))]],tags:l};let p;p=s||this.options.generateId?t[e+3]:this.points[t[e+3]].id,void 0!==p&&(h.id=p),o.features.push(h)}}_limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}_cluster(e,t){const{radius:i,extent:r,reduce:n,minPoints:o}=this.options,a=i/(r*Math.pow(2,t)),s=e.data,l=[],c=this.stride;for(let i=0;i<s.length;i+=c){if(s[i+2]<=t)continue;s[i+2]=t;const r=s[i],u=s[i+1],h=e.within(s[i],s[i+1],a),p=s[i+5];let d=p;for(const e of h){const i=e*c;s[i+2]>t&&(d+=s[i+5])}if(d>p&&d>=o){let e,o=r*p,a=u*p,m=-1;const f=(i/c<<5)+(t+1)+this.points.length;for(const r of h){const l=r*c;if(s[l+2]<=t)continue;s[l+2]=t;const u=s[l+5];o+=s[l]*u,a+=s[l+1]*u,s[l+4]=f,n&&(e||(e=this._map(s,i,!0),m=this.clusterProps.length,this.clusterProps.push(e)),n(e,this._map(s,l)))}s[i+4]=f,l.push(o/d,a/d,1/0,f,-1,d),n&&l.push(m)}else{for(let e=0;e<c;e++)l.push(s[i+e]);if(d>1)for(const e of h){const i=e*c;if(!(s[i+2]<=t)){s[i+2]=t;for(let e=0;e<c;e++)l.push(s[i+e])}}}}return l}_getOriginId(e){return e-this.points.length>>5}_getOriginZoom(e){return(e-this.points.length)%32}_map(e,t,i){if(e[t+5]>1){const r=this.clusterProps[e[t+6]];return i?Object.assign({},r):r}const r=this.points[e[t+3]].properties,n=this.options.map(r);return i&&n===r?Object.assign({},n):n}}function qp(e,t,i){return{type:"Feature",id:e[t+3],properties:Zp(e,t,i),geometry:{type:"Point",coordinates:[Wp(e[t]),Kp(e[t+1])]}}}function Zp(e,t,i){const r=e[t+5],n=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?Math.round(r/100)/10+"k":r,o=e[t+6],a=-1===o?{}:Object.assign({},i[o]);return Object.assign(a,{cluster:!0,cluster_id:e[t+3],point_count:r,point_count_abbreviated:n})}function Gp(e){return e/360+.5}function Hp(e){const t=Math.sin(e*Math.PI/180),i=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return i<0?0:i>1?1:i}function Wp(e){return 360*(e-.5)}function Kp(e){const t=(180-360*e)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}const Xp=window.loadCardHelpers?window.loadCardHelpers():void 0,Yp=()=>{var e,t,i,r,n,o;customElements.get("ha-entity-marker")||null===(e=customElements.get("hui-map-card"))||void 0===e||e.getConfigElement(),customElements.get("ha-form")||null===(t=customElements.get("hui-button-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-entity-picker")||null===(i=customElements.get("hui-entities-card"))||void 0===i||i.getConfigElement(),customElements.get("ha-card-conditions-editor")||null===(r=customElements.get("hui-conditional-card"))||void 0===r||r.getConfigElement(),customElements.get("ha-form-multi_select")||null===(n=customElements.get("hui-entities-card"))||void 0===n||n.getConfigElement(),customElements.get("hui-entity-editor")||null===(o=customElements.get("hui-glance-card"))||void 0===o||o.getConfigElement()},Jp=async e=>{if(!customElements.get("ha-entity-marker")){const t={type:"map",entities:e,theme_mode:"auto"};let i;if(window.loadCardHelpers?i=await window.loadCardHelpers():Xp&&(i=Xp),!i||!i.createCardElement)return;if(!await i.createCardElement(t))return}};var Qp,ed,td,id,rd,nd,od,ad;!function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(Qp||(Qp={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(ed||(ed={})),function(e){e.local="local",e.server="server"}(td||(td={})),function(e){e.language="language",e.system="system",e.DMY="DMY",e.MDY="MDY",e.YMD="YMD"}(id||(id={})),function(e){e.language="language",e.monday="monday",e.tuesday="tuesday",e.wednesday="wednesday",e.thursday="thursday",e.friday="friday",e.saturday="saturday",e.sunday="sunday"}(rd||(rd={}));const sd=e=>"string"==typeof e?e:e.entity_id,ld=at((async(e,t,i)=>{const r={address:"streetName",locality:"sublocality",municipality:"city"},n=`https://api.maptiler.com/geocoding/${t},${e}.json?key=${i}`;try{const e=await fetch(n);if(!e.ok)throw new Error("Failed to fetch address from MapTiler");const t=await e.json();if(t&&t.features&&t.features.length>0){let e={};if(t.features.forEach((t=>{const i=t.place_type[0];if(r[i]){const n=r[i],o=t.text;"address"===i&&(e.streetNumber=t.address?`${t.address}`:""),e[n]=`${o}`}})),e.streetName&&e.city)return e}return null}catch(e){return console.warn("Error fetching address from MapTiler:",e),null}})),cd=null===(ad=null===(nd=Intl.DateTimeFormat)||void 0===nd?void 0:(od=nd.call(Intl)).resolvedOptions)||void 0===ad?void 0:ad.call(od).timeZone,ud=null!=cd?cd:"UTC",hd=(e,t)=>e===td.local&&cd?ud:t,pd=at((e=>{if(e.time_format===ed.language||e.time_format===ed.system){const t=e.time_format===ed.language?e.language:void 0;return new Date("January 1, 2023 22:00:00").toLocaleString(t).includes("10")}return e.time_format===ed.am_pm})),dd=(e,t,i)=>md(t,i.time_zone).format(e),md=at(((e,t)=>new Intl.DateTimeFormat(e.language,{weekday:"long",hour:pd(e)?"numeric":"2-digit",minute:"2-digit",hour12:pd(e),timeZone:hd(e.time_zone,t)}))),fd={dark:ei.STREETS.DARK,light:ei.DATAVIZ.LIGHT,demo:"https://demotiles.maplibre.org/style.json"},gd={backgroundColor:{light:"#fff",dark:"#222222"},fill:{light:"#222222",dark:"#c1c1c1"},boxShadow:{light:"0 0 0 2px rgba(0, 0, 0, 0.1)",dark:"0 0 0 2px rgba(255, 255, 255, 0.1)"},borderTop:{light:"1px solid #ddd",dark:"1px solid #424242"},themeBtn:{light:"mdi:weather-sunny",dark:"mdi:weather-night"}};class yd extends Ke{constructor(){super(...arguments),this.autoFit=!1,this.fitZones=!1,this.zoom=pp,this.themeMode="auto",this.useMoreInfo=!1,this._darkStyle=!1,this._mapItems=[],this._zoneItems=[],this._mapFocusZones=[],this._mapFocusItems=[],this._mapPaths=[],this._mapHelper=gh,this._clusters=[],this._clustersZoom=0,this._circleLoaded=!1,this._mapClusterItems=[],this._mapClusterFocusItems=[],this._loaded=!1,this._clustersLoaded=!1,this._createButton=(e,t)=>{const i=document.createElement("div");i.classList.add("maplibregl-ctrl","maplibregl-ctrl-group");const r=document.createElement("button"),n=document.createElement("ha-icon");return n.setAttribute("icon",e),n.style.color="var(--emc-btn-color)",r.appendChild(n),r.title=t,i.appendChild(r),i.style.display="none",i},this.getModeColor=(e,t)=>t?gd[e][t]:this._darkMode?gd[e].dark:gd[e].light}get _darkMode(){return"dark"===this.themeMode||"auto"===this.themeMode&&Boolean(this.hass.themes.darkMode)}async firstUpdated(){await Jp(this.entities),await new Promise((e=>setTimeout(e,0))),this._initMap()}render(){const e=this._renderLoadError();return ke`
|
|
219
|
+
}`,Gh=6371008.8,Hh={centimeters:100*Gh,centimetres:100*Gh,degrees:360/(2*Math.PI),feet:3.28084*Gh,inches:39.37*Gh,kilometers:Gh/1e3,kilometres:Gh/1e3,meters:Gh,metres:Gh,miles:Gh/1609.344,millimeters:1e3*Gh,millimetres:1e3*Gh,nauticalmiles:Gh/1852,radians:1,yards:1.0936*Gh};function Wh(e,t,i={}){const r={type:"Feature"};return(0===i.id||i.id)&&(r.id=i.id),i.bbox&&(r.bbox=i.bbox),r.properties=t||{},r.geometry=e,r}function Kh(e,t,i={}){if(!e)throw new Error("coordinates is required");if(!Array.isArray(e))throw new Error("coordinates must be an Array");if(e.length<2)throw new Error("coordinates must be at least 2 numbers long");if(!ep(e[0])||!ep(e[1]))throw new Error("coordinates must contain numbers");return Wh({type:"Point",coordinates:e},t,i)}function Xh(e,t,i={}){for(const t of e){if(t.length<4)throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");if(t[t.length-1].length!==t[0].length)throw new Error("First and last Position are not equivalent.");for(let e=0;e<t[t.length-1].length;e++)if(t[t.length-1][e]!==t[0][e])throw new Error("First and last Position are not equivalent.")}return Wh({type:"Polygon",coordinates:e},t,i)}function Yh(e,t="kilometers"){const i=Hh[t];if(!i)throw new Error(t+" units is invalid");return e/i}function Jh(e){return 180*(e%(2*Math.PI))/Math.PI}function Qh(e){return e%360*Math.PI/180}function ep(e){return!isNaN(e)&&null!==e&&!Array.isArray(e)}function tp(e){if(!e)throw new Error("coord is required");if(!Array.isArray(e)){if("Feature"===e.type&&null!==e.geometry&&"Point"===e.geometry.type)return[...e.geometry.coordinates];if("Point"===e.type)return[...e.coordinates]}if(Array.isArray(e)&&e.length>=2&&!Array.isArray(e[0])&&!Array.isArray(e[1]))return[...e];throw new Error("coord must be GeoJSON Point or an Array of numbers")}function ip(e,t,i,r={}){const n=tp(e),o=Qh(n[0]),a=Qh(n[1]),s=Qh(i),l=Yh(t,r.units),c=Math.asin(Math.sin(a)*Math.cos(l)+Math.cos(a)*Math.sin(l)*Math.cos(s));return Kh([Jh(o+Math.atan2(Math.sin(s)*Math.sin(l)*Math.cos(a),Math.cos(l)-Math.sin(a)*Math.sin(c))),Jh(c)],r.properties)}function rp(e,t,i={}){const r=i.steps||64,n=i.properties?i.properties:!Array.isArray(e)&&"Feature"===e.type&&e.properties?e.properties:{},o=[];for(let n=0;n<r;n++)o.push(ip(e,t,-360*n/r,i).geometry.coordinates);return o.push(o[0]),Xh([o],n)}var np="M17.5,12A1.5,1.5 0 0,1 16,10.5A1.5,1.5 0 0,1 17.5,9A1.5,1.5 0 0,1 19,10.5A1.5,1.5 0 0,1 17.5,12M14.5,8A1.5,1.5 0 0,1 13,6.5A1.5,1.5 0 0,1 14.5,5A1.5,1.5 0 0,1 16,6.5A1.5,1.5 0 0,1 14.5,8M9.5,8A1.5,1.5 0 0,1 8,6.5A1.5,1.5 0 0,1 9.5,5A1.5,1.5 0 0,1 11,6.5A1.5,1.5 0 0,1 9.5,8M6.5,12A1.5,1.5 0 0,1 5,10.5A1.5,1.5 0 0,1 6.5,9A1.5,1.5 0 0,1 8,10.5A1.5,1.5 0 0,1 6.5,12M12,3A9,9 0 0,0 3,12A9,9 0 0,0 12,21A1.5,1.5 0 0,0 13.5,19.5C13.5,19.11 13.35,18.76 13.11,18.5C12.88,18.23 12.73,17.88 12.73,17.5A1.5,1.5 0 0,1 14.23,16H16A5,5 0 0,0 21,11C21,6.58 16.97,3 12,3Z",op="1.2.6";const ap=op,sp=[{name:"Navigation and city exploration",selector:{select:{options:["STREETS","STREETS.DARK","STREETS.LIGHT","STREETS.PASTEL"]}}},{name:"Data visualization",selector:{select:{options:["DATAVIZ","DATAVIZ.DARK","DATAVIZ.LIGHT"]}}},{name:"Minimalist and general purpose",selector:{select:{options:["BASIC","BASIC.DARK","BASIC.LIGHT"]}}},{name:"High contrast navigation",selector:{select:{options:["BRIGHT","BRIGHT.DARK","BRIGHT.LIGHT","BRIGHT.PASTEL"]}}},{name:"Topographic study",selector:{select:{options:["TOPO","TOPO.SHINY","TOPO.PASTEL","TOPO.TOPOGRAPHIQUE"]}}},{name:"Minimalist",selector:{select:{options:["VOYAGER","VOYAGER.DARK","VOYAGER.LIGHT","VOYAGER.VINTAGE"]}}},{name:"High contrast",selector:{select:{options:["TONER","TONER.BACKGROUND","TONER.LITE","TONER.LINES"]}}},{name:"Neutral greyscale style with hillshading",selector:{select:{options:["BACKDROP","BACKDROP.DARK","BACKDROP.LIGHT"]}}},{name:"Other",selector:{select:{options:["OPENSTREETMAP","OUTDOOR","WINTER","SATELLITE","HYBRID"]}}}],lp=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],cp=()=>sp.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),up=cp(),hp=0,pp=13,dp=["auto","light","dark"],mp=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:pp,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:dp.map((e=>({value:e,label:e.charAt(0).toUpperCase()+e.slice(1)})))}}},{name:"hours_to_show",label:"Hours to Show",default:0,selector:{number:{mode:"box",min:0}}},{name:"history_period",label:"History Period",default:"",selector:{select:{mode:"dropdown",options:[{value:"today",label:"Today"},{value:"yesterday",label:"Yesterday"}]}}},{name:"auto_fit",label:"Auto Fit",default:!1,selector:{boolean:{}}},{name:"fit_zones",label:"Fit Zones",default:!1,selector:{boolean:{}}},{name:"use_more_info",label:"Marker more info",default:!1,selector:{boolean:{}}}],fp={name:"custom_styles",type:"expandable",iconPath:np,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:up}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:up}}}]}]},gp=at((e=>[{name:"",type:"expandable",iconPath:np,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...mp]},fp]}])),yp=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),_p=at((e=>[...yp(),...gp(e)])),vp=Symbol.for("constructDateFrom");function xp(e,t){return"function"==typeof e?e(t):e&&"object"==typeof e&&vp in e?e[vp](t):e instanceof Date?new e.constructor(t):new Date(t)}function bp(e,t){return xp(e,e)}function wp(e,...t){const i=xp.bind(null,t.find((e=>"object"==typeof e)));return t.map(i)}function Cp(e,t){const i=bp(e);return i.setHours(0,0,0,0),i}function Tp(e){return xp(e,Date.now())}function Sp(e,t,i){const[r,n]=wp(i?.in,e,t);return+Cp(r)==+Cp(n)}function Ap(e,t){return Sp(xp(e,e),Tp(e))}const Mp=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],Ep=1,Pp=8;class Ip{static from(e){if(!(e instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[t,i]=new Uint8Array(e,0,2);if(219!==t)throw new Error("Data does not appear to be in a KDBush format.");const r=i>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const n=Mp[15&i];if(!n)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(e,2,1),[a]=new Uint32Array(e,4,1);return new Ip(a,o,n,e)}constructor(e,t=64,i=Float64Array,r){if(isNaN(e)||e<0)throw new Error(`Unpexpected numItems value: ${e}.`);this.numItems=+e,this.nodeSize=Math.min(Math.max(+t,2),65535),this.ArrayType=i,this.IndexArrayType=e<65536?Uint16Array:Uint32Array;const n=Mp.indexOf(this.ArrayType),o=2*e*this.ArrayType.BYTES_PER_ELEMENT,a=e*this.IndexArrayType.BYTES_PER_ELEMENT,s=(8-a%8)%8;if(n<0)throw new Error(`Unexpected typed array class: ${i}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=2*e,this._finished=!0):(this.data=new ArrayBuffer(8+o+a+s),this.ids=new this.IndexArrayType(this.data,8,e),this.coords=new this.ArrayType(this.data,8+a+s,2*e),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+n]),new Uint16Array(this.data,2,1)[0]=t,new Uint32Array(this.data,4,1)[0]=e)}add(e,t){const i=this._pos>>1;return this.ids[i]=i,this.coords[this._pos++]=e,this.coords[this._pos++]=t,i}finish(){const e=this._pos>>1;if(e!==this.numItems)throw new Error(`Added ${e} items when expected ${this.numItems}.`);return kp(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(e,t,i,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:a}=this,s=[0,n.length-1,0],l=[];for(;s.length;){const c=s.pop()||0,u=s.pop()||0,h=s.pop()||0;if(u-h<=a){for(let a=h;a<=u;a++){const s=o[2*a],c=o[2*a+1];s>=e&&s<=i&&c>=t&&c<=r&&l.push(n[a])}continue}const p=h+u>>1,d=o[2*p],m=o[2*p+1];d>=e&&d<=i&&m>=t&&m<=r&&l.push(n[p]),(0===c?e<=d:t<=m)&&(s.push(h),s.push(p-1),s.push(1-c)),(0===c?i>=d:r>=m)&&(s.push(p+1),s.push(u),s.push(1-c))}return l}within(e,t,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:n,nodeSize:o}=this,a=[0,r.length-1,0],s=[],l=i*i;for(;a.length;){const c=a.pop()||0,u=a.pop()||0,h=a.pop()||0;if(u-h<=o){for(let i=h;i<=u;i++)Fp(n[2*i],n[2*i+1],e,t)<=l&&s.push(r[i]);continue}const p=h+u>>1,d=n[2*p],m=n[2*p+1];Fp(d,m,e,t)<=l&&s.push(r[p]),(0===c?e-i<=d:t-i<=m)&&(a.push(h),a.push(p-1),a.push(1-c)),(0===c?e+i>=d:t+i>=m)&&(a.push(p+1),a.push(u),a.push(1-c))}return s}}function kp(e,t,i,r,n,o){if(n-r<=i)return;const a=r+n>>1;zp(e,t,a,r,n,o),kp(e,t,i,r,a-1,1-o),kp(e,t,i,a+1,n,1-o)}function zp(e,t,i,r,n,o){for(;n>r;){if(n-r>600){const a=n-r+1,s=i-r+1,l=Math.log(a),c=.5*Math.exp(2*l/3),u=.5*Math.sqrt(l*c*(a-c)/a)*(s-a/2<0?-1:1);zp(e,t,i,Math.max(r,Math.floor(i-s*c/a+u)),Math.min(n,Math.floor(i+(a-s)*c/a+u)),o)}const a=t[2*i+o];let s=r,l=n;for(Lp(e,t,r,i),t[2*n+o]>a&&Lp(e,t,r,n);s<l;){for(Lp(e,t,s,l),s++,l--;t[2*s+o]<a;)s++;for(;t[2*l+o]>a;)l--}t[2*r+o]===a?Lp(e,t,r,l):(l++,Lp(e,t,l,n)),l<=i&&(r=l+1),i<=l&&(n=l-1)}}function Lp(e,t,i,r){Dp(e,i,r),Dp(t,2*i,2*r),Dp(t,2*i+1,2*r+1)}function Dp(e,t,i){const r=e[t];e[t]=e[i],e[i]=r}function Fp(e,t,i,r){const n=e-i,o=t-r;return n*n+o*o}const Rp={minZoom:0,maxZoom:16,minPoints:2,radius:40,extent:512,nodeSize:64,log:!1,generateId:!1,reduce:null,map:e=>e},Bp=Math.fround||(e=>t=>(e[0]=+t,e[0]))(new Float32Array(1)),Op=2,jp=3,Np=4,$p=5,Vp=6;class Up{constructor(e){this.options=Object.assign(Object.create(Rp),e),this.trees=new Array(this.options.maxZoom+1),this.stride=this.options.reduce?7:6,this.clusterProps=[]}load(e){const{log:t,minZoom:i,maxZoom:r}=this.options;t&&console.time("total time");const n=`prepare ${e.length} points`;t&&console.time(n),this.points=e;const o=[];for(let t=0;t<e.length;t++){const i=e[t];if(!i.geometry)continue;const[r,n]=i.geometry.coordinates,a=Bp(Gp(r)),s=Bp(Hp(n));o.push(a,s,1/0,t,-1,1),this.options.reduce&&o.push(0)}let a=this.trees[r+1]=this._createTree(o);t&&console.timeEnd(n);for(let e=r;e>=i;e--){Date.now();a=this.trees[e]=this._createTree(this._cluster(a,e))}return t&&console.timeEnd("total time"),this}getClusters(e,t){let i=((e[0]+180)%360+360)%360-180;const r=Math.max(-90,Math.min(90,e[1]));let n=180===e[2]?180:((e[2]+180)%360+360)%360-180;const o=Math.max(-90,Math.min(90,e[3]));if(e[2]-e[0]>=360)i=-180,n=180;else if(i>n){const e=this.getClusters([i,r,180,o],t),a=this.getClusters([-180,r,n,o],t);return e.concat(a)}const a=this.trees[this._limitZoom(t)],s=a.range(Gp(i),Hp(o),Gp(n),Hp(r)),l=a.data,c=[];for(const e of s){const t=this.stride*e;c.push(l[t+5]>1?qp(l,t,this.clusterProps):this.points[l[t+3]])}return c}getChildren(e){const t=this._getOriginId(e),i=this._getOriginZoom(e),r="No cluster with the specified id.",n=this.trees[i];if(!n)throw new Error(r);const o=n.data;if(t*this.stride>=o.length)throw new Error(r);const a=this.options.radius/(this.options.extent*Math.pow(2,i-1)),s=o[t*this.stride],l=o[t*this.stride+1],c=n.within(s,l,a),u=[];for(const t of c){const i=t*this.stride;o[i+4]===e&&u.push(o[i+5]>1?qp(o,i,this.clusterProps):this.points[o[i+3]])}if(0===u.length)throw new Error(r);return u}getLeaves(e,t,i){t=t||10,i=i||0;const r=[];return this._appendLeaves(r,e,t,i,0),r}getTile(e,t,i){const r=this.trees[this._limitZoom(e)],n=Math.pow(2,e),{extent:o,radius:a}=this.options,s=a/o,l=(i-s)/n,c=(i+1+s)/n,u={features:[]};return this._addTileFeatures(r.range((t-s)/n,l,(t+1+s)/n,c),r.data,t,i,n,u),0===t&&this._addTileFeatures(r.range(1-s/n,l,1,c),r.data,n,i,n,u),t===n-1&&this._addTileFeatures(r.range(0,l,s/n,c),r.data,-1,i,n,u),u.features.length?u:null}getClusterExpansionZoom(e){let t=this._getOriginZoom(e)-1;for(;t<=this.options.maxZoom;){const i=this.getChildren(e);if(t++,1!==i.length)break;e=i[0].properties.cluster_id}return t}_appendLeaves(e,t,i,r,n){const o=this.getChildren(t);for(const t of o){const o=t.properties;if(o&&o.cluster?n+o.point_count<=r?n+=o.point_count:n=this._appendLeaves(e,o.cluster_id,i,r,n):n<r?n++:e.push(t),e.length===i)break}return n}_createTree(e){const t=new Ip(e.length/this.stride|0,this.options.nodeSize,Float32Array);for(let i=0;i<e.length;i+=this.stride)t.add(e[i],e[i+1]);return t.finish(),t.data=e,t}_addTileFeatures(e,t,i,r,n,o){for(const a of e){const e=a*this.stride,s=t[e+5]>1;let l,c,u;if(s)l=Zp(t,e,this.clusterProps),c=t[e],u=t[e+1];else{const i=this.points[t[e+3]];l=i.properties;const[r,n]=i.geometry.coordinates;c=Gp(r),u=Hp(n)}const h={type:1,geometry:[[Math.round(this.options.extent*(c*n-i)),Math.round(this.options.extent*(u*n-r))]],tags:l};let p;p=s||this.options.generateId?t[e+3]:this.points[t[e+3]].id,void 0!==p&&(h.id=p),o.features.push(h)}}_limitZoom(e){return Math.max(this.options.minZoom,Math.min(Math.floor(+e),this.options.maxZoom+1))}_cluster(e,t){const{radius:i,extent:r,reduce:n,minPoints:o}=this.options,a=i/(r*Math.pow(2,t)),s=e.data,l=[],c=this.stride;for(let i=0;i<s.length;i+=c){if(s[i+2]<=t)continue;s[i+2]=t;const r=s[i],u=s[i+1],h=e.within(s[i],s[i+1],a),p=s[i+5];let d=p;for(const e of h){const i=e*c;s[i+2]>t&&(d+=s[i+5])}if(d>p&&d>=o){let e,o=r*p,a=u*p,m=-1;const f=(i/c<<5)+(t+1)+this.points.length;for(const r of h){const l=r*c;if(s[l+2]<=t)continue;s[l+2]=t;const u=s[l+5];o+=s[l]*u,a+=s[l+1]*u,s[l+4]=f,n&&(e||(e=this._map(s,i,!0),m=this.clusterProps.length,this.clusterProps.push(e)),n(e,this._map(s,l)))}s[i+4]=f,l.push(o/d,a/d,1/0,f,-1,d),n&&l.push(m)}else{for(let e=0;e<c;e++)l.push(s[i+e]);if(d>1)for(const e of h){const i=e*c;if(!(s[i+2]<=t)){s[i+2]=t;for(let e=0;e<c;e++)l.push(s[i+e])}}}}return l}_getOriginId(e){return e-this.points.length>>5}_getOriginZoom(e){return(e-this.points.length)%32}_map(e,t,i){if(e[t+5]>1){const r=this.clusterProps[e[t+6]];return i?Object.assign({},r):r}const r=this.points[e[t+3]].properties,n=this.options.map(r);return i&&n===r?Object.assign({},n):n}}function qp(e,t,i){return{type:"Feature",id:e[t+3],properties:Zp(e,t,i),geometry:{type:"Point",coordinates:[Wp(e[t]),Kp(e[t+1])]}}}function Zp(e,t,i){const r=e[t+5],n=r>=1e4?`${Math.round(r/1e3)}k`:r>=1e3?Math.round(r/100)/10+"k":r,o=e[t+6],a=-1===o?{}:Object.assign({},i[o]);return Object.assign(a,{cluster:!0,cluster_id:e[t+3],point_count:r,point_count_abbreviated:n})}function Gp(e){return e/360+.5}function Hp(e){const t=Math.sin(e*Math.PI/180),i=.5-.25*Math.log((1+t)/(1-t))/Math.PI;return i<0?0:i>1?1:i}function Wp(e){return 360*(e-.5)}function Kp(e){const t=(180-360*e)*Math.PI/180;return 360*Math.atan(Math.exp(t))/Math.PI-90}const Xp=window.loadCardHelpers?window.loadCardHelpers():void 0,Yp=()=>{var e,t,i,r,n,o;customElements.get("ha-entity-marker")||null===(e=customElements.get("hui-map-card"))||void 0===e||e.getConfigElement(),customElements.get("ha-form")||null===(t=customElements.get("hui-button-card"))||void 0===t||t.getConfigElement(),customElements.get("ha-entity-picker")||null===(i=customElements.get("hui-entities-card"))||void 0===i||i.getConfigElement(),customElements.get("ha-card-conditions-editor")||null===(r=customElements.get("hui-conditional-card"))||void 0===r||r.getConfigElement(),customElements.get("ha-form-multi_select")||null===(n=customElements.get("hui-entities-card"))||void 0===n||n.getConfigElement(),customElements.get("hui-entity-editor")||null===(o=customElements.get("hui-glance-card"))||void 0===o||o.getConfigElement()},Jp=async e=>{if(!customElements.get("ha-entity-marker")){const t={type:"map",entities:e,theme_mode:"auto"};let i;if(window.loadCardHelpers?i=await window.loadCardHelpers():Xp&&(i=Xp),!i||!i.createCardElement)return;if(!await i.createCardElement(t))return}};var Qp,ed,td,id,rd,nd,od,ad;!function(e){e.language="language",e.system="system",e.comma_decimal="comma_decimal",e.decimal_comma="decimal_comma",e.space_comma="space_comma",e.none="none"}(Qp||(Qp={})),function(e){e.language="language",e.system="system",e.am_pm="12",e.twenty_four="24"}(ed||(ed={})),function(e){e.local="local",e.server="server"}(td||(td={})),function(e){e.language="language",e.system="system",e.DMY="DMY",e.MDY="MDY",e.YMD="YMD"}(id||(id={})),function(e){e.language="language",e.monday="monday",e.tuesday="tuesday",e.wednesday="wednesday",e.thursday="thursday",e.friday="friday",e.saturday="saturday",e.sunday="sunday"}(rd||(rd={}));const sd=e=>"string"==typeof e?e:e.entity_id,ld=at((async(e,t,i)=>{const r={address:"streetName",locality:"sublocality",municipality:"city"},n=`https://api.maptiler.com/geocoding/${t},${e}.json?key=${i}`;try{const e=await fetch(n);if(!e.ok)throw new Error("Failed to fetch address from MapTiler");const t=await e.json();if(t&&t.features&&t.features.length>0){let e={};if(t.features.forEach((t=>{const i=t.place_type[0];if(r[i]){const n=r[i],o=t.text;"address"===i&&(e.streetNumber=t.address?`${t.address}`:""),e[n]=`${o}`}})),e.streetName&&e.city)return e}return null}catch(e){return console.warn("Error fetching address from MapTiler:",e),null}})),cd=null===(ad=null===(nd=Intl.DateTimeFormat)||void 0===nd?void 0:(od=nd.call(Intl)).resolvedOptions)||void 0===ad?void 0:ad.call(od).timeZone,ud=null!=cd?cd:"UTC",hd=(e,t)=>e===td.local&&cd?ud:t,pd=at((e=>{if(e.time_format===ed.language||e.time_format===ed.system){const t=e.time_format===ed.language?e.language:void 0;return new Date("January 1, 2023 22:00:00").toLocaleString(t).includes("10")}return e.time_format===ed.am_pm})),dd=(e,t,i)=>md(t,i.time_zone).format(e),md=at(((e,t)=>new Intl.DateTimeFormat(e.language,{weekday:"long",hour:pd(e)?"numeric":"2-digit",minute:"2-digit",hour12:pd(e),timeZone:hd(e.time_zone,t)}))),fd={dark:ei.STREETS.DARK,light:ei.DATAVIZ.LIGHT,demo:"https://demotiles.maplibre.org/style.json"},gd={backgroundColor:{light:"#fff",dark:"#222222"},fill:{light:"#222222",dark:"#c1c1c1"},boxShadow:{light:"0 0 0 2px rgba(0, 0, 0, 0.1)",dark:"0 0 0 2px rgba(255, 255, 255, 0.1)"},borderTop:{light:"1px solid #ddd",dark:"1px solid #424242"},themeBtn:{light:"mdi:weather-sunny",dark:"mdi:weather-night"}};class yd extends Ke{constructor(){super(...arguments),this.autoFit=!1,this.fitZones=!1,this.zoom=pp,this.themeMode="auto",this.useMoreInfo=!1,this._darkStyle=!1,this._mapItems=[],this._zoneItems=[],this._mapFocusZones=[],this._mapFocusItems=[],this._mapPaths=[],this._mapHelper=gh,this._clusters=[],this._clustersZoom=0,this._mapClusterItems=[],this._mapClusterFocusItems=[],this._circleLoaded=!1,this._loaded=!1,this._clustersLoaded=!1,this._createButton=(e,t)=>{const i=document.createElement("div");i.classList.add("maplibregl-ctrl","maplibregl-ctrl-group");const r=document.createElement("button"),n=document.createElement("ha-icon");return n.setAttribute("icon",e),n.style.color="var(--emc-btn-color)",r.appendChild(n),r.title=t,i.appendChild(r),i.style.display="none",i},this.getModeColor=(e,t)=>t?gd[e][t]:this._darkMode?gd[e].dark:gd[e].light}get _darkMode(){return"dark"===this.themeMode||"auto"===this.themeMode&&Boolean(this.hass.themes.darkMode)}async firstUpdated(){await Jp(this.entities),await new Promise((e=>setTimeout(e,0))),this._initMap()}render(){const e=this._renderLoadError();return ke`
|
|
220
220
|
<div class="maptiler-map">
|
|
221
221
|
${e}
|
|
222
222
|
<div id="map"></div>
|
|
@@ -325,7 +325,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
325
325
|
.maplibregl-ctrl.maplibregl-ctrl-group > button:hover > ha-icon {
|
|
326
326
|
filter: invert(39%) sepia(77%) saturate(909%) hue-rotate(182deg) brightness(89%) contrast(85%);
|
|
327
327
|
}
|
|
328
|
-
`]}}e([Qe({attribute:!1})],yd.prototype,"hass",void 0),e([Qe({attribute:!1})],yd.prototype,"entities",void 0),e([Qe({attribute:!1})],yd.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],yd.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],yd.prototype,"fitZones",void 0),e([Qe({type:Number})],yd.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],yd.prototype,"themeMode",void 0),e([Qe({type:String})],yd.prototype,"apiKey",void 0),e([Qe({type:Boolean})],yd.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],yd.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],yd.prototype,"_darkStyle",void 0),e([et()],yd.prototype,"_loaded",void 0),e([et()],yd.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",yd);class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._zoom=pp,this._getHistoryPaths=at(((e,t)=>{var i,r,n,o;if(!t)return;const a=[];for(const s of Object.keys(t)){if("zone"===z(s))continue;const l=t[s];if(!(null==l?void 0:l.length))continue;const c=[];for(const e of l){const t=e.a.latitude,i=e.a.longitude;if(!t||!i)continue;const r={};r.point=[i,t],r.timestamp=new Date(1e3*e.lu),c.push(r)}const u=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===s)),h=null!==(r=null==u?void 0:u.name)&&void 0!==r?r:s in this.hass.states?ht(this.hass.states[s]):s,p=null!==(n=null==u?void 0:u.color)&&void 0!==n?n:this._getColor(s);a.push({points:c,name:h,fullDatetime:(null!==(o=e.hours_to_show)&&void 0!==o?o:0)>=144,color:p,gradualOpacity:.8})}return a}))}_getAllEntities(){const e=this.hass,t=new Set,i=[];return Object.values(e.states).forEach((e=>{"latitude"in e.attributes&&"longitude"in e.attributes&&(i.push(e.entity_id),"person"===L(e)&&e.attributes.source&&t.add(e.attributes.source))})),i.filter((e=>!t.has(e)))}static async getConfigElement(){return await Promise.resolve().then((function(){return wd})),document.createElement("extra-map-editor")}static getStubConfig(e,t,i){return{type:"custom:extra-map-card",entities:dt(e,2,t,i,["device_tracker"]),theme_mode:"auto",use_more_info:!0}}setConfig(e){var t;if(!e)throw new Error("Invalid configuration");if(!e.show_all&&!(null===(t=e.entities)||void 0===t?void 0:t.length))throw new Error("Either entities or show_all is required");if(e.entities&&!Array.isArray(e.entities))throw new Error("Entities need to be an array");if(e.show_all&&e.entities)throw new Error("Cannot specify show_all and entities at the same time");if(this._config=Object.assign({},e),this._config.default_zoom)this._zoom=this._config.default_zoom;else if(this._config.aspect_ratio){const e=Ct(this._config.aspect_ratio),t=e&&e.w>0&&e.h>0?`${(100*e.h/e.w).toFixed(2)}`:"100";t&&Number(t)<=100?this._zoom=12:this._zoom=pp}this.hass&&e.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?gt(this._config.entities):[],this._mapEntities=this._getMapEntities()}getCardSize(){var e;if(!(null===(e=this._config)||void 0===e?void 0:e.aspect_ratio))return 7;const t=Ct(this._config.aspect_ratio),i=t&&t.w>0&&t.h>0?`${(100*t.h/t.w).toFixed(2)}`:"100";return 1+Math.floor(Number(i)/25)||3}getGridOptions(){return{columns:"full",rows:"auto",min_columns:6,min_rows:2}}render(){var e;if(!this._config)return Le;if(this._error)return ke`<ha-alert alert-type="error">
|
|
328
|
+
`]}}e([Qe({attribute:!1})],yd.prototype,"hass",void 0),e([Qe({attribute:!1})],yd.prototype,"entities",void 0),e([Qe({attribute:!1})],yd.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],yd.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],yd.prototype,"fitZones",void 0),e([Qe({type:Number})],yd.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],yd.prototype,"themeMode",void 0),e([Qe({type:String})],yd.prototype,"apiKey",void 0),e([Qe({type:Boolean})],yd.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],yd.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],yd.prototype,"_darkStyle",void 0),e([et()],yd.prototype,"_circleLoaded",void 0),e([et()],yd.prototype,"_loaded",void 0),e([et()],yd.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",yd);class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._zoom=pp,this._getHistoryPaths=at(((e,t)=>{var i,r,n,o;if(!t)return;const a=[];for(const s of Object.keys(t)){if("zone"===z(s))continue;const l=t[s];if(!(null==l?void 0:l.length))continue;const c=[];for(const e of l){const t=e.a.latitude,i=e.a.longitude;if(!t||!i)continue;const r={};r.point=[i,t],r.timestamp=new Date(1e3*e.lu),c.push(r)}const u=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===s)),h=null!==(r=null==u?void 0:u.name)&&void 0!==r?r:s in this.hass.states?ht(this.hass.states[s]):s,p=null!==(n=null==u?void 0:u.color)&&void 0!==n?n:this._getColor(s);a.push({points:c,name:h,fullDatetime:(null!==(o=e.hours_to_show)&&void 0!==o?o:0)>=144,color:p,gradualOpacity:.8})}return a}))}_getAllEntities(){const e=this.hass,t=new Set,i=[];return Object.values(e.states).forEach((e=>{"latitude"in e.attributes&&"longitude"in e.attributes&&(i.push(e.entity_id),"person"===L(e)&&e.attributes.source&&t.add(e.attributes.source))})),i.filter((e=>!t.has(e)))}static async getConfigElement(){return await Promise.resolve().then((function(){return wd})),document.createElement("extra-map-editor")}static getStubConfig(e,t,i){return{type:"custom:extra-map-card",entities:dt(e,2,t,i,["device_tracker"]),theme_mode:"auto",use_more_info:!0}}setConfig(e){var t;if(!e)throw new Error("Invalid configuration");if(!e.show_all&&!(null===(t=e.entities)||void 0===t?void 0:t.length))throw new Error("Either entities or show_all is required");if(e.entities&&!Array.isArray(e.entities))throw new Error("Entities need to be an array");if(e.show_all&&e.entities)throw new Error("Cannot specify show_all and entities at the same time");if(this._config=Object.assign({},e),this._config.default_zoom)this._zoom=this._config.default_zoom;else if(this._config.aspect_ratio){const e=Ct(this._config.aspect_ratio),t=e&&e.w>0&&e.h>0?`${(100*e.h/e.w).toFixed(2)}`:"100";t&&Number(t)<=100?this._zoom=12:this._zoom=pp}this.hass&&e.show_all&&(this._config.entities=this._getAllEntities()),this._configEntities=this._config.entities?gt(this._config.entities):[],this._mapEntities=this._getMapEntities()}getCardSize(){var e;if(!(null===(e=this._config)||void 0===e?void 0:e.aspect_ratio))return 7;const t=Ct(this._config.aspect_ratio),i=t&&t.w>0&&t.h>0?`${(100*t.h/t.w).toFixed(2)}`:"100";return 1+Math.floor(Number(i)/25)||3}getGridOptions(){return{columns:"full",rows:"auto",min_columns:6,min_rows:2}}render(){var e;if(!this._config)return Le;if(this._error)return ke`<ha-alert alert-type="error">
|
|
329
329
|
${this.hass.localize("ui.components.map.error")}: ${this._error.message} (${this._error.code})
|
|
330
330
|
</ha-alert>`;const t=this._config.theme_mode||(this._config.dark_mode?"dark":"auto"),i=this._config.custom_styles||{};return ke`
|
|
331
331
|
<ha-card id="card" .header=${this._config.title}>
|