rapid-render 1.0.13 → 1.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- var b = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(b || {});
2
- class _ {
1
+ var A = /* @__PURE__ */ ((n) => (n[n.Float32 = 0] = "Float32", n[n.Uint32 = 1] = "Uint32", n[n.Uint16 = 2] = "Uint16", n))(A || {});
2
+ class b {
3
3
  /** The number of elements currently used in the buffer. */
4
4
  usedElemNum;
5
5
  /** The main typed array view corresponding to the specified ArrayType. */
@@ -172,7 +172,7 @@ class _ {
172
172
  this.usedElemNum = 0;
173
173
  }
174
174
  }
175
- class it extends _ {
175
+ class tt extends b {
176
176
  /** The actual WebGLBuffer object maintained by this instance. */
177
177
  buffer;
178
178
  /** The related WebGL rendering context. */
@@ -480,7 +480,7 @@ class x {
480
480
  static TRANSPARENT = new x(0, 0, 0, 0);
481
481
  }
482
482
  const E = 6;
483
- class Ut {
483
+ class Rt {
484
484
  /** Total number of matrices currently allocated in the store. */
485
485
  matrixCount = 0;
486
486
  /** The dynamic buffer used to hold matrix data. */
@@ -493,7 +493,7 @@ class Ut {
493
493
  * @param capacity - The initial capacity of the matrix store (default is 10).
494
494
  */
495
495
  constructor(t = 10) {
496
- this.buffer = new _(b.Float32), this.buffer.resize(t * E), this.data = this.buffer.getArray(), this.reset();
496
+ this.buffer = new b(A.Float32), this.buffer.resize(t * E), this.data = this.buffer.getArray(), this.reset();
497
497
  }
498
498
  /**
499
499
  * Allocates a new matrix and initializes it to the identity matrix.
@@ -596,8 +596,8 @@ class Ut {
596
596
  * @param bIdx - The index of matrix B.
597
597
  */
598
598
  multiplyOut(t, e, r) {
599
- const i = t * E, s = e * E, a = r * E, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a], v = o[a + 1], y = o[a + 2], T = o[a + 3], M = o[a + 4], A = o[a + 5];
600
- o[i] = h * m + u * v, o[i + 1] = c * m + l * v, o[i + 2] = h * y + u * T, o[i + 3] = c * y + l * T, o[i + 4] = h * M + u * A + d, o[i + 5] = c * M + l * A + f;
599
+ const i = t * E, s = e * E, a = r * E, o = this.data, h = o[s], c = o[s + 1], u = o[s + 2], l = o[s + 3], d = o[s + 4], f = o[s + 5], m = o[a], g = o[a + 1], v = o[a + 2], y = o[a + 3], R = o[a + 4], M = o[a + 5];
600
+ o[i] = h * m + u * g, o[i + 1] = c * m + l * g, o[i + 2] = h * v + u * y, o[i + 3] = c * v + l * y, o[i + 4] = h * R + u * M + d, o[i + 5] = c * R + l * M + f;
601
601
  }
602
602
  /**
603
603
  * Inverts the matrix at the given index. If the matrix is not invertible, it defaults to the identity matrix.
@@ -721,29 +721,29 @@ class Ut {
721
721
  i[r] = e[0], i[r + 1] = e[1], i[r + 2] = e[2], i[r + 3] = e[3], i[r + 4] = e[4], i[r + 5] = e[5];
722
722
  }
723
723
  multiplyAffineInPlace(t, e, r, i, s, a, o) {
724
- const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4], v = c[h + 5];
725
- c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o + v;
724
+ const h = t * 6, c = this.data, u = c[h], l = c[h + 1], d = c[h + 2], f = c[h + 3], m = c[h + 4], g = c[h + 5];
725
+ c[h] = u * e + d * r, c[h + 1] = l * e + f * r, c[h + 2] = u * i + d * s, c[h + 3] = l * i + f * s, c[h + 4] = u * a + d * o + m, c[h + 5] = l * a + f * o + g;
726
726
  }
727
727
  multiplyAffine(t, e, r, i, s, a, o, h) {
728
- const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], v = l[c + 3], y = l[c + 4], T = l[c + 5];
729
- l[u] = d * r + m * i, l[u + 1] = f * r + v * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + v * a, l[u + 4] = d * o + m * h + y, l[u + 5] = f * o + v * h + T;
728
+ const c = t * 6, u = e * 6, l = this.data, d = l[c], f = l[c + 1], m = l[c + 2], g = l[c + 3], v = l[c + 4], y = l[c + 5];
729
+ l[u] = d * r + m * i, l[u + 1] = f * r + g * i, l[u + 2] = d * s + m * a, l[u + 3] = f * s + g * a, l[u + 4] = d * o + m * h + v, l[u + 5] = f * o + g * h + y;
730
730
  }
731
731
  }
732
- class Ct {
732
+ class wt {
733
733
  /** The underlying store for matrices. */
734
- matrix = new Ut();
734
+ matrix = new Rt();
735
735
  /** The current step or depth in the transformation hierarchy. */
736
736
  step = 0;
737
737
  /** Internal stack maintaining structural information. */
738
- stack = new _(b.Uint32);
738
+ stack = new b(A.Uint32);
739
739
  /** Records the world matrices generated at each step. */
740
- stepWorldM = new _(b.Uint32);
740
+ stepWorldM = new b(A.Uint32);
741
741
  /** Records actions (push/pop) taken during the traversal. */
742
- stepAction = new _(b.Uint32);
742
+ stepAction = new b(A.Uint32);
743
743
  /** Records the parent world matrix for each step (used by updateMatrixSubtree). */
744
- stepParentM = new _(b.Uint32);
744
+ stepParentM = new b(A.Uint32);
745
745
  /** Buffer used during hierarchy traversal updates. */
746
- parentStack = new _(b.Uint32);
746
+ parentStack = new b(A.Uint32);
747
747
  /** The index of the current local matrix in the matrix store. */
748
748
  curLocalM = -1;
749
749
  /** The index of the current world matrix in the matrix store. */
@@ -919,41 +919,41 @@ class Ct {
919
919
  t.offset && (l += t.offset.x, d += t.offset.y);
920
920
  const f = t.origin;
921
921
  f !== void 0 && (typeof f == "number" ? (l -= f * e, d -= f * r) : (l -= f.x * e, d -= f.y * r));
922
- const m = u ? Math.cos(u) : 1, v = u ? Math.sin(u) : 0, y = m * o, T = v * o, M = -v * h, A = m * h, P = s + y * l + M * d, C = a + T * l + A * d;
922
+ const m = u ? Math.cos(u) : 1, g = u ? Math.sin(u) : 0, v = m * o, y = g * o, R = -g * h, M = m * h, C = s + v * l + R * d, P = a + y * l + M * d;
923
923
  if (i !== -1) {
924
924
  this.matrix.multiplyAffine(
925
925
  this.curWorldM,
926
926
  i,
927
+ v,
927
928
  y,
928
- T,
929
+ R,
929
930
  M,
930
- A,
931
- P,
932
- C
931
+ C,
932
+ P
933
933
  );
934
934
  return;
935
935
  }
936
936
  this.matrix.multiplyAffineInPlace(
937
937
  this.curLocalM,
938
+ v,
938
939
  y,
939
- T,
940
+ R,
940
941
  M,
941
- A,
942
- P,
943
- C
942
+ C,
943
+ P
944
944
  ), this.matrix.multiplyAffineInPlace(
945
945
  this.curWorldM,
946
+ v,
946
947
  y,
947
- T,
948
+ R,
948
949
  M,
949
- A,
950
- P,
951
- C
950
+ C,
951
+ P
952
952
  );
953
953
  }
954
954
  }
955
- var Q = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(Q || {});
956
- class _t {
955
+ var K = /* @__PURE__ */ ((n) => (n[n.REPEAT = 0] = "REPEAT", n[n.CLAMP = 1] = "CLAMP", n[n.MIRRORED_REPEAT = 2] = "MIRRORED_REPEAT", n))(K || {});
956
+ class Mt {
957
957
  render;
958
958
  cache = /* @__PURE__ */ new Map();
959
959
  constructor(t) {
@@ -968,10 +968,10 @@ class _t {
968
968
  async load(t, e) {
969
969
  let r = this.cache.get(t);
970
970
  if (r)
971
- return new O(r);
971
+ return new N(r);
972
972
  try {
973
973
  const i = await this._fetchImage(t);
974
- return r = z.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new O(r);
974
+ return r = Y.fromSource(this.render, i, e), r.uid = t, this.cache.set(t, r), new N(r);
975
975
  } catch (i) {
976
976
  throw console.error(`[TextureManager] Failed to load: ${t}`, i), i;
977
977
  }
@@ -984,9 +984,9 @@ class _t {
984
984
  */
985
985
  create(t, e) {
986
986
  if (e?.key && this.cache.has(e.key))
987
- return new O(this.cache.get(e.key));
988
- const r = z.fromSource(this.render, t, e);
989
- return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new O(r);
987
+ return new N(this.cache.get(e.key));
988
+ const r = Y.fromSource(this.render, t, e);
989
+ return e?.key && (r.uid = e.key, this.cache.set(e.key, r)), new N(r);
990
990
  }
991
991
  /**
992
992
  * Creates a generic Render Texture (FrameBuffer).
@@ -996,7 +996,7 @@ class _t {
996
996
  * @returns The newly created RenderTexture.
997
997
  */
998
998
  createRenderTexture(t) {
999
- return new Pt(this.render, t);
999
+ return new At(this.render, t);
1000
1000
  }
1001
1001
  /**
1002
1002
  * Creates a TextTexture for rendering text.
@@ -1004,7 +1004,7 @@ class _t {
1004
1004
  * @returns The newly created TextTexture.
1005
1005
  */
1006
1006
  createTextTexture(t) {
1007
- return new Lt(this.render, t);
1007
+ return new bt(this.render, t);
1008
1008
  }
1009
1009
  /**
1010
1010
  * Destroys a texture and potentially removes its BaseTexture from the cache.
@@ -1015,7 +1015,7 @@ class _t {
1015
1015
  */
1016
1016
  destroy(t, e = !1) {
1017
1017
  let r, i;
1018
- typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof O ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
1018
+ typeof t == "string" ? (i = t, r = this.cache.get(i)) : t instanceof N ? (r = t.base, i = r?.uid, t.destroy()) : (r = t, i = r.uid), r && (r.refCount <= 0 || e) && (r.destroy(this.render.gl), i && this.cache.delete(i));
1019
1019
  }
1020
1020
  /**
1021
1021
  * Destroys all cached textures and clears the cache, ignoring reference counts.
@@ -1032,7 +1032,7 @@ class _t {
1032
1032
  });
1033
1033
  }
1034
1034
  }
1035
- class z {
1035
+ class Y {
1036
1036
  glTexture = null;
1037
1037
  width;
1038
1038
  height;
@@ -1049,8 +1049,8 @@ class z {
1049
1049
  * @returns The created BaseTexture.
1050
1050
  */
1051
1051
  static fromSource(t, e, r = {}) {
1052
- const i = et(t, e, r);
1053
- return new z(i, e.width, e.height);
1052
+ const i = Z(t, e, r);
1053
+ return new Y(i, e.width, e.height);
1054
1054
  }
1055
1055
  /**
1056
1056
  * Updates the content of the existing texture (e.g. for Video or dynamic Canvas).
@@ -1059,19 +1059,19 @@ class z {
1059
1059
  * @param source - The new image source.
1060
1060
  */
1061
1061
  updateSource(t, e, r = {}) {
1062
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && nt(t, r.textureFilter), r.wrap !== void 0 && st(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1062
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), r.textureFilter !== void 0 && rt(t, r.textureFilter), r.wrap !== void 0 && et(t, r.wrap), t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL, 1), t.pixelStorei(t.UNPACK_ALIGNMENT, 1), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r.premultipliedAlpha), this.width === e.width && this.height === e.height ? t.texSubImage2D(t.TEXTURE_2D, 0, 0, 0, t.RGBA, t.UNSIGNED_BYTE, e) : (t.texImage2D(t.TEXTURE_2D, 0, t.RGBA, t.RGBA, t.UNSIGNED_BYTE, e), this.width = e.width, this.height = e.height), r.premultipliedAlpha !== void 0 && t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1));
1063
1063
  }
1064
1064
  /**
1065
1065
  * Dynamically updates the texture filtering mode.
1066
1066
  */
1067
1067
  setFilterMode(t, e) {
1068
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), nt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1068
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), rt(t, e), t.bindTexture(t.TEXTURE_2D, null));
1069
1069
  }
1070
1070
  /**
1071
1071
  * Dynamically updates the texture wrap mode.
1072
1072
  */
1073
1073
  setWrapMode(t, e) {
1074
- this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), st(t, e), t.bindTexture(t.TEXTURE_2D, null));
1074
+ this.glTexture && (t.bindTexture(t.TEXTURE_2D, this.glTexture), et(t, e), t.bindTexture(t.TEXTURE_2D, null));
1075
1075
  }
1076
1076
  /**
1077
1077
  * Destroys the WebGL texture resource.
@@ -1081,7 +1081,7 @@ class z {
1081
1081
  this.glTexture && (t.deleteTexture(this.glTexture), this.glTexture = null);
1082
1082
  }
1083
1083
  }
1084
- class O {
1084
+ class N {
1085
1085
  base;
1086
1086
  uvX = 0;
1087
1087
  uvY = 0;
@@ -1097,10 +1097,10 @@ class O {
1097
1097
  isRotated = !1;
1098
1098
  glTexture = null;
1099
1099
  get width() {
1100
- return (this.isRotated ? this.rawHeight : this.rawWidth) * this.scale;
1100
+ return this.isRotated ? this.rawHeight : this.rawWidth;
1101
1101
  }
1102
1102
  get height() {
1103
- return (this.isRotated ? this.rawWidth : this.rawHeight) * this.scale;
1103
+ return this.isRotated ? this.rawWidth : this.rawHeight;
1104
1104
  }
1105
1105
  // Stored pixel-space region (before UV conversion), used by getSubTexture()
1106
1106
  _px = 0;
@@ -1138,7 +1138,7 @@ class O {
1138
1138
  * @returns A new Texture pointing to the sub-region.
1139
1139
  */
1140
1140
  getSubTexture(t, e, r, i) {
1141
- if (!this.base) return new O();
1141
+ if (!this.base) return new N();
1142
1142
  const s = this.clone(), a = this._px, o = this._py;
1143
1143
  return s.setRegion(a + t, o + e, r, i), s;
1144
1144
  }
@@ -1147,7 +1147,7 @@ class O {
1147
1147
  * @returns A new Texture instance.
1148
1148
  */
1149
1149
  clone(t) {
1150
- const e = t ?? new O(this.base);
1150
+ const e = t ?? new N(this.base);
1151
1151
  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;
1152
1152
  }
1153
1153
  /**
@@ -1164,8 +1164,8 @@ class O {
1164
1164
  if (!this.base) return [];
1165
1165
  const a = [], o = this.rawWidth, h = this.rawHeight, c = Math.max(0, s), u = t + c, l = e + c, d = r ?? Math.floor((o + c) / u), f = i ?? Math.floor((h + c) / l);
1166
1166
  for (let m = 0; m < f; m++)
1167
- for (let v = 0; v < d; v++)
1168
- a.push(this.getSubTexture(v * u, m * l, t, e));
1167
+ for (let g = 0; g < d; g++)
1168
+ a.push(this.getSubTexture(g * u, m * l, t, e));
1169
1169
  return a;
1170
1170
  }
1171
1171
  /**
@@ -1174,8 +1174,8 @@ class O {
1174
1174
  * @param options - Optional antialias and wrap mode settings.
1175
1175
  */
1176
1176
  static fromImageSource(t, e, r = {}) {
1177
- const i = et(t, e, r);
1178
- return new O(new z(i, e.width, e.height));
1177
+ const i = Z(t, e, r);
1178
+ return new N(new Y(i, e.width, e.height));
1179
1179
  }
1180
1180
  /**
1181
1181
  * Marks this Texture as destroyed, decrementing the BaseTexture reference count.
@@ -1184,7 +1184,7 @@ class O {
1184
1184
  this.base && (this.base.refCount--, this.base = void 0), this.glTexture = null;
1185
1185
  }
1186
1186
  }
1187
- class Pt extends O {
1187
+ class At extends N {
1188
1188
  framebuffer;
1189
1189
  renderbuffer;
1190
1190
  gl;
@@ -1195,8 +1195,8 @@ class Pt extends O {
1195
1195
  _allocH = 0;
1196
1196
  constructor(t, e) {
1197
1197
  super(), this.gl = t.gl, this.clearColor = e.clearColor ?? x.Black;
1198
- const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = et(t, { width: r, height: i }, { ...e, onlySize: !0 });
1199
- if (this.setBase(new z(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1198
+ const r = Math.max(Math.round(e.width), 1), i = Math.max(Math.round(e.height), 1), a = Z(t, { width: r, height: i }, { ...e, onlySize: !0 });
1199
+ if (this.setBase(new Y(a, r, i)), this.framebuffer = this.gl.createFramebuffer(), this.renderbuffer = this.gl.createRenderbuffer(), !this.framebuffer || !this.renderbuffer)
1200
1200
  throw new Error("Failed to create Framebuffer or Renderbuffer");
1201
1201
  this.resize(r, i, !0);
1202
1202
  }
@@ -1274,7 +1274,7 @@ class Pt extends O {
1274
1274
  super.destroy(), this.framebuffer && this.gl.deleteFramebuffer(this.framebuffer), this.renderbuffer && this.gl.deleteRenderbuffer(this.renderbuffer), this.base?.destroy(this.gl);
1275
1275
  }
1276
1276
  }
1277
- const Nt = {
1277
+ const St = {
1278
1278
  fontFamily: "Arial",
1279
1279
  fontSize: 24,
1280
1280
  fontWeight: "normal",
@@ -1283,7 +1283,7 @@ const Nt = {
1283
1283
  align: "left",
1284
1284
  lineHeight: 1
1285
1285
  };
1286
- class Lt extends O {
1286
+ class bt extends N {
1287
1287
  canvas;
1288
1288
  ctx;
1289
1289
  render;
@@ -1292,12 +1292,12 @@ class Lt extends O {
1292
1292
  options;
1293
1293
  flipY = !0;
1294
1294
  constructor(t, e) {
1295
- super(), this.render = t, this._style = { ...Nt, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1295
+ super(), this.render = t, this._style = { ...St, ...e }, this._text = e?.text ?? "", this.options = { premultipliedAlpha: t.premultipliedAlpha, ...e }, this.scale = 1 / t.dpr, this.canvas = document.createElement("canvas");
1296
1296
  const r = this.canvas.getContext("2d", { willReadFrequently: !0 });
1297
1297
  if (!r) throw new Error("Failed to get 2d context for TextTexture");
1298
1298
  this.ctx = r, this.canvas.width = 1, this.canvas.height = 1;
1299
- const i = et(t, this.canvas, this.options);
1300
- this.setBase(new z(i, 1, 1)), this.update();
1299
+ const i = Z(t, this.canvas, this.options);
1300
+ this.setBase(new Y(i, 1, 1)), this.update();
1301
1301
  }
1302
1302
  get text() {
1303
1303
  return this._text;
@@ -1337,27 +1337,27 @@ class Lt extends O {
1337
1337
  `);
1338
1338
  let u = 0, l = 0;
1339
1339
  const d = t.measureText(c[0] || "M"), f = (d.fontBoundingBoxAscent || r) + (d.fontBoundingBoxDescent || r * 0.2);
1340
- for (const W of c) {
1341
- const N = t.measureText(W);
1342
- N.width > u && (u = N.width), l += f * a;
1340
+ for (const O of c) {
1341
+ const _ = t.measureText(O);
1342
+ _.width > u && (u = _.width), l += f * a;
1343
1343
  }
1344
1344
  l -= f * (a - 1);
1345
- const m = this._style.strokeThickness || 0, v = Math.ceil(u + m * 2) || 1, y = Math.ceil(l + m * 2) || 1, T = Math.ceil(v * h), M = Math.ceil(y * h);
1346
- (this.canvas.width !== T || this.canvas.height !== M) && (this.canvas.width = T, this.canvas.height = M), t.setTransform(h, 0, 0, h, 0, 0), t.clearRect(0, 0, v, y), t.font = o, t.textBaseline = "top", t.textAlign = this._style.align;
1347
- const A = this.updateOffset(v, m), P = e.strokeThickness, C = P > 0;
1348
- C && (t.lineWidth = P, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
1349
- let F = m;
1350
- for (const W of c)
1351
- C && t.strokeText(W, A, F), e.fill && t.fillText(W, A, F), F += f * a;
1352
- this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, T, M);
1345
+ const m = this._style.strokeThickness || 0, g = Math.ceil(u + m * 2) || 1, v = Math.ceil(l + m * 2) || 1, y = Math.ceil(g * h), R = Math.ceil(v * h);
1346
+ (this.canvas.width !== y || this.canvas.height !== R) && (this.canvas.width = y, this.canvas.height = R), t.setTransform(h, 0, 0, h, 0, 0), t.clearRect(0, 0, g, v), t.font = o, t.textBaseline = "top", t.textAlign = this._style.align;
1347
+ const M = this.updateOffset(g, m), C = e.strokeThickness, P = C > 0;
1348
+ P && (t.lineWidth = C, t.strokeStyle = e.stroke, t.lineJoin = "round"), e.fill && (t.fillStyle = e.fill);
1349
+ let I = m;
1350
+ for (const O of c)
1351
+ P && t.strokeText(O, M, I), e.fill && t.fillText(O, M, I), I += f * a;
1352
+ this.base?.updateSource(this.render.gl, this.canvas, this.options), this.setRegion(0, 0, y, R);
1353
1353
  }
1354
1354
  }
1355
- const It = (n, t = !1, e = !0) => {
1355
+ const Ut = (n, t = !1, e = !0) => {
1356
1356
  const r = n.getContext("webgl2", { stencil: !0, antialias: t, premultipliedAlpha: e });
1357
1357
  if (!r)
1358
1358
  throw new Error("WebGL2 is not supported in this browser.");
1359
1359
  return r;
1360
- }, dt = (n, t, e) => {
1360
+ }, at = (n, t, e) => {
1361
1361
  const r = n.createShader(e);
1362
1362
  if (!r)
1363
1363
  throw new Error("Unable to create webgl shader");
@@ -1366,8 +1366,8 @@ const It = (n, t = !1, e = !0) => {
1366
1366
  throw console.error("Shader compilation failed:", s), new Error("Unable to compile shader: " + s + t);
1367
1367
  }
1368
1368
  return r;
1369
- }, Ot = (n, t, e) => {
1370
- var r = n.createProgram(), i = dt(n, t, 35633), s = dt(n, e, 35632);
1369
+ }, Ct = (n, t, e) => {
1370
+ var r = n.createProgram(), i = at(n, t, 35633), s = at(n, e, 35632);
1371
1371
  if (!r)
1372
1372
  throw new Error("Unable to create program shader");
1373
1373
  if (n.attachShader(r, i), n.attachShader(r, s), n.linkProgram(r), !n.getProgramParameter(r, n.LINK_STATUS)) {
@@ -1376,26 +1376,26 @@ const It = (n, t = !1, e = !0) => {
1376
1376
  }
1377
1377
  return r;
1378
1378
  };
1379
- function st(n, t) {
1379
+ function et(n, t) {
1380
1380
  const e = {
1381
- [Q.CLAMP]: n.CLAMP_TO_EDGE,
1382
- [Q.REPEAT]: n.REPEAT,
1383
- [Q.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
1381
+ [K.CLAMP]: n.CLAMP_TO_EDGE,
1382
+ [K.REPEAT]: n.REPEAT,
1383
+ [K.MIRRORED_REPEAT]: n.MIRRORED_REPEAT
1384
1384
  }[t] || n.CLAMP_TO_EDGE;
1385
1385
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_S, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_WRAP_T, e);
1386
1386
  }
1387
- function nt(n, t) {
1387
+ function rt(n, t) {
1388
1388
  const e = {
1389
- [ht.LINEAR]: n.LINEAR,
1390
- [ht.NEAREST]: n.NEAREST
1389
+ [st.LINEAR]: n.LINEAR,
1390
+ [st.NEAREST]: n.NEAREST
1391
1391
  }[t] ?? n.NEAREST;
1392
1392
  n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MIN_FILTER, e), n.texParameteri(n.TEXTURE_2D, n.TEXTURE_MAG_FILTER, e);
1393
1393
  }
1394
- function et(n, t, e) {
1394
+ function Z(n, t, e) {
1395
1395
  const r = n.gl, i = r.createTexture();
1396
1396
  if (!i)
1397
1397
  throw new Error("Unable to create WebGL texture");
1398
- if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), st(r, e.wrap ?? Q.CLAMP), nt(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
1398
+ if (r.bindTexture(r.TEXTURE_2D, i), r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL, 0), r.pixelStorei(r.UNPACK_ALIGNMENT, 1), et(r, e.wrap ?? K.CLAMP), rt(r, e.textureFilter ?? n.textureFilter), e.onlySize) {
1399
1399
  const s = t;
1400
1400
  r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, s.width, s.height, 0, r.RGBA, r.UNSIGNED_BYTE, null);
1401
1401
  } else {
@@ -1404,7 +1404,7 @@ function et(n, t, e) {
1404
1404
  }
1405
1405
  return r.bindTexture(r.TEXTURE_2D, null), i;
1406
1406
  }
1407
- function V(n, t) {
1407
+ function H(n, t) {
1408
1408
  if (n.includes("%TEXTURE_NUM%") && (n = n.replace("%TEXTURE_NUM%", t.toString())), n.includes("%GET_COLOR%")) {
1409
1409
  let e = "";
1410
1410
  for (let r = 0; r < t; r++)
@@ -1413,15 +1413,15 @@ function V(n, t) {
1413
1413
  }
1414
1414
  return n;
1415
1415
  }
1416
- const Ft = 5126, at = 5121;
1417
- function Wt(n, t, e) {
1416
+ const _t = 5126, it = 5121;
1417
+ function Pt(n, t, e) {
1418
1418
  n.vertexAttribDivisor(t, e);
1419
1419
  }
1420
- function Mt(n, t, e, r, i) {
1420
+ function pt(n, t, e, r, i) {
1421
1421
  n.drawArraysInstanced(t, e, r, i);
1422
1422
  }
1423
- let Bt = 0;
1424
- class wt {
1423
+ let Lt = 0;
1424
+ class gt {
1425
1425
  program;
1426
1426
  attributeLoc = {};
1427
1427
  uniformLoc = {};
@@ -1433,11 +1433,11 @@ class wt {
1433
1433
  /** Whether the uniform is an array (e.g. sampler2D uTextures[8]) */
1434
1434
  uniformIsArray = {};
1435
1435
  gl;
1436
- shaderId = Bt++;
1436
+ shaderId = Lt++;
1437
1437
  // for debug
1438
1438
  vao;
1439
1439
  constructor(t, e, r, i) {
1440
- this.gl = t, this.program = Ot(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
1440
+ this.gl = t, this.program = Ct(t, e, r), this.parseShader(e), this.parseShader(r), this.vao = t.createVertexArray(), i && this.setAttributes(i);
1441
1441
  }
1442
1442
  /** Switch GPU to use this shader program */
1443
1443
  use() {
@@ -1463,7 +1463,7 @@ class wt {
1463
1463
  const r = this.uniformLoc[t];
1464
1464
  if (r === void 0) return;
1465
1465
  const i = this.uniformType[t], s = this.uniformIsArray[t];
1466
- Dt(this.gl, r, i, e, s);
1466
+ Nt(this.gl, r, i, e, s);
1467
1467
  }
1468
1468
  /**
1469
1469
  * Batch-set uniforms via a plain value map.
@@ -1490,11 +1490,11 @@ class wt {
1490
1490
  r.vertexAttribPointer(
1491
1491
  e,
1492
1492
  t.size,
1493
- t.type ?? Ft,
1493
+ t.type ?? _t,
1494
1494
  t.normalized ?? !1,
1495
1495
  t.stride,
1496
1496
  t.offset ?? 0
1497
- ), r.enableVertexAttribArray(e), Wt(r, e, t.divisor ?? 0);
1497
+ ), r.enableVertexAttribArray(e), Pt(r, e, t.divisor ?? 0);
1498
1498
  }
1499
1499
  /** Bind all vertex attribute pointers at once */
1500
1500
  setAttributes(t) {
@@ -1514,15 +1514,16 @@ class wt {
1514
1514
  const o = s.split(/\s+/)[2], h = e.getAttribLocation(this.program, o);
1515
1515
  h !== -1 && (this.attributeLoc[o] = h);
1516
1516
  }
1517
- const i = t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);
1518
- if (i)
1519
- for (const s of i) {
1520
- const a = s.split(/\s+/), o = a[1], h = a[2].replace(/\[\d+\]$/, ""), c = e.getUniformLocation(this.program, h);
1521
- c !== null && (this.uniformLoc[h] = c, this.uniformType[h] = o, this.uniformIsArray[h] = /\[\d+\]$/.test(a[2]));
1522
- }
1517
+ const i = t.matchAll(
1518
+ /uniform\s+(?:(?:lowp|mediump|highp)\s+)?(\w+)\s+(\w+)(\s*\[\s*\d+\s*\])?/g
1519
+ );
1520
+ for (const s of i) {
1521
+ const a = s[1], o = s[2], h = e.getUniformLocation(this.program, o);
1522
+ h !== null && (this.uniformLoc[o] = h, this.uniformType[o] = a, this.uniformIsArray[o] = s[3] !== void 0);
1523
+ }
1523
1524
  }
1524
1525
  }
1525
- function Dt(n, t, e, r, i = !1) {
1526
+ function Nt(n, t, e, r, i = !1) {
1526
1527
  switch (e) {
1527
1528
  // scalars
1528
1529
  case "float":
@@ -1558,10 +1559,10 @@ function Dt(n, t, e, r, i = !1) {
1558
1559
  return n.uniformMatrix4fv(t, !1, r);
1559
1560
  // fallback: guess by value shape
1560
1561
  default:
1561
- return kt(n, t, r);
1562
+ return It(n, t, r);
1562
1563
  }
1563
1564
  }
1564
- function kt(n, t, e) {
1565
+ function It(n, t, e) {
1565
1566
  if (typeof e == "number")
1566
1567
  return n.uniform1f(t, e);
1567
1568
  const r = e;
@@ -1580,7 +1581,7 @@ function kt(n, t, e) {
1580
1581
  return n.uniform1fv(t, r);
1581
1582
  }
1582
1583
  }
1583
- class ft {
1584
+ class ht {
1584
1585
  /** Custom vertex shader code */
1585
1586
  vs;
1586
1587
  /** Custom fragment shader code */
@@ -1655,7 +1656,7 @@ class ft {
1655
1656
  this.glshader.forEach((t) => t.destroy());
1656
1657
  }
1657
1658
  }
1658
- class At {
1659
+ class vt {
1659
1660
  constructor(t) {
1660
1661
  this.rapid = t, this.gl = t.gl, this.maxTextureUnits = t.maxTextureUnits, this.matrixStore = t.matrix;
1661
1662
  }
@@ -1698,7 +1699,7 @@ class At {
1698
1699
  return i == -1 ? (this.freeTextureUnitNum === 0 && this.flush(), this.usedTextures.push(t), this.usedTexturePadding.push(e), this.usedTexturePadding.push(r), this.usedTextures.length - 1) : i;
1699
1700
  }
1700
1701
  createShader(t, e) {
1701
- return new wt(this.gl, t, e);
1702
+ return new gt(this.gl, t, e);
1702
1703
  }
1703
1704
  createCustomShader(t) {
1704
1705
  return t.getGLShader(this, this.KEY, this.vs, this.fs);
@@ -1706,7 +1707,7 @@ class At {
1706
1707
  getCustomShader(t) {
1707
1708
  if (!t)
1708
1709
  return this.defaultShader;
1709
- if (t instanceof ft) {
1710
+ if (t instanceof ht) {
1710
1711
  const e = this.createCustomShader(t);
1711
1712
  return e ?? this.defaultShader;
1712
1713
  }
@@ -1721,7 +1722,7 @@ class At {
1721
1722
  return this.isDefaultShader && !t ? !0 : this.getCustomShader(t) == this.currentShader;
1722
1723
  }
1723
1724
  enter(t) {
1724
- this.resetRender(), this.currentShader = this.getCustomShader(t), t instanceof ft ? (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);
1725
+ 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);
1725
1726
  }
1726
1727
  exit() {
1727
1728
  this.hasPendingContent() && this.flush(), this.gl.bindVertexArray(null);
@@ -1758,7 +1759,7 @@ class At {
1758
1759
  return !1;
1759
1760
  }
1760
1761
  }
1761
- const tt = `#version 300 es\r
1762
+ const Q = `#version 300 es\r
1762
1763
  precision highp float;\r
1763
1764
  \r
1764
1765
  // per-vertex\r
@@ -1806,7 +1807,7 @@ void main(void) {\r
1806
1807
  \r
1807
1808
  gl_Position = u_projection * position;\r
1808
1809
  }\r
1809
- `, mt = `#version 300 es\r
1810
+ `, ot = `#version 300 es\r
1810
1811
  precision mediump float;\r
1811
1812
  \r
1812
1813
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -1855,8 +1856,8 @@ void main(void) {\r
1855
1856
  \r
1856
1857
  // CUSTOM_CODE_CALL\r
1857
1858
  }\r
1858
- `, $ = 48, Gt = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1859
- class ot extends At {
1859
+ `, z = 48, Ot = new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);
1860
+ class nt extends vt {
1860
1861
  instanceBuffer;
1861
1862
  quadBuffer;
1862
1863
  instanceCount = 0;
@@ -1868,28 +1869,28 @@ class ot extends At {
1868
1869
  }
1869
1870
  createBuffer() {
1870
1871
  const t = this.gl;
1871
- this.quadBuffer = new it(t, b.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1872
- for (const e of Gt) this.quadBuffer.pushFloat32(e);
1873
- this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new it(t, b.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1872
+ this.quadBuffer = new tt(t, A.Float32, t.ARRAY_BUFFER, t.STATIC_DRAW), this.quadBuffer.bindBuffer();
1873
+ for (const e of Ot) this.quadBuffer.pushFloat32(e);
1874
+ this.quadBuffer.makeDirty(), this.quadBuffer.bufferData(), this.instanceBuffer = new tt(t, A.Uint32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW);
1874
1875
  }
1875
1876
  createDefaultShader() {
1876
- const t = this.rapid, e = V(mt, t.maxTextureUnits), r = V(tt, t.maxTextureUnits);
1877
+ const t = this.rapid, e = H(ot, t.maxTextureUnits), r = H(Q, t.maxTextureUnits);
1877
1878
  return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
1878
1879
  }
1879
1880
  createShader(t, e) {
1880
1881
  const r = super.createShader(t, e);
1881
1882
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
1882
- { name: "aMatrixRow0", size: 3, stride: $, offset: 0, divisor: 1 },
1883
- { name: "aMatrixRow1", size: 3, stride: $, offset: 12, divisor: 1 },
1884
- { name: "aUVRect", size: 4, stride: $, offset: 24, divisor: 1 },
1885
- { name: "aColor", size: 4, type: at, normalized: !0, stride: $, offset: 40, divisor: 1 },
1886
- { name: "aTextureId", size: 1, type: at, stride: $, offset: 44, divisor: 1 }
1883
+ { name: "aMatrixRow0", size: 3, stride: z, offset: 0, divisor: 1 },
1884
+ { name: "aMatrixRow1", size: 3, stride: z, offset: 12, divisor: 1 },
1885
+ { name: "aUVRect", size: 4, stride: z, offset: 24, divisor: 1 },
1886
+ { name: "aColor", size: 4, type: it, normalized: !0, stride: z, offset: 40, divisor: 1 },
1887
+ { name: "aTextureId", size: 1, type: it, stride: z, offset: 44, divisor: 1 }
1887
1888
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
1888
1889
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
1889
1890
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
1890
1891
  }
1891
1892
  createCustomShader(t) {
1892
- const e = V(mt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(tt, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1893
+ const e = H(ot, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = H(Q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
1893
1894
  return t.getGLShader(this, this.KEY, r, e);
1894
1895
  }
1895
1896
  /**
@@ -1926,23 +1927,23 @@ class ot extends At {
1926
1927
  d
1927
1928
  );
1928
1929
  }
1929
- drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, v = !1, y = !1, T = !1) {
1930
- const M = t.base, A = t.rawWidth, P = t.rawHeight, C = t.offsetX, F = t.offsetY, W = this.useTexture(
1930
+ drawSpriteAffine(t, e, r, i, s, a, o, h = 0, c = 0, u = 1, l = 1, d = 4294967295, f = 0, m = 0, g = !1, v = !1, y = !1) {
1931
+ const R = t.base, M = t.rawWidth, C = t.rawHeight, P = t.offsetX, I = t.offsetY, O = this.useTexture(
1931
1932
  t.glTexture,
1932
- f / M.width,
1933
- m / M.height
1934
- ), N = this.instanceBuffer, w = N.usedElemNum;
1935
- N.resize(12);
1936
- const U = N.float32, X = N.uint32, k = T ? P : A, G = T ? A : P, I = k + 2 * f, B = G + 2 * m, H = C - f, R = F - m, g = this.localSpriteMatrix;
1937
- T ? (g[0] = 0, g[1] = y ? B : -B, g[2] = v ? -I : I, g[3] = 0, g[4] = H + (v ? I : 0), g[5] = R + (y ? 0 : B)) : (g[0] = v ? -I : I, g[1] = 0, g[2] = 0, g[3] = y ? -B : B, g[4] = H + (v ? I : 0), g[5] = R + (y ? B : 0));
1933
+ f / R.width,
1934
+ m / R.height
1935
+ ), _ = this.instanceBuffer, w = _.usedElemNum;
1936
+ _.resize(12);
1937
+ const U = _.float32, B = _.uint32, D = y ? C : M, G = y ? M : C, F = D + 2 * f, k = G + 2 * m, X = P - f, W = I - m, T = this.localSpriteMatrix;
1938
+ y ? (T[0] = 0, T[1] = v ? k : -k, T[2] = g ? -F : F, T[3] = 0, T[4] = X + (g ? F : 0), T[5] = W + (v ? 0 : k)) : (T[0] = g ? -F : F, T[1] = 0, T[2] = 0, T[3] = v ? -k : k, T[4] = X + (g ? F : 0), T[5] = W + (v ? k : 0));
1938
1939
  const S = this.worldSpriteMatrix;
1939
- S[0] = e * g[0] + i * g[1], S[1] = r * g[0] + s * g[1], S[2] = e * g[2] + i * g[3], S[3] = r * g[2] + s * g[3], S[4] = a + e * g[4] + i * g[5], S[5] = o + r * g[4] + s * g[5], U[w + 6] = h, U[w + 7] = c, U[w + 8] = u, U[w + 9] = l, X[w + 10] = d, X[w + 11] = W, this.rapid.roundPixels && (S[4] = Math.round(S[4]), S[5] = Math.round(S[5])), U[w] = S[0], U[w + 1] = S[2], U[w + 2] = S[4], U[w + 3] = S[1], U[w + 4] = S[3], U[w + 5] = S[5], N.usedElemNum += 12, N.makeDirty(), this.instanceCount++;
1940
+ S[0] = e * T[0] + i * T[1], S[1] = r * T[0] + s * T[1], S[2] = e * T[2] + i * T[3], S[3] = r * T[2] + s * T[3], S[4] = a + e * T[4] + i * T[5], S[5] = o + r * T[4] + s * T[5], U[w + 6] = h, U[w + 7] = c, U[w + 8] = u, U[w + 9] = l, B[w + 10] = d, B[w + 11] = O, this.rapid.roundPixels && (S[4] = Math.round(S[4]), S[5] = Math.round(S[5])), U[w] = S[0], U[w + 1] = S[2], U[w + 2] = S[4], U[w + 3] = S[1], U[w + 4] = S[3], U[w + 5] = S[5], _.usedElemNum += 12, _.makeDirty(), this.instanceCount++;
1940
1941
  }
1941
1942
  render() {
1942
1943
  if (this.instanceCount === 0) return;
1943
1944
  this.prepareRender();
1944
1945
  const t = this.gl, e = this.currentShader;
1945
- this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), Mt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1946
+ this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO(), pt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++;
1946
1947
  }
1947
1948
  resetRender() {
1948
1949
  super.resetRender(), this.instanceBuffer.clear(), this.instanceCount = 0;
@@ -1951,7 +1952,7 @@ class ot extends At {
1951
1952
  return this.instanceCount > 0;
1952
1953
  }
1953
1954
  }
1954
- const Ht = `#version 300 es\r
1955
+ const Ft = `#version 300 es\r
1955
1956
  precision highp float;\r
1956
1957
  \r
1957
1958
  in vec2 aPosition;\r
@@ -1982,7 +1983,7 @@ void main(void) {\r
1982
1983
  // CUSTOM_CODE_CALL\r
1983
1984
  gl_Position = u_projection * position;\r
1984
1985
  }\r
1985
- `, Vt = `#version 300 es\r
1986
+ `, Wt = `#version 300 es\r
1986
1987
  precision mediump float;\r
1987
1988
  \r
1988
1989
  in vec4 vColor;\r
@@ -2028,7 +2029,7 @@ void main(void) {\r
2028
2029
  fragColor = sampleTexture(vRegion) * vColor;\r
2029
2030
  // CUSTOM_CODE_CALL\r
2030
2031
  }\r
2031
- `, Yt = `#version 300 es\r
2032
+ `, Bt = `#version 300 es\r
2032
2033
  precision highp float;\r
2033
2034
  \r
2034
2035
  in vec2 aPosition;\r
@@ -2051,7 +2052,7 @@ void main(void) {\r
2051
2052
  );\r
2052
2053
  gl_Position = u_projection * position;\r
2053
2054
  }\r
2054
- `, zt = `#version 300 es\r
2055
+ `, Dt = `#version 300 es\r
2055
2056
  precision mediump float;\r
2056
2057
  \r
2057
2058
  in vec2 vRegion;\r
@@ -2071,8 +2072,8 @@ void main(void) {\r
2071
2072
  discard;\r
2072
2073
  }\r
2073
2074
  }\r
2074
- `, K = 20;
2075
- class Xt extends At {
2075
+ `, $ = 20;
2076
+ class kt extends vt {
2076
2077
  vertexBuffer;
2077
2078
  vertexCount = 0;
2078
2079
  matrixIndex = -1;
@@ -2085,24 +2086,24 @@ class Xt extends At {
2085
2086
  }
2086
2087
  createBuffer() {
2087
2088
  const t = this.gl;
2088
- this.vertexBuffer = new it(t, b.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Yt, zt);
2089
+ this.vertexBuffer = new tt(t, A.Float32, t.ARRAY_BUFFER, t.DYNAMIC_DRAW), this.maskShader = this.createMaskShader(Bt, Dt);
2089
2090
  }
2090
2091
  createDefaultShader() {
2091
- return this.vs = Ht, this.fs = Vt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2092
+ return this.vs = Ft, this.fs = Wt, this.defaultShader = this.createShader(this.vs, this.fs), this.defaultShader;
2092
2093
  }
2093
2094
  createMaskShader(t, e) {
2094
- const r = this.gl, i = new wt(r, t, e);
2095
+ const r = this.gl, i = new gt(r, t, e);
2095
2096
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
2096
- { name: "aPosition", size: 2, type: r.FLOAT, stride: K - 4, offset: 0, divisor: 0 },
2097
- { name: "aUV", size: 2, type: r.FLOAT, stride: K - 4, offset: 8, divisor: 0 }
2097
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $ - 4, offset: 0, divisor: 0 },
2098
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $ - 4, offset: 8, divisor: 0 }
2098
2099
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2099
2100
  }
2100
2101
  createShader(t, e) {
2101
2102
  const r = this.gl, i = super.createShader(t, e);
2102
2103
  return i.use(), i.bindVAO(), this.vertexBuffer.bindBuffer(), i.setAttributes([
2103
- { name: "aPosition", size: 2, type: r.FLOAT, stride: K, offset: 0, divisor: 0 },
2104
- { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: K, offset: 8, divisor: 0 },
2105
- { name: "aUV", size: 2, type: r.FLOAT, stride: K, offset: 12, divisor: 0 }
2104
+ { name: "aPosition", size: 2, type: r.FLOAT, stride: $, offset: 0, divisor: 0 },
2105
+ { name: "aColor", size: 4, type: r.UNSIGNED_BYTE, normalized: !0, stride: $, offset: 8, divisor: 0 },
2106
+ { name: "aUV", size: 2, type: r.FLOAT, stride: $, offset: 12, divisor: 0 }
2106
2107
  ]), i.unbindVAO(), this.currentShader && this.currentShader.use(), i;
2107
2108
  }
2108
2109
  /**
@@ -2271,7 +2272,7 @@ class p {
2271
2272
  return new p(Math.cos(t), Math.sin(t));
2272
2273
  }
2273
2274
  }
2274
- const jt = (n, t) => {
2275
+ const Ht = (n, t) => {
2275
2276
  const [e, r, i, s, a, o] = t, h = new Float32Array([
2276
2277
  e,
2277
2278
  i,
@@ -2290,8 +2291,8 @@ const jt = (n, t) => {
2290
2291
  0,
2291
2292
  1
2292
2293
  ]);
2293
- return $t(h, n);
2294
- }, $t = (n, t) => {
2294
+ return Gt(h, n);
2295
+ }, Gt = (n, t) => {
2295
2296
  const e = new Float32Array(16);
2296
2297
  for (let r = 0; r < 4; r++)
2297
2298
  for (let i = 0; i < 4; i++) {
@@ -2302,15 +2303,15 @@ const jt = (n, t) => {
2302
2303
  }
2303
2304
  return e;
2304
2305
  };
2305
- var Kt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(Kt || {});
2306
- const rt = 10, xt = (n, t, e, r, i, s) => {
2306
+ var Vt = /* @__PURE__ */ ((n) => (n[n.STRETCH = 0] = "STRETCH", n[n.REPEAT = 1] = "REPEAT", n))(Vt || {});
2307
+ const J = 10, ct = (n, t, e, r, i, s) => {
2307
2308
  const a = [], o = [], h = r ? Math.atan2(t.y, t.x) : Math.atan2(-t.y, -t.x), c = Math.PI, u = new p(t.y, -t.x);
2308
- for (let l = 0; l < rt; l++) {
2309
- const d = l / rt, f = (l + 1) / rt, m = h + d * c, v = h + f * c, y = new p(Math.cos(m) * e, Math.sin(m) * e), T = new p(Math.cos(v) * e, Math.sin(v) * e);
2310
- a.push(n), o.push(new p(i, 0.5)), a.push(n.add(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e)), a.push(n.add(T)), o.push(new p(i + T.dot(u) * s, 0.5 - 0.5 * T.dot(t) / e));
2309
+ for (let l = 0; l < J; l++) {
2310
+ const d = l / J, f = (l + 1) / J, m = h + d * c, g = h + f * c, v = new p(Math.cos(m) * e, Math.sin(m) * e), y = new p(Math.cos(g) * e, Math.sin(g) * e);
2311
+ a.push(n), o.push(new p(i, 0.5)), a.push(n.add(v)), o.push(new p(i + v.dot(u) * s, 0.5 - 0.5 * v.dot(t) / e)), a.push(n.add(y)), o.push(new p(i + y.dot(u) * s, 0.5 - 0.5 * y.dot(t) / e));
2311
2312
  }
2312
2313
  return { vertices: a, uv: o };
2313
- }, qt = (n, t = !1) => {
2314
+ }, Yt = (n, t = !1) => {
2314
2315
  const e = [];
2315
2316
  if (n.length < 2 || t && n.length < 3) return { normals: e, length: 0 };
2316
2317
  const r = 4, i = 1e-3, s = n.length;
@@ -2330,8 +2331,8 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2330
2331
  {
2331
2332
  let m = d.add(l).normalize();
2332
2333
  l.cross(d) < 0 && (m = m.multiply(-1));
2333
- let v = 1 / Math.sqrt((1 - f) / 2);
2334
- return { normal: m, miters: Math.min(v, r) };
2334
+ let g = 1 / Math.sqrt((1 - f) / 2);
2335
+ return { normal: m, miters: Math.min(g, r) };
2335
2336
  }
2336
2337
  };
2337
2338
  if (t)
@@ -2350,27 +2351,27 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2350
2351
  } else
2351
2352
  e.push(o(n[h - 1], n[h], n[h + 1]));
2352
2353
  return { normals: e, length: a };
2353
- }, Qt = (n) => {
2354
+ }, Xt = (n) => {
2354
2355
  const t = n.points;
2355
2356
  if (t.length < 2) return { vertices: [], uv: [] };
2356
- const { normals: e, length: r } = qt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
2357
+ const { normals: e, length: r } = Yt(t, n.closed), i = (n.width || 1) / 2, s = [], a = [], o = n.roundCap || !1, h = n.textureMode || 0;
2357
2358
  let c = 0;
2358
2359
  const u = n.texture?.rawWidth || 1, l = n.closed ? t.length : t.length - 1;
2359
2360
  for (let d = 0; d < l; d++) {
2360
- const f = t[d], m = e[d].normal, v = e[d].miters, y = (d + 1) % t.length, T = t[y], M = e[y].normal, A = e[y].miters, P = f.add(m.multiply(v * i)), C = f.subtract(m.multiply(v * i)), F = T.add(M.multiply(A * i)), W = T.subtract(M.multiply(A * i)), N = f.distanceTo(T);
2361
+ const f = t[d], m = e[d].normal, g = e[d].miters, v = (d + 1) % t.length, y = t[v], R = e[v].normal, M = e[v].miters, C = f.add(m.multiply(g * i)), P = f.subtract(m.multiply(g * i)), I = y.add(R.multiply(M * i)), O = y.subtract(R.multiply(M * i)), _ = f.distanceTo(y);
2361
2362
  let w = 0, U = 0;
2362
- h === 0 ? (w = c / r, U = (c + N) / r) : (w = c / u, U = w + N / u);
2363
- const X = new p(w, 0), k = new p(w, 1), G = new p(U, 0), I = new p(U, 1);
2364
- s.push(P), a.push(X), s.push(C), a.push(k), s.push(F), a.push(G), s.push(F), a.push(G), s.push(W), a.push(I), s.push(C), a.push(k), c += N;
2363
+ h === 0 ? (w = c / r, U = (c + _) / r) : (w = c / u, U = w + _ / u);
2364
+ const B = new p(w, 0), D = new p(w, 1), G = new p(U, 0), F = new p(U, 1);
2365
+ s.push(C), a.push(B), s.push(P), a.push(D), s.push(I), a.push(G), s.push(I), a.push(G), s.push(O), a.push(F), s.push(P), a.push(D), c += _;
2365
2366
  }
2366
2367
  if (o && !n.closed) {
2367
- const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, v = xt(d, f, i, !0, 0, m);
2368
- s.push(...v.vertices), a.push(...v.uv);
2369
- const y = t[t.length - 1], T = e[t.length - 1].normal, M = h === 0 ? 1 : c / u, A = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, P = xt(y, T, i, !1, M, A);
2370
- s.push(...P.vertices), a.push(...P.uv);
2368
+ const d = t[0], f = e[0].normal, m = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, g = ct(d, f, i, !0, 0, m);
2369
+ s.push(...g.vertices), a.push(...g.uv);
2370
+ const v = t[t.length - 1], y = e[t.length - 1].normal, R = h === 0 ? 1 : c / u, M = h === 0 ? r > 0 ? 1 / r : 0 : 1 / u, C = ct(v, y, i, !1, R, M);
2371
+ s.push(...C.vertices), a.push(...C.uv);
2371
2372
  }
2372
2373
  return { vertices: s, uv: a };
2373
- }, Z = (n, t, e, r) => {
2374
+ }, q = (n, t, e, r) => {
2374
2375
  if (t.customMatrix !== void 0)
2375
2376
  return t.customMatrix;
2376
2377
  if (t.modifyStack) {
@@ -2389,8 +2390,8 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2389
2390
  i
2390
2391
  ), i;
2391
2392
  }
2392
- }, Zt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, Jt = 2, te = (n, t) => {
2393
- const e = Z(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
2393
+ }, zt = (n, t) => t ? n ? t.premultipliedUint32 : t.uint32 : 4294967295, $t = 2, jt = (n, t) => {
2394
+ const e = q(n, t, t.texture.rawWidth, t.texture.rawHeight), r = t.texture;
2394
2395
  if (!r?.base || n.inCreateMask)
2395
2396
  return;
2396
2397
  const i = r.isAtlas ? n.atlasSpriteRegion : n.spriteRegion;
@@ -2398,7 +2399,7 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2398
2399
  let s = r.uvX, a = r.uvY, o = r.uvW, h = r.uvH;
2399
2400
  const c = !!t.flipX, u = !!t.flipY != !!r.flipY;
2400
2401
  let l = t.padding ?? i.currentShader.padding;
2401
- r.isAtlas && (l += Jt);
2402
+ r.isAtlas && (l += $t);
2402
2403
  const d = s <= o ? l : -l, f = a <= h ? l : -l;
2403
2404
  i.drawSprite(
2404
2405
  r,
@@ -2414,7 +2415,7 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2414
2415
  u,
2415
2416
  r.isRotated
2416
2417
  );
2417
- }, ee = (n, t) => {
2418
+ }, Kt = (n, t) => {
2418
2419
  const e = n.particleRegion;
2419
2420
  n.enterRegion(e, t.shader);
2420
2421
  const r = t.texture, i = t.count ?? t.x.length, s = t.color;
@@ -2440,9 +2441,9 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2440
2441
  t.reverseOrder,
2441
2442
  t.customMatrix
2442
2443
  );
2443
- }, St = (n, t) => {
2444
+ }, yt = (n, t) => {
2444
2445
  if (t.points.length === 0) return;
2445
- const e = Z(n, t, 0, 0);
2446
+ const e = q(n, t, 0, 0);
2446
2447
  n.startGraphic(
2447
2448
  t.drawMode ?? n.gl.TRIANGLES,
2448
2449
  t.texture,
@@ -2460,18 +2461,18 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2460
2461
  );
2461
2462
  }
2462
2463
  n.endGraphic();
2463
- }, re = (n, t) => {
2464
+ }, qt = (n, t) => {
2464
2465
  if (n.inCreateMask)
2465
2466
  return;
2466
- const { vertices: e, uv: r } = Qt(t);
2467
- St(n, {
2467
+ const { vertices: e, uv: r } = Xt(t);
2468
+ yt(n, {
2468
2469
  ...t,
2469
2470
  points: e,
2470
2471
  uv: r,
2471
2472
  drawMode: n.gl.TRIANGLES
2472
2473
  });
2473
- }, ie = (n, t) => {
2474
- const e = Z(
2474
+ }, Qt = (n, t) => {
2475
+ const e = q(
2475
2476
  n,
2476
2477
  t,
2477
2478
  t.texture.rawWidth,
@@ -2482,16 +2483,16 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2482
2483
  t.texture,
2483
2484
  e ?? t.customMatrix
2484
2485
  ), n.addRectVertex(t.texture.rawWidth, t.texture.rawHeight), n.endGraphic();
2485
- }, se = (n, t) => {
2486
- const e = Z(n, t, t.width, t.height);
2486
+ }, Zt = (n, t) => {
2487
+ const e = q(n, t, t.width, t.height);
2487
2488
  n.startGraphic(
2488
2489
  n.gl.TRIANGLE_FAN,
2489
2490
  t.texture,
2490
2491
  t.shader,
2491
2492
  e ?? t.customMatrix
2492
2493
  ), n.addRectVertex(t.width, t.height, t.color), n.endGraphic();
2493
- }, ne = (n, t) => {
2494
- const e = t.segments ?? 32, r = Z(n, t, 0, 0);
2494
+ }, Jt = (n, t) => {
2495
+ const e = t.segments ?? 32, r = q(n, t, 0, 0);
2495
2496
  n.startGraphic(
2496
2497
  n.gl.TRIANGLE_FAN,
2497
2498
  void 0,
@@ -2500,7 +2501,7 @@ const rt = 10, xt = (n, t, e, r, i, s) => {
2500
2501
  );
2501
2502
  const i = n.getColorUint32(t.color);
2502
2503
  n.addGraphicVertex(0, 0, 0.5, 0.5, i), n.addCircleVertex(t.radius, t.color, e), n.addGraphicVertex(t.radius, 0, 1, 0.5, i), n.endGraphic();
2503
- }, pt = `#version 300 es\r
2504
+ }, ut = `#version 300 es\r
2504
2505
  precision mediump float;\r
2505
2506
  \r
2506
2507
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -2550,21 +2551,21 @@ void main(void) {\r
2550
2551
  // CUSTOM_CODE_CALL\r
2551
2552
  }\r
2552
2553
  `;
2553
- class ae extends ot {
2554
+ class te extends nt {
2554
2555
  KEY = "AtlasSprite";
2555
2556
  constructor(t) {
2556
2557
  super(t);
2557
2558
  }
2558
2559
  createCustomShader(t) {
2559
- const e = V(pt, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = V(tt, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2560
+ const e = H(ut, this.rapid.maxTextureUnits - t.usedTextureUnitNum), r = H(Q, this.rapid.maxTextureUnits - t.usedTextureUnitNum);
2560
2561
  return t.getGLShader(this, this.KEY, r, e);
2561
2562
  }
2562
2563
  createDefaultShader() {
2563
- const t = this.rapid, e = V(pt, t.maxTextureUnits), r = V(tt, t.maxTextureUnits);
2564
+ const t = this.rapid, e = H(ut, t.maxTextureUnits), r = H(Q, t.maxTextureUnits);
2564
2565
  return this.vs = r, this.fs = e, this.defaultShader = this.createShader(r, e), this.defaultShader;
2565
2566
  }
2566
2567
  }
2567
- const gt = `#version 300 es\r
2568
+ const lt = `#version 300 es\r
2568
2569
  precision highp float;\r
2569
2570
  \r
2570
2571
  // per-vertex\r
@@ -2605,7 +2606,7 @@ void main(void) {\r
2605
2606
  \r
2606
2607
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
2607
2608
  }\r
2608
- `, vt = `#version 300 es\r
2609
+ `, dt = `#version 300 es\r
2609
2610
  precision mediump float;\r
2610
2611
  \r
2611
2612
  uniform sampler2D uTexture;\r
@@ -2621,19 +2622,20 @@ void main(void) {\r
2621
2622
  \r
2622
2623
  // CUSTOM_CODE_CALL\r
2623
2624
  }\r
2624
- `, Y = 48, yt = Y / 4;
2625
- class he extends ot {
2625
+ `, V = 48, ee = V / 4;
2626
+ class re extends nt {
2626
2627
  KEY = "ParticleSprite";
2627
2628
  texture;
2628
2629
  customMatrix;
2630
+ particleLoopCache = /* @__PURE__ */ new Map();
2629
2631
  constructor(t) {
2630
2632
  super(t);
2631
2633
  }
2632
2634
  createCustomShader(t) {
2633
- return t.getGLShader(this, this.KEY, gt, vt);
2635
+ return t.getGLShader(this, this.KEY, lt, dt);
2634
2636
  }
2635
2637
  createDefaultShader() {
2636
- const t = vt, e = gt;
2638
+ const t = dt, e = lt;
2637
2639
  return this.vs = e, this.fs = t, this.defaultShader = this.createShader(e, t), this.defaultShader;
2638
2640
  }
2639
2641
  enter(t) {
@@ -2642,52 +2644,111 @@ class he extends ot {
2642
2644
  createShader(t, e) {
2643
2645
  const r = super.createShader(t, e);
2644
2646
  return r.use(), r.bindVAO(), this.instanceBuffer.bindBuffer(), r.setAttributes([
2645
- { name: "aPosition", size: 2, stride: Y, offset: 0, divisor: 1 },
2646
- { name: "aScale", size: 2, stride: Y, offset: 8, divisor: 1 },
2647
- { name: "aRotation", size: 1, stride: Y, offset: 16, divisor: 1 },
2648
- { name: "aUVRect", size: 4, stride: Y, offset: 20, divisor: 1 },
2649
- { name: "aColor", size: 4, type: at, normalized: !0, stride: Y, offset: 36, divisor: 1 },
2650
- { name: "aOrigin", size: 2, stride: Y, offset: 40, divisor: 1 }
2647
+ { name: "aPosition", size: 2, stride: V, offset: 0, divisor: 1 },
2648
+ { name: "aScale", size: 2, stride: V, offset: 8, divisor: 1 },
2649
+ { name: "aRotation", size: 1, stride: V, offset: 16, divisor: 1 },
2650
+ { name: "aUVRect", size: 4, stride: V, offset: 20, divisor: 1 },
2651
+ { name: "aColor", size: 4, type: it, normalized: !0, stride: V, offset: 36, divisor: 1 },
2652
+ { name: "aOrigin", size: 2, stride: V, offset: 40, divisor: 1 }
2651
2653
  ]), this.quadBuffer.bindBuffer(), r.setAttributes([
2652
2654
  { name: "aVertex", size: 2, stride: 8, offset: 0, divisor: 0 }
2653
2655
  ]), r.unbindVAO(), this.currentShader && this.currentShader.use(), r;
2654
2656
  }
2655
- drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, v = !1, y = 0.5, T = 0.5, M, A = !1, P) {
2657
+ drawParticles(t, e, r, i = 0, s = 4294967295, a, o = 1, h = 1, c = 0, u = 0, l = 1, d = 1, f = !1, m = !1, g = !1, v = 0.5, y = 0.5, R, M = !1, C) {
2656
2658
  if (!t.glTexture || a <= 0) return;
2657
- let C = 0;
2658
- const F = typeof o == "number", W = typeof h == "number", N = typeof i == "number", w = typeof s == "number", U = typeof c == "number", X = !w && typeof s[0] == "number";
2659
- let k = t.rawWidth * (f ? -1 : 1);
2660
- F && (k *= o);
2661
- let G = t.rawHeight * (m ? -1 : 1);
2662
- W && (G *= h), U && (G *= d - u, k *= l - c);
2663
- let I = v ? Math.PI / 2 : 0;
2664
- for (N && (I += i); C < a; ) {
2665
- this.texture && t !== this.texture && this.flush(), this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2666
- const B = a - C, H = this.instanceBuffer;
2667
- let R = H.usedElemNum;
2668
- H.resize(B * yt);
2669
- const g = H.float32, S = H.uint32;
2670
- for (let J = 0; J < B; J++) {
2671
- const D = A ? a - 1 - C - J : C + J;
2672
- if (g[R] = e[D], g[R + 1] = r[D], g[R + 2] = F ? k : k * o[D], g[R + 3] = W ? G : G * h[D], g[R + 4] = N ? I : i[D] + I, U)
2673
- g[R + 5] = c, g[R + 6] = u, g[R + 7] = l, g[R + 8] = d;
2674
- else {
2675
- const j = c[D], ct = u[D], ut = l[D], lt = d[D];
2676
- g[R + 5] = j, g[R + 6] = ct, g[R + 7] = ut, g[R + 8] = lt, g[R + 2] *= lt - ct, g[R + 3] *= ut - j;
2677
- }
2678
- if (w)
2679
- S[R + 9] = 4294967295;
2680
- else if (X)
2681
- S[R + 9] = s[D];
2682
- else {
2683
- const j = s[D];
2684
- S[R + 9] = M ? j.premultipliedUint32 : j.uint32;
2685
- }
2686
- g[R + 10] = y, g[R + 11] = T, R += yt;
2687
- }
2688
- H.usedElemNum = R, H.makeDirty(), this.instanceCount += B, C += B;
2689
- }
2690
- this.customMatrix = P, this.flush();
2659
+ this.texture && t !== this.texture && this.flush();
2660
+ const P = typeof o == "number", I = typeof h == "number", O = typeof i == "number", _ = typeof s == "number", w = typeof c == "number", U = !_ && typeof s[0] == "number";
2661
+ let B = t.rawWidth * (f ? -1 : 1);
2662
+ P && (B *= o);
2663
+ let D = t.rawHeight * (m ? -1 : 1);
2664
+ I && (D *= h), w && (B *= l - c, D *= d - u);
2665
+ let G = g ? Math.PI / 2 : 0;
2666
+ O && (G += i);
2667
+ const F = s ?? 4294967295, k = this.getParticleLoop(
2668
+ P,
2669
+ I,
2670
+ O,
2671
+ w,
2672
+ _,
2673
+ U,
2674
+ M,
2675
+ R
2676
+ );
2677
+ this.texture || (this.texture = t, this.useTexture(t.glTexture, 0, 0));
2678
+ const X = a, W = this.instanceBuffer;
2679
+ let T = W.usedElemNum;
2680
+ W.resize(X * ee);
2681
+ const S = W.float32, Et = W.uint32;
2682
+ T = k(
2683
+ e,
2684
+ r,
2685
+ o,
2686
+ h,
2687
+ i,
2688
+ c,
2689
+ u,
2690
+ l,
2691
+ d,
2692
+ s,
2693
+ S,
2694
+ Et,
2695
+ B,
2696
+ D,
2697
+ G,
2698
+ F,
2699
+ v,
2700
+ y,
2701
+ a,
2702
+ X,
2703
+ T
2704
+ ), W.usedElemNum = T, W.makeDirty(), this.instanceCount += X, this.customMatrix = C, this.flush();
2705
+ }
2706
+ getParticleLoop(t, e, r, i, s, a, o, h) {
2707
+ const c = [...arguments].join("_");
2708
+ if (this.particleLoopCache.has(c))
2709
+ return this.particleLoopCache.get(c);
2710
+ let u = `
2711
+ return function( x, y, scaleX, scaleY, rotation, u0, v0, u1, v1, color, f32, u32, rawWidth, rawHeight, rotationOffset, staticColor, originX, originY, count, batchCount, index ) {
2712
+ ${t && i ? "const baseSx = rawWidth;" : ""}
2713
+ ${e && i ? "const baseSy = rawHeight;" : ""}
2714
+
2715
+ const endIdx = index + batchCount * 12;
2716
+ let idx = index;
2717
+ if (endIdx > f32.length) return index;
2718
+
2719
+ ${o ? "for (let src = count - 1; idx < endIdx; src--, idx += 12) {" : "for (let src = 0; idx < endIdx; src++, idx += 12) {"}
2720
+ f32[idx] = x[src];
2721
+ f32[idx + 1] = y[src];
2722
+
2723
+ ${i ? `
2724
+ f32[idx + 2] = ${t ? "baseSx" : "rawWidth * scaleX[src]"};
2725
+ f32[idx + 3] = ${e ? "baseSy" : "rawHeight * scaleY[src]"};
2726
+ f32[idx + 4] = ${r ? "rotationOffset" : "rotation[src] + rotationOffset"};
2727
+ f32[idx + 5] = u0;
2728
+ f32[idx + 6] = v0;
2729
+ f32[idx + 7] = u1;
2730
+ f32[idx + 8] = v1;
2731
+ ` : `
2732
+ const cu0 = u0[src], cv0 = v0[src], cu1 = u1[src], cv1 = v1[src];
2733
+ f32[idx + 2] = (rawWidth * (cu1 - cu0)) ${t ? "" : "* scaleX[src]"};
2734
+ f32[idx + 3] = (rawHeight * (cv1 - cv0)) ${e ? "" : "* scaleY[src]"};
2735
+ f32[idx + 4] = ${r ? "rotationOffset" : "rotation[src] + rotationOffset"};
2736
+ f32[idx + 5] = cu0;
2737
+ f32[idx + 6] = cv0;
2738
+ f32[idx + 7] = cu1;
2739
+ f32[idx + 8] = cv1;
2740
+ `}
2741
+
2742
+ u32[idx + 9] = ${s ? "staticColor" : a ? "color[src]" : `color[src].${h ? "premultipliedUint32" : "uint32"}`};
2743
+
2744
+ f32[idx + 10] = originX;
2745
+ f32[idx + 11] = originY;
2746
+ }
2747
+ return idx;
2748
+ }
2749
+ `;
2750
+ const l = new Function(u)();
2751
+ return this.particleLoopCache.set(c, l), l;
2691
2752
  }
2692
2753
  render() {
2693
2754
  if (this.instanceCount === 0) return;
@@ -2696,12 +2757,12 @@ class he extends ot {
2696
2757
  this.texture && (t.activeTexture(t.TEXTURE0), t.bindTexture(t.TEXTURE_2D, this.texture.glTexture));
2697
2758
  const e = this.currentShader;
2698
2759
  this.instanceBuffer.bindBuffer(), this.instanceBuffer.bufferData(), e.bindVAO();
2699
- const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = jt(this.rapid.projection, s);
2700
- this.currentShader.setUniform("u_projection", a), Mt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2760
+ const r = this.rapid.matrixStack, s = this.rapid.matrix.getMatrix(this.customMatrix ?? r.curWorldM), a = Ht(this.rapid.projection, s);
2761
+ this.currentShader.setUniform("u_projection", a), pt(t, t.TRIANGLE_STRIP, 0, 4, this.instanceCount), this.rapid.drawcallCount++, this.texture = void 0, this.customMatrix = void 0;
2701
2762
  }
2702
2763
  }
2703
- var oe = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(oe || {}), ce = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(ce || {}), ht = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(ht || {}), ue = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(ue || {});
2704
- class fe {
2764
+ var ie = /* @__PURE__ */ ((n) => (n[n.EQUAL = 0] = "EQUAL", n[n.NOT_EQUAL = 1] = "NOT_EQUAL", n))(ie || {}), se = /* @__PURE__ */ ((n) => (n[n.NORMAL = 0] = "NORMAL", n[n.ADD = 1] = "ADD", n[n.MULTIPLY = 2] = "MULTIPLY", n[n.SCREEN = 3] = "SCREEN", n[n.ERASE = 4] = "ERASE", n))(se || {}), st = /* @__PURE__ */ ((n) => (n[n.LINEAR = 0] = "LINEAR", n[n.NEAREST = 1] = "NEAREST", n))(st || {}), ne = /* @__PURE__ */ ((n) => (n[n.CanvasItem = 0] = "CanvasItem", n[n.Viewport = 1] = "Viewport", n))(ne || {});
2765
+ class oe {
2705
2766
  /** The active WebGL context. */
2706
2767
  gl;
2707
2768
  /** The target HTMLCanvasElement. */
@@ -2727,7 +2788,7 @@ class fe {
2727
2788
  /** Maximum number of texture units supported by the device. */
2728
2789
  maxTextureUnits = 0;
2729
2790
  /** Matrix stack for hierarchical transformations. */
2730
- matrixStack = new Ct(this);
2791
+ matrixStack = new wt(this);
2731
2792
  /** Direct access to the underlying matrix store. */
2732
2793
  matrix;
2733
2794
  /** Region dedicated to fast sprite rendering. */
@@ -2752,7 +2813,7 @@ class fe {
2752
2813
  scaleMode;
2753
2814
  /** Internal ping-pong RenderTextures for multi-filter chains. */
2754
2815
  _filterRT = [null, null];
2755
- _filterInput = new O();
2816
+ _filterInput = new N();
2756
2817
  get height() {
2757
2818
  return this.logicHeight;
2758
2819
  }
@@ -2765,10 +2826,10 @@ class fe {
2765
2826
  */
2766
2827
  constructor(t) {
2767
2828
  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;
2768
- const e = It(this.canvas, this.antialias, this.premultipliedAlpha);
2769
- this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new ot(this), this.graphicRegion = new Xt(this), this.atlasSpriteRegion = new ae(this), this.particleRegion = new he(this);
2829
+ const e = Ut(this.canvas, this.antialias, this.premultipliedAlpha);
2830
+ this.gl = e, this.maxTextureUnits = e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS), this.matrix = this.matrixStack.matrix, this.spriteRegion = new nt(this), this.graphicRegion = new kt(this), this.atlasSpriteRegion = new te(this), this.particleRegion = new re(this);
2770
2831
  const r = this.canvas.clientWidth || this.canvas.width, i = this.canvas.clientHeight || this.canvas.height;
2771
- this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new _t(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);
2832
+ this.physicsWidth = t.physicsWidth || Math.round(r * this.dpr), this.physicsHeight = t.physicsHeight || Math.round(i * this.dpr), this.logicWidth = t.logicWidth || t.width || this.physicsWidth / this.dpr, this.logicHeight = t.logicHeight || t.height || this.physicsHeight / this.dpr, this.resize(this.logicWidth, this.logicHeight, this.physicsWidth, this.physicsHeight), this.texture = new Mt(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);
2772
2833
  }
2773
2834
  setTextureFilter(t) {
2774
2835
  this.textureFilter = t;
@@ -2777,7 +2838,7 @@ class fe {
2777
2838
  this.antialias = t;
2778
2839
  }
2779
2840
  getColorUint32(t) {
2780
- return Zt(this.premultipliedAlpha, t);
2841
+ return zt(this.premultipliedAlpha, t);
2781
2842
  }
2782
2843
  /**
2783
2844
  * Enters a specific rendering region, flushing the previous one if necessary.
@@ -2788,22 +2849,22 @@ class fe {
2788
2849
  this.currentRegion === t && this.currentRegion.isSameShader(e) || (this.flush(), this.currentRegion = t, t.enter(e));
2789
2850
  }
2790
2851
  drawParticles(t) {
2791
- ee(this, t);
2852
+ Kt(this, t);
2792
2853
  }
2793
2854
  drawSprite(t) {
2794
- te(this, t);
2855
+ jt(this, t);
2795
2856
  }
2796
2857
  drawLine(t) {
2797
- re(this, t);
2858
+ qt(this, t);
2798
2859
  }
2799
2860
  drawGraphic(t) {
2800
- St(this, t);
2861
+ yt(this, t);
2801
2862
  }
2802
2863
  drawRect(t) {
2803
- se(this, t);
2864
+ Zt(this, t);
2804
2865
  }
2805
2866
  drawCircle(t) {
2806
- ne(this, t);
2867
+ Jt(this, t);
2807
2868
  }
2808
2869
  /**
2809
2870
  * Starts rendering arbitrary graphics geometries.
@@ -2827,7 +2888,7 @@ class fe {
2827
2888
  * @param texture The texture to be used as a mask.
2828
2889
  */
2829
2890
  drawMaskImage(t) {
2830
- ie(this, t);
2891
+ Qt(this, t);
2831
2892
  }
2832
2893
  /**
2833
2894
  * Pushes vertices for a rectangle geometry. Should be enclosed by startGraphic and endGraphic.
@@ -3223,7 +3284,7 @@ class fe {
3223
3284
  return this.matrix.toCSSMatrix(t ?? this.matrixStack.curWorldM, e, r);
3224
3285
  }
3225
3286
  }
3226
- function le(n) {
3287
+ function ae(n) {
3227
3288
  return !(n === null || typeof n != "object" || Array.isArray(n) || n instanceof p || n instanceof x);
3228
3289
  }
3229
3290
  class L {
@@ -3289,17 +3350,17 @@ class L {
3289
3350
  return typeof t == "number" ? t : t.clone();
3290
3351
  }
3291
3352
  }
3292
- var de = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(de || {});
3293
- const Tt = 10, Et = 0, Rt = !0;
3294
- class q {
3353
+ var he = /* @__PURE__ */ ((n) => (n.POINT = "point", n.CIRCLE = "circle", n.RECT = "rect", n))(he || {});
3354
+ const ft = 10, mt = 0, xt = !0;
3355
+ class j {
3295
3356
  components;
3296
3357
  constructor(t = 1) {
3297
3358
  if (!Number.isInteger(t) || t <= 0)
3298
3359
  throw new RangeError("ParticleAttributeStore size must be a positive integer");
3299
3360
  this.components = Array.from({ length: t }, () => ({
3300
- value: new _(b.Float32),
3301
- delta: new _(b.Float32),
3302
- damping: new _(b.Float32)
3361
+ value: new b(A.Float32),
3362
+ delta: new b(A.Float32),
3363
+ damping: new b(A.Float32)
3303
3364
  }));
3304
3365
  }
3305
3366
  getArrayBuffer() {
@@ -3338,7 +3399,7 @@ class q {
3338
3399
  ) : this.getComponent(t, e);
3339
3400
  }
3340
3401
  create(t, e, r = 1) {
3341
- const i = le(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
3402
+ const i = ae(t) ? t : void 0, s = i === void 0 ? t : void 0, a = r > 0 ? r : 1;
3342
3403
  let o = 0;
3343
3404
  for (let h = 0; h < this.components.length; h++) {
3344
3405
  const { value: c, delta: u, damping: l } = this.components[h], d = this.getComponent(e, h), f = s === void 0 ? this.resolveComponent(i?.start, h, d) : this.getComponent(s, h), m = i?.end === void 0 ? f : this.resolveComponent(i.end, h, d);
@@ -3347,28 +3408,29 @@ class q {
3347
3408
  return o;
3348
3409
  }
3349
3410
  }
3350
- class bt {
3411
+ class Tt {
3351
3412
  options;
3352
3413
  emitting = !1;
3353
3414
  emitTimer = 0;
3354
- emitRate = Tt;
3355
- emitTime = Et;
3415
+ emitRate = ft;
3416
+ emitTime = mt;
3356
3417
  emitTimeCounter = 0;
3357
3418
  /** Whether spawned particles are positioned in local emitter space (default: true). */
3358
- localSpace = Rt;
3419
+ localSpace = xt;
3359
3420
  rapid;
3360
- x = new _(b.Float32);
3361
- y = new _(b.Float32);
3362
- scaleX = new _(b.Float32);
3363
- scaleY = new _(b.Float32);
3364
- rotation = new _(b.Float32);
3365
- color = new _(b.Uint32);
3421
+ x = new b(A.Float32);
3422
+ y = new b(A.Float32);
3423
+ scaleX = new b(A.Float32);
3424
+ scaleY = new b(A.Float32);
3425
+ rotation = new b(A.Float32);
3426
+ color = new b(A.Uint32);
3427
+ remainingLife = new b(A.Float32);
3366
3428
  animations = {
3367
- speed: new q(),
3368
- rotation: new q(),
3369
- scale: new q(),
3370
- color: new q(4),
3371
- velocity: new q(2)
3429
+ speed: new j(),
3430
+ rotation: new j(),
3431
+ scale: new j(),
3432
+ color: new j(4),
3433
+ velocity: new j(2)
3372
3434
  };
3373
3435
  count = 0;
3374
3436
  /**
@@ -3377,7 +3439,7 @@ class bt {
3377
3439
  * @param options - Emitter configuration options
3378
3440
  */
3379
3441
  constructor(t, e) {
3380
- this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? Tt, this.emitTime = e.emitTime ?? Et, this.localSpace = e.localSpace ?? Rt;
3442
+ this.rapid = t, this.options = e, this.emitRate = e.emitRate ?? ft, this.emitTime = e.emitTime ?? mt, this.localSpace = e.localSpace ?? xt;
3381
3443
  }
3382
3444
  getAllArrayBuffer() {
3383
3445
  return [
@@ -3387,6 +3449,7 @@ class bt {
3387
3449
  this.scaleY,
3388
3450
  this.rotation,
3389
3451
  this.color,
3452
+ this.remainingLife,
3390
3453
  ...Object.values(this.animations).flatMap((t) => t.getArrayBuffer())
3391
3454
  ];
3392
3455
  }
@@ -3399,7 +3462,7 @@ class bt {
3399
3462
  * Particle state is NOT copied.
3400
3463
  */
3401
3464
  clone() {
3402
- return new bt(this.rapid, { ...this.options });
3465
+ return new Tt(this.rapid, { ...this.options });
3403
3466
  }
3404
3467
  /** Sets particles-per-second emission rate (continuous mode). */
3405
3468
  setEmitRate(t) {
@@ -3434,6 +3497,7 @@ class bt {
3434
3497
  }
3435
3498
  createParticle() {
3436
3499
  const t = L.scalarOrRange(this.options.life, 1);
3500
+ this.remainingLife.push(t);
3437
3501
  let e = 0, r = 0;
3438
3502
  switch (this.options.emitShape) {
3439
3503
  case "circle": {
@@ -3479,12 +3543,16 @@ class bt {
3479
3543
  r > 0 && (this.emit(r), this.emitTimer -= r / this.emitRate);
3480
3544
  }
3481
3545
  const e = this.updateParticle(t);
3482
- this.count -= e.length, _.removeAtIndices(e, this.getAllArrayBuffer());
3546
+ this.count -= e.length, b.removeAtIndices(e, this.getAllArrayBuffer());
3483
3547
  }
3484
3548
  updateParticle(t) {
3485
3549
  const e = [], r = this.animations;
3486
3550
  Object.values(r).forEach((i) => i.update(t));
3487
3551
  for (let i = 0; i < this.count; i++) {
3552
+ if (this.remainingLife.typedArray[i] -= t, this.remainingLife.typedArray[i] <= 0) {
3553
+ e.push(i);
3554
+ continue;
3555
+ }
3488
3556
  const s = r.rotation.get(i), a = r.scale.get(i), o = r.speed.get(i);
3489
3557
  this.rotation.typedArray[i] = s, this.scaleX.typedArray[i] = a, this.scaleY.typedArray[i] = a, this.color.uint32[i] = x.packColor(
3490
3558
  r.color.get(i, 0),
@@ -3530,41 +3598,41 @@ class bt {
3530
3598
  }
3531
3599
  }
3532
3600
  export {
3533
- b as ArrayType,
3534
- z as BaseTexture,
3535
- ce as BlendMode,
3536
- ue as CanvasScaleMode,
3601
+ A as ArrayType,
3602
+ Y as BaseTexture,
3603
+ se as BlendMode,
3604
+ ne as CanvasScaleMode,
3537
3605
  x as Color,
3538
- ft as CustomGlShader,
3539
- _ as DynamicArrayBuffer,
3540
- wt as GLShader,
3541
- Xt as GraphicRegion,
3542
- Kt as LineTextureMode,
3543
- oe as MaskType,
3544
- Ct as MatrixStack,
3545
- Ut as MatrixStore,
3546
- bt as ParticleEmitter,
3547
- de as ParticleShape,
3548
- Gt as QUAD_VERTICES,
3549
- fe as Rapid,
3550
- At as Region,
3551
- Pt as RenderTexture,
3552
- ot as SpriteRegion,
3553
- Lt as TextTexture,
3554
- O as Texture,
3555
- ht as TextureFilterMode,
3556
- _t as TextureManager,
3557
- Q as TextureWrapMode,
3606
+ ht as CustomGlShader,
3607
+ b as DynamicArrayBuffer,
3608
+ gt as GLShader,
3609
+ kt as GraphicRegion,
3610
+ Vt as LineTextureMode,
3611
+ ie as MaskType,
3612
+ wt as MatrixStack,
3613
+ Rt as MatrixStore,
3614
+ Tt as ParticleEmitter,
3615
+ he as ParticleShape,
3616
+ Ot as QUAD_VERTICES,
3617
+ oe as Rapid,
3618
+ vt as Region,
3619
+ At as RenderTexture,
3620
+ nt as SpriteRegion,
3621
+ bt as TextTexture,
3622
+ N as Texture,
3623
+ st as TextureFilterMode,
3624
+ Mt as TextureManager,
3625
+ K as TextureWrapMode,
3558
3626
  p as Vec2,
3559
- it as WebglBufferArray,
3560
- jt as composeProjectionWithAffine,
3561
- ne as drawCircle,
3562
- St as drawGraphic,
3563
- re as drawLine,
3564
- ie as drawMaskImage,
3565
- ee as drawParticles,
3566
- se as drawRect,
3567
- te as drawSprite,
3568
- Zt as getColorUint32,
3569
- $t as multiplyMat4
3627
+ tt as WebglBufferArray,
3628
+ Ht as composeProjectionWithAffine,
3629
+ Jt as drawCircle,
3630
+ yt as drawGraphic,
3631
+ qt as drawLine,
3632
+ Qt as drawMaskImage,
3633
+ Kt as drawParticles,
3634
+ Zt as drawRect,
3635
+ jt as drawSprite,
3636
+ zt as getColorUint32,
3637
+ Gt as multiplyMat4
3570
3638
  };