extra-map-card 1.2.3 β 1.2.4
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.
- package/dist/constants/map-schema.d.ts +2 -1
- package/dist/extra-map-card-bundle.js +21 -8
- package/dist/index.js +20 -7
- package/package.json +2 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { LocalizeFunc } from 'custom-card-helpers';
|
|
2
|
+
export declare const CARD_VERSION: string;
|
|
2
3
|
export declare const STYLE_SCHEMA: {
|
|
3
4
|
name: string;
|
|
4
5
|
selector: {
|
|
@@ -13,7 +14,7 @@ export declare const STYLE_OPTIONS: {
|
|
|
13
14
|
label: string;
|
|
14
15
|
}[];
|
|
15
16
|
export declare const DEFAULT_HOURS_TO_SHOW = 0;
|
|
16
|
-
export declare const DEFAULT_ZOOM =
|
|
17
|
+
export declare const DEFAULT_ZOOM = 13;
|
|
17
18
|
export declare const singleMapConfingSchema: import("memoize-one").MemoizedFn<(localize: LocalizeFunc) => readonly [{
|
|
18
19
|
readonly name: "";
|
|
19
20
|
readonly type: "expandable";
|
|
@@ -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.4","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
|
|
@@ -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})],id.prototype,"hass",void 0),e([Qe({attribute:!1})],id.prototype,"entities",void 0),e([Qe({attribute:!1})],id.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],id.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],id.prototype,"fitZones",void 0),e([Qe({type:Number})],id.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],id.prototype,"themeMode",void 0),e([Qe({type:String})],id.prototype,"apiKey",void 0),e([Qe({type:Boolean})],id.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],id.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],id.prototype,"_darkStyle",void 0),e([et()],id.prototype,"_loaded",void 0),e([et()],id.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",id);var rd="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";const nd=[{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"]}}}],
|
|
328
|
+
`]}}e([Qe({attribute:!1})],id.prototype,"hass",void 0),e([Qe({attribute:!1})],id.prototype,"entities",void 0),e([Qe({attribute:!1})],id.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],id.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],id.prototype,"fitZones",void 0),e([Qe({type:Number})],id.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],id.prototype,"themeMode",void 0),e([Qe({type:String})],id.prototype,"apiKey",void 0),e([Qe({type:Boolean})],id.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],id.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],id.prototype,"_darkStyle",void 0),e([et()],id.prototype,"_loaded",void 0),e([et()],id.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",id);var rd="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",nd="1.2.4";const od=nd,ad=[{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"]}}}],sd=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],ld=()=>ad.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),cd=ld(),ud=0,hd=13,pd=["auto","light","dark"],dd=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:hd,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:pd.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:{}}}],md={name:"custom_styles",type:"expandable",iconPath:rd,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:cd}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:cd}}}]}]},fd=at((e=>[{name:"",type:"expandable",iconPath:rd,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...dd]},md]}])),gd=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),yd=at((e=>[...gd(),...fd(e)]));class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._getHistoryPaths=at(((e,t)=>{var i,r,n;if(!t)return;const o=[];for(const a of Object.keys(t)){if("zone"===z(a))continue;const s=t[a];if(!(null==s?void 0:s.length))continue;const l=[];for(const e of s){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),l.push(r)}const c=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===a)),u=null!==(r=null==c?void 0:c.name)&&void 0!==r?r:a in this.hass.states?ht(this.hass.states[a]):a;o.push({points:l,name:u,fullDatetime:(null!==(n=e.hours_to_show)&&void 0!==n?n:0)>=144,color:this._getColor(a),gradualOpacity:.8})}return o}))}_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");this._config=Object.assign({},e),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:4,min_columns:6,min_rows:2}}render(){var e,t,i,r;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 n=this._config.theme_mode||(this._config.dark_mode?"dark":"auto"),o=this._config.custom_styles||{};return ke`
|
|
331
331
|
<ha-card id="card" .header=${this._config.title}>
|
|
@@ -336,7 +336,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
336
336
|
.paths=${this._getHistoryPaths(this._config,this._stateHistory)}
|
|
337
337
|
.autoFit=${null!==(e=this._config.auto_fit)&&void 0!==e&&e}
|
|
338
338
|
.fitZones=${null!==(t=this._config.fit_zones)&&void 0!==t&&t}
|
|
339
|
-
.zoom=${null!==(i=this._config.default_zoom)&&void 0!==i?i:
|
|
339
|
+
.zoom=${null!==(i=this._config.default_zoom)&&void 0!==i?i:hd}
|
|
340
340
|
.themeMode=${n}
|
|
341
341
|
.apiKey=${this._config.api_key}
|
|
342
342
|
.useMoreInfo=${null!==(r=this._config.use_more_info)&&void 0!==r&&r}
|
|
@@ -344,7 +344,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
344
344
|
></emc-map>
|
|
345
345
|
</div>
|
|
346
346
|
</ha-card>
|
|
347
|
-
`}shouldUpdate(e){var t;if(!e.has("hass")||e.size>1)return!0;const i=e.get("hass");return!i||!this._configEntities||(i.themes.darkMode!==this.hass.themes.darkMode||(!!e.has("_stateHistory")||((null===(t=this._config)||void 0===t?void 0:t.entities)?bt(this,e):yt(this,e))))}willUpdate(e){var t,i;super.willUpdate(e),(null===(t=this._config)||void 0===t?void 0:t.show_all)&&!(null===(i=this._config)||void 0===i?void 0:i.entities)&&this.hass&&e.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=gt(this._config.entities),this._mapEntities=this._getMapEntities())}connectedCallback(){var e;super.connectedCallback(),window.ExtraMapCard=this,this.hasUpdated&&(null===(e=this._configEntities)||void 0===e?void 0:e.length)&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){var e,i;if(!t(this.hass,"history")||this._subscribed||!(null===(e=this._config)||void 0===e?void 0:e.history_period)&&!(null===(i=this._config)||void 0===i?void 0:i.hours_to_show))return;const r=this._config;let n=0;if(void 0!==r.history_period){const e=new Date;if("today"===r.history_period)n=e.getHours();else if("yesterday"===r.history_period){const t=new Date(e);t.setDate(e.getDate()-1),n=t.getHours()+24}}else n=r.hours_to_show||0;this._subscribed=O(this.hass,(e=>{this._subscribed&&(this._stateHistory=e)}),n,(this._configEntities||[]).map((e=>e.entity)),!1,!1,!1).catch((e=>{this._subscribed=void 0,this._error=e}))}_unsubscribeHistory(){this._subscribed&&(this._subscribed.then((e=>null==e?void 0:e())),this._subscribed=void 0)}updated(e){var t;(null===(t=this._configEntities)||void 0===t?void 0:t.length)?this._subscribed&&!e.has("_config")||(this._unsubscribeHistory(),this._subscribeHistory()):this._unsubscribeHistory(),e.has("_config")&&this._computePadding()}_computePadding(){const e=this.shadowRoot.getElementById("root"),t="panel"===this.layout||"grid"===this.layout;if(!this._config||t||!e)return;if(!this._config.aspect_ratio)return void(e.style.paddingBottom="100%");e.style.height="auto";const i=Ct(this._config.aspect_ratio);e.style.paddingBottom=i&&i.w>0&&i.h>0?`${(100*i.h/i.w).toFixed(2)}%`:e.style.paddingBottom="100%"}_getColor(e){let t=this._colorDict[e];return t||(t=lt(this._colorIndex),this._colorIndex++,this._colorDict[e]=t,t)}_getMapEntities(){return[...(this._configEntities||[]).map((e=>({entity_id:e.entity,color:this._getColor(e.entity),label_mode:e.label_mode,attribute:e.attribute,focus:e.focus,name:e.name})))]}}function
|
|
347
|
+
`}shouldUpdate(e){var t;if(!e.has("hass")||e.size>1)return!0;const i=e.get("hass");return!i||!this._configEntities||(i.themes.darkMode!==this.hass.themes.darkMode||(!!e.has("_stateHistory")||((null===(t=this._config)||void 0===t?void 0:t.entities)?bt(this,e):yt(this,e))))}willUpdate(e){var t,i;super.willUpdate(e),(null===(t=this._config)||void 0===t?void 0:t.show_all)&&!(null===(i=this._config)||void 0===i?void 0:i.entities)&&this.hass&&e.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=gt(this._config.entities),this._mapEntities=this._getMapEntities())}connectedCallback(){var e;super.connectedCallback(),window.ExtraMapCard=this,this.hasUpdated&&(null===(e=this._configEntities)||void 0===e?void 0:e.length)&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){var e,i;if(!t(this.hass,"history")||this._subscribed||!(null===(e=this._config)||void 0===e?void 0:e.history_period)&&!(null===(i=this._config)||void 0===i?void 0:i.hours_to_show))return;const r=this._config;let n=0;if(void 0!==r.history_period){const e=new Date;if("today"===r.history_period)n=e.getHours();else if("yesterday"===r.history_period){const t=new Date(e);t.setDate(e.getDate()-1),n=t.getHours()+24}}else n=r.hours_to_show||0;this._subscribed=O(this.hass,(e=>{this._subscribed&&(this._stateHistory=e)}),n,(this._configEntities||[]).map((e=>e.entity)),!1,!1,!1).catch((e=>{this._subscribed=void 0,this._error=e}))}_unsubscribeHistory(){this._subscribed&&(this._subscribed.then((e=>null==e?void 0:e())),this._subscribed=void 0)}updated(e){var t;(null===(t=this._configEntities)||void 0===t?void 0:t.length)?this._subscribed&&!e.has("_config")||(this._unsubscribeHistory(),this._subscribeHistory()):this._unsubscribeHistory(),e.has("_config")&&this._computePadding()}_computePadding(){const e=this.shadowRoot.getElementById("root"),t="panel"===this.layout||"grid"===this.layout;if(!this._config||t||!e)return;if(!this._config.aspect_ratio)return void(e.style.paddingBottom="100%");e.style.height="auto";const i=Ct(this._config.aspect_ratio);e.style.paddingBottom=i&&i.w>0&&i.h>0?`${(100*i.h/i.w).toFixed(2)}%`:e.style.paddingBottom="100%"}_getColor(e){let t=this._colorDict[e];return t||(t=lt(this._colorIndex),this._colorIndex++,this._colorDict[e]=t,t)}_getMapEntities(){return[...(this._configEntities||[]).map((e=>({entity_id:e.entity,color:this._getColor(e.entity),label_mode:e.label_mode,attribute:e.attribute,focus:e.focus,name:e.name})))]}}function vd(e){return e.map((e=>"string"==typeof e?{entity:e}:e))}_d.styles=G`
|
|
348
348
|
ha-card {
|
|
349
349
|
overflow: hidden;
|
|
350
350
|
width: 100%;
|
|
@@ -356,7 +356,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
356
356
|
position: relative;
|
|
357
357
|
height: 100%;
|
|
358
358
|
}
|
|
359
|
-
`,e([Qe({attribute:!1})],
|
|
359
|
+
`,e([Qe({attribute:!1})],_d.prototype,"hass",void 0),e([Qe({attribute:!1})],_d.prototype,"layout",void 0),e([et()],_d.prototype,"_config",void 0),e([et()],_d.prototype,"_mapEntities",void 0),e([et()],_d.prototype,"_error",void 0),e([et()],_d.prototype,"_stateHistory",void 0),e([it("emc-map")],_d.prototype,"_mapTiler",void 0),customElements.get("extra-map-card")||customElements.define("extra-map-card",_d),window.customCards=window.customCards||[],window.customCards.find((e=>"extra-map-card"===e.type))||window.customCards.push({description:"Extra Map Card using MapTiler",name:"Extra Map Card",preview:!0,type:"extra-map-card"});const xd=e=>"latitude"in e.attributes&&"longitude"in e.attributes;class bd extends Ke{constructor(){super(...arguments),this._computeLabelCallback=e=>{var t,i;let r=null===(t=this.hass)||void 0===t?void 0:t.localize(`ui.panel.lovelace.editor.card.generic.${e.name}`);return r||(r=null===(i=this.hass)||void 0===i?void 0:i.localize(`ui.panel.lovelace.editor.card.${e.label}`),r||e.label)}}connectedCallback(){super.connectedCallback(),Rp()}disconnectedCallback(){super.disconnectedCallback()}setConfig(e){this._config=e,this._configEntities=e.entities?vd(e.entities):[]}render(){if(!this.hass||!this._config)return Le;const e=yd(this.hass.localize);return ke`
|
|
360
360
|
<ha-form
|
|
361
361
|
.hass=${this.hass}
|
|
362
362
|
.data=${this._config}
|
|
@@ -368,11 +368,13 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
368
368
|
|
|
369
369
|
<hui-entity-editor
|
|
370
370
|
.hass=${this.hass}
|
|
371
|
+
.label=${"Entities"}
|
|
371
372
|
.entities=${this._configEntities}
|
|
372
|
-
.entityFilter=${
|
|
373
|
+
.entityFilter=${xd}
|
|
373
374
|
@entities-changed=${this._entitiesValueChanged}
|
|
374
375
|
></hui-entity-editor>
|
|
375
|
-
|
|
376
|
+
<div class="card-version">${od}</div>
|
|
377
|
+
`}_valueChanged(e){e.stopPropagation(),C(this,"config-changed",{config:e.detail.value})}_entitiesValueChanged(e){e.detail&&e.detail.entities&&(this._config=Object.assign(Object.assign({},this._config),{entities:e.detail.entities}),this._configEntities=vd(this._config.entities||[]),C(this,"config-changed",{config:this._config}))}static get styles(){return G`
|
|
376
378
|
.card-config {
|
|
377
379
|
/* Cancels overlapping Margins for HAForm + Card Config options */
|
|
378
380
|
overflow: auto;
|
|
@@ -423,4 +425,15 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
423
425
|
ha-expansion-panel ha-svg-icon {
|
|
424
426
|
color: var(--secondary-text-color);
|
|
425
427
|
}
|
|
426
|
-
|
|
428
|
+
.card-version {
|
|
429
|
+
font-size: 12px;
|
|
430
|
+
color: var(--secondary-text-color);
|
|
431
|
+
padding: 8px 16px;
|
|
432
|
+
text-align: center;
|
|
433
|
+
margin-top: 8px;
|
|
434
|
+
place-self: flex-end;
|
|
435
|
+
display: flex;
|
|
436
|
+
justify-content: center;
|
|
437
|
+
align-items: center;
|
|
438
|
+
}
|
|
439
|
+
`}}e([Qe({attribute:!1})],bd.prototype,"hass",void 0),e([et()],bd.prototype,"_config",void 0),e([et()],bd.prototype,"_configEntities",void 0),customElements.get("extra-map-editor")||customElements.define("extra-map-editor",bd);var wd=Object.freeze({__proto__:null,ExtraMapEditor:bd});export{od as CARD_VERSION,st as COLORS,sd as DARK_AVAILABLE_STYLES,ud as DEFAULT_HOURS_TO_SHOW,hd as DEFAULT_ZOOM,id as EmcMap,_d as ExtraMapCard,Kp as LOCAL_TIME_ZONE,cd as STYLE_OPTIONS,ad as STYLE_SCHEMA,gd as baseMapConfigSchema,ct as computeObjectId,ht as computeStateName,ut as computeStateNameFromEntityAttributes,x as createResource,f as deleteConfig,w as deleteResource,_ as ensureBadgeConfig,R as entityIdHistoryNeedsAttributes,d as fetchConfig,B as fetchDateWS,v as fetchResources,n as findCardIndex,dt as findEntities,c as findLovelaceCards,l as findLovelaceContainer,C as fireEvent,Jp as formatTimeWeekday,Hp as getAddress,lt as getColorByIndex,Gp as getEntityId,i as getLovelace,s as getLovelaceContainerPath,yt as hasConfigChanged,bt as hasConfigOrEntitiesChanged,xt as hasConfigOrEntityChanged,xd as hasLocation,t as isComponentLoaded,p as isStrategyDashboard,y as isStrategySection,g as isStrategyView,ft as isValidEntityId,yd as mapConfigSchema,o as parseLovelaceCardPath,a as parseLovelaceContainerPath,gt as processConfigEntities,vd as processEditorEntities,Xp as resolveTimeZone,m as saveConfig,fd as singleMapConfingSchema,j as subscribeHistory,O as subscribeHistoryStatesTimeWindow,T as subscribeRenderTemplate,h as updateLovelaceCards,u as updateLovelaceContainer,b as updateResource,Yp as useAmPm};
|
package/dist/index.js
CHANGED
|
@@ -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})],id.prototype,"hass",void 0),e([Qe({attribute:!1})],id.prototype,"entities",void 0),e([Qe({attribute:!1})],id.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],id.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],id.prototype,"fitZones",void 0),e([Qe({type:Number})],id.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],id.prototype,"themeMode",void 0),e([Qe({type:String})],id.prototype,"apiKey",void 0),e([Qe({type:Boolean})],id.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],id.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],id.prototype,"_darkStyle",void 0),e([et()],id.prototype,"_loaded",void 0),e([et()],id.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",id);var rd="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";const nd=[{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"]}}}],
|
|
328
|
+
`]}}e([Qe({attribute:!1})],id.prototype,"hass",void 0),e([Qe({attribute:!1})],id.prototype,"entities",void 0),e([Qe({attribute:!1})],id.prototype,"paths",void 0),e([Qe({attribute:"auto-fit",type:Boolean})],id.prototype,"autoFit",void 0),e([Qe({attribute:"fit-zones",type:Boolean})],id.prototype,"fitZones",void 0),e([Qe({type:Number})],id.prototype,"zoom",void 0),e([Qe({attribute:"theme-mode",type:String})],id.prototype,"themeMode",void 0),e([Qe({type:String})],id.prototype,"apiKey",void 0),e([Qe({type:Boolean})],id.prototype,"useMoreInfo",void 0),e([Qe({type:Object})],id.prototype,"customStyles",void 0),e([Qe({attribute:"dark-style",type:Boolean,reflect:!0})],id.prototype,"_darkStyle",void 0),e([et()],id.prototype,"_loaded",void 0),e([et()],id.prototype,"_error",void 0),customElements.get("emc-map")||customElements.define("emc-map",id);var rd="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",nd="1.2.4";const od=nd,ad=[{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"]}}}],sd=["STREETS","BASIC","BRIGHT","DATAVIZ","VOYAGER","BACKDROP"],ld=()=>ad.reduce(((e,t)=>{const i=t.selector.select.options;return e.concat(i.map((e=>({value:e,label:e}))))}),[]),cd=ld(),ud=0,hd=13,pd=["auto","light","dark"],dd=[{name:"aspect_ratio",label:"Aspect Ratio",selector:{text:{}}},{name:"default_zoom",label:"Default Zoom",default:hd,selector:{number:{mode:"box",min:0}}},{name:"theme_mode",label:"Theme Mode",default:"auto",selector:{select:{mode:"dropdown",options:pd.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:{}}}],md={name:"custom_styles",type:"expandable",iconPath:rd,title:"Custom Styles",schema:[{name:"",type:"grid",schema:[{name:"light",label:"Light Style",selector:{select:{mode:"dropdown",options:cd}}},{name:"dark",label:"Dark Style",selector:{select:{mode:"dropdown",options:cd}}}]}]},fd=at((e=>[{name:"",type:"expandable",iconPath:rd,title:e("ui.panel.lovelace.editor.card.map.appearance"),schema:[{name:"",type:"grid",schema:[...dd]},md]}])),gd=at((()=>[{name:"title",label:"Title",selector:{text:{type:"text"}}},{name:"api_key",label:"MapTiler API Key (required)",required:!0,selector:{text:{type:"text"}}}])),yd=at((e=>[...gd(),...fd(e)]));class _d extends Ke{constructor(){super(...arguments),this._mapEntities=[],this._colorDict={},this._colorIndex=0,this._getHistoryPaths=at(((e,t)=>{var i,r,n;if(!t)return;const o=[];for(const a of Object.keys(t)){if("zone"===z(a))continue;const s=t[a];if(!(null==s?void 0:s.length))continue;const l=[];for(const e of s){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),l.push(r)}const c=null===(i=this._configEntities)||void 0===i?void 0:i.find((e=>e.entity===a)),u=null!==(r=null==c?void 0:c.name)&&void 0!==r?r:a in this.hass.states?ht(this.hass.states[a]):a;o.push({points:l,name:u,fullDatetime:(null!==(n=e.hours_to_show)&&void 0!==n?n:0)>=144,color:this._getColor(a),gradualOpacity:.8})}return o}))}_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");this._config=Object.assign({},e),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:4,min_columns:6,min_rows:2}}render(){var e,t,i,r;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 n=this._config.theme_mode||(this._config.dark_mode?"dark":"auto"),o=this._config.custom_styles||{};return ke`
|
|
331
331
|
<ha-card id="card" .header=${this._config.title}>
|
|
@@ -336,7 +336,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
336
336
|
.paths=${this._getHistoryPaths(this._config,this._stateHistory)}
|
|
337
337
|
.autoFit=${null!==(e=this._config.auto_fit)&&void 0!==e&&e}
|
|
338
338
|
.fitZones=${null!==(t=this._config.fit_zones)&&void 0!==t&&t}
|
|
339
|
-
.zoom=${null!==(i=this._config.default_zoom)&&void 0!==i?i:
|
|
339
|
+
.zoom=${null!==(i=this._config.default_zoom)&&void 0!==i?i:hd}
|
|
340
340
|
.themeMode=${n}
|
|
341
341
|
.apiKey=${this._config.api_key}
|
|
342
342
|
.useMoreInfo=${null!==(r=this._config.use_more_info)&&void 0!==r&&r}
|
|
@@ -344,7 +344,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
344
344
|
></emc-map>
|
|
345
345
|
</div>
|
|
346
346
|
</ha-card>
|
|
347
|
-
`}shouldUpdate(e){var t;if(!e.has("hass")||e.size>1)return!0;const i=e.get("hass");return!i||!this._configEntities||(i.themes.darkMode!==this.hass.themes.darkMode||(!!e.has("_stateHistory")||((null===(t=this._config)||void 0===t?void 0:t.entities)?bt(this,e):yt(this,e))))}willUpdate(e){var t,i;super.willUpdate(e),(null===(t=this._config)||void 0===t?void 0:t.show_all)&&!(null===(i=this._config)||void 0===i?void 0:i.entities)&&this.hass&&e.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=gt(this._config.entities),this._mapEntities=this._getMapEntities())}connectedCallback(){var e;super.connectedCallback(),window.ExtraMapCard=this,this.hasUpdated&&(null===(e=this._configEntities)||void 0===e?void 0:e.length)&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){var e,i;if(!t(this.hass,"history")||this._subscribed||!(null===(e=this._config)||void 0===e?void 0:e.history_period)&&!(null===(i=this._config)||void 0===i?void 0:i.hours_to_show))return;const r=this._config;let n=0;if(void 0!==r.history_period){const e=new Date;if("today"===r.history_period)n=e.getHours();else if("yesterday"===r.history_period){const t=new Date(e);t.setDate(e.getDate()-1),n=t.getHours()+24}}else n=r.hours_to_show||0;this._subscribed=O(this.hass,(e=>{this._subscribed&&(this._stateHistory=e)}),n,(this._configEntities||[]).map((e=>e.entity)),!1,!1,!1).catch((e=>{this._subscribed=void 0,this._error=e}))}_unsubscribeHistory(){this._subscribed&&(this._subscribed.then((e=>null==e?void 0:e())),this._subscribed=void 0)}updated(e){var t;(null===(t=this._configEntities)||void 0===t?void 0:t.length)?this._subscribed&&!e.has("_config")||(this._unsubscribeHistory(),this._subscribeHistory()):this._unsubscribeHistory(),e.has("_config")&&this._computePadding()}_computePadding(){const e=this.shadowRoot.getElementById("root"),t="panel"===this.layout||"grid"===this.layout;if(!this._config||t||!e)return;if(!this._config.aspect_ratio)return void(e.style.paddingBottom="100%");e.style.height="auto";const i=Ct(this._config.aspect_ratio);e.style.paddingBottom=i&&i.w>0&&i.h>0?`${(100*i.h/i.w).toFixed(2)}%`:e.style.paddingBottom="100%"}_getColor(e){let t=this._colorDict[e];return t||(t=lt(this._colorIndex),this._colorIndex++,this._colorDict[e]=t,t)}_getMapEntities(){return[...(this._configEntities||[]).map((e=>({entity_id:e.entity,color:this._getColor(e.entity),label_mode:e.label_mode,attribute:e.attribute,focus:e.focus,name:e.name})))]}}function
|
|
347
|
+
`}shouldUpdate(e){var t;if(!e.has("hass")||e.size>1)return!0;const i=e.get("hass");return!i||!this._configEntities||(i.themes.darkMode!==this.hass.themes.darkMode||(!!e.has("_stateHistory")||((null===(t=this._config)||void 0===t?void 0:t.entities)?bt(this,e):yt(this,e))))}willUpdate(e){var t,i;super.willUpdate(e),(null===(t=this._config)||void 0===t?void 0:t.show_all)&&!(null===(i=this._config)||void 0===i?void 0:i.entities)&&this.hass&&e.has("hass")&&(this._config.entities=this._getAllEntities(),this._configEntities=gt(this._config.entities),this._mapEntities=this._getMapEntities())}connectedCallback(){var e;super.connectedCallback(),window.ExtraMapCard=this,this.hasUpdated&&(null===(e=this._configEntities)||void 0===e?void 0:e.length)&&this._subscribeHistory()}disconnectedCallback(){super.disconnectedCallback(),this._unsubscribeHistory()}_subscribeHistory(){var e,i;if(!t(this.hass,"history")||this._subscribed||!(null===(e=this._config)||void 0===e?void 0:e.history_period)&&!(null===(i=this._config)||void 0===i?void 0:i.hours_to_show))return;const r=this._config;let n=0;if(void 0!==r.history_period){const e=new Date;if("today"===r.history_period)n=e.getHours();else if("yesterday"===r.history_period){const t=new Date(e);t.setDate(e.getDate()-1),n=t.getHours()+24}}else n=r.hours_to_show||0;this._subscribed=O(this.hass,(e=>{this._subscribed&&(this._stateHistory=e)}),n,(this._configEntities||[]).map((e=>e.entity)),!1,!1,!1).catch((e=>{this._subscribed=void 0,this._error=e}))}_unsubscribeHistory(){this._subscribed&&(this._subscribed.then((e=>null==e?void 0:e())),this._subscribed=void 0)}updated(e){var t;(null===(t=this._configEntities)||void 0===t?void 0:t.length)?this._subscribed&&!e.has("_config")||(this._unsubscribeHistory(),this._subscribeHistory()):this._unsubscribeHistory(),e.has("_config")&&this._computePadding()}_computePadding(){const e=this.shadowRoot.getElementById("root"),t="panel"===this.layout||"grid"===this.layout;if(!this._config||t||!e)return;if(!this._config.aspect_ratio)return void(e.style.paddingBottom="100%");e.style.height="auto";const i=Ct(this._config.aspect_ratio);e.style.paddingBottom=i&&i.w>0&&i.h>0?`${(100*i.h/i.w).toFixed(2)}%`:e.style.paddingBottom="100%"}_getColor(e){let t=this._colorDict[e];return t||(t=lt(this._colorIndex),this._colorIndex++,this._colorDict[e]=t,t)}_getMapEntities(){return[...(this._configEntities||[]).map((e=>({entity_id:e.entity,color:this._getColor(e.entity),label_mode:e.label_mode,attribute:e.attribute,focus:e.focus,name:e.name})))]}}function vd(e){return e.map((e=>"string"==typeof e?{entity:e}:e))}_d.styles=G`
|
|
348
348
|
ha-card {
|
|
349
349
|
overflow: hidden;
|
|
350
350
|
width: 100%;
|
|
@@ -356,7 +356,7 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
356
356
|
position: relative;
|
|
357
357
|
height: 100%;
|
|
358
358
|
}
|
|
359
|
-
`,e([Qe({attribute:!1})],
|
|
359
|
+
`,e([Qe({attribute:!1})],_d.prototype,"hass",void 0),e([Qe({attribute:!1})],_d.prototype,"layout",void 0),e([et()],_d.prototype,"_config",void 0),e([et()],_d.prototype,"_mapEntities",void 0),e([et()],_d.prototype,"_error",void 0),e([et()],_d.prototype,"_stateHistory",void 0),e([it("emc-map")],_d.prototype,"_mapTiler",void 0),customElements.get("extra-map-card")||customElements.define("extra-map-card",_d),window.customCards=window.customCards||[],window.customCards.find((e=>"extra-map-card"===e.type))||window.customCards.push({description:"Extra Map Card using MapTiler",name:"Extra Map Card",preview:!0,type:"extra-map-card"});const xd=e=>"latitude"in e.attributes&&"longitude"in e.attributes;class bd extends Ke{constructor(){super(...arguments),this._computeLabelCallback=e=>{var t,i;let r=null===(t=this.hass)||void 0===t?void 0:t.localize(`ui.panel.lovelace.editor.card.generic.${e.name}`);return r||(r=null===(i=this.hass)||void 0===i?void 0:i.localize(`ui.panel.lovelace.editor.card.${e.label}`),r||e.label)}}connectedCallback(){super.connectedCallback(),Rp()}disconnectedCallback(){super.disconnectedCallback()}setConfig(e){this._config=e,this._configEntities=e.entities?vd(e.entities):[]}render(){if(!this.hass||!this._config)return Le;const e=yd(this.hass.localize);return ke`
|
|
360
360
|
<ha-form
|
|
361
361
|
.hass=${this.hass}
|
|
362
362
|
.data=${this._config}
|
|
@@ -368,11 +368,13 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
368
368
|
|
|
369
369
|
<hui-entity-editor
|
|
370
370
|
.hass=${this.hass}
|
|
371
|
+
.label=${"Entities"}
|
|
371
372
|
.entities=${this._configEntities}
|
|
372
|
-
.entityFilter=${
|
|
373
|
+
.entityFilter=${xd}
|
|
373
374
|
@entities-changed=${this._entitiesValueChanged}
|
|
374
375
|
></hui-entity-editor>
|
|
375
|
-
|
|
376
|
+
<div class="card-version">${od}</div>
|
|
377
|
+
`}_valueChanged(e){e.stopPropagation(),C(this,"config-changed",{config:e.detail.value})}_entitiesValueChanged(e){e.detail&&e.detail.entities&&(this._config=Object.assign(Object.assign({},this._config),{entities:e.detail.entities}),this._configEntities=vd(this._config.entities||[]),C(this,"config-changed",{config:this._config}))}static get styles(){return G`
|
|
376
378
|
.card-config {
|
|
377
379
|
/* Cancels overlapping Margins for HAForm + Card Config options */
|
|
378
380
|
overflow: auto;
|
|
@@ -423,4 +425,15 @@ const Ye={attribute:!0,type:String,converter:ae,reflect:!1,hasChanged:se},Je=(e=
|
|
|
423
425
|
ha-expansion-panel ha-svg-icon {
|
|
424
426
|
color: var(--secondary-text-color);
|
|
425
427
|
}
|
|
426
|
-
|
|
428
|
+
.card-version {
|
|
429
|
+
font-size: 12px;
|
|
430
|
+
color: var(--secondary-text-color);
|
|
431
|
+
padding: 8px 16px;
|
|
432
|
+
text-align: center;
|
|
433
|
+
margin-top: 8px;
|
|
434
|
+
place-self: flex-end;
|
|
435
|
+
display: flex;
|
|
436
|
+
justify-content: center;
|
|
437
|
+
align-items: center;
|
|
438
|
+
}
|
|
439
|
+
`}}e([Qe({attribute:!1})],bd.prototype,"hass",void 0),e([et()],bd.prototype,"_config",void 0),e([et()],bd.prototype,"_configEntities",void 0),customElements.get("extra-map-editor")||customElements.define("extra-map-editor",bd);var wd=Object.freeze({__proto__:null,ExtraMapEditor:bd});export{od as CARD_VERSION,st as COLORS,sd as DARK_AVAILABLE_STYLES,ud as DEFAULT_HOURS_TO_SHOW,hd as DEFAULT_ZOOM,id as EmcMap,_d as ExtraMapCard,Kp as LOCAL_TIME_ZONE,cd as STYLE_OPTIONS,ad as STYLE_SCHEMA,gd as baseMapConfigSchema,ct as computeObjectId,ht as computeStateName,ut as computeStateNameFromEntityAttributes,x as createResource,f as deleteConfig,w as deleteResource,_ as ensureBadgeConfig,R as entityIdHistoryNeedsAttributes,d as fetchConfig,B as fetchDateWS,v as fetchResources,n as findCardIndex,dt as findEntities,c as findLovelaceCards,l as findLovelaceContainer,C as fireEvent,Jp as formatTimeWeekday,Hp as getAddress,lt as getColorByIndex,Gp as getEntityId,i as getLovelace,s as getLovelaceContainerPath,yt as hasConfigChanged,bt as hasConfigOrEntitiesChanged,xt as hasConfigOrEntityChanged,xd as hasLocation,t as isComponentLoaded,p as isStrategyDashboard,y as isStrategySection,g as isStrategyView,ft as isValidEntityId,yd as mapConfigSchema,o as parseLovelaceCardPath,a as parseLovelaceContainerPath,gt as processConfigEntities,vd as processEditorEntities,Xp as resolveTimeZone,m as saveConfig,fd as singleMapConfingSchema,j as subscribeHistory,O as subscribeHistoryStatesTimeWindow,T as subscribeRenderTemplate,h as updateLovelaceCards,u as updateLovelaceContainer,b as updateResource,Yp as useAmPm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "extra-map-card",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.4",
|
|
4
4
|
"description": "Lovelace custom map card for Home Assistant",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"home-assistant",
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"@babel/core": "^7.26.9",
|
|
48
48
|
"@rollup/plugin-babel": "^6.0.4",
|
|
49
49
|
"@rollup/plugin-commonjs": "^28.0.3",
|
|
50
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
50
51
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
51
52
|
"@rollup/plugin-terser": "^0.4.4",
|
|
52
53
|
"@turf/turf": "^7.2.0",
|