@arenarium/maps-integration-google 1.0.2 → 1.0.3

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/main.d.ts CHANGED
@@ -1,197 +1,36 @@
1
- import * as v from "valibot";
2
-
3
- //#region ../../../2 - shared/dist/schemas-ChiG16AA.d.ts
4
-
5
- declare const mapCoordinatesSchema: v.ObjectSchema<{
6
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
7
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
8
- }, undefined>;
9
- declare const mapBoundsSchema: v.ObjectSchema<{
10
- readonly sw: v.ObjectSchema<{
11
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
12
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
13
- }, undefined>;
14
- readonly ne: v.ObjectSchema<{
15
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
16
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
17
- }, undefined>;
18
- }, undefined>;
19
- declare const mapViewportSchema: v.ObjectSchema<{
20
- readonly bounds: v.ObjectSchema<{
21
- readonly sw: v.ObjectSchema<{
22
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
23
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
24
- }, undefined>;
25
- readonly ne: v.ObjectSchema<{
26
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
27
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
28
- }, undefined>;
29
- }, undefined>;
30
- readonly center: v.ObjectSchema<{
31
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
32
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
33
- }, undefined>;
34
- readonly zoom: v.NumberSchema<undefined>;
35
- }, undefined>;
36
- declare const mapProviderParametersSchema: v.ObjectSchema<{
37
- readonly mapSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
38
- readonly zoomMin: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
39
- readonly zoomMax: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
40
- readonly zoomScale: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10, undefined>]>;
41
- }, undefined>;
42
- declare const mapProviderMarkerSchema: v.ObjectSchema<{
43
- readonly inserted: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.BooleanSchema<undefined>>]>;
44
- readonly insert: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.VoidSchema<undefined>>]>;
45
- readonly remove: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.VoidSchema<undefined>>]>;
46
- readonly update: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.NumberSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: number) => unknown, v.VoidSchema<undefined>>]>;
47
- }, undefined>;
48
- declare const mapProviderEventSchema: v.UnionSchema<[v.LiteralSchema<"idle", undefined>, v.LiteralSchema<"move", undefined>, v.LiteralSchema<"click", undefined>], undefined>;
49
- declare const mapProviderSchema: v.ObjectSchema<{
50
- readonly getParameters: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.ObjectSchema<{
51
- readonly mapSize: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>]>;
52
- readonly zoomMin: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
53
- readonly zoomMax: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>]>;
54
- readonly zoomScale: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 10, undefined>]>;
55
- }, undefined>>]>;
56
- readonly getContainer: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.CustomSchema<HTMLElement, v.ErrorMessage<v.CustomIssue> | undefined>>]>;
57
- readonly getZoom: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.NumberSchema<undefined>>]>;
58
- readonly getBounds: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.ObjectSchema<{
59
- readonly sw: v.ObjectSchema<{
60
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
61
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
62
- }, undefined>;
63
- readonly ne: v.ObjectSchema<{
64
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
65
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
66
- }, undefined>;
67
- }, undefined>>]>;
68
- readonly getCenter: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.ObjectSchema<{
69
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
70
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
71
- }, undefined>>]>;
72
- readonly getViewport: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.ObjectSchema<{
73
- readonly bounds: v.ObjectSchema<{
74
- readonly sw: v.ObjectSchema<{
75
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
76
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
77
- }, undefined>;
78
- readonly ne: v.ObjectSchema<{
79
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
80
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
81
- }, undefined>;
82
- }, undefined>;
83
- readonly center: v.ObjectSchema<{
84
- readonly lat: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>;
85
- readonly lng: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>;
86
- }, undefined>;
87
- readonly zoom: v.NumberSchema<undefined>;
88
- }, undefined>>]>;
89
- readonly panBy: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.NumberSchema<undefined>, v.NumberSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: number, args_1: number) => unknown, v.VoidSchema<undefined>>]>;
90
- readonly createMarker: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.CustomSchema<HTMLElement, v.ErrorMessage<v.CustomIssue> | undefined>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -90, undefined>, v.MaxValueAction<number, 90, undefined>]>, v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, -180, undefined>, v.MaxValueAction<number, 180, undefined>]>, v.NumberSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: HTMLElement, args_1: number, args_2: number, args_3: number) => unknown, v.ObjectSchema<{
91
- readonly inserted: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.BooleanSchema<undefined>>]>;
92
- readonly insert: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.VoidSchema<undefined>>]>;
93
- readonly remove: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[], undefined>>, v.ReturnsAction<() => unknown, v.VoidSchema<undefined>>]>;
94
- readonly update: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.NumberSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: number) => unknown, v.VoidSchema<undefined>>]>;
95
- }, undefined>>]>;
96
- readonly subscribe: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.UnionSchema<[v.LiteralSchema<"idle", undefined>, v.LiteralSchema<"move", undefined>, v.LiteralSchema<"click", undefined>], undefined>, v.FunctionSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: "idle" | "move" | "click", args_1: (...args: unknown[]) => unknown) => unknown, v.VoidSchema<undefined>>]>;
97
- readonly unsubscribe: v.SchemaWithPipe<readonly [v.FunctionSchema<undefined>, v.ArgsAction<(...args: unknown[]) => unknown, v.TupleSchema<[v.UnionSchema<[v.LiteralSchema<"idle", undefined>, v.LiteralSchema<"move", undefined>, v.LiteralSchema<"click", undefined>], undefined>, v.FunctionSchema<undefined>], undefined>>, v.ReturnsAction<(args_0: "idle" | "move" | "click", args_1: (...args: unknown[]) => unknown) => unknown, v.VoidSchema<undefined>>]>;
98
- }, undefined>;
99
- type MapCoordinates = v.InferOutput<typeof mapCoordinatesSchema>;
100
- type MapBounds = v.InferOutput<typeof mapBoundsSchema>;
101
- type MapViewport = v.InferOutput<typeof mapViewportSchema>;
102
- type MapProviderParameters = v.InferOutput<typeof mapProviderParametersSchema>;
103
- type MapProviderMarker = v.InferOutput<typeof mapProviderMarkerSchema>;
104
- type MapProviderEvent = v.InferOutput<typeof mapProviderEventSchema>;
105
- type MapProvider = v.InferOutput<typeof mapProviderSchema>;
106
- //#endregion
107
- //#region src/lib/provider.d.ts
1
+ import { MapProvider, MapProviderParameters, MapProviderMarker, MapProviderEvent, MapBounds, MapViewport, MapCoordinates } from "@arenarium/maps-core/schemas";
108
2
  interface GoogleMapsClass {
109
- new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
3
+ new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
110
4
  }
111
5
  interface GoogleMapsMarkerClass {
112
- new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
6
+ new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
113
7
  }
114
8
  interface GoogleMapsOptions extends google.maps.MapOptions {
115
- attribution?: boolean;
9
+ attribution?: boolean;
116
10
  }
117
11
  declare class GoogleMapsProvider implements MapProvider {
118
- private MapClass;
119
- private MapMarkerClass;
120
- private map;
121
- private options;
122
- private listeners;
123
- private attributionObserver;
124
- private attributionElement;
125
- constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions);
126
- private insertAttributionElement;
127
- private updateAttributionElement;
128
- getParameters(): MapProviderParameters;
129
- getMap(): google.maps.Map;
130
- getContainer(): HTMLElement;
131
- getZoom(): number;
132
- getCenter(): MapCoordinates;
133
- getBounds(): MapBounds;
134
- getViewport(): MapViewport;
135
- panBy(x: number, y: number): undefined;
136
- createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker;
137
- subscribe(event: MapProviderEvent, callback: () => void): void;
138
- unsubscribe(event: MapProviderEvent, callback: () => void): void;
12
+ private MapClass;
13
+ private MapMarkerClass;
14
+ private map;
15
+ private options;
16
+ private listeners;
17
+ private attributionObserver;
18
+ private attributionElement;
19
+ constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions);
20
+ private insertAttributionElement;
21
+ private updateAttributionElement;
22
+ getParameters(): MapProviderParameters;
23
+ getMap(): google.maps.Map;
24
+ getContainer(): HTMLElement;
25
+ getZoom(): number;
26
+ getCenter(): MapCoordinates;
27
+ getBounds(): MapBounds;
28
+ getViewport(): MapViewport;
29
+ panBy(x: number, y: number): undefined;
30
+ createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker;
31
+ subscribe(event: MapProviderEvent, callback: () => void): void;
32
+ unsubscribe(event: MapProviderEvent, callback: () => void): void;
139
33
  }
140
- //#endregion
141
- //#region src/lib/styles.d.ts
142
- declare const GoogleMapLightStyle: ({
143
- elementType: string;
144
- stylers: {
145
- visibility: string;
146
- }[];
147
- featureType?: undefined;
148
- } | {
149
- stylers: ({
150
- saturation: number;
151
- lightness?: undefined;
152
- } | {
153
- lightness: number;
154
- saturation?: undefined;
155
- })[];
156
- elementType?: undefined;
157
- featureType?: undefined;
158
- } | {
159
- featureType: string;
160
- stylers: {
161
- lightness: number;
162
- }[];
163
- elementType?: undefined;
164
- } | {
165
- featureType: string;
166
- elementType: string;
167
- stylers: {
168
- saturation: number;
169
- }[];
170
- })[];
171
- declare const GoogleMapDarkStyle: ({
172
- elementType: string;
173
- stylers: {
174
- visibility: string;
175
- }[];
176
- featureType?: undefined;
177
- } | {
178
- stylers: {
179
- saturation: number;
180
- }[];
181
- elementType?: undefined;
182
- featureType?: undefined;
183
- } | {
184
- elementType: string;
185
- stylers: {
186
- lightness: number;
187
- }[];
188
- featureType?: undefined;
189
- } | {
190
- featureType: string;
191
- elementType: string;
192
- stylers: {
193
- lightness: number;
194
- }[];
195
- })[];
196
- //#endregion
197
- export { GoogleMapDarkStyle, GoogleMapLightStyle, GoogleMapsProvider };
34
+ declare const GoogleMapLightStyle: google.maps.MapTypeStyle[];
35
+ declare const GoogleMapDarkStyle: google.maps.MapTypeStyle[];
36
+ export { GoogleMapsProvider, GoogleMapLightStyle, GoogleMapDarkStyle };
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- const e=()=>`<img src="https://arenarium.dev/favicon.svg" alt="Arenarium Maps" class="arenarium-maps-attribution-image" />`,t=()=>`<a href="https://arenarium.dev" target="_blank" class="arenarium-maps-attribution-link">${e()}<span>&nbsp;arenarium/maps</span></a>`;var n=class{constructor(e,t,n,r){this.listeners=new Set,this.MapClass=e,this.MapMarkerClass=t,this.options=r,this.map=new this.MapClass(n,{...r}),(r.attribution||r.attribution==null)&&(this.map.addListener(`idle`,()=>{this.attributionObserver||(this.attributionObserver=new MutationObserver((e,t)=>{this.insertAttributionElement(),this.attributionElement!=null&&(this.updateAttributionElement(),t.disconnect())}),this.attributionObserver.observe(n,{childList:!0,subtree:!0}))}),this.map.addListener(`bounds_changed`,()=>{this.updateAttributionElement()}))}insertAttributionElement(){let e=this.map.getDiv();if(e==null)return;let n=e.getElementsByClassName(`gmnoprint`)[0];if(n==null||n.parentElement==null)return;let r=n.cloneNode(!0),i=r.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);i!=null&&(i.title=``,i.innerHTML=t(),n.parentElement.insertBefore(r,n),this.attributionElement=i)}updateAttributionElement(){let e=this.map.getDiv();if(e==null)return;let t=this.attributionElement?.childNodes.item(0);if(t){t.style.height=`14px`,t.style.display=`inline-flex`,t.style.alignItems=`center`,t.style.gap=`1px`;let n=t.childNodes.item(0);n&&(n.style.height=`12px`,n.style.width=`auto`);let r=t.childNodes.item(1);r&&(r.style.display=e.clientWidth>500?`initial`:`none`,r.style.color=this.options.colorScheme==google.maps.ColorScheme.DARK?`#fff`:`#000`)}}getParameters(){return{mapSize:256,zoomMin:this.options.minZoom??0,zoomMax:this.options.maxZoom??24,zoomScale:10}}getMap(){return this.map}getContainer(){return this.map.getDiv()}getZoom(){return this.map.getZoom()??NaN}getCenter(){let e=this.map.getCenter();return e==null?{lat:NaN,lng:NaN}:{lat:e.lat(),lng:e.lng()}}getBounds(){let e=this.map.getBounds();if(e==null)return{sw:{lat:NaN,lng:NaN},ne:{lat:NaN,lng:NaN}};let t=e.getSouthWest(),n=e.getNorthEast();return{sw:{lat:t.lat(),lng:t.lng()},ne:{lat:n.lat(),lng:n.lng()}}}getViewport(){return{bounds:this.getBounds(),center:this.getCenter(),zoom:this.getZoom()}}panBy(e,t){this.map.panBy(e,t)}createMarker(e,t,n,r){let i=new this.MapMarkerClass({position:{lat:t,lng:n},content:e,zIndex:r});return{inserted:()=>i.map!=null&&i.map==this.map,insert:()=>i.map=this.map,remove:()=>i.map=void 0,update:e=>i.zIndex=e}}subscribe(e,t){let n=google.maps.event.addListener(this.map,e,t);this.listeners.add({id:n,event:e,callback:t})}unsubscribe(e,t){let n=this.listeners.values().find(n=>n.event==e&&n.callback==t);n!=null&&google.maps.event.removeListener(n.id)}};const r=[{elementType:`labels.icon`,stylers:[{visibility:`off`}]},{stylers:[{saturation:-100},{lightness:-10}]},{featureType:`landscape`,stylers:[{lightness:30}]},{featureType:`road`,elementType:`geometry`,stylers:[{saturation:-100}]}],i=[{elementType:`labels.icon`,stylers:[{visibility:`off`}]},{stylers:[{saturation:-100}]},{elementType:`geometry`,stylers:[{lightness:-45}]},{elementType:`labels.text.fill`,stylers:[{lightness:-100}]},{elementType:`labels.text.stroke`,stylers:[{lightness:-15}]},{featureType:`water`,elementType:`geometry`,stylers:[{lightness:-50}]}];export{i as GoogleMapDarkStyle,r as GoogleMapLightStyle,n as GoogleMapsProvider};
1
+ import{getAttributionHtml as S}from"@arenarium/maps-core/attribution";class M{MapClass;MapMarkerClass;map;options;listeners=new Set;attributionObserver;attributionElement;constructor(s,y,f,g){if(this.MapClass=s,this.MapMarkerClass=y,this.options=g,this.map=new this.MapClass(f,{...g}),g.attribution||g.attribution==null)this.map.addListener("idle",()=>{if(this.attributionObserver)return;this.attributionObserver=new MutationObserver((T,G)=>{if(this.insertAttributionElement(),this.attributionElement==null)return;this.updateAttributionElement(),G.disconnect()}),this.attributionObserver.observe(f,{childList:!0,subtree:!0})}),this.map.addListener("bounds_changed",()=>{this.updateAttributionElement()})}insertAttributionElement(){let s=this.map.getDiv();if(s==null)return;let y=s.getElementsByClassName("gmnoprint")[0];if(y==null)return;if(y.parentElement==null)return;let f=y.cloneNode(!0),g=f.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);if(g==null)return;g.title="",g.innerHTML=S(),y.parentElement.insertBefore(f,y),this.attributionElement=g}updateAttributionElement(){let s=this.map.getDiv();if(s==null)return;let y=this.attributionElement?.childNodes.item(0);if(y){y.style.height="14px",y.style.display="inline-flex",y.style.alignItems="center",y.style.gap="1px";let f=y.childNodes.item(0);if(f)f.style.height="12px",f.style.width="auto";let g=y.childNodes.item(1);if(g)g.style.display=s.clientWidth>500?"initial":"none",g.style.color=this.options.colorScheme==google.maps.ColorScheme.DARK?"#fff":"#000"}}getParameters(){return{mapSize:256,zoomMin:this.options.minZoom??0,zoomMax:this.options.maxZoom??24,zoomScale:10}}getMap(){return this.map}getContainer(){return this.map.getDiv()}getZoom(){return this.map.getZoom()??NaN}getCenter(){let s=this.map.getCenter();if(s==null)return{lat:NaN,lng:NaN};return{lat:s.lat(),lng:s.lng()}}getBounds(){let s=this.map.getBounds();if(s==null)return{sw:{lat:NaN,lng:NaN},ne:{lat:NaN,lng:NaN}};let y=s.getSouthWest(),f=s.getNorthEast();return{sw:{lat:y.lat(),lng:y.lng()},ne:{lat:f.lat(),lng:f.lng()}}}getViewport(){return{bounds:this.getBounds(),center:this.getCenter(),zoom:this.getZoom()}}panBy(s,y){this.map.panBy(s,y)}createMarker(s,y,f,g){let T=new this.MapMarkerClass({position:{lat:y,lng:f},content:s,zIndex:g});return{inserted:()=>T.map!=null&&T.map==this.map,insert:()=>T.map=this.map,remove:()=>T.map=void 0,update:(G)=>T.zIndex=G}}subscribe(s,y){let f=google.maps.event.addListener(this.map,s,y);this.listeners.add({id:f,event:s,callback:y})}unsubscribe(s,y){let f=this.listeners.values().find((g)=>g.event==s&&g.callback==y);if(f==null)return;google.maps.event.removeListener(f.id)}}var D=[{elementType:"labels.icon",stylers:[{visibility:"off"}]},{stylers:[{saturation:-100},{lightness:-10}]},{featureType:"landscape",stylers:[{lightness:30}]},{featureType:"road",elementType:"geometry",stylers:[{saturation:-100}]}],P=[{elementType:"labels.icon",stylers:[{visibility:"off"}]},{stylers:[{saturation:-100}]},{elementType:"geometry",stylers:[{lightness:-45}]},{elementType:"labels.text.fill",stylers:[{lightness:-100}]},{elementType:"labels.text.stroke",stylers:[{lightness:-15}]},{featureType:"water",elementType:"geometry",stylers:[{lightness:-50}]}];export{M as GoogleMapsProvider,D as GoogleMapLightStyle,P as GoogleMapDarkStyle};
package/package.json CHANGED
@@ -1,41 +1,44 @@
1
1
  {
2
- "name": "@arenarium/maps-integration-google",
3
- "version": "1.0.2",
4
- "license": "MIT",
5
- "author": "arenarium",
6
- "description": "Integration with Google Maps for @arenarium/maps.",
7
- "homepage": "https://arenarium.dev",
8
- "keywords": [
9
- "arenarium",
10
- "maps",
11
- "google",
12
- "google maps"
13
- ],
14
- "type": "module",
15
- "main": "./dist/main.js",
16
- "module": "./dist/main.js",
17
- "types": "./dist/main.d.ts",
18
- "exports": {
19
- ".": {
20
- "types": "./dist/main.d.ts",
21
- "import": "./dist/main.js"
22
- }
23
- },
24
- "devDependencies": {
25
- "tsdown": "^0.17.0",
26
- "@arenarium/maps-shared": "1.0.0"
27
- },
28
- "peerDependencies": {
29
- "@googlemaps/js-api-loader": "^2.0.2",
30
- "@types/google.maps": "^3.58.1"
31
- },
32
- "dependencies": {
33
- "valibot": "^1.2.0"
34
- },
35
- "scripts": {
36
- "lib_google_build": "tsdown --minify",
37
- "lib_google_build_dev": "tsdown",
38
- "lib_google_patch": "pnpm version patch --no-git-tag-version",
39
- "lib_google_publish": "pnpm publish --access public"
40
- }
41
- }
2
+ "name": "@arenarium/maps-integration-google",
3
+ "description": "Integration with Google Maps for @arenarium/maps.",
4
+ "version": "1.0.3",
5
+ "type": "module",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/main.js",
10
+ "types": "./dist/main.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": {
14
+ "types": "./dist/main.d.ts",
15
+ "default": "./dist/main.js"
16
+ }
17
+ },
18
+ "./package.json": "./package.json"
19
+ },
20
+ "license": "MIT",
21
+ "author": "arenarium",
22
+ "homepage": "https://arenarium.dev",
23
+ "keywords": [
24
+ "arenarium",
25
+ "maps",
26
+ "google",
27
+ "google maps"
28
+ ],
29
+ "devDependencies": {
30
+ "bunup": "^0.16.10"
31
+ },
32
+ "peerDependencies": {
33
+ "@googlemaps/js-api-loader": "^2.0.2",
34
+ "@types/google.maps": "^3.58.1"
35
+ },
36
+ "dependencies": {
37
+ "@arenarium/maps-core": "1.0.2"
38
+ },
39
+ "scripts": {
40
+ "lib_google_build": "bunup",
41
+ "lib_google_patch": "bun pm version patch --no-git-tag-version",
42
+ "lib_google_publish": "bun publish --access public"
43
+ }
44
+ }
@@ -1,203 +0,0 @@
1
- import { getAttributionHtml } from '@arenarium/maps-shared/manager/attribution';
2
- import type {
3
- MapProvider,
4
- MapProviderParameters,
5
- MapProviderMarker,
6
- MapProviderEvent,
7
- MapBounds,
8
- MapViewport,
9
- MapCoordinates
10
- } from '@arenarium/maps-shared/schemas';
11
-
12
- interface GoogleMapsClass {
13
- new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
14
- }
15
-
16
- interface GoogleMapsMarkerClass {
17
- new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
18
- }
19
-
20
- interface GoogleMapsOptions extends google.maps.MapOptions {
21
- attribution?: boolean;
22
- }
23
-
24
- interface GoogleMapsEventListener {
25
- id: google.maps.MapsEventListener;
26
- event: MapProviderEvent;
27
- callback: () => void;
28
- }
29
-
30
- export class GoogleMapsProvider implements MapProvider {
31
- private MapClass: GoogleMapsClass;
32
- private MapMarkerClass: GoogleMapsMarkerClass;
33
-
34
- private map: google.maps.Map;
35
- private options: google.maps.MapOptions;
36
-
37
- private listeners = new Set<GoogleMapsEventListener>();
38
-
39
- private attributionObserver: MutationObserver | undefined;
40
- private attributionElement: HTMLElement | undefined;
41
-
42
- constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions) {
43
- this.MapClass = mapClass;
44
- this.MapMarkerClass = mapMarkerClass;
45
-
46
- this.options = options;
47
- this.map = new this.MapClass(container, {
48
- ...options
49
- });
50
-
51
- if (options.attribution || options.attribution == undefined) {
52
- // Add attribution element
53
- this.map.addListener('idle', () => {
54
- if (this.attributionObserver) return;
55
-
56
- this.attributionObserver = new MutationObserver((_, observer) => {
57
- // Try to insert attribution element
58
- this.insertAttributionElement();
59
- // If insertion failed, return
60
- if (this.attributionElement == undefined) return;
61
- // Update attribution element
62
- this.updateAttributionElement();
63
- // Disconnect observer
64
- observer.disconnect();
65
- });
66
- this.attributionObserver.observe(container, { childList: true, subtree: true });
67
- });
68
-
69
- this.map.addListener('bounds_changed', () => {
70
- // Update attribution element
71
- this.updateAttributionElement();
72
- });
73
- }
74
- }
75
-
76
- private insertAttributionElement() {
77
- // Get map container
78
- const container = this.map.getDiv();
79
- if (container == undefined) return;
80
-
81
- // Find bottom right attribution elements first child
82
- const attributionElementsFirstChild = container.getElementsByClassName('gmnoprint')[0];
83
- if (attributionElementsFirstChild == undefined) return;
84
- if (attributionElementsFirstChild.parentElement == undefined) return;
85
-
86
- // Clone attribution element
87
- const attributionWrapper = attributionElementsFirstChild.cloneNode(true) as HTMLElement;
88
-
89
- // Find attribution wrapper target child
90
- const attributionWrapperTargetChild = attributionWrapper.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0) as HTMLElement;
91
- if (attributionWrapperTargetChild == undefined) return;
92
-
93
- // Set attribution wrapper target child inner HTML
94
- attributionWrapperTargetChild.title = '';
95
- attributionWrapperTargetChild.innerHTML = getAttributionHtml();
96
-
97
- // Insert attribution wrapper before attribution elements first child
98
- attributionElementsFirstChild.parentElement.insertBefore(attributionWrapper, attributionElementsFirstChild);
99
-
100
- // Assign attribution element
101
- this.attributionElement = attributionWrapperTargetChild;
102
- }
103
-
104
- private updateAttributionElement() {
105
- // Get map container
106
- const container = this.map.getDiv();
107
- if (container == undefined) return;
108
-
109
- // Get attribution element
110
- const attributionElementLink = this.attributionElement?.childNodes.item(0) as HTMLElement;
111
- if (attributionElementLink) {
112
- attributionElementLink.style.height = '14px';
113
- attributionElementLink.style.display = 'inline-flex';
114
- attributionElementLink.style.alignItems = 'center';
115
- attributionElementLink.style.gap = '1px';
116
-
117
- // Get attribution element image
118
- const attributionElementImage = attributionElementLink.childNodes.item(0) as HTMLElement;
119
- if (attributionElementImage) {
120
- attributionElementImage.style.height = '12px';
121
- attributionElementImage.style.width = 'auto';
122
- }
123
-
124
- // Get attribution element span
125
- const attributionElementSpan = attributionElementLink.childNodes.item(1) as HTMLElement;
126
- if (attributionElementSpan) {
127
- // Set attribution element span display
128
- attributionElementSpan.style.display = container.clientWidth > 500 ? 'initial' : 'none';
129
- attributionElementSpan.style.color = this.options.colorScheme == google.maps.ColorScheme.DARK ? '#fff' : '#000';
130
- }
131
- }
132
- }
133
-
134
- public getParameters(): MapProviderParameters {
135
- return {
136
- mapSize: 256,
137
- zoomMin: this.options.minZoom ?? 0,
138
- zoomMax: this.options.maxZoom ?? 24,
139
- zoomScale: 10
140
- };
141
- }
142
-
143
- public getMap(): google.maps.Map {
144
- return this.map;
145
- }
146
-
147
- public getContainer(): HTMLElement {
148
- return this.map.getDiv();
149
- }
150
-
151
- public getZoom(): number {
152
- return this.map.getZoom() ?? NaN;
153
- }
154
-
155
- public getCenter(): MapCoordinates {
156
- const center = this.map.getCenter();
157
- if (center == undefined) return { lat: NaN, lng: NaN };
158
-
159
- return { lat: center.lat(), lng: center.lng() };
160
- }
161
-
162
- public getBounds(): MapBounds {
163
- const bounds = this.map.getBounds();
164
- if (bounds == undefined) return { sw: { lat: NaN, lng: NaN }, ne: { lat: NaN, lng: NaN } };
165
-
166
- const sw = bounds.getSouthWest();
167
- const ne = bounds.getNorthEast();
168
- return { sw: { lat: sw.lat(), lng: sw.lng() }, ne: { lat: ne.lat(), lng: ne.lng() } };
169
- }
170
-
171
- public getViewport(): MapViewport {
172
- return {
173
- bounds: this.getBounds(),
174
- center: this.getCenter(),
175
- zoom: this.getZoom()
176
- };
177
- }
178
-
179
- public panBy(x: number, y: number): undefined {
180
- this.map.panBy(x, y);
181
- }
182
-
183
- public createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker {
184
- const marker = new this.MapMarkerClass({ position: { lat, lng }, content: element, zIndex });
185
- return {
186
- inserted: () => marker.map != undefined && marker.map == this.map,
187
- insert: () => (marker.map = this.map),
188
- remove: () => (marker.map = undefined),
189
- update: (zIndex: number) => (marker.zIndex = zIndex)
190
- };
191
- }
192
-
193
- public subscribe(event: MapProviderEvent, callback: () => void) {
194
- const id = google.maps.event.addListener(this.map, event, callback);
195
- this.listeners.add({ id, event, callback });
196
- }
197
-
198
- public unsubscribe(event: MapProviderEvent, callback: () => void) {
199
- const listener = this.listeners.values().find((l) => l.event == event && l.callback == callback);
200
- if (listener == undefined) return;
201
- google.maps.event.removeListener(listener.id);
202
- }
203
- }
package/src/lib/styles.ts DELETED
@@ -1,88 +0,0 @@
1
- export const GoogleMapLightStyle = [
2
- {
3
- elementType: 'labels.icon',
4
- stylers: [
5
- {
6
- visibility: 'off'
7
- }
8
- ]
9
- },
10
- {
11
- stylers: [
12
- {
13
- saturation: -100
14
- },
15
- {
16
- lightness: -10
17
- }
18
- ]
19
- },
20
- {
21
- featureType: 'landscape',
22
- stylers: [
23
- {
24
- lightness: 30
25
- }
26
- ]
27
- },
28
- {
29
- featureType: 'road',
30
- elementType: 'geometry',
31
- stylers: [
32
- {
33
- saturation: -100
34
- }
35
- ]
36
- }
37
- ];
38
-
39
- export const GoogleMapDarkStyle = [
40
- {
41
- elementType: 'labels.icon',
42
- stylers: [
43
- {
44
- visibility: 'off'
45
- }
46
- ]
47
- },
48
- {
49
- stylers: [
50
- {
51
- saturation: -100
52
- }
53
- ]
54
- },
55
- {
56
- elementType: 'geometry',
57
- stylers: [
58
- {
59
- lightness: -45
60
- }
61
- ]
62
- },
63
- {
64
- elementType: 'labels.text.fill',
65
- stylers: [
66
- {
67
- lightness: -100
68
- }
69
- ]
70
- },
71
- {
72
- elementType: 'labels.text.stroke',
73
- stylers: [
74
- {
75
- lightness: -15
76
- }
77
- ]
78
- },
79
- {
80
- featureType: 'water',
81
- elementType: 'geometry',
82
- stylers: [
83
- {
84
- lightness: -50
85
- }
86
- ]
87
- }
88
- ];
package/src/main.ts DELETED
@@ -1,3 +0,0 @@
1
- import { GoogleMapsProvider } from './lib/provider.js';
2
- import { GoogleMapDarkStyle, GoogleMapLightStyle } from './lib/styles.js';
3
- export { GoogleMapsProvider, GoogleMapDarkStyle, GoogleMapLightStyle };
package/tsconfig.json DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "checkJs": true,
5
- "esModuleInterop": true,
6
- "forceConsistentCasingInFileNames": true,
7
- "resolveJsonModule": true,
8
- "skipLibCheck": true,
9
- "sourceMap": true,
10
- "strict": true,
11
- "outDir": "dist",
12
- "declaration": true,
13
- "declarationDir": "dist",
14
- "emitDeclarationOnly": true,
15
- "module": "NodeNext",
16
- "moduleResolution": "NodeNext",
17
- "types": ["./node_modules/@types/google.maps/index.d.ts"]
18
- }
19
- }
package/tsdown.config.ts DELETED
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'tsdown';
2
-
3
- export default defineConfig({
4
- name: 'ArenariumMapsIntegrationGoogle',
5
- entry: ['./src/main.ts'],
6
- platform: 'browser',
7
- dts: {
8
- resolve: ['@arenarium/maps-shared']
9
- }
10
- });