rapid-render 1.0.6 → 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,4 +1,4 @@
1
- var O = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(O || {});
1
+ var I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
2
2
  class B {
3
3
  /** The number of elements currently used in the buffer. */
4
4
  usedElemNum;
@@ -171,8 +171,8 @@ class Q extends B {
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 Q extends B {
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,24 +434,24 @@ 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 v = 6;
454
+ const y = 6;
455
455
  class Mt {
456
456
  /** Total number of matrices currently allocated in the store. */
457
457
  matrixCount = 0;
@@ -459,12 +459,13 @@ class Mt {
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 B(O.Float32), this.buffer.resize(t * v), 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 Mt {
479
480
  * @returns The index of the newly allocated matrix.
480
481
  */
481
482
  allocDirty() {
482
- return this.buffer.resize(v) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += v, 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 * v, 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 Mt {
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 * v, 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 Mt {
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 * v, 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 Mt {
521
522
  * @param radians - The rotation angle in radians.
522
523
  */
523
524
  rotate(t, e) {
524
- const i = t * v, 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 Mt {
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 Mt {
549
550
  * @param src - The index of the source matrix.
550
551
  */
551
552
  copy(t, e) {
552
- const i = t * v, r = e * v, 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 Mt {
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 * v, n = e * v, a = i * v, 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], g = o[a + 1], T = o[a + 2], y = o[a + 3], w = o[a + 4], M = o[a + 5];
571
- o[r] = h * x + u * g, o[r + 1] = c * x + f * g, o[r + 2] = h * T + u * y, o[r + 3] = c * T + f * y, o[r + 4] = h * w + u * M + l, o[r + 5] = c * w + f * M + 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 * v, 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 Mt {
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 * v, 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 Mt {
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 -= v, 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 Mt {
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 Mt {
627
628
  * @returns An object containing `x` and `y` global coordinates.
628
629
  */
629
630
  getPosition(t) {
630
- const e = t * v, 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 Mt {
636
637
  * @returns An object containing `x` and `y` global scale factors.
637
638
  */
638
639
  getScale(t) {
639
- const e = t * v, 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 Mt {
645
646
  * @returns The global rotation in radians.
646
647
  */
647
648
  getRotation(t) {
648
- const e = t * v, 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 Mt {
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 * v, 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 Mt {
667
668
  * @returns A new Float32Array containing the 6 elements of the matrix.
668
669
  */
669
670
  getMatrix(t) {
670
- const e = t * v;
671
- return this.data.slice(e, e + v);
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 Mt {
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 * v;
682
- return this.data.subarray(e, e + v);
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,12 +689,16 @@ class Mt {
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 * v, 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], g = 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 + g;
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
704
  class St {
@@ -702,15 +707,15 @@ class St {
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 B(O.Uint32);
710
+ stack = new B(I.Uint32);
706
711
  /** Records the world matrices generated at each step. */
707
- stepWorldM = new B(O.Uint32);
712
+ stepWorldM = new B(I.Uint32);
708
713
  /** Records actions (push/pop) taken during the traversal. */
709
- stepAction = new B(O.Uint32);
714
+ stepAction = new B(I.Uint32);
710
715
  /** Records the parent world matrix for each step (used by updateMatrix). */
711
- stepParentM = new B(O.Uint32);
716
+ stepParentM = new B(I.Uint32);
712
717
  /** Buffer used during hierarchy traversal updates. */
713
- parentStack = new B(O.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 St {
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 St {
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,53 +864,65 @@ class St {
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 * v;
863
- return this.matrix.data.slice(t, t + v);
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 * v, 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, g = p * a, T = x * a, y = -x * o, w = p * o, M = r + g * u + y * f, A = n + T * u + w * 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
- g,
911
+ v,
895
912
  T,
896
- y,
897
- w,
898
- M,
899
- A
913
+ R,
914
+ E,
915
+ b,
916
+ N
900
917
  ), this.matrix.multiplyAffineInPlace(
901
918
  this.curWorldM,
902
- g,
919
+ v,
903
920
  T,
904
- y,
905
- w,
906
- M,
907
- A
908
- ), t.afterSave?.();
921
+ R,
922
+ E,
923
+ b,
924
+ N
925
+ );
909
926
  }
910
927
  }
911
928
  var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
@@ -922,14 +939,14 @@ class bt {
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 = k.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 bt {
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 = k.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).
@@ -970,8 +987,8 @@ class bt {
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,9 +999,9 @@ class bt {
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
  }
@@ -994,8 +1011,8 @@ class k {
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 k {
1004
1021
  * @param options - Optional configuration.
1005
1022
  * @returns The created BaseTexture.
1006
1023
  */
1007
- static fromSource(t, e, i = {}) {
1008
- const r = K(t, e, i);
1009
- return new k(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,8 +1031,8 @@ class k {
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 && tt(t, i.textureFilter), i.wrap !== void 0 && J(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.
@@ -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 g = 0; g < l; g++)
1124
- a.push(this.getSubTexture(g * 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 = K(t, e, i);
1134
- return new P(new k(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.
@@ -1150,11 +1167,11 @@ class At 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 = K(t, { width: i, height: r }, { ...e, onlySize: !0 });
1155
- if (this.setBase(new k(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 At 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 At 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 At 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 At 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.
@@ -1249,11 +1266,11 @@ class _t extends P {
1249
1266
  flipY = !0;
1250
1267
  constructor(t, e) {
1251
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");
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 = K(t, this.canvas, this.options);
1256
- this.setBase(new k(r, 1, 1)), this.update();
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,51 +1318,51 @@ class _t 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 M of o) {
1312
- const A = t.measureText(M);
1313
- A.width > h && (h = A.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, g = Math.ceil(c + p) || 1, T = x * a, y = g * a;
1317
- (this.canvas.width !== T || this.canvas.height !== y) && (this.canvas.width = T, this.canvas.height = y), 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);
1318
- let w = p / 2;
1319
- for (const M of o) {
1320
- let A = p / 2;
1321
- this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(M, A, w)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(M, A, w)), w += 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
1343
  const Ct = (s, t = !1, e = !0) => {
1327
- const i = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1328
- if (!i)
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;
1347
+ return r;
1331
1348
  }, ht = (s, t, e) => {
1332
- const i = s.createShader(e);
1333
- if (!i)
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;
1356
+ return r;
1340
1357
  }, Pt = (s, t, e) => {
1341
- var i = s.createProgram(), r = ht(s, t, 35633), n = ht(s, e, 35632);
1342
- if (!i)
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
1367
  function J(s, t) {
1351
1368
  const e = {
@@ -1357,29 +1374,29 @@ function J(s, t) {
1357
1374
  }
1358
1375
  function tt(s, t) {
1359
1376
  const e = {
1360
- [it.LINEAR]: s.LINEAR,
1361
- [it.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
1382
  function K(s, t, e) {
1366
- const i = s.gl, r = i.createTexture();
1367
- if (!r)
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), J(i, e.wrap ?? Y.CLAMP), tt(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
- function W(s, t) {
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;
@@ -1388,8 +1405,8 @@ const Nt = 5126, et = 5121;
1388
1405
  function Lt(s, t, e) {
1389
1406
  s.vertexAttribDivisor(t, e);
1390
1407
  }
1391
- function vt(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
1412
  class Tt {
@@ -1407,8 +1424,8 @@ class Tt {
1407
1424
  shaderId = Ot++;
1408
1425
  // for debug
1409
1426
  vao;
1410
- constructor(t, e, i, r) {
1411
- this.gl = t, this.program = Pt(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 Tt {
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
- It(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 Tt {
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
1481
  t.type ?? Nt,
1465
1482
  t.normalized ?? !1,
1466
1483
  t.stride,
1467
1484
  t.offset ?? 0
1468
- ), i.enableVertexAttribArray(e), Lt(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,76 +1496,76 @@ class Tt {
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 It(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 Wt(s, t, i);
1549
+ return Wt(s, t, r);
1533
1550
  }
1534
1551
  }
1535
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
1571
  class ot {
@@ -1569,8 +1586,8 @@ class ot {
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 ot {
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 ot {
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,13 +1630,13 @@ class ot {
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
  }
@@ -1653,17 +1670,17 @@ class yt {
1653
1670
  (t, e) => e
1654
1671
  );
1655
1672
  }
1656
- findTextureUnit(t, e = 0, i = 0) {
1657
- for (let r = 0; r < this.usedTextures.length; r++) {
1658
- const n = r * 2;
1659
- if (this.usedTextures[r] === t && this.usedTexturePadding[n] === e && this.usedTexturePadding[n + 1] === i)
1660
- 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;
1661
1678
  }
1662
1679
  return -1;
1663
1680
  }
1664
- useTexture(t, e = 0, i = 0) {
1665
- const r = this.findTextureUnit(t, e, i);
1666
- 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;
1667
1684
  }
1668
1685
  createShader(t, e) {
1669
1686
  return new Tt(this.gl, t, e);
@@ -1703,20 +1720,20 @@ class yt {
1703
1720
  prepareRender() {
1704
1721
  const t = this.currentShader;
1705
1722
  if (t.use(), this.customShader) {
1706
- const i = this.customShader, r = {};
1707
- for (const n in i.uniformTextures)
1708
- r[n] = this.useTexture(i.uniformTextures[n]);
1709
- 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);
1710
1727
  }
1711
1728
  const e = this.gl;
1712
- for (let i = 0; i < this.usedTextures.length; i++)
1713
- 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]);
1714
1731
  t.setUniform("uTextures", Int32Array.from(
1715
1732
  { length: this.usedTextures.length },
1716
- (i, r) => r
1733
+ (r, i) => i
1717
1734
  )), t.setUniform("uPadding", Float32Array.from(
1718
1735
  { length: this.usedTexturePadding.length },
1719
- (i, r) => this.usedTexturePadding[r]
1736
+ (r, i) => this.usedTexturePadding[i]
1720
1737
  ));
1721
1738
  }
1722
1739
  resetRender() {
@@ -1727,7 +1744,7 @@ class yt {
1727
1744
  }
1728
1745
  }
1729
1746
  const $ = `#version 300 es\r
1730
- precision mediump float;\r
1747
+ precision highp float;\r
1731
1748
  \r
1732
1749
  // per-vertex\r
1733
1750
  in vec2 aVertex;\r
@@ -1814,7 +1831,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
1814
1831
  // CUSTOM_CODE\r
1815
1832
  \r
1816
1833
  void main(void) {\r
1817
- fragColor = sampleTexture(vRegion);\r
1834
+ fragColor = sampleTexture(vRegion) * vColor;\r
1818
1835
  // if (vPadding.x != 0.0) {\r
1819
1836
  // if (clampUV(vRegion)) {\r
1820
1837
  // fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
@@ -1824,7 +1841,7 @@ void main(void) {\r
1824
1841
  // CUSTOM_CODE_CALL\r
1825
1842
  }\r
1826
1843
  `, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1827
- class rt extends yt {
1844
+ class it extends yt {
1828
1845
  instanceBuffer;
1829
1846
  quadBuffer;
1830
1847
  instanceCount = 0;
@@ -1836,29 +1853,29 @@ class rt extends yt {
1836
1853
  }
1837
1854
  createBuffer() {
1838
1855
  const t = this.gl;
1839
- this.quadBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1856
+ this.quadBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1840
1857
  for (const e of Ft) this.quadBuffer.pushFloat32(e);
1841
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, O.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1858
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, I.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1842
1859
  }
1843
1860
  createDefaultShader() {
1844
- const t = this.rapid, e = W(ct, t.maxTextureUnits), i = W($, t.maxTextureUnits);
1845
- 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;
1846
1863
  }
1847
1864
  createShader(t, e) {
1848
- const i = super.createShader(t, e);
1849
- return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
1865
+ const r = super.createShader(t, e);
1866
+ return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1850
1867
  { name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
1851
1868
  { name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
1852
1869
  { name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
1853
1870
  { name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
1854
1871
  { name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
1855
- ]), this.quadBuffer.bindBuffer(), i.setAttributes([
1872
+ ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1856
1873
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1857
- ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1874
+ ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1858
1875
  }
1859
1876
  createCustomShader(t) {
1860
- const e = W(ct, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1861
- 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);
1862
1879
  }
1863
1880
  /**
1864
1881
  * Draws a textured sprite via instanced rendering to significantly improve performance.
@@ -1872,39 +1889,39 @@ class rt extends yt {
1872
1889
  * @param v1 Bottom UV mapped coordinate (default 1).
1873
1890
  * @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
1874
1891
  */
1875
- drawSprite(t, e, i = 0, r = 0, n = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, f = !1, l = !1) {
1876
- 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;
1877
1894
  this.drawSpriteAffine(
1878
1895
  t,
1879
- x[p],
1880
- x[p + 1],
1881
- x[p + 2],
1882
- x[p + 3],
1883
- x[p + 4],
1884
- x[p + 5],
1885
- i,
1896
+ x[f],
1897
+ x[f + 1],
1898
+ x[f + 2],
1899
+ x[f + 3],
1900
+ x[f + 4],
1901
+ x[f + 5],
1886
1902
  r,
1903
+ i,
1887
1904
  n,
1888
1905
  a,
1889
- o,
1890
- h,
1891
1906
  c,
1907
+ h,
1908
+ o,
1892
1909
  u,
1893
- f,
1894
- l
1910
+ l,
1911
+ d
1895
1912
  );
1896
1913
  }
1897
- drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, g = !1, T = !1, y = !1) {
1898
- const w = t.base, M = t.scale ?? 1, A = t.rawWidth, F = t.rawHeight, I = t.offsetX, N = t.offsetY, S = 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(
1899
1916
  t.glTexture,
1900
- p / M / w.width,
1901
- x / M / w.height
1902
- ), R = this.instanceBuffer, b = R.usedElemNum;
1903
- R.resize(12);
1904
- const U = R.float32, L = R.uint32, j = (y ? F : A) * M, q = (y ? A : F) * M, G = j + 2 * p, H = q + 2 * x, nt = I - p, at = N - x, E = this.localSpriteMatrix;
1905
- y ? (E[0] = 0, E[1] = T ? H : -H, E[2] = g ? -G : G, E[3] = 0, E[4] = nt + (g ? G : 0), E[5] = at + (T ? 0 : H)) : (E[0] = g ? -G : G, E[1] = 0, E[2] = 0, E[3] = T ? -H : H, E[4] = nt + (g ? G : 0), E[5] = at + (T ? H : 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));
1906
1923
  const _ = this.worldSpriteMatrix;
1907
- _[0] = e * E[0] + r * E[1], _[1] = i * E[0] + n * E[1], _[2] = e * E[2] + r * E[3], _[3] = i * E[2] + n * E[3], _[4] = a + e * E[4] + r * E[5], _[5] = o + i * E[4] + n * E[5], U[b + 6] = h, U[b + 7] = c, U[b + 8] = u, U[b + 9] = f, L[b + 10] = l, L[b + 11] = S, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), U[b] = _[0], U[b + 1] = _[2], U[b + 2] = _[4], U[b + 3] = _[1], U[b + 4] = _[3], U[b + 5] = _[5], R.usedElemNum += 12, R.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++;
1908
1925
  }
1909
1926
  render() {
1910
1927
  if (this.instanceCount === 0) return;
@@ -1920,7 +1937,7 @@ class rt extends yt {
1920
1937
  }
1921
1938
  }
1922
1939
  const Dt = `#version 300 es\r
1923
- precision mediump float;\r
1940
+ precision highp float;\r
1924
1941
  \r
1925
1942
  in vec2 aPosition;\r
1926
1943
  in vec4 aColor;\r
@@ -1970,9 +1987,9 @@ bool clampUV(vec2 uv) {\r
1970
1987
  \r
1971
1988
  vec4 sampleTexture(vec2 uv) {\r
1972
1989
  if (uUseTexture > 0) {\r
1973
- return texture(uTexture, uv) * vColor;\r
1990
+ return texture(uTexture, uv);\r
1974
1991
  }\r
1975
- return vColor;\r
1992
+ return vec4(1,1,1,1);\r
1976
1993
  }\r
1977
1994
  \r
1978
1995
  vec4 sampleClampTexture(vec2 uv) {\r
@@ -1993,11 +2010,11 @@ vec4 sampleTextureLocal(vec2 uv) {\r
1993
2010
  // CUSTOM_CODE\r
1994
2011
  \r
1995
2012
  void main(void) {\r
1996
- fragColor = sampleTexture(vRegion);\r
2013
+ fragColor = sampleTexture(vRegion) * vColor;\r
1997
2014
  // CUSTOM_CODE_CALL\r
1998
2015
  }\r
1999
2016
  `, kt = `#version 300 es\r
2000
- precision mediump float;\r
2017
+ precision highp float;\r
2001
2018
  \r
2002
2019
  in vec2 aPosition;\r
2003
2020
  in vec2 aUV;\r
@@ -2053,25 +2070,25 @@ class Ht extends yt {
2053
2070
  }
2054
2071
  createBuffer() {
2055
2072
  const t = this.gl;
2056
- this.vertexBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
2073
+ this.vertexBuffer = new Q(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
2057
2074
  }
2058
2075
  createDefaultShader() {
2059
2076
  return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2060
2077
  }
2061
2078
  createMaskShader(t, e) {
2062
- const i = this.gl, r = new Tt(i, t, e);
2063
- return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2064
- { name: "aPosition", size: 2, type: i.FLOAT, stride: z - 4, offset: 0, divisor: 0 },
2065
- { name: "aUV", size: 2, type: i.FLOAT, stride: z - 4, offset: 8, divisor: 0 }
2066
- ]), 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;
2067
2084
  }
2068
2085
  createShader(t, e) {
2069
- const i = this.gl, r = super.createShader(t, e);
2070
- return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2071
- { name: "aPosition", size: 2, type: i.FLOAT, stride: z, offset: 0, divisor: 0 },
2072
- { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: z, offset: 8, divisor: 0 },
2073
- { name: "aUV", size: 2, type: i.FLOAT, stride: z, offset: 12, divisor: 0 }
2074
- ]), 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;
2075
2092
  }
2076
2093
  /**
2077
2094
  * Begins a new polygon drawing sequence. Must be followed by addVertex() calls and endGraphic().
@@ -2079,8 +2096,8 @@ class Ht extends yt {
2079
2096
  * @param drawMode The WebGL drawing primitive mode (e.g., gl.TRIANGLES).
2080
2097
  * @param texture Optional texture to apply over the polygon.
2081
2098
  */
2082
- startGraphic(t, e = this.gl.TRIANGLES, i) {
2083
- 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);
2084
2101
  }
2085
2102
  /**
2086
2103
  * Adds a vertex to the current polygon. Local coordinates and color settings.
@@ -2090,9 +2107,9 @@ class Ht extends yt {
2090
2107
  * @param v UV mapped Y value (0-1, default 0).
2091
2108
  * @param color Pre-multiplied hex color combined using ABGR byte order (default 0xFFFFFFFF).
2092
2109
  */
2093
- addVertex(t, e, i = 0, r = 0, n = 4294967295) {
2110
+ addVertex(t, e, r = 0, i = 0, n = 4294967295) {
2094
2111
  const a = this.vertexBuffer;
2095
- 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();
2096
2113
  }
2097
2114
  /**
2098
2115
  * Finishes the graphic construction and dispatches the rendering call immediately.
@@ -2103,9 +2120,9 @@ class Ht extends yt {
2103
2120
  render() {
2104
2121
  if (this.vertexCount === 0) return;
2105
2122
  this.prepareRender();
2106
- const t = this.gl, e = this.currentShader, i = this.matrixIndex * 6, r = this.matrixStore.data;
2107
- let n = r[i + 4], a = r[i + 5];
2108
- 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(
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(
2109
2126
  "uUVRect",
2110
2127
  this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
2111
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;
@@ -2114,15 +2131,15 @@ class Ht extends yt {
2114
2131
  return !1;
2115
2132
  }
2116
2133
  }
2117
- class d {
2134
+ class m {
2118
2135
  x;
2119
2136
  y;
2120
- static ZERO = new d(0, 0);
2121
- static ONE = new d(1, 1);
2122
- static UP = new d(0, 1);
2123
- static DOWN = new d(0, -1);
2124
- static LEFT = new d(-1, 0);
2125
- 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);
2126
2143
  constructor(t, e) {
2127
2144
  this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
2128
2145
  }
@@ -2130,22 +2147,22 @@ class d {
2130
2147
  return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
2131
2148
  }
2132
2149
  add(t) {
2133
- return new d(this.x + t.x, this.y + t.y);
2150
+ return new m(this.x + t.x, this.y + t.y);
2134
2151
  }
2135
2152
  subtract(t) {
2136
- return new d(this.x - t.x, this.y - t.y);
2153
+ return new m(this.x - t.x, this.y - t.y);
2137
2154
  }
2138
2155
  sub(t) {
2139
- return new d(this.x - t.x, this.y - t.y);
2156
+ return new m(this.x - t.x, this.y - t.y);
2140
2157
  }
2141
2158
  multiply(t) {
2142
- 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);
2143
2160
  }
2144
2161
  mul(t) {
2145
2162
  return this.multiply(t);
2146
2163
  }
2147
2164
  divide(t) {
2148
- 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);
2149
2166
  }
2150
2167
  dot(t) {
2151
2168
  return this.x * t.x + this.y * t.y;
@@ -2154,17 +2171,17 @@ class d {
2154
2171
  return this.x * t.y - this.y * t.x;
2155
2172
  }
2156
2173
  distanceTo(t) {
2157
- const e = this.x - t.x, i = this.y - t.y;
2158
- 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);
2159
2176
  }
2160
2177
  clone() {
2161
- return new d(this.x, this.y);
2178
+ return new m(this.x, this.y);
2162
2179
  }
2163
2180
  to(t) {
2164
2181
  this.x = t.x, this.y = t.y;
2165
2182
  }
2166
2183
  copy() {
2167
- return new d(this.x, this.y);
2184
+ return new m(this.x, this.y);
2168
2185
  }
2169
2186
  equals(t) {
2170
2187
  return t.x == this.x && t.y == this.y;
@@ -2177,7 +2194,7 @@ class d {
2177
2194
  return this.x = -this.x, this.y = -this.y, this;
2178
2195
  }
2179
2196
  inverted() {
2180
- return new d(this.x * -1, this.y * -1);
2197
+ return new m(this.x * -1, this.y * -1);
2181
2198
  }
2182
2199
  length() {
2183
2200
  return Math.sqrt(this.x * this.x + this.y * this.y);
@@ -2191,13 +2208,13 @@ class d {
2191
2208
  }
2192
2209
  normalized() {
2193
2210
  const t = this.length();
2194
- return new d(this.x / t || 0, this.y / t || 0);
2211
+ return new m(this.x / t || 0, this.y / t || 0);
2195
2212
  }
2196
2213
  fix(t = 1e-13) {
2197
2214
  this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
2198
2215
  }
2199
2216
  fixed(t = 1e-13) {
2200
- return new d(
2217
+ return new m(
2201
2218
  Math.abs(this.x) < t ? 0 : this.x,
2202
2219
  Math.abs(this.y) < t ? 0 : this.y
2203
2220
  );
@@ -2206,13 +2223,13 @@ class d {
2206
2223
  return Math.atan2(this.y, this.x);
2207
2224
  }
2208
2225
  abs() {
2209
- return new d(Math.abs(this.x), Math.abs(this.y));
2226
+ return new m(Math.abs(this.x), Math.abs(this.y));
2210
2227
  }
2211
2228
  floor() {
2212
- return new d(Math.floor(this.x), Math.floor(this.y));
2229
+ return new m(Math.floor(this.x), Math.floor(this.y));
2213
2230
  }
2214
2231
  ceil() {
2215
- return new d(Math.ceil(this.x), Math.ceil(this.y));
2232
+ return new m(Math.ceil(this.x), Math.ceil(this.y));
2216
2233
  }
2217
2234
  stringify() {
2218
2235
  return `Vec2(${this.x}, ${this.y})`;
@@ -2233,24 +2250,24 @@ class d {
2233
2250
  return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
2234
2251
  }
2235
2252
  static FromArray(t) {
2236
- return t.map((e) => new d(e[0], e[1]));
2253
+ return t.map((e) => new m(e[0], e[1]));
2237
2254
  }
2238
2255
  static fromAngle(t) {
2239
- return new d(Math.cos(t), Math.sin(t));
2256
+ return new m(Math.cos(t), Math.sin(t));
2240
2257
  }
2241
2258
  }
2242
2259
  const Vt = (s, t) => {
2243
- const [e, i, r, n, a, o] = t, h = new Float32Array([
2260
+ const [e, r, i, n, a, c] = t, h = new Float32Array([
2244
2261
  e,
2245
2262
  n,
2246
2263
  0,
2247
2264
  0,
2248
- i,
2265
+ r,
2249
2266
  a,
2250
2267
  0,
2251
2268
  0,
2252
- r,
2253
- o,
2269
+ i,
2270
+ c,
2254
2271
  1,
2255
2272
  0,
2256
2273
  0,
@@ -2261,142 +2278,153 @@ const Vt = (s, t) => {
2261
2278
  return zt(s, h);
2262
2279
  }, zt = (s, t) => {
2263
2280
  const e = new Float32Array(16);
2264
- for (let i = 0; i < 4; i++)
2265
- for (let r = 0; r < 4; r++) {
2281
+ for (let r = 0; r < 4; r++)
2282
+ for (let i = 0; i < 4; i++) {
2266
2283
  let n = 0;
2267
2284
  for (let a = 0; a < 4; a++)
2268
- n += s[r * 4 + a] * t[a * 4 + i];
2269
- e[r * 4 + i] = n;
2285
+ n += s[i * 4 + a] * t[a * 4 + r];
2286
+ e[i * 4 + r] = n;
2270
2287
  }
2271
2288
  return e;
2272
2289
  };
2273
2290
  var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
2274
- const Z = 10, ut = (s, t, e, i, r, n) => {
2275
- 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);
2276
- for (let f = 0; f < Z; f++) {
2277
- const l = f / Z, p = (f + 1) / Z, x = h + l * c, g = h + p * c, T = new d(Math.cos(x) * e, Math.sin(x) * e), y = new d(Math.cos(g) * e, Math.sin(g) * e);
2278
- a.push(s), o.push(new d(r, 0.5)), a.push(s.add(T)), o.push(new d(r + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e)), a.push(s.add(y)), o.push(new d(r + y.dot(u) * n, 0.5 - 0.5 * y.dot(t) / e));
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));
2279
2296
  }
2280
- return { vertices: a, uv: o };
2297
+ return { vertices: a, uv: c };
2281
2298
  }, Xt = (s, t = !1) => {
2282
2299
  const e = [];
2283
2300
  if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
2284
- const i = 4, r = 1e-3, n = s.length;
2301
+ const r = 4, i = 1e-3, n = s.length;
2285
2302
  let a = 0;
2286
2303
  if (t)
2287
2304
  for (let h = 0; h < n; h++) {
2288
- const c = s[h], u = s[(h + 1) % n];
2289
- a += c.distanceTo(u);
2305
+ const o = s[h], u = s[(h + 1) % n];
2306
+ a += o.distanceTo(u);
2290
2307
  }
2291
2308
  else
2292
2309
  for (let h = 0; h < n - 1; h++)
2293
2310
  a += s[h].distanceTo(s[h + 1]);
2294
- const o = (h, c, u) => {
2295
- const f = c.subtract(h).normalize(), l = c.subtract(u).normalize(), p = l.dot(f);
2296
- if (p < -1 + r)
2297
- 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 };
2298
2315
  {
2299
- let x = l.add(f).normalize();
2300
- f.cross(l) < 0 && (x = x.multiply(-1));
2301
- let g = 1 / Math.sqrt((1 - p) / 2);
2302
- return { normal: x, miters: Math.min(g, 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) };
2303
2320
  }
2304
2321
  };
2305
2322
  if (t)
2306
2323
  for (let h = 0; h < n; h++) {
2307
- const c = h === 0 ? s[n - 1] : s[h - 1], u = s[h], f = h === n - 1 ? s[0] : s[h + 1];
2308
- 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));
2309
2326
  }
2310
2327
  else
2311
2328
  for (let h = 0; h < n; h++)
2312
2329
  if (h === 0) {
2313
- const c = s[1].subtract(s[0]).normalize();
2314
- e.push({ normal: c.perpendicular(), miters: 1 });
2330
+ const o = s[1].subtract(s[0]).normalize();
2331
+ e.push({ normal: o.perpendicular(), miters: 1 });
2315
2332
  } else if (h === n - 1) {
2316
- const c = s[h].subtract(s[h - 1]).normalize();
2317
- 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 });
2318
2335
  } else
2319
- e.push(o(s[h - 1], s[h], s[h + 1]));
2336
+ e.push(c(s[h - 1], s[h], s[h + 1]));
2320
2337
  return { normals: e, length: a };
2321
2338
  }, jt = (s) => {
2322
2339
  const t = s.points;
2323
2340
  if (t.length < 2) return { vertices: [], uv: [] };
2324
- const { normals: e, length: i } = Xt(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2325
- let c = 0;
2326
- const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
2327
- for (let l = 0; l < f; l++) {
2328
- const p = t[l], x = e[l].normal, g = e[l].miters, T = (l + 1) % t.length, y = t[T], w = e[T].normal, M = e[T].miters, A = p.add(x.multiply(g * r)), F = p.subtract(x.multiply(g * r)), I = y.add(w.multiply(M * r)), N = y.subtract(w.multiply(M * r)), S = p.distanceTo(y);
2329
- let R = 0, b = 0;
2330
- h === 0 ? (R = c / i, b = (c + S) / i) : (R = c / u, b = R + S / u);
2331
- const U = new d(R, 0), L = new d(R, 1), j = new d(b, 0), q = new d(b, 1);
2332
- n.push(A), a.push(U), n.push(F), a.push(L), n.push(I), a.push(j), n.push(I), a.push(j), n.push(N), a.push(q), n.push(F), a.push(L), c += S;
2333
- }
2334
- if (o && !s.closed) {
2335
- const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, g = ut(l, p, r, !0, 0, x);
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);
2336
2353
  n.push(...g.vertices), a.push(...g.uv);
2337
- const T = t[t.length - 1], y = e[t.length - 1].normal, w = h === 0 ? 1 : c / u, M = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, A = ut(T, y, r, !1, w, M);
2338
- n.push(...A.vertices), a.push(...A.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);
2355
+ n.push(...b.vertices), a.push(...b.uv);
2339
2356
  }
2340
2357
  return { vertices: n, uv: a };
2341
- }, X = (s, t, e, i, r) => {
2342
- s.matrixStack.applyTransform(t, e, i);
2343
- try {
2344
- r();
2345
- } finally {
2346
- t.saveTransform !== !1 && s.matrixStack.restore();
2347
- }
2348
- }, st = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, Rt = (s, t) => {
2349
- const e = t.texture;
2350
- 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
+ );
2367
+ return;
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)
2351
2380
  return;
2352
- const i = e.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
2381
+ const i = r.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
2353
2382
  s.enterRegion(i, t.shader);
2354
- let r = e.uvX, n = e.uvY, a = e.uvW, o = e.uvH;
2355
- const h = !!t.flipX, c = !!t.flipY != !!e.flipY;
2356
- let u = t.padding ?? i.currentShader.padding;
2357
- e.isAtlas && (u += $t);
2358
- 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;
2359
2388
  i.drawSprite(
2360
- e,
2361
- t.customMatrix ?? s.matrixStack.curWorldM,
2362
2389
  r,
2390
+ e ?? t.customMatrix ?? s.matrixStack.curWorldM,
2363
2391
  n,
2364
2392
  a,
2365
- o,
2393
+ c,
2394
+ h,
2366
2395
  st(s, t.color),
2396
+ d,
2367
2397
  f,
2368
- l,
2369
- h,
2370
- c,
2371
- e.isRotated
2398
+ o,
2399
+ u,
2400
+ r.isRotated
2372
2401
  );
2373
2402
  }, Kt = (s, t) => {
2374
- X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2375
- Rt(s, t);
2376
- });
2403
+ const e = X(s, t, t.texture.rawWidth, t.texture.rawHeight);
2404
+ Rt(s, t, e);
2377
2405
  }, qt = (s, t) => {
2378
2406
  const e = s.particleRegion;
2379
2407
  s.enterRegion(e, t.shader);
2380
- 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);
2381
2409
  if (s.premultipliedAlpha)
2382
2410
  for (let h = 0; h < a; h++)
2383
- o[h] = n[h].premultipliedUint32;
2411
+ c[h] = n[h].premultipliedUint32;
2384
2412
  else
2385
2413
  for (let h = 0; h < a; h++)
2386
- o[h] = n[h].uint32;
2414
+ c[h] = n[h].uint32;
2387
2415
  e.drawParticles(
2388
- i,
2416
+ r,
2389
2417
  t.x,
2390
2418
  t.y,
2391
2419
  t.rotation,
2392
- o,
2393
- r,
2420
+ c,
2421
+ i,
2394
2422
  t.scaleX,
2395
2423
  t.scaleY,
2396
- i.uvX,
2397
- i.uvY,
2398
- i.uvW,
2399
- i.uvH,
2424
+ r.uvX,
2425
+ r.uvY,
2426
+ r.uvW,
2427
+ r.uvH,
2400
2428
  t.flipX,
2401
2429
  t.flipY,
2402
2430
  t.isRotated,
@@ -2404,64 +2432,65 @@ const Z = 10, ut = (s, t, e, i, r, n) => {
2404
2432
  t.originY
2405
2433
  );
2406
2434
  }, Et = (s, t) => {
2407
- t.points.length !== 0 && X(s, t, 0, 0, () => {
2408
- s.startGraphic(
2409
- t.drawMode ?? s.gl.TRIANGLES,
2410
- t.texture,
2411
- t.shader,
2412
- t.customMatrix
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)
2413
2451
  );
2414
- for (let e = 0; e < t.points.length; e++) {
2415
- const i = t.points[e], r = t.uv?.[e], n = Array.isArray(t.color) ? t.color[e] : t.color;
2416
- s.addGraphicVertex(
2417
- i.x,
2418
- i.y,
2419
- r?.x ?? 0,
2420
- r?.y ?? 0,
2421
- st(s, n)
2422
- );
2423
- }
2424
- s.endGraphic();
2425
- });
2452
+ }
2453
+ s.endGraphic();
2426
2454
  }, Zt = (s, t) => {
2427
2455
  if (s.inCreateMask)
2428
2456
  return;
2429
- const { vertices: e, uv: i } = jt(t);
2457
+ const { vertices: e, uv: r } = jt(t);
2430
2458
  Et(s, {
2431
2459
  ...t,
2432
2460
  points: e,
2433
- uv: i,
2461
+ uv: r,
2434
2462
  drawMode: s.gl.TRIANGLES
2435
2463
  });
2436
2464
  }, Qt = (s, t) => {
2437
- X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2438
- s.startMaskGraphic(
2439
- s.gl.TRIANGLE_FAN,
2440
- t.texture,
2441
- t.customMatrix
2442
- ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2443
- });
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();
2444
2476
  }, Jt = (s, t) => {
2445
- X(s, t, t.width, t.height, () => {
2446
- s.startGraphic(
2447
- s.gl.TRIANGLE_FAN,
2448
- t.texture,
2449
- t.shader,
2450
- t.customMatrix
2451
- ), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
2452
- });
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();
2453
2484
  }, te = (s, t) => {
2454
- const e = t.segments ?? 32;
2455
- X(s, t, 0, 0, () => {
2456
- s.startGraphic(
2457
- s.gl.TRIANGLE_FAN,
2458
- void 0,
2459
- t.shader,
2460
- t.customMatrix
2461
- );
2462
- const i = st(s, t.color);
2463
- 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();
2464
- });
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();
2465
2494
  }, lt = `#version 300 es\r
2466
2495
  precision mediump float;\r
2467
2496
  \r
@@ -2502,7 +2531,7 @@ vec4 sampleTextureLocal(vec2 uv){\r
2502
2531
  // CUSTOM_CODE\r
2503
2532
  \r
2504
2533
  void main(void) {\r
2505
- fragColor = sampleClampTexture(vRegion);\r
2534
+ fragColor = sampleClampTexture(vRegion) * vColor;\r
2506
2535
  // if (vPadding.x != 0.0) {\r
2507
2536
  // if (clampUV(vRegion)) {\r
2508
2537
  // fragColor = vec4(0.0, 0.0, 0.0, 0.0);\r
@@ -2512,31 +2541,31 @@ void main(void) {\r
2512
2541
  // CUSTOM_CODE_CALL\r
2513
2542
  }\r
2514
2543
  `;
2515
- class ee extends rt {
2544
+ class ee extends it {
2516
2545
  KEY = "AtlasSprite";
2517
2546
  constructor(t) {
2518
2547
  super(t);
2519
2548
  }
2520
2549
  createCustomShader(t) {
2521
- const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2522
- 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);
2523
2552
  }
2524
2553
  createDefaultShader() {
2525
- const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W($, t.maxTextureUnits);
2526
- 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;
2527
2556
  }
2528
2557
  }
2529
2558
  const dt = `#version 300 es\r
2530
- precision mediump float;\r
2559
+ precision highp float;\r
2531
2560
  \r
2532
2561
  // per-vertex\r
2533
2562
  in vec2 aVertex;\r
2534
2563
  \r
2535
2564
  // per-instance: 变换\r
2536
2565
  in vec2 aPosition;\r
2537
- in vec2 aScale;
2538
- in float aRotation;
2539
- in vec2 aOrigin;
2566
+ in vec2 aScale;\r
2567
+ in float aRotation;\r
2568
+ in vec2 aOrigin;\r
2540
2569
  \r
2541
2570
  // per-instance:UV 区域 (u0, v0, u1, v1)\r
2542
2571
  in vec4 aUVRect;\r
@@ -2556,7 +2585,7 @@ void main(void) {\r
2556
2585
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
2557
2586
  // CUSTOM_CODE_CALL\r
2558
2587
  \r
2559
- vec2 scaled = (aVertex - aOrigin) * aScale;
2588
+ vec2 scaled = (aVertex - aOrigin) * aScale;\r
2560
2589
  float c = cos(aRotation);\r
2561
2590
  float s = sin(aRotation);\r
2562
2591
  \r
@@ -2584,7 +2613,7 @@ void main(void) {\r
2584
2613
  // CUSTOM_CODE_CALL\r
2585
2614
  }\r
2586
2615
  `, D = 48, mt = D / 4;
2587
- class ie extends rt {
2616
+ class re extends it {
2588
2617
  KEY = "ParticleSprite";
2589
2618
  texture;
2590
2619
  constructor(t) {
@@ -2601,33 +2630,33 @@ class ie extends rt {
2601
2630
  super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
2602
2631
  }
2603
2632
  createShader(t, e) {
2604
- const i = super.createShader(t, e);
2605
- return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
2633
+ const r = super.createShader(t, e);
2634
+ return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
2606
2635
  { name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
2607
2636
  { name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
2608
2637
  { name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
2609
2638
  { name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
2610
2639
  { name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
2611
2640
  { name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
2612
- ]), this.quadBuffer.bindBuffer(), i.setAttributes([
2641
+ ]), this.quadBuffer.bindBuffer(), r.setAttributes([
2613
2642
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2614
- ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2643
+ ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2615
2644
  }
2616
- drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, g = !1, T = 0.5, y = 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) {
2617
2646
  if (!t.glTexture || a <= 0) return;
2618
- let w = 0;
2619
- const M = t.rawWidth * o * (p ? -1 : 1), A = t.rawHeight * h * (x ? -1 : 1), F = g ? Math.PI / 2 : 0;
2620
- for (; w < 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; ) {
2621
2650
  this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2622
- const I = a - w, N = this.instanceBuffer;
2623
- let S = N.usedElemNum;
2624
- N.resize(I * mt);
2625
- const R = N.float32, b = N.uint32;
2626
- for (let U = 0; U < I; U++) {
2627
- const L = w + U;
2628
- R[S] = e[L], R[S + 1] = i[L], R[S + 2] = M, R[S + 3] = A, R[S + 4] = r[L] + F, R[S + 5] = c, R[S + 6] = u, R[S + 7] = f, R[S + 8] = l, b[S + 9] = n[L], R[S + 10] = T, R[S + 11] = y, S += mt;
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;
2629
2658
  }
2630
- N.usedElemNum = S, N.makeDirty(), this.instanceCount += I, w += I;
2659
+ L.usedElemNum = S, L.makeDirty(), this.instanceCount += W, R += W;
2631
2660
  }
2632
2661
  }
2633
2662
  render() {
@@ -2637,11 +2666,11 @@ class ie extends rt {
2637
2666
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2638
2667
  const e = this.currentShader;
2639
2668
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2640
- const i = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(i.curWorldM), a = Vt(this.rapid.projection, n);
2669
+ const r = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(r.curWorldM), a = Vt(this.rapid.projection, n);
2641
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;
2642
2671
  }
2643
2672
  }
2644
- var re = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(re || {}), 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 || {}), it = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(it || {}), ne = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(ne || {});
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 || {});
2645
2674
  class ce {
2646
2675
  /** The active WebGL context. */
2647
2676
  gl;
@@ -2654,7 +2683,7 @@ class ce {
2654
2683
  /** The current device pixel ratio. */
2655
2684
  dpr;
2656
2685
  /** Background clear color [r, g, b, a], values range from 0 to 255. */
2657
- backgroundColor = m.Black;
2686
+ backgroundColor = p.Black;
2658
2687
  /** Logical width in CSS pixels, used for coordinate system and projection matrix. */
2659
2688
  logicWidth = 0;
2660
2689
  /** Logical height in CSS pixels, used for coordinate system and projection matrix. */
@@ -2707,9 +2736,9 @@ class ce {
2707
2736
  constructor(t) {
2708
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;
2709
2738
  const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
2710
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new rt(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new ee(this), this.particleRegion = new ie(this);
2711
- const i = this.canvas.clientWidth || this.canvas.width, r = this.canvas.clientHeight || this.canvas.height;
2712
- 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 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);
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);
2713
2742
  }
2714
2743
  setTextureFilter(t) {
2715
2744
  this.textureFilter = t;
@@ -2752,16 +2781,16 @@ class ce {
2752
2781
  * @param texture An optional texture applied to the graphic vertices.
2753
2782
  * @param customShader An optional custom shader overriding the region's default shader.
2754
2783
  */
2755
- startGraphic(t = this.gl.TRIANGLES, e, i, r) {
2756
- 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);
2757
2786
  }
2758
2787
  /**
2759
2788
  * Starts rendering graphics explicitly for use as a mask, overriding the shader.
2760
2789
  * @param drawMode The WebGL drawing mode (e.g., gl.TRIANGLES).
2761
2790
  * @param texture An optional texture whose alpha channel may dictate masking rules.
2762
2791
  */
2763
- startMaskGraphic(t = this.gl.TRIANGLES, e, i) {
2764
- 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);
2765
2794
  }
2766
2795
  /**
2767
2796
  * Utility method: Draws an image directly as a mask using a generic rectangle geometry.
@@ -2776,9 +2805,9 @@ class ce {
2776
2805
  * @param h The height of the rectangle.
2777
2806
  * @param color An optional tint color.
2778
2807
  */
2779
- addRectVertex(t, e, i) {
2780
- const r = this.getColorUint32(i);
2781
- 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);
2782
2811
  }
2783
2812
  /**
2784
2813
  * Pushes vertices for a circle geometry using TRIANGLES or similar primitives.
@@ -2786,11 +2815,11 @@ class ce {
2786
2815
  * @param color An optional tint color.
2787
2816
  * @param segments The number of segments (polygons) used to approximate the circle.
2788
2817
  */
2789
- addCircleVertex(t, e, i = 32) {
2790
- const r = Math.PI * 2 / i, n = this.getColorUint32(e);
2791
- for (let a = 0; a < i; a++) {
2792
- 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;
2793
- 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);
2794
2823
  }
2795
2824
  }
2796
2825
  /**
@@ -2801,8 +2830,8 @@ class ce {
2801
2830
  * @param v The V texture coordinate (0 to 1).
2802
2831
  * @param color The vertex color as a 32-bit unsigned integer.
2803
2832
  */
2804
- addGraphicVertex(t, e, i = 0, r = 0, n = 4294967295) {
2805
- 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);
2806
2835
  }
2807
2836
  /**
2808
2837
  * Ends the current graphics geometry definition, readying it for rendering.
@@ -2817,10 +2846,10 @@ class ce {
2817
2846
  * @param cssWidth Optional CSS display width.
2818
2847
  * @param cssHeight Optional CSS display height.
2819
2848
  */
2820
- resize(t, e, i, r) {
2849
+ resize(t, e, r, i) {
2821
2850
  this.flush();
2822
- const n = i ?? this.canvas.clientWidth ?? this.canvas.width, a = r ?? this.canvas.clientHeight ?? this.canvas.height;
2823
- 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) {
2824
2853
  case 1:
2825
2854
  this.canvas.width = t, this.canvas.height = e, this.canvas.style.imageRendering = "pixelated", this.gl.viewport(0, 0, t, e);
2826
2855
  break;
@@ -2836,8 +2865,8 @@ class ce {
2836
2865
  * Updates the projection matrix using an orthographic mapping.
2837
2866
  * Automatically sets local flag projectionDirty.
2838
2867
  */
2839
- updateProjection(t, e, i, r) {
2840
- 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;
2841
2870
  }
2842
2871
  /**
2843
2872
  * Clears the active framebuffer applying the default background color.
@@ -2850,8 +2879,8 @@ class ce {
2850
2879
  * Populates an orthographic projection matrix in place.
2851
2880
  * Avoids continuous Float32Array allocations for performance reasons.
2852
2881
  */
2853
- updateOrthMatrix(t, e, i, r, n) {
2854
- 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;
2855
2884
  }
2856
2885
  /**
2857
2886
  * Flushes currently buffered rendering operations across all active regions.
@@ -2876,23 +2905,23 @@ class ce {
2876
2905
  applyFilters(t, e) {
2877
2906
  if (e.length === 0)
2878
2907
  throw new Error("applyFilters: shaders array must not be empty.");
2879
- const i = Math.max(...e.map((c) => c.padding)), r = i, n = t.rawWidth + i * 2, a = t.rawHeight + i * 2;
2880
- for (let c = 0; c < 2; c++)
2881
- this._filterRT[c] ? this._filterRT[c].resize(n, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: n, height: a });
2882
- 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;
2883
2912
  this.matrixStack.save(), this.matrixStack.identity();
2884
- for (let c = 0; c < e.length; c++) {
2913
+ for (let o = 0; o < e.length; o++) {
2885
2914
  const u = this._filterRT[h % 2];
2886
2915
  u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
2887
- texture: o,
2888
- shader: e[c],
2889
- offsetX: c == 0 ? r : 0,
2916
+ texture: c,
2917
+ shader: e[o],
2918
+ offsetX: o == 0 ? i : 0,
2890
2919
  // padding back
2891
- offsetY: c == 0 ? r : 0,
2892
- padding: i
2893
- }), this.leaveRenderTexture(), o = u, h++;
2920
+ offsetY: o == 0 ? i : 0,
2921
+ padding: r
2922
+ }), this.leaveRenderTexture(), c = u, h++;
2894
2923
  }
2895
- return this.matrixStack.restore(), o.offsetX = -r, o.offsetY = -r, o;
2924
+ return this.matrixStack.restore(), c.offsetX = -i, c.offsetY = -i, c;
2896
2925
  }
2897
2926
  enterRenderTexture(t) {
2898
2927
  this.flush(), t.activate(), this.gl.viewport(0, 0, t.rawWidth, t.rawHeight), this.updateProjection(0, t.rawWidth, t.rawHeight, 0);
@@ -2904,7 +2933,7 @@ class ce {
2904
2933
  * @param rt The render texture to clear.
2905
2934
  * @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
2906
2935
  */
2907
- clearRenderTexture(t = new m(0, 0, 0, 0)) {
2936
+ clearRenderTexture(t = new p(0, 0, 0, 0)) {
2908
2937
  this.flush();
2909
2938
  const e = this.gl;
2910
2939
  t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
@@ -2926,10 +2955,10 @@ class ce {
2926
2955
  * rapid.drawSprite({ texture: mySprite });
2927
2956
  * });
2928
2957
  */
2929
- drawToRenderTexture(t, e, i = new m(0, 0, 0, 0)) {
2958
+ drawToRenderTexture(t, e, r = new p(0, 0, 0, 0)) {
2930
2959
  this.enterRenderTexture(t);
2931
2960
  try {
2932
- i !== null && this.clearRenderTexture(i), e();
2961
+ r !== null && this.clearRenderTexture(r), e();
2933
2962
  } finally {
2934
2963
  this.leaveRenderTexture();
2935
2964
  }
@@ -2947,14 +2976,14 @@ class ce {
2947
2976
  * () => rapid.drawSprite({ texture: myTexture }),
2948
2977
  * );
2949
2978
  */
2950
- withMask(t, e, i = 0, r = 1) {
2951
- this.clearMask(), this.startDrawMask(r);
2979
+ withMask(t, e, r = 0, i = 1) {
2980
+ this.clearMask(), this.startDrawMask(i);
2952
2981
  try {
2953
2982
  t();
2954
2983
  } finally {
2955
2984
  this.endDrawMask();
2956
2985
  }
2957
- this.enterMask(i, r);
2986
+ this.enterMask(r, i);
2958
2987
  try {
2959
2988
  e();
2960
2989
  } finally {
@@ -2983,21 +3012,12 @@ class ce {
2983
3012
  * rapid.drawSprite({ texture: myTexture });
2984
3013
  * }, { x: 100, y: 50, rotation: Math.PI / 4, origin: 0.5 }, myTexture.width, myTexture.height);
2985
3014
  */
2986
- withTransform(t, e, i = 0, r = 0) {
2987
- if (e) {
2988
- const n = e.saveTransform ?? !0;
2989
- try {
2990
- this.matrixStack.applyTransform(e, i, r), t();
2991
- } finally {
2992
- n && this.matrixStack.restore();
2993
- }
2994
- } else {
2995
- this.matrixStack.save();
2996
- try {
2997
- t();
2998
- } finally {
2999
- this.matrixStack.restore();
3000
- }
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();
3001
3021
  }
3002
3022
  }
3003
3023
  /**
@@ -3013,8 +3033,8 @@ class ce {
3013
3033
  * rapid.drawSprite({ texture: myTexture });
3014
3034
  * });
3015
3035
  */
3016
- withScissor(t, e, i, r, n) {
3017
- this.startScissor(t, e, i, r);
3036
+ withScissor(t, e, r, i, n) {
3037
+ this.startScissor(t, e, r, i);
3018
3038
  try {
3019
3039
  n();
3020
3040
  } finally {
@@ -3049,8 +3069,8 @@ class ce {
3049
3069
  */
3050
3070
  startDrawMask(t = 1, e = 255) {
3051
3071
  this.flush();
3052
- const i = this.gl;
3053
- 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;
3054
3074
  }
3055
3075
  /**
3056
3076
  * Finishes the mask drawing phase and restores color buffer writing.
@@ -3075,10 +3095,10 @@ class ce {
3075
3095
  * @param ref The reference value to test against.
3076
3096
  * @param mask The bitmask specifying which stencil bits to consider.
3077
3097
  */
3078
- enterMask(t, e = 1, i = 255) {
3098
+ enterMask(t, e = 1, r = 255) {
3079
3099
  this.flush();
3080
- const r = this.gl;
3081
- 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;
3082
3102
  }
3083
3103
  /**
3084
3104
  * Exits the masked rendering phase, restoring default full-screen stencil values tests.
@@ -3122,10 +3142,10 @@ class ce {
3122
3142
  * @param width Width in logical pixels.
3123
3143
  * @param height Height in logical pixels.
3124
3144
  */
3125
- startScissor(t, e, i, r) {
3145
+ startScissor(t, e, r, i) {
3126
3146
  this.flush();
3127
- 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);
3128
- 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);
3129
3149
  }
3130
3150
  /**
3131
3151
  * Disables scissor clipping, restoring full-canvas rendering.
@@ -3139,13 +3159,13 @@ class ce {
3139
3159
  this.matrix.invert(e);
3140
3160
  }
3141
3161
  logicToPhysics(t) {
3142
- return t.multiply(new d(
3162
+ return t.multiply(new m(
3143
3163
  this.physicsWidth / this.logicWidth,
3144
3164
  this.physicsHeight / this.logicHeight
3145
3165
  ));
3146
3166
  }
3147
3167
  physicsToLogic(t) {
3148
- return t.multiply(new d(
3168
+ return t.multiply(new m(
3149
3169
  this.logicWidth / this.physicsWidth,
3150
3170
  this.logicHeight / this.physicsHeight
3151
3171
  ));
@@ -3169,12 +3189,12 @@ class ce {
3169
3189
  * @param index - Matrix index to export. Defaults to the current world matrix.
3170
3190
  */
3171
3191
  toCSSMatrix(t) {
3172
- const e = this.physicsWidth / this.dpr / this.logicWidth, i = this.physicsHeight / this.dpr / this.logicHeight;
3173
- 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);
3174
3194
  }
3175
3195
  }
3176
3196
  function ae(s) {
3177
- return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof d || s instanceof m);
3197
+ return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof m || s instanceof p);
3178
3198
  }
3179
3199
  class C {
3180
3200
  /** Random float in [min, max). */
@@ -3190,12 +3210,12 @@ class C {
3190
3210
  return Math.random() * Math.PI * 2;
3191
3211
  }
3192
3212
  /** Random Vec2 with components in the supplied per-axis ranges. */
3193
- static vector(t, e, i, r) {
3194
- 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));
3195
3215
  }
3196
3216
  /** Random Color with each component interpolated between minColor and maxColor. */
3197
3217
  static randomColor(t, e) {
3198
- return new m(
3218
+ return new p(
3199
3219
  C.float(t.r, e.r),
3200
3220
  C.float(t.g, e.g),
3201
3221
  C.float(t.b, e.b),
@@ -3213,10 +3233,10 @@ class C {
3213
3233
  static pickWeight(t) {
3214
3234
  if (!t || t.length === 0) return null;
3215
3235
  let e = 0;
3216
- for (const [, r] of t) e += r;
3217
- let i = Math.random() * e;
3218
- for (const [r, n] of t)
3219
- 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;
3220
3240
  return t[t.length - 1][0];
3221
3241
  }
3222
3242
  /**
@@ -3228,13 +3248,13 @@ class C {
3228
3248
  static scalarOrRange(t, e) {
3229
3249
  if (t == null) return e;
3230
3250
  if (Array.isArray(t)) {
3231
- const [i, r] = t;
3232
- if (typeof i == "number")
3233
- return C.float(i, r);
3234
- if (i instanceof d)
3235
- return C.vector(i.x, r.x, i.y, r.y);
3236
- if (i instanceof m)
3237
- 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);
3238
3258
  }
3239
3259
  return typeof t == "number" ? t : t.clone();
3240
3260
  }
@@ -3254,19 +3274,19 @@ class oe {
3254
3274
  speed: this.processAttribute(e.animation.speed, 0),
3255
3275
  rotation: this.processAttribute(e.animation.rotation, 0),
3256
3276
  scale: this.processAttribute(e.animation.scale, 1),
3257
- color: this.processAttribute(e.animation.color, m.White.clone()),
3258
- velocity: this.processAttribute(e.animation.velocity, d.ZERO)
3259
- }, 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();
3260
3280
  }
3261
3281
  processAttribute(t, e) {
3262
3282
  if (t == null)
3263
3283
  return { value: e };
3264
3284
  if (ae(t)) {
3265
- const i = t, r = C.scalarOrRange(i.start, e), n = i.end === void 0 ? r : C.scalarOrRange(i.end, e);
3285
+ const r = t, i = C.scalarOrRange(r.start, e), n = r.end === void 0 ? i : C.scalarOrRange(r.end, e);
3266
3286
  return {
3267
- delta: i.delta ?? this.getDelta(r, n, this.maxLife),
3268
- value: r,
3269
- damping: i.damping
3287
+ delta: r.delta ?? this.getDelta(i, n, this.maxLife),
3288
+ value: i,
3289
+ damping: r.damping
3270
3290
  };
3271
3291
  } else
3272
3292
  return this.processAttribute({ start: t }, e);
@@ -3283,11 +3303,11 @@ class oe {
3283
3303
  updateAttributes(t) {
3284
3304
  const e = this.datas;
3285
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);
3286
- const r = d.fromAngle(e.rotation.value).multiply(e.speed.value * t);
3287
- 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));
3288
3308
  }
3289
- getDelta(t, e, i) {
3290
- 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;
3291
3311
  }
3292
3312
  /**
3293
3313
  * Updates particle state.
@@ -3302,27 +3322,27 @@ class oe {
3302
3322
  * The emitter is responsible for calling save/restore around a batch of particles.
3303
3323
  */
3304
3324
  render() {
3305
- const t = this.rapid.matrixStack, e = this.datas.scale.value, i = this.datas.rotation.value, r = this.datas.color.value;
3306
- 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);
3307
3327
  const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
3308
- (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(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();
3309
3329
  }
3310
3330
  initializePosition() {
3311
3331
  switch (this.options.emitShape) {
3312
3332
  case "circle": {
3313
3333
  const t = Math.random() * Math.PI * 2, e = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
3314
- 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);
3315
3335
  break;
3316
3336
  }
3317
3337
  case "rect": {
3318
- this.position = new d(
3338
+ this.position = new m(
3319
3339
  (Math.random() - 0.5) * (this.options.emitRect?.width ?? 0),
3320
3340
  (Math.random() - 0.5) * (this.options.emitRect?.height ?? 0)
3321
3341
  );
3322
3342
  break;
3323
3343
  }
3324
3344
  default:
3325
- this.position = d.ZERO;
3345
+ this.position = m.ZERO;
3326
3346
  break;
3327
3347
  }
3328
3348
  !this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
@@ -3339,7 +3359,7 @@ class wt {
3339
3359
  /** Whether spawned particles are positioned in local emitter space (default: true). */
3340
3360
  localSpace = gt;
3341
3361
  /** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
3342
- position = d.ZERO;
3362
+ position = m.ZERO;
3343
3363
  rapid;
3344
3364
  gameObject;
3345
3365
  /**
@@ -3348,7 +3368,7 @@ class wt {
3348
3368
  * @param options - Emitter configuration options
3349
3369
  */
3350
3370
  constructor(t, e) {
3351
- 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 ?? 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;
3352
3372
  }
3353
3373
  /** Replaces the emitter's texture at runtime. */
3354
3374
  setTexture(t) {
@@ -3386,8 +3406,8 @@ class wt {
3386
3406
  * Respects `maxParticles` if set.
3387
3407
  */
3388
3408
  emit(t) {
3389
- const e = this.options.maxParticles ?? 1 / 0, i = Math.min(t, e - this.particles.length);
3390
- for (let r = 0; r < i; r++)
3409
+ const e = this.options.maxParticles ?? 1 / 0, r = Math.min(t, e - this.particles.length);
3410
+ for (let i = 0; i < r; i++)
3391
3411
  this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
3392
3412
  }
3393
3413
  /**
@@ -3436,17 +3456,17 @@ class wt {
3436
3456
  }
3437
3457
  }
3438
3458
  export {
3439
- O as ArrayType,
3459
+ I as ArrayType,
3440
3460
  k as BaseTexture,
3441
3461
  se as BlendMode,
3442
3462
  ne as CanvasScaleMode,
3443
- m as Color,
3463
+ p as Color,
3444
3464
  ot as CustomGlShader,
3445
3465
  B as DynamicArrayBuffer,
3446
3466
  Tt as GLShader,
3447
3467
  Ht as GraphicRegion,
3448
3468
  Yt as LineTextureMode,
3449
- re as MaskType,
3469
+ ie as MaskType,
3450
3470
  St as MatrixStack,
3451
3471
  Mt as MatrixStore,
3452
3472
  oe as Particle,
@@ -3456,13 +3476,13 @@ export {
3456
3476
  ce as Rapid,
3457
3477
  yt as Region,
3458
3478
  At as RenderTexture,
3459
- rt as SpriteRegion,
3479
+ it as SpriteRegion,
3460
3480
  _t as TextTexture,
3461
3481
  P as Texture,
3462
- it as TextureFilterMode,
3482
+ rt as TextureFilterMode,
3463
3483
  bt as TextureManager,
3464
3484
  Y as TextureWrapMode,
3465
- d as Vec2,
3485
+ m as Vec2,
3466
3486
  Q as WebglBufferArray,
3467
3487
  Vt as composeProjectionWithAffine,
3468
3488
  te as drawCircle,