rapid-render 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- var N = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(N || {});
2
- class W {
1
+ var I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
2
+ class D {
3
3
  /** The number of elements currently used in the buffer. */
4
4
  usedElemNum;
5
5
  /** The main typed array view corresponding to the specified ArrayType. */
@@ -151,7 +151,7 @@ class W {
151
151
  this.usedElemNum = 0;
152
152
  }
153
153
  }
154
- class j extends W {
154
+ class et extends D {
155
155
  /** The actual WebGLBuffer object maintained by this instance. */
156
156
  buffer;
157
157
  /** The related WebGL rendering context. */
@@ -202,7 +202,7 @@ class j extends W {
202
202
  }
203
203
  }
204
204
  }
205
- class d {
205
+ class m {
206
206
  _r;
207
207
  _g;
208
208
  _b;
@@ -283,7 +283,7 @@ class d {
283
283
  */
284
284
  updateUint() {
285
285
  this.uint32 = (this._a << 24 | this._b << 16 | this._g << 8 | this._r) >>> 0;
286
- const t = d.clampByte(this._a), e = d.clampByte(this._r * t / 255), i = d.clampByte(this._g * t / 255), r = d.clampByte(this._b * t / 255);
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
287
  this.premultipliedUint32 = (t << 24 | r << 16 | i << 8 | e) >>> 0;
288
288
  }
289
289
  reset() {
@@ -302,8 +302,8 @@ class d {
302
302
  setHSL(t, e, i) {
303
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
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, u = 0;
306
- return t < 60 ? [o, h, u] = [r, n, 0] : t < 120 ? [o, h, u] = [n, r, 0] : t < 180 ? [o, h, u] = [0, r, n] : t < 240 ? [o, h, u] = [0, n, r] : t < 300 ? [o, h, u] = [n, 0, r] : [o, h, u] = [r, 0, n], this.setRGBA((o + a) * 255, (h + a) * 255, (u + a) * 255, 255), this;
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;
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 d {
321
321
  * @returns A new `Color` instance with the same RGBA values.
322
322
  */
323
323
  clone() {
324
- return new d(this._r, this._g, this._b, this._a);
324
+ return new m(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').
@@ -355,13 +355,13 @@ class d {
355
355
  * Color.fromNorm(0.9, 0.87, 0.55, 0.1) // moon glow
356
356
  */
357
357
  static FromHSL(t, e, i) {
358
- return new d(0, 0, 0).setHSL(t, e, i);
358
+ return new m(0, 0, 0).setHSL(t, e, i);
359
359
  }
360
360
  static FromRGB(t, e, i) {
361
- return new d(t, e, i);
361
+ return new m(t, e, i);
362
362
  }
363
363
  static fromNorm(t, e, i, r = 1) {
364
- return new d(
364
+ return new m(
365
365
  Math.round(t * 255),
366
366
  Math.round(e * 255),
367
367
  Math.round(i * 255),
@@ -377,7 +377,7 @@ class d {
377
377
  t.startsWith("#") && (t = t.slice(1));
378
378
  const e = parseInt(t.slice(0, 2), 16), i = parseInt(t.slice(2, 4), 16), r = parseInt(t.slice(4, 6), 16);
379
379
  let n = 255;
380
- return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new d(e, i, r, n);
380
+ return t.length >= 8 && (n = parseInt(t.slice(6, 8), 16)), new m(e, i, r, 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 d {
385
385
  * @returns A new Color instance with the result of the addition.
386
386
  */
387
387
  add(t) {
388
- return new d(
388
+ return new m(
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,24 +398,20 @@ class d {
398
398
  * @returns A new Color instance with the result of the subtraction.
399
399
  */
400
400
  subtract(t) {
401
- return new d(
402
- Math.max(0, this.r - t.r),
403
- // Clamp to 0
404
- Math.max(0, this.g - t.g),
405
- // Clamp to 0
406
- Math.max(0, this.b - t.b),
407
- // Clamp to 0
408
- Math.max(0, this.a - t.a)
409
- // Clamp to 0
401
+ return new m(
402
+ this.r - t.r,
403
+ this.g - t.g,
404
+ this.b - t.b,
405
+ this.a - t.a
410
406
  );
411
407
  }
412
408
  divide(t) {
413
- return t instanceof d ? new d(
409
+ return t instanceof m ? new m(
414
410
  this.r / t.r,
415
411
  this.g / t.g,
416
412
  this.b / t.b,
417
413
  this.a / t.a
418
- ) : new d(
414
+ ) : new m(
419
415
  this.r / t,
420
416
  this.g / t,
421
417
  this.b / t,
@@ -423,12 +419,12 @@ class d {
423
419
  );
424
420
  }
425
421
  multiply(t) {
426
- return t instanceof d ? new d(
422
+ return t instanceof m ? new m(
427
423
  this.r * t.r,
428
424
  this.g * t.g,
429
425
  this.b * t.b,
430
426
  this.a * t.a
431
- ) : new d(
427
+ ) : new m(
432
428
  this.r * t,
433
429
  this.g * t,
434
430
  this.b * t,
@@ -438,25 +434,25 @@ class d {
438
434
  clamp() {
439
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));
440
436
  }
441
- static Red = new d(255, 0, 0, 255);
442
- static Green = new d(0, 255, 0, 255);
443
- static Blue = new d(0, 0, 255, 255);
444
- static Yellow = new d(255, 255, 0, 255);
445
- static Purple = new d(128, 0, 128, 255);
446
- static Orange = new d(255, 165, 0, 255);
447
- static Pink = new d(255, 192, 203, 255);
448
- static Gray = new d(128, 128, 128, 255);
449
- static Brown = new d(139, 69, 19, 255);
450
- static Cyan = new d(0, 255, 255, 255);
451
- static Magenta = new d(255, 0, 255, 255);
452
- static Lime = new d(192, 255, 0, 255);
453
- static White = new d(255, 255, 255, 255);
454
- static Black = new d(0, 0, 0, 255);
455
- static Transparent = new d(0, 0, 0, 0);
456
- static TRANSPARENT = new d(0, 0, 0, 0);
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);
457
453
  }
458
- const p = 6;
459
- class pt {
454
+ const R = 6;
455
+ class St {
460
456
  /** Total number of matrices currently allocated in the store. */
461
457
  matrixCount = 0;
462
458
  /** The dynamic buffer used to hold matrix data. */
@@ -468,7 +464,7 @@ class pt {
468
464
  * @param capacity - The initial capacity of the matrix store (default is 10).
469
465
  */
470
466
  constructor(t = 10) {
471
- this.buffer = new W(N.Float32), this.buffer.resize(t * p), this.data = this.buffer.getArray();
467
+ this.buffer = new D(I.Float32), this.buffer.resize(t * R), this.data = this.buffer.getArray();
472
468
  }
473
469
  /**
474
470
  * Allocates a new matrix and initializes it to the identity matrix.
@@ -483,7 +479,7 @@ class pt {
483
479
  * @returns The index of the newly allocated matrix.
484
480
  */
485
481
  allocDirty() {
486
- return this.buffer.resize(p) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += p, this.matrixCount++;
482
+ return this.buffer.resize(R) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += R, this.matrixCount++;
487
483
  }
488
484
  /**
489
485
  * Resets the store, clearing all allocated matrices.
@@ -496,7 +492,7 @@ class pt {
496
492
  * @param index - The index of the matrix to modify.
497
493
  */
498
494
  identity(t) {
499
- const e = t * p, i = this.data;
495
+ const e = t * R, i = this.data;
500
496
  i[e] = 1, i[e + 1] = 0, i[e + 2] = 0, i[e + 3] = 1, i[e + 4] = 0, i[e + 5] = 0;
501
497
  }
502
498
  /**
@@ -506,7 +502,7 @@ class pt {
506
502
  * @param y - The y translation.
507
503
  */
508
504
  translate(t, e, i) {
509
- const r = t * p, n = this.data;
505
+ const r = t * R, n = this.data;
510
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];
511
507
  }
512
508
  /**
@@ -516,7 +512,7 @@ class pt {
516
512
  * @param scaleY - The scale factor along the y-axis.
517
513
  */
518
514
  scale(t, e, i) {
519
- const r = t * p, n = this.data;
515
+ const r = t * R, n = this.data;
520
516
  n[r] *= e, n[r + 1] *= e, n[r + 2] *= i, n[r + 3] *= i;
521
517
  }
522
518
  /**
@@ -525,8 +521,8 @@ class pt {
525
521
  * @param radians - The rotation angle in radians.
526
522
  */
527
523
  rotate(t, e) {
528
- const i = t * p, r = this.data, n = Math.cos(e), a = Math.sin(e), o = r[i], h = r[i + 1], u = r[i + 2], c = r[i + 3];
529
- r[i] = o * n + u * a, r[i + 1] = h * n + c * a, r[i + 2] = o * -a + u * n, r[i + 3] = h * -a + c * n;
524
+ const i = t * R, 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;
530
526
  }
531
527
  /**
532
528
  * Rotates the matrix at the given index around a local offset point (pivot).
@@ -553,7 +549,7 @@ class pt {
553
549
  * @param src - The index of the source matrix.
554
550
  */
555
551
  copy(t, e) {
556
- const i = t * p, r = e * p, n = this.data;
552
+ const i = t * R, r = e * R, n = this.data;
557
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];
558
554
  }
559
555
  /**
@@ -571,21 +567,21 @@ class pt {
571
567
  * @param bIdx - The index of matrix B.
572
568
  */
573
569
  multiplyOut(t, e, i) {
574
- const r = t * p, n = e * p, a = i * p, o = this.data, h = o[n], u = o[n + 1], c = o[n + 2], m = o[n + 3], f = o[n + 4], v = o[n + 5], x = o[a], T = o[a + 1], E = o[a + 2], R = o[a + 3], _ = o[a + 4], A = o[a + 5];
575
- o[r] = h * x + c * T, o[r + 1] = u * x + m * T, o[r + 2] = h * E + c * R, o[r + 3] = u * E + m * R, o[r + 4] = h * _ + c * A + f, o[r + 5] = u * _ + m * A + v;
570
+ const r = t * R, n = e * R, a = i * R, 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], v = o[a + 2], y = o[a + 3], w = o[a + 4], T = o[a + 5];
571
+ o[r] = h * x + u * g, o[r + 1] = c * x + f * g, o[r + 2] = h * v + u * y, o[r + 3] = c * v + f * y, o[r + 4] = h * w + u * T + l, o[r + 5] = c * w + f * T + p;
576
572
  }
577
573
  /**
578
574
  * Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
579
575
  * @param index - The index of the matrix to invert.
580
576
  */
581
577
  invert(t) {
582
- const e = t * p, i = this.data, r = i[e], n = i[e + 1], a = i[e + 2], o = i[e + 3], h = i[e + 4], u = i[e + 5];
583
- let c = r * o - n * a;
584
- if (!c) {
578
+ const e = t * R, 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;
580
+ if (!u) {
585
581
  this.identity(t);
586
582
  return;
587
583
  }
588
- c = 1 / c, i[e] = o * c, i[e + 1] = -n * c, i[e + 2] = -a * c, i[e + 3] = r * c, i[e + 4] = (a * u - o * h) * c, i[e + 5] = (n * h - r * u) * c;
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;
589
585
  }
590
586
  /**
591
587
  * Transforms a point by the matrix at the given index.
@@ -595,7 +591,7 @@ class pt {
595
591
  * @returns The transformed point {x, y}.
596
592
  */
597
593
  transformPoint(t, e, i) {
598
- const r = t * p, n = this.data;
594
+ const r = t * R, n = this.data;
599
595
  return {
600
596
  x: e * n[r] + i * n[r + 2] + n[r + 4],
601
597
  y: e * n[r + 1] + i * n[r + 3] + n[r + 5]
@@ -613,7 +609,7 @@ class pt {
613
609
  const r = this.allocDirty();
614
610
  this.copy(r, t), this.invert(r);
615
611
  const n = this.transformPoint(r, e, i);
616
- return this.matrixCount--, this.buffer.usedElemNum -= p, n;
612
+ return this.matrixCount--, this.buffer.usedElemNum -= R, n;
617
613
  }
618
614
  /**
619
615
  * Transforms a point from local coordinates to world coordinates.
@@ -631,7 +627,7 @@ class pt {
631
627
  * @returns An object containing `x` and `y` global coordinates.
632
628
  */
633
629
  getPosition(t) {
634
- const e = t * p, i = this.data;
630
+ const e = t * R, i = this.data;
635
631
  return { x: i[e + 4], y: i[e + 5] };
636
632
  }
637
633
  /**
@@ -640,7 +636,7 @@ class pt {
640
636
  * @returns An object containing `x` and `y` global scale factors.
641
637
  */
642
638
  getScale(t) {
643
- const e = t * p, 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]);
639
+ const e = t * R, 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]);
644
640
  return { x: r, y: n };
645
641
  }
646
642
  /**
@@ -649,7 +645,7 @@ class pt {
649
645
  * @returns The global rotation in radians.
650
646
  */
651
647
  getRotation(t) {
652
- const e = t * p, i = this.data;
648
+ const e = t * R, i = this.data;
653
649
  return Math.atan2(i[e + 1], i[e]);
654
650
  }
655
651
  /**
@@ -660,7 +656,7 @@ class pt {
660
656
  * @returns A CSS matrix string.
661
657
  */
662
658
  toCSSMatrix(t, e = 1, i = 1) {
663
- const r = t * p, n = this.data;
659
+ const r = t * R, n = this.data;
664
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})`;
665
661
  }
666
662
  /**
@@ -671,8 +667,8 @@ class pt {
671
667
  * @returns A new Float32Array containing the 6 elements of the matrix.
672
668
  */
673
669
  getMatrix(t) {
674
- const e = t * p;
675
- return this.data.slice(e, e + p);
670
+ const e = t * R;
671
+ return this.data.slice(e, e + R);
676
672
  }
677
673
  /**
678
674
  * Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
@@ -682,8 +678,8 @@ class pt {
682
678
  * @returns A Float32Array view pointing directly to the matrix's data in memory.
683
679
  */
684
680
  getMatrixRef(t) {
685
- const e = t * p;
686
- return this.data.subarray(e, e + p);
681
+ const e = t * R;
682
+ return this.data.subarray(e, e + R);
687
683
  }
688
684
  /**
689
685
  * Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
@@ -692,25 +688,29 @@ class pt {
692
688
  * @param f - An array (Float32Array or standard number array) containing the 6 new elements.
693
689
  */
694
690
  setMatrix(t, e) {
695
- const i = t * p, r = this.data;
691
+ const i = t * R, r = this.data;
696
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];
697
693
  }
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;
697
+ }
698
698
  }
699
- class gt {
699
+ class bt {
700
700
  /** The underlying store for matrices. */
701
- matrix = new pt();
701
+ matrix = new St();
702
702
  /** The current step or depth in the transformation hierarchy. */
703
703
  step = 0;
704
704
  /** Internal stack maintaining structural information. */
705
- stack = new W(N.Uint32);
705
+ stack = new D(I.Uint32);
706
706
  /** Records the world matrices generated at each step. */
707
- stepWorldM = new W(N.Uint32);
707
+ stepWorldM = new D(I.Uint32);
708
708
  /** Records actions (push/pop) taken during the traversal. */
709
- stepAction = new W(N.Uint32);
709
+ stepAction = new D(I.Uint32);
710
710
  /** Records the parent world matrix for each step (used by updateMatrix). */
711
- stepParentM = new W(N.Uint32);
711
+ stepParentM = new D(I.Uint32);
712
712
  /** Buffer used during hierarchy traversal updates. */
713
- parentStack = new W(N.Uint32);
713
+ parentStack = new D(I.Uint32);
714
714
  /** The index of the current local matrix in the matrix store. */
715
715
  curLocalM = -1;
716
716
  /** The index of the current world matrix in the matrix store. */
@@ -749,8 +749,8 @@ class gt {
749
749
  const a = this.parentStack;
750
750
  for (a.reset(), a.push(i); n < this.stepAction.length; ) {
751
751
  if (this.stepAction.get(n) === 1) {
752
- const h = this.stepWorldM.get(n), u = h - 1, c = a.top();
753
- this.matrix.multiplyOut(h, c, u), a.push(h), r++;
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
754
  } else if (a.pop(), r--, r === 0)
755
755
  break;
756
756
  n++;
@@ -859,14 +859,14 @@ class gt {
859
859
  * Returns the current world matrix as Float32Array [a, b, c, d, tx, ty].
860
860
  */
861
861
  getTransform() {
862
- const t = this.curWorldM * p;
863
- return this.matrix.data.slice(t, t + p);
862
+ const t = this.curWorldM * R;
863
+ return this.matrix.data.slice(t, t + R);
864
864
  }
865
865
  /**
866
866
  * Directly overwrites the current world matrix with the given 6-element 2D transform.
867
867
  */
868
868
  setTransform(t) {
869
- const e = this.curWorldM * p, i = this.matrix.data;
869
+ const e = this.curWorldM * R, i = this.matrix.data;
870
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];
871
871
  }
872
872
  transformPoint(t, e) {
@@ -877,22 +877,39 @@ class gt {
877
877
  * Optionally saves the matrix first (saveTransform defaults to true).
878
878
  */
879
879
  applyTransform(t, e = 0, i = 0) {
880
- (t.saveTransform ?? !0) && this.save(), t.afterSave?.();
881
- const r = t.x ?? 0, n = t.y ?? 0;
882
- (r || n) && this.translate(r, n), t.position && this.translate(t.position.x, t.position.y), t.rotation && this.rotate(t.rotation);
883
- const a = t.scale, o = typeof a == "number";
884
- a && this.scale(
885
- o ? a : a.x,
886
- o ? a : a.y
887
- );
888
- let h = t.offsetX ?? 0, u = t.offsetY ?? 0;
889
- t.offset && (h += t.offset.x, u += t.offset.y);
890
- const c = t.origin;
891
- c !== void 0 && (typeof c == "number" ? (h -= c * e, u -= c * i) : (h -= c.x * e, u -= c.y * i)), this.translate(h, u);
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, v = x * a, y = -x * o, w = p * o, T = r + g * u + y * f, S = n + v * u + w * f;
892
+ (t.afterSave !== void 0 || t.saveTransform === !1) && this.matrix.multiplyAffineInPlace(
893
+ this.curLocalM,
894
+ g,
895
+ v,
896
+ y,
897
+ w,
898
+ T,
899
+ S
900
+ ), this.matrix.multiplyAffineInPlace(
901
+ this.curWorldM,
902
+ g,
903
+ v,
904
+ y,
905
+ w,
906
+ T,
907
+ S
908
+ ), t.afterSave?.();
892
909
  }
893
910
  }
894
- var H = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(H || {});
895
- class vt {
911
+ var z = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(z || {});
912
+ class At {
896
913
  render;
897
914
  cache = /* @__PURE__ */ new Map();
898
915
  constructor(t) {
@@ -907,10 +924,10 @@ class vt {
907
924
  async load(t, e) {
908
925
  let i = this.cache.get(t);
909
926
  if (i)
910
- return new C(i);
927
+ return new P(i);
911
928
  try {
912
929
  const r = await this._fetchImage(t);
913
- return i = D.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new C(i);
930
+ return i = B.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new P(i);
914
931
  } catch (r) {
915
932
  throw console.error(`[TextureManager] Failed to load: ${t}`, r), r;
916
933
  }
@@ -923,9 +940,9 @@ class vt {
923
940
  */
924
941
  create(t, e) {
925
942
  if (e?.key && this.cache.has(e.key))
926
- return new C(this.cache.get(e.key));
927
- const i = D.fromSource(this.render, t, e);
928
- return e?.key && (i.uid = e.key, this.cache.set(e.key, i)), new C(i);
943
+ return new P(this.cache.get(e.key));
944
+ const i = B.fromSource(this.render, t, e);
945
+ return e?.key && (i.uid = e.key, this.cache.set(e.key, i)), new P(i);
929
946
  }
930
947
  /**
931
948
  * Creates a generic Render Texture (FrameBuffer).
@@ -935,7 +952,7 @@ class vt {
935
952
  * @returns The newly created RenderTexture.
936
953
  */
937
954
  createRenderTexture(t) {
938
- return new Tt(this.render, t);
955
+ return new Ut(this.render, t);
939
956
  }
940
957
  /**
941
958
  * Creates a TextTexture for rendering text.
@@ -943,7 +960,7 @@ class vt {
943
960
  * @returns The newly created TextTexture.
944
961
  */
945
962
  createTextTexture(t) {
946
- return new Et(this.render, t);
963
+ return new Ct(this.render, t);
947
964
  }
948
965
  /**
949
966
  * Destroys a texture and potentially removes its BaseTexture from the cache.
@@ -954,7 +971,7 @@ class vt {
954
971
  */
955
972
  destroy(t, e = !1) {
956
973
  let i, r;
957
- typeof t == "string" ? (r = t, i = this.cache.get(r)) : t instanceof C ? (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));
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));
958
975
  }
959
976
  /**
960
977
  * Destroys all cached textures and clears the cache, ignoring reference counts.
@@ -971,7 +988,7 @@ class vt {
971
988
  });
972
989
  }
973
990
  }
974
- class D {
991
+ class B {
975
992
  glTexture = null;
976
993
  width;
977
994
  height;
@@ -988,8 +1005,8 @@ class D {
988
1005
  * @returns The created BaseTexture.
989
1006
  */
990
1007
  static fromSource(t, e, i = {}) {
991
- const r = X(t, e, i);
992
- return new D(r, e.width, e.height);
1008
+ const r = Z(t, e, i);
1009
+ return new B(r, e.width, e.height);
993
1010
  }
994
1011
  /**
995
1012
  * Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
@@ -998,19 +1015,19 @@ class D {
998
1015
  * @param source - The new image source.
999
1016
  */
1000
1017
  updateSource(t, e, i = {}) {
1001
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && Z(t, i.textureFilter), i.wrap !== void 0 && q(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));
1018
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && rt(t, i.textureFilter), i.wrap !== void 0 && it(t, i.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, i.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1002
1019
  }
1003
1020
  /**
1004
1021
  * Dynamically updates the texture filtering mode.
1005
1022
  */
1006
1023
  setFilterMode(t, e) {
1007
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), Z(t, e), t.bindTexture(t.TEXTURE_2D, null));
1024
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), rt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1008
1025
  }
1009
1026
  /**
1010
1027
  * Dynamically updates the texture wrap mode.
1011
1028
  */
1012
1029
  setWrapMode(t, e) {
1013
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), q(t, e), t.bindTexture(t.TEXTURE_2D, null));
1030
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), it(t, e), t.bindTexture(t.TEXTURE_2D, null));
1014
1031
  }
1015
1032
  /**
1016
1033
  * Destroys the WebGL texture resource.
@@ -1020,7 +1037,7 @@ class D {
1020
1037
  this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
1021
1038
  }
1022
1039
  }
1023
- class C {
1040
+ class P {
1024
1041
  base;
1025
1042
  uvX = 0;
1026
1043
  uvY = 0;
@@ -1077,7 +1094,7 @@ class C {
1077
1094
  * @returns A new Texture pointing to the sub-region.
1078
1095
  */
1079
1096
  getSubTexture(t, e, i, r) {
1080
- if (!this.base) return new C();
1097
+ if (!this.base) return new P();
1081
1098
  const n = this.clone(), a = this._px, o = this._py;
1082
1099
  return n.setRegion(a + t, o + e, i, r), n;
1083
1100
  }
@@ -1086,7 +1103,7 @@ class C {
1086
1103
  * @returns A new Texture instance.
1087
1104
  */
1088
1105
  clone(t) {
1089
- const e = t ?? new C(this.base);
1106
+ const e = t ?? new P(this.base);
1090
1107
  return t && this.base && t.setBase(this.base), e.scale = this.scale, e.uvX = this.uvX, e.uvY = this.uvY, e.uvW = this.uvW, e.uvH = this.uvH, e.rawWidth = this.rawWidth, e.rawHeight = this.rawHeight, e.offsetX = this.offsetX, e.offsetY = this.offsetY, e.flipY = this.flipY, e.isRotated = this.isRotated, e.isAtlas = this.isAtlas, e._px = this._px, e._py = this._py, e._pw = this._pw, e._ph = this._ph, e;
1091
1108
  }
1092
1109
  /**
@@ -1101,10 +1118,10 @@ class C {
1101
1118
  */
1102
1119
  splitGrid(t, e, i, r, n = 0) {
1103
1120
  if (!this.base) return [];
1104
- const a = [], o = this.rawWidth, h = this.rawHeight, u = Math.max(0, n), c = t + u, m = e + u, f = i ?? Math.floor((o + u) / c), v = r ?? Math.floor((h + u) / m);
1105
- for (let x = 0; x < v; x++)
1106
- for (let T = 0; T < f; T++)
1107
- a.push(this.getSubTexture(T * c, x * m, t, e));
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));
1108
1125
  return a;
1109
1126
  }
1110
1127
  /**
@@ -1113,8 +1130,8 @@ class C {
1113
1130
  * @param options - Optional antialias and wrap mode settings.
1114
1131
  */
1115
1132
  static fromImageSource(t, e, i = {}) {
1116
- const r = X(t, e, i);
1117
- return new C(new D(r, e.width, e.height));
1133
+ const r = Z(t, e, i);
1134
+ return new P(new B(r, e.width, e.height));
1118
1135
  }
1119
1136
  /**
1120
1137
  * Marks this Texture as destroyed, decrementing the BaseTexture reference count.
@@ -1123,7 +1140,7 @@ class C {
1123
1140
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
1124
1141
  }
1125
1142
  }
1126
- class Tt extends C {
1143
+ class Ut extends P {
1127
1144
  framebuffer;
1128
1145
  renderbuffer;
1129
1146
  gl;
@@ -1133,9 +1150,9 @@ class Tt extends C {
1133
1150
  _allocW = 0;
1134
1151
  _allocH = 0;
1135
1152
  constructor(t, e) {
1136
- super(), this.gl = t.gl, this.clearColor = e.clearColor ?? d.Black;
1137
- const i = Math.max(Math.round(e.width), 1), r = Math.max(Math.round(e.height), 1), a = X(t, { width: i, height: r }, { ...e, onlySize: !0 });
1138
- if (this.setBase(new D(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
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 = Z(t, { width: i, height: r }, { ...e, onlySize: !0 });
1155
+ if (this.setBase(new B(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1139
1156
  throw new Error("Failed to create Framebuffer or Renderbuffer");
1140
1157
  this.resize(i, r, !0);
1141
1158
  }
@@ -1192,10 +1209,10 @@ class Tt extends C {
1192
1209
  if (o <= 0 || h <= 0) return new Uint8Array(0);
1193
1210
  if (n < 0 || a < 0 || n >= this.rawWidth || a >= this.rawHeight)
1194
1211
  return new Uint8Array(0);
1195
- const u = Math.min(o, this.rawWidth - n), c = Math.min(h, this.rawHeight - a), m = this.rawHeight - a - c, f = this.gl, v = f.getParameter(f.FRAMEBUFFER_BINDING);
1196
- f.bindFramebuffer(f.FRAMEBUFFER, this.framebuffer);
1197
- const x = new Uint8Array(u * c * 4);
1198
- return f.readPixels(n, m, u, c, f.RGBA, f.UNSIGNED_BYTE, x), f.bindFramebuffer(f.FRAMEBUFFER, v), x;
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;
1199
1216
  }
1200
1217
  /**
1201
1218
  * Get the color at a pixel in the render texture.
@@ -1204,7 +1221,7 @@ class Tt extends C {
1204
1221
  */
1205
1222
  GetColorAt(t, e) {
1206
1223
  const i = this.GetPixels(t, e, 1, 1);
1207
- return i.length < 4 ? new d(0, 0, 0, 0) : new d(i[0], i[1], i[2], i[3]);
1224
+ return i.length < 4 ? new m(0, 0, 0, 0) : new m(i[0], i[1], i[2], i[3]);
1208
1225
  }
1209
1226
  /**
1210
1227
  * Destroys the framebuffer, renderbuffer, and base texture.
@@ -1213,7 +1230,7 @@ class Tt extends C {
1213
1230
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
1214
1231
  }
1215
1232
  }
1216
- const yt = {
1233
+ const _t = {
1217
1234
  fontFamily: "Arial",
1218
1235
  fontSize: 24,
1219
1236
  fontWeight: "normal",
@@ -1222,7 +1239,7 @@ const yt = {
1222
1239
  align: "left",
1223
1240
  baseline: "top"
1224
1241
  };
1225
- class Et extends C {
1242
+ class Ct extends P {
1226
1243
  canvas;
1227
1244
  ctx;
1228
1245
  render;
@@ -1231,12 +1248,12 @@ class Et extends C {
1231
1248
  options;
1232
1249
  flipY = !0;
1233
1250
  constructor(t, e) {
1234
- super(), this.render = t, this._style = { ...yt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1251
+ super(), this.render = t, this._style = { ..._t, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1235
1252
  const i = this.canvas.getContext("2d", { willReadFrequently: !0 });
1236
1253
  if (!i) throw new Error("Failed to get 2d context for TextTexture");
1237
1254
  this.ctx = i, this.canvas.width = 1, this.canvas.height = 1;
1238
- const r = X(t, this.canvas, this.options);
1239
- this.setBase(new D(r, 1, 1)), this.update();
1255
+ const r = Z(t, this.canvas, this.options);
1256
+ this.setBase(new B(r, 1, 1)), this.update();
1240
1257
  }
1241
1258
  get text() {
1242
1259
  return this._text;
@@ -1288,30 +1305,30 @@ class Et extends C {
1288
1305
  t.font = n;
1289
1306
  const o = this._text.split(`
1290
1307
  `);
1291
- let h = 0, u = 0;
1308
+ let h = 0, c = 0;
1292
1309
  t.textBaseline = "alphabetic";
1293
- const c = t.measureText(o[0]), m = c.fontBoundingBoxAscent, f = c.fontBoundingBoxDescent;
1294
- for (const A of o) {
1295
- const g = t.measureText(A);
1296
- g.width > h && (h = g.width), u += m + f;
1310
+ const u = t.measureText(o[0]), f = u.fontBoundingBoxAscent, l = u.fontBoundingBoxDescent;
1311
+ for (const T of o) {
1312
+ const S = t.measureText(T);
1313
+ S.width > h && (h = S.width), c += f + l;
1297
1314
  }
1298
- u -= f;
1299
- const v = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + v) || 1, T = Math.ceil(u + v) || 1, E = x * a, R = T * a;
1300
- (this.canvas.width !== E || this.canvas.height !== R) && (this.canvas.width = E, this.canvas.height = R), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, T), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, T);
1301
- let _ = v / 2;
1302
- for (const A of o) {
1303
- let g = v / 2;
1304
- this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(A, g, _)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(A, g, _)), _ += m + f;
1315
+ c -= l;
1316
+ const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1, g = Math.ceil(c + p) || 1, v = x * a, y = g * a;
1317
+ (this.canvas.width !== v || this.canvas.height !== y) && (this.canvas.width = v, 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 T of o) {
1320
+ let S = p / 2;
1321
+ this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(T, S, w)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(T, S, w)), w += f + l;
1305
1322
  }
1306
1323
  this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
1307
1324
  }
1308
1325
  }
1309
- const Rt = (s, t = !1, e = !0) => {
1326
+ const Pt = (s, t = !1, e = !0) => {
1310
1327
  const i = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1311
1328
  if (!i)
1312
1329
  throw new Error("WebGL2 is not supported in this browser.");
1313
1330
  return i;
1314
- }, et = (s, t, e) => {
1331
+ }, ct = (s, t, e) => {
1315
1332
  const i = s.createShader(e);
1316
1333
  if (!i)
1317
1334
  throw new Error("Unable to create webgl shader");
@@ -1320,8 +1337,8 @@ const Rt = (s, t = !1, e = !0) => {
1320
1337
  throw console.error("Shader compilation failed:", n), new Error("Unable to compile shader: " + n + t);
1321
1338
  }
1322
1339
  return i;
1323
- }, Mt = (s, t, e) => {
1324
- var i = s.createProgram(), r = et(s, t, 35633), n = et(s, e, 35632);
1340
+ }, Nt = (s, t, e) => {
1341
+ var i = s.createProgram(), r = ct(s, t, 35633), n = ct(s, e, 35632);
1325
1342
  if (!i)
1326
1343
  throw new Error("Unable to create program shader");
1327
1344
  if (s.attachShader(i, r), s.attachShader(i, n), s.linkProgram(i), !s.getProgramParameter(i, s.LINK_STATUS)) {
@@ -1330,26 +1347,26 @@ const Rt = (s, t = !1, e = !0) => {
1330
1347
  }
1331
1348
  return i;
1332
1349
  };
1333
- function q(s, t) {
1350
+ function it(s, t) {
1334
1351
  const e = {
1335
- [H.CLAMP]: s.CLAMP_TO_EDGE,
1336
- [H.REPEAT]: s.REPEAT,
1337
- [H.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1352
+ [z.CLAMP]: s.CLAMP_TO_EDGE,
1353
+ [z.REPEAT]: s.REPEAT,
1354
+ [z.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1338
1355
  }[t] || s.CLAMP_TO_EDGE;
1339
1356
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, e);
1340
1357
  }
1341
- function Z(s, t) {
1358
+ function rt(s, t) {
1342
1359
  const e = {
1343
- [Q.LINEAR]: s.LINEAR,
1344
- [Q.NEAREST]: s.NEAREST
1360
+ [nt.LINEAR]: s.LINEAR,
1361
+ [nt.NEAREST]: s.NEAREST
1345
1362
  }[t] ?? s.NEAREST;
1346
1363
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, e);
1347
1364
  }
1348
- function X(s, t, e) {
1365
+ function Z(s, t, e) {
1349
1366
  const i = s.gl, r = i.createTexture();
1350
1367
  if (!r)
1351
1368
  throw new Error("Unable to create WebGL texture");
1352
- if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1), q(i, e.wrap ?? H.CLAMP), Z(i, e.textureFilter ?? s.textureFilter), e.onlySize) {
1369
+ if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1), it(i, e.wrap ?? z.CLAMP), rt(i, e.textureFilter ?? s.textureFilter), e.onlySize) {
1353
1370
  const n = t;
1354
1371
  i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, n.width, n.height, 0, i.RGBA, i.UNSIGNED_BYTE, null);
1355
1372
  } else {
@@ -1358,7 +1375,7 @@ function X(s, t, e) {
1358
1375
  }
1359
1376
  return i.bindTexture(i.TEXTURE_2D, null), r;
1360
1377
  }
1361
- function F(s, t) {
1378
+ function W(s, t) {
1362
1379
  if (s.includes("%TEXTURE_NUM%") && (s = s.replace("%TEXTURE_NUM%", t.toString())), s.includes("%GET_COLOR%")) {
1363
1380
  let e = "";
1364
1381
  for (let i = 0; i < t; i++)
@@ -1367,15 +1384,15 @@ function F(s, t) {
1367
1384
  }
1368
1385
  return s;
1369
1386
  }
1370
- const wt = 5126, it = 5121;
1371
- function bt(s, t, e) {
1387
+ const Lt = 5126, st = 5121;
1388
+ function It(s, t, e) {
1372
1389
  s.vertexAttribDivisor(t, e);
1373
1390
  }
1374
- function At(s, t, e, i, r) {
1391
+ function Tt(s, t, e, i, r) {
1375
1392
  s.drawArraysInstanced(t, e, i, r);
1376
1393
  }
1377
- let St = 0;
1378
- class ct {
1394
+ let Ot = 0;
1395
+ class yt {
1379
1396
  program;
1380
1397
  attributeLoc = {};
1381
1398
  uniformLoc = {};
@@ -1387,11 +1404,11 @@ class ct {
1387
1404
  /** Whether the uniform is an array (e.g. sampler2D uTextures[8]) */
1388
1405
  uniformIsArray = {};
1389
1406
  gl;
1390
- shaderId = St++;
1407
+ shaderId = Ot++;
1391
1408
  // for debug
1392
1409
  vao;
1393
1410
  constructor(t, e, i, r) {
1394
- this.gl = t, this.program = Mt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
1411
+ this.gl = t, this.program = Nt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
1395
1412
  }
1396
1413
  /** Switch GPU to use this shader program */
1397
1414
  use() {
@@ -1417,7 +1434,7 @@ class ct {
1417
1434
  const i = this.uniformLoc[t];
1418
1435
  if (i === void 0) return;
1419
1436
  const r = this.uniformType[t], n = this.uniformIsArray[t];
1420
- Ut(this.gl, i, r, e, n);
1437
+ Wt(this.gl, i, r, e, n);
1421
1438
  }
1422
1439
  /**
1423
1440
  * Batch-set uniforms via a plain value map.
@@ -1444,11 +1461,11 @@ class ct {
1444
1461
  i.vertexAttribPointer(
1445
1462
  e,
1446
1463
  t.size,
1447
- t.type ?? wt,
1464
+ t.type ?? Lt,
1448
1465
  t.normalized ?? !1,
1449
1466
  t.stride,
1450
1467
  t.offset ?? 0
1451
- ), i.enableVertexAttribArray(e), bt(i, e, t.divisor ?? 0);
1468
+ ), i.enableVertexAttribArray(e), It(i, e, t.divisor ?? 0);
1452
1469
  }
1453
1470
  /** Bind all vertex attribute pointers at once */
1454
1471
  setAttributes(t) {
@@ -1471,12 +1488,12 @@ class ct {
1471
1488
  const r = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
1472
1489
  if (r)
1473
1490
  for (const n of r) {
1474
- const a = n.split(/\s+/), o = a[1], h = a[2].replace(/\[\d+\]$/, ""), u = e.getUniformLocation(this.program, h);
1475
- u !== null && (this.uniformLoc[h] = u, this.uniformType[h] = o, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
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]));
1476
1493
  }
1477
1494
  }
1478
1495
  }
1479
- function Ut(s, t, e, i, r = !1) {
1496
+ function Wt(s, t, e, i, r = !1) {
1480
1497
  switch (e) {
1481
1498
  // scalars
1482
1499
  case "float":
@@ -1512,10 +1529,10 @@ function Ut(s, t, e, i, r = !1) {
1512
1529
  return s.uniformMatrix4fv(t, !1, i);
1513
1530
  // fallback: guess by value shape
1514
1531
  default:
1515
- return _t(s, t, i);
1532
+ return Ft(s, t, i);
1516
1533
  }
1517
1534
  }
1518
- function _t(s, t, e) {
1535
+ function Ft(s, t, e) {
1519
1536
  if (typeof e == "number")
1520
1537
  return s.uniform1f(t, e);
1521
1538
  const i = e;
@@ -1534,7 +1551,7 @@ function _t(s, t, e) {
1534
1551
  return s.uniform1fv(t, i);
1535
1552
  }
1536
1553
  }
1537
- class rt {
1554
+ class ut {
1538
1555
  /** Custom vertex shader code */
1539
1556
  vs;
1540
1557
  /** Custom fragment shader code */
@@ -1606,7 +1623,8 @@ class rt {
1606
1623
  return n.isCustom = !0, n.padding = this.padding, this.glshader.set(e, n), this.uniformDirty.add(e), n;
1607
1624
  }
1608
1625
  }
1609
- class lt {
1626
+ const K = 1 / 0;
1627
+ class Rt {
1610
1628
  constructor(t) {
1611
1629
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
1612
1630
  }
@@ -1649,7 +1667,7 @@ class lt {
1649
1667
  return r == -1 ? (this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(i), this.usedTextures.length - 1) : r;
1650
1668
  }
1651
1669
  createShader(t, e) {
1652
- return new ct(this.gl, t, e);
1670
+ return new yt(this.gl, t, e);
1653
1671
  }
1654
1672
  createCustomShader(t) {
1655
1673
  return t.getGLShader(this, this.KEY, this.vs, this.fs);
@@ -1657,7 +1675,7 @@ class lt {
1657
1675
  getCustomShader(t) {
1658
1676
  if (!t)
1659
1677
  return this.defaultShader;
1660
- if (t instanceof rt) {
1678
+ if (t instanceof ut) {
1661
1679
  const e = this.createCustomShader(t);
1662
1680
  return e ?? this.defaultShader;
1663
1681
  }
@@ -1672,7 +1690,7 @@ class lt {
1672
1690
  return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
1673
1691
  }
1674
1692
  enter(t) {
1675
- this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof rt ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
1693
+ this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ut ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
1676
1694
  }
1677
1695
  exit() {
1678
1696
  this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
@@ -1706,7 +1724,7 @@ class lt {
1706
1724
  return !1;
1707
1725
  }
1708
1726
  }
1709
- const z = `#version 300 es\r
1727
+ const q = `#version 300 es\r
1710
1728
  precision mediump float;\r
1711
1729
  \r
1712
1730
  // per-vertex\r
@@ -1754,7 +1772,7 @@ void main(void) {\r
1754
1772
  \r
1755
1773
  gl_Position = u_projection * position;\r
1756
1774
  }\r
1757
- `, st = `#version 300 es\r
1775
+ `, lt = `#version 300 es\r
1758
1776
  precision mediump float;\r
1759
1777
  \r
1760
1778
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1803,8 +1821,8 @@ void main(void) {\r
1803
1821
  \r
1804
1822
  // CUSTOM_CODE_CALL\r
1805
1823
  }\r
1806
- `, k = 48, Ct = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1807
- class dt extends lt {
1824
+ `, V = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1825
+ class at extends Rt {
1808
1826
  instanceBuffer;
1809
1827
  quadBuffer;
1810
1828
  instanceCount = 0;
@@ -1816,28 +1834,28 @@ class dt extends lt {
1816
1834
  }
1817
1835
  createBuffer() {
1818
1836
  const t = this.gl;
1819
- this.quadBuffer = new j(t, N.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1820
- for (const e of Ct) this.quadBuffer.pushFloat32(e);
1821
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new j(t, N.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1837
+ this.quadBuffer = new et(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1838
+ for (const e of Dt) this.quadBuffer.pushFloat32(e);
1839
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, I.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1822
1840
  }
1823
1841
  createDefaultShader() {
1824
- const t = this.rapid, e = F(st, t.maxTextureUnits), i = F(z, t.maxTextureUnits);
1842
+ const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
1825
1843
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
1826
1844
  }
1827
1845
  createShader(t, e) {
1828
1846
  const i = super.createShader(t, e);
1829
1847
  return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
1830
- { name: "aMatrixRow0", size: 3, stride: k, offset: 0, divisor: 1 },
1831
- { name: "aMatrixRow1", size: 3, stride: k, offset: 12, divisor: 1 },
1832
- { name: "aUVRect", size: 4, stride: k, offset: 24, divisor: 1 },
1833
- { name: "aColor", size: 4, type: it, normalized: !0, stride: k, offset: 40, divisor: 1 },
1834
- { name: "aTextureId", size: 1, type: it, stride: k, offset: 44, divisor: 1 }
1848
+ { name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
1849
+ { name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
1850
+ { name: "aUVRect", size: 4, stride: V, offset: 24, divisor: 1 },
1851
+ { name: "aColor", size: 4, type: st, normalized: !0, stride: V, offset: 40, divisor: 1 },
1852
+ { name: "aTextureId", size: 1, type: st, stride: V, offset: 44, divisor: 1 }
1835
1853
  ]), this.quadBuffer.bindBuffer(), i.setAttributes([
1836
1854
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1837
1855
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1838
1856
  }
1839
1857
  createCustomShader(t) {
1840
- const e = F(st, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1858
+ const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1841
1859
  return t.getGLShader(this, this.KEY, i, e);
1842
1860
  }
1843
1861
  /**
@@ -1852,24 +1870,46 @@ class dt extends lt {
1852
1870
  * @param v1 Bottom UV mapped coordinate (default 1).
1853
1871
  * @param color The tint color as packed ABGR uniform uint32 (default 0xFFFFFFFF).
1854
1872
  */
1855
- drawSprite(t, e, i = 0, r = 0, n = 1, a = 1, o = 4294967295, h = 0, u = 0, c = !1, m = !1, f = !1) {
1856
- this.freeTextureUnitNum === 0 && this.flush();
1857
- const v = t.base, x = t.scale || 1, T = t.rawWidth, E = t.rawHeight, R = t.offsetX, _ = t.offsetY, A = this.useTexture(
1873
+ drawSprite(t, e, i = 0, r = 0, n = 1, a = 1, o = 4294967295, h = 0, c = 0, u = !1, f = !1, l = !1) {
1874
+ const p = e * 6, x = this.matrixStore.data;
1875
+ this.drawSpriteAffine(
1876
+ t,
1877
+ x[p],
1878
+ x[p + 1],
1879
+ x[p + 2],
1880
+ x[p + 3],
1881
+ x[p + 4],
1882
+ x[p + 5],
1883
+ i,
1884
+ r,
1885
+ n,
1886
+ a,
1887
+ o,
1888
+ h,
1889
+ c,
1890
+ u,
1891
+ f,
1892
+ l
1893
+ );
1894
+ }
1895
+ drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, g = !1, v = !1, y = !1) {
1896
+ (this.freeTextureUnitNum === 0 || this.instanceCount > K) && this.flush();
1897
+ const w = t.base, T = t.scale ?? 1, S = t.rawWidth, F = t.rawHeight, O = t.offsetX, N = t.offsetY, A = this.useTexture(
1858
1898
  t.glTexture,
1859
- h / x / v.width,
1860
- u / x / v.height
1861
- ), g = e * 6, M = this.matrixStore.data, L = this.instanceBuffer, S = L.usedElemNum;
1862
- L.resize(12);
1863
- const U = L.float32, O = L.uint32, B = (f ? E : T) * x, K = (f ? T : E) * x, P = B + 2 * h, I = K + 2 * u, Y = R - h, tt = _ - u, y = this.localSpriteMatrix;
1864
- f ? (y[0] = 0, y[1] = m ? I : -I, y[2] = c ? -P : P, y[3] = 0, y[4] = Y + (c ? P : 0), y[5] = tt + (m ? 0 : I)) : (y[0] = c ? -P : P, y[1] = 0, y[2] = 0, y[3] = m ? -I : I, y[4] = Y + (c ? P : 0), y[5] = tt + (m ? I : 0));
1865
- const w = this.worldSpriteMatrix;
1866
- w[0] = M[g] * y[0] + M[g + 2] * y[1], w[1] = M[g + 1] * y[0] + M[g + 3] * y[1], w[2] = M[g] * y[2] + M[g + 2] * y[3], w[3] = M[g + 1] * y[2] + M[g + 3] * y[3], w[4] = M[g + 4] + M[g] * y[4] + M[g + 2] * y[5], w[5] = M[g + 5] + M[g + 1] * y[4] + M[g + 3] * y[5], U[S + 6] = i, U[S + 7] = r, U[S + 8] = n, U[S + 9] = a, O[S + 10] = o, O[S + 11] = A, this.rapid.roundPixels && (w[4] = Math.round(w[4]), w[5] = Math.round(w[5])), U[S] = w[0], U[S + 1] = w[2], U[S + 2] = w[4], U[S + 3] = w[1], U[S + 4] = w[3], U[S + 5] = w[5], L.usedElemNum += 12, L.makeDirty(), this.instanceCount++;
1899
+ p / T / w.width,
1900
+ x / T / w.height
1901
+ ), M = this.instanceBuffer, b = M.usedElemNum;
1902
+ M.resize(12);
1903
+ const U = M.float32, L = M.uint32, $ = (y ? F : S) * T, J = (y ? S : F) * T, k = $ + 2 * p, G = J + 2 * x, ht = O - p, ot = N - x, E = this.localSpriteMatrix;
1904
+ y ? (E[0] = 0, E[1] = v ? G : -G, E[2] = g ? -k : k, E[3] = 0, E[4] = ht + (g ? k : 0), E[5] = ot + (v ? 0 : G)) : (E[0] = g ? -k : k, E[1] = 0, E[2] = 0, E[3] = v ? -G : G, E[4] = ht + (g ? k : 0), E[5] = ot + (v ? G : 0));
1905
+ const _ = this.worldSpriteMatrix;
1906
+ _[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] = A, 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], M.usedElemNum += 12, M.makeDirty(), this.instanceCount++;
1867
1907
  }
1868
1908
  render() {
1869
1909
  if (this.instanceCount === 0) return;
1870
1910
  super.render();
1871
1911
  const t = this.gl, e = this.currentShader;
1872
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), At(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1912
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Tt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1873
1913
  }
1874
1914
  resetRender() {
1875
1915
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1878,7 +1918,7 @@ class dt extends lt {
1878
1918
  return this.instanceCount > 0;
1879
1919
  }
1880
1920
  }
1881
- const Nt = `#version 300 es\r
1921
+ const Bt = `#version 300 es\r
1882
1922
  precision mediump float;\r
1883
1923
  \r
1884
1924
  in vec2 aPosition;\r
@@ -1909,7 +1949,7 @@ void main(void) {\r
1909
1949
  // CUSTOM_CODE_CALL\r
1910
1950
  gl_Position = u_projection * position;\r
1911
1951
  }\r
1912
- `, Lt = `#version 300 es\r
1952
+ `, kt = `#version 300 es\r
1913
1953
  precision mediump float;\r
1914
1954
  \r
1915
1955
  in vec4 vColor;\r
@@ -1955,7 +1995,7 @@ void main(void) {\r
1955
1995
  fragColor = sampleTexture(vRegion);\r
1956
1996
  // CUSTOM_CODE_CALL\r
1957
1997
  }\r
1958
- `, Pt = `#version 300 es\r
1998
+ `, Gt = `#version 300 es\r
1959
1999
  precision mediump float;\r
1960
2000
  \r
1961
2001
  in vec2 aPosition;\r
@@ -1978,7 +2018,7 @@ void main(void) {\r
1978
2018
  );\r
1979
2019
  gl_Position = u_projection * position;\r
1980
2020
  }\r
1981
- `, It = `#version 300 es\r
2021
+ `, Ht = `#version 300 es\r
1982
2022
  precision mediump float;\r
1983
2023
  \r
1984
2024
  in vec2 vRegion;\r
@@ -1998,8 +2038,8 @@ void main(void) {\r
1998
2038
  discard;\r
1999
2039
  }\r
2000
2040
  }\r
2001
- `, G = 20;
2002
- class Ot extends lt {
2041
+ `, Y = 20;
2042
+ class Vt extends Rt {
2003
2043
  vertexBuffer;
2004
2044
  vertexCount = 0;
2005
2045
  matrixIndex = -1;
@@ -2012,24 +2052,24 @@ class Ot extends lt {
2012
2052
  }
2013
2053
  createBuffer() {
2014
2054
  const t = this.gl;
2015
- this.vertexBuffer = new j(t, N.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Pt, It);
2055
+ this.vertexBuffer = new et(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Ht);
2016
2056
  }
2017
2057
  createDefaultShader() {
2018
- return this.vs = Nt, this.fs = Lt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2058
+ return this.vs = Bt, this.fs = kt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2019
2059
  }
2020
2060
  createMaskShader(t, e) {
2021
- const i = this.gl, r = new ct(i, t, e);
2061
+ const i = this.gl, r = new yt(i, t, e);
2022
2062
  return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2023
- { name: "aPosition", size: 2, type: i.FLOAT, stride: G - 4, offset: 0, divisor: 0 },
2024
- { name: "aUV", size: 2, type: i.FLOAT, stride: G - 4, offset: 8, divisor: 0 }
2063
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: Y - 4, offset: 0, divisor: 0 },
2064
+ { name: "aUV", size: 2, type: i.FLOAT, stride: Y - 4, offset: 8, divisor: 0 }
2025
2065
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2026
2066
  }
2027
2067
  createShader(t, e) {
2028
2068
  const i = this.gl, r = super.createShader(t, e);
2029
2069
  return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
2030
- { name: "aPosition", size: 2, type: i.FLOAT, stride: G, offset: 0, divisor: 0 },
2031
- { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: G, offset: 8, divisor: 0 },
2032
- { name: "aUV", size: 2, type: i.FLOAT, stride: G, offset: 12, divisor: 0 }
2070
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: Y, offset: 0, divisor: 0 },
2071
+ { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: Y, offset: 8, divisor: 0 },
2072
+ { name: "aUV", size: 2, type: i.FLOAT, stride: Y, offset: 12, divisor: 0 }
2033
2073
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2034
2074
  }
2035
2075
  /**
@@ -2039,7 +2079,7 @@ class Ot extends lt {
2039
2079
  * @param texture Optional texture to apply over the polygon.
2040
2080
  */
2041
2081
  startGraphic(t, e = this.gl.TRIANGLES, i) {
2042
- this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture = i;
2082
+ this.vertexBuffer.clear(), this.vertexCount = 0, this.matrixIndex = t, this.drawMode = e, this.texture = i, this.texture?.glTexture && this.useTexture(this.texture.glTexture, 0, 0);
2043
2083
  }
2044
2084
  /**
2045
2085
  * Adds a vertex to the current polygon. Local coordinates and color settings.
@@ -2067,21 +2107,21 @@ class Ot extends lt {
2067
2107
  this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r[i], r[i + 2], n]), e.setUniform("uMatrixRow1", [r[i + 1], r[i + 3], a]), e.setUniform(
2068
2108
  "uUVRect",
2069
2109
  this.texture ? [this.texture.uvX, this.texture.uvY, this.texture.uvW, this.texture.uvH] : [0, 0, 1, 1]
2070
- ), 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++;
2110
+ ), 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;
2071
2111
  }
2072
2112
  hasPendingContent() {
2073
2113
  return !1;
2074
2114
  }
2075
2115
  }
2076
- class l {
2116
+ class d {
2077
2117
  x;
2078
2118
  y;
2079
- static ZERO = new l(0, 0);
2080
- static ONE = new l(1, 1);
2081
- static UP = new l(0, 1);
2082
- static DOWN = new l(0, -1);
2083
- static LEFT = new l(-1, 0);
2084
- static RIGHT = new l(1, 0);
2119
+ static ZERO = new d(0, 0);
2120
+ static ONE = new d(1, 1);
2121
+ static UP = new d(0, 1);
2122
+ static DOWN = new d(0, -1);
2123
+ static LEFT = new d(-1, 0);
2124
+ static RIGHT = new d(1, 0);
2085
2125
  constructor(t, e) {
2086
2126
  this.x = t !== void 0 ? t : 0, this.y = e !== void 0 ? e : 0;
2087
2127
  }
@@ -2089,22 +2129,22 @@ class l {
2089
2129
  return e === void 0 ? (this.x = t, this.y = t) : (this.x = t, this.y = e), this;
2090
2130
  }
2091
2131
  add(t) {
2092
- return new l(this.x + t.x, this.y + t.y);
2132
+ return new d(this.x + t.x, this.y + t.y);
2093
2133
  }
2094
2134
  subtract(t) {
2095
- return new l(this.x - t.x, this.y - t.y);
2135
+ return new d(this.x - t.x, this.y - t.y);
2096
2136
  }
2097
2137
  sub(t) {
2098
- return new l(this.x - t.x, this.y - t.y);
2138
+ return new d(this.x - t.x, this.y - t.y);
2099
2139
  }
2100
2140
  multiply(t) {
2101
- return t instanceof l ? new l(this.x * t.x, this.y * t.y) : new l(this.x * t, this.y * t);
2141
+ return t instanceof d ? new d(this.x * t.x, this.y * t.y) : new d(this.x * t, this.y * t);
2102
2142
  }
2103
2143
  mul(t) {
2104
2144
  return this.multiply(t);
2105
2145
  }
2106
2146
  divide(t) {
2107
- return t instanceof l ? new l(this.x / t.x, this.y / t.y) : new l(this.x / t, this.y / t);
2147
+ return t instanceof d ? new d(this.x / t.x, this.y / t.y) : new d(this.x / t, this.y / t);
2108
2148
  }
2109
2149
  dot(t) {
2110
2150
  return this.x * t.x + this.y * t.y;
@@ -2117,13 +2157,13 @@ class l {
2117
2157
  return Math.sqrt(e * e + i * i);
2118
2158
  }
2119
2159
  clone() {
2120
- return new l(this.x, this.y);
2160
+ return new d(this.x, this.y);
2121
2161
  }
2122
2162
  to(t) {
2123
2163
  this.x = t.x, this.y = t.y;
2124
2164
  }
2125
2165
  copy() {
2126
- return new l(this.x, this.y);
2166
+ return new d(this.x, this.y);
2127
2167
  }
2128
2168
  equals(t) {
2129
2169
  return t.x == this.x && t.y == this.y;
@@ -2136,7 +2176,7 @@ class l {
2136
2176
  return this.x = -this.x, this.y = -this.y, this;
2137
2177
  }
2138
2178
  inverted() {
2139
- return new l(this.x * -1, this.y * -1);
2179
+ return new d(this.x * -1, this.y * -1);
2140
2180
  }
2141
2181
  length() {
2142
2182
  return Math.sqrt(this.x * this.x + this.y * this.y);
@@ -2150,13 +2190,13 @@ class l {
2150
2190
  }
2151
2191
  normalized() {
2152
2192
  const t = this.length();
2153
- return new l(this.x / t || 0, this.y / t || 0);
2193
+ return new d(this.x / t || 0, this.y / t || 0);
2154
2194
  }
2155
2195
  fix(t = 1e-13) {
2156
2196
  this.x = Math.abs(this.x) < t ? 0 : this.x, this.y = Math.abs(this.y) < t ? 0 : this.y;
2157
2197
  }
2158
2198
  fixed(t = 1e-13) {
2159
- return new l(
2199
+ return new d(
2160
2200
  Math.abs(this.x) < t ? 0 : this.x,
2161
2201
  Math.abs(this.y) < t ? 0 : this.y
2162
2202
  );
@@ -2165,13 +2205,13 @@ class l {
2165
2205
  return Math.atan2(this.y, this.x);
2166
2206
  }
2167
2207
  abs() {
2168
- return new l(Math.abs(this.x), Math.abs(this.y));
2208
+ return new d(Math.abs(this.x), Math.abs(this.y));
2169
2209
  }
2170
2210
  floor() {
2171
- return new l(Math.floor(this.x), Math.floor(this.y));
2211
+ return new d(Math.floor(this.x), Math.floor(this.y));
2172
2212
  }
2173
2213
  ceil() {
2174
- return new l(Math.ceil(this.x), Math.ceil(this.y));
2214
+ return new d(Math.ceil(this.x), Math.ceil(this.y));
2175
2215
  }
2176
2216
  stringify() {
2177
2217
  return `Vec2(${this.x}, ${this.y})`;
@@ -2192,101 +2232,129 @@ class l {
2192
2232
  return this.x = Math.cos(t) * e, this.y = Math.sin(t) * e, this;
2193
2233
  }
2194
2234
  static FromArray(t) {
2195
- return t.map((e) => new l(e[0], e[1]));
2235
+ return t.map((e) => new d(e[0], e[1]));
2196
2236
  }
2197
2237
  static fromAngle(t) {
2198
- return new l(Math.cos(t), Math.sin(t));
2238
+ return new d(Math.cos(t), Math.sin(t));
2199
2239
  }
2200
2240
  }
2201
- const $ = 10, nt = (s, t, e, i, r, n) => {
2202
- const a = [], o = [], h = i ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), u = Math.PI, c = new l(t.y, -t.x);
2203
- for (let m = 0; m < $; m++) {
2204
- const f = m / $, v = (m + 1) / $, x = h + f * u, T = h + v * u, E = new l(Math.cos(x) * e, Math.sin(x) * e), R = new l(Math.cos(T) * e, Math.sin(T) * e);
2205
- a.push(s), o.push(new l(r, 0.5)), a.push(s.add(E)), o.push(new l(r + E.dot(c) * n, 0.5 - 0.5 * E.dot(t) / e)), a.push(s.add(R)), o.push(new l(r + R.dot(c) * n, 0.5 - 0.5 * R.dot(t) / e));
2241
+ const Yt = (s, t) => {
2242
+ const [e, i, r, n, a, o] = t, h = new Float32Array([
2243
+ e,
2244
+ n,
2245
+ 0,
2246
+ 0,
2247
+ i,
2248
+ a,
2249
+ 0,
2250
+ 0,
2251
+ r,
2252
+ o,
2253
+ 1,
2254
+ 0,
2255
+ 0,
2256
+ 0,
2257
+ 0,
2258
+ 1
2259
+ ]);
2260
+ return zt(s, h);
2261
+ }, zt = (s, t) => {
2262
+ const e = new Float32Array(16);
2263
+ for (let i = 0; i < 4; i++)
2264
+ for (let r = 0; r < 4; r++) {
2265
+ let n = 0;
2266
+ for (let a = 0; a < 4; a++)
2267
+ n += s[r * 4 + a] * t[a * 4 + i];
2268
+ e[r * 4 + i] = n;
2269
+ }
2270
+ return e;
2271
+ };
2272
+ var Xt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Xt || {});
2273
+ const tt = 10, dt = (s, t, e, i, r, n) => {
2274
+ const a = [], o = [], h = i ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new d(t.y, -t.x);
2275
+ for (let f = 0; f < tt; f++) {
2276
+ const l = f / tt, p = (f + 1) / tt, x = h + l * c, g = h + p * c, v = new d(Math.cos(x) * e, Math.sin(x) * e), y = new d(Math.cos(g) * e, Math.sin(g) * e);
2277
+ a.push(s), o.push(new d(r, 0.5)), a.push(s.add(v)), o.push(new d(r + v.dot(u) * n, 0.5 - 0.5 * v.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));
2206
2278
  }
2207
2279
  return { vertices: a, uv: o };
2208
- }, Ft = (s, t = !1) => {
2280
+ }, $t = (s, t = !1) => {
2209
2281
  const e = [];
2210
2282
  if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
2211
2283
  const i = 4, r = 1e-3, n = s.length;
2212
2284
  let a = 0;
2213
2285
  if (t)
2214
2286
  for (let h = 0; h < n; h++) {
2215
- const u = s[h], c = s[(h + 1) % n];
2216
- a += u.distanceTo(c);
2287
+ const c = s[h], u = s[(h + 1) % n];
2288
+ a += c.distanceTo(u);
2217
2289
  }
2218
2290
  else
2219
2291
  for (let h = 0; h < n - 1; h++)
2220
2292
  a += s[h].distanceTo(s[h + 1]);
2221
- const o = (h, u, c) => {
2222
- const m = u.subtract(h).normalize(), f = u.subtract(c).normalize(), v = f.dot(m);
2223
- if (v < -1 + r)
2224
- return { normal: m.perpendicular(), miters: 1 };
2293
+ const o = (h, c, u) => {
2294
+ const f = c.subtract(h).normalize(), l = c.subtract(u).normalize(), p = l.dot(f);
2295
+ if (p < -1 + r)
2296
+ return { normal: f.perpendicular(), miters: 1 };
2225
2297
  {
2226
- let x = f.add(m).normalize();
2227
- m.cross(f) < 0 && (x = x.multiply(-1));
2228
- let T = 1 / Math.sqrt((1 - v) / 2);
2229
- return { normal: x, miters: Math.min(T, i) };
2298
+ let x = l.add(f).normalize();
2299
+ f.cross(l) < 0 && (x = x.multiply(-1));
2300
+ let g = 1 / Math.sqrt((1 - p) / 2);
2301
+ return { normal: x, miters: Math.min(g, i) };
2230
2302
  }
2231
2303
  };
2232
2304
  if (t)
2233
2305
  for (let h = 0; h < n; h++) {
2234
- const u = h === 0 ? s[n - 1] : s[h - 1], c = s[h], m = h === n - 1 ? s[0] : s[h + 1];
2235
- e.push(o(u, c, m));
2306
+ const c = h === 0 ? s[n - 1] : s[h - 1], u = s[h], f = h === n - 1 ? s[0] : s[h + 1];
2307
+ e.push(o(c, u, f));
2236
2308
  }
2237
2309
  else
2238
2310
  for (let h = 0; h < n; h++)
2239
2311
  if (h === 0) {
2240
- const u = s[1].subtract(s[0]).normalize();
2241
- e.push({ normal: u.perpendicular(), miters: 1 });
2312
+ const c = s[1].subtract(s[0]).normalize();
2313
+ e.push({ normal: c.perpendicular(), miters: 1 });
2242
2314
  } else if (h === n - 1) {
2243
- const u = s[h].subtract(s[h - 1]).normalize();
2244
- e.push({ normal: u.perpendicular(), miters: 1 });
2315
+ const c = s[h].subtract(s[h - 1]).normalize();
2316
+ e.push({ normal: c.perpendicular(), miters: 1 });
2245
2317
  } else
2246
2318
  e.push(o(s[h - 1], s[h], s[h + 1]));
2247
2319
  return { normals: e, length: a };
2248
- }, Wt = (s) => {
2320
+ }, jt = (s) => {
2249
2321
  const t = s.points;
2250
2322
  if (t.length < 2) return { vertices: [], uv: [] };
2251
- const { normals: e, length: i } = Ft(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2252
- let u = 0;
2253
- const c = s.texture?.rawWidth || 1, m = s.closed ? t.length : t.length - 1;
2254
- for (let f = 0; f < m; f++) {
2255
- const v = t[f], x = e[f].normal, T = e[f].miters, E = (f + 1) % t.length, R = t[E], _ = e[E].normal, A = e[E].miters, g = v.add(x.multiply(T * r)), M = v.subtract(x.multiply(T * r)), L = R.add(_.multiply(A * r)), S = R.subtract(_.multiply(A * r)), U = v.distanceTo(R);
2256
- let O = 0, B = 0;
2257
- h === 0 ? (O = u / i, B = (u + U) / i) : (O = u / c, B = O + U / c);
2258
- const K = new l(O, 0), P = new l(O, 1), I = new l(B, 0), Y = new l(B, 1);
2259
- n.push(g), a.push(K), n.push(M), a.push(P), n.push(L), a.push(I), n.push(L), a.push(I), n.push(S), a.push(Y), n.push(M), a.push(P), u += U;
2323
+ const { normals: e, length: i } = $t(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2324
+ let c = 0;
2325
+ const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
2326
+ for (let l = 0; l < f; l++) {
2327
+ const p = t[l], x = e[l].normal, g = e[l].miters, v = (l + 1) % t.length, y = t[v], w = e[v].normal, T = e[v].miters, S = p.add(x.multiply(g * r)), F = p.subtract(x.multiply(g * r)), O = y.add(w.multiply(T * r)), N = y.subtract(w.multiply(T * r)), A = p.distanceTo(y);
2328
+ let M = 0, b = 0;
2329
+ h === 0 ? (M = c / i, b = (c + A) / i) : (M = c / u, b = M + A / u);
2330
+ const U = new d(M, 0), L = new d(M, 1), $ = new d(b, 0), J = new d(b, 1);
2331
+ n.push(S), a.push(U), n.push(F), a.push(L), n.push(O), a.push($), n.push(O), a.push($), n.push(N), a.push(J), n.push(F), a.push(L), c += A;
2260
2332
  }
2261
2333
  if (o && !s.closed) {
2262
- const f = t[0], v = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / c, T = nt(f, v, r, !0, 0, x);
2263
- n.push(...T.vertices), a.push(...T.uv);
2264
- const E = t[t.length - 1], R = e[t.length - 1].normal, _ = h === 0 ? 1 : u / c, A = h === 0 ? i > 0 ? 1 / i : 0 : 1 / c, g = nt(E, R, r, !1, _, A);
2334
+ const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, g = dt(l, p, r, !0, 0, x);
2265
2335
  n.push(...g.vertices), a.push(...g.uv);
2336
+ const v = t[t.length - 1], y = e[t.length - 1].normal, w = h === 0 ? 1 : c / u, T = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, S = dt(v, y, r, !1, w, T);
2337
+ n.push(...S.vertices), a.push(...S.uv);
2266
2338
  }
2267
2339
  return { vertices: n, uv: a };
2268
- }, Dt = (s) => s.saveTransform !== void 0 || s.afterSave !== void 0 || s.x !== void 0 || s.y !== void 0 || s.position !== void 0 || s.rotation !== void 0 || s.scale !== void 0 || s.offsetX !== void 0 || s.offsetY !== void 0 || s.offset !== void 0 || s.origin !== void 0, V = (s, t, e, i, r) => {
2269
- if (!Dt(t)) {
2270
- r();
2271
- return;
2272
- }
2340
+ }, X = (s, t, e, i, r) => {
2273
2341
  s.matrixStack.applyTransform(t, e, i);
2274
2342
  try {
2275
2343
  r();
2276
2344
  } finally {
2277
- (t.saveTransform ?? !0) && s.matrixStack.restore();
2345
+ t.saveTransform !== !1 && s.matrixStack.restore();
2278
2346
  }
2279
- }, J = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Bt = 2, ft = (s, t) => {
2347
+ }, Q = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, Et = (s, t) => {
2280
2348
  const e = t.texture;
2281
2349
  if (!e?.base || s.inCreateMask)
2282
2350
  return;
2283
2351
  const i = e.isAtlas ? s.atlasSpriteRegion : s.spriteRegion;
2284
2352
  s.enterRegion(i, t.shader);
2285
2353
  let r = e.uvX, n = e.uvY, a = e.uvW, o = e.uvH;
2286
- const h = !!t.flipX, u = !!t.flipY != !!e.flipY;
2287
- let c = t.padding ?? i.currentShader.padding;
2288
- e.isAtlas && (c += Bt);
2289
- const m = r <= a ? c : -c, f = n <= o ? c : -c;
2354
+ const h = !!t.flipX, c = !!t.flipY != !!e.flipY;
2355
+ let u = t.padding ?? i.currentShader.padding;
2356
+ e.isAtlas && (u += Kt);
2357
+ const f = r <= a ? u : -u, l = n <= o ? u : -u;
2290
2358
  i.drawSprite(
2291
2359
  e,
2292
2360
  t.customMatrix ?? s.matrixStack.curWorldM,
@@ -2294,19 +2362,66 @@ const $ = 10, nt = (s, t, e, i, r, n) => {
2294
2362
  n,
2295
2363
  a,
2296
2364
  o,
2297
- J(s, t.color),
2298
- m,
2365
+ Q(s, t.color),
2299
2366
  f,
2367
+ l,
2300
2368
  h,
2301
- u,
2369
+ c,
2302
2370
  e.isRotated
2303
2371
  );
2304
- }, kt = (s, t) => {
2305
- V(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2306
- ft(s, t);
2372
+ }, qt = (s, t) => {
2373
+ X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2374
+ Et(s, t);
2307
2375
  });
2308
- }, mt = (s, t) => {
2309
- t.points.length !== 0 && V(s, t, 0, 0, () => {
2376
+ }, Zt = (s, t) => {
2377
+ const e = s.particleRegion;
2378
+ s.enterRegion(e, t.shader);
2379
+ const i = t.texture, r = i.uvX, n = i.uvY, a = i.uvW, o = i.uvH;
2380
+ e.drawParticle(
2381
+ i,
2382
+ t.x,
2383
+ t.y,
2384
+ t.scaleX,
2385
+ t.scaleY,
2386
+ t.rotation,
2387
+ r,
2388
+ n,
2389
+ a,
2390
+ o,
2391
+ Q(s, t.color),
2392
+ t.flipX,
2393
+ t.flipY,
2394
+ t.isRotated
2395
+ );
2396
+ }, Qt = (s, t) => {
2397
+ const e = s.particleRegion;
2398
+ s.enterRegion(e, t.shader);
2399
+ const i = t.texture, r = t.count ?? t.x.length, n = t.color, a = n.length, o = new Array(a);
2400
+ if (s.premultipliedAlpha)
2401
+ for (let h = 0; h < a; h++)
2402
+ o[h] = n[h].premultipliedUint32;
2403
+ else
2404
+ for (let h = 0; h < a; h++)
2405
+ o[h] = n[h].uint32;
2406
+ e.drawParticles(
2407
+ i,
2408
+ t.x,
2409
+ t.y,
2410
+ t.rotation,
2411
+ o,
2412
+ r,
2413
+ t.scaleX,
2414
+ t.scaleY,
2415
+ i.uvX,
2416
+ i.uvY,
2417
+ i.uvW,
2418
+ i.uvH,
2419
+ t.flipX,
2420
+ t.flipY,
2421
+ t.isRotated
2422
+ );
2423
+ }, wt = (s, t) => {
2424
+ t.points.length !== 0 && X(s, t, 0, 0, () => {
2310
2425
  s.startGraphic(
2311
2426
  t.drawMode ?? s.gl.TRIANGLES,
2312
2427
  t.texture,
@@ -2320,31 +2435,31 @@ const $ = 10, nt = (s, t, e, i, r, n) => {
2320
2435
  i.y,
2321
2436
  r?.x ?? 0,
2322
2437
  r?.y ?? 0,
2323
- J(s, n)
2438
+ Q(s, n)
2324
2439
  );
2325
2440
  }
2326
2441
  s.endGraphic();
2327
2442
  });
2328
- }, Gt = (s, t) => {
2443
+ }, Jt = (s, t) => {
2329
2444
  if (s.inCreateMask)
2330
2445
  return;
2331
- const { vertices: e, uv: i } = Wt(t);
2332
- mt(s, {
2446
+ const { vertices: e, uv: i } = jt(t);
2447
+ wt(s, {
2333
2448
  ...t,
2334
2449
  points: e,
2335
2450
  uv: i,
2336
2451
  drawMode: s.gl.TRIANGLES
2337
2452
  });
2338
- }, Ht = (s, t) => {
2339
- V(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2453
+ }, te = (s, t) => {
2454
+ X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2340
2455
  s.startMaskGraphic(
2341
2456
  s.gl.TRIANGLE_FAN,
2342
2457
  t.texture,
2343
2458
  t.customMatrix
2344
2459
  ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2345
2460
  });
2346
- }, Vt = (s, t) => {
2347
- V(s, t, t.width, t.height, () => {
2461
+ }, ee = (s, t) => {
2462
+ X(s, t, t.width, t.height, () => {
2348
2463
  s.startGraphic(
2349
2464
  s.gl.TRIANGLE_FAN,
2350
2465
  t.texture,
@@ -2352,19 +2467,19 @@ const $ = 10, nt = (s, t, e, i, r, n) => {
2352
2467
  t.customMatrix
2353
2468
  ), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
2354
2469
  });
2355
- }, Yt = (s, t) => {
2470
+ }, ie = (s, t) => {
2356
2471
  const e = t.segments ?? 32;
2357
- V(s, t, 0, 0, () => {
2472
+ X(s, t, 0, 0, () => {
2358
2473
  s.startGraphic(
2359
2474
  s.gl.TRIANGLE_FAN,
2360
2475
  void 0,
2361
2476
  t.shader,
2362
2477
  t.customMatrix
2363
2478
  );
2364
- const i = J(s, t.color);
2479
+ const i = Q(s, t.color);
2365
2480
  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();
2366
2481
  });
2367
- }, at = `#version 300 es\r
2482
+ }, ft = `#version 300 es\r
2368
2483
  precision mediump float;\r
2369
2484
  \r
2370
2485
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -2414,22 +2529,137 @@ void main(void) {\r
2414
2529
  // CUSTOM_CODE_CALL\r
2415
2530
  }\r
2416
2531
  `;
2417
- class zt extends dt {
2532
+ class re extends at {
2418
2533
  KEY = "AtlasSprite";
2419
2534
  constructor(t) {
2420
2535
  super(t);
2421
2536
  }
2422
2537
  createCustomShader(t) {
2423
- const e = F(at, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2538
+ const e = W(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2424
2539
  return t.getGLShader(this, this.KEY, i, e);
2425
2540
  }
2426
2541
  createDefaultShader() {
2427
- const t = this.rapid, e = F(at, t.maxTextureUnits), i = F(z, t.maxTextureUnits);
2542
+ const t = this.rapid, e = W(ft, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
2428
2543
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
2429
2544
  }
2430
2545
  }
2431
- var Xt = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(Xt || {}), Kt = /* @__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))(Kt || {}), Q = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(Q || {}), $t = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))($t || {});
2432
- class Qt {
2546
+ const mt = `#version 300 es\r
2547
+ precision mediump float;\r
2548
+ \r
2549
+ // per-vertex\r
2550
+ in vec2 aVertex;\r
2551
+ \r
2552
+ // per-instance: 变换\r
2553
+ in vec2 aPosition;\r
2554
+ in vec2 aScale;\r
2555
+ in float aRotation;\r
2556
+ \r
2557
+ // per-instance:UV 区域 (u0, v0, u1, v1)\r
2558
+ in vec4 aUVRect;\r
2559
+ \r
2560
+ // per-instance:tint color\r
2561
+ in vec4 aColor;\r
2562
+ uniform mat4 u_projection;\r
2563
+ \r
2564
+ out vec2 vRegion;\r
2565
+ out vec4 vColor;\r
2566
+ // CUSTOM_CODE\r
2567
+ \r
2568
+ void main(void) {\r
2569
+ vColor = aColor;\r
2570
+ \r
2571
+ //vRegion = mix(aUVRect.xy, aUVRect.zw, vertex.xy);\r
2572
+ vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
2573
+ // CUSTOM_CODE_CALL\r
2574
+ \r
2575
+ vec2 v;\r
2576
+ v.x = (aVertex.x) * cos(aRotation) - (aVertex.y) * sin(aRotation);\r
2577
+ v.y = (aVertex.x) * sin(aRotation) + (aVertex.y) * cos(aRotation);\r
2578
+ v = v * aScale + aPosition;\r
2579
+ gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
2580
+ }\r
2581
+ `, xt = `#version 300 es\r
2582
+ precision mediump float;\r
2583
+ \r
2584
+ uniform sampler2D uTexture;\r
2585
+ \r
2586
+ in vec2 vRegion;\r
2587
+ in vec4 vColor;\r
2588
+ out vec4 fragColor;\r
2589
+ \r
2590
+ // CUSTOM_CODE\r
2591
+ \r
2592
+ void main(void) {\r
2593
+ fragColor = texture(uTexture, vRegion) * vColor;\r
2594
+ \r
2595
+ // CUSTOM_CODE_CALL\r
2596
+ }\r
2597
+ `, H = 40, j = H / 4;
2598
+ class se extends at {
2599
+ KEY = "ParticleSprite";
2600
+ texture;
2601
+ constructor(t) {
2602
+ super(t);
2603
+ }
2604
+ createCustomShader(t) {
2605
+ return t.getGLShader(this, this.KEY, mt, xt);
2606
+ }
2607
+ createDefaultShader() {
2608
+ const t = xt, e = mt;
2609
+ return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
2610
+ }
2611
+ enter(t) {
2612
+ super.enter(t), this.currentShader.setUniform("u_projection", this.rapid.projection);
2613
+ }
2614
+ createShader(t, e) {
2615
+ const i = super.createShader(t, e);
2616
+ return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
2617
+ { name: "aPosition", size: 2, stride: H, offset: 0, divisor: 1 },
2618
+ { name: "aScale", size: 2, stride: H, offset: 8, divisor: 1 },
2619
+ { name: "aRotation", size: 1, stride: H, offset: 16, divisor: 1 },
2620
+ { name: "aUVRect", size: 4, stride: H, offset: 20, divisor: 1 },
2621
+ { name: "aColor", size: 4, type: st, normalized: !0, stride: H, offset: 36, divisor: 1 }
2622
+ ]), this.quadBuffer.bindBuffer(), i.setAttributes([
2623
+ { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2624
+ ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2625
+ }
2626
+ drawParticle(t, e = 0, i = 0, r = 1, n = 1, a = 0, o = 0, h = 0, c = 1, u = 1, f = 4294967295, l = !1, p = !1, x = !1) {
2627
+ (this.instanceCount >= K || this.texture && t != this.texture) && this.flush(), t.glTexture && (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2628
+ const g = this.instanceBuffer, v = g.usedElemNum, y = t.rawWidth, w = t.rawHeight;
2629
+ g.resize(j);
2630
+ const T = g.float32, S = g.uint32;
2631
+ T[v] = e, T[v + 1] = i, T[v + 2] = r * (l ? -1 : 1) * y, T[v + 3] = n * (p ? -1 : 1) * w, T[v + 4] = a, x && (T[v + 4] += Math.PI / 2), T[v + 5] = o, T[v + 6] = h, T[v + 7] = c, T[v + 8] = u, S[v + 9] = f, g.usedElemNum += j, g.makeDirty(), this.instanceCount++;
2632
+ }
2633
+ 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) {
2634
+ if (!t.glTexture || a <= 0) return;
2635
+ let v = 0;
2636
+ const y = t.rawWidth * o * (p ? -1 : 1), w = t.rawHeight * h * (x ? -1 : 1), T = g ? Math.PI / 2 : 0;
2637
+ for (; v < a; ) {
2638
+ this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2639
+ const S = a - v, F = K - this.instanceCount, O = Math.min(S, F), N = this.instanceBuffer;
2640
+ let A = N.usedElemNum;
2641
+ N.resize(O * j);
2642
+ const M = N.float32, b = N.uint32;
2643
+ for (let U = 0; U < O; U++) {
2644
+ const L = v + U;
2645
+ M[A] = e[L], M[A + 1] = i[L], M[A + 2] = y, M[A + 3] = w, M[A + 4] = r[L] + T, M[A + 5] = c, M[A + 6] = u, M[A + 7] = f, M[A + 8] = l, b[A + 9] = n[L], A += j;
2646
+ }
2647
+ N.usedElemNum = A, N.makeDirty(), this.instanceCount += O, v += O, this.instanceCount >= K && this.flush();
2648
+ }
2649
+ }
2650
+ render() {
2651
+ if (this.instanceCount === 0) return;
2652
+ super.render();
2653
+ const t = this.gl;
2654
+ this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2655
+ const e = this.currentShader;
2656
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2657
+ const i = Yt(this.rapid.projection, this.worldSpriteMatrix);
2658
+ this.currentShader.setUniform("u_projection", i), Tt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
2659
+ }
2660
+ }
2661
+ var ne = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(ne || {}), ae = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(ae || {}), nt = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(nt || {}), he = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(he || {});
2662
+ class le {
2433
2663
  /** The active WebGL context. */
2434
2664
  gl;
2435
2665
  /** The target HTMLCanvasElement. */
@@ -2441,7 +2671,7 @@ class Qt {
2441
2671
  /** The current device pixel ratio. */
2442
2672
  dpr;
2443
2673
  /** Background clear color [r, g, b, a], values range from 0 to 255. */
2444
- backgroundColor = d.Black;
2674
+ backgroundColor = m.Black;
2445
2675
  /** Logical width in CSS pixels, used for coordinate system and projection matrix. */
2446
2676
  logicWidth = 0;
2447
2677
  /** Logical height in CSS pixels, used for coordinate system and projection matrix. */
@@ -2455,7 +2685,7 @@ class Qt {
2455
2685
  /** Maximum number of texture units supported by the device. */
2456
2686
  maxTextureUnits = 0;
2457
2687
  /** Matrix stack for hierarchical transformations. */
2458
- matrixStack = new gt(this);
2688
+ matrixStack = new bt(this);
2459
2689
  /** Direct access to the underlying matrix store. */
2460
2690
  matrix;
2461
2691
  /** Region dedicated to fast sprite rendering. */
@@ -2463,6 +2693,7 @@ class Qt {
2463
2693
  /** Region dedicated to arbitrary geometry and shapes rendering. */
2464
2694
  graphicRegion;
2465
2695
  atlasSpriteRegion;
2696
+ particleRegion;
2466
2697
  /** Counts the number of WebGL draw calls made in the current frame. */
2467
2698
  drawcallCount = 0;
2468
2699
  /** Indicates whether we are currently writing to the stencil buffer to create a mask. */
@@ -2479,7 +2710,7 @@ class Qt {
2479
2710
  scaleMode;
2480
2711
  /** Internal ping-pong RenderTextures for multi-filter chains. */
2481
2712
  _filterRT = [null, null];
2482
- _filterInput = new C();
2713
+ _filterInput = new P();
2483
2714
  get height() {
2484
2715
  return this.logicHeight;
2485
2716
  }
@@ -2492,10 +2723,10 @@ class Qt {
2492
2723
  */
2493
2724
  constructor(t) {
2494
2725
  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;
2495
- const e = Rt(this.canvas, this.antialias, this.premultipliedAlpha);
2496
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new dt(this), this.graphicRegion = new Ot(this), this.atlasSpriteRegion = new zt(this);
2726
+ const e = Pt(this.canvas, this.antialias, this.premultipliedAlpha);
2727
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new at(this), this.graphicRegion = new Vt(this), this.atlasSpriteRegion = new re(this), this.particleRegion = new se(this);
2497
2728
  const i = this.canvas.clientWidth || this.canvas.width, r = this.canvas.clientHeight || this.canvas.height;
2498
- this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * this.dpr), this.logicWidth = t.logicWidth || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new vt(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);
2729
+ this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new At(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
2499
2730
  }
2500
2731
  setTextureFilter(t) {
2501
2732
  this.textureFilter = t;
@@ -2514,20 +2745,26 @@ class Qt {
2514
2745
  enterRegion(t, e) {
2515
2746
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2516
2747
  }
2748
+ drawParticle(t) {
2749
+ Zt(this, t);
2750
+ }
2751
+ drawParticles(t) {
2752
+ Qt(this, t);
2753
+ }
2517
2754
  drawSprite(t) {
2518
- kt(this, t);
2755
+ qt(this, t);
2519
2756
  }
2520
2757
  drawLine(t) {
2521
- Gt(this, t);
2758
+ Jt(this, t);
2522
2759
  }
2523
2760
  drawGraphic(t) {
2524
- mt(this, t);
2761
+ wt(this, t);
2525
2762
  }
2526
2763
  drawRect(t) {
2527
- Vt(this, t);
2764
+ ee(this, t);
2528
2765
  }
2529
2766
  drawCircle(t) {
2530
- Yt(this, t);
2767
+ ie(this, t);
2531
2768
  }
2532
2769
  /**
2533
2770
  * Starts rendering arbitrary graphics geometries.
@@ -2551,7 +2788,7 @@ class Qt {
2551
2788
  * @param texture The texture to be used as a mask.
2552
2789
  */
2553
2790
  drawMaskImage(t) {
2554
- Ht(this, t);
2791
+ te(this, t);
2555
2792
  }
2556
2793
  /**
2557
2794
  * Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
@@ -2572,8 +2809,8 @@ class Qt {
2572
2809
  addCircleVertex(t, e, i = 32) {
2573
2810
  const r = Math.PI * 2 / i, n = this.getColorUint32(e);
2574
2811
  for (let a = 0; a < i; a++) {
2575
- const o = r * a, h = Math.cos(o) * t, u = Math.sin(o) * t, c = 0.5 + Math.cos(o) * 0.5, m = 0.5 + Math.sin(o) * 0.5;
2576
- this.addGraphicVertex(h, u, c, m, n);
2812
+ 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;
2813
+ this.addGraphicVertex(h, c, u, f, n);
2577
2814
  }
2578
2815
  }
2579
2816
  /**
@@ -2659,21 +2896,21 @@ class Qt {
2659
2896
  applyFilters(t, e) {
2660
2897
  if (e.length === 0)
2661
2898
  throw new Error("applyFilters: shaders array must not be empty.");
2662
- const i = Math.max(...e.map((u) => u.padding)), r = i, n = t.rawWidth + i * 2, a = t.rawHeight + i * 2;
2663
- for (let u = 0; u < 2; u++)
2664
- this._filterRT[u] ? this._filterRT[u].resize(n, a) : this._filterRT[u] = this.texture.createRenderTexture({ width: n, height: a });
2899
+ const i = Math.max(...e.map((c) => c.padding)), r = i, n = t.rawWidth + i * 2, a = t.rawHeight + i * 2;
2900
+ for (let c = 0; c < 2; c++)
2901
+ this._filterRT[c] ? this._filterRT[c].resize(n, a) : this._filterRT[c] = this.texture.createRenderTexture({ width: n, height: a });
2665
2902
  let o = t.clone(this._filterInput), h = 0;
2666
2903
  this.matrixStack.save(), this.matrixStack.identity();
2667
- for (let u = 0; u < e.length; u++) {
2668
- const c = this._filterRT[h % 2];
2669
- c.offsetX = 0, c.offsetY = 0, this.enterRenderTexture(c), this.clearRenderTexture(), this.drawSprite({
2904
+ for (let c = 0; c < e.length; c++) {
2905
+ const u = this._filterRT[h % 2];
2906
+ u.offsetX = 0, u.offsetY = 0, this.enterRenderTexture(u), this.clearRenderTexture(), this.drawSprite({
2670
2907
  texture: o,
2671
- shader: e[u],
2672
- offsetX: u == 0 ? r : 0,
2908
+ shader: e[c],
2909
+ offsetX: c == 0 ? r : 0,
2673
2910
  // padding back
2674
- offsetY: u == 0 ? r : 0,
2911
+ offsetY: c == 0 ? r : 0,
2675
2912
  padding: i
2676
- }), this.leaveRenderTexture(), o = c, h++;
2913
+ }), this.leaveRenderTexture(), o = u, h++;
2677
2914
  }
2678
2915
  return this.matrixStack.restore(), o.offsetX = -r, o.offsetY = -r, o;
2679
2916
  }
@@ -2687,7 +2924,7 @@ class Qt {
2687
2924
  * @param rt The render texture to clear.
2688
2925
  * @param color Clear color. Defaults to transparent black (0, 0, 0, 0).
2689
2926
  */
2690
- clearRenderTexture(t = new d(0, 0, 0, 0)) {
2927
+ clearRenderTexture(t = new m(0, 0, 0, 0)) {
2691
2928
  this.flush();
2692
2929
  const e = this.gl;
2693
2930
  t.setClearColor(e), e.clear(e.COLOR_BUFFER_BIT);
@@ -2709,7 +2946,7 @@ class Qt {
2709
2946
  * rapid.drawSprite({ texture: mySprite });
2710
2947
  * });
2711
2948
  */
2712
- drawToRenderTexture(t, e, i = new d(0, 0, 0, 0)) {
2949
+ drawToRenderTexture(t, e, i = new m(0, 0, 0, 0)) {
2713
2950
  this.enterRenderTexture(t);
2714
2951
  try {
2715
2952
  i !== null && this.clearRenderTexture(i), e();
@@ -2907,8 +3144,8 @@ class Qt {
2907
3144
  */
2908
3145
  startScissor(t, e, i, r) {
2909
3146
  this.flush();
2910
- const n = this.gl, a = this.physicsWidth / this.logicWidth, o = this.physicsHeight / this.logicHeight, h = Math.round(t * a), u = Math.round(this.physicsHeight - (e + r) * o), c = Math.round(i * a), m = Math.round(r * o);
2911
- n.enable(n.SCISSOR_TEST), n.scissor(h, u, c, m);
3147
+ 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);
3148
+ n.enable(n.SCISSOR_TEST), n.scissor(h, c, u, f);
2912
3149
  }
2913
3150
  /**
2914
3151
  * Disables scissor clipping, restoring full-canvas rendering.
@@ -2922,13 +3159,13 @@ class Qt {
2922
3159
  this.matrix.invert(e);
2923
3160
  }
2924
3161
  logicToPhysics(t) {
2925
- return t.multiply(new l(
3162
+ return t.multiply(new d(
2926
3163
  this.physicsWidth / this.logicWidth,
2927
3164
  this.physicsHeight / this.logicHeight
2928
3165
  ));
2929
3166
  }
2930
3167
  physicsToLogic(t) {
2931
- return t.multiply(new l(
3168
+ return t.multiply(new d(
2932
3169
  this.logicWidth / this.physicsWidth,
2933
3170
  this.logicHeight / this.physicsHeight
2934
3171
  ));
@@ -2956,10 +3193,10 @@ class Qt {
2956
3193
  return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, i);
2957
3194
  }
2958
3195
  }
2959
- function jt(s) {
2960
- return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof l || s instanceof d);
3196
+ function oe(s) {
3197
+ return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof d || s instanceof m);
2961
3198
  }
2962
- class b {
3199
+ class C {
2963
3200
  /** Random float in [min, max). */
2964
3201
  static float(t, e) {
2965
3202
  return Math.random() * (e - t) + t;
@@ -2974,20 +3211,20 @@ class b {
2974
3211
  }
2975
3212
  /** Random Vec2 with components in the supplied per-axis ranges. */
2976
3213
  static vector(t, e, i, r) {
2977
- return new l(b.float(t, e), b.float(i, r));
3214
+ return new d(C.float(t, e), C.float(i, r));
2978
3215
  }
2979
3216
  /** Random Color with each component interpolated between minColor and maxColor. */
2980
3217
  static randomColor(t, e) {
2981
- return new d(
2982
- b.float(t.r, e.r),
2983
- b.float(t.g, e.g),
2984
- b.float(t.b, e.b),
2985
- b.float(t.a, e.a)
3218
+ return new m(
3219
+ C.float(t.r, e.r),
3220
+ C.float(t.g, e.g),
3221
+ C.float(t.b, e.b),
3222
+ C.float(t.a, e.a)
2986
3223
  );
2987
3224
  }
2988
3225
  /** Pick a random element from an array with uniform probability. */
2989
3226
  static pick(t) {
2990
- return t[b.int(0, t.length - 1)];
3227
+ return t[C.int(0, t.length - 1)];
2991
3228
  }
2992
3229
  /**
2993
3230
  * Pick a random element using weighted probability.
@@ -3013,18 +3250,18 @@ class b {
3013
3250
  if (Array.isArray(t)) {
3014
3251
  const [i, r] = t;
3015
3252
  if (typeof i == "number")
3016
- return b.float(i, r);
3017
- if (i instanceof l)
3018
- return b.vector(i.x, r.x, i.y, r.y);
3253
+ return C.float(i, r);
3019
3254
  if (i instanceof d)
3020
- return b.randomColor(i, r);
3255
+ return C.vector(i.x, r.x, i.y, r.y);
3256
+ if (i instanceof m)
3257
+ return C.randomColor(i, r);
3021
3258
  }
3022
3259
  return typeof t == "number" ? t : t.clone();
3023
3260
  }
3024
3261
  }
3025
- var qt = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(qt || {});
3026
- const ht = 10, ot = 0, ut = !0;
3027
- class Zt {
3262
+ var ce = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(ce || {});
3263
+ const pt = 10, gt = 0, vt = !0;
3264
+ class ue {
3028
3265
  life = 0;
3029
3266
  maxLife;
3030
3267
  texture;
@@ -3033,20 +3270,19 @@ class Zt {
3033
3270
  datas;
3034
3271
  rapid;
3035
3272
  constructor(t, e) {
3036
- this.rapid = t, this.options = e, e.texture instanceof C ? this.texture = e.texture : e.texture instanceof Array && e.texture[0] instanceof Array ? this.texture = b.pickWeight(e.texture) : e.texture instanceof Array && (this.texture = b.pick(e.texture)), this.maxLife = b.scalarOrRange(e.life, 1), this.datas = {
3273
+ this.rapid = t, this.options = e, e.texture instanceof P ? this.texture = e.texture : e.texture instanceof Array && e.texture[0] instanceof Array ? this.texture = C.pickWeight(e.texture) : e.texture instanceof Array && (this.texture = C.pick(e.texture)), this.maxLife = C.scalarOrRange(e.life, 1), this.datas = {
3037
3274
  speed: this.processAttribute(e.animation.speed, 0),
3038
3275
  rotation: this.processAttribute(e.animation.rotation, 0),
3039
3276
  scale: this.processAttribute(e.animation.scale, 1),
3040
- color: this.processAttribute(e.animation.color, d.White.clone()),
3041
- velocity: this.processAttribute(e.animation.velocity, l.ZERO),
3042
- acceleration: this.processAttribute(e.animation.acceleration, l.ZERO)
3043
- }, this.position = l.ZERO, this.initializePosition();
3277
+ color: this.processAttribute(e.animation.color, m.White.clone()),
3278
+ velocity: this.processAttribute(e.animation.velocity, d.ZERO)
3279
+ }, this.position = d.ZERO, this.initializePosition();
3044
3280
  }
3045
3281
  processAttribute(t, e) {
3046
3282
  if (t == null)
3047
3283
  return { value: e };
3048
- if (jt(t)) {
3049
- const i = t, r = b.scalarOrRange(i.start, e), n = i.end === void 0 ? r : b.scalarOrRange(i.end, e);
3284
+ if (oe(t)) {
3285
+ const i = t, r = C.scalarOrRange(i.start, e), n = i.end === void 0 ? r : C.scalarOrRange(i.end, e);
3050
3286
  return {
3051
3287
  delta: i.delta ?? this.getDelta(r, n, this.maxLife),
3052
3288
  value: r,
@@ -3066,14 +3302,12 @@ class Zt {
3066
3302
  }
3067
3303
  updateAttributes(t) {
3068
3304
  const e = this.datas;
3069
- 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), this.updateVec2Attribute(e.acceleration, t), e.velocity.value = e.velocity.value.add(
3070
- e.acceleration.value.multiply(t)
3071
- );
3072
- const r = l.fromAngle(e.rotation.value).multiply(e.speed.value * t);
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);
3306
+ const r = d.fromAngle(e.rotation.value).multiply(e.speed.value * t);
3073
3307
  this.position = this.position.add(r).add(e.velocity.value.multiply(t));
3074
3308
  }
3075
3309
  getDelta(t, e, i) {
3076
- return typeof t == "number" && typeof e == "number" ? (e - t) / i : t instanceof l && e instanceof l || t instanceof d && e instanceof d ? e.subtract(t).divide(i) : t;
3310
+ 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;
3077
3311
  }
3078
3312
  /**
3079
3313
  * Updates particle state.
@@ -3091,41 +3325,41 @@ class Zt {
3091
3325
  const t = this.rapid.matrixStack, e = this.datas.scale.value, i = this.datas.rotation.value, r = this.datas.color.value;
3092
3326
  t.save(), t.translate(this.position.x, this.position.y), i !== 0 && t.rotate(i), e !== 1 && t.scale(e, e);
3093
3327
  const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
3094
- (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), ft(this.rapid, { texture: this.texture, color: r }), t.restore();
3328
+ (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Et(this.rapid, { texture: this.texture, color: r }), t.restore();
3095
3329
  }
3096
3330
  initializePosition() {
3097
3331
  switch (this.options.emitShape) {
3098
3332
  case "circle": {
3099
3333
  const t = Math.random() * Math.PI * 2, e = (this.options.emitRadius ?? 0) * Math.sqrt(Math.random());
3100
- this.position = new l(Math.cos(t) * e, Math.sin(t) * e);
3334
+ this.position = new d(Math.cos(t) * e, Math.sin(t) * e);
3101
3335
  break;
3102
3336
  }
3103
3337
  case "rect": {
3104
- this.position = new l(
3338
+ this.position = new d(
3105
3339
  (Math.random() - 0.5) * (this.options.emitRect?.width ?? 0),
3106
3340
  (Math.random() - 0.5) * (this.options.emitRect?.height ?? 0)
3107
3341
  );
3108
3342
  break;
3109
3343
  }
3110
3344
  default:
3111
- this.position = l.ZERO;
3345
+ this.position = d.ZERO;
3112
3346
  break;
3113
3347
  }
3114
3348
  !this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
3115
3349
  }
3116
3350
  }
3117
- class xt {
3351
+ class Mt {
3118
3352
  particles = [];
3119
3353
  options;
3120
3354
  emitting = !1;
3121
3355
  emitTimer = 0;
3122
- emitRate = ht;
3123
- emitTime = ot;
3356
+ emitRate = pt;
3357
+ emitTime = gt;
3124
3358
  emitTimeCounter = 0;
3125
3359
  /** Whether spawned particles are positioned in local emitter space (default: true). */
3126
- localSpace = ut;
3360
+ localSpace = vt;
3127
3361
  /** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
3128
- position = l.ZERO;
3362
+ position = d.ZERO;
3129
3363
  rapid;
3130
3364
  gameObject;
3131
3365
  /**
@@ -3134,7 +3368,7 @@ class xt {
3134
3368
  * @param options - Emitter configuration options
3135
3369
  */
3136
3370
  constructor(t, e) {
3137
- this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : ht, this.emitTime = e.emitTime !== void 0 ? e.emitTime : ot, this.localSpace = e.localSpace !== void 0 ? e.localSpace : ut, this.position = e.position ?? l.ZERO;
3371
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : pt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : gt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : vt, this.position = e.position ?? d.ZERO;
3138
3372
  }
3139
3373
  /** Replaces the emitter's texture at runtime. */
3140
3374
  setTexture(t) {
@@ -3145,7 +3379,7 @@ class xt {
3145
3379
  * Particle state is NOT copied.
3146
3380
  */
3147
3381
  clone() {
3148
- return new xt(this.rapid, { ...this.options });
3382
+ return new Mt(this.rapid, { ...this.options });
3149
3383
  }
3150
3384
  /** Sets particles-per-second emission rate (continuous mode). */
3151
3385
  setEmitRate(t) {
@@ -3174,7 +3408,7 @@ class xt {
3174
3408
  emit(t) {
3175
3409
  const e = this.options.maxParticles ?? 1 / 0, i = Math.min(t, e - this.particles.length);
3176
3410
  for (let r = 0; r < i; r++)
3177
- this.particles.push(new Zt(this.rapid, { ...this.options }));
3411
+ this.particles.push(new ue(this.rapid, { ...this.options, position: this.position }));
3178
3412
  }
3179
3413
  /**
3180
3414
  * Updates the emitter and all live particles.
@@ -3222,37 +3456,44 @@ class xt {
3222
3456
  }
3223
3457
  }
3224
3458
  export {
3225
- N as ArrayType,
3226
- D as BaseTexture,
3227
- Kt as BlendMode,
3228
- $t as CanvasScaleMode,
3229
- d as Color,
3230
- rt as CustomGlShader,
3231
- W as DynamicArrayBuffer,
3232
- ct as GLShader,
3233
- Ot as GraphicRegion,
3234
- Xt as MaskType,
3235
- gt as MatrixStack,
3236
- pt as MatrixStore,
3237
- Zt as Particle,
3238
- xt as ParticleEmitter,
3239
- qt as ParticleShape,
3240
- Qt as Rapid,
3241
- lt as Region,
3242
- Tt as RenderTexture,
3243
- dt as SpriteRegion,
3244
- Et as TextTexture,
3245
- C as Texture,
3246
- Q as TextureFilterMode,
3247
- vt as TextureManager,
3248
- H as TextureWrapMode,
3249
- l as Vec2,
3250
- j as WebglBufferArray,
3251
- Yt as drawCircle,
3252
- mt as drawGraphic,
3253
- Gt as drawLine,
3254
- Ht as drawMaskImage,
3255
- Vt as drawRect,
3256
- kt as drawSprite,
3257
- ft as drawSpriteRaw
3459
+ I as ArrayType,
3460
+ B as BaseTexture,
3461
+ ae as BlendMode,
3462
+ he as CanvasScaleMode,
3463
+ m as Color,
3464
+ ut as CustomGlShader,
3465
+ D as DynamicArrayBuffer,
3466
+ yt as GLShader,
3467
+ Vt as GraphicRegion,
3468
+ Xt as LineTextureMode,
3469
+ K as MAX_INSTANCES,
3470
+ ne as MaskType,
3471
+ bt as MatrixStack,
3472
+ St as MatrixStore,
3473
+ ue as Particle,
3474
+ Mt as ParticleEmitter,
3475
+ ce as ParticleShape,
3476
+ Dt as QUAD_VERTICES,
3477
+ le as Rapid,
3478
+ Rt as Region,
3479
+ Ut as RenderTexture,
3480
+ at as SpriteRegion,
3481
+ Ct as TextTexture,
3482
+ P as Texture,
3483
+ nt as TextureFilterMode,
3484
+ At as TextureManager,
3485
+ z as TextureWrapMode,
3486
+ d as Vec2,
3487
+ et as WebglBufferArray,
3488
+ Yt as composeProjectionWithAffine,
3489
+ ie as drawCircle,
3490
+ wt as drawGraphic,
3491
+ Jt as drawLine,
3492
+ te as drawMaskImage,
3493
+ Zt as drawParticle,
3494
+ Qt as drawParticles,
3495
+ ee as drawRect,
3496
+ qt as drawSprite,
3497
+ Et as drawSpriteRaw,
3498
+ zt as multiplyMat4
3258
3499
  };