@geolonia/embed 6.0.0-pre.4 → 6.0.0-pre.6
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/dependabot.yml +89 -0
- package/.github/workflows/build.yml +84 -32
- package/.pinact.yml +83 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +32 -0
- package/README.md +36 -7
- package/dist/embed +1 -1
- package/dist/embed-chunks/{18a79c1f77cc6894d617.js → 4574b15eb540c5efc533.js} +1 -1
- package/dist/embed-chunks/{b50d8f9685823588d639.js → 4b5b1b54a5dac816ef15.js} +1 -1
- package/dist/embed-chunks/5fc1f8cd252efa958f7d.js +2 -0
- package/dist/embed-chunks/64c22ed093c8de0fcbf8.js +2 -0
- package/dist/embed-chunks/{cfb9cc05d697ae310f6a.js → d1fe32cb4bfb0e9c6575.js} +1 -1
- package/dist/embed-chunks/ffdb8e820d823ee3571c.js +1 -0
- package/dist/embed-core.js +2 -1
- package/dist/embed-core.js.LICENSE.txt +4 -0
- package/dist/embed.js +1 -1
- package/dist/embed.js.LICENSE.txt +1 -1
- package/dist/types.d.ts +34 -0
- package/dist/version.d.ts +1 -1
- package/e2e/data-driven.spec.ts +61 -0
- package/e2e/helper.ts +2 -1
- package/e2e/production-bundle.spec.ts +56 -0
- package/package.json +22 -22
- package/playwright.config.ts +1 -1
- package/pnpm-workspace.yaml +23 -0
- package/src/lib/parse-atts.test.ts +146 -0
- package/src/lib/parse-atts.ts +102 -1
- package/src/types.ts +34 -0
- package/src/version.ts +1 -1
- package/webpack.config.js +27 -1
- package/dist/embed-chunks/88308c97950af0326501.js +0 -1
- package/dist/embed-chunks/c22ad704365fc721df0a.js +0 -2
- package/dist/embed-chunks/ec26dd45d3c0fe2695b2.js +0 -2
- /package/dist/embed-chunks/{c22ad704365fc721df0a.js.LICENSE.txt → 5fc1f8cd252efa958f7d.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{ec26dd45d3c0fe2695b2.js.LICENSE.txt → 64c22ed093c8de0fcbf8.js.LICENSE.txt} +0 -0
package/dist/types.d.ts
CHANGED
|
@@ -170,6 +170,40 @@ 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
|
* プラグイン固有の属性など)。
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "6.0.0-pre.
|
|
1
|
+
export declare const VERSION = "6.0.0-pre.6";
|
|
@@ -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/e2e/helper.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Page } from '@playwright/test';
|
|
2
2
|
|
|
3
|
-
export const
|
|
3
|
+
export const BASE_URL = 'http://localhost:3000';
|
|
4
|
+
export const TEST_URL = `${BASE_URL}/e2e`;
|
|
4
5
|
export const LOAD_TIMEOUT = 5000;
|
|
5
6
|
|
|
6
7
|
/** 地図コンテナと canvas の出現を待つ。既存テスト互換。 */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { test, expect } from '@playwright/test';
|
|
2
|
+
import { BASE_URL, TEST_URL, mockGeoloniaTiles, waitForStyleLoad } from './helper';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* production 出力 (`dist/embed.js` を docs/ へコピーしたもの) を直接読み込んで検証する。
|
|
6
|
+
*
|
|
7
|
+
* 他の spec が読む `../embed` は dev サーバーが生成するバンドルで、mode も
|
|
8
|
+
* minify も production とは別物。配布するのは production 出力のほうなのに、
|
|
9
|
+
* これまでどこでも実行されていなかった。
|
|
10
|
+
*
|
|
11
|
+
* minify やローダーの更新で production だけが壊れる事故を拾うのが目的。実際
|
|
12
|
+
* #527 の css-loader 7 / style-loader 4 への更新では、production バンドルが
|
|
13
|
+
* CSS を注入できるかを確かめる手段が無く、その場限りのテストを書いて確認していた。
|
|
14
|
+
*/
|
|
15
|
+
const BUNDLE_URL = `${BASE_URL}/embed.js`;
|
|
16
|
+
|
|
17
|
+
test.describe('production バンドル', () => {
|
|
18
|
+
test('地図が描画され、CSS が注入される', async ({ page, request }) => {
|
|
19
|
+
// `docs/embed.js` は .gitignore 対象で、`pnpm run build` でしか作られない。
|
|
20
|
+
// CI は build ジョブの成果物を展開しているので、無ければ設定の不備として落とす。
|
|
21
|
+
const bundle = await request.get(BUNDLE_URL);
|
|
22
|
+
if (!bundle.ok()) {
|
|
23
|
+
if (process.env.CI) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`${BUNDLE_URL} が ${bundle.status()} を返しました。` +
|
|
26
|
+
'e2e ジョブで build ジョブの成果物が展開されているか確認してください。',
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
test.skip(
|
|
30
|
+
true,
|
|
31
|
+
'`pnpm run build` を実行すると production バンドルの検証が走ります',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const errors: string[] = [];
|
|
36
|
+
page.on('pageerror', (e) => errors.push(e.message));
|
|
37
|
+
|
|
38
|
+
await mockGeoloniaTiles(page);
|
|
39
|
+
await page.goto(`${TEST_URL}/production-bundle.html`);
|
|
40
|
+
await waitForStyleLoad(page, '#map');
|
|
41
|
+
|
|
42
|
+
await expect(page.locator('#map canvas')).toBeVisible();
|
|
43
|
+
|
|
44
|
+
// style-loader が maplibre の CSS を <style> として注入しているか。
|
|
45
|
+
// ローダーの更新でここが壊れるとコントロール類の見た目だけが崩れ、
|
|
46
|
+
// canvas は出るので気づきにくい。
|
|
47
|
+
const injectedMaplibreCss = await page.evaluate(() =>
|
|
48
|
+
[...document.querySelectorAll('style')].some((s) =>
|
|
49
|
+
s.textContent?.includes('maplibregl-ctrl'),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
expect(injectedMaplibreCss).toBe(true);
|
|
53
|
+
|
|
54
|
+
expect(errors).toEqual([]);
|
|
55
|
+
});
|
|
56
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "6.0.0-pre.
|
|
3
|
+
"version": "6.0.0-pre.6",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "dist/src/embed.d.ts",
|
|
@@ -14,18 +14,6 @@
|
|
|
14
14
|
"default": "./dist/embed-core.js"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"start": "MAP_PLATFORM_STAGE=v1 webpack serve --config ./docs/webpack.config.js",
|
|
19
|
-
"build": "npm run build:version && npm run build:embed",
|
|
20
|
-
"build:version": "node ./scripts/build-version.mjs",
|
|
21
|
-
"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/",
|
|
22
|
-
"analyze": "ANALYZE=true MAP_PLATFORM_STAGE=v1 webpack --mode production",
|
|
23
|
-
"format": "prettier \"./src/**/*.ts\" --write",
|
|
24
|
-
"lint": "eslint .",
|
|
25
|
-
"test": "vitest run",
|
|
26
|
-
"e2e": "playwright test",
|
|
27
|
-
"docs:api": "typedoc"
|
|
28
|
-
},
|
|
29
17
|
"author": "Geolonia (https://geolonia.com)",
|
|
30
18
|
"repository": {
|
|
31
19
|
"type": "git",
|
|
@@ -40,12 +28,12 @@
|
|
|
40
28
|
"@eslint/compat": "^1.4.1",
|
|
41
29
|
"@eslint/eslintrc": "^3.3.1",
|
|
42
30
|
"@eslint/js": "^9.39.1",
|
|
31
|
+
"@types/geojson": "^7946.0.16",
|
|
43
32
|
"@types/jsdom": "^21.1.7",
|
|
44
33
|
"@types/node": "^24.0.4",
|
|
45
34
|
"@typescript-eslint/eslint-plugin": "^8.46.4",
|
|
46
35
|
"@typescript-eslint/parser": "^8.46.4",
|
|
47
|
-
"
|
|
48
|
-
"css-loader": "^6.7.2",
|
|
36
|
+
"css-loader": "^7.1.5",
|
|
49
37
|
"esbuild": "^0.28.2",
|
|
50
38
|
"eslint": "^9.39.1",
|
|
51
39
|
"eslint-config-prettier": "^10.1.8",
|
|
@@ -57,7 +45,7 @@
|
|
|
57
45
|
"jsdom": "^29.1.1",
|
|
58
46
|
"node-fetch": "2",
|
|
59
47
|
"prettier": "^3.6.2",
|
|
60
|
-
"style-loader": "^
|
|
48
|
+
"style-loader": "^4.0.0",
|
|
61
49
|
"svg-inline-loader": "^0.8.2",
|
|
62
50
|
"ts-loader": "^9.4.3",
|
|
63
51
|
"typedoc": "^0.28.20",
|
|
@@ -65,13 +53,25 @@
|
|
|
65
53
|
"typescript": "^5.1.3",
|
|
66
54
|
"vitest": "^4.1.1",
|
|
67
55
|
"webpack": "^5.75.0",
|
|
68
|
-
"webpack-bundle-analyzer": "^4.
|
|
69
|
-
"webpack-cli": "^
|
|
70
|
-
"webpack-dev-server": "^
|
|
56
|
+
"webpack-bundle-analyzer": "^5.4.0",
|
|
57
|
+
"webpack-cli": "^7.2.3",
|
|
58
|
+
"webpack-dev-server": "^6.0.0"
|
|
71
59
|
},
|
|
72
60
|
"dependencies": {
|
|
73
|
-
"@geolonia/maps-core": "^0.
|
|
61
|
+
"@geolonia/maps-core": "^0.8.0",
|
|
74
62
|
"@playwright/test": "^1.61.1",
|
|
75
|
-
"maplibre-gl": "6.
|
|
63
|
+
"maplibre-gl": "6.12.0"
|
|
64
|
+
},
|
|
65
|
+
"scripts": {
|
|
66
|
+
"start": "MAP_PLATFORM_STAGE=v1 webpack serve --config ./docs/webpack.config.js",
|
|
67
|
+
"build": "pnpm run build:version && pnpm run build:embed",
|
|
68
|
+
"build:version": "node ./scripts/build-version.mjs",
|
|
69
|
+
"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/",
|
|
70
|
+
"analyze": "ANALYZE=true MAP_PLATFORM_STAGE=v1 webpack --mode production",
|
|
71
|
+
"format": "prettier \"./src/**/*.ts\" --write",
|
|
72
|
+
"lint": "eslint .",
|
|
73
|
+
"test": "vitest run",
|
|
74
|
+
"e2e": "playwright test",
|
|
75
|
+
"docs:api": "typedoc"
|
|
76
76
|
}
|
|
77
|
-
}
|
|
77
|
+
}
|
package/playwright.config.ts
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# pnpm の設定ファイル。pnpm 11 以降、これらの設定は .npmrc ではなくここで指定する。
|
|
2
|
+
#
|
|
3
|
+
# ignoreScripts: 依存パッケージのライフサイクルスクリプトを実行しない。
|
|
4
|
+
# 以前は .npmrc の `ignore-scripts=true` で同じことをしていたが、pnpm は .npmrc の
|
|
5
|
+
# この設定を読まないため移設した。設定が無いと pnpm は esbuild のビルドスクリプトを
|
|
6
|
+
# 無視したことを ERR_PNPM_IGNORED_BUILDS として扱い、install が失敗する。
|
|
7
|
+
# esbuild は 0.25 以降プラットフォーム別パッケージを optionalDependencies で解決するので、
|
|
8
|
+
# ビルドスクリプトを実行しなくても動作する。
|
|
9
|
+
ignoreScripts: true
|
|
10
|
+
|
|
11
|
+
# pmOnFail: `packageManager` のバージョン不一致チェックをスキップする
|
|
12
|
+
# (pnpm のドキュメント上は旧 `managePackageManagerVersions: false` 相当)。
|
|
13
|
+
#
|
|
14
|
+
# 既定の `download` だと、pnpm 12 は宣言された pnpm 自身を解決するための
|
|
15
|
+
# "env lockfile" を pnpm-lock.yaml の 1 つ目の YAML ドキュメントとして書く。
|
|
16
|
+
# GitHub の依存グラフの静的パーサーは 1 つ目しか読まないため、グラフには
|
|
17
|
+
# pnpm と @pnpm/exe.* だけが載り、npm パッケージが 1 つも入らなくなる。
|
|
18
|
+
# その結果 Dependabot アラートも届かない (dependabot/dependabot-core#15904)。
|
|
19
|
+
#
|
|
20
|
+
# `ignore` にすると env lockfile が作られず lock は単一ドキュメントに戻るので、
|
|
21
|
+
# パーサーが実依存を読めるようになる。
|
|
22
|
+
# CI は pnpm/action-setup が packageManager を読んで版を揃えるため影響はない。
|
|
23
|
+
pmOnFail: ignore
|
|
@@ -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` のみ日本語スタイル、それ以外は英語スタイル
|
package/src/lib/parse-atts.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import type { ControlPosition } from 'maplibre-gl';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
getLang,
|
|
6
|
+
keyring,
|
|
7
|
+
type ChoroplethOptions,
|
|
8
|
+
type CircleOptions,
|
|
9
|
+
type GeoloniaMapOptions,
|
|
10
|
+
type HeatmapOptions,
|
|
11
|
+
} from '@geolonia/maps-core';
|
|
5
12
|
import type { EmbedAttributes } from '../types';
|
|
6
13
|
|
|
7
14
|
type ParseAttsParams = {
|
|
@@ -125,6 +132,99 @@ const resolveGeojson = (
|
|
|
125
132
|
return value;
|
|
126
133
|
};
|
|
127
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Split a comma-separated list of CSS colors. Commas inside parentheses
|
|
137
|
+
* (`rgb(0, 0, 0)`) are part of the color, not separators.
|
|
138
|
+
*/
|
|
139
|
+
const parseColors = (value: string): string[] => {
|
|
140
|
+
const colors: string[] = [];
|
|
141
|
+
let depth = 0;
|
|
142
|
+
let current = '';
|
|
143
|
+
for (const char of value) {
|
|
144
|
+
if (char === '(') depth++;
|
|
145
|
+
if (char === ')') depth = Math.max(0, depth - 1);
|
|
146
|
+
if (char === ',' && depth === 0) {
|
|
147
|
+
colors.push(current);
|
|
148
|
+
current = '';
|
|
149
|
+
} else {
|
|
150
|
+
current += char;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
colors.push(current);
|
|
154
|
+
return colors.map((c) => c.trim()).filter((c) => c !== '');
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Parse `"min,max"` into a range, or `undefined` when it is not two numbers
|
|
159
|
+
* with min < max (a reversed range would paint everything in one color).
|
|
160
|
+
*/
|
|
161
|
+
const parseRange = (value: string): [number, number] | undefined => {
|
|
162
|
+
const parts = value.split(',').map((n) => n.trim());
|
|
163
|
+
if (parts.length !== 2 || parts.some((n) => n === '')) {
|
|
164
|
+
return undefined;
|
|
165
|
+
}
|
|
166
|
+
const [min, max] = parts.map(Number);
|
|
167
|
+
if (!Number.isFinite(min) || !Number.isFinite(max) || min >= max) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
return [min, max];
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Convert `data-choropleth` / `data-heatmap` / `data-circle-*` into maps-core's
|
|
175
|
+
* data-driven options. The `-colors` / `-range` attributes only apply when the
|
|
176
|
+
* attribute that turns the drawing on is present.
|
|
177
|
+
*/
|
|
178
|
+
const dataDrivenOptions = (
|
|
179
|
+
atts: EmbedAttributes,
|
|
180
|
+
): Pick<GeoloniaMapOptions, 'choropleth' | 'heatmap' | 'circle'> => {
|
|
181
|
+
const options: Pick<GeoloniaMapOptions, 'choropleth' | 'heatmap' | 'circle'> =
|
|
182
|
+
{};
|
|
183
|
+
|
|
184
|
+
if (atts.choropleth) {
|
|
185
|
+
const choropleth: ChoroplethOptions = { property: String(atts.choropleth) };
|
|
186
|
+
if (atts.choroplethColors) {
|
|
187
|
+
choropleth.colors = parseColors(String(atts.choroplethColors));
|
|
188
|
+
}
|
|
189
|
+
const range = atts.choroplethRange
|
|
190
|
+
? parseRange(String(atts.choroplethRange))
|
|
191
|
+
: undefined;
|
|
192
|
+
if (range) {
|
|
193
|
+
choropleth.range = range;
|
|
194
|
+
}
|
|
195
|
+
options.choropleth = choropleth;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const heatmapValue = String(atts.heatmap ?? '').trim();
|
|
199
|
+
const heatmapFlag = heatmapValue.toLowerCase();
|
|
200
|
+
if (heatmapValue && heatmapFlag !== 'off') {
|
|
201
|
+
const heatmap: HeatmapOptions = {};
|
|
202
|
+
if (heatmapFlag !== 'on') {
|
|
203
|
+
heatmap.weight = heatmapValue;
|
|
204
|
+
}
|
|
205
|
+
if (atts.heatmapColors) {
|
|
206
|
+
heatmap.colors = parseColors(String(atts.heatmapColors));
|
|
207
|
+
}
|
|
208
|
+
options.heatmap = heatmap;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (atts.circleSize || atts.circleColor) {
|
|
212
|
+
const circle: CircleOptions = {};
|
|
213
|
+
if (atts.circleSize) {
|
|
214
|
+
circle.size = String(atts.circleSize);
|
|
215
|
+
}
|
|
216
|
+
if (atts.circleColor) {
|
|
217
|
+
circle.color = String(atts.circleColor);
|
|
218
|
+
}
|
|
219
|
+
if (atts.circleColors) {
|
|
220
|
+
circle.colors = parseColors(String(atts.circleColors));
|
|
221
|
+
}
|
|
222
|
+
options.circle = circle;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return options;
|
|
226
|
+
};
|
|
227
|
+
|
|
128
228
|
/**
|
|
129
229
|
* Convert normalised {@link EmbedAttributes} into a typed `GeoloniaMapOptions`
|
|
130
230
|
* for maps-core's `GeoloniaMap` constructor.
|
|
@@ -195,6 +295,7 @@ export const attsToOptions = (
|
|
|
195
295
|
if (atts.simpleVector) {
|
|
196
296
|
options.simpleVector = String(atts.simpleVector);
|
|
197
297
|
}
|
|
298
|
+
Object.assign(options, dataDrivenOptions(atts));
|
|
198
299
|
|
|
199
300
|
if (
|
|
200
301
|
atts.minZoom !== '' &&
|
package/src/types.ts
CHANGED
|
@@ -171,6 +171,40 @@ export type EmbedAttributes = {
|
|
|
171
171
|
* @defaultValue `''`(off として扱われる)
|
|
172
172
|
*/
|
|
173
173
|
'3d': string;
|
|
174
|
+
/**
|
|
175
|
+
* `data-choropleth`:`data-geojson` のポリゴンを、このプロパティの値で塗り分ける。
|
|
176
|
+
* 既定値はなく、指定したときだけキーが入る。
|
|
177
|
+
*/
|
|
178
|
+
choropleth?: string;
|
|
179
|
+
/**
|
|
180
|
+
* `data-choropleth-colors`:塗り分けの色。値の小さい側から順にカンマで区切る。
|
|
181
|
+
* `data-choropleth` が無いときは無視する。
|
|
182
|
+
*/
|
|
183
|
+
choroplethColors?: string;
|
|
184
|
+
/**
|
|
185
|
+
* `data-choropleth-range`:色を割り当てる値の範囲。`"最小,最大"` 形式。
|
|
186
|
+
* 省略時や読めないときはデータの最小値と最大値を使う。
|
|
187
|
+
*/
|
|
188
|
+
choroplethRange?: string;
|
|
189
|
+
/**
|
|
190
|
+
* `data-heatmap`:`data-geojson` のポイントをヒートマップで描く。`'on'` で重みなし、
|
|
191
|
+
* プロパティ名でその値を重みにする。`'off'` または空なら描かない。
|
|
192
|
+
*/
|
|
193
|
+
heatmap?: string;
|
|
194
|
+
/**
|
|
195
|
+
* `data-heatmap-colors`:ヒートマップの色。密度の低い側から順にカンマで区切る。
|
|
196
|
+
* `data-heatmap` が無いときは無視する。
|
|
197
|
+
*/
|
|
198
|
+
heatmapColors?: string;
|
|
199
|
+
/** `data-circle-size`:ポイントの円の大きさに使うプロパティ名。 */
|
|
200
|
+
circleSize?: string;
|
|
201
|
+
/** `data-circle-color`:ポイントの円の色に使うプロパティ名。 */
|
|
202
|
+
circleColor?: string;
|
|
203
|
+
/**
|
|
204
|
+
* `data-circle-colors`:`data-circle-color` に使う色をカンマで区切る。
|
|
205
|
+
* `data-circle-size` と `data-circle-color` のどちらも無いときは無視する。
|
|
206
|
+
*/
|
|
207
|
+
circleColors?: string;
|
|
174
208
|
/**
|
|
175
209
|
* 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
|
|
176
210
|
* プラグイン固有の属性など)。
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '6.0.0-pre.
|
|
1
|
+
export const VERSION = '6.0.0-pre.6';
|
package/webpack.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
|
3
|
-
const { DefinePlugin } = require('webpack');
|
|
3
|
+
const { BannerPlugin, DefinePlugin } = require('webpack');
|
|
4
4
|
const esbuild = require('esbuild');
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -27,11 +27,37 @@ const bundleMaplibreWorkerSource = () => {
|
|
|
27
27
|
return result.outputFiles[0].text;
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* バンドルした maplibre-gl のライセンス表記。
|
|
32
|
+
*
|
|
33
|
+
* maplibre-gl のソース先頭には `@license` コメントがあり、通常は terser の
|
|
34
|
+
* extractComments が `<bundle>.js.LICENSE.txt` へ切り出す。ただし terser はコメント単体
|
|
35
|
+
* ではなく「コメントが付いているコード」を基準に扱うため、そのコードが削除・並べ替えされると
|
|
36
|
+
* コメントごと消え、extractComments まで届かない。
|
|
37
|
+
*
|
|
38
|
+
* embed.js は `Object.assign(..., maplibregl, ...)` で名前空間を丸ごと使うので偶然残るが、
|
|
39
|
+
* embed-core.js は一部のシンボルしか使わないため消える。実際 6.0.0-pre.4 の
|
|
40
|
+
* `dist/embed-core.js` は maplibre を同梱しながらライセンス表記が無い状態で公開された
|
|
41
|
+
* (6.0.0-pre.3 までは残っていた)。偶然に頼らず明示する。
|
|
42
|
+
*
|
|
43
|
+
* バージョンは maplibre-gl から読むので手で追従する必要はない。maplibre を同梱しなくなったら
|
|
44
|
+
* この banner も外すこと。
|
|
45
|
+
*/
|
|
46
|
+
const maplibreLicenseBanner = `/**
|
|
47
|
+
* MapLibre GL JS
|
|
48
|
+
* @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v${require('maplibre-gl/package.json').version}/LICENSE.txt
|
|
49
|
+
*/`;
|
|
50
|
+
|
|
30
51
|
const plugins = [
|
|
31
52
|
new DefinePlugin({
|
|
32
53
|
'process.env.MAP_PLATFORM_STAGE': JSON.stringify(process.env.MAP_PLATFORM_STAGE || 'dev'),
|
|
33
54
|
__MAPLIBRE_WORKER_SOURCE__: JSON.stringify(bundleMaplibreWorkerSource()),
|
|
34
55
|
}),
|
|
56
|
+
new BannerPlugin({
|
|
57
|
+
banner: maplibreLicenseBanner,
|
|
58
|
+
raw: true,
|
|
59
|
+
entryOnly: true,
|
|
60
|
+
}),
|
|
35
61
|
];
|
|
36
62
|
if (process.env.ANALYZE === 'true') {
|
|
37
63
|
plugins.push(new BundleAnalyzerPlugin());
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunkgeoloniaEmbedCore=self.webpackChunkgeoloniaEmbedCore||[]).push([[445],{9746(){},9977(){},197(){},1866(){},2739(){}}]);
|