@osmix/core 0.1.10 → 0.3.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/CHANGELOG.md +56 -0
- package/LICENSE +21 -0
- package/README.md +136 -72
- package/dist/contracts.d.ts +27 -0
- package/dist/contracts.d.ts.map +1 -0
- package/dist/contracts.js +1 -0
- package/dist/contracts.js.map +1 -0
- package/dist/entities.d.ts +22 -2
- package/dist/entities.d.ts.map +1 -1
- package/dist/entities.js +54 -10
- package/dist/entities.js.map +1 -1
- package/dist/ids.d.ts +20 -5
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +87 -29
- package/dist/ids.js.map +1 -1
- package/dist/index.d.ts +7 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/indirect-kd-index.d.ts +28 -0
- package/dist/indirect-kd-index.d.ts.map +1 -0
- package/dist/indirect-kd-index.js +163 -0
- package/dist/indirect-kd-index.js.map +1 -0
- package/dist/limits.d.ts +30 -0
- package/dist/limits.d.ts.map +1 -0
- package/dist/limits.js +51 -0
- package/dist/limits.js.map +1 -0
- package/dist/mocks.d.ts.map +1 -1
- package/dist/mocks.js.map +1 -1
- package/dist/nodes.d.ts +36 -15
- package/dist/nodes.d.ts.map +1 -1
- package/dist/nodes.js +185 -62
- package/dist/nodes.js.map +1 -1
- package/dist/osm.d.ts +60 -4
- package/dist/osm.d.ts.map +1 -1
- package/dist/osm.js +32 -6
- package/dist/osm.js.map +1 -1
- package/dist/relations.d.ts +11 -4
- package/dist/relations.d.ts.map +1 -1
- package/dist/relations.js +73 -29
- package/dist/relations.js.map +1 -1
- package/dist/renumber.d.ts +23 -0
- package/dist/renumber.d.ts.map +1 -0
- package/dist/renumber.js +64 -0
- package/dist/renumber.js.map +1 -0
- package/dist/stringtable.d.ts +2 -1
- package/dist/stringtable.d.ts.map +1 -1
- package/dist/stringtable.js +9 -14
- package/dist/stringtable.js.map +1 -1
- package/dist/tags.d.ts +45 -12
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +153 -27
- package/dist/tags.js.map +1 -1
- package/dist/typed-arrays.d.ts +63 -48
- package/dist/typed-arrays.d.ts.map +1 -1
- package/dist/typed-arrays.js +184 -107
- package/dist/typed-arrays.js.map +1 -1
- package/dist/ways.d.ts +52 -3
- package/dist/ways.d.ts.map +1 -1
- package/dist/ways.js +223 -46
- package/dist/ways.js.map +1 -1
- package/package.json +45 -31
- package/src/contracts.ts +29 -0
- package/src/entities.ts +242 -194
- package/src/ids.ts +278 -235
- package/src/index.ts +22 -13
- package/src/indirect-kd-index.ts +212 -0
- package/src/limits.ts +73 -0
- package/src/mocks.ts +114 -113
- package/src/nodes.ts +538 -397
- package/src/osm.ts +282 -207
- package/src/relations.ts +580 -558
- package/src/renumber.ts +80 -0
- package/src/stringtable.ts +189 -184
- package/src/tags.ts +406 -272
- package/src/typed-arrays.ts +307 -205
- package/src/types/geoflatbush.d.ts +28 -33
- package/src/ways.ts +577 -406
- package/test/entity-index-errors.test.ts +41 -0
- package/test/ids.bench.ts +33 -0
- package/test/ids.test.ts +122 -0
- package/test/limits.test.ts +83 -0
- package/test/memory.test.ts +29 -30
- package/test/no-shared-array-buffer.test.ts +41 -0
- package/test/nodes-spatial-index.test.ts +261 -0
- package/test/osm-bbox.test.ts +30 -0
- package/test/relations.bench.ts +32 -0
- package/test/relations.test.ts +124 -0
- package/test/renumber.test.ts +54 -0
- package/test/spatial-index-rebuild.test.ts +33 -0
- package/test/storage-compaction.test.ts +269 -0
- package/test/tags-search.test.ts +89 -56
- package/test/typed-arrays.test.ts +252 -132
- package/tsconfig.build.json +6 -6
- package/tsconfig.json +7 -7
- package/src/types/geokdbush.d.ts +0 -37
- package/src/types/kdbush.d.ts +0 -47
package/dist/ids.d.ts
CHANGED
|
@@ -22,10 +22,10 @@ export type IdOrIndex = {
|
|
|
22
22
|
export interface IdsTransferables<T extends BufferType = BufferType> {
|
|
23
23
|
/** Entity IDs in insertion order. */
|
|
24
24
|
ids: T;
|
|
25
|
-
/** Sorted IDs for binary search
|
|
26
|
-
sortedIds
|
|
27
|
-
/** Maps sorted position → original insertion index. */
|
|
28
|
-
sortedIdPositionToIndex
|
|
25
|
+
/** Sorted IDs for binary search. Omitted when `idsAreSorted` is true. */
|
|
26
|
+
sortedIds?: T;
|
|
27
|
+
/** Maps sorted position → original insertion index. Omitted for sorted IDs. */
|
|
28
|
+
sortedIdPositionToIndex?: T;
|
|
29
29
|
/** Anchor array: every BLOCK_SIZE-th sorted ID. */
|
|
30
30
|
anchors: T;
|
|
31
31
|
/** True if IDs were inserted in ascending order. */
|
|
@@ -101,6 +101,16 @@ export declare class Ids {
|
|
|
101
101
|
idOrIndex(i: IdOrIndex): [index: number, id: number];
|
|
102
102
|
/** Returns the sorted array of IDs for iteration. */
|
|
103
103
|
get sorted(): Float64Array<ArrayBufferLike>;
|
|
104
|
+
/** @internal Iterate sorted IDs with their original storage positions. */
|
|
105
|
+
sortedEntries(): Generator<readonly [id: number, index: number]>;
|
|
106
|
+
/**
|
|
107
|
+
* Iterate in canonical OSM file order: negative IDs first by increasing
|
|
108
|
+
* absolute value, followed by non-negative IDs in ascending order.
|
|
109
|
+
*
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
osmSortedEntries(): Generator<readonly [id: number, index: number]>;
|
|
113
|
+
private sortedEntry;
|
|
104
114
|
/**
|
|
105
115
|
* Get transferable buffers for passing to another thread.
|
|
106
116
|
* @returns Serializable representation of this index.
|
|
@@ -108,8 +118,13 @@ export declare class Ids {
|
|
|
108
118
|
transferables(): IdsTransferables;
|
|
109
119
|
/**
|
|
110
120
|
* Get the approximate memory requirements for a given number of IDs in bytes.
|
|
121
|
+
*
|
|
122
|
+
* `idsAreSorted` defaults to true because PBF entity collections arrive in
|
|
123
|
+
* ascending ID order and retain no separate sort buffers. Pass false when
|
|
124
|
+
* estimating a programmatically built (unsorted) collection, which also
|
|
125
|
+
* retains sorted IDs plus a position map.
|
|
111
126
|
*/
|
|
112
|
-
static getBytesRequired(count: number): number;
|
|
127
|
+
static getBytesRequired(count: number, idsAreSorted?: boolean): number;
|
|
113
128
|
/**
|
|
114
129
|
* Update a ContentHasher with the IDs data.
|
|
115
130
|
* Uses the sorted IDs for consistent hashing regardless of insertion order.
|
package/dist/ids.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAElE,OAAO,EAAqB,KAAK,UAAU,EAA+B,MAAM,mBAAmB,CAAC;AAEpG;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAS3D;;GAEG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,SAAS,UAAU,GAAG,UAAU;IACjE,qCAAqC;IACrC,GAAG,EAAE,CAAC,CAAC;IACP,yEAAyE;IACzE,SAAS,CAAC,EAAE,CAAC,CAAC;IACd,+EAA+E;IAC/E,uBAAuB,CAAC,EAAE,CAAC,CAAC;IAC5B,mDAAmD;IACnD,OAAO,EAAE,CAAC,CAAC;IACX,oDAAoD;IACpD,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,qBAAa,GAAG;IACd,iCAAiC;IACjC,OAAO,CAAC,GAAG,CAAoB;IAC/B,2CAA2C;IAC3C,OAAO,CAAC,UAAU,CAAS;IAC3B,4EAA4E;IAC5E,OAAO,CAAC,YAAY,CAAQ;IAC5B,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F"}
|
package/dist/ids.js
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
9
|
import { assertValue } from "@osmix/shared/assert";
|
|
10
|
-
import { BufferConstructor, ResizeableTypedArray as RTA
|
|
10
|
+
import { BufferConstructor, ResizeableTypedArray as RTA } from "./typed-arrays.js";
|
|
11
11
|
/**
|
|
12
12
|
* Number of IDs per anchor block for the two-level binary search.
|
|
13
13
|
* Smaller values increase anchor array size but speed up block-level search;
|
|
@@ -40,8 +40,17 @@ export class Ids {
|
|
|
40
40
|
constructor(transferables) {
|
|
41
41
|
if (transferables) {
|
|
42
42
|
this.ids = RTA.from(Float64Array, transferables.ids);
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
if (transferables.idsAreSorted) {
|
|
44
|
+
this.idsSorted = this.ids.array;
|
|
45
|
+
this.sortedIdPositionToIndex = new Uint32Array(new BufferConstructor(0));
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
if (!transferables.sortedIds || !transferables.sortedIdPositionToIndex) {
|
|
49
|
+
throw Error("Unsorted IDs require sorted lookup buffers.");
|
|
50
|
+
}
|
|
51
|
+
this.idsSorted = new Float64Array(transferables.sortedIds);
|
|
52
|
+
this.sortedIdPositionToIndex = new Uint32Array(transferables.sortedIdPositionToIndex);
|
|
53
|
+
}
|
|
45
54
|
this.anchors = new Float64Array(transferables.anchors);
|
|
46
55
|
this.idsAreSorted = transferables.idsAreSorted;
|
|
47
56
|
this.indexBuilt = true;
|
|
@@ -110,32 +119,26 @@ export class Ids {
|
|
|
110
119
|
const posBuffer = new BufferConstructor(this.size * Uint32Array.BYTES_PER_ELEMENT);
|
|
111
120
|
this.idsSorted = new Float64Array(idsBuffer);
|
|
112
121
|
this.sortedIdPositionToIndex = new Uint32Array(posBuffer);
|
|
113
|
-
//
|
|
122
|
+
// Sort positions by ID, using the original position as a deterministic
|
|
123
|
+
// tie-breaker for duplicate IDs.
|
|
124
|
+
const sortedPositions = new Uint32Array(this.size);
|
|
125
|
+
for (let i = 0; i < this.size; i++)
|
|
126
|
+
sortedPositions[i] = i;
|
|
127
|
+
sortedPositions.sort((a, b) => {
|
|
128
|
+
const idDifference = this.ids.array[a] - this.ids.array[b];
|
|
129
|
+
return idDifference === 0 ? a - b : idDifference;
|
|
130
|
+
});
|
|
114
131
|
for (let i = 0; i < this.size; i++) {
|
|
115
|
-
|
|
116
|
-
this.
|
|
132
|
+
const position = sortedPositions[i];
|
|
133
|
+
this.idsSorted[i] = this.ids.array[position];
|
|
134
|
+
this.sortedIdPositionToIndex[i] = position;
|
|
117
135
|
}
|
|
118
|
-
// Sort by id, carrying position; use native sort on chunks or a custom radix/merge for stability.
|
|
119
|
-
// For simplicity:
|
|
120
|
-
const tmp = Array.from({ length: this.size }, (_, i) => ({
|
|
121
|
-
id: this.idsSorted[i],
|
|
122
|
-
pos: this.sortedIdPositionToIndex[i],
|
|
123
|
-
}));
|
|
124
|
-
tmp.sort((a, b) => a.id - b.id);
|
|
125
|
-
tmp.forEach(({ id, pos }, i) => {
|
|
126
|
-
this.idsSorted[i] = id;
|
|
127
|
-
this.sortedIdPositionToIndex[i] = pos;
|
|
128
|
-
});
|
|
129
136
|
}
|
|
130
137
|
else {
|
|
131
138
|
// Point to the same array
|
|
132
139
|
this.idsSorted = this.ids.array;
|
|
133
|
-
//
|
|
134
|
-
|
|
135
|
-
this.sortedIdPositionToIndex = new Uint32Array(posBuffer);
|
|
136
|
-
for (let i = 0; i < this.size; i++) {
|
|
137
|
-
this.sortedIdPositionToIndex[i] = i;
|
|
138
|
-
}
|
|
140
|
+
// Sorted position is already the insertion index; no identity map is needed.
|
|
141
|
+
this.sortedIdPositionToIndex = new Uint32Array(new BufferConstructor(0));
|
|
139
142
|
}
|
|
140
143
|
// Build anchors (every blockSize-th key)
|
|
141
144
|
const aLen = Math.ceil(this.size / BLOCK_SIZE);
|
|
@@ -206,28 +209,83 @@ export class Ids {
|
|
|
206
209
|
get sorted() {
|
|
207
210
|
return this.idsSorted;
|
|
208
211
|
}
|
|
212
|
+
/** @internal Iterate sorted IDs with their original storage positions. */
|
|
213
|
+
*sortedEntries() {
|
|
214
|
+
for (let i = 0; i < this.idsSorted.length; i++) {
|
|
215
|
+
yield this.sortedEntry(i);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Iterate in canonical OSM file order: negative IDs first by increasing
|
|
220
|
+
* absolute value, followed by non-negative IDs in ascending order.
|
|
221
|
+
*
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
*osmSortedEntries() {
|
|
225
|
+
let firstNonNegative = 0;
|
|
226
|
+
while (firstNonNegative < this.idsSorted.length && this.idsSorted[firstNonNegative] < 0) {
|
|
227
|
+
firstNonNegative++;
|
|
228
|
+
}
|
|
229
|
+
// Numeric sorting places negative IDs in the opposite of canonical OSM
|
|
230
|
+
// order. Reverse ID groups while preserving duplicate insertion order.
|
|
231
|
+
let groupEnd = firstNonNegative;
|
|
232
|
+
while (groupEnd > 0) {
|
|
233
|
+
const id = this.idsSorted[groupEnd - 1];
|
|
234
|
+
assertValue(id, "Sorted ID is undefined");
|
|
235
|
+
let groupStart = groupEnd - 1;
|
|
236
|
+
while (groupStart > 0 && this.idsSorted[groupStart - 1] === id)
|
|
237
|
+
groupStart--;
|
|
238
|
+
for (let position = groupStart; position < groupEnd; position++) {
|
|
239
|
+
yield this.sortedEntry(position);
|
|
240
|
+
}
|
|
241
|
+
groupEnd = groupStart;
|
|
242
|
+
}
|
|
243
|
+
for (let position = firstNonNegative; position < this.idsSorted.length; position++) {
|
|
244
|
+
yield this.sortedEntry(position);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
sortedEntry(position) {
|
|
248
|
+
const id = this.idsSorted[position];
|
|
249
|
+
assertValue(id, "Sorted ID is undefined");
|
|
250
|
+
if (this.idsAreSorted)
|
|
251
|
+
return [id, position];
|
|
252
|
+
const index = this.sortedIdPositionToIndex[position];
|
|
253
|
+
assertValue(index, "Sorted position is undefined");
|
|
254
|
+
return [id, index];
|
|
255
|
+
}
|
|
209
256
|
/**
|
|
210
257
|
* Get transferable buffers for passing to another thread.
|
|
211
258
|
* @returns Serializable representation of this index.
|
|
212
259
|
*/
|
|
213
260
|
transferables() {
|
|
214
|
-
|
|
261
|
+
const base = {
|
|
215
262
|
ids: this.ids.array.buffer,
|
|
216
|
-
sortedIds: this.idsSorted.buffer,
|
|
217
|
-
sortedIdPositionToIndex: this.sortedIdPositionToIndex.buffer,
|
|
218
263
|
anchors: this.anchors.buffer,
|
|
219
264
|
idsAreSorted: this.idsAreSorted,
|
|
220
265
|
};
|
|
266
|
+
if (this.idsAreSorted)
|
|
267
|
+
return base;
|
|
268
|
+
return {
|
|
269
|
+
...base,
|
|
270
|
+
sortedIds: this.idsSorted.buffer,
|
|
271
|
+
sortedIdPositionToIndex: this.sortedIdPositionToIndex.buffer,
|
|
272
|
+
};
|
|
221
273
|
}
|
|
222
274
|
/**
|
|
223
275
|
* Get the approximate memory requirements for a given number of IDs in bytes.
|
|
276
|
+
*
|
|
277
|
+
* `idsAreSorted` defaults to true because PBF entity collections arrive in
|
|
278
|
+
* ascending ID order and retain no separate sort buffers. Pass false when
|
|
279
|
+
* estimating a programmatically built (unsorted) collection, which also
|
|
280
|
+
* retains sorted IDs plus a position map.
|
|
224
281
|
*/
|
|
225
|
-
static getBytesRequired(count) {
|
|
282
|
+
static getBytesRequired(count, idsAreSorted = true) {
|
|
226
283
|
if (count === 0)
|
|
227
284
|
return 0;
|
|
228
285
|
return (count * Float64Array.BYTES_PER_ELEMENT + // ids
|
|
229
|
-
|
|
230
|
-
|
|
286
|
+
(idsAreSorted
|
|
287
|
+
? 0
|
|
288
|
+
: count * (Float64Array.BYTES_PER_ELEMENT + Uint32Array.BYTES_PER_ELEMENT)) + // sort index
|
|
231
289
|
Math.ceil(count / BLOCK_SIZE) * Float64Array.BYTES_PER_ELEMENT // anchors
|
|
232
290
|
);
|
|
233
291
|
}
|
package/dist/ids.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,
|
|
1
|
+
{"version":3,"file":"ids.js","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGnD,OAAO,EAAE,iBAAiB,EAAmB,oBAAoB,IAAI,GAAG,EAAE,MAAM,mBAAmB,CAAC;AAOpG;;;;GAIG;AACH,MAAM,UAAU,GAAG,GAAG,CAAC;AAkBvB;;;;;GAKG;AACH,MAAM,OAAO,GAAG;IACd,iCAAiC;IACzB,GAAG,CAAoB;IAC/B,2CAA2C;IACnC,UAAU,GAAG,KAAK,CAAC;IAC3B,4EAA4E;IACpE,YAAY,GAAG,IAAI,CAAC;IAC5B,2CAA2C;IACnC,SAAS,CAAe;IAChC,+DAA+D;IACvD,uBAAuB,CAAc;IAC7C,8EAA8E;IACtE,OAAO,CAAe;IAE9B;;;OAGG;IACH,YAAY,aAAgC;QAC1C,IAAI,aAAa,EAAE,CAAC;YAClB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;YACrD,IAAI,aAAa,CAAC,YAAY,EAAE,CAAC;gBAC/B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;gBAChC,IAAI,CAAC,uBAAuB,GAAG,IAAI,WAAW,CAAC,IAAI,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3E,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,aAAa,CAAC,SAAS,IAAI,CAAC,aAAa,CAAC,uBAAuB,EAAE,CAAC;oBACvE,MAAM,KAAK,CAAC,6CAA6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@
|
|
|
4
4
|
* Efficiently stores and queries OpenStreetMap entities (nodes, ways, relations).
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
|
-
* - **Memory-efficient**: Uses typed arrays
|
|
8
|
-
* - **Spatial indexing**:
|
|
7
|
+
* - **Memory-efficient**: Uses typed arrays; coordinates are Int32 at 1e-7 degrees.
|
|
8
|
+
* - **Spatial indexing**: Compact indirect KD trees (points) and Flatbush (bboxes).
|
|
9
9
|
* - **Worker-ready**: Zero-copy transfer via `transferables()`.
|
|
10
10
|
* - **Tag indexing**: Fast reverse lookup by tag key.
|
|
11
11
|
*
|
|
@@ -22,12 +22,15 @@
|
|
|
22
22
|
* @module @osmix/core
|
|
23
23
|
*/
|
|
24
24
|
export type { IdOrIndex } from "./ids.ts";
|
|
25
|
-
export
|
|
25
|
+
export type { OsmReader, OsmWriter } from "./contracts.ts";
|
|
26
|
+
export { OsmEntityIndexBuildError, type OsmEntityIndexComponent } from "./entities.ts";
|
|
27
|
+
export * from "./limits.ts";
|
|
26
28
|
export * from "./nodes.ts";
|
|
27
29
|
export * from "./osm.ts";
|
|
28
30
|
export * from "./relations.ts";
|
|
31
|
+
export { negativeIdMap, renumberNegativeIds, type OsmIdMap } from "./renumber.ts";
|
|
29
32
|
export * from "./stringtable.ts";
|
|
30
33
|
export * from "./tags.ts";
|
|
31
|
-
export { BufferConstructor, type BufferType } from "./typed-arrays.ts";
|
|
34
|
+
export { BufferConstructor, ResizeableTypedArray, TypedBufferAllocationError, type BufferType, type TypedBufferAllocationOperation, type TypedBufferType, } from "./typed-arrays.ts";
|
|
32
35
|
export * from "./ways.ts";
|
|
33
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAKH,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1C,YAAY,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAE,wBAAwB,EAAE,KAAK,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACvF,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,KAAK,QAAQ,EAAE,MAAM,eAAe,CAAC;AAClF,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,UAAU,EACf,KAAK,8BAA8B,EACnC,KAAK,eAAe,GACrB,MAAM,mBAAmB,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* Efficiently stores and queries OpenStreetMap entities (nodes, ways, relations).
|
|
5
5
|
*
|
|
6
6
|
* Features:
|
|
7
|
-
* - **Memory-efficient**: Uses typed arrays
|
|
8
|
-
* - **Spatial indexing**:
|
|
7
|
+
* - **Memory-efficient**: Uses typed arrays; coordinates are Int32 at 1e-7 degrees.
|
|
8
|
+
* - **Spatial indexing**: Compact indirect KD trees (points) and Flatbush (bboxes).
|
|
9
9
|
* - **Worker-ready**: Zero-copy transfer via `transferables()`.
|
|
10
10
|
* - **Tag indexing**: Fast reverse lookup by tag key.
|
|
11
11
|
*
|
|
@@ -21,12 +21,14 @@
|
|
|
21
21
|
*
|
|
22
22
|
* @module @osmix/core
|
|
23
23
|
*/
|
|
24
|
-
export
|
|
24
|
+
export { OsmEntityIndexBuildError } from "./entities.js";
|
|
25
|
+
export * from "./limits.js";
|
|
25
26
|
export * from "./nodes.js";
|
|
26
27
|
export * from "./osm.js";
|
|
27
28
|
export * from "./relations.js";
|
|
29
|
+
export { negativeIdMap, renumberNegativeIds } from "./renumber.js";
|
|
28
30
|
export * from "./stringtable.js";
|
|
29
31
|
export * from "./tags.js";
|
|
30
|
-
export { BufferConstructor } from "./typed-arrays.js";
|
|
32
|
+
export { BufferConstructor, ResizeableTypedArray, TypedBufferAllocationError, } from "./typed-arrays.js";
|
|
31
33
|
export * from "./ways.js";
|
|
32
34
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAOH,OAAO,EAAE,wBAAwB,EAAgC,MAAM,eAAe,CAAC;AACvF,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAiB,MAAM,eAAe,CAAC;AAClF,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,GAI3B,MAAM,mBAAmB,CAAC;AAC3B,cAAc,WAAW,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compact static KD index over coordinate columns owned by another object.
|
|
3
|
+
*
|
|
4
|
+
* The selection and traversal algorithms are adapted from KDBush 4.1.0,
|
|
5
|
+
* Copyright (c) 2018 Vladimir Agafonkin, distributed under the ISC License.
|
|
6
|
+
* Unlike KDBush, this index stores only a Uint32 permutation. Coordinates are
|
|
7
|
+
* dereferenced from the existing Int32 microdegree columns.
|
|
8
|
+
*/
|
|
9
|
+
import type { BufferType } from "./typed-arrays.ts";
|
|
10
|
+
export declare class IndirectKdIndex {
|
|
11
|
+
readonly indexes: Uint32Array;
|
|
12
|
+
private readonly lons;
|
|
13
|
+
private readonly lats;
|
|
14
|
+
private readonly nodeSize;
|
|
15
|
+
constructor(lons: Int32Array, lats: Int32Array, indexes: Uint32Array, nodeSize?: number);
|
|
16
|
+
static build(lons: Int32Array, lats: Int32Array, count: number, fill: (indexes: Uint32Array) => void): IndirectKdIndex;
|
|
17
|
+
static from(lons: Int32Array, lats: Int32Array, buffer: BufferType): IndirectKdIndex;
|
|
18
|
+
get buffer(): BufferType;
|
|
19
|
+
/**
|
|
20
|
+
* Find entity indexes within an inclusive bounding box.
|
|
21
|
+
*
|
|
22
|
+
* Bounds are **integer microdegrees** (the units of the underlying Int32
|
|
23
|
+
* coordinate columns), not degrees. `Nodes.findIndexesWithinBbox` performs
|
|
24
|
+
* the degree → microdegree conversion.
|
|
25
|
+
*/
|
|
26
|
+
range(minLon: number, minLat: number, maxLon: number, maxLat: number): number[];
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=indirect-kd-index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indirect-kd-index.d.ts","sourceRoot":"","sources":["../src/indirect-kd-index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAKpD,qBAAa,eAAe;IAC1B,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC;IAC9B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,YACE,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,OAAO,EAAE,WAAW,EACpB,QAAQ,SAAoB,EAM7B;IAED,MAAM,CAAC,KAAK,CACV,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,GACnC,eAAe,CAMjB;IAED,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,GAAG,eAAe,CAKnF;IAED,IAAI,MAAM,IAAI,UAAU,CAEvB;IAED;;;;;;OAMG;IACH,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAyC9E;CACF"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A compact static KD index over coordinate columns owned by another object.
|
|
3
|
+
*
|
|
4
|
+
* The selection and traversal algorithms are adapted from KDBush 4.1.0,
|
|
5
|
+
* Copyright (c) 2018 Vladimir Agafonkin, distributed under the ISC License.
|
|
6
|
+
* Unlike KDBush, this index stores only a Uint32 permutation. Coordinates are
|
|
7
|
+
* dereferenced from the existing Int32 microdegree columns.
|
|
8
|
+
*/
|
|
9
|
+
import { BufferConstructor } from "./typed-arrays.js";
|
|
10
|
+
const DEFAULT_NODE_SIZE = 64;
|
|
11
|
+
export class IndirectKdIndex {
|
|
12
|
+
indexes;
|
|
13
|
+
lons;
|
|
14
|
+
lats;
|
|
15
|
+
nodeSize;
|
|
16
|
+
constructor(lons, lats, indexes, nodeSize = DEFAULT_NODE_SIZE) {
|
|
17
|
+
this.lons = lons;
|
|
18
|
+
this.lats = lats;
|
|
19
|
+
this.indexes = indexes;
|
|
20
|
+
this.nodeSize = nodeSize;
|
|
21
|
+
}
|
|
22
|
+
static build(lons, lats, count, fill) {
|
|
23
|
+
const buffer = new BufferConstructor(count * Uint32Array.BYTES_PER_ELEMENT);
|
|
24
|
+
const indexes = new Uint32Array(buffer);
|
|
25
|
+
fill(indexes);
|
|
26
|
+
sortKd(indexes, lons, lats, DEFAULT_NODE_SIZE, 0, indexes.length - 1, 0);
|
|
27
|
+
return new IndirectKdIndex(lons, lats, indexes);
|
|
28
|
+
}
|
|
29
|
+
static from(lons, lats, buffer) {
|
|
30
|
+
if (buffer.byteLength % Uint32Array.BYTES_PER_ELEMENT !== 0) {
|
|
31
|
+
throw new Error("Indirect KD index buffer length must be divisible by four");
|
|
32
|
+
}
|
|
33
|
+
return new IndirectKdIndex(lons, lats, new Uint32Array(buffer));
|
|
34
|
+
}
|
|
35
|
+
get buffer() {
|
|
36
|
+
return this.indexes.buffer;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Find entity indexes within an inclusive bounding box.
|
|
40
|
+
*
|
|
41
|
+
* Bounds are **integer microdegrees** (the units of the underlying Int32
|
|
42
|
+
* coordinate columns), not degrees. `Nodes.findIndexesWithinBbox` performs
|
|
43
|
+
* the degree → microdegree conversion.
|
|
44
|
+
*/
|
|
45
|
+
range(minLon, minLat, maxLon, maxLat) {
|
|
46
|
+
const stack = [0, this.indexes.length - 1, 0];
|
|
47
|
+
const result = [];
|
|
48
|
+
while (stack.length > 0) {
|
|
49
|
+
const axis = stack.pop();
|
|
50
|
+
const right = stack.pop();
|
|
51
|
+
const left = stack.pop();
|
|
52
|
+
if (axis === undefined || right === undefined || left === undefined) {
|
|
53
|
+
throw new Error("Indirect KD index traversal stack is corrupt");
|
|
54
|
+
}
|
|
55
|
+
if (right - left <= this.nodeSize) {
|
|
56
|
+
for (let i = left; i <= right; i++) {
|
|
57
|
+
const entityIndex = entityAt(this.indexes, i);
|
|
58
|
+
const lon = coordinate(this.lons, this.lats, entityIndex, 0);
|
|
59
|
+
const lat = coordinate(this.lons, this.lats, entityIndex, 1);
|
|
60
|
+
if (lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat) {
|
|
61
|
+
result.push(entityIndex);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const middle = (left + right) >> 1;
|
|
67
|
+
const entityIndex = entityAt(this.indexes, middle);
|
|
68
|
+
const lon = coordinate(this.lons, this.lats, entityIndex, 0);
|
|
69
|
+
const lat = coordinate(this.lons, this.lats, entityIndex, 1);
|
|
70
|
+
if (lon >= minLon && lon <= maxLon && lat >= minLat && lat <= maxLat) {
|
|
71
|
+
result.push(entityIndex);
|
|
72
|
+
}
|
|
73
|
+
const splitCoordinate = axis === 0 ? lon : lat;
|
|
74
|
+
const minimum = axis === 0 ? minLon : minLat;
|
|
75
|
+
const maximum = axis === 0 ? maxLon : maxLat;
|
|
76
|
+
if (minimum <= splitCoordinate)
|
|
77
|
+
stack.push(left, middle - 1, 1 - axis);
|
|
78
|
+
if (maximum >= splitCoordinate)
|
|
79
|
+
stack.push(middle + 1, right, 1 - axis);
|
|
80
|
+
}
|
|
81
|
+
return result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function sortKd(indexes, lons, lats, nodeSize, left, right, axis) {
|
|
85
|
+
if (right - left <= nodeSize)
|
|
86
|
+
return;
|
|
87
|
+
const middle = (left + right) >> 1;
|
|
88
|
+
select(indexes, lons, lats, middle, left, right, axis);
|
|
89
|
+
sortKd(indexes, lons, lats, nodeSize, left, middle - 1, 1 - axis);
|
|
90
|
+
sortKd(indexes, lons, lats, nodeSize, middle + 1, right, 1 - axis);
|
|
91
|
+
}
|
|
92
|
+
/** Floyd-Rivest selection adapted to dereference coordinates indirectly. */
|
|
93
|
+
function select(indexes, lons, lats, k, initialLeft, initialRight, axis) {
|
|
94
|
+
let left = initialLeft;
|
|
95
|
+
let right = initialRight;
|
|
96
|
+
while (right > left) {
|
|
97
|
+
if (right - left > 600) {
|
|
98
|
+
const n = right - left + 1;
|
|
99
|
+
const m = k - left + 1;
|
|
100
|
+
const z = Math.log(n);
|
|
101
|
+
const s = 0.5 * Math.exp((2 * z) / 3);
|
|
102
|
+
const sd = 0.5 * Math.sqrt((z * s * (n - s)) / n) * (m - n / 2 < 0 ? -1 : 1);
|
|
103
|
+
const newLeft = Math.max(left, Math.floor(k - (m * s) / n + sd));
|
|
104
|
+
const newRight = Math.min(right, Math.floor(k + ((n - m) * s) / n + sd));
|
|
105
|
+
select(indexes, lons, lats, k, newLeft, newRight, axis);
|
|
106
|
+
}
|
|
107
|
+
const pivotIndex = entityAt(indexes, k);
|
|
108
|
+
const pivot = coordinate(lons, lats, pivotIndex, axis);
|
|
109
|
+
let i = left;
|
|
110
|
+
let j = right;
|
|
111
|
+
swap(indexes, left, k);
|
|
112
|
+
if (compareCoordinate(lons, lats, entityAt(indexes, right), pivotIndex, axis) > 0) {
|
|
113
|
+
swap(indexes, left, right);
|
|
114
|
+
}
|
|
115
|
+
while (i < j) {
|
|
116
|
+
swap(indexes, i, j);
|
|
117
|
+
i++;
|
|
118
|
+
j--;
|
|
119
|
+
while (i <= right && coordinate(lons, lats, entityAt(indexes, i), axis) < pivot)
|
|
120
|
+
i++;
|
|
121
|
+
while (j >= left && coordinate(lons, lats, entityAt(indexes, j), axis) > pivot)
|
|
122
|
+
j--;
|
|
123
|
+
}
|
|
124
|
+
if (coordinate(lons, lats, entityAt(indexes, left), axis) === pivot) {
|
|
125
|
+
swap(indexes, left, j);
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
j++;
|
|
129
|
+
swap(indexes, j, right);
|
|
130
|
+
}
|
|
131
|
+
if (j <= k)
|
|
132
|
+
left = j + 1;
|
|
133
|
+
if (k <= j)
|
|
134
|
+
right = j - 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Read the permutation entry at `position`, throwing on an out-of-bounds read.
|
|
139
|
+
* A silent skip here would leave the permutation subtly unsorted and produce
|
|
140
|
+
* wrong query results, so fail loudly instead.
|
|
141
|
+
*/
|
|
142
|
+
function entityAt(indexes, position) {
|
|
143
|
+
const value = indexes[position];
|
|
144
|
+
if (value === undefined) {
|
|
145
|
+
throw new Error(`Indirect KD index read out of bounds at position ${position}`);
|
|
146
|
+
}
|
|
147
|
+
return value;
|
|
148
|
+
}
|
|
149
|
+
function coordinate(lons, lats, entityIndex, axis) {
|
|
150
|
+
const value = axis === 0 ? lons[entityIndex] : lats[entityIndex];
|
|
151
|
+
if (value === undefined)
|
|
152
|
+
throw new Error(`Missing coordinate for node index ${entityIndex}`);
|
|
153
|
+
return value;
|
|
154
|
+
}
|
|
155
|
+
function compareCoordinate(lons, lats, a, b, axis) {
|
|
156
|
+
return coordinate(lons, lats, a, axis) - coordinate(lons, lats, b, axis);
|
|
157
|
+
}
|
|
158
|
+
function swap(indexes, a, b) {
|
|
159
|
+
const valueA = entityAt(indexes, a);
|
|
160
|
+
indexes[a] = entityAt(indexes, b);
|
|
161
|
+
indexes[b] = valueA;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=indirect-kd-index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indirect-kd-index.js","sourceRoot":"","sources":["../src/indirect-kd-index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,MAAM,OAAO,eAAe;IACjB,OAAO,CAAc;IACb,IAAI,CAAa;IACjB,IAAI,CAAa;IACjB,QAAQ,CAAS;IAElC,YACE,IAAgB,EAChB,IAAgB,EAChB,OAAoB,EACpB,QAAQ,GAAG,iBAAiB;QAE5B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,KAAK,CACV,IAAgB,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,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,IAAI,CAAC,OAAoB,EAAE,CAAS,EAAE,CAAS;IACtD,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IACpC,OAAO,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;AACtB,CAAC"}
|
package/dist/limits.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hard capacity limits set by the typed-array layout of `Osm` storage.
|
|
3
|
+
*
|
|
4
|
+
* See `docs/limits.md` for the full list, including limits that come from the
|
|
5
|
+
* JavaScript engine rather than from this layout.
|
|
6
|
+
*/
|
|
7
|
+
/** Largest number of node refs one way can hold (`Ways.refCount` is a `Uint16Array`). */
|
|
8
|
+
export declare const MAX_WAY_REFS = 65535;
|
|
9
|
+
/** Largest number of members one relation can hold (`Relations.memberCount` is a `Uint16Array`). */
|
|
10
|
+
export declare const MAX_RELATION_MEMBERS = 65535;
|
|
11
|
+
/** Largest UTF-8 byte length of one string (`StringTable.count` is a `Uint16Array`). */
|
|
12
|
+
export declare const MAX_STRING_BYTES = 65535;
|
|
13
|
+
/**
|
|
14
|
+
* Largest element offset a `Uint32Array` offset column can store. Bounds the total
|
|
15
|
+
* way refs, relation members and string-table bytes in one dataset.
|
|
16
|
+
*/
|
|
17
|
+
export declare const MAX_UINT32_OFFSET = 4294967295;
|
|
18
|
+
/** The storage limit an {@link OsmCapacityError} reports. */
|
|
19
|
+
export type OsmCapacityLimit = "way-refs" | "relation-members" | "string-bytes" | "total-way-refs" | "total-relation-members" | "total-string-bytes";
|
|
20
|
+
/** Thrown when an entity or dataset is larger than the storage layout can hold. */
|
|
21
|
+
export declare class OsmCapacityError extends Error {
|
|
22
|
+
readonly code = "OSM_CAPACITY_EXCEEDED";
|
|
23
|
+
readonly limit: OsmCapacityLimit;
|
|
24
|
+
readonly value: number;
|
|
25
|
+
readonly max: number;
|
|
26
|
+
constructor(limit: OsmCapacityLimit, value: number, max: number, subject: string);
|
|
27
|
+
}
|
|
28
|
+
/** Throw {@link OsmCapacityError} when `value` is above `max`. */
|
|
29
|
+
export declare function assertCapacity(limit: OsmCapacityLimit, value: number, max: number, subject: () => string): void;
|
|
30
|
+
//# sourceMappingURL=limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../src/limits.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,yFAAyF;AACzF,eAAO,MAAM,YAAY,QAAS,CAAC;AAEnC,oGAAoG;AACpG,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAE3C,wFAAwF;AACxF,eAAO,MAAM,gBAAgB,QAAS,CAAC;AAEvC;;;GAGG;AACH,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAE5C,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GACxB,UAAU,GACV,kBAAkB,GAClB,cAAc,GACd,gBAAgB,GAChB,wBAAwB,GACxB,oBAAoB,CAAC;AAEzB,mFAAmF;AACnF,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,2BAA2B;IACxC,QAAQ,CAAC,KAAK,EAAE,gBAAgB,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,YAAY,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAS/E;CACF;AAgBD,kEAAkE;AAClE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,MAAM,GACpB,IAAI,CAEN"}
|