@naivemap/image-layer-core 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.
package/dist/index.js ADDED
@@ -0,0 +1,1880 @@
1
+ import Ir from "proj4";
2
+ /* @license twgl.js 5.5.4 Copyright (c) 2015, Gregg Tavares All Rights Reserved.
3
+ Available via the MIT license.
4
+ see: http://github.com/greggman/twgl.js for details */
5
+ const $e = 5120, ee = 5121, Ve = 5122, He = 5123, Xe = 5124, Ze = 5125, je = 5126, gr = 32819, Pr = 32820, vr = 33635, Nr = 5131, Ur = 33640, Br = 35899, wr = 35902, Dr = 36269, Lr = 34042, gt = {};
6
+ {
7
+ const e = gt;
8
+ e[$e] = Int8Array, e[ee] = Uint8Array, e[Ve] = Int16Array, e[He] = Uint16Array, e[Xe] = Int32Array, e[Ze] = Uint32Array, e[je] = Float32Array, e[gr] = Uint16Array, e[Pr] = Uint16Array, e[vr] = Uint16Array, e[Nr] = Uint16Array, e[Ur] = Uint32Array, e[Br] = Uint32Array, e[wr] = Uint32Array, e[Dr] = Uint32Array, e[Lr] = Uint32Array;
9
+ }
10
+ function We(e) {
11
+ if (e instanceof Int8Array)
12
+ return $e;
13
+ if (e instanceof Uint8Array || e instanceof Uint8ClampedArray)
14
+ return ee;
15
+ if (e instanceof Int16Array)
16
+ return Ve;
17
+ if (e instanceof Uint16Array)
18
+ return He;
19
+ if (e instanceof Int32Array)
20
+ return Xe;
21
+ if (e instanceof Uint32Array)
22
+ return Ze;
23
+ if (e instanceof Float32Array)
24
+ return je;
25
+ throw new Error("unsupported typed array type");
26
+ }
27
+ function Pt(e) {
28
+ if (e === Int8Array)
29
+ return $e;
30
+ if (e === Uint8Array || e === Uint8ClampedArray)
31
+ return ee;
32
+ if (e === Int16Array)
33
+ return Ve;
34
+ if (e === Uint16Array)
35
+ return He;
36
+ if (e === Int32Array)
37
+ return Xe;
38
+ if (e === Uint32Array)
39
+ return Ze;
40
+ if (e === Float32Array)
41
+ return je;
42
+ throw new Error("unsupported typed array type");
43
+ }
44
+ function vt(e) {
45
+ const t = gt[e];
46
+ if (!t)
47
+ throw new Error("unknown gl type");
48
+ return t;
49
+ }
50
+ const de = typeof SharedArrayBuffer < "u" ? function(t) {
51
+ return t && t.buffer && (t.buffer instanceof ArrayBuffer || t.buffer instanceof SharedArrayBuffer);
52
+ } : function(t) {
53
+ return t && t.buffer && t.buffer instanceof ArrayBuffer;
54
+ };
55
+ function Nt(...e) {
56
+ console.error(...e);
57
+ }
58
+ const at = /* @__PURE__ */ new Map();
59
+ function Ye(e, t) {
60
+ if (!e || typeof e != "object")
61
+ return !1;
62
+ let r = at.get(t);
63
+ r || (r = /* @__PURE__ */ new WeakMap(), at.set(t, r));
64
+ let n = r.get(e);
65
+ if (n === void 0) {
66
+ const o = Object.prototype.toString.call(e);
67
+ n = o.substring(8, o.length - 1) === t, r.set(e, n);
68
+ }
69
+ return n;
70
+ }
71
+ function Mr(e, t) {
72
+ return typeof WebGLBuffer < "u" && Ye(t, "WebGLBuffer");
73
+ }
74
+ function Ut(e, t) {
75
+ return typeof WebGLTexture < "u" && Ye(t, "WebGLTexture");
76
+ }
77
+ function Cr(e, t) {
78
+ return typeof WebGLSampler < "u" && Ye(t, "WebGLSampler");
79
+ }
80
+ const Bt = 35044, z = 34962, Or = 34963, Gr = 34660, kr = 5120, zr = 5121, $r = 5122, Vr = 5123, Hr = 5124, Xr = 5125, wt = 5126, Dt = {
81
+ attribPrefix: ""
82
+ };
83
+ function Zr(e, t, r, n, o) {
84
+ e.bindBuffer(t, r), e.bufferData(t, n, o || Bt);
85
+ }
86
+ function Lt(e, t, r, n) {
87
+ if (Mr(e, t))
88
+ return t;
89
+ r = r || z;
90
+ const o = e.createBuffer();
91
+ return Zr(e, r, o, t, n), o;
92
+ }
93
+ function Mt(e) {
94
+ return e === "indices";
95
+ }
96
+ function jr(e) {
97
+ return e === Int8Array || e === Uint8Array;
98
+ }
99
+ function Wr(e) {
100
+ return e.length ? e : e.data;
101
+ }
102
+ const Yr = /coord|texture/i, Kr = /color|colour/i;
103
+ function Jr(e, t) {
104
+ let r;
105
+ if (Yr.test(e) ? r = 2 : Kr.test(e) ? r = 4 : r = 3, t % r > 0)
106
+ throw new Error(`Can not guess numComponents for attribute '${e}'. Tried ${r} but ${t} values is not evenly divisible by ${r}. You should specify it.`);
107
+ return r;
108
+ }
109
+ function Qr(e, t, r) {
110
+ return e.numComponents || e.size || Jr(t, r || Wr(e).length);
111
+ }
112
+ function Ct(e, t) {
113
+ if (de(e))
114
+ return e;
115
+ if (de(e.data))
116
+ return e.data;
117
+ Array.isArray(e) && (e = {
118
+ data: e
119
+ });
120
+ let r = e.type ? Ke(e.type) : void 0;
121
+ return r || (Mt(t) ? r = Uint16Array : r = Float32Array), new r(e.data);
122
+ }
123
+ function qr(e) {
124
+ return typeof e == "number" ? e : e ? Pt(e) : wt;
125
+ }
126
+ function Ke(e) {
127
+ return typeof e == "number" ? vt(e) : e || Float32Array;
128
+ }
129
+ function en(e, t) {
130
+ return {
131
+ buffer: t.buffer,
132
+ numValues: 2 * 3 * 4,
133
+ // safely divided by 2, 3, 4
134
+ type: qr(t.type),
135
+ arrayType: Ke(t.type)
136
+ };
137
+ }
138
+ function tn(e, t) {
139
+ const r = t.data || t, n = Ke(t.type), o = r * n.BYTES_PER_ELEMENT, i = e.createBuffer();
140
+ return e.bindBuffer(z, i), e.bufferData(z, o, t.drawType || Bt), {
141
+ buffer: i,
142
+ numValues: r,
143
+ type: Pt(n),
144
+ arrayType: n
145
+ };
146
+ }
147
+ function rn(e, t, r) {
148
+ const n = Ct(t, r);
149
+ return {
150
+ arrayType: n.constructor,
151
+ buffer: Lt(e, n, void 0, t.drawType),
152
+ type: We(n),
153
+ numValues: 0
154
+ };
155
+ }
156
+ function nn(e, t) {
157
+ const r = {};
158
+ return Object.keys(t).forEach(function(n) {
159
+ if (!Mt(n)) {
160
+ const o = t[n], i = o.attrib || o.name || o.attribName || Dt.attribPrefix + n;
161
+ if (o.value) {
162
+ if (!Array.isArray(o.value) && !de(o.value))
163
+ throw new Error("array.value is not array or typedarray");
164
+ r[i] = {
165
+ value: o.value
166
+ };
167
+ } else {
168
+ let s;
169
+ o.buffer && o.buffer instanceof WebGLBuffer ? s = en : typeof o == "number" || typeof o.data == "number" ? s = tn : s = rn;
170
+ const { buffer: a, type: u, numValues: c, arrayType: x } = s(e, o, n), f = o.normalize !== void 0 ? o.normalize : jr(x), m = Qr(o, n, c);
171
+ r[i] = {
172
+ buffer: a,
173
+ numComponents: m,
174
+ type: u,
175
+ normalize: f,
176
+ stride: o.stride || 0,
177
+ offset: o.offset || 0,
178
+ divisor: o.divisor === void 0 ? void 0 : o.divisor,
179
+ drawType: o.drawType
180
+ };
181
+ }
182
+ }
183
+ }), e.bindBuffer(z, null), r;
184
+ }
185
+ function on(e, t) {
186
+ return t === kr || t === zr ? 1 : t === $r || t === Vr ? 2 : t === Hr || t === Xr || t === wt ? 4 : 0;
187
+ }
188
+ const ve = ["position", "positions", "a_position"];
189
+ function sn(e, t) {
190
+ let r, n;
191
+ for (n = 0; n < ve.length && (r = ve[n], !(r in t || (r = Dt.attribPrefix + r, r in t))); ++n)
192
+ ;
193
+ n === ve.length && (r = Object.keys(t)[0]);
194
+ const o = t[r];
195
+ if (!o.buffer)
196
+ return 1;
197
+ e.bindBuffer(z, o.buffer);
198
+ const i = e.getBufferParameter(z, Gr);
199
+ e.bindBuffer(z, null);
200
+ const s = on(e, o.type), a = i / s, u = o.numComponents || o.size, c = a / u;
201
+ if (c % 1 !== 0)
202
+ throw new Error(`numComponents ${u} not correct for length ${length}`);
203
+ return c;
204
+ }
205
+ function Ne(e, t, r) {
206
+ const n = nn(e, t), o = Object.assign({}, r || {});
207
+ o.attribs = Object.assign({}, r ? r.attribs : {}, n);
208
+ const i = t.indices;
209
+ if (i) {
210
+ const s = Ct(i, "indices");
211
+ o.indices = Lt(e, s, Or), o.numElements = s.length, o.elementType = We(s);
212
+ } else o.numElements || (o.numElements = sn(e, o.attribs));
213
+ return o;
214
+ }
215
+ function se(e) {
216
+ return !!e.texStorage2D;
217
+ }
218
+ const Ot = /* @__PURE__ */ function() {
219
+ const e = {}, t = {};
220
+ function r(n) {
221
+ const o = n.constructor.name;
222
+ if (!e[o]) {
223
+ for (const i in n)
224
+ if (typeof n[i] == "number") {
225
+ const s = t[n[i]];
226
+ t[n[i]] = s ? `${s} | ${i}` : i;
227
+ }
228
+ e[o] = !0;
229
+ }
230
+ }
231
+ return function(o, i) {
232
+ return r(o), t[i] || (typeof i == "number" ? `0x${i.toString(16)}` : i);
233
+ };
234
+ }(), D = {
235
+ textureColor: new Uint8Array([128, 192, 255, 255]),
236
+ textureOptions: {},
237
+ crossOrigin: void 0
238
+ }, te = de, Gt = /* @__PURE__ */ function() {
239
+ let e;
240
+ return function() {
241
+ return e = e || (typeof document < "u" && document.createElement ? document.createElement("canvas").getContext("2d") : null), e;
242
+ };
243
+ }(), ut = 6406, N = 6407, b = 6408, ct = 6409, ft = 6410, J = 6402, lt = 34041, Ee = 33071, an = 9728, un = 9729, L = 3553, w = 34067, $ = 32879, V = 35866, Je = 34069, cn = 34070, fn = 34071, ln = 34072, xn = 34073, mn = 34074, De = 10241, Le = 10240, _e = 10242, pe = 10243, xt = 32882, hn = 33082, yn = 33083, dn = 33084, En = 33085, _n = 34892, pn = 34893, Qe = 3317, kt = 3314, zt = 32878, $t = 3316, Vt = 3315, Ht = 32877, Tn = 37443, An = 37441, bn = 37440, Sn = 33321, Fn = 36756, Rn = 33325, In = 33326, gn = 33330, Pn = 33329, vn = 33338, Nn = 33337, Un = 33340, Bn = 33339, wn = 33323, Dn = 36757, Ln = 33327, Mn = 33328, Cn = 33336, On = 33335, Gn = 33332, kn = 33331, zn = 33334, $n = 33333, Vn = 32849, Hn = 35905, Xn = 36194, Zn = 36758, jn = 35898, Wn = 35901, Yn = 34843, Kn = 34837, Jn = 36221, Qn = 36239, qn = 36215, eo = 36233, to = 36209, ro = 36227, no = 32856, oo = 35907, io = 36759, so = 32855, ao = 32854, uo = 32857, co = 34842, fo = 34836, lo = 36220, xo = 36238, mo = 36975, ho = 36214, yo = 36232, Eo = 36226, _o = 36208, po = 33189, To = 33190, Ao = 36012, bo = 36013, So = 35056, B = 5120, A = 5121, ce = 5122, X = 5123, fe = 5124, G = 5125, I = 5126, mt = 32819, ht = 32820, yt = 33635, v = 5131, Q = 36193, Ue = 33640, Fo = 35899, Ro = 35902, Io = 36269, go = 34042, le = 33319, Z = 33320, xe = 6403, j = 36244, W = 36248, k = 36249;
244
+ let Be;
245
+ function Ae(e) {
246
+ if (!Be) {
247
+ const t = {};
248
+ t[ut] = { textureFormat: ut, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, v, Q, I] }, t[ct] = { textureFormat: ct, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1, 2, 2, 4], type: [A, v, Q, I] }, t[ft] = { textureFormat: ft, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2, 4, 4, 8], type: [A, v, Q, I] }, t[N] = { textureFormat: N, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 6, 6, 12, 2], type: [A, v, Q, I, yt] }, t[b] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 8, 8, 16, 2, 2], type: [A, v, Q, I, mt, ht] }, t[J] = { textureFormat: J, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [G, X] }, t[Sn] = { textureFormat: xe, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [1], type: [A] }, t[Fn] = { textureFormat: xe, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [1], type: [B] }, t[Rn] = { textureFormat: xe, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4, 2], type: [I, v] }, t[In] = { textureFormat: xe, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [4], type: [I] }, t[gn] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [A] }, t[Pn] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [1], type: [B] }, t[Gn] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [X] }, t[kn] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [ce] }, t[zn] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [G] }, t[$n] = { textureFormat: j, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [fe] }, t[wn] = { textureFormat: le, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [2], type: [A] }, t[Dn] = { textureFormat: le, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [2], type: [B] }, t[Ln] = { textureFormat: le, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [8, 4], type: [I, v] }, t[Mn] = { textureFormat: le, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [8], type: [I] }, t[Cn] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [A] }, t[On] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2], type: [B] }, t[vn] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [X] }, t[Nn] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [ce] }, t[Un] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [G] }, t[Bn] = { textureFormat: Z, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [fe] }, t[Vn] = { textureFormat: N, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3], type: [A] }, t[Hn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [A] }, t[Xn] = { textureFormat: N, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [3, 2], type: [A, yt] }, t[Zn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [3], type: [B] }, t[jn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [I, v, Fo] }, t[Wn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6, 4], type: [I, v, Ro] }, t[Yn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [12, 6], type: [I, v] }, t[Kn] = { textureFormat: N, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [I] }, t[Jn] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [A] }, t[Qn] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [3], type: [B] }, t[qn] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [X] }, t[eo] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [6], type: [ce] }, t[to] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [G] }, t[ro] = { textureFormat: W, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [12], type: [fe] }, t[no] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, t[oo] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [A] }, t[io] = { textureFormat: b, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [4], type: [B] }, t[so] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2, 4], type: [A, ht, Ue] }, t[ao] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4, 2], type: [A, mt] }, t[uo] = { textureFormat: b, colorRenderable: !0, textureFilterable: !0, bytesPerElement: [4], type: [Ue] }, t[co] = { textureFormat: b, colorRenderable: !1, textureFilterable: !0, bytesPerElement: [16, 8], type: [I, v] }, t[fo] = { textureFormat: b, colorRenderable: !1, textureFilterable: !1, bytesPerElement: [16], type: [I] }, t[lo] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [A] }, t[xo] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [B] }, t[mo] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Ue] }, t[ho] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [X] }, t[yo] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [8], type: [ce] }, t[Eo] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [fe] }, t[_o] = { textureFormat: k, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [16], type: [G] }, t[po] = { textureFormat: J, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [2, 4], type: [X, G] }, t[To] = { textureFormat: J, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [G] }, t[Ao] = { textureFormat: J, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [I] }, t[So] = { textureFormat: lt, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [go] }, t[bo] = { textureFormat: lt, colorRenderable: !0, textureFilterable: !1, bytesPerElement: [4], type: [Io] }, Object.keys(t).forEach(function(r) {
249
+ const n = t[r];
250
+ n.bytesPerElementMap = {}, n.bytesPerElement.forEach(function(o, i) {
251
+ const s = n.type[i];
252
+ n.bytesPerElementMap[s] = o;
253
+ });
254
+ }), Be = t;
255
+ }
256
+ return Be[e];
257
+ }
258
+ function Po(e, t) {
259
+ const r = Ae(e);
260
+ if (!r)
261
+ throw "unknown internal format";
262
+ const n = r.bytesPerElementMap[t];
263
+ if (n === void 0)
264
+ throw "unknown internal format";
265
+ return n;
266
+ }
267
+ function ae(e) {
268
+ const t = Ae(e);
269
+ if (!t)
270
+ throw "unknown internal format";
271
+ return {
272
+ format: t.textureFormat,
273
+ type: t.type[0]
274
+ };
275
+ }
276
+ function dt(e) {
277
+ return (e & e - 1) === 0;
278
+ }
279
+ function vo(e, t, r, n) {
280
+ if (!se(e))
281
+ return dt(t) && dt(r);
282
+ const o = Ae(n);
283
+ if (!o)
284
+ throw "unknown internal format";
285
+ return o.colorRenderable && o.textureFilterable;
286
+ }
287
+ function No(e) {
288
+ const t = Ae(e);
289
+ if (!t)
290
+ throw "unknown internal format";
291
+ return t.textureFilterable;
292
+ }
293
+ function Uo(e, t, r) {
294
+ return te(t) ? We(t) : r || A;
295
+ }
296
+ function me(e, t, r, n, o) {
297
+ if (o % 1 !== 0)
298
+ throw "can't guess dimensions";
299
+ if (!r && !n) {
300
+ const i = Math.sqrt(o / (t === w ? 6 : 1));
301
+ i % 1 === 0 ? (r = i, n = i) : (r = o, n = 1);
302
+ } else if (n) {
303
+ if (!r && (r = o / n, r % 1))
304
+ throw "can't guess dimensions";
305
+ } else if (n = o / r, n % 1)
306
+ throw "can't guess dimensions";
307
+ return {
308
+ width: r,
309
+ height: n
310
+ };
311
+ }
312
+ function Y(e, t) {
313
+ t.colorspaceConversion !== void 0 && e.pixelStorei(Tn, t.colorspaceConversion), t.premultiplyAlpha !== void 0 && e.pixelStorei(An, t.premultiplyAlpha), t.flipY !== void 0 && e.pixelStorei(bn, t.flipY);
314
+ }
315
+ function Xt(e) {
316
+ e.pixelStorei(Qe, 4), se(e) && (e.pixelStorei(kt, 0), e.pixelStorei(zt, 0), e.pixelStorei($t, 0), e.pixelStorei(Vt, 0), e.pixelStorei(Ht, 0));
317
+ }
318
+ function Bo(e, t, r, n) {
319
+ n.minMag && (r.call(e, t, De, n.minMag), r.call(e, t, Le, n.minMag)), n.min && r.call(e, t, De, n.min), n.mag && r.call(e, t, Le, n.mag), n.wrap && (r.call(e, t, _e, n.wrap), r.call(e, t, pe, n.wrap), (t === $ || Cr(e, t)) && r.call(e, t, xt, n.wrap)), n.wrapR && r.call(e, t, xt, n.wrapR), n.wrapS && r.call(e, t, _e, n.wrapS), n.wrapT && r.call(e, t, pe, n.wrapT), n.minLod !== void 0 && r.call(e, t, hn, n.minLod), n.maxLod !== void 0 && r.call(e, t, yn, n.maxLod), n.baseLevel !== void 0 && r.call(e, t, dn, n.baseLevel), n.maxLevel !== void 0 && r.call(e, t, En, n.maxLevel), n.compareFunc !== void 0 && r.call(e, t, pn, n.compareFunc), n.compareMode !== void 0 && r.call(e, t, _n, n.compareMode);
320
+ }
321
+ function Zt(e, t, r) {
322
+ const n = r.target || L;
323
+ e.bindTexture(n, t), Bo(e, n, e.texParameteri, r);
324
+ }
325
+ function wo(e) {
326
+ return e = e || D.textureColor, te(e) ? e : new Uint8Array([e[0] * 255, e[1] * 255, e[2] * 255, e[3] * 255]);
327
+ }
328
+ function Me(e, t, r, n, o, i) {
329
+ r = r || D.textureOptions, i = i || b;
330
+ const s = r.target || L;
331
+ if (n = n || r.width, o = o || r.height, e.bindTexture(s, t), vo(e, n, o, i))
332
+ e.generateMipmap(s);
333
+ else {
334
+ const a = No(i) ? un : an;
335
+ e.texParameteri(s, De, a), e.texParameteri(s, Le, a), e.texParameteri(s, _e, Ee), e.texParameteri(s, pe, Ee);
336
+ }
337
+ }
338
+ function re(e) {
339
+ return e.auto === !0 || e.auto === void 0 && e.level === void 0;
340
+ }
341
+ function Ce(e, t) {
342
+ return t = t || {}, t.cubeFaceOrder || [
343
+ Je,
344
+ cn,
345
+ fn,
346
+ ln,
347
+ xn,
348
+ mn
349
+ ];
350
+ }
351
+ function Oe(e, t) {
352
+ const n = Ce(e, t).map(function(o, i) {
353
+ return { face: o, ndx: i };
354
+ });
355
+ return n.sort(function(o, i) {
356
+ return o.face - i.face;
357
+ }), n;
358
+ }
359
+ function jt(e, t, r, n) {
360
+ n = n || D.textureOptions;
361
+ const o = n.target || L, i = n.level || 0;
362
+ let s = r.width, a = r.height;
363
+ const u = n.internalFormat || n.format || b, c = ae(u), x = n.format || c.format, f = n.type || c.type;
364
+ if (Y(e, n), e.bindTexture(o, t), o === w) {
365
+ const m = r.width, h = r.height;
366
+ let l, E;
367
+ if (m / 6 === h)
368
+ l = h, E = [0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0];
369
+ else if (h / 6 === m)
370
+ l = m, E = [0, 0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5];
371
+ else if (m / 3 === h / 2)
372
+ l = m / 3, E = [0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1];
373
+ else if (m / 2 === h / 3)
374
+ l = m / 2, E = [0, 0, 1, 0, 0, 1, 1, 1, 0, 2, 1, 2];
375
+ else
376
+ throw "can't figure out cube map from element: " + (r.src ? r.src : r.nodeName);
377
+ const p = Gt();
378
+ p ? (p.canvas.width = l, p.canvas.height = l, s = l, a = l, Oe(e, n).forEach(function(T) {
379
+ const R = E[T.ndx * 2 + 0] * l, y = E[T.ndx * 2 + 1] * l;
380
+ p.drawImage(r, R, y, l, l, 0, 0, l, l), e.texImage2D(T.face, i, u, x, f, p.canvas);
381
+ }), p.canvas.width = 1, p.canvas.height = 1) : typeof createImageBitmap < "u" && (s = l, a = l, Oe(e, n).forEach(function(T) {
382
+ const R = E[T.ndx * 2 + 0] * l, y = E[T.ndx * 2 + 1] * l;
383
+ e.texImage2D(T.face, i, u, l, l, 0, x, f, null), createImageBitmap(r, R, y, l, l, {
384
+ premultiplyAlpha: "none",
385
+ colorSpaceConversion: "none"
386
+ }).then(function(_) {
387
+ Y(e, n), e.bindTexture(o, t), e.texImage2D(T.face, i, u, x, f, _), re(n) && Me(e, t, n, s, a, u);
388
+ });
389
+ }));
390
+ } else if (o === $ || o === V) {
391
+ const m = Math.min(r.width, r.height), h = Math.max(r.width, r.height), l = h / m;
392
+ if (l % 1 !== 0)
393
+ throw "can not compute 3D dimensions of element";
394
+ const E = r.width === h ? 1 : 0, p = r.height === h ? 1 : 0;
395
+ e.pixelStorei(Qe, 1), e.pixelStorei(kt, r.width), e.pixelStorei(zt, 0), e.pixelStorei(Ht, 0), e.texImage3D(o, i, u, m, m, m, 0, x, f, null);
396
+ for (let T = 0; T < l; ++T) {
397
+ const R = T * m * E, y = T * m * p;
398
+ e.pixelStorei($t, R), e.pixelStorei(Vt, y), e.texSubImage3D(o, i, 0, 0, T, m, m, 1, x, f, r);
399
+ }
400
+ Xt(e);
401
+ } else
402
+ e.texImage2D(o, i, u, x, f, r);
403
+ re(n) && Me(e, t, n, s, a, u), Zt(e, t, n);
404
+ }
405
+ function ue() {
406
+ }
407
+ function Do(e) {
408
+ if (typeof document < "u") {
409
+ const t = document.createElement("a");
410
+ return t.href = e, t.hostname === location.hostname && t.port === location.port && t.protocol === location.protocol;
411
+ } else {
412
+ const t = new URL(location.href).origin;
413
+ return new URL(e, location.href).origin === t;
414
+ }
415
+ }
416
+ function Lo(e, t) {
417
+ return t === void 0 && !Do(e) ? "anonymous" : t;
418
+ }
419
+ function Mo(e, t, r) {
420
+ r = r || ue;
421
+ let n;
422
+ if (t = t !== void 0 ? t : D.crossOrigin, t = Lo(e, t), typeof Image < "u") {
423
+ n = new Image(), t !== void 0 && (n.crossOrigin = t);
424
+ const o = function() {
425
+ n.removeEventListener("error", i), n.removeEventListener("load", s), n = null;
426
+ }, i = function() {
427
+ const u = "couldn't load image: " + e;
428
+ Nt(u), r(u, n), o();
429
+ }, s = function() {
430
+ r(null, n), o();
431
+ };
432
+ return n.addEventListener("error", i), n.addEventListener("load", s), n.src = e, n;
433
+ } else if (typeof ImageBitmap < "u") {
434
+ let o, i;
435
+ const s = function() {
436
+ r(o, i);
437
+ }, a = {};
438
+ t && (a.mode = "cors"), fetch(e, a).then(function(u) {
439
+ if (!u.ok)
440
+ throw u;
441
+ return u.blob();
442
+ }).then(function(u) {
443
+ return createImageBitmap(u, {
444
+ premultiplyAlpha: "none",
445
+ colorSpaceConversion: "none"
446
+ });
447
+ }).then(function(u) {
448
+ i = u, setTimeout(s);
449
+ }).catch(function(u) {
450
+ o = u, setTimeout(s);
451
+ }), n = null;
452
+ }
453
+ return n;
454
+ }
455
+ function Wt(e) {
456
+ return typeof ImageBitmap < "u" && e instanceof ImageBitmap || typeof ImageData < "u" && e instanceof ImageData || typeof HTMLElement < "u" && e instanceof HTMLElement;
457
+ }
458
+ function qe(e, t, r) {
459
+ return Wt(e) ? (setTimeout(function() {
460
+ r(null, e);
461
+ }), e) : Mo(e, t, r);
462
+ }
463
+ function et(e, t, r) {
464
+ r = r || D.textureOptions;
465
+ const n = r.target || L;
466
+ if (e.bindTexture(n, t), r.color === !1)
467
+ return;
468
+ const o = wo(r.color);
469
+ if (n === w)
470
+ for (let i = 0; i < 6; ++i)
471
+ e.texImage2D(Je + i, 0, b, 1, 1, 0, b, A, o);
472
+ else n === $ || n === V ? e.texImage3D(n, 0, b, 1, 1, 1, 0, b, A, o) : e.texImage2D(n, 0, b, 1, 1, 0, b, A, o);
473
+ }
474
+ function Co(e, t, r, n) {
475
+ return n = n || ue, r = r || D.textureOptions, et(e, t, r), r = Object.assign({}, r), qe(r.src, r.crossOrigin, function(i, s) {
476
+ i ? n(i, t, s) : (jt(e, t, s, r), n(null, t, s));
477
+ });
478
+ }
479
+ function Oo(e, t, r, n) {
480
+ n = n || ue;
481
+ const o = r.src;
482
+ if (o.length !== 6)
483
+ throw "there must be 6 urls for a cubemap";
484
+ const i = r.level || 0, s = r.internalFormat || r.format || b, a = ae(s), u = r.format || a.format, c = r.type || A, x = r.target || L;
485
+ if (x !== w)
486
+ throw "target must be TEXTURE_CUBE_MAP";
487
+ et(e, t, r), r = Object.assign({}, r);
488
+ let f = 6;
489
+ const m = [], h = Ce(e, r);
490
+ let l;
491
+ function E(p) {
492
+ return function(T, R) {
493
+ --f, T ? m.push(T) : R.width !== R.height ? m.push("cubemap face img is not a square: " + R.src) : (Y(e, r), e.bindTexture(x, t), f === 5 ? Ce().forEach(function(y) {
494
+ e.texImage2D(y, i, s, u, c, R);
495
+ }) : e.texImage2D(p, i, s, u, c, R), re(r) && e.generateMipmap(x)), f === 0 && n(m.length ? m : void 0, t, l);
496
+ };
497
+ }
498
+ l = o.map(function(p, T) {
499
+ return qe(p, r.crossOrigin, E(h[T]));
500
+ });
501
+ }
502
+ function Go(e, t, r, n) {
503
+ n = n || ue;
504
+ const o = r.src, i = r.internalFormat || r.format || b, s = ae(i), a = r.format || s.format, u = r.type || A, c = r.target || V;
505
+ if (c !== $ && c !== V)
506
+ throw "target must be TEXTURE_3D or TEXTURE_2D_ARRAY";
507
+ et(e, t, r), r = Object.assign({}, r);
508
+ let x = o.length;
509
+ const f = [];
510
+ let m;
511
+ const h = r.level || 0;
512
+ let l = r.width, E = r.height;
513
+ const p = o.length;
514
+ let T = !0;
515
+ function R(y) {
516
+ return function(_, C) {
517
+ if (--x, _)
518
+ f.push(_);
519
+ else {
520
+ if (Y(e, r), e.bindTexture(c, t), T) {
521
+ T = !1, l = r.width || C.width, E = r.height || C.height, e.texImage3D(c, h, i, l, E, p, 0, a, u, null);
522
+ for (let O = 0; O < p; ++O)
523
+ e.texSubImage3D(c, h, 0, 0, O, l, E, 1, a, u, C);
524
+ } else {
525
+ let O = C, U;
526
+ (C.width !== l || C.height !== E) && (U = Gt(), O = U.canvas, U.canvas.width = l, U.canvas.height = E, U.drawImage(C, 0, 0, l, E)), e.texSubImage3D(c, h, 0, 0, y, l, E, 1, a, u, O), U && O === U.canvas && (U.canvas.width = 0, U.canvas.height = 0);
527
+ }
528
+ re(r) && e.generateMipmap(c);
529
+ }
530
+ x === 0 && n(f.length ? f : void 0, t, m);
531
+ };
532
+ }
533
+ m = o.map(function(y, _) {
534
+ return qe(y, r.crossOrigin, R(_));
535
+ });
536
+ }
537
+ function ko(e, t, r, n) {
538
+ n = n || D.textureOptions;
539
+ const o = n.target || L;
540
+ e.bindTexture(o, t);
541
+ let i = n.width, s = n.height, a = n.depth;
542
+ const u = n.level || 0, c = n.internalFormat || n.format || b, x = ae(c), f = n.format || x.format, m = n.type || Uo(e, r, x.type);
543
+ if (te(r))
544
+ r instanceof Uint8ClampedArray && (r = new Uint8Array(r.buffer));
545
+ else {
546
+ const p = vt(m);
547
+ r = new p(r);
548
+ }
549
+ const h = Po(c, m), l = r.byteLength / h;
550
+ if (l % 1)
551
+ throw "length wrong size for format: " + Ot(e, f);
552
+ let E;
553
+ if (o === $ || o === V)
554
+ if (!i && !s && !a) {
555
+ const p = Math.cbrt(l);
556
+ if (p % 1 !== 0)
557
+ throw "can't guess cube size of array of numElements: " + l;
558
+ i = p, s = p, a = p;
559
+ } else i && (!s || !a) ? (E = me(e, o, s, a, l / i), s = E.width, a = E.height) : s && (!i || !a) ? (E = me(e, o, i, a, l / s), i = E.width, a = E.height) : (E = me(e, o, i, s, l / a), i = E.width, s = E.height);
560
+ else
561
+ E = me(e, o, i, s, l), i = E.width, s = E.height;
562
+ if (Xt(e), e.pixelStorei(Qe, n.unpackAlignment || 1), Y(e, n), o === w) {
563
+ const p = h / r.BYTES_PER_ELEMENT, T = l / 6 * p;
564
+ Oe(e, n).forEach((R) => {
565
+ const y = T * R.ndx, _ = r.subarray(y, y + T);
566
+ e.texImage2D(R.face, u, c, i, s, 0, f, m, _);
567
+ });
568
+ } else o === $ || o === V ? e.texImage3D(o, u, c, i, s, a, 0, f, m, r) : e.texImage2D(o, u, c, i, s, 0, f, m, r);
569
+ return {
570
+ width: i,
571
+ height: s,
572
+ depth: a,
573
+ type: m
574
+ };
575
+ }
576
+ function zo(e, t, r) {
577
+ const n = r.target || L;
578
+ e.bindTexture(n, t);
579
+ const o = r.level || 0, i = r.internalFormat || r.format || b, s = ae(i), a = r.format || s.format, u = r.type || s.type;
580
+ if (Y(e, r), n === w)
581
+ for (let c = 0; c < 6; ++c)
582
+ e.texImage2D(Je + c, o, i, r.width, r.height, 0, a, u, null);
583
+ else n === $ || n === V ? e.texImage3D(n, o, i, r.width, r.height, r.depth, 0, a, u, null) : e.texImage2D(n, o, i, r.width, r.height, 0, a, u, null);
584
+ }
585
+ function $o(e, t, r) {
586
+ r = r || ue, t = t || D.textureOptions;
587
+ const n = e.createTexture(), o = t.target || L;
588
+ let i = t.width || 1, s = t.height || 1;
589
+ const a = t.internalFormat || b;
590
+ e.bindTexture(o, n), o === w && (e.texParameteri(o, _e, Ee), e.texParameteri(o, pe, Ee));
591
+ let u = t.src;
592
+ if (u)
593
+ if (typeof u == "function" && (u = u(e, t)), typeof u == "string")
594
+ Co(e, n, t, r);
595
+ else if (te(u) || Array.isArray(u) && (typeof u[0] == "number" || Array.isArray(u[0]) || te(u[0]))) {
596
+ const c = ko(e, n, u, t);
597
+ i = c.width, s = c.height;
598
+ } else Array.isArray(u) && (typeof u[0] == "string" || Wt(u[0])) ? o === w ? Oo(e, n, t, r) : Go(e, n, t, r) : (jt(e, n, u, t), i = u.width, s = u.height);
599
+ else
600
+ zo(e, n, t);
601
+ return re(t) && Me(e, n, t, i, s, a), Zt(e, n, t), n;
602
+ }
603
+ const tt = Nt;
604
+ function Yt(e) {
605
+ return typeof document < "u" && document.getElementById ? document.getElementById(e) : null;
606
+ }
607
+ const Te = 33984, be = 34962, Vo = 34963, Ho = 35713, Xo = 35714, Zo = 35632, jo = 35633, Wo = 35981, Kt = 35718, Yo = 35721, Ko = 35971, Jo = 35382, Qo = 35396, qo = 35398, ei = 35392, ti = 35395, Se = 5126, Jt = 35664, Qt = 35665, qt = 35666, rt = 5124, er = 35667, tr = 35668, rr = 35669, nr = 35670, or = 35671, ir = 35672, sr = 35673, ar = 35674, ur = 35675, cr = 35676, ri = 35678, ni = 35680, oi = 35679, ii = 35682, si = 35685, ai = 35686, ui = 35687, ci = 35688, fi = 35689, li = 35690, xi = 36289, mi = 36292, hi = 36293, nt = 5125, fr = 36294, lr = 36295, xr = 36296, yi = 36298, di = 36299, Ei = 36300, _i = 36303, pi = 36306, Ti = 36307, Ai = 36308, bi = 36311, Fe = 3553, Re = 34067, ot = 32879, Ie = 35866, d = {};
608
+ function mr(e, t) {
609
+ return d[t].bindPoint;
610
+ }
611
+ function Si(e, t) {
612
+ return function(r) {
613
+ e.uniform1f(t, r);
614
+ };
615
+ }
616
+ function Fi(e, t) {
617
+ return function(r) {
618
+ e.uniform1fv(t, r);
619
+ };
620
+ }
621
+ function Ri(e, t) {
622
+ return function(r) {
623
+ e.uniform2fv(t, r);
624
+ };
625
+ }
626
+ function Ii(e, t) {
627
+ return function(r) {
628
+ e.uniform3fv(t, r);
629
+ };
630
+ }
631
+ function gi(e, t) {
632
+ return function(r) {
633
+ e.uniform4fv(t, r);
634
+ };
635
+ }
636
+ function hr(e, t) {
637
+ return function(r) {
638
+ e.uniform1i(t, r);
639
+ };
640
+ }
641
+ function yr(e, t) {
642
+ return function(r) {
643
+ e.uniform1iv(t, r);
644
+ };
645
+ }
646
+ function dr(e, t) {
647
+ return function(r) {
648
+ e.uniform2iv(t, r);
649
+ };
650
+ }
651
+ function Er(e, t) {
652
+ return function(r) {
653
+ e.uniform3iv(t, r);
654
+ };
655
+ }
656
+ function _r(e, t) {
657
+ return function(r) {
658
+ e.uniform4iv(t, r);
659
+ };
660
+ }
661
+ function Pi(e, t) {
662
+ return function(r) {
663
+ e.uniform1ui(t, r);
664
+ };
665
+ }
666
+ function vi(e, t) {
667
+ return function(r) {
668
+ e.uniform1uiv(t, r);
669
+ };
670
+ }
671
+ function Ni(e, t) {
672
+ return function(r) {
673
+ e.uniform2uiv(t, r);
674
+ };
675
+ }
676
+ function Ui(e, t) {
677
+ return function(r) {
678
+ e.uniform3uiv(t, r);
679
+ };
680
+ }
681
+ function Bi(e, t) {
682
+ return function(r) {
683
+ e.uniform4uiv(t, r);
684
+ };
685
+ }
686
+ function wi(e, t) {
687
+ return function(r) {
688
+ e.uniformMatrix2fv(t, !1, r);
689
+ };
690
+ }
691
+ function Di(e, t) {
692
+ return function(r) {
693
+ e.uniformMatrix3fv(t, !1, r);
694
+ };
695
+ }
696
+ function Li(e, t) {
697
+ return function(r) {
698
+ e.uniformMatrix4fv(t, !1, r);
699
+ };
700
+ }
701
+ function Mi(e, t) {
702
+ return function(r) {
703
+ e.uniformMatrix2x3fv(t, !1, r);
704
+ };
705
+ }
706
+ function Ci(e, t) {
707
+ return function(r) {
708
+ e.uniformMatrix3x2fv(t, !1, r);
709
+ };
710
+ }
711
+ function Oi(e, t) {
712
+ return function(r) {
713
+ e.uniformMatrix2x4fv(t, !1, r);
714
+ };
715
+ }
716
+ function Gi(e, t) {
717
+ return function(r) {
718
+ e.uniformMatrix4x2fv(t, !1, r);
719
+ };
720
+ }
721
+ function ki(e, t) {
722
+ return function(r) {
723
+ e.uniformMatrix3x4fv(t, !1, r);
724
+ };
725
+ }
726
+ function zi(e, t) {
727
+ return function(r) {
728
+ e.uniformMatrix4x3fv(t, !1, r);
729
+ };
730
+ }
731
+ function g(e, t, r, n) {
732
+ const o = mr(e, t);
733
+ return se(e) ? function(i) {
734
+ let s, a;
735
+ !i || Ut(e, i) ? (s = i, a = null) : (s = i.texture, a = i.sampler), e.uniform1i(n, r), e.activeTexture(Te + r), e.bindTexture(o, s), e.bindSampler(r, a);
736
+ } : function(i) {
737
+ e.uniform1i(n, r), e.activeTexture(Te + r), e.bindTexture(o, i);
738
+ };
739
+ }
740
+ function P(e, t, r, n, o) {
741
+ const i = mr(e, t), s = new Int32Array(o);
742
+ for (let a = 0; a < o; ++a)
743
+ s[a] = r + a;
744
+ return se(e) ? function(a) {
745
+ e.uniform1iv(n, s), a.forEach(function(u, c) {
746
+ e.activeTexture(Te + s[c]);
747
+ let x, f;
748
+ !u || Ut(e, u) ? (x = u, f = null) : (x = u.texture, f = u.sampler), e.bindSampler(r, f), e.bindTexture(i, x);
749
+ });
750
+ } : function(a) {
751
+ e.uniform1iv(n, s), a.forEach(function(u, c) {
752
+ e.activeTexture(Te + s[c]), e.bindTexture(i, u);
753
+ });
754
+ };
755
+ }
756
+ d[Se] = { Type: Float32Array, size: 4, setter: Si, arraySetter: Fi };
757
+ d[Jt] = { Type: Float32Array, size: 8, setter: Ri, cols: 2 };
758
+ d[Qt] = { Type: Float32Array, size: 12, setter: Ii, cols: 3 };
759
+ d[qt] = { Type: Float32Array, size: 16, setter: gi, cols: 4 };
760
+ d[rt] = { Type: Int32Array, size: 4, setter: hr, arraySetter: yr };
761
+ d[er] = { Type: Int32Array, size: 8, setter: dr, cols: 2 };
762
+ d[tr] = { Type: Int32Array, size: 12, setter: Er, cols: 3 };
763
+ d[rr] = { Type: Int32Array, size: 16, setter: _r, cols: 4 };
764
+ d[nt] = { Type: Uint32Array, size: 4, setter: Pi, arraySetter: vi };
765
+ d[fr] = { Type: Uint32Array, size: 8, setter: Ni, cols: 2 };
766
+ d[lr] = { Type: Uint32Array, size: 12, setter: Ui, cols: 3 };
767
+ d[xr] = { Type: Uint32Array, size: 16, setter: Bi, cols: 4 };
768
+ d[nr] = { Type: Uint32Array, size: 4, setter: hr, arraySetter: yr };
769
+ d[or] = { Type: Uint32Array, size: 8, setter: dr, cols: 2 };
770
+ d[ir] = { Type: Uint32Array, size: 12, setter: Er, cols: 3 };
771
+ d[sr] = { Type: Uint32Array, size: 16, setter: _r, cols: 4 };
772
+ d[ar] = { Type: Float32Array, size: 32, setter: wi, rows: 2, cols: 2 };
773
+ d[ur] = { Type: Float32Array, size: 48, setter: Di, rows: 3, cols: 3 };
774
+ d[cr] = { Type: Float32Array, size: 64, setter: Li, rows: 4, cols: 4 };
775
+ d[si] = { Type: Float32Array, size: 32, setter: Mi, rows: 2, cols: 3 };
776
+ d[ai] = { Type: Float32Array, size: 32, setter: Oi, rows: 2, cols: 4 };
777
+ d[ui] = { Type: Float32Array, size: 48, setter: Ci, rows: 3, cols: 2 };
778
+ d[ci] = { Type: Float32Array, size: 48, setter: ki, rows: 3, cols: 4 };
779
+ d[fi] = { Type: Float32Array, size: 64, setter: Gi, rows: 4, cols: 2 };
780
+ d[li] = { Type: Float32Array, size: 64, setter: zi, rows: 4, cols: 3 };
781
+ d[ri] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Fe };
782
+ d[ni] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Re };
783
+ d[oi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: ot };
784
+ d[ii] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Fe };
785
+ d[xi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Ie };
786
+ d[mi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Ie };
787
+ d[hi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Re };
788
+ d[yi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Fe };
789
+ d[di] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: ot };
790
+ d[Ei] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Re };
791
+ d[_i] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Ie };
792
+ d[pi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Fe };
793
+ d[Ti] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: ot };
794
+ d[Ai] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Re };
795
+ d[bi] = { Type: null, size: 0, setter: g, arraySetter: P, bindPoint: Ie };
796
+ function ge(e, t) {
797
+ return function(r) {
798
+ if (r.value)
799
+ switch (e.disableVertexAttribArray(t), r.value.length) {
800
+ case 4:
801
+ e.vertexAttrib4fv(t, r.value);
802
+ break;
803
+ case 3:
804
+ e.vertexAttrib3fv(t, r.value);
805
+ break;
806
+ case 2:
807
+ e.vertexAttrib2fv(t, r.value);
808
+ break;
809
+ case 1:
810
+ e.vertexAttrib1fv(t, r.value);
811
+ break;
812
+ default:
813
+ throw new Error("the length of a float constant value must be between 1 and 4!");
814
+ }
815
+ else
816
+ e.bindBuffer(be, r.buffer), e.enableVertexAttribArray(t), e.vertexAttribPointer(
817
+ t,
818
+ r.numComponents || r.size,
819
+ r.type || Se,
820
+ r.normalize || !1,
821
+ r.stride || 0,
822
+ r.offset || 0
823
+ ), e.vertexAttribDivisor && e.vertexAttribDivisor(t, r.divisor || 0);
824
+ };
825
+ }
826
+ function M(e, t) {
827
+ return function(r) {
828
+ if (r.value)
829
+ if (e.disableVertexAttribArray(t), r.value.length === 4)
830
+ e.vertexAttrib4iv(t, r.value);
831
+ else
832
+ throw new Error("The length of an integer constant value must be 4!");
833
+ else
834
+ e.bindBuffer(be, r.buffer), e.enableVertexAttribArray(t), e.vertexAttribIPointer(
835
+ t,
836
+ r.numComponents || r.size,
837
+ r.type || rt,
838
+ r.stride || 0,
839
+ r.offset || 0
840
+ ), e.vertexAttribDivisor && e.vertexAttribDivisor(t, r.divisor || 0);
841
+ };
842
+ }
843
+ function Pe(e, t) {
844
+ return function(r) {
845
+ if (r.value)
846
+ if (e.disableVertexAttribArray(t), r.value.length === 4)
847
+ e.vertexAttrib4uiv(t, r.value);
848
+ else
849
+ throw new Error("The length of an unsigned integer constant value must be 4!");
850
+ else
851
+ e.bindBuffer(be, r.buffer), e.enableVertexAttribArray(t), e.vertexAttribIPointer(
852
+ t,
853
+ r.numComponents || r.size,
854
+ r.type || nt,
855
+ r.stride || 0,
856
+ r.offset || 0
857
+ ), e.vertexAttribDivisor && e.vertexAttribDivisor(t, r.divisor || 0);
858
+ };
859
+ }
860
+ function it(e, t, r) {
861
+ const n = r.size, o = r.count;
862
+ return function(i) {
863
+ e.bindBuffer(be, i.buffer);
864
+ const s = i.size || i.numComponents || n, a = s / o, u = i.type || Se, x = d[u].size * s, f = i.normalize || !1, m = i.offset || 0, h = x / o;
865
+ for (let l = 0; l < o; ++l)
866
+ e.enableVertexAttribArray(t + l), e.vertexAttribPointer(
867
+ t + l,
868
+ a,
869
+ u,
870
+ f,
871
+ x,
872
+ m + h * l
873
+ ), e.vertexAttribDivisor && e.vertexAttribDivisor(t + l, i.divisor || 0);
874
+ };
875
+ }
876
+ const F = {};
877
+ F[Se] = { size: 4, setter: ge };
878
+ F[Jt] = { size: 8, setter: ge };
879
+ F[Qt] = { size: 12, setter: ge };
880
+ F[qt] = { size: 16, setter: ge };
881
+ F[rt] = { size: 4, setter: M };
882
+ F[er] = { size: 8, setter: M };
883
+ F[tr] = { size: 12, setter: M };
884
+ F[rr] = { size: 16, setter: M };
885
+ F[nt] = { size: 4, setter: Pe };
886
+ F[fr] = { size: 8, setter: Pe };
887
+ F[lr] = { size: 12, setter: Pe };
888
+ F[xr] = { size: 16, setter: Pe };
889
+ F[nr] = { size: 4, setter: M };
890
+ F[or] = { size: 8, setter: M };
891
+ F[ir] = { size: 12, setter: M };
892
+ F[sr] = { size: 16, setter: M };
893
+ F[ar] = { size: 4, setter: it, count: 2 };
894
+ F[ur] = { size: 9, setter: it, count: 3 };
895
+ F[cr] = { size: 16, setter: it, count: 4 };
896
+ const $i = /ERROR:\s*\d+:(\d+)/gi;
897
+ function Vi(e, t = "", r = 0) {
898
+ const n = [...t.matchAll($i)], o = new Map(n.map((i, s) => {
899
+ const a = parseInt(i[1]), u = n[s + 1], c = u ? u.index : t.length, x = t.substring(i.index, c);
900
+ return [a - 1, x];
901
+ }));
902
+ return e.split(`
903
+ `).map((i, s) => {
904
+ const a = o.get(s);
905
+ return `${s + 1 + r}: ${i}${a ? `
906
+
907
+ ^^^ ${a}` : ""}`;
908
+ }).join(`
909
+ `);
910
+ }
911
+ const Et = /^[ \t]*\n/;
912
+ function pr(e) {
913
+ let t = 0;
914
+ return Et.test(e) && (t = 1, e = e.replace(Et, "")), { lineOffset: t, shaderSource: e };
915
+ }
916
+ function Hi(e, t) {
917
+ return e.errorCallback(t), e.callback && setTimeout(() => {
918
+ e.callback(`${t}
919
+ ${e.errors.join(`
920
+ `)}`);
921
+ }), null;
922
+ }
923
+ function Xi(e, t, r, n) {
924
+ if (n = n || tt, !e.getShaderParameter(r, Ho)) {
925
+ const i = e.getShaderInfoLog(r), { lineOffset: s, shaderSource: a } = pr(e.getShaderSource(r)), u = `${Vi(a, i, s)}
926
+ Error compiling ${Ot(e, t)}: ${i}`;
927
+ return n(u), u;
928
+ }
929
+ return "";
930
+ }
931
+ function st(e, t, r) {
932
+ let n, o, i;
933
+ if (typeof t == "function" && (r = t, t = void 0), typeof e == "function")
934
+ r = e, e = void 0;
935
+ else if (e && !Array.isArray(e)) {
936
+ const c = e;
937
+ r = c.errorCallback, e = c.attribLocations, n = c.transformFeedbackVaryings, o = c.transformFeedbackMode, i = c.callback;
938
+ }
939
+ const s = r || tt, a = [], u = {
940
+ errorCallback(c, ...x) {
941
+ a.push(c), s(c, ...x);
942
+ },
943
+ transformFeedbackVaryings: n,
944
+ transformFeedbackMode: o,
945
+ callback: i,
946
+ errors: a
947
+ };
948
+ {
949
+ let c = {};
950
+ Array.isArray(e) ? e.forEach(function(x, f) {
951
+ c[x] = t ? t[f] : f;
952
+ }) : c = e || {}, u.attribLocations = c;
953
+ }
954
+ return u;
955
+ }
956
+ const Zi = [
957
+ "VERTEX_SHADER",
958
+ "FRAGMENT_SHADER"
959
+ ];
960
+ function ji(e, t) {
961
+ if (t.indexOf("frag") >= 0)
962
+ return Zo;
963
+ if (t.indexOf("vert") >= 0)
964
+ return jo;
965
+ }
966
+ function Wi(e, t, r) {
967
+ const n = e.getAttachedShaders(t);
968
+ for (const o of n)
969
+ r.has(o) && e.deleteShader(o);
970
+ e.deleteProgram(t);
971
+ }
972
+ const Yi = (e = 0) => new Promise((t) => setTimeout(t, e));
973
+ function Ki(e, t, r) {
974
+ const n = e.createProgram(), {
975
+ attribLocations: o,
976
+ transformFeedbackVaryings: i,
977
+ transformFeedbackMode: s
978
+ } = st(r);
979
+ for (let a = 0; a < t.length; ++a) {
980
+ let u = t[a];
981
+ if (typeof u == "string") {
982
+ const c = Yt(u), x = c ? c.text : u;
983
+ let f = e[Zi[a]];
984
+ c && c.type && (f = ji(e, c.type) || f), u = e.createShader(f), e.shaderSource(u, pr(x).shaderSource), e.compileShader(u), e.attachShader(n, u);
985
+ }
986
+ }
987
+ Object.entries(o).forEach(([a, u]) => e.bindAttribLocation(n, u, a));
988
+ {
989
+ let a = i;
990
+ a && (a.attribs && (a = a.attribs), Array.isArray(a) || (a = Object.keys(a)), e.transformFeedbackVaryings(n, a, s || Wo));
991
+ }
992
+ return e.linkProgram(n), n;
993
+ }
994
+ function Ji(e, t, r, n, o) {
995
+ const i = st(r, n, o), s = new Set(t), a = Ki(e, t, i);
996
+ function u(c, x) {
997
+ const f = qi(c, x, i.errorCallback);
998
+ return f && Wi(c, x, s), f;
999
+ }
1000
+ if (i.callback) {
1001
+ Qi(e, a).then(() => {
1002
+ const c = u(e, a);
1003
+ i.callback(c, c ? void 0 : a);
1004
+ });
1005
+ return;
1006
+ }
1007
+ return u(e, a) ? void 0 : a;
1008
+ }
1009
+ async function Qi(e, t) {
1010
+ const r = e.getExtension("KHR_parallel_shader_compile"), n = r ? (i, s) => i.getProgramParameter(s, r.COMPLETION_STATUS_KHR) : () => !0;
1011
+ let o = 0;
1012
+ do
1013
+ await Yi(o), o = 1e3 / 60;
1014
+ while (!n(e, t));
1015
+ }
1016
+ function qi(e, t, r) {
1017
+ if (r = r || tt, !e.getProgramParameter(t, Xo)) {
1018
+ const o = e.getProgramInfoLog(t);
1019
+ r(`Error in program linking: ${o}`);
1020
+ const s = e.getAttachedShaders(t).map((a) => Xi(e, e.getShaderParameter(a, e.SHADER_TYPE), a, r));
1021
+ return `${o}
1022
+ ${s.filter((a) => a).join(`
1023
+ `)}`;
1024
+ }
1025
+ }
1026
+ function es(e, t, r, n, o) {
1027
+ return Ji(e, t, r, n, o);
1028
+ }
1029
+ function Tr(e) {
1030
+ const t = e.name;
1031
+ return t.startsWith("gl_") || t.startsWith("webgl_");
1032
+ }
1033
+ const ts = /(\.|\[|]|\w+)/g, rs = (e) => e >= "0" && e <= "9";
1034
+ function ns(e, t, r, n) {
1035
+ const o = e.split(ts).filter((a) => a !== "");
1036
+ let i = 0, s = "";
1037
+ for (; ; ) {
1038
+ const a = o[i++];
1039
+ s += a;
1040
+ const u = rs(a[0]), c = u ? parseInt(a) : a;
1041
+ if (u && (s += o[i++]), i === o.length) {
1042
+ r[c] = t;
1043
+ break;
1044
+ } else {
1045
+ const f = o[i++], m = f === "[", h = r[c] || (m ? [] : {});
1046
+ r[c] = h, r = h, n[s] = n[s] || /* @__PURE__ */ function(l) {
1047
+ return function(E) {
1048
+ Ar(l, E);
1049
+ };
1050
+ }(h), s += f;
1051
+ }
1052
+ }
1053
+ }
1054
+ function os(e, t) {
1055
+ let r = 0;
1056
+ function n(a, u, c) {
1057
+ const x = u.name.endsWith("[0]"), f = u.type, m = d[f];
1058
+ if (!m)
1059
+ throw new Error(`unknown type: 0x${f.toString(16)}`);
1060
+ let h;
1061
+ if (m.bindPoint) {
1062
+ const l = r;
1063
+ r += u.size, x ? h = m.arraySetter(e, f, l, c, u.size) : h = m.setter(e, f, l, c, u.size);
1064
+ } else
1065
+ m.arraySetter && x ? h = m.arraySetter(e, c) : h = m.setter(e, c);
1066
+ return h.location = c, h;
1067
+ }
1068
+ const o = {}, i = {}, s = e.getProgramParameter(t, Kt);
1069
+ for (let a = 0; a < s; ++a) {
1070
+ const u = e.getActiveUniform(t, a);
1071
+ if (Tr(u))
1072
+ continue;
1073
+ let c = u.name;
1074
+ c.endsWith("[0]") && (c = c.substr(0, c.length - 3));
1075
+ const x = e.getUniformLocation(t, u.name);
1076
+ if (x) {
1077
+ const f = n(t, u, x);
1078
+ o[c] = f, ns(c, f, i, o);
1079
+ }
1080
+ }
1081
+ return o;
1082
+ }
1083
+ function is(e, t) {
1084
+ const r = {}, n = e.getProgramParameter(t, Ko);
1085
+ for (let o = 0; o < n; ++o) {
1086
+ const i = e.getTransformFeedbackVarying(t, o);
1087
+ r[i.name] = {
1088
+ index: o,
1089
+ type: i.type,
1090
+ size: i.size
1091
+ };
1092
+ }
1093
+ return r;
1094
+ }
1095
+ function ss(e, t) {
1096
+ const r = e.getProgramParameter(t, Kt), n = [], o = [];
1097
+ for (let a = 0; a < r; ++a) {
1098
+ o.push(a), n.push({});
1099
+ const u = e.getActiveUniform(t, a);
1100
+ n[a].name = u.name;
1101
+ }
1102
+ [
1103
+ ["UNIFORM_TYPE", "type"],
1104
+ ["UNIFORM_SIZE", "size"],
1105
+ // num elements
1106
+ ["UNIFORM_BLOCK_INDEX", "blockNdx"],
1107
+ ["UNIFORM_OFFSET", "offset"]
1108
+ ].forEach(function(a) {
1109
+ const u = a[0], c = a[1];
1110
+ e.getActiveUniforms(t, o, e[u]).forEach(function(x, f) {
1111
+ n[f][c] = x;
1112
+ });
1113
+ });
1114
+ const i = {}, s = e.getProgramParameter(t, Jo);
1115
+ for (let a = 0; a < s; ++a) {
1116
+ const u = e.getActiveUniformBlockName(t, a), c = {
1117
+ index: e.getUniformBlockIndex(t, u),
1118
+ usedByVertexShader: e.getActiveUniformBlockParameter(t, a, Qo),
1119
+ usedByFragmentShader: e.getActiveUniformBlockParameter(t, a, qo),
1120
+ size: e.getActiveUniformBlockParameter(t, a, ei),
1121
+ uniformIndices: e.getActiveUniformBlockParameter(t, a, ti)
1122
+ };
1123
+ c.used = c.usedByVertexShader || c.usedByFragmentShader, i[u] = c;
1124
+ }
1125
+ return {
1126
+ blockSpecs: i,
1127
+ uniformData: n
1128
+ };
1129
+ }
1130
+ function Ar(e, t) {
1131
+ for (const r in t) {
1132
+ const n = e[r];
1133
+ typeof n == "function" ? n(t[r]) : Ar(e[r], t[r]);
1134
+ }
1135
+ }
1136
+ function Ge(e, ...t) {
1137
+ const r = e.uniformSetters || e, n = t.length;
1138
+ for (let o = 0; o < n; ++o) {
1139
+ const i = t[o];
1140
+ if (Array.isArray(i)) {
1141
+ const s = i.length;
1142
+ for (let a = 0; a < s; ++a)
1143
+ Ge(r, i[a]);
1144
+ } else
1145
+ for (const s in i) {
1146
+ const a = r[s];
1147
+ a && a(i[s]);
1148
+ }
1149
+ }
1150
+ }
1151
+ function as(e, t) {
1152
+ const r = {}, n = e.getProgramParameter(t, Yo);
1153
+ for (let o = 0; o < n; ++o) {
1154
+ const i = e.getActiveAttrib(t, o);
1155
+ if (Tr(i))
1156
+ continue;
1157
+ const s = e.getAttribLocation(t, i.name), a = F[i.type], u = a.setter(e, s, a);
1158
+ u.location = s, r[i.name] = u;
1159
+ }
1160
+ return r;
1161
+ }
1162
+ function us(e, t) {
1163
+ for (const r in t) {
1164
+ const n = e[r];
1165
+ n && n(t[r]);
1166
+ }
1167
+ }
1168
+ function _t(e, t, r) {
1169
+ r.vertexArrayObject ? e.bindVertexArray(r.vertexArrayObject) : (us(t.attribSetters || t, r.attribs), r.indices && e.bindBuffer(Vo, r.indices));
1170
+ }
1171
+ function pt(e, t) {
1172
+ const r = os(e, t), n = as(e, t), o = {
1173
+ program: t,
1174
+ uniformSetters: r,
1175
+ attribSetters: n
1176
+ };
1177
+ return se(e) && (o.uniformBlockSpec = ss(e, t), o.transformFeedbackInfo = is(e, t)), o;
1178
+ }
1179
+ const cs = /\s|{|}|;/;
1180
+ function we(e, t, r, n, o) {
1181
+ const i = st(r, n, o), s = [];
1182
+ if (t = t.map(function(c) {
1183
+ if (!cs.test(c)) {
1184
+ const x = Yt(c);
1185
+ if (x)
1186
+ c = x.text;
1187
+ else {
1188
+ const f = `no element with id: ${c}`;
1189
+ i.errorCallback(f), s.push(f);
1190
+ }
1191
+ }
1192
+ return c;
1193
+ }), s.length)
1194
+ return Hi(i, "");
1195
+ const a = i.callback;
1196
+ a && (i.callback = (c, x) => {
1197
+ a(c, c ? void 0 : pt(e, x));
1198
+ });
1199
+ const u = es(e, t, i);
1200
+ return u ? pt(e, u) : null;
1201
+ }
1202
+ class fs {
1203
+ constructor(t = [], r = (n, o) => n < o ? -1 : n > o ? 1 : 0) {
1204
+ if (this.data = t, this.length = this.data.length, this.compare = r, this.length > 0)
1205
+ for (let n = (this.length >> 1) - 1; n >= 0; n--) this._down(n);
1206
+ }
1207
+ push(t) {
1208
+ this.data.push(t), this._up(this.length++);
1209
+ }
1210
+ pop() {
1211
+ if (this.length === 0) return;
1212
+ const t = this.data[0], r = this.data.pop();
1213
+ return --this.length > 0 && (this.data[0] = r, this._down(0)), t;
1214
+ }
1215
+ peek() {
1216
+ return this.data[0];
1217
+ }
1218
+ _up(t) {
1219
+ const { data: r, compare: n } = this, o = r[t];
1220
+ for (; t > 0; ) {
1221
+ const i = t - 1 >> 1, s = r[i];
1222
+ if (n(o, s) >= 0) break;
1223
+ r[t] = s, t = i;
1224
+ }
1225
+ r[t] = o;
1226
+ }
1227
+ _down(t) {
1228
+ const { data: r, compare: n } = this, o = this.length >> 1, i = r[t];
1229
+ for (; t < o; ) {
1230
+ let s = (t << 1) + 1;
1231
+ const a = s + 1;
1232
+ if (a < this.length && n(r[a], r[s]) < 0 && (s = a), n(r[s], i) >= 0) break;
1233
+ r[t] = r[s], t = s;
1234
+ }
1235
+ r[t] = i;
1236
+ }
1237
+ }
1238
+ class ls {
1239
+ constructor(t, r, n, o) {
1240
+ this._projector = t, this._verts = r, this._uv = n, this._projVerts = r.map(t), this._trigs = o, this._segs = [], this._segCount = 0, this._segTrigs = [], this._queue = new fs([], function(i, s) {
1241
+ return s.epsilon - i.epsilon;
1242
+ }), this._vertToSeg = new Array(r.length);
1243
+ for (const i in this._verts)
1244
+ this._vertToSeg[i] = [];
1245
+ for (const i in this._trigs) {
1246
+ const s = this._trigs[i], a = s[0], u = s[1], c = s[2];
1247
+ this._segment(a, u, i), this._segment(u, c, i), this._segment(c, a, i);
1248
+ }
1249
+ }
1250
+ _segment(t, r, n, o = 1 / 0) {
1251
+ if (this._vertToSeg[t] && this._vertToSeg[t][r] !== void 0) {
1252
+ const x = this._vertToSeg[t][r];
1253
+ return this._segTrigs[x].includes(n) || this._segTrigs[x].push(n), x;
1254
+ }
1255
+ const i = this._segCount++;
1256
+ this._segs[i] = [t, r], this._vertToSeg[t][r] = i, this._vertToSeg[r][t] = i, this._segTrigs[i] = [n];
1257
+ const s = [(this._verts[t][0] + this._verts[r][0]) / 2, (this._verts[t][1] + this._verts[r][1]) / 2], a = this._projector(s), u = [
1258
+ (this._projVerts[t][0] + this._projVerts[r][0]) / 2,
1259
+ (this._projVerts[t][1] + this._projVerts[r][1]) / 2
1260
+ ], c = (a[0] - u[0]) ** 2 + (a[1] - u[1]) ** 2;
1261
+ return Number.isFinite(c) && c < o && this._queue.push({
1262
+ v1: t,
1263
+ v2: r,
1264
+ epsilon: c,
1265
+ midpoint: s,
1266
+ projectedMid: a
1267
+ }), i;
1268
+ }
1269
+ output() {
1270
+ return {
1271
+ unprojected: Array.from(this._verts),
1272
+ projected: Array.from(this._projVerts),
1273
+ uv: Array.from(this._uv),
1274
+ trigs: Array.from(this._trigs)
1275
+ };
1276
+ }
1277
+ _stepsWithSameEpsilon = 0;
1278
+ lowerEpsilon(t) {
1279
+ let r = this._queue.peek().epsilon, n = r;
1280
+ for (; r >= t; )
1281
+ if (this.step(), r = this._queue.peek().epsilon, r === n) {
1282
+ if (this._stepsWithSameEpsilon++, this._stepsWithSameEpsilon < 500) {
1283
+ console.warn("Arrugator stopped due to epsilon stall. Raster may need hints for proper arrugation.");
1284
+ break;
1285
+ }
1286
+ } else
1287
+ this._stepsWithSameEpsilon = 0, n = r;
1288
+ }
1289
+ get epsilon() {
1290
+ return this._queue.peek().epsilon;
1291
+ }
1292
+ set epsilon(t) {
1293
+ return this.lowerEpsilon(t);
1294
+ }
1295
+ step() {
1296
+ const t = this._queue.pop();
1297
+ return this._splitSegment(t, t.epsilon);
1298
+ }
1299
+ force() {
1300
+ const t = this._queue.data;
1301
+ this._queue.data = [], this._queue.length = 0, t.forEach((r) => this._splitSegment(r, 1 / 0));
1302
+ }
1303
+ _splitSegment(t, r) {
1304
+ const n = t.v1, o = t.v2, i = this._vertToSeg[n] && this._vertToSeg[n][o], s = this._segTrigs[i];
1305
+ if (s.length >= 3)
1306
+ throw new Error("Somehow a segment is shared by three triangles");
1307
+ delete this._segTrigs[i], delete this._segs[i], delete this._vertToSeg[n][o], delete this._vertToSeg[o][n];
1308
+ const a = this._verts.length;
1309
+ this._projVerts[a] = t.projectedMid, this._verts[a] = t.midpoint, this._vertToSeg[a] = [], this._uv[a] = [(this._uv[n][0] + this._uv[o][0]) / 2, (this._uv[n][1] + this._uv[o][1]) / 2];
1310
+ for (const u of s)
1311
+ this._splitTriangle(n, o, a, u, r);
1312
+ }
1313
+ _splitTriangle(t, r, n, o, i = 1 / 0) {
1314
+ const s = this._trigs[o];
1315
+ let a, u = !1;
1316
+ if (s[0] === t && s[1] === r)
1317
+ a = s[2], u = !0;
1318
+ else if (s[1] === t && s[2] === r)
1319
+ a = s[0], u = !0;
1320
+ else if (s[2] === t && s[0] === r)
1321
+ a = s[1], u = !0;
1322
+ else if (s[1] === t && s[0] === r)
1323
+ a = s[2], u = !1;
1324
+ else if (s[2] === t && s[1] === r)
1325
+ a = s[0], u = !1;
1326
+ else if (s[0] === t && s[2] === r)
1327
+ a = s[1], u = !1;
1328
+ else
1329
+ throw new Error("Data structure mishap: could not fetch 3rd vertex used in triangle");
1330
+ const c = this._trigs.length;
1331
+ u ? (this._trigs[o] = [t, n, a], this._trigs[c] = [n, r, a]) : (this._trigs[o] = [n, t, a], this._trigs[c] = [r, n, a]);
1332
+ const x = this._vertToSeg[t] && this._vertToSeg[t][r], f = this._vertToSeg[r] && this._vertToSeg[r][a], m = this._vertToSeg[a] && this._vertToSeg[a][t];
1333
+ function h(l) {
1334
+ return l !== o;
1335
+ }
1336
+ x !== void 0 && (this._segTrigs[x] = this._segTrigs[x].filter(h)), f !== void 0 && (this._segTrigs[f] = this._segTrigs[f].filter(h)), m !== void 0 && (this._segTrigs[m] = this._segTrigs[m].filter(h)), this._segment(t, n, o, i), this._segment(n, a, o, i), this._segment(a, t, o, i), this._segment(r, n, c, i), this._segment(n, a, c, i), this._segment(a, r, c, i);
1337
+ }
1338
+ }
1339
+ function Tt(e, t, r = 100) {
1340
+ const n = [-20037508342789244e-9, 20037508342789244e-9], o = [t[0], t[3], t[1], t[2]], i = Ir(e, "EPSG:3857").forward;
1341
+ function s(x) {
1342
+ const f = i(x), m = Math.abs((f[0] - n[0]) / (20037508342789244e-9 * 2)), h = Math.abs((f[1] - n[1]) / (20037508342789244e-9 * 2));
1343
+ return [m, h];
1344
+ }
1345
+ const a = [
1346
+ [0, 0],
1347
+ [0, 1],
1348
+ [1, 0],
1349
+ [1, 1]
1350
+ ], u = new ls(s, o, a, [
1351
+ [0, 1, 3],
1352
+ [0, 3, 2]
1353
+ ]);
1354
+ if (r > 0) {
1355
+ u.force();
1356
+ for (let x = 0; x < r; x++)
1357
+ u.step();
1358
+ }
1359
+ const c = u.output();
1360
+ return {
1361
+ pos: c.projected.flat(),
1362
+ uv: c.uv.flat(),
1363
+ trigs: c.trigs.flat()
1364
+ };
1365
+ }
1366
+ function At(e, t, r = 2) {
1367
+ const n = t && t.length, o = n ? t[0] * r : e.length;
1368
+ let i = br(e, 0, o, r, !0);
1369
+ const s = [];
1370
+ if (!i || i.next === i.prev) return s;
1371
+ let a, u, c;
1372
+ if (n && (i = ds(e, t, i, r)), e.length > 80 * r) {
1373
+ a = 1 / 0, u = 1 / 0;
1374
+ let x = -1 / 0, f = -1 / 0;
1375
+ for (let m = r; m < o; m += r) {
1376
+ const h = e[m], l = e[m + 1];
1377
+ h < a && (a = h), l < u && (u = l), h > x && (x = h), l > f && (f = l);
1378
+ }
1379
+ c = Math.max(x - a, f - u), c = c !== 0 ? 32767 / c : 0;
1380
+ }
1381
+ return ne(i, s, r, a, u, c, 0), s;
1382
+ }
1383
+ function br(e, t, r, n, o) {
1384
+ let i;
1385
+ if (o === gs(e, t, r, n) > 0)
1386
+ for (let s = t; s < r; s += n) i = bt(s / n | 0, e[s], e[s + 1], i);
1387
+ else
1388
+ for (let s = r - n; s >= t; s -= n) i = bt(s / n | 0, e[s], e[s + 1], i);
1389
+ return i && K(i, i.next) && (ie(i), i = i.next), i;
1390
+ }
1391
+ function H(e, t) {
1392
+ if (!e) return e;
1393
+ t || (t = e);
1394
+ let r = e, n;
1395
+ do
1396
+ if (n = !1, !r.steiner && (K(r, r.next) || S(r.prev, r, r.next) === 0)) {
1397
+ if (ie(r), r = t = r.prev, r === r.next) break;
1398
+ n = !0;
1399
+ } else
1400
+ r = r.next;
1401
+ while (n || r !== t);
1402
+ return t;
1403
+ }
1404
+ function ne(e, t, r, n, o, i, s) {
1405
+ if (!e) return;
1406
+ !s && i && As(e, n, o, i);
1407
+ let a = e;
1408
+ for (; e.prev !== e.next; ) {
1409
+ const u = e.prev, c = e.next;
1410
+ if (i ? ms(e, n, o, i) : xs(e)) {
1411
+ t.push(u.i, e.i, c.i), ie(e), e = c.next, a = c.next;
1412
+ continue;
1413
+ }
1414
+ if (e = c, e === a) {
1415
+ s ? s === 1 ? (e = hs(H(e), t), ne(e, t, r, n, o, i, 2)) : s === 2 && ys(e, t, r, n, o, i) : ne(H(e), t, r, n, o, i, 1);
1416
+ break;
1417
+ }
1418
+ }
1419
+ }
1420
+ function xs(e) {
1421
+ const t = e.prev, r = e, n = e.next;
1422
+ if (S(t, r, n) >= 0) return !1;
1423
+ const o = t.x, i = r.x, s = n.x, a = t.y, u = r.y, c = n.y, x = Math.min(o, i, s), f = Math.min(a, u, c), m = Math.max(o, i, s), h = Math.max(a, u, c);
1424
+ let l = n.next;
1425
+ for (; l !== t; ) {
1426
+ if (l.x >= x && l.x <= m && l.y >= f && l.y <= h && q(o, a, i, u, s, c, l.x, l.y) && S(l.prev, l, l.next) >= 0) return !1;
1427
+ l = l.next;
1428
+ }
1429
+ return !0;
1430
+ }
1431
+ function ms(e, t, r, n) {
1432
+ const o = e.prev, i = e, s = e.next;
1433
+ if (S(o, i, s) >= 0) return !1;
1434
+ const a = o.x, u = i.x, c = s.x, x = o.y, f = i.y, m = s.y, h = Math.min(a, u, c), l = Math.min(x, f, m), E = Math.max(a, u, c), p = Math.max(x, f, m), T = ke(h, l, t, r, n), R = ke(E, p, t, r, n);
1435
+ let y = e.prevZ, _ = e.nextZ;
1436
+ for (; y && y.z >= T && _ && _.z <= R; ) {
1437
+ if (y.x >= h && y.x <= E && y.y >= l && y.y <= p && y !== o && y !== s && q(a, x, u, f, c, m, y.x, y.y) && S(y.prev, y, y.next) >= 0 || (y = y.prevZ, _.x >= h && _.x <= E && _.y >= l && _.y <= p && _ !== o && _ !== s && q(a, x, u, f, c, m, _.x, _.y) && S(_.prev, _, _.next) >= 0)) return !1;
1438
+ _ = _.nextZ;
1439
+ }
1440
+ for (; y && y.z >= T; ) {
1441
+ if (y.x >= h && y.x <= E && y.y >= l && y.y <= p && y !== o && y !== s && q(a, x, u, f, c, m, y.x, y.y) && S(y.prev, y, y.next) >= 0) return !1;
1442
+ y = y.prevZ;
1443
+ }
1444
+ for (; _ && _.z <= R; ) {
1445
+ if (_.x >= h && _.x <= E && _.y >= l && _.y <= p && _ !== o && _ !== s && q(a, x, u, f, c, m, _.x, _.y) && S(_.prev, _, _.next) >= 0) return !1;
1446
+ _ = _.nextZ;
1447
+ }
1448
+ return !0;
1449
+ }
1450
+ function hs(e, t) {
1451
+ let r = e;
1452
+ do {
1453
+ const n = r.prev, o = r.next.next;
1454
+ !K(n, o) && Fr(n, r, r.next, o) && oe(n, o) && oe(o, n) && (t.push(n.i, r.i, o.i), ie(r), ie(r.next), r = e = o), r = r.next;
1455
+ } while (r !== e);
1456
+ return H(r);
1457
+ }
1458
+ function ys(e, t, r, n, o, i) {
1459
+ let s = e;
1460
+ do {
1461
+ let a = s.next.next;
1462
+ for (; a !== s.prev; ) {
1463
+ if (s.i !== a.i && Fs(s, a)) {
1464
+ let u = Rr(s, a);
1465
+ s = H(s, s.next), u = H(u, u.next), ne(s, t, r, n, o, i, 0), ne(u, t, r, n, o, i, 0);
1466
+ return;
1467
+ }
1468
+ a = a.next;
1469
+ }
1470
+ s = s.next;
1471
+ } while (s !== e);
1472
+ }
1473
+ function ds(e, t, r, n) {
1474
+ const o = [];
1475
+ for (let i = 0, s = t.length; i < s; i++) {
1476
+ const a = t[i] * n, u = i < s - 1 ? t[i + 1] * n : e.length, c = br(e, a, u, n, !1);
1477
+ c === c.next && (c.steiner = !0), o.push(Ss(c));
1478
+ }
1479
+ o.sort(Es);
1480
+ for (let i = 0; i < o.length; i++)
1481
+ r = _s(o[i], r);
1482
+ return r;
1483
+ }
1484
+ function Es(e, t) {
1485
+ let r = e.x - t.x;
1486
+ if (r === 0 && (r = e.y - t.y, r === 0)) {
1487
+ const n = (e.next.y - e.y) / (e.next.x - e.x), o = (t.next.y - t.y) / (t.next.x - t.x);
1488
+ r = n - o;
1489
+ }
1490
+ return r;
1491
+ }
1492
+ function _s(e, t) {
1493
+ const r = ps(e, t);
1494
+ if (!r)
1495
+ return t;
1496
+ const n = Rr(r, e);
1497
+ return H(n, n.next), H(r, r.next);
1498
+ }
1499
+ function ps(e, t) {
1500
+ let r = t;
1501
+ const n = e.x, o = e.y;
1502
+ let i = -1 / 0, s;
1503
+ if (K(e, r)) return r;
1504
+ do {
1505
+ if (K(e, r.next)) return r.next;
1506
+ if (o <= r.y && o >= r.next.y && r.next.y !== r.y) {
1507
+ const f = r.x + (o - r.y) * (r.next.x - r.x) / (r.next.y - r.y);
1508
+ if (f <= n && f > i && (i = f, s = r.x < r.next.x ? r : r.next, f === n))
1509
+ return s;
1510
+ }
1511
+ r = r.next;
1512
+ } while (r !== t);
1513
+ if (!s) return null;
1514
+ const a = s, u = s.x, c = s.y;
1515
+ let x = 1 / 0;
1516
+ r = s;
1517
+ do {
1518
+ if (n >= r.x && r.x >= u && n !== r.x && Sr(o < c ? n : i, o, u, c, o < c ? i : n, o, r.x, r.y)) {
1519
+ const f = Math.abs(o - r.y) / (n - r.x);
1520
+ oe(r, e) && (f < x || f === x && (r.x > s.x || r.x === s.x && Ts(s, r))) && (s = r, x = f);
1521
+ }
1522
+ r = r.next;
1523
+ } while (r !== a);
1524
+ return s;
1525
+ }
1526
+ function Ts(e, t) {
1527
+ return S(e.prev, e, t.prev) < 0 && S(t.next, e, e.next) < 0;
1528
+ }
1529
+ function As(e, t, r, n) {
1530
+ let o = e;
1531
+ do
1532
+ o.z === 0 && (o.z = ke(o.x, o.y, t, r, n)), o.prevZ = o.prev, o.nextZ = o.next, o = o.next;
1533
+ while (o !== e);
1534
+ o.prevZ.nextZ = null, o.prevZ = null, bs(o);
1535
+ }
1536
+ function bs(e) {
1537
+ let t, r = 1;
1538
+ do {
1539
+ let n = e, o;
1540
+ e = null;
1541
+ let i = null;
1542
+ for (t = 0; n; ) {
1543
+ t++;
1544
+ let s = n, a = 0;
1545
+ for (let c = 0; c < r && (a++, s = s.nextZ, !!s); c++)
1546
+ ;
1547
+ let u = r;
1548
+ for (; a > 0 || u > 0 && s; )
1549
+ a !== 0 && (u === 0 || !s || n.z <= s.z) ? (o = n, n = n.nextZ, a--) : (o = s, s = s.nextZ, u--), i ? i.nextZ = o : e = o, o.prevZ = i, i = o;
1550
+ n = s;
1551
+ }
1552
+ i.nextZ = null, r *= 2;
1553
+ } while (t > 1);
1554
+ return e;
1555
+ }
1556
+ function ke(e, t, r, n, o) {
1557
+ return e = (e - r) * o | 0, t = (t - n) * o | 0, e = (e | e << 8) & 16711935, e = (e | e << 4) & 252645135, e = (e | e << 2) & 858993459, e = (e | e << 1) & 1431655765, t = (t | t << 8) & 16711935, t = (t | t << 4) & 252645135, t = (t | t << 2) & 858993459, t = (t | t << 1) & 1431655765, e | t << 1;
1558
+ }
1559
+ function Ss(e) {
1560
+ let t = e, r = e;
1561
+ do
1562
+ (t.x < r.x || t.x === r.x && t.y < r.y) && (r = t), t = t.next;
1563
+ while (t !== e);
1564
+ return r;
1565
+ }
1566
+ function Sr(e, t, r, n, o, i, s, a) {
1567
+ return (o - s) * (t - a) >= (e - s) * (i - a) && (e - s) * (n - a) >= (r - s) * (t - a) && (r - s) * (i - a) >= (o - s) * (n - a);
1568
+ }
1569
+ function q(e, t, r, n, o, i, s, a) {
1570
+ return !(e === s && t === a) && Sr(e, t, r, n, o, i, s, a);
1571
+ }
1572
+ function Fs(e, t) {
1573
+ return e.next.i !== t.i && e.prev.i !== t.i && !Rs(e, t) && // dones't intersect other edges
1574
+ (oe(e, t) && oe(t, e) && Is(e, t) && // locally visible
1575
+ (S(e.prev, e, t.prev) || S(e, t.prev, t)) || // does not create opposite-facing sectors
1576
+ K(e, t) && S(e.prev, e, e.next) > 0 && S(t.prev, t, t.next) > 0);
1577
+ }
1578
+ function S(e, t, r) {
1579
+ return (t.y - e.y) * (r.x - t.x) - (t.x - e.x) * (r.y - t.y);
1580
+ }
1581
+ function K(e, t) {
1582
+ return e.x === t.x && e.y === t.y;
1583
+ }
1584
+ function Fr(e, t, r, n) {
1585
+ const o = ye(S(e, t, r)), i = ye(S(e, t, n)), s = ye(S(r, n, e)), a = ye(S(r, n, t));
1586
+ return !!(o !== i && s !== a || o === 0 && he(e, r, t) || i === 0 && he(e, n, t) || s === 0 && he(r, e, n) || a === 0 && he(r, t, n));
1587
+ }
1588
+ function he(e, t, r) {
1589
+ return t.x <= Math.max(e.x, r.x) && t.x >= Math.min(e.x, r.x) && t.y <= Math.max(e.y, r.y) && t.y >= Math.min(e.y, r.y);
1590
+ }
1591
+ function ye(e) {
1592
+ return e > 0 ? 1 : e < 0 ? -1 : 0;
1593
+ }
1594
+ function Rs(e, t) {
1595
+ let r = e;
1596
+ do {
1597
+ if (r.i !== e.i && r.next.i !== e.i && r.i !== t.i && r.next.i !== t.i && Fr(r, r.next, e, t)) return !0;
1598
+ r = r.next;
1599
+ } while (r !== e);
1600
+ return !1;
1601
+ }
1602
+ function oe(e, t) {
1603
+ return S(e.prev, e, e.next) < 0 ? S(e, t, e.next) >= 0 && S(e, e.prev, t) >= 0 : S(e, t, e.prev) < 0 || S(e, e.next, t) < 0;
1604
+ }
1605
+ function Is(e, t) {
1606
+ let r = e, n = !1;
1607
+ const o = (e.x + t.x) / 2, i = (e.y + t.y) / 2;
1608
+ do
1609
+ r.y > i != r.next.y > i && r.next.y !== r.y && o < (r.next.x - r.x) * (i - r.y) / (r.next.y - r.y) + r.x && (n = !n), r = r.next;
1610
+ while (r !== e);
1611
+ return n;
1612
+ }
1613
+ function Rr(e, t) {
1614
+ const r = ze(e.i, e.x, e.y), n = ze(t.i, t.x, t.y), o = e.next, i = t.prev;
1615
+ return e.next = t, t.prev = e, r.next = o, o.prev = r, n.next = r, r.prev = n, i.next = n, n.prev = i, n;
1616
+ }
1617
+ function bt(e, t, r, n) {
1618
+ const o = ze(e, t, r);
1619
+ return n ? (o.next = n.next, o.prev = n, n.next.prev = o, n.next = o) : (o.prev = o, o.next = o), o;
1620
+ }
1621
+ function ie(e) {
1622
+ e.next.prev = e.prev, e.prev.next = e.next, e.prevZ && (e.prevZ.nextZ = e.nextZ), e.nextZ && (e.nextZ.prevZ = e.prevZ);
1623
+ }
1624
+ function ze(e, t, r) {
1625
+ return {
1626
+ i: e,
1627
+ // vertex index in coordinates array
1628
+ x: t,
1629
+ y: r,
1630
+ // vertex coordinates
1631
+ prev: null,
1632
+ // previous and next vertex nodes in a polygon ring
1633
+ next: null,
1634
+ z: 0,
1635
+ // z-order curve value
1636
+ prevZ: null,
1637
+ // previous and next nodes in z-order
1638
+ nextZ: null,
1639
+ steiner: !1
1640
+ // indicates whether this is a steiner point
1641
+ };
1642
+ }
1643
+ function gs(e, t, r, n) {
1644
+ let o = 0;
1645
+ for (let i = t, s = r - n; i < r; i += n)
1646
+ o += (e[s] - e[i]) * (e[i + 1] + e[s + 1]), s = i;
1647
+ return o;
1648
+ }
1649
+ function St(e) {
1650
+ const t = [], r = [], n = e[0][0].length;
1651
+ let o = 0, i = 0;
1652
+ for (const s of e) {
1653
+ for (const a of s)
1654
+ for (let u = 0; u < n; u++) t.push(a[u]);
1655
+ i && (o += i, r.push(o)), i = s.length;
1656
+ }
1657
+ return { vertices: t, holes: r, dimensions: n };
1658
+ }
1659
+ function Ft(e) {
1660
+ if (Object.prototype.hasOwnProperty.call(e, "type")) {
1661
+ const t = e.type;
1662
+ if (t === "Polygon" || t === "MultiPolygon")
1663
+ return e;
1664
+ if (t === "Feature" && (e.geometry.type === "Polygon" || e.geometry.type === "MultiPolygon"))
1665
+ return e.geometry;
1666
+ if (t === "FeatureCollection") {
1667
+ const r = e.features.filter(
1668
+ (n) => n.geometry.type === "Polygon" || n.geometry.type === "MultiPolygon"
1669
+ );
1670
+ if (r.length === 1)
1671
+ return r[0].geometry;
1672
+ if (r.length > 1) {
1673
+ const n = [];
1674
+ for (const o of r) {
1675
+ const i = o.geometry;
1676
+ if (i.type === "MultiPolygon")
1677
+ for (const s of i.coordinates)
1678
+ n.push(s);
1679
+ else
1680
+ n.push(i.coordinates);
1681
+ }
1682
+ return {
1683
+ type: "MultiPolygon",
1684
+ coordinates: n
1685
+ };
1686
+ } else
1687
+ throw new Error("No valid Polygon or MultiPolygon features found");
1688
+ } else
1689
+ throw new Error("Invalid GeoJSON format, only support Polygon, MultiPolygon, Feature, FeatureCollection");
1690
+ } else
1691
+ throw new Error("Invalid GeoJSON format");
1692
+ }
1693
+ function Ps(e) {
1694
+ return typeof e == "string" ? fetch(e).then((t) => t.json()).then((t) => Ft(t)) : Promise.resolve(Ft(e));
1695
+ }
1696
+ function vs(e) {
1697
+ let t = [], r = [];
1698
+ if (e.type === "MultiPolygon") {
1699
+ const n = e.coordinates.length;
1700
+ let o = 0;
1701
+ for (let i = 0; i < n; i++) {
1702
+ const s = e.coordinates[i], a = St(s), { vertices: u, holes: c, dimensions: x } = a, m = At(u, c, x).map((h) => h + o);
1703
+ o += u.length / 2;
1704
+ for (let h = 0; h < u.length; h++)
1705
+ t.push(u[h]);
1706
+ for (let h = 0; h < m.length; h++)
1707
+ r.push(m[h]);
1708
+ }
1709
+ } else {
1710
+ const n = St(e.coordinates), { vertices: o, holes: i, dimensions: s } = n;
1711
+ t = o, r = At(o, i, s);
1712
+ }
1713
+ return {
1714
+ vertices: t,
1715
+ indices: r
1716
+ };
1717
+ }
1718
+ const Ns = `
1719
+ #ifdef GL_ES
1720
+ precision highp int;
1721
+ precision mediump float;
1722
+ #endif
1723
+ uniform sampler2D u_sampler;
1724
+ uniform float u_opacity;
1725
+ varying vec2 v_uv;
1726
+ void main() {
1727
+ vec4 color = texture2D(u_sampler, v_uv);
1728
+ gl_FragColor = color * u_opacity;
1729
+ }
1730
+ `, Us = `
1731
+ uniform mat4 u_matrix;
1732
+ attribute vec2 a_pos;
1733
+ attribute vec2 a_uv;
1734
+ varying vec2 v_uv;
1735
+ void main() {
1736
+ gl_Position = u_matrix * vec4(a_pos, 0.0, 1.0);
1737
+ v_uv = a_uv;
1738
+ }
1739
+ `, Rt = `
1740
+ #ifdef GL_ES
1741
+ precision highp int;
1742
+ precision mediump float;
1743
+ #endif
1744
+
1745
+ void main() {
1746
+ gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);
1747
+ }
1748
+ `, It = `
1749
+ uniform mat4 u_matrix;
1750
+ uniform float u_alt;
1751
+ attribute vec2 a_pos;
1752
+
1753
+ const float PI = 3.1415926536;
1754
+ const float earthRadius = 6371008.8;
1755
+ const float earthCircumference = 2.0 * PI * earthRadius;
1756
+
1757
+ float circumferenceAtLatitude(float latitude) {
1758
+ return earthCircumference * cos(latitude * PI / 180.0);
1759
+ }
1760
+
1761
+ float mercatorXfromLng(float lng) {
1762
+ return (180.0 + lng) / 360.0;
1763
+ }
1764
+
1765
+ float mercatorYfromLat(float lat) {
1766
+ return (180.0 - (180.0 / PI * log(tan(PI / 4.0 + lat * PI / 360.0)))) / 360.0;
1767
+ }
1768
+
1769
+ float mercatorZfromAltitude(float altitude, float lat) {
1770
+ return altitude / circumferenceAtLatitude(lat);
1771
+ }
1772
+
1773
+ vec3 mercatorfromLngLat(vec2 lnglat, float alt) {
1774
+ return vec3(mercatorXfromLng(lnglat.x), mercatorYfromLat(lnglat.y), mercatorZfromAltitude(alt, lnglat.y));
1775
+ }
1776
+
1777
+ void main() {
1778
+ vec3 mercator = mercatorfromLngLat(a_pos, 0.0);
1779
+ gl_Position = u_matrix * vec4(mercator, 1.0);
1780
+ }
1781
+ `;
1782
+ class ws {
1783
+ option;
1784
+ map;
1785
+ gl;
1786
+ loaded;
1787
+ arrugado;
1788
+ programInfo;
1789
+ bufferInfo;
1790
+ texture;
1791
+ maskProperty;
1792
+ maskProgramInfo;
1793
+ maskBufferInfo;
1794
+ constructor(t) {
1795
+ this.option = t, this.loaded = !1, this.maskProperty = Object.assign({ type: "in" }, t.mask);
1796
+ const { projection: r, coordinates: n } = t;
1797
+ this.arrugado = Tt(r, n, t.arrugatorStep);
1798
+ }
1799
+ onAdd(t, r) {
1800
+ if (!r)
1801
+ throw new Error("ImageLayerCore requires a WebGL rendering context during onAdd.");
1802
+ this.map = t, this.gl = r, this.programInfo = we(r, [Us, Ns]), this.loadTexture(t, r), this.bufferInfo = Ne(r, {
1803
+ a_pos: { numComponents: 2, data: this.arrugado.pos },
1804
+ a_uv: { numComponents: 2, data: this.arrugado.uv },
1805
+ indices: this.arrugado.trigs
1806
+ }), this.maskProperty.data && this.getMaskBufferInfo(r, this.maskProperty.data).then((n) => {
1807
+ this.maskProgramInfo = we(r, [It, Rt]), this.maskBufferInfo = n;
1808
+ });
1809
+ }
1810
+ onRemove(t, r) {
1811
+ r && (this.programInfo && r.deleteProgram(this.programInfo.program), this.maskProgramInfo && r.deleteProgram(this.maskProgramInfo.program), this.texture && (r.deleteTexture(this.texture), this.texture = void 0));
1812
+ }
1813
+ render(t) {
1814
+ if (this.maskProperty.data && !this.maskBufferInfo)
1815
+ return;
1816
+ const r = t.gl;
1817
+ if (this.loaded && this.programInfo && this.bufferInfo) {
1818
+ if (r.enable(r.BLEND), r.blendFunc(r.ONE, r.ONE_MINUS_SRC_ALPHA), this.maskProgramInfo && this.maskBufferInfo) {
1819
+ t.prepareStencilMask?.(), r.useProgram(this.maskProgramInfo.program), r.enable(r.STENCIL_TEST), r.stencilFunc(r.ALWAYS, 1, 255), r.stencilOp(r.REPLACE, r.REPLACE, r.REPLACE), r.stencilMask(255), r.clear(r.STENCIL_BUFFER_BIT), Ge(this.maskProgramInfo, { u_matrix: t.matrix }), _t(r, this.maskProgramInfo, this.maskBufferInfo);
1820
+ let n = r.UNSIGNED_SHORT;
1821
+ this.maskBufferInfo.numElements / 3 > 65535 && (r.getExtension("OES_element_index_uint"), n = r.UNSIGNED_INT), r.drawElements(r.TRIANGLES, this.maskBufferInfo.numElements, n, 0);
1822
+ }
1823
+ if (r.useProgram(this.programInfo.program), this.maskProgramInfo?.program) {
1824
+ const n = this.maskProperty.type === "out" ? 0 : 1;
1825
+ r.stencilFunc(r.EQUAL, n, 255), r.stencilOp(r.KEEP, r.KEEP, r.KEEP);
1826
+ }
1827
+ Ge(this.programInfo, {
1828
+ u_matrix: t.matrix,
1829
+ u_opacity: this.option.opacity ?? 1,
1830
+ u_sampler: this.texture
1831
+ }), _t(r, this.programInfo, this.bufferInfo), r.drawElements(r.TRIANGLES, this.arrugado.trigs.length, r.UNSIGNED_SHORT, 0);
1832
+ }
1833
+ }
1834
+ updateImage(t) {
1835
+ return !this.map || !this.gl ? this : (this.option.opacity = t.opacity ?? this.option.opacity, this.option.crossOrigin = t.crossOrigin ?? this.option.crossOrigin, (t.projection || t.coordinates || t.arrugatorStep) && (this.option.projection = t.projection ?? this.option.projection, this.option.coordinates = t.coordinates ?? this.option.coordinates, this.option.arrugatorStep = t.arrugatorStep ?? this.option.arrugatorStep, this.arrugado = Tt(this.option.projection, this.option.coordinates, this.option.arrugatorStep), this.bufferInfo = Ne(this.gl, {
1836
+ a_pos: { numComponents: 2, data: this.arrugado.pos },
1837
+ a_uv: { numComponents: 2, data: this.arrugado.uv },
1838
+ indices: this.arrugado.trigs
1839
+ })), t.url || t.resampling ? (this.loaded = !1, this.option.url = t.url ?? this.option.url, this.option.resampling = t.resampling ?? this.option.resampling, this.loadTexture(this.map, this.gl)) : this.map.triggerRepaint(), this);
1840
+ }
1841
+ updateMask(t) {
1842
+ return !this.map || !this.gl ? this : (this.maskProperty = Object.assign(this.maskProperty, t), t.data ? this.getMaskBufferInfo(this.gl, t.data).then((r) => {
1843
+ this.maskProgramInfo || (this.maskProgramInfo = we(this.gl, [It, Rt])), this.maskBufferInfo = r, this.map?.triggerRepaint();
1844
+ }) : Object.prototype.hasOwnProperty.call(t, "data") && t.data === void 0 ? (this.maskBufferInfo = void 0, this.map?.triggerRepaint()) : this.map?.triggerRepaint(), this);
1845
+ }
1846
+ loadTexture(t, r) {
1847
+ this.texture && (r.deleteTexture(this.texture), this.texture = void 0);
1848
+ const n = this.option.resampling === "nearest" ? r.NEAREST : r.LINEAR;
1849
+ $o(
1850
+ r,
1851
+ {
1852
+ src: this.option.url,
1853
+ crossOrigin: this.option.crossOrigin,
1854
+ minMag: n,
1855
+ flipY: 0,
1856
+ premultiplyAlpha: 1
1857
+ },
1858
+ (o, i, s) => {
1859
+ if (o)
1860
+ throw o;
1861
+ const a = r.getParameter(r.MAX_TEXTURE_SIZE), { width: u, height: c } = s;
1862
+ if (u > a || c > a)
1863
+ throw new Error(`The texture size exceeds the maximum supported size: ${a}x${a}`);
1864
+ this.texture = i, this.loaded = !0, t.triggerRepaint();
1865
+ }
1866
+ );
1867
+ }
1868
+ getMaskBufferInfo(t, r) {
1869
+ return Ps(r).then((n) => {
1870
+ const { vertices: o, indices: i } = vs(n);
1871
+ return Ne(t, {
1872
+ a_pos: { numComponents: 2, data: o },
1873
+ indices: i.length / 3 > 65535 ? new Uint32Array(i) : new Uint16Array(i)
1874
+ });
1875
+ });
1876
+ }
1877
+ }
1878
+ export {
1879
+ ws as default
1880
+ };