@duoquote/polytini 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +120 -3
  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 +60 -0
  15. package/dist/types/flexible.d.cts +80 -0
  16. package/dist/types/google.d.cts +48 -0
  17. package/dist/types/google.jsr.d.cts +60 -0
  18. package/dist/types/index.d.cts +87 -0
  19. package/dist/types/leaflet-auto.d.cts +4 -0
  20. package/dist/types/leaflet-auto.jsr.d.cts +2 -0
  21. package/dist/types/leaflet.d.cts +39 -0
  22. package/dist/types/leaflet.jsr.d.cts +13 -0
  23. package/dist/types/mapbox.d.cts +50 -0
  24. package/dist/types/maplibre.d.cts +54 -0
  25. package/dist/types/openlayers.d.cts +23 -0
  26. package/dist/types/presets.d.cts +66 -0
  27. package/dist/types/turf.d.cts +33 -0
  28. package/dist/types/wasm.d.cts +33 -0
  29. package/dist/web.cjs +231 -0
  30. package/package.json +200 -6
  31. package/src/browser.js +15 -0
  32. package/src/bun.js +4 -0
  33. package/src/cli-lib.js +160 -0
  34. package/src/cli.js +7 -0
  35. package/src/core.js +268 -0
  36. package/src/deckgl.js +176 -0
  37. package/src/deno.js +12 -0
  38. package/src/error.js +15 -0
  39. package/src/fast.js +179 -0
  40. package/src/flexible.js +283 -0
  41. package/src/google.js +70 -0
  42. package/src/leaflet-auto.js +11 -0
  43. package/src/leaflet.js +44 -0
  44. package/src/mapbox.js +10 -0
  45. package/src/maplibre.js +57 -0
  46. package/src/node.js +17 -0
  47. package/src/openlayers.js +172 -0
  48. package/src/presets.js +242 -0
  49. package/src/text.js +111 -0
  50. package/src/turf.js +80 -0
  51. package/src/wasm-bytes.js +2 -0
  52. package/src/wasm.js +235 -0
  53. package/src/web.js +9 -0
  54. package/types/cli.d.ts +2 -0
  55. package/types/deckgl.d.ts +60 -0
  56. package/types/flexible.d.ts +80 -0
  57. package/types/google.d.ts +48 -0
  58. package/types/google.jsr.d.ts +60 -0
  59. package/types/index.d.ts +87 -0
  60. package/types/leaflet-auto.d.ts +4 -0
  61. package/types/leaflet-auto.jsr.d.ts +2 -0
  62. package/types/leaflet.d.ts +39 -0
  63. package/types/leaflet.jsr.d.ts +13 -0
  64. package/types/mapbox.d.ts +50 -0
  65. package/types/maplibre.d.ts +54 -0
  66. package/types/openlayers.d.ts +23 -0
  67. package/types/presets.d.ts +66 -0
  68. package/types/turf.d.ts +33 -0
  69. package/types/wasm.d.ts +33 -0
  70. package/wasm/polytini.wasm +0 -0
@@ -0,0 +1,232 @@
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/google.js
20
+ var google_exports = {};
21
+ __export(google_exports, {
22
+ PolylineError: () => PolylineError,
23
+ decodePath: () => decodePath,
24
+ encodePath: () => encodePath
25
+ });
26
+ module.exports = __toCommonJS(google_exports);
27
+
28
+ // src/error.js
29
+ var PolylineError = class extends Error {
30
+ constructor(code, message, index) {
31
+ super(index == null ? message : message + " at " + index);
32
+ this.name = "PolylineError";
33
+ this.code = code;
34
+ this.index = index;
35
+ }
36
+ };
37
+ var fail = (code, message, index) => {
38
+ throw new PolylineError(code, message, index);
39
+ };
40
+
41
+ // src/core.js
42
+ var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
43
+ function opts(o) {
44
+ st.swap = false;
45
+ st.strict = true;
46
+ st.dims = 2;
47
+ return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
48
+ }
49
+ function objOpts(o) {
50
+ const { order, dimensions: d } = o;
51
+ if (order == "lnglat") st.swap = true;
52
+ else if (order != null && order != "latlng") bad("order");
53
+ if (o.strict === false) st.strict = false;
54
+ if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
55
+ const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
56
+ st.zf = o.zFactor != null ? num(o.zFactor) : f;
57
+ return f;
58
+ }
59
+ var bad = (name) => fail("option", "Invalid " + name);
60
+ var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
61
+ var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
62
+ var LIMIT = 2 ** 29;
63
+ function slowDecode(str, f, flat) {
64
+ if (typeof str != "string") fail("input", "Expected a string");
65
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
66
+ let v = 0, scale = 1, i = 0, c;
67
+ for (; i < str.length; i++) {
68
+ c = str.charCodeAt(i) - 63;
69
+ if (c < 0 || c > 63) {
70
+ if (strict) fail("char", "Invalid character", i);
71
+ continue;
72
+ }
73
+ v += (c & 31) * scale;
74
+ scale *= 32;
75
+ if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
76
+ if (c < 32) {
77
+ values.push(v % 2 ? -(v + 1) / 2 : v / 2);
78
+ v = 0;
79
+ scale = 1;
80
+ }
81
+ }
82
+ if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
83
+ const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
84
+ for (let j = 0, k = 0; j < n; j++) {
85
+ const p = flat ? out : Array(d);
86
+ for (let a = 0; a < d; a++, k++) {
87
+ sum[a] += values[k];
88
+ p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
89
+ }
90
+ if (!flat) out[j] = p;
91
+ }
92
+ return out;
93
+ }
94
+ function slowEncode(points, f, flat) {
95
+ if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
96
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
97
+ if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
98
+ let s = "";
99
+ for (let i = 0; i < (n | 0); i++) {
100
+ const p = flat ? 0 : points[i];
101
+ for (let a = 0; a < d; a++) {
102
+ const b = sw && a < 2 ? 1 - a : a;
103
+ 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;
104
+ x = x == null ? NaN : +x * (a < 2 ? f : zf);
105
+ if (!(x - x == 0)) {
106
+ if (strict) fail("coordinate", "Invalid coordinate", i);
107
+ x = 0;
108
+ }
109
+ x = Math.sign(x) * Math.round(Math.abs(x));
110
+ let z = x - last[a];
111
+ last[a] = x;
112
+ z = z < 0 ? -z * 2 - 1 : z * 2;
113
+ if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
114
+ for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
115
+ s += String.fromCharCode(z + 63);
116
+ }
117
+ }
118
+ return s;
119
+ }
120
+ var decodeWith = (str, o, flat) => {
121
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
122
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
123
+ };
124
+ var flip = (out) => {
125
+ for (const p of out) {
126
+ const t = p[0];
127
+ p[0] = p[1];
128
+ p[1] = t;
129
+ }
130
+ return out;
131
+ };
132
+ var decode = (str, o) => decodeWith(str, o, 0);
133
+ function decodeLoop(str, f, sw, flat) {
134
+ const len = str.length, a = +sw;
135
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
136
+ if (flat) {
137
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
138
+ out = new Float64Array(n & ~1);
139
+ i = n = 0;
140
+ } else out = len < 64 ? [] : Array(len >> 1);
141
+ while (i < len) {
142
+ c = str.charCodeAt(i++) - 63;
143
+ bad2 |= c;
144
+ v = c & 31;
145
+ for (s = 5; c >= 32; s += 5) {
146
+ c = str.charCodeAt(i++) - 63;
147
+ bad2 |= c | 25 - s;
148
+ v |= (c & 31) << s;
149
+ }
150
+ lat += v >>> 1 ^ -(v & 1);
151
+ c = str.charCodeAt(i++) - 63;
152
+ bad2 |= c;
153
+ v = c & 31;
154
+ for (s = 5; c >= 32; s += 5) {
155
+ c = str.charCodeAt(i++) - 63;
156
+ bad2 |= c | 25 - s;
157
+ v |= (c & 31) << s;
158
+ }
159
+ lng += v >>> 1 ^ -(v & 1);
160
+ if (flat) {
161
+ out[n + a] = lat / f;
162
+ out[n + 1 - a] = lng / f;
163
+ n += 2;
164
+ } else out[n++] = [lat / f, lng / f];
165
+ }
166
+ if (bad2 & ~63 || i != len) return null;
167
+ if (out.length != n) out.length = n;
168
+ return out;
169
+ }
170
+ var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
171
+ function chars(z) {
172
+ let s = "";
173
+ for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
174
+ return s + String.fromCharCode(z + 63);
175
+ }
176
+ var encodeWith = (src, o, flat) => {
177
+ const f = opts(o);
178
+ 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);
179
+ };
180
+ var encode = (points, o) => encodeWith(points, o, 0);
181
+ function encodeLoop(src, f, a, flat) {
182
+ const n = flat ? src.length >> 1 : src.length;
183
+ let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
184
+ try {
185
+ for (; i < n; i++) {
186
+ if (flat) {
187
+ x = src[i * 2 + a];
188
+ y = src[i * 2 + 1 - a];
189
+ } else {
190
+ pt = src[i];
191
+ x = pt[a];
192
+ y = pt[1 - a];
193
+ }
194
+ if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
195
+ p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
196
+ q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
197
+ if (x < 0.5 && x > -0.5) p = 0;
198
+ if (y < 0.5 && y > -0.5) q = 0;
199
+ z = p - la;
200
+ z = z << 1 ^ z >> 31;
201
+ s += z < 1024 ? CHARS[z] : chars(z);
202
+ z = q - lb;
203
+ z = z << 1 ^ z >> 31;
204
+ s += z < 1024 ? CHARS[z] : chars(z);
205
+ la = p;
206
+ lb = q;
207
+ }
208
+ } catch {
209
+ return null;
210
+ }
211
+ return s;
212
+ }
213
+
214
+ // src/google.js
215
+ var latFirst = (o) => o?.order == "lnglat" ? { ...o, order: "latlng" } : o;
216
+ function decodePath(encodedPath, o) {
217
+ const C = o?.LatLng !== void 0 ? o.LatLng : globalThis.google?.maps?.LatLng;
218
+ const pts = decode(encodedPath, latFirst(o)), nw = o?.noClampNoWrap;
219
+ for (let i = 0; i < pts.length; i++) {
220
+ const [lat, lng] = pts[i];
221
+ pts[i] = C ? new C(lat, lng, nw) : { lat, lng };
222
+ }
223
+ return pts;
224
+ }
225
+ function encodePath(path, o) {
226
+ if (path && typeof path.getArray == "function") path = path.getArray();
227
+ if (Array.isArray(path)) {
228
+ const sw = o?.order == "lnglat";
229
+ path = path.map((p) => p && typeof p.lat == "function" ? sw ? [p.lng(), p.lat()] : [p.lat(), p.lng()] : p);
230
+ }
231
+ return encode(path, o);
232
+ }
@@ -0,0 +1,209 @@
1
+ // src/error.js
2
+ var PolylineError = class extends Error {
3
+ constructor(code, message, index) {
4
+ super(index == null ? message : message + " at " + index);
5
+ this.name = "PolylineError";
6
+ this.code = code;
7
+ this.index = index;
8
+ }
9
+ };
10
+ var fail = (code, message, index) => {
11
+ throw new PolylineError(code, message, index);
12
+ };
13
+
14
+ // src/core.js
15
+ var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
16
+ function opts(o) {
17
+ st.swap = false;
18
+ st.strict = true;
19
+ st.dims = 2;
20
+ return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
21
+ }
22
+ function objOpts(o) {
23
+ const { order, dimensions: d } = o;
24
+ if (order == "lnglat") st.swap = true;
25
+ else if (order != null && order != "latlng") bad("order");
26
+ if (o.strict === false) st.strict = false;
27
+ if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
28
+ const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
29
+ st.zf = o.zFactor != null ? num(o.zFactor) : f;
30
+ return f;
31
+ }
32
+ var bad = (name) => fail("option", "Invalid " + name);
33
+ var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
34
+ var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
35
+ var LIMIT = 2 ** 29;
36
+ function slowDecode(str, f, flat) {
37
+ if (typeof str != "string") fail("input", "Expected a string");
38
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
39
+ let v = 0, scale = 1, i = 0, c;
40
+ for (; i < str.length; i++) {
41
+ c = str.charCodeAt(i) - 63;
42
+ if (c < 0 || c > 63) {
43
+ if (strict) fail("char", "Invalid character", i);
44
+ continue;
45
+ }
46
+ v += (c & 31) * scale;
47
+ scale *= 32;
48
+ if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
49
+ if (c < 32) {
50
+ values.push(v % 2 ? -(v + 1) / 2 : v / 2);
51
+ v = 0;
52
+ scale = 1;
53
+ }
54
+ }
55
+ if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
56
+ const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
57
+ for (let j = 0, k = 0; j < n; j++) {
58
+ const p = flat ? out : Array(d);
59
+ for (let a = 0; a < d; a++, k++) {
60
+ sum[a] += values[k];
61
+ p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
62
+ }
63
+ if (!flat) out[j] = p;
64
+ }
65
+ return out;
66
+ }
67
+ function slowEncode(points, f, flat) {
68
+ if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
69
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
70
+ if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
71
+ let s = "";
72
+ for (let i = 0; i < (n | 0); i++) {
73
+ const p = flat ? 0 : points[i];
74
+ for (let a = 0; a < d; a++) {
75
+ const b = sw && a < 2 ? 1 - a : a;
76
+ 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;
77
+ x = x == null ? NaN : +x * (a < 2 ? f : zf);
78
+ if (!(x - x == 0)) {
79
+ if (strict) fail("coordinate", "Invalid coordinate", i);
80
+ x = 0;
81
+ }
82
+ x = Math.sign(x) * Math.round(Math.abs(x));
83
+ let z = x - last[a];
84
+ last[a] = x;
85
+ z = z < 0 ? -z * 2 - 1 : z * 2;
86
+ if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
87
+ for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
88
+ s += String.fromCharCode(z + 63);
89
+ }
90
+ }
91
+ return s;
92
+ }
93
+ var decodeWith = (str, o, flat) => {
94
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
95
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
96
+ };
97
+ var flip = (out) => {
98
+ for (const p of out) {
99
+ const t = p[0];
100
+ p[0] = p[1];
101
+ p[1] = t;
102
+ }
103
+ return out;
104
+ };
105
+ var decode = (str, o) => decodeWith(str, o, 0);
106
+ function decodeLoop(str, f, sw, flat) {
107
+ const len = str.length, a = +sw;
108
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
109
+ if (flat) {
110
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
111
+ out = new Float64Array(n & ~1);
112
+ i = n = 0;
113
+ } else out = len < 64 ? [] : Array(len >> 1);
114
+ while (i < len) {
115
+ c = str.charCodeAt(i++) - 63;
116
+ bad2 |= c;
117
+ v = c & 31;
118
+ for (s = 5; c >= 32; s += 5) {
119
+ c = str.charCodeAt(i++) - 63;
120
+ bad2 |= c | 25 - s;
121
+ v |= (c & 31) << s;
122
+ }
123
+ lat += v >>> 1 ^ -(v & 1);
124
+ c = str.charCodeAt(i++) - 63;
125
+ bad2 |= c;
126
+ v = c & 31;
127
+ for (s = 5; c >= 32; s += 5) {
128
+ c = str.charCodeAt(i++) - 63;
129
+ bad2 |= c | 25 - s;
130
+ v |= (c & 31) << s;
131
+ }
132
+ lng += v >>> 1 ^ -(v & 1);
133
+ if (flat) {
134
+ out[n + a] = lat / f;
135
+ out[n + 1 - a] = lng / f;
136
+ n += 2;
137
+ } else out[n++] = [lat / f, lng / f];
138
+ }
139
+ if (bad2 & ~63 || i != len) return null;
140
+ if (out.length != n) out.length = n;
141
+ return out;
142
+ }
143
+ var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
144
+ function chars(z) {
145
+ let s = "";
146
+ for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
147
+ return s + String.fromCharCode(z + 63);
148
+ }
149
+ var encodeWith = (src, o, flat) => {
150
+ const f = opts(o);
151
+ 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);
152
+ };
153
+ var encode = (points, o) => encodeWith(points, o, 0);
154
+ function encodeLoop(src, f, a, flat) {
155
+ const n = flat ? src.length >> 1 : src.length;
156
+ let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
157
+ try {
158
+ for (; i < n; i++) {
159
+ if (flat) {
160
+ x = src[i * 2 + a];
161
+ y = src[i * 2 + 1 - a];
162
+ } else {
163
+ pt = src[i];
164
+ x = pt[a];
165
+ y = pt[1 - a];
166
+ }
167
+ if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
168
+ p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
169
+ q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
170
+ if (x < 0.5 && x > -0.5) p = 0;
171
+ if (y < 0.5 && y > -0.5) q = 0;
172
+ z = p - la;
173
+ z = z << 1 ^ z >> 31;
174
+ s += z < 1024 ? CHARS[z] : chars(z);
175
+ z = q - lb;
176
+ z = z << 1 ^ z >> 31;
177
+ s += z < 1024 ? CHARS[z] : chars(z);
178
+ la = p;
179
+ lb = q;
180
+ }
181
+ } catch {
182
+ return null;
183
+ }
184
+ return s;
185
+ }
186
+
187
+ // src/leaflet.js
188
+ var toLatLngs = (s, o) => typeof s == "string" ? decode(s, o) : s.map((x) => toLatLngs(x, o));
189
+ var toStrings = (l, o) => Array.isArray(l[0]) ? l.map((x) => toStrings(x, o)) : encode(l.map((p) => [p.lat, p.lng]), o);
190
+ function install(L2) {
191
+ const { Polyline, Polygon } = L2;
192
+ const add = (C, name) => {
193
+ C.fromEncoded = (s, o) => new C(toLatLngs(s, o), o);
194
+ C.prototype.toEncoded = function(o) {
195
+ return toStrings(this.getLatLngs(), o);
196
+ };
197
+ C.prototype.encodePath = C.prototype.toEncoded;
198
+ if (Object.isExtensible(L2)) L2[name] = C.fromEncoded;
199
+ };
200
+ add(Polyline, "polylineEncoded");
201
+ add(Polygon, "polygonEncoded");
202
+ if (Object.isExtensible(L2)) L2.PolylineUtil ??= { encode, decode };
203
+ return L2;
204
+ }
205
+
206
+ // src/leaflet-auto.js
207
+ var L = globalThis.L;
208
+ if (!L?.Polyline) throw new Error("@duoquote/polytini/leaflet/auto: load Leaflet first, or call install(L) from @duoquote/polytini/leaflet");
209
+ install(L);
@@ -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/leaflet.js
20
+ var leaflet_exports = {};
21
+ __export(leaflet_exports, {
22
+ decode: () => decode,
23
+ encode: () => encode,
24
+ install: () => install
25
+ });
26
+ module.exports = __toCommonJS(leaflet_exports);
27
+
28
+ // src/error.js
29
+ var PolylineError = class extends Error {
30
+ constructor(code, message, index) {
31
+ super(index == null ? message : message + " at " + index);
32
+ this.name = "PolylineError";
33
+ this.code = code;
34
+ this.index = index;
35
+ }
36
+ };
37
+ var fail = (code, message, index) => {
38
+ throw new PolylineError(code, message, index);
39
+ };
40
+
41
+ // src/core.js
42
+ var st = { swap: false, strict: true, dims: 2, zf: 1e5 };
43
+ function opts(o) {
44
+ st.swap = false;
45
+ st.strict = true;
46
+ st.dims = 2;
47
+ return o && typeof o == "object" ? objOpts(o) : st.zf = o == null ? 1e5 : pow(o);
48
+ }
49
+ function objOpts(o) {
50
+ const { order, dimensions: d } = o;
51
+ if (order == "lnglat") st.swap = true;
52
+ else if (order != null && order != "latlng") bad("order");
53
+ if (o.strict === false) st.strict = false;
54
+ if (d != null) st.dims = d >= 1 && d <= 16 && d % 1 == 0 ? d : bad("dimensions");
55
+ const f = o.factor != null ? num(o.factor) : pow(o.precision ?? 5);
56
+ st.zf = o.zFactor != null ? num(o.zFactor) : f;
57
+ return f;
58
+ }
59
+ var bad = (name) => fail("option", "Invalid " + name);
60
+ var num = (f) => f > 0 && f < 1 / 0 ? f : bad("factor");
61
+ var pow = (p) => typeof p == "number" && p >= 0 && p <= 15 && p % 1 == 0 ? 10 ** p : bad("precision");
62
+ var LIMIT = 2 ** 29;
63
+ function slowDecode(str, f, flat) {
64
+ if (typeof str != "string") fail("input", "Expected a string");
65
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, values = [];
66
+ let v = 0, scale = 1, i = 0, c;
67
+ for (; i < str.length; i++) {
68
+ c = str.charCodeAt(i) - 63;
69
+ if (c < 0 || c > 63) {
70
+ if (strict) fail("char", "Invalid character", i);
71
+ continue;
72
+ }
73
+ v += (c & 31) * scale;
74
+ scale *= 32;
75
+ if (v > 2 ** 53 && strict) fail("overflow", "Value too large", i);
76
+ if (c < 32) {
77
+ values.push(v % 2 ? -(v + 1) / 2 : v / 2);
78
+ v = 0;
79
+ scale = 1;
80
+ }
81
+ }
82
+ if (strict && (scale > 1 || values.length % d)) fail("truncated", "Truncated", i);
83
+ const n = values.length / d | 0, sum = Array(d).fill(0), out = flat ? new Float64Array(n * d) : Array(n);
84
+ for (let j = 0, k = 0; j < n; j++) {
85
+ const p = flat ? out : Array(d);
86
+ for (let a = 0; a < d; a++, k++) {
87
+ sum[a] += values[k];
88
+ p[(flat ? k - a : 0) + (sw && a < 2 ? 1 - a : a)] = sum[a] / (a < 2 ? f : zf);
89
+ }
90
+ if (!flat) out[j] = p;
91
+ }
92
+ return out;
93
+ }
94
+ function slowEncode(points, f, flat) {
95
+ if (points == null || !(points.length >= 0)) fail("input", "Expected an array");
96
+ const { dims: d, strict, zf } = st, sw = st.swap && d > 1, last = Array(d).fill(0), n = flat ? points.length / d : points.length;
97
+ if (n % 1 && strict) fail("input", "Length not a multiple of " + d);
98
+ let s = "";
99
+ for (let i = 0; i < (n | 0); i++) {
100
+ const p = flat ? 0 : points[i];
101
+ for (let a = 0; a < d; a++) {
102
+ const b = sw && a < 2 ? 1 - a : a;
103
+ 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;
104
+ x = x == null ? NaN : +x * (a < 2 ? f : zf);
105
+ if (!(x - x == 0)) {
106
+ if (strict) fail("coordinate", "Invalid coordinate", i);
107
+ x = 0;
108
+ }
109
+ x = Math.sign(x) * Math.round(Math.abs(x));
110
+ let z = x - last[a];
111
+ last[a] = x;
112
+ z = z < 0 ? -z * 2 - 1 : z * 2;
113
+ if (z > 2 ** 53 && strict) fail("overflow", "Value too large", i);
114
+ for (; z >= 32; z = Math.floor(z / 32)) s += String.fromCharCode(z % 32 + 95);
115
+ s += String.fromCharCode(z + 63);
116
+ }
117
+ }
118
+ return s;
119
+ }
120
+ var decodeWith = (str, o, flat) => {
121
+ const f = opts(o), out = st.dims == 2 && typeof str == "string" && decodeLoop(str, f, st.swap, flat);
122
+ return out ? st.swap && !flat ? flip(out) : out : slowDecode(str, f, flat);
123
+ };
124
+ var flip = (out) => {
125
+ for (const p of out) {
126
+ const t = p[0];
127
+ p[0] = p[1];
128
+ p[1] = t;
129
+ }
130
+ return out;
131
+ };
132
+ var decode = (str, o) => decodeWith(str, o, 0);
133
+ function decodeLoop(str, f, sw, flat) {
134
+ const len = str.length, a = +sw;
135
+ let i = 0, n = 0, lat = 0, lng = 0, bad2 = 0, c, v, s, out;
136
+ if (flat) {
137
+ for (; i < len; i++) n += str.charCodeAt(i) - 95 >>> 31;
138
+ out = new Float64Array(n & ~1);
139
+ i = n = 0;
140
+ } else out = len < 64 ? [] : Array(len >> 1);
141
+ while (i < len) {
142
+ c = str.charCodeAt(i++) - 63;
143
+ bad2 |= c;
144
+ v = c & 31;
145
+ for (s = 5; c >= 32; s += 5) {
146
+ c = str.charCodeAt(i++) - 63;
147
+ bad2 |= c | 25 - s;
148
+ v |= (c & 31) << s;
149
+ }
150
+ lat += v >>> 1 ^ -(v & 1);
151
+ c = str.charCodeAt(i++) - 63;
152
+ bad2 |= c;
153
+ v = c & 31;
154
+ for (s = 5; c >= 32; s += 5) {
155
+ c = str.charCodeAt(i++) - 63;
156
+ bad2 |= c | 25 - s;
157
+ v |= (c & 31) << s;
158
+ }
159
+ lng += v >>> 1 ^ -(v & 1);
160
+ if (flat) {
161
+ out[n + a] = lat / f;
162
+ out[n + 1 - a] = lng / f;
163
+ n += 2;
164
+ } else out[n++] = [lat / f, lng / f];
165
+ }
166
+ if (bad2 & ~63 || i != len) return null;
167
+ if (out.length != n) out.length = n;
168
+ return out;
169
+ }
170
+ var CHARS = /* @__PURE__ */ Array.from({ length: 1024 }, (_, z) => chars(z));
171
+ function chars(z) {
172
+ let s = "";
173
+ for (; z >= 32; z >>>= 5) s += String.fromCharCode((z & 31) + 95);
174
+ return s + String.fromCharCode(z + 63);
175
+ }
176
+ var encodeWith = (src, o, flat) => {
177
+ const f = opts(o);
178
+ 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);
179
+ };
180
+ var encode = (points, o) => encodeWith(points, o, 0);
181
+ function encodeLoop(src, f, a, flat) {
182
+ const n = flat ? src.length >> 1 : src.length;
183
+ let s = "", i = 0, la = 0, lb = 0, x, y, p, q, z, pt;
184
+ try {
185
+ for (; i < n; i++) {
186
+ if (flat) {
187
+ x = src[i * 2 + a];
188
+ y = src[i * 2 + 1 - a];
189
+ } else {
190
+ pt = src[i];
191
+ x = pt[a];
192
+ y = pt[1 - a];
193
+ }
194
+ if (typeof x != "number" || typeof y != "number" || !((x *= f) < LIMIT && x > -LIMIT && (y *= f) < LIMIT && y > -LIMIT)) return null;
195
+ p = x < 0 ? -(0.5 - x | 0) : x + 0.5 | 0;
196
+ q = y < 0 ? -(0.5 - y | 0) : y + 0.5 | 0;
197
+ if (x < 0.5 && x > -0.5) p = 0;
198
+ if (y < 0.5 && y > -0.5) q = 0;
199
+ z = p - la;
200
+ z = z << 1 ^ z >> 31;
201
+ s += z < 1024 ? CHARS[z] : chars(z);
202
+ z = q - lb;
203
+ z = z << 1 ^ z >> 31;
204
+ s += z < 1024 ? CHARS[z] : chars(z);
205
+ la = p;
206
+ lb = q;
207
+ }
208
+ } catch {
209
+ return null;
210
+ }
211
+ return s;
212
+ }
213
+
214
+ // src/leaflet.js
215
+ var toLatLngs = (s, o) => typeof s == "string" ? decode(s, o) : s.map((x) => toLatLngs(x, o));
216
+ var toStrings = (l, o) => Array.isArray(l[0]) ? l.map((x) => toStrings(x, o)) : encode(l.map((p) => [p.lat, p.lng]), o);
217
+ function install(L) {
218
+ const { Polyline, Polygon } = L;
219
+ const add = (C, name) => {
220
+ C.fromEncoded = (s, o) => new C(toLatLngs(s, o), o);
221
+ C.prototype.toEncoded = function(o) {
222
+ return toStrings(this.getLatLngs(), o);
223
+ };
224
+ C.prototype.encodePath = C.prototype.toEncoded;
225
+ if (Object.isExtensible(L)) L[name] = C.fromEncoded;
226
+ };
227
+ add(Polyline, "polylineEncoded");
228
+ add(Polygon, "polygonEncoded");
229
+ if (Object.isExtensible(L)) L.PolylineUtil ??= { encode, decode };
230
+ return L;
231
+ }