@geolonia/embed 5.0.3 → 5.2.1
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 +9 -4
- package/.vscode/settings.json +27 -0
- package/CHANGELOG.md +9 -0
- package/README.md +71 -2
- package/dist/embed +1 -1
- package/dist/embed-chunks/12cbd0d1cb4cf744c32f.js +2 -0
- package/dist/embed-chunks/1492645e3d07fd3de940.js +1 -0
- package/dist/embed-chunks/8a521e8312a5b4da123d.js +2 -0
- package/dist/embed-chunks/8a521e8312a5b4da123d.js.LICENSE.txt +6 -0
- package/dist/embed-core.d.ts +14 -0
- package/dist/embed-core.js +2 -0
- package/dist/embed-core.js.LICENSE.txt +4 -0
- package/dist/{src/embed.d.ts → embed.d.ts} +2 -37
- package/dist/embed.js +1 -1
- package/dist/embed.js.LICENSE.txt +1 -1
- package/dist/lib/keyring.d.ts +45 -0
- package/dist/{src/lib → lib}/parse-atts.d.ts +1 -1
- package/dist/{src/lib → lib}/simplestyle.d.ts +2 -0
- package/dist/{src/lib → lib}/util.d.ts +3 -3
- package/dist/types.d.ts +38 -0
- package/dist/version.d.ts +1 -0
- package/e2e/basic.spec.ts +6 -1
- package/e2e/external-style.spec.ts +25 -0
- package/e2e/map.spec.ts +12 -12
- package/package.json +15 -8
- package/src/embed-core.ts +22 -0
- package/src/embed.ts +2 -42
- package/src/lib/geolonia-map.ts +4 -3
- package/src/lib/geolonia-marker.ts +1 -1
- package/src/lib/keyring.test.ts +58 -15
- package/src/lib/keyring.ts +53 -1
- package/src/lib/parse-atts.test.ts +2 -2
- package/src/lib/parse-atts.ts +5 -1
- package/src/lib/render.ts +1 -1
- package/src/lib/simplestyle.test.ts +94 -56
- package/src/lib/simplestyle.ts +75 -17
- package/src/lib/util.test.ts +136 -96
- package/src/lib/util.ts +55 -10
- package/src/testability.test.ts +13 -10
- package/src/types.ts +44 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +1 -0
- package/vitest.config.ts +8 -0
- package/webpack.config.js +45 -14
- package/.mocharc.js +0 -9
- package/dist/e2e/basic.spec.d.ts +0 -8
- package/dist/e2e/helper.d.ts +0 -4
- package/dist/e2e/map.spec.d.ts +0 -1
- package/dist/embed-chunks/2489af4328c51b71e92d.js +0 -2
- package/dist/playwright.config.d.ts +0 -9
- package/dist/src/lib/keyring.d.ts +0 -29
- package/dist/src/lib/keyring.test.d.ts +0 -1
- package/dist/src/lib/parse-atts.test.d.ts +0 -1
- package/dist/src/lib/simplestyle.test.d.ts +0 -1
- package/dist/src/lib/util.test.d.ts +0 -1
- package/dist/src/testability.test.d.ts +0 -1
- package/dist/src/version.d.ts +0 -1
- /package/dist/embed-chunks/{2489af4328c51b71e92d.js.LICENSE.txt → 12cbd0d1cb4cf744c32f.js.LICENSE.txt} +0 -0
- /package/dist/{src/lib → lib}/CustomAttributionControl.d.ts +0 -0
- /package/dist/{src/lib → lib}/controls/geolonia-control.d.ts +0 -0
- /package/dist/{src/lib → lib}/geolonia-map.d.ts +0 -0
- /package/dist/{src/lib → lib}/geolonia-marker.d.ts +0 -0
- /package/dist/{src/lib → lib}/maplibre-util.d.ts +0 -0
- /package/dist/{src/lib → lib}/render.d.ts +0 -0
- /package/dist/{src/lib → lib}/simplestyle-vector.d.ts +0 -0
- /package/dist/{src/types-internal.d.ts → types-internal.d.ts} +0 -0
package/src/lib/util.test.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { describe, it, expect, beforeAll } from 'vitest';
|
|
2
|
+
|
|
2
3
|
import { JSDOM } from 'jsdom';
|
|
3
4
|
import {
|
|
4
5
|
getContainer,
|
|
@@ -17,7 +18,7 @@ import {
|
|
|
17
18
|
|
|
18
19
|
const base = 'https://base.example.com/parent/';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
beforeAll(() => {
|
|
21
22
|
global.location = {
|
|
22
23
|
...global.location,
|
|
23
24
|
href: base,
|
|
@@ -26,58 +27,52 @@ before(() => {
|
|
|
26
27
|
|
|
27
28
|
describe('Tests for util.js', () => {
|
|
28
29
|
it('URL should be detected', () => {
|
|
29
|
-
|
|
30
|
+
expect(true).toEqual(!!isURL('http://example.com'));
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
it('URL with SSL should be detected', () => {
|
|
33
|
-
|
|
34
|
+
expect(true).toEqual(!!isURL('https://example.com'));
|
|
34
35
|
});
|
|
35
36
|
|
|
36
37
|
it('Path should be detected', () => {
|
|
37
|
-
|
|
38
|
-
'https://base.example.com/parent/example-path',
|
|
39
|
-
isURL('./example-path'),
|
|
38
|
+
expect('https://base.example.com/parent/example-path').toEqual(isURL('./example-path'),
|
|
40
39
|
);
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
it('Parent path should be detected', () => {
|
|
44
|
-
|
|
45
|
-
'https://base.example.com/example-path',
|
|
46
|
-
isURL('../example-path'),
|
|
43
|
+
expect('https://base.example.com/example-path').toEqual(isURL('../example-path'),
|
|
47
44
|
);
|
|
48
45
|
});
|
|
49
46
|
|
|
50
47
|
it('Absolute path should be detected', () => {
|
|
51
|
-
|
|
52
|
-
'https://base.example.com/example-path',
|
|
53
|
-
isURL('/example-path'),
|
|
48
|
+
expect('https://base.example.com/example-path').toEqual(isURL('/example-path'),
|
|
54
49
|
);
|
|
55
50
|
});
|
|
56
51
|
|
|
57
52
|
it('Name should not be detected', () => {
|
|
58
|
-
|
|
53
|
+
expect(false).toEqual(isURL('example.com/hello'));
|
|
59
54
|
});
|
|
60
55
|
|
|
61
56
|
describe('isGeoloniaTilesHost', () => {
|
|
62
57
|
it('detects primary tileserver hostname', () => {
|
|
63
58
|
const url =
|
|
64
59
|
'https://tileserver.geolonia.com/v3/tiles.json?key=YOUR-API-KEY';
|
|
65
|
-
|
|
60
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
66
61
|
});
|
|
67
62
|
|
|
68
63
|
it('detects tiles.geolonia.com subdomains', () => {
|
|
69
64
|
const url = new URL('https://osm.v2.tiles.geolonia.com/tiles.json');
|
|
70
|
-
|
|
65
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
71
66
|
});
|
|
72
67
|
|
|
73
68
|
it('detects tiles.geolonia.com subdomains', () => {
|
|
74
69
|
const url = new URL('https://osm.v3.tiles.geolonia.com/tiles.json');
|
|
75
|
-
|
|
70
|
+
expect(isGeoloniaTilesHost(url)).toBe(true);
|
|
76
71
|
});
|
|
77
72
|
|
|
78
73
|
it('returns false for other hosts or invalid urls', () => {
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
expect(isGeoloniaTilesHost('https://example.com/tiles')).toBe(false);
|
|
75
|
+
expect(isGeoloniaTilesHost('not-a-url')).toBe(false);
|
|
81
76
|
});
|
|
82
77
|
});
|
|
83
78
|
|
|
@@ -86,12 +81,10 @@ describe('Tests for util.js', () => {
|
|
|
86
81
|
<div class="test-class"></div>
|
|
87
82
|
</body></html>`).window;
|
|
88
83
|
|
|
89
|
-
|
|
90
|
-
true,
|
|
91
|
-
isDomElement(mocDocument.querySelector('.test-class')),
|
|
84
|
+
expect(true).toEqual(isDomElement(mocDocument.querySelector('.test-class')),
|
|
92
85
|
);
|
|
93
|
-
|
|
94
|
-
|
|
86
|
+
expect(false).toEqual(isDomElement('hello world'));
|
|
87
|
+
expect(false).toEqual(isDomElement({ hello: 'world' }));
|
|
95
88
|
});
|
|
96
89
|
|
|
97
90
|
it('should be able to get dom', () => {
|
|
@@ -104,26 +97,26 @@ describe('Tests for util.js', () => {
|
|
|
104
97
|
global.document = dom.window.document;
|
|
105
98
|
|
|
106
99
|
const el = document.querySelector('#test-element') as HTMLElement;
|
|
107
|
-
|
|
100
|
+
expect(el).toEqual(getContainer(el));
|
|
108
101
|
const params = { container: el };
|
|
109
|
-
|
|
102
|
+
expect(el).toEqual(getContainer(params));
|
|
110
103
|
|
|
111
104
|
// specify as a selector
|
|
112
|
-
|
|
113
|
-
|
|
105
|
+
expect(el).toEqual(getContainer('#test-element'));
|
|
106
|
+
expect(el).toEqual(getContainer({ container: '#test-element' }));
|
|
114
107
|
|
|
115
108
|
// specify as an id attribute value
|
|
116
|
-
|
|
117
|
-
|
|
109
|
+
expect(el).toEqual(getContainer('test-element'));
|
|
110
|
+
expect(el).toEqual(getContainer({ container: 'test-element' }));
|
|
118
111
|
|
|
119
112
|
// negative cases
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
113
|
+
expect(false).toEqual(getContainer('#fail-element'));
|
|
114
|
+
expect(false).toEqual(getContainer({ container: '#fail-element' }));
|
|
115
|
+
expect(false).toEqual(getContainer('fail-element'));
|
|
116
|
+
expect(false).toEqual(getContainer({ container: 'fail-element' }));
|
|
124
117
|
});
|
|
125
118
|
|
|
126
|
-
it('should merge
|
|
119
|
+
it('should merge legacy options into options as expected.', () => {
|
|
127
120
|
const dom = new JSDOM(`<html><body>
|
|
128
121
|
<div id="test-element"></div>
|
|
129
122
|
</body></html>`);
|
|
@@ -136,14 +129,14 @@ describe('Tests for util.js', () => {
|
|
|
136
129
|
document.getElementById('test-element'),
|
|
137
130
|
{ color: '#FF1122' },
|
|
138
131
|
);
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
expect(document.getElementById('test-element')).toEqual(options1.element);
|
|
133
|
+
expect(options1.color).toEqual('#FF1122');
|
|
141
134
|
|
|
142
135
|
const options2 = handleMarkerOptions(false, { color: '#FF1122' });
|
|
143
|
-
|
|
136
|
+
expect(options2.color).toEqual('#FF1122');
|
|
144
137
|
|
|
145
138
|
const options3 = handleMarkerOptions({ scale: 2 }, { color: '#FF1122' });
|
|
146
|
-
|
|
139
|
+
expect(options3.scale).toEqual(2);
|
|
147
140
|
});
|
|
148
141
|
|
|
149
142
|
describe('language detection', () => {
|
|
@@ -155,7 +148,7 @@ describe('Tests for util.js', () => {
|
|
|
155
148
|
languages: ['ja', 'en', 'en-US', 'ar'],
|
|
156
149
|
},
|
|
157
150
|
};
|
|
158
|
-
|
|
151
|
+
expect(getLang()).toEqual('ja');
|
|
159
152
|
});
|
|
160
153
|
|
|
161
154
|
it('should work with iOS safari', () => {
|
|
@@ -166,7 +159,7 @@ describe('Tests for util.js', () => {
|
|
|
166
159
|
languages: ['ja-JP'],
|
|
167
160
|
},
|
|
168
161
|
};
|
|
169
|
-
|
|
162
|
+
expect(getLang()).toEqual('ja');
|
|
170
163
|
});
|
|
171
164
|
});
|
|
172
165
|
|
|
@@ -174,86 +167,137 @@ describe('Tests for util.js', () => {
|
|
|
174
167
|
const atts = {
|
|
175
168
|
apiUrl: 'https://example.com',
|
|
176
169
|
key: '1234',
|
|
170
|
+
lang: 'en',
|
|
177
171
|
};
|
|
178
172
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
173
|
+
// 従来モード: 論理名(API キー必須)
|
|
174
|
+
expect('https://cdn.geolonia.com/style/hello/world/en.json').toEqual(getStyle('hello/world', atts),
|
|
175
|
+
);
|
|
176
|
+
|
|
177
|
+
// URL モード: https://(外部 URL、API キー不要)
|
|
178
|
+
expect('https://example.com/style.json').toEqual(getStyle('https://example.com/style.json', atts),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// URL モード: 相対パス ./(外部 URL、API キー不要)
|
|
182
|
+
expect('https://base.example.com/parent/style.json').toEqual(getStyle('./style.json', atts),
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
// URL モード: 絶対パス /(外部 URL、API キー不要)
|
|
186
|
+
expect('https://base.example.com/style.json').toEqual(getStyle('/style.json', atts),
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
// URL モード: .json で終わる(外部 URL として解決)
|
|
190
|
+
expect('https://base.example.com/parent/custom.json').toEqual(getStyle('custom.json', atts),
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
// デフォルト: 空文字列(API キー必須)
|
|
194
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/en.json').toEqual(getStyle('', atts),
|
|
182
195
|
);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
196
|
+
|
|
197
|
+
// デフォルト: null/undefined(API キー必須)
|
|
198
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/en.json').toEqual(getStyle(null, atts),
|
|
186
199
|
);
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
200
|
+
|
|
201
|
+
// 日本語環境でのデフォルト
|
|
202
|
+
const attsJa = { ...atts, lang: 'ja' };
|
|
203
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic-v2/ja.json').toEqual(getStyle('', attsJa),
|
|
190
204
|
);
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
205
|
+
|
|
206
|
+
// 日本語環境での論理名
|
|
207
|
+
expect('https://cdn.geolonia.com/style/geolonia/basic/ja.json').toEqual(getStyle('geolonia/basic', attsJa),
|
|
194
208
|
);
|
|
195
209
|
});
|
|
196
210
|
|
|
211
|
+
it('should throw error when using Geolonia styles without API key', () => {
|
|
212
|
+
const attsNoKey = {
|
|
213
|
+
apiUrl: 'https://example.com',
|
|
214
|
+
key: '',
|
|
215
|
+
lang: 'en',
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
// 論理名: API キー無しでエラー
|
|
219
|
+
expect(
|
|
220
|
+
() => getStyle('geolonia/basic', attsNoKey),
|
|
221
|
+
).toThrow(/API key is required/);
|
|
222
|
+
|
|
223
|
+
// デフォルト: API キー無しでエラー
|
|
224
|
+
expect(
|
|
225
|
+
() => getStyle('', attsNoKey),
|
|
226
|
+
).toThrow(/API key is required/);
|
|
227
|
+
|
|
228
|
+
// Geolonia CDN の URL: API キー無しでエラー
|
|
229
|
+
expect(
|
|
230
|
+
() => getStyle('https://cdn.geolonia.com/style/geolonia/basic/en.json', attsNoKey),
|
|
231
|
+
).toThrow(/API key is required/);
|
|
232
|
+
|
|
233
|
+
// 外部 URL: API キー無しでも OK
|
|
234
|
+
expect(() => {
|
|
235
|
+
getStyle('https://tile.openstreetmap.jp/styles/osm-bright/style.json', attsNoKey);
|
|
236
|
+
}).not.toThrow();
|
|
237
|
+
|
|
238
|
+
expect(() => {
|
|
239
|
+
getStyle('./my-style.json', attsNoKey);
|
|
240
|
+
}).not.toThrow();
|
|
241
|
+
});
|
|
242
|
+
|
|
197
243
|
it('should handle maplibregl options `minZoom` and `maxZoom` well', () => {
|
|
198
244
|
{
|
|
199
245
|
const atts = { minZoom: '', maxZoom: '10' };
|
|
200
246
|
const options = getOptions({}, {}, atts);
|
|
201
|
-
|
|
202
|
-
|
|
247
|
+
expect('undefined').toEqual(typeof options.minZoom);
|
|
248
|
+
expect(10).toEqual(options.maxZoom);
|
|
203
249
|
}
|
|
204
250
|
|
|
205
251
|
{
|
|
206
252
|
const atts = { minZoom: '0', maxZoom: '' };
|
|
207
253
|
const options = getOptions({}, {}, atts);
|
|
208
|
-
|
|
209
|
-
|
|
254
|
+
expect(0).toEqual(options.minZoom);
|
|
255
|
+
expect('undefined').toEqual(typeof options.maxZoom);
|
|
210
256
|
}
|
|
211
257
|
|
|
212
258
|
{
|
|
213
259
|
const atts = { minZoom: '0', maxZoom: '' };
|
|
214
260
|
const params = { minZoom: 7 };
|
|
215
261
|
const options = getOptions({}, params, atts);
|
|
216
|
-
|
|
217
|
-
|
|
262
|
+
expect(7).toEqual(options.minZoom);
|
|
263
|
+
expect('undefined').toEqual(typeof options.maxZoom);
|
|
218
264
|
}
|
|
219
265
|
});
|
|
220
266
|
|
|
221
267
|
it('should handle control position options.', () => {
|
|
222
268
|
const att = 'top-left';
|
|
223
269
|
const { enabled, position } = parseControlOption(att);
|
|
224
|
-
|
|
225
|
-
|
|
270
|
+
expect(true).toBe(enabled);
|
|
271
|
+
expect('top-left').toBe(position);
|
|
226
272
|
});
|
|
227
273
|
|
|
228
274
|
it('should handle control position on.', () => {
|
|
229
275
|
const att = 'on';
|
|
230
276
|
const { enabled, position } = parseControlOption(att);
|
|
231
|
-
|
|
232
|
-
|
|
277
|
+
expect(true).toBe(enabled);
|
|
278
|
+
expect(void 0).toBe(position);
|
|
233
279
|
});
|
|
234
280
|
|
|
235
281
|
it('should handle control position off.', () => {
|
|
236
282
|
const att = 'off';
|
|
237
283
|
const { enabled, position } = parseControlOption(att);
|
|
238
|
-
|
|
239
|
-
|
|
284
|
+
expect(false).toBe(enabled);
|
|
285
|
+
expect(void 0).toBe(position);
|
|
240
286
|
});
|
|
241
287
|
|
|
242
288
|
it('should parse simple vector value with http.', () => {
|
|
243
289
|
const attributeValue = 'https://example.com/path/to/tile.json';
|
|
244
|
-
|
|
290
|
+
expect(attributeValue).toBe(parseSimpleVector(attributeValue));
|
|
245
291
|
});
|
|
246
292
|
|
|
247
293
|
it('should parse simple vector value with geolonia schema.', () => {
|
|
248
294
|
const attributeValue = 'geolonia://tiles/username/ct_123';
|
|
249
|
-
|
|
295
|
+
expect(attributeValue).toBe(parseSimpleVector(attributeValue));
|
|
250
296
|
});
|
|
251
297
|
|
|
252
|
-
it('should parse simple vector value with
|
|
298
|
+
it('should parse simple vector value with custom tile ID', () => {
|
|
253
299
|
const attributeValue = 'ct_123';
|
|
254
|
-
|
|
255
|
-
'geolonia://tiles/custom/ct_123',
|
|
256
|
-
parseSimpleVector(attributeValue),
|
|
300
|
+
expect('geolonia://tiles/custom/ct_123').toBe(parseSimpleVector(attributeValue),
|
|
257
301
|
);
|
|
258
302
|
});
|
|
259
303
|
|
|
@@ -261,9 +305,7 @@ describe('Tests for util.js', () => {
|
|
|
261
305
|
it('should sanitize description', async () => {
|
|
262
306
|
const description =
|
|
263
307
|
'<script>alert("hello");</script>ここが集合場所です。13時までに集合してください。';
|
|
264
|
-
|
|
265
|
-
'ここが集合場所です。13時までに集合してください。',
|
|
266
|
-
await sanitizeDescription(description),
|
|
308
|
+
expect('ここが集合場所です。13時までに集合してください。').toBe(await sanitizeDescription(description),
|
|
267
309
|
);
|
|
268
310
|
});
|
|
269
311
|
|
|
@@ -271,26 +313,21 @@ describe('Tests for util.js', () => {
|
|
|
271
313
|
// Ref. https://www.npmjs.com/package/sanitize-html
|
|
272
314
|
const description =
|
|
273
315
|
'<img decoding="auto" src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。';
|
|
274
|
-
|
|
275
|
-
'<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。',
|
|
276
|
-
await sanitizeDescription(description),
|
|
316
|
+
expect('<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。').toBe(await sanitizeDescription(description),
|
|
277
317
|
);
|
|
278
318
|
});
|
|
279
319
|
|
|
280
320
|
it('should not sanitize "class" attribute', async () => {
|
|
281
321
|
const description =
|
|
282
322
|
'<span class="red">ここが集合場所です。13時までに集合してください。</span>';
|
|
283
|
-
|
|
284
|
-
'<span class="red">ここが集合場所です。13時までに集合してください。</span>',
|
|
285
|
-
await sanitizeDescription(description),
|
|
323
|
+
expect('<span class="red">ここが集合場所です。13時までに集合してください。</span>').toBe(await sanitizeDescription(description),
|
|
286
324
|
);
|
|
287
325
|
});
|
|
288
326
|
});
|
|
289
327
|
});
|
|
290
328
|
|
|
291
329
|
describe('loadImageCompatibility', () => {
|
|
292
|
-
it('should call the callback with response data when the promise resolves', (
|
|
293
|
-
// モックされた成功した promise
|
|
330
|
+
it('should call the callback with response data when the promise resolves', async () => {
|
|
294
331
|
const mockResponse = {
|
|
295
332
|
data: new Image(),
|
|
296
333
|
cacheControl: 'public, max-age=3600',
|
|
@@ -298,27 +335,30 @@ describe('loadImageCompatibility', () => {
|
|
|
298
335
|
};
|
|
299
336
|
const promise = Promise.resolve(mockResponse);
|
|
300
337
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
338
|
+
await new Promise<void>((resolve) => {
|
|
339
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
340
|
+
expect(error).toEqual(null);
|
|
341
|
+
expect(data).toEqual(mockResponse.data);
|
|
342
|
+
expect(expiry).toEqual({
|
|
343
|
+
cacheControl: mockResponse.cacheControl,
|
|
344
|
+
expires: mockResponse.expires,
|
|
345
|
+
});
|
|
346
|
+
resolve();
|
|
307
347
|
});
|
|
308
|
-
done();
|
|
309
348
|
});
|
|
310
349
|
});
|
|
311
350
|
|
|
312
|
-
it('should call the callback with error when the promise rejects', (
|
|
313
|
-
// モックされた失敗した promise
|
|
351
|
+
it('should call the callback with error when the promise rejects', async () => {
|
|
314
352
|
const mockError = new Error('Failed to load image');
|
|
315
353
|
const promise = Promise.reject(mockError);
|
|
316
354
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
355
|
+
await new Promise<void>((resolve) => {
|
|
356
|
+
loadImageCompatibility(promise, (error, data, expiry) => {
|
|
357
|
+
expect(error).toEqual(mockError);
|
|
358
|
+
expect(data).toBe(undefined);
|
|
359
|
+
expect(expiry).toBe(undefined);
|
|
360
|
+
resolve();
|
|
361
|
+
});
|
|
322
362
|
});
|
|
323
363
|
});
|
|
324
364
|
});
|
package/src/lib/util.ts
CHANGED
|
@@ -50,12 +50,12 @@ export function isGeoloniaTilesHost(url: string | URL): boolean {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export function checkPermission() {
|
|
53
|
-
// It looks that isn't iFrame, so
|
|
53
|
+
// It looks that isn't iFrame, so returns true.
|
|
54
54
|
if (window.self === window.parent) {
|
|
55
55
|
return true;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
// Always
|
|
58
|
+
// Always returns true if API key is loaded.
|
|
59
59
|
if (keyring.apiKey) {
|
|
60
60
|
return true;
|
|
61
61
|
}
|
|
@@ -106,7 +106,7 @@ export function checkPermission() {
|
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
108
|
* `window.parent` will be blocked if same origin policy is activated.
|
|
109
|
-
* So, it should be
|
|
109
|
+
* So, it should be caught.
|
|
110
110
|
*/
|
|
111
111
|
try {
|
|
112
112
|
if (window.self.location.origin === window.top.location.origin) {
|
|
@@ -147,7 +147,7 @@ export function isScrollable() {
|
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
/**
|
|
150
|
-
* Detects the object is
|
|
150
|
+
* Detects the object is HTMLElement?
|
|
151
151
|
*
|
|
152
152
|
* @param {*} o
|
|
153
153
|
*/
|
|
@@ -215,16 +215,61 @@ export function handleMarkerOptions(
|
|
|
215
215
|
}
|
|
216
216
|
|
|
217
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:// で始まる、または相対パス(/、./、../)
|
|
218
233
|
const styleUrl = isURL(style);
|
|
219
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
|
+
}
|
|
220
244
|
return styleUrl;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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;
|
|
226
264
|
}
|
|
227
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
|
+
}
|
|
228
273
|
}
|
|
229
274
|
|
|
230
275
|
// params are the parameters that have been passed to new geolonia.Map(params)
|
|
@@ -269,7 +314,7 @@ export function getOptions(container, params, atts): MapOptions {
|
|
|
269
314
|
/**
|
|
270
315
|
*
|
|
271
316
|
* @param {string} an data-*-control Embed attribute
|
|
272
|
-
* @returns { enabled:
|
|
317
|
+
* @returns { enabled: boolean, position: 'top-right' | 'bottom-right' | 'bottom-left' | 'top-left' | void }
|
|
273
318
|
*/
|
|
274
319
|
export function parseControlOption(att) {
|
|
275
320
|
const normalizedAtt = att.toLowerCase();
|
package/src/testability.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { describe, it, expect, vi } from 'vitest';
|
|
1
2
|
import { JSDOM } from 'jsdom';
|
|
2
|
-
|
|
3
|
+
|
|
3
4
|
import maplibregl from 'maplibre-gl';
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -10,11 +11,14 @@ import maplibregl from 'maplibre-gl';
|
|
|
10
11
|
|
|
11
12
|
describe('maplibre-gl jsdom limitation', () => {
|
|
12
13
|
it('jsdom上ではMaplibre Mapインスタンス生成時にエラー(WebGL未対応のため)', () => {
|
|
14
|
+
// jsdom の "Not implemented" メッセージを抑制
|
|
15
|
+
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
16
|
+
|
|
13
17
|
const dom = new JSDOM(
|
|
14
18
|
'<!DOCTYPE html><html><body><div id="map"></div></body></html>',
|
|
15
19
|
{
|
|
16
20
|
url: 'http://localhost',
|
|
17
|
-
pretendToBeVisual: true,
|
|
21
|
+
pretendToBeVisual: true,
|
|
18
22
|
},
|
|
19
23
|
);
|
|
20
24
|
// @ts-ignore
|
|
@@ -31,16 +35,15 @@ describe('maplibre-gl jsdom limitation', () => {
|
|
|
31
35
|
} catch (err) {
|
|
32
36
|
errorCaught = err;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
);
|
|
38
|
+
expect(errorCaught).toBeInstanceOf(Error);
|
|
39
|
+
expect(
|
|
40
|
+
/webgl|WebGL|context|device|Not implemented/i.test(errorCaught.message),
|
|
41
|
+
).toBe(true);
|
|
42
|
+
|
|
43
|
+
consoleSpy.mockRestore();
|
|
40
44
|
});
|
|
41
45
|
|
|
42
46
|
it('【NOTE】描画テストが必要な場合はE2E(ブラウザ実行)で行うこと', () => {
|
|
43
|
-
|
|
44
|
-
assert.strictEqual(true, true);
|
|
47
|
+
expect(true).toBe(true);
|
|
45
48
|
});
|
|
46
49
|
});
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type GeoloniaMap from './lib/geolonia-map';
|
|
2
|
+
|
|
3
|
+
export type EmbedAttributes = {
|
|
4
|
+
lat: string | number;
|
|
5
|
+
lng: string | number;
|
|
6
|
+
zoom: string | number;
|
|
7
|
+
bearing: string | number;
|
|
8
|
+
pitch: string | number;
|
|
9
|
+
hash: string;
|
|
10
|
+
marker: string;
|
|
11
|
+
markerColor: string;
|
|
12
|
+
openPopup: string;
|
|
13
|
+
customMarker: string;
|
|
14
|
+
customMarkerOffset: string;
|
|
15
|
+
gestureHandling: string;
|
|
16
|
+
navigationControl: string;
|
|
17
|
+
geolocateControl: string;
|
|
18
|
+
fullscreenControl: string;
|
|
19
|
+
scaleControl: string;
|
|
20
|
+
geoloniaControl: string;
|
|
21
|
+
geojson: string;
|
|
22
|
+
cluster: string;
|
|
23
|
+
clusterColor: string;
|
|
24
|
+
style: string;
|
|
25
|
+
lang: string;
|
|
26
|
+
plugin: string;
|
|
27
|
+
key: string;
|
|
28
|
+
apiUrl: string;
|
|
29
|
+
loader: string;
|
|
30
|
+
minZoom: string | number;
|
|
31
|
+
maxZoom: string | number;
|
|
32
|
+
'3d': string;
|
|
33
|
+
[otherKey: string]: string | number;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type EmbedPlugin<
|
|
37
|
+
PluginAttributes extends { [otherKey: string]: string } = {
|
|
38
|
+
[otherKey: string]: string;
|
|
39
|
+
},
|
|
40
|
+
> = (
|
|
41
|
+
map: GeoloniaMap,
|
|
42
|
+
target: HTMLElement,
|
|
43
|
+
atts: EmbedAttributes & PluginAttributes,
|
|
44
|
+
) => void;
|
package/tsconfig.json
CHANGED