@geolonia/embed 6.0.0-pre.6 → 6.0.1
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/.github/workflows/build.yml +4 -4
- package/.tool-versions +1 -1
- package/CHANGELOG.md +47 -0
- package/README.md +1 -1
- package/dist/embed +1 -1
- package/dist/embed-chunks/{d1fe32cb4bfb0e9c6575.js → 124e026690b0fa17700b.js} +1 -1
- package/dist/embed-chunks/{5fc1f8cd252efa958f7d.js → 9734b8bdf9fe84261b54.js} +2 -2
- package/dist/embed-chunks/{64c22ed093c8de0fcbf8.js → ae36f6b8e34f85ae3045.js} +2 -2
- package/dist/embed-chunks/{4b5b1b54a5dac816ef15.js → db5eea9dfc49d1cf19e7.js} +1 -1
- package/dist/embed-core.d.ts +1 -1
- package/dist/embed-core.js +1 -1
- package/dist/embed-core.js.LICENSE.txt +1 -1
- package/dist/embed.d.ts +3 -3
- package/dist/embed.js +1 -1
- package/dist/embed.js.LICENSE.txt +1 -1
- package/dist/lib/parse-atts.d.ts +1 -1
- package/dist/lib/render.d.ts +2 -2
- package/dist/lib/util.d.ts +0 -5
- package/dist/types-internal.d.ts +4 -0
- package/dist/types.d.ts +13 -6
- package/dist/version.d.ts +1 -1
- package/e2e/iframe.spec.ts +37 -22
- package/eslint.config.js +15 -48
- package/package.json +14 -19
- package/src/embed-core.ts +5 -1
- package/src/embed.ts +7 -3
- package/src/lib/parse-atts.test.ts +6 -6
- package/src/lib/parse-atts.ts +8 -7
- package/src/lib/render.ts +111 -97
- package/src/lib/util.ts +0 -76
- package/src/testability.test.ts +20 -17
- package/src/types-internal.ts +18 -0
- package/src/types.ts +12 -4
- package/src/version.ts +1 -1
- package/tsconfig.build.json +5 -0
- package/tsconfig.json +5 -3
- package/webpack.config.js +2 -2
- /package/dist/embed-chunks/{4574b15eb540c5efc533.js → 5f80e0235f4b38778d0d.js} +0 -0
- /package/dist/embed-chunks/{5fc1f8cd252efa958f7d.js.LICENSE.txt → 9734b8bdf9fe84261b54.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{64c22ed093c8de0fcbf8.js.LICENSE.txt → ae36f6b8e34f85ae3045.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{ffdb8e820d823ee3571c.js → c83bb7c9a4a7ed9d5b23.js} +0 -0
package/dist/lib/parse-atts.d.ts
CHANGED
|
@@ -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:
|
|
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`
|
package/dist/lib/render.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'maplibre-gl/dist/maplibre-gl.css';
|
|
2
2
|
import '../style.css';
|
|
3
|
-
import {
|
|
3
|
+
import type { EmbedPlugin, EmbedPluginAttributes } from '../types';
|
|
4
4
|
export declare const renderGeoloniaMap: () => void;
|
|
5
|
-
export declare const registerPlugin: (plugin:
|
|
5
|
+
export declare const registerPlugin: <PluginAttributes extends EmbedPluginAttributes>(plugin: EmbedPlugin<PluginAttributes>) => void;
|
package/dist/lib/util.d.ts
CHANGED
|
@@ -13,8 +13,3 @@ export declare function parseScriptTagApiKey(doc?: Document): {
|
|
|
13
13
|
apiKey: string;
|
|
14
14
|
stage: string;
|
|
15
15
|
} | null;
|
|
16
|
-
/**
|
|
17
|
-
* Detect whether the embed is allowed to render in the current (possibly
|
|
18
|
-
* iframed) context. Embed-specific: not provided by maps-core.
|
|
19
|
-
*/
|
|
20
|
-
export declare function checkPermission(): boolean;
|
package/dist/types-internal.d.ts
CHANGED
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.
|
|
1
|
+
export declare const VERSION = "6.0.1";
|
package/e2e/iframe.spec.ts
CHANGED
|
@@ -1,35 +1,50 @@
|
|
|
1
1
|
import { test, expect } from '@playwright/test';
|
|
2
|
-
import { TEST_URL, mockGeoloniaTiles, waitForMapLoad, hasMapInstance } from './helper';
|
|
2
|
+
import { BASE_URL, LOAD_TIMEOUT, TEST_URL, mockGeoloniaTiles, waitForMapLoad, hasMapInstance } from './helper';
|
|
3
3
|
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
test
|
|
10
|
-
|
|
4
|
+
// 子フレーム用の別オリジン。リクエストは route で dev サーバーへ転送する
|
|
5
|
+
const OTHER_ORIGIN = 'http://embed-iframe.test';
|
|
6
|
+
|
|
7
|
+
// embed (wrapper) 固有: class="geolonia" の要素は、iframe の中でも API キーの有無に関係なく地図になる。
|
|
8
|
+
test.describe('iframe の中での描画 (wrapper-only)', () => {
|
|
9
|
+
test('非 iframe で地図が描画される', async ({ page }) => {
|
|
10
|
+
await mockGeoloniaTiles(page);
|
|
11
|
+
await page.goto(`${TEST_URL}/basic.html`);
|
|
12
|
+
await waitForMapLoad(page);
|
|
13
|
+
|
|
14
|
+
expect(await hasMapInstance(page, '#map')).toBe(true);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('API キー無しの embed を別オリジンの iframe に入れても地図が描画される', async ({ page }) => {
|
|
11
18
|
const consoleErrors: string[] = [];
|
|
12
19
|
page.on('console', (msg) => {
|
|
13
20
|
if (msg.type() === 'error') consoleErrors.push(msg.text());
|
|
14
21
|
});
|
|
15
22
|
|
|
16
23
|
await mockGeoloniaTiles(page);
|
|
17
|
-
await page.
|
|
18
|
-
|
|
24
|
+
await page.route(`${OTHER_ORIGIN}/**`, async (route) => {
|
|
25
|
+
const url = route.request().url().replace(OTHER_ORIGIN, BASE_URL);
|
|
26
|
+
await route.fulfill({ response: await route.fetch({ url }) });
|
|
27
|
+
});
|
|
28
|
+
await page.goto(`${TEST_URL}/iframe.html?origin=${encodeURIComponent(OTHER_ORIGIN)}`);
|
|
19
29
|
|
|
20
|
-
|
|
21
|
-
|
|
30
|
+
const frame = page.frameLocator('#frame');
|
|
31
|
+
await expect(frame.locator('#map canvas')).toBeVisible({ timeout: 10000 });
|
|
22
32
|
|
|
23
|
-
|
|
33
|
+
const child = page.frames().find((f) => f.url().endsWith('/e2e/no-api-key.html'));
|
|
34
|
+
expect(child).toBeDefined();
|
|
35
|
+
// waitForStyleLoad と同じ条件で、子フレームの地図がスタイルまで読み終えるのを待つ
|
|
36
|
+
await child!.waitForFunction(
|
|
37
|
+
() => {
|
|
38
|
+
const map = (document.querySelector('#map') as any)?.geoloniaMap;
|
|
39
|
+
return !!(map && map.loaded() && map.isStyleLoaded());
|
|
40
|
+
},
|
|
41
|
+
undefined,
|
|
42
|
+
{ timeout: LOAD_TIMEOUT },
|
|
43
|
+
);
|
|
44
|
+
expect(new URL(child!.url()).origin).toBe(OTHER_ORIGIN);
|
|
45
|
+
expect(
|
|
46
|
+
await child!.evaluate(() => !!(document.querySelector('#map') as any)?.geoloniaMap),
|
|
47
|
+
).toBe(true);
|
|
24
48
|
expect(consoleErrors.some((t) => t.includes("can't display our map in iframe"))).toBe(false);
|
|
25
49
|
});
|
|
26
|
-
|
|
27
|
-
// 拒否ケース (iframe + API key 無し → console.error) は E2E では再現が難しい:
|
|
28
|
-
// - ローカルでは特例 origin (codepen 等) + referrer を満たせない
|
|
29
|
-
// - child frame の console は親フレームから capture しにくい
|
|
30
|
-
// このゲートは checkPermission() のユニットテスト (window.self/parent/location をモック) で
|
|
31
|
-
// 検証する方が現実的。E2E では skip する (silent に落とさず明示)。
|
|
32
|
-
test.skip('iframe + API key 無し → 拒否される (ユニットテストで担保)', async () => {
|
|
33
|
-
// intentionally skipped — see comment above
|
|
34
|
-
});
|
|
35
50
|
});
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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:
|
|
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"
|
|
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"
|
|
131
|
+
files: ["**/*.mjs"],
|
|
131
132
|
|
|
132
133
|
languageOptions: {
|
|
133
134
|
sourceType: "module",
|
|
134
135
|
parserOptions: {},
|
|
135
136
|
},
|
|
136
137
|
}, {
|
|
137
|
-
files: ["**/*.ts"
|
|
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.
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
|
-
"types": "dist/
|
|
6
|
+
"types": "dist/embed.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./dist/
|
|
9
|
+
"types": "./dist/embed.d.ts",
|
|
10
10
|
"default": "./dist/embed.js"
|
|
11
11
|
},
|
|
12
12
|
"./core": {
|
|
13
|
-
"types": "./dist/
|
|
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": "^
|
|
29
|
+
"@eslint/js": "^10.0.1",
|
|
31
30
|
"@types/geojson": "^7946.0.16",
|
|
32
|
-
"@types/
|
|
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": "^
|
|
36
|
+
"eslint": "^10.14.0",
|
|
39
37
|
"eslint-config-prettier": "^10.1.8",
|
|
40
|
-
"eslint-plugin-import": "^
|
|
38
|
+
"eslint-plugin-import-x": "^4.17.1",
|
|
41
39
|
"eslint-plugin-promise": "^7.2.1",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
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": "^
|
|
54
|
-
"vitest": "^
|
|
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.
|
|
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.
|
|
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 {
|
|
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 {
|
|
16
|
-
|
|
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
|
-
|
|
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(
|
|
350
|
-
'/en
|
|
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(
|
|
358
|
-
'/ja
|
|
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)', () => {
|
package/src/lib/parse-atts.ts
CHANGED
|
@@ -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
|
|
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
|
|
131
|
+
return JSON.parse(el.textContent) as FeatureCollection;
|
|
131
132
|
}
|
|
132
133
|
return value;
|
|
133
134
|
};
|