@geolonia/embed 4.2.2 → 5.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 (50) hide show
  1. package/.eslintrc.js +3 -0
  2. package/.github/workflows/build.yml +89 -28
  3. package/dist/e2e/basic.spec.d.ts +8 -0
  4. package/dist/e2e/helper.d.ts +4 -0
  5. package/dist/embed +2 -1
  6. package/dist/embed-chunks/416af3373e37004e65f4.js +1 -0
  7. package/dist/embed-chunks/488aacb380a87ea633f6.js +2 -0
  8. package/dist/embed.js +2 -1
  9. package/dist/embed.js.LICENSE.txt +4 -0
  10. package/dist/playwright.config.d.ts +9 -0
  11. package/dist/{lib → src/lib}/geolonia-map.d.ts +10 -1
  12. package/dist/{lib → src/lib}/maplibre-util.d.ts +1 -3
  13. package/dist/{lib → src/lib}/util.d.ts +6 -3
  14. package/dist/src/lib/util.test.d.ts +1 -0
  15. package/dist/src/testability.test.d.ts +1 -0
  16. package/dist/src/version.d.ts +1 -0
  17. package/e2e/basic.spec.ts +52 -0
  18. package/e2e/helper.ts +12 -0
  19. package/e2e/map.spec.ts +69 -0
  20. package/package.json +8 -4
  21. package/playwright.config.ts +79 -0
  22. package/src/embed.ts +1 -1
  23. package/src/lib/geolonia-map.ts +35 -9
  24. package/src/lib/parse-atts.test.ts +2 -0
  25. package/src/lib/render.ts +12 -2
  26. package/src/lib/simplestyle-vector.ts +3 -3
  27. package/src/lib/simplestyle.ts +10 -20
  28. package/src/lib/util.test.ts +40 -2
  29. package/src/lib/util.ts +48 -2
  30. package/src/style.css +28 -0
  31. package/src/testability.test.ts +43 -0
  32. package/tsconfig.json +3 -1
  33. package/dist/embed-chunks/b52b89229e47dc93c64b.js +0 -2
  34. package/dist/embed-chunks/d0f087405f7ae2fcf1c1.js +0 -1
  35. package/dist/version.d.ts +0 -1
  36. /package/dist/{lib/keyring.test.d.ts → e2e/map.spec.d.ts} +0 -0
  37. /package/dist/embed-chunks/{b52b89229e47dc93c64b.js.LICENSE.txt → 488aacb380a87ea633f6.js.LICENSE.txt} +0 -0
  38. /package/dist/{embed.d.ts → src/embed.d.ts} +0 -0
  39. /package/dist/{lib → src/lib}/CustomAttributionControl.d.ts +0 -0
  40. /package/dist/{lib → src/lib}/controls/geolonia-control.d.ts +0 -0
  41. /package/dist/{lib → src/lib}/geolonia-marker.d.ts +0 -0
  42. /package/dist/{lib → src/lib}/keyring.d.ts +0 -0
  43. /package/dist/{lib/parse-atts.test.d.ts → src/lib/keyring.test.d.ts} +0 -0
  44. /package/dist/{lib → src/lib}/parse-atts.d.ts +0 -0
  45. /package/dist/{lib/simplestyle.test.d.ts → src/lib/parse-atts.test.d.ts} +0 -0
  46. /package/dist/{lib → src/lib}/render.d.ts +0 -0
  47. /package/dist/{lib → src/lib}/simplestyle-vector.d.ts +0 -0
  48. /package/dist/{lib → src/lib}/simplestyle.d.ts +0 -0
  49. /package/dist/{lib/util.test.d.ts → src/lib/simplestyle.test.d.ts} +0 -0
  50. /package/dist/{types-internal.d.ts → src/types-internal.d.ts} +0 -0
package/src/lib/util.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  import { keyring } from './keyring';
4
- import type { MapOptions, MarkerOptions } from 'maplibre-gl';
4
+ import type { GetResourceResponse, MapOptions, MarkerOptions, ExpiryData } from 'maplibre-gl';
5
+
6
+ // GetImageCallback extracted from maplibre-gl v3.6.2 ( https://github.com/maplibre/maplibre-gl-js/releases/tag/v3.6.2 )
7
+ export type GetImageCallback = (error?: Error | null, image?: HTMLImageElement | ImageBitmap | null, expiry?: ExpiryData | null) => void;
5
8
 
6
9
  /**
7
10
  *
8
11
  * @param {string} str target URL string
9
12
  * @return {string|false} Resolved URL or false if not resolved
10
13
  */
11
- export function isURL(str) {
14
+ export function isURL(str: string): string | false {
12
15
  if (str.match(/^https?:\/\//)) {
13
16
  return str;
14
17
  } else if (str.match(/^\//) || str.match(/^\.\.?/)) {
@@ -272,6 +275,24 @@ export const handleRestrictedMode = (map) => {
272
275
  }
273
276
  };
274
277
 
278
+ export const handleErrorMode = (container) => {
279
+
280
+ const errorContainer = document.createElement('div');
281
+ errorContainer.classList.add('geolonia__error-container');
282
+
283
+ const div = document.createElement('div');
284
+
285
+ const h1 = document.createElement('h2');
286
+ h1.textContent = 'Geolonia Maps';
287
+ div.appendChild(h1);
288
+
289
+ div.classList.add('geolonia__error-message');
290
+ div.innerHTML += '<div class="geolonia__error-message-description">地図の初期化に失敗しました。管理者にお問い合わせ下さい。開発者の方は開発者ツールでエラー詳細をご確認下さい。</div>';
291
+
292
+ errorContainer.appendChild(div);
293
+ container.appendChild(errorContainer);
294
+ };
295
+
275
296
  export const sanitizeDescription = async (description) => {
276
297
  const { default: sanitizeHtml } = await import('sanitize-html');
277
298
  return sanitizeHtml(description, {
@@ -281,3 +302,28 @@ export const sanitizeDescription = async (description) => {
281
302
  };
282
303
 
283
304
  export const random = (max: number): number => Math.floor(Math.random() * max);
305
+
306
+ // This function is used to provide backward compatibility with callback invocations,
307
+ // so we ignore ESLint rules for this function.
308
+ // Note: this cannot be a generic promiseToCallback function because the callback is not
309
+ // the traditional (error, result) style callback.
310
+ export function loadImageCompatibility(
311
+ promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>,
312
+ callback: GetImageCallback,
313
+ ): void {
314
+ promise
315
+ // eslint-disable-next-line promise/prefer-await-to-then
316
+ .then((response) => {
317
+ // eslint-disable-next-line promise/no-callback-in-promise
318
+ callback(null, response.data, {
319
+ cacheControl: response.cacheControl,
320
+ expires: response.expires,
321
+ });
322
+ return;
323
+ })
324
+ // eslint-disable-next-line promise/prefer-await-to-then
325
+ .catch((error) => {
326
+ // eslint-disable-next-line promise/no-callback-in-promise
327
+ callback(error);
328
+ });
329
+ }
package/src/style.css CHANGED
@@ -110,6 +110,34 @@
110
110
  background-size: cover;
111
111
  }
112
112
 
113
+ /* Style for error message */
114
+ .geolonia__error-container {
115
+ display: flex;
116
+ justify-content: center;
117
+ align-items: center;
118
+ height: 100%;
119
+ width: 100%;
120
+ background-color: #dedede;
121
+ z-index: 9999;
122
+ position: absolute;
123
+ }
124
+
125
+ .geolonia__error-message {
126
+ max-width: 300px;
127
+ background-color: #ffffff;
128
+ margin: 10px;
129
+ padding: 0.75rem 1.25rem;
130
+ border-radius: 6px;
131
+ position: absolute;
132
+ z-index: 99999;
133
+ word-wrap: break-word;
134
+ box-shadow: 0 4px 10px #0000001a
135
+ }
136
+
137
+ .geolonia__error-message-description {
138
+ margin: 15px 0;
139
+ }
140
+
113
141
  /* CSS for Attribution */
114
142
  /* Fix: https://github.com/geolonia/embed/issues/291 */
115
143
  .maplibregl-map {
@@ -0,0 +1,43 @@
1
+ import { JSDOM } from 'jsdom';
2
+ import assert from 'assert';
3
+ import maplibregl from 'maplibre-gl';
4
+
5
+ /**
6
+ * このテストは、jsdom環境ではmaplibre-glのMapインスタンスが
7
+ * WebGL不足のため生成できないことを「動作証跡付き」でドキュメント化するものです。
8
+ * 実際の描画テストはE2Eテストで行ってください。
9
+ */
10
+
11
+ describe('maplibre-gl jsdom limitation', () => {
12
+ it('jsdom上ではMaplibre Mapインスタンス生成時にエラー(WebGL未対応のため)', () => {
13
+ const dom = new JSDOM('<!DOCTYPE html><html><body><div id="map"></div></body></html>', {
14
+ url: 'http://localhost',
15
+ pretendToBeVisual: true, // jsdomを視覚的な環境として
16
+ });
17
+ // @ts-ignore
18
+ global.window = dom.window;
19
+ global.document = dom.window.document;
20
+ let errorCaught = null;
21
+ try {
22
+ new maplibregl.Map({
23
+ container: 'map',
24
+ style: 'https://demotiles.maplibre.org/style.json',
25
+ center: [139.767, 35.681],
26
+ zoom: 10,
27
+ });
28
+ } catch (err) {
29
+ errorCaught = err;
30
+ }
31
+ assert(errorCaught instanceof Error);
32
+ // 期待される理由: WebGLが利用できない旨のエラーメッセージ
33
+ assert(
34
+ /webgl|WebGL|context|device/i.test(errorCaught.message),
35
+ `Error message should mention WebGL or context, but got: ${errorCaught.message}`,
36
+ );
37
+ });
38
+
39
+ it('【NOTE】描画テストが必要な場合はE2E(ブラウザ実行)で行うこと', () => {
40
+ // このテストは常に成功。ドキュメント用途。
41
+ assert.strictEqual(true, true);
42
+ });
43
+ });
package/tsconfig.json CHANGED
@@ -23,6 +23,8 @@
23
23
  "newLine": "lf"
24
24
  },
25
25
  "include": [
26
- "src"
26
+ "src",
27
+ "e2e",
28
+ "playwright.config.ts",
27
29
  ]
28
30
  }