@duoquote/polytini 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +119 -2
- package/dist/deckgl.cjs +250 -0
- package/dist/flexible.cjs +229 -0
- package/dist/google.cjs +232 -0
- package/dist/leaflet-auto.cjs +209 -0
- package/dist/leaflet.cjs +231 -0
- package/dist/mapbox.cjs +185 -0
- package/dist/maplibre.cjs +185 -0
- package/dist/node.cjs +322 -0
- package/dist/presets.cjs +65 -0
- package/dist/turf.cjs +267 -0
- package/dist/types/cli.d.cts +2 -0
- package/dist/types/deckgl.d.cts +72 -0
- package/dist/types/flexible.d.cts +92 -0
- package/dist/types/geojson.jsr.d.cts +111 -0
- package/dist/types/google.d.cts +48 -0
- package/dist/types/google.jsr.d.cts +72 -0
- package/dist/types/index.d.cts +109 -0
- package/dist/types/leaflet-auto.d.cts +4 -0
- package/dist/types/leaflet-auto.jsr.d.cts +2 -0
- package/dist/types/leaflet.d.cts +39 -0
- package/dist/types/leaflet.jsr.d.cts +15 -0
- package/dist/types/mapbox.d.cts +50 -0
- package/dist/types/mapbox.jsr.d.cts +5 -0
- package/dist/types/maplibre.d.cts +54 -0
- package/dist/types/maplibre.jsr.d.cts +92 -0
- package/dist/types/openlayers.d.cts +23 -0
- package/dist/types/openlayers.jsr.d.cts +42 -0
- package/dist/types/presets.d.cts +70 -0
- package/dist/types/turf.d.cts +33 -0
- package/dist/types/turf.jsr.d.cts +46 -0
- package/dist/types/wasm.d.cts +42 -0
- package/dist/web.cjs +231 -0
- package/package.json +198 -4
- package/src/browser.js +15 -0
- package/src/bun.js +4 -0
- package/src/cli-lib.js +160 -0
- package/src/cli.js +7 -0
- package/src/core.js +268 -0
- package/src/deckgl.js +176 -0
- package/src/deno.js +12 -0
- package/src/error.js +15 -0
- package/src/fast.js +179 -0
- package/src/flexible.js +283 -0
- package/src/google.js +70 -0
- package/src/leaflet-auto.js +11 -0
- package/src/leaflet.js +44 -0
- package/src/mapbox.js +10 -0
- package/src/maplibre.js +57 -0
- package/src/node.js +17 -0
- package/src/openlayers.js +172 -0
- package/src/presets.js +242 -0
- package/src/text.js +111 -0
- package/src/turf.js +80 -0
- package/src/wasm-bytes.js +2 -0
- package/src/wasm.js +235 -0
- package/src/web.js +9 -0
- package/types/cli.d.ts +2 -0
- package/types/deckgl.d.ts +72 -0
- package/types/flexible.d.ts +92 -0
- package/types/geojson.jsr.d.ts +111 -0
- package/types/google.d.ts +48 -0
- package/types/google.jsr.d.ts +72 -0
- package/types/index.d.ts +109 -0
- package/types/leaflet-auto.d.ts +4 -0
- package/types/leaflet-auto.jsr.d.ts +2 -0
- package/types/leaflet.d.ts +39 -0
- package/types/leaflet.jsr.d.ts +15 -0
- package/types/mapbox.d.ts +50 -0
- package/types/mapbox.jsr.d.ts +5 -0
- package/types/maplibre.d.ts +54 -0
- package/types/maplibre.jsr.d.ts +92 -0
- package/types/openlayers.d.ts +23 -0
- package/types/openlayers.jsr.d.ts +42 -0
- package/types/presets.d.ts +70 -0
- package/types/turf.d.ts +33 -0
- package/types/turf.jsr.d.ts +46 -0
- package/types/wasm.d.ts +42 -0
- package/wasm/polytini.wasm +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// JSR copy of turf.d.ts. JSR builds its docs without node_modules, so the
|
|
2
|
+
// GeoJSON types come from geojson.jsr.d.ts and Turf's Id and AllGeoJSON are
|
|
3
|
+
// written out here. They have the same shapes as @types/geojson's and
|
|
4
|
+
// @turf/helpers', which the npm package's turf.d.ts uses.
|
|
5
|
+
import type { Options } from './index.d.ts';
|
|
6
|
+
import type { Feature, FeatureCollection, Geometry, LineString, Polygon, GeoJsonProperties } from './geojson.jsr.d.ts';
|
|
7
|
+
|
|
8
|
+
export type { Feature, FeatureCollection, Geometry, GeometryCollection, Point, MultiPoint, LineString, MultiLineString, Polygon, MultiPolygon, Position, BBox, GeoJsonProperties } from './geojson.jsr.d.ts';
|
|
9
|
+
|
|
10
|
+
/** A feature id, like Turf's Id. */
|
|
11
|
+
export type Id = string | number;
|
|
12
|
+
|
|
13
|
+
/** Any GeoJSON object, like Turf's AllGeoJSON. */
|
|
14
|
+
export type AllGeoJSON = Feature<Geometry | null> | FeatureCollection<Geometry | null> | Geometry;
|
|
15
|
+
|
|
16
|
+
/** Options for toFeature and toPolygonFeature. */
|
|
17
|
+
export interface FeatureOptions<P = GeoJsonProperties> extends Options {
|
|
18
|
+
/** Feature properties. Default {}. */
|
|
19
|
+
properties?: P;
|
|
20
|
+
/** Feature id. */
|
|
21
|
+
id?: Id;
|
|
22
|
+
/** Add a [west, south, east, north] bbox. Default false. */
|
|
23
|
+
bbox?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Options for toFeatureCollection. */
|
|
27
|
+
export interface CollectionOptions<P = GeoJsonProperties> extends Options {
|
|
28
|
+
/** Shared properties, or one object per line. */
|
|
29
|
+
properties?: P | P[];
|
|
30
|
+
/** One id per line, or the same for all. */
|
|
31
|
+
id?: Id | Id[];
|
|
32
|
+
/** Add a bbox to each feature. Default false. */
|
|
33
|
+
bbox?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A Feature<LineString> ([lng, lat], like Turf) from one encoded line. */
|
|
37
|
+
export function toFeature<P = GeoJsonProperties>(encoded: string, options?: number | FeatureOptions<P>): Feature<LineString, P>;
|
|
38
|
+
|
|
39
|
+
/** A FeatureCollection<LineString>, one Feature per string. */
|
|
40
|
+
export function toFeatureCollection<P = GeoJsonProperties>(encoded: string[], options?: number | CollectionOptions<P>): FeatureCollection<LineString, P>;
|
|
41
|
+
|
|
42
|
+
/** A Feature<Polygon> from encoded rings: outer first, then holes. */
|
|
43
|
+
export function toPolygonFeature<P = GeoJsonProperties>(rings: string[], options?: number | FeatureOptions<P>): Feature<Polygon, P>;
|
|
44
|
+
|
|
45
|
+
/** Every line in any GeoJSON: LineStrings, MultiLineString parts and polygon rings, in document order. Points are skipped. */
|
|
46
|
+
export function fromGeoJSON(geojson: AllGeoJSON, options?: number | Options): string[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The /wasm entry: the same API as the main entry, after init.
|
|
2
|
+
import type * as P from './index.d.ts';
|
|
3
|
+
|
|
4
|
+
export type { Point, LatLngLike, Options, OptionsArg, ErrorCode, LineString, LineStringFeature } from './index.d.ts';
|
|
5
|
+
/** The main entry's encode. */
|
|
6
|
+
export declare const encode: typeof P.encode;
|
|
7
|
+
/** The main entry's decode. */
|
|
8
|
+
export declare const decode: typeof P.decode;
|
|
9
|
+
/** The main entry's encodeFlat. */
|
|
10
|
+
export declare const encodeFlat: typeof P.encodeFlat;
|
|
11
|
+
/** The main entry's decodeFlat. */
|
|
12
|
+
export declare const decodeFlat: typeof P.decodeFlat;
|
|
13
|
+
/** The main entry's decodeLatLng. */
|
|
14
|
+
export declare const decodeLatLng: typeof P.decodeLatLng;
|
|
15
|
+
/** The main entry's toGeoJSON. */
|
|
16
|
+
export declare const toGeoJSON: typeof P.toGeoJSON;
|
|
17
|
+
/** The main entry's fromGeoJSON. */
|
|
18
|
+
export declare const fromGeoJSON: typeof P.fromGeoJSON;
|
|
19
|
+
/** The main entry's PolylineError. */
|
|
20
|
+
export declare const PolylineError: typeof P.PolylineError;
|
|
21
|
+
/** The main entry's PolylineError type. */
|
|
22
|
+
export type PolylineError = P.PolylineError;
|
|
23
|
+
|
|
24
|
+
/** Compiles and instantiates the WASM module. Call once before anything else; repeat calls are free. */
|
|
25
|
+
export function init(): Promise<void>;
|
|
26
|
+
|
|
27
|
+
/** The same, synchronously. Fine here because the module is under 1 KB. */
|
|
28
|
+
export function initSync(): void;
|
|
29
|
+
|
|
30
|
+
/** Many lines decoded in one call: all points in one array, plus where each line starts. */
|
|
31
|
+
export interface ManyLines {
|
|
32
|
+
/** lat, lng pairs (lng, lat with order 'lnglat') of every line, back to back. */
|
|
33
|
+
coords: Float64Array;
|
|
34
|
+
/** The first point index of each line, then the total point count (length + 1 entries), as deck.gl's binary paths expect. */
|
|
35
|
+
starts: Uint32Array;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Decodes many lines in one WASM call. Strict mode throws on the first bad line. */
|
|
39
|
+
export function decodeMany(lines: readonly string[], options?: P.OptionsArg): ManyLines;
|
|
40
|
+
|
|
41
|
+
/** Encodes many lines in one WASM call: arrays of points, or the { coords, starts } shape decodeMany returns. */
|
|
42
|
+
export function encodeMany(lines: readonly (readonly P.Point[])[] | ManyLines, options?: P.OptionsArg): string[];
|
package/dist/web.cjs
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/web.js
|
|
20
|
+
var web_exports = {};
|
|
21
|
+
__export(web_exports, {
|
|
22
|
+
PolylineError: () => PolylineError,
|
|
23
|
+
decode: () => decode,
|
|
24
|
+
decodeFlat: () => decodeFlat,
|
|
25
|
+
decodeLatLng: () => decodeLatLng,
|
|
26
|
+
encode: () => encode,
|
|
27
|
+
encodeFlat: () => encodeFlat,
|
|
28
|
+
fromGeoJSON: () => fromGeoJSON,
|
|
29
|
+
toGeoJSON: () => toGeoJSON
|
|
30
|
+
});
|
|
31
|
+
module.exports = __toCommonJS(web_exports);
|
|
32
|
+
|
|
33
|
+
// src/error.js
|
|
34
|
+
var PolylineError = class extends Error {
|
|
35
|
+
constructor(code, message, index) {
|
|
36
|
+
super(index == null ? message : message + " at " + index);
|
|
37
|
+
this.name = "PolylineError";
|
|
38
|
+
this.code = code;
|
|
39
|
+
this.index = index;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var fail = (code, message, index) => {
|
|
43
|
+
throw new PolylineError(code, message, index);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
// src/core.js
|
|
47
|
+
var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
|
|
48
|
+
function opts(o) {
|
|
49
|
+
st.swap = false;
|
|
50
|
+
st.strict = true;
|
|
51
|
+
st.dims = 2;
|
|
52
|
+
return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
|
|
53
|
+
}
|
|
54
|
+
function objOpts(o) {
|
|
55
|
+
const { order, dimensions: d } = o;
|
|
56
|
+
if (order == "lnglat") st.swap = true;
|
|
57
|
+
else if (order != null && order != "latlng") bad("order");
|
|
58
|
+
if (o.strict === false) st.strict = false;
|
|
59
|
+
if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
|
|
60
|
+
const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
|
|
61
|
+
st.zf = o.zFactor != null ? num(o.zFactor) : f;
|
|
62
|
+
return f;
|
|
63
|
+
}
|
|
64
|
+
var bad = (name) => fail("option", "Invalid " + name);
|
|
65
|
+
var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
|
|
66
|
+
var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
|
|
67
|
+
var LIMIT = 2 ** 29;
|
|
68
|
+
function slowDecode(str, f, flat) {
|
|
69
|
+
if (typeof str != "string") fail("input", "Expected a string");
|
|
70
|
+
const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
|
|
71
|
+
let v = 0, scale = 1, i = 0, c;
|
|
72
|
+
for (; i < str.length; i++) {
|
|
73
|
+
c = str.charCodeAt(i) - 63;
|
|
74
|
+
if (c < 0 || c > 63) {
|
|
75
|
+
if (strict) fail("char", "Invalid character", i);
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
v += (c & 31) * scale;
|
|
79
|
+
scale *= 32;
|
|
80
|
+
if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
|
|
81
|
+
if (c < 32) {
|
|
82
|
+
values.push(v % 2 ? -(v + 1) / 2 : v / 2);
|
|
83
|
+
v = 0;
|
|
84
|
+
scale = 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
|
|
88
|
+
const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
|
|
89
|
+
for (let j = 0, k = 0; j < n; j++) {
|
|
90
|
+
const p = flat ? out : Array(d);
|
|
91
|
+
for (let a = 0; a < d; a++, k++) {
|
|
92
|
+
sum[a] += values[k];
|
|
93
|
+
p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
|
|
94
|
+
}
|
|
95
|
+
if (!flat) out[j] = p;
|
|
96
|
+
}
|
|
97
|
+
return out;
|
|
98
|
+
}
|
|
99
|
+
function slowEncode(points, f, flat) {
|
|
100
|
+
if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
|
|
101
|
+
const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
|
|
102
|
+
if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
|
|
103
|
+
let s = "";
|
|
104
|
+
for (let i = 0; i < (n | 0); i++) {
|
|
105
|
+
const p = flat ? 0 : points[i];
|
|
106
|
+
for (let a = 0; a < d; a++) {
|
|
107
|
+
const b = sw && a < 2 ? 1 - a : a;
|
|
108
|
+
let x = flat ? points[i * d + b] : p == null ? p : p.length >= 0 ? p[b] : a ? a > 1 ? p.alt ?? p.altitude : p.lng ?? p.lon ?? p.longitude : p.lat ?? p.latitude;
|
|
109
|
+
x = x == null ? NaN : +x * (a < 2 ? f : zf);
|
|
110
|
+
if (!(x - x == 0)) {
|
|
111
|
+
if (strict) fail("coordinate", "Invalid coordinate", i);
|
|
112
|
+
x = 0;
|
|
113
|
+
}
|
|
114
|
+
x = Math.sign(x) * Math.round(Math.abs(x));
|
|
115
|
+
let z = x - last[a];
|
|
116
|
+
last[a] = x;
|
|
117
|
+
z = z < 0 ? -z * 2 - 1 : z * 2;
|
|
118
|
+
if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
|
|
119
|
+
for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
|
|
120
|
+
s += String.fromCharCode(z + 63);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return s;
|
|
124
|
+
}
|
|
125
|
+
var decodeWith = (str, o, flat) => {
|
|
126
|
+
const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
|
|
127
|
+
return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
|
|
128
|
+
};
|
|
129
|
+
var flip = (out) => {
|
|
130
|
+
for (const p of out) {
|
|
131
|
+
const t = p[0];
|
|
132
|
+
p[0] = p[1];
|
|
133
|
+
p[1] = t;
|
|
134
|
+
}
|
|
135
|
+
return out;
|
|
136
|
+
};
|
|
137
|
+
var decode = (str, o) => decodeWith(str, o, 0);
|
|
138
|
+
var decodeFlat = (str, o) => decodeWith(str, o, 1);
|
|
139
|
+
function decodeLoop(str, f, sw, flat) {
|
|
140
|
+
const len = str.length, a = +sw;
|
|
141
|
+
let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
|
|
142
|
+
if (flat) {
|
|
143
|
+
for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
|
|
144
|
+
out = new Float64Array(n & ~1);
|
|
145
|
+
i = n = 0;
|
|
146
|
+
} else out = len < 64 ? [] : Array(len >> 1);
|
|
147
|
+
while (i < len) {
|
|
148
|
+
c = str.charCodeAt(i++) - 63;
|
|
149
|
+
bad2 |= c;
|
|
150
|
+
v = c & 31;
|
|
151
|
+
for (s = 5; c >= 32; s += 5) {
|
|
152
|
+
c = str.charCodeAt(i++) - 63;
|
|
153
|
+
bad2 |= c | 25 - s;
|
|
154
|
+
v |= (c & 31) << s;
|
|
155
|
+
}
|
|
156
|
+
lat += v >>> 1 ^ -(v & 1);
|
|
157
|
+
c = str.charCodeAt(i++) - 63;
|
|
158
|
+
bad2 |= c;
|
|
159
|
+
v = c & 31;
|
|
160
|
+
for (s = 5; c >= 32; s += 5) {
|
|
161
|
+
c = str.charCodeAt(i++) - 63;
|
|
162
|
+
bad2 |= c | 25 - s;
|
|
163
|
+
v |= (c & 31) << s;
|
|
164
|
+
}
|
|
165
|
+
lng += v >>> 1 ^ -(v & 1);
|
|
166
|
+
if (flat) {
|
|
167
|
+
out[n + a] = lat / f;
|
|
168
|
+
out[n + 1 - a] = lng / f;
|
|
169
|
+
n += 2;
|
|
170
|
+
} else out[n++] = [lat / f, lng / f];
|
|
171
|
+
}
|
|
172
|
+
if (bad2 & ~63 || i != len) return null;
|
|
173
|
+
if (out.length != n) out.length = n;
|
|
174
|
+
return out;
|
|
175
|
+
}
|
|
176
|
+
var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
|
|
177
|
+
function chars(z) {
|
|
178
|
+
let s = "";
|
|
179
|
+
for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
|
|
180
|
+
return s + String.fromCharCode(z + 63);
|
|
181
|
+
}
|
|
182
|
+
var encodeWith = (src, o, flat) => {
|
|
183
|
+
const f = opts(o);
|
|
184
|
+
return (st.dims == 2 && f <= 1e6 && (flat ? src != null && !(src.length % 2) : Array.isArray(src)) ? encodeLoop(src, f, +st.swap, flat) : null) ?? slowEncode(src, f, flat);
|
|
185
|
+
};
|
|
186
|
+
var encode = (points, o) => encodeWith(points, o, 0);
|
|
187
|
+
var encodeFlat = (values, o) => encodeWith(values, o, 1);
|
|
188
|
+
function encodeLoop(src, f, a, flat) {
|
|
189
|
+
const n = flat ? src.length >> 1 : src.length;
|
|
190
|
+
let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
|
|
191
|
+
try {
|
|
192
|
+
for (; i < n; i++) {
|
|
193
|
+
if (flat) {
|
|
194
|
+
x = src[i * 2 + a];
|
|
195
|
+
y = src[i * 2 + 1 - a];
|
|
196
|
+
} else {
|
|
197
|
+
pt = src[i];
|
|
198
|
+
x = pt[a];
|
|
199
|
+
y = pt[1 - a];
|
|
200
|
+
}
|
|
201
|
+
if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
|
|
202
|
+
p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
|
|
203
|
+
q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
|
|
204
|
+
if (x < 0.5 && x > -0.5) p = 0;
|
|
205
|
+
if (y < 0.5 && y > -0.5) q = 0;
|
|
206
|
+
z = p - la;
|
|
207
|
+
z = z << 1 ^ z >> 31;
|
|
208
|
+
s += z < 1024 ? CHARS[z] : chars(z);
|
|
209
|
+
z = q - lb;
|
|
210
|
+
z = z << 1 ^ z >> 31;
|
|
211
|
+
s += z < 1024 ? CHARS[z] : chars(z);
|
|
212
|
+
la = p;
|
|
213
|
+
lb = q;
|
|
214
|
+
}
|
|
215
|
+
} catch {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
return s;
|
|
219
|
+
}
|
|
220
|
+
var lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
|
|
221
|
+
var latLngs = (decode2) => (str, o) => decode2(str, o).map(([lat, lng]) => ({ lat, lng }));
|
|
222
|
+
var toGeo = (decode2) => (str, o) => ({ type: "LineString", coordinates: decode2(str, lngLat(o)) });
|
|
223
|
+
var fromGeo = (encode2) => (g, o) => {
|
|
224
|
+
if (g?.type == "Feature") g = g.geometry;
|
|
225
|
+
return g?.type == "LineString" ? encode2(g.coordinates, lngLat(o)) : fail("input", "Expected a LineString");
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/web.js
|
|
229
|
+
var decodeLatLng = /* @__PURE__ */ latLngs(decode);
|
|
230
|
+
var toGeoJSON = /* @__PURE__ */ toGeo(decode);
|
|
231
|
+
var fromGeoJSON = /* @__PURE__ */ fromGeo(encode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,200 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@duoquote/polytini",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Encode and decode Google encoded polylines. Small, strict by default, with fast paths for Node, Bun and Deno.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"polyline",
|
|
7
|
+
"encoded polyline",
|
|
8
|
+
"google maps",
|
|
9
|
+
"geojson",
|
|
10
|
+
"osrm",
|
|
11
|
+
"valhalla",
|
|
12
|
+
"leaflet",
|
|
13
|
+
"turf"
|
|
14
|
+
],
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"author": "Güven Değirmenci",
|
|
17
|
+
"homepage": "https://github.com/Duoquote/polytini#readme",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/Duoquote/polytini.git"
|
|
21
|
+
},
|
|
22
|
+
"bugs": "https://github.com/Duoquote/polytini/issues",
|
|
23
|
+
"type": "module",
|
|
24
|
+
"sideEffects": [
|
|
25
|
+
"./src/leaflet-auto.js",
|
|
26
|
+
"./dist/leaflet-auto.cjs"
|
|
27
|
+
],
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"browser": {
|
|
31
|
+
"types": "./types/index.d.ts",
|
|
32
|
+
"default": "./src/browser.js"
|
|
33
|
+
},
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./dist/types/index.d.cts",
|
|
36
|
+
"default": "./dist/node.cjs"
|
|
37
|
+
},
|
|
38
|
+
"types": "./types/index.d.ts",
|
|
39
|
+
"bun": "./src/bun.js",
|
|
40
|
+
"deno": "./src/deno.js",
|
|
41
|
+
"node": "./src/node.js",
|
|
42
|
+
"default": "./src/web.js"
|
|
43
|
+
},
|
|
44
|
+
"./web": {
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./dist/types/index.d.cts",
|
|
47
|
+
"default": "./dist/web.cjs"
|
|
48
|
+
},
|
|
49
|
+
"types": "./types/index.d.ts",
|
|
50
|
+
"default": "./src/web.js"
|
|
51
|
+
},
|
|
52
|
+
"./node": {
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/types/index.d.cts",
|
|
55
|
+
"default": "./dist/node.cjs"
|
|
56
|
+
},
|
|
57
|
+
"types": "./types/index.d.ts",
|
|
58
|
+
"default": "./src/node.js"
|
|
59
|
+
},
|
|
60
|
+
"./browser": {
|
|
61
|
+
"types": "./types/index.d.ts",
|
|
62
|
+
"default": "./src/browser.js"
|
|
63
|
+
},
|
|
64
|
+
"./wasm": {
|
|
65
|
+
"types": "./types/wasm.d.ts",
|
|
66
|
+
"default": "./src/wasm.js"
|
|
67
|
+
},
|
|
68
|
+
"./turf": {
|
|
69
|
+
"require": {
|
|
70
|
+
"types": "./dist/types/turf.d.cts",
|
|
71
|
+
"default": "./dist/turf.cjs"
|
|
72
|
+
},
|
|
73
|
+
"types": "./types/turf.d.ts",
|
|
74
|
+
"default": "./src/turf.js"
|
|
75
|
+
},
|
|
76
|
+
"./leaflet": {
|
|
77
|
+
"require": {
|
|
78
|
+
"types": "./dist/types/leaflet.d.cts",
|
|
79
|
+
"default": "./dist/leaflet.cjs"
|
|
80
|
+
},
|
|
81
|
+
"types": "./types/leaflet.d.ts",
|
|
82
|
+
"default": "./src/leaflet.js"
|
|
83
|
+
},
|
|
84
|
+
"./presets": {
|
|
85
|
+
"require": {
|
|
86
|
+
"types": "./dist/types/presets.d.cts",
|
|
87
|
+
"default": "./dist/presets.cjs"
|
|
88
|
+
},
|
|
89
|
+
"types": "./types/presets.d.ts",
|
|
90
|
+
"default": "./src/presets.js"
|
|
91
|
+
},
|
|
92
|
+
"./flexible": {
|
|
93
|
+
"require": {
|
|
94
|
+
"types": "./dist/types/flexible.d.cts",
|
|
95
|
+
"default": "./dist/flexible.cjs"
|
|
96
|
+
},
|
|
97
|
+
"types": "./types/flexible.d.ts",
|
|
98
|
+
"default": "./src/flexible.js"
|
|
99
|
+
},
|
|
100
|
+
"./google": {
|
|
101
|
+
"require": {
|
|
102
|
+
"types": "./dist/types/google.d.cts",
|
|
103
|
+
"default": "./dist/google.cjs"
|
|
104
|
+
},
|
|
105
|
+
"types": "./types/google.d.ts",
|
|
106
|
+
"default": "./src/google.js"
|
|
107
|
+
},
|
|
108
|
+
"./maplibre": {
|
|
109
|
+
"require": {
|
|
110
|
+
"types": "./dist/types/maplibre.d.cts",
|
|
111
|
+
"default": "./dist/maplibre.cjs"
|
|
112
|
+
},
|
|
113
|
+
"types": "./types/maplibre.d.ts",
|
|
114
|
+
"default": "./src/maplibre.js"
|
|
115
|
+
},
|
|
116
|
+
"./mapbox": {
|
|
117
|
+
"require": {
|
|
118
|
+
"types": "./dist/types/mapbox.d.cts",
|
|
119
|
+
"default": "./dist/mapbox.cjs"
|
|
120
|
+
},
|
|
121
|
+
"types": "./types/mapbox.d.ts",
|
|
122
|
+
"default": "./src/mapbox.js"
|
|
123
|
+
},
|
|
124
|
+
"./deckgl": {
|
|
125
|
+
"require": {
|
|
126
|
+
"types": "./dist/types/deckgl.d.cts",
|
|
127
|
+
"default": "./dist/deckgl.cjs"
|
|
128
|
+
},
|
|
129
|
+
"types": "./types/deckgl.d.ts",
|
|
130
|
+
"default": "./src/deckgl.js"
|
|
131
|
+
},
|
|
132
|
+
"./leaflet/auto": {
|
|
133
|
+
"require": {
|
|
134
|
+
"types": "./dist/types/leaflet-auto.d.cts",
|
|
135
|
+
"default": "./dist/leaflet-auto.cjs"
|
|
136
|
+
},
|
|
137
|
+
"types": "./types/leaflet-auto.d.ts",
|
|
138
|
+
"default": "./src/leaflet-auto.js"
|
|
139
|
+
},
|
|
140
|
+
"./openlayers": {
|
|
141
|
+
"types": "./types/openlayers.d.ts",
|
|
142
|
+
"default": "./src/openlayers.js"
|
|
143
|
+
},
|
|
144
|
+
"./package.json": "./package.json"
|
|
145
|
+
},
|
|
146
|
+
"types": "./types/index.d.ts",
|
|
147
|
+
"main": "./dist/node.cjs",
|
|
148
|
+
"bin": {
|
|
149
|
+
"polytini": "src/cli.js"
|
|
150
|
+
},
|
|
151
|
+
"files": [
|
|
152
|
+
"src",
|
|
153
|
+
"types",
|
|
154
|
+
"dist",
|
|
155
|
+
"wasm/polytini.wasm"
|
|
156
|
+
],
|
|
157
|
+
"engines": {
|
|
158
|
+
"node": ">=22"
|
|
159
|
+
},
|
|
160
|
+
"publishConfig": {
|
|
161
|
+
"access": "public"
|
|
162
|
+
},
|
|
163
|
+
"scripts": {
|
|
164
|
+
"build": "node scripts/build.js",
|
|
165
|
+
"build:wasm": "node scripts/build-wasm.js",
|
|
166
|
+
"prepack": "node scripts/build.js",
|
|
167
|
+
"test": "node test/run.js",
|
|
168
|
+
"test:bun": "bun test/run.js",
|
|
169
|
+
"test:deno": "deno run --allow-read --allow-env --allow-run --allow-write test/run.js",
|
|
170
|
+
"test:browser": "node test/browser.js",
|
|
171
|
+
"size": "node scripts/size.js",
|
|
172
|
+
"smoke": "node test/smoke.js",
|
|
173
|
+
"check:deps": "node scripts/check-deps.js"
|
|
174
|
+
},
|
|
175
|
+
"devDependencies": {
|
|
176
|
+
"@deck.gl/core": "^9.4.2",
|
|
177
|
+
"@deck.gl/geo-layers": "^9.4.2",
|
|
178
|
+
"@deck.gl/layers": "^9.4.2",
|
|
179
|
+
"@here/flexpolyline": "^0.1.0",
|
|
180
|
+
"@maplibre/maplibre-gl-style-spec": "^26.11.0",
|
|
181
|
+
"@turf/helpers": "^7.4.0",
|
|
182
|
+
"@turf/turf": "^7.4.0",
|
|
183
|
+
"@types/geojson": "^7946.0.16",
|
|
184
|
+
"@types/google.maps": "^3.67.0",
|
|
185
|
+
"@types/leaflet": "^1.9.23",
|
|
186
|
+
"c8": "^12.0.0",
|
|
187
|
+
"esbuild": "^0.28.2",
|
|
188
|
+
"fast-check": "^4.11.0",
|
|
189
|
+
"jsdom": "^29.1.1",
|
|
190
|
+
"leaflet": "^1.9.4",
|
|
191
|
+
"leaflet-2": "npm:leaflet@^2.0.0-beta.5",
|
|
192
|
+
"mapbox-gl": "^3.36.0",
|
|
193
|
+
"maplibre-gl": "^6.19.0",
|
|
194
|
+
"ol": "^10.11.0",
|
|
195
|
+
"playwright-core": "^1.65.1",
|
|
196
|
+
"tinybench": "^6.2.5",
|
|
197
|
+
"typescript": "^7.0.2",
|
|
198
|
+
"wabt": "^1.0.39"
|
|
199
|
+
}
|
|
200
|
+
}
|
package/src/browser.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Browser entry (the "browser" export condition): the portable core, except
|
|
2
|
+
// that long lines encode through TextDecoder (text.js). In headless Chrome
|
|
3
|
+
// that was about 50% faster from 1,000 points up and the same below 512,
|
|
4
|
+
// where it falls back to the core. Decoding stays on the core's charCodeAt
|
|
5
|
+
// loop: TextEncoder.encodeInto made it slower in Chrome. No Node, Bun or
|
|
6
|
+
// Deno globals.
|
|
7
|
+
/* @ts-self-types="../types/index.d.ts" */
|
|
8
|
+
import { decode, latLngs, toGeo, fromGeo } from './core.js';
|
|
9
|
+
import { encode } from './text.js';
|
|
10
|
+
|
|
11
|
+
export { decode, decodeFlat, PolylineError } from './core.js';
|
|
12
|
+
export { encode, encodeFlat } from './text.js';
|
|
13
|
+
export const decodeLatLng = /* @__PURE__ */ latLngs(decode);
|
|
14
|
+
export const toGeoJSON = /* @__PURE__ */ toGeo(decode);
|
|
15
|
+
export const fromGeoJSON = /* @__PURE__ */ fromGeo(encode);
|
package/src/bun.js
ADDED