@geolonia/embed 6.0.0-pre.5 → 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 (43) hide show
  1. package/.github/workflows/build.yml +4 -4
  2. package/.pinact.yml +5 -2
  3. package/.tool-versions +1 -1
  4. package/CHANGELOG.md +58 -0
  5. package/README.md +1 -1
  6. package/dist/embed +1 -1
  7. package/dist/embed-chunks/{d1fe32cb4bfb0e9c6575.js → 124e026690b0fa17700b.js} +1 -1
  8. package/dist/embed-chunks/9734b8bdf9fe84261b54.js +2 -0
  9. package/dist/embed-chunks/ae36f6b8e34f85ae3045.js +2 -0
  10. package/dist/embed-chunks/{4b5b1b54a5dac816ef15.js → db5eea9dfc49d1cf19e7.js} +1 -1
  11. package/dist/embed-core.d.ts +1 -1
  12. package/dist/embed-core.js +1 -1
  13. package/dist/embed-core.js.LICENSE.txt +1 -1
  14. package/dist/embed.d.ts +3 -3
  15. package/dist/embed.js +1 -1
  16. package/dist/embed.js.LICENSE.txt +1 -1
  17. package/dist/lib/parse-atts.d.ts +1 -1
  18. package/dist/lib/render.d.ts +2 -2
  19. package/dist/types-internal.d.ts +4 -0
  20. package/dist/types.d.ts +47 -6
  21. package/dist/version.d.ts +1 -1
  22. package/e2e/data-driven.spec.ts +61 -0
  23. package/eslint.config.js +15 -48
  24. package/package.json +15 -20
  25. package/src/embed-core.ts +5 -1
  26. package/src/embed.ts +7 -3
  27. package/src/lib/parse-atts.test.ts +152 -6
  28. package/src/lib/parse-atts.ts +110 -8
  29. package/src/lib/render.ts +31 -10
  30. package/src/lib/util.ts +1 -1
  31. package/src/testability.test.ts +20 -17
  32. package/src/types-internal.ts +18 -0
  33. package/src/types.ts +46 -4
  34. package/src/version.ts +1 -1
  35. package/tsconfig.build.json +5 -0
  36. package/tsconfig.json +5 -3
  37. package/webpack.config.js +2 -2
  38. package/dist/embed-chunks/00ecbfa5ec913dd002fb.js +0 -2
  39. package/dist/embed-chunks/52e84382012e7ba206d5.js +0 -2
  40. /package/dist/embed-chunks/{4574b15eb540c5efc533.js → 5f80e0235f4b38778d0d.js} +0 -0
  41. /package/dist/embed-chunks/{00ecbfa5ec913dd002fb.js.LICENSE.txt → 9734b8bdf9fe84261b54.js.LICENSE.txt} +0 -0
  42. /package/dist/embed-chunks/{52e84382012e7ba206d5.js.LICENSE.txt → ae36f6b8e34f85ae3045.js.LICENSE.txt} +0 -0
  43. /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
@@ -170,11 +170,56 @@ export type EmbedAttributes = {
170
170
  * @defaultValue `''`(off として扱われる)
171
171
  */
172
172
  '3d': string;
173
+ /**
174
+ * `data-choropleth`:`data-geojson` のポリゴンを、このプロパティの値で塗り分ける。
175
+ * 既定値はなく、指定したときだけキーが入る。
176
+ */
177
+ choropleth?: string;
178
+ /**
179
+ * `data-choropleth-colors`:塗り分けの色。値の小さい側から順にカンマで区切る。
180
+ * `data-choropleth` が無いときは無視する。
181
+ */
182
+ choroplethColors?: string;
183
+ /**
184
+ * `data-choropleth-range`:色を割り当てる値の範囲。`"最小,最大"` 形式。
185
+ * 省略時や読めないときはデータの最小値と最大値を使う。
186
+ */
187
+ choroplethRange?: string;
188
+ /**
189
+ * `data-heatmap`:`data-geojson` のポイントをヒートマップで描く。`'on'` で重みなし、
190
+ * プロパティ名でその値を重みにする。`'off'` または空なら描かない。
191
+ */
192
+ heatmap?: string;
193
+ /**
194
+ * `data-heatmap-colors`:ヒートマップの色。密度の低い側から順にカンマで区切る。
195
+ * `data-heatmap` が無いときは無視する。
196
+ */
197
+ heatmapColors?: string;
198
+ /** `data-circle-size`:ポイントの円の大きさに使うプロパティ名。 */
199
+ circleSize?: string;
200
+ /** `data-circle-color`:ポイントの円の色に使うプロパティ名。 */
201
+ circleColor?: string;
202
+ /**
203
+ * `data-circle-colors`:`data-circle-color` に使う色をカンマで区切る。
204
+ * `data-circle-size` と `data-circle-color` のどちらも無いときは無視する。
205
+ */
206
+ circleColors?: string;
173
207
  /**
174
208
  * 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
175
209
  * プラグイン固有の属性など)。
176
210
  */
177
- [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;
178
223
  };
179
224
  /**
180
225
  * 埋め込みプラグインの型。地図インスタンス、対象のコンテナ要素、正規化済みの
@@ -185,8 +230,4 @@ export type EmbedAttributes = {
185
230
  * まで保留され、そのイベント時にまとめて呼び出される。呼び出し前に削除された地図に
186
231
  * 対しては呼び出されない。
187
232
  */
188
- export type EmbedPlugin<PluginAttributes extends {
189
- [otherKey: string]: string;
190
- } = {
191
- [otherKey: string]: string;
192
- }> = (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.5";
1
+ export declare const VERSION = "6.0.0";
@@ -0,0 +1,61 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { TEST_URL, mockGeoloniaTiles, waitForStyleLoad, hasLayer } from './helper';
3
+
4
+ // embed (wrapper) 固有: data-choropleth / data-heatmap / data-circle-* を読んで
5
+ // maps-core の choropleth / heatmap / circle オプションへ渡す (embed#546)。
6
+ // 式がどう描かれるか (option → 描画) は maps-core 側 E2E (maps-core#156) が担保する。
7
+ // ここでは、属性で指定したプロパティ名と色がレイヤーの paint に届き、MapLibre が
8
+ // その式を受け付ける (error イベントもページのエラーも出ない) ことを見る。
9
+ test.describe('data-choropleth / data-heatmap / data-circle-* フォワーディング (wrapper-only)', () => {
10
+ let pageErrors: string[];
11
+
12
+ test.beforeEach(async ({ page }) => {
13
+ pageErrors = [];
14
+ page.on('pageerror', (error) => pageErrors.push(error.message));
15
+ page.on('console', (message) => {
16
+ if (message.type() === 'error') pageErrors.push(message.text());
17
+ });
18
+ await mockGeoloniaTiles(page);
19
+ await page.goto(`${TEST_URL}/data-driven.html`);
20
+ });
21
+
22
+ for (const [selector, layer, property, expected] of [
23
+ ['#choropleth', 'geolonia-simple-style-polygon', 'fill-color', ['"value"', '#00ff00', 'rgb(0, 0, 255)']],
24
+ ['#heatmap', 'geolonia-simple-style-heatmap', 'heatmap-weight', ['"weight"']],
25
+ ['#heatmap', 'geolonia-simple-style-heatmap', 'heatmap-color', ['#00ff00', '#0000ff']],
26
+ ['#circle', 'geolonia-simple-style-circle-points', 'circle-radius', ['"weight"']],
27
+ ['#circle', 'geolonia-simple-style-circle-points', 'circle-color', ['"category"', '#00ff00', '#0000ff']],
28
+ ] as const) {
29
+ test(`${selector} の ${property} に属性の指定が届く`, async ({ page }) => {
30
+ await waitForStyleLoad(page, selector);
31
+ expect(await hasLayer(page, layer, selector)).toBe(true);
32
+
33
+ // 届いていなければ paint の中身を返して、失敗時に何が入っていたかを見えるようにする
34
+ await expect
35
+ .poll(
36
+ async () => {
37
+ const paint = JSON.stringify(
38
+ await page.evaluate(
39
+ ({ sel, layer, property }) => {
40
+ const el = document.querySelector(sel) as any;
41
+ return el.geoloniaMap.getPaintProperty(layer, property);
42
+ },
43
+ { sel: selector, layer, property },
44
+ ),
45
+ );
46
+ return expected.every((s) => paint.includes(s)) ? 'ok' : paint;
47
+ },
48
+ { timeout: 5000 },
49
+ )
50
+ .toBe('ok');
51
+
52
+ // 不正な式は MapLibre が拒否して error イベントで報告する
53
+ const mapErrors = await page.evaluate(
54
+ (id) => (window as any).__mapErrors[id],
55
+ selector.slice(1),
56
+ );
57
+ expect(mapErrors).toEqual([]);
58
+ expect(pageErrors).toEqual([]);
59
+ });
60
+ }
61
+ });
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.5",
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
- "@geolonia/maps-core": "^0.6.0",
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 {
@@ -171,6 +171,152 @@ describe('attsToOptions', () => {
171
171
  });
172
172
  });
173
173
 
174
+ // data-choropleth / data-heatmap / data-circle-* (embed#546 / maps-core#156)。
175
+ describe('attsToOptions のデータ駆動の描き方', () => {
176
+ beforeEach(() => {
177
+ keyring.reset();
178
+ keyring.setApiKey('YOUR-API-KEY');
179
+ keyring.setStage('v1');
180
+ });
181
+
182
+ afterEach(() => {
183
+ keyring.reset();
184
+ });
185
+
186
+ const toOptions = (dataset: Record<string, string>) => {
187
+ const container = document.createElement('div');
188
+ Object.assign(container.dataset, dataset);
189
+ return attsToOptions(container, parseAtts(container));
190
+ };
191
+
192
+ it('属性が無ければ choropleth / heatmap / circle を渡さない', () => {
193
+ const options = toOptions({});
194
+
195
+ expect(options.choropleth).toBe(undefined);
196
+ expect(options.heatmap).toBe(undefined);
197
+ expect(options.circle).toBe(undefined);
198
+ });
199
+
200
+ it('data-choropleth はプロパティ名だけを渡す', () => {
201
+ expect(toOptions({ choropleth: 'value' }).choropleth).toEqual({
202
+ property: 'value',
203
+ });
204
+ });
205
+
206
+ it('data-choropleth-colors と data-choropleth-range を読む', () => {
207
+ const options = toOptions({
208
+ choropleth: 'value',
209
+ choroplethColors: '#ffffff, #ff0000',
210
+ choroplethRange: '0, 100',
211
+ });
212
+
213
+ expect(options.choropleth).toEqual({
214
+ property: 'value',
215
+ colors: ['#ffffff', '#ff0000'],
216
+ range: [0, 100],
217
+ });
218
+ });
219
+
220
+ it('色の区切りは括弧の中のカンマを区切りとして扱わない', () => {
221
+ const options = toOptions({
222
+ choropleth: 'value',
223
+ choroplethColors:
224
+ 'rgb(255, 255, 255),rgba(255, 0, 0, 0.5) , hsl(0, 100%, 50%)',
225
+ });
226
+
227
+ expect(options.choropleth).toEqual({
228
+ property: 'value',
229
+ colors: [
230
+ 'rgb(255, 255, 255)',
231
+ 'rgba(255, 0, 0, 0.5)',
232
+ 'hsl(0, 100%, 50%)',
233
+ ],
234
+ });
235
+ });
236
+
237
+ it('読めない data-choropleth-range は無視する', () => {
238
+ for (const range of ['abc', '1', '1,2,3', '1,x', '', '100,0', '5,5']) {
239
+ expect(
240
+ toOptions({ choropleth: 'value', choroplethRange: range }).choropleth,
241
+ ).toEqual({ property: 'value' });
242
+ }
243
+ });
244
+
245
+ it('data-choropleth が無ければ -colors と -range は無視する', () => {
246
+ const options = toOptions({
247
+ choroplethColors: '#fff,#f00',
248
+ choroplethRange: '0,1',
249
+ });
250
+
251
+ expect(options.choropleth).toBe(undefined);
252
+ });
253
+
254
+ it('data-heatmap="on" は重みなしのヒートマップにする', () => {
255
+ expect(toOptions({ heatmap: 'on' }).heatmap).toEqual({});
256
+ });
257
+
258
+ it('data-heatmap="off" と空の値はヒートマップにしない', () => {
259
+ expect(toOptions({ heatmap: 'off' }).heatmap).toBe(undefined);
260
+ expect(toOptions({ heatmap: '' }).heatmap).toBe(undefined);
261
+ });
262
+
263
+ it('data-heatmap の on / off は大文字小文字と前後の空白を区別しない', () => {
264
+ expect(toOptions({ heatmap: 'ON' }).heatmap).toEqual({});
265
+ expect(toOptions({ heatmap: ' On ' }).heatmap).toEqual({});
266
+ expect(toOptions({ heatmap: 'OFF' }).heatmap).toBe(undefined);
267
+ expect(toOptions({ heatmap: 'Off' }).heatmap).toBe(undefined);
268
+ });
269
+
270
+ it('data-heatmap のプロパティ名は大文字小文字をそのまま渡す', () => {
271
+ expect(toOptions({ heatmap: 'Weight' }).heatmap).toEqual({
272
+ weight: 'Weight',
273
+ });
274
+ });
275
+
276
+ it('data-heatmap が無ければ data-heatmap-colors は無視する', () => {
277
+ expect(toOptions({ heatmapColors: '#ff0,#f00' }).heatmap).toBe(undefined);
278
+ });
279
+
280
+ it('data-heatmap にプロパティ名を書くとその値を重みにする', () => {
281
+ expect(toOptions({ heatmap: 'weight' }).heatmap).toEqual({
282
+ weight: 'weight',
283
+ });
284
+ });
285
+
286
+ it('data-heatmap-colors を読む', () => {
287
+ expect(
288
+ toOptions({ heatmap: 'on', heatmapColors: '#ff0,#f00' }).heatmap,
289
+ ).toEqual({ colors: ['#ff0', '#f00'] });
290
+ });
291
+
292
+ it('data-circle-size と data-circle-color と data-circle-colors を読む', () => {
293
+ const options = toOptions({
294
+ circleSize: 'weight',
295
+ circleColor: 'category',
296
+ circleColors: '#f00,#0f0,#00f',
297
+ });
298
+
299
+ expect(options.circle).toEqual({
300
+ size: 'weight',
301
+ color: 'category',
302
+ colors: ['#f00', '#0f0', '#00f'],
303
+ });
304
+ });
305
+
306
+ it('data-circle-size か data-circle-color の片方だけでも円にする', () => {
307
+ expect(toOptions({ circleSize: 'weight' }).circle).toEqual({
308
+ size: 'weight',
309
+ });
310
+ expect(toOptions({ circleColor: 'category' }).circle).toEqual({
311
+ color: 'category',
312
+ });
313
+ });
314
+
315
+ it('data-circle-colors だけでは円にしない', () => {
316
+ expect(toOptions({ circleColors: '#f00' }).circle).toBe(undefined);
317
+ });
318
+ });
319
+
174
320
  // data-lang の言語解決 (embed#462 / maps-core#50)。
175
321
  // 正しい契約 (maps-core#50 のテストが基準):
176
322
  // - `ja` / `ja-jp` のみ日本語スタイル、それ以外は英語スタイル
@@ -200,17 +346,17 @@ describe('data-lang 言語解決', () => {
200
346
  it('data-lang="en" は browser が ja でも英語スタイルになる (ja にならない)', () => {
201
347
  const opts = optionsFor('en', ['ja']);
202
348
  expect(opts.lang).toBe('en');
203
- expect(getStyle('geolonia/basic-v2', { lang: 'en', apiKey: 'KEY' })).toContain(
204
- '/en.json',
205
- );
349
+ expect(
350
+ getStyle('geolonia/basic-v2', { lang: 'en', apiKey: 'KEY' }),
351
+ ).toContain('/en.json');
206
352
  });
207
353
 
208
354
  it('data-lang="ja" は browser が en でも日本語スタイルになる', () => {
209
355
  const opts = optionsFor('ja', ['en']);
210
356
  expect(opts.lang).toBe('ja');
211
- expect(getStyle('geolonia/basic-v2', { lang: 'ja', apiKey: 'KEY' })).toContain(
212
- '/ja.json',
213
- );
357
+ expect(
358
+ getStyle('geolonia/basic-v2', { lang: 'ja', apiKey: 'KEY' }),
359
+ ).toContain('/ja.json');
214
360
  });
215
361
 
216
362
  it('data-lang="ja-jp" は日本語スタイルになる (maps-core#50)', () => {