@arenarium/maps-integration-google 1.0.1 → 1.0.2

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/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 arenarium.dev
3
+ Copyright (c) 2025 arenarium
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/main.d.ts CHANGED
@@ -1,93 +1,197 @@
1
- import { MapBounds } from '@arenarium/maps';
2
- import { MapProvider } from '@arenarium/maps';
3
- import { MapProviderMarker } from '@arenarium/maps';
4
- import { MapProviderParameters } from '@arenarium/maps';
5
-
6
- export declare const GoogleMapDarkStyle: ({
7
- elementType: string;
8
- stylers: {
9
- visibility: string;
10
- }[];
11
- featureType?: undefined;
12
- } | {
13
- stylers: {
14
- saturation: number;
15
- }[];
16
- elementType?: undefined;
17
- featureType?: undefined;
18
- } | {
19
- elementType: string;
20
- stylers: {
21
- lightness: number;
22
- }[];
23
- featureType?: undefined;
24
- } | {
25
- featureType: string;
26
- elementType: string;
27
- stylers: {
28
- lightness: number;
29
- }[];
30
- })[];
31
-
32
- export declare const GoogleMapLightStyle: ({
33
- elementType: string;
34
- stylers: {
35
- visibility: string;
36
- }[];
37
- featureType?: undefined;
38
- } | {
39
- stylers: ({
40
- saturation: number;
41
- lightness?: undefined;
42
- } | {
43
- lightness: number;
44
- saturation?: undefined;
45
- })[];
46
- elementType?: undefined;
47
- featureType?: undefined;
48
- } | {
49
- featureType: string;
50
- stylers: {
51
- lightness: number;
52
- }[];
53
- elementType?: undefined;
54
- } | {
55
- featureType: string;
56
- elementType: string;
57
- stylers: {
58
- saturation: number;
59
- }[];
60
- })[];
61
-
62
- declare interface GoogleMapsClass {
63
- new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
64
- }
65
-
66
- declare interface GoogleMapsMarkerClass {
67
- new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
68
- }
69
-
70
- declare interface GoogleMapsOptions extends google.maps.MapOptions {
71
- attribution?: boolean;
72
- }
73
-
74
- export declare class GoogleMapsProvider implements MapProvider {
75
- private MapClass;
76
- private MapMarkerClass;
77
- private map;
78
- private options;
79
- private attributionObserver;
80
- private attributionElement;
81
- constructor(mapClass: GoogleMapsClass, mapMarkerClass: GoogleMapsMarkerClass, container: HTMLElement, options: GoogleMapsOptions);
82
- private insertAttributionElement;
83
- private updateAttributionElement;
84
- getParameters(): MapProviderParameters;
85
- getMap(): google.maps.Map;
86
- getContainer(): HTMLElement;
87
- getZoom(): number;
88
- getBounds(): MapBounds;
89
- panBy(x: number, y: number): undefined;
90
- createMarker(element: HTMLElement, lat: number, lng: number, zIndex: number): MapProviderMarker;
91
- }
92
-
93
- export { }
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
108
+ interface GoogleMapsClass {
109
+ new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
110
+ }
111
+ interface GoogleMapsMarkerClass {
112
+ new (options: google.maps.marker.AdvancedMarkerElementOptions): google.maps.marker.AdvancedMarkerElement;
113
+ }
114
+ interface GoogleMapsOptions extends google.maps.MapOptions {
115
+ attribution?: boolean;
116
+ }
117
+ 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;
139
+ }
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 };
package/dist/main.js ADDED
@@ -0,0 +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};
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@arenarium/maps-integration-google",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "license": "MIT",
5
- "author": "arenarium.dev",
5
+ "author": "arenarium",
6
6
  "description": "Integration with Google Maps for @arenarium/maps.",
7
7
  "homepage": "https://arenarium.dev",
8
8
  "keywords": [
@@ -12,33 +12,29 @@
12
12
  "google maps"
13
13
  ],
14
14
  "type": "module",
15
- "main": "./dist/main.cjs.js",
16
- "module": "./dist/main.es.js",
17
- "svelte": "./dist/main.es.js",
15
+ "main": "./dist/main.js",
16
+ "module": "./dist/main.js",
18
17
  "types": "./dist/main.d.ts",
19
- "unpkg": "./dist/main.js",
20
- "jsdelivr": "./dist/main.js",
21
18
  "exports": {
22
19
  ".": {
23
20
  "types": "./dist/main.d.ts",
24
- "svelte": "./dist/main.es.js",
25
- "import": "./dist/main.es.js",
26
- "require": "./dist/main.cjs.js"
21
+ "import": "./dist/main.js"
27
22
  }
28
23
  },
29
24
  "devDependencies": {
30
- "@types/node": "^24.5.2",
31
- "vite": "^7.1.7",
32
- "vite-plugin-dts": "^4.5.4",
33
- "@arenarium/maps": "1.2.0",
25
+ "tsdown": "^0.17.0",
34
26
  "@arenarium/maps-shared": "1.0.0"
35
27
  },
36
28
  "peerDependencies": {
37
- "@googlemaps/js-api-loader": "^1.16.10",
29
+ "@googlemaps/js-api-loader": "^2.0.2",
38
30
  "@types/google.maps": "^3.58.1"
39
31
  },
32
+ "dependencies": {
33
+ "valibot": "^1.2.0"
34
+ },
40
35
  "scripts": {
41
- "lib_google_build": "vite build",
36
+ "lib_google_build": "tsdown --minify",
37
+ "lib_google_build_dev": "tsdown",
42
38
  "lib_google_patch": "pnpm version patch --no-git-tag-version",
43
39
  "lib_google_publish": "pnpm publish --access public"
44
40
  }
@@ -1,5 +1,13 @@
1
- import { getAttributionHtml } from '@arenarium/maps';
2
- import type { MapProvider, MapProviderParameters, MapProviderMarker, MapBounds } from '@arenarium/maps';
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';
3
11
 
4
12
  interface GoogleMapsClass {
5
13
  new (container: HTMLElement, options: google.maps.MapOptions): google.maps.Map;
@@ -13,6 +21,12 @@ interface GoogleMapsOptions extends google.maps.MapOptions {
13
21
  attribution?: boolean;
14
22
  }
15
23
 
24
+ interface GoogleMapsEventListener {
25
+ id: google.maps.MapsEventListener;
26
+ event: MapProviderEvent;
27
+ callback: () => void;
28
+ }
29
+
16
30
  export class GoogleMapsProvider implements MapProvider {
17
31
  private MapClass: GoogleMapsClass;
18
32
  private MapMarkerClass: GoogleMapsMarkerClass;
@@ -20,6 +34,8 @@ export class GoogleMapsProvider implements MapProvider {
20
34
  private map: google.maps.Map;
21
35
  private options: google.maps.MapOptions;
22
36
 
37
+ private listeners = new Set<GoogleMapsEventListener>();
38
+
23
39
  private attributionObserver: MutationObserver | undefined;
24
40
  private attributionElement: HTMLElement | undefined;
25
41
 
@@ -90,12 +106,29 @@ export class GoogleMapsProvider implements MapProvider {
90
106
  const container = this.map.getDiv();
91
107
  if (container == undefined) return;
92
108
 
93
- // Get attribution element span
94
- const attributionElementSpan = this.attributionElement?.childNodes.item(0)?.childNodes.item(1) as HTMLElement;
95
- if (attributionElementSpan == undefined) return;
96
-
97
- // Set attribution element span display
98
- attributionElementSpan.style.display = container.clientWidth > 500 ? 'initial' : 'none';
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
+ }
99
132
  }
100
133
 
101
134
  public getParameters(): MapProviderParameters {
@@ -119,6 +152,13 @@ export class GoogleMapsProvider implements MapProvider {
119
152
  return this.map.getZoom() ?? NaN;
120
153
  }
121
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
+
122
162
  public getBounds(): MapBounds {
123
163
  const bounds = this.map.getBounds();
124
164
  if (bounds == undefined) return { sw: { lat: NaN, lng: NaN }, ne: { lat: NaN, lng: NaN } };
@@ -128,6 +168,14 @@ export class GoogleMapsProvider implements MapProvider {
128
168
  return { sw: { lat: sw.lat(), lng: sw.lng() }, ne: { lat: ne.lat(), lng: ne.lng() } };
129
169
  }
130
170
 
171
+ public getViewport(): MapViewport {
172
+ return {
173
+ bounds: this.getBounds(),
174
+ center: this.getCenter(),
175
+ zoom: this.getZoom()
176
+ };
177
+ }
178
+
131
179
  public panBy(x: number, y: number): undefined {
132
180
  this.map.panBy(x, y);
133
181
  }
@@ -141,4 +189,15 @@ export class GoogleMapsProvider implements MapProvider {
141
189
  update: (zIndex: number) => (marker.zIndex = zIndex)
142
190
  };
143
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
+ }
144
203
  }
package/tsconfig.json CHANGED
@@ -14,6 +14,6 @@
14
14
  "emitDeclarationOnly": true,
15
15
  "module": "NodeNext",
16
16
  "moduleResolution": "NodeNext",
17
- "types": ["vite/client", "./node_modules/@types/google.maps/index.d.ts"]
17
+ "types": ["./node_modules/@types/google.maps/index.d.ts"]
18
18
  }
19
19
  }
@@ -0,0 +1,10 @@
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
+ });
package/dist/main.cjs.js DELETED
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d="5";typeof window<"u"&&((window.__svelte??={}).v??=new Set).add(d);var u;(l=>{function i(e,s,t){const n=e/2,a=s/2,r=Math.sqrt(n*n+a*a),h=Math.atan(a/n)*(180/Math.PI),o=t*(Math.PI/180);return t<180?t<90?t<h?{x:0,y:r*Math.sin(o)-a}:{x:r*Math.cos(o)-n,y:0}:t<180-h?{x:r*Math.cos(o)-n,y:0}:{x:-e,y:r*Math.sin(o)-a}:t<270?t<180+h?{x:-e,y:r*Math.sin(o)-a}:{x:r*Math.cos(o)-n,y:-s}:t<360-h?{x:r*Math.cos(o)-n,y:-s}:{x:0,y:r*Math.sin(o)-a}}l.getOffsets=i})(u||(u={}));var p;(l=>{async function i(s,t){const n=await fetch(s,t);if(!n.ok)throw new Error(n.statusText);return n.json()}l.get=i;async function e(s,t,n){const a=await fetch(s,{method:"POST",body:JSON.stringify(t),headers:{"Content-Type":"application/json",...n?.headers},...n});if(!a.ok)throw new Error(a.statusText);return a.json()}l.post=e})(p||(p={}));var m;(l=>{function i(r,h,o){return{x:s(h)*o,y:t(r)*o}}l.project=i;function e(r,h,o){return{lat:a(h/o),lng:n(r/o)}}l.unproject=e;function s(r){return(180+r)/360}function t(r){return(180-180/Math.PI*Math.log(Math.tan(Math.PI/4+r*Math.PI/360)))/360}function n(r){return r*360-180}function a(r){return 360/Math.PI*Math.atan(Math.exp((180-r*360)*Math.PI/180))-90}})(m||(m={}));var c;(l=>{l.COUNT=12,l.DEGREES=[0,30,60,90,120,150,180,210,240,270,300,330],l.DEGREES_DEFAULT=270})(c||(c={}));const y=()=>'<img src="https://arenarium.dev/favicon.svg" alt="Arenarium Maps" style="height: 1.25em; vertical-align: middle;" />',g=()=>`<a href="https://arenarium.dev" target="_blank" style="color: inherit;">${y()}<span>&nbsp;@arenarium/maps</span></a>`;class M{constructor(i,e,s,t){this.MapClass=i,this.MapMarkerClass=e,this.options=t,this.map=new this.MapClass(s,{...t}),(t.attribution||t.attribution==null)&&(this.map.addListener("idle",()=>{this.attributionObserver||(this.attributionObserver=new MutationObserver((n,a)=>{this.insertAttributionElement(),this.attributionElement!=null&&(this.updateAttributionElement(),a.disconnect())}),this.attributionObserver.observe(s,{childList:!0,subtree:!0}))}),this.map.addListener("bounds_changed",()=>{this.updateAttributionElement()}))}insertAttributionElement(){const i=this.map.getDiv();if(i==null)return;const e=i.getElementsByClassName("gmnoprint")[0];if(e==null||e.parentElement==null)return;const s=e.cloneNode(!0),t=s.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);t!=null&&(t.title="",t.innerHTML=g(),e.parentElement.insertBefore(s,e),this.attributionElement=t)}updateAttributionElement(){const i=this.map.getDiv();if(i==null)return;const e=this.attributionElement?.childNodes.item(0)?.childNodes.item(1);e!=null&&(e.style.display=i.clientWidth>500?"initial":"none")}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}getBounds(){const i=this.map.getBounds();if(i==null)return{sw:{lat:NaN,lng:NaN},ne:{lat:NaN,lng:NaN}};const e=i.getSouthWest(),s=i.getNorthEast();return{sw:{lat:e.lat(),lng:e.lng()},ne:{lat:s.lat(),lng:s.lng()}}}panBy(i,e){this.map.panBy(i,e)}createMarker(i,e,s,t){const n=new this.MapMarkerClass({position:{lat:e,lng:s},content:i,zIndex:t});return{inserted:()=>n.map!=null&&n.map==this.map,insert:()=>n.map=this.map,remove:()=>n.map=void 0,update:a=>n.zIndex=a}}}const f=[{elementType:"labels.icon",stylers:[{visibility:"off"}]},{stylers:[{saturation:-100},{lightness:-10}]},{featureType:"landscape",stylers:[{lightness:30}]},{featureType:"road",elementType:"geometry",stylers:[{saturation:-100}]}],b=[{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}]}];exports.GoogleMapDarkStyle=b;exports.GoogleMapLightStyle=f;exports.GoogleMapsProvider=M;
package/dist/main.es.js DELETED
@@ -1,243 +0,0 @@
1
- typeof window < "u" && ((window.__svelte ??= {}).v ??= /* @__PURE__ */ new Set()).add("5");
2
- var u;
3
- ((l) => {
4
- function i(e, s, t) {
5
- const n = e / 2, a = s / 2, r = Math.sqrt(n * n + a * a), h = Math.atan(a / n) * (180 / Math.PI), o = t * (Math.PI / 180);
6
- return t < 180 ? t < 90 ? t < h ? {
7
- x: 0,
8
- y: r * Math.sin(o) - a
9
- } : {
10
- x: r * Math.cos(o) - n,
11
- y: 0
12
- } : t < 180 - h ? {
13
- x: r * Math.cos(o) - n,
14
- y: 0
15
- } : {
16
- x: -e,
17
- y: r * Math.sin(o) - a
18
- } : t < 270 ? t < 180 + h ? {
19
- x: -e,
20
- y: r * Math.sin(o) - a
21
- } : {
22
- x: r * Math.cos(o) - n,
23
- y: -s
24
- } : t < 360 - h ? {
25
- x: r * Math.cos(o) - n,
26
- y: -s
27
- } : {
28
- x: 0,
29
- y: r * Math.sin(o) - a
30
- };
31
- }
32
- l.getOffsets = i;
33
- })(u || (u = {}));
34
- var m;
35
- ((l) => {
36
- async function i(s, t) {
37
- const n = await fetch(s, t);
38
- if (!n.ok) throw new Error(n.statusText);
39
- return n.json();
40
- }
41
- l.get = i;
42
- async function e(s, t, n) {
43
- const a = await fetch(s, {
44
- method: "POST",
45
- body: JSON.stringify(t),
46
- headers: {
47
- "Content-Type": "application/json",
48
- ...n?.headers
49
- },
50
- ...n
51
- });
52
- if (!a.ok) throw new Error(a.statusText);
53
- return a.json();
54
- }
55
- l.post = e;
56
- })(m || (m = {}));
57
- var p;
58
- ((l) => {
59
- function i(r, h, o) {
60
- return {
61
- x: s(h) * o,
62
- y: t(r) * o
63
- };
64
- }
65
- l.project = i;
66
- function e(r, h, o) {
67
- return {
68
- lat: a(h / o),
69
- lng: n(r / o)
70
- };
71
- }
72
- l.unproject = e;
73
- function s(r) {
74
- return (180 + r) / 360;
75
- }
76
- function t(r) {
77
- return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + r * Math.PI / 360))) / 360;
78
- }
79
- function n(r) {
80
- return r * 360 - 180;
81
- }
82
- function a(r) {
83
- return 360 / Math.PI * Math.atan(Math.exp((180 - r * 360) * Math.PI / 180)) - 90;
84
- }
85
- })(p || (p = {}));
86
- var c;
87
- ((l) => {
88
- l.COUNT = 12, l.DEGREES = [0, 30, 60, 90, 120, 150, 180, 210, 240, 270, 300, 330], l.DEGREES_DEFAULT = 270;
89
- })(c || (c = {}));
90
- const d = () => '<img src="https://arenarium.dev/favicon.svg" alt="Arenarium Maps" style="height: 1.25em; vertical-align: middle;" />', y = () => `<a href="https://arenarium.dev" target="_blank" style="color: inherit;">${d()}<span>&nbsp;@arenarium/maps</span></a>`;
91
- class g {
92
- constructor(i, e, s, t) {
93
- this.MapClass = i, this.MapMarkerClass = e, this.options = t, this.map = new this.MapClass(s, {
94
- ...t
95
- }), (t.attribution || t.attribution == null) && (this.map.addListener("idle", () => {
96
- this.attributionObserver || (this.attributionObserver = new MutationObserver((n, a) => {
97
- this.insertAttributionElement(), this.attributionElement != null && (this.updateAttributionElement(), a.disconnect());
98
- }), this.attributionObserver.observe(s, { childList: !0, subtree: !0 }));
99
- }), this.map.addListener("bounds_changed", () => {
100
- this.updateAttributionElement();
101
- }));
102
- }
103
- insertAttributionElement() {
104
- const i = this.map.getDiv();
105
- if (i == null) return;
106
- const e = i.getElementsByClassName("gmnoprint")[0];
107
- if (e == null || e.parentElement == null) return;
108
- const s = e.cloneNode(!0), t = s.childNodes.item(0)?.childNodes.item(1)?.childNodes.item(0);
109
- t != null && (t.title = "", t.innerHTML = y(), e.parentElement.insertBefore(s, e), this.attributionElement = t);
110
- }
111
- updateAttributionElement() {
112
- const i = this.map.getDiv();
113
- if (i == null) return;
114
- const e = this.attributionElement?.childNodes.item(0)?.childNodes.item(1);
115
- e != null && (e.style.display = i.clientWidth > 500 ? "initial" : "none");
116
- }
117
- getParameters() {
118
- return {
119
- mapSize: 256,
120
- zoomMin: this.options.minZoom ?? 0,
121
- zoomMax: this.options.maxZoom ?? 24,
122
- zoomScale: 10
123
- };
124
- }
125
- getMap() {
126
- return this.map;
127
- }
128
- getContainer() {
129
- return this.map.getDiv();
130
- }
131
- getZoom() {
132
- return this.map.getZoom() ?? NaN;
133
- }
134
- getBounds() {
135
- const i = this.map.getBounds();
136
- if (i == null) return { sw: { lat: NaN, lng: NaN }, ne: { lat: NaN, lng: NaN } };
137
- const e = i.getSouthWest(), s = i.getNorthEast();
138
- return { sw: { lat: e.lat(), lng: e.lng() }, ne: { lat: s.lat(), lng: s.lng() } };
139
- }
140
- panBy(i, e) {
141
- this.map.panBy(i, e);
142
- }
143
- createMarker(i, e, s, t) {
144
- const n = new this.MapMarkerClass({ position: { lat: e, lng: s }, content: i, zIndex: t });
145
- return {
146
- inserted: () => n.map != null && n.map == this.map,
147
- insert: () => n.map = this.map,
148
- remove: () => n.map = void 0,
149
- update: (a) => n.zIndex = a
150
- };
151
- }
152
- }
153
- const f = [
154
- {
155
- elementType: "labels.icon",
156
- stylers: [
157
- {
158
- visibility: "off"
159
- }
160
- ]
161
- },
162
- {
163
- stylers: [
164
- {
165
- saturation: -100
166
- },
167
- {
168
- lightness: -10
169
- }
170
- ]
171
- },
172
- {
173
- featureType: "landscape",
174
- stylers: [
175
- {
176
- lightness: 30
177
- }
178
- ]
179
- },
180
- {
181
- featureType: "road",
182
- elementType: "geometry",
183
- stylers: [
184
- {
185
- saturation: -100
186
- }
187
- ]
188
- }
189
- ], M = [
190
- {
191
- elementType: "labels.icon",
192
- stylers: [
193
- {
194
- visibility: "off"
195
- }
196
- ]
197
- },
198
- {
199
- stylers: [
200
- {
201
- saturation: -100
202
- }
203
- ]
204
- },
205
- {
206
- elementType: "geometry",
207
- stylers: [
208
- {
209
- lightness: -45
210
- }
211
- ]
212
- },
213
- {
214
- elementType: "labels.text.fill",
215
- stylers: [
216
- {
217
- lightness: -100
218
- }
219
- ]
220
- },
221
- {
222
- elementType: "labels.text.stroke",
223
- stylers: [
224
- {
225
- lightness: -15
226
- }
227
- ]
228
- },
229
- {
230
- featureType: "water",
231
- elementType: "geometry",
232
- stylers: [
233
- {
234
- lightness: -50
235
- }
236
- ]
237
- }
238
- ];
239
- export {
240
- M as GoogleMapDarkStyle,
241
- f as GoogleMapLightStyle,
242
- g as GoogleMapsProvider
243
- };
package/vite.config.ts DELETED
@@ -1,23 +0,0 @@
1
- import { defineConfig } from 'vite';
2
- import dts from 'vite-plugin-dts';
3
-
4
- export default defineConfig({
5
- plugins: [
6
- dts({
7
- rollupTypes: true,
8
- insertTypesEntry: true,
9
- entryRoot: './src',
10
- copyDtsFiles: true,
11
- exclude: ['**/node_modules/**']
12
- })
13
- ],
14
- build: {
15
- lib: {
16
- entry: './src/main.ts',
17
- name: 'ArenariumMapsIntegrationGoogle',
18
- formats: ['es', 'cjs'],
19
- fileName: (format, entryName) => `${entryName}.${format}.js`,
20
- cssFileName: 'style'
21
- }
22
- }
23
- });