styled-map-package-api 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.
- package/dist/download.cjs +100 -0
- package/dist/download.d.cts +64 -0
- package/dist/download.d.ts +64 -0
- package/dist/download.js +76 -0
- package/dist/from-mbtiles.cjs +81 -0
- package/dist/from-mbtiles.d.cts +10 -0
- package/dist/from-mbtiles.d.ts +10 -0
- package/dist/from-mbtiles.js +57 -0
- package/dist/index.cjs +46 -0
- package/dist/index.d.cts +25 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +16 -0
- package/dist/reader.cjs +287 -0
- package/dist/reader.d.cts +68 -0
- package/dist/reader.d.ts +68 -0
- package/dist/reader.js +259 -0
- package/dist/server.cjs +73 -0
- package/dist/server.d.cts +46 -0
- package/dist/server.d.ts +46 -0
- package/dist/server.js +49 -0
- package/dist/style-downloader.cjs +314 -0
- package/dist/style-downloader.d.cts +119 -0
- package/dist/style-downloader.d.ts +119 -0
- package/dist/style-downloader.js +290 -0
- package/dist/tile-downloader.cjs +156 -0
- package/dist/tile-downloader.d.cts +83 -0
- package/dist/tile-downloader.d.ts +83 -0
- package/dist/tile-downloader.js +124 -0
- package/dist/types-CJq90eOB.d.cts +184 -0
- package/dist/types-CJq90eOB.d.ts +184 -0
- package/dist/utils/errors.cjs +41 -0
- package/dist/utils/errors.d.cts +18 -0
- package/dist/utils/errors.d.ts +18 -0
- package/dist/utils/errors.js +16 -0
- package/dist/utils/fetch.cjs +97 -0
- package/dist/utils/fetch.d.cts +50 -0
- package/dist/utils/fetch.d.ts +50 -0
- package/dist/utils/fetch.js +63 -0
- package/dist/utils/file-formats.cjs +96 -0
- package/dist/utils/file-formats.d.cts +33 -0
- package/dist/utils/file-formats.d.ts +33 -0
- package/dist/utils/file-formats.js +70 -0
- package/dist/utils/geo.cjs +84 -0
- package/dist/utils/geo.d.cts +46 -0
- package/dist/utils/geo.d.ts +46 -0
- package/dist/utils/geo.js +56 -0
- package/dist/utils/mapbox.cjs +121 -0
- package/dist/utils/mapbox.d.cts +43 -0
- package/dist/utils/mapbox.d.ts +43 -0
- package/dist/utils/mapbox.js +91 -0
- package/dist/utils/misc.cjs +39 -0
- package/dist/utils/misc.d.cts +22 -0
- package/dist/utils/misc.d.ts +22 -0
- package/dist/utils/misc.js +13 -0
- package/dist/utils/streams.cjs +99 -0
- package/dist/utils/streams.d.cts +49 -0
- package/dist/utils/streams.d.ts +49 -0
- package/dist/utils/streams.js +73 -0
- package/dist/utils/style.cjs +126 -0
- package/dist/utils/style.d.cts +67 -0
- package/dist/utils/style.d.ts +67 -0
- package/dist/utils/style.js +98 -0
- package/dist/utils/templates.cjs +124 -0
- package/dist/utils/templates.d.cts +80 -0
- package/dist/utils/templates.d.ts +80 -0
- package/dist/utils/templates.js +85 -0
- package/dist/writer.cjs +465 -0
- package/dist/writer.d.cts +5 -0
- package/dist/writer.d.ts +5 -0
- package/dist/writer.js +452 -0
- package/package.json +161 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const r2d = 180 / Math.PI;
|
|
2
|
+
const MAX_BOUNDS = (
|
|
3
|
+
/** @type {BBox} */
|
|
4
|
+
[
|
|
5
|
+
-180,
|
|
6
|
+
-85.051129,
|
|
7
|
+
180,
|
|
8
|
+
85.051129
|
|
9
|
+
]
|
|
10
|
+
);
|
|
11
|
+
function tileToBBox({ x, y, z }) {
|
|
12
|
+
const e = tile2lon({ x: x + 1, z });
|
|
13
|
+
const w = tile2lon({ x, z });
|
|
14
|
+
const s = tile2lat({ y: y + 1, z });
|
|
15
|
+
const n = tile2lat({ y, z });
|
|
16
|
+
return [w, s, e, n];
|
|
17
|
+
}
|
|
18
|
+
function getQuadkey({ x, y, z }) {
|
|
19
|
+
let quadkey = "";
|
|
20
|
+
let mask;
|
|
21
|
+
for (let i = z; i > 0; i--) {
|
|
22
|
+
mask = 1 << i - 1;
|
|
23
|
+
quadkey += (x & mask ? 1 : 0) + (y & mask ? 2 : 0);
|
|
24
|
+
}
|
|
25
|
+
return quadkey;
|
|
26
|
+
}
|
|
27
|
+
function getTileUrl(urls, { x, y, z, scheme = "xyz" }) {
|
|
28
|
+
const bboxEspg3857 = tileToBBox({ x, y: Math.pow(2, z) - y - 1, z });
|
|
29
|
+
const quadkey = getQuadkey({ x, y, z });
|
|
30
|
+
return urls[(x + y) % urls.length].replace("{prefix}", (x % 16).toString(16) + (y % 16).toString(16)).replace(/{z}/g, String(z)).replace(/{x}/g, String(x)).replace(/{y}/g, String(scheme === "tms" ? Math.pow(2, z) - y - 1 : y)).replace("{quadkey}", quadkey).replace("{bbox-epsg-3857}", bboxEspg3857.join(","));
|
|
31
|
+
}
|
|
32
|
+
function unionBBox(bboxes) {
|
|
33
|
+
let [w, s, e, n] = bboxes[0];
|
|
34
|
+
for (let i = 1; i < bboxes.length; i++) {
|
|
35
|
+
const [w1, s1, e1, n1] = bboxes[i];
|
|
36
|
+
w = Math.min(w, w1);
|
|
37
|
+
s = Math.min(s, s1);
|
|
38
|
+
e = Math.max(e, e1);
|
|
39
|
+
n = Math.max(n, n1);
|
|
40
|
+
}
|
|
41
|
+
return [w, s, e, n];
|
|
42
|
+
}
|
|
43
|
+
function tile2lon({ x, z }) {
|
|
44
|
+
return x / Math.pow(2, z) * 360 - 180;
|
|
45
|
+
}
|
|
46
|
+
function tile2lat({ y, z }) {
|
|
47
|
+
const n = Math.PI - 2 * Math.PI * y / Math.pow(2, z);
|
|
48
|
+
return r2d * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
MAX_BOUNDS,
|
|
52
|
+
getQuadkey,
|
|
53
|
+
getTileUrl,
|
|
54
|
+
tileToBBox,
|
|
55
|
+
unionBBox
|
|
56
|
+
};
|
|
@@ -0,0 +1,121 @@
|
|
|
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 mapbox_exports = {};
|
|
20
|
+
__export(mapbox_exports, {
|
|
21
|
+
API_URL: () => API_URL,
|
|
22
|
+
isMapboxURL: () => isMapboxURL,
|
|
23
|
+
normalizeGlyphsURL: () => normalizeGlyphsURL,
|
|
24
|
+
normalizeSourceURL: () => normalizeSourceURL,
|
|
25
|
+
normalizeSpriteURL: () => normalizeSpriteURL,
|
|
26
|
+
normalizeStyleURL: () => normalizeStyleURL,
|
|
27
|
+
normalizeTileURL: () => normalizeTileURL
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(mapbox_exports);
|
|
30
|
+
const API_URL = "https://api.mapbox.com";
|
|
31
|
+
const HELP = "See https://www.mapbox.com/api-documentation/#access-tokens";
|
|
32
|
+
function makeAPIURL(urlObject, accessToken) {
|
|
33
|
+
const apiUrlObject = parseUrl(API_URL);
|
|
34
|
+
urlObject.protocol = apiUrlObject.protocol;
|
|
35
|
+
urlObject.authority = apiUrlObject.authority;
|
|
36
|
+
if (!accessToken) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`An API access token is required to use a Mapbox style. ${HELP}`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
if (accessToken[0] === "s") {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Use a public access token (pk.*) not a secret access token (sk.*). ${HELP}`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
urlObject.params.push(`access_token=${accessToken}`);
|
|
47
|
+
return formatUrl(urlObject);
|
|
48
|
+
}
|
|
49
|
+
function isMapboxURL(url) {
|
|
50
|
+
return url.indexOf("mapbox:") === 0;
|
|
51
|
+
}
|
|
52
|
+
function normalizeStyleURL(url, accessToken) {
|
|
53
|
+
if (!isMapboxURL(url)) return url;
|
|
54
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
55
|
+
const urlObject = parseUrl(url);
|
|
56
|
+
urlObject.path = `/styles/v1${urlObject.path}`;
|
|
57
|
+
return makeAPIURL(urlObject, accessToken);
|
|
58
|
+
}
|
|
59
|
+
function normalizeGlyphsURL(url, accessToken) {
|
|
60
|
+
if (!isMapboxURL(url)) return url;
|
|
61
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
62
|
+
const urlObject = parseUrl(url);
|
|
63
|
+
urlObject.path = `/fonts/v1${urlObject.path}`;
|
|
64
|
+
return makeAPIURL(urlObject, accessToken);
|
|
65
|
+
}
|
|
66
|
+
function normalizeSourceURL(url, accessToken) {
|
|
67
|
+
if (!isMapboxURL(url)) return url;
|
|
68
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
69
|
+
const urlObject = parseUrl(url);
|
|
70
|
+
urlObject.path = `/v4/${urlObject.authority}.json`;
|
|
71
|
+
urlObject.params.push("secure");
|
|
72
|
+
return makeAPIURL(urlObject, accessToken);
|
|
73
|
+
}
|
|
74
|
+
function normalizeSpriteURL(url, format, extension, accessToken) {
|
|
75
|
+
const urlObject = parseUrl(url);
|
|
76
|
+
if (!isMapboxURL(url)) {
|
|
77
|
+
urlObject.path += `${format}${extension}`;
|
|
78
|
+
return formatUrl(urlObject);
|
|
79
|
+
}
|
|
80
|
+
urlObject.path = `/styles/v1${urlObject.path}/sprite${format}${extension}`;
|
|
81
|
+
return makeAPIURL(urlObject, accessToken);
|
|
82
|
+
}
|
|
83
|
+
const imageExtensionRe = /(\.(png|jpg)\d*)(?=$)/;
|
|
84
|
+
function normalizeTileURL(tileURL, sourceURL, tileSize, { devicePixelRatio = 1, supportsWebp = false } = {}) {
|
|
85
|
+
if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;
|
|
86
|
+
const urlObject = parseUrl(tileURL);
|
|
87
|
+
const suffix = devicePixelRatio >= 2 || tileSize === 512 ? "@2x" : "";
|
|
88
|
+
const extension = supportsWebp ? ".webp" : "$1";
|
|
89
|
+
urlObject.path = urlObject.path.replace(
|
|
90
|
+
imageExtensionRe,
|
|
91
|
+
`${suffix}${extension}`
|
|
92
|
+
);
|
|
93
|
+
return formatUrl(urlObject);
|
|
94
|
+
}
|
|
95
|
+
const urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
|
|
96
|
+
function parseUrl(url) {
|
|
97
|
+
const parts = url.match(urlRe);
|
|
98
|
+
if (!parts) {
|
|
99
|
+
throw new Error("Unable to parse URL object");
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
protocol: parts[1],
|
|
103
|
+
authority: parts[2],
|
|
104
|
+
path: parts[3] || "/",
|
|
105
|
+
params: parts[4] ? parts[4].split("&") : []
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function formatUrl(obj) {
|
|
109
|
+
const params = obj.params.length ? `?${obj.params.join("&")}` : "";
|
|
110
|
+
return `${obj.protocol}://${obj.authority}${obj.path}${params}`;
|
|
111
|
+
}
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
API_URL,
|
|
115
|
+
isMapboxURL,
|
|
116
|
+
normalizeGlyphsURL,
|
|
117
|
+
normalizeSourceURL,
|
|
118
|
+
normalizeSpriteURL,
|
|
119
|
+
normalizeStyleURL,
|
|
120
|
+
normalizeTileURL
|
|
121
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @param {string} url */
|
|
2
|
+
declare function isMapboxURL(url: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @param {string} [accessToken]
|
|
6
|
+
*/
|
|
7
|
+
declare function normalizeStyleURL(url: string, accessToken?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} url
|
|
10
|
+
* @param {string} [accessToken]
|
|
11
|
+
*/
|
|
12
|
+
declare function normalizeGlyphsURL(url: string, accessToken?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {string} [accessToken]
|
|
16
|
+
*/
|
|
17
|
+
declare function normalizeSourceURL(url: string, accessToken?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @param {'' | '@2x'} format
|
|
21
|
+
* @param {'.png' | '.json'} extension
|
|
22
|
+
* @param {string} [accessToken]
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} tileURL
|
|
27
|
+
* @param {string} sourceURL
|
|
28
|
+
* @param {256 | 512} [tileSize]
|
|
29
|
+
* @param {{ devicePixelRatio?: number; supportsWebp?: boolean; }} [opts]
|
|
30
|
+
*/
|
|
31
|
+
declare function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
|
|
32
|
+
devicePixelRatio?: number;
|
|
33
|
+
supportsWebp?: boolean;
|
|
34
|
+
}): any;
|
|
35
|
+
declare const API_URL: "https://api.mapbox.com";
|
|
36
|
+
type URLObject = {
|
|
37
|
+
protocol: string;
|
|
38
|
+
authority: string;
|
|
39
|
+
path: string;
|
|
40
|
+
params: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { API_URL, type URLObject, isMapboxURL, normalizeGlyphsURL, normalizeSourceURL, normalizeSpriteURL, normalizeStyleURL, normalizeTileURL };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** @param {string} url */
|
|
2
|
+
declare function isMapboxURL(url: string): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} url
|
|
5
|
+
* @param {string} [accessToken]
|
|
6
|
+
*/
|
|
7
|
+
declare function normalizeStyleURL(url: string, accessToken?: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* @param {string} url
|
|
10
|
+
* @param {string} [accessToken]
|
|
11
|
+
*/
|
|
12
|
+
declare function normalizeGlyphsURL(url: string, accessToken?: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* @param {string} url
|
|
15
|
+
* @param {string} [accessToken]
|
|
16
|
+
*/
|
|
17
|
+
declare function normalizeSourceURL(url: string, accessToken?: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* @param {string} url
|
|
20
|
+
* @param {'' | '@2x'} format
|
|
21
|
+
* @param {'.png' | '.json'} extension
|
|
22
|
+
* @param {string} [accessToken]
|
|
23
|
+
*/
|
|
24
|
+
declare function normalizeSpriteURL(url: string, format: "" | "@2x", extension: ".png" | ".json", accessToken?: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* @param {any} tileURL
|
|
27
|
+
* @param {string} sourceURL
|
|
28
|
+
* @param {256 | 512} [tileSize]
|
|
29
|
+
* @param {{ devicePixelRatio?: number; supportsWebp?: boolean; }} [opts]
|
|
30
|
+
*/
|
|
31
|
+
declare function normalizeTileURL(tileURL: any, sourceURL: string, tileSize?: 256 | 512, { devicePixelRatio, supportsWebp }?: {
|
|
32
|
+
devicePixelRatio?: number;
|
|
33
|
+
supportsWebp?: boolean;
|
|
34
|
+
}): any;
|
|
35
|
+
declare const API_URL: "https://api.mapbox.com";
|
|
36
|
+
type URLObject = {
|
|
37
|
+
protocol: string;
|
|
38
|
+
authority: string;
|
|
39
|
+
path: string;
|
|
40
|
+
params: string[];
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { API_URL, type URLObject, isMapboxURL, normalizeGlyphsURL, normalizeSourceURL, normalizeSpriteURL, normalizeStyleURL, normalizeTileURL };
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
const API_URL = "https://api.mapbox.com";
|
|
2
|
+
const HELP = "See https://www.mapbox.com/api-documentation/#access-tokens";
|
|
3
|
+
function makeAPIURL(urlObject, accessToken) {
|
|
4
|
+
const apiUrlObject = parseUrl(API_URL);
|
|
5
|
+
urlObject.protocol = apiUrlObject.protocol;
|
|
6
|
+
urlObject.authority = apiUrlObject.authority;
|
|
7
|
+
if (!accessToken) {
|
|
8
|
+
throw new Error(
|
|
9
|
+
`An API access token is required to use a Mapbox style. ${HELP}`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
if (accessToken[0] === "s") {
|
|
13
|
+
throw new Error(
|
|
14
|
+
`Use a public access token (pk.*) not a secret access token (sk.*). ${HELP}`
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
urlObject.params.push(`access_token=${accessToken}`);
|
|
18
|
+
return formatUrl(urlObject);
|
|
19
|
+
}
|
|
20
|
+
function isMapboxURL(url) {
|
|
21
|
+
return url.indexOf("mapbox:") === 0;
|
|
22
|
+
}
|
|
23
|
+
function normalizeStyleURL(url, accessToken) {
|
|
24
|
+
if (!isMapboxURL(url)) return url;
|
|
25
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
26
|
+
const urlObject = parseUrl(url);
|
|
27
|
+
urlObject.path = `/styles/v1${urlObject.path}`;
|
|
28
|
+
return makeAPIURL(urlObject, accessToken);
|
|
29
|
+
}
|
|
30
|
+
function normalizeGlyphsURL(url, accessToken) {
|
|
31
|
+
if (!isMapboxURL(url)) return url;
|
|
32
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
33
|
+
const urlObject = parseUrl(url);
|
|
34
|
+
urlObject.path = `/fonts/v1${urlObject.path}`;
|
|
35
|
+
return makeAPIURL(urlObject, accessToken);
|
|
36
|
+
}
|
|
37
|
+
function normalizeSourceURL(url, accessToken) {
|
|
38
|
+
if (!isMapboxURL(url)) return url;
|
|
39
|
+
if (!accessToken) throw new Error("Mapbox styles require an access token");
|
|
40
|
+
const urlObject = parseUrl(url);
|
|
41
|
+
urlObject.path = `/v4/${urlObject.authority}.json`;
|
|
42
|
+
urlObject.params.push("secure");
|
|
43
|
+
return makeAPIURL(urlObject, accessToken);
|
|
44
|
+
}
|
|
45
|
+
function normalizeSpriteURL(url, format, extension, accessToken) {
|
|
46
|
+
const urlObject = parseUrl(url);
|
|
47
|
+
if (!isMapboxURL(url)) {
|
|
48
|
+
urlObject.path += `${format}${extension}`;
|
|
49
|
+
return formatUrl(urlObject);
|
|
50
|
+
}
|
|
51
|
+
urlObject.path = `/styles/v1${urlObject.path}/sprite${format}${extension}`;
|
|
52
|
+
return makeAPIURL(urlObject, accessToken);
|
|
53
|
+
}
|
|
54
|
+
const imageExtensionRe = /(\.(png|jpg)\d*)(?=$)/;
|
|
55
|
+
function normalizeTileURL(tileURL, sourceURL, tileSize, { devicePixelRatio = 1, supportsWebp = false } = {}) {
|
|
56
|
+
if (!sourceURL || !isMapboxURL(sourceURL)) return tileURL;
|
|
57
|
+
const urlObject = parseUrl(tileURL);
|
|
58
|
+
const suffix = devicePixelRatio >= 2 || tileSize === 512 ? "@2x" : "";
|
|
59
|
+
const extension = supportsWebp ? ".webp" : "$1";
|
|
60
|
+
urlObject.path = urlObject.path.replace(
|
|
61
|
+
imageExtensionRe,
|
|
62
|
+
`${suffix}${extension}`
|
|
63
|
+
);
|
|
64
|
+
return formatUrl(urlObject);
|
|
65
|
+
}
|
|
66
|
+
const urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
|
|
67
|
+
function parseUrl(url) {
|
|
68
|
+
const parts = url.match(urlRe);
|
|
69
|
+
if (!parts) {
|
|
70
|
+
throw new Error("Unable to parse URL object");
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
protocol: parts[1],
|
|
74
|
+
authority: parts[2],
|
|
75
|
+
path: parts[3] || "/",
|
|
76
|
+
params: parts[4] ? parts[4].split("&") : []
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function formatUrl(obj) {
|
|
80
|
+
const params = obj.params.length ? `?${obj.params.join("&")}` : "";
|
|
81
|
+
return `${obj.protocol}://${obj.authority}${obj.path}${params}`;
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
API_URL,
|
|
85
|
+
isMapboxURL,
|
|
86
|
+
normalizeGlyphsURL,
|
|
87
|
+
normalizeSourceURL,
|
|
88
|
+
normalizeSpriteURL,
|
|
89
|
+
normalizeStyleURL,
|
|
90
|
+
normalizeTileURL
|
|
91
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
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 misc_exports = {};
|
|
20
|
+
__export(misc_exports, {
|
|
21
|
+
clone: () => clone,
|
|
22
|
+
hasOwn: () => hasOwn,
|
|
23
|
+
noop: () => noop
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(misc_exports);
|
|
26
|
+
function clone(obj) {
|
|
27
|
+
return JSON.parse(JSON.stringify(obj));
|
|
28
|
+
}
|
|
29
|
+
function noop() {
|
|
30
|
+
}
|
|
31
|
+
function hasOwn(obj, key) {
|
|
32
|
+
return Object.hasOwn(obj, key);
|
|
33
|
+
}
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
clone,
|
|
37
|
+
hasOwn,
|
|
38
|
+
noop
|
|
39
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dumb and quick clone an object. Won't keep undefined properties. Types could
|
|
3
|
+
* be tighted so that return type excludes undefined properties, but not really
|
|
4
|
+
* needed.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T} obj
|
|
8
|
+
* @returns {T}
|
|
9
|
+
*/
|
|
10
|
+
declare function clone<T>(obj: T): T;
|
|
11
|
+
declare function noop(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Like `Object.hasOwn`, but refines the type of `key`.
|
|
14
|
+
*
|
|
15
|
+
* @template {Record<string, unknown>} T
|
|
16
|
+
* @param {T} obj
|
|
17
|
+
* @param {string} key
|
|
18
|
+
* @returns {key is (keyof T)}
|
|
19
|
+
*/
|
|
20
|
+
declare function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
|
|
21
|
+
|
|
22
|
+
export { clone, hasOwn, noop };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dumb and quick clone an object. Won't keep undefined properties. Types could
|
|
3
|
+
* be tighted so that return type excludes undefined properties, but not really
|
|
4
|
+
* needed.
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {T} obj
|
|
8
|
+
* @returns {T}
|
|
9
|
+
*/
|
|
10
|
+
declare function clone<T>(obj: T): T;
|
|
11
|
+
declare function noop(): void;
|
|
12
|
+
/**
|
|
13
|
+
* Like `Object.hasOwn`, but refines the type of `key`.
|
|
14
|
+
*
|
|
15
|
+
* @template {Record<string, unknown>} T
|
|
16
|
+
* @param {T} obj
|
|
17
|
+
* @param {string} key
|
|
18
|
+
* @returns {key is (keyof T)}
|
|
19
|
+
*/
|
|
20
|
+
declare function hasOwn<T extends Record<string, unknown>>(obj: T, key: string): key is (keyof T);
|
|
21
|
+
|
|
22
|
+
export { clone, hasOwn, noop };
|
|
@@ -0,0 +1,99 @@
|
|
|
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 streams_exports = {};
|
|
20
|
+
__export(streams_exports, {
|
|
21
|
+
ProgressStream: () => ProgressStream,
|
|
22
|
+
readableFromAsync: () => readableFromAsync,
|
|
23
|
+
writeStreamFromAsync: () => writeStreamFromAsync
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(streams_exports);
|
|
26
|
+
function readableFromAsync(iterable) {
|
|
27
|
+
if (typeof ReadableStream.from === "function") {
|
|
28
|
+
return ReadableStream.from(iterable);
|
|
29
|
+
}
|
|
30
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
31
|
+
return new ReadableStream({
|
|
32
|
+
async pull(controller) {
|
|
33
|
+
const { value, done } = await iterator.next();
|
|
34
|
+
if (done) {
|
|
35
|
+
controller.close();
|
|
36
|
+
} else {
|
|
37
|
+
controller.enqueue(value);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
async cancel(reason) {
|
|
41
|
+
await iterator.return?.(reason);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
function writeStreamFromAsync(fn, { concurrency = 16 } = {}) {
|
|
46
|
+
const pending = /* @__PURE__ */ new Set();
|
|
47
|
+
return new WritableStream(
|
|
48
|
+
{
|
|
49
|
+
write(chunk) {
|
|
50
|
+
const p = fn(...chunk);
|
|
51
|
+
pending.add(p);
|
|
52
|
+
p.finally(() => pending.delete(p));
|
|
53
|
+
if (pending.size >= concurrency) {
|
|
54
|
+
return Promise.race(pending);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
async close() {
|
|
58
|
+
await Promise.all(pending);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
new CountQueuingStrategy({ highWaterMark: concurrency })
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
class ProgressStream {
|
|
65
|
+
#byteLength = 0;
|
|
66
|
+
#ts;
|
|
67
|
+
/**
|
|
68
|
+
* @param {{ onprogress?: ProgressCallback }} [opts]
|
|
69
|
+
*/
|
|
70
|
+
constructor({ onprogress } = {}) {
|
|
71
|
+
const self = this;
|
|
72
|
+
this.#ts = new TransformStream({
|
|
73
|
+
transform(chunk, controller) {
|
|
74
|
+
self.#byteLength += chunk.byteLength;
|
|
75
|
+
onprogress?.({
|
|
76
|
+
totalBytes: self.#byteLength,
|
|
77
|
+
chunkBytes: chunk.byteLength
|
|
78
|
+
});
|
|
79
|
+
controller.enqueue(chunk);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
get readable() {
|
|
84
|
+
return this.#ts.readable;
|
|
85
|
+
}
|
|
86
|
+
get writable() {
|
|
87
|
+
return this.#ts.writable;
|
|
88
|
+
}
|
|
89
|
+
/** Total bytes that have passed through this stream */
|
|
90
|
+
get byteLength() {
|
|
91
|
+
return this.#byteLength;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
ProgressStream,
|
|
97
|
+
readableFromAsync,
|
|
98
|
+
writeStreamFromAsync
|
|
99
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as stream_web from 'stream/web';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a ReadableStream from an async iterable. Uses the native
|
|
5
|
+
* `ReadableStream.from()` when available (Node 20+), otherwise falls back to a
|
|
6
|
+
* manual approach for Node 18 compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {AsyncIterable<T>} iterable
|
|
10
|
+
* @returns {ReadableStream<T>}
|
|
11
|
+
*/
|
|
12
|
+
declare function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a writable stream from an async function. Default concurrency is 16 -
|
|
15
|
+
* this is the number of parallel functions that will be pending before
|
|
16
|
+
* backpressure is applied on the stream.
|
|
17
|
+
*
|
|
18
|
+
* @template {(...args: any[]) => Promise<void>} T
|
|
19
|
+
* @param {T} fn
|
|
20
|
+
* @returns {WritableStream}
|
|
21
|
+
*/
|
|
22
|
+
declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
|
|
23
|
+
concurrency?: number | undefined;
|
|
24
|
+
}): WritableStream;
|
|
25
|
+
/** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
|
|
26
|
+
/**
|
|
27
|
+
* A web TransformStream that counts the bytes passing through it. Pass an
|
|
28
|
+
* optional `onprogress` callback that will be called with the accumulated
|
|
29
|
+
* total byte count and the chunk byte count after each chunk.
|
|
30
|
+
*/
|
|
31
|
+
declare class ProgressStream {
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ onprogress?: ProgressCallback }} [opts]
|
|
34
|
+
*/
|
|
35
|
+
constructor({ onprogress }?: {
|
|
36
|
+
onprogress?: ProgressCallback;
|
|
37
|
+
});
|
|
38
|
+
get readable(): stream_web.ReadableStream<any>;
|
|
39
|
+
get writable(): stream_web.WritableStream<any>;
|
|
40
|
+
/** Total bytes that have passed through this stream */
|
|
41
|
+
get byteLength(): number;
|
|
42
|
+
#private;
|
|
43
|
+
}
|
|
44
|
+
type ProgressCallback = (opts: {
|
|
45
|
+
totalBytes: number;
|
|
46
|
+
chunkBytes: number;
|
|
47
|
+
}) => void;
|
|
48
|
+
|
|
49
|
+
export { type ProgressCallback, ProgressStream, readableFromAsync, writeStreamFromAsync };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as stream_web from 'stream/web';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Create a ReadableStream from an async iterable. Uses the native
|
|
5
|
+
* `ReadableStream.from()` when available (Node 20+), otherwise falls back to a
|
|
6
|
+
* manual approach for Node 18 compatibility.
|
|
7
|
+
*
|
|
8
|
+
* @template T
|
|
9
|
+
* @param {AsyncIterable<T>} iterable
|
|
10
|
+
* @returns {ReadableStream<T>}
|
|
11
|
+
*/
|
|
12
|
+
declare function readableFromAsync<T>(iterable: AsyncIterable<T>): ReadableStream<T>;
|
|
13
|
+
/**
|
|
14
|
+
* Create a writable stream from an async function. Default concurrency is 16 -
|
|
15
|
+
* this is the number of parallel functions that will be pending before
|
|
16
|
+
* backpressure is applied on the stream.
|
|
17
|
+
*
|
|
18
|
+
* @template {(...args: any[]) => Promise<void>} T
|
|
19
|
+
* @param {T} fn
|
|
20
|
+
* @returns {WritableStream}
|
|
21
|
+
*/
|
|
22
|
+
declare function writeStreamFromAsync<T extends (...args: any[]) => Promise<void>>(fn: T, { concurrency }?: {
|
|
23
|
+
concurrency?: number | undefined;
|
|
24
|
+
}): WritableStream;
|
|
25
|
+
/** @typedef {(opts: { totalBytes: number, chunkBytes: number }) => void} ProgressCallback */
|
|
26
|
+
/**
|
|
27
|
+
* A web TransformStream that counts the bytes passing through it. Pass an
|
|
28
|
+
* optional `onprogress` callback that will be called with the accumulated
|
|
29
|
+
* total byte count and the chunk byte count after each chunk.
|
|
30
|
+
*/
|
|
31
|
+
declare class ProgressStream {
|
|
32
|
+
/**
|
|
33
|
+
* @param {{ onprogress?: ProgressCallback }} [opts]
|
|
34
|
+
*/
|
|
35
|
+
constructor({ onprogress }?: {
|
|
36
|
+
onprogress?: ProgressCallback;
|
|
37
|
+
});
|
|
38
|
+
get readable(): stream_web.ReadableStream<any>;
|
|
39
|
+
get writable(): stream_web.WritableStream<any>;
|
|
40
|
+
/** Total bytes that have passed through this stream */
|
|
41
|
+
get byteLength(): number;
|
|
42
|
+
#private;
|
|
43
|
+
}
|
|
44
|
+
type ProgressCallback = (opts: {
|
|
45
|
+
totalBytes: number;
|
|
46
|
+
chunkBytes: number;
|
|
47
|
+
}) => void;
|
|
48
|
+
|
|
49
|
+
export { type ProgressCallback, ProgressStream, readableFromAsync, writeStreamFromAsync };
|