@geolonia/embed 3.0.0-pre.1 → 3.1.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.
- package/.eslintrc.js +1 -1
- package/.github/workflows/build.yml +1 -1
- package/dist/embed +1 -1
- package/dist/embed-chunks/32f7b26f64d2caa77f2b.js +2 -0
- package/dist/embed-chunks/{9c922d7b054813866369.js.LICENSE.txt → 32f7b26f64d2caa77f2b.js.LICENSE.txt} +0 -0
- package/dist/embed-chunks/3d467b2d527e4e5de1b8.js +1 -0
- package/dist/embed.js +1 -1
- package/package.json +29 -27
- package/src/embed.d.ts +4 -0
- package/src/embed.js +0 -1
- package/src/lib/CustomAttributionControl.js +25 -3
- package/src/lib/parse-api-key.js +3 -4
- package/src/lib/simplestyle-vector.js +7 -9
- package/src/lib/simplestyle.js +8 -10
- package/src/lib/simplestyle.test.js +2 -0
- package/src/lib/util.js +8 -0
- package/src/lib/util.test.js +27 -0
- package/dist/embed-chunks/5ae1cbf5b6a878d13f8b.js +0 -1
- package/dist/embed-chunks/9c922d7b054813866369.js +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geolonia/embed",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Geolonia embed JS API",
|
|
5
5
|
"main": "dist/embed.js",
|
|
6
6
|
"types": "src/embed.d.ts",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"analyze": "ANALYZE=true webpack --mode production",
|
|
11
11
|
"format": "prettier-eslint \"./src/**/*.js\" --write",
|
|
12
12
|
"lint": "eslint \"src/**/*.js\"",
|
|
13
|
-
"test": "
|
|
13
|
+
"test": "yarn run lint && mocha ./src/**/*.test.js --recursive -r jsdom-global/register -r @babel/register"
|
|
14
14
|
},
|
|
15
15
|
"author": "Geolonia (https://geolonia.com)",
|
|
16
16
|
"repository": {
|
|
@@ -23,42 +23,44 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/geolonia/embed#readme",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@babel/cli": "^7.
|
|
27
|
-
"@babel/core": "^7.
|
|
28
|
-
"@babel/
|
|
29
|
-
"@babel/
|
|
30
|
-
"@babel/
|
|
26
|
+
"@babel/cli": "^7.19.3",
|
|
27
|
+
"@babel/core": "^7.20.5",
|
|
28
|
+
"@babel/eslint-parser": "^7.19.1",
|
|
29
|
+
"@babel/plugin-transform-classes": "^7.20.2",
|
|
30
|
+
"@babel/preset-env": "^7.20.2",
|
|
31
|
+
"@babel/register": "^7.18.9",
|
|
31
32
|
"@geolonia/eslint-config": "^0.0.1",
|
|
32
|
-
"babel-
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"jsdom": "^16.2.2",
|
|
33
|
+
"babel-loader": "^9.1.0",
|
|
34
|
+
"css-loader": "^6.7.2",
|
|
35
|
+
"eslint": "^8.29.0",
|
|
36
|
+
"jsdom": "^20.0.3",
|
|
37
37
|
"jsdom-global": "^3.0.2",
|
|
38
|
-
"mocha": "^
|
|
38
|
+
"mocha": "^10.2.0",
|
|
39
39
|
"node-fetch": "2",
|
|
40
|
-
"prettier-eslint": "^
|
|
41
|
-
"prettier-eslint-cli": "^
|
|
42
|
-
"style-loader": "^
|
|
40
|
+
"prettier-eslint": "^15.0.0",
|
|
41
|
+
"prettier-eslint-cli": "^7.1.0",
|
|
42
|
+
"style-loader": "^3.3.1",
|
|
43
43
|
"svg-inline-loader": "^0.8.2",
|
|
44
|
-
"webpack": "^5.
|
|
45
|
-
"webpack-bundle-analyzer": "^4.
|
|
46
|
-
"webpack-cli": "^
|
|
47
|
-
"webpack-dev-server": "^4.
|
|
44
|
+
"webpack": "^5.75.0",
|
|
45
|
+
"webpack-bundle-analyzer": "^4.7.0",
|
|
46
|
+
"webpack-cli": "^5.0.1",
|
|
47
|
+
"webpack-dev-server": "^4.11.1"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@geolonia/mbgl-geolonia-control": "^0.4.2",
|
|
51
51
|
"@geolonia/mbgl-gesture-handling": "^1.0.15",
|
|
52
|
-
"@mapbox/geojson-extent": "^0.
|
|
52
|
+
"@mapbox/geojson-extent": "^1.0.0",
|
|
53
53
|
"@mapbox/point-geometry": "^0.1.0",
|
|
54
54
|
"@turf/center": "^6.0.1",
|
|
55
|
-
"core-js": "^3.
|
|
56
|
-
"intersection-observer": "^0.5.1",
|
|
55
|
+
"core-js": "^3.26.1",
|
|
57
56
|
"maplibre-gl": "2.4.0",
|
|
58
|
-
"promise-polyfill": "^8.
|
|
59
|
-
"sanitize-html": "^2.
|
|
57
|
+
"promise-polyfill": "^8.2.3",
|
|
58
|
+
"sanitize-html": "^2.8.0",
|
|
60
59
|
"tinycolor2": "^1.4.1",
|
|
61
|
-
"url-parse": "^1.
|
|
60
|
+
"url-parse": "^1.5.10",
|
|
62
61
|
"whatwg-fetch": "^3.0.0"
|
|
63
|
-
}
|
|
62
|
+
},
|
|
63
|
+
"browserslist": [
|
|
64
|
+
"defaults or >= 1% in JP"
|
|
65
|
+
]
|
|
64
66
|
}
|
package/src/embed.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import * as maplibregl from 'maplibre-gl';
|
|
2
|
+
import SimpleStyle from './lib/simplestyle'
|
|
2
3
|
|
|
3
4
|
export class Map extends maplibregl.Map {}
|
|
4
5
|
export class Marker extends maplibregl.Marker {}
|
|
6
|
+
export class Popup extends maplibregl.Popup {}
|
|
5
7
|
|
|
6
8
|
export type EmbedAttributes = {
|
|
7
9
|
lat: string;
|
|
@@ -45,6 +47,8 @@ declare global {
|
|
|
45
47
|
baseApiUrl: string;
|
|
46
48
|
Map: typeof Map;
|
|
47
49
|
Marker: typeof Marker;
|
|
50
|
+
Popup: typeof Popup;
|
|
51
|
+
SimpleStyle: typeof SimpleStyle;
|
|
48
52
|
registerPlugin: (embedPlugin: EmbedPlugin) => void;
|
|
49
53
|
}
|
|
50
54
|
}
|
package/src/embed.js
CHANGED
|
@@ -5,6 +5,23 @@ import { DOM, bindAll } from './maplibre-util';
|
|
|
5
5
|
* https://github.com/maplibre/maplibre-gl-js/blob/main/src/ui/control/attribution_control.ts
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* When the map is too small to display the full attribution, it will be
|
|
10
|
+
* collapsed in to a "i" icon. It is open by default, and will hide itself
|
|
11
|
+
* when user interaction is detected.
|
|
12
|
+
* For more information on why this is open by default, see the following links:
|
|
13
|
+
*
|
|
14
|
+
* The OSM Foundation attribution guidelines.
|
|
15
|
+
* https://wiki.osmfoundation.org/wiki/Licence/Attribution_Guidelines#Interactive_maps
|
|
16
|
+
* > You may use a mechanism to fade/collapse the attribution under certain conditions:
|
|
17
|
+
* > * immediately with a dismiss interaction, for example clicking an ‘x’ in the corner of a dialog
|
|
18
|
+
* > * automatically on map interaction such as panning, clicking, or zooming
|
|
19
|
+
* > * automatically after five seconds. This also applies to splash screens or pop-ups.
|
|
20
|
+
*
|
|
21
|
+
* This is the issue where attribution is open by default in the MapLibre GL JS library:
|
|
22
|
+
* https://github.com/maplibre/maplibre-gl-js/issues/205
|
|
23
|
+
*/
|
|
24
|
+
|
|
8
25
|
class CustomAttributionControl {
|
|
9
26
|
|
|
10
27
|
constructor(options = {}) {
|
|
@@ -48,13 +65,16 @@ class CustomAttributionControl {
|
|
|
48
65
|
const style = document.createElement('style');
|
|
49
66
|
style.textContent = `
|
|
50
67
|
.maplibregl-ctrl {
|
|
68
|
+
font: 12px/20px Helvetica Neue,Arial,Helvetica,sans-serif;
|
|
51
69
|
clear: both;
|
|
52
70
|
pointer-events: auto;
|
|
53
71
|
transform: translate(0);
|
|
54
72
|
}
|
|
73
|
+
|
|
55
74
|
.maplibregl-ctrl-attrib-button:focus,.maplibregl-ctrl-group button:focus {
|
|
56
75
|
box-shadow: 0 0 2px 2px #0096ff
|
|
57
76
|
}
|
|
77
|
+
|
|
58
78
|
.maplibregl-ctrl.maplibregl-ctrl-attrib {
|
|
59
79
|
background-color: hsla(0,0%,100%,.5);
|
|
60
80
|
margin: 0;
|
|
@@ -66,15 +86,17 @@ class CustomAttributionControl {
|
|
|
66
86
|
background-color: #fff;
|
|
67
87
|
border-radius: 12px;
|
|
68
88
|
box-sizing: content-box;
|
|
69
|
-
margin: 10px;
|
|
70
89
|
min-height: 20px;
|
|
71
90
|
padding: 2px 24px 2px 0;
|
|
72
|
-
position: relative
|
|
91
|
+
position: relative;
|
|
92
|
+
margin: 10px 10px 10px auto;
|
|
93
|
+
width: 0;
|
|
73
94
|
}
|
|
74
95
|
|
|
75
96
|
.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
|
76
97
|
padding: 2px 28px 2px 8px;
|
|
77
|
-
visibility: visible
|
|
98
|
+
visibility: visible;
|
|
99
|
+
width: auto;
|
|
78
100
|
}
|
|
79
101
|
|
|
80
102
|
.maplibregl-ctrl-bottom-left>.maplibregl-ctrl-attrib.maplibregl-compact-show,.maplibregl-ctrl-top-left>.maplibregl-ctrl-attrib.maplibregl-compact-show {
|
package/src/lib/parse-api-key.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import urlParse from 'url-parse';
|
|
2
|
-
import querystring from 'querystring';
|
|
3
2
|
|
|
4
3
|
export default (document) => {
|
|
5
4
|
if (typeof window.geolonia === 'undefined') {
|
|
@@ -21,10 +20,10 @@ export default (document) => {
|
|
|
21
20
|
|
|
22
21
|
for (const script of scripts) {
|
|
23
22
|
const { pathname, query } = urlParse(script.src);
|
|
24
|
-
const q =
|
|
23
|
+
const q = new URLSearchParams(query.replace(/^\?/, ''));
|
|
25
24
|
|
|
26
|
-
if (q
|
|
27
|
-
params.key = q
|
|
25
|
+
if (q.get('geolonia-api-key')) {
|
|
26
|
+
params.key = q.get('geolonia-api-key') || 'YOUR-API-KEY';
|
|
28
27
|
|
|
29
28
|
const res = pathname.match( /^\/(v[0-9.]+)\/embed/ );
|
|
30
29
|
if (res && res[1]) {
|
|
@@ -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';
|
|
@@ -152,7 +153,7 @@ class SimpleStyleVector {
|
|
|
152
153
|
type: 'circle',
|
|
153
154
|
source: this.sourceName,
|
|
154
155
|
'source-layer': 'g-simplestyle-v1',
|
|
155
|
-
filter: ['==', '$type', 'Point'],
|
|
156
|
+
filter: ['all', ['==', '$type', 'Point'], ['!has', 'marker-symbol']],
|
|
156
157
|
paint: {
|
|
157
158
|
'circle-radius': [
|
|
158
159
|
'case',
|
|
@@ -180,11 +181,7 @@ class SimpleStyleVector {
|
|
|
180
181
|
'text-halo-width': 1,
|
|
181
182
|
},
|
|
182
183
|
layout: {
|
|
183
|
-
'icon-image': [
|
|
184
|
-
'case',
|
|
185
|
-
['==', 'large', ['get', 'marker-size']], ['image', ['concat', ['get', 'marker-symbol'], '-15']],
|
|
186
|
-
['image', ['concat', ['get', 'marker-symbol'], '-11']],
|
|
187
|
-
],
|
|
184
|
+
'icon-image': ['get', 'marker-symbol'],
|
|
188
185
|
'text-field': ['get', 'title'],
|
|
189
186
|
'text-font': ['Noto Sans Regular'],
|
|
190
187
|
'text-size': 12,
|
|
@@ -201,16 +198,17 @@ class SimpleStyleVector {
|
|
|
201
198
|
});
|
|
202
199
|
|
|
203
200
|
this.setPopup(map, 'vt-circle-simple-style-points');
|
|
201
|
+
this.setPopup(map, 'vt-geolonia-simple-style-points');
|
|
204
202
|
}
|
|
205
203
|
|
|
206
204
|
async setPopup(map, source) {
|
|
207
|
-
|
|
208
|
-
map.on('click', source, (e) => {
|
|
205
|
+
map.on('click', source, async (e) => {
|
|
209
206
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
210
207
|
const description = e.features[0].properties.description;
|
|
211
208
|
|
|
212
209
|
if (description) {
|
|
213
|
-
|
|
210
|
+
const sanitizedDescription = await sanitizeDescription(description);
|
|
211
|
+
new maplibregl.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
214
212
|
}
|
|
215
213
|
});
|
|
216
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';
|
|
@@ -196,7 +196,7 @@ class SimpleStyle {
|
|
|
196
196
|
id: `${this.options.id}-circle-points`,
|
|
197
197
|
type: 'circle',
|
|
198
198
|
source: `${this.options.id}-points`,
|
|
199
|
-
filter: ['
|
|
199
|
+
filter: ['all', ['!has', 'point_count'], ['!has', 'marker-symbol']],
|
|
200
200
|
paint: {
|
|
201
201
|
'circle-radius': [
|
|
202
202
|
'case',
|
|
@@ -223,11 +223,7 @@ class SimpleStyle {
|
|
|
223
223
|
'text-halo-width': 1,
|
|
224
224
|
},
|
|
225
225
|
layout: {
|
|
226
|
-
'icon-image': [
|
|
227
|
-
'case',
|
|
228
|
-
['==', 'large', ['get', 'marker-size']], ['image', ['concat', ['get', 'marker-symbol'], '-15']],
|
|
229
|
-
['image', ['concat', ['get', 'marker-symbol'], '-11']],
|
|
230
|
-
],
|
|
226
|
+
'icon-image': ['get', 'marker-symbol'],
|
|
231
227
|
'text-field': ['get', 'title'],
|
|
232
228
|
'text-font': ['Noto Sans Regular'],
|
|
233
229
|
'text-size': 12,
|
|
@@ -240,20 +236,22 @@ class SimpleStyle {
|
|
|
240
236
|
['literal', [0, 0.8]],
|
|
241
237
|
],
|
|
242
238
|
'text-allow-overlap': false,
|
|
239
|
+
'icon-allow-overlap': true,
|
|
243
240
|
},
|
|
244
241
|
});
|
|
245
242
|
|
|
246
243
|
this.setPopup(this.map, `${this.options.id}-circle-points`);
|
|
244
|
+
this.setPopup(this.map, `${this.options.id}-symbol-points`);
|
|
247
245
|
}
|
|
248
246
|
|
|
249
247
|
async setPopup(map, source) {
|
|
250
|
-
|
|
251
|
-
map.on('click', source, (e) => {
|
|
248
|
+
map.on('click', source, async (e) => {
|
|
252
249
|
const center = turfCenter(e.features[0]).geometry.coordinates;
|
|
253
250
|
const description = e.features[0].properties.description;
|
|
254
251
|
|
|
255
252
|
if (description) {
|
|
256
|
-
|
|
253
|
+
const sanitizedDescription = await sanitizeDescription(description);
|
|
254
|
+
new maplibregl.Popup().setLngLat(center).setHTML(sanitizedDescription).addTo(map);
|
|
257
255
|
}
|
|
258
256
|
});
|
|
259
257
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable no-loss-of-precision */
|
|
1
2
|
'use strict';
|
|
2
3
|
|
|
3
4
|
import assert from 'assert';
|
|
@@ -82,6 +83,7 @@ describe('Tests for simpleStyle()', () => {
|
|
|
82
83
|
assert.deepEqual([ 'geolonia-simple-style', 'geolonia-simple-style-points' ], Object.keys(map.sources));
|
|
83
84
|
assert.deepEqual(8, map.layers.length);
|
|
84
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']);
|
|
85
87
|
});
|
|
86
88
|
|
|
87
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
|
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(self.webpackChunk_geolonia_embed=self.webpackChunk_geolonia_embed||[]).push([[841],{5347:()=>{},1777:()=>{},4017:()=>{},9905:()=>{},4604:()=>{}}]);
|