styled-map-package 4.1.0 → 5.0.0-pre.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.
Files changed (238) hide show
  1. package/README.md +47 -7
  2. package/bin/smp-download.js +27 -151
  3. package/bin/smp-mbtiles.js +12 -7
  4. package/bin/smp-view.js +32 -54
  5. package/lib/commands/download.js +188 -0
  6. package/lib/commands/mbtiles.js +21 -0
  7. package/lib/commands/view.js +57 -0
  8. package/lib/reporters.js +92 -0
  9. package/package.json +9 -181
  10. package/LICENSE.md +0 -7
  11. package/dist/download.cjs +0 -101
  12. package/dist/download.d.cts +0 -65
  13. package/dist/download.d.ts +0 -65
  14. package/dist/download.js +0 -77
  15. package/dist/from-mbtiles.cjs +0 -91
  16. package/dist/from-mbtiles.d.cts +0 -17
  17. package/dist/from-mbtiles.d.ts +0 -17
  18. package/dist/from-mbtiles.js +0 -57
  19. package/dist/index.cjs +0 -49
  20. package/dist/index.d.cts +0 -27
  21. package/dist/index.d.ts +0 -27
  22. package/dist/index.js +0 -18
  23. package/dist/reader-watch.cjs +0 -135
  24. package/dist/reader-watch.d.cts +0 -24
  25. package/dist/reader-watch.d.ts +0 -24
  26. package/dist/reader-watch.js +0 -101
  27. package/dist/reader.cjs +0 -168
  28. package/dist/reader.d.cts +0 -62
  29. package/dist/reader.d.ts +0 -62
  30. package/dist/reader.js +0 -139
  31. package/dist/reporters.cjs +0 -122
  32. package/dist/reporters.d.cts +0 -10
  33. package/dist/reporters.d.ts +0 -10
  34. package/dist/reporters.js +0 -88
  35. package/dist/server.cjs +0 -78
  36. package/dist/server.d.cts +0 -48
  37. package/dist/server.d.ts +0 -48
  38. package/dist/server.js +0 -54
  39. package/dist/style-downloader.cjs +0 -312
  40. package/dist/style-downloader.d.cts +0 -120
  41. package/dist/style-downloader.d.ts +0 -120
  42. package/dist/style-downloader.js +0 -288
  43. package/dist/tile-downloader.cjs +0 -158
  44. package/dist/tile-downloader.d.cts +0 -84
  45. package/dist/tile-downloader.d.ts +0 -84
  46. package/dist/tile-downloader.js +0 -126
  47. package/dist/types-yLQy3AKR.d.cts +0 -192
  48. package/dist/types-yLQy3AKR.d.ts +0 -192
  49. package/dist/utils/errors.cjs +0 -41
  50. package/dist/utils/errors.d.cts +0 -18
  51. package/dist/utils/errors.d.ts +0 -18
  52. package/dist/utils/errors.js +0 -16
  53. package/dist/utils/fetch.cjs +0 -96
  54. package/dist/utils/fetch.d.cts +0 -51
  55. package/dist/utils/fetch.d.ts +0 -51
  56. package/dist/utils/fetch.js +0 -62
  57. package/dist/utils/file-formats.cjs +0 -98
  58. package/dist/utils/file-formats.d.cts +0 -35
  59. package/dist/utils/file-formats.d.ts +0 -35
  60. package/dist/utils/file-formats.js +0 -62
  61. package/dist/utils/geo.cjs +0 -84
  62. package/dist/utils/geo.d.cts +0 -46
  63. package/dist/utils/geo.d.ts +0 -46
  64. package/dist/utils/geo.js +0 -56
  65. package/dist/utils/mapbox.cjs +0 -121
  66. package/dist/utils/mapbox.d.cts +0 -43
  67. package/dist/utils/mapbox.d.ts +0 -43
  68. package/dist/utils/mapbox.js +0 -91
  69. package/dist/utils/misc.cjs +0 -39
  70. package/dist/utils/misc.d.cts +0 -22
  71. package/dist/utils/misc.d.ts +0 -22
  72. package/dist/utils/misc.js +0 -13
  73. package/dist/utils/streams.cjs +0 -130
  74. package/dist/utils/streams.d.cts +0 -73
  75. package/dist/utils/streams.d.ts +0 -73
  76. package/dist/utils/streams.js +0 -103
  77. package/dist/utils/style.cjs +0 -126
  78. package/dist/utils/style.d.cts +0 -69
  79. package/dist/utils/style.d.ts +0 -69
  80. package/dist/utils/style.js +0 -98
  81. package/dist/utils/templates.cjs +0 -118
  82. package/dist/utils/templates.d.cts +0 -80
  83. package/dist/utils/templates.d.ts +0 -80
  84. package/dist/utils/templates.js +0 -81
  85. package/dist/writer.cjs +0 -449
  86. package/dist/writer.d.cts +0 -7
  87. package/dist/writer.d.ts +0 -7
  88. package/dist/writer.js +0 -424
  89. package/node_modules/@node-rs/crc32/LICENSE +0 -21
  90. package/node_modules/@node-rs/crc32/README.md +0 -61
  91. package/node_modules/@node-rs/crc32/browser.js +0 -1
  92. package/node_modules/@node-rs/crc32/index.d.ts +0 -5
  93. package/node_modules/@node-rs/crc32/index.js +0 -368
  94. package/node_modules/@node-rs/crc32/package.json +0 -97
  95. package/node_modules/@node-rs/crc32-linux-x64-gnu/README.md +0 -3
  96. package/node_modules/@node-rs/crc32-linux-x64-gnu/crc32.linux-x64-gnu.node +0 -0
  97. package/node_modules/@node-rs/crc32-linux-x64-gnu/package.json +0 -43
  98. package/node_modules/@node-rs/crc32-linux-x64-musl/README.md +0 -3
  99. package/node_modules/@node-rs/crc32-linux-x64-musl/crc32.linux-x64-musl.node +0 -0
  100. package/node_modules/@node-rs/crc32-linux-x64-musl/package.json +0 -43
  101. package/node_modules/define-data-property/.eslintrc +0 -24
  102. package/node_modules/define-data-property/.github/FUNDING.yml +0 -12
  103. package/node_modules/define-data-property/.nycrc +0 -13
  104. package/node_modules/define-data-property/CHANGELOG.md +0 -70
  105. package/node_modules/define-data-property/LICENSE +0 -21
  106. package/node_modules/define-data-property/README.md +0 -67
  107. package/node_modules/define-data-property/index.d.ts +0 -12
  108. package/node_modules/define-data-property/index.js +0 -56
  109. package/node_modules/define-data-property/package.json +0 -106
  110. package/node_modules/define-data-property/test/index.js +0 -392
  111. package/node_modules/define-data-property/tsconfig.json +0 -59
  112. package/node_modules/define-properties/.editorconfig +0 -13
  113. package/node_modules/define-properties/.eslintrc +0 -19
  114. package/node_modules/define-properties/.github/FUNDING.yml +0 -12
  115. package/node_modules/define-properties/.nycrc +0 -9
  116. package/node_modules/define-properties/CHANGELOG.md +0 -91
  117. package/node_modules/define-properties/LICENSE +0 -21
  118. package/node_modules/define-properties/README.md +0 -84
  119. package/node_modules/define-properties/index.js +0 -47
  120. package/node_modules/define-properties/package.json +0 -88
  121. package/node_modules/es-define-property/.eslintrc +0 -13
  122. package/node_modules/es-define-property/.github/FUNDING.yml +0 -12
  123. package/node_modules/es-define-property/.nycrc +0 -9
  124. package/node_modules/es-define-property/CHANGELOG.md +0 -29
  125. package/node_modules/es-define-property/LICENSE +0 -21
  126. package/node_modules/es-define-property/README.md +0 -49
  127. package/node_modules/es-define-property/index.d.ts +0 -3
  128. package/node_modules/es-define-property/index.js +0 -14
  129. package/node_modules/es-define-property/package.json +0 -81
  130. package/node_modules/es-define-property/test/index.js +0 -56
  131. package/node_modules/es-define-property/tsconfig.json +0 -10
  132. package/node_modules/es-errors/.eslintrc +0 -5
  133. package/node_modules/es-errors/.github/FUNDING.yml +0 -12
  134. package/node_modules/es-errors/CHANGELOG.md +0 -40
  135. package/node_modules/es-errors/LICENSE +0 -21
  136. package/node_modules/es-errors/README.md +0 -55
  137. package/node_modules/es-errors/eval.d.ts +0 -3
  138. package/node_modules/es-errors/eval.js +0 -4
  139. package/node_modules/es-errors/index.d.ts +0 -3
  140. package/node_modules/es-errors/index.js +0 -4
  141. package/node_modules/es-errors/package.json +0 -80
  142. package/node_modules/es-errors/range.d.ts +0 -3
  143. package/node_modules/es-errors/range.js +0 -4
  144. package/node_modules/es-errors/ref.d.ts +0 -3
  145. package/node_modules/es-errors/ref.js +0 -4
  146. package/node_modules/es-errors/syntax.d.ts +0 -3
  147. package/node_modules/es-errors/syntax.js +0 -4
  148. package/node_modules/es-errors/test/index.js +0 -19
  149. package/node_modules/es-errors/tsconfig.json +0 -49
  150. package/node_modules/es-errors/type.d.ts +0 -3
  151. package/node_modules/es-errors/type.js +0 -4
  152. package/node_modules/es-errors/uri.d.ts +0 -3
  153. package/node_modules/es-errors/uri.js +0 -4
  154. package/node_modules/globalthis/.eslintrc +0 -18
  155. package/node_modules/globalthis/.nycrc +0 -10
  156. package/node_modules/globalthis/CHANGELOG.md +0 -109
  157. package/node_modules/globalthis/LICENSE +0 -21
  158. package/node_modules/globalthis/README.md +0 -70
  159. package/node_modules/globalthis/auto.js +0 -3
  160. package/node_modules/globalthis/implementation.browser.js +0 -11
  161. package/node_modules/globalthis/implementation.js +0 -3
  162. package/node_modules/globalthis/index.js +0 -19
  163. package/node_modules/globalthis/package.json +0 -99
  164. package/node_modules/globalthis/polyfill.js +0 -10
  165. package/node_modules/globalthis/shim.js +0 -29
  166. package/node_modules/globalthis/test/implementation.js +0 -11
  167. package/node_modules/globalthis/test/index.js +0 -11
  168. package/node_modules/globalthis/test/native.js +0 -26
  169. package/node_modules/globalthis/test/shimmed.js +0 -29
  170. package/node_modules/globalthis/test/tests.js +0 -36
  171. package/node_modules/gopd/.eslintrc +0 -16
  172. package/node_modules/gopd/.github/FUNDING.yml +0 -12
  173. package/node_modules/gopd/CHANGELOG.md +0 -45
  174. package/node_modules/gopd/LICENSE +0 -21
  175. package/node_modules/gopd/README.md +0 -40
  176. package/node_modules/gopd/gOPD.d.ts +0 -1
  177. package/node_modules/gopd/gOPD.js +0 -4
  178. package/node_modules/gopd/index.d.ts +0 -5
  179. package/node_modules/gopd/index.js +0 -15
  180. package/node_modules/gopd/package.json +0 -77
  181. package/node_modules/gopd/test/index.js +0 -36
  182. package/node_modules/gopd/tsconfig.json +0 -9
  183. package/node_modules/has-property-descriptors/.eslintrc +0 -13
  184. package/node_modules/has-property-descriptors/.github/FUNDING.yml +0 -12
  185. package/node_modules/has-property-descriptors/.nycrc +0 -9
  186. package/node_modules/has-property-descriptors/CHANGELOG.md +0 -35
  187. package/node_modules/has-property-descriptors/LICENSE +0 -21
  188. package/node_modules/has-property-descriptors/README.md +0 -43
  189. package/node_modules/has-property-descriptors/index.js +0 -22
  190. package/node_modules/has-property-descriptors/package.json +0 -77
  191. package/node_modules/has-property-descriptors/test/index.js +0 -57
  192. package/node_modules/is-it-type/License +0 -19
  193. package/node_modules/is-it-type/README.md +0 -102
  194. package/node_modules/is-it-type/changelog.md +0 -239
  195. package/node_modules/is-it-type/dist/cjs/is-it-type.js +0 -173
  196. package/node_modules/is-it-type/dist/cjs/is-it-type.js.map +0 -1
  197. package/node_modules/is-it-type/dist/cjs/is-it-type.min.js +0 -2
  198. package/node_modules/is-it-type/dist/cjs/is-it-type.min.js.map +0 -1
  199. package/node_modules/is-it-type/dist/esm/is-it-type.js +0 -143
  200. package/node_modules/is-it-type/dist/esm/is-it-type.js.map +0 -1
  201. package/node_modules/is-it-type/dist/esm/is-it-type.min.js +0 -2
  202. package/node_modules/is-it-type/dist/esm/is-it-type.min.js.map +0 -1
  203. package/node_modules/is-it-type/dist/esm/package.json +0 -3
  204. package/node_modules/is-it-type/dist/umd/is-it-type.js +0 -450
  205. package/node_modules/is-it-type/dist/umd/is-it-type.js.map +0 -1
  206. package/node_modules/is-it-type/dist/umd/is-it-type.min.js +0 -2
  207. package/node_modules/is-it-type/dist/umd/is-it-type.min.js.map +0 -1
  208. package/node_modules/is-it-type/es/index.js +0 -8
  209. package/node_modules/is-it-type/es/package.json +0 -3
  210. package/node_modules/is-it-type/index.js +0 -10
  211. package/node_modules/is-it-type/package.json +0 -87
  212. package/node_modules/is-it-type/src/index.js +0 -169
  213. package/node_modules/object-keys/.editorconfig +0 -13
  214. package/node_modules/object-keys/.eslintrc +0 -17
  215. package/node_modules/object-keys/.travis.yml +0 -277
  216. package/node_modules/object-keys/CHANGELOG.md +0 -232
  217. package/node_modules/object-keys/LICENSE +0 -21
  218. package/node_modules/object-keys/README.md +0 -76
  219. package/node_modules/object-keys/implementation.js +0 -122
  220. package/node_modules/object-keys/index.js +0 -32
  221. package/node_modules/object-keys/isArguments.js +0 -17
  222. package/node_modules/object-keys/package.json +0 -88
  223. package/node_modules/object-keys/test/index.js +0 -5
  224. package/node_modules/simple-invariant/License +0 -19
  225. package/node_modules/simple-invariant/README.md +0 -64
  226. package/node_modules/simple-invariant/changelog.md +0 -31
  227. package/node_modules/simple-invariant/index.js +0 -19
  228. package/node_modules/simple-invariant/package.json +0 -50
  229. package/node_modules/yauzl-promise/License +0 -19
  230. package/node_modules/yauzl-promise/README.md +0 -440
  231. package/node_modules/yauzl-promise/index.js +0 -10
  232. package/node_modules/yauzl-promise/lib/entry.js +0 -312
  233. package/node_modules/yauzl-promise/lib/index.js +0 -160
  234. package/node_modules/yauzl-promise/lib/reader.js +0 -289
  235. package/node_modules/yauzl-promise/lib/shared.js +0 -20
  236. package/node_modules/yauzl-promise/lib/utils.js +0 -105
  237. package/node_modules/yauzl-promise/lib/zip.js +0 -1224
  238. package/node_modules/yauzl-promise/package.json +0 -56
@@ -1,80 +0,0 @@
1
- import * as type_fest from 'type-fest';
2
- import { d as GlyphRange, T as TileInfo, c as TileFormat } from '../types-yLQy3AKR.cjs';
3
- import '@maplibre/maplibre-gl-style-spec';
4
- import 'geojson';
5
- import 'stream';
6
- import 'readable-stream';
7
- import 'events';
8
-
9
- /**
10
- * @param {string} path
11
- * @returns
12
- */
13
- declare function getResourceType(path: string): "sprite" | "style" | "tile" | "glyph";
14
- /**
15
- * Determine the content type of a file based on its extension.
16
- *
17
- * @param {string} path
18
- */
19
- declare function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
20
- /**
21
- * Get the filename for a tile, given the TileInfo
22
- *
23
- * @param {import("type-fest").SetRequired<import("../writer.js").TileInfo, 'format'>} tileInfo
24
- * @returns
25
- */
26
- declare function getTileFilename({ sourceId, z, x, y, format }: type_fest.SetRequired<TileInfo, "format">): string;
27
- /**
28
- * Get a filename for a sprite file, given the sprite id, pixel ratio and extension
29
- *
30
- * @param {{ id: string, pixelRatio: number, ext: '.json' | '.png'}} spriteInfo
31
- */
32
- declare function getSpriteFilename({ id, pixelRatio, ext }: {
33
- id: string;
34
- pixelRatio: number;
35
- ext: ".json" | ".png";
36
- }): string;
37
- /**
38
- * Get the filename for a glyph file, given the fontstack and range
39
- *
40
- * @param {object} options
41
- * @param {string} options.fontstack
42
- * @param {import("../writer.js").GlyphRange} options.range
43
- */
44
- declare function getGlyphFilename({ fontstack, range }: {
45
- fontstack: string;
46
- range: GlyphRange;
47
- }): string;
48
- /**
49
- * Get the URI template for the sprites in the style
50
- */
51
- declare function getSpriteUri(id?: string): string;
52
- /**
53
- * Get the URI template for tiles in the style
54
- *
55
- * @param {object} opts
56
- * @param {string} opts.sourceId
57
- * @param {import("../writer.js").TileFormat} opts.format
58
- * @returns
59
- */
60
- declare function getTileUri({ sourceId, format }: {
61
- sourceId: string;
62
- format: TileFormat;
63
- }): string;
64
- /**
65
- * Replaces variables in a string with values provided in an object. Variables
66
- * in the string are denoted by curly braces, e.g., {variableName}.
67
- *
68
- * @param {string} template - The string containing variables wrapped in curly braces.
69
- * @param {Record<string, string | number>} variables - An object where the keys correspond to variable names and values correspond to the replacement values.
70
- * @returns {string} The string with the variables replaced by their corresponding values.
71
- */
72
- declare function replaceVariables(template: string, variables: Record<string, string | number>): string;
73
- declare const URI_SCHEME: "smp";
74
- declare const URI_BASE: string;
75
- declare const STYLE_FILE: "style.json";
76
- declare const SOURCES_FOLDER: "s";
77
- declare const FONTS_FOLDER: "fonts";
78
- declare const GLYPH_URI: string;
79
-
80
- export { FONTS_FOLDER, GLYPH_URI, SOURCES_FOLDER, STYLE_FILE, URI_BASE, URI_SCHEME, getContentType, getGlyphFilename, getResourceType, getSpriteFilename, getSpriteUri, getTileFilename, getTileUri, replaceVariables };
@@ -1,80 +0,0 @@
1
- import * as type_fest from 'type-fest';
2
- import { d as GlyphRange, T as TileInfo, c as TileFormat } from '../types-yLQy3AKR.js';
3
- import '@maplibre/maplibre-gl-style-spec';
4
- import 'geojson';
5
- import 'stream';
6
- import 'readable-stream';
7
- import 'events';
8
-
9
- /**
10
- * @param {string} path
11
- * @returns
12
- */
13
- declare function getResourceType(path: string): "sprite" | "style" | "tile" | "glyph";
14
- /**
15
- * Determine the content type of a file based on its extension.
16
- *
17
- * @param {string} path
18
- */
19
- declare function getContentType(path: string): "application/json; charset=utf-8" | "application/x-protobuf" | "image/png" | "image/jpeg" | "image/webp" | "application/vnd.mapbox-vector-tile";
20
- /**
21
- * Get the filename for a tile, given the TileInfo
22
- *
23
- * @param {import("type-fest").SetRequired<import("../writer.js").TileInfo, 'format'>} tileInfo
24
- * @returns
25
- */
26
- declare function getTileFilename({ sourceId, z, x, y, format }: type_fest.SetRequired<TileInfo, "format">): string;
27
- /**
28
- * Get a filename for a sprite file, given the sprite id, pixel ratio and extension
29
- *
30
- * @param {{ id: string, pixelRatio: number, ext: '.json' | '.png'}} spriteInfo
31
- */
32
- declare function getSpriteFilename({ id, pixelRatio, ext }: {
33
- id: string;
34
- pixelRatio: number;
35
- ext: ".json" | ".png";
36
- }): string;
37
- /**
38
- * Get the filename for a glyph file, given the fontstack and range
39
- *
40
- * @param {object} options
41
- * @param {string} options.fontstack
42
- * @param {import("../writer.js").GlyphRange} options.range
43
- */
44
- declare function getGlyphFilename({ fontstack, range }: {
45
- fontstack: string;
46
- range: GlyphRange;
47
- }): string;
48
- /**
49
- * Get the URI template for the sprites in the style
50
- */
51
- declare function getSpriteUri(id?: string): string;
52
- /**
53
- * Get the URI template for tiles in the style
54
- *
55
- * @param {object} opts
56
- * @param {string} opts.sourceId
57
- * @param {import("../writer.js").TileFormat} opts.format
58
- * @returns
59
- */
60
- declare function getTileUri({ sourceId, format }: {
61
- sourceId: string;
62
- format: TileFormat;
63
- }): string;
64
- /**
65
- * Replaces variables in a string with values provided in an object. Variables
66
- * in the string are denoted by curly braces, e.g., {variableName}.
67
- *
68
- * @param {string} template - The string containing variables wrapped in curly braces.
69
- * @param {Record<string, string | number>} variables - An object where the keys correspond to variable names and values correspond to the replacement values.
70
- * @returns {string} The string with the variables replaced by their corresponding values.
71
- */
72
- declare function replaceVariables(template: string, variables: Record<string, string | number>): string;
73
- declare const URI_SCHEME: "smp";
74
- declare const URI_BASE: string;
75
- declare const STYLE_FILE: "style.json";
76
- declare const SOURCES_FOLDER: "s";
77
- declare const FONTS_FOLDER: "fonts";
78
- declare const GLYPH_URI: string;
79
-
80
- export { FONTS_FOLDER, GLYPH_URI, SOURCES_FOLDER, STYLE_FILE, URI_BASE, URI_SCHEME, getContentType, getGlyphFilename, getResourceType, getSpriteFilename, getSpriteUri, getTileFilename, getTileUri, replaceVariables };
@@ -1,81 +0,0 @@
1
- const URI_SCHEME = "smp";
2
- const URI_BASE = URI_SCHEME + "://maps.v1/";
3
- const STYLE_FILE = "style.json";
4
- const SOURCES_FOLDER = "s";
5
- const SPRITES_FOLDER = "sprites";
6
- const FONTS_FOLDER = "fonts";
7
- const TILE_FILE = SOURCES_FOLDER + "/{sourceId}/{z}/{x}/{y}{ext}";
8
- const SPRITE_FILE = SPRITES_FOLDER + "/{id}/sprite{pixelRatio}{ext}";
9
- const GLYPH_FILE = FONTS_FOLDER + "/{fontstack}/{range}.pbf.gz";
10
- const GLYPH_URI = URI_BASE + GLYPH_FILE;
11
- const pathToResouceType = (
12
- /** @type {const} */
13
- {
14
- [TILE_FILE.split("/")[0] + "/"]: "tile",
15
- [SPRITE_FILE.split("/")[0] + "/"]: "sprite",
16
- [GLYPH_FILE.split("/")[0] + "/"]: "glyph"
17
- }
18
- );
19
- function getResourceType(path) {
20
- if (path === "style.json") return "style";
21
- for (const [prefix, type] of Object.entries(pathToResouceType)) {
22
- if (path.startsWith(prefix)) return type;
23
- }
24
- throw new Error(`Unknown resource type for path: ${path}`);
25
- }
26
- function getContentType(path) {
27
- if (path.endsWith(".json")) return "application/json; charset=utf-8";
28
- if (path.endsWith(".pbf.gz") || path.endsWith(".pbf"))
29
- return "application/x-protobuf";
30
- if (path.endsWith(".png")) return "image/png";
31
- if (path.endsWith(".jpg")) return "image/jpeg";
32
- if (path.endsWith(".webp")) return "image/webp";
33
- if (path.endsWith(".mvt.gz") || path.endsWith(".mvt"))
34
- return "application/vnd.mapbox-vector-tile";
35
- throw new Error(`Unknown content type for path: ${path}`);
36
- }
37
- function getTileFilename({ sourceId, z, x, y, format }) {
38
- const ext = "." + format + (format === "mvt" ? ".gz" : "");
39
- return replaceVariables(TILE_FILE, { sourceId, z, x, y, ext });
40
- }
41
- function getSpriteFilename({ id, pixelRatio, ext }) {
42
- return replaceVariables(SPRITE_FILE, {
43
- id,
44
- pixelRatio: getPixelRatioString(pixelRatio),
45
- ext
46
- });
47
- }
48
- function getGlyphFilename({ fontstack, range }) {
49
- return replaceVariables(GLYPH_FILE, { fontstack, range });
50
- }
51
- function getSpriteUri(id = "default") {
52
- return URI_BASE + replaceVariables(SPRITE_FILE, { id, pixelRatio: "", ext: "" });
53
- }
54
- function getTileUri({ sourceId, format }) {
55
- const ext = "." + format + (format === "mvt" ? ".gz" : "");
56
- return URI_BASE + TILE_FILE.replace("{sourceId}", sourceId).replace("{ext}", ext);
57
- }
58
- function getPixelRatioString(pixelRatio) {
59
- return pixelRatio === 1 ? "" : `@${pixelRatio}x`;
60
- }
61
- function replaceVariables(template, variables) {
62
- return template.replace(/{(.*?)}/g, (match, varName) => {
63
- return varName in variables ? String(variables[varName]) : match;
64
- });
65
- }
66
- export {
67
- FONTS_FOLDER,
68
- GLYPH_URI,
69
- SOURCES_FOLDER,
70
- STYLE_FILE,
71
- URI_BASE,
72
- URI_SCHEME,
73
- getContentType,
74
- getGlyphFilename,
75
- getResourceType,
76
- getSpriteFilename,
77
- getSpriteUri,
78
- getTileFilename,
79
- getTileUri,
80
- replaceVariables
81
- };
package/dist/writer.cjs DELETED
@@ -1,449 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var writer_exports = {};
30
- __export(writer_exports, {
31
- SUPPORTED_SOURCE_TYPES: () => SUPPORTED_SOURCE_TYPES,
32
- Writer: () => Writer
33
- });
34
- module.exports = __toCommonJS(writer_exports);
35
- var import_maplibre_gl_style_spec = require("@maplibre/maplibre-gl-style-spec");
36
- var import_bbox = require("@turf/bbox");
37
- var import_archiver = __toESM(require("archiver"), 1);
38
- var import_events = require("events");
39
- var import_filter_obj = require("filter-obj");
40
- var import_fs = __toESM(require("fs"), 1);
41
- var import_p_event = require("p-event");
42
- var import_readable_stream = require("readable-stream");
43
- var import_stream = require("stream");
44
- var import_file_formats = require('./utils/file-formats.cjs');
45
- var import_geo = require('./utils/geo.cjs');
46
- var import_misc = require('./utils/misc.cjs');
47
- var import_streams = require('./utils/streams.cjs');
48
- var import_style = require('./utils/style.cjs');
49
- var import_templates = require('./utils/templates.cjs');
50
- const SUPPORTED_SOURCE_TYPES = (
51
- /** @type {const} */
52
- [
53
- "raster",
54
- "vector",
55
- "geojson"
56
- ]
57
- );
58
- class Writer extends import_events.EventEmitter {
59
- #archive = (0, import_archiver.default)("zip", { zlib: { level: 9 } }).setMaxListeners(Infinity).on("error", console.error);
60
- /** @type {Set<string>} */
61
- #addedFiles = /* @__PURE__ */ new Set();
62
- /** @type {Set<string>} */
63
- #fonts = /* @__PURE__ */ new Set();
64
- /** @type {Set<string>} */
65
- #addedSpriteIds = /* @__PURE__ */ new Set();
66
- /** @type {Map<string, SourceInfo>} */
67
- #sources = /* @__PURE__ */ new Map();
68
- /** @type {StyleSpecification} */
69
- #style;
70
- #outputStream;
71
- static SUPPORTED_SOURCE_TYPES = SUPPORTED_SOURCE_TYPES;
72
- /**
73
- * @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to
74
- * v8. (There are currently no typescript declarations for v7 styles, hence
75
- * this is typed as `any` and validated internally)
76
- * @param {object} opts
77
- * @param {number} [opts.highWaterMark=1048576] The maximum number of bytes to buffer during write
78
- */
79
- constructor(style, { highWaterMark = 1024 * 1024 } = {}) {
80
- super();
81
- if (!style || !("version" in style)) {
82
- throw new Error("Invalid style");
83
- }
84
- if (style.version !== 7 && style.version !== 8) {
85
- throw new Error(`Invalid style: Unsupported version v${style.version}`);
86
- }
87
- if (!Array.isArray(style.layers)) {
88
- throw new Error("Invalid style: missing layers property");
89
- }
90
- const styleCopy = (0, import_misc.clone)(style);
91
- (0, import_maplibre_gl_style_spec.migrate)(styleCopy);
92
- const errors = (0, import_maplibre_gl_style_spec.validateStyleMin)(styleCopy);
93
- if (errors.length) {
94
- throw new AggregateError(errors, "Invalid style");
95
- }
96
- this.#style = styleCopy;
97
- for (const [sourceId, source] of Object.entries(this.#style.sources)) {
98
- if (source.type !== "geojson") continue;
99
- this.#addSource(sourceId, source);
100
- }
101
- this.#outputStream = new import_readable_stream.PassThrough({ highWaterMark });
102
- (0, import_readable_stream.pipeline)(this.#archive, this.#outputStream, (err) => {
103
- if (err) this.emit("error", err);
104
- });
105
- }
106
- /**
107
- * @returns {import('stream').Readable} Readable stream of the styled map package
108
- */
109
- get outputStream() {
110
- return this.#outputStream;
111
- }
112
- #getBounds() {
113
- let bounds;
114
- let maxzoom = 0;
115
- for (const { source } of this.#sources.values()) {
116
- if (source.type === "geojson") {
117
- if (isEmptyFeatureCollection(source.data)) continue;
118
- const bbox2 = get2DBBox(source.data.bbox);
119
- bounds = bounds ? (0, import_geo.unionBBox)([bounds, bbox2]) : [...bbox2];
120
- } else {
121
- if (source.maxzoom < maxzoom) continue;
122
- if (source.maxzoom === maxzoom) {
123
- bounds = bounds ? (0, import_geo.unionBBox)([bounds, source.bounds]) : source.bounds;
124
- } else {
125
- bounds = source.bounds;
126
- maxzoom = source.maxzoom;
127
- }
128
- }
129
- }
130
- return bounds;
131
- }
132
- #getMaxZoom() {
133
- let maxzoom = 0;
134
- for (const { source } of this.#sources.values()) {
135
- const sourceMaxzoom = (
136
- // For GeoJSON sources, the maxzoom is 16 unless otherwise set
137
- source.type === "geojson" ? source.maxzoom || 16 : source.maxzoom
138
- );
139
- maxzoom = Math.max(maxzoom, sourceMaxzoom);
140
- }
141
- return maxzoom;
142
- }
143
- /**
144
- * Add a source definition to the styled map package
145
- *
146
- * @param {string} sourceId
147
- * @param {InputSource} source
148
- * @returns {SourceInfo}
149
- */
150
- #addSource(sourceId, source) {
151
- const encodedSourceId = encodeSourceId(this.#sources.size);
152
- const tileSourceOverrides = {
153
- minzoom: 0,
154
- maxzoom: 0,
155
- bounds: (
156
- /** @type {import('./utils/geo.js').BBox} */
157
- [...import_geo.MAX_BOUNDS]
158
- ),
159
- tiles: (
160
- /** @type {string[]} */
161
- []
162
- )
163
- };
164
- let smpSource;
165
- switch (source.type) {
166
- case "raster":
167
- case "vector":
168
- smpSource = {
169
- ...(0, import_filter_obj.excludeKeys)(source, ["tiles", "url"]),
170
- ...tileSourceOverrides
171
- };
172
- break;
173
- case "geojson":
174
- smpSource = {
175
- ...source,
176
- maxzoom: 0,
177
- data: typeof source.data !== "string" ? (
178
- // Add a bbox property to the GeoJSON data if it doesn't already have one
179
- { ...source.data, bbox: source.data.bbox || (0, import_bbox.bbox)(source.data) }
180
- ) : (
181
- // If GeoJSON data is referenced by a URL, start with an empty FeatureCollection
182
- {
183
- type: "FeatureCollection",
184
- features: [],
185
- bbox: [0, 0, 0, 0]
186
- }
187
- )
188
- };
189
- break;
190
- }
191
- const sourceInfo = {
192
- source: smpSource,
193
- encodedSourceId
194
- };
195
- this.#sources.set(sourceId, sourceInfo);
196
- return sourceInfo;
197
- }
198
- /**
199
- * Add a tile to the styled map package
200
- *
201
- * @param {Source} tileData
202
- * @param {TileInfo} opts
203
- */
204
- async addTile(tileData, { z, x, y, sourceId, format }) {
205
- let sourceInfo = this.#sources.get(sourceId);
206
- if (!sourceInfo) {
207
- const source2 = this.#style.sources[sourceId];
208
- if (!source2) {
209
- throw new Error(`Source not referenced in style.json: ${sourceId}`);
210
- }
211
- if (source2.type !== "raster" && source2.type !== "vector") {
212
- throw new Error(`Unsupported source type: ${source2.type}`);
213
- }
214
- sourceInfo = this.#addSource(sourceId, source2);
215
- }
216
- const { source, encodedSourceId } = sourceInfo;
217
- if (source.type !== "raster" && source.type !== "vector") {
218
- throw new Error(`Unsupported source type: ${source.type}`);
219
- }
220
- if (!format) {
221
- const tileDataStream = typeof tileData === "string" ? import_fs.default.createReadStream(tileData) : tileData instanceof Uint8Array ? import_stream.Readable.from(tileData) : tileData;
222
- [format, tileData] = await (0, import_file_formats.getTileFormatFromStream)(tileDataStream);
223
- }
224
- if (!sourceInfo.format) {
225
- sourceInfo.format = format;
226
- } else if (sourceInfo.format !== format) {
227
- throw new Error(
228
- `Tile format mismatch for source ${sourceId}: expected ${sourceInfo.format}, got ${format}`
229
- );
230
- }
231
- const bbox2 = (0, import_geo.tileToBBox)({ z, x, y });
232
- if (z > source.maxzoom) {
233
- source.maxzoom = z;
234
- source.bounds = bbox2;
235
- } else if (z === source.maxzoom) {
236
- source.bounds = (0, import_geo.unionBBox)([source.bounds, bbox2]);
237
- }
238
- const name = (0, import_templates.getTileFilename)({ sourceId: encodedSourceId, z, x, y, format });
239
- return this.#append(tileData, { name, store: true });
240
- }
241
- /**
242
- * Create a write stream for adding tiles to the styled map package
243
- *
244
- * @param {object} opts
245
- * @param {number} [opts.concurrency=16] The number of concurrent writes
246
- *
247
- * @returns
248
- */
249
- createTileWriteStream({ concurrency = 16 } = {}) {
250
- return (0, import_streams.writeStreamFromAsync)(this.addTile.bind(this), { concurrency });
251
- }
252
- /**
253
- * Add a sprite to the styled map package
254
- *
255
- * @param {object} options
256
- * @param {Source} options.json
257
- * @param {Source} options.png
258
- * @param {number} [options.pixelRatio]
259
- * @param {string} [options.id='default']
260
- * @returns {Promise<void>}
261
- */
262
- async addSprite({ json, png, pixelRatio = 1, id = "default" }) {
263
- this.#addedSpriteIds.add(id);
264
- const jsonName = (0, import_templates.getSpriteFilename)({ id, pixelRatio, ext: ".json" });
265
- const pngName = (0, import_templates.getSpriteFilename)({ id, pixelRatio, ext: ".png" });
266
- await Promise.all([
267
- this.#append(json, { name: jsonName }),
268
- this.#append(png, { name: pngName })
269
- ]);
270
- }
271
- /**
272
- * Add glyphs to the styled map package
273
- *
274
- * @param {Source} glyphData
275
- * @param {GlyphInfo} glyphInfo
276
- * @returns {Promise<void>}
277
- */
278
- addGlyphs(glyphData, { font: fontName, range }) {
279
- this.#fonts.add(fontName);
280
- const name = (0, import_templates.getGlyphFilename)({ fontstack: fontName, range });
281
- return this.#append(glyphData, { name });
282
- }
283
- /**
284
- * Create a write stream for adding glyphs to the styled map package
285
- *
286
- * @param {object} opts
287
- * @param {number} [opts.concurrency=16] The number of concurrent writes
288
- * @returns
289
- */
290
- createGlyphWriteStream({ concurrency = 16 } = {}) {
291
- return (0, import_streams.writeStreamFromAsync)(this.addGlyphs.bind(this), { concurrency });
292
- }
293
- /**
294
- * Finalize the styled map package and write the style to the archive.
295
- * This method must be called to complete the archive.
296
- * You must wait for your destination write stream to 'finish' before using the output.
297
- */
298
- async finish() {
299
- this.#prepareStyle();
300
- const style = JSON.stringify(this.#style);
301
- await this.#append(style, { name: import_templates.STYLE_FILE });
302
- sortEntries(this.#archive);
303
- await this.#archive.finalize();
304
- }
305
- /**
306
- * Mutates the style object to prepare it for writing to the archive.
307
- * Deterministic: can be run more than once with the same result.
308
- */
309
- #prepareStyle() {
310
- if (this.#sources.size === 0) {
311
- throw new Error("Missing sources: add at least one source");
312
- }
313
- if (this.#style.glyphs && this.#fonts.size === 0) {
314
- throw new Error(
315
- "Missing fonts: style references glyphs but no fonts added"
316
- );
317
- }
318
- (0, import_style.replaceFontStacks)(this.#style, [...this.#fonts]);
319
- if (this.#style.glyphs) {
320
- this.#style.glyphs = import_templates.GLYPH_URI;
321
- }
322
- if (typeof this.#style.sprite === "string") {
323
- if (!this.#addedSpriteIds.has("default")) {
324
- throw new Error(
325
- "Missing sprite: style references sprite but none added"
326
- );
327
- }
328
- this.#style.sprite = (0, import_templates.getSpriteUri)();
329
- } else if (Array.isArray(this.#style.sprite)) {
330
- this.#style.sprite = this.#style.sprite.map(({ id }) => {
331
- if (!this.#addedSpriteIds.has(id)) {
332
- throw new Error(
333
- `Missing sprite: style references sprite ${id} but none added`
334
- );
335
- }
336
- return { id, url: (0, import_templates.getSpriteUri)(id) };
337
- });
338
- }
339
- this.#style.sources = {};
340
- for (const [sourceId, { source, encodedSourceId, format = "mvt" }] of this.#sources) {
341
- if (source.type === "geojson" && isEmptyFeatureCollection(source.data)) {
342
- continue;
343
- }
344
- this.#style.sources[sourceId] = source;
345
- if (!("tiles" in source)) continue;
346
- source.tiles = [(0, import_templates.getTileUri)({ sourceId: encodedSourceId, format })];
347
- }
348
- this.#style.layers = this.#style.layers.filter(
349
- (layer) => !("source" in layer) || !!this.#style.sources[layer.source]
350
- );
351
- const metadata = this.#style.metadata || (this.#style.metadata = {});
352
- const bounds = this.#getBounds();
353
- if (bounds) {
354
- metadata["smp:bounds"] = bounds;
355
- const [w, s, e, n] = bounds;
356
- this.#style.center = [w + (e - w) / 2, s + (n - s) / 2];
357
- }
358
- metadata["smp:maxzoom"] = this.#getMaxZoom();
359
- metadata["smp:sourceFolders"] = {};
360
- for (const [sourceId, { encodedSourceId }] of this.#sources) {
361
- metadata["smp:sourceFolders"][sourceId] = encodedSourceId;
362
- }
363
- this.#style.zoom = Math.max(0, this.#getMaxZoom() - 2);
364
- }
365
- /**
366
- *
367
- * @param {Source} source
368
- * @param {{ name: string, store?: boolean }} options
369
- * @returns {Promise<void>}
370
- */
371
- async #append(source, { name, store = false }) {
372
- if (this.#addedFiles.has(name)) {
373
- throw new Error(`${name} already added`);
374
- }
375
- this.#addedFiles.add(name);
376
- const onAdded = (0, import_p_event.pEvent)(
377
- this.#archive,
378
- "entry",
379
- (entry) => entry.name === name
380
- );
381
- this.#archive.append(convertSource(source), { name, store });
382
- await onAdded;
383
- }
384
- }
385
- function encodeSourceId(sourceIndex) {
386
- return sourceIndex.toString(36);
387
- }
388
- function convertSource(source) {
389
- return !Buffer.isBuffer(source) && source instanceof Uint8Array ? Buffer.from(source.buffer, source.byteOffset, source.length) : source;
390
- }
391
- function isEmptyFeatureCollection(data) {
392
- return data.type === "FeatureCollection" && data.features.length === 0;
393
- }
394
- function get2DBBox(bbox2) {
395
- if (bbox2.length === 4) return bbox2;
396
- return [bbox2[0], bbox2[1], bbox2[3], bbox2[4]];
397
- }
398
- function sortEntries(archive) {
399
- const entries = (
400
- /** @type {unknown} */
401
- archive._module?.engine?._entries
402
- );
403
- if (!Array.isArray(entries)) {
404
- throw new Error(
405
- "Cannot find zip entries: check implementation changes in Archiver"
406
- );
407
- }
408
- const sortedEntries = entries.sort(
409
- /**
410
- * @param {unknown} a
411
- * @param {unknown} b
412
- */
413
- function(a, b) {
414
- assertValidEntry(a);
415
- assertValidEntry(b);
416
- if (a.name === "style.json") return -1;
417
- if (b.name === "style.json") return 1;
418
- const foldersA = a.name.split("/");
419
- const foldersB = b.name.split("/");
420
- if (foldersA[0] === import_templates.FONTS_FOLDER && foldersA[2] === "0-255.pbf.gz")
421
- return -1;
422
- if (foldersB[0] === import_templates.FONTS_FOLDER && foldersB[2] === "0-255.pbf.gz")
423
- return 1;
424
- if (foldersA[0] === import_templates.SOURCES_FOLDER && foldersB[0] !== import_templates.SOURCES_FOLDER)
425
- return -1;
426
- if (foldersB[0] === import_templates.SOURCES_FOLDER && foldersA[0] !== import_templates.SOURCES_FOLDER)
427
- return 1;
428
- if (foldersA[0] === import_templates.SOURCES_FOLDER && foldersB[0] === import_templates.SOURCES_FOLDER) {
429
- const zoomA = +foldersA[2];
430
- const zoomB = +foldersB[2];
431
- return zoomA - zoomB;
432
- }
433
- return 0;
434
- }
435
- );
436
- archive._module.engine._entries = sortedEntries;
437
- }
438
- function assertValidEntry(maybeEntry) {
439
- if (!maybeEntry || typeof maybeEntry !== "object" || !("name" in maybeEntry) || typeof maybeEntry.name !== "string") {
440
- throw new Error(
441
- "Unexpected zip entry type: check implementation changes in Archiver"
442
- );
443
- }
444
- }
445
- // Annotate the CommonJS export names for ESM import in node:
446
- 0 && (module.exports = {
447
- SUPPORTED_SOURCE_TYPES,
448
- Writer
449
- });
package/dist/writer.d.cts DELETED
@@ -1,7 +0,0 @@
1
- export { G as GlyphInfo, d as GlyphRange, e as SUPPORTED_SOURCE_TYPES, f as Source, g as SourceInfo, h as SourceInternal, c as TileFormat, T as TileInfo, W as Writer, Z as ZipEntry } from './types-yLQy3AKR.cjs';
2
- import 'readable-stream';
3
- import 'stream';
4
- import 'events';
5
- import '@maplibre/maplibre-gl-style-spec';
6
- import 'geojson';
7
- import 'type-fest';