@osmix/shared 0.0.6 → 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.
Files changed (97) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/assert.d.ts +24 -0
  3. package/dist/assert.d.ts.map +1 -0
  4. package/dist/assert.js +28 -0
  5. package/dist/assert.js.map +1 -0
  6. package/dist/bbox-intersects.d.ts +15 -0
  7. package/dist/bbox-intersects.d.ts.map +1 -0
  8. package/dist/bbox-intersects.js +24 -0
  9. package/dist/bbox-intersects.js.map +1 -0
  10. package/dist/bytes-to-stream.d.ts +18 -0
  11. package/dist/bytes-to-stream.d.ts.map +1 -0
  12. package/dist/bytes-to-stream.js +25 -0
  13. package/dist/bytes-to-stream.js.map +1 -0
  14. package/dist/color.d.ts +4 -0
  15. package/dist/color.d.ts.map +1 -0
  16. package/dist/color.js +33 -0
  17. package/dist/color.js.map +1 -0
  18. package/dist/concat-bytes.d.ts +5 -0
  19. package/dist/concat-bytes.d.ts.map +1 -0
  20. package/dist/concat-bytes.js +14 -0
  21. package/dist/concat-bytes.js.map +1 -0
  22. package/dist/coordinates.d.ts +28 -0
  23. package/dist/coordinates.d.ts.map +1 -0
  24. package/dist/coordinates.js +38 -0
  25. package/dist/coordinates.js.map +1 -0
  26. package/dist/haversine-distance.d.ts +16 -0
  27. package/dist/haversine-distance.d.ts.map +1 -0
  28. package/dist/haversine-distance.js +26 -0
  29. package/dist/haversine-distance.js.map +1 -0
  30. package/dist/lineclip.d.ts +2 -0
  31. package/dist/lineclip.d.ts.map +1 -0
  32. package/dist/lineclip.js +3 -0
  33. package/dist/lineclip.js.map +1 -0
  34. package/dist/progress.d.ts +42 -0
  35. package/dist/progress.d.ts.map +1 -0
  36. package/dist/progress.js +53 -0
  37. package/dist/progress.js.map +1 -0
  38. package/dist/relation-kind.d.ts +69 -0
  39. package/dist/relation-kind.d.ts.map +1 -0
  40. package/dist/relation-kind.js +375 -0
  41. package/dist/relation-kind.js.map +1 -0
  42. package/dist/relation-multipolygon.d.ts +43 -0
  43. package/dist/relation-multipolygon.d.ts.map +1 -0
  44. package/dist/relation-multipolygon.js +195 -0
  45. package/dist/relation-multipolygon.js.map +1 -0
  46. package/dist/src/color.d.ts +4 -0
  47. package/dist/src/color.d.ts.map +1 -0
  48. package/dist/src/color.js +33 -0
  49. package/dist/src/color.js.map +1 -0
  50. package/dist/src/progress.d.ts +4 -2
  51. package/dist/src/progress.d.ts.map +1 -1
  52. package/dist/src/progress.js +17 -4
  53. package/dist/src/progress.js.map +1 -1
  54. package/dist/src/test/fixtures.d.ts.map +1 -1
  55. package/dist/src/test/fixtures.js +3 -0
  56. package/dist/src/test/fixtures.js.map +1 -1
  57. package/dist/stream-to-bytes.d.ts +18 -0
  58. package/dist/stream-to-bytes.d.ts.map +1 -0
  59. package/dist/stream-to-bytes.js +30 -0
  60. package/dist/stream-to-bytes.js.map +1 -0
  61. package/dist/test/fixtures.d.ts +36 -0
  62. package/dist/test/fixtures.d.ts.map +1 -0
  63. package/dist/test/fixtures.js +175 -0
  64. package/dist/test/fixtures.js.map +1 -0
  65. package/dist/throttle.d.ts +25 -0
  66. package/dist/throttle.d.ts.map +1 -0
  67. package/dist/throttle.js +34 -0
  68. package/dist/throttle.js.map +1 -0
  69. package/dist/tile.d.ts +34 -0
  70. package/dist/tile.d.ts.map +1 -0
  71. package/dist/tile.js +72 -0
  72. package/dist/tile.js.map +1 -0
  73. package/dist/transform-bytes.d.ts +24 -0
  74. package/dist/transform-bytes.d.ts.map +1 -0
  75. package/dist/transform-bytes.js +28 -0
  76. package/dist/transform-bytes.js.map +1 -0
  77. package/dist/types.d.ts +99 -0
  78. package/dist/types.d.ts.map +1 -0
  79. package/dist/types.js +9 -0
  80. package/dist/types.js.map +1 -0
  81. package/dist/utils.d.ts +30 -0
  82. package/dist/utils.d.ts.map +1 -0
  83. package/dist/utils.js +70 -0
  84. package/dist/utils.js.map +1 -0
  85. package/dist/way-is-area.d.ts +24 -0
  86. package/dist/way-is-area.d.ts.map +1 -0
  87. package/dist/way-is-area.js +104 -0
  88. package/dist/way-is-area.js.map +1 -0
  89. package/dist/zigzag.d.ts +33 -0
  90. package/dist/zigzag.d.ts.map +1 -0
  91. package/dist/zigzag.js +40 -0
  92. package/dist/zigzag.js.map +1 -0
  93. package/package.json +8 -7
  94. package/src/color.ts +37 -0
  95. package/src/progress.ts +23 -4
  96. package/src/test/fixtures.ts +3 -0
  97. package/tsconfig.build.json +5 -0
@@ -0,0 +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
+ */
23
+ export declare function transformBytes(bytes: Uint8Array<ArrayBuffer>, transformStream: TransformStream<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>): Promise<Uint8Array<ArrayBuffer>>;
24
+ //# sourceMappingURL=transform-bytes.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Transform stream utilities.
3
+ *
4
+ * Helpers for piping byte arrays through TransformStreams (e.g., compression).
5
+ *
6
+ * @module
7
+ */
8
+ import { bytesToStream } from "./bytes-to-stream";
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
+ */
25
+ export async function transformBytes(bytes, transformStream) {
26
+ return streamToBytes(bytesToStream(bytes).pipeThrough(transformStream));
27
+ }
28
+ //# sourceMappingURL=transform-bytes.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Shared type definitions used across all Osmix packages.
3
+ *
4
+ * Includes geographic primitives (LonLat, Bbox), tile coordinates,
5
+ * and core OSM entity types (Node, Way, Relation).
6
+ *
7
+ * @module
8
+ */
9
+ /** Geographic coordinate as [longitude, latitude] tuple. */
10
+ export type LonLat = [lon: number, lat: number];
11
+ /** 2D pixel or cartesian coordinate as [x, y] tuple. */
12
+ export type XY = [x: number, y: number];
13
+ /** Geographic coordinate as object with lon/lat properties. */
14
+ export interface ILonLat {
15
+ lon: number;
16
+ lat: number;
17
+ }
18
+ /** XYZ tile coordinate as [x, y, z] tuple. */
19
+ export type Tile = [x: number, y: number, z: number];
20
+ /**
21
+ * Project LonLat to pixels
22
+ */
23
+ export type LonLatToPixel = (ll: LonLat, zoom: number) => XY;
24
+ export type LonLatToTilePixel = (ll: LonLat, z: number, extent: number) => XY;
25
+ export type Rgba = [r: number, g: number, b: number, a: number] | Uint8ClampedArray;
26
+ /**
27
+ * A bounding box in the format [minLon, minLat, maxLon, maxLat].
28
+ * GeoJSON.BBox allows for 3D bounding boxes, but we use tools that expect 2D bounding boxes.
29
+ */
30
+ export type GeoBbox2D = [
31
+ minLon: number,
32
+ minLat: number,
33
+ maxLon: number,
34
+ maxLat: number
35
+ ];
36
+ /**
37
+ * A pixel bounding box in the format [minX, minY, maxX, maxY]. Note: minY is north. maxY is south.
38
+ */
39
+ export type TilePxBbox = [
40
+ minX: number,
41
+ minY: number,
42
+ maxX: number,
43
+ maxY: number
44
+ ];
45
+ /**
46
+ * Shared OSM Types
47
+ */
48
+ export type OsmEntityType = "node" | "way" | "relation";
49
+ export interface OsmInfoParsed {
50
+ version?: number;
51
+ timestamp?: number;
52
+ changeset?: number;
53
+ uid?: number;
54
+ user_sid?: number;
55
+ visible?: boolean;
56
+ user?: string;
57
+ }
58
+ export interface OsmTags {
59
+ [key: string]: string | number;
60
+ }
61
+ interface IOsmEntity {
62
+ id: number;
63
+ info?: OsmInfoParsed;
64
+ tags?: OsmTags;
65
+ }
66
+ export interface OsmNode extends IOsmEntity, ILonLat {
67
+ }
68
+ export interface OsmWay extends IOsmEntity {
69
+ refs: number[];
70
+ }
71
+ export interface OsmRelationMember {
72
+ type: OsmEntityType;
73
+ ref: number;
74
+ role?: string;
75
+ }
76
+ export interface OsmRelation extends IOsmEntity {
77
+ members: OsmRelationMember[];
78
+ }
79
+ export type OsmEntity = OsmNode | OsmWay | OsmRelation;
80
+ export interface OsmEntityTypeMap extends Record<OsmEntityType, IOsmEntity> {
81
+ node: OsmNode;
82
+ way: OsmWay;
83
+ relation: OsmRelation;
84
+ }
85
+ /**
86
+ * Semantic kinds of OSM relations based on their type tag and structure.
87
+ */
88
+ export type RelationKind = "area" | "line" | "point" | "logic" | "super";
89
+ /**
90
+ * Metadata about a relation kind, including expected roles and whether member order matters.
91
+ */
92
+ export interface RelationKindMetadata {
93
+ kind: RelationKind;
94
+ expectedRoles?: string[];
95
+ orderMatters: boolean;
96
+ description: string;
97
+ }
98
+ export {};
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,4DAA4D;AAC5D,MAAM,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC,CAAA;AAC/C,wDAAwD;AACxD,MAAM,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AAEvC,+DAA+D;AAC/D,MAAM,WAAW,OAAO;IACvB,GAAG,EAAE,MAAM,CAAA;IACX,GAAG,EAAE,MAAM,CAAA;CACX;AACD,8CAA8C;AAC9C,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,CAAC,CAAA;AAEpD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,EAAE,CAAA;AAE5D,MAAM,MAAM,iBAAiB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,EAAE,CAAA;AAE7E,MAAM,MAAM,IAAI,GACb,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC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M,WAAW,WAAY,SAAQ,UAAU;IAC9C,OAAO,EAAE,iBAAiB,EAAE,CAAA;CAC5B;AAED,MAAM,MAAM,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,WAAW,CAAA;AAEtD,MAAM,WAAW,gBAAiB,SAAQ,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC;IAC1E,IAAI,EAAE,OAAO,CAAA;IACb,GAAG,EAAE,MAAM,CAAA;IACX,QAAQ,EAAE,WAAW,CAAA;CACrB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAA;AAExE;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACpC,IAAI,EAAE,YAAY,CAAA;IAClB,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;IACxB,YAAY,EAAE,OAAO,CAAA;IACrB,WAAW,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared type definitions used across all Osmix packages.
3
+ *
4
+ * Includes geographic primitives (LonLat, Bbox), tile coordinates,
5
+ * and core OSM entity types (Node, Way, Relation).
6
+ *
7
+ * @module
8
+ */
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * General OSM entity utilities.
3
+ *
4
+ * Provides type guards, equality checks, and type detection for OSM entities.
5
+ * Uses deep equality checking for tags, info, and entity-specific properties.
6
+ *
7
+ * @module
8
+ */
9
+ import type { OsmEntity, OsmEntityType, OsmNode, OsmRelation, OsmWay } from "./types";
10
+ /** Type guard: check if entity is a Node. */
11
+ export declare function isNode(entity: OsmEntity): entity is OsmNode;
12
+ /** Check if two nodes are equal (position, tags, and info). */
13
+ export declare function isNodeEqual(a: OsmNode, b: OsmNode): boolean;
14
+ /** Type guard: check if entity is a Way. */
15
+ export declare function isWay(entity: OsmEntity): entity is OsmWay;
16
+ /** Type guard: check if entity is a Relation. */
17
+ export declare function isRelation(entity: OsmEntity): entity is OsmRelation;
18
+ /** Check if two ways are equal (refs, tags, and info). */
19
+ export declare function isWayEqual(a: OsmWay, b: OsmWay): boolean;
20
+ /** Check if two relations are equal (members, tags, and info). */
21
+ export declare function isRelationEqual(a: OsmRelation, b: OsmRelation): boolean;
22
+ /** Check if two entities have equal properties (type-aware comparison). */
23
+ export declare function entityPropertiesEqual(a: OsmEntity, b: OsmEntity): boolean;
24
+ /** Get the entity type ("node", "way", or "relation") for an entity. */
25
+ export declare function getEntityType(entity: OsmEntity): OsmEntityType;
26
+ /**
27
+ * Check if a relation is a multipolygon relation.
28
+ */
29
+ export declare function isMultipolygonRelation(relation: OsmRelation): boolean;
30
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EACb,OAAO,EACP,WAAW,EACX,MAAM,EACN,MAAM,SAAS,CAAA;AAShB,6CAA6C;AAC7C,wBAAgB,MAAM,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,OAAO,CAE3D;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,WAEjD;AAED,4CAA4C;AAC5C,wBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,MAAM,CAEzD;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,MAAM,IAAI,WAAW,CAEnE;AAED,0DAA0D;AAC1D,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,WAE9C;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,WAE7D;AAED,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,WAO/D;AAED,wEAAwE;AACxE,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,GAAG,aAAa,CAK9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO,CAErE"}
package/dist/utils.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * General OSM entity utilities.
3
+ *
4
+ * Provides type guards, equality checks, and type detection for OSM entities.
5
+ * Uses deep equality checking for tags, info, and entity-specific properties.
6
+ *
7
+ * @module
8
+ */
9
+ import { dequal } from "dequal/lite";
10
+ /**
11
+ * Check if two entities have equal tags and info.
12
+ */
13
+ function isTagsAndInfoEqual(a, b) {
14
+ return dequal(a.tags, b.tags) && dequal(a.info, b.info);
15
+ }
16
+ /** Type guard: check if entity is a Node. */
17
+ export function isNode(entity) {
18
+ return "lon" in entity && "lat" in entity;
19
+ }
20
+ /** Check if two nodes are equal (position, tags, and info). */
21
+ export function isNodeEqual(a, b) {
22
+ return a.lat === b.lat && a.lon === b.lon && isTagsAndInfoEqual(a, b);
23
+ }
24
+ /** Type guard: check if entity is a Way. */
25
+ export function isWay(entity) {
26
+ return "refs" in entity;
27
+ }
28
+ /** Type guard: check if entity is a Relation. */
29
+ export function isRelation(entity) {
30
+ return "members" in entity;
31
+ }
32
+ /** Check if two ways are equal (refs, tags, and info). */
33
+ export function isWayEqual(a, b) {
34
+ return dequal(a.refs, b.refs) && isTagsAndInfoEqual(a, b);
35
+ }
36
+ /** Check if two relations are equal (members, tags, and info). */
37
+ export function isRelationEqual(a, b) {
38
+ return dequal(a.members, b.members) && isTagsAndInfoEqual(a, b);
39
+ }
40
+ /** Check if two entities have equal properties (type-aware comparison). */
41
+ export function entityPropertiesEqual(a, b) {
42
+ if (!dequal(a.tags, b.tags))
43
+ return false;
44
+ if (!dequal(a.info, b.info))
45
+ return false;
46
+ if (isNode(a) && isNode(b))
47
+ return isNodeEqual(a, b);
48
+ if (isWay(a) && isWay(b))
49
+ return isWayEqual(a, b);
50
+ if (isRelation(a) && isRelation(b))
51
+ return isRelationEqual(a, b);
52
+ return false;
53
+ }
54
+ /** Get the entity type ("node", "way", or "relation") for an entity. */
55
+ export function getEntityType(entity) {
56
+ if (isNode(entity))
57
+ return "node";
58
+ if (isWay(entity))
59
+ return "way";
60
+ if (isRelation(entity))
61
+ return "relation";
62
+ throw Error("Unknown entity type");
63
+ }
64
+ /**
65
+ * Check if a relation is a multipolygon relation.
66
+ */
67
+ export function isMultipolygonRelation(relation) {
68
+ return relation.tags?.["type"] === "multipolygon";
69
+ }
70
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AASpC;;GAEG;AACH,SAAS,kBAAkB,CAAC,CAAY,EAAE,CAAY;IACrD,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC;AAED,6CAA6C;AAC7C,MAAM,UAAU,MAAM,CAAC,MAAiB;IACvC,OAAO,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,MAAM,CAAA;AAC1C,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,WAAW,CAAC,CAAU,EAAE,CAAU;IACjD,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,GAAG,IAAI,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC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,CAAA;IAChE,OAAO,KAAK,CAAA;AACb,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,aAAa,CAAC,MAAiB;IAC9C,IAAI,MAAM,CAAC,MAAM,CAAC;QAAE,OAAO,MAAM,CAAA;IACjC,IAAI,KAAK,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAA;IAC/B,IAAI,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,UAAU,CAAA;IACzC,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;AACnC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,QAAqB;IAC3D,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,CAAC,KAAK,cAAc,CAAA;AAClD,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Area detection for OSM ways.
3
+ *
4
+ * Implements the OSM wiki heuristics for determining whether a closed way
5
+ * should be rendered as an area (polygon) or a closed linear feature.
6
+ *
7
+ * @see https://wiki.openstreetmap.org/wiki/Key:area
8
+ * @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
9
+ *
10
+ * @module
11
+ */
12
+ import type { OsmWay } from "./types";
13
+ /**
14
+ * Determine if a way is an area based on its tags and nodes.
15
+ *
16
+ * This function implements the logic described in the OSM wiki:
17
+ * https://wiki.openstreetmap.org/wiki/Key:area
18
+ * https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
19
+ *
20
+ * @param way - The way to check.
21
+ * @returns `true` if the way is an area, `false` otherwise.
22
+ */
23
+ export declare function wayIsArea(way?: OsmWay): boolean;
24
+ //# sourceMappingURL=way-is-area.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"way-is-area.d.ts","sourceRoot":"","sources":["../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAqDrC;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CA+B/C"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Area detection for OSM ways.
3
+ *
4
+ * Implements the OSM wiki heuristics for determining whether a closed way
5
+ * should be rendered as an area (polygon) or a closed linear feature.
6
+ *
7
+ * @see https://wiki.openstreetmap.org/wiki/Key:area
8
+ * @see https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
9
+ *
10
+ * @module
11
+ */
12
+ /**
13
+ * Tags that imply an area unless their value is exactly "no"
14
+ */
15
+ const IMPLIED_ANY_VALUE_BUT_NO = new Set([
16
+ "amenity",
17
+ "boundary",
18
+ "building",
19
+ "building:part",
20
+ "craft",
21
+ // "golf", Seeing a lot of golf=cartpath which is not an area
22
+ "historic",
23
+ "indoor",
24
+ "landuse",
25
+ "leisure",
26
+ "military",
27
+ "office",
28
+ "place",
29
+ "public_transport",
30
+ "ruins",
31
+ "shop",
32
+ "tourism",
33
+ ]);
34
+ /**
35
+ * Tags that imply an area only for these specific values
36
+ */
37
+ const INCLUDED_VALUE_TAGS = {
38
+ barrier: new Set([
39
+ "city_wall",
40
+ "ditch",
41
+ "hedge",
42
+ "retaining_wall",
43
+ "wall",
44
+ "spikes",
45
+ ]),
46
+ highway: new Set(["services", "rest_area", "escape", "elevator"]),
47
+ power: new Set(["plant", "substation", "generator", "transformer"]),
48
+ railway: new Set(["station", "turntable", "roundhouse", "platform"]),
49
+ waterway: new Set(["riverbank", "dock", "boatyard", "dam"]),
50
+ };
51
+ /**
52
+ * Tags that imply an area unless the value is in this exclusion list
53
+ */
54
+ const EXCLUDED_VALUE_TAGS = {
55
+ aeroway: new Set(["no", "taxiway"]),
56
+ "area:highway": new Set(["no"]),
57
+ man_made: new Set(["no", "cutline", "embankment", "pipeline"]),
58
+ natural: new Set(["no", "coastline", "cliff", "ridge", "arete", "tree_row"]),
59
+ };
60
+ /**
61
+ * Determine if a way is an area based on its tags and nodes.
62
+ *
63
+ * This function implements the logic described in the OSM wiki:
64
+ * https://wiki.openstreetmap.org/wiki/Key:area
65
+ * https://wiki.openstreetmap.org/wiki/Overpass_turbo/Polygon_Features
66
+ *
67
+ * @param way - The way to check.
68
+ * @returns `true` if the way is an area, `false` otherwise.
69
+ */
70
+ export function wayIsArea(way) {
71
+ if (!way)
72
+ return false;
73
+ const { refs, tags } = way;
74
+ if (refs.length < 3)
75
+ return false;
76
+ if (refs[0] !== refs[refs.length - 1])
77
+ return false;
78
+ // End refs are equal, no tags, assume it is an area.
79
+ if (!tags || Object.keys(tags).length === 0)
80
+ return true;
81
+ // Explicit override
82
+ if ("area" in tags)
83
+ return tags["area"] !== "no";
84
+ // Tags that count if value is NOT "no"
85
+ for (const key of IMPLIED_ANY_VALUE_BUT_NO) {
86
+ const v = tags[key];
87
+ if (v && v !== "no")
88
+ return true;
89
+ }
90
+ // Tags that are area only for INCLUDED values
91
+ for (const [key, included] of Object.entries(INCLUDED_VALUE_TAGS)) {
92
+ const v = tags[key];
93
+ if (v && included.has(`${v}`))
94
+ return true;
95
+ }
96
+ // Tags that are area unless value is excluded
97
+ for (const [key, excluded] of Object.entries(EXCLUDED_VALUE_TAGS)) {
98
+ const v = tags[key];
99
+ if (v && !excluded.has(`${v}`))
100
+ return true;
101
+ }
102
+ return false;
103
+ }
104
+ //# sourceMappingURL=way-is-area.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"way-is-area.js","sourceRoot":"","sources":["../src/way-is-area.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,wBAAwB,GAAG,IAAI,GAAG,CAAC;IACxC,SAAS;IACT,UAAU;IACV,UAAU;IACV,eAAe;IACf,OAAO;IACP,8DAA8D;IAC9D,UAAU;IACV,QAAQ;IACR,SAAS;IACT,SAAS;IACT,UAAU;IACV,QAAQ;IACR,OAAO;IACP,kBAAkB;IAClB,OAAO;IACP,MAAM;IACN,SAAS;CACT,CAAC,CAAA;AAEF;;GAE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C,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC;QAAE,OAAO,KAAK,CAAA;IAEnD,qDAAqD;IACrD,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IAExD,oBAAoB;IACpB,IAAI,MAAM,IAAI,IAAI;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAA;IAEhD,uCAAuC;IACvC,KAAK,MAAM,GAAG,IAAI,wBAAwB,EAAE,CAAC;QAC5C,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI;YAAE,OAAO,IAAI,CAAA;IACjC,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC3C,CAAC;IAED,8CAA8C;IAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,CAAC;QACnE,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAAE,OAAO,IAAI,CAAA;IAC5C,CAAC;IAED,OAAO,KAAK,CAAA;AACb,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Zigzag encoding/decoding for protobuf-style varints.
3
+ *
4
+ * Zigzag encoding converts signed integers to unsigned by interleaving
5
+ * negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
6
+ * varint encoding of small negative numbers.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Zigzag encode a number using arithmetic operations.
12
+ * This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
13
+ * Formula: n < 0 ? -2*n - 1 : 2*n
14
+ *
15
+ * Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
16
+ * for unsigned varint encoding.
17
+ */
18
+ export declare function zigzag(num: number): number;
19
+ /**
20
+ * Zigzag encode using bitwise operations (for geometry deltas only).
21
+ * This is faster but limited to 32-bit signed integers.
22
+ * Used for small coordinate deltas in geometry encoding.
23
+ */
24
+ export declare function zigzag32(num: number): number;
25
+ /**
26
+ * Decode zigzag-encoded number back to original value.
27
+ * Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
28
+ * encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
29
+ *
30
+ * Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
31
+ */
32
+ export declare function decodeZigzag(encoded: number): number;
33
+ //# sourceMappingURL=zigzag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zigzag.d.ts","sourceRoot":"","sources":["../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE1C;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAGpD"}
package/dist/zigzag.js ADDED
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Zigzag encoding/decoding for protobuf-style varints.
3
+ *
4
+ * Zigzag encoding converts signed integers to unsigned by interleaving
5
+ * negative and positive values: 0, -1, 1, -2, 2, ... This allows efficient
6
+ * varint encoding of small negative numbers.
7
+ *
8
+ * @module
9
+ */
10
+ /**
11
+ * Zigzag encode a number using arithmetic operations.
12
+ * This supports the full safe integer range (up to Number.MAX_SAFE_INTEGER).
13
+ * Formula: n < 0 ? -2*n - 1 : 2*n
14
+ *
15
+ * Used for encoding IDs in vector tiles to convert negative IDs to positive numbers
16
+ * for unsigned varint encoding.
17
+ */
18
+ export function zigzag(num) {
19
+ return num < 0 ? -2 * num - 1 : 2 * num;
20
+ }
21
+ /**
22
+ * Zigzag encode using bitwise operations (for geometry deltas only).
23
+ * This is faster but limited to 32-bit signed integers.
24
+ * Used for small coordinate deltas in geometry encoding.
25
+ */
26
+ export function zigzag32(num) {
27
+ return (num << 1) ^ (num >> 31);
28
+ }
29
+ /**
30
+ * Decode zigzag-encoded number back to original value.
31
+ * Zigzag encoding is used to convert negative IDs to positive numbers for unsigned varint
32
+ * encoding in vector tiles. Uses arithmetic-based decoding to support the full safe integer range.
33
+ *
34
+ * Formula: (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2
35
+ */
36
+ export function decodeZigzag(encoded) {
37
+ // Check if encoded is odd (negative) using bitwise, then use arithmetic
38
+ return (encoded & 1) === 1 ? -(encoded + 1) / 2 : encoded / 2;
39
+ }
40
+ //# sourceMappingURL=zigzag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zigzag.js","sourceRoot":"","sources":["../src/zigzag.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH;;;;;;;GAOG;AACH,MAAM,UAAU,MAAM,CAAC,GAAW;IACjC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAA;AACxC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAW;IACnC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAA;AAChC,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,YAAY,CAAC,OAAe;IAC3C,wEAAwE;IACxE,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAA;AAC9D,CAAC"}
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@osmix/shared",
4
4
  "type": "module",
5
- "version": "0.0.6",
5
+ "version": "0.0.7",
6
6
  "description": "Shared utilities for Osmix",
7
7
  "exports": {
8
8
  "./*": "./src/*.ts",
@@ -36,19 +36,20 @@
36
36
  },
37
37
  "sideEffects": false,
38
38
  "scripts": {
39
- "build": "tsc",
39
+ "build": "tsc -p tsconfig.build.json",
40
40
  "bench": "bun test --bench",
41
- "prepublishOnly": "tsc",
41
+ "prepare": "bun run build",
42
+ "release": "bun publish",
42
43
  "test": "bun test",
43
44
  "typecheck": "tsgo --noEmit"
44
45
  },
45
46
  "devDependencies": {
46
- "@types/bun": "catalog:",
47
- "typescript": "catalog:"
47
+ "@types/bun": "^1.3.3",
48
+ "typescript": "^5.9.0"
48
49
  },
49
50
  "dependencies": {
50
- "@mapbox/tilebelt": "^2.0.2",
51
- "dequal": "catalog:",
51
+ "@mapbox/tilebelt": "^2.0.3",
52
+ "dequal": "^2.0.3",
52
53
  "lineclip": "^2.0.0"
53
54
  }
54
55
  }
package/src/color.ts ADDED
@@ -0,0 +1,37 @@
1
+ import type { Rgba } from "./types"
2
+
3
+ const hexPattern = /^[0-9a-fA-F]+$/
4
+
5
+ export function normalizeHexColor(
6
+ value: string | number | null | undefined,
7
+ ): string | undefined {
8
+ if (value === null || value === undefined) return
9
+ const raw = String(value).trim()
10
+ if (!raw) return
11
+ let hex = raw.startsWith("#") ? raw.slice(1) : raw
12
+ if (!hexPattern.test(hex)) return
13
+
14
+ if (hex.length === 3 || hex.length === 4) {
15
+ hex = hex
16
+ .split("")
17
+ .map((char) => `${char}${char}`)
18
+ .join("")
19
+ } else if (hex.length !== 6 && hex.length !== 8) {
20
+ return
21
+ }
22
+
23
+ return `#${hex.toUpperCase()}`
24
+ }
25
+
26
+ export function hexColorToRgba(
27
+ value: string | number | null | undefined,
28
+ ): Rgba | undefined {
29
+ const normalized = normalizeHexColor(value)
30
+ if (!normalized) return
31
+ const hex = normalized.slice(1)
32
+ const r = Number.parseInt(hex.slice(0, 2), 16)
33
+ const g = Number.parseInt(hex.slice(2, 4), 16)
34
+ const b = Number.parseInt(hex.slice(4, 6), 16)
35
+ const a = hex.length === 8 ? Number.parseInt(hex.slice(6, 8), 16) : 255
36
+ return [r, g, b, a]
37
+ }
package/src/progress.ts CHANGED
@@ -7,6 +7,8 @@
7
7
  * @module
8
8
  */
9
9
 
10
+ export type ProgressLevel = "info" | "warn" | "error"
11
+
10
12
  /**
11
13
  * Progress payload containing a message and timestamp.
12
14
  * Planned expansion to include percentage completion.
@@ -14,6 +16,7 @@
14
16
  export type Progress = {
15
17
  msg: string
16
18
  timestamp: number
19
+ level: ProgressLevel
17
20
  }
18
21
 
19
22
  /** CustomEvent carrying progress details. */
@@ -23,10 +26,11 @@ export interface ProgressEvent extends CustomEvent<Progress> {}
23
26
  * Create a Progress payload with current timestamp.
24
27
  * @param msg - The progress message.
25
28
  */
26
- export function progress(msg: string): Progress {
29
+ export function progress(msg: string, level: ProgressLevel = "info"): Progress {
27
30
  return {
28
31
  msg,
29
32
  timestamp: Date.now(),
33
+ level,
30
34
  }
31
35
  }
32
36
 
@@ -34,8 +38,11 @@ export function progress(msg: string): Progress {
34
38
  * Create a ProgressEvent with the given message.
35
39
  * @param msg - The progress message.
36
40
  */
37
- export function progressEvent(msg: string): ProgressEvent {
38
- return new CustomEvent("progress", { detail: progress(msg) })
41
+ export function progressEvent(
42
+ msg: string,
43
+ level: ProgressLevel = "info",
44
+ ): ProgressEvent {
45
+ return new CustomEvent("progress", { detail: progress(msg, level) })
39
46
  }
40
47
 
41
48
  /**
@@ -51,5 +58,17 @@ export function progressEventMessage(event: Event): string {
51
58
  * @param progress - The progress event to log.
52
59
  */
53
60
  export function logProgress(progress: ProgressEvent) {
54
- console.log(progressEventMessage(progress))
61
+ const level = progress.detail.level
62
+ const message = progressEventMessage(progress)
63
+ switch (level) {
64
+ case "info":
65
+ console.log(message)
66
+ break
67
+ case "warn":
68
+ console.warn(message)
69
+ break
70
+ case "error":
71
+ console.error(message)
72
+ break
73
+ }
55
74
  }
@@ -25,6 +25,9 @@ export async function getFixtureFile(
25
25
  const file = await Bun.file(filePath).arrayBuffer()
26
26
  return new Uint8Array<ArrayBuffer>(file)
27
27
  } catch (_error) {
28
+ if (process.env["CI"]) {
29
+ throw Error(`Do not download fixtures in CI: ${url} not found`)
30
+ }
28
31
  const response = await fetch(url)
29
32
  const buffer = await response.arrayBuffer()
30
33
  const data = new Uint8Array<ArrayBuffer>(buffer)