@geolonia/embed 4.3.0 → 5.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.
Files changed (63) hide show
  1. package/.github/workflows/build.yml +99 -36
  2. package/.nvmrc +1 -1
  3. package/.prettierrc.json +4 -0
  4. package/.tool-versions +1 -1
  5. package/README.md +7 -1
  6. package/dist/e2e/basic.spec.d.ts +8 -0
  7. package/dist/e2e/helper.d.ts +4 -0
  8. package/dist/embed +2 -1
  9. package/dist/embed-chunks/2489af4328c51b71e92d.js +2 -0
  10. package/dist/embed-chunks/6e05bbf5f391fda5b858.js +1 -0
  11. package/dist/embed.js +2 -1
  12. package/dist/embed.js.LICENSE.txt +4 -0
  13. package/dist/playwright.config.d.ts +9 -0
  14. package/dist/{embed.d.ts → src/embed.d.ts} +3 -1
  15. package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -2
  16. package/dist/{lib → src/lib}/geolonia-marker.d.ts +1 -2
  17. package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
  18. package/dist/{lib → src/lib}/util.d.ts +6 -3
  19. package/dist/src/lib/util.test.d.ts +1 -0
  20. package/dist/src/testability.test.d.ts +1 -0
  21. package/dist/src/version.d.ts +1 -0
  22. package/e2e/basic.spec.ts +52 -0
  23. package/e2e/helper.ts +12 -0
  24. package/e2e/map.spec.ts +69 -0
  25. package/eslint.config.js +232 -0
  26. package/package.json +25 -12
  27. package/playwright.config.ts +79 -0
  28. package/src/embed.ts +13 -7
  29. package/src/lib/CustomAttributionControl.ts +52 -29
  30. package/src/lib/geolonia-map.ts +144 -38
  31. package/src/lib/geolonia-marker.ts +9 -6
  32. package/src/lib/keyring.test.ts +18 -0
  33. package/src/lib/keyring.ts +11 -13
  34. package/src/lib/maplibre-util.ts +31 -19
  35. package/src/lib/parse-atts.test.ts +2 -1
  36. package/src/lib/render.ts +18 -7
  37. package/src/lib/simplestyle-vector.ts +42 -13
  38. package/src/lib/simplestyle.test.ts +80 -69
  39. package/src/lib/simplestyle.ts +61 -43
  40. package/src/lib/util.test.ts +108 -21
  41. package/src/lib/util.ts +115 -32
  42. package/src/testability.test.ts +46 -0
  43. package/tsconfig.json +3 -1
  44. package/webpack.config.js +10 -1
  45. package/.eslintignore +0 -3
  46. package/.eslintrc.js +0 -14
  47. package/.prettierrc.js +0 -1
  48. package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
  49. package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
  50. package/dist/version.d.ts +0 -1
  51. /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
  52. /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 2489af4328c51b71e92d.js.LICENSE.txt} +0 -0
  53. /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
  54. /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
  55. /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
  56. /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
  57. /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
  58. /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
  59. /package/dist/{lib → src/lib}/render.d.ts +0 -0
  60. /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
  61. /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
  62. /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
  63. /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
@@ -0,0 +1,4 @@
1
+ /**
2
+ * MapLibre GL JS
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v5.7.0/LICENSE.txt
4
+ */
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Read environment variables from file.
3
+ * https://github.com/motdotla/dotenv
4
+ */
5
+ /**
6
+ * See https://playwright.dev/docs/test-configuration.
7
+ */
8
+ declare const _default: import("@playwright/test").PlaywrightTestConfig<{}, {}>;
9
+ export default _default;
@@ -42,7 +42,9 @@ export type EmbedAttributes = {
42
42
  };
43
43
  export type EmbedPlugin<PluginAttributes extends {
44
44
  [otherKey: string]: string;
45
- } = {}> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
45
+ } = {
46
+ [otherKey: string]: string;
47
+ }> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
46
48
  export type Geolonia = Partial<typeof maplibregl> & {
47
49
  accessToken?: string;
48
50
  embedVersion: string;
@@ -1,5 +1,5 @@
1
- import maplibregl from 'maplibre-gl';
2
- import type { MapOptions, StyleOptions, StyleSpecification, StyleSwapOptions } from 'maplibre-gl';
1
+ import maplibregl, { MapOptions, StyleOptions, StyleSpecification, StyleSwapOptions, GetResourceResponse } from 'maplibre-gl';
2
+ import { GetImageCallback } from './util';
3
3
  export type GeoloniaMapOptions = MapOptions & {
4
4
  interactive?: boolean;
5
5
  };
@@ -19,4 +19,12 @@ export default class GeoloniaMap extends maplibregl.Map {
19
19
  */
20
20
  setStyle(style: string | StyleSpecification, options?: StyleSwapOptions & StyleOptions): this;
21
21
  remove(): void;
22
+ /**
23
+ * Backward compatibility for breaking change of loadImage() in MapLibre GL JS v4.0.0.
24
+ * Related to https://github.com/maplibre/maplibre-gl-js/pull/3422/
25
+ * @param url
26
+ * @param callback
27
+ */
28
+ loadImage(url: string, callback: GetImageCallback): void;
29
+ loadImage(url: string): Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>;
22
30
  }
@@ -1,5 +1,4 @@
1
- import maplibregl from 'maplibre-gl';
2
- import type { MarkerOptions } from 'maplibre-gl';
1
+ import maplibregl, { type MarkerOptions } from 'maplibre-gl';
3
2
  /**
4
3
  * Geolonia default marker
5
4
  *
@@ -1,5 +1,3 @@
1
- /// <reference types="mapbox__point-geometry" />
2
- import Point from '@mapbox/point-geometry';
3
1
  /**
4
2
  * This class is a copy of maplibre-gl-js's util DOM class and rewrite it to JavaScript.
5
3
  * https://github.com/maplibre/maplibre-gl-js/blob/main/src/util/dom.ts
@@ -15,7 +13,7 @@ export declare class DOM {
15
13
  static addEventListener(target: any, type: any, callback: any, options: any): void;
16
14
  static removeEventListener(target: any, type: any, callback: any, options: any): void;
17
15
  static suppressClick(): void;
18
- static mousePos(el: any, e: any): Point;
16
+ static mousePos(el: any, e: any): any;
19
17
  static touchPos(el: any, touches: any): any[];
20
18
  static mouseButton(e: any): any;
21
19
  static remove(node: any): void;
@@ -1,10 +1,12 @@
1
- import type { MapOptions, MarkerOptions } from 'maplibre-gl';
1
+ import type { GetResourceResponse, MapOptions, MarkerOptions, ExpiryData } from 'maplibre-gl';
2
+ export type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
2
3
  /**
3
4
  *
4
5
  * @param {string} str target URL string
5
6
  * @return {string|false} Resolved URL or false if not resolved
6
7
  */
7
- export declare function isURL(str: any): any;
8
+ export declare function isURL(str: string): string | false;
9
+ export declare function isGeoloniaTilesHost(url: string | URL): boolean;
8
10
  export declare function checkPermission(): boolean;
9
11
  export declare function getLang(): "ja" | "en";
10
12
  /**
@@ -34,7 +36,7 @@ export declare function getContainer(arg: HTMLElement | string | {
34
36
  * @param {*} legacyOptions
35
37
  */
36
38
  export declare function handleMarkerOptions(options: MarkerOptions | null | undefined | false, legacyOptions: MarkerOptions): MarkerOptions;
37
- export declare function getStyle(style: any, atts: any): any;
39
+ export declare function getStyle(style: any, atts: any): string;
38
40
  export declare function getOptions(container: any, params: any, atts: any): MapOptions;
39
41
  /**
40
42
  *
@@ -56,3 +58,4 @@ export declare const handleRestrictedMode: (map: any) => void;
56
58
  export declare const handleErrorMode: (container: any) => void;
57
59
  export declare const sanitizeDescription: (description: any) => Promise<any>;
58
60
  export declare const random: (max: number) => number;
61
+ export declare function loadImageCompatibility(promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>, callback: GetImageCallback): void;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const VERSION = "5.0.2";
@@ -0,0 +1,52 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { Geolonia } from '../src/embed';
3
+ import { TEST_URL, waitForMapLoad } from './helper';
4
+
5
+ declare global {
6
+ interface Window {
7
+ geolonia: Geolonia,
8
+ maplibregl?: Geolonia,
9
+ mapboxgl?: Geolonia,
10
+ }
11
+ }
12
+
13
+ test.describe('1. 基本的な地図表示', () => {
14
+ test.beforeEach(async ({ page }) => {
15
+ await page.goto(`${TEST_URL}/basic.html`);
16
+ await waitForMapLoad(page);
17
+ });
18
+
19
+ test('1.1 ページ読み込み時に地図が表示されること', async ({ page }) => {
20
+ await page.goto(`${TEST_URL}/basic.html`);
21
+ await waitForMapLoad(page);
22
+ const mapContainer = page.locator('.geolonia');
23
+ await expect(mapContainer).toBeVisible();
24
+ const canvas = page.locator('.geolonia canvas');
25
+ await expect(canvas).toBeVisible();
26
+ });
27
+
28
+ test('1.2 デフォルトで原点に地図が表示されること', async ({ page }) => {
29
+ await page.goto(`${TEST_URL}/basic.html`);
30
+ await waitForMapLoad(page);
31
+ const center = await page.evaluate(() => {
32
+ const map = new window.geolonia.Map('map');
33
+ return map.getCenter();
34
+ });
35
+ // 日本のおおよその中心座標
36
+ expect(center.lat).toBeCloseTo(0.0, 0);
37
+ expect(center.lng).toBeCloseTo(0.0, 0);
38
+ });
39
+
40
+ test('1.3 コンソールエラーが発生していないこと', async ({ page }) => {
41
+ const consoleErrors: string[] = [];
42
+ page.on('console', (msg) => {
43
+ if (msg.type() === 'error') {
44
+ consoleErrors.push(msg.text());
45
+ }
46
+ });
47
+ await page.goto(`${TEST_URL}/basic.html`);
48
+ await waitForMapLoad(page);
49
+ expect(consoleErrors).toHaveLength(0);
50
+ });
51
+ });
52
+
package/e2e/helper.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { Page } from '@playwright/test';
2
+ // テスト用の設定
3
+ export const TEST_URL = 'http://localhost:3000/e2e';
4
+ export const LOAD_TIMEOUT = 5000;
5
+
6
+ // ヘルパー関数
7
+ export async function waitForMapLoad(page: Page, selector = '.geolonia') {
8
+ // 地図コンテナの存在を確認
9
+ await page.waitForSelector(selector);
10
+ // Maplibreのcanvasが表示されるまで待機
11
+ await page.waitForSelector(`${selector} canvas`, { timeout: LOAD_TIMEOUT });
12
+ }
@@ -0,0 +1,69 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { TEST_URL, LOAD_TIMEOUT, waitForMapLoad } from './helper';
3
+
4
+ test.describe('1. 基本的な地図表示', () => {
5
+ test.beforeEach(async ({ page }) => {
6
+ await page.goto(`${TEST_URL}/nocontrol.html`);
7
+ await waitForMapLoad(page);
8
+ });
9
+
10
+ test.describe.serial('2.1 地図が表示できること', () => {
11
+ test('2.1.1 ページ読み込み時に地図がロードされること', async ({ page }) => {
12
+ // MapLibre GLのmapインスタンスがロードされるまで待つ
13
+ try {
14
+ await page.waitForFunction(() => {
15
+ const map = new window.geolonia.Map('map');
16
+ // 地図が完全に読み込まれたかどうか
17
+ return map && map.loaded();
18
+ }, { timeout: LOAD_TIMEOUT });
19
+ // 成功
20
+ } catch {
21
+ // タイムアウト
22
+ expect(false).toBe(true); // テスト失敗
23
+ }
24
+ });
25
+ test('2.1.2 タイルが描画されていることを確認(上半分のみ)', async ({ page }) => {
26
+ const isNotBlank = await page.evaluate(() => {
27
+ const canvas = document.querySelector('.maplibregl-canvas') as HTMLCanvasElement;
28
+ // WebGLコンテキストを取得
29
+ const gl = canvas.getContext('webgl2') || canvas.getContext('webgl');
30
+
31
+ if (!gl) {
32
+ return false; // WebGLコンテキストが取得できない場合
33
+ }
34
+
35
+ const width = canvas.width;
36
+ const height = Math.floor(canvas.height / 2); // 上半分のみ
37
+ // ピクセルデータを読み取る
38
+ const pixels = new Uint8Array(width * height * 4);
39
+
40
+ // 下にAttributeがある場合、真っ白ではないため上半分だけを取得
41
+ // WebGLは下から上に向かって読み取るので、上半分を取得するには
42
+ // 下半分をスキップする必要がある
43
+ gl.readPixels(0, Math.floor(canvas.height / 2), width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
44
+ // 色の分析
45
+ let nonWhiteCount = 0;
46
+ const totalPixels = pixels.length / 4;
47
+
48
+ for (let i = 0; i < pixels.length; i += 4) {
49
+ const r = pixels[i];
50
+ const g = pixels[i + 1];
51
+ const b = pixels[i + 2];
52
+
53
+ // 白以外のピクセルをカウント
54
+ if (r < 250 || g < 250 || b < 250) {
55
+ nonWhiteCount++;
56
+
57
+ // 早期終了:十分な非白色ピクセルが見つかったら
58
+ if (nonWhiteCount > totalPixels * 0.01) {
59
+ return true;
60
+ }
61
+ }
62
+ }
63
+
64
+ return nonWhiteCount > 0;
65
+ });
66
+ expect(isNotBlank).toBe(true);
67
+ });
68
+ });
69
+ });
@@ -0,0 +1,232 @@
1
+ const {
2
+ defineConfig,
3
+ globalIgnores,
4
+ } = require("eslint/config");
5
+
6
+ const globals = require("globals");
7
+ const _import = require("eslint-plugin-import");
8
+ const promise = require("eslint-plugin-promise");
9
+
10
+ const {
11
+ fixupPluginRules,
12
+ fixupConfigRules,
13
+ } = require("@eslint/compat");
14
+
15
+ const tsParser = require("@typescript-eslint/parser");
16
+ const react = require("eslint-plugin-react");
17
+ const reactHooks = require("eslint-plugin-react-hooks");
18
+ const js = require("@eslint/js");
19
+
20
+ const {
21
+ FlatCompat,
22
+ } = require("@eslint/eslintrc");
23
+
24
+ const compat = new FlatCompat({
25
+ baseDirectory: __dirname,
26
+ recommendedConfig: js.configs.recommended,
27
+ allConfig: js.configs.all
28
+ });
29
+
30
+ module.exports = defineConfig([{
31
+ extends: compat.extends(
32
+ "eslint:recommended",
33
+ "plugin:promise/recommended",
34
+ ),
35
+
36
+ languageOptions: {
37
+ globals: {
38
+ ...globals.browser,
39
+ ...globals.commonjs,
40
+ ...globals.node,
41
+ ...globals.mocha,
42
+ },
43
+
44
+ sourceType: "module",
45
+
46
+ parserOptions: {
47
+ project: "./tsconfig.json",
48
+ },
49
+ },
50
+
51
+ plugins: {
52
+ import: fixupPluginRules(_import),
53
+ promise,
54
+ },
55
+
56
+ rules: {
57
+ "array-callback-return": "error",
58
+ "arrow-parens": "error",
59
+ "arrow-spacing": "error",
60
+ "block-spacing": "error",
61
+ "key-spacing": "error",
62
+ "keyword-spacing": "error",
63
+ "generator-star-spacing": "error",
64
+ "no-console": "warn",
65
+ "no-useless-computed-key": "error",
66
+ "no-useless-rename": "error",
67
+ "no-var": "error",
68
+ "prefer-arrow-callback": "error",
69
+ "prefer-const": "error",
70
+ "prefer-rest-params": "error",
71
+ "prefer-spread": "error",
72
+ "prefer-template": "error",
73
+ "rest-spread-spacing": "error",
74
+ "semi-spacing": "error",
75
+ "sort-imports": "off",
76
+ "space-before-blocks": "error",
77
+ "template-curly-spacing": "error",
78
+ "yield-star-spacing": "error",
79
+
80
+ yoda: ["error", "never", {
81
+ exceptRange: true,
82
+ }],
83
+
84
+ "import/no-extraneous-dependencies": ["warn", {
85
+ "devDependencies": [
86
+ "**/.eslintrc.js",
87
+ "**/.eslintrc.cjs",
88
+ "**/.mocharc.js",
89
+ "**/.prettierrc.js",
90
+ "**/jest.config.js",
91
+ "**/next.config.js",
92
+ "**/vite.config.js",
93
+ "**/vite.config.ts",
94
+ "**/webpack.config.js",
95
+ ],
96
+ }],
97
+
98
+ "promise/prefer-await-to-then": "error",
99
+ },
100
+ }, {
101
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
102
+
103
+ rules: {
104
+ "comma-dangle": ["error", "always-multiline"],
105
+
106
+ "comma-spacing": ["error", {
107
+ before: false,
108
+ after: true,
109
+ }],
110
+
111
+ "no-duplicate-imports": "error",
112
+ "no-useless-constructor": "error",
113
+
114
+ "no-unused-vars": ["warn", {
115
+ argsIgnorePattern: "^_",
116
+ }],
117
+
118
+ quotes: ["error", "single"],
119
+ semi: ["error", "always"],
120
+ "no-loss-of-precision": "off",
121
+ },
122
+ }, {
123
+ files: ["**/*.cjs"],
124
+
125
+ languageOptions: {
126
+ sourceType: "script",
127
+ parserOptions: {},
128
+ },
129
+ }, {
130
+ files: ["**/*.mjs", "**/*.jsx"],
131
+
132
+ languageOptions: {
133
+ sourceType: "module",
134
+ parserOptions: {},
135
+ },
136
+ }, {
137
+ files: ["**/*.ts", "**/*.tsx"],
138
+ extends: compat.extends("plugin:@typescript-eslint/recommended"),
139
+
140
+ languageOptions: {
141
+ parser: tsParser,
142
+ sourceType: "module",
143
+ parserOptions: {},
144
+ },
145
+
146
+ rules: {
147
+ "@typescript-eslint/ban-ts-comment": ["off", {
148
+ "ts-ignore": true,
149
+ }],
150
+
151
+ "comma-dangle": ["error", "always-multiline"],
152
+
153
+ "comma-spacing": ["error", {
154
+ before: false,
155
+ after: true,
156
+ }],
157
+
158
+ "no-duplicate-imports": "error",
159
+ "@typescript-eslint/no-useless-constructor": "error",
160
+
161
+ "@typescript-eslint/no-unused-vars": ["warn", {
162
+ argsIgnorePattern: "^_",
163
+ }],
164
+
165
+ "quotes": ["error", "single", {
166
+ "avoidEscape": true,
167
+ }],
168
+ "semi": ["error", "always"],
169
+
170
+ "@typescript-eslint/no-misused-promises": ["warn", {
171
+ "checksConditionals": true,
172
+ "checksVoidReturn": false,
173
+ }],
174
+
175
+ "@typescript-eslint/ban-types": "off",
176
+ "@typescript-eslint/camelcase": "off",
177
+ "@typescript-eslint/explicit-function-return-type": "off",
178
+ "@typescript-eslint/explicit-module-boundary-types": "off",
179
+ "@typescript-eslint/no-explicit-any": "off",
180
+ "@typescript-eslint/no-empty-function": "off",
181
+ "@typescript-eslint/no-extra-semi": "off",
182
+ "@typescript-eslint/no-loss-of-precision": "off",
183
+ "@typescript-eslint/no-this-alias": "off",
184
+ "@typescript-eslint/no-var-requires": "off",
185
+ },
186
+ }, {
187
+ files: ["**/*.jsx", "**/*.tsx"],
188
+
189
+ extends: fixupConfigRules(
190
+ compat.extends("plugin:react/recommended", "plugin:react-hooks/recommended"),
191
+ ),
192
+
193
+ languageOptions: {
194
+ globals: {
195
+ ...globals.browser,
196
+ },
197
+ },
198
+
199
+ plugins: {
200
+ react: fixupPluginRules(react),
201
+ "react-hooks": fixupPluginRules(reactHooks),
202
+ },
203
+
204
+ settings: {
205
+ react: {
206
+ pragma: "React",
207
+ version: "detect",
208
+ },
209
+ },
210
+
211
+ rules: {
212
+ "react/jsx-uses-react": "off",
213
+ "react/prop-types": "off",
214
+ "react/react-in-jsx-scope": "off",
215
+ },
216
+ }, {
217
+ files: [
218
+ "**/*.test.js",
219
+ "**/*.test.ts",
220
+ "**/*.test.jsx",
221
+ "**/*.test.tsx",
222
+ "**/*.spec.js",
223
+ "**/*.spec.ts",
224
+ "**/*.spec.jsx",
225
+ "**/*.spec.tsx",
226
+ ],
227
+
228
+ rules: {
229
+ "no-import-assign": "off",
230
+ "import/no-extraneous-dependencies": "off",
231
+ },
232
+ }, globalIgnores(["node_modules/", "docs", "dist", "eslint.config.js", ".*.js"])]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "4.3.0",
3
+ "version": "5.0.2",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "dist/embed.d.ts",
@@ -10,11 +10,12 @@
10
10
  "start": "webpack serve --config ./docs/webpack.config.js",
11
11
  "build": "npm run build:version && npm run build:embed",
12
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/",
14
- "analyze": "ANALYZE=true webpack --mode production",
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"
13
+ "build:embed": "MAP_PLATFORM_STAGE=v1 webpack --mode production && cp ./dist/embed.js ./dist/embed && cp -r ./dist/* ./docs/ && rm -rf ./docs/*.d.ts ./docs/lib/",
14
+ "analyze": "ANALYZE=true MAP_PLATFORM_STAGE=v1 webpack --mode production",
15
+ "format": "prettier \"./src/**/*.ts\" --write",
16
+ "lint": "eslint .",
17
+ "test": "TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' NODE_OPTIONS=\"--no-experimental-strip-types\" mocha",
18
+ "e2e": "playwright test"
18
19
  },
19
20
  "author": "Geolonia (https://geolonia.com)",
20
21
  "repository": {
@@ -27,17 +28,28 @@
27
28
  },
28
29
  "homepage": "https://github.com/geolonia/embed#readme",
29
30
  "devDependencies": {
30
- "@geolonia/eslint-config": "latest",
31
+ "@eslint/compat": "^1.4.1",
32
+ "@eslint/eslintrc": "^3.3.1",
33
+ "@eslint/js": "^9.39.1",
34
+ "@types/jsdom": "^21.1.7",
31
35
  "@types/mocha": "^10.0.1",
36
+ "@types/node": "^24.0.4",
37
+ "@typescript-eslint/eslint-plugin": "^8.46.4",
38
+ "@typescript-eslint/parser": "^8.46.4",
32
39
  "babel-loader": "^9.1.0",
33
40
  "css-loader": "^6.7.2",
34
- "eslint": "^8.29.0",
41
+ "eslint": "^9.39.1",
42
+ "eslint-config-prettier": "^10.1.8",
43
+ "eslint-plugin-import": "^2.32.0",
44
+ "eslint-plugin-promise": "^7.2.1",
45
+ "eslint-plugin-react": "^7.37.5",
46
+ "eslint-plugin-react-hooks": "^7.0.1",
47
+ "globals": "^16.5.0",
35
48
  "jsdom": "^20.0.3",
36
49
  "jsdom-global": "^3.0.2",
37
50
  "mocha": "^10.2.0",
38
51
  "node-fetch": "2",
39
- "prettier-eslint": "^15.0.0",
40
- "prettier-eslint-cli": "^7.1.0",
52
+ "prettier": "^3.6.2",
41
53
  "style-loader": "^3.3.1",
42
54
  "svg-inline-loader": "^0.8.2",
43
55
  "ts-loader": "^9.4.3",
@@ -52,9 +64,10 @@
52
64
  "@geolonia/mbgl-gesture-handling": "^1.0.15",
53
65
  "@mapbox/geojson-extent": "^1.0.0",
54
66
  "@mapbox/point-geometry": "^0.1.0",
67
+ "@playwright/test": "^1.53.1",
55
68
  "@turf/center": "^6.0.1",
56
- "maplibre-gl": "3.4.1",
57
- "pmtiles": "2.11.0",
69
+ "maplibre-gl": "5.7.0",
70
+ "pmtiles": "^3.0.6",
58
71
  "sanitize-html": "^2.8.0",
59
72
  "tinycolor2": "^1.4.1"
60
73
  }
@@ -0,0 +1,79 @@
1
+ import { defineConfig, devices } from '@playwright/test';
2
+
3
+ /**
4
+ * Read environment variables from file.
5
+ * https://github.com/motdotla/dotenv
6
+ */
7
+ // import dotenv from 'dotenv';
8
+ // import path from 'path';
9
+ // dotenv.config({ path: path.resolve(__dirname, '.env') });
10
+
11
+ /**
12
+ * See https://playwright.dev/docs/test-configuration.
13
+ */
14
+ export default defineConfig({
15
+ testDir: './e2e',
16
+ /* Run tests in files in parallel */
17
+ fullyParallel: true,
18
+ /* Fail the build on CI if you accidentally left test.only in the source code. */
19
+ forbidOnly: !!process.env.CI,
20
+ /* Retry on CI only */
21
+ retries: process.env.CI ? 2 : 0,
22
+ /* Opt out of parallel tests on CI. */
23
+ workers: process.env.CI ? 1 : undefined,
24
+ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
25
+ reporter: 'html',
26
+ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
27
+ use: {
28
+ /* Base URL to use in actions like `await page.goto('/')`. */
29
+ // baseURL: 'http://localhost:3000',
30
+
31
+ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
32
+ trace: 'on-first-retry',
33
+ },
34
+
35
+ /* Configure projects for major browsers */
36
+ projects: [
37
+ {
38
+ name: 'chromium',
39
+ use: { ...devices['Desktop Chrome'] },
40
+ },
41
+
42
+ {
43
+ name: 'firefox',
44
+ use: { ...devices['Desktop Firefox'] },
45
+ },
46
+
47
+ {
48
+ name: 'webkit',
49
+ use: { ...devices['Desktop Safari'] },
50
+ },
51
+
52
+ /* Test against mobile viewports. */
53
+ // {
54
+ // name: 'Mobile Chrome',
55
+ // use: { ...devices['Pixel 5'] },
56
+ // },
57
+ // {
58
+ // name: 'Mobile Safari',
59
+ // use: { ...devices['iPhone 12'] },
60
+ // },
61
+
62
+ /* Test against branded browsers. */
63
+ // {
64
+ // name: 'Microsoft Edge',
65
+ // use: { ...devices['Desktop Edge'], channel: 'msedge' },
66
+ // },
67
+ // {
68
+ // name: 'Google Chrome',
69
+ // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
70
+ // },
71
+ ],
72
+
73
+ /* Run your local dev server before starting the tests */
74
+ webServer: {
75
+ command: 'npm run start',
76
+ url: 'http://localhost:3000',
77
+ reuseExistingServer: !process.env.CI,
78
+ },
79
+ });
package/src/embed.ts CHANGED
@@ -46,7 +46,15 @@ export type EmbedAttributes = {
46
46
  [otherKey: string]: string;
47
47
  };
48
48
 
49
- export type EmbedPlugin<PluginAttributes extends { [otherKey: string]: string } = {}> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
49
+ export type EmbedPlugin<
50
+ PluginAttributes extends { [otherKey: string]: string } = {
51
+ [otherKey: string]: string;
52
+ },
53
+ > = (
54
+ map: GeoloniaMap,
55
+ target: HTMLElement,
56
+ atts: EmbedAttributes & PluginAttributes,
57
+ ) => void;
50
58
 
51
59
  // Type for `window.geolonia`
52
60
  export type Geolonia = Partial<typeof maplibregl> & {
@@ -61,9 +69,9 @@ export type Geolonia = Partial<typeof maplibregl> & {
61
69
 
62
70
  declare global {
63
71
  interface Window {
64
- geolonia: Geolonia,
65
- maplibregl?: Geolonia,
66
- mapboxgl?: Geolonia,
72
+ geolonia: Geolonia;
73
+ maplibregl?: Geolonia;
74
+ mapboxgl?: Geolonia;
67
75
  }
68
76
  }
69
77
 
@@ -76,9 +84,7 @@ const geolonia: Geolonia = Object.assign(window.geolonia || {}, maplibregl, {
76
84
  registerPlugin,
77
85
  });
78
86
 
79
- window.geolonia =
80
- window.maplibregl =
81
- window.mapboxgl = geolonia;
87
+ window.geolonia = (window.maplibregl as any) = window.mapboxgl = geolonia;
82
88
 
83
89
  renderGeoloniaMap();
84
90