rapid-render 1.0.4 → 1.0.5

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.
package/dist/draw.d.ts CHANGED
@@ -26,6 +26,8 @@ export interface IDrawParticleOptions {
26
26
  rotation?: number;
27
27
  scaleX?: number;
28
28
  scaleY?: number;
29
+ originX?: number;
30
+ originY?: number;
29
31
  isRotated?: boolean;
30
32
  }
31
33
  export interface IDrawParticleBatchOptions {
@@ -38,6 +40,8 @@ export interface IDrawParticleBatchOptions {
38
40
  count?: number;
39
41
  scaleX?: number;
40
42
  scaleY?: number;
43
+ originX?: number;
44
+ originY?: number;
41
45
  flipX?: boolean;
42
46
  flipY?: boolean;
43
47
  isRotated?: boolean;
@@ -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 L = /* @__PURE__ */ ((s) => (s[s.Float32 = 0] = "Float32", s[s.Uint32 = 1] = "Uint32", s[s.Uint16 = 2] = "Uint16", s))(L || {});
2
+ class k {
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 et extends k {
155
155
  /** The actual WebGLBuffer object maintained by this instance. */
156
156
  buffer;
157
157
  /** The related WebGL rendering context. */
@@ -451,7 +451,7 @@ 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;
454
+ const E = 6;
455
455
  class St {
456
456
  /** Total number of matrices currently allocated in the store. */
457
457
  matrixCount = 0;
@@ -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 k(L.Float32), this.buffer.resize(t * E), 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(E) && (this.data = this.buffer.getArray()), this.buffer.usedElemNum += E, 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 * E, 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 * E, 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 * E, 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 * E, r = this.data, n = Math.cos(e), a = Math.sin(e), o = r[i], h = r[i + 1], c = r[i + 2], u = r[i + 3];
525
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 * E, r = e * E, 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 * E, n = e * E, a = i * E, o = this.data, h = o[n], c = o[n + 1], u = o[n + 2], f = o[n + 3], l = o[n + 4], p = o[n + 5], x = o[a], v = o[a + 1], R = o[a + 2], T = o[a + 3], g = o[a + 4], w = o[a + 5];
571
+ o[r] = h * x + u * v, o[r + 1] = c * x + f * v, o[r + 2] = h * R + u * T, o[r + 3] = c * R + f * T, o[r + 4] = h * g + u * w + l, o[r + 5] = c * g + f * w + p;
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 * E, i = this.data, r = i[e], n = i[e + 1], a = i[e + 2], o = i[e + 3], h = i[e + 4], c = i[e + 5];
579
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 * E, 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 -= E, 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 * E, 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 * E, i = this.data, r = Math.sqrt(i[e] * i[e] + i[e + 1] * i[e + 1]), n = Math.sqrt(i[e + 2] * i[e + 2] + i[e + 3] * i[e + 3]);
640
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 * E, 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 * E, 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 * E;
671
+ return this.data.slice(e, e + E);
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 * E;
682
+ return this.data.subarray(e, e + E);
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,12 +688,12 @@ 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 * E, 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) {
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;
695
+ const h = t * 6, c = this.data, u = c[h], f = c[h + 1], l = c[h + 2], p = c[h + 3], x = c[h + 4], v = c[h + 5];
696
+ c[h] = u * e + l * i, c[h + 1] = f * e + p * i, c[h + 2] = u * r + l * n, c[h + 3] = f * r + p * n, c[h + 4] = u * a + l * o + x, c[h + 5] = f * a + p * o + v;
697
697
  }
698
698
  }
699
699
  class bt {
@@ -702,15 +702,15 @@ class bt {
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 k(L.Uint32);
706
706
  /** Records the world matrices generated at each step. */
707
- stepWorldM = new D(I.Uint32);
707
+ stepWorldM = new k(L.Uint32);
708
708
  /** Records actions (push/pop) taken during the traversal. */
709
- stepAction = new D(I.Uint32);
709
+ stepAction = new k(L.Uint32);
710
710
  /** Records the parent world matrix for each step (used by updateMatrix). */
711
- stepParentM = new D(I.Uint32);
711
+ stepParentM = new k(L.Uint32);
712
712
  /** Buffer used during hierarchy traversal updates. */
713
- parentStack = new D(I.Uint32);
713
+ parentStack = new k(L.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 * E;
863
+ return this.matrix.data.slice(t, t + E);
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 * E, 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,27 +888,27 @@ 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, v = p * a, R = x * a, T = -x * o, g = p * o, w = r + v * u + T * f, b = n + R * u + g * f;
892
892
  (t.afterSave !== void 0 || t.saveTransform === !1) && this.matrix.multiplyAffineInPlace(
893
893
  this.curLocalM,
894
- g,
895
894
  v,
896
- y,
897
- w,
895
+ R,
898
896
  T,
899
- S
897
+ g,
898
+ w,
899
+ b
900
900
  ), this.matrix.multiplyAffineInPlace(
901
901
  this.curWorldM,
902
- g,
903
902
  v,
904
- y,
905
- w,
903
+ R,
906
904
  T,
907
- S
905
+ g,
906
+ w,
907
+ b
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 || {});
911
+ var $ = /* @__PURE__ */ ((s) => (s[s.REPEAT = 0] = "REPEAT", s[s.CLAMP = 1] = "CLAMP", s[s.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", s))($ || {});
912
912
  class At {
913
913
  render;
914
914
  cache = /* @__PURE__ */ new Map();
@@ -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 = G.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 = G.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
  /**
@@ -988,7 +988,7 @@ class At {
988
988
  });
989
989
  }
990
990
  }
991
- class B {
991
+ class G {
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 = Q(t, e, i);
1009
+ return new G(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).
@@ -1120,8 +1120,8 @@ class P {
1120
1120
  if (!this.base) return [];
1121
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
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));
1123
+ for (let v = 0; v < l; v++)
1124
+ a.push(this.getSubTexture(v * u, x * f, t, e));
1125
1125
  return a;
1126
1126
  }
1127
1127
  /**
@@ -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 = Q(t, e, i);
1134
+ return new P(new G(r, e.width, e.height));
1135
1135
  }
1136
1136
  /**
1137
1137
  * Marks this Texture as destroyed, decrementing the BaseTexture reference count.
@@ -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 = Q(t, { width: i, height: r }, { ...e, onlySize: !0 });
1155
+ if (this.setBase(new G(a, i, r)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1156
1156
  throw new Error("Failed to create Framebuffer or Renderbuffer");
1157
1157
  this.resize(i, r, !0);
1158
1158
  }
@@ -1252,8 +1252,8 @@ class Ct extends P {
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 = Q(t, this.canvas, this.options);
1256
+ this.setBase(new G(r, 1, 1)), this.update();
1257
1257
  }
1258
1258
  get text() {
1259
1259
  return this._text;
@@ -1308,17 +1308,17 @@ 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 w of o) {
1312
+ const b = t.measureText(w);
1313
+ b.width > h && (h = b.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);
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;
1316
+ const p = (this._style.strokeThickness || 0) * 2, x = Math.ceil(h + p) || 1, v = Math.ceil(c + p) || 1, R = x * a, T = v * a;
1317
+ (this.canvas.width !== R || this.canvas.height !== T) && (this.canvas.width = R, this.canvas.height = T), t.setTransform(a, 0, 0, a, 0, 0), t.clearRect(0, 0, x, v), t.font = n, t.textBaseline = "top", t.textAlign = "left", this.updateOffset(x, v);
1318
+ let g = p / 2;
1319
+ for (const w of o) {
1320
+ let b = p / 2;
1321
+ this._style.stroke && this._style.strokeThickness > 0 && (t.lineWidth = this._style.strokeThickness, t.strokeStyle = this._style.stroke, t.strokeText(w, b, g)), this._style.fill && (t.fillStyle = this._style.fill, t.fillText(w, b, g)), g += f + l;
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
  }
@@ -1349,9 +1349,9 @@ const Pt = (s, t = !1, e = !0) => {
1349
1349
  };
1350
1350
  function it(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
+ [$.CLAMP]: s.CLAMP_TO_EDGE,
1353
+ [$.REPEAT]: s.REPEAT,
1354
+ [$.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
  }
@@ -1362,11 +1362,11 @@ function rt(s, t) {
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 Q(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), it(i, e.wrap ?? $.CLAMP), rt(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 {
@@ -1375,7 +1375,7 @@ function Z(s, t, e) {
1375
1375
  }
1376
1376
  return i.bindTexture(i.TEXTURE_2D, null), r;
1377
1377
  }
1378
- function W(s, t) {
1378
+ function F(s, t) {
1379
1379
  if (s.includes("%TEXTURE_NUM%") && (s = s.replace("%TEXTURE_NUM%", t.toString())), s.includes("%GET_COLOR%")) {
1380
1380
  let e = "";
1381
1381
  for (let i = 0; i < t; i++)
@@ -1623,7 +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;
1626
+ const q = 1 / 0;
1627
1627
  class Rt {
1628
1628
  constructor(t) {
1629
1629
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
@@ -1724,7 +1724,7 @@ class Rt {
1724
1724
  return !1;
1725
1725
  }
1726
1726
  }
1727
- const q = `#version 300 es\r
1727
+ const Z = `#version 300 es\r
1728
1728
  precision mediump float;\r
1729
1729
  \r
1730
1730
  // per-vertex\r
@@ -1821,7 +1821,7 @@ void main(void) {\r
1821
1821
  \r
1822
1822
  // CUSTOM_CODE_CALL\r
1823
1823
  }\r
1824
- `, V = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1824
+ `, z = 48, Dt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1825
1825
  class at extends Rt {
1826
1826
  instanceBuffer;
1827
1827
  quadBuffer;
@@ -1834,28 +1834,28 @@ class at extends Rt {
1834
1834
  }
1835
1835
  createBuffer() {
1836
1836
  const t = this.gl;
1837
- this.quadBuffer = new et(t, I.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1837
+ this.quadBuffer = new et(t, L.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1838
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.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new et(t, L.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1840
1840
  }
1841
1841
  createDefaultShader() {
1842
- const t = this.rapid, e = W(lt, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
1842
+ const t = this.rapid, e = F(lt, t.maxTextureUnits), i = F(Z, t.maxTextureUnits);
1843
1843
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
1844
1844
  }
1845
1845
  createShader(t, e) {
1846
1846
  const i = super.createShader(t, e);
1847
1847
  return i.use(), i.bindVAO(), this.instanceBuffer.bindBuffer(), i.setAttributes([
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 }
1848
+ { name: "aMatrixRow0", size: 3, stride: z, offset: 0, divisor: 1 },
1849
+ { name: "aMatrixRow1", size: 3, stride: z, offset: 12, divisor: 1 },
1850
+ { name: "aUVRect", size: 4, stride: z, offset: 24, divisor: 1 },
1851
+ { name: "aColor", size: 4, type: st, normalized: !0, stride: z, offset: 40, divisor: 1 },
1852
+ { name: "aTextureId", size: 1, type: st, stride: z, offset: 44, divisor: 1 }
1853
1853
  ]), this.quadBuffer.bindBuffer(), i.setAttributes([
1854
1854
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1855
1855
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
1856
1856
  }
1857
1857
  createCustomShader(t) {
1858
- const e = W(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1858
+ const e = F(lt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1859
1859
  return t.getGLShader(this, this.KEY, i, e);
1860
1860
  }
1861
1861
  /**
@@ -1892,18 +1892,18 @@ class at extends Rt {
1892
1892
  l
1893
1893
  );
1894
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.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(
1895
+ drawSpriteAffine(t, e, i, r, n, a, o, h = 0, c = 0, u = 1, f = 1, l = 4294967295, p = 0, x = 0, v = !1, R = !1, T = !1) {
1896
+ this.instanceCount > q && this.flush();
1897
+ const g = t.base, w = t.scale ?? 1, b = t.rawWidth, A = t.rawHeight, I = t.offsetX, Y = t.offsetY, N = this.useTexture(
1898
1898
  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));
1899
+ p / w / g.width,
1900
+ x / w / g.height
1901
+ ), U = this.instanceBuffer, y = U.usedElemNum;
1902
+ U.resize(12);
1903
+ const M = U.float32, D = U.uint32, O = (T ? A : b) * w, W = (T ? b : A) * w, H = O + 2 * p, V = W + 2 * x, ht = I - p, ot = Y - x, S = this.localSpriteMatrix;
1904
+ T ? (S[0] = 0, S[1] = R ? V : -V, S[2] = v ? -H : H, S[3] = 0, S[4] = ht + (v ? H : 0), S[5] = ot + (R ? 0 : V)) : (S[0] = v ? -H : H, S[1] = 0, S[2] = 0, S[3] = R ? -V : V, S[4] = ht + (v ? H : 0), S[5] = ot + (R ? V : 0));
1905
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++;
1906
+ _[0] = e * S[0] + r * S[1], _[1] = i * S[0] + n * S[1], _[2] = e * S[2] + r * S[3], _[3] = i * S[2] + n * S[3], _[4] = a + e * S[4] + r * S[5], _[5] = o + i * S[4] + n * S[5], M[y + 6] = h, M[y + 7] = c, M[y + 8] = u, M[y + 9] = f, D[y + 10] = l, D[y + 11] = N, this.rapid.roundPixels && (_[4] = Math.round(_[4]), _[5] = Math.round(_[5])), M[y] = _[0], M[y + 1] = _[2], M[y + 2] = _[4], M[y + 3] = _[1], M[y + 4] = _[3], M[y + 5] = _[5], U.usedElemNum += 12, U.makeDirty(), this.instanceCount++;
1907
1907
  }
1908
1908
  render() {
1909
1909
  if (this.instanceCount === 0) return;
@@ -2038,7 +2038,7 @@ void main(void) {\r
2038
2038
  discard;\r
2039
2039
  }\r
2040
2040
  }\r
2041
- `, Y = 20;
2041
+ `, X = 20;
2042
2042
  class Vt extends Rt {
2043
2043
  vertexBuffer;
2044
2044
  vertexCount = 0;
@@ -2052,7 +2052,7 @@ class Vt extends Rt {
2052
2052
  }
2053
2053
  createBuffer() {
2054
2054
  const t = this.gl;
2055
- this.vertexBuffer = new et(t, I.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Ht);
2055
+ this.vertexBuffer = new et(t, L.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Gt, Ht);
2056
2056
  }
2057
2057
  createDefaultShader() {
2058
2058
  return this.vs = Bt, this.fs = kt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
@@ -2060,16 +2060,16 @@ class Vt extends Rt {
2060
2060
  createMaskShader(t, e) {
2061
2061
  const i = this.gl, r = new yt(i, t, e);
2062
2062
  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 }
2063
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: X - 4, offset: 0, divisor: 0 },
2064
+ { name: "aUV", size: 2, type: i.FLOAT, stride: X - 4, offset: 8, divisor: 0 }
2065
2065
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2066
2066
  }
2067
2067
  createShader(t, e) {
2068
2068
  const i = this.gl, r = super.createShader(t, e);
2069
2069
  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 }
2070
+ { name: "aPosition", size: 2, type: i.FLOAT, stride: X, offset: 0, divisor: 0 },
2071
+ { name: "aColor", size: 4, type: i.UNSIGNED_BYTE, normalized: !0, stride: X, offset: 8, divisor: 0 },
2072
+ { name: "aUV", size: 2, type: i.FLOAT, stride: X, offset: 12, divisor: 0 }
2073
2073
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2074
2074
  }
2075
2075
  /**
@@ -2273,8 +2273,8 @@ var Xt = /* @__PURE__ */ ((s) => (s[s.STRETCH = 0] = "STRETCH", s[s.REPEAT = 1]
2273
2273
  const tt = 10, dt = (s, t, e, i, r, n) => {
2274
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
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
+ const l = f / tt, p = (f + 1) / tt, x = h + l * c, v = h + p * c, R = new d(Math.cos(x) * e, Math.sin(x) * e), T = new d(Math.cos(v) * e, Math.sin(v) * e);
2277
+ a.push(s), o.push(new d(r, 0.5)), a.push(s.add(R)), o.push(new d(r + R.dot(u) * n, 0.5 - 0.5 * R.dot(t) / e)), a.push(s.add(T)), o.push(new d(r + T.dot(u) * n, 0.5 - 0.5 * T.dot(t) / e));
2278
2278
  }
2279
2279
  return { vertices: a, uv: o };
2280
2280
  }, $t = (s, t = !1) => {
@@ -2297,8 +2297,8 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2297
2297
  {
2298
2298
  let x = l.add(f).normalize();
2299
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) };
2300
+ let v = 1 / Math.sqrt((1 - p) / 2);
2301
+ return { normal: x, miters: Math.min(v, i) };
2302
2302
  }
2303
2303
  };
2304
2304
  if (t)
@@ -2324,27 +2324,27 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2324
2324
  let c = 0;
2325
2325
  const u = s.texture?.rawWidth || 1, f = s.closed ? t.length : t.length - 1;
2326
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;
2327
+ const p = t[l], x = e[l].normal, v = e[l].miters, R = (l + 1) % t.length, T = t[R], g = e[R].normal, w = e[R].miters, b = p.add(x.multiply(v * r)), A = p.subtract(x.multiply(v * r)), I = T.add(g.multiply(w * r)), Y = T.subtract(g.multiply(w * r)), N = p.distanceTo(T);
2328
+ let U = 0, y = 0;
2329
+ h === 0 ? (U = c / i, y = (c + N) / i) : (U = c / u, y = U + N / u);
2330
+ const M = new d(U, 0), D = new d(U, 1), O = new d(y, 0), W = new d(y, 1);
2331
+ n.push(b), a.push(M), n.push(A), a.push(D), n.push(I), a.push(O), n.push(I), a.push(O), n.push(Y), a.push(W), n.push(A), a.push(D), c += N;
2332
2332
  }
2333
2333
  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
- 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);
2334
+ const l = t[0], p = e[0].normal, x = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, v = dt(l, p, r, !0, 0, x);
2335
+ n.push(...v.vertices), a.push(...v.uv);
2336
+ const R = t[t.length - 1], T = e[t.length - 1].normal, g = h === 0 ? 1 : c / u, w = h === 0 ? i > 0 ? 1 / i : 0 : 1 / u, b = dt(R, T, r, !1, g, w);
2337
+ n.push(...b.vertices), a.push(...b.uv);
2338
2338
  }
2339
2339
  return { vertices: n, uv: a };
2340
- }, X = (s, t, e, i, r) => {
2340
+ }, j = (s, t, e, i, r) => {
2341
2341
  s.matrixStack.applyTransform(t, e, i);
2342
2342
  try {
2343
2343
  r();
2344
2344
  } finally {
2345
2345
  t.saveTransform !== !1 && s.matrixStack.restore();
2346
2346
  }
2347
- }, Q = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, Et = (s, t) => {
2347
+ }, J = (s, t) => t ? s.premultipliedAlpha ? t.premultipliedUint32 : t.uint32 : 4294967295, Kt = 2, Et = (s, t) => {
2348
2348
  const e = t.texture;
2349
2349
  if (!e?.base || s.inCreateMask)
2350
2350
  return;
@@ -2362,7 +2362,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2362
2362
  n,
2363
2363
  a,
2364
2364
  o,
2365
- Q(s, t.color),
2365
+ J(s, t.color),
2366
2366
  f,
2367
2367
  l,
2368
2368
  h,
@@ -2370,7 +2370,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2370
2370
  e.isRotated
2371
2371
  );
2372
2372
  }, qt = (s, t) => {
2373
- X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2373
+ j(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2374
2374
  Et(s, t);
2375
2375
  });
2376
2376
  }, Zt = (s, t) => {
@@ -2388,10 +2388,12 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2388
2388
  n,
2389
2389
  a,
2390
2390
  o,
2391
- Q(s, t.color),
2391
+ J(s, t.color),
2392
2392
  t.flipX,
2393
2393
  t.flipY,
2394
- t.isRotated
2394
+ t.isRotated,
2395
+ t.originX,
2396
+ t.originY
2395
2397
  );
2396
2398
  }, Qt = (s, t) => {
2397
2399
  const e = s.particleRegion;
@@ -2418,10 +2420,12 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2418
2420
  i.uvH,
2419
2421
  t.flipX,
2420
2422
  t.flipY,
2421
- t.isRotated
2423
+ t.isRotated,
2424
+ t.originX,
2425
+ t.originY
2422
2426
  );
2423
2427
  }, wt = (s, t) => {
2424
- t.points.length !== 0 && X(s, t, 0, 0, () => {
2428
+ t.points.length !== 0 && j(s, t, 0, 0, () => {
2425
2429
  s.startGraphic(
2426
2430
  t.drawMode ?? s.gl.TRIANGLES,
2427
2431
  t.texture,
@@ -2435,7 +2439,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2435
2439
  i.y,
2436
2440
  r?.x ?? 0,
2437
2441
  r?.y ?? 0,
2438
- Q(s, n)
2442
+ J(s, n)
2439
2443
  );
2440
2444
  }
2441
2445
  s.endGraphic();
@@ -2451,7 +2455,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2451
2455
  drawMode: s.gl.TRIANGLES
2452
2456
  });
2453
2457
  }, te = (s, t) => {
2454
- X(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2458
+ j(s, t, t.texture.rawWidth, t.texture.rawHeight, () => {
2455
2459
  s.startMaskGraphic(
2456
2460
  s.gl.TRIANGLE_FAN,
2457
2461
  t.texture,
@@ -2459,7 +2463,7 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2459
2463
  ), s.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), s.endGraphic();
2460
2464
  });
2461
2465
  }, ee = (s, t) => {
2462
- X(s, t, t.width, t.height, () => {
2466
+ j(s, t, t.width, t.height, () => {
2463
2467
  s.startGraphic(
2464
2468
  s.gl.TRIANGLE_FAN,
2465
2469
  t.texture,
@@ -2469,14 +2473,14 @@ const tt = 10, dt = (s, t, e, i, r, n) => {
2469
2473
  });
2470
2474
  }, ie = (s, t) => {
2471
2475
  const e = t.segments ?? 32;
2472
- X(s, t, 0, 0, () => {
2476
+ j(s, t, 0, 0, () => {
2473
2477
  s.startGraphic(
2474
2478
  s.gl.TRIANGLE_FAN,
2475
2479
  void 0,
2476
2480
  t.shader,
2477
2481
  t.customMatrix
2478
2482
  );
2479
- const i = Q(s, t.color);
2483
+ const i = J(s, t.color);
2480
2484
  s.addGraphicVertex(0, 0, 0.5, 0.5, i), s.addCircleVertex(t.radius, t.color, e), s.addGraphicVertex(t.radius, 0, 1, 0.5, i), s.endGraphic();
2481
2485
  });
2482
2486
  }, ft = `#version 300 es\r
@@ -2535,11 +2539,11 @@ class re extends at {
2535
2539
  super(t);
2536
2540
  }
2537
2541
  createCustomShader(t) {
2538
- const e = W(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = W(q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2542
+ const e = F(ft, this.rapid.maxTextureUnits - t.usedTextureUnitNum), i = F(Z, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2539
2543
  return t.getGLShader(this, this.KEY, i, e);
2540
2544
  }
2541
2545
  createDefaultShader() {
2542
- const t = this.rapid, e = W(ft, t.maxTextureUnits), i = W(q, t.maxTextureUnits);
2546
+ const t = this.rapid, e = F(ft, t.maxTextureUnits), i = F(Z, t.maxTextureUnits);
2543
2547
  return this.vs = i, this.fs = e, this.defaultShader = this.createShader(i, e), this.defaultShader;
2544
2548
  }
2545
2549
  }
@@ -2551,8 +2555,9 @@ in vec2 aVertex;\r
2551
2555
  \r
2552
2556
  // per-instance: 变换\r
2553
2557
  in vec2 aPosition;\r
2554
- in vec2 aScale;\r
2555
- in float aRotation;\r
2558
+ in vec2 aScale;
2559
+ in float aRotation;
2560
+ in vec2 aOrigin;
2556
2561
  \r
2557
2562
  // per-instance:UV 区域 (u0, v0, u1, v1)\r
2558
2563
  in vec4 aUVRect;\r
@@ -2572,10 +2577,15 @@ void main(void) {\r
2572
2577
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
2573
2578
  // CUSTOM_CODE_CALL\r
2574
2579
  \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
2580
+ vec2 scaled = (aVertex - aOrigin) * aScale;
2581
+ float c = cos(aRotation);\r
2582
+ float s = sin(aRotation);\r
2583
+ \r
2584
+ vec2 v = vec2(\r
2585
+ scaled.x * c - scaled.y * s,\r
2586
+ scaled.x * s + scaled.y * c\r
2587
+ ) + aPosition;\r
2588
+ \r
2579
2589
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
2580
2590
  }\r
2581
2591
  `, xt = `#version 300 es\r
@@ -2594,7 +2604,7 @@ void main(void) {\r
2594
2604
  \r
2595
2605
  // CUSTOM_CODE_CALL\r
2596
2606
  }\r
2597
- `, H = 40, j = H / 4;
2607
+ `, B = 48, K = B / 4;
2598
2608
  class se extends at {
2599
2609
  KEY = "ParticleSprite";
2600
2610
  texture;
@@ -2614,37 +2624,38 @@ class se extends at {
2614
2624
  createShader(t, e) {
2615
2625
  const i = super.createShader(t, e);
2616
2626
  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 }
2627
+ { name: "aPosition", size: 2, stride: B, offset: 0, divisor: 1 },
2628
+ { name: "aScale", size: 2, stride: B, offset: 8, divisor: 1 },
2629
+ { name: "aRotation", size: 1, stride: B, offset: 16, divisor: 1 },
2630
+ { name: "aUVRect", size: 4, stride: B, offset: 20, divisor: 1 },
2631
+ { name: "aColor", size: 4, type: st, normalized: !0, stride: B, offset: 36, divisor: 1 },
2632
+ { name: "aOrigin", size: 2, stride: B, offset: 40, divisor: 1 }
2622
2633
  ]), this.quadBuffer.bindBuffer(), i.setAttributes([
2623
2634
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2624
2635
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2625
2636
  }
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++;
2637
+ drawParticle(t, e = 0, i = 0, r = 1, n = 1, a = 0, o = 0, h = 0, c = 1, u = 1, f = 4294967295, l = !1, p = !1, x = !1, v = 0.5, R = 0.5) {
2638
+ (this.instanceCount >= q || this.texture && t != this.texture) && this.flush(), t.glTexture && (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2639
+ const T = this.instanceBuffer, g = T.usedElemNum, w = t.rawWidth, b = t.rawHeight;
2640
+ T.resize(K);
2641
+ const A = T.float32, I = T.uint32;
2642
+ A[g] = e, A[g + 1] = i, A[g + 2] = r * (l ? -1 : 1) * w, A[g + 3] = n * (p ? -1 : 1) * b, A[g + 4] = a, x && (A[g + 4] += Math.PI / 2), A[g + 5] = o, A[g + 6] = h, A[g + 7] = c, A[g + 8] = u, I[g + 9] = f, A[g + 10] = v, A[g + 11] = R, T.usedElemNum += K, T.makeDirty(), this.instanceCount++;
2632
2643
  }
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) {
2644
+ drawParticles(t, e, i, r, n, a, o = 1, h = 1, c = 0, u = 0, f = 1, l = 1, p = !1, x = !1, v = !1, R = 0.5, T = 0.5) {
2634
2645
  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; ) {
2646
+ let g = 0;
2647
+ const w = t.rawWidth * o * (p ? -1 : 1), b = t.rawHeight * h * (x ? -1 : 1), A = v ? Math.PI / 2 : 0;
2648
+ for (; g < a; ) {
2638
2649
  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;
2650
+ const I = a - g, Y = q - this.instanceCount, N = Math.min(I, Y), U = this.instanceBuffer;
2651
+ let y = U.usedElemNum;
2652
+ U.resize(N * K);
2653
+ const M = U.float32, D = U.uint32;
2654
+ for (let O = 0; O < N; O++) {
2655
+ const W = g + O;
2656
+ M[y] = e[W], M[y + 1] = i[W], M[y + 2] = w, M[y + 3] = b, M[y + 4] = r[W] + A, M[y + 5] = c, M[y + 6] = u, M[y + 7] = f, M[y + 8] = l, D[y + 9] = n[W], M[y + 10] = R, M[y + 11] = T, y += K;
2646
2657
  }
2647
- N.usedElemNum = A, N.makeDirty(), this.instanceCount += O, v += O, this.instanceCount >= K && this.flush();
2658
+ U.usedElemNum = y, U.makeDirty(), this.instanceCount += N, g += N, this.instanceCount >= q && this.flush();
2648
2659
  }
2649
2660
  }
2650
2661
  render() {
@@ -3456,17 +3467,17 @@ class Mt {
3456
3467
  }
3457
3468
  }
3458
3469
  export {
3459
- I as ArrayType,
3460
- B as BaseTexture,
3470
+ L as ArrayType,
3471
+ G as BaseTexture,
3461
3472
  ae as BlendMode,
3462
3473
  he as CanvasScaleMode,
3463
3474
  m as Color,
3464
3475
  ut as CustomGlShader,
3465
- D as DynamicArrayBuffer,
3476
+ k as DynamicArrayBuffer,
3466
3477
  yt as GLShader,
3467
3478
  Vt as GraphicRegion,
3468
3479
  Xt as LineTextureMode,
3469
- K as MAX_INSTANCES,
3480
+ q as MAX_INSTANCES,
3470
3481
  ne as MaskType,
3471
3482
  bt as MatrixStack,
3472
3483
  St as MatrixStore,
@@ -3482,7 +3493,7 @@ export {
3482
3493
  P as Texture,
3483
3494
  nt as TextureFilterMode,
3484
3495
  At as TextureManager,
3485
- z as TextureWrapMode,
3496
+ $ as TextureWrapMode,
3486
3497
  d as Vec2,
3487
3498
  et as WebglBufferArray,
3488
3499
  Yt as composeProjectionWithAffine,
@@ -1,5 +1,5 @@
1
- (function(x,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(x=typeof globalThis<"u"?globalThis:x||self,N(x.RapidRender={}))})(this,(function(x){"use strict";var N=(s=>(s[s.Float32=0]="Float32",s[s.Uint32=1]="Uint32",s[s.Uint16=2]="Uint16",s))(N||{});class F{usedElemNum;typedArray;arrayType;maxElemNum;bytePerElem;arraybuffer;uint32;float32;uint16;constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case 0:return Float32Array;case 1:return Uint32Array;case 2:return Uint16Array;default:throw new Error("Unsupported ArrayType")}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case 0:this.typedArray=this.float32;break;case 1:this.typedArray=this.uint32;break;case 2:this.typedArray=this.uint16;break}}clear(){this.usedElemNum=0}resize(t=0){if(t+=this.usedElemNum,t>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum*=2;return this.setMaxSize(this.maxElemNum),!0}return!1}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.resize(1),this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.resize(1),this.float32[this.usedElemNum++]=t}push(t){this.resize(1),this.typedArray[this.usedElemNum++]=t}pop(){return this.typedArray[--this.usedElemNum]}top(){return this.typedArray[this.usedElemNum-1]}get(t){return this.typedArray[t]}getArray(t=0,e){return e===void 0?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.usedElemNum}reset(){this.usedElemNum=0}}class K extends F{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,i=t.ARRAY_BUFFER,r=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=i,this.usage=r}makeDirty(){this.dirty=!0}clear(){super.clear(),this.dirty=!1}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize&&(t.bufferData(this.type,this.maxElemNum*this.bytePerElem,this.usage),this.webglBufferSize=this.maxElemNum),t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class m{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,i,r=255){this._r=t,this._g=e,this._b=i,this._a=r,this.updateUint()}setClearColor(t){t.clearColor(this.r/255,this.g/255,this.b/255,this.a/255)}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0;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);this.premultipliedUint32=(t<<24|r<<16|i<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,i,r){this.r=t,this.g=e,this.b=i,this.a=r,this.updateUint()}setHSL(t,e,i){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,i=Math.max(0,Math.min(100,i))/100;const r=(1-Math.abs(2*i-1))*e,n=r*(1-Math.abs(t/60%2-1)),a=i-r/2;let o=0,h=0,c=0;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}toHex(){const t=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${t(this._r)}${t(this._g)}${t(this._b)}${t(this._a)}`}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new m(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),i=this.g.toString(16).padStart(2,"0"),r=this.b.toString(16).padStart(2,"0"),n=this.a.toString(16).padStart(2,"0");return`#${e}${i}${r}${t?n:""}`}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}equals(t){return this.equal(t)}static FromHSL(t,e,i){return new m(0,0,0).setHSL(t,e,i)}static FromRGB(t,e,i){return new m(t,e,i)}static fromNorm(t,e,i,r=1){return new m(Math.round(t*255),Math.round(e*255),Math.round(i*255),Math.round(r*255))}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);let n=255;return t.length>=8&&(n=parseInt(t.slice(6,8),16)),new m(e,i,r,n)}add(t){return new m(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new m(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof m?new m(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new m(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof m?new m(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new m(this.r*t,this.g*t,this.b*t,this.a*t)}clamp(){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))}static Red=new m(255,0,0,255);static Green=new m(0,255,0,255);static Blue=new m(0,0,255,255);static Yellow=new m(255,255,0,255);static Purple=new m(128,0,128,255);static Orange=new m(255,165,0,255);static Pink=new m(255,192,203,255);static Gray=new m(128,128,128,255);static Brown=new m(139,69,19,255);static Cyan=new m(0,255,255,255);static Magenta=new m(255,0,255,255);static Lime=new m(192,255,0,255);static White=new m(255,255,255,255);static Black=new m(0,0,0,255);static Transparent=new m(0,0,0,0);static TRANSPARENT=new m(0,0,0,0)}const R=6;class mt{matrixCount=0;buffer;data;constructor(t=10){this.buffer=new F(N.Float32),this.buffer.resize(t*R),this.data=this.buffer.getArray()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(R)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=R,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0}identity(t){const e=t*R,i=this.data;i[e]=1,i[e+1]=0,i[e+2]=0,i[e+3]=1,i[e+4]=0,i[e+5]=0}translate(t,e,i){const r=t*R,n=this.data;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]}scale(t,e,i){const r=t*R,n=this.data;n[r]*=e,n[r+1]*=e,n[r+2]*=i,n[r+3]*=i}rotate(t,e){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];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}rotateWithOffset(t,e,i,r){this.translate(t,i,r),this.rotate(t,e),this.translate(t,-i,-r)}copy(t,e){const i=t*R,r=e*R,n=this.data;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]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,i){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],g=o[n+5],p=o[a],v=o[a+1],T=o[a+2],E=o[a+3],S=o[a+4],y=o[a+5];o[r]=h*p+u*v,o[r+1]=c*p+f*v,o[r+2]=h*T+u*E,o[r+3]=c*T+f*E,o[r+4]=h*S+u*y+l,o[r+5]=c*S+f*y+g}invert(t){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];let u=r*o-n*a;if(!u){this.identity(t);return}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}transformPoint(t,e,i){const r=t*R,n=this.data;return{x:e*n[r]+i*n[r+2]+n[r+4],y:e*n[r+1]+i*n[r+3]+n[r+5]}}worldToLocal(t,e,i){const r=this.allocDirty();this.copy(r,t),this.invert(r);const n=this.transformPoint(r,e,i);return this.matrixCount--,this.buffer.usedElemNum-=R,n}localToWorld(t,e,i){return this.transformPoint(t,e,i)}getPosition(t){const e=t*R,i=this.data;return{x:i[e+4],y:i[e+5]}}getScale(t){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]);return{x:r,y:n}}getRotation(t){const e=t*R,i=this.data;return Math.atan2(i[e+1],i[e])}toCSSMatrix(t,e=1,i=1){const r=t*R,n=this.data;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})`}getMatrix(t){const e=t*R;return this.data.slice(e,e+R)}getMatrixRef(t){const e=t*R;return this.data.subarray(e,e+R)}setMatrix(t,e){const i=t*R,r=this.data;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]}multiplyAffineInPlace(t,e,i,r,n,a,o){const h=t*6,c=this.data,u=c[h],f=c[h+1],l=c[h+2],g=c[h+3],p=c[h+4],v=c[h+5];c[h]=u*e+l*i,c[h+1]=f*e+g*i,c[h+2]=u*r+l*n,c[h+3]=f*r+g*n,c[h+4]=u*a+l*o+p,c[h+5]=f*a+g*o+v}}class xt{matrix=new mt;step=0;stack=new F(N.Uint32);stepWorldM=new F(N.Uint32);stepAction=new F(N.Uint32);stepParentM=new F(N.Uint32);parentStack=new F(N.Uint32);curLocalM=-1;curWorldM=-1;rapid;constructor(t){this.reset(),this.rapid=t}save(){this.stack.push(this.curWorldM);const t=this.curWorldM;return this.step++,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.matrix.copy(this.curWorldM,t),this.stepAction.push(1),{world:this.curWorldM,local:this.curLocalM,step:this.step}}restore(){this.stack.length!=0&&(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepAction.push(0))}updateMatrix(t){const e=(typeof t=="number"?t:t.step)-1,i=this.stepParentM.get(e);let r=0,n=e;const a=this.parentStack;for(a.reset(),a.push(i);n<this.stepAction.length;){if(this.stepAction.get(n)===1){const h=this.stepWorldM.get(n),c=h-1,u=a.top();this.matrix.multiplyOut(h,u,c),a.push(h),r++}else if(a.pop(),r--,r===0)break;n++}}translate(t,e){this.matrix.translate(this.curLocalM,t,e),this.matrix.translate(this.curWorldM,t,e)}scale(t,e=t){this.matrix.scale(this.curLocalM,t,e),this.matrix.scale(this.curWorldM,t,e)}rotate(t){this.matrix.rotate(this.curLocalM,t),this.matrix.rotate(this.curWorldM,t)}rotateWithOffset(t,e,i){this.matrix.rotateWithOffset(this.curLocalM,t,e,i),this.matrix.rotateWithOffset(this.curWorldM,t,e,i)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.reset(),this.stepAction.reset(),this.stepWorldM.reset(),this.stepParentM.reset(),this.step=0,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.alloc()}localToWorld(t,e){return this.matrix.localToWorld(this.curWorldM,t,e)}worldToLocal(t,e){return this.matrix.worldToLocal(this.curWorldM,t,e)}getGlobalPosition(){return this.matrix.getPosition(this.curWorldM)}getGlobalScale(){return this.matrix.getScale(this.curWorldM)}getGlobalRotation(){return this.matrix.getRotation(this.curWorldM)}toCSSMatrix(){return this.matrix.toCSSMatrix(this.curWorldM)}getTransform(){const t=this.curWorldM*R;return this.matrix.data.slice(t,t+R)}setTransform(t){const e=this.curWorldM*R,i=this.matrix.data;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]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,i=0){(t.saveTransform??!0)&&this.save();let r=t.x??0,n=t.y??0;t.position&&(r+=t.position.x,n+=t.position.y);let a=1,o=1;const h=t.scale;h&&(typeof h=="number"?(a=h,o=h):(a=h.x,o=h.y));const c=t.rotation??0;let u=t.offsetX??0,f=t.offsetY??0;t.offset&&(u+=t.offset.x,f+=t.offset.y);const l=t.origin;l!==void 0&&(typeof l=="number"?(u-=l*e,f-=l*i):(u-=l.x*e,f-=l.y*i));const g=c?Math.cos(c):1,p=c?Math.sin(c):0,v=g*a,T=p*a,E=-p*o,S=g*o,y=r+v*u+E*f,b=n+T*u+S*f;(t.afterSave!==void 0||t.saveTransform===!1)&&this.matrix.multiplyAffineInPlace(this.curLocalM,v,T,E,S,y,b),this.matrix.multiplyAffineInPlace(this.curWorldM,v,T,E,S,y,b),t.afterSave?.()}}var G=(s=>(s[s.REPEAT=0]="REPEAT",s[s.CLAMP=1]="CLAMP",s[s.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",s))(G||{});class pt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let i=this.cache.get(t);if(i)return new L(i);try{const r=await this._fetchImage(t);return i=D.fromSource(this.render,r,e),i.uid=t,this.cache.set(t,i),new L(i)}catch(r){throw console.error(`[TextureManager] Failed to load: ${t}`,r),r}}create(t,e){if(e?.key&&this.cache.has(e.key))return new L(this.cache.get(e.key));const i=D.fromSource(this.render,t,e);return e?.key&&(i.uid=e.key,this.cache.set(e.key,i)),new L(i)}createRenderTexture(t){return new gt(this.render,t)}createTextTexture(t){return new vt(this.render,t)}destroy(t,e=!1){let i,r;typeof t=="string"?(r=t,i=this.cache.get(r)):t instanceof L?(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))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,i)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>e(r),r.onerror=()=>i(new Error(`Failed to load image resource: ${t}`)),r.src=t})}}class D{glTexture=null;width;height;uid;refCount=0;constructor(t,e,i){this.glTexture=t,this.width=e,this.height=i}static fromSource(t,e,i={}){const r=q(t,e,i);return new D(r,e.width,e.height)}updateSource(t,e,i={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),i.textureFilter!==void 0&&st(t,i.textureFilter),i.wrap!==void 0&&rt(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))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),st(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),rt(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class L{base;uvX=0;uvY=0;uvW=1;uvH=1;rawWidth=0;rawHeight=0;offsetX=0;offsetY=0;scale=1;isAtlas=!1;flipY=!1;isRotated=!1;glTexture=null;get width(){return(this.isRotated?this.rawHeight:this.rawWidth)*this.scale}get height(){return(this.isRotated?this.rawWidth:this.rawHeight)*this.scale}_px=0;_py=0;_pw=0;_ph=0;constructor(t){t&&this.setBase(t)}setBase(t){return this.base===t?this:(this.base&&this.base.refCount--,this.base=t,this.base.refCount++,this.setRegion(0,0,t.width,t.height),this.glTexture=t.glTexture,this)}setRegion(t,e,i,r){return this.base?(this._px=t,this._py=e,this._pw=i,this._ph=r,this.isAtlas=t!==0||e!==0||i!==this.base.width||r!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+i/this.base.width,this.uvH=this.uvY+r/this.base.height,this.rawWidth=i,this.rawHeight=r,this):this}getSubTexture(t,e,i,r){if(!this.base)return new L;const n=this.clone(),a=this._px,o=this._py;return n.setRegion(a+t,o+e,i,r),n}clone(t){const e=t??new L(this.base);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}splitGrid(t,e,i,r,n=0){if(!this.base)return[];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),g=r??Math.floor((h+c)/f);for(let p=0;p<g;p++)for(let v=0;v<l;v++)a.push(this.getSubTexture(v*u,p*f,t,e));return a}static fromImageSource(t,e,i={}){const r=q(t,e,i);return new L(new D(r,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class gt extends L{framebuffer;renderbuffer;gl;flipY=!0;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??m.Black;const i=Math.max(Math.round(e.width),1),r=Math.max(Math.round(e.height),1),a=q(t,{width:i,height:r},{...e,onlySize:!0});if(this.setBase(new D(a,i,r)),this.framebuffer=this.gl.createFramebuffer(),this.renderbuffer=this.gl.createRenderbuffer(),!this.framebuffer||!this.renderbuffer)throw new Error("Failed to create Framebuffer or Renderbuffer");this.resize(i,r,!0)}resize(t,e,i=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const r=this.rawWidth===t&&this.rawHeight===e;if(!i&&r)return;const n=this.gl;(i||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,n.bindTexture(n.TEXTURE_2D,this.base.glTexture),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,this._allocW,this._allocH,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindRenderbuffer(n.RENDERBUFFER,this.renderbuffer),n.renderbufferStorage(n.RENDERBUFFER,n.STENCIL_INDEX8,this._allocW,this._allocH),n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,this.base.glTexture,0),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.STENCIL_ATTACHMENT,n.RENDERBUFFER,this.renderbuffer),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindTexture(n.TEXTURE_2D,null)),this.rawWidth=t,this.rawHeight=e,this.uvX=0,this.uvW=t/this._allocW,this.uvY=0,this.uvH=e/this._allocH}activate(t=!1){if(!this.framebuffer)return;const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.viewport(0,0,this.rawWidth,this.rawHeight),t&&this.clear()}clear(t){if(!this.framebuffer)return;const e=this.gl,i=t??this.clearColor;i&&(i.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT|e.STENCIL_BUFFER_BIT))}deactivate(){const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,null)}GetPixels(t=0,e=0,i=this.rawWidth,r=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const n=Math.floor(t),a=Math.floor(e),o=Math.floor(i),h=Math.floor(r);if(o<=0||h<=0)return new Uint8Array(0);if(n<0||a<0||n>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(o,this.rawWidth-n),u=Math.min(h,this.rawHeight-a),f=this.rawHeight-a-u,l=this.gl,g=l.getParameter(l.FRAMEBUFFER_BINDING);l.bindFramebuffer(l.FRAMEBUFFER,this.framebuffer);const p=new Uint8Array(c*u*4);return l.readPixels(n,f,c,u,l.RGBA,l.UNSIGNED_BYTE,p),l.bindFramebuffer(l.FRAMEBUFFER,g),p}GetColorAt(t,e){const i=this.GetPixels(t,e,1,1);return i.length<4?new m(0,0,0,0):new m(i[0],i[1],i[2],i[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const $t={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:1,align:"left",baseline:"top"};class vt extends L{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){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");const i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Failed to get 2d context for TextTexture");this.ctx=i,this.canvas.width=1,this.canvas.height=1;const r=q(t,this.canvas,this.options);this.setBase(new D(r,1,1)),this.update()}get text(){return this._text}set text(t){this._text!==t&&(this._text=t,this.update())}get style(){return this._style}set style(t){this._style={...this._style,...t},this.update()}updateOffset(t,e){switch(this._style.align){case"center":this.offsetX=-t/2;break;case"right":this.offsetX=-t;break;default:this.offsetX=0;break}switch(this._style.baseline){case"middle":this.offsetY=-e/2;break;case"bottom":this.offsetY=-e;break;default:this.offsetY=0;break}}update(){const t=this.ctx,e=this._style.fontSize,i=this._style.fontWeight,r=this._style.fontFamily,n=`${i} ${e}px ${r}`,a=this.render.dpr;t.font=n;const o=this._text.split(`
2
- `);let h=0,c=0;t.textBaseline="alphabetic";const u=t.measureText(o[0]),f=u.fontBoundingBoxAscent,l=u.fontBoundingBoxDescent;for(const y of o){const b=t.measureText(y);b.width>h&&(h=b.width),c+=f+l}c-=l;const g=(this._style.strokeThickness||0)*2,p=Math.ceil(h+g)||1,v=Math.ceil(c+g)||1,T=p*a,E=v*a;(this.canvas.width!==T||this.canvas.height!==E)&&(this.canvas.width=T,this.canvas.height=E),t.setTransform(a,0,0,a,0,0),t.clearRect(0,0,p,v),t.font=n,t.textBaseline="top",t.textAlign="left",this.updateOffset(p,v);let S=g/2;for(const y of o){let b=g/2;this._style.stroke&&this._style.strokeThickness>0&&(t.lineWidth=this._style.strokeThickness,t.strokeStyle=this._style.stroke,t.strokeText(y,b,S)),this._style.fill&&(t.fillStyle=this._style.fill,t.fillText(y,b,S)),S+=f+l}this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,this.canvas.width,this.canvas.height)}}const Kt=(s,t=!1,e=!0)=>{const i=s.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!i)throw new Error("WebGL2 is not supported in this browser.");return i},Tt=(s,t,e)=>{const i=s.createShader(e);if(!i)throw new Error("Unable to create webgl shader");if(s.shaderSource(i,t),s.compileShader(i),!s.getShaderParameter(i,s.COMPILE_STATUS)){const n=s.getShaderInfoLog(i);throw console.error("Shader compilation failed:",n),new Error("Unable to compile shader: "+n+t)}return i},qt=(s,t,e)=>{var i=s.createProgram(),r=Tt(s,t,35633),n=Tt(s,e,35632);if(!i)throw new Error("Unable to create program shader");if(s.attachShader(i,r),s.attachShader(i,n),s.linkProgram(i),!s.getProgramParameter(i,s.LINK_STATUS)){const o=s.getProgramInfoLog(i);throw new Error("Unable to link shader program: "+o)}return i};function rt(s,t){const e={[G.CLAMP]:s.CLAMP_TO_EDGE,[G.REPEAT]:s.REPEAT,[G.MIRRORED_REPEAT]:s.MIRRORED_REPEAT}[t]||s.CLAMP_TO_EDGE;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,e),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,e)}function st(s,t){const e={[et.LINEAR]:s.LINEAR,[et.NEAREST]:s.NEAREST}[t]??s.NEAREST;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,e),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,e)}function q(s,t,e){const i=s.gl,r=i.createTexture();if(!r)throw new Error("Unable to create WebGL texture");if(i.bindTexture(i.TEXTURE_2D,r),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,0),i.pixelStorei(i.UNPACK_ALIGNMENT,1),rt(i,e.wrap??G.CLAMP),st(i,e.textureFilter??s.textureFilter),e.onlySize){const n=t;i.texImage2D(i.TEXTURE_2D,0,i.RGBA,n.width,n.height,0,i.RGBA,i.UNSIGNED_BYTE,null)}else{const n=e.premultipliedAlpha??s.premultipliedAlpha;n&&i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),n&&i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return i.bindTexture(i.TEXTURE_2D,null),r}function B(s,t){if(s.includes("%TEXTURE_NUM%")&&(s=s.replace("%TEXTURE_NUM%",t.toString())),s.includes("%GET_COLOR%")){let e="";for(let i=0;i<t;i++)i==0?e+=`if(vTextureId == ${i})`:i==t-1?e+="else":e+=`else if(vTextureId == ${i})`,e+=`{return texture(uTextures[${i}], uv) * vColor;}`;s=s.replace("%GET_COLOR%",e)}return s}const Zt=5126,nt=5121;function Qt(s,t,e){s.vertexAttribDivisor(t,e)}function yt(s,t,e,i,r){s.drawArraysInstanced(t,e,i,r)}let Jt=0;class at{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=Jt++;vao;constructor(t,e,i,r){this.gl=t,this.program=qt(t,e,i),this.parseShader(e),this.parseShader(i),this.vao=t.createVertexArray(),r&&this.setAttributes(r)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const i=this.uniformLoc[t];if(i===void 0)return;const r=this.uniformType[t],n=this.uniformIsArray[t];te(this.gl,i,r,e,n)}setUniforms(t){for(const e in t)this.setUniform(e,t[e])}setAttribute(t){const e=this.attributeLoc[t.name];if(e===void 0)return;const i=this.gl;i.vertexAttribPointer(e,t.size,t.type??Zt,t.normalized??!1,t.stride,t.offset??0),i.enableVertexAttribArray(e),Qt(i,e,t.divisor??0)}setAttributes(t){for(const e of t)this.setAttribute(e)}destroy(){this.gl.deleteProgram(this.program)}parseShader(t){const e=this.gl,i=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(i)for(const n of i){const o=n.split(/\s+/)[2],h=e.getAttribLocation(this.program,o);h!==-1&&(this.attributeLoc[o]=h)}const r=t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);if(r)for(const n of r){const a=n.split(/\s+/),o=a[1],h=a[2].replace(/\[\d+\]$/,""),c=e.getUniformLocation(this.program,h);c!==null&&(this.uniformLoc[h]=c,this.uniformType[h]=o,this.uniformIsArray[h]=/\[\d+\]$/.test(a[2]))}}}function te(s,t,e,i,r=!1){switch(e){case"float":return s.uniform1f(t,i);case"int":case"bool":case"sampler2D":case"samplerCube":return r?s.uniform1iv(t,i):s.uniform1i(t,i);case"vec2":return s.uniform2fv(t,i);case"vec3":return s.uniform3fv(t,i);case"vec4":return s.uniform4fv(t,i);case"ivec2":case"bvec2":return s.uniform2iv(t,i);case"ivec3":case"bvec3":return s.uniform3iv(t,i);case"ivec4":case"bvec4":return s.uniform4iv(t,i);case"mat2":return s.uniformMatrix2fv(t,!1,i);case"mat3":return s.uniformMatrix3fv(t,!1,i);case"mat4":return s.uniformMatrix4fv(t,!1,i);default:return ee(s,t,i)}}function ee(s,t,e){if(typeof e=="number")return s.uniform1f(t,e);const i=e;switch(i.length){case 2:return s.uniform2fv(t,i);case 3:return s.uniform3fv(t,i);case 4:return s.uniform4fv(t,i);case 9:return s.uniformMatrix3fv(t,!1,i);case 16:return s.uniformMatrix4fv(t,!1,i);default:return s.uniform1fv(t,i)}}class ht{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};usedTextureUnitNum=0;padding=0;rapid;constructor(t,e,i,r=0,n){this.vs=e,this.fs=i,this.rapid=t,this.uniforms=n??{},this.usedTextureUnitNum=r}setUniforms(t){this.rapid.flush();const e={},i={};for(const[r,n]of Object.entries(t))n instanceof WebGLTexture?i[r]=n:e[r]=n;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,i);for(const r of this.glshader.keys())this.uniformDirty.add(r)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const i=this.glshader.get(t);i&&(Object.keys(e).length>0&&i.setUniforms(e),this.uniformDirty.has(t)&&(i.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}getGLShader(t,e,i,r){if(this.glshader.has(e))return this.glshader.get(e);if(r==null||i==null)return console.warn("CustomGlShader: missing base shader for "+e),null;i=i.replace("// CUSTOM_CODE_CALL","vertex(position, vRegion);"),r=r.replace("// CUSTOM_CODE_CALL","fragment(fragColor);"),i=i.replace("// CUSTOM_CODE",this.vs),r=r.replace("// CUSTOM_CODE",this.fs);const n=t.createShader(i,r);return n.isCustom=!0,n.padding=this.padding,this.glshader.set(e,n),this.uniformDirty.add(e),n}}const z=1/0;class ot{constructor(t){this.rapid=t,this.gl=t.gl,this.maxTextureUnits=t.maxTextureUnits,this.matrixStore=t.matrix}defaultShader;currentShader;customShader=null;customShaderUsedTextureNum=0;gl;maxTextureUnits;matrixStore;isDefaultShader=!0;KEY="default";vs="";fs="";usedTextures=[];usedTexturePadding=[];createBuffer(){}createDefaultShader(){}get freeTextureUnitNum(){return this.maxTextureUnits-this.usedTextures.length-this.customShaderUsedTextureNum}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},(t,e)=>e)}findTextureUnit(t,e=0,i=0){for(let r=0;r<this.usedTextures.length;r++){const n=r*2;if(this.usedTextures[r]===t&&this.usedTexturePadding[n]===e&&this.usedTexturePadding[n+1]===i)return r}return-1}useTexture(t,e=0,i=0){const r=this.findTextureUnit(t,e,i);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}createShader(t,e){return new at(this.gl,t,e)}createCustomShader(t){return t.getGLShader(this,this.KEY,this.vs,this.fs)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof ht){const e=this.createCustomShader(t);return e??this.defaultShader}return t}isSameShader(t){return this.isDefaultShader&&!t?!0:this.getCustomShader(t)==this.currentShader}enter(t){this.resetRender(),this.currentShader=this.getCustomShader(t),t instanceof ht?(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)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){const t=this.currentShader;if(t.use(),this.customShader){const i=this.customShader,r={};for(const n in i.uniformTextures)r[n]=this.useTexture(i.uniformTextures[n]);this.customShader.applyUniform(this.KEY,r)}const e=this.gl;for(let i=0;i<this.usedTextures.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,this.usedTextures[i]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(i,r)=>r)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(i,r)=>this.usedTexturePadding[r]))}resetRender(){this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}const Z=`#version 300 es\r
1
+ (function(x,N){typeof exports=="object"&&typeof module<"u"?N(exports):typeof define=="function"&&define.amd?define(["exports"],N):(x=typeof globalThis<"u"?globalThis:x||self,N(x.RapidRender={}))})(this,(function(x){"use strict";var N=(s=>(s[s.Float32=0]="Float32",s[s.Uint32=1]="Uint32",s[s.Uint16=2]="Uint16",s))(N||{});class O{usedElemNum;typedArray;arrayType;maxElemNum;bytePerElem;arraybuffer;uint32;float32;uint16;constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case 0:return Float32Array;case 1:return Uint32Array;case 2:return Uint16Array;default:throw new Error("Unsupported ArrayType")}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case 0:this.typedArray=this.float32;break;case 1:this.typedArray=this.uint32;break;case 2:this.typedArray=this.uint16;break}}clear(){this.usedElemNum=0}resize(t=0){if(t+=this.usedElemNum,t>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum*=2;return this.setMaxSize(this.maxElemNum),!0}return!1}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.resize(1),this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.resize(1),this.float32[this.usedElemNum++]=t}push(t){this.resize(1),this.typedArray[this.usedElemNum++]=t}pop(){return this.typedArray[--this.usedElemNum]}top(){return this.typedArray[this.usedElemNum-1]}get(t){return this.typedArray[t]}getArray(t=0,e){return e===void 0?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.usedElemNum}reset(){this.usedElemNum=0}}class Z extends O{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,i=t.ARRAY_BUFFER,r=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=i,this.usage=r}makeDirty(){this.dirty=!0}clear(){super.clear(),this.dirty=!1}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize&&(t.bufferData(this.type,this.maxElemNum*this.bytePerElem,this.usage),this.webglBufferSize=this.maxElemNum),t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class m{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,i,r=255){this._r=t,this._g=e,this._b=i,this._a=r,this.updateUint()}setClearColor(t){t.clearColor(this.r/255,this.g/255,this.b/255,this.a/255)}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0;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);this.premultipliedUint32=(t<<24|r<<16|i<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,i,r){this.r=t,this.g=e,this.b=i,this.a=r,this.updateUint()}setHSL(t,e,i){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,i=Math.max(0,Math.min(100,i))/100;const r=(1-Math.abs(2*i-1))*e,n=r*(1-Math.abs(t/60%2-1)),a=i-r/2;let o=0,h=0,c=0;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}toHex(){const t=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${t(this._r)}${t(this._g)}${t(this._b)}${t(this._a)}`}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new m(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),i=this.g.toString(16).padStart(2,"0"),r=this.b.toString(16).padStart(2,"0"),n=this.a.toString(16).padStart(2,"0");return`#${e}${i}${r}${t?n:""}`}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}equals(t){return this.equal(t)}static FromHSL(t,e,i){return new m(0,0,0).setHSL(t,e,i)}static FromRGB(t,e,i){return new m(t,e,i)}static fromNorm(t,e,i,r=1){return new m(Math.round(t*255),Math.round(e*255),Math.round(i*255),Math.round(r*255))}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),i=parseInt(t.slice(2,4),16),r=parseInt(t.slice(4,6),16);let n=255;return t.length>=8&&(n=parseInt(t.slice(6,8),16)),new m(e,i,r,n)}add(t){return new m(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new m(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof m?new m(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new m(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof m?new m(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new m(this.r*t,this.g*t,this.b*t,this.a*t)}clamp(){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))}static Red=new m(255,0,0,255);static Green=new m(0,255,0,255);static Blue=new m(0,0,255,255);static Yellow=new m(255,255,0,255);static Purple=new m(128,0,128,255);static Orange=new m(255,165,0,255);static Pink=new m(255,192,203,255);static Gray=new m(128,128,128,255);static Brown=new m(139,69,19,255);static Cyan=new m(0,255,255,255);static Magenta=new m(255,0,255,255);static Lime=new m(192,255,0,255);static White=new m(255,255,255,255);static Black=new m(0,0,0,255);static Transparent=new m(0,0,0,0);static TRANSPARENT=new m(0,0,0,0)}const w=6;class mt{matrixCount=0;buffer;data;constructor(t=10){this.buffer=new O(N.Float32),this.buffer.resize(t*w),this.data=this.buffer.getArray()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(w)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=w,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0}identity(t){const e=t*w,i=this.data;i[e]=1,i[e+1]=0,i[e+2]=0,i[e+3]=1,i[e+4]=0,i[e+5]=0}translate(t,e,i){const r=t*w,n=this.data;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]}scale(t,e,i){const r=t*w,n=this.data;n[r]*=e,n[r+1]*=e,n[r+2]*=i,n[r+3]*=i}rotate(t,e){const i=t*w,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];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}rotateWithOffset(t,e,i,r){this.translate(t,i,r),this.rotate(t,e),this.translate(t,-i,-r)}copy(t,e){const i=t*w,r=e*w,n=this.data;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]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,i){const r=t*w,n=e*w,a=i*w,o=this.data,h=o[n],c=o[n+1],u=o[n+2],f=o[n+3],l=o[n+4],g=o[n+5],p=o[a],T=o[a+1],E=o[a+2],y=o[a+3],v=o[a+4],S=o[a+5];o[r]=h*p+u*T,o[r+1]=c*p+f*T,o[r+2]=h*E+u*y,o[r+3]=c*E+f*y,o[r+4]=h*v+u*S+l,o[r+5]=c*v+f*S+g}invert(t){const e=t*w,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];let u=r*o-n*a;if(!u){this.identity(t);return}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}transformPoint(t,e,i){const r=t*w,n=this.data;return{x:e*n[r]+i*n[r+2]+n[r+4],y:e*n[r+1]+i*n[r+3]+n[r+5]}}worldToLocal(t,e,i){const r=this.allocDirty();this.copy(r,t),this.invert(r);const n=this.transformPoint(r,e,i);return this.matrixCount--,this.buffer.usedElemNum-=w,n}localToWorld(t,e,i){return this.transformPoint(t,e,i)}getPosition(t){const e=t*w,i=this.data;return{x:i[e+4],y:i[e+5]}}getScale(t){const e=t*w,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]);return{x:r,y:n}}getRotation(t){const e=t*w,i=this.data;return Math.atan2(i[e+1],i[e])}toCSSMatrix(t,e=1,i=1){const r=t*w,n=this.data;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})`}getMatrix(t){const e=t*w;return this.data.slice(e,e+w)}getMatrixRef(t){const e=t*w;return this.data.subarray(e,e+w)}setMatrix(t,e){const i=t*w,r=this.data;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]}multiplyAffineInPlace(t,e,i,r,n,a,o){const h=t*6,c=this.data,u=c[h],f=c[h+1],l=c[h+2],g=c[h+3],p=c[h+4],T=c[h+5];c[h]=u*e+l*i,c[h+1]=f*e+g*i,c[h+2]=u*r+l*n,c[h+3]=f*r+g*n,c[h+4]=u*a+l*o+p,c[h+5]=f*a+g*o+T}}class xt{matrix=new mt;step=0;stack=new O(N.Uint32);stepWorldM=new O(N.Uint32);stepAction=new O(N.Uint32);stepParentM=new O(N.Uint32);parentStack=new O(N.Uint32);curLocalM=-1;curWorldM=-1;rapid;constructor(t){this.reset(),this.rapid=t}save(){this.stack.push(this.curWorldM);const t=this.curWorldM;return this.step++,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.matrix.copy(this.curWorldM,t),this.stepAction.push(1),{world:this.curWorldM,local:this.curLocalM,step:this.step}}restore(){this.stack.length!=0&&(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepAction.push(0))}updateMatrix(t){const e=(typeof t=="number"?t:t.step)-1,i=this.stepParentM.get(e);let r=0,n=e;const a=this.parentStack;for(a.reset(),a.push(i);n<this.stepAction.length;){if(this.stepAction.get(n)===1){const h=this.stepWorldM.get(n),c=h-1,u=a.top();this.matrix.multiplyOut(h,u,c),a.push(h),r++}else if(a.pop(),r--,r===0)break;n++}}translate(t,e){this.matrix.translate(this.curLocalM,t,e),this.matrix.translate(this.curWorldM,t,e)}scale(t,e=t){this.matrix.scale(this.curLocalM,t,e),this.matrix.scale(this.curWorldM,t,e)}rotate(t){this.matrix.rotate(this.curLocalM,t),this.matrix.rotate(this.curWorldM,t)}rotateWithOffset(t,e,i){this.matrix.rotateWithOffset(this.curLocalM,t,e,i),this.matrix.rotateWithOffset(this.curWorldM,t,e,i)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.reset(),this.stepAction.reset(),this.stepWorldM.reset(),this.stepParentM.reset(),this.step=0,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.alloc()}localToWorld(t,e){return this.matrix.localToWorld(this.curWorldM,t,e)}worldToLocal(t,e){return this.matrix.worldToLocal(this.curWorldM,t,e)}getGlobalPosition(){return this.matrix.getPosition(this.curWorldM)}getGlobalScale(){return this.matrix.getScale(this.curWorldM)}getGlobalRotation(){return this.matrix.getRotation(this.curWorldM)}toCSSMatrix(){return this.matrix.toCSSMatrix(this.curWorldM)}getTransform(){const t=this.curWorldM*w;return this.matrix.data.slice(t,t+w)}setTransform(t){const e=this.curWorldM*w,i=this.matrix.data;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]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,i=0){(t.saveTransform??!0)&&this.save();let r=t.x??0,n=t.y??0;t.position&&(r+=t.position.x,n+=t.position.y);let a=1,o=1;const h=t.scale;h&&(typeof h=="number"?(a=h,o=h):(a=h.x,o=h.y));const c=t.rotation??0;let u=t.offsetX??0,f=t.offsetY??0;t.offset&&(u+=t.offset.x,f+=t.offset.y);const l=t.origin;l!==void 0&&(typeof l=="number"?(u-=l*e,f-=l*i):(u-=l.x*e,f-=l.y*i));const g=c?Math.cos(c):1,p=c?Math.sin(c):0,T=g*a,E=p*a,y=-p*o,v=g*o,S=r+T*u+y*f,A=n+E*u+v*f;(t.afterSave!==void 0||t.saveTransform===!1)&&this.matrix.multiplyAffineInPlace(this.curLocalM,T,E,y,v,S,A),this.matrix.multiplyAffineInPlace(this.curWorldM,T,E,y,v,S,A),t.afterSave?.()}}var V=(s=>(s[s.REPEAT=0]="REPEAT",s[s.CLAMP=1]="CLAMP",s[s.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",s))(V||{});class pt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let i=this.cache.get(t);if(i)return new L(i);try{const r=await this._fetchImage(t);return i=W.fromSource(this.render,r,e),i.uid=t,this.cache.set(t,i),new L(i)}catch(r){throw console.error(`[TextureManager] Failed to load: ${t}`,r),r}}create(t,e){if(e?.key&&this.cache.has(e.key))return new L(this.cache.get(e.key));const i=W.fromSource(this.render,t,e);return e?.key&&(i.uid=e.key,this.cache.set(e.key,i)),new L(i)}createRenderTexture(t){return new gt(this.render,t)}createTextTexture(t){return new vt(this.render,t)}destroy(t,e=!1){let i,r;typeof t=="string"?(r=t,i=this.cache.get(r)):t instanceof L?(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))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,i)=>{const r=new Image;r.crossOrigin="anonymous",r.onload=()=>e(r),r.onerror=()=>i(new Error(`Failed to load image resource: ${t}`)),r.src=t})}}class W{glTexture=null;width;height;uid;refCount=0;constructor(t,e,i){this.glTexture=t,this.width=e,this.height=i}static fromSource(t,e,i={}){const r=Q(t,e,i);return new W(r,e.width,e.height)}updateSource(t,e,i={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),i.textureFilter!==void 0&&nt(t,i.textureFilter),i.wrap!==void 0&&st(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))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),nt(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),st(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class L{base;uvX=0;uvY=0;uvW=1;uvH=1;rawWidth=0;rawHeight=0;offsetX=0;offsetY=0;scale=1;isAtlas=!1;flipY=!1;isRotated=!1;glTexture=null;get width(){return(this.isRotated?this.rawHeight:this.rawWidth)*this.scale}get height(){return(this.isRotated?this.rawWidth:this.rawHeight)*this.scale}_px=0;_py=0;_pw=0;_ph=0;constructor(t){t&&this.setBase(t)}setBase(t){return this.base===t?this:(this.base&&this.base.refCount--,this.base=t,this.base.refCount++,this.setRegion(0,0,t.width,t.height),this.glTexture=t.glTexture,this)}setRegion(t,e,i,r){return this.base?(this._px=t,this._py=e,this._pw=i,this._ph=r,this.isAtlas=t!==0||e!==0||i!==this.base.width||r!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+i/this.base.width,this.uvH=this.uvY+r/this.base.height,this.rawWidth=i,this.rawHeight=r,this):this}getSubTexture(t,e,i,r){if(!this.base)return new L;const n=this.clone(),a=this._px,o=this._py;return n.setRegion(a+t,o+e,i,r),n}clone(t){const e=t??new L(this.base);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}splitGrid(t,e,i,r,n=0){if(!this.base)return[];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),g=r??Math.floor((h+c)/f);for(let p=0;p<g;p++)for(let T=0;T<l;T++)a.push(this.getSubTexture(T*u,p*f,t,e));return a}static fromImageSource(t,e,i={}){const r=Q(t,e,i);return new L(new W(r,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class gt extends L{framebuffer;renderbuffer;gl;flipY=!0;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??m.Black;const i=Math.max(Math.round(e.width),1),r=Math.max(Math.round(e.height),1),a=Q(t,{width:i,height:r},{...e,onlySize:!0});if(this.setBase(new W(a,i,r)),this.framebuffer=this.gl.createFramebuffer(),this.renderbuffer=this.gl.createRenderbuffer(),!this.framebuffer||!this.renderbuffer)throw new Error("Failed to create Framebuffer or Renderbuffer");this.resize(i,r,!0)}resize(t,e,i=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const r=this.rawWidth===t&&this.rawHeight===e;if(!i&&r)return;const n=this.gl;(i||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,n.bindTexture(n.TEXTURE_2D,this.base.glTexture),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,this._allocW,this._allocH,0,n.RGBA,n.UNSIGNED_BYTE,null),n.bindRenderbuffer(n.RENDERBUFFER,this.renderbuffer),n.renderbufferStorage(n.RENDERBUFFER,n.STENCIL_INDEX8,this._allocW,this._allocH),n.bindFramebuffer(n.FRAMEBUFFER,this.framebuffer),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,this.base.glTexture,0),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.STENCIL_ATTACHMENT,n.RENDERBUFFER,this.renderbuffer),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindTexture(n.TEXTURE_2D,null)),this.rawWidth=t,this.rawHeight=e,this.uvX=0,this.uvW=t/this._allocW,this.uvY=0,this.uvH=e/this._allocH}activate(t=!1){if(!this.framebuffer)return;const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.viewport(0,0,this.rawWidth,this.rawHeight),t&&this.clear()}clear(t){if(!this.framebuffer)return;const e=this.gl,i=t??this.clearColor;i&&(i.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT|e.STENCIL_BUFFER_BIT))}deactivate(){const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,null)}GetPixels(t=0,e=0,i=this.rawWidth,r=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const n=Math.floor(t),a=Math.floor(e),o=Math.floor(i),h=Math.floor(r);if(o<=0||h<=0)return new Uint8Array(0);if(n<0||a<0||n>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(o,this.rawWidth-n),u=Math.min(h,this.rawHeight-a),f=this.rawHeight-a-u,l=this.gl,g=l.getParameter(l.FRAMEBUFFER_BINDING);l.bindFramebuffer(l.FRAMEBUFFER,this.framebuffer);const p=new Uint8Array(c*u*4);return l.readPixels(n,f,c,u,l.RGBA,l.UNSIGNED_BYTE,p),l.bindFramebuffer(l.FRAMEBUFFER,g),p}GetColorAt(t,e){const i=this.GetPixels(t,e,1,1);return i.length<4?new m(0,0,0,0):new m(i[0],i[1],i[2],i[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const $t={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:1,align:"left",baseline:"top"};class vt extends L{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){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");const i=this.canvas.getContext("2d",{willReadFrequently:!0});if(!i)throw new Error("Failed to get 2d context for TextTexture");this.ctx=i,this.canvas.width=1,this.canvas.height=1;const r=Q(t,this.canvas,this.options);this.setBase(new W(r,1,1)),this.update()}get text(){return this._text}set text(t){this._text!==t&&(this._text=t,this.update())}get style(){return this._style}set style(t){this._style={...this._style,...t},this.update()}updateOffset(t,e){switch(this._style.align){case"center":this.offsetX=-t/2;break;case"right":this.offsetX=-t;break;default:this.offsetX=0;break}switch(this._style.baseline){case"middle":this.offsetY=-e/2;break;case"bottom":this.offsetY=-e;break;default:this.offsetY=0;break}}update(){const t=this.ctx,e=this._style.fontSize,i=this._style.fontWeight,r=this._style.fontFamily,n=`${i} ${e}px ${r}`,a=this.render.dpr;t.font=n;const o=this._text.split(`
2
+ `);let h=0,c=0;t.textBaseline="alphabetic";const u=t.measureText(o[0]),f=u.fontBoundingBoxAscent,l=u.fontBoundingBoxDescent;for(const S of o){const A=t.measureText(S);A.width>h&&(h=A.width),c+=f+l}c-=l;const g=(this._style.strokeThickness||0)*2,p=Math.ceil(h+g)||1,T=Math.ceil(c+g)||1,E=p*a,y=T*a;(this.canvas.width!==E||this.canvas.height!==y)&&(this.canvas.width=E,this.canvas.height=y),t.setTransform(a,0,0,a,0,0),t.clearRect(0,0,p,T),t.font=n,t.textBaseline="top",t.textAlign="left",this.updateOffset(p,T);let v=g/2;for(const S of o){let A=g/2;this._style.stroke&&this._style.strokeThickness>0&&(t.lineWidth=this._style.strokeThickness,t.strokeStyle=this._style.stroke,t.strokeText(S,A,v)),this._style.fill&&(t.fillStyle=this._style.fill,t.fillText(S,A,v)),v+=f+l}this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,this.canvas.width,this.canvas.height)}}const Kt=(s,t=!1,e=!0)=>{const i=s.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!i)throw new Error("WebGL2 is not supported in this browser.");return i},Tt=(s,t,e)=>{const i=s.createShader(e);if(!i)throw new Error("Unable to create webgl shader");if(s.shaderSource(i,t),s.compileShader(i),!s.getShaderParameter(i,s.COMPILE_STATUS)){const n=s.getShaderInfoLog(i);throw console.error("Shader compilation failed:",n),new Error("Unable to compile shader: "+n+t)}return i},qt=(s,t,e)=>{var i=s.createProgram(),r=Tt(s,t,35633),n=Tt(s,e,35632);if(!i)throw new Error("Unable to create program shader");if(s.attachShader(i,r),s.attachShader(i,n),s.linkProgram(i),!s.getProgramParameter(i,s.LINK_STATUS)){const o=s.getProgramInfoLog(i);throw new Error("Unable to link shader program: "+o)}return i};function st(s,t){const e={[V.CLAMP]:s.CLAMP_TO_EDGE,[V.REPEAT]:s.REPEAT,[V.MIRRORED_REPEAT]:s.MIRRORED_REPEAT}[t]||s.CLAMP_TO_EDGE;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,e),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,e)}function nt(s,t){const e={[rt.LINEAR]:s.LINEAR,[rt.NEAREST]:s.NEAREST}[t]??s.NEAREST;s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,e),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,e)}function Q(s,t,e){const i=s.gl,r=i.createTexture();if(!r)throw new Error("Unable to create WebGL texture");if(i.bindTexture(i.TEXTURE_2D,r),i.pixelStorei(i.UNPACK_FLIP_Y_WEBGL,0),i.pixelStorei(i.UNPACK_ALIGNMENT,1),st(i,e.wrap??V.CLAMP),nt(i,e.textureFilter??s.textureFilter),e.onlySize){const n=t;i.texImage2D(i.TEXTURE_2D,0,i.RGBA,n.width,n.height,0,i.RGBA,i.UNSIGNED_BYTE,null)}else{const n=e.premultipliedAlpha??s.premultipliedAlpha;n&&i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,i.RGBA,i.UNSIGNED_BYTE,t),n&&i.pixelStorei(i.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return i.bindTexture(i.TEXTURE_2D,null),r}function F(s,t){if(s.includes("%TEXTURE_NUM%")&&(s=s.replace("%TEXTURE_NUM%",t.toString())),s.includes("%GET_COLOR%")){let e="";for(let i=0;i<t;i++)i==0?e+=`if(vTextureId == ${i})`:i==t-1?e+="else":e+=`else if(vTextureId == ${i})`,e+=`{return texture(uTextures[${i}], uv) * vColor;}`;s=s.replace("%GET_COLOR%",e)}return s}const Zt=5126,at=5121;function Qt(s,t,e){s.vertexAttribDivisor(t,e)}function yt(s,t,e,i,r){s.drawArraysInstanced(t,e,i,r)}let Jt=0;class ht{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=Jt++;vao;constructor(t,e,i,r){this.gl=t,this.program=qt(t,e,i),this.parseShader(e),this.parseShader(i),this.vao=t.createVertexArray(),r&&this.setAttributes(r)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const i=this.uniformLoc[t];if(i===void 0)return;const r=this.uniformType[t],n=this.uniformIsArray[t];te(this.gl,i,r,e,n)}setUniforms(t){for(const e in t)this.setUniform(e,t[e])}setAttribute(t){const e=this.attributeLoc[t.name];if(e===void 0)return;const i=this.gl;i.vertexAttribPointer(e,t.size,t.type??Zt,t.normalized??!1,t.stride,t.offset??0),i.enableVertexAttribArray(e),Qt(i,e,t.divisor??0)}setAttributes(t){for(const e of t)this.setAttribute(e)}destroy(){this.gl.deleteProgram(this.program)}parseShader(t){const e=this.gl,i=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(i)for(const n of i){const o=n.split(/\s+/)[2],h=e.getAttribLocation(this.program,o);h!==-1&&(this.attributeLoc[o]=h)}const r=t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);if(r)for(const n of r){const a=n.split(/\s+/),o=a[1],h=a[2].replace(/\[\d+\]$/,""),c=e.getUniformLocation(this.program,h);c!==null&&(this.uniformLoc[h]=c,this.uniformType[h]=o,this.uniformIsArray[h]=/\[\d+\]$/.test(a[2]))}}}function te(s,t,e,i,r=!1){switch(e){case"float":return s.uniform1f(t,i);case"int":case"bool":case"sampler2D":case"samplerCube":return r?s.uniform1iv(t,i):s.uniform1i(t,i);case"vec2":return s.uniform2fv(t,i);case"vec3":return s.uniform3fv(t,i);case"vec4":return s.uniform4fv(t,i);case"ivec2":case"bvec2":return s.uniform2iv(t,i);case"ivec3":case"bvec3":return s.uniform3iv(t,i);case"ivec4":case"bvec4":return s.uniform4iv(t,i);case"mat2":return s.uniformMatrix2fv(t,!1,i);case"mat3":return s.uniformMatrix3fv(t,!1,i);case"mat4":return s.uniformMatrix4fv(t,!1,i);default:return ee(s,t,i)}}function ee(s,t,e){if(typeof e=="number")return s.uniform1f(t,e);const i=e;switch(i.length){case 2:return s.uniform2fv(t,i);case 3:return s.uniform3fv(t,i);case 4:return s.uniform4fv(t,i);case 9:return s.uniformMatrix3fv(t,!1,i);case 16:return s.uniformMatrix4fv(t,!1,i);default:return s.uniform1fv(t,i)}}class ot{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};usedTextureUnitNum=0;padding=0;rapid;constructor(t,e,i,r=0,n){this.vs=e,this.fs=i,this.rapid=t,this.uniforms=n??{},this.usedTextureUnitNum=r}setUniforms(t){this.rapid.flush();const e={},i={};for(const[r,n]of Object.entries(t))n instanceof WebGLTexture?i[r]=n:e[r]=n;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,i);for(const r of this.glshader.keys())this.uniformDirty.add(r)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const i=this.glshader.get(t);i&&(Object.keys(e).length>0&&i.setUniforms(e),this.uniformDirty.has(t)&&(i.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}getGLShader(t,e,i,r){if(this.glshader.has(e))return this.glshader.get(e);if(r==null||i==null)return console.warn("CustomGlShader: missing base shader for "+e),null;i=i.replace("// CUSTOM_CODE_CALL","vertex(position, vRegion);"),r=r.replace("// CUSTOM_CODE_CALL","fragment(fragColor);"),i=i.replace("// CUSTOM_CODE",this.vs),r=r.replace("// CUSTOM_CODE",this.fs);const n=t.createShader(i,r);return n.isCustom=!0,n.padding=this.padding,this.glshader.set(e,n),this.uniformDirty.add(e),n}}const X=1/0;class ct{constructor(t){this.rapid=t,this.gl=t.gl,this.maxTextureUnits=t.maxTextureUnits,this.matrixStore=t.matrix}defaultShader;currentShader;customShader=null;customShaderUsedTextureNum=0;gl;maxTextureUnits;matrixStore;isDefaultShader=!0;KEY="default";vs="";fs="";usedTextures=[];usedTexturePadding=[];createBuffer(){}createDefaultShader(){}get freeTextureUnitNum(){return this.maxTextureUnits-this.usedTextures.length-this.customShaderUsedTextureNum}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},(t,e)=>e)}findTextureUnit(t,e=0,i=0){for(let r=0;r<this.usedTextures.length;r++){const n=r*2;if(this.usedTextures[r]===t&&this.usedTexturePadding[n]===e&&this.usedTexturePadding[n+1]===i)return r}return-1}useTexture(t,e=0,i=0){const r=this.findTextureUnit(t,e,i);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}createShader(t,e){return new ht(this.gl,t,e)}createCustomShader(t){return t.getGLShader(this,this.KEY,this.vs,this.fs)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof ot){const e=this.createCustomShader(t);return e??this.defaultShader}return t}isSameShader(t){return this.isDefaultShader&&!t?!0:this.getCustomShader(t)==this.currentShader}enter(t){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)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){const t=this.currentShader;if(t.use(),this.customShader){const i=this.customShader,r={};for(const n in i.uniformTextures)r[n]=this.useTexture(i.uniformTextures[n]);this.customShader.applyUniform(this.KEY,r)}const e=this.gl;for(let i=0;i<this.usedTextures.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,this.usedTextures[i]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(i,r)=>r)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(i,r)=>this.usedTexturePadding[r]))}resetRender(){this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}const J=`#version 300 es\r
3
3
  precision mediump float;\r
4
4
  \r
5
5
  // per-vertex\r
@@ -96,7 +96,7 @@ void main(void) {\r
96
96
  \r
97
97
  // CUSTOM_CODE_CALL\r
98
98
  }\r
99
- `,X=48,Et=new Float32Array([0,0,1,0,0,1,1,1]);class Q extends ot{instanceBuffer;quadBuffer;instanceCount=0;localSpriteMatrix=new Float32Array(6);worldSpriteMatrix=new Float32Array(6);KEY="Sprite";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.quadBuffer=new K(t,N.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Et)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new K(t,N.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){const t=this.rapid,e=B(Rt,t.maxTextureUnits),i=B(Z,t.maxTextureUnits);return this.vs=i,this.fs=e,this.defaultShader=this.createShader(i,e),this.defaultShader}createShader(t,e){const i=super.createShader(t,e);return i.use(),i.bindVAO(),this.instanceBuffer.bindBuffer(),i.setAttributes([{name:"aMatrixRow0",size:3,stride:X,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:X,offset:12,divisor:1},{name:"aUVRect",size:4,stride:X,offset:24,divisor:1},{name:"aColor",size:4,type:nt,normalized:!0,stride:X,offset:40,divisor:1},{name:"aTextureId",size:1,type:nt,stride:X,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),i.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createCustomShader(t){const e=B(Rt,this.rapid.maxTextureUnits-t.usedTextureUnitNum),i=B(Z,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,i,e)}drawSprite(t,e,i=0,r=0,n=1,a=1,o=4294967295,h=0,c=0,u=!1,f=!1,l=!1){const g=e*6,p=this.matrixStore.data;this.drawSpriteAffine(t,p[g],p[g+1],p[g+2],p[g+3],p[g+4],p[g+5],i,r,n,a,o,h,c,u,f,l)}drawSpriteAffine(t,e,i,r,n,a,o,h=0,c=0,u=1,f=1,l=4294967295,g=0,p=0,v=!1,T=!1,E=!1){this.instanceCount>z&&this.flush();const S=t.base,y=t.scale??1,b=t.rawWidth,k=t.rawHeight,W=t.offsetX,I=t.offsetY,U=this.useTexture(t.glTexture,g/y/S.width,p/y/S.height),M=this.instanceBuffer,A=M.usedElemNum;M.resize(12);const C=M.float32,O=M.uint32,it=(E?k:b)*y,ft=(E?b:k)*y,V=it+2*g,Y=ft+2*p,Xt=W-g,jt=I-p,w=this.localSpriteMatrix;E?(w[0]=0,w[1]=T?Y:-Y,w[2]=v?-V:V,w[3]=0,w[4]=Xt+(v?V:0),w[5]=jt+(T?0:Y)):(w[0]=v?-V:V,w[1]=0,w[2]=0,w[3]=T?-Y:Y,w[4]=Xt+(v?V:0),w[5]=jt+(T?Y:0));const P=this.worldSpriteMatrix;P[0]=e*w[0]+r*w[1],P[1]=i*w[0]+n*w[1],P[2]=e*w[2]+r*w[3],P[3]=i*w[2]+n*w[3],P[4]=a+e*w[4]+r*w[5],P[5]=o+i*w[4]+n*w[5],C[A+6]=h,C[A+7]=c,C[A+8]=u,C[A+9]=f,O[A+10]=l,O[A+11]=U,this.rapid.roundPixels&&(P[4]=Math.round(P[4]),P[5]=Math.round(P[5])),C[A]=P[0],C[A+1]=P[2],C[A+2]=P[4],C[A+3]=P[1],C[A+4]=P[3],C[A+5]=P[5],M.usedElemNum+=12,M.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;super.render();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++}resetRender(){super.resetRender(),this.instanceBuffer.clear(),this.instanceCount=0}hasPendingContent(){return this.instanceCount>0}}const ie=`#version 300 es\r
99
+ `,j=48,Et=new Float32Array([0,0,1,0,0,1,1,1]);class tt extends ct{instanceBuffer;quadBuffer;instanceCount=0;localSpriteMatrix=new Float32Array(6);worldSpriteMatrix=new Float32Array(6);KEY="Sprite";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.quadBuffer=new Z(t,N.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Et)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new Z(t,N.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){const t=this.rapid,e=F(Rt,t.maxTextureUnits),i=F(J,t.maxTextureUnits);return this.vs=i,this.fs=e,this.defaultShader=this.createShader(i,e),this.defaultShader}createShader(t,e){const i=super.createShader(t,e);return i.use(),i.bindVAO(),this.instanceBuffer.bindBuffer(),i.setAttributes([{name:"aMatrixRow0",size:3,stride:j,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:j,offset:12,divisor:1},{name:"aUVRect",size:4,stride:j,offset:24,divisor:1},{name:"aColor",size:4,type:at,normalized:!0,stride:j,offset:40,divisor:1},{name:"aTextureId",size:1,type:at,stride:j,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),i.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createCustomShader(t){const e=F(Rt,this.rapid.maxTextureUnits-t.usedTextureUnitNum),i=F(J,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,i,e)}drawSprite(t,e,i=0,r=0,n=1,a=1,o=4294967295,h=0,c=0,u=!1,f=!1,l=!1){const g=e*6,p=this.matrixStore.data;this.drawSpriteAffine(t,p[g],p[g+1],p[g+2],p[g+3],p[g+4],p[g+5],i,r,n,a,o,h,c,u,f,l)}drawSpriteAffine(t,e,i,r,n,a,o,h=0,c=0,u=1,f=1,l=4294967295,g=0,p=0,T=!1,E=!1,y=!1){this.instanceCount>X&&this.flush();const v=t.base,S=t.scale??1,A=t.rawWidth,U=t.rawHeight,D=t.offsetX,q=t.offsetY,I=this.useTexture(t.glTexture,g/S/v.width,p/S/v.height),_=this.instanceBuffer,R=_.usedElemNum;_.resize(12);const M=_.float32,H=_.uint32,B=(y?U:A)*S,k=(y?A:U)*S,Y=B+2*g,z=k+2*p,Xt=D-g,jt=q-p,b=this.localSpriteMatrix;y?(b[0]=0,b[1]=E?z:-z,b[2]=T?-Y:Y,b[3]=0,b[4]=Xt+(T?Y:0),b[5]=jt+(E?0:z)):(b[0]=T?-Y:Y,b[1]=0,b[2]=0,b[3]=E?-z:z,b[4]=Xt+(T?Y:0),b[5]=jt+(E?z:0));const P=this.worldSpriteMatrix;P[0]=e*b[0]+r*b[1],P[1]=i*b[0]+n*b[1],P[2]=e*b[2]+r*b[3],P[3]=i*b[2]+n*b[3],P[4]=a+e*b[4]+r*b[5],P[5]=o+i*b[4]+n*b[5],M[R+6]=h,M[R+7]=c,M[R+8]=u,M[R+9]=f,H[R+10]=l,H[R+11]=I,this.rapid.roundPixels&&(P[4]=Math.round(P[4]),P[5]=Math.round(P[5])),M[R]=P[0],M[R+1]=P[2],M[R+2]=P[4],M[R+3]=P[1],M[R+4]=P[3],M[R+5]=P[5],_.usedElemNum+=12,_.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;super.render();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++}resetRender(){super.resetRender(),this.instanceBuffer.clear(),this.instanceCount=0}hasPendingContent(){return this.instanceCount>0}}const ie=`#version 300 es\r
100
100
  precision mediump float;\r
101
101
  \r
102
102
  in vec2 aPosition;\r
@@ -216,7 +216,7 @@ void main(void) {\r
216
216
  discard;\r
217
217
  }\r
218
218
  }\r
219
- `,j=20;class wt extends ot{vertexBuffer;vertexCount=0;matrixIndex=-1;drawMode=this.gl.TRIANGLES;texture;maskShader;KEY="Graphic";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.vertexBuffer=new K(t,N.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(se,ne)}createDefaultShader(){return this.vs=ie,this.fs=re,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const i=this.gl,r=new at(i,t,e);return r.use(),r.bindVAO(),this.vertexBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,type:i.FLOAT,stride:j-4,offset:0,divisor:0},{name:"aUV",size:2,type:i.FLOAT,stride:j-4,offset:8,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}createShader(t,e){const i=this.gl,r=super.createShader(t,e);return r.use(),r.bindVAO(),this.vertexBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,type:i.FLOAT,stride:j,offset:0,divisor:0},{name:"aColor",size:4,type:i.UNSIGNED_BYTE,normalized:!0,stride:j,offset:8,divisor:0},{name:"aUV",size:2,type:i.FLOAT,stride:j,offset:12,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}startGraphic(t,e=this.gl.TRIANGLES,i){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)}addVertex(t,e,i=0,r=0,n=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(n),a.pushFloat32(i),a.pushFloat32(r),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.render()}render(){if(this.vertexCount===0)return;super.render();const t=this.gl,e=this.currentShader,i=this.matrixIndex*6,r=this.matrixStore.data;let n=r[i+4],a=r[i+5];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("uUVRect",this.texture?[this.texture.uvX,this.texture.uvY,this.texture.uvW,this.texture.uvH]:[0,0,1,1]),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}hasPendingContent(){return!1}}class d{x;y;static ZERO=new d(0,0);static ONE=new d(1,1);static UP=new d(0,1);static DOWN=new d(0,-1);static LEFT=new d(-1,0);static RIGHT=new d(1,0);constructor(t,e){this.x=t!==void 0?t:0,this.y=e!==void 0?e:0}set(t,e){return e===void 0?(this.x=t,this.y=t):(this.x=t,this.y=e),this}add(t){return new d(this.x+t.x,this.y+t.y)}subtract(t){return new d(this.x-t.x,this.y-t.y)}sub(t){return new d(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof d?new d(this.x*t.x,this.y*t.y):new d(this.x*t,this.y*t)}mul(t){return this.multiply(t)}divide(t){return t instanceof d?new d(this.x/t.x,this.y/t.y):new d(this.x/t,this.y/t)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}clone(){return new d(this.x,this.y)}to(t){this.x=t.x,this.y=t.y}copy(){return new d(this.x,this.y)}equals(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}inverted(){return new d(this.x*-1,this.y*-1)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}squaredLength(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}normalized(){const t=this.length();return new d(this.x/t||0,this.y/t||0)}fix(t=1e-13){this.x=Math.abs(this.x)<t?0:this.x,this.y=Math.abs(this.y)<t?0:this.y}fixed(t=1e-13){return new d(Math.abs(this.x)<t?0:this.x,Math.abs(this.y)<t?0:this.y)}angle(){return Math.atan2(this.y,this.x)}abs(){return new d(Math.abs(this.x),Math.abs(this.y))}floor(){return new d(Math.floor(this.x),Math.floor(this.y))}ceil(){return new d(Math.ceil(this.x),Math.ceil(this.y))}stringify(){return`Vec2(${this.x}, ${this.y})`}clear(){this.x=0,this.y=0}isPrettyMuchZero(){return Math.abs(this.x)<1e-4&&Math.abs(this.y)<1e-4}isZero(){return this.x==0&&this.y==0}isNotZero(){return this.x!==0||this.y!==0}setToPolar(t,e=1){return this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this}static FromArray(t){return t.map(e=>new d(e[0],e[1]))}static fromAngle(t){return new d(Math.cos(t),Math.sin(t))}}const St=(s,t)=>{const[e,i,r,n,a,o]=t,h=new Float32Array([e,n,0,0,i,a,0,0,r,o,1,0,0,0,0,1]);return Mt(s,h)},Mt=(s,t)=>{const e=new Float32Array(16);for(let i=0;i<4;i++)for(let r=0;r<4;r++){let n=0;for(let a=0;a<4;a++)n+=s[r*4+a]*t[a*4+i];e[r*4+i]=n}return e};var bt=(s=>(s[s.STRETCH=0]="STRETCH",s[s.REPEAT=1]="REPEAT",s))(bt||{});const ct=10,At=(s,t,e,i,r,n)=>{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);for(let f=0;f<ct;f++){const l=f/ct,g=(f+1)/ct,p=h+l*c,v=h+g*c,T=new d(Math.cos(p)*e,Math.sin(p)*e),E=new d(Math.cos(v)*e,Math.sin(v)*e);a.push(s),o.push(new d(r,.5)),a.push(s.add(T)),o.push(new d(r+T.dot(u)*n,.5-.5*T.dot(t)/e)),a.push(s.add(E)),o.push(new d(r+E.dot(u)*n,.5-.5*E.dot(t)/e))}return{vertices:a,uv:o}},ae=(s,t=!1)=>{const e=[];if(s.length<2||t&&s.length<3)return{normals:e,length:0};const i=4,r=.001,n=s.length;let a=0;if(t)for(let h=0;h<n;h++){const c=s[h],u=s[(h+1)%n];a+=c.distanceTo(u)}else for(let h=0;h<n-1;h++)a+=s[h].distanceTo(s[h+1]);const o=(h,c,u)=>{const f=c.subtract(h).normalize(),l=c.subtract(u).normalize(),g=l.dot(f);if(g<-1+r)return{normal:f.perpendicular(),miters:1};{let p=l.add(f).normalize();f.cross(l)<0&&(p=p.multiply(-1));let v=1/Math.sqrt((1-g)/2);return{normal:p,miters:Math.min(v,i)}}};if(t)for(let h=0;h<n;h++){const c=h===0?s[n-1]:s[h-1],u=s[h],f=h===n-1?s[0]:s[h+1];e.push(o(c,u,f))}else for(let h=0;h<n;h++)if(h===0){const c=s[1].subtract(s[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(h===n-1){const c=s[h].subtract(s[h-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(o(s[h-1],s[h],s[h+1]));return{normals:e,length:a}},he=s=>{const t=s.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:i}=ae(t,s.closed),r=(s.width||1)/2,n=[],a=[],o=s.roundCap||!1,h=s.textureMode||0;let c=0;const u=s.texture?.rawWidth||1,f=s.closed?t.length:t.length-1;for(let l=0;l<f;l++){const g=t[l],p=e[l].normal,v=e[l].miters,T=(l+1)%t.length,E=t[T],S=e[T].normal,y=e[T].miters,b=g.add(p.multiply(v*r)),k=g.subtract(p.multiply(v*r)),W=E.add(S.multiply(y*r)),I=E.subtract(S.multiply(y*r)),U=g.distanceTo(E);let M=0,A=0;h===0?(M=c/i,A=(c+U)/i):(M=c/u,A=M+U/u);const C=new d(M,0),O=new d(M,1),it=new d(A,0),ft=new d(A,1);n.push(b),a.push(C),n.push(k),a.push(O),n.push(W),a.push(it),n.push(W),a.push(it),n.push(I),a.push(ft),n.push(k),a.push(O),c+=U}if(o&&!s.closed){const l=t[0],g=e[0].normal,p=h===0?i>0?1/i:0:1/u,v=At(l,g,r,!0,0,p);n.push(...v.vertices),a.push(...v.uv);const T=t[t.length-1],E=e[t.length-1].normal,S=h===0?1:c/u,y=h===0?i>0?1/i:0:1/u,b=At(T,E,r,!1,S,y);n.push(...b.vertices),a.push(...b.uv)}return{vertices:n,uv:a}},$=(s,t,e,i,r)=>{s.matrixStack.applyTransform(t,e,i);try{r()}finally{t.saveTransform!==!1&&s.matrixStack.restore()}},J=(s,t)=>t?s.premultipliedAlpha?t.premultipliedUint32:t.uint32:4294967295,oe=2,ut=(s,t)=>{const e=t.texture;if(!e?.base||s.inCreateMask)return;const i=e.isAtlas?s.atlasSpriteRegion:s.spriteRegion;s.enterRegion(i,t.shader);let r=e.uvX,n=e.uvY,a=e.uvW,o=e.uvH;const h=!!t.flipX,c=!!t.flipY!=!!e.flipY;let u=t.padding??i.currentShader.padding;e.isAtlas&&(u+=oe);const f=r<=a?u:-u,l=n<=o?u:-u;i.drawSprite(e,t.customMatrix??s.matrixStack.curWorldM,r,n,a,o,J(s,t.color),f,l,h,c,e.isRotated)},Ut=(s,t)=>{$(s,t,t.texture.rawWidth,t.texture.rawHeight,()=>{ut(s,t)})},_t=(s,t)=>{const e=s.particleRegion;s.enterRegion(e,t.shader);const i=t.texture,r=i.uvX,n=i.uvY,a=i.uvW,o=i.uvH;e.drawParticle(i,t.x,t.y,t.scaleX,t.scaleY,t.rotation,r,n,a,o,J(s,t.color),t.flipX,t.flipY,t.isRotated)},Ct=(s,t)=>{const e=s.particleRegion;s.enterRegion(e,t.shader);const i=t.texture,r=t.count??t.x.length,n=t.color,a=n.length,o=new Array(a);if(s.premultipliedAlpha)for(let h=0;h<a;h++)o[h]=n[h].premultipliedUint32;else for(let h=0;h<a;h++)o[h]=n[h].uint32;e.drawParticles(i,t.x,t.y,t.rotation,o,r,t.scaleX,t.scaleY,i.uvX,i.uvY,i.uvW,i.uvH,t.flipX,t.flipY,t.isRotated)},lt=(s,t)=>{t.points.length!==0&&$(s,t,0,0,()=>{s.startGraphic(t.drawMode??s.gl.TRIANGLES,t.texture,t.shader,t.customMatrix);for(let e=0;e<t.points.length;e++){const i=t.points[e],r=t.uv?.[e],n=Array.isArray(t.color)?t.color[e]:t.color;s.addGraphicVertex(i.x,i.y,r?.x??0,r?.y??0,J(s,n))}s.endGraphic()})},Pt=(s,t)=>{if(s.inCreateMask)return;const{vertices:e,uv:i}=he(t);lt(s,{...t,points:e,uv:i,drawMode:s.gl.TRIANGLES})},Nt=(s,t)=>{$(s,t,t.texture.rawWidth,t.texture.rawHeight,()=>{s.startMaskGraphic(s.gl.TRIANGLE_FAN,t.texture,t.customMatrix),s.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),s.endGraphic()})},Lt=(s,t)=>{$(s,t,t.width,t.height,()=>{s.startGraphic(s.gl.TRIANGLE_FAN,t.texture,t.shader,t.customMatrix),s.addRectVertex(t.width,t.height,t.color),s.endGraphic()})},It=(s,t)=>{const e=t.segments??32;$(s,t,0,0,()=>{s.startGraphic(s.gl.TRIANGLE_FAN,void 0,t.shader,t.customMatrix);const i=J(s,t.color);s.addGraphicVertex(0,0,.5,.5,i),s.addCircleVertex(t.radius,t.color,e),s.addGraphicVertex(t.radius,0,1,.5,i),s.endGraphic()})},Ot=`#version 300 es\r
219
+ `,$=20;class wt extends ct{vertexBuffer;vertexCount=0;matrixIndex=-1;drawMode=this.gl.TRIANGLES;texture;maskShader;KEY="Graphic";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.vertexBuffer=new Z(t,N.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(se,ne)}createDefaultShader(){return this.vs=ie,this.fs=re,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const i=this.gl,r=new ht(i,t,e);return r.use(),r.bindVAO(),this.vertexBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,type:i.FLOAT,stride:$-4,offset:0,divisor:0},{name:"aUV",size:2,type:i.FLOAT,stride:$-4,offset:8,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}createShader(t,e){const i=this.gl,r=super.createShader(t,e);return r.use(),r.bindVAO(),this.vertexBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,type:i.FLOAT,stride:$,offset:0,divisor:0},{name:"aColor",size:4,type:i.UNSIGNED_BYTE,normalized:!0,stride:$,offset:8,divisor:0},{name:"aUV",size:2,type:i.FLOAT,stride:$,offset:12,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}startGraphic(t,e=this.gl.TRIANGLES,i){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)}addVertex(t,e,i=0,r=0,n=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(n),a.pushFloat32(i),a.pushFloat32(r),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.render()}render(){if(this.vertexCount===0)return;super.render();const t=this.gl,e=this.currentShader,i=this.matrixIndex*6,r=this.matrixStore.data;let n=r[i+4],a=r[i+5];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("uUVRect",this.texture?[this.texture.uvX,this.texture.uvY,this.texture.uvW,this.texture.uvH]:[0,0,1,1]),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}hasPendingContent(){return!1}}class d{x;y;static ZERO=new d(0,0);static ONE=new d(1,1);static UP=new d(0,1);static DOWN=new d(0,-1);static LEFT=new d(-1,0);static RIGHT=new d(1,0);constructor(t,e){this.x=t!==void 0?t:0,this.y=e!==void 0?e:0}set(t,e){return e===void 0?(this.x=t,this.y=t):(this.x=t,this.y=e),this}add(t){return new d(this.x+t.x,this.y+t.y)}subtract(t){return new d(this.x-t.x,this.y-t.y)}sub(t){return new d(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof d?new d(this.x*t.x,this.y*t.y):new d(this.x*t,this.y*t)}mul(t){return this.multiply(t)}divide(t){return t instanceof d?new d(this.x/t.x,this.y/t.y):new d(this.x/t,this.y/t)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,i=this.y-t.y;return Math.sqrt(e*e+i*i)}clone(){return new d(this.x,this.y)}to(t){this.x=t.x,this.y=t.y}copy(){return new d(this.x,this.y)}equals(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}inverted(){return new d(this.x*-1,this.y*-1)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}squaredLength(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}normalized(){const t=this.length();return new d(this.x/t||0,this.y/t||0)}fix(t=1e-13){this.x=Math.abs(this.x)<t?0:this.x,this.y=Math.abs(this.y)<t?0:this.y}fixed(t=1e-13){return new d(Math.abs(this.x)<t?0:this.x,Math.abs(this.y)<t?0:this.y)}angle(){return Math.atan2(this.y,this.x)}abs(){return new d(Math.abs(this.x),Math.abs(this.y))}floor(){return new d(Math.floor(this.x),Math.floor(this.y))}ceil(){return new d(Math.ceil(this.x),Math.ceil(this.y))}stringify(){return`Vec2(${this.x}, ${this.y})`}clear(){this.x=0,this.y=0}isPrettyMuchZero(){return Math.abs(this.x)<1e-4&&Math.abs(this.y)<1e-4}isZero(){return this.x==0&&this.y==0}isNotZero(){return this.x!==0||this.y!==0}setToPolar(t,e=1){return this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this}static FromArray(t){return t.map(e=>new d(e[0],e[1]))}static fromAngle(t){return new d(Math.cos(t),Math.sin(t))}}const St=(s,t)=>{const[e,i,r,n,a,o]=t,h=new Float32Array([e,n,0,0,i,a,0,0,r,o,1,0,0,0,0,1]);return Mt(s,h)},Mt=(s,t)=>{const e=new Float32Array(16);for(let i=0;i<4;i++)for(let r=0;r<4;r++){let n=0;for(let a=0;a<4;a++)n+=s[r*4+a]*t[a*4+i];e[r*4+i]=n}return e};var bt=(s=>(s[s.STRETCH=0]="STRETCH",s[s.REPEAT=1]="REPEAT",s))(bt||{});const ut=10,At=(s,t,e,i,r,n)=>{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);for(let f=0;f<ut;f++){const l=f/ut,g=(f+1)/ut,p=h+l*c,T=h+g*c,E=new d(Math.cos(p)*e,Math.sin(p)*e),y=new d(Math.cos(T)*e,Math.sin(T)*e);a.push(s),o.push(new d(r,.5)),a.push(s.add(E)),o.push(new d(r+E.dot(u)*n,.5-.5*E.dot(t)/e)),a.push(s.add(y)),o.push(new d(r+y.dot(u)*n,.5-.5*y.dot(t)/e))}return{vertices:a,uv:o}},ae=(s,t=!1)=>{const e=[];if(s.length<2||t&&s.length<3)return{normals:e,length:0};const i=4,r=.001,n=s.length;let a=0;if(t)for(let h=0;h<n;h++){const c=s[h],u=s[(h+1)%n];a+=c.distanceTo(u)}else for(let h=0;h<n-1;h++)a+=s[h].distanceTo(s[h+1]);const o=(h,c,u)=>{const f=c.subtract(h).normalize(),l=c.subtract(u).normalize(),g=l.dot(f);if(g<-1+r)return{normal:f.perpendicular(),miters:1};{let p=l.add(f).normalize();f.cross(l)<0&&(p=p.multiply(-1));let T=1/Math.sqrt((1-g)/2);return{normal:p,miters:Math.min(T,i)}}};if(t)for(let h=0;h<n;h++){const c=h===0?s[n-1]:s[h-1],u=s[h],f=h===n-1?s[0]:s[h+1];e.push(o(c,u,f))}else for(let h=0;h<n;h++)if(h===0){const c=s[1].subtract(s[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(h===n-1){const c=s[h].subtract(s[h-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(o(s[h-1],s[h],s[h+1]));return{normals:e,length:a}},he=s=>{const t=s.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:i}=ae(t,s.closed),r=(s.width||1)/2,n=[],a=[],o=s.roundCap||!1,h=s.textureMode||0;let c=0;const u=s.texture?.rawWidth||1,f=s.closed?t.length:t.length-1;for(let l=0;l<f;l++){const g=t[l],p=e[l].normal,T=e[l].miters,E=(l+1)%t.length,y=t[E],v=e[E].normal,S=e[E].miters,A=g.add(p.multiply(T*r)),U=g.subtract(p.multiply(T*r)),D=y.add(v.multiply(S*r)),q=y.subtract(v.multiply(S*r)),I=g.distanceTo(y);let _=0,R=0;h===0?(_=c/i,R=(c+I)/i):(_=c/u,R=_+I/u);const M=new d(_,0),H=new d(_,1),B=new d(R,0),k=new d(R,1);n.push(A),a.push(M),n.push(U),a.push(H),n.push(D),a.push(B),n.push(D),a.push(B),n.push(q),a.push(k),n.push(U),a.push(H),c+=I}if(o&&!s.closed){const l=t[0],g=e[0].normal,p=h===0?i>0?1/i:0:1/u,T=At(l,g,r,!0,0,p);n.push(...T.vertices),a.push(...T.uv);const E=t[t.length-1],y=e[t.length-1].normal,v=h===0?1:c/u,S=h===0?i>0?1/i:0:1/u,A=At(E,y,r,!1,v,S);n.push(...A.vertices),a.push(...A.uv)}return{vertices:n,uv:a}},K=(s,t,e,i,r)=>{s.matrixStack.applyTransform(t,e,i);try{r()}finally{t.saveTransform!==!1&&s.matrixStack.restore()}},et=(s,t)=>t?s.premultipliedAlpha?t.premultipliedUint32:t.uint32:4294967295,oe=2,lt=(s,t)=>{const e=t.texture;if(!e?.base||s.inCreateMask)return;const i=e.isAtlas?s.atlasSpriteRegion:s.spriteRegion;s.enterRegion(i,t.shader);let r=e.uvX,n=e.uvY,a=e.uvW,o=e.uvH;const h=!!t.flipX,c=!!t.flipY!=!!e.flipY;let u=t.padding??i.currentShader.padding;e.isAtlas&&(u+=oe);const f=r<=a?u:-u,l=n<=o?u:-u;i.drawSprite(e,t.customMatrix??s.matrixStack.curWorldM,r,n,a,o,et(s,t.color),f,l,h,c,e.isRotated)},Ut=(s,t)=>{K(s,t,t.texture.rawWidth,t.texture.rawHeight,()=>{lt(s,t)})},_t=(s,t)=>{const e=s.particleRegion;s.enterRegion(e,t.shader);const i=t.texture,r=i.uvX,n=i.uvY,a=i.uvW,o=i.uvH;e.drawParticle(i,t.x,t.y,t.scaleX,t.scaleY,t.rotation,r,n,a,o,et(s,t.color),t.flipX,t.flipY,t.isRotated,t.originX,t.originY)},Ct=(s,t)=>{const e=s.particleRegion;s.enterRegion(e,t.shader);const i=t.texture,r=t.count??t.x.length,n=t.color,a=n.length,o=new Array(a);if(s.premultipliedAlpha)for(let h=0;h<a;h++)o[h]=n[h].premultipliedUint32;else for(let h=0;h<a;h++)o[h]=n[h].uint32;e.drawParticles(i,t.x,t.y,t.rotation,o,r,t.scaleX,t.scaleY,i.uvX,i.uvY,i.uvW,i.uvH,t.flipX,t.flipY,t.isRotated,t.originX,t.originY)},dt=(s,t)=>{t.points.length!==0&&K(s,t,0,0,()=>{s.startGraphic(t.drawMode??s.gl.TRIANGLES,t.texture,t.shader,t.customMatrix);for(let e=0;e<t.points.length;e++){const i=t.points[e],r=t.uv?.[e],n=Array.isArray(t.color)?t.color[e]:t.color;s.addGraphicVertex(i.x,i.y,r?.x??0,r?.y??0,et(s,n))}s.endGraphic()})},Pt=(s,t)=>{if(s.inCreateMask)return;const{vertices:e,uv:i}=he(t);dt(s,{...t,points:e,uv:i,drawMode:s.gl.TRIANGLES})},Nt=(s,t)=>{K(s,t,t.texture.rawWidth,t.texture.rawHeight,()=>{s.startMaskGraphic(s.gl.TRIANGLE_FAN,t.texture,t.customMatrix),s.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),s.endGraphic()})},Lt=(s,t)=>{K(s,t,t.width,t.height,()=>{s.startGraphic(s.gl.TRIANGLE_FAN,t.texture,t.shader,t.customMatrix),s.addRectVertex(t.width,t.height,t.color),s.endGraphic()})},It=(s,t)=>{const e=t.segments??32;K(s,t,0,0,()=>{s.startGraphic(s.gl.TRIANGLE_FAN,void 0,t.shader,t.customMatrix);const i=et(s,t.color);s.addGraphicVertex(0,0,.5,.5,i),s.addCircleVertex(t.radius,t.color,e),s.addGraphicVertex(t.radius,0,1,.5,i),s.endGraphic()})},Ot=`#version 300 es\r
220
220
  precision mediump float;\r
221
221
  \r
222
222
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -265,7 +265,7 @@ void main(void) {\r
265
265
  \r
266
266
  // CUSTOM_CODE_CALL\r
267
267
  }\r
268
- `;class ce extends Q{KEY="AtlasSprite";constructor(t){super(t)}createCustomShader(t){const e=B(Ot,this.rapid.maxTextureUnits-t.usedTextureUnitNum),i=B(Z,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,i,e)}createDefaultShader(){const t=this.rapid,e=B(Ot,t.maxTextureUnits),i=B(Z,t.maxTextureUnits);return this.vs=i,this.fs=e,this.defaultShader=this.createShader(i,e),this.defaultShader}}const Wt=`#version 300 es\r
268
+ `;class ce extends tt{KEY="AtlasSprite";constructor(t){super(t)}createCustomShader(t){const e=F(Ot,this.rapid.maxTextureUnits-t.usedTextureUnitNum),i=F(J,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,i,e)}createDefaultShader(){const t=this.rapid,e=F(Ot,t.maxTextureUnits),i=F(J,t.maxTextureUnits);return this.vs=i,this.fs=e,this.defaultShader=this.createShader(i,e),this.defaultShader}}const Wt=`#version 300 es\r
269
269
  precision mediump float;\r
270
270
  \r
271
271
  // per-vertex\r
@@ -273,8 +273,9 @@ in vec2 aVertex;\r
273
273
  \r
274
274
  // per-instance: 变换\r
275
275
  in vec2 aPosition;\r
276
- in vec2 aScale;\r
277
- in float aRotation;\r
276
+ in vec2 aScale;
277
+ in float aRotation;
278
+ in vec2 aOrigin;
278
279
  \r
279
280
  // per-instance:UV 区域 (u0, v0, u1, v1)\r
280
281
  in vec4 aUVRect;\r
@@ -294,10 +295,15 @@ void main(void) {\r
294
295
  vRegion = aUVRect.xy + aVertex * (aUVRect.zw - aUVRect.xy);\r
295
296
  // CUSTOM_CODE_CALL\r
296
297
  \r
297
- vec2 v;\r
298
- v.x = (aVertex.x) * cos(aRotation) - (aVertex.y) * sin(aRotation);\r
299
- v.y = (aVertex.x) * sin(aRotation) + (aVertex.y) * cos(aRotation);\r
300
- v = v * aScale + aPosition;\r
298
+ vec2 scaled = (aVertex - aOrigin) * aScale;
299
+ float c = cos(aRotation);\r
300
+ float s = sin(aRotation);\r
301
+ \r
302
+ vec2 v = vec2(\r
303
+ scaled.x * c - scaled.y * s,\r
304
+ scaled.x * s + scaled.y * c\r
305
+ ) + aPosition;\r
306
+ \r
301
307
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
302
308
  }\r
303
309
  `,Ft=`#version 300 es\r
@@ -316,4 +322,4 @@ void main(void) {\r
316
322
  \r
317
323
  // CUSTOM_CODE_CALL\r
318
324
  }\r
319
- `,H=40,tt=H/4;class ue extends Q{KEY="ParticleSprite";texture;constructor(t){super(t)}createCustomShader(t){return t.getGLShader(this,this.KEY,Wt,Ft)}createDefaultShader(){const t=Ft,e=Wt;return this.vs=e,this.fs=t,this.defaultShader=this.createShader(e,t),this.defaultShader}enter(t){super.enter(t),this.currentShader.setUniform("u_projection",this.rapid.projection)}createShader(t,e){const i=super.createShader(t,e);return i.use(),i.bindVAO(),this.instanceBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,stride:H,offset:0,divisor:1},{name:"aScale",size:2,stride:H,offset:8,divisor:1},{name:"aRotation",size:1,stride:H,offset:16,divisor:1},{name:"aUVRect",size:4,stride:H,offset:20,divisor:1},{name:"aColor",size:4,type:nt,normalized:!0,stride:H,offset:36,divisor:1}]),this.quadBuffer.bindBuffer(),i.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}drawParticle(t,e=0,i=0,r=1,n=1,a=0,o=0,h=0,c=1,u=1,f=4294967295,l=!1,g=!1,p=!1){(this.instanceCount>=z||this.texture&&t!=this.texture)&&this.flush(),t.glTexture&&(this.texture=t,this.useTexture(t.glTexture,0,0));const v=this.instanceBuffer,T=v.usedElemNum,E=t.rawWidth,S=t.rawHeight;v.resize(tt);const y=v.float32,b=v.uint32;y[T]=e,y[T+1]=i,y[T+2]=r*(l?-1:1)*E,y[T+3]=n*(g?-1:1)*S,y[T+4]=a,p&&(y[T+4]+=Math.PI/2),y[T+5]=o,y[T+6]=h,y[T+7]=c,y[T+8]=u,b[T+9]=f,v.usedElemNum+=tt,v.makeDirty(),this.instanceCount++}drawParticles(t,e,i,r,n,a,o=1,h=1,c=0,u=0,f=1,l=1,g=!1,p=!1,v=!1){if(!t.glTexture||a<=0)return;let T=0;const E=t.rawWidth*o*(g?-1:1),S=t.rawHeight*h*(p?-1:1),y=v?Math.PI/2:0;for(;T<a;){this.texture&&t!==this.texture&&this.flush(),this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const b=a-T,k=z-this.instanceCount,W=Math.min(b,k),I=this.instanceBuffer;let U=I.usedElemNum;I.resize(W*tt);const M=I.float32,A=I.uint32;for(let C=0;C<W;C++){const O=T+C;M[U]=e[O],M[U+1]=i[O],M[U+2]=E,M[U+3]=S,M[U+4]=r[O]+y,M[U+5]=c,M[U+6]=u,M[U+7]=f,M[U+8]=l,A[U+9]=n[O],U+=tt}I.usedElemNum=U,I.makeDirty(),this.instanceCount+=W,T+=W,this.instanceCount>=z&&this.flush()}}render(){if(this.instanceCount===0)return;super.render();const t=this.gl;this.texture&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture));const e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO();const i=St(this.rapid.projection,this.worldSpriteMatrix);this.currentShader.setUniform("u_projection",i),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++,this.texture=void 0}}var Dt=(s=>(s[s.EQUAL=0]="EQUAL",s[s.NOT_EQUAL=1]="NOT_EQUAL",s))(Dt||{}),Bt=(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))(Bt||{}),et=(s=>(s[s.LINEAR=0]="LINEAR",s[s.NEAREST=1]="NEAREST",s))(et||{}),kt=(s=>(s[s.CanvasItem=0]="CanvasItem",s[s.Viewport=1]="Viewport",s))(kt||{});class le{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=m.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new xt(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new L;get height(){return this.logicHeight}get width(){return this.logicWidth}constructor(t){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;const e=Kt(this.canvas,this.antialias,this.premultipliedAlpha);this.gl=e,this.maxTextureUnits=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.matrix=this.matrixStack.matrix,this.spriteRegion=new Q(this),this.graphicRegion=new wt(this),this.atlasSpriteRegion=new ce(this),this.particleRegion=new ue(this);const i=this.canvas.clientWidth||this.canvas.width,r=this.canvas.clientHeight||this.canvas.height;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 pt(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)}setTextureFilter(t){this.textureFilter=t}setAntialias(t){this.antialias=t}getColorUint32(t){return t?this.premultipliedAlpha?t.premultipliedUint32:t.uint32:4294967295}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticle(t){_t(this,t)}drawParticles(t){Ct(this,t)}drawSprite(t){Ut(this,t)}drawLine(t){Pt(this,t)}drawGraphic(t){lt(this,t)}drawRect(t){Lt(this,t)}drawCircle(t){It(this,t)}startGraphic(t=this.gl.TRIANGLES,e,i,r){this.enterRegion(this.graphicRegion,i),this.graphicRegion.startGraphic(r??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,i){this.startGraphic(t,e,this.graphicRegion.maskShader,i)}drawMaskImage(t){Nt(this,t)}addRectVertex(t,e,i){const r=this.getColorUint32(i);this.addGraphicVertex(0,0,0,0,r),this.addGraphicVertex(t,0,1,0,r),this.addGraphicVertex(t,e,1,1,r),this.addGraphicVertex(0,e,0,1,r)}addCircleVertex(t,e,i=32){const r=Math.PI*2/i,n=this.getColorUint32(e);for(let a=0;a<i;a++){const o=r*a,h=Math.cos(o)*t,c=Math.sin(o)*t,u=.5+Math.cos(o)*.5,f=.5+Math.sin(o)*.5;this.addGraphicVertex(h,c,u,f,n)}}addGraphicVertex(t,e,i=0,r=0,n=4294967295){this.graphicRegion.addVertex(t,e,i,r,n)}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,i,r){this.flush();const n=i??this.canvas.clientWidth??this.canvas.width,a=r??this.canvas.clientHeight??this.canvas.height;switch(i!==void 0&&(this.canvas.style.width=n+"px"),r!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=n*this.dpr,this.physicsHeight=a*this.dpr,this.logicWidth=t,this.logicHeight=e,this.scaleMode){case 1:this.canvas.width=t,this.canvas.height=e,this.canvas.style.imageRendering="pixelated",this.gl.viewport(0,0,t,e);break;case 0:this.canvas.width=this.physicsWidth,this.canvas.height=this.physicsHeight,this.canvas.style.imageRendering="auto",this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight);break;default:throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem")}this.updateProjection(0,this.logicWidth,this.logicHeight,0)}updateProjection(t,e,i,r){this.updateOrthMatrix(this.projection,t,e,i,r),this.projectionDirty=!0}clear(){const t=this.gl;this.backgroundColor.setClearColor(t),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),this.drawcallCount=0,this.matrixStack.reset()}updateOrthMatrix(t,e,i,r,n){t[0]=2/(i-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(n-r),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(i+e)/(i-e),t[13]=-(n+r)/(n-r),t[14]=0,t[15]=1}flush(){this.currentRegion&&(this.currentRegion.exit(),this.currentRegion=null)}applyFilters(t,e){if(e.length===0)throw new Error("applyFilters: shaders array must not be empty.");const i=Math.max(...e.map(c=>c.padding)),r=i,n=t.rawWidth+i*2,a=t.rawHeight+i*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(n,a):this._filterRT[c]=this.texture.createRenderTexture({width:n,height:a});let o=t.clone(this._filterInput),h=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[h%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:o,shader:e[c],offsetX:c==0?r:0,offsetY:c==0?r:0,padding:i}),this.leaveRenderTexture(),o=u,h++}return this.matrixStack.restore(),o.offsetX=-r,o.offsetY=-r,o}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,t.rawHeight,0)}clearRenderTexture(t=new m(0,0,0,0)){this.flush();const e=this.gl;t.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT)}leaveRenderTexture(){this.flush(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight),this.updateProjection(0,this.logicWidth,this.logicHeight,0)}drawToRenderTexture(t,e,i=new m(0,0,0,0)){this.enterRenderTexture(t);try{i!==null&&this.clearRenderTexture(i),e()}finally{this.leaveRenderTexture()}}withMask(t,e,i=0,r=1){this.clearMask(),this.startDrawMask(r);try{t()}finally{this.endDrawMask()}this.enterMask(i,r);try{e()}finally{this.exitMask()}}withTransform(t,e,i=0,r=0){if(e){const n=e.saveTransform??!0;try{this.matrixStack.applyTransform(e,i,r),t()}finally{n&&this.matrixStack.restore()}}else{this.matrixStack.save();try{t()}finally{this.matrixStack.restore()}}}withScissor(t,e,i,r,n){this.startScissor(t,e,i,r);try{n()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const i=this.gl;i.stencilMask(e),i.colorMask(!1,!1,!1,!1),i.stencilFunc(i.ALWAYS,t,e),i.stencilOp(i.KEEP,i.KEEP,i.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}endDrawMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(0),this.inCreateMask=!1}clearMask(t=255){this.flush();const e=this.gl;e.stencilMask(t),e.clear(e.STENCIL_BUFFER_BIT),this.inCreateMask=!1}enterMask(t,e=1,i=255){this.flush();const r=this.gl;r.colorMask(!0,!0,!0,!0),r.stencilMask(0),r.stencilFunc(t===0?r.EQUAL:r.NOTEQUAL,e,i),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),this.inCreateMask=!1}exitMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(255),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),this.inCreateMask=!1}setBlendMode(t){this.flush();const e=this.gl;switch(t){case 0:this.premultipliedAlpha?e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 1:e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE);break;case 2:e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 3:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_COLOR,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 4:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE_MINUS_SRC_ALPHA);break}}startScissor(t,e,i,r){this.flush();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);n.enable(n.SCISSOR_TEST),n.scissor(h,c,u,f)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}renderCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new d(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new d(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.mul(this.dpr)}cssToLogic(t){const e=this.cssToDevicePixel(t);return this.physicsToLogic(e)}devicePixelToCss(t){return t.divide(this.dpr)}toCSSMatrix(t){const e=this.physicsWidth/this.dpr/this.logicWidth,i=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,i)}}function de(s){return!(s===null||typeof s!="object"||Array.isArray(s)||s instanceof d||s instanceof m)}class _{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,i,r){return new d(_.float(t,e),_.float(i,r))}static randomColor(t,e){return new m(_.float(t.r,e.r),_.float(t.g,e.g),_.float(t.b,e.b),_.float(t.a,e.a))}static pick(t){return t[_.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,r]of t)e+=r;let i=Math.random()*e;for(const[r,n]of t)if(i-=n,i<=0)return r;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[i,r]=t;if(typeof i=="number")return _.float(i,r);if(i instanceof d)return _.vector(i.x,r.x,i.y,r.y);if(i instanceof m)return _.randomColor(i,r)}return typeof t=="number"?t:t.clone()}}var Gt=(s=>(s.POINT="point",s.CIRCLE="circle",s.RECT="rect",s))(Gt||{});const Ht=10,Vt=0,Yt=!0;class zt{life=0;maxLife;texture;options;position;datas;rapid;constructor(t,e){this.rapid=t,this.options=e,e.texture instanceof L?this.texture=e.texture:e.texture instanceof Array&&e.texture[0]instanceof Array?this.texture=_.pickWeight(e.texture):e.texture instanceof Array&&(this.texture=_.pick(e.texture)),this.maxLife=_.scalarOrRange(e.life,1),this.datas={speed:this.processAttribute(e.animation.speed,0),rotation:this.processAttribute(e.animation.rotation,0),scale:this.processAttribute(e.animation.scale,1),color:this.processAttribute(e.animation.color,m.White.clone()),velocity:this.processAttribute(e.animation.velocity,d.ZERO)},this.position=d.ZERO,this.initializePosition()}processAttribute(t,e){if(t==null)return{value:e};if(de(t)){const i=t,r=_.scalarOrRange(i.start,e),n=i.end===void 0?r:_.scalarOrRange(i.end,e);return{delta:i.delta??this.getDelta(r,n,this.maxLife),value:r,damping:i.damping}}else return this.processAttribute({start:t},e)}updateNumberAttribute(t,e){t.damping!==void 0&&(t.value*=Math.pow(t.damping,e)),t.delta!==void 0&&(t.value+=t.delta*e)}updateVec2Attribute(t,e){t.damping!==void 0&&(t.value=t.value.multiply(Math.pow(t.damping,e))),t.delta!==void 0&&(t.value=t.value.add(t.delta.multiply(e)))}updateColorAttribute(t,e){t.damping!==void 0&&(t.value=t.value.multiply(Math.pow(t.damping,e))),t.delta!==void 0&&(t.value=t.value.add(t.delta.multiply(e))),t.value.clamp()}updateAttributes(t){const e=this.datas;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);const r=d.fromAngle(e.rotation.value).multiply(e.speed.value*t);this.position=this.position.add(r).add(e.velocity.value.multiply(t))}getDelta(t,e,i){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}update(t){return this.life+=t,this.life>=this.maxLife?!1:(this.updateAttributes(t),!0)}render(){const t=this.rapid.matrixStack,e=this.datas.scale.value,i=this.datas.rotation.value,r=this.datas.color.value;t.save(),t.translate(this.position.x,this.position.y),i!==0&&t.rotate(i),e!==1&&t.scale(e,e);const n=this.options.origin?this.options.origin.x:.5,a=this.options.origin?this.options.origin.y:.5;(n!==0||a!==0)&&t.translate(-n*this.texture.rawWidth,-a*this.texture.rawHeight),ut(this.rapid,{texture:this.texture,color:r}),t.restore()}initializePosition(){switch(this.options.emitShape){case"circle":{const t=Math.random()*Math.PI*2,e=(this.options.emitRadius??0)*Math.sqrt(Math.random());this.position=new d(Math.cos(t)*e,Math.sin(t)*e);break}case"rect":{this.position=new d((Math.random()-.5)*(this.options.emitRect?.width??0),(Math.random()-.5)*(this.options.emitRect?.height??0));break}default:this.position=d.ZERO;break}!this.options.localSpace&&this.options.position&&(this.position=this.position.add(this.options.position))}}class dt{particles=[];options;emitting=!1;emitTimer=0;emitRate=Ht;emitTime=Vt;emitTimeCounter=0;localSpace=Yt;position=d.ZERO;rapid;gameObject;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate!==void 0?e.emitRate:Ht,this.emitTime=e.emitTime!==void 0?e.emitTime:Vt,this.localSpace=e.localSpace!==void 0?e.localSpace:Yt,this.position=e.position??d.ZERO}setTexture(t){this.options.texture=t}clone(){return new dt(this.rapid,{...this.options})}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){this.particles=[],this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,i=Math.min(t,e-this.particles.length);for(let r=0;r<i;r++)this.particles.push(new zt(this.rapid,{...this.options,position:this.position}))}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const e=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*e),this.emitTimeCounter-=e*this.emitTime}}else{this.emitTimer+=t;const e=Math.floor(this.emitTimer*this.emitRate);e>0&&(this.emit(e),this.emitTimer-=e/this.emitRate)}for(let e=this.particles.length-1;e>=0;e--)this.particles[e].update(t)||this.particles.splice(e,1)}render(){const t=this.rapid.matrixStack;this.localSpace&&(t.save(),t.translate(this.position.x,this.position.y));for(const e of this.particles)e.render();this.localSpace&&t.restore()}getParticleCount(){return this.particles.length}isActive(){return this.emitting||this.particles.length>0}oneShot(){this.emit(this.emitRate)}}x.ArrayType=N,x.BaseTexture=D,x.BlendMode=Bt,x.CanvasScaleMode=kt,x.Color=m,x.CustomGlShader=ht,x.DynamicArrayBuffer=F,x.GLShader=at,x.GraphicRegion=wt,x.LineTextureMode=bt,x.MAX_INSTANCES=z,x.MaskType=Dt,x.MatrixStack=xt,x.MatrixStore=mt,x.Particle=zt,x.ParticleEmitter=dt,x.ParticleShape=Gt,x.QUAD_VERTICES=Et,x.Rapid=le,x.Region=ot,x.RenderTexture=gt,x.SpriteRegion=Q,x.TextTexture=vt,x.Texture=L,x.TextureFilterMode=et,x.TextureManager=pt,x.TextureWrapMode=G,x.Vec2=d,x.WebglBufferArray=K,x.composeProjectionWithAffine=St,x.drawCircle=It,x.drawGraphic=lt,x.drawLine=Pt,x.drawMaskImage=Nt,x.drawParticle=_t,x.drawParticles=Ct,x.drawRect=Lt,x.drawSprite=Ut,x.drawSpriteRaw=ut,x.multiplyMat4=Mt,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
325
+ `,G=48,it=G/4;class ue extends tt{KEY="ParticleSprite";texture;constructor(t){super(t)}createCustomShader(t){return t.getGLShader(this,this.KEY,Wt,Ft)}createDefaultShader(){const t=Ft,e=Wt;return this.vs=e,this.fs=t,this.defaultShader=this.createShader(e,t),this.defaultShader}enter(t){super.enter(t),this.currentShader.setUniform("u_projection",this.rapid.projection)}createShader(t,e){const i=super.createShader(t,e);return i.use(),i.bindVAO(),this.instanceBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,stride:G,offset:0,divisor:1},{name:"aScale",size:2,stride:G,offset:8,divisor:1},{name:"aRotation",size:1,stride:G,offset:16,divisor:1},{name:"aUVRect",size:4,stride:G,offset:20,divisor:1},{name:"aColor",size:4,type:at,normalized:!0,stride:G,offset:36,divisor:1},{name:"aOrigin",size:2,stride:G,offset:40,divisor:1}]),this.quadBuffer.bindBuffer(),i.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}drawParticle(t,e=0,i=0,r=1,n=1,a=0,o=0,h=0,c=1,u=1,f=4294967295,l=!1,g=!1,p=!1,T=.5,E=.5){(this.instanceCount>=X||this.texture&&t!=this.texture)&&this.flush(),t.glTexture&&(this.texture=t,this.useTexture(t.glTexture,0,0));const y=this.instanceBuffer,v=y.usedElemNum,S=t.rawWidth,A=t.rawHeight;y.resize(it);const U=y.float32,D=y.uint32;U[v]=e,U[v+1]=i,U[v+2]=r*(l?-1:1)*S,U[v+3]=n*(g?-1:1)*A,U[v+4]=a,p&&(U[v+4]+=Math.PI/2),U[v+5]=o,U[v+6]=h,U[v+7]=c,U[v+8]=u,D[v+9]=f,U[v+10]=T,U[v+11]=E,y.usedElemNum+=it,y.makeDirty(),this.instanceCount++}drawParticles(t,e,i,r,n,a,o=1,h=1,c=0,u=0,f=1,l=1,g=!1,p=!1,T=!1,E=.5,y=.5){if(!t.glTexture||a<=0)return;let v=0;const S=t.rawWidth*o*(g?-1:1),A=t.rawHeight*h*(p?-1:1),U=T?Math.PI/2:0;for(;v<a;){this.texture&&t!==this.texture&&this.flush(),this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const D=a-v,q=X-this.instanceCount,I=Math.min(D,q),_=this.instanceBuffer;let R=_.usedElemNum;_.resize(I*it);const M=_.float32,H=_.uint32;for(let B=0;B<I;B++){const k=v+B;M[R]=e[k],M[R+1]=i[k],M[R+2]=S,M[R+3]=A,M[R+4]=r[k]+U,M[R+5]=c,M[R+6]=u,M[R+7]=f,M[R+8]=l,H[R+9]=n[k],M[R+10]=E,M[R+11]=y,R+=it}_.usedElemNum=R,_.makeDirty(),this.instanceCount+=I,v+=I,this.instanceCount>=X&&this.flush()}}render(){if(this.instanceCount===0)return;super.render();const t=this.gl;this.texture&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture));const e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO();const i=St(this.rapid.projection,this.worldSpriteMatrix);this.currentShader.setUniform("u_projection",i),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++,this.texture=void 0}}var Dt=(s=>(s[s.EQUAL=0]="EQUAL",s[s.NOT_EQUAL=1]="NOT_EQUAL",s))(Dt||{}),Bt=(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))(Bt||{}),rt=(s=>(s[s.LINEAR=0]="LINEAR",s[s.NEAREST=1]="NEAREST",s))(rt||{}),kt=(s=>(s[s.CanvasItem=0]="CanvasItem",s[s.Viewport=1]="Viewport",s))(kt||{});class le{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=m.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new xt(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new L;get height(){return this.logicHeight}get width(){return this.logicWidth}constructor(t){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;const e=Kt(this.canvas,this.antialias,this.premultipliedAlpha);this.gl=e,this.maxTextureUnits=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.matrix=this.matrixStack.matrix,this.spriteRegion=new tt(this),this.graphicRegion=new wt(this),this.atlasSpriteRegion=new ce(this),this.particleRegion=new ue(this);const i=this.canvas.clientWidth||this.canvas.width,r=this.canvas.clientHeight||this.canvas.height;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 pt(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)}setTextureFilter(t){this.textureFilter=t}setAntialias(t){this.antialias=t}getColorUint32(t){return t?this.premultipliedAlpha?t.premultipliedUint32:t.uint32:4294967295}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticle(t){_t(this,t)}drawParticles(t){Ct(this,t)}drawSprite(t){Ut(this,t)}drawLine(t){Pt(this,t)}drawGraphic(t){dt(this,t)}drawRect(t){Lt(this,t)}drawCircle(t){It(this,t)}startGraphic(t=this.gl.TRIANGLES,e,i,r){this.enterRegion(this.graphicRegion,i),this.graphicRegion.startGraphic(r??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,i){this.startGraphic(t,e,this.graphicRegion.maskShader,i)}drawMaskImage(t){Nt(this,t)}addRectVertex(t,e,i){const r=this.getColorUint32(i);this.addGraphicVertex(0,0,0,0,r),this.addGraphicVertex(t,0,1,0,r),this.addGraphicVertex(t,e,1,1,r),this.addGraphicVertex(0,e,0,1,r)}addCircleVertex(t,e,i=32){const r=Math.PI*2/i,n=this.getColorUint32(e);for(let a=0;a<i;a++){const o=r*a,h=Math.cos(o)*t,c=Math.sin(o)*t,u=.5+Math.cos(o)*.5,f=.5+Math.sin(o)*.5;this.addGraphicVertex(h,c,u,f,n)}}addGraphicVertex(t,e,i=0,r=0,n=4294967295){this.graphicRegion.addVertex(t,e,i,r,n)}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,i,r){this.flush();const n=i??this.canvas.clientWidth??this.canvas.width,a=r??this.canvas.clientHeight??this.canvas.height;switch(i!==void 0&&(this.canvas.style.width=n+"px"),r!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=n*this.dpr,this.physicsHeight=a*this.dpr,this.logicWidth=t,this.logicHeight=e,this.scaleMode){case 1:this.canvas.width=t,this.canvas.height=e,this.canvas.style.imageRendering="pixelated",this.gl.viewport(0,0,t,e);break;case 0:this.canvas.width=this.physicsWidth,this.canvas.height=this.physicsHeight,this.canvas.style.imageRendering="auto",this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight);break;default:throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem")}this.updateProjection(0,this.logicWidth,this.logicHeight,0)}updateProjection(t,e,i,r){this.updateOrthMatrix(this.projection,t,e,i,r),this.projectionDirty=!0}clear(){const t=this.gl;this.backgroundColor.setClearColor(t),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),this.drawcallCount=0,this.matrixStack.reset()}updateOrthMatrix(t,e,i,r,n){t[0]=2/(i-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(n-r),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(i+e)/(i-e),t[13]=-(n+r)/(n-r),t[14]=0,t[15]=1}flush(){this.currentRegion&&(this.currentRegion.exit(),this.currentRegion=null)}applyFilters(t,e){if(e.length===0)throw new Error("applyFilters: shaders array must not be empty.");const i=Math.max(...e.map(c=>c.padding)),r=i,n=t.rawWidth+i*2,a=t.rawHeight+i*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(n,a):this._filterRT[c]=this.texture.createRenderTexture({width:n,height:a});let o=t.clone(this._filterInput),h=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[h%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:o,shader:e[c],offsetX:c==0?r:0,offsetY:c==0?r:0,padding:i}),this.leaveRenderTexture(),o=u,h++}return this.matrixStack.restore(),o.offsetX=-r,o.offsetY=-r,o}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,t.rawHeight,0)}clearRenderTexture(t=new m(0,0,0,0)){this.flush();const e=this.gl;t.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT)}leaveRenderTexture(){this.flush(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight),this.updateProjection(0,this.logicWidth,this.logicHeight,0)}drawToRenderTexture(t,e,i=new m(0,0,0,0)){this.enterRenderTexture(t);try{i!==null&&this.clearRenderTexture(i),e()}finally{this.leaveRenderTexture()}}withMask(t,e,i=0,r=1){this.clearMask(),this.startDrawMask(r);try{t()}finally{this.endDrawMask()}this.enterMask(i,r);try{e()}finally{this.exitMask()}}withTransform(t,e,i=0,r=0){if(e){const n=e.saveTransform??!0;try{this.matrixStack.applyTransform(e,i,r),t()}finally{n&&this.matrixStack.restore()}}else{this.matrixStack.save();try{t()}finally{this.matrixStack.restore()}}}withScissor(t,e,i,r,n){this.startScissor(t,e,i,r);try{n()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const i=this.gl;i.stencilMask(e),i.colorMask(!1,!1,!1,!1),i.stencilFunc(i.ALWAYS,t,e),i.stencilOp(i.KEEP,i.KEEP,i.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}endDrawMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(0),this.inCreateMask=!1}clearMask(t=255){this.flush();const e=this.gl;e.stencilMask(t),e.clear(e.STENCIL_BUFFER_BIT),this.inCreateMask=!1}enterMask(t,e=1,i=255){this.flush();const r=this.gl;r.colorMask(!0,!0,!0,!0),r.stencilMask(0),r.stencilFunc(t===0?r.EQUAL:r.NOTEQUAL,e,i),r.stencilOp(r.KEEP,r.KEEP,r.KEEP),this.inCreateMask=!1}exitMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(255),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),this.inCreateMask=!1}setBlendMode(t){this.flush();const e=this.gl;switch(t){case 0:this.premultipliedAlpha?e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 1:e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE);break;case 2:e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 3:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_COLOR,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 4:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE_MINUS_SRC_ALPHA);break}}startScissor(t,e,i,r){this.flush();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);n.enable(n.SCISSOR_TEST),n.scissor(h,c,u,f)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}renderCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new d(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new d(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.mul(this.dpr)}cssToLogic(t){const e=this.cssToDevicePixel(t);return this.physicsToLogic(e)}devicePixelToCss(t){return t.divide(this.dpr)}toCSSMatrix(t){const e=this.physicsWidth/this.dpr/this.logicWidth,i=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,i)}}function de(s){return!(s===null||typeof s!="object"||Array.isArray(s)||s instanceof d||s instanceof m)}class C{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,i,r){return new d(C.float(t,e),C.float(i,r))}static randomColor(t,e){return new m(C.float(t.r,e.r),C.float(t.g,e.g),C.float(t.b,e.b),C.float(t.a,e.a))}static pick(t){return t[C.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,r]of t)e+=r;let i=Math.random()*e;for(const[r,n]of t)if(i-=n,i<=0)return r;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[i,r]=t;if(typeof i=="number")return C.float(i,r);if(i instanceof d)return C.vector(i.x,r.x,i.y,r.y);if(i instanceof m)return C.randomColor(i,r)}return typeof t=="number"?t:t.clone()}}var Gt=(s=>(s.POINT="point",s.CIRCLE="circle",s.RECT="rect",s))(Gt||{});const Ht=10,Vt=0,Yt=!0;class zt{life=0;maxLife;texture;options;position;datas;rapid;constructor(t,e){this.rapid=t,this.options=e,e.texture instanceof L?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={speed:this.processAttribute(e.animation.speed,0),rotation:this.processAttribute(e.animation.rotation,0),scale:this.processAttribute(e.animation.scale,1),color:this.processAttribute(e.animation.color,m.White.clone()),velocity:this.processAttribute(e.animation.velocity,d.ZERO)},this.position=d.ZERO,this.initializePosition()}processAttribute(t,e){if(t==null)return{value:e};if(de(t)){const i=t,r=C.scalarOrRange(i.start,e),n=i.end===void 0?r:C.scalarOrRange(i.end,e);return{delta:i.delta??this.getDelta(r,n,this.maxLife),value:r,damping:i.damping}}else return this.processAttribute({start:t},e)}updateNumberAttribute(t,e){t.damping!==void 0&&(t.value*=Math.pow(t.damping,e)),t.delta!==void 0&&(t.value+=t.delta*e)}updateVec2Attribute(t,e){t.damping!==void 0&&(t.value=t.value.multiply(Math.pow(t.damping,e))),t.delta!==void 0&&(t.value=t.value.add(t.delta.multiply(e)))}updateColorAttribute(t,e){t.damping!==void 0&&(t.value=t.value.multiply(Math.pow(t.damping,e))),t.delta!==void 0&&(t.value=t.value.add(t.delta.multiply(e))),t.value.clamp()}updateAttributes(t){const e=this.datas;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);const r=d.fromAngle(e.rotation.value).multiply(e.speed.value*t);this.position=this.position.add(r).add(e.velocity.value.multiply(t))}getDelta(t,e,i){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}update(t){return this.life+=t,this.life>=this.maxLife?!1:(this.updateAttributes(t),!0)}render(){const t=this.rapid.matrixStack,e=this.datas.scale.value,i=this.datas.rotation.value,r=this.datas.color.value;t.save(),t.translate(this.position.x,this.position.y),i!==0&&t.rotate(i),e!==1&&t.scale(e,e);const n=this.options.origin?this.options.origin.x:.5,a=this.options.origin?this.options.origin.y:.5;(n!==0||a!==0)&&t.translate(-n*this.texture.rawWidth,-a*this.texture.rawHeight),lt(this.rapid,{texture:this.texture,color:r}),t.restore()}initializePosition(){switch(this.options.emitShape){case"circle":{const t=Math.random()*Math.PI*2,e=(this.options.emitRadius??0)*Math.sqrt(Math.random());this.position=new d(Math.cos(t)*e,Math.sin(t)*e);break}case"rect":{this.position=new d((Math.random()-.5)*(this.options.emitRect?.width??0),(Math.random()-.5)*(this.options.emitRect?.height??0));break}default:this.position=d.ZERO;break}!this.options.localSpace&&this.options.position&&(this.position=this.position.add(this.options.position))}}class ft{particles=[];options;emitting=!1;emitTimer=0;emitRate=Ht;emitTime=Vt;emitTimeCounter=0;localSpace=Yt;position=d.ZERO;rapid;gameObject;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate!==void 0?e.emitRate:Ht,this.emitTime=e.emitTime!==void 0?e.emitTime:Vt,this.localSpace=e.localSpace!==void 0?e.localSpace:Yt,this.position=e.position??d.ZERO}setTexture(t){this.options.texture=t}clone(){return new ft(this.rapid,{...this.options})}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){this.particles=[],this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,i=Math.min(t,e-this.particles.length);for(let r=0;r<i;r++)this.particles.push(new zt(this.rapid,{...this.options,position:this.position}))}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const e=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*e),this.emitTimeCounter-=e*this.emitTime}}else{this.emitTimer+=t;const e=Math.floor(this.emitTimer*this.emitRate);e>0&&(this.emit(e),this.emitTimer-=e/this.emitRate)}for(let e=this.particles.length-1;e>=0;e--)this.particles[e].update(t)||this.particles.splice(e,1)}render(){const t=this.rapid.matrixStack;this.localSpace&&(t.save(),t.translate(this.position.x,this.position.y));for(const e of this.particles)e.render();this.localSpace&&t.restore()}getParticleCount(){return this.particles.length}isActive(){return this.emitting||this.particles.length>0}oneShot(){this.emit(this.emitRate)}}x.ArrayType=N,x.BaseTexture=W,x.BlendMode=Bt,x.CanvasScaleMode=kt,x.Color=m,x.CustomGlShader=ot,x.DynamicArrayBuffer=O,x.GLShader=ht,x.GraphicRegion=wt,x.LineTextureMode=bt,x.MAX_INSTANCES=X,x.MaskType=Dt,x.MatrixStack=xt,x.MatrixStore=mt,x.Particle=zt,x.ParticleEmitter=ft,x.ParticleShape=Gt,x.QUAD_VERTICES=Et,x.Rapid=le,x.Region=ct,x.RenderTexture=gt,x.SpriteRegion=tt,x.TextTexture=vt,x.Texture=L,x.TextureFilterMode=rt,x.TextureManager=pt,x.TextureWrapMode=V,x.Vec2=d,x.WebglBufferArray=Z,x.composeProjectionWithAffine=St,x.drawCircle=It,x.drawGraphic=dt,x.drawLine=Pt,x.drawMaskImage=Nt,x.drawParticle=_t,x.drawParticles=Ct,x.drawRect=Lt,x.drawSprite=Ut,x.drawSpriteRaw=lt,x.multiplyMat4=Mt,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})}));
@@ -10,7 +10,7 @@ export declare class ParticleRegion extends SpriteRegion {
10
10
  createDefaultShader(): GLShader;
11
11
  enter(customShader?: GLShader | CustomGlShader): void;
12
12
  createShader(vs: string, fs: string): GLShader;
13
- drawParticle(texture: Texture, x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, u0?: number, v0?: number, u1?: number, v1?: number, color?: number, flipX?: boolean, flipY?: boolean, isRotated?: boolean): void;
14
- drawParticles(texture: Texture, x: Array<number>, y: Array<number>, rotation: Array<number>, color: Array<number>, count: number, scaleX?: number, scaleY?: number, u0?: number, v0?: number, u1?: number, v1?: number, flipX?: boolean, flipY?: boolean, isRotated?: boolean): void;
13
+ drawParticle(texture: Texture, x?: number, y?: number, scaleX?: number, scaleY?: number, rotation?: number, u0?: number, v0?: number, u1?: number, v1?: number, color?: number, flipX?: boolean, flipY?: boolean, isRotated?: boolean, originX?: number, originY?: number): void;
14
+ drawParticles(texture: Texture, x: Array<number>, y: Array<number>, rotation: Array<number>, color: Array<number>, count: number, scaleX?: number, scaleY?: number, u0?: number, v0?: number, u1?: number, v1?: number, flipX?: boolean, flipY?: boolean, isRotated?: boolean, originX?: number, originY?: number): void;
15
15
  render(): void;
16
16
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rapid-render",
3
3
  "private": false,
4
- "version": "1.0.4",
4
+ "version": "1.0.5",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",