@geolonia/embed 3.0.0 → 3.1.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 +23 -9
- package/dist/embed +1 -1
- package/dist/embed.js +1 -1
- package/package.json +2 -2
- package/src/lib/geolonia-map.js +5 -0
- package/src/lib/simplestyle-vector.js +4 -3
- package/src/lib/simplestyle.js +5 -4
- package/src/lib/simplestyle.test.js +1 -0
- package/src/lib/util.js +8 -0
- package/src/lib/util.test.js +27 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.1",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "src/embed.d.ts",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@babel/cli": "^7.19.3",
|
|
27
27
|
"@babel/core": "^7.20.5",
|
|
28
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
28
29
|
"@babel/plugin-transform-classes": "^7.20.2",
|
|
29
30
|
"@babel/preset-env": "^7.20.2",
|
|
30
31
|
"@babel/register": "^7.18.9",
|
|
31
32
|
"@geolonia/eslint-config": "^0.0.1",
|
|
32
|
-
"@babel/eslint-parser": "^7.19.1",
|
|
33
33
|
"babel-loader": "^9.1.0",
|
|
34
34
|
"css-loader": "^6.7.2",
|
|
35
35
|
"eslint": "^8.29.0",
|
package/src/lib/geolonia-map.js
CHANGED
|
@@ -41,6 +41,11 @@ export default class GeoloniaMap extends maplibregl.Map {
|
|
|
41
41
|
return container.geoloniaMap;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
if (container.clientHeight === 0) {
|
|
45
|
+
// eslint-disable-next-line no-console
|
|
46
|
+
console.warn('Geolonia Embed API failed to render the map because the container has no height. Please set the CSS property `height` to the container.');
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
const atts = parseAtts(container, params);
|
|
45
50
|
const options = util.getOptions(container, params, atts);
|
|
46
51
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import maplibregl from 'maplibre-gl';
|
|
4
4
|
import turfCenter from '@turf/center';
|
|
5
|
+
import { sanitizeDescription } from './util';
|
|
5
6
|
|
|
6
7
|
const textColor = '#000000';
|
|
7
8
|
const textHaloColor = '#FFFFFF';
|
|
@@ -201,13 +202,13 @@ class SimpleStyleVector {
|
|
|
201
202
|
}
|
|
202
203
|
|
|
203
204
|
async setPopup(map, source) {
|
|
204
|
-
|
|
205
|
-
map.on('click', source, (e) => {
|
|
205
|
+
map.on('click', source, async (e) => {
|
|
206
206
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
207
207
|
const description = e.features[0].properties.description;
|
|
208
208
|
|
|
209
209
|
if (description) {
|
|
210
|
-
|
|
210
|
+
const sanitizedDescription = await sanitizeDescription(description);
|
|
211
|
+
new maplibregl.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
211
212
|
}
|
|
212
213
|
});
|
|
213
214
|
|
package/src/lib/simplestyle.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import maplibregl from 'maplibre-gl';
|
|
4
4
|
import geojsonExtent from '@mapbox/geojson-extent';
|
|
5
5
|
import turfCenter from '@turf/center';
|
|
6
|
-
import { isURL } from './util';
|
|
6
|
+
import { isURL, sanitizeDescription } from './util';
|
|
7
7
|
|
|
8
8
|
const textColor = '#000000';
|
|
9
9
|
const textHaloColor = '#FFFFFF';
|
|
@@ -236,6 +236,7 @@ class SimpleStyle {
|
|
|
236
236
|
['literal', [0, 0.8]],
|
|
237
237
|
],
|
|
238
238
|
'text-allow-overlap': false,
|
|
239
|
+
'icon-allow-overlap': true,
|
|
239
240
|
},
|
|
240
241
|
});
|
|
241
242
|
|
|
@@ -244,13 +245,13 @@ class SimpleStyle {
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
async setPopup(map, source) {
|
|
247
|
-
|
|
248
|
-
map.on('click', source, (e) => {
|
|
248
|
+
map.on('click', source, async (e) => {
|
|
249
249
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
250
250
|
const description = e.features[0].properties.description;
|
|
251
251
|
|
|
252
252
|
if (description) {
|
|
253
|
-
|
|
253
|
+
const sanitizedDescription = await sanitizeDescription(description);
|
|
254
|
+
new maplibregl.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
254
255
|
}
|
|
255
256
|
});
|
|
256
257
|
|
|
@@ -83,6 +83,7 @@ describe('Tests for simpleStyle()', () => {
|
|
|
83
83
|
assert.deepEqual([ 'geolonia-simple-style', 'geolonia-simple-style-points' ], Object.keys(map.sources));
|
|
84
84
|
assert.deepEqual(8, map.layers.length);
|
|
85
85
|
assert.deepEqual(true, map.bounds);
|
|
86
|
+
assert.deepEqual(true, map.layers.find((layer) => layer.id === 'geolonia-simple-style-symbol-points').layout['icon-allow-overlap']);
|
|
86
87
|
});
|
|
87
88
|
|
|
88
89
|
it('should has sources and layers as expected with custom IDs', async () => {
|
package/src/lib/util.js
CHANGED
|
@@ -274,3 +274,11 @@ export const handleRestrictedMode = (map) => {
|
|
|
274
274
|
container.classList.add('geolonia__restricted-mode-image-container');
|
|
275
275
|
}
|
|
276
276
|
};
|
|
277
|
+
|
|
278
|
+
export const sanitizeDescription = async (description) => {
|
|
279
|
+
const { default: sanitizeHtml } = await import('sanitize-html');
|
|
280
|
+
return sanitizeHtml(description, {
|
|
281
|
+
allowedTags: sanitizeHtml.defaults.allowedTags.concat([ 'img' ]),
|
|
282
|
+
allowedAttributes: {...sanitizeHtml.defaults.allowedAttributes, '*': ['class']},
|
|
283
|
+
});
|
|
284
|
+
};
|
package/src/lib/util.test.js
CHANGED
|
@@ -202,4 +202,31 @@ describe('Tests for util.js', () => {
|
|
|
202
202
|
util.parseSimpleVector(attributeValue),
|
|
203
203
|
);
|
|
204
204
|
});
|
|
205
|
+
|
|
206
|
+
describe('Tests for sanitizeDescription', async () => {
|
|
207
|
+
it('should sanitize description', async () => {
|
|
208
|
+
const description = '<script>alert("hello");</script>ここが集合場所です。13時までに集合してください。';
|
|
209
|
+
assert.strictEqual(
|
|
210
|
+
'ここが集合場所です。13時までに集合してください。',
|
|
211
|
+
await util.sanitizeDescription(description),
|
|
212
|
+
);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('should not sanitize img tag, but should sanitize attributes other than "src", "srcset", "alt", "title", "width", "height", "loading"', async () => {
|
|
216
|
+
// Ref. https://www.npmjs.com/package/sanitize-html
|
|
217
|
+
const description = '<img decoding="auto" src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。';
|
|
218
|
+
assert.strictEqual(
|
|
219
|
+
'<img src="hibiya-park.jpeg" /><br />ここが集合場所です。13時までに集合してください。',
|
|
220
|
+
await util.sanitizeDescription(description),
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it('should not sanitize "class" attribute', async () => {
|
|
225
|
+
const description = '<span class="red">ここが集合場所です。13時までに集合してください。</span>';
|
|
226
|
+
assert.strictEqual(
|
|
227
|
+
'<span class="red">ここが集合場所です。13時までに集合してください。</span>',
|
|
228
|
+
await util.sanitizeDescription(description),
|
|
229
|
+
);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
205
232
|
});
|