@geolonia/embed 6.0.0-pre.2 → 6.0.0-pre.4

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 (32) hide show
  1. package/CHANGELOG.md +17 -2
  2. package/README.md +11 -2
  3. package/dist/embed +1 -1
  4. package/dist/embed-chunks/18a79c1f77cc6894d617.js +1 -0
  5. package/dist/embed-chunks/88308c97950af0326501.js +1 -0
  6. package/dist/embed-chunks/b50d8f9685823588d639.js +1 -0
  7. package/dist/embed-chunks/c22ad704365fc721df0a.js +2 -0
  8. package/dist/embed-chunks/cfb9cc05d697ae310f6a.js +1 -0
  9. package/dist/embed-chunks/ec26dd45d3c0fe2695b2.js +2 -0
  10. package/dist/embed-core.d.ts +4 -1
  11. package/dist/embed-core.js +1 -2
  12. package/dist/embed.js +1 -1
  13. package/dist/embed.js.LICENSE.txt +3 -3
  14. package/dist/lib/maplibre-worker.d.ts +26 -0
  15. package/dist/version.d.ts +1 -1
  16. package/e2e/umd-worker.spec.ts +27 -0
  17. package/package.json +6 -5
  18. package/src/embed-core.ts +8 -1
  19. package/src/embed.ts +5 -0
  20. package/src/lib/maplibre-worker.ts +52 -0
  21. package/src/testability.test.ts +2 -1
  22. package/src/version.ts +1 -1
  23. package/webpack.config.js +35 -0
  24. package/dist/embed-chunks/1492645e3d07fd3de940.js +0 -1
  25. package/dist/embed-chunks/4ada77b78cc0cc5ccef9.js +0 -1
  26. package/dist/embed-chunks/6e05bbf5f391fda5b858.js +0 -1
  27. package/dist/embed-chunks/8176630945512b29f294.js +0 -2
  28. package/dist/embed-chunks/c783fffcd28083f7d5cb.js +0 -2
  29. package/dist/embed-chunks/f2124097fda51d0079ee.js +0 -1
  30. package/dist/embed-core.js.LICENSE.txt +0 -4
  31. /package/dist/embed-chunks/{8176630945512b29f294.js.LICENSE.txt → c22ad704365fc721df0a.js.LICENSE.txt} +0 -0
  32. /package/dist/embed-chunks/{c783fffcd28083f7d5cb.js.LICENSE.txt → ec26dd45d3c0fe2695b2.js.LICENSE.txt} +0 -0
@@ -1,4 +1,4 @@
1
1
  /**
2
- * MapLibre GL JS
3
- * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v5.19.0/LICENSE.txt
4
- */
2
+ * MapLibre GL JS
3
+ * @license 3-Clause BSD. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v6.11.2/LICENSE.txt
4
+ */
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @file UMD バンドルで maplibre-gl v6 の worker を動かすための設定。
3
+ *
4
+ * maplibre-gl v6 は worker を `import.meta.url` 基準の実 URL として解決しますが、
5
+ * webpack の `library.type: 'umd'` 出力では `import.meta.url` がビルド時に
6
+ * ビルドマシンのファイルパス (`file:///...`) へ置換されます。maplibre はこれを
7
+ * `https?:` でないと判断して worker URL を空文字へフォールバックするため、
8
+ * **例外もコンソールエラーも出ないまま地図だけが表示されない** 状態になります。
9
+ *
10
+ * embed は「1 ファイルを置くだけで動く」ことが利点なので、worker を別ファイルとして
11
+ * 配るのではなくバンドルへ文字列として埋め込み、実行時に Blob URL 化して maplibre へ
12
+ * 渡します。埋め込む中身は `webpack.config.js` の `bundleMaplibreWorkerSource()` が
13
+ * esbuild で自己完結する 1 ファイルへ束ねたものです(maps-core の `src/umd.ts` と同じ方式)。
14
+ *
15
+ * Blob worker を使うため、CSP を設定しているページでは `worker-src blob:` が必要です。
16
+ *
17
+ * @see https://github.com/geolonia/embed/issues/518
18
+ */
19
+ /**
20
+ * 埋め込んだ worker を Blob URL 化して maplibre に登録する。
21
+ *
22
+ * 置換されていない環境(vitest など webpack を通らない実行)や、ブラウザ外
23
+ * (SSR。Node にも Blob / URL.createObjectURL はあるので window で判定する)
24
+ * では何もしない。その場合は maplibre 既定の解決にそのまま任せる。
25
+ */
26
+ export declare const installMaplibreWorker: () => void;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "6.0.0-pre.2";
1
+ export declare const VERSION = "6.0.0-pre.4";
@@ -0,0 +1,27 @@
1
+ import { test, expect } from '@playwright/test';
2
+ import { TEST_URL, mockGeoloniaTiles, waitForStyleLoad } from './helper';
3
+
4
+ /**
5
+ * embed は UMD で配る。maplibre-gl v6 の worker は `import.meta.url` 基準で解決される
6
+ * が、UMD 出力では webpack が `import.meta.url` をビルドマシンのファイルパスへ置換する
7
+ * ため、maplibre は worker URL を空文字へフォールバックする。この失敗は例外もコンソール
8
+ * エラーも出さず「地図だけが出ない」形で現れるので、worker が実際に登録されているかを
9
+ * 明示的に確かめる (#518)。
10
+ *
11
+ * 実体は `src/lib/maplibre-worker.ts` が worker をバンドル内の文字列から Blob URL 化して
12
+ * `setWorkerUrl()` に渡している。
13
+ */
14
+ test.describe('UMD バンドルの maplibre worker (#518)', () => {
15
+ test('worker URL が Blob URL として登録され、スタイルが読み込まれる', async ({
16
+ page,
17
+ }) => {
18
+ await mockGeoloniaTiles(page);
19
+ await page.goto(`${TEST_URL}/basic.html`);
20
+ await waitForStyleLoad(page, '#map');
21
+
22
+ const workerUrl = await page.evaluate(() =>
23
+ (window as any).geolonia.getWorkerUrl(),
24
+ );
25
+ expect(workerUrl).toMatch(/^blob:/);
26
+ });
27
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geolonia/embed",
3
- "version": "6.0.0-pre.2",
3
+ "version": "6.0.0-pre.4",
4
4
  "description": "Geolonia embed JS API",
5
5
  "main": "dist/embed.js",
6
6
  "types": "dist/src/embed.d.ts",
@@ -46,6 +46,7 @@
46
46
  "@typescript-eslint/parser": "^8.46.4",
47
47
  "babel-loader": "^9.1.0",
48
48
  "css-loader": "^6.7.2",
49
+ "esbuild": "^0.28.2",
49
50
  "eslint": "^9.39.1",
50
51
  "eslint-config-prettier": "^10.1.8",
51
52
  "eslint-plugin-import": "^2.32.0",
@@ -53,7 +54,7 @@
53
54
  "eslint-plugin-react": "^7.37.5",
54
55
  "eslint-plugin-react-hooks": "^7.0.1",
55
56
  "globals": "^16.5.0",
56
- "jsdom": "^20.0.3",
57
+ "jsdom": "^29.1.1",
57
58
  "node-fetch": "2",
58
59
  "prettier": "^3.6.2",
59
60
  "style-loader": "^3.3.1",
@@ -66,11 +67,11 @@
66
67
  "webpack": "^5.75.0",
67
68
  "webpack-bundle-analyzer": "^4.7.0",
68
69
  "webpack-cli": "^5.0.1",
69
- "webpack-dev-server": "^4.11.1"
70
+ "webpack-dev-server": "^5.2.6"
70
71
  },
71
72
  "dependencies": {
72
- "@geolonia/maps-core": "^0.4.3",
73
+ "@geolonia/maps-core": "^0.6.0",
73
74
  "@playwright/test": "^1.61.1",
74
- "maplibre-gl": "5.19.0"
75
+ "maplibre-gl": "6.11.2"
75
76
  }
76
77
  }
package/src/embed-core.ts CHANGED
@@ -1,12 +1,19 @@
1
1
  /**
2
- * @file Side-effect-free entry point for programmatic use (e.g. React wrapper).
2
+ * @file Entry point for programmatic use (e.g. React wrapper).
3
3
  * Does NOT call renderGeoloniaMap() or set window.geolonia.
4
4
  *
5
5
  * The Geolonia core (map, marker, simplestyle, keyring, PMTiles protocol
6
6
  * registration, ...) now lives in `@geolonia/maps-core`; this entry simply
7
7
  * re-exports it alongside embed-specific helpers (registerPlugin, version).
8
+ *
9
+ * 唯一の副作用として、UMD 出力で maplibre が worker を解決できない問題への対処
10
+ * (`installMaplibreWorker()`) をここで行う。詳細は `./lib/maplibre-worker` を参照。
8
11
  */
9
12
 
13
+ import { installMaplibreWorker } from './lib/maplibre-worker';
14
+
15
+ installMaplibreWorker();
16
+
10
17
  export {
11
18
  GeoloniaMap,
12
19
  GeoloniaMarker,
package/src/embed.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  import * as maplibregl from 'maplibre-gl';
6
6
  import { GeoloniaMap, GeoloniaMarker, SimpleStyle } from '@geolonia/maps-core';
7
7
  import { VERSION as embedVersion } from './version';
8
+ import { installMaplibreWorker } from './lib/maplibre-worker';
8
9
  import { registerPlugin, renderGeoloniaMap } from './lib/render';
9
10
 
10
11
  export type { GeoloniaMapOptions } from '@geolonia/maps-core';
@@ -33,6 +34,10 @@ declare global {
33
34
  }
34
35
  }
35
36
 
37
+ // UMD 出力では maplibre が worker を自力で解決できない。地図を作る前に
38
+ // バンドルへ埋め込んだ worker を登録する (#518)。
39
+ installMaplibreWorker();
40
+
36
41
  const geolonia: Geolonia = Object.assign(window.geolonia || {}, maplibregl, {
37
42
  Map: GeoloniaMap,
38
43
  Marker: GeoloniaMarker,
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @file UMD バンドルで maplibre-gl v6 の worker を動かすための設定。
3
+ *
4
+ * maplibre-gl v6 は worker を `import.meta.url` 基準の実 URL として解決しますが、
5
+ * webpack の `library.type: 'umd'` 出力では `import.meta.url` がビルド時に
6
+ * ビルドマシンのファイルパス (`file:///...`) へ置換されます。maplibre はこれを
7
+ * `https?:` でないと判断して worker URL を空文字へフォールバックするため、
8
+ * **例外もコンソールエラーも出ないまま地図だけが表示されない** 状態になります。
9
+ *
10
+ * embed は「1 ファイルを置くだけで動く」ことが利点なので、worker を別ファイルとして
11
+ * 配るのではなくバンドルへ文字列として埋め込み、実行時に Blob URL 化して maplibre へ
12
+ * 渡します。埋め込む中身は `webpack.config.js` の `bundleMaplibreWorkerSource()` が
13
+ * esbuild で自己完結する 1 ファイルへ束ねたものです(maps-core の `src/umd.ts` と同じ方式)。
14
+ *
15
+ * Blob worker を使うため、CSP を設定しているページでは `worker-src blob:` が必要です。
16
+ *
17
+ * @see https://github.com/geolonia/embed/issues/518
18
+ */
19
+
20
+ import { setWorkerUrl } from 'maplibre-gl';
21
+
22
+ /** webpack の DefinePlugin がビルド時に worker のソース文字列へ置換する。 */
23
+ declare const __MAPLIBRE_WORKER_SOURCE__: string;
24
+
25
+ /**
26
+ * 埋め込んだ worker を Blob URL 化して maplibre に登録する。
27
+ *
28
+ * 置換されていない環境(vitest など webpack を通らない実行)や、ブラウザ外
29
+ * (SSR。Node にも Blob / URL.createObjectURL はあるので window で判定する)
30
+ * では何もしない。その場合は maplibre 既定の解決にそのまま任せる。
31
+ */
32
+ export const installMaplibreWorker = (): void => {
33
+ const source =
34
+ typeof __MAPLIBRE_WORKER_SOURCE__ === 'string'
35
+ ? __MAPLIBRE_WORKER_SOURCE__
36
+ : '';
37
+ if (!source) {
38
+ return;
39
+ }
40
+ if (
41
+ typeof window === 'undefined' ||
42
+ typeof Blob === 'undefined' ||
43
+ typeof URL === 'undefined' ||
44
+ typeof URL.createObjectURL !== 'function'
45
+ ) {
46
+ return;
47
+ }
48
+
49
+ setWorkerUrl(
50
+ URL.createObjectURL(new Blob([source], { type: 'text/javascript' })),
51
+ );
52
+ };
@@ -1,7 +1,8 @@
1
1
  import { describe, it, expect, vi } from 'vitest';
2
2
  import { JSDOM } from 'jsdom';
3
3
 
4
- import maplibregl from 'maplibre-gl';
4
+ // maplibre-gl v6 にデフォルトエクスポートは無いので名前空間でインポートする。
5
+ import * as maplibregl from 'maplibre-gl';
5
6
 
6
7
  /**
7
8
  * このテストは、jsdom環境ではmaplibre-glのMapインスタンスが
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '6.0.0-pre.2';
1
+ export const VERSION = '6.0.0-pre.4';
package/webpack.config.js CHANGED
@@ -1,10 +1,36 @@
1
1
  const path = require('path');
2
2
  const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
3
3
  const { DefinePlugin } = require('webpack');
4
+ const esbuild = require('esbuild');
5
+
6
+ /**
7
+ * maplibre-gl v6 の worker を、依存する `maplibre-gl-shared.mjs` ごと自己完結する
8
+ * 1 ファイルへ束ね、その中身を文字列として返す。
9
+ *
10
+ * v6 の worker は `import.meta.url` 基準の実 URL として解決されるが、UMD 出力では
11
+ * webpack が `import.meta.url` をビルドマシンの `file:///...` へ置換してしまい、
12
+ * maplibre はそれを `https?:` でないと判断して worker URL を空文字へフォールバックする
13
+ * (例外もエラーも出ないまま地図だけが出ない)。UMD の利点である単一ファイル配布を保つため、
14
+ * 別ファイルを配るのではなくバンドルへ埋め込む。`src/lib/maplibre-worker.ts` を参照。
15
+ *
16
+ * @see https://github.com/geolonia/embed/issues/518
17
+ * @returns {string} worker のソースコード
18
+ */
19
+ const bundleMaplibreWorkerSource = () => {
20
+ const result = esbuild.buildSync({
21
+ entryPoints: [require.resolve('maplibre-gl/dist/maplibre-gl-worker.mjs')],
22
+ bundle: true,
23
+ format: 'esm',
24
+ minify: true,
25
+ write: false,
26
+ });
27
+ return result.outputFiles[0].text;
28
+ };
4
29
 
5
30
  const plugins = [
6
31
  new DefinePlugin({
7
32
  'process.env.MAP_PLATFORM_STAGE': JSON.stringify(process.env.MAP_PLATFORM_STAGE || 'dev'),
33
+ __MAPLIBRE_WORKER_SOURCE__: JSON.stringify(bundleMaplibreWorkerSource()),
8
34
  }),
9
35
  ];
10
36
  if (process.env.ANALYZE === 'true') {
@@ -15,6 +41,15 @@ const sharedConfig = {
15
41
  plugins: plugins,
16
42
  module: {
17
43
  rules: [
44
+ {
45
+ // maplibre-gl v6 は worker URL のフォールバック経路で
46
+ // `new URL(expr, import.meta.url)` を使う。webpack はこれを解決できない
47
+ // asset 参照と見なして "Critical dependency" を警告し、dist ディレクトリ全体の
48
+ // context module を作る。worker は DefinePlugin による埋め込みで解決済みで
49
+ // この経路には到達しないため、maplibre に限って `new URL()` の asset 解釈を切る。
50
+ test: /[\\/]node_modules[\\/]maplibre-gl[\\/].+\.mjs$/,
51
+ parser: { url: false },
52
+ },
18
53
  {
19
54
  test: /\.svg$/,
20
55
  use: {
@@ -1 +0,0 @@
1
- (self.webpackChunkgeoloniaEmbedCore=self.webpackChunkgeoloniaEmbedCore||[]).push([[445],{197:()=>{},1866:()=>{},2739:()=>{},9746:()=>{},9977:()=>{}}]);
@@ -1 +0,0 @@
1
- "use strict";(self.webpackChunkgeoloniaEmbed=self.webpackChunkgeoloniaEmbed||[]).push([[521],{7521:(e,t,s)=>{s.d(t,{default:()=>h});const l={altKey:{en:"alt",ja:"Alt"},ctrlKey:{en:"Ctrl",ja:"Ctrl"},metaKey:{en:"⌘",ja:"⌘"}},n={en:e=>({wheel:`Use ${l[e].en} + scroll to zoom the map.`,touch:"Use two fingers to move the map."}),ja:e=>({wheel:`${l[e].ja} キーを押しながらスクロールしてください。`,touch:"2本指を使って操作してください。"})};function i(e){const t=function(e){switch(e){case"alt":return"altKey";case"ctrl":return"ctrlKey";case"meta":return"metaKey";default:return function(){const e=navigator.userAgentData;return e?.platform?"macOS"===e.platform:/mac/i.test(navigator.platform)}()?"metaKey":"ctrlKey"}}(e.modifierKey),s="auto"!==e.lang&&e.lang?e.lang:function(){const e=(navigator.languages?.[0]??navigator.language).toLowerCase();return"ja"===e||"ja-jp"===e?"ja":"en"}(),l=n[s](t);return{backgroundColor:e.backgroundColor??"rgba(0, 0, 0, 0.8)",textColor:e.textColor??"#ffffff",textMessage:e.textMessage??l.wheel,textMessageMobile:e.textMessageMobile??l.touch,timeout:e.timeout??2e3,modifierKey:t}}const h=class{constructor(e={}){this.fullscreen=!1,this.timer=null,this.settings=i(e),this.handleWheel=this.onWheel.bind(this),this.handleHelpWheel=this.onHelpWheel.bind(this),this.handleHelpTouchStart=this.onHelpTouchStart.bind(this),this.handleMoveStart=this.onMoveStart.bind(this),this.handleFullscreenChange=this.onFullscreenChange.bind(this)}onAdd(e){this.map=e;const t=document.createElement("div");t.className="gesture-handling-help-overlay",t.style.backgroundColor=this.settings.backgroundColor,t.style.position="absolute",t.style.display="none",t.style.zIndex="9999",t.style.justifyContent="center",t.style.alignItems="center";const s=document.createElement("div");s.style.textAlign="center",s.style.color=this.settings.textColor,t.appendChild(s),this.helpElement=t,e.scrollZoom.disable(),t.addEventListener("wheel",this.handleHelpWheel),t.addEventListener("touchstart",this.handleHelpTouchStart,{passive:!1}),e.getContainer().addEventListener("wheel",this.handleWheel),e.on("movestart",this.handleMoveStart),document.addEventListener("fullscreenchange",this.handleFullscreenChange);const l=document.createElement("div");return l.className="maplibregl-ctrl",l.style.display="none",l}onRemove(){this.clearTimer(),this.helpElement&&(this.helpElement.removeEventListener("wheel",this.handleHelpWheel),this.helpElement.removeEventListener("touchstart",this.handleHelpTouchStart),this.hideHelp(),this.helpElement=void 0),this.map&&(this.map.getContainer().removeEventListener("wheel",this.handleWheel),this.map.off("movestart",this.handleMoveStart),this.map.scrollZoom.enable(),this.map=void 0),document.removeEventListener("fullscreenchange",this.handleFullscreenChange)}getDefaultPosition(){return"top-left"}showHelp(e){const t=this.map,s=this.helpElement;if(!t||!s)return;s.style.top="0",s.style.left="0",s.style.width="100%",s.style.height="100%",s.style.display="flex";const l=s.firstElementChild;l&&(l.innerText=e),t.getContainer().appendChild(s)}hideHelp(){const e=this.helpElement;e&&(e.style.display="none",e.remove())}clearTimer(){null!==this.timer&&(clearTimeout(this.timer),this.timer=null)}onWheel(e){const t=this.map;t&&(e[this.settings.modifierKey]||this.fullscreen?(e.preventDefault(),t.scrollZoom.isEnabled()||(t.scrollZoom.reset(),t.scrollZoom.enable())):(t.scrollZoom.disable(),this.showHelp(this.settings.textMessage),this.clearTimer(),this.timer=setTimeout(()=>{this.hideHelp()},this.settings.timeout)))}onHelpWheel(e){e[this.settings.modifierKey]||this.fullscreen?(e.preventDefault(),this.clearTimer(),this.hideHelp()):(this.clearTimer(),this.timer=setTimeout(()=>{this.hideHelp()},this.settings.timeout))}onHelpTouchStart(e){const t=this.map;t&&e.touches&&(e.touches.length>=2||this.fullscreen)&&(this.clearTimer(),this.hideHelp(),t.dragPan.enable(),e.preventDefault())}onMoveStart(e){const t=this.map;t&&e.originalEvent&&"touches"in e.originalEvent&&e.originalEvent.touches.length<2&&!this.fullscreen&&(this.showHelp(this.settings.textMessageMobile),t.dragPan.disable(),this.clearTimer(),this.timer=setTimeout(()=>{t.dragPan.enable(),this.hideHelp()},this.settings.timeout))}onFullscreenChange(){this.fullscreen=!!document.fullscreenElement}}}}]);
@@ -1 +0,0 @@
1
- (self.webpackChunkgeoloniaEmbed=self.webpackChunkgeoloniaEmbed||[]).push([[445],{197:()=>{},1866:()=>{},2739:()=>{},9746:()=>{},9977:()=>{}}]);