rapid-render 1.0.16 → 1.0.17

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.
@@ -1,130 +1,4 @@
1
- var S = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(S || {});
2
- class A {
3
- usedElemNum;
4
- typedArray;
5
- arrayType;
6
- maxElemNum;
7
- bytePerElem;
8
- arraybuffer;
9
- uint32;
10
- float32;
11
- uint16;
12
- constructor(t) {
13
- this.usedElemNum = 0, this.maxElemNum = 512, this.bytePerElem = this.getArrayType(t).BYTES_PER_ELEMENT, this.arrayType = t, this.arraybuffer = new ArrayBuffer(this.maxElemNum * this.bytePerElem), this.updateTypedArray();
14
- }
15
- getArrayType(t) {
16
- switch (t) {
17
- case 0:
18
- return Float32Array;
19
- case 1:
20
- return Uint32Array;
21
- case 2:
22
- return Uint16Array;
23
- default:
24
- throw new Error("Unsupported ArrayType");
25
- }
26
- }
27
- updateTypedArray() {
28
- switch (this.uint32 = new Uint32Array(this.arraybuffer), this.float32 = new Float32Array(this.arraybuffer), this.uint16 = new Uint16Array(this.arraybuffer), this.arrayType) {
29
- case 0:
30
- this.typedArray = this.float32;
31
- break;
32
- case 1:
33
- this.typedArray = this.uint32;
34
- break;
35
- case 2:
36
- this.typedArray = this.uint16;
37
- break;
38
- }
39
- }
40
- clear() {
41
- this.usedElemNum = 0;
42
- }
43
- static removeAtIndices(t, e) {
44
- const r = Math.max(...e.map((h) => h.usedElemNum)), i = [...new Set(t)].filter(
45
- (h) => h >= 0 && h < r
46
- ).sort((h, o) => h - o);
47
- if (i.length === 0)
48
- return 0;
49
- let s = 0, a = 0;
50
- for (let h = 0; h < r; h++) {
51
- if (a < i.length && h === i[a]) {
52
- a++;
53
- continue;
54
- }
55
- if (s !== h)
56
- for (const o of e)
57
- o.typedArray[s] = o.typedArray[h];
58
- s++;
59
- }
60
- for (const h of e)
61
- h.usedElemNum = s;
62
- return r - s;
63
- }
64
- resize(t = 0) {
65
- if (t += this.usedElemNum, t > this.maxElemNum) {
66
- for (; t > this.maxElemNum; )
67
- this.maxElemNum *= 2;
68
- return this.setMaxSize(this.maxElemNum), !0;
69
- }
70
- return !1;
71
- }
72
- setMaxSize(t = this.maxElemNum) {
73
- const e = this.typedArray;
74
- this.maxElemNum = t, this.arraybuffer = new ArrayBuffer(t * this.bytePerElem), this.updateTypedArray(), this.typedArray.set(e);
75
- }
76
- pushUint32(t) {
77
- this.resize(1), this.uint32[this.usedElemNum++] = t;
78
- }
79
- pushFloat32(t) {
80
- this.resize(1), this.float32[this.usedElemNum++] = t;
81
- }
82
- push(t) {
83
- this.resize(1), this.typedArray[this.usedElemNum++] = t;
84
- }
85
- pop() {
86
- return this.typedArray[--this.usedElemNum];
87
- }
88
- top() {
89
- return this.typedArray[this.usedElemNum - 1];
90
- }
91
- get(t) {
92
- return this.typedArray[t];
93
- }
94
- getArray(t = 0, e) {
95
- return e === void 0 ? this.typedArray : this.typedArray.subarray(t, e);
96
- }
97
- get length() {
98
- return this.usedElemNum;
99
- }
100
- }
101
- class it extends A {
102
- buffer;
103
- gl;
104
- dirty = !0;
105
- type;
106
- webglBufferSize = 0;
107
- usage;
108
- constructor(t, e, r = t.ARRAY_BUFFER, i = t.DYNAMIC_DRAW) {
109
- super(e), this.gl = t, this.buffer = t.createBuffer(), this.type = r, this.usage = i;
110
- }
111
- makeDirty() {
112
- this.dirty = !0;
113
- }
114
- clear() {
115
- super.clear(), this.dirty = !1;
116
- }
117
- bindBuffer() {
118
- this.gl.bindBuffer(this.type, this.buffer);
119
- }
120
- bufferData() {
121
- if (this.dirty) {
122
- const t = this.gl;
123
- this.maxElemNum > this.webglBufferSize && (t.bufferData(this.type, this.maxElemNum * this.bytePerElem, this.usage), this.webglBufferSize = this.maxElemNum), t.bufferSubData(this.type, 0, this.getArray(0, this.usedElemNum)), this.dirty = !1;
124
- }
125
- }
126
- }
127
- class x {
1
+ class m {
128
2
  _r;
129
3
  _g;
130
4
  _b;
@@ -166,7 +40,7 @@ class x {
166
40
  }
167
41
  updateUint() {
168
42
  this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
169
- const t = x.clampByte(this._a), e = x.clampByte(this._r * t / 255), r = x.clampByte(this._g * t / 255), i = x.clampByte(this._b * t / 255);
43
+ const t = m.clampByte(this._a), e = m.clampByte(this._r * t / 255), r = m.clampByte(this._g * t / 255), i = m.clampByte(this._b * t / 255);
170
44
  this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
171
45
  }
172
46
  reset() {
@@ -185,7 +59,7 @@ class x {
185
59
  this.setRGBA(t.r, t.g, t.b, t.a);
186
60
  }
187
61
  clone() {
188
- return new x(this._r, this._g, this._b, this._a);
62
+ return new m(this._r, this._g, this._b, this._a);
189
63
  }
190
64
  toHexString(t = !0) {
191
65
  const e = this.r.toString(16).padStart(2, "0"), r = this.g.toString(16).padStart(2, "0"), i = this.b.toString(16).padStart(2, "0"), s = this.a.toString(16).padStart(2, "0");
@@ -195,13 +69,13 @@ class x {
195
69
  return t.r === this.r && t.g === this.g && t.b === this.b && t.a === this.a;
196
70
  }
197
71
  static FromHSL(t, e, r) {
198
- return new x(0, 0, 0).setHSL(t, e, r);
72
+ return new m(0, 0, 0).setHSL(t, e, r);
199
73
  }
200
74
  static FromRGB(t, e, r) {
201
- return new x(t, e, r);
75
+ return new m(t, e, r);
202
76
  }
203
77
  static fromNorm(t, e, r, i = 1) {
204
- return new x(
78
+ return new m(
205
79
  Math.round(t * 255),
206
80
  Math.round(e * 255),
207
81
  Math.round(r * 255),
@@ -209,17 +83,17 @@ class x {
209
83
  );
210
84
  }
211
85
  static packColor(t, e, r, i, s) {
212
- const a = x.clampByte(i), h = s ? a / 255 : 1, o = x.clampByte(t * h), c = x.clampByte(e * h), u = x.clampByte(r * h);
86
+ const a = m.clampByte(i), h = s ? a / 255 : 1, o = m.clampByte(t * h), c = m.clampByte(e * h), u = m.clampByte(r * h);
213
87
  return (a << 24 | u << 16 | c << 8 | o) >>> 0;
214
88
  }
215
89
  static fromHex(t) {
216
90
  t.startsWith("#") && (t = t.slice(1));
217
91
  const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
218
92
  let s = 255;
219
- return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new x(e, r, i, s);
93
+ return t.length >= 8 && (s = parseInt(t.slice(6, 8), 16)), new m(e, r, i, s);
220
94
  }
221
95
  add(t) {
222
- return new x(
96
+ return new m(
223
97
  Math.min(this.r + t.r, 255),
224
98
  Math.min(this.g + t.g, 255),
225
99
  Math.min(this.b + t.b, 255),
@@ -227,7 +101,7 @@ class x {
227
101
  );
228
102
  }
229
103
  subtract(t) {
230
- return new x(
104
+ return new m(
231
105
  this.r - t.r,
232
106
  this.g - t.g,
233
107
  this.b - t.b,
@@ -235,12 +109,12 @@ class x {
235
109
  );
236
110
  }
237
111
  divide(t) {
238
- return t instanceof x ? new x(
112
+ return t instanceof m ? new m(
239
113
  this.r / t.r,
240
114
  this.g / t.g,
241
115
  this.b / t.b,
242
116
  this.a / t.a
243
- ) : new x(
117
+ ) : new m(
244
118
  this.r / t,
245
119
  this.g / t,
246
120
  this.b / t,
@@ -248,12 +122,12 @@ class x {
248
122
  );
249
123
  }
250
124
  multiply(t) {
251
- return t instanceof x ? new x(
125
+ return t instanceof m ? new m(
252
126
  this.r * t.r,
253
127
  this.g * t.g,
254
128
  this.b * t.b,
255
129
  this.a * t.a
256
- ) : new x(
130
+ ) : new m(
257
131
  this.r * t,
258
132
  this.g * t,
259
133
  this.b * t,
@@ -263,384 +137,114 @@ class x {
263
137
  clamp() {
264
138
  this._r = Math.max(0, Math.min(255, this._r)), this._g = Math.max(0, Math.min(255, this._g)), this._b = Math.max(0, Math.min(255, this._b)), this._a = Math.max(0, Math.min(255, this._a)), this.updateUint();
265
139
  }
266
- static Red = new x(255, 0, 0, 255);
267
- static Green = new x(0, 255, 0, 255);
268
- static Blue = new x(0, 0, 255, 255);
269
- static Yellow = new x(255, 255, 0, 255);
270
- static Purple = new x(128, 0, 128, 255);
271
- static Orange = new x(255, 165, 0, 255);
272
- static Pink = new x(255, 192, 203, 255);
273
- static Gray = new x(128, 128, 128, 255);
274
- static Brown = new x(139, 69, 19, 255);
275
- static Cyan = new x(0, 255, 255, 255);
276
- static Magenta = new x(255, 0, 255, 255);
277
- static Lime = new x(192, 255, 0, 255);
278
- static White = new x(255, 255, 255, 255);
279
- static Black = new x(0, 0, 0, 255);
280
- static Transparent = new x(0, 0, 0, 0);
140
+ static Red = new m(255, 0, 0, 255);
141
+ static Green = new m(0, 255, 0, 255);
142
+ static Blue = new m(0, 0, 255, 255);
143
+ static Yellow = new m(255, 255, 0, 255);
144
+ static Purple = new m(128, 0, 128, 255);
145
+ static Orange = new m(255, 165, 0, 255);
146
+ static Pink = new m(255, 192, 203, 255);
147
+ static Gray = new m(128, 128, 128, 255);
148
+ static Brown = new m(139, 69, 19, 255);
149
+ static Cyan = new m(0, 255, 255, 255);
150
+ static Magenta = new m(255, 0, 255, 255);
151
+ static Lime = new m(192, 255, 0, 255);
152
+ static White = new m(255, 255, 255, 255);
153
+ static Black = new m(0, 0, 0, 255);
154
+ static Transparent = new m(0, 0, 0, 0);
281
155
  }
282
- const T = 6;
283
- class At {
284
- matrixCount = 0;
285
- buffer;
286
- data;
287
- temporary = -1;
288
- constructor(t = 10) {
289
- this.buffer = new A(S.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
290
- }
291
- alloc() {
292
- const t = this.allocDirty();
293
- return this.identity(t), t;
156
+ var tt = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(tt || {}), q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
157
+ class Ct {
158
+ render;
159
+ cache = /* @__PURE__ */ new Map();
160
+ constructor(t) {
161
+ this.render = t;
294
162
  }
295
- allocDirty() {
296
- return this.buffer.resize(T) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += T, this.matrixCount++;
163
+ async load(t, e) {
164
+ let r = this.cache.get(t);
165
+ if (r)
166
+ return new N(r);
167
+ try {
168
+ const i = await this._fetchImage(t);
169
+ return r = V.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
170
+ } catch (i) {
171
+ throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
172
+ }
297
173
  }
298
- reset() {
299
- this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
174
+ create(t, e) {
175
+ if (e?.key && this.cache.has(e.key))
176
+ return new N(this.cache.get(e.key));
177
+ const r = V.fromSource(this.render, t, e);
178
+ return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new N(r);
300
179
  }
301
- identity(t) {
302
- const e = t * T, r = this.data;
303
- r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
180
+ createRenderTexture(t) {
181
+ return new _t(this.render, t);
304
182
  }
305
- translate(t, e, r) {
306
- const i = t * T, s = this.data;
307
- s[i + 4] = s[i] * e + s[i + 2] * r + s[i + 4], s[i + 5] = s[i + 1] * e + s[i + 3] * r + s[i + 5];
183
+ createTextTexture(t) {
184
+ return new Pt(this.render, t);
308
185
  }
309
- scale(t, e, r) {
310
- const i = t * T, s = this.data;
311
- s[i] *= e, s[i + 1] *= e, s[i + 2] *= r, s[i + 3] *= r;
186
+ destroy(t, e = !1) {
187
+ let r, i;
188
+ typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof N ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
312
189
  }
313
- rotate(t, e) {
314
- const r = t * T, i = this.data, s = Math.cos(e), a = Math.sin(e), h = i[r], o = i[r + 1], c = i[r + 2], u = i[r + 3];
315
- i[r] = h * s + c * a, i[r + 1] = o * s + u * a, i[r + 2] = h * -a + c * s, i[r + 3] = o * -a + u * s;
190
+ destroyAll() {
191
+ for (const t of this.cache.values())
192
+ t.destroy(this.render.gl);
193
+ this.cache.clear();
316
194
  }
317
- rotateWithOffset(t, e, r, i) {
318
- this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
195
+ _fetchImage(t) {
196
+ return new Promise((e, r) => {
197
+ const i = new Image();
198
+ i.crossOrigin = "anonymous", i.onload = () => e(i), i.onerror = () => r(new Error(`Failed to load image resource: ${t}`)), i.src = t;
199
+ });
319
200
  }
320
- copy(t, e) {
321
- const r = t * T, i = e * T, s = this.data;
322
- s[r] = s[i], s[r + 1] = s[i + 1], s[r + 2] = s[i + 2], s[r + 3] = s[i + 3], s[r + 4] = s[i + 4], s[r + 5] = s[i + 5];
201
+ }
202
+ class V {
203
+ glTexture = null;
204
+ width;
205
+ height;
206
+ uid;
207
+ refCount = 0;
208
+ constructor(t, e, r) {
209
+ this.glTexture = t, this.width = e, this.height = r;
323
210
  }
324
- multiply(t, e) {
325
- this.multiplyOut(t, t, e);
211
+ static fromSource(t, e, r = {}) {
212
+ const i = rt(t, e, r);
213
+ return new V(i, e.width, e.height);
326
214
  }
327
- multiplyOut(t, e, r) {
328
- const i = t * T, s = e * T, a = r * T, h = this.data, o = h[s], c = h[s + 1], u = h[s + 2], l = h[s + 3], d = h[s + 4], f = h[s + 5], m = h[a], g = h[a + 1], v = h[a + 2], y = h[a + 3], w = h[a + 4], M = h[a + 5];
329
- h[i] = o * m + u * g, h[i + 1] = c * m + l * g, h[i + 2] = o * v + u * y, h[i + 3] = c * v + l * y, h[i + 4] = o * w + u * M + d, h[i + 5] = c * w + l * M + f;
215
+ updateSource(t, e, r = {}) {
216
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && ht(t, r.textureFilter), r.wrap !== void 0 && at(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
330
217
  }
331
- invert(t) {
332
- const e = t * T, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], h = r[e + 3], o = r[e + 4], c = r[e + 5];
333
- let u = i * h - s * a;
334
- if (!u) {
335
- this.identity(t);
336
- return;
337
- }
338
- u = 1 / u, r[e] = h * u, r[e + 1] = -s * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * c - h * o) * u, r[e + 5] = (s * o - i * c) * u;
218
+ setFilterMode(t, e) {
219
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), ht(t, e), t.bindTexture(t.TEXTURE_2D, null));
339
220
  }
340
- transformPoint(t, e, r) {
341
- const i = t * T, s = this.data;
342
- return {
343
- x: e * s[i] + r * s[i + 2] + s[i + 4],
344
- y: e * s[i + 1] + r * s[i + 3] + s[i + 5]
345
- };
221
+ setWrapMode(t, e) {
222
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), at(t, e), t.bindTexture(t.TEXTURE_2D, null));
346
223
  }
347
- worldToLocal(t, e, r) {
348
- const i = this.allocDirty();
349
- this.copy(i, t), this.invert(i);
350
- const s = this.transformPoint(i, e, r);
351
- return this.matrixCount--, this.buffer.usedElemNum -= T, s;
224
+ destroy(t) {
225
+ this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
352
226
  }
353
- localToWorld(t, e, r) {
354
- return this.transformPoint(t, e, r);
227
+ }
228
+ class N {
229
+ base;
230
+ uvX = 0;
231
+ uvY = 0;
232
+ uvW = 1;
233
+ uvH = 1;
234
+ rawWidth = 0;
235
+ rawHeight = 0;
236
+ offsetX = 0;
237
+ offsetY = 0;
238
+ scale = 1;
239
+ isAtlas = !1;
240
+ flipY = !1;
241
+ isRotated = !1;
242
+ glTexture = null;
243
+ get width() {
244
+ return this.isRotated ? this.rawHeight : this.rawWidth;
355
245
  }
356
- getPosition(t) {
357
- const e = t * T, r = this.data;
358
- return { x: r[e + 4], y: r[e + 5] };
359
- }
360
- getScale(t) {
361
- const e = t * T, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), s = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
362
- return { x: i, y: s };
363
- }
364
- getRotation(t) {
365
- const e = t * T, r = this.data;
366
- return Math.atan2(r[e + 1], r[e]);
367
- }
368
- toCSSMatrix(t, e = 1, r = 1) {
369
- const i = t * T, s = this.data;
370
- return `matrix(${s[i] * e}, ${s[i + 1] * r}, ${s[i + 2] * e}, ${s[i + 3] * r}, ${s[i + 4] * e}, ${s[i + 5] * r})`;
371
- }
372
- getMatrix(t) {
373
- const e = t * T;
374
- return this.data.slice(e, e + T);
375
- }
376
- getMatrixRef(t) {
377
- const e = t * T;
378
- return this.data.subarray(e, e + T);
379
- }
380
- setMatrix(t, e) {
381
- const r = t * T, i = this.data;
382
- i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
383
- }
384
- multiplyAffineInPlace(t, e, r, i, s, a, h) {
385
- const o = t * 6, c = this.data, u = c[o], l = c[o + 1], d = c[o + 2], f = c[o + 3], m = c[o + 4], g = c[o + 5];
386
- c[o] = u * e + d * r, c[o + 1] = l * e + f * r, c[o + 2] = u * i + d * s, c[o + 3] = l * i + f * s, c[o + 4] = u * a + d * h + m, c[o + 5] = l * a + f * h + g;
387
- }
388
- multiplyAffine(t, e, r, i, s, a, h, o) {
389
- const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], g = l[c + 3], v = l[c + 4], y = l[c + 5];
390
- l[u] = d * r + m * i, l[u + 1] = f * r + g * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + g * a, l[u + 4] = d * h + m * o + v, l[u + 5] = f * h + g * o + y;
391
- }
392
- }
393
- class bt {
394
- matrix = new At();
395
- step = 0;
396
- stack = new A(S.Uint32);
397
- stepWorldM = new A(S.Uint32);
398
- stepAction = new A(S.Uint32);
399
- stepParentM = new A(S.Uint32);
400
- stepClose = new A(S.Uint32);
401
- stepStack = new A(S.Uint32);
402
- curLocalM = -1;
403
- curWorldM = -1;
404
- rapid;
405
- constructor(t) {
406
- this.reset(), this.rapid = t;
407
- }
408
- save() {
409
- this.stack.push(this.curWorldM);
410
- const t = this.curWorldM;
411
- return this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.allocDirty(), this.stepWorldM.push(this.curWorldM), this.stepParentM.push(t), this.stepAction.push(1), this.stepClose.push(0), this.stepStack.push(this.step), this.matrix.copy(this.curWorldM, t), { world: this.curWorldM, local: this.curLocalM, step: this.step++ };
412
- }
413
- restore() {
414
- this.stack.length == 0 || this.stepStack.length == 0 || (this.curWorldM = this.stack.pop(), this.curLocalM = this.curWorldM - 1, this.stepParentM.push(this.stack.get(this.stack.length - 1)), this.stepWorldM.push(this.curWorldM), this.stepAction.push(0), this.stepClose.push(0), this.stepClose.typedArray[this.stepStack.pop()] = this.step, this.step++);
415
- }
416
- restoreAll() {
417
- for (; this.stack.length > 0 && this.stepStack.length > 0; )
418
- this.restore();
419
- }
420
- getStep(t) {
421
- return typeof t == "number" ? t : t.step;
422
- }
423
- walkSubtree(t, e, r = 1 / 0) {
424
- let i = 0, s = t;
425
- for (; s < this.step; ) {
426
- const a = this.stepAction.get(s);
427
- if (a === 1) {
428
- if (i++, i > r) {
429
- const h = this.stepClose.get(s);
430
- if (h > s) {
431
- s = h + 1, i--;
432
- continue;
433
- }
434
- }
435
- } else
436
- i--;
437
- if (e(s, a, i) === !1 || a === 0 && i === 0) return;
438
- s++;
439
- }
440
- }
441
- getParent(t) {
442
- const e = this.getStep(t);
443
- return this.stepParentM.get(e);
444
- }
445
- getChildren(t) {
446
- const e = this.getStep(t), r = this.stepClose.get(e), i = [];
447
- let s = e + 1;
448
- for (; s < r; )
449
- this.stepAction.get(s) === 1 ? (i.push(s), s = this.stepClose.get(s) + 1) : s++;
450
- return i;
451
- }
452
- updateMatrixSubtree(t) {
453
- const e = this.getStep(t);
454
- this.walkSubtree(e, (r, i) => {
455
- if (i === 1) {
456
- const s = this.stepWorldM.get(r), a = s - 1, h = this.stepParentM.get(r);
457
- this.matrix.multiplyOut(s, h, a);
458
- }
459
- });
460
- }
461
- translate(t, e) {
462
- this.matrix.translate(this.curLocalM, t, e), this.matrix.translate(this.curWorldM, t, e);
463
- }
464
- scale(t, e = t) {
465
- this.matrix.scale(this.curLocalM, t, e), this.matrix.scale(this.curWorldM, t, e);
466
- }
467
- rotate(t) {
468
- this.matrix.rotate(this.curLocalM, t), this.matrix.rotate(this.curWorldM, t);
469
- }
470
- rotateWithOffset(t, e, r) {
471
- this.matrix.rotateWithOffset(this.curLocalM, t, e, r), this.matrix.rotateWithOffset(this.curWorldM, t, e, r);
472
- }
473
- identity() {
474
- this.matrix.identity(this.curLocalM), this.matrix.identity(this.curWorldM);
475
- }
476
- reset() {
477
- this.matrix.reset(), this.stack.clear(), this.stepAction.clear(), this.stepWorldM.clear(), this.stepParentM.clear(), this.stepClose.clear(), this.stepStack.clear(), this.step = 0, this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.alloc();
478
- }
479
- localToWorld(t, e) {
480
- return this.matrix.localToWorld(this.curWorldM, t, e);
481
- }
482
- worldToLocal(t, e) {
483
- return this.matrix.worldToLocal(this.curWorldM, t, e);
484
- }
485
- getGlobalPosition() {
486
- return this.matrix.getPosition(this.curWorldM);
487
- }
488
- getGlobalScale() {
489
- return this.matrix.getScale(this.curWorldM);
490
- }
491
- getGlobalRotation() {
492
- return this.matrix.getRotation(this.curWorldM);
493
- }
494
- toCSSMatrix() {
495
- return this.matrix.toCSSMatrix(this.curWorldM);
496
- }
497
- getTransform() {
498
- const t = this.curWorldM * T;
499
- return this.matrix.data.slice(t, t + T);
500
- }
501
- setTransform(t) {
502
- const e = this.curWorldM * T, r = this.matrix.data;
503
- r[e] = t[0], r[e + 1] = t[1], r[e + 2] = t[2], r[e + 3] = t[3], r[e + 4] = t[4], r[e + 5] = t[5];
504
- }
505
- transformPoint(t, e) {
506
- return this.matrix.transformPoint(this.curLocalM, t, e);
507
- }
508
- applyTransform(t, e = 0, r = 0, i = -1) {
509
- let s = t.x ?? 0, a = t.y ?? 0;
510
- t.position && (s += t.position.x, a += t.position.y);
511
- let h = 1, o = 1;
512
- const c = t.scale;
513
- c && (typeof c == "number" ? (h = c, o = c) : (h = c.x, o = c.y));
514
- const u = t.rotation ?? 0;
515
- let l = t.offsetX ?? 0, d = t.offsetY ?? 0;
516
- t.offset && (l += t.offset.x, d += t.offset.y);
517
- const f = t.origin;
518
- f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
519
- const m = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = m * h, y = g * h, w = -g * o, M = m * o, _ = s + v * l + w * d, P = a + y * l + M * d;
520
- if (i !== -1) {
521
- this.matrix.multiplyAffine(
522
- this.curWorldM,
523
- i,
524
- v,
525
- y,
526
- w,
527
- M,
528
- _,
529
- P
530
- );
531
- return;
532
- }
533
- this.matrix.multiplyAffineInPlace(
534
- this.curLocalM,
535
- v,
536
- y,
537
- w,
538
- M,
539
- _,
540
- P
541
- ), this.matrix.multiplyAffineInPlace(
542
- this.curWorldM,
543
- v,
544
- y,
545
- w,
546
- M,
547
- _,
548
- P
549
- );
550
- }
551
- }
552
- var q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(q || {});
553
- class Ut {
554
- render;
555
- cache = /* @__PURE__ */ new Map();
556
- constructor(t) {
557
- this.render = t;
558
- }
559
- async load(t, e) {
560
- let r = this.cache.get(t);
561
- if (r)
562
- return new N(r);
563
- try {
564
- const i = await this._fetchImage(t);
565
- return r = V.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
566
- } catch (i) {
567
- throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
568
- }
569
- }
570
- create(t, e) {
571
- if (e?.key && this.cache.has(e.key))
572
- return new N(this.cache.get(e.key));
573
- const r = V.fromSource(this.render, t, e);
574
- return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new N(r);
575
- }
576
- createRenderTexture(t) {
577
- return new Ct(this.render, t);
578
- }
579
- createTextTexture(t) {
580
- return new Pt(this.render, t);
581
- }
582
- destroy(t, e = !1) {
583
- let r, i;
584
- typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof N ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
585
- }
586
- destroyAll() {
587
- for (const t of this.cache.values())
588
- t.destroy(this.render.gl);
589
- this.cache.clear();
590
- }
591
- _fetchImage(t) {
592
- return new Promise((e, r) => {
593
- const i = new Image();
594
- i.crossOrigin = "anonymous", i.onload = () => e(i), i.onerror = () => r(new Error(`Failed to load image resource: ${t}`)), i.src = t;
595
- });
596
- }
597
- }
598
- class V {
599
- glTexture = null;
600
- width;
601
- height;
602
- uid;
603
- refCount = 0;
604
- constructor(t, e, r) {
605
- this.glTexture = t, this.width = e, this.height = r;
606
- }
607
- static fromSource(t, e, r = {}) {
608
- const i = J(t, e, r);
609
- return new V(i, e.width, e.height);
610
- }
611
- updateSource(t, e, r = {}) {
612
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && nt(t, r.textureFilter), r.wrap !== void 0 && st(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
613
- }
614
- setFilterMode(t, e) {
615
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), nt(t, e), t.bindTexture(t.TEXTURE_2D, null));
616
- }
617
- setWrapMode(t, e) {
618
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), st(t, e), t.bindTexture(t.TEXTURE_2D, null));
619
- }
620
- destroy(t) {
621
- this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
622
- }
623
- }
624
- class N {
625
- base;
626
- uvX = 0;
627
- uvY = 0;
628
- uvW = 1;
629
- uvH = 1;
630
- rawWidth = 0;
631
- rawHeight = 0;
632
- offsetX = 0;
633
- offsetY = 0;
634
- scale = 1;
635
- isAtlas = !1;
636
- flipY = !1;
637
- isRotated = !1;
638
- glTexture = null;
639
- get width() {
640
- return this.isRotated ? this.rawHeight : this.rawWidth;
641
- }
642
- get height() {
643
- return this.isRotated ? this.rawWidth : this.rawHeight;
246
+ get height() {
247
+ return this.isRotated ? this.rawWidth : this.rawHeight;
644
248
  }
645
249
  // Stored pixel-space region (before UV conversion), used by getSubTexture()
646
250
  _px = 0;
@@ -665,31 +269,30 @@ class N {
665
269
  }
666
270
  splitGrid(t, e, r, i, s = 0) {
667
271
  if (!this.base) return [];
668
- const a = [], h = this.rawWidth, o = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((h + c) / u), f = i ?? Math.floor((o + c) / l);
669
- for (let m = 0; m < f; m++)
670
- for (let g = 0; g < d; g++)
671
- a.push(this.getSubTexture(g * u, m * l, t, e));
272
+ const a = [], h = this.rawWidth, o = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, f = r ?? Math.floor((h + c) / u), d = i ?? Math.floor((o + c) / l);
273
+ for (let x = 0; x < d; x++)
274
+ for (let p = 0; p < f; p++)
275
+ a.push(this.getSubTexture(p * u, x * l, t, e));
672
276
  return a;
673
277
  }
674
278
  static fromImageSource(t, e, r = {}) {
675
- const i = J(t, e, r);
279
+ const i = rt(t, e, r);
676
280
  return new N(new V(i, e.width, e.height));
677
281
  }
678
282
  destroy() {
679
283
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
680
284
  }
681
285
  }
682
- class Ct extends N {
286
+ class _t extends N {
683
287
  framebuffer;
684
288
  renderbuffer;
685
289
  gl;
686
- flipY = !0;
687
290
  clearColor;
688
291
  _allocW = 0;
689
292
  _allocH = 0;
690
293
  constructor(t, e) {
691
- super(), this.gl = t.gl, this.clearColor = e.clearColor ?? x.Black;
692
- const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = J(t, { width: r, height: i }, { ...e, onlySize: !0 });
294
+ super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
295
+ const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = rt(t, { width: r, height: i }, { ...e, onlySize: !0 });
693
296
  if (this.setBase(new V(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
694
297
  throw new Error("Failed to create Framebuffer or Renderbuffer");
695
298
  this.resize(r, i, !0);
@@ -721,20 +324,20 @@ class Ct extends N {
721
324
  if (h <= 0 || o <= 0) return new Uint8Array(0);
722
325
  if (s < 0 || a < 0 || s >= this.rawWidth || a >= this.rawHeight)
723
326
  return new Uint8Array(0);
724
- const c = Math.min(h, this.rawWidth - s), u = Math.min(o, this.rawHeight - a), l = this.rawHeight - a - u, d = this.gl, f = d.getParameter(d.FRAMEBUFFER_BINDING);
725
- d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
726
- const m = new Uint8Array(c * u * 4);
727
- return d.readPixels(s, l, c, u, d.RGBA, d.UNSIGNED_BYTE, m), d.bindFramebuffer(d.FRAMEBUFFER, f), m;
327
+ const c = Math.min(h, this.rawWidth - s), u = Math.min(o, this.rawHeight - a), l = this.gl, f = l.getParameter(l.FRAMEBUFFER_BINDING);
328
+ l.bindFramebuffer(l.FRAMEBUFFER, this.framebuffer);
329
+ const d = new Uint8Array(c * u * 4);
330
+ return l.readPixels(s, a, c, u, l.RGBA, l.UNSIGNED_BYTE, d), l.bindFramebuffer(l.FRAMEBUFFER, f), d;
728
331
  }
729
332
  GetColorAt(t, e) {
730
333
  const r = this.GetPixels(t, e, 1, 1);
731
- return r.length < 4 ? new x(0, 0, 0, 0) : new x(r[0], r[1], r[2], r[3]);
334
+ return r.length < 4 ? new m(0, 0, 0, 0) : new m(r[0], r[1], r[2], r[3]);
732
335
  }
733
336
  destroy() {
734
337
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
735
338
  }
736
339
  }
737
- const _t = {
340
+ const Lt = {
738
341
  fontFamily: "Arial",
739
342
  fontSize: 24,
740
343
  fontWeight: "normal",
@@ -752,11 +355,11 @@ class Pt extends N {
752
355
  options;
753
356
  flipY = !0;
754
357
  constructor(t, e) {
755
- super(), this.render = t, this._style = { ..._t, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
358
+ super(), this.render = t, this._style = { ...Lt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
756
359
  const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
757
360
  if (!r) throw new Error("Failed to get 2d context for TextTexture");
758
361
  this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
759
- const i = J(t, this.canvas, this.options);
362
+ const i = rt(t, this.canvas, this.options);
760
363
  this.setBase(new V(i, 1, 1)), this.update();
761
364
  }
762
365
  get text() {
@@ -787,28 +390,28 @@ class Pt extends N {
787
390
  const c = this._text.split(`
788
391
  `);
789
392
  let u = 0, l = 0;
790
- const m = t.measureText(c[0] || "M").fontBoundingBoxDescent;
393
+ const x = t.measureText(c[0] || "M").fontBoundingBoxDescent;
791
394
  for (const b of c) {
792
- const R = t.measureText(b);
793
- R.width > u && (u = R.width), l += m * a;
395
+ const M = t.measureText(b);
396
+ M.width > u && (u = M.width), l += x * a;
794
397
  }
795
- l -= m * (a - 1);
796
- const g = this._style.strokeThickness || 0, v = Math.ceil(u + g * 2) || 1, y = Math.ceil(l + g * 2) || 1, w = Math.ceil(v * o), M = Math.ceil(y * o);
797
- (this.canvas.width !== w || this.canvas.height !== M) && (this.canvas.width = w, this.canvas.height = M), t.setTransform(o, 0, 0, o, 0, 0), t.clearRect(0, 0, v, y), t.font = h, t.textBaseline = "top", t.textAlign = this._style.align;
798
- const _ = this.updateOffset(v, g), P = e.strokeThickness, O = P > 0;
799
- O && (t.lineWidth = P, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
800
- let W = g;
398
+ l -= x * (a - 1);
399
+ const p = this._style.strokeThickness || 0, v = Math.ceil(u + p * 2) || 1, y = Math.ceil(l + p * 2) || 1, E = Math.ceil(v * o), w = Math.ceil(y * o);
400
+ (this.canvas.width !== E || this.canvas.height !== w) && (this.canvas.width = E, this.canvas.height = w), t.setTransform(o, 0, 0, o, 0, 0), t.clearRect(0, 0, v, y), t.font = h, t.textBaseline = "top", t.textAlign = this._style.align;
401
+ const _ = this.updateOffset(v, p), L = e.strokeThickness, W = L > 0;
402
+ W && (t.lineWidth = L, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
403
+ let O = p;
801
404
  for (const b of c)
802
- O && t.strokeText(b, _, W), e.fill && t.fillText(b, _, W), W += m * a;
803
- this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, w, M);
405
+ W && t.strokeText(b, _, O), e.fill && t.fillText(b, _, O), O += x * a;
406
+ this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, E, w);
804
407
  }
805
408
  }
806
- const Lt = (n, t = !1, e = !0) => {
409
+ const Nt = (n, t = !1, e = !0) => {
807
410
  const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
808
411
  if (!r)
809
412
  throw new Error("WebGL2 is not supported in this browser.");
810
413
  return r;
811
- }, ct = (n, t, e) => {
414
+ }, dt = (n, t, e) => {
812
415
  const r = n.createShader(e);
813
416
  if (!r)
814
417
  throw new Error("Unable to create webgl shader");
@@ -817,8 +420,8 @@ const Lt = (n, t = !1, e = !0) => {
817
420
  throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
818
421
  }
819
422
  return r;
820
- }, Nt = (n, t, e) => {
821
- var r = n.createProgram(), i = ct(n, t, 35633), s = ct(n, e, 35632);
423
+ }, It = (n, t, e) => {
424
+ var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
822
425
  if (!r)
823
426
  throw new Error("Unable to create program shader");
824
427
  if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
@@ -827,7 +430,7 @@ const Lt = (n, t = !1, e = !0) => {
827
430
  }
828
431
  return r;
829
432
  };
830
- function st(n, t) {
433
+ function at(n, t) {
831
434
  const e = {
832
435
  [q.CLAMP]: n.CLAMP_TO_EDGE,
833
436
  [q.REPEAT]: n.REPEAT,
@@ -835,18 +438,18 @@ function st(n, t) {
835
438
  }[t] || n.CLAMP_TO_EDGE;
836
439
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
837
440
  }
838
- function nt(n, t) {
441
+ function ht(n, t) {
839
442
  const e = {
840
- [ht.LINEAR]: n.LINEAR,
841
- [ht.NEAREST]: n.NEAREST
443
+ [tt.LINEAR]: n.LINEAR,
444
+ [tt.NEAREST]: n.NEAREST
842
445
  }[t] ?? n.NEAREST;
843
446
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
844
447
  }
845
- function J(n, t, e) {
448
+ function rt(n, t, e) {
846
449
  const r = n.gl, i = r.createTexture();
847
450
  if (!i)
848
451
  throw new Error("Unable to create WebGL texture");
849
- if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), st(r, e.wrap ?? q.CLAMP), nt(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
452
+ if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), at(r, e.wrap ?? q.CLAMP), ht(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
850
453
  const s = t;
851
454
  r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
852
455
  } else {
@@ -855,24 +458,24 @@ function J(n, t, e) {
855
458
  }
856
459
  return r.bindTexture(r.TEXTURE_2D, null), i;
857
460
  }
858
- function B(n, t) {
859
- if (n.includes("%TEXTURE_NUM%") && (n = n.replace("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
860
- let e = "";
861
- for (let r = 0; r < t; r++)
862
- r == 0 ? e += `if(vTextureId == ${r})` : r == t - 1 ? e += "else" : e += `else if(vTextureId == ${r})`, e += `{return texture(uTextures[${r}], uv);}`;
863
- n = n.replace("%GET_COLOR%", e);
461
+ function D(n, t, e = "vTextureId", r = "uv", i = "return") {
462
+ if (n.includes("%TEXTURE_NUM%") && (n = n.replaceAll("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
463
+ let s = "";
464
+ for (let a = 0; a < t; a++)
465
+ a == 0 ? s += `if(${e} == ${a})` : a == t - 1 ? s += "else" : s += `else if(${e} == ${a})`, s += `{${i} texture(uTextures[${a}], ${r});}`;
466
+ n = n.replaceAll("%GET_COLOR%", s);
864
467
  }
865
468
  return n;
866
469
  }
867
- const It = 5126, at = 5121;
470
+ const Wt = 5126, ot = 5121;
868
471
  function Ot(n, t, e) {
869
472
  n.vertexAttribDivisor(t, e);
870
473
  }
871
- function yt(n, t, e, r, i) {
474
+ function Et(n, t, e, r, i) {
872
475
  n.drawArraysInstanced(t, e, r, i);
873
476
  }
874
- let Wt = 0;
875
- class Tt {
477
+ let Ft = 0;
478
+ class Rt {
876
479
  program;
877
480
  attributeLoc = {};
878
481
  uniformLoc = {};
@@ -881,11 +484,11 @@ class Tt {
881
484
  uniformType = {};
882
485
  uniformIsArray = {};
883
486
  gl;
884
- shaderId = Wt++;
487
+ shaderId = Ft++;
885
488
  // for debug
886
489
  vao;
887
490
  constructor(t, e, r, i) {
888
- this.gl = t, this.program = Nt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
491
+ this.gl = t, this.program = It(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
889
492
  }
890
493
  use() {
891
494
  this.gl.useProgram(this.program);
@@ -901,7 +504,7 @@ class Tt {
901
504
  const r = this.uniformLoc[t];
902
505
  if (r === void 0) return;
903
506
  const i = this.uniformType[t], s = this.uniformIsArray[t];
904
- Ft(this.gl, r, i, e, s);
507
+ Dt(this.gl, r, i, e, s);
905
508
  }
906
509
  setUniforms(t) {
907
510
  for (const e in t)
@@ -915,7 +518,7 @@ class Tt {
915
518
  r.vertexAttribPointer(
916
519
  e,
917
520
  t.size,
918
- t.type ?? It,
521
+ t.type ?? Wt,
919
522
  t.normalized ?? !1,
920
523
  t.stride,
921
524
  t.offset ?? 0
@@ -945,11 +548,11 @@ class Tt {
945
548
  }
946
549
  }
947
550
  }
948
- function Ft(n, t, e, r, i = !1) {
551
+ function Dt(n, t, e, r, i = !1) {
949
552
  switch (e) {
950
553
  // scalars
951
554
  case "float":
952
- return n.uniform1f(t, r);
555
+ return i ? n.uniform1fv(t, r) : n.uniform1f(t, r);
953
556
  case "int":
954
557
  case "bool":
955
558
  case "sampler2D":
@@ -979,6 +582,8 @@ function Ft(n, t, e, r, i = !1) {
979
582
  return n.uniformMatrix3fv(t, !1, r);
980
583
  case "mat4":
981
584
  return n.uniformMatrix4fv(t, !1, r);
585
+ case "mat3x2":
586
+ return n.uniformMatrix3x2fv(t, !1, r);
982
587
  // fallback: guess by value shape
983
588
  default:
984
589
  return Bt(n, t, r);
@@ -1003,27 +608,29 @@ function Bt(n, t, e) {
1003
608
  return n.uniform1fv(t, r);
1004
609
  }
1005
610
  }
1006
- class ut {
611
+ class ct {
1007
612
  vs;
1008
613
  fs;
1009
614
  glshader = /* @__PURE__ */ new Map();
1010
615
  uniforms = {};
1011
616
  uniformDirty = /* @__PURE__ */ new Set();
1012
617
  uniformTextures = {};
618
+ uniformArrayTexture = {};
1013
619
  usedTextureUnitNum = 0;
1014
620
  padding = 0;
1015
621
  rapid;
1016
- constructor(t, e, r, i = 0, s) {
622
+ prefix = [];
623
+ constructor(t, e = "", r = "", i = 0, s) {
1017
624
  this.vs = e, this.fs = r, this.rapid = t, this.uniforms = s ?? {}, this.usedTextureUnitNum = i;
1018
625
  }
1019
626
  setUniforms(t) {
1020
627
  this.rapid.flush();
1021
- const e = {}, r = {};
1022
- for (const [i, s] of Object.entries(t))
1023
- s instanceof WebGLTexture ? r[i] = s : e[i] = s;
1024
- Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, r);
1025
- for (const i of this.glshader.keys())
1026
- this.uniformDirty.add(i);
628
+ const e = {}, r = {}, i = {};
629
+ for (const [s, a] of Object.entries(t))
630
+ a instanceof WebGLTexture ? r[s] = a : Array.isArray(a) && a[0] instanceof WebGLTexture ? i[s] = a : e[s] = a;
631
+ Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, r), Object.assign(this.uniformArrayTexture, i);
632
+ for (const s of this.glshader.keys())
633
+ this.uniformDirty.add(s);
1027
634
  }
1028
635
  setPadding(t) {
1029
636
  this.padding = t;
@@ -1040,15 +647,16 @@ class ut {
1040
647
  return this.glshader.get(e);
1041
648
  if (i == null || r == null)
1042
649
  return console.warn("CustomGlShader: missing base shader for " + e), null;
1043
- r = r.replace("// CUSTOM_CODE_CALL", "vertex(position, vRegion);"), i = i.replace("// CUSTOM_CODE_CALL", "fragment(fragColor);"), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE", this.fs);
1044
- const s = t.createShader(r, i);
1045
- return s.isCustom = !0, s.padding = this.padding, this.glshader.set(e, s), this.uniformDirty.add(e), s;
650
+ const s = this.prefix.length == 0 ? [""] : this.prefix;
651
+ r = r.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "vertex(position, vRegion);").join("")), r = r.replace("// CUSTOM_CODE", this.vs), i = i.replace("// CUSTOM_CODE_CALL", s.map((h) => h + "fragment(fragColor, vRegion);").join("")), i = i.replace("// CUSTOM_CODE", this.fs);
652
+ const a = t.createShader(r, i);
653
+ return a.isCustom = !0, a.padding = this.padding, this.glshader.set(e, a), this.uniformDirty.add(e), a;
1046
654
  }
1047
655
  destroy() {
1048
656
  this.glshader.forEach((t) => t.destroy());
1049
657
  }
1050
658
  }
1051
- class Et {
659
+ class Mt {
1052
660
  constructor(t) {
1053
661
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
1054
662
  }
@@ -1069,84 +677,215 @@ class Et {
1069
677
  }
1070
678
  createDefaultShader() {
1071
679
  }
1072
- get freeTextureUnitNum() {
1073
- return this.maxTextureUnits - this.usedTextures.length - this.customShaderUsedTextureNum;
680
+ get freeTextureUnitNum() {
681
+ return this.maxTextureUnits - this.usedTextures.length - this.customShaderUsedTextureNum;
682
+ }
683
+ getTextureUnitList() {
684
+ return Array.from(
685
+ { length: this.maxTextureUnits },
686
+ (t, e) => e
687
+ );
688
+ }
689
+ findTextureUnit(t, e = 0, r = 0) {
690
+ for (let i = 0; i < this.usedTextures.length; i++) {
691
+ const s = i * 2;
692
+ if (this.usedTextures[i] === t && this.usedTexturePadding[s] === e && this.usedTexturePadding[s + 1] === r)
693
+ return i;
694
+ }
695
+ return -1;
696
+ }
697
+ useTexture(t, e = 0, r = 0) {
698
+ const i = this.findTextureUnit(t, e, r);
699
+ return i == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(r), this.usedTextures.length - 1) : i;
700
+ }
701
+ createShader(t, e) {
702
+ return new Rt(this.gl, t, e);
703
+ }
704
+ createCustomShader(t) {
705
+ return t.getGLShader(this, this.KEY, this.vs, this.fs);
706
+ }
707
+ getCustomShader(t) {
708
+ if (!t)
709
+ return this.defaultShader;
710
+ if (t instanceof ct) {
711
+ const e = this.createCustomShader(t);
712
+ return e ?? this.defaultShader;
713
+ }
714
+ return t;
715
+ }
716
+ isSameShader(t) {
717
+ return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
718
+ }
719
+ enter(t) {
720
+ this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ct ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
721
+ }
722
+ exit() {
723
+ this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
724
+ }
725
+ flush() {
726
+ this.render(), this.resetRender();
727
+ }
728
+ render() {
729
+ this.prepareRender();
730
+ }
731
+ prepareRender() {
732
+ const t = this.currentShader;
733
+ if (t.use(), this.customShader) {
734
+ const r = this.customShader, i = {};
735
+ for (const [s, a] of Object.entries(r.uniformTextures))
736
+ i[s] = this.useTexture(a);
737
+ for (const [s, a] of Object.entries(r.uniformArrayTexture))
738
+ i[s] = a.map((h) => this.useTexture(h));
739
+ this.customShader.applyUniform(this.KEY, i);
740
+ }
741
+ const e = this.gl;
742
+ for (let r = 0; r < this.usedTextures.length; r++)
743
+ e.activeTexture(e.TEXTURE0 + r), e.bindTexture(e.TEXTURE_2D, this.usedTextures[r]);
744
+ t.setUniform("uTextures", Int32Array.from(
745
+ { length: this.usedTextures.length },
746
+ (r, i) => i
747
+ )), t.setUniform("uPadding", Float32Array.from(
748
+ { length: this.usedTexturePadding.length },
749
+ (r, i) => this.usedTexturePadding[i]
750
+ ));
751
+ }
752
+ resetRender() {
753
+ const t = this.gl;
754
+ for (let e = 0; e < this.usedTextures.length; e++)
755
+ t.activeTexture(t.TEXTURE0 + e), t.bindTexture(t.TEXTURE_2D, null);
756
+ this.usedTextures.length = 0, this.usedTexturePadding.length = 0;
757
+ }
758
+ hasPendingContent() {
759
+ return !1;
760
+ }
761
+ }
762
+ var S = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(S || {});
763
+ class A {
764
+ usedElemNum;
765
+ typedArray;
766
+ arrayType;
767
+ maxElemNum;
768
+ bytePerElem;
769
+ arraybuffer;
770
+ uint32;
771
+ float32;
772
+ uint16;
773
+ constructor(t) {
774
+ this.usedElemNum = 0, this.maxElemNum = 512, this.bytePerElem = this.getArrayType(t).BYTES_PER_ELEMENT, this.arrayType = t, this.arraybuffer = new ArrayBuffer(this.maxElemNum * this.bytePerElem), this.updateTypedArray();
775
+ }
776
+ getArrayType(t) {
777
+ switch (t) {
778
+ case 0:
779
+ return Float32Array;
780
+ case 1:
781
+ return Uint32Array;
782
+ case 2:
783
+ return Uint16Array;
784
+ default:
785
+ throw new Error("Unsupported ArrayType");
786
+ }
787
+ }
788
+ updateTypedArray() {
789
+ switch (this.uint32 = new Uint32Array(this.arraybuffer), this.float32 = new Float32Array(this.arraybuffer), this.uint16 = new Uint16Array(this.arraybuffer), this.arrayType) {
790
+ case 0:
791
+ this.typedArray = this.float32;
792
+ break;
793
+ case 1:
794
+ this.typedArray = this.uint32;
795
+ break;
796
+ case 2:
797
+ this.typedArray = this.uint16;
798
+ break;
799
+ }
800
+ }
801
+ clear() {
802
+ this.usedElemNum = 0;
803
+ }
804
+ static removeAtIndices(t, e) {
805
+ const r = Math.max(...e.map((h) => h.usedElemNum)), i = [...new Set(t)].filter(
806
+ (h) => h >= 0 && h < r
807
+ ).sort((h, o) => h - o);
808
+ if (i.length === 0)
809
+ return 0;
810
+ let s = 0, a = 0;
811
+ for (let h = 0; h < r; h++) {
812
+ if (a < i.length && h === i[a]) {
813
+ a++;
814
+ continue;
815
+ }
816
+ if (s !== h)
817
+ for (const o of e)
818
+ o.typedArray[s] = o.typedArray[h];
819
+ s++;
820
+ }
821
+ for (const h of e)
822
+ h.usedElemNum = s;
823
+ return r - s;
824
+ }
825
+ resize(t = 0) {
826
+ if (t += this.usedElemNum, t > this.maxElemNum) {
827
+ for (; t > this.maxElemNum; )
828
+ this.maxElemNum *= 2;
829
+ return this.setMaxSize(this.maxElemNum), !0;
830
+ }
831
+ return !1;
1074
832
  }
1075
- getTextureUnitList() {
1076
- return Array.from(
1077
- { length: this.maxTextureUnits },
1078
- (t, e) => e
1079
- );
833
+ setMaxSize(t = this.maxElemNum) {
834
+ const e = this.typedArray;
835
+ this.maxElemNum = t, this.arraybuffer = new ArrayBuffer(t * this.bytePerElem), this.updateTypedArray(), this.typedArray.set(e);
1080
836
  }
1081
- findTextureUnit(t, e = 0, r = 0) {
1082
- for (let i = 0; i < this.usedTextures.length; i++) {
1083
- const s = i * 2;
1084
- if (this.usedTextures[i] === t && this.usedTexturePadding[s] === e && this.usedTexturePadding[s + 1] === r)
1085
- return i;
1086
- }
1087
- return -1;
837
+ pushUint32(t) {
838
+ this.resize(1), this.uint32[this.usedElemNum++] = t;
1088
839
  }
1089
- useTexture(t, e = 0, r = 0) {
1090
- const i = this.findTextureUnit(t, e, r);
1091
- return i == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(r), this.usedTextures.length - 1) : i;
840
+ pushFloat32(t) {
841
+ this.resize(1), this.float32[this.usedElemNum++] = t;
1092
842
  }
1093
- createShader(t, e) {
1094
- return new Tt(this.gl, t, e);
843
+ push(t) {
844
+ this.resize(1), this.typedArray[this.usedElemNum++] = t;
1095
845
  }
1096
- createCustomShader(t) {
1097
- return t.getGLShader(this, this.KEY, this.vs, this.fs);
846
+ pop() {
847
+ return this.typedArray[--this.usedElemNum];
1098
848
  }
1099
- getCustomShader(t) {
1100
- if (!t)
1101
- return this.defaultShader;
1102
- if (t instanceof ut) {
1103
- const e = this.createCustomShader(t);
1104
- return e ?? this.defaultShader;
1105
- }
1106
- return t;
849
+ top() {
850
+ return this.typedArray[this.usedElemNum - 1];
1107
851
  }
1108
- isSameShader(t) {
1109
- return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
852
+ get(t) {
853
+ return this.typedArray[t];
1110
854
  }
1111
- enter(t) {
1112
- this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ut ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
855
+ getArray(t = 0, e) {
856
+ return e === void 0 ? this.typedArray : this.typedArray.subarray(t, e);
1113
857
  }
1114
- exit() {
1115
- this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
858
+ get length() {
859
+ return this.usedElemNum;
1116
860
  }
1117
- flush() {
1118
- this.render(), this.resetRender();
861
+ }
862
+ class ut extends A {
863
+ buffer;
864
+ gl;
865
+ dirty = !0;
866
+ type;
867
+ webglBufferSize = 0;
868
+ usage;
869
+ constructor(t, e, r = t.ARRAY_BUFFER, i = t.DYNAMIC_DRAW) {
870
+ super(e), this.gl = t, this.buffer = t.createBuffer(), this.type = r, this.usage = i;
1119
871
  }
1120
- render() {
1121
- this.prepareRender();
872
+ makeDirty() {
873
+ this.dirty = !0;
1122
874
  }
1123
- prepareRender() {
1124
- const t = this.currentShader;
1125
- if (t.use(), this.customShader) {
1126
- const r = this.customShader, i = {};
1127
- for (const s in r.uniformTextures)
1128
- i[s] = this.useTexture(r.uniformTextures[s]);
1129
- this.customShader.applyUniform(this.KEY, i);
1130
- }
1131
- const e = this.gl;
1132
- for (let r = 0; r < this.usedTextures.length; r++)
1133
- e.activeTexture(e.TEXTURE0 + r), e.bindTexture(e.TEXTURE_2D, this.usedTextures[r]);
1134
- t.setUniform("uTextures", Int32Array.from(
1135
- { length: this.usedTextures.length },
1136
- (r, i) => i
1137
- )), t.setUniform("uPadding", Float32Array.from(
1138
- { length: this.usedTexturePadding.length },
1139
- (r, i) => this.usedTexturePadding[i]
1140
- ));
875
+ clear() {
876
+ super.clear(), this.dirty = !1;
1141
877
  }
1142
- resetRender() {
1143
- this.usedTextures.length = 0, this.usedTexturePadding.length = 0;
878
+ bindBuffer() {
879
+ this.gl.bindBuffer(this.type, this.buffer);
1144
880
  }
1145
- hasPendingContent() {
1146
- return !1;
881
+ bufferData() {
882
+ if (this.dirty) {
883
+ const t = this.gl;
884
+ this.maxElemNum > this.webglBufferSize && (t.bufferData(this.type, this.maxElemNum * this.bytePerElem, this.usage), this.webglBufferSize = this.maxElemNum), t.bufferSubData(this.type, 0, this.getArray(0, this.usedElemNum)), this.dirty = !1;
885
+ }
1147
886
  }
1148
887
  }
1149
- const Z = `#version 300 es\r
888
+ const et = `#version 300 es\r
1150
889
  precision highp float;\r
1151
890
  \r
1152
891
  // per-vertex\r
@@ -1194,7 +933,7 @@ void main(void) {\r
1194
933
  \r
1195
934
  gl_Position = u_projection * position;\r
1196
935
  }\r
1197
- `, lt = `#version 300 es\r
936
+ `, ft = `#version 300 es\r
1198
937
  precision mediump float;\r
1199
938
  \r
1200
939
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1208,43 +947,31 @@ in vec4 vUVRect;\r
1208
947
  out vec4 fragColor;\r
1209
948
  in vec2 vPadding;\r
1210
949
  \r
1211
- bool clampUV(vec2 uv) {\r
1212
- return uv.x < vUVRect.x || uv.x > vUVRect.z || uv.y < vUVRect.y || uv.y > vUVRect.w;\r
1213
- }\r
1214
- \r
1215
950
  vec4 sampleTexture(vec2 uv) {\r
1216
951
  %GET_COLOR%\r
1217
952
  }\r
1218
953
  \r
1219
954
  vec4 sampleClampTexture(vec2 uv) {\r
1220
- if (clampUV(uv)) {\r
1221
- return vec4(0.0, 0.0, 0.0, 0.0);\r
1222
- }\r
1223
- return sampleTexture(uv);\r
955
+ vec2 inMin = step(vUVRect.xy, uv);\r
956
+ vec2 inMax = step(uv, vUVRect.zw);\r
957
+ \r
958
+ float mask = inMin.x * inMin.y * inMax.x * inMax.y;\r
959
+ \r
960
+ return sampleTexture(uv) * mask;\r
1224
961
  }\r
1225
962
  \r
1226
963
  vec4 sampleTextureLocal(vec2 uv){\r
1227
- vec2 gUV = mix(vUVRect.xy, vUVRect.zw, uv);\r
1228
- if (clampUV(gUV)) {\r
1229
- return vec4(0.0, 0.0, 0.0, 0.0);\r
1230
- }\r
1231
- return sampleTexture(gUV);\r
964
+ return sampleClampTexture(mix(vUVRect.xy, vUVRect.zw, uv));\r
1232
965
  }\r
1233
- \r
1234
966
  // CUSTOM_CODE\r
1235
967
  \r
1236
968
  void main(void) {\r
1237
969
  fragColor = sampleTexture(vRegion) * vColor;\r
1238
- // if (vPadding.x != 0.0) {\r
1239
- // if (clampUV(vRegion)) {\r
1240
- // fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
1241
- // }\r
1242
- // }\r
1243
970
  \r
1244
971
  // CUSTOM_CODE_CALL\r
1245
972
  }\r
1246
- `, $ = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1247
- class ot extends Et {
973
+ `, $ = 48, kt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
974
+ class lt extends Mt {
1248
975
  instanceBuffer;
1249
976
  quadBuffer;
1250
977
  instanceCount = 0;
@@ -1252,82 +979,352 @@ class ot extends Et {
1252
979
  worldSpriteMatrix = new Float32Array(6);
1253
980
  KEY = "Sprite";
1254
981
  constructor(t) {
1255
- super(t), this.createBuffer(), this.createDefaultShader();
982
+ super(t), this.createBuffer(), this.createDefaultShader();
983
+ }
984
+ createBuffer() {
985
+ const t = this.gl;
986
+ this.quadBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
987
+ for (const e of kt) this.quadBuffer.pushFloat32(e);
988
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new ut(t, S.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
989
+ }
990
+ createDefaultShader() {
991
+ const t = this.rapid, e = D(ft, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
992
+ return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
993
+ }
994
+ createShader(t, e) {
995
+ const r = super.createShader(t, e);
996
+ return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
997
+ { name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
998
+ { name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
999
+ { name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
1000
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: $, offset: 40, divisor: 1 },
1001
+ { name: "aTextureId", size: 1, type: ot, stride: $, offset: 44, divisor: 1 }
1002
+ ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1003
+ { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1004
+ ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1005
+ }
1006
+ createCustomShader(t) {
1007
+ const e = D(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1008
+ return t.getGLShader(this, this.KEY, r, e);
1009
+ }
1010
+ drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, h = 4294967295, o = 0, c = 0, u = !1, l = !1, f = !1) {
1011
+ const d = e * 6, x = this.matrixStore.data;
1012
+ this.drawSpriteAffine(
1013
+ t,
1014
+ x[d],
1015
+ x[d + 1],
1016
+ x[d + 2],
1017
+ x[d + 3],
1018
+ x[d + 4],
1019
+ x[d + 5],
1020
+ r,
1021
+ i,
1022
+ s,
1023
+ a,
1024
+ h,
1025
+ o,
1026
+ c,
1027
+ u,
1028
+ l,
1029
+ f
1030
+ );
1031
+ }
1032
+ drawSpriteAffine(t, e, r, i, s, a, h, o = 0, c = 0, u = 1, l = 1, f = 4294967295, d = 0, x = 0, p = !1, v = !1, y = !1) {
1033
+ const E = t.base, w = t.rawWidth, _ = t.rawHeight, L = t.offsetX, W = t.offsetY, O = this.useTexture(
1034
+ t.glTexture,
1035
+ d / E.width,
1036
+ x / E.height
1037
+ ), b = this.instanceBuffer, M = b.usedElemNum;
1038
+ b.resize(12);
1039
+ const C = b.float32, B = b.uint32, k = y ? _ : w, H = y ? w : _, I = k + 2 * d, F = H + 2 * x, X = L - d, z = W - x, R = this.localSpriteMatrix;
1040
+ y ? (R[0] = 0, R[1] = v ? F : -F, R[2] = p ? -I : I, R[3] = 0, R[4] = X + (p ? I : 0), R[5] = z + (v ? 0 : F)) : (R[0] = p ? -I : I, R[1] = 0, R[2] = 0, R[3] = v ? -F : F, R[4] = X + (p ? I : 0), R[5] = z + (v ? F : 0));
1041
+ const U = this.worldSpriteMatrix;
1042
+ U[0] = e * R[0] + i * R[1], U[1] = r * R[0] + s * R[1], U[2] = e * R[2] + i * R[3], U[3] = r * R[2] + s * R[3], U[4] = a + e * R[4] + i * R[5], U[5] = h + r * R[4] + s * R[5], C[M + 6] = o, C[M + 7] = c, C[M + 8] = u, C[M + 9] = l, B[M + 10] = f, B[M + 11] = O, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), C[M] = U[0], C[M + 1] = U[2], C[M + 2] = U[4], C[M + 3] = U[1], C[M + 4] = U[3], C[M + 5] = U[5], b.usedElemNum += 12, b.makeDirty(), this.instanceCount++;
1043
+ }
1044
+ render() {
1045
+ if (this.instanceCount === 0) return;
1046
+ this.prepareRender();
1047
+ const t = this.gl, e = this.currentShader;
1048
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1049
+ }
1050
+ resetRender() {
1051
+ super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
1052
+ }
1053
+ hasPendingContent() {
1054
+ return this.instanceCount > 0;
1055
+ }
1056
+ }
1057
+ const T = 6;
1058
+ class Ht {
1059
+ matrixCount = 0;
1060
+ buffer;
1061
+ data;
1062
+ temporary = -1;
1063
+ constructor(t = 10) {
1064
+ this.buffer = new A(S.Float32), this.buffer.resize(t * T), this.data = this.buffer.getArray(), this.reset();
1065
+ }
1066
+ alloc() {
1067
+ const t = this.allocDirty();
1068
+ return this.identity(t), t;
1069
+ }
1070
+ allocDirty() {
1071
+ return this.buffer.resize(T) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += T, this.matrixCount++;
1072
+ }
1073
+ reset() {
1074
+ this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
1075
+ }
1076
+ identity(t) {
1077
+ const e = t * T, r = this.data;
1078
+ r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
1079
+ }
1080
+ translate(t, e, r) {
1081
+ const i = t * T, s = this.data;
1082
+ s[i + 4] = s[i] * e + s[i + 2] * r + s[i + 4], s[i + 5] = s[i + 1] * e + s[i + 3] * r + s[i + 5];
1083
+ }
1084
+ scale(t, e, r) {
1085
+ const i = t * T, s = this.data;
1086
+ s[i] *= e, s[i + 1] *= e, s[i + 2] *= r, s[i + 3] *= r;
1087
+ }
1088
+ rotate(t, e) {
1089
+ const r = t * T, i = this.data, s = Math.cos(e), a = Math.sin(e), h = i[r], o = i[r + 1], c = i[r + 2], u = i[r + 3];
1090
+ i[r] = h * s + c * a, i[r + 1] = o * s + u * a, i[r + 2] = h * -a + c * s, i[r + 3] = o * -a + u * s;
1091
+ }
1092
+ rotateWithOffset(t, e, r, i) {
1093
+ this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
1094
+ }
1095
+ copy(t, e) {
1096
+ const r = t * T, i = e * T, s = this.data;
1097
+ s[r] = s[i], s[r + 1] = s[i + 1], s[r + 2] = s[i + 2], s[r + 3] = s[i + 3], s[r + 4] = s[i + 4], s[r + 5] = s[i + 5];
1098
+ }
1099
+ multiply(t, e) {
1100
+ this.multiplyOut(t, t, e);
1101
+ }
1102
+ multiplyOut(t, e, r) {
1103
+ const i = t * T, s = e * T, a = r * T, h = this.data, o = h[s], c = h[s + 1], u = h[s + 2], l = h[s + 3], f = h[s + 4], d = h[s + 5], x = h[a], p = h[a + 1], v = h[a + 2], y = h[a + 3], E = h[a + 4], w = h[a + 5];
1104
+ h[i] = o * x + u * p, h[i + 1] = c * x + l * p, h[i + 2] = o * v + u * y, h[i + 3] = c * v + l * y, h[i + 4] = o * E + u * w + f, h[i + 5] = c * E + l * w + d;
1105
+ }
1106
+ invert(t) {
1107
+ const e = t * T, r = this.data, i = r[e], s = r[e + 1], a = r[e + 2], h = r[e + 3], o = r[e + 4], c = r[e + 5];
1108
+ let u = i * h - s * a;
1109
+ if (!u) {
1110
+ this.identity(t);
1111
+ return;
1112
+ }
1113
+ u = 1 / u, r[e] = h * u, r[e + 1] = -s * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * c - h * o) * u, r[e + 5] = (s * o - i * c) * u;
1114
+ }
1115
+ transformPoint(t, e, r) {
1116
+ const i = t * T, s = this.data;
1117
+ return {
1118
+ x: e * s[i] + r * s[i + 2] + s[i + 4],
1119
+ y: e * s[i + 1] + r * s[i + 3] + s[i + 5]
1120
+ };
1121
+ }
1122
+ worldToLocal(t, e, r) {
1123
+ const i = this.allocDirty();
1124
+ this.copy(i, t), this.invert(i);
1125
+ const s = this.transformPoint(i, e, r);
1126
+ return this.matrixCount--, this.buffer.usedElemNum -= T, s;
1127
+ }
1128
+ localToWorld(t, e, r) {
1129
+ return this.transformPoint(t, e, r);
1130
+ }
1131
+ getPosition(t) {
1132
+ const e = t * T, r = this.data;
1133
+ return { x: r[e + 4], y: r[e + 5] };
1134
+ }
1135
+ getScale(t) {
1136
+ const e = t * T, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), s = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
1137
+ return { x: i, y: s };
1138
+ }
1139
+ getRotation(t) {
1140
+ const e = t * T, r = this.data;
1141
+ return Math.atan2(r[e + 1], r[e]);
1142
+ }
1143
+ toCSSMatrix(t, e = 1, r = 1) {
1144
+ const i = t * T, s = this.data;
1145
+ return `matrix(${s[i] * e}, ${s[i + 1] * r}, ${s[i + 2] * e}, ${s[i + 3] * r}, ${s[i + 4] * e}, ${s[i + 5] * r})`;
1146
+ }
1147
+ getMatrix(t) {
1148
+ const e = t * T;
1149
+ return this.data.slice(e, e + T);
1150
+ }
1151
+ getMatrixRef(t) {
1152
+ const e = t * T;
1153
+ return this.data.subarray(e, e + T);
1154
+ }
1155
+ setMatrix(t, e) {
1156
+ const r = t * T, i = this.data;
1157
+ i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
1158
+ }
1159
+ multiplyAffineInPlace(t, e, r, i, s, a, h) {
1160
+ const o = t * 6, c = this.data, u = c[o], l = c[o + 1], f = c[o + 2], d = c[o + 3], x = c[o + 4], p = c[o + 5];
1161
+ c[o] = u * e + f * r, c[o + 1] = l * e + d * r, c[o + 2] = u * i + f * s, c[o + 3] = l * i + d * s, c[o + 4] = u * a + f * h + x, c[o + 5] = l * a + d * h + p;
1162
+ }
1163
+ multiplyAffine(t, e, r, i, s, a, h, o) {
1164
+ const c = t * 6, u = e * 6, l = this.data, f = l[c], d = l[c + 1], x = l[c + 2], p = l[c + 3], v = l[c + 4], y = l[c + 5];
1165
+ l[u] = f * r + x * i, l[u + 1] = d * r + p * i, l[u + 2] = f * s + x * a, l[u + 3] = d * s + p * a, l[u + 4] = f * h + x * o + v, l[u + 5] = d * h + p * o + y;
1166
+ }
1167
+ }
1168
+ class Gt {
1169
+ matrix = new Ht();
1170
+ step = 0;
1171
+ stack = new A(S.Uint32);
1172
+ stepWorldM = new A(S.Uint32);
1173
+ stepAction = new A(S.Uint32);
1174
+ stepParentM = new A(S.Uint32);
1175
+ stepClose = new A(S.Uint32);
1176
+ stepStack = new A(S.Uint32);
1177
+ curLocalM = -1;
1178
+ curWorldM = -1;
1179
+ rapid;
1180
+ constructor(t) {
1181
+ this.reset(), this.rapid = t;
1256
1182
  }
1257
- createBuffer() {
1258
- const t = this.gl;
1259
- this.quadBuffer = new it(t, S.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1260
- for (const e of Dt) this.quadBuffer.pushFloat32(e);
1261
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new it(t, S.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1183
+ save() {
1184
+ this.stack.push(this.curWorldM);
1185
+ const t = this.curWorldM;
1186
+ return this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.allocDirty(), this.stepWorldM.push(this.curWorldM), this.stepParentM.push(t), this.stepAction.push(1), this.stepClose.push(0), this.stepStack.push(this.step), this.matrix.copy(this.curWorldM, t), { world: this.curWorldM, local: this.curLocalM, step: this.step++ };
1262
1187
  }
1263
- createDefaultShader() {
1264
- const t = this.rapid, e = B(lt, t.maxTextureUnits), r = B(Z, t.maxTextureUnits);
1265
- return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1188
+ restore() {
1189
+ this.stack.length == 0 || this.stepStack.length == 0 || (this.curWorldM = this.stack.pop(), this.curLocalM = this.curWorldM - 1, this.stepParentM.push(this.stack.get(this.stack.length - 1)), this.stepWorldM.push(this.curWorldM), this.stepAction.push(0), this.stepClose.push(0), this.stepClose.typedArray[this.stepStack.pop()] = this.step, this.step++);
1266
1190
  }
1267
- createShader(t, e) {
1268
- const r = super.createShader(t, e);
1269
- return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1270
- { name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
1271
- { name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
1272
- { name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
1273
- { name: "aColor", size: 4, type: at, normalized: !0, stride: $, offset: 40, divisor: 1 },
1274
- { name: "aTextureId", size: 1, type: at, stride: $, offset: 44, divisor: 1 }
1275
- ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1276
- { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1277
- ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1191
+ restoreAll() {
1192
+ for (; this.stack.length > 0 && this.stepStack.length > 0; )
1193
+ this.restore();
1278
1194
  }
1279
- createCustomShader(t) {
1280
- const e = B(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = B(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1281
- return t.getGLShader(this, this.KEY, r, e);
1195
+ getStep(t) {
1196
+ return typeof t == "number" ? t : t.step;
1282
1197
  }
1283
- drawSprite(t, e, r = 0, i = 0, s = 1, a = 1, h = 4294967295, o = 0, c = 0, u = !1, l = !1, d = !1) {
1284
- const f = e * 6, m = this.matrixStore.data;
1285
- this.drawSpriteAffine(
1286
- t,
1287
- m[f],
1288
- m[f + 1],
1289
- m[f + 2],
1290
- m[f + 3],
1291
- m[f + 4],
1292
- m[f + 5],
1293
- r,
1294
- i,
1295
- s,
1296
- a,
1297
- h,
1298
- o,
1299
- c,
1300
- u,
1301
- l,
1302
- d
1303
- );
1198
+ walkSubtree(t, e, r = 1 / 0) {
1199
+ let i = 0, s = t;
1200
+ for (; s < this.step; ) {
1201
+ const a = this.stepAction.get(s);
1202
+ if (a === 1) {
1203
+ if (i++, i > r) {
1204
+ const h = this.stepClose.get(s);
1205
+ if (h > s) {
1206
+ s = h + 1, i--;
1207
+ continue;
1208
+ }
1209
+ }
1210
+ } else
1211
+ i--;
1212
+ if (e(s, a, i) === !1 || a === 0 && i === 0) return;
1213
+ s++;
1214
+ }
1304
1215
  }
1305
- drawSpriteAffine(t, e, r, i, s, a, h, o = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, g = !1, v = !1, y = !1) {
1306
- const w = t.base, M = t.rawWidth, _ = t.rawHeight, P = t.offsetX, O = t.offsetY, W = this.useTexture(
1307
- t.glTexture,
1308
- f / w.width,
1309
- m / w.height
1310
- ), b = this.instanceBuffer, R = b.usedElemNum;
1311
- b.resize(12);
1312
- const C = b.float32, D = b.uint32, k = y ? _ : M, H = y ? M : _, I = k + 2 * f, F = H + 2 * m, Y = P - f, z = O - m, E = this.localSpriteMatrix;
1313
- y ? (E[0] = 0, E[1] = v ? F : -F, E[2] = g ? -I : I, E[3] = 0, E[4] = Y + (g ? I : 0), E[5] = z + (v ? 0 : F)) : (E[0] = g ? -I : I, E[1] = 0, E[2] = 0, E[3] = v ? -F : F, E[4] = Y + (g ? I : 0), E[5] = z + (v ? F : 0));
1314
- const U = this.worldSpriteMatrix;
1315
- U[0] = e * E[0] + i * E[1], U[1] = r * E[0] + s * E[1], U[2] = e * E[2] + i * E[3], U[3] = r * E[2] + s * E[3], U[4] = a + e * E[4] + i * E[5], U[5] = h + r * E[4] + s * E[5], C[R + 6] = o, C[R + 7] = c, C[R + 8] = u, C[R + 9] = l, D[R + 10] = d, D[R + 11] = W, this.rapid.roundPixels && (U[4] = Math.round(U[4]), U[5] = Math.round(U[5])), C[R] = U[0], C[R + 1] = U[2], C[R + 2] = U[4], C[R + 3] = U[1], C[R + 4] = U[3], C[R + 5] = U[5], b.usedElemNum += 12, b.makeDirty(), this.instanceCount++;
1216
+ getParent(t) {
1217
+ const e = this.getStep(t);
1218
+ return this.stepParentM.get(e);
1316
1219
  }
1317
- render() {
1318
- if (this.instanceCount === 0) return;
1319
- this.prepareRender();
1320
- const t = this.gl, e = this.currentShader;
1321
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1220
+ getChildren(t) {
1221
+ const e = this.getStep(t), r = this.stepClose.get(e), i = [];
1222
+ let s = e + 1;
1223
+ for (; s < r; )
1224
+ this.stepAction.get(s) === 1 ? (i.push(s), s = this.stepClose.get(s) + 1) : s++;
1225
+ return i;
1322
1226
  }
1323
- resetRender() {
1324
- super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
1227
+ updateMatrixSubtree(t) {
1228
+ const e = this.getStep(t);
1229
+ this.walkSubtree(e, (r, i) => {
1230
+ if (i === 1) {
1231
+ const s = this.stepWorldM.get(r), a = s - 1, h = this.stepParentM.get(r);
1232
+ this.matrix.multiplyOut(s, h, a);
1233
+ }
1234
+ });
1325
1235
  }
1326
- hasPendingContent() {
1327
- return this.instanceCount > 0;
1236
+ translate(t, e) {
1237
+ this.matrix.translate(this.curLocalM, t, e), this.matrix.translate(this.curWorldM, t, e);
1238
+ }
1239
+ scale(t, e = t) {
1240
+ this.matrix.scale(this.curLocalM, t, e), this.matrix.scale(this.curWorldM, t, e);
1241
+ }
1242
+ rotate(t) {
1243
+ this.matrix.rotate(this.curLocalM, t), this.matrix.rotate(this.curWorldM, t);
1244
+ }
1245
+ rotateWithOffset(t, e, r) {
1246
+ this.matrix.rotateWithOffset(this.curLocalM, t, e, r), this.matrix.rotateWithOffset(this.curWorldM, t, e, r);
1247
+ }
1248
+ identity() {
1249
+ this.matrix.identity(this.curLocalM), this.matrix.identity(this.curWorldM);
1250
+ }
1251
+ reset() {
1252
+ this.matrix.reset(), this.stack.clear(), this.stepAction.clear(), this.stepWorldM.clear(), this.stepParentM.clear(), this.stepClose.clear(), this.stepStack.clear(), this.step = 0, this.curLocalM = this.matrix.alloc(), this.curWorldM = this.matrix.alloc();
1253
+ }
1254
+ localToWorld(t, e) {
1255
+ return this.matrix.localToWorld(this.curWorldM, t, e);
1256
+ }
1257
+ worldToLocal(t, e) {
1258
+ return this.matrix.worldToLocal(this.curWorldM, t, e);
1259
+ }
1260
+ getGlobalPosition() {
1261
+ return this.matrix.getPosition(this.curWorldM);
1262
+ }
1263
+ getGlobalScale() {
1264
+ return this.matrix.getScale(this.curWorldM);
1265
+ }
1266
+ getGlobalRotation() {
1267
+ return this.matrix.getRotation(this.curWorldM);
1268
+ }
1269
+ toCSSMatrix() {
1270
+ return this.matrix.toCSSMatrix(this.curWorldM);
1271
+ }
1272
+ getTransform() {
1273
+ const t = this.curWorldM * T;
1274
+ return this.matrix.data.slice(t, t + T);
1275
+ }
1276
+ setTransform(t) {
1277
+ const e = this.curWorldM * T, r = this.matrix.data;
1278
+ r[e] = t[0], r[e + 1] = t[1], r[e + 2] = t[2], r[e + 3] = t[3], r[e + 4] = t[4], r[e + 5] = t[5];
1279
+ }
1280
+ transformPoint(t, e) {
1281
+ return this.matrix.transformPoint(this.curLocalM, t, e);
1282
+ }
1283
+ applyTransform(t, e = 0, r = 0, i = -1) {
1284
+ let s = t.x ?? 0, a = t.y ?? 0;
1285
+ t.position && (s += t.position.x, a += t.position.y);
1286
+ let h = 1, o = 1;
1287
+ const c = t.scale;
1288
+ c && (typeof c == "number" ? (h = c, o = c) : (h = c.x, o = c.y));
1289
+ const u = t.rotation ?? 0;
1290
+ let l = t.offsetX ?? 0, f = t.offsetY ?? 0;
1291
+ t.offset && (l += t.offset.x, f += t.offset.y);
1292
+ const d = t.origin;
1293
+ d !== void 0 && (typeof d == "number" ? (l -= d * e, f -= d * r) : (l -= d.x * e, f -= d.y * r));
1294
+ const x = u ? Math.cos(u) : 1, p = u ? Math.sin(u) : 0, v = x * h, y = p * h, E = -p * o, w = x * o, _ = s + v * l + E * f, L = a + y * l + w * f;
1295
+ if (i !== -1) {
1296
+ this.matrix.multiplyAffine(
1297
+ this.curWorldM,
1298
+ i,
1299
+ v,
1300
+ y,
1301
+ E,
1302
+ w,
1303
+ _,
1304
+ L
1305
+ );
1306
+ return;
1307
+ }
1308
+ this.matrix.multiplyAffineInPlace(
1309
+ this.curLocalM,
1310
+ v,
1311
+ y,
1312
+ E,
1313
+ w,
1314
+ _,
1315
+ L
1316
+ ), this.matrix.multiplyAffineInPlace(
1317
+ this.curWorldM,
1318
+ v,
1319
+ y,
1320
+ E,
1321
+ w,
1322
+ _,
1323
+ L
1324
+ );
1328
1325
  }
1329
1326
  }
1330
- const kt = `#version 300 es\r
1327
+ const Vt = `#version 300 es\r
1331
1328
  precision highp float;\r
1332
1329
  \r
1333
1330
  in vec2 aPosition;\r
@@ -1358,7 +1355,7 @@ void main(void) {\r
1358
1355
  // CUSTOM_CODE_CALL\r
1359
1356
  gl_Position = u_projection * position;\r
1360
1357
  }\r
1361
- `, Ht = `#version 300 es\r
1358
+ `, Xt = `#version 300 es\r
1362
1359
  precision mediump float;\r
1363
1360
  \r
1364
1361
  in vec4 vColor;\r
@@ -1404,7 +1401,7 @@ void main(void) {\r
1404
1401
  fragColor = sampleTexture(vRegion) * vColor;\r
1405
1402
  // CUSTOM_CODE_CALL\r
1406
1403
  }\r
1407
- `, Gt = `#version 300 es\r
1404
+ `, Yt = `#version 300 es\r
1408
1405
  precision highp float;\r
1409
1406
  \r
1410
1407
  in vec2 aPosition;\r
@@ -1427,7 +1424,7 @@ void main(void) {\r
1427
1424
  );\r
1428
1425
  gl_Position = u_projection * position;\r
1429
1426
  }\r
1430
- `, Vt = `#version 300 es\r
1427
+ `, zt = `#version 300 es\r
1431
1428
  precision mediump float;\r
1432
1429
  \r
1433
1430
  in vec2 vRegion;\r
@@ -1448,7 +1445,7 @@ void main(void) {\r
1448
1445
  }\r
1449
1446
  }\r
1450
1447
  `, j = 20;
1451
- class Yt extends Et {
1448
+ class $t extends Mt {
1452
1449
  vertexBuffer;
1453
1450
  vertexCount = 0;
1454
1451
  matrixIndex = -1;
@@ -1461,13 +1458,13 @@ class Yt extends Et {
1461
1458
  }
1462
1459
  createBuffer() {
1463
1460
  const t = this.gl;
1464
- this.vertexBuffer = new it(t, S.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Vt);
1461
+ this.vertexBuffer = new ut(t, S.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
1465
1462
  }
1466
1463
  createDefaultShader() {
1467
- return this.vs = kt, this.fs = Ht, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1464
+ return this.vs = Vt, this.fs = Xt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
1468
1465
  }
1469
1466
  createMaskShader(t, e) {
1470
- const r = this.gl, i = new Tt(r, t, e);
1467
+ const r = this.gl, i = new Rt(r, t, e);
1471
1468
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
1472
1469
  { name: "aPosition", size: 2, type: r.FLOAT, stride: j - 4, offset: 0, divisor: 0 },
1473
1470
  { name: "aUV", size: 2, type: r.FLOAT, stride: j - 4, offset: 8, divisor: 0 }
@@ -1505,15 +1502,15 @@ class Yt extends Et {
1505
1502
  return !1;
1506
1503
  }
1507
1504
  }
1508
- class p {
1505
+ class g {
1509
1506
  x;
1510
1507
  y;
1511
- static ZERO = new p(0, 0);
1512
- static ONE = new p(1, 1);
1513
- static UP = new p(0, 1);
1514
- static DOWN = new p(0, -1);
1515
- static LEFT = new p(-1, 0);
1516
- static RIGHT = new p(1, 0);
1508
+ static ZERO = new g(0, 0);
1509
+ static ONE = new g(1, 1);
1510
+ static UP = new g(0, 1);
1511
+ static DOWN = new g(0, -1);
1512
+ static LEFT = new g(-1, 0);
1513
+ static RIGHT = new g(1, 0);
1517
1514
  constructor(t, e) {
1518
1515
  this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
1519
1516
  }
@@ -1521,16 +1518,16 @@ class p {
1521
1518
  return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
1522
1519
  }
1523
1520
  add(t) {
1524
- return new p(this.x + t.x, this.y + t.y);
1521
+ return new g(this.x + t.x, this.y + t.y);
1525
1522
  }
1526
1523
  subtract(t) {
1527
- return new p(this.x - t.x, this.y - t.y);
1524
+ return new g(this.x - t.x, this.y - t.y);
1528
1525
  }
1529
1526
  multiply(t) {
1530
- return t instanceof p ? new p(this.x * t.x, this.y * t.y) : new p(this.x * t, this.y * t);
1527
+ return t instanceof g ? new g(this.x * t.x, this.y * t.y) : new g(this.x * t, this.y * t);
1531
1528
  }
1532
1529
  divide(t) {
1533
- return t instanceof p ? new p(this.x / t.x, this.y / t.y) : new p(this.x / t, this.y / t);
1530
+ return t instanceof g ? new g(this.x / t.x, this.y / t.y) : new g(this.x / t, this.y / t);
1534
1531
  }
1535
1532
  dot(t) {
1536
1533
  return this.x * t.x + this.y * t.y;
@@ -1543,7 +1540,7 @@ class p {
1543
1540
  return Math.sqrt(e * e + r * r);
1544
1541
  }
1545
1542
  clone() {
1546
- return new p(this.x, this.y);
1543
+ return new g(this.x, this.y);
1547
1544
  }
1548
1545
  to(t) {
1549
1546
  this.x = t.x, this.y = t.y;
@@ -1559,7 +1556,7 @@ class p {
1559
1556
  return this.x = -this.x, this.y = -this.y, this;
1560
1557
  }
1561
1558
  inverted() {
1562
- return new p(this.x * -1, this.y * -1);
1559
+ return new g(this.x * -1, this.y * -1);
1563
1560
  }
1564
1561
  length() {
1565
1562
  return Math.sqrt(this.x * this.x + this.y * this.y);
@@ -1573,13 +1570,13 @@ class p {
1573
1570
  }
1574
1571
  normalized() {
1575
1572
  const t = this.length();
1576
- return new p(this.x / t || 0, this.y / t || 0);
1573
+ return new g(this.x / t || 0, this.y / t || 0);
1577
1574
  }
1578
1575
  fix(t = 1e-13) {
1579
1576
  this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
1580
1577
  }
1581
1578
  fixed(t = 1e-13) {
1582
- return new p(
1579
+ return new g(
1583
1580
  Math.abs(this.x) < t ? 0 : this.x,
1584
1581
  Math.abs(this.y) < t ? 0 : this.y
1585
1582
  );
@@ -1588,13 +1585,13 @@ class p {
1588
1585
  return Math.atan2(this.y, this.x);
1589
1586
  }
1590
1587
  abs() {
1591
- return new p(Math.abs(this.x), Math.abs(this.y));
1588
+ return new g(Math.abs(this.x), Math.abs(this.y));
1592
1589
  }
1593
1590
  floor() {
1594
- return new p(Math.floor(this.x), Math.floor(this.y));
1591
+ return new g(Math.floor(this.x), Math.floor(this.y));
1595
1592
  }
1596
1593
  ceil() {
1597
- return new p(Math.ceil(this.x), Math.ceil(this.y));
1594
+ return new g(Math.ceil(this.x), Math.ceil(this.y));
1598
1595
  }
1599
1596
  stringify() {
1600
1597
  return `Vec2(${this.x}, ${this.y})`;
@@ -1615,13 +1612,13 @@ class p {
1615
1612
  return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
1616
1613
  }
1617
1614
  static FromArray(t) {
1618
- return t.map((e) => new p(e[0], e[1]));
1615
+ return t.map((e) => new g(e[0], e[1]));
1619
1616
  }
1620
1617
  static fromAngle(t) {
1621
- return new p(Math.cos(t), Math.sin(t));
1618
+ return new g(Math.cos(t), Math.sin(t));
1622
1619
  }
1623
1620
  }
1624
- const Xt = (n, t) => {
1621
+ const jt = (n, t) => {
1625
1622
  const [e, r, i, s, a, h] = t, o = new Float32Array([
1626
1623
  e,
1627
1624
  i,
@@ -1640,8 +1637,8 @@ const Xt = (n, t) => {
1640
1637
  0,
1641
1638
  1
1642
1639
  ]);
1643
- return zt(o, n);
1644
- }, zt = (n, t) => {
1640
+ return Kt(o, n);
1641
+ }, Kt = (n, t) => {
1645
1642
  const e = new Float32Array(16);
1646
1643
  for (let r = 0; r < 4; r++)
1647
1644
  for (let i = 0; i < 4; i++) {
@@ -1652,15 +1649,15 @@ const Xt = (n, t) => {
1652
1649
  }
1653
1650
  return e;
1654
1651
  };
1655
- var $t = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))($t || {});
1656
- const rt = 10, dt = (n, t, e, r, i, s) => {
1657
- const a = [], h = [], o = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
1658
- for (let l = 0; l < rt; l++) {
1659
- const d = l / rt, f = (l + 1) / rt, m = o + d * c, g = o + f * c, v = new p(Math.cos(m) * e, Math.sin(m) * e), y = new p(Math.cos(g) * e, Math.sin(g) * e);
1660
- a.push(n), h.push(new p(i, 0.5)), a.push(n.add(v)), h.push(new p(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(y)), h.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
1652
+ var qt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(qt || {});
1653
+ const nt = 10, mt = (n, t, e, r, i, s) => {
1654
+ const a = [], h = [], o = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new g(t.y, -t.x);
1655
+ for (let l = 0; l < nt; l++) {
1656
+ const f = l / nt, d = (l + 1) / nt, x = o + f * c, p = o + d * c, v = new g(Math.cos(x) * e, Math.sin(x) * e), y = new g(Math.cos(p) * e, Math.sin(p) * e);
1657
+ a.push(n), h.push(new g(i, 0.5)), a.push(n.add(v)), h.push(new g(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(y)), h.push(new g(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
1661
1658
  }
1662
1659
  return { vertices: a, uv: h };
1663
- }, jt = (n, t = !1) => {
1660
+ }, Qt = (n, t = !1) => {
1664
1661
  const e = [];
1665
1662
  if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
1666
1663
  const r = 4, i = 1e-3, s = n.length;
@@ -1674,14 +1671,14 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1674
1671
  for (let o = 0; o < s - 1; o++)
1675
1672
  a += n[o].distanceTo(n[o + 1]);
1676
1673
  const h = (o, c, u) => {
1677
- const l = c.subtract(o).normalize(), d = c.subtract(u).normalize(), f = d.dot(l);
1678
- if (f < -1 + i)
1674
+ const l = c.subtract(o).normalize(), f = c.subtract(u).normalize(), d = f.dot(l);
1675
+ if (d < -1 + i)
1679
1676
  return { normal: l.perpendicular(), miters: 1 };
1680
1677
  {
1681
- let m = d.add(l).normalize();
1682
- l.cross(d) < 0 && (m = m.multiply(-1));
1683
- let g = 1 / Math.sqrt((1 - f) / 2);
1684
- return { normal: m, miters: Math.min(g, r) };
1678
+ let x = f.add(l).normalize();
1679
+ l.cross(f) < 0 && (x = x.multiply(-1));
1680
+ let p = 1 / Math.sqrt((1 - d) / 2);
1681
+ return { normal: x, miters: Math.min(p, r) };
1685
1682
  }
1686
1683
  };
1687
1684
  if (t)
@@ -1700,23 +1697,23 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1700
1697
  } else
1701
1698
  e.push(h(n[o - 1], n[o], n[o + 1]));
1702
1699
  return { normals: e, length: a };
1703
- }, Kt = (n) => {
1700
+ }, Zt = (n) => {
1704
1701
  const t = n.points;
1705
1702
  if (t.length < 2) return { vertices: [], uv: [] };
1706
- const { normals: e, length: r } = jt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1703
+ const { normals: e, length: r } = Qt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], h = n.roundCap || !1, o = n.textureMode || 0;
1707
1704
  let c = 0;
1708
1705
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
1709
- for (let d = 0; d < l; d++) {
1710
- const f = t[d], m = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, y = t[v], w = e[v].normal, M = e[v].miters, _ = f.add(m.multiply(g * i)), P = f.subtract(m.multiply(g * i)), O = y.add(w.multiply(M * i)), W = y.subtract(w.multiply(M * i)), b = f.distanceTo(y);
1711
- let R = 0, C = 0;
1712
- o === 0 ? (R = c / r, C = (c + b) / r) : (R = c / u, C = R + b / u);
1713
- const D = new p(R, 0), k = new p(R, 1), H = new p(C, 0), I = new p(C, 1);
1714
- s.push(_), a.push(D), s.push(P), a.push(k), s.push(O), a.push(H), s.push(O), a.push(H), s.push(W), a.push(I), s.push(P), a.push(k), c += b;
1706
+ for (let f = 0; f < l; f++) {
1707
+ const d = t[f], x = e[f].normal, p = e[f].miters, v = (f + 1) % t.length, y = t[v], E = e[v].normal, w = e[v].miters, _ = d.add(x.multiply(p * i)), L = d.subtract(x.multiply(p * i)), W = y.add(E.multiply(w * i)), O = y.subtract(E.multiply(w * i)), b = d.distanceTo(y);
1708
+ let M = 0, C = 0;
1709
+ o === 0 ? (M = c / r, C = (c + b) / r) : (M = c / u, C = M + b / u);
1710
+ const B = new g(M, 0), k = new g(M, 1), H = new g(C, 0), I = new g(C, 1);
1711
+ s.push(_), a.push(B), s.push(L), a.push(k), s.push(W), a.push(H), s.push(W), a.push(H), s.push(O), a.push(I), s.push(L), a.push(k), c += b;
1715
1712
  }
1716
1713
  if (h && !n.closed) {
1717
- const d = t[0], f = e[0].normal, m = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = dt(d, f, i, !0, 0, m);
1718
- s.push(...g.vertices), a.push(...g.uv);
1719
- const v = t[t.length - 1], y = e[t.length - 1].normal, w = o === 0 ? 1 : c / u, M = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, _ = dt(v, y, i, !1, w, M);
1714
+ const f = t[0], d = e[0].normal, x = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, p = mt(f, d, i, !0, 0, x);
1715
+ s.push(...p.vertices), a.push(...p.uv);
1716
+ const v = t[t.length - 1], y = e[t.length - 1].normal, E = o === 0 ? 1 : c / u, w = o === 0 ? r > 0 ? 1 / r : 0 : 1 / u, _ = mt(v, y, i, !1, E, w);
1720
1717
  s.push(..._.vertices), a.push(..._.uv);
1721
1718
  }
1722
1719
  return { vertices: s, uv: a };
@@ -1739,7 +1736,7 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1739
1736
  i
1740
1737
  ), i;
1741
1738
  }
1742
- }, qt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Qt = 2, Zt = (n, t) => {
1739
+ }, Jt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, te = 2, ee = (n, t) => {
1743
1740
  const e = Q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
1744
1741
  if (!r?.base || n.inCreateMask)
1745
1742
  return;
@@ -1748,8 +1745,8 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1748
1745
  let s = r.uvX, a = r.uvY, h = r.uvW, o = r.uvH;
1749
1746
  const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
1750
1747
  let l = t.padding ?? i.currentShader.padding;
1751
- r.isAtlas && (l += Qt);
1752
- const d = s <= h ? l : -l, f = a <= o ? l : -l;
1748
+ r.isAtlas && (l += te);
1749
+ const f = s <= h ? l : -l, d = a <= o ? l : -l;
1753
1750
  i.drawSprite(
1754
1751
  r,
1755
1752
  e ?? t.customMatrix ?? n.matrixStack.curWorldM,
@@ -1758,13 +1755,13 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1758
1755
  h,
1759
1756
  o,
1760
1757
  n.getColorUint32(t.color),
1761
- d,
1762
1758
  f,
1759
+ d,
1763
1760
  c,
1764
1761
  u,
1765
1762
  r.isRotated
1766
1763
  );
1767
- }, Jt = (n, t) => {
1764
+ }, re = (n, t) => {
1768
1765
  const e = n.particleRegion;
1769
1766
  n.enterRegion(e, t.shader);
1770
1767
  const r = t.texture, i = t.count ?? t.x.length, s = t.color;
@@ -1790,7 +1787,7 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1790
1787
  t.reverseOrder,
1791
1788
  t.customMatrix
1792
1789
  );
1793
- }, Rt = (n, t) => {
1790
+ }, wt = (n, t) => {
1794
1791
  if (t.points.length === 0) return;
1795
1792
  const e = Q(n, t, 0, 0);
1796
1793
  n.startGraphic(
@@ -1810,17 +1807,17 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1810
1807
  );
1811
1808
  }
1812
1809
  n.endGraphic();
1813
- }, te = (n, t) => {
1810
+ }, ie = (n, t) => {
1814
1811
  if (n.inCreateMask)
1815
1812
  return;
1816
- const { vertices: e, uv: r } = Kt(t);
1817
- Rt(n, {
1813
+ const { vertices: e, uv: r } = Zt(t);
1814
+ wt(n, {
1818
1815
  ...t,
1819
1816
  points: e,
1820
1817
  uv: r,
1821
1818
  drawMode: n.gl.TRIANGLES
1822
1819
  });
1823
- }, ee = (n, t) => {
1820
+ }, se = (n, t) => {
1824
1821
  const e = Q(
1825
1822
  n,
1826
1823
  t,
@@ -1832,7 +1829,7 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1832
1829
  t.texture,
1833
1830
  e ?? t.customMatrix
1834
1831
  ), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
1835
- }, re = (n, t) => {
1832
+ }, ne = (n, t) => {
1836
1833
  const e = Q(n, t, t.width, t.height);
1837
1834
  n.startGraphic(
1838
1835
  n.gl.TRIANGLE_FAN,
@@ -1840,7 +1837,7 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1840
1837
  t.shader,
1841
1838
  e ?? t.customMatrix
1842
1839
  ), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
1843
- }, ie = (n, t) => {
1840
+ }, ae = (n, t) => {
1844
1841
  const e = t.segments ?? 32, r = Q(n, t, 0, 0);
1845
1842
  n.startGraphic(
1846
1843
  n.gl.TRIANGLE_FAN,
@@ -1850,7 +1847,7 @@ const rt = 10, dt = (n, t, e, r, i, s) => {
1850
1847
  );
1851
1848
  const i = n.getColorUint32(t.color);
1852
1849
  n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
1853
- }, ft = `#version 300 es\r
1850
+ }, xt = `#version 300 es\r
1854
1851
  precision mediump float;\r
1855
1852
  \r
1856
1853
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1864,27 +1861,21 @@ in vec4 vUVRect;\r
1864
1861
  out vec4 fragColor;\r
1865
1862
  in vec2 vPadding;\r
1866
1863
  \r
1867
- bool clampUV(vec2 uv) {\r
1868
- return uv.x < vUVRect.x || uv.x > vUVRect.z || uv.y < vUVRect.y || uv.y > vUVRect.w;\r
1869
- }\r
1870
- \r
1871
1864
  vec4 sampleTexture(vec2 uv) {\r
1872
1865
  %GET_COLOR%\r
1873
1866
  }\r
1874
1867
  \r
1875
1868
  vec4 sampleClampTexture(vec2 uv) {\r
1876
- if (clampUV(uv)) {\r
1877
- return vec4(0.0, 0.0, 0.0, 0.0);\r
1878
- }\r
1879
- return sampleTexture(uv);\r
1869
+ vec2 inMin = step(vUVRect.xy, uv);\r
1870
+ vec2 inMax = step(uv, vUVRect.zw);\r
1871
+ \r
1872
+ float mask = inMin.x * inMin.y * inMax.x * inMax.y;\r
1873
+ \r
1874
+ return sampleTexture(uv) * mask;\r
1880
1875
  }\r
1881
1876
  \r
1882
1877
  vec4 sampleTextureLocal(vec2 uv){\r
1883
- vec2 gUV = mix(vUVRect.xy, vUVRect.zw, uv);\r
1884
- if (clampUV(gUV)) {\r
1885
- return vec4(0.0, 0.0, 0.0, 0.0);\r
1886
- }\r
1887
- return sampleTexture(gUV);\r
1878
+ return sampleClampTexture(mix(vUVRect.xy, vUVRect.zw, uv));\r
1888
1879
  }\r
1889
1880
  \r
1890
1881
  // CUSTOM_CODE\r
@@ -1900,21 +1891,21 @@ void main(void) {\r
1900
1891
  // CUSTOM_CODE_CALL\r
1901
1892
  }\r
1902
1893
  `;
1903
- class se extends ot {
1894
+ class he extends lt {
1904
1895
  KEY = "AtlasSprite";
1905
1896
  constructor(t) {
1906
1897
  super(t);
1907
1898
  }
1908
1899
  createCustomShader(t) {
1909
- const e = B(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = B(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1900
+ const e = D(xt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = D(et, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1910
1901
  return t.getGLShader(this, this.KEY, r, e);
1911
1902
  }
1912
1903
  createDefaultShader() {
1913
- const t = this.rapid, e = B(ft, t.maxTextureUnits), r = B(Z, t.maxTextureUnits);
1904
+ const t = this.rapid, e = D(xt, t.maxTextureUnits), r = D(et, t.maxTextureUnits);
1914
1905
  return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1915
1906
  }
1916
1907
  }
1917
- const mt = `#version 300 es\r
1908
+ const gt = `#version 300 es\r
1918
1909
  precision highp float;\r
1919
1910
  \r
1920
1911
  // per-vertex\r
@@ -1926,7 +1917,7 @@ in vec2 aScale;\r
1926
1917
  in float aRotation;\r
1927
1918
  in vec2 aOrigin;\r
1928
1919
  \r
1929
- // per-instance:UV 区域 (u0, v0, u1, v1)\r
1920
+ // per-instance:UV\r
1930
1921
  in vec4 aUVRect;\r
1931
1922
  \r
1932
1923
  // per-instance:tint color\r
@@ -1940,7 +1931,6 @@ out vec4 vColor;\r
1940
1931
  void main(void) {\r
1941
1932
  vColor = aColor;\r
1942
1933
  \r
1943
- //vRegion = mix(aUVRect.xy, aUVRect.zw, vertex.xy);\r
1944
1934
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
1945
1935
  // CUSTOM_CODE_CALL\r
1946
1936
  \r
@@ -1948,14 +1938,14 @@ void main(void) {\r
1948
1938
  float c = cos(aRotation);\r
1949
1939
  float s = sin(aRotation);\r
1950
1940
  \r
1951
- vec2 v = vec2(\r
1941
+ vec2 position = vec2(\r
1952
1942
  scaled.x * c - scaled.y * s,\r
1953
1943
  scaled.x * s + scaled.y * c\r
1954
1944
  ) + aPosition;\r
1955
1945
  \r
1956
- gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
1946
+ gl_Position = u_projection * vec4(position, 0.0, 1.0);\r
1957
1947
  }\r
1958
- `, xt = `#version 300 es\r
1948
+ `, pt = `#version 300 es\r
1959
1949
  precision mediump float;\r
1960
1950
  \r
1961
1951
  uniform sampler2D uTexture;\r
@@ -1971,8 +1961,8 @@ void main(void) {\r
1971
1961
  \r
1972
1962
  // CUSTOM_CODE_CALL\r
1973
1963
  }\r
1974
- `, G = 48, ne = G / 4;
1975
- class ae extends ot {
1964
+ `, G = 48, oe = G / 4;
1965
+ class ce extends lt {
1976
1966
  KEY = "ParticleSprite";
1977
1967
  texture;
1978
1968
  customMatrix;
@@ -1981,10 +1971,10 @@ class ae extends ot {
1981
1971
  super(t);
1982
1972
  }
1983
1973
  createCustomShader(t) {
1984
- return t.getGLShader(this, this.KEY, mt, xt);
1974
+ return t.getGLShader(this, this.KEY, gt, pt);
1985
1975
  }
1986
1976
  createDefaultShader() {
1987
- const t = xt, e = mt;
1977
+ const t = pt, e = gt;
1988
1978
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
1989
1979
  }
1990
1980
  enter(t) {
@@ -1997,38 +1987,38 @@ class ae extends ot {
1997
1987
  { name: "aScale", size: 2, stride: G, offset: 8, divisor: 1 },
1998
1988
  { name: "aRotation", size: 1, stride: G, offset: 16, divisor: 1 },
1999
1989
  { name: "aUVRect", size: 4, stride: G, offset: 20, divisor: 1 },
2000
- { name: "aColor", size: 4, type: at, normalized: !0, stride: G, offset: 36, divisor: 1 },
1990
+ { name: "aColor", size: 4, type: ot, normalized: !0, stride: G, offset: 36, divisor: 1 },
2001
1991
  { name: "aOrigin", size: 2, stride: G, offset: 40, divisor: 1 }
2002
1992
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
2003
1993
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2004
1994
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2005
1995
  }
2006
- drawParticles(t, e, r, i = 0, s = 4294967295, a, h = 1, o = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, g = !1, v = 0.5, y = 0.5, w, M = !1, _) {
1996
+ drawParticles(t, e, r, i = 0, s = 4294967295, a, h = 1, o = 1, c = 0, u = 0, l = 1, f = 1, d = !1, x = !1, p = !1, v = 0.5, y = 0.5, E, w = !1, _) {
2007
1997
  if (!t.glTexture || a <= 0) return;
2008
1998
  this.texture && t !== this.texture && this.flush();
2009
- const P = typeof h == "number", O = typeof o == "number", W = typeof i == "number", b = typeof s == "number", R = typeof c == "number", C = !b && typeof s[0] == "number", D = t.uvW - t.uvX, k = t.uvH - t.uvY, H = D === 0 ? 0 : 1 / D, I = k === 0 ? 0 : 1 / k;
2010
- let F = t.rawWidth * (f ? -1 : 1);
2011
- P && (F *= h);
2012
- let Y = t.rawHeight * (m ? -1 : 1);
2013
- O && (Y *= o), R && (F *= (l - c) * H, Y *= (d - u) * I);
2014
- let z = g ? Math.PI / 2 : 0;
2015
- W && (z += i);
2016
- const E = s ?? 4294967295, U = this.getParticleLoop(
2017
- P,
2018
- O,
1999
+ const L = typeof h == "number", W = typeof o == "number", O = typeof i == "number", b = typeof s == "number", M = typeof c == "number", C = !b && typeof s[0] == "number", B = t.uvW - t.uvX, k = t.uvH - t.uvY, H = B === 0 ? 0 : 1 / B, I = k === 0 ? 0 : 1 / k;
2000
+ let F = t.rawWidth * (d ? -1 : 1);
2001
+ L && (F *= h);
2002
+ let X = t.rawHeight * (x ? -1 : 1);
2003
+ W && (X *= o), M && (F *= (l - c) * H, X *= (f - u) * I);
2004
+ let z = p ? Math.PI / 2 : 0;
2005
+ O && (z += i);
2006
+ const R = s ?? 4294967295, U = this.getParticleLoop(
2007
+ L,
2019
2008
  W,
2020
- R,
2009
+ O,
2010
+ M,
2021
2011
  b,
2022
2012
  C,
2023
- M,
2024
- w
2013
+ w,
2014
+ E
2025
2015
  );
2026
2016
  this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2027
- const tt = a, X = this.instanceBuffer;
2028
- let et = X.usedElemNum;
2029
- X.resize(tt * ne);
2030
- const Mt = X.float32, St = X.uint32;
2031
- et = U(
2017
+ const it = a, Y = this.instanceBuffer;
2018
+ let st = Y.usedElemNum;
2019
+ Y.resize(it * oe);
2020
+ const bt = Y.float32, Ut = Y.uint32;
2021
+ st = U(
2032
2022
  e,
2033
2023
  r,
2034
2024
  h,
@@ -2037,22 +2027,22 @@ class ae extends ot {
2037
2027
  c,
2038
2028
  u,
2039
2029
  l,
2040
- d,
2030
+ f,
2041
2031
  s,
2042
- Mt,
2043
- St,
2032
+ bt,
2033
+ Ut,
2044
2034
  F,
2045
- Y,
2035
+ X,
2046
2036
  H,
2047
2037
  I,
2048
2038
  z,
2049
- E,
2039
+ R,
2050
2040
  v,
2051
2041
  y,
2052
2042
  a,
2053
- tt,
2054
- et
2055
- ), X.usedElemNum = et, X.makeDirty(), this.instanceCount += tt, this.customMatrix = _, this.flush();
2043
+ it,
2044
+ st
2045
+ ), Y.usedElemNum = st, Y.makeDirty(), this.instanceCount += it, this.customMatrix = _, this.flush();
2056
2046
  }
2057
2047
  getParticleLoop(t, e, r, i, s, a, h, o) {
2058
2048
  const c = [...arguments].join("_");
@@ -2108,25 +2098,25 @@ return idx;
2108
2098
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2109
2099
  const e = this.currentShader;
2110
2100
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2111
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = Xt(this.rapid.projection, s);
2112
- this.currentShader.setUniform("u_projection", a), yt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2101
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
2102
+ this.currentShader.setUniform("u_projection", a), Et(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2113
2103
  }
2114
2104
  }
2115
- var he = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(he || {}), oe = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(oe || {}), ht = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(ht || {}), ce = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(ce || {});
2116
- class de {
2105
+ var St = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(St || {}), ue = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ue || {}), le = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(le || {});
2106
+ class pe {
2117
2107
  gl;
2118
2108
  canvas;
2119
2109
  projection = new Float32Array(16);
2120
2110
  projectionDirty = !0;
2121
2111
  dpr;
2122
- backgroundColor = x.Black;
2112
+ backgroundColor = m.Black;
2123
2113
  logicWidth = 0;
2124
2114
  logicHeight = 0;
2125
2115
  physicsWidth = 0;
2126
2116
  physicsHeight = 0;
2127
2117
  currentRegion = null;
2128
2118
  maxTextureUnits = 0;
2129
- matrixStack = new bt(this);
2119
+ matrixStack = new Gt(this);
2130
2120
  matrix;
2131
2121
  spriteRegion;
2132
2122
  graphicRegion;
@@ -2149,38 +2139,38 @@ class de {
2149
2139
  return this.logicWidth;
2150
2140
  }
2151
2141
  constructor(t) {
2152
- this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? 1, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
2153
- const e = Lt(this.canvas, this.antialias, this.premultipliedAlpha);
2154
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new ot(this), this.graphicRegion = new Yt(this), this.atlasSpriteRegion = new se(this), this.particleRegion = new ae(this);
2142
+ this.canvas = t.canvas, this.dpr = window.devicePixelRatio || 1, this.antialias = t.antialias ?? !1, this.textureFilter = t.textureFilter ?? tt.NEAREST, this.premultipliedAlpha = t.premultipliedAlpha ?? !0, this.roundPixels = t.roundPixels ?? !1, this.scaleMode = t.scaleMode ?? 0;
2143
+ const e = Nt(this.canvas, this.antialias, this.premultipliedAlpha);
2144
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new lt(this), this.graphicRegion = new $t(this), this.atlasSpriteRegion = new he(this), this.particleRegion = new ce(this);
2155
2145
  const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2156
- this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new Ut(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
2146
+ this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new Ct(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
2157
2147
  }
2158
2148
  setTextureFilter(t) {
2159
2149
  this.textureFilter = t;
2160
2150
  }
2161
2151
  getColorUint32(t) {
2162
- return qt(this.premultipliedAlpha, t);
2152
+ return Jt(this.premultipliedAlpha, t);
2163
2153
  }
2164
2154
  enterRegion(t, e) {
2165
2155
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2166
2156
  }
2167
2157
  drawParticles(t) {
2168
- Jt(this, t);
2158
+ re(this, t);
2169
2159
  }
2170
2160
  drawSprite(t) {
2171
- Zt(this, t);
2161
+ ee(this, t);
2172
2162
  }
2173
2163
  drawLine(t) {
2174
- te(this, t);
2164
+ ie(this, t);
2175
2165
  }
2176
2166
  drawGraphic(t) {
2177
- Rt(this, t);
2167
+ wt(this, t);
2178
2168
  }
2179
2169
  drawRect(t) {
2180
- re(this, t);
2170
+ ne(this, t);
2181
2171
  }
2182
2172
  drawCircle(t) {
2183
- ie(this, t);
2173
+ ae(this, t);
2184
2174
  }
2185
2175
  startGraphic(t = this.gl.TRIANGLES, e, r, i) {
2186
2176
  this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
@@ -2189,7 +2179,7 @@ class de {
2189
2179
  this.startGraphic(t, e, this.graphicRegion.maskShader, r);
2190
2180
  }
2191
2181
  drawMaskImage(t) {
2192
- ee(this, t);
2182
+ se(this, t);
2193
2183
  }
2194
2184
  addRectVertex(t, e, r) {
2195
2185
  const i = this.getColorUint32(r);
@@ -2202,7 +2192,7 @@ class de {
2202
2192
  this.addGraphicVertex(o, c, u, l, s);
2203
2193
  }
2204
2194
  }
2205
- addGraphicVertex(t, e, r = 0, i = 0, s) {
2195
+ addGraphicVertex(t, e, r = 0, i = 0, s = 4294967295) {
2206
2196
  this.graphicRegion.addVertex(t, e, r, i, typeof s == "number" ? s : this.getColorUint32(s));
2207
2197
  }
2208
2198
  endGraphic() {
@@ -2258,9 +2248,9 @@ class de {
2258
2248
  return this.matrixStack.restore(), h.offsetX = -i, h.offsetY = -i, h;
2259
2249
  }
2260
2250
  enterRenderTexture(t) {
2261
- this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
2251
+ this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, 0, t.rawHeight);
2262
2252
  }
2263
- clearRenderTexture(t = new x(0, 0, 0, 0)) {
2253
+ clearRenderTexture(t = new m(0, 0, 0, 0)) {
2264
2254
  this.flush();
2265
2255
  const e = this.gl;
2266
2256
  t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
@@ -2268,7 +2258,7 @@ class de {
2268
2258
  leaveRenderTexture() {
2269
2259
  this.flush(), this.gl.bindFramebuffer(this.gl.FRAMEBUFFER, null), this.gl.viewport(0, 0, this.physicsWidth, this.physicsHeight), this.updateProjection(0, this.logicWidth, this.logicHeight, 0);
2270
2260
  }
2271
- drawToRenderTexture(t, e, r = new x(0, 0, 0, 0)) {
2261
+ drawToRenderTexture(t, e, r = new m(0, 0, 0, 0)) {
2272
2262
  this.enterRenderTexture(t);
2273
2263
  try {
2274
2264
  r !== null && this.clearRenderTexture(r), e();
@@ -2377,13 +2367,13 @@ class de {
2377
2367
  this.matrix.invert(e);
2378
2368
  }
2379
2369
  logicToPhysics(t) {
2380
- return t.multiply(new p(
2370
+ return t.multiply(new g(
2381
2371
  this.physicsWidth / this.logicWidth,
2382
2372
  this.physicsHeight / this.logicHeight
2383
2373
  ));
2384
2374
  }
2385
2375
  physicsToLogic(t) {
2386
- return t.multiply(new p(
2376
+ return t.multiply(new g(
2387
2377
  this.logicWidth / this.physicsWidth,
2388
2378
  this.logicHeight / this.physicsHeight
2389
2379
  ));
@@ -2403,10 +2393,10 @@ class de {
2403
2393
  return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
2404
2394
  }
2405
2395
  }
2406
- function ue(n) {
2407
- return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof x);
2396
+ function de(n) {
2397
+ return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof g || n instanceof m);
2408
2398
  }
2409
- class L {
2399
+ class P {
2410
2400
  static float(t, e) {
2411
2401
  return Math.random() * (e - t) + t;
2412
2402
  }
@@ -2417,18 +2407,18 @@ class L {
2417
2407
  return Math.random() * Math.PI * 2;
2418
2408
  }
2419
2409
  static vector(t, e, r, i) {
2420
- return new p(L.float(t, e), L.float(r, i));
2410
+ return new g(P.float(t, e), P.float(r, i));
2421
2411
  }
2422
2412
  static randomColor(t, e) {
2423
- return new x(
2424
- L.float(t.r, e.r),
2425
- L.float(t.g, e.g),
2426
- L.float(t.b, e.b),
2427
- L.float(t.a, e.a)
2413
+ return new m(
2414
+ P.float(t.r, e.r),
2415
+ P.float(t.g, e.g),
2416
+ P.float(t.b, e.b),
2417
+ P.float(t.a, e.a)
2428
2418
  );
2429
2419
  }
2430
2420
  static pick(t) {
2431
- return t[L.int(0, t.length - 1)];
2421
+ return t[P.int(0, t.length - 1)];
2432
2422
  }
2433
2423
  static pickWeight(t) {
2434
2424
  if (!t || t.length === 0) return null;
@@ -2444,17 +2434,18 @@ class L {
2444
2434
  if (Array.isArray(t)) {
2445
2435
  const [r, i] = t;
2446
2436
  if (typeof r == "number")
2447
- return L.float(r, i);
2448
- if (r instanceof p)
2449
- return L.vector(r.x, i.x, r.y, i.y);
2450
- if (r instanceof x)
2451
- return L.randomColor(r, i);
2437
+ return P.float(r, i);
2438
+ if (r instanceof g)
2439
+ return P.vector(r.x, i.x, r.y, i.y);
2440
+ if (r instanceof m)
2441
+ return P.randomColor(r, i);
2452
2442
  }
2453
2443
  return typeof t == "number" ? t : t.clone();
2454
2444
  }
2455
2445
  }
2456
- var le = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(le || {});
2457
- const pt = 10, gt = 0, vt = !0;
2446
+ const Z = (n, t) => (Array.isArray(n) ? n : [n]).slice(0, t);
2447
+ var fe = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(fe || {});
2448
+ const vt = 10, yt = 0, Tt = !0;
2458
2449
  class K {
2459
2450
  components;
2460
2451
  constructor(t = 1) {
@@ -2480,7 +2471,7 @@ class K {
2480
2471
  getComponent(t, e) {
2481
2472
  if (typeof t == "number")
2482
2473
  return t;
2483
- if (t instanceof p)
2474
+ if (t instanceof g)
2484
2475
  return e === 0 ? t.x : t.y;
2485
2476
  switch (e) {
2486
2477
  case 0:
@@ -2496,29 +2487,29 @@ class K {
2496
2487
  }
2497
2488
  }
2498
2489
  resolveComponent(t, e, r) {
2499
- return t === void 0 ? r : Array.isArray(t) ? L.float(
2490
+ return t === void 0 ? r : Array.isArray(t) ? P.float(
2500
2491
  this.getComponent(t[0], e),
2501
2492
  this.getComponent(t[1], e)
2502
2493
  ) : this.getComponent(t, e);
2503
2494
  }
2504
2495
  create(t, e, r = 1) {
2505
- const i = ue(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
2496
+ const i = de(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
2506
2497
  let h = 0;
2507
2498
  for (let o = 0; o < this.components.length; o++) {
2508
- const { value: c, delta: u, damping: l } = this.components[o], d = this.getComponent(e, o), f = s === void 0 ? this.resolveComponent(i?.start, o, d) : this.getComponent(s, o), m = i?.end === void 0 ? f : this.resolveComponent(i.end, o, d);
2509
- c.push(f), u.push(i?.delta === void 0 ? (m - f) / a : this.getComponent(i.delta, o)), l.push(i?.damping ?? 1), o === 0 && (h = f);
2499
+ const { value: c, delta: u, damping: l } = this.components[o], f = this.getComponent(e, o), d = s === void 0 ? this.resolveComponent(i?.start, o, f) : this.getComponent(s, o), x = i?.end === void 0 ? d : this.resolveComponent(i.end, o, f);
2500
+ c.push(d), u.push(i?.delta === void 0 ? (x - d) / a : this.getComponent(i.delta, o)), l.push(i?.damping ?? 1), o === 0 && (h = d);
2510
2501
  }
2511
2502
  return h;
2512
2503
  }
2513
2504
  }
2514
- class wt {
2505
+ class At {
2515
2506
  options;
2516
2507
  emitting = !1;
2517
2508
  emitTimer = 0;
2518
- emitRate = pt;
2519
- emitTime = gt;
2509
+ emitRate = vt;
2510
+ emitTime = yt;
2520
2511
  emitTimeCounter = 0;
2521
- localSpace = vt;
2512
+ localSpace = Tt;
2522
2513
  rapid;
2523
2514
  x = new A(S.Float32);
2524
2515
  y = new A(S.Float32);
@@ -2536,7 +2527,7 @@ class wt {
2536
2527
  };
2537
2528
  count = 0;
2538
2529
  constructor(t, e) {
2539
- this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? pt, this.emitTime = e.emitTime ?? gt, this.localSpace = e.localSpace ?? vt;
2530
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? vt, this.emitTime = e.emitTime ?? yt, this.localSpace = e.localSpace ?? Tt;
2540
2531
  }
2541
2532
  getAllArrayBuffer() {
2542
2533
  return [
@@ -2554,7 +2545,7 @@ class wt {
2554
2545
  this.options.texture = t;
2555
2546
  }
2556
2547
  clone() {
2557
- return new wt(this.rapid, { ...this.options });
2548
+ return new At(this.rapid, { ...this.options });
2558
2549
  }
2559
2550
  setEmitRate(t) {
2560
2551
  this.emitRate = t;
@@ -2579,7 +2570,7 @@ class wt {
2579
2570
  this.createParticle();
2580
2571
  }
2581
2572
  createParticle() {
2582
- const t = L.scalarOrRange(this.options.life, 1);
2573
+ const t = P.scalarOrRange(this.options.life, 1);
2583
2574
  this.remainingLife.push(t);
2584
2575
  let e = 0, r = 0;
2585
2576
  switch (this.options.emitShape) {
@@ -2601,7 +2592,7 @@ class wt {
2601
2592
  this.x.push(c), this.y.push(u);
2602
2593
  }
2603
2594
  const s = this.options.animation, a = this.animations, h = a.scale.create(s.scale, 1, t), o = a.rotation.create(s.rotation, 0, t);
2604
- a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, p.ZERO, t), a.color.create(s.color, x.White, t), this.rotation.push(o), this.scaleX.push(h), this.scaleY.push(h), this.color.pushUint32(x.packColor(
2595
+ a.speed.create(s.speed, 0, t), a.velocity.create(s.velocity, g.ZERO, t), a.color.create(s.color, m.White, t), this.rotation.push(o), this.scaleX.push(h), this.scaleY.push(h), this.color.pushUint32(m.packColor(
2605
2596
  a.color.get(this.count, 0),
2606
2597
  a.color.get(this.count, 1),
2607
2598
  a.color.get(this.count, 2),
@@ -2633,7 +2624,7 @@ class wt {
2633
2624
  continue;
2634
2625
  }
2635
2626
  const s = r.rotation.get(i), a = r.scale.get(i), h = r.speed.get(i);
2636
- this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = x.packColor(
2627
+ this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = m.packColor(
2637
2628
  r.color.get(i, 0),
2638
2629
  r.color.get(i, 1),
2639
2630
  r.color.get(i, 2),
@@ -2668,43 +2659,151 @@ class wt {
2668
2659
  this.emit(this.emitRate);
2669
2660
  }
2670
2661
  }
2662
+ const me = `
2663
+ uniform mediump int uLightTextureId[%TEXTURE_NUM%];
2664
+
2665
+ uniform sampler2D uNormalMap;
2666
+ uniform vec2 uResolution;
2667
+ uniform vec2 uLogicalResolution;
2668
+ uniform mediump int uLightCount;
2669
+ uniform vec4 uLightColor[%TEXTURE_NUM%];
2670
+ uniform mat3x2 uLightMatrix[%TEXTURE_NUM%];
2671
+ uniform float uLightHeight[%TEXTURE_NUM%];
2672
+ uniform float uMetallic;
2673
+ uniform float uRoughness;
2674
+
2675
+ void light_fragment(inout vec4 color, in vec2 vRegion) {
2676
+ if (color.a < 0.005) return;
2677
+
2678
+ // 屏幕坐标映射到世界坐标
2679
+ vec2 worldPos = vec2(gl_FragCoord.x, uResolution.y - gl_FragCoord.y) * (uLogicalResolution / uResolution);
2680
+ vec3 normal = normalize(texture(uNormalMap, vRegion).rgb * 2.0 - 1.0) * vec3(1.0, -1.0, 1.0);
2681
+
2682
+ vec3 totalDiffuse = vec3(0.0);
2683
+ vec3 totalSpecular = vec3(0.0);
2684
+ vec3 viewDir = vec3(0.0, 0.0, 1.0);
2685
+ vec3 specColor = mix(vec3(1.0), color.rgb, uMetallic);
2686
+ float shininess = exp2((1.0 - uRoughness) * 7.0 + 1.0);
2687
+
2688
+ for (int i = 0; i < %TEXTURE_NUM%; i++) {
2689
+ if (i >= uLightCount) break;
2690
+
2691
+ vec2 lightPos = uLightMatrix[i][2];
2692
+ mat2 lightBasis = mat2(uLightMatrix[i][0], uLightMatrix[i][1]);
2693
+ vec2 lightUV = inverse(lightBasis) * (worldPos - lightPos) + 0.5;
2694
+
2695
+ // 判断当前像素是否在该光源范围内
2696
+ if (lightUV.x >= 0.0 && lightUV.x <= 1.0 && lightUV.y >= 0.0 && lightUV.y <= 1.0) {
2697
+
2698
+ // ⭐️ 核心修复:sampler2DArray 采样必须传 vec3
2699
+ // 第三个分量是该光源对应的图层 ID (转为 float)
2700
+ int layer = uLightTextureId[i];
2701
+ vec4 lightTex;
2702
+ %GET_COLOR%
2703
+
2704
+ vec3 lightDir = normalize(vec3(lightPos - worldPos, uLightHeight[i]));
2705
+ float diff = max(dot(normal, lightDir), 0.0);
2706
+ float spec = pow(max(dot(normal, normalize(lightDir + viewDir)), 0.0), shininess);
2707
+ vec3 attenuation = lightTex.rgb * lightTex.a;
2708
+
2709
+ totalDiffuse += uLightColor[i].rgb * diff * attenuation * (1.0 - uMetallic);
2710
+ totalSpecular += specColor * uLightColor[i].rgb * spec * attenuation * color.a;
2711
+ }
2712
+ }
2713
+
2714
+ // 环境光 + 漫反射 + 高光
2715
+ color.rgb = color.rgb * (vec3(0.1, 0.1, 0.15) + totalDiffuse) + totalSpecular;
2716
+ }
2717
+ `, xe = "void light_vertex(inout vec4 p, vec2 u) {}", J = 8;
2718
+ class ge extends ct {
2719
+ constructor(t, e = "", r = "", i = 0, s) {
2720
+ super(
2721
+ t,
2722
+ e + xe,
2723
+ D(r + me, t.maxTextureUnits - 1, "layer", "lightUV", "lightTex = "),
2724
+ i + 1,
2725
+ s
2726
+ ), this.prefix.push("light_");
2727
+ }
2728
+ }
2729
+ class ve {
2730
+ shader;
2731
+ rapid;
2732
+ rt;
2733
+ constructor(t) {
2734
+ this.rapid = t, this.shader = new ge(t), this.rt = t.texture.createRenderTexture({ width: 0, height: 0 });
2735
+ }
2736
+ lightShadow(t, e, r) {
2737
+ if (r.length === 0) return;
2738
+ const i = this.rapid, s = typeof e == "number" ? e : e.world, a = new g(t.rawWidth * 0.5, t.rawHeight * 0.5), h = r.map((c) => {
2739
+ const u = i.matrixStack.localToWorld(c.x, c.y), l = i.matrix.worldToLocal(s, u.x, u.y);
2740
+ return new g(
2741
+ // 要把LightTexture的基向量转化为RenderTexture的坐标
2742
+ // 纹理是从左上角开始的,所以要 + 0.5
2743
+ (l.x + 0.5) * t.rawWidth,
2744
+ (l.y + 0.5) * t.rawHeight
2745
+ );
2746
+ });
2747
+ this.rt.resize(t.rawWidth, t.rawHeight);
2748
+ const o = Math.hypot(t.rawWidth, t.rawHeight) * 0.5 * 1.05;
2749
+ return i.drawToRenderTexture(this.rt, () => {
2750
+ i.withMask(() => {
2751
+ i.startMaskGraphic(i.gl.TRIANGLES);
2752
+ for (let c = 0; c < h.length; c++) {
2753
+ const u = h[c], l = h[(c + 1) % h.length], f = u.subtract(a).normalized(), d = l.subtract(a).normalized(), x = Math.max(-0.999, Math.min(1, f.dot(d))), p = Math.sqrt((1 + x) * 0.5), v = o / p, y = a.add(f.multiply(v)), E = a.add(d.multiply(v));
2754
+ i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(l.x, l.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(u.x, u.y), i.addGraphicVertex(E.x, E.y), i.addGraphicVertex(y.x, y.y);
2755
+ }
2756
+ i.endGraphic();
2757
+ }, () => {
2758
+ i.drawSprite({ texture: t });
2759
+ }, St.NOT_EQUAL);
2760
+ }), this.rt;
2761
+ }
2762
+ setupLight(t) {
2763
+ const e = t.customShader ?? this.shader, r = Z(t.lightMatrix, J), i = Z(t.color, J), s = Z(t.lightHeight, J), a = Z(t.lightTexture, J);
2764
+ return e.setUniforms({
2765
+ uResolution: [this.rapid.physicsWidth, this.rapid.physicsHeight],
2766
+ uLogicalResolution: [this.rapid.logicWidth, this.rapid.logicHeight],
2767
+ uNormalMap: t.normalMap.glTexture,
2768
+ uLightTextureId: a.map((h) => h.glTexture),
2769
+ uLightCount: r.length,
2770
+ uLightMatrix: Float32Array.from(r.flatMap(
2771
+ (h) => Array.from(this.rapid.matrix.getMatrix(typeof h == "number" ? h : h.world))
2772
+ )),
2773
+ uLightColor: Float32Array.from(r.flatMap((h, o) => {
2774
+ const c = i[o] ?? i[0];
2775
+ return c ? [c.r / 255, c.g / 255, c.b / 255, c.a / 255] : [1, 1, 1, 1];
2776
+ })),
2777
+ uLightHeight: Float32Array.from(r.map((h, o) => s[o] ?? s[0] ?? 80)),
2778
+ uMetallic: t.metallic ?? 0.8,
2779
+ uRoughness: t.roughness ?? 0.15
2780
+ }), e;
2781
+ }
2782
+ }
2671
2783
  export {
2672
- S as ArrayType,
2673
2784
  V as BaseTexture,
2674
- oe as BlendMode,
2675
- ce as CanvasScaleMode,
2676
- x as Color,
2677
- ut as CustomGlShader,
2678
- A as DynamicArrayBuffer,
2679
- Tt as GLShader,
2680
- Yt as GraphicRegion,
2681
- $t as LineTextureMode,
2682
- he as MaskType,
2683
- bt as MatrixStack,
2684
- At as MatrixStore,
2685
- wt as ParticleEmitter,
2686
- ae as ParticleRegion,
2687
- le as ParticleShape,
2688
- Dt as QUAD_VERTICES,
2689
- de as Rapid,
2690
- Et as Region,
2691
- Ct as RenderTexture,
2692
- ot as SpriteRegion,
2785
+ ue as BlendMode,
2786
+ le as CanvasScaleMode,
2787
+ m as Color,
2788
+ ct as CustomGlShader,
2789
+ Rt as GLShader,
2790
+ ve as Light,
2791
+ ge as LightShader,
2792
+ qt as LineTextureMode,
2793
+ J as MAX_LIGHTS,
2794
+ St as MaskType,
2795
+ At as ParticleEmitter,
2796
+ fe as ParticleShape,
2797
+ pe as Rapid,
2798
+ _t as RenderTexture,
2693
2799
  Pt as TextTexture,
2694
2800
  N as Texture,
2695
- ht as TextureFilterMode,
2696
- Ut as TextureManager,
2801
+ tt as TextureFilterMode,
2802
+ Ct as TextureManager,
2697
2803
  q as TextureWrapMode,
2698
- p as Vec2,
2699
- it as WebglBufferArray,
2700
- Xt as composeProjectionWithAffine,
2701
- ie as drawCircle,
2702
- Rt as drawGraphic,
2703
- te as drawLine,
2704
- ee as drawMaskImage,
2705
- Jt as drawParticles,
2706
- re as drawRect,
2707
- Zt as drawSprite,
2708
- qt as getColorUint32,
2709
- zt as multiplyMat4
2804
+ g as Vec2,
2805
+ jt as composeProjectionWithAffine,
2806
+ Zt as getLineGeometry,
2807
+ Qt as getLineNormal,
2808
+ Kt as multiplyMat4
2710
2809
  };