@geolonia/embed 5.2.2 → 6.0.0-pre.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 +25 -1
- package/CHANGELOG.md +15 -0
- package/README.md +24 -1
- package/dist/embed +1 -1
- package/dist/embed-chunks/4ada77b78cc0cc5ccef9.js +1 -0
- package/dist/embed-chunks/8176630945512b29f294.js +2 -0
- package/dist/embed-chunks/c783fffcd28083f7d5cb.js +2 -0
- package/dist/embed-chunks/f2124097fda51d0079ee.js +1 -0
- package/dist/embed-core.d.ts +6 -7
- package/dist/embed-core.js +1 -1
- package/dist/embed.d.ts +2 -4
- package/dist/embed.js +1 -1
- package/dist/lib/parse-atts.d.ts +19 -0
- package/dist/lib/render.d.ts +1 -1
- package/dist/lib/util.d.ts +14 -55
- package/dist/types.d.ts +155 -1
- package/dist/version.d.ts +1 -1
- package/e2e/auto-render.spec.ts +44 -0
- package/e2e/basic.spec.ts +10 -74
- package/e2e/cleanup.spec.ts +43 -0
- package/e2e/data-attributes.spec.ts +56 -0
- package/e2e/globals.spec.ts +51 -0
- package/e2e/helper.ts +170 -4
- package/e2e/iframe.spec.ts +35 -0
- package/e2e/lazy-loading.spec.ts +32 -0
- package/e2e/legacy-constructor.spec.ts +102 -0
- package/e2e/plugin.spec.ts +25 -0
- package/e2e/pmtiles.spec.ts +13 -0
- package/package.json +8 -11
- package/playwright.config.ts +6 -32
- package/src/embed-core.ts +12 -14
- package/src/embed.ts +2 -4
- package/src/lib/parse-atts.test.ts +186 -18
- package/src/lib/parse-atts.ts +151 -5
- package/src/lib/render.ts +50 -12
- package/src/lib/util.ts +37 -350
- package/src/types.ts +155 -1
- package/src/version.ts +1 -1
- package/typedoc.json +13 -0
- package/vitest.config.ts +7 -0
- package/dist/embed-chunks/12cbd0d1cb4cf744c32f.js +0 -2
- package/dist/embed-chunks/8a521e8312a5b4da123d.js +0 -2
- package/dist/lib/CustomAttributionControl.d.ts +0 -47
- package/dist/lib/controls/geolonia-control.d.ts +0 -7
- package/dist/lib/geolonia-map.d.ts +0 -30
- package/dist/lib/geolonia-marker.d.ts +0 -9
- package/dist/lib/keyring.d.ts +0 -45
- package/dist/lib/maplibre-util.d.ts +0 -25
- package/dist/lib/simplestyle-vector.d.ts +0 -26
- package/dist/lib/simplestyle.d.ts +0 -31
- package/e2e/external-style.spec.ts +0 -25
- package/e2e/map.spec.ts +0 -69
- package/src/lib/CustomAttributionControl.ts +0 -394
- package/src/lib/controls/geolonia-control.ts +0 -38
- package/src/lib/geolonia-map.ts +0 -429
- package/src/lib/geolonia-marker.ts +0 -53
- package/src/lib/keyring.test.ts +0 -127
- package/src/lib/keyring.ts +0 -136
- package/src/lib/maplibre-util.ts +0 -137
- package/src/lib/marker.svg +0 -1
- package/src/lib/simplestyle-vector.ts +0 -257
- package/src/lib/simplestyle.test.ts +0 -289
- package/src/lib/simplestyle.ts +0 -435
- package/src/lib/util.test.ts +0 -364
- /package/dist/embed-chunks/{12cbd0d1cb4cf744c32f.js.LICENSE.txt → 8176630945512b29f294.js.LICENSE.txt} +0 -0
- /package/dist/embed-chunks/{8a521e8312a5b4da123d.js.LICENSE.txt → c783fffcd28083f7d5cb.js.LICENSE.txt} +0 -0
package/src/lib/util.ts
CHANGED
|
@@ -1,54 +1,51 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { keyring } from '
|
|
4
|
-
import type {
|
|
5
|
-
GetResourceResponse,
|
|
6
|
-
MapOptions,
|
|
7
|
-
MarkerOptions,
|
|
8
|
-
ExpiryData,
|
|
9
|
-
} from 'maplibre-gl';
|
|
10
|
-
|
|
11
|
-
// GetImageCallback extracted from maplibre-gl v3.6.2 ( https://github.com/maplibre/maplibre-gl-js/releases/tag/v3.6.2 )
|
|
12
|
-
export type GetImageCallback = (
|
|
13
|
-
error?: Error | null,
|
|
14
|
-
image?: HTMLImageElement | ImageBitmap | null,
|
|
15
|
-
expiry?: ExpiryData | null,
|
|
16
|
-
) => void;
|
|
3
|
+
import { keyring } from '@geolonia/maps-core';
|
|
17
4
|
|
|
18
5
|
/**
|
|
6
|
+
* Parse the Geolonia API key from the `?geolonia-api-key=` query of the
|
|
7
|
+
* embed `<script>` tag (backward compatibility).
|
|
8
|
+
*
|
|
9
|
+
* maps-core's keyring no longer scans the DOM, so this embed-specific
|
|
10
|
+
* helper reads the script tag and returns the key/stage for the caller to
|
|
11
|
+
* push into the keyring via `setApiKey()` / `setStage()`.
|
|
19
12
|
*
|
|
20
|
-
* @param
|
|
21
|
-
* @
|
|
13
|
+
* @param doc Document to scan (defaults to the global `document`)
|
|
14
|
+
* @returns `{ apiKey, stage }` when found, otherwise `null`
|
|
22
15
|
*/
|
|
23
|
-
export function
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
export function parseScriptTagApiKey(
|
|
17
|
+
doc: Document = document,
|
|
18
|
+
): { apiKey: string; stage: string } | null {
|
|
19
|
+
const scripts: HTMLScriptElement[] | HTMLCollectionOf<HTMLScriptElement> =
|
|
20
|
+
doc.currentScript
|
|
21
|
+
? [doc.currentScript as HTMLScriptElement]
|
|
22
|
+
: doc.getElementsByTagName('script');
|
|
23
|
+
|
|
24
|
+
for (const script of scripts) {
|
|
25
|
+
const src = script.src;
|
|
26
|
+
if (!src) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
// Resolve against a base URI so protocol-relative (`//cdn/...`) and
|
|
30
|
+
// relative script srcs don't throw `TypeError: Invalid URL`.
|
|
31
|
+
const url = new URL(src, doc.baseURI || window.location.href);
|
|
32
|
+
const apiKey = url.searchParams.get('geolonia-api-key');
|
|
33
|
+
|
|
34
|
+
if (apiKey) {
|
|
35
|
+
return {
|
|
36
|
+
apiKey,
|
|
37
|
+
stage: process.env.MAP_PLATFORM_STAGE || 'dev',
|
|
38
|
+
};
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function isGeoloniaTilesHost(url: string | URL): boolean {
|
|
39
|
-
try {
|
|
40
|
-
const urlObj = typeof url === 'string' ? new URL(url) : url;
|
|
41
|
-
|
|
42
|
-
return (
|
|
43
|
-
// NOTE: geolonia use tileserver.geolonia.com or *.tiles.geolonia.com for tile server. Other domains is NOT allowed.
|
|
44
|
-
urlObj.hostname === 'tileserver.geolonia.com' ||
|
|
45
|
-
urlObj.hostname.endsWith('.tiles.geolonia.com')
|
|
46
|
-
);
|
|
47
|
-
} catch {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
42
|
+
return null;
|
|
50
43
|
}
|
|
51
44
|
|
|
45
|
+
/**
|
|
46
|
+
* Detect whether the embed is allowed to render in the current (possibly
|
|
47
|
+
* iframed) context. Embed-specific: not provided by maps-core.
|
|
48
|
+
*/
|
|
52
49
|
export function checkPermission() {
|
|
53
50
|
// It looks that isn't iFrame, so returns true.
|
|
54
51
|
if (window.self === window.parent) {
|
|
@@ -118,313 +115,3 @@ export function checkPermission() {
|
|
|
118
115
|
|
|
119
116
|
return false;
|
|
120
117
|
}
|
|
121
|
-
|
|
122
|
-
export function getLang() {
|
|
123
|
-
const lang =
|
|
124
|
-
(window.navigator.languages &&
|
|
125
|
-
window.navigator.languages[0] &&
|
|
126
|
-
window.navigator.languages[0].toLowerCase()) ||
|
|
127
|
-
window.navigator.language.toLowerCase();
|
|
128
|
-
|
|
129
|
-
if (lang === 'ja' || lang === 'ja-jp') {
|
|
130
|
-
return 'ja';
|
|
131
|
-
} else {
|
|
132
|
-
return 'en';
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Detects the window is scrollable.
|
|
138
|
-
*/
|
|
139
|
-
export function isScrollable() {
|
|
140
|
-
const body = document.body;
|
|
141
|
-
const html = document.documentElement;
|
|
142
|
-
|
|
143
|
-
return (
|
|
144
|
-
body.scrollHeight > body.clientHeight ||
|
|
145
|
-
html.scrollHeight > html.clientHeight
|
|
146
|
-
);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Detects the object is HTMLElement?
|
|
151
|
-
*
|
|
152
|
-
* @param {*} o
|
|
153
|
-
*/
|
|
154
|
-
export function isDomElement(o): o is HTMLElement {
|
|
155
|
-
return typeof HTMLElement === 'object'
|
|
156
|
-
? o instanceof HTMLElement // DOM2
|
|
157
|
-
: o &&
|
|
158
|
-
typeof o === 'object' &&
|
|
159
|
-
o !== null &&
|
|
160
|
-
o.nodeType === 1 &&
|
|
161
|
-
typeof o.nodeName === 'string';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Gets the HTMLElement for the map.
|
|
166
|
-
* Possibility args are HTMLElement or CSS selector or object that has container property.
|
|
167
|
-
*
|
|
168
|
-
* @param {*} arg
|
|
169
|
-
* @return {HTMLElement | false}
|
|
170
|
-
*/
|
|
171
|
-
export function getContainer(
|
|
172
|
-
arg: HTMLElement | string | { container: HTMLElement | string },
|
|
173
|
-
): HTMLElement | false {
|
|
174
|
-
if (isDomElement(arg)) {
|
|
175
|
-
return arg;
|
|
176
|
-
} else if (typeof arg === 'string') {
|
|
177
|
-
const el =
|
|
178
|
-
(document.querySelector(arg) as HTMLElement) ||
|
|
179
|
-
document.getElementById(arg);
|
|
180
|
-
return el || false;
|
|
181
|
-
} else if (arg.container) {
|
|
182
|
-
if (isDomElement(arg.container)) {
|
|
183
|
-
return arg.container;
|
|
184
|
-
} else if (typeof arg.container === 'string') {
|
|
185
|
-
const el =
|
|
186
|
-
(document.querySelector(arg.container) as HTMLElement) ||
|
|
187
|
-
document.getElementById(arg.container);
|
|
188
|
-
return el || false;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Merge legacyOptions into options for geolonia.Marker class
|
|
197
|
-
*
|
|
198
|
-
* @param {*} options
|
|
199
|
-
* @param {*} legacyOptions
|
|
200
|
-
*/
|
|
201
|
-
export function handleMarkerOptions(
|
|
202
|
-
options: MarkerOptions | null | undefined | false,
|
|
203
|
-
legacyOptions: MarkerOptions,
|
|
204
|
-
) {
|
|
205
|
-
if (options && isDomElement(options)) {
|
|
206
|
-
options = {
|
|
207
|
-
element: options as HTMLElement,
|
|
208
|
-
...legacyOptions,
|
|
209
|
-
};
|
|
210
|
-
} else if (!options) {
|
|
211
|
-
options = legacyOptions;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return options;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
export function getStyle(style, atts) {
|
|
218
|
-
// Geolonia スタイルを使う場合は API キー必須
|
|
219
|
-
if (keyring.isGeoloniaStyleCheck(style) && !atts.key) {
|
|
220
|
-
throw new Error('[Geolonia] API key is required to use Geolonia styles. Please provide an API key or use an external style URL.');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// 空の場合はデフォルト(既存挙動を維持)
|
|
224
|
-
if (!style || style === '') {
|
|
225
|
-
if (atts.lang === 'ja') {
|
|
226
|
-
return 'https://cdn.geolonia.com/style/geolonia/basic-v2/ja.json';
|
|
227
|
-
} else {
|
|
228
|
-
return 'https://cdn.geolonia.com/style/geolonia/basic-v2/en.json';
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// URL モード: http:// or https:// で始まる、または相対パス(/、./、../)
|
|
233
|
-
const styleUrl = isURL(style);
|
|
234
|
-
if (styleUrl) {
|
|
235
|
-
// Mixed Content の警告
|
|
236
|
-
if (
|
|
237
|
-
location.protocol === 'https:' &&
|
|
238
|
-
styleUrl.startsWith('http:')
|
|
239
|
-
) {
|
|
240
|
-
console.warn( // eslint-disable-line no-console
|
|
241
|
-
`[Geolonia] Mixed Content Warning: You are loading a style from an insecure HTTP URL (${styleUrl}) on an HTTPS page. This may fail in modern browsers.`,
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
return styleUrl;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
// *.json で終わる場合も URL として扱う(相対パスの可能性)
|
|
248
|
-
if (style.endsWith('.json')) {
|
|
249
|
-
try {
|
|
250
|
-
const absoluteUrl = new URL(style, location.href).href;
|
|
251
|
-
if (
|
|
252
|
-
location.protocol === 'https:' &&
|
|
253
|
-
absoluteUrl.startsWith('http:')
|
|
254
|
-
) {
|
|
255
|
-
console.warn( // eslint-disable-line no-console
|
|
256
|
-
`[Geolonia] Mixed Content Warning: You are loading a style from an insecure HTTP URL (${absoluteUrl}) on an HTTPS page. This may fail in modern browsers.`,
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
return absoluteUrl;
|
|
260
|
-
} catch (error) {
|
|
261
|
-
console.error('[Geolonia] Failed to resolve style URL:', style, error); // eslint-disable-line no-console
|
|
262
|
-
// フォールバック: そのまま返す
|
|
263
|
-
return style;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// 従来モード: geolonia/basic などの論理名
|
|
268
|
-
if (atts.lang === 'ja') {
|
|
269
|
-
return `https://cdn.geolonia.com/style/${style}/ja.json`;
|
|
270
|
-
} else {
|
|
271
|
-
return `https://cdn.geolonia.com/style/${style}/en.json`;
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// params are the parameters that have been passed to new geolonia.Map(params)
|
|
276
|
-
// atts are the data-XYZ attributes that are on the container
|
|
277
|
-
export function getOptions(container, params, atts): MapOptions {
|
|
278
|
-
if (params.container) {
|
|
279
|
-
delete params.container; // Don't overwrite container.
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (params === container) {
|
|
283
|
-
params = {}; // `params` is HTMLElement, so we shouldn't merge it into options.
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const options: MapOptions = {
|
|
287
|
-
style: atts.style || params.style, // Validation for value of `style` will be processed on `setStyle()`.
|
|
288
|
-
container,
|
|
289
|
-
center: [parseFloat(atts.lng), parseFloat(atts.lat)],
|
|
290
|
-
bearing: parseFloat(atts.bearing),
|
|
291
|
-
pitch: parseFloat(atts.pitch),
|
|
292
|
-
zoom: parseFloat(atts.zoom),
|
|
293
|
-
hash: atts.hash === 'on',
|
|
294
|
-
localIdeographFontFamily: 'sans-serif',
|
|
295
|
-
attributionControl: false,
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
if (
|
|
299
|
-
atts.minZoom !== '' &&
|
|
300
|
-
(Number(atts.minZoom) === 0 || Number(atts.minZoom))
|
|
301
|
-
) {
|
|
302
|
-
options.minZoom = Number(atts.minZoom);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
if (atts.maxZoom !== '' && Number(atts.maxZoom)) {
|
|
306
|
-
options.maxZoom = Number(atts.maxZoom);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
Object.assign(options, params);
|
|
310
|
-
|
|
311
|
-
return options;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
*
|
|
316
|
-
* @param {string} an data-*-control Embed attribute
|
|
317
|
-
* @returns { enabled: boolean, position: 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left' | void }
|
|
318
|
-
*/
|
|
319
|
-
export function parseControlOption(att) {
|
|
320
|
-
const normalizedAtt = att.toLowerCase();
|
|
321
|
-
if (
|
|
322
|
-
['top-right', 'bottom-right', 'bottom-left', 'top-left'].includes(
|
|
323
|
-
normalizedAtt,
|
|
324
|
-
)
|
|
325
|
-
) {
|
|
326
|
-
return { enabled: true, position: normalizedAtt };
|
|
327
|
-
} else if (['on', 'off'].includes(normalizedAtt)) {
|
|
328
|
-
return { enabled: normalizedAtt === 'on', position: void 0 };
|
|
329
|
-
} else {
|
|
330
|
-
return { enabled: false, position: void 0 };
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* keep session
|
|
336
|
-
*/
|
|
337
|
-
let sessionId = '';
|
|
338
|
-
|
|
339
|
-
/**
|
|
340
|
-
*
|
|
341
|
-
* @param {number} digits for session
|
|
342
|
-
* @returns sessionId
|
|
343
|
-
*/
|
|
344
|
-
export const getSessionId = (digit) => {
|
|
345
|
-
if (sessionId) {
|
|
346
|
-
return sessionId;
|
|
347
|
-
} else {
|
|
348
|
-
const array = new Uint8Array(digit / 2);
|
|
349
|
-
window.crypto.getRandomValues(array);
|
|
350
|
-
const value = Array.from(array, (dec) =>
|
|
351
|
-
dec.toString(16).padStart(2, '0'),
|
|
352
|
-
).join('');
|
|
353
|
-
sessionId = value;
|
|
354
|
-
return value;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
export const parseSimpleVector = (attributeValue) => {
|
|
359
|
-
if (/^(https?|geolonia):\/\//.test(attributeValue)) {
|
|
360
|
-
return attributeValue;
|
|
361
|
-
} else {
|
|
362
|
-
return `geolonia://tiles/custom/${attributeValue}`;
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
export const handleRestrictedMode = (map) => {
|
|
367
|
-
if (!map._geolonia_restricted_mode_handled) {
|
|
368
|
-
map._geolonia_restricted_mode_handled = true;
|
|
369
|
-
const container = map.getContainer();
|
|
370
|
-
map.remove();
|
|
371
|
-
container.innerHTML = '';
|
|
372
|
-
container.classList.add('geolonia__restricted-mode-image-container');
|
|
373
|
-
}
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
export const handleErrorMode = (container) => {
|
|
377
|
-
const errorContainer = document.createElement('div');
|
|
378
|
-
errorContainer.classList.add('geolonia__error-container');
|
|
379
|
-
|
|
380
|
-
const div = document.createElement('div');
|
|
381
|
-
|
|
382
|
-
const h1 = document.createElement('h2');
|
|
383
|
-
h1.textContent = 'Geolonia Maps';
|
|
384
|
-
div.appendChild(h1);
|
|
385
|
-
|
|
386
|
-
div.classList.add('geolonia__error-message');
|
|
387
|
-
div.innerHTML +=
|
|
388
|
-
'<div class="geolonia__error-message-description">地図の初期化に失敗しました。管理者にお問い合わせ下さい。開発者の方は開発者ツールでエラー詳細をご確認下さい。</div>';
|
|
389
|
-
|
|
390
|
-
errorContainer.appendChild(div);
|
|
391
|
-
container.appendChild(errorContainer);
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
export const sanitizeDescription = async (description) => {
|
|
395
|
-
const { default: sanitizeHtml } = await import('sanitize-html');
|
|
396
|
-
return sanitizeHtml(description, {
|
|
397
|
-
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img']),
|
|
398
|
-
allowedAttributes: {
|
|
399
|
-
...sanitizeHtml.defaults.allowedAttributes,
|
|
400
|
-
'*': ['class'],
|
|
401
|
-
},
|
|
402
|
-
});
|
|
403
|
-
};
|
|
404
|
-
|
|
405
|
-
export const random = (max: number): number => Math.floor(Math.random() * max);
|
|
406
|
-
|
|
407
|
-
// This function is used to provide backward compatibility with callback invocations,
|
|
408
|
-
// so we ignore ESLint rules for this function.
|
|
409
|
-
// Note: this cannot be a generic promiseToCallback function because the callback is not
|
|
410
|
-
// the traditional (error, result) style callback.
|
|
411
|
-
export function loadImageCompatibility(
|
|
412
|
-
promise: Promise<GetResourceResponse<HTMLImageElement | ImageBitmap>>,
|
|
413
|
-
callback: GetImageCallback,
|
|
414
|
-
): void {
|
|
415
|
-
promise
|
|
416
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
417
|
-
.then((response) => {
|
|
418
|
-
// eslint-disable-next-line promise/no-callback-in-promise
|
|
419
|
-
callback(null, response.data, {
|
|
420
|
-
cacheControl: response.cacheControl,
|
|
421
|
-
expires: response.expires,
|
|
422
|
-
});
|
|
423
|
-
return;
|
|
424
|
-
})
|
|
425
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
426
|
-
.catch((error) => {
|
|
427
|
-
// eslint-disable-next-line promise/no-callback-in-promise
|
|
428
|
-
callback(error);
|
|
429
|
-
});
|
|
430
|
-
}
|
package/src/types.ts
CHANGED
|
@@ -1,38 +1,192 @@
|
|
|
1
|
-
import type GeoloniaMap from '
|
|
1
|
+
import type { GeoloniaMap } from '@geolonia/maps-core';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* `.geolonia` の地図コンテナから読み取った `data-*` 属性を正規化した形。
|
|
5
|
+
*
|
|
6
|
+
* 各プロパティは kebab-case の `data-*` 属性に対応する(`markerColor` は
|
|
7
|
+
* `data-marker-color`、`'3d'` は `data-3d`)。
|
|
8
|
+
* `parseAtts` がコンテナの `dataset` を読み、以下に示す既定値を補う。
|
|
9
|
+
* `data-*` で指定された値は文字列のまま保持され、未指定の数値フィールドには
|
|
10
|
+
* 数値の既定値が入る。on/off のフラグはリテラル文字列 `'on'` / `'off'` である。
|
|
11
|
+
* この形はそのまま登録済みの {@link EmbedPlugin} に渡されるため、後方互換のために
|
|
12
|
+
* 構造を安定させている。地図自体はこの値から `attsToOptions` を経て構築される。
|
|
13
|
+
*/
|
|
3
14
|
export type EmbedAttributes = {
|
|
15
|
+
/**
|
|
16
|
+
* `data-lat`:地図中心の緯度。中心は `data-lat` と `data-lng` の両方が
|
|
17
|
+
* 指定されたときにのみ適用される。
|
|
18
|
+
* @defaultValue `0`
|
|
19
|
+
*/
|
|
4
20
|
lat: string | number;
|
|
21
|
+
/**
|
|
22
|
+
* `data-lng`:地図中心の経度。{@link EmbedAttributes.lat} を参照。
|
|
23
|
+
* @defaultValue `0`
|
|
24
|
+
*/
|
|
5
25
|
lng: string | number;
|
|
26
|
+
/**
|
|
27
|
+
* `data-zoom`:初期ズームレベル。
|
|
28
|
+
* @defaultValue `0`
|
|
29
|
+
*/
|
|
6
30
|
zoom: string | number;
|
|
31
|
+
/**
|
|
32
|
+
* `data-bearing`:初期方位(回転)。単位は度。
|
|
33
|
+
* @defaultValue `0`
|
|
34
|
+
*/
|
|
7
35
|
bearing: string | number;
|
|
36
|
+
/**
|
|
37
|
+
* `data-pitch`:初期ピッチ(傾き)。単位は度。
|
|
38
|
+
* @defaultValue `0`
|
|
39
|
+
*/
|
|
8
40
|
pitch: string | number;
|
|
41
|
+
/**
|
|
42
|
+
* `data-hash`(`'on'` / `'off'`):地図の表示位置を URL のハッシュに同期する。
|
|
43
|
+
* @defaultValue `'off'`
|
|
44
|
+
*/
|
|
9
45
|
hash: string;
|
|
46
|
+
/**
|
|
47
|
+
* `data-marker`(`'on'` / `'off'`):中心にマーカーを表示する。中心が設定されて
|
|
48
|
+
* いるときにのみ有効({@link EmbedAttributes.lat} を参照)。
|
|
49
|
+
* @defaultValue `'on'`
|
|
50
|
+
*/
|
|
10
51
|
marker: string;
|
|
52
|
+
/**
|
|
53
|
+
* `data-marker-color`:中心マーカーの色。
|
|
54
|
+
* @defaultValue `'#E4402F'`
|
|
55
|
+
*/
|
|
11
56
|
markerColor: string;
|
|
57
|
+
/**
|
|
58
|
+
* `data-open-popup`(`'on'` / `'off'`):読み込み時にマーカーのポップアップを開く。
|
|
59
|
+
* @defaultValue `'off'`
|
|
60
|
+
*/
|
|
12
61
|
openPopup: string;
|
|
62
|
+
/**
|
|
63
|
+
* `data-custom-marker`:マーカーとして使う要素の CSS セレクタ。
|
|
64
|
+
* @defaultValue `''`
|
|
65
|
+
*/
|
|
13
66
|
customMarker: string;
|
|
67
|
+
/**
|
|
68
|
+
* `data-custom-marker-offset`:マーカーのオフセット。`"x, y"` 形式のピクセル値。
|
|
69
|
+
* @defaultValue `'0, 0'`
|
|
70
|
+
*/
|
|
14
71
|
customMarkerOffset: string;
|
|
72
|
+
/**
|
|
73
|
+
* `data-gesture-handling`(`'on'` / `'off'`):パン、ズーム、回転のジェスチャを
|
|
74
|
+
* 有効にする。地図を非インタラクティブに生成した場合は `'off'` に固定される。
|
|
75
|
+
* @defaultValue `'on'`
|
|
76
|
+
*/
|
|
15
77
|
gestureHandling: string;
|
|
78
|
+
/**
|
|
79
|
+
* `data-navigation-control`:ズームと回転のコントロール。`'on'` / `'off'`、または
|
|
80
|
+
* 表示位置(`'top-right'`、`'bottom-left'` など)を受け付ける。
|
|
81
|
+
* @defaultValue `'on'`
|
|
82
|
+
*/
|
|
16
83
|
navigationControl: string;
|
|
84
|
+
/**
|
|
85
|
+
* `data-geolocate-control`:現在地コントロール。`'on'` / `'off'`、または表示位置を
|
|
86
|
+
* 受け付ける。
|
|
87
|
+
* @defaultValue `'off'`
|
|
88
|
+
*/
|
|
17
89
|
geolocateControl: string;
|
|
90
|
+
/**
|
|
91
|
+
* `data-fullscreen-control`:全画面コントロール。`'on'` / `'off'`、または表示位置を
|
|
92
|
+
* 受け付ける。
|
|
93
|
+
* @defaultValue `'off'`
|
|
94
|
+
*/
|
|
18
95
|
fullscreenControl: string;
|
|
96
|
+
/**
|
|
97
|
+
* `data-scale-control`:スケールバー。`'on'` / `'off'`、または表示位置を受け付ける。
|
|
98
|
+
* @defaultValue `'off'`
|
|
99
|
+
*/
|
|
19
100
|
scaleControl: string;
|
|
101
|
+
/**
|
|
102
|
+
* `data-geolonia-control`:Geolonia のアトリビューション(ロゴ)コントロール。
|
|
103
|
+
* `'on'` / `'off'`、または表示位置を受け付ける。
|
|
104
|
+
* @defaultValue `'on'`
|
|
105
|
+
*/
|
|
20
106
|
geoloniaControl: string;
|
|
107
|
+
/**
|
|
108
|
+
* `data-geojson`:GeoJSON のソース。URL、インラインの JSON 文字列、または
|
|
109
|
+
* インライン要素(`<script type="application/json">` など)を指す CSS セレクタの
|
|
110
|
+
* いずれか。
|
|
111
|
+
* @defaultValue `''`
|
|
112
|
+
*/
|
|
21
113
|
geojson: string;
|
|
114
|
+
/**
|
|
115
|
+
* `data-cluster`(`'on'` / `'off'`):GeoJSON のポイント地物をクラスタリングする。
|
|
116
|
+
* @defaultValue `'on'`
|
|
117
|
+
*/
|
|
22
118
|
cluster: string;
|
|
119
|
+
/**
|
|
120
|
+
* `data-cluster-color`:クラスタ化されたポイントマーカーの色。
|
|
121
|
+
* @defaultValue `'#ff0000'`
|
|
122
|
+
*/
|
|
23
123
|
clusterColor: string;
|
|
124
|
+
/**
|
|
125
|
+
* `data-style`:地図スタイル。Geolonia のスタイル名(`geolonia/basic-v2`)、
|
|
126
|
+
* style.json の完全な URL、または相対パスのいずれか。
|
|
127
|
+
* @defaultValue `'geolonia/basic-v2'`
|
|
128
|
+
*/
|
|
24
129
|
style: string;
|
|
130
|
+
/**
|
|
131
|
+
* `data-lang`:ラベルの言語。`data-lang` に指定できるのは `'ja'`、`'en'`、
|
|
132
|
+
* `'auto'` など。`parseAtts` は `'ja'` のみを `'ja'` に解決し、それ以外の明示値は
|
|
133
|
+
* `'en'` に解決する(`'ja-jp'` も `'en'` になる)。`'auto'` および未指定のときは
|
|
134
|
+
* ブラウザ言語(`getLang()` の結果。`'ja'` または `'en'`)になる。
|
|
135
|
+
* @defaultValue 未指定のときは `getLang()` の結果(`'ja'` または `'en'`)
|
|
136
|
+
*/
|
|
25
137
|
lang: string;
|
|
138
|
+
/**
|
|
139
|
+
* `data-plugin`:実行する埋め込みプラグイン名。無効にする場合は `'off'`。
|
|
140
|
+
* @defaultValue `'off'`
|
|
141
|
+
*/
|
|
26
142
|
plugin: string;
|
|
143
|
+
/**
|
|
144
|
+
* `data-key`:Geolonia の API キー(埋め込み `<script>` タグの
|
|
145
|
+
* `?geolonia-api-key=` クエリで指定しない場合に使う)。
|
|
146
|
+
* @defaultValue キーリングが保持する現在の API キー
|
|
147
|
+
*/
|
|
27
148
|
key: string;
|
|
149
|
+
/**
|
|
150
|
+
* `data-api-url`:Geolonia API のエンドポイントのベース URL。
|
|
151
|
+
* @defaultValue `` `https://api.geolonia.com/${stage}` ``
|
|
152
|
+
*/
|
|
28
153
|
apiUrl: string;
|
|
154
|
+
/**
|
|
155
|
+
* `data-loader`(`'on'` / `'off'`):地図の初期化中にローディング表示を出す。
|
|
156
|
+
* @defaultValue `'on'`
|
|
157
|
+
*/
|
|
29
158
|
loader: string;
|
|
159
|
+
/**
|
|
160
|
+
* `data-min-zoom`:最小ズームレベル。空文字列は「未指定」を意味する。
|
|
161
|
+
* @defaultValue `''`
|
|
162
|
+
*/
|
|
30
163
|
minZoom: string | number;
|
|
164
|
+
/**
|
|
165
|
+
* `data-max-zoom`:最大ズームレベル。
|
|
166
|
+
* @defaultValue `20`
|
|
167
|
+
*/
|
|
31
168
|
maxZoom: string | number;
|
|
169
|
+
/**
|
|
170
|
+
* `data-3d`(`'on'` / `'off'`):3D 建物を描画する。
|
|
171
|
+
* @defaultValue `''`(off として扱われる)
|
|
172
|
+
*/
|
|
32
173
|
'3d': string;
|
|
174
|
+
/**
|
|
175
|
+
* 追加の `data-*` 属性はそのまま透過される({@link EmbedPlugin} が利用する
|
|
176
|
+
* プラグイン固有の属性など)。
|
|
177
|
+
*/
|
|
33
178
|
[otherKey: string]: string | number;
|
|
34
179
|
};
|
|
35
180
|
|
|
181
|
+
/**
|
|
182
|
+
* 埋め込みプラグインの型。地図インスタンス、対象のコンテナ要素、正規化済みの
|
|
183
|
+
* {@link EmbedAttributes} を受け取って呼び出される。
|
|
184
|
+
*
|
|
185
|
+
* 呼び出しのタイミングは地図の生成時点で異なる。`DOMContentLoaded` 後に生成された
|
|
186
|
+
* 地図では生成直後に呼び出される。それ以前に生成された地図では `DOMContentLoaded`
|
|
187
|
+
* まで保留され、そのイベント時にまとめて呼び出される。呼び出し前に削除された地図に
|
|
188
|
+
* 対しては呼び出されない。
|
|
189
|
+
*/
|
|
36
190
|
export type EmbedPlugin<
|
|
37
191
|
PluginAttributes extends { [otherKey: string]: string } = {
|
|
38
192
|
[otherKey: string]: string;
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '
|
|
1
|
+
export const VERSION = '6.0.0-pre.2';
|
package/typedoc.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://typedoc.org/schema.json",
|
|
3
|
+
"plugin": ["typedoc-plugin-markdown"],
|
|
4
|
+
"entryPoints": ["src/types.ts"],
|
|
5
|
+
"out": "api-docs",
|
|
6
|
+
"excludePrivate": true,
|
|
7
|
+
"excludeInternal": true,
|
|
8
|
+
"excludeExternals": true,
|
|
9
|
+
"readme": "none",
|
|
10
|
+
"githubPages": false,
|
|
11
|
+
"disableSources": true,
|
|
12
|
+
"flattenOutputFiles": true
|
|
13
|
+
}
|
package/vitest.config.ts
CHANGED
|
@@ -4,5 +4,12 @@ export default defineConfig({
|
|
|
4
4
|
test: {
|
|
5
5
|
include: ['src/**/*.test.ts'],
|
|
6
6
|
environment: 'jsdom',
|
|
7
|
+
// maps-core ships ESM that named-imports from maplibre-gl (CJS). Inline it
|
|
8
|
+
// so Vite transforms the module and handles the CJS/ESM interop.
|
|
9
|
+
server: {
|
|
10
|
+
deps: {
|
|
11
|
+
inline: ['@geolonia/maps-core'],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
7
14
|
},
|
|
8
15
|
});
|