styled-map-package 4.0.1 → 5.0.0-pre.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.
Files changed (85) hide show
  1. package/bin/smp-download.js +10 -6
  2. package/bin/smp-mbtiles.js +5 -7
  3. package/bin/smp-view.js +34 -26
  4. package/lib/reporters.js +92 -0
  5. package/package.json +8 -187
  6. package/LICENSE.md +0 -7
  7. package/README.md +0 -28
  8. package/dist/download.cjs +0 -101
  9. package/dist/download.d.cts +0 -65
  10. package/dist/download.d.ts +0 -65
  11. package/dist/download.js +0 -77
  12. package/dist/from-mbtiles.cjs +0 -91
  13. package/dist/from-mbtiles.d.cts +0 -17
  14. package/dist/from-mbtiles.d.ts +0 -17
  15. package/dist/from-mbtiles.js +0 -57
  16. package/dist/index.cjs +0 -49
  17. package/dist/index.d.cts +0 -27
  18. package/dist/index.d.ts +0 -27
  19. package/dist/index.js +0 -18
  20. package/dist/reader-watch.cjs +0 -135
  21. package/dist/reader-watch.d.cts +0 -24
  22. package/dist/reader-watch.d.ts +0 -24
  23. package/dist/reader-watch.js +0 -101
  24. package/dist/reader.cjs +0 -167
  25. package/dist/reader.d.cts +0 -62
  26. package/dist/reader.d.ts +0 -62
  27. package/dist/reader.js +0 -138
  28. package/dist/reporters.cjs +0 -122
  29. package/dist/reporters.d.cts +0 -10
  30. package/dist/reporters.d.ts +0 -10
  31. package/dist/reporters.js +0 -88
  32. package/dist/server.cjs +0 -78
  33. package/dist/server.d.cts +0 -48
  34. package/dist/server.d.ts +0 -48
  35. package/dist/server.js +0 -54
  36. package/dist/style-downloader.cjs +0 -312
  37. package/dist/style-downloader.d.cts +0 -120
  38. package/dist/style-downloader.d.ts +0 -120
  39. package/dist/style-downloader.js +0 -288
  40. package/dist/tile-downloader.cjs +0 -158
  41. package/dist/tile-downloader.d.cts +0 -84
  42. package/dist/tile-downloader.d.ts +0 -84
  43. package/dist/tile-downloader.js +0 -126
  44. package/dist/types-B4Xn1F9K.d.cts +0 -189
  45. package/dist/types-B4Xn1F9K.d.ts +0 -189
  46. package/dist/utils/errors.cjs +0 -41
  47. package/dist/utils/errors.d.cts +0 -18
  48. package/dist/utils/errors.d.ts +0 -18
  49. package/dist/utils/errors.js +0 -16
  50. package/dist/utils/fetch.cjs +0 -96
  51. package/dist/utils/fetch.d.cts +0 -51
  52. package/dist/utils/fetch.d.ts +0 -51
  53. package/dist/utils/fetch.js +0 -62
  54. package/dist/utils/file-formats.cjs +0 -98
  55. package/dist/utils/file-formats.d.cts +0 -35
  56. package/dist/utils/file-formats.d.ts +0 -35
  57. package/dist/utils/file-formats.js +0 -62
  58. package/dist/utils/geo.cjs +0 -84
  59. package/dist/utils/geo.d.cts +0 -46
  60. package/dist/utils/geo.d.ts +0 -46
  61. package/dist/utils/geo.js +0 -56
  62. package/dist/utils/mapbox.cjs +0 -121
  63. package/dist/utils/mapbox.d.cts +0 -43
  64. package/dist/utils/mapbox.d.ts +0 -43
  65. package/dist/utils/mapbox.js +0 -91
  66. package/dist/utils/misc.cjs +0 -39
  67. package/dist/utils/misc.d.cts +0 -22
  68. package/dist/utils/misc.d.ts +0 -22
  69. package/dist/utils/misc.js +0 -13
  70. package/dist/utils/streams.cjs +0 -130
  71. package/dist/utils/streams.d.cts +0 -73
  72. package/dist/utils/streams.d.ts +0 -73
  73. package/dist/utils/streams.js +0 -103
  74. package/dist/utils/style.cjs +0 -126
  75. package/dist/utils/style.d.cts +0 -69
  76. package/dist/utils/style.d.ts +0 -69
  77. package/dist/utils/style.js +0 -98
  78. package/dist/utils/templates.cjs +0 -114
  79. package/dist/utils/templates.d.cts +0 -78
  80. package/dist/utils/templates.d.ts +0 -78
  81. package/dist/utils/templates.js +0 -79
  82. package/dist/writer.cjs +0 -401
  83. package/dist/writer.d.cts +0 -7
  84. package/dist/writer.d.ts +0 -7
  85. package/dist/writer.js +0 -374
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env node
2
- import { Command, InvalidArgumentError } from '@commander-js/extra-typings'
3
2
  import { input, number } from '@inquirer/prompts'
3
+ import { Command, InvalidArgumentError } from 'commander'
4
4
  import fs from 'fs'
5
- import { pipeline } from 'stream/promises'
5
+ import { download } from 'styled-map-package-api/download'
6
+ import {
7
+ isMapboxURL,
8
+ API_URL as MAPBOX_API_URL,
9
+ } from 'styled-map-package-api/utils/mapbox'
6
10
 
7
- import { download } from '../dist/download.js'
8
- import { ttyReporter } from '../dist/reporters.js'
9
- import { isMapboxURL, API_URL as MAPBOX_API_URL } from '../dist/utils/mapbox.js'
11
+ import { Writable } from 'node:stream'
12
+
13
+ import { ttyReporter } from '../lib/reporters.js'
10
14
 
11
15
  const program = new Command()
12
16
 
@@ -129,7 +133,7 @@ program
129
133
  accessToken: token,
130
134
  })
131
135
  const outputStream = output ? fs.createWriteStream(output) : process.stdout
132
- await pipeline(readStream, outputStream)
136
+ await readStream.pipeTo(Writable.toWeb(outputStream))
133
137
  })
134
138
 
135
139
  program.parseAsync(process.argv)
@@ -1,8 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { Command } from 'commander'
3
- import { pipeline } from 'stream/promises'
3
+ import { fromMBTiles } from 'styled-map-package-api/from-mbtiles'
4
4
 
5
- import { fromMBTiles } from '../dist/from-mbtiles.js'
5
+ import fs from 'node:fs'
6
+ import { Writable } from 'node:stream'
6
7
 
7
8
  const program = new Command()
8
9
 
@@ -11,11 +12,8 @@ program
11
12
  .option('-o, --output <file>', 'output smp file')
12
13
  .argument('<mbtiles>', 'MBTiles file to convert')
13
14
  .action(async (mbtilesPath, { output }) => {
14
- if (output) {
15
- await fromMBTiles(mbtilesPath, output)
16
- } else {
17
- await pipeline(fromMBTiles(mbtilesPath), process.stdout)
18
- }
15
+ const dest = output ? fs.createWriteStream(output) : process.stdout
16
+ await fromMBTiles(mbtilesPath).pipeTo(Writable.toWeb(dest))
19
17
  })
20
18
 
21
19
  program.parseAsync(process.argv)
package/bin/smp-view.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
- import fastifyStatic from '@fastify/static'
3
2
  import { createServerAdapter } from '@whatwg-node/server'
4
3
  import { Command } from 'commander'
5
- import fastify from 'fastify'
4
+ import fsPromises from 'fs/promises'
5
+ import http from 'http'
6
+ import { AutoRouter } from 'itty-router'
6
7
  import openApp from 'open'
8
+ import { Reader } from 'styled-map-package-api/reader'
9
+ import { createServer } from 'styled-map-package-api/server'
7
10
 
8
11
  import path from 'node:path'
9
12
 
10
- import { Reader } from '../dist/reader.js'
11
- import { createServer } from '../dist/server.js'
12
-
13
13
  const program = new Command()
14
14
 
15
15
  program
@@ -28,37 +28,45 @@ program
28
28
  program.parseAsync(process.argv)
29
29
 
30
30
  /**
31
- * Serve a styled map package on the given port (defaults to 3000). Use the
32
- * fastify plugin in `./server.js` for more flexibility.
31
+ * Serve a styled map package on the given port (defaults to 3000).
33
32
  *
34
33
  * @param {object} opts
35
34
  * @param {number} [opts.port]
36
35
  * @param {string} opts.filepath
37
36
  * @returns
38
37
  */
39
- function serve({ port = 3000, filepath }) {
38
+ async function serve({ port = 3000, filepath }) {
40
39
  const reader = new Reader(path.relative(process.cwd(), filepath))
41
40
  const smpServer = createServer({ base: '/map' })
42
- const serverAdapter = createServerAdapter((request) => {
43
- return smpServer.fetch(request, reader)
44
- })
45
41
 
46
- const server = fastify()
47
-
48
- server.register(fastifyStatic, {
49
- root: new URL('../map-viewer', import.meta.url),
50
- serve: false,
42
+ const router = AutoRouter()
43
+ router.get('/', async () => {
44
+ const index = await fsPromises.readFile(
45
+ new URL('../map-viewer/index.html', import.meta.url),
46
+ )
47
+ return new Response(new Uint8Array(index), {
48
+ headers: {
49
+ 'Content-Type': 'text/html',
50
+ 'Content-Length': String(index.byteLength),
51
+ 'Cache-Control': 'public, max-age=0',
52
+ },
53
+ })
51
54
  })
52
- server.get('/', async (request, reply) => {
53
- return reply.sendFile('index.html')
55
+ router.all('/map/*', (request) => {
56
+ return smpServer.fetch(request, reader)
54
57
  })
55
-
56
- server.route({
57
- url: '/map/*',
58
- method: ['GET', 'HEAD', 'OPTIONS'],
59
- handler: (req, reply) => {
60
- return serverAdapter.handleNodeRequestAndResponse(req, reply)
61
- },
58
+ const server = http.createServer(createServerAdapter(router.fetch))
59
+ return new Promise((resolve, reject) => {
60
+ server.listen(port, '127.0.0.1', () => {
61
+ const address = server.address()
62
+ if (typeof address === 'string') {
63
+ resolve(`http://${address}`)
64
+ } else if (address === null) {
65
+ reject(new Error('Failed to get server address'))
66
+ } else {
67
+ resolve(`http://${address.address}:${address.port}`)
68
+ }
69
+ })
70
+ server.on('error', reject)
62
71
  })
63
- return server.listen({ port })
64
72
  }
@@ -0,0 +1,92 @@
1
+ import chalk, { chalkStderr } from 'chalk'
2
+ import logSymbols from 'log-symbols'
3
+ import ora from 'ora'
4
+ import prettyBytes from 'pretty-bytes'
5
+ import prettyMilliseconds from 'pretty-ms'
6
+ import { Writable } from 'readable-stream'
7
+
8
+ chalk.level = chalkStderr.level
9
+
10
+ const TASKS = /** @type {const} */ ([
11
+ 'style',
12
+ 'sprites',
13
+ 'tiles',
14
+ 'glyphs',
15
+ 'output',
16
+ ])
17
+
18
+ const TASK_LABEL = /** @type {const} */ ({
19
+ style: 'Downloading Map Style',
20
+ sprites: 'Downloading Sprites',
21
+ tiles: 'Downloading Tiles',
22
+ glyphs: 'Downloading Glyphs',
23
+ output: 'Writing Styled Map Package',
24
+ })
25
+
26
+ const TASK_SUFFIX =
27
+ /** @type {{ [K in (typeof TASKS)[number]]: (progress: import('styled-map-package-api/download').DownloadProgress[K]) => string }} */ ({
28
+ style: () => '',
29
+ sprites: ({ downloaded }) => `${downloaded}`,
30
+ tiles: ({ total, skipped, totalBytes, downloaded }) => {
31
+ const formattedTotal = total.toLocaleString()
32
+ const formattedCompleted = (downloaded + skipped)
33
+ .toLocaleString()
34
+ .padStart(formattedTotal.length)
35
+ return `${formattedCompleted}/${formattedTotal} (${prettyBytes(totalBytes)})`
36
+ },
37
+ glyphs: ({ total, downloaded, totalBytes }) =>
38
+ `${downloaded}/${total} (${prettyBytes(totalBytes)})`,
39
+ output: ({ totalBytes }) => `${prettyBytes(totalBytes)}`,
40
+ })
41
+
42
+ /**
43
+ * A writable stream to reporting download progress to a TTY terminal. Write
44
+ * progress messages to this stream for a pretty-printed progress task-list in
45
+ * the terminal.
46
+ */
47
+ export function ttyReporter() {
48
+ /** @type {import('styled-map-package-api/download').DownloadProgress | undefined} */
49
+ let stats
50
+ let current = 0
51
+ /** @type {import('ora').Ora} */
52
+ let spinner
53
+ return new Writable({
54
+ objectMode: true,
55
+ // @ts-ignore - missing type def
56
+ construct(cb) {
57
+ process.stderr.write('\n')
58
+ spinner = ora(TASK_LABEL[TASKS[current]]).start()
59
+ cb()
60
+ },
61
+ /** @param {ArrayLike<{ chunk: import('styled-map-package-api/download').DownloadProgress, encoding: string }>} chunks */
62
+ writev(chunks, cb) {
63
+ stats = chunks[chunks.length - 1].chunk
64
+ while (current < TASKS.length && stats[TASKS[current]].done) {
65
+ spinner.suffixText = chalk.dim(
66
+ TASK_SUFFIX[TASKS[current]](
67
+ // @ts-ignore - too complicated for TS
68
+ stats[TASKS[current]],
69
+ ),
70
+ )
71
+ spinner.succeed()
72
+ if (++current < TASKS.length) {
73
+ spinner = ora(TASK_LABEL[TASKS[current]]).start()
74
+ }
75
+ }
76
+ if (current < TASKS.length) {
77
+ spinner.suffixText = chalk.dim(
78
+ TASK_SUFFIX[TASKS[current]](
79
+ // @ts-ignore - too complicated for TS
80
+ stats[TASKS[current]],
81
+ ),
82
+ )
83
+ } else {
84
+ process.stderr.write(
85
+ `${chalk.green(logSymbols.success)} Completed in ${prettyMilliseconds(stats.elapsedMs)}\n`,
86
+ )
87
+ }
88
+
89
+ cb()
90
+ },
91
+ })
92
+ }
package/package.json CHANGED
@@ -1,218 +1,39 @@
1
1
  {
2
2
  "name": "styled-map-package",
3
- "version": "4.0.1",
4
- "description": "A Styled Map Package (`.smp`) file is a Zip archive containing all the resources needed to serve a Maplibre vector styled map offline. This includes the style JSON, vector and raster tiles, glyphs (fonts), the sprite image, and the sprite metadata.",
3
+ "version": "5.0.0-pre.0",
4
+ "description": "CLI for creating, viewing, and converting Styled Map Package (.smp) files",
5
5
  "type": "module",
6
- "main": "./dist/index.cjs",
7
- "module": "./dist/index.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/index.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/index.cjs"
18
- }
19
- },
20
- "./reader": {
21
- "import": {
22
- "types": "./dist/reader.d.ts",
23
- "default": "./dist/reader.js"
24
- },
25
- "require": {
26
- "types": "./dist/reader.d.cts",
27
- "default": "./dist/reader.cjs"
28
- }
29
- },
30
- "./reader-watch": {
31
- "import": {
32
- "types": "./dist/reader-watch.d.ts",
33
- "default": "./dist/reader-watch.js"
34
- },
35
- "require": {
36
- "types": "./dist/reader-watch.d.cts",
37
- "default": "./dist/reader-watch.cjs"
38
- }
39
- },
40
- "./writer": {
41
- "import": {
42
- "types": "./dist/writer.d.ts",
43
- "default": "./dist/writer.js"
44
- },
45
- "require": {
46
- "types": "./dist/writer.d.cts",
47
- "default": "./dist/writer.cjs"
48
- }
49
- },
50
- "./server": {
51
- "import": {
52
- "types": "./dist/server.d.ts",
53
- "default": "./dist/server.js"
54
- },
55
- "require": {
56
- "types": "./dist/server.d.cts",
57
- "default": "./dist/server.cjs"
58
- }
59
- },
60
- "./style-downloader": {
61
- "import": {
62
- "types": "./dist/style-downloader.d.ts",
63
- "default": "./dist/style-downloader.js"
64
- },
65
- "require": {
66
- "types": "./dist/style-downloader.d.cts",
67
- "default": "./dist/style-downloader.cjs"
68
- }
69
- },
70
- "./tile-downloader": {
71
- "import": {
72
- "types": "./dist/tile-downloader.d.ts",
73
- "default": "./dist/tile-downloader.js"
74
- },
75
- "require": {
76
- "types": "./dist/tile-downloader.d.cts",
77
- "default": "./dist/tile-downloader.cjs"
78
- }
79
- },
80
- "./download": {
81
- "import": {
82
- "types": "./dist/download.d.ts",
83
- "default": "./dist/download.js"
84
- },
85
- "require": {
86
- "types": "./dist/download.d.cts",
87
- "default": "./dist/download.cjs"
88
- }
89
- },
90
- "./from-mbtiles": {
91
- "import": {
92
- "types": "./dist/from-mbtiles.d.ts",
93
- "default": "./dist/from-mbtiles.js"
94
- },
95
- "require": {
96
- "types": "./dist/from-mbtiles.d.cts",
97
- "default": "./dist/from-mbtiles.cjs"
98
- }
99
- },
100
- "./package.json": "./package.json"
101
- },
102
6
  "bin": {
103
7
  "styled-map-package": "bin/smp.js",
104
8
  "smp": "bin/smp.js"
105
9
  },
106
10
  "files": [
107
11
  "bin",
108
- "dist",
12
+ "lib",
109
13
  "map-viewer"
110
14
  ],
111
15
  "scripts": {
112
- "test": "npm run lint && npm run build && npm run types && node --test",
113
- "prepare": "husky",
114
- "lint": "eslint .",
115
- "types": "tsc",
116
- "build": "tsup",
117
- "prepack": "npm run build"
16
+ "test": "echo 'No CLI tests yet'"
118
17
  },
119
18
  "keywords": [],
120
- "author": "",
121
19
  "license": "MIT",
122
20
  "dependencies": {
123
- "@commander-js/extra-typings": "^12.1.0",
124
- "@fastify/static": "^8.3.0",
21
+ "styled-map-package-api": "^5.0.0-pre.0",
125
22
  "@inquirer/prompts": "^6.0.1",
126
- "@mapbox/sphericalmercator": "^1.2.0",
127
- "@maplibre/maplibre-gl-style-spec": "^20.3.1",
128
- "@placemarkio/check-geojson": "^0.1.12",
129
- "@turf/bbox": "^7.2.0",
130
- "@turf/helpers": "^7.2.0",
131
23
  "@whatwg-node/server": "^0.10.17",
132
- "ansi-diff": "^1.2.0",
133
- "archiver": "^7.0.1",
134
- "buffer-peek-stream": "^1.1.0",
135
24
  "chalk": "^5.4.1",
136
25
  "commander": "^12.1.0",
137
- "fastify": "^5.6.2",
138
- "filter-obj": "^6.1.0",
139
- "into-stream": "^8.0.1",
140
- "is-stream": "^4.0.1",
141
26
  "itty-router": "^5.0.22",
142
- "ky": "^1.7.5",
143
27
  "log-symbols": "^7.0.0",
144
- "map-obj": "^5.0.2",
145
- "mbtiles-reader": "^1.0.0",
146
28
  "open": "^10.1.0",
147
29
  "ora": "^8.2.0",
148
- "p-event": "^6.0.1",
149
- "p-limit": "^6.2.0",
150
30
  "pretty-bytes": "^6.1.1",
151
31
  "pretty-ms": "^9.2.0",
152
- "readable-stream": "^4.7.0",
153
- "temp-dir": "^3.0.0",
154
- "yauzl-promise": "^4.0.0",
155
- "yocto-queue": "^1.1.1"
156
- },
157
- "devDependencies": {
158
- "@eslint/js": "^9.25.1",
159
- "@jsquash/jpeg": "^1.4.0",
160
- "@jsquash/png": "^3.0.1",
161
- "@stealthybox/jpg-stream": "^1.1.2",
162
- "@trivago/prettier-plugin-sort-imports": "^4.3.0",
163
- "@types/archiver": "^6.0.3",
164
- "@types/geojson": "^7946.0.16",
165
- "@types/http-errors": "^2.0.4",
166
- "@types/mapbox__sphericalmercator": "^1.2.3",
167
- "@types/node": "^18.19.130",
168
- "@types/readable-stream": "^4.0.18",
169
- "@types/yauzl-promise": "^4.0.1",
170
- "ava": "^6.2.0",
171
- "block-stream2": "^2.1.0",
172
- "esbuild-fix-imports-plugin": "^1.0.20",
173
- "eslint": "^9.25.1",
174
- "execa": "^9.4.0",
175
- "globals": "^16.0.0",
176
- "husky": "^9.1.7",
177
- "jpg-stream": "^1.1.2",
178
- "lint-staged": "^15.4.3",
179
- "pixel-stream": "^1.0.3",
180
- "playwright": "^1.50.1",
181
- "png-stream": "^1.0.5",
182
- "prettier": "^3.5.2",
183
- "random-bytes-readable-stream": "^3.0.0",
184
- "tempy": "^3.1.0",
185
- "tsup": "^8.4.0",
186
- "type-fest": "^4.35.0",
187
- "typescript": "^5.9.3"
188
- },
189
- "prettier": {
190
- "semi": false,
191
- "singleQuote": true,
192
- "importOrder": [
193
- "^node:",
194
- "^[./]"
195
- ],
196
- "importOrderSeparation": true,
197
- "plugins": [
198
- "@trivago/prettier-plugin-sort-imports"
199
- ]
200
- },
201
- "lint-staged": {
202
- "*.js": [
203
- "eslint --cache --fix"
204
- ],
205
- "*.{js,css,md}": "prettier --write"
206
- },
207
- "directories": {
208
- "lib": "lib",
209
- "test": "test"
32
+ "readable-stream": "^4.7.0"
210
33
  },
211
34
  "repository": {
212
35
  "type": "git",
213
- "url": "git+https://github.com/digidem/styled-map-package.git"
214
- },
215
- "bugs": {
216
- "url": "https://github.com/digidem/styled-map-package/issues"
36
+ "url": "git+https://github.com/digidem/styled-map-package.git",
37
+ "directory": "packages/cli"
217
38
  }
218
39
  }
package/LICENSE.md DELETED
@@ -1,7 +0,0 @@
1
- Copyright (c) 2024 Awana Digital
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md DELETED
@@ -1,28 +0,0 @@
1
- # Styled Map Package
2
-
3
- A Styled Map Package (`.smp`) file is a Zip archive containing all the resources needed to serve a Maplibre vector styled map offline. This includes the style JSON, vector and raster tiles, glyphs (fonts), the sprite image, and the sprite metadata.
4
-
5
- ## Installation
6
-
7
- Install globally to use the `smp` command.
8
-
9
- ```sh
10
- npm install --global styled-map-package
11
- ```
12
-
13
- ## Usage
14
-
15
- Download an online map to a styled map package file, specifying the bounding box (west, south, east, north) and max zoom level.
16
-
17
- ```sh
18
- smp download https://demotiles.maplibre.org/style.json \
19
- --bbox '-180,-80,180,80' \
20
- --zoom 5 \
21
- --output demotiles.smp
22
- ```
23
-
24
- Start a server and open in the default browser.
25
-
26
- ```sh
27
- smp view demotiles.smp --open
28
- ```
package/dist/download.cjs DELETED
@@ -1,101 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var download_exports = {};
20
- __export(download_exports, {
21
- download: () => download
22
- });
23
- module.exports = __toCommonJS(download_exports);
24
- var import_readable_stream = require("readable-stream");
25
- var import_promises = require("stream/promises");
26
- var import_style_downloader = require('./style-downloader.cjs');
27
- var import_writer = require('./writer.cjs');
28
- function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }) {
29
- const downloader = new import_style_downloader.StyleDownloader(styleUrl, {
30
- concurrency: 24,
31
- mapboxAccessToken: accessToken
32
- });
33
- let start = Date.now();
34
- let progress = {
35
- tiles: { downloaded: 0, totalBytes: 0, total: 0, skipped: 0, done: false },
36
- style: { done: false },
37
- sprites: { downloaded: 0, done: false },
38
- glyphs: { downloaded: 0, total: 0, totalBytes: 0, done: false },
39
- output: { totalBytes: 0, done: false },
40
- elapsedMs: 0
41
- };
42
- const sizeCounter = new import_readable_stream.Transform({
43
- transform(chunk, encoding, cb) {
44
- handleProgress({
45
- output: {
46
- totalBytes: progress.output.totalBytes + chunk.length,
47
- done: false
48
- }
49
- });
50
- cb(null, chunk);
51
- },
52
- final(cb) {
53
- handleProgress({ output: { ...progress.output, done: true } });
54
- cb();
55
- }
56
- });
57
- function handleProgress(update) {
58
- progress = { ...progress, ...update, elapsedMs: Date.now() - start };
59
- onprogress?.(progress);
60
- }
61
- ;
62
- (async () => {
63
- const style = await downloader.getStyle();
64
- const writer = new import_writer.Writer(style);
65
- handleProgress({ style: { done: true } });
66
- writer.outputStream.pipe(sizeCounter);
67
- writer.on("error", (err) => sizeCounter.destroy(err));
68
- try {
69
- for await (const spriteInfo of downloader.getSprites()) {
70
- await writer.addSprite(spriteInfo);
71
- handleProgress({
72
- sprites: { downloaded: progress.sprites.downloaded + 1, done: false }
73
- });
74
- }
75
- handleProgress({ sprites: { ...progress.sprites, done: true } });
76
- const tiles = downloader.getTiles({
77
- bounds: bbox,
78
- maxzoom,
79
- onprogress: (tileStats) => handleProgress({ tiles: { ...tileStats, done: false } })
80
- });
81
- await (0, import_promises.pipeline)(tiles, writer.createTileWriteStream({ concurrency: 24 }));
82
- handleProgress({ tiles: { ...progress.tiles, done: true } });
83
- const glyphs = downloader.getGlyphs({
84
- onprogress: (glyphStats) => handleProgress({ glyphs: { ...glyphStats, done: false } })
85
- });
86
- await (0, import_promises.pipeline)(glyphs, writer.createGlyphWriteStream());
87
- handleProgress({ glyphs: { ...progress.glyphs, done: true } });
88
- writer.finish();
89
- } catch (err) {
90
- writer.outputStream.destroy(
91
- /** @type {Error} */
92
- err
93
- );
94
- }
95
- })();
96
- return sizeCounter;
97
- }
98
- // Annotate the CommonJS export names for ESM import in node:
99
- 0 && (module.exports = {
100
- download
101
- });
@@ -1,65 +0,0 @@
1
- import { GlyphDownloadStats } from './style-downloader.cjs';
2
- import { TileDownloadStats } from './tile-downloader.cjs';
3
- import { D as DownloadStream } from './types-B4Xn1F9K.cjs';
4
- import { BBox } from './utils/geo.cjs';
5
- import 'ky';
6
- import 'stream';
7
- import '@maplibre/maplibre-gl-style-spec';
8
- import './utils/fetch.cjs';
9
- import './utils/streams.cjs';
10
- import 'readable-stream';
11
- import 'geojson';
12
- import 'type-fest';
13
- import 'events';
14
-
15
- /**
16
- * @typedef {object} DownloadProgress
17
- * @property {import('./tile-downloader.js').TileDownloadStats & { done: boolean }} tiles
18
- * @property {{ done: boolean }} style
19
- * @property {{ downloaded: number, done: boolean }} sprites
20
- * @property {import('./style-downloader.js').GlyphDownloadStats & { done: boolean }} glyphs
21
- * @property {{ totalBytes: number, done: boolean }} output
22
- * @property {number} elapsedMs
23
- */
24
- /**
25
- * Download a map style and its resources for a given bounding box and max zoom
26
- * level. Returns a readable stream of a "styled map package", a zip file
27
- * containing all the resources needed to serve the style offline.
28
- *
29
- * @param {object} opts
30
- * @param {import("./utils/geo.js").BBox} opts.bbox Bounding box to download tiles for
31
- * @param {number} opts.maxzoom Max zoom level to download tiles for
32
- * @param {string} opts.styleUrl URL of the style to download
33
- * @param { (progress: DownloadProgress) => void } [opts.onprogress] Optional callback for reporting progress
34
- * @param {string} [opts.accessToken]
35
- * @returns {import('./types.js').DownloadStream} Readable stream of the output styled map file
36
- */
37
- declare function download({ bbox, maxzoom, styleUrl, onprogress, accessToken }: {
38
- bbox: BBox;
39
- maxzoom: number;
40
- styleUrl: string;
41
- onprogress?: ((progress: DownloadProgress) => void) | undefined;
42
- accessToken?: string | undefined;
43
- }): DownloadStream;
44
- type DownloadProgress = {
45
- tiles: TileDownloadStats & {
46
- done: boolean;
47
- };
48
- style: {
49
- done: boolean;
50
- };
51
- sprites: {
52
- downloaded: number;
53
- done: boolean;
54
- };
55
- glyphs: GlyphDownloadStats & {
56
- done: boolean;
57
- };
58
- output: {
59
- totalBytes: number;
60
- done: boolean;
61
- };
62
- elapsedMs: number;
63
- };
64
-
65
- export { type DownloadProgress, download };