@geolonia/embed 4.0.0 → 4.1.0

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.
Files changed (57) hide show
  1. package/.eslintrc.js +1 -2
  2. package/.github/workflows/build.yml +1 -1
  3. package/.mocharc.js +9 -0
  4. package/.tool-versions +1 -1
  5. package/PLUGIN.md +1 -1
  6. package/dist/embed +1 -1
  7. package/dist/embed-chunks/4472555f7ea90b733a8e.js +2 -0
  8. package/dist/embed-chunks/4b3a60cc98a6be867ce3.js +1 -0
  9. package/dist/embed.d.ts +62 -0
  10. package/dist/embed.js +1 -1
  11. package/dist/lib/CustomAttributionControl.d.ts +45 -0
  12. package/dist/lib/controls/geolonia-control.d.ts +7 -0
  13. package/dist/lib/geolonia-map.d.ts +22 -0
  14. package/dist/lib/geolonia-marker.d.ts +10 -0
  15. package/dist/lib/keyring.d.ts +29 -0
  16. package/dist/lib/keyring.test.d.ts +1 -0
  17. package/dist/lib/maplibre-util.d.ts +27 -0
  18. package/dist/lib/parse-atts.d.ts +6 -0
  19. package/dist/lib/parse-atts.test.d.ts +1 -0
  20. package/dist/lib/render.d.ts +5 -0
  21. package/dist/lib/simplestyle-vector.d.ts +26 -0
  22. package/dist/lib/simplestyle.d.ts +29 -0
  23. package/dist/lib/simplestyle.test.d.ts +1 -0
  24. package/dist/lib/util.d.ts +57 -0
  25. package/dist/lib/util.test.d.ts +1 -0
  26. package/dist/types-internal.d.ts +4 -0
  27. package/dist/version.d.ts +1 -0
  28. package/package.json +17 -22
  29. package/scripts/build-version.mjs +12 -0
  30. package/src/embed.ts +85 -0
  31. package/src/lib/{CustomAttributionControl.js → CustomAttributionControl.ts} +14 -2
  32. package/src/lib/controls/{geolonia-control.js → geolonia-control.ts} +6 -2
  33. package/src/lib/{geolonia-map.js → geolonia-map.ts} +44 -47
  34. package/src/lib/{geolonia-marker.js → geolonia-marker.ts} +10 -9
  35. package/src/lib/keyring.test.ts +66 -0
  36. package/src/lib/keyring.ts +86 -0
  37. package/src/lib/{maplibre-util.js → maplibre-util.ts} +1 -1
  38. package/src/lib/{parse-atts.test.js → parse-atts.test.ts} +5 -1
  39. package/src/lib/{parse-atts.js → parse-atts.ts} +14 -9
  40. package/src/lib/render.ts +100 -0
  41. package/src/lib/{simplestyle-vector.js → simplestyle-vector.ts} +4 -3
  42. package/src/lib/{simplestyle.test.js → simplestyle.test.ts} +26 -27
  43. package/src/lib/{simplestyle.js → simplestyle.ts} +9 -8
  44. package/src/lib/{util.test.js → util.test.ts} +51 -46
  45. package/src/lib/{util.js → util.ts} +15 -14
  46. package/src/types-internal.ts +4 -0
  47. package/tsconfig.json +28 -0
  48. package/webpack.config.js +7 -5
  49. package/.babelrc +0 -12
  50. package/dist/embed-chunks/3d467b2d527e4e5de1b8.js +0 -1
  51. package/dist/embed-chunks/eb491da30c0af7f50004.js +0 -2
  52. package/src/embed.d.ts +0 -58
  53. package/src/embed.js +0 -119
  54. package/src/lib/parse-api-key.js +0 -77
  55. package/src/lib/parse-api-key.test.js +0 -102
  56. package/src/lib/providers/amazon.js +0 -116
  57. /package/dist/embed-chunks/{eb491da30c0af7f50004.js.LICENSE.txt → 4472555f7ea90b733a8e.js.LICENSE.txt} +0 -0
@@ -0,0 +1,45 @@
1
+ import type { ControlPosition, IControl } from 'maplibre-gl';
2
+ /**
3
+ * This class is a copy of maplibre-gl-js's AttributionControl class and rewrite by shadow DOM.
4
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/ui/control/attribution_control.ts
5
+ */
6
+ /**
7
+ * When the map is too small to display the full attribution, it will be
8
+ * collapsed in to a "i" icon. It is open by default, and will hide itself
9
+ * when user interaction is detected.
10
+ * For more information on why this is open by default, see the following links:
11
+ *
12
+ * The OSM Foundation attribution guidelines.
13
+ * https://wiki.osmfoundation.org/wiki/Licence/Attribution_Guidelines#Interactive_maps
14
+ * > You may use a mechanism to fade/collapse the attribution under certain conditions:
15
+ * > * immediately with a dismiss interaction, for example clicking an ‘x’ in the corner of a dialog
16
+ * > * automatically on map interaction such as panning, clicking, or zooming
17
+ * > * automatically after five seconds. This also applies to splash screens or pop-ups.
18
+ *
19
+ * This is the issue where attribution is open by default in the MapLibre GL JS library:
20
+ * https://github.com/maplibre/maplibre-gl-js/issues/205
21
+ */
22
+ declare class CustomAttributionControl implements IControl {
23
+ private options;
24
+ private _map;
25
+ private _compact;
26
+ private _container;
27
+ private _shadowContainer;
28
+ private _innerContainer;
29
+ private _compactButton;
30
+ private _editLink;
31
+ private _attribHTML;
32
+ private styleId;
33
+ private styleOwner;
34
+ constructor(options?: {});
35
+ getDefaultPosition(): ControlPosition;
36
+ onAdd(map: any): any;
37
+ onRemove(): void;
38
+ _setElementTitle(element: any, title: any): void;
39
+ _toggleAttribution(): void;
40
+ _updateData(e: any): void;
41
+ _updateAttributions(): void;
42
+ _updateCompact(): void;
43
+ _updateCompactMinimize(): void;
44
+ }
45
+ export default CustomAttributionControl;
@@ -0,0 +1,7 @@
1
+ import type { ControlPosition, IControl } from 'maplibre-gl';
2
+ export declare class GeoloniaControl implements IControl {
3
+ private container;
4
+ onAdd(): HTMLDivElement;
5
+ onRemove(): void;
6
+ getDefaultPosition(): ControlPosition;
7
+ }
@@ -0,0 +1,22 @@
1
+ import maplibregl from 'maplibre-gl';
2
+ import type { MapOptions, StyleOptions, StyleSpecification, StyleSwapOptions } from 'maplibre-gl';
3
+ export type GeoloniaMapOptions = Omit<MapOptions, 'style'> & {
4
+ interactive?: boolean;
5
+ };
6
+ /**
7
+ * Render the map
8
+ *
9
+ * @param container
10
+ */
11
+ export default class GeoloniaMap extends maplibregl.Map {
12
+ private geoloniaSourcesUrl;
13
+ private __styleExtensionLoadRequired;
14
+ constructor(params: string | GeoloniaMapOptions);
15
+ /**
16
+ *
17
+ * @param {string|null} style style identity or `null` when map.remove()
18
+ * @param {*} options
19
+ */
20
+ setStyle(style: string | StyleSpecification, options?: StyleSwapOptions & StyleOptions): this;
21
+ remove(): void;
22
+ }
@@ -0,0 +1,10 @@
1
+ import maplibregl from 'maplibre-gl';
2
+ import type { MarkerOptions } from 'maplibre-gl';
3
+ /**
4
+ * Geolonia default marker
5
+ *
6
+ * @param container
7
+ */
8
+ export default class GeoloniaMarker extends maplibregl.Marker {
9
+ constructor(options?: MarkerOptions, legacyOptions?: MarkerOptions);
10
+ }
@@ -0,0 +1,29 @@
1
+ declare class Keyring {
2
+ #private;
3
+ /**
4
+ * @returns API key
5
+ */
6
+ get apiKey(): string;
7
+ /**
8
+ * @param key - API Key to set
9
+ */
10
+ set apiKey(key: string);
11
+ /**
12
+ * @returns Stage name
13
+ */
14
+ get stage(): string;
15
+ /**
16
+ * @param stage - Stage name to set
17
+ */
18
+ set stage(stage: string);
19
+ /**
20
+ * Parses the API key and stage from the URL of the current script tag.
21
+ *
22
+ * @param {Document} document
23
+ */
24
+ parse(doc?: Document): void;
25
+ /** Reset API key and stage for testing purpose */
26
+ reset(): void;
27
+ }
28
+ declare const keyring: Keyring;
29
+ export { keyring };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ /// <reference types="mapbox__point-geometry" />
2
+ import Point from '@mapbox/point-geometry';
3
+ /**
4
+ * This class is a copy of maplibre-gl-js's util DOM class and rewrite it to JavaScript.
5
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
6
+ * */
7
+ export declare class DOM {
8
+ #private;
9
+ static testProp(props: any): any;
10
+ static create(tagName: any, className?: any, container?: any): any;
11
+ static createNS(namespaceURI: any, tagName: any): HTMLElement;
12
+ static disableDrag(): void;
13
+ static enableDrag(): void;
14
+ static setTransform(el: any, value: any): void;
15
+ static addEventListener(target: any, type: any, callback: any, options: any): void;
16
+ static removeEventListener(target: any, type: any, callback: any, options: any): void;
17
+ static suppressClick(): void;
18
+ static mousePos(el: any, e: any): Point;
19
+ static touchPos(el: any, touches: any): any[];
20
+ static mouseButton(e: any): any;
21
+ static remove(node: any): void;
22
+ }
23
+ /**
24
+ * This function is a copy of maplibre-gl-js's util function and rewrite it to JavaScript.
25
+ * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/util.ts#L223-L228
26
+ * */
27
+ export declare function bindAll(fns: any, context: any): void;
@@ -0,0 +1,6 @@
1
+ import type { EmbedAttributes } from '../embed';
2
+ type ParseAttsParams = {
3
+ interactive?: boolean;
4
+ };
5
+ declare const _default: (container: any, params?: ParseAttsParams) => EmbedAttributes;
6
+ export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import 'maplibre-gl/dist/maplibre-gl.css';
2
+ import '../style.css';
3
+ import GeoloniaMap from './geolonia-map';
4
+ export declare const renderGeoloniaMap: () => void;
5
+ export declare const registerPlugin: (plugin: (map: GeoloniaMap, target: HTMLElement, atts: any) => void) => void;
@@ -0,0 +1,26 @@
1
+ declare class SimpleStyleVector {
2
+ private url;
3
+ private sourceName;
4
+ constructor(url: any);
5
+ addTo(map: any): void;
6
+ /**
7
+ * Set polygon geometries.
8
+ *
9
+ * @param map
10
+ */
11
+ setPolygonGeometries(map: any): void;
12
+ /**
13
+ * Set line geometries.
14
+ *
15
+ * @param map
16
+ */
17
+ setLineGeometries(map: any): void;
18
+ /**
19
+ * Setup point geometries.
20
+ *
21
+ * @param map
22
+ */
23
+ setPointGeometries(map: any): void;
24
+ setPopup(map: any, source: any): Promise<void>;
25
+ }
26
+ export default SimpleStyleVector;
@@ -0,0 +1,29 @@
1
+ export declare class SimpleStyle {
2
+ _loadingPromise: Promise<unknown>;
3
+ private callFitBounds;
4
+ private geojson;
5
+ private map;
6
+ private options;
7
+ constructor(geojson: any, options?: any);
8
+ updateData(geojson: any): this;
9
+ addTo(map: any): this;
10
+ fitBounds(options?: {}): this;
11
+ /**
12
+ * Set polygon geometries.
13
+ */
14
+ setPolygonGeometries(): void;
15
+ /**
16
+ * Set line geometries.
17
+ */
18
+ setLineGeometries(): void;
19
+ /**
20
+ * Setup point geometries.
21
+ */
22
+ setPointGeometries(): void;
23
+ setPopup(map: any, source: any): Promise<void>;
24
+ /**
25
+ * Setup cluster markers
26
+ */
27
+ setCluster(): void;
28
+ setGeoJSON(geojson: any): void;
29
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { MapOptions, MarkerOptions } from 'maplibre-gl';
2
+ /**
3
+ *
4
+ * @param {string} str target URL string
5
+ * @return {string|false} Resolved URL or false if not resolved
6
+ */
7
+ export declare function isURL(str: any): any;
8
+ export declare function checkPermission(): boolean;
9
+ export declare function getLang(): "ja" | "en";
10
+ /**
11
+ * Detects the window is scrollable.
12
+ */
13
+ export declare function isScrollable(): boolean;
14
+ /**
15
+ * Detects the object is HTMLElment?
16
+ *
17
+ * @param {*} o
18
+ */
19
+ export declare function isDomElement(o: any): o is HTMLElement;
20
+ /**
21
+ * Gets the HTMLElement for the map.
22
+ * Possibility args are HTMLElement or CSS selector or object that has container property.
23
+ *
24
+ * @param {*} arg
25
+ * @return {HTMLElement | false}
26
+ */
27
+ export declare function getContainer(arg: HTMLElement | string | {
28
+ container: HTMLElement | string;
29
+ }): HTMLElement | false;
30
+ /**
31
+ * Merge legacyOptions into options for geolonia.Marker class
32
+ *
33
+ * @param {*} options
34
+ * @param {*} legacyOptions
35
+ */
36
+ export declare function handleMarkerOptions(options: MarkerOptions | null | undefined | false, legacyOptions: MarkerOptions): MarkerOptions;
37
+ export declare function getStyle(style: any, atts: any): any;
38
+ export declare function getOptions(container: any, params: any, atts: any): MapOptions;
39
+ /**
40
+ *
41
+ * @param {string} an data-*-control Embed attribute
42
+ * @returns { enabled: bolean, position: 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left' | void }
43
+ */
44
+ export declare function parseControlOption(att: any): {
45
+ enabled: boolean;
46
+ position: any;
47
+ };
48
+ /**
49
+ *
50
+ * @param {number} digits for session
51
+ * @returns sessionId
52
+ */
53
+ export declare const getSessionId: (digit: any) => string;
54
+ export declare const parseSimpleVector: (attributeValue: any) => any;
55
+ export declare const handleRestrictedMode: (map: any) => void;
56
+ export declare const sanitizeDescription: (description: any) => Promise<any>;
57
+ export declare const random: (max: number) => number;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ declare module '*.svg' {
2
+ const content: string;
3
+ export default content;
4
+ }
@@ -0,0 +1 @@
1
+ export declare const VERSION = "4.1.0";
package/package.json CHANGED
@@ -1,16 +1,20 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
- "types": "src/embed.d.ts",
6
+ "types": "dist/embed.d.ts",
7
7
  "scripts": {
8
+ "prestart": "npm run build:version",
9
+ "prelint": "npm run build:version",
8
10
  "start": "webpack serve --config ./docs/webpack.config.js",
9
- "build": "webpack --mode production && cp ./dist/embed.js ./dist/embed && cp -r ./dist/* ./docs/",
11
+ "build": "npm run build:version && npm run build:embed",
12
+ "build:version": "node ./scripts/build-version.mjs",
13
+ "build:embed": "webpack --mode production && cp ./dist/embed.js ./dist/embed && cp -r ./dist/* ./docs/ && rm -rf ./docs/*.d.ts ./docs/lib/",
10
14
  "analyze": "ANALYZE=true webpack --mode production",
11
- "format": "prettier-eslint \"./src/**/*.js\" --write",
12
- "lint": "eslint \"src/**/*.js\"",
13
- "test": "yarn run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
15
+ "format": "prettier-eslint \"./src/**/*.ts\" --write",
16
+ "lint": "eslint --ext .js,.cjs,.mjs,.jsx,.ts,.tsx .",
17
+ "test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha"
14
18
  },
15
19
  "author": "Geolonia (https://geolonia.com)",
16
20
  "repository": {
@@ -23,13 +27,8 @@
23
27
  },
24
28
  "homepage": "https://github.com/geolonia/embed#readme",
25
29
  "devDependencies": {
26
- "@babel/cli": "^7.19.3",
27
- "@babel/core": "^7.20.5",
28
- "@babel/eslint-parser": "^7.19.1",
29
- "@babel/plugin-transform-classes": "^7.20.2",
30
- "@babel/preset-env": "^7.20.2",
31
- "@babel/register": "^7.18.9",
32
- "@geolonia/eslint-config": "^0.0.1",
30
+ "@geolonia/eslint-config": "latest",
31
+ "@types/mocha": "^10.0.1",
33
32
  "babel-loader": "^9.1.0",
34
33
  "css-loader": "^6.7.2",
35
34
  "eslint": "^8.29.0",
@@ -41,6 +40,9 @@
41
40
  "prettier-eslint-cli": "^7.1.0",
42
41
  "style-loader": "^3.3.1",
43
42
  "svg-inline-loader": "^0.8.2",
43
+ "ts-loader": "^9.4.3",
44
+ "ts-node": "^10.9.1",
45
+ "typescript": "^5.1.3",
44
46
  "webpack": "^5.75.0",
45
47
  "webpack-bundle-analyzer": "^4.7.0",
46
48
  "webpack-cli": "^5.0.1",
@@ -51,16 +53,9 @@
51
53
  "@mapbox/geojson-extent": "^1.0.0",
52
54
  "@mapbox/point-geometry": "^0.1.0",
53
55
  "@turf/center": "^6.0.1",
54
- "core-js": "^3.26.1",
55
56
  "maplibre-gl": "3.0.1",
56
57
  "pmtiles": "^2.7.2",
57
- "promise-polyfill": "^8.2.3",
58
58
  "sanitize-html": "^2.8.0",
59
- "tinycolor2": "^1.4.1",
60
- "url-parse": "^1.5.10",
61
- "whatwg-fetch": "^3.0.0"
62
- },
63
- "browserslist": [
64
- "defaults or >= 1% in JP"
65
- ]
59
+ "tinycolor2": "^1.4.1"
60
+ }
66
61
  }
@@ -0,0 +1,12 @@
1
+ import { readFile, writeFile } from 'node:fs/promises';
2
+ import { join, dirname } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ const __dirname = dirname(fileURLToPath(import.meta.url));
6
+
7
+ const pkg = JSON.parse(await readFile(join(__dirname, '../package.json'), 'utf-8'));
8
+
9
+ await writeFile(
10
+ join(__dirname, '../src/version.ts'),
11
+ `export const VERSION = '${pkg.version}';\n`,
12
+ );
package/src/embed.ts ADDED
@@ -0,0 +1,85 @@
1
+ /**
2
+ * @file Entry for embed.js
3
+ */
4
+
5
+ import * as maplibregl from 'maplibre-gl';
6
+ import GeoloniaMap from './lib/geolonia-map';
7
+ import GeoloniaMarker from './lib/geolonia-marker';
8
+ import { SimpleStyle } from './lib/simplestyle';
9
+ import { VERSION as embedVersion } from './version';
10
+ import { registerPlugin, renderGeoloniaMap } from './lib/render';
11
+
12
+ export type { GeoloniaMapOptions } from './lib/geolonia-map';
13
+
14
+ export type Popup = maplibregl.Popup;
15
+
16
+ export type EmbedAttributes = {
17
+ lat: string;
18
+ lng: string;
19
+ zoom: string;
20
+ bearing: string;
21
+ pitch: string;
22
+ hash: string;
23
+ marker: string;
24
+ markerColor: string;
25
+ openPopup: string;
26
+ customMarker: string;
27
+ customMarkerOffset: string;
28
+ gestureHandling: string;
29
+ navigationControl: string;
30
+ geolocateControl: string;
31
+ fullscreenControl: string;
32
+ scaleControl: string;
33
+ geoloniaControl: string;
34
+ geojson: string;
35
+ cluster: string;
36
+ clusterColor: string;
37
+ style: string;
38
+ lang: string;
39
+ plugin: string;
40
+ key: string;
41
+ apiUrl: string;
42
+ loader: string;
43
+ minZoom: string;
44
+ maxZoom: string;
45
+ '3d': string;
46
+ [otherKey: string]: string;
47
+ };
48
+
49
+ export type EmbedPlugin<PluginAttributes extends { [otherKey: string]: string } = {}> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
50
+
51
+ // Type for `window.geolonia`
52
+ export type Geolonia = Partial<typeof maplibregl> & {
53
+ accessToken?: string;
54
+ embedVersion?: string;
55
+ Map?: typeof GeoloniaMap;
56
+ Marker?: typeof GeoloniaMarker;
57
+ SimpleStyle?: typeof SimpleStyle;
58
+ simpleStyle?: typeof SimpleStyle; // backward compatibility
59
+ registerPlugin?: (embedPlugin: EmbedPlugin) => void;
60
+ };
61
+
62
+ declare global {
63
+ interface Window {
64
+ geolonia: Geolonia,
65
+ maplibregl?: Geolonia,
66
+ mapboxgl?: Geolonia,
67
+ }
68
+ }
69
+
70
+ const geolonia: Geolonia = Object.assign(window.geolonia || {}, maplibregl, {
71
+ Map: GeoloniaMap,
72
+ Marker: GeoloniaMarker,
73
+ SimpleStyle: SimpleStyle,
74
+ simpleStyle: SimpleStyle,
75
+ embedVersion,
76
+ registerPlugin,
77
+ });
78
+
79
+ window.geolonia =
80
+ window.maplibregl =
81
+ window.mapboxgl = geolonia;
82
+
83
+ renderGeoloniaMap();
84
+
85
+ export { geolonia };
@@ -1,4 +1,5 @@
1
1
  import { DOM, bindAll } from './maplibre-util';
2
+ import type { ControlPosition, IControl } from 'maplibre-gl';
2
3
 
3
4
  /**
4
5
  * This class is a copy of maplibre-gl-js's AttributionControl class and rewrite by shadow DOM.
@@ -22,7 +23,18 @@ import { DOM, bindAll } from './maplibre-util';
22
23
  * https://github.com/maplibre/maplibre-gl-js/issues/205
23
24
  */
24
25
 
25
- class CustomAttributionControl {
26
+ class CustomAttributionControl implements IControl {
27
+ private options;
28
+ private _map;
29
+ private _compact;
30
+ private _container;
31
+ private _shadowContainer;
32
+ private _innerContainer;
33
+ private _compactButton;
34
+ private _editLink;
35
+ private _attribHTML;
36
+ private styleId;
37
+ private styleOwner;
26
38
 
27
39
  constructor(options = {}) {
28
40
  this.options = options;
@@ -45,7 +57,7 @@ class CustomAttributionControl {
45
57
  ], this);
46
58
  }
47
59
 
48
- getDefaultPosition() {
60
+ getDefaultPosition(): ControlPosition {
49
61
  return 'bottom-right';
50
62
  }
51
63
 
@@ -1,4 +1,8 @@
1
- export class GeoloniaControl {
1
+ import type { ControlPosition, IControl } from 'maplibre-gl';
2
+
3
+ export class GeoloniaControl implements IControl {
4
+ private container: HTMLDivElement;
5
+
2
6
  onAdd() {
3
7
  this.container = document.createElement('div');
4
8
  this.container.className = 'maplibregl-ctrl';
@@ -28,7 +32,7 @@ export class GeoloniaControl {
28
32
  this.container.parentNode.removeChild(this.container);
29
33
  }
30
34
 
31
- getDefaultPosition() {
35
+ getDefaultPosition(): ControlPosition {
32
36
  return 'bottom-left';
33
37
  }
34
38
  }