@geolonia/embed 5.2.2 → 5.2.3
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/workflows/build.yml +39 -10
- package/CHANGELOG.md +8 -0
- package/README.md +27 -0
- package/dist/embed +1 -1
- package/dist/embed-core.js +1 -1
- package/dist/embed-core.js.LICENSE.txt +1 -1
- package/dist/embed.js +1 -1
- package/dist/embed.js.LICENSE.txt +1 -1
- package/dist/lib/geolonia-map.d.ts +6 -0
- package/dist/lib/sanitize-attribution.d.ts +15 -0
- package/dist/lib/util.d.ts +16 -1
- package/dist/types.d.ts +6 -0
- package/dist/version.d.ts +1 -1
- package/e2e/webgl-error.spec.ts +105 -0
- package/package.json +2 -2
- package/src/lib/CustomAttributionControl.ts +7 -2
- package/src/lib/geolonia-map.ts +22 -2
- package/src/lib/parse-atts.test.ts +1 -0
- package/src/lib/parse-atts.ts +1 -0
- package/src/lib/sanitize-attribution.test.ts +122 -0
- package/src/lib/sanitize-attribution.ts +192 -0
- package/src/lib/util.test.ts +85 -0
- package/src/lib/util.ts +76 -7
- package/src/style.css +69 -4
- package/src/types.ts +6 -0
- package/src/version.ts +1 -1
package/src/lib/util.test.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
parseSimpleVector,
|
|
15
15
|
sanitizeDescription,
|
|
16
16
|
loadImageCompatibility,
|
|
17
|
+
handleErrorMode,
|
|
17
18
|
} from './util';
|
|
18
19
|
|
|
19
20
|
const base = 'https://base.example.com/parent/';
|
|
@@ -362,3 +363,87 @@ describe('loadImageCompatibility', () => {
|
|
|
362
363
|
});
|
|
363
364
|
});
|
|
364
365
|
});
|
|
366
|
+
|
|
367
|
+
describe('handleErrorMode', () => {
|
|
368
|
+
const createContainer = () => {
|
|
369
|
+
const container = document.createElement('div');
|
|
370
|
+
document.body.appendChild(container);
|
|
371
|
+
return container;
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
it('既定では行動につながる文言(見出し・手順・問い合わせ案内)を描画する', () => {
|
|
375
|
+
const container = createContainer();
|
|
376
|
+
handleErrorMode(container);
|
|
377
|
+
|
|
378
|
+
const errorContainer = container.querySelector(
|
|
379
|
+
'.geolonia__error-container',
|
|
380
|
+
);
|
|
381
|
+
expect(errorContainer).not.toBeNull();
|
|
382
|
+
expect(
|
|
383
|
+
errorContainer.querySelector('.geolonia__error-message-title')
|
|
384
|
+
.textContent,
|
|
385
|
+
).toBe('地図を表示できませんでした');
|
|
386
|
+
// 手順は 4 つ(ブラウザ再起動 → 端末再起動 → 別ブラウザ → ドライバ更新)
|
|
387
|
+
expect(
|
|
388
|
+
errorContainer.querySelectorAll('.geolonia__error-message-steps li')
|
|
389
|
+
.length,
|
|
390
|
+
).toBe(4);
|
|
391
|
+
expect(
|
|
392
|
+
errorContainer.querySelector('.geolonia__error-message-contact'),
|
|
393
|
+
).not.toBeNull();
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it('既定では狭いコンテナ向けの短縮文も同時に描画する(表示切替は CSS が担う)', () => {
|
|
397
|
+
const container = createContainer();
|
|
398
|
+
handleErrorMode(container);
|
|
399
|
+
|
|
400
|
+
expect(
|
|
401
|
+
container.querySelector('.geolonia__error-message-brief'),
|
|
402
|
+
).not.toBeNull();
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
it('開発者向けの案内文(開発者ツール)を含まない', () => {
|
|
406
|
+
const container = createContainer();
|
|
407
|
+
handleErrorMode(container);
|
|
408
|
+
|
|
409
|
+
expect(container.textContent).not.toContain('開発者ツール');
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it('data-error-message で文言を差し替えられる', () => {
|
|
413
|
+
const container = createContainer();
|
|
414
|
+
handleErrorMode(container, { message: '地図の表示に失敗しました。0120-000-000 までご連絡ください。' });
|
|
415
|
+
|
|
416
|
+
const description = container.querySelector(
|
|
417
|
+
'.geolonia__error-message-description',
|
|
418
|
+
);
|
|
419
|
+
expect(description.textContent).toBe(
|
|
420
|
+
'地図の表示に失敗しました。0120-000-000 までご連絡ください。',
|
|
421
|
+
);
|
|
422
|
+
// 既定の手順リストは描画しない
|
|
423
|
+
expect(
|
|
424
|
+
container.querySelector('.geolonia__error-message-steps'),
|
|
425
|
+
).toBeNull();
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('差し替え文言の HTML はエスケープする', () => {
|
|
429
|
+
const container = createContainer();
|
|
430
|
+
handleErrorMode(container, {
|
|
431
|
+
message: '<img src=x onerror="alert(1)">お問い合わせください',
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
expect(container.querySelector('img')).toBeNull();
|
|
435
|
+
expect(container.textContent).toContain(
|
|
436
|
+
'<img src=x onerror="alert(1)">お問い合わせください',
|
|
437
|
+
);
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it('off / false を指定すると何も描画しない', () => {
|
|
441
|
+
for (const message of ['off', 'OFF', false] as const) {
|
|
442
|
+
const container = createContainer();
|
|
443
|
+
handleErrorMode(container, { message });
|
|
444
|
+
|
|
445
|
+
expect(container.querySelector('.geolonia__error-container')).toBeNull();
|
|
446
|
+
expect(container.children.length).toBe(0);
|
|
447
|
+
}
|
|
448
|
+
});
|
|
449
|
+
});
|
package/src/lib/util.ts
CHANGED
|
@@ -373,19 +373,88 @@ export const handleRestrictedMode = (map) => {
|
|
|
373
373
|
}
|
|
374
374
|
};
|
|
375
375
|
|
|
376
|
-
|
|
376
|
+
/**
|
|
377
|
+
* 地図の初期化に失敗したときのエラー表示。
|
|
378
|
+
*
|
|
379
|
+
* 既定では「WebGL が使えない状態かもしれない」という原因と、利用者が自分で試せる
|
|
380
|
+
* 復旧手順を描画する。手順を書き切った版と 1 行の短縮版の両方を DOM に入れておき、
|
|
381
|
+
* どちらを見せるかは地図コンテナの広さに応じて CSS(コンテナクエリ)が決める。
|
|
382
|
+
* 消費側で文言を差し替えたい場合は `data-error-message` に文字列を、
|
|
383
|
+
* エラー表示自体を止めたい場合は `data-error-message="off"`(プログラム API では
|
|
384
|
+
* `errorMessage: false`)を指定する。
|
|
385
|
+
*
|
|
386
|
+
* @param container 地図コンテナ
|
|
387
|
+
* @param options `message` に差し替え文言、`false` / `'off'` で表示しない
|
|
388
|
+
*/
|
|
389
|
+
export const handleErrorMode = (
|
|
390
|
+
container: HTMLElement,
|
|
391
|
+
options: { message?: string | false } = {},
|
|
392
|
+
): void => {
|
|
393
|
+
if (options.message === false) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
const message = (options.message ?? '').trim();
|
|
398
|
+
|
|
399
|
+
if (message.toLowerCase() === 'off') {
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
377
403
|
const errorContainer = document.createElement('div');
|
|
378
404
|
errorContainer.classList.add('geolonia__error-container');
|
|
379
405
|
|
|
380
406
|
const div = document.createElement('div');
|
|
407
|
+
div.classList.add('geolonia__error-message');
|
|
408
|
+
div.setAttribute('role', 'alert');
|
|
381
409
|
|
|
382
|
-
const
|
|
383
|
-
|
|
384
|
-
div.appendChild(h1);
|
|
410
|
+
const description = document.createElement('div');
|
|
411
|
+
description.classList.add('geolonia__error-message-description');
|
|
385
412
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
413
|
+
if (message) {
|
|
414
|
+
// 消費側が指定した文言。HTML は解釈せずテキストとして描画する。
|
|
415
|
+
description.textContent = message;
|
|
416
|
+
div.appendChild(description);
|
|
417
|
+
} else {
|
|
418
|
+
const title = document.createElement('h2');
|
|
419
|
+
title.classList.add('geolonia__error-message-title');
|
|
420
|
+
title.textContent = '地図を表示できませんでした';
|
|
421
|
+
div.appendChild(title);
|
|
422
|
+
|
|
423
|
+
const lead = document.createElement('p');
|
|
424
|
+
lead.classList.add('geolonia__error-message-lead');
|
|
425
|
+
lead.textContent =
|
|
426
|
+
'お使いの環境で地図の描画機能(WebGL)が利用できない状態になっている可能性があります。次の順にお試しください。';
|
|
427
|
+
description.appendChild(lead);
|
|
428
|
+
|
|
429
|
+
const steps = document.createElement('ol');
|
|
430
|
+
steps.classList.add('geolonia__error-message-steps');
|
|
431
|
+
for (const step of [
|
|
432
|
+
'ブラウザをすべて閉じて、開き直す',
|
|
433
|
+
'パソコンやスマートフォンを再起動する',
|
|
434
|
+
'別のブラウザで開く',
|
|
435
|
+
'パソコンの場合は、グラフィックドライバを更新する',
|
|
436
|
+
]) {
|
|
437
|
+
const li = document.createElement('li');
|
|
438
|
+
li.textContent = step;
|
|
439
|
+
steps.appendChild(li);
|
|
440
|
+
}
|
|
441
|
+
description.appendChild(steps);
|
|
442
|
+
|
|
443
|
+
const contact = document.createElement('p');
|
|
444
|
+
contact.classList.add('geolonia__error-message-contact');
|
|
445
|
+
contact.textContent =
|
|
446
|
+
'解決しない場合は、このサイトの窓口までご連絡ください。';
|
|
447
|
+
description.appendChild(contact);
|
|
448
|
+
|
|
449
|
+
// 手順を書き切れない狭いコンテナ向け。表示の切り替えは CSS が行う。
|
|
450
|
+
const brief = document.createElement('p');
|
|
451
|
+
brief.classList.add('geolonia__error-message-brief');
|
|
452
|
+
brief.textContent =
|
|
453
|
+
'ブラウザや端末を再起動すると解消する場合があります。';
|
|
454
|
+
description.appendChild(brief);
|
|
455
|
+
|
|
456
|
+
div.appendChild(description);
|
|
457
|
+
}
|
|
389
458
|
|
|
390
459
|
errorContainer.appendChild(div);
|
|
391
460
|
container.appendChild(errorContainer);
|
package/src/style.css
CHANGED
|
@@ -111,6 +111,11 @@
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/* Style for error message */
|
|
114
|
+
/*
|
|
115
|
+
* 文言は「手順を書き切った版」と「短縮版」の両方が DOM にあり、
|
|
116
|
+
* どちらを見せるかは地図コンテナの広さで切り替える。
|
|
117
|
+
* コンテナクエリ非対応のブラウザでは手順を書き切った版が出る(情報が減る側に倒さない)。
|
|
118
|
+
*/
|
|
114
119
|
.geolonia__error-container {
|
|
115
120
|
display: flex;
|
|
116
121
|
justify-content: center;
|
|
@@ -120,22 +125,82 @@
|
|
|
120
125
|
background-color: #dedede;
|
|
121
126
|
z-index: 9999;
|
|
122
127
|
position: absolute;
|
|
128
|
+
container-type: size;
|
|
129
|
+
container-name: geolonia-error;
|
|
123
130
|
}
|
|
124
131
|
|
|
125
132
|
.geolonia__error-message {
|
|
126
|
-
max-width:
|
|
133
|
+
max-width: 360px;
|
|
134
|
+
max-height: calc(100% - 20px);
|
|
135
|
+
overflow: auto;
|
|
127
136
|
background-color: #ffffff;
|
|
128
137
|
margin: 10px;
|
|
129
138
|
padding: 0.75rem 1.25rem;
|
|
130
139
|
border-radius: 6px;
|
|
131
|
-
position: absolute;
|
|
132
140
|
z-index: 99999;
|
|
133
141
|
word-wrap: break-word;
|
|
134
|
-
box-shadow: 0 4px 10px #0000001a
|
|
142
|
+
box-shadow: 0 4px 10px #0000001a;
|
|
143
|
+
font-size: 14px;
|
|
144
|
+
line-height: 1.6;
|
|
145
|
+
color: #333333;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.geolonia__error-message-title {
|
|
149
|
+
margin: 0 0 0.5em;
|
|
150
|
+
font-size: 16px;
|
|
151
|
+
line-height: 1.4;
|
|
135
152
|
}
|
|
136
153
|
|
|
137
154
|
.geolonia__error-message-description {
|
|
138
|
-
margin:
|
|
155
|
+
margin: 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.geolonia__error-message-lead {
|
|
159
|
+
margin: 0 0 0.5em;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.geolonia__error-message-steps {
|
|
163
|
+
margin: 0 0 0.5em;
|
|
164
|
+
padding-left: 1.4em;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.geolonia__error-message-contact {
|
|
168
|
+
margin: 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.geolonia__error-message-brief {
|
|
172
|
+
display: none;
|
|
173
|
+
margin: 0;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/* 中くらいの地図:手順リストは収まらないので 1 行の短縮版に切り替える */
|
|
177
|
+
@container geolonia-error ((max-width: 379px) or (max-height: 259px)) {
|
|
178
|
+
.geolonia__error-message-lead,
|
|
179
|
+
.geolonia__error-message-steps,
|
|
180
|
+
.geolonia__error-message-contact {
|
|
181
|
+
display: none;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.geolonia__error-message-brief {
|
|
185
|
+
display: block;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/* 小さい地図:見出しだけにする */
|
|
190
|
+
@container geolonia-error ((max-width: 239px) or (max-height: 139px)) {
|
|
191
|
+
.geolonia__error-message {
|
|
192
|
+
padding: 0.5rem 0.75rem;
|
|
193
|
+
font-size: 13px;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
.geolonia__error-message-title {
|
|
197
|
+
margin: 0;
|
|
198
|
+
font-size: 14px;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.geolonia__error-message-brief {
|
|
202
|
+
display: none;
|
|
203
|
+
}
|
|
139
204
|
}
|
|
140
205
|
|
|
141
206
|
/* CSS for Attribution */
|
package/src/types.ts
CHANGED
|
@@ -27,6 +27,12 @@ export type EmbedAttributes = {
|
|
|
27
27
|
key: string;
|
|
28
28
|
apiUrl: string;
|
|
29
29
|
loader: string;
|
|
30
|
+
/**
|
|
31
|
+
* `data-error-message`:地図の初期化に失敗したときの表示。
|
|
32
|
+
* 文字列を指定するとその文言に差し替え、`'off'` を指定するとエラー表示自体を行わない。
|
|
33
|
+
* 未指定のときは Embed 既定の案内(復旧手順つき)を表示する。
|
|
34
|
+
*/
|
|
35
|
+
errorMessage: string;
|
|
30
36
|
minZoom: string | number;
|
|
31
37
|
maxZoom: string | number;
|
|
32
38
|
'3d': string;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '5.2.
|
|
1
|
+
export const VERSION = '5.2.3';
|