@geolonia/embed 5.2.2 → 6.0.0-pre.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.github/workflows/build.yml +25 -1
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +24 -1
  4. package/dist/embed +1 -1
  5. package/dist/embed-chunks/4ada77b78cc0cc5ccef9.js +1 -0
  6. package/dist/embed-chunks/8176630945512b29f294.js +2 -0
  7. package/dist/embed-chunks/c783fffcd28083f7d5cb.js +2 -0
  8. package/dist/embed-chunks/f2124097fda51d0079ee.js +1 -0
  9. package/dist/embed-core.d.ts +6 -7
  10. package/dist/embed-core.js +1 -1
  11. package/dist/embed.d.ts +2 -4
  12. package/dist/embed.js +1 -1
  13. package/dist/lib/parse-atts.d.ts +19 -0
  14. package/dist/lib/render.d.ts +1 -1
  15. package/dist/lib/util.d.ts +14 -55
  16. package/dist/types.d.ts +155 -1
  17. package/dist/version.d.ts +1 -1
  18. package/e2e/auto-render.spec.ts +44 -0
  19. package/e2e/basic.spec.ts +10 -74
  20. package/e2e/cleanup.spec.ts +43 -0
  21. package/e2e/data-attributes.spec.ts +56 -0
  22. package/e2e/globals.spec.ts +51 -0
  23. package/e2e/helper.ts +170 -4
  24. package/e2e/iframe.spec.ts +35 -0
  25. package/e2e/lazy-loading.spec.ts +32 -0
  26. package/e2e/legacy-constructor.spec.ts +102 -0
  27. package/e2e/plugin.spec.ts +25 -0
  28. package/e2e/pmtiles.spec.ts +13 -0
  29. package/package.json +8 -11
  30. package/playwright.config.ts +6 -32
  31. package/src/embed-core.ts +12 -14
  32. package/src/embed.ts +2 -4
  33. package/src/lib/parse-atts.test.ts +186 -18
  34. package/src/lib/parse-atts.ts +151 -5
  35. package/src/lib/render.ts +50 -12
  36. package/src/lib/util.ts +37 -350
  37. package/src/types.ts +155 -1
  38. package/src/version.ts +1 -1
  39. package/typedoc.json +13 -0
  40. package/vitest.config.ts +7 -0
  41. package/dist/embed-chunks/12cbd0d1cb4cf744c32f.js +0 -2
  42. package/dist/embed-chunks/8a521e8312a5b4da123d.js +0 -2
  43. package/dist/lib/CustomAttributionControl.d.ts +0 -47
  44. package/dist/lib/controls/geolonia-control.d.ts +0 -7
  45. package/dist/lib/geolonia-map.d.ts +0 -30
  46. package/dist/lib/geolonia-marker.d.ts +0 -9
  47. package/dist/lib/keyring.d.ts +0 -45
  48. package/dist/lib/maplibre-util.d.ts +0 -25
  49. package/dist/lib/simplestyle-vector.d.ts +0 -26
  50. package/dist/lib/simplestyle.d.ts +0 -31
  51. package/e2e/external-style.spec.ts +0 -25
  52. package/e2e/map.spec.ts +0 -69
  53. package/src/lib/CustomAttributionControl.ts +0 -394
  54. package/src/lib/controls/geolonia-control.ts +0 -38
  55. package/src/lib/geolonia-map.ts +0 -429
  56. package/src/lib/geolonia-marker.ts +0 -53
  57. package/src/lib/keyring.test.ts +0 -127
  58. package/src/lib/keyring.ts +0 -136
  59. package/src/lib/maplibre-util.ts +0 -137
  60. package/src/lib/marker.svg +0 -1
  61. package/src/lib/simplestyle-vector.ts +0 -257
  62. package/src/lib/simplestyle.test.ts +0 -289
  63. package/src/lib/simplestyle.ts +0 -435
  64. package/src/lib/util.test.ts +0 -364
  65. /package/dist/embed-chunks/{12cbd0d1cb4cf744c32f.js.LICENSE.txt → 8176630945512b29f294.js.LICENSE.txt} +0 -0
  66. /package/dist/embed-chunks/{8a521e8312a5b4da123d.js.LICENSE.txt → c783fffcd28083f7d5cb.js.LICENSE.txt} +0 -0
@@ -1,6 +1,25 @@
1
+ import { type GeoloniaMapOptions } from '@geolonia/maps-core';
1
2
  import type { EmbedAttributes } from '../types';
2
3
  type ParseAttsParams = {
3
4
  interactive?: boolean;
4
5
  };
6
+ /**
7
+ * Read the `data-*` attributes off a map container and normalise them into the
8
+ * embed's `EmbedAttributes` shape (string values, `'on'`/`'off'` flags).
9
+ *
10
+ * This is the value handed to registered plugins, so its shape is kept stable
11
+ * for backward compatibility. The map itself is constructed from
12
+ * {@link attsToOptions}, which converts these into a typed
13
+ * `GeoloniaMapOptions` for maps-core.
14
+ */
5
15
  declare const _default: (container: any, params?: ParseAttsParams) => EmbedAttributes;
6
16
  export default _default;
17
+ /**
18
+ * Convert normalised {@link EmbedAttributes} into a typed `GeoloniaMapOptions`
19
+ * for maps-core's `GeoloniaMap` constructor.
20
+ *
21
+ * `center` is only set when both `data-lat` and `data-lng` are present so that
22
+ * maps-core keeps its default marker gating (marker requires a center) and
23
+ * GeoJSON `fitBounds` (skipped only when an explicit center is given).
24
+ */
25
+ export declare const attsToOptions: (container: HTMLElement, atts: EmbedAttributes) => GeoloniaMapOptions;
@@ -1,5 +1,5 @@
1
1
  import 'maplibre-gl/dist/maplibre-gl.css';
2
2
  import '../style.css';
3
- import GeoloniaMap from './geolonia-map';
3
+ import { GeoloniaMap } from '@geolonia/maps-core';
4
4
  export declare const renderGeoloniaMap: () => void;
5
5
  export declare const registerPlugin: (plugin: (map: GeoloniaMap, target: HTMLElement, atts: any) => void) => void;
@@ -1,61 +1,20 @@
1
- import type { GetResourceResponse, MapOptions, MarkerOptions, ExpiryData } from 'maplibre-gl';
2
- export type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
3
1
  /**
2
+ * Parse the Geolonia API key from the `?geolonia-api-key=` query of the
3
+ * embed `<script>` tag (backward compatibility).
4
4
  *
5
- * @param {string} str target URL string
6
- * @return {string|false} Resolved URL or false if not resolved
7
- */
8
- export declare function isURL(str: string): string | false;
9
- export declare function isGeoloniaTilesHost(url: string | URL): boolean;
10
- export declare function checkPermission(): boolean;
11
- export declare function getLang(): "ja" | "en";
12
- /**
13
- * Detects the window is scrollable.
14
- */
15
- export declare function isScrollable(): boolean;
16
- /**
17
- * Detects the object is HTMLElement?
18
- *
19
- * @param {*} o
20
- */
21
- export declare function isDomElement(o: any): o is HTMLElement;
22
- /**
23
- * Gets the HTMLElement for the map.
24
- * Possibility args are HTMLElement or CSS selector or object that has container property.
5
+ * maps-core's keyring no longer scans the DOM, so this embed-specific
6
+ * helper reads the script tag and returns the key/stage for the caller to
7
+ * push into the keyring via `setApiKey()` / `setStage()`.
25
8
  *
26
- * @param {*} arg
27
- * @return {HTMLElement | false}
9
+ * @param doc Document to scan (defaults to the global `document`)
10
+ * @returns `{ apiKey, stage }` when found, otherwise `null`
28
11
  */
29
- export declare function getContainer(arg: HTMLElement | string | {
30
- container: HTMLElement | string;
31
- }): HTMLElement | false;
12
+ export declare function parseScriptTagApiKey(doc?: Document): {
13
+ apiKey: string;
14
+ stage: string;
15
+ } | null;
32
16
  /**
33
- * Merge legacyOptions into options for geolonia.Marker class
34
- *
35
- * @param {*} options
36
- * @param {*} legacyOptions
37
- */
38
- export declare function handleMarkerOptions(options: MarkerOptions | null | undefined | false, legacyOptions: MarkerOptions): MarkerOptions;
39
- export declare function getStyle(style: any, atts: any): any;
40
- export declare function getOptions(container: any, params: any, atts: any): MapOptions;
41
- /**
42
- *
43
- * @param {string} an data-*-control Embed attribute
44
- * @returns { enabled: boolean, position: 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left' | void }
17
+ * Detect whether the embed is allowed to render in the current (possibly
18
+ * iframed) context. Embed-specific: not provided by maps-core.
45
19
  */
46
- export declare function parseControlOption(att: any): {
47
- enabled: boolean;
48
- position: any;
49
- };
50
- /**
51
- *
52
- * @param {number} digits for session
53
- * @returns sessionId
54
- */
55
- export declare const getSessionId: (digit: any) => string;
56
- export declare const parseSimpleVector: (attributeValue: any) => any;
57
- export declare const handleRestrictedMode: (map: any) => void;
58
- export declare const handleErrorMode: (container: any) => void;
59
- export declare const sanitizeDescription: (description: any) => Promise<any>;
60
- export declare const random: (max: number) => number;
61
- export declare function loadImageCompatibility(promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>, callback: GetImageCallback): void;
20
+ export declare function checkPermission(): boolean;
package/dist/types.d.ts CHANGED
@@ -1,36 +1,190 @@
1
- import type GeoloniaMap from './lib/geolonia-map';
1
+ import type { GeoloniaMap } from '@geolonia/maps-core';
2
+ /**
3
+ * `.geolonia` の地図コンテナから読み取った `data-*` 属性を正規化した形。
4
+ *
5
+ * 各プロパティは kebab-case の `data-*` 属性に対応する(`markerColor` は
6
+ * `data-marker-color`、`'3d'` は `data-3d`)。
7
+ * `parseAtts` がコンテナの `dataset` を読み、以下に示す既定値を補う。
8
+ * `data-*` で指定された値は文字列のまま保持され、未指定の数値フィールドには
9
+ * 数値の既定値が入る。on/off のフラグはリテラル文字列 `'on'` / `'off'` である。
10
+ * この形はそのまま登録済みの {@link EmbedPlugin} に渡されるため、後方互換のために
11
+ * 構造を安定させている。地図自体はこの値から `attsToOptions` を経て構築される。
12
+ */
2
13
  export type EmbedAttributes = {
14
+ /**
15
+ * `data-lat`:地図中心の緯度。中心は `data-lat` と `data-lng` の両方が
16
+ * 指定されたときにのみ適用される。
17
+ * @defaultValue `0`
18
+ */
3
19
  lat: string | number;
20
+ /**
21
+ * `data-lng`:地図中心の経度。{@link EmbedAttributes.lat} を参照。
22
+ * @defaultValue `0`
23
+ */
4
24
  lng: string | number;
25
+ /**
26
+ * `data-zoom`:初期ズームレベル。
27
+ * @defaultValue `0`
28
+ */
5
29
  zoom: string | number;
30
+ /**
31
+ * `data-bearing`:初期方位(回転)。単位は度。
32
+ * @defaultValue `0`
33
+ */
6
34
  bearing: string | number;
35
+ /**
36
+ * `data-pitch`:初期ピッチ(傾き)。単位は度。
37
+ * @defaultValue `0`
38
+ */
7
39
  pitch: string | number;
40
+ /**
41
+ * `data-hash`(`'on'` / `'off'`):地図の表示位置を URL のハッシュに同期する。
42
+ * @defaultValue `'off'`
43
+ */
8
44
  hash: string;
45
+ /**
46
+ * `data-marker`(`'on'` / `'off'`):中心にマーカーを表示する。中心が設定されて
47
+ * いるときにのみ有効({@link EmbedAttributes.lat} を参照)。
48
+ * @defaultValue `'on'`
49
+ */
9
50
  marker: string;
51
+ /**
52
+ * `data-marker-color`:中心マーカーの色。
53
+ * @defaultValue `'#E4402F'`
54
+ */
10
55
  markerColor: string;
56
+ /**
57
+ * `data-open-popup`(`'on'` / `'off'`):読み込み時にマーカーのポップアップを開く。
58
+ * @defaultValue `'off'`
59
+ */
11
60
  openPopup: string;
61
+ /**
62
+ * `data-custom-marker`:マーカーとして使う要素の CSS セレクタ。
63
+ * @defaultValue `''`
64
+ */
12
65
  customMarker: string;
66
+ /**
67
+ * `data-custom-marker-offset`:マーカーのオフセット。`"x, y"` 形式のピクセル値。
68
+ * @defaultValue `'0, 0'`
69
+ */
13
70
  customMarkerOffset: string;
71
+ /**
72
+ * `data-gesture-handling`(`'on'` / `'off'`):パン、ズーム、回転のジェスチャを
73
+ * 有効にする。地図を非インタラクティブに生成した場合は `'off'` に固定される。
74
+ * @defaultValue `'on'`
75
+ */
14
76
  gestureHandling: string;
77
+ /**
78
+ * `data-navigation-control`:ズームと回転のコントロール。`'on'` / `'off'`、または
79
+ * 表示位置(`'top-right'`、`'bottom-left'` など)を受け付ける。
80
+ * @defaultValue `'on'`
81
+ */
15
82
  navigationControl: string;
83
+ /**
84
+ * `data-geolocate-control`:現在地コントロール。`'on'` / `'off'`、または表示位置を
85
+ * 受け付ける。
86
+ * @defaultValue `'off'`
87
+ */
16
88
  geolocateControl: string;
89
+ /**
90
+ * `data-fullscreen-control`:全画面コントロール。`'on'` / `'off'`、または表示位置を
91
+ * 受け付ける。
92
+ * @defaultValue `'off'`
93
+ */
17
94
  fullscreenControl: string;
95
+ /**
96
+ * `data-scale-control`:スケールバー。`'on'` / `'off'`、または表示位置を受け付ける。
97
+ * @defaultValue `'off'`
98
+ */
18
99
  scaleControl: string;
100
+ /**
101
+ * `data-geolonia-control`:Geolonia のアトリビューション(ロゴ)コントロール。
102
+ * `'on'` / `'off'`、または表示位置を受け付ける。
103
+ * @defaultValue `'on'`
104
+ */
19
105
  geoloniaControl: string;
106
+ /**
107
+ * `data-geojson`:GeoJSON のソース。URL、インラインの JSON 文字列、または
108
+ * インライン要素(`<script type="application/json">` など)を指す CSS セレクタの
109
+ * いずれか。
110
+ * @defaultValue `''`
111
+ */
20
112
  geojson: string;
113
+ /**
114
+ * `data-cluster`(`'on'` / `'off'`):GeoJSON のポイント地物をクラスタリングする。
115
+ * @defaultValue `'on'`
116
+ */
21
117
  cluster: string;
118
+ /**
119
+ * `data-cluster-color`:クラスタ化されたポイントマーカーの色。
120
+ * @defaultValue `'#ff0000'`
121
+ */
22
122
  clusterColor: string;
123
+ /**
124
+ * `data-style`:地図スタイル。Geolonia のスタイル名(`geolonia/basic-v2`)、
125
+ * style.json の完全な URL、または相対パスのいずれか。
126
+ * @defaultValue `'geolonia/basic-v2'`
127
+ */
23
128
  style: string;
129
+ /**
130
+ * `data-lang`:ラベルの言語。`data-lang` に指定できるのは `'ja'`、`'en'`、
131
+ * `'auto'` など。`parseAtts` は `'ja'` のみを `'ja'` に解決し、それ以外の明示値は
132
+ * `'en'` に解決する(`'ja-jp'` も `'en'` になる)。`'auto'` および未指定のときは
133
+ * ブラウザ言語(`getLang()` の結果。`'ja'` または `'en'`)になる。
134
+ * @defaultValue 未指定のときは `getLang()` の結果(`'ja'` または `'en'`)
135
+ */
24
136
  lang: string;
137
+ /**
138
+ * `data-plugin`:実行する埋め込みプラグイン名。無効にする場合は `'off'`。
139
+ * @defaultValue `'off'`
140
+ */
25
141
  plugin: string;
142
+ /**
143
+ * `data-key`:Geolonia の API キー(埋め込み `<script>` タグの
144
+ * `?geolonia-api-key=` クエリで指定しない場合に使う)。
145
+ * @defaultValue キーリングが保持する現在の API キー
146
+ */
26
147
  key: string;
148
+ /**
149
+ * `data-api-url`:Geolonia API のエンドポイントのベース URL。
150
+ * @defaultValue `` `https://api.geolonia.com/${stage}` ``
151
+ */
27
152
  apiUrl: string;
153
+ /**
154
+ * `data-loader`(`'on'` / `'off'`):地図の初期化中にローディング表示を出す。
155
+ * @defaultValue `'on'`
156
+ */
28
157
  loader: string;
158
+ /**
159
+ * `data-min-zoom`:最小ズームレベル。空文字列は「未指定」を意味する。
160
+ * @defaultValue `''`
161
+ */
29
162
  minZoom: string | number;
163
+ /**
164
+ * `data-max-zoom`:最大ズームレベル。
165
+ * @defaultValue `20`
166
+ */
30
167
  maxZoom: string | number;
168
+ /**
169
+ * `data-3d`(`'on'` / `'off'`):3D 建物を描画する。
170
+ * @defaultValue `''`(off として扱われる)
171
+ */
31
172
  '3d': string;
173
+ /**
174
+ * 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
175
+ * プラグイン固有の属性など)。
176
+ */
32
177
  [otherKey: string]: string | number;
33
178
  };
179
+ /**
180
+ * 埋め込みプラグインの型。地図インスタンス、対象のコンテナ要素、正規化済みの
181
+ * {@link EmbedAttributes} を受け取って呼び出される。
182
+ *
183
+ * 呼び出しのタイミングは地図の生成時点で異なる。`DOMContentLoaded` 後に生成された
184
+ * 地図では生成直後に呼び出される。それ以前に生成された地図では `DOMContentLoaded`
185
+ * まで保留され、そのイベント時にまとめて呼び出される。呼び出し前に削除された地図に
186
+ * 対しては呼び出されない。
187
+ */
34
188
  export type EmbedPlugin<PluginAttributes extends {
35
189
  [otherKey: string]: string;
36
190
  } = {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "5.2.2";
1
+ export declare const VERSION = "6.0.0-pre.2";
@@ -0,0 +1,44 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { TEST_URL, mockGeoloniaTiles, waitForStyleLoad, hasMapInstance } from './helper';
3
+
4
+ // embed (wrapper) 固有: script タグを読むだけで .geolonia 要素が自動描画される
5
+ // (renderGeoloniaMap の DOM 走査)。maps-core は new GeoloniaMap() の明示呼び出しのみで
6
+ // この自動走査を持たない。
7
+ test.describe('DOM 自動走査 / auto-render (wrapper-only)', () => {
8
+ test('複数の .geolonia 要素が独立に描画される', async ({ page }) => {
9
+ await mockGeoloniaTiles(page);
10
+ await page.goto(`${TEST_URL}/multiple-maps.html`);
11
+
12
+ await waitForStyleLoad(page, '#map-a');
13
+ await waitForStyleLoad(page, '#map-b');
14
+ await waitForStyleLoad(page, '#map-c');
15
+
16
+ const result = await page.evaluate(() =>
17
+ ['#map-a', '#map-b', '#map-c'].map((sel) => {
18
+ const el = document.querySelector(sel) as any;
19
+ return !!el?.geoloniaMap;
20
+ }),
21
+ );
22
+ expect(result).toEqual([true, true, true]);
23
+ });
24
+
25
+ test('DOMContentLoaded 後に追加された .geolonia は自動 render されない (one-shot)', async ({ page }) => {
26
+ await mockGeoloniaTiles(page);
27
+ await page.goto(`${TEST_URL}/multiple-maps.html`);
28
+ await waitForStyleLoad(page, '#map-a');
29
+
30
+ // 後から .geolonia を追加 (即時描画されるはずの data-lazy-loading="off" 指定)
31
+ await page.evaluate(() => {
32
+ const el = document.createElement('div');
33
+ el.id = 'late-map';
34
+ el.className = 'geolonia';
35
+ el.setAttribute('data-lazy-loading', 'off');
36
+ el.setAttribute('style', 'width:400px;height:250px;');
37
+ document.body.appendChild(el);
38
+ });
39
+ await page.waitForTimeout(500);
40
+
41
+ // renderGeoloniaMap は読込時に一度だけ走査するため拾われない
42
+ expect(await hasMapInstance(page, '#late-map')).toBe(false);
43
+ });
44
+ });
package/e2e/basic.spec.ts CHANGED
@@ -1,80 +1,16 @@
1
1
  import { test, expect } from '@playwright/test';
2
- import { Geolonia } from '../src/embed';
3
- import { TEST_URL, waitForMapLoad } from './helper';
4
-
5
- declare global {
6
- interface Window {
7
- geolonia: Geolonia,
8
- maplibregl?: Geolonia,
9
- mapboxgl?: Geolonia,
10
- }
11
- }
12
-
13
- test.describe('1. 基本的な地図表示', () => {
14
- test.beforeEach(async ({ page }) => {
15
- await page.goto(`${TEST_URL}/basic.html`);
16
- await waitForMapLoad(page);
17
- });
18
-
19
- test('1.1 ページ読み込み時に地図が表示されること', async ({ page }) => {
20
- await page.goto(`${TEST_URL}/basic.html`);
21
- await waitForMapLoad(page);
22
- const mapContainer = page.locator('.geolonia');
23
- await expect(mapContainer).toBeVisible();
24
- const canvas = page.locator('.geolonia canvas');
25
- await expect(canvas).toBeVisible();
26
- });
27
-
28
- test('1.2 デフォルトで原点に地図が表示されること', async ({ page }) => {
2
+ import { TEST_URL, mockGeoloniaTiles, waitForMapLoad } from './helper';
3
+
4
+ // 統合スモーク (embed-only): script タグ読込 → auto-render → canvas 描画 までが
5
+ // end-to-end で繋がっていることだけを1本で保証する。
6
+ // 個別の表示・機能は maps-core 側 E2E が担保し、embed 固有挙動は他の spec が担保する。
7
+ test.describe('統合スモーク', () => {
8
+ test('script タグ読込で .geolonia が auto-render され canvas が描画される', async ({ page }) => {
9
+ await mockGeoloniaTiles(page);
29
10
  await page.goto(`${TEST_URL}/basic.html`);
30
11
  await waitForMapLoad(page);
31
- const center = await page.evaluate(() => {
32
- const map = new window.geolonia.Map('map');
33
- return map.getCenter();
34
- });
35
- // 日本のおおよその中心座標
36
- expect(center.lat).toBeCloseTo(0.0, 0);
37
- expect(center.lng).toBeCloseTo(0.0, 0);
38
- });
39
-
40
- test('1.3 コンソールエラーが発生していないこと', async ({ page }) => {
41
- const consoleErrors: string[] = [];
42
- page.on('console', (msg) => {
43
- if (msg.type() === 'error') {
44
- const text = msg.text();
45
- // タイル取得失敗などブラウザレベルのネットワークエラーは除外し、
46
- // アプリコードが出すエラーのみチェックする
47
- if (!text.startsWith('Failed to load resource')) {
48
- consoleErrors.push(text);
49
- }
50
- }
51
- });
52
- await page.goto(`${TEST_URL}/basic.html`);
53
- await waitForMapLoad(page);
54
- expect(consoleErrors).toHaveLength(0);
55
- });
56
12
 
57
- test('1.4 アトリビューションが表示されていること', async ({ page }) => {
58
- await page.goto(`${TEST_URL}/basic.html`);
59
- await waitForMapLoad(page);
60
-
61
- // CustomAttributionControl は Shadow DOM 内にアトリビューションを描画する
62
- const attributionText = await page.evaluate(() => {
63
- const containers = document.querySelectorAll('.geolonia .maplibregl-control-container .maplibregl-ctrl-bottom-right > div');
64
- for (const container of containers) {
65
- const shadow = container.shadowRoot;
66
- if (shadow) {
67
- const inner = shadow.querySelector('.maplibregl-ctrl-attrib-inner');
68
- if (inner) {
69
- return inner.innerHTML;
70
- }
71
- }
72
- }
73
- return null;
74
- });
75
-
76
- expect(attributionText).not.toBeNull();
77
- expect(attributionText).not.toBe('');
13
+ await expect(page.locator('.geolonia')).toBeVisible();
14
+ await expect(page.locator('.geolonia canvas')).toBeVisible();
78
15
  });
79
16
  });
80
-
@@ -0,0 +1,43 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { TEST_URL, mockGeoloniaTiles, waitForStyleLoad } from './helper';
3
+
4
+ // embed (wrapper) 固有: MutationObserver でコンテナの DOM 削除を検知し map.remove() を呼ぶ。
5
+ // maps-core にはこの自動 cleanup は無い (明示 remove() のみ)。
6
+ test.describe('MutationObserver cleanup (wrapper-only)', () => {
7
+ test.beforeEach(async ({ page }) => {
8
+ await mockGeoloniaTiles(page);
9
+ await page.goto(`${TEST_URL}/cleanup.html`);
10
+ await waitForStyleLoad(page, '#map');
11
+ });
12
+
13
+ test('コンテナを DOM から削除すると map.remove() が発火する', async ({ page }) => {
14
+ await page.evaluate(() => {
15
+ const map = (document.querySelector('#map') as any).geoloniaMap;
16
+ (window as any).__removeFired = false;
17
+ map.on('remove', () => {
18
+ (window as any).__removeFired = true;
19
+ });
20
+ });
21
+
22
+ await page.evaluate(() => document.querySelector('#map')?.remove());
23
+
24
+ // MutationObserver は非同期で発火するため待つ
25
+ await page.waitForFunction(() => (window as any).__removeFired === true, undefined, {
26
+ timeout: 1000,
27
+ });
28
+ expect(await page.evaluate(() => (window as any).__removeFired)).toBe(true);
29
+ });
30
+
31
+ // maps-core 版 GeoloniaMap は options オブジェクトのみ受け取る (破壊的変更:
32
+ // 要素/セレクタ文字列は非対応)。同一コンテナへの再初期化は
33
+ // `container.geoloniaMap` を返して二重初期化を防ぐ。
34
+ test('同じコンテナへ再度 new すると同一インスタンスが返る (二重初期化防止)', async ({ page }) => {
35
+ const sameInstance = await page.evaluate(() => {
36
+ const container = document.querySelector('#map') as any;
37
+ const a = container.geoloniaMap;
38
+ const b = new (window as any).geolonia.Map({ container });
39
+ return a === b;
40
+ });
41
+ expect(sameInstance).toBe(true);
42
+ });
43
+ });
@@ -0,0 +1,56 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import {
3
+ TEST_URL,
4
+ mockGeoloniaTiles,
5
+ waitForStyleLoad,
6
+ getCenter,
7
+ getZoom,
8
+ getBearing,
9
+ getPitch,
10
+ } from './helper';
11
+
12
+ // embed (wrapper) 固有: HTML の data-* 属性を読んで GeoloniaMapOptions に渡すのは
13
+ // parse-atts.ts (embed のみ)。maps-core は options オブジェクト受け取りで data-* を読まない。
14
+ // よってここで守るのは「data-* を正しくパースして地図に転送できているか」というフォワーディング層。
15
+ // 各オプションが実際にどう描画されるか (option → 挙動) は maps-core 側 E2E が担保する。
16
+ test.describe('data-* → options フォワーディング (wrapper-only)', () => {
17
+ test.beforeEach(async ({ page }) => {
18
+ await mockGeoloniaTiles(page);
19
+ await page.goto(`${TEST_URL}/data-attributes.html`);
20
+ await waitForStyleLoad(page, '#map');
21
+ });
22
+
23
+ test('data-lat / data-lng が中心座標に反映される', async ({ page }) => {
24
+ const center = await getCenter(page, '#map');
25
+ expect(center.lat).toBeCloseTo(35, 4);
26
+ expect(center.lng).toBeCloseTo(139, 4);
27
+ });
28
+
29
+ test('data-zoom が反映される', async ({ page }) => {
30
+ expect(await getZoom(page, '#map')).toBeCloseTo(10, 4);
31
+ });
32
+
33
+ test('data-bearing / data-pitch が反映される', async ({ page }) => {
34
+ expect(await getBearing(page, '#map')).toBeCloseTo(30, 4);
35
+ expect(await getPitch(page, '#map')).toBeCloseTo(20, 4);
36
+ });
37
+ });
38
+
39
+ // data-* を一切指定しない場合の既定値。parse-atts の既定 (lat/lng = 0) に由来する
40
+ // embed 固有挙動で、maps-core 側には対応がない (options.spec は明示 center のみ検証)。
41
+ test.describe('data-* 無し → 既定値フォワーディング (wrapper-only)', () => {
42
+ test.beforeEach(async ({ page }) => {
43
+ await mockGeoloniaTiles(page);
44
+ // basic.html は data-* を持たない .geolonia
45
+ await page.goto(`${TEST_URL}/basic.html`);
46
+ await waitForStyleLoad(page, '#map');
47
+ });
48
+
49
+ test('data-lat / data-lng 無しなら中心は原点 (0, 0)', async ({ page }) => {
50
+ const center = await getCenter(page, '#map');
51
+ // 既定値は厳密に 0 (parse-atts の lat/lng 既定)。粗い精度だと既定転送の
52
+ // リグレッションを取りこぼすため、他の data-* テストと同等以上に厳密に見る。
53
+ expect(center.lat).toBeCloseTo(0, 5);
54
+ expect(center.lng).toBeCloseTo(0, 5);
55
+ });
56
+ });
@@ -0,0 +1,51 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { Geolonia } from '../src/embed';
3
+ import { TEST_URL, mockGeoloniaTiles, waitForMapLoad } from './helper';
4
+
5
+ declare global {
6
+ interface Window {
7
+ geolonia: Geolonia;
8
+ maplibregl?: Geolonia;
9
+ mapboxgl?: Geolonia;
10
+ }
11
+ }
12
+
13
+ // embed (wrapper) 固有: embed.js を script タグで読むとグローバルが公開される。
14
+ // 表示・機能そのものは maps-core 側 E2E が担保するため、ここでは「公開」だけを守る。
15
+ test.describe('window グローバル公開 (wrapper-only)', () => {
16
+ test.beforeEach(async ({ page }) => {
17
+ await mockGeoloniaTiles(page);
18
+ await page.goto(`${TEST_URL}/basic.html`);
19
+ await waitForMapLoad(page);
20
+ });
21
+
22
+ test('window.geolonia がセットされ、主要メンバを含む', async ({ page }) => {
23
+ const shape = await page.evaluate(() => ({
24
+ geolonia: typeof window.geolonia,
25
+ Map: typeof window.geolonia?.Map,
26
+ Marker: typeof window.geolonia?.Marker,
27
+ SimpleStyle: typeof window.geolonia?.SimpleStyle,
28
+ registerPlugin: typeof window.geolonia?.registerPlugin,
29
+ embedVersion: window.geolonia?.embedVersion,
30
+ }));
31
+
32
+ expect(shape.geolonia).toBe('object');
33
+ expect(shape.Map).toBe('function');
34
+ expect(shape.Marker).toBe('function');
35
+ expect(shape.SimpleStyle).toBe('function');
36
+ expect(shape.registerPlugin).toBe('function');
37
+ expect(shape.embedVersion).toMatch(/^\d+\.\d+/);
38
+ });
39
+
40
+ test('window.maplibregl / window.mapboxgl が window.geolonia と同一参照', async ({ page }) => {
41
+ const aliases = await page.evaluate(() => ({
42
+ maplibregl: window.maplibregl === window.geolonia,
43
+ mapboxgl: window.mapboxgl === window.geolonia,
44
+ mapClass: window.maplibregl?.Map === window.geolonia.Map,
45
+ }));
46
+
47
+ expect(aliases.maplibregl).toBe(true);
48
+ expect(aliases.mapboxgl).toBe(true);
49
+ expect(aliases.mapClass).toBe(true);
50
+ });
51
+ });