rapid-render 1.0.5 → 1.0.7

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,5 +1,5 @@
1
- var L = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(L || {});
2
- class k {
1
+ var I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
2
+ class B {
3
3
  /** The number of elements currently used in the buffer. */
4
4
  usedElemNum;
5
5
  /** The main typed array view corresponding to the specified ArrayType. */
@@ -151,7 +151,7 @@ class k {
151
151
  this.usedElemNum = 0;
152
152
  }
153
153
  }
154
- class et extends k {
154
+ class Q extends B {
155
155
  /** The actual WebGLBuffer object maintained by this instance. */
156
156
  buffer;
157
157
  /** The related WebGL rendering context. */
@@ -171,8 +171,8 @@ class et extends k {
171
171
  * @param type - Determines the type of WebGLBuffer (defaults to gl.ARRAY_BUFFER).
172
172
  * @param usage - Determines the data usage pattern (defaults to gl.DYNAMIC_DRAW).
173
173
  */
174
- constructor(t, e, i = t.ARRAY_BUFFER, r = t.DYNAMIC_DRAW) {
175
- super(e), this.gl = t, this.buffer = t.createBuffer(), this.type = i, this.usage = r;
174
+ constructor(t, e, r = t.ARRAY_BUFFER, i = t.DYNAMIC_DRAW) {
175
+ super(e), this.gl = t, this.buffer = t.createBuffer(), this.type = r, this.usage = i;
176
176
  }
177
177
  /**
178
178
  * Flags the buffer as dirty, marking it for future data synchronization.
@@ -202,7 +202,7 @@ class et extends k {
202
202
  }
203
203
  }
204
204
  }
205
- class m {
205
+ class p {
206
206
  _r;
207
207
  _g;
208
208
  _b;
@@ -219,8 +219,8 @@ class m {
219
219
  * @param b - The blue component (0-255).
220
220
  * @param a - The alpha component (0-255).
221
221
  */
222
- constructor(t, e, i, r = 255) {
223
- this._r = t, this._g = e, this._b = i, this._a = r, this.updateUint();
222
+ constructor(t, e, r, i = 255) {
223
+ this._r = t, this._g = e, this._b = r, this._a = i, this.updateUint();
224
224
  }
225
225
  setClearColor(t) {
226
226
  t.clearColor(this.r / 255, this.g / 255, this.b / 255, this.a / 255);
@@ -283,8 +283,8 @@ class m {
283
283
  */
284
284
  updateUint() {
285
285
  this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
286
- const t = m.clampByte(this._a), e = m.clampByte(this._r * t / 255), i = m.clampByte(this._g * t / 255), r = m.clampByte(this._b * t / 255);
287
- this.premultipliedUint32 = (t << 24 | r << 16 | i << 8 | e) >>> 0;
286
+ const t = p.clampByte(this._a), e = p.clampByte(this._r * t / 255), r = p.clampByte(this._g * t / 255), i = p.clampByte(this._b * t / 255);
287
+ this.premultipliedUint32 = (t << 24 | i << 16 | r << 8 | e) >>> 0;
288
288
  }
289
289
  reset() {
290
290
  this._r = 0, this._g = 0, this._b = 0, this._a = 255, this.updateUint();
@@ -296,14 +296,14 @@ class m {
296
296
  * @param b - The blue component (0-255).
297
297
  * @param a - The alpha component (0-255).
298
298
  */
299
- setRGBA(t, e, i, r) {
300
- this.r = t, this.g = e, this.b = i, this.a = r, this.updateUint();
299
+ setRGBA(t, e, r, i) {
300
+ this.r = t, this.g = e, this.b = r, this.a = i, this.updateUint();
301
301
  }
302
- setHSL(t, e, i) {
303
- t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, i = Math.max(0, Math.min(100, i)) / 100;
304
- const r = (1 - Math.abs(2 * i - 1)) * e, n = r * (1 - Math.abs(t / 60 % 2 - 1)), a = i - r / 2;
305
- let o = 0, h = 0, c = 0;
306
- return t < 60 ? [o, h, c] = [r, n, 0] : t < 120 ? [o, h, c] = [n, r, 0] : t < 180 ? [o, h, c] = [0, r, n] : t < 240 ? [o, h, c] = [0, n, r] : t < 300 ? [o, h, c] = [n, 0, r] : [o, h, c] = [r, 0, n], this.setRGBA((o + a) * 255, (h + a) * 255, (c + a) * 255, 255), this;
302
+ setHSL(t, e, r) {
303
+ t = (t % 360 + 360) % 360, e = Math.max(0, Math.min(100, e)) / 100, r = Math.max(0, Math.min(100, r)) / 100;
304
+ const i = (1 - Math.abs(2 * r - 1)) * e, n = i * (1 - Math.abs(t / 60 % 2 - 1)), a = r - i / 2;
305
+ let c = 0, h = 0, o = 0;
306
+ return t < 60 ? [c, h, o] = [i, n, 0] : t < 120 ? [c, h, o] = [n, i, 0] : t < 180 ? [c, h, o] = [0, i, n] : t < 240 ? [c, h, o] = [0, n, i] : t < 300 ? [c, h, o] = [n, 0, i] : [c, h, o] = [i, 0, n], this.setRGBA((c + a) * 255, (h + a) * 255, (o + a) * 255, 255), this;
307
307
  }
308
308
  toHex() {
309
309
  const t = (e) => Math.max(0, Math.min(255, Math.round(e))).toString(16).padStart(2, "0");
@@ -321,7 +321,7 @@ class m {
321
321
  * @returns A new `Color` instance with the same RGBA values.
322
322
  */
323
323
  clone() {
324
- return new m(this._r, this._g, this._b, this._a);
324
+ return new p(this._r, this._g, this._b, this._a);
325
325
  }
326
326
  /**
327
327
  * Converts the color to a hexadecimal string representation (e.g., '#RRGGBBAA').
@@ -329,8 +329,8 @@ class m {
329
329
  * @returns The hexadecimal string representation of the color.
330
330
  */
331
331
  toHexString(t = !0) {
332
- const e = this.r.toString(16).padStart(2, "0"), i = this.g.toString(16).padStart(2, "0"), r = this.b.toString(16).padStart(2, "0"), n = this.a.toString(16).padStart(2, "0");
333
- return `#${e}${i}${r}${t ? n : ""}`;
332
+ 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"), n = this.a.toString(16).padStart(2, "0");
333
+ return `#${e}${r}${i}${t ? n : ""}`;
334
334
  }
335
335
  /**
336
336
  * Checks if the current color is equal to another color.
@@ -354,18 +354,18 @@ class m {
354
354
  * @example
355
355
  * Color.fromNorm(0.9, 0.87, 0.55, 0.1) // moon glow
356
356
  */
357
- static FromHSL(t, e, i) {
358
- return new m(0, 0, 0).setHSL(t, e, i);
357
+ static FromHSL(t, e, r) {
358
+ return new p(0, 0, 0).setHSL(t, e, r);
359
359
  }
360
- static FromRGB(t, e, i) {
361
- return new m(t, e, i);
360
+ static FromRGB(t, e, r) {
361
+ return new p(t, e, r);
362
362
  }
363
- static fromNorm(t, e, i, r = 1) {
364
- return new m(
363
+ static fromNorm(t, e, r, i = 1) {
364
+ return new p(
365
365
  Math.round(t * 255),
366
366
  Math.round(e * 255),
367
- Math.round(i * 255),
368
- Math.round(r * 255)
367
+ Math.round(r * 255),
368
+ Math.round(i * 255)
369
369
  );
370
370
  }
371
371
  /**
@@ -375,9 +375,9 @@ class m {
375
375
  */
376
376
  static fromHex(t) {
377
377
  t.startsWith("#") && (t = t.slice(1));
378
- const e = parseInt(t.slice(0, 2), 16), i = parseInt(t.slice(2, 4), 16), r = parseInt(t.slice(4, 6), 16);
378
+ const e = parseInt(t.slice(0, 2), 16), r = parseInt(t.slice(2, 4), 16), i = parseInt(t.slice(4, 6), 16);
379
379
  let n = 255;
380
- return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new m(e, i, r, n);
380
+ return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new p(e, r, i, n);
381
381
  }
382
382
  /**
383
383
  * Adds the components of another color to this color, clamping the result to 255.
@@ -385,7 +385,7 @@ class m {
385
385
  * @returns A new Color instance with the result of the addition.
386
386
  */
387
387
  add(t) {
388
- return new m(
388
+ return new p(
389
389
  Math.min(this.r + t.r, 255),
390
390
  Math.min(this.g + t.g, 255),
391
391
  Math.min(this.b + t.b, 255),
@@ -398,7 +398,7 @@ class m {
398
398
  * @returns A new Color instance with the result of the subtraction.
399
399
  */
400
400
  subtract(t) {
401
- return new m(
401
+ return new p(
402
402
  this.r - t.r,
403
403
  this.g - t.g,
404
404
  this.b - t.b,
@@ -406,12 +406,12 @@ class m {
406
406
  );
407
407
  }
408
408
  divide(t) {
409
- return t instanceof m ? new m(
409
+ return t instanceof p ? new p(
410
410
  this.r / t.r,
411
411
  this.g / t.g,
412
412
  this.b / t.b,
413
413
  this.a / t.a
414
- ) : new m(
414
+ ) : new p(
415
415
  this.r / t,
416
416
  this.g / t,
417
417
  this.b / t,
@@ -419,12 +419,12 @@ class m {
419
419
  );
420
420
  }
421
421
  multiply(t) {
422
- return t instanceof m ? new m(
422
+ return t instanceof p ? new p(
423
423
  this.r * t.r,
424
424
  this.g * t.g,
425
425
  this.b * t.b,
426
426
  this.a * t.a
427
- ) : new m(
427
+ ) : new p(
428
428
  this.r * t,
429
429
  this.g * t,
430
430
  this.b * t,
@@ -434,37 +434,38 @@ class m {
434
434
  clamp() {
435
435
  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));
436
436
  }
437
- static Red = new m(255, 0, 0, 255);
438
- static Green = new m(0, 255, 0, 255);
439
- static Blue = new m(0, 0, 255, 255);
440
- static Yellow = new m(255, 255, 0, 255);
441
- static Purple = new m(128, 0, 128, 255);
442
- static Orange = new m(255, 165, 0, 255);
443
- static Pink = new m(255, 192, 203, 255);
444
- static Gray = new m(128, 128, 128, 255);
445
- static Brown = new m(139, 69, 19, 255);
446
- static Cyan = new m(0, 255, 255, 255);
447
- static Magenta = new m(255, 0, 255, 255);
448
- static Lime = new m(192, 255, 0, 255);
449
- static White = new m(255, 255, 255, 255);
450
- static Black = new m(0, 0, 0, 255);
451
- static Transparent = new m(0, 0, 0, 0);
452
- static TRANSPARENT = new m(0, 0, 0, 0);
437
+ static Red = new p(255, 0, 0, 255);
438
+ static Green = new p(0, 255, 0, 255);
439
+ static Blue = new p(0, 0, 255, 255);
440
+ static Yellow = new p(255, 255, 0, 255);
441
+ static Purple = new p(128, 0, 128, 255);
442
+ static Orange = new p(255, 165, 0, 255);
443
+ static Pink = new p(255, 192, 203, 255);
444
+ static Gray = new p(128, 128, 128, 255);
445
+ static Brown = new p(139, 69, 19, 255);
446
+ static Cyan = new p(0, 255, 255, 255);
447
+ static Magenta = new p(255, 0, 255, 255);
448
+ static Lime = new p(192, 255, 0, 255);
449
+ static White = new p(255, 255, 255, 255);
450
+ static Black = new p(0, 0, 0, 255);
451
+ static Transparent = new p(0, 0, 0, 0);
452
+ static TRANSPARENT = new p(0, 0, 0, 0);
453
453
  }
454
- const E = 6;
455
- class St {
454
+ const y = 6;
455
+ class Mt {
456
456
  /** Total number of matrices currently allocated in the store. */
457
457
  matrixCount = 0;
458
458
  /** The dynamic buffer used to hold matrix data. */
459
459
  buffer;
460
460
  /** The raw floating-point data of all matrices. */
461
461
  data;
462
+ temporary = -1;
462
463
  /**
463
464
  * Creates a new MatrixStore.
464
465
  * @param capacity - The initial capacity of the matrix store (default is 10).
465
466
  */
466
467
  constructor(t = 10) {
467
- this.buffer = new k(L.Float32), this.buffer.resize(t * E), this.data = this.buffer.getArray();
468
+ this.buffer = new B(I.Float32), this.buffer.resize(t * y), this.data = this.buffer.getArray(), this.reset();
468
469
  }
469
470
  /**
470
471
  * Allocates a new matrix and initializes it to the identity matrix.
@@ -479,21 +480,21 @@ class St {
479
480
  * @returns The index of the newly allocated matrix.
480
481
  */
481
482
  allocDirty() {
482
- return this.buffer.resize(E) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += E, this.matrixCount++;
483
+ return this.buffer.resize(y) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += y, this.matrixCount++;
483
484
  }
484
485
  /**
485
486
  * Resets the store, clearing all allocated matrices.
486
487
  */
487
488
  reset() {
488
- this.matrixCount = 0, this.buffer.usedElemNum = 0;
489
+ this.matrixCount = 0, this.buffer.usedElemNum = 0, this.temporary = this.alloc();
489
490
  }
490
491
  /**
491
492
  * Sets the matrix at the given index to the identity matrix.
492
493
  * @param index - The index of the matrix to modify.
493
494
  */
494
495
  identity(t) {
495
- const e = t * E, i = this.data;
496
- i[e] = 1, i[e + 1] = 0, i[e + 2] = 0, i[e + 3] = 1, i[e + 4] = 0, i[e + 5] = 0;
496
+ const e = t * y, r = this.data;
497
+ r[e] = 1, r[e + 1] = 0, r[e + 2] = 0, r[e + 3] = 1, r[e + 4] = 0, r[e + 5] = 0;
497
498
  }
498
499
  /**
499
500
  * Translates the matrix at the given index by x and y.
@@ -501,9 +502,9 @@ class St {
501
502
  * @param x - The x translation.
502
503
  * @param y - The y translation.
503
504
  */
504
- translate(t, e, i) {
505
- const r = t * E, n = this.data;
506
- n[r + 4] = n[r] * e + n[r + 2] * i + n[r + 4], n[r + 5] = n[r + 1] * e + n[r + 3] * i + n[r + 5];
505
+ translate(t, e, r) {
506
+ const i = t * y, n = this.data;
507
+ n[i + 4] = n[i] * e + n[i + 2] * r + n[i + 4], n[i + 5] = n[i + 1] * e + n[i + 3] * r + n[i + 5];
507
508
  }
508
509
  /**
509
510
  * Scales the matrix at the given index by scaleX and scaleY.
@@ -511,9 +512,9 @@ class St {
511
512
  * @param scaleX - The scale factor along the x-axis.
512
513
  * @param scaleY - The scale factor along the y-axis.
513
514
  */
514
- scale(t, e, i) {
515
- const r = t * E, n = this.data;
516
- n[r] *= e, n[r + 1] *= e, n[r + 2] *= i, n[r + 3] *= i;
515
+ scale(t, e, r) {
516
+ const i = t * y, n = this.data;
517
+ n[i] *= e, n[i + 1] *= e, n[i + 2] *= r, n[i + 3] *= r;
517
518
  }
518
519
  /**
519
520
  * Rotates the matrix at the given index by the specified radians.
@@ -521,8 +522,8 @@ class St {
521
522
  * @param radians - The rotation angle in radians.
522
523
  */
523
524
  rotate(t, e) {
524
- const i = t * E, r = this.data, n = Math.cos(e), a = Math.sin(e), o = r[i], h = r[i + 1], c = r[i + 2], u = r[i + 3];
525
- r[i] = o * n + c * a, r[i + 1] = h * n + u * a, r[i + 2] = o * -a + c * n, r[i + 3] = h * -a + u * n;
525
+ const r = t * y, i = this.data, n = Math.cos(e), a = Math.sin(e), c = i[r], h = i[r + 1], o = i[r + 2], u = i[r + 3];
526
+ i[r] = c * n + o * a, i[r + 1] = h * n + u * a, i[r + 2] = c * -a + o * n, i[r + 3] = h * -a + u * n;
526
527
  }
527
528
  /**
528
529
  * Rotates the matrix at the given index around a local offset point (pivot).
@@ -540,8 +541,8 @@ class St {
540
541
  * @param offsetX - The x component of the pivot point in local space.
541
542
  * @param offsetY - The y component of the pivot point in local space.
542
543
  */
543
- rotateWithOffset(t, e, i, r) {
544
- this.translate(t, i, r), this.rotate(t, e), this.translate(t, -i, -r);
544
+ rotateWithOffset(t, e, r, i) {
545
+ this.translate(t, r, i), this.rotate(t, e), this.translate(t, -r, -i);
545
546
  }
546
547
  /**
547
548
  * Copies the elements from the source matrix to the destination matrix.
@@ -549,8 +550,8 @@ class St {
549
550
  * @param src - The index of the source matrix.
550
551
  */
551
552
  copy(t, e) {
552
- const i = t * E, r = e * E, n = this.data;
553
- n[i] = n[r], n[i + 1] = n[r + 1], n[i + 2] = n[r + 2], n[i + 3] = n[r + 3], n[i + 4] = n[r + 4], n[i + 5] = n[r + 5];
553
+ const r = t * y, i = e * y, n = this.data;
554
+ n[r] = n[i], n[r + 1] = n[i + 1], n[r + 2] = n[i + 2], n[r + 3] = n[i + 3], n[r + 4] = n[i + 4], n[r + 5] = n[i + 5];
554
555
  }
555
556
  /**
556
557
  * Multiplies the destination matrix by the source matrix and stores the result in the destination.
@@ -566,22 +567,22 @@ class St {
566
567
  * @param aIdx - The index of matrix A.
567
568
  * @param bIdx - The index of matrix B.
568
569
  */
569
- multiplyOut(t, e, i) {
570
- const r = t * E, n = e * E, a = i * E, o = this.data, h = o[n], c = o[n + 1], u = o[n + 2], f = o[n + 3], l = o[n + 4], p = o[n + 5], x = o[a], v = o[a + 1], R = o[a + 2], T = o[a + 3], g = o[a + 4], w = o[a + 5];
571
- o[r] = h * x + u * v, o[r + 1] = c * x + f * v, o[r + 2] = h * R + u * T, o[r + 3] = c * R + f * T, o[r + 4] = h * g + u * w + l, o[r + 5] = c * g + f * w + p;
570
+ multiplyOut(t, e, r) {
571
+ const i = t * y, n = e * y, a = r * y, c = this.data, h = c[n], o = c[n + 1], u = c[n + 2], l = c[n + 3], d = c[n + 4], f = c[n + 5], x = c[a], g = c[a + 1], v = c[a + 2], T = c[a + 3], R = c[a + 4], E = c[a + 5];
572
+ c[i] = h * x + u * g, c[i + 1] = o * x + l * g, c[i + 2] = h * v + u * T, c[i + 3] = o * v + l * T, c[i + 4] = h * R + u * E + d, c[i + 5] = o * R + l * E + f;
572
573
  }
573
574
  /**
574
575
  * Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
575
576
  * @param index - The index of the matrix to invert.
576
577
  */
577
578
  invert(t) {
578
- const e = t * E, i = this.data, r = i[e], n = i[e + 1], a = i[e + 2], o = i[e + 3], h = i[e + 4], c = i[e + 5];
579
- let u = r * o - n * a;
579
+ const e = t * y, r = this.data, i = r[e], n = r[e + 1], a = r[e + 2], c = r[e + 3], h = r[e + 4], o = r[e + 5];
580
+ let u = i * c - n * a;
580
581
  if (!u) {
581
582
  this.identity(t);
582
583
  return;
583
584
  }
584
- u = 1 / u, i[e] = o * u, i[e + 1] = -n * u, i[e + 2] = -a * u, i[e + 3] = r * u, i[e + 4] = (a * c - o * h) * u, i[e + 5] = (n * h - r * c) * u;
585
+ u = 1 / u, r[e] = c * u, r[e + 1] = -n * u, r[e + 2] = -a * u, r[e + 3] = i * u, r[e + 4] = (a * o - c * h) * u, r[e + 5] = (n * h - i * o) * u;
585
586
  }
586
587
  /**
587
588
  * Transforms a point by the matrix at the given index.
@@ -590,11 +591,11 @@ class St {
590
591
  * @param y - The y coordinate of the point.
591
592
  * @returns The transformed point {x, y}.
592
593
  */
593
- transformPoint(t, e, i) {
594
- const r = t * E, n = this.data;
594
+ transformPoint(t, e, r) {
595
+ const i = t * y, n = this.data;
595
596
  return {
596
- x: e * n[r] + i * n[r + 2] + n[r + 4],
597
- y: e * n[r + 1] + i * n[r + 3] + n[r + 5]
597
+ x: e * n[i] + r * n[i + 2] + n[i + 4],
598
+ y: e * n[i + 1] + r * n[i + 3] + n[i + 5]
598
599
  };
599
600
  }
600
601
  /**
@@ -605,11 +606,11 @@ class St {
605
606
  * @param y - World y coordinate.
606
607
  * @returns The transformed point in local coordinates.
607
608
  */
608
- worldToLocal(t, e, i) {
609
- const r = this.allocDirty();
610
- this.copy(r, t), this.invert(r);
611
- const n = this.transformPoint(r, e, i);
612
- return this.matrixCount--, this.buffer.usedElemNum -= E, n;
609
+ worldToLocal(t, e, r) {
610
+ const i = this.allocDirty();
611
+ this.copy(i, t), this.invert(i);
612
+ const n = this.transformPoint(i, e, r);
613
+ return this.matrixCount--, this.buffer.usedElemNum -= y, n;
613
614
  }
614
615
  /**
615
616
  * Transforms a point from local coordinates to world coordinates.
@@ -618,8 +619,8 @@ class St {
618
619
  * @param y - Local y coordinate.
619
620
  * @returns The transformed point in world coordinates.
620
621
  */
621
- localToWorld(t, e, i) {
622
- return this.transformPoint(t, e, i);
622
+ localToWorld(t, e, r) {
623
+ return this.transformPoint(t, e, r);
623
624
  }
624
625
  /**
625
626
  * Extracts the global position (translation) from the matrix at the given index.
@@ -627,8 +628,8 @@ class St {
627
628
  * @returns An object containing `x` and `y` global coordinates.
628
629
  */
629
630
  getPosition(t) {
630
- const e = t * E, i = this.data;
631
- return { x: i[e + 4], y: i[e + 5] };
631
+ const e = t * y, r = this.data;
632
+ return { x: r[e + 4], y: r[e + 5] };
632
633
  }
633
634
  /**
634
635
  * Extracts the global scale from the matrix at the given index.
@@ -636,8 +637,8 @@ class St {
636
637
  * @returns An object containing `x` and `y` global scale factors.
637
638
  */
638
639
  getScale(t) {
639
- const e = t * E, i = this.data, r = Math.sqrt(i[e] * i[e] + i[e + 1] * i[e + 1]), n = Math.sqrt(i[e + 2] * i[e + 2] + i[e + 3] * i[e + 3]);
640
- return { x: r, y: n };
640
+ const e = t * y, r = this.data, i = Math.sqrt(r[e] * r[e] + r[e + 1] * r[e + 1]), n = Math.sqrt(r[e + 2] * r[e + 2] + r[e + 3] * r[e + 3]);
641
+ return { x: i, y: n };
641
642
  }
642
643
  /**
643
644
  * Extracts the global rotation (in radians) from the matrix at the given index.
@@ -645,8 +646,8 @@ class St {
645
646
  * @returns The global rotation in radians.
646
647
  */
647
648
  getRotation(t) {
648
- const e = t * E, i = this.data;
649
- return Math.atan2(i[e + 1], i[e]);
649
+ const e = t * y, r = this.data;
650
+ return Math.atan2(r[e + 1], r[e]);
650
651
  }
651
652
  /**
652
653
  * Converts the matrix at the given index to a CSS matrix string.
@@ -655,9 +656,9 @@ class St {
655
656
  * @param scaleY - Extra scale applied to the b/d/ty components.
656
657
  * @returns A CSS matrix string.
657
658
  */
658
- toCSSMatrix(t, e = 1, i = 1) {
659
- const r = t * E, n = this.data;
660
- return `matrix(${n[r] * e}, ${n[r + 1] * i}, ${n[r + 2] * e}, ${n[r + 3] * i}, ${n[r + 4] * e}, ${n[r + 5] * i})`;
659
+ toCSSMatrix(t, e = 1, r = 1) {
660
+ const i = t * y, n = this.data;
661
+ return `matrix(${n[i] * e}, ${n[i + 1] * r}, ${n[i + 2] * e}, ${n[i + 3] * r}, ${n[i + 4] * e}, ${n[i + 5] * r})`;
661
662
  }
662
663
  /**
663
664
  * Retrieves a copy of the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
@@ -667,8 +668,8 @@ class St {
667
668
  * @returns A new Float32Array containing the 6 elements of the matrix.
668
669
  */
669
670
  getMatrix(t) {
670
- const e = t * E;
671
- return this.data.slice(e, e + E);
671
+ const e = t * y;
672
+ return this.data.slice(e, e + y);
672
673
  }
673
674
  /**
674
675
  * Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
@@ -678,8 +679,8 @@ class St {
678
679
  * @returns A Float32Array view pointing directly to the matrix's data in memory.
679
680
  */
680
681
  getMatrixRef(t) {
681
- const e = t * E;
682
- return this.data.subarray(e, e + E);
682
+ const e = t * y;
683
+ return this.data.subarray(e, e + y);
683
684
  }
684
685
  /**
685
686
  * Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
@@ -688,29 +689,33 @@ class St {
688
689
  * @param f - An array (Float32Array or standard number array) containing the 6 new elements.
689
690
  */
690
691
  setMatrix(t, e) {
691
- const i = t * E, r = this.data;
692
- r[i] = e[0], r[i + 1] = e[1], r[i + 2] = e[2], r[i + 3] = e[3], r[i + 4] = e[4], r[i + 5] = e[5];
692
+ const r = t * y, i = this.data;
693
+ 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];
694
+ }
695
+ multiplyAffineInPlace(t, e, r, i, n, a, c) {
696
+ const h = t * 6, o = this.data, u = o[h], l = o[h + 1], d = o[h + 2], f = o[h + 3], x = o[h + 4], g = o[h + 5];
697
+ o[h] = u * e + d * r, o[h + 1] = l * e + f * r, o[h + 2] = u * i + d * n, o[h + 3] = l * i + f * n, o[h + 4] = u * a + d * c + x, o[h + 5] = l * a + f * c + g;
693
698
  }
694
- multiplyAffineInPlace(t, e, i, r, n, a, o) {
695
- const h = t * 6, c = this.data, u = c[h], f = c[h + 1], l = c[h + 2], p = c[h + 3], x = c[h + 4], v = c[h + 5];
696
- c[h] = u * e + l * i, c[h + 1] = f * e + p * i, c[h + 2] = u * r + l * n, c[h + 3] = f * r + p * n, c[h + 4] = u * a + l * o + x, c[h + 5] = f * a + p * o + v;
699
+ multiplyAffine(t, e, r, i, n, a, c, h) {
700
+ const o = t * 6, u = e * 6, l = this.data, d = l[o], f = l[o + 1], x = l[o + 2], g = l[o + 3], v = l[o + 4], T = l[o + 5];
701
+ l[u] = d * r + x * i, l[u + 1] = f * r + g * i, l[u + 2] = d * n + x * a, l[u + 3] = f * n + g * a, l[u + 4] = d * c + x * h + v, l[u + 5] = f * c + g * h + T;
697
702
  }
698
703
  }
699
- class bt {
704
+ class St {
700
705
  /** The underlying store for matrices. */
701
- matrix = new St();
706
+ matrix = new Mt();
702
707
  /** The current step or depth in the transformation hierarchy. */
703
708
  step = 0;
704
709
  /** Internal stack maintaining structural information. */
705
- stack = new k(L.Uint32);
710
+ stack = new B(I.Uint32);
706
711
  /** Records the world matrices generated at each step. */
707
- stepWorldM = new k(L.Uint32);
712
+ stepWorldM = new B(I.Uint32);
708
713
  /** Records actions (push/pop) taken during the traversal. */
709
- stepAction = new k(L.Uint32);
714
+ stepAction = new B(I.Uint32);
710
715
  /** Records the parent world matrix for each step (used by updateMatrix). */
711
- stepParentM = new k(L.Uint32);
716
+ stepParentM = new B(I.Uint32);
712
717
  /** Buffer used during hierarchy traversal updates. */
713
- parentStack = new k(L.Uint32);
718
+ parentStack = new B(I.Uint32);
714
719
  /** The index of the current local matrix in the matrix store. */
715
720
  curLocalM = -1;
716
721
  /** The index of the current world matrix in the matrix store. */
@@ -744,14 +749,14 @@ class bt {
744
749
  * @param step - The initial step to update matrices from.
745
750
  */
746
751
  updateMatrix(t) {
747
- const e = (typeof t == "number" ? t : t.step) - 1, i = this.stepParentM.get(e);
748
- let r = 0, n = e;
752
+ const e = (typeof t == "number" ? t : t.step) - 1, r = this.stepParentM.get(e);
753
+ let i = 0, n = e;
749
754
  const a = this.parentStack;
750
- for (a.reset(), a.push(i); n < this.stepAction.length; ) {
755
+ for (a.reset(), a.push(r); n < this.stepAction.length; ) {
751
756
  if (this.stepAction.get(n) === 1) {
752
- const h = this.stepWorldM.get(n), c = h - 1, u = a.top();
753
- this.matrix.multiplyOut(h, u, c), a.push(h), r++;
754
- } else if (a.pop(), r--, r === 0)
757
+ const h = this.stepWorldM.get(n), o = h - 1, u = a.top();
758
+ this.matrix.multiplyOut(h, u, o), a.push(h), i++;
759
+ } else if (a.pop(), i--, i === 0)
755
760
  break;
756
761
  n++;
757
762
  }
@@ -796,8 +801,8 @@ class bt {
796
801
  * @param offsetX - The x component of the pivot point in local space.
797
802
  * @param offsetY - The y component of the pivot point in local space.
798
803
  */
799
- rotateWithOffset(t, e, i) {
800
- this.matrix.rotateWithOffset(this.curLocalM, t, e, i), this.matrix.rotateWithOffset(this.curWorldM, t, e, i);
804
+ rotateWithOffset(t, e, r) {
805
+ this.matrix.rotateWithOffset(this.curLocalM, t, e, r), this.matrix.rotateWithOffset(this.curWorldM, t, e, r);
801
806
  }
802
807
  /**
803
808
  * Sets the current local and world matrices to the identity matrix.
@@ -859,57 +864,69 @@ class bt {
859
864
  * Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].
860
865
  */
861
866
  getTransform() {
862
- const t = this.curWorldM * E;
863
- return this.matrix.data.slice(t, t + E);
867
+ const t = this.curWorldM * y;
868
+ return this.matrix.data.slice(t, t + y);
864
869
  }
865
870
  /**
866
871
  * Directly overwrites the current world matrix with the given 6-element 2D transform.
867
872
  */
868
873
  setTransform(t) {
869
- const e = this.curWorldM * E, i = this.matrix.data;
870
- i[e] = t[0], i[e + 1] = t[1], i[e + 2] = t[2], i[e + 3] = t[3], i[e + 4] = t[4], i[e + 5] = t[5];
874
+ const e = this.curWorldM * y, r = this.matrix.data;
875
+ 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];
871
876
  }
872
877
  transformPoint(t, e) {
873
878
  return this.matrix.transformPoint(this.curLocalM, t, e);
874
879
  }
875
880
  /**
876
881
  * Applies a transform options object to the current matrix state.
877
- * Optionally saves the matrix first (saveTransform defaults to true).
878
- */
879
- applyTransform(t, e = 0, i = 0) {
880
- (t.saveTransform ?? !0) && this.save();
881
- let r = t.x ?? 0, n = t.y ?? 0;
882
- t.position && (r += t.position.x, n += t.position.y);
883
- let a = 1, o = 1;
884
- const h = t.scale;
885
- h && (typeof h == "number" ? (a = h, o = h) : (a = h.x, o = h.y));
886
- const c = t.rotation ?? 0;
887
- let u = t.offsetX ?? 0, f = t.offsetY ?? 0;
888
- t.offset && (u += t.offset.x, f += t.offset.y);
889
- const l = t.origin;
890
- l !== void 0 && (typeof l == "number" ? (u -= l * e, f -= l * i) : (u -= l.x * e, f -= l.y * i));
891
- const p = c ? Math.cos(c) : 1, x = c ? Math.sin(c) : 0, v = p * a, R = x * a, T = -x * o, g = p * o, w = r + v * u + T * f, b = n + R * u + g * f;
892
- (t.afterSave !== void 0 || t.saveTransform === !1) && this.matrix.multiplyAffineInPlace(
882
+ * Optionally saves the matrix first
883
+ */
884
+ applyTransform(t, e = 0, r = 0, i = -1) {
885
+ let n = t.x ?? 0, a = t.y ?? 0;
886
+ t.position && (n += t.position.x, a += t.position.y);
887
+ let c = 1, h = 1;
888
+ const o = t.scale;
889
+ o && (typeof o == "number" ? (c = o, h = o) : (c = o.x, h = o.y));
890
+ const u = t.rotation ?? 0;
891
+ let l = t.offsetX ?? 0, d = t.offsetY ?? 0;
892
+ t.offset && (l += t.offset.x, d += t.offset.y);
893
+ const f = t.origin;
894
+ f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
895
+ const x = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = x * c, T = g * c, R = -g * h, E = x * h, b = n + v * l + R * d, N = a + T * l + E * d;
896
+ if (i !== -1) {
897
+ this.matrix.multiplyAffine(
898
+ this.curWorldM,
899
+ i,
900
+ v,
901
+ T,
902
+ R,
903
+ E,
904
+ b,
905
+ N
906
+ );
907
+ return;
908
+ }
909
+ this.matrix.multiplyAffineInPlace(
893
910
  this.curLocalM,
894
911
  v,
895
- R,
896
912
  T,
897
- g,
898
- w,
899
- b
913
+ R,
914
+ E,
915
+ b,
916
+ N
900
917
  ), this.matrix.multiplyAffineInPlace(
901
918
  this.curWorldM,
902
919
  v,
903
- R,
904
920
  T,
905
- g,
906
- w,
907
- b
908
- ), t.afterSave?.();
921
+ R,
922
+ E,
923
+ b,
924
+ N
925
+ );
909
926
  }
910
927
  }
911
- var $ = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))($ || {});
912
- class At {
928
+ var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
929
+ class bt {
913
930
  render;
914
931
  cache = /* @__PURE__ */ new Map();
915
932
  constructor(t) {
@@ -922,14 +939,14 @@ class At {
922
939
  * @returns A promise that resolves to the loaded Texture.
923
940
  */
924
941
  async load(t, e) {
925
- let i = this.cache.get(t);
926
- if (i)
927
- return new P(i);
942
+ let r = this.cache.get(t);
943
+ if (r)
944
+ return new P(r);
928
945
  try {
929
- const r = await this._fetchImage(t);
930
- return i = G.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new P(i);
931
- } catch (r) {
932
- throw console.error(`[TextureManager] Failed to load: ${t}`, r), r;
946
+ const i = await this._fetchImage(t);
947
+ return r = k.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new P(r);
948
+ } catch (i) {
949
+ throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
933
950
  }
934
951
  }
935
952
  /**
@@ -941,8 +958,8 @@ class At {
941
958
  create(t, e) {
942
959
  if (e?.key && this.cache.has(e.key))
943
960
  return new P(this.cache.get(e.key));
944
- const i = G.fromSource(this.render, t, e);
945
- return e?.key && (i.uid = e.key, this.cache.set(e.key, i)), new P(i);
961
+ const r = k.fromSource(this.render, t, e);
962
+ return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new P(r);
946
963
  }
947
964
  /**
948
965
  * Creates a generic Render Texture (FrameBuffer).
@@ -952,7 +969,7 @@ class At {
952
969
  * @returns The newly created RenderTexture.
953
970
  */
954
971
  createRenderTexture(t) {
955
- return new Ut(this.render, t);
972
+ return new At(this.render, t);
956
973
  }
957
974
  /**
958
975
  * Creates a TextTexture for rendering text.
@@ -960,7 +977,7 @@ class At {
960
977
  * @returns The newly created TextTexture.
961
978
  */
962
979
  createTextTexture(t) {
963
- return new Ct(this.render, t);
980
+ return new _t(this.render, t);
964
981
  }
965
982
  /**
966
983
  * Destroys a texture and potentially removes its BaseTexture from the cache.
@@ -970,8 +987,8 @@ class At {
970
987
  * @param force - If true, destroys the underlying BaseTexture immediately regardless of reference count.
971
988
  */
972
989
  destroy(t, e = !1) {
973
- let i, r;
974
- typeof t == "string" ? (r = t, i = this.cache.get(r)) : t instanceof P ? (i = t.base, r = i?.uid, t.destroy()) : (i = t, r = i.uid), i && (i.refCount <= 0 || e) && (i.destroy(this.render.gl), r && this.cache.delete(r));
990
+ let r, i;
991
+ typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof P ? (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));
975
992
  }
976
993
  /**
977
994
  * Destroys all cached textures and clears the cache, ignoring reference counts.
@@ -982,20 +999,20 @@ class At {
982
999
  this.cache.clear();
983
1000
  }
984
1001
  _fetchImage(t) {
985
- return new Promise((e, i) => {
986
- const r = new Image();
987
- r.crossOrigin = "anonymous", r.onload = () => e(r), r.onerror = () => i(new Error(`Failed to load image resource: ${t}`)), r.src = t;
1002
+ return new Promise((e, r) => {
1003
+ const i = new Image();
1004
+ i.crossOrigin = "anonymous", i.onload = () => e(i), i.onerror = () => r(new Error(`Failed to load image resource: ${t}`)), i.src = t;
988
1005
  });
989
1006
  }
990
1007
  }
991
- class G {
1008
+ class k {
992
1009
  glTexture = null;
993
1010
  width;
994
1011
  height;
995
1012
  uid;
996
1013
  refCount = 0;
997
- constructor(t, e, i) {
998
- this.glTexture = t, this.width = e, this.height = i;
1014
+ constructor(t, e, r) {
1015
+ this.glTexture = t, this.width = e, this.height = r;
999
1016
  }
1000
1017
  /**
1001
1018
  * Creates a BaseTexture from an image source.
@@ -1004,9 +1021,9 @@ class G {
1004
1021
  * @param options - Optional configuration.
1005
1022
  * @returns The created BaseTexture.
1006
1023
  */
1007
- static fromSource(t, e, i = {}) {
1008
- const r = Q(t, e, i);
1009
- return new G(r, e.width, e.height);
1024
+ static fromSource(t, e, r = {}) {
1025
+ const i = K(t, e, r);
1026
+ return new k(i, e.width, e.height);
1010
1027
  }
1011
1028
  /**
1012
1029
  * Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
@@ -1014,20 +1031,20 @@ class G {
1014
1031
  * @param gl - The WebGL rendering context.
1015
1032
  * @param source - The new image source.
1016
1033
  */
1017
- updateSource(t, e, i = {}) {
1018
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && rt(t, i.textureFilter), i.wrap !== void 0 && it(t, i.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, i.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), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1034
+ updateSource(t, e, r = {}) {
1035
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && tt(t, r.textureFilter), r.wrap !== void 0 && J(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));
1019
1036
  }
1020
1037
  /**
1021
1038
  * Dynamically updates the texture filtering mode.
1022
1039
  */
1023
1040
  setFilterMode(t, e) {
1024
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), rt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1041
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), tt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1025
1042
  }
1026
1043
  /**
1027
1044
  * Dynamically updates the texture wrap mode.
1028
1045
  */
1029
1046
  setWrapMode(t, e) {
1030
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), it(t, e), t.bindTexture(t.TEXTURE_2D, null));
1047
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), J(t, e), t.bindTexture(t.TEXTURE_2D, null));
1031
1048
  }
1032
1049
  /**
1033
1050
  * Destroys the WebGL texture resource.
@@ -1082,8 +1099,8 @@ class P {
1082
1099
  * @param h - The height in pixels.
1083
1100
  * @returns The current Texture instance.
1084
1101
  */
1085
- setRegion(t, e, i, r) {
1086
- return this.base ? (this._px = t, this._py = e, this._pw = i, this._ph = r, this.isAtlas = t !== 0 || e !== 0 || i !== this.base.width || r !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + i / this.base.width, this.uvH = this.uvY + r / this.base.height, this.rawWidth = i, this.rawHeight = r, this) : this;
1102
+ setRegion(t, e, r, i) {
1103
+ return this.base ? (this._px = t, this._py = e, this._pw = r, this._ph = i, this.isAtlas = t !== 0 || e !== 0 || r !== this.base.width || i !== this.base.height, this.uvX = t / this.base.width, this.uvY = e / this.base.height, this.uvW = this.uvX + r / this.base.width, this.uvH = this.uvY + i / this.base.height, this.rawWidth = r, this.rawHeight = i, this) : this;
1087
1104
  }
1088
1105
  /**
1089
1106
  * Creates a new Texture representing a sub-region of this Texture.
@@ -1093,10 +1110,10 @@ class P {
1093
1110
  * @param height - The height of the sub-texture in pixels.
1094
1111
  * @returns A new Texture pointing to the sub-region.
1095
1112
  */
1096
- getSubTexture(t, e, i, r) {
1113
+ getSubTexture(t, e, r, i) {
1097
1114
  if (!this.base) return new P();
1098
- const n = this.clone(), a = this._px, o = this._py;
1099
- return n.setRegion(a + t, o + e, i, r), n;
1115
+ const n = this.clone(), a = this._px, c = this._py;
1116
+ return n.setRegion(a + t, c + e, r, i), n;
1100
1117
  }
1101
1118
  /**
1102
1119
  * Creates a shallow copy of this Texture, sharing the same BaseTexture.
@@ -1116,12 +1133,12 @@ class P {
1116
1133
  * @param gap - Optional pixel gap between cells.
1117
1134
  * @returns An array of split Textures.
1118
1135
  */
1119
- splitGrid(t, e, i, r, n = 0) {
1136
+ splitGrid(t, e, r, i, n = 0) {
1120
1137
  if (!this.base) return [];
1121
- const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, n), u = t + c, f = e + c, l = i ?? Math.floor((o + c) / u), p = r ?? Math.floor((h + c) / f);
1122
- for (let x = 0; x < p; x++)
1123
- for (let v = 0; v < l; v++)
1124
- a.push(this.getSubTexture(v * u, x * f, t, e));
1138
+ const a = [], c = this.rawWidth, h = this.rawHeight, o = Math.max(0, n), u = t + o, l = e + o, d = r ?? Math.floor((c + o) / u), f = i ?? Math.floor((h + o) / l);
1139
+ for (let x = 0; x < f; x++)
1140
+ for (let g = 0; g < d; g++)
1141
+ a.push(this.getSubTexture(g * u, x * l, t, e));
1125
1142
  return a;
1126
1143
  }
1127
1144
  /**
@@ -1129,9 +1146,9 @@ class P {
1129
1146
  * @param source - The image element, canvas, video, or bitmap.
1130
1147
  * @param options - Optional antialias and wrap mode settings.
1131
1148
  */
1132
- static fromImageSource(t, e, i = {}) {
1133
- const r = Q(t, e, i);
1134
- return new P(new G(r, e.width, e.height));
1149
+ static fromImageSource(t, e, r = {}) {
1150
+ const i = K(t, e, r);
1151
+ return new P(new k(i, e.width, e.height));
1135
1152
  }
1136
1153
  /**
1137
1154
  * Marks this Texture as destroyed, decrementing the BaseTexture reference count.
@@ -1140,7 +1157,7 @@ class P {
1140
1157
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
1141
1158
  }
1142
1159
  }
1143
- class Ut extends P {
1160
+ class At extends P {
1144
1161
  framebuffer;
1145
1162
  renderbuffer;
1146
1163
  gl;
@@ -1150,11 +1167,11 @@ class Ut extends P {
1150
1167
  _allocW = 0;
1151
1168
  _allocH = 0;
1152
1169
  constructor(t, e) {
1153
- super(), this.gl = t.gl, this.clearColor = e.clearColor ?? m.Black;
1154
- const i = Math.max(Math.round(e.width), 1), r = Math.max(Math.round(e.height), 1), a = Q(t, { width: i, height: r }, { ...e, onlySize: !0 });
1155
- if (this.setBase(new G(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1170
+ super(), this.gl = t.gl, this.clearColor = e.clearColor ?? p.Black;
1171
+ const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = K(t, { width: r, height: i }, { ...e, onlySize: !0 });
1172
+ if (this.setBase(new k(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1156
1173
  throw new Error("Failed to create Framebuffer or Renderbuffer");
1157
- this.resize(i, r, !0);
1174
+ this.resize(r, i, !0);
1158
1175
  }
1159
1176
  /**
1160
1177
  * Resizes the render texture using a grow-only GPU allocation strategy.
@@ -1168,12 +1185,12 @@ class Ut extends P {
1168
1185
  * @param height - New logical height.
1169
1186
  * @param force - Force full GPU reallocation regardless of current allocation size.
1170
1187
  */
1171
- resize(t, e, i = !1) {
1188
+ resize(t, e, r = !1) {
1172
1189
  t = Math.max(Math.round(t), 1), e = Math.max(Math.round(e), 1);
1173
- const r = this.rawWidth === t && this.rawHeight === e;
1174
- if (!i && r) return;
1190
+ const i = this.rawWidth === t && this.rawHeight === e;
1191
+ if (!r && i) return;
1175
1192
  const n = this.gl;
1176
- (i || t > this._allocW || e > this._allocH) && this.base && (this._allocW = Math.max(this._allocW, t), this._allocH = Math.max(this._allocH, e), this.base.width = this._allocW, this.base.height = this._allocH, n.bindTexture(n.TEXTURE_2D, this.base.glTexture), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, this._allocW, this._allocH, 0, n.RGBA, n.UNSIGNED_BYTE, null), n.bindRenderbuffer(n.RENDERBUFFER, this.renderbuffer), n.renderbufferStorage(n.RENDERBUFFER, n.STENCIL_INDEX8, this._allocW, this._allocH), n.bindFramebuffer(n.FRAMEBUFFER, this.framebuffer), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, this.base.glTexture, 0), n.framebufferRenderbuffer(n.FRAMEBUFFER, n.STENCIL_ATTACHMENT, n.RENDERBUFFER, this.renderbuffer), n.bindFramebuffer(n.FRAMEBUFFER, null), n.bindRenderbuffer(n.RENDERBUFFER, null), n.bindTexture(n.TEXTURE_2D, null)), this.rawWidth = t, this.rawHeight = e, this.uvX = 0, this.uvW = t / this._allocW, this.uvY = 0, this.uvH = e / this._allocH;
1193
+ (r || t > this._allocW || e > this._allocH) && this.base && (this._allocW = Math.max(this._allocW, t), this._allocH = Math.max(this._allocH, e), this.base.width = this._allocW, this.base.height = this._allocH, n.bindTexture(n.TEXTURE_2D, this.base.glTexture), n.texImage2D(n.TEXTURE_2D, 0, n.RGBA, this._allocW, this._allocH, 0, n.RGBA, n.UNSIGNED_BYTE, null), n.bindRenderbuffer(n.RENDERBUFFER, this.renderbuffer), n.renderbufferStorage(n.RENDERBUFFER, n.STENCIL_INDEX8, this._allocW, this._allocH), n.bindFramebuffer(n.FRAMEBUFFER, this.framebuffer), n.framebufferTexture2D(n.FRAMEBUFFER, n.COLOR_ATTACHMENT0, n.TEXTURE_2D, this.base.glTexture, 0), n.framebufferRenderbuffer(n.FRAMEBUFFER, n.STENCIL_ATTACHMENT, n.RENDERBUFFER, this.renderbuffer), n.bindFramebuffer(n.FRAMEBUFFER, null), n.bindRenderbuffer(n.RENDERBUFFER, null), n.bindTexture(n.TEXTURE_2D, null)), this.rawWidth = t, this.rawHeight = e, this.uvX = 0, this.uvW = t / this._allocW, this.uvY = 0, this.uvH = e / this._allocH;
1177
1194
  }
1178
1195
  /**
1179
1196
  * Activates this texture as the current render target.
@@ -1186,8 +1203,8 @@ class Ut extends P {
1186
1203
  }
1187
1204
  clear(t) {
1188
1205
  if (!this.framebuffer) return;
1189
- const e = this.gl, i = t ?? this.clearColor;
1190
- i && (i.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
1206
+ const e = this.gl, r = t ?? this.clearColor;
1207
+ r && (r.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT | e.STENCIL_BUFFER_BIT));
1191
1208
  }
1192
1209
  /**
1193
1210
  * Deactivates this texture, returning rendering to the default frame buffer.
@@ -1203,16 +1220,16 @@ class Ut extends P {
1203
1220
  * @param width - Width of the region to read.
1204
1221
  * @param height - Height of the region to read.
1205
1222
  */
1206
- GetPixels(t = 0, e = 0, i = this.rawWidth, r = this.rawHeight) {
1223
+ GetPixels(t = 0, e = 0, r = this.rawWidth, i = this.rawHeight) {
1207
1224
  if (!this.framebuffer) return new Uint8Array(0);
1208
- const n = Math.floor(t), a = Math.floor(e), o = Math.floor(i), h = Math.floor(r);
1209
- if (o <= 0 || h <= 0) return new Uint8Array(0);
1225
+ const n = Math.floor(t), a = Math.floor(e), c = Math.floor(r), h = Math.floor(i);
1226
+ if (c <= 0 || h <= 0) return new Uint8Array(0);
1210
1227
  if (n < 0 || a < 0 || n >= this.rawWidth || a >= this.rawHeight)
1211
1228
  return new Uint8Array(0);
1212
- const c = Math.min(o, this.rawWidth - n), u = Math.min(h, this.rawHeight - a), f = this.rawHeight - a - u, l = this.gl, p = l.getParameter(l.FRAMEBUFFER_BINDING);
1213
- l.bindFramebuffer(l.FRAMEBUFFER, this.framebuffer);
1214
- const x = new Uint8Array(c * u * 4);
1215
- return l.readPixels(n, f, c, u, l.RGBA, l.UNSIGNED_BYTE, x), l.bindFramebuffer(l.FRAMEBUFFER, p), x;
1229
+ const o = Math.min(c, this.rawWidth - n), u = Math.min(h, this.rawHeight - a), l = this.rawHeight - a - u, d = this.gl, f = d.getParameter(d.FRAMEBUFFER_BINDING);
1230
+ d.bindFramebuffer(d.FRAMEBUFFER, this.framebuffer);
1231
+ const x = new Uint8Array(o * u * 4);
1232
+ return d.readPixels(n, l, o, u, d.RGBA, d.UNSIGNED_BYTE, x), d.bindFramebuffer(d.FRAMEBUFFER, f), x;
1216
1233
  }
1217
1234
  /**
1218
1235
  * Get the color at a pixel in the render texture.
@@ -1220,8 +1237,8 @@ class Ut extends P {
1220
1237
  * @param y - Y coordinate in logical pixel space (top-left origin).
1221
1238
  */
1222
1239
  GetColorAt(t, e) {
1223
- const i = this.GetPixels(t, e, 1, 1);
1224
- return i.length < 4 ? new m(0, 0, 0, 0) : new m(i[0], i[1], i[2], i[3]);
1240
+ const r = this.GetPixels(t, e, 1, 1);
1241
+ return r.length < 4 ? new p(0, 0, 0, 0) : new p(r[0], r[1], r[2], r[3]);
1225
1242
  }
1226
1243
  /**
1227
1244
  * Destroys the framebuffer, renderbuffer, and base texture.
@@ -1230,7 +1247,7 @@ class Ut extends P {
1230
1247
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
1231
1248
  }
1232
1249
  }
1233
- const _t = {
1250
+ const Ut = {
1234
1251
  fontFamily: "Arial",
1235
1252
  fontSize: 24,
1236
1253
  fontWeight: "normal",
@@ -1239,7 +1256,7 @@ const _t = {
1239
1256
  align: "left",
1240
1257
  baseline: "top"
1241
1258
  };
1242
- class Ct extends P {
1259
+ class _t extends P {
1243
1260
  canvas;
1244
1261
  ctx;
1245
1262
  render;
@@ -1248,12 +1265,12 @@ class Ct extends P {
1248
1265
  options;
1249
1266
  flipY = !0;
1250
1267
  constructor(t, e) {
1251
- 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");
1252
- const i = this.canvas.getContext("2d", { willReadFrequently: !0 });
1253
- if (!i) throw new Error("Failed to get 2d context for TextTexture");
1254
- this.ctx = i, this.canvas.width = 1, this.canvas.height = 1;
1255
- const r = Q(t, this.canvas, this.options);
1256
- this.setBase(new G(r, 1, 1)), this.update();
1268
+ super(), this.render = t, this._style = { ...Ut, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1269
+ const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
1270
+ if (!r) throw new Error("Failed to get 2d context for TextTexture");
1271
+ this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
1272
+ const i = K(t, this.canvas, this.options);
1273
+ this.setBase(new k(i, 1, 1)), this.update();
1257
1274
  }
1258
1275
  get text() {
1259
1276
  return this._text;
@@ -1301,98 +1318,98 @@ class Ct extends P {
1301
1318
  * Updates the internal canvas and uploads it to WebGL
1302
1319
  */
1303
1320
  update() {
1304
- const t = this.ctx, e = this._style.fontSize, i = this._style.fontWeight, r = this._style.fontFamily, n = `${i} ${e}px ${r}`, a = this.render.dpr;
1321
+ const t = this.ctx, e = this._style.fontSize, r = this._style.fontWeight, i = this._style.fontFamily, n = `${r} ${e}px ${i}`, a = this.render.dpr;
1305
1322
  t.font = n;
1306
- const o = this._text.split(`
1323
+ const c = this._text.split(`
1307
1324
  `);
1308
- let h = 0, c = 0;
1325
+ let h = 0, o = 0;
1309
1326
  t.textBaseline = "alphabetic";
1310
- const u = t.measureText(o[0]), f = u.fontBoundingBoxAscent, l = u.fontBoundingBoxDescent;
1311
- for (const w of o) {
1312
- const b = t.measureText(w);
1313
- b.width > h && (h = b.width), c += f + l;
1327
+ const u = t.measureText(c[0]), l = u.fontBoundingBoxAscent, d = u.fontBoundingBoxDescent;
1328
+ for (const E of c) {
1329
+ const b = t.measureText(E);
1330
+ b.width > h && (h = b.width), o += l + d;
1314
1331
  }
1315
- c -= l;
1316
- const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1, v = Math.ceil(c + p) || 1, R = x * a, T = v * a;
1317
- (this.canvas.width !== R || this.canvas.height !== T) && (this.canvas.width = R, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, v), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, v);
1318
- let g = p / 2;
1319
- for (const w of o) {
1320
- let b = p / 2;
1321
- this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(w, b, g)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(w, b, g)), g += f + l;
1332
+ o -= d;
1333
+ const f = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + f) || 1, g = Math.ceil(o + f) || 1, v = x * a, T = g * a;
1334
+ (this.canvas.width !== v || this.canvas.height !== T) && (this.canvas.width = v, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, g);
1335
+ let R = f / 2;
1336
+ for (const E of c) {
1337
+ let b = f / 2;
1338
+ this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(E, b, R)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(E, b, R)), R += l + d;
1322
1339
  }
1323
1340
  this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
1324
1341
  }
1325
1342
  }
1326
- const Pt = (s, t = !1, e = !0) => {
1327
- const i = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1328
- if (!i)
1343
+ const Ct = (s, t = !1, e = !0) => {
1344
+ const r = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1345
+ if (!r)
1329
1346
  throw new Error("WebGL2 is not supported in this browser.");
1330
- return i;
1331
- }, ct = (s, t, e) => {
1332
- const i = s.createShader(e);
1333
- if (!i)
1347
+ return r;
1348
+ }, ht = (s, t, e) => {
1349
+ const r = s.createShader(e);
1350
+ if (!r)
1334
1351
  throw new Error("Unable to create webgl shader");
1335
- if (s.shaderSource(i, t), s.compileShader(i), !s.getShaderParameter(i, s.COMPILE_STATUS)) {
1336
- const n = s.getShaderInfoLog(i);
1352
+ if (s.shaderSource(r, t), s.compileShader(r), !s.getShaderParameter(r, s.COMPILE_STATUS)) {
1353
+ const n = s.getShaderInfoLog(r);
1337
1354
  throw console.error("Shader compilation failed:", n), new Error("Unable to compile shader: " + n + t);
1338
1355
  }
1339
- return i;
1340
- }, Nt = (s, t, e) => {
1341
- var i = s.createProgram(), r = ct(s, t, 35633), n = ct(s, e, 35632);
1342
- if (!i)
1356
+ return r;
1357
+ }, Pt = (s, t, e) => {
1358
+ var r = s.createProgram(), i = ht(s, t, 35633), n = ht(s, e, 35632);
1359
+ if (!r)
1343
1360
  throw new Error("Unable to create program shader");
1344
- if (s.attachShader(i, r), s.attachShader(i, n), s.linkProgram(i), !s.getProgramParameter(i, s.LINK_STATUS)) {
1345
- const o = s.getProgramInfoLog(i);
1346
- throw new Error("Unable to link shader program: " + o);
1361
+ if (s.attachShader(r, i), s.attachShader(r, n), s.linkProgram(r), !s.getProgramParameter(r, s.LINK_STATUS)) {
1362
+ const c = s.getProgramInfoLog(r);
1363
+ throw new Error("Unable to link shader program: " + c);
1347
1364
  }
1348
- return i;
1365
+ return r;
1349
1366
  };
1350
- function it(s, t) {
1367
+ function J(s, t) {
1351
1368
  const e = {
1352
- [$.CLAMP]: s.CLAMP_TO_EDGE,
1353
- [$.REPEAT]: s.REPEAT,
1354
- [$.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1369
+ [Y.CLAMP]: s.CLAMP_TO_EDGE,
1370
+ [Y.REPEAT]: s.REPEAT,
1371
+ [Y.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1355
1372
  }[t] || s.CLAMP_TO_EDGE;
1356
1373
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, e);
1357
1374
  }
1358
- function rt(s, t) {
1375
+ function tt(s, t) {
1359
1376
  const e = {
1360
- [nt.LINEAR]: s.LINEAR,
1361
- [nt.NEAREST]: s.NEAREST
1377
+ [rt.LINEAR]: s.LINEAR,
1378
+ [rt.NEAREST]: s.NEAREST
1362
1379
  }[t] ?? s.NEAREST;
1363
1380
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, e);
1364
1381
  }
1365
- function Q(s, t, e) {
1366
- const i = s.gl, r = i.createTexture();
1367
- if (!r)
1382
+ function K(s, t, e) {
1383
+ const r = s.gl, i = r.createTexture();
1384
+ if (!i)
1368
1385
  throw new Error("Unable to create WebGL texture");
1369
- if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1), it(i, e.wrap ?? $.CLAMP), rt(i, e.textureFilter ?? s.textureFilter), e.onlySize) {
1386
+ if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), J(r, e.wrap ?? Y.CLAMP), tt(r, e.textureFilter ?? s.textureFilter), e.onlySize) {
1370
1387
  const n = t;
1371
- i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, n.width, n.height, 0, i.RGBA, i.UNSIGNED_BYTE, null);
1388
+ r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, n.width, n.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
1372
1389
  } else {
1373
1390
  const n = e.premultipliedAlpha ?? s.premultipliedAlpha;
1374
- n && i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, i.RGBA, i.UNSIGNED_BYTE, t), n && i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
1391
+ n && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !0), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, t), n && r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1);
1375
1392
  }
1376
- return i.bindTexture(i.TEXTURE_2D, null), r;
1393
+ return r.bindTexture(r.TEXTURE_2D, null), i;
1377
1394
  }
1378
1395
  function F(s, t) {
1379
1396
  if (s.includes("%TEXTURE_NUM%") && (s = s.replace("%TEXTURE_NUM%", t.toString())), s.includes("%GET_COLOR%")) {
1380
1397
  let e = "";
1381
- for (let i = 0; i < t; i++)
1382
- i == 0 ? e += `if(vTextureId == ${i})` : i == t - 1 ? e += "else" : e += `else if(vTextureId == ${i})`, e += `{return texture(uTextures[${i}], uv) * vColor;}`;
1398
+ for (let r = 0; r < t; r++)
1399
+ r == 0 ? e += `if(vTextureId == ${r})` : r == t - 1 ? e += "else" : e += `else if(vTextureId == ${r})`, e += `{return texture(uTextures[${r}], uv);}`;
1383
1400
  s = s.replace("%GET_COLOR%", e);
1384
1401
  }
1385
1402
  return s;
1386
1403
  }
1387
- const Lt = 5126, st = 5121;
1388
- function It(s, t, e) {
1404
+ const Nt = 5126, et = 5121;
1405
+ function Lt(s, t, e) {
1389
1406
  s.vertexAttribDivisor(t, e);
1390
1407
  }
1391
- function Tt(s, t, e, i, r) {
1392
- s.drawArraysInstanced(t, e, i, r);
1408
+ function vt(s, t, e, r, i) {
1409
+ s.drawArraysInstanced(t, e, r, i);
1393
1410
  }
1394
1411
  let Ot = 0;
1395
- class yt {
1412
+ class Tt {
1396
1413
  program;
1397
1414
  attributeLoc = {};
1398
1415
  uniformLoc = {};
@@ -1407,8 +1424,8 @@ class yt {
1407
1424
  shaderId = Ot++;
1408
1425
  // for debug
1409
1426
  vao;
1410
- constructor(t, e, i, r) {
1411
- this.gl = t, this.program = Nt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
1427
+ constructor(t, e, r, i) {
1428
+ this.gl = t, this.program = Pt(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
1412
1429
  }
1413
1430
  /** Switch GPU to use this shader program */
1414
1431
  use() {
@@ -1431,10 +1448,10 @@ class yt {
1431
1448
  * shader.setUniform("uMVP", mat4array);
1432
1449
  */
1433
1450
  setUniform(t, e) {
1434
- const i = this.uniformLoc[t];
1435
- if (i === void 0) return;
1436
- const r = this.uniformType[t], n = this.uniformIsArray[t];
1437
- Wt(this.gl, i, r, e, n);
1451
+ const r = this.uniformLoc[t];
1452
+ if (r === void 0) return;
1453
+ const i = this.uniformType[t], n = this.uniformIsArray[t];
1454
+ It(this.gl, r, i, e, n);
1438
1455
  }
1439
1456
  /**
1440
1457
  * Batch-set uniforms via a plain value map.
@@ -1457,15 +1474,15 @@ class yt {
1457
1474
  setAttribute(t) {
1458
1475
  const e = this.attributeLoc[t.name];
1459
1476
  if (e === void 0) return;
1460
- const i = this.gl;
1461
- i.vertexAttribPointer(
1477
+ const r = this.gl;
1478
+ r.vertexAttribPointer(
1462
1479
  e,
1463
1480
  t.size,
1464
- t.type ?? Lt,
1481
+ t.type ?? Nt,
1465
1482
  t.normalized ?? !1,
1466
1483
  t.stride,
1467
1484
  t.offset ?? 0
1468
- ), i.enableVertexAttribArray(e), It(i, e, t.divisor ?? 0);
1485
+ ), r.enableVertexAttribArray(e), Lt(r, e, t.divisor ?? 0);
1469
1486
  }
1470
1487
  /** Bind all vertex attribute pointers at once */
1471
1488
  setAttributes(t) {
@@ -1479,79 +1496,79 @@ class yt {
1479
1496
  }
1480
1497
  /** Parse attribute/uniform names and GLSL types from raw shader source */
1481
1498
  parseShader(t) {
1482
- const e = this.gl, i = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
1483
- if (i)
1484
- for (const n of i) {
1485
- const o = n.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
1486
- h !== -1 && (this.attributeLoc[o] = h);
1487
- }
1488
- const r = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
1499
+ const e = this.gl, r = t.match(/(?:in|attribute)\s+\w+\s+\w+/g);
1489
1500
  if (r)
1490
1501
  for (const n of r) {
1491
- const a = n.split(/\s+/), o = a[1], h = a[2].replace(/\[\d+\]$/, ""), c = e.getUniformLocation(this.program, h);
1492
- c !== null && (this.uniformLoc[h] = c, this.uniformType[h] = o, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
1502
+ const c = n.split(/\s+/)[2], h = e.getAttribLocation(this.program, c);
1503
+ h !== -1 && (this.attributeLoc[c] = h);
1504
+ }
1505
+ const i = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
1506
+ if (i)
1507
+ for (const n of i) {
1508
+ const a = n.split(/\s+/), c = a[1], h = a[2].replace(/\[\d+\]$/, ""), o = e.getUniformLocation(this.program, h);
1509
+ o !== null && (this.uniformLoc[h] = o, this.uniformType[h] = c, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
1493
1510
  }
1494
1511
  }
1495
1512
  }
1496
- function Wt(s, t, e, i, r = !1) {
1513
+ function It(s, t, e, r, i = !1) {
1497
1514
  switch (e) {
1498
1515
  // scalars
1499
1516
  case "float":
1500
- return s.uniform1f(t, i);
1517
+ return s.uniform1f(t, r);
1501
1518
  case "int":
1502
1519
  case "bool":
1503
1520
  case "sampler2D":
1504
1521
  case "samplerCube":
1505
- return r ? s.uniform1iv(t, i) : s.uniform1i(t, i);
1522
+ return i ? s.uniform1iv(t, r) : s.uniform1i(t, r);
1506
1523
  // float vectors
1507
1524
  case "vec2":
1508
- return s.uniform2fv(t, i);
1525
+ return s.uniform2fv(t, r);
1509
1526
  case "vec3":
1510
- return s.uniform3fv(t, i);
1527
+ return s.uniform3fv(t, r);
1511
1528
  case "vec4":
1512
- return s.uniform4fv(t, i);
1529
+ return s.uniform4fv(t, r);
1513
1530
  // int / bool vectors
1514
1531
  case "ivec2":
1515
1532
  case "bvec2":
1516
- return s.uniform2iv(t, i);
1533
+ return s.uniform2iv(t, r);
1517
1534
  case "ivec3":
1518
1535
  case "bvec3":
1519
- return s.uniform3iv(t, i);
1536
+ return s.uniform3iv(t, r);
1520
1537
  case "ivec4":
1521
1538
  case "bvec4":
1522
- return s.uniform4iv(t, i);
1539
+ return s.uniform4iv(t, r);
1523
1540
  // matrices (column-major, transpose = false)
1524
1541
  case "mat2":
1525
- return s.uniformMatrix2fv(t, !1, i);
1542
+ return s.uniformMatrix2fv(t, !1, r);
1526
1543
  case "mat3":
1527
- return s.uniformMatrix3fv(t, !1, i);
1544
+ return s.uniformMatrix3fv(t, !1, r);
1528
1545
  case "mat4":
1529
- return s.uniformMatrix4fv(t, !1, i);
1546
+ return s.uniformMatrix4fv(t, !1, r);
1530
1547
  // fallback: guess by value shape
1531
1548
  default:
1532
- return Ft(s, t, i);
1549
+ return Wt(s, t, r);
1533
1550
  }
1534
1551
  }
1535
- function Ft(s, t, e) {
1552
+ function Wt(s, t, e) {
1536
1553
  if (typeof e == "number")
1537
1554
  return s.uniform1f(t, e);
1538
- const i = e;
1539
- switch (i.length) {
1555
+ const r = e;
1556
+ switch (r.length) {
1540
1557
  case 2:
1541
- return s.uniform2fv(t, i);
1558
+ return s.uniform2fv(t, r);
1542
1559
  case 3:
1543
- return s.uniform3fv(t, i);
1560
+ return s.uniform3fv(t, r);
1544
1561
  case 4:
1545
- return s.uniform4fv(t, i);
1562
+ return s.uniform4fv(t, r);
1546
1563
  case 9:
1547
- return s.uniformMatrix3fv(t, !1, i);
1564
+ return s.uniformMatrix3fv(t, !1, r);
1548
1565
  case 16:
1549
- return s.uniformMatrix4fv(t, !1, i);
1566
+ return s.uniformMatrix4fv(t, !1, r);
1550
1567
  default:
1551
- return s.uniform1fv(t, i);
1568
+ return s.uniform1fv(t, r);
1552
1569
  }
1553
1570
  }
1554
- class ut {
1571
+ class ot {
1555
1572
  /** Custom vertex shader code */
1556
1573
  vs;
1557
1574
  /** Custom fragment shader code */
@@ -1569,8 +1586,8 @@ class ut {
1569
1586
  /** Padding in pixels this shader needs beyond the sprite bounds (for outline/glow effects) */
1570
1587
  padding = 0;
1571
1588
  rapid;
1572
- constructor(t, e, i, r = 0, n) {
1573
- this.vs = e, this.fs = i, this.rapid = t, this.uniforms = n ?? {}, this.usedTextureUnitNum = r;
1589
+ constructor(t, e, r, i = 0, n) {
1590
+ this.vs = e, this.fs = r, this.rapid = t, this.uniforms = n ?? {}, this.usedTextureUnitNum = i;
1574
1591
  }
1575
1592
  /**
1576
1593
  * Updates uniform values or textures for the custom shader.
@@ -1578,12 +1595,12 @@ class ut {
1578
1595
  */
1579
1596
  setUniforms(t) {
1580
1597
  this.rapid.flush();
1581
- const e = {}, i = {};
1582
- for (const [r, n] of Object.entries(t))
1583
- n instanceof WebGLTexture ? i[r] = n : e[r] = n;
1584
- Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, i);
1585
- for (const r of this.glshader.keys())
1586
- this.uniformDirty.add(r);
1598
+ const e = {}, r = {};
1599
+ for (const [i, n] of Object.entries(t))
1600
+ n instanceof WebGLTexture ? r[i] = n : e[i] = n;
1601
+ Object.assign(this.uniforms, e), Object.assign(this.uniformTextures, r);
1602
+ for (const i of this.glshader.keys())
1603
+ this.uniformDirty.add(i);
1587
1604
  }
1588
1605
  /**
1589
1606
  * Sets the padding (in pixels) for this shader and propagates to all compiled GLShaders.
@@ -1602,8 +1619,8 @@ class ut {
1602
1619
  * @param textureUniforms Map of texture uniform names to assigned texture unit indices.
1603
1620
  */
1604
1621
  applyUniform(t, e) {
1605
- const i = this.glshader.get(t);
1606
- i && (Object.keys(e).length > 0 && i.setUniforms(e), this.uniformDirty.has(t) && (i.setUniforms(this.uniforms), this.uniformDirty.delete(t)));
1622
+ const r = this.glshader.get(t);
1623
+ r && (Object.keys(e).length > 0 && r.setUniforms(e), this.uniformDirty.has(t) && (r.setUniforms(this.uniforms), this.uniformDirty.delete(t)));
1607
1624
  }
1608
1625
  /**
1609
1626
  * Retrieves or compiles a customized GLShader for a specific region.
@@ -1613,18 +1630,17 @@ class ut {
1613
1630
  * @param baseFS The base fragment shader template.
1614
1631
  * @returns The combined and compiled GLShader.
1615
1632
  */
1616
- getGLShader(t, e, i, r) {
1633
+ getGLShader(t, e, r, i) {
1617
1634
  if (this.glshader.has(e))
1618
1635
  return this.glshader.get(e);
1619
- if (r == null || i == null)
1636
+ if (i == null || r == null)
1620
1637
  return console.warn("CustomGlShader: missing base shader for " + e), null;
1621
- i = i.replace("// CUSTOM_CODE_CALL", "vertex(position, vRegion);"), r = r.replace("// CUSTOM_CODE_CALL", "fragment(fragColor);"), i = i.replace("// CUSTOM_CODE", this.vs), r = r.replace("// CUSTOM_CODE", this.fs);
1622
- const n = t.createShader(i, r);
1638
+ 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);
1639
+ const n = t.createShader(r, i);
1623
1640
  return n.isCustom = !0, n.padding = this.padding, this.glshader.set(e, n), this.uniformDirty.add(e), n;
1624
1641
  }
1625
1642
  }
1626
- const q = 1 / 0;
1627
- class Rt {
1643
+ class yt {
1628
1644
  constructor(t) {
1629
1645
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
1630
1646
  }
@@ -1654,20 +1670,20 @@ class Rt {
1654
1670
  (t, e) => e
1655
1671
  );
1656
1672
  }
1657
- findTextureUnit(t, e = 0, i = 0) {
1658
- for (let r = 0; r < this.usedTextures.length; r++) {
1659
- const n = r * 2;
1660
- if (this.usedTextures[r] === t && this.usedTexturePadding[n] === e && this.usedTexturePadding[n + 1] === i)
1661
- return r;
1673
+ findTextureUnit(t, e = 0, r = 0) {
1674
+ for (let i = 0; i < this.usedTextures.length; i++) {
1675
+ const n = i * 2;
1676
+ if (this.usedTextures[i] === t && this.usedTexturePadding[n] === e && this.usedTexturePadding[n + 1] === r)
1677
+ return i;
1662
1678
  }
1663
1679
  return -1;
1664
1680
  }
1665
- useTexture(t, e = 0, i = 0) {
1666
- const r = this.findTextureUnit(t, e, i);
1667
- return r == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(i), this.usedTextures.length - 1) : r;
1681
+ useTexture(t, e = 0, r = 0) {
1682
+ const i = this.findTextureUnit(t, e, r);
1683
+ 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;
1668
1684
  }
1669
1685
  createShader(t, e) {
1670
- return new yt(this.gl, t, e);
1686
+ return new Tt(this.gl, t, e);
1671
1687
  }
1672
1688
  createCustomShader(t) {
1673
1689
  return t.getGLShader(this, this.KEY, this.vs, this.fs);
@@ -1675,7 +1691,7 @@ class Rt {
1675
1691
  getCustomShader(t) {
1676
1692
  if (!t)
1677
1693
  return this.defaultShader;
1678
- if (t instanceof ut) {
1694
+ if (t instanceof ot) {
1679
1695
  const e = this.createCustomShader(t);
1680
1696
  return e ?? this.defaultShader;
1681
1697
  }
@@ -1690,7 +1706,7 @@ class Rt {
1690
1706
  return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
1691
1707
  }
1692
1708
  enter(t) {
1693
- 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);
1709
+ this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ot ? (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);
1694
1710
  }
1695
1711
  exit() {
1696
1712
  this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
@@ -1699,22 +1715,25 @@ class Rt {
1699
1715
  this.render(), this.resetRender();
1700
1716
  }
1701
1717
  render() {
1718
+ this.prepareRender();
1719
+ }
1720
+ prepareRender() {
1702
1721
  const t = this.currentShader;
1703
1722
  if (t.use(), this.customShader) {
1704
- const i = this.customShader, r = {};
1705
- for (const n in i.uniformTextures)
1706
- r[n] = this.useTexture(i.uniformTextures[n]);
1707
- this.customShader.applyUniform(this.KEY, r);
1723
+ const r = this.customShader, i = {};
1724
+ for (const n in r.uniformTextures)
1725
+ i[n] = this.useTexture(r.uniformTextures[n]);
1726
+ this.customShader.applyUniform(this.KEY, i);
1708
1727
  }
1709
1728
  const e = this.gl;
1710
- for (let i = 0; i < this.usedTextures.length; i++)
1711
- e.activeTexture(e.TEXTURE0 + i), e.bindTexture(e.TEXTURE_2D, this.usedTextures[i]);
1729
+ for (let r = 0; r < this.usedTextures.length; r++)
1730
+ e.activeTexture(e.TEXTURE0 + r), e.bindTexture(e.TEXTURE_2D, this.usedTextures[r]);
1712
1731
  t.setUniform("uTextures", Int32Array.from(
1713
1732
  { length: this.usedTextures.length },
1714
- (i, r) => r
1733
+ (r, i) => i
1715
1734
  )), t.setUniform("uPadding", Float32Array.from(
1716
1735
  { length: this.usedTexturePadding.length },
1717
- (i, r) => this.usedTexturePadding[r]
1736
+ (r, i) => this.usedTexturePadding[i]
1718
1737
  ));
1719
1738
  }
1720
1739
  resetRender() {
@@ -1724,8 +1743,8 @@ class Rt {
1724
1743
  return !1;
1725
1744
  }
1726
1745
  }
1727
- const Z = `#version 300 es\r
1728
- precision mediump float;\r
1746
+ const $ = `#version 300 es\r
1747
+ precision highp float;\r
1729
1748
  \r
1730
1749
  // per-vertex\r
1731
1750
  in vec2 aVertex;\r
@@ -1772,7 +1791,7 @@ void main(void) {\r
1772
1791
  \r
1773
1792
  gl_Position = u_projection * position;\r
1774
1793
  }\r
1775
- `, lt = `#version 300 es\r
1794
+ `, ct = `#version 300 es\r
1776
1795
  precision mediump float;\r
1777
1796
  \r
1778
1797
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1812,7 +1831,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
1812
1831
  // CUSTOM_CODE\r
1813
1832
  \r
1814
1833
  void main(void) {\r
1815
- fragColor = sampleTexture(vRegion);\r
1834
+ fragColor = sampleTexture(vRegion) * vColor;\r
1816
1835
  // if (vPadding.x != 0.0) {\r
1817
1836
  // if (clampUV(vRegion)) {\r
1818
1837
  // fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
@@ -1821,8 +1840,8 @@ void main(void) {\r
1821
1840
  \r
1822
1841
  // CUSTOM_CODE_CALL\r
1823
1842
  }\r
1824
- `, z = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1825
- class at extends Rt {
1843
+ `, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1844
+ class it extends yt {
1826
1845
  instanceBuffer;
1827
1846
  quadBuffer;
1828
1847
  instanceCount = 0;
@@ -1834,29 +1853,29 @@ class at extends Rt {
1834
1853
  }
1835
1854
  createBuffer() {
1836
1855
  const t = this.gl;
1837
- this.quadBuffer = new et(t, L.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1838
- for (const e of Dt) this.quadBuffer.pushFloat32(e);
1839
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, L.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1856
+ this.quadBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1857
+ for (const e of Ft) this.quadBuffer.pushFloat32(e);
1858
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, I.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1840
1859
  }
1841
1860
  createDefaultShader() {
1842
- const t = this.rapid, e = F(lt, t.maxTextureUnits), i = F(Z, t.maxTextureUnits);
1843
- return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
1861
+ const t = this.rapid, e = F(ct, t.maxTextureUnits), r = F($, t.maxTextureUnits);
1862
+ return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1844
1863
  }
1845
1864
  createShader(t, e) {
1846
- const i = super.createShader(t, e);
1847
- return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
1848
- { name: "aMatrixRow0", size: 3, stride: z, offset: 0, divisor: 1 },
1849
- { name: "aMatrixRow1", size: 3, stride: z, offset: 12, divisor: 1 },
1850
- { name: "aUVRect", size: 4, stride: z, offset: 24, divisor: 1 },
1851
- { name: "aColor", size: 4, type: st, normalized: !0, stride: z, offset: 40, divisor: 1 },
1852
- { name: "aTextureId", size: 1, type: st, stride: z, offset: 44, divisor: 1 }
1853
- ]), this.quadBuffer.bindBuffer(), i.setAttributes([
1865
+ const r = super.createShader(t, e);
1866
+ return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1867
+ { name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
1868
+ { name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
1869
+ { name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
1870
+ { name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
1871
+ { name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
1872
+ ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1854
1873
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1855
- ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1874
+ ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1856
1875
  }
1857
1876
  createCustomShader(t) {
1858
- const e = F(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1859
- return t.getGLShader(this, this.KEY, i, e);
1877
+ const e = F(ct, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = F($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1878
+ return t.getGLShader(this, this.KEY, r, e);
1860
1879
  }
1861
1880
  /**
1862
1881
  * Draws a textured sprite via instanced rendering to significantly improve performance.
@@ -1870,46 +1889,45 @@ class at extends Rt {
1870
1889
  * @param v1 Bottom UV mapped coordinate (default 1).
1871
1890
  * @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
1872
1891
  */
1873
- drawSprite(t, e, i = 0, r = 0, n = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, f = !1, l = !1) {
1874
- const p = e * 6, x = this.matrixStore.data;
1892
+ drawSprite(t, e, r = 0, i = 0, n = 1, a = 1, c = 4294967295, h = 0, o = 0, u = !1, l = !1, d = !1) {
1893
+ const f = e * 6, x = this.matrixStore.data;
1875
1894
  this.drawSpriteAffine(
1876
1895
  t,
1877
- x[p],
1878
- x[p + 1],
1879
- x[p + 2],
1880
- x[p + 3],
1881
- x[p + 4],
1882
- x[p + 5],
1883
- i,
1896
+ x[f],
1897
+ x[f + 1],
1898
+ x[f + 2],
1899
+ x[f + 3],
1900
+ x[f + 4],
1901
+ x[f + 5],
1884
1902
  r,
1903
+ i,
1885
1904
  n,
1886
1905
  a,
1887
- o,
1888
- h,
1889
1906
  c,
1907
+ h,
1908
+ o,
1890
1909
  u,
1891
- f,
1892
- l
1910
+ l,
1911
+ d
1893
1912
  );
1894
1913
  }
1895
- drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, v = !1, R = !1, T = !1) {
1896
- this.instanceCount > q && this.flush();
1897
- const g = t.base, w = t.scale ?? 1, b = t.rawWidth, A = t.rawHeight, I = t.offsetX, Y = t.offsetY, N = this.useTexture(
1914
+ drawSpriteAffine(t, e, r, i, n, a, c, h = 0, o = 0, u = 1, l = 1, d = 4294967295, f = 0, x = 0, g = !1, v = !1, T = !1) {
1915
+ const R = t.base, E = t.scale ?? 1, b = t.rawWidth, N = t.rawHeight, W = t.offsetX, L = t.offsetY, S = this.useTexture(
1898
1916
  t.glTexture,
1899
- p / w / g.width,
1900
- x / w / g.height
1901
- ), U = this.instanceBuffer, y = U.usedElemNum;
1902
- U.resize(12);
1903
- const M = U.float32, D = U.uint32, O = (T ? A : b) * w, W = (T ? b : A) * w, H = O + 2 * p, V = W + 2 * x, ht = I - p, ot = Y - x, S = this.localSpriteMatrix;
1904
- T ? (S[0] = 0, S[1] = R ? V : -V, S[2] = v ? -H : H, S[3] = 0, S[4] = ht + (v ? H : 0), S[5] = ot + (R ? 0 : V)) : (S[0] = v ? -H : H, S[1] = 0, S[2] = 0, S[3] = R ? -V : V, S[4] = ht + (v ? H : 0), S[5] = ot + (R ? V : 0));
1917
+ f / E / R.width,
1918
+ x / E / R.height
1919
+ ), w = this.instanceBuffer, A = w.usedElemNum;
1920
+ w.resize(12);
1921
+ const U = w.float32, O = w.uint32, j = (T ? N : b) * E, q = (T ? b : N) * E, G = j + 2 * f, H = q + 2 * x, nt = W - f, at = L - x, M = this.localSpriteMatrix;
1922
+ T ? (M[0] = 0, M[1] = v ? H : -H, M[2] = g ? -G : G, M[3] = 0, M[4] = nt + (g ? G : 0), M[5] = at + (v ? 0 : H)) : (M[0] = g ? -G : G, M[1] = 0, M[2] = 0, M[3] = v ? -H : H, M[4] = nt + (g ? G : 0), M[5] = at + (v ? H : 0));
1905
1923
  const _ = this.worldSpriteMatrix;
1906
- _[0] = e * S[0] + r * S[1], _[1] = i * S[0] + n * S[1], _[2] = e * S[2] + r * S[3], _[3] = i * S[2] + n * S[3], _[4] = a + e * S[4] + r * S[5], _[5] = o + i * S[4] + n * S[5], M[y + 6] = h, M[y + 7] = c, M[y + 8] = u, M[y + 9] = f, D[y + 10] = l, D[y + 11] = N, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), M[y] = _[0], M[y + 1] = _[2], M[y + 2] = _[4], M[y + 3] = _[1], M[y + 4] = _[3], M[y + 5] = _[5], U.usedElemNum += 12, U.makeDirty(), this.instanceCount++;
1924
+ _[0] = e * M[0] + i * M[1], _[1] = r * M[0] + n * M[1], _[2] = e * M[2] + i * M[3], _[3] = r * M[2] + n * M[3], _[4] = a + e * M[4] + i * M[5], _[5] = c + r * M[4] + n * M[5], U[A + 6] = h, U[A + 7] = o, U[A + 8] = u, U[A + 9] = l, O[A + 10] = d, O[A + 11] = S, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), U[A] = _[0], U[A + 1] = _[2], U[A + 2] = _[4], U[A + 3] = _[1], U[A + 4] = _[3], U[A + 5] = _[5], w.usedElemNum += 12, w.makeDirty(), this.instanceCount++;
1907
1925
  }
1908
1926
  render() {
1909
1927
  if (this.instanceCount === 0) return;
1910
- super.render();
1928
+ this.prepareRender();
1911
1929
  const t = this.gl, e = this.currentShader;
1912
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Tt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1930
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1913
1931
  }
1914
1932
  resetRender() {
1915
1933
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1918,8 +1936,8 @@ class at extends Rt {
1918
1936
  return this.instanceCount > 0;
1919
1937
  }
1920
1938
  }
1921
- const Bt = `#version 300 es\r
1922
- precision mediump float;\r
1939
+ const Dt = `#version 300 es\r
1940
+ precision highp float;\r
1923
1941
  \r
1924
1942
  in vec2 aPosition;\r
1925
1943
  in vec4 aColor;\r
@@ -1949,7 +1967,7 @@ void main(void) {\r
1949
1967
  // CUSTOM_CODE_CALL\r
1950
1968
  gl_Position = u_projection * position;\r
1951
1969
  }\r
1952
- `, kt = `#version 300 es\r
1970
+ `, Bt = `#version 300 es\r
1953
1971
  precision mediump float;\r
1954
1972
  \r
1955
1973
  in vec4 vColor;\r
@@ -1969,9 +1987,9 @@ bool clampUV(vec2 uv) {\r
1969
1987
  \r
1970
1988
  vec4 sampleTexture(vec2 uv) {\r
1971
1989
  if (uUseTexture > 0) {\r
1972
- return texture(uTexture, uv) * vColor;\r
1990
+ return texture(uTexture, uv);\r
1973
1991
  }\r
1974
- return vColor;\r
1992
+ return vec4(1,1,1,1);\r
1975
1993
  }\r
1976
1994
  \r
1977
1995
  vec4 sampleClampTexture(vec2 uv) {\r
@@ -1992,11 +2010,11 @@ vec4 sampleTextureLocal(vec2 uv) {\r
1992
2010
  // CUSTOM_CODE\r
1993
2011
  \r
1994
2012
  void main(void) {\r
1995
- fragColor = sampleTexture(vRegion);\r
2013
+ fragColor = sampleTexture(vRegion) * vColor;\r
1996
2014
  // CUSTOM_CODE_CALL\r
1997
2015
  }\r
1998
- `, Gt = `#version 300 es\r
1999
- precision mediump float;\r
2016
+ `, kt = `#version 300 es\r
2017
+ precision highp float;\r
2000
2018
  \r
2001
2019
  in vec2 aPosition;\r
2002
2020
  in vec2 aUV;\r
@@ -2018,7 +2036,7 @@ void main(void) {\r
2018
2036
  );\r
2019
2037
  gl_Position = u_projection * position;\r
2020
2038
  }\r
2021
- `, Ht = `#version 300 es\r
2039
+ `, Gt = `#version 300 es\r
2022
2040
  precision mediump float;\r
2023
2041
  \r
2024
2042
  in vec2 vRegion;\r
@@ -2038,8 +2056,8 @@ void main(void) {\r
2038
2056
  discard;\r
2039
2057
  }\r
2040
2058
  }\r
2041
- `, X = 20;
2042
- class Vt extends Rt {
2059
+ `, z = 20;
2060
+ class Ht extends yt {
2043
2061
  vertexBuffer;
2044
2062
  vertexCount = 0;
2045
2063
  matrixIndex = -1;
@@ -2052,25 +2070,25 @@ class Vt extends Rt {
2052
2070
  }
2053
2071
  createBuffer() {
2054
2072
  const t = this.gl;
2055
- this.vertexBuffer = new et(t, L.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Ht);
2073
+ this.vertexBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
2056
2074
  }
2057
2075
  createDefaultShader() {
2058
- return this.vs = Bt, this.fs = kt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2076
+ return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2059
2077
  }
2060
2078
  createMaskShader(t, e) {
2061
- const i = this.gl, r = new yt(i, t, e);
2062
- return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2063
- { name: "aPosition", size: 2, type: i.FLOAT, stride: X - 4, offset: 0, divisor: 0 },
2064
- { name: "aUV", size: 2, type: i.FLOAT, stride: X - 4, offset: 8, divisor: 0 }
2065
- ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2079
+ const r = this.gl, i = new Tt(r, t, e);
2080
+ return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
2081
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: z - 4, offset: 0, divisor: 0 },
2082
+ { name: "aUV", size: 2, type: r.FLOAT, stride: z - 4, offset: 8, divisor: 0 }
2083
+ ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2066
2084
  }
2067
2085
  createShader(t, e) {
2068
- const i = this.gl, r = super.createShader(t, e);
2069
- return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2070
- { name: "aPosition", size: 2, type: i.FLOAT, stride: X, offset: 0, divisor: 0 },
2071
- { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: X, offset: 8, divisor: 0 },
2072
- { name: "aUV", size: 2, type: i.FLOAT, stride: X, offset: 12, divisor: 0 }
2073
- ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2086
+ const r = this.gl, i = super.createShader(t, e);
2087
+ return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
2088
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: z, offset: 0, divisor: 0 },
2089
+ { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: z, offset: 8, divisor: 0 },
2090
+ { name: "aUV", size: 2, type: r.FLOAT, stride: z, offset: 12, divisor: 0 }
2091
+ ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2074
2092
  }
2075
2093
  /**
2076
2094
  * Begins a new polygon drawing sequence. Must be followed by addVertex() calls and endGraphic().
@@ -2078,8 +2096,8 @@ class Vt extends Rt {
2078
2096
  * @param drawMode The WebGL drawing primitive mode (e.g., gl.TRIANGLES).
2079
2097
  * @param texture Optional texture to apply over the polygon.
2080
2098
  */
2081
- startGraphic(t, e = this.gl.TRIANGLES, i) {
2082
- this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture = i, this.texture?.glTexture && this.useTexture(this.texture.glTexture, 0, 0);
2099
+ startGraphic(t, e = this.gl.TRIANGLES, r) {
2100
+ this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture = r, this.texture?.glTexture && this.useTexture(this.texture.glTexture, 0, 0);
2083
2101
  }
2084
2102
  /**
2085
2103
  * Adds a vertex to the current polygon. Local coordinates and color settings.
@@ -2089,9 +2107,9 @@ class Vt extends Rt {
2089
2107
  * @param v UV mapped Y value (0-1, default 0).
2090
2108
  * @param color Pre-multiplied hex color combined using ABGR byte order (default 0xFFFFFFFF).
2091
2109
  */
2092
- addVertex(t, e, i = 0, r = 0, n = 4294967295) {
2110
+ addVertex(t, e, r = 0, i = 0, n = 4294967295) {
2093
2111
  const a = this.vertexBuffer;
2094
- a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(n), a.pushFloat32(i), a.pushFloat32(r), this.vertexCount++, this.vertexBuffer.makeDirty();
2112
+ a.pushFloat32(t), a.pushFloat32(e), this.currentShader != this.maskShader && a.pushUint32(n), a.pushFloat32(r), a.pushFloat32(i), this.vertexCount++, this.vertexBuffer.makeDirty();
2095
2113
  }
2096
2114
  /**
2097
2115
  * Finishes the graphic construction and dispatches the rendering call immediately.
@@ -2101,10 +2119,10 @@ class Vt extends Rt {
2101
2119
  }
2102
2120
  render() {
2103
2121
  if (this.vertexCount === 0) return;
2104
- super.render();
2105
- const t = this.gl, e = this.currentShader, i = this.matrixIndex * 6, r = this.matrixStore.data;
2106
- let n = r[i + 4], a = r[i + 5];
2107
- this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r[i], r[i + 2], n]), e.setUniform("uMatrixRow1", [r[i + 1], r[i + 3], a]), e.setUniform(
2122
+ this.prepareRender();
2123
+ const t = this.gl, e = this.currentShader, r = this.matrixIndex * 6, i = this.matrixStore.data;
2124
+ let n = i[r + 4], a = i[r + 5];
2125
+ this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [i[r], i[r + 2], n]), e.setUniform("uMatrixRow1", [i[r + 1], i[r + 3], a]), e.setUniform(
2108
2126
  "uUVRect",
2109
2127
  this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
2110
2128
  ), this.texture?.glTexture ? (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture), e.setUniform("uTexture", 0), e.setUniform("uUseTexture", 1)) : e.setUniform("uUseTexture", 0), this.vertexBuffer.bindBuffer(), this.vertexBuffer.bufferData(), e.bindVAO(), t.drawArrays(this.drawMode, 0, this.vertexCount), this.rapid.drawcallCount++, this.texture = void 0;
@@ -2113,15 +2131,15 @@ class Vt extends Rt {
2113
2131
  return !1;
2114
2132
  }
2115
2133
  }
2116
- class d {
2134
+ class m {
2117
2135
  x;
2118
2136
  y;
2119
- static ZERO = new d(0, 0);
2120
- static ONE = new d(1, 1);
2121
- static UP = new d(0, 1);
2122
- static DOWN = new d(0, -1);
2123
- static LEFT = new d(-1, 0);
2124
- static RIGHT = new d(1, 0);
2137
+ static ZERO = new m(0, 0);
2138
+ static ONE = new m(1, 1);
2139
+ static UP = new m(0, 1);
2140
+ static DOWN = new m(0, -1);
2141
+ static LEFT = new m(-1, 0);
2142
+ static RIGHT = new m(1, 0);
2125
2143
  constructor(t, e) {
2126
2144
  this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
2127
2145
  }
@@ -2129,22 +2147,22 @@ class d {
2129
2147
  return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
2130
2148
  }
2131
2149
  add(t) {
2132
- return new d(this.x + t.x, this.y + t.y);
2150
+ return new m(this.x + t.x, this.y + t.y);
2133
2151
  }
2134
2152
  subtract(t) {
2135
- return new d(this.x - t.x, this.y - t.y);
2153
+ return new m(this.x - t.x, this.y - t.y);
2136
2154
  }
2137
2155
  sub(t) {
2138
- return new d(this.x - t.x, this.y - t.y);
2156
+ return new m(this.x - t.x, this.y - t.y);
2139
2157
  }
2140
2158
  multiply(t) {
2141
- return t instanceof d ? new d(this.x * t.x, this.y * t.y) : new d(this.x * t, this.y * t);
2159
+ return t instanceof m ? new m(this.x * t.x, this.y * t.y) : new m(this.x * t, this.y * t);
2142
2160
  }
2143
2161
  mul(t) {
2144
2162
  return this.multiply(t);
2145
2163
  }
2146
2164
  divide(t) {
2147
- return t instanceof d ? new d(this.x / t.x, this.y / t.y) : new d(this.x / t, this.y / t);
2165
+ return t instanceof m ? new m(this.x / t.x, this.y / t.y) : new m(this.x / t, this.y / t);
2148
2166
  }
2149
2167
  dot(t) {
2150
2168
  return this.x * t.x + this.y * t.y;
@@ -2153,17 +2171,17 @@ class d {
2153
2171
  return this.x * t.y - this.y * t.x;
2154
2172
  }
2155
2173
  distanceTo(t) {
2156
- const e = this.x - t.x, i = this.y - t.y;
2157
- return Math.sqrt(e * e + i * i);
2174
+ const e = this.x - t.x, r = this.y - t.y;
2175
+ return Math.sqrt(e * e + r * r);
2158
2176
  }
2159
2177
  clone() {
2160
- return new d(this.x, this.y);
2178
+ return new m(this.x, this.y);
2161
2179
  }
2162
2180
  to(t) {
2163
2181
  this.x = t.x, this.y = t.y;
2164
2182
  }
2165
2183
  copy() {
2166
- return new d(this.x, this.y);
2184
+ return new m(this.x, this.y);
2167
2185
  }
2168
2186
  equals(t) {
2169
2187
  return t.x == this.x && t.y == this.y;
@@ -2176,7 +2194,7 @@ class d {
2176
2194
  return this.x = -this.x, this.y = -this.y, this;
2177
2195
  }
2178
2196
  inverted() {
2179
- return new d(this.x * -1, this.y * -1);
2197
+ return new m(this.x * -1, this.y * -1);
2180
2198
  }
2181
2199
  length() {
2182
2200
  return Math.sqrt(this.x * this.x + this.y * this.y);
@@ -2190,13 +2208,13 @@ class d {
2190
2208
  }
2191
2209
  normalized() {
2192
2210
  const t = this.length();
2193
- return new d(this.x / t || 0, this.y / t || 0);
2211
+ return new m(this.x / t || 0, this.y / t || 0);
2194
2212
  }
2195
2213
  fix(t = 1e-13) {
2196
2214
  this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
2197
2215
  }
2198
2216
  fixed(t = 1e-13) {
2199
- return new d(
2217
+ return new m(
2200
2218
  Math.abs(this.x) < t ? 0 : this.x,
2201
2219
  Math.abs(this.y) < t ? 0 : this.y
2202
2220
  );
@@ -2205,13 +2223,13 @@ class d {
2205
2223
  return Math.atan2(this.y, this.x);
2206
2224
  }
2207
2225
  abs() {
2208
- return new d(Math.abs(this.x), Math.abs(this.y));
2226
+ return new m(Math.abs(this.x), Math.abs(this.y));
2209
2227
  }
2210
2228
  floor() {
2211
- return new d(Math.floor(this.x), Math.floor(this.y));
2229
+ return new m(Math.floor(this.x), Math.floor(this.y));
2212
2230
  }
2213
2231
  ceil() {
2214
- return new d(Math.ceil(this.x), Math.ceil(this.y));
2232
+ return new m(Math.ceil(this.x), Math.ceil(this.y));
2215
2233
  }
2216
2234
  stringify() {
2217
2235
  return `Vec2(${this.x}, ${this.y})`;
@@ -2232,24 +2250,24 @@ class d {
2232
2250
  return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
2233
2251
  }
2234
2252
  static FromArray(t) {
2235
- return t.map((e) => new d(e[0], e[1]));
2253
+ return t.map((e) => new m(e[0], e[1]));
2236
2254
  }
2237
2255
  static fromAngle(t) {
2238
- return new d(Math.cos(t), Math.sin(t));
2256
+ return new m(Math.cos(t), Math.sin(t));
2239
2257
  }
2240
2258
  }
2241
- const Yt = (s, t) => {
2242
- const [e, i, r, n, a, o] = t, h = new Float32Array([
2259
+ const Vt = (s, t) => {
2260
+ const [e, r, i, n, a, c] = t, h = new Float32Array([
2243
2261
  e,
2244
2262
  n,
2245
2263
  0,
2246
2264
  0,
2247
- i,
2265
+ r,
2248
2266
  a,
2249
2267
  0,
2250
2268
  0,
2251
- r,
2252
- o,
2269
+ i,
2270
+ c,
2253
2271
  1,
2254
2272
  0,
2255
2273
  0,
@@ -2260,230 +2278,220 @@ const Yt = (s, t) => {
2260
2278
  return zt(s, h);
2261
2279
  }, zt = (s, t) => {
2262
2280
  const e = new Float32Array(16);
2263
- for (let i = 0; i < 4; i++)
2264
- for (let r = 0; r < 4; r++) {
2281
+ for (let r = 0; r < 4; r++)
2282
+ for (let i = 0; i < 4; i++) {
2265
2283
  let n = 0;
2266
2284
  for (let a = 0; a < 4; a++)
2267
- n += s[r * 4 + a] * t[a * 4 + i];
2268
- e[r * 4 + i] = n;
2285
+ n += s[i * 4 + a] * t[a * 4 + r];
2286
+ e[i * 4 + r] = n;
2269
2287
  }
2270
2288
  return e;
2271
2289
  };
2272
- var Xt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Xt || {});
2273
- const tt = 10, dt = (s, t, e, i, r, n) => {
2274
- const a = [], o = [], h = i ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new d(t.y, -t.x);
2275
- for (let f = 0; f < tt; f++) {
2276
- const l = f / tt, p = (f + 1) / tt, x = h + l * c, v = h + p * c, R = new d(Math.cos(x) * e, Math.sin(x) * e), T = new d(Math.cos(v) * e, Math.sin(v) * e);
2277
- a.push(s), o.push(new d(r, 0.5)), a.push(s.add(R)), o.push(new d(r + R.dot(u) * n, 0.5 - 0.5 * R.dot(t) / e)), a.push(s.add(T)), o.push(new d(r + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e));
2278
- }
2279
- return { vertices: a, uv: o };
2280
- }, $t = (s, t = !1) => {
2290
+ var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
2291
+ const Z = 10, ut = (s, t, e, r, i, n) => {
2292
+ const a = [], c = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), o = Math.PI, u = new m(t.y, -t.x);
2293
+ for (let l = 0; l < Z; l++) {
2294
+ const d = l / Z, f = (l + 1) / Z, x = h + d * o, g = h + f * o, v = new m(Math.cos(x) * e, Math.sin(x) * e), T = new m(Math.cos(g) * e, Math.sin(g) * e);
2295
+ a.push(s), c.push(new m(i, 0.5)), a.push(s.add(v)), c.push(new m(i + v.dot(u) * n, 0.5 - 0.5 * v.dot(t) / e)), a.push(s.add(T)), c.push(new m(i + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e));
2296
+ }
2297
+ return { vertices: a, uv: c };
2298
+ }, Xt = (s, t = !1) => {
2281
2299
  const e = [];
2282
2300
  if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
2283
- const i = 4, r = 1e-3, n = s.length;
2301
+ const r = 4, i = 1e-3, n = s.length;
2284
2302
  let a = 0;
2285
2303
  if (t)
2286
2304
  for (let h = 0; h < n; h++) {
2287
- const c = s[h], u = s[(h + 1) % n];
2288
- a += c.distanceTo(u);
2305
+ const o = s[h], u = s[(h + 1) % n];
2306
+ a += o.distanceTo(u);
2289
2307
  }
2290
2308
  else
2291
2309
  for (let h = 0; h < n - 1; h++)
2292
2310
  a += s[h].distanceTo(s[h + 1]);
2293
- const o = (h, c, u) => {
2294
- const f = c.subtract(h).normalize(), l = c.subtract(u).normalize(), p = l.dot(f);
2295
- if (p < -1 + r)
2296
- return { normal: f.perpendicular(), miters: 1 };
2311
+ const c = (h, o, u) => {
2312
+ const l = o.subtract(h).normalize(), d = o.subtract(u).normalize(), f = d.dot(l);
2313
+ if (f < -1 + i)
2314
+ return { normal: l.perpendicular(), miters: 1 };
2297
2315
  {
2298
- let x = l.add(f).normalize();
2299
- f.cross(l) < 0 && (x = x.multiply(-1));
2300
- let v = 1 / Math.sqrt((1 - p) / 2);
2301
- return { normal: x, miters: Math.min(v, i) };
2316
+ let x = d.add(l).normalize();
2317
+ l.cross(d) < 0 && (x = x.multiply(-1));
2318
+ let g = 1 / Math.sqrt((1 - f) / 2);
2319
+ return { normal: x, miters: Math.min(g, r) };
2302
2320
  }
2303
2321
  };
2304
2322
  if (t)
2305
2323
  for (let h = 0; h < n; h++) {
2306
- const c = h === 0 ? s[n - 1] : s[h - 1], u = s[h], f = h === n - 1 ? s[0] : s[h + 1];
2307
- e.push(o(c, u, f));
2324
+ const o = h === 0 ? s[n - 1] : s[h - 1], u = s[h], l = h === n - 1 ? s[0] : s[h + 1];
2325
+ e.push(c(o, u, l));
2308
2326
  }
2309
2327
  else
2310
2328
  for (let h = 0; h < n; h++)
2311
2329
  if (h === 0) {
2312
- const c = s[1].subtract(s[0]).normalize();
2313
- e.push({ normal: c.perpendicular(), miters: 1 });
2330
+ const o = s[1].subtract(s[0]).normalize();
2331
+ e.push({ normal: o.perpendicular(), miters: 1 });
2314
2332
  } else if (h === n - 1) {
2315
- const c = s[h].subtract(s[h - 1]).normalize();
2316
- e.push({ normal: c.perpendicular(), miters: 1 });
2333
+ const o = s[h].subtract(s[h - 1]).normalize();
2334
+ e.push({ normal: o.perpendicular(), miters: 1 });
2317
2335
  } else
2318
- e.push(o(s[h - 1], s[h], s[h + 1]));
2336
+ e.push(c(s[h - 1], s[h], s[h + 1]));
2319
2337
  return { normals: e, length: a };
2320
2338
  }, jt = (s) => {
2321
2339
  const t = s.points;
2322
2340
  if (t.length < 2) return { vertices: [], uv: [] };
2323
- const { normals: e, length: i } = $t(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2324
- let c = 0;
2325
- const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
2326
- for (let l = 0; l < f; l++) {
2327
- const p = t[l], x = e[l].normal, v = e[l].miters, R = (l + 1) % t.length, T = t[R], g = e[R].normal, w = e[R].miters, b = p.add(x.multiply(v * r)), A = p.subtract(x.multiply(v * r)), I = T.add(g.multiply(w * r)), Y = T.subtract(g.multiply(w * r)), N = p.distanceTo(T);
2328
- let U = 0, y = 0;
2329
- h === 0 ? (U = c / i, y = (c + N) / i) : (U = c / u, y = U + N / u);
2330
- const M = new d(U, 0), D = new d(U, 1), O = new d(y, 0), W = new d(y, 1);
2331
- n.push(b), a.push(M), n.push(A), a.push(D), n.push(I), a.push(O), n.push(I), a.push(O), n.push(Y), a.push(W), n.push(A), a.push(D), c += N;
2332
- }
2333
- if (o && !s.closed) {
2334
- const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, v = dt(l, p, r, !0, 0, x);
2335
- n.push(...v.vertices), a.push(...v.uv);
2336
- const R = t[t.length - 1], T = e[t.length - 1].normal, g = h === 0 ? 1 : c / u, w = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, b = dt(R, T, r, !1, g, w);
2341
+ const { normals: e, length: r } = Xt(t, s.closed), i = (s.width || 1) / 2, n = [], a = [], c = s.roundCap || !1, h = s.textureMode || 0;
2342
+ let o = 0;
2343
+ const u = s.texture?.rawWidth || 1, l = s.closed ? t.length : t.length - 1;
2344
+ for (let d = 0; d < l; d++) {
2345
+ const f = t[d], x = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, T = t[v], R = e[v].normal, E = e[v].miters, b = f.add(x.multiply(g * i)), N = f.subtract(x.multiply(g * i)), W = T.add(R.multiply(E * i)), L = T.subtract(R.multiply(E * i)), S = f.distanceTo(T);
2346
+ let w = 0, A = 0;
2347
+ h === 0 ? (w = o / r, A = (o + S) / r) : (w = o / u, A = w + S / u);
2348
+ const U = new m(w, 0), O = new m(w, 1), j = new m(A, 0), q = new m(A, 1);
2349
+ n.push(b), a.push(U), n.push(N), a.push(O), n.push(W), a.push(j), n.push(W), a.push(j), n.push(L), a.push(q), n.push(N), a.push(O), o += S;
2350
+ }
2351
+ if (c && !s.closed) {
2352
+ const d = t[0], f = e[0].normal, x = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = ut(d, f, i, !0, 0, x);
2353
+ n.push(...g.vertices), a.push(...g.uv);
2354
+ const v = t[t.length - 1], T = e[t.length - 1].normal, R = h === 0 ? 1 : o / u, E = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, b = ut(v, T, i, !1, R, E);
2337
2355
  n.push(...b.vertices), a.push(...b.uv);
2338
2356
  }
2339
2357
  return { vertices: n, uv: a };
2340
- }, j = (s, t, e, i, r) => {
2341
- s.matrixStack.applyTransform(t, e, i);
2342
- try {
2343
- r();
2344
- } finally {
2345
- t.saveTransform !== !1 && s.matrixStack.restore();
2346
- }
2347
- }, J = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, Et = (s, t) => {
2348
- const e = t.texture;
2349
- if (!e?.base || s.inCreateMask)
2358
+ }, X = (s, t, e, r) => {
2359
+ if (t.customMatrix !== void 0)
2360
+ return t.customMatrix;
2361
+ if (t.modifyStack) {
2362
+ s.matrixStack.applyTransform(
2363
+ t,
2364
+ e,
2365
+ r
2366
+ );
2350
2367
  return;
2351
- const i = e.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
2368
+ } else {
2369
+ const i = s.matrix.temporary;
2370
+ return s.matrixStack.applyTransform(
2371
+ t,
2372
+ e,
2373
+ r,
2374
+ i
2375
+ ), i;
2376
+ }
2377
+ }, st = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, Rt = (s, t, e) => {
2378
+ const r = t.texture;
2379
+ if (!r?.base || s.inCreateMask)
2380
+ return;
2381
+ const i = r.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
2352
2382
  s.enterRegion(i, t.shader);
2353
- let r = e.uvX, n = e.uvY, a = e.uvW, o = e.uvH;
2354
- const h = !!t.flipX, c = !!t.flipY != !!e.flipY;
2355
- let u = t.padding ?? i.currentShader.padding;
2356
- e.isAtlas && (u += Kt);
2357
- const f = r <= a ? u : -u, l = n <= o ? u : -u;
2383
+ let n = r.uvX, a = r.uvY, c = r.uvW, h = r.uvH;
2384
+ const o = !!t.flipX, u = !!t.flipY != !!r.flipY;
2385
+ let l = t.padding ?? i.currentShader.padding;
2386
+ r.isAtlas && (l += $t);
2387
+ const d = n <= c ? l : -l, f = a <= h ? l : -l;
2358
2388
  i.drawSprite(
2359
- e,
2360
- t.customMatrix ?? s.matrixStack.curWorldM,
2361
2389
  r,
2390
+ e ?? t.customMatrix ?? s.matrixStack.curWorldM,
2362
2391
  n,
2363
2392
  a,
2364
- o,
2365
- J(s, t.color),
2366
- f,
2367
- l,
2368
- h,
2369
2393
  c,
2370
- e.isRotated
2371
- );
2372
- }, qt = (s, t) => {
2373
- j(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2374
- Et(s, t);
2375
- });
2376
- }, Zt = (s, t) => {
2377
- const e = s.particleRegion;
2378
- s.enterRegion(e, t.shader);
2379
- const i = t.texture, r = i.uvX, n = i.uvY, a = i.uvW, o = i.uvH;
2380
- e.drawParticle(
2381
- i,
2382
- t.x,
2383
- t.y,
2384
- t.scaleX,
2385
- t.scaleY,
2386
- t.rotation,
2387
- r,
2388
- n,
2389
- a,
2394
+ h,
2395
+ st(s, t.color),
2396
+ d,
2397
+ f,
2390
2398
  o,
2391
- J(s, t.color),
2392
- t.flipX,
2393
- t.flipY,
2394
- t.isRotated,
2395
- t.originX,
2396
- t.originY
2399
+ u,
2400
+ r.isRotated
2397
2401
  );
2398
- }, Qt = (s, t) => {
2402
+ }, Kt = (s, t) => {
2403
+ const e = X(s, t, t.texture.rawWidth, t.texture.rawHeight);
2404
+ Rt(s, t, e);
2405
+ }, qt = (s, t) => {
2399
2406
  const e = s.particleRegion;
2400
2407
  s.enterRegion(e, t.shader);
2401
- const i = t.texture, r = t.count ?? t.x.length, n = t.color, a = n.length, o = new Array(a);
2408
+ const r = t.texture, i = t.count ?? t.x.length, n = t.color, a = n.length, c = new Array(a);
2402
2409
  if (s.premultipliedAlpha)
2403
2410
  for (let h = 0; h < a; h++)
2404
- o[h] = n[h].premultipliedUint32;
2411
+ c[h] = n[h].premultipliedUint32;
2405
2412
  else
2406
2413
  for (let h = 0; h < a; h++)
2407
- o[h] = n[h].uint32;
2414
+ c[h] = n[h].uint32;
2408
2415
  e.drawParticles(
2409
- i,
2416
+ r,
2410
2417
  t.x,
2411
2418
  t.y,
2412
2419
  t.rotation,
2413
- o,
2414
- r,
2420
+ c,
2421
+ i,
2415
2422
  t.scaleX,
2416
2423
  t.scaleY,
2417
- i.uvX,
2418
- i.uvY,
2419
- i.uvW,
2420
- i.uvH,
2424
+ r.uvX,
2425
+ r.uvY,
2426
+ r.uvW,
2427
+ r.uvH,
2421
2428
  t.flipX,
2422
2429
  t.flipY,
2423
2430
  t.isRotated,
2424
2431
  t.originX,
2425
2432
  t.originY
2426
2433
  );
2427
- }, wt = (s, t) => {
2428
- t.points.length !== 0 && j(s, t, 0, 0, () => {
2429
- s.startGraphic(
2430
- t.drawMode ?? s.gl.TRIANGLES,
2431
- t.texture,
2432
- t.shader,
2433
- t.customMatrix
2434
+ }, Et = (s, t) => {
2435
+ if (t.points.length === 0) return;
2436
+ const e = X(s, t, 0, 0);
2437
+ s.startGraphic(
2438
+ t.drawMode ?? s.gl.TRIANGLES,
2439
+ t.texture,
2440
+ t.shader,
2441
+ e ?? t.customMatrix
2442
+ );
2443
+ for (let r = 0; r < t.points.length; r++) {
2444
+ const i = t.points[r], n = t.uv?.[r], a = Array.isArray(t.color) ? t.color[r] : t.color;
2445
+ s.addGraphicVertex(
2446
+ i.x,
2447
+ i.y,
2448
+ n?.x ?? 0,
2449
+ n?.y ?? 0,
2450
+ st(s, a)
2434
2451
  );
2435
- for (let e = 0; e < t.points.length; e++) {
2436
- const i = t.points[e], r = t.uv?.[e], n = Array.isArray(t.color) ? t.color[e] : t.color;
2437
- s.addGraphicVertex(
2438
- i.x,
2439
- i.y,
2440
- r?.x ?? 0,
2441
- r?.y ?? 0,
2442
- J(s, n)
2443
- );
2444
- }
2445
- s.endGraphic();
2446
- });
2447
- }, Jt = (s, t) => {
2452
+ }
2453
+ s.endGraphic();
2454
+ }, Zt = (s, t) => {
2448
2455
  if (s.inCreateMask)
2449
2456
  return;
2450
- const { vertices: e, uv: i } = jt(t);
2451
- wt(s, {
2457
+ const { vertices: e, uv: r } = jt(t);
2458
+ Et(s, {
2452
2459
  ...t,
2453
2460
  points: e,
2454
- uv: i,
2461
+ uv: r,
2455
2462
  drawMode: s.gl.TRIANGLES
2456
2463
  });
2464
+ }, Qt = (s, t) => {
2465
+ const e = X(
2466
+ s,
2467
+ t,
2468
+ t.texture.rawWidth,
2469
+ t.texture.rawHeight
2470
+ );
2471
+ s.startMaskGraphic(
2472
+ s.gl.TRIANGLE_FAN,
2473
+ t.texture,
2474
+ e ?? t.customMatrix
2475
+ ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2476
+ }, Jt = (s, t) => {
2477
+ const e = X(s, t, t.width, t.height);
2478
+ s.startGraphic(
2479
+ s.gl.TRIANGLE_FAN,
2480
+ t.texture,
2481
+ t.shader,
2482
+ e ?? t.customMatrix
2483
+ ), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
2457
2484
  }, te = (s, t) => {
2458
- j(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2459
- s.startMaskGraphic(
2460
- s.gl.TRIANGLE_FAN,
2461
- t.texture,
2462
- t.customMatrix
2463
- ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2464
- });
2465
- }, ee = (s, t) => {
2466
- j(s, t, t.width, t.height, () => {
2467
- s.startGraphic(
2468
- s.gl.TRIANGLE_FAN,
2469
- t.texture,
2470
- t.shader,
2471
- t.customMatrix
2472
- ), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
2473
- });
2474
- }, ie = (s, t) => {
2475
- const e = t.segments ?? 32;
2476
- j(s, t, 0, 0, () => {
2477
- s.startGraphic(
2478
- s.gl.TRIANGLE_FAN,
2479
- void 0,
2480
- t.shader,
2481
- t.customMatrix
2482
- );
2483
- const i = J(s, t.color);
2484
- s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
2485
- });
2486
- }, ft = `#version 300 es\r
2485
+ const e = t.segments ?? 32, r = X(s, t, 0, 0);
2486
+ s.startGraphic(
2487
+ s.gl.TRIANGLE_FAN,
2488
+ void 0,
2489
+ t.shader,
2490
+ r ?? t.customMatrix
2491
+ );
2492
+ const i = st(s, t.color);
2493
+ s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
2494
+ }, lt = `#version 300 es\r
2487
2495
  precision mediump float;\r
2488
2496
  \r
2489
2497
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -2523,7 +2531,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
2523
2531
  // CUSTOM_CODE\r
2524
2532
  \r
2525
2533
  void main(void) {\r
2526
- fragColor = sampleClampTexture(vRegion);\r
2534
+ fragColor = sampleClampTexture(vRegion) * vColor;\r
2527
2535
  // if (vPadding.x != 0.0) {\r
2528
2536
  // if (clampUV(vRegion)) {\r
2529
2537
  // fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
@@ -2533,31 +2541,31 @@ void main(void) {\r
2533
2541
  // CUSTOM_CODE_CALL\r
2534
2542
  }\r
2535
2543
  `;
2536
- class re extends at {
2544
+ class ee extends it {
2537
2545
  KEY = "AtlasSprite";
2538
2546
  constructor(t) {
2539
2547
  super(t);
2540
2548
  }
2541
2549
  createCustomShader(t) {
2542
- const e = F(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2543
- return t.getGLShader(this, this.KEY, i, e);
2550
+ const e = F(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = F($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2551
+ return t.getGLShader(this, this.KEY, r, e);
2544
2552
  }
2545
2553
  createDefaultShader() {
2546
- const t = this.rapid, e = F(ft, t.maxTextureUnits), i = F(Z, t.maxTextureUnits);
2547
- return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
2554
+ const t = this.rapid, e = F(lt, t.maxTextureUnits), r = F($, t.maxTextureUnits);
2555
+ return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
2548
2556
  }
2549
2557
  }
2550
- const mt = `#version 300 es\r
2551
- precision mediump float;\r
2558
+ const dt = `#version 300 es\r
2559
+ precision highp float;\r
2552
2560
  \r
2553
2561
  // per-vertex\r
2554
2562
  in vec2 aVertex;\r
2555
2563
  \r
2556
2564
  // per-instance: 变换\r
2557
2565
  in vec2 aPosition;\r
2558
- in vec2 aScale;
2559
- in float aRotation;
2560
- in vec2 aOrigin;
2566
+ in vec2 aScale;\r
2567
+ in float aRotation;\r
2568
+ in vec2 aOrigin;\r
2561
2569
  \r
2562
2570
  // per-instance:UV 区域 (u0, v0, u1, v1)\r
2563
2571
  in vec4 aUVRect;\r
@@ -2577,7 +2585,7 @@ void main(void) {\r
2577
2585
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
2578
2586
  // CUSTOM_CODE_CALL\r
2579
2587
  \r
2580
- vec2 scaled = (aVertex - aOrigin) * aScale;
2588
+ vec2 scaled = (aVertex - aOrigin) * aScale;\r
2581
2589
  float c = cos(aRotation);\r
2582
2590
  float s = sin(aRotation);\r
2583
2591
  \r
@@ -2588,7 +2596,7 @@ void main(void) {\r
2588
2596
  \r
2589
2597
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
2590
2598
  }\r
2591
- `, xt = `#version 300 es\r
2599
+ `, ft = `#version 300 es\r
2592
2600
  precision mediump float;\r
2593
2601
  \r
2594
2602
  uniform sampler2D uTexture;\r
@@ -2604,73 +2612,66 @@ void main(void) {\r
2604
2612
  \r
2605
2613
  // CUSTOM_CODE_CALL\r
2606
2614
  }\r
2607
- `, B = 48, K = B / 4;
2608
- class se extends at {
2615
+ `, D = 48, mt = D / 4;
2616
+ class re extends it {
2609
2617
  KEY = "ParticleSprite";
2610
2618
  texture;
2611
2619
  constructor(t) {
2612
2620
  super(t);
2613
2621
  }
2614
2622
  createCustomShader(t) {
2615
- return t.getGLShader(this, this.KEY, mt, xt);
2623
+ return t.getGLShader(this, this.KEY, dt, ft);
2616
2624
  }
2617
2625
  createDefaultShader() {
2618
- const t = xt, e = mt;
2626
+ const t = ft, e = dt;
2619
2627
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
2620
2628
  }
2621
2629
  enter(t) {
2622
2630
  super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
2623
2631
  }
2624
2632
  createShader(t, e) {
2625
- const i = super.createShader(t, e);
2626
- return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
2627
- { name: "aPosition", size: 2, stride: B, offset: 0, divisor: 1 },
2628
- { name: "aScale", size: 2, stride: B, offset: 8, divisor: 1 },
2629
- { name: "aRotation", size: 1, stride: B, offset: 16, divisor: 1 },
2630
- { name: "aUVRect", size: 4, stride: B, offset: 20, divisor: 1 },
2631
- { name: "aColor", size: 4, type: st, normalized: !0, stride: B, offset: 36, divisor: 1 },
2632
- { name: "aOrigin", size: 2, stride: B, offset: 40, divisor: 1 }
2633
- ]), this.quadBuffer.bindBuffer(), i.setAttributes([
2633
+ const r = super.createShader(t, e);
2634
+ return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
2635
+ { name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
2636
+ { name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
2637
+ { name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
2638
+ { name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
2639
+ { name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
2640
+ { name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
2641
+ ]), this.quadBuffer.bindBuffer(), r.setAttributes([
2634
2642
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2635
- ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2636
- }
2637
- drawParticle(t, e = 0, i = 0, r = 1, n = 1, a = 0, o = 0, h = 0, c = 1, u = 1, f = 4294967295, l = !1, p = !1, x = !1, v = 0.5, R = 0.5) {
2638
- (this.instanceCount >= q || this.texture && t != this.texture) && this.flush(), t.glTexture && (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2639
- const T = this.instanceBuffer, g = T.usedElemNum, w = t.rawWidth, b = t.rawHeight;
2640
- T.resize(K);
2641
- const A = T.float32, I = T.uint32;
2642
- A[g] = e, A[g + 1] = i, A[g + 2] = r * (l ? -1 : 1) * w, A[g + 3] = n * (p ? -1 : 1) * b, A[g + 4] = a, x && (A[g + 4] += Math.PI / 2), A[g + 5] = o, A[g + 6] = h, A[g + 7] = c, A[g + 8] = u, I[g + 9] = f, A[g + 10] = v, A[g + 11] = R, T.usedElemNum += K, T.makeDirty(), this.instanceCount++;
2643
+ ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2643
2644
  }
2644
- drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, v = !1, R = 0.5, T = 0.5) {
2645
+ drawParticles(t, e, r, i, n, a, c = 1, h = 1, o = 0, u = 0, l = 1, d = 1, f = !1, x = !1, g = !1, v = 0.5, T = 0.5) {
2645
2646
  if (!t.glTexture || a <= 0) return;
2646
- let g = 0;
2647
- const w = t.rawWidth * o * (p ? -1 : 1), b = t.rawHeight * h * (x ? -1 : 1), A = v ? Math.PI / 2 : 0;
2648
- for (; g < a; ) {
2647
+ let R = 0;
2648
+ const E = t.rawWidth * c * (f ? -1 : 1), b = t.rawHeight * h * (x ? -1 : 1), N = g ? Math.PI / 2 : 0;
2649
+ for (; R < a; ) {
2649
2650
  this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2650
- const I = a - g, Y = q - this.instanceCount, N = Math.min(I, Y), U = this.instanceBuffer;
2651
- let y = U.usedElemNum;
2652
- U.resize(N * K);
2653
- const M = U.float32, D = U.uint32;
2654
- for (let O = 0; O < N; O++) {
2655
- const W = g + O;
2656
- M[y] = e[W], M[y + 1] = i[W], M[y + 2] = w, M[y + 3] = b, M[y + 4] = r[W] + A, M[y + 5] = c, M[y + 6] = u, M[y + 7] = f, M[y + 8] = l, D[y + 9] = n[W], M[y + 10] = R, M[y + 11] = T, y += K;
2651
+ const W = a - R, L = this.instanceBuffer;
2652
+ let S = L.usedElemNum;
2653
+ L.resize(W * mt);
2654
+ const w = L.float32, A = L.uint32;
2655
+ for (let U = 0; U < W; U++) {
2656
+ const O = R + U;
2657
+ w[S] = e[O], w[S + 1] = r[O], w[S + 2] = E, w[S + 3] = b, w[S + 4] = i[O] + N, w[S + 5] = o, w[S + 6] = u, w[S + 7] = l, w[S + 8] = d, A[S + 9] = n[O], w[S + 10] = v, w[S + 11] = T, S += mt;
2657
2658
  }
2658
- U.usedElemNum = y, U.makeDirty(), this.instanceCount += N, g += N, this.instanceCount >= q && this.flush();
2659
+ L.usedElemNum = S, L.makeDirty(), this.instanceCount += W, R += W;
2659
2660
  }
2660
2661
  }
2661
2662
  render() {
2662
2663
  if (this.instanceCount === 0) return;
2663
- super.render();
2664
+ this.prepareRender();
2664
2665
  const t = this.gl;
2665
2666
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2666
2667
  const e = this.currentShader;
2667
2668
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2668
- const i = Yt(this.rapid.projection, this.worldSpriteMatrix);
2669
- this.currentShader.setUniform("u_projection", i), Tt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
2669
+ const r = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(r.curWorldM), a = Vt(this.rapid.projection, n);
2670
+ this.currentShader.setUniform("u_projection", a), this.currentShader.setUniform("u_projection", this.rapid.projection), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
2670
2671
  }
2671
2672
  }
2672
- var ne = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(ne || {}), ae = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(ae || {}), nt = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(nt || {}), he = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(he || {});
2673
- class le {
2673
+ var ie = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(ie || {}), se = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(se || {}), rt = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(rt || {}), ne = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(ne || {});
2674
+ class ce {
2674
2675
  /** The active WebGL context. */
2675
2676
  gl;
2676
2677
  /** The target HTMLCanvasElement. */
@@ -2682,7 +2683,7 @@ class le {
2682
2683
  /** The current device pixel ratio. */
2683
2684
  dpr;
2684
2685
  /** Background clear color [r, g, b, a], values range from 0 to 255. */
2685
- backgroundColor = m.Black;
2686
+ backgroundColor = p.Black;
2686
2687
  /** Logical width in CSS pixels, used for coordinate system and projection matrix. */
2687
2688
  logicWidth = 0;
2688
2689
  /** Logical height in CSS pixels, used for coordinate system and projection matrix. */
@@ -2696,7 +2697,7 @@ class le {
2696
2697
  /** Maximum number of texture units supported by the device. */
2697
2698
  maxTextureUnits = 0;
2698
2699
  /** Matrix stack for hierarchical transformations. */
2699
- matrixStack = new bt(this);
2700
+ matrixStack = new St(this);
2700
2701
  /** Direct access to the underlying matrix store. */
2701
2702
  matrix;
2702
2703
  /** Region dedicated to fast sprite rendering. */
@@ -2734,10 +2735,10 @@ class le {
2734
2735
  */
2735
2736
  constructor(t) {
2736
2737
  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;
2737
- const e = Pt(this.canvas, this.antialias, this.premultipliedAlpha);
2738
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new at(this), this.graphicRegion = new Vt(this), this.atlasSpriteRegion = new re(this), this.particleRegion = new se(this);
2739
- const i = this.canvas.clientWidth || this.canvas.width, r = this.canvas.clientHeight || this.canvas.height;
2740
- this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * 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 At(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);
2738
+ const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
2739
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new it(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new ee(this), this.particleRegion = new re(this);
2740
+ const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2741
+ 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 bt(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);
2741
2742
  }
2742
2743
  setTextureFilter(t) {
2743
2744
  this.textureFilter = t;
@@ -2756,26 +2757,23 @@ class le {
2756
2757
  enterRegion(t, e) {
2757
2758
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2758
2759
  }
2759
- drawParticle(t) {
2760
- Zt(this, t);
2761
- }
2762
2760
  drawParticles(t) {
2763
- Qt(this, t);
2761
+ qt(this, t), this.flush();
2764
2762
  }
2765
2763
  drawSprite(t) {
2766
- qt(this, t);
2764
+ Kt(this, t);
2767
2765
  }
2768
2766
  drawLine(t) {
2769
- Jt(this, t);
2767
+ Zt(this, t);
2770
2768
  }
2771
2769
  drawGraphic(t) {
2772
- wt(this, t);
2770
+ Et(this, t);
2773
2771
  }
2774
2772
  drawRect(t) {
2775
- ee(this, t);
2773
+ Jt(this, t);
2776
2774
  }
2777
2775
  drawCircle(t) {
2778
- ie(this, t);
2776
+ te(this, t);
2779
2777
  }
2780
2778
  /**
2781
2779
  * Starts rendering arbitrary graphics geometries.
@@ -2783,23 +2781,23 @@ class le {
2783
2781
  * @param texture An optional texture applied to the graphic vertices.
2784
2782
  * @param customShader An optional custom shader overriding the region's default shader.
2785
2783
  */
2786
- startGraphic(t = this.gl.TRIANGLES, e, i, r) {
2787
- this.enterRegion(this.graphicRegion, i), this.graphicRegion.startGraphic(r ?? this.matrixStack.curWorldM, t, e);
2784
+ startGraphic(t = this.gl.TRIANGLES, e, r, i) {
2785
+ this.enterRegion(this.graphicRegion, r), this.graphicRegion.startGraphic(i ?? this.matrixStack.curWorldM, t, e);
2788
2786
  }
2789
2787
  /**
2790
2788
  * Starts rendering graphics explicitly for use as a mask, overriding the shader.
2791
2789
  * @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES).
2792
2790
  * @param texture An optional texture whose alpha channel may dictate masking rules.
2793
2791
  */
2794
- startMaskGraphic(t = this.gl.TRIANGLES, e, i) {
2795
- this.startGraphic(t, e, this.graphicRegion.maskShader, i);
2792
+ startMaskGraphic(t = this.gl.TRIANGLES, e, r) {
2793
+ this.startGraphic(t, e, this.graphicRegion.maskShader, r);
2796
2794
  }
2797
2795
  /**
2798
2796
  * Utility method: Draws an image directly as a mask using a generic rectangle geometry.
2799
2797
  * @param texture The texture to be used as a mask.
2800
2798
  */
2801
2799
  drawMaskImage(t) {
2802
- te(this, t);
2800
+ Qt(this, t);
2803
2801
  }
2804
2802
  /**
2805
2803
  * Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
@@ -2807,9 +2805,9 @@ class le {
2807
2805
  * @param h The height of the rectangle.
2808
2806
  * @param color An optional tint color.
2809
2807
  */
2810
- addRectVertex(t, e, i) {
2811
- const r = this.getColorUint32(i);
2812
- this.addGraphicVertex(0, 0, 0, 0, r), this.addGraphicVertex(t, 0, 1, 0, r), this.addGraphicVertex(t, e, 1, 1, r), this.addGraphicVertex(0, e, 0, 1, r);
2808
+ addRectVertex(t, e, r) {
2809
+ const i = this.getColorUint32(r);
2810
+ this.addGraphicVertex(0, 0, 0, 0, i), this.addGraphicVertex(t, 0, 1, 0, i), this.addGraphicVertex(t, e, 1, 1, i), this.addGraphicVertex(0, e, 0, 1, i);
2813
2811
  }
2814
2812
  /**
2815
2813
  * Pushes vertices for a circle geometry using TRIANGLES or similar primitives.
@@ -2817,11 +2815,11 @@ class le {
2817
2815
  * @param color An optional tint color.
2818
2816
  * @param segments The number of segments (polygons) used to approximate the circle.
2819
2817
  */
2820
- addCircleVertex(t, e, i = 32) {
2821
- const r = Math.PI * 2 / i, n = this.getColorUint32(e);
2822
- for (let a = 0; a < i; a++) {
2823
- const o = r * a, h = Math.cos(o) * t, c = Math.sin(o) * t, u = 0.5 + Math.cos(o) * 0.5, f = 0.5 + Math.sin(o) * 0.5;
2824
- this.addGraphicVertex(h, c, u, f, n);
2818
+ addCircleVertex(t, e, r = 32) {
2819
+ const i = Math.PI * 2 / r, n = this.getColorUint32(e);
2820
+ for (let a = 0; a < r; a++) {
2821
+ const c = i * a, h = Math.cos(c) * t, o = Math.sin(c) * t, u = 0.5 + Math.cos(c) * 0.5, l = 0.5 + Math.sin(c) * 0.5;
2822
+ this.addGraphicVertex(h, o, u, l, n);
2825
2823
  }
2826
2824
  }
2827
2825
  /**
@@ -2832,8 +2830,8 @@ class le {
2832
2830
  * @param v The V texture coordinate (0 to 1).
2833
2831
  * @param color The vertex color as a 32-bit unsigned integer.
2834
2832
  */
2835
- addGraphicVertex(t, e, i = 0, r = 0, n = 4294967295) {
2836
- this.graphicRegion.addVertex(t, e, i, r, n);
2833
+ addGraphicVertex(t, e, r = 0, i = 0, n = 4294967295) {
2834
+ this.graphicRegion.addVertex(t, e, r, i, n);
2837
2835
  }
2838
2836
  /**
2839
2837
  * Ends the current graphics geometry definition, readying it for rendering.
@@ -2848,10 +2846,10 @@ class le {
2848
2846
  * @param cssWidth Optional CSS display width.
2849
2847
  * @param cssHeight Optional CSS display height.
2850
2848
  */
2851
- resize(t, e, i, r) {
2849
+ resize(t, e, r, i) {
2852
2850
  this.flush();
2853
- const n = i ?? this.canvas.clientWidth ?? this.canvas.width, a = r ?? this.canvas.clientHeight ?? this.canvas.height;
2854
- switch (i !== void 0 && (this.canvas.style.width = n + "px"), r !== void 0 && (this.canvas.style.height = a + "px"), this.physicsWidth = n * this.dpr, this.physicsHeight = a * this.dpr, this.logicWidth = t, this.logicHeight = e, this.scaleMode) {
2851
+ const n = r ?? this.canvas.clientWidth ?? this.canvas.width, a = i ?? this.canvas.clientHeight ?? this.canvas.height;
2852
+ switch (r !== void 0 && (this.canvas.style.width = n + "px"), i !== void 0 && (this.canvas.style.height = a + "px"), this.physicsWidth = n * this.dpr, this.physicsHeight = a * this.dpr, this.logicWidth = t, this.logicHeight = e, this.scaleMode) {
2855
2853
  case 1:
2856
2854
  this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
2857
2855
  break;
@@ -2867,8 +2865,8 @@ class le {
2867
2865
  * Updates the projection matrix using an orthographic mapping.
2868
2866
  * Automatically sets local flag projectionDirty.
2869
2867
  */
2870
- updateProjection(t, e, i, r) {
2871
- this.updateOrthMatrix(this.projection, t, e, i, r), this.projectionDirty = !0;
2868
+ updateProjection(t, e, r, i) {
2869
+ this.updateOrthMatrix(this.projection, t, e, r, i), this.projectionDirty = !0;
2872
2870
  }
2873
2871
  /**
2874
2872
  * Clears the active framebuffer applying the default background color.
@@ -2881,8 +2879,8 @@ class le {
2881
2879
  * Populates an orthographic projection matrix in place.
2882
2880
  * Avoids continuous Float32Array allocations for performance reasons.
2883
2881
  */
2884
- updateOrthMatrix(t, e, i, r, n) {
2885
- t[0] = 2 / (i - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (n - r), t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[10] = -1, t[11] = 0, t[12] = -(i + e) / (i - e), t[13] = -(n + r) / (n - r), t[14] = 0, t[15] = 1;
2882
+ updateOrthMatrix(t, e, r, i, n) {
2883
+ t[0] = 2 / (r - e), t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0, t[5] = 2 / (n - i), t[6] = 0, t[7] = 0, t[8] = 0, t[9] = 0, t[10] = -1, t[11] = 0, t[12] = -(r + e) / (r - e), t[13] = -(n + i) / (n - i), t[14] = 0, t[15] = 1;
2886
2884
  }
2887
2885
  /**
2888
2886
  * Flushes currently buffered rendering operations across all active regions.
@@ -2907,23 +2905,23 @@ class le {
2907
2905
  applyFilters(t, e) {
2908
2906
  if (e.length === 0)
2909
2907
  throw new Error("applyFilters: shaders array must not be empty.");
2910
- const i = Math.max(...e.map((c) => c.padding)), r = i, n = t.rawWidth + i * 2, a = t.rawHeight + i * 2;
2911
- for (let c = 0; c < 2; c++)
2912
- this._filterRT[c] ? this._filterRT[c].resize(n, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: n, height: a });
2913
- let o = t.clone(this._filterInput), h = 0;
2908
+ const r = Math.max(...e.map((o) => o.padding)), i = r, n = t.rawWidth + r * 2, a = t.rawHeight + r * 2;
2909
+ for (let o = 0; o < 2; o++)
2910
+ this._filterRT[o] ? this._filterRT[o].resize(n, a) : this._filterRT[o] = this.texture.createRenderTexture({ width: n, height: a });
2911
+ let c = t.clone(this._filterInput), h = 0;
2914
2912
  this.matrixStack.save(), this.matrixStack.identity();
2915
- for (let c = 0; c < e.length; c++) {
2913
+ for (let o = 0; o < e.length; o++) {
2916
2914
  const u = this._filterRT[h % 2];
2917
2915
  u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
2918
- texture: o,
2919
- shader: e[c],
2920
- offsetX: c == 0 ? r : 0,
2916
+ texture: c,
2917
+ shader: e[o],
2918
+ offsetX: o == 0 ? i : 0,
2921
2919
  // padding back
2922
- offsetY: c == 0 ? r : 0,
2923
- padding: i
2924
- }), this.leaveRenderTexture(), o = u, h++;
2920
+ offsetY: o == 0 ? i : 0,
2921
+ padding: r
2922
+ }), this.leaveRenderTexture(), c = u, h++;
2925
2923
  }
2926
- return this.matrixStack.restore(), o.offsetX = -r, o.offsetY = -r, o;
2924
+ return this.matrixStack.restore(), c.offsetX = -i, c.offsetY = -i, c;
2927
2925
  }
2928
2926
  enterRenderTexture(t) {
2929
2927
  this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
@@ -2935,7 +2933,7 @@ class le {
2935
2933
  * @param rt The render texture to clear.
2936
2934
  * @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
2937
2935
  */
2938
- clearRenderTexture(t = new m(0, 0, 0, 0)) {
2936
+ clearRenderTexture(t = new p(0, 0, 0, 0)) {
2939
2937
  this.flush();
2940
2938
  const e = this.gl;
2941
2939
  t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
@@ -2957,10 +2955,10 @@ class le {
2957
2955
  * rapid.drawSprite({ texture: mySprite });
2958
2956
  * });
2959
2957
  */
2960
- drawToRenderTexture(t, e, i = new m(0, 0, 0, 0)) {
2958
+ drawToRenderTexture(t, e, r = new p(0, 0, 0, 0)) {
2961
2959
  this.enterRenderTexture(t);
2962
2960
  try {
2963
- i !== null && this.clearRenderTexture(i), e();
2961
+ r !== null && this.clearRenderTexture(r), e();
2964
2962
  } finally {
2965
2963
  this.leaveRenderTexture();
2966
2964
  }
@@ -2978,14 +2976,14 @@ class le {
2978
2976
  * () => rapid.drawSprite({ texture: myTexture }),
2979
2977
  * );
2980
2978
  */
2981
- withMask(t, e, i = 0, r = 1) {
2982
- this.clearMask(), this.startDrawMask(r);
2979
+ withMask(t, e, r = 0, i = 1) {
2980
+ this.clearMask(), this.startDrawMask(i);
2983
2981
  try {
2984
2982
  t();
2985
2983
  } finally {
2986
2984
  this.endDrawMask();
2987
2985
  }
2988
- this.enterMask(i, r);
2986
+ this.enterMask(r, i);
2989
2987
  try {
2990
2988
  e();
2991
2989
  } finally {
@@ -3014,21 +3012,12 @@ class le {
3014
3012
  * rapid.drawSprite({ texture: myTexture });
3015
3013
  * }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);
3016
3014
  */
3017
- withTransform(t, e, i = 0, r = 0) {
3018
- if (e) {
3019
- const n = e.saveTransform ?? !0;
3020
- try {
3021
- this.matrixStack.applyTransform(e, i, r), t();
3022
- } finally {
3023
- n && this.matrixStack.restore();
3024
- }
3025
- } else {
3026
- this.matrixStack.save();
3027
- try {
3028
- t();
3029
- } finally {
3030
- this.matrixStack.restore();
3031
- }
3015
+ withTransform(t, e, r = 0, i = 0) {
3016
+ this.matrixStack.save();
3017
+ try {
3018
+ e && this.matrixStack.applyTransform(e, r, i), t();
3019
+ } finally {
3020
+ this.matrixStack.restore();
3032
3021
  }
3033
3022
  }
3034
3023
  /**
@@ -3044,8 +3033,8 @@ class le {
3044
3033
  * rapid.drawSprite({ texture: myTexture });
3045
3034
  * });
3046
3035
  */
3047
- withScissor(t, e, i, r, n) {
3048
- this.startScissor(t, e, i, r);
3036
+ withScissor(t, e, r, i, n) {
3037
+ this.startScissor(t, e, r, i);
3049
3038
  try {
3050
3039
  n();
3051
3040
  } finally {
@@ -3080,8 +3069,8 @@ class le {
3080
3069
  */
3081
3070
  startDrawMask(t = 1, e = 255) {
3082
3071
  this.flush();
3083
- const i = this.gl;
3084
- i.stencilMask(e), i.colorMask(!1, !1, !1, !1), i.stencilFunc(i.ALWAYS, t, e), i.stencilOp(i.KEEP, i.KEEP, i.REPLACE), this.enterRegion(this.graphicRegion, this.graphicRegion.maskShader), this.inCreateMask = !0;
3072
+ const r = this.gl;
3073
+ r.stencilMask(e), r.colorMask(!1, !1, !1, !1), r.stencilFunc(r.ALWAYS, t, e), r.stencilOp(r.KEEP, r.KEEP, r.REPLACE), this.enterRegion(this.graphicRegion, this.graphicRegion.maskShader), this.inCreateMask = !0;
3085
3074
  }
3086
3075
  /**
3087
3076
  * Finishes the mask drawing phase and restores color buffer writing.
@@ -3106,10 +3095,10 @@ class le {
3106
3095
  * @param ref The reference value to test against.
3107
3096
  * @param mask The bitmask specifying which stencil bits to consider.
3108
3097
  */
3109
- enterMask(t, e = 1, i = 255) {
3098
+ enterMask(t, e = 1, r = 255) {
3110
3099
  this.flush();
3111
- const r = this.gl;
3112
- r.colorMask(!0, !0, !0, !0), r.stencilMask(0), r.stencilFunc(t === 0 ? r.EQUAL : r.NOTEQUAL, e, i), r.stencilOp(r.KEEP, r.KEEP, r.KEEP), this.inCreateMask = !1;
3100
+ const i = this.gl;
3101
+ i.colorMask(!0, !0, !0, !0), i.stencilMask(0), i.stencilFunc(t === 0 ? i.EQUAL : i.NOTEQUAL, e, r), i.stencilOp(i.KEEP, i.KEEP, i.KEEP), this.inCreateMask = !1;
3113
3102
  }
3114
3103
  /**
3115
3104
  * Exits the masked rendering phase, restoring default full-screen stencil values tests.
@@ -3153,10 +3142,10 @@ class le {
3153
3142
  * @param width Width in logical pixels.
3154
3143
  * @param height Height in logical pixels.
3155
3144
  */
3156
- startScissor(t, e, i, r) {
3145
+ startScissor(t, e, r, i) {
3157
3146
  this.flush();
3158
- const n = this.gl, a = this.physicsWidth / this.logicWidth, o = this.physicsHeight / this.logicHeight, h = Math.round(t * a), c = Math.round(this.physicsHeight - (e + r) * o), u = Math.round(i * a), f = Math.round(r * o);
3159
- n.enable(n.SCISSOR_TEST), n.scissor(h, c, u, f);
3147
+ const n = this.gl, a = this.physicsWidth / this.logicWidth, c = this.physicsHeight / this.logicHeight, h = Math.round(t * a), o = Math.round(this.physicsHeight - (e + i) * c), u = Math.round(r * a), l = Math.round(i * c);
3148
+ n.enable(n.SCISSOR_TEST), n.scissor(h, o, u, l);
3160
3149
  }
3161
3150
  /**
3162
3151
  * Disables scissor clipping, restoring full-canvas rendering.
@@ -3170,13 +3159,13 @@ class le {
3170
3159
  this.matrix.invert(e);
3171
3160
  }
3172
3161
  logicToPhysics(t) {
3173
- return t.multiply(new d(
3162
+ return t.multiply(new m(
3174
3163
  this.physicsWidth / this.logicWidth,
3175
3164
  this.physicsHeight / this.logicHeight
3176
3165
  ));
3177
3166
  }
3178
3167
  physicsToLogic(t) {
3179
- return t.multiply(new d(
3168
+ return t.multiply(new m(
3180
3169
  this.logicWidth / this.physicsWidth,
3181
3170
  this.logicHeight / this.physicsHeight
3182
3171
  ));
@@ -3200,12 +3189,12 @@ class le {
3200
3189
  * @param index - Matrix index to export. Defaults to the current world matrix.
3201
3190
  */
3202
3191
  toCSSMatrix(t) {
3203
- const e = this.physicsWidth / this.dpr / this.logicWidth, i = this.physicsHeight / this.dpr / this.logicHeight;
3204
- return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, i);
3192
+ const e = this.physicsWidth / this.dpr / this.logicWidth, r = this.physicsHeight / this.dpr / this.logicHeight;
3193
+ return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
3205
3194
  }
3206
3195
  }
3207
- function oe(s) {
3208
- return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof d || s instanceof m);
3196
+ function ae(s) {
3197
+ return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof m || s instanceof p);
3209
3198
  }
3210
3199
  class C {
3211
3200
  /** Random float in [min, max). */
@@ -3221,12 +3210,12 @@ class C {
3221
3210
  return Math.random() * Math.PI * 2;
3222
3211
  }
3223
3212
  /** Random Vec2 with components in the supplied per-axis ranges. */
3224
- static vector(t, e, i, r) {
3225
- return new d(C.float(t, e), C.float(i, r));
3213
+ static vector(t, e, r, i) {
3214
+ return new m(C.float(t, e), C.float(r, i));
3226
3215
  }
3227
3216
  /** Random Color with each component interpolated between minColor and maxColor. */
3228
3217
  static randomColor(t, e) {
3229
- return new m(
3218
+ return new p(
3230
3219
  C.float(t.r, e.r),
3231
3220
  C.float(t.g, e.g),
3232
3221
  C.float(t.b, e.b),
@@ -3244,10 +3233,10 @@ class C {
3244
3233
  static pickWeight(t) {
3245
3234
  if (!t || t.length === 0) return null;
3246
3235
  let e = 0;
3247
- for (const [, r] of t) e += r;
3248
- let i = Math.random() * e;
3249
- for (const [r, n] of t)
3250
- if (i -= n, i <= 0) return r;
3236
+ for (const [, i] of t) e += i;
3237
+ let r = Math.random() * e;
3238
+ for (const [i, n] of t)
3239
+ if (r -= n, r <= 0) return i;
3251
3240
  return t[t.length - 1][0];
3252
3241
  }
3253
3242
  /**
@@ -3259,20 +3248,20 @@ class C {
3259
3248
  static scalarOrRange(t, e) {
3260
3249
  if (t == null) return e;
3261
3250
  if (Array.isArray(t)) {
3262
- const [i, r] = t;
3263
- if (typeof i == "number")
3264
- return C.float(i, r);
3265
- if (i instanceof d)
3266
- return C.vector(i.x, r.x, i.y, r.y);
3267
- if (i instanceof m)
3268
- return C.randomColor(i, r);
3251
+ const [r, i] = t;
3252
+ if (typeof r == "number")
3253
+ return C.float(r, i);
3254
+ if (r instanceof m)
3255
+ return C.vector(r.x, i.x, r.y, i.y);
3256
+ if (r instanceof p)
3257
+ return C.randomColor(r, i);
3269
3258
  }
3270
3259
  return typeof t == "number" ? t : t.clone();
3271
3260
  }
3272
3261
  }
3273
- var ce = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(ce || {});
3274
- const pt = 10, gt = 0, vt = !0;
3275
- class ue {
3262
+ var he = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(he || {});
3263
+ const xt = 10, pt = 0, gt = !0;
3264
+ class oe {
3276
3265
  life = 0;
3277
3266
  maxLife;
3278
3267
  texture;
@@ -3285,19 +3274,19 @@ class ue {
3285
3274
  speed: this.processAttribute(e.animation.speed, 0),
3286
3275
  rotation: this.processAttribute(e.animation.rotation, 0),
3287
3276
  scale: this.processAttribute(e.animation.scale, 1),
3288
- color: this.processAttribute(e.animation.color, m.White.clone()),
3289
- velocity: this.processAttribute(e.animation.velocity, d.ZERO)
3290
- }, this.position = d.ZERO, this.initializePosition();
3277
+ color: this.processAttribute(e.animation.color, p.White.clone()),
3278
+ velocity: this.processAttribute(e.animation.velocity, m.ZERO)
3279
+ }, this.position = m.ZERO, this.initializePosition();
3291
3280
  }
3292
3281
  processAttribute(t, e) {
3293
3282
  if (t == null)
3294
3283
  return { value: e };
3295
- if (oe(t)) {
3296
- const i = t, r = C.scalarOrRange(i.start, e), n = i.end === void 0 ? r : C.scalarOrRange(i.end, e);
3284
+ if (ae(t)) {
3285
+ const r = t, i = C.scalarOrRange(r.start, e), n = r.end === void 0 ? i : C.scalarOrRange(r.end, e);
3297
3286
  return {
3298
- delta: i.delta ?? this.getDelta(r, n, this.maxLife),
3299
- value: r,
3300
- damping: i.damping
3287
+ delta: r.delta ?? this.getDelta(i, n, this.maxLife),
3288
+ value: i,
3289
+ damping: r.damping
3301
3290
  };
3302
3291
  } else
3303
3292
  return this.processAttribute({ start: t }, e);
@@ -3314,11 +3303,11 @@ class ue {
3314
3303
  updateAttributes(t) {
3315
3304
  const e = this.datas;
3316
3305
  this.updateNumberAttribute(e.speed, t), this.updateNumberAttribute(e.rotation, t), this.updateNumberAttribute(e.scale, t), this.updateColorAttribute(e.color, t), this.updateVec2Attribute(e.velocity, t);
3317
- const r = d.fromAngle(e.rotation.value).multiply(e.speed.value * t);
3318
- this.position = this.position.add(r).add(e.velocity.value.multiply(t));
3306
+ const i = m.fromAngle(e.rotation.value).multiply(e.speed.value * t);
3307
+ this.position = this.position.add(i).add(e.velocity.value.multiply(t));
3319
3308
  }
3320
- getDelta(t, e, i) {
3321
- return typeof t == "number" && typeof e == "number" ? (e - t) / i : t instanceof d && e instanceof d || t instanceof m && e instanceof m ? e.subtract(t).divide(i) : t;
3309
+ getDelta(t, e, r) {
3310
+ return typeof t == "number" && typeof e == "number" ? (e - t) / r : t instanceof m && e instanceof m || t instanceof p && e instanceof p ? e.subtract(t).divide(r) : t;
3322
3311
  }
3323
3312
  /**
3324
3313
  * Updates particle state.
@@ -3333,44 +3322,44 @@ class ue {
3333
3322
  * The emitter is responsible for calling save/restore around a batch of particles.
3334
3323
  */
3335
3324
  render() {
3336
- const t = this.rapid.matrixStack, e = this.datas.scale.value, i = this.datas.rotation.value, r = this.datas.color.value;
3337
- t.save(), t.translate(this.position.x, this.position.y), i !== 0 && t.rotate(i), e !== 1 && t.scale(e, e);
3325
+ const t = this.rapid.matrixStack, e = this.datas.scale.value, r = this.datas.rotation.value, i = this.datas.color.value;
3326
+ t.save(), t.translate(this.position.x, this.position.y), r !== 0 && t.rotate(r), e !== 1 && t.scale(e, e);
3338
3327
  const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
3339
- (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Et(this.rapid, { texture: this.texture, color: r }), t.restore();
3328
+ (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color: i }), t.restore();
3340
3329
  }
3341
3330
  initializePosition() {
3342
3331
  switch (this.options.emitShape) {
3343
3332
  case "circle": {
3344
3333
  const t = Math.random() * Math.PI * 2, e = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
3345
- this.position = new d(Math.cos(t) * e, Math.sin(t) * e);
3334
+ this.position = new m(Math.cos(t) * e, Math.sin(t) * e);
3346
3335
  break;
3347
3336
  }
3348
3337
  case "rect": {
3349
- this.position = new d(
3338
+ this.position = new m(
3350
3339
  (Math.random() - 0.5) * (this.options.emitRect?.width ?? 0),
3351
3340
  (Math.random() - 0.5) * (this.options.emitRect?.height ?? 0)
3352
3341
  );
3353
3342
  break;
3354
3343
  }
3355
3344
  default:
3356
- this.position = d.ZERO;
3345
+ this.position = m.ZERO;
3357
3346
  break;
3358
3347
  }
3359
3348
  !this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
3360
3349
  }
3361
3350
  }
3362
- class Mt {
3351
+ class wt {
3363
3352
  particles = [];
3364
3353
  options;
3365
3354
  emitting = !1;
3366
3355
  emitTimer = 0;
3367
- emitRate = pt;
3368
- emitTime = gt;
3356
+ emitRate = xt;
3357
+ emitTime = pt;
3369
3358
  emitTimeCounter = 0;
3370
3359
  /** Whether spawned particles are positioned in local emitter space (default: true). */
3371
- localSpace = vt;
3360
+ localSpace = gt;
3372
3361
  /** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
3373
- position = d.ZERO;
3362
+ position = m.ZERO;
3374
3363
  rapid;
3375
3364
  gameObject;
3376
3365
  /**
@@ -3379,7 +3368,7 @@ class Mt {
3379
3368
  * @param options - Emitter configuration options
3380
3369
  */
3381
3370
  constructor(t, e) {
3382
- this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : pt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : gt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : vt, this.position = e.position ?? d.ZERO;
3371
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : xt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : pt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : gt, this.position = e.position ?? m.ZERO;
3383
3372
  }
3384
3373
  /** Replaces the emitter's texture at runtime. */
3385
3374
  setTexture(t) {
@@ -3390,7 +3379,7 @@ class Mt {
3390
3379
  * Particle state is NOT copied.
3391
3380
  */
3392
3381
  clone() {
3393
- return new Mt(this.rapid, { ...this.options });
3382
+ return new wt(this.rapid, { ...this.options });
3394
3383
  }
3395
3384
  /** Sets particles-per-second emission rate (continuous mode). */
3396
3385
  setEmitRate(t) {
@@ -3417,9 +3406,9 @@ class Mt {
3417
3406
  * Respects `maxParticles` if set.
3418
3407
  */
3419
3408
  emit(t) {
3420
- const e = this.options.maxParticles ?? 1 / 0, i = Math.min(t, e - this.particles.length);
3421
- for (let r = 0; r < i; r++)
3422
- this.particles.push(new ue(this.rapid, { ...this.options, position: this.position }));
3409
+ const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.particles.length);
3410
+ for (let i = 0; i < r; i++)
3411
+ this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
3423
3412
  }
3424
3413
  /**
3425
3414
  * Updates the emitter and all live particles.
@@ -3467,44 +3456,42 @@ class Mt {
3467
3456
  }
3468
3457
  }
3469
3458
  export {
3470
- L as ArrayType,
3471
- G as BaseTexture,
3472
- ae as BlendMode,
3473
- he as CanvasScaleMode,
3474
- m as Color,
3475
- ut as CustomGlShader,
3476
- k as DynamicArrayBuffer,
3477
- yt as GLShader,
3478
- Vt as GraphicRegion,
3479
- Xt as LineTextureMode,
3480
- q as MAX_INSTANCES,
3481
- ne as MaskType,
3482
- bt as MatrixStack,
3483
- St as MatrixStore,
3484
- ue as Particle,
3485
- Mt as ParticleEmitter,
3486
- ce as ParticleShape,
3487
- Dt as QUAD_VERTICES,
3488
- le as Rapid,
3489
- Rt as Region,
3490
- Ut as RenderTexture,
3491
- at as SpriteRegion,
3492
- Ct as TextTexture,
3459
+ I as ArrayType,
3460
+ k as BaseTexture,
3461
+ se as BlendMode,
3462
+ ne as CanvasScaleMode,
3463
+ p as Color,
3464
+ ot as CustomGlShader,
3465
+ B as DynamicArrayBuffer,
3466
+ Tt as GLShader,
3467
+ Ht as GraphicRegion,
3468
+ Yt as LineTextureMode,
3469
+ ie as MaskType,
3470
+ St as MatrixStack,
3471
+ Mt as MatrixStore,
3472
+ oe as Particle,
3473
+ wt as ParticleEmitter,
3474
+ he as ParticleShape,
3475
+ Ft as QUAD_VERTICES,
3476
+ ce as Rapid,
3477
+ yt as Region,
3478
+ At as RenderTexture,
3479
+ it as SpriteRegion,
3480
+ _t as TextTexture,
3493
3481
  P as Texture,
3494
- nt as TextureFilterMode,
3495
- At as TextureManager,
3496
- $ as TextureWrapMode,
3497
- d as Vec2,
3498
- et as WebglBufferArray,
3499
- Yt as composeProjectionWithAffine,
3500
- ie as drawCircle,
3501
- wt as drawGraphic,
3502
- Jt as drawLine,
3503
- te as drawMaskImage,
3504
- Zt as drawParticle,
3505
- Qt as drawParticles,
3506
- ee as drawRect,
3507
- qt as drawSprite,
3508
- Et as drawSpriteRaw,
3482
+ rt as TextureFilterMode,
3483
+ bt as TextureManager,
3484
+ Y as TextureWrapMode,
3485
+ m as Vec2,
3486
+ Q as WebglBufferArray,
3487
+ Vt as composeProjectionWithAffine,
3488
+ te as drawCircle,
3489
+ Et as drawGraphic,
3490
+ Zt as drawLine,
3491
+ Qt as drawMaskImage,
3492
+ qt as drawParticles,
3493
+ Jt as drawRect,
3494
+ Kt as drawSprite,
3495
+ Rt as drawSpriteRaw,
3509
3496
  zt as multiplyMat4
3510
3497
  };