@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.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +119 -2
  3. package/dist/deckgl.cjs +250 -0
  4. package/dist/flexible.cjs +229 -0
  5. package/dist/google.cjs +232 -0
  6. package/dist/leaflet-auto.cjs +209 -0
  7. package/dist/leaflet.cjs +231 -0
  8. package/dist/mapbox.cjs +185 -0
  9. package/dist/maplibre.cjs +185 -0
  10. package/dist/node.cjs +322 -0
  11. package/dist/presets.cjs +65 -0
  12. package/dist/turf.cjs +267 -0
  13. package/dist/types/cli.d.cts +2 -0
  14. package/dist/types/deckgl.d.cts +72 -0
  15. package/dist/types/flexible.d.cts +92 -0
  16. package/dist/types/geojson.jsr.d.cts +111 -0
  17. package/dist/types/google.d.cts +48 -0
  18. package/dist/types/google.jsr.d.cts +72 -0
  19. package/dist/types/index.d.cts +109 -0
  20. package/dist/types/leaflet-auto.d.cts +4 -0
  21. package/dist/types/leaflet-auto.jsr.d.cts +2 -0
  22. package/dist/types/leaflet.d.cts +39 -0
  23. package/dist/types/leaflet.jsr.d.cts +15 -0
  24. package/dist/types/mapbox.d.cts +50 -0
  25. package/dist/types/mapbox.jsr.d.cts +5 -0
  26. package/dist/types/maplibre.d.cts +54 -0
  27. package/dist/types/maplibre.jsr.d.cts +92 -0
  28. package/dist/types/openlayers.d.cts +23 -0
  29. package/dist/types/openlayers.jsr.d.cts +42 -0
  30. package/dist/types/presets.d.cts +70 -0
  31. package/dist/types/turf.d.cts +33 -0
  32. package/dist/types/turf.jsr.d.cts +46 -0
  33. package/dist/types/wasm.d.cts +42 -0
  34. package/dist/web.cjs +231 -0
  35. package/package.json +198 -4
  36. package/src/browser.js +15 -0
  37. package/src/bun.js +4 -0
  38. package/src/cli-lib.js +160 -0
  39. package/src/cli.js +7 -0
  40. package/src/core.js +268 -0
  41. package/src/deckgl.js +176 -0
  42. package/src/deno.js +12 -0
  43. package/src/error.js +15 -0
  44. package/src/fast.js +179 -0
  45. package/src/flexible.js +283 -0
  46. package/src/google.js +70 -0
  47. package/src/leaflet-auto.js +11 -0
  48. package/src/leaflet.js +44 -0
  49. package/src/mapbox.js +10 -0
  50. package/src/maplibre.js +57 -0
  51. package/src/node.js +17 -0
  52. package/src/openlayers.js +172 -0
  53. package/src/presets.js +242 -0
  54. package/src/text.js +111 -0
  55. package/src/turf.js +80 -0
  56. package/src/wasm-bytes.js +2 -0
  57. package/src/wasm.js +235 -0
  58. package/src/web.js +9 -0
  59. package/types/cli.d.ts +2 -0
  60. package/types/deckgl.d.ts +72 -0
  61. package/types/flexible.d.ts +92 -0
  62. package/types/geojson.jsr.d.ts +111 -0
  63. package/types/google.d.ts +48 -0
  64. package/types/google.jsr.d.ts +72 -0
  65. package/types/index.d.ts +109 -0
  66. package/types/leaflet-auto.d.ts +4 -0
  67. package/types/leaflet-auto.jsr.d.ts +2 -0
  68. package/types/leaflet.d.ts +39 -0
  69. package/types/leaflet.jsr.d.ts +15 -0
  70. package/types/mapbox.d.ts +50 -0
  71. package/types/mapbox.jsr.d.ts +5 -0
  72. package/types/maplibre.d.ts +54 -0
  73. package/types/maplibre.jsr.d.ts +92 -0
  74. package/types/openlayers.d.ts +23 -0
  75. package/types/openlayers.jsr.d.ts +42 -0
  76. package/types/presets.d.ts +70 -0
  77. package/types/turf.d.ts +33 -0
  78. package/types/turf.jsr.d.ts +46 -0
  79. package/types/wasm.d.ts +42 -0
  80. package/wasm/polytini.wasm +0 -0
@@ -0,0 +1,65 @@
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/presets.js
20
+ var presets_exports = {};
21
+ __export(presets_exports, {
22
+ google: () => google,
23
+ graphhopper: () => graphhopper,
24
+ graphhopper3d: () => graphhopper3d,
25
+ mapbox: () => mapbox,
26
+ mapbox6: () => mapbox6,
27
+ openrouteservice: () => openrouteservice,
28
+ openrouteservice3d: () => openrouteservice3d,
29
+ osrm: () => osrm,
30
+ osrm6: () => osrm6,
31
+ otp: () => otp,
32
+ presets: () => presets,
33
+ stadia: () => stadia,
34
+ strava: () => strava,
35
+ valhalla: () => valhalla
36
+ });
37
+ module.exports = __toCommonJS(presets_exports);
38
+ var google = { precision: 5, order: "latlng" };
39
+ var osrm = { precision: 5, order: "lnglat" };
40
+ var osrm6 = { precision: 6, order: "lnglat" };
41
+ var valhalla = { precision: 6, order: "lnglat" };
42
+ var stadia = { precision: 6, order: "lnglat" };
43
+ var graphhopper = { precision: 5, order: "lnglat" };
44
+ var graphhopper3d = { precision: 5, dimensions: 3, zFactor: 100, order: "lnglat" };
45
+ var openrouteservice = { precision: 5, order: "lnglat" };
46
+ var openrouteservice3d = { precision: 5, dimensions: 3, zFactor: 100, order: "lnglat" };
47
+ var mapbox = { precision: 5, order: "lnglat" };
48
+ var mapbox6 = { precision: 6, order: "lnglat" };
49
+ var strava = { precision: 5, order: "latlng" };
50
+ var otp = { precision: 5, order: "latlng" };
51
+ var presets = {
52
+ google,
53
+ osrm,
54
+ osrm6,
55
+ valhalla,
56
+ stadia,
57
+ graphhopper,
58
+ graphhopper3d,
59
+ openrouteservice,
60
+ openrouteservice3d,
61
+ mapbox,
62
+ mapbox6,
63
+ strava,
64
+ otp
65
+ };
package/dist/turf.cjs ADDED
@@ -0,0 +1,267 @@
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/turf.js
20
+ var turf_exports = {};
21
+ __export(turf_exports, {
22
+ fromGeoJSON: () => fromGeoJSON,
23
+ toFeature: () => toFeature,
24
+ toFeatureCollection: () => toFeatureCollection,
25
+ toPolygonFeature: () => toPolygonFeature
26
+ });
27
+ module.exports = __toCommonJS(turf_exports);
28
+
29
+ // src/error.js
30
+ var PolylineError = class extends Error {
31
+ constructor(code, message, index) {
32
+ super(index == null ? message : message + " at " + index);
33
+ this.name = "PolylineError";
34
+ this.code = code;
35
+ this.index = index;
36
+ }
37
+ };
38
+ var fail = (code, message, index) => {
39
+ throw new PolylineError(code, message, index);
40
+ };
41
+
42
+ // src/core.js
43
+ var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
44
+ function opts(o) {
45
+ st.swap = false;
46
+ st.strict = true;
47
+ st.dims = 2;
48
+ return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
49
+ }
50
+ function objOpts(o) {
51
+ const { order, dimensions: d } = o;
52
+ if (order == "lnglat") st.swap = true;
53
+ else if (order != null && order != "latlng") bad("order");
54
+ if (o.strict === false) st.strict = false;
55
+ if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
56
+ const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
57
+ st.zf = o.zFactor != null ? num(o.zFactor) : f;
58
+ return f;
59
+ }
60
+ var bad = (name) => fail("option", "Invalid " + name);
61
+ var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
62
+ var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
63
+ var LIMIT = 2 ** 29;
64
+ function slowDecode(str, f, flat) {
65
+ if (typeof str != "string") fail("input", "Expected a string");
66
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
67
+ let v = 0, scale = 1, i = 0, c;
68
+ for (; i < str.length; i++) {
69
+ c = str.charCodeAt(i) - 63;
70
+ if (c < 0 || c > 63) {
71
+ if (strict) fail("char", "Invalid character", i);
72
+ continue;
73
+ }
74
+ v += (c & 31) * scale;
75
+ scale *= 32;
76
+ if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
77
+ if (c < 32) {
78
+ values.push(v % 2 ? -(v + 1) / 2 : v / 2);
79
+ v = 0;
80
+ scale = 1;
81
+ }
82
+ }
83
+ if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
84
+ const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
85
+ for (let j = 0, k = 0; j < n; j++) {
86
+ const p = flat ? out : Array(d);
87
+ for (let a = 0; a < d; a++, k++) {
88
+ sum[a] += values[k];
89
+ p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
90
+ }
91
+ if (!flat) out[j] = p;
92
+ }
93
+ return out;
94
+ }
95
+ function slowEncode(points, f, flat) {
96
+ if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
97
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
98
+ if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
99
+ let s = "";
100
+ for (let i = 0; i < (n | 0); i++) {
101
+ const p = flat ? 0 : points[i];
102
+ for (let a = 0; a < d; a++) {
103
+ const b = sw && a < 2 ? 1 - a : a;
104
+ 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;
105
+ x = x == null ? NaN : +x * (a < 2 ? f : zf);
106
+ if (!(x - x == 0)) {
107
+ if (strict) fail("coordinate", "Invalid coordinate", i);
108
+ x = 0;
109
+ }
110
+ x = Math.sign(x) * Math.round(Math.abs(x));
111
+ let z = x - last[a];
112
+ last[a] = x;
113
+ z = z < 0 ? -z * 2 - 1 : z * 2;
114
+ if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
115
+ for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
116
+ s += String.fromCharCode(z + 63);
117
+ }
118
+ }
119
+ return s;
120
+ }
121
+ var decodeWith = (str, o, flat) => {
122
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
123
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
124
+ };
125
+ var flip = (out) => {
126
+ for (const p of out) {
127
+ const t = p[0];
128
+ p[0] = p[1];
129
+ p[1] = t;
130
+ }
131
+ return out;
132
+ };
133
+ var decode = (str, o) => decodeWith(str, o, 0);
134
+ function decodeLoop(str, f, sw, flat) {
135
+ const len = str.length, a = +sw;
136
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
137
+ if (flat) {
138
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
139
+ out = new Float64Array(n & ~1);
140
+ i = n = 0;
141
+ } else out = len < 64 ? [] : Array(len >> 1);
142
+ while (i < len) {
143
+ c = str.charCodeAt(i++) - 63;
144
+ bad2 |= c;
145
+ v = c & 31;
146
+ for (s = 5; c >= 32; s += 5) {
147
+ c = str.charCodeAt(i++) - 63;
148
+ bad2 |= c | 25 - s;
149
+ v |= (c & 31) << s;
150
+ }
151
+ lat += v >>> 1 ^ -(v & 1);
152
+ c = str.charCodeAt(i++) - 63;
153
+ bad2 |= c;
154
+ v = c & 31;
155
+ for (s = 5; c >= 32; s += 5) {
156
+ c = str.charCodeAt(i++) - 63;
157
+ bad2 |= c | 25 - s;
158
+ v |= (c & 31) << s;
159
+ }
160
+ lng += v >>> 1 ^ -(v & 1);
161
+ if (flat) {
162
+ out[n + a] = lat / f;
163
+ out[n + 1 - a] = lng / f;
164
+ n += 2;
165
+ } else out[n++] = [lat / f, lng / f];
166
+ }
167
+ if (bad2 & ~63 || i != len) return null;
168
+ if (out.length != n) out.length = n;
169
+ return out;
170
+ }
171
+ var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
172
+ function chars(z) {
173
+ let s = "";
174
+ for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
175
+ return s + String.fromCharCode(z + 63);
176
+ }
177
+ var encodeWith = (src, o, flat) => {
178
+ const f = opts(o);
179
+ 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);
180
+ };
181
+ var encode = (points, o) => encodeWith(points, o, 0);
182
+ function encodeLoop(src, f, a, flat) {
183
+ const n = flat ? src.length >> 1 : src.length;
184
+ let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
185
+ try {
186
+ for (; i < n; i++) {
187
+ if (flat) {
188
+ x = src[i * 2 + a];
189
+ y = src[i * 2 + 1 - a];
190
+ } else {
191
+ pt = src[i];
192
+ x = pt[a];
193
+ y = pt[1 - a];
194
+ }
195
+ if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
196
+ p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
197
+ q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
198
+ if (x < 0.5 && x > -0.5) p = 0;
199
+ if (y < 0.5 && y > -0.5) q = 0;
200
+ z = p - la;
201
+ z = z << 1 ^ z >> 31;
202
+ s += z < 1024 ? CHARS[z] : chars(z);
203
+ z = q - lb;
204
+ z = z << 1 ^ z >> 31;
205
+ s += z < 1024 ? CHARS[z] : chars(z);
206
+ la = p;
207
+ lb = q;
208
+ }
209
+ } catch {
210
+ return null;
211
+ }
212
+ return s;
213
+ }
214
+
215
+ // src/turf.js
216
+ var lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
217
+ function bbox(c) {
218
+ const b = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
219
+ const walk = (a) => {
220
+ if (typeof a[0] == "number") {
221
+ b[0] = Math.min(b[0], a[0]);
222
+ b[1] = Math.min(b[1], a[1]);
223
+ b[2] = Math.max(b[2], a[0]);
224
+ b[3] = Math.max(b[3], a[1]);
225
+ } else a.forEach(walk);
226
+ };
227
+ walk(c);
228
+ return b;
229
+ }
230
+ function feature(geometry, o, i) {
231
+ const f = { type: "Feature" }, p = o?.properties;
232
+ if (o?.id != null) f.id = Array.isArray(o.id) ? o.id[i] : o.id;
233
+ if (o?.bbox && geometry.coordinates.length) f.bbox = bbox(geometry.coordinates);
234
+ f.properties = (Array.isArray(p) ? p[i] : p) ?? {};
235
+ f.geometry = geometry;
236
+ return f;
237
+ }
238
+ var toFeature = (str, o, i) => feature({ type: "LineString", coordinates: decode(str, lngLat(o)) }, o, i);
239
+ var toFeatureCollection = (strs, o) => ({ type: "FeatureCollection", features: strs.map((s, i) => toFeature(s, o, i)) });
240
+ var toPolygonFeature = (rings, o) => feature({ type: "Polygon", coordinates: rings.map((s) => decode(s, lngLat(o))) }, o, 0);
241
+ function fromGeoJSON(g, o) {
242
+ const out = [], ll = lngLat(o);
243
+ const walk = (g2) => {
244
+ switch (g2?.type) {
245
+ case "Feature":
246
+ return g2.geometry && walk(g2.geometry);
247
+ case "FeatureCollection":
248
+ return g2.features.forEach(walk);
249
+ case "GeometryCollection":
250
+ return g2.geometries.forEach(walk);
251
+ case "LineString":
252
+ return out.push(encode(g2.coordinates, ll));
253
+ case "MultiLineString":
254
+ case "Polygon":
255
+ return g2.coordinates.forEach((c) => out.push(encode(c, ll)));
256
+ case "MultiPolygon":
257
+ return g2.coordinates.forEach((p) => p.forEach((c) => out.push(encode(c, ll))));
258
+ case "Point":
259
+ case "MultiPoint":
260
+ return;
261
+ default:
262
+ fail("input", "Expected GeoJSON");
263
+ }
264
+ };
265
+ walk(g);
266
+ return out;
267
+ }
@@ -0,0 +1,2 @@
1
+ // The polytini command. Running it is the whole API.
2
+ export {};
@@ -0,0 +1,72 @@
1
+ // Types for @duoquote/polytini/deckgl. The results are plain objects in
2
+ // deck.gl's binary data shape, so they need no deck.gl types: they can be
3
+ // passed as `data` to PathLayer, TripsLayer and SolidPolygonLayer.
4
+ import type { Options } from './index.d.ts';
5
+
6
+ /** Options for binaryPolygons: polytini's options plus float32. */
7
+ export interface BinaryOptions extends Options {
8
+ /** Float32Array instead of Float64Array. Smaller, and enough for most maps; deck.gl uses 64-bit positions only when given them. Default false. */
9
+ float32?: boolean;
10
+ }
11
+
12
+ /** Options for binaryPaths: BinaryOptions plus timestamps. */
13
+ export interface PathOptions extends BinaryOptions {
14
+ /**
15
+ * For TripsLayer: the last value of each point (with dimensions 3 or 4) goes
16
+ * to attributes.getTimestamps instead of the positions. The values are
17
+ * divided by zFactor, like any value after the second, and always come out
18
+ * as a Float32Array, because TripsLayer's timestamp attribute is 32-bit
19
+ * (deck.gl 9.4 drew nothing given Float64Array timestamps). Default false.
20
+ */
21
+ timestamps?: boolean;
22
+ }
23
+
24
+ /** A deck.gl binary attribute. */
25
+ export interface BinaryAttribute<T extends Float32Array | Float64Array = Float32Array | Float64Array, S extends number = number> {
26
+ /** The values, size per vertex. */
27
+ value: T;
28
+ /** Values per vertex. */
29
+ size: S;
30
+ }
31
+
32
+ /** What binaryPaths returns: `data` for PathLayer or TripsLayer. */
33
+ export interface BinaryPaths<T extends Float32Array | Float64Array = Float32Array | Float64Array> {
34
+ /** The number of paths, one per string. */
35
+ length: number;
36
+ /** The first vertex of each path, plus the vertex count at the end (length + 1 entries). */
37
+ startIndices: Uint32Array;
38
+ /** The vertex attributes. */
39
+ attributes: {
40
+ /** [lng, lat] (size 2) or [lng, lat, z] (size 3) per vertex. */
41
+ getPath: BinaryAttribute<T, 2 | 3>;
42
+ /** One value per vertex, with the timestamps option. Always 32-bit. */
43
+ getTimestamps?: BinaryAttribute<Float32Array, 1>;
44
+ };
45
+ }
46
+
47
+ /** What binaryPolygons returns: `data` for SolidPolygonLayer. */
48
+ export interface BinaryPolygons<T extends Float32Array | Float64Array = Float32Array | Float64Array> {
49
+ /** The number of polygons, one ring per string. */
50
+ length: number;
51
+ /** The first vertex of each ring, plus the vertex count at the end (length + 1 entries). */
52
+ startIndices: Uint32Array;
53
+ /** The vertex attributes. */
54
+ attributes: {
55
+ /** [lng, lat] (size 2) or [lng, lat, z] (size 3) per vertex, every ring closed. */
56
+ getPolygon: BinaryAttribute<T, 2 | 3>;
57
+ };
58
+ }
59
+
60
+ /** Binary data for PathLayer and TripsLayer, one path per string. Pass _pathType: 'open' to skip deck.gl's normalization. */
61
+ export function binaryPaths(encoded: string | string[], options: PathOptions & { float32: true }): BinaryPaths<Float32Array>;
62
+ /** binaryPaths with Float64Array positions, the default. */
63
+ export function binaryPaths(encoded: string | string[], options?: number | (PathOptions & { float32?: false })): BinaryPaths<Float64Array>;
64
+ /** binaryPaths when float32 isn't known until runtime. */
65
+ export function binaryPaths(encoded: string | string[], options?: number | PathOptions): BinaryPaths;
66
+
67
+ /** Binary data for SolidPolygonLayer, one closed ring per string (no holes). */
68
+ export function binaryPolygons(encoded: string | string[], options: BinaryOptions & { float32: true }): BinaryPolygons<Float32Array>;
69
+ /** binaryPolygons with Float64Array positions, the default. */
70
+ export function binaryPolygons(encoded: string | string[], options?: number | (BinaryOptions & { float32?: false })): BinaryPolygons<Float64Array>;
71
+ /** binaryPolygons when float32 isn't known until runtime. */
72
+ export function binaryPolygons(encoded: string | string[], options?: number | BinaryOptions): BinaryPolygons;
@@ -0,0 +1,92 @@
1
+ // Types for @duoquote/polytini/flexible, HERE's Flexible Polyline format
2
+ // (version 1). Separate from the Google-format entry points.
3
+ import type { ErrorCode } from './index.d.ts';
4
+
5
+ /** Third dimension types, as stored in the header. */
6
+ /** No third value: a 2D line. */
7
+ export const ABSENT: 0;
8
+ /** The third value is a level, such as a floor. */
9
+ export const LEVEL: 1;
10
+ /** The third value is altitude. */
11
+ export const ALTITUDE: 2;
12
+ /** The third value is elevation. */
13
+ export const ELEVATION: 3;
14
+ /** Reserved by the spec: decode accepts it, encode refuses it. */
15
+ export const RESERVED1: 4;
16
+ /** Reserved by the spec: decode accepts it, encode refuses it. */
17
+ export const RESERVED2: 5;
18
+ /** A third value of your own meaning. */
19
+ export const CUSTOM1: 6;
20
+ /** A second type for a third value of your own meaning. */
21
+ export const CUSTOM2: 7;
22
+
23
+ /** Any type a header can hold. */
24
+ export type ThirdDimension = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7;
25
+ /** The types encode accepts. */
26
+ export type EncodableThirdDimension = 0 | 1 | 2 | 3 | 6 | 7;
27
+
28
+ /** The header fields of an encoded line. */
29
+ export interface Header {
30
+ /** Decimal places of latitude and longitude, 0 to 15. */
31
+ precision: number;
32
+ /** What the third value means. ABSENT (0) for 2D lines. */
33
+ thirdDim: ThirdDimension;
34
+ /** Decimal places of the third value, 0 to 15. */
35
+ thirdDimPrecision: number;
36
+ }
37
+
38
+ /** What decode returns: the header and the points. */
39
+ export interface DecodedResult extends Header {
40
+ /** [lat, lng] points, or [lat, lng, z] when thirdDim is not ABSENT. */
41
+ polyline: number[][];
42
+ }
43
+
44
+ /** The header fields encode writes. */
45
+ export interface EncodeOptions {
46
+ /** Decimal places of latitude and longitude, an integer from 0 to 15. Default 5. */
47
+ precision?: number;
48
+ /** Type of the third value. Default ABSENT, which ignores any third value. */
49
+ thirdDim?: EncodableThirdDimension;
50
+ /** Decimal places of the third value, an integer from 0 to 15. Default 0. */
51
+ thirdDimPrecision?: number;
52
+ }
53
+
54
+ /** [lat, lng] or [lat, lng, z] points, or one flat array of numbers: [lat0, lng0, lat1, lng1, ...]. */
55
+ export type Points = ArrayLike<ArrayLike<number>> | ArrayLike<number>;
56
+
57
+ /** The argument of @here/flexpolyline's encode. */
58
+ export interface EncodeInput extends EncodeOptions {
59
+ /** The points. */
60
+ polyline: Points;
61
+ }
62
+
63
+ /**
64
+ * Codes of a PolylineError from this entry: the main entry's, plus 'version'
65
+ * for a format version other than 1 or a header with bits set above bit 10.
66
+ */
67
+ export type FlexibleErrorCode = Exclude<ErrorCode, 'init'> | 'version';
68
+
69
+ /** The same class as the main entry's PolylineError. */
70
+ export class PolylineError extends Error {
71
+ /** Always "PolylineError". */
72
+ readonly name: 'PolylineError';
73
+ /** What went wrong. */
74
+ readonly code: FlexibleErrorCode;
75
+ /** Character index (decode) or point index (encode), when there is one. */
76
+ readonly index: number | undefined;
77
+ /** Makes an error; the message gets " at <index>" appended when there's an index. */
78
+ constructor(code: FlexibleErrorCode, message: string, index?: number);
79
+ }
80
+
81
+ /**
82
+ * Encodes a line. Takes @here/flexpolyline's argument, or the points with
83
+ * the header fields in `options`, which win over the input object's.
84
+ * Rounds half away from zero.
85
+ */
86
+ export function encode(input: EncodeInput | Points, options?: EncodeOptions): string;
87
+
88
+ /** Decodes a line, with its header. The same result shape as @here/flexpolyline. */
89
+ export function decode(str: string): DecodedResult;
90
+
91
+ /** Reads only the header. */
92
+ export function header(str: string): Header;
@@ -0,0 +1,111 @@
1
+ // The GeoJSON types the JSR type files need, written out here because JSR
2
+ // builds its docs without node_modules, so `geojson` (@types/geojson) can't
3
+ // be imported. The npm type files use @types/geojson itself. These follow
4
+ // RFC 7946 and have the same shape as @types/geojson's, so values flow
5
+ // between the two.
6
+
7
+ /** [longitude, latitude], then an optional altitude and anything else. */
8
+ export type Position = number[];
9
+
10
+ /** [west, south, east, north], or with altitudes [west, south, low, east, north, high]. */
11
+ export type BBox = [number, number, number, number] | [number, number, number, number, number, number];
12
+
13
+ /** The properties of a Feature: any JSON object, or null. */
14
+ export type GeoJsonProperties = { [name: string]: unknown } | null;
15
+
16
+ /** A GeoJSON Point. */
17
+ export interface Point {
18
+ /** Always "Point". */
19
+ type: 'Point';
20
+ /** The position. */
21
+ coordinates: Position;
22
+ /** Optional bounding box. */
23
+ bbox?: BBox;
24
+ }
25
+
26
+ /** A GeoJSON MultiPoint. */
27
+ export interface MultiPoint {
28
+ /** Always "MultiPoint". */
29
+ type: 'MultiPoint';
30
+ /** The positions. */
31
+ coordinates: Position[];
32
+ /** Optional bounding box. */
33
+ bbox?: BBox;
34
+ }
35
+
36
+ /** A GeoJSON LineString: two or more positions. */
37
+ export interface LineString {
38
+ /** Always "LineString". */
39
+ type: 'LineString';
40
+ /** The positions, [lng, lat]. */
41
+ coordinates: Position[];
42
+ /** Optional bounding box. */
43
+ bbox?: BBox;
44
+ }
45
+
46
+ /** A GeoJSON MultiLineString. */
47
+ export interface MultiLineString {
48
+ /** Always "MultiLineString". */
49
+ type: 'MultiLineString';
50
+ /** One position array per line. */
51
+ coordinates: Position[][];
52
+ /** Optional bounding box. */
53
+ bbox?: BBox;
54
+ }
55
+
56
+ /** A GeoJSON Polygon: the outer ring, then holes. */
57
+ export interface Polygon {
58
+ /** Always "Polygon". */
59
+ type: 'Polygon';
60
+ /** One closed position array per ring. */
61
+ coordinates: Position[][];
62
+ /** Optional bounding box. */
63
+ bbox?: BBox;
64
+ }
65
+
66
+ /** A GeoJSON MultiPolygon. */
67
+ export interface MultiPolygon {
68
+ /** Always "MultiPolygon". */
69
+ type: 'MultiPolygon';
70
+ /** One ring array per polygon. */
71
+ coordinates: Position[][][];
72
+ /** Optional bounding box. */
73
+ bbox?: BBox;
74
+ }
75
+
76
+ /** A GeoJSON GeometryCollection. */
77
+ export interface GeometryCollection {
78
+ /** Always "GeometryCollection". */
79
+ type: 'GeometryCollection';
80
+ /** The geometries. */
81
+ geometries: Geometry[];
82
+ /** Optional bounding box. */
83
+ bbox?: BBox;
84
+ }
85
+
86
+ /** Any GeoJSON geometry. */
87
+ export type Geometry = Point | MultiPoint | LineString | MultiLineString | Polygon | MultiPolygon | GeometryCollection;
88
+
89
+ /** A GeoJSON Feature. */
90
+ export interface Feature<G extends Geometry | null = Geometry, P = GeoJsonProperties> {
91
+ /** Always "Feature". */
92
+ type: 'Feature';
93
+ /** The geometry, or null. */
94
+ geometry: G;
95
+ /** The properties. */
96
+ properties: P;
97
+ /** Optional id. */
98
+ id?: string | number;
99
+ /** Optional bounding box. */
100
+ bbox?: BBox;
101
+ }
102
+
103
+ /** A GeoJSON FeatureCollection. */
104
+ export interface FeatureCollection<G extends Geometry | null = Geometry, P = GeoJsonProperties> {
105
+ /** Always "FeatureCollection". */
106
+ type: 'FeatureCollection';
107
+ /** The features. */
108
+ features: Feature<G, P>[];
109
+ /** Optional bounding box. */
110
+ bbox?: BBox;
111
+ }
@@ -0,0 +1,48 @@
1
+ // Types for @duoquote/polytini/google, using the google.maps types from
2
+ // @types/google.maps. Those are global declarations, not a module, so they
3
+ // are pulled in with a reference directive: types only, nothing at runtime.
4
+ /// <reference types="google.maps" />
5
+ import type * as P from './index.d.ts';
6
+ import type { Options, Point } from './index.d.ts';
7
+
8
+ export declare const PolylineError: typeof P.PolylineError;
9
+ export type PolylineError = P.PolylineError;
10
+
11
+ /** A LatLng constructor: google.maps.LatLng or anything built the same way. */
12
+ export type LatLngConstructor = new (lat: number, lng: number, noClampNoWrap?: boolean) => google.maps.LatLng;
13
+
14
+ export interface DecodePathOptions extends Omit<Options, 'order'> {
15
+ /**
16
+ * The class to build points with. Default: globalThis.google.maps.LatLng
17
+ * when it exists. false or null returns LatLngLiteral objects.
18
+ */
19
+ LatLng?: LatLngConstructor | false | null;
20
+ /** Passed to the LatLng constructor. Without it, LatLng clamps latitude and wraps longitude into [-180, 180). */
21
+ noClampNoWrap?: boolean;
22
+ }
23
+
24
+ /** A point encodePath takes: google.maps.LatLng, LatLngLiteral or a [lat, lng] tuple. */
25
+ export type PathPoint = google.maps.LatLng | google.maps.LatLngLiteral | Point;
26
+
27
+ /**
28
+ * Decodes an encoded path to LatLngLiteral objects (`LatLng: false`).
29
+ */
30
+ export function decodePath(encodedPath: string, options: DecodePathOptions & { LatLng: false | null }): google.maps.LatLngLiteral[];
31
+ /**
32
+ * Decodes an encoded path, like google.maps.geometry.encoding.decodePath,
33
+ * to google.maps.LatLng objects. Without a `LatLng` option this uses
34
+ * globalThis.google.maps.LatLng; when the Maps JavaScript API isn't loaded
35
+ * the result is LatLngLiteral objects at runtime, so pass `LatLng: false`
36
+ * there to get that type. Strict by default: a malformed string throws a
37
+ * PolylineError unless `strict: false`.
38
+ */
39
+ export function decodePath(encodedPath: string, options?: number | (DecodePathOptions & { LatLng?: LatLngConstructor })): google.maps.LatLng[];
40
+ export function decodePath(encodedPath: string, options?: number | DecodePathOptions): google.maps.LatLng[] | google.maps.LatLngLiteral[];
41
+
42
+ /**
43
+ * Encodes a path, like google.maps.geometry.encoding.encodePath: an array or
44
+ * MVCArray of google.maps.LatLng, LatLngLiteral or [lat, lng] tuples, mixed
45
+ * or not. Precision 5 by default. `order: 'lnglat'` applies to tuples and
46
+ * LatLng objects; literals are read by name. Strict by default.
47
+ */
48
+ export function encodePath(path: readonly PathPoint[] | google.maps.MVCArray<PathPoint>, options?: number | Options): string;