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.
- package/README.md +47 -7
- package/bin/smp-download.js +27 -151
- package/bin/smp-mbtiles.js +12 -7
- package/bin/smp-view.js +32 -54
- package/lib/commands/download.js +188 -0
- package/lib/commands/mbtiles.js +21 -0
- package/lib/commands/view.js +57 -0
- package/lib/reporters.js +92 -0
- package/package.json +9 -181
- package/LICENSE.md +0 -7
- package/dist/download.cjs +0 -101
- package/dist/download.d.cts +0 -65
- package/dist/download.d.ts +0 -65
- package/dist/download.js +0 -77
- package/dist/from-mbtiles.cjs +0 -91
- package/dist/from-mbtiles.d.cts +0 -17
- package/dist/from-mbtiles.d.ts +0 -17
- package/dist/from-mbtiles.js +0 -57
- package/dist/index.cjs +0 -49
- package/dist/index.d.cts +0 -27
- package/dist/index.d.ts +0 -27
- package/dist/index.js +0 -18
- package/dist/reader-watch.cjs +0 -135
- package/dist/reader-watch.d.cts +0 -24
- package/dist/reader-watch.d.ts +0 -24
- package/dist/reader-watch.js +0 -101
- package/dist/reader.cjs +0 -168
- package/dist/reader.d.cts +0 -62
- package/dist/reader.d.ts +0 -62
- package/dist/reader.js +0 -139
- package/dist/reporters.cjs +0 -122
- package/dist/reporters.d.cts +0 -10
- package/dist/reporters.d.ts +0 -10
- package/dist/reporters.js +0 -88
- package/dist/server.cjs +0 -78
- package/dist/server.d.cts +0 -48
- package/dist/server.d.ts +0 -48
- package/dist/server.js +0 -54
- package/dist/style-downloader.cjs +0 -312
- package/dist/style-downloader.d.cts +0 -120
- package/dist/style-downloader.d.ts +0 -120
- package/dist/style-downloader.js +0 -288
- package/dist/tile-downloader.cjs +0 -158
- package/dist/tile-downloader.d.cts +0 -84
- package/dist/tile-downloader.d.ts +0 -84
- package/dist/tile-downloader.js +0 -126
- package/dist/types-yLQy3AKR.d.cts +0 -192
- package/dist/types-yLQy3AKR.d.ts +0 -192
- package/dist/utils/errors.cjs +0 -41
- package/dist/utils/errors.d.cts +0 -18
- package/dist/utils/errors.d.ts +0 -18
- package/dist/utils/errors.js +0 -16
- package/dist/utils/fetch.cjs +0 -96
- package/dist/utils/fetch.d.cts +0 -51
- package/dist/utils/fetch.d.ts +0 -51
- package/dist/utils/fetch.js +0 -62
- package/dist/utils/file-formats.cjs +0 -98
- package/dist/utils/file-formats.d.cts +0 -35
- package/dist/utils/file-formats.d.ts +0 -35
- package/dist/utils/file-formats.js +0 -62
- package/dist/utils/geo.cjs +0 -84
- package/dist/utils/geo.d.cts +0 -46
- package/dist/utils/geo.d.ts +0 -46
- package/dist/utils/geo.js +0 -56
- package/dist/utils/mapbox.cjs +0 -121
- package/dist/utils/mapbox.d.cts +0 -43
- package/dist/utils/mapbox.d.ts +0 -43
- package/dist/utils/mapbox.js +0 -91
- package/dist/utils/misc.cjs +0 -39
- package/dist/utils/misc.d.cts +0 -22
- package/dist/utils/misc.d.ts +0 -22
- package/dist/utils/misc.js +0 -13
- package/dist/utils/streams.cjs +0 -130
- package/dist/utils/streams.d.cts +0 -73
- package/dist/utils/streams.d.ts +0 -73
- package/dist/utils/streams.js +0 -103
- package/dist/utils/style.cjs +0 -126
- package/dist/utils/style.d.cts +0 -69
- package/dist/utils/style.d.ts +0 -69
- package/dist/utils/style.js +0 -98
- package/dist/utils/templates.cjs +0 -118
- package/dist/utils/templates.d.cts +0 -80
- package/dist/utils/templates.d.ts +0 -80
- package/dist/utils/templates.js +0 -81
- package/dist/writer.cjs +0 -449
- package/dist/writer.d.cts +0 -7
- package/dist/writer.d.ts +0 -7
- package/dist/writer.js +0 -424
- package/node_modules/@node-rs/crc32/LICENSE +0 -21
- package/node_modules/@node-rs/crc32/README.md +0 -61
- package/node_modules/@node-rs/crc32/browser.js +0 -1
- package/node_modules/@node-rs/crc32/index.d.ts +0 -5
- package/node_modules/@node-rs/crc32/index.js +0 -368
- package/node_modules/@node-rs/crc32/package.json +0 -97
- package/node_modules/@node-rs/crc32-linux-x64-gnu/README.md +0 -3
- package/node_modules/@node-rs/crc32-linux-x64-gnu/crc32.linux-x64-gnu.node +0 -0
- package/node_modules/@node-rs/crc32-linux-x64-gnu/package.json +0 -43
- package/node_modules/@node-rs/crc32-linux-x64-musl/README.md +0 -3
- package/node_modules/@node-rs/crc32-linux-x64-musl/crc32.linux-x64-musl.node +0 -0
- package/node_modules/@node-rs/crc32-linux-x64-musl/package.json +0 -43
- package/node_modules/define-data-property/.eslintrc +0 -24
- package/node_modules/define-data-property/.github/FUNDING.yml +0 -12
- package/node_modules/define-data-property/.nycrc +0 -13
- package/node_modules/define-data-property/CHANGELOG.md +0 -70
- package/node_modules/define-data-property/LICENSE +0 -21
- package/node_modules/define-data-property/README.md +0 -67
- package/node_modules/define-data-property/index.d.ts +0 -12
- package/node_modules/define-data-property/index.js +0 -56
- package/node_modules/define-data-property/package.json +0 -106
- package/node_modules/define-data-property/test/index.js +0 -392
- package/node_modules/define-data-property/tsconfig.json +0 -59
- package/node_modules/define-properties/.editorconfig +0 -13
- package/node_modules/define-properties/.eslintrc +0 -19
- package/node_modules/define-properties/.github/FUNDING.yml +0 -12
- package/node_modules/define-properties/.nycrc +0 -9
- package/node_modules/define-properties/CHANGELOG.md +0 -91
- package/node_modules/define-properties/LICENSE +0 -21
- package/node_modules/define-properties/README.md +0 -84
- package/node_modules/define-properties/index.js +0 -47
- package/node_modules/define-properties/package.json +0 -88
- package/node_modules/es-define-property/.eslintrc +0 -13
- package/node_modules/es-define-property/.github/FUNDING.yml +0 -12
- package/node_modules/es-define-property/.nycrc +0 -9
- package/node_modules/es-define-property/CHANGELOG.md +0 -29
- package/node_modules/es-define-property/LICENSE +0 -21
- package/node_modules/es-define-property/README.md +0 -49
- package/node_modules/es-define-property/index.d.ts +0 -3
- package/node_modules/es-define-property/index.js +0 -14
- package/node_modules/es-define-property/package.json +0 -81
- package/node_modules/es-define-property/test/index.js +0 -56
- package/node_modules/es-define-property/tsconfig.json +0 -10
- package/node_modules/es-errors/.eslintrc +0 -5
- package/node_modules/es-errors/.github/FUNDING.yml +0 -12
- package/node_modules/es-errors/CHANGELOG.md +0 -40
- package/node_modules/es-errors/LICENSE +0 -21
- package/node_modules/es-errors/README.md +0 -55
- package/node_modules/es-errors/eval.d.ts +0 -3
- package/node_modules/es-errors/eval.js +0 -4
- package/node_modules/es-errors/index.d.ts +0 -3
- package/node_modules/es-errors/index.js +0 -4
- package/node_modules/es-errors/package.json +0 -80
- package/node_modules/es-errors/range.d.ts +0 -3
- package/node_modules/es-errors/range.js +0 -4
- package/node_modules/es-errors/ref.d.ts +0 -3
- package/node_modules/es-errors/ref.js +0 -4
- package/node_modules/es-errors/syntax.d.ts +0 -3
- package/node_modules/es-errors/syntax.js +0 -4
- package/node_modules/es-errors/test/index.js +0 -19
- package/node_modules/es-errors/tsconfig.json +0 -49
- package/node_modules/es-errors/type.d.ts +0 -3
- package/node_modules/es-errors/type.js +0 -4
- package/node_modules/es-errors/uri.d.ts +0 -3
- package/node_modules/es-errors/uri.js +0 -4
- package/node_modules/globalthis/.eslintrc +0 -18
- package/node_modules/globalthis/.nycrc +0 -10
- package/node_modules/globalthis/CHANGELOG.md +0 -109
- package/node_modules/globalthis/LICENSE +0 -21
- package/node_modules/globalthis/README.md +0 -70
- package/node_modules/globalthis/auto.js +0 -3
- package/node_modules/globalthis/implementation.browser.js +0 -11
- package/node_modules/globalthis/implementation.js +0 -3
- package/node_modules/globalthis/index.js +0 -19
- package/node_modules/globalthis/package.json +0 -99
- package/node_modules/globalthis/polyfill.js +0 -10
- package/node_modules/globalthis/shim.js +0 -29
- package/node_modules/globalthis/test/implementation.js +0 -11
- package/node_modules/globalthis/test/index.js +0 -11
- package/node_modules/globalthis/test/native.js +0 -26
- package/node_modules/globalthis/test/shimmed.js +0 -29
- package/node_modules/globalthis/test/tests.js +0 -36
- package/node_modules/gopd/.eslintrc +0 -16
- package/node_modules/gopd/.github/FUNDING.yml +0 -12
- package/node_modules/gopd/CHANGELOG.md +0 -45
- package/node_modules/gopd/LICENSE +0 -21
- package/node_modules/gopd/README.md +0 -40
- package/node_modules/gopd/gOPD.d.ts +0 -1
- package/node_modules/gopd/gOPD.js +0 -4
- package/node_modules/gopd/index.d.ts +0 -5
- package/node_modules/gopd/index.js +0 -15
- package/node_modules/gopd/package.json +0 -77
- package/node_modules/gopd/test/index.js +0 -36
- package/node_modules/gopd/tsconfig.json +0 -9
- package/node_modules/has-property-descriptors/.eslintrc +0 -13
- package/node_modules/has-property-descriptors/.github/FUNDING.yml +0 -12
- package/node_modules/has-property-descriptors/.nycrc +0 -9
- package/node_modules/has-property-descriptors/CHANGELOG.md +0 -35
- package/node_modules/has-property-descriptors/LICENSE +0 -21
- package/node_modules/has-property-descriptors/README.md +0 -43
- package/node_modules/has-property-descriptors/index.js +0 -22
- package/node_modules/has-property-descriptors/package.json +0 -77
- package/node_modules/has-property-descriptors/test/index.js +0 -57
- package/node_modules/is-it-type/License +0 -19
- package/node_modules/is-it-type/README.md +0 -102
- package/node_modules/is-it-type/changelog.md +0 -239
- package/node_modules/is-it-type/dist/cjs/is-it-type.js +0 -173
- package/node_modules/is-it-type/dist/cjs/is-it-type.js.map +0 -1
- package/node_modules/is-it-type/dist/cjs/is-it-type.min.js +0 -2
- package/node_modules/is-it-type/dist/cjs/is-it-type.min.js.map +0 -1
- package/node_modules/is-it-type/dist/esm/is-it-type.js +0 -143
- package/node_modules/is-it-type/dist/esm/is-it-type.js.map +0 -1
- package/node_modules/is-it-type/dist/esm/is-it-type.min.js +0 -2
- package/node_modules/is-it-type/dist/esm/is-it-type.min.js.map +0 -1
- package/node_modules/is-it-type/dist/esm/package.json +0 -3
- package/node_modules/is-it-type/dist/umd/is-it-type.js +0 -450
- package/node_modules/is-it-type/dist/umd/is-it-type.js.map +0 -1
- package/node_modules/is-it-type/dist/umd/is-it-type.min.js +0 -2
- package/node_modules/is-it-type/dist/umd/is-it-type.min.js.map +0 -1
- package/node_modules/is-it-type/es/index.js +0 -8
- package/node_modules/is-it-type/es/package.json +0 -3
- package/node_modules/is-it-type/index.js +0 -10
- package/node_modules/is-it-type/package.json +0 -87
- package/node_modules/is-it-type/src/index.js +0 -169
- package/node_modules/object-keys/.editorconfig +0 -13
- package/node_modules/object-keys/.eslintrc +0 -17
- package/node_modules/object-keys/.travis.yml +0 -277
- package/node_modules/object-keys/CHANGELOG.md +0 -232
- package/node_modules/object-keys/LICENSE +0 -21
- package/node_modules/object-keys/README.md +0 -76
- package/node_modules/object-keys/implementation.js +0 -122
- package/node_modules/object-keys/index.js +0 -32
- package/node_modules/object-keys/isArguments.js +0 -17
- package/node_modules/object-keys/package.json +0 -88
- package/node_modules/object-keys/test/index.js +0 -5
- package/node_modules/simple-invariant/License +0 -19
- package/node_modules/simple-invariant/README.md +0 -64
- package/node_modules/simple-invariant/changelog.md +0 -31
- package/node_modules/simple-invariant/index.js +0 -19
- package/node_modules/simple-invariant/package.json +0 -50
- package/node_modules/yauzl-promise/License +0 -19
- package/node_modules/yauzl-promise/README.md +0 -440
- package/node_modules/yauzl-promise/index.js +0 -10
- package/node_modules/yauzl-promise/lib/entry.js +0 -312
- package/node_modules/yauzl-promise/lib/index.js +0 -160
- package/node_modules/yauzl-promise/lib/reader.js +0 -289
- package/node_modules/yauzl-promise/lib/shared.js +0 -20
- package/node_modules/yauzl-promise/lib/utils.js +0 -105
- package/node_modules/yauzl-promise/lib/zip.js +0 -1224
- package/node_modules/yauzl-promise/package.json +0 -56
package/dist/writer.d.ts
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.js';
|
|
2
|
-
import 'readable-stream';
|
|
3
|
-
import 'stream';
|
|
4
|
-
import 'events';
|
|
5
|
-
import '@maplibre/maplibre-gl-style-spec';
|
|
6
|
-
import 'geojson';
|
|
7
|
-
import 'type-fest';
|
package/dist/writer.js
DELETED
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
import { validateStyleMin, migrate } from "@maplibre/maplibre-gl-style-spec";
|
|
2
|
-
import { bbox } from "@turf/bbox";
|
|
3
|
-
import archiver from "archiver";
|
|
4
|
-
import { EventEmitter } from "events";
|
|
5
|
-
import { excludeKeys } from "filter-obj";
|
|
6
|
-
import fs from "fs";
|
|
7
|
-
import { pEvent } from "p-event";
|
|
8
|
-
import { PassThrough, pipeline } from "readable-stream";
|
|
9
|
-
import { Readable } from "stream";
|
|
10
|
-
import { getTileFormatFromStream } from "./utils/file-formats.js";
|
|
11
|
-
import { MAX_BOUNDS, tileToBBox, unionBBox } from "./utils/geo.js";
|
|
12
|
-
import { clone } from "./utils/misc.js";
|
|
13
|
-
import { writeStreamFromAsync } from "./utils/streams.js";
|
|
14
|
-
import { replaceFontStacks } from "./utils/style.js";
|
|
15
|
-
import {
|
|
16
|
-
FONTS_FOLDER,
|
|
17
|
-
getGlyphFilename,
|
|
18
|
-
getSpriteFilename,
|
|
19
|
-
getSpriteUri,
|
|
20
|
-
getTileFilename,
|
|
21
|
-
getTileUri,
|
|
22
|
-
GLYPH_URI,
|
|
23
|
-
SOURCES_FOLDER,
|
|
24
|
-
STYLE_FILE
|
|
25
|
-
} from "./utils/templates.js";
|
|
26
|
-
const SUPPORTED_SOURCE_TYPES = (
|
|
27
|
-
/** @type {const} */
|
|
28
|
-
[
|
|
29
|
-
"raster",
|
|
30
|
-
"vector",
|
|
31
|
-
"geojson"
|
|
32
|
-
]
|
|
33
|
-
);
|
|
34
|
-
class Writer extends EventEmitter {
|
|
35
|
-
#archive = archiver("zip", { zlib: { level: 9 } }).setMaxListeners(Infinity).on("error", console.error);
|
|
36
|
-
/** @type {Set<string>} */
|
|
37
|
-
#addedFiles = /* @__PURE__ */ new Set();
|
|
38
|
-
/** @type {Set<string>} */
|
|
39
|
-
#fonts = /* @__PURE__ */ new Set();
|
|
40
|
-
/** @type {Set<string>} */
|
|
41
|
-
#addedSpriteIds = /* @__PURE__ */ new Set();
|
|
42
|
-
/** @type {Map<string, SourceInfo>} */
|
|
43
|
-
#sources = /* @__PURE__ */ new Map();
|
|
44
|
-
/** @type {StyleSpecification} */
|
|
45
|
-
#style;
|
|
46
|
-
#outputStream;
|
|
47
|
-
static SUPPORTED_SOURCE_TYPES = SUPPORTED_SOURCE_TYPES;
|
|
48
|
-
/**
|
|
49
|
-
* @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to
|
|
50
|
-
* v8. (There are currently no typescript declarations for v7 styles, hence
|
|
51
|
-
* this is typed as `any` and validated internally)
|
|
52
|
-
* @param {object} opts
|
|
53
|
-
* @param {number} [opts.highWaterMark=1048576] The maximum number of bytes to buffer during write
|
|
54
|
-
*/
|
|
55
|
-
constructor(style, { highWaterMark = 1024 * 1024 } = {}) {
|
|
56
|
-
super();
|
|
57
|
-
if (!style || !("version" in style)) {
|
|
58
|
-
throw new Error("Invalid style");
|
|
59
|
-
}
|
|
60
|
-
if (style.version !== 7 && style.version !== 8) {
|
|
61
|
-
throw new Error(`Invalid style: Unsupported version v${style.version}`);
|
|
62
|
-
}
|
|
63
|
-
if (!Array.isArray(style.layers)) {
|
|
64
|
-
throw new Error("Invalid style: missing layers property");
|
|
65
|
-
}
|
|
66
|
-
const styleCopy = clone(style);
|
|
67
|
-
migrate(styleCopy);
|
|
68
|
-
const errors = validateStyleMin(styleCopy);
|
|
69
|
-
if (errors.length) {
|
|
70
|
-
throw new AggregateError(errors, "Invalid style");
|
|
71
|
-
}
|
|
72
|
-
this.#style = styleCopy;
|
|
73
|
-
for (const [sourceId, source] of Object.entries(this.#style.sources)) {
|
|
74
|
-
if (source.type !== "geojson") continue;
|
|
75
|
-
this.#addSource(sourceId, source);
|
|
76
|
-
}
|
|
77
|
-
this.#outputStream = new PassThrough({ highWaterMark });
|
|
78
|
-
pipeline(this.#archive, this.#outputStream, (err) => {
|
|
79
|
-
if (err) this.emit("error", err);
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @returns {import('stream').Readable} Readable stream of the styled map package
|
|
84
|
-
*/
|
|
85
|
-
get outputStream() {
|
|
86
|
-
return this.#outputStream;
|
|
87
|
-
}
|
|
88
|
-
#getBounds() {
|
|
89
|
-
let bounds;
|
|
90
|
-
let maxzoom = 0;
|
|
91
|
-
for (const { source } of this.#sources.values()) {
|
|
92
|
-
if (source.type === "geojson") {
|
|
93
|
-
if (isEmptyFeatureCollection(source.data)) continue;
|
|
94
|
-
const bbox2 = get2DBBox(source.data.bbox);
|
|
95
|
-
bounds = bounds ? unionBBox([bounds, bbox2]) : [...bbox2];
|
|
96
|
-
} else {
|
|
97
|
-
if (source.maxzoom < maxzoom) continue;
|
|
98
|
-
if (source.maxzoom === maxzoom) {
|
|
99
|
-
bounds = bounds ? unionBBox([bounds, source.bounds]) : source.bounds;
|
|
100
|
-
} else {
|
|
101
|
-
bounds = source.bounds;
|
|
102
|
-
maxzoom = source.maxzoom;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return bounds;
|
|
107
|
-
}
|
|
108
|
-
#getMaxZoom() {
|
|
109
|
-
let maxzoom = 0;
|
|
110
|
-
for (const { source } of this.#sources.values()) {
|
|
111
|
-
const sourceMaxzoom = (
|
|
112
|
-
// For GeoJSON sources, the maxzoom is 16 unless otherwise set
|
|
113
|
-
source.type === "geojson" ? source.maxzoom || 16 : source.maxzoom
|
|
114
|
-
);
|
|
115
|
-
maxzoom = Math.max(maxzoom, sourceMaxzoom);
|
|
116
|
-
}
|
|
117
|
-
return maxzoom;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Add a source definition to the styled map package
|
|
121
|
-
*
|
|
122
|
-
* @param {string} sourceId
|
|
123
|
-
* @param {InputSource} source
|
|
124
|
-
* @returns {SourceInfo}
|
|
125
|
-
*/
|
|
126
|
-
#addSource(sourceId, source) {
|
|
127
|
-
const encodedSourceId = encodeSourceId(this.#sources.size);
|
|
128
|
-
const tileSourceOverrides = {
|
|
129
|
-
minzoom: 0,
|
|
130
|
-
maxzoom: 0,
|
|
131
|
-
bounds: (
|
|
132
|
-
/** @type {import('./utils/geo.js').BBox} */
|
|
133
|
-
[...MAX_BOUNDS]
|
|
134
|
-
),
|
|
135
|
-
tiles: (
|
|
136
|
-
/** @type {string[]} */
|
|
137
|
-
[]
|
|
138
|
-
)
|
|
139
|
-
};
|
|
140
|
-
let smpSource;
|
|
141
|
-
switch (source.type) {
|
|
142
|
-
case "raster":
|
|
143
|
-
case "vector":
|
|
144
|
-
smpSource = {
|
|
145
|
-
...excludeKeys(source, ["tiles", "url"]),
|
|
146
|
-
...tileSourceOverrides
|
|
147
|
-
};
|
|
148
|
-
break;
|
|
149
|
-
case "geojson":
|
|
150
|
-
smpSource = {
|
|
151
|
-
...source,
|
|
152
|
-
maxzoom: 0,
|
|
153
|
-
data: typeof source.data !== "string" ? (
|
|
154
|
-
// Add a bbox property to the GeoJSON data if it doesn't already have one
|
|
155
|
-
{ ...source.data, bbox: source.data.bbox || bbox(source.data) }
|
|
156
|
-
) : (
|
|
157
|
-
// If GeoJSON data is referenced by a URL, start with an empty FeatureCollection
|
|
158
|
-
{
|
|
159
|
-
type: "FeatureCollection",
|
|
160
|
-
features: [],
|
|
161
|
-
bbox: [0, 0, 0, 0]
|
|
162
|
-
}
|
|
163
|
-
)
|
|
164
|
-
};
|
|
165
|
-
break;
|
|
166
|
-
}
|
|
167
|
-
const sourceInfo = {
|
|
168
|
-
source: smpSource,
|
|
169
|
-
encodedSourceId
|
|
170
|
-
};
|
|
171
|
-
this.#sources.set(sourceId, sourceInfo);
|
|
172
|
-
return sourceInfo;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Add a tile to the styled map package
|
|
176
|
-
*
|
|
177
|
-
* @param {Source} tileData
|
|
178
|
-
* @param {TileInfo} opts
|
|
179
|
-
*/
|
|
180
|
-
async addTile(tileData, { z, x, y, sourceId, format }) {
|
|
181
|
-
let sourceInfo = this.#sources.get(sourceId);
|
|
182
|
-
if (!sourceInfo) {
|
|
183
|
-
const source2 = this.#style.sources[sourceId];
|
|
184
|
-
if (!source2) {
|
|
185
|
-
throw new Error(`Source not referenced in style.json: ${sourceId}`);
|
|
186
|
-
}
|
|
187
|
-
if (source2.type !== "raster" && source2.type !== "vector") {
|
|
188
|
-
throw new Error(`Unsupported source type: ${source2.type}`);
|
|
189
|
-
}
|
|
190
|
-
sourceInfo = this.#addSource(sourceId, source2);
|
|
191
|
-
}
|
|
192
|
-
const { source, encodedSourceId } = sourceInfo;
|
|
193
|
-
if (source.type !== "raster" && source.type !== "vector") {
|
|
194
|
-
throw new Error(`Unsupported source type: ${source.type}`);
|
|
195
|
-
}
|
|
196
|
-
if (!format) {
|
|
197
|
-
const tileDataStream = typeof tileData === "string" ? fs.createReadStream(tileData) : tileData instanceof Uint8Array ? Readable.from(tileData) : tileData;
|
|
198
|
-
[format, tileData] = await getTileFormatFromStream(tileDataStream);
|
|
199
|
-
}
|
|
200
|
-
if (!sourceInfo.format) {
|
|
201
|
-
sourceInfo.format = format;
|
|
202
|
-
} else if (sourceInfo.format !== format) {
|
|
203
|
-
throw new Error(
|
|
204
|
-
`Tile format mismatch for source ${sourceId}: expected ${sourceInfo.format}, got ${format}`
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
const bbox2 = tileToBBox({ z, x, y });
|
|
208
|
-
if (z > source.maxzoom) {
|
|
209
|
-
source.maxzoom = z;
|
|
210
|
-
source.bounds = bbox2;
|
|
211
|
-
} else if (z === source.maxzoom) {
|
|
212
|
-
source.bounds = unionBBox([source.bounds, bbox2]);
|
|
213
|
-
}
|
|
214
|
-
const name = getTileFilename({ sourceId: encodedSourceId, z, x, y, format });
|
|
215
|
-
return this.#append(tileData, { name, store: true });
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Create a write stream for adding tiles to the styled map package
|
|
219
|
-
*
|
|
220
|
-
* @param {object} opts
|
|
221
|
-
* @param {number} [opts.concurrency=16] The number of concurrent writes
|
|
222
|
-
*
|
|
223
|
-
* @returns
|
|
224
|
-
*/
|
|
225
|
-
createTileWriteStream({ concurrency = 16 } = {}) {
|
|
226
|
-
return writeStreamFromAsync(this.addTile.bind(this), { concurrency });
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Add a sprite to the styled map package
|
|
230
|
-
*
|
|
231
|
-
* @param {object} options
|
|
232
|
-
* @param {Source} options.json
|
|
233
|
-
* @param {Source} options.png
|
|
234
|
-
* @param {number} [options.pixelRatio]
|
|
235
|
-
* @param {string} [options.id='default']
|
|
236
|
-
* @returns {Promise<void>}
|
|
237
|
-
*/
|
|
238
|
-
async addSprite({ json, png, pixelRatio = 1, id = "default" }) {
|
|
239
|
-
this.#addedSpriteIds.add(id);
|
|
240
|
-
const jsonName = getSpriteFilename({ id, pixelRatio, ext: ".json" });
|
|
241
|
-
const pngName = getSpriteFilename({ id, pixelRatio, ext: ".png" });
|
|
242
|
-
await Promise.all([
|
|
243
|
-
this.#append(json, { name: jsonName }),
|
|
244
|
-
this.#append(png, { name: pngName })
|
|
245
|
-
]);
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Add glyphs to the styled map package
|
|
249
|
-
*
|
|
250
|
-
* @param {Source} glyphData
|
|
251
|
-
* @param {GlyphInfo} glyphInfo
|
|
252
|
-
* @returns {Promise<void>}
|
|
253
|
-
*/
|
|
254
|
-
addGlyphs(glyphData, { font: fontName, range }) {
|
|
255
|
-
this.#fonts.add(fontName);
|
|
256
|
-
const name = getGlyphFilename({ fontstack: fontName, range });
|
|
257
|
-
return this.#append(glyphData, { name });
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Create a write stream for adding glyphs to the styled map package
|
|
261
|
-
*
|
|
262
|
-
* @param {object} opts
|
|
263
|
-
* @param {number} [opts.concurrency=16] The number of concurrent writes
|
|
264
|
-
* @returns
|
|
265
|
-
*/
|
|
266
|
-
createGlyphWriteStream({ concurrency = 16 } = {}) {
|
|
267
|
-
return writeStreamFromAsync(this.addGlyphs.bind(this), { concurrency });
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Finalize the styled map package and write the style to the archive.
|
|
271
|
-
* This method must be called to complete the archive.
|
|
272
|
-
* You must wait for your destination write stream to 'finish' before using the output.
|
|
273
|
-
*/
|
|
274
|
-
async finish() {
|
|
275
|
-
this.#prepareStyle();
|
|
276
|
-
const style = JSON.stringify(this.#style);
|
|
277
|
-
await this.#append(style, { name: STYLE_FILE });
|
|
278
|
-
sortEntries(this.#archive);
|
|
279
|
-
await this.#archive.finalize();
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* Mutates the style object to prepare it for writing to the archive.
|
|
283
|
-
* Deterministic: can be run more than once with the same result.
|
|
284
|
-
*/
|
|
285
|
-
#prepareStyle() {
|
|
286
|
-
if (this.#sources.size === 0) {
|
|
287
|
-
throw new Error("Missing sources: add at least one source");
|
|
288
|
-
}
|
|
289
|
-
if (this.#style.glyphs && this.#fonts.size === 0) {
|
|
290
|
-
throw new Error(
|
|
291
|
-
"Missing fonts: style references glyphs but no fonts added"
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
replaceFontStacks(this.#style, [...this.#fonts]);
|
|
295
|
-
if (this.#style.glyphs) {
|
|
296
|
-
this.#style.glyphs = GLYPH_URI;
|
|
297
|
-
}
|
|
298
|
-
if (typeof this.#style.sprite === "string") {
|
|
299
|
-
if (!this.#addedSpriteIds.has("default")) {
|
|
300
|
-
throw new Error(
|
|
301
|
-
"Missing sprite: style references sprite but none added"
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
this.#style.sprite = getSpriteUri();
|
|
305
|
-
} else if (Array.isArray(this.#style.sprite)) {
|
|
306
|
-
this.#style.sprite = this.#style.sprite.map(({ id }) => {
|
|
307
|
-
if (!this.#addedSpriteIds.has(id)) {
|
|
308
|
-
throw new Error(
|
|
309
|
-
`Missing sprite: style references sprite ${id} but none added`
|
|
310
|
-
);
|
|
311
|
-
}
|
|
312
|
-
return { id, url: getSpriteUri(id) };
|
|
313
|
-
});
|
|
314
|
-
}
|
|
315
|
-
this.#style.sources = {};
|
|
316
|
-
for (const [sourceId, { source, encodedSourceId, format = "mvt" }] of this.#sources) {
|
|
317
|
-
if (source.type === "geojson" && isEmptyFeatureCollection(source.data)) {
|
|
318
|
-
continue;
|
|
319
|
-
}
|
|
320
|
-
this.#style.sources[sourceId] = source;
|
|
321
|
-
if (!("tiles" in source)) continue;
|
|
322
|
-
source.tiles = [getTileUri({ sourceId: encodedSourceId, format })];
|
|
323
|
-
}
|
|
324
|
-
this.#style.layers = this.#style.layers.filter(
|
|
325
|
-
(layer) => !("source" in layer) || !!this.#style.sources[layer.source]
|
|
326
|
-
);
|
|
327
|
-
const metadata = this.#style.metadata || (this.#style.metadata = {});
|
|
328
|
-
const bounds = this.#getBounds();
|
|
329
|
-
if (bounds) {
|
|
330
|
-
metadata["smp:bounds"] = bounds;
|
|
331
|
-
const [w, s, e, n] = bounds;
|
|
332
|
-
this.#style.center = [w + (e - w) / 2, s + (n - s) / 2];
|
|
333
|
-
}
|
|
334
|
-
metadata["smp:maxzoom"] = this.#getMaxZoom();
|
|
335
|
-
metadata["smp:sourceFolders"] = {};
|
|
336
|
-
for (const [sourceId, { encodedSourceId }] of this.#sources) {
|
|
337
|
-
metadata["smp:sourceFolders"][sourceId] = encodedSourceId;
|
|
338
|
-
}
|
|
339
|
-
this.#style.zoom = Math.max(0, this.#getMaxZoom() - 2);
|
|
340
|
-
}
|
|
341
|
-
/**
|
|
342
|
-
*
|
|
343
|
-
* @param {Source} source
|
|
344
|
-
* @param {{ name: string, store?: boolean }} options
|
|
345
|
-
* @returns {Promise<void>}
|
|
346
|
-
*/
|
|
347
|
-
async #append(source, { name, store = false }) {
|
|
348
|
-
if (this.#addedFiles.has(name)) {
|
|
349
|
-
throw new Error(`${name} already added`);
|
|
350
|
-
}
|
|
351
|
-
this.#addedFiles.add(name);
|
|
352
|
-
const onAdded = pEvent(
|
|
353
|
-
this.#archive,
|
|
354
|
-
"entry",
|
|
355
|
-
(entry) => entry.name === name
|
|
356
|
-
);
|
|
357
|
-
this.#archive.append(convertSource(source), { name, store });
|
|
358
|
-
await onAdded;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function encodeSourceId(sourceIndex) {
|
|
362
|
-
return sourceIndex.toString(36);
|
|
363
|
-
}
|
|
364
|
-
function convertSource(source) {
|
|
365
|
-
return !Buffer.isBuffer(source) && source instanceof Uint8Array ? Buffer.from(source.buffer, source.byteOffset, source.length) : source;
|
|
366
|
-
}
|
|
367
|
-
function isEmptyFeatureCollection(data) {
|
|
368
|
-
return data.type === "FeatureCollection" && data.features.length === 0;
|
|
369
|
-
}
|
|
370
|
-
function get2DBBox(bbox2) {
|
|
371
|
-
if (bbox2.length === 4) return bbox2;
|
|
372
|
-
return [bbox2[0], bbox2[1], bbox2[3], bbox2[4]];
|
|
373
|
-
}
|
|
374
|
-
function sortEntries(archive) {
|
|
375
|
-
const entries = (
|
|
376
|
-
/** @type {unknown} */
|
|
377
|
-
archive._module?.engine?._entries
|
|
378
|
-
);
|
|
379
|
-
if (!Array.isArray(entries)) {
|
|
380
|
-
throw new Error(
|
|
381
|
-
"Cannot find zip entries: check implementation changes in Archiver"
|
|
382
|
-
);
|
|
383
|
-
}
|
|
384
|
-
const sortedEntries = entries.sort(
|
|
385
|
-
/**
|
|
386
|
-
* @param {unknown} a
|
|
387
|
-
* @param {unknown} b
|
|
388
|
-
*/
|
|
389
|
-
function(a, b) {
|
|
390
|
-
assertValidEntry(a);
|
|
391
|
-
assertValidEntry(b);
|
|
392
|
-
if (a.name === "style.json") return -1;
|
|
393
|
-
if (b.name === "style.json") return 1;
|
|
394
|
-
const foldersA = a.name.split("/");
|
|
395
|
-
const foldersB = b.name.split("/");
|
|
396
|
-
if (foldersA[0] === FONTS_FOLDER && foldersA[2] === "0-255.pbf.gz")
|
|
397
|
-
return -1;
|
|
398
|
-
if (foldersB[0] === FONTS_FOLDER && foldersB[2] === "0-255.pbf.gz")
|
|
399
|
-
return 1;
|
|
400
|
-
if (foldersA[0] === SOURCES_FOLDER && foldersB[0] !== SOURCES_FOLDER)
|
|
401
|
-
return -1;
|
|
402
|
-
if (foldersB[0] === SOURCES_FOLDER && foldersA[0] !== SOURCES_FOLDER)
|
|
403
|
-
return 1;
|
|
404
|
-
if (foldersA[0] === SOURCES_FOLDER && foldersB[0] === SOURCES_FOLDER) {
|
|
405
|
-
const zoomA = +foldersA[2];
|
|
406
|
-
const zoomB = +foldersB[2];
|
|
407
|
-
return zoomA - zoomB;
|
|
408
|
-
}
|
|
409
|
-
return 0;
|
|
410
|
-
}
|
|
411
|
-
);
|
|
412
|
-
archive._module.engine._entries = sortedEntries;
|
|
413
|
-
}
|
|
414
|
-
function assertValidEntry(maybeEntry) {
|
|
415
|
-
if (!maybeEntry || typeof maybeEntry !== "object" || !("name" in maybeEntry) || typeof maybeEntry.name !== "string") {
|
|
416
|
-
throw new Error(
|
|
417
|
-
"Unexpected zip entry type: check implementation changes in Archiver"
|
|
418
|
-
);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
export {
|
|
422
|
-
SUPPORTED_SOURCE_TYPES,
|
|
423
|
-
Writer
|
|
424
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020-present LongYinan
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
# `@node-rs/crc32`
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-
|
|
6
|
-
Fastest `crc32` implement in `Node.js`
|
|
7
|
-
|
|
8
|
-
The 4 tested implementations are:
|
|
9
|
-
|
|
10
|
-
- **@node-rs/crc32** Hardware accelerated CRC-32C from [crc32fast](https://crates.io/crates/crc32fast)
|
|
11
|
-
- **sse4_crc32c** Hardware accelerated CRC-32C from [sse4_crc32](https://github.com/Voxer/sse4_crc32)
|
|
12
|
-
- **js_crc32c** Javascript implemented CRC-32C
|
|
13
|
-
- **js_crc32** Javascript implemented CRC-32 from [buffer-crc32](https://github.com/brianloveswords/buffer-crc32)
|
|
14
|
-
|
|
15
|
-
## Performance
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
@node-rs/crc32 for inputs 1024B x 5,108,123 ops/sec ±1.86% (89 runs sampled)
|
|
19
|
-
@node-rs/crc32 for inputs 16931844B, avg 2066B x 271 ops/sec ±1.15% (85 runs sampled)
|
|
20
|
-
sse4_crc32c_hw for inputs 1024B x 3,543,443 ops/sec ±1.39% (93 runs sampled)
|
|
21
|
-
sse4_crc32c_hw for inputs 16931844B, avg 2066B x 209 ops/sec ±0.78% (76 runs sampled)
|
|
22
|
-
sse4_crc32c_sw for inputs 1024B x 1,460,284 ops/sec ±2.35% (90 runs sampled)
|
|
23
|
-
sse4_crc32c_sw for inputs 16931844B, avg 2066B x 93.50 ops/sec ±2.43% (69 runs sampled)
|
|
24
|
-
js_crc32c for inputs 1024B x 464,681 ops/sec ±0.46% (91 runs sampled)
|
|
25
|
-
js_crc32c for inputs 16931844B, avg 2066B x 28.25 ops/sec ±1.64% (51 runs sampled)
|
|
26
|
-
js_crc32 for inputs 1024B x 442,272 ops/sec ±2.66% (93 runs sampled)
|
|
27
|
-
js_crc32 for inputs 16931844B, avg 2066B x 22.12 ops/sec ±5.20% (40 runs sampled)
|
|
28
|
-
+---------------------+-------------------+----------------------+
|
|
29
|
-
| │ 1024B │ 16931844B, avg 2066B |
|
|
30
|
-
+---------------------+-------------------+----------------------+
|
|
31
|
-
| @node-rs/crc32 │ 5,108,123 ops/sec │ 271 ops/sec |
|
|
32
|
-
+---------------------+-------------------+----------------------+
|
|
33
|
-
| sse4_crc32c_hw │ 3,543,443 ops/sec │ 209 ops/sec |
|
|
34
|
-
+---------------------+-------------------+----------------------+
|
|
35
|
-
| sse4_crc32c_sw │ 1,460,284 ops/sec │ 93.50 ops/sec |
|
|
36
|
-
+---------------------+-------------------+----------------------+
|
|
37
|
-
| js_crc32c │ 464,681 ops/sec │ 28.25 ops/sec |
|
|
38
|
-
+---------------------+-------------------+----------------------+
|
|
39
|
-
| js_crc32 │ 442,272 ops/sec │ 22.12 ops/sec |
|
|
40
|
-
+---------------------+-------------------+----------------------+
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## API
|
|
44
|
-
|
|
45
|
-
> The type of **input initial crc** and **output crc number** is `u32`
|
|
46
|
-
|
|
47
|
-
```ts
|
|
48
|
-
export function crc32(input: Buffer, crc?: number): number
|
|
49
|
-
export function crc32c(input: Buffer, crc?: number): number
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## Usage
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const { crc32 } = require('@node-rs/crc32')
|
|
56
|
-
const { readFileSync } = require('fs')
|
|
57
|
-
|
|
58
|
-
const content = readFileSync('./avatar.png')
|
|
59
|
-
|
|
60
|
-
crc32(content)
|
|
61
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@node-rs/crc32-wasm32-wasi'
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/* auto-generated by NAPI-RS */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
export declare function crc32(input: string | Uint8Array, initialState?: number | undefined | null): number
|
|
4
|
-
|
|
5
|
-
export declare function crc32c(input: string | Uint8Array, initialState?: number | undefined | null): number
|