@unvt/charites 0.5.1 → 0.5.4

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.
@@ -16,8 +16,8 @@ jobs:
16
16
  build:
17
17
  strategy:
18
18
  matrix:
19
- node-version: [14.x, 16.x, 18.x]
20
- os: [ubuntu-latest, windows-latest]
19
+ node-version: [18.x, 20.x, 21.x]
20
+ os: [ubuntu-latest]
21
21
  runs-on: ${{ matrix.os }}
22
22
  steps:
23
23
  - uses: actions/checkout@v3
@@ -67,7 +67,7 @@ jobs:
67
67
  - uses: actions/setup-node@v3
68
68
  with:
69
69
  tag_name: 'v%s'
70
- node-version: '14.x'
70
+ node-version: '18.x'
71
71
  registry-url: 'https://registry.npmjs.org'
72
72
  scope: '@unvt'
73
73
  - run: npm install
package/dist/cli/serve.js CHANGED
@@ -16,6 +16,7 @@ program
16
16
  .option('--provider [provider]', 'your map service. e.g. `mapbox`, `geolonia`')
17
17
  .option('--mapbox-access-token [mapboxAccessToken]', 'Your Mapbox Access Token (required if using the `mapbox` provider)')
18
18
  .option('-i, --sprite-input [<icon input directory>]', 'directory path of icon source to build icons. The default <icon source> is `icons/`')
19
+ .option('--sdf', 'Allows to use SDF sprite in charites')
19
20
  .option('--port [port]', 'Specify custom port')
20
21
  .option('--no-open', "Don't open the preview in the default browser")
21
22
  .action(async (source, serveOptions) => {
@@ -25,6 +26,7 @@ program
25
26
  options.port = serveOptions.port;
26
27
  options.spriteInput = serveOptions.spriteInput;
27
28
  options.open = serveOptions.open;
29
+ options.sdf = serveOptions.sdf;
28
30
  if (!fs_1.default.existsSync(defaultValues_1.defaultSettings.configFile)) {
29
31
  fs_1.default.writeFileSync(defaultValues_1.defaultSettings.configFile, `provider: ${options.provider || 'default'}`);
30
32
  }
@@ -45,7 +45,7 @@ async function serve(source, options) {
45
45
  typeof spriteOut === 'undefined') {
46
46
  return;
47
47
  }
48
- await (0, build_sprite_1.buildSprite)(options.spriteInput, spriteOut, 'sprite');
48
+ await (0, build_sprite_1.buildSprite)(options.spriteInput, spriteOut, 'sprite', options.sdf);
49
49
  };
50
50
  await spriteRefresher();
51
51
  }
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildSprite = void 0;
7
7
  const sprite_one_1 = require("@unvt/sprite-one");
8
8
  const path_1 = __importDefault(require("path"));
9
- async function buildSprite(svgPath, publicPath, iconSlug) {
9
+ async function buildSprite(svgPath, publicPath, iconSlug, sdf = false) {
10
10
  const pxRatios = [1, 2];
11
11
  const outPath = path_1.default.join(publicPath, iconSlug);
12
- await (0, sprite_one_1.generateSprite)(outPath, [svgPath], pxRatios);
12
+ await (0, sprite_one_1.generateSprite)(outPath, [svgPath], pxRatios, sdf);
13
13
  return;
14
14
  }
15
15
  exports.buildSprite = buildSprite;
@@ -2,11 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSpriteSlug = void 0;
4
4
  function getSpriteSlug(style) {
5
- var _a;
6
- if (!style.hasOwnProperty('sprite')) {
5
+ if (!style.hasOwnProperty('sprite') || !style.sprite) {
7
6
  return false;
8
7
  }
9
- const matchedUrl = (_a = style.sprite) === null || _a === void 0 ? void 0 : _a.match(/^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?(?:([^?#]*\/)([^\/?#]*))?(\?[^#]*)?(?:#.*)?$/);
8
+ const firstUrl = Array.isArray(style.sprite)
9
+ ? style.sprite[0].url
10
+ : style.sprite;
11
+ const matchedUrl = firstUrl.match(/^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?(?:([^?#]*\/)([^\/?#]*))?(\?[^#]*)?(?:#.*)?$/);
10
12
  if (!matchedUrl || !matchedUrl[2]) {
11
13
  return false;
12
14
  }
@@ -1,7 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.validateStyle = void 0;
4
- const maplibreStyleSpec = require('@maplibre/maplibre-gl-style-spec');
7
+ const maplibre_gl_style_spec_1 = __importDefault(require("@maplibre/maplibre-gl-style-spec"));
5
8
  const mapboxStyleSpec = require('@mapbox/mapbox-gl-style-spec');
6
9
  function validateStyle(style, provider = 'default') {
7
10
  let result = [];
@@ -9,12 +12,21 @@ function validateStyle(style, provider = 'default') {
9
12
  result = mapboxStyleSpec.validate(style);
10
13
  }
11
14
  else {
12
- result = maplibreStyleSpec.validate(style);
15
+ result = maplibre_gl_style_spec_1.default.validateStyleMin(style);
13
16
  }
14
17
  const errors = [];
15
18
  for (let i = 0; i < result.length; i++) {
16
- if (result[i].message) {
17
- errors.push(result[i].message);
19
+ const msg = result[i].message;
20
+ if (msg) {
21
+ const layerMatch = msg.match(/^layers\[([0-9]+)\]/);
22
+ if (layerMatch) {
23
+ const layerIndex = Number(layerMatch[1]);
24
+ const layerId = style.layers[layerIndex].id;
25
+ errors.push(`Layer "${layerId}": ${msg}`);
26
+ }
27
+ else {
28
+ errors.push(msg);
29
+ }
18
30
  }
19
31
  }
20
32
  if (errors.length) {
@@ -1,6 +1,6 @@
1
1
  Install
2
2
  =======
3
- Make sure that npm and nodejs are installed. Nodeis version 14 or later version are recommended. Then, install charites by running the following command:
3
+ Make sure that npm and nodejs are installed. Nodeis version 18 or later version are recommended. Then, install charites by running the following command:
4
4
 
5
5
  .. code-block:: bash
6
6
 
@@ -15,13 +15,13 @@ Steps
15
15
 
16
16
  Step 1. Installation of nodejs (if it is not installed yet)
17
17
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18
- Check if nodejs is installed. If not, visit `nodejs <https://nodejs.org/en/>`_ to install them. Version 14 or later version is recommended. Installation will fail with the older version of nodejs than 12.20.0.
18
+ Check if nodejs is installed. If not, visit `nodejs <https://nodejs.org/en/>`_ to install them. Version 18 or later version is recommended. Installation will fail with the older version of nodejs than 12.20.0.
19
19
 
20
20
  Step 2. Open Windows PowerShell
21
21
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
22
22
  Open Windows PowerShell and confirm if nodejs and npm works.
23
23
 
24
- .. code-block::
24
+ .. code-block::
25
25
 
26
26
  npm --version
27
27
  node --version
@@ -30,7 +30,7 @@ Step 3. Install @unvt/charites as a npm package
30
30
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
31
31
  Just rung the following command to install the charites.
32
32
 
33
- .. code-block::
33
+ .. code-block::
34
34
 
35
35
  npm install -g @unvt/charites
36
36
 
@@ -39,7 +39,7 @@ Step 4. Confirm if charites is properly installed
39
39
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
40
  If you can see the charites version and command lits with the following command. It seems that your installation has done successfully.
41
41
 
42
- .. code-block::
42
+ .. code-block::
43
43
 
44
44
  charites --version
45
45
  charites --help
@@ -3,4 +3,4 @@ Recommended environment
3
3
 
4
4
  Chrities may work well on OSX, Ubuntu, Windows 10 and Raspberry Pi.
5
5
 
6
- Nodejs and npm are needed to install charites. Docker can also be a good environment in Windows while WSL might work well. For charites version 0.3.0 released in December 2022, nodejs ver 14. or later version is recommended.
6
+ Nodejs and npm are needed to install charites. Docker can also be a good environment in Windows while WSL might work well. For charites version 0.3.0 released in December 2022, nodejs ver 18. or later version is recommended.
@@ -98,6 +98,7 @@ Realtime editor on browser
98
98
  --mapbox-access-token [mapboxAccessToken] Access Token for the Mapbox
99
99
  -i, --sprite-input [<icon input directory>] directory path of icon source to build icons. The default <icon
100
100
  source> is `icons/`
101
+ --sdf Allows to use SDF sprite in charites
101
102
  --port [port] Specify custom port
102
103
  -h, --help display help for command
103
104
 
@@ -112,4 +113,6 @@ Charites has three options for `serve` command.
112
113
 
113
114
  - ``--sprite-input`` - If you are building icon spritesheets with Charites, you can specify the directory of SVG files to compile here. See the ``build`` command for more information.
114
115
 
116
+ - ``--sdf`` - if this option is used together with ``--sprite-input``, the viewer will generate SDF sprite. If the option is not specified, non SDF sprite will be generated.
117
+
115
118
  - ``--port`` - Set http server's port number. When not specified, the default is 8080.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unvt/charites",
3
- "version": "0.5.1",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "charites": "dist/cli.js"
@@ -18,9 +18,9 @@
18
18
  "license": "MIT",
19
19
  "dependencies": {
20
20
  "@mapbox/mapbox-gl-style-spec": "^13.27.0",
21
- "@maplibre/maplibre-gl-style-spec": "^17.0.2",
21
+ "@maplibre/maplibre-gl-style-spec": "^19.3.0",
22
22
  "@types/jsonminify": "^0.4.1",
23
- "@unvt/sprite-one": "^0.0.9",
23
+ "@unvt/sprite-one": "^0.1.1",
24
24
  "axios": "^1.2.2",
25
25
  "commander": "^9.4.1",
26
26
  "glob": "^8.0.3",
@@ -14,7 +14,7 @@
14
14
  map.addControl(new maplibregl.NavigationControl(), 'top-right')
15
15
 
16
16
  map.addControl(
17
- new MaplibreLegendControl(
17
+ new MaplibreLegendControl.MaplibreLegendControl(
18
18
  {},
19
19
  {
20
20
  showDefault: true,
@@ -3,10 +3,10 @@
3
3
  <head>
4
4
  <link rel="stylesheet" href="/app.css" />
5
5
  <link href='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.css' rel='stylesheet' />
6
- <link href='https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.css' rel='stylesheet' />
6
+ <link href='https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.css' rel='stylesheet' />
7
7
  <title>Charites Live Preview</title>
8
8
  <script src='https://unpkg.com/maplibre-gl@2.4.0/dist/maplibre-gl.js'></script>
9
- <script src="https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.js"></script>
9
+ <script src="https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.umd.js"></script>
10
10
  <script src="https://unpkg.com/pmtiles@2.7.0/dist/index.js"></script>
11
11
  </head>
12
12
  <body>
@@ -1,21 +1,23 @@
1
1
  ;(async () => {
2
2
  window._charites = {
3
3
  initializeWebSocket: function (map) {
4
- const socket = new WebSocket(`ws://${window.location.host}`)
4
+ const isHttps = window.location.protocol === 'https:'
5
+ const wsProtocol = isHttps ? 'wss' : 'ws'
6
+ const socket = new WebSocket(`${wsProtocol}://${window.location.host}`)
5
7
 
6
8
  socket.addEventListener('message', (message) => {
7
9
  const data = JSON.parse(message.data)
8
10
  if (data.event === 'styleUpdate') {
9
- map.setStyle(`http://${window.location.host}/style.json`)
11
+ map.setStyle(`//${window.location.host}/style.json`)
10
12
  } else if (data.event === 'spriteUpdate') {
11
- map.setStyle(`http://${window.location.host}/style.json`, {
13
+ map.setStyle(`//${window.location.host}/style.json`, {
12
14
  diff: false,
13
15
  })
14
16
  }
15
17
  })
16
18
  },
17
19
  parseMapStyle: async function () {
18
- const mapStyleUrl = `http://${window.location.host}/style.json`
20
+ const mapStyleUrl = `//${window.location.host}/style.json`
19
21
  const mapStyleRes = await fetch(mapStyleUrl)
20
22
  const mapStyleJson = await mapStyleRes.json()
21
23
 
@@ -40,8 +42,12 @@
40
42
  if (center === undefined) {
41
43
  const bounds = mapTileJson.bounds
42
44
  center = mapTileJson.center
43
- ? mapTileJson.center
44
- : [(bounds[0] + bounds[2]) / 2, (bounds[1] + bounds[3]) / 2]
45
+ if (!center && bounds) {
46
+ center = [
47
+ (bounds[0] + bounds[2]) / 2,
48
+ (bounds[1] + bounds[3]) / 2,
49
+ ]
50
+ }
45
51
  }
46
52
  if (zoom === undefined) {
47
53
  zoom = (mapTileJson.minzoom + mapTileJson.maxzoom) / 2
@@ -12,7 +12,7 @@
12
12
  window._charites.initializeWebSocket(map)
13
13
 
14
14
  map.addControl(
15
- new MaplibreLegendControl(
15
+ new MaplibreLegendControl.MaplibreLegendControl(
16
16
  {},
17
17
  {
18
18
  showDefault: true,
@@ -3,7 +3,7 @@
3
3
  <head>
4
4
  <link rel="stylesheet" href="/app.css" />
5
5
  <title>Charites Live Preview</title>
6
- <link href='https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.css' rel='stylesheet' />
6
+ <link href='https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.css' rel='stylesheet' />
7
7
  </head>
8
8
  <body>
9
9
  <div class="overlay">
@@ -15,7 +15,7 @@
15
15
  </div>
16
16
  <div id="map"></div>
17
17
  <script type="text/javascript" src="https://cdn.geolonia.com/v1/embed?geolonia-api-key=YOUR-API-KEY"></script>
18
- <script src="https://watergis.github.io/maplibre-gl-legend/maplibre-gl-legend.js"></script>
18
+ <script src="https://unpkg.com/@watergis/maplibre-gl-legend@2.0.0/dist/maplibre-gl-legend.umd.js"></script>
19
19
  <script type="text/javascript" src="/shared.js"></script>
20
20
  <script type="text/javascript" src="/app.js"></script>
21
21
  </body>
package/src/cli/serve.ts CHANGED
@@ -21,6 +21,7 @@ program
21
21
  '-i, --sprite-input [<icon input directory>]',
22
22
  'directory path of icon source to build icons. The default <icon source> is `icons/`',
23
23
  )
24
+ .option('--sdf', 'Allows to use SDF sprite in charites')
24
25
  .option('--port [port]', 'Specify custom port')
25
26
  .option('--no-open', "Don't open the preview in the default browser")
26
27
  .action(async (source: string, serveOptions: serveOptions) => {
@@ -30,6 +31,7 @@ program
30
31
  options.port = serveOptions.port
31
32
  options.spriteInput = serveOptions.spriteInput
32
33
  options.open = serveOptions.open
34
+ options.sdf = serveOptions.sdf
33
35
  if (!fs.existsSync(defaultSettings.configFile)) {
34
36
  fs.writeFileSync(
35
37
  defaultSettings.configFile,
@@ -17,6 +17,7 @@ export interface serveOptions {
17
17
  port?: string
18
18
  spriteInput?: string
19
19
  open?: boolean
20
+ sdf?: boolean
20
21
  }
21
22
 
22
23
  export async function serve(source: string, options: serveOptions) {
@@ -57,7 +58,7 @@ export async function serve(source: string, options: serveOptions) {
57
58
  ) {
58
59
  return
59
60
  }
60
- await buildSprite(options.spriteInput, spriteOut, 'sprite')
61
+ await buildSprite(options.spriteInput, spriteOut, 'sprite', options.sdf)
61
62
  }
62
63
  await spriteRefresher()
63
64
  }
@@ -5,9 +5,10 @@ export async function buildSprite(
5
5
  svgPath: string,
6
6
  publicPath: string,
7
7
  iconSlug: string,
8
+ sdf = false,
8
9
  ): Promise<void> {
9
10
  const pxRatios = [1, 2]
10
11
  const outPath = path.join(publicPath, iconSlug)
11
- await generateSprite(outPath, [svgPath], pxRatios)
12
+ await generateSprite(outPath, [svgPath], pxRatios, sdf)
12
13
  return
13
14
  }
@@ -1,11 +1,15 @@
1
1
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
2
2
 
3
3
  export function getSpriteSlug(style: StyleSpecification): string | false {
4
- if (!style.hasOwnProperty('sprite')) {
4
+ if (!style.hasOwnProperty('sprite') || !style.sprite) {
5
5
  return false
6
6
  }
7
7
 
8
- const matchedUrl = style.sprite?.match(
8
+ const firstUrl = Array.isArray(style.sprite)
9
+ ? style.sprite[0].url
10
+ : style.sprite
11
+
12
+ const matchedUrl = firstUrl.match(
9
13
  /^(?:[^:\/?#]+:)?(?:\/\/[^\/?#]*)?(?:([^?#]*\/)([^\/?#]*))?(\?[^#]*)?(?:#.*)?$/,
10
14
  )
11
15
 
@@ -1,4 +1,4 @@
1
- const maplibreStyleSpec = require('@maplibre/maplibre-gl-style-spec')
1
+ import maplibreStyleSpec from '@maplibre/maplibre-gl-style-spec'
2
2
  const mapboxStyleSpec = require('@mapbox/mapbox-gl-style-spec')
3
3
  import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec'
4
4
 
@@ -10,13 +10,21 @@ export function validateStyle(
10
10
  if ('mapbox' === provider) {
11
11
  result = mapboxStyleSpec.validate(style)
12
12
  } else {
13
- result = maplibreStyleSpec.validate(style)
13
+ result = maplibreStyleSpec.validateStyleMin(style)
14
14
  }
15
15
 
16
16
  const errors = []
17
17
  for (let i = 0; i < result.length; i++) {
18
- if (result[i].message) {
19
- errors.push(result[i].message)
18
+ const msg = result[i].message
19
+ if (msg) {
20
+ const layerMatch = msg.match(/^layers\[([0-9]+)\]/)
21
+ if (layerMatch) {
22
+ const layerIndex = Number(layerMatch[1])
23
+ const layerId = style.layers[layerIndex].id
24
+ errors.push(`Layer "${layerId}": ${msg}`)
25
+ } else {
26
+ errors.push(msg)
27
+ }
20
28
  }
21
29
  }
22
30