@prometa/sleek 0.0.9 → 0.0.11
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/components/google-map-static.d.ts +4 -0
- package/dist/components/google-map-static.d.ts.map +1 -0
- package/dist/components/google-map.d.ts +37 -0
- package/dist/components/google-map.d.ts.map +1 -0
- package/dist/components.cjs +1 -1
- package/dist/components.js +1 -1
- package/dist/google-map-static.cjs +1 -0
- package/dist/google-map-static.js +10 -0
- package/dist/google-map.cjs +1 -0
- package/dist/google-map.js +356 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/sleek-select.cjs +3 -2
- package/dist/sleek-select.js +142 -139
- package/dist/sleek.cjs +1 -1
- package/dist/sleek.js +29 -25
- package/package.json +3 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-map-static.d.ts","sourceRoot":"","sources":["../../src/components/google-map-static.ts"],"names":[],"mappings":"AAAA,qBAAa,eAAgB,SAAQ,WAAW;IAC9C,iBAAiB;CAWlB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
type GoogleMapsLibrary = "maps" | "marker" | "places" | "geometry" | "drawing";
|
|
2
|
+
export declare function load<T extends GoogleMapsLibrary[]>(libraries?: T): Promise<Record<string, any>>;
|
|
3
|
+
export declare class GoogleMap extends HTMLElement {
|
|
4
|
+
#private;
|
|
5
|
+
private markers;
|
|
6
|
+
private bounds;
|
|
7
|
+
map: google.maps.Map;
|
|
8
|
+
constructor();
|
|
9
|
+
connectedCallback(): void;
|
|
10
|
+
setMarker(position: {
|
|
11
|
+
lat: number;
|
|
12
|
+
lng: number;
|
|
13
|
+
}, draggable?: boolean, pinOptions?: any): Promise<any>;
|
|
14
|
+
panTo(position: {
|
|
15
|
+
lat: number;
|
|
16
|
+
lng: number;
|
|
17
|
+
}, options?: {
|
|
18
|
+
keepZoom?: boolean;
|
|
19
|
+
}): void;
|
|
20
|
+
}
|
|
21
|
+
export declare class GoogleMapMarker extends HTMLElement {
|
|
22
|
+
#private;
|
|
23
|
+
static observedAttributes: string[];
|
|
24
|
+
private marker;
|
|
25
|
+
private infoWindow;
|
|
26
|
+
connectedCallback(): Promise<void>;
|
|
27
|
+
attributeChangedCallback(): void;
|
|
28
|
+
private updateMarker;
|
|
29
|
+
private getOrCreateMarker;
|
|
30
|
+
get position(): {
|
|
31
|
+
lat: number;
|
|
32
|
+
lng: number;
|
|
33
|
+
};
|
|
34
|
+
openInfoWindow(): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
37
|
+
//# sourceMappingURL=google-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google-map.d.ts","sourceRoot":"","sources":["../../src/components/google-map.ts"],"names":[],"mappings":"AAEA,KAAK,iBAAiB,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,UAAU,GAAG,SAAS,CAAC;AAI/E,wBAAsB,IAAI,CAAC,CAAC,SAAS,iBAAiB,EAAE,EACtD,SAAS,GAAE,CAAsB,gCAelC;AAED,qBAAa,SAAU,SAAQ,WAAW;;IACxC,OAAO,CAAC,OAAO,CAA6C;IAC5D,OAAO,CAAC,MAAM,CAAM;IACb,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAQ;;IAUnC,iBAAiB;IAsCX,SAAS,CAAC,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,SAAS,GAAE,OAAe,EAAE,UAAU,GAAE,GAAQ;IA2BxG,KAAK,CAAC,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAO;CAKnF;AAGD,qBAAa,eAAgB,SAAQ,WAAW;;IAC9C,MAAM,CAAC,kBAAkB,WAAiC;IAE1D,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,UAAU,CAAa;IAIzB,iBAAiB;IAQvB,wBAAwB;YASV,YAAY;YAQZ,iBAAiB;IA6D/B,IAAI,QAAQ,IAAI;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAK3C;IAED,cAAc;CAKf"}
|
package/dist/components.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(){return Object.assign({"./chartjs-chart.ts":()=>Promise.resolve().then(()=>require("./chartjs-chart.cjs")),"./sleek-select.ts":()=>Promise.resolve().then(()=>require("./sleek-select.cjs"))})}exports.importCustomElements=e;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function e(){return Object.assign({"./chartjs-chart.ts":()=>Promise.resolve().then(()=>require("./chartjs-chart.cjs")),"./google-map-static.ts":()=>Promise.resolve().then(()=>require("./google-map-static.cjs")),"./google-map.ts":()=>Promise.resolve().then(()=>require("./google-map.cjs")),"./sleek-select.ts":()=>Promise.resolve().then(()=>require("./sleek-select.cjs"))})}exports.importCustomElements=e;
|
package/dist/components.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
function t() {
|
|
2
|
-
return /* @__PURE__ */ Object.assign({ "./chartjs-chart.ts": () => import("./chartjs-chart.js"), "./sleek-select.ts": () => import("./sleek-select.js") });
|
|
2
|
+
return /* @__PURE__ */ Object.assign({ "./chartjs-chart.ts": () => import("./chartjs-chart.js"), "./google-map-static.ts": () => import("./google-map-static.js"), "./google-map.ts": () => import("./google-map.js"), "./sleek-select.ts": () => import("./sleek-select.js") });
|
|
3
3
|
}
|
|
4
4
|
export {
|
|
5
5
|
t as importCustomElements
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});class o extends HTMLElement{connectedCallback(){const t=this.getAttribute("lat"),e=this.getAttribute("lng"),s=this.getAttribute("zoom")||"14",a=this.getAttribute("size")||"600x300",i=this.getAttribute("type")||"roadmap",l=window.SLEEK.maps.googleMapsApiKey,c=`https://maps.googleapis.com/maps/api/staticmap?center=${t},${e}&zoom=${s}&size=${a}&maptype=${i}&markers=color:red%7Clabel:S%7C${t},${e}&key=${l}`;this.style.display="block",this.innerHTML=`<img src="${c}" alt="Standortkarte" style="width: 100%; height: auto;">`}}customElements.define("google-map-static",o);exports.GoogleMapStatic=o;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
class l extends HTMLElement {
|
|
2
|
+
connectedCallback() {
|
|
3
|
+
const t = this.getAttribute("lat"), e = this.getAttribute("lng"), s = this.getAttribute("zoom") || "14", o = this.getAttribute("size") || "600x300", a = this.getAttribute("type") || "roadmap", i = window.SLEEK.maps.googleMapsApiKey, c = `https://maps.googleapis.com/maps/api/staticmap?center=${t},${e}&zoom=${s}&size=${o}&maptype=${a}&markers=color:red%7Clabel:S%7C${t},${e}&key=${i}`;
|
|
4
|
+
this.style.display = "block", this.innerHTML = `<img src="${c}" alt="Standortkarte" style="width: 100%; height: auto;">`;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
customElements.define("google-map-static", l);
|
|
8
|
+
export {
|
|
9
|
+
l as GoogleMapStatic
|
|
10
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var R=r=>{throw TypeError(r)};var T=(r,e,t)=>e.has(r)||R("Cannot "+t);var I=(r,e,t)=>(T(r,e,"read from private field"),t?t.call(r):e.get(r)),M=(r,e,t)=>e.has(r)?R("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(r):e.set(r,t),g=(r,e,t,i)=>(T(r,e,"write to private field"),i?i.call(r,t):e.set(r,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function N(r,e,t,i){function s(n){return n instanceof t?n:new t(function(o){o(n)})}return new(t||(t=Promise))(function(n,o){function a(h){try{c(i.next(h))}catch(p){o(p)}}function l(h){try{c(i.throw(h))}catch(p){o(p)}}function c(h){h.done?n(h.value):s(h.value).then(a,l)}c((i=i.apply(r,[])).next())})}function U(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var O,K;function G(){return K||(K=1,O=function r(e,t){if(e===t)return!0;if(e&&t&&typeof e=="object"&&typeof t=="object"){if(e.constructor!==t.constructor)return!1;var i,s,n;if(Array.isArray(e)){if(i=e.length,i!=t.length)return!1;for(s=i;s--!==0;)if(!r(e[s],t[s]))return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if(n=Object.keys(e),i=n.length,i!==Object.keys(t).length)return!1;for(s=i;s--!==0;)if(!Object.prototype.hasOwnProperty.call(t,n[s]))return!1;for(s=i;s--!==0;){var o=n[s];if(!r(e[o],t[o]))return!1}return!0}return e!==e&&t!==t}),O}var x=G(),W=U(x);const _="__googleMapsScriptId";var f;(function(r){r[r.INITIALIZED=0]="INITIALIZED",r[r.LOADING=1]="LOADING",r[r.SUCCESS=2]="SUCCESS",r[r.FAILURE=3]="FAILURE"})(f||(f={}));class d{constructor({apiKey:e,authReferrerPolicy:t,channel:i,client:s,id:n=_,language:o,libraries:a=[],mapIds:l,nonce:c,region:h,retries:p=3,url:b="https://maps.googleapis.com/maps/api/js",version:w}){if(this.callbacks=[],this.done=!1,this.loading=!1,this.errors=[],this.apiKey=e,this.authReferrerPolicy=t,this.channel=i,this.client=s,this.id=n||_,this.language=o,this.libraries=a,this.mapIds=l,this.nonce=c,this.region=h,this.retries=p,this.url=b,this.version=w,d.instance){if(!W(this.options,d.instance.options))throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(d.instance.options)}`);return d.instance}d.instance=this}get options(){return{version:this.version,apiKey:this.apiKey,channel:this.channel,client:this.client,id:this.id,libraries:this.libraries,language:this.language,region:this.region,mapIds:this.mapIds,nonce:this.nonce,url:this.url,authReferrerPolicy:this.authReferrerPolicy}}get status(){return this.errors.length?f.FAILURE:this.done?f.SUCCESS:this.loading?f.LOADING:f.INITIALIZED}get failed(){return this.done&&!this.loading&&this.errors.length>=this.retries+1}createUrl(){let e=this.url;return e+="?callback=__googleMapsCallback&loading=async",this.apiKey&&(e+=`&key=${this.apiKey}`),this.channel&&(e+=`&channel=${this.channel}`),this.client&&(e+=`&client=${this.client}`),this.libraries.length>0&&(e+=`&libraries=${this.libraries.join(",")}`),this.language&&(e+=`&language=${this.language}`),this.region&&(e+=`®ion=${this.region}`),this.version&&(e+=`&v=${this.version}`),this.mapIds&&(e+=`&map_ids=${this.mapIds.join(",")}`),this.authReferrerPolicy&&(e+=`&auth_referrer_policy=${this.authReferrerPolicy}`),e}deleteScript(){const e=document.getElementById(this.id);e&&e.remove()}load(){return this.loadPromise()}loadPromise(){return new Promise((e,t)=>{this.loadCallback(i=>{i?t(i.error):e(window.google)})})}importLibrary(e){return this.execute(),google.maps.importLibrary(e)}loadCallback(e){this.callbacks.push(e),this.execute()}setScript(){var e,t;if(document.getElementById(this.id)){this.callback();return}const i={key:this.apiKey,channel:this.channel,client:this.client,libraries:this.libraries.length&&this.libraries,v:this.version,mapIds:this.mapIds,language:this.language,region:this.region,authReferrerPolicy:this.authReferrerPolicy};Object.keys(i).forEach(n=>!i[n]&&delete i[n]),!((t=(e=window==null?void 0:window.google)===null||e===void 0?void 0:e.maps)===null||t===void 0)&&t.importLibrary||(n=>{let o,a,l,c="The Google Maps JavaScript API",h="google",p="importLibrary",b="__ib__",w=document,y=window;y=y[h]||(y[h]={});const E=y.maps||(y.maps={}),j=new Set,k=new URLSearchParams,F=()=>o||(o=new Promise((v,A)=>N(this,void 0,void 0,function*(){var C;yield a=w.createElement("script"),a.id=this.id,k.set("libraries",[...j]+"");for(l in n)k.set(l.replace(/[A-Z]/g,$=>"_"+$[0].toLowerCase()),n[l]);k.set("callback",h+".maps."+b),a.src=this.url+"?"+k,E[b]=v,a.onerror=()=>o=A(Error(c+" could not load.")),a.nonce=this.nonce||((C=w.querySelector("script[nonce]"))===null||C===void 0?void 0:C.nonce)||"",w.head.append(a)})));E[p]?console.warn(c+" only loads once. Ignoring:",n):E[p]=(v,...A)=>j.add(v)&&F().then(()=>E[p](v,...A))})(i);const s=this.libraries.map(n=>this.importLibrary(n));s.length||s.push(this.importLibrary("core")),Promise.all(s).then(()=>this.callback(),n=>{const o=new ErrorEvent("error",{error:n});this.loadErrorCallback(o)})}reset(){this.deleteScript(),this.done=!1,this.loading=!1,this.errors=[],this.onerrorEvent=null}resetIfRetryingFailed(){this.failed&&this.reset()}loadErrorCallback(e){if(this.errors.push(e),this.errors.length<=this.retries){const t=this.errors.length*Math.pow(2,this.errors.length);console.error(`Failed to load Google Maps script, retrying in ${t} ms.`),setTimeout(()=>{this.deleteScript(),this.setScript()},t)}else this.onerrorEvent=e,this.callback()}callback(){this.done=!0,this.loading=!1,this.callbacks.forEach(e=>{e(this.onerrorEvent)}),this.callbacks=[]}execute(){if(this.resetIfRetryingFailed(),!this.loading)if(this.done)this.callback();else{if(window.google&&window.google.maps&&window.google.maps.version){console.warn("Google Maps already loaded outside @googlemaps/js-api-loader. This may result in undesirable behavior as options and script parameters may not match."),this.callback();return}this.loading=!0,this.setScript()}}}let q=null;async function S(r=[]){if(!window.SLEEK||!window.SLEEK.maps||!window.SLEEK.maps.googleMapsApiKey)throw new Error("Google Maps API key is not configured. Please set window.SLEEK.maps.googleMapsApiKey.");return q??(q=new d({apiKey:window.SLEEK.maps.googleMapsApiKey})),(await Promise.all(r.map(t=>q.importLibrary(t)))).reduce((t,i)=>({...t,...i}),{})}var m;class D extends HTMLElement{constructor(){super();M(this,m);this.map=null,g(this,m,void 0),this.markers=[],this.bounds=null}connectedCallback(){const t=this.attachShadow({mode:"open"});this.querySelectorAll("style").forEach(a=>{t.appendChild(a)});const i=t.appendChild(document.createElement("main"));i.style.display="block",i.style.width="100%",i.style.height="100%";const s=parseFloat(this.getAttribute("init-lat"))||47.816,n=parseFloat(this.getAttribute("init-lng"))||16.25,o=parseInt(this.getAttribute("zoom"))||14;this.style.display="block",g(this,m,S(["maps"]).then(({Map:a})=>{this.map=new a(i,{center:{lat:s,lng:n},zoom:o,mapId:"location-map",streetViewControl:!1}),this.map.addListener("rightclick",l=>{this.dispatchEvent(new CustomEvent("right-click",{detail:{lat:l.latLng.lat(),lng:l.latLng.lng()}}))}),this.bounds=new google.maps.LatLngBounds}).catch(console.error))}async setMarker(t,i=!1,s={}){await I(this,m);const{AdvancedMarkerElement:n,PinElement:o}=await S(["marker"]),a=new o({...s}),l=new n({position:t,map:this.map,gmpDraggable:i,content:a.element});return l.pin=a,this.markers.push(l),this.bounds??(this.bounds=new google.maps.LatLngBounds),this.bounds.extend(t),this.markers.length>1&&this.map.fitBounds(this.bounds),this.markers.length===1&&this.map.setCenter(t),l}panTo(t,i={}){this.map&&(this.map.panTo(t),i.keepZoom||this.map.setZoom(20))}}m=new WeakMap;customElements.define("google-map",D);var u;const P=class P extends HTMLElement{constructor(){super(...arguments);M(this,u);this.marker=null,this.infoWindow=null,g(this,u,null)}async connectedCallback(){let t=this.closest("google-map");for(;!t;)await new Promise(i=>setTimeout(i,100)),t=this.closest("google-map")}attributeChangedCallback(){if(!this.parentElement)return;const t=this.position;isNaN(t.lat)||isNaN(t.lng)||this.updateMarker(t).catch(console.error)}async updateMarker(t){this.marker=await this.getOrCreateMarker(t);try{this.marker&&this.hasAttribute("pin-options")&&Object.assign(this.marker.pin,JSON.parse(this.getAttribute("pin-options")))}catch(i){console.error("invalid pin-options",i)}}async getOrCreateMarker(t){if(I(this,u)&&await I(this,u),!this.marker){const i=this.closest("google-map");if(!i)return;await g(this,u,i.setMarker(t,this.getAttribute("draggable")==="true").then(async s=>{const{InfoWindow:n}=await S(["maps"]),o=this.querySelector('slot[name="info-window"]');o&&(o.style.display="none");const a=this.querySelector('slot[name="info-window-title"]');a&&(a.style.display="none");const l=o==null?void 0:o.innerHTML,c=(a==null?void 0:a.innerHTML)||void 0;let h;return c&&(h=document.createElement("div"),h.innerHTML=c),l&&(this.infoWindow=new n({content:l,headerContent:h}),s.addListener("click",()=>{this.openInfoWindow()})),s.addListener("dragend",()=>{this.dispatchEvent(new CustomEvent("change",{detail:this.marker.position})),queueMicrotask(()=>this.marker.position=this.position)}),s}).then(s=>(this.marker=s,s)).finally(()=>g(this,u,null)))}return this.marker.position=t,this.marker}get position(){return{lat:parseFloat(this.getAttribute("lat")),lng:parseFloat(this.getAttribute("lng"))}}openInfoWindow(){this.infoWindow&&this.marker&&this.infoWindow.open(this.marker.map,this.marker)}};u=new WeakMap,P.observedAttributes=["lat","lng","pin-options"];let L=P;customElements.define("google-map-marker",L);exports.GoogleMap=D;exports.GoogleMapMarker=L;exports.load=S;
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
var j = (r) => {
|
|
2
|
+
throw TypeError(r);
|
|
3
|
+
};
|
|
4
|
+
var K = (r, t, e) => t.has(r) || j("Cannot " + e);
|
|
5
|
+
var I = (r, t, e) => (K(r, t, "read from private field"), e ? e.call(r) : t.get(r)), A = (r, t, e) => t.has(r) ? j("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), g = (r, t, e, i) => (K(r, t, "write to private field"), i ? i.call(r, e) : t.set(r, e), e);
|
|
6
|
+
function $(r, t, e, i) {
|
|
7
|
+
function s(n) {
|
|
8
|
+
return n instanceof e ? n : new e(function(o) {
|
|
9
|
+
o(n);
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
return new (e || (e = Promise))(function(n, o) {
|
|
13
|
+
function a(h) {
|
|
14
|
+
try {
|
|
15
|
+
c(i.next(h));
|
|
16
|
+
} catch (p) {
|
|
17
|
+
o(p);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function l(h) {
|
|
21
|
+
try {
|
|
22
|
+
c(i.throw(h));
|
|
23
|
+
} catch (p) {
|
|
24
|
+
o(p);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function c(h) {
|
|
28
|
+
h.done ? n(h.value) : s(h.value).then(a, l);
|
|
29
|
+
}
|
|
30
|
+
c((i = i.apply(r, [])).next());
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function N(r) {
|
|
34
|
+
return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r;
|
|
35
|
+
}
|
|
36
|
+
var C, T;
|
|
37
|
+
function U() {
|
|
38
|
+
return T || (T = 1, C = function r(t, e) {
|
|
39
|
+
if (t === e) return !0;
|
|
40
|
+
if (t && e && typeof t == "object" && typeof e == "object") {
|
|
41
|
+
if (t.constructor !== e.constructor) return !1;
|
|
42
|
+
var i, s, n;
|
|
43
|
+
if (Array.isArray(t)) {
|
|
44
|
+
if (i = t.length, i != e.length) return !1;
|
|
45
|
+
for (s = i; s-- !== 0; )
|
|
46
|
+
if (!r(t[s], e[s])) return !1;
|
|
47
|
+
return !0;
|
|
48
|
+
}
|
|
49
|
+
if (t.constructor === RegExp) return t.source === e.source && t.flags === e.flags;
|
|
50
|
+
if (t.valueOf !== Object.prototype.valueOf) return t.valueOf() === e.valueOf();
|
|
51
|
+
if (t.toString !== Object.prototype.toString) return t.toString() === e.toString();
|
|
52
|
+
if (n = Object.keys(t), i = n.length, i !== Object.keys(e).length) return !1;
|
|
53
|
+
for (s = i; s-- !== 0; )
|
|
54
|
+
if (!Object.prototype.hasOwnProperty.call(e, n[s])) return !1;
|
|
55
|
+
for (s = i; s-- !== 0; ) {
|
|
56
|
+
var o = n[s];
|
|
57
|
+
if (!r(t[o], e[o])) return !1;
|
|
58
|
+
}
|
|
59
|
+
return !0;
|
|
60
|
+
}
|
|
61
|
+
return t !== t && e !== e;
|
|
62
|
+
}), C;
|
|
63
|
+
}
|
|
64
|
+
var x = U(), G = /* @__PURE__ */ N(x);
|
|
65
|
+
const _ = "__googleMapsScriptId";
|
|
66
|
+
var f;
|
|
67
|
+
(function(r) {
|
|
68
|
+
r[r.INITIALIZED = 0] = "INITIALIZED", r[r.LOADING = 1] = "LOADING", r[r.SUCCESS = 2] = "SUCCESS", r[r.FAILURE = 3] = "FAILURE";
|
|
69
|
+
})(f || (f = {}));
|
|
70
|
+
class d {
|
|
71
|
+
/**
|
|
72
|
+
* Creates an instance of Loader using [[LoaderOptions]]. No defaults are set
|
|
73
|
+
* using this library, instead the defaults are set by the Google Maps
|
|
74
|
+
* JavaScript API server.
|
|
75
|
+
*
|
|
76
|
+
* ```
|
|
77
|
+
* const loader = Loader({apiKey, version: 'weekly', libraries: ['places']});
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
constructor({ apiKey: t, authReferrerPolicy: e, channel: i, client: s, id: n = _, language: o, libraries: a = [], mapIds: l, nonce: c, region: h, retries: p = 3, url: E = "https://maps.googleapis.com/maps/api/js", version: w }) {
|
|
81
|
+
if (this.callbacks = [], this.done = !1, this.loading = !1, this.errors = [], this.apiKey = t, this.authReferrerPolicy = e, this.channel = i, this.client = s, this.id = n || _, this.language = o, this.libraries = a, this.mapIds = l, this.nonce = c, this.region = h, this.retries = p, this.url = E, this.version = w, d.instance) {
|
|
82
|
+
if (!G(this.options, d.instance.options))
|
|
83
|
+
throw new Error(`Loader must not be called again with different options. ${JSON.stringify(this.options)} !== ${JSON.stringify(d.instance.options)}`);
|
|
84
|
+
return d.instance;
|
|
85
|
+
}
|
|
86
|
+
d.instance = this;
|
|
87
|
+
}
|
|
88
|
+
get options() {
|
|
89
|
+
return {
|
|
90
|
+
version: this.version,
|
|
91
|
+
apiKey: this.apiKey,
|
|
92
|
+
channel: this.channel,
|
|
93
|
+
client: this.client,
|
|
94
|
+
id: this.id,
|
|
95
|
+
libraries: this.libraries,
|
|
96
|
+
language: this.language,
|
|
97
|
+
region: this.region,
|
|
98
|
+
mapIds: this.mapIds,
|
|
99
|
+
nonce: this.nonce,
|
|
100
|
+
url: this.url,
|
|
101
|
+
authReferrerPolicy: this.authReferrerPolicy
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
get status() {
|
|
105
|
+
return this.errors.length ? f.FAILURE : this.done ? f.SUCCESS : this.loading ? f.LOADING : f.INITIALIZED;
|
|
106
|
+
}
|
|
107
|
+
get failed() {
|
|
108
|
+
return this.done && !this.loading && this.errors.length >= this.retries + 1;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* CreateUrl returns the Google Maps JavaScript API script url given the [[LoaderOptions]].
|
|
112
|
+
*
|
|
113
|
+
* @ignore
|
|
114
|
+
* @deprecated
|
|
115
|
+
*/
|
|
116
|
+
createUrl() {
|
|
117
|
+
let t = this.url;
|
|
118
|
+
return t += "?callback=__googleMapsCallback&loading=async", this.apiKey && (t += `&key=${this.apiKey}`), this.channel && (t += `&channel=${this.channel}`), this.client && (t += `&client=${this.client}`), this.libraries.length > 0 && (t += `&libraries=${this.libraries.join(",")}`), this.language && (t += `&language=${this.language}`), this.region && (t += `®ion=${this.region}`), this.version && (t += `&v=${this.version}`), this.mapIds && (t += `&map_ids=${this.mapIds.join(",")}`), this.authReferrerPolicy && (t += `&auth_referrer_policy=${this.authReferrerPolicy}`), t;
|
|
119
|
+
}
|
|
120
|
+
deleteScript() {
|
|
121
|
+
const t = document.getElementById(this.id);
|
|
122
|
+
t && t.remove();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Load the Google Maps JavaScript API script and return a Promise.
|
|
126
|
+
* @deprecated, use importLibrary() instead.
|
|
127
|
+
*/
|
|
128
|
+
load() {
|
|
129
|
+
return this.loadPromise();
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Load the Google Maps JavaScript API script and return a Promise.
|
|
133
|
+
*
|
|
134
|
+
* @ignore
|
|
135
|
+
* @deprecated, use importLibrary() instead.
|
|
136
|
+
*/
|
|
137
|
+
loadPromise() {
|
|
138
|
+
return new Promise((t, e) => {
|
|
139
|
+
this.loadCallback((i) => {
|
|
140
|
+
i ? e(i.error) : t(window.google);
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
importLibrary(t) {
|
|
145
|
+
return this.execute(), google.maps.importLibrary(t);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Load the Google Maps JavaScript API script with a callback.
|
|
149
|
+
* @deprecated, use importLibrary() instead.
|
|
150
|
+
*/
|
|
151
|
+
loadCallback(t) {
|
|
152
|
+
this.callbacks.push(t), this.execute();
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Set the script on document.
|
|
156
|
+
*/
|
|
157
|
+
setScript() {
|
|
158
|
+
var t, e;
|
|
159
|
+
if (document.getElementById(this.id)) {
|
|
160
|
+
this.callback();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const i = {
|
|
164
|
+
key: this.apiKey,
|
|
165
|
+
channel: this.channel,
|
|
166
|
+
client: this.client,
|
|
167
|
+
libraries: this.libraries.length && this.libraries,
|
|
168
|
+
v: this.version,
|
|
169
|
+
mapIds: this.mapIds,
|
|
170
|
+
language: this.language,
|
|
171
|
+
region: this.region,
|
|
172
|
+
authReferrerPolicy: this.authReferrerPolicy
|
|
173
|
+
};
|
|
174
|
+
Object.keys(i).forEach(
|
|
175
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
176
|
+
(n) => !i[n] && delete i[n]
|
|
177
|
+
), !((e = (t = window == null ? void 0 : window.google) === null || t === void 0 ? void 0 : t.maps) === null || e === void 0) && e.importLibrary || ((n) => {
|
|
178
|
+
let o, a, l, c = "The Google Maps JavaScript API", h = "google", p = "importLibrary", E = "__ib__", w = document, y = window;
|
|
179
|
+
y = y[h] || (y[h] = {});
|
|
180
|
+
const b = y.maps || (y.maps = {}), R = /* @__PURE__ */ new Set(), k = new URLSearchParams(), D = () => (
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
o || (o = new Promise((v, S) => $(this, void 0, void 0, function* () {
|
|
183
|
+
var L;
|
|
184
|
+
yield a = w.createElement("script"), a.id = this.id, k.set("libraries", [...R] + "");
|
|
185
|
+
for (l in n)
|
|
186
|
+
k.set(l.replace(/[A-Z]/g, (F) => "_" + F[0].toLowerCase()), n[l]);
|
|
187
|
+
k.set("callback", h + ".maps." + E), a.src = this.url + "?" + k, b[E] = v, a.onerror = () => o = S(Error(c + " could not load.")), a.nonce = this.nonce || ((L = w.querySelector("script[nonce]")) === null || L === void 0 ? void 0 : L.nonce) || "", w.head.append(a);
|
|
188
|
+
})))
|
|
189
|
+
);
|
|
190
|
+
b[p] ? console.warn(c + " only loads once. Ignoring:", n) : b[p] = (v, ...S) => R.add(v) && D().then(() => b[p](v, ...S));
|
|
191
|
+
})(i);
|
|
192
|
+
const s = this.libraries.map((n) => this.importLibrary(n));
|
|
193
|
+
s.length || s.push(this.importLibrary("core")), Promise.all(s).then(() => this.callback(), (n) => {
|
|
194
|
+
const o = new ErrorEvent("error", { error: n });
|
|
195
|
+
this.loadErrorCallback(o);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reset the loader state.
|
|
200
|
+
*/
|
|
201
|
+
reset() {
|
|
202
|
+
this.deleteScript(), this.done = !1, this.loading = !1, this.errors = [], this.onerrorEvent = null;
|
|
203
|
+
}
|
|
204
|
+
resetIfRetryingFailed() {
|
|
205
|
+
this.failed && this.reset();
|
|
206
|
+
}
|
|
207
|
+
loadErrorCallback(t) {
|
|
208
|
+
if (this.errors.push(t), this.errors.length <= this.retries) {
|
|
209
|
+
const e = this.errors.length * Math.pow(2, this.errors.length);
|
|
210
|
+
console.error(`Failed to load Google Maps script, retrying in ${e} ms.`), setTimeout(() => {
|
|
211
|
+
this.deleteScript(), this.setScript();
|
|
212
|
+
}, e);
|
|
213
|
+
} else
|
|
214
|
+
this.onerrorEvent = t, this.callback();
|
|
215
|
+
}
|
|
216
|
+
callback() {
|
|
217
|
+
this.done = !0, this.loading = !1, this.callbacks.forEach((t) => {
|
|
218
|
+
t(this.onerrorEvent);
|
|
219
|
+
}), this.callbacks = [];
|
|
220
|
+
}
|
|
221
|
+
execute() {
|
|
222
|
+
if (this.resetIfRetryingFailed(), !this.loading)
|
|
223
|
+
if (this.done)
|
|
224
|
+
this.callback();
|
|
225
|
+
else {
|
|
226
|
+
if (window.google && window.google.maps && window.google.maps.version) {
|
|
227
|
+
console.warn("Google Maps already loaded outside @googlemaps/js-api-loader. This may result in undesirable behavior as options and script parameters may not match."), this.callback();
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.loading = !0, this.setScript();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let q = null;
|
|
235
|
+
async function M(r = []) {
|
|
236
|
+
if (!window.SLEEK || !window.SLEEK.maps || !window.SLEEK.maps.googleMapsApiKey)
|
|
237
|
+
throw new Error("Google Maps API key is not configured. Please set window.SLEEK.maps.googleMapsApiKey.");
|
|
238
|
+
return q ?? (q = new d({
|
|
239
|
+
apiKey: window.SLEEK.maps.googleMapsApiKey
|
|
240
|
+
})), (await Promise.all(
|
|
241
|
+
r.map((e) => q.importLibrary(e))
|
|
242
|
+
)).reduce((e, i) => ({ ...e, ...i }), {});
|
|
243
|
+
}
|
|
244
|
+
var m;
|
|
245
|
+
class W extends HTMLElement {
|
|
246
|
+
constructor() {
|
|
247
|
+
super();
|
|
248
|
+
A(this, m);
|
|
249
|
+
this.map = null, g(this, m, void 0), this.markers = [], this.bounds = null;
|
|
250
|
+
}
|
|
251
|
+
connectedCallback() {
|
|
252
|
+
const e = this.attachShadow({ mode: "open" });
|
|
253
|
+
this.querySelectorAll("style").forEach((a) => {
|
|
254
|
+
e.appendChild(a);
|
|
255
|
+
});
|
|
256
|
+
const i = e.appendChild(document.createElement("main"));
|
|
257
|
+
i.style.display = "block", i.style.width = "100%", i.style.height = "100%";
|
|
258
|
+
const s = parseFloat(this.getAttribute("init-lat")) || 47.816, n = parseFloat(this.getAttribute("init-lng")) || 16.25, o = parseInt(this.getAttribute("zoom")) || 14;
|
|
259
|
+
this.style.display = "block", g(this, m, M(["maps"]).then(({ Map: a }) => {
|
|
260
|
+
this.map = new a(i, {
|
|
261
|
+
center: { lat: s, lng: n },
|
|
262
|
+
zoom: o,
|
|
263
|
+
mapId: "location-map",
|
|
264
|
+
streetViewControl: !1
|
|
265
|
+
}), this.map.addListener("rightclick", (l) => {
|
|
266
|
+
this.dispatchEvent(
|
|
267
|
+
new CustomEvent(
|
|
268
|
+
"right-click",
|
|
269
|
+
{ detail: { lat: l.latLng.lat(), lng: l.latLng.lng() } }
|
|
270
|
+
)
|
|
271
|
+
);
|
|
272
|
+
}), this.bounds = new google.maps.LatLngBounds();
|
|
273
|
+
}).catch(console.error));
|
|
274
|
+
}
|
|
275
|
+
async setMarker(e, i = !1, s = {}) {
|
|
276
|
+
await I(this, m);
|
|
277
|
+
const { AdvancedMarkerElement: n, PinElement: o } = await M(["marker"]), a = new o({ ...s }), l = new n({
|
|
278
|
+
position: e,
|
|
279
|
+
map: this.map,
|
|
280
|
+
gmpDraggable: i,
|
|
281
|
+
content: a.element
|
|
282
|
+
});
|
|
283
|
+
return l.pin = a, this.markers.push(l), this.bounds ?? (this.bounds = new google.maps.LatLngBounds()), this.bounds.extend(e), this.markers.length > 1 && this.map.fitBounds(this.bounds), this.markers.length === 1 && this.map.setCenter(e), l;
|
|
284
|
+
}
|
|
285
|
+
panTo(e, i = {}) {
|
|
286
|
+
this.map && (this.map.panTo(e), i.keepZoom || this.map.setZoom(20));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
m = new WeakMap();
|
|
290
|
+
customElements.define("google-map", W);
|
|
291
|
+
var u;
|
|
292
|
+
const P = class P extends HTMLElement {
|
|
293
|
+
constructor() {
|
|
294
|
+
super(...arguments);
|
|
295
|
+
A(this, u);
|
|
296
|
+
this.marker = null, this.infoWindow = null, g(this, u, null);
|
|
297
|
+
}
|
|
298
|
+
async connectedCallback() {
|
|
299
|
+
let e = this.closest("google-map");
|
|
300
|
+
for (; !e; )
|
|
301
|
+
await new Promise((i) => setTimeout(i, 100)), e = this.closest("google-map");
|
|
302
|
+
}
|
|
303
|
+
attributeChangedCallback() {
|
|
304
|
+
if (!this.parentElement) return;
|
|
305
|
+
const e = this.position;
|
|
306
|
+
isNaN(e.lat) || isNaN(e.lng) || this.updateMarker(e).catch(console.error);
|
|
307
|
+
}
|
|
308
|
+
async updateMarker(e) {
|
|
309
|
+
this.marker = await this.getOrCreateMarker(e);
|
|
310
|
+
try {
|
|
311
|
+
this.marker && this.hasAttribute("pin-options") && Object.assign(this.marker.pin, JSON.parse(this.getAttribute("pin-options")));
|
|
312
|
+
} catch (i) {
|
|
313
|
+
console.error("invalid pin-options", i);
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async getOrCreateMarker(e) {
|
|
317
|
+
if (I(this, u) && await I(this, u), !this.marker) {
|
|
318
|
+
const i = this.closest("google-map");
|
|
319
|
+
if (!i) return;
|
|
320
|
+
await g(this, u, i.setMarker(e, this.getAttribute("draggable") === "true").then(async (s) => {
|
|
321
|
+
const { InfoWindow: n } = await M(["maps"]), o = this.querySelector('slot[name="info-window"]');
|
|
322
|
+
o && (o.style.display = "none");
|
|
323
|
+
const a = this.querySelector('slot[name="info-window-title"]');
|
|
324
|
+
a && (a.style.display = "none");
|
|
325
|
+
const l = o == null ? void 0 : o.innerHTML, c = (a == null ? void 0 : a.innerHTML) || void 0;
|
|
326
|
+
let h;
|
|
327
|
+
return c && (h = document.createElement("div"), h.innerHTML = c), l && (this.infoWindow = new n({
|
|
328
|
+
content: l,
|
|
329
|
+
headerContent: h
|
|
330
|
+
}), s.addListener("click", () => {
|
|
331
|
+
this.openInfoWindow();
|
|
332
|
+
})), s.addListener("dragend", () => {
|
|
333
|
+
this.dispatchEvent(new CustomEvent("change", { detail: this.marker.position })), queueMicrotask(() => this.marker.position = this.position);
|
|
334
|
+
}), s;
|
|
335
|
+
}).then((s) => (this.marker = s, s)).finally(() => g(this, u, null)));
|
|
336
|
+
}
|
|
337
|
+
return this.marker.position = e, this.marker;
|
|
338
|
+
}
|
|
339
|
+
get position() {
|
|
340
|
+
return {
|
|
341
|
+
lat: parseFloat(this.getAttribute("lat")),
|
|
342
|
+
lng: parseFloat(this.getAttribute("lng"))
|
|
343
|
+
};
|
|
344
|
+
}
|
|
345
|
+
openInfoWindow() {
|
|
346
|
+
this.infoWindow && this.marker && this.infoWindow.open(this.marker.map, this.marker);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
u = new WeakMap(), P.observedAttributes = ["lat", "lng", "pin-options"];
|
|
350
|
+
let O = P;
|
|
351
|
+
customElements.define("google-map-marker", O);
|
|
352
|
+
export {
|
|
353
|
+
W as GoogleMap,
|
|
354
|
+
O as GoogleMapMarker,
|
|
355
|
+
M as load
|
|
356
|
+
};
|
package/dist/main.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export * from './utils.js';
|
|
2
|
+
export declare function setup({ maps }: {
|
|
3
|
+
maps: any;
|
|
4
|
+
}): void;
|
|
2
5
|
export declare function loadCustomElements(mapping: CustomElementLoaderMapping, { resolveTagName, watch, }?: {
|
|
3
6
|
resolveTagName?: (key: string) => string;
|
|
4
7
|
watch?: boolean;
|
package/dist/main.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,0BAA0B,EACnC,EACE,cAA6B,EAC7B,KAAY,GACb,GAAE;IAAE,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACpE,MAAM,CAmER;AAED,KAAK,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AACxE,KAAK,MAAM,GAAG;IACZ,gBAAgB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACjD,EAAE,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACnC,mBAAmB,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAA;IACvD,GAAG,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAA;CACxC,CAAA"}
|
|
1
|
+
{"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA;AAE1B,wBAAgB,KAAK,CAAC,EAAE,IAAI,EAAE,EAAE;IAAE,IAAI,EAAE,GAAG,CAAA;CAAE,QAG5C;AAED,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,0BAA0B,EACnC,EACE,cAA6B,EAC7B,KAAY,GACb,GAAE;IAAE,cAAc,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GACpE,MAAM,CAmER;AAED,KAAK,0BAA0B,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAA;AACxE,KAAK,MAAM,GAAG;IACZ,gBAAgB,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACjD,EAAE,EAAE,WAAW,CAAC,kBAAkB,CAAC,CAAA;IACnC,mBAAmB,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAA;IACvD,GAAG,EAAE,WAAW,CAAC,qBAAqB,CAAC,CAAA;CACxC,CAAA"}
|