rapid-render 1.0.4 → 1.0.6

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 I = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(I || {});
2
- class D {
1
+ var O = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(O || {});
2
+ class B {
3
3
  /** The number of elements currently used in the buffer. */
4
4
  usedElemNum;
5
5
  /** The main typed array view corresponding to the specified ArrayType. */
@@ -151,7 +151,7 @@ class D {
151
151
  this.usedElemNum = 0;
152
152
  }
153
153
  }
154
- class et extends D {
154
+ class Q extends B {
155
155
  /** The actual WebGLBuffer object maintained by this instance. */
156
156
  buffer;
157
157
  /** The related WebGL rendering context. */
@@ -451,8 +451,8 @@ class m {
451
451
  static Transparent = new m(0, 0, 0, 0);
452
452
  static TRANSPARENT = new m(0, 0, 0, 0);
453
453
  }
454
- const R = 6;
455
- class St {
454
+ const v = 6;
455
+ class Mt {
456
456
  /** Total number of matrices currently allocated in the store. */
457
457
  matrixCount = 0;
458
458
  /** The dynamic buffer used to hold matrix data. */
@@ -464,7 +464,7 @@ class St {
464
464
  * @param capacity - The initial capacity of the matrix store (default is 10).
465
465
  */
466
466
  constructor(t = 10) {
467
- this.buffer = new D(I.Float32), this.buffer.resize(t * R), this.data = this.buffer.getArray();
467
+ this.buffer = new B(O.Float32), this.buffer.resize(t * v), this.data = this.buffer.getArray();
468
468
  }
469
469
  /**
470
470
  * Allocates a new matrix and initializes it to the identity matrix.
@@ -479,7 +479,7 @@ class St {
479
479
  * @returns The index of the newly allocated matrix.
480
480
  */
481
481
  allocDirty() {
482
- return this.buffer.resize(R) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += R, this.matrixCount++;
482
+ return this.buffer.resize(v) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += v, this.matrixCount++;
483
483
  }
484
484
  /**
485
485
  * Resets the store, clearing all allocated matrices.
@@ -492,7 +492,7 @@ class St {
492
492
  * @param index - The index of the matrix to modify.
493
493
  */
494
494
  identity(t) {
495
- const e = t * R, i = this.data;
495
+ const e = t * v, i = this.data;
496
496
  i[e] = 1, i[e + 1] = 0, i[e + 2] = 0, i[e + 3] = 1, i[e + 4] = 0, i[e + 5] = 0;
497
497
  }
498
498
  /**
@@ -502,7 +502,7 @@ class St {
502
502
  * @param y - The y translation.
503
503
  */
504
504
  translate(t, e, i) {
505
- const r = t * R, n = this.data;
505
+ const r = t * v, n = this.data;
506
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];
507
507
  }
508
508
  /**
@@ -512,7 +512,7 @@ class St {
512
512
  * @param scaleY - The scale factor along the y-axis.
513
513
  */
514
514
  scale(t, e, i) {
515
- const r = t * R, n = this.data;
515
+ const r = t * v, n = this.data;
516
516
  n[r] *= e, n[r + 1] *= e, n[r + 2] *= i, n[r + 3] *= i;
517
517
  }
518
518
  /**
@@ -521,7 +521,7 @@ class St {
521
521
  * @param radians - The rotation angle in radians.
522
522
  */
523
523
  rotate(t, e) {
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];
524
+ const i = t * v, r = this.data, n = Math.cos(e), a = Math.sin(e), o = r[i], h = r[i + 1], c = r[i + 2], u = r[i + 3];
525
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;
526
526
  }
527
527
  /**
@@ -549,7 +549,7 @@ class St {
549
549
  * @param src - The index of the source matrix.
550
550
  */
551
551
  copy(t, e) {
552
- const i = t * R, r = e * R, n = this.data;
552
+ const i = t * v, r = e * v, n = this.data;
553
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];
554
554
  }
555
555
  /**
@@ -567,15 +567,15 @@ class St {
567
567
  * @param bIdx - The index of matrix B.
568
568
  */
569
569
  multiplyOut(t, e, i) {
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;
570
+ const r = t * v, n = e * v, a = i * v, o = this.data, h = o[n], c = o[n + 1], u = o[n + 2], f = o[n + 3], l = o[n + 4], p = o[n + 5], x = o[a], g = o[a + 1], T = o[a + 2], y = o[a + 3], w = o[a + 4], M = o[a + 5];
571
+ o[r] = h * x + u * g, o[r + 1] = c * x + f * g, o[r + 2] = h * T + u * y, o[r + 3] = c * T + f * y, o[r + 4] = h * w + u * M + l, o[r + 5] = c * w + f * M + p;
572
572
  }
573
573
  /**
574
574
  * Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
575
575
  * @param index - The index of the matrix to invert.
576
576
  */
577
577
  invert(t) {
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];
578
+ const e = t * v, i = this.data, r = i[e], n = i[e + 1], a = i[e + 2], o = i[e + 3], h = i[e + 4], c = i[e + 5];
579
579
  let u = r * o - n * a;
580
580
  if (!u) {
581
581
  this.identity(t);
@@ -591,7 +591,7 @@ class St {
591
591
  * @returns The transformed point {x, y}.
592
592
  */
593
593
  transformPoint(t, e, i) {
594
- const r = t * R, n = this.data;
594
+ const r = t * v, n = this.data;
595
595
  return {
596
596
  x: e * n[r] + i * n[r + 2] + n[r + 4],
597
597
  y: e * n[r + 1] + i * n[r + 3] + n[r + 5]
@@ -609,7 +609,7 @@ class St {
609
609
  const r = this.allocDirty();
610
610
  this.copy(r, t), this.invert(r);
611
611
  const n = this.transformPoint(r, e, i);
612
- return this.matrixCount--, this.buffer.usedElemNum -= R, n;
612
+ return this.matrixCount--, this.buffer.usedElemNum -= v, n;
613
613
  }
614
614
  /**
615
615
  * Transforms a point from local coordinates to world coordinates.
@@ -627,7 +627,7 @@ class St {
627
627
  * @returns An object containing `x` and `y` global coordinates.
628
628
  */
629
629
  getPosition(t) {
630
- const e = t * R, i = this.data;
630
+ const e = t * v, i = this.data;
631
631
  return { x: i[e + 4], y: i[e + 5] };
632
632
  }
633
633
  /**
@@ -636,7 +636,7 @@ class St {
636
636
  * @returns An object containing `x` and `y` global scale factors.
637
637
  */
638
638
  getScale(t) {
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]);
639
+ const e = t * v, i = this.data, r = Math.sqrt(i[e] * i[e] + i[e + 1] * i[e + 1]), n = Math.sqrt(i[e + 2] * i[e + 2] + i[e + 3] * i[e + 3]);
640
640
  return { x: r, y: n };
641
641
  }
642
642
  /**
@@ -645,7 +645,7 @@ class St {
645
645
  * @returns The global rotation in radians.
646
646
  */
647
647
  getRotation(t) {
648
- const e = t * R, i = this.data;
648
+ const e = t * v, i = this.data;
649
649
  return Math.atan2(i[e + 1], i[e]);
650
650
  }
651
651
  /**
@@ -656,7 +656,7 @@ class St {
656
656
  * @returns A CSS matrix string.
657
657
  */
658
658
  toCSSMatrix(t, e = 1, i = 1) {
659
- const r = t * R, n = this.data;
659
+ const r = t * v, n = this.data;
660
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})`;
661
661
  }
662
662
  /**
@@ -667,8 +667,8 @@ class St {
667
667
  * @returns A new Float32Array containing the 6 elements of the matrix.
668
668
  */
669
669
  getMatrix(t) {
670
- const e = t * R;
671
- return this.data.slice(e, e + R);
670
+ const e = t * v;
671
+ return this.data.slice(e, e + v);
672
672
  }
673
673
  /**
674
674
  * Retrieves a direct reference (view) to the 6 elements [a, b, c, d, tx, ty] for the matrix at the specified index.
@@ -678,8 +678,8 @@ class St {
678
678
  * @returns A Float32Array view pointing directly to the matrix's data in memory.
679
679
  */
680
680
  getMatrixRef(t) {
681
- const e = t * R;
682
- return this.data.subarray(e, e + R);
681
+ const e = t * v;
682
+ return this.data.subarray(e, e + v);
683
683
  }
684
684
  /**
685
685
  * Overwrites the matrix at the specified index with the provided 6 elements [a, b, c, d, tx, ty].
@@ -688,7 +688,7 @@ class St {
688
688
  * @param f - An array (Float32Array or standard number array) containing the 6 new elements.
689
689
  */
690
690
  setMatrix(t, e) {
691
- const i = t * R, r = this.data;
691
+ const i = t * v, r = this.data;
692
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];
693
693
  }
694
694
  multiplyAffineInPlace(t, e, i, r, n, a, o) {
@@ -696,21 +696,21 @@ class St {
696
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
697
  }
698
698
  }
699
- class bt {
699
+ class St {
700
700
  /** The underlying store for matrices. */
701
- matrix = new St();
701
+ matrix = new Mt();
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 D(I.Uint32);
705
+ stack = new B(O.Uint32);
706
706
  /** Records the world matrices generated at each step. */
707
- stepWorldM = new D(I.Uint32);
707
+ stepWorldM = new B(O.Uint32);
708
708
  /** Records actions (push/pop) taken during the traversal. */
709
- stepAction = new D(I.Uint32);
709
+ stepAction = new B(O.Uint32);
710
710
  /** Records the parent world matrix for each step (used by updateMatrix). */
711
- stepParentM = new D(I.Uint32);
711
+ stepParentM = new B(O.Uint32);
712
712
  /** Buffer used during hierarchy traversal updates. */
713
- parentStack = new D(I.Uint32);
713
+ parentStack = new B(O.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. */
@@ -859,14 +859,14 @@ class bt {
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 * R;
863
- return this.matrix.data.slice(t, t + R);
862
+ const t = this.curWorldM * v;
863
+ return this.matrix.data.slice(t, t + v);
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 * R, i = this.matrix.data;
869
+ const e = this.curWorldM * v, 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) {
@@ -888,28 +888,28 @@ class bt {
888
888
  t.offset && (u += t.offset.x, f += t.offset.y);
889
889
  const l = t.origin;
890
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;
891
+ const p = c ? Math.cos(c) : 1, x = c ? Math.sin(c) : 0, g = p * a, T = x * a, y = -x * o, w = p * o, M = r + g * u + y * f, A = n + T * u + w * f;
892
892
  (t.afterSave !== void 0 || t.saveTransform === !1) && this.matrix.multiplyAffineInPlace(
893
893
  this.curLocalM,
894
894
  g,
895
- v,
895
+ T,
896
896
  y,
897
897
  w,
898
- T,
899
- S
898
+ M,
899
+ A
900
900
  ), this.matrix.multiplyAffineInPlace(
901
901
  this.curWorldM,
902
902
  g,
903
- v,
903
+ T,
904
904
  y,
905
905
  w,
906
- T,
907
- S
906
+ M,
907
+ A
908
908
  ), t.afterSave?.();
909
909
  }
910
910
  }
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 {
911
+ var Y = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))(Y || {});
912
+ class bt {
913
913
  render;
914
914
  cache = /* @__PURE__ */ new Map();
915
915
  constructor(t) {
@@ -927,7 +927,7 @@ class At {
927
927
  return new P(i);
928
928
  try {
929
929
  const r = await this._fetchImage(t);
930
- return i = B.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new P(i);
930
+ return i = k.fromSource(this.render, r, e), i.uid = t, this.cache.set(t, i), new P(i);
931
931
  } catch (r) {
932
932
  throw console.error(`[TextureManager] Failed to load: ${t}`, r), r;
933
933
  }
@@ -941,7 +941,7 @@ class At {
941
941
  create(t, e) {
942
942
  if (e?.key && this.cache.has(e.key))
943
943
  return new P(this.cache.get(e.key));
944
- const i = B.fromSource(this.render, t, e);
944
+ const i = k.fromSource(this.render, t, e);
945
945
  return e?.key && (i.uid = e.key, this.cache.set(e.key, i)), new P(i);
946
946
  }
947
947
  /**
@@ -952,7 +952,7 @@ class At {
952
952
  * @returns The newly created RenderTexture.
953
953
  */
954
954
  createRenderTexture(t) {
955
- return new Ut(this.render, t);
955
+ return new At(this.render, t);
956
956
  }
957
957
  /**
958
958
  * Creates a TextTexture for rendering text.
@@ -960,7 +960,7 @@ class At {
960
960
  * @returns The newly created TextTexture.
961
961
  */
962
962
  createTextTexture(t) {
963
- return new Ct(this.render, t);
963
+ return new _t(this.render, t);
964
964
  }
965
965
  /**
966
966
  * Destroys a texture and potentially removes its BaseTexture from the cache.
@@ -988,7 +988,7 @@ class At {
988
988
  });
989
989
  }
990
990
  }
991
- class B {
991
+ class k {
992
992
  glTexture = null;
993
993
  width;
994
994
  height;
@@ -1005,8 +1005,8 @@ class B {
1005
1005
  * @returns The created BaseTexture.
1006
1006
  */
1007
1007
  static fromSource(t, e, i = {}) {
1008
- const r = Z(t, e, i);
1009
- return new B(r, e.width, e.height);
1008
+ const r = K(t, e, i);
1009
+ return new k(r, e.width, e.height);
1010
1010
  }
1011
1011
  /**
1012
1012
  * Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
@@ -1015,19 +1015,19 @@ class B {
1015
1015
  * @param source - The new image source.
1016
1016
  */
1017
1017
  updateSource(t, e, i = {}) {
1018
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && rt(t, i.textureFilter), i.wrap !== void 0 && it(t, i.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, i.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1018
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), i.textureFilter !== void 0 && tt(t, i.textureFilter), i.wrap !== void 0 && J(t, i.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, i.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), i.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1019
1019
  }
1020
1020
  /**
1021
1021
  * Dynamically updates the texture filtering mode.
1022
1022
  */
1023
1023
  setFilterMode(t, e) {
1024
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), rt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1024
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), tt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1025
1025
  }
1026
1026
  /**
1027
1027
  * Dynamically updates the texture wrap mode.
1028
1028
  */
1029
1029
  setWrapMode(t, e) {
1030
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), it(t, e), t.bindTexture(t.TEXTURE_2D, null));
1030
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), J(t, e), t.bindTexture(t.TEXTURE_2D, null));
1031
1031
  }
1032
1032
  /**
1033
1033
  * Destroys the WebGL texture resource.
@@ -1130,8 +1130,8 @@ class P {
1130
1130
  * @param options - Optional antialias and wrap mode settings.
1131
1131
  */
1132
1132
  static fromImageSource(t, e, i = {}) {
1133
- const r = Z(t, e, i);
1134
- return new P(new B(r, e.width, e.height));
1133
+ const r = K(t, e, i);
1134
+ return new P(new k(r, e.width, e.height));
1135
1135
  }
1136
1136
  /**
1137
1137
  * Marks this Texture as destroyed, decrementing the BaseTexture reference count.
@@ -1140,7 +1140,7 @@ class P {
1140
1140
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
1141
1141
  }
1142
1142
  }
1143
- class Ut extends P {
1143
+ class At extends P {
1144
1144
  framebuffer;
1145
1145
  renderbuffer;
1146
1146
  gl;
@@ -1151,8 +1151,8 @@ class Ut extends P {
1151
1151
  _allocH = 0;
1152
1152
  constructor(t, e) {
1153
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)
1154
+ const i = Math.max(Math.round(e.width), 1), r = Math.max(Math.round(e.height), 1), a = K(t, { width: i, height: r }, { ...e, onlySize: !0 });
1155
+ if (this.setBase(new k(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1156
1156
  throw new Error("Failed to create Framebuffer or Renderbuffer");
1157
1157
  this.resize(i, r, !0);
1158
1158
  }
@@ -1230,7 +1230,7 @@ class Ut extends P {
1230
1230
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
1231
1231
  }
1232
1232
  }
1233
- const _t = {
1233
+ const Ut = {
1234
1234
  fontFamily: "Arial",
1235
1235
  fontSize: 24,
1236
1236
  fontWeight: "normal",
@@ -1239,7 +1239,7 @@ const _t = {
1239
1239
  align: "left",
1240
1240
  baseline: "top"
1241
1241
  };
1242
- class Ct extends P {
1242
+ class _t extends P {
1243
1243
  canvas;
1244
1244
  ctx;
1245
1245
  render;
@@ -1248,12 +1248,12 @@ class Ct extends P {
1248
1248
  options;
1249
1249
  flipY = !0;
1250
1250
  constructor(t, e) {
1251
- super(), this.render = t, this._style = { ..._t, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1251
+ super(), this.render = t, this._style = { ...Ut, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1252
1252
  const i = this.canvas.getContext("2d", { willReadFrequently: !0 });
1253
1253
  if (!i) throw new Error("Failed to get 2d context for TextTexture");
1254
1254
  this.ctx = i, this.canvas.width = 1, this.canvas.height = 1;
1255
- const r = Z(t, this.canvas, this.options);
1256
- this.setBase(new B(r, 1, 1)), this.update();
1255
+ const r = K(t, this.canvas, this.options);
1256
+ this.setBase(new k(r, 1, 1)), this.update();
1257
1257
  }
1258
1258
  get text() {
1259
1259
  return this._text;
@@ -1308,27 +1308,27 @@ class Ct extends P {
1308
1308
  let h = 0, c = 0;
1309
1309
  t.textBaseline = "alphabetic";
1310
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;
1311
+ for (const M of o) {
1312
+ const A = t.measureText(M);
1313
+ A.width > h && (h = A.width), c += f + l;
1314
1314
  }
1315
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);
1316
+ const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1, g = Math.ceil(c + p) || 1, T = x * a, y = g * a;
1317
+ (this.canvas.width !== T || this.canvas.height !== y) && (this.canvas.width = T, this.canvas.height = y), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, g), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, g);
1318
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;
1319
+ for (const M of o) {
1320
+ let A = p / 2;
1321
+ this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(M, A, w)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(M, A, w)), w += f + l;
1322
1322
  }
1323
1323
  this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, this.canvas.width, this.canvas.height);
1324
1324
  }
1325
1325
  }
1326
- const Pt = (s, t = !1, e = !0) => {
1326
+ const Ct = (s, t = !1, e = !0) => {
1327
1327
  const i = s.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1328
1328
  if (!i)
1329
1329
  throw new Error("WebGL2 is not supported in this browser.");
1330
1330
  return i;
1331
- }, ct = (s, t, e) => {
1331
+ }, ht = (s, t, e) => {
1332
1332
  const i = s.createShader(e);
1333
1333
  if (!i)
1334
1334
  throw new Error("Unable to create webgl shader");
@@ -1337,8 +1337,8 @@ const Pt = (s, t = !1, e = !0) => {
1337
1337
  throw console.error("Shader compilation failed:", n), new Error("Unable to compile shader: " + n + t);
1338
1338
  }
1339
1339
  return i;
1340
- }, Nt = (s, t, e) => {
1341
- var i = s.createProgram(), r = ct(s, t, 35633), n = ct(s, e, 35632);
1340
+ }, Pt = (s, t, e) => {
1341
+ var i = s.createProgram(), r = ht(s, t, 35633), n = ht(s, e, 35632);
1342
1342
  if (!i)
1343
1343
  throw new Error("Unable to create program shader");
1344
1344
  if (s.attachShader(i, r), s.attachShader(i, n), s.linkProgram(i), !s.getProgramParameter(i, s.LINK_STATUS)) {
@@ -1347,26 +1347,26 @@ const Pt = (s, t = !1, e = !0) => {
1347
1347
  }
1348
1348
  return i;
1349
1349
  };
1350
- function it(s, t) {
1350
+ function J(s, t) {
1351
1351
  const e = {
1352
- [z.CLAMP]: s.CLAMP_TO_EDGE,
1353
- [z.REPEAT]: s.REPEAT,
1354
- [z.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1352
+ [Y.CLAMP]: s.CLAMP_TO_EDGE,
1353
+ [Y.REPEAT]: s.REPEAT,
1354
+ [Y.MIRRORED_REPEAT]: s.MIRRORED_REPEAT
1355
1355
  }[t] || s.CLAMP_TO_EDGE;
1356
1356
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_S, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_WRAP_T, e);
1357
1357
  }
1358
- function rt(s, t) {
1358
+ function tt(s, t) {
1359
1359
  const e = {
1360
- [nt.LINEAR]: s.LINEAR,
1361
- [nt.NEAREST]: s.NEAREST
1360
+ [it.LINEAR]: s.LINEAR,
1361
+ [it.NEAREST]: s.NEAREST
1362
1362
  }[t] ?? s.NEAREST;
1363
1363
  s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MIN_FILTER, e), s.texParameteri(s.TEXTURE_2D, s.TEXTURE_MAG_FILTER, e);
1364
1364
  }
1365
- function Z(s, t, e) {
1365
+ function K(s, t, e) {
1366
1366
  const i = s.gl, r = i.createTexture();
1367
1367
  if (!r)
1368
1368
  throw new Error("Unable to create WebGL texture");
1369
- if (i.bindTexture(i.TEXTURE_2D, r), i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL, 0), i.pixelStorei(i.UNPACK_ALIGNMENT, 1), it(i, e.wrap ?? z.CLAMP), rt(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), J(i, e.wrap ?? Y.CLAMP), tt(i, e.textureFilter ?? s.textureFilter), e.onlySize) {
1370
1370
  const n = t;
1371
1371
  i.texImage2D(i.TEXTURE_2D, 0, i.RGBA, n.width, n.height, 0, i.RGBA, i.UNSIGNED_BYTE, null);
1372
1372
  } else {
@@ -1384,15 +1384,15 @@ function W(s, t) {
1384
1384
  }
1385
1385
  return s;
1386
1386
  }
1387
- const Lt = 5126, st = 5121;
1388
- function It(s, t, e) {
1387
+ const Nt = 5126, et = 5121;
1388
+ function Lt(s, t, e) {
1389
1389
  s.vertexAttribDivisor(t, e);
1390
1390
  }
1391
- function Tt(s, t, e, i, r) {
1391
+ function vt(s, t, e, i, r) {
1392
1392
  s.drawArraysInstanced(t, e, i, r);
1393
1393
  }
1394
1394
  let Ot = 0;
1395
- class yt {
1395
+ class Tt {
1396
1396
  program;
1397
1397
  attributeLoc = {};
1398
1398
  uniformLoc = {};
@@ -1408,7 +1408,7 @@ class yt {
1408
1408
  // for debug
1409
1409
  vao;
1410
1410
  constructor(t, e, i, r) {
1411
- this.gl = t, this.program = Nt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
1411
+ this.gl = t, this.program = Pt(t, e, i), this.parseShader(e), this.parseShader(i), this.vao = t.createVertexArray(), r && this.setAttributes(r);
1412
1412
  }
1413
1413
  /** Switch GPU to use this shader program */
1414
1414
  use() {
@@ -1434,7 +1434,7 @@ class yt {
1434
1434
  const i = this.uniformLoc[t];
1435
1435
  if (i === void 0) return;
1436
1436
  const r = this.uniformType[t], n = this.uniformIsArray[t];
1437
- Wt(this.gl, i, r, e, n);
1437
+ It(this.gl, i, r, e, n);
1438
1438
  }
1439
1439
  /**
1440
1440
  * Batch-set uniforms via a plain value map.
@@ -1461,11 +1461,11 @@ class yt {
1461
1461
  i.vertexAttribPointer(
1462
1462
  e,
1463
1463
  t.size,
1464
- t.type ?? Lt,
1464
+ t.type ?? Nt,
1465
1465
  t.normalized ?? !1,
1466
1466
  t.stride,
1467
1467
  t.offset ?? 0
1468
- ), i.enableVertexAttribArray(e), It(i, e, t.divisor ?? 0);
1468
+ ), i.enableVertexAttribArray(e), Lt(i, e, t.divisor ?? 0);
1469
1469
  }
1470
1470
  /** Bind all vertex attribute pointers at once */
1471
1471
  setAttributes(t) {
@@ -1493,7 +1493,7 @@ class yt {
1493
1493
  }
1494
1494
  }
1495
1495
  }
1496
- function Wt(s, t, e, i, r = !1) {
1496
+ function It(s, t, e, i, r = !1) {
1497
1497
  switch (e) {
1498
1498
  // scalars
1499
1499
  case "float":
@@ -1529,10 +1529,10 @@ function Wt(s, t, e, i, r = !1) {
1529
1529
  return s.uniformMatrix4fv(t, !1, i);
1530
1530
  // fallback: guess by value shape
1531
1531
  default:
1532
- return Ft(s, t, i);
1532
+ return Wt(s, t, i);
1533
1533
  }
1534
1534
  }
1535
- function Ft(s, t, e) {
1535
+ function Wt(s, t, e) {
1536
1536
  if (typeof e == "number")
1537
1537
  return s.uniform1f(t, e);
1538
1538
  const i = e;
@@ -1551,7 +1551,7 @@ function Ft(s, t, e) {
1551
1551
  return s.uniform1fv(t, i);
1552
1552
  }
1553
1553
  }
1554
- class ut {
1554
+ class ot {
1555
1555
  /** Custom vertex shader code */
1556
1556
  vs;
1557
1557
  /** Custom fragment shader code */
@@ -1623,8 +1623,7 @@ class ut {
1623
1623
  return n.isCustom = !0, n.padding = this.padding, this.glshader.set(e, n), this.uniformDirty.add(e), n;
1624
1624
  }
1625
1625
  }
1626
- const K = 1 / 0;
1627
- class Rt {
1626
+ class yt {
1628
1627
  constructor(t) {
1629
1628
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
1630
1629
  }
@@ -1667,7 +1666,7 @@ class Rt {
1667
1666
  return r == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(i), this.usedTextures.length - 1) : r;
1668
1667
  }
1669
1668
  createShader(t, e) {
1670
- return new yt(this.gl, t, e);
1669
+ return new Tt(this.gl, t, e);
1671
1670
  }
1672
1671
  createCustomShader(t) {
1673
1672
  return t.getGLShader(this, this.KEY, this.vs, this.fs);
@@ -1675,7 +1674,7 @@ class Rt {
1675
1674
  getCustomShader(t) {
1676
1675
  if (!t)
1677
1676
  return this.defaultShader;
1678
- if (t instanceof ut) {
1677
+ if (t instanceof ot) {
1679
1678
  const e = this.createCustomShader(t);
1680
1679
  return e ?? this.defaultShader;
1681
1680
  }
@@ -1690,7 +1689,7 @@ class Rt {
1690
1689
  return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
1691
1690
  }
1692
1691
  enter(t) {
1693
- this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ut ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
1692
+ this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ot ? (this.customShader = t, this.customShaderUsedTextureNum = t.usedTextureUnitNum) : (this.customShader = null, this.customShaderUsedTextureNum = 0), this.isDefaultShader = this.currentShader == this.defaultShader, this.currentShader.use(), this.currentShader.setUniform("u_projection", this.rapid.projection);
1694
1693
  }
1695
1694
  exit() {
1696
1695
  this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
@@ -1699,6 +1698,9 @@ class Rt {
1699
1698
  this.render(), this.resetRender();
1700
1699
  }
1701
1700
  render() {
1701
+ this.prepareRender();
1702
+ }
1703
+ prepareRender() {
1702
1704
  const t = this.currentShader;
1703
1705
  if (t.use(), this.customShader) {
1704
1706
  const i = this.customShader, r = {};
@@ -1724,7 +1726,7 @@ class Rt {
1724
1726
  return !1;
1725
1727
  }
1726
1728
  }
1727
- const q = `#version 300 es\r
1729
+ const $ = `#version 300 es\r
1728
1730
  precision mediump float;\r
1729
1731
  \r
1730
1732
  // per-vertex\r
@@ -1772,7 +1774,7 @@ void main(void) {\r
1772
1774
  \r
1773
1775
  gl_Position = u_projection * position;\r
1774
1776
  }\r
1775
- `, lt = `#version 300 es\r
1777
+ `, ct = `#version 300 es\r
1776
1778
  precision mediump float;\r
1777
1779
  \r
1778
1780
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1821,8 +1823,8 @@ void main(void) {\r
1821
1823
  \r
1822
1824
  // CUSTOM_CODE_CALL\r
1823
1825
  }\r
1824
- `, V = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1825
- class at extends Rt {
1826
+ `, V = 48, Ft = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1827
+ class rt extends yt {
1826
1828
  instanceBuffer;
1827
1829
  quadBuffer;
1828
1830
  instanceCount = 0;
@@ -1834,12 +1836,12 @@ class at extends Rt {
1834
1836
  }
1835
1837
  createBuffer() {
1836
1838
  const t = this.gl;
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);
1839
+ this.quadBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1840
+ for (const e of Ft) this.quadBuffer.pushFloat32(e);
1841
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new Q(t, O.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1840
1842
  }
1841
1843
  createDefaultShader() {
1842
- const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
1844
+ const t = this.rapid, e = W(ct, t.maxTextureUnits), i = W($, t.maxTextureUnits);
1843
1845
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
1844
1846
  }
1845
1847
  createShader(t, e) {
@@ -1848,14 +1850,14 @@ class at extends Rt {
1848
1850
  { name: "aMatrixRow0", size: 3, stride: V, offset: 0, divisor: 1 },
1849
1851
  { name: "aMatrixRow1", size: 3, stride: V, offset: 12, divisor: 1 },
1850
1852
  { 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 }
1853
+ { name: "aColor", size: 4, type: et, normalized: !0, stride: V, offset: 40, divisor: 1 },
1854
+ { name: "aTextureId", size: 1, type: et, stride: V, offset: 44, divisor: 1 }
1853
1855
  ]), this.quadBuffer.bindBuffer(), i.setAttributes([
1854
1856
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1855
1857
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1856
1858
  }
1857
1859
  createCustomShader(t) {
1858
- const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1860
+ const e = W(ct, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1859
1861
  return t.getGLShader(this, this.KEY, i, e);
1860
1862
  }
1861
1863
  /**
@@ -1892,24 +1894,23 @@ class at extends Rt {
1892
1894
  l
1893
1895
  );
1894
1896
  }
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.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(
1897
+ drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, g = !1, T = !1, y = !1) {
1898
+ const w = t.base, M = t.scale ?? 1, A = t.rawWidth, F = t.rawHeight, I = t.offsetX, N = t.offsetY, S = this.useTexture(
1898
1899
  t.glTexture,
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));
1900
+ p / M / w.width,
1901
+ x / M / w.height
1902
+ ), R = this.instanceBuffer, b = R.usedElemNum;
1903
+ R.resize(12);
1904
+ const U = R.float32, L = R.uint32, j = (y ? F : A) * M, q = (y ? A : F) * M, G = j + 2 * p, H = q + 2 * x, nt = I - p, at = N - x, E = this.localSpriteMatrix;
1905
+ y ? (E[0] = 0, E[1] = T ? H : -H, E[2] = g ? -G : G, E[3] = 0, E[4] = nt + (g ? G : 0), E[5] = at + (T ? 0 : H)) : (E[0] = g ? -G : G, E[1] = 0, E[2] = 0, E[3] = T ? -H : H, E[4] = nt + (g ? G : 0), E[5] = at + (T ? H : 0));
1905
1906
  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++;
1907
+ _[0] = e * E[0] + r * E[1], _[1] = i * E[0] + n * E[1], _[2] = e * E[2] + r * E[3], _[3] = i * E[2] + n * E[3], _[4] = a + e * E[4] + r * E[5], _[5] = o + i * E[4] + n * E[5], U[b + 6] = h, U[b + 7] = c, U[b + 8] = u, U[b + 9] = f, L[b + 10] = l, L[b + 11] = S, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), U[b] = _[0], U[b + 1] = _[2], U[b + 2] = _[4], U[b + 3] = _[1], U[b + 4] = _[3], U[b + 5] = _[5], R.usedElemNum += 12, R.makeDirty(), this.instanceCount++;
1907
1908
  }
1908
1909
  render() {
1909
1910
  if (this.instanceCount === 0) return;
1910
- super.render();
1911
+ this.prepareRender();
1911
1912
  const t = this.gl, e = this.currentShader;
1912
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Tt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1913
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1913
1914
  }
1914
1915
  resetRender() {
1915
1916
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1918,7 +1919,7 @@ class at extends Rt {
1918
1919
  return this.instanceCount > 0;
1919
1920
  }
1920
1921
  }
1921
- const Bt = `#version 300 es\r
1922
+ const Dt = `#version 300 es\r
1922
1923
  precision mediump float;\r
1923
1924
  \r
1924
1925
  in vec2 aPosition;\r
@@ -1949,7 +1950,7 @@ void main(void) {\r
1949
1950
  // CUSTOM_CODE_CALL\r
1950
1951
  gl_Position = u_projection * position;\r
1951
1952
  }\r
1952
- `, kt = `#version 300 es\r
1953
+ `, Bt = `#version 300 es\r
1953
1954
  precision mediump float;\r
1954
1955
  \r
1955
1956
  in vec4 vColor;\r
@@ -1995,7 +1996,7 @@ void main(void) {\r
1995
1996
  fragColor = sampleTexture(vRegion);\r
1996
1997
  // CUSTOM_CODE_CALL\r
1997
1998
  }\r
1998
- `, Gt = `#version 300 es\r
1999
+ `, kt = `#version 300 es\r
1999
2000
  precision mediump float;\r
2000
2001
  \r
2001
2002
  in vec2 aPosition;\r
@@ -2018,7 +2019,7 @@ void main(void) {\r
2018
2019
  );\r
2019
2020
  gl_Position = u_projection * position;\r
2020
2021
  }\r
2021
- `, Ht = `#version 300 es\r
2022
+ `, Gt = `#version 300 es\r
2022
2023
  precision mediump float;\r
2023
2024
  \r
2024
2025
  in vec2 vRegion;\r
@@ -2038,8 +2039,8 @@ void main(void) {\r
2038
2039
  discard;\r
2039
2040
  }\r
2040
2041
  }\r
2041
- `, Y = 20;
2042
- class Vt extends Rt {
2042
+ `, z = 20;
2043
+ class Ht extends yt {
2043
2044
  vertexBuffer;
2044
2045
  vertexCount = 0;
2045
2046
  matrixIndex = -1;
@@ -2052,24 +2053,24 @@ class Vt extends Rt {
2052
2053
  }
2053
2054
  createBuffer() {
2054
2055
  const t = this.gl;
2055
- this.vertexBuffer = new et(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Ht);
2056
+ this.vertexBuffer = new Q(t, O.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(kt, Gt);
2056
2057
  }
2057
2058
  createDefaultShader() {
2058
- return this.vs = Bt, this.fs = kt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2059
+ return this.vs = Dt, this.fs = Bt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2059
2060
  }
2060
2061
  createMaskShader(t, e) {
2061
- const i = this.gl, r = new yt(i, t, e);
2062
+ const i = this.gl, r = new Tt(i, t, e);
2062
2063
  return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
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 }
2064
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: z - 4, offset: 0, divisor: 0 },
2065
+ { name: "aUV", size: 2, type: i.FLOAT, stride: z - 4, offset: 8, divisor: 0 }
2065
2066
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2066
2067
  }
2067
2068
  createShader(t, e) {
2068
2069
  const i = this.gl, r = super.createShader(t, e);
2069
2070
  return r.use(), r.bindVAO(), this.vertexBuffer.bindBuffer(), r.setAttributes([
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 }
2071
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: z, offset: 0, divisor: 0 },
2072
+ { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: z, offset: 8, divisor: 0 },
2073
+ { name: "aUV", size: 2, type: i.FLOAT, stride: z, offset: 12, divisor: 0 }
2073
2074
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2074
2075
  }
2075
2076
  /**
@@ -2101,7 +2102,7 @@ class Vt extends Rt {
2101
2102
  }
2102
2103
  render() {
2103
2104
  if (this.vertexCount === 0) return;
2104
- super.render();
2105
+ this.prepareRender();
2105
2106
  const t = this.gl, e = this.currentShader, i = this.matrixIndex * 6, r = this.matrixStore.data;
2106
2107
  let n = r[i + 4], a = r[i + 5];
2107
2108
  this.rapid.roundPixels && (n = Math.round(n), a = Math.round(a)), e.setUniform("uMatrixRow0", [r[i], r[i + 2], n]), e.setUniform("uMatrixRow1", [r[i + 1], r[i + 3], a]), e.setUniform(
@@ -2238,7 +2239,7 @@ class d {
2238
2239
  return new d(Math.cos(t), Math.sin(t));
2239
2240
  }
2240
2241
  }
2241
- const Yt = (s, t) => {
2242
+ const Vt = (s, t) => {
2242
2243
  const [e, i, r, n, a, o] = t, h = new Float32Array([
2243
2244
  e,
2244
2245
  n,
@@ -2269,15 +2270,15 @@ const Yt = (s, t) => {
2269
2270
  }
2270
2271
  return e;
2271
2272
  };
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) => {
2273
+ var Yt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1] = "REPEAT", s))(Yt || {});
2274
+ const Z = 10, ut = (s, t, e, i, r, n) => {
2274
2275
  const a = [], o = [], h = i ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new d(t.y, -t.x);
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));
2276
+ for (let f = 0; f < Z; f++) {
2277
+ const l = f / Z, p = (f + 1) / Z, x = h + l * c, g = h + p * c, T = new d(Math.cos(x) * e, Math.sin(x) * e), y = new d(Math.cos(g) * e, Math.sin(g) * e);
2278
+ a.push(s), o.push(new d(r, 0.5)), a.push(s.add(T)), o.push(new d(r + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e)), a.push(s.add(y)), o.push(new d(r + y.dot(u) * n, 0.5 - 0.5 * y.dot(t) / e));
2278
2279
  }
2279
2280
  return { vertices: a, uv: o };
2280
- }, $t = (s, t = !1) => {
2281
+ }, Xt = (s, t = !1) => {
2281
2282
  const e = [];
2282
2283
  if (s.length < 2 || t && s.length < 3) return { normals: e, length: 0 };
2283
2284
  const i = 4, r = 1e-3, n = s.length;
@@ -2320,21 +2321,21 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2320
2321
  }, jt = (s) => {
2321
2322
  const t = s.points;
2322
2323
  if (t.length < 2) return { vertices: [], uv: [] };
2323
- const { normals: e, length: i } = $t(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2324
+ const { normals: e, length: i } = Xt(t, s.closed), r = (s.width || 1) / 2, n = [], a = [], o = s.roundCap || !1, h = s.textureMode || 0;
2324
2325
  let c = 0;
2325
2326
  const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
2326
2327
  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;
2328
+ const p = t[l], x = e[l].normal, g = e[l].miters, T = (l + 1) % t.length, y = t[T], w = e[T].normal, M = e[T].miters, A = p.add(x.multiply(g * r)), F = p.subtract(x.multiply(g * r)), I = y.add(w.multiply(M * r)), N = y.subtract(w.multiply(M * r)), S = p.distanceTo(y);
2329
+ let R = 0, b = 0;
2330
+ h === 0 ? (R = c / i, b = (c + S) / i) : (R = c / u, b = R + S / u);
2331
+ const U = new d(R, 0), L = new d(R, 1), j = new d(b, 0), q = new d(b, 1);
2332
+ n.push(A), a.push(U), n.push(F), a.push(L), n.push(I), a.push(j), n.push(I), a.push(j), n.push(N), a.push(q), n.push(F), a.push(L), c += S;
2332
2333
  }
2333
2334
  if (o && !s.closed) {
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);
2335
+ const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, g = ut(l, p, r, !0, 0, x);
2335
2336
  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);
2337
+ const T = t[t.length - 1], y = e[t.length - 1].normal, w = h === 0 ? 1 : c / u, M = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, A = ut(T, y, r, !1, w, M);
2338
+ n.push(...A.vertices), a.push(...A.uv);
2338
2339
  }
2339
2340
  return { vertices: n, uv: a };
2340
2341
  }, X = (s, t, e, i, r) => {
@@ -2344,7 +2345,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2344
2345
  } finally {
2345
2346
  t.saveTransform !== !1 && s.matrixStack.restore();
2346
2347
  }
2347
- }, Q = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, Et = (s, t) => {
2348
+ }, st = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, Rt = (s, t) => {
2348
2349
  const e = t.texture;
2349
2350
  if (!e?.base || s.inCreateMask)
2350
2351
  return;
@@ -2353,7 +2354,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2353
2354
  let r = e.uvX, n = e.uvY, a = e.uvW, o = e.uvH;
2354
2355
  const h = !!t.flipX, c = !!t.flipY != !!e.flipY;
2355
2356
  let u = t.padding ?? i.currentShader.padding;
2356
- e.isAtlas && (u += Kt);
2357
+ e.isAtlas && (u += $t);
2357
2358
  const f = r <= a ? u : -u, l = n <= o ? u : -u;
2358
2359
  i.drawSprite(
2359
2360
  e,
@@ -2362,38 +2363,18 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2362
2363
  n,
2363
2364
  a,
2364
2365
  o,
2365
- Q(s, t.color),
2366
+ st(s, t.color),
2366
2367
  f,
2367
2368
  l,
2368
2369
  h,
2369
2370
  c,
2370
2371
  e.isRotated
2371
2372
  );
2372
- }, qt = (s, t) => {
2373
+ }, Kt = (s, t) => {
2373
2374
  X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2374
- Et(s, t);
2375
+ Rt(s, t);
2375
2376
  });
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) => {
2377
+ }, qt = (s, t) => {
2397
2378
  const e = s.particleRegion;
2398
2379
  s.enterRegion(e, t.shader);
2399
2380
  const i = t.texture, r = t.count ?? t.x.length, n = t.color, a = n.length, o = new Array(a);
@@ -2418,9 +2399,11 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2418
2399
  i.uvH,
2419
2400
  t.flipX,
2420
2401
  t.flipY,
2421
- t.isRotated
2402
+ t.isRotated,
2403
+ t.originX,
2404
+ t.originY
2422
2405
  );
2423
- }, wt = (s, t) => {
2406
+ }, Et = (s, t) => {
2424
2407
  t.points.length !== 0 && X(s, t, 0, 0, () => {
2425
2408
  s.startGraphic(
2426
2409
  t.drawMode ?? s.gl.TRIANGLES,
@@ -2435,22 +2418,22 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2435
2418
  i.y,
2436
2419
  r?.x ?? 0,
2437
2420
  r?.y ?? 0,
2438
- Q(s, n)
2421
+ st(s, n)
2439
2422
  );
2440
2423
  }
2441
2424
  s.endGraphic();
2442
2425
  });
2443
- }, Jt = (s, t) => {
2426
+ }, Zt = (s, t) => {
2444
2427
  if (s.inCreateMask)
2445
2428
  return;
2446
2429
  const { vertices: e, uv: i } = jt(t);
2447
- wt(s, {
2430
+ Et(s, {
2448
2431
  ...t,
2449
2432
  points: e,
2450
2433
  uv: i,
2451
2434
  drawMode: s.gl.TRIANGLES
2452
2435
  });
2453
- }, te = (s, t) => {
2436
+ }, Qt = (s, t) => {
2454
2437
  X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2455
2438
  s.startMaskGraphic(
2456
2439
  s.gl.TRIANGLE_FAN,
@@ -2458,7 +2441,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2458
2441
  t.customMatrix
2459
2442
  ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2460
2443
  });
2461
- }, ee = (s, t) => {
2444
+ }, Jt = (s, t) => {
2462
2445
  X(s, t, t.width, t.height, () => {
2463
2446
  s.startGraphic(
2464
2447
  s.gl.TRIANGLE_FAN,
@@ -2467,7 +2450,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2467
2450
  t.customMatrix
2468
2451
  ), s.addRectVertex(t.width, t.height, t.color), s.endGraphic();
2469
2452
  });
2470
- }, ie = (s, t) => {
2453
+ }, te = (s, t) => {
2471
2454
  const e = t.segments ?? 32;
2472
2455
  X(s, t, 0, 0, () => {
2473
2456
  s.startGraphic(
@@ -2476,10 +2459,10 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2476
2459
  t.shader,
2477
2460
  t.customMatrix
2478
2461
  );
2479
- const i = Q(s, t.color);
2462
+ const i = st(s, t.color);
2480
2463
  s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
2481
2464
  });
2482
- }, ft = `#version 300 es\r
2465
+ }, lt = `#version 300 es\r
2483
2466
  precision mediump float;\r
2484
2467
  \r
2485
2468
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -2529,21 +2512,21 @@ void main(void) {\r
2529
2512
  // CUSTOM_CODE_CALL\r
2530
2513
  }\r
2531
2514
  `;
2532
- class re extends at {
2515
+ class ee extends rt {
2533
2516
  KEY = "AtlasSprite";
2534
2517
  constructor(t) {
2535
2518
  super(t);
2536
2519
  }
2537
2520
  createCustomShader(t) {
2538
- const e = W(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2521
+ const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W($, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2539
2522
  return t.getGLShader(this, this.KEY, i, e);
2540
2523
  }
2541
2524
  createDefaultShader() {
2542
- const t = this.rapid, e = W(ft, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
2525
+ const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W($, t.maxTextureUnits);
2543
2526
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
2544
2527
  }
2545
2528
  }
2546
- const mt = `#version 300 es\r
2529
+ const dt = `#version 300 es\r
2547
2530
  precision mediump float;\r
2548
2531
  \r
2549
2532
  // per-vertex\r
@@ -2551,8 +2534,9 @@ in vec2 aVertex;\r
2551
2534
  \r
2552
2535
  // per-instance: 变换\r
2553
2536
  in vec2 aPosition;\r
2554
- in vec2 aScale;\r
2555
- in float aRotation;\r
2537
+ in vec2 aScale;
2538
+ in float aRotation;
2539
+ in vec2 aOrigin;
2556
2540
  \r
2557
2541
  // per-instance:UV 区域 (u0, v0, u1, v1)\r
2558
2542
  in vec4 aUVRect;\r
@@ -2572,13 +2556,18 @@ void main(void) {\r
2572
2556
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
2573
2557
  // CUSTOM_CODE_CALL\r
2574
2558
  \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
2559
+ vec2 scaled = (aVertex - aOrigin) * aScale;
2560
+ float c = cos(aRotation);\r
2561
+ float s = sin(aRotation);\r
2562
+ \r
2563
+ vec2 v = vec2(\r
2564
+ scaled.x * c - scaled.y * s,\r
2565
+ scaled.x * s + scaled.y * c\r
2566
+ ) + aPosition;\r
2567
+ \r
2579
2568
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
2580
2569
  }\r
2581
- `, xt = `#version 300 es\r
2570
+ `, ft = `#version 300 es\r
2582
2571
  precision mediump float;\r
2583
2572
  \r
2584
2573
  uniform sampler2D uTexture;\r
@@ -2594,18 +2583,18 @@ void main(void) {\r
2594
2583
  \r
2595
2584
  // CUSTOM_CODE_CALL\r
2596
2585
  }\r
2597
- `, H = 40, j = H / 4;
2598
- class se extends at {
2586
+ `, D = 48, mt = D / 4;
2587
+ class ie extends rt {
2599
2588
  KEY = "ParticleSprite";
2600
2589
  texture;
2601
2590
  constructor(t) {
2602
2591
  super(t);
2603
2592
  }
2604
2593
  createCustomShader(t) {
2605
- return t.getGLShader(this, this.KEY, mt, xt);
2594
+ return t.getGLShader(this, this.KEY, dt, ft);
2606
2595
  }
2607
2596
  createDefaultShader() {
2608
- const t = xt, e = mt;
2597
+ const t = ft, e = dt;
2609
2598
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
2610
2599
  }
2611
2600
  enter(t) {
@@ -2614,52 +2603,46 @@ class se extends at {
2614
2603
  createShader(t, e) {
2615
2604
  const i = super.createShader(t, e);
2616
2605
  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 }
2606
+ { name: "aPosition", size: 2, stride: D, offset: 0, divisor: 1 },
2607
+ { name: "aScale", size: 2, stride: D, offset: 8, divisor: 1 },
2608
+ { name: "aRotation", size: 1, stride: D, offset: 16, divisor: 1 },
2609
+ { name: "aUVRect", size: 4, stride: D, offset: 20, divisor: 1 },
2610
+ { name: "aColor", size: 4, type: et, normalized: !0, stride: D, offset: 36, divisor: 1 },
2611
+ { name: "aOrigin", size: 2, stride: D, offset: 40, divisor: 1 }
2622
2612
  ]), this.quadBuffer.bindBuffer(), i.setAttributes([
2623
2613
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2624
2614
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2625
2615
  }
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) {
2616
+ drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, g = !1, T = 0.5, y = 0.5) {
2634
2617
  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; ) {
2618
+ let w = 0;
2619
+ const M = t.rawWidth * o * (p ? -1 : 1), A = t.rawHeight * h * (x ? -1 : 1), F = g ? Math.PI / 2 : 0;
2620
+ for (; w < a; ) {
2638
2621
  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;
2622
+ const I = a - w, N = this.instanceBuffer;
2623
+ let S = N.usedElemNum;
2624
+ N.resize(I * mt);
2625
+ const R = N.float32, b = N.uint32;
2626
+ for (let U = 0; U < I; U++) {
2627
+ const L = w + U;
2628
+ R[S] = e[L], R[S + 1] = i[L], R[S + 2] = M, R[S + 3] = A, R[S + 4] = r[L] + F, R[S + 5] = c, R[S + 6] = u, R[S + 7] = f, R[S + 8] = l, b[S + 9] = n[L], R[S + 10] = T, R[S + 11] = y, S += mt;
2646
2629
  }
2647
- N.usedElemNum = A, N.makeDirty(), this.instanceCount += O, v += O, this.instanceCount >= K && this.flush();
2630
+ N.usedElemNum = S, N.makeDirty(), this.instanceCount += I, w += I;
2648
2631
  }
2649
2632
  }
2650
2633
  render() {
2651
2634
  if (this.instanceCount === 0) return;
2652
- super.render();
2635
+ this.prepareRender();
2653
2636
  const t = this.gl;
2654
2637
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2655
2638
  const e = this.currentShader;
2656
2639
  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;
2640
+ const i = this.rapid.matrixStack, n = this.rapid.matrix.getMatrix(i.curWorldM), a = Vt(this.rapid.projection, n);
2641
+ this.currentShader.setUniform("u_projection", a), this.currentShader.setUniform("u_projection", this.rapid.projection), vt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0;
2659
2642
  }
2660
2643
  }
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 {
2644
+ var re = /* @__PURE__ */ ((s) => (s[s.EQUAL = 0] = "EQUAL", s[s.NOT_EQUAL = 1] = "NOT_EQUAL", s))(re || {}), se = /* @__PURE__ */ ((s) => (s[s.NORMAL = 0] = "NORMAL", s[s.ADD = 1] = "ADD", s[s.MULTIPLY = 2] = "MULTIPLY", s[s.SCREEN = 3] = "SCREEN", s[s.ERASE = 4] = "ERASE", s))(se || {}), it = /* @__PURE__ */ ((s) => (s[s.LINEAR = 0] = "LINEAR", s[s.NEAREST = 1] = "NEAREST", s))(it || {}), ne = /* @__PURE__ */ ((s) => (s[s.CanvasItem = 0] = "CanvasItem", s[s.Viewport = 1] = "Viewport", s))(ne || {});
2645
+ class ce {
2663
2646
  /** The active WebGL context. */
2664
2647
  gl;
2665
2648
  /** The target HTMLCanvasElement. */
@@ -2685,7 +2668,7 @@ class le {
2685
2668
  /** Maximum number of texture units supported by the device. */
2686
2669
  maxTextureUnits = 0;
2687
2670
  /** Matrix stack for hierarchical transformations. */
2688
- matrixStack = new bt(this);
2671
+ matrixStack = new St(this);
2689
2672
  /** Direct access to the underlying matrix store. */
2690
2673
  matrix;
2691
2674
  /** Region dedicated to fast sprite rendering. */
@@ -2723,10 +2706,10 @@ class le {
2723
2706
  */
2724
2707
  constructor(t) {
2725
2708
  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;
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);
2709
+ const e = Ct(this.canvas, this.antialias, this.premultipliedAlpha);
2710
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new rt(this), this.graphicRegion = new Ht(this), this.atlasSpriteRegion = new ee(this), this.particleRegion = new ie(this);
2728
2711
  const i = this.canvas.clientWidth || this.canvas.width, r = this.canvas.clientHeight || this.canvas.height;
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);
2712
+ this.physicsWidth = t.physicsWidth || Math.round(i * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(r * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new bt(this), t.backgroundColor && (this.backgroundColor = t.backgroundColor), e.enable(e.BLEND), this.premultipliedAlpha ? e.blendFunc(e.ONE, e.ONE_MINUS_SRC_ALPHA) : e.blendFunc(e.SRC_ALPHA, e.ONE_MINUS_SRC_ALPHA), e.enable(e.STENCIL_TEST), e.stencilFunc(e.ALWAYS, 1, 255), e.stencilOp(e.KEEP, e.KEEP, e.KEEP);
2730
2713
  }
2731
2714
  setTextureFilter(t) {
2732
2715
  this.textureFilter = t;
@@ -2745,26 +2728,23 @@ class le {
2745
2728
  enterRegion(t, e) {
2746
2729
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2747
2730
  }
2748
- drawParticle(t) {
2749
- Zt(this, t);
2750
- }
2751
2731
  drawParticles(t) {
2752
- Qt(this, t);
2732
+ qt(this, t), this.flush();
2753
2733
  }
2754
2734
  drawSprite(t) {
2755
- qt(this, t);
2735
+ Kt(this, t);
2756
2736
  }
2757
2737
  drawLine(t) {
2758
- Jt(this, t);
2738
+ Zt(this, t);
2759
2739
  }
2760
2740
  drawGraphic(t) {
2761
- wt(this, t);
2741
+ Et(this, t);
2762
2742
  }
2763
2743
  drawRect(t) {
2764
- ee(this, t);
2744
+ Jt(this, t);
2765
2745
  }
2766
2746
  drawCircle(t) {
2767
- ie(this, t);
2747
+ te(this, t);
2768
2748
  }
2769
2749
  /**
2770
2750
  * Starts rendering arbitrary graphics geometries.
@@ -2788,7 +2768,7 @@ class le {
2788
2768
  * @param texture The texture to be used as a mask.
2789
2769
  */
2790
2770
  drawMaskImage(t) {
2791
- te(this, t);
2771
+ Qt(this, t);
2792
2772
  }
2793
2773
  /**
2794
2774
  * Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
@@ -3193,7 +3173,7 @@ class le {
3193
3173
  return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, i);
3194
3174
  }
3195
3175
  }
3196
- function oe(s) {
3176
+ function ae(s) {
3197
3177
  return !(s === null || typeof s != "object" || Array.isArray(s) || s instanceof d || s instanceof m);
3198
3178
  }
3199
3179
  class C {
@@ -3259,9 +3239,9 @@ class C {
3259
3239
  return typeof t == "number" ? t : t.clone();
3260
3240
  }
3261
3241
  }
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 {
3242
+ var he = /* @__PURE__ */ ((s) => (s.POINT = "point", s.CIRCLE = "circle", s.RECT = "rect", s))(he || {});
3243
+ const xt = 10, pt = 0, gt = !0;
3244
+ class oe {
3265
3245
  life = 0;
3266
3246
  maxLife;
3267
3247
  texture;
@@ -3281,7 +3261,7 @@ class ue {
3281
3261
  processAttribute(t, e) {
3282
3262
  if (t == null)
3283
3263
  return { value: e };
3284
- if (oe(t)) {
3264
+ if (ae(t)) {
3285
3265
  const i = t, r = C.scalarOrRange(i.start, e), n = i.end === void 0 ? r : C.scalarOrRange(i.end, e);
3286
3266
  return {
3287
3267
  delta: i.delta ?? this.getDelta(r, n, this.maxLife),
@@ -3325,7 +3305,7 @@ class ue {
3325
3305
  const t = this.rapid.matrixStack, e = this.datas.scale.value, i = this.datas.rotation.value, r = this.datas.color.value;
3326
3306
  t.save(), t.translate(this.position.x, this.position.y), i !== 0 && t.rotate(i), e !== 1 && t.scale(e, e);
3327
3307
  const n = this.options.origin ? this.options.origin.x : 0.5, a = this.options.origin ? this.options.origin.y : 0.5;
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();
3308
+ (n !== 0 || a !== 0) && t.translate(-n * this.texture.rawWidth, -a * this.texture.rawHeight), Rt(this.rapid, { texture: this.texture, color: r }), t.restore();
3329
3309
  }
3330
3310
  initializePosition() {
3331
3311
  switch (this.options.emitShape) {
@@ -3348,16 +3328,16 @@ class ue {
3348
3328
  !this.options.localSpace && this.options.position && (this.position = this.position.add(this.options.position));
3349
3329
  }
3350
3330
  }
3351
- class Mt {
3331
+ class wt {
3352
3332
  particles = [];
3353
3333
  options;
3354
3334
  emitting = !1;
3355
3335
  emitTimer = 0;
3356
- emitRate = pt;
3357
- emitTime = gt;
3336
+ emitRate = xt;
3337
+ emitTime = pt;
3358
3338
  emitTimeCounter = 0;
3359
3339
  /** Whether spawned particles are positioned in local emitter space (default: true). */
3360
- localSpace = vt;
3340
+ localSpace = gt;
3361
3341
  /** World position of the emitter. Used for both local-space transform and world-space spawn offset. */
3362
3342
  position = d.ZERO;
3363
3343
  rapid;
@@ -3368,7 +3348,7 @@ class Mt {
3368
3348
  * @param options - Emitter configuration options
3369
3349
  */
3370
3350
  constructor(t, e) {
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;
3351
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate !== void 0 ? e.emitRate : xt, this.emitTime = e.emitTime !== void 0 ? e.emitTime : pt, this.localSpace = e.localSpace !== void 0 ? e.localSpace : gt, this.position = e.position ?? d.ZERO;
3372
3352
  }
3373
3353
  /** Replaces the emitter's texture at runtime. */
3374
3354
  setTexture(t) {
@@ -3379,7 +3359,7 @@ class Mt {
3379
3359
  * Particle state is NOT copied.
3380
3360
  */
3381
3361
  clone() {
3382
- return new Mt(this.rapid, { ...this.options });
3362
+ return new wt(this.rapid, { ...this.options });
3383
3363
  }
3384
3364
  /** Sets particles-per-second emission rate (continuous mode). */
3385
3365
  setEmitRate(t) {
@@ -3408,7 +3388,7 @@ class Mt {
3408
3388
  emit(t) {
3409
3389
  const e = this.options.maxParticles ?? 1 / 0, i = Math.min(t, e - this.particles.length);
3410
3390
  for (let r = 0; r < i; r++)
3411
- this.particles.push(new ue(this.rapid, { ...this.options, position: this.position }));
3391
+ this.particles.push(new oe(this.rapid, { ...this.options, position: this.position }));
3412
3392
  }
3413
3393
  /**
3414
3394
  * Updates the emitter and all live particles.
@@ -3456,44 +3436,42 @@ class Mt {
3456
3436
  }
3457
3437
  }
3458
3438
  export {
3459
- I as ArrayType,
3460
- B as BaseTexture,
3461
- ae as BlendMode,
3462
- he as CanvasScaleMode,
3439
+ O as ArrayType,
3440
+ k as BaseTexture,
3441
+ se as BlendMode,
3442
+ ne as CanvasScaleMode,
3463
3443
  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,
3444
+ ot as CustomGlShader,
3445
+ B as DynamicArrayBuffer,
3446
+ Tt as GLShader,
3447
+ Ht as GraphicRegion,
3448
+ Yt as LineTextureMode,
3449
+ re as MaskType,
3450
+ St as MatrixStack,
3451
+ Mt as MatrixStore,
3452
+ oe as Particle,
3453
+ wt as ParticleEmitter,
3454
+ he as ParticleShape,
3455
+ Ft as QUAD_VERTICES,
3456
+ ce as Rapid,
3457
+ yt as Region,
3458
+ At as RenderTexture,
3459
+ rt as SpriteRegion,
3460
+ _t as TextTexture,
3482
3461
  P as Texture,
3483
- nt as TextureFilterMode,
3484
- At as TextureManager,
3485
- z as TextureWrapMode,
3462
+ it as TextureFilterMode,
3463
+ bt as TextureManager,
3464
+ Y as TextureWrapMode,
3486
3465
  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,
3466
+ Q as WebglBufferArray,
3467
+ Vt as composeProjectionWithAffine,
3468
+ te as drawCircle,
3469
+ Et as drawGraphic,
3470
+ Zt as drawLine,
3471
+ Qt as drawMaskImage,
3472
+ qt as drawParticles,
3473
+ Jt as drawRect,
3474
+ Kt as drawSprite,
3475
+ Rt as drawSpriteRaw,
3498
3476
  zt as multiplyMat4
3499
3477
  };