@geolonia/embed 6.0.0-pre.6 → 6.0.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 (39) hide show
  1. package/.github/workflows/build.yml +4 -4
  2. package/.tool-versions +1 -1
  3. package/CHANGELOG.md +43 -0
  4. package/README.md +1 -1
  5. package/dist/embed +1 -1
  6. package/dist/embed-chunks/{d1fe32cb4bfb0e9c6575.js → 124e026690b0fa17700b.js} +1 -1
  7. package/dist/embed-chunks/{5fc1f8cd252efa958f7d.js → 9734b8bdf9fe84261b54.js} +2 -2
  8. package/dist/embed-chunks/{64c22ed093c8de0fcbf8.js → ae36f6b8e34f85ae3045.js} +2 -2
  9. package/dist/embed-chunks/{4b5b1b54a5dac816ef15.js → db5eea9dfc49d1cf19e7.js} +1 -1
  10. package/dist/embed-core.d.ts +1 -1
  11. package/dist/embed-core.js +1 -1
  12. package/dist/embed-core.js.LICENSE.txt +1 -1
  13. package/dist/embed.d.ts +3 -3
  14. package/dist/embed.js +1 -1
  15. package/dist/embed.js.LICENSE.txt +1 -1
  16. package/dist/lib/parse-atts.d.ts +1 -1
  17. package/dist/lib/render.d.ts +2 -2
  18. package/dist/types-internal.d.ts +4 -0
  19. package/dist/types.d.ts +13 -6
  20. package/dist/version.d.ts +1 -1
  21. package/eslint.config.js +15 -48
  22. package/package.json +14 -19
  23. package/src/embed-core.ts +5 -1
  24. package/src/embed.ts +7 -3
  25. package/src/lib/parse-atts.test.ts +6 -6
  26. package/src/lib/parse-atts.ts +8 -7
  27. package/src/lib/render.ts +31 -10
  28. package/src/lib/util.ts +1 -1
  29. package/src/testability.test.ts +20 -17
  30. package/src/types-internal.ts +18 -0
  31. package/src/types.ts +12 -4
  32. package/src/version.ts +1 -1
  33. package/tsconfig.build.json +5 -0
  34. package/tsconfig.json +5 -3
  35. package/webpack.config.js +2 -2
  36. /package/dist/embed-chunks/{4574b15eb540c5efc533.js → 5f80e0235f4b38778d0d.js} +0 -0
  37. /package/dist/embed-chunks/{5fc1f8cd252efa958f7d.js.LICENSE.txt → 9734b8bdf9fe84261b54.js.LICENSE.txt} +0 -0
  38. /package/dist/embed-chunks/{64c22ed093c8de0fcbf8.js.LICENSE.txt → ae36f6b8e34f85ae3045.js.LICENSE.txt} +0 -0
  39. /package/dist/embed-chunks/{ffdb8e820d823ee3571c.js → c83bb7c9a4a7ed9d5b23.js} +0 -0
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * MapLibre GL JS
3
- * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.12.0/LICENSE.txt
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.16.0/LICENSE.txt
4
4
  */
@@ -12,7 +12,7 @@ type ParseAttsParams = {
12
12
  * {@link attsToOptions}, which converts these into a typed
13
13
  * `GeoloniaMapOptions` for maps-core.
14
14
  */
15
- declare const _default: (container: any, params?: ParseAttsParams) => EmbedAttributes;
15
+ declare const _default: (container: HTMLElement, params?: ParseAttsParams) => EmbedAttributes;
16
16
  export default _default;
17
17
  /**
18
18
  * Convert normalised {@link EmbedAttributes} into a typed `GeoloniaMapOptions`
@@ -1,5 +1,5 @@
1
1
  import 'maplibre-gl/dist/maplibre-gl.css';
2
2
  import '../style.css';
3
- import { GeoloniaMap } from '@geolonia/maps-core';
3
+ import type { EmbedPlugin, EmbedPluginAttributes } from '../types';
4
4
  export declare const renderGeoloniaMap: () => void;
5
- export declare const registerPlugin: (plugin: (map: GeoloniaMap, target: HTMLElement, atts: any) => void) => void;
5
+ export declare const registerPlugin: <PluginAttributes extends EmbedPluginAttributes>(plugin: EmbedPlugin<PluginAttributes>) => void;
@@ -2,3 +2,7 @@ declare module '*.svg' {
2
2
  const content: string;
3
3
  export default content;
4
4
  }
5
+ declare module '*.css';
6
+ interface HTMLElement {
7
+ geoloniaMap?: import('@geolonia/maps-core').GeoloniaMap;
8
+ }
package/dist/types.d.ts CHANGED
@@ -208,7 +208,18 @@ export type EmbedAttributes = {
208
208
  * 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
209
209
  * プラグイン固有の属性など)。
210
210
  */
211
- [otherKey: string]: string | number;
211
+ [otherKey: string]: string | number | undefined;
212
+ };
213
+ /**
214
+ * プラグインが独自に読む `data-*` 属性の型。
215
+ *
216
+ * {@link EmbedAttributes} のインデックスシグネチャが `number` も許すのは、
217
+ * `maxZoom: 20` のように既定値が数値の組み込み属性があるため。一方こちらは
218
+ * プラグイン固有の `data-*` だけを指し、`parseAtts` が `container.dataset`
219
+ * (`DOMStringMap`) をそのまま広げて渡すので、実行時には必ず文字列か未定義になる。
220
+ */
221
+ export type EmbedPluginAttributes = {
222
+ [otherKey: string]: string | undefined;
212
223
  };
213
224
  /**
214
225
  * 埋め込みプラグインの型。地図インスタンス、対象のコンテナ要素、正規化済みの
@@ -219,8 +230,4 @@ export type EmbedAttributes = {
219
230
  * まで保留され、そのイベント時にまとめて呼び出される。呼び出し前に削除された地図に
220
231
  * 対しては呼び出されない。
221
232
  */
222
- export type EmbedPlugin<PluginAttributes extends {
223
- [otherKey: string]: string;
224
- } = {
225
- [otherKey: string]: string;
226
- }> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
233
+ export type EmbedPlugin<PluginAttributes extends EmbedPluginAttributes = EmbedPluginAttributes> = (map: GeoloniaMap, target: HTMLElement, atts: EmbedAttributes & PluginAttributes) => void;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "6.0.0-pre.6";
1
+ export declare const VERSION = "6.0.0";
package/eslint.config.js CHANGED
@@ -4,17 +4,15 @@ const {
4
4
  } = require("eslint/config");
5
5
 
6
6
  const globals = require("globals");
7
- const _import = require("eslint-plugin-import");
8
- const promise = require("eslint-plugin-promise");
9
7
 
10
- const {
11
- fixupPluginRules,
12
- fixupConfigRules,
13
- } = require("@eslint/compat");
8
+ // eslint-plugin-import ではなく import-x を使う (geolonia/embed#561)。
9
+ // 本家は 2025-06-20 を最後にリリースが止まっており、eslint 10 を peer に
10
+ // 宣言したバージョンが無い。import-x はそのフォークで flat config に対応して
11
+ // いるため、@eslint/compat の fixupPluginRules も要らない。
12
+ const importX = require("eslint-plugin-import-x");
13
+ const promise = require("eslint-plugin-promise");
14
14
 
15
15
  const tsParser = require("@typescript-eslint/parser");
16
- const react = require("eslint-plugin-react");
17
- const reactHooks = require("eslint-plugin-react-hooks");
18
16
  const js = require("@eslint/js");
19
17
 
20
18
  const {
@@ -49,7 +47,7 @@ module.exports = defineConfig([{
49
47
  },
50
48
 
51
49
  plugins: {
52
- import: fixupPluginRules(_import),
50
+ "import-x": importX,
53
51
  promise,
54
52
  },
55
53
 
@@ -81,7 +79,7 @@ module.exports = defineConfig([{
81
79
  exceptRange: true,
82
80
  }],
83
81
 
84
- "import/no-extraneous-dependencies": ["warn", {
82
+ "import-x/no-extraneous-dependencies": ["warn", {
85
83
  "devDependencies": [
86
84
  "**/.eslintrc.js",
87
85
  "**/.eslintrc.cjs",
@@ -91,6 +89,9 @@ module.exports = defineConfig([{
91
89
  "**/next.config.js",
92
90
  "**/vite.config.js",
93
91
  "**/vite.config.ts",
92
+ // import-x に替えて初めて報告されるようになった。本家は同じ
93
+ // ファイルの prettier は報告するのに vitest だけ見落としていた。
94
+ "**/vitest.config.ts",
94
95
  "**/webpack.config.js",
95
96
  ],
96
97
  }],
@@ -98,7 +99,7 @@ module.exports = defineConfig([{
98
99
  "promise/prefer-await-to-then": "error",
99
100
  },
100
101
  }, {
101
- files: ["**/*.js", "**/*.cjs", "**/*.mjs", "**/*.jsx"],
102
+ files: ["**/*.js", "**/*.cjs", "**/*.mjs"],
102
103
 
103
104
  rules: {
104
105
  "comma-dangle": ["error", "always-multiline"],
@@ -127,14 +128,14 @@ module.exports = defineConfig([{
127
128
  parserOptions: {},
128
129
  },
129
130
  }, {
130
- files: ["**/*.mjs", "**/*.jsx"],
131
+ files: ["**/*.mjs"],
131
132
 
132
133
  languageOptions: {
133
134
  sourceType: "module",
134
135
  parserOptions: {},
135
136
  },
136
137
  }, {
137
- files: ["**/*.ts", "**/*.tsx"],
138
+ files: ["**/*.ts"],
138
139
  extends: compat.extends("plugin:@typescript-eslint/recommended"),
139
140
 
140
141
  languageOptions: {
@@ -183,50 +184,16 @@ module.exports = defineConfig([{
183
184
  "@typescript-eslint/no-this-alias": "off",
184
185
  "@typescript-eslint/no-var-requires": "off",
185
186
  },
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
187
  }, {
217
188
  files: [
218
189
  "**/*.test.js",
219
190
  "**/*.test.ts",
220
- "**/*.test.jsx",
221
- "**/*.test.tsx",
222
191
  "**/*.spec.js",
223
192
  "**/*.spec.ts",
224
- "**/*.spec.jsx",
225
- "**/*.spec.tsx",
226
193
  ],
227
194
 
228
195
  rules: {
229
196
  "no-import-assign": "off",
230
- "import/no-extraneous-dependencies": "off",
197
+ "import-x/no-extraneous-dependencies": "off",
231
198
  },
232
199
  }, globalIgnores(["node_modules/", "docs", "dist", "eslint.config.js", ".*.js"])]);
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "6.0.0-pre.6",
3
+ "version": "6.0.0",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
- "types": "dist/src/embed.d.ts",
6
+ "types": "dist/embed.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
- "types": "./dist/src/embed.d.ts",
9
+ "types": "./dist/embed.d.ts",
10
10
  "default": "./dist/embed.js"
11
11
  },
12
12
  "./core": {
13
- "types": "./dist/src/embed-core.d.ts",
13
+ "types": "./dist/embed-core.d.ts",
14
14
  "default": "./dist/embed-core.js"
15
15
  }
16
16
  },
@@ -25,42 +25,37 @@
25
25
  },
26
26
  "homepage": "https://github.com/geolonia/embed#readme",
27
27
  "devDependencies": {
28
- "@eslint/compat": "^1.4.1",
29
28
  "@eslint/eslintrc": "^3.3.1",
30
- "@eslint/js": "^9.39.1",
29
+ "@eslint/js": "^10.0.1",
31
30
  "@types/geojson": "^7946.0.16",
32
- "@types/jsdom": "^21.1.7",
33
- "@types/node": "^24.0.4",
31
+ "@types/node": "^26.6.6",
34
32
  "@typescript-eslint/eslint-plugin": "^8.46.4",
35
33
  "@typescript-eslint/parser": "^8.46.4",
36
34
  "css-loader": "^7.1.5",
37
35
  "esbuild": "^0.28.2",
38
- "eslint": "^9.39.1",
36
+ "eslint": "^10.14.0",
39
37
  "eslint-config-prettier": "^10.1.8",
40
- "eslint-plugin-import": "^2.32.0",
38
+ "eslint-plugin-import-x": "^4.17.1",
41
39
  "eslint-plugin-promise": "^7.2.1",
42
- "eslint-plugin-react": "^7.37.5",
43
- "eslint-plugin-react-hooks": "^7.0.1",
44
- "globals": "^16.5.0",
45
- "jsdom": "^29.1.1",
46
- "node-fetch": "2",
40
+ "globals": "^17.14.0",
41
+ "jsdom": "^30.1.3",
47
42
  "prettier": "^3.6.2",
48
43
  "style-loader": "^4.0.0",
49
44
  "svg-inline-loader": "^0.8.2",
50
45
  "ts-loader": "^9.4.3",
51
46
  "typedoc": "^0.28.20",
52
47
  "typedoc-plugin-markdown": "^4.12.0",
53
- "typescript": "^5.1.3",
54
- "vitest": "^4.1.1",
48
+ "typescript": "^6.0.3",
49
+ "vitest": "^5.0.5",
55
50
  "webpack": "^5.75.0",
56
51
  "webpack-bundle-analyzer": "^5.4.0",
57
- "webpack-cli": "^7.2.3",
52
+ "webpack-cli": "^7.3.1",
58
53
  "webpack-dev-server": "^6.0.0"
59
54
  },
60
55
  "dependencies": {
61
56
  "@geolonia/maps-core": "^0.8.0",
62
57
  "@playwright/test": "^1.61.1",
63
- "maplibre-gl": "6.12.0"
58
+ "maplibre-gl": "6.16.0"
64
59
  },
65
60
  "scripts": {
66
61
  "start": "MAP_PLATFORM_STAGE=v1 webpack serve --config ./docs/webpack.config.js",
package/src/embed-core.ts CHANGED
@@ -23,5 +23,9 @@ export {
23
23
  } from '@geolonia/maps-core';
24
24
  export { registerPlugin } from './lib/render';
25
25
  export { VERSION as embedVersion } from './version';
26
- export type { EmbedAttributes, EmbedPlugin } from './types';
26
+ export type {
27
+ EmbedAttributes,
28
+ EmbedPlugin,
29
+ EmbedPluginAttributes,
30
+ } from './types';
27
31
  export type { GeoloniaMapOptions } from '@geolonia/maps-core';
package/src/embed.ts CHANGED
@@ -12,8 +12,11 @@ export type { GeoloniaMapOptions } from '@geolonia/maps-core';
12
12
 
13
13
  export type Popup = maplibregl.Popup;
14
14
 
15
- export type { EmbedAttributes, EmbedPlugin } from './types';
16
- import type { EmbedPlugin } from './types';
15
+ export type {
16
+ EmbedAttributes,
17
+ EmbedPlugin,
18
+ EmbedPluginAttributes,
19
+ } from './types';
17
20
 
18
21
  // Type for `window.geolonia`
19
22
  export type Geolonia = Partial<typeof maplibregl> & {
@@ -23,7 +26,8 @@ export type Geolonia = Partial<typeof maplibregl> & {
23
26
  Marker: typeof GeoloniaMarker;
24
27
  SimpleStyle: typeof SimpleStyle;
25
28
  simpleStyle: typeof SimpleStyle; // backward compatibility
26
- registerPlugin: (embedPlugin: EmbedPlugin) => void;
29
+ // render.ts の実装とシグネチャを必ず一致させる。
30
+ registerPlugin: typeof registerPlugin;
27
31
  };
28
32
 
29
33
  declare global {
@@ -346,17 +346,17 @@ describe('data-lang 言語解決', () => {
346
346
  it('data-lang="en" は browser が ja でも英語スタイルになる (ja にならない)', () => {
347
347
  const opts = optionsFor('en', ['ja']);
348
348
  expect(opts.lang).toBe('en');
349
- expect(getStyle('geolonia/basic-v2', { lang: 'en', apiKey: 'KEY' })).toContain(
350
- '/en.json',
351
- );
349
+ expect(
350
+ getStyle('geolonia/basic-v2', { lang: 'en', apiKey: 'KEY' }),
351
+ ).toContain('/en.json');
352
352
  });
353
353
 
354
354
  it('data-lang="ja" は browser が en でも日本語スタイルになる', () => {
355
355
  const opts = optionsFor('ja', ['en']);
356
356
  expect(opts.lang).toBe('ja');
357
- expect(getStyle('geolonia/basic-v2', { lang: 'ja', apiKey: 'KEY' })).toContain(
358
- '/ja.json',
359
- );
357
+ expect(
358
+ getStyle('geolonia/basic-v2', { lang: 'ja', apiKey: 'KEY' }),
359
+ ).toContain('/ja.json');
360
360
  });
361
361
 
362
362
  it('data-lang="ja-jp" は日本語スタイルになる (maps-core#50)', () => {
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import type { ControlPosition } from 'maplibre-gl';
4
+ import type { FeatureCollection } from 'geojson';
4
5
  import {
5
6
  getLang,
6
7
  keyring,
@@ -25,14 +26,16 @@ type ParseAttsParams = {
25
26
  * `GeoloniaMapOptions` for maps-core.
26
27
  */
27
28
  export default (
28
- container,
29
+ container: HTMLElement,
29
30
  params: ParseAttsParams = {},
30
31
  ): EmbedAttributes => {
32
+ // HTMLElement なら dataset は必ずあるが、plain object を渡していた頃の経路の
33
+ // 保険として残している。HTMLElement.dataset は readonly なのでキャストする。
31
34
  if (!container.dataset) {
32
- container.dataset = {};
35
+ (container as unknown as { dataset: DOMStringMap }).dataset = {};
33
36
  }
34
37
 
35
- let lang = 'auto';
38
+ let lang: string;
36
39
  if (container.dataset.lang && container.dataset.lang === 'auto') {
37
40
  lang = getLang();
38
41
  } else if (container.dataset.lang && container.dataset.lang === 'ja') {
@@ -122,12 +125,10 @@ const isCssSelector = (value: string): Element | false => {
122
125
  * a URL / inline JSON string, or a parsed FeatureCollection when the value is a
123
126
  * CSS selector referencing an inline element.
124
127
  */
125
- const resolveGeojson = (
126
- value: string,
127
- ): string | GeoJSON.FeatureCollection => {
128
+ const resolveGeojson = (value: string): string | FeatureCollection => {
128
129
  const el = isCssSelector(value);
129
130
  if (el && el.textContent) {
130
- return JSON.parse(el.textContent) as GeoJSON.FeatureCollection;
131
+ return JSON.parse(el.textContent) as FeatureCollection;
131
132
  }
132
133
  return value;
133
134
  };
package/src/lib/render.ts CHANGED
@@ -3,8 +3,15 @@ import '../style.css';
3
3
  import { GeoloniaMap, keyring } from '@geolonia/maps-core';
4
4
  import { checkPermission, parseScriptTagApiKey } from './util';
5
5
  import parseAtts, { attsToOptions } from './parse-atts';
6
+ import type {
7
+ EmbedAttributes,
8
+ EmbedPlugin,
9
+ EmbedPluginAttributes,
10
+ } from '../types';
6
11
 
7
- const plugins = [];
12
+ // 登録済みプラグインは個別の PluginAttributes を持ちうるので、配列としては
13
+ // それらをまとめて保持できる形にしておく (呼び出しは常に EmbedAttributes で行う)。
14
+ const plugins: EmbedPlugin<any>[] = [];
8
15
 
9
16
  /**
10
17
  * Move any inline HTML the author placed inside the map container into
@@ -45,21 +52,29 @@ export const renderGeoloniaMap = () => {
45
52
 
46
53
  if (checkPermission()) {
47
54
  let isDOMContentLoaded = false;
48
- const alreadyRenderedMaps = [];
49
55
  const isRemoved = Symbol('map-is-removed');
50
56
 
57
+ // 手動で remove された地図に印を付けるための symbol プロパティ。
58
+ type RemovableMap = GeoloniaMap & { [isRemoved]?: boolean };
59
+
60
+ const alreadyRenderedMaps: {
61
+ map: RemovableMap;
62
+ target: HTMLElement;
63
+ atts: EmbedAttributes;
64
+ }[] = [];
65
+
51
66
  /**
52
67
  *
53
68
  * @param {HTMLElement} target
54
69
  */
55
- const renderSingleMap = (target) => {
70
+ const renderSingleMap = (target: HTMLElement) => {
56
71
  const atts = parseAtts(target);
57
72
 
58
73
  // Dedup: if this container was already initialised (e.g. constructed
59
74
  // programmatically before the lazy observer fired), reuse the instance.
60
75
  // Must happen before extractPopupContent(), otherwise we'd wipe the
61
76
  // already-rendered map DOM out of the container.
62
- let map = target.geoloniaMap;
77
+ let map: RemovableMap | undefined = target.geoloniaMap;
63
78
  if (!map) {
64
79
  // Grab inline popup content before maps-core clears/renders the container.
65
80
  extractPopupContent(target);
@@ -81,7 +96,10 @@ export const renderGeoloniaMap = () => {
81
96
  map.remove();
82
97
  }
83
98
  });
84
- observer.observe(target.parentNode, { childList: true });
99
+ // 親が無いコンテナは DOM から外されることがないので監視しない。
100
+ if (target.parentNode) {
101
+ observer.observe(target.parentNode, { childList: true });
102
+ }
85
103
 
86
104
  // plugin
87
105
  if (isDOMContentLoaded && !map[isRemoved]) {
@@ -108,7 +126,8 @@ export const renderGeoloniaMap = () => {
108
126
  return;
109
127
  }
110
128
  try {
111
- renderSingleMap(item.target);
129
+ // 監視対象は下の querySelectorAll<HTMLElement> で集めた要素に限られる。
130
+ renderSingleMap(item.target as HTMLElement);
112
131
  } catch (e) {
113
132
  // Not throw error because, following maps will not be rendered.
114
133
  console.error('[Geolonia] Failed to initialize map', e); // eslint-disable-line
@@ -117,10 +136,10 @@ export const renderGeoloniaMap = () => {
117
136
  });
118
137
  });
119
138
 
120
- const containers = document.querySelectorAll(
139
+ const containers = document.querySelectorAll<HTMLElement>(
121
140
  '.geolonia[data-lazy-loading="off"]',
122
141
  );
123
- const lazyContainers = document.querySelectorAll(
142
+ const lazyContainers = document.querySelectorAll<HTMLElement>(
124
143
  '.geolonia:not([data-lazy-loading="off"])',
125
144
  );
126
145
 
@@ -151,8 +170,10 @@ export const renderGeoloniaMap = () => {
151
170
  }
152
171
  };
153
172
 
154
- export const registerPlugin = (
155
- plugin: (map: GeoloniaMap, target: HTMLElement, atts) => void,
173
+ // PluginAttributes を推論させる。EmbedPlugin<{ foo: string }> のように固有の
174
+ // data-* を要求するプラグインも、そのまま登録できるようにするため。
175
+ export const registerPlugin = <PluginAttributes extends EmbedPluginAttributes>(
176
+ plugin: EmbedPlugin<PluginAttributes>,
156
177
  ): void => {
157
178
  plugins.push(plugin);
158
179
  return void 0;
package/src/lib/util.ts CHANGED
@@ -106,7 +106,7 @@ export function checkPermission() {
106
106
  * So, it should be caught.
107
107
  */
108
108
  try {
109
- if (window.self.location.origin === window.top.location.origin) {
109
+ if (window.self.location.origin === window.top?.location.origin) {
110
110
  return true;
111
111
  }
112
112
  } catch {
@@ -1,5 +1,4 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { JSDOM } from 'jsdom';
1
+ import { describe, it, expect } from 'vitest';
3
2
 
4
3
  // maplibre-gl v6 にデフォルトエクスポートは無いので名前空間でインポートする。
5
4
  import * as maplibregl from 'maplibre-gl';
@@ -12,20 +11,14 @@ import * as maplibregl from 'maplibre-gl';
12
11
 
13
12
  describe('maplibre-gl jsdom limitation', () => {
14
13
  it('jsdom上ではMaplibre Mapインスタンス生成時にエラー(WebGL未対応のため)', () => {
15
- // jsdom の "Not implemented" メッセージを抑制
16
- const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
14
+ // vitest.config.ts の environment: 'jsdom' が用意する document を使う。
15
+ // 以前はここで JSDOM を自前に生成して global.window / global.document を
16
+ // 差し替えていたが、vitest 5 では jsdom 環境の document が getter のみになり
17
+ // 代入できない (Cannot set property document of [object Window])。
18
+ // 環境として jsdom が既にあるので、器だけ用意すれば足りる。
19
+ document.body.innerHTML = '<div id="map"></div>';
17
20
 
18
- const dom = new JSDOM(
19
- '<!DOCTYPE html><html><body><div id="map"></div></body></html>',
20
- {
21
- url: 'http://localhost',
22
- pretendToBeVisual: true,
23
- },
24
- );
25
- // @ts-ignore
26
- global.window = dom.window;
27
- global.document = dom.window.document;
28
- let errorCaught = null;
21
+ let errorCaught: unknown = null;
29
22
  try {
30
23
  new maplibregl.Map({
31
24
  container: 'map',
@@ -38,10 +31,20 @@ describe('maplibre-gl jsdom limitation', () => {
38
31
  }
39
32
  expect(errorCaught).toBeInstanceOf(Error);
40
33
  expect(
41
- /webgl|WebGL|context|device|Not implemented/i.test(errorCaught.message),
34
+ /webgl|WebGL|context|device|Not implemented/i.test(
35
+ (errorCaught as Error).message,
36
+ ),
42
37
  ).toBe(true);
43
38
 
44
- consoleSpy.mockRestore();
39
+ // 実行すると jsdom が
40
+ // Not implemented: HTMLCanvasElement's getContext() method
41
+ // をテスト出力に書く。これは失敗ではなく、このテストが記録している
42
+ // 「jsdom には WebGL が無い」ことの証跡そのもの。
43
+ //
44
+ // 以前は console.error を spy で潰していたが、vitest 5 では jsdom 環境が
45
+ // 環境セットアップ時に VirtualConsole を作るため、テスト内で貼る spy では
46
+ // もう捕まえられない (environmentOptions.jsdom.console: true でも同じ)。
47
+ // 何も抑制しない spy を残すと誤解を生むので外してある。
45
48
  });
46
49
 
47
50
  it('【NOTE】描画テストが必要な場合はE2E(ブラウザ実行)で行うこと', () => {
@@ -1,4 +1,22 @@
1
+ // 型を持たないモジュールと、maps-core が実行時に生やすプロパティのための
2
+ // アンビエント宣言をここにまとめている。
3
+
1
4
  declare module '*.svg' {
2
5
  const content: string;
3
6
  export default content;
4
7
  }
8
+
9
+ // TypeScript 6 は型を持たないモジュールの副作用 import を TS2882 として
10
+ // 報告するようになった。webpack 側は css-loader / style-loader が処理する。
11
+ declare module '*.css';
12
+
13
+ // maps-core は初期化した地図インスタンスをコンテナ要素に生やす。
14
+ // render.ts の二重初期化チェックと e2e がこれを読んでいる。
15
+ //
16
+ // このファイルはアンビエント宣言のためのスクリプト (module ではない) なので、
17
+ // グローバルの HTMLElement をそのまま宣言マージする。declare global は module で
18
+ // しか使えず、module にすると上の declare module '*.svg' が書けなくなる。
19
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
20
+ interface HTMLElement {
21
+ geoloniaMap?: import('@geolonia/maps-core').GeoloniaMap;
22
+ }
package/src/types.ts CHANGED
@@ -209,9 +209,19 @@ export type EmbedAttributes = {
209
209
  * 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
210
210
  * プラグイン固有の属性など)。
211
211
  */
212
- [otherKey: string]: string | number;
212
+ [otherKey: string]: string | number | undefined;
213
213
  };
214
214
 
215
+ /**
216
+ * プラグインが独自に読む `data-*` 属性の型。
217
+ *
218
+ * {@link EmbedAttributes} のインデックスシグネチャが `number` も許すのは、
219
+ * `maxZoom: 20` のように既定値が数値の組み込み属性があるため。一方こちらは
220
+ * プラグイン固有の `data-*` だけを指し、`parseAtts` が `container.dataset`
221
+ * (`DOMStringMap`) をそのまま広げて渡すので、実行時には必ず文字列か未定義になる。
222
+ */
223
+ export type EmbedPluginAttributes = { [otherKey: string]: string | undefined };
224
+
215
225
  /**
216
226
  * 埋め込みプラグインの型。地図インスタンス、対象のコンテナ要素、正規化済みの
217
227
  * {@link EmbedAttributes} を受け取って呼び出される。
@@ -222,9 +232,7 @@ export type EmbedAttributes = {
222
232
  * 対しては呼び出されない。
223
233
  */
224
234
  export type EmbedPlugin<
225
- PluginAttributes extends { [otherKey: string]: string } = {
226
- [otherKey: string]: string;
227
- },
235
+ PluginAttributes extends EmbedPluginAttributes = EmbedPluginAttributes,
228
236
  > = (
229
237
  map: GeoloniaMap,
230
238
  target: HTMLElement,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '6.0.0-pre.6';
1
+ export const VERSION = '6.0.0';
@@ -1,5 +1,10 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ // TypeScript 6 は rootDir の明示を要求する (TS5011)。これまでの推論結果と
5
+ // 同じ ./src を指定しており、dist の .d.ts の配置は変わらない。
6
+ "rootDir": "./src"
7
+ },
3
8
  "exclude": [
4
9
  "src/**/*.test.ts",
5
10
  "e2e",
package/tsconfig.json CHANGED
@@ -12,13 +12,15 @@
12
12
  "sourceMap": true,
13
13
  "esModuleInterop": true,
14
14
  "allowSyntheticDefaultImports": true,
15
- // "strict": true,
15
+ "strict": true,
16
16
  "forceConsistentCasingInFileNames": true,
17
17
  "module": "esnext",
18
- "moduleResolution": "node",
18
+ "moduleResolution": "bundler",
19
+ // TypeScript 6 は node_modules/@types を自動で全部取り込まなくなったので、
20
+ // グローバル型が要るものを明示する (process など)。
21
+ "types": ["node"],
19
22
  "resolveJsonModule": true,
20
23
  "isolatedModules": true,
21
- "jsx": "react-jsx",
22
24
  "noFallthroughCasesInSwitch": true,
23
25
  "newLine": "lf"
24
26
  },
package/webpack.config.js CHANGED
@@ -83,7 +83,7 @@ const sharedConfig = {
83
83
  },
84
84
  },
85
85
  {
86
- test: /\.tsx?$/,
86
+ test: /\.ts$/,
87
87
  use: {
88
88
  loader: 'ts-loader',
89
89
  options: {
@@ -99,7 +99,7 @@ const sharedConfig = {
99
99
  ],
100
100
  },
101
101
  resolve: {
102
- extensions: ['.tsx', '.ts', '.js'],
102
+ extensions: ['.ts', '.js'],
103
103
  },
104
104
  };
105
105