@osmix/shared 0.0.2 → 0.0.7
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/CHANGELOG.md +33 -0
- package/README.md +49 -19
- package/dist/assert.d.ts +24 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +28 -0
- package/dist/assert.js.map +1 -0
- package/dist/bbox-intersects.d.ts +15 -0
- package/dist/bbox-intersects.d.ts.map +1 -0
- package/dist/bbox-intersects.js +24 -0
- package/dist/bbox-intersects.js.map +1 -0
- package/dist/bytes-to-stream.d.ts +18 -0
- package/dist/bytes-to-stream.d.ts.map +1 -0
- package/dist/bytes-to-stream.js +25 -0
- package/dist/bytes-to-stream.js.map +1 -0
- package/dist/color.d.ts +4 -0
- package/dist/color.d.ts.map +1 -0
- package/dist/color.js +33 -0
- package/dist/color.js.map +1 -0
- package/dist/concat-bytes.d.ts +5 -0
- package/dist/concat-bytes.d.ts.map +1 -0
- package/dist/concat-bytes.js +14 -0
- package/dist/concat-bytes.js.map +1 -0
- package/dist/coordinates.d.ts +28 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +38 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/haversine-distance.d.ts +16 -0
- package/dist/haversine-distance.d.ts.map +1 -0
- package/dist/haversine-distance.js +26 -0
- package/dist/haversine-distance.js.map +1 -0
- package/dist/lineclip.d.ts +2 -0
- package/dist/lineclip.d.ts.map +1 -0
- package/dist/lineclip.js +3 -0
- package/dist/lineclip.js.map +1 -0
- package/dist/progress.d.ts +42 -0
- package/dist/progress.d.ts.map +1 -0
- package/dist/progress.js +53 -0
- package/dist/progress.js.map +1 -0
- package/dist/relation-kind.d.ts +69 -0
- package/dist/relation-kind.d.ts.map +1 -0
- package/dist/relation-kind.js +375 -0
- package/dist/relation-kind.js.map +1 -0
- package/dist/relation-multipolygon.d.ts +43 -0
- package/dist/relation-multipolygon.d.ts.map +1 -0
- package/dist/relation-multipolygon.js +195 -0
- package/dist/relation-multipolygon.js.map +1 -0
- package/dist/src/assert.d.ts +20 -1
- package/dist/src/assert.d.ts.map +1 -1
- package/dist/src/assert.js +20 -1
- package/dist/src/assert.js.map +1 -1
- package/dist/src/bbox-intersects.d.ts +15 -0
- package/dist/src/bbox-intersects.d.ts.map +1 -0
- package/dist/src/bbox-intersects.js +24 -0
- package/dist/src/bbox-intersects.js.map +1 -0
- package/dist/src/bytes-to-stream.d.ts +17 -1
- package/dist/src/bytes-to-stream.d.ts.map +1 -1
- package/dist/src/bytes-to-stream.js +16 -0
- package/dist/src/bytes-to-stream.js.map +1 -1
- package/dist/src/color.d.ts +4 -0
- package/dist/src/color.d.ts.map +1 -0
- package/dist/src/color.js +33 -0
- package/dist/src/color.js.map +1 -0
- package/dist/src/coordinates.d.ts +28 -0
- package/dist/src/coordinates.d.ts.map +1 -0
- package/dist/src/coordinates.js +38 -0
- package/dist/src/coordinates.js.map +1 -0
- package/dist/src/haversine-distance.d.ts +9 -1
- package/dist/src/haversine-distance.d.ts.map +1 -1
- package/dist/src/haversine-distance.js +9 -1
- package/dist/src/haversine-distance.js.map +1 -1
- package/dist/src/progress.d.ts +42 -0
- package/dist/src/progress.d.ts.map +1 -0
- package/dist/src/progress.js +53 -0
- package/dist/src/progress.js.map +1 -0
- package/dist/src/relation-kind.d.ts +69 -0
- package/dist/src/relation-kind.d.ts.map +1 -0
- package/dist/src/relation-kind.js +375 -0
- package/dist/src/relation-kind.js.map +1 -0
- package/dist/src/relation-multipolygon.d.ts +43 -0
- package/dist/src/relation-multipolygon.d.ts.map +1 -0
- package/dist/src/relation-multipolygon.js +195 -0
- package/dist/src/relation-multipolygon.js.map +1 -0
- package/dist/src/stream-to-bytes.d.ts +16 -0
- package/dist/src/stream-to-bytes.d.ts.map +1 -1
- package/dist/src/stream-to-bytes.js +16 -0
- package/dist/src/stream-to-bytes.js.map +1 -1
- package/dist/src/test/fixtures.d.ts +1 -1
- package/dist/src/test/fixtures.d.ts.map +1 -1
- package/dist/src/test/fixtures.js +16 -8
- package/dist/src/test/fixtures.js.map +1 -1
- package/dist/src/throttle.d.ts +25 -0
- package/dist/src/throttle.d.ts.map +1 -0
- package/dist/src/throttle.js +34 -0
- package/dist/src/throttle.js.map +1 -0
- package/dist/src/tile.d.ts +34 -0
- package/dist/src/tile.d.ts.map +1 -0
- package/dist/src/tile.js +72 -0
- package/dist/src/tile.js.map +1 -0
- package/dist/src/transform-bytes.d.ts +22 -0
- package/dist/src/transform-bytes.d.ts.map +1 -1
- package/dist/src/transform-bytes.js +22 -0
- package/dist/src/transform-bytes.js.map +1 -1
- package/dist/src/types.d.ts +76 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +8 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/utils.d.ts +30 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +70 -0
- package/dist/src/utils.js.map +1 -0
- package/dist/src/way-is-area.d.ts +24 -0
- package/dist/src/way-is-area.d.ts.map +1 -0
- package/dist/src/way-is-area.js +104 -0
- package/dist/src/way-is-area.js.map +1 -0
- package/dist/src/zigzag.d.ts +33 -0
- package/dist/src/zigzag.d.ts.map +1 -0
- package/dist/src/zigzag.js +40 -0
- package/dist/src/zigzag.js.map +1 -0
- package/dist/stream-to-bytes.d.ts +18 -0
- package/dist/stream-to-bytes.d.ts.map +1 -0
- package/dist/stream-to-bytes.js +30 -0
- package/dist/stream-to-bytes.js.map +1 -0
- package/dist/test/fixtures.d.ts +36 -0
- package/dist/test/fixtures.d.ts.map +1 -0
- package/dist/test/fixtures.js +175 -0
- package/dist/test/fixtures.js.map +1 -0
- package/dist/test/haversine-distance.test.js +2 -2
- package/dist/test/haversine-distance.test.js.map +1 -1
- package/dist/test/relation-kind.test.d.ts +2 -0
- package/dist/test/relation-kind.test.d.ts.map +1 -0
- package/dist/test/relation-kind.test.js +367 -0
- package/dist/test/relation-kind.test.js.map +1 -0
- package/dist/test/relation-multipolygon.test.d.ts +2 -0
- package/dist/test/relation-multipolygon.test.d.ts.map +1 -0
- package/dist/test/relation-multipolygon.test.js +237 -0
- package/dist/test/relation-multipolygon.test.js.map +1 -0
- package/dist/test/utils.test.d.ts +2 -0
- package/dist/test/utils.test.d.ts.map +1 -0
- package/dist/test/utils.test.js +76 -0
- package/dist/test/utils.test.js.map +1 -0
- package/dist/test/way-is-area.test.d.ts +2 -0
- package/dist/test/way-is-area.test.d.ts.map +1 -0
- package/dist/test/way-is-area.test.js +31 -0
- package/dist/test/way-is-area.test.js.map +1 -0
- package/dist/throttle.d.ts +25 -0
- package/dist/throttle.d.ts.map +1 -0
- package/dist/throttle.js +34 -0
- package/dist/throttle.js.map +1 -0
- package/dist/tile.d.ts +34 -0
- package/dist/tile.d.ts.map +1 -0
- package/dist/tile.js +72 -0
- package/dist/tile.js.map +1 -0
- package/dist/transform-bytes.d.ts +24 -0
- package/dist/transform-bytes.d.ts.map +1 -0
- package/dist/transform-bytes.js +28 -0
- package/dist/transform-bytes.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +30 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +70 -0
- package/dist/utils.js.map +1 -0
- package/dist/way-is-area.d.ts +24 -0
- package/dist/way-is-area.d.ts.map +1 -0
- package/dist/way-is-area.js +104 -0
- package/dist/way-is-area.js.map +1 -0
- package/dist/zigzag.d.ts +33 -0
- package/dist/zigzag.d.ts.map +1 -0
- package/dist/zigzag.js +40 -0
- package/dist/zigzag.js.map +1 -0
- package/package.json +11 -10
- package/src/assert.ts +21 -1
- package/src/bbox-intersects.ts +30 -0
- package/src/bytes-to-stream.ts +17 -0
- package/src/color.ts +37 -0
- package/src/coordinates.ts +45 -0
- package/src/haversine-distance.ts +10 -1
- package/src/progress.ts +74 -0
- package/src/relation-kind.ts +446 -0
- package/src/relation-multipolygon.ts +225 -0
- package/src/stream-to-bytes.ts +17 -0
- package/src/test/fixtures.ts +16 -12
- package/src/throttle.ts +37 -0
- package/src/tile.ts +89 -0
- package/src/transform-bytes.ts +23 -0
- package/src/types.ts +93 -1
- package/src/utils.ts +79 -0
- package/src/way-is-area.ts +107 -0
- package/src/zigzag.ts +42 -0
- package/test/haversine-distance.test.ts +2 -2
- package/test/relation-kind.test.ts +426 -0
- package/test/relation-multipolygon.test.ts +265 -0
- package/test/utils.test.ts +103 -0
- package/test/way-is-area.test.ts +42 -0
- package/tsconfig/test.json +1 -0
- package/tsconfig.build.json +5 -0
- package/dist/src/spherical-mercator.d.ts +0 -15
- package/dist/src/spherical-mercator.d.ts.map +0 -1
- package/dist/src/spherical-mercator.js +0 -35
- package/dist/src/spherical-mercator.js.map +0 -1
- package/dist/src/spherical-mercator.test.d.ts +0 -2
- package/dist/src/spherical-mercator.test.d.ts.map +0 -1
- package/dist/src/spherical-mercator.test.js +0 -25
- package/dist/src/spherical-mercator.test.js.map +0 -1
- package/src/spherical-mercator.test.ts +0 -42
- package/src/spherical-mercator.ts +0 -42
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Multipolygon relation building utilities.
|
|
3
|
+
*
|
|
4
|
+
* Implements the OSM multipolygon relation specification to construct
|
|
5
|
+
* polygon geometries from way members. Handles outer/inner roles,
|
|
6
|
+
* way connection, and ring closure.
|
|
7
|
+
*
|
|
8
|
+
* @see https://wiki.openstreetmap.org/wiki/Relation:multipolygon
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Get way members from a relation, grouped by role (outer/inner).
|
|
14
|
+
*/
|
|
15
|
+
export function getWayMembersByRole(relation) {
|
|
16
|
+
const outer = [];
|
|
17
|
+
const inner = [];
|
|
18
|
+
for (const member of relation.members) {
|
|
19
|
+
if (member.type !== "way")
|
|
20
|
+
continue;
|
|
21
|
+
const role = member.role?.toLowerCase() ?? "";
|
|
22
|
+
if (role === "outer") {
|
|
23
|
+
outer.push(member);
|
|
24
|
+
}
|
|
25
|
+
else if (role === "inner") {
|
|
26
|
+
inner.push(member);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return { outer, inner };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Connect ways that share endpoints to form a continuous ring.
|
|
33
|
+
* Returns an array of rings (each ring is an array of way IDs in order).
|
|
34
|
+
*
|
|
35
|
+
* This function handles:
|
|
36
|
+
* - Ways that are reversed (end matches end, or start matches start).
|
|
37
|
+
* - Closed ways (single ways that form a ring).
|
|
38
|
+
* - Disconnected chains (multiple independent rings).
|
|
39
|
+
*/
|
|
40
|
+
export function connectWaysToRings(wayMembers) {
|
|
41
|
+
if (wayMembers.length === 0)
|
|
42
|
+
return [];
|
|
43
|
+
const rings = [];
|
|
44
|
+
const used = new Set();
|
|
45
|
+
const wayMap = new Map();
|
|
46
|
+
// Build map of way ID to member
|
|
47
|
+
for (const member of wayMembers) {
|
|
48
|
+
wayMap.set(member.id, member);
|
|
49
|
+
}
|
|
50
|
+
// Helper to reverse a way's refs
|
|
51
|
+
const reverseWay = (way) => ({
|
|
52
|
+
...way,
|
|
53
|
+
refs: [...way.refs].reverse(),
|
|
54
|
+
});
|
|
55
|
+
// Build rings by connecting ways
|
|
56
|
+
for (const startWay of wayMembers) {
|
|
57
|
+
if (used.has(startWay.id))
|
|
58
|
+
continue;
|
|
59
|
+
if (startWay.refs.length < 2)
|
|
60
|
+
throw Error("Way has less than 2 refs");
|
|
61
|
+
const ring = [startWay];
|
|
62
|
+
used.add(startWay.id);
|
|
63
|
+
let currentStart = startWay.refs[0];
|
|
64
|
+
let currentEnd = startWay.refs[startWay.refs.length - 1];
|
|
65
|
+
// Try to extend the ring forward
|
|
66
|
+
while (true) {
|
|
67
|
+
let found = false;
|
|
68
|
+
for (const nextWay of wayMembers) {
|
|
69
|
+
if (used.has(nextWay.id))
|
|
70
|
+
continue;
|
|
71
|
+
if (nextWay.refs.length < 2)
|
|
72
|
+
throw Error("Way has less than 2 refs");
|
|
73
|
+
const nextStart = nextWay.refs[0];
|
|
74
|
+
const nextEnd = nextWay.refs[nextWay.refs.length - 1];
|
|
75
|
+
// Check if next way connects to current end
|
|
76
|
+
if (currentEnd === nextStart) {
|
|
77
|
+
ring.push(nextWay);
|
|
78
|
+
used.add(nextWay.id);
|
|
79
|
+
currentEnd = nextEnd;
|
|
80
|
+
found = true;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
if (currentEnd === nextEnd) {
|
|
84
|
+
// Need to reverse next way
|
|
85
|
+
ring.push(reverseWay(nextWay));
|
|
86
|
+
used.add(nextWay.id);
|
|
87
|
+
currentEnd = nextStart;
|
|
88
|
+
found = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (!found)
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
// Try to extend the ring backward
|
|
96
|
+
currentStart = startWay.refs[0];
|
|
97
|
+
currentEnd = startWay.refs[startWay.refs.length - 1];
|
|
98
|
+
while (true) {
|
|
99
|
+
let found = false;
|
|
100
|
+
for (const nextWay of wayMembers) {
|
|
101
|
+
if (used.has(nextWay.id))
|
|
102
|
+
continue;
|
|
103
|
+
if (nextWay.refs.length < 2)
|
|
104
|
+
throw Error("Way has less than 2 refs");
|
|
105
|
+
const nextStart = nextWay.refs[0];
|
|
106
|
+
const nextEnd = nextWay.refs[nextWay.refs.length - 1];
|
|
107
|
+
// Check if next way connects to current start
|
|
108
|
+
if (currentStart === nextEnd) {
|
|
109
|
+
ring.unshift(nextWay);
|
|
110
|
+
used.add(nextWay.id);
|
|
111
|
+
currentStart = nextStart;
|
|
112
|
+
found = true;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if (currentStart === nextStart) {
|
|
116
|
+
// Need to reverse next way
|
|
117
|
+
ring.unshift(reverseWay(nextWay));
|
|
118
|
+
used.add(nextWay.id);
|
|
119
|
+
currentStart = nextEnd;
|
|
120
|
+
found = true;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!found)
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
// Only add ring if it's closed (first and last node are the same)
|
|
128
|
+
if (ring.length > 0) {
|
|
129
|
+
const firstWay = ring[0];
|
|
130
|
+
const lastWay = ring[ring.length - 1];
|
|
131
|
+
if (firstWay?.refs[0] === lastWay?.refs[lastWay.refs.length - 1]) {
|
|
132
|
+
rings.push(ring);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return rings;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Build polygon rings from way members of a relation.
|
|
140
|
+
* Returns an array where each element is an array of coordinate rings (outer + inner).
|
|
141
|
+
*
|
|
142
|
+
* Based on OSM multipolygon relation specification:
|
|
143
|
+
* https://wiki.openstreetmap.org/wiki/Relation:multipolygon
|
|
144
|
+
*
|
|
145
|
+
* This implementation connects way members into closed rings, and then groups them
|
|
146
|
+
* into polygons. Currently, it associates all inner rings with every outer ring
|
|
147
|
+
* found in the relation, which is a simplification. A robust implementation would
|
|
148
|
+
* use point-in-polygon checks to strictly nest holes inside their parent outer ring.
|
|
149
|
+
*/
|
|
150
|
+
export function buildRelationRings(relation, getWay, getNodeCoordinates) {
|
|
151
|
+
const { outer, inner } = getWayMembersByRole(relation);
|
|
152
|
+
// Connect outer ways into rings
|
|
153
|
+
const outerRings = connectWaysToRings(outer.map((m) => getWay(m.ref)).filter((w) => w !== null));
|
|
154
|
+
// Connect inner ways into rings
|
|
155
|
+
const innerRings = connectWaysToRings(inner.map((m) => getWay(m.ref)).filter((w) => w !== null));
|
|
156
|
+
const wayRingToCoords = (ring) => {
|
|
157
|
+
const coords = [];
|
|
158
|
+
for (const way of ring) {
|
|
159
|
+
for (const nodeId of way.refs) {
|
|
160
|
+
const coord = getNodeCoordinates(nodeId);
|
|
161
|
+
if (coord)
|
|
162
|
+
coords.push(coord);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// Ensure ring is closed
|
|
166
|
+
if (coords.length > 0) {
|
|
167
|
+
const first = coords[0];
|
|
168
|
+
const last = coords[coords.length - 1];
|
|
169
|
+
if (first && last && (first[0] !== last[0] || first[1] !== last[1])) {
|
|
170
|
+
coords.push([first[0], first[1]]);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return coords;
|
|
174
|
+
};
|
|
175
|
+
// Convert way rings to coordinate rings
|
|
176
|
+
const coordinateRings = [];
|
|
177
|
+
for (const outerRing of outerRings) {
|
|
178
|
+
const outerCoordinates = wayRingToCoords(outerRing);
|
|
179
|
+
if (outerCoordinates.length >= 3) {
|
|
180
|
+
// Find inner rings that belong to this outer ring
|
|
181
|
+
const innerCoordinates = [];
|
|
182
|
+
for (const innerRing of innerRings) {
|
|
183
|
+
const innerCoords = wayRingToCoords(innerRing);
|
|
184
|
+
if (innerCoords.length >= 3) {
|
|
185
|
+
// TODO: do proper point-in-polygon test with https://github.com/rowanwins/point-in-polygon-hao
|
|
186
|
+
innerCoordinates.push(innerCoords);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// Create polygon: [outer ring, ...inner rings]
|
|
190
|
+
coordinateRings.push([outerCoordinates, ...innerCoordinates]);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return coordinateRings;
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=relation-multipolygon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation-multipolygon.js","sourceRoot":"","sources":["../../src/relation-multipolygon.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAAqB;IAIxD,MAAM,KAAK,GAAwB,EAAE,CAAA;IACrC,MAAM,KAAK,GAAwB,EAAE,CAAA;IAErC,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,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GAAa,eAAe,CAAC,SAAS,CAAC,CAAA;gBAExD,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;oBAC7B,+FAA+F;oBAC/F,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;gBACnC,CAAC;YACF,CAAC;YAED,+CAA+C;YAC/C,eAAe,CAAC,IAAI,CAAC,CAAC,gBAAgB,EAAE,GAAG,gBAAgB,CAAC,CAAC,CAAA;QAC9D,CAAC;IACF,CAAC;IAED,OAAO,eAAe,CAAA;AACvB,CAAC"}
|
|
@@ -1,2 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream to byte array conversion.
|
|
3
|
+
*
|
|
4
|
+
* Consumes a ReadableStream and concatenates all chunks into a single Uint8Array.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Consume a ReadableStream and return all data as a single Uint8Array.
|
|
10
|
+
*
|
|
11
|
+
* Reads all chunks from the stream and concatenates them.
|
|
12
|
+
* The stream will be fully consumed after this function returns.
|
|
13
|
+
*
|
|
14
|
+
* @param stream - The stream to consume.
|
|
15
|
+
* @returns A Promise resolving to the concatenated bytes.
|
|
16
|
+
*/
|
|
1
17
|
export declare function streamToBytes(stream: ReadableStream<Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
|
|
2
18
|
//# sourceMappingURL=stream-to-bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-bytes.d.ts","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-to-bytes.d.ts","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,GAC7C,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAelC"}
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream to byte array conversion.
|
|
3
|
+
*
|
|
4
|
+
* Consumes a ReadableStream and concatenates all chunks into a single Uint8Array.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
1
8
|
import { concatBytes } from "./concat-bytes";
|
|
9
|
+
/**
|
|
10
|
+
* Consume a ReadableStream and return all data as a single Uint8Array.
|
|
11
|
+
*
|
|
12
|
+
* Reads all chunks from the stream and concatenates them.
|
|
13
|
+
* The stream will be fully consumed after this function returns.
|
|
14
|
+
*
|
|
15
|
+
* @param stream - The stream to consume.
|
|
16
|
+
* @returns A Promise resolving to the concatenated bytes.
|
|
17
|
+
*/
|
|
2
18
|
export async function streamToBytes(stream) {
|
|
3
19
|
const reader = stream.getReader();
|
|
4
20
|
const chunks = [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-to-bytes.js","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAA+C;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAE3C,IAAI,IAAI,EAAE,CAAC;YACV,MAAK;QACN,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC"}
|
|
1
|
+
{"version":3,"file":"stream-to-bytes.js","sourceRoot":"","sources":["../../src/stream-to-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAE5C;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,MAA+C;IAE/C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,MAAM,MAAM,GAA8B,EAAE,CAAA;IAE5C,OAAO,IAAI,EAAE,CAAC;QACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;QAE3C,IAAI,IAAI,EAAE,CAAC;YACV,MAAK;QACN,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACnB,CAAC;IAED,OAAO,WAAW,CAAC,MAAM,CAAC,CAAA;AAC3B,CAAC"}
|
|
@@ -3,7 +3,7 @@ export declare function getFixturePath(url: string): string;
|
|
|
3
3
|
* Get file from the cache folder or download it from the URL
|
|
4
4
|
*/
|
|
5
5
|
export declare function getFixtureFile(url: string): Promise<Uint8Array<ArrayBufferLike>>;
|
|
6
|
-
export declare function getFixtureFileReadStream(url: string): ReadableStream<Uint8Array<
|
|
6
|
+
export declare function getFixtureFileReadStream(url: string): ReadableStream<Uint8Array<ArrayBuffer>>;
|
|
7
7
|
export declare function getFixtureFileWriteStream(url: string): WritableStream<Uint8Array<ArrayBufferLike>>;
|
|
8
8
|
export type PbfFixture = {
|
|
9
9
|
url: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fixtures.d.ts","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAOA,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,UAOzC;AAED;;GAEG;AACH,wBAAsB,cAAc,CACnC,GAAG,EAAE,MAAM,GACT,OAAO,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAetC;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,MAAM,2CAEnD;AAED,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,MAAM,+CAUpD;AAED,MAAM,MAAM,UAAU,GAAG;IACxB,GAAG,EAAE,MAAM,CAAA;IACX,IAAI,EAAE;QACL,MAAM,EAAE,MAAM,CAAA;QACd,GAAG,EAAE,MAAM,CAAA;QACX,IAAI,EAAE,MAAM,CAAA;QACZ,KAAK,EAAE,MAAM,CAAA;KACb,CAAA;IACD,aAAa,EAAE,MAAM,CAAA;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE;QACN,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;QACX,EAAE,EAAE,MAAM,CAAA;KACV,CAAA;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,eAAe,EAAE,MAAM,CAAA;CACvB,CAAA;AAiCD,eAAO,MAAM,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CA0FrC,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAgC,CAAA"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { createReadStream, createWriteStream } from "node:fs";
|
|
2
|
-
import { readFile, writeFile } from "node:fs/promises";
|
|
3
1
|
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import { Readable, Writable } from "node:stream";
|
|
5
2
|
import { fileURLToPath } from "node:url";
|
|
6
3
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
4
|
const ROOT_DIR = resolve(__dirname, "../../../../");
|
|
@@ -21,22 +18,33 @@ export function getFixturePath(url) {
|
|
|
21
18
|
export async function getFixtureFile(url) {
|
|
22
19
|
const filePath = getFixturePath(url);
|
|
23
20
|
try {
|
|
24
|
-
const file = await
|
|
25
|
-
return new Uint8Array(file
|
|
21
|
+
const file = await Bun.file(filePath).arrayBuffer();
|
|
22
|
+
return new Uint8Array(file);
|
|
26
23
|
}
|
|
27
24
|
catch (_error) {
|
|
25
|
+
if (process.env["CI"]) {
|
|
26
|
+
throw Error(`Do not download fixtures in CI: ${url} not found`);
|
|
27
|
+
}
|
|
28
28
|
const response = await fetch(url);
|
|
29
29
|
const buffer = await response.arrayBuffer();
|
|
30
30
|
const data = new Uint8Array(buffer);
|
|
31
|
-
await
|
|
31
|
+
await Bun.write(filePath, data);
|
|
32
32
|
return data;
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
export function getFixtureFileReadStream(url) {
|
|
36
|
-
return
|
|
36
|
+
return Bun.file(getFixturePath(url)).stream();
|
|
37
37
|
}
|
|
38
38
|
export function getFixtureFileWriteStream(url) {
|
|
39
|
-
|
|
39
|
+
const incrementalWriter = Bun.file(getFixturePath(url)).writer();
|
|
40
|
+
return new WritableStream({
|
|
41
|
+
write: (chunk) => {
|
|
42
|
+
incrementalWriter.write(chunk);
|
|
43
|
+
},
|
|
44
|
+
close: () => {
|
|
45
|
+
incrementalWriter.end();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
40
48
|
}
|
|
41
49
|
/**
|
|
42
50
|
* List of PBFs and their metadata used for testing. Cached locally in the top level fixtures directory so they can
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"fixtures.js","sourceRoot":"","sources":["../../../src/test/fixtures.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU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CAAC;SACL;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,IAAI;KACnB;IACD,UAAU,EAAE;QACX,GAAG,EAAE,0EAA0E;QAC/E,IAAI,EAAE;YACL,MAAM,EAAE,QAAQ;YAChB,GAAG,EAAE,QAAQ;YACb,IAAI,EAAE,CAAC,QAAQ;YACf,KAAK,EAAE,CAAC,UAAU;SAClB;QACD,aAAa,EAAE,SAAS;QACxB,KAAK,EAAE,UAAU;QACjB,IAAI,EAAE,SAAS;QACf,SAAS,EAAE,MAAM;QACjB,KAAK,EAAE;YACN,GAAG,EAAE,QAAQ;YACb,GAAG,EAAE,CAAC,WAAW;YACjB,EAAE,EAAE,QAAQ;SACZ;QACD,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,GAAG;QACd,aAAa,EAAE,OAAO;QACtB,eAAe,EAAE,MAAM;KACvB;CACQ,CAAA;AAEV;;;GAGG;AACH,MAAM,CAAC,MAAM,IAAI,GAA+B,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttling utilities for rate-limiting function calls.
|
|
3
|
+
*
|
|
4
|
+
* Useful for limiting progress updates from workers or other high-frequency
|
|
5
|
+
* operations to avoid overwhelming the UI or logging.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a throttled version of a function that only executes at most
|
|
11
|
+
* once per `timeFrame` milliseconds.
|
|
12
|
+
*
|
|
13
|
+
* @param func - The function to throttle.
|
|
14
|
+
* @param timeFrame - Minimum time between calls in milliseconds.
|
|
15
|
+
* @returns A throttled version of the function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const logThrottled = throttle((msg) => console.log(msg), 1000)
|
|
20
|
+
* // Only logs at most once per second
|
|
21
|
+
* for (let i = 0; i < 1000; i++) logThrottled(`Progress: ${i}`)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function throttle<T extends unknown[]>(func: (...args: T) => void, timeFrame: number): (...args: T) => void;
|
|
25
|
+
//# sourceMappingURL=throttle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.d.ts","sourceRoot":"","sources":["../../src/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAC3C,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,IAAI,EAC1B,SAAS,EAAE,MAAM,IAGT,GAAG,MAAM,CAAC,UAOlB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Throttling utilities for rate-limiting function calls.
|
|
3
|
+
*
|
|
4
|
+
* Useful for limiting progress updates from workers or other high-frequency
|
|
5
|
+
* operations to avoid overwhelming the UI or logging.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Create a throttled version of a function that only executes at most
|
|
11
|
+
* once per `timeFrame` milliseconds.
|
|
12
|
+
*
|
|
13
|
+
* @param func - The function to throttle.
|
|
14
|
+
* @param timeFrame - Minimum time between calls in milliseconds.
|
|
15
|
+
* @returns A throttled version of the function.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* const logThrottled = throttle((msg) => console.log(msg), 1000)
|
|
20
|
+
* // Only logs at most once per second
|
|
21
|
+
* for (let i = 0; i < 1000; i++) logThrottled(`Progress: ${i}`)
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export function throttle(func, timeFrame) {
|
|
25
|
+
let lastTime = 0;
|
|
26
|
+
return (...args) => {
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (now - lastTime >= timeFrame) {
|
|
29
|
+
func(...args);
|
|
30
|
+
lastTime = now;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=throttle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttle.js","sourceRoot":"","sources":["../../src/throttle.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,QAAQ,CACvB,IAA0B,EAC1B,SAAiB;IAEjB,IAAI,QAAQ,GAAG,CAAC,CAAA;IAChB,OAAO,CAAC,GAAG,IAAO,EAAE,EAAE;QACrB,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;QACtB,IAAI,GAAG,GAAG,QAAQ,IAAI,SAAS,EAAE,CAAC;YACjC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAA;YACb,QAAQ,GAAG,GAAG,CAAA;QACf,CAAC;IACF,CAAC,CAAA;AACF,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XYZ tile coordinate utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides conversions between geographic coordinates (lon/lat) and
|
|
5
|
+
* tile pixel coordinates for XYZ tiled map systems. Supports various
|
|
6
|
+
* tile sizes and zoom levels.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { GeoBbox2D, LonLat, Tile, TilePxBbox, XY } from "./types";
|
|
11
|
+
/**
|
|
12
|
+
* Get the geographic bounding box of a tile.
|
|
13
|
+
* Returns [west, south, east, north].
|
|
14
|
+
*/
|
|
15
|
+
export declare function tileToBbox(tile: Tile): GeoBbox2D;
|
|
16
|
+
/**
|
|
17
|
+
* Convert a bounding box from geographic coordinates to tile pixel coordinates.
|
|
18
|
+
*/
|
|
19
|
+
export declare function bboxToTilePx(bbox: GeoBbox2D, tile: Tile, tileSize?: number): TilePxBbox;
|
|
20
|
+
/**
|
|
21
|
+
* Convert a geographic coordinate to tile pixel coordinates.
|
|
22
|
+
* Returns [x, y] in pixels relative to the top-left of the tile.
|
|
23
|
+
*/
|
|
24
|
+
export declare function llToTilePx(ll: LonLat, tile: Tile, tileSize?: number): XY;
|
|
25
|
+
/**
|
|
26
|
+
* Convert tile pixel coordinates to geographic coordinates.
|
|
27
|
+
*/
|
|
28
|
+
export declare function tilePxToLonLat(px: XY, tile: Tile, tileSize?: number): LonLat;
|
|
29
|
+
/**
|
|
30
|
+
* Clamp a pixel coordinate to the tile bounds and round to the nearest integer. Useful for converting a floating point pixel
|
|
31
|
+
* coordinate to a the exact tile pixel it is contained by.
|
|
32
|
+
*/
|
|
33
|
+
export declare function clampAndRoundPx(px: XY, tileSizeOrBbox: number | GeoBbox2D): XY;
|
|
34
|
+
//# sourceMappingURL=tile.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile.d.ts","sourceRoot":"","sources":["../../src/tile.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAatE;;;GAGG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAOhD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC3B,IAAI,EAAE,SAAS,EACf,IAAI,EAAE,IAAI,EACV,QAAQ,SAAM,GACZ,UAAU,CAIZ;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,SAAM,GAAG,EAAE,CAMrE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,SAAM,GAAG,MAAM,CAKzE;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAC9B,EAAE,EAAE,EAAE,EACN,cAAc,EAAE,MAAM,GAAG,SAAS,GAChC,EAAE,CASJ"}
|
package/dist/src/tile.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* XYZ tile coordinate utilities.
|
|
3
|
+
*
|
|
4
|
+
* Provides conversions between geographic coordinates (lon/lat) and
|
|
5
|
+
* tile pixel coordinates for XYZ tiled map systems. Supports various
|
|
6
|
+
* tile sizes and zoom levels.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { pointToTileFraction } from "@mapbox/tilebelt";
|
|
11
|
+
const RADIANS_TO_DEGREES = 180 / Math.PI;
|
|
12
|
+
function tile2lon(x, z) {
|
|
13
|
+
return (x / 2 ** z) * 360 - 180;
|
|
14
|
+
}
|
|
15
|
+
function tile2lat(y, z) {
|
|
16
|
+
const n = Math.PI - (2 * Math.PI * y) / 2 ** z;
|
|
17
|
+
return RADIANS_TO_DEGREES * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get the geographic bounding box of a tile.
|
|
21
|
+
* Returns [west, south, east, north].
|
|
22
|
+
*/
|
|
23
|
+
export function tileToBbox(tile) {
|
|
24
|
+
const [tx, ty, tz] = tile;
|
|
25
|
+
const n = tile2lat(ty, tz);
|
|
26
|
+
const s = tile2lat(ty + 1, tz);
|
|
27
|
+
const e = tile2lon(tx + 1, tz);
|
|
28
|
+
const w = tile2lon(tx, tz);
|
|
29
|
+
return [w, s, e, n];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Convert a bounding box from geographic coordinates to tile pixel coordinates.
|
|
33
|
+
*/
|
|
34
|
+
export function bboxToTilePx(bbox, tile, tileSize = 256) {
|
|
35
|
+
const [minX, minY] = llToTilePx([bbox[0], bbox[3]], tile, tileSize);
|
|
36
|
+
const [maxX, maxY] = llToTilePx([bbox[2], bbox[1]], tile, tileSize);
|
|
37
|
+
return [minX, minY, maxX, maxY];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Convert a geographic coordinate to tile pixel coordinates.
|
|
41
|
+
* Returns [x, y] in pixels relative to the top-left of the tile.
|
|
42
|
+
*/
|
|
43
|
+
export function llToTilePx(ll, tile, tileSize = 256) {
|
|
44
|
+
const [tx, ty, tz] = tile;
|
|
45
|
+
const tf = pointToTileFraction(ll[0], ll[1], tz);
|
|
46
|
+
const x = (tf[0] - tx) * tileSize;
|
|
47
|
+
const y = (tf[1] - ty) * tileSize;
|
|
48
|
+
return [x, y];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convert tile pixel coordinates to geographic coordinates.
|
|
52
|
+
*/
|
|
53
|
+
export function tilePxToLonLat(px, tile, tileSize = 256) {
|
|
54
|
+
const [tx, ty, tz] = tile;
|
|
55
|
+
const lon = tile2lon(px[0] / tileSize + tx, tz);
|
|
56
|
+
const lat = tile2lat(px[1] / tileSize + ty, tz);
|
|
57
|
+
return [lon, lat];
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Clamp a pixel coordinate to the tile bounds and round to the nearest integer. Useful for converting a floating point pixel
|
|
61
|
+
* coordinate to a the exact tile pixel it is contained by.
|
|
62
|
+
*/
|
|
63
|
+
export function clampAndRoundPx(px, tileSizeOrBbox) {
|
|
64
|
+
const [minX, minY, maxX, maxY] = typeof tileSizeOrBbox === "number"
|
|
65
|
+
? [0, 0, tileSizeOrBbox, tileSizeOrBbox]
|
|
66
|
+
: tileSizeOrBbox;
|
|
67
|
+
return [
|
|
68
|
+
Math.max(minX, Math.min(maxX, Math.round(px[0]))),
|
|
69
|
+
Math.max(minY, Math.min(maxY, Math.round(px[1]))),
|
|
70
|
+
];
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=tile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tile.js","sourceRoot":"","sources":["../../src/tile.ts"],"names":[],"mappings":"AAAA;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AC,CAAC,GAAG,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,CAAA;IAC/C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;AAClB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,EAAM,EACN,cAAkC;IAElC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,GAC7B,OAAO,cAAc,KAAK,QAAQ;QACjC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,cAAc,EAAE,cAAc,CAAC;QACxC,CAAC,CAAC,cAAc,CAAA;IAClB,OAAO;QACN,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KACjD,CAAA;AACF,CAAC"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform stream utilities.
|
|
3
|
+
*
|
|
4
|
+
* Helpers for piping byte arrays through TransformStreams (e.g., compression).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Pipe a byte array through a TransformStream and return the result.
|
|
10
|
+
*
|
|
11
|
+
* Useful for applying compression/decompression or other transformations
|
|
12
|
+
* to byte data using the Web Streams API.
|
|
13
|
+
*
|
|
14
|
+
* @param bytes - The input bytes.
|
|
15
|
+
* @param transformStream - The transform to apply (e.g., CompressionStream).
|
|
16
|
+
* @returns A Promise resolving to the transformed bytes.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const compressed = await transformBytes(data, new CompressionStream('gzip'))
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
1
23
|
export declare function transformBytes(bytes: Uint8Array<ArrayBuffer>, transformStream: TransformStream<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
|
|
2
24
|
//# sourceMappingURL=transform-bytes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-bytes.d.ts","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transform-bytes.d.ts","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,cAAc,CACnC,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,EAC9B,eAAe,EAAE,eAAe,CAC/B,UAAU,CAAC,WAAW,CAAC,EACvB,UAAU,CAAC,WAAW,CAAC,CACvB,GACC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAElC"}
|
|
@@ -1,5 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform stream utilities.
|
|
3
|
+
*
|
|
4
|
+
* Helpers for piping byte arrays through TransformStreams (e.g., compression).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
1
8
|
import { bytesToStream } from "./bytes-to-stream";
|
|
2
9
|
import { streamToBytes } from "./stream-to-bytes";
|
|
10
|
+
/**
|
|
11
|
+
* Pipe a byte array through a TransformStream and return the result.
|
|
12
|
+
*
|
|
13
|
+
* Useful for applying compression/decompression or other transformations
|
|
14
|
+
* to byte data using the Web Streams API.
|
|
15
|
+
*
|
|
16
|
+
* @param bytes - The input bytes.
|
|
17
|
+
* @param transformStream - The transform to apply (e.g., CompressionStream).
|
|
18
|
+
* @returns A Promise resolving to the transformed bytes.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* const compressed = await transformBytes(data, new CompressionStream('gzip'))
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
3
25
|
export async function transformBytes(bytes, transformStream) {
|
|
4
26
|
return streamToBytes(bytesToStream(bytes).pipeThrough(transformStream));
|
|
5
27
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transform-bytes.js","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAA8B,EAC9B,eAGC;IAED,OAAO,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAA;AACxE,CAAC"}
|
|
1
|
+
{"version":3,"file":"transform-bytes.js","sourceRoot":"","sources":["../../src/transform-bytes.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAEjD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CACnC,KAA8B,EAC9B,eAGC;IAED,OAAO,aAAa,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC,CAAA;AACxE,CAAC"}
|