@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,185 @@
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/mapbox.js
20
+ var mapbox_exports = {};
21
+ __export(mapbox_exports, {
22
+ addPolylineLayer: () => addPolylineLayer,
23
+ polylineData: () => polylineData,
24
+ polylineSource: () => polylineSource,
25
+ setPolylineData: () => setPolylineData
26
+ });
27
+ module.exports = __toCommonJS(mapbox_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
+ var decodeWith = (str, o, flat) => {
96
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
97
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
98
+ };
99
+ var flip = (out) => {
100
+ for (const p of out) {
101
+ const t = p[0];
102
+ p[0] = p[1];
103
+ p[1] = t;
104
+ }
105
+ return out;
106
+ };
107
+ var decode = (str, o) => decodeWith(str, o, 0);
108
+ function decodeLoop(str, f, sw, flat) {
109
+ const len = str.length, a = +sw;
110
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
111
+ if (flat) {
112
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
113
+ out = new Float64Array(n & ~1);
114
+ i = n = 0;
115
+ } else out = len < 64 ? [] : Array(len >> 1);
116
+ while (i < len) {
117
+ c = str.charCodeAt(i++) - 63;
118
+ bad2 |= c;
119
+ v = c & 31;
120
+ for (s = 5; c >= 32; s += 5) {
121
+ c = str.charCodeAt(i++) - 63;
122
+ bad2 |= c | 25 - s;
123
+ v |= (c & 31) << s;
124
+ }
125
+ lat += v >>> 1 ^ -(v & 1);
126
+ c = str.charCodeAt(i++) - 63;
127
+ bad2 |= c;
128
+ v = c & 31;
129
+ for (s = 5; c >= 32; s += 5) {
130
+ c = str.charCodeAt(i++) - 63;
131
+ bad2 |= c | 25 - s;
132
+ v |= (c & 31) << s;
133
+ }
134
+ lng += v >>> 1 ^ -(v & 1);
135
+ if (flat) {
136
+ out[n + a] = lat / f;
137
+ out[n + 1 - a] = lng / f;
138
+ n += 2;
139
+ } else out[n++] = [lat / f, lng / f];
140
+ }
141
+ if (bad2 & ~63 || i != len) return null;
142
+ if (out.length != n) out.length = n;
143
+ return out;
144
+ }
145
+
146
+ // src/turf.js
147
+ var lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
148
+ function bbox(c) {
149
+ const b = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
150
+ const walk = (a) => {
151
+ if (typeof a[0] == "number") {
152
+ b[0] = Math.min(b[0], a[0]);
153
+ b[1] = Math.min(b[1], a[1]);
154
+ b[2] = Math.max(b[2], a[0]);
155
+ b[3] = Math.max(b[3], a[1]);
156
+ } else a.forEach(walk);
157
+ };
158
+ walk(c);
159
+ return b;
160
+ }
161
+ function feature(geometry, o, i) {
162
+ const f = { type: "Feature" }, p = o?.properties;
163
+ if (o?.id != null) f.id = Array.isArray(o.id) ? o.id[i] : o.id;
164
+ if (o?.bbox && geometry.coordinates.length) f.bbox = bbox(geometry.coordinates);
165
+ f.properties = (Array.isArray(p) ? p[i] : p) ?? {};
166
+ f.geometry = geometry;
167
+ return f;
168
+ }
169
+ var toFeature = (str, o, i) => feature({ type: "LineString", coordinates: decode(str, lngLat(o)) }, o, i);
170
+ var toFeatureCollection = (strs, o) => ({ type: "FeatureCollection", features: strs.map((s, i) => toFeature(s, o, i)) });
171
+
172
+ // src/maplibre.js
173
+ var list = (encoded) => typeof encoded == "string" ? [encoded] : encoded;
174
+ var polylineData = (encoded, options) => toFeatureCollection(list(encoded), options);
175
+ var polylineSource = (encoded, options) => ({ ...options?.source, type: "geojson", data: polylineData(encoded, options) });
176
+ function addPolylineLayer(map, id, encoded, options) {
177
+ map.addSource(id, polylineSource(encoded, options));
178
+ map.addLayer({ id, type: "line", source: id, ...options?.layer }, options?.beforeId);
179
+ return map;
180
+ }
181
+ function setPolylineData(map, id, encoded, options) {
182
+ const source = map.getSource(id);
183
+ if (typeof source?.setData != "function") fail("input", "No GeoJSON source named " + id);
184
+ return source.setData(polylineData(encoded, options));
185
+ }
@@ -0,0 +1,185 @@
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/maplibre.js
20
+ var maplibre_exports = {};
21
+ __export(maplibre_exports, {
22
+ addPolylineLayer: () => addPolylineLayer,
23
+ polylineData: () => polylineData,
24
+ polylineSource: () => polylineSource,
25
+ setPolylineData: () => setPolylineData
26
+ });
27
+ module.exports = __toCommonJS(maplibre_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
+ var decodeWith = (str, o, flat) => {
96
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
97
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
98
+ };
99
+ var flip = (out) => {
100
+ for (const p of out) {
101
+ const t = p[0];
102
+ p[0] = p[1];
103
+ p[1] = t;
104
+ }
105
+ return out;
106
+ };
107
+ var decode = (str, o) => decodeWith(str, o, 0);
108
+ function decodeLoop(str, f, sw, flat) {
109
+ const len = str.length, a = +sw;
110
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
111
+ if (flat) {
112
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
113
+ out = new Float64Array(n & ~1);
114
+ i = n = 0;
115
+ } else out = len < 64 ? [] : Array(len >> 1);
116
+ while (i < len) {
117
+ c = str.charCodeAt(i++) - 63;
118
+ bad2 |= c;
119
+ v = c & 31;
120
+ for (s = 5; c >= 32; s += 5) {
121
+ c = str.charCodeAt(i++) - 63;
122
+ bad2 |= c | 25 - s;
123
+ v |= (c & 31) << s;
124
+ }
125
+ lat += v >>> 1 ^ -(v & 1);
126
+ c = str.charCodeAt(i++) - 63;
127
+ bad2 |= c;
128
+ v = c & 31;
129
+ for (s = 5; c >= 32; s += 5) {
130
+ c = str.charCodeAt(i++) - 63;
131
+ bad2 |= c | 25 - s;
132
+ v |= (c & 31) << s;
133
+ }
134
+ lng += v >>> 1 ^ -(v & 1);
135
+ if (flat) {
136
+ out[n + a] = lat / f;
137
+ out[n + 1 - a] = lng / f;
138
+ n += 2;
139
+ } else out[n++] = [lat / f, lng / f];
140
+ }
141
+ if (bad2 & ~63 || i != len) return null;
142
+ if (out.length != n) out.length = n;
143
+ return out;
144
+ }
145
+
146
+ // src/turf.js
147
+ var lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
148
+ function bbox(c) {
149
+ const b = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
150
+ const walk = (a) => {
151
+ if (typeof a[0] == "number") {
152
+ b[0] = Math.min(b[0], a[0]);
153
+ b[1] = Math.min(b[1], a[1]);
154
+ b[2] = Math.max(b[2], a[0]);
155
+ b[3] = Math.max(b[3], a[1]);
156
+ } else a.forEach(walk);
157
+ };
158
+ walk(c);
159
+ return b;
160
+ }
161
+ function feature(geometry, o, i) {
162
+ const f = { type: "Feature" }, p = o?.properties;
163
+ if (o?.id != null) f.id = Array.isArray(o.id) ? o.id[i] : o.id;
164
+ if (o?.bbox && geometry.coordinates.length) f.bbox = bbox(geometry.coordinates);
165
+ f.properties = (Array.isArray(p) ? p[i] : p) ?? {};
166
+ f.geometry = geometry;
167
+ return f;
168
+ }
169
+ var toFeature = (str, o, i) => feature({ type: "LineString", coordinates: decode(str, lngLat(o)) }, o, i);
170
+ var toFeatureCollection = (strs, o) => ({ type: "FeatureCollection", features: strs.map((s, i) => toFeature(s, o, i)) });
171
+
172
+ // src/maplibre.js
173
+ var list = (encoded) => typeof encoded == "string" ? [encoded] : encoded;
174
+ var polylineData = (encoded, options) => toFeatureCollection(list(encoded), options);
175
+ var polylineSource = (encoded, options) => ({ ...options?.source, type: "geojson", data: polylineData(encoded, options) });
176
+ function addPolylineLayer(map, id, encoded, options) {
177
+ map.addSource(id, polylineSource(encoded, options));
178
+ map.addLayer({ id, type: "line", source: id, ...options?.layer }, options?.beforeId);
179
+ return map;
180
+ }
181
+ function setPolylineData(map, id, encoded, options) {
182
+ const source = map.getSource(id);
183
+ if (typeof source?.setData != "function") fail("input", "No GeoJSON source named " + id);
184
+ return source.setData(polylineData(encoded, options));
185
+ }
package/dist/node.cjs ADDED
@@ -0,0 +1,322 @@
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/node.js
20
+ var node_exports = {};
21
+ __export(node_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(node_exports);
32
+ var import_node_buffer = require("node:buffer");
33
+
34
+ // src/error.js
35
+ var PolylineError = class extends Error {
36
+ constructor(code, message, index) {
37
+ super(index == null ? message : message + " at " + index);
38
+ this.name = "PolylineError";
39
+ this.code = code;
40
+ this.index = index;
41
+ }
42
+ };
43
+ var fail = (code, message, index) => {
44
+ throw new PolylineError(code, message, index);
45
+ };
46
+
47
+ // src/core.js
48
+ var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
49
+ function opts(o) {
50
+ st.swap = false;
51
+ st.strict = true;
52
+ st.dims = 2;
53
+ return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
54
+ }
55
+ function objOpts(o) {
56
+ const { order, dimensions: d } = o;
57
+ if (order == "lnglat") st.swap = true;
58
+ else if (order != null && order != "latlng") bad("order");
59
+ if (o.strict === false) st.strict = false;
60
+ if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
61
+ const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
62
+ st.zf = o.zFactor != null ? num(o.zFactor) : f;
63
+ return f;
64
+ }
65
+ var bad = (name) => fail("option", "Invalid " + name);
66
+ var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
67
+ var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
68
+ var LIMIT = 2 ** 29;
69
+ function slowDecode(str, f, flat) {
70
+ if (typeof str != "string") fail("input", "Expected a string");
71
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
72
+ let v = 0, scale = 1, i = 0, c;
73
+ for (; i < str.length; i++) {
74
+ c = str.charCodeAt(i) - 63;
75
+ if (c < 0 || c > 63) {
76
+ if (strict) fail("char", "Invalid character", i);
77
+ continue;
78
+ }
79
+ v += (c & 31) * scale;
80
+ scale *= 32;
81
+ if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
82
+ if (c < 32) {
83
+ values.push(v % 2 ? -(v + 1) / 2 : v / 2);
84
+ v = 0;
85
+ scale = 1;
86
+ }
87
+ }
88
+ if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
89
+ const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
90
+ for (let j = 0, k = 0; j < n; j++) {
91
+ const p = flat ? out : Array(d);
92
+ for (let a = 0; a < d; a++, k++) {
93
+ sum[a] += values[k];
94
+ p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
95
+ }
96
+ if (!flat) out[j] = p;
97
+ }
98
+ return out;
99
+ }
100
+ function slowEncode(points, f, flat) {
101
+ if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
102
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
103
+ if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
104
+ let s = "";
105
+ for (let i = 0; i < (n | 0); i++) {
106
+ const p = flat ? 0 : points[i];
107
+ for (let a = 0; a < d; a++) {
108
+ const b = sw && a < 2 ? 1 - a : a;
109
+ 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;
110
+ x = x == null ? NaN : +x * (a < 2 ? f : zf);
111
+ if (!(x - x == 0)) {
112
+ if (strict) fail("coordinate", "Invalid coordinate", i);
113
+ x = 0;
114
+ }
115
+ x = Math.sign(x) * Math.round(Math.abs(x));
116
+ let z = x - last[a];
117
+ last[a] = x;
118
+ z = z < 0 ? -z * 2 - 1 : z * 2;
119
+ if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
120
+ for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
121
+ s += String.fromCharCode(z + 63);
122
+ }
123
+ }
124
+ return s;
125
+ }
126
+ var flip = (out) => {
127
+ for (const p of out) {
128
+ const t = p[0];
129
+ p[0] = p[1];
130
+ p[1] = t;
131
+ }
132
+ return out;
133
+ };
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 lngLat = (o) => ({ ...typeof o == "number" ? { precision: o } : o, order: "lnglat" });
172
+ var latLngs = (decode2) => (str, o) => decode2(str, o).map(([lat, lng]) => ({ lat, lng }));
173
+ var toGeo = (decode2) => (str, o) => ({ type: "LineString", coordinates: decode2(str, lngLat(o)) });
174
+ var fromGeo = (encode2) => (g, o) => {
175
+ if (g?.type == "Feature") g = g.geometry;
176
+ return g?.type == "LineString" ? encode2(g.coordinates, lngLat(o)) : fail("input", "Expected a LineString");
177
+ };
178
+
179
+ // src/fast.js
180
+ var KEEP = 1 << 20;
181
+ function fast(Buffer3, grow = Infinity) {
182
+ const ucs2Write = Buffer3.prototype.ucs2Write, latin1Slice = Buffer3.prototype.latin1Slice;
183
+ let kept, k16, k32, u16;
184
+ const views = (buf) => [buf, new Uint16Array(buf.buffer, 0, buf.length >> 1), new Uint32Array(buf.buffer, 0, buf.length >> 2)];
185
+ [kept, k16, k32] = views(Buffer3.allocUnsafeSlow(1 << 14));
186
+ const scratch = (bytes) => bytes <= kept.length ? kept : bytes <= KEEP ? ([kept, k16, k32] = views(Buffer3.allocUnsafeSlow(bytes)))[0] : Buffer3.allocUnsafeSlow(bytes);
187
+ function load(str, len) {
188
+ const buf = scratch((len + 4) * 2 + 8);
189
+ ucs2Write.call(buf, str, 0);
190
+ let u32 = k32;
191
+ if (buf == kept) u16 = k16;
192
+ else [, u16, u32] = views(buf);
193
+ u16[len] = u16[len + 1] = u16[len + 2] = 63;
194
+ let more = 0;
195
+ for (let k = 0, w = len + 1 >> 1; k < w; k++) {
196
+ const y = u32[k] + 65537 >>> 5 & 65537;
197
+ more += (y & 65535) + (y >>> 16);
198
+ }
199
+ return len - more;
200
+ }
201
+ function big(str, f) {
202
+ const len = str.length, want = load(str, len) >> 1, b = u16, out = want > grow ? [] : Array(want);
203
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s;
204
+ while (i < len) {
205
+ c = b[i++] - 63;
206
+ bad2 |= c;
207
+ v = c & 31;
208
+ for (s = 5; c >= 32; s += 5) {
209
+ c = b[i++] - 63;
210
+ bad2 |= c | 25 - s;
211
+ v |= (c & 31) << s;
212
+ }
213
+ lat += v >>> 1 ^ -(v & 1);
214
+ c = b[i++] - 63;
215
+ bad2 |= c;
216
+ v = c & 31;
217
+ for (s = 5; c >= 32; s += 5) {
218
+ c = b[i++] - 63;
219
+ bad2 |= c | 25 - s;
220
+ v |= (c & 31) << s;
221
+ }
222
+ lng += v >>> 1 ^ -(v & 1);
223
+ out[n++] = [lat / f, lng / f];
224
+ }
225
+ return bad2 & ~63 || i != len ? null : out;
226
+ }
227
+ function bigFlat(str, f, sw) {
228
+ const len = str.length, out = new Float64Array(load(str, len) & ~1), b = u16, a = +sw;
229
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s;
230
+ while (i < len) {
231
+ c = b[i++] - 63;
232
+ bad2 |= c;
233
+ v = c & 31;
234
+ for (s = 5; c >= 32; s += 5) {
235
+ c = b[i++] - 63;
236
+ bad2 |= c | 25 - s;
237
+ v |= (c & 31) << s;
238
+ }
239
+ lat += v >>> 1 ^ -(v & 1);
240
+ c = b[i++] - 63;
241
+ bad2 |= c;
242
+ v = c & 31;
243
+ for (s = 5; c >= 32; s += 5) {
244
+ c = b[i++] - 63;
245
+ bad2 |= c | 25 - s;
246
+ v |= (c & 31) << s;
247
+ }
248
+ lng += v >>> 1 ^ -(v & 1);
249
+ out[n + a] = lat / f;
250
+ out[n + 1 - a] = lng / f;
251
+ n += 2;
252
+ }
253
+ return bad2 & ~63 || i != len ? null : out;
254
+ }
255
+ const decodeWith = (str, o, flat) => {
256
+ const f = opts(o);
257
+ if (st.dims != 2 || typeof str != "string") return slowDecode(str, f, flat);
258
+ const out = str.length < 64 ? decodeLoop(str, f, st.swap, flat) : flat ? bigFlat(str, f, st.swap) : big(str, f);
259
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
260
+ };
261
+ function encodeLoop(src, f, a, flat) {
262
+ const n = flat ? src.length >> 1 : src.length, buf = scratch(n * 14 + 8);
263
+ let i = 0, k = 0, la = 0, lb = 0, x, y, p, q, z, pt;
264
+ try {
265
+ for (; i < n; i++) {
266
+ if (flat) {
267
+ x = src[i * 2 + a];
268
+ y = src[i * 2 + 1 - a];
269
+ } else {
270
+ pt = src[i];
271
+ x = pt[a];
272
+ y = pt[1 - a];
273
+ }
274
+ if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
275
+ p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
276
+ q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
277
+ if (x < 0.5 && x > -0.5) p = 0;
278
+ if (y < 0.5 && y > -0.5) q = 0;
279
+ z = p - la;
280
+ z = z << 1 ^ z >> 31;
281
+ for (; z >= 32; z >>>= 5) buf[k++] = (z & 31) + 95;
282
+ buf[k++] = z + 63;
283
+ z = q - lb;
284
+ z = z << 1 ^ z >> 31;
285
+ for (; z >= 32; z >>>= 5) buf[k++] = (z & 31) + 95;
286
+ buf[k++] = z + 63;
287
+ la = p;
288
+ lb = q;
289
+ }
290
+ } catch {
291
+ return null;
292
+ }
293
+ return latin1Slice.call(buf, 0, k);
294
+ }
295
+ const encodeWith = (src, o, flat) => {
296
+ const f = opts(o);
297
+ 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);
298
+ };
299
+ return {
300
+ decode: (str, o) => decodeWith(str, o, 0),
301
+ decodeFlat: (str, o) => decodeWith(str, o, 1),
302
+ encode: (src, o) => encodeWith(src, o, 0),
303
+ encodeFlat: (src, o) => encodeWith(src, o, 1)
304
+ };
305
+ }
306
+
307
+ // src/node.js
308
+ var { decode, decodeFlat, encode, encodeFlat } = fast(import_node_buffer.Buffer, process.versions.v8?.startsWith("12.") ? 32768 : Infinity);
309
+ var decodeLatLng = latLngs(decode);
310
+ var toGeoJSON = toGeo(decode);
311
+ var fromGeoJSON = fromGeo(encode);
312
+ // Annotate the CommonJS export names for ESM import in node:
313
+ 0 && (module.exports = {
314
+ PolylineError,
315
+ decode,
316
+ decodeFlat,
317
+ decodeLatLng,
318
+ encode,
319
+ encodeFlat,
320
+ fromGeoJSON,
321
+ toGeoJSON
322
+ });